Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Expose near-lake-primitives to VM #613

Merged
merged 8 commits into from
Mar 26, 2024

Conversation

morgsmccauley
Copy link
Collaborator

@morgsmccauley morgsmccauley commented Mar 20, 2024

  • Upgrade near-lake-primitives to 0.2.0, which includes borsh
  • Expose entire near-lake-primitives library to VM via primitives, e.g. borsh can be accessed via primitives.borsh.fromBorsh()

@morgsmccauley morgsmccauley changed the title feat/expose lake primitives feat: Expose near-lake-primitives to VM Mar 20, 2024
@@ -1,6114 +0,0 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The project expects npm install and we should stick to that

@morgsmccauley morgsmccauley marked this pull request as ready for review March 20, 2024 00:56
@morgsmccauley morgsmccauley requested a review from a team as a code owner March 20, 2024 00:56
@morgsmccauley morgsmccauley self-assigned this Mar 20, 2024
@morgsmccauley morgsmccauley linked an issue Mar 20, 2024 that may be closed by this pull request
@darunrs
Copy link
Collaborator

darunrs commented Mar 20, 2024

I believe we need to increase the primitives library version in the frontend too. I don't think we need to make any code changes though, since we pull the primitives type file from node nodules and add the whole file. Could be wrong on that though.

@morgsmccauley morgsmccauley force-pushed the feat/expose-lake-primitives branch from 4280afb to f517967 Compare March 20, 2024 20:21
@morgsmccauley
Copy link
Collaborator Author

I believe we need to increase the primitives library version in the frontend too. I don't think we need to make any code changes though, since we pull the primitives type file from node nodules and add the whole file. Could be wrong on that though.

Done, looks like it does pull from node_modules so shouldn't require any change

@darunrs
Copy link
Collaborator

darunrs commented Mar 21, 2024

Sorry another thought just occurred to me. The reason we can freeze Block as "block" is because we import it through import { Block } from "@near-lake/primitives"; and then have users write code in a function which surfaces it as block through async function getBlock(block: Block) { in the frontend. I believe we might need to make a change to the template code on the frontend to import whatever we want from primitives as Primitives. Otherwise, autocomplete might lead users to write code that doesn't reference primitives the way we were expecting.

@morgsmccauley
Copy link
Collaborator Author

Sorry another thought just occurred to me. The reason we can freeze Block as "block" is because we import it through import { Block } from "@near-lake/primitives"; and then have users write code in a function which surfaces it as block through async function getBlock(block: Block) { in the frontend. I believe we might need to make a change to the template code on the frontend to import whatever we want from primitives as Primitives. Otherwise, autocomplete might lead users to write code that doesn't reference primitives the way we were expecting.

Good catch - we do need to update the template, most likely to import * as primitives from "@near-lake/primitives", so they have access to the entire primitives library.

It also looks like type declarations are manually defined/included, so those will need to be updated. Would be more convenient if we could pull from the library/node_modules directly, but I don't think that's possible with the multi-file output near-lake-primitives currently has. I'll see if I can get that working.

@morgsmccauley
Copy link
Collaborator Author

I've updated the primitives (near-lake-primitives) types for Frontend - but this won't include the types for exported dependant packages, i.e. borsher. This exports are still usable, but won't be visible via frontend intellisense. Dependant packages are referenced via imports, which therefore assume that the library exists within node_modules, this is tricky to achieve with Monaco, so for now, all dependant packages will be left as any. We may revisit this again in future.

For reference, borsher is exported under the borsh module within near-lake-primitives. So the entire library is accessible via primitives.borsh.{borsher API}, e.g. primitives.borsh.borshSerialize()

FYI @Tguntenaar

@morgsmccauley morgsmccauley merged commit 41ccc6a into main Mar 26, 2024
5 checks passed
@morgsmccauley morgsmccauley deleted the feat/expose-lake-primitives branch March 26, 2024 22:02
@darunrs darunrs mentioned this pull request Mar 28, 2024
darunrs pushed a commit that referenced this pull request Apr 3, 2024
- feat: Instrument Runner Service (#602)
- Support WHERE col IN (...) in context.db.table.select and delete
(#606)
- feat: Include indexer name in context db build failure warning (#611)
- Cache provisioning status (#607)
- Fix ESLint on DmlHandler (#612)
- fix: Substitution 'node-sql-parser' with a forked version until Apri
1st (#597)
- feat: Add pgBouncer to QueryApi (#615)
- feat: Expose near-lake-primitives to VM (#613)

---------

Co-authored-by: Pavel Kudinov <mrkroz@gmail.com>
Co-authored-by: Pavel Kudinov <pavel@near.org>
Co-authored-by: Kevin Zhang <42101107+Kevin101Zhang@users.noreply.github.com>
Co-authored-by: Morgan McCauley <morgan@mccauley.co.nz>
This was referenced Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support from borsh-js
2 participants