@tanstack/db-sqlite-persistence-core 0.1.2
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/README.md +95 -0
- package/dist/cjs/errors.cjs +72 -0
- package/dist/cjs/errors.cjs.map +1 -0
- package/dist/cjs/errors.d.cts +25 -0
- package/dist/cjs/index.cjs +22 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +3 -0
- package/dist/cjs/persisted.cjs +1705 -0
- package/dist/cjs/persisted.cjs.map +1 -0
- package/dist/cjs/persisted.d.cts +293 -0
- package/dist/cjs/sqlite-core-adapter.cjs +1588 -0
- package/dist/cjs/sqlite-core-adapter.cjs.map +1 -0
- package/dist/cjs/sqlite-core-adapter.d.cts +67 -0
- package/dist/esm/errors.d.ts +25 -0
- package/dist/esm/errors.js +72 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +22 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/persisted.d.ts +293 -0
- package/dist/esm/persisted.js +1705 -0
- package/dist/esm/persisted.js.map +1 -0
- package/dist/esm/sqlite-core-adapter.d.ts +67 -0
- package/dist/esm/sqlite-core-adapter.js +1588 -0
- package/dist/esm/sqlite-core-adapter.js.map +1 -0
- package/package.json +57 -0
- package/src/errors.ts +73 -0
- package/src/index.ts +3 -0
- package/src/persisted.ts +2820 -0
- package/src/sqlite-core-adapter.ts +2129 -0
package/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# @tanstack/db-sqlite-persistence-core
|
|
2
|
+
|
|
3
|
+
Shared SQLite persistence primitives for TanStack DB. Runtime-specific wrappers
|
|
4
|
+
(Node, Electron, React Native, Cloudflare Durable Objects) build on top of this
|
|
5
|
+
package.
|
|
6
|
+
|
|
7
|
+
## What this package provides
|
|
8
|
+
|
|
9
|
+
- Generic persisted collection wrapper utilities
|
|
10
|
+
- Shared persistence/coordinator protocol types
|
|
11
|
+
- SQLite core persistence adapter (`createSQLiteCorePersistenceAdapter`)
|
|
12
|
+
- Validation and storage key helpers
|
|
13
|
+
- Shared error types
|
|
14
|
+
|
|
15
|
+
This package intentionally does **not** include a concrete SQLite engine
|
|
16
|
+
binding. Provide a runtime `SQLiteDriver` implementation from a wrapper package.
|
|
17
|
+
|
|
18
|
+
## Exported API (complete)
|
|
19
|
+
|
|
20
|
+
### Persisted wrapper and protocol APIs
|
|
21
|
+
|
|
22
|
+
- `PersistedMutationEnvelope`
|
|
23
|
+
- `ProtocolEnvelope<TPayload>`
|
|
24
|
+
- `LeaderHeartbeat`
|
|
25
|
+
- `TxCommitted`
|
|
26
|
+
- `EnsureRemoteSubsetRequest`
|
|
27
|
+
- `EnsureRemoteSubsetResponse`
|
|
28
|
+
- `ApplyLocalMutationsRequest`
|
|
29
|
+
- `ApplyLocalMutationsResponse`
|
|
30
|
+
- `PullSinceRequest`
|
|
31
|
+
- `PullSinceResponse`
|
|
32
|
+
- `CollectionReset`
|
|
33
|
+
- `PersistedIndexSpec`
|
|
34
|
+
- `PersistedTx<T, TKey>`
|
|
35
|
+
- `PersistenceAdapter<T, TKey>`
|
|
36
|
+
- `SQLiteDriver`
|
|
37
|
+
- `PersistedCollectionCoordinator`
|
|
38
|
+
- `PersistedCollectionPersistence<T, TKey>`
|
|
39
|
+
- `PersistedCollectionMode`
|
|
40
|
+
- `PersistedCollectionLeadershipState`
|
|
41
|
+
- `PersistedCollectionUtils`
|
|
42
|
+
- `PersistedSyncWrappedOptions<T, TKey, TSchema, TUtils>`
|
|
43
|
+
- `PersistedLocalOnlyOptions<T, TKey, TSchema, TUtils>`
|
|
44
|
+
- `SingleProcessCoordinator`
|
|
45
|
+
- `validatePersistedCollectionCoordinator(...)`
|
|
46
|
+
- `persistedCollectionOptions(...)`
|
|
47
|
+
- `encodePersistedStorageKey(...)`
|
|
48
|
+
- `decodePersistedStorageKey(...)`
|
|
49
|
+
- `createPersistedTableName(...)`
|
|
50
|
+
|
|
51
|
+
`PersistedCollectionPersistence` can optionally implement:
|
|
52
|
+
|
|
53
|
+
- `resolvePersistenceForMode(mode)` (legacy mode-aware resolution)
|
|
54
|
+
- `resolvePersistenceForCollection({ collectionId, mode, schemaVersion })`
|
|
55
|
+
(collection-aware resolution)
|
|
56
|
+
|
|
57
|
+
`persistedCollectionOptions(...)` now supports `schemaVersion` per collection
|
|
58
|
+
and resolves persistence using:
|
|
59
|
+
|
|
60
|
+
- collection id
|
|
61
|
+
- inferred mode (`sync-present` or `sync-absent`)
|
|
62
|
+
- optional `schemaVersion`
|
|
63
|
+
|
|
64
|
+
This lets runtime wrappers expose one shared persistence instance per database
|
|
65
|
+
while still handling per-collection schema versions correctly.
|
|
66
|
+
|
|
67
|
+
### SQLite core adapter APIs
|
|
68
|
+
|
|
69
|
+
- `SQLiteCoreAdapterOptions`
|
|
70
|
+
- `SQLitePullSinceResult<TKey>`
|
|
71
|
+
- `SQLiteCorePersistenceAdapter<T, TKey>`
|
|
72
|
+
- `createSQLiteCorePersistenceAdapter<T, TKey>(...)`
|
|
73
|
+
|
|
74
|
+
### Error APIs
|
|
75
|
+
|
|
76
|
+
- `PersistedCollectionCoreError`
|
|
77
|
+
- `InvalidPersistedCollectionConfigError`
|
|
78
|
+
- `InvalidSyncConfigError`
|
|
79
|
+
- `InvalidPersistedCollectionCoordinatorError`
|
|
80
|
+
- `InvalidPersistenceAdapterError`
|
|
81
|
+
- `InvalidPersistedStorageKeyError`
|
|
82
|
+
- `InvalidPersistedStorageKeyEncodingError`
|
|
83
|
+
- `PersistenceUnavailableError`
|
|
84
|
+
|
|
85
|
+
## Typical usage (via runtime wrappers)
|
|
86
|
+
|
|
87
|
+
In most applications, use a runtime package directly:
|
|
88
|
+
|
|
89
|
+
- `@tanstack/node-db-sqlite-persistence`
|
|
90
|
+
- `@tanstack/browser-db-sqlite-persistence`
|
|
91
|
+
- `@tanstack/electron-db-sqlite-persistence`
|
|
92
|
+
- `@tanstack/react-native-db-sqlite-persistence`
|
|
93
|
+
- `@tanstack/cloudflare-durable-objects-db-sqlite-persistence`
|
|
94
|
+
|
|
95
|
+
Those packages provide concrete drivers and runtime wiring.
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const db = require("@tanstack/db");
|
|
4
|
+
class PersistedCollectionCoreError extends db.TanStackDBError {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = `PersistedCollectionCoreError`;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
class InvalidPersistedCollectionConfigError extends PersistedCollectionCoreError {
|
|
11
|
+
constructor(message) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = `InvalidPersistedCollectionConfigError`;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
class InvalidSyncConfigError extends InvalidPersistedCollectionConfigError {
|
|
17
|
+
constructor(details) {
|
|
18
|
+
super(
|
|
19
|
+
details ? `Invalid sync config: ${details}` : `Invalid sync config: expected an object with a callable sync function`
|
|
20
|
+
);
|
|
21
|
+
this.name = `InvalidSyncConfigError`;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
class InvalidPersistedCollectionCoordinatorError extends InvalidPersistedCollectionConfigError {
|
|
25
|
+
constructor(methodName) {
|
|
26
|
+
super(
|
|
27
|
+
`Invalid persisted collection coordinator: missing required "${methodName}" method`
|
|
28
|
+
);
|
|
29
|
+
this.name = `InvalidPersistedCollectionCoordinatorError`;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
class InvalidPersistenceAdapterError extends InvalidPersistedCollectionConfigError {
|
|
33
|
+
constructor(methodName) {
|
|
34
|
+
super(
|
|
35
|
+
`Invalid persistence adapter: missing required "${methodName}" method`
|
|
36
|
+
);
|
|
37
|
+
this.name = `InvalidPersistenceAdapterError`;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
class InvalidPersistedStorageKeyError extends InvalidPersistedCollectionConfigError {
|
|
41
|
+
constructor(key) {
|
|
42
|
+
super(
|
|
43
|
+
`Invalid persisted storage key "${String(key)}": numeric keys must be finite`
|
|
44
|
+
);
|
|
45
|
+
this.name = `InvalidPersistedStorageKeyError`;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
class InvalidPersistedStorageKeyEncodingError extends InvalidPersistedCollectionConfigError {
|
|
49
|
+
constructor(encoded) {
|
|
50
|
+
super(
|
|
51
|
+
`Invalid persisted storage key encoding "${encoded}": expected prefix "n:" or "s:"`
|
|
52
|
+
);
|
|
53
|
+
this.name = `InvalidPersistedStorageKeyEncodingError`;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
class PersistenceUnavailableError extends PersistedCollectionCoreError {
|
|
57
|
+
constructor(details) {
|
|
58
|
+
super(
|
|
59
|
+
details ? `Persistence unavailable: ${details}` : `Persistence unavailable in this runtime`
|
|
60
|
+
);
|
|
61
|
+
this.name = `PersistenceUnavailableError`;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.InvalidPersistedCollectionConfigError = InvalidPersistedCollectionConfigError;
|
|
65
|
+
exports.InvalidPersistedCollectionCoordinatorError = InvalidPersistedCollectionCoordinatorError;
|
|
66
|
+
exports.InvalidPersistedStorageKeyEncodingError = InvalidPersistedStorageKeyEncodingError;
|
|
67
|
+
exports.InvalidPersistedStorageKeyError = InvalidPersistedStorageKeyError;
|
|
68
|
+
exports.InvalidPersistenceAdapterError = InvalidPersistenceAdapterError;
|
|
69
|
+
exports.InvalidSyncConfigError = InvalidSyncConfigError;
|
|
70
|
+
exports.PersistedCollectionCoreError = PersistedCollectionCoreError;
|
|
71
|
+
exports.PersistenceUnavailableError = PersistenceUnavailableError;
|
|
72
|
+
//# sourceMappingURL=errors.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.cjs","sources":["../../src/errors.ts"],"sourcesContent":["import { TanStackDBError } from '@tanstack/db'\n\nexport class PersistedCollectionCoreError extends TanStackDBError {\n constructor(message: string) {\n super(message)\n this.name = `PersistedCollectionCoreError`\n }\n}\n\nexport class InvalidPersistedCollectionConfigError extends PersistedCollectionCoreError {\n constructor(message: string) {\n super(message)\n this.name = `InvalidPersistedCollectionConfigError`\n }\n}\n\nexport class InvalidSyncConfigError extends InvalidPersistedCollectionConfigError {\n constructor(details?: string) {\n super(\n details\n ? `Invalid sync config: ${details}`\n : `Invalid sync config: expected an object with a callable sync function`,\n )\n this.name = `InvalidSyncConfigError`\n }\n}\n\nexport class InvalidPersistedCollectionCoordinatorError extends InvalidPersistedCollectionConfigError {\n constructor(methodName: string) {\n super(\n `Invalid persisted collection coordinator: missing required \"${methodName}\" method`,\n )\n this.name = `InvalidPersistedCollectionCoordinatorError`\n }\n}\n\nexport class InvalidPersistenceAdapterError extends InvalidPersistedCollectionConfigError {\n constructor(methodName: string) {\n super(\n `Invalid persistence adapter: missing required \"${methodName}\" method`,\n )\n this.name = `InvalidPersistenceAdapterError`\n }\n}\n\nexport class InvalidPersistedStorageKeyError extends InvalidPersistedCollectionConfigError {\n constructor(key: string | number) {\n super(\n `Invalid persisted storage key \"${String(key)}\": numeric keys must be finite`,\n )\n this.name = `InvalidPersistedStorageKeyError`\n }\n}\n\nexport class InvalidPersistedStorageKeyEncodingError extends InvalidPersistedCollectionConfigError {\n constructor(encoded: string) {\n super(\n `Invalid persisted storage key encoding \"${encoded}\": expected prefix \"n:\" or \"s:\"`,\n )\n this.name = `InvalidPersistedStorageKeyEncodingError`\n }\n}\n\nexport class PersistenceUnavailableError extends PersistedCollectionCoreError {\n constructor(details?: string) {\n super(\n details\n ? `Persistence unavailable: ${details}`\n : `Persistence unavailable in this runtime`,\n )\n this.name = `PersistenceUnavailableError`\n }\n}\n"],"names":["TanStackDBError"],"mappings":";;;AAEO,MAAM,qCAAqCA,GAAAA,gBAAgB;AAAA,EAChE,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAEO,MAAM,8CAA8C,6BAA6B;AAAA,EACtF,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAEO,MAAM,+BAA+B,sCAAsC;AAAA,EAChF,YAAY,SAAkB;AAC5B;AAAA,MACE,UACI,wBAAwB,OAAO,KAC/B;AAAA,IAAA;AAEN,SAAK,OAAO;AAAA,EACd;AACF;AAEO,MAAM,mDAAmD,sCAAsC;AAAA,EACpG,YAAY,YAAoB;AAC9B;AAAA,MACE,+DAA+D,UAAU;AAAA,IAAA;AAE3E,SAAK,OAAO;AAAA,EACd;AACF;AAEO,MAAM,uCAAuC,sCAAsC;AAAA,EACxF,YAAY,YAAoB;AAC9B;AAAA,MACE,kDAAkD,UAAU;AAAA,IAAA;AAE9D,SAAK,OAAO;AAAA,EACd;AACF;AAEO,MAAM,wCAAwC,sCAAsC;AAAA,EACzF,YAAY,KAAsB;AAChC;AAAA,MACE,kCAAkC,OAAO,GAAG,CAAC;AAAA,IAAA;AAE/C,SAAK,OAAO;AAAA,EACd;AACF;AAEO,MAAM,gDAAgD,sCAAsC;AAAA,EACjG,YAAY,SAAiB;AAC3B;AAAA,MACE,2CAA2C,OAAO;AAAA,IAAA;AAEpD,SAAK,OAAO;AAAA,EACd;AACF;AAEO,MAAM,oCAAoC,6BAA6B;AAAA,EAC5E,YAAY,SAAkB;AAC5B;AAAA,MACE,UACI,4BAA4B,OAAO,KACnC;AAAA,IAAA;AAEN,SAAK,OAAO;AAAA,EACd;AACF;;;;;;;;;"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { TanStackDBError } from '@tanstack/db';
|
|
2
|
+
export declare class PersistedCollectionCoreError extends TanStackDBError {
|
|
3
|
+
constructor(message: string);
|
|
4
|
+
}
|
|
5
|
+
export declare class InvalidPersistedCollectionConfigError extends PersistedCollectionCoreError {
|
|
6
|
+
constructor(message: string);
|
|
7
|
+
}
|
|
8
|
+
export declare class InvalidSyncConfigError extends InvalidPersistedCollectionConfigError {
|
|
9
|
+
constructor(details?: string);
|
|
10
|
+
}
|
|
11
|
+
export declare class InvalidPersistedCollectionCoordinatorError extends InvalidPersistedCollectionConfigError {
|
|
12
|
+
constructor(methodName: string);
|
|
13
|
+
}
|
|
14
|
+
export declare class InvalidPersistenceAdapterError extends InvalidPersistedCollectionConfigError {
|
|
15
|
+
constructor(methodName: string);
|
|
16
|
+
}
|
|
17
|
+
export declare class InvalidPersistedStorageKeyError extends InvalidPersistedCollectionConfigError {
|
|
18
|
+
constructor(key: string | number);
|
|
19
|
+
}
|
|
20
|
+
export declare class InvalidPersistedStorageKeyEncodingError extends InvalidPersistedCollectionConfigError {
|
|
21
|
+
constructor(encoded: string);
|
|
22
|
+
}
|
|
23
|
+
export declare class PersistenceUnavailableError extends PersistedCollectionCoreError {
|
|
24
|
+
constructor(details?: string);
|
|
25
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const persisted = require("./persisted.cjs");
|
|
4
|
+
const errors = require("./errors.cjs");
|
|
5
|
+
const sqliteCoreAdapter = require("./sqlite-core-adapter.cjs");
|
|
6
|
+
exports.SingleProcessCoordinator = persisted.SingleProcessCoordinator;
|
|
7
|
+
exports.createPersistedTableName = persisted.createPersistedTableName;
|
|
8
|
+
exports.decodePersistedStorageKey = persisted.decodePersistedStorageKey;
|
|
9
|
+
exports.encodePersistedStorageKey = persisted.encodePersistedStorageKey;
|
|
10
|
+
exports.persistedCollectionOptions = persisted.persistedCollectionOptions;
|
|
11
|
+
exports.validatePersistedCollectionCoordinator = persisted.validatePersistedCollectionCoordinator;
|
|
12
|
+
exports.InvalidPersistedCollectionConfigError = errors.InvalidPersistedCollectionConfigError;
|
|
13
|
+
exports.InvalidPersistedCollectionCoordinatorError = errors.InvalidPersistedCollectionCoordinatorError;
|
|
14
|
+
exports.InvalidPersistedStorageKeyEncodingError = errors.InvalidPersistedStorageKeyEncodingError;
|
|
15
|
+
exports.InvalidPersistedStorageKeyError = errors.InvalidPersistedStorageKeyError;
|
|
16
|
+
exports.InvalidPersistenceAdapterError = errors.InvalidPersistenceAdapterError;
|
|
17
|
+
exports.InvalidSyncConfigError = errors.InvalidSyncConfigError;
|
|
18
|
+
exports.PersistedCollectionCoreError = errors.PersistedCollectionCoreError;
|
|
19
|
+
exports.PersistenceUnavailableError = errors.PersistenceUnavailableError;
|
|
20
|
+
exports.SQLiteCorePersistenceAdapter = sqliteCoreAdapter.SQLiteCorePersistenceAdapter;
|
|
21
|
+
exports.createSQLiteCorePersistenceAdapter = sqliteCoreAdapter.createSQLiteCorePersistenceAdapter;
|
|
22
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;"}
|