@livestore/common 0.0.48-dev.0 → 0.0.48-dev.2

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.
Files changed (47) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/__tests__/fixture.d.ts +8 -2
  3. package/dist/__tests__/fixture.d.ts.map +1 -1
  4. package/dist/derived-mutations.d.ts +22 -26
  5. package/dist/derived-mutations.d.ts.map +1 -1
  6. package/dist/derived-mutations.js +5 -4
  7. package/dist/derived-mutations.js.map +1 -1
  8. package/dist/schema/index.d.ts +1 -1
  9. package/dist/schema/index.d.ts.map +1 -1
  10. package/dist/schema/index.js +2 -1
  11. package/dist/schema/index.js.map +1 -1
  12. package/dist/schema/mutations.d.ts +12 -1
  13. package/dist/schema/mutations.d.ts.map +1 -1
  14. package/dist/schema/mutations.js +2 -1
  15. package/dist/schema/mutations.js.map +1 -1
  16. package/dist/schema/system-tables.d.ts +207 -232
  17. package/dist/schema/system-tables.d.ts.map +1 -1
  18. package/dist/schema/system-tables.js +1 -1
  19. package/dist/schema/system-tables.js.map +1 -1
  20. package/dist/schema/table-def.d.ts +41 -7
  21. package/dist/schema/table-def.d.ts.map +1 -1
  22. package/dist/schema/table-def.js +8 -2
  23. package/dist/schema/table-def.js.map +1 -1
  24. package/dist/schema-management/common.d.ts +8 -0
  25. package/dist/schema-management/common.d.ts.map +1 -1
  26. package/dist/schema-management/migrations.d.ts +3 -0
  27. package/dist/schema-management/migrations.d.ts.map +1 -1
  28. package/dist/schema-management/migrations.js +24 -3
  29. package/dist/schema-management/migrations.js.map +1 -1
  30. package/dist/schema-management/validate-mutation-defs.d.ts +1 -11
  31. package/dist/schema-management/validate-mutation-defs.d.ts.map +1 -1
  32. package/dist/schema-management/validate-mutation-defs.js +0 -26
  33. package/dist/schema-management/validate-mutation-defs.js.map +1 -1
  34. package/dist/sync/sync.d.ts +4 -0
  35. package/dist/sync/sync.d.ts.map +1 -1
  36. package/dist/sync/sync.js +6 -2
  37. package/dist/sync/sync.js.map +1 -1
  38. package/package.json +3 -3
  39. package/src/derived-mutations.ts +55 -15
  40. package/src/schema/index.ts +2 -2
  41. package/src/schema/mutations.ts +13 -0
  42. package/src/schema/system-tables.ts +1 -1
  43. package/src/schema/table-def.ts +44 -8
  44. package/src/schema-management/common.ts +11 -0
  45. package/src/schema-management/migrations.ts +42 -4
  46. package/src/schema-management/validate-mutation-defs.ts +1 -49
  47. package/src/sync/sync.ts +6 -2
@@ -1,15 +1,9 @@
1
1
  import { shouldNeverHappen } from '@livestore/utils'
2
2
  import { Schema } from '@livestore/utils/effect'
3
- import * as otel from '@opentelemetry/api'
4
3
 
5
- import type { InMemoryDatabase } from '../adapter-types.js'
6
4
  import type { LiveStoreSchema } from '../schema/index.js'
7
5
  import type { MutationDef } from '../schema/mutations.js'
8
- import type { SchemaMutationsMetaRow } from '../schema/system-tables.js'
9
- import { SCHEMA_MUTATIONS_META_TABLE, schemaMutationsMetaTable } from '../schema/system-tables.js'
10
- import { sql } from '../util.js'
11
- import { dbExecute, dbSelect } from './common.js'
12
- import { migrateTable } from './migrations.js'
6
+ import type { MutationDefInfo, SchemaManager } from './common.js'
13
7
 
14
8
  export const validateSchema = (schema: LiveStoreSchema, schemaManager: SchemaManager) => {
15
9
  // Validate mutation definitions
@@ -64,45 +58,3 @@ export const validateMutationDef = (
64
58
  mutationName: mutationDef.name,
65
59
  })
66
60
  }
67
-
68
- interface SchemaManager {
69
- getMutationDefInfos: () => ReadonlyArray<MutationDefInfo>
70
-
71
- setMutationDefInfo: (mutationDefInfo: MutationDefInfo) => void
72
- }
73
-
74
- type MutationDefInfo = {
75
- mutationName: string
76
- schemaHash: number
77
- }
78
-
79
- export const makeSchemaManager = (db: InMemoryDatabase): SchemaManager => {
80
- migrateTable({
81
- db,
82
- otelContext: otel.context.active(),
83
- tableAst: schemaMutationsMetaTable.sqliteDef.ast,
84
- behaviour: 'create-if-not-exists',
85
- })
86
-
87
- return {
88
- getMutationDefInfos: () => {
89
- const schemaMutationsMetaRows = dbSelect<SchemaMutationsMetaRow>(
90
- db,
91
- sql`SELECT * FROM ${SCHEMA_MUTATIONS_META_TABLE}`,
92
- )
93
-
94
- return schemaMutationsMetaRows
95
- },
96
- setMutationDefInfo: (info) => {
97
- dbExecute(
98
- db,
99
- sql`INSERT OR REPLACE INTO ${SCHEMA_MUTATIONS_META_TABLE} (mutationName, schemaHash, updatedAt) VALUES ($mutationName, $schemaHash, $updatedAt)`,
100
- {
101
- mutationName: info.mutationName,
102
- schemaHash: info.schemaHash,
103
- updatedAt: new Date().toISOString(),
104
- },
105
- )
106
- },
107
- }
108
- }
package/src/sync/sync.ts CHANGED
@@ -10,5 +10,9 @@ export type SyncImpl = {
10
10
  }
11
11
 
12
12
  export class IsOfflineError extends Schema.TaggedError<IsOfflineError>()('IsOfflineError', {}) {}
13
- export class InvalidPushError extends Schema.TaggedError<InvalidPushError>()('InvalidPushError', {}) {}
14
- export class InvalidPullError extends Schema.TaggedError<InvalidPullError>()('InvalidPullError', {}) {}
13
+ export class InvalidPushError extends Schema.TaggedError<InvalidPushError>()('InvalidPushError', {
14
+ message: Schema.String,
15
+ }) {}
16
+ export class InvalidPullError extends Schema.TaggedError<InvalidPullError>()('InvalidPullError', {
17
+ message: Schema.String,
18
+ }) {}