@tanstack/db 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,7 +11,9 @@ const transactions = require("./transactions.cjs");
11
11
  const errors = require("./errors.cjs");
12
12
  const changeEvents = require("./change-events.cjs");
13
13
  function createCollection(options) {
14
- const collection = new CollectionImpl(options);
14
+ const collection = new CollectionImpl(
15
+ options
16
+ );
15
17
  if (options.utils) {
16
18
  collection.utils = { ...options.utils };
17
19
  } else {
@@ -804,7 +806,10 @@ class CollectionImpl {
804
806
  switch (mutation.type) {
805
807
  case `insert`:
806
808
  case `update`:
807
- this.optimisticUpserts.set(mutation.key, mutation.modified);
809
+ this.optimisticUpserts.set(
810
+ mutation.key,
811
+ mutation.modified
812
+ );
808
813
  this.optimisticDeletes.delete(mutation.key);
809
814
  break;
810
815
  case `delete`:
@@ -1236,7 +1241,12 @@ class CollectionImpl {
1236
1241
  });
1237
1242
  throw new errors.SchemaValidationError(type, typedIssues);
1238
1243
  }
1239
- return data;
1244
+ const validatedMergedData = result2.value;
1245
+ const modifiedKeys = Object.keys(data);
1246
+ const extractedChanges = Object.fromEntries(
1247
+ modifiedKeys.map((k) => [k, validatedMergedData[k]])
1248
+ );
1249
+ return extractedChanges;
1240
1250
  }
1241
1251
  }
1242
1252
  const result = standardSchema[`~standard`].validate(data);
@@ -1317,7 +1327,16 @@ class CollectionImpl {
1317
1327
  mutationId: crypto.randomUUID(),
1318
1328
  original: originalItem,
1319
1329
  modified: modifiedItem,
1320
- changes: validatedUpdatePayload,
1330
+ // Pick the values from modifiedItem based on what's passed in - this is for cases
1331
+ // where a schema has default values or transforms. The modified data has the extra
1332
+ // default or transformed values but for changes, we just want to show the data that
1333
+ // was actually passed in.
1334
+ changes: Object.fromEntries(
1335
+ Object.keys(itemChanges).map((k) => [
1336
+ k,
1337
+ modifiedItem[k]
1338
+ ])
1339
+ ),
1321
1340
  globalKey,
1322
1341
  key,
1323
1342
  metadata: config.metadata,