silgi 0.16.5 → 0.17.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.
@@ -1,9 +1,9 @@
1
- const version = "0.16.5";
1
+ const version = "0.17.0";
2
2
  const peerDependencies = {
3
3
  "@fastify/deepmerge": "^2.0.2",
4
4
  "@nuxt/kit": "^3.15.3",
5
5
  "@nuxt/schema": "^3.15.4",
6
- "@silgi/ecosystem": "^0.0.10",
6
+ "@silgi/ecosystem": "^0.2.0",
7
7
  h3: "^1.14.0",
8
8
  nitropack: "^2.10.4",
9
9
  nuxt: "^3.15.3",
@@ -51,6 +51,7 @@ const devDependencies = {
51
51
  "@antfu/eslint-config": "catalog:",
52
52
  "@nuxt/kit": "catalog:",
53
53
  "@nuxt/schema": "catalog:",
54
+ "@silgi/ecosystem": "catalog:",
54
55
  "@types/node": "catalog:",
55
56
  "@types/semver": "catalog:",
56
57
  "@vitest/coverage-v8": "catalog:",
@@ -40,46 +40,90 @@ import 'pathe/utils';
40
40
  import 'untyped';
41
41
  import './types.mjs';
42
42
 
43
- function serializeToString(obj, indent = 0) {
44
- const spacing = " ".repeat(indent);
45
- const innerSpacing = " ".repeat(indent + 4);
46
- if (obj === null || obj === void 0)
47
- return "null";
48
- if (typeof obj === "function")
49
- return obj.toString();
50
- if (typeof obj !== "object")
51
- return JSON.stringify(obj);
52
- if (Array.isArray(obj)) {
53
- if (obj.length === 0)
54
- return "[]";
55
- const items = obj.map((item) => serializeToString(item, indent + 4));
56
- return `[
57
- ${innerSpacing}${items.join(`,
58
- ${innerSpacing}`)}
59
- ${spacing}]`;
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
- const exportedRules = silgi.routeRules.exportRules();
73
- const serialized = serializeToString(exportedRules);
74
- const content = `/* eslint-disable */
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
- const file = join(silgi.options.silgi.serverDir, "rules.ts");
82
- await writeFile(file, content);
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({
@@ -21,7 +21,7 @@ import ignore from 'ignore';
21
21
  import { parseSync } from '@oxc-parser/wasm';
22
22
  import { klona } from 'klona';
23
23
  import { createStorage, builtinDrivers } from 'unstorage';
24
- import { peerDependencies } from 'silgi/meta';
24
+ import { devDependencies, dependencies } from 'silgi/meta';
25
25
  import { l as loadOptions } from './loader.mjs';
26
26
  import { resolveAlias as resolveAlias$1 } from 'pathe/utils';
27
27
  import { generateTypes, resolveSchema } from 'untyped';
@@ -1338,8 +1338,8 @@ async function commands(silgi) {
1338
1338
  async function installPackages(silgi) {
1339
1339
  const packages = {
1340
1340
  dependencies: {
1341
- "@fastify/deepmerge": peerDependencies["@fastify/deepmerge"],
1342
- "@silgi/ecosystem": peerDependencies["@silgi/ecosystem"],
1341
+ "@fastify/deepmerge": dependencies["@fastify/deepmerge"],
1342
+ "@silgi/ecosystem": devDependencies["@silgi/ecosystem"],
1343
1343
  ...silgi.options.installPackages?.dependencies
1344
1344
  },
1345
1345
  devDependencies: {
@@ -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) {
@@ -1,9 +1,9 @@
1
- const version = "0.16.5";
1
+ const version = "0.17.0";
2
2
  const peerDependencies = {
3
3
  "@fastify/deepmerge": "^2.0.2",
4
4
  "@nuxt/kit": "^3.15.3",
5
5
  "@nuxt/schema": "^3.15.4",
6
- "@silgi/ecosystem": "^0.0.10",
6
+ "@silgi/ecosystem": "^0.2.0",
7
7
  h3: "^1.14.0",
8
8
  nitropack: "^2.10.4",
9
9
  nuxt: "^3.15.3",
@@ -51,6 +51,7 @@ const devDependencies = {
51
51
  "@antfu/eslint-config": "catalog:",
52
52
  "@nuxt/kit": "catalog:",
53
53
  "@nuxt/schema": "catalog:",
54
+ "@silgi/ecosystem": "catalog:",
54
55
  "@types/node": "catalog:",
55
56
  "@types/semver": "catalog:",
56
57
  "@vitest/coverage-v8": "catalog:",
@@ -1,9 +1,9 @@
1
- const version = "0.16.5";
1
+ const version = "0.17.0";
2
2
  const peerDependencies = {
3
3
  "@fastify/deepmerge": "^2.0.2",
4
4
  "@nuxt/kit": "^3.15.3",
5
5
  "@nuxt/schema": "^3.15.4",
6
- "@silgi/ecosystem": "^0.0.10",
6
+ "@silgi/ecosystem": "^0.2.0",
7
7
  h3: "^1.14.0",
8
8
  nitropack: "^2.10.4",
9
9
  nuxt: "^3.15.3",
@@ -51,6 +51,7 @@ const devDependencies = {
51
51
  "@antfu/eslint-config": "catalog:",
52
52
  "@nuxt/kit": "catalog:",
53
53
  "@nuxt/schema": "catalog:",
54
+ "@silgi/ecosystem": "catalog:",
54
55
  "@types/node": "catalog:",
55
56
  "@types/semver": "catalog:",
56
57
  "@vitest/coverage-v8": "catalog:",
@@ -826,7 +826,7 @@ interface SilgiRuntimeRouteRulesConfig {
826
826
  /**
827
827
  * Interface for the object returned by createRouteRules
828
828
  */
829
- interface RouteRules<T extends Record<string, any> = DefaultRouteRules> {
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;
@@ -826,7 +826,7 @@ interface SilgiRuntimeRouteRulesConfig {
826
826
  /**
827
827
  * Interface for the object returned by createRouteRules
828
828
  */
829
- interface RouteRules<T extends Record<string, any> = DefaultRouteRules> {
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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.16.5",
4
+ "version": "0.17.0",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {
@@ -79,7 +79,7 @@
79
79
  "@fastify/deepmerge": "^2.0.2",
80
80
  "@nuxt/kit": "^3.15.3",
81
81
  "@nuxt/schema": "^3.15.4",
82
- "@silgi/ecosystem": "^0.0.10",
82
+ "@silgi/ecosystem": "^0.2.0",
83
83
  "h3": "^1.14.0",
84
84
  "nitropack": "^2.10.4",
85
85
  "nuxt": "^3.15.3",
@@ -113,7 +113,7 @@
113
113
  "dependencies": {
114
114
  "@clack/prompts": "^0.10.0",
115
115
  "@fastify/deepmerge": "^2.0.2",
116
- "@oxc-parser/wasm": "^0.56.0",
116
+ "@oxc-parser/wasm": "^0.56.5",
117
117
  "@standard-schema/spec": "^1.0.0",
118
118
  "c12": "^3.0.2",
119
119
  "chokidar": "^4.0.3",
@@ -147,16 +147,17 @@
147
147
  "untyped": "^2.0.0"
148
148
  },
149
149
  "devDependencies": {
150
- "@antfu/eslint-config": "^4.6.0",
151
- "@nuxt/kit": "^3.15.4",
152
- "@nuxt/schema": "^3.15.4",
153
- "@types/node": "^22.13.9",
150
+ "@antfu/eslint-config": "^4.8.1",
151
+ "@nuxt/kit": "^3.16.0",
152
+ "@nuxt/schema": "^3.16.0",
153
+ "@silgi/ecosystem": "^0.2.0",
154
+ "@types/node": "^22.13.10",
154
155
  "@types/semver": "^7.5.8",
155
156
  "@vitest/coverage-v8": "3.0.5",
156
- "eslint": "^9.21.0",
157
+ "eslint": "^9.22.0",
157
158
  "h3": "^1.15.1",
158
- "nitropack": "^2.11.4",
159
- "nuxt": "^3.15.4",
159
+ "nitropack": "^2.11.6",
160
+ "nuxt": "^3.16.0",
160
161
  "typescript": "^5.8.2",
161
162
  "unbuild": "^3.5.0",
162
163
  "vitest": "^3.0.8",