@shware/http 0.2.6 → 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.
- package/dist/__tests__/index.test.cjs +27 -0
- package/dist/__tests__/index.test.cjs.map +1 -0
- package/dist/__tests__/index.test.d.cts +2 -0
- package/dist/__tests__/index.test.d.ts +2 -0
- package/dist/__tests__/index.test.mjs +25 -0
- package/dist/__tests__/index.test.mjs.map +1 -0
- package/dist/detail.cjs +93 -0
- package/dist/detail.cjs.map +1 -0
- package/dist/detail.d.cts +101 -0
- package/dist/detail.d.ts +101 -0
- package/dist/detail.mjs +67 -0
- package/dist/detail.mjs.map +1 -0
- package/dist/hono/geolocation.cjs +59 -0
- package/dist/hono/geolocation.cjs.map +1 -0
- package/dist/hono/geolocation.d.cts +21 -0
- package/dist/hono/geolocation.d.ts +21 -0
- package/dist/hono/geolocation.mjs +33 -0
- package/dist/hono/geolocation.mjs.map +1 -0
- package/dist/hono/handler.cjs +42 -0
- package/dist/hono/handler.cjs.map +1 -0
- package/dist/hono/handler.d.cts +11 -0
- package/dist/hono/handler.d.ts +11 -0
- package/dist/hono/handler.mjs +17 -0
- package/dist/hono/handler.mjs.map +1 -0
- package/dist/hono/index.cjs +39 -0
- package/dist/hono/index.cjs.map +1 -0
- package/dist/hono/index.d.cts +8 -0
- package/dist/hono/index.d.ts +8 -0
- package/dist/hono/index.mjs +11 -0
- package/dist/hono/index.mjs.map +1 -0
- package/dist/hono/validator.cjs +44 -0
- package/dist/hono/validator.cjs.map +1 -0
- package/dist/hono/validator.d.cts +26 -0
- package/dist/hono/validator.d.ts +26 -0
- package/dist/hono/validator.mjs +19 -0
- package/dist/hono/validator.mjs.map +1 -0
- package/dist/index.cjs +13 -387
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -269
- package/dist/index.d.ts +6 -269
- package/dist/index.mjs +6 -370
- package/dist/index.mjs.map +1 -1
- package/dist/message.cjs +32 -0
- package/dist/message.cjs.map +1 -0
- package/dist/message.d.cts +3 -0
- package/dist/message.d.ts +3 -0
- package/dist/message.mjs +7 -0
- package/dist/message.mjs.map +1 -0
- package/dist/reason.cjs +19 -0
- package/dist/reason.cjs.map +1 -0
- package/dist/reason.d.cts +66 -0
- package/dist/reason.d.ts +66 -0
- package/dist/reason.mjs +1 -0
- package/dist/reason.mjs.map +1 -0
- package/dist/snowflake.cjs +75 -0
- package/dist/snowflake.cjs.map +1 -0
- package/dist/snowflake.d.cts +29 -0
- package/dist/snowflake.d.ts +29 -0
- package/dist/snowflake.mjs +49 -0
- package/dist/snowflake.mjs.map +1 -0
- package/dist/status.cjs +266 -0
- package/dist/status.cjs.map +1 -0
- package/dist/status.d.cts +69 -0
- package/dist/status.d.ts +69 -0
- package/dist/status.mjs +237 -0
- package/dist/status.mjs.map +1 -0
- package/dist/vaild.cjs +51 -0
- package/dist/vaild.cjs.map +1 -0
- package/dist/vaild.d.cts +13 -0
- package/dist/vaild.d.ts +13 -0
- package/dist/vaild.mjs +26 -0
- package/dist/vaild.mjs.map +1 -0
- package/package.json +14 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,269 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
interface StatusErrorReason {
|
|
9
|
-
OK: string;
|
|
10
|
-
CANCELLED: string;
|
|
11
|
-
UNKNOWN: string;
|
|
12
|
-
INVALID_ARGUMENT: string;
|
|
13
|
-
DEADLINE_EXCEEDED: string;
|
|
14
|
-
NOT_FOUND: string;
|
|
15
|
-
ALREADY_EXISTS: string;
|
|
16
|
-
PERMISSION_DENIED: string;
|
|
17
|
-
RESOURCE_EXHAUSTED: string;
|
|
18
|
-
FAILED_PRECONDITION: string;
|
|
19
|
-
ABORTED: string;
|
|
20
|
-
OUT_OF_RANGE: string;
|
|
21
|
-
UNIMPLEMENTED: string;
|
|
22
|
-
INTERNAL: string;
|
|
23
|
-
UNAVAILABLE: string;
|
|
24
|
-
DATA_LOSS: string;
|
|
25
|
-
UNAUTHENTICATED: string;
|
|
26
|
-
}
|
|
27
|
-
interface AuthenticationErrorReason {
|
|
28
|
-
ACCOUNT_LOCKED: string;
|
|
29
|
-
ACCOUNT_EXPIRED: string;
|
|
30
|
-
ACCOUNT_INACTIVE: string;
|
|
31
|
-
ACCOUNT_DISABLED: string;
|
|
32
|
-
ACCOUNT_SUSPENDED: string;
|
|
33
|
-
ACCESS_DENIED: string;
|
|
34
|
-
ACCESS_TOKEN_REQUIRED: string;
|
|
35
|
-
PASSWORD_MISMATCH: string;
|
|
36
|
-
USERNAME_ALREADY_EXISTS: string;
|
|
37
|
-
VERIFICATION_CODE_MISMATCH: string;
|
|
38
|
-
VERIFICATION_CODE_SEND_FAILED: string;
|
|
39
|
-
}
|
|
40
|
-
interface ModerationErrorReason {
|
|
41
|
-
POSSIBLY_SENSITIVE: string;
|
|
42
|
-
ADULT_CONTENT: string;
|
|
43
|
-
NUDITY_CONTENT: string;
|
|
44
|
-
SEXUAL_CONTENT: string;
|
|
45
|
-
BLOODY_CONTENT: string;
|
|
46
|
-
WEAPON_CONTENT: string;
|
|
47
|
-
POLITICS_CONTENT: string;
|
|
48
|
-
VIOLENCE_CONTENT: string;
|
|
49
|
-
ABUSE_CONTENT: string;
|
|
50
|
-
ADVERTISEMENT_CONTENT: string;
|
|
51
|
-
CONTRABAND_CONTENT: string;
|
|
52
|
-
SPAM_CONTENT: string;
|
|
53
|
-
MEANINGLESS_CONTENT: string;
|
|
54
|
-
UNSAFE_TEXT_DETECTED: string;
|
|
55
|
-
}
|
|
56
|
-
interface MultipartErrorReason {
|
|
57
|
-
MAX_UPLOAD_SIZE_EXCEEDED: string;
|
|
58
|
-
MEDIA_TYPE_NOT_SUPPORTED: string;
|
|
59
|
-
MEDIA_TYPE_NOT_ACCEPTABLE: string;
|
|
60
|
-
}
|
|
61
|
-
interface AppErrorReason {
|
|
62
|
-
NOT_SUBSCRIBED: string;
|
|
63
|
-
CREDIT_NOT_ENOUGH: string;
|
|
64
|
-
ALREADY_SUBSCRIBED_AT_OTHER_PLATFORM: string;
|
|
65
|
-
}
|
|
66
|
-
type ErrorReason = NetworkErrorReason & StatusErrorReason & AuthenticationErrorReason & ModerationErrorReason & MultipartErrorReason & AppErrorReason;
|
|
67
|
-
|
|
68
|
-
declare enum DetailType {
|
|
69
|
-
ERROR_INFO = "ERROR_INFO",
|
|
70
|
-
RETRY_INFO = "RETRY_INFO",
|
|
71
|
-
DEBUG_INFO = "DEBUG_INFO",
|
|
72
|
-
QUOTA_FAILURE = "QUOTA_FAILURE",
|
|
73
|
-
PRECONDITION_FAILURE = "PRECONDITION_FAILURE",
|
|
74
|
-
BAD_REQUEST = "BAD_REQUEST",
|
|
75
|
-
REQUEST_INFO = "REQUEST_INFO",
|
|
76
|
-
RESOURCE_INFO = "RESOURCE_INFO",
|
|
77
|
-
HELP = "HELP",
|
|
78
|
-
LOCALIZED_MESSAGE = "LOCALIZED_MESSAGE"
|
|
79
|
-
}
|
|
80
|
-
interface ErrorInfo {
|
|
81
|
-
type: DetailType.ERROR_INFO;
|
|
82
|
-
reason: keyof ErrorReason;
|
|
83
|
-
domain?: string;
|
|
84
|
-
metadata?: {
|
|
85
|
-
[key: string]: string;
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
interface RetryInfo {
|
|
89
|
-
type: DetailType.RETRY_INFO;
|
|
90
|
-
retryDelay: number;
|
|
91
|
-
}
|
|
92
|
-
interface DebugInfo {
|
|
93
|
-
type: DetailType.DEBUG_INFO;
|
|
94
|
-
stackEntries: string[];
|
|
95
|
-
detail?: string;
|
|
96
|
-
}
|
|
97
|
-
interface QuotaFailure {
|
|
98
|
-
type: DetailType.QUOTA_FAILURE;
|
|
99
|
-
violations: {
|
|
100
|
-
subject: string;
|
|
101
|
-
description: string;
|
|
102
|
-
}[];
|
|
103
|
-
}
|
|
104
|
-
interface PreconditionFailure {
|
|
105
|
-
type: DetailType.PRECONDITION_FAILURE;
|
|
106
|
-
violations: {
|
|
107
|
-
type: string;
|
|
108
|
-
subject: string;
|
|
109
|
-
description: string;
|
|
110
|
-
}[];
|
|
111
|
-
}
|
|
112
|
-
interface BadRequest {
|
|
113
|
-
type: DetailType.BAD_REQUEST;
|
|
114
|
-
fieldViolations: {
|
|
115
|
-
field: string;
|
|
116
|
-
description: string;
|
|
117
|
-
}[];
|
|
118
|
-
}
|
|
119
|
-
interface RequestInfo {
|
|
120
|
-
type: DetailType.REQUEST_INFO;
|
|
121
|
-
requestId: string;
|
|
122
|
-
servingData: string;
|
|
123
|
-
}
|
|
124
|
-
interface ResourceInfo {
|
|
125
|
-
type: DetailType.RESOURCE_INFO;
|
|
126
|
-
resourceType: string;
|
|
127
|
-
resourceName: string;
|
|
128
|
-
owner: string;
|
|
129
|
-
description: string;
|
|
130
|
-
}
|
|
131
|
-
interface Help {
|
|
132
|
-
type: DetailType.HELP;
|
|
133
|
-
links: {
|
|
134
|
-
url: string;
|
|
135
|
-
description: string;
|
|
136
|
-
}[];
|
|
137
|
-
}
|
|
138
|
-
interface LocalizedMessage {
|
|
139
|
-
type: DetailType.LOCALIZED_MESSAGE;
|
|
140
|
-
locale: string;
|
|
141
|
-
message: string;
|
|
142
|
-
}
|
|
143
|
-
type Detail = RetryInfo | DebugInfo | QuotaFailure | ErrorInfo | PreconditionFailure | BadRequest | RequestInfo | ResourceInfo | Help | LocalizedMessage;
|
|
144
|
-
/**
|
|
145
|
-
* Example usage:
|
|
146
|
-
* const details = Details.new()
|
|
147
|
-
* .requestInfo({ requestId: '1234567890', servingData: '/v1/tests' })
|
|
148
|
-
* .errorInfo({ reason: 'ACCOUNT_LOCKED' });
|
|
149
|
-
* */
|
|
150
|
-
declare class Details {
|
|
151
|
-
readonly list: Detail[];
|
|
152
|
-
private constructor();
|
|
153
|
-
static new(): Details;
|
|
154
|
-
errorInfo(detail: Omit<ErrorInfo, 'type'>): this;
|
|
155
|
-
retryInfo(detail: Omit<RetryInfo, 'type'>): this;
|
|
156
|
-
debugInfo(detail: Omit<DebugInfo, 'type'>): this;
|
|
157
|
-
quotaFailure(detail: Omit<QuotaFailure, 'type'>): this;
|
|
158
|
-
preconditionFailure(detail: Omit<PreconditionFailure, 'type'>): this;
|
|
159
|
-
badRequest(detail: Omit<BadRequest, 'type'>): this;
|
|
160
|
-
requestInfo(detail: Omit<RequestInfo, 'type'>): this;
|
|
161
|
-
resourceInfo(detail: Omit<ResourceInfo, 'type'>): this;
|
|
162
|
-
help(detail: Omit<Help, 'type'>): this;
|
|
163
|
-
localizedMessage(detail: Omit<LocalizedMessage, 'type'>): this;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
declare const Code: {
|
|
167
|
-
readonly OK: 200;
|
|
168
|
-
readonly CANCELLED: 499;
|
|
169
|
-
readonly UNKNOWN: 500;
|
|
170
|
-
readonly INVALID_ARGUMENT: 400;
|
|
171
|
-
readonly DEADLINE_EXCEEDED: 504;
|
|
172
|
-
readonly NOT_FOUND: 404;
|
|
173
|
-
readonly ALREADY_EXISTS: 409;
|
|
174
|
-
readonly PERMISSION_DENIED: 403;
|
|
175
|
-
readonly RESOURCE_EXHAUSTED: 429;
|
|
176
|
-
readonly FAILED_PRECONDITION: 400;
|
|
177
|
-
readonly ABORTED: 409;
|
|
178
|
-
readonly OUT_OF_RANGE: 400;
|
|
179
|
-
readonly UNIMPLEMENTED: 501;
|
|
180
|
-
readonly INTERNAL: 500;
|
|
181
|
-
readonly UNAVAILABLE: 503;
|
|
182
|
-
readonly DATA_LOSS: 500;
|
|
183
|
-
readonly UNAUTHENTICATED: 401;
|
|
184
|
-
readonly METHOD_NOT_ALLOWED: 405;
|
|
185
|
-
};
|
|
186
|
-
declare const DEFAULT_MESSAGES: Record<keyof typeof Code, string>;
|
|
187
|
-
interface ErrorBody {
|
|
188
|
-
error: {
|
|
189
|
-
code: number;
|
|
190
|
-
status: keyof typeof Code;
|
|
191
|
-
message: string;
|
|
192
|
-
details: Detail[];
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
declare class StatusError extends Error {
|
|
196
|
-
readonly status: number;
|
|
197
|
-
readonly body?: ErrorBody;
|
|
198
|
-
constructor(status: number, body?: ErrorBody);
|
|
199
|
-
}
|
|
200
|
-
declare class StatusCode {
|
|
201
|
-
code: keyof typeof Code;
|
|
202
|
-
message?: string;
|
|
203
|
-
private constructor();
|
|
204
|
-
static of(code: keyof typeof Code, message?: string): StatusCode;
|
|
205
|
-
body(details?: Details): ErrorBody;
|
|
206
|
-
error(details?: Details): Error;
|
|
207
|
-
response(details?: Details): Response;
|
|
208
|
-
}
|
|
209
|
-
declare class Status {
|
|
210
|
-
static adapter?: (status: number, response: ErrorBody) => Error;
|
|
211
|
-
static ok: (message?: string) => StatusCode;
|
|
212
|
-
static cancelled: (message?: string) => StatusCode;
|
|
213
|
-
static unknown: (message?: string) => StatusCode;
|
|
214
|
-
static invalidArgument: (message?: string) => StatusCode;
|
|
215
|
-
static deadlineExceeded: (message?: string) => StatusCode;
|
|
216
|
-
static notFound: (message?: string) => StatusCode;
|
|
217
|
-
static alreadyExists: (message?: string) => StatusCode;
|
|
218
|
-
static permissionDenied: (message?: string) => StatusCode;
|
|
219
|
-
static unauthorized: (message?: string) => StatusCode;
|
|
220
|
-
static resourceExhausted: (message?: string) => StatusCode;
|
|
221
|
-
static failedPrecondition: (message?: string) => StatusCode;
|
|
222
|
-
static aborted: (message?: string) => StatusCode;
|
|
223
|
-
static outOfRange: (message?: string) => StatusCode;
|
|
224
|
-
static unimplemented: (message?: string) => StatusCode;
|
|
225
|
-
static internal: (message?: string) => StatusCode;
|
|
226
|
-
static unavailable: (message?: string) => StatusCode;
|
|
227
|
-
static dataLoss: (message?: string) => StatusCode;
|
|
228
|
-
static methodNotAllowed: (message?: string) => StatusCode;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
type Result<S extends ZodSchema> = {
|
|
232
|
-
data: z.infer<S>;
|
|
233
|
-
error: null;
|
|
234
|
-
} | {
|
|
235
|
-
data: null;
|
|
236
|
-
error: Response;
|
|
237
|
-
};
|
|
238
|
-
type Target = 'json' | 'form' | 'query' | 'param' | 'header' | 'cookie';
|
|
239
|
-
declare function valid<S extends ZodSchema>(request: Request, target: Target, schema: S): Promise<Result<S>>;
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* A distributed unique ID generator inspired by Twitter's Snowflake.
|
|
243
|
-
*
|
|
244
|
-
* ID data bits:
|
|
245
|
-
* +----------------------+----------------+-----------+
|
|
246
|
-
* | delta millisecond | machine id | sequence |
|
|
247
|
-
* +----------------------+----------------+-----------+
|
|
248
|
-
* | 41bits | 10bits | 12bits |
|
|
249
|
-
* +----------------------+----------------+-----------+
|
|
250
|
-
*
|
|
251
|
-
*/
|
|
252
|
-
declare class UidGenerator {
|
|
253
|
-
readonly MAX: bigint;
|
|
254
|
-
private readonly machineBits;
|
|
255
|
-
private readonly sequenceBits;
|
|
256
|
-
private readonly epochMillisecond;
|
|
257
|
-
private readonly sequenceMask;
|
|
258
|
-
private readonly maxMachineId;
|
|
259
|
-
private readonly machineIdShift;
|
|
260
|
-
private readonly timeStampShift;
|
|
261
|
-
private readonly machineId;
|
|
262
|
-
private sequence;
|
|
263
|
-
private lastTimestamp;
|
|
264
|
-
constructor(mackineId: number);
|
|
265
|
-
readonly next: () => bigint;
|
|
266
|
-
}
|
|
267
|
-
declare const uid: UidGenerator;
|
|
268
|
-
|
|
269
|
-
export { type AppErrorReason, type AuthenticationErrorReason, type BadRequest, Code, DEFAULT_MESSAGES, type DebugInfo, type Detail, DetailType, Details, type ErrorBody, type ErrorInfo, type ErrorReason, type Help, type LocalizedMessage, type ModerationErrorReason, type MultipartErrorReason, type NetworkErrorReason, type PreconditionFailure, type QuotaFailure, type RequestInfo, type ResourceInfo, type Result, type RetryInfo, Status, StatusCode, StatusError, type StatusErrorReason, UidGenerator, uid, valid };
|
|
1
|
+
export { AppErrorReason, AuthenticationErrorReason, ErrorReason, ModerationErrorReason, MultipartErrorReason, NetworkErrorReason, StatusErrorReason } from './reason.cjs';
|
|
2
|
+
export { BadRequest, DebugInfo, Detail, DetailType, Details, ErrorInfo, Help, LocalizedMessage, PreconditionFailure, QuotaFailure, RequestInfo, ResourceInfo, RetryInfo } from './detail.cjs';
|
|
3
|
+
export { Code, DEFAULT_MESSAGES, ErrorBody, Status, StatusCode, StatusError } from './status.cjs';
|
|
4
|
+
export { Result, valid } from './vaild.cjs';
|
|
5
|
+
export { UidGenerator, uid } from './snowflake.cjs';
|
|
6
|
+
import 'zod';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,269 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
interface StatusErrorReason {
|
|
9
|
-
OK: string;
|
|
10
|
-
CANCELLED: string;
|
|
11
|
-
UNKNOWN: string;
|
|
12
|
-
INVALID_ARGUMENT: string;
|
|
13
|
-
DEADLINE_EXCEEDED: string;
|
|
14
|
-
NOT_FOUND: string;
|
|
15
|
-
ALREADY_EXISTS: string;
|
|
16
|
-
PERMISSION_DENIED: string;
|
|
17
|
-
RESOURCE_EXHAUSTED: string;
|
|
18
|
-
FAILED_PRECONDITION: string;
|
|
19
|
-
ABORTED: string;
|
|
20
|
-
OUT_OF_RANGE: string;
|
|
21
|
-
UNIMPLEMENTED: string;
|
|
22
|
-
INTERNAL: string;
|
|
23
|
-
UNAVAILABLE: string;
|
|
24
|
-
DATA_LOSS: string;
|
|
25
|
-
UNAUTHENTICATED: string;
|
|
26
|
-
}
|
|
27
|
-
interface AuthenticationErrorReason {
|
|
28
|
-
ACCOUNT_LOCKED: string;
|
|
29
|
-
ACCOUNT_EXPIRED: string;
|
|
30
|
-
ACCOUNT_INACTIVE: string;
|
|
31
|
-
ACCOUNT_DISABLED: string;
|
|
32
|
-
ACCOUNT_SUSPENDED: string;
|
|
33
|
-
ACCESS_DENIED: string;
|
|
34
|
-
ACCESS_TOKEN_REQUIRED: string;
|
|
35
|
-
PASSWORD_MISMATCH: string;
|
|
36
|
-
USERNAME_ALREADY_EXISTS: string;
|
|
37
|
-
VERIFICATION_CODE_MISMATCH: string;
|
|
38
|
-
VERIFICATION_CODE_SEND_FAILED: string;
|
|
39
|
-
}
|
|
40
|
-
interface ModerationErrorReason {
|
|
41
|
-
POSSIBLY_SENSITIVE: string;
|
|
42
|
-
ADULT_CONTENT: string;
|
|
43
|
-
NUDITY_CONTENT: string;
|
|
44
|
-
SEXUAL_CONTENT: string;
|
|
45
|
-
BLOODY_CONTENT: string;
|
|
46
|
-
WEAPON_CONTENT: string;
|
|
47
|
-
POLITICS_CONTENT: string;
|
|
48
|
-
VIOLENCE_CONTENT: string;
|
|
49
|
-
ABUSE_CONTENT: string;
|
|
50
|
-
ADVERTISEMENT_CONTENT: string;
|
|
51
|
-
CONTRABAND_CONTENT: string;
|
|
52
|
-
SPAM_CONTENT: string;
|
|
53
|
-
MEANINGLESS_CONTENT: string;
|
|
54
|
-
UNSAFE_TEXT_DETECTED: string;
|
|
55
|
-
}
|
|
56
|
-
interface MultipartErrorReason {
|
|
57
|
-
MAX_UPLOAD_SIZE_EXCEEDED: string;
|
|
58
|
-
MEDIA_TYPE_NOT_SUPPORTED: string;
|
|
59
|
-
MEDIA_TYPE_NOT_ACCEPTABLE: string;
|
|
60
|
-
}
|
|
61
|
-
interface AppErrorReason {
|
|
62
|
-
NOT_SUBSCRIBED: string;
|
|
63
|
-
CREDIT_NOT_ENOUGH: string;
|
|
64
|
-
ALREADY_SUBSCRIBED_AT_OTHER_PLATFORM: string;
|
|
65
|
-
}
|
|
66
|
-
type ErrorReason = NetworkErrorReason & StatusErrorReason & AuthenticationErrorReason & ModerationErrorReason & MultipartErrorReason & AppErrorReason;
|
|
67
|
-
|
|
68
|
-
declare enum DetailType {
|
|
69
|
-
ERROR_INFO = "ERROR_INFO",
|
|
70
|
-
RETRY_INFO = "RETRY_INFO",
|
|
71
|
-
DEBUG_INFO = "DEBUG_INFO",
|
|
72
|
-
QUOTA_FAILURE = "QUOTA_FAILURE",
|
|
73
|
-
PRECONDITION_FAILURE = "PRECONDITION_FAILURE",
|
|
74
|
-
BAD_REQUEST = "BAD_REQUEST",
|
|
75
|
-
REQUEST_INFO = "REQUEST_INFO",
|
|
76
|
-
RESOURCE_INFO = "RESOURCE_INFO",
|
|
77
|
-
HELP = "HELP",
|
|
78
|
-
LOCALIZED_MESSAGE = "LOCALIZED_MESSAGE"
|
|
79
|
-
}
|
|
80
|
-
interface ErrorInfo {
|
|
81
|
-
type: DetailType.ERROR_INFO;
|
|
82
|
-
reason: keyof ErrorReason;
|
|
83
|
-
domain?: string;
|
|
84
|
-
metadata?: {
|
|
85
|
-
[key: string]: string;
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
interface RetryInfo {
|
|
89
|
-
type: DetailType.RETRY_INFO;
|
|
90
|
-
retryDelay: number;
|
|
91
|
-
}
|
|
92
|
-
interface DebugInfo {
|
|
93
|
-
type: DetailType.DEBUG_INFO;
|
|
94
|
-
stackEntries: string[];
|
|
95
|
-
detail?: string;
|
|
96
|
-
}
|
|
97
|
-
interface QuotaFailure {
|
|
98
|
-
type: DetailType.QUOTA_FAILURE;
|
|
99
|
-
violations: {
|
|
100
|
-
subject: string;
|
|
101
|
-
description: string;
|
|
102
|
-
}[];
|
|
103
|
-
}
|
|
104
|
-
interface PreconditionFailure {
|
|
105
|
-
type: DetailType.PRECONDITION_FAILURE;
|
|
106
|
-
violations: {
|
|
107
|
-
type: string;
|
|
108
|
-
subject: string;
|
|
109
|
-
description: string;
|
|
110
|
-
}[];
|
|
111
|
-
}
|
|
112
|
-
interface BadRequest {
|
|
113
|
-
type: DetailType.BAD_REQUEST;
|
|
114
|
-
fieldViolations: {
|
|
115
|
-
field: string;
|
|
116
|
-
description: string;
|
|
117
|
-
}[];
|
|
118
|
-
}
|
|
119
|
-
interface RequestInfo {
|
|
120
|
-
type: DetailType.REQUEST_INFO;
|
|
121
|
-
requestId: string;
|
|
122
|
-
servingData: string;
|
|
123
|
-
}
|
|
124
|
-
interface ResourceInfo {
|
|
125
|
-
type: DetailType.RESOURCE_INFO;
|
|
126
|
-
resourceType: string;
|
|
127
|
-
resourceName: string;
|
|
128
|
-
owner: string;
|
|
129
|
-
description: string;
|
|
130
|
-
}
|
|
131
|
-
interface Help {
|
|
132
|
-
type: DetailType.HELP;
|
|
133
|
-
links: {
|
|
134
|
-
url: string;
|
|
135
|
-
description: string;
|
|
136
|
-
}[];
|
|
137
|
-
}
|
|
138
|
-
interface LocalizedMessage {
|
|
139
|
-
type: DetailType.LOCALIZED_MESSAGE;
|
|
140
|
-
locale: string;
|
|
141
|
-
message: string;
|
|
142
|
-
}
|
|
143
|
-
type Detail = RetryInfo | DebugInfo | QuotaFailure | ErrorInfo | PreconditionFailure | BadRequest | RequestInfo | ResourceInfo | Help | LocalizedMessage;
|
|
144
|
-
/**
|
|
145
|
-
* Example usage:
|
|
146
|
-
* const details = Details.new()
|
|
147
|
-
* .requestInfo({ requestId: '1234567890', servingData: '/v1/tests' })
|
|
148
|
-
* .errorInfo({ reason: 'ACCOUNT_LOCKED' });
|
|
149
|
-
* */
|
|
150
|
-
declare class Details {
|
|
151
|
-
readonly list: Detail[];
|
|
152
|
-
private constructor();
|
|
153
|
-
static new(): Details;
|
|
154
|
-
errorInfo(detail: Omit<ErrorInfo, 'type'>): this;
|
|
155
|
-
retryInfo(detail: Omit<RetryInfo, 'type'>): this;
|
|
156
|
-
debugInfo(detail: Omit<DebugInfo, 'type'>): this;
|
|
157
|
-
quotaFailure(detail: Omit<QuotaFailure, 'type'>): this;
|
|
158
|
-
preconditionFailure(detail: Omit<PreconditionFailure, 'type'>): this;
|
|
159
|
-
badRequest(detail: Omit<BadRequest, 'type'>): this;
|
|
160
|
-
requestInfo(detail: Omit<RequestInfo, 'type'>): this;
|
|
161
|
-
resourceInfo(detail: Omit<ResourceInfo, 'type'>): this;
|
|
162
|
-
help(detail: Omit<Help, 'type'>): this;
|
|
163
|
-
localizedMessage(detail: Omit<LocalizedMessage, 'type'>): this;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
declare const Code: {
|
|
167
|
-
readonly OK: 200;
|
|
168
|
-
readonly CANCELLED: 499;
|
|
169
|
-
readonly UNKNOWN: 500;
|
|
170
|
-
readonly INVALID_ARGUMENT: 400;
|
|
171
|
-
readonly DEADLINE_EXCEEDED: 504;
|
|
172
|
-
readonly NOT_FOUND: 404;
|
|
173
|
-
readonly ALREADY_EXISTS: 409;
|
|
174
|
-
readonly PERMISSION_DENIED: 403;
|
|
175
|
-
readonly RESOURCE_EXHAUSTED: 429;
|
|
176
|
-
readonly FAILED_PRECONDITION: 400;
|
|
177
|
-
readonly ABORTED: 409;
|
|
178
|
-
readonly OUT_OF_RANGE: 400;
|
|
179
|
-
readonly UNIMPLEMENTED: 501;
|
|
180
|
-
readonly INTERNAL: 500;
|
|
181
|
-
readonly UNAVAILABLE: 503;
|
|
182
|
-
readonly DATA_LOSS: 500;
|
|
183
|
-
readonly UNAUTHENTICATED: 401;
|
|
184
|
-
readonly METHOD_NOT_ALLOWED: 405;
|
|
185
|
-
};
|
|
186
|
-
declare const DEFAULT_MESSAGES: Record<keyof typeof Code, string>;
|
|
187
|
-
interface ErrorBody {
|
|
188
|
-
error: {
|
|
189
|
-
code: number;
|
|
190
|
-
status: keyof typeof Code;
|
|
191
|
-
message: string;
|
|
192
|
-
details: Detail[];
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
declare class StatusError extends Error {
|
|
196
|
-
readonly status: number;
|
|
197
|
-
readonly body?: ErrorBody;
|
|
198
|
-
constructor(status: number, body?: ErrorBody);
|
|
199
|
-
}
|
|
200
|
-
declare class StatusCode {
|
|
201
|
-
code: keyof typeof Code;
|
|
202
|
-
message?: string;
|
|
203
|
-
private constructor();
|
|
204
|
-
static of(code: keyof typeof Code, message?: string): StatusCode;
|
|
205
|
-
body(details?: Details): ErrorBody;
|
|
206
|
-
error(details?: Details): Error;
|
|
207
|
-
response(details?: Details): Response;
|
|
208
|
-
}
|
|
209
|
-
declare class Status {
|
|
210
|
-
static adapter?: (status: number, response: ErrorBody) => Error;
|
|
211
|
-
static ok: (message?: string) => StatusCode;
|
|
212
|
-
static cancelled: (message?: string) => StatusCode;
|
|
213
|
-
static unknown: (message?: string) => StatusCode;
|
|
214
|
-
static invalidArgument: (message?: string) => StatusCode;
|
|
215
|
-
static deadlineExceeded: (message?: string) => StatusCode;
|
|
216
|
-
static notFound: (message?: string) => StatusCode;
|
|
217
|
-
static alreadyExists: (message?: string) => StatusCode;
|
|
218
|
-
static permissionDenied: (message?: string) => StatusCode;
|
|
219
|
-
static unauthorized: (message?: string) => StatusCode;
|
|
220
|
-
static resourceExhausted: (message?: string) => StatusCode;
|
|
221
|
-
static failedPrecondition: (message?: string) => StatusCode;
|
|
222
|
-
static aborted: (message?: string) => StatusCode;
|
|
223
|
-
static outOfRange: (message?: string) => StatusCode;
|
|
224
|
-
static unimplemented: (message?: string) => StatusCode;
|
|
225
|
-
static internal: (message?: string) => StatusCode;
|
|
226
|
-
static unavailable: (message?: string) => StatusCode;
|
|
227
|
-
static dataLoss: (message?: string) => StatusCode;
|
|
228
|
-
static methodNotAllowed: (message?: string) => StatusCode;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
type Result<S extends ZodSchema> = {
|
|
232
|
-
data: z.infer<S>;
|
|
233
|
-
error: null;
|
|
234
|
-
} | {
|
|
235
|
-
data: null;
|
|
236
|
-
error: Response;
|
|
237
|
-
};
|
|
238
|
-
type Target = 'json' | 'form' | 'query' | 'param' | 'header' | 'cookie';
|
|
239
|
-
declare function valid<S extends ZodSchema>(request: Request, target: Target, schema: S): Promise<Result<S>>;
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* A distributed unique ID generator inspired by Twitter's Snowflake.
|
|
243
|
-
*
|
|
244
|
-
* ID data bits:
|
|
245
|
-
* +----------------------+----------------+-----------+
|
|
246
|
-
* | delta millisecond | machine id | sequence |
|
|
247
|
-
* +----------------------+----------------+-----------+
|
|
248
|
-
* | 41bits | 10bits | 12bits |
|
|
249
|
-
* +----------------------+----------------+-----------+
|
|
250
|
-
*
|
|
251
|
-
*/
|
|
252
|
-
declare class UidGenerator {
|
|
253
|
-
readonly MAX: bigint;
|
|
254
|
-
private readonly machineBits;
|
|
255
|
-
private readonly sequenceBits;
|
|
256
|
-
private readonly epochMillisecond;
|
|
257
|
-
private readonly sequenceMask;
|
|
258
|
-
private readonly maxMachineId;
|
|
259
|
-
private readonly machineIdShift;
|
|
260
|
-
private readonly timeStampShift;
|
|
261
|
-
private readonly machineId;
|
|
262
|
-
private sequence;
|
|
263
|
-
private lastTimestamp;
|
|
264
|
-
constructor(mackineId: number);
|
|
265
|
-
readonly next: () => bigint;
|
|
266
|
-
}
|
|
267
|
-
declare const uid: UidGenerator;
|
|
268
|
-
|
|
269
|
-
export { type AppErrorReason, type AuthenticationErrorReason, type BadRequest, Code, DEFAULT_MESSAGES, type DebugInfo, type Detail, DetailType, Details, type ErrorBody, type ErrorInfo, type ErrorReason, type Help, type LocalizedMessage, type ModerationErrorReason, type MultipartErrorReason, type NetworkErrorReason, type PreconditionFailure, type QuotaFailure, type RequestInfo, type ResourceInfo, type Result, type RetryInfo, Status, StatusCode, StatusError, type StatusErrorReason, UidGenerator, uid, valid };
|
|
1
|
+
export { AppErrorReason, AuthenticationErrorReason, ErrorReason, ModerationErrorReason, MultipartErrorReason, NetworkErrorReason, StatusErrorReason } from './reason.js';
|
|
2
|
+
export { BadRequest, DebugInfo, Detail, DetailType, Details, ErrorInfo, Help, LocalizedMessage, PreconditionFailure, QuotaFailure, RequestInfo, ResourceInfo, RetryInfo } from './detail.js';
|
|
3
|
+
export { Code, DEFAULT_MESSAGES, ErrorBody, Status, StatusCode, StatusError } from './status.js';
|
|
4
|
+
export { Result, valid } from './vaild.js';
|
|
5
|
+
export { UidGenerator, uid } from './snowflake.js';
|
|
6
|
+
import 'zod';
|