silgi 0.4.8 → 0.4.11
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/_chunks/index.mjs +1 -1
- package/dist/cli/prepare.mjs +28 -4
- package/dist/core/index.d.mts +21 -36
- package/dist/core/index.d.ts +21 -36
- package/dist/core/index.mjs +8 -6
- package/dist/ecosystem/nitro/index.mjs +1 -1
- package/dist/ecosystem/nuxt/module.mjs +1 -1
- package/dist/meta/index.d.mts +1 -1
- package/dist/meta/index.d.ts +1 -1
- package/dist/runtime/internal/nuxt.d.ts +15 -15
- package/dist/runtime/internal/nuxt.mjs +8 -5
- package/package.json +1 -1
package/dist/_chunks/index.mjs
CHANGED
package/dist/cli/prepare.mjs
CHANGED
|
@@ -250,10 +250,29 @@ async function generateRouterDTS(silgi) {
|
|
|
250
250
|
silgi.hook("close", async () => {
|
|
251
251
|
const { object } = await data();
|
|
252
252
|
const uris = object.uris;
|
|
253
|
-
const
|
|
254
|
-
|
|
253
|
+
const groupedPaths = /* @__PURE__ */ new Map();
|
|
254
|
+
Object.entries(uris || {}).forEach(([key, params]) => {
|
|
255
255
|
const [service, resource, method, action] = key.split("/");
|
|
256
|
-
const
|
|
256
|
+
const basePath = params ? `${service}/${resource}/${action}/${params}` : `${service}/${resource}/${action}`;
|
|
257
|
+
const fullPath = `${service}/${resource}/${action}`;
|
|
258
|
+
if (!groupedPaths.has(basePath)) {
|
|
259
|
+
groupedPaths.set(basePath, /* @__PURE__ */ new Map());
|
|
260
|
+
}
|
|
261
|
+
groupedPaths.get(basePath)?.set(method.toLowerCase(), fullPath);
|
|
262
|
+
});
|
|
263
|
+
const keys = [
|
|
264
|
+
" keys: {",
|
|
265
|
+
Array.from(groupedPaths.entries()).map(([basePath, methods]) => {
|
|
266
|
+
return ` '/${basePath}': {${Array.from(methods.entries()).map(([method, path]) => `
|
|
267
|
+
${method}: '/${path}'`).join(",")}
|
|
268
|
+
}`;
|
|
269
|
+
}).join(",\n"),
|
|
270
|
+
" }",
|
|
271
|
+
""
|
|
272
|
+
].join("\n");
|
|
273
|
+
const groupedRoutes = Object.entries(uris || {}).reduce((acc, [key, _params]) => {
|
|
274
|
+
const [service, resource, method, action] = key.split("/");
|
|
275
|
+
const routePath = `${service}/${resource}/${action}`;
|
|
257
276
|
if (!acc[routePath]) {
|
|
258
277
|
acc[routePath] = {};
|
|
259
278
|
}
|
|
@@ -281,11 +300,16 @@ ${methodEntries}
|
|
|
281
300
|
" interface InternalApi extends RouterTypes {}",
|
|
282
301
|
"}"
|
|
283
302
|
];
|
|
303
|
+
const content = [
|
|
304
|
+
keys.slice(0, -1),
|
|
305
|
+
// son satırdaki boş satırı kaldır
|
|
306
|
+
...routerTypes
|
|
307
|
+
].join(",\n");
|
|
284
308
|
const context = [
|
|
285
309
|
"import type { ExtractInputFromURI, ExtractOutputFromURI, ExtractRouterParamsFromURI } from 'silgi/types'",
|
|
286
310
|
"",
|
|
287
311
|
"export interface RouterTypes {",
|
|
288
|
-
|
|
312
|
+
content,
|
|
289
313
|
"}",
|
|
290
314
|
"",
|
|
291
315
|
"declare module 'silgi/types' {",
|
package/dist/core/index.d.mts
CHANGED
|
@@ -14,49 +14,34 @@ declare function silgiGenerateType(silgi: SilgiCLI): Promise<{
|
|
|
14
14
|
|
|
15
15
|
declare function createSilgi(config: SilgiConfig): Promise<Silgi>;
|
|
16
16
|
|
|
17
|
-
type
|
|
18
|
-
type
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
type
|
|
22
|
-
[K in StaticRoutes]: ExtractStaticPath<K & string> extends never ? never : T extends `${ExtractStaticPath<K & string>}${string}` ? K : never;
|
|
23
|
-
}[StaticRoutes];
|
|
24
|
-
type Method<R extends ValidRoute> = R extends StaticRoutes ? keyof SilgiRouterTypes[R] : keyof SilgiRouterTypes[FindMatchingRoute<R & string>];
|
|
25
|
-
type DefaultMethodType = 'get' | 'post' | 'put' | 'delete';
|
|
26
|
-
type FetchResponseData<R extends ValidRoute, M extends Method<R>> = R extends StaticRoutes ? SilgiRouterTypes[R][M & keyof SilgiRouterTypes[R]]['output'] : SilgiRouterTypes[FindMatchingRoute<R & string>][M & keyof SilgiRouterTypes[FindMatchingRoute<R & string>]]['output'];
|
|
27
|
-
type RequestBodyOption<R extends ValidRoute, M extends Method<R>> = R extends StaticRoutes ? SilgiRouterTypes[R][M & keyof SilgiRouterTypes[R]] extends {
|
|
28
|
-
input: infer I;
|
|
29
|
-
} ? {
|
|
30
|
-
body: I;
|
|
31
|
-
} : {
|
|
32
|
-
body?: never;
|
|
33
|
-
} : SilgiRouterTypes[FindMatchingRoute<R & string>][M & keyof SilgiRouterTypes[FindMatchingRoute<R & string>]] extends {
|
|
34
|
-
input: infer I;
|
|
35
|
-
} ? {
|
|
36
|
-
body: I;
|
|
37
|
-
} : {
|
|
38
|
-
body?: never;
|
|
39
|
-
};
|
|
40
|
-
type ExtractParams<T extends string> = T extends `${string}:${infer Param}/${infer Rest}` ? {
|
|
17
|
+
type TrimAfterFourSlashes<T extends string> = T extends `/${infer S1}/${infer S2}/${infer S3}/${infer _}` ? `/${S1}/${S2}/${S3}` : T;
|
|
18
|
+
type AllPaths = SilgiRouterTypes extends {
|
|
19
|
+
keys: infer U;
|
|
20
|
+
} ? keyof U extends never ? string : keyof U : string;
|
|
21
|
+
type ExtractPathParams<T extends string> = T extends `${infer _Start}:${infer Param}/${infer Rest}` ? {
|
|
41
22
|
[K in Param]: string;
|
|
42
|
-
} &
|
|
23
|
+
} & ExtractPathParams<Rest> : T extends `${infer _Start}:${infer Param}` ? {
|
|
43
24
|
[K in Param]: string;
|
|
44
25
|
} : object;
|
|
45
|
-
type
|
|
46
|
-
|
|
26
|
+
type ValidRoute = AllPaths | (string & {});
|
|
27
|
+
type Method<R extends ValidRoute> = TrimAfterFourSlashes<R> extends keyof SilgiRouterTypes ? keyof SilgiRouterTypes[TrimAfterFourSlashes<R>] : never;
|
|
28
|
+
type FetchResponseData<R extends ValidRoute, M extends Method<R>> = TrimAfterFourSlashes<R> extends keyof SilgiRouterTypes ? SilgiRouterTypes[TrimAfterFourSlashes<R>][M]['output'] : never;
|
|
29
|
+
type RequestBodyOption<R extends ValidRoute, M extends Method<R>> = TrimAfterFourSlashes<R> extends keyof SilgiRouterTypes ? SilgiRouterTypes[TrimAfterFourSlashes<R>][M] extends {
|
|
30
|
+
input: infer I;
|
|
47
31
|
} ? {
|
|
48
|
-
|
|
49
|
-
} : R extends `${string}:${string}` ? {
|
|
50
|
-
params: ExtractParams<R>;
|
|
51
|
-
} : {
|
|
52
|
-
params?: never;
|
|
32
|
+
body: I;
|
|
53
33
|
} : {
|
|
54
|
-
|
|
55
|
-
};
|
|
34
|
+
body?: never;
|
|
35
|
+
} : never;
|
|
36
|
+
type RouterParams<R extends ValidRoute> = ExtractPathParams<R>;
|
|
56
37
|
type SilgiFetchOptions<R extends ValidRoute, M extends Method<R>> = {
|
|
57
38
|
method: M;
|
|
58
|
-
} & RequestBodyOption<R, M> & RouterParams<R
|
|
59
|
-
|
|
39
|
+
} & RequestBodyOption<R, M> & (RouterParams<R> extends object ? {
|
|
40
|
+
params: RouterParams<R>;
|
|
41
|
+
} : {
|
|
42
|
+
params?: never;
|
|
43
|
+
}) & Omit<FetchOptions, 'query' | 'body' | 'method'>;
|
|
44
|
+
type SilgiFetchClient = <R extends ValidRoute, M extends Method<R> = 'get' extends Method<R> ? 'get' : Method<R>>(url: R, options: SilgiFetchOptions<R, M>) => Promise<FetchResponseData<R, M>>;
|
|
60
45
|
declare function createSilgiFetch(options: FetchOptions | ((options: FetchOptions) => FetchOptions), localFetch?: typeof globalThis.$fetch): SilgiFetchClient;
|
|
61
46
|
|
|
62
47
|
interface Options {
|
package/dist/core/index.d.ts
CHANGED
|
@@ -14,49 +14,34 @@ declare function silgiGenerateType(silgi: SilgiCLI): Promise<{
|
|
|
14
14
|
|
|
15
15
|
declare function createSilgi(config: SilgiConfig): Promise<Silgi>;
|
|
16
16
|
|
|
17
|
-
type
|
|
18
|
-
type
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
type
|
|
22
|
-
[K in StaticRoutes]: ExtractStaticPath<K & string> extends never ? never : T extends `${ExtractStaticPath<K & string>}${string}` ? K : never;
|
|
23
|
-
}[StaticRoutes];
|
|
24
|
-
type Method<R extends ValidRoute> = R extends StaticRoutes ? keyof SilgiRouterTypes[R] : keyof SilgiRouterTypes[FindMatchingRoute<R & string>];
|
|
25
|
-
type DefaultMethodType = 'get' | 'post' | 'put' | 'delete';
|
|
26
|
-
type FetchResponseData<R extends ValidRoute, M extends Method<R>> = R extends StaticRoutes ? SilgiRouterTypes[R][M & keyof SilgiRouterTypes[R]]['output'] : SilgiRouterTypes[FindMatchingRoute<R & string>][M & keyof SilgiRouterTypes[FindMatchingRoute<R & string>]]['output'];
|
|
27
|
-
type RequestBodyOption<R extends ValidRoute, M extends Method<R>> = R extends StaticRoutes ? SilgiRouterTypes[R][M & keyof SilgiRouterTypes[R]] extends {
|
|
28
|
-
input: infer I;
|
|
29
|
-
} ? {
|
|
30
|
-
body: I;
|
|
31
|
-
} : {
|
|
32
|
-
body?: never;
|
|
33
|
-
} : SilgiRouterTypes[FindMatchingRoute<R & string>][M & keyof SilgiRouterTypes[FindMatchingRoute<R & string>]] extends {
|
|
34
|
-
input: infer I;
|
|
35
|
-
} ? {
|
|
36
|
-
body: I;
|
|
37
|
-
} : {
|
|
38
|
-
body?: never;
|
|
39
|
-
};
|
|
40
|
-
type ExtractParams<T extends string> = T extends `${string}:${infer Param}/${infer Rest}` ? {
|
|
17
|
+
type TrimAfterFourSlashes<T extends string> = T extends `/${infer S1}/${infer S2}/${infer S3}/${infer _}` ? `/${S1}/${S2}/${S3}` : T;
|
|
18
|
+
type AllPaths = SilgiRouterTypes extends {
|
|
19
|
+
keys: infer U;
|
|
20
|
+
} ? keyof U extends never ? string : keyof U : string;
|
|
21
|
+
type ExtractPathParams<T extends string> = T extends `${infer _Start}:${infer Param}/${infer Rest}` ? {
|
|
41
22
|
[K in Param]: string;
|
|
42
|
-
} &
|
|
23
|
+
} & ExtractPathParams<Rest> : T extends `${infer _Start}:${infer Param}` ? {
|
|
43
24
|
[K in Param]: string;
|
|
44
25
|
} : object;
|
|
45
|
-
type
|
|
46
|
-
|
|
26
|
+
type ValidRoute = AllPaths | (string & {});
|
|
27
|
+
type Method<R extends ValidRoute> = TrimAfterFourSlashes<R> extends keyof SilgiRouterTypes ? keyof SilgiRouterTypes[TrimAfterFourSlashes<R>] : never;
|
|
28
|
+
type FetchResponseData<R extends ValidRoute, M extends Method<R>> = TrimAfterFourSlashes<R> extends keyof SilgiRouterTypes ? SilgiRouterTypes[TrimAfterFourSlashes<R>][M]['output'] : never;
|
|
29
|
+
type RequestBodyOption<R extends ValidRoute, M extends Method<R>> = TrimAfterFourSlashes<R> extends keyof SilgiRouterTypes ? SilgiRouterTypes[TrimAfterFourSlashes<R>][M] extends {
|
|
30
|
+
input: infer I;
|
|
47
31
|
} ? {
|
|
48
|
-
|
|
49
|
-
} : R extends `${string}:${string}` ? {
|
|
50
|
-
params: ExtractParams<R>;
|
|
51
|
-
} : {
|
|
52
|
-
params?: never;
|
|
32
|
+
body: I;
|
|
53
33
|
} : {
|
|
54
|
-
|
|
55
|
-
};
|
|
34
|
+
body?: never;
|
|
35
|
+
} : never;
|
|
36
|
+
type RouterParams<R extends ValidRoute> = ExtractPathParams<R>;
|
|
56
37
|
type SilgiFetchOptions<R extends ValidRoute, M extends Method<R>> = {
|
|
57
38
|
method: M;
|
|
58
|
-
} & RequestBodyOption<R, M> & RouterParams<R
|
|
59
|
-
|
|
39
|
+
} & RequestBodyOption<R, M> & (RouterParams<R> extends object ? {
|
|
40
|
+
params: RouterParams<R>;
|
|
41
|
+
} : {
|
|
42
|
+
params?: never;
|
|
43
|
+
}) & Omit<FetchOptions, 'query' | 'body' | 'method'>;
|
|
44
|
+
type SilgiFetchClient = <R extends ValidRoute, M extends Method<R> = 'get' extends Method<R> ? 'get' : Method<R>>(url: R, options: SilgiFetchOptions<R, M>) => Promise<FetchResponseData<R, M>>;
|
|
60
45
|
declare function createSilgiFetch(options: FetchOptions | ((options: FetchOptions) => FetchOptions), localFetch?: typeof globalThis.$fetch): SilgiFetchClient;
|
|
61
46
|
|
|
62
47
|
interface Options {
|
package/dist/core/index.mjs
CHANGED
|
@@ -1124,12 +1124,14 @@ async function createSilgi(config) {
|
|
|
1124
1124
|
}
|
|
1125
1125
|
|
|
1126
1126
|
function createSilgiFetch(options, localFetch) {
|
|
1127
|
-
return (url, opts
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
opts
|
|
1131
|
-
|
|
1132
|
-
|
|
1127
|
+
return (url, opts) => {
|
|
1128
|
+
const finalOpts = {
|
|
1129
|
+
...typeof options === "function" ? options(opts) : options,
|
|
1130
|
+
...opts,
|
|
1131
|
+
method: opts.method || "get"
|
|
1132
|
+
};
|
|
1133
|
+
const $fetch = getFetch(url, finalOpts, localFetch);
|
|
1134
|
+
return $fetch(fillPath(url, opts.params), finalOpts);
|
|
1133
1135
|
};
|
|
1134
1136
|
}
|
|
1135
1137
|
function getFetch(url, opts, localFetch) {
|
|
@@ -20,7 +20,7 @@ const module = defineNuxtModule({
|
|
|
20
20
|
nuxt.options.nitro.modules ||= [];
|
|
21
21
|
nuxt.options.nitro.modules.push(await resolvePath("silgi/ecosystem/nitro"));
|
|
22
22
|
nuxt.hook("prepare:types", ({ references }) => {
|
|
23
|
-
references.push({ path: relativeWithDot(nuxt.options.buildDir, join(silgi.build.
|
|
23
|
+
references.push({ path: relativeWithDot(nuxt.options.buildDir, join(silgi.build.typesDir, "silgi.d.ts")) });
|
|
24
24
|
});
|
|
25
25
|
nuxt.options.imports.presets.push({
|
|
26
26
|
from: "silgi/types",
|
package/dist/meta/index.d.mts
CHANGED
package/dist/meta/index.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import type { AvailableRouterMethod } from 'nitropack';
|
|
2
1
|
import type { FetchError } from 'ofetch';
|
|
3
2
|
import type { SilgiRouterTypes } from 'silgi/types';
|
|
4
|
-
import { type AsyncData
|
|
5
|
-
type
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
3
|
+
import { type AsyncData } from 'nuxt/app';
|
|
4
|
+
type TrimAfterFourSlashes<T extends string> = T extends `/${infer S1}/${infer S2}/${infer S3}/${infer _}` ? `/${S1}/${S2}/${S3}` : T;
|
|
5
|
+
type AllPaths = SilgiRouterTypes extends {
|
|
6
|
+
keys: infer U;
|
|
7
|
+
} ? keyof U extends never ? string : keyof U : string;
|
|
8
|
+
type ExtractPathParams<T extends string> = T extends `${infer _Start}:${infer Param}/${infer Rest}` ? {
|
|
9
|
+
[K in Param]: string;
|
|
10
|
+
} & ExtractPathParams<Rest> : T extends `${infer _Start}:${infer Param}` ? {
|
|
11
|
+
[K in Param]: string;
|
|
12
|
+
} : unknown;
|
|
13
|
+
export declare function useSilgiFetch<P extends AllPaths | (string & {}), BasePath extends keyof SilgiRouterTypes = TrimAfterFourSlashes<P> extends keyof SilgiRouterTypes ? TrimAfterFourSlashes<P> : never, M extends keyof SilgiRouterTypes[BasePath] = keyof SilgiRouterTypes[BasePath]>(path: P, options?: {
|
|
14
|
+
method?: M;
|
|
15
|
+
params?: ExtractPathParams<P>;
|
|
16
|
+
body?: SilgiRouterTypes[BasePath][M]['input'];
|
|
17
|
+
}): AsyncData<SilgiRouterTypes[BasePath][M]["output"], FetchError | null>;
|
|
18
18
|
export {};
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { useFetch } from "nuxt/app";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
function replacePathParams(template, params) {
|
|
3
|
+
return template.replace(/:([^/]+)/g, (_, param) => params[param] || `:${param}`);
|
|
4
|
+
}
|
|
5
|
+
export function useSilgiFetch(path, options) {
|
|
6
|
+
const resolvedPath = options?.params ? replacePathParams(path, options.params) : path;
|
|
7
|
+
return useFetch(resolvedPath, {
|
|
8
|
+
method: options?.method,
|
|
9
|
+
body: options?.body
|
|
7
10
|
});
|
|
8
11
|
}
|