@livestore/common 0.0.54-dev.0 → 0.0.54-dev.1
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.
- package/dist/.tsbuildinfo +1 -1
- package/dist/adapter-types.d.ts +8 -0
- package/dist/adapter-types.d.ts.map +1 -1
- package/dist/adapter-types.js +5 -1
- package/dist/adapter-types.js.map +1 -1
- package/dist/bounded-collections.d.ts +36 -0
- package/dist/bounded-collections.d.ts.map +1 -0
- package/dist/bounded-collections.js +98 -0
- package/dist/bounded-collections.js.map +1 -0
- package/dist/debug-info.d.ts +118 -0
- package/dist/debug-info.d.ts.map +1 -0
- package/dist/debug-info.js +50 -0
- package/dist/debug-info.js.map +1 -0
- package/dist/devtools/devtools-messages.d.ts +223 -0
- package/dist/devtools/devtools-messages.d.ts.map +1 -0
- package/dist/devtools/devtools-messages.js +148 -0
- package/dist/devtools/devtools-messages.js.map +1 -0
- package/dist/devtools/index copy.d.ts +214 -0
- package/dist/devtools/index copy.d.ts.map +1 -0
- package/dist/devtools/index copy.js +137 -0
- package/dist/devtools/index copy.js.map +1 -0
- package/dist/devtools/index.d.ts +1 -136
- package/dist/devtools/index.d.ts.map +1 -1
- package/dist/devtools/index.js +1 -114
- package/dist/devtools/index.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/schema/index.d.ts +1 -45
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +3 -53
- package/dist/schema/index.js.map +1 -1
- package/dist/util.d.ts +4 -1
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +3 -0
- package/dist/util.js.map +1 -1
- package/package.json +3 -3
- package/src/adapter-types.ts +9 -0
- package/src/bounded-collections.ts +121 -0
- package/src/debug-info.ts +88 -0
- package/src/devtools/devtools-messages.ts +186 -0
- package/src/devtools/index.ts +1 -146
- package/src/index.ts +2 -0
- package/src/schema/index.ts +4 -66
- package/src/util.ts +10 -2
package/dist/devtools/index.js
CHANGED
|
@@ -1,115 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { LiveStoreSchemaSchema } from '../schema/index.js';
|
|
3
|
-
import { mutationEventSchemaEncodedAny } from '../schema/mutations.js';
|
|
4
|
-
const requestId = Schema.String;
|
|
5
|
-
export class SnapshotReq extends Schema.TaggedStruct('LSD.SnapshotReq', {
|
|
6
|
-
requestId,
|
|
7
|
-
}) {
|
|
8
|
-
}
|
|
9
|
-
export class SnapshotRes extends Schema.TaggedStruct('LSD.SnapshotRes', {
|
|
10
|
-
requestId,
|
|
11
|
-
snapshot: Schema.Uint8Array,
|
|
12
|
-
}) {
|
|
13
|
-
}
|
|
14
|
-
export class SerializedSchemaReq extends Schema.TaggedStruct('LSD.SerializedSchemaReq', {
|
|
15
|
-
requestId,
|
|
16
|
-
}) {
|
|
17
|
-
}
|
|
18
|
-
export class SerializedSchemaRes extends Schema.TaggedStruct('LSD.SerializedSchemaRes', {
|
|
19
|
-
requestId,
|
|
20
|
-
schema: LiveStoreSchemaSchema,
|
|
21
|
-
}) {
|
|
22
|
-
}
|
|
23
|
-
export class MutationBroadcast extends Schema.TaggedStruct('LSD.MutationBroadcast', {
|
|
24
|
-
requestId,
|
|
25
|
-
mutationEventEncoded: mutationEventSchemaEncodedAny,
|
|
26
|
-
persisted: Schema.Boolean,
|
|
27
|
-
}) {
|
|
28
|
-
}
|
|
29
|
-
export class MutationLogReq extends Schema.TaggedStruct('LSD.MutationLogReq', {
|
|
30
|
-
requestId,
|
|
31
|
-
}) {
|
|
32
|
-
}
|
|
33
|
-
export class MutationLogRes extends Schema.TaggedStruct('LSD.MutationLogRes', {
|
|
34
|
-
requestId,
|
|
35
|
-
mutationLog: Schema.Uint8Array,
|
|
36
|
-
}) {
|
|
37
|
-
}
|
|
38
|
-
export class SubscribeSignalsReq extends Schema.TaggedStruct('LSD.SubscribeSignalsReq', {
|
|
39
|
-
requestId,
|
|
40
|
-
includeResults: Schema.Boolean,
|
|
41
|
-
}) {
|
|
42
|
-
}
|
|
43
|
-
export class SubscribeSignalsRes extends Schema.TaggedStruct('LSD.SubscribeSignalsRes', {
|
|
44
|
-
requestId,
|
|
45
|
-
signals: Schema.Any,
|
|
46
|
-
}) {
|
|
47
|
-
}
|
|
48
|
-
export class SubscribeLiveQueriesReq extends Schema.TaggedStruct('LSD.SubscribeLiveQueriesReq', {
|
|
49
|
-
requestId,
|
|
50
|
-
}) {
|
|
51
|
-
}
|
|
52
|
-
export class SerializedLiveQuery extends Schema.Struct({
|
|
53
|
-
_tag: Schema.Literal('js', 'sql', 'graphql'),
|
|
54
|
-
id: Schema.Number,
|
|
55
|
-
label: Schema.String,
|
|
56
|
-
runs: Schema.Number,
|
|
57
|
-
executionTimes: Schema.Array(Schema.Number),
|
|
58
|
-
lastestResult: Schema.Any,
|
|
59
|
-
activeSubscriptions: Schema.Array(Schema.Struct({ frames: Schema.Array(Schema.Struct({ name: Schema.String, filePath: Schema.String })) })),
|
|
60
|
-
}) {
|
|
61
|
-
}
|
|
62
|
-
export class SubscribeLiveQueriesRes extends Schema.TaggedStruct('LSD.SubscribeLiveQueriesRes', {
|
|
63
|
-
requestId,
|
|
64
|
-
liveQueries: Schema.Array(SerializedLiveQuery),
|
|
65
|
-
}) {
|
|
66
|
-
}
|
|
67
|
-
export class ResetAllDataReq extends Schema.TaggedStruct('LSD.ResetAllDataReq', {
|
|
68
|
-
requestId,
|
|
69
|
-
mode: Schema.Literal('all-data', 'only-app-db'),
|
|
70
|
-
}) {
|
|
71
|
-
}
|
|
72
|
-
export class ResetAllDataRes extends Schema.TaggedStruct('LSD.ResetAllDataRes', {
|
|
73
|
-
requestId,
|
|
74
|
-
}) {
|
|
75
|
-
}
|
|
76
|
-
export class AppHostReadyReq extends Schema.TaggedStruct('LSD.AppHostReadyReq', {
|
|
77
|
-
requestId,
|
|
78
|
-
}) {
|
|
79
|
-
}
|
|
80
|
-
export class AppHostReadyRes extends Schema.TaggedStruct('LSD.AppHostReadyRes', {
|
|
81
|
-
requestId,
|
|
82
|
-
}) {
|
|
83
|
-
}
|
|
84
|
-
export class Disconnect extends Schema.TaggedStruct('LSD.Disconnect', {
|
|
85
|
-
requestId,
|
|
86
|
-
}) {
|
|
87
|
-
}
|
|
88
|
-
export class SchemaChanged extends Schema.TaggedStruct('LSD.SchemaChanged', {
|
|
89
|
-
requestId,
|
|
90
|
-
}) {
|
|
91
|
-
}
|
|
92
|
-
// export const Message = Schema.Union(
|
|
93
|
-
// SnapshotReq,
|
|
94
|
-
// SnapshotRes,
|
|
95
|
-
// SerializedSchemaReq,
|
|
96
|
-
// SerializedSchemaRes,
|
|
97
|
-
// MutationBroadcast,
|
|
98
|
-
// MutationLogReq,
|
|
99
|
-
// MutationLogRes,
|
|
100
|
-
// SubscribeSignalsReq,
|
|
101
|
-
// SubscribeSignalsRes,
|
|
102
|
-
// SubscribeLiveQueriesReq,
|
|
103
|
-
// SubscribeLiveQueriesRes,
|
|
104
|
-
// ResetAllDataReq,
|
|
105
|
-
// ResetAllDataRes,
|
|
106
|
-
// Disconnect,
|
|
107
|
-
// SchemaChanged,
|
|
108
|
-
// AppHostReadyReq,
|
|
109
|
-
// AppHostReadyRes,
|
|
110
|
-
// )
|
|
111
|
-
// export type Message = typeof Message.Type
|
|
112
|
-
export const MessageToAppHost = Schema.Union(SnapshotReq, SerializedSchemaReq, MutationLogReq, SubscribeSignalsReq, SubscribeLiveQueriesReq, ResetAllDataReq, AppHostReadyReq);
|
|
113
|
-
export const MessageFromAppHost = Schema.Union(SnapshotRes, SerializedSchemaRes, MutationLogRes, SubscribeSignalsRes, SubscribeLiveQueriesRes, ResetAllDataRes, AppHostReadyRes, Disconnect, SchemaChanged, MutationBroadcast);
|
|
114
|
-
export const makeBc = () => new BroadcastChannel('livestore-devtools');
|
|
1
|
+
export * from './devtools-messages.js';
|
|
115
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/devtools/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/devtools/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -9,4 +9,6 @@ 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';
|
|
12
14
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAA;AACzC,cAAc,WAAW,CAAA;AACzB,cAAc,oBAAoB,CAAA;AAClC,cAAc,mCAAmC,CAAA;AACjD,cAAc,eAAe,CAAA;AAC7B,cAAc,4BAA4B,CAAA;AAC1C,cAAc,iCAAiC,CAAA;AAC/C,cAAc,iBAAiB,CAAA;AAC/B,cAAc,wBAAwB,CAAA;AACtC,cAAc,iBAAiB,CAAA;AAC/B,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAA;AACzC,cAAc,WAAW,CAAA;AACzB,cAAc,oBAAoB,CAAA;AAClC,cAAc,mCAAmC,CAAA;AACjD,cAAc,eAAe,CAAA;AAC7B,cAAc,4BAA4B,CAAA;AAC1C,cAAc,iCAAiC,CAAA;AAC/C,cAAc,iBAAiB,CAAA;AAC/B,cAAc,wBAAwB,CAAA;AACtC,cAAc,iBAAiB,CAAA;AAC/B,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA;AAC/C,cAAc,iBAAiB,CAAA;AAC/B,cAAc,0BAA0B,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -9,4 +9,6 @@ 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';
|
|
12
14
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAA;AACzC,cAAc,WAAW,CAAA;AACzB,cAAc,oBAAoB,CAAA;AAClC,cAAc,mCAAmC,CAAA;AACjD,cAAc,eAAe,CAAA;AAC7B,cAAc,4BAA4B,CAAA;AAC1C,cAAc,iCAAiC,CAAA;AAC/C,cAAc,iBAAiB,CAAA;AAC/B,cAAc,wBAAwB,CAAA;AACtC,cAAc,iBAAiB,CAAA;AAC/B,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAA;AACzC,cAAc,WAAW,CAAA;AACzB,cAAc,oBAAoB,CAAA;AAClC,cAAc,mCAAmC,CAAA;AACjD,cAAc,eAAe,CAAA;AAC7B,cAAc,4BAA4B,CAAA;AAC1C,cAAc,iCAAiC,CAAA;AAC/C,cAAc,iBAAiB,CAAA;AAC/B,cAAc,wBAAwB,CAAA;AACtC,cAAc,iBAAiB,CAAA;AAC/B,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA;AAC/C,cAAc,iBAAiB,CAAA;AAC/B,cAAc,0BAA0B,CAAA"}
|
package/dist/schema/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { SqliteDsl } from 'effect-db-schema';
|
|
1
|
+
import type { SqliteDsl } from 'effect-db-schema';
|
|
3
2
|
import type { MigrationOptions } from '../adapter-types.js';
|
|
4
3
|
import { type MutationDef, type MutationDefMap, type MutationDefRecord, type RawSqlMutation } from './mutations.js';
|
|
5
4
|
import { type TableDef } from './table-def.js';
|
|
@@ -55,47 +54,4 @@ declare namespace FromInputSchema {
|
|
|
55
54
|
} : never;
|
|
56
55
|
export {};
|
|
57
56
|
}
|
|
58
|
-
export declare const LiveStoreSchemaFromSelf: Schema.Schema<LiveStoreSchema>;
|
|
59
|
-
export declare const TableDefColumnSchema: Schema.Struct<{
|
|
60
|
-
columnType: Schema.Literal<["blob", "integer", "text", "real"]>;
|
|
61
|
-
nullable: typeof Schema.Boolean;
|
|
62
|
-
primaryKey: typeof Schema.Boolean;
|
|
63
|
-
}>;
|
|
64
|
-
export declare const TableDefSqliteSchema: Schema.Struct<{
|
|
65
|
-
name: typeof Schema.String;
|
|
66
|
-
columns: Schema.Record$<typeof Schema.String, Schema.Struct<{
|
|
67
|
-
columnType: Schema.Literal<["blob", "integer", "text", "real"]>;
|
|
68
|
-
nullable: typeof Schema.Boolean;
|
|
69
|
-
primaryKey: typeof Schema.Boolean;
|
|
70
|
-
}>>;
|
|
71
|
-
ast: typeof Schema.Any;
|
|
72
|
-
}>;
|
|
73
|
-
export declare const TableDefSchema: Schema.Struct<{
|
|
74
|
-
sqliteDef: Schema.Struct<{
|
|
75
|
-
name: typeof Schema.String;
|
|
76
|
-
columns: Schema.Record$<typeof Schema.String, Schema.Struct<{
|
|
77
|
-
columnType: Schema.Literal<["blob", "integer", "text", "real"]>;
|
|
78
|
-
nullable: typeof Schema.Boolean;
|
|
79
|
-
primaryKey: typeof Schema.Boolean;
|
|
80
|
-
}>>;
|
|
81
|
-
ast: typeof Schema.Any;
|
|
82
|
-
}>;
|
|
83
|
-
isSingleColumn: typeof Schema.Boolean;
|
|
84
|
-
options: typeof Schema.Any;
|
|
85
|
-
}>;
|
|
86
|
-
export declare const LiveStoreSchemaSchema: Schema.transform<Schema.Struct<{
|
|
87
|
-
tables: Schema.Record$<typeof Schema.String, Schema.Struct<{
|
|
88
|
-
sqliteDef: Schema.Struct<{
|
|
89
|
-
name: typeof Schema.String;
|
|
90
|
-
columns: Schema.Record$<typeof Schema.String, Schema.Struct<{
|
|
91
|
-
columnType: Schema.Literal<["blob", "integer", "text", "real"]>;
|
|
92
|
-
nullable: typeof Schema.Boolean;
|
|
93
|
-
primaryKey: typeof Schema.Boolean;
|
|
94
|
-
}>>;
|
|
95
|
-
ast: typeof Schema.Any;
|
|
96
|
-
}>;
|
|
97
|
-
isSingleColumn: typeof Schema.Boolean;
|
|
98
|
-
options: typeof Schema.Any;
|
|
99
|
-
}>>;
|
|
100
|
-
}>, Schema.Schema<LiveStoreSchema<SqliteDsl.DbSchema, MutationDefRecord>, LiveStoreSchema<SqliteDsl.DbSchema, MutationDefRecord>, never>>;
|
|
101
57
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/schema/index.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/schema/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAGjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAE3D,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EAEpB,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,KAAK,QAAQ,EAA4B,MAAM,gBAAgB,CAAA;AAExE,cAAc,oBAAoB,CAAA;AAClC,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAA;AAC1C,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAA;AAC9C,cA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teAst, SqliteDsl } from 'effect-db-schema';
|
|
1
|
+
import { isReadonlyArray, shouldNeverHappen } from '@livestore/utils';
|
|
2
|
+
import { SqliteAst } from 'effect-db-schema';
|
|
4
3
|
import { makeDerivedMutationDefsForTable } from '../derived-mutations.js';
|
|
5
4
|
import { rawSqlMutation, } from './mutations.js';
|
|
6
5
|
import { systemTables } from './system-tables.js';
|
|
7
|
-
import {
|
|
6
|
+
import { tableHasDerivedMutations } from './table-def.js';
|
|
8
7
|
export * from './system-tables.js';
|
|
9
8
|
export * as DbSchema from './table-def.js';
|
|
10
9
|
export * as ParseUtils from './parse-utils.js';
|
|
@@ -65,53 +64,4 @@ inputSchema) => {
|
|
|
65
64
|
hash,
|
|
66
65
|
};
|
|
67
66
|
};
|
|
68
|
-
export const LiveStoreSchemaFromSelf = Schema.declare((_) => _._DbSchemaType === Symbol.for('livestore.DbSchemaType') &&
|
|
69
|
-
_._MutationDefMapType === Symbol.for('livestore.MutationDefMapType'), {
|
|
70
|
-
identifier: 'LiveStoreSchemaFromSelf',
|
|
71
|
-
pretty: () => (_) => `LiveStoreSchema(hash: ${_.hash})`,
|
|
72
|
-
arbitrary: () => (fc) => fc.anything,
|
|
73
|
-
equivalence: () => (a, b) => a.hash === b.hash,
|
|
74
|
-
});
|
|
75
|
-
export const TableDefColumnSchema = Schema.Struct({
|
|
76
|
-
columnType: Schema.Literal('blob', 'integer', 'text', 'real'),
|
|
77
|
-
nullable: Schema.Boolean,
|
|
78
|
-
primaryKey: Schema.Boolean,
|
|
79
|
-
});
|
|
80
|
-
export const TableDefSqliteSchema = Schema.Struct({
|
|
81
|
-
name: Schema.String,
|
|
82
|
-
columns: Schema.Record(Schema.String, TableDefColumnSchema),
|
|
83
|
-
ast: Schema.Any,
|
|
84
|
-
});
|
|
85
|
-
export const TableDefSchema = Schema.Struct({
|
|
86
|
-
sqliteDef: TableDefSqliteSchema,
|
|
87
|
-
isSingleColumn: Schema.Boolean,
|
|
88
|
-
options: Schema.Any,
|
|
89
|
-
});
|
|
90
|
-
export const LiveStoreSchemaSchema = Schema.transform(Schema.Struct({
|
|
91
|
-
tables: Schema.Record(Schema.String, TableDefSchema),
|
|
92
|
-
// mutations: Schema.Record(Schema.String, MutationDef.AnySchema),
|
|
93
|
-
// migrationOptions: Schema.Struct({ strategy: Schema.Literal('hard-reset') }),
|
|
94
|
-
}), LiveStoreSchemaFromSelf, {
|
|
95
|
-
encode: (schema) => ({
|
|
96
|
-
tables: ReadonlyRecord.map(Object.fromEntries(schema.tables.entries()), (t) => ({
|
|
97
|
-
sqliteDef: {
|
|
98
|
-
name: t.sqliteDef.name,
|
|
99
|
-
columns: ReadonlyRecord.map(t.sqliteDef.columns, (c) => pick(c, ['columnType', 'nullable', 'primaryKey'])),
|
|
100
|
-
ast: JSON.parse(JSON.stringify(t.sqliteDef.ast)),
|
|
101
|
-
},
|
|
102
|
-
isSingleColumn: t.isSingleColumn,
|
|
103
|
-
options: t.options,
|
|
104
|
-
})),
|
|
105
|
-
}),
|
|
106
|
-
decode: (schema) => {
|
|
107
|
-
const tables = ReadonlyRecord.map(schema.tables, (t) => {
|
|
108
|
-
const columns = ReadonlyRecord.map(t.sqliteDef.columns, (c) => {
|
|
109
|
-
const makeCol = SqliteDsl[c.columnType];
|
|
110
|
-
return makeCol({ nullable: c.nullable, primaryKey: c.primaryKey });
|
|
111
|
-
});
|
|
112
|
-
return table(t.sqliteDef.name, columns, t.options);
|
|
113
|
-
});
|
|
114
|
-
return makeSchema({ tables });
|
|
115
|
-
},
|
|
116
|
-
});
|
|
117
67
|
//# sourceMappingURL=index.js.map
|
package/dist/schema/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/schema/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/schema/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe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AAC,MAAM,CAAC,CAAA;YAC1E,SAAS,CAAC,GAAG,CAAC,mBAAmB,CAAC,MAAM,CAAC,IAAI,EAAE,mBAAmB,CAAC,MAAM,CAAC,CAAA;QAC5E,CAAC;IACH,CAAC;IAED,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC;QAC1B,IAAI,EAAE,UAAU;QAChB,MAAM,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC;KACzD,CAAC,CAAA;IAEF,OAAO;QACL,KAAK,EAAE,qBAAqB;QAC5B,aAAa,EAAE,MAAM,CAAC,GAAG,CAAC,wBAAwB,CAAQ;QAC1D,mBAAmB,EAAE,MAAM,CAAC,GAAG,CAAC,8BAA8B,CAAQ;QACtE,MAAM;QACN,SAAS;QACT,gBAAgB,EAAE,WAAW,CAAC,UAAU,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE;QACtE,IAAI;KACqB,CAAA;AAC7B,CAAC,CAAA"}
|
package/dist/util.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
/// <reference lib="es2022" />
|
|
2
2
|
import type { Brand } from '@livestore/utils/effect';
|
|
3
|
+
import { Schema } from '@livestore/utils/effect';
|
|
3
4
|
export type ParamsObject = Record<string, SqlValue>;
|
|
4
5
|
export type SqlValue = string | number | Uint8Array | null;
|
|
5
|
-
export type Bindable = SqlValue
|
|
6
|
+
export type Bindable = ReadonlyArray<SqlValue> | ParamsObject;
|
|
7
|
+
export declare const SqlValueSchema: Schema.Union<[typeof Schema.String, typeof Schema.Number, Schema.Schema<Uint8Array, readonly number[], never>, typeof Schema.Null]>;
|
|
8
|
+
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">;
|
|
6
9
|
export type PreparedBindValues = Brand.Branded<Bindable, 'PreparedBindValues'>;
|
|
7
10
|
/**
|
|
8
11
|
* This is a tag function for tagged literals.
|
package/dist/util.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;
|
|
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;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,WAAY,QAAQ,aAAa,MAAM,KAAG,kBAWvE,CAAA"}
|
package/dist/util.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
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(Schema.String, SqlValueSchema)).pipe(Schema.brand('PreparedBindValues'));
|
|
2
5
|
/**
|
|
3
6
|
* This is a tag function for tagged literals.
|
|
4
7
|
* it lets us get syntax highlighting on SQL queries in VSCode, but
|
package/dist/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,8BAA8B;
|
|
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,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAC7C,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;;;;;GAKG;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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livestore/common",
|
|
3
|
-
"version": "0.0.54-dev.
|
|
3
|
+
"version": "0.0.54-dev.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@opentelemetry/api": "^1.9.0",
|
|
32
|
-
"@livestore/utils": "0.0.54-dev.
|
|
33
|
-
"effect-db-schema": "0.0.54-dev.
|
|
32
|
+
"@livestore/utils": "0.0.54-dev.1",
|
|
33
|
+
"effect-db-schema": "0.0.54-dev.1"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"vitest": "^1.6.0"
|
package/src/adapter-types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Stream, SubscriptionRef, TRef } from '@livestore/utils/effect'
|
|
2
|
+
import { Schema } from '@livestore/utils/effect'
|
|
2
3
|
import type * as otel from '@opentelemetry/api'
|
|
3
4
|
|
|
4
5
|
import type { LiveStoreSchema, MutationEvent } from './schema/index.js'
|
|
@@ -27,12 +28,20 @@ export type InMemoryDatabase = {
|
|
|
27
28
|
|
|
28
29
|
export type ResetMode = 'all-data' | 'only-app-db'
|
|
29
30
|
|
|
31
|
+
export const NetworkStatus = Schema.Struct({
|
|
32
|
+
isConnected: Schema.Boolean,
|
|
33
|
+
timestampMs: Schema.Number,
|
|
34
|
+
})
|
|
35
|
+
|
|
30
36
|
export type NetworkStatus = {
|
|
31
37
|
isConnected: boolean
|
|
32
38
|
timestampMs: number
|
|
33
39
|
}
|
|
34
40
|
|
|
35
41
|
export type Coordinator = {
|
|
42
|
+
devtools: {
|
|
43
|
+
channelId: string
|
|
44
|
+
}
|
|
36
45
|
hasLock: TRef.TRef<boolean>
|
|
37
46
|
syncMutations: Stream.Stream<MutationEvent.AnyEncoded>
|
|
38
47
|
execute(queryStr: string, bindValues: PreparedBindValues | undefined, span: otel.Span | undefined): Promise<void>
|
|
@@ -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
|