@nhtio/validation 0.1.0-master-bc86d1b4 → 0.1.0-master-fb686bf1
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/index.cjs +20598 -20369
- package/index.cjs.map +1 -1
- package/index.mjs +14746 -14545
- package/index.mjs.map +1 -1
- package/package.json +6 -2
- package/private/index.d.ts +9 -2
- package/private/monkeypatches/index.d.ts +2 -0
- package/private/monkeypatches/validate_async.d.ts +23 -0
- package/private/patches/i18n.d.ts +3 -0
- package/private/patches/index.d.ts +2 -1
- package/private/patches/knex.d.ts +2 -0
- package/private/root.d.ts +17 -0
- package/private/schemas/knex.d.ts +32 -0
- package/private/schemas.d.ts +5 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nhtio/validation",
|
|
3
|
-
"version": "0.1.0-master-
|
|
3
|
+
"version": "0.1.0-master-fb686bf1",
|
|
4
4
|
"description": "A powerful schema description language and data validator",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "Jak Giveon <jak@nht.io>",
|
|
@@ -21,9 +21,13 @@
|
|
|
21
21
|
},
|
|
22
22
|
"onlyBuiltDependencies": [
|
|
23
23
|
"es5-ext",
|
|
24
|
-
"esbuild"
|
|
24
|
+
"esbuild",
|
|
25
|
+
"sqlite3"
|
|
25
26
|
]
|
|
26
27
|
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"@adonisjs/lucid": "^21.8.0"
|
|
30
|
+
},
|
|
27
31
|
"packageManager": "pnpm@10.8.0+sha512.0e82714d1b5b43c74610193cb20734897c1d00de89d0e18420aebc5977fa13d780a9cb05734624e81ebd81cc876cd464794850641c48b9544326b5622ca29971",
|
|
28
32
|
"type": "module",
|
|
29
33
|
"dependencies": {}
|
package/private/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type * as Joi from 'joi';
|
|
2
2
|
import type { DateTime } from 'luxon';
|
|
3
3
|
import type { PhoneSchema } from './schemas/phone';
|
|
4
4
|
import type { BigIntSchema } from './schemas/bigint';
|
|
@@ -6,6 +6,7 @@ import type { DatetimeSchema } from './schemas/datetime';
|
|
|
6
6
|
import type { CountryOrUnknown } from '@nhtio/phone-object';
|
|
7
7
|
import type { Root, Reference, SchemaMap, SchemaLike } from 'joi';
|
|
8
8
|
import type { I18nCallback, SetI18nCallback } from './patches/i18n';
|
|
9
|
+
import type { KnexSchema, KnexSchemaConnection, KnexSchemaSearchRuleOptions } from './schemas/knex';
|
|
9
10
|
import type { AnySchema, StringSchema, BinarySchema, NumberSchema, BooleanSchema, ObjectSchema, ArraySchema, DateSchema, AlternativesSchema, FunctionSchema, LinkSchema, SymbolSchema, Schema } from './schemas';
|
|
10
11
|
/**
|
|
11
12
|
* Extended Joi root interface that includes custom schema types for
|
|
@@ -109,6 +110,11 @@ export interface ValidationRoot extends Omit<Root, 'allow' | 'alt' | 'alternativ
|
|
|
109
110
|
* @param country - Optional country code or reference for phone validation
|
|
110
111
|
*/
|
|
111
112
|
phone<TSchema = string>(country?: CountryOrUnknown | Reference | null): PhoneSchema<TSchema>;
|
|
113
|
+
/**
|
|
114
|
+
* Generates a schema object that matches a database record using a Knex.js connection or Adonis Lucid Database connection for validation.
|
|
115
|
+
* @param connection - The database connection or QueryClientContract to use for validation
|
|
116
|
+
*/
|
|
117
|
+
knex<TSchema = any>(connection: KnexSchemaConnection): KnexSchema<TSchema>;
|
|
112
118
|
/**
|
|
113
119
|
* Returns an object where each key is a plain joi schema type.
|
|
114
120
|
* Useful for creating type shortcuts using deconstruction.
|
|
@@ -130,6 +136,7 @@ export interface ValidationRoot extends Omit<Root, 'allow' | 'alt' | 'alternativ
|
|
|
130
136
|
bigint: BigIntSchema;
|
|
131
137
|
datetime: DatetimeSchema;
|
|
132
138
|
phone: PhoneSchema;
|
|
139
|
+
knex: KnexSchema;
|
|
133
140
|
};
|
|
134
141
|
/**
|
|
135
142
|
* Whitelists a value
|
|
@@ -253,6 +260,6 @@ export interface ValidationRoot extends Omit<Root, 'allow' | 'alt' | 'alternativ
|
|
|
253
260
|
* @public
|
|
254
261
|
*/
|
|
255
262
|
export declare const validator: ValidationRoot;
|
|
256
|
-
export type { BigIntSchema, DatetimeSchema, PhoneSchema, SetI18nCallback, I18nCallback };
|
|
263
|
+
export type { BigIntSchema, DatetimeSchema, PhoneSchema, KnexSchema, SetI18nCallback, I18nCallback, KnexSchemaConnection, KnexSchemaSearchRuleOptions, };
|
|
257
264
|
export type * from './schemas';
|
|
258
265
|
export { encode, decode } from './utils';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Schema } from '../';
|
|
2
|
+
import type { AsyncValidationOptions, ValidationWarning, Context } from 'joi';
|
|
3
|
+
export declare const doValidation: (value: any, schema: any, state: any, prefs: any, overrides?: any) => Promise<any>;
|
|
4
|
+
export declare const validateAsync: <TOpts extends AsyncValidationOptions, TSchema = any>(this: Schema, value: any, options?: TOpts) => Promise<TOpts extends {
|
|
5
|
+
artifacts: true;
|
|
6
|
+
} | {
|
|
7
|
+
warnings: true;
|
|
8
|
+
} ? {
|
|
9
|
+
value: TSchema;
|
|
10
|
+
} & (TOpts extends {
|
|
11
|
+
artifacts: true;
|
|
12
|
+
} ? {
|
|
13
|
+
artifacts: Map<any, string[][]>;
|
|
14
|
+
} : {}) & (TOpts extends {
|
|
15
|
+
warnings: true;
|
|
16
|
+
} ? {
|
|
17
|
+
warning: ValidationWarning;
|
|
18
|
+
} : {}) : TSchema>;
|
|
19
|
+
export declare const doAsyncValidateForKeysSchema: (value: any, { schema, error, state, prefs }: Context) => Promise<{
|
|
20
|
+
value: any;
|
|
21
|
+
errors: any;
|
|
22
|
+
} | undefined>;
|
|
23
|
+
export declare const doAsyncValidationForAlternativesSchema: (value: any, helpers: Context) => Promise<any>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In order to create a better DX, and to allow for deeper
|
|
3
|
+
* patching of root instances of Joi, we are going to completely
|
|
4
|
+
* recreate the Joi default export here based on:
|
|
5
|
+
* https://github.com/hapijs/joi/blob/master/lib/index.js
|
|
6
|
+
* Due to the lack of type definitions for the internal parts of Joi,
|
|
7
|
+
* this file will be mainly untyped.
|
|
8
|
+
*/
|
|
9
|
+
import type { Schema } from '../index';
|
|
10
|
+
export type SchemaTypeDefinition = Schema;
|
|
11
|
+
export type SchemaTypeDefinititionMiddlewareFn = (ctx: SchemaTypeDefinition) => SchemaTypeDefinition;
|
|
12
|
+
export type ShortcutsMiddlewareFn = (ctx: string[]) => string[];
|
|
13
|
+
export type RootFactoryOptions = {
|
|
14
|
+
schemaTypeModifiers?: SchemaTypeDefinititionMiddlewareFn[];
|
|
15
|
+
shortcutsModifiers?: ShortcutsMiddlewareFn[];
|
|
16
|
+
};
|
|
17
|
+
export declare const internals: any;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Knex } from 'knex';
|
|
2
|
+
import type { AnySchema } from '../../index';
|
|
3
|
+
import type { QueryClientContract } from '@adonisjs/lucid/types/database';
|
|
4
|
+
import type { ExtensionFactory, Reference } from 'joi';
|
|
5
|
+
import type { DatabaseQueryBuilderContract } from '@adonisjs/lucid/types/querybuilder';
|
|
6
|
+
export type QueryClient = Knex | Knex.Transaction | QueryClientContract;
|
|
7
|
+
export type QueryBuilder = Knex.QueryBuilder | DatabaseQueryBuilderContract;
|
|
8
|
+
export interface KnexConnectionConfigurations {
|
|
9
|
+
client: NonNullable<Knex.Config['client']>;
|
|
10
|
+
connection: NonNullable<Knex.Config['connection']>;
|
|
11
|
+
[key: string | number | symbol]: any;
|
|
12
|
+
}
|
|
13
|
+
export type KnexSchemaConnection = QueryClient | KnexConnectionConfigurations;
|
|
14
|
+
export type KnexSchemaSearchRuleOptions = {
|
|
15
|
+
caseInsensitive: boolean;
|
|
16
|
+
filter: (queryBuilder: QueryBuilder, value: any, column: string) => void | Promise<void>;
|
|
17
|
+
};
|
|
18
|
+
export type KnexSchemaSearchRule<TSchema = any> = (table: string | Reference, column: string | Reference, options?: Partial<KnexSchemaSearchRuleOptions>) => KnexSchema<TSchema>;
|
|
19
|
+
export interface KnexSchema<TSchema = any> extends Omit<AnySchema<TSchema>, 'cast'> {
|
|
20
|
+
unique: KnexSchemaSearchRule<TSchema>;
|
|
21
|
+
exists: KnexSchemaSearchRule<TSchema>;
|
|
22
|
+
db: (connection: KnexSchemaConnection) => KnexSchema<TSchema>;
|
|
23
|
+
}
|
|
24
|
+
export declare const messages: {
|
|
25
|
+
'knex.unique': string;
|
|
26
|
+
'knex.exists': string;
|
|
27
|
+
'knex.missingConnection': string;
|
|
28
|
+
'knex.invalidTable': string;
|
|
29
|
+
'knex.invalidColumn': string;
|
|
30
|
+
'knex.internal': string;
|
|
31
|
+
};
|
|
32
|
+
export declare const knex: ExtensionFactory;
|
package/private/schemas.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { DateTime } from 'luxon';
|
|
|
2
2
|
import type { PhoneSchema } from './schemas/phone';
|
|
3
3
|
import type { BigIntSchema } from './schemas/bigint';
|
|
4
4
|
import type { DatetimeSchema } from './schemas/datetime';
|
|
5
|
+
import type { KnexSchema, KnexSchemaConnection } from './schemas/knex';
|
|
5
6
|
import type { default as Joi, AnySchema as JoiAnySchema, Reference, BasicType, CustomHelpers } from 'joi';
|
|
6
7
|
export type DefaultableValue = Reference | BasicType | DateTime | bigint | ((parent: any, helpers: CustomHelpers) => Reference | BasicType | DateTime | bigint);
|
|
7
8
|
/**
|
|
@@ -118,6 +119,10 @@ export interface AnySchema<TSchema = any> extends Omit<JoiAnySchema<TSchema>, '$
|
|
|
118
119
|
*/
|
|
119
120
|
default(value?: DefaultableValue): this;
|
|
120
121
|
cast(to: 'map' | 'number' | 'set' | 'string' | 'object'): this;
|
|
122
|
+
/**
|
|
123
|
+
* Add the Knex.js extension methods to a string schema.
|
|
124
|
+
*/
|
|
125
|
+
knex(connection: KnexSchemaConnection): KnexSchema<TSchema>;
|
|
121
126
|
}
|
|
122
127
|
/**
|
|
123
128
|
* Schema type for string validation.
|