@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.
@@ -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>(schemaDefaultValues: T, explicitDefaultValues: T): T => {
112
+ const mergeDefaultValues = <T>(defaultValues: T, explicitDefaultValues: T): T => {
113
113
  if (
114
- typeof schemaDefaultValues !== 'object' ||
114
+ typeof defaultValues !== 'object' ||
115
115
  typeof explicitDefaultValues !== 'object' ||
116
- schemaDefaultValues === null ||
116
+ defaultValues === null ||
117
117
  explicitDefaultValues === null
118
118
  ) {
119
119
  return explicitDefaultValues
120
120
  }
121
121
 
122
- return Object.keys(schemaDefaultValues as any).reduce((acc, key) => {
123
- acc[key] = (explicitDefaultValues as any)[key] ?? (schemaDefaultValues 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
- ON CONFLICT (id) DO UPDATE SET
188
- value = ${jsonSetSql}
196
+ ${onConflictClause}
189
197
  `
190
198
 
191
199
  return {