@rocicorp/zero 0.25.0-canary.11 → 0.25.0-canary.13
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/zero/package.json.js +1 -1
- package/out/zero/src/pg.js +4 -2
- package/out/zero/src/server.js +4 -2
- package/out/zero-cache/src/server/otel-diag-logger.js +1 -0
- package/out/zero-cache/src/server/otel-diag-logger.js.map +1 -1
- package/out/zero-client/src/client/bindings.d.ts +2 -3
- package/out/zero-client/src/client/bindings.d.ts.map +1 -1
- package/out/zero-client/src/client/bindings.js.map +1 -1
- package/out/zero-client/src/client/connection-manager.d.ts +3 -3
- package/out/zero-client/src/client/connection-manager.d.ts.map +1 -1
- package/out/zero-client/src/client/connection-manager.js.map +1 -1
- package/out/zero-client/src/client/connection.d.ts.map +1 -1
- package/out/zero-client/src/client/connection.js +8 -1
- package/out/zero-client/src/client/connection.js.map +1 -1
- package/out/zero-client/src/client/custom.d.ts.map +1 -1
- package/out/zero-client/src/client/custom.js +4 -3
- package/out/zero-client/src/client/custom.js.map +1 -1
- package/out/zero-client/src/client/error.d.ts +6 -1
- package/out/zero-client/src/client/error.d.ts.map +1 -1
- package/out/zero-client/src/client/error.js +2 -2
- package/out/zero-client/src/client/error.js.map +1 -1
- package/out/zero-client/src/client/make-mutate-property.d.ts +6 -9
- package/out/zero-client/src/client/make-mutate-property.d.ts.map +1 -1
- package/out/zero-client/src/client/make-mutate-property.js +3 -8
- package/out/zero-client/src/client/make-mutate-property.js.map +1 -1
- package/out/zero-client/src/client/make-replicache-mutators.js.map +1 -1
- package/out/zero-client/src/client/mutator-proxy.d.ts +3 -2
- package/out/zero-client/src/client/mutator-proxy.d.ts.map +1 -1
- package/out/zero-client/src/client/mutator-proxy.js +15 -3
- package/out/zero-client/src/client/mutator-proxy.js.map +1 -1
- package/out/zero-client/src/client/options.d.ts +3 -3
- package/out/zero-client/src/client/options.d.ts.map +1 -1
- package/out/zero-client/src/client/options.js.map +1 -1
- package/out/zero-client/src/client/version.js +1 -1
- package/out/zero-client/src/client/zero.d.ts +1 -2
- package/out/zero-client/src/client/zero.d.ts.map +1 -1
- package/out/zero-client/src/client/zero.js +8 -8
- package/out/zero-client/src/client/zero.js.map +1 -1
- package/out/zero-client/src/mod.d.ts +5 -7
- package/out/zero-client/src/mod.d.ts.map +1 -1
- package/out/zero-react/src/components/inspector.d.ts +1 -2
- package/out/zero-react/src/components/inspector.d.ts.map +1 -1
- package/out/zero-react/src/components/inspector.js.map +1 -1
- package/out/zero-react/src/components/zero-inspector.d.ts +1 -2
- package/out/zero-react/src/components/zero-inspector.d.ts.map +1 -1
- package/out/zero-react/src/components/zero-inspector.js.map +1 -1
- package/out/zero-react/src/use-query.d.ts +1 -2
- package/out/zero-react/src/use-query.d.ts.map +1 -1
- package/out/zero-react/src/use-query.js.map +1 -1
- package/out/zero-react/src/zero-provider.d.ts +4 -5
- package/out/zero-react/src/zero-provider.d.ts.map +1 -1
- package/out/zero-react/src/zero-provider.js.map +1 -1
- package/out/zero-schema/src/permissions.d.ts +3 -0
- package/out/zero-schema/src/permissions.d.ts.map +1 -1
- package/out/zero-schema/src/permissions.js.map +1 -1
- package/out/zero-server/src/mod.d.ts +1 -1
- package/out/zero-server/src/mod.d.ts.map +1 -1
- package/out/zero-server/src/process-mutations.d.ts +10 -6
- package/out/zero-server/src/process-mutations.d.ts.map +1 -1
- package/out/zero-server/src/process-mutations.js +9 -18
- package/out/zero-server/src/process-mutations.js.map +1 -1
- package/out/zero-server/src/push-processor.d.ts.map +1 -1
- package/out/zero-server/src/push-processor.js +10 -8
- package/out/zero-server/src/push-processor.js.map +1 -1
- package/out/zero-server/src/queries/process-queries.d.ts +14 -2
- package/out/zero-server/src/queries/process-queries.d.ts.map +1 -1
- package/out/zero-server/src/queries/process-queries.js +18 -15
- package/out/zero-server/src/queries/process-queries.js.map +1 -1
- package/out/zero-solid/src/use-zero.d.ts +4 -5
- package/out/zero-solid/src/use-zero.d.ts.map +1 -1
- package/out/zero-solid/src/use-zero.js.map +1 -1
- package/out/zero-types/src/default-types.d.ts +2 -2
- package/out/zero-types/src/default-types.d.ts.map +1 -1
- package/out/zql/src/builder/builder.d.ts.map +1 -1
- package/out/zql/src/builder/builder.js +0 -1
- package/out/zql/src/builder/builder.js.map +1 -1
- package/out/zql/src/ivm/data.js +0 -11
- package/out/zql/src/ivm/data.js.map +1 -1
- package/out/zql/src/ivm/exists.d.ts +2 -2
- package/out/zql/src/ivm/exists.d.ts.map +1 -1
- package/out/zql/src/ivm/exists.js +34 -20
- package/out/zql/src/ivm/exists.js.map +1 -1
- package/out/zql/src/ivm/fan-in.d.ts +1 -1
- package/out/zql/src/ivm/fan-in.d.ts.map +1 -1
- package/out/zql/src/ivm/fan-in.js +4 -2
- package/out/zql/src/ivm/fan-in.js.map +1 -1
- package/out/zql/src/ivm/fan-out.d.ts +1 -1
- package/out/zql/src/ivm/fan-out.d.ts.map +1 -1
- package/out/zql/src/ivm/fan-out.js +9 -3
- package/out/zql/src/ivm/fan-out.js.map +1 -1
- package/out/zql/src/ivm/filter-operators.d.ts +4 -6
- package/out/zql/src/ivm/filter-operators.d.ts.map +1 -1
- package/out/zql/src/ivm/filter-operators.js +14 -27
- package/out/zql/src/ivm/filter-operators.js.map +1 -1
- package/out/zql/src/ivm/filter.d.ts +1 -1
- package/out/zql/src/ivm/filter.d.ts.map +1 -1
- package/out/zql/src/ivm/filter.js +4 -2
- package/out/zql/src/ivm/filter.js.map +1 -1
- package/out/zql/src/ivm/flipped-join.d.ts +0 -1
- package/out/zql/src/ivm/flipped-join.d.ts.map +1 -1
- package/out/zql/src/ivm/flipped-join.js +0 -2
- package/out/zql/src/ivm/flipped-join.js.map +1 -1
- package/out/zql/src/ivm/join.d.ts +2 -15
- package/out/zql/src/ivm/join.d.ts.map +1 -1
- package/out/zql/src/ivm/join.js +10 -83
- package/out/zql/src/ivm/join.js.map +1 -1
- package/out/zql/src/ivm/memory-source.d.ts +4 -3
- package/out/zql/src/ivm/memory-source.d.ts.map +1 -1
- package/out/zql/src/ivm/memory-source.js +24 -23
- package/out/zql/src/ivm/memory-source.js.map +1 -1
- package/out/zql/src/ivm/operator.d.ts +0 -12
- package/out/zql/src/ivm/operator.d.ts.map +1 -1
- package/out/zql/src/ivm/operator.js.map +1 -1
- package/out/zql/src/ivm/skip.d.ts +0 -1
- package/out/zql/src/ivm/skip.d.ts.map +1 -1
- package/out/zql/src/ivm/skip.js +3 -11
- package/out/zql/src/ivm/skip.js.map +1 -1
- package/out/zql/src/ivm/take.d.ts +0 -1
- package/out/zql/src/ivm/take.d.ts.map +1 -1
- package/out/zql/src/ivm/take.js +0 -17
- package/out/zql/src/ivm/take.js.map +1 -1
- package/out/zql/src/ivm/union-fan-in.d.ts +0 -1
- package/out/zql/src/ivm/union-fan-in.d.ts.map +1 -1
- package/out/zql/src/ivm/union-fan-in.js +0 -3
- package/out/zql/src/ivm/union-fan-in.js.map +1 -1
- package/out/zql/src/ivm/union-fan-out.d.ts +0 -1
- package/out/zql/src/ivm/union-fan-out.d.ts.map +1 -1
- package/out/zql/src/ivm/union-fan-out.js +0 -3
- package/out/zql/src/ivm/union-fan-out.js.map +1 -1
- package/out/zql/src/ivm/view-apply-change.d.ts.map +1 -1
- package/out/zql/src/ivm/view-apply-change.js +1 -2
- package/out/zql/src/ivm/view-apply-change.js.map +1 -1
- package/out/zql/src/mutate/custom.d.ts +2 -2
- package/out/zql/src/mutate/custom.d.ts.map +1 -1
- package/out/zql/src/mutate/custom.js.map +1 -1
- package/out/zql/src/mutate/mutator-registry.d.ts +33 -15
- package/out/zql/src/mutate/mutator-registry.d.ts.map +1 -1
- package/out/zql/src/mutate/mutator-registry.js +2 -8
- package/out/zql/src/mutate/mutator-registry.js.map +1 -1
- package/out/zql/src/mutate/mutator.d.ts +50 -25
- package/out/zql/src/mutate/mutator.d.ts.map +1 -1
- package/out/zql/src/mutate/mutator.js +2 -3
- package/out/zql/src/mutate/mutator.js.map +1 -1
- package/out/zql/src/query/create-builder.d.ts +2 -2
- package/out/zql/src/query/create-builder.d.ts.map +1 -1
- package/out/zql/src/query/create-builder.js +12 -3
- package/out/zql/src/query/create-builder.js.map +1 -1
- package/out/zql/src/query/measure-push-operator.d.ts +0 -1
- package/out/zql/src/query/measure-push-operator.d.ts.map +1 -1
- package/out/zql/src/query/measure-push-operator.js +0 -3
- package/out/zql/src/query/measure-push-operator.js.map +1 -1
- package/out/zql/src/query/query-internals.d.ts.map +1 -1
- package/out/zql/src/query/query-internals.js +2 -2
- package/out/zql/src/query/query-internals.js.map +1 -1
- package/out/zql/src/query/query-registry.d.ts +126 -58
- package/out/zql/src/query/query-registry.d.ts.map +1 -1
- package/out/zql/src/query/query-registry.js +13 -21
- package/out/zql/src/query/query-registry.js.map +1 -1
- package/out/zql/src/query/query.d.ts +18 -5
- package/out/zql/src/query/query.d.ts.map +1 -1
- package/out/zqlite/src/table-source.d.ts.map +1 -1
- package/out/zqlite/src/table-source.js +6 -10
- package/out/zqlite/src/table-source.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutator-registry.d.ts","sourceRoot":"","sources":["../../../../../zql/src/mutate/mutator-registry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mutator-registry.d.ts","sourceRoot":"","sources":["../../../../../zql/src/mutate/mutator-registry.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,KAAK,SAAS,EAAC,MAAM,mCAAmC,CAAC;AAC5E,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,6BAA6B,CAAC;AAKnE,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,0CAA0C,CAAC;AAC5E,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,mCAAmC,CAAC;AAG9D,OAAO,EAGL,KAAK,UAAU,EAEf,KAAK,OAAO,EACZ,KAAK,iBAAiB,EACvB,MAAM,cAAc,CAAC;AAEtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,EACtB,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,qBAAqB,CAAC,CAClC,GACD,EAAE,CAAC,CAAC,CAAC,SAAS,qBAAqB,GACjC,eAAe,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,GAC/B,KAAK;CACZ,CAAC,MAAM,EAAE,CAAC,CAAC;AA2DZ,wBAAiB,eAAe,CAC9B,QAAQ,EAAE,kBAAkB,GAC3B,QAAQ,CAAC,UAAU,CAAC,CAEtB"}
|
|
@@ -13,10 +13,7 @@ function defineMutators(definitionsOrBase, maybeOverrides) {
|
|
|
13
13
|
if (isMutatorDefinition(value)) {
|
|
14
14
|
result[key] = createMutator(name, value);
|
|
15
15
|
} else {
|
|
16
|
-
result[key] = processDefinitions(
|
|
17
|
-
value,
|
|
18
|
-
path
|
|
19
|
-
);
|
|
16
|
+
result[key] = processDefinitions(value, path);
|
|
20
17
|
}
|
|
21
18
|
path.pop();
|
|
22
19
|
}
|
|
@@ -25,10 +22,7 @@ function defineMutators(definitionsOrBase, maybeOverrides) {
|
|
|
25
22
|
if (maybeOverrides !== void 0) {
|
|
26
23
|
let base;
|
|
27
24
|
if (!isMutatorRegistry(definitionsOrBase)) {
|
|
28
|
-
base = processDefinitions(
|
|
29
|
-
definitionsOrBase,
|
|
30
|
-
[]
|
|
31
|
-
);
|
|
25
|
+
base = processDefinitions(definitionsOrBase, []);
|
|
32
26
|
} else {
|
|
33
27
|
base = definitionsOrBase;
|
|
34
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutator-registry.js","sources":["../../../../../zql/src/mutate/mutator-registry.ts"],"sourcesContent":["import {deepMerge, type DeepMerge} from '../../../shared/src/deep-merge.ts';\nimport type {ReadonlyJSONValue} from '../../../shared/src/json.ts';\nimport {\n getValueAtPath,\n iterateLeaves,\n} from '../../../shared/src/object-traversal.ts';\nimport type {\n DefaultContext,\n DefaultSchema,\n} from '../../../zero-types/src/default-types.ts';\nimport type {Schema} from '../../../zero-types/src/schema.ts';\nimport {validateInput} from '../query/validate-input.ts';\nimport type {Transaction} from './custom.ts';\nimport {\n isMutator,\n isMutatorDefinition,\n type AnyMutator,\n type MutationRequest,\n type Mutator,\n type MutatorDefinition,\n} from './mutator.ts';\n\n/**\n * Creates a MutatorRegistry from a tree of MutatorDefinitions,\n * optionally extending a base MutatorRegistry.\n *\n * @example\n * ```ts\n * // Create a new registry\n * const mutators = defineMutators({\n * user: {\n * create: defineMutator(...),\n * delete: defineMutator(...),\n * },\n * post: {\n * publish: defineMutator(...),\n * },\n * });\n *\n * // Extend an existing registry (e.g., for server-side overrides)\n * const serverMutators = defineMutators(mutators, {\n * user: {\n * create: defineMutator(...), // overrides mutators.user.create\n * },\n * // post.publish is inherited from mutators\n * });\n *\n * // Access mutators by path\n * const mr = mutators.user.create({name: 'Alice'});\n *\n * // Execute on client\n * zero.mutate(mr);\n *\n * // Execute on server\n * mr.mutator.fn({tx, ctx, args: mr.args});\n *\n * // Lookup by name (for server-side dispatch)\n * const mutator = getMutator(mutators, 'user.create');\n * ```\n */\nexport function defineMutators<\n T extends MutatorDefinitions<S, C>,\n S extends Schema = DefaultSchema,\n C = DefaultContext,\n>(definitions: T): MutatorRegistry<S, C, T>;\n\nexport function defineMutators<\n TBase extends MutatorDefinitions<S, C>,\n TOverrides extends MutatorDefinitions<S, C>,\n S extends Schema = DefaultSchema,\n C = DefaultContext,\n>(\n base: MutatorRegistry<S, C, TBase>,\n overrides: TOverrides,\n): MutatorRegistry<S, C, DeepMerge<TBase, TOverrides>>;\n\nexport function defineMutators<\n TBase extends MutatorDefinitions<S, C>,\n TOverrides extends MutatorDefinitions<S, C>,\n S extends Schema = DefaultSchema,\n C = DefaultContext,\n>(\n base: TBase,\n overrides: TOverrides,\n): MutatorRegistry<S, C, DeepMerge<TBase, TOverrides>>;\n\nexport function defineMutators<S extends Schema, C>(\n definitionsOrBase: MutatorDefinitions<S, C> | AnyMutatorRegistry,\n maybeOverrides?: MutatorDefinitions<S, C>,\n): AnyMutatorRegistry {\n function processDefinitions(\n definitions: MutatorDefinitions<S, C>,\n path: string[],\n ): Record<string | symbol, unknown> {\n const result: Record<string | symbol, unknown> = {\n [mutatorRegistryTag]: true,\n };\n\n for (const [key, value] of Object.entries(definitions)) {\n path.push(key);\n const name = path.join('.');\n\n if (isMutatorDefinition(value)) {\n result[key] = createMutator(name, value);\n } else {\n // Nested definitions\n result[key] = processDefinitions(\n value as MutatorDefinitions<S, C>,\n path,\n );\n }\n path.pop();\n }\n\n return result;\n }\n\n if (maybeOverrides !== undefined) {\n // Merge base and overrides\n let base: Record<string | symbol, unknown>;\n if (!isMutatorRegistry(definitionsOrBase)) {\n base = processDefinitions(\n definitionsOrBase as MutatorDefinitions<S, C>,\n [],\n );\n } else {\n base = definitionsOrBase;\n }\n\n const processed = processDefinitions(maybeOverrides, []);\n\n const merged = deepMerge(base, processed, isMutator) as Record<\n string | symbol,\n unknown\n >;\n // deepMerge doesn't copy symbols, so we need to add the tag\n merged[mutatorRegistryTag] = true;\n return merged as AnyMutatorRegistry;\n }\n\n return processDefinitions(\n definitionsOrBase as MutatorDefinitions<S, C>,\n [],\n ) as AnyMutatorRegistry;\n}\n\n/**\n * Gets a Mutator by its dot-separated name from a MutatorRegistry.\n * Returns undefined if not found.\n */\nexport function getMutator(\n registry: AnyMutatorRegistry,\n name: string,\n): AnyMutator | undefined {\n const m = getValueAtPath(registry, name, '.');\n return m as AnyMutator | undefined;\n}\n\n/**\n * Gets a Mutator by its dot-separated name from a MutatorRegistry.\n * Throws if not found.\n */\nexport function mustGetMutator(\n registry: AnyMutatorRegistry,\n name: string,\n): AnyMutator {\n const mutator = getMutator(registry, name);\n if (mutator === undefined) {\n throw new Error(`Mutator not found: ${name}`);\n }\n return mutator;\n}\n\n/**\n * Checks if a value is a MutatorRegistry.\n */\nexport function isMutatorRegistry<S extends Schema, C>(\n value: unknown,\n): value is MutatorRegistry<S, C, MutatorDefinitions<S, C>> {\n return (\n typeof value === 'object' && value !== null && mutatorRegistryTag in value\n );\n}\n\n// ----------------------------------------------------------------------------\n// Types\n// ----------------------------------------------------------------------------\n\n/**\n * A tree of MutatorDefinitions, possibly nested.\n */\nexport type MutatorDefinitions<S extends Schema, C> = {\n readonly [key: string]: // oxlint-disable-next-line no-explicit-any\n MutatorDefinition<any, any, S, C, any> | MutatorDefinitions<S, C>;\n};\n\n/**\n * The result of defineMutators(). A tree of Mutators with a tag for detection.\n */\nexport type MutatorRegistry<\n S extends Schema,\n C,\n T extends MutatorDefinitions<S, C>,\n> = ToMutatorTree<S, C, T> & {\n [mutatorRegistryTag]: true;\n};\n\n/**\n * A branded type for use in type constraints. Use this instead of\n * `MutatorRegistry<S, C, any>` to avoid TypeScript drilling into\n * the complex ToMutatorTree structure and hitting variance issues.\n */\nexport type AnyMutatorRegistry = {[mutatorRegistryTag]: true} & Record<\n string,\n unknown\n>;\n\n// ----------------------------------------------------------------------------\n// Internal\n// ----------------------------------------------------------------------------\n\nconst mutatorRegistryTag = Symbol('mutatorRegistry');\n\n/**\n * Transforms a MutatorDefinitions into a tree of Mutators.\n * Each MutatorDefinition becomes a Mutator at the same path.\n * Uses TInput for the callable args (TOutput is only used internally for validation).\n */\ntype ToMutatorTree<S extends Schema, C, T extends MutatorDefinitions<S, C>> = {\n readonly [K in keyof T]: T[K] extends MutatorDefinition<\n infer TInput,\n // oxlint-disable-next-line no-explicit-any\n any, // TOutput - only used internally for validation\n S,\n C,\n infer TWrappedTransaction\n >\n ? Mutator<TInput, S, C, TWrappedTransaction>\n : T[K] extends MutatorDefinitions<S, C>\n ? ToMutatorTree<S, C, T[K]>\n : never;\n};\n\nfunction createMutator<\n S extends Schema,\n C,\n ArgsInput extends ReadonlyJSONValue | undefined,\n ArgsOutput extends ReadonlyJSONValue | undefined,\n TWrappedTransaction,\n>(\n name: string,\n definition: MutatorDefinition<\n ArgsInput,\n ArgsOutput,\n S,\n C,\n TWrappedTransaction\n >,\n): Mutator<ArgsInput, S, C, TWrappedTransaction> {\n const {validator} = definition;\n\n // fn takes ReadonlyJSONValue args because it's called during rebase (from\n // stored JSON) and on the server (from wire format). Validation happens here.\n const fn = async (options: {\n args: ArgsInput;\n ctx: C;\n tx: Transaction<S, TWrappedTransaction>;\n }): Promise<void> => {\n const validatedArgs = validator\n ? validateInput<ArgsInput, ArgsOutput>(\n name,\n options.args,\n validator,\n 'mutator',\n )\n : (options.args as unknown as ArgsOutput);\n await definition({\n args: validatedArgs,\n ctx: options.ctx,\n tx: options.tx,\n });\n };\n\n // Create the callable mutator\n const mutator = (\n args: ArgsInput,\n ): MutationRequest<ArgsInput, S, C, Transaction<S, TWrappedTransaction>> => ({\n mutator: mutator as unknown as Mutator<\n ArgsInput,\n S,\n C,\n Transaction<S, TWrappedTransaction>\n >,\n args,\n });\n mutator.mutatorName = name;\n mutator.fn = fn;\n\n return mutator as unknown as Mutator<\n ArgsInput,\n S,\n C,\n Transaction<S, TWrappedTransaction>\n >;\n}\n\nexport function* iterateMutators(\n registry: AnyMutatorRegistry,\n): Iterable<AnyMutator> {\n yield* iterateLeaves(registry, isMutator);\n}\n"],"names":[],"mappings":";;;;AAsFO,SAAS,eACd,mBACA,gBACoB;AACpB,WAAS,mBACP,aACA,MACkC;AAClC,UAAM,SAA2C;AAAA,MAC/C,CAAC,kBAAkB,GAAG;AAAA,IAAA;AAGxB,eAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,WAAW,GAAG;AACtD,WAAK,KAAK,GAAG;AACb,YAAM,OAAO,KAAK,KAAK,GAAG;AAE1B,UAAI,oBAAoB,KAAK,GAAG;AAC9B,eAAO,GAAG,IAAI,cAAc,MAAM,KAAK;AAAA,MACzC,OAAO;AAEL,eAAO,GAAG,IAAI;AAAA,UACZ;AAAA,UACA;AAAA,QAAA;AAAA,MAEJ;AACA,WAAK,IAAA;AAAA,IACP;AAEA,WAAO;AAAA,EACT;AAEA,MAAI,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":"mutator-registry.js","sources":["../../../../../zql/src/mutate/mutator-registry.ts"],"sourcesContent":["// oxlint-disable no-explicit-any\nimport {deepMerge, type DeepMerge} from '../../../shared/src/deep-merge.ts';\nimport type {ReadonlyJSONValue} from '../../../shared/src/json.ts';\nimport {\n getValueAtPath,\n iterateLeaves,\n} from '../../../shared/src/object-traversal.ts';\nimport type {DefaultSchema} from '../../../zero-types/src/default-types.ts';\nimport type {Schema} from '../../../zero-types/src/schema.ts';\nimport {validateInput} from '../query/validate-input.ts';\nimport type {AnyTransaction} from './custom.ts';\nimport {\n isMutator,\n isMutatorDefinition,\n type AnyMutator,\n type MutationRequest,\n type Mutator,\n type MutatorDefinition,\n} from './mutator.ts';\n\n/**\n * Creates a MutatorRegistry from a tree of MutatorDefinitions,\n * optionally extending a base MutatorRegistry.\n *\n * @example\n * ```ts\n * // Create a new registry\n * const mutators = defineMutators({\n * user: {\n * create: defineMutator(...),\n * delete: defineMutator(...),\n * },\n * post: {\n * publish: defineMutator(...),\n * },\n * });\n *\n * // Extend an existing registry (e.g., for server-side overrides)\n * const serverMutators = defineMutators(mutators, {\n * user: {\n * create: defineMutator(...), // overrides mutators.user.create\n * },\n * // post.publish is inherited from mutators\n * });\n *\n * // Access mutators by path\n * const mr = mutators.user.create({name: 'Alice'});\n *\n * // Execute on client\n * zero.mutate(mr);\n *\n * // Execute on server\n * mr.mutator.fn({tx, ctx, args: mr.args});\n *\n * // Lookup by name (for server-side dispatch)\n * const mutator = getMutator(mutators, 'user.create');\n * ```\n */\nexport function defineMutators<\n // let MD infer freely so defaults aren't erased by a AnyMutatorDefinitions constraint\n const MD,\n S extends Schema = DefaultSchema,\n>(\n // we assert types here for clear error messages\n definitions: MD & AssertMutatorDefinitions<MD>,\n): MutatorRegistry<EnsureMutatorDefinitions<MD>, S>;\n\nexport function defineMutators<\n // same as MD above, but for TBase and TOverrides\n const TBase,\n const TOverrides,\n S extends Schema = DefaultSchema,\n>(\n base:\n | MutatorRegistry<EnsureMutatorDefinitions<TBase>, S>\n | (TBase & AssertMutatorDefinitions<TBase>),\n overrides: TOverrides & AssertMutatorDefinitions<TOverrides>,\n): MutatorRegistry<\n DeepMerge<\n EnsureMutatorDefinitions<TBase>,\n EnsureMutatorDefinitions<TOverrides>\n >,\n S\n>;\n\nexport function defineMutators(\n definitionsOrBase: AnyMutatorDefinitions | AnyMutatorRegistry,\n maybeOverrides?: AnyMutatorDefinitions,\n): AnyMutatorRegistry {\n function processDefinitions(\n definitions: AnyMutatorDefinitions,\n path: string[],\n ): Record<string | symbol, unknown> {\n const result: Record<string | symbol, unknown> = {\n [mutatorRegistryTag]: true,\n };\n\n for (const [key, value] of Object.entries(definitions)) {\n path.push(key);\n const name = path.join('.');\n\n if (isMutatorDefinition(value)) {\n result[key] = createMutator(name, value);\n } else {\n // Nested definitions\n result[key] = processDefinitions(value as AnyMutatorDefinitions, path);\n }\n path.pop();\n }\n\n return result;\n }\n\n if (maybeOverrides !== undefined) {\n // Merge base and overrides\n let base: Record<string | symbol, unknown>;\n if (!isMutatorRegistry(definitionsOrBase)) {\n base = processDefinitions(definitionsOrBase as AnyMutatorDefinitions, []);\n } else {\n base = definitionsOrBase;\n }\n\n const processed = processDefinitions(maybeOverrides, []);\n\n const merged = deepMerge(base, processed, isMutator) as Record<\n string | symbol,\n unknown\n >;\n // deepMerge doesn't copy symbols, so we need to add the tag\n merged[mutatorRegistryTag] = true;\n return merged as AnyMutatorRegistry;\n }\n\n return processDefinitions(\n definitionsOrBase as AnyMutatorDefinitions,\n [],\n ) as AnyMutatorRegistry;\n}\n\n/**\n * Gets a Mutator by its dot-separated name from a MutatorRegistry.\n * Returns undefined if not found.\n */\nexport function getMutator<\n MD extends AnyMutatorDefinitions,\n TSchema extends Schema = DefaultSchema,\n>(\n registry: MutatorRegistry<MD, TSchema>,\n name: string,\n): FromMutatorTree<MD, TSchema> | undefined {\n const m = getValueAtPath(registry, name, '.');\n return m as FromMutatorTree<MD, TSchema> | undefined;\n}\n\n/**\n * Gets a Mutator by its dot-separated name from a MutatorRegistry.\n * Throws if not found.\n */\nexport function mustGetMutator<\n MD extends AnyMutatorDefinitions,\n TSchema extends Schema = DefaultSchema,\n>(\n registry: MutatorRegistry<MD, TSchema>,\n name: string,\n): FromMutatorTree<MD, TSchema> {\n const mutator = getMutator(registry, name);\n if (mutator === undefined) {\n throw new Error(`Mutator not found: ${name}`);\n }\n return mutator;\n}\n\n/**\n * Checks if a value is a MutatorRegistry.\n */\nexport function isMutatorRegistry<\n MD extends AnyMutatorDefinitions,\n TSchema extends Schema = DefaultSchema,\n>(value: unknown): value is MutatorRegistry<MD, TSchema> {\n return (\n typeof value === 'object' && value !== null && mutatorRegistryTag in value\n );\n}\n\n/**\n * Creates a function that can be used to define mutators with a specific schema.\n */\nexport function defineMutatorsWithType<\n TSchema extends Schema,\n>(): TypedDefineMutators<TSchema> {\n return defineMutators;\n}\n\n/**\n * The return type of defineMutatorsWithType. A function matching the\n * defineMutators overloads but with Schema pre-bound.\n */\ntype TypedDefineMutators<S extends Schema> = {\n // Single definitions\n <MD>(\n definitions: MD & AssertMutatorDefinitions<MD>,\n ): MutatorRegistry<EnsureMutatorDefinitions<MD>, S>;\n\n // Base and overrides\n <TBase, TOverrides>(\n base:\n | MutatorRegistry<EnsureMutatorDefinitions<TBase>, S>\n | (TBase & AssertMutatorDefinitions<TBase>),\n overrides: TOverrides,\n ): MutatorRegistry<\n DeepMerge<\n EnsureMutatorDefinitions<TBase>,\n EnsureMutatorDefinitions<TOverrides>\n >,\n S\n >;\n};\n\n// ----------------------------------------------------------------------------\n// Types\n// ----------------------------------------------------------------------------\n\n/**\n * A tree of MutatorDefinitions, possibly nested.\n */\nexport type MutatorDefinitions<Context, WrappedTransaction> = {\n readonly [key: string]:\n | MutatorDefinition<any, any, Context, WrappedTransaction>\n | MutatorDefinitions<Context, WrappedTransaction>;\n};\n\nexport type AnyMutatorDefinitions = MutatorDefinitions<any, any>;\n\nexport type AssertMutatorDefinitions<MD> = MD extends AnyMutatorDefinitions\n ? unknown\n : never;\n\nexport type EnsureMutatorDefinitions<MD> = MD extends AnyMutatorDefinitions\n ? MD\n : never;\n\n/**\n * The result of defineMutators(). A tree of Mutators with a tag for detection.\n */\nexport type MutatorRegistry<\n MD extends AnyMutatorDefinitions,\n TSchema extends Schema,\n> = ToMutatorTree<MD, TSchema> & {\n [mutatorRegistryTag]: true;\n};\n\n/**\n * A branded type for use in type constraints. Use this instead of\n * `MutatorRegistry<S, C, any>` to avoid TypeScript drilling into\n * the complex ToMutatorTree structure and hitting variance issues.\n */\nexport type AnyMutatorRegistry = {\n [mutatorRegistryTag]: true;\n [key: string]: unknown;\n};\n\n// ----------------------------------------------------------------------------\n// Internal\n// ----------------------------------------------------------------------------\n\nconst mutatorRegistryTag = Symbol('mutatorRegistry');\n\n/**\n * Transforms a MutatorDefinitions into a tree of Mutators.\n * Each MutatorDefinition becomes a Mutator at the same path.\n * Uses TInput for the callable args (TOutput is only used internally for validation).\n */\nexport type ToMutatorTree<\n MD extends AnyMutatorDefinitions,\n TSchema extends Schema,\n> = {\n readonly [K in keyof MD]: MD[K] extends MutatorDefinition<any, any, any, any>\n ? // pull types from the phantom property\n Mutator<\n MD[K]['~']['$input'],\n TSchema,\n MD[K]['~']['$context'],\n MD[K]['~']['$wrappedTransaction']\n >\n : MD[K] extends AnyMutatorDefinitions\n ? ToMutatorTree<MD[K], TSchema>\n : never;\n};\n\nexport type FromMutatorTree<\n MD extends AnyMutatorDefinitions,\n TSchema extends Schema,\n> = {\n readonly [K in keyof MD]: MD[K] extends MutatorDefinition<any, any, any, any>\n ? // pull types from the phantom property\n Mutator<\n ReadonlyJSONValue | undefined, // intentionally left as generic to avoid variance issues\n TSchema,\n MD[K]['~']['$context'],\n MD[K]['~']['$wrappedTransaction']\n >\n : MD[K] extends AnyMutatorDefinitions\n ? FromMutatorTree<MD[K], TSchema>\n : never;\n}[keyof MD];\n\nfunction createMutator<\n ArgsInput extends ReadonlyJSONValue | undefined,\n ArgsOutput extends ReadonlyJSONValue | undefined,\n TSchema extends Schema,\n C,\n TWrappedTransaction,\n>(\n name: string,\n definition: MutatorDefinition<ArgsInput, ArgsOutput, C, TWrappedTransaction>,\n): Mutator<ArgsInput, TSchema, C, TWrappedTransaction> {\n const {validator} = definition;\n\n // fn takes ReadonlyJSONValue args because it's called during rebase (from\n // stored JSON) and on the server (from wire format). Validation happens here.\n const fn = async (options: {\n args: ArgsInput;\n ctx: C;\n tx: AnyTransaction;\n }): Promise<void> => {\n const validatedArgs = validator\n ? validateInput<ArgsInput, ArgsOutput>(\n name,\n options.args,\n validator,\n 'mutator',\n )\n : (options.args as unknown as ArgsOutput);\n await definition({\n args: validatedArgs,\n ctx: options.ctx,\n tx: options.tx,\n });\n };\n\n // Create the callable mutator\n const mutator = (\n args: ArgsInput,\n ): MutationRequest<ArgsInput, TSchema, C, TWrappedTransaction> => ({\n mutator: mutator as unknown as Mutator<\n ArgsInput,\n TSchema,\n C,\n TWrappedTransaction\n >,\n args,\n });\n mutator.mutatorName = name;\n mutator.fn = fn;\n\n return mutator as unknown as Mutator<\n ArgsInput,\n TSchema,\n C,\n TWrappedTransaction\n >;\n}\n\nexport function* iterateMutators(\n registry: AnyMutatorRegistry,\n): Iterable<AnyMutator> {\n yield* iterateLeaves(registry, isMutator);\n}\n"],"names":[],"mappings":";;;;AAqFO,SAAS,eACd,mBACA,gBACoB;AACpB,WAAS,mBACP,aACA,MACkC;AAClC,UAAM,SAA2C;AAAA,MAC/C,CAAC,kBAAkB,GAAG;AAAA,IAAA;AAGxB,eAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,WAAW,GAAG;AACtD,WAAK,KAAK,GAAG;AACb,YAAM,OAAO,KAAK,KAAK,GAAG;AAE1B,UAAI,oBAAoB,KAAK,GAAG;AAC9B,eAAO,GAAG,IAAI,cAAc,MAAM,KAAK;AAAA,MACzC,OAAO;AAEL,eAAO,GAAG,IAAI,mBAAmB,OAAgC,IAAI;AAAA,MACvE;AACA,WAAK,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AAS;AAC1C;"}
|
|
@@ -1,28 +1,58 @@
|
|
|
1
1
|
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
import type { Expand } from '../../../shared/src/expand.ts';
|
|
2
3
|
import type { ReadonlyJSONValue } from '../../../shared/src/json.ts';
|
|
3
4
|
import type { DefaultContext, DefaultSchema, DefaultWrappedTransaction } from '../../../zero-types/src/default-types.ts';
|
|
4
5
|
import type { Schema } from '../../../zero-types/src/schema.ts';
|
|
5
6
|
import type { AnyTransaction, Transaction } from './custom.ts';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
export type MutatorDefinitionTypes<TInput extends ReadonlyJSONValue | undefined, TOutput, TContext, TWrappedTransaction> = 'MutatorDefinition' & {
|
|
8
|
+
readonly $input: TInput;
|
|
9
|
+
readonly $output: TOutput;
|
|
10
|
+
readonly $context: TContext;
|
|
11
|
+
readonly $wrappedTransaction: TWrappedTransaction;
|
|
12
|
+
};
|
|
13
|
+
export declare function isMutatorDefinition<TInput extends ReadonlyJSONValue | undefined, TOutput extends ReadonlyJSONValue | undefined, TContext = DefaultContext, TWrappedTransaction = DefaultWrappedTransaction>(f: unknown): f is MutatorDefinition<TInput, TOutput, TContext, TWrappedTransaction>;
|
|
14
|
+
export type MutatorDefinition<TInput extends ReadonlyJSONValue | undefined, TOutput extends ReadonlyJSONValue | undefined, TContext = DefaultContext, TWrappedTransaction = DefaultWrappedTransaction> = ((options: {
|
|
9
15
|
args: TOutput;
|
|
10
16
|
ctx: TContext;
|
|
11
|
-
tx:
|
|
17
|
+
tx: AnyTransaction;
|
|
12
18
|
}) => Promise<void>) & {
|
|
13
|
-
[defineMutatorTag]: true;
|
|
14
19
|
validator: StandardSchemaV1<TInput, TOutput> | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Type-only phantom property to surface mutator types in a covariant position.
|
|
22
|
+
*/
|
|
23
|
+
['~']: Expand<MutatorDefinitionTypes<TInput, TOutput, TContext, TWrappedTransaction>>;
|
|
15
24
|
};
|
|
16
|
-
export declare function defineMutator<TInput extends ReadonlyJSONValue | undefined, TOutput extends ReadonlyJSONValue | undefined, TSchema extends Schema = DefaultSchema, TContext = DefaultContext, TWrappedTransaction = DefaultWrappedTransaction>(validator: StandardSchemaV1<TInput, TOutput>, mutator: (options: {
|
|
25
|
+
export declare function defineMutator<TInput extends ReadonlyJSONValue | undefined = undefined, TOutput extends ReadonlyJSONValue | undefined = TInput, TSchema extends Schema = DefaultSchema, TContext = DefaultContext, TWrappedTransaction = DefaultWrappedTransaction>(validator: StandardSchemaV1<TInput, TOutput>, mutator: (options: {
|
|
17
26
|
args: TOutput;
|
|
18
27
|
ctx: TContext;
|
|
19
28
|
tx: Transaction<TSchema, TWrappedTransaction>;
|
|
20
|
-
}) => Promise<void>): MutatorDefinition<TInput, TOutput,
|
|
21
|
-
export declare function defineMutator<
|
|
22
|
-
args:
|
|
29
|
+
}) => Promise<void>): MutatorDefinition<TInput, TOutput, TContext, TWrappedTransaction>;
|
|
30
|
+
export declare function defineMutator<TInput extends ReadonlyJSONValue | undefined = ReadonlyJSONValue | undefined, TSchema extends Schema = DefaultSchema, TContext = DefaultContext, TWrappedTransaction = DefaultWrappedTransaction>(mutator: (options: {
|
|
31
|
+
args: TInput;
|
|
23
32
|
ctx: TContext;
|
|
24
33
|
tx: Transaction<TSchema, TWrappedTransaction>;
|
|
25
|
-
}) => Promise<void>): MutatorDefinition<
|
|
34
|
+
}) => Promise<void>): MutatorDefinition<TInput, TInput, TContext, TWrappedTransaction>;
|
|
35
|
+
export declare function defineMutatorWithType<TSchema extends Schema, TContext = unknown, TWrappedTransaction = unknown>(): TypedDefineMutator<TSchema, TContext, TWrappedTransaction>;
|
|
36
|
+
/**
|
|
37
|
+
* The return type of defineMutatorWithType. A function matching the
|
|
38
|
+
* defineMutator overloads but with Schema, Context, and WrappedTransaction
|
|
39
|
+
* pre-bound.
|
|
40
|
+
*
|
|
41
|
+
* This is used as a workaround to using DefaultTypes (e.g. when using
|
|
42
|
+
* multiple Zero instances).
|
|
43
|
+
*/
|
|
44
|
+
type TypedDefineMutator<TSchema extends Schema, TContext, TWrappedTransaction> = {
|
|
45
|
+
<TArgs extends ReadonlyJSONValue | undefined>(mutator: (options: {
|
|
46
|
+
args: TArgs;
|
|
47
|
+
ctx: TContext;
|
|
48
|
+
tx: Transaction<TSchema, TWrappedTransaction>;
|
|
49
|
+
}) => Promise<void>): MutatorDefinition<TArgs, TArgs, TContext, TWrappedTransaction>;
|
|
50
|
+
<TInput extends ReadonlyJSONValue | undefined, TOutput extends ReadonlyJSONValue | undefined>(validator: StandardSchemaV1<TInput, TOutput>, mutator: (options: {
|
|
51
|
+
args: TOutput;
|
|
52
|
+
ctx: TContext;
|
|
53
|
+
tx: Transaction<TSchema, TWrappedTransaction>;
|
|
54
|
+
}) => Promise<void>): MutatorDefinition<TInput, TOutput, TContext, TWrappedTransaction>;
|
|
55
|
+
};
|
|
26
56
|
/**
|
|
27
57
|
* A callable wrapper around a MutatorDefinition, created by `defineMutators()`.
|
|
28
58
|
*
|
|
@@ -32,43 +62,38 @@ export declare function defineMutator<TArgs extends ReadonlyJSONValue | undefine
|
|
|
32
62
|
* The `fn` property is used for execution and takes raw JSON args (for rebase
|
|
33
63
|
* and server wire format cases) that are validated internally.
|
|
34
64
|
*
|
|
35
|
-
* @template
|
|
36
|
-
* @template TSchema - The schema type
|
|
65
|
+
* @template TInput - The argument type accepted by the callable (before validation)
|
|
37
66
|
* @template TContext - The context type available during mutation execution
|
|
38
67
|
* @template TWrappedTransaction - The wrapped transaction type
|
|
39
68
|
*/
|
|
40
|
-
export type Mutator<
|
|
69
|
+
export type Mutator<TInput extends ReadonlyJSONValue | undefined, TSchema extends Schema = DefaultSchema, TContext = DefaultContext, TWrappedTransaction = DefaultWrappedTransaction> = MutatorCallable<TInput, TSchema, TContext, TWrappedTransaction> & {
|
|
41
70
|
readonly mutatorName: string;
|
|
42
71
|
/**
|
|
43
72
|
* Execute the mutation. Args are ReadonlyJSONValue because this is called
|
|
44
73
|
* during rebase (from stored JSON) and on the server (from wire format).
|
|
45
74
|
* Validation happens internally before the recipe function runs.
|
|
46
|
-
*
|
|
47
|
-
* The tx parameter uses AnyTransaction to avoid contravariance issues when
|
|
48
|
-
* calling from generic code. The implementation casts to the specific type.
|
|
49
75
|
*/
|
|
50
76
|
readonly fn: (options: {
|
|
51
|
-
args:
|
|
77
|
+
args: TInput;
|
|
52
78
|
ctx: TContext;
|
|
53
|
-
tx:
|
|
79
|
+
tx: Transaction<TSchema, TWrappedTransaction>;
|
|
54
80
|
}) => Promise<void>;
|
|
55
81
|
};
|
|
56
|
-
type MutatorCallable<
|
|
57
|
-
export type AnyMutator = Mutator<any,
|
|
82
|
+
type MutatorCallable<TInput extends ReadonlyJSONValue | undefined, TSchema extends Schema, TContext, TWrappedTransaction> = [TInput] extends [undefined] ? () => MutationRequest<TInput, TSchema, TContext, TWrappedTransaction> : undefined extends TInput ? (args?: TInput) => MutationRequest<TInput, TSchema, TContext, TWrappedTransaction> : (args: TInput) => MutationRequest<TInput, TSchema, TContext, TWrappedTransaction>;
|
|
83
|
+
export type AnyMutator = Mutator<any, any, any, any>;
|
|
58
84
|
/**
|
|
59
85
|
* The result of calling a Mutator with arguments.
|
|
60
86
|
*
|
|
61
87
|
* Created by `mutators.foo.bar(42)`, executed by `zero.mutate(mr)` on the client
|
|
62
88
|
* or `mr.mutator.fn({tx, ctx, args: mr.args})` on the server.
|
|
63
89
|
*
|
|
64
|
-
* @template
|
|
65
|
-
* @template TSchema - The schema type
|
|
90
|
+
* @template TInput - The argument type (before validation, sent to server)
|
|
66
91
|
* @template TContext - The context type available during mutation execution
|
|
67
92
|
* @template TWrappedTransaction - The wrapped transaction type
|
|
68
93
|
*/
|
|
69
|
-
export type MutationRequest<
|
|
70
|
-
readonly mutator: Mutator<
|
|
71
|
-
readonly args:
|
|
94
|
+
export type MutationRequest<TInput extends ReadonlyJSONValue | undefined, TSchema extends Schema = DefaultSchema, TContext = DefaultContext, TWrappedTransaction = DefaultWrappedTransaction> = {
|
|
95
|
+
readonly mutator: Mutator<TInput, TSchema, TContext, TWrappedTransaction>;
|
|
96
|
+
readonly args: TInput;
|
|
72
97
|
};
|
|
73
98
|
/**
|
|
74
99
|
* Checks if a value is a Mutator (the result of processing a MutatorDefinition
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutator.d.ts","sourceRoot":"","sources":["../../../../../zql/src/mutate/mutator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,6BAA6B,CAAC;AAEnE,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,yBAAyB,EAC1B,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,mCAAmC,CAAC;AAC9D,OAAO,KAAK,EAAC,cAAc,EAAE,WAAW,EAAC,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"mutator.d.ts","sourceRoot":"","sources":["../../../../../zql/src/mutate/mutator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,+BAA+B,CAAC;AAC1D,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,6BAA6B,CAAC;AAEnE,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,yBAAyB,EAC1B,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,mCAAmC,CAAC;AAC9D,OAAO,KAAK,EAAC,cAAc,EAAE,WAAW,EAAC,MAAM,aAAa,CAAC;AAQ7D,MAAM,MAAM,sBAAsB,CAChC,MAAM,SAAS,iBAAiB,GAAG,SAAS,EAC5C,OAAO,EACP,QAAQ,EACR,mBAAmB,IACjB,mBAAmB,GAAG;IAC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,CAAC,SAAS,CAAC,GAC5B,MAAM,eAAe,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,mBAAmB,CAAC,GACrE,SAAS,SAAS,MAAM,GACtB,CACE,IAAI,CAAC,EAAE,MAAM,KACV,eAAe,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,mBAAmB,CAAC,GACpE,CACE,IAAI,EAAE,MAAM,KACT,eAAe,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,mBAAmB,CAAC,CAAC;AAG3E,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAErD;;;;;;;;;GASG;AACH,MAAM,MAAM,eAAe,CACzB,MAAM,SAAS,iBAAiB,GAAG,SAAS,EAC5C,OAAO,SAAS,MAAM,GAAG,aAAa,EACtC,QAAQ,GAAG,cAAc,EACzB,mBAAmB,GAAG,yBAAyB,IAC7C;IACF,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,mBAAmB,CAAC,CAAC;IAC1E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;;GAGG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAQ7D"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { must } from "../../../shared/src/must.js";
|
|
2
|
-
const defineMutatorTag = Symbol();
|
|
3
2
|
function isMutatorDefinition(f) {
|
|
4
|
-
return typeof f === "function" &&
|
|
3
|
+
return typeof f === "function" && f["~"] === "MutatorDefinition";
|
|
5
4
|
}
|
|
6
5
|
function defineMutator(validatorOrMutator, mutator) {
|
|
7
6
|
let validator;
|
|
@@ -14,7 +13,7 @@ function defineMutator(validatorOrMutator, mutator) {
|
|
|
14
13
|
actualMutator = must(mutator);
|
|
15
14
|
}
|
|
16
15
|
const f = actualMutator;
|
|
17
|
-
f[
|
|
16
|
+
f["~"] = "MutatorDefinition";
|
|
18
17
|
f.validator = validator;
|
|
19
18
|
return f;
|
|
20
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutator.js","sources":["../../../../../zql/src/mutate/mutator.ts"],"sourcesContent":["import type {StandardSchemaV1} from '@standard-schema/spec';\nimport type {ReadonlyJSONValue} from '../../../shared/src/json.ts';\nimport {must} from '../../../shared/src/must.ts';\nimport type {\n DefaultContext,\n DefaultSchema,\n DefaultWrappedTransaction,\n} from '../../../zero-types/src/default-types.ts';\nimport type {Schema} from '../../../zero-types/src/schema.ts';\nimport type {AnyTransaction, Transaction} from './custom.ts';\n\n// ----------------------------------------------------------------------------\n// defineMutator\n// ----------------------------------------------------------------------------\n\nconst defineMutatorTag = Symbol();\n\nexport function isMutatorDefinition<\n TInput extends ReadonlyJSONValue | undefined,\n TOutput extends ReadonlyJSONValue | undefined,\n TSchema extends Schema,\n TContext,\n TWrappedTransaction = unknown,\n>(\n f: unknown,\n): f is MutatorDefinition<\n TInput,\n TOutput,\n TSchema,\n TContext,\n TWrappedTransaction\n> {\n // oxlint-disable-next-line no-explicit-any\n return typeof f === 'function' && !!(f as any)[defineMutatorTag];\n}\n\nexport type MutatorDefinition<\n TInput extends ReadonlyJSONValue | undefined,\n TOutput extends ReadonlyJSONValue | undefined,\n TSchema extends Schema = DefaultSchema,\n TContext = DefaultContext,\n TWrappedTransaction = DefaultWrappedTransaction,\n> = ((options: {\n args: TOutput;\n ctx: TContext;\n tx: Transaction<TSchema, TWrappedTransaction>;\n}) => Promise<void>) & {\n [defineMutatorTag]: true;\n validator: StandardSchemaV1<TInput, TOutput> | undefined;\n};\n\n// Overload 1: Call with validator\nexport function defineMutator<\n TInput extends ReadonlyJSONValue | undefined,\n TOutput extends ReadonlyJSONValue | undefined,\n TSchema extends Schema = DefaultSchema,\n TContext = DefaultContext,\n TWrappedTransaction = DefaultWrappedTransaction,\n>(\n validator: StandardSchemaV1<TInput, TOutput>,\n mutator: (options: {\n args: TOutput;\n ctx: TContext;\n tx: Transaction<TSchema, TWrappedTransaction>;\n }) => Promise<void>,\n): MutatorDefinition<TInput, TOutput, TSchema, TContext, TWrappedTransaction>;\n\n// Overload 2: Call without validator\nexport function defineMutator<\n TArgs extends ReadonlyJSONValue | undefined,\n TSchema extends Schema = DefaultSchema,\n TContext = DefaultContext,\n TWrappedTransaction = DefaultWrappedTransaction,\n>(\n mutator: (options: {\n args: TArgs;\n ctx: TContext;\n tx: Transaction<TSchema, TWrappedTransaction>;\n }) => Promise<void>,\n): MutatorDefinition<TArgs, TArgs, TSchema, TContext, TWrappedTransaction>;\n\n// Implementation\nexport function defineMutator<\n TInput extends ReadonlyJSONValue | undefined,\n TOutput extends ReadonlyJSONValue | undefined,\n TSchema extends Schema = DefaultSchema,\n TContext = DefaultContext,\n TWrappedTransaction = DefaultWrappedTransaction,\n>(\n validatorOrMutator:\n | StandardSchemaV1<TInput, TOutput>\n | ((options: {\n args: TOutput;\n ctx: TContext;\n tx: Transaction<TSchema, TWrappedTransaction>;\n }) => Promise<void>),\n mutator?: (options: {\n args: TOutput;\n ctx: TContext;\n tx: Transaction<TSchema, TWrappedTransaction>;\n }) => Promise<void>,\n): MutatorDefinition<TInput, TOutput, TSchema, TContext, TWrappedTransaction> {\n let validator: StandardSchemaV1<TInput, TOutput> | undefined;\n let actualMutator: (options: {\n args: TOutput;\n ctx: TContext;\n tx: Transaction<TSchema, TWrappedTransaction>;\n }) => Promise<void>;\n\n if (typeof validatorOrMutator === 'function') {\n // defineMutator(mutator) - no validator\n validator = undefined;\n actualMutator = validatorOrMutator;\n } else {\n // defineMutator(validator, mutator)\n validator = validatorOrMutator;\n actualMutator = must(mutator);\n }\n\n const f = actualMutator as MutatorDefinition<\n TInput,\n TOutput,\n TSchema,\n TContext,\n TWrappedTransaction\n >;\n f[defineMutatorTag] = true;\n f.validator = validator;\n return f;\n}\n\n// ----------------------------------------------------------------------------\n// Mutator and MutationRequest types\n// ----------------------------------------------------------------------------\n\n/**\n * A callable wrapper around a MutatorDefinition, created by `defineMutators()`.\n *\n * Accessed like `mutators.foo.bar`, and called to create a MutationRequest:\n * `mutators.foo.bar(42)` returns a `MutationRequest`.\n *\n * The `fn` property is used for execution and takes raw JSON args (for rebase\n * and server wire format cases) that are validated internally.\n *\n * @template TArgsInput - The argument type accepted by the callable (before validation)\n * @template TSchema - The schema type\n * @template TContext - The context type available during mutation execution\n * @template TWrappedTransaction - The wrapped transaction type\n */\nexport type Mutator<\n TArgsInput extends ReadonlyJSONValue | undefined,\n TSchema extends Schema = DefaultSchema,\n TContext = DefaultContext,\n TWrappedTransaction = DefaultWrappedTransaction,\n> = MutatorCallable<TSchema, TContext, TArgsInput, TWrappedTransaction> & {\n readonly mutatorName: string;\n /**\n * Execute the mutation. Args are ReadonlyJSONValue because this is called\n * during rebase (from stored JSON) and on the server (from wire format).\n * Validation happens internally before the recipe function runs.\n *\n * The tx parameter uses AnyTransaction to avoid contravariance issues when\n * calling from generic code. The implementation casts to the specific type.\n */\n readonly fn: (options: {\n args: TArgsInput;\n ctx: TContext;\n tx: AnyTransaction;\n }) => Promise<void>;\n};\n\n// Helper type for the callable part of Mutator\n// When TArgsInput is undefined, the function is callable with 0 args\n// When TArgsInput includes undefined (optional), args is optional\n// Otherwise, args is required\ntype MutatorCallable<\n TSchema extends Schema,\n TContext,\n TArgsInput extends ReadonlyJSONValue | undefined,\n TWrappedTransaction,\n> = [TArgsInput] extends [undefined]\n ? () => MutationRequest<TArgsInput, TSchema, TContext, TWrappedTransaction>\n : undefined extends TArgsInput\n ? (\n args?: TArgsInput,\n ) => MutationRequest<TArgsInput, TSchema, TContext, TWrappedTransaction>\n : (\n args: TArgsInput,\n ) => MutationRequest<TArgsInput, TSchema, TContext, TWrappedTransaction>;\n\n// oxlint-disable-next-line no-explicit-any\nexport type AnyMutator = Mutator<any, Schema, any, any>;\n\n/**\n * The result of calling a Mutator with arguments.\n *\n * Created by `mutators.foo.bar(42)`, executed by `zero.mutate(mr)` on the client\n * or `mr.mutator.fn({tx, ctx, args: mr.args})` on the server.\n *\n * @template TArgsInput - The argument type (before validation, sent to server)\n * @template TSchema - The schema type\n * @template TContext - The context type available during mutation execution\n * @template TWrappedTransaction - The wrapped transaction type\n */\nexport type MutationRequest<\n TArgsInput extends ReadonlyJSONValue | undefined,\n TSchema extends Schema,\n TContext,\n TWrappedTransaction,\n> = {\n readonly mutator: Mutator<TArgsInput, TSchema, TContext, TWrappedTransaction>;\n readonly args: TArgsInput;\n};\n\n/**\n * Checks if a value is a Mutator (the result of processing a MutatorDefinition\n * through defineMutators).\n */\nexport function isMutator(value: unknown): value is AnyMutator {\n return (\n typeof value === 'function' &&\n // oxlint-disable-next-line no-explicit-any\n typeof (value as any).mutatorName === 'string' &&\n // oxlint-disable-next-line no-explicit-any\n typeof (value as any).fn === 'function'\n );\n}\n"],"names":[],"mappings":";AAeA,MAAM,mBAAmB,OAAA;AAElB,SAAS,oBAOd,GAOA;AAEA,SAAO,OAAO,MAAM,cAAc,CAAC,CAAE,EAAU,gBAAgB;AACjE;AAgDO,SAAS,cAOd,oBAOA,SAK4E;AAC5E,MAAI;AACJ,MAAI;AAMJ,MAAI,OAAO,uBAAuB,YAAY;AAE5C,gBAAY;AACZ,oBAAgB;AAAA,EAClB,OAAO;AAEL,gBAAY;AACZ,oBAAgB,KAAK,OAAO;AAAA,EAC9B;AAEA,QAAM,IAAI;AAOV,IAAE,gBAAgB,IAAI;AACtB,IAAE,YAAY;AACd,SAAO;AACT;AAyFO,SAAS,UAAU,OAAqC;AAC7D,SACE,OAAO,UAAU;AAAA,EAEjB,OAAQ,MAAc,gBAAgB;AAAA,EAEtC,OAAQ,MAAc,OAAO;AAEjC;"}
|
|
1
|
+
{"version":3,"file":"mutator.js","sources":["../../../../../zql/src/mutate/mutator.ts"],"sourcesContent":["import type {StandardSchemaV1} from '@standard-schema/spec';\nimport type {Expand} from '../../../shared/src/expand.ts';\nimport type {ReadonlyJSONValue} from '../../../shared/src/json.ts';\nimport {must} from '../../../shared/src/must.ts';\nimport type {\n DefaultContext,\n DefaultSchema,\n DefaultWrappedTransaction,\n} from '../../../zero-types/src/default-types.ts';\nimport type {Schema} from '../../../zero-types/src/schema.ts';\nimport type {AnyTransaction, Transaction} from './custom.ts';\n\n// oxlint-disable no-explicit-any\n\n// ----------------------------------------------------------------------------\n// defineMutator\n// ----------------------------------------------------------------------------\n\nexport type MutatorDefinitionTypes<\n TInput extends ReadonlyJSONValue | undefined,\n TOutput,\n TContext,\n TWrappedTransaction,\n> = 'MutatorDefinition' & {\n readonly $input: TInput;\n readonly $output: TOutput;\n readonly $context: TContext;\n readonly $wrappedTransaction: TWrappedTransaction;\n};\n\nexport function isMutatorDefinition<\n TInput extends ReadonlyJSONValue | undefined,\n TOutput extends ReadonlyJSONValue | undefined,\n TContext = DefaultContext,\n TWrappedTransaction = DefaultWrappedTransaction,\n>(\n f: unknown,\n): f is MutatorDefinition<TInput, TOutput, TContext, TWrappedTransaction> {\n return typeof f === 'function' && (f as any)['~'] === 'MutatorDefinition';\n}\n\nexport type MutatorDefinition<\n TInput extends ReadonlyJSONValue | undefined,\n TOutput extends ReadonlyJSONValue | undefined,\n TContext = DefaultContext,\n TWrappedTransaction = DefaultWrappedTransaction,\n> = ((options: {\n args: TOutput;\n ctx: TContext;\n tx: AnyTransaction;\n}) => Promise<void>) & {\n validator: StandardSchemaV1<TInput, TOutput> | undefined;\n\n /**\n * Type-only phantom property to surface mutator types in a covariant position.\n */\n ['~']: Expand<\n MutatorDefinitionTypes<TInput, TOutput, TContext, TWrappedTransaction>\n >;\n};\n\n// Overload 1: Call with validator\nexport function defineMutator<\n TInput extends ReadonlyJSONValue | undefined = undefined,\n TOutput extends ReadonlyJSONValue | undefined = TInput,\n TSchema extends Schema = DefaultSchema,\n TContext = DefaultContext,\n TWrappedTransaction = DefaultWrappedTransaction,\n>(\n validator: StandardSchemaV1<TInput, TOutput>,\n mutator: (options: {\n args: TOutput;\n ctx: TContext;\n tx: Transaction<TSchema, TWrappedTransaction>;\n }) => Promise<void>,\n): MutatorDefinition<TInput, TOutput, TContext, TWrappedTransaction>;\n\n// Overload 2: Call without validator\nexport function defineMutator<\n TInput extends ReadonlyJSONValue | undefined = ReadonlyJSONValue | undefined,\n TSchema extends Schema = DefaultSchema,\n TContext = DefaultContext,\n TWrappedTransaction = DefaultWrappedTransaction,\n>(\n mutator: (options: {\n args: TInput;\n ctx: TContext;\n tx: Transaction<TSchema, TWrappedTransaction>;\n }) => Promise<void>,\n): MutatorDefinition<TInput, TInput, TContext, TWrappedTransaction>;\n\n// Implementation\nexport function defineMutator<\n TInput extends ReadonlyJSONValue | undefined = undefined,\n TOutput extends ReadonlyJSONValue | undefined = TInput,\n TSchema extends Schema = DefaultSchema,\n TContext = DefaultContext,\n TWrappedTransaction = DefaultWrappedTransaction,\n>(\n validatorOrMutator:\n | StandardSchemaV1<TInput, TOutput>\n | ((options: {\n args: TOutput;\n ctx: TContext;\n tx: Transaction<TSchema, TWrappedTransaction>;\n }) => Promise<void>),\n mutator?: (options: {\n args: TOutput;\n ctx: TContext;\n tx: Transaction<TSchema, TWrappedTransaction>;\n }) => Promise<void>,\n): MutatorDefinition<TInput, TOutput, TContext, TWrappedTransaction> {\n let validator: StandardSchemaV1<TInput, TOutput> | undefined;\n let actualMutator: (options: {\n args: TOutput;\n ctx: TContext;\n tx: Transaction<TSchema, TWrappedTransaction>;\n }) => Promise<void>;\n\n if (typeof validatorOrMutator === 'function') {\n // defineMutator(mutator) - no validator\n validator = undefined;\n actualMutator = validatorOrMutator;\n } else {\n // defineMutator(validator, mutator)\n validator = validatorOrMutator;\n actualMutator = must(mutator);\n }\n\n const f = actualMutator as MutatorDefinition<\n TInput,\n TOutput,\n TContext,\n TWrappedTransaction\n >;\n f['~'] = 'MutatorDefinition' as unknown as MutatorDefinitionTypes<\n TInput,\n TOutput,\n TContext,\n TWrappedTransaction\n >;\n\n f.validator = validator;\n return f;\n}\n\n// intentionally not using DefaultSchema, DefaultContext, or DefaultWrappedTransaction\nexport function defineMutatorWithType<\n TSchema extends Schema,\n TContext = unknown,\n TWrappedTransaction = unknown,\n>(): TypedDefineMutator<TSchema, TContext, TWrappedTransaction> {\n return defineMutator;\n}\n\n/**\n * The return type of defineMutatorWithType. A function matching the\n * defineMutator overloads but with Schema, Context, and WrappedTransaction\n * pre-bound.\n *\n * This is used as a workaround to using DefaultTypes (e.g. when using\n * multiple Zero instances).\n */\ntype TypedDefineMutator<\n TSchema extends Schema,\n TContext,\n TWrappedTransaction,\n> = {\n // Without validator\n <TArgs extends ReadonlyJSONValue | undefined>(\n mutator: (options: {\n args: TArgs;\n ctx: TContext;\n tx: Transaction<TSchema, TWrappedTransaction>;\n }) => Promise<void>,\n ): MutatorDefinition<TArgs, TArgs, TContext, TWrappedTransaction>;\n\n // With validator\n <\n TInput extends ReadonlyJSONValue | undefined,\n TOutput extends ReadonlyJSONValue | undefined,\n >(\n validator: StandardSchemaV1<TInput, TOutput>,\n mutator: (options: {\n args: TOutput;\n ctx: TContext;\n tx: Transaction<TSchema, TWrappedTransaction>;\n }) => Promise<void>,\n ): MutatorDefinition<TInput, TOutput, TContext, TWrappedTransaction>;\n};\n\n// ----------------------------------------------------------------------------\n// Mutator and MutationRequest types\n// ----------------------------------------------------------------------------\n\n/**\n * A callable wrapper around a MutatorDefinition, created by `defineMutators()`.\n *\n * Accessed like `mutators.foo.bar`, and called to create a MutationRequest:\n * `mutators.foo.bar(42)` returns a `MutationRequest`.\n *\n * The `fn` property is used for execution and takes raw JSON args (for rebase\n * and server wire format cases) that are validated internally.\n *\n * @template TInput - The argument type accepted by the callable (before validation)\n * @template TContext - The context type available during mutation execution\n * @template TWrappedTransaction - The wrapped transaction type\n */\nexport type Mutator<\n TInput extends ReadonlyJSONValue | undefined,\n TSchema extends Schema = DefaultSchema,\n TContext = DefaultContext,\n TWrappedTransaction = DefaultWrappedTransaction,\n> = MutatorCallable<TInput, TSchema, TContext, TWrappedTransaction> & {\n readonly mutatorName: string;\n /**\n * Execute the mutation. Args are ReadonlyJSONValue because this is called\n * during rebase (from stored JSON) and on the server (from wire format).\n * Validation happens internally before the recipe function runs.\n */\n readonly fn: (options: {\n args: TInput;\n ctx: TContext;\n tx: Transaction<TSchema, TWrappedTransaction>;\n }) => Promise<void>;\n};\n\n// Helper type for the callable part of Mutator\n// When TInput is undefined, the function is callable with 0 args\n// When TInput includes undefined (optional), args is optional\n// Otherwise, args is required\ntype MutatorCallable<\n TInput extends ReadonlyJSONValue | undefined,\n TSchema extends Schema,\n TContext,\n TWrappedTransaction,\n> = [TInput] extends [undefined]\n ? () => MutationRequest<TInput, TSchema, TContext, TWrappedTransaction>\n : undefined extends TInput\n ? (\n args?: TInput,\n ) => MutationRequest<TInput, TSchema, TContext, TWrappedTransaction>\n : (\n args: TInput,\n ) => MutationRequest<TInput, TSchema, TContext, TWrappedTransaction>;\n\n// oxlint-disable-next-line no-explicit-any\nexport type AnyMutator = Mutator<any, any, any, any>;\n\n/**\n * The result of calling a Mutator with arguments.\n *\n * Created by `mutators.foo.bar(42)`, executed by `zero.mutate(mr)` on the client\n * or `mr.mutator.fn({tx, ctx, args: mr.args})` on the server.\n *\n * @template TInput - The argument type (before validation, sent to server)\n * @template TContext - The context type available during mutation execution\n * @template TWrappedTransaction - The wrapped transaction type\n */\nexport type MutationRequest<\n TInput extends ReadonlyJSONValue | undefined,\n TSchema extends Schema = DefaultSchema,\n TContext = DefaultContext,\n TWrappedTransaction = DefaultWrappedTransaction,\n> = {\n readonly mutator: Mutator<TInput, TSchema, TContext, TWrappedTransaction>;\n readonly args: TInput;\n};\n\n/**\n * Checks if a value is a Mutator (the result of processing a MutatorDefinition\n * through defineMutators).\n */\nexport function isMutator(value: unknown): value is AnyMutator {\n return (\n typeof value === 'function' &&\n // oxlint-disable-next-line no-explicit-any\n typeof (value as any).mutatorName === 'string' &&\n // oxlint-disable-next-line no-explicit-any\n typeof (value as any).fn === 'function'\n );\n}\n"],"names":[],"mappings":";AA8BO,SAAS,oBAMd,GACwE;AACxE,SAAO,OAAO,MAAM,cAAe,EAAU,GAAG,MAAM;AACxD;AAqDO,SAAS,cAOd,oBAOA,SAKmE;AACnE,MAAI;AACJ,MAAI;AAMJ,MAAI,OAAO,uBAAuB,YAAY;AAE5C,gBAAY;AACZ,oBAAgB;AAAA,EAClB,OAAO;AAEL,gBAAY;AACZ,oBAAgB,KAAK,OAAO;AAAA,EAC9B;AAEA,QAAM,IAAI;AAMV,IAAE,GAAG,IAAI;AAOT,IAAE,YAAY;AACd,SAAO;AACT;AAiIO,SAAS,UAAU,OAAqC;AAC7D,SACE,OAAO,UAAU;AAAA,EAEjB,OAAQ,MAAc,gBAAgB;AAAA,EAEtC,OAAQ,MAAc,OAAO;AAEjC;"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Schema } from '../../../zero-types/src/schema.ts';
|
|
2
|
-
import type {
|
|
2
|
+
import type { QueryDelegate } from './query-delegate.ts';
|
|
3
3
|
import type { SchemaQuery } from './schema-query.ts';
|
|
4
4
|
/**
|
|
5
5
|
* Returns a set of query builders for the given schema.
|
|
6
6
|
*/
|
|
7
7
|
export declare function createBuilder<S extends Schema>(schema: S): SchemaQuery<S>;
|
|
8
|
-
export declare function
|
|
8
|
+
export declare function createRunnableBuilder<S extends Schema>(delegate: QueryDelegate, schema: S): SchemaQuery<S>;
|
|
9
9
|
//# sourceMappingURL=create-builder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-builder.d.ts","sourceRoot":"","sources":["../../../../../zql/src/query/create-builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"create-builder.d.ts","sourceRoot":"","sources":["../../../../../zql/src/query/create-builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,mCAAmC,CAAC;AAC9D,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,qBAAqB,CAAC;AAIvD,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,mBAAmB,CAAC;AAEnD;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAIzE;AAED,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,MAAM,EACpD,QAAQ,EAAE,aAAa,EACvB,MAAM,EAAE,CAAC,GACR,WAAW,CAAC,CAAC,CAAC,CAIhB"}
|
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import { newQuery } from "./query-impl.js";
|
|
2
|
+
import { newRunnableQuery } from "./runnable-query-impl.js";
|
|
2
3
|
function createBuilder(schema) {
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
return createBuilderWithQueryFactory(
|
|
5
|
+
schema,
|
|
6
|
+
(table) => newQuery(schema, table)
|
|
7
|
+
);
|
|
8
|
+
}
|
|
9
|
+
function createRunnableBuilder(delegate, schema) {
|
|
10
|
+
return createBuilderWithQueryFactory(
|
|
11
|
+
schema,
|
|
12
|
+
(table) => newRunnableQuery(delegate, schema, table)
|
|
13
|
+
);
|
|
5
14
|
}
|
|
6
15
|
function createBuilderWithQueryFactory(schema, queryFactory) {
|
|
7
16
|
const cache = /* @__PURE__ */ new Map();
|
|
@@ -44,6 +53,6 @@ function createBuilderWithQueryFactory(schema, queryFactory) {
|
|
|
44
53
|
}
|
|
45
54
|
export {
|
|
46
55
|
createBuilder,
|
|
47
|
-
|
|
56
|
+
createRunnableBuilder
|
|
48
57
|
};
|
|
49
58
|
//# sourceMappingURL=create-builder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-builder.js","sources":["../../../../../zql/src/query/create-builder.ts"],"sourcesContent":["import type {Schema} from '../../../zero-types/src/schema.ts';\nimport {newQuery} from './query-impl.ts';\nimport type {Query} from './query.ts';\nimport type {SchemaQuery} from './schema-query.ts';\n\n/**\n * Returns a set of query builders for the given schema.\n */\nexport function createBuilder<S extends Schema>(schema: S): SchemaQuery<S> {\n
|
|
1
|
+
{"version":3,"file":"create-builder.js","sources":["../../../../../zql/src/query/create-builder.ts"],"sourcesContent":["import type {Schema} from '../../../zero-types/src/schema.ts';\nimport type {QueryDelegate} from './query-delegate.ts';\nimport {newQuery} from './query-impl.ts';\nimport type {Query} from './query.ts';\nimport {newRunnableQuery} from './runnable-query-impl.ts';\nimport type {SchemaQuery} from './schema-query.ts';\n\n/**\n * Returns a set of query builders for the given schema.\n */\nexport function createBuilder<S extends Schema>(schema: S): SchemaQuery<S> {\n return createBuilderWithQueryFactory(schema, table =>\n newQuery(schema, table),\n );\n}\n\nexport function createRunnableBuilder<S extends Schema>(\n delegate: QueryDelegate,\n schema: S,\n): SchemaQuery<S> {\n return createBuilderWithQueryFactory(schema, table =>\n newRunnableQuery(delegate, schema, table),\n );\n}\n\nfunction createBuilderWithQueryFactory<S extends Schema>(\n schema: S,\n queryFactory: (table: keyof S['tables'] & string) => Query<string, S>,\n): SchemaQuery<S> {\n const cache = new Map<string, Query<string, S>>();\n const {tables} = schema;\n\n function getQuery(prop: string) {\n const cached = cache.get(prop);\n if (cached) {\n return cached;\n }\n\n if (!Object.hasOwn(schema.tables, prop)) {\n return undefined;\n }\n\n const q = queryFactory(prop);\n cache.set(prop, q);\n return q;\n }\n\n return new Proxy(tables, {\n get: (_target, prop) => {\n if (typeof prop === 'symbol') {\n return undefined;\n }\n const q = getQuery(prop);\n if (!q) {\n throw new Error(`Table ${String(prop)} does not exist in schema`);\n }\n return q;\n },\n\n getOwnPropertyDescriptor: (_target, prop) => {\n if (typeof prop === 'symbol') {\n return undefined;\n }\n const value = getQuery(prop);\n if (!value) {\n return undefined;\n }\n const desc = Reflect.getOwnPropertyDescriptor(tables, prop);\n return {...desc, value};\n },\n }) as unknown as SchemaQuery<S>;\n}\n"],"names":[],"mappings":";;AAUO,SAAS,cAAgC,QAA2B;AACzE,SAAO;AAAA,IAA8B;AAAA,IAAQ,CAAA,UAC3C,SAAS,QAAQ,KAAK;AAAA,EAAA;AAE1B;AAEO,SAAS,sBACd,UACA,QACgB;AAChB,SAAO;AAAA,IAA8B;AAAA,IAAQ,CAAA,UAC3C,iBAAiB,UAAU,QAAQ,KAAK;AAAA,EAAA;AAE5C;AAEA,SAAS,8BACP,QACA,cACgB;AAChB,QAAM,4BAAY,IAAA;AAClB,QAAM,EAAC,WAAU;AAEjB,WAAS,SAAS,MAAc;AAC9B,UAAM,SAAS,MAAM,IAAI,IAAI;AAC7B,QAAI,QAAQ;AACV,aAAO;AAAA,IACT;AAEA,QAAI,CAAC,OAAO,OAAO,OAAO,QAAQ,IAAI,GAAG;AACvC,aAAO;AAAA,IACT;AAEA,UAAM,IAAI,aAAa,IAAI;AAC3B,UAAM,IAAI,MAAM,CAAC;AACjB,WAAO;AAAA,EACT;AAEA,SAAO,IAAI,MAAM,QAAQ;AAAA,IACvB,KAAK,CAAC,SAAS,SAAS;AACtB,UAAI,OAAO,SAAS,UAAU;AAC5B,eAAO;AAAA,MACT;AACA,YAAM,IAAI,SAAS,IAAI;AACvB,UAAI,CAAC,GAAG;AACN,cAAM,IAAI,MAAM,SAAS,OAAO,IAAI,CAAC,2BAA2B;AAAA,MAClE;AACA,aAAO;AAAA,IACT;AAAA,IAEA,0BAA0B,CAAC,SAAS,SAAS;AAC3C,UAAI,OAAO,SAAS,UAAU;AAC5B,eAAO;AAAA,MACT;AACA,YAAM,QAAQ,SAAS,IAAI;AAC3B,UAAI,CAAC,OAAO;AACV,eAAO;AAAA,MACT;AACA,YAAM,OAAO,QAAQ,yBAAyB,QAAQ,IAAI;AAC1D,aAAO,EAAC,GAAG,MAAM,MAAA;AAAA,IACnB;AAAA,EAAA,CACD;AACH;"}
|
|
@@ -10,7 +10,6 @@ export declare class MeasurePushOperator implements Operator {
|
|
|
10
10
|
constructor(input: Input, queryID: string, metricsDelegate: MetricsDelegate, metricName: MetricName);
|
|
11
11
|
setOutput(output: Output): void;
|
|
12
12
|
fetch(req: FetchRequest): Stream<Node | 'yield'>;
|
|
13
|
-
cleanup(req: FetchRequest): Stream<Node>;
|
|
14
13
|
getSchema(): SourceSchema;
|
|
15
14
|
destroy(): void;
|
|
16
15
|
push(change: Change): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"measure-push-operator.d.ts","sourceRoot":"","sources":["../../../../../zql/src/query/measure-push-operator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,KAAK,EACV,KAAK,QAAQ,EACb,KAAK,MAAM,EACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,uBAAuB,CAAC;AAE3D,KAAK,UAAU,GAAG,qBAAqB,GAAG,qBAAqB,CAAC;AAEhE,qBAAa,mBAAoB,YAAW,QAAQ;;gBAShD,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,MAAM,EACf,eAAe,EAAE,eAAe,EAChC,UAAU,EAAE,UAAU;IASxB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI/B,KAAK,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC;IAIhD,
|
|
1
|
+
{"version":3,"file":"measure-push-operator.d.ts","sourceRoot":"","sources":["../../../../../zql/src/query/measure-push-operator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,KAAK,EACV,KAAK,QAAQ,EACb,KAAK,MAAM,EACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,uBAAuB,CAAC;AAE3D,KAAK,UAAU,GAAG,qBAAqB,GAAG,qBAAqB,CAAC;AAEhE,qBAAa,mBAAoB,YAAW,QAAQ;;gBAShD,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,MAAM,EACf,eAAe,EAAE,eAAe,EAChC,UAAU,EAAE,UAAU;IASxB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI/B,KAAK,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC;IAIhD,SAAS,IAAI,YAAY;IAIzB,OAAO,IAAI,IAAI;IAIf,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;CAS3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"measure-push-operator.js","sources":["../../../../../zql/src/query/measure-push-operator.ts"],"sourcesContent":["import type {Change} from '../ivm/change.ts';\nimport type {Node} from '../ivm/data.ts';\nimport {\n throwOutput,\n type FetchRequest,\n type Input,\n type Operator,\n type Output,\n} from '../ivm/operator.ts';\nimport type {SourceSchema} from '../ivm/schema.ts';\nimport type {Stream} from '../ivm/stream.ts';\nimport type {MetricsDelegate} from './metrics-delegate.ts';\n\ntype MetricName = 'query-update-client' | 'query-update-server';\n\nexport class MeasurePushOperator implements Operator {\n readonly #input: Input;\n readonly #queryID: string;\n readonly #metricsDelegate: MetricsDelegate;\n\n #output: Output = throwOutput;\n readonly #metricName: MetricName;\n\n constructor(\n input: Input,\n queryID: string,\n metricsDelegate: MetricsDelegate,\n metricName: MetricName,\n ) {\n this.#input = input;\n this.#queryID = queryID;\n this.#metricsDelegate = metricsDelegate;\n this.#metricName = metricName;\n input.setOutput(this);\n }\n\n setOutput(output: Output): void {\n this.#output = output;\n }\n\n fetch(req: FetchRequest): Stream<Node | 'yield'> {\n return this.#input.fetch(req);\n }\n\n
|
|
1
|
+
{"version":3,"file":"measure-push-operator.js","sources":["../../../../../zql/src/query/measure-push-operator.ts"],"sourcesContent":["import type {Change} from '../ivm/change.ts';\nimport type {Node} from '../ivm/data.ts';\nimport {\n throwOutput,\n type FetchRequest,\n type Input,\n type Operator,\n type Output,\n} from '../ivm/operator.ts';\nimport type {SourceSchema} from '../ivm/schema.ts';\nimport type {Stream} from '../ivm/stream.ts';\nimport type {MetricsDelegate} from './metrics-delegate.ts';\n\ntype MetricName = 'query-update-client' | 'query-update-server';\n\nexport class MeasurePushOperator implements Operator {\n readonly #input: Input;\n readonly #queryID: string;\n readonly #metricsDelegate: MetricsDelegate;\n\n #output: Output = throwOutput;\n readonly #metricName: MetricName;\n\n constructor(\n input: Input,\n queryID: string,\n metricsDelegate: MetricsDelegate,\n metricName: MetricName,\n ) {\n this.#input = input;\n this.#queryID = queryID;\n this.#metricsDelegate = metricsDelegate;\n this.#metricName = metricName;\n input.setOutput(this);\n }\n\n setOutput(output: Output): void {\n this.#output = output;\n }\n\n fetch(req: FetchRequest): Stream<Node | 'yield'> {\n return this.#input.fetch(req);\n }\n\n getSchema(): SourceSchema {\n return this.#input.getSchema();\n }\n\n destroy(): void {\n this.#input.destroy();\n }\n\n push(change: Change): void {\n const startTime = performance.now();\n this.#output.push(change, this);\n this.#metricsDelegate.addMetric(\n this.#metricName,\n performance.now() - startTime,\n this.#queryID,\n );\n }\n}\n"],"names":[],"mappings":";AAeO,MAAM,oBAAwC;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AAAA,EAET,UAAkB;AAAA,EACT;AAAA,EAET,YACE,OACA,SACA,iBACA,YACA;AACA,SAAK,SAAS;AACd,SAAK,WAAW;AAChB,SAAK,mBAAmB;AACxB,SAAK,cAAc;AACnB,UAAM,UAAU,IAAI;AAAA,EACtB;AAAA,EAEA,UAAU,QAAsB;AAC9B,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,MAAM,KAA2C;AAC/C,WAAO,KAAK,OAAO,MAAM,GAAG;AAAA,EAC9B;AAAA,EAEA,YAA0B;AACxB,WAAO,KAAK,OAAO,UAAA;AAAA,EACrB;AAAA,EAEA,UAAgB;AACd,SAAK,OAAO,QAAA;AAAA,EACd;AAAA,EAEA,KAAK,QAAsB;AACzB,UAAM,YAAY,YAAY,IAAA;AAC9B,SAAK,QAAQ,KAAK,QAAQ,IAAI;AAC9B,SAAK,iBAAiB;AAAA,MACpB,KAAK;AAAA,MACL,YAAY,QAAQ;AAAA,MACpB,KAAK;AAAA,IAAA;AAAA,EAET;AACF;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-internals.d.ts","sourceRoot":"","sources":["../../../../../zql/src/query/query-internals.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,mCAAmC,CAAC;AAC3D,OAAO,KAAK,EAAC,MAAM,IAAI,UAAU,EAAC,MAAM,mCAAmC,CAAC;AAC5E,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAAC,KAAK,EAAC,MAAM,YAAY,CAAC;AAEtC,eAAO,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"query-internals.d.ts","sourceRoot":"","sources":["../../../../../zql/src/query/query-internals.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,mCAAmC,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C/C,OAAO,SAAS,UAAU,EAC1B,OAAO,EACP,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAE/D;AAED,wBAAgB,OAAO,CACrB,MAAM,SAAS,MAAM,OAAO,CAAC,QAAQ,CAAC,GAAG,MAAM,EAC/C,OAAO,SAAS,UAAU,EAC1B,OAAO,EAEP,cAAc,EAAE,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,GACvD,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAGjC;AAGD,MAAM,MAAM,iBAAiB,GAAG,cAAc,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { assert } from "../../../shared/src/asserts.js";
|
|
2
|
-
const queryInternalsTag = Symbol(
|
|
2
|
+
const queryInternalsTag = Symbol();
|
|
3
3
|
function asQueryInternals(query) {
|
|
4
|
-
assert(queryInternalsTag in query);
|
|
4
|
+
assert(queryInternalsTag in query, "Query does not implement QueryInternals");
|
|
5
5
|
return query;
|
|
6
6
|
}
|
|
7
7
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-internals.js","sources":["../../../../../zql/src/query/query-internals.ts"],"sourcesContent":["import {assert} from '../../../shared/src/asserts.ts';\nimport type {ReadonlyJSONValue} from '../../../shared/src/json.ts';\nimport type {AST} from '../../../zero-protocol/src/ast.ts';\nimport type {Schema as ZeroSchema} from '../../../zero-types/src/schema.ts';\nimport type {Format} from '../ivm/view.ts';\nimport type {CustomQueryID} from './named.ts';\nimport type {Query} from './query.ts';\n\nexport const queryInternalsTag = Symbol(
|
|
1
|
+
{"version":3,"file":"query-internals.js","sources":["../../../../../zql/src/query/query-internals.ts"],"sourcesContent":["import {assert} from '../../../shared/src/asserts.ts';\nimport type {ReadonlyJSONValue} from '../../../shared/src/json.ts';\nimport type {AST} from '../../../zero-protocol/src/ast.ts';\nimport type {Schema as ZeroSchema} from '../../../zero-types/src/schema.ts';\nimport type {Format} from '../ivm/view.ts';\nimport type {CustomQueryID} from './named.ts';\nimport type {Query} from './query.ts';\n\nexport const queryInternalsTag = Symbol();\n\n/**\n * Internal interface for query implementation details.\n * This is not part of the public API and should only be accessed via\n * the {@linkcode asQueryInternals} function.\n *\n * @typeParam TSchema The database schema type extending ZeroSchema\n * @typeParam TTable The name of the table being queried, must be a key of TSchema['tables']\n * @typeParam TReturn The return type of the query, defaults to PullRow<TTable, TSchema>\n */\nexport interface QueryInternals<\n TTable extends keyof TSchema['tables'] & string,\n TSchema extends ZeroSchema,\n TReturn,\n> {\n readonly [queryInternalsTag]: true;\n\n /**\n * Format is used to specify the shape of the query results. This is used by\n * {@linkcode one} and it also describes the shape when using\n * {@linkcode related}.\n */\n readonly format: Format;\n\n /**\n * A string that uniquely identifies this query. This can be used to determine\n * if two queries are the same.\n *\n * The hash of a custom query, on the client, is the hash of its AST.\n * The hash of a custom query, on the server, is the hash of its name and args.\n *\n * The first allows many client-side queries to be pinned to the same backend query.\n * The second ensures we do not invoke a named query on the backend more than once for the same `name:arg` pairing.\n *\n * If the query.hash was of `name:args` then `useQuery` would de-dupe\n * queries with divergent ASTs.\n *\n * QueryManager will hash based on `name:args` since it is speaking with\n * the server which tracks queries by `name:args`.\n */\n hash(): string;\n\n /**\n * The completed AST for this query, with any missing primary keys added to\n * orderBy and start.\n */\n readonly ast: AST;\n\n readonly customQueryID: CustomQueryID | undefined;\n\n /**\n * Associates a name and arguments with this query for custom query tracking.\n * This is used internally to track named queries on the server.\n *\n * @internal\n */\n nameAndArgs(\n name: string,\n args: ReadonlyArray<ReadonlyJSONValue>,\n ): Query<TTable, TSchema, TReturn>;\n}\n\n/**\n * Helper function to cast a Query to QueryInternals.\n * This is used in tests and internal code to access query implementation details.\n * The function asserts that the query has the queryInternalsTag to ensure it\n * properly implements the QueryInternals interface.\n *\n * @internal\n */\nexport function asQueryInternals<\n TTable extends keyof TSchema['tables'] & string,\n TSchema extends ZeroSchema,\n TReturn,\n>(\n query: Query<TTable, TSchema, TReturn>,\n): QueryInternals<TTable, TSchema, TReturn> {\n assert(queryInternalsTag in query, 'Query does not implement QueryInternals');\n return query as unknown as QueryInternals<TTable, TSchema, TReturn>;\n}\n\nexport function isQueryInternals<\n TTable extends keyof TSchema['tables'] & string,\n TSchema extends ZeroSchema,\n TReturn,\n>(obj: unknown): obj is QueryInternals<TTable, TSchema, TReturn> {\n return typeof obj === 'object' && obj !== null && queryInternalsTag in obj;\n}\n\nexport function asQuery<\n TTable extends keyof TSchema['tables'] & string,\n TSchema extends ZeroSchema,\n TReturn,\n>(\n queryInternals: QueryInternals<TTable, TSchema, TReturn>,\n): Query<TTable, TSchema, TReturn> {\n assert(queryInternalsTag in queryInternals);\n return queryInternals as unknown as Query<TTable, TSchema, TReturn>;\n}\n\n// oxlint-disable-next-line no-explicit-any\nexport type AnyQueryInternals = QueryInternals<string, ZeroSchema, any>;\n"],"names":[],"mappings":";AAQO,MAAM,oBAAoB,OAAA;AAuE1B,SAAS,iBAKd,OAC0C;AAC1C,SAAO,qBAAqB,OAAO,yCAAyC;AAC5E,SAAO;AACT;"}
|