tinybase 9.4.0-beta.1 → 9.4.0
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/persisters/index.d.ts +4 -0
- package/@types/persisters/persister-durable-object-sql-storage/index.d.ts +9 -2
- package/@types/persisters/persister-durable-object-sql-storage/with-schemas/index.d.ts +9 -2
- package/@types/persisters/with-schemas/index.d.ts +4 -0
- package/@types/queries/index.d.ts +4 -0
- package/@types/queries/with-schemas/index.d.ts +4 -0
- package/@types/synchronizers/synchronizer-ws-client/index.d.ts +7 -3
- package/@types/synchronizers/synchronizer-ws-client/with-schemas/index.d.ts +7 -3
- package/@types/synchronizers/synchronizer-ws-server/index.d.ts +9 -3
- package/@types/synchronizers/synchronizer-ws-server/with-schemas/index.d.ts +9 -3
- package/@types/synchronizers/synchronizer-ws-server-simple/index.d.ts +6 -3
- package/@types/synchronizers/synchronizer-ws-server-simple/with-schemas/index.d.ts +6 -3
- package/@types/ui-react-dom/index.d.ts +10 -10
- package/@types/ui-react-dom/with-schemas/index.d.ts +10 -10
- package/@types/ui-react-dom-charts/index.d.ts +7 -7
- package/@types/ui-react-dom-charts/with-schemas/index.d.ts +7 -7
- package/@types/ui-react-inspector/index.d.ts +1 -1
- package/@types/ui-react-inspector/with-schemas/index.d.ts +1 -1
- package/@types/ui-solid-dom/index.d.ts +10 -10
- package/@types/ui-solid-dom/with-schemas/index.d.ts +10 -10
- package/@types/ui-solid-inspector/index.d.ts +1 -1
- package/@types/ui-solid-inspector/with-schemas/index.d.ts +1 -1
- package/@types/ui-svelte-dom/index.d.ts +10 -10
- package/@types/ui-svelte-dom/with-schemas/index.d.ts +10 -10
- package/@types/ui-svelte-inspector/index.d.ts +1 -1
- package/@types/ui-svelte-inspector/with-schemas/index.d.ts +1 -1
- package/index.js +191 -74
- package/min/index.js +1 -1
- package/min/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/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-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/ui-solid-inspector/index.js +1 -1
- package/min/ui-solid-inspector/index.js.gz +0 -0
- package/min/ui-solid-inspector/with-schemas/index.js +1 -1
- package/min/ui-solid-inspector/with-schemas/index.js.gz +0 -0
- package/min/ui-svelte-inspector/index.js +1 -1
- package/min/ui-svelte-inspector/index.js.gz +0 -0
- package/min/ui-svelte-inspector/with-schemas/index.js +1 -1
- package/min/ui-svelte-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 +606 -179
- package/omni/with-schemas/index.js +606 -179
- package/package.json +12 -8
- package/persisters/index.js +49 -10
- package/persisters/persister-automerge/index.js +29 -5
- package/persisters/persister-automerge/with-schemas/index.js +29 -5
- package/persisters/persister-browser/index.js +29 -5
- package/persisters/persister-browser/with-schemas/index.js +29 -5
- package/persisters/persister-cr-sqlite-wasm/index.js +29 -5
- package/persisters/persister-cr-sqlite-wasm/with-schemas/index.js +29 -5
- package/persisters/persister-durable-object-sql-storage/index.js +44 -8
- package/persisters/persister-durable-object-sql-storage/with-schemas/index.js +44 -8
- package/persisters/persister-durable-object-storage/index.js +31 -5
- package/persisters/persister-durable-object-storage/with-schemas/index.js +31 -5
- package/persisters/persister-electric-sql/index.js +29 -5
- package/persisters/persister-electric-sql/with-schemas/index.js +29 -5
- package/persisters/persister-expo-sqlite/index.js +29 -5
- package/persisters/persister-expo-sqlite/with-schemas/index.js +29 -5
- package/persisters/persister-file/index.js +31 -5
- package/persisters/persister-file/with-schemas/index.js +31 -5
- package/persisters/persister-indexed-db/index.js +29 -5
- package/persisters/persister-indexed-db/with-schemas/index.js +29 -5
- package/persisters/persister-libsql/index.js +29 -5
- package/persisters/persister-libsql/with-schemas/index.js +29 -5
- package/persisters/persister-partykit-client/index.js +31 -5
- package/persisters/persister-partykit-client/with-schemas/index.js +31 -5
- package/persisters/persister-pglite/index.js +49 -10
- package/persisters/persister-pglite/with-schemas/index.js +49 -10
- package/persisters/persister-postgres/index.js +49 -10
- package/persisters/persister-postgres/with-schemas/index.js +49 -10
- package/persisters/persister-powersync/index.js +29 -5
- package/persisters/persister-powersync/with-schemas/index.js +29 -5
- package/persisters/persister-react-native-mmkv/index.js +31 -5
- package/persisters/persister-react-native-mmkv/with-schemas/index.js +31 -5
- package/persisters/persister-react-native-sqlite/index.js +29 -5
- package/persisters/persister-react-native-sqlite/with-schemas/index.js +29 -5
- package/persisters/persister-remote/index.js +31 -5
- package/persisters/persister-remote/with-schemas/index.js +31 -5
- package/persisters/persister-sqlite-bun/index.js +29 -5
- package/persisters/persister-sqlite-bun/with-schemas/index.js +29 -5
- package/persisters/persister-sqlite-wasm/index.js +29 -5
- package/persisters/persister-sqlite-wasm/with-schemas/index.js +29 -5
- package/persisters/persister-sqlite3/index.js +29 -5
- package/persisters/persister-sqlite3/with-schemas/index.js +29 -5
- package/persisters/persister-yjs/index.js +29 -5
- package/persisters/persister-yjs/with-schemas/index.js +29 -5
- package/persisters/with-schemas/index.js +49 -10
- package/queries/index.js +205 -74
- package/queries/with-schemas/index.js +205 -74
- package/readme.md +14 -14
- package/releases.md +84 -67
- package/synchronizers/index.js +31 -5
- package/synchronizers/synchronizer-broadcast-channel/index.js +39 -13
- package/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +39 -13
- package/synchronizers/synchronizer-local/index.js +31 -5
- package/synchronizers/synchronizer-local/with-schemas/index.js +31 -5
- package/synchronizers/synchronizer-ws-client/index.js +220 -61
- package/synchronizers/synchronizer-ws-client/with-schemas/index.js +220 -61
- package/synchronizers/synchronizer-ws-server/index.js +253 -73
- package/synchronizers/synchronizer-ws-server/with-schemas/index.js +253 -73
- package/synchronizers/synchronizer-ws-server-durable-object/index.js +88 -40
- package/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +88 -40
- package/synchronizers/synchronizer-ws-server-simple/index.js +184 -60
- package/synchronizers/synchronizer-ws-server-simple/with-schemas/index.js +184 -60
- package/synchronizers/with-schemas/index.js +31 -5
- package/ui-react-inspector/index.js +29 -5
- package/ui-react-inspector/with-schemas/index.js +29 -5
- package/ui-solid-inspector/index.js +29 -5
- package/ui-solid-inspector/with-schemas/index.js +29 -5
- package/ui-svelte-inspector/index.js +29 -5
- package/ui-svelte-inspector/with-schemas/index.js +29 -5
- package/with-schemas/index.js +191 -74
|
@@ -829,11 +829,35 @@ const createCustomPersister = (
|
|
|
829
829
|
initialContent,
|
|
830
830
|
startSaveFirst = false,
|
|
831
831
|
) => {
|
|
832
|
-
const [call1, call2] = startSaveFirst
|
|
833
|
-
? [startAutoSave, startAutoLoad]
|
|
834
|
-
: [startAutoLoad, startAutoSave];
|
|
835
|
-
|
|
836
|
-
|
|
832
|
+
const [call1, call2, stop1, stop2] = startSaveFirst
|
|
833
|
+
? [startAutoSave, startAutoLoad, stopAutoSave, stopAutoLoad]
|
|
834
|
+
: [startAutoLoad, startAutoSave, stopAutoLoad, stopAutoSave];
|
|
835
|
+
const start1 = call1(initialContent);
|
|
836
|
+
const generation1 = startSaveFirst
|
|
837
|
+
? autoSaveGeneration
|
|
838
|
+
: autoLoadGeneration;
|
|
839
|
+
await start1;
|
|
840
|
+
const start2 = call2(initialContent);
|
|
841
|
+
const generation2 = startSaveFirst
|
|
842
|
+
? autoLoadGeneration
|
|
843
|
+
: autoSaveGeneration;
|
|
844
|
+
try {
|
|
845
|
+
await start2;
|
|
846
|
+
} catch (error) {
|
|
847
|
+
if (
|
|
848
|
+
generation2 ==
|
|
849
|
+
(startSaveFirst ? autoLoadGeneration : autoSaveGeneration)
|
|
850
|
+
) {
|
|
851
|
+
await tryCatchIgnore(stop2);
|
|
852
|
+
}
|
|
853
|
+
if (
|
|
854
|
+
generation1 ==
|
|
855
|
+
(startSaveFirst ? autoSaveGeneration : autoLoadGeneration)
|
|
856
|
+
) {
|
|
857
|
+
await tryCatchIgnore(stop1);
|
|
858
|
+
}
|
|
859
|
+
throw error;
|
|
860
|
+
}
|
|
837
861
|
return persister;
|
|
838
862
|
};
|
|
839
863
|
const stopAutoPersisting = async (stopSaveFirst = false) => {
|
|
@@ -1545,6 +1569,8 @@ const createTabularPersister = (
|
|
|
1545
1569
|
const TABLE_CREATED = 'c';
|
|
1546
1570
|
const DATA_CHANGED = 'd';
|
|
1547
1571
|
const EVENT_REGEX = /^([cd]:)(.+)/;
|
|
1572
|
+
const SIMPLE_TABLE_NAME = /^[A-Za-z0-9_]+$/;
|
|
1573
|
+
const POSTGRES_IDENTIFIER_SIZE = 63;
|
|
1548
1574
|
const listenerResourcesByThing = mapNew();
|
|
1549
1575
|
const createCustomPostgreSqlPersister = (
|
|
1550
1576
|
store,
|
|
@@ -1617,17 +1643,30 @@ const createCustomPostgreSqlPersister = (
|
|
|
1617
1643
|
);
|
|
1618
1644
|
const addDataChangedTriggers = (tableName, dataChangedFunction) =>
|
|
1619
1645
|
promiseAll(
|
|
1620
|
-
arrayMap([INSERT, DELETE, UPDATE], (action, newOrOldOrBoth) =>
|
|
1621
|
-
|
|
1646
|
+
arrayMap([INSERT, DELETE, UPDATE], (action, newOrOldOrBoth) => {
|
|
1647
|
+
const legacyTriggerId = arrayJoin(
|
|
1648
|
+
[TINYBASE, DATA_CHANGED, configHash, tableName, action],
|
|
1649
|
+
'_',
|
|
1650
|
+
);
|
|
1651
|
+
return createTrigger(
|
|
1622
1652
|
OR_REPLACE,
|
|
1623
|
-
|
|
1653
|
+
test(SIMPLE_TABLE_NAME, tableName) &&
|
|
1654
|
+
size(legacyTriggerId) <= POSTGRES_IDENTIFIER_SIZE
|
|
1655
|
+
? escapeId(legacyTriggerId)
|
|
1656
|
+
: escapeIds(
|
|
1657
|
+
TINYBASE,
|
|
1658
|
+
DATA_CHANGED,
|
|
1659
|
+
configHash,
|
|
1660
|
+
action,
|
|
1661
|
+
EMPTY_STRING + getHash(tableName),
|
|
1662
|
+
),
|
|
1624
1663
|
`AFTER ${action} ON${escapeId(tableName)}FOR EACH ROW WHEN(${when(
|
|
1625
1664
|
tableName,
|
|
1626
1665
|
newOrOldOrBoth,
|
|
1627
1666
|
)})`,
|
|
1628
1667
|
dataChangedFunction,
|
|
1629
|
-
)
|
|
1630
|
-
),
|
|
1668
|
+
);
|
|
1669
|
+
}),
|
|
1631
1670
|
);
|
|
1632
1671
|
const dropFunctions = async (functionNames) => {
|
|
1633
1672
|
if (!isEmpty(functionNames)) {
|
|
@@ -829,11 +829,35 @@ const createCustomPersister = (
|
|
|
829
829
|
initialContent,
|
|
830
830
|
startSaveFirst = false,
|
|
831
831
|
) => {
|
|
832
|
-
const [call1, call2] = startSaveFirst
|
|
833
|
-
? [startAutoSave, startAutoLoad]
|
|
834
|
-
: [startAutoLoad, startAutoSave];
|
|
835
|
-
|
|
836
|
-
|
|
832
|
+
const [call1, call2, stop1, stop2] = startSaveFirst
|
|
833
|
+
? [startAutoSave, startAutoLoad, stopAutoSave, stopAutoLoad]
|
|
834
|
+
: [startAutoLoad, startAutoSave, stopAutoLoad, stopAutoSave];
|
|
835
|
+
const start1 = call1(initialContent);
|
|
836
|
+
const generation1 = startSaveFirst
|
|
837
|
+
? autoSaveGeneration
|
|
838
|
+
: autoLoadGeneration;
|
|
839
|
+
await start1;
|
|
840
|
+
const start2 = call2(initialContent);
|
|
841
|
+
const generation2 = startSaveFirst
|
|
842
|
+
? autoLoadGeneration
|
|
843
|
+
: autoSaveGeneration;
|
|
844
|
+
try {
|
|
845
|
+
await start2;
|
|
846
|
+
} catch (error) {
|
|
847
|
+
if (
|
|
848
|
+
generation2 ==
|
|
849
|
+
(startSaveFirst ? autoLoadGeneration : autoSaveGeneration)
|
|
850
|
+
) {
|
|
851
|
+
await tryCatchIgnore(stop2);
|
|
852
|
+
}
|
|
853
|
+
if (
|
|
854
|
+
generation1 ==
|
|
855
|
+
(startSaveFirst ? autoSaveGeneration : autoLoadGeneration)
|
|
856
|
+
) {
|
|
857
|
+
await tryCatchIgnore(stop1);
|
|
858
|
+
}
|
|
859
|
+
throw error;
|
|
860
|
+
}
|
|
837
861
|
return persister;
|
|
838
862
|
};
|
|
839
863
|
const stopAutoPersisting = async (stopSaveFirst = false) => {
|
|
@@ -1545,6 +1569,8 @@ const createTabularPersister = (
|
|
|
1545
1569
|
const TABLE_CREATED = 'c';
|
|
1546
1570
|
const DATA_CHANGED = 'd';
|
|
1547
1571
|
const EVENT_REGEX = /^([cd]:)(.+)/;
|
|
1572
|
+
const SIMPLE_TABLE_NAME = /^[A-Za-z0-9_]+$/;
|
|
1573
|
+
const POSTGRES_IDENTIFIER_SIZE = 63;
|
|
1548
1574
|
const listenerResourcesByThing = mapNew();
|
|
1549
1575
|
const createCustomPostgreSqlPersister = (
|
|
1550
1576
|
store,
|
|
@@ -1617,17 +1643,30 @@ const createCustomPostgreSqlPersister = (
|
|
|
1617
1643
|
);
|
|
1618
1644
|
const addDataChangedTriggers = (tableName, dataChangedFunction) =>
|
|
1619
1645
|
promiseAll(
|
|
1620
|
-
arrayMap([INSERT, DELETE, UPDATE], (action, newOrOldOrBoth) =>
|
|
1621
|
-
|
|
1646
|
+
arrayMap([INSERT, DELETE, UPDATE], (action, newOrOldOrBoth) => {
|
|
1647
|
+
const legacyTriggerId = arrayJoin(
|
|
1648
|
+
[TINYBASE, DATA_CHANGED, configHash, tableName, action],
|
|
1649
|
+
'_',
|
|
1650
|
+
);
|
|
1651
|
+
return createTrigger(
|
|
1622
1652
|
OR_REPLACE,
|
|
1623
|
-
|
|
1653
|
+
test(SIMPLE_TABLE_NAME, tableName) &&
|
|
1654
|
+
size(legacyTriggerId) <= POSTGRES_IDENTIFIER_SIZE
|
|
1655
|
+
? escapeId(legacyTriggerId)
|
|
1656
|
+
: escapeIds(
|
|
1657
|
+
TINYBASE,
|
|
1658
|
+
DATA_CHANGED,
|
|
1659
|
+
configHash,
|
|
1660
|
+
action,
|
|
1661
|
+
EMPTY_STRING + getHash(tableName),
|
|
1662
|
+
),
|
|
1624
1663
|
`AFTER ${action} ON${escapeId(tableName)}FOR EACH ROW WHEN(${when(
|
|
1625
1664
|
tableName,
|
|
1626
1665
|
newOrOldOrBoth,
|
|
1627
1666
|
)})`,
|
|
1628
1667
|
dataChangedFunction,
|
|
1629
|
-
)
|
|
1630
|
-
),
|
|
1668
|
+
);
|
|
1669
|
+
}),
|
|
1631
1670
|
);
|
|
1632
1671
|
const dropFunctions = async (functionNames) => {
|
|
1633
1672
|
if (!isEmpty(functionNames)) {
|
|
@@ -826,11 +826,35 @@ const createCustomPersister = (
|
|
|
826
826
|
initialContent,
|
|
827
827
|
startSaveFirst = false,
|
|
828
828
|
) => {
|
|
829
|
-
const [call1, call2] = startSaveFirst
|
|
830
|
-
? [startAutoSave, startAutoLoad]
|
|
831
|
-
: [startAutoLoad, startAutoSave];
|
|
832
|
-
|
|
833
|
-
|
|
829
|
+
const [call1, call2, stop1, stop2] = startSaveFirst
|
|
830
|
+
? [startAutoSave, startAutoLoad, stopAutoSave, stopAutoLoad]
|
|
831
|
+
: [startAutoLoad, startAutoSave, stopAutoLoad, stopAutoSave];
|
|
832
|
+
const start1 = call1(initialContent);
|
|
833
|
+
const generation1 = startSaveFirst
|
|
834
|
+
? autoSaveGeneration
|
|
835
|
+
: autoLoadGeneration;
|
|
836
|
+
await start1;
|
|
837
|
+
const start2 = call2(initialContent);
|
|
838
|
+
const generation2 = startSaveFirst
|
|
839
|
+
? autoLoadGeneration
|
|
840
|
+
: autoSaveGeneration;
|
|
841
|
+
try {
|
|
842
|
+
await start2;
|
|
843
|
+
} catch (error) {
|
|
844
|
+
if (
|
|
845
|
+
generation2 ==
|
|
846
|
+
(startSaveFirst ? autoLoadGeneration : autoSaveGeneration)
|
|
847
|
+
) {
|
|
848
|
+
await tryCatchIgnore(stop2);
|
|
849
|
+
}
|
|
850
|
+
if (
|
|
851
|
+
generation1 ==
|
|
852
|
+
(startSaveFirst ? autoSaveGeneration : autoLoadGeneration)
|
|
853
|
+
) {
|
|
854
|
+
await tryCatchIgnore(stop1);
|
|
855
|
+
}
|
|
856
|
+
throw error;
|
|
857
|
+
}
|
|
834
858
|
return persister;
|
|
835
859
|
};
|
|
836
860
|
const stopAutoPersisting = async (stopSaveFirst = false) => {
|
|
@@ -826,11 +826,35 @@ const createCustomPersister = (
|
|
|
826
826
|
initialContent,
|
|
827
827
|
startSaveFirst = false,
|
|
828
828
|
) => {
|
|
829
|
-
const [call1, call2] = startSaveFirst
|
|
830
|
-
? [startAutoSave, startAutoLoad]
|
|
831
|
-
: [startAutoLoad, startAutoSave];
|
|
832
|
-
|
|
833
|
-
|
|
829
|
+
const [call1, call2, stop1, stop2] = startSaveFirst
|
|
830
|
+
? [startAutoSave, startAutoLoad, stopAutoSave, stopAutoLoad]
|
|
831
|
+
: [startAutoLoad, startAutoSave, stopAutoLoad, stopAutoSave];
|
|
832
|
+
const start1 = call1(initialContent);
|
|
833
|
+
const generation1 = startSaveFirst
|
|
834
|
+
? autoSaveGeneration
|
|
835
|
+
: autoLoadGeneration;
|
|
836
|
+
await start1;
|
|
837
|
+
const start2 = call2(initialContent);
|
|
838
|
+
const generation2 = startSaveFirst
|
|
839
|
+
? autoLoadGeneration
|
|
840
|
+
: autoSaveGeneration;
|
|
841
|
+
try {
|
|
842
|
+
await start2;
|
|
843
|
+
} catch (error) {
|
|
844
|
+
if (
|
|
845
|
+
generation2 ==
|
|
846
|
+
(startSaveFirst ? autoLoadGeneration : autoSaveGeneration)
|
|
847
|
+
) {
|
|
848
|
+
await tryCatchIgnore(stop2);
|
|
849
|
+
}
|
|
850
|
+
if (
|
|
851
|
+
generation1 ==
|
|
852
|
+
(startSaveFirst ? autoSaveGeneration : autoLoadGeneration)
|
|
853
|
+
) {
|
|
854
|
+
await tryCatchIgnore(stop1);
|
|
855
|
+
}
|
|
856
|
+
throw error;
|
|
857
|
+
}
|
|
834
858
|
return persister;
|
|
835
859
|
};
|
|
836
860
|
const stopAutoPersisting = async (stopSaveFirst = false) => {
|
|
@@ -51,6 +51,8 @@ const tryCatch = async (action, onError) => {
|
|
|
51
51
|
onError?.(error);
|
|
52
52
|
}
|
|
53
53
|
};
|
|
54
|
+
const tryCatchIgnore = (action, onIgnoredError) =>
|
|
55
|
+
tryCatch(action, (error) => void tryCatch(() => onIgnoredError?.(error)));
|
|
54
56
|
const tryCatchSync = (action, onError) => {
|
|
55
57
|
try {
|
|
56
58
|
return action();
|
|
@@ -623,11 +625,35 @@ const createCustomPersister = (
|
|
|
623
625
|
initialContent,
|
|
624
626
|
startSaveFirst = false,
|
|
625
627
|
) => {
|
|
626
|
-
const [call1, call2] = startSaveFirst
|
|
627
|
-
? [startAutoSave, startAutoLoad]
|
|
628
|
-
: [startAutoLoad, startAutoSave];
|
|
629
|
-
|
|
630
|
-
|
|
628
|
+
const [call1, call2, stop1, stop2] = startSaveFirst
|
|
629
|
+
? [startAutoSave, startAutoLoad, stopAutoSave, stopAutoLoad]
|
|
630
|
+
: [startAutoLoad, startAutoSave, stopAutoLoad, stopAutoSave];
|
|
631
|
+
const start1 = call1(initialContent);
|
|
632
|
+
const generation1 = startSaveFirst
|
|
633
|
+
? autoSaveGeneration
|
|
634
|
+
: autoLoadGeneration;
|
|
635
|
+
await start1;
|
|
636
|
+
const start2 = call2(initialContent);
|
|
637
|
+
const generation2 = startSaveFirst
|
|
638
|
+
? autoLoadGeneration
|
|
639
|
+
: autoSaveGeneration;
|
|
640
|
+
try {
|
|
641
|
+
await start2;
|
|
642
|
+
} catch (error) {
|
|
643
|
+
if (
|
|
644
|
+
generation2 ==
|
|
645
|
+
(startSaveFirst ? autoLoadGeneration : autoSaveGeneration)
|
|
646
|
+
) {
|
|
647
|
+
await tryCatchIgnore(stop2);
|
|
648
|
+
}
|
|
649
|
+
if (
|
|
650
|
+
generation1 ==
|
|
651
|
+
(startSaveFirst ? autoSaveGeneration : autoLoadGeneration)
|
|
652
|
+
) {
|
|
653
|
+
await tryCatchIgnore(stop1);
|
|
654
|
+
}
|
|
655
|
+
throw error;
|
|
656
|
+
}
|
|
631
657
|
return persister;
|
|
632
658
|
};
|
|
633
659
|
const stopAutoPersisting = async (stopSaveFirst = false) => {
|
|
@@ -51,6 +51,8 @@ const tryCatch = async (action, onError) => {
|
|
|
51
51
|
onError?.(error);
|
|
52
52
|
}
|
|
53
53
|
};
|
|
54
|
+
const tryCatchIgnore = (action, onIgnoredError) =>
|
|
55
|
+
tryCatch(action, (error) => void tryCatch(() => onIgnoredError?.(error)));
|
|
54
56
|
const tryCatchSync = (action, onError) => {
|
|
55
57
|
try {
|
|
56
58
|
return action();
|
|
@@ -623,11 +625,35 @@ const createCustomPersister = (
|
|
|
623
625
|
initialContent,
|
|
624
626
|
startSaveFirst = false,
|
|
625
627
|
) => {
|
|
626
|
-
const [call1, call2] = startSaveFirst
|
|
627
|
-
? [startAutoSave, startAutoLoad]
|
|
628
|
-
: [startAutoLoad, startAutoSave];
|
|
629
|
-
|
|
630
|
-
|
|
628
|
+
const [call1, call2, stop1, stop2] = startSaveFirst
|
|
629
|
+
? [startAutoSave, startAutoLoad, stopAutoSave, stopAutoLoad]
|
|
630
|
+
: [startAutoLoad, startAutoSave, stopAutoLoad, stopAutoSave];
|
|
631
|
+
const start1 = call1(initialContent);
|
|
632
|
+
const generation1 = startSaveFirst
|
|
633
|
+
? autoSaveGeneration
|
|
634
|
+
: autoLoadGeneration;
|
|
635
|
+
await start1;
|
|
636
|
+
const start2 = call2(initialContent);
|
|
637
|
+
const generation2 = startSaveFirst
|
|
638
|
+
? autoLoadGeneration
|
|
639
|
+
: autoSaveGeneration;
|
|
640
|
+
try {
|
|
641
|
+
await start2;
|
|
642
|
+
} catch (error) {
|
|
643
|
+
if (
|
|
644
|
+
generation2 ==
|
|
645
|
+
(startSaveFirst ? autoLoadGeneration : autoSaveGeneration)
|
|
646
|
+
) {
|
|
647
|
+
await tryCatchIgnore(stop2);
|
|
648
|
+
}
|
|
649
|
+
if (
|
|
650
|
+
generation1 ==
|
|
651
|
+
(startSaveFirst ? autoSaveGeneration : autoLoadGeneration)
|
|
652
|
+
) {
|
|
653
|
+
await tryCatchIgnore(stop1);
|
|
654
|
+
}
|
|
655
|
+
throw error;
|
|
656
|
+
}
|
|
631
657
|
return persister;
|
|
632
658
|
};
|
|
633
659
|
const stopAutoPersisting = async (stopSaveFirst = false) => {
|
|
@@ -826,11 +826,35 @@ const createCustomPersister = (
|
|
|
826
826
|
initialContent,
|
|
827
827
|
startSaveFirst = false,
|
|
828
828
|
) => {
|
|
829
|
-
const [call1, call2] = startSaveFirst
|
|
830
|
-
? [startAutoSave, startAutoLoad]
|
|
831
|
-
: [startAutoLoad, startAutoSave];
|
|
832
|
-
|
|
833
|
-
|
|
829
|
+
const [call1, call2, stop1, stop2] = startSaveFirst
|
|
830
|
+
? [startAutoSave, startAutoLoad, stopAutoSave, stopAutoLoad]
|
|
831
|
+
: [startAutoLoad, startAutoSave, stopAutoLoad, stopAutoSave];
|
|
832
|
+
const start1 = call1(initialContent);
|
|
833
|
+
const generation1 = startSaveFirst
|
|
834
|
+
? autoSaveGeneration
|
|
835
|
+
: autoLoadGeneration;
|
|
836
|
+
await start1;
|
|
837
|
+
const start2 = call2(initialContent);
|
|
838
|
+
const generation2 = startSaveFirst
|
|
839
|
+
? autoLoadGeneration
|
|
840
|
+
: autoSaveGeneration;
|
|
841
|
+
try {
|
|
842
|
+
await start2;
|
|
843
|
+
} catch (error) {
|
|
844
|
+
if (
|
|
845
|
+
generation2 ==
|
|
846
|
+
(startSaveFirst ? autoLoadGeneration : autoSaveGeneration)
|
|
847
|
+
) {
|
|
848
|
+
await tryCatchIgnore(stop2);
|
|
849
|
+
}
|
|
850
|
+
if (
|
|
851
|
+
generation1 ==
|
|
852
|
+
(startSaveFirst ? autoSaveGeneration : autoLoadGeneration)
|
|
853
|
+
) {
|
|
854
|
+
await tryCatchIgnore(stop1);
|
|
855
|
+
}
|
|
856
|
+
throw error;
|
|
857
|
+
}
|
|
834
858
|
return persister;
|
|
835
859
|
};
|
|
836
860
|
const stopAutoPersisting = async (stopSaveFirst = false) => {
|
|
@@ -826,11 +826,35 @@ const createCustomPersister = (
|
|
|
826
826
|
initialContent,
|
|
827
827
|
startSaveFirst = false,
|
|
828
828
|
) => {
|
|
829
|
-
const [call1, call2] = startSaveFirst
|
|
830
|
-
? [startAutoSave, startAutoLoad]
|
|
831
|
-
: [startAutoLoad, startAutoSave];
|
|
832
|
-
|
|
833
|
-
|
|
829
|
+
const [call1, call2, stop1, stop2] = startSaveFirst
|
|
830
|
+
? [startAutoSave, startAutoLoad, stopAutoSave, stopAutoLoad]
|
|
831
|
+
: [startAutoLoad, startAutoSave, stopAutoLoad, stopAutoSave];
|
|
832
|
+
const start1 = call1(initialContent);
|
|
833
|
+
const generation1 = startSaveFirst
|
|
834
|
+
? autoSaveGeneration
|
|
835
|
+
: autoLoadGeneration;
|
|
836
|
+
await start1;
|
|
837
|
+
const start2 = call2(initialContent);
|
|
838
|
+
const generation2 = startSaveFirst
|
|
839
|
+
? autoLoadGeneration
|
|
840
|
+
: autoSaveGeneration;
|
|
841
|
+
try {
|
|
842
|
+
await start2;
|
|
843
|
+
} catch (error) {
|
|
844
|
+
if (
|
|
845
|
+
generation2 ==
|
|
846
|
+
(startSaveFirst ? autoLoadGeneration : autoSaveGeneration)
|
|
847
|
+
) {
|
|
848
|
+
await tryCatchIgnore(stop2);
|
|
849
|
+
}
|
|
850
|
+
if (
|
|
851
|
+
generation1 ==
|
|
852
|
+
(startSaveFirst ? autoSaveGeneration : autoLoadGeneration)
|
|
853
|
+
) {
|
|
854
|
+
await tryCatchIgnore(stop1);
|
|
855
|
+
}
|
|
856
|
+
throw error;
|
|
857
|
+
}
|
|
834
858
|
return persister;
|
|
835
859
|
};
|
|
836
860
|
const stopAutoPersisting = async (stopSaveFirst = false) => {
|
|
@@ -55,6 +55,8 @@ const tryCatch = async (action, onError) => {
|
|
|
55
55
|
onError?.(error);
|
|
56
56
|
}
|
|
57
57
|
};
|
|
58
|
+
const tryCatchIgnore = (action, onIgnoredError) =>
|
|
59
|
+
tryCatch(action, (error) => void tryCatch(() => onIgnoredError?.(error)));
|
|
58
60
|
const tryCatchSync = (action, onError) => {
|
|
59
61
|
try {
|
|
60
62
|
return action();
|
|
@@ -611,11 +613,35 @@ const createCustomPersister = (
|
|
|
611
613
|
initialContent,
|
|
612
614
|
startSaveFirst = false,
|
|
613
615
|
) => {
|
|
614
|
-
const [call1, call2] = startSaveFirst
|
|
615
|
-
? [startAutoSave, startAutoLoad]
|
|
616
|
-
: [startAutoLoad, startAutoSave];
|
|
617
|
-
|
|
618
|
-
|
|
616
|
+
const [call1, call2, stop1, stop2] = startSaveFirst
|
|
617
|
+
? [startAutoSave, startAutoLoad, stopAutoSave, stopAutoLoad]
|
|
618
|
+
: [startAutoLoad, startAutoSave, stopAutoLoad, stopAutoSave];
|
|
619
|
+
const start1 = call1(initialContent);
|
|
620
|
+
const generation1 = startSaveFirst
|
|
621
|
+
? autoSaveGeneration
|
|
622
|
+
: autoLoadGeneration;
|
|
623
|
+
await start1;
|
|
624
|
+
const start2 = call2(initialContent);
|
|
625
|
+
const generation2 = startSaveFirst
|
|
626
|
+
? autoLoadGeneration
|
|
627
|
+
: autoSaveGeneration;
|
|
628
|
+
try {
|
|
629
|
+
await start2;
|
|
630
|
+
} catch (error) {
|
|
631
|
+
if (
|
|
632
|
+
generation2 ==
|
|
633
|
+
(startSaveFirst ? autoLoadGeneration : autoSaveGeneration)
|
|
634
|
+
) {
|
|
635
|
+
await tryCatchIgnore(stop2);
|
|
636
|
+
}
|
|
637
|
+
if (
|
|
638
|
+
generation1 ==
|
|
639
|
+
(startSaveFirst ? autoSaveGeneration : autoLoadGeneration)
|
|
640
|
+
) {
|
|
641
|
+
await tryCatchIgnore(stop1);
|
|
642
|
+
}
|
|
643
|
+
throw error;
|
|
644
|
+
}
|
|
619
645
|
return persister;
|
|
620
646
|
};
|
|
621
647
|
const stopAutoPersisting = async (stopSaveFirst = false) => {
|
|
@@ -55,6 +55,8 @@ const tryCatch = async (action, onError) => {
|
|
|
55
55
|
onError?.(error);
|
|
56
56
|
}
|
|
57
57
|
};
|
|
58
|
+
const tryCatchIgnore = (action, onIgnoredError) =>
|
|
59
|
+
tryCatch(action, (error) => void tryCatch(() => onIgnoredError?.(error)));
|
|
58
60
|
const tryCatchSync = (action, onError) => {
|
|
59
61
|
try {
|
|
60
62
|
return action();
|
|
@@ -611,11 +613,35 @@ const createCustomPersister = (
|
|
|
611
613
|
initialContent,
|
|
612
614
|
startSaveFirst = false,
|
|
613
615
|
) => {
|
|
614
|
-
const [call1, call2] = startSaveFirst
|
|
615
|
-
? [startAutoSave, startAutoLoad]
|
|
616
|
-
: [startAutoLoad, startAutoSave];
|
|
617
|
-
|
|
618
|
-
|
|
616
|
+
const [call1, call2, stop1, stop2] = startSaveFirst
|
|
617
|
+
? [startAutoSave, startAutoLoad, stopAutoSave, stopAutoLoad]
|
|
618
|
+
: [startAutoLoad, startAutoSave, stopAutoLoad, stopAutoSave];
|
|
619
|
+
const start1 = call1(initialContent);
|
|
620
|
+
const generation1 = startSaveFirst
|
|
621
|
+
? autoSaveGeneration
|
|
622
|
+
: autoLoadGeneration;
|
|
623
|
+
await start1;
|
|
624
|
+
const start2 = call2(initialContent);
|
|
625
|
+
const generation2 = startSaveFirst
|
|
626
|
+
? autoLoadGeneration
|
|
627
|
+
: autoSaveGeneration;
|
|
628
|
+
try {
|
|
629
|
+
await start2;
|
|
630
|
+
} catch (error) {
|
|
631
|
+
if (
|
|
632
|
+
generation2 ==
|
|
633
|
+
(startSaveFirst ? autoLoadGeneration : autoSaveGeneration)
|
|
634
|
+
) {
|
|
635
|
+
await tryCatchIgnore(stop2);
|
|
636
|
+
}
|
|
637
|
+
if (
|
|
638
|
+
generation1 ==
|
|
639
|
+
(startSaveFirst ? autoSaveGeneration : autoLoadGeneration)
|
|
640
|
+
) {
|
|
641
|
+
await tryCatchIgnore(stop1);
|
|
642
|
+
}
|
|
643
|
+
throw error;
|
|
644
|
+
}
|
|
619
645
|
return persister;
|
|
620
646
|
};
|
|
621
647
|
const stopAutoPersisting = async (stopSaveFirst = false) => {
|
|
@@ -826,11 +826,35 @@ const createCustomPersister = (
|
|
|
826
826
|
initialContent,
|
|
827
827
|
startSaveFirst = false,
|
|
828
828
|
) => {
|
|
829
|
-
const [call1, call2] = startSaveFirst
|
|
830
|
-
? [startAutoSave, startAutoLoad]
|
|
831
|
-
: [startAutoLoad, startAutoSave];
|
|
832
|
-
|
|
833
|
-
|
|
829
|
+
const [call1, call2, stop1, stop2] = startSaveFirst
|
|
830
|
+
? [startAutoSave, startAutoLoad, stopAutoSave, stopAutoLoad]
|
|
831
|
+
: [startAutoLoad, startAutoSave, stopAutoLoad, stopAutoSave];
|
|
832
|
+
const start1 = call1(initialContent);
|
|
833
|
+
const generation1 = startSaveFirst
|
|
834
|
+
? autoSaveGeneration
|
|
835
|
+
: autoLoadGeneration;
|
|
836
|
+
await start1;
|
|
837
|
+
const start2 = call2(initialContent);
|
|
838
|
+
const generation2 = startSaveFirst
|
|
839
|
+
? autoLoadGeneration
|
|
840
|
+
: autoSaveGeneration;
|
|
841
|
+
try {
|
|
842
|
+
await start2;
|
|
843
|
+
} catch (error) {
|
|
844
|
+
if (
|
|
845
|
+
generation2 ==
|
|
846
|
+
(startSaveFirst ? autoLoadGeneration : autoSaveGeneration)
|
|
847
|
+
) {
|
|
848
|
+
await tryCatchIgnore(stop2);
|
|
849
|
+
}
|
|
850
|
+
if (
|
|
851
|
+
generation1 ==
|
|
852
|
+
(startSaveFirst ? autoSaveGeneration : autoLoadGeneration)
|
|
853
|
+
) {
|
|
854
|
+
await tryCatchIgnore(stop1);
|
|
855
|
+
}
|
|
856
|
+
throw error;
|
|
857
|
+
}
|
|
834
858
|
return persister;
|
|
835
859
|
};
|
|
836
860
|
const stopAutoPersisting = async (stopSaveFirst = false) => {
|
|
@@ -826,11 +826,35 @@ const createCustomPersister = (
|
|
|
826
826
|
initialContent,
|
|
827
827
|
startSaveFirst = false,
|
|
828
828
|
) => {
|
|
829
|
-
const [call1, call2] = startSaveFirst
|
|
830
|
-
? [startAutoSave, startAutoLoad]
|
|
831
|
-
: [startAutoLoad, startAutoSave];
|
|
832
|
-
|
|
833
|
-
|
|
829
|
+
const [call1, call2, stop1, stop2] = startSaveFirst
|
|
830
|
+
? [startAutoSave, startAutoLoad, stopAutoSave, stopAutoLoad]
|
|
831
|
+
: [startAutoLoad, startAutoSave, stopAutoLoad, stopAutoSave];
|
|
832
|
+
const start1 = call1(initialContent);
|
|
833
|
+
const generation1 = startSaveFirst
|
|
834
|
+
? autoSaveGeneration
|
|
835
|
+
: autoLoadGeneration;
|
|
836
|
+
await start1;
|
|
837
|
+
const start2 = call2(initialContent);
|
|
838
|
+
const generation2 = startSaveFirst
|
|
839
|
+
? autoLoadGeneration
|
|
840
|
+
: autoSaveGeneration;
|
|
841
|
+
try {
|
|
842
|
+
await start2;
|
|
843
|
+
} catch (error) {
|
|
844
|
+
if (
|
|
845
|
+
generation2 ==
|
|
846
|
+
(startSaveFirst ? autoLoadGeneration : autoSaveGeneration)
|
|
847
|
+
) {
|
|
848
|
+
await tryCatchIgnore(stop2);
|
|
849
|
+
}
|
|
850
|
+
if (
|
|
851
|
+
generation1 ==
|
|
852
|
+
(startSaveFirst ? autoSaveGeneration : autoLoadGeneration)
|
|
853
|
+
) {
|
|
854
|
+
await tryCatchIgnore(stop1);
|
|
855
|
+
}
|
|
856
|
+
throw error;
|
|
857
|
+
}
|
|
834
858
|
return persister;
|
|
835
859
|
};
|
|
836
860
|
const stopAutoPersisting = async (stopSaveFirst = false) => {
|
|
@@ -826,11 +826,35 @@ const createCustomPersister = (
|
|
|
826
826
|
initialContent,
|
|
827
827
|
startSaveFirst = false,
|
|
828
828
|
) => {
|
|
829
|
-
const [call1, call2] = startSaveFirst
|
|
830
|
-
? [startAutoSave, startAutoLoad]
|
|
831
|
-
: [startAutoLoad, startAutoSave];
|
|
832
|
-
|
|
833
|
-
|
|
829
|
+
const [call1, call2, stop1, stop2] = startSaveFirst
|
|
830
|
+
? [startAutoSave, startAutoLoad, stopAutoSave, stopAutoLoad]
|
|
831
|
+
: [startAutoLoad, startAutoSave, stopAutoLoad, stopAutoSave];
|
|
832
|
+
const start1 = call1(initialContent);
|
|
833
|
+
const generation1 = startSaveFirst
|
|
834
|
+
? autoSaveGeneration
|
|
835
|
+
: autoLoadGeneration;
|
|
836
|
+
await start1;
|
|
837
|
+
const start2 = call2(initialContent);
|
|
838
|
+
const generation2 = startSaveFirst
|
|
839
|
+
? autoLoadGeneration
|
|
840
|
+
: autoSaveGeneration;
|
|
841
|
+
try {
|
|
842
|
+
await start2;
|
|
843
|
+
} catch (error) {
|
|
844
|
+
if (
|
|
845
|
+
generation2 ==
|
|
846
|
+
(startSaveFirst ? autoLoadGeneration : autoSaveGeneration)
|
|
847
|
+
) {
|
|
848
|
+
await tryCatchIgnore(stop2);
|
|
849
|
+
}
|
|
850
|
+
if (
|
|
851
|
+
generation1 ==
|
|
852
|
+
(startSaveFirst ? autoSaveGeneration : autoLoadGeneration)
|
|
853
|
+
) {
|
|
854
|
+
await tryCatchIgnore(stop1);
|
|
855
|
+
}
|
|
856
|
+
throw error;
|
|
857
|
+
}
|
|
834
858
|
return persister;
|
|
835
859
|
};
|
|
836
860
|
const stopAutoPersisting = async (stopSaveFirst = false) => {
|