@orion-js/schema 4.3.1 → 4.4.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/LICENSE +21 -0
- package/dist/Errors.d.ts +21 -0
- package/dist/ValidationError.d.ts +16 -0
- package/dist/clean/cleanType.d.ts +3 -0
- package/dist/clean/getObjectNode.d.ts +2 -0
- package/dist/clean/index.d.ts +3 -0
- package/dist/clean/recursiveClean.d.ts +3 -0
- package/dist/cleanAndValidate.d.ts +2 -0
- package/dist/cleanKey.d.ts +1 -0
- package/dist/clone.d.ts +1 -0
- package/dist/cloneSchema.d.ts +35 -0
- package/dist/dotGetSchema.d.ts +2 -0
- package/dist/fieldType.d.ts +19 -0
- package/dist/fieldTypes/ID.d.ts +2 -0
- package/dist/fieldTypes/any.d.ts +2 -0
- package/dist/fieldTypes/array.d.ts +2 -0
- package/dist/fieldTypes/blackbox.d.ts +3 -0
- package/dist/fieldTypes/boolean.d.ts +2 -0
- package/dist/fieldTypes/date.d.ts +2 -0
- package/dist/fieldTypes/email.d.ts +2 -0
- package/dist/fieldTypes/enum.d.ts +2 -0
- package/dist/fieldTypes/index.d.ts +14 -0
- package/dist/fieldTypes/integer.d.ts +2 -0
- package/dist/fieldTypes/number.d.ts +2 -0
- package/dist/fieldTypes/plainObject.d.ts +3 -0
- package/dist/fieldTypes/string.d.ts +2 -0
- package/dist/getValidationErrors/convertTypedSchema.d.ts +2 -0
- package/dist/getValidationErrors/doValidation.d.ts +2 -0
- package/dist/getValidationErrors/getError/getFieldType.d.ts +4 -0
- package/dist/getValidationErrors/getError/getFieldValidator.d.ts +3 -0
- package/dist/getValidationErrors/getError/index.d.ts +2 -0
- package/dist/getValidationErrors/getFieldLabels.d.ts +6 -0
- package/dist/getValidationErrors/getValidationErrorsObject.d.ts +4 -0
- package/dist/getValidationErrors/index.d.ts +3 -0
- package/dist/index.cjs +2 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +18 -304
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/isValid.d.ts +3 -0
- package/dist/models.d.ts +7 -0
- package/dist/schemaWithName/index.d.ts +15 -0
- package/dist/types/fieldValidators.d.ts +2 -0
- package/dist/types/fields.d.ts +37 -0
- package/dist/types/helpers.d.ts +2 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/schema.d.ts +145 -0
- package/dist/validate.d.ts +3 -0
- package/dist/validateKey/dotGetSchema.d.ts +2 -0
- package/dist/validateKey/index.d.ts +2 -0
- package/package.json +10 -11
- package/dist/index.d.cts +0 -304
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Orionjs Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/Errors.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
NOT_IN_SCHEMA: string;
|
|
3
|
+
REQUIRED: string;
|
|
4
|
+
UNKNOWN_FIELD_TYPE: string;
|
|
5
|
+
NOT_AN_ARRAY: string;
|
|
6
|
+
NOT_AN_OBJECT: string;
|
|
7
|
+
NOT_A_STRING: string;
|
|
8
|
+
NOT_A_DATE: string;
|
|
9
|
+
NOT_AN_INTEGER: string;
|
|
10
|
+
NOT_A_NUMBER: string;
|
|
11
|
+
NOT_AN_ID: string;
|
|
12
|
+
STRING_TOO_SHORT: string;
|
|
13
|
+
STRING_TOO_LONG: string;
|
|
14
|
+
NUMBER_TOO_SMALL: string;
|
|
15
|
+
NUMBER_TOO_BIG: string;
|
|
16
|
+
NOT_A_BOOLEAN: string;
|
|
17
|
+
NOT_AN_EMAIL: string;
|
|
18
|
+
NOT_UNIQUE: string;
|
|
19
|
+
NOT_AN_ALLOWED_VALUE: string;
|
|
20
|
+
};
|
|
21
|
+
export default _default;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface ValidationErrorInfo {
|
|
2
|
+
error: string;
|
|
3
|
+
message: string;
|
|
4
|
+
validationErrors: Record<string, string>;
|
|
5
|
+
labels: Record<string, string>;
|
|
6
|
+
}
|
|
7
|
+
export default class ValidationError extends Error {
|
|
8
|
+
code: string;
|
|
9
|
+
isValidationError: boolean;
|
|
10
|
+
isOrionError: boolean;
|
|
11
|
+
validationErrors: Record<string, string>;
|
|
12
|
+
labels: Record<string, string>;
|
|
13
|
+
constructor(validationErrors: Record<string, string>, labels?: Record<string, string>);
|
|
14
|
+
getInfo: () => ValidationErrorInfo;
|
|
15
|
+
prependKey: (prepend: any) => ValidationError;
|
|
16
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { FieldValidatorType } from '../types/fieldValidators';
|
|
2
|
+
import { CurrentNodeInfo, SchemaFieldType, SchemaNode } from '../types/schema';
|
|
3
|
+
export default function cleanType(type: SchemaFieldType | FieldValidatorType, fieldSchema: Partial<SchemaNode>, value: any, info: CurrentNodeInfo, ...args: any[]): Promise<any>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { InferSchemaType } from '../types';
|
|
2
|
+
import { CurrentNodeInfoOptions, SchemaFieldType } from '../types/schema';
|
|
3
|
+
export default function clean<TSchema extends SchemaFieldType>(schema: TSchema, doc: InferSchemaType<TSchema>, opts?: CurrentNodeInfoOptions, ...args: any[]): Promise<InferSchemaType<TSchema>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function (schema: any, key: any, value: any, passedOptions?: {}, ...args: any[]): Promise<any>;
|
package/dist/clone.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function clone<T>(value: T): T;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Schema, SchemaNode } from './types';
|
|
2
|
+
export type CloneSchemaOptions<TSchema extends Schema, TExtendFields extends Schema | undefined = undefined, TPickFields extends (keyof TSchema)[] | undefined = undefined, TOmitFields extends (keyof TSchema)[] | undefined = undefined> = {
|
|
3
|
+
/**
|
|
4
|
+
* The schema to clone
|
|
5
|
+
*/
|
|
6
|
+
schema: TSchema;
|
|
7
|
+
/**
|
|
8
|
+
* The name of the cloned schema
|
|
9
|
+
*/
|
|
10
|
+
name?: string;
|
|
11
|
+
/**
|
|
12
|
+
* The schema to extend the cloned schema with
|
|
13
|
+
*/
|
|
14
|
+
extendSchema?: TExtendFields;
|
|
15
|
+
/**
|
|
16
|
+
* A function to map the fields of the cloned schema.
|
|
17
|
+
* Warning: This function will not be applied to the typescript types of this schema.
|
|
18
|
+
*/
|
|
19
|
+
mapFields?: (field: TSchema[keyof TSchema], key: keyof TSchema) => SchemaNode;
|
|
20
|
+
/**
|
|
21
|
+
* The fields to pick from the cloned schema
|
|
22
|
+
*/
|
|
23
|
+
pickFields?: TPickFields;
|
|
24
|
+
/**
|
|
25
|
+
* The fields to omit from the cloned schema
|
|
26
|
+
*/
|
|
27
|
+
omitFields?: TOmitFields;
|
|
28
|
+
};
|
|
29
|
+
type ExtendFields<TSchema extends Schema, TExtendFields extends Schema | undefined> = TExtendFields extends undefined ? TSchema : {
|
|
30
|
+
[key in keyof (TSchema & TExtendFields)]: key extends keyof TExtendFields ? TExtendFields[key] : key extends keyof TSchema ? TSchema[key] : never;
|
|
31
|
+
};
|
|
32
|
+
type PickOrOmit<TSchema extends Schema, TPickFields extends (keyof TSchema)[] | undefined = undefined, TOmitFields extends (keyof TSchema)[] | undefined = undefined> = TPickFields extends undefined ? TOmitFields extends undefined ? TSchema : Omit<TSchema, TOmitFields[number]> : Pick<TSchema, TPickFields[number]>;
|
|
33
|
+
export type ClonedSchema<TSchema extends Schema, TExtendFields extends Schema | undefined = undefined, TPickFields extends (keyof TSchema)[] | undefined = undefined, TOmitFields extends (keyof TSchema)[] | undefined = undefined> = ExtendFields<PickOrOmit<TSchema, TPickFields, TOmitFields>, TExtendFields>;
|
|
34
|
+
export declare function cloneSchema<TSchema extends Schema, TExtendFields extends Schema | undefined = undefined, TPickFields extends (keyof TSchema)[] | undefined = undefined, TOmitFields extends (keyof TSchema)[] | undefined = undefined>(options: CloneSchemaOptions<TSchema, TExtendFields, TPickFields, TOmitFields>): ClonedSchema<TSchema, TExtendFields, TPickFields, TOmitFields>;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CleanFunction, SchemaFieldType, SchemaNode, ValidateFunction } from './types/schema';
|
|
2
|
+
export interface FieldTypeOpts<TType = any> {
|
|
3
|
+
name: string;
|
|
4
|
+
validate?: ValidateFunction<TType>;
|
|
5
|
+
clean?: CleanFunction<TType>;
|
|
6
|
+
toGraphQLType?: (GraphQL: any) => any;
|
|
7
|
+
meta?: any;
|
|
8
|
+
}
|
|
9
|
+
export interface FieldType<TType = any> {
|
|
10
|
+
name: string;
|
|
11
|
+
validate: ValidateFunction;
|
|
12
|
+
clean: CleanFunction;
|
|
13
|
+
meta?: any;
|
|
14
|
+
toGraphQLType?: (GraphQL: any) => any;
|
|
15
|
+
toSerializedType?: (node: SchemaNode) => Promise<SchemaFieldType>;
|
|
16
|
+
__tsFieldType: TType;
|
|
17
|
+
__isFieldType: boolean;
|
|
18
|
+
}
|
|
19
|
+
export default function fieldType<TType>(opts: FieldTypeOpts<TType>): FieldType<TType>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
array: import("..").FieldType<any[]>;
|
|
3
|
+
plainObject: import("..").FieldType<import("..").Blackbox>;
|
|
4
|
+
string: import("..").FieldType<string>;
|
|
5
|
+
date: import("..").FieldType<Date>;
|
|
6
|
+
integer: import("..").FieldType<number>;
|
|
7
|
+
number: import("..").FieldType<number>;
|
|
8
|
+
ID: import("..").FieldType<string>;
|
|
9
|
+
boolean: import("..").FieldType<boolean>;
|
|
10
|
+
email: import("..").FieldType<string>;
|
|
11
|
+
blackbox: import("..").FieldType<import("..").Blackbox>;
|
|
12
|
+
any: import("..").FieldType<any>;
|
|
13
|
+
};
|
|
14
|
+
export default _default;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { SchemaFieldType } from '../types/schema';
|
|
2
|
+
/**
|
|
3
|
+
* Extracts field labels from a schema, creating a flat object with dot-notation keys
|
|
4
|
+
* matching the validation error keys and their corresponding labels.
|
|
5
|
+
*/
|
|
6
|
+
export default function getFieldLabels(schema: SchemaFieldType, currentKey?: string): Record<string, string>;
|
package/dist/index.cjs
CHANGED
|
@@ -915,7 +915,8 @@ function getArrayNode(schema2, value) {
|
|
|
915
915
|
var clean = async (info) => {
|
|
916
916
|
convertTypedSchema(info);
|
|
917
917
|
const { schema: schema2, args = [], value } = info;
|
|
918
|
-
const
|
|
918
|
+
const schemaValue = schema2;
|
|
919
|
+
const currSchema = typeof schemaValue === "object" && schemaValue !== null && "type" in schemaValue ? schemaValue : { type: schemaValue };
|
|
919
920
|
const objectSchema = getObjectNode(currSchema, value);
|
|
920
921
|
if (objectSchema) {
|
|
921
922
|
const newDoc = await cleanObjectFields({
|