@nxgt/graphql-validation 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -1
- package/dist/bad-user-input.d.ts +1 -1
- package/dist/builder/args-schema.d.ts +1 -1
- package/dist/builder/check-constraints.d.ts +15 -0
- package/dist/builder/check-constraints.d.ts.map +1 -0
- package/dist/builder/constraints.d.ts +1 -1
- package/dist/builder/input-code.d.ts +29 -0
- package/dist/builder/input-code.d.ts.map +1 -0
- package/dist/builder/input-schema.d.ts.map +1 -1
- package/dist/builder/leaf.d.ts +14 -4
- package/dist/builder/leaf.d.ts.map +1 -1
- package/dist/chunks/{index-n3hypgpf.js → index-rbxe5m3y.js} +7 -3
- package/dist/chunks/{index-n3hypgpf.js.map → index-rbxe5m3y.js.map} +3 -3
- package/dist/chunks/index-s1kkmg35.js +266 -0
- package/dist/chunks/index-s1kkmg35.js.map +14 -0
- package/dist/cli.js +1 -1
- package/dist/codegen.d.ts +4 -0
- package/dist/codegen.d.ts.map +1 -0
- package/dist/codegen.js +56 -0
- package/dist/codegen.js.map +10 -0
- package/dist/formats/all.d.ts +8 -8
- package/dist/formats/byte.d.ts +1 -1
- package/dist/formats/date-time.d.ts +1 -1
- package/dist/formats/date.d.ts +1 -1
- package/dist/formats/email.d.ts +1 -1
- package/dist/formats/index.d.ts +2 -2
- package/dist/formats/ipv4.d.ts +1 -1
- package/dist/formats/ipv6.d.ts +1 -1
- package/dist/formats/uri.d.ts +1 -1
- package/dist/formats/uuid.d.ts +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +12 -243
- package/dist/index.js.map +4 -8
- package/dist/rules/all.d.ts +15 -15
- package/dist/rules/contains.d.ts +1 -1
- package/dist/rules/ends-with.d.ts +1 -1
- package/dist/rules/exclusive-max.d.ts +1 -1
- package/dist/rules/exclusive-min.d.ts +1 -1
- package/dist/rules/format.d.ts +1 -1
- package/dist/rules/index.d.ts +3 -1
- package/dist/rules/index.d.ts.map +1 -1
- package/dist/rules/max-items.d.ts +1 -1
- package/dist/rules/max-length.d.ts +1 -1
- package/dist/rules/max.d.ts +1 -1
- package/dist/rules/min-items.d.ts +1 -1
- package/dist/rules/min-length.d.ts +1 -1
- package/dist/rules/min.d.ts +1 -1
- package/dist/rules/multiple-of.d.ts +1 -1
- package/dist/rules/not-contains.d.ts +1 -1
- package/dist/rules/pattern.d.ts +1 -1
- package/dist/rules/rule.d.ts +1 -1
- package/dist/rules/starts-with.d.ts +1 -1
- package/dist/with-validation.d.ts.map +1 -1
- package/docs/guide/constraints.md +1 -1
- package/docs/roadmap.md +6 -3
- package/docs/troubleshooting.md +14 -2
- package/package.json +7 -1
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ Your `tsconfig.json` needs:
|
|
|
26
26
|
```jsonc
|
|
27
27
|
{
|
|
28
28
|
"compilerOptions": {
|
|
29
|
-
"moduleResolution": "bundler" //
|
|
29
|
+
"moduleResolution": "bundler" // or "nodenext" / "node16", from 0.2.1; "node" / "node10" ignore `exports`
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
```
|
|
@@ -178,6 +178,32 @@ the directive declared is this package's. Both at once throw
|
|
|
178
178
|
| `ConstraintArgument` | the type of `issues[].constraint`: `'minLength' \| 'format' \| ...` |
|
|
179
179
|
| `ArgsSchema`, `SchemaOf` | the types `validated` accepts |
|
|
180
180
|
|
|
181
|
+
`@nxgt/graphql-validation/codegen` is for a code generator, such as
|
|
182
|
+
[`@nxgt/graphql-codegen-zod`](https://www.npmjs.com/package/@nxgt/graphql-codegen-zod): it writes the schemas `withValidation` builds as source, and
|
|
183
|
+
refuses the schemas `withValidation` refuses. A server does not need it.
|
|
184
|
+
|
|
185
|
+
| Export | Is |
|
|
186
|
+
| --- | --- |
|
|
187
|
+
| `checkConstraints(schema, onArgs?)` | runs every startup check of `withValidation` without wrapping anything; returns the `@constraint` directive, or `undefined` when the schema declares none |
|
|
188
|
+
| `constraintsOn(directive, node)` | the `Constraint`s written on an argument or input field (`arg.astNode`), `format` first |
|
|
189
|
+
| `inputCode(type, constraints, where, named, options?)` | the schema of that argument or field as source, `z` a free identifier: built-in scalars and lists written in full, nullable types `.nullish()`; every other named type (enum, input object, custom scalar) is what `named(type)` returns. A constraint that cannot apply throws the startup message, naming `where`. `options` (`InputCodeOptions`): `list({ type, code, single })` returns each list's source, given `code` (the array with every rule) and `single` (the list's named type, non-null, without rules), e.g. to take a single value as graphql does: `single`, wrapped, piped into `code` |
|
|
190
|
+
| `Constraint` | `{ rule, value }`, one `@constraint` argument. Of `rule`, read `argument` (`'minItems'`, `'format'`, …), `target` (`'list'` for `minItems`/`maxItems`, else what the rule narrows) and `base` (`true` for `format`, which picks the schema the others narrow); the rest is internal |
|
|
191
|
+
|
|
192
|
+
```ts
|
|
193
|
+
import { checkConstraints, constraintsOn, inputCode } from '@nxgt/graphql-validation/codegen';
|
|
194
|
+
|
|
195
|
+
const directive = checkConstraints(schema); // throws what withValidation would
|
|
196
|
+
const arg = schema.getMutationType()!.getFields().signUp!.args[0]!;
|
|
197
|
+
const source = inputCode(
|
|
198
|
+
arg.type,
|
|
199
|
+
constraintsOn(directive, arg.astNode),
|
|
200
|
+
'Mutation.signUp(input:)', // named in errors, as at startup
|
|
201
|
+
(type) => `z${type.name}`, // enums, input objects, custom scalars
|
|
202
|
+
);
|
|
203
|
+
// e.g. 'zSignUpInput' — or, for `name: String @constraint(minLength: 2)`,
|
|
204
|
+
// 'z.string().min(2).nullish()'
|
|
205
|
+
```
|
|
206
|
+
|
|
181
207
|
Also shipped, outside `exports`:
|
|
182
208
|
|
|
183
209
|
| File | Is |
|
package/dist/bad-user-input.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GraphQLError } from 'graphql';
|
|
2
2
|
import type { z } from 'zod';
|
|
3
|
-
import type { ConstraintArgument } from './rules';
|
|
3
|
+
import type { ConstraintArgument } from './rules/index.js';
|
|
4
4
|
/** One reason an input was refused, at its path inside the arguments. */
|
|
5
5
|
export interface ValidationIssue {
|
|
6
6
|
/** `['input', 'address', 'zip']`: the argument, then the input fields. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { GraphQLField, GraphQLObjectType } from 'graphql';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import type { InputSchemas } from './input-schema';
|
|
3
|
+
import type { InputSchemas } from './input-schema.js';
|
|
4
4
|
/**
|
|
5
5
|
* The schema of a field's arguments, or `undefined` when none of them can
|
|
6
6
|
* break a constraint, so a field with nothing to check is left untouched.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type GraphQLDirective, type GraphQLField, type GraphQLObjectType, type GraphQLSchema } from 'graphql';
|
|
2
|
+
import type { z } from 'zod';
|
|
3
|
+
/**
|
|
4
|
+
* Runs every check `withValidation` makes at startup, so a code generator
|
|
5
|
+
* refuses the same schemas: the declaration is `constraintTypeDefs`', every
|
|
6
|
+
* constraint applies where it is written (in every input type), none sits on
|
|
7
|
+
* a directive's argument, objects keep their interfaces' constraints, and no
|
|
8
|
+
* default value breaks its own. `onArgs` receives each object field's
|
|
9
|
+
* arguments schema, for a field with something to check.
|
|
10
|
+
*
|
|
11
|
+
* Returns the `@constraint` directive, or `undefined` when the schema
|
|
12
|
+
* declares none (and so carries no constraint).
|
|
13
|
+
*/
|
|
14
|
+
export declare function checkConstraints(schema: GraphQLSchema, onArgs?: (type: GraphQLObjectType, field: GraphQLField<unknown, unknown>, args: z.ZodType) => void): GraphQLDirective | undefined;
|
|
15
|
+
//# sourceMappingURL=check-constraints.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-constraints.d.ts","sourceRoot":"","sources":["../../src/builder/check-constraints.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAGlB,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAM7B;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAC/B,MAAM,EAAE,aAAa,EACrB,MAAM,CAAC,EAAE,CACR,IAAI,EAAE,iBAAiB,EACvB,KAAK,EAAE,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,EACrC,IAAI,EAAE,CAAC,CAAC,OAAO,KACX,IAAI,GACP,gBAAgB,GAAG,SAAS,CAyB9B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type DirectiveNode, type GraphQLDirective } from 'graphql';
|
|
2
|
-
import { type RegisteredRule } from '../rules';
|
|
2
|
+
import { type RegisteredRule } from '../rules/index.js';
|
|
3
3
|
/** One `@constraint` argument written on an argument or an input field. */
|
|
4
4
|
export interface Constraint {
|
|
5
5
|
readonly rule: RegisteredRule;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type GraphQLInputType, type GraphQLList, type GraphQLNamedInputType } from 'graphql';
|
|
2
|
+
import type { Constraint } from './constraints.js';
|
|
3
|
+
/**
|
|
4
|
+
* The source of the schema of one argument or input field: what
|
|
5
|
+
* `InputSchemas` builds at startup, written for a code generator. The
|
|
6
|
+
* source names zod as a free `z`.
|
|
7
|
+
*
|
|
8
|
+
* The runtime leaves what graphql already checked to graphql; generated
|
|
9
|
+
* code checks every value, so each named type comes from `named`: an input
|
|
10
|
+
* object's or an enum's schema by name, a custom scalar's from a mapping.
|
|
11
|
+
* The built-in scalars are written here, with their constraints. A
|
|
12
|
+
* constraint that cannot apply fails as it does at startup.
|
|
13
|
+
*/
|
|
14
|
+
export declare function inputCode(type: GraphQLInputType, constraints: readonly Constraint[], where: string, named: (type: GraphQLNamedInputType) => string, options?: InputCodeOptions): string;
|
|
15
|
+
/** How `inputCode` writes what a generator may want written otherwise. */
|
|
16
|
+
export interface InputCodeOptions {
|
|
17
|
+
/**
|
|
18
|
+
* A list's schema, given its `type`, `code` (the array with every rule)
|
|
19
|
+
* and `single` (the list's named type, non-null, without rules): to
|
|
20
|
+
* take a single value for a list, as graphql does, `single` wrapped then
|
|
21
|
+
* piped into `code`. Default: `code`.
|
|
22
|
+
*/
|
|
23
|
+
readonly list?: (list: {
|
|
24
|
+
readonly type: GraphQLList<GraphQLInputType>;
|
|
25
|
+
readonly code: string;
|
|
26
|
+
readonly single: string;
|
|
27
|
+
}) => string;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=input-code.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-code.d.ts","sourceRoot":"","sources":["../../src/builder/input-code.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,qBAAqB,EAK1B,MAAM,SAAS,CAAC;AAEjB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGhD;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CACxB,IAAI,EAAE,gBAAgB,EACtB,WAAW,EAAE,SAAS,UAAU,EAAE,EAClC,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,CAAC,IAAI,EAAE,qBAAqB,KAAK,MAAM,EAC9C,OAAO,GAAE,gBAAqB,GAC5B,MAAM,CAGR;AAED,0EAA0E;AAC1E,MAAM,WAAW,gBAAgB;IAChC;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE;QACtB,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,gBAAgB,CAAC,CAAC;QAC7C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;KACxB,KAAK,MAAM,CAAC;CACb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input-schema.d.ts","sourceRoot":"","sources":["../../src/builder/input-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,eAAe,EACpB,KAAK,gBAAgB,E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A8E;IAC9E,EAAE,CAAC,KAAK,EAAE,eAAe,GAAG,iBAAiB,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC,OAAO;IAYxE;;;;OAIG;IACH,aAAa,IAAI,IAAI;CAoErB"}
|
package/dist/builder/leaf.d.ts
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
import { type GraphQLLeafType } from 'graphql';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import type { Target } from '../rules/rule';
|
|
4
|
-
import type { Constraint } from './constraints';
|
|
3
|
+
import type { Target } from '../rules/rule.js';
|
|
4
|
+
import type { Constraint } from './constraints.js';
|
|
5
|
+
/**
|
|
6
|
+
* Fails unless every constraint applies to a value of `type`: `minLength` on
|
|
7
|
+
* an `Int`, anything on a custom scalar or an enum, fails, naming `where`.
|
|
8
|
+
* The runtime and the code generator refuse the same schemas with the same
|
|
9
|
+
* message.
|
|
10
|
+
*/
|
|
11
|
+
export declare function assertLeafTargets(type: GraphQLLeafType, constraints: readonly Constraint[], where: string): void;
|
|
12
|
+
/** Fails when an input object carries a constraint: none applies to it. */
|
|
13
|
+
export declare function assertObjectTargets(typeName: string, constraints: readonly Constraint[], where: string): void;
|
|
5
14
|
/**
|
|
6
15
|
* The schema of a scalar or enum value with its constraints applied. A leaf
|
|
7
16
|
* without any is left as graphql parsed it. A constraint that cannot apply
|
|
8
|
-
*
|
|
9
|
-
* here, at startup, naming `where`.
|
|
17
|
+
* fails here, at startup.
|
|
10
18
|
*/
|
|
11
19
|
export declare function leafSchema(type: GraphQLLeafType, constraints: readonly Constraint[], where: string): z.ZodType;
|
|
20
|
+
/** The source of a built-in scalar's schema, before its constraints. */
|
|
21
|
+
export declare function baseCode(type: GraphQLLeafType): string | undefined;
|
|
12
22
|
/** What a rule's target reads as in an error. */
|
|
13
23
|
export declare function describeTarget(target: Target): string;
|
|
14
24
|
//# sourceMappingURL=leaf.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"leaf.d.ts","sourceRoot":"","sources":["../../src/builder/leaf.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"leaf.d.ts","sourceRoot":"","sources":["../../src/builder/leaf.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,KAAK,eAAe,EAEpB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAehD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAChC,IAAI,EAAE,eAAe,EACrB,WAAW,EAAE,SAAS,UAAU,EAAE,EAClC,KAAK,EAAE,MAAM,GACX,IAAI,CAMN;AAED,2EAA2E;AAC3E,wBAAgB,mBAAmB,CAClC,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,SAAS,UAAU,EAAE,EAClC,KAAK,EAAE,MAAM,GACX,IAAI,CAIN;AAYD;;;;GAIG;AACH,wBAAgB,UAAU,CACzB,IAAI,EAAE,eAAe,EACrB,WAAW,EAAE,SAAS,UAAU,EAAE,EAClC,KAAK,EAAE,MAAM,GACX,CAAC,CAAC,OAAO,CAQX;AAED,wEAAwE;AACxE,wBAAgB,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,MAAM,GAAG,SAAS,CAMlE;AAED,iDAAiD;AACjD,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAIrD"}
|
|
@@ -277,6 +277,10 @@ function applyRule(rule, schema, value) {
|
|
|
277
277
|
const toZod = rule.toZod;
|
|
278
278
|
return toZod(schema, value);
|
|
279
279
|
}
|
|
280
|
+
function applyRuleCode(rule, source, value) {
|
|
281
|
+
const toCode = rule.toCode;
|
|
282
|
+
return toCode(source, value);
|
|
283
|
+
}
|
|
280
284
|
function constraintOf(issue) {
|
|
281
285
|
const fields = issue;
|
|
282
286
|
return Object.values(rules).find((rule) => rule.owns(fields))?.argument;
|
|
@@ -309,7 +313,7 @@ function assertOwnConstraint(directive) {
|
|
|
309
313
|
}
|
|
310
314
|
}
|
|
311
315
|
|
|
312
|
-
export { rules, applyRule, constraintOf, constraintTypeDefs2, assertOwnConstraint };
|
|
316
|
+
export { rules, applyRule, applyRuleCode, constraintOf, constraintTypeDefs2, assertOwnConstraint };
|
|
313
317
|
|
|
314
|
-
//# debugId=
|
|
315
|
-
//# sourceMappingURL=index-
|
|
318
|
+
//# debugId=0FAF783CE1246B6764756E2164756E21
|
|
319
|
+
//# sourceMappingURL=index-rbxe5m3y.js.map
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"import { defineRule, literal } from './rule';\n\nconst message = (value: string) => `Must not contain ${literal(value)}`;\n\nexport const notContainsRule = defineRule({\n\targument: 'notContains',\n\ttype: 'String',\n\ttarget: 'string',\n\t// `refine` keeps the schema's own type, so later rules still chain.\n\ttoZod: (schema, value) =>\n\t\tschema.refine((input) => !input.includes(value), message(value)),\n\ttoCode: (schema, value) =>\n\t\t`${schema}.refine((input) => !input.includes(${literal(value)}), ${literal(message(value))})`,\n\towns: (issue) => issue.code === 'custom',\n});\n",
|
|
30
30
|
"import { defineRule, literal } from './rule';\n\n/** The pattern as a RegExp, or an error that names the argument. */\nfunction compile(value: string): RegExp {\n\ttry {\n\t\treturn new RegExp(value);\n\t} catch (error) {\n\t\tthrow new Error(\n\t\t\t`Invalid @constraint pattern ${literal(value)}: ${(error as Error).message}`,\n\t\t);\n\t}\n}\n\nexport const patternRule = defineRule({\n\targument: 'pattern',\n\ttype: 'String',\n\ttarget: 'string',\n\ttoZod: (schema, value) => schema.regex(compile(value)),\n\ttoCode: (schema, value) =>\n\t\t`${schema}.regex(new RegExp(${literal(compile(value).source)}))`,\n\towns: (issue) => issue.format === 'regex',\n});\n",
|
|
31
31
|
"import { defineRule, literal } from './rule';\n\nexport const startsWithRule = defineRule({\n\targument: 'startsWith',\n\ttype: 'String',\n\ttarget: 'string',\n\ttoZod: (schema, value) => schema.startsWith(value),\n\ttoCode: (schema, value) => `${schema}.startsWith(${literal(value)})`,\n\towns: (issue) => issue.format === 'starts_with',\n});\n",
|
|
32
|
-
"import type { z } from 'zod';\nimport * as all from './all';\nimport type { IssueFields } from './rule';\n\n/**\n * One of the rules, as its own type: a builder narrows it on `target`, so a\n * number schema never reaches a string rule.\n */\nexport type RegisteredRule = (typeof all)[keyof typeof all];\n\n/** An argument `@constraint` takes. */\nexport type ConstraintArgument = RegisteredRule['argument'];\n\n/**\n * Every rule, keyed by its `@constraint` argument. Derived from what\n * `./all` exports, so a new rule is one file and one line there, and the\n * directive's SDL follows.\n */\nexport const rules = Object.fromEntries(\n\tObject.values(all).map((rule) => [rule.argument, rule]),\n) as {\n\treadonly [A in ConstraintArgument]: Extract<RegisteredRule, { argument: A }>;\n};\n\n/**\n * Applies a rule to a schema its caller has already matched to the rule's\n * target: the one place the rule's typed `toZod` meets a schema built from\n * GraphQL types, which the compiler cannot relate.\n */\nexport function applyRule(\n\trule: RegisteredRule,\n\tschema: z.ZodType,\n\tvalue: string | number,\n): z.ZodType {\n\tconst toZod = rule.toZod as unknown as (\n\t\tschema: z.ZodType,\n\t\tvalue: string | number,\n\t) => z.ZodType;\n\treturn toZod(schema, value);\n}\n\n/** The `@constraint` argument whose rule refused with this issue, if any. */\nexport function constraintOf(\n\tissue: z.core.$ZodIssue,\n): ConstraintArgument | undefined {\n\tconst fields = issue as unknown as IssueFields;\n\treturn Object.values(rules).find((rule) => rule.owns(fields))?.argument;\n}\n"
|
|
32
|
+
"import type { z } from 'zod';\nimport * as all from './all';\nimport type { IssueFields } from './rule';\n\n/**\n * One of the rules, as its own type: a builder narrows it on `target`, so a\n * number schema never reaches a string rule.\n */\nexport type RegisteredRule = (typeof all)[keyof typeof all];\n\n/** An argument `@constraint` takes. */\nexport type ConstraintArgument = RegisteredRule['argument'];\n\n/**\n * Every rule, keyed by its `@constraint` argument. Derived from what\n * `./all` exports, so a new rule is one file and one line there, and the\n * directive's SDL follows.\n */\nexport const rules = Object.fromEntries(\n\tObject.values(all).map((rule) => [rule.argument, rule]),\n) as {\n\treadonly [A in ConstraintArgument]: Extract<RegisteredRule, { argument: A }>;\n};\n\n/**\n * Applies a rule to a schema its caller has already matched to the rule's\n * target: the one place the rule's typed `toZod` meets a schema built from\n * GraphQL types, which the compiler cannot relate.\n */\nexport function applyRule(\n\trule: RegisteredRule,\n\tschema: z.ZodType,\n\tvalue: string | number,\n): z.ZodType {\n\tconst toZod = rule.toZod as unknown as (\n\t\tschema: z.ZodType,\n\t\tvalue: string | number,\n\t) => z.ZodType;\n\treturn toZod(schema, value);\n}\n\n/** `applyRule` for source: the rule's typed `toCode` on a schema's source. */\nexport function applyRuleCode(\n\trule: RegisteredRule,\n\tsource: string,\n\tvalue: string | number,\n): string {\n\tconst toCode = rule.toCode as (\n\t\tschema: string,\n\t\tvalue: string | number,\n\t) => string;\n\treturn toCode(source, value);\n}\n\n/** The `@constraint` argument whose rule refused with this issue, if any. */\nexport function constraintOf(\n\tissue: z.core.$ZodIssue,\n): ConstraintArgument | undefined {\n\tconst fields = issue as unknown as IssueFields;\n\treturn Object.values(rules).find((rule) => rule.owns(fields))?.argument;\n}\n"
|
|
33
33
|
],
|
|
34
|
-
"mappings": ";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;AC4DO,SAAS,UAIf,CAAC,MAAoC;AAAA,EACrC,OAAO;AAAA;AAID,IAAM,UAAU,CAAC,UAA0B,KAAK,UAAU,KAAK;;;ACnE/D,IAAM,eAAe,WAAW;AAAA,EACtC,UAAU;AAAA,EACV,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,OAAO,CAAC,QAAQ,UAAU,OAAO,SAAS,KAAK;AAAA,EAC/C,QAAQ,CAAC,QAAQ,UAAU,GAAG,mBAAmB,QAAQ,KAAK;AAAA,EAC9D,MAAM,CAAC,UAAU,MAAM,WAAW;AACnC,CAAC;;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ule,
|
|
4
|
+
assertOwnConstraint
|
|
5
|
+
} from "./index-rbxe5m3y.js";
|
|
6
|
+
|
|
7
|
+
// src/builder/constraints.ts
|
|
8
|
+
import {
|
|
9
|
+
getDirectiveValues
|
|
10
|
+
} from "graphql";
|
|
11
|
+
function constraintsOn2(directive, node) {
|
|
12
|
+
if (!directive || !node)
|
|
13
|
+
return [];
|
|
14
|
+
const values = getDirectiveValues(directive, { directives: node.directives ?? [] }) ?? {};
|
|
15
|
+
return Object.entries(values).filter(([, value]) => value !== undefined && value !== null).map(([argument, value]) => ({
|
|
16
|
+
rule: rules[argument],
|
|
17
|
+
value
|
|
18
|
+
})).sort((a, b) => Number(Boolean(b.rule.base)) - Number(Boolean(a.rule.base)));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// src/builder/check-constraints.ts
|
|
22
|
+
import {
|
|
23
|
+
isInterfaceType,
|
|
24
|
+
isObjectType
|
|
25
|
+
} from "graphql";
|
|
26
|
+
|
|
27
|
+
// src/builder/args-schema.ts
|
|
28
|
+
import { z } from "zod";
|
|
29
|
+
function argsSchemaOf(inputs, parent, field) {
|
|
30
|
+
if (!field.args.some((arg) => inputs.needsCheck(arg)))
|
|
31
|
+
return;
|
|
32
|
+
return z.object(Object.fromEntries(field.args.map((arg) => [
|
|
33
|
+
arg.name,
|
|
34
|
+
inputs.of(arg, `${parent}.${field.name}(${arg.name}:)`)
|
|
35
|
+
])));
|
|
36
|
+
}
|
|
37
|
+
function signature(inputs, arg) {
|
|
38
|
+
return constraintsOn2(inputs.directive, arg.astNode).map(({ rule, value }) => `${rule.argument}: ${JSON.stringify(value)}`).sort().join(", ");
|
|
39
|
+
}
|
|
40
|
+
var written = (signature) => signature ? `@constraint(${signature})` : "no @constraint";
|
|
41
|
+
function assertInterfaceConstraintsKept(inputs, type) {
|
|
42
|
+
for (const contract of type.getInterfaces()) {
|
|
43
|
+
for (const [name, declared] of Object.entries(contract.getFields())) {
|
|
44
|
+
const field = type.getFields()[name];
|
|
45
|
+
for (const arg of declared.args) {
|
|
46
|
+
const wanted = signature(inputs, arg);
|
|
47
|
+
if (!wanted)
|
|
48
|
+
continue;
|
|
49
|
+
const own = field?.args.find(({ name: argName }) => argName === arg.name);
|
|
50
|
+
const found = own ? signature(inputs, own) : wanted;
|
|
51
|
+
if (found !== wanted) {
|
|
52
|
+
const verb = found ? "differs on" : "is not repeated on";
|
|
53
|
+
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.`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// src/builder/input-schema.ts
|
|
61
|
+
import {
|
|
62
|
+
getNamedType,
|
|
63
|
+
isInputObjectType,
|
|
64
|
+
isListType,
|
|
65
|
+
isNonNullType,
|
|
66
|
+
valueFromAST
|
|
67
|
+
} from "graphql";
|
|
68
|
+
import { z as z3 } from "zod";
|
|
69
|
+
|
|
70
|
+
// src/builder/leaf.ts
|
|
71
|
+
import {
|
|
72
|
+
GraphQLBoolean,
|
|
73
|
+
GraphQLFloat,
|
|
74
|
+
GraphQLID,
|
|
75
|
+
GraphQLInt,
|
|
76
|
+
GraphQLString
|
|
77
|
+
} from "graphql";
|
|
78
|
+
import { z as z2 } from "zod";
|
|
79
|
+
var kinds = {
|
|
80
|
+
[GraphQLString.name]: "string",
|
|
81
|
+
[GraphQLID.name]: "string",
|
|
82
|
+
[GraphQLInt.name]: "number",
|
|
83
|
+
[GraphQLFloat.name]: "number"
|
|
84
|
+
};
|
|
85
|
+
function baseOf(type) {
|
|
86
|
+
if (type.name === GraphQLInt.name)
|
|
87
|
+
return z2.number().int();
|
|
88
|
+
return kinds[type.name] === "number" ? z2.number() : z2.string();
|
|
89
|
+
}
|
|
90
|
+
function assertLeafTargets(type, constraints, where) {
|
|
91
|
+
const misplaced = constraints.find(({ rule }) => rule.target === "list");
|
|
92
|
+
if (misplaced)
|
|
93
|
+
throw misplacedOn(misplaced, where, type.name);
|
|
94
|
+
const kind = kinds[type.name];
|
|
95
|
+
const wrong = constraints.find(({ rule }) => rule.target !== kind);
|
|
96
|
+
if (wrong)
|
|
97
|
+
throw misplacedOn(wrong, where, type.name);
|
|
98
|
+
}
|
|
99
|
+
function assertObjectTargets(typeName, constraints, where) {
|
|
100
|
+
const first = constraints.find(({ rule }) => rule.target === "list") ?? constraints[0];
|
|
101
|
+
if (first)
|
|
102
|
+
throw misplacedOn(first, where, typeName);
|
|
103
|
+
}
|
|
104
|
+
function misplacedOn({ rule }, where, typeName) {
|
|
105
|
+
return new Error(`@constraint(${rule.argument}) on ${where} needs ${describeTarget(rule.target)}, not ${typeName}.`);
|
|
106
|
+
}
|
|
107
|
+
function leafSchema(type, constraints, where) {
|
|
108
|
+
if (constraints.length === 0)
|
|
109
|
+
return z2.unknown();
|
|
110
|
+
assertLeafTargets(type, constraints, where);
|
|
111
|
+
let schema = baseOf(type);
|
|
112
|
+
for (const { rule, value } of constraints) {
|
|
113
|
+
schema = applyRule(rule, schema, value);
|
|
114
|
+
}
|
|
115
|
+
return schema;
|
|
116
|
+
}
|
|
117
|
+
function baseCode(type) {
|
|
118
|
+
if (type.name === GraphQLInt.name)
|
|
119
|
+
return "z.int32()";
|
|
120
|
+
if (type.name === GraphQLFloat.name)
|
|
121
|
+
return "z.number()";
|
|
122
|
+
if (type.name === GraphQLBoolean.name)
|
|
123
|
+
return "z.boolean()";
|
|
124
|
+
return kinds[type.name] === "string" ? "z.string()" : undefined;
|
|
125
|
+
}
|
|
126
|
+
function describeTarget(target) {
|
|
127
|
+
if (target === "string")
|
|
128
|
+
return "a String or an ID";
|
|
129
|
+
if (target === "number")
|
|
130
|
+
return "an Int or a Float";
|
|
131
|
+
return "a list";
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/builder/input-schema.ts
|
|
135
|
+
class InputSchemas {
|
|
136
|
+
directive;
|
|
137
|
+
#objects = new Map;
|
|
138
|
+
#defaults = [];
|
|
139
|
+
#constrained = new Set;
|
|
140
|
+
constructor(schema) {
|
|
141
|
+
this.directive = schema.getDirective("constraint") ?? undefined;
|
|
142
|
+
const objects = Object.values(schema.getTypeMap()).filter(isInputObjectType);
|
|
143
|
+
for (let changed = true;changed; ) {
|
|
144
|
+
changed = false;
|
|
145
|
+
for (const type of objects) {
|
|
146
|
+
if (this.#constrained.has(type.name))
|
|
147
|
+
continue;
|
|
148
|
+
const constrained = Object.values(type.getFields()).some((field) => constraintsOn2(this.directive, field.astNode).length > 0 || this.isConstrained(field.type));
|
|
149
|
+
if (constrained) {
|
|
150
|
+
this.#constrained.add(type.name);
|
|
151
|
+
changed = true;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
isConstrained(type) {
|
|
157
|
+
const named = getNamedType(type);
|
|
158
|
+
return isInputObjectType(named) && this.#constrained.has(named.name);
|
|
159
|
+
}
|
|
160
|
+
buildAll(schema) {
|
|
161
|
+
for (const type of Object.values(schema.getTypeMap())) {
|
|
162
|
+
if (isInputObjectType(type))
|
|
163
|
+
this.#object(type);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
needsCheck(input) {
|
|
167
|
+
return constraintsOn2(this.directive, input.astNode).length > 0 || this.isConstrained(input.type);
|
|
168
|
+
}
|
|
169
|
+
of(input, where) {
|
|
170
|
+
const schema = this.#typed(input.type, constraintsOn2(this.directive, input.astNode), where);
|
|
171
|
+
const literal = input.astNode?.defaultValue;
|
|
172
|
+
if (literal)
|
|
173
|
+
this.#defaults.push({ schema, literal, type: input.type, where });
|
|
174
|
+
return schema;
|
|
175
|
+
}
|
|
176
|
+
checkDefaults() {
|
|
177
|
+
for (const { schema, literal, type, where } of this.#defaults.splice(0)) {
|
|
178
|
+
const value = valueFromAST(literal, type);
|
|
179
|
+
if (value === undefined)
|
|
180
|
+
continue;
|
|
181
|
+
const result = schema.safeParse(value);
|
|
182
|
+
if (!result.success) {
|
|
183
|
+
throw new Error(`The default value of ${where} breaks its @constraint: ${result.error.issues[0]?.message}`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
#typed(type, constraints, where) {
|
|
188
|
+
if (isNonNullType(type))
|
|
189
|
+
return this.#required(type.ofType, constraints, where);
|
|
190
|
+
return this.#required(type, constraints, where).nullish();
|
|
191
|
+
}
|
|
192
|
+
#required(type, constraints, where) {
|
|
193
|
+
if (isNonNullType(type))
|
|
194
|
+
return this.#required(type.ofType, constraints, where);
|
|
195
|
+
if (isListType(type)) {
|
|
196
|
+
const own = constraints.filter(({ rule }) => rule.target === "list");
|
|
197
|
+
const items = constraints.filter(({ rule }) => rule.target !== "list");
|
|
198
|
+
let list = z3.array(this.#typed(type.ofType, items, where));
|
|
199
|
+
for (const { rule, value } of own)
|
|
200
|
+
list = applyRule(rule, list, value);
|
|
201
|
+
return list;
|
|
202
|
+
}
|
|
203
|
+
if (isInputObjectType(type)) {
|
|
204
|
+
assertObjectTargets(type.name, constraints, where);
|
|
205
|
+
return this.#object(type);
|
|
206
|
+
}
|
|
207
|
+
return leafSchema(type, constraints, where);
|
|
208
|
+
}
|
|
209
|
+
#object(type) {
|
|
210
|
+
if (!this.isConstrained(type))
|
|
211
|
+
return z3.unknown();
|
|
212
|
+
const built = this.#objects.get(type.name);
|
|
213
|
+
if (built)
|
|
214
|
+
return built;
|
|
215
|
+
let schema;
|
|
216
|
+
this.#objects.set(type.name, z3.lazy(() => schema));
|
|
217
|
+
schema = z3.object(Object.fromEntries(Object.values(type.getFields()).map((field) => [
|
|
218
|
+
field.name,
|
|
219
|
+
this.of(field, `${type.name}.${field.name}`)
|
|
220
|
+
])));
|
|
221
|
+
this.#objects.set(type.name, schema);
|
|
222
|
+
return schema;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// src/builder/check-constraints.ts
|
|
227
|
+
function checkConstraints2(schema, onArgs) {
|
|
228
|
+
const inputs = new InputSchemas(schema);
|
|
229
|
+
if (!inputs.directive)
|
|
230
|
+
return;
|
|
231
|
+
assertOwnConstraint(inputs.directive);
|
|
232
|
+
inputs.buildAll(schema);
|
|
233
|
+
assertNoDirectiveArgumentConstrained(inputs, schema);
|
|
234
|
+
for (const type of Object.values(schema.getTypeMap())) {
|
|
235
|
+
if (type.name.startsWith("__"))
|
|
236
|
+
continue;
|
|
237
|
+
if (isInterfaceType(type)) {
|
|
238
|
+
for (const field of Object.values(type.getFields()))
|
|
239
|
+
argsSchemaOf(inputs, type.name, field);
|
|
240
|
+
}
|
|
241
|
+
if (!isObjectType(type))
|
|
242
|
+
continue;
|
|
243
|
+
assertInterfaceConstraintsKept(inputs, type);
|
|
244
|
+
for (const field of Object.values(type.getFields())) {
|
|
245
|
+
const args = argsSchemaOf(inputs, type.name, field);
|
|
246
|
+
if (args)
|
|
247
|
+
onArgs?.(type, field, args);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
inputs.checkDefaults();
|
|
251
|
+
return inputs.directive;
|
|
252
|
+
}
|
|
253
|
+
function assertNoDirectiveArgumentConstrained(inputs, schema) {
|
|
254
|
+
for (const directive of schema.getDirectives()) {
|
|
255
|
+
for (const arg of directive.args) {
|
|
256
|
+
if (constraintsOn2(inputs.directive, arg.astNode).length > 0) {
|
|
257
|
+
throw new Error(`@constraint on @${directive.name}(${arg.name}:) checks nothing: a directive's argument reaches no resolver. Remove it.`);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export { constraintsOn2, assertLeafTargets, assertObjectTargets, baseCode, checkConstraints2 };
|
|
264
|
+
|
|
265
|
+
//# debugId=7C317F3D691975BE64756E2164756E21
|
|
266
|
+
//# sourceMappingURL=index-s1kkmg35.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/builder/constraints.ts", "../src/builder/check-constraints.ts", "../src/builder/args-schema.ts", "../src/builder/input-schema.ts", "../src/builder/leaf.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"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",
|
|
6
|
+
"import {\n\ttype GraphQLDirective,\n\ttype GraphQLField,\n\ttype GraphQLObjectType,\n\ttype GraphQLSchema,\n\tisInterfaceType,\n\tisObjectType,\n} from 'graphql';\nimport type { z } from 'zod';\nimport { assertOwnConstraint } from '../constraint-directive';\nimport { argsSchemaOf, assertInterfaceConstraintsKept } from './args-schema';\nimport { constraintsOn } from './constraints';\nimport { InputSchemas } from './input-schema';\n\n/**\n * Runs every check `withValidation` makes at startup, so a code generator\n * refuses the same schemas: the declaration is `constraintTypeDefs`', every\n * constraint applies where it is written (in every input type), none sits on\n * a directive's argument, objects keep their interfaces' constraints, and no\n * default value breaks its own. `onArgs` receives each object field's\n * arguments schema, for a field with something to check.\n *\n * Returns the `@constraint` directive, or `undefined` when the schema\n * declares none (and so carries no constraint).\n */\nexport function checkConstraints(\n\tschema: GraphQLSchema,\n\tonArgs?: (\n\t\ttype: GraphQLObjectType,\n\t\tfield: GraphQLField<unknown, unknown>,\n\t\targs: z.ZodType,\n\t) => void,\n): GraphQLDirective | undefined {\n\tconst inputs = new InputSchemas(schema);\n\tif (!inputs.directive) return undefined;\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) onArgs?.(type, field, args);\n\t\t}\n\t}\n\tinputs.checkDefaults();\n\treturn inputs.directive;\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",
|
|
7
|
+
"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",
|
|
8
|
+
"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 { assertObjectTargets, 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\tassertObjectTargets(type.name, constraints, where);\n\t\t\treturn this.#object(type);\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",
|
|
9
|
+
"import {\n\tGraphQLBoolean,\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 * Fails unless every constraint applies to a value of `type`: `minLength` on\n * an `Int`, anything on a custom scalar or an enum, fails, naming `where`.\n * The runtime and the code generator refuse the same schemas with the same\n * message.\n */\nexport function assertLeafTargets(\n\ttype: GraphQLLeafType,\n\tconstraints: readonly Constraint[],\n\twhere: string,\n): void {\n\tconst misplaced = constraints.find(({ rule }) => rule.target === 'list');\n\tif (misplaced) throw misplacedOn(misplaced, where, type.name);\n\tconst kind = kinds[type.name];\n\tconst wrong = constraints.find(({ rule }) => rule.target !== kind);\n\tif (wrong) throw misplacedOn(wrong, where, type.name);\n}\n\n/** Fails when an input object carries a constraint: none applies to it. */\nexport function assertObjectTargets(\n\ttypeName: string,\n\tconstraints: readonly Constraint[],\n\twhere: string,\n): void {\n\tconst first =\n\t\tconstraints.find(({ rule }) => rule.target === 'list') ?? constraints[0];\n\tif (first) throw misplacedOn(first, where, typeName);\n}\n\nfunction misplacedOn(\n\t{ rule }: Constraint,\n\twhere: string,\n\ttypeName: string,\n): Error {\n\treturn new Error(\n\t\t`@constraint(${rule.argument}) on ${where} needs ${describeTarget(rule.target)}, not ${typeName}.`,\n\t);\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 * fails here, at startup.\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\tassertLeafTargets(type, constraints, where);\n\tlet schema = baseOf(type);\n\tfor (const { rule, value } of constraints) {\n\t\tschema = applyRule(rule, schema, value);\n\t}\n\treturn schema;\n}\n\n/** The source of a built-in scalar's schema, before its constraints. */\nexport function baseCode(type: GraphQLLeafType): string | undefined {\n\t// graphql's Int is 32-bit: the client refuses what it refuses.\n\tif (type.name === GraphQLInt.name) return 'z.int32()';\n\tif (type.name === GraphQLFloat.name) return 'z.number()';\n\tif (type.name === GraphQLBoolean.name) return 'z.boolean()';\n\treturn kinds[type.name] === 'string' ? 'z.string()' : undefined;\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"
|
|
10
|
+
],
|
|
11
|
+
"mappings": ";;;;;;;AAAA;AAAA;AAAA;AAkBO,SAAS,cAAa,CAC5B,WACA,MAIe;AAAA,EACf,IAAI,CAAC,aAAa,CAAC;AAAA,IAAM,OAAO,CAAC;AAAA,EACjC,MAAM,SACL,mBAAmB,WAAW,EAAE,YAAY,KAAK,cAAc,CAAC,EAAE,CAAC,KAAK,CAAC;AAAA,EAC1E,OAAO,OAAO,QAAQ,MAAM,EAC1B,OAAO,IAAI,WAAW,UAAU,aAAa,UAAU,IAAI,EAC3D,IAAI,EAAE,UAAU,YAAY;AAAA,IAC5B,MAAM,MAAM;AAAA,IACZ;AAAA,EACD,EAAE,EACD,KACA,CAAC,GAAG,MAA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mBAAmB,UAAU,QAAQ,IAAI,+EAC1C;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAAA;",
|
|
12
|
+
"debugId": "7C317F3D691975BE64756E2164756E21",
|
|
13
|
+
"names": []
|
|
14
|
+
}
|
package/dist/cli.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../src/codegen.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,KAAK,UAAU,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,KAAK,gBAAgB,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC"}
|