inkandswitch / cambria-project

Schema evolution with bi-directional lenses.
MIT License
611 stars 24 forks source link

Missing property type in reversed `remove` op #10

Open lukasschwab opened 2 years ago

lukasschwab commented 2 years ago

Description

This demo mentioned in README.md seems broken:

Compile back from an updated "simple issue" to a new github issue file:

cat ./demo/simple-issue.json | node ./dist/cli.js -l ./demo/github-arthropod.lens.yml -r -b ./demo/github-issue.json

In practice:

$ cat ./demo/simple-issue.json | node ./dist/cli.js -l ./demo/github-arthropod.lens.yml -r -b ./demo/github-issue.json
./dist/json-schema.js:35
        throw new Error(`Missing property name in addProperty.\nFound:\n${JSON.stringify(property)}`);
        ^

Error: Missing property name in addProperty.
Found:
{"op":"add","name":"labels"}
    at addProperty (./dist/json-schema.js:35:15)
    at applyLensOperation (./dist/json-schema.js:338:20)
    at ./cambria-project/dist/json-schema.js:366:16
    at Array.reduce (<anonymous>)
    at Object.updateSchema (./dist/json-schema.js:363:17)
    at Object.applyLensToDoc (./dist/doc.js:51:40)
    at Object.<anonymous> (./dist/cli.js:25:22)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)

Cause

github-arthropod.lens.yml defines a valid remove op––no type required:

https://github.com/inkandswitch/cambria-project/blob/da8961440cac7eba1c3113488f5bcbc26046620f/demo/github-arthropod.lens.yml#L41-L42

And reverse.ts just swaps in the add op:

https://github.com/inkandswitch/cambria-project/blob/da8961440cac7eba1c3113488f5bcbc26046620f/src/reverse.ts#L30-L34

But an add op must specify a type! It's the type missing, not the name:

https://github.com/inkandswitch/cambria-project/blob/da8961440cac7eba1c3113488f5bcbc26046620f/src/json-schema.ts#L35-L37

Solutions

Let me know if you'd like me to open a PR.

Cool stuff––enjoyed the HYTRADBOI talk!

michielbdejong commented 3 months ago

I ran into this same problem when trying to follow the readme instructions, and looks like https://github.com/lukasschwab/cambria-project/commit/77b602e22ec0d46c12d2861cd9c27ae47cb281ca indeed makes this error disappear.