@douglasneuroinformatics/libjs 2.2.1 → 2.3.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/dist/exception.d.ts +18 -1
- package/dist/exception.d.ts.map +1 -1
- package/dist/exception.js +6 -1
- package/dist/zod.d.ts +3 -0
- package/dist/zod.d.ts.map +1 -1
- package/dist/zod.js +14 -0
- package/package.json +1 -1
package/dist/exception.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Result, ResultAsync } from 'neverthrow';
|
|
2
2
|
import type { IsNever, RequiredKeysOf } from 'type-fest';
|
|
3
|
+
import type { z } from 'zod';
|
|
3
4
|
import type { SingleKeyMap, ToAbstractConstructor } from './types.js';
|
|
4
5
|
type ExceptionName = `${string}Exception`;
|
|
5
6
|
type ExceptionOptions = {
|
|
@@ -51,6 +52,11 @@ declare class ExceptionBuilder<TParams extends ExceptionParams | undefined, TOpt
|
|
|
51
52
|
[K in TName]: TMethod;
|
|
52
53
|
}>;
|
|
53
54
|
}
|
|
55
|
+
declare const RuntimeException: ExceptionType<{
|
|
56
|
+
readonly name: "RuntimeException";
|
|
57
|
+
}, ExceptionOptions, {
|
|
58
|
+
[key: string]: unknown;
|
|
59
|
+
}>;
|
|
54
60
|
declare const ValueException: ExceptionType<{
|
|
55
61
|
readonly name: "ValueException";
|
|
56
62
|
}, ExceptionOptions, {
|
|
@@ -100,6 +106,17 @@ declare const OutOfRangeException: ExceptionType<{
|
|
|
100
106
|
};
|
|
101
107
|
}>;
|
|
102
108
|
}>;
|
|
109
|
+
export declare const ValidationException: ExceptionType<{
|
|
110
|
+
readonly message: "Zod schema validation failed";
|
|
111
|
+
readonly name: "ValidationException";
|
|
112
|
+
}, {
|
|
113
|
+
details: {
|
|
114
|
+
data: unknown;
|
|
115
|
+
issues: z.ZodIssue[];
|
|
116
|
+
};
|
|
117
|
+
}, {
|
|
118
|
+
[key: string]: unknown;
|
|
119
|
+
}>;
|
|
103
120
|
export type { ExceptionConstructor, ExceptionConstructorArgs, ExceptionName, ExceptionOptions, ExceptionParams, ExceptionStatic, ExceptionType };
|
|
104
|
-
export { BaseException, ExceptionBuilder, OutOfRangeException, ValueException };
|
|
121
|
+
export { BaseException, ExceptionBuilder, OutOfRangeException, RuntimeException, ValueException };
|
|
105
122
|
//# sourceMappingURL=exception.d.ts.map
|
package/dist/exception.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exception.d.ts","sourceRoot":"","sources":["../src/exception.ts"],"names":[],"mappings":"AAKA,OAAO,EAAiB,MAAM,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEhE,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"exception.d.ts","sourceRoot":"","sources":["../src/exception.ts"],"names":[],"mappings":"AAKA,OAAO,EAAiB,MAAM,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEhE,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAK7B,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEtE,KAAK,aAAa,GAAG,GAAG,MAAM,WAAW,CAAC;AAE1C,KAAK,gBAAgB,GAAG;IACtB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE;QACR,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,CAAC;CACH,CAAC;AAEF,KAAK,eAAe,CAAC,QAAQ,GAAG,GAAG,IAAI;IACrC,OAAO,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,QAAQ,KAAK,MAAM,CAAC,GAAG,MAAM,CAAC;IACnD,IAAI,EAAE,aAAa,CAAC;CACrB,CAAC;AAEF,KAAK,wBAAwB,CAA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CAAC,QAAQ,EAAE,CAAA;KAAE;;;EAE1D,CAAC;AAEX,YAAY,EACV,oBAAoB,EACpB,wBAAwB,EACxB,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,aAAa,EACd,CAAC;AACF,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,cAAc,EAAE,CAAC"}
|
package/dist/exception.js
CHANGED
|
@@ -98,6 +98,7 @@ class ExceptionBuilder {
|
|
|
98
98
|
return this;
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
|
+
const { RuntimeException } = new ExceptionBuilder().setParams({ name: 'RuntimeException' }).build();
|
|
101
102
|
const { ValueException } = new ExceptionBuilder().setParams({ name: 'ValueException' }).build();
|
|
102
103
|
const { OutOfRangeException } = new ExceptionBuilder()
|
|
103
104
|
.extend(ValueException)
|
|
@@ -110,4 +111,8 @@ const { OutOfRangeException } = new ExceptionBuilder()
|
|
|
110
111
|
return new this({ details: { max: Infinity, min: 0, value } });
|
|
111
112
|
})
|
|
112
113
|
.build();
|
|
113
|
-
export {
|
|
114
|
+
export const { ValidationException } = new ExceptionBuilder()
|
|
115
|
+
.setOptionsType()
|
|
116
|
+
.setParams({ message: 'Zod schema validation failed', name: 'ValidationException' })
|
|
117
|
+
.build();
|
|
118
|
+
export { BaseException, ExceptionBuilder, OutOfRangeException, RuntimeException, ValueException };
|
package/dist/zod.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import type { Result } from 'neverthrow';
|
|
1
2
|
import { z } from 'zod';
|
|
3
|
+
import { ValidationException } from './exception.js';
|
|
2
4
|
/** Used to determine if object is of type `ZodType` independent of specific instances or library versions */
|
|
3
5
|
export declare function isZodType(arg: unknown): arg is z.ZodTypeAny;
|
|
4
6
|
export declare const $BooleanLike: z.ZodType<boolean, z.ZodTypeDef, any>;
|
|
5
7
|
export declare const $NumberLike: z.ZodType<number, z.ZodTypeDef, any>;
|
|
6
8
|
export declare const $UrlLike: z.ZodType<URL, z.ZodTypeDef, any>;
|
|
7
9
|
export declare const $Uint8ArrayLike: z.ZodType<Uint8Array, z.ZodTypeDef, any>;
|
|
10
|
+
export declare function safeParse<TSchema extends z.ZodTypeAny>(data: unknown, $Schema: TSchema): Result<z.infer<TSchema>, typeof ValidationException.Instance>;
|
|
8
11
|
//# sourceMappingURL=zod.d.ts.map
|
package/dist/zod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../src/zod.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../src/zod.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAIrD,6GAA6G;AAC7G,wBAAgB,SAAS,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,CAAC,CAAC,UAAU,CAM3D;AAED,eAAO,MAAM,YAAY,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,UAAU,EAAE,GAAG,CAShD,CAAC;AAEhB,eAAO,MAAM,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,EAAE,GAAG,CAK/C,CAAC;AAEf,eAAO,MAAM,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,UAAU,EAAE,GAAG,CAWtD,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,UAAU,EAAE,GAAG,CAOjE,CAAC;AAEL,wBAAgB,SAAS,CAAC,OAAO,SAAS,CAAC,CAAC,UAAU,EACpD,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,OAAO,GACf,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO,mBAAmB,CAAC,QAAQ,CAAC,CAW/D"}
|
package/dist/zod.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { ok } from 'neverthrow';
|
|
1
2
|
import { z } from 'zod';
|
|
3
|
+
import { ValidationException } from './exception.js';
|
|
2
4
|
import { isNumberLike, parseNumber } from './number.js';
|
|
3
5
|
import { isObject } from './object.js';
|
|
4
6
|
/** Used to determine if object is of type `ZodType` independent of specific instances or library versions */
|
|
@@ -43,3 +45,15 @@ export const $Uint8ArrayLike = z
|
|
|
43
45
|
}
|
|
44
46
|
return arg;
|
|
45
47
|
});
|
|
48
|
+
export function safeParse(data, $Schema) {
|
|
49
|
+
const result = $Schema.safeParse(data);
|
|
50
|
+
if (!result.success) {
|
|
51
|
+
return ValidationException.asErr({
|
|
52
|
+
details: {
|
|
53
|
+
data,
|
|
54
|
+
issues: result.error.issues
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return ok(result.data);
|
|
59
|
+
}
|
package/package.json
CHANGED