@livestore/common 0.0.54-dev.0 → 0.0.54-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/adapter-types.d.ts +8 -0
  3. package/dist/adapter-types.d.ts.map +1 -1
  4. package/dist/adapter-types.js +5 -1
  5. package/dist/adapter-types.js.map +1 -1
  6. package/dist/bounded-collections.d.ts +36 -0
  7. package/dist/bounded-collections.d.ts.map +1 -0
  8. package/dist/bounded-collections.js +98 -0
  9. package/dist/bounded-collections.js.map +1 -0
  10. package/dist/debug-info.d.ts +118 -0
  11. package/dist/debug-info.d.ts.map +1 -0
  12. package/dist/debug-info.js +50 -0
  13. package/dist/debug-info.js.map +1 -0
  14. package/dist/devtools/devtools-messages.d.ts +248 -0
  15. package/dist/devtools/devtools-messages.d.ts.map +1 -0
  16. package/dist/devtools/devtools-messages.js +175 -0
  17. package/dist/devtools/devtools-messages.js.map +1 -0
  18. package/dist/devtools/index copy.d.ts +214 -0
  19. package/dist/devtools/index copy.d.ts.map +1 -0
  20. package/dist/devtools/index copy.js +137 -0
  21. package/dist/devtools/index copy.js.map +1 -0
  22. package/dist/devtools/index.d.ts +1 -136
  23. package/dist/devtools/index.d.ts.map +1 -1
  24. package/dist/devtools/index.js +1 -114
  25. package/dist/devtools/index.js.map +1 -1
  26. package/dist/index.d.ts +2 -0
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +2 -0
  29. package/dist/index.js.map +1 -1
  30. package/dist/schema/index.d.ts +1 -45
  31. package/dist/schema/index.d.ts.map +1 -1
  32. package/dist/schema/index.js +3 -53
  33. package/dist/schema/index.js.map +1 -1
  34. package/dist/util.d.ts +4 -1
  35. package/dist/util.d.ts.map +1 -1
  36. package/dist/util.js +3 -0
  37. package/dist/util.js.map +1 -1
  38. package/package.json +7 -3
  39. package/src/adapter-types.ts +9 -0
  40. package/src/bounded-collections.ts +121 -0
  41. package/src/debug-info.ts +88 -0
  42. package/src/devtools/devtools-messages.ts +213 -0
  43. package/src/devtools/index.ts +1 -146
  44. package/src/index.ts +2 -0
  45. package/src/schema/index.ts +4 -66
  46. package/src/util.ts +10 -2
  47. package/tsconfig.json +1 -0
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Creates a map that has a fixed number of entries.
3
+ * Once hitting the bound, earliest insertions are removed
4
+ */
5
+ export class BoundMap<K, V> {
6
+ #map = new Map<K, V>()
7
+ #sizeLimit: number
8
+
9
+ constructor(sizeLimit: number) {
10
+ this.#sizeLimit = sizeLimit
11
+ }
12
+
13
+ onEvict: ((key: K, value: V) => void) | undefined
14
+
15
+ set = (key: K, value: V) => {
16
+ this.#map.set(key, value)
17
+ // console.log(this.#map.size, this.#sizeLimit);
18
+ if (this.#map.size > this.#sizeLimit) {
19
+ const firstKey = this.#map.keys().next().value
20
+ const deletedValue = this.#map.get(firstKey)!
21
+ this.#map.delete(firstKey)
22
+ if (this.onEvict) {
23
+ this.onEvict(firstKey, deletedValue)
24
+ }
25
+ }
26
+ }
27
+
28
+ get = (key: K): V | undefined => {
29
+ return this.#map.get(key)
30
+ }
31
+
32
+ delete = (key: K) => {
33
+ this.#map.delete(key)
34
+ }
35
+
36
+ keys = () => {
37
+ return this.#map.keys()
38
+ }
39
+ }
40
+
41
+ export class BoundSet<V> {
42
+ #map: BoundMap<V, V>
43
+
44
+ constructor(sizeLimit: number) {
45
+ this.#map = new BoundMap(sizeLimit)
46
+ this.#map.onEvict = this.#onEvict
47
+ }
48
+
49
+ #onEvict = (v: V) => {
50
+ if (this.onEvict) {
51
+ this.onEvict(v)
52
+ }
53
+ }
54
+
55
+ onEvict: ((key: V) => void) | undefined
56
+
57
+ add = (v: V) => {
58
+ this.#map.set(v, v)
59
+ };
60
+
61
+ [Symbol.iterator] = () => {
62
+ return this.#map.keys()
63
+ }
64
+ }
65
+
66
+ export class BoundArray<V> {
67
+ #array: V[] = []
68
+ public sizeLimit: number
69
+
70
+ constructor(sizeLimit: number) {
71
+ this.sizeLimit = sizeLimit
72
+ }
73
+
74
+ static make = <V>(sizeLimit: number, initial: ReadonlyArray<V> = []): BoundArray<V> => {
75
+ const b = new BoundArray<V>(sizeLimit)
76
+ for (const v of initial) {
77
+ b.push(v)
78
+ }
79
+ return b
80
+ }
81
+
82
+ onEvict: ((key: V) => void) | undefined
83
+
84
+ push = (v: V) => {
85
+ this.#array.push(v)
86
+ if (this.#array.length > this.sizeLimit) {
87
+ const first = this.#array.shift()
88
+ if (first && this.onEvict) {
89
+ this.onEvict(first)
90
+ }
91
+ }
92
+ }
93
+
94
+ get = (index: number): V | undefined => {
95
+ return this.#array[index]
96
+ }
97
+
98
+ delete = (index: number) => {
99
+ this.#array.splice(index, 1)
100
+ }
101
+
102
+ get length() {
103
+ return this.#array.length
104
+ }
105
+
106
+ [Symbol.iterator] = (): IterableIterator<V> => {
107
+ return this.#array[Symbol.iterator]()
108
+ }
109
+
110
+ map = <T>(fn: (v: V) => T): T[] => {
111
+ return this.#array.map(fn)
112
+ }
113
+
114
+ clear = () => {
115
+ this.#array = []
116
+ }
117
+
118
+ sort = (fn?: (a: V, b: V) => number) => {
119
+ return this.#array.sort(fn)
120
+ }
121
+ }
@@ -0,0 +1,88 @@
1
+ import { ParseResult, Schema } from '@livestore/utils/effect'
2
+
3
+ import { BoundArray } from './bounded-collections.js'
4
+ import { PreparedBindValues } from './util.js'
5
+
6
+ export type SlowQueryInfo = {
7
+ queryStr: string
8
+ bindValues: PreparedBindValues | undefined
9
+ durationMs: number
10
+ rowsCount: number | undefined
11
+ queriedTables: Set<string>
12
+ startTimePerfNow: DOMHighResTimeStamp
13
+ }
14
+
15
+ export const SlowQueryInfo = Schema.Struct({
16
+ queryStr: Schema.String,
17
+ bindValues: Schema.UndefinedOr(PreparedBindValues),
18
+ durationMs: Schema.Number,
19
+ rowsCount: Schema.UndefinedOr(Schema.Number),
20
+ queriedTables: Schema.ReadonlySet(Schema.String),
21
+ startTimePerfNow: Schema.Number,
22
+ })
23
+
24
+ const BoundArraySchemaFromSelf = <ItemDecoded, ItemEncoded>(_elSchema: Schema.Schema<ItemDecoded, ItemEncoded>) =>
25
+ Schema.declare((_): _ is BoundArray<ItemDecoded> => _ instanceof BoundArray, {
26
+ identifier: `BoundArrayFromSelf`,
27
+ pretty: () => (_) => `BoundArray(${_.length})`,
28
+ arbitrary: () => (fc) => fc.anything() as any,
29
+ equivalence: () => (a, b) => a === b,
30
+ }) as any as Schema.Schema<BoundArray<ItemDecoded>, BoundArray<ItemEncoded>>
31
+
32
+ const BoundArraySchemaFromSelf_ = <A, I, R>(
33
+ item: Schema.Schema<A, I, R>,
34
+ ): Schema.Schema<BoundArray<A>, BoundArray<I>, R> =>
35
+ Schema.declare(
36
+ [item],
37
+ {
38
+ decode: (item) => (input, parseOptions, ast) => {
39
+ if (input instanceof BoundArray) {
40
+ const elements = ParseResult.decodeUnknown(Schema.Array(item))([...input], parseOptions)
41
+ return ParseResult.map(elements, (as): BoundArray<A> => BoundArray.make(input.sizeLimit, as))
42
+ }
43
+ return ParseResult.fail(new ParseResult.Type(ast, input))
44
+ },
45
+ encode: (item) => (input, parseOptions, ast) => {
46
+ if (input instanceof BoundArray) {
47
+ const elements = ParseResult.encodeUnknown(Schema.Array(item))([...input], parseOptions)
48
+ return ParseResult.map(elements, (is): BoundArray<I> => BoundArray.make(input.sizeLimit, is))
49
+ }
50
+ return ParseResult.fail(new ParseResult.Type(ast, input))
51
+ },
52
+ },
53
+ {
54
+ description: `BoundArray<${Schema.format(item)}>`,
55
+ },
56
+ )
57
+
58
+ const BoundArraySchema = <ItemDecoded, ItemEncoded>(elSchema: Schema.Schema<ItemDecoded, ItemEncoded>) =>
59
+ Schema.transform(
60
+ Schema.Struct({
61
+ size: Schema.Number,
62
+ items: Schema.Array(elSchema),
63
+ }),
64
+ BoundArraySchemaFromSelf(elSchema as any as Schema.Schema<ItemDecoded>),
65
+ {
66
+ encode: (_) => ({ size: _.sizeLimit, items: [..._] }),
67
+ decode: (_) => BoundArray.make(_.size, _.items),
68
+ },
69
+ )
70
+
71
+ export const DebugInfo = Schema.Struct({
72
+ slowQueries: BoundArraySchema(SlowQueryInfo),
73
+ queryFrameDuration: Schema.Number,
74
+ queryFrameCount: Schema.Number,
75
+ events: BoundArraySchema(Schema.Tuple(Schema.String, Schema.Any)),
76
+ })
77
+
78
+ // export interface DebugInfo {
79
+ // slowQueries: BoundArray<SlowQueryInfo>
80
+ // queryFrameDuration: number
81
+ // queryFrameCount: number
82
+ // events: BoundArray<[queryStr: string, bindValues: Bindable | undefined]>
83
+ // }
84
+
85
+ export type DebugInfo = typeof DebugInfo.Type
86
+
87
+ export const MutableDebugInfo = Schema.mutable(DebugInfo)
88
+ export type MutableDebugInfo = typeof MutableDebugInfo.Type
@@ -0,0 +1,213 @@
1
+ import { version as pkgVersion } from '@livestore/common/package.json'
2
+ import { Schema } from '@livestore/utils/effect'
3
+ import { type SqliteDsl as __SqliteDsl } from 'effect-db-schema'
4
+
5
+ import { NetworkStatus } from '../adapter-types.js'
6
+ import { DebugInfo } from '../debug-info.js'
7
+ import { mutationEventSchemaEncodedAny } from '../schema/mutations.js'
8
+ import { PreparedBindValues } from '../util.js'
9
+
10
+ const requestId = Schema.String
11
+ const channelId = Schema.String
12
+ const liveStoreVersion = Schema.Literal(pkgVersion)
13
+
14
+ export class SnapshotReq extends Schema.TaggedStruct('LSD.SnapshotReq', {
15
+ liveStoreVersion,
16
+ requestId,
17
+ channelId,
18
+ }) {}
19
+
20
+ export class SnapshotRes extends Schema.TaggedStruct('LSD.SnapshotRes', {
21
+ liveStoreVersion,
22
+ requestId,
23
+ snapshot: Schema.Uint8Array,
24
+ }) {}
25
+
26
+ export class DebugInfoReq extends Schema.TaggedStruct('LSD.DebugInfoReq', {
27
+ liveStoreVersion,
28
+ requestId,
29
+ channelId,
30
+ }) {}
31
+
32
+ export class DebugInfoRes extends Schema.TaggedStruct('LSD.DebugInfoRes', {
33
+ liveStoreVersion,
34
+ requestId,
35
+ debugInfo: DebugInfo,
36
+ }) {}
37
+
38
+ export class DebugInfoResetReq extends Schema.TaggedStruct('LSD.DebugInfoResetReq', {
39
+ liveStoreVersion,
40
+ requestId,
41
+ channelId,
42
+ }) {}
43
+
44
+ export class DebugInfoResetRes extends Schema.TaggedStruct('LSD.DebugInfoResetRes', {
45
+ liveStoreVersion,
46
+ requestId,
47
+ }) {}
48
+
49
+ export class DebugInfoRerunQueryReq extends Schema.TaggedStruct('LSD.DebugInfoRerunQueryReq', {
50
+ liveStoreVersion,
51
+ requestId,
52
+ channelId,
53
+ queryStr: Schema.String,
54
+ bindValues: Schema.UndefinedOr(PreparedBindValues),
55
+ queriedTables: Schema.ReadonlySet(Schema.String),
56
+ }) {}
57
+
58
+ export class DebugInfoRerunQueryRes extends Schema.TaggedStruct('LSD.DebugInfoRerunQueryRes', {
59
+ liveStoreVersion,
60
+ requestId,
61
+ }) {}
62
+
63
+ export class MutationBroadcast extends Schema.TaggedStruct('LSD.MutationBroadcast', {
64
+ liveStoreVersion,
65
+ requestId,
66
+ mutationEventEncoded: mutationEventSchemaEncodedAny,
67
+ persisted: Schema.Boolean,
68
+ }) {}
69
+
70
+ export class MutationLogReq extends Schema.TaggedStruct('LSD.MutationLogReq', {
71
+ liveStoreVersion,
72
+ requestId,
73
+ channelId,
74
+ }) {}
75
+
76
+ export class MutationLogRes extends Schema.TaggedStruct('LSD.MutationLogRes', {
77
+ liveStoreVersion,
78
+ requestId,
79
+ mutationLog: Schema.Uint8Array,
80
+ }) {}
81
+
82
+ export class SignalsSubscribe extends Schema.TaggedStruct('LSD.SignalsSubscribe', {
83
+ liveStoreVersion,
84
+ requestId,
85
+ channelId,
86
+ includeResults: Schema.Boolean,
87
+ }) {}
88
+
89
+ export class SignalsUnsubscribe extends Schema.TaggedStruct('LSD.SignalsUnsubscribe', {
90
+ liveStoreVersion,
91
+ requestId,
92
+ channelId,
93
+ }) {}
94
+
95
+ export class SignalsRes extends Schema.TaggedStruct('LSD.SignalsRes', {
96
+ liveStoreVersion,
97
+ requestId,
98
+ signals: Schema.Any,
99
+ }) {}
100
+
101
+ export class LiveQueriesSubscribe extends Schema.TaggedStruct('LSD.LiveQueriesSubscribe', {
102
+ liveStoreVersion,
103
+ requestId,
104
+ channelId,
105
+ }) {}
106
+
107
+ export class LiveQueriesUnsubscribe extends Schema.TaggedStruct('LSD.LiveQueriesUnsubscribe', {
108
+ liveStoreVersion,
109
+ requestId,
110
+ channelId,
111
+ }) {}
112
+
113
+ export class SerializedLiveQuery extends Schema.Struct({
114
+ _tag: Schema.Literal('js', 'sql', 'graphql'),
115
+ id: Schema.Number,
116
+ label: Schema.String,
117
+ runs: Schema.Number,
118
+ executionTimes: Schema.Array(Schema.Number),
119
+ lastestResult: Schema.Any,
120
+ activeSubscriptions: Schema.Array(
121
+ Schema.Struct({ frames: Schema.Array(Schema.Struct({ name: Schema.String, filePath: Schema.String })) }),
122
+ ),
123
+ }) {}
124
+
125
+ export class LiveQueriesRes extends Schema.TaggedStruct('LSD.LiveQueriesRes', {
126
+ liveStoreVersion,
127
+ requestId,
128
+ liveQueries: Schema.Array(SerializedLiveQuery),
129
+ }) {}
130
+
131
+ export class ResetAllDataReq extends Schema.TaggedStruct('LSD.ResetAllDataReq', {
132
+ liveStoreVersion,
133
+ requestId,
134
+ channelId,
135
+ mode: Schema.Literal('all-data', 'only-app-db'),
136
+ }) {}
137
+
138
+ export class ResetAllDataRes extends Schema.TaggedStruct('LSD.ResetAllDataRes', {
139
+ liveStoreVersion,
140
+ requestId,
141
+ }) {}
142
+
143
+ export class NetworkStatusBroadcast extends Schema.TaggedStruct('LSD.NetworkStatusBroadcast', {
144
+ liveStoreVersion,
145
+ channelId,
146
+ networkStatus: NetworkStatus,
147
+ }) {}
148
+
149
+ export class DevtoolsReadyBroadcast extends Schema.TaggedStruct('LSD.DevtoolsReadyBroadcast', {
150
+ liveStoreVersion,
151
+ }) {}
152
+
153
+ export class DevtoolsConnected extends Schema.TaggedStruct('LSD.DevtoolsConnected', {
154
+ liveStoreVersion,
155
+ channelId,
156
+ }) {}
157
+
158
+ export class AppHostReadyBroadcast extends Schema.TaggedStruct('LSD.AppHostReadyBroadcast', {
159
+ liveStoreVersion,
160
+ channelId,
161
+ }) {}
162
+
163
+ export class Disconnect extends Schema.TaggedStruct('LSD.Disconnect', {
164
+ liveStoreVersion,
165
+ requestId,
166
+ channelId,
167
+ }) {}
168
+
169
+ // export class SchemaChanged extends Schema.TaggedStruct('LSD.SchemaChanged', {
170
+ // requestId,
171
+ // }) {}
172
+
173
+ export const MessageToAppHost = Schema.Union(
174
+ SnapshotReq,
175
+ MutationLogReq,
176
+ DebugInfoReq,
177
+ DebugInfoResetReq,
178
+ DebugInfoRerunQueryReq,
179
+ SignalsSubscribe,
180
+ SignalsUnsubscribe,
181
+ LiveQueriesSubscribe,
182
+ LiveQueriesUnsubscribe,
183
+ ResetAllDataReq,
184
+ DevtoolsReadyBroadcast,
185
+ Disconnect,
186
+ DevtoolsConnected,
187
+ )
188
+
189
+ export type MessageToAppHost = typeof MessageToAppHost.Type
190
+
191
+ export const MessageFromAppHost = Schema.Union(
192
+ SnapshotRes,
193
+ MutationLogRes,
194
+ DebugInfoRes,
195
+ DebugInfoResetRes,
196
+ DebugInfoRerunQueryRes,
197
+ SignalsRes,
198
+ LiveQueriesRes,
199
+ ResetAllDataRes,
200
+ Disconnect,
201
+ // SchemaChanged,
202
+ MutationBroadcast,
203
+ AppHostReadyBroadcast,
204
+ NetworkStatusBroadcast,
205
+ )
206
+
207
+ export type MessageFromAppHost = typeof MessageFromAppHost.Type
208
+
209
+ // TODO make specific over app key
210
+ export const makeBroadcastChannels = () => ({
211
+ fromAppHost: new BroadcastChannel(`livestore-devtools-from-app-host`),
212
+ toAppHost: new BroadcastChannel(`livestore-devtools-to-app-host`),
213
+ })
@@ -1,146 +1 @@
1
- import { Schema } from '@livestore/utils/effect'
2
- import { type SqliteDsl as __SqliteDsl } from 'effect-db-schema'
3
-
4
- import { LiveStoreSchemaSchema } from '../schema/index.js'
5
- import { mutationEventSchemaEncodedAny } from '../schema/mutations.js'
6
-
7
- const requestId = Schema.String
8
-
9
- export class SnapshotReq extends Schema.TaggedStruct('LSD.SnapshotReq', {
10
- requestId,
11
- }) {}
12
-
13
- export class SnapshotRes extends Schema.TaggedStruct('LSD.SnapshotRes', {
14
- requestId,
15
- snapshot: Schema.Uint8Array,
16
- }) {}
17
-
18
- export class SerializedSchemaReq extends Schema.TaggedStruct('LSD.SerializedSchemaReq', {
19
- requestId,
20
- }) {}
21
-
22
- export class SerializedSchemaRes extends Schema.TaggedStruct('LSD.SerializedSchemaRes', {
23
- requestId,
24
- schema: LiveStoreSchemaSchema,
25
- }) {}
26
-
27
- export class MutationBroadcast extends Schema.TaggedStruct('LSD.MutationBroadcast', {
28
- requestId,
29
- mutationEventEncoded: mutationEventSchemaEncodedAny,
30
- persisted: Schema.Boolean,
31
- }) {}
32
-
33
- export class MutationLogReq extends Schema.TaggedStruct('LSD.MutationLogReq', {
34
- requestId,
35
- }) {}
36
-
37
- export class MutationLogRes extends Schema.TaggedStruct('LSD.MutationLogRes', {
38
- requestId,
39
- mutationLog: Schema.Uint8Array,
40
- }) {}
41
-
42
- export class SubscribeSignalsReq extends Schema.TaggedStruct('LSD.SubscribeSignalsReq', {
43
- requestId,
44
- includeResults: Schema.Boolean,
45
- }) {}
46
-
47
- export class SubscribeSignalsRes extends Schema.TaggedStruct('LSD.SubscribeSignalsRes', {
48
- requestId,
49
- signals: Schema.Any,
50
- }) {}
51
-
52
- export class SubscribeLiveQueriesReq extends Schema.TaggedStruct('LSD.SubscribeLiveQueriesReq', {
53
- requestId,
54
- }) {}
55
-
56
- export class SerializedLiveQuery extends Schema.Struct({
57
- _tag: Schema.Literal('js', 'sql', 'graphql'),
58
- id: Schema.Number,
59
- label: Schema.String,
60
- runs: Schema.Number,
61
- executionTimes: Schema.Array(Schema.Number),
62
- lastestResult: Schema.Any,
63
- activeSubscriptions: Schema.Array(
64
- Schema.Struct({ frames: Schema.Array(Schema.Struct({ name: Schema.String, filePath: Schema.String })) }),
65
- ),
66
- }) {}
67
-
68
- export class SubscribeLiveQueriesRes extends Schema.TaggedStruct('LSD.SubscribeLiveQueriesRes', {
69
- requestId,
70
- liveQueries: Schema.Array(SerializedLiveQuery),
71
- }) {}
72
-
73
- export class ResetAllDataReq extends Schema.TaggedStruct('LSD.ResetAllDataReq', {
74
- requestId,
75
- mode: Schema.Literal('all-data', 'only-app-db'),
76
- }) {}
77
-
78
- export class ResetAllDataRes extends Schema.TaggedStruct('LSD.ResetAllDataRes', {
79
- requestId,
80
- }) {}
81
-
82
- export class AppHostReadyReq extends Schema.TaggedStruct('LSD.AppHostReadyReq', {
83
- requestId,
84
- }) {}
85
- export class AppHostReadyRes extends Schema.TaggedStruct('LSD.AppHostReadyRes', {
86
- requestId,
87
- }) {}
88
-
89
- export class Disconnect extends Schema.TaggedStruct('LSD.Disconnect', {
90
- requestId,
91
- }) {}
92
-
93
- export class SchemaChanged extends Schema.TaggedStruct('LSD.SchemaChanged', {
94
- requestId,
95
- }) {}
96
-
97
- // export const Message = Schema.Union(
98
- // SnapshotReq,
99
- // SnapshotRes,
100
- // SerializedSchemaReq,
101
- // SerializedSchemaRes,
102
- // MutationBroadcast,
103
- // MutationLogReq,
104
- // MutationLogRes,
105
- // SubscribeSignalsReq,
106
- // SubscribeSignalsRes,
107
- // SubscribeLiveQueriesReq,
108
- // SubscribeLiveQueriesRes,
109
- // ResetAllDataReq,
110
- // ResetAllDataRes,
111
- // Disconnect,
112
- // SchemaChanged,
113
- // AppHostReadyReq,
114
- // AppHostReadyRes,
115
- // )
116
-
117
- // export type Message = typeof Message.Type
118
-
119
- export const MessageToAppHost = Schema.Union(
120
- SnapshotReq,
121
- SerializedSchemaReq,
122
- MutationLogReq,
123
- SubscribeSignalsReq,
124
- SubscribeLiveQueriesReq,
125
- ResetAllDataReq,
126
- AppHostReadyReq,
127
- )
128
-
129
- export type MessageToAppHost = typeof MessageToAppHost.Type
130
-
131
- export const MessageFromAppHost = Schema.Union(
132
- SnapshotRes,
133
- SerializedSchemaRes,
134
- MutationLogRes,
135
- SubscribeSignalsRes,
136
- SubscribeLiveQueriesRes,
137
- ResetAllDataRes,
138
- AppHostReadyRes,
139
- Disconnect,
140
- SchemaChanged,
141
- MutationBroadcast,
142
- )
143
-
144
- export type MessageFromAppHost = typeof MessageFromAppHost.Type
145
-
146
- export const makeBc = () => new BroadcastChannel('livestore-devtools')
1
+ export * from './devtools-messages.js'
package/src/index.ts CHANGED
@@ -9,3 +9,5 @@ export * from './query-info.js'
9
9
  export * from './derived-mutations.js'
10
10
  export * from './sync/index.js'
11
11
  export * as Devtools from './devtools/index.js'
12
+ export * from './debug-info.js'
13
+ export * from './bounded-collections.js'
@@ -1,7 +1,7 @@
1
- import { isReadonlyArray, pick, shouldNeverHappen } from '@livestore/utils'
1
+ import { isReadonlyArray, shouldNeverHappen } from '@livestore/utils'
2
2
  import type { ReadonlyArray } from '@livestore/utils/effect'
3
- import { ReadonlyRecord, Schema } from '@livestore/utils/effect'
4
- import { SqliteAst, SqliteDsl } from 'effect-db-schema'
3
+ import type { SqliteDsl } from 'effect-db-schema'
4
+ import { SqliteAst } from 'effect-db-schema'
5
5
 
6
6
  import type { MigrationOptions } from '../adapter-types.js'
7
7
  import { makeDerivedMutationDefsForTable } from '../derived-mutations.js'
@@ -13,7 +13,7 @@ import {
13
13
  rawSqlMutation,
14
14
  } from './mutations.js'
15
15
  import { systemTables } from './system-tables.js'
16
- import { table, type TableDef, tableHasDerivedMutations } from './table-def.js'
16
+ import { type TableDef, tableHasDerivedMutations } from './table-def.js'
17
17
 
18
18
  export * from './system-tables.js'
19
19
  export * as DbSchema from './table-def.js'
@@ -139,65 +139,3 @@ namespace FromInputSchema {
139
139
  ? { [K in keyof TMutations as TMutations[K]['name']]: TMutations[K] } & { 'livestore.RawSql': RawSqlMutation }
140
140
  : never
141
141
  }
142
-
143
- export const LiveStoreSchemaFromSelf: Schema.Schema<LiveStoreSchema> = Schema.declare(
144
- (_): _ is LiveStoreSchema =>
145
- (_ as any)._DbSchemaType === Symbol.for('livestore.DbSchemaType') &&
146
- (_ as any)._MutationDefMapType === Symbol.for('livestore.MutationDefMapType'),
147
- {
148
- identifier: 'LiveStoreSchemaFromSelf',
149
- pretty: () => (_) => `LiveStoreSchema(hash: ${_.hash})`,
150
- arbitrary: () => (fc) => fc.anything as any,
151
- equivalence: () => (a, b) => a.hash === b.hash,
152
- },
153
- )
154
-
155
- export const TableDefColumnSchema = Schema.Struct({
156
- columnType: Schema.Literal('blob', 'integer', 'text', 'real'),
157
- nullable: Schema.Boolean,
158
- primaryKey: Schema.Boolean,
159
- })
160
-
161
- export const TableDefSqliteSchema = Schema.Struct({
162
- name: Schema.String,
163
- columns: Schema.Record(Schema.String, TableDefColumnSchema),
164
- ast: Schema.Any,
165
- })
166
-
167
- export const TableDefSchema = Schema.Struct({
168
- sqliteDef: TableDefSqliteSchema,
169
- isSingleColumn: Schema.Boolean,
170
- options: Schema.Any,
171
- })
172
-
173
- export const LiveStoreSchemaSchema = Schema.transform(
174
- Schema.Struct({
175
- tables: Schema.Record(Schema.String, TableDefSchema),
176
- // mutations: Schema.Record(Schema.String, MutationDef.AnySchema),
177
- // migrationOptions: Schema.Struct({ strategy: Schema.Literal('hard-reset') }),
178
- }),
179
- LiveStoreSchemaFromSelf,
180
- {
181
- encode: (schema) => ({
182
- tables: ReadonlyRecord.map(Object.fromEntries(schema.tables.entries()), (t) => ({
183
- sqliteDef: {
184
- name: t.sqliteDef.name,
185
- columns: ReadonlyRecord.map(t.sqliteDef.columns, (c) => pick(c!, ['columnType', 'nullable', 'primaryKey'])),
186
- ast: JSON.parse(JSON.stringify(t.sqliteDef.ast)),
187
- },
188
- isSingleColumn: t.isSingleColumn,
189
- options: t.options,
190
- })),
191
- }),
192
- decode: (schema) => {
193
- const tables = ReadonlyRecord.map(schema.tables, (t) => {
194
- const columns = ReadonlyRecord.map(t.sqliteDef.columns, (c) => {
195
- const makeCol = SqliteDsl[c.columnType] as any
196
- return makeCol({ nullable: c.nullable, primaryKey: c.primaryKey })
197
- })
198
- return table(t.sqliteDef.name, columns, t.options)
199
- })
200
- return makeSchema({ tables })
201
- },
202
- },
203
- )
package/src/util.ts CHANGED
@@ -1,11 +1,19 @@
1
1
  /// <reference lib="es2022" />
2
2
 
3
3
  import type { Brand } from '@livestore/utils/effect'
4
+ import { Schema } from '@livestore/utils/effect'
4
5
 
5
6
  export type ParamsObject = Record<string, SqlValue>
6
7
  export type SqlValue = string | number | Uint8Array | null
7
8
 
8
- export type Bindable = SqlValue[] | ParamsObject
9
+ export type Bindable = ReadonlyArray<SqlValue> | ParamsObject
10
+
11
+ export const SqlValueSchema = Schema.Union(Schema.String, Schema.Number, Schema.Uint8Array, Schema.Null)
12
+
13
+ export const PreparedBindValues = Schema.Union(
14
+ Schema.Array(SqlValueSchema),
15
+ Schema.Record(Schema.String, SqlValueSchema),
16
+ ).pipe(Schema.brand('PreparedBindValues'))
9
17
 
10
18
  export type PreparedBindValues = Brand.Branded<Bindable, 'PreparedBindValues'>
11
19
 
@@ -33,7 +41,7 @@ export const sql = (template: TemplateStringsArray, ...args: unknown[]): string
33
41
  /* TODO: Search for unused params via proper parsing, not string search
34
42
  **/
35
43
  export const prepareBindValues = (values: Bindable, statement: string): PreparedBindValues => {
36
- if (Array.isArray(values)) return values as PreparedBindValues
44
+ if (Array.isArray(values)) return values as any as PreparedBindValues
37
45
 
38
46
  const result: ParamsObject = {}
39
47
  for (const [key, value] of Object.entries(values)) {
package/tsconfig.json CHANGED
@@ -3,6 +3,7 @@
3
3
  "compilerOptions": {
4
4
  "outDir": "./dist",
5
5
  "rootDir": "./src",
6
+ "resolveJsonModule": true,
6
7
  "tsBuildInfoFile": "./dist/.tsbuildinfo"
7
8
  },
8
9
  "include": ["./src"],