@nxgt/graphql-validation 0.0.0-stage → 0.1.0

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 (95) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +209 -2
  3. package/dist/bad-user-input.d.ts +35 -0
  4. package/dist/bad-user-input.d.ts.map +1 -0
  5. package/dist/builder/args-schema.d.ts +17 -0
  6. package/dist/builder/args-schema.d.ts.map +1 -0
  7. package/dist/builder/constraints.d.ts +16 -0
  8. package/dist/builder/constraints.d.ts.map +1 -0
  9. package/dist/builder/input-schema.d.ts +31 -0
  10. package/dist/builder/input-schema.d.ts.map +1 -0
  11. package/dist/builder/leaf.d.ts +14 -0
  12. package/dist/builder/leaf.d.ts.map +1 -0
  13. package/dist/chunks/index-n3hypgpf.js +315 -0
  14. package/dist/chunks/index-n3hypgpf.js.map +37 -0
  15. package/dist/cli.d.ts +3 -0
  16. package/dist/cli.d.ts.map +1 -0
  17. package/dist/cli.js +69 -0
  18. package/dist/cli.js.map +11 -0
  19. package/dist/constraint-directive.d.ts +21 -0
  20. package/dist/constraint-directive.d.ts.map +1 -0
  21. package/dist/formats/all.d.ts +9 -0
  22. package/dist/formats/all.d.ts.map +1 -0
  23. package/dist/formats/byte.d.ts +2 -0
  24. package/dist/formats/byte.d.ts.map +1 -0
  25. package/dist/formats/date-time.d.ts +2 -0
  26. package/dist/formats/date-time.d.ts.map +1 -0
  27. package/dist/formats/date.d.ts +2 -0
  28. package/dist/formats/date.d.ts.map +1 -0
  29. package/dist/formats/email.d.ts +2 -0
  30. package/dist/formats/email.d.ts.map +1 -0
  31. package/dist/formats/format.d.ts +15 -0
  32. package/dist/formats/format.d.ts.map +1 -0
  33. package/dist/formats/index.d.ts +13 -0
  34. package/dist/formats/index.d.ts.map +1 -0
  35. package/dist/formats/ipv4.d.ts +2 -0
  36. package/dist/formats/ipv4.d.ts.map +1 -0
  37. package/dist/formats/ipv6.d.ts +2 -0
  38. package/dist/formats/ipv6.d.ts.map +1 -0
  39. package/dist/formats/uri.d.ts +2 -0
  40. package/dist/formats/uri.d.ts.map +1 -0
  41. package/dist/formats/uuid.d.ts +2 -0
  42. package/dist/formats/uuid.d.ts.map +1 -0
  43. package/dist/index.d.ts +6 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +315 -0
  46. package/dist/index.js.map +16 -0
  47. package/dist/rules/all.d.ts +16 -0
  48. package/dist/rules/all.d.ts.map +1 -0
  49. package/dist/rules/contains.d.ts +2 -0
  50. package/dist/rules/contains.d.ts.map +1 -0
  51. package/dist/rules/ends-with.d.ts +2 -0
  52. package/dist/rules/ends-with.d.ts.map +1 -0
  53. package/dist/rules/exclusive-max.d.ts +2 -0
  54. package/dist/rules/exclusive-max.d.ts.map +1 -0
  55. package/dist/rules/exclusive-min.d.ts +2 -0
  56. package/dist/rules/exclusive-min.d.ts.map +1 -0
  57. package/dist/rules/format.d.ts +2 -0
  58. package/dist/rules/format.d.ts.map +1 -0
  59. package/dist/rules/index.d.ts +26 -0
  60. package/dist/rules/index.d.ts.map +1 -0
  61. package/dist/rules/max-items.d.ts +2 -0
  62. package/dist/rules/max-items.d.ts.map +1 -0
  63. package/dist/rules/max-length.d.ts +2 -0
  64. package/dist/rules/max-length.d.ts.map +1 -0
  65. package/dist/rules/max.d.ts +2 -0
  66. package/dist/rules/max.d.ts.map +1 -0
  67. package/dist/rules/min-items.d.ts +2 -0
  68. package/dist/rules/min-items.d.ts.map +1 -0
  69. package/dist/rules/min-length.d.ts +2 -0
  70. package/dist/rules/min-length.d.ts.map +1 -0
  71. package/dist/rules/min.d.ts +2 -0
  72. package/dist/rules/min.d.ts.map +1 -0
  73. package/dist/rules/multiple-of.d.ts +2 -0
  74. package/dist/rules/multiple-of.d.ts.map +1 -0
  75. package/dist/rules/not-contains.d.ts +2 -0
  76. package/dist/rules/not-contains.d.ts.map +1 -0
  77. package/dist/rules/pattern.d.ts +2 -0
  78. package/dist/rules/pattern.d.ts.map +1 -0
  79. package/dist/rules/rule.d.ts +55 -0
  80. package/dist/rules/rule.d.ts.map +1 -0
  81. package/dist/rules/starts-with.d.ts +2 -0
  82. package/dist/rules/starts-with.d.ts.map +1 -0
  83. package/dist/typedefs-command.d.ts +10 -0
  84. package/dist/typedefs-command.d.ts.map +1 -0
  85. package/dist/validated.d.ts +22 -0
  86. package/dist/validated.d.ts.map +1 -0
  87. package/dist/with-validation.d.ts +26 -0
  88. package/dist/with-validation.d.ts.map +1 -0
  89. package/docs/README.md +15 -0
  90. package/docs/guide/constraints.md +291 -0
  91. package/docs/guide/errors.md +194 -0
  92. package/docs/roadmap.md +30 -0
  93. package/docs/troubleshooting.md +260 -0
  94. package/graphql/constraint.graphqls +20 -0
  95. package/package.json +67 -5
@@ -0,0 +1,6 @@
1
+ export { type BadUserInputExtensions, badUserInput, type ValidationIssue, } from './bad-user-input';
2
+ export { constraintTypeDefs } from './constraint-directive';
3
+ export type { ConstraintArgument } from './rules';
4
+ export { type ArgsSchema, type SchemaOf, validated } from './validated';
5
+ export { withValidation } from './with-validation';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,sBAAsB,EAC3B,YAAY,EACZ,KAAK,eAAe,GACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,YAAY,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,315 @@
1
+ import {
2
+ rules,
3
+ applyRule,
4
+ constraintOf,
5
+ constraintTypeDefs2,
6
+ assertOwnConstraint
7
+ } from "./chunks/index-n3hypgpf.js";
8
+
9
+ // src/bad-user-input.ts
10
+ import { GraphQLError } from "graphql";
11
+ function issuesOf(error, constraintOf) {
12
+ return error.issues.map((issue) => {
13
+ const path = issue.path.map((key) => typeof key === "number" ? key : String(key));
14
+ const constraint = constraintOf?.(issue);
15
+ return constraint ? { path, message: issue.message, code: issue.code, constraint } : { path, message: issue.message, code: issue.code };
16
+ });
17
+ }
18
+ function errorOf(where, issues) {
19
+ const [first] = issues;
20
+ const reason = first ? `${first.path.join(".") || "arguments"}: ${first.message}` : "refused";
21
+ const extensions = { code: "BAD_USER_INPUT", issues };
22
+ return new GraphQLError(`Invalid arguments for ${where}. ${reason}`, {
23
+ extensions
24
+ });
25
+ }
26
+ function badUserInput(where, error) {
27
+ return errorOf(where, issuesOf(error));
28
+ }
29
+ async function parseArgs(schema, args, where, constraintOf) {
30
+ const result = await schema.safeParseAsync(args);
31
+ if (!result.success)
32
+ throw errorOf(where, issuesOf(result.error, constraintOf));
33
+ return result.data;
34
+ }
35
+ // src/validated.ts
36
+ import { z } from "zod";
37
+ function validated(schema, resolve) {
38
+ const checked = "_zod" in schema ? schema : z.object(schema);
39
+ return async (source, args, context, info) => {
40
+ const where = `${info.parentType.name}.${info.fieldName}`;
41
+ const parsed = await parseArgs(checked, args, where);
42
+ return await resolve(source, parsed, context, info);
43
+ };
44
+ }
45
+ // src/with-validation.ts
46
+ import {
47
+ defaultFieldResolver,
48
+ isInterfaceType,
49
+ isObjectType
50
+ } from "graphql";
51
+
52
+ // src/builder/args-schema.ts
53
+ import { z as z2 } from "zod";
54
+
55
+ // src/builder/constraints.ts
56
+ import {
57
+ getDirectiveValues
58
+ } from "graphql";
59
+ function constraintsOn(directive, node) {
60
+ if (!directive || !node)
61
+ return [];
62
+ const values = getDirectiveValues(directive, { directives: node.directives ?? [] }) ?? {};
63
+ return Object.entries(values).filter(([, value]) => value !== undefined && value !== null).map(([argument, value]) => ({
64
+ rule: rules[argument],
65
+ value
66
+ })).sort((a, b) => Number(Boolean(b.rule.base)) - Number(Boolean(a.rule.base)));
67
+ }
68
+
69
+ // src/builder/args-schema.ts
70
+ function argsSchemaOf(inputs, parent, field) {
71
+ if (!field.args.some((arg) => inputs.needsCheck(arg)))
72
+ return;
73
+ return z2.object(Object.fromEntries(field.args.map((arg) => [
74
+ arg.name,
75
+ inputs.of(arg, `${parent}.${field.name}(${arg.name}:)`)
76
+ ])));
77
+ }
78
+ function signature(inputs, arg) {
79
+ return constraintsOn(inputs.directive, arg.astNode).map(({ rule, value }) => `${rule.argument}: ${JSON.stringify(value)}`).sort().join(", ");
80
+ }
81
+ var written = (signature) => signature ? `@constraint(${signature})` : "no @constraint";
82
+ function assertInterfaceConstraintsKept(inputs, type) {
83
+ for (const contract of type.getInterfaces()) {
84
+ for (const [name, declared] of Object.entries(contract.getFields())) {
85
+ const field = type.getFields()[name];
86
+ for (const arg of declared.args) {
87
+ const wanted = signature(inputs, arg);
88
+ if (!wanted)
89
+ continue;
90
+ const own = field?.args.find(({ name: argName }) => argName === arg.name);
91
+ const found = own ? signature(inputs, own) : wanted;
92
+ if (found !== wanted) {
93
+ const verb = found ? "differs on" : "is not repeated on";
94
+ throw new Error(`@constraint on ${contract.name}.${name}(${arg.name}:) ${verb} ${type.name}.${name}(${arg.name}:), which resolves it (${written(wanted)} there, ${written(found)} here). Write the same @constraint on both.`);
95
+ }
96
+ }
97
+ }
98
+ }
99
+ }
100
+
101
+ // src/builder/input-schema.ts
102
+ import {
103
+ getNamedType,
104
+ isInputObjectType,
105
+ isListType,
106
+ isNonNullType,
107
+ valueFromAST
108
+ } from "graphql";
109
+ import { z as z4 } from "zod";
110
+
111
+ // src/builder/leaf.ts
112
+ import {
113
+ GraphQLFloat,
114
+ GraphQLID,
115
+ GraphQLInt,
116
+ GraphQLString
117
+ } from "graphql";
118
+ import { z as z3 } from "zod";
119
+ var kinds = {
120
+ [GraphQLString.name]: "string",
121
+ [GraphQLID.name]: "string",
122
+ [GraphQLInt.name]: "number",
123
+ [GraphQLFloat.name]: "number"
124
+ };
125
+ function baseOf(type) {
126
+ if (type.name === GraphQLInt.name)
127
+ return z3.number().int();
128
+ return kinds[type.name] === "number" ? z3.number() : z3.string();
129
+ }
130
+ function leafSchema(type, constraints, where) {
131
+ if (constraints.length === 0)
132
+ return z3.unknown();
133
+ const kind = kinds[type.name];
134
+ let schema = baseOf(type);
135
+ for (const { rule, value } of constraints) {
136
+ if (rule.target !== kind) {
137
+ throw new Error(`@constraint(${rule.argument}) on ${where} needs ${describeTarget(rule.target)}, not ${type.name}.`);
138
+ }
139
+ schema = applyRule(rule, schema, value);
140
+ }
141
+ return schema;
142
+ }
143
+ function describeTarget(target) {
144
+ if (target === "string")
145
+ return "a String or an ID";
146
+ if (target === "number")
147
+ return "an Int or a Float";
148
+ return "a list";
149
+ }
150
+
151
+ // src/builder/input-schema.ts
152
+ class InputSchemas {
153
+ directive;
154
+ #objects = new Map;
155
+ #defaults = [];
156
+ #constrained = new Set;
157
+ constructor(schema) {
158
+ this.directive = schema.getDirective("constraint") ?? undefined;
159
+ const objects = Object.values(schema.getTypeMap()).filter(isInputObjectType);
160
+ for (let changed = true;changed; ) {
161
+ changed = false;
162
+ for (const type of objects) {
163
+ if (this.#constrained.has(type.name))
164
+ continue;
165
+ const constrained = Object.values(type.getFields()).some((field) => constraintsOn(this.directive, field.astNode).length > 0 || this.isConstrained(field.type));
166
+ if (constrained) {
167
+ this.#constrained.add(type.name);
168
+ changed = true;
169
+ }
170
+ }
171
+ }
172
+ }
173
+ isConstrained(type) {
174
+ const named = getNamedType(type);
175
+ return isInputObjectType(named) && this.#constrained.has(named.name);
176
+ }
177
+ buildAll(schema) {
178
+ for (const type of Object.values(schema.getTypeMap())) {
179
+ if (isInputObjectType(type))
180
+ this.#object(type);
181
+ }
182
+ }
183
+ needsCheck(input) {
184
+ return constraintsOn(this.directive, input.astNode).length > 0 || this.isConstrained(input.type);
185
+ }
186
+ of(input, where) {
187
+ const schema = this.#typed(input.type, constraintsOn(this.directive, input.astNode), where);
188
+ const literal = input.astNode?.defaultValue;
189
+ if (literal)
190
+ this.#defaults.push({ schema, literal, type: input.type, where });
191
+ return schema;
192
+ }
193
+ checkDefaults() {
194
+ for (const { schema, literal, type, where } of this.#defaults.splice(0)) {
195
+ const value = valueFromAST(literal, type);
196
+ if (value === undefined)
197
+ continue;
198
+ const result = schema.safeParse(value);
199
+ if (!result.success) {
200
+ throw new Error(`The default value of ${where} breaks its @constraint: ${result.error.issues[0]?.message}`);
201
+ }
202
+ }
203
+ }
204
+ #typed(type, constraints, where) {
205
+ if (isNonNullType(type))
206
+ return this.#required(type.ofType, constraints, where);
207
+ return this.#required(type, constraints, where).nullish();
208
+ }
209
+ #required(type, constraints, where) {
210
+ if (isNonNullType(type))
211
+ return this.#required(type.ofType, constraints, where);
212
+ if (isListType(type)) {
213
+ const own = constraints.filter(({ rule }) => rule.target === "list");
214
+ const items = constraints.filter(({ rule }) => rule.target !== "list");
215
+ let list = z4.array(this.#typed(type.ofType, items, where));
216
+ for (const { rule, value } of own)
217
+ list = applyRule(rule, list, value);
218
+ return list;
219
+ }
220
+ if (isInputObjectType(type)) {
221
+ const list = constraints.find(({ rule }) => rule.target === "list");
222
+ const first = list ?? constraints[0];
223
+ if (first) {
224
+ throw new Error(`@constraint(${first.rule.argument}) on ${where} needs ${describeTarget(first.rule.target)}, not ${type.name}.`);
225
+ }
226
+ return this.#object(type);
227
+ }
228
+ const misplaced = constraints.find(({ rule }) => rule.target === "list");
229
+ if (misplaced) {
230
+ throw new Error(`@constraint(${misplaced.rule.argument}) on ${where} needs a list, not ${type.name}.`);
231
+ }
232
+ return leafSchema(type, constraints, where);
233
+ }
234
+ #object(type) {
235
+ if (!this.isConstrained(type))
236
+ return z4.unknown();
237
+ const built = this.#objects.get(type.name);
238
+ if (built)
239
+ return built;
240
+ let schema;
241
+ this.#objects.set(type.name, z4.lazy(() => schema));
242
+ schema = z4.object(Object.fromEntries(Object.values(type.getFields()).map((field) => [
243
+ field.name,
244
+ this.of(field, `${type.name}.${field.name}`)
245
+ ])));
246
+ this.#objects.set(type.name, schema);
247
+ return schema;
248
+ }
249
+ }
250
+
251
+ // src/with-validation.ts
252
+ var wrapped = Symbol.for("@nxgt/graphql-validation/wrapped");
253
+ function checking(schema, where, resolve) {
254
+ const check = async (source, args, context, info) => await resolve(source, await parseArgs(schema, args, where, constraintOf), context, info);
255
+ check[wrapped] = true;
256
+ return check;
257
+ }
258
+ function wrap(field, args, where, subscription) {
259
+ const subscribe = field.subscribe ?? (subscription ? defaultFieldResolver : undefined);
260
+ if (subscribe) {
261
+ if (!subscribe[wrapped])
262
+ field.subscribe = checking(args, where, subscribe);
263
+ return;
264
+ }
265
+ const resolve = field.resolve ?? defaultFieldResolver;
266
+ if (!resolve[wrapped])
267
+ field.resolve = checking(args, where, resolve);
268
+ }
269
+ function assertNoDirectiveArgumentConstrained(inputs, schema) {
270
+ for (const directive of schema.getDirectives()) {
271
+ for (const arg of directive.args) {
272
+ if (constraintsOn(inputs.directive, arg.astNode).length > 0) {
273
+ throw new Error(`@constraint on @${directive.name}(${arg.name}:) checks nothing: a directive's argument reaches no resolver. Remove it.`);
274
+ }
275
+ }
276
+ }
277
+ }
278
+ function withValidation(schema) {
279
+ const inputs = new InputSchemas(schema);
280
+ if (!inputs.directive) {
281
+ throw new Error("withValidation: this schema declares no @constraint directive. Add constraintTypeDefs to its type definitions.");
282
+ }
283
+ assertOwnConstraint(inputs.directive);
284
+ inputs.buildAll(schema);
285
+ assertNoDirectiveArgumentConstrained(inputs, schema);
286
+ for (const type of Object.values(schema.getTypeMap())) {
287
+ if (type.name.startsWith("__"))
288
+ continue;
289
+ if (isInterfaceType(type)) {
290
+ for (const field of Object.values(type.getFields()))
291
+ argsSchemaOf(inputs, type.name, field);
292
+ }
293
+ if (!isObjectType(type))
294
+ continue;
295
+ assertInterfaceConstraintsKept(inputs, type);
296
+ for (const field of Object.values(type.getFields())) {
297
+ const args = argsSchemaOf(inputs, type.name, field);
298
+ if (args) {
299
+ const subscription = type === schema.getSubscriptionType();
300
+ wrap(field, args, `${type.name}.${field.name}`, subscription);
301
+ }
302
+ }
303
+ }
304
+ inputs.checkDefaults();
305
+ return schema;
306
+ }
307
+ export {
308
+ badUserInput,
309
+ constraintTypeDefs2 as constraintTypeDefs,
310
+ validated,
311
+ withValidation
312
+ };
313
+
314
+ //# debugId=E5B8091B29212FAF64756E2164756E21
315
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,16 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/bad-user-input.ts", "../src/validated.ts", "../src/with-validation.ts", "../src/builder/args-schema.ts", "../src/builder/constraints.ts", "../src/builder/input-schema.ts", "../src/builder/leaf.ts"],
4
+ "sourcesContent": [
5
+ "import { GraphQLError } from 'graphql';\nimport type { z } from 'zod';\nimport type { ConstraintArgument } from './rules';\n\n/** One reason an input was refused, at its path inside the arguments. */\nexport interface ValidationIssue {\n\t/** `['input', 'address', 'zip']`: the argument, then the input fields. */\n\treadonly path: readonly (string | number)[];\n\treadonly message: string;\n\t/** Zod's issue code: `too_small`, `invalid_format`, `custom`, ... */\n\treadonly code: string;\n\t/**\n\t * The `@constraint` argument that refused (`minLength`, `format`), when a\n\t * directive did: stable across Zod versions, unlike `code`. Absent for a\n\t * refusal of `validated()`'s own schema.\n\t */\n\treadonly constraint?: ConstraintArgument;\n}\n\n/** The `extensions` of the error an invalid input becomes. */\nexport type BadUserInputExtensions = {\n\treadonly code: 'BAD_USER_INPUT';\n\treadonly issues: readonly ValidationIssue[];\n};\n\n/** Names the `@constraint` argument behind an issue, when there is one. */\nexport type ConstraintOf = (\n\tissue: z.core.$ZodIssue,\n) => ConstraintArgument | undefined;\n\nfunction issuesOf(\n\terror: z.ZodError,\n\tconstraintOf?: ConstraintOf,\n): ValidationIssue[] {\n\treturn error.issues.map((issue) => {\n\t\tconst path = issue.path.map((key) =>\n\t\t\ttypeof key === 'number' ? key : String(key),\n\t\t);\n\t\tconst constraint = constraintOf?.(issue);\n\t\treturn constraint\n\t\t\t? { path, message: issue.message, code: issue.code, constraint }\n\t\t\t: { path, message: issue.message, code: issue.code };\n\t});\n}\n\nfunction errorOf(where: string, issues: ValidationIssue[]): GraphQLError {\n\tconst [first] = issues;\n\tconst reason = first\n\t\t? `${first.path.join('.') || 'arguments'}: ${first.message}`\n\t\t: 'refused';\n\tconst extensions: BadUserInputExtensions = { code: 'BAD_USER_INPUT', issues };\n\treturn new GraphQLError(`Invalid arguments for ${where}. ${reason}`, {\n\t\textensions,\n\t});\n}\n\n/**\n * The one error an invalid input becomes: `extensions.code` is\n * `BAD_USER_INPUT`, the code Apollo and most clients already read, and\n * `extensions.issues` lists every reason with its path, so a form can show\n * each one beside its field. The message names the field and the first\n * reason, for a log line.\n */\nexport function badUserInput(where: string, error: z.ZodError): GraphQLError {\n\treturn errorOf(where, issuesOf(error));\n}\n\n/** The parsed arguments, or the error above, its issues named by `constraintOf`. */\nexport async function parseArgs(\n\tschema: z.ZodType,\n\targs: unknown,\n\twhere: string,\n\tconstraintOf?: ConstraintOf,\n): Promise<unknown> {\n\tconst result = await schema.safeParseAsync(args);\n\tif (!result.success)\n\t\tthrow errorOf(where, issuesOf(result.error, constraintOf));\n\treturn result.data;\n}\n",
6
+ "import type { GraphQLFieldResolver, GraphQLResolveInfo } from 'graphql';\nimport { z } from 'zod';\nimport { parseArgs } from './bad-user-input';\n\n/** An object schema of the arguments, or its shape. */\nexport type ArgsSchema = z.ZodType<Record<string, unknown>> | z.ZodRawShape;\n\n/** The schema `ArgsSchema` stands for. */\nexport type SchemaOf<S extends ArgsSchema> = S extends z.ZodType\n\t? S\n\t: z.ZodObject<S & z.ZodRawShape>;\n\n/**\n * A resolver whose arguments are checked by `schema` before it runs, for what\n * a `@constraint` cannot say: a rule across arguments, a business refinement,\n * an async check. It receives the parsed arguments (`z.output`), defaults and\n * transforms applied; an invalid input is the same `BAD_USER_INPUT` error as\n * the directives'.\n *\n * ```ts\n * signUp: validated(\n * z.object({ input: signUpSchema }).refine(({ input }) => input.password !== input.email),\n * (_, { input }) => users.create(input),\n * )\n * ```\n */\nexport function validated<\n\tS extends ArgsSchema,\n\tTSource = unknown,\n\tTContext = unknown,\n\tTResult = unknown,\n>(\n\tschema: S,\n\tresolve: (\n\t\tsource: TSource,\n\t\targs: z.output<SchemaOf<S>>,\n\t\tcontext: TContext,\n\t\tinfo: GraphQLResolveInfo,\n\t) => TResult,\n): GraphQLFieldResolver<\n\tTSource,\n\tTContext,\n\tz.input<SchemaOf<S>>,\n\tPromise<Awaited<TResult>>\n> {\n\t// `_zod`, not `instanceof`: a schema from another copy of zod is still one.\n\tconst checked = (\n\t\t'_zod' in schema ? schema : z.object(schema as z.ZodRawShape)\n\t) as z.ZodType;\n\treturn async (source, args, context, info): Promise<Awaited<TResult>> => {\n\t\tconst where = `${info.parentType.name}.${info.fieldName}`;\n\t\tconst parsed = (await parseArgs(checked, args, where)) as z.output<\n\t\t\tSchemaOf<S>\n\t\t>;\n\t\treturn await resolve(source, parsed, context, info);\n\t};\n}\n",
7
+ "import {\n\tdefaultFieldResolver,\n\ttype GraphQLField,\n\ttype GraphQLFieldResolver,\n\ttype GraphQLSchema,\n\tisInterfaceType,\n\tisObjectType,\n} from 'graphql';\nimport type { z } from 'zod';\nimport { parseArgs } from './bad-user-input';\nimport {\n\targsSchemaOf,\n\tassertInterfaceConstraintsKept,\n} from './builder/args-schema';\nimport { constraintsOn } from './builder/constraints';\nimport { InputSchemas } from './builder/input-schema';\nimport { assertOwnConstraint } from './constraint-directive';\nimport { constraintOf } from './rules';\n\n// Symbol.for: two copies of the package in one tree still wrap a field once.\nconst wrapped = Symbol.for('@nxgt/graphql-validation/wrapped');\n\ntype Resolver = GraphQLFieldResolver<unknown, unknown> & { [wrapped]?: true };\n\nfunction checking(\n\tschema: z.ZodType,\n\twhere: string,\n\tresolve: Resolver,\n): Resolver {\n\tconst check: Resolver = async (source, args, context, info) =>\n\t\tawait resolve(\n\t\t\tsource,\n\t\t\tawait parseArgs(schema, args, where, constraintOf),\n\t\t\tcontext,\n\t\t\tinfo,\n\t\t);\n\tcheck[wrapped] = true;\n\treturn check;\n}\n\n/**\n * Wraps a field once. A subscription field is checked in `subscribe`, which\n * runs once per subscription — graphql's default one when the field has none\n * — and its `resolve` runs once per event, with the same arguments, already\n * checked.\n */\nfunction wrap(\n\tfield: GraphQLField<unknown, unknown>,\n\targs: z.ZodType,\n\twhere: string,\n\tsubscription: boolean,\n): void {\n\tconst subscribe = (field.subscribe ??\n\t\t(subscription ? defaultFieldResolver : undefined)) as Resolver | undefined;\n\tif (subscribe) {\n\t\tif (!subscribe[wrapped]) field.subscribe = checking(args, where, subscribe);\n\t\treturn;\n\t}\n\tconst resolve = (field.resolve ?? defaultFieldResolver) as Resolver;\n\tif (!resolve[wrapped]) field.resolve = checking(args, where, resolve);\n}\n\n/**\n * Fails on a `@constraint` written on a directive's argument: graphql allows\n * it there (ARGUMENT_DEFINITION), but no resolver receives that argument, so\n * it would check nothing.\n */\nfunction assertNoDirectiveArgumentConstrained(\n\tinputs: InputSchemas,\n\tschema: GraphQLSchema,\n): void {\n\tfor (const directive of schema.getDirectives()) {\n\t\tfor (const arg of directive.args) {\n\t\t\tif (constraintsOn(inputs.directive, arg.astNode).length > 0) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`@constraint on @${directive.name}(${arg.name}:) checks nothing: a directive's argument reaches no resolver. Remove it.`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Checks every `@constraint` of `schema` before the resolvers run. Each\n * field with a constrained argument — directly, or anywhere inside an input\n * type it takes — gets its resolver (and its `subscribe`) wrapped: the\n * arguments are parsed by the Zod schema the directives describe, the\n * resolver receives the parsed value, and an invalid input becomes one\n * `BAD_USER_INPUT` error. Fields with nothing to check are left untouched.\n *\n * The schema is built here, once: a constraint that cannot apply (a\n * `minLength` on an `Int`, an unknown format, a bad pattern) throws now, not\n * on the first request. The resolvers are wrapped in place and the same\n * schema is returned, so it goes wherever it went before; calling it twice\n * wraps nothing twice. Call it last, once every resolver is attached: a\n * resolver set on a field afterwards replaces the check.\n *\n * A `@constraint` on an interface's argument must be repeated on each\n * object's field, which is the one that resolves; a field that drops it\n * fails here.\n *\n * The directives are read from the SDL (`astNode`), so a schema built from\n * type definitions — `buildSchema`, `makeExecutableSchema`, Yoga, Apollo —\n * is checked; a code-first schema with no SDL has no `@constraint` to read.\n */\nexport function withValidation<S extends GraphQLSchema>(schema: S): S {\n\tconst inputs = new InputSchemas(schema);\n\tif (!inputs.directive) {\n\t\tthrow new Error(\n\t\t\t'withValidation: this schema declares no @constraint directive. Add constraintTypeDefs to its type definitions.',\n\t\t);\n\t}\n\tassertOwnConstraint(inputs.directive);\n\tinputs.buildAll(schema);\n\tassertNoDirectiveArgumentConstrained(inputs, schema);\n\tfor (const type of Object.values(schema.getTypeMap())) {\n\t\tif (type.name.startsWith('__')) continue;\n\t\t// An interface's fields resolve on its objects: built for their errors only.\n\t\tif (isInterfaceType(type)) {\n\t\t\tfor (const field of Object.values(type.getFields()))\n\t\t\t\targsSchemaOf(inputs, type.name, field);\n\t\t}\n\t\tif (!isObjectType(type)) continue;\n\t\tassertInterfaceConstraintsKept(inputs, type);\n\t\tfor (const field of Object.values(type.getFields()) as GraphQLField<\n\t\t\tunknown,\n\t\t\tunknown\n\t\t>[]) {\n\t\t\tconst args = argsSchemaOf(inputs, type.name, field);\n\t\t\tif (args) {\n\t\t\t\tconst subscription = type === schema.getSubscriptionType();\n\t\t\t\twrap(field, args, `${type.name}.${field.name}`, subscription);\n\t\t\t}\n\t\t}\n\t}\n\tinputs.checkDefaults();\n\treturn schema;\n}\n",
8
+ "import type { GraphQLArgument, GraphQLField, GraphQLObjectType } from 'graphql';\nimport { z } from 'zod';\nimport { constraintsOn } from './constraints';\nimport type { InputSchemas } from './input-schema';\n\n/**\n * The schema of a field's arguments, or `undefined` when none of them can\n * break a constraint, so a field with nothing to check is left untouched.\n * `parent` is the type's name, for errors: `Mutation.signUp(input:)`.\n */\nexport function argsSchemaOf(\n\tinputs: InputSchemas,\n\tparent: string,\n\tfield: GraphQLField<unknown, unknown>,\n): z.ZodType | undefined {\n\tif (!field.args.some((arg) => inputs.needsCheck(arg))) return undefined;\n\treturn z.object(\n\t\tObject.fromEntries(\n\t\t\tfield.args.map((arg) => [\n\t\t\t\targ.name,\n\t\t\t\tinputs.of(arg, `${parent}.${field.name}(${arg.name}:)`),\n\t\t\t]),\n\t\t),\n\t);\n}\n\n/** The constraints of an argument as written, sorted: `maxLength: 5, min: 1`. */\nfunction signature(inputs: InputSchemas, arg: GraphQLArgument): string {\n\treturn constraintsOn(inputs.directive, arg.astNode)\n\t\t.map(({ rule, value }) => `${rule.argument}: ${JSON.stringify(value)}`)\n\t\t.sort()\n\t\t.join(', ');\n}\n\n/** A signature as it reads in an error. */\nconst written = (signature: string) =>\n\tsignature ? `@constraint(${signature})` : 'no @constraint';\n\n/**\n * Fails when an object type's field does not repeat the `@constraint` its\n * interface writes on an argument. The object's field is the one that\n * resolves, and graphql lets it redeclare the argument bare: the interface's\n * constraint would then check nothing, in silence.\n */\nexport function assertInterfaceConstraintsKept(\n\tinputs: InputSchemas,\n\ttype: GraphQLObjectType,\n): void {\n\tfor (const contract of type.getInterfaces()) {\n\t\tfor (const [name, declared] of Object.entries(contract.getFields())) {\n\t\t\tconst field = type.getFields()[name];\n\t\t\tfor (const arg of declared.args) {\n\t\t\t\tconst wanted = signature(inputs, arg);\n\t\t\t\tif (!wanted) continue;\n\t\t\t\tconst own = field?.args.find(\n\t\t\t\t\t({ name: argName }) => argName === arg.name,\n\t\t\t\t);\n\t\t\t\tconst found = own ? signature(inputs, own) : wanted;\n\t\t\t\tif (found !== wanted) {\n\t\t\t\t\tconst verb = found ? 'differs on' : 'is not repeated on';\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`@constraint on ${contract.name}.${name}(${arg.name}:) ${verb} ${type.name}.${name}(${arg.name}:), which resolves it (${written(wanted)} there, ${written(found)} here). Write the same @constraint on both.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n",
9
+ "import {\n\ttype DirectiveNode,\n\ttype GraphQLDirective,\n\tgetDirectiveValues,\n} from 'graphql';\nimport { type RegisteredRule, rules } from '../rules';\n\n/** One `@constraint` argument written on an argument or an input field. */\nexport interface Constraint {\n\treadonly rule: RegisteredRule;\n\treadonly value: string | number;\n}\n\n/**\n * The constraints written on a node, base rules (`format`) first so the\n * others narrow the schema they produce. Empty when the schema declares no\n * `@constraint` or the node carries none.\n */\nexport function constraintsOn(\n\tdirective: GraphQLDirective | undefined,\n\tnode:\n\t\t| { readonly directives?: ReadonlyArray<DirectiveNode> | undefined }\n\t\t| null\n\t\t| undefined,\n): Constraint[] {\n\tif (!directive || !node) return [];\n\tconst values =\n\t\tgetDirectiveValues(directive, { directives: node.directives ?? [] }) ?? {};\n\treturn Object.entries(values)\n\t\t.filter(([, value]) => value !== undefined && value !== null)\n\t\t.map(([argument, value]) => ({\n\t\t\trule: rules[argument as keyof typeof rules],\n\t\t\tvalue: value as string | number,\n\t\t}))\n\t\t.sort(\n\t\t\t(a, b) => Number(Boolean(b.rule.base)) - Number(Boolean(a.rule.base)),\n\t\t);\n}\n",
10
+ "import {\n\ttype ConstValueNode,\n\ttype GraphQLArgument,\n\ttype GraphQLDirective,\n\ttype GraphQLInputField,\n\ttype GraphQLInputObjectType,\n\ttype GraphQLInputType,\n\ttype GraphQLSchema,\n\tgetNamedType,\n\tisInputObjectType,\n\tisListType,\n\tisNonNullType,\n\tvalueFromAST,\n} from 'graphql';\nimport { z } from 'zod';\nimport { applyRule } from '../rules';\nimport { type Constraint, constraintsOn } from './constraints';\nimport { describeTarget, leafSchema } from './leaf';\n\n/**\n * Builds the schemas of the arguments and input fields of one GraphQL\n * schema, once each: an input type is walked a single time however many\n * fields use it, and a recursive one (`input Filter { and: [Filter!] }`) is\n * reached through `z.lazy`.\n */\nexport class InputSchemas {\n\treadonly directive: GraphQLDirective | undefined;\n\treadonly #objects = new Map<string, z.ZodType>();\n\treadonly #defaults: {\n\t\tschema: z.ZodType;\n\t\tliteral: ConstValueNode;\n\t\ttype: GraphQLInputType;\n\t\twhere: string;\n\t}[] = [];\n\t/** The input types a value can break a constraint inside. */\n\treadonly #constrained = new Set<string>();\n\n\tconstructor(schema: GraphQLSchema) {\n\t\tthis.directive = schema.getDirective('constraint') ?? undefined;\n\t\tconst objects = Object.values(schema.getTypeMap()).filter(\n\t\t\tisInputObjectType,\n\t\t);\n\t\t// A fixpoint, not a memoised walk: in a cycle, a type visited while it\n\t\t// is still being decided would be cached as unconstrained for good.\n\t\tfor (let changed = true; changed; ) {\n\t\t\tchanged = false;\n\t\t\tfor (const type of objects) {\n\t\t\t\tif (this.#constrained.has(type.name)) continue;\n\t\t\t\tconst constrained = Object.values(type.getFields()).some(\n\t\t\t\t\t(field) =>\n\t\t\t\t\t\tconstraintsOn(this.directive, field.astNode).length > 0 ||\n\t\t\t\t\t\tthis.isConstrained(field.type),\n\t\t\t\t);\n\t\t\t\tif (constrained) {\n\t\t\t\t\tthis.#constrained.add(type.name);\n\t\t\t\t\tchanged = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Whether a value of this type can break a constraint anywhere inside. */\n\tisConstrained(type: GraphQLInputType): boolean {\n\t\tconst named = getNamedType(type);\n\t\treturn isInputObjectType(named) && this.#constrained.has(named.name);\n\t}\n\n\t/**\n\t * Builds every constrained input type, reached by an argument or not, so\n\t * a constraint that cannot apply fails at startup wherever it is written.\n\t */\n\tbuildAll(schema: GraphQLSchema): void {\n\t\tfor (const type of Object.values(schema.getTypeMap())) {\n\t\t\tif (isInputObjectType(type)) this.#object(type);\n\t\t}\n\t}\n\n\t/** Whether an argument or input field needs checking at all. */\n\tneedsCheck(input: GraphQLArgument | GraphQLInputField): boolean {\n\t\treturn (\n\t\t\tconstraintsOn(this.directive, input.astNode).length > 0 ||\n\t\t\tthis.isConstrained(input.type)\n\t\t);\n\t}\n\n\t/** The schema of one argument or input field, `where` naming it in errors. */\n\tof(input: GraphQLArgument | GraphQLInputField, where: string): z.ZodType {\n\t\tconst schema = this.#typed(\n\t\t\tinput.type,\n\t\t\tconstraintsOn(this.directive, input.astNode),\n\t\t\twhere,\n\t\t);\n\t\tconst literal = input.astNode?.defaultValue;\n\t\tif (literal)\n\t\t\tthis.#defaults.push({ schema, literal, type: input.type, where });\n\t\treturn schema;\n\t}\n\n\t/**\n\t * Fails when a default value breaks its own constraint: every request that\n\t * leaves the value out would be refused for something the client never\n\t * sent. Run once every schema is built, so a recursive type is complete.\n\t */\n\tcheckDefaults(): void {\n\t\tfor (const { schema, literal, type, where } of this.#defaults.splice(0)) {\n\t\t\t// Coerced as graphql coerces it: a single value for a list, an input\n\t\t\t// object's own field defaults. One graphql refuses is its to report.\n\t\t\tconst value = valueFromAST(literal, type);\n\t\t\tif (value === undefined) continue;\n\t\t\tconst result = schema.safeParse(value);\n\t\t\tif (!result.success) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`The default value of ${where} breaks its @constraint: ${result.error.issues[0]?.message}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t#typed(\n\t\ttype: GraphQLInputType,\n\t\tconstraints: readonly Constraint[],\n\t\twhere: string,\n\t): z.ZodType {\n\t\tif (isNonNullType(type))\n\t\t\treturn this.#required(type.ofType, constraints, where);\n\t\treturn this.#required(type, constraints, where).nullish();\n\t}\n\n\t#required(\n\t\ttype: GraphQLInputType,\n\t\tconstraints: readonly Constraint[],\n\t\twhere: string,\n\t): z.ZodType {\n\t\tif (isNonNullType(type))\n\t\t\treturn this.#required(type.ofType, constraints, where);\n\t\tif (isListType(type)) {\n\t\t\t// minItems and maxItems are the list's; every other rule is its items'.\n\t\t\tconst own = constraints.filter(({ rule }) => rule.target === 'list');\n\t\t\tconst items = constraints.filter(({ rule }) => rule.target !== 'list');\n\t\t\tlet list: z.ZodType = z.array(this.#typed(type.ofType, items, where));\n\t\t\tfor (const { rule, value } of own) list = applyRule(rule, list, value);\n\t\t\treturn list;\n\t\t}\n\t\tif (isInputObjectType(type)) {\n\t\t\tconst list = constraints.find(({ rule }) => rule.target === 'list');\n\t\t\tconst first = list ?? constraints[0];\n\t\t\tif (first) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`@constraint(${first.rule.argument}) on ${where} needs ${describeTarget(first.rule.target)}, not ${type.name}.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn this.#object(type);\n\t\t}\n\t\tconst misplaced = constraints.find(({ rule }) => rule.target === 'list');\n\t\tif (misplaced) {\n\t\t\tthrow new Error(\n\t\t\t\t`@constraint(${misplaced.rule.argument}) on ${where} needs a list, not ${type.name}.`,\n\t\t\t);\n\t\t}\n\t\treturn leafSchema(type, constraints, where);\n\t}\n\n\t#object(type: GraphQLInputObjectType): z.ZodType {\n\t\tif (!this.isConstrained(type)) return z.unknown();\n\t\tconst built = this.#objects.get(type.name);\n\t\tif (built) return built;\n\t\t// Registered before the walk, so a field that comes back here ends.\n\t\tlet schema: z.ZodType | undefined;\n\t\tthis.#objects.set(\n\t\t\ttype.name,\n\t\t\tz.lazy(() => schema as z.ZodType),\n\t\t);\n\t\tschema = z.object(\n\t\t\tObject.fromEntries(\n\t\t\t\tObject.values(type.getFields()).map((field) => [\n\t\t\t\t\tfield.name,\n\t\t\t\t\tthis.of(field, `${type.name}.${field.name}`),\n\t\t\t\t]),\n\t\t\t),\n\t\t);\n\t\tthis.#objects.set(type.name, schema);\n\t\treturn schema;\n\t}\n}\n",
11
+ "import {\n\tGraphQLFloat,\n\tGraphQLID,\n\tGraphQLInt,\n\ttype GraphQLLeafType,\n\tGraphQLString,\n} from 'graphql';\nimport { z } from 'zod';\nimport { applyRule } from '../rules';\nimport type { Target } from '../rules/rule';\nimport type { Constraint } from './constraints';\n\n/** The kind of value each built-in scalar holds once graphql parsed it. */\nconst kinds: Record<string, Exclude<Target, 'list'>> = {\n\t[GraphQLString.name]: 'string',\n\t[GraphQLID.name]: 'string',\n\t[GraphQLInt.name]: 'number',\n\t[GraphQLFloat.name]: 'number',\n};\n\nfunction baseOf(type: GraphQLLeafType): z.ZodType {\n\tif (type.name === GraphQLInt.name) return z.number().int();\n\treturn kinds[type.name] === 'number' ? z.number() : z.string();\n}\n\n/**\n * The schema of a scalar or enum value with its constraints applied. A leaf\n * without any is left as graphql parsed it. A constraint that cannot apply\n * — `minLength` on an `Int`, anything on a custom scalar or an enum — fails\n * here, at startup, naming `where`.\n */\nexport function leafSchema(\n\ttype: GraphQLLeafType,\n\tconstraints: readonly Constraint[],\n\twhere: string,\n): z.ZodType {\n\tif (constraints.length === 0) return z.unknown();\n\tconst kind = kinds[type.name];\n\tlet schema = baseOf(type);\n\tfor (const { rule, value } of constraints) {\n\t\tif (rule.target !== kind) {\n\t\t\tthrow new Error(\n\t\t\t\t`@constraint(${rule.argument}) on ${where} needs ${describeTarget(rule.target)}, not ${type.name}.`,\n\t\t\t);\n\t\t}\n\t\tschema = applyRule(rule, schema, value);\n\t}\n\treturn schema;\n}\n\n/** What a rule's target reads as in an error. */\nexport function describeTarget(target: Target): string {\n\tif (target === 'string') return 'a String or an ID';\n\tif (target === 'number') return 'an Int or a Float';\n\treturn 'a list';\n}\n"
12
+ ],
13
+ "mappings": ";;;;;;;;;AAAA;AA8BA,SAAS,QAAQ,CAChB,OACA,cACoB;AAAA,EACpB,OAAO,MAAM,OAAO,IAAI,CAAC,UAAU;AAAA,IAClC,MAAM,OAAO,MAAM,KAAK,IAAI,CAAC,QAC5B,OAAO,QAAQ,WAAW,MAAM,OAAO,GAAG,CAC3C;AAAA,IACA,MAAM,aAAa,eAAe,KAAK;AAAA,IACvC,OAAO,aACJ,EAAE,MAAM,SAAS,MAAM,SAAS,MAAM,MAAM,MAAM,WAAW,IAC7D,EAAE,MAAM,SAAS,MAAM,SAAS,MAAM,MAAM,KAAK;AAAA,GACpD;AAAA;AAGF,SAAS,OAAO,CAAC,OAAe,QAAyC;AA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,KAAK,MAAM,KAAK;AAAA,IACvC;AAAA,IACA,IAAI,CAAC,aAAa,IAAI;AAAA,MAAG;AAAA,IACzB,+BAA+B,QAAQ,IAAI;AAAA,IAC3C,WAAW,SAAS,OAAO,OAAO,KAAK,UAAU,CAAC,GAG7C;AAAA,MACJ,MAAM,OAAO,aAAa,QAAQ,KAAK,MAAM,KAAK;AAAA,MAClD,IAAI,MAAM;AAAA,QACT,MAAM,eAAe,SAAS,OAAO,oBAAoB;AAAA,QACzD,KAAK,OAAO,MAAM,GAAG,KAAK,QAAQ,MAAM,QAAQ,YAAY;AAAA,MAC7D;AAAA,IACD;AAAA,EACD;AAAA,EACA,OAAO,cAAc;AAAA,EACrB,OAAO;AAAA;",
14
+ "debugId": "E5B8091B29212FAF64756E2164756E21",
15
+ "names": []
16
+ }
@@ -0,0 +1,16 @@
1
+ export * from './contains';
2
+ export * from './ends-with';
3
+ export * from './exclusive-max';
4
+ export * from './exclusive-min';
5
+ export * from './format';
6
+ export * from './max';
7
+ export * from './max-items';
8
+ export * from './max-length';
9
+ export * from './min';
10
+ export * from './min-items';
11
+ export * from './min-length';
12
+ export * from './multiple-of';
13
+ export * from './not-contains';
14
+ export * from './pattern';
15
+ export * from './starts-with';
16
+ //# sourceMappingURL=all.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"all.d.ts","sourceRoot":"","sources":["../../src/rules/all.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,OAAO,CAAC;AACtB,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,OAAO,CAAC;AACtB,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const containsRule: import("./rule").Rule<"contains", "String", "string">;
2
+ //# sourceMappingURL=contains.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contains.d.ts","sourceRoot":"","sources":["../../src/rules/contains.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,YAAY,uDAOvB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const endsWithRule: import("./rule").Rule<"endsWith", "String", "string">;
2
+ //# sourceMappingURL=ends-with.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ends-with.d.ts","sourceRoot":"","sources":["../../src/rules/ends-with.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,YAAY,uDAOvB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const exclusiveMaxRule: import("./rule").Rule<"exclusiveMax", "Float", "number">;
2
+ //# sourceMappingURL=exclusive-max.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exclusive-max.d.ts","sourceRoot":"","sources":["../../src/rules/exclusive-max.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,gBAAgB,0DAU3B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const exclusiveMinRule: import("./rule").Rule<"exclusiveMin", "Float", "number">;
2
+ //# sourceMappingURL=exclusive-min.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exclusive-min.d.ts","sourceRoot":"","sources":["../../src/rules/exclusive-min.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,gBAAgB,0DAU3B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const formatRule: import("./rule").Rule<"format", "String", "string">;
2
+ //# sourceMappingURL=format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/rules/format.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,UAAU,qDASrB,CAAC"}
@@ -0,0 +1,26 @@
1
+ import type { z } from 'zod';
2
+ import * as all from './all';
3
+ /**
4
+ * One of the rules, as its own type: a builder narrows it on `target`, so a
5
+ * number schema never reaches a string rule.
6
+ */
7
+ export type RegisteredRule = (typeof all)[keyof typeof all];
8
+ /** An argument `@constraint` takes. */
9
+ export type ConstraintArgument = RegisteredRule['argument'];
10
+ /**
11
+ * Every rule, keyed by its `@constraint` argument. Derived from what
12
+ * `./all` exports, so a new rule is one file and one line there, and the
13
+ * directive's SDL follows.
14
+ */
15
+ export declare const rules: { readonly [A in ConstraintArgument]: Extract<RegisteredRule, {
16
+ argument: A;
17
+ }>; };
18
+ /**
19
+ * Applies a rule to a schema its caller has already matched to the rule's
20
+ * target: the one place the rule's typed `toZod` meets a schema built from
21
+ * GraphQL types, which the compiler cannot relate.
22
+ */
23
+ export declare function applyRule(rule: RegisteredRule, schema: z.ZodType, value: string | number): z.ZodType;
24
+ /** The `@constraint` argument whose rule refused with this issue, if any. */
25
+ export declare function constraintOf(issue: z.core.$ZodIssue): ConstraintArgument | undefined;
26
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAG7B;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,GAAG,CAAC,CAAC,MAAM,OAAO,GAAG,CAAC,CAAC;AAE5D,uCAAuC;AACvC,MAAM,MAAM,kBAAkB,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;AAE5D;;;;GAIG;AACH,eAAO,MAAM,KAAK,EAEb,EACJ,QAAQ,EAAE,CAAC,IAAI,kBAAkB,GAAG,OAAO,CAAC,cAAc,EAAE;IAAE,QAAQ,EAAE,CAAC,CAAA;CAAE,CAAC,GAC5E,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,SAAS,CACxB,IAAI,EAAE,cAAc,EACpB,MAAM,EAAE,CAAC,CAAC,OAAO,EACjB,KAAK,EAAE,MAAM,GAAG,MAAM,GACpB,CAAC,CAAC,OAAO,CAMX;AAED,6EAA6E;AAC7E,wBAAgB,YAAY,CAC3B,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,SAAS,GACrB,kBAAkB,GAAG,SAAS,CAGhC"}
@@ -0,0 +1,2 @@
1
+ export declare const maxItemsRule: import("./rule").Rule<"maxItems", "Int", "list">;
2
+ //# sourceMappingURL=max-items.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"max-items.d.ts","sourceRoot":"","sources":["../../src/rules/max-items.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,YAAY,kDAOvB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const maxLengthRule: import("./rule").Rule<"maxLength", "Int", "string">;
2
+ //# sourceMappingURL=max-length.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"max-length.d.ts","sourceRoot":"","sources":["../../src/rules/max-length.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,qDAOxB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const maxRule: import("./rule").Rule<"max", "Float", "number">;
2
+ //# sourceMappingURL=max.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"max.d.ts","sourceRoot":"","sources":["../../src/rules/max.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,iDAUlB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const minItemsRule: import("./rule").Rule<"minItems", "Int", "list">;
2
+ //# sourceMappingURL=min-items.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"min-items.d.ts","sourceRoot":"","sources":["../../src/rules/min-items.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,YAAY,kDAOvB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const minLengthRule: import("./rule").Rule<"minLength", "Int", "string">;
2
+ //# sourceMappingURL=min-length.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"min-length.d.ts","sourceRoot":"","sources":["../../src/rules/min-length.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,qDAOxB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const minRule: import("./rule").Rule<"min", "Float", "number">;
2
+ //# sourceMappingURL=min.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"min.d.ts","sourceRoot":"","sources":["../../src/rules/min.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,iDAUlB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const multipleOfRule: import("./rule").Rule<"multipleOf", "Float", "number">;
2
+ //# sourceMappingURL=multiple-of.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multiple-of.d.ts","sourceRoot":"","sources":["../../src/rules/multiple-of.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,wDAOzB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const notContainsRule: import("./rule").Rule<"notContains", "String", "string">;
2
+ //# sourceMappingURL=not-contains.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"not-contains.d.ts","sourceRoot":"","sources":["../../src/rules/not-contains.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,eAAe,0DAU1B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const patternRule: import("./rule").Rule<"pattern", "String", "string">;
2
+ //# sourceMappingURL=pattern.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pattern.d.ts","sourceRoot":"","sources":["../../src/rules/pattern.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,WAAW,sDAQtB,CAAC"}
@@ -0,0 +1,55 @@
1
+ import type { z } from 'zod';
2
+ import type { StringSchema } from '../formats/format';
3
+ /** The schema each kind of rule narrows. */
4
+ export interface Targets {
5
+ string: StringSchema;
6
+ number: z.ZodNumber;
7
+ list: z.ZodArray<z.ZodType>;
8
+ }
9
+ export type Target = keyof Targets;
10
+ /** What a `@constraint` argument's value can be. */
11
+ interface ValueOf {
12
+ Int: number;
13
+ Float: number;
14
+ String: string;
15
+ }
16
+ /**
17
+ * One `@constraint` argument: its GraphQL type in the directive's SDL, the
18
+ * kind of value it narrows, and the same narrowing twice — `toZod` applied to
19
+ * a schema at startup, `toCode` written as source by a code generator. The
20
+ * spec beside each rule proves the two accept and refuse the same values.
21
+ *
22
+ * A `base` rule (only `format`) replaces the schema instead of narrowing it,
23
+ * so a builder applies it before every other rule of its target.
24
+ */
25
+ export interface Rule<A extends string = string, T extends keyof ValueOf = keyof ValueOf, K extends Target = Target> {
26
+ readonly argument: A;
27
+ readonly type: T;
28
+ readonly target: K;
29
+ readonly base?: true;
30
+ readonly toZod: (schema: Targets[K], value: ValueOf[T]) => Targets[K];
31
+ /**
32
+ * `schema` is the source of the schema this rule narrows. The source names
33
+ * zod as a free `z`: the generated file imports it.
34
+ */
35
+ readonly toCode: (schema: string, value: ValueOf[T]) => string;
36
+ /**
37
+ * Whether a Zod issue is this rule's refusal, so the error a client gets
38
+ * names the rule (`constraint: 'minLength'`), which does not change with
39
+ * Zod's own issue codes.
40
+ */
41
+ readonly owns: (issue: IssueFields) => boolean;
42
+ }
43
+ /** The fields of a Zod issue a rule recognises its refusal by. */
44
+ export interface IssueFields {
45
+ readonly code: string;
46
+ readonly origin?: string;
47
+ readonly format?: string;
48
+ readonly inclusive?: boolean;
49
+ }
50
+ /** Declares a rule, with its argument name kept literal. */
51
+ export declare function defineRule<const A extends string, T extends keyof ValueOf, K extends Target>(rule: Rule<A, T, K>): Rule<A, T, K>;
52
+ /** A string literal as source: quotes and escapes included. */
53
+ export declare const literal: (value: string) => string;
54
+ export {};
55
+ //# sourceMappingURL=rule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rule.d.ts","sourceRoot":"","sources":["../../src/rules/rule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC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