@temporary-name/server 1.9.3-alpha.ec3bfb9dce56198911349c322c970208b21b50db → 1.9.3-alpha.edd373b82156a10608d43b19a44b75ae72e72de7
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 +2 -2
- package/dist/adapters/aws-lambda/index.d.ts +2 -2
- package/dist/adapters/aws-lambda/index.mjs +3 -3
- package/dist/adapters/fetch/index.d.mts +2 -2
- package/dist/adapters/fetch/index.d.ts +2 -2
- package/dist/adapters/fetch/index.mjs +3 -3
- package/dist/adapters/node/index.d.mts +2 -2
- package/dist/adapters/node/index.d.ts +2 -2
- package/dist/adapters/node/index.mjs +3 -3
- package/dist/adapters/standard/index.d.mts +2 -2
- package/dist/adapters/standard/index.d.ts +2 -2
- package/dist/adapters/standard/index.mjs +3 -3
- package/dist/index.d.mts +268 -16
- package/dist/index.d.ts +268 -16
- package/dist/index.mjs +379 -71
- package/dist/openapi/index.d.mts +11 -30
- package/dist/openapi/index.d.ts +11 -30
- package/dist/openapi/index.mjs +338 -295
- package/dist/shared/{server.Cza0RB3u.mjs → server.BCY45g2x.mjs} +1 -1
- package/dist/shared/{server.ChOv1yG3.mjs → server.BETu17rq.mjs} +1 -1
- package/dist/shared/server.B_oW_rPl.mjs +525 -0
- package/dist/shared/server.CjPiuQYH.d.mts +51 -0
- package/dist/shared/server.CjPiuQYH.d.ts +51 -0
- package/dist/shared/{server.CYa9puL2.mjs → server.Cq7SBLD5.mjs} +2 -2
- package/dist/shared/{server.CVhIyQ4x.d.mts → server.DGH2Bq4t.d.mts} +1 -1
- package/dist/shared/{server.D8RAzJ_p.d.ts → server.nQoUObAJ.d.ts} +1 -1
- package/dist/shared/{server.Cj3_Lp61.d.ts → server.zsKBRxsz.d.mts} +26 -11
- package/dist/shared/{server.Cj3_Lp61.d.mts → server.zsKBRxsz.d.ts} +26 -11
- package/package.json +8 -8
- package/dist/shared/server.YUvuxHty.mjs +0 -48
package/dist/index.mjs
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import { assertNever, splitFirst, ORPCError, onError, resolveMaybeOptionalOptions, isTypescriptObject, isPropertyKey } from '@temporary-name/shared';
|
|
1
|
+
import { assertNever, splitFirst, ORPCError, onError, isObject, toArray, guard, resolveMaybeOptionalOptions, isTypescriptObject, isPropertyKey } from '@temporary-name/shared';
|
|
2
2
|
export { AsyncIteratorClass, EventPublisher, ORPCError, asyncIteratorToStream as eventIteratorToStream, isDefinedError, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@temporary-name/shared';
|
|
3
3
|
import * as z from '@temporary-name/zod';
|
|
4
4
|
import { SchemaClass, object, core, gatingContext } from '@temporary-name/zod';
|
|
5
5
|
import { g as getCookie } from './shared/server.C1RJffw4.mjs';
|
|
6
|
-
import { P as Procedure, m as mergePrefix, a as mergeTags, e as enhanceRouter, C as Contract, p as parseEndpointDefinition, b as mergeRoute, c as prefixRoute, d as addMiddleware, l as lazyInternal, f as getLazyMeta, u as unlazy, i as isProcedure
|
|
7
|
-
export { L as LAZY_SYMBOL, V as ValidationError, q as createAccessibleLazyRouter, w as endpointRegex, g as getDynamicParams,
|
|
8
|
-
import { c as createProcedureClient } from './shared/server.
|
|
9
|
-
export { m as mergeCurrentContext, a as middlewareOutputFn } from './shared/server.
|
|
10
|
-
|
|
6
|
+
import { P as Procedure, m as mergePrefix, a as mergeTags, e as enhanceRouter, C as Contract, p as parseEndpointDefinition, b as mergeRoute, c as prefixRoute, d as addMiddleware, l as lazyInternal, f as getLazyMeta, u as unlazy, i as isProcedure } from './shared/server.BETu17rq.mjs';
|
|
7
|
+
export { L as LAZY_SYMBOL, V as ValidationError, q as createAccessibleLazyRouter, w as endpointRegex, g as getDynamicParams, o as getRouter, j as isLazy, k as isStartWithMiddlewares, h as lazy, n as mergeMiddlewares, r as resolveContractProcedures, s as standardizeHTTPPath, t as traverseContractProcedures, v as unlazyRouter } from './shared/server.BETu17rq.mjs';
|
|
8
|
+
import { c as createProcedureClient } from './shared/server.BCY45g2x.mjs';
|
|
9
|
+
export { m as mergeCurrentContext, a as middlewareOutputFn } from './shared/server.BCY45g2x.mjs';
|
|
10
|
+
import { J as JsonSchemaXNativeType } from './shared/server.B_oW_rPl.mjs';
|
|
11
|
+
export { b as JSON_SCHEMA_INPUT_REGISTRY, c as JSON_SCHEMA_OUTPUT_REGISTRY, a as JSON_SCHEMA_REGISTRY, Z as ZodToJsonSchemaConverter, e as eventIterator, g as getEventIteratorSchemaDetails } from './shared/server.B_oW_rPl.mjs';
|
|
11
12
|
export { getEventMeta, withEventMeta } from '@temporary-name/standard-server';
|
|
12
13
|
import 'cookie';
|
|
14
|
+
import '@temporary-name/server/openapi';
|
|
15
|
+
import 'zod/v4/core';
|
|
13
16
|
|
|
14
17
|
function validateTokenPrefix(prefix, token) {
|
|
15
18
|
if (prefix && !token.startsWith(prefix)) {
|
|
@@ -21,41 +24,47 @@ function validateTokenAuth(config, token, options) {
|
|
|
21
24
|
validateTokenPrefix(tokenPrefix, token);
|
|
22
25
|
return validate(token, options);
|
|
23
26
|
}
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
27
|
+
function runAuth(config, options) {
|
|
28
|
+
switch (config.type) {
|
|
29
|
+
case "header": {
|
|
30
|
+
const authHeader = options.request.headers.get(config.name);
|
|
31
|
+
return authHeader ? validateTokenAuth(config, authHeader, options) : void 0;
|
|
32
|
+
}
|
|
33
|
+
case "query": {
|
|
34
|
+
const { name, tokenPrefix, validate } = config;
|
|
35
|
+
const query = options.request.url.searchParams;
|
|
36
|
+
const token = query.get(name);
|
|
37
|
+
if (!token) return void 0;
|
|
38
|
+
validateTokenPrefix(tokenPrefix, token);
|
|
39
|
+
return validate(token, options);
|
|
40
|
+
}
|
|
41
|
+
case "cookie": {
|
|
42
|
+
const cookie = getCookie(options.request.headers, config.name);
|
|
43
|
+
return cookie ? validateTokenAuth(config, cookie, options) : void 0;
|
|
44
|
+
}
|
|
45
|
+
case "bearer": {
|
|
46
|
+
const authHeader = options.request.headers.get("Authorization");
|
|
47
|
+
if (!authHeader) return void 0;
|
|
48
|
+
const [authType, bearer] = splitFirst(authHeader, " ");
|
|
49
|
+
return authType === "Bearer" ? validateTokenAuth(config, bearer, options) : void 0;
|
|
50
|
+
}
|
|
51
|
+
case "basic": {
|
|
52
|
+
const authHeader = options.request.headers.get("Authorization");
|
|
53
|
+
if (!authHeader) return void 0;
|
|
54
|
+
const [authType, encoded] = splitFirst(authHeader, " ");
|
|
55
|
+
if (authType !== "Basic") return void 0;
|
|
56
|
+
const decoded = Buffer.from(encoded, "base64").toString("utf-8");
|
|
57
|
+
const [username, password] = splitFirst(decoded, ":");
|
|
58
|
+
validateTokenPrefix(config.tokenPrefix, password);
|
|
59
|
+
return config.validate(username, password, options);
|
|
60
|
+
}
|
|
61
|
+
case "none": {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
default: {
|
|
65
|
+
assertNever(config);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
59
68
|
}
|
|
60
69
|
function authDescription(config) {
|
|
61
70
|
const { type } = config;
|
|
@@ -179,15 +188,13 @@ class ProcedureBuilder extends Contract {
|
|
|
179
188
|
middlewares: addMiddleware(this["~orpc"].middlewares, middleware)
|
|
180
189
|
});
|
|
181
190
|
}
|
|
182
|
-
// `& {}` is so AuthType will be expanded in parameter info tooltips.
|
|
183
191
|
// The default of false for ValidatedAuthContext is used when you pass in the type 'none'. We use false
|
|
184
192
|
// because we can't use null or undefined (see ValidatedAuthContext) but we still want it to be falsy.
|
|
185
|
-
useAuth(
|
|
186
|
-
const config = { type, ...rest[0] };
|
|
193
|
+
useAuth(config) {
|
|
187
194
|
const middleware = baseApi.$context().middleware(async (options) => {
|
|
188
195
|
const { next, context } = options;
|
|
189
196
|
if (context.auth) return next();
|
|
190
|
-
const auth = await
|
|
197
|
+
const auth = await runAuth(config, options);
|
|
191
198
|
if (auth === void 0) {
|
|
192
199
|
const { authConfigs } = options.procedure["~orpc"];
|
|
193
200
|
if (context.auth !== false && config === authConfigs.at(-1)) {
|
|
@@ -315,6 +322,332 @@ const baseApi = new Builder({
|
|
|
315
322
|
authConfigs: []
|
|
316
323
|
});
|
|
317
324
|
|
|
325
|
+
const FLEXIBLE_DATE_FORMAT_REGEX = /^[^-]+-[^-]+-[^-]+$/;
|
|
326
|
+
class experimental_JsonSchemaCoercer {
|
|
327
|
+
coerce(schema, value, options = {}) {
|
|
328
|
+
const [, coerced] = this.#coerce(schema, value, options);
|
|
329
|
+
return coerced;
|
|
330
|
+
}
|
|
331
|
+
#coerce(schema, originalValue, options) {
|
|
332
|
+
if (typeof schema === "boolean") {
|
|
333
|
+
return [schema, originalValue];
|
|
334
|
+
}
|
|
335
|
+
if (Array.isArray(schema.type)) {
|
|
336
|
+
return this.#coerce(
|
|
337
|
+
{
|
|
338
|
+
anyOf: schema.type.map((type) => ({ ...schema, type }))
|
|
339
|
+
},
|
|
340
|
+
originalValue,
|
|
341
|
+
options
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
let coerced = originalValue;
|
|
345
|
+
let satisfied = true;
|
|
346
|
+
if (typeof schema.$ref === "string") {
|
|
347
|
+
const refSchema = options?.components?.[schema.$ref];
|
|
348
|
+
if (refSchema !== void 0) {
|
|
349
|
+
const [subSatisfied, subCoerced] = this.#coerce(refSchema, coerced, options);
|
|
350
|
+
coerced = subCoerced;
|
|
351
|
+
satisfied = subSatisfied;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
const enumValues = schema.const !== void 0 ? [schema.const] : schema.enum;
|
|
355
|
+
if (enumValues !== void 0 && !enumValues.includes(coerced)) {
|
|
356
|
+
if (typeof coerced === "string") {
|
|
357
|
+
const numberValue = this.#stringToNumber(coerced);
|
|
358
|
+
if (enumValues.includes(numberValue)) {
|
|
359
|
+
coerced = numberValue;
|
|
360
|
+
} else {
|
|
361
|
+
const booleanValue = this.#stringToBoolean(coerced);
|
|
362
|
+
if (enumValues.includes(booleanValue)) {
|
|
363
|
+
coerced = booleanValue;
|
|
364
|
+
} else {
|
|
365
|
+
satisfied = false;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
} else {
|
|
369
|
+
satisfied = false;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
if (typeof schema.type === "string") {
|
|
373
|
+
switch (schema.type) {
|
|
374
|
+
case "null": {
|
|
375
|
+
if (coerced !== null) {
|
|
376
|
+
satisfied = false;
|
|
377
|
+
}
|
|
378
|
+
break;
|
|
379
|
+
}
|
|
380
|
+
case "string": {
|
|
381
|
+
if (typeof coerced !== "string") {
|
|
382
|
+
satisfied = false;
|
|
383
|
+
}
|
|
384
|
+
break;
|
|
385
|
+
}
|
|
386
|
+
case "number": {
|
|
387
|
+
if (typeof coerced === "string") {
|
|
388
|
+
coerced = this.#stringToNumber(coerced);
|
|
389
|
+
}
|
|
390
|
+
if (typeof coerced !== "number") {
|
|
391
|
+
satisfied = false;
|
|
392
|
+
}
|
|
393
|
+
break;
|
|
394
|
+
}
|
|
395
|
+
case "integer": {
|
|
396
|
+
if (typeof coerced === "string") {
|
|
397
|
+
coerced = this.#stringToInteger(coerced);
|
|
398
|
+
}
|
|
399
|
+
if (typeof coerced !== "number" || !Number.isInteger(coerced)) {
|
|
400
|
+
satisfied = false;
|
|
401
|
+
}
|
|
402
|
+
break;
|
|
403
|
+
}
|
|
404
|
+
case "boolean": {
|
|
405
|
+
if (typeof coerced === "string") {
|
|
406
|
+
coerced = this.#stringToBoolean(coerced);
|
|
407
|
+
}
|
|
408
|
+
if (typeof coerced !== "boolean") {
|
|
409
|
+
satisfied = false;
|
|
410
|
+
}
|
|
411
|
+
break;
|
|
412
|
+
}
|
|
413
|
+
case "array": {
|
|
414
|
+
if (Array.isArray(coerced)) {
|
|
415
|
+
const prefixItemSchemas = "prefixItems" in schema ? toArray(schema.prefixItems) : Array.isArray(schema.items) ? schema.items : [];
|
|
416
|
+
const itemSchema = Array.isArray(schema.items) ? schema.additionalItems : schema.items;
|
|
417
|
+
let shouldUseCoercedItems = false;
|
|
418
|
+
const coercedItems = coerced.map((item, i) => {
|
|
419
|
+
const subSchema = prefixItemSchemas[i] ?? itemSchema;
|
|
420
|
+
if (subSchema === void 0) {
|
|
421
|
+
satisfied = false;
|
|
422
|
+
return item;
|
|
423
|
+
}
|
|
424
|
+
const [subSatisfied, subCoerced] = this.#coerce(subSchema, item, options);
|
|
425
|
+
if (!subSatisfied) {
|
|
426
|
+
satisfied = false;
|
|
427
|
+
}
|
|
428
|
+
if (subCoerced !== item) {
|
|
429
|
+
shouldUseCoercedItems = true;
|
|
430
|
+
}
|
|
431
|
+
return subCoerced;
|
|
432
|
+
});
|
|
433
|
+
if (coercedItems.length < prefixItemSchemas.length) {
|
|
434
|
+
satisfied = false;
|
|
435
|
+
}
|
|
436
|
+
if (shouldUseCoercedItems) {
|
|
437
|
+
coerced = coercedItems;
|
|
438
|
+
}
|
|
439
|
+
} else {
|
|
440
|
+
satisfied = false;
|
|
441
|
+
}
|
|
442
|
+
break;
|
|
443
|
+
}
|
|
444
|
+
case "object": {
|
|
445
|
+
if (Array.isArray(coerced)) {
|
|
446
|
+
coerced = { ...coerced };
|
|
447
|
+
}
|
|
448
|
+
if (isObject(coerced)) {
|
|
449
|
+
let shouldUseCoercedItems = false;
|
|
450
|
+
const coercedItems = {};
|
|
451
|
+
const patternProperties = Object.entries(schema.patternProperties ?? {}).map(
|
|
452
|
+
([key, value]) => [new RegExp(key), value]
|
|
453
|
+
);
|
|
454
|
+
for (const key in coerced) {
|
|
455
|
+
const value = coerced[key];
|
|
456
|
+
const subSchema = schema.properties?.[key] ?? patternProperties.find(([pattern]) => pattern.test(key))?.[1] ?? schema.additionalProperties;
|
|
457
|
+
if (value === void 0 && !schema.required?.includes(key)) {
|
|
458
|
+
coercedItems[key] = value;
|
|
459
|
+
} else if (subSchema === void 0) {
|
|
460
|
+
coercedItems[key] = value;
|
|
461
|
+
satisfied = false;
|
|
462
|
+
} else {
|
|
463
|
+
const [subSatisfied, subCoerced] = this.#coerce(subSchema, value, options);
|
|
464
|
+
coercedItems[key] = subCoerced;
|
|
465
|
+
if (!subSatisfied) {
|
|
466
|
+
satisfied = false;
|
|
467
|
+
}
|
|
468
|
+
if (subCoerced !== value) {
|
|
469
|
+
shouldUseCoercedItems = true;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
if (schema.required?.some((key) => !Object.hasOwn(coercedItems, key))) {
|
|
474
|
+
satisfied = false;
|
|
475
|
+
}
|
|
476
|
+
if (shouldUseCoercedItems) {
|
|
477
|
+
coerced = coercedItems;
|
|
478
|
+
}
|
|
479
|
+
} else {
|
|
480
|
+
satisfied = false;
|
|
481
|
+
}
|
|
482
|
+
break;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
if ("x-native-type" in schema && typeof schema["x-native-type"] === "string") {
|
|
487
|
+
switch (schema["x-native-type"]) {
|
|
488
|
+
case JsonSchemaXNativeType.Date: {
|
|
489
|
+
if (typeof coerced === "string") {
|
|
490
|
+
coerced = this.#stringToDate(coerced);
|
|
491
|
+
}
|
|
492
|
+
if (!(coerced instanceof Date)) {
|
|
493
|
+
satisfied = false;
|
|
494
|
+
}
|
|
495
|
+
break;
|
|
496
|
+
}
|
|
497
|
+
case JsonSchemaXNativeType.BigInt: {
|
|
498
|
+
switch (typeof coerced) {
|
|
499
|
+
case "string":
|
|
500
|
+
coerced = this.#stringToBigInt(coerced);
|
|
501
|
+
break;
|
|
502
|
+
case "number":
|
|
503
|
+
coerced = this.#numberToBigInt(coerced);
|
|
504
|
+
break;
|
|
505
|
+
}
|
|
506
|
+
if (typeof coerced !== "bigint") {
|
|
507
|
+
satisfied = false;
|
|
508
|
+
}
|
|
509
|
+
break;
|
|
510
|
+
}
|
|
511
|
+
case JsonSchemaXNativeType.RegExp: {
|
|
512
|
+
if (typeof coerced === "string") {
|
|
513
|
+
coerced = this.#stringToRegExp(coerced);
|
|
514
|
+
}
|
|
515
|
+
if (!(coerced instanceof RegExp)) {
|
|
516
|
+
satisfied = false;
|
|
517
|
+
}
|
|
518
|
+
break;
|
|
519
|
+
}
|
|
520
|
+
case JsonSchemaXNativeType.Url: {
|
|
521
|
+
if (typeof coerced === "string") {
|
|
522
|
+
coerced = this.#stringToURL(coerced);
|
|
523
|
+
}
|
|
524
|
+
if (!(coerced instanceof URL)) {
|
|
525
|
+
satisfied = false;
|
|
526
|
+
}
|
|
527
|
+
break;
|
|
528
|
+
}
|
|
529
|
+
case JsonSchemaXNativeType.Set: {
|
|
530
|
+
if (Array.isArray(coerced)) {
|
|
531
|
+
coerced = this.#arrayToSet(coerced);
|
|
532
|
+
}
|
|
533
|
+
if (!(coerced instanceof Set)) {
|
|
534
|
+
satisfied = false;
|
|
535
|
+
}
|
|
536
|
+
break;
|
|
537
|
+
}
|
|
538
|
+
case JsonSchemaXNativeType.Map: {
|
|
539
|
+
if (Array.isArray(coerced)) {
|
|
540
|
+
coerced = this.#arrayToMap(coerced);
|
|
541
|
+
}
|
|
542
|
+
if (!(coerced instanceof Map)) {
|
|
543
|
+
satisfied = false;
|
|
544
|
+
}
|
|
545
|
+
break;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
if (schema.allOf) {
|
|
550
|
+
for (const subSchema of schema.allOf) {
|
|
551
|
+
const [subSatisfied, subCoerced] = this.#coerce(subSchema, coerced, options);
|
|
552
|
+
coerced = subCoerced;
|
|
553
|
+
if (!subSatisfied) {
|
|
554
|
+
satisfied = false;
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
for (const key of ["anyOf", "oneOf"]) {
|
|
559
|
+
if (schema[key]) {
|
|
560
|
+
let bestOptions;
|
|
561
|
+
for (const subSchema of schema[key]) {
|
|
562
|
+
const [subSatisfied, subCoerced] = this.#coerce(subSchema, coerced, options);
|
|
563
|
+
if (subSatisfied) {
|
|
564
|
+
if (!bestOptions || subCoerced === coerced) {
|
|
565
|
+
bestOptions = { coerced: subCoerced, satisfied: subSatisfied };
|
|
566
|
+
}
|
|
567
|
+
if (subCoerced === coerced) {
|
|
568
|
+
break;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
coerced = bestOptions ? bestOptions.coerced : coerced;
|
|
573
|
+
satisfied = bestOptions ? bestOptions.satisfied : false;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
if (typeof schema.not !== "undefined") {
|
|
577
|
+
const [notSatisfied] = this.#coerce(schema.not, coerced, options);
|
|
578
|
+
if (notSatisfied) {
|
|
579
|
+
satisfied = false;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
return [satisfied, coerced];
|
|
583
|
+
}
|
|
584
|
+
#stringToNumber(value) {
|
|
585
|
+
const num = Number.parseFloat(value);
|
|
586
|
+
if (Number.isNaN(num) || num !== Number(value)) {
|
|
587
|
+
return value;
|
|
588
|
+
}
|
|
589
|
+
return num;
|
|
590
|
+
}
|
|
591
|
+
#stringToInteger(value) {
|
|
592
|
+
const num = Number.parseInt(value);
|
|
593
|
+
if (Number.isNaN(num) || num !== Number(value)) {
|
|
594
|
+
return value;
|
|
595
|
+
}
|
|
596
|
+
return num;
|
|
597
|
+
}
|
|
598
|
+
#stringToBoolean(value) {
|
|
599
|
+
const lower = value.toLowerCase();
|
|
600
|
+
if (lower === "false" || lower === "off") {
|
|
601
|
+
return false;
|
|
602
|
+
}
|
|
603
|
+
if (lower === "true" || lower === "on") {
|
|
604
|
+
return true;
|
|
605
|
+
}
|
|
606
|
+
return value;
|
|
607
|
+
}
|
|
608
|
+
#stringToBigInt(value) {
|
|
609
|
+
return guard(() => BigInt(value)) ?? value;
|
|
610
|
+
}
|
|
611
|
+
#numberToBigInt(value) {
|
|
612
|
+
return guard(() => BigInt(value)) ?? value;
|
|
613
|
+
}
|
|
614
|
+
#stringToDate(value) {
|
|
615
|
+
const date = new Date(value);
|
|
616
|
+
if (Number.isNaN(date.getTime()) || !FLEXIBLE_DATE_FORMAT_REGEX.test(value)) {
|
|
617
|
+
return value;
|
|
618
|
+
}
|
|
619
|
+
return date;
|
|
620
|
+
}
|
|
621
|
+
#stringToRegExp(value) {
|
|
622
|
+
const match = value.match(/^\/(.*)\/([a-z]*)$/);
|
|
623
|
+
if (match) {
|
|
624
|
+
const [, pattern, flags] = match;
|
|
625
|
+
return guard(() => new RegExp(pattern, flags)) ?? value;
|
|
626
|
+
}
|
|
627
|
+
return value;
|
|
628
|
+
}
|
|
629
|
+
#stringToURL(value) {
|
|
630
|
+
return guard(() => new URL(value)) ?? value;
|
|
631
|
+
}
|
|
632
|
+
#arrayToSet(value) {
|
|
633
|
+
const set = new Set(value);
|
|
634
|
+
if (set.size !== value.length) {
|
|
635
|
+
return value;
|
|
636
|
+
}
|
|
637
|
+
return set;
|
|
638
|
+
}
|
|
639
|
+
#arrayToMap(value) {
|
|
640
|
+
if (value.some((item) => !Array.isArray(item) || item.length !== 2)) {
|
|
641
|
+
return value;
|
|
642
|
+
}
|
|
643
|
+
const result = new Map(value);
|
|
644
|
+
if (result.size !== value.length) {
|
|
645
|
+
return value;
|
|
646
|
+
}
|
|
647
|
+
return result;
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
|
|
318
651
|
function createAssertedLazyProcedure(lazied) {
|
|
319
652
|
const lazyProcedure = lazyInternal(async () => {
|
|
320
653
|
const { default: maybeProcedure } = await unlazy(lazied);
|
|
@@ -334,31 +667,6 @@ function call(procedure, input, ...rest) {
|
|
|
334
667
|
return createProcedureClient(procedure, options)(input, options);
|
|
335
668
|
}
|
|
336
669
|
|
|
337
|
-
function createRouterClient(router, ...rest) {
|
|
338
|
-
const options = resolveMaybeOptionalOptions(rest);
|
|
339
|
-
if (isProcedure(router)) {
|
|
340
|
-
const caller = createProcedureClient(router, options);
|
|
341
|
-
return caller;
|
|
342
|
-
}
|
|
343
|
-
const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router), options) : {};
|
|
344
|
-
const recursive = new Proxy(procedureCaller, {
|
|
345
|
-
get(target, key) {
|
|
346
|
-
if (typeof key !== "string") {
|
|
347
|
-
return Reflect.get(target, key);
|
|
348
|
-
}
|
|
349
|
-
const next = getRouter(router, [key]);
|
|
350
|
-
if (!next) {
|
|
351
|
-
return Reflect.get(target, key);
|
|
352
|
-
}
|
|
353
|
-
return createRouterClient(next, {
|
|
354
|
-
...rest[0],
|
|
355
|
-
path: [...rest[0]?.path ?? [], key]
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
});
|
|
359
|
-
return recursive;
|
|
360
|
-
}
|
|
361
|
-
|
|
362
670
|
function isSchemaIssue(issue) {
|
|
363
671
|
if (!isTypescriptObject(issue) || typeof issue.message !== "string") {
|
|
364
672
|
return false;
|
|
@@ -376,4 +684,4 @@ function isSchemaIssue(issue) {
|
|
|
376
684
|
return true;
|
|
377
685
|
}
|
|
378
686
|
|
|
379
|
-
export { Builder, BuilderWithMiddlewares, Contract, DecoratedProcedure, Procedure, ProcedureBuilder, addMiddleware, baseApi, call, createAssertedLazyProcedure, createProcedureClient,
|
|
687
|
+
export { Builder, BuilderWithMiddlewares, Contract, DecoratedProcedure, JsonSchemaXNativeType, Procedure, ProcedureBuilder, addMiddleware, baseApi, call, createAssertedLazyProcedure, createProcedureClient, decorateMiddleware, enhanceRouter, experimental_JsonSchemaCoercer, getLazyMeta, initialSchemas, isProcedure, isSchemaIssue, lazyInternal, mergeMeta, parseEndpointDefinition, unlazy };
|
package/dist/openapi/index.d.mts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { Contract } from '@temporary-name/server';
|
|
2
2
|
import { OpenAPI, Promisable, Value, HTTPPath, HTTPMethod } from '@temporary-name/shared';
|
|
3
3
|
export { OpenAPI } from '@temporary-name/shared';
|
|
4
|
-
import {
|
|
4
|
+
import { Z as ZodToJsonSchemaConverterOptions } from '../shared/server.CjPiuQYH.mjs';
|
|
5
|
+
import { d as AnySchema, b as Contract$1, a9 as TraverseContractProcedureCallbackOptions, Z as ContractRouter, _ as AnyRouter } from '../shared/server.zsKBRxsz.mjs';
|
|
5
6
|
import { JSONSchema } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
6
7
|
export { JSONSchema, ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
8
|
+
import '@temporary-name/server/openapi';
|
|
7
9
|
import '@temporary-name/zod';
|
|
8
10
|
|
|
9
11
|
type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: OpenAPI.OperationObject, procedure: Contract) => OpenAPI.OperationObject);
|
|
@@ -55,22 +57,11 @@ interface SchemaConvertOptions {
|
|
|
55
57
|
*/
|
|
56
58
|
minStructureDepthForRef?: number;
|
|
57
59
|
}
|
|
58
|
-
|
|
59
|
-
convert(schemas: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
|
|
60
|
-
}
|
|
61
|
-
interface ConditionalSchemaConverter extends SchemaConverter {
|
|
62
|
-
condition(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<boolean>;
|
|
63
|
-
}
|
|
64
|
-
declare class CompositeSchemaConverter implements SchemaConverter {
|
|
65
|
-
private readonly converters;
|
|
66
|
-
constructor(converters: readonly ConditionalSchemaConverter[]);
|
|
67
|
-
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promise<[required: boolean, jsonSchema: JSONSchema]>;
|
|
68
|
-
}
|
|
60
|
+
type SchemaConverter = (schemas: AnySchema | undefined, options: SchemaConvertOptions) => Promisable<[required: boolean, jsonSchema: JSONSchema]>;
|
|
69
61
|
|
|
70
|
-
interface
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
interface OpenAPIGeneratorGenerateOptions extends Partial<Omit<OpenAPI.Document, 'openapi'>> {
|
|
62
|
+
interface OpenAPIGeneratorGenerateOptions {
|
|
63
|
+
spec?: Partial<Omit<OpenAPI.Document, 'openapi'>>;
|
|
64
|
+
schemaConverter?: ZodToJsonSchemaConverterOptions | SchemaConverter;
|
|
74
65
|
/**
|
|
75
66
|
* Exclude procedures from the OpenAPI specification.
|
|
76
67
|
*
|
|
@@ -117,21 +108,11 @@ interface OpenAPIGeneratorGenerateOptions extends Partial<Omit<OpenAPI.Document,
|
|
|
117
108
|
}>;
|
|
118
109
|
}
|
|
119
110
|
/**
|
|
120
|
-
*
|
|
111
|
+
* Generates OpenAPI specifications from oRPC routers/contracts.
|
|
121
112
|
*
|
|
122
113
|
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
|
|
123
114
|
*/
|
|
124
|
-
declare
|
|
125
|
-
#private;
|
|
126
|
-
private readonly converter;
|
|
127
|
-
constructor(options?: OpenAPIGeneratorOptions);
|
|
128
|
-
/**
|
|
129
|
-
* Generates OpenAPI specifications from oRPC routers/contracts.
|
|
130
|
-
*
|
|
131
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
|
|
132
|
-
*/
|
|
133
|
-
generate(router: ContractRouter | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPI.Document>;
|
|
134
|
-
}
|
|
115
|
+
declare function generateOpenApiSpec(router: ContractRouter | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPI.Document>;
|
|
135
116
|
|
|
136
117
|
/**
|
|
137
118
|
* @internal
|
|
@@ -200,5 +181,5 @@ declare const oo: {
|
|
|
200
181
|
spec: typeof customOpenAPIOperation;
|
|
201
182
|
};
|
|
202
183
|
|
|
203
|
-
export {
|
|
204
|
-
export type {
|
|
184
|
+
export { LOGIC_KEYWORDS, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, generateOpenApiSpec, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, isPrimitiveSchema, oo, resolveOpenAPIJsonSchemaRef, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
|
|
185
|
+
export type { FileSchema, ObjectSchema, OpenAPIGeneratorGenerateOptions, OverrideOperationValue, SchemaConvertOptions, SchemaConverter, SchemaConverterComponent };
|
package/dist/openapi/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { Contract } from '@temporary-name/server';
|
|
2
2
|
import { OpenAPI, Promisable, Value, HTTPPath, HTTPMethod } from '@temporary-name/shared';
|
|
3
3
|
export { OpenAPI } from '@temporary-name/shared';
|
|
4
|
-
import {
|
|
4
|
+
import { Z as ZodToJsonSchemaConverterOptions } from '../shared/server.CjPiuQYH.js';
|
|
5
|
+
import { d as AnySchema, b as Contract$1, a9 as TraverseContractProcedureCallbackOptions, Z as ContractRouter, _ as AnyRouter } from '../shared/server.zsKBRxsz.js';
|
|
5
6
|
import { JSONSchema } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
6
7
|
export { JSONSchema, ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
8
|
+
import '@temporary-name/server/openapi';
|
|
7
9
|
import '@temporary-name/zod';
|
|
8
10
|
|
|
9
11
|
type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: OpenAPI.OperationObject, procedure: Contract) => OpenAPI.OperationObject);
|
|
@@ -55,22 +57,11 @@ interface SchemaConvertOptions {
|
|
|
55
57
|
*/
|
|
56
58
|
minStructureDepthForRef?: number;
|
|
57
59
|
}
|
|
58
|
-
|
|
59
|
-
convert(schemas: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
|
|
60
|
-
}
|
|
61
|
-
interface ConditionalSchemaConverter extends SchemaConverter {
|
|
62
|
-
condition(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<boolean>;
|
|
63
|
-
}
|
|
64
|
-
declare class CompositeSchemaConverter implements SchemaConverter {
|
|
65
|
-
private readonly converters;
|
|
66
|
-
constructor(converters: readonly ConditionalSchemaConverter[]);
|
|
67
|
-
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promise<[required: boolean, jsonSchema: JSONSchema]>;
|
|
68
|
-
}
|
|
60
|
+
type SchemaConverter = (schemas: AnySchema | undefined, options: SchemaConvertOptions) => Promisable<[required: boolean, jsonSchema: JSONSchema]>;
|
|
69
61
|
|
|
70
|
-
interface
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
interface OpenAPIGeneratorGenerateOptions extends Partial<Omit<OpenAPI.Document, 'openapi'>> {
|
|
62
|
+
interface OpenAPIGeneratorGenerateOptions {
|
|
63
|
+
spec?: Partial<Omit<OpenAPI.Document, 'openapi'>>;
|
|
64
|
+
schemaConverter?: ZodToJsonSchemaConverterOptions | SchemaConverter;
|
|
74
65
|
/**
|
|
75
66
|
* Exclude procedures from the OpenAPI specification.
|
|
76
67
|
*
|
|
@@ -117,21 +108,11 @@ interface OpenAPIGeneratorGenerateOptions extends Partial<Omit<OpenAPI.Document,
|
|
|
117
108
|
}>;
|
|
118
109
|
}
|
|
119
110
|
/**
|
|
120
|
-
*
|
|
111
|
+
* Generates OpenAPI specifications from oRPC routers/contracts.
|
|
121
112
|
*
|
|
122
113
|
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
|
|
123
114
|
*/
|
|
124
|
-
declare
|
|
125
|
-
#private;
|
|
126
|
-
private readonly converter;
|
|
127
|
-
constructor(options?: OpenAPIGeneratorOptions);
|
|
128
|
-
/**
|
|
129
|
-
* Generates OpenAPI specifications from oRPC routers/contracts.
|
|
130
|
-
*
|
|
131
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
|
|
132
|
-
*/
|
|
133
|
-
generate(router: ContractRouter | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPI.Document>;
|
|
134
|
-
}
|
|
115
|
+
declare function generateOpenApiSpec(router: ContractRouter | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPI.Document>;
|
|
135
116
|
|
|
136
117
|
/**
|
|
137
118
|
* @internal
|
|
@@ -200,5 +181,5 @@ declare const oo: {
|
|
|
200
181
|
spec: typeof customOpenAPIOperation;
|
|
201
182
|
};
|
|
202
183
|
|
|
203
|
-
export {
|
|
204
|
-
export type {
|
|
184
|
+
export { LOGIC_KEYWORDS, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, generateOpenApiSpec, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, isPrimitiveSchema, oo, resolveOpenAPIJsonSchemaRef, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
|
|
185
|
+
export type { FileSchema, ObjectSchema, OpenAPIGeneratorGenerateOptions, OverrideOperationValue, SchemaConvertOptions, SchemaConverter, SchemaConverterComponent };
|