@rocicorp/zero 0.25.0-canary.15 → 0.25.0-canary.18

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.
Files changed (100) hide show
  1. package/out/shared/src/deep-merge.d.ts +6 -4
  2. package/out/shared/src/deep-merge.d.ts.map +1 -1
  3. package/out/shared/src/deep-merge.js +2 -1
  4. package/out/shared/src/deep-merge.js.map +1 -1
  5. package/out/z2s/src/compiler.d.ts.map +1 -1
  6. package/out/z2s/src/compiler.js +4 -2
  7. package/out/z2s/src/compiler.js.map +1 -1
  8. package/out/zero/package.json.js +1 -1
  9. package/out/zero/src/pg.js +4 -3
  10. package/out/zero/src/server.js +4 -3
  11. package/out/zero/src/zero.js +11 -3
  12. package/out/zero/src/zero.js.map +1 -1
  13. package/out/zero-cache/src/config/zero-config.d.ts +8 -0
  14. package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
  15. package/out/zero-cache/src/config/zero-config.js +16 -0
  16. package/out/zero-cache/src/config/zero-config.js.map +1 -1
  17. package/out/zero-cache/src/server/otel-diag-logger.d.ts.map +1 -1
  18. package/out/zero-cache/src/server/otel-diag-logger.js +1 -22
  19. package/out/zero-cache/src/server/otel-diag-logger.js.map +1 -1
  20. package/out/zero-cache/src/services/litestream/commands.js +3 -2
  21. package/out/zero-cache/src/services/litestream/commands.js.map +1 -1
  22. package/out/zero-client/src/client/crud-impl.d.ts +11 -0
  23. package/out/zero-client/src/client/crud-impl.d.ts.map +1 -0
  24. package/out/zero-client/src/client/crud-impl.js +102 -0
  25. package/out/zero-client/src/client/crud-impl.js.map +1 -0
  26. package/out/zero-client/src/client/crud.d.ts +4 -37
  27. package/out/zero-client/src/client/crud.d.ts.map +1 -1
  28. package/out/zero-client/src/client/crud.js +18 -114
  29. package/out/zero-client/src/client/crud.js.map +1 -1
  30. package/out/zero-client/src/client/custom.d.ts +2 -2
  31. package/out/zero-client/src/client/custom.d.ts.map +1 -1
  32. package/out/zero-client/src/client/custom.js +5 -43
  33. package/out/zero-client/src/client/custom.js.map +1 -1
  34. package/out/zero-client/src/client/make-replicache-mutators.d.ts.map +1 -1
  35. package/out/zero-client/src/client/make-replicache-mutators.js +4 -1
  36. package/out/zero-client/src/client/make-replicache-mutators.js.map +1 -1
  37. package/out/zero-client/src/client/version.js +1 -1
  38. package/out/zero-client/src/client/zero.d.ts +9 -7
  39. package/out/zero-client/src/client/zero.d.ts.map +1 -1
  40. package/out/zero-client/src/client/zero.js +10 -3
  41. package/out/zero-client/src/client/zero.js.map +1 -1
  42. package/out/zero-client/src/mod.d.ts +7 -6
  43. package/out/zero-client/src/mod.d.ts.map +1 -1
  44. package/out/zero-react/src/use-query.d.ts +6 -4
  45. package/out/zero-react/src/use-query.d.ts.map +1 -1
  46. package/out/zero-react/src/use-query.js +2 -1
  47. package/out/zero-react/src/use-query.js.map +1 -1
  48. package/out/zero-server/src/custom.d.ts +44 -5
  49. package/out/zero-server/src/custom.d.ts.map +1 -1
  50. package/out/zero-server/src/custom.js +96 -17
  51. package/out/zero-server/src/custom.js.map +1 -1
  52. package/out/zero-server/src/zql-database.d.ts +1 -1
  53. package/out/zero-server/src/zql-database.d.ts.map +1 -1
  54. package/out/zero-server/src/zql-database.js +5 -13
  55. package/out/zero-server/src/zql-database.js.map +1 -1
  56. package/out/zero-solid/src/solid-view.d.ts +6 -1
  57. package/out/zero-solid/src/solid-view.d.ts.map +1 -1
  58. package/out/zero-solid/src/solid-view.js +1 -32
  59. package/out/zero-solid/src/solid-view.js.map +1 -1
  60. package/out/zero-solid/src/use-query.d.ts +5 -3
  61. package/out/zero-solid/src/use-query.d.ts.map +1 -1
  62. package/out/zero-solid/src/use-query.js +5 -1
  63. package/out/zero-solid/src/use-query.js.map +1 -1
  64. package/out/zql/src/mutate/crud.d.ts +139 -0
  65. package/out/zql/src/mutate/crud.d.ts.map +1 -0
  66. package/out/zql/src/mutate/crud.js +53 -0
  67. package/out/zql/src/mutate/crud.js.map +1 -0
  68. package/out/zql/src/mutate/custom.d.ts +12 -53
  69. package/out/zql/src/mutate/custom.d.ts.map +1 -1
  70. package/out/zql/src/mutate/custom.js +1 -5
  71. package/out/zql/src/mutate/custom.js.map +1 -1
  72. package/out/zql/src/mutate/mutator-registry.d.ts +33 -32
  73. package/out/zql/src/mutate/mutator-registry.d.ts.map +1 -1
  74. package/out/zql/src/mutate/mutator-registry.js +25 -25
  75. package/out/zql/src/mutate/mutator-registry.js.map +1 -1
  76. package/out/zql/src/mutate/mutator.d.ts +42 -62
  77. package/out/zql/src/mutate/mutator.d.ts.map +1 -1
  78. package/out/zql/src/mutate/mutator.js +12 -8
  79. package/out/zql/src/mutate/mutator.js.map +1 -1
  80. package/out/zql/src/query/abstract-query.d.ts +2 -3
  81. package/out/zql/src/query/abstract-query.d.ts.map +1 -1
  82. package/out/zql/src/query/abstract-query.js +0 -3
  83. package/out/zql/src/query/abstract-query.js.map +1 -1
  84. package/out/zql/src/query/query-impl.d.ts +2 -2
  85. package/out/zql/src/query/query-impl.d.ts.map +1 -1
  86. package/out/zql/src/query/query-impl.js.map +1 -1
  87. package/out/zql/src/query/query-registry.d.ts +87 -79
  88. package/out/zql/src/query/query-registry.d.ts.map +1 -1
  89. package/out/zql/src/query/query-registry.js +44 -38
  90. package/out/zql/src/query/query-registry.js.map +1 -1
  91. package/out/zql/src/query/query.d.ts +3 -18
  92. package/out/zql/src/query/query.d.ts.map +1 -1
  93. package/out/zql/src/query/runnable-query-impl.d.ts +2 -2
  94. package/out/zql/src/query/runnable-query-impl.d.ts.map +1 -1
  95. package/out/zql/src/query/runnable-query-impl.js.map +1 -1
  96. package/out/zql/src/query/static-query.d.ts +1 -0
  97. package/out/zql/src/query/static-query.d.ts.map +1 -1
  98. package/out/zql/src/query/static-query.js +2 -2
  99. package/out/zql/src/query/static-query.js.map +1 -1
  100. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"custom.js","sources":["../../../../../zql/src/mutate/custom.ts"],"sourcesContent":["import {assert} from '../../../shared/src/asserts.ts';\nimport type {Expand} from '../../../shared/src/expand.ts';\nimport type {AST} from '../../../zero-protocol/src/ast.ts';\nimport type {\n DefaultSchema,\n DefaultWrappedTransaction,\n} from '../../../zero-types/src/default-types.ts';\nimport type {SchemaValueToTSType} from '../../../zero-types/src/schema-value.ts';\nimport type {Schema, TableSchema} from '../../../zero-types/src/schema.ts';\nimport type {ServerSchema} from '../../../zero-types/src/server-schema.ts';\nimport type {Format} from '../ivm/view.ts';\nimport type {HumanReadable, Query, RunOptions} from '../query/query.ts';\nimport type {SchemaQuery} from '../query/schema-query.ts';\n\ntype ClientID = string;\n\n/**\n * A base transaction interface that any Transaction<S, T> is assignable to.\n * Used in places where the schema type doesn't need to be preserved,\n * like the public signature of Mutator.fn.\n */\nexport interface AnyTransaction {\n readonly location: Location;\n readonly clientID: string;\n readonly mutationID: number;\n readonly reason: TransactionReason;\n}\n\nexport type Location = 'client' | 'server';\nexport type TransactionReason = 'optimistic' | 'rebase' | 'authoritative';\n\nexport interface TransactionBase<S extends Schema> {\n readonly location: Location;\n readonly clientID: ClientID;\n /**\n * The ID of the mutation that is being applied.\n */\n readonly mutationID: number;\n\n /**\n * The reason for the transaction.\n */\n readonly reason: TransactionReason;\n\n readonly mutate: SchemaCRUD<S>;\n readonly query: SchemaQuery<S>;\n\n run<TTable extends keyof S['tables'] & string, TReturn>(\n query: Query<TTable, S, TReturn>,\n options?: RunOptions,\n ): Promise<HumanReadable<TReturn>>;\n}\n\nexport type Transaction<\n S extends Schema = DefaultSchema,\n TWrappedTransaction = DefaultWrappedTransaction,\n> = ServerTransaction<S, TWrappedTransaction> | ClientTransaction<S>;\n\nexport interface ServerTransaction<\n S extends Schema = DefaultSchema,\n TWrappedTransaction = DefaultWrappedTransaction,\n> extends TransactionBase<S> {\n readonly location: 'server';\n readonly reason: 'authoritative';\n readonly dbTransaction: DBTransaction<TWrappedTransaction>;\n}\n\n/**\n * An instance of this is passed to custom mutator implementations and\n * allows reading and writing to the database and IVM at the head at which the\n * mutator is being applied.\n */\nexport interface ClientTransaction<S extends Schema = DefaultSchema>\n extends TransactionBase<S> {\n readonly location: 'client';\n readonly reason: 'optimistic' | 'rebase';\n}\n\nexport interface Row {\n [column: string]: unknown;\n}\n\nexport interface DBConnection<TWrappedTransaction> {\n transaction: <T>(\n cb: (tx: DBTransaction<TWrappedTransaction>) => Promise<T>,\n ) => Promise<T>;\n}\n\nexport interface DBTransaction<T> extends Queryable {\n readonly wrappedTransaction: T;\n runQuery<TReturn>(\n ast: AST,\n format: Format,\n schema: Schema,\n serverSchema: ServerSchema,\n ): Promise<HumanReadable<TReturn>>;\n}\n\ninterface Queryable {\n query: (query: string, args: unknown[]) => Promise<Iterable<Row>>;\n}\n\nexport type SchemaCRUD<S extends Schema> = {\n [Table in keyof S['tables']]: TableCRUD<S['tables'][Table]>;\n};\n\nexport type TableCRUD<S extends TableSchema> = {\n /**\n * Writes a row if a row with the same primary key doesn't already exists.\n * Non-primary-key fields that are 'optional' can be omitted or set to\n * `undefined`. Such fields will be assigned the value `null` optimistically\n * and then the default value as defined by the server.\n */\n insert: (value: InsertValue<S>) => Promise<void>;\n\n /**\n * Writes a row unconditionally, overwriting any existing row with the same\n * primary key. Non-primary-key fields that are 'optional' can be omitted or\n * set to `undefined`. Such fields will be assigned the value `null`\n * optimistically and then the default value as defined by the server.\n */\n upsert: (value: UpsertValue<S>) => Promise<void>;\n\n /**\n * Updates a row with the same primary key. If no such row exists, this\n * function does nothing. All non-primary-key fields can be omitted or set to\n * `undefined`. Such fields will be left unchanged from previous value.\n */\n update: (value: UpdateValue<S>) => Promise<void>;\n\n /**\n * Deletes the row with the specified primary key. If no such row exists, this\n * function does nothing.\n */\n delete: (id: DeleteID<S>) => Promise<void>;\n};\n\nexport type DeleteID<S extends TableSchema> = Expand<PrimaryKeyFields<S>>;\n\ntype PrimaryKeyFields<S extends TableSchema> = {\n [K in Extract<\n S['primaryKey'][number],\n keyof S['columns']\n >]: SchemaValueToTSType<S['columns'][K]>;\n};\n\nexport type InsertValue<S extends TableSchema> = Expand<\n PrimaryKeyFields<S> & {\n [K in keyof S['columns'] as S['columns'][K] extends {optional: true}\n ? K\n : never]?: SchemaValueToTSType<S['columns'][K]> | undefined;\n } & {\n [K in keyof S['columns'] as S['columns'][K] extends {optional: true}\n ? never\n : K]: SchemaValueToTSType<S['columns'][K]>;\n }\n>;\n\nexport type UpsertValue<S extends TableSchema> = InsertValue<S>;\n\nexport type UpdateValue<S extends TableSchema> = Expand<\n PrimaryKeyFields<S> & {\n [K in keyof S['columns']]?:\n | SchemaValueToTSType<S['columns'][K]>\n | undefined;\n }\n>;\n\nexport function customMutatorKey(sep: string, parts: string[]) {\n for (const part of parts) {\n assert(\n !part.includes(sep),\n `mutator names/namespaces must not include a ${sep}`,\n );\n }\n return parts.join(sep);\n}\n\nexport function splitMutatorKey(key: string, sep: string | RegExp): string[] {\n return key.split(sep);\n}\n"],"names":[],"mappings":";AAwKO,SAAS,iBAAiB,KAAa,OAAiB;AAC7D,aAAW,QAAQ,OAAO;AACxB;AAAA,MACE,CAAC,KAAK,SAAS,GAAG;AAAA,MAClB,+CAA+C,GAAG;AAAA,IAAA;AAAA,EAEtD;AACA,SAAO,MAAM,KAAK,GAAG;AACvB;AAEO,SAAS,gBAAgB,KAAa,KAAgC;AAC3E,SAAO,IAAI,MAAM,GAAG;AACtB;"}
1
+ {"version":3,"file":"custom.js","sources":["../../../../../zql/src/mutate/custom.ts"],"sourcesContent":["import {assert} from '../../../shared/src/asserts.ts';\nimport type {AST} from '../../../zero-protocol/src/ast.ts';\nimport type {\n DefaultSchema,\n DefaultWrappedTransaction,\n} from '../../../zero-types/src/default-types.ts';\nimport type {Schema} from '../../../zero-types/src/schema.ts';\nimport type {ServerSchema} from '../../../zero-types/src/server-schema.ts';\nimport type {Format} from '../ivm/view.ts';\nimport type {HumanReadable, Query, RunOptions} from '../query/query.ts';\nimport type {SchemaQuery} from '../query/schema-query.ts';\nimport type {CRUDMutateRequest, SchemaCRUD} from './crud.ts';\nexport type {\n DeleteID,\n InsertValue,\n SchemaCRUD,\n TableCRUD,\n UpdateValue,\n UpsertValue,\n} from './crud.ts';\n\ntype ClientID = string;\n\n/**\n * A base transaction interface that any Transaction<S, T> is assignable to.\n * Used in places where the schema type doesn't need to be preserved,\n * like the public signature of Mutator.fn.\n */\nexport interface AnyTransaction {\n readonly location: Location;\n readonly clientID: string;\n readonly mutationID: number;\n readonly reason: TransactionReason;\n}\n\nexport type Location = 'client' | 'server';\nexport type TransactionReason = 'optimistic' | 'rebase' | 'authoritative';\n\nexport interface TransactionBase<S extends Schema> {\n readonly location: Location;\n readonly clientID: ClientID;\n /**\n * The ID of the mutation that is being applied.\n */\n readonly mutationID: number;\n\n /**\n * The reason for the transaction.\n */\n readonly reason: TransactionReason;\n\n readonly mutate: MutateCRUD<S>;\n readonly query: SchemaQuery<S>;\n\n run<TTable extends keyof S['tables'] & string, TReturn>(\n query: Query<TTable, S, TReturn>,\n options?: RunOptions,\n ): Promise<HumanReadable<TReturn>>;\n}\n\nexport type Transaction<\n S extends Schema = DefaultSchema,\n TWrappedTransaction = DefaultWrappedTransaction,\n> = ServerTransaction<S, TWrappedTransaction> | ClientTransaction<S>;\n\nexport interface ServerTransaction<\n S extends Schema = DefaultSchema,\n TWrappedTransaction = DefaultWrappedTransaction,\n> extends TransactionBase<S> {\n readonly location: 'server';\n readonly reason: 'authoritative';\n readonly dbTransaction: DBTransaction<TWrappedTransaction>;\n}\n\n/**\n * An instance of this is passed to custom mutator implementations and\n * allows reading and writing to the database and IVM at the head at which the\n * mutator is being applied.\n */\nexport interface ClientTransaction<S extends Schema = DefaultSchema>\n extends TransactionBase<S> {\n readonly location: 'client';\n readonly reason: 'optimistic' | 'rebase';\n}\n\nexport interface Row {\n [column: string]: unknown;\n}\n\nexport interface DBConnection<TWrappedTransaction> {\n transaction: <T>(\n cb: (tx: DBTransaction<TWrappedTransaction>) => Promise<T>,\n ) => Promise<T>;\n}\n\nexport interface DBTransaction<T> extends Queryable {\n readonly wrappedTransaction: T;\n runQuery<TReturn>(\n ast: AST,\n format: Format,\n schema: Schema,\n serverSchema: ServerSchema,\n ): Promise<HumanReadable<TReturn>>;\n}\n\ninterface Queryable {\n query: (query: string, args: unknown[]) => Promise<Iterable<Row>>;\n}\n\n/**\n * The type of `tx.mutate` which is:\n * 1. A callable function that accepts a `CRUDMutateRequest`\n * 2. When `enableLegacyMutators` is true, also an object with CRUD methods per table\n */\nexport type MutateCRUD<S extends Schema> = {\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n (request: CRUDMutateRequest<S, any, any, any>): Promise<void>;\n} & (S['enableLegacyMutators'] extends true ? SchemaCRUD<S> : {});\n\nexport function customMutatorKey(sep: string, parts: string[]) {\n for (const part of parts) {\n assert(\n !part.includes(sep),\n `mutator names/namespaces must not include a ${sep}`,\n );\n }\n return parts.join(sep);\n}\n"],"names":[],"mappings":";AAuHO,SAAS,iBAAiB,KAAa,OAAiB;AAC7D,aAAW,QAAQ,OAAO;AACxB;AAAA,MACE,CAAC,KAAK,SAAS,GAAG;AAAA,MAClB,+CAA+C,GAAG;AAAA,IAAA;AAAA,EAEtD;AACA,SAAO,MAAM,KAAK,GAAG;AACvB;"}
@@ -2,7 +2,7 @@ import { type DeepMerge } from '../../../shared/src/deep-merge.ts';
2
2
  import type { ReadonlyJSONValue } from '../../../shared/src/json.ts';
3
3
  import type { DefaultSchema } from '../../../zero-types/src/default-types.ts';
4
4
  import type { Schema } from '../../../zero-types/src/schema.ts';
5
- import { type AnyMutator, type Mutator, type MutatorDefinition } from './mutator.ts';
5
+ import { type AnyMutator, type AnyMutatorDefinition, type Mutator } from './mutator.ts';
6
6
  /**
7
7
  * Creates a MutatorRegistry from a tree of MutatorDefinitions,
8
8
  * optionally extending a base MutatorRegistry.
@@ -42,21 +42,7 @@ import { type AnyMutator, type Mutator, type MutatorDefinition } from './mutator
42
42
  * ```
43
43
  */
44
44
  export declare function defineMutators<const MD, S extends Schema = DefaultSchema>(definitions: MD & AssertMutatorDefinitions<MD>): MutatorRegistry<EnsureMutatorDefinitions<MD>, S>;
45
- export declare function defineMutators<const TBase, const TOverrides, S extends Schema = DefaultSchema>(base: MutatorRegistry<EnsureMutatorDefinitions<TBase>, S> | (TBase & AssertMutatorDefinitions<TBase>), overrides: TOverrides & AssertMutatorDefinitions<TOverrides>): MutatorRegistry<DeepMerge<EnsureMutatorDefinitions<TBase>, EnsureMutatorDefinitions<TOverrides>>, S>;
46
- /**
47
- * Gets a Mutator by its dot-separated name from a MutatorRegistry.
48
- * Returns undefined if not found.
49
- */
50
- export declare function getMutator<MD extends AnyMutatorDefinitions, TSchema extends Schema = DefaultSchema>(registry: MutatorRegistry<MD, TSchema>, name: string): FromMutatorTree<MD, TSchema> | undefined;
51
- /**
52
- * Gets a Mutator by its dot-separated name from a MutatorRegistry.
53
- * Throws if not found.
54
- */
55
- export declare function mustGetMutator<MD extends AnyMutatorDefinitions, TSchema extends Schema = DefaultSchema>(registry: MutatorRegistry<MD, TSchema>, name: string): FromMutatorTree<MD, TSchema>;
56
- /**
57
- * Checks if a value is a MutatorRegistry.
58
- */
59
- export declare function isMutatorRegistry<MD extends AnyMutatorDefinitions, TSchema extends Schema = DefaultSchema>(value: unknown): value is MutatorRegistry<MD, TSchema>;
45
+ export declare function defineMutators<const TBase, const TOverrides, S extends Schema = DefaultSchema>(base: MutatorRegistry<EnsureMutatorDefinitions<TBase>, S> | (TBase & AssertMutatorDefinitions<TBase>), overrides: TOverrides & AssertMutatorDefinitions<TOverrides>): MutatorRegistry<DeepMerge<EnsureMutatorDefinitions<TBase>, EnsureMutatorDefinitions<TOverrides>, AnyMutatorDefinition>, S>;
60
46
  /**
61
47
  * Creates a function that can be used to define mutators with a specific schema.
62
48
  */
@@ -67,22 +53,22 @@ export declare function defineMutatorsWithType<TSchema extends Schema>(): TypedD
67
53
  */
68
54
  type TypedDefineMutators<S extends Schema> = {
69
55
  <MD>(definitions: MD & AssertMutatorDefinitions<MD>): MutatorRegistry<EnsureMutatorDefinitions<MD>, S>;
70
- <TBase, TOverrides>(base: MutatorRegistry<EnsureMutatorDefinitions<TBase>, S> | (TBase & AssertMutatorDefinitions<TBase>), overrides: TOverrides): MutatorRegistry<DeepMerge<EnsureMutatorDefinitions<TBase>, EnsureMutatorDefinitions<TOverrides>>, S>;
56
+ <TBase, TOverrides>(base: MutatorRegistry<EnsureMutatorDefinitions<TBase>, S> | (TBase & AssertMutatorDefinitions<TBase>), overrides: TOverrides): MutatorRegistry<DeepMerge<EnsureMutatorDefinitions<TBase>, EnsureMutatorDefinitions<TOverrides>, AnyMutatorDefinition>, S>;
71
57
  };
58
+ export type AssertMutatorDefinitions<MD> = MD extends MutatorDefinitions ? unknown : never;
59
+ export type EnsureMutatorDefinitions<MD> = MD extends MutatorDefinitions ? MD : never;
72
60
  /**
73
- * A tree of MutatorDefinitions, possibly nested.
61
+ * Checks if a value is a MutatorRegistry.
74
62
  */
75
- export type MutatorDefinitions<Context, WrappedTransaction> = {
76
- readonly [key: string]: MutatorDefinition<any, any, Context, WrappedTransaction> | MutatorDefinitions<Context, WrappedTransaction>;
63
+ export declare function isMutatorRegistry(value: unknown): value is AnyMutatorRegistry;
64
+ export type MutatorRegistryTypes<TSchema extends Schema> = 'MutatorRegistry' & {
65
+ readonly $schema: TSchema;
77
66
  };
78
- export type AnyMutatorDefinitions = MutatorDefinitions<any, any>;
79
- export type AssertMutatorDefinitions<MD> = MD extends AnyMutatorDefinitions ? unknown : never;
80
- export type EnsureMutatorDefinitions<MD> = MD extends AnyMutatorDefinitions ? MD : never;
81
67
  /**
82
68
  * The result of defineMutators(). A tree of Mutators with a tag for detection.
83
69
  */
84
- export type MutatorRegistry<MD extends AnyMutatorDefinitions, TSchema extends Schema> = ToMutatorTree<MD, TSchema> & {
85
- [mutatorRegistryTag]: true;
70
+ export type MutatorRegistry<MD extends MutatorDefinitions, TSchema extends Schema> = ToMutatorTree<MD, TSchema> & {
71
+ ['~']: MutatorRegistryTypes<TSchema>;
86
72
  };
87
73
  /**
88
74
  * A branded type for use in type constraints. Use this instead of
@@ -90,22 +76,37 @@ export type MutatorRegistry<MD extends AnyMutatorDefinitions, TSchema extends Sc
90
76
  * the complex ToMutatorTree structure and hitting variance issues.
91
77
  */
92
78
  export type AnyMutatorRegistry = {
93
- [mutatorRegistryTag]: true;
79
+ ['~']: MutatorRegistryTypes<Schema>;
94
80
  [key: string]: unknown;
95
81
  };
96
- declare const mutatorRegistryTag: unique symbol;
97
82
  /**
98
83
  * Transforms a MutatorDefinitions into a tree of Mutators.
99
84
  * Each MutatorDefinition becomes a Mutator at the same path.
100
85
  * Uses TInput for the callable args (TOutput is only used internally for validation).
101
86
  */
102
- export type ToMutatorTree<MD extends AnyMutatorDefinitions, TSchema extends Schema> = {
103
- readonly [K in keyof MD]: MD[K] extends MutatorDefinition<any, any, any, any> ? Mutator<MD[K]['~']['$input'], TSchema, MD[K]['~']['$context'], MD[K]['~']['$wrappedTransaction']> : MD[K] extends AnyMutatorDefinitions ? ToMutatorTree<MD[K], TSchema> : never;
87
+ export type ToMutatorTree<MD extends MutatorDefinitions, TSchema extends Schema> = {
88
+ readonly [K in keyof MD]: MD[K] extends AnyMutatorDefinition ? Mutator<MD[K]['~']['$input'], TSchema, MD[K]['~']['$context'], MD[K]['~']['$wrappedTransaction']> : MD[K] extends MutatorDefinitions ? ToMutatorTree<MD[K], TSchema> : never;
104
89
  };
105
- export type FromMutatorTree<MD extends AnyMutatorDefinitions, TSchema extends Schema> = {
106
- readonly [K in keyof MD]: MD[K] extends MutatorDefinition<any, any, any, any> ? Mutator<ReadonlyJSONValue | undefined, // intentionally left as generic to avoid variance issues
107
- TSchema, MD[K]['~']['$context'], MD[K]['~']['$wrappedTransaction']> : MD[K] extends AnyMutatorDefinitions ? FromMutatorTree<MD[K], TSchema> : never;
90
+ export type FromMutatorTree<MD extends MutatorDefinitions, TSchema extends Schema> = {
91
+ readonly [K in keyof MD]: MD[K] extends AnyMutatorDefinition ? Mutator<ReadonlyJSONValue | undefined, // intentionally left as generic to avoid variance issues
92
+ TSchema, MD[K]['~']['$context'], MD[K]['~']['$wrappedTransaction']> : MD[K] extends MutatorDefinitions ? FromMutatorTree<MD[K], TSchema> : never;
108
93
  }[keyof MD];
94
+ /**
95
+ * A tree of MutatorDefinitions, possibly nested.
96
+ */
97
+ export type MutatorDefinitions = {
98
+ readonly [key: string]: AnyMutatorDefinition | MutatorDefinitions;
99
+ };
109
100
  export declare function iterateMutators(registry: AnyMutatorRegistry): Iterable<AnyMutator>;
101
+ /**
102
+ * Gets a Mutator by its dot-separated name from a MutatorRegistry.
103
+ * Returns undefined if not found.
104
+ */
105
+ export declare function getMutator<MD extends MutatorDefinitions, TSchema extends Schema = DefaultSchema>(registry: MutatorRegistry<MD, TSchema>, name: string): FromMutatorTree<MD, TSchema> | undefined;
106
+ /**
107
+ * Gets a Mutator by its dot-separated name from a MutatorRegistry.
108
+ * Throws if not found.
109
+ */
110
+ export declare function mustGetMutator<MD extends MutatorDefinitions, TSchema extends Schema = DefaultSchema>(registry: MutatorRegistry<MD, TSchema>, name: string): FromMutatorTree<MD, TSchema>;
110
111
  export {};
111
112
  //# sourceMappingURL=mutator-registry.d.ts.map
@@ -1 +1 @@
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,EAEvB,MAAM,cAAc,CAAC;AAEtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;A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GAAG,CAAC,CAAC,UAAU,CAAC,EACtB,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,qBAAqB,CAAC,CAClC,GACD,EAAE,CAAC,CAAC,CAAC,SAAS,kBAAkB,GAC9B,eAAe,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,GAC/B,KAAK;CACZ,CAAC,MAAM,EAAE,CAAC,CAAC;AAEZ;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,oBAAoB,GAAG,kBAAkB,CAAC;CACnE,CAAC;AAkEF,wBAAiB,eAAe,CAC9B,QAAQ,EAAE,kBAAkB,GAC3B,QAAQ,CAAC,UAAU,CAAC,CAEtB;AAED;;;GAGG;AACH,wBAAgB,UAAU,CACxB,EAAE,SAAS,kBAAkB,EAC7B,OAAO,SAAS,MAAM,GAAG,aAAa,EAEtC,QAAQ,EAAE,eAAe,CAAC,EAAE,EAAE,OAAO,CAAC,EACtC,IAAI,EAAE,MAAM,GACX,eAAe,CAAC,EAAE,EAAE,OAAO,CAAC,GAAG,SAAS,CAG1C;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,EAAE,SAAS,kBAAkB,EAC7B,OAAO,SAAS,MAAM,GAAG,aAAa,EAEtC,QAAQ,EAAE,eAAe,CAAC,EAAE,EAAE,OAAO,CAAC,EACtC,IAAI,EAAE,MAAM,GACX,eAAe,CAAC,EAAE,EAAE,OAAO,CAAC,CAM9B"}
@@ -1,11 +1,11 @@
1
- import { deepMerge } from "../../../shared/src/deep-merge.js";
1
+ import { deepMerge, isPlainObject } from "../../../shared/src/deep-merge.js";
2
2
  import { getValueAtPath, iterateLeaves } from "../../../shared/src/object-traversal.js";
3
3
  import { validateInput } from "../query/validate-input.js";
4
4
  import { isMutatorDefinition, isMutator } from "./mutator.js";
5
5
  function defineMutators(definitionsOrBase, maybeOverrides) {
6
6
  function processDefinitions(definitions, path) {
7
7
  const result = {
8
- [mutatorRegistryTag]: true
8
+ ["~"]: "MutatorRegistry"
9
9
  };
10
10
  for (const [key, value] of Object.entries(definitions)) {
11
11
  path.push(key);
@@ -27,8 +27,8 @@ function defineMutators(definitionsOrBase, maybeOverrides) {
27
27
  base = definitionsOrBase;
28
28
  }
29
29
  const processed = processDefinitions(maybeOverrides, []);
30
- const merged = deepMerge(base, processed, isMutator);
31
- merged[mutatorRegistryTag] = true;
30
+ const merged = deepMerge(base, processed, isMutatorLeaf);
31
+ merged["~"] = "MutatorRegistry";
32
32
  return merged;
33
33
  }
34
34
  return processDefinitions(
@@ -36,39 +36,27 @@ function defineMutators(definitionsOrBase, maybeOverrides) {
36
36
  []
37
37
  );
38
38
  }
39
- function getMutator(registry, name) {
40
- const m = getValueAtPath(registry, name, ".");
41
- return m;
42
- }
43
- function mustGetMutator(registry, name) {
44
- const mutator = getMutator(registry, name);
45
- if (mutator === void 0) {
46
- throw new Error(`Mutator not found: ${name}`);
47
- }
48
- return mutator;
39
+ const isMutatorLeaf = (value) => !isPlainObject(value) || isMutator(value);
40
+ function defineMutatorsWithType() {
41
+ return defineMutators;
49
42
  }
50
43
  function isMutatorRegistry(value) {
51
- return typeof value === "object" && value !== null && mutatorRegistryTag in value;
44
+ return typeof value === "object" && value !== null && value["~"] === "MutatorRegistry";
52
45
  }
53
- const mutatorRegistryTag = Symbol("mutatorRegistry");
54
46
  function createMutator(name, definition) {
55
47
  const { validator } = definition;
56
48
  const fn = async (options) => {
57
- const validatedArgs = validator ? validateInput(
58
- name,
59
- options.args,
60
- validator,
61
- "mutator"
62
- ) : options.args;
63
- await definition({
49
+ const validatedArgs = validator ? validateInput(name, options.args, validator, "mutator") : options.args;
50
+ await definition.fn({
64
51
  args: validatedArgs,
65
52
  ctx: options.ctx,
66
53
  tx: options.tx
67
54
  });
68
55
  };
69
56
  const mutator = (args) => ({
70
- mutator,
71
- args
57
+ args,
58
+ "~": "MutateRequest",
59
+ "mutator": mutator
72
60
  });
73
61
  mutator.mutatorName = name;
74
62
  mutator.fn = fn;
@@ -78,8 +66,20 @@ function createMutator(name, definition) {
78
66
  function* iterateMutators(registry) {
79
67
  yield* iterateLeaves(registry, isMutator);
80
68
  }
69
+ function getMutator(registry, name) {
70
+ const m = getValueAtPath(registry, name, ".");
71
+ return m;
72
+ }
73
+ function mustGetMutator(registry, name) {
74
+ const mutator = getMutator(registry, name);
75
+ if (mutator === void 0) {
76
+ throw new Error(`Mutator not found: ${name}`);
77
+ }
78
+ return mutator;
79
+ }
81
80
  export {
82
81
  defineMutators,
82
+ defineMutatorsWithType,
83
83
  getMutator,
84
84
  isMutatorRegistry,
85
85
  iterateMutators,
@@ -1 +1 @@
1
- {"version":3,"file":"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 type MutatorTypes,\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 mutator['~'] = 'Mutator' as unknown as MutatorTypes<\n ArgsInput,\n TSchema,\n C,\n TWrappedTransaction\n >;\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":";;;;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,mBAAmB,OAAgC,IAAI;AAAA,MACvE;AACA,WAAK,IAAA;AAAA,IACP;AAEA,WAAO;AAAA,EACT;AAEA,MAAI,mBAAmB,QAAW;AAEhC,QAAI;AACJ,QAAI,CAAC,kBAAkB,iBAAiB,GAAG;AACzC,aAAO,mBAAmB,mBAA4C,EAAE;AAAA,IAC1E,OAAO;AACL,aAAO;AAAA,IACT;AAEA,UAAM,YAAY,mBAAmB,gBAAgB,EAAE;AAEvD,UAAM,SAAS,UAAU,MAAM,WAAW,SAAS;AAKnD,WAAO,kBAAkB,IAAI;AAC7B,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL;AAAA,IACA,CAAA;AAAA,EAAC;AAEL;AAMO,SAAS,WAId,UACA,MAC0C;AAC1C,QAAM,IAAI,eAAe,UAAU,MAAM,GAAG;AAC5C,SAAO;AACT;AAMO,SAAS,eAId,UACA,MAC8B;AAC9B,QAAM,UAAU,WAAW,UAAU,IAAI;AACzC,MAAI,YAAY,QAAW;AACzB,UAAM,IAAI,MAAM,sBAAsB,IAAI,EAAE;AAAA,EAC9C;AACA,SAAO;AACT;AAKO,SAAS,kBAGd,OAAuD;AACvD,SACE,OAAO,UAAU,YAAY,UAAU,QAAQ,sBAAsB;AAEzE;AAmFA,MAAM,qBAAqB,OAAO,iBAAiB;AAyCnD,SAAS,cAOP,MACA,YACqD;AACrD,QAAM,EAAC,cAAa;AAIpB,QAAM,KAAK,OAAO,YAIG;AACnB,UAAM,gBAAgB,YAClB;AAAA,MACE;AAAA,MACA,QAAQ;AAAA,MACR;AAAA,MACA;AAAA,IAAA,IAED,QAAQ;AACb,UAAM,WAAW;AAAA,MACf,MAAM;AAAA,MACN,KAAK,QAAQ;AAAA,MACb,IAAI,QAAQ;AAAA,IAAA,CACb;AAAA,EACH;AAGA,QAAM,UAAU,CACd,UACiE;AAAA,IACjE;AAAA,IAMA;AAAA,EAAA;AAEF,UAAQ,cAAc;AACtB,UAAQ,KAAK;AACb,UAAQ,GAAG,IAAI;AAOf,SAAO;AAMT;AAEO,UAAU,gBACf,UACsB;AACtB,SAAO,cAAc,UAAU,SAAS;AAC1C;"}
1
+ {"version":3,"file":"mutator-registry.js","sources":["../../../../../zql/src/mutate/mutator-registry.ts"],"sourcesContent":["import {\n deepMerge,\n isPlainObject,\n type DeepMerge,\n} 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 {Transaction} from './custom.ts';\nimport {\n isMutator,\n isMutatorDefinition,\n type AnyMutator,\n type AnyMutatorDefinition,\n type MutateRequest,\n type MutateRequestTypes,\n type Mutator,\n type MutatorDefinition,\n type MutatorDefinitionFunction,\n type MutatorTypes,\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 MutatorDefinitions 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 AnyMutatorDefinition\n >,\n S\n>;\n\nexport function defineMutators(\n definitionsOrBase: MutatorDefinitions | AnyMutatorRegistry,\n maybeOverrides?: MutatorDefinitions,\n): AnyMutatorRegistry {\n function processDefinitions(\n definitions: MutatorDefinitions,\n path: string[],\n ): Record<string | symbol, unknown> {\n const result: Record<string | symbol, unknown> = {\n ['~']: 'MutatorRegistry',\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 MutatorDefinitions, 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, []);\n } else {\n base = definitionsOrBase;\n }\n\n const processed = processDefinitions(maybeOverrides, []);\n\n const merged = deepMerge(base, processed, isMutatorLeaf);\n merged['~'] = 'MutatorRegistry';\n return merged as AnyMutatorRegistry;\n }\n\n return processDefinitions(\n definitionsOrBase as MutatorDefinitions,\n [],\n ) as AnyMutatorRegistry;\n}\n\nconst isMutatorLeaf = (value: unknown): boolean =>\n !isPlainObject(value) || isMutator(value);\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 AnyMutatorDefinition\n >,\n S\n >;\n};\n\nexport type AssertMutatorDefinitions<MD> = MD extends MutatorDefinitions\n ? unknown\n : never;\n\nexport type EnsureMutatorDefinitions<MD> = MD extends MutatorDefinitions\n ? MD\n : never;\n\n/**\n * Checks if a value is a MutatorRegistry.\n */\nexport function isMutatorRegistry(value: unknown): value is AnyMutatorRegistry {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as Record<string, unknown>)['~'] === 'MutatorRegistry'\n );\n}\n\nexport type MutatorRegistryTypes<TSchema extends Schema> = 'MutatorRegistry' & {\n readonly $schema: TSchema;\n};\n\n/**\n * The result of defineMutators(). A tree of Mutators with a tag for detection.\n */\nexport type MutatorRegistry<\n MD extends MutatorDefinitions,\n TSchema extends Schema,\n> = ToMutatorTree<MD, TSchema> & {\n ['~']: MutatorRegistryTypes<TSchema>;\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 ['~']: MutatorRegistryTypes<Schema>;\n [key: string]: unknown;\n};\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 MutatorDefinitions,\n TSchema extends Schema,\n> = {\n readonly [K in keyof MD]: MD[K] extends AnyMutatorDefinition\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 MutatorDefinitions\n ? ToMutatorTree<MD[K], TSchema>\n : never;\n};\n\nexport type FromMutatorTree<\n MD extends MutatorDefinitions,\n TSchema extends Schema,\n> = {\n readonly [K in keyof MD]: MD[K] extends AnyMutatorDefinition\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 MutatorDefinitions\n ? FromMutatorTree<MD[K], TSchema>\n : never;\n}[keyof MD];\n\n/**\n * A tree of MutatorDefinitions, possibly nested.\n */\nexport type MutatorDefinitions = {\n readonly [key: string]: AnyMutatorDefinition | MutatorDefinitions;\n};\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: MutatorDefinitionFunction<\n ArgsInput,\n C,\n Transaction<TSchema, TWrappedTransaction>\n > = async options => {\n const validatedArgs = validator\n ? validateInput(name, options.args, validator, 'mutator')\n : (options.args as unknown as ArgsOutput);\n await definition.fn({\n args: validatedArgs,\n ctx: options.ctx,\n tx: options.tx,\n });\n };\n\n const mutator = (\n args: ArgsInput,\n ): MutateRequest<ArgsInput, TSchema, C, TWrappedTransaction> => ({\n args,\n '~': 'MutateRequest' as MutateRequestTypes<\n ArgsInput,\n TSchema,\n C,\n TWrappedTransaction\n >,\n 'mutator': mutator as unknown as Mutator<\n ArgsInput,\n TSchema,\n C,\n TWrappedTransaction\n >,\n });\n\n mutator.mutatorName = name;\n mutator.fn = fn;\n mutator['~'] = 'Mutator' as unknown as MutatorTypes<\n ArgsInput,\n TSchema,\n C,\n TWrappedTransaction\n >;\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\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 MutatorDefinitions,\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 MutatorDefinitions,\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"],"names":[],"mappings":";;;;AA6FO,SAAS,eACd,mBACA,gBACoB;AACpB,WAAS,mBACP,aACA,MACkC;AAClC,UAAM,SAA2C;AAAA,MAC/C,CAAC,GAAG,GAAG;AAAA,IAAA;AAGT,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,OAA6B,IAAI;AAAA,MACpE;AACA,WAAK,IAAA;AAAA,IACP;AAEA,WAAO;AAAA,EACT;AAEA,MAAI,mBAAmB,QAAW;AAEhC,QAAI;AACJ,QAAI,CAAC,kBAAkB,iBAAiB,GAAG;AACzC,aAAO,mBAAmB,mBAAmB,EAAE;AAAA,IACjD,OAAO;AACL,aAAO;AAAA,IACT;AAEA,UAAM,YAAY,mBAAmB,gBAAgB,EAAE;AAEvD,UAAM,SAAS,UAAU,MAAM,WAAW,aAAa;AACvD,WAAO,GAAG,IAAI;AACd,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL;AAAA,IACA,CAAA;AAAA,EAAC;AAEL;AAEA,MAAM,gBAAgB,CAAC,UACrB,CAAC,cAAc,KAAK,KAAK,UAAU,KAAK;AAKnC,SAAS,yBAEkB;AAChC,SAAO;AACT;AAuCO,SAAS,kBAAkB,OAA6C;AAC7E,SACE,OAAO,UAAU,YACjB,UAAU,QACT,MAAkC,GAAG,MAAM;AAEhD;AAwEA,SAAS,cAOP,MACA,YACqD;AACrD,QAAM,EAAC,cAAa;AAIpB,QAAM,KAIF,OAAM,YAAW;AACnB,UAAM,gBAAgB,YAClB,cAAc,MAAM,QAAQ,MAAM,WAAW,SAAS,IACrD,QAAQ;AACb,UAAM,WAAW,GAAG;AAAA,MAClB,MAAM;AAAA,MACN,KAAK,QAAQ;AAAA,MACb,IAAI,QAAQ;AAAA,IAAA,CACb;AAAA,EACH;AAEA,QAAM,UAAU,CACd,UAC+D;AAAA,IAC/D;AAAA,IACA,KAAK;AAAA,IAML,WAAW;AAAA,EAAA;AAQb,UAAQ,cAAc;AACtB,UAAQ,KAAK;AACb,UAAQ,GAAG,IAAI;AAOf,SAAO;AAMT;AAEO,UAAU,gBACf,UACsB;AACtB,SAAO,cAAc,UAAU,SAAS;AAC1C;AAMO,SAAS,WAId,UACA,MAC0C;AAC1C,QAAM,IAAI,eAAe,UAAU,MAAM,GAAG;AAC5C,SAAO;AACT;AAMO,SAAS,eAId,UACA,MAC8B;AAC9B,QAAM,UAAU,WAAW,UAAU,IAAI;AACzC,MAAI,YAAY,QAAW;AACzB,UAAM,IAAI,MAAM,sBAAsB,IAAI,EAAE;AAAA,EAC9C;AACA,SAAO;AACT;"}
@@ -1,5 +1,4 @@
1
1
  import type { StandardSchemaV1 } from '@standard-schema/spec';
2
- import type { Expand } from '../../../shared/src/expand.ts';
3
2
  import type { ReadonlyJSONValue } from '../../../shared/src/json.ts';
4
3
  import type { DefaultContext, DefaultSchema, DefaultWrappedTransaction } from '../../../zero-types/src/default-types.ts';
5
4
  import type { Schema } from '../../../zero-types/src/schema.ts';
@@ -10,28 +9,15 @@ export type MutatorDefinitionTypes<TInput extends ReadonlyJSONValue | undefined,
10
9
  readonly $context: TContext;
11
10
  readonly $wrappedTransaction: TWrappedTransaction;
12
11
  };
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: {
15
- args: TOutput;
16
- ctx: TContext;
17
- tx: AnyTransaction;
18
- }) => Promise<void>) & {
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>>;
12
+ export type MutatorDefinition<TInput extends ReadonlyJSONValue | undefined, TOutput extends ReadonlyJSONValue | undefined, TContext = DefaultContext, TWrappedTransaction = DefaultWrappedTransaction> = {
13
+ readonly 'fn': MutatorDefinitionFunction<TOutput, TContext, AnyTransaction>;
14
+ readonly 'validator': StandardSchemaV1<TInput, TOutput> | undefined;
15
+ readonly '~': MutatorDefinitionTypes<TInput, TOutput, TContext, TWrappedTransaction>;
24
16
  };
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: {
26
- args: TOutput;
27
- ctx: TContext;
28
- tx: Transaction<TSchema, TWrappedTransaction>;
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;
32
- ctx: TContext;
33
- tx: Transaction<TSchema, TWrappedTransaction>;
34
- }) => Promise<void>): MutatorDefinition<TInput, TInput, TContext, TWrappedTransaction>;
17
+ export type AnyMutatorDefinition = MutatorDefinition<any, any, any, any>;
18
+ export declare function isMutatorDefinition(f: unknown): f is AnyMutatorDefinition;
19
+ export declare function defineMutator<TInput extends ReadonlyJSONValue | undefined = ReadonlyJSONValue | undefined, TSchema extends Schema = DefaultSchema, TContext = DefaultContext, TWrappedTransaction = DefaultWrappedTransaction>(mutator: MutatorDefinitionFunction<TInput, TContext, Transaction<TSchema, TWrappedTransaction>>): MutatorDefinition<TInput, TInput, TContext, TWrappedTransaction>;
20
+ 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: MutatorDefinitionFunction<TOutput, TContext, Transaction<TSchema, TWrappedTransaction>>): MutatorDefinition<TInput, TOutput, TContext, TWrappedTransaction>;
35
21
  export declare function defineMutatorWithType<TSchema extends Schema, TContext = unknown, TWrappedTransaction = unknown>(): TypedDefineMutator<TSchema, TContext, TWrappedTransaction>;
36
22
  /**
37
23
  * The return type of defineMutatorWithType. A function matching the
@@ -42,17 +28,14 @@ export declare function defineMutatorWithType<TSchema extends Schema, TContext =
42
28
  * multiple Zero instances).
43
29
  */
44
30
  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>;
31
+ <TArgs extends ReadonlyJSONValue | undefined>(mutator: MutatorDefinitionFunction<TArgs, TContext, Transaction<TSchema, TWrappedTransaction>>): MutatorDefinition<TArgs, TArgs, TContext, TWrappedTransaction>;
32
+ <TInput extends ReadonlyJSONValue | undefined, TOutput extends ReadonlyJSONValue | undefined>(validator: StandardSchemaV1<TInput, TOutput>, mutator: MutatorDefinitionFunction<TOutput, TContext, Transaction<TSchema, TWrappedTransaction>>): MutatorDefinition<TInput, TOutput, TContext, TWrappedTransaction>;
55
33
  };
34
+ export type MutatorDefinitionFunction<TOutput extends ReadonlyJSONValue | undefined, TContext, TTransaction> = (options: {
35
+ args: TOutput;
36
+ ctx: TContext;
37
+ tx: TTransaction;
38
+ }) => Promise<void>;
56
39
  export type MutatorTypes<TInput extends ReadonlyJSONValue | undefined, TSchema extends Schema, TContext, TWrappedTransaction> = 'Mutator' & {
57
40
  readonly $input: TInput;
58
41
  readonly $schema: TSchema;
@@ -62,53 +45,50 @@ export type MutatorTypes<TInput extends ReadonlyJSONValue | undefined, TSchema e
62
45
  /**
63
46
  * A callable wrapper around a MutatorDefinition, created by `defineMutators()`.
64
47
  *
65
- * Accessed like `mutators.foo.bar`, and called to create a MutationRequest:
66
- * `mutators.foo.bar(42)` returns a `MutationRequest`.
48
+ * Accessed like `mutators.foo.bar`, and called to create a MutateRequest:
49
+ * `mutators.foo.bar(42)` returns a `MutateRequest`.
67
50
  *
68
51
  * The `fn` property is used for execution and takes raw JSON args (for rebase
69
52
  * and server wire format cases) that are validated internally.
70
- *
71
- * @template TInput - The argument type accepted by the callable (before validation)
72
- * @template TContext - The context type available during mutation execution
73
- * @template TWrappedTransaction - The wrapped transaction type
74
53
  */
75
- export type Mutator<TInput extends ReadonlyJSONValue | undefined, TSchema extends Schema = DefaultSchema, TContext = DefaultContext, TWrappedTransaction = DefaultWrappedTransaction> = MutatorCallable<TInput, TSchema, TContext, TWrappedTransaction> & {
76
- readonly mutatorName: string;
54
+ export type Mutator<TInput extends ReadonlyJSONValue | undefined, TSchema extends Schema = DefaultSchema, TContext = DefaultContext, TWrappedTransaction = DefaultWrappedTransaction> = {
55
+ readonly 'mutatorName': string;
77
56
  /**
78
57
  * Execute the mutation. Args are ReadonlyJSONValue because this is called
79
58
  * during rebase (from stored JSON) and on the server (from wire format).
80
59
  * Validation happens internally before the recipe function runs.
81
60
  */
82
- readonly fn: (options: {
83
- args: TInput;
84
- ctx: TContext;
85
- tx: Transaction<TSchema, TWrappedTransaction>;
86
- }) => Promise<void>;
87
- /**
88
- * Type-only phantom property to surface mutator types in a covariant position.
89
- */
90
- ['~']: Expand<MutatorTypes<TInput, TSchema, TContext, TWrappedTransaction>>;
61
+ readonly 'fn': MutatorDefinitionFunction<TInput, TContext, Transaction<TSchema, TWrappedTransaction>>;
62
+ readonly '~': MutatorTypes<TInput, TSchema, TContext, TWrappedTransaction>;
63
+ } & MutatorCallable<TInput, TSchema, TContext, TWrappedTransaction>;
64
+ type MutatorCallable<TInput extends ReadonlyJSONValue | undefined, TSchema extends Schema, TContext, TWrappedTransaction> = [TInput] extends [undefined] ? () => MutateRequest<TInput, TSchema, TContext, TWrappedTransaction> : undefined extends TInput ? {
65
+ (): MutateRequest<TInput, TSchema, TContext, TWrappedTransaction>;
66
+ (args?: TInput): MutateRequest<TInput, TSchema, TContext, TWrappedTransaction>;
67
+ } : {
68
+ (args: TInput): MutateRequest<TInput, TSchema, TContext, TWrappedTransaction>;
91
69
  };
92
- 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>;
93
70
  export type AnyMutator = Mutator<any, any, any, any>;
71
+ /**
72
+ * Checks if a value is a Mutator (the result of processing a MutatorDefinition
73
+ * through defineMutators).
74
+ */
75
+ export declare function isMutator(value: unknown): value is AnyMutator;
76
+ export type MutateRequestTypes<TInput extends ReadonlyJSONValue | undefined, TSchema extends Schema, TContext, TWrappedTransaction> = 'MutateRequest' & {
77
+ readonly $input: TInput;
78
+ readonly $schema: TSchema;
79
+ readonly $context: TContext;
80
+ readonly $wrappedTransaction: TWrappedTransaction;
81
+ };
94
82
  /**
95
83
  * The result of calling a Mutator with arguments.
96
84
  *
97
85
  * Created by `mutators.foo.bar(42)`, executed by `zero.mutate(mr)` on the client
98
86
  * or `mr.mutator.fn({tx, ctx, args: mr.args})` on the server.
99
- *
100
- * @template TInput - The argument type (before validation, sent to server)
101
- * @template TContext - The context type available during mutation execution
102
- * @template TWrappedTransaction - The wrapped transaction type
103
87
  */
104
- export type MutationRequest<TInput extends ReadonlyJSONValue | undefined, TSchema extends Schema = DefaultSchema, TContext = DefaultContext, TWrappedTransaction = DefaultWrappedTransaction> = {
105
- readonly mutator: Mutator<TInput, TSchema, TContext, TWrappedTransaction>;
106
- readonly args: TInput;
88
+ export type MutateRequest<TInput extends ReadonlyJSONValue | undefined, TSchema extends Schema = DefaultSchema, TContext = DefaultContext, TWrappedTransaction = DefaultWrappedTransaction> = {
89
+ readonly 'mutator': Mutator<TInput, TSchema, TContext, TWrappedTransaction>;
90
+ readonly 'args': TInput;
91
+ readonly '~': MutateRequestTypes<TInput, TSchema, TContext, TWrappedTransaction>;
107
92
  };
108
- /**
109
- * Checks if a value is a Mutator (the result of processing a MutatorDefinition
110
- * through defineMutators).
111
- */
112
- export declare function isMutator(value: unknown): value is AnyMutator;
113
93
  export {};
114
94
  //# sourceMappingURL=mutator.d.ts.map
@@ -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,MAAM,EAAC,MAAM,+BAA+B,CAAC;AAC1D,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,6BAA6B,CAAC;AAEnE,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,y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AAC;CAClE,GACD;IACE,CACE,IAAI,EAAE,MAAM,GACX,aAAa,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,mBAAmB,CAAC,CAAC;CAClE,CAAC;AAGR,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAErD;;;GAGG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAM7D;AAED,MAAM,MAAM,kBAAkB,CAC5B,MAAM,SAAS,iBAAiB,GAAG,SAAS,EAC5C,OAAO,SAAS,MAAM,EACtB,QAAQ,EACR,mBAAmB,IACjB,eAAe,GAAG;IACpB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,mBAAmB,EAAE,mBAAmB,CAAC;CACnD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,aAAa,CACvB,MAAM,SAAS,iBAAiB,GAAG,SAAS,EAC5C,OAAO,SAAS,MAAM,GAAG,aAAa,EACtC,QAAQ,GAAG,cAAc,EACzB,mBAAmB,GAAG,yBAAyB,IAC7C;IACF,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,mBAAmB,CAAC,CAAC;IAC5E,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,GAAG,EAAE,kBAAkB,CAC9B,MAAM,EACN,OAAO,EACP,QAAQ,EACR,mBAAmB,CACpB,CAAC;CACH,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { must } from "../../../shared/src/must.js";
2
2
  function isMutatorDefinition(f) {
3
- return typeof f === "function" && f["~"] === "MutatorDefinition";
3
+ return typeof f === "object" && f !== null && f["~"] === "MutatorDefinition";
4
4
  }
5
5
  function defineMutator(validatorOrMutator, mutator) {
6
6
  let validator;
@@ -12,18 +12,22 @@ function defineMutator(validatorOrMutator, mutator) {
12
12
  validator = validatorOrMutator;
13
13
  actualMutator = must(mutator);
14
14
  }
15
- const f = actualMutator;
16
- f["~"] = "MutatorDefinition";
17
- f.validator = validator;
18
- return f;
15
+ const mutatorDefinition = {
16
+ "fn": actualMutator,
17
+ "validator": validator,
18
+ "~": "MutatorDefinition"
19
+ };
20
+ return mutatorDefinition;
21
+ }
22
+ function defineMutatorWithType() {
23
+ return defineMutator;
19
24
  }
20
25
  function isMutator(value) {
21
- return typeof value === "function" && // oxlint-disable-next-line no-explicit-any
22
- typeof value.mutatorName === "string" && // oxlint-disable-next-line no-explicit-any
23
- typeof value.fn === "function";
26
+ return typeof value === "function" && typeof value.mutatorName === "string" && typeof value.fn === "function";
24
27
  }
25
28
  export {
26
29
  defineMutator,
30
+ defineMutatorWithType,
27
31
  isMutator,
28
32
  isMutatorDefinition
29
33
  };
@@ -1 +1 @@
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\nexport type MutatorTypes<\n TInput extends ReadonlyJSONValue | undefined,\n TSchema extends Schema,\n TContext,\n TWrappedTransaction,\n> = 'Mutator' & {\n readonly $input: TInput;\n readonly $schema: TSchema;\n readonly $context: TContext;\n readonly $wrappedTransaction: TWrappedTransaction;\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 * Type-only phantom property to surface mutator types in a covariant position.\n */\n ['~']: Expand<MutatorTypes<TInput, TSchema, TContext, TWrappedTransaction>>;\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;AAkJO,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 {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\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 type MutatorDefinition<\n TInput extends ReadonlyJSONValue | undefined,\n TOutput extends ReadonlyJSONValue | undefined,\n TContext = DefaultContext,\n TWrappedTransaction = DefaultWrappedTransaction,\n> = {\n readonly 'fn': MutatorDefinitionFunction<TOutput, TContext, AnyTransaction>;\n readonly 'validator': StandardSchemaV1<TInput, TOutput> | undefined;\n readonly '~': MutatorDefinitionTypes<\n TInput,\n TOutput,\n TContext,\n TWrappedTransaction\n >;\n};\n\n// oxlint-disable-next-line no-explicit-any\nexport type AnyMutatorDefinition = MutatorDefinition<any, any, any, any>;\n\nexport function isMutatorDefinition(f: unknown): f is AnyMutatorDefinition {\n return (\n typeof f === 'object' &&\n f !== null &&\n (f as {['~']?: unknown})['~'] === 'MutatorDefinition'\n );\n}\n\n// Overload for no 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: MutatorDefinitionFunction<\n TInput,\n TContext,\n Transaction<TSchema, TWrappedTransaction>\n >,\n): MutatorDefinition<TInput, TInput, TContext, TWrappedTransaction>;\n\n// Overload for 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: MutatorDefinitionFunction<\n TOutput,\n TContext,\n Transaction<TSchema, TWrappedTransaction>\n >,\n): MutatorDefinition<TInput, TOutput, 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 | MutatorDefinitionFunction<\n TOutput,\n TContext,\n Transaction<TSchema, TWrappedTransaction>\n >,\n mutator?: MutatorDefinitionFunction<\n TOutput,\n TContext,\n Transaction<TSchema, TWrappedTransaction>\n >,\n): MutatorDefinition<TInput, TOutput, TContext, TWrappedTransaction> {\n let validator: StandardSchemaV1<TInput, TOutput> | undefined;\n let actualMutator: MutatorDefinitionFunction<\n TOutput,\n TContext,\n Transaction<TSchema, TWrappedTransaction>\n >;\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 mutatorDefinition: MutatorDefinition<\n TInput,\n TOutput,\n TContext,\n TWrappedTransaction\n > = {\n 'fn': actualMutator as MutatorDefinitionFunction<\n TOutput,\n TContext,\n AnyTransaction\n >,\n 'validator': validator,\n '~': 'MutatorDefinition' as unknown as MutatorDefinitionTypes<\n TInput,\n TOutput,\n TContext,\n TWrappedTransaction\n >,\n };\n return mutatorDefinition;\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: MutatorDefinitionFunction<\n TArgs,\n TContext,\n Transaction<TSchema, TWrappedTransaction>\n >,\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: MutatorDefinitionFunction<\n TOutput,\n TContext,\n Transaction<TSchema, TWrappedTransaction>\n >,\n ): MutatorDefinition<TInput, TOutput, TContext, TWrappedTransaction>;\n};\n\nexport type MutatorDefinitionFunction<\n TOutput extends ReadonlyJSONValue | undefined,\n TContext,\n TTransaction,\n> = (options: {\n args: TOutput;\n ctx: TContext;\n tx: TTransaction;\n}) => Promise<void>;\n\n// ----------------------------------------------------------------------------\n// Mutator and MutateRequest types\n// ----------------------------------------------------------------------------\n\nexport type MutatorTypes<\n TInput extends ReadonlyJSONValue | undefined,\n TSchema extends Schema,\n TContext,\n TWrappedTransaction,\n> = 'Mutator' & {\n readonly $input: TInput;\n readonly $schema: TSchema;\n readonly $context: TContext;\n readonly $wrappedTransaction: TWrappedTransaction;\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 MutateRequest:\n * `mutators.foo.bar(42)` returns a `MutateRequest`.\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 */\nexport type Mutator<\n TInput extends ReadonlyJSONValue | undefined,\n TSchema extends Schema = DefaultSchema,\n TContext = DefaultContext,\n TWrappedTransaction = DefaultWrappedTransaction,\n> = {\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': MutatorDefinitionFunction<\n TInput,\n TContext,\n Transaction<TSchema, TWrappedTransaction>\n >;\n readonly '~': MutatorTypes<TInput, TSchema, TContext, TWrappedTransaction>;\n} & MutatorCallable<TInput, TSchema, TContext, TWrappedTransaction>;\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 ? () => MutateRequest<TInput, TSchema, TContext, TWrappedTransaction>\n : undefined extends TInput\n ? {\n (): MutateRequest<TInput, TSchema, TContext, TWrappedTransaction>;\n (\n args?: TInput,\n ): MutateRequest<TInput, TSchema, TContext, TWrappedTransaction>;\n }\n : {\n (\n args: TInput,\n ): MutateRequest<TInput, TSchema, TContext, TWrappedTransaction>;\n };\n\n// oxlint-disable-next-line no-explicit-any\nexport type AnyMutator = Mutator<any, any, any, any>;\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 typeof (value as {mutatorName?: unknown}).mutatorName === 'string' &&\n typeof (value as {fn?: unknown}).fn === 'function'\n );\n}\n\nexport type MutateRequestTypes<\n TInput extends ReadonlyJSONValue | undefined,\n TSchema extends Schema,\n TContext,\n TWrappedTransaction,\n> = 'MutateRequest' & {\n readonly $input: TInput;\n readonly $schema: TSchema;\n readonly $context: TContext;\n readonly $wrappedTransaction: TWrappedTransaction;\n};\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 */\nexport type MutateRequest<\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 readonly '~': MutateRequestTypes<\n TInput,\n TSchema,\n TContext,\n TWrappedTransaction\n >;\n};\n"],"names":[],"mappings":";AA8CO,SAAS,oBAAoB,GAAuC;AACzE,SACE,OAAO,MAAM,YACb,MAAM,QACL,EAAwB,GAAG,MAAM;AAEtC;AAiCO,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,oBAKF;AAAA,IACF,MAAM;AAAA,IAKN,aAAa;AAAA,IACb,KAAK;AAAA,EAAA;AAOP,SAAO;AACT;AAGO,SAAS,wBAIgD;AAC9D,SAAO;AACT;AA4HO,SAAS,UAAU,OAAqC;AAC7D,SACE,OAAO,UAAU,cACjB,OAAQ,MAAkC,gBAAgB,YAC1D,OAAQ,MAAyB,OAAO;AAE5C;"}