@aiao/rxdb-adapter-pglite 0.0.6 → 0.0.8

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.
Files changed (50) hide show
  1. package/dist/PGliteClient.d.ts +11 -2
  2. package/dist/PGliteClient.d.ts.map +1 -1
  3. package/dist/RxDBAdapterPGlite.d.ts +15 -16
  4. package/dist/RxDBAdapterPGlite.d.ts.map +1 -1
  5. package/dist/execute_helper.d.ts +70 -0
  6. package/dist/execute_helper.d.ts.map +1 -0
  7. package/dist/handle_rxdb_change.d.ts +26 -0
  8. package/dist/handle_rxdb_change.d.ts.map +1 -0
  9. package/dist/index.d.ts +7 -0
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +2403 -1884
  12. package/dist/pglite.interface.d.ts +37 -0
  13. package/dist/pglite.interface.d.ts.map +1 -1
  14. package/dist/pglite.utils.d.ts +46 -12
  15. package/dist/pglite.utils.d.ts.map +1 -1
  16. package/dist/query/find_by_row_ids_sql.d.ts +15 -0
  17. package/dist/query/find_by_row_ids_sql.d.ts.map +1 -0
  18. package/dist/query/join_sql.d.ts +10 -5
  19. package/dist/query/join_sql.d.ts.map +1 -1
  20. package/dist/query/query_sql.d.ts +3 -3
  21. package/dist/query/query_sql.d.ts.map +1 -1
  22. package/dist/repository/PGliteRepository.d.ts +3 -1
  23. package/dist/repository/PGliteRepository.d.ts.map +1 -1
  24. package/dist/repository/PGliteRepositoryBase.d.ts +8 -0
  25. package/dist/repository/PGliteRepositoryBase.d.ts.map +1 -1
  26. package/dist/rxdb_adapter_mutations.d.ts +72 -0
  27. package/dist/rxdb_adapter_mutations.d.ts.map +1 -0
  28. package/dist/sql_dialect.d.ts +77 -0
  29. package/dist/sql_dialect.d.ts.map +1 -0
  30. package/dist/table/{create_sql.d.ts → create_table_sql.d.ts} +1 -1
  31. package/dist/table/create_table_sql.d.ts.map +1 -0
  32. package/dist/table/create_tables_sql.d.ts +31 -0
  33. package/dist/table/create_tables_sql.d.ts.map +1 -0
  34. package/dist/table/notify_function_sql.d.ts +46 -0
  35. package/dist/table/notify_function_sql.d.ts.map +1 -0
  36. package/dist/table/remove_trigger_sql.d.ts +41 -0
  37. package/dist/table/remove_trigger_sql.d.ts.map +1 -0
  38. package/dist/table/trigger_sql.d.ts +0 -2
  39. package/dist/table/trigger_sql.d.ts.map +1 -1
  40. package/dist/transaction_pglite_result.d.ts +102 -0
  41. package/dist/transaction_pglite_result.d.ts.map +1 -0
  42. package/dist/version/create_branch.d.ts +24 -0
  43. package/dist/version/create_branch.d.ts.map +1 -0
  44. package/dist/{rxdb_adapter_switch_transaction_id.d.ts → version/switch_transaction_id.d.ts} +3 -3
  45. package/dist/version/switch_transaction_id.d.ts.map +1 -0
  46. package/package.json +7 -7
  47. package/dist/rxdb_adapter_create_branch.d.ts +0 -7
  48. package/dist/rxdb_adapter_create_branch.d.ts.map +0 -1
  49. package/dist/rxdb_adapter_switch_transaction_id.d.ts.map +0 -1
  50. package/dist/table/create_sql.d.ts.map +0 -1
@@ -0,0 +1,102 @@
1
+ import { EntityType } from '../packages/rxdb/src/index.ts';
2
+ import { RxDBAdapterPGlite } from './RxDBAdapterPGlite.js';
3
+ /**
4
+ * PGlite 执行结果(从 execute_helper 返回)
5
+ */
6
+ export interface PGliteExecuteResult<T = any> {
7
+ rows: T[];
8
+ rowsAffected: number;
9
+ elapsed: number;
10
+ }
11
+ /**
12
+ * 从 PGlite 查询结果创建或重用实体
13
+ *
14
+ * 这是处理 SELECT/INSERT RETURNING/UPDATE RETURNING 结果的统一入口。
15
+ *
16
+ * ## 行为
17
+ *
18
+ * 1. **新实体**:如果 ID 在缓存中不存在,创建新实体并标记为 `local=true, modified=false`
19
+ * 2. **已存在实体**:返回缓存中的同一实例(引用相等)
20
+ * 3. **forcedUpdate=true**:强制更新已存在实体的所有字段
21
+ * 4. **forcedUpdate=false**(默认):不更新已存在实体
22
+ *
23
+ * ## 使用场景
24
+ *
25
+ * - **INSERT RETURNING**: 总是创建新实体
26
+ * - **SELECT**: 查询结果,可能包含新旧实体
27
+ * - **UPDATE RETURNING**: 需要 `forcedUpdate=true` 更新实体状态
28
+ *
29
+ * @param adapter - PGlite 适配器实例
30
+ * @param EntityType - 实体类型
31
+ * @param result - execute_helper 返回的结果
32
+ * @param forcedUpdate - 是否强制更新已存在的实体
33
+ * @returns 实体数组(新创建或重用的)
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * // SELECT 查询:重用缓存实体
38
+ * const result = await execute_query(client, 'SELECT * FROM todos WHERE completed = $1', [false]);
39
+ * const todos = transaction_pglite_result(adapter, Todo, result);
40
+ *
41
+ * // INSERT RETURNING:创建新实体
42
+ * const insertResult = await execute_query(
43
+ * client,
44
+ * 'INSERT INTO todos (id, title) VALUES ($1, $2) RETURNING *',
45
+ * ['new-id', 'New Todo']
46
+ * );
47
+ * const newTodo = transaction_pglite_result(adapter, Todo, insertResult)[0];
48
+ *
49
+ * // UPDATE RETURNING:强制更新实体
50
+ * const updateResult = await execute_query(
51
+ * client,
52
+ * 'UPDATE todos SET completed = true WHERE id = $1 RETURNING *',
53
+ * ['todo-id']
54
+ * );
55
+ * transaction_pglite_result(adapter, Todo, updateResult, true);
56
+ * ```
57
+ */
58
+ export declare const transaction_pglite_result: <T extends EntityType>(adapter: RxDBAdapterPGlite, EntityType: T, result: PGliteExecuteResult, forcedUpdate?: boolean) => InstanceType<T>[];
59
+ /**
60
+ * 更新已存在的实体(仅更新,不创建新实体)
61
+ *
62
+ * 用于 UPDATE RETURNING 场景:只更新已在内存中的实体,不创建新实体。
63
+ *
64
+ * ## 与 transaction_pglite_result(forcedUpdate=true) 的区别
65
+ *
66
+ * - `transaction_pglite_result(forcedUpdate=true)`: 更新 **或** 创建
67
+ * - `update_entity_from_pglite_result`: **只更新**,忽略不存在的实体
68
+ *
69
+ * @param adapter - PGlite 适配器实例
70
+ * @param EntityType - 实体类型
71
+ * @param result - execute_helper 返回的结果
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * // 仅更新内存中的实体,忽略不存在的 ID
76
+ * const result = await execute_query(
77
+ * client,
78
+ * 'UPDATE todos SET completed = true WHERE id = ANY($1) RETURNING *',
79
+ * [todoIds]
80
+ * );
81
+ * update_entity_from_pglite_result(adapter, Todo, result);
82
+ * ```
83
+ */
84
+ export declare const update_entity_from_pglite_result: <T extends EntityType>(adapter: RxDBAdapterPGlite, EntityType: T, result: PGliteExecuteResult) => void;
85
+ /**
86
+ * 将实体标记为已删除(从缓存中移除)
87
+ *
88
+ * 用于 DELETE 操作后清理内存状态。实体不会被销毁,但会被标记为 `removed=true, local=false`。
89
+ *
90
+ * @param adapter - PGlite 适配器实例
91
+ * @param EntityType - 实体类型
92
+ * @param ids - 要删除的实体 ID 数组
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * // 删除后清理缓存
97
+ * await execute_query(client, 'DELETE FROM todos WHERE id = ANY($1)', [todoIds]);
98
+ * remove_entity_ids_from_cache(adapter, Todo, todoIds);
99
+ * ```
100
+ */
101
+ export declare const remove_entity_ids_from_cache: <T extends EntityType>(adapter: RxDBAdapterPGlite, EntityType: T, ids: any[]) => void;
102
+ //# sourceMappingURL=transaction_pglite_result.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction_pglite_result.d.ts","sourceRoot":"","sources":["../src/transaction_pglite_result.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,UAAU,EAAsC,MAAM,YAAY,CAAC;AAC5E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAGhE;;GAEG;AACH,MAAM,WAAW,mBAAmB,CAAC,CAAC,GAAG,GAAG;IAC1C,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,yBAAyB,GAAI,CAAC,SAAS,UAAU,EAC5D,SAAS,iBAAiB,EAC1B,YAAY,CAAC,EACb,QAAQ,mBAAmB,EAC3B,eAAc,OAAe,KAC5B,YAAY,CAAC,CAAC,CAAC,EAkDjB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,gCAAgC,GAAI,CAAC,SAAS,UAAU,EACnE,SAAS,iBAAiB,EAC1B,YAAY,CAAC,EACb,QAAQ,mBAAmB,KAC1B,IAuBF,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,4BAA4B,GAAI,CAAC,SAAS,UAAU,EAC/D,SAAS,iBAAiB,EAC1B,YAAY,CAAC,EACb,KAAK,GAAG,EAAE,KACT,IAUF,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { RxDBBranch } from '../../packages/rxdb/src/index.ts';
2
+ import { RxDBAdapterPGlite } from '../RxDBAdapterPGlite.js';
3
+ /**
4
+ * 创建分支
5
+ *
6
+ * 从当前分支或指定变更点创建新分支
7
+ *
8
+ * @param adapter - PGlite 适配器实例
9
+ * @param branchId - 新分支 ID
10
+ * @param fromChangeId - 可选,从指定变更点创建分支
11
+ * @returns 创建的分支实体
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * // 从当前分支创建新分支
16
+ * const branch = await rxdb_adapter_create_branch(adapter, 'feature-01');
17
+ *
18
+ * // 从指定变更点创建分支
19
+ * const branch = await rxdb_adapter_create_branch(adapter, 'feature-02', 42);
20
+ * ```
21
+ */
22
+ declare const _default: (adapter: RxDBAdapterPGlite, branchId: string, fromChangeId?: number) => Promise<InstanceType<typeof RxDBBranch>>;
23
+ export default _default;
24
+ //# sourceMappingURL=create_branch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create_branch.d.ts","sourceRoot":"","sources":["../../src/version/create_branch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D;;;;;;;;;;;;;;;;;;GAkBG;yBAED,SAAS,iBAAiB,EAC1B,UAAU,MAAM,EAChB,eAAe,MAAM,KACpB,OAAO,CAAC,YAAY,CAAC,OAAO,UAAU,CAAC,CAAC;AAJ3C,wBA4EE"}
@@ -1,5 +1,5 @@
1
- import { UUID } from '../packages/rxdb/src/index.ts';
2
- import { RxDBAdapterPGlite } from './RxDBAdapterPGlite.js';
1
+ import { UUID } from '../../packages/rxdb/src/index.ts';
2
+ import { RxDBAdapterPGlite } from '../RxDBAdapterPGlite.js';
3
3
  /**
4
4
  * 切换事务 ID
5
5
  *
@@ -15,4 +15,4 @@ import { RxDBAdapterPGlite } from './RxDBAdapterPGlite.js';
15
15
  * @returns SQL 语句数组(因为在事务中 query() 方法不支持多条语句)
16
16
  */
17
17
  export default function rxdb_adapter_switch_transaction_id(adapter: RxDBAdapterPGlite, branchId: string, transactionId?: UUID): string[];
18
- //# sourceMappingURL=rxdb_adapter_switch_transaction_id.d.ts.map
18
+ //# sourceMappingURL=switch_transaction_id.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"switch_transaction_id.d.ts","sourceRoot":"","sources":["../../src/version/switch_transaction_id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,IAAI,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAGjE;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,OAAO,UAAU,kCAAkC,CACxD,OAAO,EAAE,iBAAiB,EAC1B,QAAQ,EAAE,MAAM,EAChB,aAAa,CAAC,EAAE,IAAI,GACnB,MAAM,EAAE,CAiBV"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiao/rxdb-adapter-pglite",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -25,14 +25,14 @@
25
25
  ]
26
26
  },
27
27
  "dependencies": {
28
- "rxjs": "^7.8.2",
29
- "@electric-sql/pglite": "^0.3.9",
28
+ "@electric-sql/pglite": "^0.3.14",
30
29
  "object-hash": "^3.0.0",
31
- "type-fest": "^5.1.0",
32
- "@aiao/rxdb": "0.0.6",
33
- "@aiao/utils": "0.0.6"
30
+ "rxjs": "^7.8.2",
31
+ "type-fest": "^5.3.1",
32
+ "@aiao/rxdb": "0.0.8",
33
+ "@aiao/utils": "0.0.8"
34
34
  },
35
35
  "devDependencies": {
36
- "@aiao/rxdb-test": "0.0.6"
36
+ "@aiao/rxdb-test": "0.0.8"
37
37
  }
38
38
  }
@@ -1,7 +0,0 @@
1
- import { RxDBAdapterPGlite } from './RxDBAdapterPGlite.js';
2
- /**
3
- * 创建分支
4
- */
5
- declare const _default: (adapter: RxDBAdapterPGlite, branchId: string, fromChangeId?: number) => Promise<void>;
6
- export default _default;
7
- //# sourceMappingURL=rxdb_adapter_create_branch.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rxdb_adapter_create_branch.d.ts","sourceRoot":"","sources":["../src/rxdb_adapter_create_branch.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D;;GAEG;yBACmB,SAAS,iBAAiB,EAAE,UAAU,MAAM,EAAE,eAAe,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC;AAAzG,wBAiEE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"rxdb_adapter_switch_transaction_id.d.ts","sourceRoot":"","sources":["../src/rxdb_adapter_switch_transaction_id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,IAAI,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAGhE;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,OAAO,UAAU,kCAAkC,CACxD,OAAO,EAAE,iBAAiB,EAC1B,QAAQ,EAAE,MAAM,EAChB,aAAa,CAAC,EAAE,IAAI,GACnB,MAAM,EAAE,CAiBV"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"create_sql.d.ts","sourceRoot":"","sources":["../../src/table/create_sql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAA8B,MAAM,YAAY,CAAC;AAExE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;yBAoK5C,SAAS,iBAAiB,EAAE,UAAU,cAAc;AAApE,wBAKE"}