@livestore/livestore 0.0.54-dev.5 → 0.0.55-dev.0
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/MainDatabaseWrapper.d.ts +6 -5
- package/dist/MainDatabaseWrapper.d.ts.map +1 -1
- package/dist/MainDatabaseWrapper.js +3 -3
- package/dist/MainDatabaseWrapper.js.map +1 -1
- package/dist/QueryCache.d.ts +1 -1
- package/dist/QueryCache.d.ts.map +1 -1
- package/dist/QueryCache.js.map +1 -1
- package/dist/__tests__/react/fixture.d.ts +9 -27
- package/dist/__tests__/react/fixture.d.ts.map +1 -1
- package/dist/__tests__/react/fixture.js +12 -10
- package/dist/__tests__/react/fixture.js.map +1 -1
- package/dist/effect/LiveStore.d.ts +20 -12
- package/dist/effect/LiveStore.d.ts.map +1 -1
- package/dist/effect/LiveStore.js +23 -22
- package/dist/effect/LiveStore.js.map +1 -1
- package/dist/effect/index.d.ts +1 -1
- package/dist/effect/index.d.ts.map +1 -1
- package/dist/effect/index.js +1 -1
- package/dist/effect/index.js.map +1 -1
- package/dist/global-state.d.ts +1 -3
- package/dist/global-state.d.ts.map +1 -1
- package/dist/global-state.js +2 -3
- package/dist/global-state.js.map +1 -1
- package/dist/index.d.ts +6 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -6
- package/dist/index.js.map +1 -1
- package/dist/react/LiveStoreContext.d.ts +5 -2
- package/dist/react/LiveStoreContext.d.ts.map +1 -1
- package/dist/react/LiveStoreContext.js +3 -0
- package/dist/react/LiveStoreContext.js.map +1 -1
- package/dist/react/LiveStoreProvider.d.ts +8 -7
- package/dist/react/LiveStoreProvider.d.ts.map +1 -1
- package/dist/react/LiveStoreProvider.js +70 -43
- package/dist/react/LiveStoreProvider.js.map +1 -1
- package/dist/react/LiveStoreProvider.test.js +33 -12
- package/dist/react/LiveStoreProvider.test.js.map +1 -1
- package/dist/react/components/LiveList.d.ts.map +1 -1
- package/dist/react/useAtom.d.ts +1 -1
- package/dist/react/useAtom.d.ts.map +1 -1
- package/dist/react/useLocalId.d.ts.map +1 -1
- package/dist/react/useQuery.d.ts.map +1 -1
- package/dist/react/useQuery.js +2 -2
- package/dist/react/useQuery.js.map +1 -1
- package/dist/react/useRow.d.ts +2 -2
- package/dist/react/useRow.d.ts.map +1 -1
- package/dist/react/useRow.js +5 -5
- package/dist/react/useRow.js.map +1 -1
- package/dist/react/useRow.test.js +22 -22
- package/dist/react/useRow.test.js.map +1 -1
- package/dist/react/useTemporaryQuery.d.ts.map +1 -1
- package/dist/react/useTemporaryQuery.js +1 -1
- package/dist/react/useTemporaryQuery.js.map +1 -1
- package/dist/react/utils/useStateRefWithReactiveInput.d.ts.map +1 -1
- package/dist/reactive.d.ts +1 -1
- package/dist/reactive.d.ts.map +1 -1
- package/dist/reactive.js +4 -5
- package/dist/reactive.js.map +1 -1
- package/dist/reactiveQueries/base-class.d.ts +6 -6
- package/dist/reactiveQueries/base-class.d.ts.map +1 -1
- package/dist/reactiveQueries/base-class.js +3 -3
- package/dist/reactiveQueries/base-class.js.map +1 -1
- package/dist/reactiveQueries/graphql.d.ts +8 -8
- package/dist/reactiveQueries/graphql.d.ts.map +1 -1
- package/dist/reactiveQueries/graphql.js +10 -10
- package/dist/reactiveQueries/graphql.js.map +1 -1
- package/dist/reactiveQueries/js.d.ts +6 -6
- package/dist/reactiveQueries/js.d.ts.map +1 -1
- package/dist/reactiveQueries/js.js +8 -8
- package/dist/reactiveQueries/js.js.map +1 -1
- package/dist/reactiveQueries/sql.d.ts +9 -10
- package/dist/reactiveQueries/sql.d.ts.map +1 -1
- package/dist/reactiveQueries/sql.js +12 -12
- package/dist/reactiveQueries/sql.js.map +1 -1
- package/dist/reactiveQueries/sql.test.js +6 -6
- package/dist/reactiveQueries/sql.test.js.map +1 -1
- package/dist/row-query.d.ts +2 -2
- package/dist/row-query.d.ts.map +1 -1
- package/dist/row-query.js +4 -38
- package/dist/row-query.js.map +1 -1
- package/dist/store.d.ts +41 -24
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +336 -223
- package/dist/store.js.map +1 -1
- package/dist/utils/otel.d.ts.map +1 -1
- package/package.json +10 -19
- package/src/MainDatabaseWrapper.ts +14 -8
- package/src/QueryCache.ts +1 -2
- package/src/__tests__/react/fixture.tsx +13 -11
- package/src/effect/LiveStore.ts +65 -54
- package/src/effect/index.ts +2 -1
- package/src/global-state.ts +2 -6
- package/src/index.ts +25 -7
- package/src/react/LiveStoreContext.ts +7 -2
- package/src/react/LiveStoreProvider.test.tsx +56 -14
- package/src/react/LiveStoreProvider.tsx +105 -46
- package/src/react/useQuery.ts +2 -2
- package/src/react/useRow.test.tsx +22 -22
- package/src/react/useRow.ts +7 -10
- package/src/react/useTemporaryQuery.ts +2 -2
- package/src/reactive.ts +6 -5
- package/src/reactiveQueries/base-class.ts +9 -9
- package/src/reactiveQueries/graphql.ts +19 -15
- package/src/reactiveQueries/js.ts +12 -12
- package/src/reactiveQueries/sql.test.ts +6 -6
- package/src/reactiveQueries/sql.ts +19 -21
- package/src/row-query.ts +8 -54
- package/src/store.ts +533 -284
- package/dist/utils/bounded-collections.d.ts +0 -34
- package/dist/utils/bounded-collections.d.ts.map +0 -1
- package/dist/utils/bounded-collections.js +0 -91
- package/dist/utils/bounded-collections.js.map +0 -1
- package/dist/utils/util.d.ts +0 -14
- package/dist/utils/util.d.ts.map +0 -1
- package/dist/utils/util.js +0 -19
- package/dist/utils/util.js.map +0 -1
- package/src/utils/util.ts +0 -31
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import type { QueryInfo, QueryInfoNone } from '@livestore/common';
|
|
2
2
|
import type { Thunk } from '../reactive.js';
|
|
3
3
|
import type { RefreshReason } from '../store.js';
|
|
4
|
-
import type {
|
|
4
|
+
import type { GetAtomResult, LiveQuery, QueryContext, ReactivityGraph } from './base-class.js';
|
|
5
5
|
import { LiveStoreQueryBase } from './base-class.js';
|
|
6
6
|
export declare const computed: <TResult, TQueryInfo extends QueryInfo = QueryInfoNone>(fn: (get: GetAtomResult) => TResult, options?: {
|
|
7
7
|
label: string;
|
|
8
|
-
|
|
8
|
+
reactivityGraph?: ReactivityGraph;
|
|
9
9
|
queryInfo?: TQueryInfo;
|
|
10
10
|
}) => LiveQuery<TResult, TQueryInfo>;
|
|
11
11
|
export declare class LiveStoreJSQuery<TResult, TQueryInfo extends QueryInfo = QueryInfoNone> extends LiveStoreQueryBase<TResult, TQueryInfo> {
|
|
12
12
|
_tag: 'js';
|
|
13
13
|
/** A reactive thunk representing the query results */
|
|
14
|
-
results$: Thunk<TResult,
|
|
14
|
+
results$: Thunk<TResult, QueryContext, RefreshReason>;
|
|
15
15
|
label: string;
|
|
16
|
-
protected
|
|
16
|
+
protected reactivityGraph: ReactivityGraph;
|
|
17
17
|
queryInfo: TQueryInfo;
|
|
18
18
|
/**
|
|
19
19
|
* Currently only used for "nested destruction" of piped queries
|
|
@@ -22,12 +22,12 @@ export declare class LiveStoreJSQuery<TResult, TQueryInfo extends QueryInfo = Qu
|
|
|
22
22
|
* we need to also destory the SQL query when the JS query `q` is destroyed
|
|
23
23
|
*/
|
|
24
24
|
private onDestroy;
|
|
25
|
-
constructor({ fn, label, onDestroy,
|
|
25
|
+
constructor({ fn, label, onDestroy, reactivityGraph, queryInfo, }: {
|
|
26
26
|
label: string;
|
|
27
27
|
fn: (get: GetAtomResult) => TResult;
|
|
28
28
|
/** Currently only used for "nested destruction" of piped queries */
|
|
29
29
|
onDestroy?: () => void;
|
|
30
|
-
|
|
30
|
+
reactivityGraph?: ReactivityGraph;
|
|
31
31
|
queryInfo?: TQueryInfo;
|
|
32
32
|
});
|
|
33
33
|
destroy: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"js.d.ts","sourceRoot":"","sources":["../../src/reactiveQueries/js.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,mBAAmB,CA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EACF,KAAK,EACL,SAAS,EACT,eAAe,EACf,SAAS,GACV,EAAE;QACD,KAAK,EAAE,MAAM,CAAA;QACb,EAAE,EAAE,CAAC,GAAG,EAAE,aAAa,KAAK,OAAO,CAAA;QACnC,oEAAoE;QACpE,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;QACtB,eAAe,CAAC,EAAE,eAAe,CAAA;QACjC,SAAS,CAAC,EAAE,UAAU,CAAA;KACvB;IA0CD,OAAO,aAGN;CACF"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as otel from '@opentelemetry/api';
|
|
2
|
-
import {
|
|
2
|
+
import { globalReactivityGraph } from '../global-state.js';
|
|
3
3
|
import { getDurationMsFromSpan } from '../utils/otel.js';
|
|
4
4
|
import { LiveStoreQueryBase, makeGetAtomResult } from './base-class.js';
|
|
5
5
|
export const computed = (fn, options) => new LiveStoreJSQuery({
|
|
6
6
|
fn,
|
|
7
7
|
label: options?.label ?? fn.toString(),
|
|
8
|
-
|
|
8
|
+
reactivityGraph: options?.reactivityGraph,
|
|
9
9
|
queryInfo: options?.queryInfo,
|
|
10
10
|
});
|
|
11
11
|
export class LiveStoreJSQuery extends LiveStoreQueryBase {
|
|
@@ -13,7 +13,7 @@ export class LiveStoreJSQuery extends LiveStoreQueryBase {
|
|
|
13
13
|
/** A reactive thunk representing the query results */
|
|
14
14
|
results$;
|
|
15
15
|
label;
|
|
16
|
-
|
|
16
|
+
reactivityGraph;
|
|
17
17
|
queryInfo;
|
|
18
18
|
/**
|
|
19
19
|
* Currently only used for "nested destruction" of piped queries
|
|
@@ -22,14 +22,14 @@ export class LiveStoreJSQuery extends LiveStoreQueryBase {
|
|
|
22
22
|
* we need to also destory the SQL query when the JS query `q` is destroyed
|
|
23
23
|
*/
|
|
24
24
|
onDestroy;
|
|
25
|
-
constructor({ fn, label, onDestroy,
|
|
25
|
+
constructor({ fn, label, onDestroy, reactivityGraph, queryInfo, }) {
|
|
26
26
|
super();
|
|
27
27
|
this.onDestroy = onDestroy;
|
|
28
28
|
this.label = label;
|
|
29
|
-
this.
|
|
29
|
+
this.reactivityGraph = reactivityGraph ?? globalReactivityGraph;
|
|
30
30
|
this.queryInfo = queryInfo ?? { _tag: 'None' };
|
|
31
31
|
const queryLabel = `${label}:results`;
|
|
32
|
-
this.results$ = this.
|
|
32
|
+
this.results$ = this.reactivityGraph.makeThunk((get, setDebugInfo, { otelTracer, rootOtelContext }, otelContext) => otelTracer.startActiveSpan(`js:${label}`, {}, otelContext ?? rootOtelContext, (span) => {
|
|
33
33
|
const otelContext = otel.trace.setSpan(otel.context.active(), span);
|
|
34
34
|
const res = fn(makeGetAtomResult(get, otelContext));
|
|
35
35
|
span.end();
|
|
@@ -47,10 +47,10 @@ export class LiveStoreJSQuery extends LiveStoreQueryBase {
|
|
|
47
47
|
// },
|
|
48
48
|
// label: `${this.label}:js`,
|
|
49
49
|
// onDestroy: () => this.destroy(),
|
|
50
|
-
//
|
|
50
|
+
// reactivityGraph: this.reactivityGraph,
|
|
51
51
|
// })
|
|
52
52
|
destroy = () => {
|
|
53
|
-
this.
|
|
53
|
+
this.reactivityGraph.destroyNode(this.results$);
|
|
54
54
|
this.onDestroy?.();
|
|
55
55
|
};
|
|
56
56
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"js.js","sourceRoot":"","sources":["../../src/reactiveQueries/js.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAE1C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"js.js","sourceRoot":"","sources":["../../src/reactiveQueries/js.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAE1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAG1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AAExD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;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ACnE,MAAM,GAAG,GAAG,EAAE,CAAC,iBAAiB,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,CAAA;YAEnD,IAAI,CAAC,GAAG,EAAE,CAAA;YAEV,MAAM,UAAU,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAA;YAE9C,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;YAEpC,YAAY,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,QAAQ,EAAE,EAAE,UAAU,EAAE,CAAC,CAAA;YAErE,OAAO,GAAG,CAAA;QACZ,CAAC,CAAC,EACJ,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,kBAAkB,EAAE,WAAW,EAAE,EAAE,CACjE,CAAA;IACH,CAAC;IAED,qFAAqF;IACrF,2BAA2B;IAC3B,qBAAqB;IACrB,2CAA2C;IAC3C,gCAAgC;IAChC,SAAS;IACT,iCAAiC;IACjC,uCAAuC;IACvC,6CAA6C;IAC7C,OAAO;IAEP,OAAO,GAAG,GAAG,EAAE;QACb,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAC/C,IAAI,CAAC,SAAS,EAAE,EAAE,CAAA;IACpB,CAAC,CAAA;CACF"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Bindable, type QueryInfo, type QueryInfoNone } from '@livestore/common';
|
|
2
2
|
import { Schema } from '@livestore/utils/effect';
|
|
3
3
|
import type { Thunk } from '../reactive.js';
|
|
4
4
|
import type { RefreshReason } from '../store.js';
|
|
5
|
-
import type {
|
|
6
|
-
import type { DbContext, DbGraph, GetAtomResult, LiveQuery } from './base-class.js';
|
|
5
|
+
import type { GetAtomResult, LiveQuery, QueryContext, ReactivityGraph } from './base-class.js';
|
|
7
6
|
import { LiveStoreQueryBase } from './base-class.js';
|
|
8
7
|
export type MapRows<TResult, TRaw = any> = ((rows: ReadonlyArray<TRaw>) => TResult) | Schema.Schema<TResult, ReadonlyArray<TRaw>, unknown>;
|
|
9
8
|
export declare const querySQL: <TResult, TRaw = any>(query: string | ((get: GetAtomResult) => string), options?: {
|
|
@@ -16,28 +15,28 @@ export declare const querySQL: <TResult, TRaw = any>(query: string | ((get: GetA
|
|
|
16
15
|
queriedTables?: Set<string>;
|
|
17
16
|
bindValues?: Bindable;
|
|
18
17
|
label?: string;
|
|
19
|
-
|
|
18
|
+
reactivityGraph?: ReactivityGraph;
|
|
20
19
|
}) => LiveQuery<TResult, QueryInfoNone>;
|
|
21
20
|
export declare class LiveStoreSQLQuery<TResult, TQueryInfo extends QueryInfo = QueryInfoNone> extends LiveStoreQueryBase<TResult, TQueryInfo> {
|
|
22
21
|
_tag: 'sql';
|
|
23
22
|
/** A reactive thunk representing the query text */
|
|
24
|
-
queryString$: Thunk<string,
|
|
23
|
+
queryString$: Thunk<string, QueryContext, RefreshReason> | undefined;
|
|
25
24
|
/** A reactive thunk representing the query results */
|
|
26
|
-
results$: Thunk<TResult,
|
|
25
|
+
results$: Thunk<TResult, QueryContext, RefreshReason>;
|
|
27
26
|
label: string;
|
|
28
|
-
protected
|
|
27
|
+
protected reactivityGraph: ReactivityGraph;
|
|
29
28
|
/** Currently only used by `rowQuery` for lazy table migrations and eager default row insertion */
|
|
30
29
|
private execBeforeFirstRun;
|
|
31
30
|
private mapRows;
|
|
32
31
|
queryInfo: TQueryInfo;
|
|
33
|
-
constructor({ genQueryString, queriedTables, bindValues, label: label_,
|
|
32
|
+
constructor({ genQueryString, queriedTables, bindValues, label: label_, reactivityGraph, map, execBeforeFirstRun, queryInfo, }: {
|
|
34
33
|
label?: string;
|
|
35
34
|
genQueryString: string | ((get: GetAtomResult) => string);
|
|
36
35
|
queriedTables?: Set<string>;
|
|
37
36
|
bindValues?: Bindable;
|
|
38
|
-
|
|
37
|
+
reactivityGraph?: ReactivityGraph;
|
|
39
38
|
map?: MapRows<TResult>;
|
|
40
|
-
execBeforeFirstRun?: (ctx:
|
|
39
|
+
execBeforeFirstRun?: (ctx: QueryContext) => void;
|
|
41
40
|
queryInfo?: TQueryInfo;
|
|
42
41
|
});
|
|
43
42
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["../../src/reactiveQueries/sql.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["../../src/reactiveQueries/sql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAqB,KAAK,SAAS,EAAE,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAExG,OAAO,EAAE,MAAM,EAAiB,MAAM,yBAAyB,CAAA;AAI/D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEhD,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAC9F,OAAO,EAAE,kBAAkB,EAAqB,MAAM,iBAAiB,CAAA;AAEvE,MAAM,MAAM,OAAO,CAAC,OAAO,EAAE,IAAI,GAAG,GAAG,IACnC,CAAC,CAAC,IAAI,EAAE,aAAa,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC,GACxC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,aAAa,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,CAAA;AAExD,eAAO,MAAM,QAAQ,GAAI,OAAO,EAAE,IAAI,eAC7B,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,aAAa,KAAK,MAAM,CAAC,YACtC;IACR,GAAG,CAAC,EAAE,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;IAC5B;;;;OAIG;IACH,aAAa,CAAC,EAAE,GAAG,CAAC,MA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AGG;IAaH,gCAAgC;IAiBhC,OAAO,aAMN;CACF"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
+
import { prepareBindValues } from '@livestore/common';
|
|
1
2
|
import { shouldNeverHappen } from '@livestore/utils';
|
|
2
3
|
import { Schema, TreeFormatter } from '@livestore/utils/effect';
|
|
3
4
|
import * as otel from '@opentelemetry/api';
|
|
4
|
-
import {
|
|
5
|
+
import { globalReactivityGraph } from '../global-state.js';
|
|
5
6
|
import { getDurationMsFromSpan } from '../utils/otel.js';
|
|
6
|
-
import { prepareBindValues } from '../utils/util.js';
|
|
7
7
|
import { LiveStoreQueryBase, makeGetAtomResult } from './base-class.js';
|
|
8
8
|
export const querySQL = (query, options) => new LiveStoreSQLQuery({
|
|
9
9
|
label: options?.label,
|
|
10
10
|
genQueryString: query,
|
|
11
11
|
queriedTables: options?.queriedTables,
|
|
12
12
|
bindValues: options?.bindValues,
|
|
13
|
-
|
|
13
|
+
reactivityGraph: options?.reactivityGraph,
|
|
14
14
|
map: options?.map,
|
|
15
15
|
queryInfo: { _tag: 'None' },
|
|
16
16
|
});
|
|
@@ -22,16 +22,16 @@ export class LiveStoreSQLQuery extends LiveStoreQueryBase {
|
|
|
22
22
|
/** A reactive thunk representing the query results */
|
|
23
23
|
results$;
|
|
24
24
|
label;
|
|
25
|
-
|
|
25
|
+
reactivityGraph;
|
|
26
26
|
/** Currently only used by `rowQuery` for lazy table migrations and eager default row insertion */
|
|
27
27
|
execBeforeFirstRun;
|
|
28
28
|
mapRows;
|
|
29
29
|
queryInfo;
|
|
30
|
-
constructor({ genQueryString, queriedTables, bindValues, label: label_,
|
|
30
|
+
constructor({ genQueryString, queriedTables, bindValues, label: label_, reactivityGraph, map, execBeforeFirstRun, queryInfo, }) {
|
|
31
31
|
super();
|
|
32
32
|
const label = label_ ?? genQueryString.toString();
|
|
33
33
|
this.label = `sql(${label})`;
|
|
34
|
-
this.
|
|
34
|
+
this.reactivityGraph = reactivityGraph ?? globalReactivityGraph;
|
|
35
35
|
this.execBeforeFirstRun = execBeforeFirstRun;
|
|
36
36
|
this.queryInfo = queryInfo ?? { _tag: 'None' };
|
|
37
37
|
this.mapRows =
|
|
@@ -67,7 +67,7 @@ Result:`, rows);
|
|
|
67
67
|
: shouldNeverHappen(`Invalid map function ${map}`);
|
|
68
68
|
let queryString$OrQueryString;
|
|
69
69
|
if (typeof genQueryString === 'function') {
|
|
70
|
-
queryString$OrQueryString = this.
|
|
70
|
+
queryString$OrQueryString = this.reactivityGraph.makeThunk((get, setDebugInfo, { rootOtelContext }, otelContext) => {
|
|
71
71
|
const startMs = performance.now();
|
|
72
72
|
const queryString = genQueryString(makeGetAtomResult(get, otelContext ?? rootOtelContext));
|
|
73
73
|
const durationMs = performance.now() - startMs;
|
|
@@ -81,7 +81,7 @@ Result:`, rows);
|
|
|
81
81
|
}
|
|
82
82
|
const queryLabel = `${label}:results`;
|
|
83
83
|
const queriedTablesRef = { current: queriedTables };
|
|
84
|
-
const results$ = this.
|
|
84
|
+
const results$ = this.reactivityGraph.makeThunk((get, setDebugInfo, { store, otelTracer, rootOtelContext }, otelContext) => otelTracer.startActiveSpan('sql:...', // NOTE span name will be overridden further down
|
|
85
85
|
{}, otelContext ?? rootOtelContext, (span) => {
|
|
86
86
|
const otelContext = otel.trace.setSpan(otel.context.active(), span);
|
|
87
87
|
if (this.execBeforeFirstRun !== undefined) {
|
|
@@ -128,7 +128,7 @@ Result:`, rows);
|
|
|
128
128
|
// },
|
|
129
129
|
// label: `${this.label}:js`,
|
|
130
130
|
// onDestroy: () => this.destroy(),
|
|
131
|
-
//
|
|
131
|
+
// reactivityGraph: this.reactivityGraph,
|
|
132
132
|
// queryInfo: undefined,
|
|
133
133
|
// })
|
|
134
134
|
/** Returns a reactive query */
|
|
@@ -145,13 +145,13 @@ Result:`, rows);
|
|
|
145
145
|
// },
|
|
146
146
|
// label: `${this.label}:first`,
|
|
147
147
|
// onDestroy: () => this.destroy(),
|
|
148
|
-
//
|
|
148
|
+
// reactivityGraph: this.reactivityGraph,
|
|
149
149
|
// })
|
|
150
150
|
destroy = () => {
|
|
151
151
|
if (this.queryString$ !== undefined) {
|
|
152
|
-
this.
|
|
152
|
+
this.reactivityGraph.destroyNode(this.queryString$);
|
|
153
153
|
}
|
|
154
|
-
this.
|
|
154
|
+
this.reactivityGraph.destroyNode(this.results$);
|
|
155
155
|
};
|
|
156
156
|
}
|
|
157
157
|
//# sourceMappingURL=sql.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql.js","sourceRoot":"","sources":["../../src/reactiveQueries/sql.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sql.js","sourceRoot":"","sources":["../../src/reactiveQueries/sql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,iBAAiB,EAAsC,MAAM,mBAAmB,CAAA;AACxG,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAE1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAG1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AAExD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAMvE,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,KAAgD,EAChD,OAWC,EACkC,EAAE,CACrC,IAAI,iBAAiB,CAAyB;IAC5C,KAAK,EAAE,OAAO,EAAE,KAAK;IACrB,cAAc,EAAE,KAAK;IACrB,aAAa,EAAE,OAAO,EAAE,aAAa;IACrC,UAAU,EAAE,OAAO,EAAE,UAAU;IAC/B,eAAe,EAAE,OAAO,EAAE,eAAe;IACzC,GAAG,EAAE,OAAO,EAAE,GAAG;IACjB,SAAS,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;CAC5B,CAAC,C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AA4C;IAC5C,gCAAgC;IAChC,SAAS;IACT,iCAAiC;IACjC,uCAAuC;IACvC,6CAA6C;IAC7C,4BAA4B;IAC5B,OAAO;IAEP,gCAAgC;IAChC,sDAAsD;IACtD,2BAA2B;IAC3B,qBAAqB;IACrB,4CAA4C;IAC5C,wEAAwE;IACxE,iHAAiH;IACjH,wCAAwC;IACxC,iGAAiG;IACjG,UAAU;IACV,iDAAiD;IACjD,SAAS;IACT,oCAAoC;IACpC,uCAAuC;IACvC,6CAA6C;IAC7C,OAAO;IAEP,OAAO,GAAG,GAAG,EAAE;QACb,IAAI,IAAI,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;YACpC,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;QACrD,CAAC;QAED,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IACjD,CAAC,CAAA;CACF"}
|
|
@@ -18,14 +18,14 @@ describe('otel', () => {
|
|
|
18
18
|
cachedProvider = provider;
|
|
19
19
|
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));
|
|
20
20
|
provider.register();
|
|
21
|
-
const
|
|
22
|
-
const span =
|
|
21
|
+
const otelTracer = otel.trace.getTracer('test');
|
|
22
|
+
const span = otelTracer.startSpan('test');
|
|
23
23
|
const otelContext = otel.trace.setSpan(otel.context.active(), span);
|
|
24
|
-
const { store } = await makeTodoMvc({ otelTracer
|
|
24
|
+
const { store } = await makeTodoMvc({ otelTracer, otelContext });
|
|
25
25
|
return {
|
|
26
26
|
[Symbol.dispose]: () => store.destroy(),
|
|
27
27
|
store,
|
|
28
|
-
|
|
28
|
+
otelTracer,
|
|
29
29
|
exporter,
|
|
30
30
|
span,
|
|
31
31
|
provider,
|
|
@@ -46,7 +46,7 @@ describe('otel', () => {
|
|
|
46
46
|
},
|
|
47
47
|
]
|
|
48
48
|
`);
|
|
49
|
-
store.destroy();
|
|
49
|
+
await store.destroy();
|
|
50
50
|
query.destroy();
|
|
51
51
|
span.end();
|
|
52
52
|
expect(getSimplifiedRootSpan(exporter)).toMatchInlineSnapshot(`
|
|
@@ -171,7 +171,7 @@ describe('otel', () => {
|
|
|
171
171
|
"text": "buy milk",
|
|
172
172
|
}
|
|
173
173
|
`);
|
|
174
|
-
store.destroy();
|
|
174
|
+
await store.destroy();
|
|
175
175
|
query.destroy();
|
|
176
176
|
span.end();
|
|
177
177
|
expect(getSimplifiedRootSpan(exporter)).toMatchInlineSnapshot(`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql.test.js","sourceRoot":"","sources":["../../src/reactiveQueries/sql.test.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAC1C,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAA;AAC9G,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7C,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAA;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AACxE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AAEjF;;;;;EAKE;AAEF,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE;IACpB,IAAI,cAA+C,CAAA;IAEnD,MAAM,SAAS,GAAG,KAAK,IAAI,EAAE;QAC3B,MAAM,QAAQ,GAAG,IAAI,oBAAoB,EAAE,CAAA;QAE3C,MAAM,QAAQ,GAAG,cAAc,IAAI,IAAI,mBAAmB,EAAE,CAAA;QAC5D,cAAc,GAAG,QAAQ,CAAA;QACzB,QAAQ,CAAC,gBAAgB,CAAC,IAAI,mBAAmB,CAAC,QAAQ,CAAC,CAAC,CAAA;QAC5D,QAAQ,CAAC,Q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"}
|
package/dist/row-query.d.ts
CHANGED
|
@@ -3,11 +3,11 @@ import { DbSchema } from '@livestore/common/schema';
|
|
|
3
3
|
import type { GetValForKey } from '@livestore/utils';
|
|
4
4
|
import type * as otel from '@opentelemetry/api';
|
|
5
5
|
import type { SqliteDsl } from 'effect-db-schema';
|
|
6
|
-
import type {
|
|
6
|
+
import type { LiveQuery, ReactivityGraph } from './reactiveQueries/base-class.js';
|
|
7
7
|
export type RowQueryOptions = {
|
|
8
8
|
otelContext?: otel.Context;
|
|
9
9
|
skipInsertDefaultRow?: boolean;
|
|
10
|
-
|
|
10
|
+
reactivityGraph?: ReactivityGraph;
|
|
11
11
|
};
|
|
12
12
|
export type RowQueryOptionsDefaulValues<TTableDef extends DbSchema.TableDef> = {
|
|
13
13
|
defaultValues: Partial<RowResult<TTableDef>>;
|
package/dist/row-query.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"row-query.d.ts","sourceRoot":"","sources":["../src/row-query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"row-query.d.ts","sourceRoot":"","sources":["../src/row-query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAElF,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAGpD,OAAO,KAAK,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAEjD,OAAO,KAAK,EAAE,SAAS,EAA8B,eAAe,EAAE,MAAM,iCAAiC,CAAA;AAK7G,MAAM,MAAM,eAAe,GAAG;IAC5B,WAAW,CAAC,EAAE,IAAI,CAAC,OAAO,CAAA;IAC1B,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,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,CAAC,CAAC,CAAA;AAEvE,MAAM,MAAM,gBAAgB,CAAC,SAAS,SAAS,QAAQ,CAAC,QAAQ,IAAI,SAAS,CAAC,gBAAgB,CAAC,SAAS,IAAI,GACxG,YAAY,CAAC,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,OAAO,CAAC,GAC1F,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,SAAS,CAAC,CAAC,CAAA;AAEvE,eAAO,MAAM,cAAc,EAAE;IAC3B,CAAC,MAAM,SAAS,SAAS,CAAC,GAAG,EAAE,aAAa,CAAC,EAAE,IAAI,SAAS,MAAM,MAAM,CAAC,WAAW,CAAC,GAAG,MAAM,EAC5F,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,IAAI,GACZ,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,EAAE,aAAa,CAAC,CAAA;IACtD,CAAC,MAAM,SAAS,SAAS,CAAC,GAAG,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,SAAS,MAAM,MAAM,CAAC,WAAW,CAAC,GAAG,MAAM,EAChG,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,IAAI,GACZ,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,EAAE,YAAY,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,CAAC,CAAA;CAS1F,CAAA"}
|
package/dist/row-query.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DbSchema
|
|
1
|
+
import { sql } from '@livestore/common';
|
|
2
|
+
import { DbSchema } from '@livestore/common/schema';
|
|
3
3
|
import { shouldNeverHappen } from '@livestore/utils';
|
|
4
4
|
import { Schema, TreeFormatter } from '@livestore/utils/effect';
|
|
5
|
-
import { SqliteAst } from 'effect-db-schema';
|
|
6
5
|
import { computed } from './reactiveQueries/js.js';
|
|
7
6
|
import { LiveStoreSQLQuery } from './reactiveQueries/sql.js';
|
|
8
7
|
// TODO also allow other where clauses and multiple rows
|
|
@@ -25,12 +24,11 @@ export const rowQuery = (table, idOrOptions, options_) => {
|
|
|
25
24
|
label: `rowQuery:query:${tableSchema.name}${id === undefined ? '' : `:${id}`}`,
|
|
26
25
|
genQueryString: queryStr,
|
|
27
26
|
queriedTables: new Set([tableName]),
|
|
28
|
-
|
|
27
|
+
reactivityGraph: options?.reactivityGraph,
|
|
29
28
|
// While this code-path is not needed for singleton tables, it's still needed for `useRow` with non-existing rows for a given ID
|
|
30
29
|
execBeforeFirstRun: makeExecBeforeFirstRun({
|
|
31
30
|
otelContext: options?.otelContext,
|
|
32
31
|
table,
|
|
33
|
-
tableName,
|
|
34
32
|
defaultValues,
|
|
35
33
|
id,
|
|
36
34
|
skipInsertDefaultRow: options?.skipInsertDefaultRow,
|
|
@@ -56,40 +54,8 @@ export const deriveColQuery = (query$, colName) => {
|
|
|
56
54
|
: undefined,
|
|
57
55
|
});
|
|
58
56
|
};
|
|
59
|
-
const makeExecBeforeFirstRun = ({ id, defaultValues, skipInsertDefaultRow, otelContext: otelContext_, table,
|
|
57
|
+
const makeExecBeforeFirstRun = ({ id, defaultValues, skipInsertDefaultRow, otelContext: otelContext_, table, }) => ({ store }) => {
|
|
60
58
|
const otelContext = otelContext_ ?? store.otel.queriesSpanContext;
|
|
61
|
-
// TODO we can remove this codepath again when Devtools v2 has landed
|
|
62
|
-
if (store.tableRefs[tableName] === undefined) {
|
|
63
|
-
const schemaHash = SqliteAst.hash(table.sqliteDef.ast);
|
|
64
|
-
const res = store.mainDbWrapper.select(sql `SELECT schemaHash FROM ${SCHEMA_META_TABLE} WHERE tableName = '${tableName}'`);
|
|
65
|
-
if (res.length === 0 || res[0].schemaHash !== schemaHash) {
|
|
66
|
-
const db = {
|
|
67
|
-
...store.adapter.mainDb,
|
|
68
|
-
prepare: (query) => {
|
|
69
|
-
const mainStmt = store.adapter.mainDb.prepare(query);
|
|
70
|
-
return {
|
|
71
|
-
...mainStmt,
|
|
72
|
-
execute: (bindValues) => {
|
|
73
|
-
const getRowsChanged = mainStmt.execute(bindValues);
|
|
74
|
-
store.adapter.coordinator.execute(query, bindValues, undefined);
|
|
75
|
-
return getRowsChanged;
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
migrateTable({
|
|
81
|
-
db,
|
|
82
|
-
tableAst: table.sqliteDef.ast,
|
|
83
|
-
otelContext,
|
|
84
|
-
schemaHash,
|
|
85
|
-
behaviour: 'create-if-not-exists',
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
const label = `tableRef:${tableName}`;
|
|
89
|
-
// TODO find a better implementation for this
|
|
90
|
-
const existingTableRefFromGraph = Array.from(store.graph.atoms.values()).find((_) => _._tag === 'ref' && _.label === label);
|
|
91
|
-
store.tableRefs[tableName] = existingTableRefFromGraph ?? store.makeTableRef(tableName);
|
|
92
|
-
}
|
|
93
59
|
if (skipInsertDefaultRow !== true && table.options.isSingleton === false) {
|
|
94
60
|
insertRowWithDefaultValuesOrIgnore({
|
|
95
61
|
store,
|
package/dist/row-query.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"row-query.js","sourceRoot":"","sources":["../src/row-query.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"row-query.js","sourceRoot":"","sources":["../src/row-query.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAEnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAK/D,OAAO,EAAE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AErB,qDAAqD;IACrD,IAAI,QAAQ,CAAC,wBAAwB,CAAC,KAAK,CAAC,KAAK,KAAK,EAAE,CAAC;QACvD,OAAO,iBAAiB,CACtB,gCAAgC,KAAK,CAAC,SAAS,CAAC,IAAI,mDAAmD,CACxG,CAAA;IACH,CAAC;IACD,6GAA6G;IAC7G,KAAK,CAAC,oBAAoB,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,GAAG,qBAAqB,EAAE,CAAC,EAAE;QACzE,WAAW;QACX,eAAe,EAAE,SAAS;KAC3B,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
package/dist/store.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import type { BootDb, ResetMode, StoreAdapter, StoreAdapterFactory } from '@livestore/common';
|
|
2
|
-
import
|
|
1
|
+
import type { BootDb, BootStatus, ParamsObject, ResetMode, StoreAdapter, StoreAdapterFactory } from '@livestore/common';
|
|
2
|
+
import { UnexpectedError } from '@livestore/common';
|
|
3
|
+
import type { LiveStoreSchema, MutationEvent } from '@livestore/common/schema';
|
|
4
|
+
import { Effect, FiberSet, Inspectable, Scope } from '@livestore/utils/effect';
|
|
3
5
|
import * as otel from '@opentelemetry/api';
|
|
4
6
|
import type { GraphQLSchema } from 'graphql';
|
|
5
7
|
import { MainDatabaseWrapper } from './MainDatabaseWrapper.js';
|
|
6
8
|
import type { StackInfo } from './react/utils/stack-info.js';
|
|
7
|
-
import type { DebugRefreshReasonBase,
|
|
8
|
-
import type {
|
|
9
|
-
import type { ParamsObject } from './utils/util.js';
|
|
9
|
+
import type { DebugRefreshReasonBase, Ref } from './reactive.js';
|
|
10
|
+
import type { LiveQuery, QueryContext, ReactivityGraph } from './reactiveQueries/base-class.js';
|
|
10
11
|
export type BaseGraphQLContext = {
|
|
11
12
|
queriedTables: Set<string>;
|
|
12
13
|
/** Needed by Pothos Otel plugin for resolver tracing to work */
|
|
@@ -16,15 +17,19 @@ export type GraphQLOptions<TContext> = {
|
|
|
16
17
|
schema: GraphQLSchema;
|
|
17
18
|
makeContext: (db: MainDatabaseWrapper, tracer: otel.Tracer) => TContext;
|
|
18
19
|
};
|
|
20
|
+
export type OtelOptions = {
|
|
21
|
+
tracer: otel.Tracer;
|
|
22
|
+
rootSpanContext: otel.Context;
|
|
23
|
+
};
|
|
19
24
|
export type StoreOptions<TGraphQLContext extends BaseGraphQLContext, TSchema extends LiveStoreSchema = LiveStoreSchema> = {
|
|
20
25
|
adapter: StoreAdapter;
|
|
21
26
|
schema: TSchema;
|
|
22
27
|
graphQLOptions?: GraphQLOptions<TGraphQLContext>;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
dbGraph: DbGraph;
|
|
26
|
-
mutationEventSchema: MutationEventSchema<any>;
|
|
28
|
+
otelOptions: OtelOptions;
|
|
29
|
+
reactivityGraph: ReactivityGraph;
|
|
27
30
|
disableDevtools?: boolean;
|
|
31
|
+
fiberSet: FiberSet.FiberSet;
|
|
32
|
+
__processedMutationIds: Set<string>;
|
|
28
33
|
};
|
|
29
34
|
export type RefreshReason = DebugRefreshReasonBase | {
|
|
30
35
|
_tag: 'mutate';
|
|
@@ -64,9 +69,11 @@ export type StoreMutateOptions = {
|
|
|
64
69
|
*/
|
|
65
70
|
persisted?: boolean;
|
|
66
71
|
};
|
|
67
|
-
export declare class Store<TGraphQLContext extends BaseGraphQLContext = BaseGraphQLContext, TSchema extends LiveStoreSchema = LiveStoreSchema> {
|
|
72
|
+
export declare class Store<TGraphQLContext extends BaseGraphQLContext = BaseGraphQLContext, TSchema extends LiveStoreSchema = LiveStoreSchema> extends Inspectable.Class {
|
|
68
73
|
id: string;
|
|
69
|
-
|
|
74
|
+
readonly devtoolsConnectionId: string;
|
|
75
|
+
private fiberSet;
|
|
76
|
+
reactivityGraph: ReactivityGraph;
|
|
70
77
|
mainDbWrapper: MainDatabaseWrapper;
|
|
71
78
|
adapter: StoreAdapter;
|
|
72
79
|
schema: LiveStoreSchema;
|
|
@@ -78,13 +85,13 @@ export declare class Store<TGraphQLContext extends BaseGraphQLContext = BaseGrap
|
|
|
78
85
|
* This only works in combination with `equal: () => false` which will always trigger a refresh.
|
|
79
86
|
*/
|
|
80
87
|
tableRefs: {
|
|
81
|
-
[key: string]: Ref<null,
|
|
88
|
+
[key: string]: Ref<null, QueryContext, RefreshReason>;
|
|
82
89
|
};
|
|
83
|
-
__processedMutationIds
|
|
84
|
-
__processedMutationWithoutRefreshIds
|
|
90
|
+
private __processedMutationIds;
|
|
91
|
+
private __processedMutationWithoutRefreshIds;
|
|
85
92
|
/** RC-based set to see which queries are currently subscribed to */
|
|
86
93
|
activeQueries: ReferenceCountedSet<LiveQuery<any>>;
|
|
87
|
-
readonly __mutationEventSchema: MutationEventSchema<
|
|
94
|
+
readonly __mutationEventSchema: import("@livestore/common/schema").MutationEventSchema<TSchema["_MutationDefMapType"]>;
|
|
88
95
|
private constructor();
|
|
89
96
|
static createStore: <TGraphQLContext_1 extends BaseGraphQLContext, TSchema_1 extends LiveStoreSchema = LiveStoreSchema>(storeOptions: StoreOptions<TGraphQLContext_1, TSchema_1>, parentSpan: otel.Span) => Store<TGraphQLContext_1, TSchema_1>;
|
|
90
97
|
/**
|
|
@@ -123,7 +130,7 @@ export declare class Store<TGraphQLContext extends BaseGraphQLContext = BaseGrap
|
|
|
123
130
|
*/
|
|
124
131
|
mutateWithoutRefresh: (mutationEventDecoded: MutationEvent.ForSchema<TSchema>, options: {
|
|
125
132
|
otelContext: otel.Context;
|
|
126
|
-
coordinatorMode:
|
|
133
|
+
coordinatorMode: "default" | "skip-coordinator" | "skip-persist";
|
|
127
134
|
}) => {
|
|
128
135
|
writeTables: ReadonlySet<string>;
|
|
129
136
|
durationMs: number;
|
|
@@ -135,24 +142,34 @@ export declare class Store<TGraphQLContext extends BaseGraphQLContext = BaseGrap
|
|
|
135
142
|
*/
|
|
136
143
|
execute: (query: string, params?: ParamsObject, writeTables?: ReadonlySet<string>, otelContext?: otel.Context) => void;
|
|
137
144
|
select: (query: string, params?: ParamsObject) => readonly any[];
|
|
138
|
-
makeTableRef: (tableName: string) => Ref<null,
|
|
145
|
+
makeTableRef: (tableName: string) => Ref<null, QueryContext, RefreshReason>;
|
|
139
146
|
private bootDevtools;
|
|
140
147
|
__devDownloadDb: () => void;
|
|
141
148
|
__devDownloadMutationLogDb: () => Promise<void>;
|
|
142
149
|
dangerouslyResetStorage: (mode: ResetMode) => Promise<void>;
|
|
150
|
+
toJSON: () => {
|
|
151
|
+
_tag: string;
|
|
152
|
+
reactivityGraph: import("./reactive.js").ReactiveGraphSnapshot;
|
|
153
|
+
};
|
|
143
154
|
}
|
|
144
|
-
|
|
145
|
-
export declare const createStore: <TGraphQLContext extends BaseGraphQLContext, TSchema extends LiveStoreSchema = LiveStoreSchema>({ schema, graphQLOptions, otelTracer, otelRootSpanContext, adapter: adapterFactory, boot, dbGraph, batchUpdates, disableDevtools, }: {
|
|
155
|
+
export type CreateStoreOptions<TGraphQLContext extends BaseGraphQLContext, TSchema extends LiveStoreSchema> = {
|
|
146
156
|
schema: TSchema;
|
|
147
|
-
graphQLOptions?: GraphQLOptions<TGraphQLContext>;
|
|
148
|
-
otelTracer?: otel.Tracer;
|
|
149
|
-
otelRootSpanContext?: otel.Context;
|
|
150
157
|
adapter: StoreAdapterFactory;
|
|
151
|
-
|
|
152
|
-
|
|
158
|
+
reactivityGraph?: ReactivityGraph;
|
|
159
|
+
graphQLOptions?: GraphQLOptions<TGraphQLContext>;
|
|
160
|
+
otelOptions?: Partial<OtelOptions>;
|
|
161
|
+
boot?: (db: BootDb, parentSpan: otel.Span) => void | Promise<void> | Effect.Effect<void, unknown, otel.Tracer>;
|
|
153
162
|
batchUpdates?: (run: () => void) => void;
|
|
154
163
|
disableDevtools?: boolean;
|
|
164
|
+
onBootStatus?: (status: BootStatus) => void;
|
|
165
|
+
};
|
|
166
|
+
/** Create a new LiveStore Store */
|
|
167
|
+
export declare const createStorePromise: <TGraphQLContext extends BaseGraphQLContext, TSchema extends LiveStoreSchema = LiveStoreSchema>({ signal, ...options }: CreateStoreOptions<TGraphQLContext, TSchema> & {
|
|
168
|
+
signal?: AbortSignal;
|
|
155
169
|
}) => Promise<Store<TGraphQLContext, TSchema>>;
|
|
170
|
+
export declare const createStore: <TGraphQLContext extends BaseGraphQLContext, TSchema extends LiveStoreSchema = LiveStoreSchema>({ schema, graphQLOptions, otelOptions, adapter: adapterFactory, boot, reactivityGraph, batchUpdates, disableDevtools, onBootStatus, fiberSet, }: CreateStoreOptions<TGraphQLContext, TSchema> & {
|
|
171
|
+
fiberSet: FiberSet.FiberSet;
|
|
172
|
+
}) => Effect.Effect<Store<TGraphQLContext, TSchema>, UnexpectedError, Scope.Scope>;
|
|
156
173
|
declare class ReferenceCountedSet<T> {
|
|
157
174
|
private map;
|
|
158
175
|
constructor();
|