silgi 0.8.36 → 0.8.38
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
CHANGED
package/dist/cli/prepare.mjs
CHANGED
|
@@ -1052,13 +1052,11 @@ async function scanModules$1(silgi) {
|
|
|
1052
1052
|
function createDependencyGraph(modules) {
|
|
1053
1053
|
const graph = /* @__PURE__ */ new Map();
|
|
1054
1054
|
const inDegree = /* @__PURE__ */ new Map();
|
|
1055
|
-
const dependencyRelations = /* @__PURE__ */ new Map();
|
|
1056
1055
|
modules.forEach((module) => {
|
|
1057
1056
|
const key = module.meta?.configKey;
|
|
1058
1057
|
if (key) {
|
|
1059
1058
|
graph.set(key, /* @__PURE__ */ new Set());
|
|
1060
1059
|
inDegree.set(key, 0);
|
|
1061
|
-
dependencyRelations.set(key, { required: [], before: [], after: [] });
|
|
1062
1060
|
logger$1.debug(`Module registered: ${key}`);
|
|
1063
1061
|
}
|
|
1064
1062
|
});
|
|
@@ -1067,65 +1065,29 @@ function createDependencyGraph(modules) {
|
|
|
1067
1065
|
if (!key)
|
|
1068
1066
|
return;
|
|
1069
1067
|
const requiredDeps = module.meta?.requiredDependencies || [];
|
|
1070
|
-
const beforeDeps = module.meta?.beforeDependencies || [];
|
|
1071
|
-
const afterDeps = module.meta?.afterDependencies || [];
|
|
1072
|
-
const missingRequired = requiredDeps.filter((dep) => !graph.has(dep));
|
|
1073
|
-
if (missingRequired.length > 0) {
|
|
1074
|
-
throw new Error(`Module ${key} is missing required dependencies: ${missingRequired.join(", ")}`);
|
|
1075
|
-
}
|
|
1076
|
-
const allDeps = /* @__PURE__ */ new Set([...requiredDeps, ...beforeDeps, ...afterDeps]);
|
|
1077
|
-
if (allDeps.size < requiredDeps.length + beforeDeps.length + afterDeps.length) {
|
|
1078
|
-
logger$1.error(`Module ${key} has overlapping dependencies`);
|
|
1079
|
-
return;
|
|
1080
|
-
}
|
|
1081
|
-
logger$1.debug(`
|
|
1082
|
-
Module ${key} dependencies:`);
|
|
1083
|
-
if (requiredDeps.length)
|
|
1084
|
-
logger$1.debug(` Required: ${requiredDeps.join(", ")}`);
|
|
1085
|
-
if (beforeDeps.length)
|
|
1086
|
-
logger$1.debug(` Must run after: ${beforeDeps.join(", ")}`);
|
|
1087
|
-
if (afterDeps.length)
|
|
1088
|
-
logger$1.debug(` Must run before: ${afterDeps.join(", ")}`);
|
|
1089
|
-
});
|
|
1090
|
-
modules.forEach((module) => {
|
|
1091
|
-
const key = module.meta?.configKey;
|
|
1092
|
-
if (!key)
|
|
1093
|
-
return;
|
|
1094
|
-
const requiredDeps = module.meta?.requiredDependencies || [];
|
|
1095
|
-
const beforeDeps = module.meta?.beforeDependencies || [];
|
|
1096
1068
|
const afterDeps = module.meta?.afterDependencies || [];
|
|
1097
1069
|
requiredDeps.forEach((dep) => {
|
|
1098
1070
|
if (!graph.has(dep)) {
|
|
1099
1071
|
throw new Error(`Required dependency "${dep}" for module "${key}" is missing`);
|
|
1100
1072
|
}
|
|
1101
|
-
graph.get(
|
|
1073
|
+
graph.get(key)?.add(dep);
|
|
1102
1074
|
inDegree.set(key, (inDegree.get(key) || 0) + 1);
|
|
1103
1075
|
logger$1.debug(`${key} requires ${dep}`);
|
|
1104
1076
|
});
|
|
1105
|
-
beforeDeps.forEach((dep) => {
|
|
1106
|
-
if (!graph.has(dep)) {
|
|
1107
|
-
logger$1.debug(`Optional dependency for ${key}: "${dep}" (beforeDependencies) not found, skipping`);
|
|
1108
|
-
return;
|
|
1109
|
-
}
|
|
1110
|
-
graph.get(dep)?.add(key);
|
|
1111
|
-
inDegree.set(key, (inDegree.get(key) || 0) + 1);
|
|
1112
|
-
logger$1.debug(`${key} will run after ${dep}`);
|
|
1113
|
-
});
|
|
1114
1077
|
afterDeps.forEach((dep) => {
|
|
1115
1078
|
if (!graph.has(dep)) {
|
|
1116
1079
|
logger$1.debug(`Optional dependency for ${key}: "${dep}" (afterDependencies) not found, skipping`);
|
|
1117
1080
|
return;
|
|
1118
1081
|
}
|
|
1119
1082
|
graph.get(key)?.add(dep);
|
|
1120
|
-
inDegree.set(
|
|
1121
|
-
logger$1.debug(`${key} will run
|
|
1083
|
+
inDegree.set(key, (inDegree.get(key) || 0) + 1);
|
|
1084
|
+
logger$1.debug(`${key} will run after ${dep}`);
|
|
1122
1085
|
});
|
|
1123
1086
|
});
|
|
1124
1087
|
logger$1.debug("\nDependency Graph:");
|
|
1125
1088
|
for (const [module, deps] of graph.entries()) {
|
|
1126
1089
|
const depsStr = Array.from(deps).join(", ");
|
|
1127
|
-
|
|
1128
|
-
logger$1.debug(`${module} -> [${depsStr}] (required: ${required.join(", ")}) (in-degree: ${inDegree.get(module)})`);
|
|
1090
|
+
logger$1.debug(`${module} -> [${depsStr}] (in-degree: ${inDegree.get(module)})`);
|
|
1129
1091
|
}
|
|
1130
1092
|
return { graph, inDegree };
|
|
1131
1093
|
}
|
package/dist/meta/index.d.mts
CHANGED
package/dist/meta/index.d.ts
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { FetchContext, FetchOptions } from 'ofetch';
|
|
2
|
+
import type { SilgiRouterTypes } from 'silgi/types';
|
|
3
|
+
type TrimAfterFourSlashes<T extends string> = T extends `/${infer S1}/${infer S2}/${infer S3}/${infer S4}/${infer _}` ? `/${S1}/${S2}/${S3}/${S4}` : T;
|
|
4
|
+
type AllPaths = SilgiRouterTypes extends {
|
|
5
|
+
keys: infer U;
|
|
6
|
+
} ? keyof U extends never ? string : keyof U : string;
|
|
7
|
+
type ExtractPathParams<T extends string> = T extends `${infer _Start}:${infer Param}/${infer Rest}` ? {
|
|
8
|
+
[K in Param]: string;
|
|
9
|
+
} & ExtractPathParams<Rest> : T extends `${infer _Start}:${infer Param}` ? {
|
|
10
|
+
[K in Param]: string;
|
|
11
|
+
} : object;
|
|
12
|
+
type ValidRoute = AllPaths | (string & {});
|
|
13
|
+
type Method<R extends ValidRoute> = TrimAfterFourSlashes<R> extends keyof SilgiRouterTypes ? keyof SilgiRouterTypes[TrimAfterFourSlashes<R>] : never;
|
|
14
|
+
export type FetchResponseData<R extends ValidRoute, M extends Method<R>> = TrimAfterFourSlashes<R> extends keyof SilgiRouterTypes ? SilgiRouterTypes[TrimAfterFourSlashes<R>][M]['output'] : never;
|
|
15
|
+
export type RequestBodyOption<R extends ValidRoute, M extends Method<R>> = TrimAfterFourSlashes<R> extends keyof SilgiRouterTypes ? SilgiRouterTypes[TrimAfterFourSlashes<R>][M] extends {
|
|
16
|
+
input: infer I;
|
|
17
|
+
} ? {
|
|
18
|
+
body: I;
|
|
19
|
+
} : {
|
|
20
|
+
body?: never;
|
|
21
|
+
} : never;
|
|
22
|
+
export type RouterParams<R extends ValidRoute> = ExtractPathParams<R>;
|
|
23
|
+
type SilgiFetchOptions<R extends ValidRoute, M extends Method<R>> = {
|
|
24
|
+
method: M;
|
|
25
|
+
} & RequestBodyOption<R, M> & (RouterParams<R> extends object ? {
|
|
26
|
+
params?: RouterParams<R>;
|
|
27
|
+
} : {
|
|
28
|
+
params?: never;
|
|
29
|
+
}) & Omit<FetchOptions, 'query' | 'body' | 'method'>;
|
|
30
|
+
export 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>>;
|
|
31
|
+
export declare function silgiFetchRequestInterceptor(ctx: FetchContext): void;
|
|
32
|
+
export declare function createSilgiFetch(options: FetchOptions | ((options: FetchOptions) => FetchOptions), localFetch?: typeof globalThis.$fetch): SilgiFetchClient;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export function silgiFetchRequestInterceptor(ctx) {
|
|
2
|
+
ctx.request = fillPath(ctx.request, ctx.options.path);
|
|
3
|
+
}
|
|
4
|
+
export function createSilgiFetch(options, localFetch) {
|
|
5
|
+
return (url, opts) => {
|
|
6
|
+
const finalOpts = {
|
|
7
|
+
...typeof options === "function" ? options(opts) : options,
|
|
8
|
+
...opts,
|
|
9
|
+
method: opts.method || "get"
|
|
10
|
+
};
|
|
11
|
+
const $fetch = getFetch(url, finalOpts, localFetch);
|
|
12
|
+
return $fetch(fillPath(url, opts.params), finalOpts);
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function getFetch(url, opts, localFetch) {
|
|
16
|
+
if (import.meta.server && localFetch) {
|
|
17
|
+
const isLocalFetch = url[0] === "/" && (!opts.baseURL || opts.baseURL[0] === "/");
|
|
18
|
+
if (isLocalFetch)
|
|
19
|
+
return localFetch;
|
|
20
|
+
}
|
|
21
|
+
return globalThis.$fetch;
|
|
22
|
+
}
|
|
23
|
+
function fillPath(path, params) {
|
|
24
|
+
if (!params) {
|
|
25
|
+
if (path.includes(":"))
|
|
26
|
+
throw new Error("Parametreler dogru kullanmal\u0131s\u0131n\u0131z");
|
|
27
|
+
return path;
|
|
28
|
+
}
|
|
29
|
+
if (!path.includes(":"))
|
|
30
|
+
throw new Error("Path parametler : ile belirtilmelidir");
|
|
31
|
+
let result = path;
|
|
32
|
+
for (const [key, value] of Object.entries(params)) {
|
|
33
|
+
result = result.replace(`:${key}`, value);
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
}
|