@livestore/livestore 0.0.41-dev.2 → 0.0.42-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/{inMemoryDatabase.d.ts → MainDatabaseWrapper.d.ts} +11 -18
- package/dist/MainDatabaseWrapper.d.ts.map +1 -0
- package/dist/{inMemoryDatabase.js → MainDatabaseWrapper.js} +26 -72
- package/dist/MainDatabaseWrapper.js.map +1 -0
- package/dist/__tests__/react/fixture.d.ts +41 -40
- package/dist/__tests__/react/fixture.d.ts.map +1 -1
- package/dist/__tests__/react/fixture.js +2 -8
- package/dist/__tests__/react/fixture.js.map +1 -1
- package/dist/cud.d.ts +9 -9
- package/dist/cud.d.ts.map +1 -1
- package/dist/cud.js +7 -8
- package/dist/cud.js.map +1 -1
- package/dist/effect/LiveStore.d.ts +10 -10
- package/dist/effect/LiveStore.d.ts.map +1 -1
- package/dist/effect/LiveStore.js +2 -11
- package/dist/effect/LiveStore.js.map +1 -1
- package/dist/global-state.d.ts +2 -2
- package/dist/global-state.d.ts.map +1 -1
- package/dist/global-state.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/migrations.d.ts +5 -5
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +37 -21
- package/dist/migrations.js.map +1 -1
- package/dist/query-info.d.ts +8 -9
- package/dist/query-info.d.ts.map +1 -1
- package/dist/query-info.js +1 -1
- package/dist/query-info.js.map +1 -1
- package/dist/react/LiveStoreProvider.d.ts +7 -7
- package/dist/react/LiveStoreProvider.d.ts.map +1 -1
- package/dist/react/LiveStoreProvider.js +11 -19
- package/dist/react/LiveStoreProvider.js.map +1 -1
- package/dist/react/useRow.d.ts +6 -6
- package/dist/react/useRow.d.ts.map +1 -1
- package/dist/react/useRow.js +2 -2
- package/dist/react/useRow.js.map +1 -1
- package/dist/reactiveQueries/sql.js +2 -2
- package/dist/reactiveQueries/sql.js.map +1 -1
- package/dist/reactiveQueries/sql.test.js +12 -31
- package/dist/reactiveQueries/sql.test.js.map +1 -1
- package/dist/row-query.d.ts +6 -6
- package/dist/row-query.d.ts.map +1 -1
- package/dist/row-query.js +9 -12
- package/dist/row-query.js.map +1 -1
- package/dist/store.d.ts +18 -18
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +80 -86
- package/dist/store.js.map +1 -1
- package/dist/utils/bounded-collections.d.ts +1 -1
- package/dist/utils/bounded-collections.d.ts.map +1 -1
- package/dist/utils/bounded-collections.js +2 -1
- package/dist/utils/bounded-collections.js.map +1 -1
- package/dist/utils/util.d.ts +0 -16
- package/dist/utils/util.d.ts.map +1 -1
- package/dist/utils/util.js +0 -38
- package/dist/utils/util.js.map +1 -1
- package/package.json +8 -44
- package/src/{inMemoryDatabase.ts → MainDatabaseWrapper.ts} +40 -94
- package/src/__tests__/react/fixture.tsx +3 -9
- package/src/cud.ts +17 -16
- package/src/effect/LiveStore.ts +12 -24
- package/src/global-state.ts +3 -2
- package/src/index.ts +7 -23
- package/src/migrations.ts +51 -34
- package/src/query-info.ts +10 -9
- package/src/react/LiveStoreProvider.tsx +19 -27
- package/src/react/useRow.ts +24 -12
- package/src/reactiveQueries/sql.test.ts +12 -31
- package/src/reactiveQueries/sql.ts +2 -2
- package/src/row-query.ts +32 -29
- package/src/store.ts +98 -103
- package/src/utils/bounded-collections.ts +3 -2
- package/src/utils/util.ts +0 -44
- package/tsconfig.json +1 -1
- package/vitest.config.js +4 -0
- package/dist/inMemoryDatabase.d.ts.map +0 -1
- package/dist/inMemoryDatabase.js.map +0 -1
- package/dist/schema/index.d.ts +0 -42
- package/dist/schema/index.d.ts.map +0 -1
- package/dist/schema/index.js +0 -42
- package/dist/schema/index.js.map +0 -1
- package/dist/schema/mutations.d.ts +0 -81
- package/dist/schema/mutations.d.ts.map +0 -1
- package/dist/schema/mutations.js +0 -29
- package/dist/schema/mutations.js.map +0 -1
- package/dist/schema/parse-utils.d.ts +0 -6
- package/dist/schema/parse-utils.d.ts.map +0 -1
- package/dist/schema/parse-utils.js +0 -22
- package/dist/schema/parse-utils.js.map +0 -1
- package/dist/schema/system-tables.d.ts +0 -76
- package/dist/schema/system-tables.d.ts.map +0 -1
- package/dist/schema/system-tables.js +0 -11
- package/dist/schema/system-tables.js.map +0 -1
- package/dist/schema/table-def.d.ts +0 -100
- package/dist/schema/table-def.d.ts.map +0 -1
- package/dist/schema/table-def.js +0 -70
- package/dist/schema/table-def.js.map +0 -1
- package/dist/storage/in-memory/index.d.ts +0 -19
- package/dist/storage/in-memory/index.d.ts.map +0 -1
- package/dist/storage/in-memory/index.js +0 -16
- package/dist/storage/in-memory/index.js.map +0 -1
- package/dist/storage/index.d.ts +0 -18
- package/dist/storage/index.d.ts.map +0 -1
- package/dist/storage/index.js +0 -9
- package/dist/storage/index.js.map +0 -1
- package/dist/storage/tauri/index.d.ts +0 -23
- package/dist/storage/tauri/index.d.ts.map +0 -1
- package/dist/storage/tauri/index.js +0 -46
- package/dist/storage/tauri/index.js.map +0 -1
- package/dist/storage/utils/idb.d.ts +0 -11
- package/dist/storage/utils/idb.d.ts.map +0 -1
- package/dist/storage/utils/idb.js +0 -71
- package/dist/storage/utils/idb.js.map +0 -1
- package/dist/storage/web-worker/common.d.ts +0 -11
- package/dist/storage/web-worker/common.d.ts.map +0 -1
- package/dist/storage/web-worker/common.js +0 -2
- package/dist/storage/web-worker/common.js.map +0 -1
- package/dist/storage/web-worker/index.d.ts +0 -34
- package/dist/storage/web-worker/index.d.ts.map +0 -1
- package/dist/storage/web-worker/index.js +0 -134
- package/dist/storage/web-worker/index.js.map +0 -1
- package/dist/storage/web-worker/make-worker.d.ts +0 -20
- package/dist/storage/web-worker/make-worker.d.ts.map +0 -1
- package/dist/storage/web-worker/make-worker.js +0 -155
- package/dist/storage/web-worker/make-worker.js.map +0 -1
- package/dist/storage/web-worker/vite-dev-polyfill.d.ts +0 -2
- package/dist/storage/web-worker/vite-dev-polyfill.d.ts.map +0 -1
- package/dist/storage/web-worker/vite-dev-polyfill.js +0 -35
- package/dist/storage/web-worker/vite-dev-polyfill.js.map +0 -1
- package/src/schema/index.ts +0 -100
- package/src/schema/mutations.ts +0 -128
- package/src/schema/parse-utils.ts +0 -42
- package/src/schema/system-tables.ts +0 -21
- package/src/schema/table-def.ts +0 -270
- package/src/storage/in-memory/index.ts +0 -28
- package/src/storage/index.ts +0 -36
- package/src/storage/tauri/index.ts +0 -66
- package/src/storage/utils/idb.ts +0 -85
- package/src/storage/web-worker/common.ts +0 -6
- package/src/storage/web-worker/index.ts +0 -185
- package/src/storage/web-worker/make-worker.ts +0 -214
- package/src/storage/web-worker/vite-dev-polyfill.ts +0 -33
package/dist/cud.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
+
import type { RawSqlMutationEvent } from '@livestore/common/schema';
|
|
2
|
+
import { DbSchema } from '@livestore/common/schema';
|
|
1
3
|
import type { SqliteDsl } from 'effect-db-schema';
|
|
2
4
|
import type { RowResult } from './row-query.js';
|
|
3
|
-
import { type RawSqlMutationEvent } from './schema/index.js';
|
|
4
|
-
import { type TableDef } from './schema/table-def.js';
|
|
5
5
|
import { type GetValForKey } from './utils/util.js';
|
|
6
|
-
export declare const makeCudMutations: <TTableDef extends TableDef
|
|
7
|
-
export type UpdateMutation<TTableDef extends TableDef> = (args: {
|
|
6
|
+
export declare const makeCudMutations: <TTableDef extends DbSchema.TableDef<DbSchema.DefaultSqliteTableDefConstrained, boolean, DbSchema.TableOptions, import("@effect/schema/Schema").Schema<any, any, never>>>(tables: Iterable<TTableDef> | Record<string, TTableDef>) => CudMutations<TTableDef>;
|
|
7
|
+
export type UpdateMutation<TTableDef extends DbSchema.TableDef> = (args: {
|
|
8
8
|
where: Partial<RowResult<TTableDef>>;
|
|
9
9
|
values: Partial<RowResult<TTableDef>>;
|
|
10
10
|
}) => RawSqlMutationEvent;
|
|
11
|
-
export type RowInsert<TTableDef extends TableDef> = TTableDef['isSingleColumn'] extends true ? GetValForKey<SqliteDsl.FromColumns.InsertRowDecoded<TTableDef['sqliteDef']['columns']>, 'value'> : SqliteDsl.FromColumns.InsertRowDecoded<TTableDef['sqliteDef']['columns']>;
|
|
12
|
-
export type InsertMutation<TTableDef extends TableDef> = (values: RowInsert<TTableDef>) => RawSqlMutationEvent;
|
|
13
|
-
export type DeleteMutation<TTableDef extends TableDef> = (args: {
|
|
11
|
+
export type RowInsert<TTableDef extends DbSchema.TableDef> = TTableDef['isSingleColumn'] extends true ? GetValForKey<SqliteDsl.FromColumns.InsertRowDecoded<TTableDef['sqliteDef']['columns']>, 'value'> : SqliteDsl.FromColumns.InsertRowDecoded<TTableDef['sqliteDef']['columns']>;
|
|
12
|
+
export type InsertMutation<TTableDef extends DbSchema.TableDef> = (values: RowInsert<TTableDef>) => RawSqlMutationEvent;
|
|
13
|
+
export type DeleteMutation<TTableDef extends DbSchema.TableDef> = (args: {
|
|
14
14
|
where: Partial<RowResult<TTableDef>>;
|
|
15
15
|
}) => RawSqlMutationEvent;
|
|
16
|
-
export type CudMutation<TTableDef extends TableDef> = {
|
|
16
|
+
export type CudMutation<TTableDef extends DbSchema.TableDef> = {
|
|
17
17
|
insert: InsertMutation<TTableDef>;
|
|
18
18
|
update: UpdateMutation<TTableDef>;
|
|
19
19
|
delete: DeleteMutation<TTableDef>;
|
|
20
20
|
};
|
|
21
|
-
export type CudMutations<TTableDef extends TableDef> = {
|
|
21
|
+
export type CudMutations<TTableDef extends DbSchema.TableDef> = {
|
|
22
22
|
[TTableName in TTableDef['sqliteDef']['name']]: CudMutation<Extract<TTableDef, {
|
|
23
23
|
sqliteDef: {
|
|
24
24
|
name: TTableName;
|
package/dist/cud.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cud.d.ts","sourceRoot":"","sources":["../src/cud.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,
|
|
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AC,SAAS,CAAC,CAAC,CAAA;CACrC,KAAK,mBAAmB,CAAA;AAEzB,MAAM,MAAM,WAAW,CAAC,SAAS,SAAS,QAAQ,CAAC,QAAQ,IAAI;IAC7D,MAAM,EAAE,cAAc,CAAC,SAAS,CAAC,CAAA;IACjC,MAAM,EAAE,cAAc,CAAC,SAAS,CAAC,CAAA;IACjC,MAAM,EAAE,cAAc,CAAC,SAAS,CAAC,CAAA;CAClC,CAAA;AAED,MAAM,MAAM,YAAY,CAAC,SAAS,SAAS,QAAQ,CAAC,QAAQ,IAAI;KAC7D,UAAU,IAAI,SAAS,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,GAAG,WAAW,CAAC,OAAO,CAAC,SAAS,EAAE;QAAE,SAAS,EAAE;YAAE,IAAI,EAAE,UAAU,CAAA;SAAE,CAAA;KAAE,CAAC,CAAC;CACrH,CAAA"}
|
package/dist/cud.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { rawSqlMutation } from '
|
|
3
|
-
import {
|
|
4
|
-
import { isIterable } from './utils/util.js';
|
|
1
|
+
import { deleteRows, insertRow, updateRows } from '@livestore/common';
|
|
2
|
+
import { DbSchema, rawSqlMutation } from '@livestore/common/schema';
|
|
3
|
+
import { isIterable } from '@livestore/utils';
|
|
5
4
|
export const makeCudMutations = (tables) => {
|
|
6
5
|
const cudMutationRecord = {};
|
|
7
6
|
const tables_ = isIterable(tables) ? tables : Object.values(tables);
|
|
@@ -16,8 +15,8 @@ const cudMutationsForTable = (tableDef) => {
|
|
|
16
15
|
const writeTables = new Set([table.name]);
|
|
17
16
|
const api = {
|
|
18
17
|
insert: (values_) => {
|
|
19
|
-
const values =
|
|
20
|
-
const [sql, bindValues] =
|
|
18
|
+
const values = DbSchema.getDefaultValuesDecoded(tableDef, values_);
|
|
19
|
+
const [sql, bindValues] = insertRow({
|
|
21
20
|
tableName: table.name,
|
|
22
21
|
columns: table.columns,
|
|
23
22
|
options: { orReplace: false },
|
|
@@ -26,7 +25,7 @@ const cudMutationsForTable = (tableDef) => {
|
|
|
26
25
|
return rawSqlMutation({ sql, bindValues, writeTables });
|
|
27
26
|
},
|
|
28
27
|
update: ({ where, values }) => {
|
|
29
|
-
const [sql, bindValues] =
|
|
28
|
+
const [sql, bindValues] = updateRows({
|
|
30
29
|
tableName: table.name,
|
|
31
30
|
columns: table.columns,
|
|
32
31
|
where: where,
|
|
@@ -35,7 +34,7 @@ const cudMutationsForTable = (tableDef) => {
|
|
|
35
34
|
return rawSqlMutation({ sql, bindValues, writeTables });
|
|
36
35
|
},
|
|
37
36
|
delete: ({ where }) => {
|
|
38
|
-
const [sql, bindValues] =
|
|
37
|
+
const [sql, bindValues] = deleteRows({
|
|
39
38
|
tableName: table.name,
|
|
40
39
|
columns: table.columns,
|
|
41
40
|
where: where,
|
package/dist/cud.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cud.js","sourceRoot":"","sources":["../src/cud.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"cud.js","sourceRoot":"","sources":["../src/cud.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAErE,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAM7C,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,MAAuD,EAC9B,EAAE;IAC3B,MAAM,iBAAiB,GAA4B,EAAS,CAAA;IAE5D,MAAM,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IAEnE,KAAK,MAAM,QAAQ,IAAI,OAAO,EAAE,CAAC;QAC/B,MAAM,CAAC,SAAS,EAAE,WA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M,CAAC,GAAG,EAAE,UAAU,CAAC,GAAG,UAAU,CAAC;gBACnC,SAAS,EAAE,KAAK,CAAC,IAAI;gBACrB,OAAO,EAAE,KAAK,CAAC,OAAO;gBACtB,KAAK,EAAE,KAAK;aACb,CAAC,CAAA;YACF,OAAO,cAAc,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAA;QACzD,CAAC;KAC+B,CAAA;IAElC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;AACvC,CAAC,CAAA"}
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
+
import type { DatabaseFactory, MainDatabase } from '@livestore/common';
|
|
2
|
+
import type { LiveStoreSchema } from '@livestore/common/schema';
|
|
1
3
|
import type { Scope } from '@livestore/utils/effect';
|
|
2
4
|
import { Context, Deferred, Effect, Layer } from '@livestore/utils/effect';
|
|
3
5
|
import * as otel from '@opentelemetry/api';
|
|
4
6
|
import type { GraphQLSchema } from 'graphql';
|
|
5
|
-
import type { InMemoryDatabase } from '../inMemoryDatabase.js';
|
|
6
7
|
import type { LiveQuery } from '../reactiveQueries/base-class.js';
|
|
7
|
-
import type {
|
|
8
|
-
import type { StorageInit } from '../storage/index.js';
|
|
9
|
-
import type { BaseGraphQLContext, GraphQLOptions, Store } from '../store.js';
|
|
8
|
+
import type { BaseGraphQLContext, BootDb, GraphQLOptions, Store } from '../store.js';
|
|
10
9
|
export type LiveStoreContext = {
|
|
11
10
|
store: Store;
|
|
12
11
|
};
|
|
13
12
|
export type QueryDefinition = <TResult>(store: Store) => LiveQuery<TResult>;
|
|
14
13
|
export type LiveStoreCreateStoreOptions<GraphQLContext extends BaseGraphQLContext> = {
|
|
15
14
|
schema: LiveStoreSchema;
|
|
16
|
-
loadStorage: () => StorageInit | Promise<StorageInit>;
|
|
17
15
|
graphQLOptions?: GraphQLOptions<GraphQLContext>;
|
|
18
16
|
otelTracer?: otel.Tracer;
|
|
19
17
|
otelRootSpanContext?: otel.Context;
|
|
20
|
-
boot?: (db:
|
|
18
|
+
boot?: (db: BootDb, parentSpan: otel.Span) => unknown | Promise<unknown>;
|
|
19
|
+
makeDb: DatabaseFactory;
|
|
20
|
+
batchUpdates?: (run: () => void) => void;
|
|
21
21
|
};
|
|
22
22
|
export declare const LiveStoreContext: Context.Tag<LiveStoreContext, LiveStoreContext>;
|
|
23
23
|
export type DeferredStoreContext = Deferred.Deferred<LiveStoreContext>;
|
|
24
24
|
export declare const DeferredStoreContext: Context.Tag<DeferredStoreContext, DeferredStoreContext>;
|
|
25
25
|
export type LiveStoreContextProps<GraphQLContext extends BaseGraphQLContext> = {
|
|
26
26
|
schema: LiveStoreSchema;
|
|
27
|
-
loadStorage: () => StorageInit | Promise<StorageInit>;
|
|
28
27
|
graphQLOptions?: {
|
|
29
28
|
schema: Effect.Effect<GraphQLSchema, never, otel.Tracer>;
|
|
30
|
-
makeContext: (db:
|
|
29
|
+
makeContext: (db: MainDatabase) => GraphQLContext;
|
|
31
30
|
};
|
|
32
|
-
boot?: (db:
|
|
31
|
+
boot?: (db: BootDb) => Effect.Effect<void>;
|
|
32
|
+
makeDb: DatabaseFactory;
|
|
33
33
|
};
|
|
34
34
|
export declare const LiveStoreContextLayer: <GraphQLContext extends BaseGraphQLContext>(props: LiveStoreContextProps<GraphQLContext>) => Layer.Layer<LiveStoreContext, never, otel.Tracer>;
|
|
35
35
|
export declare const LiveStoreContextDeferred: Layer.Layer<DeferredStoreContext, never, never>;
|
|
36
|
-
export declare const makeLiveStoreContext: <GraphQLContext extends BaseGraphQLContext>({ schema,
|
|
36
|
+
export declare const makeLiveStoreContext: <GraphQLContext extends BaseGraphQLContext>({ schema, graphQLOptions: graphQLOptions_, boot: boot_, makeDb, }: LiveStoreContextProps<GraphQLContext>) => Effect.Effect<LiveStoreContext, never, DeferredStoreContext | Scope.Scope | otel.Tracer>;
|
|
37
37
|
//# 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,
|
|
1
|
+
{"version":3,"file":"LiveStore.d.ts","sourceRoot":"","sources":["../../src/effect/LiveStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACtE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC/D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAY,MAAM,EAAE,KAAK,EAA6B,MAAM,yBAAyB,CAAA;AAC/G,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAA;AACjE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAIpF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAED,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,KAAK,SAAS,CAAC,OAAO,CAAC,CAAA;AAE3E,MAAM,MAAM,2BAA2B,CAAC,cAAc,SAAS,kBAAkB,IAAI;IACnF,MAAM,EAAE,eAAe,CAAA;IACvB,cAAc,CAAC,EAAE,cAAc,CAAC,cAAc,CAAC,CAAA;IAC/C,UAAU,CAAC,EAAE,IAAI,CAAC,MAAM,CAAA;IACxB,mBAAmB,CAAC,EAAE,IAAI,CAAC,OAAO,CAAA;IAClC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,IAAI,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IACxE,MAAM,EAAE,eAAe,CAAA;IACvB,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,IAAI,KAAK,IAAI,CAAA;CACzC,CAAA;AAED,eAAO,MAAM,gBAAgB,iDAAgF,CAAA;AAE7G,MAAM,MAAM,oBAAoB,GAAG,QAAQ,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAA;AACtE,eAAO,MAAM,oBAAoB,yDAEhC,CAAA;AAID,MAAM,MAAM,qBAAqB,CAAC,cAAc,SAAS,kBAAkB,IAAI;IAC7E,MAAM,EAAE,eAAe,CAAA;IACvB,cAAc,CAAC,EAAE;QACf,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;QACxD,WAAW,EAAE,CAAC,EAAE,EAAE,YAAY,KAAK,cAAc,CAAA;KAClD,CAAA;IACD,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAC1C,MAAM,EAAE,eAAe,CAAA;CACxB,CAAA;AAED,eAAO,MAAM,qBAAqB,+FAE/B,WAAW,CAAC,gBAAgB,EAAE,KAAK,EAAE,KAAK,MAAM,CAIhD,CAAA;AAEH,eAAO,MAAM,wBAAwB,iDAAwE,CAAA;AAE7G,eAAO,MAAM,oBAAoB,2JAKU,aAAa,CACtD,gBAAgB,EAChB,KAAK,EACL,oBAAoB,GAAG,WAAW,GAAG,KAAK,MAAM,CA4C/C,CAAA"}
|
package/dist/effect/LiveStore.js
CHANGED
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
import { Context, Deferred, Duration, Effect, Layer, OtelTracer, pipe, Runtime } from '@livestore/utils/effect';
|
|
2
2
|
import * as otel from '@opentelemetry/api';
|
|
3
|
-
import initSqlite3Wasm from 'sqlite-esm';
|
|
4
3
|
import { createStore } from '../store.js';
|
|
5
|
-
// NOTE we're starting to initialize the sqlite wasm binary here (already before calling `createStore`),
|
|
6
|
-
// so that it's ready when we need it
|
|
7
|
-
const sqlite3Promise = initSqlite3Wasm({
|
|
8
|
-
print: (message) => console.log(`[livestore sqlite] ${message}`),
|
|
9
|
-
printErr: (message) => console.error(`[livestore sqlite] ${message}`),
|
|
10
|
-
});
|
|
11
4
|
export const LiveStoreContext = Context.GenericTag('@livestore/livestore/LiveStoreContext');
|
|
12
5
|
export const DeferredStoreContext = Context.GenericTag('@livestore/livestore/DeferredStoreContext');
|
|
13
6
|
export const LiveStoreContextLayer = (props) => Layer.scoped(LiveStoreContext, makeLiveStoreContext(props)).pipe(Layer.withSpan('LiveStore'), Layer.provide(LiveStoreContextDeferred));
|
|
14
7
|
export const LiveStoreContextDeferred = Layer.effect(DeferredStoreContext, Deferred.make());
|
|
15
|
-
export const makeLiveStoreContext = ({ schema,
|
|
8
|
+
export const makeLiveStoreContext = ({ schema, graphQLOptions: graphQLOptions_, boot: boot_, makeDb, }) => pipe(Effect.gen(function* ($) {
|
|
16
9
|
const runtime = yield* $(Effect.runtime());
|
|
17
10
|
const otelRootSpanContext = otel.context.active();
|
|
18
11
|
const otelTracer = yield* $(OtelTracer.Tracer);
|
|
@@ -22,15 +15,13 @@ export const makeLiveStoreContext = ({ schema, loadStorage, graphQLOptions: grap
|
|
|
22
15
|
const boot = boot_
|
|
23
16
|
? (db) => boot_(db).pipe(Effect.withSpan('boot'), Effect.tapCauseLogPretty, Runtime.runPromise(runtime))
|
|
24
17
|
: undefined;
|
|
25
|
-
const sqlite3 = yield* $(Effect.promise(() => sqlite3Promise));
|
|
26
18
|
const store = yield* $(Effect.tryPromise(() => createStore({
|
|
27
19
|
schema,
|
|
28
|
-
loadStorage,
|
|
29
20
|
graphQLOptions,
|
|
30
21
|
otelTracer,
|
|
31
22
|
otelRootSpanContext,
|
|
32
23
|
boot,
|
|
33
|
-
|
|
24
|
+
makeDb,
|
|
34
25
|
})), Effect.acquireRelease((store) => Effect.sync(() => store.destroy())));
|
|
35
26
|
window.__debugLiveStore = store;
|
|
36
27
|
return { store };
|
|
@@ -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":"AAGA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAA;AAC/G,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAK1C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAmBzC,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAC,UAAU,CAAmB,uCAAuC,CAAC,CAAA;AAG7G,MAAM,CAAC,MAAM,oBAAoB,GAAG,OAAO,CAAC,UAAU,CACpD,2CAA2C,CAC5C,CAAA;AAcD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,KAA4C,EACO,EAAE,CACrD,KAAK,CAAC,MAAM,CAAC,gBAAgB,EAAE,oBAAoB,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAC9D,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,EAC3B,KAAK,CAAC,OAAO,CAAC,wBAAwB,CAAC,CACxC,CAAA;AAEH,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,CAAC,MAAM,CAAC,oBAAoB,EAAE,QAAQ,CAAC,IAAI,EAAoB,CAAC,CAAA;AAE7G,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAA4C,EAC9E,MAAM,EACN,cAAc,EAAE,eAAe,EAC/B,IAAI,EAAE,KAAK,EACX,MAAM,GACgC,EAItC,EAAE,CACF,IAAI,CACF,MAAM,CAAC,GAAG,CAAC,QAAQ,CAA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AClB,CAAC,CAAC,EACF,MAAM,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,oBAAoB,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,EACxG,MAAM,CAAC,WAAW,CAAC;IACjB,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI,KAAK,CAAC,sDAAsD,CAAC;IAClF,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;CAC/B,CAAC,EACF,MAAM,CAAC,KAAK,CACb,CAAA"}
|
package/dist/global-state.d.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* explicitly pass instances of state below into the LiveStore constructors.
|
|
11
11
|
*
|
|
12
12
|
*/
|
|
13
|
-
import type {
|
|
13
|
+
import type { DbSchema } from '@livestore/common/schema';
|
|
14
14
|
export declare const globalDbGraph: import("./reactiveQueries/base-class.js").DbGraph;
|
|
15
|
-
export declare const dynamicallyRegisteredTables: Map<string, TableDef>;
|
|
15
|
+
export declare const dynamicallyRegisteredTables: Map<string, DbSchema.TableDef>;
|
|
16
16
|
//# sourceMappingURL=global-state.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global-state.d.ts","sourceRoot":"","sources":["../src/global-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;
|
|
1
|
+
{"version":3,"file":"global-state.d.ts","sourceRoot":"","sources":["../src/global-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAIxD,eAAO,MAAM,aAAa,mDAAgB,CAAA;AAE1C,eAAO,MAAM,2BAA2B,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAa,CAAA"}
|
package/dist/global-state.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global-state.js","sourceRoot":"","sources":["../src/global-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;
|
|
1
|
+
{"version":3,"file":"global-state.js","sourceRoot":"","sources":["../src/global-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAA;AAE7D,MAAM,CAAC,MAAM,aAAa,GAAG,WAAW,EAAE,CAAA;AAE1C,MAAM,CAAC,MAAM,2BAA2B,GAAmC,IAAI,GAAG,EAAE,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
export { Store, createStore } from './store.js';
|
|
2
|
-
export type { BaseGraphQLContext, QueryDebugInfo, RefreshReason } from './store.js';
|
|
2
|
+
export type { BaseGraphQLContext, QueryDebugInfo, RefreshReason, BootDb } from './store.js';
|
|
3
3
|
export type { QueryDefinition, LiveStoreCreateStoreOptions, LiveStoreContext } from './effect/LiveStore.js';
|
|
4
|
-
export { InMemoryDatabase, type DebugInfo, emptyDebugInfo } from './
|
|
5
|
-
export type { Storage, StorageType, StorageInit } from './storage/index.js';
|
|
4
|
+
export { MainDatabaseWrapper as InMemoryDatabase, type DebugInfo, emptyDebugInfo } from './MainDatabaseWrapper.js';
|
|
6
5
|
export type { GetAtom, AtomDebugInfo, RefreshDebugInfo, SerializedAtom, Atom, Node, Ref, Effect } from './reactive.js';
|
|
7
6
|
export { LiveStoreJSQuery, computed } from './reactiveQueries/js.js';
|
|
8
7
|
export { LiveStoreSQLQuery, querySQL, type MapRows } from './reactiveQueries/sql.js';
|
|
@@ -11,9 +10,10 @@ export { type GetAtomResult, type DbGraph, makeDbGraph, type LiveQuery } from '.
|
|
|
11
10
|
export { globalDbGraph, dynamicallyRegisteredTables } from './global-state.js';
|
|
12
11
|
export { type RowResult, type RowResultEncoded, rowQuery, deriveColQuery } from './row-query.js';
|
|
13
12
|
export * from './cud.js';
|
|
14
|
-
export
|
|
15
|
-
export
|
|
13
|
+
export * from '@livestore/common/schema';
|
|
14
|
+
export { sql } from '@livestore/common';
|
|
16
15
|
export { SqliteAst, SqliteDsl } from 'effect-db-schema';
|
|
17
|
-
export { prepareBindValues,
|
|
16
|
+
export { prepareBindValues, type Bindable, type PreparedBindValues } from './utils/util.js';
|
|
18
17
|
export { isEqual } from 'lodash-es';
|
|
18
|
+
export type { DatabaseImpl, DatabaseFactory, PreparedStatement } from '@livestore/common';
|
|
19
19
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAC/C,YAAY,EAAE,kBAAkB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAC/C,YAAY,EAAE,kBAAkB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAE3F,YAAY,EAAE,eAAe,EAAE,2BAA2B,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAE3G,OAAO,EAAE,mBAAmB,IAAI,gBAAgB,EAAE,KAAK,SAAS,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAElH,YAAY,EAAE,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,cAAc,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AACtH,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,EAAE,KAAK,aAAa,EAAE,KAAK,OAAO,EAAE,WAAW,EAAE,KAAK,SAAS,EAAE,MAAM,iCAAiC,CAAA;AAE/G,OAAO,EAAE,aAAa,EAAE,2BAA2B,EAAE,MAAM,mBAAmB,CAAA;AAE9E,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,gBAAgB,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEhG,cAAc,UAAU,CAAA;AAExB,cAAc,0BAA0B,CAAA;AACxC,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AAEvC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAEvD,OAAO,EAAE,iBAAiB,EAAE,KAAK,QAAQ,EAAE,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAC3F,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Store, createStore } from './store.js';
|
|
2
|
-
export { InMemoryDatabase, emptyDebugInfo } from './
|
|
2
|
+
export { MainDatabaseWrapper as InMemoryDatabase, emptyDebugInfo } from './MainDatabaseWrapper.js';
|
|
3
3
|
export { LiveStoreJSQuery, computed } from './reactiveQueries/js.js';
|
|
4
4
|
export { LiveStoreSQLQuery, querySQL } from './reactiveQueries/sql.js';
|
|
5
5
|
export { LiveStoreGraphQLQuery, queryGraphQL } from './reactiveQueries/graphql.js';
|
|
@@ -7,8 +7,9 @@ export { makeDbGraph } from './reactiveQueries/base-class.js';
|
|
|
7
7
|
export { globalDbGraph, dynamicallyRegisteredTables } from './global-state.js';
|
|
8
8
|
export { rowQuery, deriveColQuery } from './row-query.js';
|
|
9
9
|
export * from './cud.js';
|
|
10
|
-
export
|
|
10
|
+
export * from '@livestore/common/schema';
|
|
11
|
+
export { sql } from '@livestore/common';
|
|
11
12
|
export { SqliteAst, SqliteDsl } from 'effect-db-schema';
|
|
12
|
-
export { prepareBindValues
|
|
13
|
+
export { prepareBindValues } from './utils/util.js';
|
|
13
14
|
export { isEqual } from 'lodash-es';
|
|
14
15
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAK/C,OAAO,EAAE,gBAAgB,EAAkB,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAK/C,OAAO,EAAE,mBAAmB,IAAI,gBAAgB,EAAkB,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAGlH,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,EAAoC,WAAW,EAAkB,MAAM,iCAAiC,CAAA;AAE/G,OAAO,EAAE,aAAa,EAAE,2BAA2B,EAAE,MAAM,mBAAmB,CAAA;AAE9E,OAAO,EAAyC,QAAQ,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEhG,cAAc,UAAU,CAAA;AAExB,cAAc,0BAA0B,CAAA;AACxC,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AAEvC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAEvD,OAAO,EAAE,iBAAiB,EAA0C,MAAM,iBAAiB,CAAA;AAC3F,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA"}
|
package/dist/migrations.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
import { type DatabaseImpl } from '@livestore/common';
|
|
2
|
+
import type { LiveStoreSchema } from '@livestore/common/schema';
|
|
1
3
|
import type * as otel from '@opentelemetry/api';
|
|
2
4
|
import { SqliteAst } from 'effect-db-schema';
|
|
3
|
-
import type { InMemoryDatabase } from './index.js';
|
|
4
|
-
import type { LiveStoreSchema } from './schema/index.js';
|
|
5
5
|
export declare const migrateDb: ({ db, otelContext, schema, }: {
|
|
6
|
-
db:
|
|
6
|
+
db: DatabaseImpl;
|
|
7
7
|
otelContext: otel.Context;
|
|
8
8
|
schema: LiveStoreSchema;
|
|
9
9
|
}) => void;
|
|
10
|
-
export declare const migrateTable: ({ db, tableAst,
|
|
11
|
-
db:
|
|
10
|
+
export declare const migrateTable: ({ db, tableAst, schemaHash, }: {
|
|
11
|
+
db: DatabaseImpl;
|
|
12
12
|
tableAst: SqliteAst.Table;
|
|
13
13
|
otelContext: otel.Context;
|
|
14
14
|
schemaHash: number;
|
package/dist/migrations.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../src/migrations.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../src/migrations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAO,MAAM,mBAAmB,CAAA;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAiB,MAAM,0BAA0B,CAAA;AAG9E,OAAO,KAAK,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAa,MAAM,kBAAkB,CAAA;AAoCvD,eAAO,MAAM,SAAS;QAKhB,YAAY;iBACH,KAAK,OAAO;YACjB,eAAe;UAiCxB,CAAA;AAED,eAAO,MAAM,YAAY;QAMnB,YAAY;cACN,UAAU,KAAK;iBACZ,KAAK,OAAO;gBACb,MAAM;UAwBnB,CAAA"}
|
package/dist/migrations.js
CHANGED
|
@@ -1,54 +1,70 @@
|
|
|
1
|
+
import { sql } from '@livestore/common';
|
|
2
|
+
import { SCHEMA_META_TABLE, systemTables } from '@livestore/common/schema';
|
|
1
3
|
import { Schema as EffectSchema } from '@livestore/utils/effect';
|
|
2
4
|
import { SqliteAst, SqliteDsl } from 'effect-db-schema';
|
|
3
5
|
import { memoize } from 'lodash-es';
|
|
4
|
-
import {
|
|
5
|
-
import { SCHEMA_META_TABLE, systemTables } from './schema/index.js';
|
|
6
|
-
import { sql } from './utils/util.js';
|
|
6
|
+
import { prepareBindValues } from './utils/util.js';
|
|
7
7
|
const getMemoizedTimestamp = memoize(() => new Date().toISOString());
|
|
8
|
+
// TODO bring back statement caching
|
|
9
|
+
// const cachedStmts = new Map<string, PreparedStatement>()
|
|
10
|
+
const dbExecute = (db, queryStr, bindValues) => {
|
|
11
|
+
// let stmt = cachedStmts.get(queryStr)
|
|
12
|
+
// if (!stmt) {
|
|
13
|
+
const stmt = db.mainDb.prepare(queryStr);
|
|
14
|
+
// cachedStmts.set(queryStr, stmt)
|
|
15
|
+
// }
|
|
16
|
+
const preparedBindValues = bindValues ? prepareBindValues(bindValues, queryStr) : undefined;
|
|
17
|
+
stmt.execute(preparedBindValues);
|
|
18
|
+
void db.storageDb.execute(queryStr, preparedBindValues, undefined);
|
|
19
|
+
};
|
|
20
|
+
const dbSelect = (db, queryStr, bindValues) => {
|
|
21
|
+
// let stmt = cachedStmts.get(queryStr)
|
|
22
|
+
// if (!stmt) {
|
|
23
|
+
const stmt = db.mainDb.prepare(queryStr);
|
|
24
|
+
// cachedStmts.set(queryStr, stmt)
|
|
25
|
+
// }
|
|
26
|
+
return stmt.select(bindValues ? prepareBindValues(bindValues, queryStr) : undefined);
|
|
27
|
+
};
|
|
8
28
|
// TODO more graceful DB migration (e.g. backup DB before destructive migrations)
|
|
9
29
|
export const migrateDb = ({ db, otelContext, schema, }) => {
|
|
10
|
-
db
|
|
30
|
+
dbExecute(db,
|
|
11
31
|
// TODO use schema migration definition from schema.ts instead
|
|
12
|
-
sql `create table if not exists ${SCHEMA_META_TABLE} (tableName text primary key, schemaHash text, updatedAt text)
|
|
13
|
-
const schemaMetaRows = db
|
|
32
|
+
sql `create table if not exists ${SCHEMA_META_TABLE} (tableName text primary key, schemaHash text, updatedAt text);`);
|
|
33
|
+
const schemaMetaRows = dbSelect(db, sql `SELECT * FROM ${SCHEMA_META_TABLE}`);
|
|
14
34
|
const dbSchemaHashByTable = Object.fromEntries(schemaMetaRows.map(({ tableName, schemaHash }) => [tableName, schemaHash]));
|
|
15
35
|
const tableDefs = new Set([
|
|
16
36
|
// NOTE it's important the `SCHEMA_META_TABLE` comes first since we're writing to it below
|
|
17
37
|
...systemTables,
|
|
18
38
|
...Array.from(schema.tables.values()).filter((_) => _.sqliteDef.name !== SCHEMA_META_TABLE),
|
|
19
|
-
...dynamicallyRegisteredTables.values(),
|
|
20
39
|
]);
|
|
21
40
|
for (const tableDef of tableDefs) {
|
|
22
41
|
const tableAst = tableDef.sqliteDef.ast;
|
|
23
42
|
const tableName = tableAst.name;
|
|
24
43
|
const dbSchemaHash = dbSchemaHashByTable[tableName];
|
|
25
44
|
const schemaHash = SqliteAst.hash(tableAst);
|
|
26
|
-
if (schemaHash !== dbSchemaHash) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
console.log(`Schema hash mismatch for table '${tableName}' (DB: ${dbSchemaHash}, expected: ${schemaHash}), migrating table...`);
|
|
32
|
-
migrateTable({ db, tableAst, otelContext, schemaHash });
|
|
33
|
-
}
|
|
45
|
+
if (schemaHash !== dbSchemaHash && import.meta.env.VITE_LIVESTORE_SKIP_MIGRATIONS === undefined) {
|
|
46
|
+
console.log(`Schema hash mismatch for table '${tableName}' (DB: ${dbSchemaHash}, expected: ${schemaHash}), migrating table...`);
|
|
47
|
+
migrateTable({ db, tableAst, otelContext, schemaHash });
|
|
34
48
|
}
|
|
35
49
|
}
|
|
36
50
|
};
|
|
37
|
-
export const migrateTable = ({ db, tableAst,
|
|
51
|
+
export const migrateTable = ({ db, tableAst,
|
|
52
|
+
// otelContext,
|
|
53
|
+
schemaHash, }) => {
|
|
38
54
|
console.log(`Migrating table '${tableAst.name}'...`);
|
|
39
55
|
const tableName = tableAst.name;
|
|
40
56
|
const columnSpec = makeColumnSpec(tableAst);
|
|
41
57
|
// TODO need to possibly handle cascading deletes due to foreign keys
|
|
42
|
-
db
|
|
43
|
-
db
|
|
58
|
+
dbExecute(db, sql `drop table if exists ${tableName}`);
|
|
59
|
+
dbExecute(db, sql `create table if not exists ${tableName} (${columnSpec})`);
|
|
44
60
|
for (const index of tableAst.indexes) {
|
|
45
|
-
db
|
|
61
|
+
dbExecute(db, createIndexFromDefinition(tableName, index));
|
|
46
62
|
}
|
|
47
63
|
const updatedAt = getMemoizedTimestamp();
|
|
48
|
-
db
|
|
64
|
+
dbExecute(db, sql `
|
|
49
65
|
INSERT INTO ${SCHEMA_META_TABLE} (tableName, schemaHash, updatedAt) VALUES ($tableName, $schemaHash, $updatedAt)
|
|
50
66
|
ON CONFLICT (tableName) DO UPDATE SET schemaHash = $schemaHash, updatedAt = $updatedAt;
|
|
51
|
-
`, {
|
|
67
|
+
`, { tableName, schemaHash, updatedAt });
|
|
52
68
|
};
|
|
53
69
|
const createIndexFromDefinition = (tableName, index) => {
|
|
54
70
|
const uniqueStr = index.unique ? 'UNIQUE' : '';
|
package/dist/migrations.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrations.js","sourceRoot":"","sources":["../src/migrations.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M,CAAC,OAAO,CAAC,IAAI,KAAK,MAAM;YAAE,OAAO,EAAE,CAAA;QAE7C,IAAI,SAAS,CAAC,iBAAiB,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;YAAE,OAAO,WAAW,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,CAAA;QAEnG,MAAM,WAAW,GAAG,YAAY,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QAC1D,MAAM,mBAAmB,GAAG,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QAE7D,IAAI,aAAa,KAAK,MAAM;YAAE,OAAO,YAAY,mBAAmB,GAAG,CAAA;QACvE,OAAO,WAAW,mBAAmB,EAAE,CAAA;IACzC,CAAC,CAAC,EAAE,CAAA;IAEJ,OAAO,GAAG,MAAM,CAAC,IAAI,IAAI,aAAa,IAAI,WAAW,IAAI,eAAe,EAAE,CAAA;AAC5E,CAAC,CAAA"}
|
package/dist/query-info.d.ts
CHANGED
|
@@ -1,28 +1,27 @@
|
|
|
1
|
+
import { type DbSchema, type RawSqlMutationEvent } from '@livestore/common/schema';
|
|
1
2
|
import { Schema } from '@livestore/utils/effect';
|
|
2
|
-
import { type RawSqlMutationEvent } from './schema/mutations.js';
|
|
3
|
-
import type { FromTable, TableDef } from './schema/table-def.js';
|
|
4
3
|
/**
|
|
5
4
|
* Semantic information about a query with supported cases being:
|
|
6
5
|
* - a whole row
|
|
7
6
|
* - a single column value
|
|
8
7
|
* - a sub value in a JSON column
|
|
9
8
|
*/
|
|
10
|
-
export type QueryInfo<TTableDef extends TableDef = TableDef> = QueryInfoNone | QueryInfoRow<TTableDef> | QueryInfoColJsonValue<TTableDef, GetJsonColumn<TTableDef>> | QueryInfoCol<TTableDef, keyof TTableDef['sqliteDef']['columns']>;
|
|
9
|
+
export type QueryInfo<TTableDef extends DbSchema.TableDef = DbSchema.TableDef> = QueryInfoNone | QueryInfoRow<TTableDef> | QueryInfoColJsonValue<TTableDef, GetJsonColumn<TTableDef>> | QueryInfoCol<TTableDef, keyof TTableDef['sqliteDef']['columns']>;
|
|
11
10
|
export type QueryInfoNone = {
|
|
12
11
|
_tag: 'None';
|
|
13
12
|
};
|
|
14
|
-
export type QueryInfoRow<TTableDef extends TableDef> = {
|
|
13
|
+
export type QueryInfoRow<TTableDef extends DbSchema.TableDef> = {
|
|
15
14
|
_tag: 'Row';
|
|
16
15
|
table: TTableDef;
|
|
17
16
|
id: string;
|
|
18
17
|
};
|
|
19
|
-
export type QueryInfoCol<TTableDef extends TableDef, TColName extends keyof TTableDef['sqliteDef']['columns']> = {
|
|
18
|
+
export type QueryInfoCol<TTableDef extends DbSchema.TableDef, TColName extends keyof TTableDef['sqliteDef']['columns']> = {
|
|
20
19
|
_tag: 'Col';
|
|
21
20
|
table: TTableDef;
|
|
22
21
|
id: string;
|
|
23
22
|
column: TColName;
|
|
24
23
|
};
|
|
25
|
-
export type QueryInfoColJsonValue<TTableDef extends TableDef, TColName extends GetJsonColumn<TTableDef>> = {
|
|
24
|
+
export type QueryInfoColJsonValue<TTableDef extends DbSchema.TableDef, TColName extends GetJsonColumn<TTableDef>> = {
|
|
26
25
|
_tag: 'ColJsonValue';
|
|
27
26
|
table: TTableDef;
|
|
28
27
|
id: string;
|
|
@@ -32,18 +31,18 @@ export type QueryInfoColJsonValue<TTableDef extends TableDef, TColName extends G
|
|
|
32
31
|
*/
|
|
33
32
|
jsonPath: string;
|
|
34
33
|
};
|
|
35
|
-
type GetJsonColumn<TTableDef extends TableDef> = keyof {
|
|
34
|
+
type GetJsonColumn<TTableDef extends DbSchema.TableDef> = keyof {
|
|
36
35
|
[ColName in keyof TTableDef['sqliteDef']['columns'] as TTableDef['sqliteDef']['columns'][ColName]['columnType'] extends 'text' ? ColName : never]: {};
|
|
37
36
|
};
|
|
38
37
|
export type UpdateValueForPath<TPath extends QueryInfo> = TPath extends {
|
|
39
38
|
_tag: 'Row';
|
|
40
|
-
} ? Partial<FromTable.RowDecodedAll<TPath['table']>> : TPath extends {
|
|
39
|
+
} ? Partial<DbSchema.FromTable.RowDecodedAll<TPath['table']>> : TPath extends {
|
|
41
40
|
_tag: 'Col';
|
|
42
41
|
} ? Schema.Schema.To<TPath['table']['sqliteDef']['columns'][TPath['column']]['schema']> : TPath extends {
|
|
43
42
|
_tag: 'ColJsonValue';
|
|
44
43
|
} ? {
|
|
45
44
|
TODO: true;
|
|
46
45
|
} : never;
|
|
47
|
-
export declare const mutationForQueryInfo: <const TPath extends QueryInfo<TableDef
|
|
46
|
+
export declare const mutationForQueryInfo: <const TPath extends QueryInfo<DbSchema.TableDef<DbSchema.DefaultSqliteTableDefConstrained, boolean, DbSchema.TableOptions, Schema.Schema<any, any, never>>>>(updatePath: TPath, value: UpdateValueForPath<TPath>) => RawSqlMutationEvent;
|
|
48
47
|
export {};
|
|
49
48
|
//# sourceMappingURL=query-info.d.ts.map
|
package/dist/query-info.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-info.d.ts","sourceRoot":"","sources":["../src/query-info.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"query-info.d.ts","sourceRoot":"","sources":["../src/query-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAkB,KAAK,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAElG,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEhD;;;;;GAKG;AACH,MAAM,MAAM,SAAS,CAAC,SAAS,SAAS,QAAQ,CAAC,QAAQ,GAAG,QAAQ,CAAC,QAAQ,IACzE,aAAa,GACb,YAAY,CAAC,SAAS,CAAC,GACvB,qBAAqB,CAAC,SAAS,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC,GAC1D,YAAY,CAAC,SAAS,EAAE,MAAM,SAAS,CAAC,WAAW,CAAC,CAAC,SAAS,CAAC,CAAC,CAAA;AAEpE,MAAM,MAAM,aAAa,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AAC,CAAC,GACzD,KAAK,SAAS;IAAE,IAAI,EAAE,KAAK,CAAA;CAAE,GAC3B,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,GACnF,KAAK,SAAS;IAAE,IAAI,EAAE,cAAc,CAAA;CAAE,GACpC;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,GACd,KAAK,CAAA;AAEb,eAAO,MAAM,oBAAoB,wNAG9B,mBAmCF,CAAA"}
|
package/dist/query-info.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { rawSqlMutation } from '@livestore/common/schema';
|
|
1
2
|
import { notYetImplemented, shouldNeverHappen } from '@livestore/utils';
|
|
2
3
|
import { Schema } from '@livestore/utils/effect';
|
|
3
|
-
import { rawSqlMutation } from './schema/mutations.js';
|
|
4
4
|
export const mutationForQueryInfo = (updatePath, value) => {
|
|
5
5
|
if (updatePath._tag === 'ColJsonValue' || updatePath._tag === 'None') {
|
|
6
6
|
return notYetImplemented('TODO');
|
package/dist/query-info.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-info.js","sourceRoot":"","sources":["../src/query-info.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"query-info.js","sourceRoot":"","sources":["../src/query-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,cAAc,EAA4B,MAAM,0BAA0B,CAAA;AAClG,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AA2DhD,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,UAAiB,EACjB,KAAgC,EACX,EAAE;IACvB,IAAI,UAAU,CAAC,IAAI,KAAK,cAAc,IAA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W,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,GAAG,UAAU,OAAO,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAEjG,MAAM,WAAW,GAAG,eAAe,EAAE,GAAG,CAAA;IACxC,MAAM,GAAG,GAAG,UAAU,cAAc,CAAC,IAAI,QAAQ,YAAY,IAAI,WAAW,EAAE,CAAA;IAC9E,MAAM,WAAW,GAAG,IAAI,GAAG,CAAS,CAAC,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAA;IAEtE,OAAO,cAAc,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAA;AACzD,CAAC,CAAA"}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
+
import type { DatabaseFactory } from '@livestore/common';
|
|
2
|
+
import type { LiveStoreSchema } from '@livestore/common/schema';
|
|
1
3
|
import type * as otel from '@opentelemetry/api';
|
|
2
4
|
import type { ReactElement, ReactNode } from 'react';
|
|
3
|
-
import type {
|
|
4
|
-
import type { LiveStoreSchema } from '../schema/index.js';
|
|
5
|
-
import type { StorageInit } from '../storage/index.js';
|
|
6
|
-
import type { BaseGraphQLContext, GraphQLOptions } from '../store.js';
|
|
5
|
+
import type { BaseGraphQLContext, BootDb, GraphQLOptions } from '../store.js';
|
|
7
6
|
interface LiveStoreProviderProps<GraphQLContext> {
|
|
8
7
|
schema: LiveStoreSchema;
|
|
9
|
-
|
|
10
|
-
boot?: (db: InMemoryDatabase, parentSpan: otel.Span) => unknown | Promise<unknown>;
|
|
8
|
+
boot?: (db: BootDb, parentSpan: otel.Span) => unknown | Promise<unknown>;
|
|
11
9
|
graphQLOptions?: GraphQLOptions<GraphQLContext>;
|
|
12
10
|
otelTracer?: otel.Tracer;
|
|
13
11
|
otelRootSpanContext?: otel.Context;
|
|
14
12
|
fallback: ReactElement;
|
|
13
|
+
makeDb: DatabaseFactory;
|
|
14
|
+
batchUpdates?: (run: () => void) => void;
|
|
15
15
|
}
|
|
16
|
-
export declare const LiveStoreProvider: <GraphQLContext extends BaseGraphQLContext>({ fallback,
|
|
16
|
+
export declare const LiveStoreProvider: <GraphQLContext extends BaseGraphQLContext>({ fallback, graphQLOptions, otelTracer, otelRootSpanContext, children, schema, boot, makeDb, batchUpdates, }: LiveStoreProviderProps<GraphQLContext> & {
|
|
17
17
|
children?: ReactNode;
|
|
18
18
|
}) => JSX.Element;
|
|
19
19
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LiveStoreProvider.d.ts","sourceRoot":"","sources":["../../src/react/LiveStoreProvider.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"LiveStoreProvider.d.ts","sourceRoot":"","sources":["../../src/react/LiveStoreProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAE/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,MAAM,EAAE,cAAc,EAAS,MAAM,aAAa,CAAA;AAIpF,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,UAAU,CAAC,EAAE,IAAI,CAAC,MAAM,CAAA;IACxB,mBAAmB,CAAC,EAAE,IAAI,CAAC,OAAO,CAAA;IAClC,QAAQ,EAAE,YAAY,CAAA;IACtB,MAAM,EAAE,eAAe,CAAA;IACvB,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,IAAI,KAAK,IAAI,CAAA;CACzC;AAED,eAAO,MAAM,iBAAiB;eAU2B,SAAS;MAAK,WAkBtE,CAAA"}
|