@emeryld/rrroutes-client 2.2.15 → 2.2.16
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 +136 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +136 -1
- package/dist/index.mjs.map +1 -1
- package/dist/routesV3.client.types.d.ts +41 -0
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -155,7 +155,9 @@ function getZodShape(schema) {
|
|
|
155
155
|
function augmentFeedQuerySchema(schema) {
|
|
156
156
|
if (!schema) return defaultFeedQuerySchema;
|
|
157
157
|
if (!(schema instanceof z.ZodObject)) {
|
|
158
|
-
console.warn(
|
|
158
|
+
console.warn(
|
|
159
|
+
"Feed queries must be a ZodObject; default pagination applied."
|
|
160
|
+
);
|
|
159
161
|
return defaultFeedQuerySchema;
|
|
160
162
|
}
|
|
161
163
|
return schema.extend(paginationQueryShape);
|
|
@@ -520,9 +522,77 @@ function createRouteClient(opts) {
|
|
|
520
522
|
fetch: fetchMutation
|
|
521
523
|
};
|
|
522
524
|
}
|
|
525
|
+
const fetchRaw = async (input) => {
|
|
526
|
+
const { path, method, query, body, params } = input;
|
|
527
|
+
if (!path || typeof path !== "string") {
|
|
528
|
+
throw new Error("fetch(path, ...) requires a non-empty string path.");
|
|
529
|
+
}
|
|
530
|
+
if (!method) {
|
|
531
|
+
throw new Error("fetch(path, method, ...) requires an HTTP method.");
|
|
532
|
+
}
|
|
533
|
+
const methodLower = String(method).toLowerCase();
|
|
534
|
+
const methodUpper = toUpper(methodLower);
|
|
535
|
+
const flatQuery = normalizeFlatQuery(query);
|
|
536
|
+
const search = toSearchString(flatQuery);
|
|
537
|
+
const compiledPath = compileRawPath(path, params);
|
|
538
|
+
const url = `${baseUrl ?? ""}${compiledPath}${search}`;
|
|
539
|
+
const leafLabel = `${methodUpper} ${path}`;
|
|
540
|
+
const startedAt = Date.now();
|
|
541
|
+
const detail = isVerboseDebug ? { params, query: flatQuery } : void 0;
|
|
542
|
+
emitDebug(
|
|
543
|
+
decorateDebugEvent(
|
|
544
|
+
{
|
|
545
|
+
type: "fetch",
|
|
546
|
+
stage: "start",
|
|
547
|
+
method: methodUpper,
|
|
548
|
+
url,
|
|
549
|
+
leaf: leafLabel,
|
|
550
|
+
...body !== void 0 ? { body } : {}
|
|
551
|
+
},
|
|
552
|
+
detail
|
|
553
|
+
)
|
|
554
|
+
);
|
|
555
|
+
try {
|
|
556
|
+
const out = await fetcher(
|
|
557
|
+
body === void 0 ? { url, method: methodUpper } : { url, method: methodUpper, body }
|
|
558
|
+
);
|
|
559
|
+
emitDebug(
|
|
560
|
+
decorateDebugEvent(
|
|
561
|
+
{
|
|
562
|
+
type: "fetch",
|
|
563
|
+
stage: "success",
|
|
564
|
+
method: methodUpper,
|
|
565
|
+
url,
|
|
566
|
+
leaf: leafLabel,
|
|
567
|
+
durationMs: Date.now() - startedAt
|
|
568
|
+
},
|
|
569
|
+
isVerboseDebug ? { params, query: flatQuery, output: out } : void 0
|
|
570
|
+
)
|
|
571
|
+
);
|
|
572
|
+
return out;
|
|
573
|
+
} catch (error) {
|
|
574
|
+
emitDebug(
|
|
575
|
+
decorateDebugEvent(
|
|
576
|
+
{
|
|
577
|
+
type: "fetch",
|
|
578
|
+
stage: "error",
|
|
579
|
+
method: methodUpper,
|
|
580
|
+
url,
|
|
581
|
+
leaf: leafLabel,
|
|
582
|
+
durationMs: Date.now() - startedAt,
|
|
583
|
+
...body !== void 0 ? { body } : {},
|
|
584
|
+
error
|
|
585
|
+
},
|
|
586
|
+
detail
|
|
587
|
+
)
|
|
588
|
+
);
|
|
589
|
+
throw error;
|
|
590
|
+
}
|
|
591
|
+
};
|
|
523
592
|
return {
|
|
524
593
|
queryClient,
|
|
525
594
|
invalidate,
|
|
595
|
+
fetch: fetchRaw,
|
|
526
596
|
build: buildInternal
|
|
527
597
|
};
|
|
528
598
|
}
|
|
@@ -544,6 +614,71 @@ function toFormData(body) {
|
|
|
544
614
|
}
|
|
545
615
|
return fd;
|
|
546
616
|
}
|
|
617
|
+
function getPathParamNames(path) {
|
|
618
|
+
const names = /* @__PURE__ */ new Set();
|
|
619
|
+
const re = /:([A-Za-z0-9_]+)/g;
|
|
620
|
+
let match;
|
|
621
|
+
while ((match = re.exec(path)) !== null) {
|
|
622
|
+
names.add(match[1]);
|
|
623
|
+
}
|
|
624
|
+
return names;
|
|
625
|
+
}
|
|
626
|
+
function normalizeFlatQuery(query) {
|
|
627
|
+
if (query == null) return void 0;
|
|
628
|
+
if (typeof query !== "object" || Array.isArray(query)) {
|
|
629
|
+
throw new Error("Query must be a plain object (Record<string, string>).");
|
|
630
|
+
}
|
|
631
|
+
const result = {};
|
|
632
|
+
for (const [k, v] of Object.entries(query)) {
|
|
633
|
+
if (v == null) continue;
|
|
634
|
+
if (typeof v !== "string") {
|
|
635
|
+
throw new Error(
|
|
636
|
+
`Query param "${k}" must be a string; received type "${typeof v}".`
|
|
637
|
+
);
|
|
638
|
+
}
|
|
639
|
+
result[k] = v;
|
|
640
|
+
}
|
|
641
|
+
return Object.keys(result).length > 0 ? result : void 0;
|
|
642
|
+
}
|
|
643
|
+
function compileRawPath(path, params) {
|
|
644
|
+
const placeholders = getPathParamNames(path);
|
|
645
|
+
if (!params || typeof params !== "object" || Array.isArray(params)) {
|
|
646
|
+
if (placeholders.size > 0) {
|
|
647
|
+
throw new Error(
|
|
648
|
+
`Missing path parameters for "${path}": ${[...placeholders].join(
|
|
649
|
+
", "
|
|
650
|
+
)}`
|
|
651
|
+
);
|
|
652
|
+
}
|
|
653
|
+
return path;
|
|
654
|
+
}
|
|
655
|
+
const paramObj = params;
|
|
656
|
+
const providedNames = new Set(Object.keys(paramObj));
|
|
657
|
+
for (const name of providedNames) {
|
|
658
|
+
if (!placeholders.has(name)) {
|
|
659
|
+
throw new Error(
|
|
660
|
+
`Unexpected path parameter "${name}" for template "${path}".`
|
|
661
|
+
);
|
|
662
|
+
}
|
|
663
|
+
const value = paramObj[name];
|
|
664
|
+
if (value != null && (typeof value === "object" || Array.isArray(value))) {
|
|
665
|
+
throw new Error(
|
|
666
|
+
`Path parameter "${name}" must be a primitive; received "${typeof value}".`
|
|
667
|
+
);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
for (const name of placeholders) {
|
|
671
|
+
if (!providedNames.has(name)) {
|
|
672
|
+
throw new Error(
|
|
673
|
+
`Missing value for path parameter "${name}" in template "${path}".`
|
|
674
|
+
);
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
if (placeholders.size === 0) {
|
|
678
|
+
return path;
|
|
679
|
+
}
|
|
680
|
+
return compilePath(path, paramObj);
|
|
681
|
+
}
|
|
547
682
|
|
|
548
683
|
// src/sockets/socket.client.sys.ts
|
|
549
684
|
import { z as z2 } from "zod";
|