@livestore/common 0.0.0-snapshot-909cdd1ac2fd591945c2be2b0f53e14d87f3c9d4

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 (220) hide show
  1. package/dist/.tsbuildinfo +1 -0
  2. package/dist/__tests__/fixture.d.ts +72 -0
  3. package/dist/__tests__/fixture.d.ts.map +1 -0
  4. package/dist/__tests__/fixture.js +16 -0
  5. package/dist/__tests__/fixture.js.map +1 -0
  6. package/dist/adapter-types.d.ts +202 -0
  7. package/dist/adapter-types.d.ts.map +1 -0
  8. package/dist/adapter-types.js +49 -0
  9. package/dist/adapter-types.js.map +1 -0
  10. package/dist/bounded-collections.d.ts +36 -0
  11. package/dist/bounded-collections.d.ts.map +1 -0
  12. package/dist/bounded-collections.js +98 -0
  13. package/dist/bounded-collections.js.map +1 -0
  14. package/dist/debug-info.d.ts +122 -0
  15. package/dist/debug-info.d.ts.map +1 -0
  16. package/dist/debug-info.js +47 -0
  17. package/dist/debug-info.js.map +1 -0
  18. package/dist/derived-mutations.d.ts +109 -0
  19. package/dist/derived-mutations.d.ts.map +1 -0
  20. package/dist/derived-mutations.js +54 -0
  21. package/dist/derived-mutations.js.map +1 -0
  22. package/dist/derived-mutations.test.d.ts +2 -0
  23. package/dist/derived-mutations.test.d.ts.map +1 -0
  24. package/dist/derived-mutations.test.js +93 -0
  25. package/dist/derived-mutations.test.js.map +1 -0
  26. package/dist/devtools/devtools-bridge.d.ts +12 -0
  27. package/dist/devtools/devtools-bridge.d.ts.map +1 -0
  28. package/dist/devtools/devtools-bridge.js +2 -0
  29. package/dist/devtools/devtools-bridge.js.map +1 -0
  30. package/dist/devtools/devtools-messages.d.ts +705 -0
  31. package/dist/devtools/devtools-messages.d.ts.map +1 -0
  32. package/dist/devtools/devtools-messages.js +178 -0
  33. package/dist/devtools/devtools-messages.js.map +1 -0
  34. package/dist/devtools/devtools-window-message.d.ts +29 -0
  35. package/dist/devtools/devtools-window-message.d.ts.map +1 -0
  36. package/dist/devtools/devtools-window-message.js +33 -0
  37. package/dist/devtools/devtools-window-message.js.map +1 -0
  38. package/dist/devtools/index.d.ts +42 -0
  39. package/dist/devtools/index.d.ts.map +1 -0
  40. package/dist/devtools/index.js +49 -0
  41. package/dist/devtools/index.js.map +1 -0
  42. package/dist/index.d.ts +19 -0
  43. package/dist/index.d.ts.map +1 -0
  44. package/dist/index.js +15 -0
  45. package/dist/index.js.map +1 -0
  46. package/dist/init-singleton-tables.d.ts +4 -0
  47. package/dist/init-singleton-tables.d.ts.map +1 -0
  48. package/dist/init-singleton-tables.js +16 -0
  49. package/dist/init-singleton-tables.js.map +1 -0
  50. package/dist/mutation.d.ts +13 -0
  51. package/dist/mutation.d.ts.map +1 -0
  52. package/dist/mutation.js +43 -0
  53. package/dist/mutation.js.map +1 -0
  54. package/dist/query-info.d.ts +47 -0
  55. package/dist/query-info.d.ts.map +1 -0
  56. package/dist/query-info.js +38 -0
  57. package/dist/query-info.js.map +1 -0
  58. package/dist/rehydrate-from-mutationlog.d.ts +14 -0
  59. package/dist/rehydrate-from-mutationlog.d.ts.map +1 -0
  60. package/dist/rehydrate-from-mutationlog.js +72 -0
  61. package/dist/rehydrate-from-mutationlog.js.map +1 -0
  62. package/dist/schema/index.d.ts +60 -0
  63. package/dist/schema/index.d.ts.map +1 -0
  64. package/dist/schema/index.js +66 -0
  65. package/dist/schema/index.js.map +1 -0
  66. package/dist/schema/mutations.d.ts +227 -0
  67. package/dist/schema/mutations.d.ts.map +1 -0
  68. package/dist/schema/mutations.js +68 -0
  69. package/dist/schema/mutations.js.map +1 -0
  70. package/dist/schema/schema-helpers.d.ts +4 -0
  71. package/dist/schema/schema-helpers.d.ts.map +1 -0
  72. package/dist/schema/schema-helpers.js +30 -0
  73. package/dist/schema/schema-helpers.js.map +1 -0
  74. package/dist/schema/system-tables.d.ts +331 -0
  75. package/dist/schema/system-tables.d.ts.map +1 -0
  76. package/dist/schema/system-tables.js +46 -0
  77. package/dist/schema/system-tables.js.map +1 -0
  78. package/dist/schema/table-def.d.ts +135 -0
  79. package/dist/schema/table-def.d.ts.map +1 -0
  80. package/dist/schema/table-def.js +70 -0
  81. package/dist/schema/table-def.js.map +1 -0
  82. package/dist/schema-management/common.d.ts +13 -0
  83. package/dist/schema-management/common.d.ts.map +1 -0
  84. package/dist/schema-management/common.js +25 -0
  85. package/dist/schema-management/common.js.map +1 -0
  86. package/dist/schema-management/migrations.d.ts +23 -0
  87. package/dist/schema-management/migrations.d.ts.map +1 -0
  88. package/dist/schema-management/migrations.js +116 -0
  89. package/dist/schema-management/migrations.js.map +1 -0
  90. package/dist/schema-management/validate-mutation-defs.d.ts +8 -0
  91. package/dist/schema-management/validate-mutation-defs.d.ts.map +1 -0
  92. package/dist/schema-management/validate-mutation-defs.js +39 -0
  93. package/dist/schema-management/validate-mutation-defs.js.map +1 -0
  94. package/dist/sql-queries/index.d.ts +4 -0
  95. package/dist/sql-queries/index.d.ts.map +1 -0
  96. package/dist/sql-queries/index.js +4 -0
  97. package/dist/sql-queries/index.js.map +1 -0
  98. package/dist/sql-queries/misc.d.ts +2 -0
  99. package/dist/sql-queries/misc.d.ts.map +1 -0
  100. package/dist/sql-queries/misc.js +2 -0
  101. package/dist/sql-queries/misc.js.map +1 -0
  102. package/dist/sql-queries/sql-queries.d.ts +72 -0
  103. package/dist/sql-queries/sql-queries.d.ts.map +1 -0
  104. package/dist/sql-queries/sql-queries.js +191 -0
  105. package/dist/sql-queries/sql-queries.js.map +1 -0
  106. package/dist/sql-queries/sql-query-builder.d.ts +47 -0
  107. package/dist/sql-queries/sql-query-builder.d.ts.map +1 -0
  108. package/dist/sql-queries/sql-query-builder.js +60 -0
  109. package/dist/sql-queries/sql-query-builder.js.map +1 -0
  110. package/dist/sql-queries/types.d.ts +50 -0
  111. package/dist/sql-queries/types.d.ts.map +1 -0
  112. package/dist/sql-queries/types.js +5 -0
  113. package/dist/sql-queries/types.js.map +1 -0
  114. package/dist/sync/index.d.ts +2 -0
  115. package/dist/sync/index.d.ts.map +1 -0
  116. package/dist/sync/index.js +2 -0
  117. package/dist/sync/index.js.map +1 -0
  118. package/dist/sync/next/compact-events.d.ts +15 -0
  119. package/dist/sync/next/compact-events.d.ts.map +1 -0
  120. package/dist/sync/next/compact-events.js +176 -0
  121. package/dist/sync/next/compact-events.js.map +1 -0
  122. package/dist/sync/next/facts.d.ts +37 -0
  123. package/dist/sync/next/facts.d.ts.map +1 -0
  124. package/dist/sync/next/facts.js +156 -0
  125. package/dist/sync/next/facts.js.map +1 -0
  126. package/dist/sync/next/graphology.d.ts +8 -0
  127. package/dist/sync/next/graphology.d.ts.map +1 -0
  128. package/dist/sync/next/graphology.js +36 -0
  129. package/dist/sync/next/graphology.js.map +1 -0
  130. package/dist/sync/next/graphology_.d.ts +3 -0
  131. package/dist/sync/next/graphology_.d.ts.map +1 -0
  132. package/dist/sync/next/graphology_.js +3 -0
  133. package/dist/sync/next/graphology_.js.map +1 -0
  134. package/dist/sync/next/history-dag.d.ts +30 -0
  135. package/dist/sync/next/history-dag.d.ts.map +1 -0
  136. package/dist/sync/next/history-dag.js +69 -0
  137. package/dist/sync/next/history-dag.js.map +1 -0
  138. package/dist/sync/next/mod.d.ts +5 -0
  139. package/dist/sync/next/mod.d.ts.map +1 -0
  140. package/dist/sync/next/mod.js +5 -0
  141. package/dist/sync/next/mod.js.map +1 -0
  142. package/dist/sync/next/rebase-events.d.ts +27 -0
  143. package/dist/sync/next/rebase-events.d.ts.map +1 -0
  144. package/dist/sync/next/rebase-events.js +41 -0
  145. package/dist/sync/next/rebase-events.js.map +1 -0
  146. package/dist/sync/next/test/compact-events.calculator.test.d.ts +2 -0
  147. package/dist/sync/next/test/compact-events.calculator.test.d.ts.map +1 -0
  148. package/dist/sync/next/test/compact-events.calculator.test.js +101 -0
  149. package/dist/sync/next/test/compact-events.calculator.test.js.map +1 -0
  150. package/dist/sync/next/test/compact-events.test.d.ts +2 -0
  151. package/dist/sync/next/test/compact-events.test.d.ts.map +1 -0
  152. package/dist/sync/next/test/compact-events.test.js +201 -0
  153. package/dist/sync/next/test/compact-events.test.js.map +1 -0
  154. package/dist/sync/next/test/mod.d.ts +2 -0
  155. package/dist/sync/next/test/mod.d.ts.map +1 -0
  156. package/dist/sync/next/test/mod.js +2 -0
  157. package/dist/sync/next/test/mod.js.map +1 -0
  158. package/dist/sync/next/test/mutation-fixtures.d.ts +73 -0
  159. package/dist/sync/next/test/mutation-fixtures.d.ts.map +1 -0
  160. package/dist/sync/next/test/mutation-fixtures.js +161 -0
  161. package/dist/sync/next/test/mutation-fixtures.js.map +1 -0
  162. package/dist/sync/sync.d.ts +45 -0
  163. package/dist/sync/sync.d.ts.map +1 -0
  164. package/dist/sync/sync.js +12 -0
  165. package/dist/sync/sync.js.map +1 -0
  166. package/dist/util.d.ts +25 -0
  167. package/dist/util.d.ts.map +1 -0
  168. package/dist/util.js +38 -0
  169. package/dist/util.js.map +1 -0
  170. package/dist/version.d.ts +10 -0
  171. package/dist/version.d.ts.map +1 -0
  172. package/dist/version.js +12 -0
  173. package/dist/version.js.map +1 -0
  174. package/package.json +61 -0
  175. package/src/__tests__/fixture.ts +23 -0
  176. package/src/adapter-types.ts +216 -0
  177. package/src/ambient.d.ts +3 -0
  178. package/src/bounded-collections.ts +121 -0
  179. package/src/debug-info.ts +76 -0
  180. package/src/derived-mutations.test.ts +101 -0
  181. package/src/derived-mutations.ts +170 -0
  182. package/src/devtools/devtools-bridge.ts +13 -0
  183. package/src/devtools/devtools-messages.ts +247 -0
  184. package/src/devtools/devtools-window-message.ts +27 -0
  185. package/src/devtools/index.ts +49 -0
  186. package/src/index.ts +20 -0
  187. package/src/init-singleton-tables.ts +24 -0
  188. package/src/mutation.ts +69 -0
  189. package/src/query-info.ts +104 -0
  190. package/src/rehydrate-from-mutationlog.ts +131 -0
  191. package/src/schema/index.ts +144 -0
  192. package/src/schema/mutations.ts +313 -0
  193. package/src/schema/schema-helpers.ts +49 -0
  194. package/src/schema/system-tables.ts +84 -0
  195. package/src/schema/table-def.ts +312 -0
  196. package/src/schema-management/common.ts +44 -0
  197. package/src/schema-management/migrations.ts +188 -0
  198. package/src/schema-management/validate-mutation-defs.ts +63 -0
  199. package/src/sql-queries/index.ts +3 -0
  200. package/src/sql-queries/misc.ts +2 -0
  201. package/src/sql-queries/sql-queries.ts +359 -0
  202. package/src/sql-queries/sql-query-builder.ts +135 -0
  203. package/src/sql-queries/types.ts +97 -0
  204. package/src/sync/index.ts +1 -0
  205. package/src/sync/next/ambient.d.ts +3 -0
  206. package/src/sync/next/compact-events.ts +218 -0
  207. package/src/sync/next/facts.ts +229 -0
  208. package/src/sync/next/graphology.ts +49 -0
  209. package/src/sync/next/graphology_.ts +2 -0
  210. package/src/sync/next/history-dag.ts +109 -0
  211. package/src/sync/next/mod.ts +4 -0
  212. package/src/sync/next/rebase-events.ts +97 -0
  213. package/src/sync/next/test/compact-events.calculator.test.ts +121 -0
  214. package/src/sync/next/test/compact-events.test.ts +232 -0
  215. package/src/sync/next/test/mod.ts +1 -0
  216. package/src/sync/next/test/mutation-fixtures.ts +230 -0
  217. package/src/sync/sync.ts +46 -0
  218. package/src/util.ts +56 -0
  219. package/src/version.ts +13 -0
  220. package/tsconfig.json +11 -0
@@ -0,0 +1,73 @@
1
+ import type { MutationDef } from '../../../schema/mutations.js';
2
+ import type { HistoryDagNode } from '../history-dag.js';
3
+ /** Used for conflict detection and event history compaction */
4
+ export declare const facts: {
5
+ todoExists: (id: string) => string;
6
+ todoIsWriteable: (id: string, writeable: boolean) => [string, boolean];
7
+ todoCompleted: (id: string, completed: boolean) => [string, boolean];
8
+ todoTextUpdated: (id: string) => string;
9
+ inputValue: (id: string) => string;
10
+ };
11
+ export declare const mutations: {
12
+ createTodo: MutationDef<"createTodo", {
13
+ readonly text: string;
14
+ readonly id: string;
15
+ }, {
16
+ readonly text: string;
17
+ readonly id: string;
18
+ }>;
19
+ upsertTodo: MutationDef<"upsertTodo", {
20
+ readonly id: string;
21
+ readonly text?: string | undefined;
22
+ }, {
23
+ readonly text?: string | undefined;
24
+ readonly id: string;
25
+ }>;
26
+ completeTodo: MutationDef<"completeTodo", {
27
+ readonly id: string;
28
+ }, {
29
+ readonly id: string;
30
+ }>;
31
+ uncompleteTodo: MutationDef<"uncompleteTodo", {
32
+ readonly id: string;
33
+ }, {
34
+ readonly id: string;
35
+ }>;
36
+ completeTodos: MutationDef<"completeTodos", {
37
+ readonly ids: readonly string[];
38
+ }, {
39
+ readonly ids: readonly string[];
40
+ }>;
41
+ toggleTodo: MutationDef<"toggleTodo", {
42
+ readonly id: string;
43
+ }, {
44
+ readonly id: string;
45
+ }>;
46
+ setReadonlyTodo: MutationDef<"setReadonlyTodo", {
47
+ readonly id: string;
48
+ readonly readonly: boolean;
49
+ }, {
50
+ readonly id: string;
51
+ readonly readonly: boolean;
52
+ }>;
53
+ setTextTodo: MutationDef<"setTextTodo", {
54
+ readonly text: string;
55
+ readonly id: string;
56
+ }, {
57
+ readonly text: string;
58
+ readonly id: string;
59
+ }>;
60
+ setInputValue: MutationDef<"setInputValue", {
61
+ readonly text: string;
62
+ readonly id: string;
63
+ }, {
64
+ readonly text: string;
65
+ readonly id: string;
66
+ }>;
67
+ };
68
+ export type PartialEvent = {
69
+ mutation: string;
70
+ args: any;
71
+ };
72
+ export declare const toEventNodes: (partialEvents: PartialEvent[], mutationDefs: Record<string, MutationDef.Any>) => HistoryDagNode[];
73
+ //# sourceMappingURL=mutation-fixtures.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mutation-fixtures.d.ts","sourceRoot":"","sources":["../../../../src/sync/next/test/mutation-fixtures.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAG/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAGvD,+DAA+D;AAC/D,eAAO,MAAM,KAAK;qBACC,MAAM;0BACD,MAAM,aAAa,OAAO;wBAC5B,MAAM,aAAa,OAAO;0BACxB,MAAM;qBACX,MAAM;CACvB,CAAA;AAEF,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+GrB,CAAA;AAED,MAAM,MAAM,YAAY,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,GAAG,CAAA;CAAE,CAAA;AAE1D,eAAO,MAAM,YAAY,kBACR,YAAY,EAAE,gBACf,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,CAAC,KAC5C,cAAc,EAkFhB,CAAA"}
@@ -0,0 +1,161 @@
1
+ import { Schema } from '@livestore/utils/effect';
2
+ import { ROOT_ID } from '../../../adapter-types.js';
3
+ import { defineFacts, defineMutation } from '../../../schema/mutations.js';
4
+ import { factsSnapshotForDag, getFactsGroupForMutationArgs } from '../facts.js';
5
+ import { historyDagFromNodes, rootEventNode } from '../history-dag.js';
6
+ /** Used for conflict detection and event history compaction */
7
+ export const facts = defineFacts({
8
+ todoExists: (id) => `todo-exists-${id}`,
9
+ todoIsWriteable: (id, writeable) => [`todo-is-writeable-${id}`, writeable],
10
+ todoCompleted: (id, completed) => [`todo-completed-${id}`, completed],
11
+ todoTextUpdated: (id) => `todo-text-updated-${id}`,
12
+ inputValue: (id) => `input-value-${id}`,
13
+ });
14
+ export const mutations = {
15
+ createTodo: defineMutation('createTodo', Schema.Struct({ id: Schema.String, text: Schema.String }), 'INSERT INTO todos (id, text) VALUES ($id, $text)', {
16
+ facts: ({ id }) => ({
17
+ modify: {
18
+ set: [facts.todoExists(id), facts.todoIsWriteable(id, true), facts.todoCompleted(id, false)],
19
+ },
20
+ }),
21
+ }),
22
+ upsertTodo: defineMutation('upsertTodo', Schema.Struct({ id: Schema.String, text: Schema.optional(Schema.String) }), 'INSERT INTO todos (id, text) VALUES ($id, $text) ON CONFLICT (id) DO UPDATE SET text = $text', {
23
+ facts: ({ id }, currentFacts) =>
24
+ // TODO enable an API along the lines of `map.has(key, value)`
25
+ currentFacts.has(facts.todoExists(id)) && currentFacts.get(facts.todoIsWriteable(id, true)[0]) === false
26
+ ? { require: [facts.todoExists(id), facts.todoIsWriteable(id, true)] }
27
+ : { modify: { set: [facts.todoExists(id), facts.todoIsWriteable(id, true), facts.todoTextUpdated(id)] } },
28
+ }),
29
+ completeTodo: defineMutation('completeTodo', Schema.Struct({ id: Schema.String }),
30
+ // consider `RETURNING` to validate before applying facts
31
+ 'UPDATE todos SET completed = true WHERE id = $id', {
32
+ // prewrite assertions from DB
33
+ // enables more concurrency
34
+ // turning database inside out
35
+ // similar to upsert semantics
36
+ facts: ({ id }) => ({
37
+ require: [facts.todoExists(id), facts.todoIsWriteable(id, true)],
38
+ modify: { set: [facts.todoCompleted(id, true)] },
39
+ }),
40
+ }),
41
+ uncompleteTodo: defineMutation('uncompleteTodo', Schema.Struct({ id: Schema.String }), 'UPDATE todos SET completed = false WHERE id = $id', {
42
+ facts: ({ id }) => ({
43
+ require: [facts.todoExists(id), facts.todoIsWriteable(id, true)],
44
+ modify: { set: [facts.todoCompleted(id, false)] },
45
+ }),
46
+ }),
47
+ completeTodos: defineMutation('completeTodos', Schema.Struct({ ids: Schema.Array(Schema.String) }), 'UPDATE todos SET completed = true WHERE id IN ($ids:csv)', {
48
+ facts: ({ ids }) => ({
49
+ require: ids.flatMap((id) => [facts.todoExists(id), facts.todoIsWriteable(id, true)]),
50
+ modify: { set: ids.map((id) => facts.todoCompleted(id, true)) },
51
+ }),
52
+ }),
53
+ toggleTodo: defineMutation('toggleTodo', Schema.Struct({ id: Schema.String }), 'UPDATE todos SET completed = NOT completed WHERE id = $id', {
54
+ facts: ({ id }, currentFacts) => {
55
+ const currentIsCompleted = currentFacts.get(facts.todoCompleted(id, true)[0]) === true;
56
+ return {
57
+ require: [facts.todoExists(id), facts.todoIsWriteable(id, true)],
58
+ modify: {
59
+ // remove: [facts.todoCompleted(id, currentIsCompleted)],
60
+ set: [facts.todoCompleted(id, !currentIsCompleted)],
61
+ },
62
+ };
63
+ },
64
+ }),
65
+ setReadonlyTodo: defineMutation('setReadonlyTodo', Schema.Struct({ id: Schema.String, readonly: Schema.Boolean }), 'UPDATE todos SET readonly = $readonly WHERE id = $id', {
66
+ facts: ({ id, readonly }) => ({
67
+ require: [facts.todoExists(id)],
68
+ modify: { set: [facts.todoIsWriteable(id, !readonly)] },
69
+ }),
70
+ }),
71
+ setTextTodo: defineMutation('setTextTodo', Schema.Struct({ id: Schema.String, text: Schema.String }), 'UPDATE todos SET text = $text WHERE id = $id', {
72
+ facts: ({ id }) => ({
73
+ require: [facts.todoExists(id), facts.todoIsWriteable(id, true)],
74
+ modify: { set: [facts.todoTextUpdated(id)] },
75
+ }),
76
+ }),
77
+ setInputValue: defineMutation('setInputValue', Schema.Struct({ id: Schema.String, text: Schema.String }), 'UPDATE todos SET text = $text WHERE id = $id', {
78
+ localOnly: true,
79
+ facts: ({ id }) => ({ modify: { set: [facts.inputValue(id)] } }),
80
+ }),
81
+ };
82
+ export const toEventNodes = (partialEvents, mutationDefs) => {
83
+ const nodesAcc = [rootEventNode];
84
+ let currentEventId = ROOT_ID;
85
+ const getNextEventId = (mutationDef) => {
86
+ if (mutationDef.options.localOnly) {
87
+ return { global: currentEventId.global, local: currentEventId.local + 1 };
88
+ }
89
+ return { global: currentEventId.global + 1, local: 0 };
90
+ };
91
+ const eventNodes = partialEvents.map((partialEvent) => {
92
+ const mutationDef = mutationDefs[partialEvent.mutation];
93
+ const eventId = getNextEventId(mutationDef);
94
+ currentEventId = eventId;
95
+ const factsSnapshot = factsSnapshotForDag(historyDagFromNodes(nodesAcc, { skipFactsCheck: true }), undefined);
96
+ // console.log('factsSnapshot', eventId, factsSnapshot)
97
+ // const depRead: MutationEventFactsSnapshot = new Map<string, any>()
98
+ // const factsSnapshotProxy = new Proxy(factsSnapshot, {
99
+ // get: (target, prop) => {
100
+ // if (prop === 'has') {
101
+ // return (key: string) => {
102
+ // depRead.set(key, EMPTY_FACT_VALUE)
103
+ // return target.has(key)
104
+ // }
105
+ // } else if (prop === 'get') {
106
+ // return (key: string) => {
107
+ // depRead.set(key, EMPTY_FACT_VALUE)
108
+ // return target.get(key)
109
+ // }
110
+ // }
111
+ // notYetImplemented(`toEventNodes: ${prop.toString()} is not yet implemented`)
112
+ // },
113
+ // })
114
+ // const factsRes = mutationDef.options.facts?.(partialEvent.args, factsSnapshotProxy)
115
+ // console.log('factsRes', factsRes?.modify, factsRes?.require)
116
+ // const iterableToMap = (iterable: Iterable<MutationEventFactInput>) => {
117
+ // const map = new Map()
118
+ // for (const item of iterable) {
119
+ // if (typeof item === 'string') {
120
+ // map.set(item, EMPTY_FACT_VALUE)
121
+ // } else {
122
+ // map.set(item[0], item[1])
123
+ // }
124
+ // }
125
+ // return map
126
+ // }
127
+ // const facts = {
128
+ // modifyAdd: factsRes?.modify.add ? iterableToMap(factsRes.modify.add) : new Map(),
129
+ // modifyRemove: factsRes?.modify.remove ? iterableToMap(factsRes.modify.remove) : new Map(),
130
+ // depRequire: factsRes?.require ? iterableToMap(factsRes.require) : new Map(),
131
+ // depRead,
132
+ // } satisfies MutationEventFactsGroup
133
+ // applyFactGroup(facts, factsSnapshot)
134
+ const facts = getFactsGroupForMutationArgs({
135
+ factsCallback: mutationDef.options.facts,
136
+ args: partialEvent.args,
137
+ currentFacts: factsSnapshot,
138
+ });
139
+ const node = {
140
+ id: eventId,
141
+ parentId: getParentId(eventId),
142
+ mutation: partialEvent.mutation,
143
+ args: partialEvent.args,
144
+ factsGroup: facts,
145
+ };
146
+ nodesAcc.push(node);
147
+ return node;
148
+ });
149
+ eventNodes.unshift(rootEventNode);
150
+ // console.log('eventNodes', eventNodes)
151
+ return eventNodes;
152
+ };
153
+ const getParentId = (eventId) => {
154
+ const globalParentId = eventId.global;
155
+ const localParentId = eventId.local - 1;
156
+ if (localParentId < 0) {
157
+ return { global: globalParentId - 1, local: 0 };
158
+ }
159
+ return { global: globalParentId, local: localParentId };
160
+ };
161
+ //# sourceMappingURL=mutation-fixtures.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mutation-fixtures.js","sourceRoot":"","sources":["../../../../src/sync/next/test/mutation-fixtures.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEhD,OAAO,EAAgB,OAAO,EAAE,MAAM,2BAA2B,CAAA;AAEjE,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAC1E,OAAO,EAAE,mBAAmB,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAA;AAE/E,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEtE,+DAA+D;AAC/D,MAAM,CAAC,MAAM,KAAK,GAAG,WAAW,CAAC;IAC/B,UAAU,EAAE,CAAC,EAAU,EAAE,EAAE,CAAC,eAAe,EAAE,EAAE;IAC/C,eAAe,EAAE,CAAC,EAAU,EAAE,SAAkB,EAAE,EAAE,CAAC,CAAC,qBAAqB,EAAE,EAAE,EAAE,SAAS,CAAC;IAC3F,aAAa,EAAE,CAAC,EAAU,EAAE,SAAkB,EAAE,EAAE,CAAC,CAAC,kBAAkB,EAAE,EAAE,EAAE,SAAS,CAAC;IACtF,eAAe,EAAE,CAAC,EAAU,EAAE,EAAE,CAAC,qBAAqB,EAAE,EAAE;IAC1D,UAAU,EAAE,CAAC,EAAU,EAAE,EAAE,CAAC,eAAe,EAAE,EAAE;CAChD,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,UAAU,EAAE,cAAc,CACxB,YAAY,EACZ,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,EACzD,kDAAkD,EAClD;QACE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;YAClB,MAAM,EAAE;gBACN,GA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,QAAQ,EAAE,YAAY,CAAC,QAAQ;YAC/B,IAAI,EAAE,YAAY,CAAC,IAAI;YACvB,UAAU,EAAE,KAAK;SACO,CAAA;QAC1B,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACnB,OAAO,IAAI,CAAA;IACb,CAAC,CAAC,CAAA;IAEF,UAAU,CAAC,OAAO,CAAC,aAAsB,CAAC,CAAA;IAE1C,wCAAwC;IAExC,OAAO,UAAU,CAAA;AACnB,CAAC,CAAA;AAED,MAAM,WAAW,GAAG,CAAC,OAAgB,EAAW,EAAE;IAChD,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAA;IACrC,MAAM,aAAa,GAAG,OAAO,CAAC,KAAK,GAAG,CAAC,CAAA;IAEvC,IAAI,aAAa,GAAG,CAAC,EAAE,CAAC;QACtB,OAAO,EAAE,MAAM,EAAE,cAAc,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAA;IACjD,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,aAAa,EAAE,CAAA;AACzD,CAAC,CAAA"}
@@ -0,0 +1,45 @@
1
+ import type { Effect, HttpClient, Option, Stream, SubscriptionRef } from '@livestore/utils/effect';
2
+ import { Schema } from '@livestore/utils/effect';
3
+ import type { EventId } from '../adapter-types.js';
4
+ import type { MutationEvent } from '../schema/mutations.js';
5
+ export interface SyncBackendOptionsBase {
6
+ type: string;
7
+ [key: string]: Schema.JsonValue;
8
+ }
9
+ export type SyncBackend<TSyncMetadata = Schema.JsonValue> = {
10
+ pull: (args: Option.Option<{
11
+ cursor: EventId;
12
+ metadata: Option.Option<TSyncMetadata>;
13
+ }>, options: {
14
+ listenForNew: boolean;
15
+ }) => Stream.Stream<{
16
+ mutationEventEncoded: MutationEvent.AnyEncoded;
17
+ metadata: Option.Option<TSyncMetadata>;
18
+ persisted: boolean;
19
+ }, IsOfflineError | InvalidPullError, HttpClient.HttpClient>;
20
+ push: (mutationEventEncoded: MutationEvent.AnyEncoded, persisted: boolean) => Effect.Effect<{
21
+ metadata: Option.Option<TSyncMetadata>;
22
+ }, IsOfflineError | InvalidPushError, HttpClient.HttpClient>;
23
+ isConnected: SubscriptionRef.SubscriptionRef<boolean>;
24
+ };
25
+ declare const IsOfflineError_base: Schema.TaggedErrorClass<IsOfflineError, "IsOfflineError", {
26
+ readonly _tag: Schema.tag<"IsOfflineError">;
27
+ }>;
28
+ export declare class IsOfflineError extends IsOfflineError_base {
29
+ }
30
+ declare const InvalidPushError_base: Schema.TaggedErrorClass<InvalidPushError, "InvalidPushError", {
31
+ readonly _tag: Schema.tag<"InvalidPushError">;
32
+ } & {
33
+ message: typeof Schema.String;
34
+ }>;
35
+ export declare class InvalidPushError extends InvalidPushError_base {
36
+ }
37
+ declare const InvalidPullError_base: Schema.TaggedErrorClass<InvalidPullError, "InvalidPullError", {
38
+ readonly _tag: Schema.tag<"InvalidPullError">;
39
+ } & {
40
+ message: typeof Schema.String;
41
+ }>;
42
+ export declare class InvalidPullError extends InvalidPullError_base {
43
+ }
44
+ export {};
45
+ //# sourceMappingURL=sync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/sync/sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAClG,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEhD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAE3D,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,CAAA;IACZ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,SAAS,CAAA;CAChC;AAED,MAAM,MAAM,WAAW,CAAC,aAAa,GAAG,MAAM,CAAC,SAAS,IAAI;IAC1D,IAAI,EAAE,CACJ,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC;QAClB,MAAM,EAAE,OAAO,CAAA;QACf,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAA;KACvC,CAAC,EACF,OAAO,EAAE;QAAE,YAAY,EAAE,OAAO,CAAA;KAAE,KAC/B,MAAM,CAAC,MAAM,CAChB;QACE,oBAAoB,EAAE,aAAa,CAAC,UAAU,CAAA;QAC9C,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAA;QACtC,SAAS,EAAE,OAAO,CAAA;KACnB,EACD,cAAc,GAAG,gBAAgB,EACjC,UAAU,CAAC,UAAU,CACtB,CAAA;IAED,IAAI,EAAE,CACJ,oBAAoB,EAAE,aAAa,CAAC,UAAU,EAC9C,SAAS,EAAE,OAAO,KACf,MAAM,CAAC,MAAM,CAChB;QAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAA;KAAE,EAC1C,cAAc,GAAG,gBAAgB,EACjC,UAAU,CAAC,UAAU,CACtB,CAAA;IACD,WAAW,EAAE,eAAe,CAAC,eAAe,CAAC,OAAO,CAAC,CAAA;CACtD,CAAA;;;;AAED,qBAAa,cAAe,SAAQ,mBAA0D;CAAG;;;;;;AACjG,qBAAa,gBAAiB,SAAQ,qBAEpC;CAAG;;;;;;AACL,qBAAa,gBAAiB,SAAQ,qBAEpC;CAAG"}
@@ -0,0 +1,12 @@
1
+ import { Schema } from '@livestore/utils/effect';
2
+ export class IsOfflineError extends Schema.TaggedError()('IsOfflineError', {}) {
3
+ }
4
+ export class InvalidPushError extends Schema.TaggedError()('InvalidPushError', {
5
+ message: Schema.String,
6
+ }) {
7
+ }
8
+ export class InvalidPullError extends Schema.TaggedError()('InvalidPullError', {
9
+ message: Schema.String,
10
+ }) {
11
+ }
12
+ //# sourceMappingURL=sync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync.js","sourceRoot":"","sources":["../../src/sync/sync.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAsChD,MAAM,OAAO,cAAe,SAAQ,MAAM,CAAC,WAAW,EAAkB,CAAC,gBAAgB,EAAE,EAAE,CAAC;CAAG;AACjG,MAAM,OAAO,gBAAiB,SAAQ,MAAM,CAAC,WAAW,EAAoB,CAAC,kBAAkB,EAAE;IAC/F,OAAO,EAAE,MAAM,CAAC,MAAM;CACvB,CAAC;CAAG;AACL,MAAM,OAAO,gBAAiB,SAAQ,MAAM,CAAC,WAAW,EAAoB,CAAC,kBAAkB,EAAE;IAC/F,OAAO,EAAE,MAAM,CAAC,MAAM;CACvB,CAAC;CAAG"}
package/dist/util.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ import type { Brand } from '@livestore/utils/effect';
2
+ import { Schema } from '@livestore/utils/effect';
3
+ export type ParamsObject = Record<string, SqlValue>;
4
+ export type SqlValue = string | number | Uint8Array | null;
5
+ export type Bindable = ReadonlyArray<SqlValue> | ParamsObject;
6
+ export declare const SqlValueSchema: Schema.Union<[typeof Schema.String, typeof Schema.Number, Schema.Schema<Uint8Array, readonly number[], never>, typeof Schema.Null]>;
7
+ export declare const PreparedBindValues: Schema.brand<Schema.Union<[Schema.Array$<Schema.Union<[typeof Schema.String, typeof Schema.Number, Schema.Schema<Uint8Array, readonly number[], never>, typeof Schema.Null]>>, Schema.Record$<typeof Schema.String, Schema.Union<[typeof Schema.String, typeof Schema.Number, Schema.Schema<Uint8Array, readonly number[], never>, typeof Schema.Null]>>]>, "PreparedBindValues">;
8
+ export type PreparedBindValues = Brand.Branded<Bindable, 'PreparedBindValues'>;
9
+ /**
10
+ * This is a tag function for tagged literals.
11
+ * it lets us get syntax highlighting on SQL queries in VSCode, but
12
+ * doesn't do anything at runtime.
13
+ * Code copied from: https://esdiscuss.org/topic/string-identity-template-tag
14
+ */
15
+ export declare const sql: (template: TemplateStringsArray, ...args: unknown[]) => string;
16
+ /**
17
+ * Prepare bind values to send to SQLite
18
+ * Add $ to the beginning of keys; which we use as our interpolation syntax
19
+ * We also strip out any params that aren't used in the statement,
20
+ * because rusqlite doesn't allow unused named params
21
+ * TODO: Search for unused params via proper parsing, not string search
22
+ * TODO: Also make sure that the SQLite binding limit of 1000 is respected
23
+ */
24
+ export declare const prepareBindValues: (values: Bindable, statement: string) => PreparedBindValues;
25
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEhD,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;AACnD,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG,IAAI,CAAA;AAE1D,MAAM,MAAM,QAAQ,GAAG,aAAa,CAAC,QAAQ,CAAC,GAAG,YAAY,CAAA;AAE7D,eAAO,MAAM,cAAc,qIAA6E,CAAA;AAExG,eAAO,MAAM,kBAAkB,mXAGW,CAAA;AAE1C,MAAM,MAAM,kBAAkB,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,oBAAoB,CAAC,CAAA;AAE9E;;;;;GAKG;AACH,eAAO,MAAM,GAAG,aAAc,oBAAoB,WAAW,OAAO,EAAE,KAAG,MASxE,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,WAAY,QAAQ,aAAa,MAAM,KAAG,kBAWvE,CAAA"}
package/dist/util.js ADDED
@@ -0,0 +1,38 @@
1
+ /// <reference lib="es2022" />
2
+ import { Schema } from '@livestore/utils/effect';
3
+ export const SqlValueSchema = Schema.Union(Schema.String, Schema.Number, Schema.Uint8Array, Schema.Null);
4
+ export const PreparedBindValues = Schema.Union(Schema.Array(SqlValueSchema), Schema.Record({ key: Schema.String, value: SqlValueSchema })).pipe(Schema.brand('PreparedBindValues'));
5
+ /**
6
+ * This is a tag function for tagged literals.
7
+ * it lets us get syntax highlighting on SQL queries in VSCode, but
8
+ * doesn't do anything at runtime.
9
+ * Code copied from: https://esdiscuss.org/topic/string-identity-template-tag
10
+ */
11
+ export const sql = (template, ...args) => {
12
+ let str = '';
13
+ for (const [i, arg] of args.entries()) {
14
+ str += template[i] + String(arg);
15
+ }
16
+ // eslint-disable-next-line unicorn/prefer-at
17
+ return str + template[template.length - 1];
18
+ };
19
+ /**
20
+ * Prepare bind values to send to SQLite
21
+ * Add $ to the beginning of keys; which we use as our interpolation syntax
22
+ * We also strip out any params that aren't used in the statement,
23
+ * because rusqlite doesn't allow unused named params
24
+ * TODO: Search for unused params via proper parsing, not string search
25
+ * TODO: Also make sure that the SQLite binding limit of 1000 is respected
26
+ */
27
+ export const prepareBindValues = (values, statement) => {
28
+ if (Array.isArray(values))
29
+ return values;
30
+ const result = {};
31
+ for (const [key, value] of Object.entries(values)) {
32
+ if (statement.includes(key)) {
33
+ result[`$${key}`] = value;
34
+ }
35
+ }
36
+ return result;
37
+ };
38
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAG9B,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAOhD,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;AAExG,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,KAAK,CAC5C,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,EAC5B,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,CAC7D,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC,CAAA;AAI1C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,QAA8B,EAAE,GAAG,IAAe,EAAU,EAAE;IAChF,IAAI,GAAG,GAAG,EAAE,CAAA;IAEZ,KAAK,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;QACtC,GAAG,IAAI,QAAQ,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;IAClC,CAAC;IAED,6CAA6C;IAC7C,OAAO,GAAG,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;AAC5C,CAAC,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,MAAgB,EAAE,SAAiB,EAAsB,EAAE;IAC3F,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QAAE,OAAO,MAAmC,CAAA;IAErE,MAAM,MAAM,GAAiB,EAAE,CAAA;IAC/B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,IAAI,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YAC5B,MAAM,CAAC,IAAI,GAAG,EAAE,CAAC,GAAG,KAAK,CAAA;QAC3B,CAAC;IACH,CAAC;IAED,OAAO,MAA4B,CAAA;AACrC,CAAC,CAAA"}
@@ -0,0 +1,10 @@
1
+ export declare const liveStoreVersion: string;
2
+ /**
3
+ * This version number is incremented whenever the internal storage format changes in a breaking way.
4
+ * Whenever this version changes, LiveStore will start with fresh database files. Old database files are not deleted.
5
+ *
6
+ * While LiveStore is in alpha, this might happen more frequently.
7
+ * In the future, LiveStore will provide a migration path for older database files to avoid the impression of data loss.
8
+ */
9
+ export declare const liveStoreStorageFormatVersion = 2;
10
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,gBAAgB,QAAsB,CAAA;AAEnD;;;;;;GAMG;AACH,eAAO,MAAM,6BAA6B,IAAI,CAAA"}
@@ -0,0 +1,12 @@
1
+ import packageJson from '../package.json' with { type: 'json' };
2
+ // import packageJson from '../package.json' assert { type: 'json' }
3
+ export const liveStoreVersion = packageJson.version;
4
+ /**
5
+ * This version number is incremented whenever the internal storage format changes in a breaking way.
6
+ * Whenever this version changes, LiveStore will start with fresh database files. Old database files are not deleted.
7
+ *
8
+ * While LiveStore is in alpha, this might happen more frequently.
9
+ * In the future, LiveStore will provide a migration path for older database files to avoid the impression of data loss.
10
+ */
11
+ export const liveStoreStorageFormatVersion = 2;
12
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,iBAAiB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AAC/D,oEAAoE;AAEpE,MAAM,CAAC,MAAM,gBAAgB,GAAG,WAAW,CAAC,OAAO,CAAA;AAEnD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,CAAA"}
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@livestore/common",
3
+ "version": "0.0.0-snapshot-909cdd1ac2fd591945c2be2b0f53e14d87f3c9d4",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./dist/index.d.ts",
8
+ "default": "./dist/index.js"
9
+ },
10
+ "./sql-queries": {
11
+ "types": "./dist/sql-queries/index.d.ts",
12
+ "default": "./dist/sql-queries/index.js"
13
+ },
14
+ "./schema": {
15
+ "types": "./dist/schema/index.d.ts",
16
+ "default": "./dist/schema/index.js"
17
+ },
18
+ "./sync/next": {
19
+ "types": "./dist/sync/next/mod.d.ts",
20
+ "default": "./dist/sync/next/mod.js"
21
+ },
22
+ "./sync/next/test": {
23
+ "types": "./dist/sync/next/test/mod.d.ts",
24
+ "default": "./dist/sync/next/test/mod.js"
25
+ }
26
+ },
27
+ "types": "./dist/index.d.ts",
28
+ "typesVersions": {
29
+ "*": {
30
+ "schema": [
31
+ "./dist/schema/index.d.ts"
32
+ ],
33
+ "sql-queries": [
34
+ "./dist/sql-queries/index.d.ts"
35
+ ],
36
+ "sync/next": [
37
+ "./dist/sync/next/mod.d.ts"
38
+ ],
39
+ "sync/next/test": [
40
+ "./dist/sync/next/test/mod.d.ts"
41
+ ]
42
+ }
43
+ },
44
+ "dependencies": {
45
+ "@opentelemetry/api": "^1.9.0",
46
+ "graphology": "0.26.0-alpha1",
47
+ "graphology-dag": "0.4.1",
48
+ "graphology-types": "0.24.7",
49
+ "@livestore/utils": "0.0.0-snapshot-909cdd1ac2fd591945c2be2b0f53e14d87f3c9d4",
50
+ "@livestore/db-schema": "0.0.0-snapshot-909cdd1ac2fd591945c2be2b0f53e14d87f3c9d4"
51
+ },
52
+ "devDependencies": {
53
+ "vitest": "^2.1.4"
54
+ },
55
+ "publishConfig": {
56
+ "access": "public"
57
+ },
58
+ "scripts": {
59
+ "test": "vitest"
60
+ }
61
+ }
@@ -0,0 +1,23 @@
1
+ import { Schema } from '@livestore/utils/effect'
2
+
3
+ import { DbSchema } from '../schema/index.js'
4
+
5
+ export const todos = DbSchema.table(
6
+ 'todos',
7
+ {
8
+ id: DbSchema.text({ primaryKey: true }),
9
+ text: DbSchema.text({ default: '', nullable: false }),
10
+ completed: DbSchema.boolean({ default: false, nullable: false }),
11
+ },
12
+ { deriveMutations: true },
13
+ )
14
+
15
+ const Config = Schema.Struct({
16
+ fontSize: Schema.Number,
17
+ theme: Schema.Literal('light', 'dark'),
18
+ })
19
+
20
+ export const appConfig = DbSchema.table('app_config', DbSchema.json({ schema: Config, nullable: true }), {
21
+ isSingleton: true,
22
+ deriveMutations: true,
23
+ })