@livestore/livestore 0.0.54-dev.25 → 0.0.54-dev.27
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/__tests__/react/fixture.d.ts.map +1 -1
- package/dist/__tests__/react/fixture.js +2 -2
- package/dist/__tests__/react/fixture.js.map +1 -1
- package/dist/effect/LiveStore.d.ts +14 -8
- package/dist/effect/LiveStore.d.ts.map +1 -1
- package/dist/effect/LiveStore.js +15 -16
- 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/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- 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.map +1 -1
- package/dist/react/LiveStoreProvider.d.ts +3 -2
- package/dist/react/LiveStoreProvider.d.ts.map +1 -1
- package/dist/react/LiveStoreProvider.js +63 -39
- package/dist/react/LiveStoreProvider.js.map +1 -1
- package/dist/react/LiveStoreProvider.test.js +28 -9
- package/dist/react/LiveStoreProvider.test.js.map +1 -1
- package/dist/react/useRow.test.js +1 -1
- package/dist/react/useRow.test.js.map +1 -1
- package/dist/reactiveQueries/sql.test.js +6 -6
- package/dist/reactiveQueries/sql.test.js.map +1 -1
- package/dist/store.d.ts +11 -4
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +52 -120
- package/dist/store.js.map +1 -1
- package/package.json +5 -5
- package/src/__tests__/react/fixture.tsx +2 -2
- package/src/effect/LiveStore.ts +48 -41
- package/src/effect/index.ts +2 -1
- package/src/index.ts +6 -2
- package/src/react/LiveStoreContext.ts +3 -2
- package/src/react/LiveStoreProvider.test.tsx +47 -10
- package/src/react/LiveStoreProvider.tsx +95 -38
- package/src/react/useRow.test.tsx +1 -1
- package/src/reactiveQueries/sql.test.ts +6 -6
- package/src/store.ts +234 -284
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fixture.d.ts","sourceRoot":"","sources":["../../../src/__tests__/react/fixture.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAE5D,OAAO,KAAK,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAC/C,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,OAAO,
|
|
1
|
+
{"version":3,"file":"fixture.d.ts","sourceRoot":"","sources":["../../../src/__tests__/react/fixture.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAE5D,OAAO,KAAK,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAC/C,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,OAAO,EAAsB,QAAQ,EAAoD,MAAM,gBAAgB,CAAA;AAG/G,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAId,CAAA;AAmBF,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAA4C,CAAA;AAC/D,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAAyB,CAAA;AAE5C,eAAO,MAAM,UAAU;;;;GAAyB,CAAA;AAEhD,eAAO,MAAM,WAAW,wEAKrB;IACD,UAAU,CAAC,EAAE,KAAK,MAAM,CAAA;IACxB,WAAW,CAAC,EAAE,KAAK,OAAO,CAAA;IAC1B,wBAAwB,CAAC,EAAE,OAAO,CAAA;IAClC,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;;4BAkCgC,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkBnC,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { makeInMemoryAdapter } from '@livestore/web';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { globalReactivityGraph } from '../../global-state.js';
|
|
4
|
-
import {
|
|
4
|
+
import { createStorePromise, DbSchema, makeReactivityGraph, makeSchema, ParseUtils, sql } from '../../index.js';
|
|
5
5
|
import * as LiveStoreReact from '../../react/index.js';
|
|
6
6
|
export const todos = DbSchema.table('todos', {
|
|
7
7
|
id: DbSchema.text({ primaryKey: true }),
|
|
@@ -37,7 +37,7 @@ export const makeTodoMvc = async ({ otelTracer, otelContext, useGlobalReactivity
|
|
|
37
37
|
inc,
|
|
38
38
|
};
|
|
39
39
|
};
|
|
40
|
-
const store = await
|
|
40
|
+
const store = await createStorePromise({
|
|
41
41
|
schema,
|
|
42
42
|
boot: (db) => db.execute(sql `INSERT OR IGNORE INTO app (id, newTodoText, filter) VALUES ('static', '', 'all');`),
|
|
43
43
|
adapter: makeInMemoryAdapter(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fixture.js","sourceRoot":"","sources":["../../../src/__tests__/react/fixture.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAEpD,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAE7D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"fixture.js","sourceRoot":"","sources":["../../../src/__tests__/react/fixture.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAEpD,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAE7D,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,mBAAmB,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AAC/G,OAAO,KAAK,cAAc,MAAM,sBAAsB,CAAA;AAetD,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,CAA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;QACvC,OAAO;QACP,kBAAkB,EAAE,QAAQ;QAC5B,eAAe;QACf,KAAK;QACL,eAAe;QACf,eAAe;QACf,UAAU;KACX,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import type { BootDb, StoreAdapterFactory } from '@livestore/common';
|
|
1
|
+
import type { BootDb, StoreAdapterFactory, UnexpectedError } from '@livestore/common';
|
|
2
2
|
import type { LiveStoreSchema } from '@livestore/common/schema';
|
|
3
|
-
import
|
|
4
|
-
import { Context, Deferred, Effect, Layer } from '@livestore/utils/effect';
|
|
3
|
+
import { Context, Deferred, Effect, Layer, Scope } from '@livestore/utils/effect';
|
|
5
4
|
import * as otel from '@opentelemetry/api';
|
|
6
5
|
import type { GraphQLSchema } from 'graphql';
|
|
7
6
|
import type { MainDatabaseWrapper } from '../MainDatabaseWrapper.js';
|
|
8
7
|
import type { LiveQuery } from '../reactiveQueries/base-class.js';
|
|
9
8
|
import type { BaseGraphQLContext, GraphQLOptions, OtelOptions, Store } from '../store.js';
|
|
10
|
-
export type LiveStoreContext = {
|
|
9
|
+
export type LiveStoreContext = LiveStoreContextRunning | {
|
|
10
|
+
stage: 'error';
|
|
11
|
+
error: UnexpectedError | unknown;
|
|
12
|
+
} | {
|
|
13
|
+
stage: 'shutdown';
|
|
14
|
+
};
|
|
15
|
+
export type LiveStoreContextRunning = {
|
|
11
16
|
stage: 'running';
|
|
12
17
|
store: Store;
|
|
13
18
|
};
|
|
@@ -20,9 +25,10 @@ export type LiveStoreCreateStoreOptions<GraphQLContext extends BaseGraphQLContex
|
|
|
20
25
|
adapter: StoreAdapterFactory;
|
|
21
26
|
batchUpdates?: (run: () => void) => void;
|
|
22
27
|
disableDevtools?: boolean;
|
|
28
|
+
signal?: AbortSignal;
|
|
23
29
|
};
|
|
24
|
-
export declare const
|
|
25
|
-
export type DeferredStoreContext = Deferred.Deferred<
|
|
30
|
+
export declare const LiveStoreContextRunning: Context.Tag<LiveStoreContextRunning, LiveStoreContextRunning>;
|
|
31
|
+
export type DeferredStoreContext = Deferred.Deferred<LiveStoreContextRunning>;
|
|
26
32
|
export declare const DeferredStoreContext: Context.Tag<DeferredStoreContext, DeferredStoreContext>;
|
|
27
33
|
export type LiveStoreContextProps<GraphQLContext extends BaseGraphQLContext> = {
|
|
28
34
|
schema: LiveStoreSchema;
|
|
@@ -34,7 +40,7 @@ export type LiveStoreContextProps<GraphQLContext extends BaseGraphQLContext> = {
|
|
|
34
40
|
adapter: StoreAdapterFactory;
|
|
35
41
|
disableDevtools?: boolean;
|
|
36
42
|
};
|
|
37
|
-
export declare const LiveStoreContextLayer: <GraphQLContext extends BaseGraphQLContext>(props: LiveStoreContextProps<GraphQLContext>) => Layer.Layer<
|
|
43
|
+
export declare const LiveStoreContextLayer: <GraphQLContext extends BaseGraphQLContext>(props: LiveStoreContextProps<GraphQLContext>) => Layer.Layer<LiveStoreContextRunning, never, otel.Tracer>;
|
|
38
44
|
export declare const LiveStoreContextDeferred: Layer.Layer<DeferredStoreContext, never, never>;
|
|
39
|
-
export declare const makeLiveStoreContext: <GraphQLContext extends BaseGraphQLContext>({ schema, graphQLOptions: graphQLOptions_, boot: boot_, adapter, disableDevtools, }: LiveStoreContextProps<GraphQLContext>) => Effect.Effect<
|
|
45
|
+
export declare const makeLiveStoreContext: <GraphQLContext extends BaseGraphQLContext>({ schema, graphQLOptions: graphQLOptions_, boot: boot_, adapter, disableDevtools, }: LiveStoreContextProps<GraphQLContext>) => Effect.Effect<LiveStoreContextRunning, never, DeferredStoreContext | Scope.Scope | otel.Tracer>;
|
|
40
46
|
//# sourceMappingURL=LiveStore.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LiveStore.d.ts","sourceRoot":"","sources":["../../src/effect/LiveStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"LiveStore.d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
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
import { Context, Deferred, Duration, Effect, Layer, OtelTracer, pipe, Runtime } from '@livestore/utils/effect';
|
|
1
|
+
import { Context, Deferred, Duration, Effect, Layer, OtelTracer, pipe, Runtime, Scope } from '@livestore/utils/effect';
|
|
2
2
|
import * as otel from '@opentelemetry/api';
|
|
3
3
|
import { createStore } from '../store.js';
|
|
4
|
-
export const
|
|
5
|
-
export const DeferredStoreContext = Context.GenericTag('@livestore/livestore/DeferredStoreContext');
|
|
6
|
-
export const LiveStoreContextLayer = (props) => Layer.scoped(
|
|
4
|
+
export const LiveStoreContextRunning = Context.GenericTag('@livestore/livestore/effect/LiveStoreContextRunning');
|
|
5
|
+
export const DeferredStoreContext = Context.GenericTag('@livestore/livestore/effect/DeferredStoreContext');
|
|
6
|
+
export const LiveStoreContextLayer = (props) => Layer.scoped(LiveStoreContextRunning, makeLiveStoreContext(props)).pipe(Layer.withSpan('LiveStore'), Layer.provide(LiveStoreContextDeferred));
|
|
7
7
|
export const LiveStoreContextDeferred = Layer.effect(DeferredStoreContext, Deferred.make());
|
|
8
|
-
export const makeLiveStoreContext = ({ schema, graphQLOptions: graphQLOptions_, boot: boot_, adapter, disableDevtools, }) => pipe(Effect.gen(function* (
|
|
9
|
-
const runtime = yield*
|
|
8
|
+
export const makeLiveStoreContext = ({ schema, graphQLOptions: graphQLOptions_, boot: boot_, adapter, disableDevtools, }) => pipe(Effect.gen(function* () {
|
|
9
|
+
const runtime = yield* Effect.runtime();
|
|
10
10
|
const otelRootSpanContext = otel.context.active();
|
|
11
|
-
const
|
|
12
|
-
|
|
11
|
+
const storeScope = yield* Scope.make();
|
|
12
|
+
yield* Effect.addFinalizer((ex) => Scope.close(storeScope, ex));
|
|
13
|
+
const otelTracer = yield* OtelTracer.Tracer;
|
|
14
|
+
const graphQLOptions = yield* graphQLOptions_
|
|
13
15
|
? Effect.all({ schema: graphQLOptions_.schema, makeContext: Effect.succeed(graphQLOptions_.makeContext) })
|
|
14
|
-
: Effect.succeed(undefined)
|
|
16
|
+
: Effect.succeed(undefined);
|
|
15
17
|
const boot = boot_
|
|
16
18
|
? (db) => boot_(db).pipe(Effect.withSpan('boot'), Effect.tapCauseLogPretty, Runtime.runPromise(runtime))
|
|
17
19
|
: undefined;
|
|
18
|
-
const store = yield*
|
|
20
|
+
const store = yield* createStore({
|
|
19
21
|
schema,
|
|
20
22
|
graphQLOptions,
|
|
21
23
|
otelOptions: {
|
|
@@ -25,12 +27,9 @@ export const makeLiveStoreContext = ({ schema, graphQLOptions: graphQLOptions_,
|
|
|
25
27
|
boot,
|
|
26
28
|
adapter,
|
|
27
29
|
disableDevtools,
|
|
28
|
-
|
|
30
|
+
storeScope,
|
|
31
|
+
});
|
|
29
32
|
window.__debugLiveStore = store;
|
|
30
33
|
return { stage: 'running', store };
|
|
31
|
-
}), Effect.tap((storeCtx) => Effect.flatMap(DeferredStoreContext, (def) => Deferred.succeed(def, storeCtx))), Effect.
|
|
32
|
-
// NOTE migrating from the mutation log can take a long time (so might need to increase this even further)
|
|
33
|
-
onTimeout: () => new Error('Timed out while creating LiveStore store after 60sec'),
|
|
34
|
-
duration: Duration.seconds(60),
|
|
35
|
-
}), Effect.orDie);
|
|
34
|
+
}), Effect.tap((storeCtx) => Effect.flatMap(DeferredStoreContext, (def) => Deferred.succeed(def, storeCtx))), Effect.timeout(Duration.seconds(60)), Effect.withSpan('@livestore/livestore/effect:makeLiveStoreContext'), Effect.orDie);
|
|
36
35
|
//# sourceMappingURL=LiveStore.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LiveStore.js","sourceRoot":"","sources":["../../src/effect/LiveStore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"LiveStore.js","sourceRoot":"","sources":["../../src/effect/LiveStore.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,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AAC,QAAQ,CAAC,kDAAkD,CAAC,EACnE,MAAM,CAAC,KAAK,CACb,CAAA"}
|
package/dist/effect/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { LiveStoreContextLayer, LiveStoreContext, LiveStoreContextDeferred, DeferredStoreContext, type LiveStoreContextProps, } from './LiveStore.js';
|
|
1
|
+
export { LiveStoreContextLayer, LiveStoreContextRunning as LiveStoreContext, LiveStoreContextRunning, LiveStoreContextDeferred, DeferredStoreContext, type LiveStoreContextProps, } from './LiveStore.js';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/effect/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/effect/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,uBAAuB,IAAI,gBAAgB,EAC3C,uBAAuB,EACvB,wBAAwB,EACxB,oBAAoB,EACpB,KAAK,qBAAqB,GAC3B,MAAM,gBAAgB,CAAA"}
|
package/dist/effect/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { LiveStoreContextLayer, LiveStoreContext, LiveStoreContextDeferred, DeferredStoreContext, } from './LiveStore.js';
|
|
1
|
+
export { LiveStoreContextLayer, LiveStoreContextRunning as LiveStoreContext, LiveStoreContextRunning, LiveStoreContextDeferred, DeferredStoreContext, } from './LiveStore.js';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/effect/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/effect/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/effect/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,uBAAuB,IAAI,gBAAgB,EAC3C,uBAAuB,EACvB,wBAAwB,EACxB,oBAAoB,GAErB,MAAM,gBAAgB,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { Store, createStore } from './store.js';
|
|
1
|
+
export { Store, createStorePromise, createStore } from './store.js';
|
|
2
2
|
export type { BaseGraphQLContext, QueryDebugInfo, RefreshReason } from './store.js';
|
|
3
|
-
export type { QueryDefinition, LiveStoreCreateStoreOptions, LiveStoreContext } from './effect/LiveStore.js';
|
|
3
|
+
export type { QueryDefinition, LiveStoreCreateStoreOptions, LiveStoreContextRunning as LiveStoreContext, } from './effect/LiveStore.js';
|
|
4
4
|
export { MainDatabaseWrapper, emptyDebugInfo } from './MainDatabaseWrapper.js';
|
|
5
5
|
export type { GetAtom, AtomDebugInfo, RefreshDebugInfo, ReactiveGraphSnapshot, SerializedAtom, SerializedEffect, Atom, Node, Ref, Effect, } from './reactive.js';
|
|
6
6
|
export { LiveStoreJSQuery, computed } from './reactiveQueries/js.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACnE,YAAY,EAAE,kBAAkB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAEnF,YAAY,EACV,eAAe,EACf,2BAA2B,EAC3B,uBAAuB,IAAI,gBAAgB,GAC5C,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAE9E,YAAY,EACV,OAAO,EACP,aAAa,EACb,gBAAgB,EAChB,qBAAqB,EACrB,cAAc,EACd,gBAAgB,EAChB,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,MAAM,GACP,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AACpE,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,KAAK,OAAO,EAAE,MAAM,0BAA0B,CAAA;AACpF,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAClF,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,mBAAmB,EACnB,KAAK,SAAS,GACf,MAAM,iCAAiC,CAAA;AAExC,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAEzD,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,gBAAgB,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEhG,cAAc,0BAA0B,CAAA;AACxC,OAAO,EACL,GAAG,EACH,KAAK,MAAM,EACX,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,iBAAiB,EACjB,KAAK,QAAQ,EACb,KAAK,kBAAkB,GACxB,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAEvD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,YAAY,EACV,YAAY,IAAI,YAAY,EAC5B,mBAAmB,IAAI,eAAe,EACtC,iBAAiB,GAClB,MAAM,mBAAmB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { Store, createStore } from './store.js';
|
|
1
|
+
export { Store, createStorePromise, createStore } from './store.js';
|
|
2
2
|
export { MainDatabaseWrapper, emptyDebugInfo } from './MainDatabaseWrapper.js';
|
|
3
3
|
export { LiveStoreJSQuery, computed } from './reactiveQueries/js.js';
|
|
4
4
|
export { LiveStoreSQLQuery, querySQL } from './reactiveQueries/sql.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AASnE,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAc9E,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AACpE,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAgB,MAAM,0BAA0B,CAAA;AACpF,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAClF,OAAO,EAGL,mBAAmB,GAEpB,MAAM,iCAAiC,CAAA;AAExC,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAEzD,OAAO,EAAyC,QAAQ,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEhG,cAAc,0BAA0B,CAAA;AACxC,OAAO,EACL,GAAG,EAMH,iBAAiB,GAGlB,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAEvD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type {
|
|
2
|
+
import type { LiveStoreContextRunning as LiveStoreContext_ } from '../effect/LiveStore.js';
|
|
3
|
+
import type { Store } from '../store.js';
|
|
3
4
|
export declare const LiveStoreContext: React.Context<LiveStoreContext_ | undefined>;
|
|
4
|
-
export declare const useStore: () =>
|
|
5
|
+
export declare const useStore: () => {
|
|
6
|
+
store: Store;
|
|
7
|
+
};
|
|
5
8
|
//# sourceMappingURL=LiveStoreContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LiveStoreContext.d.ts","sourceRoot":"","sources":["../../src/react/LiveStoreContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAqB,MAAM,OAAO,CAAA;AAEzC,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"LiveStoreContext.d.ts","sourceRoot":"","sources":["../../src/react/LiveStoreContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAqB,MAAM,OAAO,CAAA;AAEzC,OAAO,KAAK,EAAE,uBAAuB,IAAI,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1F,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAExC,eAAO,MAAM,gBAAgB,8CAAgE,CAAA;AAE7F,eAAO,MAAM,QAAQ,QAAO;IAAE,KAAK,EAAE,KAAK,CAAA;CAYzC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LiveStoreContext.js","sourceRoot":"","sources":["../../src/react/LiveStoreContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"LiveStoreContext.js","sourceRoot":"","sources":["../../src/react/LiveStoreContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAKzC,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAC,aAAa,CAAgC,SAAS,CAAC,CAAA;AAE7F,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAqB,EAAE;IAC7C,MAAM,YAAY,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAA;IAEjD,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAA;IAC3E,CAAC;IAED,IAAI,YAAY,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAA;IACzE,CAAC;IAED,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type BootDb, type BootStatus, type StoreAdapterFactory } from '@livestore/common';
|
|
2
2
|
import type { LiveStoreSchema } from '@livestore/common/schema';
|
|
3
3
|
import type * as otel from '@opentelemetry/api';
|
|
4
4
|
import type { ReactElement, ReactNode } from 'react';
|
|
@@ -12,8 +12,9 @@ interface LiveStoreProviderProps<GraphQLContext> {
|
|
|
12
12
|
adapter: StoreAdapterFactory;
|
|
13
13
|
batchUpdates?: (run: () => void) => void;
|
|
14
14
|
disableDevtools?: boolean;
|
|
15
|
+
signal?: AbortSignal;
|
|
15
16
|
}
|
|
16
|
-
export declare const LiveStoreProvider: <GraphQLContext extends BaseGraphQLContext>({ renderLoading, graphQLOptions, otelOptions, children, schema, boot, adapter, batchUpdates, disableDevtools, }: LiveStoreProviderProps<GraphQLContext> & {
|
|
17
|
+
export declare const LiveStoreProvider: <GraphQLContext extends BaseGraphQLContext>({ renderLoading, graphQLOptions, otelOptions, children, schema, boot, adapter, batchUpdates, disableDevtools, signal, }: LiveStoreProviderProps<GraphQLContext> & {
|
|
17
18
|
children?: ReactNode;
|
|
18
19
|
}) => JSX.Element;
|
|
19
20
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LiveStoreProvider.d.ts","sourceRoot":"","sources":["../../src/react/LiveStoreProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"LiveStoreProvider.d.ts","sourceRoot":"","sources":["../../src/react/LiveStoreProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,UAAU,EAAE,KAAK,mBAAmB,EAAmB,MAAM,mBAAmB,CAAA;AAC3G,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAG/D,OAAO,KAAK,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAKpD,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAIlF,UAAU,sBAAsB,CAAC,cAAc;IAC7C,MAAM,EAAE,eAAe,CAAA;IACvB,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,IAAI,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IACxE,cAAc,CAAC,EAAE,cAAc,CAAC,cAAc,CAAC,CAAA;IAC/C,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,aAAa,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,YAAY,CAAA;IACnD,OAAO,EAAE,mBAAmB,CAAA;IAC5B,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,IAAI,KAAK,IAAI,CAAA;IACxC,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB;AAED,eAAO,MAAM,iBAAiB,uKAW3B,uBAAuB,cAAc,CAAC,GAAG;IAAE,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,KAAG,WA+BtE,CAAA"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UnexpectedError } from '@livestore/common';
|
|
2
|
+
import { errorToString } from '@livestore/utils';
|
|
3
|
+
import { Effect, Exit, Logger, LogLevel, Schema, Scope } from '@livestore/utils/effect';
|
|
2
4
|
import React from 'react';
|
|
3
5
|
import { createStore } from '../store.js';
|
|
4
6
|
import { LiveStoreContext } from './LiveStoreContext.js';
|
|
5
|
-
export const LiveStoreProvider = ({ renderLoading, graphQLOptions, otelOptions, children, schema, boot, adapter, batchUpdates, disableDevtools, }) => {
|
|
7
|
+
export const LiveStoreProvider = ({ renderLoading, graphQLOptions, otelOptions, children, schema, boot, adapter, batchUpdates, disableDevtools, signal, }) => {
|
|
6
8
|
const storeCtx = useCreateStore({
|
|
7
9
|
schema,
|
|
8
10
|
graphQLOptions,
|
|
@@ -11,16 +13,28 @@ export const LiveStoreProvider = ({ renderLoading, graphQLOptions, otelOptions,
|
|
|
11
13
|
adapter,
|
|
12
14
|
batchUpdates,
|
|
13
15
|
disableDevtools,
|
|
16
|
+
signal,
|
|
14
17
|
});
|
|
18
|
+
if (storeCtx.stage === 'error') {
|
|
19
|
+
return (React.createElement("div", null, Schema.is(UnexpectedError)(storeCtx.error) ? storeCtx.error.toString() : errorToString(storeCtx.error)));
|
|
20
|
+
}
|
|
21
|
+
if (storeCtx.stage === 'shutdown') {
|
|
22
|
+
return React.createElement("div", null, "LiveStore Shutdown");
|
|
23
|
+
}
|
|
15
24
|
if (storeCtx.stage !== 'running') {
|
|
16
25
|
return React.createElement("div", null, renderLoading(storeCtx));
|
|
17
26
|
}
|
|
18
27
|
window.__debugLiveStore = storeCtx.store;
|
|
19
28
|
return React.createElement(LiveStoreContext.Provider, { value: storeCtx }, children);
|
|
20
29
|
};
|
|
21
|
-
const useCreateStore = ({ schema, graphQLOptions, otelOptions, boot, adapter, batchUpdates, disableDevtools, }) => {
|
|
30
|
+
const useCreateStore = ({ schema, graphQLOptions, otelOptions, boot, adapter, batchUpdates, disableDevtools, signal, }) => {
|
|
22
31
|
const [_, rerender] = React.useState(0);
|
|
23
|
-
const ctxValueRef = React.useRef({
|
|
32
|
+
const ctxValueRef = React.useRef({
|
|
33
|
+
value: { stage: 'loading' },
|
|
34
|
+
scope: undefined,
|
|
35
|
+
counter: 0,
|
|
36
|
+
});
|
|
37
|
+
// console.debug(`useCreateStore (${ctxValueRef.current.counter})`, ctxValueRef.current.value.stage)
|
|
24
38
|
const inputPropsCacheRef = React.useRef({
|
|
25
39
|
schema,
|
|
26
40
|
graphQLOptions,
|
|
@@ -28,14 +42,17 @@ const useCreateStore = ({ schema, graphQLOptions, otelOptions, boot, adapter, ba
|
|
|
28
42
|
boot,
|
|
29
43
|
adapter,
|
|
30
44
|
batchUpdates,
|
|
45
|
+
disableDevtools,
|
|
46
|
+
signal,
|
|
31
47
|
});
|
|
32
|
-
const oldStoreAlreadyDestroyedRef = React.useRef(false);
|
|
33
48
|
if (inputPropsCacheRef.current.schema !== schema ||
|
|
34
49
|
inputPropsCacheRef.current.graphQLOptions !== graphQLOptions ||
|
|
35
50
|
inputPropsCacheRef.current.otelOptions !== otelOptions ||
|
|
36
51
|
inputPropsCacheRef.current.boot !== boot ||
|
|
37
52
|
inputPropsCacheRef.current.adapter !== adapter ||
|
|
38
|
-
inputPropsCacheRef.current.batchUpdates !== batchUpdates
|
|
53
|
+
inputPropsCacheRef.current.batchUpdates !== batchUpdates ||
|
|
54
|
+
inputPropsCacheRef.current.disableDevtools !== disableDevtools ||
|
|
55
|
+
inputPropsCacheRef.current.signal !== signal) {
|
|
39
56
|
inputPropsCacheRef.current = {
|
|
40
57
|
schema,
|
|
41
58
|
graphQLOptions,
|
|
@@ -43,46 +60,53 @@ const useCreateStore = ({ schema, graphQLOptions, otelOptions, boot, adapter, ba
|
|
|
43
60
|
boot,
|
|
44
61
|
adapter,
|
|
45
62
|
batchUpdates,
|
|
63
|
+
disableDevtools,
|
|
64
|
+
signal,
|
|
46
65
|
};
|
|
47
|
-
if (ctxValueRef.current.
|
|
48
|
-
ctxValueRef.current.
|
|
49
|
-
oldStoreAlreadyDestroyedRef.current = true;
|
|
50
|
-
ctxValueRef.current = { stage: 'loading' };
|
|
66
|
+
if (ctxValueRef.current.scope !== undefined) {
|
|
67
|
+
Scope.close(ctxValueRef.current.scope, Exit.void).pipe(Effect.tapCauseLogPretty, Effect.runFork);
|
|
51
68
|
}
|
|
69
|
+
ctxValueRef.current = { value: { stage: 'loading' }, scope: undefined, counter: ctxValueRef.current.counter + 1 };
|
|
52
70
|
}
|
|
53
71
|
React.useEffect(() => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
ctxValueRef.current = status;
|
|
69
|
-
rerender((c) => c + 1);
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
ctxValueRef.current = { stage: 'running', store };
|
|
73
|
-
oldStoreAlreadyDestroyedRef.current = false;
|
|
74
|
-
rerender((c) => c + 1);
|
|
75
|
-
}
|
|
76
|
-
catch (e) {
|
|
77
|
-
shouldNeverHappen(`Error creating LiveStore store: ${e}`);
|
|
72
|
+
const storeScope = Scope.make().pipe(Effect.runSync);
|
|
73
|
+
const counter = ctxValueRef.current.counter;
|
|
74
|
+
const setContextValue = (value) => {
|
|
75
|
+
if (ctxValueRef.current.counter !== counter)
|
|
76
|
+
return;
|
|
77
|
+
ctxValueRef.current.value = value;
|
|
78
|
+
rerender((c) => c + 1);
|
|
79
|
+
};
|
|
80
|
+
Scope.addFinalizer(storeScope, Effect.sync(() => setContextValue({ stage: 'shutdown' }))).pipe(Effect.runSync);
|
|
81
|
+
ctxValueRef.current.scope = storeScope;
|
|
82
|
+
signal?.addEventListener('abort', () => {
|
|
83
|
+
if (ctxValueRef.current.scope !== undefined && ctxValueRef.current.counter === counter) {
|
|
84
|
+
Scope.close(ctxValueRef.current.scope, Exit.void).pipe(Effect.tapCauseLogPretty, Effect.runFork);
|
|
85
|
+
ctxValueRef.current.scope = undefined;
|
|
78
86
|
}
|
|
79
|
-
})
|
|
87
|
+
});
|
|
88
|
+
createStore({
|
|
89
|
+
storeScope,
|
|
90
|
+
schema,
|
|
91
|
+
graphQLOptions,
|
|
92
|
+
otelOptions,
|
|
93
|
+
boot,
|
|
94
|
+
adapter,
|
|
95
|
+
batchUpdates,
|
|
96
|
+
disableDevtools,
|
|
97
|
+
onBootStatus: (status) => {
|
|
98
|
+
if (ctxValueRef.current.value.stage === 'running' || ctxValueRef.current.value.stage === 'error')
|
|
99
|
+
return;
|
|
100
|
+
setContextValue(status);
|
|
101
|
+
},
|
|
102
|
+
}).pipe(Effect.tapSync((store) => setContextValue({ stage: 'running', store })), Effect.tapError((error) => Effect.sync(() => setContextValue({ stage: 'error', error }))), Effect.tapDefect((defect) => Effect.sync(() => setContextValue({ stage: 'error', error: defect }))), Scope.extend(storeScope), Effect.forkIn(storeScope), Effect.tapCauseLogPretty, Effect.annotateLogs({ thread: 'window' }), Effect.provide(Logger.pretty), Logger.withMinimumLogLevel(LogLevel.Debug), Effect.runFork);
|
|
80
103
|
return () => {
|
|
81
|
-
if (
|
|
82
|
-
|
|
104
|
+
if (ctxValueRef.current.scope !== undefined) {
|
|
105
|
+
Scope.close(ctxValueRef.current.scope, Exit.void).pipe(Effect.tapCauseLogPretty, Effect.runFork);
|
|
106
|
+
ctxValueRef.current.scope = undefined;
|
|
83
107
|
}
|
|
84
108
|
};
|
|
85
|
-
}, [schema, graphQLOptions, otelOptions, boot, adapter, batchUpdates, disableDevtools]);
|
|
86
|
-
return ctxValueRef.current;
|
|
109
|
+
}, [schema, graphQLOptions, otelOptions, boot, adapter, batchUpdates, disableDevtools, signal]);
|
|
110
|
+
return ctxValueRef.current.value;
|
|
87
111
|
};
|
|
88
112
|
//# sourceMappingURL=LiveStoreProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LiveStoreProvider.js","sourceRoot":"","sources":["../../src/react/LiveStoreProvider.tsx"],"names":[],"mappings":"
|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AK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EACnG,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,EACxB,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,EACzB,MAAM,CAAC,iBAAiB,EACxB,MAAM,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,EACzC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAC7B,MAAM,CAAC,mBAAmB,CAAC,QAAQ,CAAC,KAAK,CAAC,EAC1C,MAAM,CAAC,OAAO,CACf,CAAA;QAED,OAAO,GAAG,EAAE;YACV,IAAI,WAAW,CAAC,OAAO,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;gBAC5C,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,MAAM,CAAC,OAAO,CAAC,CAAA;gBAChG,WAAW,CAAC,OAAO,CAAC,KAAK,GAAG,SAAS,CAAA;YACvC,CAAC;QACH,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,CAAC,CAAC,CAAA;IAE/F,OAAO,WAAW,CAAC,OAAO,CAAC,KAAK,CAAA;AAClC,CAAC,CAAA"}
|
|
@@ -9,33 +9,52 @@ import * as LiveStoreReact from './index.js';
|
|
|
9
9
|
import { LiveStoreProvider } from './LiveStoreProvider.js';
|
|
10
10
|
describe('LiveStoreProvider', () => {
|
|
11
11
|
it('simple', async () => {
|
|
12
|
-
let
|
|
12
|
+
let appRenderCount = 0;
|
|
13
13
|
const allTodos$ = querySQL(`select * from todos`, { map: parseTodos });
|
|
14
|
-
let latestStoreCtx = undefined;
|
|
15
14
|
const App = () => {
|
|
16
|
-
|
|
17
|
-
latestStoreCtx = LiveStoreReact.useStore();
|
|
15
|
+
appRenderCount++;
|
|
18
16
|
const todos = LiveStoreReact.useQuery(allTodos$);
|
|
19
17
|
return React.createElement("div", null, JSON.stringify(todos));
|
|
20
18
|
};
|
|
19
|
+
const abortController = new AbortController();
|
|
21
20
|
const Root = ({ forceUpdate }) => {
|
|
22
21
|
const bootCb = React.useCallback((db) => db.execute(sql `INSERT OR IGNORE INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0);`), []);
|
|
23
22
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
24
23
|
const adapterMemo = React.useMemo(() => makeInMemoryAdapter(), [forceUpdate]);
|
|
25
24
|
return (React.createElement(LiveStoreProvider, { schema: schema, renderLoading: (status) => React.createElement("div", null,
|
|
26
25
|
"Loading LiveStore: ",
|
|
27
|
-
status.stage), adapter: adapterMemo, boot: bootCb },
|
|
26
|
+
status.stage), adapter: adapterMemo, boot: bootCb, signal: abortController.signal },
|
|
28
27
|
React.createElement(App, null)));
|
|
29
28
|
};
|
|
30
29
|
const { rerender } = render(React.createElement(Root, { forceUpdate: 1 }));
|
|
31
|
-
expect(
|
|
30
|
+
expect(appRenderCount).toBe(0);
|
|
32
31
|
await waitForElementToBeRemoved(() => screen.getByText((_) => _.startsWith('Loading LiveStore')));
|
|
33
|
-
expect(
|
|
32
|
+
expect(appRenderCount).toBe(1);
|
|
34
33
|
rerender(React.createElement(Root, { forceUpdate: 2 }));
|
|
35
34
|
await waitFor(() => screen.getByText('Loading LiveStore: loading'));
|
|
36
35
|
await waitForElementToBeRemoved(() => screen.getByText((_) => _.startsWith('Loading LiveStore')));
|
|
37
|
-
expect(
|
|
38
|
-
|
|
36
|
+
expect(appRenderCount).toBe(2);
|
|
37
|
+
abortController.abort();
|
|
38
|
+
await waitFor(() => screen.getByText('LiveStore Shutdown'));
|
|
39
|
+
});
|
|
40
|
+
it('error during boot', async () => {
|
|
41
|
+
let appRenderCount = 0;
|
|
42
|
+
const App = () => {
|
|
43
|
+
appRenderCount++;
|
|
44
|
+
return React.createElement("div", null, "hello world");
|
|
45
|
+
};
|
|
46
|
+
const Root = ({ forceUpdate }) => {
|
|
47
|
+
const bootCb = React.useCallback((db) => db.execute(sql `INSERT INTO todos_mising_table (id, text, completed) VALUES ('t1', 'buy milk', 0);`), []);
|
|
48
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
49
|
+
const adapterMemo = React.useMemo(() => makeInMemoryAdapter(), [forceUpdate]);
|
|
50
|
+
return (React.createElement(LiveStoreProvider, { schema: schema, renderLoading: (status) => React.createElement("div", null,
|
|
51
|
+
"Loading LiveStore: ",
|
|
52
|
+
status.stage), adapter: adapterMemo, boot: bootCb },
|
|
53
|
+
React.createElement(App, null)));
|
|
54
|
+
};
|
|
55
|
+
render(React.createElement(Root, { forceUpdate: 1 }));
|
|
56
|
+
expect(appRenderCount).toBe(0);
|
|
57
|
+
await waitFor(() => screen.getByText((_) => _.startsWith('LiveStore.UnexpectedError')));
|
|
39
58
|
});
|
|
40
59
|
});
|
|
41
60
|
//# sourceMappingURL=LiveStoreProvider.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LiveStoreProvider.test.js","sourceRoot":"","sources":["../../src/react/LiveStoreProvider.test.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AACvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAA;AAC3F,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7C,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAA;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,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AC,CAAC,CAAC,UAAU,CAAC,2BAA2B,CAAC,CAAC,CAAC,CAAA;IACzF,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -163,7 +163,7 @@ describe.concurrent('useRow', () => {
|
|
|
163
163
|
expect(result.current.state.username).toBe('username_u2');
|
|
164
164
|
expect(renderCount.val).toBe(2);
|
|
165
165
|
unmount();
|
|
166
|
-
store.destroy();
|
|
166
|
+
await store.destroy();
|
|
167
167
|
span.end();
|
|
168
168
|
const mapAttributes = (attributes) => {
|
|
169
169
|
return ReadonlyRecord.map(attributes, (val, key) => {
|