silgi 0.16.5 → 0.16.6
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 +76 -32
- package/dist/kit/index.mjs +8 -2
- package/dist/meta/index.d.mts +1 -1
- package/dist/meta/index.d.ts +1 -1
- package/dist/types/index.d.mts +2 -1
- package/dist/types/index.d.ts +2 -1
- package/package.json +1 -1
package/dist/_chunks/index.mjs
CHANGED
package/dist/cli/prepare.mjs
CHANGED
|
@@ -40,46 +40,90 @@ import 'pathe/utils';
|
|
|
40
40
|
import 'untyped';
|
|
41
41
|
import './types.mjs';
|
|
42
42
|
|
|
43
|
-
function
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
${
|
|
59
|
-
|
|
43
|
+
function serializeRules(rules, options = {}) {
|
|
44
|
+
try {
|
|
45
|
+
const config = {
|
|
46
|
+
indent: 2,
|
|
47
|
+
functionIndent: 2,
|
|
48
|
+
// Daha tutarlı indentasyon için değiştirildi
|
|
49
|
+
...options
|
|
50
|
+
};
|
|
51
|
+
const uniqueId = Date.now().toString(36) + Math.random().toString(36).substring(2, 7);
|
|
52
|
+
const FUNCTION_MARKER = `__SILGI_FUNCTION_${uniqueId}_`;
|
|
53
|
+
const FUNCTION_MARKER_END = `_FUNCTION_END_${uniqueId}__`;
|
|
54
|
+
const safeStringify = (obj) => {
|
|
55
|
+
const cache = [];
|
|
56
|
+
const serialized2 = JSON.stringify(obj, (key, value) => {
|
|
57
|
+
if (typeof value === "function") {
|
|
58
|
+
return `${FUNCTION_MARKER}${value.toString()}${FUNCTION_MARKER_END}`;
|
|
59
|
+
}
|
|
60
|
+
if (typeof value === "object" && value !== null) {
|
|
61
|
+
if (cache.includes(value)) {
|
|
62
|
+
return "[Circular Reference]";
|
|
63
|
+
}
|
|
64
|
+
cache.push(value);
|
|
65
|
+
}
|
|
66
|
+
return value;
|
|
67
|
+
}, config.indent);
|
|
68
|
+
return serialized2;
|
|
69
|
+
};
|
|
70
|
+
const serialized = safeStringify(rules);
|
|
71
|
+
const getIndentLevel = (matchIndex) => {
|
|
72
|
+
const beforeMatch = serialized.substring(0, matchIndex);
|
|
73
|
+
const lastNewline = beforeMatch.lastIndexOf("\n");
|
|
74
|
+
if (lastNewline === -1)
|
|
75
|
+
return 0;
|
|
76
|
+
const lineStart = beforeMatch.substring(lastNewline + 1);
|
|
77
|
+
return lineStart.match(/^\s*/)?.[0].length ?? 0;
|
|
78
|
+
};
|
|
79
|
+
const result = serialized.replace(
|
|
80
|
+
new RegExp(`"${FUNCTION_MARKER}(.*?)${FUNCTION_MARKER_END}"`, "gs"),
|
|
81
|
+
(match, fnContent, offset) => {
|
|
82
|
+
const baseIndent = getIndentLevel(offset);
|
|
83
|
+
const functionBodyIndent = " ".repeat(baseIndent + config.functionIndent);
|
|
84
|
+
return fnContent.replace(/\\n/g, "\n").replace(/\\"/g, '"').replace(/\\\\/g, "\\").split("\n").map((line, i) => {
|
|
85
|
+
if (i === 0)
|
|
86
|
+
return line;
|
|
87
|
+
const trimmedLine = line.trimStart();
|
|
88
|
+
return trimmedLine ? `${functionBodyIndent}${trimmedLine}` : "";
|
|
89
|
+
}).filter(Boolean).join("\n");
|
|
90
|
+
}
|
|
91
|
+
);
|
|
92
|
+
return result;
|
|
93
|
+
} catch (error) {
|
|
94
|
+
console.error("Error serializing rules:", error);
|
|
95
|
+
return JSON.stringify(rules, null, 2);
|
|
60
96
|
}
|
|
61
|
-
const entries = Object.entries(obj);
|
|
62
|
-
if (entries.length === 0)
|
|
63
|
-
return "{}";
|
|
64
|
-
const props = entries.map(
|
|
65
|
-
([key, value]) => `${innerSpacing}"${key}": ${serializeToString(value, indent + 4)}`
|
|
66
|
-
);
|
|
67
|
-
return `{
|
|
68
|
-
${props.join(",\n")}
|
|
69
|
-
${spacing}}`;
|
|
70
97
|
}
|
|
71
98
|
async function prepareBuild(silgi) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
99
|
+
try {
|
|
100
|
+
if (!silgi?.routeRules?.exportRules) {
|
|
101
|
+
throw new Error("Invalid silgi configuration: routeRules or exportRules is undefined");
|
|
102
|
+
}
|
|
103
|
+
const exportedRules = silgi.routeRules.exportRules();
|
|
104
|
+
if (!exportedRules || typeof exportedRules !== "object") {
|
|
105
|
+
throw new Error("No valid route rules to export");
|
|
106
|
+
}
|
|
107
|
+
const serialized = serializeRules(exportedRules);
|
|
108
|
+
const content = `/* eslint-disable */
|
|
75
109
|
// @ts-nocheck
|
|
76
|
-
// This file is auto-generated at build time
|
|
110
|
+
// This file is auto-generated at build time by Silgi
|
|
77
111
|
// Contains route rules with preserved functions
|
|
112
|
+
// Generated: ${(/* @__PURE__ */ new Date()).toISOString()}
|
|
78
113
|
|
|
79
114
|
export const routeRules = ${serialized}
|
|
80
115
|
`;
|
|
81
|
-
|
|
82
|
-
|
|
116
|
+
const serverDir = silgi.options.silgi.serverDir;
|
|
117
|
+
if (!serverDir) {
|
|
118
|
+
throw new Error("Server directory not defined in configuration");
|
|
119
|
+
}
|
|
120
|
+
const file = join(serverDir, "rules.ts");
|
|
121
|
+
await writeFile(file, content);
|
|
122
|
+
console.log(`\u2705 Route rules written to ${file}`);
|
|
123
|
+
} catch (error) {
|
|
124
|
+
console.error("\u274C Failed to prepare build:", error instanceof Error ? error.message : String(error));
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
83
127
|
}
|
|
84
128
|
|
|
85
129
|
const prepare = defineCommand({
|
package/dist/kit/index.mjs
CHANGED
|
@@ -201,13 +201,19 @@ const parseGraphQLServices = serviceParseModule(({
|
|
|
201
201
|
const parseRouteRules = serviceParseModule(({
|
|
202
202
|
node,
|
|
203
203
|
basePath,
|
|
204
|
-
silgi
|
|
204
|
+
silgi,
|
|
205
|
+
pathLength
|
|
205
206
|
}) => {
|
|
206
207
|
const routeRules = node.routeRules;
|
|
207
208
|
if (!routeRules)
|
|
208
209
|
return;
|
|
209
210
|
let removeMethod = "";
|
|
210
211
|
removeMethod = withLeadingSlash(basePath);
|
|
212
|
+
if (pathLength === 1 || pathLength === 2 || pathLength === 3) {
|
|
213
|
+
if (routeRules.doubleSplat === void 0) {
|
|
214
|
+
routeRules.doubleSplat = true;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
211
217
|
if (routeRules.splat)
|
|
212
218
|
removeMethod = `${removeMethod}/*`;
|
|
213
219
|
else if (routeRules.doubleSplat)
|
|
@@ -228,7 +234,7 @@ function parseServices(silgi, pathLength = [4, 3, 2, 1], servicesObject, current
|
|
|
228
234
|
if (pathLengths.includes(path.length)) {
|
|
229
235
|
const basePath = path.join("/");
|
|
230
236
|
for (const handler of silgi.options.serviceParseModules) {
|
|
231
|
-
handler({ node, basePath, silgi, modulesURIs });
|
|
237
|
+
handler({ node, basePath, silgi, modulesURIs, pathLength: path.length });
|
|
232
238
|
}
|
|
233
239
|
}
|
|
234
240
|
for (const key in node) {
|
package/dist/meta/index.d.mts
CHANGED
package/dist/meta/index.d.ts
CHANGED
package/dist/types/index.d.mts
CHANGED
|
@@ -826,7 +826,7 @@ interface SilgiRuntimeRouteRulesConfig {
|
|
|
826
826
|
/**
|
|
827
827
|
* Interface for the object returned by createRouteRules
|
|
828
828
|
*/
|
|
829
|
-
interface RouteRules
|
|
829
|
+
interface RouteRules {
|
|
830
830
|
readonly rules: Record<string, DefaultRouteConfig>;
|
|
831
831
|
readonly mergedRules: Record<string, DefaultRouteConfig>;
|
|
832
832
|
importRules: (config: Record<string, DefaultRouteConfig>) => void;
|
|
@@ -1122,6 +1122,7 @@ interface ServiceParse {
|
|
|
1122
1122
|
basePath: string;
|
|
1123
1123
|
silgi: SilgiCLI;
|
|
1124
1124
|
modulesURIs: Record<string, Record<string, any>>;
|
|
1125
|
+
pathLength: number;
|
|
1125
1126
|
}
|
|
1126
1127
|
interface ServiceParseModule {
|
|
1127
1128
|
(params: ServiceParse): Awaited<void> | void;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -826,7 +826,7 @@ interface SilgiRuntimeRouteRulesConfig {
|
|
|
826
826
|
/**
|
|
827
827
|
* Interface for the object returned by createRouteRules
|
|
828
828
|
*/
|
|
829
|
-
interface RouteRules
|
|
829
|
+
interface RouteRules {
|
|
830
830
|
readonly rules: Record<string, DefaultRouteConfig>;
|
|
831
831
|
readonly mergedRules: Record<string, DefaultRouteConfig>;
|
|
832
832
|
importRules: (config: Record<string, DefaultRouteConfig>) => void;
|
|
@@ -1122,6 +1122,7 @@ interface ServiceParse {
|
|
|
1122
1122
|
basePath: string;
|
|
1123
1123
|
silgi: SilgiCLI;
|
|
1124
1124
|
modulesURIs: Record<string, Record<string, any>>;
|
|
1125
|
+
pathLength: number;
|
|
1125
1126
|
}
|
|
1126
1127
|
interface ServiceParseModule {
|
|
1127
1128
|
(params: ServiceParse): Awaited<void> | void;
|