@nxgt/graphql-validation 0.4.1 → 0.6.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.
- package/README.md +59 -8
- package/dist/bad-user-input.d.ts +17 -2
- package/dist/bad-user-input.d.ts.map +1 -1
- package/dist/builder/check-constraints.d.ts +4 -2
- package/dist/builder/check-constraints.d.ts.map +1 -1
- package/dist/builder/declared.d.ts +12 -0
- package/dist/builder/declared.d.ts.map +1 -0
- package/dist/chunks/{index-xcaf9kes.js → index-atwkcfg3.js} +5 -5
- package/dist/chunks/{index-xcaf9kes.js.map → index-atwkcfg3.js.map} +2 -2
- package/dist/chunks/{index-twevz7yc.js → index-w9pw7fsk.js} +68 -34
- package/dist/chunks/{index-twevz7yc.js.map → index-w9pw7fsk.js.map} +6 -5
- package/dist/cli.js +1 -1
- package/dist/codegen.js +2 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +385 -11
- package/dist/index.js.map +11 -6
- package/dist/limits/describe.d.ts +9 -0
- package/dist/limits/describe.d.ts.map +1 -0
- package/dist/limits/introspection.d.ts +12 -0
- package/dist/limits/introspection.d.ts.map +1 -0
- package/dist/limits/list-size.d.ts +15 -0
- package/dist/limits/list-size.d.ts.map +1 -0
- package/dist/limits/max-depth.d.ts +28 -0
- package/dist/limits/max-depth.d.ts.map +1 -0
- package/dist/limits/max-list-cost.d.ts +62 -0
- package/dist/limits/max-list-cost.d.ts.map +1 -0
- package/dist/validated.d.ts +28 -1
- package/dist/validated.d.ts.map +1 -1
- package/dist/with-validation.d.ts.map +1 -1
- package/docs/README.md +1 -0
- package/docs/guide/constraints.md +3 -3
- package/docs/guide/errors.md +78 -4
- package/docs/guide/query-limits.md +206 -0
- package/docs/roadmap.md +13 -2
- package/docs/troubleshooting.md +53 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -151,8 +151,8 @@ formats, or none, it throws. Without `formats`, nothing changes. Details in
|
|
|
151
151
|
"extensions": {
|
|
152
152
|
"code": "BAD_USER_INPUT",
|
|
153
153
|
"issues": [
|
|
154
|
-
{ "path": ["input", "email"], "message": "Invalid email address", "code": "invalid_format", "constraint": "format" },
|
|
155
|
-
{ "path": ["input", "age"], "message": "Too small: expected number to be >=18", "code": "too_small", "constraint": "min" }
|
|
154
|
+
{ "path": ["input", "email"], "message": "Invalid email address", "code": "invalid_format", "constraint": "format", "value": "email" },
|
|
155
|
+
{ "path": ["input", "age"], "message": "Too small: expected number to be >=18", "code": "too_small", "constraint": "min", "value": 18 }
|
|
156
156
|
]
|
|
157
157
|
}
|
|
158
158
|
}
|
|
@@ -161,13 +161,18 @@ formats, or none, it throws. Without `formats`, nothing changes. Details in
|
|
|
161
161
|
```
|
|
162
162
|
|
|
163
163
|
`issues[].path` is relative to the arguments, and `issues[].constraint` names the
|
|
164
|
-
`@constraint` argument that refused
|
|
164
|
+
`@constraint` argument that refused, with `issues[].value` the value it was
|
|
165
|
+
declared with (`18` for `min: 18`): "at least 18" without parsing `message`.
|
|
166
|
+
Mapping issues to form fields is
|
|
165
167
|
in [Errors](docs/guide/errors.md).
|
|
166
168
|
|
|
167
169
|
### Rules a directive cannot say
|
|
168
170
|
|
|
169
171
|
`validated(schema, resolver)` checks the arguments with a Zod schema you write,
|
|
170
172
|
for rules across fields, refinements and async checks. It raises the same error.
|
|
173
|
+
A check that needs the request (a uniqueness query, a rule depending on the viewer)
|
|
174
|
+
takes a function in place of the schema, `(context, info) => schema`, called on each
|
|
175
|
+
call; what it throws reaches the client as it is. See [Errors](docs/guide/errors.md#a-schema-that-reads-the-context).
|
|
171
176
|
|
|
172
177
|
```ts
|
|
173
178
|
import { validated } from '@nxgt/graphql-validation';
|
|
@@ -231,6 +236,49 @@ if (!result.success)
|
|
|
231
236
|
The codes, and `fieldsError`, are in
|
|
232
237
|
[Answering invalid input as one error](docs/guide/invalid-input.md).
|
|
233
238
|
|
|
239
|
+
### Limiting the depth and cost of a query
|
|
240
|
+
|
|
241
|
+
A schema with list cycles (`Folder.items` returns items, `Item.folder` returns
|
|
242
|
+
its folder) lets a client nest a query whose cost grows exponentially.
|
|
243
|
+
`maxDepth` and `maxListCost` are graphql-js validation rules that refuse such a
|
|
244
|
+
query before any resolver runs.
|
|
245
|
+
|
|
246
|
+
```ts
|
|
247
|
+
import { maxDepth, maxListCost } from '@nxgt/graphql-validation';
|
|
248
|
+
import { parse, specifiedRules, validate } from 'graphql';
|
|
249
|
+
|
|
250
|
+
const rules = [maxDepth({ depth: 8 }), maxListCost({ budget: 10_000, defaultFirst: 50 })];
|
|
251
|
+
const errors = validate(schema, parse(query), [...specifiedRules, ...rules]);
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
```ts
|
|
255
|
+
// graphql-yoga
|
|
256
|
+
import { maxDepth, maxListCost } from '@nxgt/graphql-validation';
|
|
257
|
+
import { createYoga } from 'graphql-yoga';
|
|
258
|
+
|
|
259
|
+
const yoga = createYoga({
|
|
260
|
+
schema,
|
|
261
|
+
plugins: [
|
|
262
|
+
{
|
|
263
|
+
onValidate: ({ addValidationRule }) => {
|
|
264
|
+
addValidationRule(maxDepth({ depth: 8 }));
|
|
265
|
+
addValidationRule(maxListCost({ budget: 10_000, defaultFirst: 50 }));
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
],
|
|
269
|
+
});
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
One `GraphQLError` per operation: `extensions: { code: 'QUERY_TOO_DEEP', depth,
|
|
273
|
+
limit }` or `{ code: 'QUERY_TOO_COSTLY', cost, limit }`. A list field is sized by
|
|
274
|
+
its `first`, `last` or `limit` argument; a variable, a negative number or no
|
|
275
|
+
argument uses the argument's SDL default, else `defaultFirst`. A size is an
|
|
276
|
+
Int, a canonical-integer string or an integral Float; the largest of several
|
|
277
|
+
size arguments wins. Introspection is
|
|
278
|
+
counted too; add `ignoreIntrospection: true` where it is trusted (GraphiQL in
|
|
279
|
+
development). See
|
|
280
|
+
[Limiting the depth and cost of a query](docs/guide/query-limits.md).
|
|
281
|
+
|
|
234
282
|
## IDE support
|
|
235
283
|
|
|
236
284
|
An IDE's GraphQL plugin (JetBrains GraphQL, VS Code GraphQL) reads your `.graphql`
|
|
@@ -272,7 +320,7 @@ the directive declared is this package's. Both at once throw
|
|
|
272
320
|
| --- | --- |
|
|
273
321
|
| `constraintTypeDefs` | the SDL of `@constraint`, to add to `typeDefs` |
|
|
274
322
|
| `withValidation(schema, options?)` | checks every `@constraint` of a schema before its resolvers run; `options.formats` adds your own formats |
|
|
275
|
-
| `validated(schema \| shape, resolver)` | a resolver whose arguments a Zod schema checks |
|
|
323
|
+
| `validated(schema \| shape \| (context, info) => schema, resolver)` | a resolver whose arguments a Zod schema checks |
|
|
276
324
|
| `badUserInput(where, zodError)` | builds the error above, for code that validates by hand |
|
|
277
325
|
| `invalidInputError(issues, options?)` | one 400 error, `extensions: { code: 'validation.errors.invalid-input', http, fields }`; `options`: `translate` and `GraphQLError`'s own |
|
|
278
326
|
| `fieldsError(code, issues, options?)` | a refusal of your own naming fields, `extensions: { code, params?, http?, fields }`; `options` adds `status` and `params` |
|
|
@@ -281,9 +329,12 @@ the directive declared is this package's. Both at once throw
|
|
|
281
329
|
| `FIELD_CODES` | those codes, keyed `tooShort`, `tooLong`, `outOfRange`, `tooFew`, `tooMany`, `invalidFormat`, `invalid` |
|
|
282
330
|
| `INVALID_INPUT` | `'validation.errors.invalid-input'` |
|
|
283
331
|
| `FieldIssue`, `FieldError`, `IssueParams`, `Translate`, `InvalidInputOptions`, `FieldsErrorOptions` | their types: an issue you write, a `fields` entry, its params, your translator, the options |
|
|
284
|
-
| `ValidationIssue`, `BadUserInputExtensions` | the types of `extensions.issues` and `extensions` |
|
|
332
|
+
| `ValidationIssue`, `ConstraintValue`, `BadUserInputExtensions` | the types of `extensions.issues`, of an issue's `value`, and of `extensions` |
|
|
333
|
+
| `maxDepth({ depth, ignoreIntrospection? })` | a graphql-js validation rule refusing an operation nested deeper than `depth` fields, `extensions.code` `QUERY_TOO_DEEP`; introspection counts (the standard query is 15 levels) unless `ignoreIntrospection` |
|
|
334
|
+
| `maxListCost({ budget, defaultFirst, sizeArguments?, ignoreIntrospection? })` | a graphql-js validation rule refusing an operation whose list-weighted cost is over `budget`, `extensions.code` `QUERY_TOO_COSTLY`; `sizeArguments` names the arguments sizing a list (default `first`, `last`, `limit`, the largest wins); `ignoreIntrospection` skips `__schema` and `__type` |
|
|
335
|
+
| `MaxDepthOptions`, `MaxListCostOptions` | their options |
|
|
285
336
|
| `ConstraintArgument` | the type of `issues[].constraint`: `'minLength' \| 'format' \| ...` |
|
|
286
|
-
| `ArgsSchema`, `SchemaOf` | the types `validated` accepts |
|
|
337
|
+
| `ArgsSchema`, `ArgsSchemaFor`, `SchemaOf` | the types `validated` accepts: the schema or shape, and that or the function building it from the context |
|
|
287
338
|
| `WithValidationOptions`, `FormatSchemas`, `OwnFormats`, `StringSchema`, `FormatName` | the types of `withValidation`'s options: a record of string schemas, with no built-in format name (`FormatName`) |
|
|
288
339
|
|
|
289
340
|
`@nxgt/graphql-validation/codegen` is for a code generator, such as
|
|
@@ -292,7 +343,7 @@ refuses the schemas `withValidation` refuses. A server does not need it.
|
|
|
292
343
|
|
|
293
344
|
| Export | Is |
|
|
294
345
|
| --- | --- |
|
|
295
|
-
| `checkConstraints(schema, onArgs?, formats?)` | runs every startup check of `withValidation` without wrapping anything; returns the `@constraint` directive, or `undefined` when the schema declares none. `formats` is the record `withValidation` takes, checked the same way |
|
|
346
|
+
| `checkConstraints(schema, onArgs?, formats?)` | runs every startup check of `withValidation` without wrapping anything (`onArgs(type, field, args, declared)`: `declared(path)` lists the `Constraint`s the field's SDL writes where a Zod issue's `path` points); returns the `@constraint` directive, or `undefined` when the schema declares none. `formats` is the record `withValidation` takes, checked the same way |
|
|
296
347
|
| `constraintsOn(directive, node)` | the `Constraint`s written on an argument or input field (`arg.astNode`), `format` first |
|
|
297
348
|
| `inputCode(type, constraints, where, named, options?, formats?)` | 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`. `format(name)` returns the source of one of your formats, since only the generator knows where your record is imported from: a reference to your schema, which the other rules narrow (`formatSchemas.siret.max(14)`); built-in formats never reach it. `formats`: the record `withValidation` takes, checked the same way, so its names are known; a field using one of them without the `format` option throws `@constraint(format: "<name>") is one of the application's formats: its source is the code generator's to write, through inputCode's format option.` |
|
|
298
349
|
| `FormatSchemas` | the type of that record |
|
|
@@ -340,6 +391,6 @@ Every startup error and its fix is in [Troubleshooting](docs/troubleshooting.md)
|
|
|
340
391
|
## Documentation
|
|
341
392
|
|
|
342
393
|
- [Documentation index](docs/README.md)
|
|
343
|
-
- Guides: [Constraints](docs/guide/constraints.md), [Errors](docs/guide/errors.md), [Answering invalid input as one error](docs/guide/invalid-input.md)
|
|
394
|
+
- Guides: [Constraints](docs/guide/constraints.md), [Errors](docs/guide/errors.md), [Answering invalid input as one error](docs/guide/invalid-input.md), [Limiting the depth and cost of a query](docs/guide/query-limits.md)
|
|
344
395
|
- [Troubleshooting](docs/troubleshooting.md)
|
|
345
396
|
- [Roadmap](docs/roadmap.md): schemas that read the context, emitting the invalid-input shape directly
|
package/dist/bad-user-input.d.ts
CHANGED
|
@@ -14,14 +14,29 @@ export interface ValidationIssue {
|
|
|
14
14
|
* refusal of `validated()`'s own schema.
|
|
15
15
|
*/
|
|
16
16
|
readonly constraint?: ConstraintArgument;
|
|
17
|
+
/**
|
|
18
|
+
* What that `@constraint` argument was declared with, exactly as written
|
|
19
|
+
* (`100` for `maxLength: 100`, `"email"` for `format: "email"`), so a
|
|
20
|
+
* client can say "at most 100 characters" without parsing `message`.
|
|
21
|
+
* Present exactly when `constraint` is.
|
|
22
|
+
*/
|
|
23
|
+
readonly value?: ConstraintValue;
|
|
17
24
|
}
|
|
25
|
+
/** What a `@constraint` argument is declared with: a number or a string. */
|
|
26
|
+
export type ConstraintValue = string | number;
|
|
18
27
|
/** The `extensions` of the error an invalid input becomes. */
|
|
19
28
|
export type BadUserInputExtensions = {
|
|
20
29
|
readonly code: 'BAD_USER_INPUT';
|
|
21
30
|
readonly issues: readonly ValidationIssue[];
|
|
22
31
|
};
|
|
23
|
-
/**
|
|
24
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Names the `@constraint` argument behind an issue, and what it was declared
|
|
34
|
+
* with, when there is one.
|
|
35
|
+
*/
|
|
36
|
+
export type ConstraintOf = (issue: z.core.$ZodIssue) => {
|
|
37
|
+
argument: ConstraintArgument;
|
|
38
|
+
value: ConstraintValue;
|
|
39
|
+
} | undefined;
|
|
25
40
|
/**
|
|
26
41
|
* The one error an invalid input becomes: `extensions.code` is
|
|
27
42
|
* `BAD_USER_INPUT`, the code Apollo and most clients already read, and
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bad-user-input.d.ts","sourceRoot":"","sources":["../src/bad-user-input.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD,yEAAyE;AACzE,MAAM,WAAW,eAAe;IAC/B,0EAA0E;IAC1E,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAC5C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,qEAAqE;IACrE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"bad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AAK,EAAE,MAAM,EACb,YAAY,CAAC,EAAE,YAAY,GACzB,OAAO,CAAC,OAAO,CAAC,CAKlB"}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { type GraphQLDirective, type GraphQLField, type GraphQLObjectType, type GraphQLSchema } from 'graphql';
|
|
2
2
|
import type { z } from 'zod';
|
|
3
3
|
import { type FormatSchemas } from '../formats/registry.js';
|
|
4
|
+
import { type Constraint } from './constraints.js';
|
|
4
5
|
/**
|
|
5
6
|
* Runs every check `withValidation` makes at startup, so a code generator
|
|
6
7
|
* refuses the same schemas: the declaration is `constraintTypeDefs`', every
|
|
7
8
|
* constraint applies where it is written (in every input type), none sits on
|
|
8
9
|
* a directive's argument, objects keep their interfaces' constraints, and no
|
|
9
10
|
* default value breaks its own. `onArgs` receives each object field's
|
|
10
|
-
* arguments schema, for a field with something to check
|
|
11
|
+
* arguments schema, for a field with something to check, and `declared`
|
|
12
|
+
* the `@constraint`s the field's SDL writes where an issue's path points.
|
|
11
13
|
*
|
|
12
14
|
* `formats` are the application's own, which `@constraint(format: "...")`
|
|
13
15
|
* may name beside the built-in ones; they are checked first (name, no
|
|
@@ -16,5 +18,5 @@ import { type FormatSchemas } from '../formats/registry.js';
|
|
|
16
18
|
* Returns the `@constraint` directive, or `undefined` when the schema
|
|
17
19
|
* declares none (and so carries no constraint).
|
|
18
20
|
*/
|
|
19
|
-
export declare function checkConstraints(schema: GraphQLSchema, onArgs?: (type: GraphQLObjectType, field: GraphQLField<unknown, unknown>, args: z.ZodType) => void, formats?: FormatSchemas): GraphQLDirective | undefined;
|
|
21
|
+
export declare function checkConstraints(schema: GraphQLSchema, onArgs?: (type: GraphQLObjectType, field: GraphQLField<unknown, unknown>, args: z.ZodType, declared: (path: readonly PropertyKey[]) => readonly Constraint[]) => void, formats?: FormatSchemas): GraphQLDirective | undefined;
|
|
20
22
|
//# sourceMappingURL=check-constraints.d.ts.map
|
|
@@ -1 +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;AAE7B,OAAO,EAAE,KAAK,aAAa,EAAc,MAAM,qBAAqB,CAAC;
|
|
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;AAE7B,OAAO,EAAE,KAAK,aAAa,EAAc,MAAM,qBAAqB,CAAC;AAErE,OAAO,EAAE,KAAK,UAAU,EAAiB,MAAM,eAAe,CAAC;AAI/D;;;;;;;;;;;;;;;GAeG;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,EACf,QAAQ,EAAE,CAAC,IAAI,EAAE,SAAS,WAAW,EAAE,KAAK,SAAS,UAAU,EAAE,KAC7D,IAAI,EACT,OAAO,CAAC,EAAE,aAAa,GACrB,gBAAgB,GAAG,SAAS,CA0B9B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type GraphQLField } from 'graphql';
|
|
2
|
+
import { type Constraint } from './constraints.js';
|
|
3
|
+
import type { InputSchemas } from './input-schema.js';
|
|
4
|
+
/**
|
|
5
|
+
* The `@constraint` arguments written where a Zod issue's `path` points, in
|
|
6
|
+
* a field's arguments: the argument or input field it ends on, or, under a
|
|
7
|
+
* list, the list's own rules (`minItems`, `maxItems`) at the list and its
|
|
8
|
+
* items' at an index, as `InputSchemas` splits them. Empty when the path
|
|
9
|
+
* leaves the declared types.
|
|
10
|
+
*/
|
|
11
|
+
export declare function declaredAt(inputs: InputSchemas, field: GraphQLField<unknown, unknown>, path: readonly PropertyKey[]): readonly Constraint[];
|
|
12
|
+
//# sourceMappingURL=declared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declared.d.ts","sourceRoot":"","sources":["../../src/builder/declared.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,YAAY,EAMjB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,KAAK,UAAU,EAAiB,MAAM,eAAe,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD;;;;;;GAMG;AACH,wBAAgB,UAAU,CACzB,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,EACrC,IAAI,EAAE,SAAS,WAAW,EAAE,GAC1B,SAAS,UAAU,EAAE,CAyBvB"}
|
|
@@ -13,9 +13,6 @@ var __export = (target, all) => {
|
|
|
13
13
|
});
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
// src/constraint-directive.ts
|
|
17
|
-
import { DirectiveLocation } from "graphql";
|
|
18
|
-
|
|
19
16
|
// src/rules/all.ts
|
|
20
17
|
var exports_all = {};
|
|
21
18
|
__export(exports_all, {
|
|
@@ -36,6 +33,9 @@ __export(exports_all, {
|
|
|
36
33
|
startsWithRule: () => startsWithRule
|
|
37
34
|
});
|
|
38
35
|
|
|
36
|
+
// src/constraint-directive.ts
|
|
37
|
+
import { DirectiveLocation } from "graphql";
|
|
38
|
+
|
|
39
39
|
// src/rules/rule.ts
|
|
40
40
|
var RULE_PARAM = "nxgtConstraint";
|
|
41
41
|
function defineRule(rule) {
|
|
@@ -242,5 +242,5 @@ function assertOwnConstraint(directive) {
|
|
|
242
242
|
|
|
243
243
|
export { __export, RULE_PARAM, rules, applyRule, applyRuleCode, constraintOf, constraintTypeDefs2, assertOwnConstraint };
|
|
244
244
|
|
|
245
|
-
//# debugId=
|
|
246
|
-
//# sourceMappingURL=index-
|
|
245
|
+
//# debugId=02497C6067AC4D4564756E2164756E21
|
|
246
|
+
//# sourceMappingURL=index-atwkcfg3.js.map
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"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",
|
|
22
22
|
"import type { z } from 'zod';\nimport * as all from './all';\nimport { type IssueFields, RULE_PARAM, type RuleContext } 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\tcontext: RuleContext,\n): z.ZodType {\n\tconst toZod = rule.toZod as unknown as (\n\t\tschema: z.ZodType,\n\t\tvalue: string | number,\n\t\tcontext: RuleContext,\n\t) => z.ZodType;\n\treturn toZod(schema, value, context);\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\tcontext: RuleContext,\n): string {\n\tconst toCode = rule.toCode as (\n\t\tschema: string,\n\t\tvalue: string | number,\n\t\tcontext: RuleContext,\n\t) => string;\n\treturn toCode(source, value, context);\n}\n\n/**\n * The `@constraint` argument whose rule refused with this issue, if any: the\n * one the issue is marked with (an application format's), else the one rule\n * that owns its shape.\n */\nexport function constraintOf(\n\tissue: z.core.$ZodIssue,\n): ConstraintArgument | undefined {\n\tconst fields = issue as unknown as IssueFields;\n\tconst marked = fields.params?.[RULE_PARAM];\n\tif (typeof marked === 'string' && Object.hasOwn(rules, marked))\n\t\treturn marked as ConstraintArgument;\n\treturn Object.values(rules).find((rule) => rule.owns(fields))?.argument;\n}\n"
|
|
23
23
|
],
|
|
24
|
-
"mappings": "
|
|
25
|
-
"debugId": "
|
|
24
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;ACoFO,IAAM,aAAa;AAGnB,SAAS,UAIf,CAAC,MAAoC;AAAA,EACrC,OAAO;AAAA;AAID,IAAM,UAAU,CAAC,UAA0B,KAAK,UAAU,KAAK;;;AC9F/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;;ACPM,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,UAA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AAK,MAAM,EAChD,KAAK;AAAA,CAAI;AAAA;AAAA;AAIX,IAAM,UAAU,IAAI,IAAY;AAAA,EAC/B,kBAAkB;AAAA,EAClB,kBAAkB;AACnB,CAAC;AASM,SAAS,mBAAmB,CAAC,WAAmC;AAAA,EACtE,MAAM,WAAW;AAAA,IAChB,GAAI,UAAU,eACX,CAAC,4CAA4C,IAC7C,CAAC;AAAA,IACJ,GAAG,UAAU,UACX,OAAO,CAAC,aAAa,CAAC,QAAQ,IAAI,QAAQ,CAAC,EAC3C,IAAI,CAAC,aAAa,cAAc,UAAU;AAAA,IAC5C,GAAG,UAAU,KAAK,QAAQ,CAAC,QAAQ;AAAA,MAClC,MAAM,OAAQ,MACb,IAAI;AAAA,MAEL,IAAI,CAAC;AAAA,QAAM,OAAO,CAAC,YAAY,IAAI,2BAA2B;AAAA,MAC9D,MAAM,OAAO,OAAO,IAAI,IAAI;AAAA,MAC5B,OAAO,SAAS,KAAK,OAClB,CAAC,IACD,CAAC,YAAY,IAAI,SAAS,aAAa,KAAK,MAAM;AAAA,KACrD;AAAA,EACF;AAAA,EACA,IAAI,SAAS,SAAS,GAAG;AAAA,IACxB,MAAM,IAAI,MACT,+DAA+D,SAAS,KAAK,IAAI,wCAClF;AAAA,EACD;AAAA;",
|
|
25
|
+
"debugId": "02497C6067AC4D4564756E2164756E21",
|
|
26
26
|
"names": []
|
|
27
27
|
}
|
|
@@ -4,27 +4,7 @@ import {
|
|
|
4
4
|
rules,
|
|
5
5
|
applyRule,
|
|
6
6
|
assertOwnConstraint
|
|
7
|
-
} from "./index-
|
|
8
|
-
|
|
9
|
-
// src/builder/constraints.ts
|
|
10
|
-
import {
|
|
11
|
-
getDirectiveValues
|
|
12
|
-
} from "graphql";
|
|
13
|
-
function constraintsOn2(directive, node) {
|
|
14
|
-
if (!directive || !node)
|
|
15
|
-
return [];
|
|
16
|
-
const values = getDirectiveValues(directive, { directives: node.directives ?? [] }) ?? {};
|
|
17
|
-
return Object.entries(values).filter(([, value]) => value !== undefined && value !== null).map(([argument, value]) => ({
|
|
18
|
-
rule: rules[argument],
|
|
19
|
-
value
|
|
20
|
-
})).sort((a, b) => Number(Boolean(b.rule.base)) - Number(Boolean(a.rule.base)));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// src/builder/check-constraints.ts
|
|
24
|
-
import {
|
|
25
|
-
isInterfaceType,
|
|
26
|
-
isObjectType
|
|
27
|
-
} from "graphql";
|
|
7
|
+
} from "./index-atwkcfg3.js";
|
|
28
8
|
|
|
29
9
|
// src/formats/all.ts
|
|
30
10
|
var exports_all = {};
|
|
@@ -39,6 +19,12 @@ __export(exports_all, {
|
|
|
39
19
|
uuidFormat: () => uuidFormat
|
|
40
20
|
});
|
|
41
21
|
|
|
22
|
+
// src/builder/check-constraints.ts
|
|
23
|
+
import {
|
|
24
|
+
isInterfaceType,
|
|
25
|
+
isObjectType
|
|
26
|
+
} from "graphql";
|
|
27
|
+
|
|
42
28
|
// src/formats/byte.ts
|
|
43
29
|
import { z } from "zod";
|
|
44
30
|
|
|
@@ -276,6 +262,22 @@ function registryOf(own) {
|
|
|
276
262
|
|
|
277
263
|
// src/builder/args-schema.ts
|
|
278
264
|
import { z as z10 } from "zod";
|
|
265
|
+
|
|
266
|
+
// src/builder/constraints.ts
|
|
267
|
+
import {
|
|
268
|
+
getDirectiveValues
|
|
269
|
+
} from "graphql";
|
|
270
|
+
function constraintsOn2(directive, node) {
|
|
271
|
+
if (!directive || !node)
|
|
272
|
+
return [];
|
|
273
|
+
const values = getDirectiveValues(directive, { directives: node.directives ?? [] }) ?? {};
|
|
274
|
+
return Object.entries(values).filter(([, value]) => value !== undefined && value !== null).map(([argument, value]) => ({
|
|
275
|
+
rule: rules[argument],
|
|
276
|
+
value
|
|
277
|
+
})).sort((a, b) => Number(Boolean(b.rule.base)) - Number(Boolean(a.rule.base)));
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// src/builder/args-schema.ts
|
|
279
281
|
function argsSchemaOf(inputs, parent, field) {
|
|
280
282
|
if (!field.args.some((arg) => inputs.needsCheck(arg)))
|
|
281
283
|
return;
|
|
@@ -307,12 +309,44 @@ function assertInterfaceConstraintsKept(inputs, type) {
|
|
|
307
309
|
}
|
|
308
310
|
}
|
|
309
311
|
|
|
310
|
-
// src/builder/
|
|
312
|
+
// src/builder/declared.ts
|
|
311
313
|
import {
|
|
312
314
|
getNamedType,
|
|
313
315
|
isInputObjectType,
|
|
314
316
|
isListType,
|
|
315
|
-
isNonNullType
|
|
317
|
+
isNonNullType
|
|
318
|
+
} from "graphql";
|
|
319
|
+
function declaredAt(inputs, field, path) {
|
|
320
|
+
const [name, ...rest] = path;
|
|
321
|
+
const arg = field.args.find((candidate) => candidate.name === name);
|
|
322
|
+
if (!arg)
|
|
323
|
+
return [];
|
|
324
|
+
let type = arg.type;
|
|
325
|
+
let constraints = constraintsOn2(inputs.directive, arg.astNode);
|
|
326
|
+
for (const key of rest) {
|
|
327
|
+
const unwrapped = isNonNullType(type) ? type.ofType : type;
|
|
328
|
+
if (isListType(unwrapped) && typeof key === "number") {
|
|
329
|
+
constraints = constraints.filter(({ rule }) => rule.target !== "list");
|
|
330
|
+
type = unwrapped.ofType;
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
const named = getNamedType(unwrapped);
|
|
334
|
+
const next = !isListType(unwrapped) && isInputObjectType(named) ? named.getFields()[String(key)] : undefined;
|
|
335
|
+
if (!next)
|
|
336
|
+
return [];
|
|
337
|
+
type = next.type;
|
|
338
|
+
constraints = constraintsOn2(inputs.directive, next.astNode);
|
|
339
|
+
}
|
|
340
|
+
const onList = isListType(isNonNullType(type) ? type.ofType : type);
|
|
341
|
+
return constraints.filter(({ rule }) => rule.target === "list" === onList);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// src/builder/input-schema.ts
|
|
345
|
+
import {
|
|
346
|
+
getNamedType as getNamedType2,
|
|
347
|
+
isInputObjectType as isInputObjectType2,
|
|
348
|
+
isListType as isListType2,
|
|
349
|
+
isNonNullType as isNonNullType2,
|
|
316
350
|
valueFromAST
|
|
317
351
|
} from "graphql";
|
|
318
352
|
import { z as z12 } from "zod";
|
|
@@ -392,7 +426,7 @@ class InputSchemas {
|
|
|
392
426
|
constructor(schema, formats = registryOf()) {
|
|
393
427
|
this.#context = { formats };
|
|
394
428
|
this.directive = schema.getDirective("constraint") ?? undefined;
|
|
395
|
-
const objects = Object.values(schema.getTypeMap()).filter(
|
|
429
|
+
const objects = Object.values(schema.getTypeMap()).filter(isInputObjectType2);
|
|
396
430
|
for (let changed = true;changed; ) {
|
|
397
431
|
changed = false;
|
|
398
432
|
for (const type of objects) {
|
|
@@ -407,12 +441,12 @@ class InputSchemas {
|
|
|
407
441
|
}
|
|
408
442
|
}
|
|
409
443
|
isConstrained(type) {
|
|
410
|
-
const named =
|
|
411
|
-
return
|
|
444
|
+
const named = getNamedType2(type);
|
|
445
|
+
return isInputObjectType2(named) && this.#constrained.has(named.name);
|
|
412
446
|
}
|
|
413
447
|
buildAll(schema) {
|
|
414
448
|
for (const type of Object.values(schema.getTypeMap())) {
|
|
415
|
-
if (
|
|
449
|
+
if (isInputObjectType2(type))
|
|
416
450
|
this.#object(type);
|
|
417
451
|
}
|
|
418
452
|
}
|
|
@@ -446,14 +480,14 @@ class InputSchemas {
|
|
|
446
480
|
}
|
|
447
481
|
}
|
|
448
482
|
#typed(type, constraints, where) {
|
|
449
|
-
if (
|
|
483
|
+
if (isNonNullType2(type))
|
|
450
484
|
return this.#required(type.ofType, constraints, where);
|
|
451
485
|
return this.#required(type, constraints, where).nullish();
|
|
452
486
|
}
|
|
453
487
|
#required(type, constraints, where) {
|
|
454
|
-
if (
|
|
488
|
+
if (isNonNullType2(type))
|
|
455
489
|
return this.#required(type.ofType, constraints, where);
|
|
456
|
-
if (
|
|
490
|
+
if (isListType2(type)) {
|
|
457
491
|
const own = constraints.filter(({ rule }) => rule.target === "list");
|
|
458
492
|
const items = constraints.filter(({ rule }) => rule.target !== "list");
|
|
459
493
|
let list = z12.array(this.#typed(type.ofType, items, where));
|
|
@@ -461,7 +495,7 @@ class InputSchemas {
|
|
|
461
495
|
list = applyRule(rule, list, value, this.#context);
|
|
462
496
|
return list;
|
|
463
497
|
}
|
|
464
|
-
if (
|
|
498
|
+
if (isInputObjectType2(type)) {
|
|
465
499
|
assertObjectTargets(type.name, constraints, where);
|
|
466
500
|
return this.#object(type);
|
|
467
501
|
}
|
|
@@ -505,7 +539,7 @@ function checkConstraints2(schema, onArgs, formats) {
|
|
|
505
539
|
for (const field of Object.values(type.getFields())) {
|
|
506
540
|
const args = argsSchemaOf(inputs, type.name, field);
|
|
507
541
|
if (args)
|
|
508
|
-
onArgs?.(type, field, args);
|
|
542
|
+
onArgs?.(type, field, args, (path) => declaredAt(inputs, field, path));
|
|
509
543
|
}
|
|
510
544
|
}
|
|
511
545
|
inputs.checkDefaults();
|
|
@@ -523,5 +557,5 @@ function assertNoDirectiveArgumentConstrained(inputs, schema) {
|
|
|
523
557
|
|
|
524
558
|
export { registryOf, constraintsOn2, assertLeafTargets, assertObjectTargets, baseCode, checkConstraints2 };
|
|
525
559
|
|
|
526
|
-
//# debugId=
|
|
527
|
-
//# sourceMappingURL=index-
|
|
560
|
+
//# debugId=418E0FAAA9B9E68E64756E2164756E21
|
|
561
|
+
//# sourceMappingURL=index-w9pw7fsk.js.map
|