@rocicorp/zero 1.11.0-canary.1 → 1.11.0-canary.2
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/out/replicache/src/btree/read.d.ts +12 -1
- package/out/replicache/src/btree/read.d.ts.map +1 -1
- package/out/replicache/src/btree/read.js +24 -12
- package/out/replicache/src/btree/read.js.map +1 -1
- package/out/replicache/src/db/write.js.map +1 -1
- package/out/replicache/src/replicache-impl.d.ts.map +1 -1
- package/out/replicache/src/replicache-impl.js +10 -0
- package/out/replicache/src/replicache-impl.js.map +1 -1
- package/out/replicache/src/transactions.d.ts.map +1 -1
- package/out/replicache/src/transactions.js +1 -1
- package/out/replicache/src/transactions.js.map +1 -1
- package/out/zero/package.js +1 -1
- package/out/zero/package.js.map +1 -1
- package/out/zero-cache/src/config/zero-config.d.ts +2 -0
- package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
- package/out/zero-cache/src/config/zero-config.js +12 -4
- package/out/zero-cache/src/config/zero-config.js.map +1 -1
- package/out/zero-cache/src/server/replicator.d.ts.map +1 -1
- package/out/zero-cache/src/server/replicator.js +1 -1
- package/out/zero-cache/src/server/replicator.js.map +1 -1
- package/out/zero-cache/src/services/change-source/common/replica-schema.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/common/replica-schema.js +2 -39
- package/out/zero-cache/src/services/change-source/common/replica-schema.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer-http.d.ts +2 -2
- package/out/zero-cache/src/services/change-streamer/change-streamer-http.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer-http.js +2 -2
- package/out/zero-cache/src/services/change-streamer/change-streamer-http.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer.d.ts +6 -6
- package/out/zero-cache/src/services/change-streamer/change-streamer.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer.js.map +1 -1
- package/out/zero-cache/src/services/litestream/commands.d.ts.map +1 -1
- package/out/zero-cache/src/services/litestream/commands.js +3 -1
- package/out/zero-cache/src/services/litestream/commands.js.map +1 -1
- package/out/zero-cache/src/services/litestream/config-v5.yml +1 -4
- package/out/zero-cache/src/services/replicator/change-log-db.js.map +1 -1
- package/out/zero-cache/src/services/replicator/incremental-sync.d.ts.map +1 -1
- package/out/zero-cache/src/services/replicator/incremental-sync.js +22 -5
- package/out/zero-cache/src/services/replicator/incremental-sync.js.map +1 -1
- package/out/zero-cache/src/services/replicator/replicator.js.map +1 -1
- package/out/zero-cache/src/services/replicator/write-worker-client.d.ts +4 -4
- package/out/zero-cache/src/services/replicator/write-worker-client.d.ts.map +1 -1
- package/out/zero-cache/src/services/replicator/write-worker-client.js +2 -2
- package/out/zero-cache/src/services/replicator/write-worker-client.js.map +1 -1
- package/out/zero-cache/src/services/replicator/write-worker.js +10 -4
- package/out/zero-cache/src/services/replicator/write-worker.js.map +1 -1
- package/out/zero-cache/src/types/streams.d.ts +6 -6
- package/out/zero-cache/src/types/streams.d.ts.map +1 -1
- package/out/zero-cache/src/types/streams.js +6 -11
- package/out/zero-cache/src/types/streams.js.map +1 -1
- package/out/zero-client/src/client/context.d.ts +15 -0
- package/out/zero-client/src/client/context.d.ts.map +1 -1
- package/out/zero-client/src/client/context.js +44 -0
- package/out/zero-client/src/client/context.js.map +1 -1
- package/out/zero-client/src/client/inspector/lazy-inspector.js +2 -2
- package/out/zero-client/src/client/inspector/lazy-inspector.js.map +1 -1
- package/out/zero-client/src/client/ivm-branch.js.map +1 -1
- package/out/zero-client/src/client/version.js +1 -1
- package/out/zero-client/src/client/zero-rep.d.ts.map +1 -1
- package/out/zero-client/src/client/zero-rep.js +2 -1
- package/out/zero-client/src/client/zero-rep.js.map +1 -1
- package/out/zero-client/src/client/zero.d.ts.map +1 -1
- package/out/zero-client/src/client/zero.js +48 -11
- package/out/zero-client/src/client/zero.js.map +1 -1
- package/out/zero-protocol/src/down.d.ts +29 -29
- package/out/zero-protocol/src/inspect-down.d.ts +81 -81
- package/out/zero-protocol/src/poke.d.ts +6 -6
- package/out/zero-react/src/use-query.d.ts.map +1 -1
- package/out/zero-react/src/use-query.js +24 -5
- package/out/zero-react/src/use-query.js.map +1 -1
- package/out/zero-solid/src/use-query.js +4 -1
- package/out/zero-solid/src/use-query.js.map +1 -1
- package/out/zql/src/ivm/array-view.d.ts.map +1 -1
- package/out/zql/src/ivm/array-view.js +5 -3
- package/out/zql/src/ivm/array-view.js.map +1 -1
- package/out/zql/src/ivm/deferred-input.d.ts +44 -0
- package/out/zql/src/ivm/deferred-input.d.ts.map +1 -0
- package/out/zql/src/ivm/deferred-input.js +88 -0
- package/out/zql/src/ivm/deferred-input.js.map +1 -0
- package/out/zql/src/ivm/memory-source.d.ts.map +1 -1
- package/out/zql/src/ivm/memory-source.js +5 -10
- package/out/zql/src/ivm/memory-source.js.map +1 -1
- package/out/zql/src/query/query-delegate-base.d.ts +6 -0
- package/out/zql/src/query/query-delegate-base.d.ts.map +1 -1
- package/out/zql/src/query/query-delegate-base.js +73 -10
- package/out/zql/src/query/query-delegate-base.js.map +1 -1
- package/out/zql/src/query/query-delegate.d.ts +22 -0
- package/out/zql/src/query/query-delegate.d.ts.map +1 -1
- package/out/zql/src/query/query-impl.d.ts +12 -11
- package/out/zql/src/query/query-impl.d.ts.map +1 -1
- package/out/zql/src/query/query-impl.js +383 -60
- package/out/zql/src/query/query-impl.js.map +1 -1
- package/out/zql/src/query/query-transitions.d.ts +171 -0
- package/out/zql/src/query/query-transitions.d.ts.map +1 -0
- package/out/zql/src/query/query-transitions.js +207 -0
- package/out/zql/src/query/query-transitions.js.map +1 -0
- package/out/zql/src/query/runnable-query-impl.d.ts.map +1 -1
- package/out/zql/src/query/runnable-query-impl.js +21 -1
- package/out/zql/src/query/runnable-query-impl.js.map +1 -1
- package/package.json +1 -1
|
@@ -3,6 +3,7 @@ import { asQueryInternals } from "./query-internals.js";
|
|
|
3
3
|
import { hashOfAST } from "../../../zero-protocol/src/query-hash.js";
|
|
4
4
|
import { buildPipeline } from "../builder/builder.js";
|
|
5
5
|
import { ArrayView } from "../ivm/array-view.js";
|
|
6
|
+
import { DeferredInput } from "../ivm/deferred-input.js";
|
|
6
7
|
import { MemoryStorage } from "../ivm/memory-storage.js";
|
|
7
8
|
import "./ttl.js";
|
|
8
9
|
import { resolver } from "@rocicorp/resolver";
|
|
@@ -115,6 +116,16 @@ var QueryDelegateBase = class {
|
|
|
115
116
|
* Default implementation is a no-op.
|
|
116
117
|
*/
|
|
117
118
|
assertValidRunOptions(_options) {}
|
|
119
|
+
/**
|
|
120
|
+
* Default: pipelines can always be built immediately. Override (together
|
|
121
|
+
* with `onPipelinesReady`) to defer pipeline construction.
|
|
122
|
+
*/
|
|
123
|
+
get pipelinesReady() {
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
onPipelinesReady(_cb) {
|
|
127
|
+
throw new Error("onPipelinesReady called on a delegate whose pipelines are always ready");
|
|
128
|
+
}
|
|
118
129
|
};
|
|
119
130
|
async function runImpl(query, delegate, options) {
|
|
120
131
|
delegate.assertValidRunOptions(options);
|
|
@@ -159,9 +170,18 @@ function materializeImpl(query, delegate, factory = arrayViewFactory, options) {
|
|
|
159
170
|
const { ast, format, customQueryID } = qi;
|
|
160
171
|
const queryID = customQueryID ? hashNameAndArgs(customQueryID.name, customQueryID.args) : hashOfAST(qi.ast);
|
|
161
172
|
const queryCompleteResolver = resolver();
|
|
162
|
-
|
|
163
|
-
let
|
|
173
|
+
const deferPipeline = !delegate.pipelinesReady;
|
|
174
|
+
let attached = !deferPipeline;
|
|
175
|
+
let gotQueries = delegate.defaultQueryComplete;
|
|
176
|
+
let queryComplete = attached && gotQueries;
|
|
164
177
|
const updateTTL = customQueryID ? (newTTL) => delegate.updateCustomQuery(customQueryID, newTTL) : (newTTL) => delegate.updateServerQuery(ast, newTTL);
|
|
178
|
+
const maybeResolveComplete = () => {
|
|
179
|
+
if (attached && gotQueries && queryComplete !== true) {
|
|
180
|
+
delegate.addMetric("query-materialization-end-to-end", performance.now() - t0, queryID, ast);
|
|
181
|
+
queryComplete = true;
|
|
182
|
+
queryCompleteResolver.resolve(true);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
165
185
|
const gotCallback = (got, error) => {
|
|
166
186
|
if (error) {
|
|
167
187
|
queryCompleteResolver.reject(error);
|
|
@@ -169,29 +189,72 @@ function materializeImpl(query, delegate, factory = arrayViewFactory, options) {
|
|
|
169
189
|
return;
|
|
170
190
|
}
|
|
171
191
|
if (got) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
endToEndMetricRecorded = true;
|
|
175
|
-
}
|
|
176
|
-
queryComplete = true;
|
|
177
|
-
queryCompleteResolver.resolve(true);
|
|
192
|
+
gotQueries = true;
|
|
193
|
+
maybeResolveComplete();
|
|
178
194
|
}
|
|
179
195
|
};
|
|
180
196
|
let removeCommitObserver;
|
|
197
|
+
let removePendingAttach;
|
|
181
198
|
const onDestroy = () => {
|
|
199
|
+
removePendingAttach?.();
|
|
200
|
+
removePendingAttach = void 0;
|
|
182
201
|
input.destroy();
|
|
183
202
|
removeCommitObserver?.();
|
|
184
203
|
removeAddedQuery();
|
|
185
204
|
};
|
|
186
205
|
const t0 = performance.now();
|
|
187
206
|
const removeAddedQuery = customQueryID ? delegate.addCustomQuery(ast, customQueryID, ttl, gotCallback) : delegate.addServerQuery(ast, ttl, gotCallback);
|
|
188
|
-
const
|
|
207
|
+
const deferred = deferPipeline ? newDeferredInput(ast, delegate, queryID) : void 0;
|
|
208
|
+
const input = deferred ?? buildPipeline(ast, delegate, queryID);
|
|
189
209
|
const view = delegate.batchViewUpdates(() => (factory ?? arrayViewFactory)(query, input, format, onDestroy, (cb) => {
|
|
190
210
|
removeCommitObserver = delegate.onTransactionCommit(cb);
|
|
191
211
|
}, queryComplete || queryCompleteResolver.promise, updateTTL));
|
|
192
|
-
delegate.addMetric("query-materialization-client", performance.now() - t0, queryID);
|
|
212
|
+
if (!deferred) delegate.addMetric("query-materialization-client", performance.now() - t0, queryID);
|
|
213
|
+
else removePendingAttach = delegate.onPipelinesReady(() => {
|
|
214
|
+
removePendingAttach = void 0;
|
|
215
|
+
if (deferred.destroyed) return;
|
|
216
|
+
const t1 = performance.now();
|
|
217
|
+
try {
|
|
218
|
+
deferred.attach();
|
|
219
|
+
} catch (e) {
|
|
220
|
+
const error = {
|
|
221
|
+
error: "app",
|
|
222
|
+
id: queryID,
|
|
223
|
+
name: customQueryID?.name ?? "",
|
|
224
|
+
message: e instanceof Error ? e.message : String(e)
|
|
225
|
+
};
|
|
226
|
+
queryComplete = error;
|
|
227
|
+
queryCompleteResolver.reject(error);
|
|
228
|
+
throw e;
|
|
229
|
+
}
|
|
230
|
+
attached = true;
|
|
231
|
+
delegate.addMetric("query-materialization-client", performance.now() - t1, queryID);
|
|
232
|
+
maybeResolveComplete();
|
|
233
|
+
});
|
|
193
234
|
return view;
|
|
194
235
|
}
|
|
236
|
+
/**
|
|
237
|
+
* Creates the placeholder input for a query whose pipeline cannot be built yet.
|
|
238
|
+
*
|
|
239
|
+
* `Input.getSchema()` is unconditional, so the placeholder needs the schema up
|
|
240
|
+
* front. It is captured by building a pipeline and immediately destroying it:
|
|
241
|
+
* building only connects to the sources, while the indexes and rows -- the
|
|
242
|
+
* expensive part this deferral exists to postpone -- are read on the first
|
|
243
|
+
* fetch. Measured at ~5us against ~500us for a single 100 row fetch.
|
|
244
|
+
*
|
|
245
|
+
* Building here also means a query that cannot be built at all (an unknown
|
|
246
|
+
* table, `not(exists())` on the client) still throws from `materialize()`,
|
|
247
|
+
* as it did before hydration was deferred.
|
|
248
|
+
*/
|
|
249
|
+
function newDeferredInput(ast, delegate, queryID) {
|
|
250
|
+
const build = () => buildPipeline(ast, delegate, queryID);
|
|
251
|
+
const probe = build();
|
|
252
|
+
try {
|
|
253
|
+
return new DeferredInput(probe.getSchema(), build);
|
|
254
|
+
} finally {
|
|
255
|
+
probe.destroy();
|
|
256
|
+
}
|
|
257
|
+
}
|
|
195
258
|
function arrayViewFactory(_query, input, format, onDestroy, onTransactionCommit, queryComplete, updateTTL) {
|
|
196
259
|
const v = new ArrayView(input, format, queryComplete, updateTTL);
|
|
197
260
|
v.onDestroy = onDestroy;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-delegate-base.js","names":[],"sources":["../../../../../zql/src/query/query-delegate-base.ts"],"sourcesContent":["import {resolver} from '@rocicorp/resolver';\nimport type {AST} from '../../../zero-protocol/src/ast.ts';\nimport type {ErroredQuery} from '../../../zero-protocol/src/custom-queries.ts';\nimport {\n hashOfAST,\n hashOfNameAndArgs,\n} from '../../../zero-protocol/src/query-hash.ts';\nimport type {Schema} from '../../../zero-types/src/schema.ts';\nimport {buildPipeline} from '../builder/builder.ts';\nimport {ArrayView} from '../ivm/array-view.ts';\nimport type {FilterInput} from '../ivm/filter-operators.ts';\nimport {MemoryStorage} from '../ivm/memory-storage.ts';\nimport type {Input, InputBase, Storage} from '../ivm/operator.ts';\nimport type {Source, SourceInput} from '../ivm/source.ts';\nimport type {Format, ViewFactory} from '../ivm/view.ts';\nimport type {MetricMap} from './metrics-delegate.ts';\nimport type {CustomQueryID} from './named.ts';\nimport type {\n CommitListener,\n GotCallback,\n QueryDelegate,\n} from './query-delegate.ts';\nimport {asQueryInternals, type QueryInternals} from './query-internals.ts';\nimport type {\n HumanReadable,\n MaterializeOptions,\n PreloadOptions,\n Query,\n RunOptions,\n} from './query.ts';\nimport {DEFAULT_PRELOAD_TTL_MS, DEFAULT_TTL_MS, type TTL} from './ttl.ts';\nimport type {TypedView} from './typed-view.ts';\n\n/**\n * Base class that provides default implementations for common QueryDelegate methods.\n * Subclasses can override specific methods as needed.\n */\nexport abstract class QueryDelegateBase implements QueryDelegate {\n /**\n * Default implementation that just calls applyViewUpdates synchronously.\n * Override if you need custom batching behavior (e.g., SolidJS).\n */\n batchViewUpdates<T>(applyViewUpdates: () => T): T {\n return applyViewUpdates();\n }\n\n /**\n * Default implementation returns MemoryStorage.\n * Override if you need custom storage.\n */\n createStorage(): Storage {\n return new MemoryStorage();\n }\n\n /**\n * Default implementation calls materializeImpl.\n * Override if you need custom materialization behavior.\n */\n materialize<\n TTable extends keyof TSchema['tables'] & string,\n TSchema extends Schema,\n TReturn,\n >(\n query: Query<TTable, TSchema, TReturn>,\n factory?: undefined,\n options?: MaterializeOptions,\n ): TypedView<HumanReadable<TReturn>>;\n\n materialize<\n TTable extends keyof TSchema['tables'] & string,\n TSchema extends Schema,\n TReturn,\n T,\n >(\n query: Query<TTable, TSchema, TReturn>,\n factory?: ViewFactory<TTable, TSchema, TReturn, T>,\n options?: MaterializeOptions,\n ): T;\n\n /**\n * Materialize a query into a custom view using a provided factory function.\n */\n materialize<\n TTable extends keyof TSchema['tables'] & string,\n TSchema extends Schema,\n TReturn,\n T,\n >(\n query: Query<TTable, TSchema, TReturn>,\n factory?: ViewFactory<TTable, TSchema, TReturn, T>,\n options?: MaterializeOptions,\n ): T;\n\n materialize<\n TTable extends keyof TSchema['tables'] & string,\n TSchema extends Schema,\n TReturn,\n T,\n >(\n query: Query<TTable, TSchema, TReturn>,\n factory?: ViewFactory<TTable, TSchema, TReturn, T>,\n options?: MaterializeOptions,\n ): T {\n return materializeImpl(query, this, factory, options);\n }\n\n /**\n * Default implementation calls runImpl.\n * Override if you need custom query execution (e.g., TestPGQueryDelegate).\n */\n run<\n TTable extends keyof TSchema['tables'] & string,\n TSchema extends Schema,\n TReturn,\n >(\n query: Query<TTable, TSchema, TReturn>,\n options?: RunOptions,\n ): Promise<HumanReadable<TReturn>> {\n return runImpl(query, this, options);\n }\n\n /**\n * Default implementation calls preloadImpl.\n * Override if you need custom preload behavior.\n */\n preload<\n TTable extends keyof TSchema['tables'] & string,\n TSchema extends Schema,\n TReturn,\n >(\n query: Query<TTable, TSchema, TReturn>,\n options?: PreloadOptions,\n ): {\n cleanup: () => void;\n complete: Promise<void>;\n } {\n return preloadImpl(query, this, options);\n }\n\n /**\n * Default no-op implementation for decorateSourceInput.\n * Override if you need to wrap or instrument source inputs.\n */\n decorateSourceInput(input: SourceInput, _queryID: string): Input {\n return input;\n }\n\n /**\n * Default no-op implementation for decorateInput.\n * Override if you need to wrap or instrument inputs.\n */\n decorateInput(input: Input, _name: string): Input {\n return input;\n }\n\n /**\n * Default no-op implementation for decorateFilterInput.\n * Override if you need to wrap or instrument filter inputs.\n */\n decorateFilterInput(input: FilterInput, _name: string): FilterInput {\n return input;\n }\n\n /**\n * Default no-op implementation for addEdge.\n * Override if you need to track graph edges (e.g., visualization).\n */\n addEdge(_source: InputBase, _dest: InputBase): void {\n // No-op\n }\n\n /**\n * Default no-op implementation for addMetric.\n * Override if you need to collect metrics.\n */\n addMetric<K extends keyof MetricMap>(\n _metric: K,\n _value: number,\n ..._args: MetricMap[K]\n ): void {\n // No-op\n }\n\n /**\n * Default no-op implementation.\n * Override if you need to track server queries (e.g., ZeroContext, test delegates).\n */\n addServerQuery(_ast: AST, _ttl: TTL, _gotCallback?: GotCallback): () => void {\n return () => {};\n }\n\n /**\n * Default no-op implementation.\n * Override if you need to track custom queries (e.g., ZeroContext, test delegates).\n */\n addCustomQuery(\n _ast: AST,\n _customQueryID: CustomQueryID,\n _ttl: TTL,\n _gotCallback?: GotCallback,\n ): () => void {\n return () => {};\n }\n\n /**\n * Default no-op implementation.\n * Override if you need to handle query updates.\n */\n updateServerQuery(_ast: AST, _ttl: TTL): void {\n // No-op\n }\n\n /**\n * Default no-op implementation.\n * Override if you need to handle custom query updates.\n */\n updateCustomQuery(_customQueryID: CustomQueryID, _ttl: TTL): void {\n // No-op\n }\n\n /**\n * Default no-op implementation.\n * Override if you need to flush query changes.\n */\n flushQueryChanges(): void {\n // No-op\n }\n\n /**\n * Called when a transaction commits. Override to add custom behavior.\n * Default implementation returns a no-op cleanup function.\n */\n onTransactionCommit(_cb: CommitListener): () => void {\n return () => {};\n }\n\n /**\n * Validates run options. Override to add custom validation.\n * Default implementation is a no-op.\n */\n assertValidRunOptions(_options?: RunOptions): void {\n // No-op\n }\n\n abstract readonly defaultQueryComplete: boolean;\n\n // BuilderDelegate methods - must be implemented\n abstract getSource(name: string): Source | undefined;\n}\n\n// oxlint-disable-next-line require-await\nexport async function runImpl<\n TTable extends keyof TSchema['tables'] & string,\n TSchema extends Schema,\n TReturn,\n>(\n query: Query<TTable, TSchema, TReturn>,\n delegate: QueryDelegate,\n options?: RunOptions,\n): Promise<HumanReadable<TReturn>> {\n delegate.assertValidRunOptions(options);\n const v: TypedView<HumanReadable<TReturn>> = materializeImpl(\n query,\n delegate,\n undefined,\n {\n ttl: options?.ttl,\n },\n );\n if (options?.type === 'complete') {\n return new Promise(resolve => {\n v.addListener((data, type) => {\n if (type === 'complete') {\n v.destroy();\n resolve(data as HumanReadable<TReturn>);\n } else if (type === 'error') {\n v.destroy();\n resolve(Promise.reject(data));\n }\n });\n });\n }\n\n options?.type satisfies 'unknown' | undefined;\n\n const ret = v.data;\n v.destroy();\n return ret;\n}\n\nexport function preloadImpl<\n TTable extends keyof TSchema['tables'] & string,\n TSchema extends Schema,\n TReturn,\n>(\n query: Query<TTable, TSchema, TReturn>,\n delegate: QueryDelegate,\n options?: PreloadOptions,\n): {\n cleanup: () => void;\n complete: Promise<void>;\n} {\n const qi = asQueryInternals(query);\n const ttl = options?.ttl ?? DEFAULT_PRELOAD_TTL_MS;\n const {resolve, promise: complete} = resolver<void>();\n const {customQueryID, ast} = qi;\n if (customQueryID) {\n const cleanup = delegate.addCustomQuery(ast, customQueryID, ttl, got => {\n if (got) {\n resolve();\n }\n });\n return {\n cleanup,\n complete,\n };\n }\n\n const cleanup = delegate.addServerQuery(ast, ttl, got => {\n if (got) {\n resolve();\n }\n });\n return {\n cleanup,\n complete,\n };\n}\n\nexport function materializeImpl<\n TTable extends keyof TSchema['tables'] & string,\n TSchema extends Schema,\n TReturn,\n T,\n>(\n query: Query<TTable, TSchema, TReturn>,\n delegate: QueryDelegate,\n factory: ViewFactory<\n TTable,\n TSchema,\n TReturn,\n T\n // oxlint-disable-next-line no-explicit-any\n > = arrayViewFactory as any,\n options?: MaterializeOptions,\n): T {\n let ttl: TTL = options?.ttl ?? DEFAULT_TTL_MS;\n\n const qi = asQueryInternals(query);\n const {ast, format, customQueryID} = qi;\n\n const queryID = customQueryID\n ? hashOfNameAndArgs(customQueryID.name, customQueryID.args)\n : hashOfAST(qi.ast);\n const queryCompleteResolver = resolver<true>();\n let queryComplete: boolean | ErroredQuery = delegate.defaultQueryComplete;\n let endToEndMetricRecorded = false;\n const updateTTL = customQueryID\n ? (newTTL: TTL) => delegate.updateCustomQuery(customQueryID, newTTL)\n : (newTTL: TTL) => delegate.updateServerQuery(ast, newTTL);\n\n const gotCallback: GotCallback = (got, error) => {\n if (error) {\n queryCompleteResolver.reject(error);\n queryComplete = error;\n return;\n }\n\n if (got) {\n if (!endToEndMetricRecorded) {\n delegate.addMetric(\n 'query-materialization-end-to-end',\n performance.now() - t0,\n queryID,\n ast,\n );\n endToEndMetricRecorded = true;\n }\n queryComplete = true;\n queryCompleteResolver.resolve(true);\n }\n };\n\n let removeCommitObserver: (() => void) | undefined;\n const onDestroy = () => {\n input.destroy();\n removeCommitObserver?.();\n removeAddedQuery();\n };\n\n const t0 = performance.now();\n\n const removeAddedQuery = customQueryID\n ? delegate.addCustomQuery(ast, customQueryID, ttl, gotCallback)\n : delegate.addServerQuery(ast, ttl, gotCallback);\n\n const input = buildPipeline(ast, delegate, queryID);\n\n const view = delegate.batchViewUpdates(() =>\n (factory ?? arrayViewFactory)(\n query,\n input,\n format,\n onDestroy,\n cb => {\n removeCommitObserver = delegate.onTransactionCommit(cb);\n },\n queryComplete || queryCompleteResolver.promise,\n updateTTL,\n ),\n );\n\n delegate.addMetric(\n 'query-materialization-client',\n performance.now() - t0,\n queryID,\n );\n\n return view as T;\n}\n\nfunction arrayViewFactory<\n TTable extends string,\n TSchema extends Schema,\n TReturn,\n>(\n _query: QueryInternals<TTable, TSchema, TReturn>,\n input: Input,\n format: Format,\n onDestroy: () => void,\n onTransactionCommit: (cb: () => void) => void,\n queryComplete: true | ErroredQuery | Promise<true>,\n updateTTL: (ttl: TTL) => void,\n): TypedView<HumanReadable<TReturn>> {\n const v = new ArrayView<HumanReadable<TReturn>>(\n input,\n format,\n queryComplete,\n updateTTL,\n );\n v.onDestroy = onDestroy;\n onTransactionCommit(() => v.flush());\n return v;\n}\n"],"mappings":";;;;;;;;;;;;;AAqCA,IAAsB,oBAAtB,MAAiE;;;;;CAK/D,iBAAoB,kBAA8B;EAChD,OAAO,iBAAiB;CAC1B;;;;;CAMA,gBAAyB;EACvB,OAAO,IAAI,cAAc;CAC3B;CAyCA,YAME,OACA,SACA,SACG;EACH,OAAO,gBAAgB,OAAO,MAAM,SAAS,OAAO;CACtD;;;;;CAMA,IAKE,OACA,SACiC;EACjC,OAAO,QAAQ,OAAO,MAAM,OAAO;CACrC;;;;;CAMA,QAKE,OACA,SAIA;EACA,OAAO,YAAY,OAAO,MAAM,OAAO;CACzC;;;;;CAMA,oBAAoB,OAAoB,UAAyB;EAC/D,OAAO;CACT;;;;;CAMA,cAAc,OAAc,OAAsB;EAChD,OAAO;CACT;;;;;CAMA,oBAAoB,OAAoB,OAA4B;EAClE,OAAO;CACT;;;;;CAMA,QAAQ,SAAoB,OAAwB,CAEpD;;;;;CAMA,UACE,SACA,QACA,GAAG,OACG,CAER;;;;;CAMA,eAAe,MAAW,MAAW,cAAwC;EAC3E,aAAa,CAAC;CAChB;;;;;CAMA,eACE,MACA,gBACA,MACA,cACY;EACZ,aAAa,CAAC;CAChB;;;;;CAMA,kBAAkB,MAAW,MAAiB,CAE9C;;;;;CAMA,kBAAkB,gBAA+B,MAAiB,CAElE;;;;;CAMA,oBAA0B,CAE1B;;;;;CAMA,oBAAoB,KAAiC;EACnD,aAAa,CAAC;CAChB;;;;;CAMA,sBAAsB,UAA6B,CAEnD;AAMF;AAGA,eAAsB,QAKpB,OACA,UACA,SACiC;CACjC,SAAS,sBAAsB,OAAO;CACtC,MAAM,IAAuC,gBAC3C,OACA,UACA,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OAAO,KAAK;GAClC,gBAAgB;GAChB;EACF;EAEA,IAAI,KAAK;GACP,IAAI,CAAC,wBAAwB;IAC3B,SAAS,UACP,oCACA,YAAY,IAAI,IAAI,IACpB,SACA,GACF;IACA,yBAAyB;GAC3B;GACA,gBAAgB;GAChB,sBAAsB,QAAQ,IAAI;EACpC;CACF;CAEA,IAAI;CACJ,MAAM,kBAAkB;EACtB,MAAM,QAAQ;EACd,uBAAuB;EACvB,iBAAiB;CACnB;CAEA,MAAM,KAAK,YAAY,IAAI;CAE3B,MAAM,mBAAmB,gBACrB,SAAS,eAAe,KAAK,eAAe,KAAK,WAAW,IAC5D,SAAS,eAAe,KAAK,KAAK,WAAW;CAEjD,MAAM,QAAQ,cAAc,KAAK,UAAU,OAAO;CAElD,MAAM,OAAO,SAAS,wBACnB,WAAW,kBACV,OACA,OACA,QACA,YACA,OAAM;EACJ,uBAAuB,SAAS,oBAAoB,EAAE;CACxD,GACA,iBAAiB,sBAAsB,SACvC,SACF,CACF;CAEA,SAAS,UACP,gCACA,YAAY,IAAI,IAAI,IACpB,OACF;CAEA,OAAO;AACT;AAEA,SAAS,iBAKP,QACA,OACA,QACA,WACA,qBACA,eACA,WACmC;CACnC,MAAM,IAAI,IAAI,UACZ,OACA,QACA,eACA,SACF;CACA,EAAE,YAAY;CACd,0BAA0B,EAAE,MAAM,CAAC;CACnC,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"query-delegate-base.js","names":[],"sources":["../../../../../zql/src/query/query-delegate-base.ts"],"sourcesContent":["import {resolver} from '@rocicorp/resolver';\nimport type {AST} from '../../../zero-protocol/src/ast.ts';\nimport type {ErroredQuery} from '../../../zero-protocol/src/custom-queries.ts';\nimport {\n hashOfAST,\n hashOfNameAndArgs,\n} from '../../../zero-protocol/src/query-hash.ts';\nimport type {Schema} from '../../../zero-types/src/schema.ts';\nimport {buildPipeline} from '../builder/builder.ts';\nimport {ArrayView} from '../ivm/array-view.ts';\nimport {DeferredInput} from '../ivm/deferred-input.ts';\nimport type {FilterInput} from '../ivm/filter-operators.ts';\nimport {MemoryStorage} from '../ivm/memory-storage.ts';\nimport type {Input, InputBase, Storage} from '../ivm/operator.ts';\nimport type {Source, SourceInput} from '../ivm/source.ts';\nimport type {Format, ViewFactory} from '../ivm/view.ts';\nimport type {MetricMap} from './metrics-delegate.ts';\nimport type {CustomQueryID} from './named.ts';\nimport type {\n CommitListener,\n GotCallback,\n QueryDelegate,\n} from './query-delegate.ts';\nimport {asQueryInternals, type QueryInternals} from './query-internals.ts';\nimport type {\n HumanReadable,\n MaterializeOptions,\n PreloadOptions,\n Query,\n RunOptions,\n} from './query.ts';\nimport {DEFAULT_PRELOAD_TTL_MS, DEFAULT_TTL_MS, type TTL} from './ttl.ts';\nimport type {TypedView} from './typed-view.ts';\n\n/**\n * Base class that provides default implementations for common QueryDelegate methods.\n * Subclasses can override specific methods as needed.\n */\nexport abstract class QueryDelegateBase implements QueryDelegate {\n /**\n * Default implementation that just calls applyViewUpdates synchronously.\n * Override if you need custom batching behavior (e.g., SolidJS).\n */\n batchViewUpdates<T>(applyViewUpdates: () => T): T {\n return applyViewUpdates();\n }\n\n /**\n * Default implementation returns MemoryStorage.\n * Override if you need custom storage.\n */\n createStorage(): Storage {\n return new MemoryStorage();\n }\n\n /**\n * Default implementation calls materializeImpl.\n * Override if you need custom materialization behavior.\n */\n materialize<\n TTable extends keyof TSchema['tables'] & string,\n TSchema extends Schema,\n TReturn,\n >(\n query: Query<TTable, TSchema, TReturn>,\n factory?: undefined,\n options?: MaterializeOptions,\n ): TypedView<HumanReadable<TReturn>>;\n\n materialize<\n TTable extends keyof TSchema['tables'] & string,\n TSchema extends Schema,\n TReturn,\n T,\n >(\n query: Query<TTable, TSchema, TReturn>,\n factory?: ViewFactory<TTable, TSchema, TReturn, T>,\n options?: MaterializeOptions,\n ): T;\n\n /**\n * Materialize a query into a custom view using a provided factory function.\n */\n materialize<\n TTable extends keyof TSchema['tables'] & string,\n TSchema extends Schema,\n TReturn,\n T,\n >(\n query: Query<TTable, TSchema, TReturn>,\n factory?: ViewFactory<TTable, TSchema, TReturn, T>,\n options?: MaterializeOptions,\n ): T;\n\n materialize<\n TTable extends keyof TSchema['tables'] & string,\n TSchema extends Schema,\n TReturn,\n T,\n >(\n query: Query<TTable, TSchema, TReturn>,\n factory?: ViewFactory<TTable, TSchema, TReturn, T>,\n options?: MaterializeOptions,\n ): T {\n return materializeImpl(query, this, factory, options);\n }\n\n /**\n * Default implementation calls runImpl.\n * Override if you need custom query execution (e.g., TestPGQueryDelegate).\n */\n run<\n TTable extends keyof TSchema['tables'] & string,\n TSchema extends Schema,\n TReturn,\n >(\n query: Query<TTable, TSchema, TReturn>,\n options?: RunOptions,\n ): Promise<HumanReadable<TReturn>> {\n return runImpl(query, this, options);\n }\n\n /**\n * Default implementation calls preloadImpl.\n * Override if you need custom preload behavior.\n */\n preload<\n TTable extends keyof TSchema['tables'] & string,\n TSchema extends Schema,\n TReturn,\n >(\n query: Query<TTable, TSchema, TReturn>,\n options?: PreloadOptions,\n ): {\n cleanup: () => void;\n complete: Promise<void>;\n } {\n return preloadImpl(query, this, options);\n }\n\n /**\n * Default no-op implementation for decorateSourceInput.\n * Override if you need to wrap or instrument source inputs.\n */\n decorateSourceInput(input: SourceInput, _queryID: string): Input {\n return input;\n }\n\n /**\n * Default no-op implementation for decorateInput.\n * Override if you need to wrap or instrument inputs.\n */\n decorateInput(input: Input, _name: string): Input {\n return input;\n }\n\n /**\n * Default no-op implementation for decorateFilterInput.\n * Override if you need to wrap or instrument filter inputs.\n */\n decorateFilterInput(input: FilterInput, _name: string): FilterInput {\n return input;\n }\n\n /**\n * Default no-op implementation for addEdge.\n * Override if you need to track graph edges (e.g., visualization).\n */\n addEdge(_source: InputBase, _dest: InputBase): void {\n // No-op\n }\n\n /**\n * Default no-op implementation for addMetric.\n * Override if you need to collect metrics.\n */\n addMetric<K extends keyof MetricMap>(\n _metric: K,\n _value: number,\n ..._args: MetricMap[K]\n ): void {\n // No-op\n }\n\n /**\n * Default no-op implementation.\n * Override if you need to track server queries (e.g., ZeroContext, test delegates).\n */\n addServerQuery(_ast: AST, _ttl: TTL, _gotCallback?: GotCallback): () => void {\n return () => {};\n }\n\n /**\n * Default no-op implementation.\n * Override if you need to track custom queries (e.g., ZeroContext, test delegates).\n */\n addCustomQuery(\n _ast: AST,\n _customQueryID: CustomQueryID,\n _ttl: TTL,\n _gotCallback?: GotCallback,\n ): () => void {\n return () => {};\n }\n\n /**\n * Default no-op implementation.\n * Override if you need to handle query updates.\n */\n updateServerQuery(_ast: AST, _ttl: TTL): void {\n // No-op\n }\n\n /**\n * Default no-op implementation.\n * Override if you need to handle custom query updates.\n */\n updateCustomQuery(_customQueryID: CustomQueryID, _ttl: TTL): void {\n // No-op\n }\n\n /**\n * Default no-op implementation.\n * Override if you need to flush query changes.\n */\n flushQueryChanges(): void {\n // No-op\n }\n\n /**\n * Called when a transaction commits. Override to add custom behavior.\n * Default implementation returns a no-op cleanup function.\n */\n onTransactionCommit(_cb: CommitListener): () => void {\n return () => {};\n }\n\n /**\n * Validates run options. Override to add custom validation.\n * Default implementation is a no-op.\n */\n assertValidRunOptions(_options?: RunOptions): void {\n // No-op\n }\n\n abstract readonly defaultQueryComplete: boolean;\n\n /**\n * Default: pipelines can always be built immediately. Override (together\n * with `onPipelinesReady`) to defer pipeline construction.\n */\n get pipelinesReady(): boolean {\n return true;\n }\n\n onPipelinesReady(_cb: () => void): () => void {\n throw new Error(\n 'onPipelinesReady called on a delegate whose pipelines are always ready',\n );\n }\n\n // BuilderDelegate methods - must be implemented\n abstract getSource(name: string): Source | undefined;\n}\n\n// oxlint-disable-next-line require-await\nexport async function runImpl<\n TTable extends keyof TSchema['tables'] & string,\n TSchema extends Schema,\n TReturn,\n>(\n query: Query<TTable, TSchema, TReturn>,\n delegate: QueryDelegate,\n options?: RunOptions,\n): Promise<HumanReadable<TReturn>> {\n delegate.assertValidRunOptions(options);\n const v: TypedView<HumanReadable<TReturn>> = materializeImpl(\n query,\n delegate,\n undefined,\n {\n ttl: options?.ttl,\n },\n );\n if (options?.type === 'complete') {\n return new Promise(resolve => {\n v.addListener((data, type) => {\n if (type === 'complete') {\n v.destroy();\n resolve(data as HumanReadable<TReturn>);\n } else if (type === 'error') {\n v.destroy();\n resolve(Promise.reject(data));\n }\n });\n });\n }\n\n options?.type satisfies 'unknown' | undefined;\n\n const ret = v.data;\n v.destroy();\n return ret;\n}\n\nexport function preloadImpl<\n TTable extends keyof TSchema['tables'] & string,\n TSchema extends Schema,\n TReturn,\n>(\n query: Query<TTable, TSchema, TReturn>,\n delegate: QueryDelegate,\n options?: PreloadOptions,\n): {\n cleanup: () => void;\n complete: Promise<void>;\n} {\n const qi = asQueryInternals(query);\n const ttl = options?.ttl ?? DEFAULT_PRELOAD_TTL_MS;\n const {resolve, promise: complete} = resolver<void>();\n const {customQueryID, ast} = qi;\n if (customQueryID) {\n const cleanup = delegate.addCustomQuery(ast, customQueryID, ttl, got => {\n if (got) {\n resolve();\n }\n });\n return {\n cleanup,\n complete,\n };\n }\n\n const cleanup = delegate.addServerQuery(ast, ttl, got => {\n if (got) {\n resolve();\n }\n });\n return {\n cleanup,\n complete,\n };\n}\n\nexport function materializeImpl<\n TTable extends keyof TSchema['tables'] & string,\n TSchema extends Schema,\n TReturn,\n T,\n>(\n query: Query<TTable, TSchema, TReturn>,\n delegate: QueryDelegate,\n factory: ViewFactory<\n TTable,\n TSchema,\n TReturn,\n T\n // oxlint-disable-next-line no-explicit-any\n > = arrayViewFactory as any,\n options?: MaterializeOptions,\n): T {\n let ttl: TTL = options?.ttl ?? DEFAULT_TTL_MS;\n\n const qi = asQueryInternals(query);\n const {ast, format, customQueryID} = qi;\n\n const queryID = customQueryID\n ? hashOfNameAndArgs(customQueryID.name, customQueryID.args)\n : hashOfAST(qi.ast);\n const queryCompleteResolver = resolver<true>();\n // When the delegate cannot build pipelines yet, the view starts over an\n // empty DeferredInput and is hydrated later. A view must not report\n // `complete` until it has actually been hydrated, so completion is gated on\n // both the server's \"got\" and the pipeline being attached.\n const deferPipeline = !delegate.pipelinesReady;\n let attached = !deferPipeline;\n let gotQueries = delegate.defaultQueryComplete;\n let queryComplete: boolean | ErroredQuery = attached && gotQueries;\n const updateTTL = customQueryID\n ? (newTTL: TTL) => delegate.updateCustomQuery(customQueryID, newTTL)\n : (newTTL: TTL) => delegate.updateServerQuery(ast, newTTL);\n\n // Completion, and the end-to-end metric, require both the server's \"got\"\n // and the pipeline being attached: until then the view is still empty.\n const maybeResolveComplete = () => {\n if (attached && gotQueries && queryComplete !== true) {\n delegate.addMetric(\n 'query-materialization-end-to-end',\n performance.now() - t0,\n queryID,\n ast,\n );\n queryComplete = true;\n queryCompleteResolver.resolve(true);\n }\n };\n\n const gotCallback: GotCallback = (got, error) => {\n if (error) {\n queryCompleteResolver.reject(error);\n queryComplete = error;\n return;\n }\n\n if (got) {\n gotQueries = true;\n maybeResolveComplete();\n }\n };\n\n let removeCommitObserver: (() => void) | undefined;\n let removePendingAttach: (() => void) | undefined;\n const onDestroy = () => {\n removePendingAttach?.();\n removePendingAttach = undefined;\n input.destroy();\n removeCommitObserver?.();\n removeAddedQuery();\n };\n\n const t0 = performance.now();\n\n const removeAddedQuery = customQueryID\n ? delegate.addCustomQuery(ast, customQueryID, ttl, gotCallback)\n : delegate.addServerQuery(ast, ttl, gotCallback);\n\n const deferred = deferPipeline\n ? newDeferredInput(ast, delegate, queryID)\n : undefined;\n // No type annotation here: annotating this as `Input` widens it enough that\n // the view type loses the pipeline's concrete schema, and `Zero.run` then\n // stops rejecting a query built from a schema with legacy queries enabled\n // (custom.test.ts covers that rejection).\n const input = deferred ?? buildPipeline(ast, delegate, queryID);\n\n const view = delegate.batchViewUpdates(() =>\n (factory ?? arrayViewFactory)(\n query,\n input,\n format,\n onDestroy,\n cb => {\n removeCommitObserver = delegate.onTransactionCommit(cb);\n },\n queryComplete || queryCompleteResolver.promise,\n updateTTL,\n ),\n );\n\n if (!deferred) {\n delegate.addMetric(\n 'query-materialization-client',\n performance.now() - t0,\n queryID,\n );\n } else {\n // Registered after the factory ran so a throwing factory leaves nothing\n // behind.\n removePendingAttach = delegate.onPipelinesReady(() => {\n removePendingAttach = undefined;\n if (deferred.destroyed) {\n return;\n }\n const t1 = performance.now();\n try {\n deferred.attach();\n } catch (e) {\n // Surface the failure on this view and let the delegate decide how\n // to log it. Other pending pipelines are unaffected.\n const error: ErroredQuery = {\n error: 'app',\n id: queryID,\n name: customQueryID?.name ?? '',\n message: e instanceof Error ? e.message : String(e),\n };\n queryComplete = error;\n queryCompleteResolver.reject(error);\n throw e;\n }\n attached = true;\n delegate.addMetric(\n 'query-materialization-client',\n performance.now() - t1,\n queryID,\n );\n maybeResolveComplete();\n });\n }\n\n return view as T;\n}\n\n/**\n * Creates the placeholder input for a query whose pipeline cannot be built yet.\n *\n * `Input.getSchema()` is unconditional, so the placeholder needs the schema up\n * front. It is captured by building a pipeline and immediately destroying it:\n * building only connects to the sources, while the indexes and rows -- the\n * expensive part this deferral exists to postpone -- are read on the first\n * fetch. Measured at ~5us against ~500us for a single 100 row fetch.\n *\n * Building here also means a query that cannot be built at all (an unknown\n * table, `not(exists())` on the client) still throws from `materialize()`,\n * as it did before hydration was deferred.\n */\nfunction newDeferredInput(\n ast: AST,\n delegate: QueryDelegate,\n queryID: string,\n): DeferredInput {\n const build = () => buildPipeline(ast, delegate, queryID);\n const probe = build();\n try {\n return new DeferredInput(probe.getSchema(), build);\n } finally {\n probe.destroy();\n }\n}\n\nfunction arrayViewFactory<\n TTable extends string,\n TSchema extends Schema,\n TReturn,\n>(\n _query: QueryInternals<TTable, TSchema, TReturn>,\n input: Input,\n format: Format,\n onDestroy: () => void,\n onTransactionCommit: (cb: () => void) => void,\n queryComplete: true | ErroredQuery | Promise<true>,\n updateTTL: (ttl: TTL) => void,\n): TypedView<HumanReadable<TReturn>> {\n const v = new ArrayView<HumanReadable<TReturn>>(\n input,\n format,\n queryComplete,\n updateTTL,\n );\n v.onDestroy = onDestro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OACF;EACA,qBAAqB;CACvB,CAAC;CAGH,OAAO;AACT;;;;;;;;;;;;;;AAeA,SAAS,iBACP,KACA,UACA,SACe;CACf,MAAM,cAAc,cAAc,KAAK,UAAU,OAAO;CACxD,MAAM,QAAQ,MAAM;CACpB,IAAI;EACF,OAAO,IAAI,cAAc,MAAM,UAAU,GAAG,KAAK;CACnD,UAAU;EACR,MAAM,QAAQ;CAChB;AACF;AAEA,SAAS,iBAKP,QACA,OACA,QACA,WACA,qBACA,eACA,WACmC;CACnC,MAAM,IAAI,IAAI,UACZ,OACA,QACA,eACA,SACF;CACA,EAAE,YAAY;CACd,0BAA0B,EAAE,MAAM,CAAC;CACnC,OAAO;AACT"}
|
|
@@ -44,6 +44,28 @@ export interface QueryDelegate extends BuilderDelegate, MetricsDelegate {
|
|
|
44
44
|
* data is always available.
|
|
45
45
|
*/
|
|
46
46
|
readonly defaultQueryComplete: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Whether query pipelines can be built against the sources right now.
|
|
49
|
+
*
|
|
50
|
+
* When `false`, `materialize` registers the query with the server as usual
|
|
51
|
+
* but returns a view over an empty placeholder input. The pipeline is built
|
|
52
|
+
* and the view hydrated when the delegate invokes the callbacks registered
|
|
53
|
+
* with {@link onPipelinesReady}. Zero uses this during cold boot so the
|
|
54
|
+
* replica is loaded into the IVM sources once, instead of being pushed row
|
|
55
|
+
* by row through every already-materialized pipeline.
|
|
56
|
+
*
|
|
57
|
+
*/
|
|
58
|
+
readonly pipelinesReady: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Register a callback to build a deferred pipeline once
|
|
61
|
+
* {@link pipelinesReady} becomes `true`. Callbacks are invoked in
|
|
62
|
+
* registration order inside `batchViewUpdates`, and the delegate notifies
|
|
63
|
+
* its commit listeners after the batch so views flush.
|
|
64
|
+
*
|
|
65
|
+
* Returns a function that unregisters the callback (used when the view is
|
|
66
|
+
* destroyed before the pipeline is built).
|
|
67
|
+
*/
|
|
68
|
+
onPipelinesReady(cb: () => void): () => void;
|
|
47
69
|
/** Using the default view factory creates a TypedView */
|
|
48
70
|
materialize<TTable extends keyof TSchema['tables'] & string, TSchema extends Schema, TReturn>(query: Query<TTable, TSchema, TReturn>, factory?: undefined, options?: MaterializeOptions): TypedView<HumanReadable<TReturn>>;
|
|
49
71
|
materialize<TTable extends keyof TSchema['tables'] & string, TSchema extends Schema, TReturn, T>(query: Query<TTable, TSchema, TReturn>, factory?: ViewFactory<TTable, TSchema, TReturn, T>, options?: MaterializeOptions): T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-delegate.d.ts","sourceRoot":"","sources":["../../../../../zql/src/query/query-delegate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,mCAAmC,CAAC;AAC3D,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,8CAA8C,CAAC;AAC/E,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,mCAAmC,CAAC;AAC9D,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAC,MAAM,EAAE,WAAW,EAAC,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EACV,aAAa,EACb,kBAAkB,EAClB,cAAc,EACd,KAAK,EACL,UAAU,EACX,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,UAAU,CAAC;AAClC,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAE/C,MAAM,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC;AACxC,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,YAAY,KAAK,IAAI,CAAC;AAEvE,MAAM,WAAW,gBAAgB;I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AE,OAAO,EAAE,OAAO,CAAC,EACtC,OAAO,CAAC,EAAE,cAAc,GACvB;QACD,OAAO,EAAE,MAAM,IAAI,CAAC;QACpB,QAAQ,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;KACzB,CAAC;CACH"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { type AST, type NormalizedAST, type System } from '../../../zero-protocol/src/ast.ts';
|
|
1
|
+
import { type ReadonlyJSONValue } from '../../../shared/src/json.ts';
|
|
2
|
+
import { type AST, type NormalizedAST, type Parameter, type SimpleOperator, type System } from '../../../zero-protocol/src/ast.ts';
|
|
3
3
|
import type { Schema } from '../../../zero-types/src/schema.ts';
|
|
4
4
|
import type { Format, ViewFactory } from '../ivm/view.ts';
|
|
5
5
|
import { type ExpressionFactory, ExpressionBuilder } from './expression.ts';
|
|
6
6
|
import type { CustomQueryID } from './named.ts';
|
|
7
7
|
import { type QueryInternals, queryInternalsTag } from './query-internals.ts';
|
|
8
|
-
import type { AnyQuery, ExistsOptions, HumanReadable, PreloadOptions, PullRow, Query, RunOptions } from './query.ts';
|
|
8
|
+
import type { AnyQuery, ExistsOptions, GetFilterType, HumanReadable, PreloadOptions, PullRow, Query, RunOptions } from './query.ts';
|
|
9
9
|
import type { TTL } from './ttl.ts';
|
|
10
10
|
import type { TypedView } from './typed-view.ts';
|
|
11
|
+
type GetFilterTypeAny = GetFilterType<any, any, any>;
|
|
11
12
|
type NewQueryFunction<TSchema extends Schema> = <TTable extends keyof TSchema['tables'] & string, TReturn>(this: unknown, tableName: TTable, ast: NormalizedAST, format: Format, customQueryID: CustomQueryID | undefined, currentJunction: string | undefined) => QueryImpl<TTable, TSchema, TReturn>;
|
|
12
13
|
export declare function newQuery<TTable extends keyof TSchema['tables'] & string, TSchema extends Schema>(schema: TSchema, table: TTable): Query<TTable, TSchema>;
|
|
13
14
|
export declare function newQueryImpl<TTable extends keyof TSchema['tables'] & string, TSchema extends Schema, TReturn = PullRow<TTable, TSchema>>(schema: TSchema, tableName: TTable, ast: AST, format: Format, system: System): QueryImpl<TTable, TSchema, TReturn>;
|
|
@@ -35,15 +36,15 @@ export declare class QueryImpl<TTable extends keyof TSchema['tables'] & string,
|
|
|
35
36
|
materialize<T>(factory: ViewFactory<TTable, TSchema, TReturn, T>, ttl?: TTL): T;
|
|
36
37
|
nameAndArgs(name: string, args: ReadonlyArray<ReadonlyJSONValue>): Query<TTable, TSchema, TReturn>;
|
|
37
38
|
hash(): string;
|
|
38
|
-
one
|
|
39
|
-
whereExists
|
|
40
|
-
related
|
|
41
|
-
where
|
|
42
|
-
start
|
|
39
|
+
one(): Query<TTable, TSchema, TReturn | undefined>;
|
|
40
|
+
whereExists(relationship: string, cbOrOptions?: ((q: AnyQuery) => AnyQuery) | ExistsOptions, options?: ExistsOptions): Query<TTable, TSchema, TReturn>;
|
|
41
|
+
related(relationship: string, cb?: (q: AnyQuery) => AnyQuery): Query<TTable, TSchema, any>;
|
|
42
|
+
where(fieldOrExpressionFactory: string | ExpressionFactory<TTable, TSchema>, opOrValue?: SimpleOperator | GetFilterTypeAny | Parameter, value?: GetFilterTypeAny | Parameter): Query<TTable, TSchema, TReturn, any>;
|
|
43
|
+
start(row: Partial<Record<string, ReadonlyJSONValue | undefined>>, opts?: {
|
|
43
44
|
inclusive: boolean;
|
|
44
|
-
})
|
|
45
|
-
limit
|
|
46
|
-
orderBy
|
|
45
|
+
}): Query<TTable, TSchema, TReturn>;
|
|
46
|
+
limit(limit: number): Query<TTable, TSchema, TReturn>;
|
|
47
|
+
orderBy<TSelector extends keyof TSchema['tables'][TTable]['columns']>(field: TSelector, direction: 'asc' | 'desc'): Query<TTable, TSchema, TReturn>;
|
|
47
48
|
get ast(): NormalizedAST;
|
|
48
49
|
expressionBuilder(): ExpressionBuilder<TTable, TSchema>;
|
|
49
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-impl.d.ts","sourceRoot":"","sources":["../../../../../zql/src/query/query-impl.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"query-impl.d.ts","sourceRoot":"","sources":["../../../../../zql/src/query/query-impl.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,iBAAiB,EACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,KAAK,GAAG,EAGR,KAAK,aAAa,EAClB,KAAK,SAAS,EAGd,KAAK,cAAc,EACnB,KAAK,MAAM,EAOZ,MAAM,mCAAmC,CAAC;AAE3C,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,mCAAmC,CAAC;AAG9D,OAAO,KAAK,EAAC,MAAM,EAAE,WAAW,EAAC,MAAM,gBAAgB,CAAC;AACxD,OAAO,EACL,KAAK,iBAAiB,EACtB,iBAAiB,EAIlB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAC,KAAK,cAAc,EAAE,iBAAiB,EAAC,MAAM,sBAAsB,CAAC;AAO5E,OAAO,KAAK,EACV,QAAQ,EACR,aAAa,EACb,aAAa,EACb,aAAa,EACb,cAAc,EACd,OAAO,EACP,KAAK,EACL,UAAU,EACX,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,UAAU,CAAC;AAClC,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAE/C,KAAK,gBAAgB,GAAG,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAErD,KAAK,gBAAgB,CAAC,OAAO,SAAS,MAAM,IAAI,CAC9C,MAAM,SAAS,MAAM,OAAO,CAAC,QAAQ,CAAC,GAAG,MAAM,EAC/C,OAAO,EAEP,IAAI,EAAE,OAAO,EACb,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,aAAa,EAClB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,aAAa,GAAG,SAAS,EACxC,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