@tolki/ts 0.1.0 → 1.0.0
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/README.md +4746 -52
- package/dist/index.js +12 -11
- package/dist/routes.d.ts +22 -3
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +126 -120
- package/package.json +21 -4
package/dist/index.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { cases as o, defineEnum as
|
|
2
|
-
import { addRouteDefault as s, annotatePageProps as m, defineRoute as
|
|
1
|
+
import { cases as o, defineEnum as a, from as f, tryFrom as u } from "./enums.js";
|
|
2
|
+
import { addRouteDefault as s, annotatePageProps as n, annotateRequestPayload as m, defineRoute as R, formSafeOptions as d, getRouteDefaults as l, resetRouteDefaults as p, setRouteDefaults as D } from "./routes.js";
|
|
3
3
|
export {
|
|
4
4
|
s as addRouteDefault,
|
|
5
|
-
|
|
5
|
+
n as annotatePageProps,
|
|
6
|
+
m as annotateRequestPayload,
|
|
6
7
|
o as cases,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
a as defineEnum,
|
|
9
|
+
R as defineRoute,
|
|
10
|
+
d as formSafeOptions,
|
|
11
|
+
f as from,
|
|
12
|
+
l as getRouteDefaults,
|
|
13
|
+
p as resetRouteDefaults,
|
|
14
|
+
D as setRouteDefaults,
|
|
15
|
+
u as tryFrom
|
|
15
16
|
};
|
package/dist/routes.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DefineRouteResult, InferPageProps, RouteArgMeta, RouteCallResult, RouteCallResultWithComponent, RouteComponentType, RouteFormResult, RouteMetadata, RouteQueryOptions } from '../packages/types/src/index.ts';
|
|
2
|
-
export type { DefineRouteResult, InferPageProps, RouteArgMeta, RouteCallResult, RouteCallResultWithComponent, RouteComponentType, RouteFormResult, RouteMetadata, RouteQueryOptions, };
|
|
1
|
+
import { DefineRouteResult, InferPageProps, InferRequestPayload, RouteArgMeta, RouteCallResult, RouteCallResultWithComponent, RouteComponentType, RouteFormResult, RouteMetadata, RouteQueryOptions } from '../packages/types/src/index.ts';
|
|
2
|
+
export type { DefineRouteResult, InferPageProps, InferRequestPayload, RouteArgMeta, RouteCallResult, RouteCallResultWithComponent, RouteComponentType, RouteFormResult, RouteMetadata, RouteQueryOptions, };
|
|
3
3
|
/**
|
|
4
4
|
* Attach a phantom page props type to a `defineRoute` result without losing
|
|
5
5
|
* the inferred TMethods / TArgs / TComponent specificity.
|
|
@@ -18,7 +18,26 @@ export type { DefineRouteResult, InferPageProps, RouteArgMeta, RouteCallResult,
|
|
|
18
18
|
* @returns A one-argument function that accepts a `defineRoute` result and returns
|
|
19
19
|
* the same value cast to carry `TPageProps`.
|
|
20
20
|
*/
|
|
21
|
-
export declare function annotatePageProps<TPageProps>(): <TMethods extends readonly string[], TArgs extends readonly RouteArgMeta[], TComponent extends RouteComponentType | undefined, TExistingPageProps>(route: DefineRouteResult<TMethods, TArgs, TComponent, TExistingPageProps>) => DefineRouteResult<TMethods, TArgs, TComponent, TPageProps>;
|
|
21
|
+
export declare function annotatePageProps<TPageProps>(): <TMethods extends readonly string[], TArgs extends readonly RouteArgMeta[], TComponent extends RouteComponentType | undefined, TExistingPageProps, TExistingRequestPayload>(route: DefineRouteResult<TMethods, TArgs, TComponent, TExistingPageProps, TExistingRequestPayload>) => DefineRouteResult<TMethods, TArgs, TComponent, TPageProps, TExistingRequestPayload>;
|
|
22
|
+
/**
|
|
23
|
+
* Attach a phantom request payload type to a `defineRoute` result without
|
|
24
|
+
* losing the inferred TMethods / TArgs / TComponent / TPageProps specificity.
|
|
25
|
+
*
|
|
26
|
+
* Use a curried call so TypeScript can infer the route generics while you
|
|
27
|
+
* supply `TRequestPayload` explicitly:
|
|
28
|
+
*
|
|
29
|
+
* ```typescript
|
|
30
|
+
* export const store = annotateRequestPayload<StorePostRequest>()(defineRoute({ ... }));
|
|
31
|
+
* type Payload = InferRequestPayload<typeof store>; // StorePostRequest
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* Already-annotated routes can be re-annotated — the existing `TRequestPayload` generic
|
|
35
|
+
* (`TExistingRequestPayload`) is accepted and discarded in favour of the new one.
|
|
36
|
+
*
|
|
37
|
+
* @returns A one-argument function that accepts a `defineRoute` result and returns
|
|
38
|
+
* the same value cast to carry `TRequestPayload`.
|
|
39
|
+
*/
|
|
40
|
+
export declare function annotateRequestPayload<TRequestPayload>(): <TMethods extends readonly string[], TArgs extends readonly RouteArgMeta[], TComponent extends RouteComponentType | undefined, TPageProps, TExistingRequestPayload>(route: DefineRouteResult<TMethods, TArgs, TComponent, TPageProps, TExistingRequestPayload>) => DefineRouteResult<TMethods, TArgs, TComponent, TPageProps, TRequestPayload>;
|
|
22
41
|
/**
|
|
23
42
|
* Set global default route parameter values.
|
|
24
43
|
*
|
package/dist/routes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,eAAe,EACf,4BAA4B,EAC5B,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,iBAAiB,EACpB,MAAM,cAAc,CAAC;AAYtB,YAAY,EACR,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,eAAe,EACf,4BAA4B,EAC5B,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,iBAAiB,GACpB,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,KAAK,CAC7C,QAAQ,SAAS,SAAS,MAAM,EAAE,EAClC,KAAK,SAAS,SAAS,YAAY,EAAE,EACrC,UAAU,SAAS,kBAAkB,GAAG,SAAS,EACjD,kBAAkB,
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,iBAAiB,EACjB,cAAc,EACd,mBAAmB,EACnB,YAAY,EACZ,eAAe,EACf,4BAA4B,EAC5B,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,iBAAiB,EACpB,MAAM,cAAc,CAAC;AAYtB,YAAY,EACR,iBAAiB,EACjB,cAAc,EACd,mBAAmB,EACnB,YAAY,EACZ,eAAe,EACf,4BAA4B,EAC5B,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,iBAAiB,GACpB,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,KAAK,CAC7C,QAAQ,SAAS,SAAS,MAAM,EAAE,EAClC,KAAK,SAAS,SAAS,YAAY,EAAE,EACrC,UAAU,SAAS,kBAAkB,GAAG,SAAS,EACjD,kBAAkB,EAClB,uBAAuB,EAEvB,KAAK,EAAE,iBAAiB,CACpB,QAAQ,EACR,KAAK,EACL,UAAU,EACV,kBAAkB,EAClB,uBAAuB,CAC1B,KACA,iBAAiB,CAClB,QAAQ,EACR,KAAK,EACL,UAAU,EACV,UAAU,EACV,uBAAuB,CAC1B,CA8BA;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,sBAAsB,CAAC,eAAe,KAAK,CACvD,QAAQ,SAAS,SAAS,MAAM,EAAE,EAClC,KAAK,SAAS,SAAS,YAAY,EAAE,EACrC,UAAU,SAAS,kBAAkB,GAAG,SAAS,EACjD,UAAU,EACV,uBAAuB,EAEvB,KAAK,EAAE,iBAAiB,CACpB,QAAQ,EACR,KAAK,EACL,UAAU,EACV,UAAU,EACV,uBAAuB,CAC1B,KACA,iBAAiB,CAClB,QAAQ,EACR,KAAK,EACL,UAAU,EACV,UAAU,EACV,eAAe,CAClB,CA8BA;AAiBD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC5B,QAAQ,EACF,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,GACzC,CAAC,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC,GACxD,IAAI,CAEN;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC3B,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GACjC,IAAI,CAMN;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAE5E;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC;AA8YD;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC3B,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,iBAAiB,GAC5B,iBAAiB,CAWnB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,WAAW,CACvB,KAAK,CAAC,QAAQ,SAAS,SAAS,MAAM,EAAE,EACxC,KAAK,CAAC,KAAK,SAAS,SAAS,YAAY,EAAE,GAAG,SAAS,EAAE,EACzD,KAAK,CAAC,UAAU,SAAS,kBAAkB,GAAG,SAAS,GAAG,SAAS,EAEnE,QAAQ,EAAE,aAAa,CAAC,QAAQ,EAAE,KAAK,EAAE,UAAU,CAAC,GACrD,iBAAiB,CAAC,QAAQ,EAAE,KAAK,EAAE,UAAU,CAAC,CAkGhD"}
|
package/dist/routes.js
CHANGED
|
@@ -1,39 +1,44 @@
|
|
|
1
|
-
import { isString as U, isFunction as E, isUndefined as
|
|
1
|
+
import { isString as U, isFunction as E, isUndefined as $, isNull as j, isObject as g, isArray as q, isNumber as K, isBoolean as Q } from "@tolki/utils";
|
|
2
|
+
function F() {
|
|
3
|
+
return function(e) {
|
|
4
|
+
return e;
|
|
5
|
+
};
|
|
6
|
+
}
|
|
2
7
|
function I() {
|
|
3
8
|
return function(e) {
|
|
4
9
|
return e;
|
|
5
10
|
};
|
|
6
11
|
}
|
|
7
12
|
const C = () => ({});
|
|
8
|
-
let
|
|
9
|
-
function
|
|
10
|
-
|
|
13
|
+
let y = C;
|
|
14
|
+
function T(e) {
|
|
15
|
+
y = E(e) ? e : () => ({ ...e });
|
|
11
16
|
}
|
|
12
|
-
function
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
...
|
|
17
|
+
function V(e, n) {
|
|
18
|
+
const t = y;
|
|
19
|
+
y = () => ({
|
|
20
|
+
...t(),
|
|
16
21
|
[e]: n
|
|
17
22
|
});
|
|
18
23
|
}
|
|
19
|
-
function V() {
|
|
20
|
-
return { ...b() };
|
|
21
|
-
}
|
|
22
24
|
function v() {
|
|
23
|
-
|
|
25
|
+
return { ...y() };
|
|
26
|
+
}
|
|
27
|
+
function L() {
|
|
28
|
+
y = C;
|
|
24
29
|
}
|
|
25
30
|
function O(e, n) {
|
|
26
|
-
if (
|
|
31
|
+
if ($(e) || j(e))
|
|
27
32
|
return "";
|
|
28
33
|
if (g(e)) {
|
|
29
34
|
if (n?._routeKey) {
|
|
30
|
-
const
|
|
31
|
-
if (
|
|
32
|
-
return String(e[
|
|
35
|
+
const t = n._routeKey;
|
|
36
|
+
if (t in e)
|
|
37
|
+
return String(e[t]);
|
|
33
38
|
if ("id" in e)
|
|
34
39
|
return String(e.id);
|
|
35
40
|
throw new Error(
|
|
36
|
-
`Route error: object passed as '${n.name}' parameter is missing route model binding key '${
|
|
41
|
+
`Route error: object passed as '${n.name}' parameter is missing route model binding key '${t}'.`
|
|
37
42
|
);
|
|
38
43
|
}
|
|
39
44
|
if (n?._enumValues) {
|
|
@@ -48,139 +53,139 @@ function O(e, n) {
|
|
|
48
53
|
return String(e);
|
|
49
54
|
}
|
|
50
55
|
function S(e, n) {
|
|
51
|
-
if (
|
|
56
|
+
if (j(n) || $(n))
|
|
52
57
|
return [];
|
|
53
|
-
if (
|
|
58
|
+
if (Q(n))
|
|
54
59
|
return [`${encodeURIComponent(e)}=${n ? "1" : "0"}`];
|
|
55
|
-
if (
|
|
56
|
-
const
|
|
60
|
+
if (q(n)) {
|
|
61
|
+
const t = [];
|
|
57
62
|
for (let r = 0; r < n.length; r++)
|
|
58
|
-
|
|
63
|
+
t.push(
|
|
59
64
|
...S(`${e}[${r}]`, n[r])
|
|
60
65
|
);
|
|
61
|
-
return
|
|
66
|
+
return t;
|
|
62
67
|
}
|
|
63
68
|
if (g(n)) {
|
|
64
|
-
const
|
|
69
|
+
const t = [];
|
|
65
70
|
for (const [r, h] of Object.entries(n))
|
|
66
|
-
|
|
71
|
+
t.push(
|
|
67
72
|
...S(`${e}[${r}]`, h)
|
|
68
73
|
);
|
|
69
|
-
return
|
|
74
|
+
return t;
|
|
70
75
|
}
|
|
71
76
|
return [`${encodeURIComponent(e)}=${encodeURIComponent(String(n))}`];
|
|
72
77
|
}
|
|
73
|
-
function
|
|
78
|
+
function x(e) {
|
|
74
79
|
const n = [];
|
|
75
|
-
for (const [
|
|
76
|
-
n.push(...S(
|
|
80
|
+
for (const [t, r] of Object.entries(e))
|
|
81
|
+
n.push(...S(t, r));
|
|
77
82
|
return n.length === 0 ? "" : `?${n.join("&")}`;
|
|
78
83
|
}
|
|
79
|
-
function
|
|
84
|
+
function R(e, n) {
|
|
80
85
|
if (e.length === 0)
|
|
81
86
|
return [{}, void 0];
|
|
82
|
-
const
|
|
87
|
+
const t = n;
|
|
83
88
|
let r;
|
|
84
|
-
if (
|
|
89
|
+
if (t.length === 0)
|
|
85
90
|
return e.length === 1 && g(e[0]) ? [{}, e[0]] : [{}, void 0];
|
|
86
|
-
const h = new Set(
|
|
91
|
+
const h = new Set(t.map((s) => s.name));
|
|
87
92
|
if (e.length >= 2) {
|
|
88
93
|
const s = e[e.length - 1];
|
|
89
94
|
g(s) && !Object.keys(s).some(
|
|
90
|
-
(
|
|
91
|
-
) && e.length >
|
|
95
|
+
(c) => h.has(c)
|
|
96
|
+
) && e.length > t.length && (r = s, e = e.slice(0, -1));
|
|
92
97
|
}
|
|
93
|
-
if (e.length === 1 &&
|
|
98
|
+
if (e.length === 1 && q(e[0])) {
|
|
94
99
|
const s = e[0], m = {};
|
|
95
|
-
for (let
|
|
96
|
-
m[
|
|
100
|
+
for (let c = 0; c < s.length && c < t.length; c++)
|
|
101
|
+
m[t[c].name] = s[c];
|
|
97
102
|
return [m, r];
|
|
98
103
|
}
|
|
99
104
|
if (e.length === 1 && g(e[0])) {
|
|
100
105
|
const s = e[0];
|
|
101
|
-
if (Object.keys(s).some((
|
|
102
|
-
const
|
|
103
|
-
for (const [
|
|
104
|
-
h.has(
|
|
106
|
+
if (Object.keys(s).some((c) => h.has(c))) {
|
|
107
|
+
const c = {}, i = {};
|
|
108
|
+
for (const [u, f] of Object.entries(s))
|
|
109
|
+
h.has(u) ? c[u] = f : u === "_query" ? r = {
|
|
105
110
|
...r,
|
|
106
|
-
_query:
|
|
107
|
-
} : u
|
|
108
|
-
return Object.keys(
|
|
109
|
-
|
|
111
|
+
_query: f
|
|
112
|
+
} : i[u] = f;
|
|
113
|
+
return Object.keys(i).length > 0 && (r = { ...r, ...i }), [
|
|
114
|
+
c,
|
|
110
115
|
Object.keys(r ?? {}).length > 0 ? r : void 0
|
|
111
116
|
];
|
|
112
117
|
}
|
|
113
|
-
if (
|
|
114
|
-
const
|
|
115
|
-
if (
|
|
116
|
-
return [{ [
|
|
118
|
+
if (t.length === 1) {
|
|
119
|
+
const c = t[0], i = c.name, u = c._routeKey;
|
|
120
|
+
if (u && u in s || "id" in s || "_routeKey" in s)
|
|
121
|
+
return [{ [i]: s }, r];
|
|
117
122
|
}
|
|
118
123
|
return [{}, { ...r, ...s }];
|
|
119
124
|
}
|
|
120
125
|
if (e.length >= 1 && e.every((s) => U(s) || K(s) || g(s))) {
|
|
121
126
|
const s = {};
|
|
122
|
-
for (let m = 0; m < e.length && m <
|
|
123
|
-
s[
|
|
127
|
+
for (let m = 0; m < e.length && m < t.length; m++)
|
|
128
|
+
s[t[m].name] = e[m];
|
|
124
129
|
return [s, r];
|
|
125
130
|
}
|
|
126
131
|
return [{}, r];
|
|
127
132
|
}
|
|
128
|
-
function d(e, n,
|
|
133
|
+
function d(e, n, t, r) {
|
|
129
134
|
let h = e;
|
|
130
135
|
!h.startsWith("/") && !h.startsWith("//") && !h.includes("://") && (h = `//${h}`);
|
|
131
|
-
const s = new Map(
|
|
132
|
-
for (const
|
|
133
|
-
|
|
134
|
-
for (const [
|
|
135
|
-
|
|
136
|
-
for (const
|
|
137
|
-
if (
|
|
138
|
-
const
|
|
139
|
-
if (
|
|
136
|
+
const s = new Map(t.map((o) => [o.name, o])), m = y(), c = {};
|
|
137
|
+
for (const o of t)
|
|
138
|
+
o.name in m && !(o.name in n) && (c[o.name] = m[o.name]);
|
|
139
|
+
for (const [o, l] of Object.entries(n))
|
|
140
|
+
c[o] = l;
|
|
141
|
+
for (const o of t)
|
|
142
|
+
if (o.where && o.name in c) {
|
|
143
|
+
const l = O(c[o.name], o);
|
|
144
|
+
if (l !== "") {
|
|
140
145
|
let p;
|
|
141
146
|
try {
|
|
142
|
-
p = new RegExp(`^${
|
|
147
|
+
p = new RegExp(`^${o.where}$`);
|
|
143
148
|
} catch {
|
|
144
149
|
throw new Error(
|
|
145
|
-
`Route error: '${
|
|
150
|
+
`Route error: '${o.name}' has invalid 'where' constraint pattern '${o.where}'.`
|
|
146
151
|
);
|
|
147
152
|
}
|
|
148
|
-
if (!p.test(
|
|
153
|
+
if (!p.test(l))
|
|
149
154
|
throw new Error(
|
|
150
|
-
`Route error: '${
|
|
155
|
+
`Route error: '${o.name}' parameter '${l}' does not match required format '${o.where}'.`
|
|
151
156
|
);
|
|
152
157
|
}
|
|
153
158
|
}
|
|
154
|
-
const
|
|
159
|
+
const u = h.replace(
|
|
155
160
|
/{([^{}?]+)(\??)}/g,
|
|
156
|
-
(
|
|
157
|
-
const
|
|
158
|
-
if (!p && (
|
|
161
|
+
(o, l, p) => {
|
|
162
|
+
const b = c[l], P = s.get(l);
|
|
163
|
+
if (!p && ($(b) || j(b)))
|
|
159
164
|
throw new Error(
|
|
160
|
-
`Route error: '${
|
|
165
|
+
`Route error: '${l}' parameter is required.`
|
|
161
166
|
);
|
|
162
|
-
const D = O(
|
|
167
|
+
const D = O(b, P);
|
|
163
168
|
return encodeURI(D).replace(/%7C/g, "|").replace(/%25/g, "%").replace(/\$/g, "%24");
|
|
164
169
|
}
|
|
165
|
-
).replace(/([^:])\/{2,}/g, "$1/").replace(/\/+$/, "") || "/",
|
|
170
|
+
).replace(/([^:])\/{2,}/g, "$1/").replace(/\/+$/, "") || "/", f = {};
|
|
166
171
|
if (r) {
|
|
167
172
|
if (r.mergeQuery) {
|
|
168
|
-
const
|
|
169
|
-
for (const [
|
|
170
|
-
l
|
|
171
|
-
for (const [
|
|
172
|
-
|
|
173
|
+
const o = $(globalThis.window) ? new URLSearchParams() : new URLSearchParams(globalThis.window.location.search);
|
|
174
|
+
for (const [l, p] of o.entries())
|
|
175
|
+
f[l] = p;
|
|
176
|
+
for (const [l, p] of Object.entries(r.mergeQuery))
|
|
177
|
+
j(p) || $(p) ? delete f[l] : f[l] = p;
|
|
173
178
|
}
|
|
174
|
-
for (const [
|
|
175
|
-
if (
|
|
176
|
-
for (const [p,
|
|
177
|
-
|
|
179
|
+
for (const [o, l] of Object.entries(r))
|
|
180
|
+
if (o === "_query" && g(l))
|
|
181
|
+
for (const [p, b] of Object.entries(
|
|
182
|
+
l
|
|
178
183
|
))
|
|
179
|
-
|
|
180
|
-
else
|
|
184
|
+
f[p] = b;
|
|
185
|
+
else o !== "_query" && o !== "mergeQuery" && (f[o] = l);
|
|
181
186
|
}
|
|
182
|
-
const a =
|
|
183
|
-
return
|
|
187
|
+
const a = x(f);
|
|
188
|
+
return u + a;
|
|
184
189
|
}
|
|
185
190
|
function k(e, n) {
|
|
186
191
|
return {
|
|
@@ -200,68 +205,69 @@ function _(e, n) {
|
|
|
200
205
|
}
|
|
201
206
|
};
|
|
202
207
|
}
|
|
203
|
-
function
|
|
204
|
-
const
|
|
208
|
+
function w(e, n) {
|
|
209
|
+
const t = n?.mergeQuery ? "mergeQuery" : "_query", r = n?.[t] ?? {};
|
|
205
210
|
return {
|
|
206
211
|
...n,
|
|
207
|
-
[
|
|
212
|
+
[t]: {
|
|
208
213
|
...r,
|
|
209
214
|
_method: e.toUpperCase()
|
|
210
215
|
}
|
|
211
216
|
};
|
|
212
217
|
}
|
|
213
|
-
function
|
|
214
|
-
const n = e.args ?? [],
|
|
215
|
-
const [u,
|
|
216
|
-
return k(
|
|
218
|
+
function W(e) {
|
|
219
|
+
const n = e.args ?? [], t = e.methods[0] ?? "get", r = (...i) => {
|
|
220
|
+
const [u, f] = R(i, n), a = d(e.url, u, n, f);
|
|
221
|
+
return k(a, t);
|
|
217
222
|
}, s = Object.assign(r, {
|
|
218
|
-
url: (...
|
|
219
|
-
const [u,
|
|
220
|
-
return d(e.url, u, n,
|
|
223
|
+
url: (...i) => {
|
|
224
|
+
const [u, f] = R(i, n);
|
|
225
|
+
return d(e.url, u, n, f);
|
|
221
226
|
},
|
|
222
227
|
definition: e,
|
|
223
228
|
toString() {
|
|
224
229
|
return d(e.url, {}, n);
|
|
225
230
|
}
|
|
226
231
|
});
|
|
227
|
-
for (const
|
|
232
|
+
for (const i of e.methods)
|
|
228
233
|
Object.assign(s, {
|
|
229
|
-
[
|
|
230
|
-
const [
|
|
231
|
-
return k(
|
|
234
|
+
[i]: (...u) => {
|
|
235
|
+
const [f, a] = R(u, n), o = d(e.url, f, n, a);
|
|
236
|
+
return k(o, i);
|
|
232
237
|
}
|
|
233
238
|
});
|
|
234
|
-
const m = (...
|
|
235
|
-
const [u,
|
|
236
|
-
return _(
|
|
239
|
+
const m = t !== "get" && t !== "post", c = (...i) => {
|
|
240
|
+
const [u, f] = R(i, n), a = m ? w(t, f) : f, o = d(e.url, u, n, a);
|
|
241
|
+
return _(o, t);
|
|
237
242
|
};
|
|
238
|
-
for (const
|
|
239
|
-
const u =
|
|
240
|
-
Object.assign(
|
|
241
|
-
[
|
|
242
|
-
const [
|
|
243
|
-
return _(
|
|
243
|
+
for (const i of e.methods) {
|
|
244
|
+
const u = i !== "get" && i !== "post";
|
|
245
|
+
Object.assign(c, {
|
|
246
|
+
[i]: (...f) => {
|
|
247
|
+
const [a, o] = R(f, n), l = u ? w(i, o) : o, p = d(e.url, a, n, l);
|
|
248
|
+
return _(p, i);
|
|
244
249
|
}
|
|
245
250
|
});
|
|
246
251
|
}
|
|
247
|
-
if (Object.assign(s, { form:
|
|
252
|
+
if (Object.assign(s, { form: c }), e.component !== void 0)
|
|
248
253
|
if (Object.assign(s, { component: e.component }), U(e.component)) {
|
|
249
|
-
const
|
|
254
|
+
const i = e.component;
|
|
250
255
|
Object.assign(s, {
|
|
251
|
-
withComponent: (...u) => ({ ...r(...u), component:
|
|
256
|
+
withComponent: (...u) => ({ ...r(...u), component: i })
|
|
252
257
|
});
|
|
253
258
|
} else
|
|
254
259
|
Object.assign(s, {
|
|
255
|
-
withComponent: (
|
|
260
|
+
withComponent: (i, ...u) => ({ ...r(...u), component: i })
|
|
256
261
|
});
|
|
257
262
|
return s;
|
|
258
263
|
}
|
|
259
264
|
export {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
v as
|
|
266
|
-
|
|
265
|
+
V as addRouteDefault,
|
|
266
|
+
F as annotatePageProps,
|
|
267
|
+
I as annotateRequestPayload,
|
|
268
|
+
W as defineRoute,
|
|
269
|
+
w as formSafeOptions,
|
|
270
|
+
v as getRouteDefaults,
|
|
271
|
+
L as resetRouteDefaults,
|
|
272
|
+
T as setRouteDefaults
|
|
267
273
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tolki/ts",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "A set of TypeScript utilities for the Laravel TypeScript Publish PHP package.",
|
|
5
5
|
"author": "Abraham Arango <https://github.com/abetwothree>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"tolki"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@tolki/types": "^1.
|
|
42
|
+
"@tolki/types": "^1.4.0",
|
|
43
43
|
"@tolki/utils": "^1.0.2"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
@@ -74,8 +74,25 @@
|
|
|
74
74
|
"tolki": {
|
|
75
75
|
"docs": [
|
|
76
76
|
"ts/index.md",
|
|
77
|
-
"ts/
|
|
78
|
-
"ts/
|
|
77
|
+
"ts/enums.md",
|
|
78
|
+
"ts/models.md",
|
|
79
|
+
"ts/api-resources.md",
|
|
80
|
+
"ts/broadcast-channels.md",
|
|
81
|
+
"ts/broadcast-events.md",
|
|
82
|
+
"ts/casing-configuration.md",
|
|
83
|
+
"ts/enum-api-resource.md",
|
|
84
|
+
"ts/excluding-content.md",
|
|
85
|
+
"ts/extending-interfaces.md",
|
|
86
|
+
"ts/form-requests.md",
|
|
87
|
+
"ts/generating-cache.md",
|
|
88
|
+
"ts/inertia.md",
|
|
89
|
+
"ts/modular-publishing.md",
|
|
90
|
+
"ts/pre-command-hook.md",
|
|
91
|
+
"ts/routing.md",
|
|
92
|
+
"ts/vite-env.md",
|
|
93
|
+
"ts/vite-plugin.md",
|
|
94
|
+
"ts/customizing-the-pipeline.md",
|
|
95
|
+
"ts/configuration-reference.md"
|
|
79
96
|
]
|
|
80
97
|
},
|
|
81
98
|
"scripts": {
|