@orpc/contract 0.0.0-next.ed15210 → 0.0.0-next.ed8babc

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.js DELETED
@@ -1,527 +0,0 @@
1
- // src/procedure.ts
2
- var ContractProcedure = class {
3
- "~type" = "ContractProcedure";
4
- "~orpc";
5
- constructor(def) {
6
- if (def.route?.successStatus && (def.route.successStatus < 200 || def.route?.successStatus > 299)) {
7
- throw new Error("[ContractProcedure] The successStatus must be between 200 and 299");
8
- }
9
- if (Object.values(def.errorMap).some((val) => val && val.status && (val.status < 400 || val.status > 599))) {
10
- throw new Error("[ContractProcedure] The error status code must be in the 400-599 range.");
11
- }
12
- this["~orpc"] = def;
13
- }
14
- };
15
- function isContractProcedure(item) {
16
- if (item instanceof ContractProcedure) {
17
- return true;
18
- }
19
- return (typeof item === "object" || typeof item === "function") && item !== null && "~type" in item && item["~type"] === "ContractProcedure" && "~orpc" in item && typeof item["~orpc"] === "object" && item["~orpc"] !== null && "InputSchema" in item["~orpc"] && "OutputSchema" in item["~orpc"] && "errorMap" in item["~orpc"] && "route" in item["~orpc"];
20
- }
21
-
22
- // src/route.ts
23
- function mergeRoute(a, b) {
24
- return {
25
- ...a,
26
- ...b
27
- };
28
- }
29
- function prefixRoute(route, prefix) {
30
- if (!route.path) {
31
- return route;
32
- }
33
- return {
34
- ...route,
35
- path: `${prefix}${route.path}`
36
- };
37
- }
38
- function unshiftTagRoute(route, tags) {
39
- return {
40
- ...route,
41
- tags: [...tags, ...route.tags ?? []]
42
- };
43
- }
44
- function mergePrefix(a, b) {
45
- return a ? `${a}${b}` : b;
46
- }
47
- function mergeTags(a, b) {
48
- return a ? [...a, ...b] : b;
49
- }
50
-
51
- // src/procedure-decorated.ts
52
- var DecoratedContractProcedure = class _DecoratedContractProcedure extends ContractProcedure {
53
- static decorate(procedure) {
54
- if (procedure instanceof _DecoratedContractProcedure) {
55
- return procedure;
56
- }
57
- return new _DecoratedContractProcedure(procedure["~orpc"]);
58
- }
59
- errors(errors) {
60
- return new _DecoratedContractProcedure({
61
- ...this["~orpc"],
62
- errorMap: {
63
- ...this["~orpc"].errorMap,
64
- ...errors
65
- }
66
- });
67
- }
68
- route(route) {
69
- return new _DecoratedContractProcedure({
70
- ...this["~orpc"],
71
- route: mergeRoute(this["~orpc"].route, route)
72
- });
73
- }
74
- prefix(prefix) {
75
- return new _DecoratedContractProcedure({
76
- ...this["~orpc"],
77
- route: prefixRoute(this["~orpc"].route, prefix)
78
- });
79
- }
80
- unshiftTag(...tags) {
81
- return new _DecoratedContractProcedure({
82
- ...this["~orpc"],
83
- route: unshiftTagRoute(this["~orpc"].route, tags)
84
- });
85
- }
86
- };
87
-
88
- // src/procedure-builder-with-input.ts
89
- var ContractProcedureBuilderWithInput = class _ContractProcedureBuilderWithInput extends ContractProcedure {
90
- errors(errors) {
91
- const decorated = DecoratedContractProcedure.decorate(this).errors(errors);
92
- return new _ContractProcedureBuilderWithInput(decorated["~orpc"]);
93
- }
94
- route(route) {
95
- const decorated = DecoratedContractProcedure.decorate(this).route(route);
96
- return new _ContractProcedureBuilderWithInput(decorated["~orpc"]);
97
- }
98
- prefix(prefix) {
99
- const decorated = DecoratedContractProcedure.decorate(this).prefix(prefix);
100
- return new _ContractProcedureBuilderWithInput(decorated["~orpc"]);
101
- }
102
- unshiftTag(...tags) {
103
- const decorated = DecoratedContractProcedure.decorate(this).unshiftTag(...tags);
104
- return new _ContractProcedureBuilderWithInput(decorated["~orpc"]);
105
- }
106
- output(schema, example) {
107
- return new DecoratedContractProcedure({
108
- ...this["~orpc"],
109
- OutputSchema: schema,
110
- outputExample: example
111
- });
112
- }
113
- };
114
-
115
- // src/procedure-builder-with-output.ts
116
- var ContractProcedureBuilderWithOutput = class _ContractProcedureBuilderWithOutput extends ContractProcedure {
117
- errors(errors) {
118
- const decorated = DecoratedContractProcedure.decorate(this).errors(errors);
119
- return new _ContractProcedureBuilderWithOutput(decorated["~orpc"]);
120
- }
121
- route(route) {
122
- const decorated = DecoratedContractProcedure.decorate(this).route(route);
123
- return new _ContractProcedureBuilderWithOutput(decorated["~orpc"]);
124
- }
125
- prefix(prefix) {
126
- const decorated = DecoratedContractProcedure.decorate(this).prefix(prefix);
127
- return new _ContractProcedureBuilderWithOutput(decorated["~orpc"]);
128
- }
129
- unshiftTag(...tags) {
130
- const decorated = DecoratedContractProcedure.decorate(this).unshiftTag(...tags);
131
- return new _ContractProcedureBuilderWithOutput(decorated["~orpc"]);
132
- }
133
- input(schema, example) {
134
- return new DecoratedContractProcedure({
135
- ...this["~orpc"],
136
- InputSchema: schema,
137
- inputExample: example
138
- });
139
- }
140
- };
141
-
142
- // src/procedure-builder.ts
143
- var ContractProcedureBuilder = class _ContractProcedureBuilder extends ContractProcedure {
144
- errors(errors) {
145
- const decorated = DecoratedContractProcedure.decorate(this).errors(errors);
146
- return new _ContractProcedureBuilder(decorated["~orpc"]);
147
- }
148
- route(route) {
149
- const decorated = DecoratedContractProcedure.decorate(this).route(route);
150
- return new _ContractProcedureBuilder(decorated["~orpc"]);
151
- }
152
- prefix(prefix) {
153
- const decorated = DecoratedContractProcedure.decorate(this).prefix(prefix);
154
- return new _ContractProcedureBuilder(decorated["~orpc"]);
155
- }
156
- unshiftTag(...tags) {
157
- const decorated = DecoratedContractProcedure.decorate(this).unshiftTag(...tags);
158
- return new _ContractProcedureBuilder(decorated["~orpc"]);
159
- }
160
- input(schema, example) {
161
- return new ContractProcedureBuilderWithInput({
162
- ...this["~orpc"],
163
- InputSchema: schema,
164
- inputExample: example
165
- });
166
- }
167
- output(schema, example) {
168
- return new ContractProcedureBuilderWithOutput({
169
- ...this["~orpc"],
170
- OutputSchema: schema,
171
- outputExample: example
172
- });
173
- }
174
- };
175
-
176
- // src/router-builder.ts
177
- var ContractRouterBuilder = class _ContractRouterBuilder {
178
- "~type" = "ContractProcedure";
179
- "~orpc";
180
- constructor(def) {
181
- this["~orpc"] = def;
182
- }
183
- prefix(prefix) {
184
- return new _ContractRouterBuilder({
185
- ...this["~orpc"],
186
- prefix: mergePrefix(this["~orpc"].prefix, prefix)
187
- });
188
- }
189
- tag(...tags) {
190
- return new _ContractRouterBuilder({
191
- ...this["~orpc"],
192
- tags: mergeTags(this["~orpc"].tags, tags)
193
- });
194
- }
195
- errors(errors) {
196
- return new _ContractRouterBuilder({
197
- ...this["~orpc"],
198
- errorMap: {
199
- ...this["~orpc"].errorMap,
200
- ...errors
201
- }
202
- });
203
- }
204
- router(router) {
205
- if (isContractProcedure(router)) {
206
- let decorated = DecoratedContractProcedure.decorate(router);
207
- if (this["~orpc"].tags) {
208
- decorated = decorated.unshiftTag(...this["~orpc"].tags);
209
- }
210
- if (this["~orpc"].prefix) {
211
- decorated = decorated.prefix(this["~orpc"].prefix);
212
- }
213
- decorated = decorated.errors(this["~orpc"].errorMap);
214
- return decorated;
215
- }
216
- const adapted = {};
217
- for (const key in router) {
218
- adapted[key] = this.router(router[key]);
219
- }
220
- return adapted;
221
- }
222
- };
223
-
224
- // src/builder.ts
225
- var ContractBuilder = class _ContractBuilder extends ContractProcedure {
226
- constructor(def) {
227
- super(def);
228
- this["~orpc"].config = def.config;
229
- }
230
- config(config) {
231
- return new _ContractBuilder({
232
- ...this["~orpc"],
233
- config: {
234
- ...this["~orpc"].config,
235
- ...config
236
- }
237
- });
238
- }
239
- errors(errors) {
240
- return new _ContractBuilder({
241
- ...this["~orpc"],
242
- errorMap: {
243
- ...this["~orpc"].errorMap,
244
- ...errors
245
- }
246
- });
247
- }
248
- route(route) {
249
- return new ContractProcedureBuilder({
250
- route: mergeRoute(this["~orpc"].route, route),
251
- InputSchema: void 0,
252
- OutputSchema: void 0,
253
- errorMap: this["~orpc"].errorMap
254
- });
255
- }
256
- input(schema, example) {
257
- return new ContractProcedureBuilderWithInput({
258
- route: this["~orpc"].route,
259
- InputSchema: schema,
260
- inputExample: example,
261
- OutputSchema: void 0,
262
- errorMap: this["~orpc"].errorMap
263
- });
264
- }
265
- output(schema, example) {
266
- return new ContractProcedureBuilderWithOutput({
267
- route: this["~orpc"].route,
268
- OutputSchema: schema,
269
- outputExample: example,
270
- InputSchema: void 0,
271
- errorMap: this["~orpc"].errorMap
272
- });
273
- }
274
- prefix(prefix) {
275
- return new ContractRouterBuilder({
276
- prefix,
277
- errorMap: this["~orpc"].errorMap,
278
- tags: void 0
279
- });
280
- }
281
- tag(...tags) {
282
- return new ContractRouterBuilder({
283
- tags,
284
- errorMap: this["~orpc"].errorMap,
285
- prefix: void 0
286
- });
287
- }
288
- router(router) {
289
- return new ContractRouterBuilder({
290
- errorMap: this["~orpc"].errorMap,
291
- prefix: void 0,
292
- tags: void 0
293
- }).router(router);
294
- }
295
- };
296
-
297
- // src/error-orpc.ts
298
- import { isPlainObject } from "@orpc/shared";
299
- var COMMON_ORPC_ERROR_DEFS = {
300
- BAD_REQUEST: {
301
- status: 400,
302
- message: "Bad Request"
303
- },
304
- UNAUTHORIZED: {
305
- status: 401,
306
- message: "Unauthorized"
307
- },
308
- FORBIDDEN: {
309
- status: 403,
310
- message: "Forbidden"
311
- },
312
- NOT_FOUND: {
313
- status: 404,
314
- message: "Not Found"
315
- },
316
- METHOD_NOT_SUPPORTED: {
317
- status: 405,
318
- message: "Method Not Supported"
319
- },
320
- NOT_ACCEPTABLE: {
321
- status: 406,
322
- message: "Not Acceptable"
323
- },
324
- TIMEOUT: {
325
- status: 408,
326
- message: "Request Timeout"
327
- },
328
- CONFLICT: {
329
- status: 409,
330
- message: "Conflict"
331
- },
332
- PRECONDITION_FAILED: {
333
- status: 412,
334
- message: "Precondition Failed"
335
- },
336
- PAYLOAD_TOO_LARGE: {
337
- status: 413,
338
- message: "Payload Too Large"
339
- },
340
- UNSUPPORTED_MEDIA_TYPE: {
341
- status: 415,
342
- message: "Unsupported Media Type"
343
- },
344
- UNPROCESSABLE_CONTENT: {
345
- status: 422,
346
- message: "Unprocessable Content"
347
- },
348
- TOO_MANY_REQUESTS: {
349
- status: 429,
350
- message: "Too Many Requests"
351
- },
352
- CLIENT_CLOSED_REQUEST: {
353
- status: 499,
354
- message: "Client Closed Request"
355
- },
356
- INTERNAL_SERVER_ERROR: {
357
- status: 500,
358
- message: "Internal Server Error"
359
- },
360
- NOT_IMPLEMENTED: {
361
- status: 501,
362
- message: "Not Implemented"
363
- },
364
- BAD_GATEWAY: {
365
- status: 502,
366
- message: "Bad Gateway"
367
- },
368
- SERVICE_UNAVAILABLE: {
369
- status: 503,
370
- message: "Service Unavailable"
371
- },
372
- GATEWAY_TIMEOUT: {
373
- status: 504,
374
- message: "Gateway Timeout"
375
- }
376
- };
377
- function fallbackORPCErrorStatus(code, status) {
378
- return status ?? COMMON_ORPC_ERROR_DEFS[code]?.status ?? 500;
379
- }
380
- function fallbackORPCErrorMessage(code, message) {
381
- return message || COMMON_ORPC_ERROR_DEFS[code]?.message || code;
382
- }
383
- var ORPCError = class extends Error {
384
- defined;
385
- code;
386
- status;
387
- data;
388
- constructor(options) {
389
- if (options.status && (options.status < 400 || options.status >= 600)) {
390
- throw new Error("[ORPCError] The error status code must be in the 400-599 range.");
391
- }
392
- const message = fallbackORPCErrorMessage(options.code, options.message);
393
- super(message, options);
394
- this.code = options.code;
395
- this.status = fallbackORPCErrorStatus(options.code, options.status);
396
- this.defined = options.defined ?? false;
397
- this.data = options.data;
398
- }
399
- toJSON() {
400
- return {
401
- defined: this.defined,
402
- code: this.code,
403
- status: this.status,
404
- message: this.message,
405
- data: this.data
406
- };
407
- }
408
- static isValidJSON(json) {
409
- return isPlainObject(json) && "defined" in json && typeof json.defined === "boolean" && "code" in json && typeof json.code === "string" && "status" in json && typeof json.status === "number" && "message" in json && typeof json.message === "string";
410
- }
411
- };
412
- function isDefinedError(error) {
413
- return error instanceof ORPCError && error.defined;
414
- }
415
- async function validateORPCError(map, error) {
416
- const { code, status, message, data, cause, defined } = error;
417
- const config = map?.[error.code];
418
- if (!config || fallbackORPCErrorStatus(error.code, config.status) !== error.status) {
419
- return defined ? new ORPCError({ defined: false, code, status, message, data, cause }) : error;
420
- }
421
- if (!config.data) {
422
- return defined ? error : new ORPCError({ defined: true, code, status, message, data, cause });
423
- }
424
- const validated = await config.data["~standard"].validate(error.data);
425
- if (validated.issues) {
426
- return defined ? new ORPCError({ defined: false, code, status, message, data, cause }) : error;
427
- }
428
- return new ORPCError({
429
- defined: true,
430
- code,
431
- status,
432
- message,
433
- data: validated.value,
434
- cause
435
- });
436
- }
437
-
438
- // src/client-utils.ts
439
- async function safe(promise) {
440
- try {
441
- const output = await promise;
442
- return [output, void 0, false];
443
- } catch (e) {
444
- const error = e;
445
- if (isDefinedError(error)) {
446
- return [void 0, error, true];
447
- }
448
- return [void 0, error, false];
449
- }
450
- }
451
-
452
- // src/config.ts
453
- var DEFAULT_CONFIG = {
454
- defaultMethod: "POST",
455
- defaultSuccessStatus: 200,
456
- defaultSuccessDescription: "OK",
457
- defaultInputStructure: "compact",
458
- defaultOutputStructure: "compact",
459
- defaultInitialRoute: {}
460
- };
461
- function fallbackContractConfig(key, value) {
462
- if (value === void 0) {
463
- return DEFAULT_CONFIG[key];
464
- }
465
- return value;
466
- }
467
-
468
- // src/error.ts
469
- var ValidationError = class extends Error {
470
- issues;
471
- constructor(options) {
472
- super(options.message, options);
473
- this.issues = options.issues;
474
- }
475
- };
476
-
477
- // src/schema-utils.ts
478
- function type(...[map]) {
479
- return {
480
- "~standard": {
481
- vendor: "custom",
482
- version: 1,
483
- async validate(value) {
484
- if (map) {
485
- return { value: await map(value) };
486
- }
487
- return { value };
488
- }
489
- }
490
- };
491
- }
492
-
493
- // src/index.ts
494
- var oc = new ContractBuilder({
495
- config: {},
496
- route: {},
497
- errorMap: {},
498
- InputSchema: void 0,
499
- OutputSchema: void 0
500
- });
501
- export {
502
- COMMON_ORPC_ERROR_DEFS,
503
- ContractBuilder,
504
- ContractProcedure,
505
- ContractProcedureBuilder,
506
- ContractProcedureBuilderWithInput,
507
- ContractProcedureBuilderWithOutput,
508
- ContractRouterBuilder,
509
- DecoratedContractProcedure,
510
- ORPCError,
511
- ValidationError,
512
- fallbackContractConfig,
513
- fallbackORPCErrorMessage,
514
- fallbackORPCErrorStatus,
515
- isContractProcedure,
516
- isDefinedError,
517
- mergePrefix,
518
- mergeRoute,
519
- mergeTags,
520
- oc,
521
- prefixRoute,
522
- safe,
523
- type,
524
- unshiftTagRoute,
525
- validateORPCError
526
- };
527
- //# sourceMappingURL=index.js.map
@@ -1,32 +0,0 @@
1
- import type { ErrorMap, ErrorMapGuard, ErrorMapSuggestions, StrictErrorMap } from './error-map';
2
- import type { ContractProcedureDef } from './procedure';
3
- import type { HTTPPath, MergeRoute, Route, StrictRoute } from './route';
4
- import type { ContractRouter } from './router';
5
- import type { AdaptedContractRouter } from './router-builder';
6
- import type { Schema, SchemaInput, SchemaOutput } from './types';
7
- import { ContractProcedure } from './procedure';
8
- import { ContractProcedureBuilder } from './procedure-builder';
9
- import { ContractProcedureBuilderWithInput } from './procedure-builder-with-input';
10
- import { ContractProcedureBuilderWithOutput } from './procedure-builder-with-output';
11
- import { ContractRouterBuilder } from './router-builder';
12
- export interface ContractBuilderConfig {
13
- initialRoute?: Route;
14
- }
15
- export type MergeContractBuilderConfig<A extends ContractBuilderConfig, B extends ContractBuilderConfig> = Omit<A, keyof B> & B;
16
- export type GetInitialRoute<T extends ContractBuilderConfig> = T['initialRoute'] extends Route ? T['initialRoute'] : Record<never, never>;
17
- export interface ContractBuilderDef<TConfig extends ContractBuilderConfig, TErrorMap extends ErrorMap> extends ContractProcedureDef<undefined, undefined, TErrorMap, StrictRoute<GetInitialRoute<TConfig>>> {
18
- config: TConfig;
19
- }
20
- export declare class ContractBuilder<TConfig extends ContractBuilderConfig, TErrorMap extends ErrorMap> extends ContractProcedure<undefined, undefined, TErrorMap, GetInitialRoute<TConfig>> {
21
- '~orpc': ContractBuilderDef<TConfig, TErrorMap>;
22
- constructor(def: ContractBuilderDef<TConfig, TErrorMap>);
23
- config<const U extends ContractBuilderConfig>(config: U): ContractBuilder<MergeContractBuilderConfig<TConfig, U>, TErrorMap>;
24
- errors<const U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): ContractBuilder<TConfig, StrictErrorMap<U> & TErrorMap>;
25
- route<const U extends Route>(route: U): ContractProcedureBuilder<TErrorMap, MergeRoute<StrictRoute<GetInitialRoute<TConfig>>, U>>;
26
- input<U extends Schema>(schema: U, example?: SchemaInput<U>): ContractProcedureBuilderWithInput<U, TErrorMap, StrictRoute<GetInitialRoute<TConfig>>>;
27
- output<U extends Schema>(schema: U, example?: SchemaOutput<U>): ContractProcedureBuilderWithOutput<U, TErrorMap, StrictRoute<GetInitialRoute<TConfig>>>;
28
- prefix<U extends HTTPPath>(prefix: U): ContractRouterBuilder<TErrorMap, U, undefined>;
29
- tag<U extends string[]>(...tags: U): ContractRouterBuilder<TErrorMap, undefined, U>;
30
- router<T extends ContractRouter<ErrorMap & Partial<TErrorMap>>>(router: T): AdaptedContractRouter<T, TErrorMap, undefined, undefined>;
31
- }
32
- //# sourceMappingURL=builder.d.ts.map
@@ -1,5 +0,0 @@
1
- import type { ClientPromiseResult } from './client';
2
- import { type ORPCError } from './error-orpc';
3
- export type SafeResult<TOutput, TError extends Error> = [output: TOutput, error: undefined, isDefinedError: false] | [output: undefined, error: TError, isDefinedError: false] | [output: undefined, error: Extract<TError, ORPCError<any, any>>, isDefinedError: true];
4
- export declare function safe<TOutput, TError extends Error>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
5
- //# sourceMappingURL=client-utils.d.ts.map
@@ -1,19 +0,0 @@
1
- import type { AbortSignal } from './types';
2
- export type ClientOptions<TClientContext> = {
3
- signal?: AbortSignal;
4
- } & (undefined extends TClientContext ? {
5
- context?: TClientContext;
6
- } : {
7
- context: TClientContext;
8
- });
9
- export type ClientRest<TClientContext, TInput> = [input: TInput, options: ClientOptions<TClientContext>] | (undefined extends TInput & TClientContext ? [] : never) | (undefined extends TClientContext ? [input: TInput] : never);
10
- export type ClientPromiseResult<TOutput, TError extends Error> = Promise<TOutput> & {
11
- __typeError?: TError;
12
- };
13
- export interface Client<TClientContext, TInput, TOutput, TError extends Error> {
14
- (...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
15
- }
16
- export type NestedClient<TClientContext> = Client<TClientContext, any, any, any> | {
17
- [k: string]: NestedClient<TClientContext>;
18
- };
19
- //# sourceMappingURL=client.d.ts.map
@@ -1,11 +0,0 @@
1
- import type { HTTPMethod, InputStructure, Route } from './route';
2
- export interface ContractConfig {
3
- defaultMethod: HTTPMethod;
4
- defaultSuccessStatus: number;
5
- defaultSuccessDescription: string;
6
- defaultInputStructure: InputStructure;
7
- defaultOutputStructure: InputStructure;
8
- defaultInitialRoute: Route;
9
- }
10
- export declare function fallbackContractConfig<T extends keyof ContractConfig>(key: T, value: ContractConfig[T] | undefined): ContractConfig[T];
11
- //# sourceMappingURL=config.d.ts.map
@@ -1,58 +0,0 @@
1
- import type { CommonORPCErrorCode } from './error-orpc';
2
- import type { Schema } from './types';
3
- export type ErrorMapItem<TDataSchema extends Schema> = {
4
- /**
5
- *
6
- * @default 500
7
- */
8
- status?: number;
9
- message?: string;
10
- description?: string;
11
- data?: TDataSchema;
12
- };
13
- export interface ErrorMap {
14
- [k: string]: ErrorMapItem<Schema>;
15
- }
16
- /**
17
- * const U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions
18
- *
19
- * Purpose:
20
- * - Helps `U` suggest `CommonORPCErrorCode` to the user when typing.
21
- *
22
- * Why not replace `ErrorMap` with `ErrorMapSuggestions`?
23
- * - `ErrorMapSuggestions` has a drawback: it allows `undefined` values for items.
24
- * - `ErrorMapGuard<TErrorMap>` uses `Partial`, which can introduce `undefined` values.
25
- *
26
- * This could lead to unintended behavior where `undefined` values override `TErrorMap`,
27
- * potentially resulting in a `never` type after merging.
28
- *
29
- * Recommendation:
30
- * - Use `ErrorMapSuggestions` to assist users in typing correctly but do not replace `ErrorMap`.
31
- * - Ensure `ErrorMapGuard<TErrorMap>` is adjusted to prevent `undefined` values.
32
- */
33
- export type ErrorMapSuggestions = {
34
- [key in CommonORPCErrorCode | (string & {})]?: ErrorMapItem<Schema>;
35
- };
36
- /**
37
- * `U` extends `ErrorMap` & `ErrorMapGuard<TErrorMap>`
38
- *
39
- * `ErrorMapGuard` is a utility type that ensures `U` cannot redefine the structure of `TErrorMap`.
40
- * It achieves this by setting each key in `TErrorMap` to `never`, effectively preventing any redefinition.
41
- *
42
- * Why not just use `Partial<TErrorMap>`?
43
- * - Allowing users to redefine existing error map items would require using `StrictErrorMap`.
44
- * - However, I prefer not to use `StrictErrorMap` frequently, due to perceived performance concerns,
45
- * though this has not been benchmarked and is based on personal preference.
46
- *
47
- */
48
- export type ErrorMapGuard<TErrorMap extends ErrorMap> = {
49
- [K in keyof TErrorMap]?: never;
50
- };
51
- /**
52
- * Since `undefined` has a specific meaning (it use default value),
53
- * we ensure all additional properties in each item of the ErrorMap are explicitly set to `undefined`.
54
- */
55
- export type StrictErrorMap<T extends ErrorMap> = {
56
- [K in keyof T]: T[K] & Partial<Record<Exclude<keyof ErrorMapItem<any>, keyof T[K]>, undefined>>;
57
- };
58
- //# sourceMappingURL=error-map.d.ts.map