@temporary-name/server 1.9.3-alpha.0d2fa3247b6b23bbc2e3097a95f631b86740e4d8 → 1.9.3-alpha.0f2e1f4d66464608b85c66977bff51174cbb238f

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 (39) hide show
  1. package/dist/adapters/aws-lambda/index.d.mts +12 -7
  2. package/dist/adapters/aws-lambda/index.d.ts +12 -7
  3. package/dist/adapters/aws-lambda/index.mjs +12 -4
  4. package/dist/adapters/fetch/index.d.mts +12 -7
  5. package/dist/adapters/fetch/index.d.ts +12 -7
  6. package/dist/adapters/fetch/index.mjs +12 -11
  7. package/dist/adapters/node/index.d.mts +12 -7
  8. package/dist/adapters/node/index.d.ts +12 -7
  9. package/dist/adapters/node/index.mjs +12 -11
  10. package/dist/adapters/standard/index.d.mts +27 -13
  11. package/dist/adapters/standard/index.d.ts +27 -13
  12. package/dist/adapters/standard/index.mjs +8 -100
  13. package/dist/helpers/index.mjs +3 -29
  14. package/dist/index.d.mts +82 -459
  15. package/dist/index.d.ts +82 -459
  16. package/dist/index.mjs +213 -366
  17. package/dist/openapi/index.d.mts +220 -0
  18. package/dist/openapi/index.d.ts +220 -0
  19. package/dist/openapi/index.mjs +709 -0
  20. package/dist/plugins/index.d.mts +5 -83
  21. package/dist/plugins/index.d.ts +5 -83
  22. package/dist/plugins/index.mjs +17 -189
  23. package/dist/shared/{server.Btxrgkj5.d.ts → server.25yUS-xw.d.mts} +7 -25
  24. package/dist/shared/server.BKwU5-Ea.d.mts +23 -0
  25. package/dist/shared/server.C1RJffw4.mjs +30 -0
  26. package/dist/shared/{server.Bo94xDTv.d.mts → server.Co-zpS8Y.d.ts} +7 -25
  27. package/dist/shared/server.DRYRuXpK.mjs +254 -0
  28. package/dist/shared/server.DV_PWBS2.d.ts +23 -0
  29. package/dist/shared/server.DWEp52Gx.mjs +379 -0
  30. package/dist/shared/server.JtIZ8YG7.mjs +237 -0
  31. package/dist/shared/server.VtI8pLxV.d.mts +242 -0
  32. package/dist/shared/server.VtI8pLxV.d.ts +242 -0
  33. package/package.json +18 -23
  34. package/dist/shared/server.BEQrAa3A.mjs +0 -207
  35. package/dist/shared/server.C1YnHvvf.d.mts +0 -192
  36. package/dist/shared/server.C1YnHvvf.d.ts +0 -192
  37. package/dist/shared/server.D6K9uoPI.mjs +0 -35
  38. package/dist/shared/server.DZ5BIITo.mjs +0 -9
  39. package/dist/shared/server.X0YaZxSJ.mjs +0 -13
@@ -0,0 +1,242 @@
1
+ import { Meta, Schemas, ContractProcedureDef, AnyContractRouter, ContractProcedure, InferProcedureClientInputs, InferSchemaOutput, EnhanceRouteOptions, AnyContractProcedure, ContractRouter, AnySchema } from '@temporary-name/contract';
2
+ import { Promisable, StandardLazyRequest, HTTPPath, ClientContext, Interceptor, Value, Client, MaybeOptionalOptions } from '@temporary-name/shared';
3
+
4
+ type Context = Record<PropertyKey, any>;
5
+ type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
6
+ type MergedCurrentContext<T extends Context, U extends Context> = Omit<T, keyof U> & U;
7
+ type BuildContextWithAuth<TContext extends Context, TAuthContext> = MergedCurrentContext<TContext, {
8
+ auth: TAuthContext | ('auth' extends keyof TContext ? TContext['auth'] : never);
9
+ }>;
10
+ declare function mergeCurrentContext<T extends Context, U extends Context>(context: T, other: U): MergedCurrentContext<T, U>;
11
+
12
+ type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
13
+ output: TOutput;
14
+ context: TOutContext;
15
+ }>;
16
+ interface MiddlewareNextFn<TOutput> {
17
+ <U extends Context = {}>(options?: {
18
+ context?: U;
19
+ }): MiddlewareResult<U, TOutput>;
20
+ }
21
+ interface MiddlewareOutputFn<TOutput> {
22
+ (output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
23
+ }
24
+ interface MiddlewareOptions<TInContext extends Context, TOutput, TMeta extends Meta> extends ProcedureHandlerOptions<TInContext, TMeta> {
25
+ next: MiddlewareNextFn<TOutput>;
26
+ }
27
+ /**
28
+ * A function that represents a middleware.
29
+ *
30
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
31
+ */
32
+ interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TMeta extends Meta> {
33
+ (options: MiddlewareOptions<TInContext, TOutput, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
34
+ }
35
+ type AnyMiddleware = Middleware<any, any, any, any, any>;
36
+ interface MapInputMiddleware<TInput, TMappedInput> {
37
+ (input: TInput): TMappedInput;
38
+ }
39
+ declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
40
+
41
+ type DefaultProcedureHandlerOptions = ProcedureHandlerOptions<Context, Meta>;
42
+ interface ProcedureHandlerOptions<TCurrentContext extends Context, TMeta extends Meta> {
43
+ context: TCurrentContext;
44
+ path: readonly string[];
45
+ procedure: Procedure<Context, Context, Schemas, TMeta>;
46
+ signal?: AbortSignal;
47
+ request?: StandardLazyRequest;
48
+ lastEventId: string | undefined;
49
+ }
50
+ interface ProcedureHandler<TCurrentContext extends Context, TInput extends {
51
+ path: any;
52
+ query: any;
53
+ body: any;
54
+ }, THandlerOutput, TMeta extends Meta> {
55
+ (input: TInput, opt: ProcedureHandlerOptions<TCurrentContext, TMeta>): Promisable<THandlerOutput>;
56
+ }
57
+ interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TMeta extends Meta> extends ContractProcedureDef<TSchemas, TMeta> {
58
+ __initialContext?: (type: TInitialContext) => unknown;
59
+ middlewares: readonly AnyMiddleware[];
60
+ authConfigs: TypedAuthConfig[];
61
+ inputValidationIndex: number;
62
+ outputValidationIndex: number;
63
+ handler: ProcedureHandler<TCurrentContext, any, any, any>;
64
+ }
65
+ /**
66
+ * This class represents a procedure.
67
+ *
68
+ * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
69
+ */
70
+ declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TMeta extends Meta> {
71
+ /**
72
+ * This property holds the defined options.
73
+ */
74
+ '~orpc': ProcedureDef<TInitialContext, TCurrentContext, TSchemas, TMeta>;
75
+ constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TSchemas, TMeta>);
76
+ }
77
+ type AnyProcedure = Procedure<any, any, Schemas, any>;
78
+ declare function isProcedure(item: unknown): item is AnyProcedure;
79
+
80
+ type ValidatedAuthContext = {};
81
+ interface BasicAuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> {
82
+ tokenPrefix?: string;
83
+ validate: (username: string, password: string, options: ProcedureHandlerOptions<TCurrentContext, TMeta>) => Promisable<TAuthContext>;
84
+ }
85
+ interface TokenAuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> {
86
+ tokenPrefix?: string;
87
+ validate: (token: string, options: ProcedureHandlerOptions<TCurrentContext, TMeta>) => Promisable<TAuthContext>;
88
+ }
89
+ interface NamedTokenAuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> extends TokenAuthConfig<TAuthContext, TCurrentContext, TMeta> {
90
+ name: string;
91
+ }
92
+ type AuthType = 'header' | 'query' | 'cookie' | 'bearer' | 'basic' | 'none';
93
+ type AuthConfig<TAuthType extends AuthType, TAuthContext extends ValidatedAuthContext = ValidatedAuthContext, TCurrentContext extends Context = Context, TMeta extends Meta = Meta> = TAuthType extends 'basic' ? BasicAuthConfig<TAuthContext, TCurrentContext, TMeta> : TAuthType extends 'bearer' ? TokenAuthConfig<TAuthContext, TCurrentContext, TMeta> : TAuthType extends 'header' ? NamedTokenAuthConfig<TAuthContext, TCurrentContext, TMeta> : TAuthType extends 'query' ? NamedTokenAuthConfig<TAuthContext, TCurrentContext, TMeta> : TAuthType extends 'cookie' ? NamedTokenAuthConfig<TAuthContext, TCurrentContext, TMeta> : TAuthType extends 'none' ? {} : never;
94
+ type TypedAuthConfig<TAuthType extends AuthType = AuthType> = {
95
+ type: TAuthType;
96
+ } & AuthConfig<TAuthType, object>;
97
+
98
+ /**
99
+ * Represents a router, which defines a hierarchical structure of procedures.
100
+ *
101
+ * @info A procedure is a router too.
102
+ * @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#contract-router Contract Router Docs}
103
+ */
104
+ type Router<T extends AnyContractRouter, TInitialContext extends Context> = T extends ContractProcedure<infer USchemas, infer UMeta> ? Procedure<TInitialContext, any, USchemas, UMeta> : {
105
+ [K in keyof T]: T[K] extends AnyContractRouter ? Lazyable<Router<T[K], TInitialContext>> : never;
106
+ };
107
+ type AnyRouter = Router<any, any>;
108
+ type InferRouterInitialContext<T extends AnyRouter> = T extends Router<any, infer UInitialContext> ? UInitialContext : never;
109
+ /**
110
+ * Infer all initial context of the router.
111
+ *
112
+ * @info A procedure is a router too.
113
+ * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
114
+ */
115
+ type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any> ? UInitialContext : {
116
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
117
+ };
118
+ /**
119
+ * Infer all current context of the router.
120
+ *
121
+ * @info A procedure is a router too.
122
+ * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
123
+ */
124
+ type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any> ? UCurrentContext : {
125
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : never;
126
+ };
127
+ /**
128
+ * Infer all router inputs
129
+ *
130
+ * @info A procedure is a router too.
131
+ * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
132
+ */
133
+ type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer USchemas, any> ? InferProcedureClientInputs<USchemas> : {
134
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
135
+ };
136
+ /**
137
+ * Infer all router outputs
138
+ *
139
+ * @info A procedure is a router too.
140
+ * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
141
+ */
142
+ type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, infer USchemas, any> ? InferSchemaOutput<USchemas['outputSchema']> : {
143
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
144
+ };
145
+
146
+ declare function getRouter<T extends Lazyable<AnyRouter | undefined>>(router: T, path: readonly string[]): T extends Lazy<any> ? Lazy<AnyRouter | undefined> : Lazyable<AnyRouter | undefined>;
147
+ type AccessibleLazyRouter<T extends Lazyable<AnyRouter | undefined>> = T extends Lazy<infer U extends AnyRouter | undefined | Lazy<AnyRouter | undefined>> ? AccessibleLazyRouter<U> : T extends AnyProcedure | undefined ? Lazy<T> : Lazy<T> & {
148
+ [K in keyof T]: T[K] extends Lazyable<AnyRouter> ? AccessibleLazyRouter<T[K]> : never;
149
+ };
150
+ declare function createAccessibleLazyRouter<T extends Lazy<AnyRouter | undefined>>(lazied: T): AccessibleLazyRouter<T>;
151
+ type EnhancedRouter<T extends Lazyable<AnyRouter>, TInitialContext extends Context, TCurrentContext extends Context> = T extends Lazy<infer U extends AnyRouter> ? AccessibleLazyRouter<EnhancedRouter<U, TInitialContext, TCurrentContext>> : T extends Procedure<infer UInitialContext, infer UCurrentContext, infer USchemas, infer UMeta> ? Procedure<MergedInitialContext<TInitialContext, UInitialContext, TCurrentContext>, UCurrentContext, USchemas, UMeta> : {
152
+ [K in keyof T]: T[K] extends Lazyable<AnyRouter> ? EnhancedRouter<T[K], TInitialContext, TCurrentContext> : never;
153
+ };
154
+ interface EnhanceRouterOptions extends EnhanceRouteOptions {
155
+ middlewares: readonly AnyMiddleware[];
156
+ dedupeLeadingMiddlewares: boolean;
157
+ }
158
+ declare function enhanceRouter<T extends Lazyable<AnyRouter>, TInitialContext extends Context, TCurrentContext extends Context>(router: T, options: EnhanceRouterOptions): EnhancedRouter<T, TInitialContext, TCurrentContext>;
159
+ interface TraverseContractProceduresOptions {
160
+ router: AnyContractRouter | AnyRouter;
161
+ path: readonly string[];
162
+ }
163
+ interface TraverseContractProcedureCallbackOptions {
164
+ contract: AnyContractProcedure | AnyProcedure;
165
+ path: readonly string[];
166
+ }
167
+ /**
168
+ * @deprecated Use `TraverseContractProcedureCallbackOptions` instead.
169
+ */
170
+ type ContractProcedureCallbackOptions = TraverseContractProcedureCallbackOptions;
171
+ interface LazyTraverseContractProceduresOptions {
172
+ router: Lazy<AnyRouter>;
173
+ path: readonly string[];
174
+ }
175
+ declare function traverseContractProcedures(options: TraverseContractProceduresOptions, callback: (options: TraverseContractProcedureCallbackOptions) => void, lazyOptions?: LazyTraverseContractProceduresOptions[]): LazyTraverseContractProceduresOptions[];
176
+ declare function resolveContractProcedures(options: TraverseContractProceduresOptions, callback: (options: TraverseContractProcedureCallbackOptions) => void): Promise<void>;
177
+ type UnlaziedRouter<T extends AnyRouter> = T extends AnyProcedure ? T : {
178
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? UnlaziedRouter<U> : never;
179
+ };
180
+ declare function unlazyRouter<T extends AnyRouter>(router: T): Promise<UnlaziedRouter<T>>;
181
+
182
+ declare const LAZY_SYMBOL: unique symbol;
183
+ interface LazyMeta {
184
+ prefix?: HTTPPath;
185
+ }
186
+ interface Lazy<T> {
187
+ [LAZY_SYMBOL]: {
188
+ loader: () => Promise<{
189
+ default: T;
190
+ }>;
191
+ meta: LazyMeta;
192
+ };
193
+ }
194
+ type Lazyable<T> = T | Lazy<T>;
195
+ /**
196
+ * @internal
197
+ */
198
+ declare function lazyInternal<T>(loader: () => Promise<{
199
+ default: T;
200
+ }>, meta?: LazyMeta): Lazy<T>;
201
+ /**
202
+ * Creates a lazy-loaded item.
203
+ *
204
+ * @warning The `prefix` in `meta` only holds metadata and does not apply the prefix to the lazy router, use `os.prefix(...).lazyRoute(...)` instead.
205
+ */
206
+ declare function lazy<T extends Router<ContractRouter<{}>, any>>(prefix: HTTPPath, loader: () => Promise<{
207
+ default: T;
208
+ }>): EnhancedRouter<Lazy<T>, {}, {}>;
209
+ declare function isLazy(item: unknown): item is Lazy<any>;
210
+ declare function getLazyMeta(lazied: Lazy<any>): LazyMeta;
211
+ declare function unlazy<T extends Lazyable<any>>(lazied: T): Promise<{
212
+ default: T extends Lazy<infer U> ? U : T;
213
+ }>;
214
+
215
+ type ProcedureClient<TClientContext extends ClientContext, TSchemas extends Schemas> = Client<TClientContext, InferProcedureClientInputs<TSchemas>, InferSchemaOutput<TSchemas['outputSchema']>>;
216
+ interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TMeta extends Meta> extends ProcedureHandlerOptions<TInitialContext, TMeta> {
217
+ input: {
218
+ path: unknown;
219
+ query: unknown;
220
+ body: unknown;
221
+ };
222
+ }
223
+ type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TMeta extends Meta, TClientContext extends ClientContext> = {
224
+ /**
225
+ * This is helpful for logging and analytics.
226
+ */
227
+ path?: readonly string[];
228
+ interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TMeta>, Promise<InferSchemaOutput<TOutputSchema>>>[];
229
+ } & (Record<never, never> extends TInitialContext ? {
230
+ context?: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
231
+ } : {
232
+ context: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
233
+ });
234
+ /**
235
+ * Create Server-side client from a procedure.
236
+ *
237
+ * @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
238
+ */
239
+ declare function createProcedureClient<TInitialContext extends Context, TSchemas extends Schemas, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TSchemas, TMeta>>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TSchemas['outputSchema'], TMeta, TClientContext>>): ProcedureClient<TClientContext, TSchemas>;
240
+
241
+ export { isProcedure as G, createProcedureClient as J, Procedure as P, getRouter as S, createAccessibleLazyRouter as W, enhanceRouter as X, traverseContractProcedures as a0, resolveContractProcedures as a1, unlazyRouter as a3, mergeCurrentContext as m, LAZY_SYMBOL as n, lazyInternal as p, lazy as q, isLazy as r, getLazyMeta as s, unlazy as u, middlewareOutputFn as y };
242
+ export type { LazyTraverseContractProceduresOptions as $, AuthType as A, BuildContextWithAuth as B, Context as C, DefaultProcedureHandlerOptions as D, EnhanceRouterOptions as E, ProcedureDef as F, ProcedureClientInterceptorOptions as H, InferRouterInitialContext as I, InferRouterInitialContexts as K, Lazy as L, Middleware as M, InferRouterCurrentContexts as N, InferRouterInputs as O, InferRouterOutputs as Q, Router as R, TypedAuthConfig as T, AccessibleLazyRouter as U, ValidatedAuthContext as V, TraverseContractProceduresOptions as Y, TraverseContractProcedureCallbackOptions as Z, ContractProcedureCallbackOptions as _, CreateProcedureClientOptions as a, UnlaziedRouter as a2, ProcedureClient as b, MergedInitialContext as c, MergedCurrentContext as d, AuthConfig as e, ProcedureHandler as f, EnhancedRouter as g, MapInputMiddleware as h, AnyMiddleware as i, AnyProcedure as j, Lazyable as k, AnyRouter as l, LazyMeta as o, MiddlewareResult as t, MiddlewareNextFn as v, MiddlewareOutputFn as w, MiddlewareOptions as x, ProcedureHandlerOptions as z };
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@temporary-name/server",
3
3
  "type": "module",
4
- "version": "1.9.3-alpha.0d2fa3247b6b23bbc2e3097a95f631b86740e4d8",
4
+ "version": "1.9.3-alpha.0f2e1f4d66464608b85c66977bff51174cbb238f",
5
5
  "license": "MIT",
6
6
  "homepage": "https://www.stainless.com/",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "git+https://github.com/unnoq/krusty.git",
9
+ "url": "git+https://github.com/stainless-api/krusty.git",
10
10
  "directory": "packages/server"
11
11
  },
12
12
  "keywords": [
@@ -47,37 +47,32 @@
47
47
  "types": "./dist/adapters/aws-lambda/index.d.mts",
48
48
  "import": "./dist/adapters/aws-lambda/index.mjs",
49
49
  "default": "./dist/adapters/aws-lambda/index.mjs"
50
+ },
51
+ "./openapi": {
52
+ "types": "./dist/openapi/index.d.mts",
53
+ "import": "./dist/openapi/index.mjs",
54
+ "default": "./dist/openapi/index.mjs"
50
55
  }
51
56
  },
52
57
  "files": [
53
58
  "dist"
54
59
  ],
55
- "peerDependencies": {
56
- "drizzle-orm": "^0.44.5",
57
- "drizzle-zod": "^0.8.3"
58
- },
59
- "peerDependenciesMeta": {
60
- "drizzle-orm": {
61
- "optional": true
62
- },
63
- "drizzle-zod": {
64
- "optional": true
65
- }
66
- },
67
60
  "dependencies": {
68
61
  "cookie": "^1.0.2",
69
- "@standard-schema/spec": "^1.0.0",
62
+ "rou3": "^0.7.7",
70
63
  "zod": "^4.1.12",
71
- "@temporary-name/contract": "1.9.3-alpha.0d2fa3247b6b23bbc2e3097a95f631b86740e4d8",
72
- "@temporary-name/interop": "1.9.3-alpha.0d2fa3247b6b23bbc2e3097a95f631b86740e4d8",
73
- "@temporary-name/openapi": "1.9.3-alpha.0d2fa3247b6b23bbc2e3097a95f631b86740e4d8",
74
- "@temporary-name/shared": "1.9.3-alpha.0d2fa3247b6b23bbc2e3097a95f631b86740e4d8",
75
- "@temporary-name/standard-server": "1.9.3-alpha.0d2fa3247b6b23bbc2e3097a95f631b86740e4d8",
76
- "@temporary-name/standard-server-aws-lambda": "1.9.3-alpha.0d2fa3247b6b23bbc2e3097a95f631b86740e4d8",
77
- "@temporary-name/standard-server-fetch": "1.9.3-alpha.0d2fa3247b6b23bbc2e3097a95f631b86740e4d8",
78
- "@temporary-name/standard-server-node": "1.9.3-alpha.0d2fa3247b6b23bbc2e3097a95f631b86740e4d8"
64
+ "@temporary-name/interop": "1.9.3-alpha.0f2e1f4d66464608b85c66977bff51174cbb238f",
65
+ "@temporary-name/json-schema": "1.9.3-alpha.0f2e1f4d66464608b85c66977bff51174cbb238f",
66
+ "@temporary-name/standard-server": "1.9.3-alpha.0f2e1f4d66464608b85c66977bff51174cbb238f",
67
+ "@temporary-name/standard-server-aws-lambda": "1.9.3-alpha.0f2e1f4d66464608b85c66977bff51174cbb238f",
68
+ "@temporary-name/standard-server-fetch": "1.9.3-alpha.0f2e1f4d66464608b85c66977bff51174cbb238f",
69
+ "@temporary-name/shared": "1.9.3-alpha.0f2e1f4d66464608b85c66977bff51174cbb238f",
70
+ "@temporary-name/standard-server-node": "1.9.3-alpha.0f2e1f4d66464608b85c66977bff51174cbb238f",
71
+ "@temporary-name/zod": "1.9.3-alpha.0f2e1f4d66464608b85c66977bff51174cbb238f",
72
+ "@temporary-name/contract": "1.9.3-alpha.0f2e1f4d66464608b85c66977bff51174cbb238f"
79
73
  },
80
74
  "devDependencies": {
75
+ "@types/supertest": "^6.0.3",
81
76
  "@types/ws": "^8.18.1",
82
77
  "supertest": "^7.1.4"
83
78
  },
@@ -1,207 +0,0 @@
1
- import { validateORPCError, ValidationError } from '@temporary-name/contract';
2
- import { resolveMaybeOptionalOptions, ORPCError, toArray, value, runWithSpan, intercept, isAsyncIteratorObject, overlayProxy, asyncIteratorWithSpan } from '@temporary-name/shared';
3
- import { HibernationEventIterator, mapEventIterator } from '@temporary-name/standard-server';
4
- import { g as gatingContext, w as withoutGatedFields } from './server.D6K9uoPI.mjs';
5
-
6
- const LAZY_SYMBOL = Symbol("ORPC_LAZY_SYMBOL");
7
- function lazy(loader, meta = {}) {
8
- return {
9
- [LAZY_SYMBOL]: {
10
- loader,
11
- meta
12
- }
13
- };
14
- }
15
- function isLazy(item) {
16
- return (typeof item === "object" || typeof item === "function") && item !== null && LAZY_SYMBOL in item;
17
- }
18
- function getLazyMeta(lazied) {
19
- return lazied[LAZY_SYMBOL].meta;
20
- }
21
- function unlazy(lazied) {
22
- return isLazy(lazied) ? lazied[LAZY_SYMBOL].loader() : Promise.resolve({ default: lazied });
23
- }
24
-
25
- function mergeCurrentContext(context, other) {
26
- return { ...context, ...other };
27
- }
28
-
29
- function createORPCErrorConstructorMap(errors) {
30
- const proxy = new Proxy(errors, {
31
- get(target, code) {
32
- if (typeof code !== "string") {
33
- return Reflect.get(target, code);
34
- }
35
- const item = (...rest) => {
36
- const options = resolveMaybeOptionalOptions(rest);
37
- const config = errors[code];
38
- return new ORPCError(code, {
39
- defined: Boolean(config),
40
- status: config?.status,
41
- message: options.message ?? config?.message,
42
- data: options.data,
43
- cause: options.cause
44
- });
45
- };
46
- return item;
47
- }
48
- });
49
- return proxy;
50
- }
51
-
52
- function middlewareOutputFn(output) {
53
- return { output, context: {} };
54
- }
55
-
56
- function createProcedureClient(lazyableProcedure, ...rest) {
57
- const options = resolveMaybeOptionalOptions(rest);
58
- return async (...[input, callerOptions]) => {
59
- const path = toArray(options.path);
60
- const { default: procedure } = await unlazy(lazyableProcedure);
61
- const clientContext = callerOptions?.context ?? {};
62
- const context = await value(options.context ?? {}, clientContext);
63
- const errors = createORPCErrorConstructorMap(procedure["~orpc"].errorMap);
64
- const validateError = async (e) => {
65
- if (e instanceof ORPCError) {
66
- return await validateORPCError(procedure["~orpc"].errorMap, e);
67
- }
68
- return e;
69
- };
70
- try {
71
- const output = await runWithSpan({ name: "call_procedure", signal: callerOptions?.signal }, (span) => {
72
- span?.setAttribute("procedure.path", [...path]);
73
- return intercept(
74
- toArray(options.interceptors),
75
- {
76
- context,
77
- input,
78
- // input only optional when it undefinable so we can safely cast it
79
- errors,
80
- path,
81
- procedure,
82
- signal: callerOptions?.signal,
83
- lastEventId: callerOptions?.lastEventId
84
- },
85
- (interceptorOptions) => executeProcedureInternal(interceptorOptions.procedure, interceptorOptions)
86
- );
87
- });
88
- if (isAsyncIteratorObject(output)) {
89
- if (output instanceof HibernationEventIterator) {
90
- return output;
91
- }
92
- return overlayProxy(
93
- output,
94
- mapEventIterator(
95
- asyncIteratorWithSpan(
96
- { name: "consume_event_iterator_output", signal: callerOptions?.signal },
97
- output
98
- ),
99
- {
100
- value: (v) => v,
101
- error: (e) => validateError(e)
102
- }
103
- )
104
- );
105
- }
106
- return output;
107
- } catch (e) {
108
- throw await validateError(e);
109
- }
110
- };
111
- }
112
- async function validateInput(procedure, input) {
113
- const schema = procedure["~orpc"].inputSchema;
114
- if (!schema) {
115
- return input;
116
- }
117
- return runWithSpan({ name: "validate_input" }, async () => {
118
- const result = await schema["~standard"].validate(input);
119
- if (result.issues) {
120
- throw new ORPCError("BAD_REQUEST", {
121
- message: "Input validation failed",
122
- data: {
123
- issues: result.issues
124
- },
125
- cause: new ValidationError({
126
- message: "Input validation failed",
127
- issues: result.issues,
128
- data: input
129
- })
130
- });
131
- }
132
- return result.value;
133
- });
134
- }
135
- async function validateOutput(schema, output) {
136
- return runWithSpan({ name: "validate_output" }, async () => {
137
- const result = await schema["~standard"].validate(output);
138
- if (result.issues) {
139
- throw new ORPCError("INTERNAL_SERVER_ERROR", {
140
- message: "Output validation failed",
141
- cause: new ValidationError({
142
- message: "Output validation failed",
143
- issues: result.issues,
144
- data: output
145
- })
146
- });
147
- }
148
- return result.value;
149
- });
150
- }
151
- async function executeProcedureInternal(procedure, options) {
152
- const middlewares = procedure["~orpc"].middlewares;
153
- const inputValidationIndex = Math.min(
154
- Math.max(0, procedure["~orpc"].inputValidationIndex),
155
- middlewares.length
156
- );
157
- const outputValidationIndex = Math.min(
158
- Math.max(0, procedure["~orpc"].outputValidationIndex),
159
- middlewares.length
160
- );
161
- const next = async (index, context, input) => {
162
- let currentInput = input;
163
- if (index === inputValidationIndex) {
164
- currentInput = await validateInput(procedure, currentInput);
165
- }
166
- const mid = middlewares[index];
167
- const output = mid ? await runWithSpan({ name: `middleware.${mid.name}`, signal: options.signal }, async (span) => {
168
- span?.setAttribute("middleware.index", index);
169
- span?.setAttribute("middleware.name", mid.name);
170
- const result = await mid(
171
- {
172
- ...options,
173
- context,
174
- next: async (...[nextOptions]) => {
175
- const nextContext = nextOptions?.context ?? {};
176
- return {
177
- output: await next(index + 1, mergeCurrentContext(context, nextContext), currentInput),
178
- context: nextContext
179
- };
180
- }
181
- },
182
- currentInput,
183
- middlewareOutputFn
184
- );
185
- return result.output;
186
- }) : await runWithSpan(
187
- { name: "handler", signal: options.signal },
188
- () => procedure["~orpc"].handler({ ...options, context, input: currentInput })
189
- );
190
- if (index === outputValidationIndex) {
191
- const schema = procedure["~orpc"].outputSchema;
192
- if (!schema) {
193
- return output;
194
- }
195
- const validated = await validateOutput(schema, output);
196
- const isGateEnabled = gatingContext.getStore();
197
- if (!validated || !isGateEnabled) {
198
- return validated;
199
- }
200
- return withoutGatedFields(validated, schema, isGateEnabled);
201
- }
202
- return output;
203
- };
204
- return next(0, options.context, options.input);
205
- }
206
-
207
- export { LAZY_SYMBOL as L, createORPCErrorConstructorMap as a, middlewareOutputFn as b, createProcedureClient as c, getLazyMeta as g, isLazy as i, lazy as l, mergeCurrentContext as m, unlazy as u };