@temporary-name/server 1.9.3-alpha.4275e976ddda4d8be107c2cfde9899bdea9a337d → 1.9.3-alpha.52ad782be6ff2aac22845e524cd6454f857fb89b

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 (34) hide show
  1. package/dist/adapters/aws-lambda/index.d.mts +12 -6
  2. package/dist/adapters/aws-lambda/index.d.ts +12 -6
  3. package/dist/adapters/aws-lambda/index.mjs +12 -4
  4. package/dist/adapters/fetch/index.d.mts +12 -6
  5. package/dist/adapters/fetch/index.d.ts +12 -6
  6. package/dist/adapters/fetch/index.mjs +12 -11
  7. package/dist/adapters/node/index.d.mts +12 -6
  8. package/dist/adapters/node/index.d.ts +12 -6
  9. package/dist/adapters/node/index.mjs +12 -11
  10. package/dist/adapters/standard/index.d.mts +23 -13
  11. package/dist/adapters/standard/index.d.ts +23 -13
  12. package/dist/adapters/standard/index.mjs +8 -100
  13. package/dist/index.d.mts +62 -436
  14. package/dist/index.d.ts +62 -436
  15. package/dist/index.mjs +111 -355
  16. package/dist/openapi/index.d.mts +220 -0
  17. package/dist/openapi/index.d.ts +220 -0
  18. package/dist/openapi/index.mjs +742 -0
  19. package/dist/plugins/index.d.mts +2 -2
  20. package/dist/plugins/index.d.ts +2 -2
  21. package/dist/shared/server.B-pKBQ0r.d.mts +23 -0
  22. package/dist/shared/server.BQV-lt_s.d.ts +23 -0
  23. package/dist/shared/server.BdGbIyq8.mjs +396 -0
  24. package/dist/shared/{server.Btxrgkj5.d.ts → server.DAzElr6Q.d.ts} +7 -24
  25. package/dist/shared/{server.C1YnHvvf.d.ts → server.Do2Whl-h.d.mts} +114 -71
  26. package/dist/shared/{server.C1YnHvvf.d.mts → server.Do2Whl-h.d.ts} +114 -71
  27. package/dist/shared/{server.Bo94xDTv.d.mts → server.KIlJQ8K_.d.mts} +7 -24
  28. package/dist/shared/server.Kxw442A9.mjs +247 -0
  29. package/dist/shared/server.SmOM3Fae.mjs +262 -0
  30. package/package.json +19 -13
  31. package/dist/shared/server.BEQrAa3A.mjs +0 -207
  32. package/dist/shared/server.D6K9uoPI.mjs +0 -35
  33. package/dist/shared/server.DZ5BIITo.mjs +0 -9
  34. package/dist/shared/server.X0YaZxSJ.mjs +0 -13
@@ -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 };
@@ -1,35 +0,0 @@
1
- import { AsyncLocalStorage } from 'node:async_hooks';
2
- import 'zod';
3
- import * as z4 from 'zod/v4/core';
4
-
5
- const gatingContext = new AsyncLocalStorage();
6
- function withoutGatedFields(data, schema, isGateEnabled) {
7
- const filtered = { ...data };
8
- const gatedFields = getGatedFields(schema);
9
- for (const [fieldName, gate] of gatedFields) {
10
- if (!isGateEnabled(gate)) {
11
- delete filtered[fieldName];
12
- }
13
- }
14
- return filtered;
15
- }
16
- function getGatedFields(schema) {
17
- if (!schema || schema["~standard"].vendor !== "zod") {
18
- return [];
19
- }
20
- const gatedFields = [];
21
- const zodDef = schema._zod.def;
22
- if (zodDef.type === "object") {
23
- const shape = zodDef.shape;
24
- for (const fieldName in shape) {
25
- const fieldSchema = shape[fieldName];
26
- const gate = z4.globalRegistry.get(fieldSchema)?.gate;
27
- if (gate) {
28
- gatedFields.push([fieldName, gate]);
29
- }
30
- }
31
- }
32
- return gatedFields;
33
- }
34
-
35
- export { gatingContext as g, withoutGatedFields as w };
@@ -1,9 +0,0 @@
1
- function resolveFriendlyStandardHandleOptions(options) {
2
- return {
3
- ...options,
4
- context: options.context ?? {}
5
- // Context only optional if all fields are optional
6
- };
7
- }
8
-
9
- export { resolveFriendlyStandardHandleOptions as r };
@@ -1,13 +0,0 @@
1
- class CompositeStandardHandlerPlugin {
2
- plugins;
3
- constructor(plugins = []) {
4
- this.plugins = [...plugins].sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
5
- }
6
- init(options, router) {
7
- for (const plugin of this.plugins) {
8
- plugin.init?.(options, router);
9
- }
10
- }
11
- }
12
-
13
- export { CompositeStandardHandlerPlugin as C };