@livestore/livestore 0.4.0-dev.21 → 0.4.0-dev.22
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 +123 -2
- package/dist/effect/LiveStore.d.ts.map +1 -1
- package/dist/effect/LiveStore.js +195 -1
- package/dist/effect/LiveStore.js.map +1 -1
- package/dist/effect/mod.d.ts +1 -1
- package/dist/effect/mod.d.ts.map +1 -1
- package/dist/effect/mod.js +3 -1
- package/dist/effect/mod.js.map +1 -1
- package/dist/mod.d.ts +1 -0
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js +1 -0
- package/dist/mod.js.map +1 -1
- package/dist/store/StoreRegistry.d.ts +190 -0
- package/dist/store/StoreRegistry.d.ts.map +1 -0
- package/dist/store/StoreRegistry.js +244 -0
- package/dist/store/StoreRegistry.js.map +1 -0
- package/dist/store/StoreRegistry.test.d.ts +2 -0
- package/dist/store/StoreRegistry.test.d.ts.map +1 -0
- package/dist/store/StoreRegistry.test.js +380 -0
- package/dist/store/StoreRegistry.test.js.map +1 -0
- package/dist/store/create-store.d.ts +50 -4
- package/dist/store/create-store.d.ts.map +1 -1
- package/dist/store/create-store.js +19 -0
- package/dist/store/create-store.js.map +1 -1
- package/dist/store/devtools.d.ts.map +1 -1
- package/dist/store/devtools.js +13 -0
- package/dist/store/devtools.js.map +1 -1
- package/dist/store/store-types.d.ts +10 -25
- package/dist/store/store-types.d.ts.map +1 -1
- package/dist/store/store-types.js.map +1 -1
- package/dist/store/store.d.ts +23 -6
- package/dist/store/store.d.ts.map +1 -1
- package/dist/store/store.js +20 -2
- package/dist/store/store.js.map +1 -1
- package/docs/building-with-livestore/complex-ui-state/index.md +0 -2
- package/docs/building-with-livestore/crud/index.md +0 -2
- package/docs/building-with-livestore/data-modeling/index.md +29 -0
- package/docs/building-with-livestore/examples/todo-workspaces/index.md +0 -6
- package/docs/building-with-livestore/opentelemetry/index.md +25 -6
- package/docs/building-with-livestore/rules-for-ai-agents/index.md +2 -2
- package/docs/building-with-livestore/state/sql-queries/index.md +22 -0
- package/docs/building-with-livestore/state/sqlite-schema/index.md +2 -2
- package/docs/building-with-livestore/store/index.md +344 -0
- package/docs/framework-integrations/react-integration/index.md +380 -361
- package/docs/framework-integrations/vue-integration/index.md +2 -2
- package/docs/getting-started/expo/index.md +189 -43
- package/docs/getting-started/react-web/index.md +77 -24
- package/docs/getting-started/vue/index.md +3 -3
- package/docs/index.md +1 -2
- package/docs/llms.txt +0 -1
- package/docs/misc/troubleshooting/index.md +3 -3
- package/docs/overview/how-livestore-works/index.md +1 -1
- package/docs/overview/introduction/index.md +409 -1
- package/docs/overview/why-livestore/index.md +108 -2
- package/docs/patterns/auth/index.md +185 -34
- package/docs/patterns/effect/index.md +11 -1
- package/docs/patterns/storybook/index.md +43 -26
- package/docs/platform-adapters/expo-adapter/index.md +36 -19
- package/docs/platform-adapters/web-adapter/index.md +71 -2
- package/docs/tutorial/1-setup-starter-project/index.md +5 -5
- package/docs/tutorial/3-read-and-write-todos-via-livestore/index.md +54 -35
- package/docs/tutorial/5-expand-business-logic/index.md +1 -1
- package/docs/tutorial/6-persist-ui-state/index.md +12 -12
- package/package.json +6 -6
- package/src/effect/LiveStore.ts +385 -3
- package/src/effect/mod.ts +13 -1
- package/src/mod.ts +1 -0
- package/src/store/StoreRegistry.test.ts +516 -0
- package/src/store/StoreRegistry.ts +393 -0
- package/src/store/create-store.ts +50 -4
- package/src/store/devtools.ts +15 -0
- package/src/store/store-types.ts +17 -5
- package/src/store/store.ts +25 -5
- package/docs/building-with-livestore/examples/index.md +0 -30
|
@@ -1,10 +1,131 @@
|
|
|
1
1
|
import type { UnknownError } from '@livestore/common';
|
|
2
|
-
import type { LiveStoreSchema } from '@livestore/common/schema';
|
|
2
|
+
import type { LiveStoreEvent, LiveStoreSchema } from '@livestore/common/schema';
|
|
3
3
|
import type { Cause, OtelTracer, Scope } from '@livestore/utils/effect';
|
|
4
|
-
import { Effect, Layer } from '@livestore/utils/effect';
|
|
4
|
+
import { Context, Deferred, Effect, Layer } from '@livestore/utils/effect';
|
|
5
5
|
import type { LiveStoreContextProps } from '../store/create-store.ts';
|
|
6
6
|
import { DeferredStoreContext, LiveStoreContextRunning } from '../store/create-store.ts';
|
|
7
|
+
import type { LiveStoreContextRunning as LiveStoreContextRunningType, Queryable } from '../store/store-types.ts';
|
|
7
8
|
export declare const makeLiveStoreContext: <TSchema extends LiveStoreSchema, TContext = {}>({ schema, storeId, context, boot, adapter, disableDevtools, onBootStatus, batchUpdates, syncPayload, syncPayloadSchema, }: LiveStoreContextProps<TSchema, TContext>) => Effect.Effect<LiveStoreContextRunning["Type"], UnknownError | Cause.TimeoutException, DeferredStoreContext | Scope.Scope | OtelTracer.OtelTracer>;
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated Use `Store.Tag(schema, storeId)` instead for type-safe store contexts.
|
|
11
|
+
*
|
|
12
|
+
* @example Migration
|
|
13
|
+
* ```ts
|
|
14
|
+
* // Before
|
|
15
|
+
* const layer = LiveStoreContextLayer({ schema, adapter, ... })
|
|
16
|
+
*
|
|
17
|
+
* // After
|
|
18
|
+
* class MainStore extends Store.Tag(schema, 'main') {}
|
|
19
|
+
* const layer = MainStore.layer({ adapter, ... })
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
8
22
|
export declare const LiveStoreContextLayer: <TSchema extends LiveStoreSchema, TContext = {}>(props: LiveStoreContextProps<TSchema, TContext>) => Layer.Layer<LiveStoreContextRunning, UnknownError | Cause.TimeoutException, OtelTracer.OtelTracer>;
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated Use `Store.Tag(schema, storeId)` and `MainStore.DeferredLayer` instead.
|
|
25
|
+
*/
|
|
9
26
|
export declare const LiveStoreContextDeferred: Layer.Layer<DeferredStoreContext, never, never>;
|
|
27
|
+
/** Branded type for unique store context identity */
|
|
28
|
+
declare const StoreContextTypeId: unique symbol;
|
|
29
|
+
/** Phantom type carrying schema and storeId information */
|
|
30
|
+
export interface StoreContextId<TSchema extends LiveStoreSchema, TStoreId extends string> {
|
|
31
|
+
readonly [StoreContextTypeId]: {
|
|
32
|
+
readonly schema: TSchema;
|
|
33
|
+
readonly storeId: TStoreId;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/** Phantom type for deferred store context */
|
|
37
|
+
declare const DeferredContextTypeId: unique symbol;
|
|
38
|
+
export interface DeferredContextId<TStoreId extends string> {
|
|
39
|
+
readonly [DeferredContextTypeId]: {
|
|
40
|
+
readonly storeId: TStoreId;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** Props for creating a store layer (schema and storeId are already provided) */
|
|
44
|
+
export type StoreLayerProps<TSchema extends LiveStoreSchema, TContext = {}> = Omit<LiveStoreContextProps<TSchema, TContext>, 'storeId' | 'schema'>;
|
|
45
|
+
/**
|
|
46
|
+
* Type for a Store.Tag class. This is the return type of `Store.Tag(schema, storeId)`.
|
|
47
|
+
* Can be extended as a class and is yieldable in Effect.gen.
|
|
48
|
+
*
|
|
49
|
+
* Note: This uses a type alias with a new() signature to make it extendable.
|
|
50
|
+
*/
|
|
51
|
+
export type StoreTagClass<TSchema extends LiveStoreSchema, TStoreId extends string> = {
|
|
52
|
+
/** Constructor signature (makes the type extendable as a class) */
|
|
53
|
+
new (): Context.Tag<StoreContextId<TSchema, TStoreId>, LiveStoreContextRunningType<TSchema>>;
|
|
54
|
+
/** Tag identity type (from Context.Tag) */
|
|
55
|
+
readonly Id: StoreContextId<TSchema, TStoreId>;
|
|
56
|
+
/** Service type (from Context.Tag) */
|
|
57
|
+
readonly Type: LiveStoreContextRunningType<TSchema>;
|
|
58
|
+
/** The LiveStore schema for this store */
|
|
59
|
+
readonly schema: TSchema;
|
|
60
|
+
/** Unique identifier for this store */
|
|
61
|
+
readonly storeId: TStoreId;
|
|
62
|
+
/** Creates a layer that initializes the store */
|
|
63
|
+
layer<TContext = {}>(props: StoreLayerProps<TSchema, TContext>): Layer.Layer<StoreTagClass<TSchema, TStoreId>, UnknownError | Cause.TimeoutException, OtelTracer.OtelTracer>;
|
|
64
|
+
/** Deferred store tag for async initialization patterns */
|
|
65
|
+
readonly Deferred: Context.Tag<DeferredContextId<TStoreId>, Deferred.Deferred<LiveStoreContextRunningType<TSchema>, UnknownError>>;
|
|
66
|
+
/** Layer that provides the Deferred tag */
|
|
67
|
+
readonly DeferredLayer: Layer.Layer<DeferredContextId<TStoreId>, never, never>;
|
|
68
|
+
/** Layer that waits for Deferred and provides the running store */
|
|
69
|
+
readonly fromDeferred: Layer.Layer<StoreTagClass<TSchema, TStoreId>, UnknownError, DeferredContextId<TStoreId>>;
|
|
70
|
+
/** Query the store. Returns an Effect that yields the query result. */
|
|
71
|
+
query<TResult>(query: Queryable<TResult>): Effect.Effect<TResult, never, StoreTagClass<TSchema, TStoreId>>;
|
|
72
|
+
/** Commit events to the store. */
|
|
73
|
+
commit(...eventInputs: LiveStoreEvent.Input.ForSchema<TSchema>[]): Effect.Effect<void, never, StoreTagClass<TSchema, TStoreId>>;
|
|
74
|
+
/** Use the store with a callback function. */
|
|
75
|
+
use<A, E, R>(f: (ctx: LiveStoreContextRunningType<TSchema>) => Effect.Effect<A, E, R>): Effect.Effect<A, E, R | StoreTagClass<TSchema, TStoreId>>;
|
|
76
|
+
} & Context.Tag<StoreContextId<TSchema, TStoreId>, LiveStoreContextRunningType<TSchema>>;
|
|
77
|
+
/**
|
|
78
|
+
* Store utilities for Effect integration.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* import { Store } from '@livestore/livestore/effect'
|
|
83
|
+
*
|
|
84
|
+
* export class MainStore extends Store.Tag(schema, 'main') {}
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export declare const Store: {
|
|
88
|
+
/**
|
|
89
|
+
* Create a typed store context class for use with Effect.
|
|
90
|
+
* @see {@link makeStoreTag} for full documentation
|
|
91
|
+
*/
|
|
92
|
+
Tag: <TSchema extends LiveStoreSchema, TStoreId extends string>(schema: TSchema, storeId: TStoreId) => StoreTagClass<TSchema, TStoreId>;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* @deprecated Use `Store.Tag(schema, storeId)` instead.
|
|
96
|
+
*
|
|
97
|
+
* @example Migration
|
|
98
|
+
* ```ts
|
|
99
|
+
* // Before
|
|
100
|
+
* const MainStoreContext = makeStoreContext<typeof schema>()('main')
|
|
101
|
+
* export const MainStore = MainStoreContext.Tag
|
|
102
|
+
* export const MainStoreLayer = MainStoreContext.Layer
|
|
103
|
+
*
|
|
104
|
+
* // After
|
|
105
|
+
* export class MainStore extends Store.Tag(schema, 'main') {}
|
|
106
|
+
* // MainStore.layer({ ... }) for the layer
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
export interface StoreContext<TSchema extends LiveStoreSchema, TStoreId extends string> {
|
|
110
|
+
readonly storeId: TStoreId;
|
|
111
|
+
readonly Tag: Context.Tag<StoreContextId<TSchema, TStoreId>, LiveStoreContextRunningType<TSchema>>;
|
|
112
|
+
readonly DeferredTag: Context.Tag<DeferredContextId<TStoreId>, Deferred.Deferred<LiveStoreContextRunningType<TSchema>, UnknownError>>;
|
|
113
|
+
readonly Layer: <TContext = {}>(props: Omit<LiveStoreContextProps<TSchema, TContext>, 'storeId'>) => Layer.Layer<StoreContextId<TSchema, TStoreId>, UnknownError | Cause.TimeoutException, OtelTracer.OtelTracer>;
|
|
114
|
+
readonly DeferredLayer: Layer.Layer<DeferredContextId<TStoreId>, never, never>;
|
|
115
|
+
readonly fromDeferred: Layer.Layer<StoreContextId<TSchema, TStoreId>, UnknownError, DeferredContextId<TStoreId>>;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* @deprecated Use `Store.Tag(schema, storeId)` instead.
|
|
119
|
+
*
|
|
120
|
+
* @example Migration
|
|
121
|
+
* ```ts
|
|
122
|
+
* // Before
|
|
123
|
+
* const MainStoreContext = makeStoreContext<typeof schema>()('main')
|
|
124
|
+
*
|
|
125
|
+
* // After
|
|
126
|
+
* class MainStore extends Store.Tag(schema, 'main') {}
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export declare const makeStoreContext: <TSchema extends LiveStoreSchema>() => <TStoreId extends string>(storeId: TStoreId) => StoreContext<TSchema, TStoreId>;
|
|
130
|
+
export {};
|
|
10
131
|
//# 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,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAE/
|
|
1
|
+
{"version":3,"file":"LiveStore.d.ts","sourceRoot":"","sources":["../../src/effect/LiveStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAE/E,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AACvE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAY,MAAM,EAAE,KAAK,EAAQ,MAAM,yBAAyB,CAAA;AAC1F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAA;AACrE,OAAO,EAAe,oBAAoB,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAA;AAErG,OAAO,KAAK,EAAE,uBAAuB,IAAI,2BAA2B,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAEhH,eAAO,MAAM,oBAAoB,GAAI,OAAO,SAAS,eAAe,EAAE,QAAQ,GAAG,EAAE,EAAE,2HAWlF,qBAAqB,CAAC,OAAO,EAAE,QA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AAG,CAAC,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,2BAA2B,CAAC,OAAO,CAAC,CAAC,CAAA;IAClG,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC,GAAG,CAC/B,iBAAiB,CAAC,QAAQ,CAAC,EAC3B,QAAQ,CAAC,QAAQ,CAAC,2BAA2B,CAAC,OAAO,CAAC,EAAE,YAAY,CAAC,CACtE,CAAA;IACD,QAAQ,CAAC,KAAK,EAAE,CAAC,QAAQ,GAAG,EAAE,EAC5B,KAAK,EAAE,IAAI,CAAC,qBAAqB,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,SAAS,CAAC,KAC7D,KAAK,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,YAAY,GAAG,KAAK,CAAC,gBAAgB,EAAE,UAAU,CAAC,UAAU,CAAC,CAAA;IACjH,QAAQ,CAAC,aAAa,EAAE,KAAK,CAAC,KAAK,CAAC,iBAAiB,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;IAC9E,QAAQ,CAAC,YAAY,EAAE,KAAK,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,YAAY,EAAE,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAA;CACjH;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,gBAAgB,GAC1B,OAAO,SAAS,eAAe,QAC/B,QAAQ,SAAS,MAAM,EAAE,SAAS,QAAQ,KAAG,YAAY,CAAC,OAAO,EAAE,QAAQ,CA2E3E,CAAA"}
|
package/dist/effect/LiveStore.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { omitUndefineds } from '@livestore/utils';
|
|
2
|
-
import { Deferred, Duration, Effect, Layer, pipe } from '@livestore/utils/effect';
|
|
2
|
+
import { Context, Deferred, Duration, Effect, Layer, pipe } from '@livestore/utils/effect';
|
|
3
3
|
import { createStore, DeferredStoreContext, LiveStoreContextRunning } from "../store/create-store.js";
|
|
4
4
|
export const makeLiveStoreContext = ({ schema, storeId = 'default', context, boot, adapter, disableDevtools, onBootStatus, batchUpdates, syncPayload, syncPayloadSchema, }) => pipe(Effect.gen(function* () {
|
|
5
5
|
const store = yield* createStore({
|
|
@@ -19,6 +19,200 @@ export const makeLiveStoreContext = ({ schema, storeId = 'default', context, boo
|
|
|
19
19
|
// This can take quite a while.
|
|
20
20
|
// TODO make this configurable
|
|
21
21
|
Effect.timeout(Duration.minutes(5)), Effect.withSpan('@livestore/livestore/effect:makeLiveStoreContext'));
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated Use `Store.Tag(schema, storeId)` instead for type-safe store contexts.
|
|
24
|
+
*
|
|
25
|
+
* @example Migration
|
|
26
|
+
* ```ts
|
|
27
|
+
* // Before
|
|
28
|
+
* const layer = LiveStoreContextLayer({ schema, adapter, ... })
|
|
29
|
+
*
|
|
30
|
+
* // After
|
|
31
|
+
* class MainStore extends Store.Tag(schema, 'main') {}
|
|
32
|
+
* const layer = MainStore.layer({ adapter, ... })
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
22
35
|
export const LiveStoreContextLayer = (props) => Layer.scoped(LiveStoreContextRunning, makeLiveStoreContext(props)).pipe(Layer.withSpan('LiveStore'), Layer.provide(LiveStoreContextDeferred));
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated Use `Store.Tag(schema, storeId)` and `MainStore.DeferredLayer` instead.
|
|
38
|
+
*/
|
|
23
39
|
export const LiveStoreContextDeferred = Layer.effect(DeferredStoreContext, Deferred.make());
|
|
40
|
+
/**
|
|
41
|
+
* Create a typed store context class for use with Effect.
|
|
42
|
+
*
|
|
43
|
+
* Returns a class that extends `Context.Tag`, making it directly yieldable in Effect code.
|
|
44
|
+
* The class includes static methods for creating layers and accessors for common operations.
|
|
45
|
+
*
|
|
46
|
+
* @param schema - The LiveStore schema (used for type inference and runtime)
|
|
47
|
+
* @param storeId - Unique identifier for this store
|
|
48
|
+
*
|
|
49
|
+
* @example Basic usage
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { Store } from '@livestore/livestore/effect'
|
|
52
|
+
* import { schema } from './schema.ts'
|
|
53
|
+
*
|
|
54
|
+
* // Define your store (once per store)
|
|
55
|
+
* export class MainStore extends Store.Tag(schema, 'main') {}
|
|
56
|
+
*
|
|
57
|
+
* // Create the layer
|
|
58
|
+
* const storeLayer = MainStore.layer({
|
|
59
|
+
* adapter: myAdapter,
|
|
60
|
+
* batchUpdates: ReactDOM.unstable_batchedUpdates,
|
|
61
|
+
* })
|
|
62
|
+
*
|
|
63
|
+
* // Use in Effect code
|
|
64
|
+
* Effect.gen(function* () {
|
|
65
|
+
* const { store } = yield* MainStore
|
|
66
|
+
* // ^? Store<typeof schema> - fully typed!
|
|
67
|
+
*
|
|
68
|
+
* // Or use accessors
|
|
69
|
+
* const users = yield* MainStore.query(tables.users.all())
|
|
70
|
+
* yield* MainStore.commit(events.createUser({ id: '1', name: 'Alice' }))
|
|
71
|
+
* })
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* @example Multiple stores
|
|
75
|
+
* ```ts
|
|
76
|
+
* class MainStore extends Store.Tag(mainSchema, 'main') {}
|
|
77
|
+
* class SettingsStore extends Store.Tag(settingsSchema, 'settings') {}
|
|
78
|
+
*
|
|
79
|
+
* // Both available in same Effect context
|
|
80
|
+
* Effect.gen(function* () {
|
|
81
|
+
* const main = yield* MainStore
|
|
82
|
+
* const settings = yield* SettingsStore
|
|
83
|
+
* })
|
|
84
|
+
*
|
|
85
|
+
* const layer = Layer.mergeAll(
|
|
86
|
+
* MainStore.layer({ adapter: mainAdapter }),
|
|
87
|
+
* SettingsStore.layer({ adapter: settingsAdapter }),
|
|
88
|
+
* )
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
const makeStoreTag = (schema, storeId) => {
|
|
92
|
+
// Create the deferred tag and layers upfront
|
|
93
|
+
const _DeferredTag = Context.GenericTag(`@livestore/store-deferred/${storeId}`);
|
|
94
|
+
const _DeferredLayer = Layer.effect(_DeferredTag, Deferred.make());
|
|
95
|
+
class Tag extends Context.Tag(`@livestore/store/${storeId}`)() {
|
|
96
|
+
static schema = schema;
|
|
97
|
+
static storeId = storeId;
|
|
98
|
+
static layer(props) {
|
|
99
|
+
return pipe(Effect.gen(function* () {
|
|
100
|
+
const store = yield* createStore({
|
|
101
|
+
schema,
|
|
102
|
+
storeId,
|
|
103
|
+
adapter: props.adapter,
|
|
104
|
+
batchUpdates: props.batchUpdates,
|
|
105
|
+
...omitUndefineds({
|
|
106
|
+
context: props.context,
|
|
107
|
+
boot: props.boot,
|
|
108
|
+
disableDevtools: props.disableDevtools,
|
|
109
|
+
onBootStatus: props.onBootStatus,
|
|
110
|
+
syncPayload: props.syncPayload,
|
|
111
|
+
syncPayloadSchema: props.syncPayloadSchema,
|
|
112
|
+
}),
|
|
113
|
+
});
|
|
114
|
+
globalThis.__debugLiveStore ??= {};
|
|
115
|
+
if (Object.keys(globalThis.__debugLiveStore).length === 0) {
|
|
116
|
+
globalThis.__debugLiveStore._ = store;
|
|
117
|
+
}
|
|
118
|
+
globalThis.__debugLiveStore[storeId] = store;
|
|
119
|
+
const ctx = { stage: 'running', store: store };
|
|
120
|
+
// Also fulfill the deferred if it exists in context
|
|
121
|
+
yield* Effect.flatMap(Effect.serviceOption(_DeferredTag), (optDeferred) => optDeferred._tag === 'Some' ? Deferred.succeed(optDeferred.value, ctx) : Effect.void);
|
|
122
|
+
return ctx;
|
|
123
|
+
}), Effect.timeout(Duration.minutes(5)), Effect.withSpan(`@livestore/effect:Store.Tag:${storeId}`), Layer.scoped(Tag), Layer.withSpan(`LiveStore:${storeId}`), Layer.provide(_DeferredLayer));
|
|
124
|
+
}
|
|
125
|
+
static Deferred = _DeferredTag;
|
|
126
|
+
static DeferredLayer = _DeferredLayer;
|
|
127
|
+
static fromDeferred = pipe(Effect.gen(function* () {
|
|
128
|
+
const deferred = yield* _DeferredTag;
|
|
129
|
+
const ctx = yield* deferred;
|
|
130
|
+
return Layer.succeed(Tag, ctx);
|
|
131
|
+
}), Layer.unwrapScoped);
|
|
132
|
+
static query(query) {
|
|
133
|
+
return Effect.map(Tag, ({ store }) => store.query(query));
|
|
134
|
+
}
|
|
135
|
+
static commit(...eventInputs) {
|
|
136
|
+
return Effect.map(Tag, ({ store }) => {
|
|
137
|
+
store.commit(...eventInputs);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
static use(f) {
|
|
141
|
+
return Effect.flatMap(Tag, f);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return Tag;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* Store utilities for Effect integration.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* import { Store } from '@livestore/livestore/effect'
|
|
152
|
+
*
|
|
153
|
+
* export class MainStore extends Store.Tag(schema, 'main') {}
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
export const Store = {
|
|
157
|
+
/**
|
|
158
|
+
* Create a typed store context class for use with Effect.
|
|
159
|
+
* @see {@link makeStoreTag} for full documentation
|
|
160
|
+
*/
|
|
161
|
+
Tag: makeStoreTag,
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* @deprecated Use `Store.Tag(schema, storeId)` instead.
|
|
165
|
+
*
|
|
166
|
+
* @example Migration
|
|
167
|
+
* ```ts
|
|
168
|
+
* // Before
|
|
169
|
+
* const MainStoreContext = makeStoreContext<typeof schema>()('main')
|
|
170
|
+
*
|
|
171
|
+
* // After
|
|
172
|
+
* class MainStore extends Store.Tag(schema, 'main') {}
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
export const makeStoreContext = () => (storeId) => {
|
|
176
|
+
const Tag = Context.GenericTag(`@livestore/store/${storeId}`);
|
|
177
|
+
const DeferredTag = Context.GenericTag(`@livestore/store-deferred/${storeId}`);
|
|
178
|
+
const DeferredLayer = Layer.effect(DeferredTag, Deferred.make());
|
|
179
|
+
const makeLayer = (props) => pipe(Effect.gen(function* () {
|
|
180
|
+
const store = yield* createStore({
|
|
181
|
+
schema: props.schema,
|
|
182
|
+
storeId,
|
|
183
|
+
adapter: props.adapter,
|
|
184
|
+
batchUpdates: props.batchUpdates,
|
|
185
|
+
...omitUndefineds({
|
|
186
|
+
context: props.context,
|
|
187
|
+
boot: props.boot,
|
|
188
|
+
disableDevtools: props.disableDevtools,
|
|
189
|
+
onBootStatus: props.onBootStatus,
|
|
190
|
+
syncPayload: props.syncPayload,
|
|
191
|
+
syncPayloadSchema: props.syncPayloadSchema,
|
|
192
|
+
}),
|
|
193
|
+
});
|
|
194
|
+
globalThis.__debugLiveStore ??= {};
|
|
195
|
+
if (Object.keys(globalThis.__debugLiveStore).length === 0) {
|
|
196
|
+
globalThis.__debugLiveStore._ = store;
|
|
197
|
+
}
|
|
198
|
+
globalThis.__debugLiveStore[storeId] = store;
|
|
199
|
+
const ctx = { stage: 'running', store: store };
|
|
200
|
+
// Also fulfill the deferred if it exists in context
|
|
201
|
+
yield* Effect.flatMap(Effect.serviceOption(DeferredTag), (optDeferred) => optDeferred._tag === 'Some' ? Deferred.succeed(optDeferred.value, ctx) : Effect.void);
|
|
202
|
+
return ctx;
|
|
203
|
+
}), Effect.timeout(Duration.minutes(5)), Effect.withSpan(`@livestore/effect:makeStoreContext:${storeId}`), Layer.scoped(Tag), Layer.withSpan(`LiveStore:${storeId}`), Layer.provide(DeferredLayer));
|
|
204
|
+
const fromDeferred = pipe(Effect.gen(function* () {
|
|
205
|
+
const deferred = yield* DeferredTag;
|
|
206
|
+
const ctx = yield* deferred;
|
|
207
|
+
return Layer.succeed(Tag, ctx);
|
|
208
|
+
}), Layer.unwrapScoped);
|
|
209
|
+
return {
|
|
210
|
+
storeId,
|
|
211
|
+
Tag,
|
|
212
|
+
DeferredTag,
|
|
213
|
+
Layer: makeLayer,
|
|
214
|
+
DeferredLayer,
|
|
215
|
+
fromDeferred,
|
|
216
|
+
};
|
|
217
|
+
};
|
|
24
218
|
//# sourceMappingURL=LiveStore.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LiveStore.js","sourceRoot":"","sources":["../../src/effect/LiveStore.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEjD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"LiveStore.js","sourceRoot":"","sources":["../../src/effect/LiveStore.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEjD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAA;AAE1F,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAA;AAIrG,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAiD,EACnF,MAAM,EACN,OAAO,GAAG,SAAS,EACnB,OAAO,EACP,IAAI,EACJ,OAAO,EACP,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,iBAAiB,GACwB,EAIzC,EAAE,CACF,IAAI,CACF,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,WAAW,CAAC;QAC/B,MAAM;QACN,OAAO;QACP,OAAO;QACP,YAAY;QACZ,GAAG,cAAc,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,CAAC;KACpG,CAAC,CAAA;IAEF,UAAU,CAAC,gBAAgB,KAAK,EAAE,CAAA;IAClC,IAAI,MAAM,CAAC,IAAI,CAAC,U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Q,CAAC,aAAa,OAAO,EAAE,CAAC,EACtC,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,CAC7B,CAAA;IAEH,MAAM,YAAY,GAId,IAAI,CACN,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QAClB,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,WAAW,CAAA;QACnC,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,QAAQ,CAAA;QAC3B,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;IAChC,CAAC,CAAC,EACF,KAAK,CAAC,YAAY,CACnB,CAAA;IAED,OAAO;QACL,OAAO;QACP,GAAG;QACH,WAAW;QACX,KAAK,EAAE,SAAS;QAChB,aAAa;QACb,YAAY;KACb,CAAA;AACH,CAAC,CAAA"}
|
package/dist/effect/mod.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { DeferredStoreContext, type LiveStoreContextProps, LiveStoreContextRunning as LiveStoreContext, LiveStoreContextRunning, } from '../store/create-store.ts';
|
|
2
|
-
export { LiveStoreContextDeferred, LiveStoreContextLayer } from './LiveStore.ts';
|
|
2
|
+
export { type DeferredContextId, LiveStoreContextDeferred, LiveStoreContextLayer, makeStoreContext, Store, type StoreContext, type StoreContextId, type StoreLayerProps, type StoreTagClass, } from './LiveStore.ts';
|
|
3
3
|
//# sourceMappingURL=mod.d.ts.map
|
package/dist/effect/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/effect/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,KAAK,qBAAqB,EAC1B,uBAAuB,IAAI,gBAAgB,EAC3C,uBAAuB,GACxB,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/effect/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,KAAK,qBAAqB,EAC1B,uBAAuB,IAAI,gBAAgB,EAC3C,uBAAuB,GACxB,MAAM,0BAA0B,CAAA;AAGjC,OAAO,EACL,KAAK,iBAAiB,EACtB,wBAAwB,EACxB,qBAAqB,EACrB,gBAAgB,EAChB,KAAK,EACL,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,aAAa,GACnB,MAAM,gBAAgB,CAAA"}
|
package/dist/effect/mod.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { DeferredStoreContext, LiveStoreContextRunning as LiveStoreContext, LiveStoreContextRunning, } from "../store/create-store.js";
|
|
2
|
-
|
|
2
|
+
// Store.Tag - Idiomatic Effect API
|
|
3
|
+
// Legacy API (deprecated)
|
|
4
|
+
export { LiveStoreContextDeferred, LiveStoreContextLayer, makeStoreContext, Store, } from "./LiveStore.js";
|
|
3
5
|
//# sourceMappingURL=mod.js.map
|
package/dist/effect/mod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../src/effect/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EAEpB,uBAAuB,IAAI,gBAAgB,EAC3C,uBAAuB,GACxB,MAAM,0BAA0B,CAAA;AACjC,OAAO,
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../src/effect/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EAEpB,uBAAuB,IAAI,gBAAgB,EAC3C,uBAAuB,GACxB,MAAM,0BAA0B,CAAA;AACjC,mCAAmC;AACnC,0BAA0B;AAC1B,OAAO,EAEL,wBAAwB,EACxB,qBAAqB,EACrB,gBAAgB,EAChB,KAAK,GAKN,MAAM,gBAAgB,CAAA"}
|
package/dist/mod.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { nanoid } from '@livestore/utils/nanoid';
|
|
|
7
7
|
export { computed, type LiveQuery, type LiveQueryDef, queryDb, type RcRef, type Signal, type SignalDef, signal, } from './live-queries/mod.ts';
|
|
8
8
|
export { emptyDebugInfo, SqliteDbWrapper } from './SqliteDbWrapper.ts';
|
|
9
9
|
export { type CreateStoreOptions, type CreateStoreOptionsPromise, createStore, createStorePromise, } from './store/create-store.ts';
|
|
10
|
+
export { type RegistryStoreOptions, StoreRegistry, storeOptions } from './store/StoreRegistry.ts';
|
|
10
11
|
export { Store } from './store/store.ts';
|
|
11
12
|
export { isLiveQueryDef, isLiveQueryInstance, isQueryable, type LiveStoreContext, type LiveStoreContextRunning, makeShutdownDeferred, type OtelOptions, type Queryable, type QueryDebugInfo, type RefreshReason, type ShutdownDeferred, type StoreInternals, StoreInternalsSymbol, type SubscribeOptions, type Unsubscribe, } from './store/store-types.ts';
|
|
12
13
|
export { exposeDebugUtils } from './utils/dev.ts';
|
package/dist/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAClF,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,SAAS,EACd,wBAAwB,EACxB,gBAAgB,EAChB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,iBAAiB,EACjB,WAAW,EACX,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,QAAQ,EACb,eAAe,EACf,KAAK,QAAQ,EACb,gBAAgB,EAChB,KAAK,SAAS,EACd,GAAG,GACJ,MAAM,mBAAmB,CAAA;AAC1B,cAAc,0BAA0B,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAE5C,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEh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AAA;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAE5C,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEhD,OAAO,EACL,QAAQ,EACR,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,OAAO,EACP,KAAK,KAAK,EACV,KAAK,MAAM,EACX,KAAK,SAAS,EACd,MAAM,GACP,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtE,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,EAC9B,WAAW,EACX,kBAAkB,GACnB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,KAAK,oBAAoB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AACjG,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACxC,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,WAAW,EACX,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAC5B,oBAAoB,EACpB,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,oBAAoB,EACpB,KAAK,gBAAgB,EACrB,KAAK,WAAW,GACjB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AACjD,cAAc,uBAAuB,CAAA"}
|
package/dist/mod.js
CHANGED
|
@@ -7,6 +7,7 @@ export { nanoid } from '@livestore/utils/nanoid';
|
|
|
7
7
|
export { computed, queryDb, signal, } from "./live-queries/mod.js";
|
|
8
8
|
export { emptyDebugInfo, SqliteDbWrapper } from "./SqliteDbWrapper.js";
|
|
9
9
|
export { createStore, createStorePromise, } from "./store/create-store.js";
|
|
10
|
+
export { StoreRegistry, storeOptions } from "./store/StoreRegistry.js";
|
|
10
11
|
export { Store } from "./store/store.js";
|
|
11
12
|
export { isLiveQueryDef, isLiveQueryInstance, isQueryable, makeShutdownDeferred, StoreInternalsSymbol, } from "./store/store-types.js";
|
|
12
13
|
export { exposeDebugUtils } from "./utils/dev.js";
|
package/dist/mod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,wBAAwB,EACxB,gBAAgB,EAGhB,iBAAiB,EACjB,WAAW,EAIX,eAAe,EAEf,gBAAgB,EAEhB,GAAG,GACJ,MAAM,mBAAmB,CAAA;AAC1B,cAAc,0BAA0B,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC5C,4DAA4D;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEhD,OAAO,EACL,QAAQ,EAGR,OAAO,EAIP,MAAM,GACP,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtE,OAAO,EAGL,WAAW,EACX,kBAAkB,GACnB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACxC,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,WAAW,EAGX,oBAAoB,EAOpB,oBAAoB,GAGrB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AACjD,cAAc,uBAAuB,CAAA"}
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,wBAAwB,EACxB,gBAAgB,EAGhB,iBAAiB,EACjB,WAAW,EAIX,eAAe,EAEf,gBAAgB,EAEhB,GAAG,GACJ,MAAM,mBAAmB,CAAA;AAC1B,cAAc,0BAA0B,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC5C,4DAA4D;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEhD,OAAO,EACL,QAAQ,EAGR,OAAO,EAIP,MAAM,GACP,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtE,OAAO,EAGL,WAAW,EACX,kBAAkB,GACnB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAA6B,aAAa,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AACjG,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACxC,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,WAAW,EAGX,oBAAoB,EAOpB,oBAAoB,GAGrB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AACjD,cAAc,uBAAuB,CAAA"}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { UnknownError } from '@livestore/common';
|
|
2
|
+
import type { LiveStoreSchema } from '@livestore/common/schema';
|
|
3
|
+
import { Effect, type OtelTracer, Runtime, type Schema, type Scope } from '@livestore/utils/effect';
|
|
4
|
+
import { type CreateStoreOptions } from './create-store.ts';
|
|
5
|
+
import type { Store } from './store.ts';
|
|
6
|
+
import type { OtelOptions } from './store-types.ts';
|
|
7
|
+
/**
|
|
8
|
+
* Configuration options for stores managed by a {@link StoreRegistry}.
|
|
9
|
+
*
|
|
10
|
+
* Extends {@link CreateStoreOptions} with registry-specific settings for caching and observability.
|
|
11
|
+
* Use with {@link storeOptions} helper to get full type inference when defining reusable store configurations.
|
|
12
|
+
*
|
|
13
|
+
* @typeParam TSchema - The LiveStore schema type
|
|
14
|
+
* @typeParam TContext - User-defined context attached to the store
|
|
15
|
+
* @typeParam TSyncPayloadSchema - Schema for the sync payload sent to the backend
|
|
16
|
+
*
|
|
17
|
+
* @see {@link storeOptions} for defining reusable store configurations
|
|
18
|
+
* @see {@link StoreRegistry} for managing store lifecycles
|
|
19
|
+
*/
|
|
20
|
+
export interface RegistryStoreOptions<TSchema extends LiveStoreSchema = LiveStoreSchema.Any, TContext = {}, TSyncPayloadSchema extends Schema.Schema<any> = typeof Schema.JsonValue> extends CreateStoreOptions<TSchema, TContext, TSyncPayloadSchema> {
|
|
21
|
+
/**
|
|
22
|
+
* OpenTelemetry configuration for tracing store operations.
|
|
23
|
+
*
|
|
24
|
+
* When provided, store operations (boot, queries, commits) will be traced
|
|
25
|
+
* under the given root span context using the specified tracer.
|
|
26
|
+
*/
|
|
27
|
+
otelOptions?: Partial<OtelOptions>;
|
|
28
|
+
/**
|
|
29
|
+
* The time in milliseconds that this store should remain
|
|
30
|
+
* in memory after becoming unused. When this store becomes
|
|
31
|
+
* unused (no active retentions), it will be disposed after this duration.
|
|
32
|
+
*
|
|
33
|
+
* Stores transition to the unused state as soon as they have no
|
|
34
|
+
* active retentions, so when all components which use that store
|
|
35
|
+
* have unmounted.
|
|
36
|
+
*
|
|
37
|
+
* @remarks
|
|
38
|
+
* - **Limitation:** Per-store values are not yet supported. Only the registry-level default
|
|
39
|
+
* (via `StoreRegistry` constructor's `defaultOptions.unusedCacheTime`) is used.
|
|
40
|
+
* See {@link https://github.com/livestorejs/livestore/issues/917 | #917} for per-store support
|
|
41
|
+
* and {@link https://github.com/livestorejs/livestore/issues/918 | #918} for dynamic "longest wins" behavior.
|
|
42
|
+
* - If set to `Infinity`, will disable automatic disposal
|
|
43
|
+
* - The maximum allowed time is about {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/setTimeout#maximum_delay_value | 24 days}
|
|
44
|
+
*
|
|
45
|
+
* @defaultValue `60_000` (60 seconds) or `Infinity` during SSR to avoid
|
|
46
|
+
* disposing stores before server render completes.
|
|
47
|
+
*/
|
|
48
|
+
unusedCacheTime?: number;
|
|
49
|
+
}
|
|
50
|
+
type StoreRegistryConfig = {
|
|
51
|
+
/**
|
|
52
|
+
* Default options that are applied to all stores when they are loaded.
|
|
53
|
+
*
|
|
54
|
+
* @remarks
|
|
55
|
+
* These are options that typically don't depend on the specific store being loaded:
|
|
56
|
+
* - Framework integration (`batchUpdates`)
|
|
57
|
+
* - Environment settings (`disableDevtools`, `debug`, `otelOptions`)
|
|
58
|
+
* - Behavior defaults (`confirmUnsavedChanges`, `unusedCacheTime`)
|
|
59
|
+
*
|
|
60
|
+
* Store-specific fields like `schema`, `adapter`, `storeId`, and `boot` are intentionally
|
|
61
|
+
* excluded since they vary per store definition.
|
|
62
|
+
*/
|
|
63
|
+
defaultOptions?: Partial<Pick<RegistryStoreOptions, 'batchUpdates' | 'disableDevtools' | 'confirmUnsavedChanges' | 'debug' | 'otelOptions' | 'unusedCacheTime'>>;
|
|
64
|
+
/**
|
|
65
|
+
* Custom Effect runtime for all registry operations (loading, caching, etc.).
|
|
66
|
+
* When the runtime's scope closes, all managed stores are automatically shut down.
|
|
67
|
+
*/
|
|
68
|
+
runtime?: Runtime.Runtime<Scope.Scope | OtelTracer.OtelTracer>;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Store Registry coordinating store loading, caching, and retention
|
|
72
|
+
*
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
75
|
+
export declare class StoreRegistry {
|
|
76
|
+
#private;
|
|
77
|
+
/**
|
|
78
|
+
* Creates a new StoreRegistry instance.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* const registry = new StoreRegistry({
|
|
83
|
+
* defaultOptions: {
|
|
84
|
+
* batchUpdates,
|
|
85
|
+
* unusedCacheTime: 30_000,
|
|
86
|
+
* }
|
|
87
|
+
* })
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
constructor(config?: StoreRegistryConfig);
|
|
91
|
+
/**
|
|
92
|
+
* Gets a cached store or loads a new one, with the store lifetime scoped to the caller.
|
|
93
|
+
*
|
|
94
|
+
* @typeParam TSchema - The schema type for the store
|
|
95
|
+
* @typeParam TContext - The context type for the store
|
|
96
|
+
* @typeParam TSyncPayloadSchema - The sync payload schema type
|
|
97
|
+
* @returns An Effect that yields the store, scoped to the provided Scope
|
|
98
|
+
*
|
|
99
|
+
* @remarks
|
|
100
|
+
* - Stores are kept in cache and reused while any scope holds them
|
|
101
|
+
* - When the scope closes, the reference is released; the store is disposed after `unusedCacheTime`
|
|
102
|
+
* if no other scopes retain it
|
|
103
|
+
* - Concurrent calls with the same storeId share the same store instance
|
|
104
|
+
*/
|
|
105
|
+
getOrLoad: <TSchema extends LiveStoreSchema, TContext = {}, TSyncPayloadSchema extends Schema.Schema<any> = typeof Schema.JsonValue>(options: RegistryStoreOptions<TSchema, TContext, TSyncPayloadSchema>) => Effect.Effect<Store<TSchema, TContext>, UnknownError, Scope.Scope>;
|
|
106
|
+
/**
|
|
107
|
+
* Get or load a store, returning it directly if already loaded or a promise if loading.
|
|
108
|
+
*
|
|
109
|
+
* @typeParam TSchema - The schema type for the store
|
|
110
|
+
* @typeParam TContext - The context type for the store
|
|
111
|
+
* @typeParam TSyncPayloadSchema - The sync payload schema type
|
|
112
|
+
* @returns The loaded store if available, or a Promise that resolves to the loaded store
|
|
113
|
+
* @throws unknown - store loading error
|
|
114
|
+
*
|
|
115
|
+
* @remarks
|
|
116
|
+
* - Returns the store instance directly (synchronous) when already loaded
|
|
117
|
+
* - Returns a stable Promise reference when loading is in progress or needs to be initiated
|
|
118
|
+
* - Throws with the same error instance on subsequent calls after failure
|
|
119
|
+
* - Applies default options from registry config, with call-site options taking precedence
|
|
120
|
+
* - Concurrent calls with the same storeId share the same store instance
|
|
121
|
+
*/
|
|
122
|
+
getOrLoadPromise: <TSchema extends LiveStoreSchema, TContext = {}, TSyncPayloadSchema extends Schema.Schema<any> = typeof Schema.JsonValue>(options: RegistryStoreOptions<TSchema, TContext, TSyncPayloadSchema>) => Store<TSchema, TContext> | Promise<Store<TSchema, TContext>>;
|
|
123
|
+
/**
|
|
124
|
+
* Retains the store in cache.
|
|
125
|
+
*
|
|
126
|
+
* @typeParam TSchema - The schema type for the store
|
|
127
|
+
* @typeParam TContext - The context type for the store
|
|
128
|
+
* @typeParam TSyncPayloadSchema - The sync payload schema type
|
|
129
|
+
* @returns A release function that, when called, removes this retention hold
|
|
130
|
+
*
|
|
131
|
+
* @remarks
|
|
132
|
+
* - Multiple retains on the same store are independent; each must be released separately
|
|
133
|
+
* - If the store isn't cached yet, it will be loaded and then retained
|
|
134
|
+
* - The store will remain in cache until all retains are released and after `unusedCacheTime` expires
|
|
135
|
+
*/
|
|
136
|
+
retain: <TSchema extends LiveStoreSchema, TContext = {}, TSyncPayloadSchema extends Schema.Schema<any> = typeof Schema.JsonValue>(options: RegistryStoreOptions<TSchema, TContext, TSyncPayloadSchema>) => (() => void);
|
|
137
|
+
/**
|
|
138
|
+
* Loads a store (without suspending) to warm up the cache.
|
|
139
|
+
*
|
|
140
|
+
* @typeParam TSchema - The schema of the store to preload
|
|
141
|
+
* @typeParam TContext - The context type for the store
|
|
142
|
+
* @typeParam TSyncPayloadSchema - The sync payload schema type
|
|
143
|
+
* @returns A promise that resolves when the loading is complete (success or failure)
|
|
144
|
+
*
|
|
145
|
+
* @remarks
|
|
146
|
+
* - We don't return the store or throw as this is a fire-and-forget operation.
|
|
147
|
+
* - If the entry remains unused after preload resolves/rejects, it is scheduled for disposal.
|
|
148
|
+
* - Does not affect the retention of the store in cache.
|
|
149
|
+
*/
|
|
150
|
+
preload: <TSchema extends LiveStoreSchema, TContext = {}, TSyncPayloadSchema extends Schema.Schema<any> = typeof Schema.JsonValue>(options: RegistryStoreOptions<TSchema, TContext, TSyncPayloadSchema>) => Promise<void>;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Helper for defining reusable store options with full type inference. Returns
|
|
154
|
+
* options that can be passed to `useStore()` or `storeRegistry.preload()`.
|
|
155
|
+
*
|
|
156
|
+
* @remarks
|
|
157
|
+
* At runtime this is an identity function that returns the input unchanged.
|
|
158
|
+
* Its value lies in enabling TypeScript's excess property checking to catch
|
|
159
|
+
* typos and configuration errors, while allowing options to be shared across
|
|
160
|
+
* `useStore()`, `storeRegistry.preload()`, `storeRegistry.getOrLoad()`, etc.
|
|
161
|
+
*
|
|
162
|
+
* @typeParam TSchema - The LiveStore schema type
|
|
163
|
+
* @typeParam TContext - User-defined context attached to the store
|
|
164
|
+
* @typeParam TSyncPayloadSchema - Schema for the sync payload sent to the backend
|
|
165
|
+
* @param options - The store configuration options
|
|
166
|
+
* @returns The same options object, unchanged
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```ts
|
|
170
|
+
* export const issueStoreOptions = (issueId: string) =>
|
|
171
|
+
* storeOptions({
|
|
172
|
+
* storeId: `issue-${issueId}`,
|
|
173
|
+
* schema,
|
|
174
|
+
* adapter,
|
|
175
|
+
* unusedCacheTime: 30_000,
|
|
176
|
+
* })
|
|
177
|
+
*
|
|
178
|
+
* // In a component
|
|
179
|
+
* const issueStore = useStore(issueStoreOptions(issueId))
|
|
180
|
+
*
|
|
181
|
+
* // In a route loader or event handler
|
|
182
|
+
* storeRegistry.preload({
|
|
183
|
+
* ...issueStoreOptions(issueId),
|
|
184
|
+
* unusedCacheTime: 10_000,
|
|
185
|
+
* });
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
export declare function storeOptions<TSchema extends LiveStoreSchema, TContext = {}, TSyncPayloadSchema extends Schema.Schema<any> = typeof Schema.JsonValue>(options: RegistryStoreOptions<TSchema, TContext, TSyncPayloadSchema>): RegistryStoreOptions<TSchema, TContext, TSyncPayloadSchema>;
|
|
189
|
+
export {};
|
|
190
|
+
//# sourceMappingURL=StoreRegistry.d.ts.map
|
|
@@ -0,0 +1 @@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