@livestore/livestore 0.0.58-dev.13 → 0.0.58-dev.15
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/effect/LiveStore.d.ts +4 -4
- package/dist/effect/LiveStore.d.ts.map +1 -1
- package/dist/effect/LiveStore.js +1 -1
- package/dist/effect/LiveStore.js.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/reactiveQueries/base-class.d.ts +4 -3
- package/dist/reactiveQueries/base-class.d.ts.map +1 -1
- package/dist/reactiveQueries/base-class.js.map +1 -1
- package/dist/reactiveQueries/computed.d.ts +35 -0
- package/dist/reactiveQueries/computed.d.ts.map +1 -0
- package/dist/reactiveQueries/computed.js +57 -0
- package/dist/reactiveQueries/computed.js.map +1 -0
- package/dist/reactiveQueries/graphql.d.ts +2 -1
- package/dist/reactiveQueries/graphql.d.ts.map +1 -1
- package/dist/reactiveQueries/graphql.js.map +1 -1
- package/dist/reactiveQueries/sql.d.ts +1 -1
- package/dist/reactiveQueries/sql.d.ts.map +1 -1
- package/dist/reactiveQueries/sql.js +1 -1
- package/dist/reactiveQueries/sql.js.map +1 -1
- package/dist/row-query.d.ts.map +1 -1
- package/dist/row-query.js +2 -6
- package/dist/row-query.js.map +1 -1
- package/dist/store/create-store.d.ts +28 -0
- package/dist/store/create-store.d.ts.map +1 -0
- package/dist/store/create-store.js +85 -0
- package/dist/store/create-store.js.map +1 -0
- package/dist/store/devtools.d.ts +19 -0
- package/dist/store/devtools.d.ts.map +1 -0
- package/dist/store/devtools.js +141 -0
- package/dist/store/devtools.js.map +1 -0
- package/dist/store/store-context.d.ts +26 -0
- package/dist/store/store-context.d.ts.map +1 -0
- package/dist/store/store-context.js +6 -0
- package/dist/store/store-context.js.map +1 -0
- package/dist/store/store-types.d.ts +98 -0
- package/dist/store/store-types.d.ts.map +1 -0
- package/dist/store/store-types.js +6 -0
- package/dist/store/store-types.js.map +1 -0
- package/dist/store/store.d.ts +88 -0
- package/dist/store/store.d.ts.map +1 -0
- package/dist/store/store.js +367 -0
- package/dist/store/store.js.map +1 -0
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +8 -8
- package/dist/store.js.map +1 -1
- package/dist/utils/dev.d.ts +1 -0
- package/dist/utils/dev.d.ts.map +1 -1
- package/dist/utils/dev.js +5 -0
- package/dist/utils/dev.js.map +1 -1
- package/dist/utils/tests/fixture.d.ts +6 -6
- package/dist/utils/tests/fixture.d.ts.map +1 -1
- package/dist/utils/tests/fixture.js +3 -4
- package/dist/utils/tests/fixture.js.map +1 -1
- package/dist/utils/tests/otel.d.ts.map +1 -1
- package/dist/utils/tests/otel.js +3 -3
- package/dist/utils/tests/otel.js.map +1 -1
- package/package.json +6 -5
- package/src/ambient.d.ts +3 -1
- package/src/effect/LiveStore.ts +5 -5
- package/src/index.ts +5 -6
- package/src/reactiveQueries/base-class.ts +4 -3
- package/src/reactiveQueries/{js.ts → computed.ts} +3 -3
- package/src/reactiveQueries/graphql.ts +2 -1
- package/src/reactiveQueries/sql.ts +2 -2
- package/src/row-query.ts +3 -7
- package/src/store/create-store.ts +214 -0
- package/src/{store-devtools.ts → store/devtools.ts} +5 -5
- package/src/store/store-types.ts +110 -0
- package/src/{store.ts → store/store.ts} +23 -392
- package/src/utils/dev.ts +6 -0
- package/src/utils/tests/fixture.ts +10 -14
- package/src/utils/tests/otel.ts +4 -4
- package/src/store-context.ts +0 -23
|
@@ -56,7 +56,7 @@ export declare const app: DbSchema.TableDef<DbSchema.SqliteDsl.TableDefinition<"
|
|
|
56
56
|
id: {
|
|
57
57
|
columnType: "text";
|
|
58
58
|
schema: import("effect/Schema").Schema<string, string, never>;
|
|
59
|
-
default: import("effect/Option").
|
|
59
|
+
default: import("effect/Option").Some<"static">;
|
|
60
60
|
nullable: false;
|
|
61
61
|
primaryKey: true;
|
|
62
62
|
};
|
|
@@ -75,7 +75,7 @@ export declare const app: DbSchema.TableDef<DbSchema.SqliteDsl.TableDefinition<"
|
|
|
75
75
|
primaryKey: false;
|
|
76
76
|
};
|
|
77
77
|
}>, false, {
|
|
78
|
-
isSingleton:
|
|
78
|
+
isSingleton: true;
|
|
79
79
|
disableAutomaticIdColumn: false;
|
|
80
80
|
deriveMutations: never;
|
|
81
81
|
isSingleColumn: false;
|
|
@@ -132,7 +132,7 @@ export declare const tables: {
|
|
|
132
132
|
id: {
|
|
133
133
|
columnType: "text";
|
|
134
134
|
schema: import("effect/Schema").Schema<string, string, never>;
|
|
135
|
-
default: import("effect/Option").
|
|
135
|
+
default: import("effect/Option").Some<"static">;
|
|
136
136
|
nullable: false;
|
|
137
137
|
primaryKey: true;
|
|
138
138
|
};
|
|
@@ -151,7 +151,7 @@ export declare const tables: {
|
|
|
151
151
|
primaryKey: false;
|
|
152
152
|
};
|
|
153
153
|
}>, false, {
|
|
154
|
-
isSingleton:
|
|
154
|
+
isSingleton: true;
|
|
155
155
|
disableAutomaticIdColumn: false;
|
|
156
156
|
deriveMutations: never;
|
|
157
157
|
isSingleColumn: false;
|
|
@@ -210,7 +210,7 @@ export declare const schema: FromInputSchema.DeriveSchema<{
|
|
|
210
210
|
id: {
|
|
211
211
|
columnType: "text";
|
|
212
212
|
schema: import("effect/Schema").Schema<string, string, never>;
|
|
213
|
-
default: import("effect/Option").
|
|
213
|
+
default: import("effect/Option").Some<"static">;
|
|
214
214
|
nullable: false;
|
|
215
215
|
primaryKey: true;
|
|
216
216
|
};
|
|
@@ -229,7 +229,7 @@ export declare const schema: FromInputSchema.DeriveSchema<{
|
|
|
229
229
|
primaryKey: false;
|
|
230
230
|
};
|
|
231
231
|
}>, false, {
|
|
232
|
-
isSingleton:
|
|
232
|
+
isSingleton: true;
|
|
233
233
|
disableAutomaticIdColumn: false;
|
|
234
234
|
deriveMutations: never;
|
|
235
235
|
isSingleColumn: false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fixture.d.ts","sourceRoot":"","sources":["../../../src/utils/tests/fixture.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC/D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AACjD,OAAO,
|
|
1
|
+
{"version":3,"file":"fixture.d.ts","sourceRoot":"","sources":["../../../src/utils/tests/fixture.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC/D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AACjD,OAAO,EAAe,QAAQ,EAA0D,MAAM,sBAAsB,CAAA;AACpH,OAAO,EAAE,MAAM,EAAY,MAAM,yBAAyB,CAAA;AAE1D,OAAO,KAAK,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAE/C,MAAM,MAAM,IAAI,GAAG;IACjB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,WAAW,CAAA;AAEnD,MAAM,MAAM,QAAQ,GAAG;IACrB,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAQjB,CAAA;AAED,eAAO,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAQf,CAAA;AAED,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAAiB,CAAA;AACpC,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAyB,CAAA;AAE5C,MAAM,WAAW,aAAc,SAAQ,eAAe,CAAC,YAAY,CAAC;IAAE,MAAM,EAAE,OAAO,MAAM,CAAA;CAAE,CAAC;CAAG;AAEjG,eAAO,MAAM,WAAW,4DAIrB;IACD,UAAU,CAAC,EAAE,IAAI,CAAC,MAAM,CAAA;IACxB,WAAW,CAAC,EAAE,IAAI,CAAC,OAAO,CAAA;IAC1B,wBAAwB,CAAC,EAAE,OAAO,CAAA;CACnC;;;mGAmBG,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createStore, DbSchema, globalReactivityGraph, makeReactivityGraph, makeSchema
|
|
1
|
+
import { createStore, DbSchema, globalReactivityGraph, makeReactivityGraph, makeSchema } from '@livestore/livestore';
|
|
2
2
|
import { Effect, FiberSet } from '@livestore/utils/effect';
|
|
3
3
|
import { makeInMemoryAdapter } from '@livestore/web';
|
|
4
4
|
export const todos = DbSchema.table('todos', {
|
|
@@ -7,10 +7,10 @@ export const todos = DbSchema.table('todos', {
|
|
|
7
7
|
completed: DbSchema.boolean({ default: false, nullable: false }),
|
|
8
8
|
}, { deriveMutations: true, isSingleton: false });
|
|
9
9
|
export const app = DbSchema.table('app', {
|
|
10
|
-
id: DbSchema.text({ primaryKey: true }),
|
|
10
|
+
id: DbSchema.text({ primaryKey: true, default: 'static' }),
|
|
11
11
|
newTodoText: DbSchema.text({ default: '', nullable: true }),
|
|
12
12
|
filter: DbSchema.text({ default: 'all', nullable: false }),
|
|
13
|
-
});
|
|
13
|
+
}, { isSingleton: true });
|
|
14
14
|
export const tables = { todos, app };
|
|
15
15
|
export const schema = makeSchema({ tables });
|
|
16
16
|
export const makeTodoMvc = ({ otelTracer, otelContext, useGlobalReactivityGraph = true, } = {}) => Effect.gen(function* () {
|
|
@@ -19,7 +19,6 @@ export const makeTodoMvc = ({ otelTracer, otelContext, useGlobalReactivityGraph
|
|
|
19
19
|
const store = yield* createStore({
|
|
20
20
|
schema,
|
|
21
21
|
storeId: 'default',
|
|
22
|
-
boot: (db) => db.execute(sql `INSERT OR IGNORE INTO app (id, newTodoText, filter) VALUES ('static', '', 'all');`),
|
|
23
22
|
adapter: makeInMemoryAdapter(),
|
|
24
23
|
reactivityGraph,
|
|
25
24
|
otelOptions: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fixture.js","sourceRoot":"","sources":["../../../src/utils/tests/fixture.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"fixture.js","sourceRoot":"","sources":["../../../src/utils/tests/fixture.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACpH,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAgBpD,MAAM,CAAC,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CACjC,OAAO,EACP;IACE,EAAE,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;IACvC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;IACrD,SAAS,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;CACjE,EACD,EAAE,eAAe,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,CAC9C,CAAA;AAED,MAAM,CAAC,MAAM,GAAG,GAAG,QAAQ,CAAC,KAAK,CAC/B,KAAK,EACL;IACE,EAAE,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;IAC1D,WAAW,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAC3D,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;CAC3D,EACD,EAAE,WAAW,EAAE,IAAI,EAAE,CACtB,CAAA;AAED,MAAM,CAAC,MAAM,MAAM,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,CAAA;AACpC,MAAM,CAAC,MAAM,MAAM,GAAG,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;AAI5C,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,EAC1B,UAAU,EACV,WAAW,EACX,wBAAwB,GAAG,IAAI,MAK7B,EAAE,EAAE,EAAE,CACR,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,eAAe,GAAG,wBAAwB,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,mBAAmB,EAAE,CAAA;IAEhG,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAA;IAEvC,MAAM,KAAK,GAA8B,KAAK,CAAC,CAAC,WAAW,CAAC;QAC1D,MAAM;QACN,OAAO,EAAE,SAAS;QAClB,OAAO,EAAE,mBAAmB,EAAE;QAC9B,eAAe;QACf,WAAW,EAAE;YACX,MAAM,EAAE,UAAU;YAClB,eAAe,EAAE,WAAW;SAC7B;QACD,QAAQ;KACT,CAAC,CAAA;IAEF,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,CAAA;AACnC,CAAC,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otel.d.ts","sourceRoot":"","sources":["../../../src/utils/tests/otel.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,KAAK,EAAE,oBAAoB,EAAgB,MAAM,+BAA+B,CAAA;AAEvF,KAAK,oBAAoB,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,GAAG,CAAC;IAAC,QAAQ,EAAE,oBAAoB,EAAE,CAAA;CAAE,CAAA;AAEhG,eAAO,MAAM,qBAAqB,aACtB,oBAAoB,kBACd,CAAC,UAAU,EAAE,UAAU,KAAK,UAAU,
|
|
1
|
+
{"version":3,"file":"otel.d.ts","sourceRoot":"","sources":["../../../src/utils/tests/otel.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,KAAK,EAAE,oBAAoB,EAAgB,MAAM,+BAA+B,CAAA;AAEvF,KAAK,oBAAoB,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,GAAG,CAAC;IAAC,QAAQ,EAAE,oBAAoB,EAAE,CAAA;CAAE,CAAA;AAEhG,eAAO,MAAM,qBAAqB,aACtB,oBAAoB,kBACd,CAAC,UAAU,EAAE,UAAU,KAAK,UAAU,KACrD,oBAgCF,CAAA"}
|
package/dist/utils/tests/otel.js
CHANGED
|
@@ -10,19 +10,19 @@ export const getSimplifiedRootSpan = (exporter, mapAttributes) => {
|
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
12
|
const rootSpan = spansMap.get(spans.find((_) => _.name === 'test').spanContext().spanId);
|
|
13
|
-
const
|
|
13
|
+
const simplifySpanRec = (span) => omitEmpty({
|
|
14
14
|
_name: span.span.name,
|
|
15
15
|
attributes: mapAttributesfn(span.span.attributes),
|
|
16
16
|
children: span.children
|
|
17
17
|
.filter((_) => _.span.name !== 'createStore')
|
|
18
18
|
// .sort((a, b) => compareHrTime(a.span.startTime, b.span.startTime))
|
|
19
|
-
.map(
|
|
19
|
+
.map(simplifySpanRec),
|
|
20
20
|
});
|
|
21
21
|
// console.dir(
|
|
22
22
|
// spans.map((_) => [_.spanContext().spanId, _.name, _.attributes, _.parentSpanId]),
|
|
23
23
|
// { depth: 10 },
|
|
24
24
|
// )
|
|
25
|
-
return
|
|
25
|
+
return simplifySpanRec(rootSpan);
|
|
26
26
|
};
|
|
27
27
|
// const compareHrTime = (a: [number, number], b: [number, number]) => {
|
|
28
28
|
// if (a[0] !== b[0]) return a[0] - b[0]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otel.js","sourceRoot":"","sources":["../../../src/utils/tests/otel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAMlD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,QAA8B,EAC9B,aAAsD,
|
|
1
|
+
{"version":3,"file":"otel.js","sourceRoot":"","sources":["../../../src/utils/tests/otel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAMlD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,QAA8B,EAC9B,aAAsD,EAChC,EAAE;IACxB,MAAM,KAAK,GAAG,QAAQ,CAAC,gBAAgB,EAAE,CAAA;IACzC,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAqB,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,CAAA;IAEtH,MAAM,eAAe,GAAG,aAAa,IAAI,QAAQ,CAAA;IAEjD,QAAQ,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;QAC9B,MAAM,UAAU,GAAG,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;QACxG,IAAI,UAAU,EAAE,CAAC;YACf,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QACtC,CAAC;IACH,CAAC,CAAC,CAAA;IAGF,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAE,CAAC,WAAW,EAAE,CAAC,MAAM,CAAE,CAAA;IAE1F,MAAM,eAAe,GAAG,CAAC,IAAgB,EAAwB,EAAE,CACjE,SAAS,CAAC;QACR,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI;QACrB,UAAU,EAAE,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC;QACjD,QAAQ,EAAE,IAAI,CAAC,QAAQ;aACpB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,aAAa,CAAC;YAC7C,qEAAqE;aACpE,GAAG,CAAC,eAAe,CAAC;KACxB,CAAC,CAAA;IAEJ,eAAe;IACf,sFAAsF;IACtF,mBAAmB;IACnB,IAAI;IAEJ,OAAO,eAAe,CAAC,QAAQ,CAAC,CAAA;AAClC,CAAC,CAAA;AAED,wEAAwE;AACxE,0CAA0C;AAC1C,uBAAuB;AACvB,IAAI;AAEJ,MAAM,SAAS,GAAG,CAAC,GAAQ,EAAE,EAAE;IAC7B,MAAM,MAAM,GAAQ,EAAE,CAAA;IACtB,KAAK,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;QACtB,IACE,GAAG,CAAC,GAAG,CAAC,KAAK,SAAS;YACtB,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;YACnD,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,EAChC,CAAC;YACD,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAA;QACxB,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livestore/livestore",
|
|
3
|
-
"version": "0.0.58-dev.
|
|
3
|
+
"version": "0.0.58-dev.15",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"sideEffects": false,
|
|
5
6
|
"exports": {
|
|
6
7
|
".": {
|
|
7
8
|
"types": "./dist/index.d.ts",
|
|
@@ -30,9 +31,9 @@
|
|
|
30
31
|
"dependencies": {
|
|
31
32
|
"@graphql-typed-document-node/core": "^3.2.0",
|
|
32
33
|
"@opentelemetry/api": "^1.9.0",
|
|
33
|
-
"@livestore/
|
|
34
|
-
"@livestore/db-schema": "0.0.58-dev.
|
|
35
|
-
"@livestore/
|
|
34
|
+
"@livestore/common": "0.0.58-dev.15",
|
|
35
|
+
"@livestore/db-schema": "0.0.58-dev.15",
|
|
36
|
+
"@livestore/utils": "0.0.58-dev.15"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
39
|
"@opentelemetry/sdk-trace-base": "1.27.0",
|
|
@@ -40,7 +41,7 @@
|
|
|
40
41
|
"typescript": "5.6.3",
|
|
41
42
|
"vite": "5.4.10",
|
|
42
43
|
"vitest": "^2.1.4",
|
|
43
|
-
"@livestore/web": "0.0.58-dev.
|
|
44
|
+
"@livestore/web": "0.0.58-dev.15"
|
|
44
45
|
},
|
|
45
46
|
"peerDependencies": {
|
|
46
47
|
"graphql": "16.x"
|
package/src/ambient.d.ts
CHANGED
package/src/effect/LiveStore.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type { Adapter,
|
|
1
|
+
import type { Adapter, BootStatus, UnexpectedError } from '@livestore/common'
|
|
2
2
|
import type { LiveStoreSchema } from '@livestore/common/schema'
|
|
3
3
|
import type { Cause, Scope } from '@livestore/utils/effect'
|
|
4
4
|
import { Context, Deferred, Duration, Effect, FiberSet, Layer, OtelTracer, pipe } from '@livestore/utils/effect'
|
|
5
5
|
import * as otel from '@opentelemetry/api'
|
|
6
6
|
import type { GraphQLSchema } from 'graphql'
|
|
7
7
|
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import type { LiveStoreContextRunning as LiveStoreContextRunning_ } from '../store-
|
|
8
|
+
import { createStore } from '../store/create-store.js'
|
|
9
|
+
import type { Store } from '../store/store.js'
|
|
10
|
+
import type { BaseGraphQLContext, LiveStoreContextRunning as LiveStoreContextRunning_ } from '../store/store-types.js'
|
|
11
11
|
import type { SynchronousDatabaseWrapper } from '../SynchronousDatabaseWrapper.js'
|
|
12
12
|
|
|
13
13
|
export type LiveStoreContextRunning = LiveStoreContextRunning_
|
|
@@ -35,7 +35,7 @@ export type LiveStoreContextProps<GraphQLContext extends BaseGraphQLContext> = {
|
|
|
35
35
|
schema: Effect.Effect<GraphQLSchema, never, otel.Tracer>
|
|
36
36
|
makeContext: (db: SynchronousDatabaseWrapper, tracer: otel.Tracer, sessionId: string) => GraphQLContext
|
|
37
37
|
}
|
|
38
|
-
boot?: (
|
|
38
|
+
boot?: (store: Store<GraphQLContext, LiveStoreSchema>) => Effect.Effect<void, unknown, otel.Tracer>
|
|
39
39
|
adapter: Adapter
|
|
40
40
|
disableDevtools?: boolean
|
|
41
41
|
onBootStatus?: (status: BootStatus) => void
|
package/src/index.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export { Store
|
|
1
|
+
export { Store } from './store/store.js'
|
|
2
|
+
export { createStore, createStorePromise, type CreateStoreOptions } from './store/create-store.js'
|
|
2
3
|
export type {
|
|
3
4
|
BaseGraphQLContext,
|
|
4
5
|
QueryDebugInfo,
|
|
5
6
|
RefreshReason,
|
|
6
|
-
CreateStoreOptions,
|
|
7
7
|
GraphQLOptions,
|
|
8
8
|
OtelOptions,
|
|
9
|
-
} from './store.js'
|
|
9
|
+
} from './store/store-types.js'
|
|
10
10
|
|
|
11
11
|
export type { LiveStoreContextRunning } from './effect/LiveStore.js'
|
|
12
|
-
export { StoreAbort, StoreInterrupted, type LiveStoreContext } from './store-
|
|
12
|
+
export { StoreAbort, StoreInterrupted, type LiveStoreContext } from './store/store-types.js'
|
|
13
13
|
|
|
14
14
|
export { SynchronousDatabaseWrapper, emptyDebugInfo } from './SynchronousDatabaseWrapper.js'
|
|
15
15
|
|
|
@@ -25,7 +25,7 @@ export type {
|
|
|
25
25
|
Ref,
|
|
26
26
|
Effect,
|
|
27
27
|
} from './reactive.js'
|
|
28
|
-
export { LiveStoreJSQuery, computed } from './reactiveQueries/
|
|
28
|
+
export { LiveStoreJSQuery, computed } from './reactiveQueries/computed.js'
|
|
29
29
|
export { LiveStoreSQLQuery, querySQL } from './reactiveQueries/sql.js'
|
|
30
30
|
export { LiveStoreGraphQLQuery, queryGraphQL } from './reactiveQueries/graphql.js'
|
|
31
31
|
export {
|
|
@@ -45,7 +45,6 @@ export * from '@livestore/common/schema'
|
|
|
45
45
|
export {
|
|
46
46
|
sql,
|
|
47
47
|
SessionIdSymbol,
|
|
48
|
-
type BootDb,
|
|
49
48
|
type BootStatus,
|
|
50
49
|
type SynchronousDatabase,
|
|
51
50
|
type DebugInfo,
|
|
@@ -2,7 +2,8 @@ import type { QueryInfo, QueryInfoNone } from '@livestore/common'
|
|
|
2
2
|
import type * as otel from '@opentelemetry/api'
|
|
3
3
|
|
|
4
4
|
import { type Atom, type GetAtom, ReactiveGraph, throwContextNotSetError, type Thunk } from '../reactive.js'
|
|
5
|
-
import type {
|
|
5
|
+
import type { Store } from '../store/store.js'
|
|
6
|
+
import type { QueryDebugInfo, RefreshReason } from '../store/store-types.js'
|
|
6
7
|
import type { StackInfo } from '../utils/stack-info.js'
|
|
7
8
|
|
|
8
9
|
export type ReactivityGraph = ReactiveGraph<RefreshReason, QueryDebugInfo, QueryContext>
|
|
@@ -28,7 +29,7 @@ export type LiveQueryAny = LiveQuery<any, QueryInfo>
|
|
|
28
29
|
|
|
29
30
|
export interface LiveQuery<TResult, TQueryInfo extends QueryInfo = QueryInfoNone> {
|
|
30
31
|
id: number
|
|
31
|
-
_tag: '
|
|
32
|
+
_tag: 'computed' | 'sql' | 'graphql'
|
|
32
33
|
|
|
33
34
|
/** This should only be used on a type-level and doesn't hold any value during runtime */
|
|
34
35
|
'__result!': TResult
|
|
@@ -64,7 +65,7 @@ export abstract class LiveStoreQueryBase<TResult, TQueryInfo extends QueryInfo>
|
|
|
64
65
|
{
|
|
65
66
|
'__result!'!: TResult
|
|
66
67
|
id = queryIdCounter++
|
|
67
|
-
abstract _tag: '
|
|
68
|
+
abstract _tag: 'computed' | 'sql' | 'graphql'
|
|
68
69
|
|
|
69
70
|
/** Human-readable label for the query for debugging */
|
|
70
71
|
abstract label: string
|
|
@@ -3,7 +3,7 @@ import * as otel from '@opentelemetry/api'
|
|
|
3
3
|
|
|
4
4
|
import { globalReactivityGraph } from '../global-state.js'
|
|
5
5
|
import type { Thunk } from '../reactive.js'
|
|
6
|
-
import type { RefreshReason } from '../store.js'
|
|
6
|
+
import type { RefreshReason } from '../store/store-types.js'
|
|
7
7
|
import { getDurationMsFromSpan } from '../utils/otel.js'
|
|
8
8
|
import type { GetAtomResult, LiveQuery, QueryContext, ReactivityGraph } from './base-class.js'
|
|
9
9
|
import { LiveStoreQueryBase, makeGetAtomResult } from './base-class.js'
|
|
@@ -27,7 +27,7 @@ export class LiveStoreJSQuery<TResult, TQueryInfo extends QueryInfo = QueryInfoN
|
|
|
27
27
|
TResult,
|
|
28
28
|
TQueryInfo
|
|
29
29
|
> {
|
|
30
|
-
_tag: '
|
|
30
|
+
_tag: 'computed' = 'computed'
|
|
31
31
|
|
|
32
32
|
/** A reactive thunk representing the query results */
|
|
33
33
|
results$: Thunk<TResult, QueryContext, RefreshReason>
|
|
@@ -82,7 +82,7 @@ export class LiveStoreJSQuery<TResult, TQueryInfo extends QueryInfo = QueryInfoN
|
|
|
82
82
|
|
|
83
83
|
this.executionTimes.push(durationMs)
|
|
84
84
|
|
|
85
|
-
setDebugInfo({ _tag: '
|
|
85
|
+
setDebugInfo({ _tag: 'computed', label, query: fn.toString(), durationMs })
|
|
86
86
|
|
|
87
87
|
return res
|
|
88
88
|
}),
|
|
@@ -7,7 +7,8 @@ import * as graphql from 'graphql'
|
|
|
7
7
|
|
|
8
8
|
import { globalReactivityGraph } from '../global-state.js'
|
|
9
9
|
import { isThunk, type Thunk } from '../reactive.js'
|
|
10
|
-
import type {
|
|
10
|
+
import type { Store } from '../store/store.js'
|
|
11
|
+
import type { BaseGraphQLContext, RefreshReason } from '../store/store-types.js'
|
|
11
12
|
import { getDurationMsFromSpan } from '../utils/otel.js'
|
|
12
13
|
import type { GetAtomResult, LiveQuery, QueryContext, ReactivityGraph } from './base-class.js'
|
|
13
14
|
import { LiveStoreQueryBase, makeGetAtomResult } from './base-class.js'
|
|
@@ -6,7 +6,7 @@ import * as otel from '@opentelemetry/api'
|
|
|
6
6
|
import { globalReactivityGraph } from '../global-state.js'
|
|
7
7
|
import type { Thunk } from '../reactive.js'
|
|
8
8
|
import { NOT_REFRESHED_YET } from '../reactive.js'
|
|
9
|
-
import type { RefreshReason } from '../store.js'
|
|
9
|
+
import type { RefreshReason } from '../store/store-types.js'
|
|
10
10
|
import { getDurationMsFromSpan } from '../utils/otel.js'
|
|
11
11
|
import type { GetAtomResult, LiveQuery, QueryContext, ReactivityGraph } from './base-class.js'
|
|
12
12
|
import { LiveStoreQueryBase, makeGetAtomResult } from './base-class.js'
|
|
@@ -105,7 +105,7 @@ export class LiveStoreSQLQuery<
|
|
|
105
105
|
const startMs = performance.now()
|
|
106
106
|
const queryString = genQueryString(makeGetAtomResult(get, otelContext ?? ctx.rootOtelContext), ctx)
|
|
107
107
|
const durationMs = performance.now() - startMs
|
|
108
|
-
setDebugInfo({ _tag: '
|
|
108
|
+
setDebugInfo({ _tag: 'computed', label: `${label}:queryString`, query: queryString, durationMs })
|
|
109
109
|
return queryString
|
|
110
110
|
},
|
|
111
111
|
{
|
package/src/row-query.ts
CHANGED
|
@@ -14,9 +14,9 @@ import type {
|
|
|
14
14
|
QueryContext,
|
|
15
15
|
ReactivityGraph,
|
|
16
16
|
} from './reactiveQueries/base-class.js'
|
|
17
|
-
import { computed } from './reactiveQueries/
|
|
17
|
+
import { computed } from './reactiveQueries/computed.js'
|
|
18
18
|
import { LiveStoreSQLQuery } from './reactiveQueries/sql.js'
|
|
19
|
-
import type { Store } from './store.js'
|
|
19
|
+
import type { Store } from './store/store.js'
|
|
20
20
|
|
|
21
21
|
export type RowQueryOptions<TTableDef extends DbSchema.TableDef, TResult = RowResult<TTableDef>> = {
|
|
22
22
|
otelContext?: otel.Context
|
|
@@ -104,11 +104,7 @@ export const rowQuery: MakeRowQuery = <TTableDef extends DbSchema.TableDef>(
|
|
|
104
104
|
}),
|
|
105
105
|
schema: rowSchema.pipe(Schema.Array, Schema.headOrElse()),
|
|
106
106
|
map: options?.map,
|
|
107
|
-
queryInfo: {
|
|
108
|
-
_tag: 'Row',
|
|
109
|
-
table,
|
|
110
|
-
id: id === SessionIdSymbol ? 'sessionId' : (id ?? 'singleton'),
|
|
111
|
-
},
|
|
107
|
+
queryInfo: { _tag: 'Row', table, id: id ?? 'singleton' },
|
|
112
108
|
})
|
|
113
109
|
}
|
|
114
110
|
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Adapter,
|
|
3
|
+
BootStatus,
|
|
4
|
+
ClientSession,
|
|
5
|
+
EventId,
|
|
6
|
+
IntentionalShutdownCause,
|
|
7
|
+
StoreDevtoolsChannel,
|
|
8
|
+
} from '@livestore/common'
|
|
9
|
+
import { UnexpectedError } from '@livestore/common'
|
|
10
|
+
import type { LiveStoreSchema, MutationEvent } from '@livestore/common/schema'
|
|
11
|
+
import { makeNoopTracer } from '@livestore/utils'
|
|
12
|
+
import {
|
|
13
|
+
Cause,
|
|
14
|
+
Deferred,
|
|
15
|
+
Duration,
|
|
16
|
+
Effect,
|
|
17
|
+
Exit,
|
|
18
|
+
FiberSet,
|
|
19
|
+
Layer,
|
|
20
|
+
Logger,
|
|
21
|
+
LogLevel,
|
|
22
|
+
MutableHashMap,
|
|
23
|
+
OtelTracer,
|
|
24
|
+
Queue,
|
|
25
|
+
Runtime,
|
|
26
|
+
Scope,
|
|
27
|
+
} from '@livestore/utils/effect'
|
|
28
|
+
import * as otel from '@opentelemetry/api'
|
|
29
|
+
|
|
30
|
+
import { globalReactivityGraph } from '../global-state.js'
|
|
31
|
+
import type { ReactivityGraph } from '../reactiveQueries/base-class.js'
|
|
32
|
+
import { connectDevtoolsToStore } from './devtools.js'
|
|
33
|
+
import { Store } from './store.js'
|
|
34
|
+
import type { BaseGraphQLContext, GraphQLOptions, OtelOptions } from './store-types.js'
|
|
35
|
+
|
|
36
|
+
export type CreateStoreOptions<TGraphQLContext extends BaseGraphQLContext, TSchema extends LiveStoreSchema> = {
|
|
37
|
+
schema: TSchema
|
|
38
|
+
adapter: Adapter
|
|
39
|
+
storeId: string
|
|
40
|
+
reactivityGraph?: ReactivityGraph
|
|
41
|
+
graphQLOptions?: GraphQLOptions<TGraphQLContext>
|
|
42
|
+
otelOptions?: Partial<OtelOptions>
|
|
43
|
+
boot?: (
|
|
44
|
+
store: Store<TGraphQLContext, TSchema>,
|
|
45
|
+
parentSpan: otel.Span,
|
|
46
|
+
) => void | Promise<void> | Effect.Effect<void, unknown, otel.Tracer>
|
|
47
|
+
batchUpdates?: (run: () => void) => void
|
|
48
|
+
disableDevtools?: boolean
|
|
49
|
+
onBootStatus?: (status: BootStatus) => void
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Create a new LiveStore Store */
|
|
53
|
+
export const createStorePromise = async <
|
|
54
|
+
TGraphQLContext extends BaseGraphQLContext,
|
|
55
|
+
TSchema extends LiveStoreSchema = LiveStoreSchema,
|
|
56
|
+
>({
|
|
57
|
+
signal,
|
|
58
|
+
...options
|
|
59
|
+
}: CreateStoreOptions<TGraphQLContext, TSchema> & { signal?: AbortSignal }): Promise<Store<TGraphQLContext, TSchema>> =>
|
|
60
|
+
Effect.gen(function* () {
|
|
61
|
+
const scope = yield* Scope.make()
|
|
62
|
+
const runtime = yield* Effect.runtime()
|
|
63
|
+
|
|
64
|
+
if (signal !== undefined) {
|
|
65
|
+
signal.addEventListener('abort', () => {
|
|
66
|
+
Scope.close(scope, Exit.void).pipe(Effect.tapCauseLogPretty, Runtime.runFork(runtime))
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return yield* FiberSet.make().pipe(
|
|
71
|
+
Effect.andThen((fiberSet) => createStore({ ...options, fiberSet })),
|
|
72
|
+
Scope.extend(scope),
|
|
73
|
+
)
|
|
74
|
+
}).pipe(
|
|
75
|
+
Effect.withSpan('createStore'),
|
|
76
|
+
Effect.tapCauseLogPretty,
|
|
77
|
+
Effect.annotateLogs({ thread: 'window' }),
|
|
78
|
+
Effect.provide(Logger.pretty),
|
|
79
|
+
Logger.withMinimumLogLevel(LogLevel.Debug),
|
|
80
|
+
Effect.runPromise,
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
export const createStore = <
|
|
84
|
+
TGraphQLContext extends BaseGraphQLContext,
|
|
85
|
+
TSchema extends LiveStoreSchema = LiveStoreSchema,
|
|
86
|
+
>({
|
|
87
|
+
schema,
|
|
88
|
+
adapter,
|
|
89
|
+
storeId,
|
|
90
|
+
graphQLOptions,
|
|
91
|
+
otelOptions,
|
|
92
|
+
boot,
|
|
93
|
+
reactivityGraph = globalReactivityGraph,
|
|
94
|
+
batchUpdates,
|
|
95
|
+
disableDevtools,
|
|
96
|
+
onBootStatus,
|
|
97
|
+
fiberSet,
|
|
98
|
+
}: CreateStoreOptions<TGraphQLContext, TSchema> & { fiberSet: FiberSet.FiberSet }): Effect.Effect<
|
|
99
|
+
Store<TGraphQLContext, TSchema>,
|
|
100
|
+
UnexpectedError,
|
|
101
|
+
Scope.Scope
|
|
102
|
+
> => {
|
|
103
|
+
const otelTracer = otelOptions?.tracer ?? makeNoopTracer()
|
|
104
|
+
const otelRootSpanContext = otelOptions?.rootSpanContext ?? otel.context.active()
|
|
105
|
+
|
|
106
|
+
const TracingLive = Layer.unwrapEffect(Effect.map(OtelTracer.make, Layer.setTracer)).pipe(
|
|
107
|
+
Layer.provide(Layer.sync(OtelTracer.Tracer, () => otelTracer)),
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
return Effect.gen(function* () {
|
|
111
|
+
const span = yield* OtelTracer.currentOtelSpan.pipe(Effect.orDie)
|
|
112
|
+
|
|
113
|
+
const bootStatusQueue = yield* Queue.unbounded<BootStatus>().pipe(Effect.acquireRelease(Queue.shutdown))
|
|
114
|
+
|
|
115
|
+
yield* Queue.take(bootStatusQueue).pipe(
|
|
116
|
+
Effect.tapSync((status) => onBootStatus?.(status)),
|
|
117
|
+
Effect.tap((status) => (status.stage === 'done' ? Queue.shutdown(bootStatusQueue) : Effect.void)),
|
|
118
|
+
Effect.forever,
|
|
119
|
+
Effect.tapCauseLogPretty,
|
|
120
|
+
Effect.forkScoped,
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
const storeDeferred = yield* Deferred.make<Store>()
|
|
124
|
+
|
|
125
|
+
const connectDevtoolsToStore_ = (storeDevtoolsChannel: StoreDevtoolsChannel) =>
|
|
126
|
+
Effect.gen(function* () {
|
|
127
|
+
const store = yield* Deferred.await(storeDeferred)
|
|
128
|
+
yield* connectDevtoolsToStore({ storeDevtoolsChannel, store })
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
const runtime = yield* Effect.runtime<Scope.Scope>()
|
|
132
|
+
|
|
133
|
+
// TODO close parent scope? (Needs refactor with Mike Arnaldi)
|
|
134
|
+
const shutdown = (cause: Cause.Cause<UnexpectedError | IntentionalShutdownCause>) =>
|
|
135
|
+
Effect.gen(function* () {
|
|
136
|
+
// NOTE we're calling `cause.toString()` here to avoid triggering a `console.error` in the grouped log
|
|
137
|
+
const logCause =
|
|
138
|
+
Cause.isFailType(cause) && cause.error._tag === 'LiveStore.IntentionalShutdownCause'
|
|
139
|
+
? cause.toString()
|
|
140
|
+
: cause
|
|
141
|
+
yield* Effect.logDebug(`Shutting down LiveStore`, logCause)
|
|
142
|
+
|
|
143
|
+
FiberSet.clear(fiberSet).pipe(
|
|
144
|
+
Effect.andThen(() => FiberSet.run(fiberSet, Effect.failCause(cause))),
|
|
145
|
+
Effect.timeout(Duration.seconds(1)),
|
|
146
|
+
Effect.logWarnIfTakesLongerThan({ label: '@livestore/livestore:shutdown:clear-fiber-set', duration: 500 }),
|
|
147
|
+
Effect.catchTag('TimeoutException', (err) =>
|
|
148
|
+
Effect.logError('Store shutdown timed out. Forcing shutdown.', err).pipe(
|
|
149
|
+
Effect.andThen(FiberSet.run(fiberSet, Effect.failCause(cause))),
|
|
150
|
+
),
|
|
151
|
+
),
|
|
152
|
+
Runtime.runFork(runtime), // NOTE we need to fork this separately otherwise it will also be interrupted
|
|
153
|
+
)
|
|
154
|
+
}).pipe(Effect.withSpan('livestore:shutdown'))
|
|
155
|
+
|
|
156
|
+
const clientSession: ClientSession = yield* adapter({
|
|
157
|
+
schema,
|
|
158
|
+
storeId,
|
|
159
|
+
devtoolsEnabled: disableDevtools !== true,
|
|
160
|
+
bootStatusQueue,
|
|
161
|
+
shutdown,
|
|
162
|
+
connectDevtoolsToStore: connectDevtoolsToStore_,
|
|
163
|
+
}).pipe(Effect.withPerformanceMeasure('livestore:makeAdapter'), Effect.withSpan('createStore:makeAdapter'))
|
|
164
|
+
|
|
165
|
+
// TODO fill up with unsynced mutation events from the client session
|
|
166
|
+
const unsyncedMutationEvents = MutableHashMap.empty<EventId, MutationEvent.ForSchema<TSchema>>()
|
|
167
|
+
|
|
168
|
+
const store = Store.createStore<TGraphQLContext, TSchema>(
|
|
169
|
+
{
|
|
170
|
+
clientSession,
|
|
171
|
+
schema,
|
|
172
|
+
graphQLOptions,
|
|
173
|
+
otelOptions: { tracer: otelTracer, rootSpanContext: otelRootSpanContext },
|
|
174
|
+
reactivityGraph,
|
|
175
|
+
disableDevtools,
|
|
176
|
+
unsyncedMutationEvents,
|
|
177
|
+
fiberSet,
|
|
178
|
+
runtime,
|
|
179
|
+
// NOTE during boot we're not yet executing mutations in a batched context
|
|
180
|
+
// but only set the provided `batchUpdates` function after boot
|
|
181
|
+
batchUpdates: (run) => run(),
|
|
182
|
+
storeId,
|
|
183
|
+
},
|
|
184
|
+
span,
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
if (boot !== undefined) {
|
|
188
|
+
// TODO also incorporate `boot` function progress into `bootStatusQueue`
|
|
189
|
+
yield* Effect.tryAll(() => boot(store, span)).pipe(
|
|
190
|
+
UnexpectedError.mapToUnexpectedError,
|
|
191
|
+
Effect.withSpan('createStore:boot'),
|
|
192
|
+
)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// NOTE it's important to yield here to allow the forked Effect in the store constructor to run
|
|
196
|
+
yield* Effect.yieldNow()
|
|
197
|
+
|
|
198
|
+
if (batchUpdates !== undefined) {
|
|
199
|
+
// Replacing the default batchUpdates function with the provided one after boot
|
|
200
|
+
store.reactivityGraph.context!.effectsWrapper = batchUpdates
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
yield* Deferred.succeed(storeDeferred, store as any as Store)
|
|
204
|
+
|
|
205
|
+
return store
|
|
206
|
+
}).pipe(
|
|
207
|
+
Effect.withSpan('createStore', {
|
|
208
|
+
parent: otelOptions?.rootSpanContext
|
|
209
|
+
? OtelTracer.makeExternalSpan(otel.trace.getSpanContext(otelOptions.rootSpanContext)!)
|
|
210
|
+
: undefined,
|
|
211
|
+
}),
|
|
212
|
+
Effect.provide(TracingLive),
|
|
213
|
+
)
|
|
214
|
+
}
|
|
@@ -4,11 +4,11 @@ import { throttle } from '@livestore/utils'
|
|
|
4
4
|
import type { WebChannel } from '@livestore/utils/effect'
|
|
5
5
|
import { Effect, Stream } from '@livestore/utils/effect'
|
|
6
6
|
|
|
7
|
-
import { NOT_REFRESHED_YET } from '
|
|
8
|
-
import type { LiveQuery, ReactivityGraph } from '
|
|
9
|
-
import type { SynchronousDatabaseWrapper } from '
|
|
10
|
-
import { emptyDebugInfo as makeEmptyDebugInfo } from '
|
|
11
|
-
import type { ReferenceCountedSet } from '
|
|
7
|
+
import { NOT_REFRESHED_YET } from '../reactive.js'
|
|
8
|
+
import type { LiveQuery, ReactivityGraph } from '../reactiveQueries/base-class.js'
|
|
9
|
+
import type { SynchronousDatabaseWrapper } from '../SynchronousDatabaseWrapper.js'
|
|
10
|
+
import { emptyDebugInfo as makeEmptyDebugInfo } from '../SynchronousDatabaseWrapper.js'
|
|
11
|
+
import type { ReferenceCountedSet } from '../utils/data-structures.js'
|
|
12
12
|
|
|
13
13
|
type IStore = {
|
|
14
14
|
clientSession: ClientSession
|