@bessemer/cornerstone 0.5.39 → 0.5.41

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.
@@ -1,16 +1,15 @@
1
- import { Zod } from '@bessemer/cornerstone';
2
1
  import { NominalType, Throwable } from '@bessemer/cornerstone/types';
3
2
  import { RecordAttribute } from '@bessemer/cornerstone/object';
4
- import { ZodType } from 'zod';
3
+ import Zod, { ZodType } from 'zod';
5
4
  export type ErrorCode = NominalType<string, 'ErrorCode'>;
6
5
  export declare const ErrorCodeSchema: ZodType<ErrorCode>;
7
6
  export type ErrorAttribute<Type = unknown> = RecordAttribute<Type, 'ErrorAttribute'>;
8
7
  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, {
8
+ declare const baseErrorEventSchema: Zod.ZodObject<{
9
+ code: Zod.ZodType<ErrorCode, Zod.ZodTypeDef, ErrorCode>;
10
+ message: Zod.ZodString;
11
+ attributes: Zod.ZodRecord<Zod.ZodType<ErrorAttribute<unknown>, Zod.ZodTypeDef, ErrorAttribute<unknown>>, Zod.ZodUnknown>;
12
+ }, "strip", Zod.ZodTypeAny, {
14
13
  code: string & import("@bessemer/cornerstone/types").NominalTyping<"ErrorCode">;
15
14
  message: string;
16
15
  attributes: Record<ErrorAttribute<unknown>, unknown>;
@@ -1 +1 @@
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,6BA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AE,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"}
@@ -1,5 +1,6 @@
1
1
  // src/error-event.ts
2
- import { Arrays, Errors, Objects, Zod } from "@bessemer/cornerstone";
2
+ import { Arrays, Errors, Objects } from "@bessemer/cornerstone";
3
+ import Zod from "zod";
3
4
  var ErrorCodeSchema = Zod.string();
4
5
  var ErrorAttributeSchema = Zod.string();
5
6
  var baseErrorEventSchema = Zod.object({
@@ -1 +1 @@
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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AAI,UAAU,KAAK,GAAG;AACpB,WAAO;AAAA,EACT;AAEA,SAAO,OAAO,MAAM,MAAM,OAAO,IAAI,CAAC,OAAO,kBAAkB,IAAI,SAAS,CAAC,EAAE,OAAO,QAAQ,SAAS,CAAC;AAC1G;AAEO,IAAM,YAAY,CAAC,SAA4B,WAAsD;AAC1G,MAAI,OAAO,WAAW,GAAG;AACvB,WAAO;AAAA,EACT;AAEA,SAAO,GAAG,EAAE,GAAG,SAAS,OAAO,CAAC;AAClC;AAEO,IAAM,qBAAgC;AACtC,IAAM,oBAA+B;AACrC,IAAM,wBAAmC;AAEzC,IAAM,gCAAwD;AAC9D,IAAM,0BAAkD;AAExD,IAAM,YAAY,CAAC,YACxB;AAAA,EACE,QAAQ,UAAU,SAAS;AAAA,IACzB,MAAM;AAAA,IACN,SAAS;AAAA,IACT,YAAY,EAAE,CAAC,uBAAuB,GAAG,IAAI;AAAA,EAC/C,CAAC;AACH;AAEK,IAAM,WAAW,CAAC,YACvB;AAAA,EACE,QAAQ,UAAU,SAAS;AAAA,IACzB,MAAM;AAAA,IACN,SAAS;AAAA,IACT,YAAY,EAAE,CAAC,uBAAuB,GAAG,IAAI;AAAA,EAC/C,CAAC;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":[]}
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'\nimport Zod, { 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,eAAe;A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U;AAAA,EACnB;AAEA,SAAO,oBAAoB;AAC7B;AAEO,IAAM,0BAA0B,CAAC,OAAmB,SAAyC;AAClG,SAAO,kBAAkB,OAAO,CAAC,OAAO,GAAG,SAAS,IAAI;AAC1D;AAOO,IAAM,oBAAoB,CAAC,OAAmB,cAAsE;AACzH,MAAI,UAAU,KAAK,GAAG;AACpB,WAAO;AAAA,EACT;AAEA,SAAO,OAAO,MAAM,MAAM,OAAO,IAAI,CAAC,OAAO,kBAAkB,IAAI,SAAS,CAAC,EAAE,OAAO,QAAQ,SAAS,CAAC;AAC1G;AAEO,IAAM,YAAY,CAAC,SAA4B,WAAsD;AAC1G,MAAI,OAAO,WAAW,GAAG;AACvB,WAAO;AAAA,EACT;AAEA,SAAO,GAAG,EAAE,GAAG,SAAS,OAAO,CAAC;AAClC;AAEO,IAAM,qBAAgC;AACtC,IAAM,oBAA+B;AACrC,IAAM,wBAAmC;AAEzC,IAAM,gCAAwD;AAC9D,IAAM,0BAAkD;AAExD,IAAM,YAAY,CAAC,YACxB;AAAA,EACE,QAAQ,UAAU,SAAS;AAAA,IACzB,MAAM;AAAA,IACN,SAAS;AAAA,IACT,YAAY,EAAE,CAAC,uBAAuB,GAAG,IAAI;AAAA,EAC/C,CAAC;AACH;AAEK,IAAM,WAAW,CAAC,YACvB;AAAA,EACE,QAAQ,UAAU,SAAS;AAAA,IACzB,MAAM;AAAA,IACN,SAAS;AAAA,IACT,YAAY,EAAE,CAAC,uBAAuB,GAAG,IAAI;AAAA,EAC/C,CAAC;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/types.d.ts CHANGED
@@ -3,6 +3,7 @@ export interface NominalTyping<NominalTypingT> {
3
3
  _type?: NominalTypingT;
4
4
  }
5
5
  export type NominalType<T, NominalTypingT> = T & NominalTyping<NominalTypingT>;
6
+ export type Alias<T> = NominalType<T, any>;
6
7
  export type TaggedTyping<TaggedTypingT extends string | number | symbol> = {
7
8
  [ZODBRAND]: {
8
9
  [k in TaggedTypingT]: true;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,QAAQ,EAAE,MAAM,KAAK,CAAA;AAEvC,MAAM,WAAW,aAAa,CAAC,cAAc;IAC3C,KAAK,CAAC,EAAE,cAAc,CAAA;CACvB;AAED,MAAM,MAAM,WAAW,CAAC,CAAC,EAAE,cAAc,IAAI,CAAC,GAAG,aAAa,CAAC,cAAc,CAAC,CAAA;AAE9E,MAAM,MAAM,YAAY,CAAC,aAAa,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,IAAI;IACzE,CAAC,QAAQ,CAAC,EAAE;SACT,CAAC,IAAI,aAAa,GAAG,IAAI;KAC3B,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,aAAa,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,YAAY,CAAC,aAAa,CAAC,CAAA;AAE3G,MAAM,MAAM,SAAS,GAAG,OAAO,CAAA;AAE/B,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;AAE7C,MAAM,MAAM,GAAG,GAAG,IAAI,GAAG,SAAS,CAAA;AAElC,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;KAC1B,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,SAAS,GAAG,WAAW,CAAC,CAAC,CAAC,CA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AAA;AAE5B,eAAO,MAAM,SAAS,GAAI,CAAC,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,+GAE5C,CAAA;AAED,eAAO,MAAM,GAAG,QAAO,OAAO,CAAC,WAAW,CAEzC,CAAA;AAED,eAAO,MAAM,KAAK,GAAI,KAAK,EAAE,GAAG,GAAG,MAAM,EAAE,OAAO,OAAO,CAAC,KAAK,CAAC,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,KAAG,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAE/G,CAAA;AAED,eAAO,MAAM,KAAK,GAAI,CAAC,SAAS,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,OAAO,KAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAOpF,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,OAAO,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
@@ -1,6 +1,7 @@
1
1
  // src/zod.ts
2
2
  import Zod from "zod";
3
- import { Json, Results } from "@bessemer/cornerstone";
3
+ import { parse as jsonParse } from "@bessemer/cornerstone/json";
4
+ import { failure, getValueOrThrow, success } from "@bessemer/cornerstone/result";
4
5
  var object = Zod.object;
5
6
  var string = Zod.string;
6
7
  var union = Zod.union;
@@ -26,16 +27,16 @@ var entry = (value, key2) => {
26
27
  var parse = (type, data) => {
27
28
  const result = type.safeParse(data);
28
29
  if (result.success) {
29
- return Results.success(result.data);
30
+ return success(result.data);
30
31
  } else {
31
- return Results.failure(result.error);
32
+ return failure(result.error);
32
33
  }
33
34
  };
34
35
  var parseOrThrow = (type, data) => {
35
- return Results.getValueOrThrow(parse(type, data));
36
+ return getValueOrThrow(parse(type, data));
36
37
  };
37
38
  var parseJson = (type, data) => {
38
- const result = Json.parse(data);
39
+ const result = jsonParse(data);
39
40
  if (!result.isSuccess) {
40
41
  return result;
41
42
  }
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 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,OAAO,GAAG,KAAK,CAAC;AACvC;AAEO,IAAM,QAAQ,CAAoB,MAAS,SAAwC;AACxF,QAAM,SAAS,KAAK,UAAU,IAAI;AAClC,MAAI,OAAO,SAAS;AAClB,WAAO,QAAQ,QAAQ,OAAO,IAAI;AAAA,EACpC,OAAO;AACL,WAAO,QAAQ,QAAQ,OAAO,KAAK;AAAA,EACrC;AACF;AAEO,IAAM,eAAe,CAAoB,MAAS,SAAgC;AACvF,SAAO,QAAQ,gBAAgB,MAAM,MAAM,IAAI,CAAC;AAClD;AAEO,IAAM,YAAY,CAAoB,MAAS,SAAuC;AAC3F,QAAM,SAAS,KAAK,MAAM,IAAI;AAC9B,MAAI,CAAC,OAAO,WAAW;AACrB,WAAO;AAAA,EACT;AAEA,SAAO,MAAM,MAAM,OAAO,KAAK;AACjC;AAEO,IAAM,mBAAmB,CAAoB,MAAS,SAA+B;AAC1F,SAAO,UAAU,MAAM,IAAI;AAC7B;","names":["key"]}
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 { parse as jsonParse } from '@bessemer/cornerstone/json'\nimport { failure, getValueOrThrow, Result, success } 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 success(result.data)\n } else {\n return failure(result.error)\n }\n}\n\nexport const parseOrThrow = <T extends ZodType>(type: T, data: unknown): Zod.infer<T> => {\n return getValueOrThrow(parse(type, data))\n}\n\nexport const parseJson = <T extends ZodType>(type: T, data: string): Result<Zod.infer<T>> => {\n const result = jsonParse(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,SAAS,iBAAiB;AACnC,SAAS,SAAS,iBAAyB,eAAe;AAKnD,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,OAAO,GAAG,KAAK,CAAC;AACvC;AAEO,IAAM,QAAQ,CAAoB,MAAS,SAAwC;AACxF,QAAM,SAAS,KAAK,UAAU,IAAI;AAClC,MAAI,OAAO,SAAS;AAClB,WAAO,QAAQ,OAAO,IAAI;AAAA,EAC5B,OAAO;AACL,WAAO,QAAQ,OAAO,KAAK;AAAA,EAC7B;AACF;AAEO,IAAM,eAAe,CAAoB,MAAS,SAAgC;AACvF,SAAO,gBAAgB,MAAM,MAAM,IAAI,CAAC;AAC1C;AAEO,IAAM,YAAY,CAAoB,MAAS,SAAuC;AAC3F,QAAM,SAAS,UAAU,IAAI;AAC7B,MAAI,CAAC,OAAO,WAAW;AACrB,WAAO;AAAA,EACT;AAEA,SAAO,MAAM,MAAM,OAAO,KAAK;AACjC;AAEO,IAAM,mBAAmB,CAAoB,MAAS,SAA+B;AAC1F,SAAO,UAAU,MAAM,IAAI;AAC7B;","names":["key"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bessemer/cornerstone",
3
3
  "type": "module",
4
- "version": "0.5.39",
4
+ "version": "0.5.41",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "sideEffects": false,