@hedystia/validations 1.7.2 → 1.7.4
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 +114 -123
- package/dist/index.js +1 -2
- package/package.json +3 -3
- package/readme.md +165 -165
- package/dist/validations_bg.wasm +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -55,39 +55,10 @@ declare namespace StandardSchemaV1 {
|
|
|
55
55
|
export { };
|
|
56
56
|
}
|
|
57
57
|
|
|
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;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
58
|
type SchemaPrimitive = "string" | "number" | "boolean" | "any";
|
|
59
|
+
interface SchemaLike {
|
|
60
|
+
[key: string]: SchemaPrimitive | SchemaLike | BaseSchema<any, any>;
|
|
61
|
+
}
|
|
91
62
|
type Simplify<T> = T extends any ? {
|
|
92
63
|
[K in keyof T]: T[K];
|
|
93
64
|
} : never;
|
|
@@ -116,12 +87,7 @@ type InferSchema<S> = S extends BaseSchema<any, infer O> ? O : S extends "string
|
|
|
116
87
|
} & {
|
|
117
88
|
[K in keyof S as undefined extends InferSchema<S[K]> ? never : K]: InferSchema<S[K]>;
|
|
118
89
|
} : unknown;
|
|
119
|
-
type SchemaDefinition =
|
|
120
|
-
[key: string]: SchemaPrimitive | SchemaLike | BaseSchema<any, any>;
|
|
121
|
-
};
|
|
122
|
-
interface SchemaLike {
|
|
123
|
-
[key: string]: SchemaPrimitive | SchemaLike | BaseSchema<any, any>;
|
|
124
|
-
}
|
|
90
|
+
type SchemaDefinition = SchemaLike;
|
|
125
91
|
interface Schema<I, O> extends StandardSchemaV1<I, O> {
|
|
126
92
|
optional(): OptionalSchema<I, O | undefined>;
|
|
127
93
|
enum<V extends O & (string | number | boolean), Values extends readonly [V, ...V[]]>(values: Values): UnionSchema<I, Values[number]>;
|
|
@@ -129,183 +95,208 @@ interface Schema<I, O> extends StandardSchemaV1<I, O> {
|
|
|
129
95
|
instanceOf<C extends new (...args: any[]) => any>(constructor: C): InstanceOfSchema<I, InstanceType<C>>;
|
|
130
96
|
jsonSchema: any;
|
|
131
97
|
readonly inferred: O;
|
|
98
|
+
schema: Schema<I, O>;
|
|
132
99
|
}
|
|
133
100
|
declare abstract class BaseSchema<I, O> implements Schema<I, O> {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
get "~standard"(): StandardSchemaV1.Props<I, O>;
|
|
137
|
-
get jsonSchema(): any;
|
|
101
|
+
abstract readonly "~standard": StandardSchemaV1.Props<I, O>;
|
|
102
|
+
jsonSchema: any;
|
|
138
103
|
get inferred(): O;
|
|
104
|
+
schema: Schema<I, O>;
|
|
105
|
+
protected _coerce: boolean;
|
|
139
106
|
coerce(): this;
|
|
140
107
|
optional(): OptionalSchema<I, O | undefined>;
|
|
141
|
-
array(): ArraySchema<I, O[]>;
|
|
142
108
|
enum<V extends O & (string | number | boolean), Values extends readonly [V, ...V[]]>(values: Values): UnionSchema<I, Values[number]>;
|
|
109
|
+
array(): ArraySchema<I, O[]>;
|
|
143
110
|
instanceOf<C extends new (...args: any[]) => any>(constructor: C): InstanceOfSchema<I, InstanceType<C>>;
|
|
144
111
|
}
|
|
145
112
|
declare class StringSchemaType extends BaseSchema<unknown, string> {
|
|
146
|
-
|
|
113
|
+
readonly type: SchemaPrimitive;
|
|
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;
|
|
147
124
|
minLength(n: number): StringSchemaType;
|
|
148
125
|
maxLength(n: number): StringSchemaType;
|
|
149
126
|
uuid(): StringSchemaType;
|
|
127
|
+
regex(regex: RegExp): StringSchemaType;
|
|
150
128
|
email(): StringSchemaType;
|
|
151
|
-
regex(r: RegExp): StringSchemaType;
|
|
152
129
|
phone(): StringSchemaType;
|
|
153
|
-
domain(
|
|
130
|
+
domain(requireHttpOrHttps?: boolean): StringSchemaType;
|
|
131
|
+
readonly "~standard": StandardSchemaV1.Props<unknown, string>;
|
|
132
|
+
private _isValidUUID;
|
|
133
|
+
private _isValidRegex;
|
|
134
|
+
private _isValidEmail;
|
|
135
|
+
private _isValidPhone;
|
|
136
|
+
private _isValidDomain;
|
|
154
137
|
}
|
|
155
138
|
declare class NumberSchemaType extends BaseSchema<unknown, number> {
|
|
156
|
-
|
|
139
|
+
readonly type: SchemaPrimitive;
|
|
140
|
+
private _min?;
|
|
141
|
+
private _max?;
|
|
142
|
+
constructor();
|
|
143
|
+
primitive(): SchemaPrimitive;
|
|
157
144
|
min(n: number): NumberSchemaType;
|
|
158
145
|
max(n: number): NumberSchemaType;
|
|
146
|
+
readonly "~standard": StandardSchemaV1.Props<unknown, number>;
|
|
159
147
|
}
|
|
160
148
|
declare class BooleanSchemaType extends BaseSchema<unknown, boolean> {
|
|
149
|
+
readonly type: SchemaPrimitive;
|
|
161
150
|
constructor();
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
constructor();
|
|
151
|
+
primitive(): SchemaPrimitive;
|
|
152
|
+
readonly "~standard": StandardSchemaV1.Props<unknown, boolean>;
|
|
165
153
|
}
|
|
166
154
|
declare class AnySchemaType extends BaseSchema<unknown, any> {
|
|
167
|
-
|
|
155
|
+
readonly type: SchemaPrimitive;
|
|
156
|
+
readonly "~standard": StandardSchemaV1.Props<unknown, any>;
|
|
168
157
|
}
|
|
169
158
|
declare class LiteralSchema<I, T extends string | number | boolean> extends BaseSchema<I, T> {
|
|
170
|
-
readonly value
|
|
159
|
+
private readonly value;
|
|
171
160
|
constructor(value: T);
|
|
161
|
+
readonly "~standard": StandardSchemaV1.Props<I, T>;
|
|
172
162
|
}
|
|
173
163
|
declare class OptionalSchema<I, O> extends BaseSchema<I, O | undefined> {
|
|
174
|
-
readonly innerSchema
|
|
175
|
-
constructor(
|
|
164
|
+
private readonly innerSchema;
|
|
165
|
+
constructor(schema: Schema<I, O>);
|
|
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>;
|
|
176
177
|
}
|
|
177
178
|
declare class ArraySchema<I, O extends any[]> extends BaseSchema<I, O> {
|
|
178
|
-
readonly innerSchema
|
|
179
|
-
constructor(
|
|
179
|
+
private readonly innerSchema;
|
|
180
|
+
constructor(schema: Schema<I, O[number]>);
|
|
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>;
|
|
180
188
|
}
|
|
181
189
|
declare class ObjectSchemaType<T extends Record<string, unknown>> extends BaseSchema<unknown, T> {
|
|
182
190
|
readonly definition: SchemaDefinition;
|
|
183
191
|
constructor(definition: SchemaDefinition);
|
|
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);
|
|
192
|
+
readonly "~standard": StandardSchemaV1.Props<unknown, T>;
|
|
192
193
|
}
|
|
193
194
|
type AnySchema = SchemaPrimitive | BaseSchema<any, any> | SchemaDefinition;
|
|
195
|
+
declare function toStandard<T>(schema: AnySchema): Schema<unknown, T>;
|
|
194
196
|
/**
|
|
195
|
-
*
|
|
196
|
-
* @returns {typeof h}
|
|
197
|
+
* Create standard schema types
|
|
198
|
+
* @returns {typeof h} Standard schema types
|
|
197
199
|
*/
|
|
198
200
|
declare const h: {
|
|
199
201
|
/**
|
|
200
|
-
* Create
|
|
202
|
+
* Create string schema type
|
|
201
203
|
* @returns {StringSchemaType} String schema type
|
|
202
204
|
*/
|
|
203
205
|
string: () => StringSchemaType;
|
|
204
206
|
/**
|
|
205
|
-
* Create
|
|
207
|
+
* Create number schema type
|
|
206
208
|
* @returns {NumberSchemaType} Number schema type
|
|
207
209
|
*/
|
|
208
210
|
number: () => NumberSchemaType;
|
|
209
211
|
/**
|
|
210
|
-
* Create
|
|
212
|
+
* Create boolean schema type
|
|
211
213
|
* @returns {BooleanSchemaType} Boolean schema type
|
|
212
214
|
*/
|
|
213
215
|
boolean: () => BooleanSchemaType;
|
|
214
216
|
/**
|
|
215
|
-
* Create
|
|
217
|
+
* Create null schema type
|
|
216
218
|
* @returns {NullSchemaType} Null schema type
|
|
217
219
|
*/
|
|
218
220
|
null: () => NullSchemaType;
|
|
219
221
|
/**
|
|
220
|
-
* Create
|
|
222
|
+
* Create any schema type
|
|
221
223
|
* @returns {AnySchemaType} Any schema type
|
|
222
224
|
*/
|
|
223
225
|
any: () => AnySchemaType;
|
|
224
226
|
/**
|
|
225
|
-
* Create
|
|
226
|
-
* @
|
|
227
|
-
* @
|
|
228
|
-
* @returns {LiteralSchema<T>} Literal schema type
|
|
227
|
+
* Create literal schema type
|
|
228
|
+
* @param {T} value - Literal value
|
|
229
|
+
* @returns {LiteralSchema<unknown, T>} Literal schema type
|
|
229
230
|
*/
|
|
230
|
-
literal: <T extends string | number | boolean>(
|
|
231
|
+
literal: <T extends string | number | boolean>(value: T) => LiteralSchema<unknown, T>;
|
|
231
232
|
/**
|
|
232
|
-
* Create
|
|
233
|
-
* @
|
|
234
|
-
* @param {S} [schemaDef] - Optional schema definition
|
|
233
|
+
* Create object schema type
|
|
234
|
+
* @param {S} [schemaDef] - 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
|
|
240
|
-
* @
|
|
241
|
-
* @
|
|
242
|
-
* @returns {ArraySchema<unknown, InferSchema<S>>} Array schema type
|
|
239
|
+
* Create array schema type
|
|
240
|
+
* @param {S} schema - Schema
|
|
241
|
+
* @returns {ArraySchema<unknown, InferSchema<S>[]>} Array schema type
|
|
243
242
|
*/
|
|
244
|
-
array: <S extends AnySchema>(schema: S) => ArraySchema<
|
|
243
|
+
array: <S extends AnySchema>(schema: S) => ArraySchema<unknown, SchemaType<S>[]>;
|
|
245
244
|
/**
|
|
246
|
-
* Create
|
|
247
|
-
* @
|
|
248
|
-
* @
|
|
249
|
-
* @returns {OptionalSchema<unknown, InferSchema<S>>} Optional schema type
|
|
245
|
+
* Create enum schema type from a list of string, number or boolean values.
|
|
246
|
+
* @param {Values} values - An array of literal values.
|
|
247
|
+
* @returns {UnionSchema<unknown, Values[number]>} A schema that validates against one of the provided literal values.
|
|
250
248
|
*/
|
|
251
|
-
|
|
249
|
+
enum: <T extends string | number | boolean, Values extends readonly [T, ...T[]]>(values: Values) => UnionSchema<unknown, Values[number]>;
|
|
252
250
|
/**
|
|
253
|
-
* Create
|
|
254
|
-
* @
|
|
255
|
-
* @
|
|
256
|
-
* @returns {UnionSchema<unknown, InferSchema<S[number]>>} Union schema type
|
|
251
|
+
* Create optional schema type
|
|
252
|
+
* @param {S} schema - Schema
|
|
253
|
+
* @returns {OptionalSchema<unknown, InferSchema<S> | undefined>} Optional schema type
|
|
257
254
|
*/
|
|
258
|
-
|
|
255
|
+
optional: <S extends AnySchema>(schema: S) => OptionalSchema<unknown, InferSchema<S> | undefined>;
|
|
259
256
|
/**
|
|
260
|
-
* Create
|
|
261
|
-
* @
|
|
262
|
-
* @
|
|
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
|
|
257
|
+
* Create options schema type
|
|
258
|
+
* @param {S} schemas - Schemas
|
|
259
|
+
* @returns {UnionSchema<unknown, InferSchema<S[number]>>} Options schema type
|
|
266
260
|
*/
|
|
267
|
-
|
|
261
|
+
options: <S extends AnySchema[]>(...schemas: S) => UnionSchema<unknown, InferSchema<S[number]>>;
|
|
268
262
|
/**
|
|
269
|
-
* Create
|
|
270
|
-
* @
|
|
271
|
-
* @
|
|
272
|
-
* @returns {InstanceOfSchema<unknown, InstanceType<C>>} InstanceOf schema type
|
|
263
|
+
* Create instance of schema type
|
|
264
|
+
* @param {C} constructor - Constructor function
|
|
265
|
+
* @returns {InstanceOfSchema<unknown, InstanceType<C>>} Instance of schema type
|
|
273
266
|
*/
|
|
274
267
|
instanceOf: <C extends new (...args: any[]) => any>(constructor: C) => InstanceOfSchema<unknown, InstanceType<C>>;
|
|
275
268
|
/**
|
|
276
|
-
* Create
|
|
269
|
+
* Create UUID schema type
|
|
277
270
|
* @returns {StringSchemaType} UUID schema type
|
|
278
271
|
*/
|
|
279
272
|
uuid: () => StringSchemaType;
|
|
280
273
|
/**
|
|
281
|
-
* Create
|
|
282
|
-
* @
|
|
274
|
+
* Create regex schema type
|
|
275
|
+
* @param {RegExp} regex - Regex
|
|
276
|
+
* @returns {StringSchemaType} Regex schema type
|
|
283
277
|
*/
|
|
284
|
-
|
|
278
|
+
regex: (regex: RegExp) => StringSchemaType;
|
|
285
279
|
/**
|
|
286
|
-
* Create
|
|
287
|
-
* @
|
|
288
|
-
* @returns {StringSchemaType} Regex schema type
|
|
280
|
+
* Create email schema type
|
|
281
|
+
* @returns {StringSchemaType} Email schema type
|
|
289
282
|
*/
|
|
290
|
-
|
|
283
|
+
email: () => StringSchemaType;
|
|
291
284
|
/**
|
|
292
|
-
* Create
|
|
285
|
+
* Create phone schema type
|
|
293
286
|
* @returns {StringSchemaType} Phone schema type
|
|
294
287
|
*/
|
|
295
288
|
phone: () => StringSchemaType;
|
|
296
|
-
/**
|
|
297
|
-
*
|
|
298
|
-
* @param {boolean} [req=true] - Whether domain must include http/https
|
|
289
|
+
/** Create domain schema type
|
|
290
|
+
* @param {boolean} requireHttpOrHttps - Require http or https
|
|
299
291
|
* @returns {StringSchemaType} Domain schema type
|
|
300
292
|
*/
|
|
301
|
-
domain: (
|
|
293
|
+
domain: (requireHttpOrHttps?: boolean) => StringSchemaType;
|
|
302
294
|
/**
|
|
303
|
-
* Convert
|
|
304
|
-
* @
|
|
305
|
-
* @
|
|
306
|
-
* @returns {Schema<unknown, T>} Standardized schema
|
|
295
|
+
* Convert schema to standard schema
|
|
296
|
+
* @param {AnySchema} schema - Schema
|
|
297
|
+
* @returns {Schema<unknown, any>} Standard schema
|
|
307
298
|
*/
|
|
308
|
-
toStandard:
|
|
299
|
+
toStandard: typeof toStandard;
|
|
309
300
|
};
|
|
310
301
|
|
|
311
302
|
export { type AnySchema, AnySchemaType, ArraySchema, BaseSchema, BooleanSchemaType, InstanceOfSchema, LiteralSchema, NullSchemaType, NumberSchemaType, ObjectSchemaType, OptionalSchema, StringSchemaType, UnionSchema, h };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
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});
|
|
1
|
+
"use strict";var O=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var j=Object.prototype.hasOwnProperty;var V=(t,e)=>{for(var n in e)O(t,n,{get:e[n],enumerable:!0})},_=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of T(e))!j.call(t,a)&&a!==n&&O(t,a,{get:()=>e[a],enumerable:!(r=k(e,a))||r.enumerable});return t};var P=t=>_(O({},"__esModule",{value:!0}),t);var K={};V(K,{AnySchemaType:()=>b,ArraySchema:()=>x,BaseSchema:()=>i,BooleanSchemaType:()=>p,InstanceOfSchema:()=>I,LiteralSchema:()=>l,NullSchemaType:()=>w,NumberSchemaType:()=>S,ObjectSchemaType:()=>f,OptionalSchema:()=>u,StringSchemaType:()=>d,UnionSchema:()=>y,h:()=>m});module.exports=P(K);var i=class{jsonSchema={};get inferred(){return null}schema=this;_coerce=!1;coerce(){return this._coerce=!0,this}optional(){return new u(this)}enum(e){let n=e.map(r=>new l(r));return new y(...n)}array(){return new x(this)}instanceOf(e){return new I(this,e)}};function R(t,e){return typeof e=="string"&&t==="string"||typeof e=="number"&&t==="number"&&!Number.isNaN(e)||typeof e=="boolean"&&t==="boolean"}var d=class t extends i{type="string";_validateUUID=!1;_validateRegex=!1;_validateEmail=!1;_validatePhone=!1;_validateDomain=!1;_requireHttpOrHttps=!1;_minLength;_maxLength;constructor(){super(),this.jsonSchema={type:"string"}}primitive(){return this.type}minLength(e){let n=new t;return Object.assign(n,this),n._minLength=e,n.jsonSchema={...this.jsonSchema,minLength:e},n}maxLength(e){let n=new t;return Object.assign(n,this),n._maxLength=e,n.jsonSchema={...this.jsonSchema,maxLength:e},n}uuid(){let e=new t;return e._validateUUID=!0,e.jsonSchema={...this.jsonSchema,format:"uuid"},e}regex(e){let n=new t;return n._validateRegex=!0,n.jsonSchema={...this.jsonSchema,pattern:e.source},n}email(){let e=new t;return e._validateEmail=!0,e.jsonSchema={...this.jsonSchema,format:"email"},e}phone(){let e=new t;return e._validatePhone=!0,e.jsonSchema={...this.jsonSchema,format:"phone"},e}domain(e=!0){let n=new t;return n._validateDomain=!0,n.jsonSchema={...this.jsonSchema,format:"domain"},n._requireHttpOrHttps=e,n}"~standard"={version:1,vendor:"h-schema",validate:e=>(this._coerce&&typeof e!="string"&&(e=String(e)),typeof e!="string"?{issues:[{message:"Expected string, received "+typeof e}]}:this._minLength!==void 0&&e.length<this._minLength?{issues:[{message:`String shorter than ${this._minLength}`}]}:this._maxLength!==void 0&&e.length>this._maxLength?{issues:[{message:`String longer than ${this._maxLength}`}]}:this._validateUUID&&!this._isValidUUID(e)?{issues:[{message:"Invalid UUID format"}]}:this._validateRegex&&!this._isValidRegex(e)?{issues:[{message:"Invalid regex format"}]}:this._validateEmail&&!this._isValidEmail(e)?{issues:[{message:"Invalid email format"}]}:this._validatePhone&&!this._isValidPhone(e)?{issues:[{message:"Invalid phone number format"}]}:this._validateDomain&&!this._isValidDomain(e)?{issues:[{message:"Invalid domain format"}]}:{value:e}),types:{input:{},output:{}}};_isValidUUID(e){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(e)}_isValidRegex(e){return new RegExp(this.jsonSchema.pattern).test(e)}_isValidEmail(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}_isValidPhone(e){return/^\+?[0-9]{7,15}$/.test(e)}_isValidDomain(e){let n=/^[a-z0-9]+([-.]{1}[a-z0-9]+)*\.[a-z]{2,6}$/;return this._requireHttpOrHttps&&(n=/^https?:\/\/[a-z0-9]+([-.]{1}[a-z0-9]+)*\.[a-z]{2,6}$/),n.test(e)}},S=class t extends i{type="number";_min;_max;constructor(){super(),this.jsonSchema={type:"number"}}primitive(){return this.type}min(e){let n=new t;return Object.assign(n,this),n._min=e,n.jsonSchema={...this.jsonSchema,minimum:e},n}max(e){let n=new t;return Object.assign(n,this),n._max=e,n.jsonSchema={...this.jsonSchema,maximum:e},n}"~standard"={version:1,vendor:"h-schema",validate:e=>{if(this._coerce&&typeof e!="number"){let n=Number(e);Number.isNaN(n)||(e=n)}return typeof e!="number"||Number.isNaN(e)?{issues:[{message:`Expected number, received ${typeof e}`}]}:this._min!==void 0&&e<this._min?{issues:[{message:`Number less than ${this._min}`}]}:this._max!==void 0&&e>this._max?{issues:[{message:`Number greater than ${this._max}`}]}:{value:e}},types:{input:{},output:{}}}},p=class extends i{type="boolean";constructor(){super(),this.jsonSchema={type:"boolean"}}primitive(){return this.type}"~standard"={version:1,vendor:"h-schema",validate:e=>(this._coerce&&typeof e!="boolean"&&(e==="true"||e===1||e==="1"?e=!0:(e==="false"||e===0||e==="0")&&(e=!1)),typeof e!="boolean"?{issues:[{message:`Expected boolean, received ${typeof e}`}]}:{value:e}),types:{input:{},output:{}}}},b=class extends i{type="any";"~standard"={version:1,vendor:"h-schema",validate:e=>({value:e}),types:{input:{},output:{}}}},l=class extends i{value;constructor(e){super(),this.value=e,this.jsonSchema={const:e,type:typeof e}}"~standard"={version:1,vendor:"h-schema",validate:e=>e!==this.value?{issues:[{message:`Expected literal value ${this.value}, received ${e}`}]}:{value:e},types:{input:{},output:{}}}},u=class extends i{innerSchema;constructor(e){super(),this.innerSchema=e,this.jsonSchema={...e.jsonSchema}}"~standard"={version:1,vendor:"h-schema",validate:e=>e==null?{value:void 0}:this.innerSchema["~standard"].validate(e),types:{input:{},output:{}}}},w=class extends i{type="null";constructor(){super(),this.jsonSchema={type:"null"}}"~standard"={version:1,vendor:"h-schema",validate:e=>e!==null?{issues:[{message:`Expected null, received ${e===void 0?"undefined":typeof e}`}]}:{value:null},types:{input:{},output:{}}}},y=class extends i{schemas;constructor(...e){super(),this.schemas=e,this.jsonSchema={anyOf:e.map(n=>n.jsonSchema)}}"~standard"={version:1,vendor:"h-schema",validate:e=>{let n=[];for(let r of this.schemas){let a=r["~standard"].validate(e);if(!("issues"in a))return{value:a.value};n.push(...a.issues)}return{issues:n}},types:{input:{},output:{}}}},x=class extends i{innerSchema;constructor(e){super(),this.innerSchema=e,this.jsonSchema={type:"array",items:e.jsonSchema}}"~standard"={version:1,vendor:"h-schema",validate:e=>{if(!Array.isArray(e))return{issues:[{message:`Expected array, received ${typeof e}`}]};let n=e.map((a,s)=>{let o=this.innerSchema["~standard"].validate(a);return"issues"in o?{index:s,issues:o.issues?.map(h=>({...h,path:h.path?[s,...h.path]:[s]}))}:{index:s,value:o.value}}),r=n.filter(a=>"issues"in a);return r.length>0?{issues:r.flatMap(a=>a.issues)}:{value:n.map(a=>"value"in a?a.value:null)}},types:{input:{},output:{}}}},I=class extends i{innerSchema;classConstructor;constructor(e,n){super(),this.innerSchema=e,this.classConstructor=n,this.jsonSchema={...e.jsonSchema,instanceOf:n.name}}"~standard"={version:1,vendor:"h-schema",validate:e=>e instanceof this.classConstructor?this.innerSchema["~standard"].validate(e):{issues:[{message:`Expected instance of ${this.classConstructor.name}`}]},types:{input:{},output:{}}}},f=class extends i{definition;constructor(e){super(),this.definition=e;let n={},r=[];for(let a in e){let s=e[a];s instanceof u||r.push(a),typeof s=="string"?n[a]={type:s}:s instanceof i?n[a]=s.jsonSchema:typeof s=="object"&&s!==null&&(n[a]={type:"object",properties:{}})}this.jsonSchema={type:"object",properties:n,required:r.length>0?r:void 0}}"~standard"={version:1,vendor:"h-schema",validate:e=>{if(typeof e!="object"||e===null||Array.isArray(e))return{issues:[{message:"Expected object, received "+(e===null?"null":Array.isArray(e)?"array":typeof e)}]};let n=e,r={},a=[];for(let s in this.definition){let o=this.definition[s],h=o instanceof u;if(!(s in n)&&!h){a.push({message:`Missing required property: ${s}`,path:[s]});continue}if(s in n){if(typeof o=="string"&&o in["string","number","boolean"]){let c=o;R(c,n[s])?r[s]=n[s]:a.push({message:`Invalid type for property ${s}: expected ${c}`,path:[s]})}else if(o instanceof i){let c=o["~standard"].validate(n[s]);"issues"in c?c.issues&&a.push(...c.issues.map(v=>({...v,path:v.path?[s,...v.path]:[s]}))):r[s]=c.value}}}return a.length>0?{issues:a}:{value:r}},types:{input:{},output:{}}}};function g(t){let e;if(t instanceof i)e=t;else if(typeof t=="string")if(t==="string")e=new d;else if(t==="number")e=new S;else if(t==="boolean")e=new p;else throw new Error("Invalid schema type provided to toStandard");else if(typeof t=="object"&&t!==null&&!Array.isArray(t))e=new f(t);else throw new Error("Invalid schema type provided to toStandard");let n={toJSONSchema:r=>r.jsonSchema};return{...e,inferred:null,"~standard":e["~standard"],jsonSchema:n.toJSONSchema(e),schema:e,optional:()=>new u(e),enum:e.enum.bind(e),array:e.array.bind(e),instanceOf:e.instanceOf.bind(e)}}var m={string:()=>new d,number:()=>new S,boolean:()=>new p,null:()=>new w,any:()=>new b,literal:t=>new l(t),object:t=>new f(t||{}),array:t=>g(t).array(),enum:t=>{if(!t||t.length===0)throw new Error("h.enum() requires a non-empty array of values.");let e=t.map(n=>m.literal(n));return m.options(...e)},optional:t=>g(t).optional(),options:(...t)=>{let e=t.map(n=>g(n).schema);return new y(...e)},instanceOf:t=>m.object({}).instanceOf(t),uuid:()=>m.string().uuid(),regex:t=>m.string().regex(t),email:()=>m.string().email(),phone:()=>m.string().phone(),domain:(t=!0)=>m.string().domain(t),toStandard:g};0&&(module.exports={AnySchemaType,ArraySchema,BaseSchema,BooleanSchemaType,InstanceOfSchema,LiteralSchema,NullSchemaType,NumberSchemaType,ObjectSchemaType,OptionalSchema,StringSchemaType,UnionSchema,h});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hedystia/validations",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.4",
|
|
4
4
|
"devDependencies": {
|
|
5
5
|
"@standard-schema/spec": "^1.0.0",
|
|
6
6
|
"@types/bun": "^1.3.3",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"private": false,
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"scripts": {
|
|
20
|
-
"build": "
|
|
21
|
-
"dev": "bun --watch --no-clear-screen run index.ts"
|
|
20
|
+
"build": "tsup",
|
|
21
|
+
"dev": "bun --watch --no-clear-screen run src/index.ts"
|
|
22
22
|
},
|
|
23
23
|
"repository": {
|
|
24
24
|
"type": "git",
|
package/readme.md
CHANGED
|
@@ -1,165 +1,165 @@
|
|
|
1
|
-
<div align="center">
|
|
2
|
-
<p>
|
|
3
|
-
<strong>🚀 Hedystia Framework</strong>
|
|
4
|
-
</p>
|
|
5
|
-
|
|
6
|
-
<p>
|
|
7
|
-
<strong>Next-gen TypeScript framework for building type-safe APIs at lightspeed! ⚡</strong>
|
|
8
|
-
</p>
|
|
9
|
-
|
|
10
|
-
<p>
|
|
11
|
-
<a href="https://www.npmjs.com/package/hedystia"><img src="https://img.shields.io/npm/v/hedystia.svg?style=flat-square" alt="npm version"></a>
|
|
12
|
-
<a href="https://www.npmjs.com/package/hedystia"><img src="https://img.shields.io/npm/dm/hedystia.svg?style=flat-square" alt="npm downloads"></a>
|
|
13
|
-
<a href="LICENSE"><img src="https://img.shields.io/github/license/Hedystia/Framework.svg?style=flat-square" alt="license"></a>
|
|
14
|
-
<img src="https://img.shields.io/badge/Bun-powered-FFD43B?style=flat-square&logo=bun" alt="Bun powered">
|
|
15
|
-
</p>
|
|
16
|
-
</div>
|
|
17
|
-
|
|
18
|
-
## 🌟 Superpowers
|
|
19
|
-
|
|
20
|
-
- 🌐 **Multi-runtime support** - Bun (default), Deno, Node.js, Vercel, Cloudflare Workers, Fastly Compute, Lambda, etc.
|
|
21
|
-
- 🔒 **End-to-end type safety** - From params to response, full TypeScript integration
|
|
22
|
-
- ⚡ **Bun-native performance** - Built for Bun runtime with native validation
|
|
23
|
-
- 🧩 **Client integration** - Auto-generated type-safe HTTP client
|
|
24
|
-
- 🛡️ **Validation built-in** - Zod integration for runtime safety
|
|
25
|
-
- 🔌 **Extensible architecture** - Middleware, hooks and macros system
|
|
26
|
-
- 📝 **Standard Schema** - Compatibility with the standard schema so you can use it with Zod, Arktype, etc.
|
|
27
|
-
|
|
28
|
-
## 🚀 Launch in 30 Seconds
|
|
29
|
-
|
|
30
|
-
1. Install with Bun:
|
|
31
|
-
```bash
|
|
32
|
-
bun add hedystia
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
2. Create your first API:
|
|
36
|
-
```typescript
|
|
37
|
-
import { Hedystia, h } from "hedystia";
|
|
38
|
-
|
|
39
|
-
const app = new Hedystia()
|
|
40
|
-
.get("/hello/:name", (ctx) => `Hello ${ctx.params.name}!`, {
|
|
41
|
-
params: h.object({ name: h.string() }),
|
|
42
|
-
response: h.string()
|
|
43
|
-
})
|
|
44
|
-
.listen(3000);
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
3. Generate client and consume API:
|
|
48
|
-
```typescript
|
|
49
|
-
import { createClient } from "@hedystia/client";
|
|
50
|
-
|
|
51
|
-
const client = createClient<typeof app>("http://localhost:3000");
|
|
52
|
-
|
|
53
|
-
// Fully typed request!
|
|
54
|
-
const { data } = await client.hello.name("World").get();
|
|
55
|
-
console.log(data); // "Hello World!"
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
## 💡 Why Developers Love Hedystia
|
|
59
|
-
|
|
60
|
-
### 🔄 Full-stack Type Safety
|
|
61
|
-
```typescript
|
|
62
|
-
// Server-side validation
|
|
63
|
-
.post("/users", (ctx) => {...}, {
|
|
64
|
-
body: h.object({
|
|
65
|
-
email: h.email(),
|
|
66
|
-
age: h.number()
|
|
67
|
-
})
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
// Client-side types
|
|
71
|
-
await client.users.post({
|
|
72
|
-
body: {
|
|
73
|
-
email: "user@example.com", // Autocompletes!
|
|
74
|
-
age: 25 // Type-checked
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### 📖 Swagger Integration
|
|
80
|
-
|
|
81
|
-
```typescript
|
|
82
|
-
import { swagger } from "@hedystia/swagger";
|
|
83
|
-
|
|
84
|
-
const swaggerPlugin = swagger({
|
|
85
|
-
title: "My API",
|
|
86
|
-
description: "An example API with Swagger",
|
|
87
|
-
version: "1.0.0",
|
|
88
|
-
tags: [
|
|
89
|
-
{ name: "users", description: "User operations" },
|
|
90
|
-
],
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
app.use("/swagger", swaggerPlugin.plugin(app));
|
|
94
|
-
|
|
95
|
-
app.listen(3000);
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
### ⚡ Performance First
|
|
99
|
-
- Bun runtime optimized
|
|
100
|
-
- Faster by default
|
|
101
|
-
- Own type validation system
|
|
102
|
-
- Faster than Express
|
|
103
|
-
- Built-in response compression
|
|
104
|
-
|
|
105
|
-
### 🧩 Modern Feature Set
|
|
106
|
-
```typescript
|
|
107
|
-
// File uploads
|
|
108
|
-
.post("/upload", async (ctx) => {
|
|
109
|
-
const formData = await ctx.body; // FormData type
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
// Binary responses
|
|
113
|
-
.get("/pdf", () => new Blob([...]), {
|
|
114
|
-
response: h.instanceof(Blob)
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
// Nested routing
|
|
118
|
-
.group("/api/v1", (v1) => v1
|
|
119
|
-
.group("/users", (users) => users
|
|
120
|
-
.get("/:id", ...)
|
|
121
|
-
)
|
|
122
|
-
)
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
## 🛠️ Development Roadmap
|
|
126
|
-
|
|
127
|
-
### Core Features
|
|
128
|
-
- ✅ HTTP Methods: GET, POST, PUT, PATCH, DELETE
|
|
129
|
-
- ✅ Response Types: JSON, Text, FormData, Blob, ArrayBuffer
|
|
130
|
-
- ✅ Router Groups & Middleware
|
|
131
|
-
- ✅ Type-safe Client Generation
|
|
132
|
-
- ✅ WebSocket Support
|
|
133
|
-
- ✅ Adapter System to work with other frameworks
|
|
134
|
-
|
|
135
|
-
### Advanced Capabilities
|
|
136
|
-
- ✅ Standard Schema Compatibility
|
|
137
|
-
- ✅ Hooks System (onRequest, onError, etc)
|
|
138
|
-
- ✅ Macro System for Auth/Rate Limiting
|
|
139
|
-
- ✅ OpenAPI - Swagger Integration
|
|
140
|
-
|
|
141
|
-
## 💼 Production Ready
|
|
142
|
-
```typescript
|
|
143
|
-
// Error handling
|
|
144
|
-
.onError((err) => {
|
|
145
|
-
return Response.json({
|
|
146
|
-
error: err.message
|
|
147
|
-
}, { status: 500 })
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
// Rate limiting macro
|
|
151
|
-
.macro({
|
|
152
|
-
rateLimit: () => ({
|
|
153
|
-
resolve: async (ctx) => {
|
|
154
|
-
// Implement your logic
|
|
155
|
-
}
|
|
156
|
-
})
|
|
157
|
-
})
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
## 📜 License
|
|
161
|
-
MIT License © 2025 Hedystia
|
|
162
|
-
|
|
163
|
-
## 🗣️ Community
|
|
164
|
-
- [GitHub Issues](https://github.com/Hedystia/Framework/issues)
|
|
165
|
-
- [Discord Server](https://hedystia.com/support)
|
|
1
|
+
<div align="center">
|
|
2
|
+
<p>
|
|
3
|
+
<strong>🚀 Hedystia Framework</strong>
|
|
4
|
+
</p>
|
|
5
|
+
|
|
6
|
+
<p>
|
|
7
|
+
<strong>Next-gen TypeScript framework for building type-safe APIs at lightspeed! ⚡</strong>
|
|
8
|
+
</p>
|
|
9
|
+
|
|
10
|
+
<p>
|
|
11
|
+
<a href="https://www.npmjs.com/package/hedystia"><img src="https://img.shields.io/npm/v/hedystia.svg?style=flat-square" alt="npm version"></a>
|
|
12
|
+
<a href="https://www.npmjs.com/package/hedystia"><img src="https://img.shields.io/npm/dm/hedystia.svg?style=flat-square" alt="npm downloads"></a>
|
|
13
|
+
<a href="LICENSE"><img src="https://img.shields.io/github/license/Hedystia/Framework.svg?style=flat-square" alt="license"></a>
|
|
14
|
+
<img src="https://img.shields.io/badge/Bun-powered-FFD43B?style=flat-square&logo=bun" alt="Bun powered">
|
|
15
|
+
</p>
|
|
16
|
+
</div>
|
|
17
|
+
|
|
18
|
+
## 🌟 Superpowers
|
|
19
|
+
|
|
20
|
+
- 🌐 **Multi-runtime support** - Bun (default), Deno, Node.js, Vercel, Cloudflare Workers, Fastly Compute, Lambda, etc.
|
|
21
|
+
- 🔒 **End-to-end type safety** - From params to response, full TypeScript integration
|
|
22
|
+
- ⚡ **Bun-native performance** - Built for Bun runtime with native validation
|
|
23
|
+
- 🧩 **Client integration** - Auto-generated type-safe HTTP client
|
|
24
|
+
- 🛡️ **Validation built-in** - Zod integration for runtime safety
|
|
25
|
+
- 🔌 **Extensible architecture** - Middleware, hooks and macros system
|
|
26
|
+
- 📝 **Standard Schema** - Compatibility with the standard schema so you can use it with Zod, Arktype, etc.
|
|
27
|
+
|
|
28
|
+
## 🚀 Launch in 30 Seconds
|
|
29
|
+
|
|
30
|
+
1. Install with Bun:
|
|
31
|
+
```bash
|
|
32
|
+
bun add hedystia
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
2. Create your first API:
|
|
36
|
+
```typescript
|
|
37
|
+
import { Hedystia, h } from "hedystia";
|
|
38
|
+
|
|
39
|
+
const app = new Hedystia()
|
|
40
|
+
.get("/hello/:name", (ctx) => `Hello ${ctx.params.name}!`, {
|
|
41
|
+
params: h.object({ name: h.string() }),
|
|
42
|
+
response: h.string()
|
|
43
|
+
})
|
|
44
|
+
.listen(3000);
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
3. Generate client and consume API:
|
|
48
|
+
```typescript
|
|
49
|
+
import { createClient } from "@hedystia/client";
|
|
50
|
+
|
|
51
|
+
const client = createClient<typeof app>("http://localhost:3000");
|
|
52
|
+
|
|
53
|
+
// Fully typed request!
|
|
54
|
+
const { data } = await client.hello.name("World").get();
|
|
55
|
+
console.log(data); // "Hello World!"
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## 💡 Why Developers Love Hedystia
|
|
59
|
+
|
|
60
|
+
### 🔄 Full-stack Type Safety
|
|
61
|
+
```typescript
|
|
62
|
+
// Server-side validation
|
|
63
|
+
.post("/users", (ctx) => {...}, {
|
|
64
|
+
body: h.object({
|
|
65
|
+
email: h.email(),
|
|
66
|
+
age: h.number()
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
// Client-side types
|
|
71
|
+
await client.users.post({
|
|
72
|
+
body: {
|
|
73
|
+
email: "user@example.com", // Autocompletes!
|
|
74
|
+
age: 25 // Type-checked
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### 📖 Swagger Integration
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { swagger } from "@hedystia/swagger";
|
|
83
|
+
|
|
84
|
+
const swaggerPlugin = swagger({
|
|
85
|
+
title: "My API",
|
|
86
|
+
description: "An example API with Swagger",
|
|
87
|
+
version: "1.0.0",
|
|
88
|
+
tags: [
|
|
89
|
+
{ name: "users", description: "User operations" },
|
|
90
|
+
],
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
app.use("/swagger", swaggerPlugin.plugin(app));
|
|
94
|
+
|
|
95
|
+
app.listen(3000);
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### ⚡ Performance First
|
|
99
|
+
- Bun runtime optimized
|
|
100
|
+
- Faster by default
|
|
101
|
+
- Own type validation system
|
|
102
|
+
- Faster than Express
|
|
103
|
+
- Built-in response compression
|
|
104
|
+
|
|
105
|
+
### 🧩 Modern Feature Set
|
|
106
|
+
```typescript
|
|
107
|
+
// File uploads
|
|
108
|
+
.post("/upload", async (ctx) => {
|
|
109
|
+
const formData = await ctx.body; // FormData type
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
// Binary responses
|
|
113
|
+
.get("/pdf", () => new Blob([...]), {
|
|
114
|
+
response: h.instanceof(Blob)
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
// Nested routing
|
|
118
|
+
.group("/api/v1", (v1) => v1
|
|
119
|
+
.group("/users", (users) => users
|
|
120
|
+
.get("/:id", ...)
|
|
121
|
+
)
|
|
122
|
+
)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## 🛠️ Development Roadmap
|
|
126
|
+
|
|
127
|
+
### Core Features
|
|
128
|
+
- ✅ HTTP Methods: GET, POST, PUT, PATCH, DELETE
|
|
129
|
+
- ✅ Response Types: JSON, Text, FormData, Blob, ArrayBuffer
|
|
130
|
+
- ✅ Router Groups & Middleware
|
|
131
|
+
- ✅ Type-safe Client Generation
|
|
132
|
+
- ✅ WebSocket Support
|
|
133
|
+
- ✅ Adapter System to work with other frameworks
|
|
134
|
+
|
|
135
|
+
### Advanced Capabilities
|
|
136
|
+
- ✅ Standard Schema Compatibility
|
|
137
|
+
- ✅ Hooks System (onRequest, onError, etc)
|
|
138
|
+
- ✅ Macro System for Auth/Rate Limiting
|
|
139
|
+
- ✅ OpenAPI - Swagger Integration
|
|
140
|
+
|
|
141
|
+
## 💼 Production Ready
|
|
142
|
+
```typescript
|
|
143
|
+
// Error handling
|
|
144
|
+
.onError((err) => {
|
|
145
|
+
return Response.json({
|
|
146
|
+
error: err.message
|
|
147
|
+
}, { status: 500 })
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
// Rate limiting macro
|
|
151
|
+
.macro({
|
|
152
|
+
rateLimit: () => ({
|
|
153
|
+
resolve: async (ctx) => {
|
|
154
|
+
// Implement your logic
|
|
155
|
+
}
|
|
156
|
+
})
|
|
157
|
+
})
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## 📜 License
|
|
161
|
+
MIT License © 2025 Hedystia
|
|
162
|
+
|
|
163
|
+
## 🗣️ Community
|
|
164
|
+
- [GitHub Issues](https://github.com/Hedystia/Framework/issues)
|
|
165
|
+
- [Discord Server](https://hedystia.com/support)
|
package/dist/validations_bg.wasm
DELETED
|
Binary file
|