tinybase 7.1.0-beta.3 → 7.1.0-beta.4
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/schematizers/schematizer-arktype/index.d.ts +114 -0
- package/@types/schematizers/schematizer-arktype/with-schemas/index.d.ts +8 -0
- package/@types/schematizers/schematizer-effect/index.d.ts +118 -0
- package/@types/schematizers/schematizer-effect/with-schemas/index.d.ts +8 -0
- package/@types/schematizers/schematizer-yup/index.d.ts +112 -0
- package/@types/schematizers/schematizer-yup/with-schemas/index.d.ts +7 -0
- package/checkpoints/index.js +2 -2
- package/checkpoints/with-schemas/index.js +2 -2
- package/index.js +6 -4
- package/indexes/index.js +2 -2
- package/indexes/with-schemas/index.js +2 -2
- package/mergeable-store/index.js +2 -2
- package/mergeable-store/with-schemas/index.js +2 -2
- package/metrics/index.js +6 -4
- package/metrics/with-schemas/index.js +6 -4
- 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/indexes/index.js +1 -1
- package/min/indexes/index.js.gz +0 -0
- package/min/indexes/with-schemas/index.js +1 -1
- package/min/indexes/with-schemas/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/metrics/index.js +1 -1
- package/min/metrics/index.js.gz +0 -0
- package/min/metrics/with-schemas/index.js +1 -1
- package/min/metrics/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/relationships/index.js +1 -1
- package/min/relationships/index.js.gz +0 -0
- package/min/relationships/with-schemas/index.js +1 -1
- package/min/relationships/with-schemas/index.js.gz +0 -0
- package/min/schematizers/schematizer-arktype/index.js +1 -0
- package/min/schematizers/schematizer-arktype/index.js.gz +0 -0
- package/min/schematizers/schematizer-arktype/with-schemas/index.js +1 -0
- package/min/schematizers/schematizer-arktype/with-schemas/index.js.gz +0 -0
- package/min/schematizers/schematizer-effect/index.js +1 -0
- package/min/schematizers/schematizer-effect/index.js.gz +0 -0
- package/min/schematizers/schematizer-effect/with-schemas/index.js +1 -0
- 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 -0
- package/min/schematizers/schematizer-yup/index.js.gz +0 -0
- package/min/schematizers/schematizer-yup/with-schemas/index.js +1 -0
- package/min/schematizers/schematizer-yup/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/synchronizer-ws-server-simple/index.js +1 -1
- package/min/synchronizers/synchronizer-ws-server-simple/index.js.gz +0 -0
- package/min/synchronizers/synchronizer-ws-server-simple/with-schemas/index.js +1 -1
- package/min/synchronizers/synchronizer-ws-server-simple/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-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 +19 -16
- package/omni/with-schemas/index.js +19 -16
- package/package.json +118 -2
- package/persisters/index.js +6 -4
- package/persisters/persister-automerge/index.js +2 -2
- package/persisters/persister-automerge/with-schemas/index.js +2 -2
- package/persisters/persister-browser/index.js +3 -3
- package/persisters/persister-browser/with-schemas/index.js +3 -3
- package/persisters/persister-cr-sqlite-wasm/index.js +6 -4
- package/persisters/persister-cr-sqlite-wasm/with-schemas/index.js +6 -4
- package/persisters/persister-durable-object-sql-storage/index.js +6 -4
- package/persisters/persister-durable-object-sql-storage/with-schemas/index.js +6 -4
- package/persisters/persister-durable-object-storage/index.js +3 -3
- package/persisters/persister-durable-object-storage/with-schemas/index.js +3 -3
- package/persisters/persister-electric-sql/index.js +6 -4
- package/persisters/persister-electric-sql/with-schemas/index.js +6 -4
- package/persisters/persister-expo-sqlite/index.js +6 -4
- package/persisters/persister-expo-sqlite/with-schemas/index.js +6 -4
- package/persisters/persister-file/index.js +3 -3
- package/persisters/persister-file/with-schemas/index.js +3 -3
- package/persisters/persister-indexed-db/index.js +2 -2
- package/persisters/persister-indexed-db/with-schemas/index.js +2 -2
- package/persisters/persister-libsql/index.js +6 -4
- package/persisters/persister-libsql/with-schemas/index.js +6 -4
- package/persisters/persister-partykit-client/index.js +2 -2
- package/persisters/persister-partykit-client/with-schemas/index.js +2 -2
- package/persisters/persister-pglite/index.js +3 -3
- package/persisters/persister-pglite/with-schemas/index.js +3 -3
- package/persisters/persister-postgres/index.js +3 -3
- package/persisters/persister-postgres/with-schemas/index.js +3 -3
- package/persisters/persister-powersync/index.js +6 -4
- package/persisters/persister-powersync/with-schemas/index.js +6 -4
- package/persisters/persister-react-native-mmkv/index.js +4 -4
- package/persisters/persister-react-native-mmkv/with-schemas/index.js +4 -4
- package/persisters/persister-react-native-sqlite/index.js +6 -4
- package/persisters/persister-react-native-sqlite/with-schemas/index.js +6 -4
- package/persisters/persister-remote/index.js +2 -2
- package/persisters/persister-remote/with-schemas/index.js +2 -2
- package/persisters/persister-sqlite-bun/index.js +6 -4
- package/persisters/persister-sqlite-bun/with-schemas/index.js +6 -4
- package/persisters/persister-sqlite-wasm/index.js +6 -4
- package/persisters/persister-sqlite-wasm/with-schemas/index.js +6 -4
- package/persisters/persister-sqlite3/index.js +6 -4
- package/persisters/persister-sqlite3/with-schemas/index.js +6 -4
- package/persisters/persister-yjs/index.js +2 -2
- package/persisters/persister-yjs/with-schemas/index.js +2 -2
- package/persisters/with-schemas/index.js +6 -4
- package/queries/index.js +1 -1
- package/queries/with-schemas/index.js +1 -1
- package/readme.md +1 -1
- package/relationships/index.js +2 -2
- package/relationships/with-schemas/index.js +2 -2
- package/schematizers/schematizer-arktype/index.js +163 -0
- package/schematizers/schematizer-arktype/with-schemas/index.js +163 -0
- package/schematizers/schematizer-effect/index.js +137 -0
- package/schematizers/schematizer-effect/with-schemas/index.js +137 -0
- package/schematizers/schematizer-typebox/index.js +3 -2
- package/schematizers/schematizer-typebox/with-schemas/index.js +3 -2
- package/schematizers/schematizer-valibot/index.js +4 -4
- package/schematizers/schematizer-valibot/with-schemas/index.js +4 -4
- package/schematizers/schematizer-yup/index.js +100 -0
- package/schematizers/schematizer-yup/with-schemas/index.js +100 -0
- package/schematizers/schematizer-zod/index.js +2 -2
- package/schematizers/schematizer-zod/with-schemas/index.js +2 -2
- package/store/index.js +2 -2
- package/store/with-schemas/index.js +2 -2
- package/synchronizers/index.js +2 -2
- package/synchronizers/synchronizer-broadcast-channel/index.js +2 -2
- package/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +2 -2
- package/synchronizers/synchronizer-local/index.js +2 -2
- package/synchronizers/synchronizer-local/with-schemas/index.js +2 -2
- package/synchronizers/synchronizer-ws-client/index.js +3 -3
- package/synchronizers/synchronizer-ws-client/with-schemas/index.js +3 -3
- package/synchronizers/synchronizer-ws-server/index.js +3 -3
- package/synchronizers/synchronizer-ws-server/with-schemas/index.js +3 -3
- package/synchronizers/synchronizer-ws-server-durable-object/index.js +3 -3
- package/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +3 -3
- package/synchronizers/synchronizer-ws-server-simple/index.js +1 -1
- package/synchronizers/synchronizer-ws-server-simple/with-schemas/index.js +1 -1
- package/synchronizers/with-schemas/index.js +2 -2
- package/ui-react-dom/index.js +11 -8
- package/ui-react-dom/with-schemas/index.js +11 -8
- package/ui-react-inspector/index.js +14 -11
- package/ui-react-inspector/with-schemas/index.js +14 -11
- package/with-schemas/index.js +6 -4
|
@@ -22,6 +22,8 @@ const stopInterval = clearInterval;
|
|
|
22
22
|
const isNullish = (thing) => thing == null;
|
|
23
23
|
const isUndefined = (thing) => thing === void 0;
|
|
24
24
|
const isNull = (thing) => thing === null;
|
|
25
|
+
const isTrue = (thing) => thing === true;
|
|
26
|
+
const isFalse = (thing) => thing === false;
|
|
25
27
|
const ifNotNullish = getIfNotFunction(isNullish);
|
|
26
28
|
const ifNotUndefined = getIfNotFunction(isUndefined);
|
|
27
29
|
const isString = (thing) => getTypeOf(thing) == STRING;
|
|
@@ -141,7 +143,7 @@ const mapForEach = (map, cb) =>
|
|
|
141
143
|
const mapMap = (coll, cb) =>
|
|
142
144
|
arrayMap([...(coll?.entries() ?? [])], ([key, value]) => cb(value, key));
|
|
143
145
|
const mapSet = (map, key, value) =>
|
|
144
|
-
value
|
|
146
|
+
isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
|
|
145
147
|
const mapEnsure = (map, key, getDefaultValue, hadExistingValue) => {
|
|
146
148
|
if (!collHas(map, key)) {
|
|
147
149
|
mapSet(map, key, getDefaultValue());
|
|
@@ -301,7 +303,7 @@ const getConfigStructures = (configOrStoreTableName) => {
|
|
|
301
303
|
const jsonString = JSON.stringify;
|
|
302
304
|
const jsonParse = JSON.parse;
|
|
303
305
|
const jsonStringWithUndefined = (obj) =>
|
|
304
|
-
jsonString(obj, (_key, value) => (value
|
|
306
|
+
jsonString(obj, (_key, value) => (isUndefined(value) ? UNDEFINED : value));
|
|
305
307
|
const jsonParseWithUndefined = (str) =>
|
|
306
308
|
jsonParse(str, (_key, value) => (value === UNDEFINED ? void 0 : value));
|
|
307
309
|
|
|
@@ -324,7 +326,7 @@ const getWildcardedLeaves = (deepIdSet, path = [EMPTY_STRING]) => {
|
|
|
324
326
|
const deep = (node, p) =>
|
|
325
327
|
p == size(path)
|
|
326
328
|
? arrayPush(leaves, node)
|
|
327
|
-
: path[p]
|
|
329
|
+
: isNull(path[p])
|
|
328
330
|
? collForEach(node, (node2) => deep(node2, p + 1))
|
|
329
331
|
: arrayForEach([path[p], null], (id) => deep(mapGet(node, id), p + 1));
|
|
330
332
|
deep(deepIdSet, 0);
|
|
@@ -1172,7 +1174,7 @@ const createCustomSqlitePersister = (
|
|
|
1172
1174
|
EMPTY_STRING,
|
|
1173
1175
|
upsert,
|
|
1174
1176
|
(cellOrValue) =>
|
|
1175
|
-
cellOrValue
|
|
1177
|
+
isTrue(cellOrValue) ? 1 : isFalse(cellOrValue) ? 0 : cellOrValue,
|
|
1176
1178
|
void 0,
|
|
1177
1179
|
);
|
|
1178
1180
|
};
|
|
@@ -22,6 +22,8 @@ const stopInterval = clearInterval;
|
|
|
22
22
|
const isNullish = (thing) => thing == null;
|
|
23
23
|
const isUndefined = (thing) => thing === void 0;
|
|
24
24
|
const isNull = (thing) => thing === null;
|
|
25
|
+
const isTrue = (thing) => thing === true;
|
|
26
|
+
const isFalse = (thing) => thing === false;
|
|
25
27
|
const ifNotNullish = getIfNotFunction(isNullish);
|
|
26
28
|
const ifNotUndefined = getIfNotFunction(isUndefined);
|
|
27
29
|
const isString = (thing) => getTypeOf(thing) == STRING;
|
|
@@ -141,7 +143,7 @@ const mapForEach = (map, cb) =>
|
|
|
141
143
|
const mapMap = (coll, cb) =>
|
|
142
144
|
arrayMap([...(coll?.entries() ?? [])], ([key, value]) => cb(value, key));
|
|
143
145
|
const mapSet = (map, key, value) =>
|
|
144
|
-
value
|
|
146
|
+
isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
|
|
145
147
|
const mapEnsure = (map, key, getDefaultValue, hadExistingValue) => {
|
|
146
148
|
if (!collHas(map, key)) {
|
|
147
149
|
mapSet(map, key, getDefaultValue());
|
|
@@ -301,7 +303,7 @@ const getConfigStructures = (configOrStoreTableName) => {
|
|
|
301
303
|
const jsonString = JSON.stringify;
|
|
302
304
|
const jsonParse = JSON.parse;
|
|
303
305
|
const jsonStringWithUndefined = (obj) =>
|
|
304
|
-
jsonString(obj, (_key, value) => (value
|
|
306
|
+
jsonString(obj, (_key, value) => (isUndefined(value) ? UNDEFINED : value));
|
|
305
307
|
const jsonParseWithUndefined = (str) =>
|
|
306
308
|
jsonParse(str, (_key, value) => (value === UNDEFINED ? void 0 : value));
|
|
307
309
|
|
|
@@ -324,7 +326,7 @@ const getWildcardedLeaves = (deepIdSet, path = [EMPTY_STRING]) => {
|
|
|
324
326
|
const deep = (node, p) =>
|
|
325
327
|
p == size(path)
|
|
326
328
|
? arrayPush(leaves, node)
|
|
327
|
-
: path[p]
|
|
329
|
+
: isNull(path[p])
|
|
328
330
|
? collForEach(node, (node2) => deep(node2, p + 1))
|
|
329
331
|
: arrayForEach([path[p], null], (id) => deep(mapGet(node, id), p + 1));
|
|
330
332
|
deep(deepIdSet, 0);
|
|
@@ -1172,7 +1174,7 @@ const createCustomSqlitePersister = (
|
|
|
1172
1174
|
EMPTY_STRING,
|
|
1173
1175
|
upsert,
|
|
1174
1176
|
(cellOrValue) =>
|
|
1175
|
-
cellOrValue
|
|
1177
|
+
isTrue(cellOrValue) ? 1 : isFalse(cellOrValue) ? 0 : cellOrValue,
|
|
1176
1178
|
void 0,
|
|
1177
1179
|
);
|
|
1178
1180
|
};
|
|
@@ -76,7 +76,7 @@ const mapGet = (map, key) => map?.get(key);
|
|
|
76
76
|
const mapForEach = (map, cb) =>
|
|
77
77
|
collForEach(map, (value, key) => cb(key, value));
|
|
78
78
|
const mapSet = (map, key, value) =>
|
|
79
|
-
value
|
|
79
|
+
isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
|
|
80
80
|
const mapEnsure = (map, key, getDefaultValue, hadExistingValue) => {
|
|
81
81
|
if (!collHas(map, key)) {
|
|
82
82
|
mapSet(map, key, getDefaultValue());
|
|
@@ -134,7 +134,7 @@ const getWildcardedLeaves = (deepIdSet, path = [EMPTY_STRING]) => {
|
|
|
134
134
|
const deep = (node, p) =>
|
|
135
135
|
p == size(path)
|
|
136
136
|
? arrayPush(leaves, node)
|
|
137
|
-
: path[p]
|
|
137
|
+
: isNull(path[p])
|
|
138
138
|
? collForEach(node, (node2) => deep(node2, p + 1))
|
|
139
139
|
: arrayForEach([path[p], null], (id) => deep(mapGet(node, id), p + 1));
|
|
140
140
|
deep(deepIdSet, 0);
|
|
@@ -76,7 +76,7 @@ const mapGet = (map, key) => map?.get(key);
|
|
|
76
76
|
const mapForEach = (map, cb) =>
|
|
77
77
|
collForEach(map, (value, key) => cb(key, value));
|
|
78
78
|
const mapSet = (map, key, value) =>
|
|
79
|
-
value
|
|
79
|
+
isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
|
|
80
80
|
const mapEnsure = (map, key, getDefaultValue, hadExistingValue) => {
|
|
81
81
|
if (!collHas(map, key)) {
|
|
82
82
|
mapSet(map, key, getDefaultValue());
|
|
@@ -134,7 +134,7 @@ const getWildcardedLeaves = (deepIdSet, path = [EMPTY_STRING]) => {
|
|
|
134
134
|
const deep = (node, p) =>
|
|
135
135
|
p == size(path)
|
|
136
136
|
? arrayPush(leaves, node)
|
|
137
|
-
: path[p]
|
|
137
|
+
: isNull(path[p])
|
|
138
138
|
? collForEach(node, (node2) => deep(node2, p + 1))
|
|
139
139
|
: arrayForEach([path[p], null], (id) => deep(mapGet(node, id), p + 1));
|
|
140
140
|
deep(deepIdSet, 0);
|
|
@@ -24,6 +24,8 @@ const stopInterval = clearInterval;
|
|
|
24
24
|
const isNullish = (thing) => thing == null;
|
|
25
25
|
const isUndefined = (thing) => thing === void 0;
|
|
26
26
|
const isNull = (thing) => thing === null;
|
|
27
|
+
const isTrue = (thing) => thing === true;
|
|
28
|
+
const isFalse = (thing) => thing === false;
|
|
27
29
|
const ifNotNullish = getIfNotFunction(isNullish);
|
|
28
30
|
const ifNotUndefined = getIfNotFunction(isUndefined);
|
|
29
31
|
const isString = (thing) => getTypeOf(thing) == STRING;
|
|
@@ -99,7 +101,7 @@ const mapForEach = (map, cb) =>
|
|
|
99
101
|
const mapMap = (coll, cb) =>
|
|
100
102
|
arrayMap([...(coll?.entries() ?? [])], ([key, value]) => cb(value, key));
|
|
101
103
|
const mapSet = (map, key, value) =>
|
|
102
|
-
value
|
|
104
|
+
isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
|
|
103
105
|
const mapEnsure = (map, key, getDefaultValue, hadExistingValue) => {
|
|
104
106
|
if (!collHas(map, key)) {
|
|
105
107
|
mapSet(map, key, getDefaultValue());
|
|
@@ -157,7 +159,7 @@ const getWildcardedLeaves = (deepIdSet, path = [EMPTY_STRING]) => {
|
|
|
157
159
|
const deep = (node, p) =>
|
|
158
160
|
p == size(path)
|
|
159
161
|
? arrayPush(leaves, node)
|
|
160
|
-
: path[p]
|
|
162
|
+
: isNull(path[p])
|
|
161
163
|
? collForEach(node, (node2) => deep(node2, p + 1))
|
|
162
164
|
: arrayForEach([path[p], null], (id) => deep(mapGet(node, id), p + 1));
|
|
163
165
|
deep(deepIdSet, 0);
|
|
@@ -475,7 +477,7 @@ const createCustomPersister = (
|
|
|
475
477
|
const jsonString = JSON.stringify;
|
|
476
478
|
const jsonParse = JSON.parse;
|
|
477
479
|
const jsonStringWithUndefined = (obj) =>
|
|
478
|
-
jsonString(obj, (_key, value) => (value
|
|
480
|
+
jsonString(obj, (_key, value) => (isUndefined(value) ? UNDEFINED : value));
|
|
479
481
|
const jsonParseWithUndefined = (str) =>
|
|
480
482
|
jsonParse(str, (_key, value) => (value === UNDEFINED ? void 0 : value));
|
|
481
483
|
|
|
@@ -1360,7 +1362,7 @@ const createCustomSqlitePersister = (
|
|
|
1360
1362
|
EMPTY_STRING,
|
|
1361
1363
|
upsert,
|
|
1362
1364
|
(cellOrValue) =>
|
|
1363
|
-
cellOrValue
|
|
1365
|
+
isTrue(cellOrValue) ? 1 : isFalse(cellOrValue) ? 0 : cellOrValue,
|
|
1364
1366
|
void 0,
|
|
1365
1367
|
);
|
|
1366
1368
|
};
|
package/queries/index.js
CHANGED
|
@@ -72,7 +72,7 @@ const mapGet = (map, key) => map?.get(key);
|
|
|
72
72
|
const mapForEach = (map, cb) =>
|
|
73
73
|
collForEach(map, (value, key) => cb(key, value));
|
|
74
74
|
const mapSet = (map, key, value) =>
|
|
75
|
-
value
|
|
75
|
+
isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
|
|
76
76
|
const mapEnsure = (map, key, getDefaultValue, hadExistingValue) => {
|
|
77
77
|
if (!collHas(map, key)) {
|
|
78
78
|
mapSet(map, key, getDefaultValue());
|
|
@@ -72,7 +72,7 @@ const mapGet = (map, key) => map?.get(key);
|
|
|
72
72
|
const mapForEach = (map, cb) =>
|
|
73
73
|
collForEach(map, (value, key) => cb(key, value));
|
|
74
74
|
const mapSet = (map, key, value) =>
|
|
75
|
-
value
|
|
75
|
+
isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
|
|
76
76
|
const mapEnsure = (map, key, getDefaultValue, hadExistingValue) => {
|
|
77
77
|
if (!collHas(map, key)) {
|
|
78
78
|
mapSet(map, key, getDefaultValue());
|
package/readme.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<link rel="preload" as="image" href="https://beta.tinybase.org/react.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/indexeddb.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/browser.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/cloudflare.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/postgresql.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/pglite.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/sqlite.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/bun.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/expo.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/electric.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/turso.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/powersync.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/partykit.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/yjs.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/crsqlite.png"><link rel="preload" as="image" href="https://beta.tinybase.org/automerge.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/typebox.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/valibot.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/zod.svg?asImg"><link rel="preload" as="image" href="https://img.shields.io/github/stars/tinyplex/tinybase?style=for-the-badge&logo=GitHub&logoColor=%23fff&label=GitHub&labelColor=%23d81b60&color=%23333"><link rel="preload" as="image" href="https://img.shields.io/badge/Bluesky-Follow-blue?style=for-the-badge&logo=bluesky&logoColor=%23fff&color=%23333&labelColor=%230285FF"><link rel="preload" as="image" href="https://img.shields.io/badge/%2F%20Twitter-Follow-blue?style=for-the-badge&logo=x&logoColor=%23fff&color=%23333&labelColor=%23000"><link rel="preload" as="image" href="https://img.shields.io/discord/1027918215323590676?style=for-the-badge&logo=discord&logoColor=%23fff&label=Discord&labelColor=%233131e8&color=%23333"><link rel="preload" as="image" href="https://img.shields.io/github/discussions/tinyplex/tinybase?style=for-the-badge&logo=GitHub&logoColor=%23fff&label=Ideas&labelColor=%23d81b60&color=%23333"><link rel="preload" as="image" href="https://img.shields.io/github/issues/tinyplex/tinybase?style=for-the-badge&logo=GitHub&logoColor=%23fff&label=Issues&labelColor=%23d81b60&color=%23333"><link rel="preload" as="image" href="https://img.shields.io/badge/Tests-100%25-green?style=for-the-badge&logo=Vitest&logoColor=%23fff&color=%23333&labelColor=%2387c305"><link rel="preload" as="image" href="https://img.shields.io/npm/v/tinybase?style=for-the-badge&logo=npm&logoColor=%23fff&labelColor=%23bd0005&color=%23333"><link rel="preload" as="image" href="https://beta.tinybase.org/ui-react-dom.webp"><link rel="preload" as="image" href="https://beta.tinybase.org/inspector.webp"><link rel="preload" as="image" href="https://github.com/cpojer.png?size=48"><link rel="preload" as="image" href="https://github.com/expo.png?size=48"><link rel="preload" as="image" href="https://github.com/beekeeb.png?size=48"><link rel="preload" as="image" href="https://github.com/cancelself.png?size=48"><link rel="preload" as="image" href="https://github.com/WonderPanda.png?size=48"><link rel="preload" as="image" href="https://github.com/arpitBhalla.png?size=48"><link rel="preload" as="image" href="https://github.com/behrends.png?size=48"><link rel="preload" as="image" href="https://github.com/betomoedano.png?size=48"><link rel="preload" as="image" href="https://github.com/brentvatne.png?size=48"><link rel="preload" as="image" href="https://github.com/byCedric.png?size=48"><link rel="preload" as="image" href="https://github.com/circadian-risk.png?size=48"><link rel="preload" as="image" href="https://github.com/cubecull.png?size=48"><link rel="preload" as="image" href="https://github.com/erwinkn.png?size=48"><link rel="preload" as="image" href="https://github.com/ezra-en.png?size=48"><link rel="preload" as="image" href="https://github.com/feychenie.png?size=48"><link rel="preload" as="image" href="https://github.com/flaming-codes.png?size=48"><link rel="preload" as="image" href="https://github.com/fostertheweb.png?size=48"><link rel="preload" as="image" href="https://github.com/Giulio987.png?size=48"><link rel="preload" as="image" href="https://github.com/hi-ogawa.png?size=48"><link rel="preload" as="image" href="https://github.com/itsdevcoffee.png?size=48"><link rel="preload" as="image" href="https://github.com/jbolda.png?size=48"><link rel="preload" as="image" href="https://github.com/Kayoo-asso.png?size=48"><link rel="preload" as="image" href="https://github.com/kotofurumiya.png?size=48"><link rel="preload" as="image" href="https://github.com/Kudo.png?size=48"><link rel="preload" as="image" href="https://github.com/learn-anything.png?size=48"><link rel="preload" as="image" href="https://github.com/lluc.png?size=48"><link rel="preload" as="image" href="https://github.com/marksteve.png?size=48"><link rel="preload" as="image" href="https://github.com/miking-the-viking.png?size=48"><link rel="preload" as="image" href="https://github.com/mjamesderocher.png?size=48"><link rel="preload" as="image" href="https://github.com/mouktardev.png?size=48"><link rel="preload" as="image" href="https://github.com/nickmessing.png?size=48"><link rel="preload" as="image" href="https://github.com/nikitavoloboev.png?size=48"><link rel="preload" as="image" href="https://github.com/nkzw-tech.png?size=48"><link rel="preload" as="image" href="https://github.com/palerdot.png?size=48"><link rel="preload" as="image" href="https://github.com/PorcoRosso85.png?size=48"><link rel="preload" as="image" href="https://github.com/primodiumxyz.png?size=48"><link rel="preload" as="image" href="https://github.com/shaneosullivan.png?size=48"><link rel="preload" as="image" href="https://github.com/sudo-self.png?size=48"><link rel="preload" as="image" href="https://github.com/SuperSonicHub1.png?size=48"><link rel="preload" as="image" href="https://github.com/threepointone.png?size=48"><link rel="preload" as="image" href="https://github.com/uptonking.png?size=48"><link rel="preload" as="image" href="https://github.com/ViktorZhurbin.png?size=48"><link rel="preload" as="image" href="https://github.com/wilkerlucio.png?size=48"><link rel="preload" as="image" href="https://synclets.org/favicon.svg?asImg"><link rel="preload" as="image" href="https://tinywidgets.org/favicon.svg?asImg"><link rel="preload" as="image" href="https://tinytick.org/favicon.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/youtube.webp"><section id="hero"><h2 id="a-reactive-data-store-sync-engine">A <em>reactive</em> data store & <span><em>sync</em> engine</span></h2></section><p><a href="https://beta.tinybase.org/guides/releases/#v7-1"><em>NEW!</em> v7.1 release</a></p><p><span id="one-with">"The one with Schematizers!"</span></p><p><a class="start" href="https://beta.tinybase.org/guides/the-basics/getting-started/">Get started</a></p><p><a href="https://beta.tinybase.org/demos/">Try the demos</a></p><p><a href="https://beta.tinybase.org/api/the-essentials/creating-stores/store/">Read the docs</a></p><hr><section><h2 id="it-s-reactive">It's <em>Reactive</em></h2><p>TinyBase lets you <a href="#register-granular-listeners">listen to changes</a> made to any part of your data. This means your app will be fast, since you only spend rendering cycles on things that change. The optional <a href="#call-hooks-to-bind-to-data">bindings to React</a> and <a href="#pre-built-reactive-components">pre-built components</a> let you easily build fully reactive UIs on top of TinyBase. You even get a built-in <a href="#set-checkpoints-for-an-undo-stack">undo stack</a>, and <a href="#an-inspector-for-your-data">developer tools</a>!</p></section><section><h2 id="it-s-database-like">It's <em>Database-Like</em></h2><p>Consumer app? Enterprise app? Or even a game? Model <a href="#start-with-a-simple-key-value-store">key-value data</a> and <a href="#level-up-to-use-tabular-data">tabular data</a> with optional typed <a href="#apply-schemas-to-tables-values">schematization</a>, whatever its data structures. There are built-in <a href="#create-indexes-for-fast-lookups">indexing</a>, <a href="#define-metrics-and-aggregations">metric aggregation</a>, and tabular <a href="#model-table-relationships">relationships</a> APIs - and a powerful <a href="#build-complex-queries-with-tinyql">query engine</a> to select, join, filter, and group data (reactively!) without SQL.</p></section><section><h2 id="it-synchronizes">It <em>Synchronizes</em></h2><p>TinyBase has <a href="#synchronize-between-devices">native CRDT</a> support, meaning that you can deterministically <a href="https://beta.tinybase.org/guides/synchronization/">synchronize</a> and merge data across multiple sources, clients, and servers. And although TinyBase is an in-memory data store, you can easily <a href="#persist-to-storage-databases-more">persist</a> your data to file, <a href="https://beta.tinybase.org/api/persister-browser">browser storage</a>, <a href="https://beta.tinybase.org/api/persister-indexed-db">IndexedDB</a>, <a href="https://beta.tinybase.org/guides/persistence/database-persistence/">SQLite or PostgreSQL databases</a>, and <a href="https://beta.tinybase.org/guides/persistence/third-party-crdt-persistence/">more</a>.</p></section><section><h2 id="it-s-built-for-a-local-first-world">It's Built For A <em>Local-First</em> World</h2><p>TinyBase works anywhere that JavaScript does, but it's especially great for local-first apps: where data is stored locally on the user's device and that can be run offline. It's tiny by name, tiny by nature: just <a href="#did-we-say-tiny">5.4kB - 11.8kB</a> and with no dependencies - yet <a href="#well-tested-and-documented">100% tested</a>, <a href="https://beta.tinybase.org/guides/the-basics/getting-started/">fully documented</a>, and of course, <a href="https://github.com/tinyplex/tinybase">open source</a>!</p></section><hr><section id="friends"><h2 id="tinybase-works-great-on-its-own-but-also-plays-well-with-friends">TinyBase works great on its own, but also plays well with friends.</h2><div><a href="https://beta.tinybase.org/guides/building-uis/getting-started-with-ui-react"><img src="https://beta.tinybase.org/react.svg?asImg" width="48"> React</a></div><div><a href="https://beta.tinybase.org/api/persister-indexed-db/functions/creation/createindexeddbpersister"><img src="https://beta.tinybase.org/indexeddb.svg?asImg" width="48"> IndexedDB</a></div><div><a href="https://beta.tinybase.org/api/persister-browser"><img src="https://beta.tinybase.org/browser.svg?asImg" width="48"> OPFS</a></div><div><a href="https://beta.tinybase.org/guides/integrations/cloudflare-durable-objects"><img src="https://beta.tinybase.org/cloudflare.svg?asImg" width="48"> Cloudflare</a></div><div><a href="https://beta.tinybase.org/guides/schemas-and-persistence/database-persistence"><img src="https://beta.tinybase.org/postgresql.svg?asImg" width="48"> PostgreSQL</a></div><div><a href="https://beta.tinybase.org/guides/schemas-and-persistence/database-persistence"><img src="https://beta.tinybase.org/pglite.svg?asImg" width="48"> PGlite</a></div><div><a href="https://beta.tinybase.org/guides/schemas-and-persistence/database-persistence"><img src="https://beta.tinybase.org/sqlite.svg?asImg" width="48"> SQLite</a></div><div><a href="https://beta.tinybase.org/guides/schemas-and-persistence/database-persistence"><img src="https://beta.tinybase.org/bun.svg?asImg" width="48"> Bun SQLite</a></div><div><a href="https://beta.tinybase.org/guides/schemas-and-persistence/database-persistence"><img src="https://beta.tinybase.org/expo.svg?asImg" width="48"> Expo SQLite</a></div><div><a href="https://beta.tinybase.org/guides/schemas-and-persistence/database-persistence"><img src="https://beta.tinybase.org/electric.svg?asImg" width="48"> ElectricSQL</a></div><div><a href="https://beta.tinybase.org/guides/schemas-and-persistence/database-persistence"><img src="https://beta.tinybase.org/turso.svg?asImg" width="48"> Turso</a></div><div><a href="https://beta.tinybase.org/guides/schemas-and-persistence/database-persistence"><img src="https://beta.tinybase.org/powersync.svg?asImg" width="48"> PowerSync</a></div><div><a href="https://beta.tinybase.org/api/persister-partykit-client"><img src="https://beta.tinybase.org/partykit.svg?asImg" width="48"> PartyKit</a></div><div><a href="https://beta.tinybase.org/api/persister-yjs/functions/creation/createyjspersister"><img src="https://beta.tinybase.org/yjs.svg?asImg" width="48"> YJS</a></div><div><a href="https://beta.tinybase.org/api/persister-cr-sqlite-wasm"><img src="https://beta.tinybase.org/crsqlite.png" width="48"> CR-SQLite</a></div><div><a href="https://beta.tinybase.org/api/persister-automerge"><img src="https://beta.tinybase.org/automerge.svg?asImg" width="48"> Automerge</a></div><div><a href="https://beta.tinybase.org/api/schematizer-typebox/functions/creation/createtypeboxschematizer"><img src="https://beta.tinybase.org/typebox.svg?asImg" width="48"> TypeBox</a></div><div><a href="https://beta.tinybase.org/api/schematizer-valibot/functions/creation/createvalibotschematizer"><img src="https://beta.tinybase.org/valibot.svg?asImg" width="48"> Valibot</a></div><div><a href="https://beta.tinybase.org/api/schematizer-zod/functions/creation/createzodschematizer"><img src="https://beta.tinybase.org/zod.svg?asImg" width="48"> Zod</a></div><p>(Baffled by all these logos? Check out our <a href="https://beta.tinybase.org/guides/the-basics/architectural-options">architectural options</a> guide to make sense of it all!)</p></section><hr><section id="follow"><p><a href="https://github.com/tinyplex/tinybase" target="_blank"><img src="https://img.shields.io/github/stars/tinyplex/tinybase?style=for-the-badge&logo=GitHub&logoColor=%23fff&label=GitHub&labelColor=%23d81b60&color=%23333"></a></p><p><a href="https://bsky.app/profile/tinybase.bsky.social"><img src="https://img.shields.io/badge/Bluesky-Follow-blue?style=for-the-badge&logo=bluesky&logoColor=%23fff&color=%23333&labelColor=%230285FF"></a></p><p><a href="https://x.com/tinybasejs" target="_blank"><img src="https://img.shields.io/badge/%2F%20Twitter-Follow-blue?style=for-the-badge&logo=x&logoColor=%23fff&color=%23333&labelColor=%23000"></a></p><p><a href="https://discord.com/invite/mGz3mevwP8" target="_blank"><img src="https://img.shields.io/discord/1027918215323590676?style=for-the-badge&logo=discord&logoColor=%23fff&label=Discord&labelColor=%233131e8&color=%23333"></a></p><br><p><a href="https://github.com/tinyplex/tinybase/discussions" target="_blank"><img src="https://img.shields.io/github/discussions/tinyplex/tinybase?style=for-the-badge&logo=GitHub&logoColor=%23fff&label=Ideas&labelColor=%23d81b60&color=%23333"></a></p><p><a href="https://github.com/tinyplex/tinybase/issues" target="_blank"><img src="https://img.shields.io/github/issues/tinyplex/tinybase?style=for-the-badge&logo=GitHub&logoColor=%23fff&label=Issues&labelColor=%23d81b60&color=%23333"></a></p><p><a href="#well-tested-and-documented"><img src="https://img.shields.io/badge/Tests-100%25-green?style=for-the-badge&logo=Vitest&logoColor=%23fff&color=%23333&labelColor=%2387c305"></a></p><p><a href="https://www.npmjs.com/package/tinybase/v/7.1.0-beta.2" target="_blank"><img src="https://img.shields.io/npm/v/tinybase?style=for-the-badge&logo=npm&logoColor=%23fff&labelColor=%23bd0005&color=%23333"></a></p></section><hr><section><h2 id="start-with-a-simple-key-value-store">Start with a simple key-value store.</h2><p>Creating a <a href="https://beta.tinybase.org/api/the-essentials/creating-stores/store/"><code>Store</code></a> requires just a simple call to the <a href="https://beta.tinybase.org/api/the-essentials/creating-stores/createstore/"><code>createStore</code></a> function. Once you have one, you can easily set <a href="https://beta.tinybase.org/api/store/type-aliases/store/values/"><code>Values</code></a> in it by unique <a href="https://beta.tinybase.org/api/common/type-aliases/identity/id/"><code>Id</code></a>. And of course you can easily get them back out again.</p><p>Read more about using keyed value data in <a href="https://beta.tinybase.org/guides/the-basics/">The Basics</a> guide.</p></section>
|
|
1
|
+
<link rel="preload" as="image" href="https://beta.tinybase.org/react.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/indexeddb.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/browser.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/cloudflare.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/postgresql.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/pglite.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/sqlite.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/bun.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/expo.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/electric.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/turso.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/powersync.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/partykit.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/yjs.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/crsqlite.png"><link rel="preload" as="image" href="https://beta.tinybase.org/automerge.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/typebox.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/valibot.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/zod.svg?asImg"><link rel="preload" as="image" href="https://img.shields.io/github/stars/tinyplex/tinybase?style=for-the-badge&logo=GitHub&logoColor=%23fff&label=GitHub&labelColor=%23d81b60&color=%23333"><link rel="preload" as="image" href="https://img.shields.io/badge/Bluesky-Follow-blue?style=for-the-badge&logo=bluesky&logoColor=%23fff&color=%23333&labelColor=%230285FF"><link rel="preload" as="image" href="https://img.shields.io/badge/%2F%20Twitter-Follow-blue?style=for-the-badge&logo=x&logoColor=%23fff&color=%23333&labelColor=%23000"><link rel="preload" as="image" href="https://img.shields.io/discord/1027918215323590676?style=for-the-badge&logo=discord&logoColor=%23fff&label=Discord&labelColor=%233131e8&color=%23333"><link rel="preload" as="image" href="https://img.shields.io/github/discussions/tinyplex/tinybase?style=for-the-badge&logo=GitHub&logoColor=%23fff&label=Ideas&labelColor=%23d81b60&color=%23333"><link rel="preload" as="image" href="https://img.shields.io/github/issues/tinyplex/tinybase?style=for-the-badge&logo=GitHub&logoColor=%23fff&label=Issues&labelColor=%23d81b60&color=%23333"><link rel="preload" as="image" href="https://img.shields.io/badge/Tests-100%25-green?style=for-the-badge&logo=Vitest&logoColor=%23fff&color=%23333&labelColor=%2387c305"><link rel="preload" as="image" href="https://img.shields.io/npm/v/tinybase?style=for-the-badge&logo=npm&logoColor=%23fff&labelColor=%23bd0005&color=%23333"><link rel="preload" as="image" href="https://beta.tinybase.org/ui-react-dom.webp"><link rel="preload" as="image" href="https://beta.tinybase.org/inspector.webp"><link rel="preload" as="image" href="https://github.com/cpojer.png?size=48"><link rel="preload" as="image" href="https://github.com/expo.png?size=48"><link rel="preload" as="image" href="https://github.com/beekeeb.png?size=48"><link rel="preload" as="image" href="https://github.com/cancelself.png?size=48"><link rel="preload" as="image" href="https://github.com/WonderPanda.png?size=48"><link rel="preload" as="image" href="https://github.com/arpitBhalla.png?size=48"><link rel="preload" as="image" href="https://github.com/behrends.png?size=48"><link rel="preload" as="image" href="https://github.com/betomoedano.png?size=48"><link rel="preload" as="image" href="https://github.com/brentvatne.png?size=48"><link rel="preload" as="image" href="https://github.com/byCedric.png?size=48"><link rel="preload" as="image" href="https://github.com/circadian-risk.png?size=48"><link rel="preload" as="image" href="https://github.com/cubecull.png?size=48"><link rel="preload" as="image" href="https://github.com/erwinkn.png?size=48"><link rel="preload" as="image" href="https://github.com/ezra-en.png?size=48"><link rel="preload" as="image" href="https://github.com/feychenie.png?size=48"><link rel="preload" as="image" href="https://github.com/flaming-codes.png?size=48"><link rel="preload" as="image" href="https://github.com/fostertheweb.png?size=48"><link rel="preload" as="image" href="https://github.com/Giulio987.png?size=48"><link rel="preload" as="image" href="https://github.com/hi-ogawa.png?size=48"><link rel="preload" as="image" href="https://github.com/itsdevcoffee.png?size=48"><link rel="preload" as="image" href="https://github.com/jbolda.png?size=48"><link rel="preload" as="image" href="https://github.com/Kayoo-asso.png?size=48"><link rel="preload" as="image" href="https://github.com/kotofurumiya.png?size=48"><link rel="preload" as="image" href="https://github.com/Kudo.png?size=48"><link rel="preload" as="image" href="https://github.com/learn-anything.png?size=48"><link rel="preload" as="image" href="https://github.com/lluc.png?size=48"><link rel="preload" as="image" href="https://github.com/marksteve.png?size=48"><link rel="preload" as="image" href="https://github.com/miking-the-viking.png?size=48"><link rel="preload" as="image" href="https://github.com/mjamesderocher.png?size=48"><link rel="preload" as="image" href="https://github.com/mouktardev.png?size=48"><link rel="preload" as="image" href="https://github.com/nickmessing.png?size=48"><link rel="preload" as="image" href="https://github.com/nikitavoloboev.png?size=48"><link rel="preload" as="image" href="https://github.com/nkzw-tech.png?size=48"><link rel="preload" as="image" href="https://github.com/palerdot.png?size=48"><link rel="preload" as="image" href="https://github.com/PorcoRosso85.png?size=48"><link rel="preload" as="image" href="https://github.com/primodiumxyz.png?size=48"><link rel="preload" as="image" href="https://github.com/shaneosullivan.png?size=48"><link rel="preload" as="image" href="https://github.com/sudo-self.png?size=48"><link rel="preload" as="image" href="https://github.com/SuperSonicHub1.png?size=48"><link rel="preload" as="image" href="https://github.com/threepointone.png?size=48"><link rel="preload" as="image" href="https://github.com/uptonking.png?size=48"><link rel="preload" as="image" href="https://github.com/ViktorZhurbin.png?size=48"><link rel="preload" as="image" href="https://github.com/wilkerlucio.png?size=48"><link rel="preload" as="image" href="https://synclets.org/favicon.svg?asImg"><link rel="preload" as="image" href="https://tinywidgets.org/favicon.svg?asImg"><link rel="preload" as="image" href="https://tinytick.org/favicon.svg?asImg"><link rel="preload" as="image" href="https://beta.tinybase.org/youtube.webp"><section id="hero"><h2 id="a-reactive-data-store-sync-engine">A <em>reactive</em> data store & <span><em>sync</em> engine</span></h2></section><p><a href="https://beta.tinybase.org/guides/releases/#v7-1"><em>NEW!</em> v7.1 release</a></p><p><span id="one-with">"The one with Schematizers!"</span></p><p><a class="start" href="https://beta.tinybase.org/guides/the-basics/getting-started/">Get started</a></p><p><a href="https://beta.tinybase.org/demos/">Try the demos</a></p><p><a href="https://beta.tinybase.org/api/the-essentials/creating-stores/store/">Read the docs</a></p><hr><section><h2 id="it-s-reactive">It's <em>Reactive</em></h2><p>TinyBase lets you <a href="#register-granular-listeners">listen to changes</a> made to any part of your data. This means your app will be fast, since you only spend rendering cycles on things that change. The optional <a href="#call-hooks-to-bind-to-data">bindings to React</a> and <a href="#pre-built-reactive-components">pre-built components</a> let you easily build fully reactive UIs on top of TinyBase. You even get a built-in <a href="#set-checkpoints-for-an-undo-stack">undo stack</a>, and <a href="#an-inspector-for-your-data">developer tools</a>!</p></section><section><h2 id="it-s-database-like">It's <em>Database-Like</em></h2><p>Consumer app? Enterprise app? Or even a game? Model <a href="#start-with-a-simple-key-value-store">key-value data</a> and <a href="#level-up-to-use-tabular-data">tabular data</a> with optional typed <a href="#apply-schemas-to-tables-values">schematization</a>, whatever its data structures. There are built-in <a href="#create-indexes-for-fast-lookups">indexing</a>, <a href="#define-metrics-and-aggregations">metric aggregation</a>, and tabular <a href="#model-table-relationships">relationships</a> APIs - and a powerful <a href="#build-complex-queries-with-tinyql">query engine</a> to select, join, filter, and group data (reactively!) without SQL.</p></section><section><h2 id="it-synchronizes">It <em>Synchronizes</em></h2><p>TinyBase has <a href="#synchronize-between-devices">native CRDT</a> support, meaning that you can deterministically <a href="https://beta.tinybase.org/guides/synchronization/">synchronize</a> and merge data across multiple sources, clients, and servers. And although TinyBase is an in-memory data store, you can easily <a href="#persist-to-storage-databases-more">persist</a> your data to file, <a href="https://beta.tinybase.org/api/persister-browser">browser storage</a>, <a href="https://beta.tinybase.org/api/persister-indexed-db">IndexedDB</a>, <a href="https://beta.tinybase.org/guides/persistence/database-persistence/">SQLite or PostgreSQL databases</a>, and <a href="https://beta.tinybase.org/guides/persistence/third-party-crdt-persistence/">more</a>.</p></section><section><h2 id="it-s-built-for-a-local-first-world">It's Built For A <em>Local-First</em> World</h2><p>TinyBase works anywhere that JavaScript does, but it's especially great for local-first apps: where data is stored locally on the user's device and that can be run offline. It's tiny by name, tiny by nature: just <a href="#did-we-say-tiny">5.4kB - 11.8kB</a> and with no dependencies - yet <a href="#well-tested-and-documented">100% tested</a>, <a href="https://beta.tinybase.org/guides/the-basics/getting-started/">fully documented</a>, and of course, <a href="https://github.com/tinyplex/tinybase">open source</a>!</p></section><hr><section id="friends"><h2 id="tinybase-works-great-on-its-own-but-also-plays-well-with-friends">TinyBase works great on its own, but also plays well with friends.</h2><div><a href="https://beta.tinybase.org/guides/building-uis/getting-started-with-ui-react"><img src="https://beta.tinybase.org/react.svg?asImg" width="48"> React</a></div><div><a href="https://beta.tinybase.org/api/persister-indexed-db/functions/creation/createindexeddbpersister"><img src="https://beta.tinybase.org/indexeddb.svg?asImg" width="48"> IndexedDB</a></div><div><a href="https://beta.tinybase.org/api/persister-browser"><img src="https://beta.tinybase.org/browser.svg?asImg" width="48"> OPFS</a></div><div><a href="https://beta.tinybase.org/guides/integrations/cloudflare-durable-objects"><img src="https://beta.tinybase.org/cloudflare.svg?asImg" width="48"> Cloudflare</a></div><div><a href="https://beta.tinybase.org/guides/schemas-and-persistence/database-persistence"><img src="https://beta.tinybase.org/postgresql.svg?asImg" width="48"> PostgreSQL</a></div><div><a href="https://beta.tinybase.org/guides/schemas-and-persistence/database-persistence"><img src="https://beta.tinybase.org/pglite.svg?asImg" width="48"> PGlite</a></div><div><a href="https://beta.tinybase.org/guides/schemas-and-persistence/database-persistence"><img src="https://beta.tinybase.org/sqlite.svg?asImg" width="48"> SQLite</a></div><div><a href="https://beta.tinybase.org/guides/schemas-and-persistence/database-persistence"><img src="https://beta.tinybase.org/bun.svg?asImg" width="48"> Bun SQLite</a></div><div><a href="https://beta.tinybase.org/guides/schemas-and-persistence/database-persistence"><img src="https://beta.tinybase.org/expo.svg?asImg" width="48"> Expo SQLite</a></div><div><a href="https://beta.tinybase.org/guides/schemas-and-persistence/database-persistence"><img src="https://beta.tinybase.org/electric.svg?asImg" width="48"> ElectricSQL</a></div><div><a href="https://beta.tinybase.org/guides/schemas-and-persistence/database-persistence"><img src="https://beta.tinybase.org/turso.svg?asImg" width="48"> Turso</a></div><div><a href="https://beta.tinybase.org/guides/schemas-and-persistence/database-persistence"><img src="https://beta.tinybase.org/powersync.svg?asImg" width="48"> PowerSync</a></div><div><a href="https://beta.tinybase.org/api/persister-partykit-client"><img src="https://beta.tinybase.org/partykit.svg?asImg" width="48"> PartyKit</a></div><div><a href="https://beta.tinybase.org/api/persister-yjs/functions/creation/createyjspersister"><img src="https://beta.tinybase.org/yjs.svg?asImg" width="48"> YJS</a></div><div><a href="https://beta.tinybase.org/api/persister-cr-sqlite-wasm"><img src="https://beta.tinybase.org/crsqlite.png" width="48"> CR-SQLite</a></div><div><a href="https://beta.tinybase.org/api/persister-automerge"><img src="https://beta.tinybase.org/automerge.svg?asImg" width="48"> Automerge</a></div><div><a href="https://beta.tinybase.org/api/schematizer-typebox/functions/creation/createtypeboxschematizer"><img src="https://beta.tinybase.org/typebox.svg?asImg" width="48"> TypeBox</a></div><div><a href="https://beta.tinybase.org/api/schematizer-valibot/functions/creation/createvalibotschematizer"><img src="https://beta.tinybase.org/valibot.svg?asImg" width="48"> Valibot</a></div><div><a href="https://beta.tinybase.org/api/schematizer-zod/functions/creation/createzodschematizer"><img src="https://beta.tinybase.org/zod.svg?asImg" width="48"> Zod</a></div><p>(Baffled by all these logos? Check out our <a href="https://beta.tinybase.org/guides/the-basics/architectural-options">architectural options</a> guide to make sense of it all!)</p></section><hr><section id="follow"><p><a href="https://github.com/tinyplex/tinybase" target="_blank"><img src="https://img.shields.io/github/stars/tinyplex/tinybase?style=for-the-badge&logo=GitHub&logoColor=%23fff&label=GitHub&labelColor=%23d81b60&color=%23333"></a></p><p><a href="https://bsky.app/profile/tinybase.bsky.social"><img src="https://img.shields.io/badge/Bluesky-Follow-blue?style=for-the-badge&logo=bluesky&logoColor=%23fff&color=%23333&labelColor=%230285FF"></a></p><p><a href="https://x.com/tinybasejs" target="_blank"><img src="https://img.shields.io/badge/%2F%20Twitter-Follow-blue?style=for-the-badge&logo=x&logoColor=%23fff&color=%23333&labelColor=%23000"></a></p><p><a href="https://discord.com/invite/mGz3mevwP8" target="_blank"><img src="https://img.shields.io/discord/1027918215323590676?style=for-the-badge&logo=discord&logoColor=%23fff&label=Discord&labelColor=%233131e8&color=%23333"></a></p><br><p><a href="https://github.com/tinyplex/tinybase/discussions" target="_blank"><img src="https://img.shields.io/github/discussions/tinyplex/tinybase?style=for-the-badge&logo=GitHub&logoColor=%23fff&label=Ideas&labelColor=%23d81b60&color=%23333"></a></p><p><a href="https://github.com/tinyplex/tinybase/issues" target="_blank"><img src="https://img.shields.io/github/issues/tinyplex/tinybase?style=for-the-badge&logo=GitHub&logoColor=%23fff&label=Issues&labelColor=%23d81b60&color=%23333"></a></p><p><a href="#well-tested-and-documented"><img src="https://img.shields.io/badge/Tests-100%25-green?style=for-the-badge&logo=Vitest&logoColor=%23fff&color=%23333&labelColor=%2387c305"></a></p><p><a href="https://www.npmjs.com/package/tinybase/v/7.1.0-beta.3" target="_blank"><img src="https://img.shields.io/npm/v/tinybase?style=for-the-badge&logo=npm&logoColor=%23fff&labelColor=%23bd0005&color=%23333"></a></p></section><hr><section><h2 id="start-with-a-simple-key-value-store">Start with a simple key-value store.</h2><p>Creating a <a href="https://beta.tinybase.org/api/the-essentials/creating-stores/store/"><code>Store</code></a> requires just a simple call to the <a href="https://beta.tinybase.org/api/the-essentials/creating-stores/createstore/"><code>createStore</code></a> function. Once you have one, you can easily set <a href="https://beta.tinybase.org/api/store/type-aliases/store/values/"><code>Values</code></a> in it by unique <a href="https://beta.tinybase.org/api/common/type-aliases/identity/id/"><code>Id</code></a>. And of course you can easily get them back out again.</p><p>Read more about using keyed value data in <a href="https://beta.tinybase.org/guides/the-basics/">The Basics</a> guide.</p></section>
|
|
2
2
|
|
|
3
3
|
```js
|
|
4
4
|
import {createStore} from 'tinybase';
|
package/relationships/index.js
CHANGED
|
@@ -43,7 +43,7 @@ const mapGet = (map, key) => map?.get(key);
|
|
|
43
43
|
const mapForEach = (map, cb) =>
|
|
44
44
|
collForEach(map, (value, key) => cb(key, value));
|
|
45
45
|
const mapSet = (map, key, value) =>
|
|
46
|
-
value
|
|
46
|
+
isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
|
|
47
47
|
const mapEnsure = (map, key, getDefaultValue, hadExistingValue) => {
|
|
48
48
|
if (!collHas(map, key)) {
|
|
49
49
|
mapSet(map, key, getDefaultValue());
|
|
@@ -272,7 +272,7 @@ const getWildcardedLeaves = (deepIdSet, path = [EMPTY_STRING]) => {
|
|
|
272
272
|
const deep = (node, p) =>
|
|
273
273
|
p == size(path)
|
|
274
274
|
? arrayPush(leaves, node)
|
|
275
|
-
: path[p]
|
|
275
|
+
: isNull(path[p])
|
|
276
276
|
? collForEach(node, (node2) => deep(node2, p + 1))
|
|
277
277
|
: arrayForEach([path[p], null], (id) => deep(mapGet(node, id), p + 1));
|
|
278
278
|
deep(deepIdSet, 0);
|
|
@@ -43,7 +43,7 @@ const mapGet = (map, key) => map?.get(key);
|
|
|
43
43
|
const mapForEach = (map, cb) =>
|
|
44
44
|
collForEach(map, (value, key) => cb(key, value));
|
|
45
45
|
const mapSet = (map, key, value) =>
|
|
46
|
-
value
|
|
46
|
+
isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
|
|
47
47
|
const mapEnsure = (map, key, getDefaultValue, hadExistingValue) => {
|
|
48
48
|
if (!collHas(map, key)) {
|
|
49
49
|
mapSet(map, key, getDefaultValue());
|
|
@@ -272,7 +272,7 @@ const getWildcardedLeaves = (deepIdSet, path = [EMPTY_STRING]) => {
|
|
|
272
272
|
const deep = (node, p) =>
|
|
273
273
|
p == size(path)
|
|
274
274
|
? arrayPush(leaves, node)
|
|
275
|
-
: path[p]
|
|
275
|
+
: isNull(path[p])
|
|
276
276
|
? collForEach(node, (node2) => deep(node2, p + 1))
|
|
277
277
|
: arrayForEach([path[p], null], (id) => deep(mapGet(node, id), p + 1));
|
|
278
278
|
deep(deepIdSet, 0);
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
const getTypeOf = (thing) => typeof thing;
|
|
2
|
+
const EMPTY_STRING = '';
|
|
3
|
+
const STRING = getTypeOf(EMPTY_STRING);
|
|
4
|
+
const BOOLEAN = getTypeOf(true);
|
|
5
|
+
const NUMBER = getTypeOf(0);
|
|
6
|
+
const TYPE = 'type';
|
|
7
|
+
const DEFAULT = 'default';
|
|
8
|
+
const ALLOW_NULL = 'allowNull';
|
|
9
|
+
const _VALUE = 'value';
|
|
10
|
+
const DOMAIN = 'domain';
|
|
11
|
+
const KEY = 'key';
|
|
12
|
+
const OPTIONAL = 'optional';
|
|
13
|
+
const REQUIRED = 'required';
|
|
14
|
+
const UNIT = 'unit';
|
|
15
|
+
|
|
16
|
+
const getIfNotFunction = (predicate) => (value, then, otherwise) =>
|
|
17
|
+
predicate(value) ? otherwise?.() : then(value);
|
|
18
|
+
const isNullish = (thing) => thing == null;
|
|
19
|
+
const isUndefined = (thing) => thing === void 0;
|
|
20
|
+
const isNull = (thing) => thing === null;
|
|
21
|
+
const isTrue = (thing) => thing === true;
|
|
22
|
+
const isFalse = (thing) => thing === false;
|
|
23
|
+
const ifNotNullish = getIfNotFunction(isNullish);
|
|
24
|
+
const ifNotUndefined = getIfNotFunction(isUndefined);
|
|
25
|
+
const isArray = (thing) => Array.isArray(thing);
|
|
26
|
+
const size = (arrayOrString) => arrayOrString.length;
|
|
27
|
+
|
|
28
|
+
const arrayEvery = (array, cb) => array.every(cb);
|
|
29
|
+
const arrayForEach = (array, cb) => array.forEach(cb);
|
|
30
|
+
const arrayFind = (array, cb) => array.find(cb);
|
|
31
|
+
|
|
32
|
+
const object = Object;
|
|
33
|
+
const getPrototypeOf = (obj) => object.getPrototypeOf(obj);
|
|
34
|
+
const objEntries = object.entries;
|
|
35
|
+
const isObject = (obj) =>
|
|
36
|
+
!isNullish(obj) &&
|
|
37
|
+
ifNotNullish(
|
|
38
|
+
getPrototypeOf(obj),
|
|
39
|
+
(objPrototype) =>
|
|
40
|
+
objPrototype == object.prototype ||
|
|
41
|
+
isNullish(getPrototypeOf(objPrototype)),
|
|
42
|
+
|
|
43
|
+
/* istanbul ignore next */
|
|
44
|
+
() => true,
|
|
45
|
+
);
|
|
46
|
+
const objIds = object.keys;
|
|
47
|
+
const objFreeze = object.freeze;
|
|
48
|
+
const objNew = (entries = []) => object.fromEntries(entries);
|
|
49
|
+
const objForEach = (obj, cb) =>
|
|
50
|
+
arrayForEach(objEntries(obj), ([id, value]) => cb(value, id));
|
|
51
|
+
const objSize = (obj) => size(objIds(obj));
|
|
52
|
+
const objIsEmpty = (obj) => isObject(obj) && objSize(obj) == 0;
|
|
53
|
+
|
|
54
|
+
const createCustomSchematizer = (unwrapSchema, getProperties) => {
|
|
55
|
+
const toCellOrValueSchema = (schema) => {
|
|
56
|
+
const [unwrapped, defaultValue, allowNull] = unwrapSchema(schema);
|
|
57
|
+
const type = unwrapped?.type;
|
|
58
|
+
if (type !== STRING && type !== NUMBER && type !== BOOLEAN) {
|
|
59
|
+
return void 0;
|
|
60
|
+
}
|
|
61
|
+
const cellOrValueSchema = {[TYPE]: type};
|
|
62
|
+
ifNotUndefined(defaultValue, (defaultValue2) => {
|
|
63
|
+
cellOrValueSchema[DEFAULT] = defaultValue2;
|
|
64
|
+
});
|
|
65
|
+
if (allowNull) {
|
|
66
|
+
cellOrValueSchema[ALLOW_NULL] = true;
|
|
67
|
+
}
|
|
68
|
+
return cellOrValueSchema;
|
|
69
|
+
};
|
|
70
|
+
const toTablesSchema = (schemas) => {
|
|
71
|
+
const tablesSchema = objNew();
|
|
72
|
+
objForEach(schemas, (schema, tableId) => {
|
|
73
|
+
const tableSchema = objNew();
|
|
74
|
+
ifNotUndefined(getProperties(schema), (properties) =>
|
|
75
|
+
objForEach(properties, (cellSchema, cellId) =>
|
|
76
|
+
ifNotUndefined(toCellOrValueSchema(cellSchema), (cellSchema2) => {
|
|
77
|
+
tableSchema[cellId] = cellSchema2;
|
|
78
|
+
}),
|
|
79
|
+
),
|
|
80
|
+
);
|
|
81
|
+
if (!objIsEmpty(tableSchema)) {
|
|
82
|
+
tablesSchema[tableId] = tableSchema;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
return tablesSchema;
|
|
86
|
+
};
|
|
87
|
+
const toValuesSchema = (schemas) => {
|
|
88
|
+
const valuesSchema = objNew();
|
|
89
|
+
objForEach(schemas, (schema, valueId) =>
|
|
90
|
+
ifNotUndefined(toCellOrValueSchema(schema), (valueSchema) => {
|
|
91
|
+
valuesSchema[valueId] = valueSchema;
|
|
92
|
+
}),
|
|
93
|
+
);
|
|
94
|
+
return valuesSchema;
|
|
95
|
+
};
|
|
96
|
+
return objFreeze({
|
|
97
|
+
toTablesSchema,
|
|
98
|
+
toValuesSchema,
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const unwrapSchema = (schema, defaultValue, allowNull) => {
|
|
103
|
+
if (isArray(schema)) {
|
|
104
|
+
const hasNull = !arrayEvery(
|
|
105
|
+
schema,
|
|
106
|
+
(item) => !isNull(item?.[UNIT]) && !isNull(item),
|
|
107
|
+
);
|
|
108
|
+
if (
|
|
109
|
+
size(schema) === 2 &&
|
|
110
|
+
isFalse(schema[0]?.[UNIT]) &&
|
|
111
|
+
isTrue(schema[1]?.[UNIT])
|
|
112
|
+
) {
|
|
113
|
+
return [{[TYPE]: BOOLEAN}, defaultValue, allowNull ?? false];
|
|
114
|
+
}
|
|
115
|
+
if (hasNull) {
|
|
116
|
+
const nonNullItem = arrayFind(
|
|
117
|
+
schema,
|
|
118
|
+
(item) => !isNull(item?.[UNIT]) && !isNull(item) && item !== '=',
|
|
119
|
+
);
|
|
120
|
+
if (nonNullItem) {
|
|
121
|
+
return unwrapSchema(nonNullItem, defaultValue, true);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return [
|
|
126
|
+
{[TYPE]: schema?.[DOMAIN] || schema},
|
|
127
|
+
defaultValue,
|
|
128
|
+
allowNull ?? false,
|
|
129
|
+
];
|
|
130
|
+
};
|
|
131
|
+
const getProperties = (schema) => {
|
|
132
|
+
const properties = objNew();
|
|
133
|
+
const schemaData = schema?.json ?? schema;
|
|
134
|
+
if (schemaData?.[REQUIRED]) {
|
|
135
|
+
arrayForEach(schemaData[REQUIRED], (field) => {
|
|
136
|
+
properties[field[KEY]] = field[_VALUE];
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
if (schemaData?.[OPTIONAL]) {
|
|
140
|
+
arrayForEach(schemaData[OPTIONAL], (field) => {
|
|
141
|
+
const value = field[_VALUE];
|
|
142
|
+
const defaultVal = field[DEFAULT];
|
|
143
|
+
properties[field[KEY]] = !isUndefined(defaultVal)
|
|
144
|
+
? {[_VALUE]: value, [DEFAULT]: defaultVal}
|
|
145
|
+
: value;
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
return objIsEmpty(properties) ? void 0 : properties;
|
|
149
|
+
};
|
|
150
|
+
const unwrapSchemaWithDefaults = (schema, defaultValue, allowNull) => {
|
|
151
|
+
if (isArray(schema) && size(schema) === 3 && schema[1] === '=') {
|
|
152
|
+
const schemaValue = schema[0]?.json ?? schema[0];
|
|
153
|
+
return unwrapSchema(schemaValue, schema[2], allowNull);
|
|
154
|
+
}
|
|
155
|
+
if (schema?.[_VALUE] && !isUndefined(schema?.[DEFAULT])) {
|
|
156
|
+
return unwrapSchema(schema[_VALUE], schema[DEFAULT], allowNull);
|
|
157
|
+
}
|
|
158
|
+
return unwrapSchema(schema, defaultValue, allowNull);
|
|
159
|
+
};
|
|
160
|
+
const createArkTypeSchematizer = () =>
|
|
161
|
+
createCustomSchematizer(unwrapSchemaWithDefaults, getProperties);
|
|
162
|
+
|
|
163
|
+
export {createArkTypeSchematizer};
|