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

Initial version with tests #1

Merged
merged 2 commits into from
Sep 20, 2022
Merged

Initial version with tests #1

merged 2 commits into from
Sep 20, 2022

Conversation

RangerMauve
Copy link
Owner

@RangerMauve RangerMauve commented Sep 13, 2022

Got support for IPLD URL parsing, traversal accross links and escaped paths, support for ADLs which can asynchronously load paths, support for schemas and using schemas as sort of ADL.

TODO:

  • Add JSDoc types
  • Support all places where typed links could exist in the data model
    • lists of links
    • maps with links
    • ???
  • Change wording from "ADL" to "Lenses" with ADLs being a subset of Lenses.
  • Add tests for 'failing' resolves for Schemas
  • Add test for a basic ADL
  • Integrate Aegir and prep move to IPLD GH org.

index.js Outdated Show resolved Hide resolved
index.js Outdated
Comment on lines 124 to 128
if (!converted) {
const dataView = JSON.stringify(node)
const schemaDSL = toDSL(schemaDMT)
throw new Error(`Data did not match schema\nData: ${dataView}\nSchema:${schemaDSL}`)
}
Copy link

Choose a reason for hiding this comment

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

some fun suggestions for you to consider in addition here:

Copy link
Owner Author

Choose a reason for hiding this comment

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

Great call on using printify!

index.js Outdated

const schemaCID = CID.parse(schema, system.cidBases)
const schemaDMT = await system.getNode(schemaCID)
const converted = makeTyped(node, schemaDMT, type)
Copy link

Choose a reason for hiding this comment

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

I'm not sure if there's a possibility for caching here, maybe there is since this is a multi-use "system", but if you memoize converted then it'll be even more efficient. These are generated functions that cost a little to generate up-front but should be really speedy for multiple uses. converted could be cached alongside the schema CID on the parent IPLDURLSystem.
Obviously not necessary, but if this gets reused over and over then it might be worth doing at some point.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Hmm, Ii'd be worried about having a memory leak. Maybe if there was an LRU? What do you think about having a separate issue to track caching of schemas? It might also be relevant to caching WASM modules once we get those in.

Copy link
Owner Author

Choose a reason for hiding this comment

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

also not sure where the caching would take place given Schema is structured as an ADL. 🤔

index.js Outdated
const typedFields = new Map()
if (typeDMT.struct) {
for (const [name, fieldDMT] of Object.entries(typeDMT.struct.fields)) {
const nestedType = fieldDMT.type?.link?.expectedType
Copy link

Choose a reason for hiding this comment

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

beware that link isn't the only possible thing in this position and that may matter

See StructField in the schema-schema, or perhaps it's easier to read now we have a typescript form of the schema-schema (!): https://github.com/ipld/js-ipld-schema/blob/fae8a4cb86f185abafddc9284bd0dec70da133c9/schema-schema.ts#L107-L123

i.e. you can also have inline defined lists and maps which can also have links in them! (foo [&Bar]). Of course you're also allowed to ignore those and say you don't support them.

Copy link

Choose a reason for hiding this comment

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

maybe also have a look at other places that inline links can show up and consider whether you need to handle them too?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Good catch. Added some todos in the issue for this

@rvagg
Copy link

rvagg commented Sep 13, 2022

pretty neat, I think this is the closest we've come to having something like go-ipld-prime's layering and integrated LinkSystem

@RangerMauve
Copy link
Owner Author

I'm gonna leave some stuff as TODOs, particularly extra tests and the migration to the ipld org.

Gonna try messing around with it in js-ipfs-fetch first

@RangerMauve RangerMauve merged commit 5ea5f3b into default Sep 20, 2022
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.

None yet

2 participants