tanstack-db-pglite 1.1.8 → 1.2.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.js +42 -38
- package/dist/sql.js +33 -28
- package/package.json +1 -1
package/dist/drizzle.js
CHANGED
|
@@ -32,31 +32,6 @@ export function drizzleCollectionOptions({ startSync = true, ...config }) {
|
|
|
32
32
|
throw e;
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
|
-
const getSyncParams = async () => {
|
|
36
|
-
const params = await syncParams;
|
|
37
|
-
return {
|
|
38
|
-
write: async (message) => {
|
|
39
|
-
params.begin();
|
|
40
|
-
try {
|
|
41
|
-
if (message.type === 'insert') {
|
|
42
|
-
await onDrizzleInsert([message.value]);
|
|
43
|
-
}
|
|
44
|
-
else if (message.type === 'update') {
|
|
45
|
-
await onDrizzleUpdate(params.collection.getKeyFromItem(message.value), message.value);
|
|
46
|
-
}
|
|
47
|
-
else if (message.type === 'delete') {
|
|
48
|
-
const key = 'key' in message ? message.key : params.collection.getKeyFromItem(message.value);
|
|
49
|
-
await onDrizzleDelete([key]);
|
|
50
|
-
}
|
|
51
|
-
params.write(message);
|
|
52
|
-
}
|
|
53
|
-
finally {
|
|
54
|
-
params.commit();
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
collection: params.collection,
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
35
|
// Mutations should run if everything is okay inside "on" handlers
|
|
61
36
|
async function runMutations(mutations) {
|
|
62
37
|
const { begin, write, commit } = await syncParams;
|
|
@@ -87,6 +62,43 @@ export function drizzleCollectionOptions({ startSync = true, ...config }) {
|
|
|
87
62
|
.from(config.table)
|
|
88
63
|
.where(eq(config.primaryColumn, m.key))));
|
|
89
64
|
}
|
|
65
|
+
const sync = async () => {
|
|
66
|
+
if (!config.sync) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const params = await syncParams;
|
|
70
|
+
try {
|
|
71
|
+
resolvers.reject();
|
|
72
|
+
}
|
|
73
|
+
catch { }
|
|
74
|
+
resolvers = Promise.withResolvers();
|
|
75
|
+
await config.sync({
|
|
76
|
+
write: async (message) => {
|
|
77
|
+
params.begin();
|
|
78
|
+
try {
|
|
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);
|
|
90
|
+
}
|
|
91
|
+
finally {
|
|
92
|
+
params.commit();
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
collection: params.collection,
|
|
96
|
+
});
|
|
97
|
+
resolvers.resolve(undefined);
|
|
98
|
+
};
|
|
99
|
+
const waitForSync = async () => {
|
|
100
|
+
await resolvers.promise.catch(() => waitForSync());
|
|
101
|
+
};
|
|
90
102
|
return {
|
|
91
103
|
startSync: true,
|
|
92
104
|
sync: {
|
|
@@ -102,10 +114,8 @@ export function drizzleCollectionOptions({ startSync = true, ...config }) {
|
|
|
102
114
|
params.write({ type: 'insert', value: db });
|
|
103
115
|
});
|
|
104
116
|
params.commit();
|
|
105
|
-
if (
|
|
106
|
-
|
|
107
|
-
await config.sync(await getSyncParams());
|
|
108
|
-
resolvers.resolve(undefined);
|
|
117
|
+
if (startSync) {
|
|
118
|
+
sync();
|
|
109
119
|
}
|
|
110
120
|
}
|
|
111
121
|
finally {
|
|
@@ -114,7 +124,6 @@ export function drizzleCollectionOptions({ startSync = true, ...config }) {
|
|
|
114
124
|
})();
|
|
115
125
|
},
|
|
116
126
|
},
|
|
117
|
-
gcTime: 0,
|
|
118
127
|
schema: createSelectSchema(config.table),
|
|
119
128
|
getKey: t => t[config.primaryColumn.name],
|
|
120
129
|
onInsert: async (params) => {
|
|
@@ -152,16 +161,11 @@ export function drizzleCollectionOptions({ startSync = true, ...config }) {
|
|
|
152
161
|
if (!config.sync) {
|
|
153
162
|
throw new Error('Sync is not defined');
|
|
154
163
|
}
|
|
155
|
-
const params = await
|
|
156
|
-
// To wait the first sync
|
|
164
|
+
const params = await syncParams;
|
|
157
165
|
await params.collection.stateWhenReady();
|
|
158
|
-
|
|
159
|
-
await config.sync(params);
|
|
160
|
-
resolvers.resolve(undefined);
|
|
161
|
-
},
|
|
162
|
-
waitForSync: async () => {
|
|
163
|
-
await resolvers.promise;
|
|
166
|
+
sync();
|
|
164
167
|
},
|
|
168
|
+
waitForSync,
|
|
165
169
|
},
|
|
166
170
|
};
|
|
167
171
|
}
|
package/dist/sql.js
CHANGED
|
@@ -36,9 +36,30 @@ export function sqlCollectionOptions({ startSync = true, ...config }) {
|
|
|
36
36
|
return;
|
|
37
37
|
await client.query(`DELETE FROM ${table} WHERE ${primaryKey} = ANY($1)`, [ids]);
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
async function runMutations(mutations) {
|
|
40
|
+
const { begin, write, commit } = await syncParams;
|
|
41
|
+
begin();
|
|
42
|
+
mutations.forEach((m) => {
|
|
43
|
+
if (m.type === 'delete') {
|
|
44
|
+
write({ type: 'delete', key: m.key });
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
write({ type: m.type, value: m.modified });
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
commit();
|
|
51
|
+
}
|
|
52
|
+
const sync = async () => {
|
|
53
|
+
if (!config.sync) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
40
56
|
const params = await syncParams;
|
|
41
|
-
|
|
57
|
+
try {
|
|
58
|
+
resolvers.reject();
|
|
59
|
+
}
|
|
60
|
+
catch { }
|
|
61
|
+
resolvers = Promise.withResolvers();
|
|
62
|
+
await config.sync({
|
|
42
63
|
write: async (p) => {
|
|
43
64
|
params.begin();
|
|
44
65
|
try {
|
|
@@ -59,21 +80,12 @@ export function sqlCollectionOptions({ startSync = true, ...config }) {
|
|
|
59
80
|
}
|
|
60
81
|
},
|
|
61
82
|
collection: params.collection,
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
async function runMutations(mutations) {
|
|
65
|
-
const { begin, write, commit } = await syncParams;
|
|
66
|
-
begin();
|
|
67
|
-
mutations.forEach((m) => {
|
|
68
|
-
if (m.type === 'delete') {
|
|
69
|
-
write({ type: 'delete', key: m.key });
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
write({ type: m.type, value: m.modified });
|
|
73
|
-
}
|
|
74
83
|
});
|
|
75
|
-
|
|
76
|
-
}
|
|
84
|
+
resolvers.resolve(undefined);
|
|
85
|
+
};
|
|
86
|
+
const waitForSync = async () => {
|
|
87
|
+
await resolvers.promise.catch(() => waitForSync());
|
|
88
|
+
};
|
|
77
89
|
return {
|
|
78
90
|
startSync,
|
|
79
91
|
sync: {
|
|
@@ -88,10 +100,8 @@ export function sqlCollectionOptions({ startSync = true, ...config }) {
|
|
|
88
100
|
params.write({ type: 'insert', value: row });
|
|
89
101
|
});
|
|
90
102
|
params.commit();
|
|
91
|
-
if (
|
|
92
|
-
|
|
93
|
-
await config.sync(await getSyncParams());
|
|
94
|
-
resolvers.resolve(undefined);
|
|
103
|
+
if (startSync) {
|
|
104
|
+
sync();
|
|
95
105
|
}
|
|
96
106
|
}
|
|
97
107
|
finally {
|
|
@@ -100,7 +110,6 @@ export function sqlCollectionOptions({ startSync = true, ...config }) {
|
|
|
100
110
|
})();
|
|
101
111
|
},
|
|
102
112
|
},
|
|
103
|
-
gcTime: 0,
|
|
104
113
|
schema: config.schema,
|
|
105
114
|
getKey,
|
|
106
115
|
onInsert: async (params) => {
|
|
@@ -135,15 +144,11 @@ export function sqlCollectionOptions({ startSync = true, ...config }) {
|
|
|
135
144
|
if (!config.sync) {
|
|
136
145
|
throw new Error('Sync is not defined');
|
|
137
146
|
}
|
|
138
|
-
const params = await
|
|
147
|
+
const params = await syncParams;
|
|
139
148
|
await params.collection.stateWhenReady();
|
|
140
|
-
|
|
141
|
-
await config.sync(params);
|
|
142
|
-
resolvers.resolve(undefined);
|
|
143
|
-
},
|
|
144
|
-
waitForSync: async () => {
|
|
145
|
-
await resolvers.promise;
|
|
149
|
+
sync();
|
|
146
150
|
},
|
|
151
|
+
waitForSync,
|
|
147
152
|
},
|
|
148
153
|
};
|
|
149
154
|
}
|