@lowerdeck/error 1.0.6 → 1.0.8

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/package.json CHANGED
@@ -1,9 +1,15 @@
1
1
  {
2
2
  "name": "@lowerdeck/error",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
+ "files": [
8
+ "src/**",
9
+ "dist/**",
10
+ "README.md",
11
+ "package.json"
12
+ ],
7
13
  "author": "Tobias Herber",
8
14
  "license": "Apache 2",
9
15
  "type": "module",
@@ -21,15 +27,15 @@
21
27
  "scripts": {
22
28
  "test": "vitest run --passWithNoTests",
23
29
  "lint": "prettier src/**/*.ts --check",
24
- "build": "microbundle"
30
+ "build": "rm -rf ./dist && microbundle"
25
31
  },
26
32
  "dependencies": {
27
- "@lowerdeck/case": "^1.0.7",
28
- "@lowerdeck/validation": "^1.0.2"
33
+ "@lowerdeck/case": "^1.0.9",
34
+ "@lowerdeck/validation": "^1.0.4"
29
35
  },
30
36
  "devDependencies": {
31
37
  "microbundle": "^0.15.1",
32
- "@lowerdeck/tsconfig": "^1.0.0",
38
+ "@lowerdeck/tsconfig": "^1.0.1",
33
39
  "typescript": "5.8.2",
34
40
  "vitest": "^3.1.2"
35
41
  }
@@ -1,12 +0,0 @@
1
-
2
- $ microbundle
3
- No name was provided for external module '@lowerdeck/case' in output.globals – guessing '_case'
4
- Build "@lowerdeck/error" to dist:
5
- 2.02 kB: index.cjs.gz
6
- 1.73 kB: index.cjs.br
7
- 1332 B: index.module.js.gz
8
- 1080 B: index.module.js.br
9
- 2.03 kB: index.module.js.gz
10
- 1.73 kB: index.module.js.br
11
- 2.1 kB: index.umd.js.gz
12
- 1.79 kB: index.umd.js.br
@@ -1,21 +0,0 @@
1
-
2
- $ vitest run --passWithNoTests
3
- [?25l
4
-  RUN  v3.2.4 /Users/tobias/code/metorial/metorial-enterprise/oss/src/packages/shared/error
5
-
6
- [?2026h
7
-  ❯ src/defaultErrors.test.ts [queued]
8
-
9
-  Test Files 0 passed (2)
10
-  Tests 0 passed (0)
11
-  Start at 10:23:43
12
-  Duration 101ms
13
- [?2026l ✓ src/error.test.ts (6 tests) 2ms
14
- ✓ src/defaultErrors.test.ts (1 test) 1ms
15
-
16
-  Test Files  2 passed (2)
17
-  Tests  7 passed (7)
18
-  Start at  10:23:43
19
-  Duration  242ms (transform 57ms, setup 0ms, collect 75ms, tests 4ms, environment 0ms, prepare 83ms)
20
-
21
- [?25h
package/CHANGELOG.md DELETED
@@ -1,51 +0,0 @@
1
- # @lowerdeck/error
2
-
3
- ## 1.0.6
4
-
5
- ### Patch Changes
6
-
7
- - update versions
8
- - Updated dependencies
9
- - @lowerdeck/validation@1.0.2
10
- - @lowerdeck/case@1.0.7
11
-
12
- ## 1.0.5
13
-
14
- ### Patch Changes
15
-
16
- - sync
17
- - Updated dependencies
18
- - @lowerdeck/case@1.0.6
19
-
20
- ## 1.0.4
21
-
22
- ### Patch Changes
23
-
24
- - Fix dist
25
- - Updated dependencies
26
- - @lowerdeck/case@1.0.5
27
-
28
- ## 1.0.3
29
-
30
- ### Patch Changes
31
-
32
- - Fix versions
33
- - Updated dependencies
34
- - @lowerdeck/case@1.0.4
35
-
36
- ## 1.0.2
37
-
38
- ### Patch Changes
39
-
40
- - Update case
41
- - Updated dependencies
42
- - @lowerdeck/case@1.0.3
43
-
44
- ## 1.0.1
45
-
46
- ### Patch Changes
47
-
48
- - Fix exports
49
- - Updated dependencies
50
- - @lowerdeck/validation@1.0.1
51
- - @lowerdeck/case@1.0.1
@@ -1,2 +0,0 @@
1
- import{Cases as e}from"@lowerdeck/case";function t(){return t=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var r in s)({}).hasOwnProperty.call(s,r)&&(e[r]=s[r])}return e},t.apply(null,arguments)}let s=e=>Object.assign((r={})=>s(t({},e,r)),{__typename:"error",data:e,toResponse:()=>t({__typename:"error",ok:!1},e)});class r extends Error{get parent(){return this._parent}constructor(e){super(e.data.message),this.error=void 0,this.__typename="ServiceError",this._parent=null,this.error=e}setParent(e){return this._parent=e,this}get data(){return this.error.data}toResponse(){return this.error.toResponse()}static fromResponse(e){let t=e;return delete t.ok,delete t.__typename,new r(s(t))}}let o=e=>"ServiceError"===(null==e?void 0:e.__typename)||"ErrorRecord"===(null==e?void 0:e.__typename),a=e=>s(t({status:400,code:"invalid_data",message:"The provided data is invalid.",hint:"Make sure the data you are sending follows the specification outlined in the documentation."},e)),n=s({status:500,code:"internal_server_error",message:"An internal server error occurred."}),i=s({status:400,code:"bad_request",message:"The request is invalid."});function d(r,o){let a="string"==typeof r?r:r.entity,n="string"==typeof r?o:r.id;return s(t({status:404,code:"not_found",message:`The requested ${e.toKebabCase(a)} could not be found.`,hint:"Make sure the resource you are trying to access exists, that you have access to it and that it has not been deleted.",entity:a,id:null!=n?n:void 0},"string"==typeof r?{}:r))}let u=s({status:401,code:"unauthorized",message:"You are not authorized to access this resource.",hint:"Make sure you are logged in and have the correct permissions to access this resource."}),c=s({status:403,code:"forbidden",message:"You do not have permission to access this resource."}),l=s({status:400,code:"invalid_version",message:"The endpoint does not support the requested version."}),h=s({status:409,code:"conflict",message:"A similar resource already exists."}),m=s({status:410,code:"gone",message:"The requested resource is no longer available."}),p=s({status:402,code:"payment_required",message:"Payment is required to access this resource."}),g=s({status:412,code:"precondition_failed",message:"The precondition of the request failed."}),_=s({status:406,code:"not_acceptable",message:"The requested resource is not acceptable."}),y=s({status:501,code:"not_implemented",message:"The requested resource is not implemented."}),v=s({status:429,code:"too_many_requests",message:"You have made too many requests in a short period of time.",hint:"Please wait a moment and try again."}),f=s({status:504,code:"timeout",message:"The request timed out."}),q=s({status:405,code:"method_not_allowed",message:"The requested method is not allowed for this resource."});export{r as ServiceError,i as badRequestError,h as conflictError,s as createError,c as forbiddenError,m as goneError,n as internalServerError,l as invalidVersion,o as isServiceError,q as methodNotAllowedError,_ as notAcceptableError,d as notFoundError,y as notImplementedError,p as paymentRequiredError,g as preconditionFailedError,f as timeoutError,v as tooManyRequestsError,u as unauthorizedError,a as validationError};
2
- //# sourceMappingURL=index.modern.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.modern.js","sources":["../src/error.ts","../src/defaultErrors.ts"],"sourcesContent":["export interface ErrorData<Code extends string, Status extends number> {\n status: Status;\n code: Code;\n message: string;\n hint?: string;\n description?: string;\n reason?: string;\n [key: string]: any;\n}\n\nexport type ErrorRecord<Code extends string, Status extends number> = {\n __typename: 'error';\n data: ErrorData<Code, Status>;\n toResponse: () => ErrorData<Code, Status> & { __typename: 'error'; ok: false };\n} & ((extension?: Partial<ErrorData<Code, Status>>) => ErrorRecord<Code, Status>);\n\nexport let createError = <Code extends string, Status extends number>(\n data: ErrorData<Code, Status>\n): ErrorRecord<Code, Status> => {\n return Object.assign(\n (extension: Partial<ErrorData<Code, Status>> = {}): ErrorRecord<Code, Status> =>\n createError({\n ...data,\n ...extension\n }),\n {\n __typename: 'error' as const,\n data,\n toResponse: () => ({ __typename: 'error' as const, ok: false as const, ...data })\n }\n );\n};\n\nexport class ServiceError<InnerError extends ErrorRecord<any, any>> extends Error {\n __typename = 'ServiceError' as const;\n\n private _parent: Error | null = null;\n\n public get parent() {\n return this._parent;\n }\n\n constructor(private readonly error: InnerError) {\n super(error.data.message);\n }\n\n setParent(parent: Error) {\n this._parent = parent;\n return this;\n }\n\n get data() {\n return this.error.data;\n }\n\n toResponse() {\n return this.error.toResponse();\n }\n\n static fromResponse(raw: ErrorData<any, any>) {\n let data = raw;\n delete data.ok;\n delete data.__typename;\n\n return new ServiceError(createError(data));\n }\n}\n\nexport let isServiceError = (e: any): e is ServiceError<any> => {\n return e?.__typename === 'ServiceError' || e?.__typename === 'ErrorRecord';\n};\n","import { Cases } from '@lowerdeck/case';\nimport { ValidationError } from '@lowerdeck/validation';\nimport { ErrorData, createError } from './error';\n\nexport let validationError = (\n d: { errors: ValidationError[]; entity: string } & Partial<ErrorData<'invalid_data', 400>>\n) =>\n createError({\n status: 400,\n code: 'invalid_data',\n message: 'The provided data is invalid.',\n hint: 'Make sure the data you are sending follows the specification outlined in the documentation.',\n ...d\n });\n\nexport let internalServerError = createError({\n status: 500,\n code: 'internal_server_error',\n message: 'An internal server error occurred.'\n});\n\nexport let badRequestError = createError({\n status: 400,\n code: 'bad_request',\n message: 'The request is invalid.'\n});\n\nexport function notFoundError(p1: { entity: string; id?: string } & Partial<ErrorData<'not_found', 404>>): ReturnType<typeof createError>;\nexport function notFoundError(p1: string, p2?: string | null): ReturnType<typeof createError>;\nexport function notFoundError(p1: any, p2?: any): ReturnType<typeof createError> {\n let entity = typeof p1 == 'string' ? p1 : p1.entity;\n let id = typeof p1 == 'string' ? p2 : p1.id;\n\n return createError({\n status: 404,\n code: 'not_found',\n message: `The requested ${Cases.toKebabCase(entity)} could not be found.`,\n hint: 'Make sure the resource you are trying to access exists, that you have access to it and that it has not been deleted.',\n entity,\n id: id ?? undefined,\n\n ...(typeof p1 == 'string' ? {} : p1)\n });\n}\n\nexport let unauthorizedError = createError({\n status: 401,\n code: 'unauthorized',\n message: 'You are not authorized to access this resource.',\n hint: 'Make sure you are logged in and have the correct permissions to access this resource.'\n});\n\nexport let forbiddenError = createError({\n status: 403,\n code: 'forbidden',\n message: 'You do not have permission to access this resource.'\n});\n\nexport let invalidVersion = createError({\n status: 400,\n code: 'invalid_version',\n message: 'The endpoint does not support the requested version.'\n});\n\nexport let conflictError = createError({\n status: 409,\n code: 'conflict',\n message: 'A similar resource already exists.'\n});\n\nexport let goneError = createError({\n status: 410,\n code: 'gone',\n message: 'The requested resource is no longer available.'\n});\n\nexport let paymentRequiredError = createError({\n status: 402,\n code: 'payment_required',\n message: 'Payment is required to access this resource.'\n});\n\nexport let preconditionFailedError = createError({\n status: 412,\n code: 'precondition_failed',\n message: 'The precondition of the request failed.'\n});\n\nexport let notAcceptableError = createError({\n status: 406,\n code: 'not_acceptable',\n message: 'The requested resource is not acceptable.'\n});\n\nexport let notImplementedError = createError({\n status: 501,\n code: 'not_implemented',\n message: 'The requested resource is not implemented.'\n});\n\nexport let tooManyRequestsError = createError({\n status: 429,\n code: 'too_many_requests',\n message: 'You have made too many requests in a short period of time.',\n hint: 'Please wait a moment and try again.'\n});\n\nexport let timeoutError = createError({\n status: 504,\n code: 'timeout',\n message: 'The request timed out.'\n});\n\nexport let methodNotAllowedError = createError({\n status: 405,\n code: 'method_not_allowed',\n message: 'The requested method is not allowed for this resource.'\n});\n"],"names":["createError","data","Object","assign","extension","_extends","__typename","toResponse","ok","ServiceError","Error","parent","this","_parent","constructor","error","super","message","setParent","fromResponse","raw","isServiceError","e","validationError","d","status","code","hint","internalServerError","badRequestError","notFoundError","p1","p2","entity","id","Cases","toKebabCase","undefined","unauthorizedError","forbiddenError","invalidVersion","conflictError","goneError","paymentRequiredError","preconditionFailedError","notAcceptableError","notImplementedError","tooManyRequestsError","timeoutError","methodNotAllowedError"],"mappings":"gQAgBW,IAAAA,EACTC,GAEOC,OAAOC,OACZ,CAACC,EAA8C,CAAA,IAC7CJ,EAAWK,EACNJ,CAAAA,EAAAA,EACAG,IAEP,CACEE,WAAY,QACZL,OACAM,WAAYA,IAAAF,EAAA,CAASC,WAAY,QAAkBE,IAAI,GAAmBP,WAKnEQ,UAA+DC,MAK1E,UAAWC,GACT,OAAWC,KAACC,OACd,CAEAC,WAAAA,CAA6BC,GAC3BC,MAAMD,EAAMd,KAAKgB,SAASL,KADCG,WAR7BT,EAAAA,KAAAA,WAAa,eAELO,KAAAA,QAAwB,KAMHD,KAAKG,MAALA,CAE7B,CAEAG,SAAAA,CAAUP,GAER,OADAC,KAAKC,QAAUF,EAEjBC,IAAA,CAEA,QAAIX,GACF,OAAOW,KAAKG,MAAMd,IACpB,CAEAM,UAAAA,GACE,OAAOK,KAAKG,MAAMR,YACpB,CAEA,mBAAOY,CAAaC,GAClB,IAAInB,EAAOmB,EAIX,cAHOnB,EAAKO,UACLP,EAAKK,WAE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CyB,OAAQ,IACRC,KAAM,kBACNT,QAAS,+CAGA8B,EAAuB/C,EAAY,CAC5CyB,OAAQ,IACRC,KAAM,oBACNT,QAAS,6DACTU,KAAM,wCAGGqB,EAAehD,EAAY,CACpCyB,OAAQ,IACRC,KAAM,UACNT,QAAS,2BAGAgC,EAAwBjD,EAAY,CAC7CyB,OAAQ,IACRC,KAAM,qBACNT,QAAS"}
package/tsconfig.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "$schema": "https://json.schemastore.org/tsconfig",
3
- "extends": "@lowerdeck/tsconfig/base.json",
4
- "exclude": ["dist"],
5
- "include": ["src"],
6
- "compilerOptions": {
7
- "outDir": "dist",
8
- "lib": ["es2021"],
9
- "target": "ES2019"
10
- }
11
- }