@ovok/native 1.17.0-dev.2258 → 1.17.0-dev.2260
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/lib/commonjs/modules/next/bluetooth/adapters/sqlite-database-outbox-store.js +80 -0
- package/lib/commonjs/modules/next/bluetooth/adapters/sqlite-database-outbox-store.js.map +1 -0
- package/lib/commonjs/modules/next/bluetooth/adapters/sqlite-database.js +0 -22
- package/lib/commonjs/modules/next/bluetooth/adapters/sqlite-database.js.map +1 -1
- package/lib/commonjs/modules/next/bluetooth/adapters/sqlite-outbox-schema.js +1 -1
- package/lib/commonjs/modules/next/bluetooth/adapters/sqlite-outbox-schema.js.map +1 -1
- package/lib/commonjs/modules/next/bluetooth/adapters/sqlite-outbox-store.js +16 -67
- package/lib/commonjs/modules/next/bluetooth/adapters/sqlite-outbox-store.js.map +1 -1
- package/lib/commonjs/modules/next/bluetooth/sqlite/index.js.map +1 -1
- package/lib/commonjs/modules/next/index.js.map +1 -1
- package/lib/commonjs/modules/next/ovok.js +25 -2
- package/lib/commonjs/modules/next/ovok.js.map +1 -1
- package/lib/commonjs/modules/next/react-native-outbox-triggers.js +40 -0
- package/lib/commonjs/modules/next/react-native-outbox-triggers.js.map +1 -0
- package/lib/module/modules/next/bluetooth/adapters/sqlite-database-outbox-store.js +77 -0
- package/lib/module/modules/next/bluetooth/adapters/sqlite-database-outbox-store.js.map +1 -0
- package/lib/module/modules/next/bluetooth/adapters/sqlite-database.js +0 -18
- package/lib/module/modules/next/bluetooth/adapters/sqlite-database.js.map +1 -1
- package/lib/module/modules/next/bluetooth/adapters/sqlite-outbox-schema.js +1 -1
- package/lib/module/modules/next/bluetooth/adapters/sqlite-outbox-schema.js.map +1 -1
- package/lib/module/modules/next/bluetooth/adapters/sqlite-outbox-store.js +16 -67
- package/lib/module/modules/next/bluetooth/adapters/sqlite-outbox-store.js.map +1 -1
- package/lib/module/modules/next/bluetooth/sqlite/index.js +3 -2
- package/lib/module/modules/next/bluetooth/sqlite/index.js.map +1 -1
- package/lib/module/modules/next/index.js +1 -1
- package/lib/module/modules/next/index.js.map +1 -1
- package/lib/module/modules/next/ovok.js +25 -2
- package/lib/module/modules/next/ovok.js.map +1 -1
- package/lib/module/modules/next/react-native-outbox-triggers.js +37 -0
- package/lib/module/modules/next/react-native-outbox-triggers.js.map +1 -0
- package/lib/typescript/commonjs/src/modules/data-sync/services/managers/sync-progress-manager.d.ts +1 -1
- package/lib/typescript/commonjs/src/modules/next/bluetooth/adapters/sqlite-database-outbox-store.d.ts +38 -0
- package/lib/typescript/commonjs/src/modules/next/bluetooth/adapters/sqlite-database-outbox-store.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/modules/next/bluetooth/adapters/sqlite-database.d.ts +9 -7
- package/lib/typescript/commonjs/src/modules/next/bluetooth/adapters/sqlite-database.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/modules/next/bluetooth/adapters/sqlite-outbox-store.d.ts +5 -33
- package/lib/typescript/commonjs/src/modules/next/bluetooth/adapters/sqlite-outbox-store.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/modules/next/bluetooth/core/device-snapshot.d.ts +1 -1
- package/lib/typescript/commonjs/src/modules/next/bluetooth/sqlite/index.d.ts +5 -3
- package/lib/typescript/commonjs/src/modules/next/bluetooth/sqlite/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/modules/next/index.d.ts +2 -1
- package/lib/typescript/commonjs/src/modules/next/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/modules/next/ovok.d.ts +11 -3
- package/lib/typescript/commonjs/src/modules/next/ovok.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/modules/next/react-native-outbox-triggers.d.ts +7 -0
- package/lib/typescript/commonjs/src/modules/next/react-native-outbox-triggers.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/modules/theme/hooks/use-app-theme.d.ts +1 -1
- package/lib/typescript/commonjs/src/modules/theme/utils/generate-theme.d.ts +1 -1
- package/lib/typescript/module/src/modules/data-sync/services/managers/sync-progress-manager.d.ts +1 -1
- package/lib/typescript/module/src/modules/next/bluetooth/adapters/sqlite-database-outbox-store.d.ts +38 -0
- package/lib/typescript/module/src/modules/next/bluetooth/adapters/sqlite-database-outbox-store.d.ts.map +1 -0
- package/lib/typescript/module/src/modules/next/bluetooth/adapters/sqlite-database.d.ts +9 -7
- package/lib/typescript/module/src/modules/next/bluetooth/adapters/sqlite-database.d.ts.map +1 -1
- package/lib/typescript/module/src/modules/next/bluetooth/adapters/sqlite-outbox-store.d.ts +5 -33
- package/lib/typescript/module/src/modules/next/bluetooth/adapters/sqlite-outbox-store.d.ts.map +1 -1
- package/lib/typescript/module/src/modules/next/bluetooth/core/device-snapshot.d.ts +1 -1
- package/lib/typescript/module/src/modules/next/bluetooth/sqlite/index.d.ts +5 -3
- package/lib/typescript/module/src/modules/next/bluetooth/sqlite/index.d.ts.map +1 -1
- package/lib/typescript/module/src/modules/next/index.d.ts +2 -1
- package/lib/typescript/module/src/modules/next/index.d.ts.map +1 -1
- package/lib/typescript/module/src/modules/next/ovok.d.ts +11 -3
- package/lib/typescript/module/src/modules/next/ovok.d.ts.map +1 -1
- package/lib/typescript/module/src/modules/next/react-native-outbox-triggers.d.ts +7 -0
- package/lib/typescript/module/src/modules/next/react-native-outbox-triggers.d.ts.map +1 -0
- package/lib/typescript/module/src/modules/theme/hooks/use-app-theme.d.ts +1 -1
- package/lib/typescript/module/src/modules/theme/utils/generate-theme.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SqliteDatabaseOutboxStore = void 0;
|
|
7
|
+
var _sqliteOutboxRows = require("./sqlite-outbox-rows.js");
|
|
8
|
+
var _sqliteOutboxSchema = require("./sqlite-outbox-schema.js");
|
|
9
|
+
/** How `SqliteDatabaseOutboxStore` opens its database. */
|
|
10
|
+
|
|
11
|
+
const DEFAULT_DATABASE_NAME = "ovok-outbox.db";
|
|
12
|
+
const PENDING = "pending";
|
|
13
|
+
const PUT = `INSERT OR REPLACE INTO outbox_items (${_sqliteOutboxRows.ITEM_COLUMN_LIST}) VALUES (${_sqliteOutboxRows.ITEM_PLACEHOLDERS})`;
|
|
14
|
+
const GET = `SELECT ${_sqliteOutboxRows.ITEM_COLUMN_LIST} FROM outbox_items WHERE id = ?`;
|
|
15
|
+
const REMOVE = "DELETE FROM outbox_items WHERE id = ?";
|
|
16
|
+
const DUE = `SELECT ${_sqliteOutboxRows.ITEM_COLUMN_LIST} FROM outbox_items
|
|
17
|
+
WHERE owner_key = ? AND state = ? AND next_attempt_at <= ?
|
|
18
|
+
ORDER BY recorded_at DESC, COALESCE(seq, 0), id
|
|
19
|
+
LIMIT ?`;
|
|
20
|
+
const SUMMARIES = `SELECT ${_sqliteOutboxRows.SUMMARY_COLUMN_LIST} FROM outbox_items WHERE owner_key = ? ORDER BY recorded_at DESC`;
|
|
21
|
+
const COUNT = "SELECT COUNT(*) AS total FROM outbox_items WHERE owner_key = ? AND state = ?";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* An `OutboxStore` on a SQLite database it is given a way to open: one row per item in `outbox_items`, the entries as
|
|
25
|
+
* one JSON text column, so listing and counting never read them. The database opens on first use.
|
|
26
|
+
*/
|
|
27
|
+
class SqliteDatabaseOutboxStore {
|
|
28
|
+
database = null;
|
|
29
|
+
constructor(options) {
|
|
30
|
+
this.options = options;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Stores an item, replacing the one with the same id. */
|
|
34
|
+
async put(item) {
|
|
35
|
+
await (await this.open()).runAsync(PUT, (0, _sqliteOutboxRows.bindValuesOf)(item));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Returns an item, or `null` when there is none. */
|
|
39
|
+
async get(id) {
|
|
40
|
+
const row = await (await this.open()).getFirstAsync(GET, [id]);
|
|
41
|
+
return row && (0, _sqliteOutboxRows.itemOf)(row);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Deletes an item; an unknown id is not an error. */
|
|
45
|
+
async remove(id) {
|
|
46
|
+
await (await this.open()).runAsync(REMOVE, [id]);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The owner's pending items that are due, newest recorded first, then by position in the recording. */
|
|
50
|
+
async due(ownerKey, now, limit) {
|
|
51
|
+
const rows = await (await this.open()).getAllAsync(DUE, [ownerKey, PENDING, now, limit]);
|
|
52
|
+
return rows.map(_sqliteOutboxRows.itemOf);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Every item of the owner in any state, newest recorded first, without its entries. */
|
|
56
|
+
async summaries(ownerKey) {
|
|
57
|
+
const rows = await (await this.open()).getAllAsync(SUMMARIES, [ownerKey]);
|
|
58
|
+
return rows.map(_sqliteOutboxRows.summaryOf);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** How many of the owner's items are in `state`. */
|
|
62
|
+
async count(ownerKey, state) {
|
|
63
|
+
const row = await (await this.open()).getFirstAsync(COUNT, [ownerKey, state]);
|
|
64
|
+
return row?.total ?? 0;
|
|
65
|
+
}
|
|
66
|
+
open() {
|
|
67
|
+
this.database ??= this.connect().catch(error => {
|
|
68
|
+
this.database = null;
|
|
69
|
+
throw error;
|
|
70
|
+
});
|
|
71
|
+
return this.database;
|
|
72
|
+
}
|
|
73
|
+
async connect() {
|
|
74
|
+
const database = await this.options.open(this.options.name ?? DEFAULT_DATABASE_NAME);
|
|
75
|
+
await (0, _sqliteOutboxSchema.migrateOutboxSchema)(database, this.options.logger);
|
|
76
|
+
return database;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.SqliteDatabaseOutboxStore = SqliteDatabaseOutboxStore;
|
|
80
|
+
//# sourceMappingURL=sqlite-database-outbox-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_sqliteOutboxRows","require","_sqliteOutboxSchema","DEFAULT_DATABASE_NAME","PENDING","PUT","ITEM_COLUMN_LIST","ITEM_PLACEHOLDERS","GET","REMOVE","DUE","SUMMARIES","SUMMARY_COLUMN_LIST","COUNT","SqliteDatabaseOutboxStore","database","constructor","options","put","item","open","runAsync","bindValuesOf","get","id","row","getFirstAsync","itemOf","remove","due","ownerKey","now","limit","rows","getAllAsync","map","summaries","summaryOf","count","state","total","connect","catch","error","name","migrateOutboxSchema","logger","exports"],"sourceRoot":"../../../../../../src","sources":["modules/next/bluetooth/adapters/sqlite-database-outbox-store.ts"],"mappings":"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","ignoreList":[]}
|
|
@@ -1,24 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.openExpoSqlite = void 0;
|
|
7
|
-
/** A value SQLite binds to a `?` placeholder. */
|
|
8
|
-
|
|
9
|
-
/** The part of an `expo-sqlite` transaction the outbox store uses. */
|
|
10
|
-
|
|
11
|
-
/** The part of an `expo-sqlite` database the outbox store uses. */
|
|
12
|
-
|
|
13
|
-
const loadExpoSqlite = () => {
|
|
14
|
-
try {
|
|
15
|
-
return require("expo-sqlite");
|
|
16
|
-
} catch {
|
|
17
|
-
throw new Error("SqliteOutboxStore requires the optional expo-sqlite peer dependency");
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
/** Opens the named database with `expo-sqlite`, which an app without the package never loads. */
|
|
22
|
-
const openExpoSqlite = name => loadExpoSqlite().openDatabaseAsync(name);
|
|
23
|
-
exports.openExpoSqlite = openExpoSqlite;
|
|
24
2
|
//# sourceMappingURL=sqlite-database.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../../../../src","sources":["modules/next/bluetooth/adapters/sqlite-database.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -32,7 +32,7 @@ const WRITE_VERSION = "INSERT INTO schema_version (version) VALUES (?)";
|
|
|
32
32
|
/** Brings the database to the latest schema; every pending migration runs in one transaction, so a crash leaves none. */
|
|
33
33
|
const migrateOutboxSchema = async (database, logger = _ports.silentLogger) => {
|
|
34
34
|
await database.execAsync(PREPARE);
|
|
35
|
-
const from = (await database.getFirstAsync(READ_VERSION))?.version ?? 0;
|
|
35
|
+
const from = (await database.getFirstAsync(READ_VERSION, []))?.version ?? 0;
|
|
36
36
|
const to = MIGRATIONS.length;
|
|
37
37
|
if (from >= to) {
|
|
38
38
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_ports","require","MIGRATIONS","PREPARE","READ_VERSION","WRITE_VERSION","migrateOutboxSchema","database","logger","silentLogger","execAsync","from","getFirstAsync","version","to","length","withExclusiveTransactionAsync","transaction","migration","slice","runAsync","info","exports"],"sourceRoot":"../../../../../../src","sources":["modules/next/bluetooth/adapters/sqlite-outbox-schema.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAIA;AACA,MAAMC,UAA6B,GAAG,CACpC;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,mEAAmE,CAClE;AAED,MAAMC,OAAO,GAAG;AAChB;AACA,wEAAwE;AAExE,MAAMC,YAAY,GAAG,oCAAoC;AACzD,MAAMC,aAAa,GAAG,iDAAiD;;AAEvE;AACA,MAAMC,mBAAmB,GAAG,MAAAA,CAAOC,QAAwB,EAAEC,MAAc,GAAGC,mBAAY,KAAoB;EAC5G,MAAMF,QAAQ,CAACG,SAAS,CAACP,OAAO,CAAC;EAEjC,MAAMQ,IAAI,GAAG,CAAC,MAAMJ,QAAQ,CAACK,aAAa,CAAsBR,YAAY,CAAC,GAAGS,OAAO,IAAI,CAAC;
|
|
1
|
+
{"version":3,"names":["_ports","require","MIGRATIONS","PREPARE","READ_VERSION","WRITE_VERSION","migrateOutboxSchema","database","logger","silentLogger","execAsync","from","getFirstAsync","version","to","length","withExclusiveTransactionAsync","transaction","migration","slice","runAsync","info","exports"],"sourceRoot":"../../../../../../src","sources":["modules/next/bluetooth/adapters/sqlite-outbox-schema.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAIA;AACA,MAAMC,UAA6B,GAAG,CACpC;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,mEAAmE,CAClE;AAED,MAAMC,OAAO,GAAG;AAChB;AACA,wEAAwE;AAExE,MAAMC,YAAY,GAAG,oCAAoC;AACzD,MAAMC,aAAa,GAAG,iDAAiD;;AAEvE;AACA,MAAMC,mBAAmB,GAAG,MAAAA,CAAOC,QAAwB,EAAEC,MAAc,GAAGC,mBAAY,KAAoB;EAC5G,MAAMF,QAAQ,CAACG,SAAS,CAACP,OAAO,CAAC;EAEjC,MAAMQ,IAAI,GAAG,CAAC,MAAMJ,QAAQ,CAACK,aAAa,CAAsBR,YAAY,EAAE,EAAE,CAAC,GAAGS,OAAO,IAAI,CAAC;EAChG,MAAMC,EAAE,GAAGZ,UAAU,CAACa,MAAM;EAE5B,IAAIJ,IAAI,IAAIG,EAAE,EAAE;IACd;EACF;EAEA,MAAMP,QAAQ,CAACS,6BAA6B,CAAC,MAAOC,WAAW,IAAK;IAClE,KAAK,MAAMC,SAAS,IAAIhB,UAAU,CAACiB,KAAK,CAACR,IAAI,CAAC,EAAE;MAC9C,MAAMM,WAAW,CAACP,SAAS,CAACQ,SAAS,CAAC;IACxC;IACA,MAAMD,WAAW,CAACP,SAAS,CAAC,4BAA4B,CAAC;IACzD,MAAMO,WAAW,CAACG,QAAQ,CAACf,aAAa,EAAE,CAACS,EAAE,CAAC,CAAC;EACjD,CAAC,CAAC;EACFN,MAAM,CAACa,IAAI,CAAC,wBAAwB,EAAE;IAAEV,IAAI;IAAEG;EAAG,CAAC,CAAC;AACrD,CAAC;AAACQ,OAAA,CAAAhB,mBAAA,GAAAA,mBAAA","ignoreList":[]}
|
|
@@ -4,78 +4,27 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.SqliteOutboxStore = void 0;
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
var _sqliteOutboxSchema = require("./sqlite-outbox-schema.js");
|
|
10
|
-
/** How `SqliteOutboxStore` finds its database; every field has a default for a phone app. */
|
|
7
|
+
var _sqliteDatabaseOutboxStore = require("./sqlite-database-outbox-store.js");
|
|
8
|
+
/** Every field has a default for a phone app; `open` defaults to `expo-sqlite`'s `openDatabaseAsync`. */
|
|
11
9
|
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const DUE = `SELECT ${_sqliteOutboxRows.ITEM_COLUMN_LIST} FROM outbox_items
|
|
18
|
-
WHERE owner_key = ? AND state = ? AND next_attempt_at <= ?
|
|
19
|
-
ORDER BY recorded_at DESC, COALESCE(seq, 0), id
|
|
20
|
-
LIMIT ?`;
|
|
21
|
-
const SUMMARIES = `SELECT ${_sqliteOutboxRows.SUMMARY_COLUMN_LIST} FROM outbox_items WHERE owner_key = ? ORDER BY recorded_at DESC`;
|
|
22
|
-
const COUNT = "SELECT COUNT(*) AS total FROM outbox_items WHERE owner_key = ? AND state = ?";
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* An `OutboxStore` on `expo-sqlite`, for phones: one row per item in `outbox_items`, the entries as one JSON text
|
|
26
|
-
* column, so listing and counting never read them. `expo-sqlite` is an optional peer dependency, loaded on first use.
|
|
27
|
-
*/
|
|
28
|
-
class SqliteOutboxStore {
|
|
29
|
-
database = null;
|
|
30
|
-
constructor(options = {}) {
|
|
31
|
-
this.options = options;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** Stores an item, replacing the one with the same id. */
|
|
35
|
-
async put(item) {
|
|
36
|
-
await (await this.open()).runAsync(PUT, (0, _sqliteOutboxRows.bindValuesOf)(item));
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/** Returns an item, or `null` when there is none. */
|
|
40
|
-
async get(id) {
|
|
41
|
-
const row = await (await this.open()).getFirstAsync(GET, [id]);
|
|
42
|
-
return row && (0, _sqliteOutboxRows.itemOf)(row);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** Deletes an item; an unknown id is not an error. */
|
|
46
|
-
async remove(id) {
|
|
47
|
-
await (await this.open()).runAsync(REMOVE, [id]);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/** The owner's pending items that are due, newest recorded first, then by position in the recording. */
|
|
51
|
-
async due(ownerKey, now, limit) {
|
|
52
|
-
const rows = await (await this.open()).getAllAsync(DUE, [ownerKey, PENDING, now, limit]);
|
|
53
|
-
return rows.map(_sqliteOutboxRows.itemOf);
|
|
10
|
+
const loadExpoSqlite = () => {
|
|
11
|
+
try {
|
|
12
|
+
return require("expo-sqlite");
|
|
13
|
+
} catch {
|
|
14
|
+
throw new Error("SqliteOutboxStore requires the optional expo-sqlite peer dependency");
|
|
54
15
|
}
|
|
16
|
+
};
|
|
55
17
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const rows = await (await this.open()).getAllAsync(SUMMARIES, [ownerKey]);
|
|
59
|
-
return rows.map(_sqliteOutboxRows.summaryOf);
|
|
60
|
-
}
|
|
18
|
+
/** Opens the named database with `expo-sqlite`, which an app without the package never loads. */
|
|
19
|
+
const openExpoSqlite = name => loadExpoSqlite().openDatabaseAsync(name);
|
|
61
20
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
this.database ??= this.connect().catch(error => {
|
|
69
|
-
this.database = null;
|
|
70
|
-
throw error;
|
|
21
|
+
/** The outbox store on `expo-sqlite`, for phones; `expo-sqlite` is an optional peer dependency, loaded on first use. */
|
|
22
|
+
class SqliteOutboxStore extends _sqliteDatabaseOutboxStore.SqliteDatabaseOutboxStore {
|
|
23
|
+
constructor(options = {}) {
|
|
24
|
+
super({
|
|
25
|
+
...options,
|
|
26
|
+
open: options.open ?? openExpoSqlite
|
|
71
27
|
});
|
|
72
|
-
return this.database;
|
|
73
|
-
}
|
|
74
|
-
async connect() {
|
|
75
|
-
const open = this.options.open ?? _sqliteDatabase.openExpoSqlite;
|
|
76
|
-
const database = await open(this.options.name ?? DEFAULT_DATABASE_NAME);
|
|
77
|
-
await (0, _sqliteOutboxSchema.migrateOutboxSchema)(database, this.options.logger);
|
|
78
|
-
return database;
|
|
79
28
|
}
|
|
80
29
|
}
|
|
81
30
|
exports.SqliteOutboxStore = SqliteOutboxStore;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_sqliteDatabaseOutboxStore","require","loadExpoSqlite","Error","openExpoSqlite","name","openDatabaseAsync","SqliteOutboxStore","SqliteDatabaseOutboxStore","constructor","options","open","exports"],"sourceRoot":"../../../../../../src","sources":["modules/next/bluetooth/adapters/sqlite-outbox-store.ts"],"mappings":";;;;;;AAEA,IAAAA,0BAAA,GAAAC,OAAA;AAGA;;AAGA,MAAMC,cAAc,GAAGA,CAAA,KAAkB;EACvC,IAAI;IACF,OAAOD,OAAO,CAAC,aAAa,CAAC;EAC/B,CAAC,CAAC,MAAM;IACN,MAAM,IAAIE,KAAK,CAAC,qEAAqE,CAAC;EACxF;AACF,CAAC;;AAED;AACA,MAAMC,cAAc,GAAIC,IAAY,IAA8BH,cAAc,CAAC,CAAC,CAACI,iBAAiB,CAACD,IAAI,CAAC;;AAE1G;AACA,MAAME,iBAAiB,SAASC,oDAAyB,CAAC;EACjDC,WAAWA,CAACC,OAA4B,GAAG,CAAC,CAAC,EAAE;IACpD,KAAK,CAAC;MAAE,GAAGA,OAAO;MAAEC,IAAI,EAAED,OAAO,CAACC,IAAI,IAAIP;IAAe,CAAC,CAAC;EAC7D;AACF;AAACQ,OAAA,CAAAL,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_sqliteOutboxStore","require"],"sourceRoot":"../../../../../../src","sources":["modules/next/bluetooth/sqlite/index.ts"],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"names":["_sqliteOutboxStore","require"],"sourceRoot":"../../../../../../src","sources":["modules/next/bluetooth/sqlite/index.ts"],"mappings":";;;;;;;;;;;AAOA,IAAAA,kBAAA,GAAAC,OAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_next","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_ovok","_secureStoreStorage"],"sourceRoot":"../../../../src","sources":["modules/next/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAOA,IAAAA,KAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,KAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAL,KAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAb,KAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,KAAA,GAAAb,OAAA;
|
|
1
|
+
{"version":3,"names":["_next","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_ovok","_secureStoreStorage"],"sourceRoot":"../../../../src","sources":["modules/next/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAOA,IAAAA,KAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,KAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAL,KAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAb,KAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,KAAA,GAAAb,OAAA;AAIA,IAAAc,mBAAA,GAAAd,OAAA","ignoreList":[]}
|
|
@@ -5,11 +5,31 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.Ovok = void 0;
|
|
7
7
|
var _next = require("@ovok/core/next");
|
|
8
|
+
var _sqliteDatabaseOutboxStore = require("./bluetooth/adapters/sqlite-database-outbox-store.js");
|
|
8
9
|
var _randomValues = require("./random-values.js");
|
|
10
|
+
var _reactNativeOutboxTriggers = require("./react-native-outbox-triggers.js");
|
|
9
11
|
var _secureStoreStorage = require("./secure-store-storage.js");
|
|
10
12
|
/** No clientSecret: anything shipped inside an app can be extracted from it. */
|
|
11
13
|
|
|
12
|
-
|
|
14
|
+
const outboxStoreOf = ({
|
|
15
|
+
outboxStore,
|
|
16
|
+
sqlite
|
|
17
|
+
}) => {
|
|
18
|
+
if (outboxStore) {
|
|
19
|
+
return outboxStore;
|
|
20
|
+
}
|
|
21
|
+
if (!sqlite) {
|
|
22
|
+
throw new TypeError("Pass the Ovok client sqlite (the expo-sqlite module) or an outboxStore for unsent measurements.");
|
|
23
|
+
}
|
|
24
|
+
return new _sqliteDatabaseOutboxStore.SqliteDatabaseOutboxStore({
|
|
25
|
+
open: name => sqlite.openDatabaseAsync(name)
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The @ovok/core/next client with the session kept in the device's secure store and unsent measurements in SQLite,
|
|
31
|
+
* sent when the network returns and when the app comes to the foreground.
|
|
32
|
+
*/
|
|
13
33
|
class Ovok extends _next.Ovok {
|
|
14
34
|
/** Base URL of the Ovok API, with a trailing slash. */
|
|
15
35
|
|
|
@@ -29,7 +49,10 @@ class Ovok extends _next.Ovok {
|
|
|
29
49
|
super({
|
|
30
50
|
...shared,
|
|
31
51
|
clientSecret: undefined,
|
|
32
|
-
storage
|
|
52
|
+
storage,
|
|
53
|
+
outboxStore: outboxStoreOf(config),
|
|
54
|
+
connectivity: shared.connectivity ?? _reactNativeOutboxTriggers.netInfoConnectivity,
|
|
55
|
+
lifecycle: shared.lifecycle ?? _reactNativeOutboxTriggers.appStateLifecycle
|
|
33
56
|
});
|
|
34
57
|
this.baseUrl = shared.baseUrl.endsWith("/") ? shared.baseUrl : `${shared.baseUrl}/`;
|
|
35
58
|
this.tenantCode = shared.tenantCode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_next","require","_randomValues","_secureStoreStorage","Ovok","CoreOvok","constructor","config","secureStore","secureStoreOptions","getRandomValues","shared","storage","SecureStoreStorage","installRandomValues","clientSecret","undefined","baseUrl","endsWith","tenantCode","exports"],"sourceRoot":"../../../../src","sources":["modules/next/ovok.ts"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;
|
|
1
|
+
{"version":3,"names":["_next","require","_sqliteDatabaseOutboxStore","_randomValues","_reactNativeOutboxTriggers","_secureStoreStorage","outboxStoreOf","outboxStore","sqlite","TypeError","SqliteDatabaseOutboxStore","open","name","openDatabaseAsync","Ovok","CoreOvok","constructor","config","secureStore","secureStoreOptions","getRandomValues","shared","storage","SecureStoreStorage","installRandomValues","clientSecret","undefined","connectivity","netInfoConnectivity","lifecycle","appStateLifecycle","baseUrl","endsWith","tenantCode","exports"],"sourceRoot":"../../../../src","sources":["modules/next/ovok.ts"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAOA,IAAAC,0BAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAF,OAAA;AACA,IAAAG,0BAAA,GAAAH,OAAA;AACA,IAAAI,mBAAA,GAAAJ,OAAA;AAIA;;AAmBA,MAAMK,aAAa,GAAGA,CAAC;EAAEC,WAAW;EAAEC;AAAyD,CAAC,KAAkB;EAChH,IAAID,WAAW,EAAE;IACf,OAAOA,WAAW;EACpB;EAEA,IAAI,CAACC,MAAM,EAAE;IACX,MAAM,IAAIC,SAAS,CAAC,iGAAiG,CAAC;EACxH;EAEA,OAAO,IAAIC,oDAAyB,CAAC;IAAEC,IAAI,EAAGC,IAAI,IAAKJ,MAAM,CAACK,iBAAiB,CAACD,IAAI;EAAE,CAAC,CAAC;AAC1F,CAAC;;AAED;AACA;AACA;AACA;AACA,MAAME,IAAI,SAASC,UAAQ,CAAC;EAC1B;;EAGA;;EAGA;;EAGAC,WAAWA,CAACC,MAAwB,EAAE;IACpC,MAAM;MAAEC,WAAW;MAAEC,kBAAkB;MAAEC,eAAe;MAAE,GAAGC;IAAO,CAAC,GAAGJ,MAAM;IAC9E,MAAMK,OAAO,GAAG,IAAIC,sCAAkB,CAACL,WAAW,EAAEC,kBAAkB,CAAC;IAEvE,IAAAK,iCAAmB,EAACJ,eAAe,CAAC;IACpC,KAAK,CAAC;MACJ,GAAGC,MAAM;MACTI,YAAY,EAAEC,SAAS;MACvBJ,OAAO;MACPf,WAAW,EAAED,aAAa,CAACW,MAAM,CAAC;MAClCU,YAAY,EAAEN,MAAM,CAACM,YAAY,IAAIC,8CAAmB;MACxDC,SAAS,EAAER,MAAM,CAACQ,SAAS,IAAIC;IACjC,CAAC,CAAC;IACF,IAAI,CAACC,OAAO,GAAGV,MAAM,CAACU,OAAO,CAACC,QAAQ,CAAC,GAAG,CAAC,GAAGX,MAAM,CAACU,OAAO,GAAG,GAAGV,MAAM,CAACU,OAAO,GAAG;IACnF,IAAI,CAACE,UAAU,GAAGZ,MAAM,CAACY,UAAU;IACnC,IAAI,CAACX,OAAO,GAAGA,OAAO;EACxB;AACF;AAACY,OAAA,CAAApB,IAAA,GAAAA,IAAA","ignoreList":[]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.netInfoConnectivity = exports.appStateLifecycle = void 0;
|
|
7
|
+
var _netinfo = require("@react-native-community/netinfo");
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
/** An unknown internet reachability counts as online, as on the first report after launch. */
|
|
10
|
+
const isOnline = ({
|
|
11
|
+
isConnected,
|
|
12
|
+
isInternetReachable
|
|
13
|
+
}) => isConnected === true && isInternetReachable !== false;
|
|
14
|
+
|
|
15
|
+
/** The device's connection through NetInfo: the outbox hears each time it comes back after going offline. */
|
|
16
|
+
const netInfoConnectivity = exports.netInfoConnectivity = {
|
|
17
|
+
subscribe: onOnline => {
|
|
18
|
+
let wasOnline = true;
|
|
19
|
+
return (0, _netinfo.addEventListener)(state => {
|
|
20
|
+
const online = isOnline(state);
|
|
21
|
+
if (online && !wasOnline) {
|
|
22
|
+
onOnline();
|
|
23
|
+
}
|
|
24
|
+
wasOnline = online;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/** The app's foreground through React Native's `AppState`. */
|
|
30
|
+
const appStateLifecycle = exports.appStateLifecycle = {
|
|
31
|
+
subscribe: onForeground => {
|
|
32
|
+
const subscription = _reactNative.AppState.addEventListener("change", state => {
|
|
33
|
+
if (state === "active") {
|
|
34
|
+
onForeground();
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return () => subscription.remove();
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=react-native-outbox-triggers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_netinfo","require","_reactNative","isOnline","isConnected","isInternetReachable","netInfoConnectivity","exports","subscribe","onOnline","wasOnline","addNetworkListener","state","online","appStateLifecycle","onForeground","subscription","AppState","addEventListener","remove"],"sourceRoot":"../../../../src","sources":["modules/next/react-native-outbox-triggers.ts"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAKA;AACA,MAAME,QAAQ,GAAGA,CAAC;EAAEC,WAAW;EAAEC;AAAkC,CAAC,KAClED,WAAW,KAAK,IAAI,IAAIC,mBAAmB,KAAK,KAAK;;AAEvD;AACA,MAAMC,mBAAuC,GAAAC,OAAA,CAAAD,mBAAA,GAAG;EAC9CE,SAAS,EAAGC,QAAQ,IAAK;IACvB,IAAIC,SAAS,GAAG,IAAI;IAEpB,OAAO,IAAAC,yBAAkB,EAAEC,KAAK,IAAK;MACnC,MAAMC,MAAM,GAAGV,QAAQ,CAACS,KAAK,CAAC;MAE9B,IAAIC,MAAM,IAAI,CAACH,SAAS,EAAE;QACxBD,QAAQ,CAAC,CAAC;MACZ;MACAC,SAAS,GAAGG,MAAM;IACpB,CAAC,CAAC;EACJ;AACF,CAAC;;AAED;AACA,MAAMC,iBAAkC,GAAAP,OAAA,CAAAO,iBAAA,GAAG;EACzCN,SAAS,EAAGO,YAAY,IAAK;IAC3B,MAAMC,YAAY,GAAGC,qBAAQ,CAACC,gBAAgB,CAAC,QAAQ,EAAGN,KAAK,IAAK;MAClE,IAAIA,KAAK,KAAK,QAAQ,EAAE;QACtBG,YAAY,CAAC,CAAC;MAChB;IACF,CAAC,CAAC;IAEF,OAAO,MAAMC,YAAY,CAACG,MAAM,CAAC,CAAC;EACpC;AACF,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { bindValuesOf, ITEM_COLUMN_LIST, ITEM_PLACEHOLDERS, itemOf, SUMMARY_COLUMN_LIST, summaryOf } from "./sqlite-outbox-rows.js";
|
|
4
|
+
import { migrateOutboxSchema } from "./sqlite-outbox-schema.js";
|
|
5
|
+
|
|
6
|
+
/** How `SqliteDatabaseOutboxStore` opens its database. */
|
|
7
|
+
|
|
8
|
+
const DEFAULT_DATABASE_NAME = "ovok-outbox.db";
|
|
9
|
+
const PENDING = "pending";
|
|
10
|
+
const PUT = `INSERT OR REPLACE INTO outbox_items (${ITEM_COLUMN_LIST}) VALUES (${ITEM_PLACEHOLDERS})`;
|
|
11
|
+
const GET = `SELECT ${ITEM_COLUMN_LIST} FROM outbox_items WHERE id = ?`;
|
|
12
|
+
const REMOVE = "DELETE FROM outbox_items WHERE id = ?";
|
|
13
|
+
const DUE = `SELECT ${ITEM_COLUMN_LIST} FROM outbox_items
|
|
14
|
+
WHERE owner_key = ? AND state = ? AND next_attempt_at <= ?
|
|
15
|
+
ORDER BY recorded_at DESC, COALESCE(seq, 0), id
|
|
16
|
+
LIMIT ?`;
|
|
17
|
+
const SUMMARIES = `SELECT ${SUMMARY_COLUMN_LIST} FROM outbox_items WHERE owner_key = ? ORDER BY recorded_at DESC`;
|
|
18
|
+
const COUNT = "SELECT COUNT(*) AS total FROM outbox_items WHERE owner_key = ? AND state = ?";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* An `OutboxStore` on a SQLite database it is given a way to open: one row per item in `outbox_items`, the entries as
|
|
22
|
+
* one JSON text column, so listing and counting never read them. The database opens on first use.
|
|
23
|
+
*/
|
|
24
|
+
class SqliteDatabaseOutboxStore {
|
|
25
|
+
database = null;
|
|
26
|
+
constructor(options) {
|
|
27
|
+
this.options = options;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Stores an item, replacing the one with the same id. */
|
|
31
|
+
async put(item) {
|
|
32
|
+
await (await this.open()).runAsync(PUT, bindValuesOf(item));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Returns an item, or `null` when there is none. */
|
|
36
|
+
async get(id) {
|
|
37
|
+
const row = await (await this.open()).getFirstAsync(GET, [id]);
|
|
38
|
+
return row && itemOf(row);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Deletes an item; an unknown id is not an error. */
|
|
42
|
+
async remove(id) {
|
|
43
|
+
await (await this.open()).runAsync(REMOVE, [id]);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The owner's pending items that are due, newest recorded first, then by position in the recording. */
|
|
47
|
+
async due(ownerKey, now, limit) {
|
|
48
|
+
const rows = await (await this.open()).getAllAsync(DUE, [ownerKey, PENDING, now, limit]);
|
|
49
|
+
return rows.map(itemOf);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Every item of the owner in any state, newest recorded first, without its entries. */
|
|
53
|
+
async summaries(ownerKey) {
|
|
54
|
+
const rows = await (await this.open()).getAllAsync(SUMMARIES, [ownerKey]);
|
|
55
|
+
return rows.map(summaryOf);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** How many of the owner's items are in `state`. */
|
|
59
|
+
async count(ownerKey, state) {
|
|
60
|
+
const row = await (await this.open()).getFirstAsync(COUNT, [ownerKey, state]);
|
|
61
|
+
return row?.total ?? 0;
|
|
62
|
+
}
|
|
63
|
+
open() {
|
|
64
|
+
this.database ??= this.connect().catch(error => {
|
|
65
|
+
this.database = null;
|
|
66
|
+
throw error;
|
|
67
|
+
});
|
|
68
|
+
return this.database;
|
|
69
|
+
}
|
|
70
|
+
async connect() {
|
|
71
|
+
const database = await this.options.open(this.options.name ?? DEFAULT_DATABASE_NAME);
|
|
72
|
+
await migrateOutboxSchema(database, this.options.logger);
|
|
73
|
+
return database;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export { SqliteDatabaseOutboxStore };
|
|
77
|
+
//# sourceMappingURL=sqlite-database-outbox-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["bindValuesOf","ITEM_COLUMN_LIST","ITEM_PLACEHOLDERS","itemOf","SUMMARY_COLUMN_LIST","summaryOf","migrateOutboxSchema","DEFAULT_DATABASE_NAME","PENDING","PUT","GET","REMOVE","DUE","SUMMARIES","COUNT","SqliteDatabaseOutboxStore","database","constructor","options","put","item","open","runAsync","get","id","row","getFirstAsync","remove","due","ownerKey","now","limit","rows","getAllAsync","map","summaries","count","state","total","connect","catch","error","name","logger"],"sourceRoot":"../../../../../../src","sources":["modules/next/bluetooth/adapters/sqlite-database-outbox-store.ts"],"mappings":"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","ignoreList":[]}
|
|
@@ -1,20 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
/** A value SQLite binds to a `?` placeholder. */
|
|
4
|
-
|
|
5
|
-
/** The part of an `expo-sqlite` transaction the outbox store uses. */
|
|
6
|
-
|
|
7
|
-
/** The part of an `expo-sqlite` database the outbox store uses. */
|
|
8
|
-
|
|
9
|
-
const loadExpoSqlite = () => {
|
|
10
|
-
try {
|
|
11
|
-
return require("expo-sqlite");
|
|
12
|
-
} catch {
|
|
13
|
-
throw new Error("SqliteOutboxStore requires the optional expo-sqlite peer dependency");
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/** Opens the named database with `expo-sqlite`, which an app without the package never loads. */
|
|
18
|
-
const openExpoSqlite = name => loadExpoSqlite().openDatabaseAsync(name);
|
|
19
|
-
export { openExpoSqlite };
|
|
20
2
|
//# sourceMappingURL=sqlite-database.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../../../../src","sources":["modules/next/bluetooth/adapters/sqlite-database.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -28,7 +28,7 @@ const WRITE_VERSION = "INSERT INTO schema_version (version) VALUES (?)";
|
|
|
28
28
|
/** Brings the database to the latest schema; every pending migration runs in one transaction, so a crash leaves none. */
|
|
29
29
|
const migrateOutboxSchema = async (database, logger = silentLogger) => {
|
|
30
30
|
await database.execAsync(PREPARE);
|
|
31
|
-
const from = (await database.getFirstAsync(READ_VERSION))?.version ?? 0;
|
|
31
|
+
const from = (await database.getFirstAsync(READ_VERSION, []))?.version ?? 0;
|
|
32
32
|
const to = MIGRATIONS.length;
|
|
33
33
|
if (from >= to) {
|
|
34
34
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["silentLogger","MIGRATIONS","PREPARE","READ_VERSION","WRITE_VERSION","migrateOutboxSchema","database","logger","execAsync","from","getFirstAsync","version","to","length","withExclusiveTransactionAsync","transaction","migration","slice","runAsync","info"],"sourceRoot":"../../../../../../src","sources":["modules/next/bluetooth/adapters/sqlite-outbox-schema.ts"],"mappings":";;AAAA,SAAiBA,YAAY,QAAQ,kBAAe;AAIpD;AACA,MAAMC,UAA6B,GAAG,CACpC;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,mEAAmE,CAClE;AAED,MAAMC,OAAO,GAAG;AAChB;AACA,wEAAwE;AAExE,MAAMC,YAAY,GAAG,oCAAoC;AACzD,MAAMC,aAAa,GAAG,iDAAiD;;AAEvE;AACA,MAAMC,mBAAmB,GAAG,MAAAA,CAAOC,QAAwB,EAAEC,MAAc,GAAGP,YAAY,KAAoB;EAC5G,MAAMM,QAAQ,CAACE,SAAS,CAACN,OAAO,CAAC;EAEjC,MAAMO,IAAI,GAAG,CAAC,MAAMH,QAAQ,CAACI,aAAa,CAAsBP,YAAY,CAAC,GAAGQ,OAAO,IAAI,CAAC;
|
|
1
|
+
{"version":3,"names":["silentLogger","MIGRATIONS","PREPARE","READ_VERSION","WRITE_VERSION","migrateOutboxSchema","database","logger","execAsync","from","getFirstAsync","version","to","length","withExclusiveTransactionAsync","transaction","migration","slice","runAsync","info"],"sourceRoot":"../../../../../../src","sources":["modules/next/bluetooth/adapters/sqlite-outbox-schema.ts"],"mappings":";;AAAA,SAAiBA,YAAY,QAAQ,kBAAe;AAIpD;AACA,MAAMC,UAA6B,GAAG,CACpC;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,mEAAmE,CAClE;AAED,MAAMC,OAAO,GAAG;AAChB;AACA,wEAAwE;AAExE,MAAMC,YAAY,GAAG,oCAAoC;AACzD,MAAMC,aAAa,GAAG,iDAAiD;;AAEvE;AACA,MAAMC,mBAAmB,GAAG,MAAAA,CAAOC,QAAwB,EAAEC,MAAc,GAAGP,YAAY,KAAoB;EAC5G,MAAMM,QAAQ,CAACE,SAAS,CAACN,OAAO,CAAC;EAEjC,MAAMO,IAAI,GAAG,CAAC,MAAMH,QAAQ,CAACI,aAAa,CAAsBP,YAAY,EAAE,EAAE,CAAC,GAAGQ,OAAO,IAAI,CAAC;EAChG,MAAMC,EAAE,GAAGX,UAAU,CAACY,MAAM;EAE5B,IAAIJ,IAAI,IAAIG,EAAE,EAAE;IACd;EACF;EAEA,MAAMN,QAAQ,CAACQ,6BAA6B,CAAC,MAAOC,WAAW,IAAK;IAClE,KAAK,MAAMC,SAAS,IAAIf,UAAU,CAACgB,KAAK,CAACR,IAAI,CAAC,EAAE;MAC9C,MAAMM,WAAW,CAACP,SAAS,CAACQ,SAAS,CAAC;IACxC;IACA,MAAMD,WAAW,CAACP,SAAS,CAAC,4BAA4B,CAAC;IACzD,MAAMO,WAAW,CAACG,QAAQ,CAACd,aAAa,EAAE,CAACQ,EAAE,CAAC,CAAC;EACjD,CAAC,CAAC;EACFL,MAAM,CAACY,IAAI,CAAC,wBAAwB,EAAE;IAAEV,IAAI;IAAEG;EAAG,CAAC,CAAC;AACrD,CAAC;AAED,SAASP,mBAAmB","ignoreList":[]}
|
|
@@ -1,78 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { bindValuesOf, ITEM_COLUMN_LIST, ITEM_PLACEHOLDERS, itemOf, SUMMARY_COLUMN_LIST, summaryOf } from "./sqlite-outbox-rows.js";
|
|
5
|
-
import { migrateOutboxSchema } from "./sqlite-outbox-schema.js";
|
|
3
|
+
import { SqliteDatabaseOutboxStore } from "./sqlite-database-outbox-store.js";
|
|
6
4
|
|
|
7
|
-
/**
|
|
5
|
+
/** Every field has a default for a phone app; `open` defaults to `expo-sqlite`'s `openDatabaseAsync`. */
|
|
8
6
|
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const DUE = `SELECT ${ITEM_COLUMN_LIST} FROM outbox_items
|
|
15
|
-
WHERE owner_key = ? AND state = ? AND next_attempt_at <= ?
|
|
16
|
-
ORDER BY recorded_at DESC, COALESCE(seq, 0), id
|
|
17
|
-
LIMIT ?`;
|
|
18
|
-
const SUMMARIES = `SELECT ${SUMMARY_COLUMN_LIST} FROM outbox_items WHERE owner_key = ? ORDER BY recorded_at DESC`;
|
|
19
|
-
const COUNT = "SELECT COUNT(*) AS total FROM outbox_items WHERE owner_key = ? AND state = ?";
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* An `OutboxStore` on `expo-sqlite`, for phones: one row per item in `outbox_items`, the entries as one JSON text
|
|
23
|
-
* column, so listing and counting never read them. `expo-sqlite` is an optional peer dependency, loaded on first use.
|
|
24
|
-
*/
|
|
25
|
-
class SqliteOutboxStore {
|
|
26
|
-
database = null;
|
|
27
|
-
constructor(options = {}) {
|
|
28
|
-
this.options = options;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** Stores an item, replacing the one with the same id. */
|
|
32
|
-
async put(item) {
|
|
33
|
-
await (await this.open()).runAsync(PUT, bindValuesOf(item));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** Returns an item, or `null` when there is none. */
|
|
37
|
-
async get(id) {
|
|
38
|
-
const row = await (await this.open()).getFirstAsync(GET, [id]);
|
|
39
|
-
return row && itemOf(row);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/** Deletes an item; an unknown id is not an error. */
|
|
43
|
-
async remove(id) {
|
|
44
|
-
await (await this.open()).runAsync(REMOVE, [id]);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/** The owner's pending items that are due, newest recorded first, then by position in the recording. */
|
|
48
|
-
async due(ownerKey, now, limit) {
|
|
49
|
-
const rows = await (await this.open()).getAllAsync(DUE, [ownerKey, PENDING, now, limit]);
|
|
50
|
-
return rows.map(itemOf);
|
|
7
|
+
const loadExpoSqlite = () => {
|
|
8
|
+
try {
|
|
9
|
+
return require("expo-sqlite");
|
|
10
|
+
} catch {
|
|
11
|
+
throw new Error("SqliteOutboxStore requires the optional expo-sqlite peer dependency");
|
|
51
12
|
}
|
|
13
|
+
};
|
|
52
14
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const rows = await (await this.open()).getAllAsync(SUMMARIES, [ownerKey]);
|
|
56
|
-
return rows.map(summaryOf);
|
|
57
|
-
}
|
|
15
|
+
/** Opens the named database with `expo-sqlite`, which an app without the package never loads. */
|
|
16
|
+
const openExpoSqlite = name => loadExpoSqlite().openDatabaseAsync(name);
|
|
58
17
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
this.database ??= this.connect().catch(error => {
|
|
66
|
-
this.database = null;
|
|
67
|
-
throw error;
|
|
18
|
+
/** The outbox store on `expo-sqlite`, for phones; `expo-sqlite` is an optional peer dependency, loaded on first use. */
|
|
19
|
+
class SqliteOutboxStore extends SqliteDatabaseOutboxStore {
|
|
20
|
+
constructor(options = {}) {
|
|
21
|
+
super({
|
|
22
|
+
...options,
|
|
23
|
+
open: options.open ?? openExpoSqlite
|
|
68
24
|
});
|
|
69
|
-
return this.database;
|
|
70
|
-
}
|
|
71
|
-
async connect() {
|
|
72
|
-
const open = this.options.open ?? openExpoSqlite;
|
|
73
|
-
const database = await open(this.options.name ?? DEFAULT_DATABASE_NAME);
|
|
74
|
-
await migrateOutboxSchema(database, this.options.logger);
|
|
75
|
-
return database;
|
|
76
25
|
}
|
|
77
26
|
}
|
|
78
27
|
export { SqliteOutboxStore };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["SqliteDatabaseOutboxStore","loadExpoSqlite","require","Error","openExpoSqlite","name","openDatabaseAsync","SqliteOutboxStore","constructor","options","open"],"sourceRoot":"../../../../../../src","sources":["modules/next/bluetooth/adapters/sqlite-outbox-store.ts"],"mappings":";;AAEA,SAAsCA,yBAAyB,QAAQ,mCAAgC;;AAGvG;;AAGA,MAAMC,cAAc,GAAGA,CAAA,KAAkB;EACvC,IAAI;IACF,OAAOC,OAAO,CAAC,aAAa,CAAC;EAC/B,CAAC,CAAC,MAAM;IACN,MAAM,IAAIC,KAAK,CAAC,qEAAqE,CAAC;EACxF;AACF,CAAC;;AAED;AACA,MAAMC,cAAc,GAAIC,IAAY,IAA8BJ,cAAc,CAAC,CAAC,CAACK,iBAAiB,CAACD,IAAI,CAAC;;AAE1G;AACA,MAAME,iBAAiB,SAASP,yBAAyB,CAAC;EACjDQ,WAAWA,CAACC,OAA4B,GAAG,CAAC,CAAC,EAAE;IACpD,KAAK,CAAC;MAAE,GAAGA,OAAO;MAAEC,IAAI,EAAED,OAAO,CAACC,IAAI,IAAIN;IAAe,CAAC,CAAC;EAC7D;AACF;AAEA,SAASG,iBAAiB","ignoreList":[]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* The outbox store on `expo-sqlite
|
|
5
|
-
* It has its own subpath so apps without `expo-sqlite`, and browser
|
|
4
|
+
* The outbox store on `expo-sqlite`, for an app that builds its own instead of passing `sqlite` to the `Ovok` client.
|
|
5
|
+
* Import from `@ovok/native/next/bluetooth/sqlite`. It has its own subpath so apps without `expo-sqlite`, and browser
|
|
6
|
+
* bundles, never load it.
|
|
6
7
|
*
|
|
7
8
|
* @module next/bluetooth/sqlite
|
|
8
9
|
*/
|