tanstack-db-pglite 1.3.7 → 1.4.1

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/drizzle.d.ts CHANGED
@@ -16,10 +16,11 @@ type SyncParams<Table extends PgTable> = Parameters<SyncConfig<Table['$inferSele
16
16
  export declare function drizzleCollectionOptions<Table extends PgTable>({ startSync, ...config }: {
17
17
  db: PgliteDatabase<any>;
18
18
  startSync?: boolean;
19
+ sync?: {
20
+ sync: (params: Pick<SyncParams<Table>, 'write' | 'collection' | 'markReady' | 'metadata'>) => Promise<(() => void) | void>;
21
+ } & Omit<SyncConfig, 'sync'>;
19
22
  table: Table;
20
23
  primaryColumn: IndexColumn;
21
- rowUpdateMode?: 'partial' | 'full';
22
- sync?: (params: Pick<SyncParams<Table>, 'write' | 'collection' | 'markReady' | 'metadata'>) => Promise<(() => void) | void>;
23
24
  prepare?: () => Promise<unknown> | unknown;
24
25
  onInsert?: (params: InsertMutationFnParams<Table['$inferSelect'], string>) => Promise<void>;
25
26
  onUpdate?: (params: UpdateMutationFnParams<Table['$inferSelect'], string>) => Promise<void>;
package/dist/drizzle.js CHANGED
@@ -77,7 +77,7 @@ export function drizzleCollectionOptions({ startSync = true, ...config }) {
77
77
  params.markReady();
78
78
  return;
79
79
  }
80
- return config.sync({
80
+ return config.sync.sync({
81
81
  write: async (message) => {
82
82
  if (message.type === 'insert') {
83
83
  await onDrizzleInsert([message.value]);
@@ -103,7 +103,7 @@ export function drizzleCollectionOptions({ startSync = true, ...config }) {
103
103
  autoIndex: 'eager',
104
104
  defaultIndexType: BasicIndex,
105
105
  sync: {
106
- ...(config.rowUpdateMode && { rowUpdateMode: config.rowUpdateMode }),
106
+ ...config.sync,
107
107
  sync: (params) => {
108
108
  resolveSyncParams(params);
109
109
  (async () => {
@@ -121,9 +121,6 @@ export function drizzleCollectionOptions({ startSync = true, ...config }) {
121
121
  syncCleanup = result;
122
122
  }
123
123
  }
124
- else {
125
- params.markReady();
126
- }
127
124
  })();
128
125
  return () => {
129
126
  syncCleanup?.();
@@ -170,8 +167,6 @@ export function drizzleCollectionOptions({ startSync = true, ...config }) {
170
167
  }
171
168
  syncCleanup?.();
172
169
  syncCleanup = undefined;
173
- const params = await syncParams;
174
- await params.collection.stateWhenReady();
175
170
  const result = await sync();
176
171
  if (typeof result === 'function') {
177
172
  syncCleanup = result;
package/dist/sql.d.ts CHANGED
@@ -16,13 +16,14 @@ type SyncParams<ItemType extends Record<string, unknown>> = Parameters<SyncConfi
16
16
  export declare function sqlCollectionOptions<Schema extends StandardSchemaV1<Record<string, unknown>>>({ startSync, ...config }: {
17
17
  db: PGlite | PGliteWorker;
18
18
  startSync?: boolean;
19
+ sync?: {
20
+ sync: (params: Pick<SyncParams<Output<Schema>>, 'write' | 'collection' | 'markReady' | 'metadata'>) => Promise<(() => void) | void>;
21
+ } & Omit<SyncConfig, 'sync'>;
19
22
  tableName: string;
20
23
  primaryKeyColumn: Extract<keyof Output<Schema>, string>;
21
- rowUpdateMode?: 'partial' | 'full';
22
24
  schema: Schema;
23
25
  getKey?: (row: Output<Schema>) => string;
24
26
  prepare?: () => Promise<unknown> | unknown;
25
- sync?: (params: Pick<SyncParams<Output<Schema>>, 'write' | 'collection' | 'markReady' | 'metadata'>) => Promise<(() => void) | void>;
26
27
  onInsert?: (params: InsertMutationFnParams<Output<Schema>, string>) => Promise<void>;
27
28
  onUpdate?: (params: UpdateMutationFnParams<Output<Schema>, string>) => Promise<void>;
28
29
  onDelete?: (params: DeleteMutationFnParams<Output<Schema>, string>) => Promise<void>;
package/dist/sql.js CHANGED
@@ -1,6 +1,5 @@
1
- import { BasicIndex, } from '@tanstack/db';
1
+ import { BasicIndex } from '@tanstack/db';
2
2
  function quoteId(name) {
3
- // eslint-disable-next-line e18e/prefer-static-regex
4
3
  return `"${String(name).replace(/"/g, '""')}"`;
5
4
  }
6
5
  /**
@@ -64,7 +63,7 @@ export function sqlCollectionOptions({ startSync = true, ...config }) {
64
63
  params.markReady();
65
64
  return;
66
65
  }
67
- return config.sync({
66
+ return config.sync.sync({
68
67
  write: async (p) => {
69
68
  if (p.type === 'insert') {
70
69
  await runInsert(config.db, [p.value]);
@@ -90,7 +89,7 @@ export function sqlCollectionOptions({ startSync = true, ...config }) {
90
89
  autoIndex: 'eager',
91
90
  defaultIndexType: BasicIndex,
92
91
  sync: {
93
- ...(config.rowUpdateMode && { rowUpdateMode: config.rowUpdateMode }),
92
+ ...config.sync,
94
93
  sync: (params) => {
95
94
  resolveSyncParams(params);
96
95
  (async () => {
@@ -151,8 +150,6 @@ export function sqlCollectionOptions({ startSync = true, ...config }) {
151
150
  if (!config.sync) {
152
151
  throw new Error('Sync is not defined');
153
152
  }
154
- const params = await syncParams;
155
- await params.collection.stateWhenReady();
156
153
  const result = await sync();
157
154
  if (typeof result === 'function') {
158
155
  syncCleanup = result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tanstack-db-pglite",
3
- "version": "1.3.7",
3
+ "version": "1.4.1",
4
4
  "author": "Valerii Strilets",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -20,8 +20,8 @@
20
20
  "dist"
21
21
  ],
22
22
  "peerDependencies": {
23
- "@electric-sql/pglite": ">=0.3.0",
24
- "@tanstack/db": ">=0.5.0",
23
+ "@electric-sql/pglite": ">=0.4.0",
24
+ "@tanstack/db": ">=0.6.5",
25
25
  "drizzle-orm": ">=0.45.0"
26
26
  },
27
27
  "peerDependenciesMeta": {
@@ -33,11 +33,11 @@
33
33
  "drizzle-zod": "^0.8.3"
34
34
  },
35
35
  "devDependencies": {
36
- "@antfu/eslint-config": "^7.7.2",
36
+ "@antfu/eslint-config": "^9.0.0",
37
37
  "@standard-schema/spec": "^1.1.0",
38
- "eslint": "^10.2.1",
39
- "jiti": "^2.6.1",
40
- "taze": "^19.11.0",
38
+ "eslint": "^10.4.0",
39
+ "jiti": "^2.7.0",
40
+ "taze": "^19.13.0",
41
41
  "typescript": "^6.0.3"
42
42
  },
43
43
  "scripts": {