@sanity/validation 2.33.4-shopify.8 → 3.0.0-canary.186

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 (87) hide show
  1. package/lib/dts/src/index.d.ts +36 -0
  2. package/lib/index.js +1547 -30
  3. package/lib/index.js.map +1 -0
  4. package/lib/index.mjs +1542 -0
  5. package/lib/index.mjs.map +1 -0
  6. package/package.json +26 -10
  7. package/src/Rule.ts +6 -2
  8. package/src/index.ts +3 -1
  9. package/src/inferFromSchema.ts +7 -1
  10. package/src/util/convertToValidationMarker.ts +5 -3
  11. package/src/util/requestIdleCallback.ts +31 -0
  12. package/src/validateDocument.test.ts +35 -101
  13. package/src/validateDocument.ts +119 -50
  14. package/src/validators/dateValidator.ts +4 -4
  15. package/src/validators/slugValidator.ts +19 -5
  16. package/src/validators/stringValidator.ts +2 -1
  17. package/dist/dts/Rule.d.ts +0 -4
  18. package/dist/dts/Rule.d.ts.map +0 -1
  19. package/dist/dts/ValidationError.d.ts +0 -4
  20. package/dist/dts/ValidationError.d.ts.map +0 -1
  21. package/dist/dts/getClient.d.ts +0 -3
  22. package/dist/dts/getClient.d.ts.map +0 -1
  23. package/dist/dts/index.d.ts +0 -13
  24. package/dist/dts/index.d.ts.map +0 -1
  25. package/dist/dts/inferFromSchema.d.ts +0 -4
  26. package/dist/dts/inferFromSchema.d.ts.map +0 -1
  27. package/dist/dts/inferFromSchemaType.d.ts +0 -5
  28. package/dist/dts/inferFromSchemaType.d.ts.map +0 -1
  29. package/dist/dts/util/convertToValidationMarker.d.ts +0 -6
  30. package/dist/dts/util/convertToValidationMarker.d.ts.map +0 -1
  31. package/dist/dts/util/deepEquals.d.ts +0 -6
  32. package/dist/dts/util/deepEquals.d.ts.map +0 -1
  33. package/dist/dts/util/escapeRegex.d.ts +0 -3
  34. package/dist/dts/util/escapeRegex.d.ts.map +0 -1
  35. package/dist/dts/util/normalizeValidationRules.d.ts +0 -6
  36. package/dist/dts/util/normalizeValidationRules.d.ts.map +0 -1
  37. package/dist/dts/util/normalizeValidationRules.test.d.ts +0 -2
  38. package/dist/dts/util/normalizeValidationRules.test.d.ts.map +0 -1
  39. package/dist/dts/util/pathToString.d.ts +0 -3
  40. package/dist/dts/util/pathToString.d.ts.map +0 -1
  41. package/dist/dts/util/typeString.d.ts +0 -2
  42. package/dist/dts/util/typeString.d.ts.map +0 -1
  43. package/dist/dts/util/typeString.test.d.ts +0 -2
  44. package/dist/dts/util/typeString.test.d.ts.map +0 -1
  45. package/dist/dts/validateDocument.d.ts +0 -22
  46. package/dist/dts/validateDocument.d.ts.map +0 -1
  47. package/dist/dts/validateDocument.test.d.ts +0 -2
  48. package/dist/dts/validateDocument.test.d.ts.map +0 -1
  49. package/dist/dts/validators/arrayValidator.d.ts +0 -4
  50. package/dist/dts/validators/arrayValidator.d.ts.map +0 -1
  51. package/dist/dts/validators/booleanValidator.d.ts +0 -4
  52. package/dist/dts/validators/booleanValidator.d.ts.map +0 -1
  53. package/dist/dts/validators/dateValidator.d.ts +0 -5
  54. package/dist/dts/validators/dateValidator.d.ts.map +0 -1
  55. package/dist/dts/validators/genericValidator.d.ts +0 -4
  56. package/dist/dts/validators/genericValidator.d.ts.map +0 -1
  57. package/dist/dts/validators/numberValidator.d.ts +0 -4
  58. package/dist/dts/validators/numberValidator.d.ts.map +0 -1
  59. package/dist/dts/validators/objectValidator.d.ts +0 -4
  60. package/dist/dts/validators/objectValidator.d.ts.map +0 -1
  61. package/dist/dts/validators/slugValidator.d.ts +0 -9
  62. package/dist/dts/validators/slugValidator.d.ts.map +0 -1
  63. package/dist/dts/validators/stringValidator.d.ts +0 -4
  64. package/dist/dts/validators/stringValidator.d.ts.map +0 -1
  65. package/jest.config.js +0 -5
  66. package/lib/Rule.js +0 -491
  67. package/lib/ValidationError.js +0 -39
  68. package/lib/getClient.js +0 -20
  69. package/lib/inferFromSchema.js +0 -22
  70. package/lib/inferFromSchemaType.js +0 -86
  71. package/lib/util/convertToValidationMarker.js +0 -65
  72. package/lib/util/deepEquals.js +0 -87
  73. package/lib/util/escapeRegex.js +0 -14
  74. package/lib/util/normalizeValidationRules.js +0 -115
  75. package/lib/util/pathToString.js +0 -30
  76. package/lib/util/typeString.js +0 -29
  77. package/lib/validateDocument.js +0 -231
  78. package/lib/validators/arrayValidator.js +0 -123
  79. package/lib/validators/booleanValidator.js +0 -29
  80. package/lib/validators/dateValidator.js +0 -120
  81. package/lib/validators/genericValidator.js +0 -135
  82. package/lib/validators/numberValidator.js +0 -70
  83. package/lib/validators/objectValidator.js +0 -93
  84. package/lib/validators/slugValidator.js +0 -133
  85. package/lib/validators/stringValidator.js +0 -131
  86. package/src/getClient.ts +0 -13
  87. package/tsconfig.json +0 -10
@@ -1,4 +0,0 @@
1
- import { Schema } from '@sanity/types';
2
- declare function inferFromSchema(schema: Schema): Schema;
3
- export default inferFromSchema;
4
- //# sourceMappingURL=inferFromSchema.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"inferFromSchema.d.ts","sourceRoot":"","sources":["../../src/inferFromSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,eAAe,CAAA;AAIpC,iBAAS,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAM/C;AAED,eAAe,eAAe,CAAA"}
@@ -1,5 +0,0 @@
1
- import { Schema, SchemaType } from '@sanity/types';
2
- declare function inferFromSchemaType(typeDef: SchemaType, _schema: Schema, _visited?: Set<SchemaType>): SchemaType;
3
- declare function inferFromSchemaType(typeDef: SchemaType): SchemaType;
4
- export default inferFromSchemaType;
5
- //# sourceMappingURL=inferFromSchemaType.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"inferFromSchemaType.d.ts","sourceRoot":"","sources":["../../src/inferFromSchemaType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,UAAU,EAAC,MAAM,eAAe,CAAA;AAoChD,iBAAS,mBAAmB,CAC1B,OAAO,EAAE,UAAU,EAEnB,OAAO,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,GAAG,CAAC,UAAU,CAAC,GACzB,UAAU,CAAA;AAEb,iBAAS,mBAAmB,CAAC,OAAO,EAAE,UAAU,GAAG,UAAU,CAAA;AAM7D,eAAe,mBAAmB,CAAA"}
@@ -1,6 +0,0 @@
1
- import { ValidationMarker, ValidationError, ValidationContext } from '@sanity/types';
2
- declare type ValidationErrorLike = Pick<ValidationError, 'message'> & Partial<ValidationError>;
3
- export declare function isNonNullable<T>(t: T): t is NonNullable<T>;
4
- export default function convertToValidationMarker(validatorResult: true | true[] | string | string[] | ValidationError | ValidationError[] | ValidationErrorLike | ValidationErrorLike[], level: 'error' | 'warning' | 'info' | undefined, context: ValidationContext): ValidationMarker[];
5
- export {};
6
- //# sourceMappingURL=convertToValidationMarker.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"convertToValidationMarker.d.ts","sourceRoot":"","sources":["../../../src/util/convertToValidationMarker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAE,eAAe,EAAE,iBAAiB,EAAC,MAAM,eAAe,CAAA;AAIlF,aAAK,mBAAmB,GAAG,IAAI,CAAC,eAAe,EAAE,SAAS,CAAC,GAAG,OAAO,CAAC,eAAe,CAAC,CAAA;AAEtF,wBAAgB,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,CAE1D;AAED,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAC/C,eAAe,EACX,IAAI,GACJ,IAAI,EAAE,GACN,MAAM,GACN,MAAM,EAAE,GACR,eAAe,GACf,eAAe,EAAE,GACjB,mBAAmB,GACnB,mBAAmB,EAAE,EACzB,KAAK,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,EAC/C,OAAO,EAAE,iBAAiB,GACzB,gBAAgB,EAAE,CA2DpB"}
@@ -1,6 +0,0 @@
1
- /**
2
- * Modified version of fast-deep-equal (https://github.com/epoberezkin/fast-deep-equal)
3
- * MIT-licensed, copyright (c) 2017 Evgeny Poberezkin
4
- **/
5
- export default function deepEquals(a: unknown, b: unknown): boolean;
6
- //# sourceMappingURL=deepEquals.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"deepEquals.d.ts","sourceRoot":"","sources":["../../../src/util/deepEquals.ts"],"names":[],"mappings":"AAAA;;;IAGI;AAOJ,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAkElE"}
@@ -1,3 +0,0 @@
1
- declare const _default: (string: string) => string;
2
- export default _default;
3
- //# sourceMappingURL=escapeRegex.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"escapeRegex.d.ts","sourceRoot":"","sources":["../../../src/util/escapeRegex.ts"],"names":[],"mappings":"iCACwB,MAAM,KAAG,MAAM;AAAvC,wBAGC"}
@@ -1,6 +0,0 @@
1
- import { SchemaType, Rule } from '@sanity/types';
2
- /**
3
- * Takes in `SchemaValidationValue` and returns an array of `Rule` instances.
4
- */
5
- export default function normalizeValidationRules(typeDef: SchemaType | undefined): Rule[];
6
- //# sourceMappingURL=normalizeValidationRules.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"normalizeValidationRules.d.ts","sourceRoot":"","sources":["../../../src/util/normalizeValidationRules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,IAAI,EAAqB,MAAM,eAAe,CAAA;AA6ElE;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,wBAAwB,CAAC,OAAO,EAAE,UAAU,GAAG,SAAS,GAAG,IAAI,EAAE,CAqCxF"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=normalizeValidationRules.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"normalizeValidationRules.test.d.ts","sourceRoot":"","sources":["../../../src/util/normalizeValidationRules.test.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- import { Path } from '@sanity/types';
2
- export default function pathToString(path?: Path | undefined): string;
3
- //# sourceMappingURL=pathToString.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pathToString.d.ts","sourceRoot":"","sources":["../../../src/util/pathToString.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAgB,MAAM,eAAe,CAAA;AAEjD,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,IAAI,GAAE,IAAI,GAAG,SAAc,GAAG,MAAM,CAkBxE"}
@@ -1,2 +0,0 @@
1
- export default function typeString(obj: unknown): string;
2
- //# sourceMappingURL=typeString.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"typeString.d.ts","sourceRoot":"","sources":["../../../src/util/typeString.ts"],"names":[],"mappings":"AAaA,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CASvD"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=typeString.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"typeString.test.d.ts","sourceRoot":"","sources":["../../../src/util/typeString.test.ts"],"names":[],"mappings":""}
@@ -1,22 +0,0 @@
1
- import { SanityDocument, Schema, SchemaType, ValidationContext, ValidationMarker } from '@sanity/types';
2
- /**
3
- * @internal
4
- */
5
- export declare function resolveTypeForArrayItem(item: unknown, candidates: SchemaType[]): SchemaType | undefined;
6
- export default function validateDocument(doc: SanityDocument, schema: Schema, context?: Pick<ValidationContext, 'getDocumentExists'>): Promise<ValidationMarker[]>;
7
- /**
8
- * this is used make optional properties required by replacing optionals with
9
- * `T[P] | undefined`. this is used to prevent errors in `validateItem` where
10
- * an option from a previous invocation would be incorrectly passed down.
11
- *
12
- * https://medium.com/terria/typescript-transforming-optional-properties-to-required-properties-that-may-be-undefined-7482cb4e1585
13
- */
14
- declare type ExplicitUndefined<T> = {
15
- [P in keyof Required<T>]: Pick<T, P> extends Required<Pick<T, P>> ? T[P] : T[P] | undefined;
16
- };
17
- declare type ValidateItemOptions = {
18
- value: unknown;
19
- } & ExplicitUndefined<ValidationContext>;
20
- export declare function validateItem({ value, type, path, parent, ...restOfContext }: ValidateItemOptions): Promise<ValidationMarker[]>;
21
- export {};
22
- //# sourceMappingURL=validateDocument.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validateDocument.d.ts","sourceRoot":"","sources":["../../src/validateDocument.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,MAAM,EACN,UAAU,EACV,iBAAiB,EACjB,gBAAgB,EAMjB,MAAM,eAAe,CAAA;AAYtB;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,OAAO,EACb,UAAU,EAAE,UAAU,EAAE,GACvB,UAAU,GAAG,SAAS,CAiBxB;AAED,wBAA8B,gBAAgB,CAC5C,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,IAAI,CAAC,iBAAiB,EAAE,mBAAmB,CAAC,GACrD,OAAO,CAAC,gBAAgB,EAAE,CAAC,CA2B7B;AAED;;;;;;GAMG;AACH,aAAK,iBAAiB,CAAC,CAAC,IAAI;KACzB,CAAC,IAAI,MAAM,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS;CAC5F,CAAA;AAED,aAAK,mBAAmB,GAAG;IACzB,KAAK,EAAE,OAAO,CAAA;CACf,GAAG,iBAAiB,CAAC,iBAAiB,CAAC,CAAA;AAExC,wBAAsB,YAAY,CAAC,EACjC,KAAK,EACL,IAAI,EACJ,IAAS,EACT,MAAM,EACN,GAAG,aAAa,EACjB,EAAE,mBAAmB,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC,CA4HnD"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=validateDocument.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validateDocument.test.d.ts","sourceRoot":"","sources":["../../src/validateDocument.test.ts"],"names":[],"mappings":""}
@@ -1,4 +0,0 @@
1
- import { Validators } from '@sanity/types';
2
- declare const arrayValidators: Validators;
3
- export default arrayValidators;
4
- //# sourceMappingURL=arrayValidator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"arrayValidator.d.ts","sourceRoot":"","sources":["../../../src/validators/arrayValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,UAAU,EAAC,MAAM,eAAe,CAAA;AAK3D,QAAA,MAAM,eAAe,EAAE,UA4FtB,CAAA;AAED,eAAe,eAAe,CAAA"}
@@ -1,4 +0,0 @@
1
- import { Validators } from '@sanity/types';
2
- declare const booleanValidators: Validators;
3
- export default booleanValidators;
4
- //# sourceMappingURL=booleanValidator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"booleanValidator.d.ts","sourceRoot":"","sources":["../../../src/validators/booleanValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAA;AAGxC,QAAA,MAAM,iBAAiB,EAAE,UAUxB,CAAA;AAED,eAAe,iBAAiB,CAAA"}
@@ -1,5 +0,0 @@
1
- import { Validators } from '@sanity/types';
2
- export declare function isRecord(obj: unknown): obj is Record<string, unknown>;
3
- declare const dateValidators: Validators;
4
- export default dateValidators;
5
- //# sourceMappingURL=dateValidator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dateValidator.d.ts","sourceRoot":"","sources":["../../../src/validators/dateValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAA;AAIxC,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAErE;AAiDD,QAAA,MAAM,cAAc,EAAE,UAuDrB,CAAA;AAED,eAAe,cAAc,CAAA"}
@@ -1,4 +0,0 @@
1
- import { Validators } from '@sanity/types';
2
- declare const genericValidators: Validators;
3
- export default genericValidators;
4
- //# sourceMappingURL=genericValidator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"genericValidator.d.ts","sourceRoot":"","sources":["../../../src/validators/genericValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,UAAU,EAAC,MAAM,eAAe,CAAA;AA+B1D,QAAA,MAAM,iBAAiB,EAAE,UAmFxB,CAAA;AAED,eAAe,iBAAiB,CAAA"}
@@ -1,4 +0,0 @@
1
- import { Validators } from '@sanity/types';
2
- declare const numberValidators: Validators;
3
- export default numberValidators;
4
- //# sourceMappingURL=numberValidator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"numberValidator.d.ts","sourceRoot":"","sources":["../../../src/validators/numberValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAA;AAKxC,QAAA,MAAM,gBAAgB,EAAE,UA0DvB,CAAA;AAED,eAAe,gBAAgB,CAAA"}
@@ -1,4 +0,0 @@
1
- import { Validators } from '@sanity/types';
2
- declare const objectValidators: Validators;
3
- export default objectValidators;
4
- //# sourceMappingURL=objectValidator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"objectValidator.d.ts","sourceRoot":"","sources":["../../../src/validators/objectValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAc,MAAM,eAAe,CAAA;AAKrD,QAAA,MAAM,gBAAgB,EAAE,UAwDvB,CAAA;AAED,eAAe,gBAAgB,CAAA"}
@@ -1,9 +0,0 @@
1
- import { CustomValidator } from '@sanity/types';
2
- /**
3
- * Validates slugs values by querying for uniqueness from the client.
4
- *
5
- * This is a custom rule implementation (e.g. `Rule.custom(slugValidator)`)
6
- * that's populated in `inferFromSchemaType` when the type name is `slug`
7
- */
8
- export declare const slugValidator: CustomValidator;
9
- //# sourceMappingURL=slugValidator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"slugValidator.d.ts","sourceRoot":"","sources":["../../../src/validators/slugValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,eAAe,EAAgB,MAAM,eAAe,CAAA;AA0EzF;;;;;GAKG;AACH,eAAO,MAAM,aAAa,EAAE,eAsB3B,CAAA"}
@@ -1,4 +0,0 @@
1
- import { Validators } from '@sanity/types';
2
- declare const stringValidators: Validators;
3
- export default stringValidators;
4
- //# sourceMappingURL=stringValidator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stringValidator.d.ts","sourceRoot":"","sources":["../../../src/validators/stringValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAA;AAOxC,QAAA,MAAM,gBAAgB,EAAE,UA6GvB,CAAA;AAED,eAAe,gBAAgB,CAAA"}
package/jest.config.js DELETED
@@ -1,5 +0,0 @@
1
- const createConfig = require('../../../createJestConfig')
2
-
3
- module.exports = createConfig({
4
- displayName: require('./package.json').name,
5
- })