tanstack-db-pglite 1.2.1 → 1.2.3
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.js +16 -22
- package/dist/sql.js +16 -22
- package/package.json +2 -3
package/dist/drizzle.js
CHANGED
|
@@ -67,37 +67,31 @@ export function drizzleCollectionOptions({ startSync = true, ...config }) {
|
|
|
67
67
|
return;
|
|
68
68
|
}
|
|
69
69
|
const params = await syncParams;
|
|
70
|
-
|
|
71
|
-
resolvers.reject();
|
|
72
|
-
}
|
|
73
|
-
catch { }
|
|
70
|
+
const previousResolvers = resolvers;
|
|
74
71
|
resolvers = Promise.withResolvers();
|
|
72
|
+
previousResolvers.resolve({ continue: true });
|
|
75
73
|
await config.sync({
|
|
76
74
|
write: async (message) => {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (message.type === 'insert') {
|
|
80
|
-
await onDrizzleInsert([message.value]);
|
|
81
|
-
}
|
|
82
|
-
else if (message.type === 'update') {
|
|
83
|
-
await onDrizzleUpdate(params.collection.getKeyFromItem(message.value), message.value);
|
|
84
|
-
}
|
|
85
|
-
else if (message.type === 'delete') {
|
|
86
|
-
const key = 'key' in message ? message.key : params.collection.getKeyFromItem(message.value);
|
|
87
|
-
await onDrizzleDelete([key]);
|
|
88
|
-
}
|
|
89
|
-
params.write(message);
|
|
75
|
+
if (message.type === 'insert') {
|
|
76
|
+
await onDrizzleInsert([message.value]);
|
|
90
77
|
}
|
|
91
|
-
|
|
92
|
-
params.
|
|
78
|
+
else if (message.type === 'update') {
|
|
79
|
+
await onDrizzleUpdate(params.collection.getKeyFromItem(message.value), message.value);
|
|
93
80
|
}
|
|
81
|
+
else if (message.type === 'delete') {
|
|
82
|
+
const key = 'key' in message ? message.key : params.collection.getKeyFromItem(message.value);
|
|
83
|
+
await onDrizzleDelete([key]);
|
|
84
|
+
}
|
|
85
|
+
params.begin();
|
|
86
|
+
params.write(message);
|
|
87
|
+
params.commit();
|
|
94
88
|
},
|
|
95
89
|
collection: params.collection,
|
|
96
90
|
});
|
|
97
|
-
resolvers.resolve(
|
|
91
|
+
resolvers.resolve({ continue: false });
|
|
98
92
|
};
|
|
99
93
|
const waitForSync = async () => {
|
|
100
|
-
await resolvers.promise.
|
|
94
|
+
await resolvers.promise.then(r => r.continue ? waitForSync() : undefined);
|
|
101
95
|
};
|
|
102
96
|
return {
|
|
103
97
|
startSync: true,
|
|
@@ -107,9 +101,9 @@ export function drizzleCollectionOptions({ startSync = true, ...config }) {
|
|
|
107
101
|
(async () => {
|
|
108
102
|
try {
|
|
109
103
|
await config.prepare?.();
|
|
110
|
-
params.begin();
|
|
111
104
|
// @ts-expect-error drizzle types
|
|
112
105
|
const dbs = await config.db.select().from(config.table);
|
|
106
|
+
params.begin();
|
|
113
107
|
dbs.forEach((db) => {
|
|
114
108
|
params.write({ type: 'insert', value: db });
|
|
115
109
|
});
|
package/dist/sql.js
CHANGED
|
@@ -54,37 +54,31 @@ export function sqlCollectionOptions({ startSync = true, ...config }) {
|
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
56
|
const params = await syncParams;
|
|
57
|
-
|
|
58
|
-
resolvers.reject();
|
|
59
|
-
}
|
|
60
|
-
catch { }
|
|
57
|
+
const previousResolvers = resolvers;
|
|
61
58
|
resolvers = Promise.withResolvers();
|
|
59
|
+
previousResolvers.resolve({ continue: true });
|
|
62
60
|
await config.sync({
|
|
63
61
|
write: async (p) => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (p.type === 'insert') {
|
|
67
|
-
await runInsert(config.db, [p.value]);
|
|
68
|
-
}
|
|
69
|
-
else if (p.type === 'update') {
|
|
70
|
-
await runUpdate(config.db, params.collection.getKeyFromItem(p.value), p.value);
|
|
71
|
-
}
|
|
72
|
-
else if (p.type === 'delete') {
|
|
73
|
-
const key = 'key' in p ? p.key : params.collection.getKeyFromItem(p.value);
|
|
74
|
-
await runDelete(config.db, [key]);
|
|
75
|
-
}
|
|
76
|
-
params.write(p);
|
|
62
|
+
if (p.type === 'insert') {
|
|
63
|
+
await runInsert(config.db, [p.value]);
|
|
77
64
|
}
|
|
78
|
-
|
|
79
|
-
params.
|
|
65
|
+
else if (p.type === 'update') {
|
|
66
|
+
await runUpdate(config.db, params.collection.getKeyFromItem(p.value), p.value);
|
|
80
67
|
}
|
|
68
|
+
else if (p.type === 'delete') {
|
|
69
|
+
const key = 'key' in p ? p.key : params.collection.getKeyFromItem(p.value);
|
|
70
|
+
await runDelete(config.db, [key]);
|
|
71
|
+
}
|
|
72
|
+
params.begin();
|
|
73
|
+
params.write(p);
|
|
74
|
+
params.commit();
|
|
81
75
|
},
|
|
82
76
|
collection: params.collection,
|
|
83
77
|
});
|
|
84
|
-
resolvers.resolve(
|
|
78
|
+
resolvers.resolve({ continue: false });
|
|
85
79
|
};
|
|
86
80
|
const waitForSync = async () => {
|
|
87
|
-
await resolvers.promise.
|
|
81
|
+
await resolvers.promise.then(r => r.continue ? waitForSync() : undefined);
|
|
88
82
|
};
|
|
89
83
|
return {
|
|
90
84
|
startSync,
|
|
@@ -94,8 +88,8 @@ export function sqlCollectionOptions({ startSync = true, ...config }) {
|
|
|
94
88
|
(async () => {
|
|
95
89
|
try {
|
|
96
90
|
await config.prepare?.();
|
|
97
|
-
params.begin();
|
|
98
91
|
const rows = await runSelect(config.db);
|
|
92
|
+
params.begin();
|
|
99
93
|
rows.forEach((row) => {
|
|
100
94
|
params.write({ type: 'insert', value: row });
|
|
101
95
|
});
|
package/package.json
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tanstack-db-pglite",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"packageManager": "pnpm@10.32.1",
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "Valerii Strilets",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "git+https://github.com/letstri/tanstack-db-pglite.git"
|
|
11
|
-
"directory": "tanstack-db-pglite"
|
|
10
|
+
"url": "git+https://github.com/letstri/tanstack-db-pglite.git"
|
|
12
11
|
},
|
|
13
12
|
"keywords": [
|
|
14
13
|
"tanstack",
|