@bessemer/cornerstone 0.5.38 → 0.5.39
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/error-event.d.ts +20 -3
- package/dist/error-event.d.ts.map +1 -1
- package/dist/error-event.js +23 -1
- package/dist/error-event.js.map +1 -1
- package/dist/zod.d.ts +4 -0
- package/dist/zod.d.ts.map +1 -1
- package/dist/zod.js +4 -0
- package/dist/zod.js.map +1 -1
- package/package.json +1 -1
package/dist/error-event.d.ts
CHANGED
@@ -1,11 +1,25 @@
|
|
1
|
+
import { Zod } from '@bessemer/cornerstone';
|
1
2
|
import { NominalType, Throwable } from '@bessemer/cornerstone/types';
|
2
3
|
import { RecordAttribute } from '@bessemer/cornerstone/object';
|
4
|
+
import { ZodType } from 'zod';
|
3
5
|
export type ErrorCode = NominalType<string, 'ErrorCode'>;
|
6
|
+
export declare const ErrorCodeSchema: ZodType<ErrorCode>;
|
4
7
|
export type ErrorAttribute<Type = unknown> = RecordAttribute<Type, 'ErrorAttribute'>;
|
5
|
-
export
|
6
|
-
|
8
|
+
export declare const ErrorAttributeSchema: ZodType<ErrorAttribute>;
|
9
|
+
declare const baseErrorEventSchema: import("zod").ZodObject<{
|
10
|
+
code: ZodType<ErrorCode, import("zod").ZodTypeDef, ErrorCode>;
|
11
|
+
message: import("zod").ZodString;
|
12
|
+
attributes: import("zod").ZodRecord<ZodType<ErrorAttribute<unknown>, import("zod").ZodTypeDef, ErrorAttribute<unknown>>, import("zod").ZodUnknown>;
|
13
|
+
}, "strip", import("zod").ZodTypeAny, {
|
14
|
+
code: string & import("@bessemer/cornerstone/types").NominalTyping<"ErrorCode">;
|
15
|
+
message: string;
|
16
|
+
attributes: Record<ErrorAttribute<unknown>, unknown>;
|
17
|
+
}, {
|
18
|
+
code: string & import("@bessemer/cornerstone/types").NominalTyping<"ErrorCode">;
|
7
19
|
message: string;
|
8
|
-
attributes: Record<ErrorAttribute
|
20
|
+
attributes: Record<ErrorAttribute<unknown>, unknown>;
|
21
|
+
}>;
|
22
|
+
export type ErrorEvent = Zod.infer<typeof baseErrorEventSchema> & {
|
9
23
|
causes: Array<ErrorEvent>;
|
10
24
|
};
|
11
25
|
export type ErrorEventBuilder = {
|
@@ -27,8 +41,11 @@ export declare const findInCausalChain: (error: ErrorEvent, predicate: (error: E
|
|
27
41
|
export declare const aggregate: (builder: ErrorEventBuilder, causes: Array<ErrorEvent>) => ErrorEvent | undefined;
|
28
42
|
export declare const UnhandledErrorCode: ErrorCode;
|
29
43
|
export declare const NotFoundErrorCode: ErrorCode;
|
44
|
+
export declare const UnauthorizedErrorCode: ErrorCode;
|
30
45
|
export declare const RequestCorrelationIdAttribute: ErrorAttribute<string>;
|
31
46
|
export declare const HttpStatusCodeAttribute: ErrorAttribute<number>;
|
32
47
|
export declare const unhandled: (builder?: ErrorEventBuilder) => ErrorEvent;
|
33
48
|
export declare const notFound: (builder?: ErrorEventBuilder) => ErrorEvent;
|
49
|
+
export declare const unauthorized: (builder?: ErrorEventBuilder) => ErrorEvent;
|
50
|
+
export {};
|
34
51
|
//# sourceMappingURL=error-event.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"error-event.d.ts","sourceRoot":"","sources":["../src/error-event.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"error-event.d.ts","sourceRoot":"","sources":["../src/error-event.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,GAAG,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAA;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAO7B,MAAM,MAAM,SAAS,GAAG,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;AACxD,eAAO,MAAM,eAAe,EAAE,OAAO,CAAC,SAAS,CAAgB,CAAA;AAE/D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ED,eAAO,MAAM,SAAS,GAAI,SAAS,iBAAiB,EAAE,QAAQ,KAAK,CAAC,UAAU,CAAC,KAAG,UAAU,GAAG,SAM9F,CAAA;AAED,eAAO,MAAM,kBAAkB,EAAE,SAAmC,CAAA;AACpE,eAAO,MAAM,iBAAiB,EAAE,SAAmC,CAAA;AACnE,eAAO,MAAM,qBAAqB,EAAE,SAAsC,CAAA;AAE1E,eAAO,MAAM,6BAA6B,EAAE,cAAc,CAAC,MAAM,CAA0B,CAAA;AAC3F,eAAO,MAAM,uBAAuB,EAAE,cAAc,CAAC,MAAM,CAAoB,CAAA;AAE/E,eAAO,MAAM,SAAS,GAAI,UAAU,iBAAiB,eAOlD,CAAA;AAEH,eAAO,MAAM,QAAQ,GAAI,UAAU,iBAAiB,eAOjD,CAAA;AAEH,eAAO,MAAM,YAAY,GAAI,UAAU,iBAAiB,eAOrD,CAAA"}
|
package/dist/error-event.js
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
// src/error-event.ts
|
2
|
-
import { Arrays, Errors, Objects } from "@bessemer/cornerstone";
|
2
|
+
import { Arrays, Errors, Objects, Zod } from "@bessemer/cornerstone";
|
3
|
+
var ErrorCodeSchema = Zod.string();
|
4
|
+
var ErrorAttributeSchema = Zod.string();
|
5
|
+
var baseErrorEventSchema = Zod.object({
|
6
|
+
code: ErrorCodeSchema,
|
7
|
+
message: Zod.string(),
|
8
|
+
attributes: Zod.record(ErrorAttributeSchema, Zod.unknown())
|
9
|
+
});
|
10
|
+
var ErrorEventSchema = baseErrorEventSchema.extend({
|
11
|
+
causes: Zod.lazy(() => Zod.array(ErrorEventSchema))
|
12
|
+
});
|
3
13
|
var ErrorEventException = class extends Error {
|
4
14
|
errorEvent;
|
5
15
|
constructor(errorEvent, cause) {
|
@@ -56,6 +66,7 @@ var aggregate = (builder, causes) => {
|
|
56
66
|
};
|
57
67
|
var UnhandledErrorCode = "error-event.unhandled";
|
58
68
|
var NotFoundErrorCode = "error-event.not-found";
|
69
|
+
var UnauthorizedErrorCode = "error-event.unauthorized";
|
59
70
|
var RequestCorrelationIdAttribute = "requestCorrelationId";
|
60
71
|
var HttpStatusCodeAttribute = "httpStatusCode";
|
61
72
|
var unhandled = (builder) => of(
|
@@ -72,11 +83,21 @@ var notFound = (builder) => of(
|
|
72
83
|
attributes: { [HttpStatusCodeAttribute]: 404 }
|
73
84
|
})
|
74
85
|
);
|
86
|
+
var unauthorized = (builder) => of(
|
87
|
+
Objects.deepMerge(builder, {
|
88
|
+
code: UnauthorizedErrorCode,
|
89
|
+
message: "The requested Resource requires authentication.",
|
90
|
+
attributes: { [HttpStatusCodeAttribute]: 401 }
|
91
|
+
})
|
92
|
+
);
|
75
93
|
export {
|
94
|
+
ErrorAttributeSchema,
|
95
|
+
ErrorCodeSchema,
|
76
96
|
ErrorEventException,
|
77
97
|
HttpStatusCodeAttribute,
|
78
98
|
NotFoundErrorCode,
|
79
99
|
RequestCorrelationIdAttribute,
|
100
|
+
UnauthorizedErrorCode,
|
80
101
|
UnhandledErrorCode,
|
81
102
|
aggregate,
|
82
103
|
findByCodeInCausalChain,
|
@@ -86,6 +107,7 @@ export {
|
|
86
107
|
isErrorEventException,
|
87
108
|
notFound,
|
88
109
|
of,
|
110
|
+
unauthorized,
|
89
111
|
unhandled
|
90
112
|
};
|
91
113
|
//# sourceMappingURL=error-event.js.map
|
package/dist/error-event.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/error-event.ts"],"sourcesContent":["import { Arrays, Errors, Objects } from '@bessemer/cornerstone'\nimport { NominalType, Throwable } from '@bessemer/cornerstone/types'\nimport { RecordAttribute } from '@bessemer/cornerstone/object'\n\n/*\n Represents a structured error event. The code can be mapped to a unique type of error while the\n message and attributes can provide contextual information about the error. Finally,\n an ErrorEvent could have multiple causes which get aggregated into a single parent error.\n */\nexport type ErrorCode = NominalType<string, 'ErrorCode'>\nexport type ErrorAttribute<Type = unknown> = RecordAttribute<Type, 'ErrorAttribute'>\
|
1
|
+
{"version":3,"sources":["../src/error-event.ts"],"sourcesContent":["import { Arrays, Errors, Objects, Zod } from '@bessemer/cornerstone'\nimport { NominalType, Throwable } from '@bessemer/cornerstone/types'\nimport { RecordAttribute } from '@bessemer/cornerstone/object'\nimport { ZodType } from 'zod'\n\n/*\n Represents a structured error event. The code can be mapped to a unique type of error while the\n message and attributes can provide contextual information about the error. Finally,\n an ErrorEvent could have multiple causes which get aggregated into a single parent error.\n */\nexport type ErrorCode = NominalType<string, 'ErrorCode'>\nexport const ErrorCodeSchema: ZodType<ErrorCode> = Zod.string()\n\nexport type ErrorAttribute<Type = unknown> = RecordAttribute<Type, 'ErrorAttribute'>\nexport const ErrorAttributeSchema: ZodType<ErrorAttribute> = Zod.string()\n\nconst baseErrorEventSchema = Zod.object({\n code: ErrorCodeSchema,\n message: Zod.string(),\n attributes: Zod.record(ErrorAttributeSchema, Zod.unknown()),\n})\n\nexport type ErrorEvent = Zod.infer<typeof baseErrorEventSchema> & {\n causes: Array<ErrorEvent>\n}\n\nconst ErrorEventSchema: ZodType<ErrorEvent> = baseErrorEventSchema.extend({\n causes: Zod.lazy(() => Zod.array(ErrorEventSchema)),\n})\n\n// Builder object that allows for 'partial' representation of ErrorEvents\nexport type ErrorEventBuilder = {\n code: ErrorCode\n message?: string | null\n attributes?: Record<ErrorAttribute, unknown>\n causes?: Array<ErrorEvent>\n}\n\n// An exception type that contains an ErrorEvent\nexport class ErrorEventException extends Error {\n readonly errorEvent: ErrorEvent\n\n constructor(errorEvent: ErrorEvent, cause?: unknown) {\n super(errorEvent.message ?? '', { cause })\n this.name = this.constructor.name\n this.errorEvent = errorEvent\n }\n}\n\nexport const isErrorEvent = (throwable: Throwable): throwable is ErrorEvent => {\n if (!Objects.isObject(throwable)) {\n return false\n }\n\n return 'code' in throwable && 'message' in throwable && 'attributes' in throwable && 'causes' in throwable\n}\n\nexport const isErrorEventException = (throwable: Throwable): throwable is ErrorEventException => {\n return throwable instanceof ErrorEventException\n}\n\nexport const of = (builder: ErrorEventBuilder): ErrorEvent => {\n const code = builder.code\n\n return {\n code,\n message: builder.message ?? code,\n attributes: builder.attributes ?? {},\n causes: builder.causes ?? [],\n }\n}\n\nexport const from = (throwable: Throwable): ErrorEvent => {\n if (isErrorEvent(throwable)) {\n return throwable\n }\n\n if (!Errors.isError(throwable)) {\n return unhandled()\n }\n\n const errorEventException = Errors.findInCausalChain(throwable, isErrorEventException) as ErrorEventException | undefined\n if (Objects.isNil(errorEventException)) {\n return unhandled()\n }\n\n return errorEventException.errorEvent\n}\n\nexport const findByCodeInCausalChain = (error: ErrorEvent, code: string): ErrorEvent | undefined => {\n return findInCausalChain(error, (it) => it.code === code)\n}\n\n/*\n Traverses the causal chain of the ErrorEvent, searching for a predicate that matches (including matching on the parent error event)\n This is useful if you want to find whether or not a given error was caused by a specific failure. The search executes depth-first and\n will return te first matching instance that satisfies the predicate, or undefined otherwise\n */\nexport const findInCausalChain = (error: ErrorEvent, predicate: (error: ErrorEvent) => boolean): ErrorEvent | undefined => {\n if (predicate(error)) {\n return error\n }\n\n return Arrays.first(error.causes.map((it) => findInCausalChain(it, predicate)).filter(Objects.isPresent))\n}\n\nexport const aggregate = (builder: ErrorEventBuilder, causes: Array<ErrorEvent>): ErrorEvent | undefined => {\n if (causes.length === 0) {\n return undefined\n }\n\n return of({ ...builder, causes })\n}\n\nexport const UnhandledErrorCode: ErrorCode = 'error-event.unhandled'\nexport const NotFoundErrorCode: ErrorCode = 'error-event.not-found'\nexport const UnauthorizedErrorCode: ErrorCode = 'error-event.unauthorized'\n\nexport const RequestCorrelationIdAttribute: ErrorAttribute<string> = 'requestCorrelationId'\nexport const HttpStatusCodeAttribute: ErrorAttribute<number> = 'httpStatusCode'\n\nexport const unhandled = (builder?: ErrorEventBuilder) =>\n of(\n Objects.deepMerge(builder, {\n code: UnhandledErrorCode,\n message: 'An Unhandled Error has occurred.',\n attributes: { [HttpStatusCodeAttribute]: 500 },\n })\n )\n\nexport const notFound = (builder?: ErrorEventBuilder) =>\n of(\n Objects.deepMerge(builder, {\n code: NotFoundErrorCode,\n message: 'The requested Resource could not be found.',\n attributes: { [HttpStatusCodeAttribute]: 404 },\n })\n )\n\nexport const unauthorized = (builder?: ErrorEventBuilder) =>\n of(\n Objects.deepMerge(builder, {\n code: UnauthorizedErrorCode,\n message: 'The requested Resource requires authentication.',\n attributes: { [HttpStatusCodeAttribute]: 401 },\n })\n )\n"],"mappings":";AAAA,SAAS,QAAQ,QAAQ,SAAS,WAAW;AAWtC,IAAM,kBAAsC,IAAI,OAAO;AAGvD,IAAM,uBAAgD,IAAI,OAAO;AAExE,IAAM,uBAAuB,IAAI,OAAO;AAAA,EACtC,MAAM;AAAA,EACN,SAAS,IAAI,OAAO;AAAA,EACpB,YAAY,IAAI,OAAO,sBAAsB,IAAI,QAAQ,CAAC;AAC5D,CAAC;AAMD,IAAM,mBAAwC,qBAAqB,OAAO;AAAA,EACxE,QAAQ,IAAI,KAAK,MAAM,IAAI,MAAM,gBAAgB,CAAC;AACpD,CAAC;AAWM,IAAM,sBAAN,cAAkC,MAAM;AAAA,EACpC;AAAA,EAET,YAAY,YAAwB,OAAiB;AACnD,UAAM,WAAW,WAAW,IAAI,EAAE,MAAM,CAAC;AACzC,SAAK,OAAO,KAAK,YAAY;AAC7B,SAAK,aAAa;AAAA,EACpB;AACF;AAEO,IAAM,eAAe,CAAC,cAAkD;AAC7E,MAAI,CAAC,QAAQ,SAAS,SAAS,GAAG;AAChC,WAAO;AAAA,EACT;AAEA,SAAO,UAAU,aAAa,aAAa,aAAa,gBAAgB,aAAa,YAAY;AACnG;AAEO,IAAM,wBAAwB,CAAC,cAA2D;AAC/F,SAAO,qBAAqB;AAC9B;AAEO,IAAM,KAAK,CAAC,YAA2C;AAC5D,QAAM,OAAO,QAAQ;AAErB,SAAO;AAAA,IACL;AAAA,IACA,SAAS,QAAQ,WAAW;AAAA,IAC5B,YAAY,QAAQ,cAAc,CAAC;AAAA,IACnC,QAAQ,QAAQ,UAAU,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AACH;AAEK,IAAM,eAAe,CAAC,YAC3B;AAAA,EACE,QAAQ,UAAU,SAAS;AAAA,IACzB,MAAM;AAAA,IACN,SAAS;AAAA,IACT,YAAY,EAAE,CAAC,uBAAuB,GAAG,IAAI;AAAA,EAC/C,CAAC;AACH;","names":[]}
|
package/dist/zod.d.ts
CHANGED
@@ -3,6 +3,8 @@ import { ResourceKey } from '@bessemer/cornerstone/resource';
|
|
3
3
|
import { Entry } from '@bessemer/cornerstone/entry';
|
4
4
|
import { Result } from '@bessemer/cornerstone/result';
|
5
5
|
export type infer<T extends ZodType<any, any, any>> = Zod.infer<T>;
|
6
|
+
export type input<T extends ZodType<any, any, any>> = Zod.input<T>;
|
7
|
+
export type output<T extends ZodType<any, any, any>> = Zod.output<T>;
|
6
8
|
export declare const object: <T extends Zod.ZodRawShape>(shape: T, params?: Zod.RawCreateParams) => Zod.ZodObject<T, "strip", Zod.ZodTypeAny, Zod.objectOutputType<T, Zod.ZodTypeAny, "strip">, Zod.objectInputType<T, Zod.ZodTypeAny, "strip">>;
|
7
9
|
export declare const string: (params?: Zod.RawCreateParams & {
|
8
10
|
coerce?: true;
|
@@ -22,6 +24,8 @@ export declare const number: (params?: Zod.RawCreateParams & {
|
|
22
24
|
coerce?: boolean;
|
23
25
|
}) => Zod.ZodNumber;
|
24
26
|
export declare const tuple: <T extends [] | [Zod.ZodTypeAny, ...Zod.ZodTypeAny[]]>(schemas: T, params?: Zod.RawCreateParams) => Zod.ZodTuple<T, null>;
|
27
|
+
export declare const record: typeof Zod.ZodRecord.create;
|
28
|
+
export declare const lazy: <T extends Zod.ZodTypeAny>(getter: () => T, params?: Zod.RawCreateParams) => Zod.ZodLazy<T>;
|
25
29
|
export declare const arrayable: <T>(type: ZodType<T>) => Zod.ZodUnion<[Zod.ZodType<T, Zod.ZodTypeDef, T>, Zod.ZodArray<Zod.ZodType<T, Zod.ZodTypeDef, T>, "many">]>;
|
26
30
|
export declare const key: () => ZodType<ResourceKey>;
|
27
31
|
export declare const entry: <Value, Key = string>(value: ZodType<Value>, key?: ZodType<Key>) => ZodType<Entry<Value, Key>>;
|
package/dist/zod.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../src/zod.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,EAAE,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAA;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAA;AAEnD,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AAErD,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAClE,eAAO,MAAM,MAAM,qNAAa,CAAA;AAChC,eAAO,MAAM,MAAM;
|
1
|
+
{"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../src/zod.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,EAAE,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAA;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAA;AAEnD,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AAErD,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAClE,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAClE,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,OAAO,CAAC,GAAG,EAAE,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KAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAEnF,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,MAAM,KAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAOvF,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,MAAM,KAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAEtF,CAAA"}
|
package/dist/zod.js
CHANGED
@@ -12,6 +12,8 @@ var date = Zod.date;
|
|
12
12
|
var boolean = Zod.boolean;
|
13
13
|
var number = Zod.number;
|
14
14
|
var tuple = Zod.tuple;
|
15
|
+
var record = Zod.record;
|
16
|
+
var lazy = Zod.lazy;
|
15
17
|
var arrayable = (type) => {
|
16
18
|
return union([type, array(type)]);
|
17
19
|
};
|
@@ -49,6 +51,7 @@ export {
|
|
49
51
|
date,
|
50
52
|
entry,
|
51
53
|
key,
|
54
|
+
lazy,
|
52
55
|
nullType,
|
53
56
|
number,
|
54
57
|
object,
|
@@ -56,6 +59,7 @@ export {
|
|
56
59
|
parseJson,
|
57
60
|
parseJsonOrThrow,
|
58
61
|
parseOrThrow,
|
62
|
+
record,
|
59
63
|
string,
|
60
64
|
tuple,
|
61
65
|
undefined,
|
package/dist/zod.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/zod.ts"],"sourcesContent":["import Zod, { ZodType } from 'zod'\nimport { ResourceKey } from '@bessemer/cornerstone/resource'\nimport { Entry } from '@bessemer/cornerstone/entry'\nimport { Json, Results } from '@bessemer/cornerstone'\nimport { Result } from '@bessemer/cornerstone/result'\n\nexport type infer<T extends ZodType<any, any, any>> = Zod.infer<T>\nexport const object = Zod.object\nexport const string = Zod.string\nexport const union = Zod.union\nexport const array = Zod.array\nexport const unknown = Zod.unknown\nexport const nullType = Zod.null\nexport const undefined = Zod.undefined\nexport const date = Zod.date\nexport const boolean = Zod.boolean\nexport const number = Zod.number\nexport const tuple = Zod.tuple\n\nexport const arrayable = <T>(type: ZodType<T>) => {\n return union([type, array(type)])\n}\n\nexport const key = (): ZodType<ResourceKey> => {\n return string()\n}\n\nexport const entry = <Value, Key = string>(value: ZodType<Value>, key?: ZodType<Key>): ZodType<Entry<Value, Key>> => {\n return tuple([key ?? string(), value]) as ZodType<Entry<Value, Key>>\n}\n\nexport const parse = <T extends ZodType>(type: T, data: unknown): Result<Zod.infer<T>> => {\n const result = type.safeParse(data)\n if (result.success) {\n return Results.success(result.data)\n } else {\n return Results.failure(result.error)\n }\n}\n\nexport const parseOrThrow = <T extends ZodType>(type: T, data: unknown): Zod.infer<T> => {\n return Results.getValueOrThrow(parse(type, data))\n}\n\nexport const parseJson = <T extends ZodType>(type: T, data: string): Result<Zod.infer<T>> => {\n const result = Json.parse(data)\n if (!result.isSuccess) {\n return result\n }\n\n return parse(type, result.value)\n}\n\nexport const parseJsonOrThrow = <T extends ZodType>(type: T, data: string): Zod.infer<T> => {\n return parseJson(type, data)\n}\n"],"mappings":";AAAA,OAAO,SAAsB;AAG7B,SAAS,MAAM,eAAe;
|
1
|
+
{"version":3,"sources":["../src/zod.ts"],"sourcesContent":["import Zod, { ZodType } from 'zod'\nimport { ResourceKey } from '@bessemer/cornerstone/resource'\nimport { Entry } from '@bessemer/cornerstone/entry'\nimport { Json, Results } from '@bessemer/cornerstone'\nimport { Result } from '@bessemer/cornerstone/result'\n\nexport type infer<T extends ZodType<any, any, any>> = Zod.infer<T>\nexport type input<T extends ZodType<any, any, any>> = Zod.input<T>\nexport type output<T extends ZodType<any, any, any>> = Zod.output<T>\nexport const object = Zod.object\nexport const string = Zod.string\nexport const union = Zod.union\nexport const array = Zod.array\nexport const unknown = Zod.unknown\nexport const nullType = Zod.null\nexport const undefined = Zod.undefined\nexport const date = Zod.date\nexport const boolean = Zod.boolean\nexport const number = Zod.number\nexport const tuple = Zod.tuple\nexport const record = Zod.record\nexport const lazy = Zod.lazy\n\nexport const arrayable = <T>(type: ZodType<T>) => {\n return union([type, array(type)])\n}\n\nexport const key = (): ZodType<ResourceKey> => {\n return string()\n}\n\nexport const entry = <Value, Key = string>(value: ZodType<Value>, key?: ZodType<Key>): ZodType<Entry<Value, Key>> => {\n return tuple([key ?? string(), value]) as ZodType<Entry<Value, Key>>\n}\n\nexport const parse = <T extends ZodType>(type: T, data: unknown): Result<Zod.infer<T>> => {\n const result = type.safeParse(data)\n if (result.success) {\n return Results.success(result.data)\n } else {\n return Results.failure(result.error)\n }\n}\n\nexport const parseOrThrow = <T extends ZodType>(type: T, data: unknown): Zod.infer<T> => {\n return Results.getValueOrThrow(parse(type, data))\n}\n\nexport const parseJson = <T extends ZodType>(type: T, data: string): Result<Zod.infer<T>> => {\n const result = Json.parse(data)\n if (!result.isSuccess) {\n return result\n }\n\n return parse(type, result.value)\n}\n\nexport const parseJsonOrThrow = <T extends ZodType>(type: T, data: string): Zod.infer<T> => {\n return parseJson(type, data)\n}\n"],"mappings":";AAAA,OAAO,SAAsB;AAG7B,SAAS,MAAM,eAAe;AAMvB,IAAM,SAAS,IAAI;AACnB,IAAM,SAAS,IAAI;AACnB,IAAM,QAAQ,IAAI;AAClB,IAAM,QAAQ,IAAI;AAClB,IAAM,UAAU,IAAI;AACpB,IAAM,WAAW,IAAI;AACrB,IAAM,YAAY,IAAI;AACtB,IAAM,OAAO,IAAI;AACjB,IAAM,UAAU,IAAI;AACpB,IAAM,SAAS,IAAI;AACnB,IAAM,QAAQ,IAAI;AAClB,IAAM,SAAS,IAAI;AACnB,IAAM,OAAO,IAAI;AAEjB,IAAM,YAAY,CAAI,SAAqB;AAChD,SAAO,MAAM,CAAC,MAAM,MAAM,IAAI,CAAC,CAAC;AAClC;AAEO,IAAM,MAAM,MAA4B;AAC7C,SAAO,OAAO;AAChB;AAEO,IAAM,QAAQ,CAAsB,OAAuBA,SAAmD;AACnH,SAAO,MAAM,CAACA,QAAO,OAA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