@livestore/common 0.3.0-dev.29 → 0.3.0-dev.30

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.
@@ -144,8 +144,7 @@ export const makeQueryBuilder = <TResult, TTableDef extends State.SQLite.TableDe
144
144
  return makeQueryBuilder(tableDef, {
145
145
  ...ast,
146
146
  limit: Option.some(1),
147
- // TODO improve
148
- pickFirst: options?.fallback ? { fallback: options.fallback } : { fallback: () => undefined },
147
+ pickFirst: options?.fallback ? { fallback: options.fallback } : 'no-fallback',
149
148
  })
150
149
  },
151
150
  // // eslint-disable-next-line prefer-arrow/prefer-arrow-functions
@@ -309,11 +308,17 @@ export const getResultSchema = (qb: QueryBuilder<any, any, any>): Schema.Schema<
309
308
  switch (queryAst._tag) {
310
309
  case 'SelectQuery': {
311
310
  const arraySchema = Schema.Array(queryAst.resultSchemaSingle)
312
- if (queryAst.pickFirst !== false) {
313
- return arraySchema.pipe(Schema.headOrElse(queryAst.pickFirst.fallback))
311
+ if (queryAst.pickFirst === false) {
312
+ return arraySchema
313
+ } else if (queryAst.pickFirst === 'no-fallback') {
314
+ // Will throw if the array is empty
315
+ return arraySchema.pipe(Schema.headOrElse())
316
+ } else {
317
+ const fallbackValue = queryAst.pickFirst.fallback()
318
+ return Schema.Union(arraySchema, Schema.Tuple(Schema.Literal(fallbackValue))).pipe(
319
+ Schema.headOrElse(() => fallbackValue),
320
+ )
314
321
  }
315
-
316
- return arraySchema
317
322
  }
318
323
  case 'CountQuery': {
319
324
  return Schema.Struct({ count: Schema.Number }).pipe(Schema.pluck('count'), Schema.Array, Schema.headOrElse())
package/src/version.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  // import packageJson from '../package.json' with { type: 'json' }
3
3
  // export const liveStoreVersion = packageJson.version
4
4
 
5
- export const liveStoreVersion = '0.3.0-dev.29' as const
5
+ export const liveStoreVersion = '0.3.0-dev.30' as const
6
6
 
7
7
  /**
8
8
  * This version number is incremented whenever the internal storage format changes in a breaking way.