@aiao/rxdb-adapter-sqliteai 0.0.25 → 0.0.28

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/package.json CHANGED
@@ -1,6 +1,19 @@
1
1
  {
2
2
  "name": "@aiao/rxdb-adapter-sqliteai",
3
- "version": "0.0.25",
3
+ "version": "0.0.28",
4
+ "description": "SQLiteAI adapter with vector and AI functions for Aiao RxDB.",
5
+ "homepage": "https://rxdb.aiao.io/docs/adapters/sqliteai",
6
+ "bugs": {
7
+ "url": "https://github.com/aiao-io/rxdb/issues"
8
+ },
9
+ "keywords": [
10
+ "aiao",
11
+ "rxdb",
12
+ "sqliteai",
13
+ "sqlite",
14
+ "vector-search",
15
+ "ai"
16
+ ],
4
17
  "license": "MIT",
5
18
  "repository": {
6
19
  "type": "git",
@@ -8,11 +21,18 @@
8
21
  "directory": "packages/rxdb-adapter-sqliteai"
9
22
  },
10
23
  "type": "module",
24
+ "sideEffects": false,
11
25
  "main": "./dist/index.js",
12
26
  "module": "./dist/index.js",
13
27
  "types": "./dist/index.d.ts",
14
28
  "exports": {
15
29
  "./package.json": "./package.json",
30
+ "./testing": {
31
+ "@aiao/source": "./src/testing.ts",
32
+ "types": "./dist/testing.d.ts",
33
+ "import": "./dist/testing.js",
34
+ "default": "./dist/testing.js"
35
+ },
16
36
  ".": {
17
37
  "types": "./dist/index.d.ts",
18
38
  "import": "./dist/index.js",
@@ -37,13 +57,19 @@
37
57
  ]
38
58
  },
39
59
  "dependencies": {
40
- "@sqliteai/sqlite-wasm": "3.50.4-wasm.1.0.0-sync.1.1.2-vector.1.0.0-memory.1.3.5",
41
- "@aiao/rxdb": "0.0.25",
42
- "@aiao/rxdb-adapter-sqlite-core": "0.0.25"
60
+ "@sqliteai/sqlite-wasm": "3.50.4-wasm.1.0.0-sync.1.2.0-vector.1.1.2-memory.1.3.5",
61
+ "@aiao/rxdb-adapter-sqlite-core": "^0.0.28"
43
62
  },
44
63
  "devDependencies": {
45
64
  "comlink": "^4.4.2",
46
65
  "ms": "^2.1.3",
47
- "@aiao/rxdb-test": "0.0.25"
66
+ "@aiao/rxdb-plugin-working-tree": "0.0.28",
67
+ "@aiao/rxdb-test": "0.0.28",
68
+ "@aiao/rxdb-plugin-sync": "0.0.28",
69
+ "@aiao/rxdb-plugin-history": "0.0.28",
70
+ "@aiao/rxdb-plugin-querycache": "0.0.28"
71
+ },
72
+ "peerDependencies": {
73
+ "@aiao/rxdb": "^0.0.28"
48
74
  }
49
75
  }
@@ -1,5 +1,5 @@
1
1
  import type { RxDB } from '@aiao/rxdb';
2
- import { RxDBAdapterSqliteBase, type SqliteClientLike } from '@aiao/rxdb-adapter-sqlite-core';
2
+ import { RxDBAdapterSqliteBase, type SqliteBackupStorage, type SqliteClientLike } from '@aiao/rxdb-adapter-sqlite-core';
3
3
  import { createSqliteClient } from './create_sqlite_client.js';
4
4
  import { ADAPTER_NAME, type SqliteaiOptions } from './sqliteai.interface.js';
5
5
 
@@ -22,6 +22,16 @@ export class RxDBAdapterSqliteai extends RxDBAdapterSqliteBase {
22
22
  this.#dbName = rxdb.config.dbName;
23
23
  }
24
24
 
25
+ /**
26
+ * 不开 OPFS 时是内存库;开 OPFS 时是持久化库。
27
+ * `opfsFallback: 'memory'` 会在 OPFS 打不开时静默落到内存,恢复目标不确定,报 `unsupported_combination`。
28
+ */
29
+ protected override backupStorage(): SqliteBackupStorage {
30
+ if (!this.options.opfs) return { kind: 'memory', label: 'memory' };
31
+ if (this.options.opfsFallback === 'memory') return { kind: 'unsupported', field: 'opfsFallback', actual: 'memory' };
32
+ return this.persistentBackupStorage('opfs');
33
+ }
34
+
25
35
  protected override async createClient(): Promise<SqliteClientLike> {
26
36
  return createSqliteClient(this.#dbName, this.options);
27
37
  }
@@ -1,12 +1,18 @@
1
- import { assertLoadOptionsTransferable, wrapWithComlink, type SqliteClientLike } from '@aiao/rxdb-adapter-sqlite-core';
1
+ import {
2
+ assertLoadOptionsTransferable,
3
+ releaseComlinkProxy,
4
+ wrapWithComlinkEndpoint,
5
+ type SqliteClientLike
6
+ } from '@aiao/rxdb-adapter-sqlite-core';
2
7
  import { SqliteaiOptions, type SqliteaiLoadOptions } from './sqliteai.interface.js';
3
8
  import { SqliteaiClient } from './SqliteaiClient.js';
4
9
 
5
10
  /**
6
11
  * 创建 SqliteAI 客户端实例并完成初始化。
7
12
  *
8
- * 如果 `options` 中指定了 worker / sharedWorker,会通过 `wrapWithComlink` 把客户端代理到 worker;
9
- * 否则在主线程直接 new。
13
+ * 如果 `options` 中指定了 worker / sharedWorker,会通过 `wrapWithComlinkEndpoint` 为这次连接租用
14
+ * worker 的一条独立子端口;否则在主线程直接 new。释放后同一个 worker 可以再连:恢复先用一条连接写库,
15
+ * 之后的 `connect()` 再开一条。
10
16
  *
11
17
  * 返回类型是 {@link SqliteClientLike} 而非具体的 `SqliteaiClient`:worker 模式下拿到的是
12
18
  * Comlink 远端代理,它把每个方法都 Promise 化,断言成实现类会让 `beginTransactionSql(): string`
@@ -32,7 +38,14 @@ export async function createSqliteClient(dbName: string, options: SqliteaiOption
32
38
 
33
39
  assertLoadOptionsTransferable(loadOptions, options);
34
40
 
35
- const client = wrapWithComlink(new SqliteaiClient(), options);
36
- await client.init(dbName, loadOptions);
37
- return client;
41
+ const client = await wrapWithComlinkEndpoint(new SqliteaiClient(), options);
42
+ try {
43
+ await client.init(dbName, loadOptions);
44
+ return client;
45
+ } catch (error) {
46
+ // 同 rxdb-adapter-sqlite / rxdb-adapter-sqlite-wasm:init 失败要释放 Comlink 代理,
47
+ // 否则 worker 模式下每次失败的重连都会多留一个 MessagePort 和一个 worker 侧客户端。
48
+ releaseComlinkProxy(client);
49
+ throw error;
50
+ }
38
51
  }
package/src/testing.ts ADDED
@@ -0,0 +1,21 @@
1
+ /**
2
+ * sqliteai 适配器测试工具入口(test-only)。
3
+ *
4
+ * 通过 `@aiao/rxdb-adapter-sqliteai/testing` 子路径导出,供跨包测试复用
5
+ * `sqliteaiFactory`(US-703 AC#8 的搜索套件入口依赖它)。
6
+ *
7
+ * 刻意用 `import.meta.glob` 而不是直接 `export ... from './__tests__/...'`:
8
+ * 后者会在 lib 类型检查里把测试工厂(及其 `@aiao/rxdb-test/encrypted` 依赖链)
9
+ * 拖进 `rootDir`,违反 `src/__tests__/` 的 lib 排除约定。glob 不产生直接 TS
10
+ * import 边,测试工厂只在 vite 打包/运行期被解析,类型由泛型声明。
11
+ *
12
+ * @packageDocumentation
13
+ */
14
+
15
+ import type { AdapterFactory } from '@aiao/rxdb-adapter-sqlite-core/testing';
16
+
17
+ const factoryModules = import.meta.glob<{ sqliteaiFactory: AdapterFactory }>('./__tests__/sqliteai-factory.ts', {
18
+ eager: true
19
+ });
20
+
21
+ export const sqliteaiFactory: AdapterFactory = factoryModules['./__tests__/sqliteai-factory.ts'].sqliteaiFactory;