@emeryld/rrroutes-client 2.2.15 → 2.2.17
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 +166 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +165 -5
- package/dist/index.mjs.map +1 -1
- package/dist/routesV3.client.fetch.d.ts +12 -0
- package/dist/routesV3.client.types.d.ts +47 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
// src/routesV3.client.fetch.ts
|
|
4
|
+
var HttpError = class extends Error {
|
|
5
|
+
constructor(args) {
|
|
6
|
+
const { res, url, body } = args;
|
|
7
|
+
super(`[${res.status}] ${res.statusText}${body ? ` - ${body}` : ""}`);
|
|
8
|
+
this.message = `${this.message}`;
|
|
9
|
+
this.name = "HttpError";
|
|
10
|
+
this.status = res.status;
|
|
11
|
+
this.statusText = res.statusText;
|
|
12
|
+
this.url = url;
|
|
13
|
+
this.body = body;
|
|
14
|
+
this.headers = res.headers ? Object.fromEntries(res.headers.entries()) : {};
|
|
15
|
+
}
|
|
16
|
+
};
|
|
4
17
|
var defaultFetcher = async (req) => {
|
|
5
18
|
const headers = { ...req.headers ?? {} };
|
|
6
19
|
const isFormData = typeof FormData !== "undefined" && req.body instanceof FormData;
|
|
@@ -15,13 +28,24 @@ var defaultFetcher = async (req) => {
|
|
|
15
28
|
});
|
|
16
29
|
const text = await res.text();
|
|
17
30
|
if (!res.ok) {
|
|
18
|
-
|
|
19
|
-
|
|
31
|
+
throw new HttpError({
|
|
32
|
+
res,
|
|
33
|
+
url: req.url,
|
|
34
|
+
body: text
|
|
35
|
+
});
|
|
20
36
|
}
|
|
21
37
|
try {
|
|
22
|
-
return
|
|
38
|
+
return {
|
|
39
|
+
data: JSON.parse(text),
|
|
40
|
+
headers: res.headers ? Object.fromEntries(res.headers.entries()) : {},
|
|
41
|
+
status: res.status
|
|
42
|
+
};
|
|
23
43
|
} catch {
|
|
24
|
-
return
|
|
44
|
+
return {
|
|
45
|
+
data: text,
|
|
46
|
+
headers: res.headers ? Object.fromEntries(res.headers.entries()) : {},
|
|
47
|
+
status: res.status
|
|
48
|
+
};
|
|
25
49
|
}
|
|
26
50
|
};
|
|
27
51
|
|
|
@@ -155,7 +179,9 @@ function getZodShape(schema) {
|
|
|
155
179
|
function augmentFeedQuerySchema(schema) {
|
|
156
180
|
if (!schema) return defaultFeedQuerySchema;
|
|
157
181
|
if (!(schema instanceof z.ZodObject)) {
|
|
158
|
-
console.warn(
|
|
182
|
+
console.warn(
|
|
183
|
+
"Feed queries must be a ZodObject; default pagination applied."
|
|
184
|
+
);
|
|
159
185
|
return defaultFeedQuerySchema;
|
|
160
186
|
}
|
|
161
187
|
return schema.extend(paginationQueryShape);
|
|
@@ -520,9 +546,77 @@ function createRouteClient(opts) {
|
|
|
520
546
|
fetch: fetchMutation
|
|
521
547
|
};
|
|
522
548
|
}
|
|
549
|
+
const fetchRaw = async (input) => {
|
|
550
|
+
const { path, method, query, body, params } = input;
|
|
551
|
+
if (!path || typeof path !== "string") {
|
|
552
|
+
throw new Error("fetch(path, ...) requires a non-empty string path.");
|
|
553
|
+
}
|
|
554
|
+
if (!method) {
|
|
555
|
+
throw new Error("fetch(path, method, ...) requires an HTTP method.");
|
|
556
|
+
}
|
|
557
|
+
const methodLower = String(method).toLowerCase();
|
|
558
|
+
const methodUpper = toUpper(methodLower);
|
|
559
|
+
const flatQuery = normalizeFlatQuery(query);
|
|
560
|
+
const search = toSearchString(flatQuery);
|
|
561
|
+
const compiledPath = compileRawPath(path, params);
|
|
562
|
+
const url = `${baseUrl ?? ""}${compiledPath}${search}`;
|
|
563
|
+
const leafLabel = `${methodUpper} ${path}`;
|
|
564
|
+
const startedAt = Date.now();
|
|
565
|
+
const detail = isVerboseDebug ? { params, query: flatQuery } : void 0;
|
|
566
|
+
emitDebug(
|
|
567
|
+
decorateDebugEvent(
|
|
568
|
+
{
|
|
569
|
+
type: "fetch",
|
|
570
|
+
stage: "start",
|
|
571
|
+
method: methodUpper,
|
|
572
|
+
url,
|
|
573
|
+
leaf: leafLabel,
|
|
574
|
+
...body !== void 0 ? { body } : {}
|
|
575
|
+
},
|
|
576
|
+
detail
|
|
577
|
+
)
|
|
578
|
+
);
|
|
579
|
+
try {
|
|
580
|
+
const out = await fetcher(
|
|
581
|
+
body === void 0 ? { url, method: methodUpper } : { url, method: methodUpper, body }
|
|
582
|
+
);
|
|
583
|
+
emitDebug(
|
|
584
|
+
decorateDebugEvent(
|
|
585
|
+
{
|
|
586
|
+
type: "fetch",
|
|
587
|
+
stage: "success",
|
|
588
|
+
method: methodUpper,
|
|
589
|
+
url,
|
|
590
|
+
leaf: leafLabel,
|
|
591
|
+
durationMs: Date.now() - startedAt
|
|
592
|
+
},
|
|
593
|
+
isVerboseDebug ? { params, query: flatQuery, output: out } : void 0
|
|
594
|
+
)
|
|
595
|
+
);
|
|
596
|
+
return out;
|
|
597
|
+
} catch (error) {
|
|
598
|
+
emitDebug(
|
|
599
|
+
decorateDebugEvent(
|
|
600
|
+
{
|
|
601
|
+
type: "fetch",
|
|
602
|
+
stage: "error",
|
|
603
|
+
method: methodUpper,
|
|
604
|
+
url,
|
|
605
|
+
leaf: leafLabel,
|
|
606
|
+
durationMs: Date.now() - startedAt,
|
|
607
|
+
...body !== void 0 ? { body } : {},
|
|
608
|
+
error
|
|
609
|
+
},
|
|
610
|
+
detail
|
|
611
|
+
)
|
|
612
|
+
);
|
|
613
|
+
throw error;
|
|
614
|
+
}
|
|
615
|
+
};
|
|
523
616
|
return {
|
|
524
617
|
queryClient,
|
|
525
618
|
invalidate,
|
|
619
|
+
fetch: fetchRaw,
|
|
526
620
|
build: buildInternal
|
|
527
621
|
};
|
|
528
622
|
}
|
|
@@ -544,6 +638,71 @@ function toFormData(body) {
|
|
|
544
638
|
}
|
|
545
639
|
return fd;
|
|
546
640
|
}
|
|
641
|
+
function getPathParamNames(path) {
|
|
642
|
+
const names = /* @__PURE__ */ new Set();
|
|
643
|
+
const re = /:([A-Za-z0-9_]+)/g;
|
|
644
|
+
let match;
|
|
645
|
+
while ((match = re.exec(path)) !== null) {
|
|
646
|
+
names.add(match[1]);
|
|
647
|
+
}
|
|
648
|
+
return names;
|
|
649
|
+
}
|
|
650
|
+
function normalizeFlatQuery(query) {
|
|
651
|
+
if (query == null) return void 0;
|
|
652
|
+
if (typeof query !== "object" || Array.isArray(query)) {
|
|
653
|
+
throw new Error("Query must be a plain object (Record<string, string>).");
|
|
654
|
+
}
|
|
655
|
+
const result = {};
|
|
656
|
+
for (const [k, v] of Object.entries(query)) {
|
|
657
|
+
if (v == null) continue;
|
|
658
|
+
if (typeof v !== "string") {
|
|
659
|
+
throw new Error(
|
|
660
|
+
`Query param "${k}" must be a string; received type "${typeof v}".`
|
|
661
|
+
);
|
|
662
|
+
}
|
|
663
|
+
result[k] = v;
|
|
664
|
+
}
|
|
665
|
+
return Object.keys(result).length > 0 ? result : void 0;
|
|
666
|
+
}
|
|
667
|
+
function compileRawPath(path, params) {
|
|
668
|
+
const placeholders = getPathParamNames(path);
|
|
669
|
+
if (!params || typeof params !== "object" || Array.isArray(params)) {
|
|
670
|
+
if (placeholders.size > 0) {
|
|
671
|
+
throw new Error(
|
|
672
|
+
`Missing path parameters for "${path}": ${[...placeholders].join(
|
|
673
|
+
", "
|
|
674
|
+
)}`
|
|
675
|
+
);
|
|
676
|
+
}
|
|
677
|
+
return path;
|
|
678
|
+
}
|
|
679
|
+
const paramObj = params;
|
|
680
|
+
const providedNames = new Set(Object.keys(paramObj));
|
|
681
|
+
for (const name of providedNames) {
|
|
682
|
+
if (!placeholders.has(name)) {
|
|
683
|
+
throw new Error(
|
|
684
|
+
`Unexpected path parameter "${name}" for template "${path}".`
|
|
685
|
+
);
|
|
686
|
+
}
|
|
687
|
+
const value = paramObj[name];
|
|
688
|
+
if (value != null && (typeof value === "object" || Array.isArray(value))) {
|
|
689
|
+
throw new Error(
|
|
690
|
+
`Path parameter "${name}" must be a primitive; received "${typeof value}".`
|
|
691
|
+
);
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
for (const name of placeholders) {
|
|
695
|
+
if (!providedNames.has(name)) {
|
|
696
|
+
throw new Error(
|
|
697
|
+
`Missing value for path parameter "${name}" in template "${path}".`
|
|
698
|
+
);
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
if (placeholders.size === 0) {
|
|
702
|
+
return path;
|
|
703
|
+
}
|
|
704
|
+
return compilePath(path, paramObj);
|
|
705
|
+
}
|
|
547
706
|
|
|
548
707
|
// src/sockets/socket.client.sys.ts
|
|
549
708
|
import { z as z2 } from "zod";
|
|
@@ -1564,6 +1723,7 @@ var SocketClient = class {
|
|
|
1564
1723
|
}
|
|
1565
1724
|
};
|
|
1566
1725
|
export {
|
|
1726
|
+
HttpError,
|
|
1567
1727
|
SocketClient,
|
|
1568
1728
|
buildRoomPayloadSchema,
|
|
1569
1729
|
buildRouter,
|