@temporary-name/server 1.9.3-alpha.f9f5ce625d5edee78250b87b3a64f1d9760c2244 → 1.9.3-alpha.fb7e3a67f82deaeffad5063e136b2f3c03c4b5b3
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/adapters/aws-lambda/index.d.mts +5 -6
- package/dist/adapters/aws-lambda/index.d.ts +5 -6
- package/dist/adapters/aws-lambda/index.mjs +5 -6
- package/dist/adapters/fetch/index.d.mts +8 -85
- package/dist/adapters/fetch/index.d.ts +8 -85
- package/dist/adapters/fetch/index.mjs +17 -157
- package/dist/adapters/node/index.d.mts +9 -63
- package/dist/adapters/node/index.d.ts +9 -63
- package/dist/adapters/node/index.mjs +15 -122
- package/dist/handler/index.d.mts +28 -0
- package/dist/handler/index.d.ts +28 -0
- package/dist/handler/index.mjs +8 -0
- package/dist/helpers/index.mjs +3 -29
- package/dist/index.d.mts +356 -206
- package/dist/index.d.ts +356 -206
- package/dist/index.mjs +466 -163
- package/dist/openapi/index.d.mts +18 -53
- package/dist/openapi/index.d.ts +18 -53
- package/dist/openapi/index.mjs +391 -368
- package/dist/shared/server.-tR-4rQ5.mjs +523 -0
- package/dist/shared/server.BwcJq6aP.d.mts +808 -0
- package/dist/shared/server.BwcJq6aP.d.ts +808 -0
- package/dist/shared/server.C1RJffw4.mjs +30 -0
- package/dist/shared/server.CjPiuQYH.d.mts +51 -0
- package/dist/shared/server.CjPiuQYH.d.ts +51 -0
- package/dist/shared/server.D2NXNHIf.mjs +156 -0
- package/dist/shared/server.Deg5phAY.d.ts +39 -0
- package/dist/shared/server.DvgWQUGK.mjs +496 -0
- package/dist/shared/server.hAH-LVh_.d.mts +39 -0
- package/dist/shared/server.n1y5fcVQ.mjs +315 -0
- package/package.json +13 -31
- package/dist/adapters/standard/index.d.mts +0 -30
- package/dist/adapters/standard/index.d.ts +0 -30
- package/dist/adapters/standard/index.mjs +0 -9
- package/dist/plugins/index.d.mts +0 -84
- package/dist/plugins/index.d.ts +0 -84
- package/dist/plugins/index.mjs +0 -122
- package/dist/shared/server.7aL9gcoU.d.mts +0 -23
- package/dist/shared/server.BL2R5jcp.d.mts +0 -228
- package/dist/shared/server.BL2R5jcp.d.ts +0 -228
- package/dist/shared/server.CVBLzkro.mjs +0 -255
- package/dist/shared/server.ClhVCxfg.mjs +0 -413
- package/dist/shared/server.D6Qs_UcF.d.mts +0 -55
- package/dist/shared/server.DFptr1Nz.d.ts +0 -23
- package/dist/shared/server.DpoO_ER_.d.ts +0 -55
- package/dist/shared/server.JtIZ8YG7.mjs +0 -237
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { parse, serialize } from 'cookie';
|
|
2
|
+
|
|
3
|
+
function setCookie(headers, name, value, options = {}) {
|
|
4
|
+
if (headers === void 0) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
const cookieString = serialize(name, value, {
|
|
8
|
+
path: "/",
|
|
9
|
+
...options
|
|
10
|
+
});
|
|
11
|
+
headers.append("Set-Cookie", cookieString);
|
|
12
|
+
}
|
|
13
|
+
function getCookie(headers, name, options = {}) {
|
|
14
|
+
if (headers === void 0) {
|
|
15
|
+
return void 0;
|
|
16
|
+
}
|
|
17
|
+
const cookieHeader = headers.get("cookie");
|
|
18
|
+
if (cookieHeader === null) {
|
|
19
|
+
return void 0;
|
|
20
|
+
}
|
|
21
|
+
return parse(cookieHeader, options)[name];
|
|
22
|
+
}
|
|
23
|
+
function deleteCookie(headers, name, options = {}) {
|
|
24
|
+
return setCookie(headers, name, "", {
|
|
25
|
+
...options,
|
|
26
|
+
maxAge: 0
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { deleteCookie as d, getCookie as g, setCookie as s };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { JSONSchema, SchemaConverter } from '@temporary-name/server/openapi';
|
|
2
|
+
|
|
3
|
+
interface ZodToJsonSchemaConverterOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Max depth of lazy type.
|
|
6
|
+
*
|
|
7
|
+
* Used anyJsonSchema (`{}`) when exceed max depth
|
|
8
|
+
*
|
|
9
|
+
* @default 2
|
|
10
|
+
*/
|
|
11
|
+
maxLazyDepth?: number;
|
|
12
|
+
/**
|
|
13
|
+
* Max depth of nested types.
|
|
14
|
+
*
|
|
15
|
+
* Used anyJsonSchema (`{}`) when exceed max depth
|
|
16
|
+
*
|
|
17
|
+
* @default 10
|
|
18
|
+
*/
|
|
19
|
+
maxStructureDepth?: number;
|
|
20
|
+
/**
|
|
21
|
+
* The schema to be used to represent the any | unknown type.
|
|
22
|
+
*
|
|
23
|
+
* @default { }
|
|
24
|
+
*/
|
|
25
|
+
anyJsonSchema?: Exclude<JSONSchema, boolean>;
|
|
26
|
+
/**
|
|
27
|
+
* The schema to be used when the Zod schema is unsupported.
|
|
28
|
+
*
|
|
29
|
+
* @default { not: {} }
|
|
30
|
+
*/
|
|
31
|
+
unsupportedJsonSchema?: Exclude<JSONSchema, boolean>;
|
|
32
|
+
/**
|
|
33
|
+
* The schema to be used to represent the undefined type.
|
|
34
|
+
*
|
|
35
|
+
* @default { not: {} }
|
|
36
|
+
*/
|
|
37
|
+
undefinedJsonSchema?: Exclude<JSONSchema, boolean>;
|
|
38
|
+
}
|
|
39
|
+
declare class ZodToJsonSchemaConverter {
|
|
40
|
+
#private;
|
|
41
|
+
private readonly maxLazyDepth;
|
|
42
|
+
private readonly maxStructureDepth;
|
|
43
|
+
private readonly anyJsonSchema;
|
|
44
|
+
private readonly unsupportedJsonSchema;
|
|
45
|
+
private readonly undefinedJsonSchema;
|
|
46
|
+
constructor(options?: ZodToJsonSchemaConverterOptions);
|
|
47
|
+
convert: SchemaConverter;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { ZodToJsonSchemaConverter as a };
|
|
51
|
+
export type { ZodToJsonSchemaConverterOptions as Z };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { JSONSchema, SchemaConverter } from '@temporary-name/server/openapi';
|
|
2
|
+
|
|
3
|
+
interface ZodToJsonSchemaConverterOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Max depth of lazy type.
|
|
6
|
+
*
|
|
7
|
+
* Used anyJsonSchema (`{}`) when exceed max depth
|
|
8
|
+
*
|
|
9
|
+
* @default 2
|
|
10
|
+
*/
|
|
11
|
+
maxLazyDepth?: number;
|
|
12
|
+
/**
|
|
13
|
+
* Max depth of nested types.
|
|
14
|
+
*
|
|
15
|
+
* Used anyJsonSchema (`{}`) when exceed max depth
|
|
16
|
+
*
|
|
17
|
+
* @default 10
|
|
18
|
+
*/
|
|
19
|
+
maxStructureDepth?: number;
|
|
20
|
+
/**
|
|
21
|
+
* The schema to be used to represent the any | unknown type.
|
|
22
|
+
*
|
|
23
|
+
* @default { }
|
|
24
|
+
*/
|
|
25
|
+
anyJsonSchema?: Exclude<JSONSchema, boolean>;
|
|
26
|
+
/**
|
|
27
|
+
* The schema to be used when the Zod schema is unsupported.
|
|
28
|
+
*
|
|
29
|
+
* @default { not: {} }
|
|
30
|
+
*/
|
|
31
|
+
unsupportedJsonSchema?: Exclude<JSONSchema, boolean>;
|
|
32
|
+
/**
|
|
33
|
+
* The schema to be used to represent the undefined type.
|
|
34
|
+
*
|
|
35
|
+
* @default { not: {} }
|
|
36
|
+
*/
|
|
37
|
+
undefinedJsonSchema?: Exclude<JSONSchema, boolean>;
|
|
38
|
+
}
|
|
39
|
+
declare class ZodToJsonSchemaConverter {
|
|
40
|
+
#private;
|
|
41
|
+
private readonly maxLazyDepth;
|
|
42
|
+
private readonly maxStructureDepth;
|
|
43
|
+
private readonly anyJsonSchema;
|
|
44
|
+
private readonly unsupportedJsonSchema;
|
|
45
|
+
private readonly undefinedJsonSchema;
|
|
46
|
+
constructor(options?: ZodToJsonSchemaConverterOptions);
|
|
47
|
+
convert: SchemaConverter;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { ZodToJsonSchemaConverter as a };
|
|
51
|
+
export type { ZodToJsonSchemaConverterOptions as Z };
|
|
@@ -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.DvgWQUGK.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 };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { HTTPPath, StandardResponse, StandardLazyRequest } from '@temporary-name/shared';
|
|
2
|
+
import { C as Context, m as Router } from './server.BwcJq6aP.js';
|
|
3
|
+
|
|
4
|
+
interface StandardHandleOptions<T extends Context> {
|
|
5
|
+
prefix?: HTTPPath;
|
|
6
|
+
context: T;
|
|
7
|
+
}
|
|
8
|
+
type StandardHandleResult = {
|
|
9
|
+
matched: true;
|
|
10
|
+
response: StandardResponse;
|
|
11
|
+
} | {
|
|
12
|
+
matched: false;
|
|
13
|
+
response: undefined;
|
|
14
|
+
};
|
|
15
|
+
declare class StandardHandler<T extends Context> {
|
|
16
|
+
private readonly matcher;
|
|
17
|
+
constructor(router: Router<T>);
|
|
18
|
+
handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (object extends T ? {
|
|
22
|
+
context?: T;
|
|
23
|
+
} : {
|
|
24
|
+
context: T;
|
|
25
|
+
});
|
|
26
|
+
declare function resolveFriendlyStandardHandleOptions<T extends Context>(options: FriendlyStandardHandleOptions<T>): StandardHandleOptions<T>;
|
|
27
|
+
/**
|
|
28
|
+
* {@link https://github.com/unjs/rou3}
|
|
29
|
+
*
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
declare function toRou3Pattern(path: HTTPPath): string;
|
|
33
|
+
/**
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
declare function decodeParams(params: Record<string, string>): Record<string, string>;
|
|
37
|
+
|
|
38
|
+
export { StandardHandler as b, decodeParams as d, resolveFriendlyStandardHandleOptions as r, toRou3Pattern as t };
|
|
39
|
+
export type { FriendlyStandardHandleOptions as F, StandardHandleOptions as S, StandardHandleResult as a };
|