@shware/http 0.2.7 → 0.2.9

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.
Files changed (73) hide show
  1. package/dist/__tests__/index.test.cjs +27 -0
  2. package/dist/__tests__/index.test.cjs.map +1 -0
  3. package/dist/__tests__/index.test.d.cts +2 -0
  4. package/dist/__tests__/index.test.d.ts +2 -0
  5. package/dist/__tests__/index.test.mjs +25 -0
  6. package/dist/__tests__/index.test.mjs.map +1 -0
  7. package/dist/detail.cjs +93 -0
  8. package/dist/detail.cjs.map +1 -0
  9. package/dist/detail.d.cts +101 -0
  10. package/dist/detail.d.ts +101 -0
  11. package/dist/detail.mjs +67 -0
  12. package/dist/detail.mjs.map +1 -0
  13. package/dist/hono/geolocation.cjs +59 -0
  14. package/dist/hono/geolocation.cjs.map +1 -0
  15. package/dist/hono/geolocation.d.cts +21 -0
  16. package/dist/hono/geolocation.d.ts +21 -0
  17. package/dist/hono/geolocation.mjs +33 -0
  18. package/dist/hono/geolocation.mjs.map +1 -0
  19. package/dist/hono/handler.cjs +42 -0
  20. package/dist/hono/handler.cjs.map +1 -0
  21. package/dist/hono/handler.d.cts +11 -0
  22. package/dist/hono/handler.d.ts +11 -0
  23. package/dist/hono/handler.mjs +17 -0
  24. package/dist/hono/handler.mjs.map +1 -0
  25. package/dist/hono/index.cjs +39 -0
  26. package/dist/hono/index.cjs.map +1 -0
  27. package/dist/hono/index.d.cts +8 -0
  28. package/dist/hono/index.d.ts +8 -0
  29. package/dist/hono/index.mjs +11 -0
  30. package/dist/hono/index.mjs.map +1 -0
  31. package/dist/hono/validator.cjs +44 -0
  32. package/dist/hono/validator.cjs.map +1 -0
  33. package/dist/hono/validator.d.cts +26 -0
  34. package/dist/hono/validator.d.ts +26 -0
  35. package/dist/hono/validator.mjs +19 -0
  36. package/dist/hono/validator.mjs.map +1 -0
  37. package/dist/index.cjs +13 -387
  38. package/dist/index.cjs.map +1 -1
  39. package/dist/index.d.cts +6 -269
  40. package/dist/index.d.ts +6 -269
  41. package/dist/index.mjs +6 -370
  42. package/dist/index.mjs.map +1 -1
  43. package/dist/message.cjs +32 -0
  44. package/dist/message.cjs.map +1 -0
  45. package/dist/message.d.cts +3 -0
  46. package/dist/message.d.ts +3 -0
  47. package/dist/message.mjs +7 -0
  48. package/dist/message.mjs.map +1 -0
  49. package/dist/reason.cjs +19 -0
  50. package/dist/reason.cjs.map +1 -0
  51. package/dist/reason.d.cts +66 -0
  52. package/dist/reason.d.ts +66 -0
  53. package/dist/reason.mjs +1 -0
  54. package/dist/reason.mjs.map +1 -0
  55. package/dist/snowflake.cjs +75 -0
  56. package/dist/snowflake.cjs.map +1 -0
  57. package/dist/snowflake.d.cts +29 -0
  58. package/dist/snowflake.d.ts +29 -0
  59. package/dist/snowflake.mjs +49 -0
  60. package/dist/snowflake.mjs.map +1 -0
  61. package/dist/status.cjs +266 -0
  62. package/dist/status.cjs.map +1 -0
  63. package/dist/status.d.cts +69 -0
  64. package/dist/status.d.ts +69 -0
  65. package/dist/status.mjs +237 -0
  66. package/dist/status.mjs.map +1 -0
  67. package/dist/vaild.cjs +51 -0
  68. package/dist/vaild.cjs.map +1 -0
  69. package/dist/vaild.d.cts +13 -0
  70. package/dist/vaild.d.ts +13 -0
  71. package/dist/vaild.mjs +26 -0
  72. package/dist/vaild.mjs.map +1 -0
  73. package/package.json +14 -1
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/snowflake.ts
21
+ var snowflake_exports = {};
22
+ __export(snowflake_exports, {
23
+ UidGenerator: () => UidGenerator,
24
+ uid: () => uid
25
+ });
26
+ module.exports = __toCommonJS(snowflake_exports);
27
+ function getNextMillisecond(timestamp) {
28
+ let now = BigInt(Date.now());
29
+ while (now < timestamp) {
30
+ now = BigInt(Date.now());
31
+ }
32
+ return now;
33
+ }
34
+ var UidGenerator = class {
35
+ MAX = (1n << 63n) - 1n;
36
+ machineBits = BigInt(10);
37
+ sequenceBits = BigInt(12);
38
+ epochMillisecond = BigInt(1577808e6);
39
+ // 2020-1-1 00:00:00
40
+ sequenceMask = ~(BigInt(-1) << this.sequenceBits);
41
+ maxMachineId = ~(BigInt(-1) << this.machineBits);
42
+ machineIdShift = this.sequenceBits;
43
+ timeStampShift = this.machineBits + this.sequenceBits;
44
+ machineId;
45
+ sequence = BigInt(0);
46
+ lastTimestamp = BigInt(-1);
47
+ constructor(mackineId) {
48
+ this.machineId = BigInt(mackineId) % this.maxMachineId;
49
+ }
50
+ next = () => {
51
+ let timestamp = BigInt(Date.now());
52
+ if (timestamp < this.lastTimestamp) {
53
+ console.error(`Clock moved backwards. time gap = ${this.lastTimestamp - timestamp}`);
54
+ timestamp = getNextMillisecond(this.lastTimestamp);
55
+ }
56
+ if (timestamp === this.lastTimestamp) {
57
+ this.sequence = this.sequence + BigInt(1) & this.sequenceMask;
58
+ if (this.sequence === BigInt(0)) {
59
+ timestamp = getNextMillisecond(timestamp);
60
+ }
61
+ } else {
62
+ this.sequence = BigInt(0);
63
+ }
64
+ this.lastTimestamp = timestamp;
65
+ return timestamp - this.epochMillisecond << this.timeStampShift | this.machineId << this.machineIdShift | this.sequence;
66
+ };
67
+ };
68
+ var machineId = Math.floor(Math.random() * 1024);
69
+ var uid = new UidGenerator(machineId);
70
+ // Annotate the CommonJS export names for ESM import in node:
71
+ 0 && (module.exports = {
72
+ UidGenerator,
73
+ uid
74
+ });
75
+ //# sourceMappingURL=snowflake.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/snowflake.ts"],"sourcesContent":["/**\n * A distributed unique ID generator inspired by Twitter's Snowflake.\n *\n * ID data bits:\n * +----------------------+----------------+-----------+\n * | delta millisecond | machine id | sequence |\n * +----------------------+----------------+-----------+\n * | 41bits | 10bits | 12bits |\n * +----------------------+----------------+-----------+\n *\n */\n\nfunction getNextMillisecond(timestamp: bigint) {\n let now = BigInt(Date.now());\n while (now < timestamp) {\n now = BigInt(Date.now());\n }\n return now;\n}\n\nexport class UidGenerator {\n public readonly MAX = (1n << 63n) - 1n;\n private readonly machineBits = BigInt(10);\n private readonly sequenceBits = BigInt(12);\n private readonly epochMillisecond = BigInt(1577808000000); // 2020-1-1 00:00:00\n private readonly sequenceMask = ~(BigInt(-1) << this.sequenceBits);\n private readonly maxMachineId = ~(BigInt(-1) << this.machineBits);\n private readonly machineIdShift = this.sequenceBits;\n private readonly timeStampShift = this.machineBits + this.sequenceBits;\n private readonly machineId: bigint;\n private sequence = BigInt(0);\n private lastTimestamp = BigInt(-1);\n\n constructor(mackineId: number) {\n this.machineId = BigInt(mackineId) % this.maxMachineId;\n }\n\n public readonly next = (): bigint => {\n let timestamp = BigInt(Date.now());\n if (timestamp < this.lastTimestamp) {\n console.error(`Clock moved backwards. time gap = ${this.lastTimestamp - timestamp}`);\n timestamp = getNextMillisecond(this.lastTimestamp);\n }\n if (timestamp === this.lastTimestamp) {\n this.sequence = (this.sequence + BigInt(1)) & this.sequenceMask;\n if (this.sequence === BigInt(0)) {\n timestamp = getNextMillisecond(timestamp);\n }\n } else {\n this.sequence = BigInt(0);\n }\n this.lastTimestamp = timestamp;\n return (\n ((timestamp - this.epochMillisecond) << this.timeStampShift) |\n (this.machineId << this.machineIdShift) |\n this.sequence\n );\n };\n}\n\nconst machineId = Math.floor(Math.random() * 1024);\nexport const uid = new UidGenerator(machineId);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,SAAS,mBAAmB,WAAmB;AAC7C,MAAI,MAAM,OAAO,KAAK,IAAI,CAAC;AAC3B,SAAO,MAAM,WAAW;AACtB,UAAM,OAAO,KAAK,IAAI,CAAC;AAAA,EACzB;AACA,SAAO;AACT;AAEO,IAAM,eAAN,MAAmB;AAAA,EACR,OAAO,MAAM,OAAO;AAAA,EACnB,cAAc,OAAO,EAAE;AAAA,EACvB,eAAe,OAAO,EAAE;AAAA,EACxB,mBAAmB,OAAO,SAAa;AAAA;AAAA,EACvC,eAAe,EAAE,OAAO,EAAE,KAAK,KAAK;AAAA,EACpC,eAAe,EAAE,OAAO,EAAE,KAAK,KAAK;AAAA,EACpC,iBAAiB,KAAK;AAAA,EACtB,iBAAiB,KAAK,cAAc,KAAK;AAAA,EACzC;AAAA,EACT,WAAW,OAAO,CAAC;AAAA,EACnB,gBAAgB,OAAO,EAAE;AAAA,EAEjC,YAAY,WAAmB;AAC7B,SAAK,YAAY,OAAO,SAAS,IAAI,KAAK;AAAA,EAC5C;AAAA,EAEgB,OAAO,MAAc;AACnC,QAAI,YAAY,OAAO,KAAK,IAAI,CAAC;AACjC,QAAI,YAAY,KAAK,eAAe;AAClC,cAAQ,MAAM,qCAAqC,KAAK,gBAAgB,SAAS,EAAE;AACnF,kBAAY,mBAAmB,KAAK,aAAa;AAAA,IACnD;AACA,QAAI,cAAc,KAAK,eAAe;AACpC,WAAK,WAAY,KAAK,WAAW,OAAO,CAAC,IAAK,KAAK;AACnD,UAAI,KAAK,aAAa,OAAO,CAAC,GAAG;AAC/B,oBAAY,mBAAmB,SAAS;AAAA,MAC1C;AAAA,IACF,OAAO;AACL,WAAK,WAAW,OAAO,CAAC;AAAA,IAC1B;AACA,SAAK,gBAAgB;AACrB,WACI,YAAY,KAAK,oBAAqB,KAAK,iBAC5C,KAAK,aAAa,KAAK,iBACxB,KAAK;AAAA,EAET;AACF;AAEA,IAAM,YAAY,KAAK,MAAM,KAAK,OAAO,IAAI,IAAI;AAC1C,IAAM,MAAM,IAAI,aAAa,SAAS;","names":[]}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * A distributed unique ID generator inspired by Twitter's Snowflake.
3
+ *
4
+ * ID data bits:
5
+ * +----------------------+----------------+-----------+
6
+ * | delta millisecond | machine id | sequence |
7
+ * +----------------------+----------------+-----------+
8
+ * | 41bits | 10bits | 12bits |
9
+ * +----------------------+----------------+-----------+
10
+ *
11
+ */
12
+ declare class UidGenerator {
13
+ readonly MAX: bigint;
14
+ private readonly machineBits;
15
+ private readonly sequenceBits;
16
+ private readonly epochMillisecond;
17
+ private readonly sequenceMask;
18
+ private readonly maxMachineId;
19
+ private readonly machineIdShift;
20
+ private readonly timeStampShift;
21
+ private readonly machineId;
22
+ private sequence;
23
+ private lastTimestamp;
24
+ constructor(mackineId: number);
25
+ readonly next: () => bigint;
26
+ }
27
+ declare const uid: UidGenerator;
28
+
29
+ export { UidGenerator, uid };
@@ -0,0 +1,29 @@
1
+ /**
2
+ * A distributed unique ID generator inspired by Twitter's Snowflake.
3
+ *
4
+ * ID data bits:
5
+ * +----------------------+----------------+-----------+
6
+ * | delta millisecond | machine id | sequence |
7
+ * +----------------------+----------------+-----------+
8
+ * | 41bits | 10bits | 12bits |
9
+ * +----------------------+----------------+-----------+
10
+ *
11
+ */
12
+ declare class UidGenerator {
13
+ readonly MAX: bigint;
14
+ private readonly machineBits;
15
+ private readonly sequenceBits;
16
+ private readonly epochMillisecond;
17
+ private readonly sequenceMask;
18
+ private readonly maxMachineId;
19
+ private readonly machineIdShift;
20
+ private readonly timeStampShift;
21
+ private readonly machineId;
22
+ private sequence;
23
+ private lastTimestamp;
24
+ constructor(mackineId: number);
25
+ readonly next: () => bigint;
26
+ }
27
+ declare const uid: UidGenerator;
28
+
29
+ export { UidGenerator, uid };
@@ -0,0 +1,49 @@
1
+ // src/snowflake.ts
2
+ function getNextMillisecond(timestamp) {
3
+ let now = BigInt(Date.now());
4
+ while (now < timestamp) {
5
+ now = BigInt(Date.now());
6
+ }
7
+ return now;
8
+ }
9
+ var UidGenerator = class {
10
+ MAX = (1n << 63n) - 1n;
11
+ machineBits = BigInt(10);
12
+ sequenceBits = BigInt(12);
13
+ epochMillisecond = BigInt(1577808e6);
14
+ // 2020-1-1 00:00:00
15
+ sequenceMask = ~(BigInt(-1) << this.sequenceBits);
16
+ maxMachineId = ~(BigInt(-1) << this.machineBits);
17
+ machineIdShift = this.sequenceBits;
18
+ timeStampShift = this.machineBits + this.sequenceBits;
19
+ machineId;
20
+ sequence = BigInt(0);
21
+ lastTimestamp = BigInt(-1);
22
+ constructor(mackineId) {
23
+ this.machineId = BigInt(mackineId) % this.maxMachineId;
24
+ }
25
+ next = () => {
26
+ let timestamp = BigInt(Date.now());
27
+ if (timestamp < this.lastTimestamp) {
28
+ console.error(`Clock moved backwards. time gap = ${this.lastTimestamp - timestamp}`);
29
+ timestamp = getNextMillisecond(this.lastTimestamp);
30
+ }
31
+ if (timestamp === this.lastTimestamp) {
32
+ this.sequence = this.sequence + BigInt(1) & this.sequenceMask;
33
+ if (this.sequence === BigInt(0)) {
34
+ timestamp = getNextMillisecond(timestamp);
35
+ }
36
+ } else {
37
+ this.sequence = BigInt(0);
38
+ }
39
+ this.lastTimestamp = timestamp;
40
+ return timestamp - this.epochMillisecond << this.timeStampShift | this.machineId << this.machineIdShift | this.sequence;
41
+ };
42
+ };
43
+ var machineId = Math.floor(Math.random() * 1024);
44
+ var uid = new UidGenerator(machineId);
45
+ export {
46
+ UidGenerator,
47
+ uid
48
+ };
49
+ //# sourceMappingURL=snowflake.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/snowflake.ts"],"sourcesContent":["/**\n * A distributed unique ID generator inspired by Twitter's Snowflake.\n *\n * ID data bits:\n * +----------------------+----------------+-----------+\n * | delta millisecond | machine id | sequence |\n * +----------------------+----------------+-----------+\n * | 41bits | 10bits | 12bits |\n * +----------------------+----------------+-----------+\n *\n */\n\nfunction getNextMillisecond(timestamp: bigint) {\n let now = BigInt(Date.now());\n while (now < timestamp) {\n now = BigInt(Date.now());\n }\n return now;\n}\n\nexport class UidGenerator {\n public readonly MAX = (1n << 63n) - 1n;\n private readonly machineBits = BigInt(10);\n private readonly sequenceBits = BigInt(12);\n private readonly epochMillisecond = BigInt(1577808000000); // 2020-1-1 00:00:00\n private readonly sequenceMask = ~(BigInt(-1) << this.sequenceBits);\n private readonly maxMachineId = ~(BigInt(-1) << this.machineBits);\n private readonly machineIdShift = this.sequenceBits;\n private readonly timeStampShift = this.machineBits + this.sequenceBits;\n private readonly machineId: bigint;\n private sequence = BigInt(0);\n private lastTimestamp = BigInt(-1);\n\n constructor(mackineId: number) {\n this.machineId = BigInt(mackineId) % this.maxMachineId;\n }\n\n public readonly next = (): bigint => {\n let timestamp = BigInt(Date.now());\n if (timestamp < this.lastTimestamp) {\n console.error(`Clock moved backwards. time gap = ${this.lastTimestamp - timestamp}`);\n timestamp = getNextMillisecond(this.lastTimestamp);\n }\n if (timestamp === this.lastTimestamp) {\n this.sequence = (this.sequence + BigInt(1)) & this.sequenceMask;\n if (this.sequence === BigInt(0)) {\n timestamp = getNextMillisecond(timestamp);\n }\n } else {\n this.sequence = BigInt(0);\n }\n this.lastTimestamp = timestamp;\n return (\n ((timestamp - this.epochMillisecond) << this.timeStampShift) |\n (this.machineId << this.machineIdShift) |\n this.sequence\n );\n };\n}\n\nconst machineId = Math.floor(Math.random() * 1024);\nexport const uid = new UidGenerator(machineId);\n"],"mappings":";AAYA,SAAS,mBAAmB,WAAmB;AAC7C,MAAI,MAAM,OAAO,KAAK,IAAI,CAAC;AAC3B,SAAO,MAAM,WAAW;AACtB,UAAM,OAAO,KAAK,IAAI,CAAC;AAAA,EACzB;AACA,SAAO;AACT;AAEO,IAAM,eAAN,MAAmB;AAAA,EACR,OAAO,MAAM,OAAO;AAAA,EACnB,cAAc,OAAO,EAAE;AAAA,EACvB,eAAe,OAAO,EAAE;AAAA,EACxB,mBAAmB,OAAO,SAAa;AAAA;AAAA,EACvC,eAAe,EAAE,OAAO,EAAE,KAAK,KAAK;AAAA,EACpC,eAAe,EAAE,OAAO,EAAE,KAAK,KAAK;AAAA,EACpC,iBAAiB,KAAK;AAAA,EACtB,iBAAiB,KAAK,cAAc,KAAK;AAAA,EACzC;AAAA,EACT,WAAW,OAAO,CAAC;AAAA,EACnB,gBAAgB,OAAO,EAAE;AAAA,EAEjC,YAAY,WAAmB;AAC7B,SAAK,YAAY,OAAO,SAAS,IAAI,KAAK;AAAA,EAC5C;AAAA,EAEgB,OAAO,MAAc;AACnC,QAAI,YAAY,OAAO,KAAK,IAAI,CAAC;AACjC,QAAI,YAAY,KAAK,eAAe;AAClC,cAAQ,MAAM,qCAAqC,KAAK,gBAAgB,SAAS,EAAE;AACnF,kBAAY,mBAAmB,KAAK,aAAa;AAAA,IACnD;AACA,QAAI,cAAc,KAAK,eAAe;AACpC,WAAK,WAAY,KAAK,WAAW,OAAO,CAAC,IAAK,KAAK;AACnD,UAAI,KAAK,aAAa,OAAO,CAAC,GAAG;AAC/B,oBAAY,mBAAmB,SAAS;AAAA,MAC1C;AAAA,IACF,OAAO;AACL,WAAK,WAAW,OAAO,CAAC;AAAA,IAC1B;AACA,SAAK,gBAAgB;AACrB,WACI,YAAY,KAAK,oBAAqB,KAAK,iBAC5C,KAAK,aAAa,KAAK,iBACxB,KAAK;AAAA,EAET;AACF;AAEA,IAAM,YAAY,KAAK,MAAM,KAAK,OAAO,IAAI,IAAI;AAC1C,IAAM,MAAM,IAAI,aAAa,SAAS;","names":[]}
@@ -0,0 +1,266 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/status.ts
21
+ var status_exports = {};
22
+ __export(status_exports, {
23
+ Code: () => Code,
24
+ DEFAULT_MESSAGES: () => DEFAULT_MESSAGES,
25
+ Status: () => Status,
26
+ StatusCode: () => StatusCode,
27
+ StatusError: () => StatusError
28
+ });
29
+ module.exports = __toCommonJS(status_exports);
30
+ var Code = {
31
+ // Not an error; returned on success
32
+ //
33
+ // HTTP Mapping: 200 OK
34
+ OK: 200,
35
+ // The operation was cancelled, typically by the caller.
36
+ //
37
+ // HTTP Mapping: 499 Client Closed Request
38
+ CANCELLED: 499,
39
+ // Unknown error. For example, this error may be returned when
40
+ // a `Status` value received from another address space belongs to
41
+ // an error space that is not known in this address space. Also,
42
+ // errors raised by APIs that do not return enough error information
43
+ // may be converted to this error.
44
+ //
45
+ // HTTP Mapping: 500 Internal Server Error
46
+ UNKNOWN: 500,
47
+ // The client specified an invalid argument. Note that this differs
48
+ // from `FAILED_PRECONDITION`. `INVALID_ARGUMENT` indicates arguments
49
+ // that are problematic regardless of the state of the system
50
+ // (e.g., a malformed file name).
51
+ //
52
+ // HTTP Mapping: 400 Bad Request
53
+ INVALID_ARGUMENT: 400,
54
+ // The deadline expired before the operation could complete. For operations
55
+ // that change the state of the system, this error may be returned
56
+ // even if the operation has completed successfully. For example, a
57
+ // successful response from a server could have been delayed long
58
+ // enough for the deadline to expire.
59
+ //
60
+ // HTTP Mapping: 504 Gateway Timeout
61
+ DEADLINE_EXCEEDED: 504,
62
+ // Some requested entity (e.g., file or directory) was not found.
63
+ //
64
+ // Note to server developers: if a request is denied for an entire class
65
+ // of users, such as gradual feature rollout or undocumented whitelist,
66
+ // `NOT_FOUND` may be used. If a request is denied for some users within
67
+ // a class of users, such as user-based access control, `PERMISSION_DENIED`
68
+ // must be used.
69
+ //
70
+ // HTTP Mapping: 404 Not Found
71
+ NOT_FOUND: 404,
72
+ // The entity that a client attempted to create (e.g., file or directory)
73
+ // already exists.
74
+ //
75
+ // HTTP Mapping: 409 Conflict
76
+ ALREADY_EXISTS: 409,
77
+ // The caller does not have permission to execute the specified
78
+ // operation. `PERMISSION_DENIED` must not be used for rejections
79
+ // caused by exhausting some resource (use `RESOURCE_EXHAUSTED`
80
+ // instead for those errors). `PERMISSION_DENIED` must not be
81
+ // used if the caller can not be identified (use `UNAUTHENTICATED`
82
+ // instead for those errors). This error code does not imply the
83
+ // request is valid or the requested entity exists or satisfies
84
+ // other pre-conditions.
85
+ //
86
+ // HTTP Mapping: 403 Forbidden
87
+ PERMISSION_DENIED: 403,
88
+ // Some resource has been exhausted, perhaps a per-user quota, or
89
+ // perhaps the entire file system is out of space.
90
+ //
91
+ // HTTP Mapping: 429 Too Many Requests
92
+ RESOURCE_EXHAUSTED: 429,
93
+ // The operation was rejected because the system is not in a state
94
+ // required for the operation's execution. For example, the directory
95
+ // to be deleted is non-empty, a rmdir operation is applied to
96
+ // a non-directory, etc.
97
+ //
98
+ // Service implementors can use the following guidelines to decide
99
+ // between `FAILED_PRECONDITION`, `ABORTED`, and `UNAVAILABLE`:
100
+ // (a) Use `UNAVAILABLE` if the client can retry just the failing call.
101
+ // (b) Use `ABORTED` if the client should retry at a higher level
102
+ // (e.g., when a client-specified test-and-set fails, indicating the
103
+ // client should restart a read-modify-write sequence).
104
+ // (c) Use `FAILED_PRECONDITION` if the client should not retry until
105
+ // the system state has been explicitly fixed. E.g., if a "rmdir"
106
+ // fails because the directory is non-empty, `FAILED_PRECONDITION`
107
+ // should be returned since the client should not retry unless
108
+ // the files are deleted from the directory.
109
+ //
110
+ // HTTP Mapping: 400 Bad Request
111
+ FAILED_PRECONDITION: 400,
112
+ // The operation was aborted, typically due to a concurrency issue such as
113
+ // a sequencer check failure or transaction abort.
114
+ //
115
+ // See the guidelines above for deciding between `FAILED_PRECONDITION`,
116
+ // `ABORTED`, and `UNAVAILABLE`.
117
+ //
118
+ // HTTP Mapping: 409 Conflict
119
+ ABORTED: 409,
120
+ // The operation was attempted past the valid range. E.g., seeking or
121
+ // reading past end-of-file.
122
+ //
123
+ // Unlike `INVALID_ARGUMENT`, this error indicates a problem that may
124
+ // be fixed if the system state changes. For example, a 32-bit file
125
+ // system will generate `INVALID_ARGUMENT` if asked to read at an
126
+ // offset that is not in the range [0,2^32-1], but it will generate
127
+ // `OUT_OF_RANGE` if asked to read from an offset past the current
128
+ // file size.
129
+ //
130
+ // There is a fair bit of overlap between `FAILED_PRECONDITION` and
131
+ // `OUT_OF_RANGE`. We recommend using `OUT_OF_RANGE` (the more specific
132
+ // error) when it applies so that callers who are iterating through
133
+ // a space can easily look for an `OUT_OF_RANGE` error to detect when
134
+ // they are done.
135
+ //
136
+ // HTTP Mapping: 400 Bad Request
137
+ OUT_OF_RANGE: 400,
138
+ // The operation is not implemented or is not supported/enabled in this
139
+ // service.
140
+ //
141
+ // HTTP Mapping: 501 Not Implemented
142
+ UNIMPLEMENTED: 501,
143
+ // Internal errors. This means that some invariants expected by the
144
+ // underlying system have been broken. This error code is reserved
145
+ // for serious errors.
146
+ //
147
+ // HTTP Mapping: 500 Internal Server Error
148
+ INTERNAL: 500,
149
+ // The service is currently unavailable. This is most likely a
150
+ // transient condition, which can be corrected by retrying with
151
+ // a backoff. Note that it is not always safe to retry
152
+ // non-idempotent operations.
153
+ //
154
+ // See the guidelines above for deciding between `FAILED_PRECONDITION`,
155
+ // `ABORTED`, and `UNAVAILABLE`.
156
+ //
157
+ // HTTP Mapping: 503 Service Unavailable
158
+ UNAVAILABLE: 503,
159
+ // Unrecoverable data loss or corruption.
160
+ //
161
+ // HTTP Mapping: 500 Internal Server Error
162
+ DATA_LOSS: 500,
163
+ // The request does not have valid authentication credentials for the
164
+ // operation.
165
+ //
166
+ // HTTP Mapping: 401 Unauthorized
167
+ UNAUTHENTICATED: 401,
168
+ // The request method is not supported by the server and cannot be handled.
169
+ //
170
+ // HTTP Mapping: 405 Method Not Allowed
171
+ METHOD_NOT_ALLOWED: 405
172
+ };
173
+ var DEFAULT_MESSAGES = {
174
+ OK: "OK",
175
+ CANCELLED: "The operation was cancelled",
176
+ UNKNOWN: "Unknown error",
177
+ INVALID_ARGUMENT: "The client specified an invalid argument",
178
+ DEADLINE_EXCEEDED: "The deadline expired before the operation could complete",
179
+ NOT_FOUND: "Some requested entity was not found",
180
+ ALREADY_EXISTS: "The entity that a client attempted to create already exists",
181
+ PERMISSION_DENIED: "The caller does not have permission to execute the specified operation",
182
+ RESOURCE_EXHAUSTED: "Some resource has been exhausted",
183
+ FAILED_PRECONDITION: "The operation was rejected because the system is not in a state required for the operation's execution",
184
+ ABORTED: "The operation was aborted",
185
+ OUT_OF_RANGE: "The operation was attempted past the valid range",
186
+ UNIMPLEMENTED: "The operation is not implemented or is not supported/enabled in this service",
187
+ INTERNAL: "Internal errors",
188
+ UNAVAILABLE: "The service is currently unavailable",
189
+ DATA_LOSS: "Unrecoverable data loss or corruption",
190
+ UNAUTHENTICATED: "The request does not have valid authentication credentials for the operation",
191
+ METHOD_NOT_ALLOWED: "The request method is not supported by the server and cannot be handled"
192
+ };
193
+ var StatusError = class _StatusError extends Error {
194
+ status;
195
+ body;
196
+ constructor(status, body) {
197
+ super(body?.error?.message ?? `Status Error: ${status}`);
198
+ this.name = "StatusError";
199
+ this.status = status;
200
+ this.body = body;
201
+ if (Error.captureStackTrace) {
202
+ Error.captureStackTrace(this, _StatusError);
203
+ }
204
+ Object.setPrototypeOf(this, _StatusError.prototype);
205
+ }
206
+ };
207
+ var StatusCode = class _StatusCode {
208
+ code;
209
+ message;
210
+ constructor(code, message) {
211
+ this.code = code;
212
+ this.message = message;
213
+ }
214
+ static of(code, message) {
215
+ return new _StatusCode(code, message ?? DEFAULT_MESSAGES[code]);
216
+ }
217
+ body(details) {
218
+ return {
219
+ error: {
220
+ code: Code[this.code],
221
+ status: this.code,
222
+ message: this.message ?? "",
223
+ details: details?.list ?? []
224
+ }
225
+ };
226
+ }
227
+ error(details) {
228
+ const body = this.body(details);
229
+ if (Status.adapter) return Status.adapter(Code[this.code], body);
230
+ return new StatusError(Code[this.code], body);
231
+ }
232
+ response(details) {
233
+ const body = this.body(details);
234
+ return Response.json(body, { status: body.error.code });
235
+ }
236
+ };
237
+ var Status = class {
238
+ static adapter;
239
+ static ok = (message) => StatusCode.of("OK", message);
240
+ static cancelled = (message) => StatusCode.of("CANCELLED", message);
241
+ static unknown = (message) => StatusCode.of("UNKNOWN", message);
242
+ static invalidArgument = (message) => StatusCode.of("INVALID_ARGUMENT", message);
243
+ static deadlineExceeded = (message) => StatusCode.of("DEADLINE_EXCEEDED", message);
244
+ static notFound = (message) => StatusCode.of("NOT_FOUND", message);
245
+ static alreadyExists = (message) => StatusCode.of("ALREADY_EXISTS", message);
246
+ static permissionDenied = (message) => StatusCode.of("PERMISSION_DENIED", message);
247
+ static unauthorized = (message) => StatusCode.of("UNAUTHENTICATED", message);
248
+ static resourceExhausted = (message) => StatusCode.of("RESOURCE_EXHAUSTED", message);
249
+ static failedPrecondition = (message) => StatusCode.of("FAILED_PRECONDITION", message);
250
+ static aborted = (message) => StatusCode.of("ABORTED", message);
251
+ static outOfRange = (message) => StatusCode.of("OUT_OF_RANGE", message);
252
+ static unimplemented = (message) => StatusCode.of("UNIMPLEMENTED", message);
253
+ static internal = (message) => StatusCode.of("INTERNAL", message);
254
+ static unavailable = (message) => StatusCode.of("UNAVAILABLE", message);
255
+ static dataLoss = (message) => StatusCode.of("DATA_LOSS", message);
256
+ static methodNotAllowed = (message) => StatusCode.of("METHOD_NOT_ALLOWED", message);
257
+ };
258
+ // Annotate the CommonJS export names for ESM import in node:
259
+ 0 && (module.exports = {
260
+ Code,
261
+ DEFAULT_MESSAGES,
262
+ Status,
263
+ StatusCode,
264
+ StatusError
265
+ });
266
+ //# sourceMappingURL=status.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/status.ts"],"sourcesContent":["import type { Detail, Details } from './detail';\n\nexport const Code = {\n // Not an error; returned on success\n //\n // HTTP Mapping: 200 OK\n OK: 200,\n\n // The operation was cancelled, typically by the caller.\n //\n // HTTP Mapping: 499 Client Closed Request\n CANCELLED: 499,\n\n // Unknown error. For example, this error may be returned when\n // a `Status` value received from another address space belongs to\n // an error space that is not known in this address space. Also,\n // errors raised by APIs that do not return enough error information\n // may be converted to this error.\n //\n // HTTP Mapping: 500 Internal Server Error\n UNKNOWN: 500,\n\n // The client specified an invalid argument. Note that this differs\n // from `FAILED_PRECONDITION`. `INVALID_ARGUMENT` indicates arguments\n // that are problematic regardless of the state of the system\n // (e.g., a malformed file name).\n //\n // HTTP Mapping: 400 Bad Request\n INVALID_ARGUMENT: 400,\n\n // The deadline expired before the operation could complete. For operations\n // that change the state of the system, this error may be returned\n // even if the operation has completed successfully. For example, a\n // successful response from a server could have been delayed long\n // enough for the deadline to expire.\n //\n // HTTP Mapping: 504 Gateway Timeout\n DEADLINE_EXCEEDED: 504,\n\n // Some requested entity (e.g., file or directory) was not found.\n //\n // Note to server developers: if a request is denied for an entire class\n // of users, such as gradual feature rollout or undocumented whitelist,\n // `NOT_FOUND` may be used. If a request is denied for some users within\n // a class of users, such as user-based access control, `PERMISSION_DENIED`\n // must be used.\n //\n // HTTP Mapping: 404 Not Found\n NOT_FOUND: 404,\n\n // The entity that a client attempted to create (e.g., file or directory)\n // already exists.\n //\n // HTTP Mapping: 409 Conflict\n ALREADY_EXISTS: 409,\n\n // The caller does not have permission to execute the specified\n // operation. `PERMISSION_DENIED` must not be used for rejections\n // caused by exhausting some resource (use `RESOURCE_EXHAUSTED`\n // instead for those errors). `PERMISSION_DENIED` must not be\n // used if the caller can not be identified (use `UNAUTHENTICATED`\n // instead for those errors). This error code does not imply the\n // request is valid or the requested entity exists or satisfies\n // other pre-conditions.\n //\n // HTTP Mapping: 403 Forbidden\n PERMISSION_DENIED: 403,\n\n // Some resource has been exhausted, perhaps a per-user quota, or\n // perhaps the entire file system is out of space.\n //\n // HTTP Mapping: 429 Too Many Requests\n RESOURCE_EXHAUSTED: 429,\n\n // The operation was rejected because the system is not in a state\n // required for the operation's execution. For example, the directory\n // to be deleted is non-empty, a rmdir operation is applied to\n // a non-directory, etc.\n //\n // Service implementors can use the following guidelines to decide\n // between `FAILED_PRECONDITION`, `ABORTED`, and `UNAVAILABLE`:\n // (a) Use `UNAVAILABLE` if the client can retry just the failing call.\n // (b) Use `ABORTED` if the client should retry at a higher level\n // (e.g., when a client-specified test-and-set fails, indicating the\n // client should restart a read-modify-write sequence).\n // (c) Use `FAILED_PRECONDITION` if the client should not retry until\n // the system state has been explicitly fixed. E.g., if a \"rmdir\"\n // fails because the directory is non-empty, `FAILED_PRECONDITION`\n // should be returned since the client should not retry unless\n // the files are deleted from the directory.\n //\n // HTTP Mapping: 400 Bad Request\n FAILED_PRECONDITION: 400,\n\n // The operation was aborted, typically due to a concurrency issue such as\n // a sequencer check failure or transaction abort.\n //\n // See the guidelines above for deciding between `FAILED_PRECONDITION`,\n // `ABORTED`, and `UNAVAILABLE`.\n //\n // HTTP Mapping: 409 Conflict\n ABORTED: 409,\n\n // The operation was attempted past the valid range. E.g., seeking or\n // reading past end-of-file.\n //\n // Unlike `INVALID_ARGUMENT`, this error indicates a problem that may\n // be fixed if the system state changes. For example, a 32-bit file\n // system will generate `INVALID_ARGUMENT` if asked to read at an\n // offset that is not in the range [0,2^32-1], but it will generate\n // `OUT_OF_RANGE` if asked to read from an offset past the current\n // file size.\n //\n // There is a fair bit of overlap between `FAILED_PRECONDITION` and\n // `OUT_OF_RANGE`. We recommend using `OUT_OF_RANGE` (the more specific\n // error) when it applies so that callers who are iterating through\n // a space can easily look for an `OUT_OF_RANGE` error to detect when\n // they are done.\n //\n // HTTP Mapping: 400 Bad Request\n OUT_OF_RANGE: 400,\n\n // The operation is not implemented or is not supported/enabled in this\n // service.\n //\n // HTTP Mapping: 501 Not Implemented\n UNIMPLEMENTED: 501,\n\n // Internal errors. This means that some invariants expected by the\n // underlying system have been broken. This error code is reserved\n // for serious errors.\n //\n // HTTP Mapping: 500 Internal Server Error\n INTERNAL: 500,\n\n // The service is currently unavailable. This is most likely a\n // transient condition, which can be corrected by retrying with\n // a backoff. Note that it is not always safe to retry\n // non-idempotent operations.\n //\n // See the guidelines above for deciding between `FAILED_PRECONDITION`,\n // `ABORTED`, and `UNAVAILABLE`.\n //\n // HTTP Mapping: 503 Service Unavailable\n UNAVAILABLE: 503,\n\n // Unrecoverable data loss or corruption.\n //\n // HTTP Mapping: 500 Internal Server Error\n DATA_LOSS: 500,\n\n // The request does not have valid authentication credentials for the\n // operation.\n //\n // HTTP Mapping: 401 Unauthorized\n UNAUTHENTICATED: 401,\n\n // The request method is not supported by the server and cannot be handled.\n //\n // HTTP Mapping: 405 Method Not Allowed\n METHOD_NOT_ALLOWED: 405,\n} as const;\n\nexport const DEFAULT_MESSAGES: Record<keyof typeof Code, string> = {\n OK: 'OK',\n CANCELLED: 'The operation was cancelled',\n UNKNOWN: 'Unknown error',\n INVALID_ARGUMENT: 'The client specified an invalid argument',\n DEADLINE_EXCEEDED: 'The deadline expired before the operation could complete',\n NOT_FOUND: 'Some requested entity was not found',\n ALREADY_EXISTS: 'The entity that a client attempted to create already exists',\n PERMISSION_DENIED: 'The caller does not have permission to execute the specified operation',\n RESOURCE_EXHAUSTED: 'Some resource has been exhausted',\n FAILED_PRECONDITION:\n \"The operation was rejected because the system is not in a state required for the operation's execution\",\n ABORTED: 'The operation was aborted',\n OUT_OF_RANGE: 'The operation was attempted past the valid range',\n UNIMPLEMENTED: 'The operation is not implemented or is not supported/enabled in this service',\n INTERNAL: 'Internal errors',\n UNAVAILABLE: 'The service is currently unavailable',\n DATA_LOSS: 'Unrecoverable data loss or corruption',\n UNAUTHENTICATED: 'The request does not have valid authentication credentials for the operation',\n METHOD_NOT_ALLOWED: 'The request method is not supported by the server and cannot be handled',\n};\n\nexport interface ErrorBody {\n error: {\n code: number;\n status: keyof typeof Code;\n message: string;\n details: Detail[];\n };\n}\n\nexport class StatusError extends Error {\n readonly status: number;\n readonly body?: ErrorBody;\n\n constructor(status: number, body?: ErrorBody) {\n super(body?.error?.message ?? `Status Error: ${status}`);\n this.name = 'StatusError';\n this.status = status;\n this.body = body;\n if ((Error as any).captureStackTrace) {\n (Error as any).captureStackTrace(this, StatusError);\n }\n Object.setPrototypeOf(this, StatusError.prototype);\n }\n}\n\nexport class StatusCode {\n code: keyof typeof Code;\n message?: string;\n private constructor(code: keyof typeof Code, message?: string) {\n this.code = code;\n this.message = message;\n }\n\n static of(code: keyof typeof Code, message?: string) {\n return new StatusCode(code, message ?? DEFAULT_MESSAGES[code]);\n }\n\n body(details?: Details): ErrorBody {\n return {\n error: {\n code: Code[this.code],\n status: this.code,\n message: this.message ?? '',\n details: details?.list ?? [],\n },\n };\n }\n\n error(details?: Details): Error {\n const body = this.body(details);\n if (Status.adapter) return Status.adapter(Code[this.code], body);\n return new StatusError(Code[this.code], body);\n }\n\n response(details?: Details): Response {\n const body = this.body(details);\n return Response.json(body, { status: body.error.code });\n }\n}\n\nexport class Status {\n static adapter?: (status: number, response: ErrorBody) => Error;\n\n static ok = (message?: string) => StatusCode.of('OK', message);\n static cancelled = (message?: string) => StatusCode.of('CANCELLED', message);\n static unknown = (message?: string) => StatusCode.of('UNKNOWN', message);\n static invalidArgument = (message?: string) => StatusCode.of('INVALID_ARGUMENT', message);\n static deadlineExceeded = (message?: string) => StatusCode.of('DEADLINE_EXCEEDED', message);\n static notFound = (message?: string) => StatusCode.of('NOT_FOUND', message);\n static alreadyExists = (message?: string) => StatusCode.of('ALREADY_EXISTS', message);\n static permissionDenied = (message?: string) => StatusCode.of('PERMISSION_DENIED', message);\n static unauthorized = (message?: string) => StatusCode.of('UNAUTHENTICATED', message);\n static resourceExhausted = (message?: string) => StatusCode.of('RESOURCE_EXHAUSTED', message);\n static failedPrecondition = (message?: string) => StatusCode.of('FAILED_PRECONDITION', message);\n static aborted = (message?: string) => StatusCode.of('ABORTED', message);\n static outOfRange = (message?: string) => StatusCode.of('OUT_OF_RANGE', message);\n static unimplemented = (message?: string) => StatusCode.of('UNIMPLEMENTED', message);\n static internal = (message?: string) => StatusCode.of('INTERNAL', message);\n static unavailable = (message?: string) => StatusCode.of('UNAVAILABLE', message);\n static dataLoss = (message?: string) => StatusCode.of('DATA_LOSS', message);\n static methodNotAllowed = (message?: string) => StatusCode.of('METHOD_NOT_ALLOWED', message);\n}\n"],"mappings":"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","names":[]}
@@ -0,0 +1,69 @@
1
+ import { Detail, Details } from './detail.cjs';
2
+ import './reason.cjs';
3
+
4
+ declare const Code: {
5
+ readonly OK: 200;
6
+ readonly CANCELLED: 499;
7
+ readonly UNKNOWN: 500;
8
+ readonly INVALID_ARGUMENT: 400;
9
+ readonly DEADLINE_EXCEEDED: 504;
10
+ readonly NOT_FOUND: 404;
11
+ readonly ALREADY_EXISTS: 409;
12
+ readonly PERMISSION_DENIED: 403;
13
+ readonly RESOURCE_EXHAUSTED: 429;
14
+ readonly FAILED_PRECONDITION: 400;
15
+ readonly ABORTED: 409;
16
+ readonly OUT_OF_RANGE: 400;
17
+ readonly UNIMPLEMENTED: 501;
18
+ readonly INTERNAL: 500;
19
+ readonly UNAVAILABLE: 503;
20
+ readonly DATA_LOSS: 500;
21
+ readonly UNAUTHENTICATED: 401;
22
+ readonly METHOD_NOT_ALLOWED: 405;
23
+ };
24
+ declare const DEFAULT_MESSAGES: Record<keyof typeof Code, string>;
25
+ interface ErrorBody {
26
+ error: {
27
+ code: number;
28
+ status: keyof typeof Code;
29
+ message: string;
30
+ details: Detail[];
31
+ };
32
+ }
33
+ declare class StatusError extends Error {
34
+ readonly status: number;
35
+ readonly body?: ErrorBody;
36
+ constructor(status: number, body?: ErrorBody);
37
+ }
38
+ declare class StatusCode {
39
+ code: keyof typeof Code;
40
+ message?: string;
41
+ private constructor();
42
+ static of(code: keyof typeof Code, message?: string): StatusCode;
43
+ body(details?: Details): ErrorBody;
44
+ error(details?: Details): Error;
45
+ response(details?: Details): Response;
46
+ }
47
+ declare class Status {
48
+ static adapter?: (status: number, response: ErrorBody) => Error;
49
+ static ok: (message?: string) => StatusCode;
50
+ static cancelled: (message?: string) => StatusCode;
51
+ static unknown: (message?: string) => StatusCode;
52
+ static invalidArgument: (message?: string) => StatusCode;
53
+ static deadlineExceeded: (message?: string) => StatusCode;
54
+ static notFound: (message?: string) => StatusCode;
55
+ static alreadyExists: (message?: string) => StatusCode;
56
+ static permissionDenied: (message?: string) => StatusCode;
57
+ static unauthorized: (message?: string) => StatusCode;
58
+ static resourceExhausted: (message?: string) => StatusCode;
59
+ static failedPrecondition: (message?: string) => StatusCode;
60
+ static aborted: (message?: string) => StatusCode;
61
+ static outOfRange: (message?: string) => StatusCode;
62
+ static unimplemented: (message?: string) => StatusCode;
63
+ static internal: (message?: string) => StatusCode;
64
+ static unavailable: (message?: string) => StatusCode;
65
+ static dataLoss: (message?: string) => StatusCode;
66
+ static methodNotAllowed: (message?: string) => StatusCode;
67
+ }
68
+
69
+ export { Code, DEFAULT_MESSAGES, type ErrorBody, Status, StatusCode, StatusError };
@@ -0,0 +1,69 @@
1
+ import { Detail, Details } from './detail.js';
2
+ import './reason.js';
3
+
4
+ declare const Code: {
5
+ readonly OK: 200;
6
+ readonly CANCELLED: 499;
7
+ readonly UNKNOWN: 500;
8
+ readonly INVALID_ARGUMENT: 400;
9
+ readonly DEADLINE_EXCEEDED: 504;
10
+ readonly NOT_FOUND: 404;
11
+ readonly ALREADY_EXISTS: 409;
12
+ readonly PERMISSION_DENIED: 403;
13
+ readonly RESOURCE_EXHAUSTED: 429;
14
+ readonly FAILED_PRECONDITION: 400;
15
+ readonly ABORTED: 409;
16
+ readonly OUT_OF_RANGE: 400;
17
+ readonly UNIMPLEMENTED: 501;
18
+ readonly INTERNAL: 500;
19
+ readonly UNAVAILABLE: 503;
20
+ readonly DATA_LOSS: 500;
21
+ readonly UNAUTHENTICATED: 401;
22
+ readonly METHOD_NOT_ALLOWED: 405;
23
+ };
24
+ declare const DEFAULT_MESSAGES: Record<keyof typeof Code, string>;
25
+ interface ErrorBody {
26
+ error: {
27
+ code: number;
28
+ status: keyof typeof Code;
29
+ message: string;
30
+ details: Detail[];
31
+ };
32
+ }
33
+ declare class StatusError extends Error {
34
+ readonly status: number;
35
+ readonly body?: ErrorBody;
36
+ constructor(status: number, body?: ErrorBody);
37
+ }
38
+ declare class StatusCode {
39
+ code: keyof typeof Code;
40
+ message?: string;
41
+ private constructor();
42
+ static of(code: keyof typeof Code, message?: string): StatusCode;
43
+ body(details?: Details): ErrorBody;
44
+ error(details?: Details): Error;
45
+ response(details?: Details): Response;
46
+ }
47
+ declare class Status {
48
+ static adapter?: (status: number, response: ErrorBody) => Error;
49
+ static ok: (message?: string) => StatusCode;
50
+ static cancelled: (message?: string) => StatusCode;
51
+ static unknown: (message?: string) => StatusCode;
52
+ static invalidArgument: (message?: string) => StatusCode;
53
+ static deadlineExceeded: (message?: string) => StatusCode;
54
+ static notFound: (message?: string) => StatusCode;
55
+ static alreadyExists: (message?: string) => StatusCode;
56
+ static permissionDenied: (message?: string) => StatusCode;
57
+ static unauthorized: (message?: string) => StatusCode;
58
+ static resourceExhausted: (message?: string) => StatusCode;
59
+ static failedPrecondition: (message?: string) => StatusCode;
60
+ static aborted: (message?: string) => StatusCode;
61
+ static outOfRange: (message?: string) => StatusCode;
62
+ static unimplemented: (message?: string) => StatusCode;
63
+ static internal: (message?: string) => StatusCode;
64
+ static unavailable: (message?: string) => StatusCode;
65
+ static dataLoss: (message?: string) => StatusCode;
66
+ static methodNotAllowed: (message?: string) => StatusCode;
67
+ }
68
+
69
+ export { Code, DEFAULT_MESSAGES, type ErrorBody, Status, StatusCode, StatusError };