tinybase 8.0.0-beta.1 → 8.0.0-beta.3
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/@types/_internal/store/with-schemas/index.d.ts +2 -2
- package/@types/common/index.d.ts +22 -0
- package/@types/common/with-schemas/index.d.ts +22 -0
- package/@types/middleware/index.d.ts +151 -29
- package/@types/middleware/with-schemas/index.d.ts +174 -29
- package/@types/store/index.d.ts +132 -79
- package/@types/store/with-schemas/index.d.ts +137 -81
- package/checkpoints/index.js +2 -8
- package/checkpoints/with-schemas/index.js +2 -8
- package/index.js +272 -143
- package/mergeable-store/index.js +271 -156
- package/mergeable-store/with-schemas/index.js +271 -156
- package/middleware/index.js +40 -1
- package/middleware/with-schemas/index.js +40 -1
- package/min/checkpoints/index.js +1 -1
- package/min/checkpoints/index.js.gz +0 -0
- package/min/checkpoints/with-schemas/index.js +1 -1
- package/min/checkpoints/with-schemas/index.js.gz +0 -0
- package/min/index.js +1 -1
- package/min/index.js.gz +0 -0
- package/min/mergeable-store/index.js +1 -1
- package/min/mergeable-store/index.js.gz +0 -0
- package/min/mergeable-store/with-schemas/index.js +1 -1
- package/min/mergeable-store/with-schemas/index.js.gz +0 -0
- package/min/middleware/index.js +1 -1
- package/min/middleware/index.js.gz +0 -0
- package/min/middleware/with-schemas/index.js +1 -1
- package/min/middleware/with-schemas/index.js.gz +0 -0
- package/min/omni/index.js +1 -1
- package/min/omni/index.js.gz +0 -0
- package/min/omni/with-schemas/index.js +1 -1
- package/min/omni/with-schemas/index.js.gz +0 -0
- package/min/persisters/index.js +1 -1
- package/min/persisters/index.js.gz +0 -0
- package/min/persisters/persister-automerge/index.js +1 -1
- package/min/persisters/persister-automerge/index.js.gz +0 -0
- package/min/persisters/persister-automerge/with-schemas/index.js +1 -1
- package/min/persisters/persister-automerge/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-browser/index.js +1 -1
- package/min/persisters/persister-browser/index.js.gz +0 -0
- package/min/persisters/persister-browser/with-schemas/index.js +1 -1
- package/min/persisters/persister-browser/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-cr-sqlite-wasm/index.js +1 -1
- package/min/persisters/persister-cr-sqlite-wasm/index.js.gz +0 -0
- package/min/persisters/persister-cr-sqlite-wasm/with-schemas/index.js +1 -1
- package/min/persisters/persister-cr-sqlite-wasm/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-durable-object-sql-storage/index.js +1 -1
- package/min/persisters/persister-durable-object-sql-storage/index.js.gz +0 -0
- package/min/persisters/persister-durable-object-sql-storage/with-schemas/index.js +1 -1
- package/min/persisters/persister-durable-object-sql-storage/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-durable-object-storage/index.js +1 -1
- package/min/persisters/persister-durable-object-storage/index.js.gz +0 -0
- package/min/persisters/persister-durable-object-storage/with-schemas/index.js +1 -1
- package/min/persisters/persister-durable-object-storage/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-electric-sql/index.js +1 -1
- package/min/persisters/persister-electric-sql/index.js.gz +0 -0
- package/min/persisters/persister-electric-sql/with-schemas/index.js +1 -1
- package/min/persisters/persister-electric-sql/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-expo-sqlite/index.js +1 -1
- package/min/persisters/persister-expo-sqlite/index.js.gz +0 -0
- package/min/persisters/persister-expo-sqlite/with-schemas/index.js +1 -1
- package/min/persisters/persister-expo-sqlite/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-file/index.js +1 -1
- package/min/persisters/persister-file/index.js.gz +0 -0
- package/min/persisters/persister-file/with-schemas/index.js +1 -1
- package/min/persisters/persister-file/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-indexed-db/index.js +1 -1
- package/min/persisters/persister-indexed-db/index.js.gz +0 -0
- package/min/persisters/persister-indexed-db/with-schemas/index.js +1 -1
- package/min/persisters/persister-indexed-db/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-libsql/index.js +1 -1
- package/min/persisters/persister-libsql/index.js.gz +0 -0
- package/min/persisters/persister-libsql/with-schemas/index.js +1 -1
- package/min/persisters/persister-libsql/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-partykit-client/index.js +1 -1
- package/min/persisters/persister-partykit-client/index.js.gz +0 -0
- package/min/persisters/persister-partykit-client/with-schemas/index.js +1 -1
- package/min/persisters/persister-partykit-client/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-pglite/index.js +1 -1
- package/min/persisters/persister-pglite/index.js.gz +0 -0
- package/min/persisters/persister-pglite/with-schemas/index.js +1 -1
- package/min/persisters/persister-pglite/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-postgres/index.js +1 -1
- package/min/persisters/persister-postgres/index.js.gz +0 -0
- package/min/persisters/persister-postgres/with-schemas/index.js +1 -1
- package/min/persisters/persister-postgres/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-powersync/index.js +1 -1
- package/min/persisters/persister-powersync/index.js.gz +0 -0
- package/min/persisters/persister-powersync/with-schemas/index.js +1 -1
- package/min/persisters/persister-powersync/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-react-native-mmkv/index.js +1 -1
- package/min/persisters/persister-react-native-mmkv/index.js.gz +0 -0
- package/min/persisters/persister-react-native-mmkv/with-schemas/index.js +1 -1
- package/min/persisters/persister-react-native-mmkv/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-react-native-sqlite/index.js +1 -1
- package/min/persisters/persister-react-native-sqlite/index.js.gz +0 -0
- package/min/persisters/persister-react-native-sqlite/with-schemas/index.js +1 -1
- package/min/persisters/persister-react-native-sqlite/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-remote/index.js +1 -1
- package/min/persisters/persister-remote/index.js.gz +0 -0
- package/min/persisters/persister-remote/with-schemas/index.js +1 -1
- package/min/persisters/persister-remote/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-sqlite-bun/index.js +1 -1
- package/min/persisters/persister-sqlite-bun/index.js.gz +0 -0
- package/min/persisters/persister-sqlite-bun/with-schemas/index.js +1 -1
- package/min/persisters/persister-sqlite-bun/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-sqlite-wasm/index.js +1 -1
- package/min/persisters/persister-sqlite-wasm/index.js.gz +0 -0
- package/min/persisters/persister-sqlite-wasm/with-schemas/index.js +1 -1
- package/min/persisters/persister-sqlite-wasm/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-sqlite3/index.js +1 -1
- package/min/persisters/persister-sqlite3/index.js.gz +0 -0
- package/min/persisters/persister-sqlite3/with-schemas/index.js +1 -1
- package/min/persisters/persister-sqlite3/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-yjs/index.js +1 -1
- package/min/persisters/persister-yjs/index.js.gz +0 -0
- package/min/persisters/persister-yjs/with-schemas/index.js +1 -1
- package/min/persisters/persister-yjs/with-schemas/index.js.gz +0 -0
- package/min/persisters/with-schemas/index.js +1 -1
- package/min/persisters/with-schemas/index.js.gz +0 -0
- package/min/queries/index.js +1 -1
- package/min/queries/index.js.gz +0 -0
- package/min/queries/with-schemas/index.js +1 -1
- package/min/queries/with-schemas/index.js.gz +0 -0
- package/min/schematizers/index.js +1 -1
- package/min/schematizers/index.js.gz +0 -0
- package/min/schematizers/schematizer-arktype/index.js +1 -1
- package/min/schematizers/schematizer-arktype/index.js.gz +0 -0
- package/min/schematizers/schematizer-arktype/with-schemas/index.js +1 -1
- package/min/schematizers/schematizer-arktype/with-schemas/index.js.gz +0 -0
- package/min/schematizers/schematizer-effect/index.js +1 -1
- package/min/schematizers/schematizer-effect/index.js.gz +0 -0
- package/min/schematizers/schematizer-effect/with-schemas/index.js +1 -1
- package/min/schematizers/schematizer-effect/with-schemas/index.js.gz +0 -0
- package/min/schematizers/schematizer-typebox/index.js +1 -1
- package/min/schematizers/schematizer-typebox/index.js.gz +0 -0
- package/min/schematizers/schematizer-typebox/with-schemas/index.js +1 -1
- package/min/schematizers/schematizer-typebox/with-schemas/index.js.gz +0 -0
- package/min/schematizers/schematizer-valibot/index.js +1 -1
- package/min/schematizers/schematizer-valibot/index.js.gz +0 -0
- package/min/schematizers/schematizer-valibot/with-schemas/index.js +1 -1
- package/min/schematizers/schematizer-valibot/with-schemas/index.js.gz +0 -0
- package/min/schematizers/schematizer-yup/index.js +1 -1
- package/min/schematizers/schematizer-yup/index.js.gz +0 -0
- package/min/schematizers/schematizer-yup/with-schemas/index.js +1 -1
- package/min/schematizers/schematizer-yup/with-schemas/index.js.gz +0 -0
- package/min/schematizers/schematizer-zod/index.js +1 -1
- package/min/schematizers/schematizer-zod/index.js.gz +0 -0
- package/min/schematizers/schematizer-zod/with-schemas/index.js +1 -1
- package/min/schematizers/schematizer-zod/with-schemas/index.js.gz +0 -0
- package/min/schematizers/with-schemas/index.js +1 -1
- package/min/schematizers/with-schemas/index.js.gz +0 -0
- package/min/store/index.js +1 -1
- package/min/store/index.js.gz +0 -0
- package/min/store/with-schemas/index.js +1 -1
- package/min/store/with-schemas/index.js.gz +0 -0
- package/min/synchronizers/index.js +1 -1
- package/min/synchronizers/index.js.gz +0 -0
- package/min/synchronizers/synchronizer-broadcast-channel/index.js +1 -1
- package/min/synchronizers/synchronizer-broadcast-channel/index.js.gz +0 -0
- package/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +1 -1
- package/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js.gz +0 -0
- package/min/synchronizers/synchronizer-local/index.js +1 -1
- package/min/synchronizers/synchronizer-local/index.js.gz +0 -0
- package/min/synchronizers/synchronizer-local/with-schemas/index.js +1 -1
- package/min/synchronizers/synchronizer-local/with-schemas/index.js.gz +0 -0
- package/min/synchronizers/synchronizer-ws-client/index.js +1 -1
- package/min/synchronizers/synchronizer-ws-client/index.js.gz +0 -0
- package/min/synchronizers/synchronizer-ws-client/with-schemas/index.js +1 -1
- package/min/synchronizers/synchronizer-ws-client/with-schemas/index.js.gz +0 -0
- package/min/synchronizers/synchronizer-ws-server/index.js +1 -1
- package/min/synchronizers/synchronizer-ws-server/index.js.gz +0 -0
- package/min/synchronizers/synchronizer-ws-server/with-schemas/index.js +1 -1
- package/min/synchronizers/synchronizer-ws-server/with-schemas/index.js.gz +0 -0
- package/min/synchronizers/synchronizer-ws-server-durable-object/index.js +1 -1
- package/min/synchronizers/synchronizer-ws-server-durable-object/index.js.gz +0 -0
- package/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +1 -1
- package/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js.gz +0 -0
- package/min/synchronizers/with-schemas/index.js +1 -1
- package/min/synchronizers/with-schemas/index.js.gz +0 -0
- package/min/ui-react/index.js +1 -1
- package/min/ui-react/index.js.gz +0 -0
- package/min/ui-react/with-schemas/index.js +1 -1
- package/min/ui-react/with-schemas/index.js.gz +0 -0
- package/min/ui-react-dom/index.js +1 -1
- package/min/ui-react-dom/index.js.gz +0 -0
- package/min/ui-react-dom/with-schemas/index.js +1 -1
- package/min/ui-react-dom/with-schemas/index.js.gz +0 -0
- package/min/ui-react-inspector/index.js +1 -1
- package/min/ui-react-inspector/index.js.gz +0 -0
- package/min/ui-react-inspector/with-schemas/index.js +1 -1
- package/min/ui-react-inspector/with-schemas/index.js.gz +0 -0
- package/min/with-schemas/index.js +1 -1
- package/min/with-schemas/index.js.gz +0 -0
- package/omni/index.js +356 -154
- package/omni/with-schemas/index.js +356 -154
- package/package.json +7 -7
- package/persisters/index.js +5 -5
- package/persisters/persister-automerge/index.js +5 -5
- package/persisters/persister-automerge/with-schemas/index.js +5 -5
- package/persisters/persister-browser/index.js +5 -5
- package/persisters/persister-browser/with-schemas/index.js +5 -5
- package/persisters/persister-cr-sqlite-wasm/index.js +5 -5
- package/persisters/persister-cr-sqlite-wasm/with-schemas/index.js +5 -5
- package/persisters/persister-durable-object-sql-storage/index.js +5 -5
- package/persisters/persister-durable-object-sql-storage/with-schemas/index.js +5 -5
- package/persisters/persister-durable-object-storage/index.js +5 -5
- package/persisters/persister-durable-object-storage/with-schemas/index.js +5 -5
- package/persisters/persister-electric-sql/index.js +5 -5
- package/persisters/persister-electric-sql/with-schemas/index.js +5 -5
- package/persisters/persister-expo-sqlite/index.js +5 -5
- package/persisters/persister-expo-sqlite/with-schemas/index.js +5 -5
- package/persisters/persister-file/index.js +5 -5
- package/persisters/persister-file/with-schemas/index.js +5 -5
- package/persisters/persister-indexed-db/index.js +5 -5
- package/persisters/persister-indexed-db/with-schemas/index.js +5 -5
- package/persisters/persister-libsql/index.js +5 -5
- package/persisters/persister-libsql/with-schemas/index.js +5 -5
- package/persisters/persister-partykit-client/index.js +5 -5
- package/persisters/persister-partykit-client/with-schemas/index.js +5 -5
- package/persisters/persister-pglite/index.js +5 -5
- package/persisters/persister-pglite/with-schemas/index.js +5 -5
- package/persisters/persister-postgres/index.js +5 -5
- package/persisters/persister-postgres/with-schemas/index.js +5 -5
- package/persisters/persister-powersync/index.js +5 -5
- package/persisters/persister-powersync/with-schemas/index.js +5 -5
- package/persisters/persister-react-native-mmkv/index.js +5 -5
- package/persisters/persister-react-native-mmkv/with-schemas/index.js +5 -5
- package/persisters/persister-react-native-sqlite/index.js +5 -5
- package/persisters/persister-react-native-sqlite/with-schemas/index.js +5 -5
- package/persisters/persister-remote/index.js +5 -5
- package/persisters/persister-remote/with-schemas/index.js +5 -5
- package/persisters/persister-sqlite-bun/index.js +5 -5
- package/persisters/persister-sqlite-bun/with-schemas/index.js +5 -5
- package/persisters/persister-sqlite-wasm/index.js +5 -5
- package/persisters/persister-sqlite-wasm/with-schemas/index.js +5 -5
- package/persisters/persister-sqlite3/index.js +5 -5
- package/persisters/persister-sqlite3/with-schemas/index.js +5 -5
- package/persisters/persister-yjs/index.js +5 -5
- package/persisters/persister-yjs/with-schemas/index.js +5 -5
- package/persisters/with-schemas/index.js +5 -5
- package/queries/index.js +11 -4
- package/queries/with-schemas/index.js +11 -4
- package/readme.md +3 -3
- package/releases.md +19 -3
- package/schematizers/index.js +9 -1
- package/schematizers/schematizer-arktype/index.js +16 -1
- package/schematizers/schematizer-arktype/with-schemas/index.js +16 -1
- package/schematizers/schematizer-effect/index.js +15 -2
- package/schematizers/schematizer-effect/with-schemas/index.js +15 -2
- package/schematizers/schematizer-typebox/index.js +9 -1
- package/schematizers/schematizer-typebox/with-schemas/index.js +9 -1
- package/schematizers/schematizer-valibot/index.js +17 -2
- package/schematizers/schematizer-valibot/with-schemas/index.js +17 -2
- package/schematizers/schematizer-yup/index.js +9 -1
- package/schematizers/schematizer-yup/with-schemas/index.js +9 -1
- package/schematizers/schematizer-zod/index.js +13 -2
- package/schematizers/schematizer-zod/with-schemas/index.js +13 -2
- package/schematizers/with-schemas/index.js +9 -1
- package/store/index.js +195 -104
- package/store/with-schemas/index.js +195 -104
- package/synchronizers/index.js +5 -5
- package/synchronizers/synchronizer-broadcast-channel/index.js +5 -5
- package/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +5 -5
- package/synchronizers/synchronizer-local/index.js +5 -5
- package/synchronizers/synchronizer-local/with-schemas/index.js +5 -5
- package/synchronizers/synchronizer-ws-client/index.js +5 -5
- package/synchronizers/synchronizer-ws-client/with-schemas/index.js +5 -5
- package/synchronizers/synchronizer-ws-server/index.js +5 -5
- package/synchronizers/synchronizer-ws-server/with-schemas/index.js +5 -5
- package/synchronizers/synchronizer-ws-server-durable-object/index.js +5 -5
- package/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +5 -5
- package/synchronizers/with-schemas/index.js +5 -5
- package/ui-react/index.js +6 -0
- package/ui-react/with-schemas/index.js +6 -0
- package/ui-react-dom/index.js +91 -6
- package/ui-react-dom/with-schemas/index.js +91 -6
- package/ui-react-inspector/index.js +248 -84
- package/ui-react-inspector/with-schemas/index.js +248 -84
- package/with-schemas/index.js +272 -143
package/with-schemas/index.js
CHANGED
|
@@ -4,6 +4,8 @@ const STRING = getTypeOf(EMPTY_STRING);
|
|
|
4
4
|
const BOOLEAN = getTypeOf(true);
|
|
5
5
|
const NUMBER = getTypeOf(0);
|
|
6
6
|
const FUNCTION = getTypeOf(getTypeOf);
|
|
7
|
+
const OBJECT = 'object';
|
|
8
|
+
const ARRAY = 'array';
|
|
7
9
|
const TYPE = 'type';
|
|
8
10
|
const DEFAULT = 'default';
|
|
9
11
|
const ALLOW_NULL = 'allowNull';
|
|
@@ -33,6 +35,7 @@ const VALUE = 'Value';
|
|
|
33
35
|
const VALUES = VALUE + 's';
|
|
34
36
|
const VALUE_IDS = VALUE + IDS;
|
|
35
37
|
const TRANSACTION = 'Transaction';
|
|
38
|
+
const JSON_PREFIX = '\uFFFD';
|
|
36
39
|
const id = (key) => EMPTY_STRING + key;
|
|
37
40
|
const strStartsWith = (str, prefix) => str.startsWith(prefix);
|
|
38
41
|
const strEndsWith = (str, suffix) => str.endsWith(suffix);
|
|
@@ -131,6 +134,7 @@ const isObject = (obj) =>
|
|
|
131
134
|
const objIds = object.keys;
|
|
132
135
|
const objFreeze = object.freeze;
|
|
133
136
|
const objNew = (entries = []) => object.fromEntries(entries);
|
|
137
|
+
const objMerge = (...objs) => object.assign({}, ...objs);
|
|
134
138
|
const objGet = (obj, id) => ifNotUndefined(obj, (obj2) => obj2[id]);
|
|
135
139
|
const objHas = (obj, id) => id in obj;
|
|
136
140
|
const objDel = (obj, id) => {
|
|
@@ -559,18 +563,12 @@ const createCheckpoints = getCreateFunction(
|
|
|
559
563
|
collForEach(cellsDelta2, (table, tableId) =>
|
|
560
564
|
collForEach(table, (row, rowId) =>
|
|
561
565
|
collForEach(row, (oldNew, cellId) =>
|
|
562
|
-
store.
|
|
563
|
-
tableId,
|
|
564
|
-
rowId,
|
|
565
|
-
cellId,
|
|
566
|
-
oldNew[oldOrNew],
|
|
567
|
-
true,
|
|
568
|
-
),
|
|
566
|
+
store._[5](tableId, rowId, cellId, oldNew[oldOrNew], true),
|
|
569
567
|
),
|
|
570
568
|
),
|
|
571
569
|
);
|
|
572
570
|
collForEach(valuesDelta2, (oldNew, valueId) =>
|
|
573
|
-
store.
|
|
571
|
+
store._[6](valueId, oldNew[oldOrNew], true),
|
|
574
572
|
);
|
|
575
573
|
});
|
|
576
574
|
listening = 1;
|
|
@@ -1160,6 +1158,12 @@ const getCellOrValueType = (cellOrValue) => {
|
|
|
1160
1158
|
if (isNull(cellOrValue)) {
|
|
1161
1159
|
return NULL;
|
|
1162
1160
|
}
|
|
1161
|
+
if (isArray(cellOrValue)) {
|
|
1162
|
+
return ARRAY;
|
|
1163
|
+
}
|
|
1164
|
+
if (isObject(cellOrValue)) {
|
|
1165
|
+
return OBJECT;
|
|
1166
|
+
}
|
|
1163
1167
|
const type = getTypeOf(cellOrValue);
|
|
1164
1168
|
return isTypeStringOrBoolean(type) ||
|
|
1165
1169
|
(type == NUMBER && isFiniteNumber(cellOrValue))
|
|
@@ -1168,9 +1172,14 @@ const getCellOrValueType = (cellOrValue) => {
|
|
|
1168
1172
|
};
|
|
1169
1173
|
const isCellOrValueOrUndefined = (cellOrValue) =>
|
|
1170
1174
|
isUndefined(cellOrValue) || !isUndefined(getCellOrValueType(cellOrValue));
|
|
1175
|
+
const isJsonType = (type) => type == OBJECT || type == ARRAY;
|
|
1176
|
+
const encodeIfJson = (value) =>
|
|
1177
|
+
isObject(value) || isArray(value) ? JSON_PREFIX + jsonString(value) : value;
|
|
1178
|
+
const isEncodedJson = (value) => isString(value) && value[0] == JSON_PREFIX;
|
|
1179
|
+
const decodeIfJson = (raw, _id, encoded) =>
|
|
1180
|
+
!encoded && isEncodedJson(raw) ? jsonParse(slice(raw, 1)) : raw;
|
|
1171
1181
|
|
|
1172
1182
|
const stampClone = ([value, hlc]) => stampNew(value, hlc);
|
|
1173
|
-
const stampCloneWithHash = ([value, hlc, hash]) => [value, hlc, hash];
|
|
1174
1183
|
const stampNew = (value, hlc) => (hlc ? [value, hlc] : [value]);
|
|
1175
1184
|
const stampNewWithHash = (value, hlc, hash) => [value, hlc, hash];
|
|
1176
1185
|
const getStampHash = (stamp) => stamp[2];
|
|
@@ -1187,10 +1196,11 @@ const stampUpdate = (stamp, hlc, hash) => {
|
|
|
1187
1196
|
};
|
|
1188
1197
|
const stampNewObj = (hlc = EMPTY_STRING) => stampNew(objNew(), hlc);
|
|
1189
1198
|
const stampNewMap = (hlc = EMPTY_STRING) => [mapNew(), hlc, 0];
|
|
1190
|
-
const stampMapToObjWithHash = (
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1199
|
+
const stampMapToObjWithHash = ([map, hlc, hash], mapper) => [
|
|
1200
|
+
mapToObj(map, mapper),
|
|
1201
|
+
hlc,
|
|
1202
|
+
hash,
|
|
1203
|
+
];
|
|
1194
1204
|
const stampMapToObjWithoutHash = ([map, hlc], mapper = stampClone) =>
|
|
1195
1205
|
stampNew(mapToObj(map, mapper), hlc);
|
|
1196
1206
|
const stampValidate = (stamp, validateThing) =>
|
|
@@ -1297,15 +1307,19 @@ const createStore = () => {
|
|
|
1297
1307
|
return false;
|
|
1298
1308
|
}
|
|
1299
1309
|
const type = schema[TYPE];
|
|
1300
|
-
if (!isTypeStringOrBoolean(type) && type != NUMBER) {
|
|
1310
|
+
if (!isTypeStringOrBoolean(type) && type != NUMBER && !isJsonType(type)) {
|
|
1301
1311
|
return false;
|
|
1302
1312
|
}
|
|
1303
1313
|
const defaultValue = schema[DEFAULT];
|
|
1304
1314
|
if (isNull(defaultValue) && !schema[ALLOW_NULL]) {
|
|
1305
1315
|
return false;
|
|
1306
1316
|
}
|
|
1307
|
-
if (!isNull(defaultValue)
|
|
1308
|
-
|
|
1317
|
+
if (!isNull(defaultValue)) {
|
|
1318
|
+
if (getCellOrValueType(defaultValue) != type) {
|
|
1319
|
+
objDel(schema, DEFAULT);
|
|
1320
|
+
} else {
|
|
1321
|
+
schema[DEFAULT] = encodeIfJson(defaultValue);
|
|
1322
|
+
}
|
|
1309
1323
|
}
|
|
1310
1324
|
return true;
|
|
1311
1325
|
};
|
|
@@ -1345,20 +1359,22 @@ const createStore = () => {
|
|
|
1345
1359
|
? cellSchema[ALLOW_NULL]
|
|
1346
1360
|
? cell
|
|
1347
1361
|
: cellInvalid(tableId, rowId, cellId, cell, cellSchema[DEFAULT])
|
|
1348
|
-
: getCellOrValueType(cell)
|
|
1349
|
-
? cell
|
|
1350
|
-
:
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1362
|
+
: getCellOrValueType(cell) === cellSchema[TYPE]
|
|
1363
|
+
? encodeIfJson(cell)
|
|
1364
|
+
: isJsonType(cellSchema[TYPE]) && isEncodedJson(cell)
|
|
1365
|
+
? cell
|
|
1366
|
+
: cellInvalid(
|
|
1367
|
+
tableId,
|
|
1368
|
+
rowId,
|
|
1369
|
+
cellId,
|
|
1370
|
+
cell,
|
|
1371
|
+
cellSchema[DEFAULT],
|
|
1372
|
+
),
|
|
1357
1373
|
() => cellInvalid(tableId, rowId, cellId, cell),
|
|
1358
1374
|
)
|
|
1359
1375
|
: isUndefined(getCellOrValueType(cell))
|
|
1360
1376
|
? cellInvalid(tableId, rowId, cellId, cell)
|
|
1361
|
-
: cell;
|
|
1377
|
+
: encodeIfJson(cell);
|
|
1362
1378
|
const validateValues = (values, skipDefaults) =>
|
|
1363
1379
|
objValidate(
|
|
1364
1380
|
skipDefaults ? values : addDefaultsToValues(values),
|
|
@@ -1382,14 +1398,16 @@ const createStore = () => {
|
|
|
1382
1398
|
? valueSchema[ALLOW_NULL]
|
|
1383
1399
|
? value
|
|
1384
1400
|
: valueInvalid(valueId, value, valueSchema[DEFAULT])
|
|
1385
|
-
: getCellOrValueType(value)
|
|
1386
|
-
? value
|
|
1387
|
-
:
|
|
1401
|
+
: getCellOrValueType(value) === valueSchema[TYPE]
|
|
1402
|
+
? encodeIfJson(value)
|
|
1403
|
+
: isJsonType(valueSchema[TYPE]) && isEncodedJson(value)
|
|
1404
|
+
? value
|
|
1405
|
+
: valueInvalid(valueId, value, valueSchema[DEFAULT]),
|
|
1388
1406
|
() => valueInvalid(valueId, value),
|
|
1389
1407
|
)
|
|
1390
1408
|
: isUndefined(getCellOrValueType(value))
|
|
1391
1409
|
? valueInvalid(valueId, value)
|
|
1392
|
-
: value;
|
|
1410
|
+
: encodeIfJson(value);
|
|
1393
1411
|
const addDefaultsToRow = (row, tableId, rowId) => {
|
|
1394
1412
|
ifNotUndefined(
|
|
1395
1413
|
mapGet(tablesSchemaRowCache, tableId),
|
|
@@ -1812,13 +1830,21 @@ const createStore = () => {
|
|
|
1812
1830
|
const getCellChange = (tableId, rowId, cellId) =>
|
|
1813
1831
|
ifNotUndefined(
|
|
1814
1832
|
mapGet(mapGet(mapGet(changedCells, tableId), rowId), cellId),
|
|
1815
|
-
([oldCell, newCell]) => [
|
|
1833
|
+
([oldCell, newCell]) => [
|
|
1834
|
+
true,
|
|
1835
|
+
decodeIfJson(oldCell),
|
|
1836
|
+
decodeIfJson(newCell),
|
|
1837
|
+
],
|
|
1816
1838
|
() => [false, ...pairNew(getCell(tableId, rowId, cellId))],
|
|
1817
1839
|
);
|
|
1818
1840
|
const getValueChange = (valueId) =>
|
|
1819
1841
|
ifNotUndefined(
|
|
1820
1842
|
mapGet(changedValues, valueId),
|
|
1821
|
-
([oldValue, newValue]) => [
|
|
1843
|
+
([oldValue, newValue]) => [
|
|
1844
|
+
true,
|
|
1845
|
+
decodeIfJson(oldValue),
|
|
1846
|
+
decodeIfJson(newValue),
|
|
1847
|
+
],
|
|
1822
1848
|
() => [false, ...pairNew(getValue(valueId))],
|
|
1823
1849
|
);
|
|
1824
1850
|
const callInvalidCellListeners = (mutator) =>
|
|
@@ -1863,6 +1889,10 @@ const createStore = () => {
|
|
|
1863
1889
|
return 1;
|
|
1864
1890
|
}
|
|
1865
1891
|
};
|
|
1892
|
+
const clonedChangedCells = (changedCells2) =>
|
|
1893
|
+
mapClone(changedCells2, (map) =>
|
|
1894
|
+
mapClone(map, (map2) => mapClone(map2, pairClone)),
|
|
1895
|
+
);
|
|
1866
1896
|
const callTabularListenersForChanges = (mutator) => {
|
|
1867
1897
|
const hasHasTablesListeners = !collIsEmpty(hasTablesListeners[mutator]);
|
|
1868
1898
|
const hasSortedRowIdListeners = !collIsEmpty(
|
|
@@ -1894,9 +1924,7 @@ const createStore = () => {
|
|
|
1894
1924
|
mapClone(changedRowCount),
|
|
1895
1925
|
mapClone2(changedRowIds),
|
|
1896
1926
|
mapClone3(changedCellIds),
|
|
1897
|
-
|
|
1898
|
-
mapClone(map, (map2) => mapClone(map2, pairClone)),
|
|
1899
|
-
),
|
|
1927
|
+
clonedChangedCells(changedCells),
|
|
1900
1928
|
]
|
|
1901
1929
|
: [
|
|
1902
1930
|
changedTableIds,
|
|
@@ -1992,8 +2020,8 @@ const createStore = () => {
|
|
|
1992
2020
|
callListeners(
|
|
1993
2021
|
cellListeners[mutator],
|
|
1994
2022
|
[tableId, rowId, cellId],
|
|
1995
|
-
newCell,
|
|
1996
|
-
oldCell,
|
|
2023
|
+
decodeIfJson(newCell),
|
|
2024
|
+
decodeIfJson(oldCell),
|
|
1997
2025
|
getCellChange,
|
|
1998
2026
|
);
|
|
1999
2027
|
tablesChanged = tableChanged = rowChanged = 1;
|
|
@@ -2049,8 +2077,8 @@ const createStore = () => {
|
|
|
2049
2077
|
callListeners(
|
|
2050
2078
|
valueListeners[mutator],
|
|
2051
2079
|
[valueId],
|
|
2052
|
-
newValue,
|
|
2053
|
-
oldValue,
|
|
2080
|
+
decodeIfJson(newValue),
|
|
2081
|
+
decodeIfJson(oldValue),
|
|
2054
2082
|
getValueChange,
|
|
2055
2083
|
);
|
|
2056
2084
|
valuesChanged = 1;
|
|
@@ -2087,10 +2115,42 @@ const createStore = () => {
|
|
|
2087
2115
|
[getTableIds],
|
|
2088
2116
|
);
|
|
2089
2117
|
};
|
|
2118
|
+
const getTransactionChangesImpl = (encoded = false) => [
|
|
2119
|
+
mapToObj(
|
|
2120
|
+
changedCells,
|
|
2121
|
+
(table, tableId) =>
|
|
2122
|
+
mapGet(changedTableIds, tableId) === -1
|
|
2123
|
+
? void 0
|
|
2124
|
+
: mapToObj(
|
|
2125
|
+
table,
|
|
2126
|
+
(row, rowId) =>
|
|
2127
|
+
mapGet(mapGet(changedRowIds, tableId), rowId) === -1
|
|
2128
|
+
? void 0
|
|
2129
|
+
: mapToObj(
|
|
2130
|
+
row,
|
|
2131
|
+
([, newCell]) =>
|
|
2132
|
+
decodeIfJson(newCell, EMPTY_STRING, encoded),
|
|
2133
|
+
(changedCell) => pairIsEqual(changedCell),
|
|
2134
|
+
),
|
|
2135
|
+
collIsEmpty,
|
|
2136
|
+
objIsEmpty,
|
|
2137
|
+
),
|
|
2138
|
+
collIsEmpty,
|
|
2139
|
+
objIsEmpty,
|
|
2140
|
+
),
|
|
2141
|
+
mapToObj(
|
|
2142
|
+
changedValues,
|
|
2143
|
+
([, newValue]) => decodeIfJson(newValue, EMPTY_STRING, encoded),
|
|
2144
|
+
(changedValue) => pairIsEqual(changedValue),
|
|
2145
|
+
),
|
|
2146
|
+
1,
|
|
2147
|
+
];
|
|
2090
2148
|
const getContent = () => [getTables(), getValues()];
|
|
2091
|
-
const
|
|
2149
|
+
const getEncodedContent = () => [mapToObj3(tablesMap), mapToObj(valuesMap)];
|
|
2150
|
+
const getTables = () => mapToObj3(tablesMap, decodeIfJson);
|
|
2092
2151
|
const getTableIds = () => mapKeys(tablesMap);
|
|
2093
|
-
const getTable = (tableId) =>
|
|
2152
|
+
const getTable = (tableId) =>
|
|
2153
|
+
mapToObj2(mapGet(tablesMap, id(tableId)), decodeIfJson);
|
|
2094
2154
|
const getTableCellIds = (tableId) =>
|
|
2095
2155
|
mapKeys(mapGet(tableCellIds, id(tableId)));
|
|
2096
2156
|
const getRowCount = (tableId) => collSize(mapGet(tablesMap, id(tableId)));
|
|
@@ -2126,14 +2186,16 @@ const createStore = () => {
|
|
|
2126
2186
|
([, rowId]) => rowId,
|
|
2127
2187
|
);
|
|
2128
2188
|
const getRow = (tableId, rowId) =>
|
|
2129
|
-
mapToObj(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)));
|
|
2189
|
+
mapToObj(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)), decodeIfJson);
|
|
2130
2190
|
const getCellIds = (tableId, rowId) =>
|
|
2131
2191
|
mapKeys(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)));
|
|
2132
2192
|
const getCell = (tableId, rowId, cellId) =>
|
|
2133
|
-
|
|
2134
|
-
|
|
2193
|
+
decodeIfJson(
|
|
2194
|
+
mapGet(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)), id(cellId)),
|
|
2195
|
+
);
|
|
2196
|
+
const getValues = () => mapToObj(valuesMap, decodeIfJson);
|
|
2135
2197
|
const getValueIds = () => mapKeys(valuesMap);
|
|
2136
|
-
const getValue = (valueId) => mapGet(valuesMap, id(valueId));
|
|
2198
|
+
const getValue = (valueId) => decodeIfJson(mapGet(valuesMap, id(valueId)));
|
|
2137
2199
|
const hasTables = () => !collIsEmpty(tablesMap);
|
|
2138
2200
|
const hasTable = (tableId) => collHas(tablesMap, id(tableId));
|
|
2139
2201
|
const hasTableCell = (tableId, cellId) =>
|
|
@@ -2420,35 +2482,8 @@ const createStore = () => {
|
|
|
2420
2482
|
}
|
|
2421
2483
|
return store;
|
|
2422
2484
|
};
|
|
2423
|
-
const getTransactionChanges = () =>
|
|
2424
|
-
|
|
2425
|
-
changedCells,
|
|
2426
|
-
(table, tableId) =>
|
|
2427
|
-
mapGet(changedTableIds, tableId) === -1
|
|
2428
|
-
? void 0
|
|
2429
|
-
: mapToObj(
|
|
2430
|
-
table,
|
|
2431
|
-
(row, rowId) =>
|
|
2432
|
-
mapGet(mapGet(changedRowIds, tableId), rowId) === -1
|
|
2433
|
-
? void 0
|
|
2434
|
-
: mapToObj(
|
|
2435
|
-
row,
|
|
2436
|
-
([, newCell]) => newCell,
|
|
2437
|
-
(changedCell) => pairIsEqual(changedCell),
|
|
2438
|
-
),
|
|
2439
|
-
collIsEmpty,
|
|
2440
|
-
objIsEmpty,
|
|
2441
|
-
),
|
|
2442
|
-
collIsEmpty,
|
|
2443
|
-
objIsEmpty,
|
|
2444
|
-
),
|
|
2445
|
-
mapToObj(
|
|
2446
|
-
changedValues,
|
|
2447
|
-
([, newValue]) => newValue,
|
|
2448
|
-
(changedValue) => pairIsEqual(changedValue),
|
|
2449
|
-
),
|
|
2450
|
-
1,
|
|
2451
|
-
];
|
|
2485
|
+
const getTransactionChanges = () => getTransactionChangesImpl();
|
|
2486
|
+
const getEncodedTransactionChanges = () => getTransactionChangesImpl(true);
|
|
2452
2487
|
const getTransactionLog = () => [
|
|
2453
2488
|
!collIsEmpty(changedCells),
|
|
2454
2489
|
!collIsEmpty(changedValues),
|
|
@@ -2461,6 +2496,37 @@ const createStore = () => {
|
|
|
2461
2496
|
mapToObj3(changedCellIds),
|
|
2462
2497
|
mapToObj(changedValueIds),
|
|
2463
2498
|
];
|
|
2499
|
+
const doDidSetRows = () => {
|
|
2500
|
+
if (middleware[14]) {
|
|
2501
|
+
const changedCells2 = clonedChangedCells(changedCells);
|
|
2502
|
+
collForEach(changedCells2, (rows, tableId) =>
|
|
2503
|
+
collForEach(rows, (cells, rowId) => {
|
|
2504
|
+
if (
|
|
2505
|
+
!arrayEvery(
|
|
2506
|
+
collValues(cells),
|
|
2507
|
+
([oldCell, newCell]) => oldCell === newCell,
|
|
2508
|
+
)
|
|
2509
|
+
) {
|
|
2510
|
+
const newRow = getRow(tableId, rowId);
|
|
2511
|
+
const oldRow = objMerge(newRow);
|
|
2512
|
+
collForEach(cells, ([oldCell], cellId) =>
|
|
2513
|
+
isUndefined(oldCell)
|
|
2514
|
+
? objDel(oldRow, cellId)
|
|
2515
|
+
: (oldRow[cellId] = oldCell),
|
|
2516
|
+
);
|
|
2517
|
+
const didSetRow = middleware[14](tableId, rowId, oldRow, newRow);
|
|
2518
|
+
if (!objIsEqual(didSetRow, newRow)) {
|
|
2519
|
+
const setOrDelRow = objMap(newRow, () => void 0);
|
|
2520
|
+
objMap(didSetRow, (cell, cellId) => (setOrDelRow[cellId] = cell));
|
|
2521
|
+
objMap(setOrDelRow, (cell, cellId) =>
|
|
2522
|
+
setOrDelCell(tableId, rowId, cellId, cell, true),
|
|
2523
|
+
);
|
|
2524
|
+
}
|
|
2525
|
+
}
|
|
2526
|
+
}),
|
|
2527
|
+
);
|
|
2528
|
+
}
|
|
2529
|
+
};
|
|
2464
2530
|
const finishTransaction = (doRollback) => {
|
|
2465
2531
|
if (transactions > 0) {
|
|
2466
2532
|
transactions--;
|
|
@@ -2470,6 +2536,7 @@ const createStore = () => {
|
|
|
2470
2536
|
callInvalidCellListeners(1);
|
|
2471
2537
|
if (!collIsEmpty(changedCells)) {
|
|
2472
2538
|
callTabularListenersForChanges(1);
|
|
2539
|
+
doDidSetRows();
|
|
2473
2540
|
}
|
|
2474
2541
|
callInvalidValueListeners(1);
|
|
2475
2542
|
if (!collIsEmpty(changedValues)) {
|
|
@@ -2530,7 +2597,9 @@ const createStore = () => {
|
|
|
2530
2597
|
tableCallback(tableId, (rowCallback) =>
|
|
2531
2598
|
collForEach(tableMap, (rowMap, rowId) =>
|
|
2532
2599
|
rowCallback(rowId, (cellCallback) =>
|
|
2533
|
-
mapForEach(rowMap,
|
|
2600
|
+
mapForEach(rowMap, (cellId, cell) =>
|
|
2601
|
+
cellCallback(cellId, decodeIfJson(cell)),
|
|
2602
|
+
),
|
|
2534
2603
|
),
|
|
2535
2604
|
),
|
|
2536
2605
|
),
|
|
@@ -2539,11 +2608,21 @@ const createStore = () => {
|
|
|
2539
2608
|
mapForEach(mapGet(tableCellIds, id(tableId)), tableCellCallback);
|
|
2540
2609
|
const forEachRow = (tableId, rowCallback) =>
|
|
2541
2610
|
collForEach(mapGet(tablesMap, id(tableId)), (rowMap, rowId) =>
|
|
2542
|
-
rowCallback(rowId, (cellCallback) =>
|
|
2611
|
+
rowCallback(rowId, (cellCallback) =>
|
|
2612
|
+
mapForEach(rowMap, (cellId, cell) =>
|
|
2613
|
+
cellCallback(cellId, decodeIfJson(cell)),
|
|
2614
|
+
),
|
|
2615
|
+
),
|
|
2543
2616
|
);
|
|
2544
2617
|
const forEachCell = (tableId, rowId, cellCallback) =>
|
|
2545
|
-
mapForEach(
|
|
2546
|
-
|
|
2618
|
+
mapForEach(
|
|
2619
|
+
mapGet(mapGet(tablesMap, id(tableId)), id(rowId)),
|
|
2620
|
+
(cellId, cell) => cellCallback(cellId, decodeIfJson(cell)),
|
|
2621
|
+
);
|
|
2622
|
+
const forEachValue = (valueCallback) =>
|
|
2623
|
+
mapForEach(valuesMap, (valueId, value) =>
|
|
2624
|
+
valueCallback(valueId, decodeIfJson(value)),
|
|
2625
|
+
);
|
|
2547
2626
|
const addSortedRowIdsListener = (
|
|
2548
2627
|
tableIdOrArgs,
|
|
2549
2628
|
cellIdOrListener,
|
|
@@ -2628,6 +2707,7 @@ const createStore = () => {
|
|
|
2628
2707
|
willDelValues,
|
|
2629
2708
|
willDelValue,
|
|
2630
2709
|
willApplyChanges,
|
|
2710
|
+
didSetRow,
|
|
2631
2711
|
) =>
|
|
2632
2712
|
(middleware = [
|
|
2633
2713
|
willSetContent,
|
|
@@ -2644,6 +2724,7 @@ const createStore = () => {
|
|
|
2644
2724
|
willDelValues,
|
|
2645
2725
|
willDelValue,
|
|
2646
2726
|
willApplyChanges,
|
|
2727
|
+
didSetRow,
|
|
2647
2728
|
]);
|
|
2648
2729
|
const setInternalListeners = (
|
|
2649
2730
|
preStartTransaction,
|
|
@@ -2733,14 +2814,17 @@ const createStore = () => {
|
|
|
2733
2814
|
delListener,
|
|
2734
2815
|
getListenerStats,
|
|
2735
2816
|
isMergeable: () => false,
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2817
|
+
_: [
|
|
2818
|
+
createStore,
|
|
2819
|
+
addListener,
|
|
2820
|
+
callListeners,
|
|
2821
|
+
setInternalListeners,
|
|
2822
|
+
setMiddleware,
|
|
2823
|
+
setOrDelCell,
|
|
2824
|
+
setOrDelValue,
|
|
2825
|
+
getEncodedContent,
|
|
2826
|
+
getEncodedTransactionChanges,
|
|
2827
|
+
],
|
|
2744
2828
|
};
|
|
2745
2829
|
objMap(
|
|
2746
2830
|
{
|
|
@@ -3055,14 +3139,78 @@ const createMergeableStore = (uniqueId, getNow) => {
|
|
|
3055
3139
|
]);
|
|
3056
3140
|
}
|
|
3057
3141
|
};
|
|
3058
|
-
const
|
|
3142
|
+
const getMergeableContentImpl = (encoded = false) => [
|
|
3059
3143
|
stampMapToObjWithHash(contentStampMap[0], (tableStampMap) =>
|
|
3060
3144
|
stampMapToObjWithHash(tableStampMap, (rowStampMap) =>
|
|
3061
|
-
stampMapToObjWithHash(rowStampMap)
|
|
3145
|
+
stampMapToObjWithHash(rowStampMap, ([cell, hlc, hash]) => [
|
|
3146
|
+
decodeIfJson(cell, EMPTY_STRING, encoded),
|
|
3147
|
+
hlc,
|
|
3148
|
+
hash,
|
|
3149
|
+
]),
|
|
3062
3150
|
),
|
|
3063
3151
|
),
|
|
3064
|
-
stampMapToObjWithHash(contentStampMap[1])
|
|
3152
|
+
stampMapToObjWithHash(contentStampMap[1], ([value, hlc, hash]) => [
|
|
3153
|
+
decodeIfJson(value, EMPTY_STRING, encoded),
|
|
3154
|
+
hlc,
|
|
3155
|
+
hash,
|
|
3156
|
+
]),
|
|
3065
3157
|
];
|
|
3158
|
+
const getTransactionMergeableChangesImpl = (withHashes, encoded = false) => {
|
|
3159
|
+
const [
|
|
3160
|
+
[tableStampMaps, tablesHlc, tablesHash],
|
|
3161
|
+
[valueStampMaps, valuesHlc, valuesHash],
|
|
3162
|
+
] = contentStampMap;
|
|
3163
|
+
const newStamp = withHashes ? stampNewWithHash : stampNew;
|
|
3164
|
+
const tablesObj = {};
|
|
3165
|
+
collForEach(touchedCells, (touchedTable, tableId) =>
|
|
3166
|
+
ifNotUndefined(
|
|
3167
|
+
mapGet(tableStampMaps, tableId),
|
|
3168
|
+
([rowStampMaps, tableHlc, tableHash]) => {
|
|
3169
|
+
const tableObj = {};
|
|
3170
|
+
collForEach(touchedTable, (touchedRow, rowId) =>
|
|
3171
|
+
ifNotUndefined(
|
|
3172
|
+
mapGet(rowStampMaps, rowId),
|
|
3173
|
+
([cellStampMaps, rowHlc, rowHash]) => {
|
|
3174
|
+
const rowObj = {};
|
|
3175
|
+
collForEach(touchedRow, (cellId) => {
|
|
3176
|
+
ifNotUndefined(
|
|
3177
|
+
mapGet(cellStampMaps, cellId),
|
|
3178
|
+
([cell, time, hash]) =>
|
|
3179
|
+
(rowObj[cellId] = newStamp(
|
|
3180
|
+
encoded ? cell : decodeIfJson(cell),
|
|
3181
|
+
time,
|
|
3182
|
+
hash,
|
|
3183
|
+
)),
|
|
3184
|
+
);
|
|
3185
|
+
});
|
|
3186
|
+
tableObj[rowId] = newStamp(rowObj, rowHlc, rowHash);
|
|
3187
|
+
},
|
|
3188
|
+
),
|
|
3189
|
+
);
|
|
3190
|
+
tablesObj[tableId] = newStamp(tableObj, tableHlc, tableHash);
|
|
3191
|
+
},
|
|
3192
|
+
),
|
|
3193
|
+
);
|
|
3194
|
+
const valuesObj = {};
|
|
3195
|
+
collForEach(touchedValues, (valueId) =>
|
|
3196
|
+
ifNotUndefined(
|
|
3197
|
+
mapGet(valueStampMaps, valueId),
|
|
3198
|
+
([value, time, hash]) =>
|
|
3199
|
+
(valuesObj[valueId] = newStamp(
|
|
3200
|
+
encoded ? value : decodeIfJson(value),
|
|
3201
|
+
time,
|
|
3202
|
+
hash,
|
|
3203
|
+
)),
|
|
3204
|
+
),
|
|
3205
|
+
);
|
|
3206
|
+
return [
|
|
3207
|
+
newStamp(tablesObj, tablesHlc, tablesHash),
|
|
3208
|
+
newStamp(valuesObj, valuesHlc, valuesHash),
|
|
3209
|
+
1,
|
|
3210
|
+
];
|
|
3211
|
+
};
|
|
3212
|
+
const getMergeableContent = () => getMergeableContentImpl();
|
|
3213
|
+
const getEncodedMergeableContent = () => getMergeableContentImpl(true);
|
|
3066
3214
|
const getMergeableContentHashes = () => [
|
|
3067
3215
|
contentStampMap[0][2],
|
|
3068
3216
|
contentStampMap[1][2],
|
|
@@ -3202,52 +3350,10 @@ const createMergeableStore = (uniqueId, getNow) => {
|
|
|
3202
3350
|
});
|
|
3203
3351
|
return mergeableStore;
|
|
3204
3352
|
};
|
|
3205
|
-
const getTransactionMergeableChanges = (withHashes = false) =>
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
] = contentStampMap;
|
|
3210
|
-
const newStamp = withHashes ? stampNewWithHash : stampNew;
|
|
3211
|
-
const tablesObj = {};
|
|
3212
|
-
collForEach(touchedCells, (touchedTable, tableId) =>
|
|
3213
|
-
ifNotUndefined(
|
|
3214
|
-
mapGet(tableStampMaps, tableId),
|
|
3215
|
-
([rowStampMaps, tableHlc, tableHash]) => {
|
|
3216
|
-
const tableObj = {};
|
|
3217
|
-
collForEach(touchedTable, (touchedRow, rowId) =>
|
|
3218
|
-
ifNotUndefined(
|
|
3219
|
-
mapGet(rowStampMaps, rowId),
|
|
3220
|
-
([cellStampMaps, rowHlc, rowHash]) => {
|
|
3221
|
-
const rowObj = {};
|
|
3222
|
-
collForEach(touchedRow, (cellId) => {
|
|
3223
|
-
ifNotUndefined(
|
|
3224
|
-
mapGet(cellStampMaps, cellId),
|
|
3225
|
-
([cell, time, hash]) =>
|
|
3226
|
-
(rowObj[cellId] = newStamp(cell, time, hash)),
|
|
3227
|
-
);
|
|
3228
|
-
});
|
|
3229
|
-
tableObj[rowId] = newStamp(rowObj, rowHlc, rowHash);
|
|
3230
|
-
},
|
|
3231
|
-
),
|
|
3232
|
-
);
|
|
3233
|
-
tablesObj[tableId] = newStamp(tableObj, tableHlc, tableHash);
|
|
3234
|
-
},
|
|
3235
|
-
),
|
|
3236
|
-
);
|
|
3237
|
-
const valuesObj = {};
|
|
3238
|
-
collForEach(touchedValues, (valueId) =>
|
|
3239
|
-
ifNotUndefined(
|
|
3240
|
-
mapGet(valueStampMaps, valueId),
|
|
3241
|
-
([value, time, hash]) =>
|
|
3242
|
-
(valuesObj[valueId] = newStamp(value, time, hash)),
|
|
3243
|
-
),
|
|
3244
|
-
);
|
|
3245
|
-
return [
|
|
3246
|
-
newStamp(tablesObj, tablesHlc, tablesHash),
|
|
3247
|
-
newStamp(valuesObj, valuesHlc, valuesHash),
|
|
3248
|
-
1,
|
|
3249
|
-
];
|
|
3250
|
-
};
|
|
3353
|
+
const getTransactionMergeableChanges = (withHashes = false) =>
|
|
3354
|
+
getTransactionMergeableChangesImpl(withHashes);
|
|
3355
|
+
const getEncodedTransactionMergeableChanges = (withHashes) =>
|
|
3356
|
+
getTransactionMergeableChangesImpl(withHashes, true);
|
|
3251
3357
|
const applyMergeableChanges = (mergeableChanges) =>
|
|
3252
3358
|
disableListeningToRawStoreChanges(() =>
|
|
3253
3359
|
store.applyChanges(mergeContentOrChanges(mergeableChanges)),
|
|
@@ -3279,10 +3385,13 @@ const createMergeableStore = (uniqueId, getNow) => {
|
|
|
3279
3385
|
getTransactionMergeableChanges,
|
|
3280
3386
|
applyMergeableChanges,
|
|
3281
3387
|
merge,
|
|
3282
|
-
|
|
3283
|
-
|
|
3388
|
+
__: [
|
|
3389
|
+
hadMutated,
|
|
3390
|
+
getEncodedMergeableContent,
|
|
3391
|
+
getEncodedTransactionMergeableChanges,
|
|
3392
|
+
],
|
|
3284
3393
|
};
|
|
3285
|
-
store.
|
|
3394
|
+
store._[3](
|
|
3286
3395
|
preStartTransaction,
|
|
3287
3396
|
preFinishTransaction,
|
|
3288
3397
|
postFinishTransaction,
|
|
@@ -3521,6 +3630,7 @@ const createMiddleware = getCreateFunction((store) => {
|
|
|
3521
3630
|
const willDelValuesCallbacks = [];
|
|
3522
3631
|
const willDelValueCallbacks = [];
|
|
3523
3632
|
const willApplyChangesCallbacks = [];
|
|
3633
|
+
const didSetRowCallbacksMap = mapNew();
|
|
3524
3634
|
const willSetContent = (content) =>
|
|
3525
3635
|
reduceCallbacks(willSetContentCallbacks, content);
|
|
3526
3636
|
const willSetTables = (tables) =>
|
|
@@ -3547,6 +3657,17 @@ const createMiddleware = getCreateFunction((store) => {
|
|
|
3547
3657
|
everyCallback(willDelValueCallbacks, valueId);
|
|
3548
3658
|
const willApplyChanges = (changes) =>
|
|
3549
3659
|
reduceCallbacks(willApplyChangesCallbacks, changes);
|
|
3660
|
+
const didSetRow = (tableId, rowId, oldRow, newRow) =>
|
|
3661
|
+
ifNotUndefined(
|
|
3662
|
+
mapGet(didSetRowCallbacksMap, tableId),
|
|
3663
|
+
(callbacks) =>
|
|
3664
|
+
arrayReduce(
|
|
3665
|
+
callbacks,
|
|
3666
|
+
(current, callback) => callback(tableId, rowId, oldRow, current),
|
|
3667
|
+
newRow,
|
|
3668
|
+
),
|
|
3669
|
+
() => newRow,
|
|
3670
|
+
);
|
|
3550
3671
|
const getStore = () => store;
|
|
3551
3672
|
const addWillSetContentCallback = addCallback(willSetContentCallbacks);
|
|
3552
3673
|
const addWillSetTablesCallback = addCallback(willSetTablesCallbacks);
|
|
@@ -3562,6 +3683,13 @@ const createMiddleware = getCreateFunction((store) => {
|
|
|
3562
3683
|
const addWillDelValuesCallback = addCallback(willDelValuesCallbacks);
|
|
3563
3684
|
const addWillDelValueCallback = addCallback(willDelValueCallbacks);
|
|
3564
3685
|
const addWillApplyChangesCallback = addCallback(willApplyChangesCallbacks);
|
|
3686
|
+
const addDidSetRowCallback = (tableId, callback) =>
|
|
3687
|
+
fluent(() =>
|
|
3688
|
+
arrayPush(
|
|
3689
|
+
mapEnsure(didSetRowCallbacksMap, tableId, () => []),
|
|
3690
|
+
callback,
|
|
3691
|
+
),
|
|
3692
|
+
);
|
|
3565
3693
|
const destroy = () => {};
|
|
3566
3694
|
const middleware = objFreeze({
|
|
3567
3695
|
getStore,
|
|
@@ -3579,9 +3707,10 @@ const createMiddleware = getCreateFunction((store) => {
|
|
|
3579
3707
|
addWillDelValuesCallback,
|
|
3580
3708
|
addWillDelValueCallback,
|
|
3581
3709
|
addWillApplyChangesCallback,
|
|
3710
|
+
addDidSetRowCallback,
|
|
3582
3711
|
destroy,
|
|
3583
3712
|
});
|
|
3584
|
-
store.
|
|
3713
|
+
store._[4](
|
|
3585
3714
|
willSetContent,
|
|
3586
3715
|
willSetTables,
|
|
3587
3716
|
willSetTable,
|
|
@@ -3596,20 +3725,20 @@ const createMiddleware = getCreateFunction((store) => {
|
|
|
3596
3725
|
willDelValues,
|
|
3597
3726
|
willDelValue,
|
|
3598
3727
|
willApplyChanges,
|
|
3728
|
+
didSetRow,
|
|
3599
3729
|
);
|
|
3600
3730
|
return middleware;
|
|
3601
3731
|
});
|
|
3602
3732
|
|
|
3603
3733
|
const createQueries = getCreateFunction((store) => {
|
|
3604
|
-
const createStore = store.
|
|
3734
|
+
const createStore = store._[0];
|
|
3605
3735
|
const preStore = createStore();
|
|
3606
3736
|
const resultStore = createStore();
|
|
3607
3737
|
const preStoreListenerIds = mapNew();
|
|
3608
3738
|
const paramValuesListeners = mapNew();
|
|
3609
3739
|
const paramValueListeners = mapNew();
|
|
3610
3740
|
const {
|
|
3611
|
-
addListener,
|
|
3612
|
-
callListeners,
|
|
3741
|
+
_: [, addListener, callListeners],
|
|
3613
3742
|
delListener: delListenerImpl,
|
|
3614
3743
|
} = resultStore;
|
|
3615
3744
|
const [
|
|
@@ -3928,7 +4057,7 @@ const createQueries = getCreateFunction((store) => {
|
|
|
3928
4057
|
selectJoinWhereStore.transaction(() =>
|
|
3929
4058
|
arrayEvery(wheres, (where2) => where2(getTableCell))
|
|
3930
4059
|
? mapForEach(selects, (asCellId, tableCellGetter) =>
|
|
3931
|
-
selectJoinWhereStore.
|
|
4060
|
+
selectJoinWhereStore._[5](
|
|
3932
4061
|
queryId,
|
|
3933
4062
|
rootRowId,
|
|
3934
4063
|
asCellId,
|