opral / lix-sdk

1 stars 0 forks source link

merge `change.value` & `change.meta` -> `change.payload` #42

Open samuelstroschein opened 3 weeks ago

samuelstroschein commented 3 weeks ago

Context

Lix has a first-level snapshot approach doesn't seem needed.

Similar insight as in https://github.com/opral/lix-sdk/issues/41: Lix is not responsible for applying changes. Hence, lix does not need to enforce snapshotting. A plugin can do "whatever" as long as plugin.applyChanges() updates a file as a user would expect.

For example, a csv format with no stable ids highly benefits (must have even) a patch based approach that can express:

  1. change abc: row 1 has been deleted
  2. change bca: cell at column 4 and row 1 has been updated to "username"
  3. change bca depends on abc (else a "different" row 1 will be updated)

For file formats with stable ids, snapshotting on the other hand is fine. Applying changes from the last snapshot is good enough as a first version.

Proposal

Introduce change.payload as replacement for change.value and change.meta.

Taking inlang as an example where snapshotting makes things simple, we could move the snapshot into the payload and have the same benefits:

payload = {
  id,
  snapshot, 
  ... other meta information
}
samuelstroschein commented 3 weeks ago

Commit https://github.com/opral/monorepo/commit/c2c2c53660ee197dfa45c7d05841553d0381ebd7 further strengthens the proposal.

I was not able to delete a change during plugin.applyChanges() if no parent exists (it's a create change). The information of the type id was lost given that no snapshot was saved.

We could introduce required id field in a diff reported by a plugin like diff.type_id but file formats with no ids like csv, markdown, html, etc. exist. To achieve generalizability, letting a plugin handle ids seems required.

samuelstroschein commented 1 week ago

I am confident about this change. If lix needs snapshots, we can introduce a plugin.getSnapshot(change) in the future.

samuelstroschein commented 4 days ago

Observations after writing LIXDK-153: