@livestore/common 0.0.0-snapshot-2c861249e50661661613204300b1fc0d902c2e46 → 0.0.0-snapshot-8115ad48d5a57244358c943ecc92bb0a30274b87
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/.tsbuildinfo +1 -1
- package/dist/bounded-collections.d.ts +1 -1
- package/dist/bounded-collections.d.ts.map +1 -1
- package/dist/devtools/devtools-messages-leader.d.ts.map +1 -1
- package/dist/query-builder/api.d.ts +2 -2
- package/dist/query-builder/api.d.ts.map +1 -1
- package/dist/query-builder/impl.d.ts.map +1 -1
- package/dist/query-builder/impl.js +4 -6
- package/dist/query-builder/impl.js.map +1 -1
- package/dist/schema/client-document-def.d.ts +1 -1
- package/dist/schema/client-document-def.d.ts.map +1 -1
- package/dist/schema/client-document-def.js +14 -8
- package/dist/schema/client-document-def.js.map +1 -1
- package/dist/schema/client-document-def.test.js +57 -17
- package/dist/schema/client-document-def.test.js.map +1 -1
- package/package.json +3 -3
- package/src/query-builder/api.ts +2 -2
- package/src/query-builder/impl.ts +9 -5
- package/src/schema/client-document-def.test.ts +71 -20
- package/src/schema/client-document-def.ts +17 -9
|
@@ -28,7 +28,7 @@ export const clientDocument = <
|
|
|
28
28
|
TName extends string,
|
|
29
29
|
TType,
|
|
30
30
|
TEncoded,
|
|
31
|
-
const TOptions extends ClientDocumentTableOptions.Input<TType
|
|
31
|
+
const TOptions extends ClientDocumentTableOptions.Input<NoInfer<TType>>,
|
|
32
32
|
>({
|
|
33
33
|
name,
|
|
34
34
|
schema: valueSchema,
|
|
@@ -77,7 +77,7 @@ export const clientDocument = <
|
|
|
77
77
|
value: Schema.Struct({
|
|
78
78
|
id: Schema.String,
|
|
79
79
|
value: options.partialSet ? Schema.partial(valueSchema) : valueSchema,
|
|
80
|
-
}),
|
|
80
|
+
}).annotations({ title: `${name}Set:Args` }),
|
|
81
81
|
})
|
|
82
82
|
Object.defineProperty(setEventDef, 'options', { value: { derived: true, clientOnly: true, facts: undefined } })
|
|
83
83
|
|
|
@@ -109,18 +109,18 @@ export const clientDocument = <
|
|
|
109
109
|
return clientDocumentTableDef
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
const mergeDefaultValues = <T>(
|
|
112
|
+
const mergeDefaultValues = <T>(defaultValues: T, explicitDefaultValues: T): T => {
|
|
113
113
|
if (
|
|
114
|
-
typeof
|
|
114
|
+
typeof defaultValues !== 'object' ||
|
|
115
115
|
typeof explicitDefaultValues !== 'object' ||
|
|
116
|
-
|
|
116
|
+
defaultValues === null ||
|
|
117
117
|
explicitDefaultValues === null
|
|
118
118
|
) {
|
|
119
119
|
return explicitDefaultValues
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
return Object.keys(
|
|
123
|
-
acc[key] = (explicitDefaultValues as any)[key] ?? (
|
|
122
|
+
return Object.keys(defaultValues as any).reduce((acc, key) => {
|
|
123
|
+
acc[key] = (explicitDefaultValues as any)[key] ?? (defaultValues as any)[key]
|
|
124
124
|
return acc
|
|
125
125
|
}, {} as any)
|
|
126
126
|
}
|
|
@@ -177,15 +177,23 @@ export const deriveEventAndMaterializer = ({
|
|
|
177
177
|
|
|
178
178
|
for (const key in encodedPartialUpdate) {
|
|
179
179
|
const encodedValueForKey = encodedPartialUpdate[key]
|
|
180
|
+
// Skipping undefined values
|
|
181
|
+
if (encodedValueForKey === undefined) {
|
|
182
|
+
continue
|
|
183
|
+
}
|
|
180
184
|
jsonSetSql = `json_set(${jsonSetSql}, ?, json(?))`
|
|
181
185
|
setBindValues.push(`$.${key}`, JSON.stringify(encodedValueForKey))
|
|
182
186
|
}
|
|
183
187
|
|
|
188
|
+
const onConflictClause =
|
|
189
|
+
setBindValues.length > 0
|
|
190
|
+
? `ON CONFLICT (id) DO UPDATE SET value = ${jsonSetSql}`
|
|
191
|
+
: 'ON CONFLICT (id) DO NOTHING'
|
|
192
|
+
|
|
184
193
|
const sqlQuery = `
|
|
185
194
|
INSERT INTO '${name}' (id, value)
|
|
186
195
|
VALUES (?, ?)
|
|
187
|
-
|
|
188
|
-
value = ${jsonSetSql}
|
|
196
|
+
${onConflictClause}
|
|
189
197
|
`
|
|
190
198
|
|
|
191
199
|
return {
|