@tanstack/db 0.2.3 → 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.
- package/dist/cjs/collection.cjs +23 -4
- package/dist/cjs/collection.cjs.map +1 -1
- package/dist/cjs/collection.d.cts +35 -41
- package/dist/cjs/local-only.cjs.map +1 -1
- package/dist/cjs/local-only.d.cts +17 -43
- package/dist/cjs/local-storage.cjs +3 -12
- package/dist/cjs/local-storage.cjs.map +1 -1
- package/dist/cjs/local-storage.d.cts +16 -39
- package/dist/cjs/query/builder/types.d.cts +12 -11
- package/dist/cjs/query/compiler/joins.cjs +4 -3
- package/dist/cjs/query/compiler/joins.cjs.map +1 -1
- package/dist/cjs/query/live/collection-subscriber.cjs +5 -1
- package/dist/cjs/query/live/collection-subscriber.cjs.map +1 -1
- package/dist/cjs/query/live-query-collection.cjs.map +1 -1
- package/dist/cjs/types.d.cts +10 -31
- package/dist/esm/collection.d.ts +35 -41
- package/dist/esm/collection.js +23 -4
- package/dist/esm/collection.js.map +1 -1
- package/dist/esm/local-only.d.ts +17 -43
- package/dist/esm/local-only.js.map +1 -1
- package/dist/esm/local-storage.d.ts +16 -39
- package/dist/esm/local-storage.js +3 -12
- package/dist/esm/local-storage.js.map +1 -1
- package/dist/esm/query/builder/types.d.ts +12 -11
- package/dist/esm/query/compiler/joins.js +4 -3
- package/dist/esm/query/compiler/joins.js.map +1 -1
- package/dist/esm/query/live/collection-subscriber.js +5 -1
- package/dist/esm/query/live/collection-subscriber.js.map +1 -1
- package/dist/esm/query/live-query-collection.js.map +1 -1
- package/dist/esm/types.d.ts +10 -31
- package/package.json +2 -2
- package/src/collection.ts +148 -196
- package/src/local-only.ts +57 -77
- package/src/local-storage.ts +53 -85
- package/src/query/builder/types.ts +52 -16
- package/src/query/compiler/joins.ts +4 -3
- package/src/query/live/collection-subscriber.ts +5 -1
- package/src/query/live-query-collection.ts +1 -1
- package/src/types.ts +25 -55
package/dist/cjs/collection.cjs
CHANGED
|
@@ -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(
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
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,
|