@temporary-name/server 1.9.3-alpha.6ef4729e23affbe6454d37025d1dfc4d998b0649 → 1.9.3-alpha.70ac9623e5fa2a8af7954e34ef97cee968e5cad9

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 (45) hide show
  1. package/dist/adapters/aws-lambda/index.d.mts +11 -7
  2. package/dist/adapters/aws-lambda/index.d.ts +11 -7
  3. package/dist/adapters/aws-lambda/index.mjs +11 -4
  4. package/dist/adapters/fetch/index.d.mts +15 -87
  5. package/dist/adapters/fetch/index.d.ts +15 -87
  6. package/dist/adapters/fetch/index.mjs +22 -161
  7. package/dist/adapters/node/index.d.mts +15 -64
  8. package/dist/adapters/node/index.d.ts +15 -64
  9. package/dist/adapters/node/index.mjs +20 -126
  10. package/dist/handler/index.d.mts +28 -0
  11. package/dist/handler/index.d.ts +28 -0
  12. package/dist/handler/index.mjs +8 -0
  13. package/dist/helpers/index.mjs +3 -29
  14. package/dist/index.d.mts +373 -546
  15. package/dist/index.d.ts +373 -546
  16. package/dist/index.mjs +547 -470
  17. package/dist/openapi/index.d.mts +185 -0
  18. package/dist/openapi/index.d.ts +185 -0
  19. package/dist/openapi/index.mjs +782 -0
  20. package/dist/shared/server.BGG3eatg.mjs +315 -0
  21. package/dist/shared/server.BJw16psR.d.mts +39 -0
  22. package/dist/shared/server.BM9lK_Yv.mjs +523 -0
  23. package/dist/shared/server.BpMVFPn5.d.ts +39 -0
  24. package/dist/shared/server.C1RJffw4.mjs +30 -0
  25. package/dist/shared/server.CjPiuQYH.d.mts +51 -0
  26. package/dist/shared/server.CjPiuQYH.d.ts +51 -0
  27. package/dist/shared/server.CmNVzZVe.mjs +156 -0
  28. package/dist/shared/server.DX_j7xyF.d.mts +805 -0
  29. package/dist/shared/server.DX_j7xyF.d.ts +805 -0
  30. package/dist/shared/server.X8F6e8eV.mjs +499 -0
  31. package/package.json +20 -31
  32. package/dist/adapters/standard/index.d.mts +0 -16
  33. package/dist/adapters/standard/index.d.ts +0 -16
  34. package/dist/adapters/standard/index.mjs +0 -101
  35. package/dist/plugins/index.d.mts +0 -160
  36. package/dist/plugins/index.d.ts +0 -160
  37. package/dist/plugins/index.mjs +0 -288
  38. package/dist/shared/server.BEQrAa3A.mjs +0 -207
  39. package/dist/shared/server.Bo94xDTv.d.mts +0 -73
  40. package/dist/shared/server.Btxrgkj5.d.ts +0 -73
  41. package/dist/shared/server.C1YnHvvf.d.mts +0 -192
  42. package/dist/shared/server.C1YnHvvf.d.ts +0 -192
  43. package/dist/shared/server.D6K9uoPI.mjs +0 -35
  44. package/dist/shared/server.DZ5BIITo.mjs +0 -9
  45. package/dist/shared/server.X0YaZxSJ.mjs +0 -13
@@ -0,0 +1,156 @@
1
+ import { resolveMaybeOptionalOptions, toArray, value, runWithSpan, isAsyncIteratorObject, overlayProxy, asyncIteratorWithSpan } from '@temporary-name/shared';
2
+ import { HibernationEventIterator, mapEventIterator } from '@temporary-name/standard-server';
3
+ import { safeDecodeAsync, safeEncodeAsync } from '@temporary-name/zod';
4
+ import { u as unlazy, B as BadRequestError, V as ValidationError, I as InternalServerError } from './server.X8F6e8eV.mjs';
5
+
6
+ function mergeCurrentContext(context, other) {
7
+ return { ...context, ...other };
8
+ }
9
+
10
+ function middlewareOutputFn(output) {
11
+ return { output, context: {} };
12
+ }
13
+
14
+ function createProcedureClient(lazyableProcedure, ...rest) {
15
+ const options = resolveMaybeOptionalOptions(rest);
16
+ return async (...[input, callerOptions]) => {
17
+ const path = toArray(options.path);
18
+ const { default: procedure } = await unlazy(lazyableProcedure);
19
+ const clientContext = callerOptions?.context ?? {};
20
+ const context = await value(options.context ?? {}, clientContext);
21
+ const output = await runWithSpan({ name: "call_procedure", signal: callerOptions?.signal }, (span) => {
22
+ span?.setAttribute("procedure.path", [...path]);
23
+ return executeProcedureInternal(procedure, input, {
24
+ context,
25
+ path,
26
+ procedure,
27
+ request: callerOptions?.request,
28
+ signal: callerOptions?.signal,
29
+ lastEventId: callerOptions?.lastEventId
30
+ });
31
+ });
32
+ if (isAsyncIteratorObject(output)) {
33
+ if (output instanceof HibernationEventIterator) {
34
+ return output;
35
+ }
36
+ return overlayProxy(
37
+ output,
38
+ mapEventIterator(
39
+ asyncIteratorWithSpan(
40
+ { name: "consume_event_iterator_output", signal: callerOptions?.signal },
41
+ output
42
+ ),
43
+ {
44
+ value: (v) => v,
45
+ error: async (e) => e
46
+ }
47
+ )
48
+ );
49
+ }
50
+ return output;
51
+ };
52
+ }
53
+ async function validateInput(procedure, input) {
54
+ const schemas = procedure["~orpc"].schemas;
55
+ return runWithSpan({ name: "validate_input" }, async () => {
56
+ const resultBody = await safeDecodeAsync(schemas.bodySchema, input.body, { parseType: "body" });
57
+ const resultPath = await safeDecodeAsync(schemas.pathSchema, input.path, { parseType: "path" });
58
+ const resultQuery = await safeDecodeAsync(schemas.querySchema, input.query, { parseType: "query" });
59
+ const issues = [];
60
+ if (!resultBody.success) {
61
+ issues.push(...resultBody.error.issues.map((i) => ({ ...i, path: ["body", ...i.path] })));
62
+ }
63
+ if (!resultPath.success) {
64
+ issues.push(...resultPath.error.issues.map((i) => ({ ...i, path: ["path", ...i.path] })));
65
+ }
66
+ if (!resultQuery.success) {
67
+ issues.push(...resultQuery.error.issues.map((i) => ({ ...i, path: ["query", ...i.path] })));
68
+ }
69
+ if (issues.length > 0) {
70
+ throw new BadRequestError({
71
+ code: "input_validation_failed",
72
+ message: "Input validation failed",
73
+ cause: new ValidationError({
74
+ issues,
75
+ data: input
76
+ })
77
+ });
78
+ }
79
+ const results = {
80
+ body: resultBody.data,
81
+ path: resultPath.data,
82
+ query: resultQuery.data
83
+ };
84
+ return results;
85
+ });
86
+ }
87
+ async function validateOutput(procedure, output) {
88
+ const schema = procedure["~orpc"].schemas.outputSchema;
89
+ if (!schema) {
90
+ return output;
91
+ }
92
+ return runWithSpan({ name: "validate_output" }, async () => {
93
+ const result = await safeEncodeAsync(schema, output, { parseType: "output" });
94
+ if (!result.success) {
95
+ throw new InternalServerError({
96
+ message: "Output validation failed",
97
+ cause: new ValidationError({
98
+ issues: result.error.issues,
99
+ data: output
100
+ })
101
+ });
102
+ }
103
+ return result.data;
104
+ });
105
+ }
106
+ async function executeProcedureInternal(procedure, input, options) {
107
+ const middlewares = procedure["~orpc"].middlewares;
108
+ const inputValidationIndex = Math.min(
109
+ Math.max(0, procedure["~orpc"].inputValidationIndex),
110
+ middlewares.length
111
+ );
112
+ const outputValidationIndex = Math.min(
113
+ Math.max(0, procedure["~orpc"].outputValidationIndex),
114
+ middlewares.length
115
+ );
116
+ const next = async (index, context, input2) => {
117
+ let currentInput = input2;
118
+ if (index === inputValidationIndex) {
119
+ currentInput = await validateInput(procedure, currentInput);
120
+ }
121
+ const mid = middlewares[index];
122
+ const output = mid ? await runWithSpan({ name: `middleware.${mid.name}`, signal: options.signal }, async (span) => {
123
+ span?.setAttribute("middleware.index", index);
124
+ span?.setAttribute("middleware.name", mid.name);
125
+ const result = await mid(
126
+ {
127
+ ...options,
128
+ context,
129
+ next: async (nextOptions) => {
130
+ const nextContext = nextOptions?.context ?? {};
131
+ return {
132
+ output: await next(index + 1, mergeCurrentContext(context, nextContext), currentInput),
133
+ // NB: Pretty sure this isn't used (or meant to be used) at runtime, it's just there
134
+ // to get type inference in the builder (via the caller returning the output of next() in
135
+ // the middleware function)
136
+ context: nextContext
137
+ };
138
+ }
139
+ },
140
+ currentInput,
141
+ middlewareOutputFn
142
+ );
143
+ return result.output;
144
+ }) : await runWithSpan(
145
+ { name: "handler", signal: options.signal },
146
+ () => procedure["~orpc"].handler(currentInput, { ...options, context })
147
+ );
148
+ if (index === outputValidationIndex) {
149
+ return await validateOutput(procedure, output);
150
+ }
151
+ return output;
152
+ };
153
+ return next(0, options.context, input);
154
+ }
155
+
156
+ export { middlewareOutputFn as a, createProcedureClient as c, mergeCurrentContext as m };