@rocicorp/zero 0.25.0-canary.11 → 0.25.0-canary.12

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/zero/package.json.js +1 -1
  2. package/out/zero-cache/src/config/zero-config.d.ts +4 -0
  3. package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
  4. package/out/zero-cache/src/config/zero-config.js +15 -5
  5. package/out/zero-cache/src/config/zero-config.js.map +1 -1
  6. package/out/zero-cache/src/server/change-streamer.d.ts.map +1 -1
  7. package/out/zero-cache/src/server/change-streamer.js +8 -2
  8. package/out/zero-cache/src/server/change-streamer.js.map +1 -1
  9. package/out/zero-cache/src/services/change-source/pg/change-source.d.ts.map +1 -1
  10. package/out/zero-cache/src/services/change-source/pg/change-source.js +42 -62
  11. package/out/zero-cache/src/services/change-source/pg/change-source.js.map +1 -1
  12. package/out/zero-cache/src/services/change-source/protocol/current/control.d.ts +0 -1
  13. package/out/zero-cache/src/services/change-source/protocol/current/control.d.ts.map +1 -1
  14. package/out/zero-cache/src/services/change-source/protocol/current/control.js +1 -5
  15. package/out/zero-cache/src/services/change-source/protocol/current/control.js.map +1 -1
  16. package/out/zero-cache/src/services/change-source/protocol/current/downstream.d.ts +0 -2
  17. package/out/zero-cache/src/services/change-source/protocol/current/downstream.d.ts.map +1 -1
  18. package/out/zero-cache/src/services/change-source/protocol/current.d.ts +0 -1
  19. package/out/zero-cache/src/services/change-source/protocol/current.d.ts.map +1 -1
  20. package/out/zero-cache/src/services/change-source/protocol/current.js +0 -3
  21. package/out/zero-cache/src/services/change-source/protocol/current.js.map +1 -1
  22. package/out/zero-cache/src/services/change-streamer/change-streamer-http.d.ts +2 -0
  23. package/out/zero-cache/src/services/change-streamer/change-streamer-http.d.ts.map +1 -1
  24. package/out/zero-cache/src/services/change-streamer/change-streamer-http.js +5 -0
  25. package/out/zero-cache/src/services/change-streamer/change-streamer-http.js.map +1 -1
  26. package/out/zero-cache/src/services/change-streamer/change-streamer-service.d.ts.map +1 -1
  27. package/out/zero-cache/src/services/change-streamer/change-streamer-service.js +1 -8
  28. package/out/zero-cache/src/services/change-streamer/change-streamer-service.js.map +1 -1
  29. package/out/zero-cache/src/services/change-streamer/storer.d.ts.map +1 -1
  30. package/out/zero-cache/src/services/change-streamer/storer.js +3 -2
  31. package/out/zero-cache/src/services/change-streamer/storer.js.map +1 -1
  32. package/out/zero-cache/src/services/http-service.d.ts +1 -0
  33. package/out/zero-cache/src/services/http-service.d.ts.map +1 -1
  34. package/out/zero-cache/src/services/http-service.js +4 -0
  35. package/out/zero-cache/src/services/http-service.js.map +1 -1
  36. package/out/zero-cache/src/services/replicator/replication-status.d.ts +0 -2
  37. package/out/zero-cache/src/services/replicator/replication-status.d.ts.map +1 -1
  38. package/out/zero-cache/src/services/replicator/replication-status.js +1 -14
  39. package/out/zero-cache/src/services/replicator/replication-status.js.map +1 -1
  40. package/out/zero-client/src/client/bindings.d.ts +2 -3
  41. package/out/zero-client/src/client/bindings.d.ts.map +1 -1
  42. package/out/zero-client/src/client/bindings.js.map +1 -1
  43. package/out/zero-client/src/client/make-mutate-property.d.ts +2 -2
  44. package/out/zero-client/src/client/make-mutate-property.d.ts.map +1 -1
  45. package/out/zero-client/src/client/make-mutate-property.js.map +1 -1
  46. package/out/zero-client/src/client/make-replicache-mutators.js.map +1 -1
  47. package/out/zero-client/src/client/options.d.ts +3 -3
  48. package/out/zero-client/src/client/options.d.ts.map +1 -1
  49. package/out/zero-client/src/client/options.js.map +1 -1
  50. package/out/zero-client/src/client/version.js +1 -1
  51. package/out/zero-client/src/client/zero.d.ts +1 -2
  52. package/out/zero-client/src/client/zero.d.ts.map +1 -1
  53. package/out/zero-client/src/client/zero.js.map +1 -1
  54. package/out/zero-client/src/mod.d.ts +5 -7
  55. package/out/zero-client/src/mod.d.ts.map +1 -1
  56. package/out/zero-events/src/status.d.ts +1 -1
  57. package/out/zero-events/src/status.d.ts.map +1 -1
  58. package/out/zero-react/src/components/inspector.d.ts +1 -2
  59. package/out/zero-react/src/components/inspector.d.ts.map +1 -1
  60. package/out/zero-react/src/components/inspector.js.map +1 -1
  61. package/out/zero-react/src/components/zero-inspector.d.ts +1 -2
  62. package/out/zero-react/src/components/zero-inspector.d.ts.map +1 -1
  63. package/out/zero-react/src/components/zero-inspector.js.map +1 -1
  64. package/out/zero-react/src/use-query.d.ts +1 -2
  65. package/out/zero-react/src/use-query.d.ts.map +1 -1
  66. package/out/zero-react/src/use-query.js.map +1 -1
  67. package/out/zero-react/src/zero-provider.d.ts +4 -5
  68. package/out/zero-react/src/zero-provider.d.ts.map +1 -1
  69. package/out/zero-react/src/zero-provider.js.map +1 -1
  70. package/out/zero-solid/src/use-zero.d.ts +4 -5
  71. package/out/zero-solid/src/use-zero.d.ts.map +1 -1
  72. package/out/zero-solid/src/use-zero.js.map +1 -1
  73. package/out/zero-types/src/default-types.d.ts +2 -2
  74. package/out/zero-types/src/default-types.d.ts.map +1 -1
  75. package/out/zql/src/ivm/join.d.ts.map +1 -1
  76. package/out/zql/src/ivm/join.js +14 -24
  77. package/out/zql/src/ivm/join.js.map +1 -1
  78. package/out/zql/src/mutate/custom.d.ts +2 -2
  79. package/out/zql/src/mutate/custom.d.ts.map +1 -1
  80. package/out/zql/src/mutate/custom.js.map +1 -1
  81. package/out/zql/src/mutate/mutator-registry.d.ts +33 -15
  82. package/out/zql/src/mutate/mutator-registry.d.ts.map +1 -1
  83. package/out/zql/src/mutate/mutator-registry.js +2 -8
  84. package/out/zql/src/mutate/mutator-registry.js.map +1 -1
  85. package/out/zql/src/mutate/mutator.d.ts +50 -25
  86. package/out/zql/src/mutate/mutator.d.ts.map +1 -1
  87. package/out/zql/src/mutate/mutator.js +2 -3
  88. package/out/zql/src/mutate/mutator.js.map +1 -1
  89. package/out/zql/src/query/query-internals.d.ts.map +1 -1
  90. package/out/zql/src/query/query-internals.js +2 -2
  91. package/out/zql/src/query/query-internals.js.map +1 -1
  92. package/out/zql/src/query/query-registry.d.ts +126 -58
  93. package/out/zql/src/query/query-registry.d.ts.map +1 -1
  94. package/out/zql/src/query/query-registry.js +13 -21
  95. package/out/zql/src/query/query-registry.js.map +1 -1
  96. package/package.json +1 -1
  97. package/out/zero-cache/src/services/change-source/protocol/current/json.d.ts +0 -8
  98. package/out/zero-cache/src/services/change-source/protocol/current/json.d.ts.map +0 -1
  99. package/out/zero-cache/src/services/change-source/protocol/current/json.js +0 -19
  100. package/out/zero-cache/src/services/change-source/protocol/current/json.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"custom.d.ts","sourceRoot":"","sources":["../../../../../zql/src/mutate/custom.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,+BAA+B,CAAC;AAC1D,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,mCAAmC,CAAC;AAC3D,OAAO,KAAK,EACV,aAAa,EACb,yBAAyB,EAC1B,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,yCAAyC,CAAC;AACjF,OAAO,KAAK,EAAC,MAAM,EAAE,WAAW,EAAC,MAAM,mCAAmC,CAAC;AAC3E,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,0CAA0C,CAAC;AAC3E,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,EAAC,aAAa,EAAE,KAAK,EAAE,UAAU,EAAC,MAAM,mBAAmB,CAAC;AACxE,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,0BAA0B,CAAC;AAE1D,KAAK,QAAQ,GAAG,MAAM,CAAC;AAEvB,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAC3C,MAAM,MAAM,iBAAiB,GAAG,YAAY,GAAG,QAAQ,GAAG,eAAe,CAAC;AAE1E;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,QAAQ,EAAE,QA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CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS;QAAC,QAAQ,EAAE,IAAI,CAAA;KAAC,GAChE,CAAC,GACD,KAAK,CAAC,CAAC,EAAE,mBAAmB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS;CAC9D,GAAG;KACD,CAAC,IAAI,MAAM,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS;QAAC,QAAQ,EAAE,IAAI,CAAA;KAAC,GAChE,KAAK,GACL,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;CAC7C,CACF,CAAC;AAEF,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,WAAW,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC;AAEhE,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,WAAW,IAAI,MAAM,CACrD,gBAAgB,CAAC,CAAC,CAAC,GAAG;KACnB,CAAC,IAAI,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EACtB,mBAAmB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,GACpC,SAAS;CACd,CACF,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,UAQ5D;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAE3E"}
@@ -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\nexport type Location = 'client' | 'server';\nexport type TransactionReason = 'optimistic' | 'rebase' | 'authoritative';\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 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 {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,5 +1,6 @@
1
1
  import { type DeepMerge } from '../../../shared/src/deep-merge.ts';
2
- import type { DefaultContext, DefaultSchema } from '../../../zero-types/src/default-types.ts';
2
+ import type { ReadonlyJSONValue } from '../../../shared/src/json.ts';
3
+ import type { DefaultSchema } from '../../../zero-types/src/default-types.ts';
3
4
  import type { Schema } from '../../../zero-types/src/schema.ts';
4
5
  import { type AnyMutator, type Mutator, type MutatorDefinition } from './mutator.ts';
5
6
  /**
@@ -40,34 +41,47 @@ import { type AnyMutator, type Mutator, type MutatorDefinition } from './mutator
40
41
  * const mutator = getMutator(mutators, 'user.create');
41
42
  * ```
42
43
  */
43
- export declare function defineMutators<T extends MutatorDefinitions<S, C>, S extends Schema = DefaultSchema, C = DefaultContext>(definitions: T): MutatorRegistry<S, C, T>;
44
- export declare function defineMutators<TBase extends MutatorDefinitions<S, C>, TOverrides extends MutatorDefinitions<S, C>, S extends Schema = DefaultSchema, C = DefaultContext>(base: MutatorRegistry<S, C, TBase>, overrides: TOverrides): MutatorRegistry<S, C, DeepMerge<TBase, TOverrides>>;
45
- export declare function defineMutators<TBase extends MutatorDefinitions<S, C>, TOverrides extends MutatorDefinitions<S, C>, S extends Schema = DefaultSchema, C = DefaultContext>(base: TBase, overrides: TOverrides): MutatorRegistry<S, C, DeepMerge<TBase, TOverrides>>;
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
46
  /**
47
47
  * Gets a Mutator by its dot-separated name from a MutatorRegistry.
48
48
  * Returns undefined if not found.
49
49
  */
50
- export declare function getMutator(registry: AnyMutatorRegistry, name: string): AnyMutator | undefined;
50
+ export declare function getMutator<MD extends AnyMutatorDefinitions, TSchema extends Schema = DefaultSchema>(registry: MutatorRegistry<MD, TSchema>, name: string): FromMutatorTree<MD, TSchema> | undefined;
51
51
  /**
52
52
  * Gets a Mutator by its dot-separated name from a MutatorRegistry.
53
53
  * Throws if not found.
54
54
  */
55
- export declare function mustGetMutator(registry: AnyMutatorRegistry, name: string): AnyMutator;
55
+ export declare function mustGetMutator<MD extends AnyMutatorDefinitions, TSchema extends Schema = DefaultSchema>(registry: MutatorRegistry<MD, TSchema>, name: string): FromMutatorTree<MD, TSchema>;
56
56
  /**
57
57
  * Checks if a value is a MutatorRegistry.
58
58
  */
59
- export declare function isMutatorRegistry<S extends Schema, C>(value: unknown): value is MutatorRegistry<S, C, MutatorDefinitions<S, C>>;
59
+ export declare function isMutatorRegistry<MD extends AnyMutatorDefinitions, TSchema extends Schema = DefaultSchema>(value: unknown): value is MutatorRegistry<MD, TSchema>;
60
+ /**
61
+ * Creates a function that can be used to define mutators with a specific schema.
62
+ */
63
+ export declare function defineMutatorsWithType<TSchema extends Schema>(): TypedDefineMutators<TSchema>;
64
+ /**
65
+ * The return type of defineMutatorsWithType. A function matching the
66
+ * defineMutators overloads but with Schema pre-bound.
67
+ */
68
+ type TypedDefineMutators<S extends Schema> = {
69
+ <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>;
71
+ };
60
72
  /**
61
73
  * A tree of MutatorDefinitions, possibly nested.
62
74
  */
63
- export type MutatorDefinitions<S extends Schema, C> = {
64
- readonly [key: string]: // oxlint-disable-next-line no-explicit-any
65
- MutatorDefinition<any, any, S, C, any> | MutatorDefinitions<S, C>;
75
+ export type MutatorDefinitions<Context, WrappedTransaction> = {
76
+ readonly [key: string]: MutatorDefinition<any, any, Context, WrappedTransaction> | MutatorDefinitions<Context, WrappedTransaction>;
66
77
  };
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;
67
81
  /**
68
82
  * The result of defineMutators(). A tree of Mutators with a tag for detection.
69
83
  */
70
- export type MutatorRegistry<S extends Schema, C, T extends MutatorDefinitions<S, C>> = ToMutatorTree<S, C, T> & {
84
+ export type MutatorRegistry<MD extends AnyMutatorDefinitions, TSchema extends Schema> = ToMutatorTree<MD, TSchema> & {
71
85
  [mutatorRegistryTag]: true;
72
86
  };
73
87
  /**
@@ -77,17 +91,21 @@ export type MutatorRegistry<S extends Schema, C, T extends MutatorDefinitions<S,
77
91
  */
78
92
  export type AnyMutatorRegistry = {
79
93
  [mutatorRegistryTag]: true;
80
- } & Record<string, unknown>;
94
+ [key: string]: unknown;
95
+ };
81
96
  declare const mutatorRegistryTag: unique symbol;
82
97
  /**
83
98
  * Transforms a MutatorDefinitions into a tree of Mutators.
84
99
  * Each MutatorDefinition becomes a Mutator at the same path.
85
100
  * Uses TInput for the callable args (TOutput is only used internally for validation).
86
101
  */
87
- type ToMutatorTree<S extends Schema, C, T extends MutatorDefinitions<S, C>> = {
88
- readonly [K in keyof T]: T[K] extends MutatorDefinition<infer TInput, any, // TOutput - only used internally for validation
89
- S, C, infer TWrappedTransaction> ? Mutator<TInput, S, C, TWrappedTransaction> : T[K] extends MutatorDefinitions<S, C> ? ToMutatorTree<S, C, T[K]> : never;
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;
90
104
  };
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;
108
+ }[keyof MD];
91
109
  export declare function iterateMutators(registry: AnyMutatorRegistry): Iterable<AnyMutator>;
92
110
  export {};
93
111
  //# 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":"AAAA,OAAO,EAAY,KAAK,SAAS,EAAC,MAAM,mCAAmC,CAAC;AAM5E,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACd,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,mCAAmC,CAAC;AAG9D,OAAO,EAGL,KAAK,UAAU,EAEf,K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eOverrides) {
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,mBAAmB,QAAW;AAEhC,QAAI;AACJ,QAAI,CAAC,kBAAkB,iBAAiB,GAAG;AACzC,aAAO;AAAA,QACL;AAAA,QACA,CAAA;AAAA,MAAC;AAAA,IAEL,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,WACd,UACA,MACwB;AACxB,QAAM,IAAI,eAAe,UAAU,MAAM,GAAG;AAC5C,SAAO;AACT;AAMO,SAAS,eACd,UACA,MACY;AACZ,QAAM,UAAU,WAAW,UAAU,IAAI;AACzC,MAAI,YAAY,QAAW;AACzB,UAAM,IAAI,MAAM,sBAAsB,IAAI,EAAE;AAAA,EAC9C;AACA,SAAO;AACT;AAKO,SAAS,kBACd,OAC0D;AAC1D,SACE,OAAO,UAAU,YAAY,UAAU,QAAQ,sBAAsB;AAEzE;AAuCA,MAAM,qBAAqB,OAAO,iBAAiB;AAsBnD,SAAS,cAOP,MACA,YAO+C;AAC/C,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,UAC2E;AAAA,IAC3E;AAAA,IAMA;AAAA,EAAA;AAEF,UAAQ,cAAc;AACtB,UAAQ,KAAK;AAEb,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":["// 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,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;AAEb,SAAO;AAMT;AAEO,UAAU,gBACf,UACsB;AACtB,SAAO,cAAc,UAAU,SAAS;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
- declare const defineMutatorTag: unique symbol;
7
- export declare function isMutatorDefinition<TInput extends ReadonlyJSONValue | undefined, TOutput extends ReadonlyJSONValue | undefined, TSchema extends Schema, TContext, TWrappedTransaction = unknown>(f: unknown): f is MutatorDefinition<TInput, TOutput, TSchema, TContext, TWrappedTransaction>;
8
- export type MutatorDefinition<TInput extends ReadonlyJSONValue | undefined, TOutput extends ReadonlyJSONValue | undefined, TSchema extends Schema = DefaultSchema, TContext = DefaultContext, TWrappedTransaction = DefaultWrappedTransaction> = ((options: {
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: Transaction<TSchema, TWrappedTransaction>;
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, TSchema, TContext, TWrappedTransaction>;
21
- export declare function defineMutator<TArgs extends ReadonlyJSONValue | undefined, TSchema extends Schema = DefaultSchema, TContext = DefaultContext, TWrappedTransaction = DefaultWrappedTransaction>(mutator: (options: {
22
- args: TArgs;
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<TArgs, TArgs, TSchema, TContext, TWrappedTransaction>;
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 TArgsInput - The argument type accepted by the callable (before validation)
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<TArgsInput extends ReadonlyJSONValue | undefined, TSchema extends Schema = DefaultSchema, TContext = DefaultContext, TWrappedTransaction = DefaultWrappedTransaction> = MutatorCallable<TSchema, TContext, TArgsInput, TWrappedTransaction> & {
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: TArgsInput;
77
+ args: TInput;
52
78
  ctx: TContext;
53
- tx: AnyTransaction;
79
+ tx: Transaction<TSchema, TWrappedTransaction>;
54
80
  }) => Promise<void>;
55
81
  };
56
- type MutatorCallable<TSchema extends Schema, TContext, TArgsInput extends ReadonlyJSONValue | undefined, TWrappedTransaction> = [TArgsInput] extends [undefined] ? () => MutationRequest<TArgsInput, TSchema, TContext, TWrappedTransaction> : undefined extends TArgsInput ? (args?: TArgsInput) => MutationRequest<TArgsInput, TSchema, TContext, TWrappedTransaction> : (args: TArgsInput) => MutationRequest<TArgsInput, TSchema, TContext, TWrappedTransaction>;
57
- export type AnyMutator = Mutator<any, Schema, any, 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 TArgsInput - The argument type (before validation, sent to server)
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<TArgsInput extends ReadonlyJSONValue | undefined, TSchema extends Schema, TContext, TWrappedTransaction> = {
70
- readonly mutator: Mutator<TArgsInput, TSchema, TContext, TWrappedTransaction>;
71
- readonly args: TArgsInput;
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,EA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AAgB,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" && !!f[defineMutatorTag];
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[defineMutatorTag] = true;
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 +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;AAC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M,EACZ,IAAI,EAAE,aAAa,CAAC,iBAAiB,CAAC,GACrC,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,SAAS,MAAM,OAAO,CAAC,QAAQ,CAAC,GAAG,MAAM,EAC/C,OAAO,SAAS,UAAU,EAC1B,OAAO,EAEP,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,GACrC,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAG1C;AAED,wBAAgB,gBAAgB,CAC9B,MAAM,SAAS,MAAM,OAAO,CAAC,QAAQ,CAAC,GAAG,MAAM,EAC/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("QueryInternals");
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('QueryInternals');\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);\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,OAAO,gBAAgB;AAuEjD,SAAS,iBAKd,OAC0C;AAC1C,SAAO,qBAAqB,KAAK;AACjC,SAAO;AACT;"}
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;"}