@emeryld/rrroutes-server 2.3.6 → 2.3.8
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/index.cjs +69 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +72 -11
- package/dist/index.js.map +1 -1
- package/dist/routesV3.server.d.ts +0 -6
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -23,18 +23,20 @@ __export(index_exports, {
|
|
|
23
23
|
CTX_SYMBOL: () => CTX_SYMBOL,
|
|
24
24
|
bindAll: () => bindAll,
|
|
25
25
|
bindExpressRoutes: () => bindExpressRoutes,
|
|
26
|
+
contractKeyOf: () => import_rrroutes_contract2.keyOf,
|
|
26
27
|
createConnectionLoggingMiddleware: () => createConnectionLoggingMiddleware,
|
|
27
28
|
createRRRoute: () => createRRRoute,
|
|
28
29
|
createSocketConnections: () => createSocketConnections,
|
|
29
30
|
defineControllers: () => defineControllers,
|
|
30
31
|
getCtx: () => getCtx,
|
|
31
|
-
keyOf: () => keyOf,
|
|
32
32
|
warnMissingControllers: () => warnMissingControllers
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(index_exports);
|
|
35
|
+
var import_rrroutes_contract2 = require("@emeryld/rrroutes-contract");
|
|
35
36
|
|
|
36
37
|
// src/routesV3.server.ts
|
|
37
38
|
var import_rrroutes_contract = require("@emeryld/rrroutes-contract");
|
|
39
|
+
var import_zod = require("zod");
|
|
38
40
|
var serverDebugEventTypes = [
|
|
39
41
|
"register",
|
|
40
42
|
"request",
|
|
@@ -68,7 +70,61 @@ function createServerDebugEmitter(option) {
|
|
|
68
70
|
}
|
|
69
71
|
return disabled;
|
|
70
72
|
}
|
|
71
|
-
var
|
|
73
|
+
var isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
74
|
+
var isZodType = (schema) => Boolean(schema && typeof schema.parse === "function");
|
|
75
|
+
var unwrapQuerySchema = (schema) => {
|
|
76
|
+
let current = schema;
|
|
77
|
+
const EffectsCtor = import_zod.z.ZodEffects;
|
|
78
|
+
const PipelineCtor = import_zod.z.ZodPipeline;
|
|
79
|
+
const CatchCtor = import_zod.z.ZodCatch;
|
|
80
|
+
for (let i = 0; i < 10; i += 1) {
|
|
81
|
+
if (!current) break;
|
|
82
|
+
if (current instanceof import_zod.z.ZodOptional || current instanceof import_zod.z.ZodNullable) {
|
|
83
|
+
current = current.unwrap();
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (current instanceof import_zod.z.ZodDefault) {
|
|
87
|
+
current = current._def?.innerType;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (CatchCtor && current instanceof CatchCtor) {
|
|
91
|
+
current = current._def?.innerType;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (EffectsCtor && current instanceof EffectsCtor) {
|
|
95
|
+
current = current._def?.schema ?? current._def?.innerType;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (PipelineCtor && current instanceof PipelineCtor) {
|
|
99
|
+
current = current._def?.out ?? current._def?.innerType;
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
return current ?? schema;
|
|
105
|
+
};
|
|
106
|
+
var normalizeQueryValue = (schema, value) => {
|
|
107
|
+
const resolved = unwrapQuerySchema(schema);
|
|
108
|
+
if (resolved instanceof import_zod.z.ZodArray) {
|
|
109
|
+
if (value === void 0 || value === null) return value;
|
|
110
|
+
return Array.isArray(value) ? value : [value];
|
|
111
|
+
}
|
|
112
|
+
if (resolved instanceof import_zod.z.ZodObject && isPlainObject(value)) {
|
|
113
|
+
const shape = (0, import_rrroutes_contract.getZodShape)(resolved);
|
|
114
|
+
const next = {};
|
|
115
|
+
for (const [key, childValue] of Object.entries(value)) {
|
|
116
|
+
const childSchema = shape[key];
|
|
117
|
+
next[key] = childSchema && isZodType(childSchema) ? normalizeQueryValue(childSchema, childValue) : childValue;
|
|
118
|
+
}
|
|
119
|
+
return next;
|
|
120
|
+
}
|
|
121
|
+
return value;
|
|
122
|
+
};
|
|
123
|
+
var normalizeQueryForSchema = (schema, value) => {
|
|
124
|
+
if (!schema || value === void 0 || value === null) return value;
|
|
125
|
+
if (!isPlainObject(value)) return value;
|
|
126
|
+
return isZodType(schema) ? normalizeQueryValue(schema, value) : value;
|
|
127
|
+
};
|
|
72
128
|
var CTX_SYMBOL = Symbol.for("typedLeaves.ctx");
|
|
73
129
|
function getCtx(res) {
|
|
74
130
|
return res.locals[CTX_SYMBOL];
|
|
@@ -156,7 +212,7 @@ function createRRRoute(router, config) {
|
|
|
156
212
|
const method = leaf.method;
|
|
157
213
|
const methodUpper = method.toUpperCase();
|
|
158
214
|
const path = leaf.path;
|
|
159
|
-
const key = keyOf(leaf);
|
|
215
|
+
const key = (0, import_rrroutes_contract.keyOf)(leaf, false);
|
|
160
216
|
const defDebug = def.debug;
|
|
161
217
|
let debugName = void 0;
|
|
162
218
|
let routeDebugEmitter;
|
|
@@ -252,7 +308,8 @@ function createRRRoute(router, config) {
|
|
|
252
308
|
try {
|
|
253
309
|
params = leaf.cfg.paramsSchema ? (0, import_rrroutes_contract.lowProfileParse)(leaf.cfg.paramsSchema, req.params) : Object.keys(req.params || {}).length ? req.params : void 0;
|
|
254
310
|
try {
|
|
255
|
-
|
|
311
|
+
const queryInput = leaf.cfg.querySchema ? normalizeQueryForSchema(leaf.cfg.querySchema, req.query) : req.query;
|
|
312
|
+
query = leaf.cfg.querySchema ? (0, import_rrroutes_contract.lowProfileParse)(leaf.cfg.querySchema, queryInput) : Object.keys(req.query || {}).length ? req.query : void 0;
|
|
256
313
|
} catch (e) {
|
|
257
314
|
logger?.error?.("Query parsing error", {
|
|
258
315
|
path,
|
|
@@ -362,7 +419,7 @@ function createRRRoute(router, config) {
|
|
|
362
419
|
}
|
|
363
420
|
function registerControllers(registry, controllers, all) {
|
|
364
421
|
for (const leaf of registry.all) {
|
|
365
|
-
const key = keyOf(leaf);
|
|
422
|
+
const key = (0, import_rrroutes_contract.keyOf)(leaf, false);
|
|
366
423
|
knownLeaves.set(key, leaf);
|
|
367
424
|
}
|
|
368
425
|
;
|
|
@@ -381,7 +438,7 @@ function createRRRoute(router, config) {
|
|
|
381
438
|
if (all) {
|
|
382
439
|
const missing = [];
|
|
383
440
|
for (const leaf of registry.all) {
|
|
384
|
-
const key = keyOf(leaf);
|
|
441
|
+
const key = (0, import_rrroutes_contract.keyOf)(leaf, false);
|
|
385
442
|
if (!controllers[key]) {
|
|
386
443
|
missing.push(key);
|
|
387
444
|
}
|
|
@@ -401,7 +458,7 @@ function createRRRoute(router, config) {
|
|
|
401
458
|
);
|
|
402
459
|
}
|
|
403
460
|
for (const leaf of registry.all) {
|
|
404
|
-
const key = keyOf(leaf);
|
|
461
|
+
const key = (0, import_rrroutes_contract.keyOf)(leaf, false);
|
|
405
462
|
if (!registeredFromStore.has(key)) {
|
|
406
463
|
warnLogger.warn(`No controller registered for route: ${key}`);
|
|
407
464
|
}
|
|
@@ -431,7 +488,7 @@ function warnMissingControllers(router, registry, logger) {
|
|
|
431
488
|
const initial = registeredStore ? Array.from(registeredStore) : collectRoutesFromStack(router);
|
|
432
489
|
const registeredKeys = new Set(initial);
|
|
433
490
|
for (const leaf of registry.all) {
|
|
434
|
-
const k = keyOf(leaf);
|
|
491
|
+
const k = (0, import_rrroutes_contract.keyOf)(leaf, false);
|
|
435
492
|
if (!registeredKeys.has(k)) {
|
|
436
493
|
logger.warn(`No controller registered for route: ${k}`);
|
|
437
494
|
}
|
|
@@ -452,7 +509,7 @@ function createDebugger(options) {
|
|
|
452
509
|
}
|
|
453
510
|
|
|
454
511
|
// src/sockets/socket.server.sys.ts
|
|
455
|
-
var
|
|
512
|
+
var import_zod2 = require("zod");
|
|
456
513
|
var normalizeError = (error) => {
|
|
457
514
|
if (error instanceof Error) {
|
|
458
515
|
return { name: error.name, message: error.message };
|
|
@@ -460,8 +517,8 @@ var normalizeError = (error) => {
|
|
|
460
517
|
if (typeof error === "string") return { message: error };
|
|
461
518
|
return { message: "Unknown error" };
|
|
462
519
|
};
|
|
463
|
-
var roomValueSchema =
|
|
464
|
-
var buildRoomPayloadSchema = (metaSchema) =>
|
|
520
|
+
var roomValueSchema = import_zod2.z.union([import_zod2.z.string(), import_zod2.z.array(import_zod2.z.string())]);
|
|
521
|
+
var buildRoomPayloadSchema = (metaSchema) => import_zod2.z.object({
|
|
465
522
|
rooms: roomValueSchema,
|
|
466
523
|
meta: metaSchema
|
|
467
524
|
});
|
|
@@ -1164,12 +1221,12 @@ var createConnectionLoggingMiddleware = (options = {}) => {
|
|
|
1164
1221
|
CTX_SYMBOL,
|
|
1165
1222
|
bindAll,
|
|
1166
1223
|
bindExpressRoutes,
|
|
1224
|
+
contractKeyOf,
|
|
1167
1225
|
createConnectionLoggingMiddleware,
|
|
1168
1226
|
createRRRoute,
|
|
1169
1227
|
createSocketConnections,
|
|
1170
1228
|
defineControllers,
|
|
1171
1229
|
getCtx,
|
|
1172
|
-
keyOf,
|
|
1173
1230
|
warnMissingControllers
|
|
1174
1231
|
});
|
|
1175
1232
|
//# sourceMappingURL=index.cjs.map
|