@hedystia/validations 1.6.10 → 1.7.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/dist/index.d.ts +123 -114
- package/dist/index.js +2 -1
- package/dist/validations_bg.wasm +0 -0
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -55,10 +55,39 @@ declare namespace StandardSchemaV1 {
|
|
|
55
55
|
export { };
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
/* tslint:disable */
|
|
59
|
+
/* eslint-disable */
|
|
60
|
+
declare class HSchema {
|
|
61
|
+
private constructor();
|
|
62
|
+
free(): void;
|
|
63
|
+
[Symbol.dispose](): void;
|
|
64
|
+
static string(): HSchema;
|
|
65
|
+
static number(): HSchema;
|
|
66
|
+
static boolean(): HSchema;
|
|
67
|
+
static any(): HSchema;
|
|
68
|
+
static null_type(): HSchema;
|
|
69
|
+
static literal(val: any): HSchema;
|
|
70
|
+
static object(): HSchema;
|
|
71
|
+
static array(item: HSchema): HSchema;
|
|
72
|
+
static union(schemas_arr: HSchema[]): HSchema;
|
|
73
|
+
static instance_of(ctor: Function, name: string): HSchema;
|
|
74
|
+
optional(): HSchema;
|
|
75
|
+
coerce(): HSchema;
|
|
76
|
+
min_length(n: number): HSchema;
|
|
77
|
+
max_length(n: number): HSchema;
|
|
78
|
+
uuid(): HSchema;
|
|
79
|
+
email(): HSchema;
|
|
80
|
+
regex(pattern: string): HSchema;
|
|
81
|
+
phone(): HSchema;
|
|
82
|
+
domain(require_protocol: boolean): HSchema;
|
|
83
|
+
min(n: number): HSchema;
|
|
84
|
+
max(n: number): HSchema;
|
|
85
|
+
add_prop(key: string, schema: HSchema): void;
|
|
86
|
+
validate(value: any): any;
|
|
87
|
+
get_json_schema(): any;
|
|
61
88
|
}
|
|
89
|
+
|
|
90
|
+
type SchemaPrimitive = "string" | "number" | "boolean" | "any";
|
|
62
91
|
type Simplify<T> = T extends any ? {
|
|
63
92
|
[K in keyof T]: T[K];
|
|
64
93
|
} : never;
|
|
@@ -87,7 +116,12 @@ type InferSchema<S> = S extends BaseSchema<any, infer O> ? O : S extends "string
|
|
|
87
116
|
} & {
|
|
88
117
|
[K in keyof S as undefined extends InferSchema<S[K]> ? never : K]: InferSchema<S[K]>;
|
|
89
118
|
} : unknown;
|
|
90
|
-
type SchemaDefinition =
|
|
119
|
+
type SchemaDefinition = {
|
|
120
|
+
[key: string]: SchemaPrimitive | SchemaLike | BaseSchema<any, any>;
|
|
121
|
+
};
|
|
122
|
+
interface SchemaLike {
|
|
123
|
+
[key: string]: SchemaPrimitive | SchemaLike | BaseSchema<any, any>;
|
|
124
|
+
}
|
|
91
125
|
interface Schema<I, O> extends StandardSchemaV1<I, O> {
|
|
92
126
|
optional(): OptionalSchema<I, O | undefined>;
|
|
93
127
|
enum<V extends O & (string | number | boolean), Values extends readonly [V, ...V[]]>(values: Values): UnionSchema<I, Values[number]>;
|
|
@@ -95,208 +129,183 @@ interface Schema<I, O> extends StandardSchemaV1<I, O> {
|
|
|
95
129
|
instanceOf<C extends new (...args: any[]) => any>(constructor: C): InstanceOfSchema<I, InstanceType<C>>;
|
|
96
130
|
jsonSchema: any;
|
|
97
131
|
readonly inferred: O;
|
|
98
|
-
schema: Schema<I, O>;
|
|
99
132
|
}
|
|
100
133
|
declare abstract class BaseSchema<I, O> implements Schema<I, O> {
|
|
101
|
-
|
|
102
|
-
|
|
134
|
+
protected wasmSchema: HSchema;
|
|
135
|
+
constructor(wasmSchema: HSchema);
|
|
136
|
+
get "~standard"(): StandardSchemaV1.Props<I, O>;
|
|
137
|
+
get jsonSchema(): any;
|
|
103
138
|
get inferred(): O;
|
|
104
|
-
schema: Schema<I, O>;
|
|
105
|
-
protected _coerce: boolean;
|
|
106
139
|
coerce(): this;
|
|
107
140
|
optional(): OptionalSchema<I, O | undefined>;
|
|
108
|
-
enum<V extends O & (string | number | boolean), Values extends readonly [V, ...V[]]>(values: Values): UnionSchema<I, Values[number]>;
|
|
109
141
|
array(): ArraySchema<I, O[]>;
|
|
142
|
+
enum<V extends O & (string | number | boolean), Values extends readonly [V, ...V[]]>(values: Values): UnionSchema<I, Values[number]>;
|
|
110
143
|
instanceOf<C extends new (...args: any[]) => any>(constructor: C): InstanceOfSchema<I, InstanceType<C>>;
|
|
111
144
|
}
|
|
112
145
|
declare class StringSchemaType extends BaseSchema<unknown, string> {
|
|
113
|
-
|
|
114
|
-
private _validateUUID;
|
|
115
|
-
private _validateRegex;
|
|
116
|
-
private _validateEmail;
|
|
117
|
-
private _validatePhone;
|
|
118
|
-
private _validateDomain;
|
|
119
|
-
private _requireHttpOrHttps;
|
|
120
|
-
private _minLength?;
|
|
121
|
-
private _maxLength?;
|
|
122
|
-
constructor();
|
|
123
|
-
primitive(): SchemaPrimitive;
|
|
146
|
+
constructor(s?: HSchema);
|
|
124
147
|
minLength(n: number): StringSchemaType;
|
|
125
148
|
maxLength(n: number): StringSchemaType;
|
|
126
149
|
uuid(): StringSchemaType;
|
|
127
|
-
regex(regex: RegExp): StringSchemaType;
|
|
128
150
|
email(): StringSchemaType;
|
|
151
|
+
regex(r: RegExp): StringSchemaType;
|
|
129
152
|
phone(): StringSchemaType;
|
|
130
|
-
domain(
|
|
131
|
-
readonly "~standard": StandardSchemaV1.Props<unknown, string>;
|
|
132
|
-
private _isValidUUID;
|
|
133
|
-
private _isValidRegex;
|
|
134
|
-
private _isValidEmail;
|
|
135
|
-
private _isValidPhone;
|
|
136
|
-
private _isValidDomain;
|
|
153
|
+
domain(r?: boolean): StringSchemaType;
|
|
137
154
|
}
|
|
138
155
|
declare class NumberSchemaType extends BaseSchema<unknown, number> {
|
|
139
|
-
|
|
140
|
-
private _min?;
|
|
141
|
-
private _max?;
|
|
142
|
-
constructor();
|
|
143
|
-
primitive(): SchemaPrimitive;
|
|
156
|
+
constructor(s?: HSchema);
|
|
144
157
|
min(n: number): NumberSchemaType;
|
|
145
158
|
max(n: number): NumberSchemaType;
|
|
146
|
-
readonly "~standard": StandardSchemaV1.Props<unknown, number>;
|
|
147
159
|
}
|
|
148
160
|
declare class BooleanSchemaType extends BaseSchema<unknown, boolean> {
|
|
149
|
-
readonly type: SchemaPrimitive;
|
|
150
161
|
constructor();
|
|
151
|
-
|
|
152
|
-
|
|
162
|
+
}
|
|
163
|
+
declare class NullSchemaType extends BaseSchema<unknown, null> {
|
|
164
|
+
constructor();
|
|
153
165
|
}
|
|
154
166
|
declare class AnySchemaType extends BaseSchema<unknown, any> {
|
|
155
|
-
|
|
156
|
-
readonly "~standard": StandardSchemaV1.Props<unknown, any>;
|
|
167
|
+
constructor();
|
|
157
168
|
}
|
|
158
169
|
declare class LiteralSchema<I, T extends string | number | boolean> extends BaseSchema<I, T> {
|
|
159
|
-
|
|
170
|
+
readonly value: T;
|
|
160
171
|
constructor(value: T);
|
|
161
|
-
readonly "~standard": StandardSchemaV1.Props<I, T>;
|
|
162
172
|
}
|
|
163
173
|
declare class OptionalSchema<I, O> extends BaseSchema<I, O | undefined> {
|
|
164
|
-
|
|
165
|
-
constructor(
|
|
166
|
-
readonly "~standard": StandardSchemaV1.Props<I, O | undefined>;
|
|
167
|
-
}
|
|
168
|
-
declare class NullSchemaType extends BaseSchema<unknown, null> {
|
|
169
|
-
readonly type = "null";
|
|
170
|
-
constructor();
|
|
171
|
-
readonly "~standard": StandardSchemaV1.Props<unknown, null>;
|
|
172
|
-
}
|
|
173
|
-
declare class UnionSchema<I, O> extends BaseSchema<I, O> {
|
|
174
|
-
private readonly schemas;
|
|
175
|
-
constructor(...schemas: Schema<I, any>[]);
|
|
176
|
-
readonly "~standard": StandardSchemaV1.Props<I, O>;
|
|
174
|
+
readonly innerSchema: BaseSchema<any, any>;
|
|
175
|
+
constructor(ws: HSchema, originalSchema?: BaseSchema<any, any>);
|
|
177
176
|
}
|
|
178
177
|
declare class ArraySchema<I, O extends any[]> extends BaseSchema<I, O> {
|
|
179
|
-
|
|
180
|
-
constructor(
|
|
181
|
-
readonly "~standard": StandardSchemaV1.Props<I, O>;
|
|
182
|
-
}
|
|
183
|
-
declare class InstanceOfSchema<I, O> extends BaseSchema<I, O> {
|
|
184
|
-
private readonly innerSchema;
|
|
185
|
-
private readonly classConstructor;
|
|
186
|
-
constructor(schema: Schema<I, any>, classConstructor: new (...args: any[]) => any);
|
|
187
|
-
readonly "~standard": StandardSchemaV1.Props<I, O>;
|
|
178
|
+
readonly innerSchema: BaseSchema<any, any>;
|
|
179
|
+
constructor(ws: HSchema, originalSchema?: BaseSchema<any, any>);
|
|
188
180
|
}
|
|
189
181
|
declare class ObjectSchemaType<T extends Record<string, unknown>> extends BaseSchema<unknown, T> {
|
|
190
182
|
readonly definition: SchemaDefinition;
|
|
191
183
|
constructor(definition: SchemaDefinition);
|
|
192
|
-
|
|
184
|
+
}
|
|
185
|
+
declare class UnionSchema<I, O> extends BaseSchema<I, O> {
|
|
186
|
+
readonly schemas: BaseSchema<any, any>[];
|
|
187
|
+
constructor(schemas: BaseSchema<any, any>[]);
|
|
188
|
+
}
|
|
189
|
+
declare class InstanceOfSchema<I, O> extends BaseSchema<I, O> {
|
|
190
|
+
readonly classConstructor: new (...args: any[]) => any;
|
|
191
|
+
constructor(_baseWasm: HSchema, constructor: new (...args: any[]) => any);
|
|
193
192
|
}
|
|
194
193
|
type AnySchema = SchemaPrimitive | BaseSchema<any, any> | SchemaDefinition;
|
|
195
|
-
declare function toStandard<T>(schema: AnySchema): Schema<unknown, T>;
|
|
196
194
|
/**
|
|
197
|
-
*
|
|
198
|
-
* @returns {typeof h}
|
|
195
|
+
* Collection of helper functions for creating schema types.
|
|
196
|
+
* @returns {typeof h} Schema type helpers
|
|
199
197
|
*/
|
|
200
198
|
declare const h: {
|
|
201
199
|
/**
|
|
202
|
-
* Create string schema type
|
|
200
|
+
* Create a string schema type.
|
|
203
201
|
* @returns {StringSchemaType} String schema type
|
|
204
202
|
*/
|
|
205
203
|
string: () => StringSchemaType;
|
|
206
204
|
/**
|
|
207
|
-
* Create number schema type
|
|
205
|
+
* Create a number schema type.
|
|
208
206
|
* @returns {NumberSchemaType} Number schema type
|
|
209
207
|
*/
|
|
210
208
|
number: () => NumberSchemaType;
|
|
211
209
|
/**
|
|
212
|
-
* Create boolean schema type
|
|
210
|
+
* Create a boolean schema type.
|
|
213
211
|
* @returns {BooleanSchemaType} Boolean schema type
|
|
214
212
|
*/
|
|
215
213
|
boolean: () => BooleanSchemaType;
|
|
216
214
|
/**
|
|
217
|
-
* Create null schema type
|
|
215
|
+
* Create a null schema type.
|
|
218
216
|
* @returns {NullSchemaType} Null schema type
|
|
219
217
|
*/
|
|
220
218
|
null: () => NullSchemaType;
|
|
221
219
|
/**
|
|
222
|
-
* Create any schema type
|
|
220
|
+
* Create an "any" schema type.
|
|
223
221
|
* @returns {AnySchemaType} Any schema type
|
|
224
222
|
*/
|
|
225
223
|
any: () => AnySchemaType;
|
|
226
224
|
/**
|
|
227
|
-
* Create literal schema type
|
|
228
|
-
* @
|
|
229
|
-
* @
|
|
225
|
+
* Create a literal schema type.
|
|
226
|
+
* @template T
|
|
227
|
+
* @param {T} val - Literal value
|
|
228
|
+
* @returns {LiteralSchema<T>} Literal schema type
|
|
230
229
|
*/
|
|
231
|
-
literal: <T extends string | number | boolean>(
|
|
230
|
+
literal: <T extends string | number | boolean>(val: T) => LiteralSchema<unknown, T>;
|
|
232
231
|
/**
|
|
233
|
-
* Create object schema type
|
|
234
|
-
* @
|
|
232
|
+
* Create an object schema type.
|
|
233
|
+
* @template S
|
|
234
|
+
* @param {S} [schemaDef] - Optional schema definition
|
|
235
235
|
* @returns {ObjectSchemaType<InferObject<S>>} Object schema type
|
|
236
236
|
*/
|
|
237
237
|
object: <S extends SchemaDefinition>(schemaDef?: S) => ObjectSchemaType<InferObject<S>>;
|
|
238
238
|
/**
|
|
239
|
-
* Create array schema type
|
|
240
|
-
* @
|
|
241
|
-
* @
|
|
239
|
+
* Create an array schema type.
|
|
240
|
+
* @template S
|
|
241
|
+
* @param {S} schema - Schema definition for array items
|
|
242
|
+
* @returns {ArraySchema<unknown, InferSchema<S>>} Array schema type
|
|
242
243
|
*/
|
|
243
|
-
array: <S extends AnySchema>(schema: S) => ArraySchema<
|
|
244
|
+
array: <S extends AnySchema>(schema: S) => ArraySchema<any, any[]>;
|
|
244
245
|
/**
|
|
245
|
-
* Create
|
|
246
|
-
* @
|
|
247
|
-
* @
|
|
246
|
+
* Create an optional schema type.
|
|
247
|
+
* @template S
|
|
248
|
+
* @param {S} schema - Schema to mark as optional
|
|
249
|
+
* @returns {OptionalSchema<unknown, InferSchema<S>>} Optional schema type
|
|
248
250
|
*/
|
|
249
|
-
|
|
251
|
+
optional: <S extends AnySchema>(schema: S) => OptionalSchema<any, any>;
|
|
250
252
|
/**
|
|
251
|
-
* Create
|
|
252
|
-
* @
|
|
253
|
-
* @
|
|
253
|
+
* Create a union schema from multiple schemas.
|
|
254
|
+
* @template S
|
|
255
|
+
* @param {...S} schemas - Schemas to combine
|
|
256
|
+
* @returns {UnionSchema<unknown, InferSchema<S[number]>>} Union schema type
|
|
254
257
|
*/
|
|
255
|
-
|
|
258
|
+
options: <S extends AnySchema[]>(...schemas: S) => UnionSchema<unknown, InferSchema<S[number]>>;
|
|
256
259
|
/**
|
|
257
|
-
* Create
|
|
258
|
-
* @
|
|
259
|
-
* @
|
|
260
|
+
* Create an enum schema from a list of primitive values.
|
|
261
|
+
* @template T
|
|
262
|
+
* @template Values
|
|
263
|
+
* @param {Values} values - Array of allowed literal values
|
|
264
|
+
* @returns {UnionSchema<unknown, Values[number]>} Enum schema type
|
|
265
|
+
* @throws {Error} If the array is empty
|
|
260
266
|
*/
|
|
261
|
-
|
|
267
|
+
enum: <T extends string | number | boolean, Values extends readonly [T, ...T[]]>(values: Values) => UnionSchema<unknown, Values[number]>;
|
|
262
268
|
/**
|
|
263
|
-
* Create
|
|
264
|
-
* @
|
|
265
|
-
* @
|
|
269
|
+
* Create a schema that validates instances of a specific class.
|
|
270
|
+
* @template C
|
|
271
|
+
* @param {C} constructor - Constructor function or class
|
|
272
|
+
* @returns {InstanceOfSchema<unknown, InstanceType<C>>} InstanceOf schema type
|
|
266
273
|
*/
|
|
267
274
|
instanceOf: <C extends new (...args: any[]) => any>(constructor: C) => InstanceOfSchema<unknown, InstanceType<C>>;
|
|
268
275
|
/**
|
|
269
|
-
* Create UUID schema type
|
|
276
|
+
* Create a UUID schema type.
|
|
270
277
|
* @returns {StringSchemaType} UUID schema type
|
|
271
278
|
*/
|
|
272
279
|
uuid: () => StringSchemaType;
|
|
273
280
|
/**
|
|
274
|
-
* Create
|
|
275
|
-
* @param {RegExp} regex - Regex
|
|
276
|
-
* @returns {StringSchemaType} Regex schema type
|
|
277
|
-
*/
|
|
278
|
-
regex: (regex: RegExp) => StringSchemaType;
|
|
279
|
-
/**
|
|
280
|
-
* Create email schema type
|
|
281
|
+
* Create an email schema type.
|
|
281
282
|
* @returns {StringSchemaType} Email schema type
|
|
282
283
|
*/
|
|
283
284
|
email: () => StringSchemaType;
|
|
284
285
|
/**
|
|
285
|
-
* Create
|
|
286
|
+
* Create a regex-validated string schema type.
|
|
287
|
+
* @param {RegExp} r - Regular expression
|
|
288
|
+
* @returns {StringSchemaType} Regex schema type
|
|
289
|
+
*/
|
|
290
|
+
regex: (r: RegExp) => StringSchemaType;
|
|
291
|
+
/**
|
|
292
|
+
* Create a phone schema type.
|
|
286
293
|
* @returns {StringSchemaType} Phone schema type
|
|
287
294
|
*/
|
|
288
295
|
phone: () => StringSchemaType;
|
|
289
|
-
/**
|
|
290
|
-
*
|
|
296
|
+
/**
|
|
297
|
+
* Create a domain schema type.
|
|
298
|
+
* @param {boolean} [req=true] - Whether domain must include http/https
|
|
291
299
|
* @returns {StringSchemaType} Domain schema type
|
|
292
300
|
*/
|
|
293
|
-
domain: (
|
|
301
|
+
domain: (req?: boolean) => StringSchemaType;
|
|
294
302
|
/**
|
|
295
|
-
* Convert schema
|
|
296
|
-
* @
|
|
297
|
-
* @
|
|
303
|
+
* Convert any schema into a standard schema.
|
|
304
|
+
* @template T
|
|
305
|
+
* @param {AnySchema} schema - Schema to convert
|
|
306
|
+
* @returns {Schema<unknown, T>} Standardized schema
|
|
298
307
|
*/
|
|
299
|
-
toStandard:
|
|
308
|
+
toStandard: <T>(schema: AnySchema) => Schema<unknown, T>;
|
|
300
309
|
};
|
|
301
310
|
|
|
302
311
|
export { type AnySchema, AnySchemaType, ArraySchema, BaseSchema, BooleanSchemaType, InstanceOfSchema, LiteralSchema, NullSchemaType, NumberSchemaType, ObjectSchemaType, OptionalSchema, StringSchemaType, UnionSchema, h };
|
package/dist/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var X=Object.create;var T=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var Z=Object.getOwnPropertyNames;var ee=Object.getPrototypeOf,ne=Object.prototype.hasOwnProperty;var te=(e,n)=>()=>(e&&(n=e(e=0)),n);var re=(e,n)=>()=>(n||e((n={exports:{}}).exports,n),n.exports),v=(e,n)=>{for(var t in n)T(e,t,{get:n[t],enumerable:!0})},P=(e,n,t,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let a of Z(n))!ne.call(e,a)&&a!==t&&T(e,a,{get:()=>n[a],enumerable:!(r=Y(n,a))||r.enumerable});return e};var ae=(e,n,t)=>(t=e!=null?X(ee(e)):{},P(n||!e||!e.__esModule?T(t,"default",{value:e,enumerable:!0}):t,e)),$=e=>P(T({},"__esModule",{value:!0}),e);var H={};v(H,{is_instance_of:()=>se});function se(e,n){return e instanceof n}var U=te(()=>{"use strict"});var Q=re((o,G)=>{"use strict";var D={};D["./snippets/validations-f447b611bd96feb0/inline0.js"]=(U(),$(H));D.__wbindgen_placeholder__=G.exports;function K(e){return e==null}function M(e){let n=typeof e;if(n=="number"||n=="boolean"||e==null)return`${e}`;if(n=="string")return`"${e}"`;if(n=="symbol"){let a=e.description;return a==null?"Symbol":`Symbol(${a})`}if(n=="function"){let a=e.name;return typeof a=="string"&&a.length>0?`Function(${a})`:"Function"}if(Array.isArray(e)){let a=e.length,c="[";a>0&&(c+=M(e[0]));for(let i=1;i<a;i++)c+=", "+M(e[i]);return c+="]",c}let t=/\[object ([^\]]+)\]/.exec(toString.call(e)),r;if(t&&t.length>1)r=t[1];else return toString.call(e);if(r=="Object")try{return"Object("+JSON.stringify(e)+")"}catch{return"Object"}return e instanceof Error?`${e.name}: ${e.message}
|
|
2
|
+
${e.stack}`:r}var d=0,k=null;function j(){return(k===null||k.byteLength===0)&&(k=new Uint8Array(s.memory.buffer)),k}var g=new TextEncoder;"encodeInto"in g||(g.encodeInto=function(e,n){let t=g.encode(e);return n.set(t),{read:e.length,written:t.length}});function y(e,n,t){if(t===void 0){let h=g.encode(e),p=n(h.length,1)>>>0;return j().subarray(p,p+h.length).set(h),d=h.length,p}let r=e.length,a=n(r,1)>>>0,c=j(),i=0;for(;i<r;i++){let h=e.charCodeAt(i);if(h>127)break;c[a+i]=h}if(i!==r){i!==0&&(e=e.slice(i)),a=t(a,r,r=i+e.length*3,1)>>>0;let h=j().subarray(a+i,a+r),p=g.encodeInto(e,h);i+=p.written,a=t(a,r,i,1)>>>0}return d=i,a}var f=null;function l(){return(f===null||f.buffer.detached===!0||f.buffer.detached===void 0&&f.buffer!==s.memory.buffer)&&(f=new DataView(s.memory.buffer)),f}var q=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});q.decode();function oe(e,n){return q.decode(j().subarray(e,e+n))}function N(e,n){return e=e>>>0,oe(e,n)}function z(e){let n=s.__externref_table_alloc();return s.__wbindgen_externrefs.set(n,e),n}function J(e,n){try{return e.apply(this,n)}catch(t){let r=z(t);s.__wbindgen_exn_store(r)}}function L(e,n){if(!(e instanceof n))throw new Error(`expected instance of ${n.name}`)}function ce(e,n){let t=n(e.length*4,4)>>>0;for(let r=0;r<e.length;r++){let a=z(e[r]);l().setUint32(t+4*r,a,!0)}return d=e.length,t}var W=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>s.__wbg_hschema_free(e>>>0,1)),b=class e{static __wrap(n){n=n>>>0;let t=Object.create(e.prototype);return t.__wbg_ptr=n,W.register(t,t.__wbg_ptr,t),t}static __unwrap(n){return n instanceof e?n.__destroy_into_raw():0}__destroy_into_raw(){let n=this.__wbg_ptr;return this.__wbg_ptr=0,W.unregister(this),n}free(){let n=this.__destroy_into_raw();s.__wbg_hschema_free(n,0)}static string(){let n=s.hschema_string();return e.__wrap(n)}static number(){let n=s.hschema_number();return e.__wrap(n)}static boolean(){let n=s.hschema_boolean();return e.__wrap(n)}static any(){let n=s.hschema_any();return e.__wrap(n)}static null_type(){let n=s.hschema_null_type();return e.__wrap(n)}static literal(n){let t=s.hschema_literal(n);return e.__wrap(t)}static object(){let n=s.hschema_object();return e.__wrap(n)}static array(n){L(n,e);let t=s.hschema_array(n.__wbg_ptr);return e.__wrap(t)}static union(n){let t=ce(n,s.__wbindgen_malloc),r=d,a=s.hschema_union(t,r);return e.__wrap(a)}static instance_of(n,t){let r=y(t,s.__wbindgen_malloc,s.__wbindgen_realloc),a=d,c=s.hschema_instance_of(n,r,a);return e.__wrap(c)}optional(){let n=s.hschema_optional(this.__wbg_ptr);return e.__wrap(n)}coerce(){let n=s.hschema_coerce(this.__wbg_ptr);return e.__wrap(n)}min_length(n){let t=s.hschema_min_length(this.__wbg_ptr,n);return e.__wrap(t)}max_length(n){let t=s.hschema_max_length(this.__wbg_ptr,n);return e.__wrap(t)}uuid(){let n=s.hschema_uuid(this.__wbg_ptr);return e.__wrap(n)}email(){let n=s.hschema_email(this.__wbg_ptr);return e.__wrap(n)}regex(n){let t=y(n,s.__wbindgen_malloc,s.__wbindgen_realloc),r=d,a=s.hschema_regex(this.__wbg_ptr,t,r);return e.__wrap(a)}phone(){let n=s.hschema_phone(this.__wbg_ptr);return e.__wrap(n)}domain(n){let t=s.hschema_domain(this.__wbg_ptr,n);return e.__wrap(t)}min(n){let t=s.hschema_min(this.__wbg_ptr,n);return e.__wrap(t)}max(n){let t=s.hschema_max(this.__wbg_ptr,n);return e.__wrap(t)}add_prop(n,t){let r=y(n,s.__wbindgen_malloc,s.__wbindgen_realloc),a=d;L(t,e),s.hschema_add_prop(this.__wbg_ptr,r,a,t.__wbg_ptr)}validate(n){return s.hschema_validate(this.__wbg_ptr,n)}get_json_schema(){return s.hschema_get_json_schema(this.__wbg_ptr)}};Symbol.dispose&&(b.prototype[Symbol.dispose]=b.prototype.free);o.HSchema=b;o.__wbg___wbindgen_boolean_get_6d5a1ee65bab5f68=function(e){let n=e,t=typeof n=="boolean"?n:void 0;return K(t)?16777215:t?1:0};o.__wbg___wbindgen_debug_string_df47ffb5e35e6763=function(e,n){let t=M(n),r=y(t,s.__wbindgen_malloc,s.__wbindgen_realloc),a=d;l().setInt32(e+4*1,a,!0),l().setInt32(e+4*0,r,!0)};o.__wbg___wbindgen_is_falsy_46b8d2f2aba49112=function(e){return!e};o.__wbg___wbindgen_is_null_5e69f72e906cc57c=function(e){return e===null};o.__wbg___wbindgen_is_object_c818261d21f283a4=function(e){let n=e;return typeof n=="object"&&n!==null};o.__wbg___wbindgen_is_string_fbb76cb2940daafd=function(e){return typeof e=="string"};o.__wbg___wbindgen_is_undefined_2d472862bd29a478=function(e){return e===void 0};o.__wbg___wbindgen_jsval_eq_6b13ab83478b1c50=function(e,n){return e===n};o.__wbg___wbindgen_number_get_a20bf9b85341449d=function(e,n){let t=n,r=typeof t=="number"?t:void 0;l().setFloat64(e+8*1,K(r)?0:r,!0),l().setInt32(e+4*0,!K(r),!0)};o.__wbg___wbindgen_string_get_e4f06c90489ad01b=function(e,n){let t=n,r=typeof t=="string"?t:void 0;var a=K(r)?0:y(r,s.__wbindgen_malloc,s.__wbindgen_realloc),c=d;l().setInt32(e+4*1,c,!0),l().setInt32(e+4*0,a,!0)};o.__wbg___wbindgen_throw_b855445ff6a94295=function(e,n){throw new Error(N(e,n))};o.__wbg_from_a4ad7cbddd0d7135=function(e){return Array.from(e)};o.__wbg_get_7bed016f185add81=function(e,n){return e[n>>>0]};o.__wbg_get_efcb449f58ec27c2=function(){return J(function(e,n){return Reflect.get(e,n)},arguments)};o.__wbg_hschema_unwrap=function(e){return b.__unwrap(e)};o.__wbg_isArray_96e0af9891d0945d=function(e){return Array.isArray(e)};o.__wbg_length_cdd215e10d9dd507=function(e){return e.length};o.__wbg_new_1acc0b6eea89d040=function(){return new Object};o.__wbg_new_e17d9f43105b08be=function(){return new Array};o.__wbg_push_df81a39d04db858c=function(e,n){return e.push(n)};o.__wbg_set_3fda3bac07393de4=function(e,n,t){e[n]=t};o.__wbg_set_c213c871859d6500=function(e,n,t){e[n>>>0]=t};o.__wbg_set_c2abbebe8b9ebee1=function(){return J(function(e,n,t){return Reflect.set(e,n,t)},arguments)};o.__wbindgen_cast_2241b6af4c4b2941=function(e,n){return N(e,n)};o.__wbindgen_cast_d6cd19b81560fd6e=function(e){return e};o.__wbindgen_init_externref_table=function(){let e=s.__wbindgen_externrefs,n=e.grow(4);e.set(0,void 0),e.set(n+0,void 0),e.set(n+1,null),e.set(n+2,!0),e.set(n+3,!1)};var ie=`${__dirname}/validations_bg.wasm`,_e=require("fs").readFileSync(ie),ue=new WebAssembly.Module(_e),s=o.__wasm=new WebAssembly.Instance(ue,D).exports;s.__wbindgen_start()});var me={};v(me,{AnySchemaType:()=>O,ArraySchema:()=>C,BaseSchema:()=>u,BooleanSchemaType:()=>I,InstanceOfSchema:()=>E,LiteralSchema:()=>B,NullSchemaType:()=>A,NumberSchemaType:()=>x,ObjectSchemaType:()=>w,OptionalSchema:()=>F,StringSchemaType:()=>S,UnionSchema:()=>R,h:()=>m});module.exports=$(me);var _=ae(Q()),u=class{wasmSchema;constructor(n){this.wasmSchema=n}get"~standard"(){return{version:1,vendor:"h-schema-rs",validate:n=>this.wasmSchema.validate(n)}}get jsonSchema(){return this.wasmSchema.get_json_schema()}get inferred(){return null}coerce(){return this.wasmSchema=this.wasmSchema.coerce(),this}optional(){return new F(this.wasmSchema.optional(),this)}array(){return new C(_.HSchema.array(this.wasmSchema),this)}enum(n){let t=n.map(r=>m.literal(r));return m.options(...t)}instanceOf(n){return new E(this.wasmSchema,n)}},S=class e extends u{constructor(n=_.HSchema.string()){super(n)}minLength(n){return new e(this.wasmSchema.min_length(n))}maxLength(n){return new e(this.wasmSchema.max_length(n))}uuid(){return new e(this.wasmSchema.uuid())}email(){return new e(this.wasmSchema.email())}regex(n){return new e(this.wasmSchema.regex(n.source))}phone(){return new e(this.wasmSchema.phone())}domain(n=!0){return new e(this.wasmSchema.domain(n))}},x=class e extends u{constructor(n=_.HSchema.number()){super(n)}min(n){return new e(this.wasmSchema.min(n))}max(n){return new e(this.wasmSchema.max(n))}},I=class extends u{constructor(){super(_.HSchema.boolean())}},A=class extends u{constructor(){super(_.HSchema.null_type())}},O=class extends u{constructor(){super(_.HSchema.any())}},B=class extends u{value;constructor(n){super(_.HSchema.literal(n)),this.value=n}},F=class extends u{innerSchema;constructor(n,t){super(n),this.innerSchema=t}},C=class extends u{innerSchema;constructor(n,t){super(n),this.innerSchema=t}},w=class extends u{definition;constructor(n){let t=_.HSchema.object();for(let r in n){let a=n[r],c;a instanceof u?c=a.wasmSchema:typeof a=="string"?a==="string"?c=_.HSchema.string():a==="number"?c=_.HSchema.number():a==="boolean"?c=_.HSchema.boolean():c=_.HSchema.any():c=_.HSchema.any(),t.add_prop(r,c)}super(t),this.definition=n}},R=class extends u{schemas;constructor(n){let t=n.map(r=>r.wasmSchema);super(_.HSchema.union(t)),this.schemas=n}},E=class extends u{classConstructor;constructor(n,t){super(_.HSchema.instance_of(t,t.name)),this.classConstructor=t}};function V(e){return e instanceof u?e:e==="string"?new S:e==="number"?new x:e==="boolean"?new I:typeof e=="object"&&e!==null?new w(e):new O}var m={string:()=>new S,number:()=>new x,boolean:()=>new I,null:()=>new A,any:()=>new O,literal:e=>new B(e),object:e=>new w(e||{}),array:e=>V(e).array(),optional:e=>V(e).optional(),options:(...e)=>{let n=e.map(t=>V(t));return new R(n)},enum:e=>{if(!e||e.length===0)throw new Error("h.enum() requires non-empty array");let n=e.map(t=>m.literal(t));return m.options(...n)},instanceOf:e=>new w({}).instanceOf(e),uuid:()=>m.string().uuid(),email:()=>m.string().email(),regex:e=>m.string().regex(e),phone:()=>m.string().phone(),domain:(e=!0)=>m.string().domain(e),toStandard:e=>V(e)};0&&(module.exports={AnySchemaType,ArraySchema,BaseSchema,BooleanSchemaType,InstanceOfSchema,LiteralSchema,NullSchemaType,NumberSchemaType,ObjectSchemaType,OptionalSchema,StringSchemaType,UnionSchema,h});
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hedystia/validations",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.1",
|
|
4
4
|
"devDependencies": {
|
|
5
5
|
"@standard-schema/spec": "^1.0.0",
|
|
6
6
|
"@types/bun": "latest",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"private": false,
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"scripts": {
|
|
20
|
-
"build": "tsup",
|
|
21
|
-
"dev": "bun --watch --no-clear-screen run
|
|
20
|
+
"build": "cargo clean && wasm-pack build --target nodejs && tsup && cp pkg/validations_bg.wasm dist/",
|
|
21
|
+
"dev": "bun --watch --no-clear-screen run index.ts"
|
|
22
22
|
},
|
|
23
23
|
"repository": {
|
|
24
24
|
"type": "git",
|