@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.cjs
CHANGED
|
@@ -189,7 +189,9 @@ function getZodShape(schema) {
|
|
|
189
189
|
function augmentFeedQuerySchema(schema) {
|
|
190
190
|
if (!schema) return defaultFeedQuerySchema;
|
|
191
191
|
if (!(schema instanceof import_zod.z.ZodObject)) {
|
|
192
|
-
console.warn(
|
|
192
|
+
console.warn(
|
|
193
|
+
"Feed queries must be a ZodObject; default pagination applied."
|
|
194
|
+
);
|
|
193
195
|
return defaultFeedQuerySchema;
|
|
194
196
|
}
|
|
195
197
|
return schema.extend(paginationQueryShape);
|
|
@@ -554,9 +556,77 @@ function createRouteClient(opts) {
|
|
|
554
556
|
fetch: fetchMutation
|
|
555
557
|
};
|
|
556
558
|
}
|
|
559
|
+
const fetchRaw = async (input) => {
|
|
560
|
+
const { path, method, query, body, params } = input;
|
|
561
|
+
if (!path || typeof path !== "string") {
|
|
562
|
+
throw new Error("fetch(path, ...) requires a non-empty string path.");
|
|
563
|
+
}
|
|
564
|
+
if (!method) {
|
|
565
|
+
throw new Error("fetch(path, method, ...) requires an HTTP method.");
|
|
566
|
+
}
|
|
567
|
+
const methodLower = String(method).toLowerCase();
|
|
568
|
+
const methodUpper = toUpper(methodLower);
|
|
569
|
+
const flatQuery = normalizeFlatQuery(query);
|
|
570
|
+
const search = toSearchString(flatQuery);
|
|
571
|
+
const compiledPath = compileRawPath(path, params);
|
|
572
|
+
const url = `${baseUrl ?? ""}${compiledPath}${search}`;
|
|
573
|
+
const leafLabel = `${methodUpper} ${path}`;
|
|
574
|
+
const startedAt = Date.now();
|
|
575
|
+
const detail = isVerboseDebug ? { params, query: flatQuery } : void 0;
|
|
576
|
+
emitDebug(
|
|
577
|
+
decorateDebugEvent(
|
|
578
|
+
{
|
|
579
|
+
type: "fetch",
|
|
580
|
+
stage: "start",
|
|
581
|
+
method: methodUpper,
|
|
582
|
+
url,
|
|
583
|
+
leaf: leafLabel,
|
|
584
|
+
...body !== void 0 ? { body } : {}
|
|
585
|
+
},
|
|
586
|
+
detail
|
|
587
|
+
)
|
|
588
|
+
);
|
|
589
|
+
try {
|
|
590
|
+
const out = await fetcher(
|
|
591
|
+
body === void 0 ? { url, method: methodUpper } : { url, method: methodUpper, body }
|
|
592
|
+
);
|
|
593
|
+
emitDebug(
|
|
594
|
+
decorateDebugEvent(
|
|
595
|
+
{
|
|
596
|
+
type: "fetch",
|
|
597
|
+
stage: "success",
|
|
598
|
+
method: methodUpper,
|
|
599
|
+
url,
|
|
600
|
+
leaf: leafLabel,
|
|
601
|
+
durationMs: Date.now() - startedAt
|
|
602
|
+
},
|
|
603
|
+
isVerboseDebug ? { params, query: flatQuery, output: out } : void 0
|
|
604
|
+
)
|
|
605
|
+
);
|
|
606
|
+
return out;
|
|
607
|
+
} catch (error) {
|
|
608
|
+
emitDebug(
|
|
609
|
+
decorateDebugEvent(
|
|
610
|
+
{
|
|
611
|
+
type: "fetch",
|
|
612
|
+
stage: "error",
|
|
613
|
+
method: methodUpper,
|
|
614
|
+
url,
|
|
615
|
+
leaf: leafLabel,
|
|
616
|
+
durationMs: Date.now() - startedAt,
|
|
617
|
+
...body !== void 0 ? { body } : {},
|
|
618
|
+
error
|
|
619
|
+
},
|
|
620
|
+
detail
|
|
621
|
+
)
|
|
622
|
+
);
|
|
623
|
+
throw error;
|
|
624
|
+
}
|
|
625
|
+
};
|
|
557
626
|
return {
|
|
558
627
|
queryClient,
|
|
559
628
|
invalidate,
|
|
629
|
+
fetch: fetchRaw,
|
|
560
630
|
build: buildInternal
|
|
561
631
|
};
|
|
562
632
|
}
|
|
@@ -578,6 +648,71 @@ function toFormData(body) {
|
|
|
578
648
|
}
|
|
579
649
|
return fd;
|
|
580
650
|
}
|
|
651
|
+
function getPathParamNames(path) {
|
|
652
|
+
const names = /* @__PURE__ */ new Set();
|
|
653
|
+
const re = /:([A-Za-z0-9_]+)/g;
|
|
654
|
+
let match;
|
|
655
|
+
while ((match = re.exec(path)) !== null) {
|
|
656
|
+
names.add(match[1]);
|
|
657
|
+
}
|
|
658
|
+
return names;
|
|
659
|
+
}
|
|
660
|
+
function normalizeFlatQuery(query) {
|
|
661
|
+
if (query == null) return void 0;
|
|
662
|
+
if (typeof query !== "object" || Array.isArray(query)) {
|
|
663
|
+
throw new Error("Query must be a plain object (Record<string, string>).");
|
|
664
|
+
}
|
|
665
|
+
const result = {};
|
|
666
|
+
for (const [k, v] of Object.entries(query)) {
|
|
667
|
+
if (v == null) continue;
|
|
668
|
+
if (typeof v !== "string") {
|
|
669
|
+
throw new Error(
|
|
670
|
+
`Query param "${k}" must be a string; received type "${typeof v}".`
|
|
671
|
+
);
|
|
672
|
+
}
|
|
673
|
+
result[k] = v;
|
|
674
|
+
}
|
|
675
|
+
return Object.keys(result).length > 0 ? result : void 0;
|
|
676
|
+
}
|
|
677
|
+
function compileRawPath(path, params) {
|
|
678
|
+
const placeholders = getPathParamNames(path);
|
|
679
|
+
if (!params || typeof params !== "object" || Array.isArray(params)) {
|
|
680
|
+
if (placeholders.size > 0) {
|
|
681
|
+
throw new Error(
|
|
682
|
+
`Missing path parameters for "${path}": ${[...placeholders].join(
|
|
683
|
+
", "
|
|
684
|
+
)}`
|
|
685
|
+
);
|
|
686
|
+
}
|
|
687
|
+
return path;
|
|
688
|
+
}
|
|
689
|
+
const paramObj = params;
|
|
690
|
+
const providedNames = new Set(Object.keys(paramObj));
|
|
691
|
+
for (const name of providedNames) {
|
|
692
|
+
if (!placeholders.has(name)) {
|
|
693
|
+
throw new Error(
|
|
694
|
+
`Unexpected path parameter "${name}" for template "${path}".`
|
|
695
|
+
);
|
|
696
|
+
}
|
|
697
|
+
const value = paramObj[name];
|
|
698
|
+
if (value != null && (typeof value === "object" || Array.isArray(value))) {
|
|
699
|
+
throw new Error(
|
|
700
|
+
`Path parameter "${name}" must be a primitive; received "${typeof value}".`
|
|
701
|
+
);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
for (const name of placeholders) {
|
|
705
|
+
if (!providedNames.has(name)) {
|
|
706
|
+
throw new Error(
|
|
707
|
+
`Missing value for path parameter "${name}" in template "${path}".`
|
|
708
|
+
);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
if (placeholders.size === 0) {
|
|
712
|
+
return path;
|
|
713
|
+
}
|
|
714
|
+
return (0, import_rrroutes_contract.compilePath)(path, paramObj);
|
|
715
|
+
}
|
|
581
716
|
|
|
582
717
|
// src/sockets/socket.client.sys.ts
|
|
583
718
|
var import_zod2 = require("zod");
|