@maestro-js/custom-errors 1.0.0-alpha.23 → 1.0.0-alpha.3

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 CHANGED
@@ -1,10 +1,8 @@
1
- declare function createMany<Entries extends Record<string, CustomErrors.CreateManyEntry>>(entries: Entries): CustomErrors.CreateManyErrors<Entries>;
2
- declare function makeCustomError<Input = undefined, AdditionalAttributes extends Record<string, any> = Input extends Record<string, any> ? Input : {}, StatusCode extends number | CustomErrors.HttpStatusCodeName | null | undefined = undefined>({ name, message, additionalAttributes, httpStatusCode, meta }: {
1
+ declare function makeCustomError<Input = undefined, AdditionalAttributes extends Record<string, any> = Input extends Record<string, any> ? Input : {}, StatusCode extends number | CustomErrors.HttpStatusCodeName | null | undefined = undefined>({ name, message, additionalAttributes, httpStatusCode }: {
3
2
  name?: string;
4
3
  message?: string | ((input: Input) => string) | null | undefined;
5
4
  additionalAttributes?: AdditionalAttributes | ((input: Input) => AdditionalAttributes) | null | undefined;
6
5
  httpStatusCode?: StatusCode;
7
- meta?: Record<string, unknown> | null | undefined;
8
6
  }): CustomErrors.CustomErrorConstructor<Input, AdditionalAttributes, StatusCode>;
9
7
  declare const httpStatusCodeNames: {
10
8
  readonly movedPermanently: 301;
@@ -24,7 +22,6 @@ declare const httpStatusCodeNames: {
24
22
  readonly internalServerError: 500;
25
23
  };
26
24
  declare function getHttpStatusCode(error: unknown): number | null;
27
- declare function getMeta(error: unknown): Record<string, unknown> | null;
28
25
  declare const MovedPermanentlyError: CustomErrors.CustomErrorConstructor<string | undefined, {}, "movedPermanently">;
29
26
  declare const FoundError: CustomErrors.CustomErrorConstructor<string | undefined, {}, "found">;
30
27
  declare const RedirectError: CustomErrors.CustomErrorConstructor<string | undefined, {}, "redirect">;
@@ -43,9 +40,7 @@ declare const InternalServerError: CustomErrors.CustomErrorConstructor<string |
43
40
 
44
41
  declare const CustomErrors: {
45
42
  create: typeof makeCustomError;
46
- createMany: typeof createMany;
47
43
  getHttpStatusCode: typeof getHttpStatusCode;
48
- getMeta: typeof getMeta;
49
44
  MovedPermanentlyError: CustomErrors.CustomErrorConstructor<string | undefined, {}, "movedPermanently">;
50
45
  FoundError: CustomErrors.CustomErrorConstructor<string | undefined, {}, "found">;
51
46
  RedirectError: CustomErrors.CustomErrorConstructor<string | undefined, {}, "redirect">;
@@ -74,25 +69,6 @@ declare namespace CustomErrors {
74
69
  readonly prototype: Error;
75
70
  };
76
71
  type HttpStatusCodeName = keyof typeof httpStatusCodeNames;
77
- type CreateManyEntry = {
78
- message?: string | ((input: any) => string) | null | undefined;
79
- additionalAttributes?: Record<string, any> | ((input: any) => Record<string, any>) | null | undefined;
80
- httpStatusCode: number | HttpStatusCodeName;
81
- meta?: Record<string, unknown> | null | undefined;
82
- };
83
- type CreateManyErrors<Entries extends Record<string, CreateManyEntry>> = {
84
- [Name in keyof Entries]: CustomErrorConstructor<CreateManyEntryInput<Entries[Name]>, CreateManyEntryAttributes<Entries[Name]>, Entries[Name]['httpStatusCode']>;
85
- };
86
- type CreateManyEntryInput<Entry extends CreateManyEntry> = Entry extends {
87
- message: (input: infer Input) => string;
88
- } ? Input : Entry extends {
89
- additionalAttributes: (input: infer Input) => Record<string, any>;
90
- } ? Input : undefined;
91
- type CreateManyEntryAttributes<Entry extends CreateManyEntry> = Entry extends {
92
- additionalAttributes: (input: any) => infer Attributes extends Record<string, any>;
93
- } ? Attributes : Entry extends {
94
- additionalAttributes: infer Attributes extends Record<string, any>;
95
- } ? Attributes : {};
96
72
  }
97
73
 
98
74
  export { BadRequestError, ConflictError, CustomErrors, ForbiddenError, FoundError, InternalServerError, LockedError, MovedPermanentlyError, NotFoundError, NotModifiedError, PaymentRequiredError, RedirectError, TooManyRequestsError, UnauthorizedError, UnprocessableContentError, ValidationError };
package/dist/index.js CHANGED
@@ -1,15 +1,9 @@
1
1
  // src/index.ts
2
- function createMany(entries) {
3
- return Object.fromEntries(
4
- Object.entries(entries).map(([name, entry]) => [name, makeCustomError({ ...entry, name })])
5
- );
6
- }
7
2
  function makeCustomError({
8
3
  name,
9
4
  message,
10
5
  additionalAttributes,
11
- httpStatusCode,
12
- meta
6
+ httpStatusCode
13
7
  }) {
14
8
  class MyError extends Error {
15
9
  constructor(input) {
@@ -31,9 +25,6 @@ function makeCustomError({
31
25
  if (name) {
32
26
  MyError.prototype.name = name;
33
27
  }
34
- if (meta != null) {
35
- MyError.prototype["meta"] = meta;
36
- }
37
28
  return MyError;
38
29
  }
39
30
  var httpStatusCodeNames = {
@@ -67,18 +58,6 @@ function getHttpStatusCode(error) {
67
58
  return null;
68
59
  }
69
60
  }
70
- function getMeta(error) {
71
- if (error instanceof Error) {
72
- const meta = error["meta"];
73
- if (typeof meta === "object" && meta !== null) {
74
- return meta;
75
- } else {
76
- return null;
77
- }
78
- } else {
79
- return null;
80
- }
81
- }
82
61
  var MovedPermanentlyError = makeCustomError({
83
62
  name: "MovedPermanentlyError",
84
63
  message: (input) => input ?? "Moved Permanently",
@@ -156,9 +135,7 @@ var InternalServerError = makeCustomError({
156
135
  });
157
136
  var CustomErrors = {
158
137
  create: makeCustomError,
159
- createMany,
160
138
  getHttpStatusCode,
161
- getMeta,
162
139
  MovedPermanentlyError,
163
140
  FoundError,
164
141
  RedirectError,
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "devDependencies": {
11
11
  "@types/node": "^22.19.11"
12
12
  },
13
- "version": "1.0.0-alpha.23",
13
+ "version": "1.0.0-alpha.3",
14
14
  "publishConfig": {
15
15
  "access": "restricted"
16
16
  },