@tanstack/tauri-db-sqlite-persistence 0.1.6 → 0.1.7
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/dist/cjs/tauri-persistence.cjs +1 -4
- package/dist/cjs/tauri-persistence.cjs.map +1 -1
- package/dist/cjs/tauri-persistence.d.cts +1 -1
- package/dist/cjs/tauri.cjs.map +1 -1
- package/dist/cjs/tauri.d.cts +1 -1
- package/dist/esm/tauri-persistence.d.ts +1 -1
- package/dist/esm/tauri-persistence.js +1 -4
- package/dist/esm/tauri-persistence.js.map +1 -1
- package/dist/esm/tauri.d.ts +1 -1
- package/dist/esm/tauri.js.map +1 -1
- package/package.json +2 -2
- package/src/tauri-persistence.ts +6 -20
- package/src/tauri.ts +3 -6
|
@@ -66,10 +66,7 @@ function createTauriSQLitePersistence(options) {
|
|
|
66
66
|
return adapter;
|
|
67
67
|
};
|
|
68
68
|
const createCollectionPersistence = (mode, schemaVersion) => ({
|
|
69
|
-
adapter: getAdapterForCollection(
|
|
70
|
-
mode,
|
|
71
|
-
schemaVersion
|
|
72
|
-
),
|
|
69
|
+
adapter: getAdapterForCollection(mode, schemaVersion),
|
|
73
70
|
coordinator: resolvedCoordinator
|
|
74
71
|
});
|
|
75
72
|
const defaultPersistence = createCollectionPersistence(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tauri-persistence.cjs","sources":["../../src/tauri-persistence.ts"],"sourcesContent":["import {\n SingleProcessCoordinator,\n createSQLiteCorePersistenceAdapter,\n} from '@tanstack/db-sqlite-persistence-core'\nimport { TauriSQLiteDriver } from './tauri-sql-driver'\nimport type {\n PersistedCollectionCoordinator,\n PersistedCollectionMode,\n PersistedCollectionPersistence,\n SQLiteCoreAdapterOptions,\n SQLiteDriver,\n} from '@tanstack/db-sqlite-persistence-core'\nimport type { TauriSQLiteDatabaseLike } from './tauri-sql-driver'\n\nexport type { TauriSQLiteDatabaseLike } from './tauri-sql-driver'\n\ntype TauriSQLiteCoreSchemaMismatchPolicy =\n | `sync-present-reset`\n | `sync-absent-error`\n | `reset`\n\nexport type TauriSQLiteSchemaMismatchPolicy =\n | TauriSQLiteCoreSchemaMismatchPolicy\n | `throw`\n\ntype TauriSQLitePersistenceBaseOptions = Omit<\n SQLiteCoreAdapterOptions,\n `driver` | `schemaVersion` | `schemaMismatchPolicy`\n> & {\n database: TauriSQLiteDatabaseLike\n coordinator?: PersistedCollectionCoordinator\n schemaMismatchPolicy?: TauriSQLiteSchemaMismatchPolicy\n}\n\nexport type TauriSQLitePersistenceOptions = TauriSQLitePersistenceBaseOptions\n\nconst tauriDriverCache = new WeakMap<\n TauriSQLiteDatabaseLike,\n TauriSQLiteDriver\n>()\n\nfunction normalizeSchemaMismatchPolicy(\n policy: TauriSQLiteSchemaMismatchPolicy,\n): TauriSQLiteCoreSchemaMismatchPolicy {\n if (policy === `throw`) {\n return `sync-absent-error`\n }\n\n return policy\n}\n\nfunction resolveSchemaMismatchPolicy(\n explicitPolicy: TauriSQLiteSchemaMismatchPolicy | undefined,\n mode: PersistedCollectionMode,\n): TauriSQLiteCoreSchemaMismatchPolicy {\n if (explicitPolicy) {\n return normalizeSchemaMismatchPolicy(explicitPolicy)\n }\n\n return mode === `sync-present` ? `sync-present-reset` : `sync-absent-error`\n}\n\nfunction createAdapterCacheKey(\n schemaMismatchPolicy: TauriSQLiteCoreSchemaMismatchPolicy,\n schemaVersion: number | undefined,\n): string {\n const schemaVersionKey =\n schemaVersion === undefined ? `schema:default` : `schema:${schemaVersion}`\n return `${schemaMismatchPolicy}|${schemaVersionKey}`\n}\n\nfunction createInternalSQLiteDriver(\n options: TauriSQLitePersistenceOptions,\n): SQLiteDriver {\n const cachedDriver = tauriDriverCache.get(options.database)\n if (cachedDriver) {\n return cachedDriver\n }\n\n const driver = new TauriSQLiteDriver({\n database: options.database,\n })\n tauriDriverCache.set(options.database, driver)\n return driver\n}\n\nfunction resolveAdapterBaseOptions(\n options: TauriSQLitePersistenceOptions,\n): Omit<\n SQLiteCoreAdapterOptions,\n `driver` | `schemaVersion` | `schemaMismatchPolicy`\n> {\n return {\n appliedTxPruneMaxRows: options.appliedTxPruneMaxRows,\n appliedTxPruneMaxAgeSeconds: options.appliedTxPruneMaxAgeSeconds,\n pullSinceReloadThreshold: options.pullSinceReloadThreshold,\n }\n}\n\nexport function createTauriSQLitePersistence
|
|
1
|
+
{"version":3,"file":"tauri-persistence.cjs","sources":["../../src/tauri-persistence.ts"],"sourcesContent":["import {\n SingleProcessCoordinator,\n createSQLiteCorePersistenceAdapter,\n} from '@tanstack/db-sqlite-persistence-core'\nimport { TauriSQLiteDriver } from './tauri-sql-driver'\nimport type {\n PersistedCollectionCoordinator,\n PersistedCollectionMode,\n PersistedCollectionPersistence,\n SQLiteCoreAdapterOptions,\n SQLiteDriver,\n} from '@tanstack/db-sqlite-persistence-core'\nimport type { TauriSQLiteDatabaseLike } from './tauri-sql-driver'\n\nexport type { TauriSQLiteDatabaseLike } from './tauri-sql-driver'\n\ntype TauriSQLiteCoreSchemaMismatchPolicy =\n | `sync-present-reset`\n | `sync-absent-error`\n | `reset`\n\nexport type TauriSQLiteSchemaMismatchPolicy =\n | TauriSQLiteCoreSchemaMismatchPolicy\n | `throw`\n\ntype TauriSQLitePersistenceBaseOptions = Omit<\n SQLiteCoreAdapterOptions,\n `driver` | `schemaVersion` | `schemaMismatchPolicy`\n> & {\n database: TauriSQLiteDatabaseLike\n coordinator?: PersistedCollectionCoordinator\n schemaMismatchPolicy?: TauriSQLiteSchemaMismatchPolicy\n}\n\nexport type TauriSQLitePersistenceOptions = TauriSQLitePersistenceBaseOptions\n\nconst tauriDriverCache = new WeakMap<\n TauriSQLiteDatabaseLike,\n TauriSQLiteDriver\n>()\n\nfunction normalizeSchemaMismatchPolicy(\n policy: TauriSQLiteSchemaMismatchPolicy,\n): TauriSQLiteCoreSchemaMismatchPolicy {\n if (policy === `throw`) {\n return `sync-absent-error`\n }\n\n return policy\n}\n\nfunction resolveSchemaMismatchPolicy(\n explicitPolicy: TauriSQLiteSchemaMismatchPolicy | undefined,\n mode: PersistedCollectionMode,\n): TauriSQLiteCoreSchemaMismatchPolicy {\n if (explicitPolicy) {\n return normalizeSchemaMismatchPolicy(explicitPolicy)\n }\n\n return mode === `sync-present` ? `sync-present-reset` : `sync-absent-error`\n}\n\nfunction createAdapterCacheKey(\n schemaMismatchPolicy: TauriSQLiteCoreSchemaMismatchPolicy,\n schemaVersion: number | undefined,\n): string {\n const schemaVersionKey =\n schemaVersion === undefined ? `schema:default` : `schema:${schemaVersion}`\n return `${schemaMismatchPolicy}|${schemaVersionKey}`\n}\n\nfunction createInternalSQLiteDriver(\n options: TauriSQLitePersistenceOptions,\n): SQLiteDriver {\n const cachedDriver = tauriDriverCache.get(options.database)\n if (cachedDriver) {\n return cachedDriver\n }\n\n const driver = new TauriSQLiteDriver({\n database: options.database,\n })\n tauriDriverCache.set(options.database, driver)\n return driver\n}\n\nfunction resolveAdapterBaseOptions(\n options: TauriSQLitePersistenceOptions,\n): Omit<\n SQLiteCoreAdapterOptions,\n `driver` | `schemaVersion` | `schemaMismatchPolicy`\n> {\n return {\n appliedTxPruneMaxRows: options.appliedTxPruneMaxRows,\n appliedTxPruneMaxAgeSeconds: options.appliedTxPruneMaxAgeSeconds,\n pullSinceReloadThreshold: options.pullSinceReloadThreshold,\n }\n}\n\nexport function createTauriSQLitePersistence(\n options: TauriSQLitePersistenceOptions,\n): PersistedCollectionPersistence {\n const { coordinator, schemaMismatchPolicy } = options\n const driver = createInternalSQLiteDriver(options)\n const adapterBaseOptions = resolveAdapterBaseOptions(options)\n const resolvedCoordinator = coordinator ?? new SingleProcessCoordinator()\n const adapterCache = new Map<\n string,\n ReturnType<typeof createSQLiteCorePersistenceAdapter>\n >()\n\n const getAdapterForCollection = (\n mode: PersistedCollectionMode,\n schemaVersion: number | undefined,\n ) => {\n const resolvedSchemaMismatchPolicy = resolveSchemaMismatchPolicy(\n schemaMismatchPolicy,\n mode,\n )\n const cacheKey = createAdapterCacheKey(\n resolvedSchemaMismatchPolicy,\n schemaVersion,\n )\n const cachedAdapter = adapterCache.get(cacheKey)\n if (cachedAdapter) {\n return cachedAdapter\n }\n\n const adapter = createSQLiteCorePersistenceAdapter({\n ...adapterBaseOptions,\n driver,\n schemaMismatchPolicy: resolvedSchemaMismatchPolicy,\n ...(schemaVersion === undefined ? {} : { schemaVersion }),\n })\n adapterCache.set(cacheKey, adapter)\n return adapter\n }\n\n const createCollectionPersistence = (\n mode: PersistedCollectionMode,\n schemaVersion: number | undefined,\n ): PersistedCollectionPersistence => ({\n adapter: getAdapterForCollection(mode, schemaVersion),\n coordinator: resolvedCoordinator,\n })\n\n const defaultPersistence = createCollectionPersistence(\n `sync-absent`,\n undefined,\n )\n\n return {\n ...defaultPersistence,\n resolvePersistenceForCollection: ({ mode, schemaVersion }) =>\n createCollectionPersistence(mode, schemaVersion),\n resolvePersistenceForMode: (mode) =>\n createCollectionPersistence(mode, undefined),\n }\n}\n"],"names":["TauriSQLiteDriver","SingleProcessCoordinator","createSQLiteCorePersistenceAdapter"],"mappings":";;;;AAoCA,MAAM,uCAAuB,QAAA;AAK7B,SAAS,8BACP,QACqC;AACrC,MAAI,WAAW,SAAS;AACtB,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEA,SAAS,4BACP,gBACA,MACqC;AACrC,MAAI,gBAAgB;AAClB,WAAO,8BAA8B,cAAc;AAAA,EACrD;AAEA,SAAO,SAAS,iBAAiB,uBAAuB;AAC1D;AAEA,SAAS,sBACP,sBACA,eACQ;AACR,QAAM,mBACJ,kBAAkB,SAAY,mBAAmB,UAAU,aAAa;AAC1E,SAAO,GAAG,oBAAoB,IAAI,gBAAgB;AACpD;AAEA,SAAS,2BACP,SACc;AACd,QAAM,eAAe,iBAAiB,IAAI,QAAQ,QAAQ;AAC1D,MAAI,cAAc;AAChB,WAAO;AAAA,EACT;AAEA,QAAM,SAAS,IAAIA,iCAAkB;AAAA,IACnC,UAAU,QA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aseOptions = Omit<SQLiteCoreAdapterOptions, `driver`
|
|
|
9
9
|
schemaMismatchPolicy?: TauriSQLiteSchemaMismatchPolicy;
|
|
10
10
|
};
|
|
11
11
|
export type TauriSQLitePersistenceOptions = TauriSQLitePersistenceBaseOptions;
|
|
12
|
-
export declare function createTauriSQLitePersistence
|
|
12
|
+
export declare function createTauriSQLitePersistence(options: TauriSQLitePersistenceOptions): PersistedCollectionPersistence;
|
package/dist/cjs/tauri.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tauri.cjs","sources":["../../src/tauri.ts"],"sourcesContent":["import { createTauriSQLitePersistence as createPersistence } from './tauri-persistence'\nimport type {\n TauriSQLitePersistenceOptions as TauriSQLitePersistenceOptionsBase,\n TauriSQLiteSchemaMismatchPolicy as TauriSQLiteSchemaMismatchPolicyBase,\n} from './tauri-persistence'\nimport type { PersistedCollectionPersistence } from '@tanstack/db-sqlite-persistence-core'\n\nexport type TauriSQLitePersistenceOptions = TauriSQLitePersistenceOptionsBase\nexport type TauriSQLiteSchemaMismatchPolicy =\n TauriSQLiteSchemaMismatchPolicyBase\nexport type { TauriSQLiteDatabaseLike } from './tauri-persistence'\n\nexport function createTauriSQLitePersistence
|
|
1
|
+
{"version":3,"file":"tauri.cjs","sources":["../../src/tauri.ts"],"sourcesContent":["import { createTauriSQLitePersistence as createPersistence } from './tauri-persistence'\nimport type {\n TauriSQLitePersistenceOptions as TauriSQLitePersistenceOptionsBase,\n TauriSQLiteSchemaMismatchPolicy as TauriSQLiteSchemaMismatchPolicyBase,\n} from './tauri-persistence'\nimport type { PersistedCollectionPersistence } from '@tanstack/db-sqlite-persistence-core'\n\nexport type TauriSQLitePersistenceOptions = TauriSQLitePersistenceOptionsBase\nexport type TauriSQLiteSchemaMismatchPolicy =\n TauriSQLiteSchemaMismatchPolicyBase\nexport type { TauriSQLiteDatabaseLike } from './tauri-persistence'\n\nexport function createTauriSQLitePersistence(\n options: TauriSQLitePersistenceOptions,\n): PersistedCollectionPersistence {\n return createPersistence(options)\n}\n"],"names":["createPersistence"],"mappings":";;;AAYO,SAAS,6BACd,SACgC;AAChC,SAAOA,iBAAAA,6BAAkB,OAAO;AAClC;;"}
|
package/dist/cjs/tauri.d.cts
CHANGED
|
@@ -3,4 +3,4 @@ import { PersistedCollectionPersistence } from '@tanstack/db-sqlite-persistence-
|
|
|
3
3
|
export type TauriSQLitePersistenceOptions = TauriSQLitePersistenceOptionsBase;
|
|
4
4
|
export type TauriSQLiteSchemaMismatchPolicy = TauriSQLiteSchemaMismatchPolicyBase;
|
|
5
5
|
export type { TauriSQLiteDatabaseLike } from './tauri-persistence.cjs';
|
|
6
|
-
export declare function createTauriSQLitePersistence
|
|
6
|
+
export declare function createTauriSQLitePersistence(options: TauriSQLitePersistenceOptions): PersistedCollectionPersistence;
|
|
@@ -9,4 +9,4 @@ type TauriSQLitePersistenceBaseOptions = Omit<SQLiteCoreAdapterOptions, `driver`
|
|
|
9
9
|
schemaMismatchPolicy?: TauriSQLiteSchemaMismatchPolicy;
|
|
10
10
|
};
|
|
11
11
|
export type TauriSQLitePersistenceOptions = TauriSQLitePersistenceBaseOptions;
|
|
12
|
-
export declare function createTauriSQLitePersistence
|
|
12
|
+
export declare function createTauriSQLitePersistence(options: TauriSQLitePersistenceOptions): PersistedCollectionPersistence;
|
|
@@ -64,10 +64,7 @@ function createTauriSQLitePersistence(options) {
|
|
|
64
64
|
return adapter;
|
|
65
65
|
};
|
|
66
66
|
const createCollectionPersistence = (mode, schemaVersion) => ({
|
|
67
|
-
adapter: getAdapterForCollection(
|
|
68
|
-
mode,
|
|
69
|
-
schemaVersion
|
|
70
|
-
),
|
|
67
|
+
adapter: getAdapterForCollection(mode, schemaVersion),
|
|
71
68
|
coordinator: resolvedCoordinator
|
|
72
69
|
});
|
|
73
70
|
const defaultPersistence = createCollectionPersistence(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tauri-persistence.js","sources":["../../src/tauri-persistence.ts"],"sourcesContent":["import {\n SingleProcessCoordinator,\n createSQLiteCorePersistenceAdapter,\n} from '@tanstack/db-sqlite-persistence-core'\nimport { TauriSQLiteDriver } from './tauri-sql-driver'\nimport type {\n PersistedCollectionCoordinator,\n PersistedCollectionMode,\n PersistedCollectionPersistence,\n SQLiteCoreAdapterOptions,\n SQLiteDriver,\n} from '@tanstack/db-sqlite-persistence-core'\nimport type { TauriSQLiteDatabaseLike } from './tauri-sql-driver'\n\nexport type { TauriSQLiteDatabaseLike } from './tauri-sql-driver'\n\ntype TauriSQLiteCoreSchemaMismatchPolicy =\n | `sync-present-reset`\n | `sync-absent-error`\n | `reset`\n\nexport type TauriSQLiteSchemaMismatchPolicy =\n | TauriSQLiteCoreSchemaMismatchPolicy\n | `throw`\n\ntype TauriSQLitePersistenceBaseOptions = Omit<\n SQLiteCoreAdapterOptions,\n `driver` | `schemaVersion` | `schemaMismatchPolicy`\n> & {\n database: TauriSQLiteDatabaseLike\n coordinator?: PersistedCollectionCoordinator\n schemaMismatchPolicy?: TauriSQLiteSchemaMismatchPolicy\n}\n\nexport type TauriSQLitePersistenceOptions = TauriSQLitePersistenceBaseOptions\n\nconst tauriDriverCache = new WeakMap<\n TauriSQLiteDatabaseLike,\n TauriSQLiteDriver\n>()\n\nfunction normalizeSchemaMismatchPolicy(\n policy: TauriSQLiteSchemaMismatchPolicy,\n): TauriSQLiteCoreSchemaMismatchPolicy {\n if (policy === `throw`) {\n return `sync-absent-error`\n }\n\n return policy\n}\n\nfunction resolveSchemaMismatchPolicy(\n explicitPolicy: TauriSQLiteSchemaMismatchPolicy | undefined,\n mode: PersistedCollectionMode,\n): TauriSQLiteCoreSchemaMismatchPolicy {\n if (explicitPolicy) {\n return normalizeSchemaMismatchPolicy(explicitPolicy)\n }\n\n return mode === `sync-present` ? `sync-present-reset` : `sync-absent-error`\n}\n\nfunction createAdapterCacheKey(\n schemaMismatchPolicy: TauriSQLiteCoreSchemaMismatchPolicy,\n schemaVersion: number | undefined,\n): string {\n const schemaVersionKey =\n schemaVersion === undefined ? `schema:default` : `schema:${schemaVersion}`\n return `${schemaMismatchPolicy}|${schemaVersionKey}`\n}\n\nfunction createInternalSQLiteDriver(\n options: TauriSQLitePersistenceOptions,\n): SQLiteDriver {\n const cachedDriver = tauriDriverCache.get(options.database)\n if (cachedDriver) {\n return cachedDriver\n }\n\n const driver = new TauriSQLiteDriver({\n database: options.database,\n })\n tauriDriverCache.set(options.database, driver)\n return driver\n}\n\nfunction resolveAdapterBaseOptions(\n options: TauriSQLitePersistenceOptions,\n): Omit<\n SQLiteCoreAdapterOptions,\n `driver` | `schemaVersion` | `schemaMismatchPolicy`\n> {\n return {\n appliedTxPruneMaxRows: options.appliedTxPruneMaxRows,\n appliedTxPruneMaxAgeSeconds: options.appliedTxPruneMaxAgeSeconds,\n pullSinceReloadThreshold: options.pullSinceReloadThreshold,\n }\n}\n\nexport function createTauriSQLitePersistence
|
|
1
|
+
{"version":3,"file":"tauri-persistence.js","sources":["../../src/tauri-persistence.ts"],"sourcesContent":["import {\n SingleProcessCoordinator,\n createSQLiteCorePersistenceAdapter,\n} from '@tanstack/db-sqlite-persistence-core'\nimport { TauriSQLiteDriver } from './tauri-sql-driver'\nimport type {\n PersistedCollectionCoordinator,\n PersistedCollectionMode,\n PersistedCollectionPersistence,\n SQLiteCoreAdapterOptions,\n SQLiteDriver,\n} from '@tanstack/db-sqlite-persistence-core'\nimport type { TauriSQLiteDatabaseLike } from './tauri-sql-driver'\n\nexport type { TauriSQLiteDatabaseLike } from './tauri-sql-driver'\n\ntype TauriSQLiteCoreSchemaMismatchPolicy =\n | `sync-present-reset`\n | `sync-absent-error`\n | `reset`\n\nexport type TauriSQLiteSchemaMismatchPolicy =\n | TauriSQLiteCoreSchemaMismatchPolicy\n | `throw`\n\ntype TauriSQLitePersistenceBaseOptions = Omit<\n SQLiteCoreAdapterOptions,\n `driver` | `schemaVersion` | `schemaMismatchPolicy`\n> & {\n database: TauriSQLiteDatabaseLike\n coordinator?: PersistedCollectionCoordinator\n schemaMismatchPolicy?: TauriSQLiteSchemaMismatchPolicy\n}\n\nexport type TauriSQLitePersistenceOptions = TauriSQLitePersistenceBaseOptions\n\nconst tauriDriverCache = new WeakMap<\n TauriSQLiteDatabaseLike,\n TauriSQLiteDriver\n>()\n\nfunction normalizeSchemaMismatchPolicy(\n policy: TauriSQLiteSchemaMismatchPolicy,\n): TauriSQLiteCoreSchemaMismatchPolicy {\n if (policy === `throw`) {\n return `sync-absent-error`\n }\n\n return policy\n}\n\nfunction resolveSchemaMismatchPolicy(\n explicitPolicy: TauriSQLiteSchemaMismatchPolicy | undefined,\n mode: PersistedCollectionMode,\n): TauriSQLiteCoreSchemaMismatchPolicy {\n if (explicitPolicy) {\n return normalizeSchemaMismatchPolicy(explicitPolicy)\n }\n\n return mode === `sync-present` ? `sync-present-reset` : `sync-absent-error`\n}\n\nfunction createAdapterCacheKey(\n schemaMismatchPolicy: TauriSQLiteCoreSchemaMismatchPolicy,\n schemaVersion: number | undefined,\n): string {\n const schemaVersionKey =\n schemaVersion === undefined ? `schema:default` : `schema:${schemaVersion}`\n return `${schemaMismatchPolicy}|${schemaVersionKey}`\n}\n\nfunction createInternalSQLiteDriver(\n options: TauriSQLitePersistenceOptions,\n): SQLiteDriver {\n const cachedDriver = tauriDriverCache.get(options.database)\n if (cachedDriver) {\n return cachedDriver\n }\n\n const driver = new TauriSQLiteDriver({\n database: options.database,\n })\n tauriDriverCache.set(options.database, driver)\n return driver\n}\n\nfunction resolveAdapterBaseOptions(\n options: TauriSQLitePersistenceOptions,\n): Omit<\n SQLiteCoreAdapterOptions,\n `driver` | `schemaVersion` | `schemaMismatchPolicy`\n> {\n return {\n appliedTxPruneMaxRows: options.appliedTxPruneMaxRows,\n appliedTxPruneMaxAgeSeconds: options.appliedTxPruneMaxAgeSeconds,\n pullSinceReloadThreshold: options.pullSinceReloadThreshold,\n }\n}\n\nexport function createTauriSQLitePersistence(\n options: TauriSQLitePersistenceOptions,\n): PersistedCollectionPersistence {\n const { coordinator, schemaMismatchPolicy } = options\n const driver = createInternalSQLiteDriver(options)\n const adapterBaseOptions = resolveAdapterBaseOptions(options)\n const resolvedCoordinator = coordinator ?? new SingleProcessCoordinator()\n const adapterCache = new Map<\n string,\n ReturnType<typeof createSQLiteCorePersistenceAdapter>\n >()\n\n const getAdapterForCollection = (\n mode: PersistedCollectionMode,\n schemaVersion: number | undefined,\n ) => {\n const resolvedSchemaMismatchPolicy = resolveSchemaMismatchPolicy(\n schemaMismatchPolicy,\n mode,\n )\n const cacheKey = createAdapterCacheKey(\n resolvedSchemaMismatchPolicy,\n schemaVersion,\n )\n const cachedAdapter = adapterCache.get(cacheKey)\n if (cachedAdapter) {\n return cachedAdapter\n }\n\n const adapter = createSQLiteCorePersistenceAdapter({\n ...adapterBaseOptions,\n driver,\n schemaMismatchPolicy: resolvedSchemaMismatchPolicy,\n ...(schemaVersion === undefined ? {} : { schemaVersion }),\n })\n adapterCache.set(cacheKey, adapter)\n return adapter\n }\n\n const createCollectionPersistence = (\n mode: PersistedCollectionMode,\n schemaVersion: number | undefined,\n ): PersistedCollectionPersistence => ({\n adapter: getAdapterForCollection(mode, schemaVersion),\n coordinator: resolvedCoordinator,\n })\n\n const defaultPersistence = createCollectionPersistence(\n `sync-absent`,\n undefined,\n )\n\n return {\n ...defaultPersistence,\n resolvePersistenceForCollection: ({ mode, schemaVersion }) =>\n createCollectionPersistence(mode, schemaVersion),\n resolvePersistenceForMode: (mode) =>\n createCollectionPersistence(mode, undefined),\n }\n}\n"],"names":[],"mappings":";;AAoCA,MAAM,uCAAuB,QAAA;AAK7B,SAAS,8BACP,QACqC;AACrC,MAAI,WAAW,SAAS;AACtB,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEA,SAAS,4BACP,gBACA,MACqC;AACrC,MAAI,gBAAgB;AAClB,WAAO,8BAA8B,cAAc;AAAA,EACrD;AAEA,SAAO,SAAS,iBAAiB,uBAAuB;AAC1D;AAEA,SAAS,sBACP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AGf,QAAM,qBAAqB;AAAA,IACzB;AAAA,IACA;AAAA,EAAA;AAGF,SAAO;AAAA,IACL,GAAG;AAAA,IACH,iCAAiC,CAAC,EAAE,MAAM,oBACxC,4BAA4B,MAAM,aAAa;AAAA,IACjD,2BAA2B,CAAC,SAC1B,4BAA4B,MAAM,MAAS;AAAA,EAAA;AAEjD;"}
|
package/dist/esm/tauri.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ import { PersistedCollectionPersistence } from '@tanstack/db-sqlite-persistence-
|
|
|
3
3
|
export type TauriSQLitePersistenceOptions = TauriSQLitePersistenceOptionsBase;
|
|
4
4
|
export type TauriSQLiteSchemaMismatchPolicy = TauriSQLiteSchemaMismatchPolicyBase;
|
|
5
5
|
export type { TauriSQLiteDatabaseLike } from './tauri-persistence.js';
|
|
6
|
-
export declare function createTauriSQLitePersistence
|
|
6
|
+
export declare function createTauriSQLitePersistence(options: TauriSQLitePersistenceOptions): PersistedCollectionPersistence;
|
package/dist/esm/tauri.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tauri.js","sources":["../../src/tauri.ts"],"sourcesContent":["import { createTauriSQLitePersistence as createPersistence } from './tauri-persistence'\nimport type {\n TauriSQLitePersistenceOptions as TauriSQLitePersistenceOptionsBase,\n TauriSQLiteSchemaMismatchPolicy as TauriSQLiteSchemaMismatchPolicyBase,\n} from './tauri-persistence'\nimport type { PersistedCollectionPersistence } from '@tanstack/db-sqlite-persistence-core'\n\nexport type TauriSQLitePersistenceOptions = TauriSQLitePersistenceOptionsBase\nexport type TauriSQLiteSchemaMismatchPolicy =\n TauriSQLiteSchemaMismatchPolicyBase\nexport type { TauriSQLiteDatabaseLike } from './tauri-persistence'\n\nexport function createTauriSQLitePersistence
|
|
1
|
+
{"version":3,"file":"tauri.js","sources":["../../src/tauri.ts"],"sourcesContent":["import { createTauriSQLitePersistence as createPersistence } from './tauri-persistence'\nimport type {\n TauriSQLitePersistenceOptions as TauriSQLitePersistenceOptionsBase,\n TauriSQLiteSchemaMismatchPolicy as TauriSQLiteSchemaMismatchPolicyBase,\n} from './tauri-persistence'\nimport type { PersistedCollectionPersistence } from '@tanstack/db-sqlite-persistence-core'\n\nexport type TauriSQLitePersistenceOptions = TauriSQLitePersistenceOptionsBase\nexport type TauriSQLiteSchemaMismatchPolicy =\n TauriSQLiteSchemaMismatchPolicyBase\nexport type { TauriSQLiteDatabaseLike } from './tauri-persistence'\n\nexport function createTauriSQLitePersistence(\n options: TauriSQLitePersistenceOptions,\n): PersistedCollectionPersistence {\n return createPersistence(options)\n}\n"],"names":["createPersistence"],"mappings":";AAYO,SAAS,6BACd,SACgC;AAChC,SAAOA,+BAAkB,OAAO;AAClC;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/tauri-db-sqlite-persistence",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Tauri SQLite persisted collection adapter for TanStack DB",
|
|
5
5
|
"author": "TanStack Team",
|
|
6
6
|
"license": "MIT",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"src"
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@tanstack/db-sqlite-persistence-core": "0.1.
|
|
52
|
+
"@tanstack/db-sqlite-persistence-core": "0.1.7"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"@tauri-apps/plugin-sql": "^2.3.2",
|
package/src/tauri-persistence.ts
CHANGED
|
@@ -97,24 +97,16 @@ function resolveAdapterBaseOptions(
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
export function createTauriSQLitePersistence
|
|
101
|
-
T extends object,
|
|
102
|
-
TKey extends string | number = string | number,
|
|
103
|
-
>(
|
|
100
|
+
export function createTauriSQLitePersistence(
|
|
104
101
|
options: TauriSQLitePersistenceOptions,
|
|
105
|
-
): PersistedCollectionPersistence
|
|
102
|
+
): PersistedCollectionPersistence {
|
|
106
103
|
const { coordinator, schemaMismatchPolicy } = options
|
|
107
104
|
const driver = createInternalSQLiteDriver(options)
|
|
108
105
|
const adapterBaseOptions = resolveAdapterBaseOptions(options)
|
|
109
106
|
const resolvedCoordinator = coordinator ?? new SingleProcessCoordinator()
|
|
110
107
|
const adapterCache = new Map<
|
|
111
108
|
string,
|
|
112
|
-
ReturnType<
|
|
113
|
-
typeof createSQLiteCorePersistenceAdapter<
|
|
114
|
-
Record<string, unknown>,
|
|
115
|
-
string | number
|
|
116
|
-
>
|
|
117
|
-
>
|
|
109
|
+
ReturnType<typeof createSQLiteCorePersistenceAdapter>
|
|
118
110
|
>()
|
|
119
111
|
|
|
120
112
|
const getAdapterForCollection = (
|
|
@@ -134,10 +126,7 @@ export function createTauriSQLitePersistence<
|
|
|
134
126
|
return cachedAdapter
|
|
135
127
|
}
|
|
136
128
|
|
|
137
|
-
const adapter = createSQLiteCorePersistenceAdapter
|
|
138
|
-
Record<string, unknown>,
|
|
139
|
-
string | number
|
|
140
|
-
>({
|
|
129
|
+
const adapter = createSQLiteCorePersistenceAdapter({
|
|
141
130
|
...adapterBaseOptions,
|
|
142
131
|
driver,
|
|
143
132
|
schemaMismatchPolicy: resolvedSchemaMismatchPolicy,
|
|
@@ -150,11 +139,8 @@ export function createTauriSQLitePersistence<
|
|
|
150
139
|
const createCollectionPersistence = (
|
|
151
140
|
mode: PersistedCollectionMode,
|
|
152
141
|
schemaVersion: number | undefined,
|
|
153
|
-
): PersistedCollectionPersistence
|
|
154
|
-
adapter: getAdapterForCollection(
|
|
155
|
-
mode,
|
|
156
|
-
schemaVersion,
|
|
157
|
-
) as unknown as PersistedCollectionPersistence<T, TKey>[`adapter`],
|
|
142
|
+
): PersistedCollectionPersistence => ({
|
|
143
|
+
adapter: getAdapterForCollection(mode, schemaVersion),
|
|
158
144
|
coordinator: resolvedCoordinator,
|
|
159
145
|
})
|
|
160
146
|
|
package/src/tauri.ts
CHANGED
|
@@ -10,11 +10,8 @@ export type TauriSQLiteSchemaMismatchPolicy =
|
|
|
10
10
|
TauriSQLiteSchemaMismatchPolicyBase
|
|
11
11
|
export type { TauriSQLiteDatabaseLike } from './tauri-persistence'
|
|
12
12
|
|
|
13
|
-
export function createTauriSQLitePersistence
|
|
14
|
-
T extends object,
|
|
15
|
-
TKey extends string | number = string | number,
|
|
16
|
-
>(
|
|
13
|
+
export function createTauriSQLitePersistence(
|
|
17
14
|
options: TauriSQLitePersistenceOptions,
|
|
18
|
-
): PersistedCollectionPersistence
|
|
19
|
-
return createPersistence
|
|
15
|
+
): PersistedCollectionPersistence {
|
|
16
|
+
return createPersistence(options)
|
|
20
17
|
}
|