@livestore/livestore 0.0.12 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/dist/.tsbuildinfo +1 -0
- package/dist/QueryCache.d.ts +20 -0
- package/dist/QueryCache.d.ts.map +1 -0
- package/dist/QueryCache.js +71 -0
- package/dist/QueryCache.js.map +1 -0
- package/dist/__tests__/react/fixture.d.ts +25 -0
- package/dist/__tests__/react/fixture.d.ts.map +1 -0
- package/dist/__tests__/react/fixture.js +60 -0
- package/dist/__tests__/react/fixture.js.map +1 -0
- package/dist/__tests__/react/useLiveStoreComponent.test.d.ts +2 -0
- package/dist/__tests__/react/useLiveStoreComponent.test.d.ts.map +1 -0
- package/dist/__tests__/react/useLiveStoreComponent.test.js +78 -0
- package/dist/__tests__/react/useLiveStoreComponent.test.js.map +1 -0
- package/dist/__tests__/reactive.test.d.ts +2 -0
- package/dist/__tests__/reactive.test.d.ts.map +1 -0
- package/dist/__tests__/reactive.test.js +197 -0
- package/dist/__tests__/reactive.test.js.map +1 -0
- package/dist/bounded-collections.d.ts +34 -0
- package/dist/bounded-collections.d.ts.map +1 -0
- package/dist/bounded-collections.js +103 -0
- package/dist/bounded-collections.js.map +1 -0
- package/dist/componentKey.d.ts +20 -0
- package/dist/componentKey.d.ts.map +1 -0
- package/dist/componentKey.js +3 -0
- package/dist/componentKey.js.map +1 -0
- package/dist/effect/LiveStore.d.ts +36 -0
- package/dist/effect/LiveStore.d.ts.map +1 -0
- package/dist/effect/LiveStore.js +41 -0
- package/dist/effect/LiveStore.js.map +1 -0
- package/dist/effect/index.d.ts +2 -0
- package/dist/effect/index.d.ts.map +1 -0
- package/dist/effect/index.js +2 -0
- package/dist/effect/index.js.map +1 -0
- package/dist/events.d.ts +7 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +2 -0
- package/dist/events.js.map +1 -0
- package/dist/inMemoryDatabase.d.ts +56 -0
- package/dist/inMemoryDatabase.d.ts.map +1 -0
- package/dist/inMemoryDatabase.js +223 -0
- package/dist/inMemoryDatabase.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/migrations.d.ts +16 -0
- package/dist/migrations.d.ts.map +1 -0
- package/dist/migrations.js +67 -0
- package/dist/migrations.js.map +1 -0
- package/dist/otel.d.ts +4 -0
- package/dist/otel.d.ts.map +1 -0
- package/dist/otel.js +6 -0
- package/dist/otel.js.map +1 -0
- package/dist/react/LiveStoreContext.d.ts +11 -0
- package/dist/react/LiveStoreContext.d.ts.map +1 -0
- package/dist/react/LiveStoreContext.js +10 -0
- package/dist/react/LiveStoreContext.js.map +1 -0
- package/dist/react/LiveStoreProvider.d.ts +20 -0
- package/dist/react/LiveStoreProvider.d.ts.map +1 -0
- package/dist/react/LiveStoreProvider.js +52 -0
- package/dist/react/LiveStoreProvider.js.map +1 -0
- package/dist/react/index.d.ts +8 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +6 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/useGraphQL.d.ts +13 -0
- package/dist/react/useGraphQL.d.ts.map +1 -0
- package/dist/react/useGraphQL.js +85 -0
- package/dist/react/useGraphQL.js.map +1 -0
- package/dist/react/useLiveStoreComponent.d.ts +75 -0
- package/dist/react/useLiveStoreComponent.d.ts.map +1 -0
- package/dist/react/useLiveStoreComponent.js +317 -0
- package/dist/react/useLiveStoreComponent.js.map +1 -0
- package/dist/react/useQuery.d.ts +3 -0
- package/dist/react/useQuery.d.ts.map +1 -0
- package/dist/react/useQuery.js +38 -0
- package/dist/react/useQuery.js.map +1 -0
- package/dist/react/utils/useStateRefWithReactiveInput.d.ts +13 -0
- package/dist/react/utils/useStateRefWithReactiveInput.d.ts.map +1 -0
- package/dist/react/utils/useStateRefWithReactiveInput.js +38 -0
- package/dist/react/utils/useStateRefWithReactiveInput.js.map +1 -0
- package/dist/reactive.d.ts +140 -0
- package/dist/reactive.d.ts.map +1 -0
- package/dist/reactive.js +302 -0
- package/dist/reactive.js.map +1 -0
- package/dist/reactiveQueries/base-class.d.ts +27 -0
- package/dist/reactiveQueries/base-class.d.ts.map +1 -0
- package/dist/reactiveQueries/base-class.js +23 -0
- package/dist/reactiveQueries/base-class.js.map +1 -0
- package/dist/reactiveQueries/graphql.d.ts +25 -0
- package/dist/reactiveQueries/graphql.d.ts.map +1 -0
- package/dist/reactiveQueries/graphql.js +18 -0
- package/dist/reactiveQueries/graphql.js.map +1 -0
- package/dist/reactiveQueries/js.d.ts +19 -0
- package/dist/reactiveQueries/js.d.ts.map +1 -0
- package/dist/reactiveQueries/js.js +13 -0
- package/dist/reactiveQueries/js.js.map +1 -0
- package/dist/reactiveQueries/sql.d.ts +31 -0
- package/dist/reactiveQueries/sql.d.ts.map +1 -0
- package/dist/reactiveQueries/sql.js +32 -0
- package/dist/reactiveQueries/sql.js.map +1 -0
- package/dist/schema.d.ts +81 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +46 -0
- package/dist/schema.js.map +1 -0
- package/dist/storage/in-memory/index.d.ts +15 -0
- package/dist/storage/in-memory/index.d.ts.map +1 -0
- package/dist/storage/in-memory/index.js +14 -0
- package/dist/storage/in-memory/index.js.map +1 -0
- package/dist/storage/index.d.ts +14 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +9 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/tauri/index.d.ts +19 -0
- package/dist/storage/tauri/index.d.ts.map +1 -0
- package/dist/storage/tauri/index.js +38 -0
- package/dist/storage/tauri/index.js.map +1 -0
- package/dist/storage/utils/idb.d.ts +10 -0
- package/dist/storage/utils/idb.d.ts.map +1 -0
- package/dist/storage/utils/idb.js +58 -0
- package/dist/storage/utils/idb.js.map +1 -0
- package/dist/storage/web-worker/index.d.ts +27 -0
- package/dist/storage/web-worker/index.d.ts.map +1 -0
- package/dist/storage/web-worker/index.js +74 -0
- package/dist/storage/web-worker/index.js.map +1 -0
- package/dist/storage/web-worker/worker.d.ts +13 -0
- package/dist/storage/web-worker/worker.d.ts.map +1 -0
- package/dist/storage/web-worker/worker.js +110 -0
- package/dist/storage/web-worker/worker.js.map +1 -0
- package/dist/store.d.ts +199 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +603 -0
- package/dist/store.js.map +1 -0
- package/dist/util.d.ts +28 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +55 -0
- package/dist/util.js.map +1 -0
- package/package.json +46 -19
- package/src/__tests__/react/fixture.tsx +23 -32
- package/src/__tests__/reactive.test.ts +3 -4
- package/src/effect/LiveStore.ts +22 -31
- package/src/events.ts +1 -1
- package/src/inMemoryDatabase.ts +115 -140
- package/src/index.ts +20 -20
- package/src/migrations.ts +119 -0
- package/src/otel.ts +0 -11
- package/src/react/LiveStoreProvider.tsx +24 -23
- package/src/react/index.ts +10 -1
- package/src/react/useGraphQL.ts +28 -2
- package/src/react/useLiveStoreComponent.ts +134 -50
- package/src/react/useQuery.ts +56 -0
- package/src/reactive.ts +6 -4
- package/src/reactiveQueries/base-class.ts +9 -3
- package/src/reactiveQueries/graphql.ts +4 -4
- package/src/reactiveQueries/js.ts +2 -2
- package/src/reactiveQueries/sql.ts +6 -6
- package/src/schema.ts +69 -145
- package/src/storage/in-memory/index.ts +21 -0
- package/src/storage/index.ts +27 -0
- package/src/{backends/tauri.ts → storage/tauri/index.ts} +14 -28
- package/src/storage/web-worker/index.ts +116 -0
- package/src/{backends/web-worker.ts → storage/web-worker/worker.ts} +17 -52
- package/src/store.ts +171 -98
- package/src/util.ts +13 -3
- package/tsconfig.json +1 -3
- package/src/backends/base.ts +0 -67
- package/src/backends/index.ts +0 -98
- package/src/backends/noop.ts +0 -32
- package/src/backends/web-in-memory.ts +0 -65
- package/src/backends/web.ts +0 -97
- package/src/react/useGlobalQuery.ts +0 -40
- /package/src/{backends → storage}/utils/idb.ts +0 -0
package/src/backends/index.ts
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
// A backend represents a raw SQLite database.
|
|
2
|
-
// Examples include:
|
|
3
|
-
// - A native SQLite process running in a Tauri Rust process
|
|
4
|
-
// - A SQL.js WASM version of SQLite running in a web worker
|
|
5
|
-
//
|
|
6
|
-
// We can send commands to execute various kinds of queries,
|
|
7
|
-
// and respond to various events from the database.
|
|
8
|
-
|
|
9
|
-
import type * as otel from '@opentelemetry/api'
|
|
10
|
-
|
|
11
|
-
import type { LiveStoreEvent } from '../events.js'
|
|
12
|
-
import type { ActionDefinition } from '../schema.js'
|
|
13
|
-
import type { ParamsObject } from '../util.js'
|
|
14
|
-
import { casesHandled } from '../util.js'
|
|
15
|
-
import type { BackendOptionsTauri } from './tauri.js'
|
|
16
|
-
import type { BackendOptionsWeb } from './web.js'
|
|
17
|
-
import { WebWorkerBackend } from './web.js'
|
|
18
|
-
import type { BackendOptionsWebInMemory } from './web-in-memory.js'
|
|
19
|
-
import { WebInMemoryBackend } from './web-in-memory.js'
|
|
20
|
-
|
|
21
|
-
/* A location of a persistent writable SQLite file */
|
|
22
|
-
export type WritableDatabaseLocation =
|
|
23
|
-
| {
|
|
24
|
-
type: 'opfs'
|
|
25
|
-
virtualFilename: string
|
|
26
|
-
}
|
|
27
|
-
| {
|
|
28
|
-
type: 'indexeddb'
|
|
29
|
-
virtualFilename: string
|
|
30
|
-
}
|
|
31
|
-
| {
|
|
32
|
-
type: 'filesystem'
|
|
33
|
-
directory: string
|
|
34
|
-
filename: string
|
|
35
|
-
}
|
|
36
|
-
| {
|
|
37
|
-
type: 'volatile-in-memory'
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export interface Backend {
|
|
41
|
-
// Select some data from the DB.
|
|
42
|
-
// This should only do reads, not writes, but we don't strongly enforce that.
|
|
43
|
-
select<T = any>(query: string, bindValues?: ParamsObject, parentSpan?: otel.Span): Promise<SelectResponse<T>>
|
|
44
|
-
|
|
45
|
-
// Execute a query where you don't care about the result.
|
|
46
|
-
// Used for writes and configuration changes.
|
|
47
|
-
execute(query: string, bindValues?: ParamsObject, parentSpan?: otel.Span): void
|
|
48
|
-
|
|
49
|
-
/** Apply an event to the backend */
|
|
50
|
-
applyEvent(event: LiveStoreEvent, eventDefiniton: ActionDefinition, parentSpan?: otel.Span): void
|
|
51
|
-
|
|
52
|
-
/** Return a snapshot of persisted data from the backend */
|
|
53
|
-
getPersistedData(parentSpan?: otel.Span): Promise<Uint8Array>
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export type BackendType = 'tauri' | 'web' | 'web-in-memory'
|
|
57
|
-
|
|
58
|
-
export const isBackendType = (type: string): type is BackendType => {
|
|
59
|
-
return type === 'tauri' || type === 'web' || type === 'web-in-memory'
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export type SelectResponse<T = any> = {
|
|
63
|
-
results: T[]
|
|
64
|
-
|
|
65
|
-
// other perf stats metadata about how long the query took
|
|
66
|
-
[key: string]: any
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export enum IndexType {
|
|
70
|
-
Basic = 'Basic',
|
|
71
|
-
FullText = 'FullText',
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export type BackendOptions = BackendOptionsTauri | BackendOptionsWeb | BackendOptionsWebInMemory
|
|
75
|
-
export type BackendOtelProps = {
|
|
76
|
-
otelTracer: otel.Tracer
|
|
77
|
-
parentSpan: otel.Span
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export const createBackend = async (options: BackendOptions, otelProps: BackendOtelProps): Promise<Backend> => {
|
|
81
|
-
switch (options.type) {
|
|
82
|
-
case 'tauri': {
|
|
83
|
-
// NOTE Dynamic import is needed to avoid Tauri is a dependency of LiveStore (e.g. when used in the web)
|
|
84
|
-
const { TauriBackend } = await import('./tauri.js')
|
|
85
|
-
return await TauriBackend.load(options, otelProps)
|
|
86
|
-
}
|
|
87
|
-
case 'web': {
|
|
88
|
-
return WebWorkerBackend.load(options, otelProps)
|
|
89
|
-
}
|
|
90
|
-
// NOTE currently only needed for testing
|
|
91
|
-
case 'web-in-memory': {
|
|
92
|
-
return WebInMemoryBackend.load(options, otelProps)
|
|
93
|
-
}
|
|
94
|
-
default: {
|
|
95
|
-
casesHandled(options)
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
package/src/backends/noop.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { makeNoopTracer } from '@livestore/utils'
|
|
2
|
-
import type * as otel from '@opentelemetry/api'
|
|
3
|
-
|
|
4
|
-
import type { ParamsObject } from '../util.js'
|
|
5
|
-
import { BaseBackend } from './base.js'
|
|
6
|
-
import type { SelectResponse } from './index.js'
|
|
7
|
-
|
|
8
|
-
export type BackendOptionsNoop = {
|
|
9
|
-
type: 'noop'
|
|
10
|
-
/** Specifies where to persist data for this backend */
|
|
11
|
-
otelTracer?: otel.Tracer
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export class NoopBackend extends BaseBackend {
|
|
15
|
-
constructor(readonly otelTracer: otel.Tracer) {
|
|
16
|
-
super()
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
static load = async (options: BackendOptionsNoop): Promise<NoopBackend> => {
|
|
20
|
-
return new NoopBackend(options.otelTracer ?? makeNoopTracer())
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
execute = (_query: string, _bindValues?: ParamsObject): void => {}
|
|
24
|
-
|
|
25
|
-
select = async <T>(_query: string, _bindValues?: ParamsObject): Promise<SelectResponse<T>> => {
|
|
26
|
-
return { results: [] }
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
getPersistedData = async (): Promise<Uint8Array> => {
|
|
30
|
-
return new Uint8Array()
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import type * as otel from '@opentelemetry/api'
|
|
2
|
-
import type * as SqliteWasm from 'sqlite-esm'
|
|
3
|
-
import sqlite3InitModule from 'sqlite-esm'
|
|
4
|
-
|
|
5
|
-
import type { ParamsObject } from '../util.js'
|
|
6
|
-
import { prepareBindValues } from '../util.js'
|
|
7
|
-
import { BaseBackend } from './base.js'
|
|
8
|
-
import type { BackendOtelProps, SelectResponse } from './index.js'
|
|
9
|
-
|
|
10
|
-
export type BackendOptionsWebInMemory = {
|
|
11
|
-
type: 'web-in-memory'
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
declare type DatabaseWithCAPI = SqliteWasm.Database & { capi: SqliteWasm.CAPI }
|
|
15
|
-
|
|
16
|
-
// NOTE: This backend is currently only used for testing
|
|
17
|
-
export class WebInMemoryBackend extends BaseBackend {
|
|
18
|
-
constructor(
|
|
19
|
-
readonly otelTracer: otel.Tracer,
|
|
20
|
-
readonly db: DatabaseWithCAPI,
|
|
21
|
-
) {
|
|
22
|
-
super()
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
static load = async (
|
|
26
|
-
_options: BackendOptionsWebInMemory,
|
|
27
|
-
{ otelTracer }: BackendOtelProps,
|
|
28
|
-
): Promise<WebInMemoryBackend> => {
|
|
29
|
-
const sqlite3 = await sqlite3InitModule({
|
|
30
|
-
print: (message) => console.log(`[sql-client] ${message}`),
|
|
31
|
-
printErr: (message) => console.error(`[sql-client] ${message}`),
|
|
32
|
-
})
|
|
33
|
-
const db = new sqlite3.oo1.DB({ filename: ':memory:', flags: 'c' }) as DatabaseWithCAPI
|
|
34
|
-
db.capi = sqlite3.capi
|
|
35
|
-
|
|
36
|
-
return new WebInMemoryBackend(otelTracer, db)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
execute = (query: string, bindValues?: ParamsObject): void => {
|
|
40
|
-
this.db.exec({
|
|
41
|
-
sql: query,
|
|
42
|
-
bind: prepareBindValues(bindValues ?? {}, query) as TODO,
|
|
43
|
-
returnValue: 'resultRows',
|
|
44
|
-
rowMode: 'object',
|
|
45
|
-
})
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
select = async <T>(query: string, bindValues?: ParamsObject): Promise<SelectResponse<T>> => {
|
|
49
|
-
const resultRows: T[] = []
|
|
50
|
-
|
|
51
|
-
this.db.exec({
|
|
52
|
-
sql: query,
|
|
53
|
-
bind: prepareBindValues(bindValues ?? {}, query) as TODO,
|
|
54
|
-
rowMode: 'object',
|
|
55
|
-
resultRows,
|
|
56
|
-
// callback: (row: any) => console.log('select result', db.filename, query, row),
|
|
57
|
-
} as TODO)
|
|
58
|
-
|
|
59
|
-
return { results: resultRows }
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
getPersistedData = async (): Promise<Uint8Array> => {
|
|
63
|
-
return this.db.capi.sqlite3_js_db_export(this.db.pointer)
|
|
64
|
-
}
|
|
65
|
-
}
|
package/src/backends/web.ts
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import type * as otel from '@opentelemetry/api'
|
|
2
|
-
import * as Comlink from 'comlink'
|
|
3
|
-
|
|
4
|
-
import type { ParamsObject } from '../util.js'
|
|
5
|
-
import { prepareBindValues } from '../util.js'
|
|
6
|
-
import { BaseBackend } from './base.js'
|
|
7
|
-
import type { BackendOtelProps, SelectResponse, WritableDatabaseLocation } from './index.js'
|
|
8
|
-
import type { WrappedWorker } from './web-worker.js'
|
|
9
|
-
|
|
10
|
-
export type BackendOptionsWeb = {
|
|
11
|
-
type: 'web'
|
|
12
|
-
/** Specifies where to persist data for this backend */
|
|
13
|
-
persistentDatabaseLocation: WritableDatabaseLocation
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export class WebWorkerBackend extends BaseBackend {
|
|
17
|
-
worker: Comlink.Remote<WrappedWorker>
|
|
18
|
-
persistentDatabaseLocation: WritableDatabaseLocation
|
|
19
|
-
otelTracer: otel.Tracer
|
|
20
|
-
|
|
21
|
-
executionBacklog: { query: string; bindValues?: ParamsObject }[] = []
|
|
22
|
-
executionPromise: Promise<void> | undefined = undefined
|
|
23
|
-
|
|
24
|
-
private constructor({
|
|
25
|
-
worker,
|
|
26
|
-
persistentDatabaseLocation,
|
|
27
|
-
otelTracer,
|
|
28
|
-
}: {
|
|
29
|
-
worker: Comlink.Remote<WrappedWorker>
|
|
30
|
-
persistentDatabaseLocation: WritableDatabaseLocation
|
|
31
|
-
otelTracer: otel.Tracer
|
|
32
|
-
}) {
|
|
33
|
-
super()
|
|
34
|
-
this.worker = worker
|
|
35
|
-
this.persistentDatabaseLocation = persistentDatabaseLocation
|
|
36
|
-
this.otelTracer = otelTracer
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
static load = async (
|
|
40
|
-
{ persistentDatabaseLocation }: BackendOptionsWeb,
|
|
41
|
-
{ otelTracer }: BackendOtelProps,
|
|
42
|
-
): Promise<WebWorkerBackend> => {
|
|
43
|
-
// TODO: Importing the worker like this only works with Vite;
|
|
44
|
-
// should this really be inside the LiveStore library?
|
|
45
|
-
// Doesn't work with Firefox right now during dev https://bugzilla.mozilla.org/show_bug.cgi?id=1247687
|
|
46
|
-
const worker = new Worker(new URL('./web-worker.js', import.meta.url), {
|
|
47
|
-
type: 'module',
|
|
48
|
-
})
|
|
49
|
-
const wrappedWorker = Comlink.wrap<WrappedWorker>(worker)
|
|
50
|
-
|
|
51
|
-
await wrappedWorker.initialize({ persistentDatabaseLocation })
|
|
52
|
-
|
|
53
|
-
return new WebWorkerBackend({
|
|
54
|
-
worker: wrappedWorker,
|
|
55
|
-
persistentDatabaseLocation,
|
|
56
|
-
otelTracer,
|
|
57
|
-
})
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
execute = (query: string, bindValues_?: ParamsObject) => {
|
|
61
|
-
const bindValues = prepareBindValues(bindValues_ ?? {}, query)
|
|
62
|
-
this.executionBacklog.push({ query, bindValues })
|
|
63
|
-
|
|
64
|
-
// Instead of sending the queries to the worker immediately, we wait a bit and batch them up (which reduces the number of messages sent to the worker)
|
|
65
|
-
if (this.executionPromise === undefined) {
|
|
66
|
-
this.executionPromise = new Promise((resolve) => {
|
|
67
|
-
setTimeout(() => {
|
|
68
|
-
void this.worker.executeBulk(this.executionBacklog)
|
|
69
|
-
this.executionBacklog = []
|
|
70
|
-
this.executionPromise = undefined
|
|
71
|
-
|
|
72
|
-
resolve()
|
|
73
|
-
}, 10)
|
|
74
|
-
})
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
select = async <T>(query: string, bindValues?: ParamsObject): Promise<SelectResponse<T>> => {
|
|
79
|
-
// NOTE we need to wait for the executionBacklog to be worked off, before we run the select query (as it might depend on the previous execution queries)
|
|
80
|
-
await this.executionPromise
|
|
81
|
-
|
|
82
|
-
try {
|
|
83
|
-
const response = (await this.worker.select(query, bindValues)) as SelectResponse<T>
|
|
84
|
-
return response
|
|
85
|
-
} catch (e) {
|
|
86
|
-
console.error(`Error while executing query via "select": ${query}`)
|
|
87
|
-
throw e
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
getPersistedData = async (_parentSpan?: otel.Span): Promise<Uint8Array> => {
|
|
92
|
-
// NOTE we need to wait for the executionBacklog to be worked off
|
|
93
|
-
await this.executionPromise
|
|
94
|
-
|
|
95
|
-
return this.worker.getPersistedData()
|
|
96
|
-
}
|
|
97
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react'
|
|
2
|
-
|
|
3
|
-
import { labelForKey } from '../componentKey.js'
|
|
4
|
-
import { TODO_REMOVE_trackLongRunningSpan } from '../otel.js'
|
|
5
|
-
import type { LiveStoreQuery, QueryResult } from '../store.js'
|
|
6
|
-
|
|
7
|
-
export const useGlobalQuery = <Q extends LiveStoreQuery>(query: Q): QueryResult<Q> => {
|
|
8
|
-
// We know the query has a result by the time we use it; so we can synchronously populate a default state
|
|
9
|
-
const [value, setValue] = useState<QueryResult<Q>>(query.results$.result)
|
|
10
|
-
|
|
11
|
-
// Subscribe to future updates for this query
|
|
12
|
-
useEffect(() => {
|
|
13
|
-
return query.store.otel.tracer.startActiveSpan(
|
|
14
|
-
`LiveStore:useGlobalQuery:${labelForKey(query.componentKey)}:${query.label}`,
|
|
15
|
-
{},
|
|
16
|
-
query.store.otel.queriesSpanContext,
|
|
17
|
-
(span) => {
|
|
18
|
-
TODO_REMOVE_trackLongRunningSpan(span)
|
|
19
|
-
|
|
20
|
-
const cancel = query.store.subscribe(
|
|
21
|
-
query,
|
|
22
|
-
(v) => {
|
|
23
|
-
// NOTE: we return a reference to the result object within LiveStore;
|
|
24
|
-
// this implies that app code must not mutate the results, or else
|
|
25
|
-
// there may be weird reactivity bugs.
|
|
26
|
-
return setValue(v)
|
|
27
|
-
},
|
|
28
|
-
undefined,
|
|
29
|
-
{ label: query.label },
|
|
30
|
-
)
|
|
31
|
-
return () => {
|
|
32
|
-
cancel()
|
|
33
|
-
span.end()
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
)
|
|
37
|
-
}, [query])
|
|
38
|
-
|
|
39
|
-
return value
|
|
40
|
-
}
|
|
File without changes
|