tinybase 6.0.0 → 6.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@types/_internal/ui-react/with-schemas/index.d.cts +1 -1
- package/@types/_internal/ui-react/with-schemas/index.d.ts +1 -1
- package/@types/index.d.cts +1 -1
- package/@types/index.d.ts +1 -1
- package/@types/persisters/persister-automerge/index.d.cts +1 -1
- package/@types/persisters/persister-automerge/index.d.ts +1 -1
- package/@types/persisters/persister-automerge/with-schemas/index.d.cts +1 -1
- package/@types/persisters/persister-automerge/with-schemas/index.d.ts +1 -1
- package/@types/persisters/persister-cr-sqlite-wasm/index.d.cts +1 -1
- package/@types/persisters/persister-cr-sqlite-wasm/index.d.ts +1 -1
- package/@types/persisters/persister-cr-sqlite-wasm/with-schemas/index.d.cts +1 -1
- package/@types/persisters/persister-cr-sqlite-wasm/with-schemas/index.d.ts +1 -1
- package/@types/persisters/persister-electric-sql/index.d.cts +4 -4
- package/@types/persisters/persister-electric-sql/index.d.ts +4 -4
- package/@types/persisters/persister-electric-sql/with-schemas/index.d.cts +4 -4
- package/@types/persisters/persister-electric-sql/with-schemas/index.d.ts +4 -4
- package/@types/persisters/persister-expo-sqlite/index.d.cts +1 -1
- package/@types/persisters/persister-expo-sqlite/index.d.ts +1 -1
- package/@types/persisters/persister-expo-sqlite/with-schemas/index.d.cts +1 -1
- package/@types/persisters/persister-expo-sqlite/with-schemas/index.d.ts +1 -1
- package/@types/persisters/persister-libsql/index.d.cts +1 -1
- package/@types/persisters/persister-libsql/index.d.ts +1 -1
- package/@types/persisters/persister-libsql/with-schemas/index.d.cts +1 -1
- package/@types/persisters/persister-libsql/with-schemas/index.d.ts +1 -1
- package/@types/persisters/persister-partykit-client/index.d.cts +1 -1
- package/@types/persisters/persister-partykit-client/index.d.ts +1 -1
- package/@types/persisters/persister-partykit-client/with-schemas/index.d.cts +1 -1
- package/@types/persisters/persister-partykit-client/with-schemas/index.d.ts +1 -1
- package/@types/persisters/persister-partykit-server/index.d.cts +7 -7
- package/@types/persisters/persister-partykit-server/index.d.ts +7 -7
- package/@types/persisters/persister-partykit-server/with-schemas/index.d.cts +1 -1
- package/@types/persisters/persister-partykit-server/with-schemas/index.d.ts +1 -1
- package/@types/persisters/persister-pglite/index.d.cts +1 -1
- package/@types/persisters/persister-pglite/index.d.ts +1 -1
- package/@types/persisters/persister-pglite/with-schemas/index.d.cts +1 -1
- package/@types/persisters/persister-pglite/with-schemas/index.d.ts +1 -1
- package/@types/persisters/persister-postgres/index.d.cts +1 -1
- package/@types/persisters/persister-postgres/index.d.ts +1 -1
- package/@types/persisters/persister-postgres/with-schemas/index.d.cts +1 -1
- package/@types/persisters/persister-postgres/with-schemas/index.d.ts +1 -1
- package/@types/persisters/persister-powersync/index.d.cts +1 -1
- package/@types/persisters/persister-powersync/index.d.ts +1 -1
- package/@types/persisters/persister-powersync/with-schemas/index.d.cts +1 -1
- package/@types/persisters/persister-powersync/with-schemas/index.d.ts +1 -1
- package/@types/persisters/persister-sqlite3/index.d.cts +1 -1
- package/@types/persisters/persister-sqlite3/index.d.ts +1 -1
- package/@types/persisters/persister-sqlite3/with-schemas/index.d.cts +1 -1
- package/@types/persisters/persister-sqlite3/with-schemas/index.d.ts +1 -1
- package/@types/persisters/persister-yjs/index.d.cts +1 -1
- package/@types/persisters/persister-yjs/index.d.ts +1 -1
- package/@types/persisters/persister-yjs/with-schemas/index.d.cts +1 -1
- package/@types/persisters/persister-yjs/with-schemas/index.d.ts +1 -1
- package/@types/synchronizers/synchronizer-ws-client/index.d.cts +1 -1
- package/@types/synchronizers/synchronizer-ws-client/index.d.ts +1 -1
- package/@types/synchronizers/synchronizer-ws-client/with-schemas/index.d.cts +1 -1
- package/@types/synchronizers/synchronizer-ws-client/with-schemas/index.d.ts +1 -1
- package/@types/synchronizers/synchronizer-ws-server/index.d.cts +1 -1
- package/@types/synchronizers/synchronizer-ws-server/index.d.ts +1 -1
- package/@types/synchronizers/synchronizer-ws-server/with-schemas/index.d.cts +1 -1
- package/@types/synchronizers/synchronizer-ws-server/with-schemas/index.d.ts +1 -1
- package/@types/synchronizers/synchronizer-ws-server-durable-object/index.d.cts +1 -1
- package/@types/synchronizers/synchronizer-ws-server-durable-object/index.d.ts +1 -1
- package/@types/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.d.cts +1 -1
- package/@types/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.d.ts +1 -1
- package/@types/ui-react/index.d.cts +3 -3
- package/@types/ui-react/index.d.ts +3 -3
- package/@types/ui-react/with-schemas/index.d.cts +1 -1
- package/@types/ui-react/with-schemas/index.d.ts +1 -1
- package/@types/ui-react-dom/index.d.cts +1 -1
- package/@types/ui-react-dom/index.d.ts +1 -1
- package/@types/ui-react-dom/with-schemas/index.d.cts +1 -1
- package/@types/ui-react-dom/with-schemas/index.d.ts +1 -1
- package/@types/ui-react-inspector/with-schemas/index.d.cts +1 -1
- package/@types/ui-react-inspector/with-schemas/index.d.ts +1 -1
- package/@types/with-schemas/index.d.cts +1 -1
- package/@types/with-schemas/index.d.ts +1 -1
- package/index.js +1564 -1564
- package/min/index.js +1 -1
- package/min/index.js.gz +0 -0
- package/min/persisters/index.js +1 -1
- package/min/persisters/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/ui-react/index.js +1 -1
- package/min/ui-react/index.js.gz +0 -0
- package/min/ui-react/with-schemas/index.js +1 -1
- package/min/ui-react/with-schemas/index.js.gz +0 -0
- package/min/with-schemas/index.js +1 -1
- package/min/with-schemas/index.js.gz +0 -0
- package/package.json +1 -4
- package/persisters/index.js +95 -95
- package/persisters/with-schemas/index.js +95 -95
- package/readme.md +13 -13
- package/releases.md +25 -25
- package/synchronizers/synchronizer-ws-server-durable-object/index.js +1 -1
- package/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +1 -1
- package/ui-react/index.js +64 -53
- package/ui-react/with-schemas/index.js +64 -53
- package/ui-react-dom/index.js +3 -3
- package/ui-react-dom/with-schemas/index.js +3 -3
- package/ui-react-inspector/index.js +4 -4
- package/ui-react-inspector/with-schemas/index.js +4 -4
- package/with-schemas/index.js +1564 -1564
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tinybase",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.1.0-beta.1",
|
|
4
4
|
"author": "jamesgpearce",
|
|
5
5
|
"repository": "github:tinyplex/tinybase",
|
|
6
6
|
"license": "MIT",
|
|
@@ -80,9 +80,6 @@
|
|
|
80
80
|
"postgres": {
|
|
81
81
|
"optional": true
|
|
82
82
|
},
|
|
83
|
-
"prettier": {
|
|
84
|
-
"optional": true
|
|
85
|
-
},
|
|
86
83
|
"react": {
|
|
87
84
|
"optional": true
|
|
88
85
|
},
|
package/persisters/index.js
CHANGED
|
@@ -434,6 +434,13 @@ const createCustomPersister = (
|
|
|
434
434
|
return objFreeze(persister);
|
|
435
435
|
};
|
|
436
436
|
|
|
437
|
+
const jsonString = JSON.stringify;
|
|
438
|
+
const jsonParse = JSON.parse;
|
|
439
|
+
const jsonStringWithUndefined = (obj) =>
|
|
440
|
+
jsonString(obj, (_key, value) => (value === void 0 ? UNDEFINED : value));
|
|
441
|
+
const jsonParseWithUndefined = (str) =>
|
|
442
|
+
jsonParse(str, (_key, value) => (value === UNDEFINED ? void 0 : value));
|
|
443
|
+
|
|
437
444
|
const SINGLE_ROW_ID = '_';
|
|
438
445
|
const DEFAULT_ROW_ID_COLUMN_NAME = '_id';
|
|
439
446
|
const SELECT = 'SELECT';
|
|
@@ -567,13 +574,6 @@ const getConfigStructures = (configOrStoreTableName) => {
|
|
|
567
574
|
return [0, autoLoadIntervalSeconds, tabularConfig, managedTableNames];
|
|
568
575
|
};
|
|
569
576
|
|
|
570
|
-
const jsonString = JSON.stringify;
|
|
571
|
-
const jsonParse = JSON.parse;
|
|
572
|
-
const jsonStringWithUndefined = (obj) =>
|
|
573
|
-
jsonString(obj, (_key, value) => (value === void 0 ? UNDEFINED : value));
|
|
574
|
-
const jsonParseWithUndefined = (str) =>
|
|
575
|
-
jsonParse(str, (_key, value) => (value === UNDEFINED ? void 0 : value));
|
|
576
|
-
|
|
577
577
|
const getCommandFunctions = (
|
|
578
578
|
databaseExecuteCommand,
|
|
579
579
|
managedTableNames,
|
|
@@ -1023,94 +1023,6 @@ const createTabularPersister = (
|
|
|
1023
1023
|
return persister;
|
|
1024
1024
|
};
|
|
1025
1025
|
|
|
1026
|
-
const createCustomSqlitePersister = (
|
|
1027
|
-
store,
|
|
1028
|
-
configOrStoreTableName,
|
|
1029
|
-
rawExecuteCommand,
|
|
1030
|
-
addChangeListener,
|
|
1031
|
-
delChangeListener,
|
|
1032
|
-
onSqlCommand,
|
|
1033
|
-
onIgnoredError,
|
|
1034
|
-
destroy,
|
|
1035
|
-
persist,
|
|
1036
|
-
thing,
|
|
1037
|
-
getThing = 'getDb',
|
|
1038
|
-
upsert,
|
|
1039
|
-
) => {
|
|
1040
|
-
let dataVersion;
|
|
1041
|
-
let schemaVersion;
|
|
1042
|
-
let totalChanges;
|
|
1043
|
-
const executeCommand = getWrappedCommand(rawExecuteCommand, onSqlCommand);
|
|
1044
|
-
const [
|
|
1045
|
-
isJson,
|
|
1046
|
-
autoLoadIntervalSeconds,
|
|
1047
|
-
defaultedConfig,
|
|
1048
|
-
managedTableNamesSet,
|
|
1049
|
-
] = getConfigStructures(configOrStoreTableName);
|
|
1050
|
-
const addPersisterListener = (listener) => {
|
|
1051
|
-
let interval;
|
|
1052
|
-
const startPolling = () =>
|
|
1053
|
-
(interval = startInterval(async () => {
|
|
1054
|
-
try {
|
|
1055
|
-
const [{d, s, c}] = await executeCommand(
|
|
1056
|
-
// eslint-disable-next-line max-len
|
|
1057
|
-
`${SELECT} ${DATA_VERSION} d,${SCHEMA_VERSION} s,TOTAL_CHANGES() c FROM ${PRAGMA}${DATA_VERSION} JOIN ${PRAGMA}${SCHEMA_VERSION}`,
|
|
1058
|
-
);
|
|
1059
|
-
if (d != dataVersion || s != schemaVersion || c != totalChanges) {
|
|
1060
|
-
if (dataVersion != null) {
|
|
1061
|
-
listener();
|
|
1062
|
-
}
|
|
1063
|
-
dataVersion = d;
|
|
1064
|
-
schemaVersion = s;
|
|
1065
|
-
totalChanges = c;
|
|
1066
|
-
}
|
|
1067
|
-
} catch {}
|
|
1068
|
-
}, autoLoadIntervalSeconds));
|
|
1069
|
-
const stopPolling = () => {
|
|
1070
|
-
dataVersion = schemaVersion = totalChanges = null;
|
|
1071
|
-
stopInterval(interval);
|
|
1072
|
-
};
|
|
1073
|
-
const listeningHandle = addChangeListener((tableName) => {
|
|
1074
|
-
if (managedTableNamesSet.has(tableName)) {
|
|
1075
|
-
stopPolling();
|
|
1076
|
-
listener();
|
|
1077
|
-
startPolling();
|
|
1078
|
-
}
|
|
1079
|
-
});
|
|
1080
|
-
startPolling();
|
|
1081
|
-
return () => {
|
|
1082
|
-
stopPolling();
|
|
1083
|
-
delChangeListener(listeningHandle);
|
|
1084
|
-
};
|
|
1085
|
-
};
|
|
1086
|
-
const delPersisterListener = (stopPollingAndDelUpdateListener) =>
|
|
1087
|
-
stopPollingAndDelUpdateListener();
|
|
1088
|
-
return (isJson ? createJsonPersister : createTabularPersister)(
|
|
1089
|
-
store,
|
|
1090
|
-
executeCommand,
|
|
1091
|
-
addPersisterListener,
|
|
1092
|
-
delPersisterListener,
|
|
1093
|
-
onIgnoredError,
|
|
1094
|
-
destroy,
|
|
1095
|
-
persist,
|
|
1096
|
-
defaultedConfig,
|
|
1097
|
-
collValues(managedTableNamesSet),
|
|
1098
|
-
async (executeCommand2, managedTableNames) =>
|
|
1099
|
-
await executeCommand2(
|
|
1100
|
-
// eslint-disable-next-line max-len
|
|
1101
|
-
`${SELECT} t.name tn,c.name cn ${FROM}${PRAGMA_TABLE}list()t,${PRAGMA_TABLE}info(t.name)c ${WHERE} t.schema='main'AND t.type IN('table','view')AND t.name IN(${getPlaceholders(managedTableNames)})ORDER BY t.name,c.name`,
|
|
1102
|
-
managedTableNames,
|
|
1103
|
-
),
|
|
1104
|
-
thing,
|
|
1105
|
-
getThing,
|
|
1106
|
-
EMPTY_STRING,
|
|
1107
|
-
upsert,
|
|
1108
|
-
(cellOrValue) =>
|
|
1109
|
-
cellOrValue === true ? 1 : cellOrValue === false ? 0 : cellOrValue,
|
|
1110
|
-
void 0,
|
|
1111
|
-
);
|
|
1112
|
-
};
|
|
1113
|
-
|
|
1114
1026
|
const EVENT_CHANNEL = TINYBASE;
|
|
1115
1027
|
const EVENT_REGEX = /^([cd]:)(.+)/;
|
|
1116
1028
|
const CHANGE_DATA_TRIGGER = TINYBASE + '_data';
|
|
@@ -1204,6 +1116,94 @@ const createCustomPostgreSqlPersister = (
|
|
|
1204
1116
|
);
|
|
1205
1117
|
};
|
|
1206
1118
|
|
|
1119
|
+
const createCustomSqlitePersister = (
|
|
1120
|
+
store,
|
|
1121
|
+
configOrStoreTableName,
|
|
1122
|
+
rawExecuteCommand,
|
|
1123
|
+
addChangeListener,
|
|
1124
|
+
delChangeListener,
|
|
1125
|
+
onSqlCommand,
|
|
1126
|
+
onIgnoredError,
|
|
1127
|
+
destroy,
|
|
1128
|
+
persist,
|
|
1129
|
+
thing,
|
|
1130
|
+
getThing = 'getDb',
|
|
1131
|
+
upsert,
|
|
1132
|
+
) => {
|
|
1133
|
+
let dataVersion;
|
|
1134
|
+
let schemaVersion;
|
|
1135
|
+
let totalChanges;
|
|
1136
|
+
const executeCommand = getWrappedCommand(rawExecuteCommand, onSqlCommand);
|
|
1137
|
+
const [
|
|
1138
|
+
isJson,
|
|
1139
|
+
autoLoadIntervalSeconds,
|
|
1140
|
+
defaultedConfig,
|
|
1141
|
+
managedTableNamesSet,
|
|
1142
|
+
] = getConfigStructures(configOrStoreTableName);
|
|
1143
|
+
const addPersisterListener = (listener) => {
|
|
1144
|
+
let interval;
|
|
1145
|
+
const startPolling = () =>
|
|
1146
|
+
(interval = startInterval(async () => {
|
|
1147
|
+
try {
|
|
1148
|
+
const [{d, s, c}] = await executeCommand(
|
|
1149
|
+
// eslint-disable-next-line max-len
|
|
1150
|
+
`${SELECT} ${DATA_VERSION} d,${SCHEMA_VERSION} s,TOTAL_CHANGES() c FROM ${PRAGMA}${DATA_VERSION} JOIN ${PRAGMA}${SCHEMA_VERSION}`,
|
|
1151
|
+
);
|
|
1152
|
+
if (d != dataVersion || s != schemaVersion || c != totalChanges) {
|
|
1153
|
+
if (dataVersion != null) {
|
|
1154
|
+
listener();
|
|
1155
|
+
}
|
|
1156
|
+
dataVersion = d;
|
|
1157
|
+
schemaVersion = s;
|
|
1158
|
+
totalChanges = c;
|
|
1159
|
+
}
|
|
1160
|
+
} catch {}
|
|
1161
|
+
}, autoLoadIntervalSeconds));
|
|
1162
|
+
const stopPolling = () => {
|
|
1163
|
+
dataVersion = schemaVersion = totalChanges = null;
|
|
1164
|
+
stopInterval(interval);
|
|
1165
|
+
};
|
|
1166
|
+
const listeningHandle = addChangeListener((tableName) => {
|
|
1167
|
+
if (managedTableNamesSet.has(tableName)) {
|
|
1168
|
+
stopPolling();
|
|
1169
|
+
listener();
|
|
1170
|
+
startPolling();
|
|
1171
|
+
}
|
|
1172
|
+
});
|
|
1173
|
+
startPolling();
|
|
1174
|
+
return () => {
|
|
1175
|
+
stopPolling();
|
|
1176
|
+
delChangeListener(listeningHandle);
|
|
1177
|
+
};
|
|
1178
|
+
};
|
|
1179
|
+
const delPersisterListener = (stopPollingAndDelUpdateListener) =>
|
|
1180
|
+
stopPollingAndDelUpdateListener();
|
|
1181
|
+
return (isJson ? createJsonPersister : createTabularPersister)(
|
|
1182
|
+
store,
|
|
1183
|
+
executeCommand,
|
|
1184
|
+
addPersisterListener,
|
|
1185
|
+
delPersisterListener,
|
|
1186
|
+
onIgnoredError,
|
|
1187
|
+
destroy,
|
|
1188
|
+
persist,
|
|
1189
|
+
defaultedConfig,
|
|
1190
|
+
collValues(managedTableNamesSet),
|
|
1191
|
+
async (executeCommand2, managedTableNames) =>
|
|
1192
|
+
await executeCommand2(
|
|
1193
|
+
// eslint-disable-next-line max-len
|
|
1194
|
+
`${SELECT} t.name tn,c.name cn ${FROM}${PRAGMA_TABLE}list()t,${PRAGMA_TABLE}info(t.name)c ${WHERE} t.schema='main'AND t.type IN('table','view')AND t.name IN(${getPlaceholders(managedTableNames)})ORDER BY t.name,c.name`,
|
|
1195
|
+
managedTableNames,
|
|
1196
|
+
),
|
|
1197
|
+
thing,
|
|
1198
|
+
getThing,
|
|
1199
|
+
EMPTY_STRING,
|
|
1200
|
+
upsert,
|
|
1201
|
+
(cellOrValue) =>
|
|
1202
|
+
cellOrValue === true ? 1 : cellOrValue === false ? 0 : cellOrValue,
|
|
1203
|
+
void 0,
|
|
1204
|
+
);
|
|
1205
|
+
};
|
|
1206
|
+
|
|
1207
1207
|
export {
|
|
1208
1208
|
Persists,
|
|
1209
1209
|
Status,
|
|
@@ -434,6 +434,13 @@ const createCustomPersister = (
|
|
|
434
434
|
return objFreeze(persister);
|
|
435
435
|
};
|
|
436
436
|
|
|
437
|
+
const jsonString = JSON.stringify;
|
|
438
|
+
const jsonParse = JSON.parse;
|
|
439
|
+
const jsonStringWithUndefined = (obj) =>
|
|
440
|
+
jsonString(obj, (_key, value) => (value === void 0 ? UNDEFINED : value));
|
|
441
|
+
const jsonParseWithUndefined = (str) =>
|
|
442
|
+
jsonParse(str, (_key, value) => (value === UNDEFINED ? void 0 : value));
|
|
443
|
+
|
|
437
444
|
const SINGLE_ROW_ID = '_';
|
|
438
445
|
const DEFAULT_ROW_ID_COLUMN_NAME = '_id';
|
|
439
446
|
const SELECT = 'SELECT';
|
|
@@ -567,13 +574,6 @@ const getConfigStructures = (configOrStoreTableName) => {
|
|
|
567
574
|
return [0, autoLoadIntervalSeconds, tabularConfig, managedTableNames];
|
|
568
575
|
};
|
|
569
576
|
|
|
570
|
-
const jsonString = JSON.stringify;
|
|
571
|
-
const jsonParse = JSON.parse;
|
|
572
|
-
const jsonStringWithUndefined = (obj) =>
|
|
573
|
-
jsonString(obj, (_key, value) => (value === void 0 ? UNDEFINED : value));
|
|
574
|
-
const jsonParseWithUndefined = (str) =>
|
|
575
|
-
jsonParse(str, (_key, value) => (value === UNDEFINED ? void 0 : value));
|
|
576
|
-
|
|
577
577
|
const getCommandFunctions = (
|
|
578
578
|
databaseExecuteCommand,
|
|
579
579
|
managedTableNames,
|
|
@@ -1023,94 +1023,6 @@ const createTabularPersister = (
|
|
|
1023
1023
|
return persister;
|
|
1024
1024
|
};
|
|
1025
1025
|
|
|
1026
|
-
const createCustomSqlitePersister = (
|
|
1027
|
-
store,
|
|
1028
|
-
configOrStoreTableName,
|
|
1029
|
-
rawExecuteCommand,
|
|
1030
|
-
addChangeListener,
|
|
1031
|
-
delChangeListener,
|
|
1032
|
-
onSqlCommand,
|
|
1033
|
-
onIgnoredError,
|
|
1034
|
-
destroy,
|
|
1035
|
-
persist,
|
|
1036
|
-
thing,
|
|
1037
|
-
getThing = 'getDb',
|
|
1038
|
-
upsert,
|
|
1039
|
-
) => {
|
|
1040
|
-
let dataVersion;
|
|
1041
|
-
let schemaVersion;
|
|
1042
|
-
let totalChanges;
|
|
1043
|
-
const executeCommand = getWrappedCommand(rawExecuteCommand, onSqlCommand);
|
|
1044
|
-
const [
|
|
1045
|
-
isJson,
|
|
1046
|
-
autoLoadIntervalSeconds,
|
|
1047
|
-
defaultedConfig,
|
|
1048
|
-
managedTableNamesSet,
|
|
1049
|
-
] = getConfigStructures(configOrStoreTableName);
|
|
1050
|
-
const addPersisterListener = (listener) => {
|
|
1051
|
-
let interval;
|
|
1052
|
-
const startPolling = () =>
|
|
1053
|
-
(interval = startInterval(async () => {
|
|
1054
|
-
try {
|
|
1055
|
-
const [{d, s, c}] = await executeCommand(
|
|
1056
|
-
// eslint-disable-next-line max-len
|
|
1057
|
-
`${SELECT} ${DATA_VERSION} d,${SCHEMA_VERSION} s,TOTAL_CHANGES() c FROM ${PRAGMA}${DATA_VERSION} JOIN ${PRAGMA}${SCHEMA_VERSION}`,
|
|
1058
|
-
);
|
|
1059
|
-
if (d != dataVersion || s != schemaVersion || c != totalChanges) {
|
|
1060
|
-
if (dataVersion != null) {
|
|
1061
|
-
listener();
|
|
1062
|
-
}
|
|
1063
|
-
dataVersion = d;
|
|
1064
|
-
schemaVersion = s;
|
|
1065
|
-
totalChanges = c;
|
|
1066
|
-
}
|
|
1067
|
-
} catch {}
|
|
1068
|
-
}, autoLoadIntervalSeconds));
|
|
1069
|
-
const stopPolling = () => {
|
|
1070
|
-
dataVersion = schemaVersion = totalChanges = null;
|
|
1071
|
-
stopInterval(interval);
|
|
1072
|
-
};
|
|
1073
|
-
const listeningHandle = addChangeListener((tableName) => {
|
|
1074
|
-
if (managedTableNamesSet.has(tableName)) {
|
|
1075
|
-
stopPolling();
|
|
1076
|
-
listener();
|
|
1077
|
-
startPolling();
|
|
1078
|
-
}
|
|
1079
|
-
});
|
|
1080
|
-
startPolling();
|
|
1081
|
-
return () => {
|
|
1082
|
-
stopPolling();
|
|
1083
|
-
delChangeListener(listeningHandle);
|
|
1084
|
-
};
|
|
1085
|
-
};
|
|
1086
|
-
const delPersisterListener = (stopPollingAndDelUpdateListener) =>
|
|
1087
|
-
stopPollingAndDelUpdateListener();
|
|
1088
|
-
return (isJson ? createJsonPersister : createTabularPersister)(
|
|
1089
|
-
store,
|
|
1090
|
-
executeCommand,
|
|
1091
|
-
addPersisterListener,
|
|
1092
|
-
delPersisterListener,
|
|
1093
|
-
onIgnoredError,
|
|
1094
|
-
destroy,
|
|
1095
|
-
persist,
|
|
1096
|
-
defaultedConfig,
|
|
1097
|
-
collValues(managedTableNamesSet),
|
|
1098
|
-
async (executeCommand2, managedTableNames) =>
|
|
1099
|
-
await executeCommand2(
|
|
1100
|
-
// eslint-disable-next-line max-len
|
|
1101
|
-
`${SELECT} t.name tn,c.name cn ${FROM}${PRAGMA_TABLE}list()t,${PRAGMA_TABLE}info(t.name)c ${WHERE} t.schema='main'AND t.type IN('table','view')AND t.name IN(${getPlaceholders(managedTableNames)})ORDER BY t.name,c.name`,
|
|
1102
|
-
managedTableNames,
|
|
1103
|
-
),
|
|
1104
|
-
thing,
|
|
1105
|
-
getThing,
|
|
1106
|
-
EMPTY_STRING,
|
|
1107
|
-
upsert,
|
|
1108
|
-
(cellOrValue) =>
|
|
1109
|
-
cellOrValue === true ? 1 : cellOrValue === false ? 0 : cellOrValue,
|
|
1110
|
-
void 0,
|
|
1111
|
-
);
|
|
1112
|
-
};
|
|
1113
|
-
|
|
1114
1026
|
const EVENT_CHANNEL = TINYBASE;
|
|
1115
1027
|
const EVENT_REGEX = /^([cd]:)(.+)/;
|
|
1116
1028
|
const CHANGE_DATA_TRIGGER = TINYBASE + '_data';
|
|
@@ -1204,6 +1116,94 @@ const createCustomPostgreSqlPersister = (
|
|
|
1204
1116
|
);
|
|
1205
1117
|
};
|
|
1206
1118
|
|
|
1119
|
+
const createCustomSqlitePersister = (
|
|
1120
|
+
store,
|
|
1121
|
+
configOrStoreTableName,
|
|
1122
|
+
rawExecuteCommand,
|
|
1123
|
+
addChangeListener,
|
|
1124
|
+
delChangeListener,
|
|
1125
|
+
onSqlCommand,
|
|
1126
|
+
onIgnoredError,
|
|
1127
|
+
destroy,
|
|
1128
|
+
persist,
|
|
1129
|
+
thing,
|
|
1130
|
+
getThing = 'getDb',
|
|
1131
|
+
upsert,
|
|
1132
|
+
) => {
|
|
1133
|
+
let dataVersion;
|
|
1134
|
+
let schemaVersion;
|
|
1135
|
+
let totalChanges;
|
|
1136
|
+
const executeCommand = getWrappedCommand(rawExecuteCommand, onSqlCommand);
|
|
1137
|
+
const [
|
|
1138
|
+
isJson,
|
|
1139
|
+
autoLoadIntervalSeconds,
|
|
1140
|
+
defaultedConfig,
|
|
1141
|
+
managedTableNamesSet,
|
|
1142
|
+
] = getConfigStructures(configOrStoreTableName);
|
|
1143
|
+
const addPersisterListener = (listener) => {
|
|
1144
|
+
let interval;
|
|
1145
|
+
const startPolling = () =>
|
|
1146
|
+
(interval = startInterval(async () => {
|
|
1147
|
+
try {
|
|
1148
|
+
const [{d, s, c}] = await executeCommand(
|
|
1149
|
+
// eslint-disable-next-line max-len
|
|
1150
|
+
`${SELECT} ${DATA_VERSION} d,${SCHEMA_VERSION} s,TOTAL_CHANGES() c FROM ${PRAGMA}${DATA_VERSION} JOIN ${PRAGMA}${SCHEMA_VERSION}`,
|
|
1151
|
+
);
|
|
1152
|
+
if (d != dataVersion || s != schemaVersion || c != totalChanges) {
|
|
1153
|
+
if (dataVersion != null) {
|
|
1154
|
+
listener();
|
|
1155
|
+
}
|
|
1156
|
+
dataVersion = d;
|
|
1157
|
+
schemaVersion = s;
|
|
1158
|
+
totalChanges = c;
|
|
1159
|
+
}
|
|
1160
|
+
} catch {}
|
|
1161
|
+
}, autoLoadIntervalSeconds));
|
|
1162
|
+
const stopPolling = () => {
|
|
1163
|
+
dataVersion = schemaVersion = totalChanges = null;
|
|
1164
|
+
stopInterval(interval);
|
|
1165
|
+
};
|
|
1166
|
+
const listeningHandle = addChangeListener((tableName) => {
|
|
1167
|
+
if (managedTableNamesSet.has(tableName)) {
|
|
1168
|
+
stopPolling();
|
|
1169
|
+
listener();
|
|
1170
|
+
startPolling();
|
|
1171
|
+
}
|
|
1172
|
+
});
|
|
1173
|
+
startPolling();
|
|
1174
|
+
return () => {
|
|
1175
|
+
stopPolling();
|
|
1176
|
+
delChangeListener(listeningHandle);
|
|
1177
|
+
};
|
|
1178
|
+
};
|
|
1179
|
+
const delPersisterListener = (stopPollingAndDelUpdateListener) =>
|
|
1180
|
+
stopPollingAndDelUpdateListener();
|
|
1181
|
+
return (isJson ? createJsonPersister : createTabularPersister)(
|
|
1182
|
+
store,
|
|
1183
|
+
executeCommand,
|
|
1184
|
+
addPersisterListener,
|
|
1185
|
+
delPersisterListener,
|
|
1186
|
+
onIgnoredError,
|
|
1187
|
+
destroy,
|
|
1188
|
+
persist,
|
|
1189
|
+
defaultedConfig,
|
|
1190
|
+
collValues(managedTableNamesSet),
|
|
1191
|
+
async (executeCommand2, managedTableNames) =>
|
|
1192
|
+
await executeCommand2(
|
|
1193
|
+
// eslint-disable-next-line max-len
|
|
1194
|
+
`${SELECT} t.name tn,c.name cn ${FROM}${PRAGMA_TABLE}list()t,${PRAGMA_TABLE}info(t.name)c ${WHERE} t.schema='main'AND t.type IN('table','view')AND t.name IN(${getPlaceholders(managedTableNames)})ORDER BY t.name,c.name`,
|
|
1195
|
+
managedTableNames,
|
|
1196
|
+
),
|
|
1197
|
+
thing,
|
|
1198
|
+
getThing,
|
|
1199
|
+
EMPTY_STRING,
|
|
1200
|
+
upsert,
|
|
1201
|
+
(cellOrValue) =>
|
|
1202
|
+
cellOrValue === true ? 1 : cellOrValue === false ? 0 : cellOrValue,
|
|
1203
|
+
void 0,
|
|
1204
|
+
);
|
|
1205
|
+
};
|
|
1206
|
+
|
|
1207
1207
|
export {
|
|
1208
1208
|
Persists,
|
|
1209
1209
|
Status,
|