silgi 0.42.4 → 0.43.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.
Files changed (266) hide show
  1. package/dist/_virtual/rolldown_runtime.mjs +11 -0
  2. package/dist/build.d.mts +3 -11
  3. package/dist/build.mjs +4 -48
  4. package/dist/cli/build/build.mjs +17 -0
  5. package/dist/cli/build/dev.d.mts +9 -0
  6. package/dist/cli/build/dev.mjs +59 -0
  7. package/dist/cli/build/prepare.d.mts +6 -0
  8. package/dist/cli/build/prepare.mjs +15 -0
  9. package/dist/cli/commands/commands.mjs +90 -0
  10. package/dist/cli/commands/env.mjs +53 -0
  11. package/dist/cli/commands/init.mjs +84 -0
  12. package/dist/cli/commands/install.mjs +52 -0
  13. package/dist/cli/commands/prepare.mjs +65 -0
  14. package/dist/cli/commands/reset.mjs +46 -0
  15. package/dist/cli/commands/run.mjs +105 -0
  16. package/dist/cli/commands/watch.mjs +48 -0
  17. package/dist/cli/config/defaults.mjs +117 -0
  18. package/dist/cli/config/index.d.mts +3 -11
  19. package/dist/cli/config/index.mjs +4 -17
  20. package/dist/cli/config/loader.d.mts +6 -0
  21. package/dist/cli/config/loader.mjs +71 -0
  22. package/dist/cli/config/resolvers/compatibility.mjs +71 -0
  23. package/dist/cli/config/resolvers/imports.mjs +35 -0
  24. package/dist/cli/config/resolvers/paths.mjs +98 -0
  25. package/dist/cli/config/resolvers/storage.mjs +23 -0
  26. package/dist/cli/config/resolvers/url.mjs +9 -0
  27. package/dist/cli/config/types.d.mts +14 -0
  28. package/dist/cli/config/types.mjs +147 -0
  29. package/dist/cli/core/apiful.mjs +36 -0
  30. package/dist/cli/core/app.mjs +105 -0
  31. package/dist/cli/core/devServer.mjs +10 -0
  32. package/dist/cli/core/env.mjs +68 -0
  33. package/dist/cli/core/installPackage.mjs +60 -0
  34. package/dist/cli/core/runtimeConfig.mjs +70 -0
  35. package/dist/cli/core/scan.mjs +35 -0
  36. package/dist/cli/core/silgi.mjs +111 -0
  37. package/dist/cli/core/templates.mjs +38 -0
  38. package/dist/cli/framework/emptyFramework.mjs +7 -0
  39. package/dist/cli/framework/h3.mjs +55 -0
  40. package/dist/cli/framework/index.mjs +15 -0
  41. package/dist/cli/framework/nitro.mjs +24 -0
  42. package/dist/cli/framework/nuxt.mjs +10 -0
  43. package/dist/cli/index.d.mts +1 -1
  44. package/dist/cli/index.mjs +24 -27
  45. package/dist/cli/module/exportScan.mjs +180 -0
  46. package/dist/cli/module/install.mjs +49 -0
  47. package/dist/cli/module/scan.mjs +195 -0
  48. package/dist/cli/scan/prepareCommands.mjs +40 -0
  49. package/dist/cli/scan/prepareConfigs.mjs +33 -0
  50. package/dist/cli/scan/prepareCoreFile.mjs +118 -0
  51. package/dist/cli/scan/prepareScanFile.mjs +59 -0
  52. package/dist/cli/scan/prepareSchema.mjs +140 -0
  53. package/dist/cli/scan/scanExportFile.mjs +312 -0
  54. package/dist/cli/scan/writeCoreFile.mjs +22 -0
  55. package/dist/cli/scan/writeTypesAndFiles.mjs +72 -0
  56. package/dist/cli/utils/cancel.mjs +14 -0
  57. package/dist/cli/utils/common.mjs +15 -0
  58. package/dist/cli/utils/compatibility.mjs +33 -0
  59. package/dist/cli/utils/debug.mjs +11 -0
  60. package/dist/cli/utils/ignore.mjs +56 -0
  61. package/dist/cli/utils/readScanFile.mjs +58 -0
  62. package/dist/cli/utils/storage.mjs +23 -0
  63. package/dist/core/context.d.mts +30 -0
  64. package/dist/core/context.mjs +32 -0
  65. package/dist/core/createSilgi.d.mts +6 -0
  66. package/dist/core/createSilgi.mjs +152 -0
  67. package/dist/core/error.d.mts +65 -0
  68. package/dist/core/error.mjs +106 -0
  69. package/dist/core/event.d.mts +26 -0
  70. package/dist/core/event.mjs +44 -0
  71. package/dist/core/index.d.mts +24 -316
  72. package/dist/core/index.mjs +27 -1345
  73. package/dist/core/orchestrate.mjs +113 -0
  74. package/dist/core/response.d.mts +20 -0
  75. package/dist/core/response.mjs +105 -0
  76. package/dist/core/silgi.d.mts +19 -0
  77. package/dist/core/silgi.mjs +141 -0
  78. package/dist/core/silgiApp.d.mts +9 -0
  79. package/dist/core/silgiApp.mjs +23 -0
  80. package/dist/core/storage.d.mts +7 -0
  81. package/dist/core/storage.mjs +15 -0
  82. package/dist/core/unctx.d.mts +21 -0
  83. package/dist/core/unctx.mjs +35 -0
  84. package/dist/core/utils/event-stream.d.mts +53 -0
  85. package/dist/core/utils/event-stream.mjs +38 -0
  86. package/dist/core/utils/event.d.mts +8 -0
  87. package/dist/core/utils/event.mjs +12 -0
  88. package/dist/core/utils/internal/event-stream.d.mts +45 -0
  89. package/dist/core/utils/internal/event-stream.mjs +137 -0
  90. package/dist/core/utils/internal/obj.mjs +9 -0
  91. package/dist/core/utils/internal/object.mjs +29 -0
  92. package/dist/core/utils/internal/query.mjs +73 -0
  93. package/dist/core/utils/internal/req.mjs +35 -0
  94. package/dist/core/utils/merge.d.mts +14 -0
  95. package/dist/core/utils/merge.mjs +27 -0
  96. package/dist/{shared/silgi.DTwQEdSr.d.mts → core/utils/middleware.d.mts} +11 -13
  97. package/dist/core/utils/middleware.mjs +12 -0
  98. package/dist/core/utils/request.mjs +35 -0
  99. package/dist/core/utils/resolver.d.mts +7 -0
  100. package/dist/core/utils/resolver.mjs +29 -0
  101. package/dist/core/utils/runtime.d.mts +7 -0
  102. package/dist/core/utils/runtime.mjs +20 -0
  103. package/dist/core/utils/sanitize.mjs +22 -0
  104. package/dist/core/utils/schema.d.mts +34 -0
  105. package/dist/core/utils/schema.mjs +33 -0
  106. package/dist/core/utils/service.d.mts +13 -0
  107. package/dist/core/utils/service.mjs +19 -0
  108. package/dist/core/utils/shared.d.mts +6 -0
  109. package/dist/core/utils/shared.mjs +7 -0
  110. package/dist/core/utils/storage.d.mts +24 -0
  111. package/dist/core/utils/storage.mjs +54 -0
  112. package/dist/index.d.mts +21 -6
  113. package/dist/index.mjs +22 -16
  114. package/dist/kit/add/add-commands.d.mts +6 -0
  115. package/dist/kit/add/add-commands.mjs +12 -0
  116. package/dist/kit/add/add-core-file.d.mts +9 -0
  117. package/dist/kit/add/add-core-file.mjs +11 -0
  118. package/dist/kit/add/add-imports.d.mts +14 -0
  119. package/dist/kit/add/add-imports.mjs +56 -0
  120. package/dist/kit/add/add-npm.d.mts +14 -0
  121. package/dist/kit/add/add-npm.mjs +23 -0
  122. package/dist/kit/define.d.mts +28 -0
  123. package/dist/kit/define.mjs +25 -0
  124. package/dist/kit/errors.d.mts +6 -0
  125. package/dist/kit/errors.mjs +11 -0
  126. package/dist/kit/esm.d.mts +11 -0
  127. package/dist/kit/esm.mjs +21 -0
  128. package/dist/kit/fs.d.mts +7 -0
  129. package/dist/kit/fs.mjs +23 -0
  130. package/dist/kit/function-utils.d.mts +27 -0
  131. package/dist/kit/function-utils.mjs +75 -0
  132. package/dist/kit/gen.d.mts +5 -0
  133. package/dist/kit/gen.mjs +26 -0
  134. package/dist/kit/hash.d.mts +4 -0
  135. package/dist/kit/hash.mjs +10 -0
  136. package/dist/kit/index.d.mts +22 -321
  137. package/dist/kit/index.mjs +23 -1039
  138. package/dist/kit/isFramework.d.mts +6 -0
  139. package/dist/kit/isFramework.mjs +21 -0
  140. package/dist/kit/logger.d.mts +6 -0
  141. package/dist/kit/logger.mjs +10 -0
  142. package/dist/kit/migration.d.mts +113 -0
  143. package/dist/kit/migration.mjs +301 -0
  144. package/dist/kit/module.d.mts +14 -0
  145. package/dist/kit/module.mjs +53 -0
  146. package/dist/kit/path.d.mts +7 -0
  147. package/dist/kit/path.mjs +26 -0
  148. package/dist/kit/preset.d.mts +8 -0
  149. package/dist/kit/preset.mjs +11 -0
  150. package/dist/kit/resolve.d.mts +37 -0
  151. package/dist/kit/resolve.mjs +82 -0
  152. package/dist/kit/template.d.mts +14 -0
  153. package/dist/kit/template.mjs +59 -0
  154. package/dist/kit/useRequest.d.mts +19 -0
  155. package/dist/kit/useRequest.mjs +63 -0
  156. package/dist/kit/utils.d.mts +34 -0
  157. package/dist/kit/utils.mjs +90 -0
  158. package/dist/package.mjs +176 -0
  159. package/dist/presets/_all.gen.d.mts +5 -2
  160. package/dist/presets/_all.gen.mjs +16 -13
  161. package/dist/presets/_resolve.d.mts +10 -6
  162. package/dist/presets/_resolve.mjs +51 -65
  163. package/dist/presets/_types.gen.d.mts +8 -5
  164. package/dist/presets/_types.gen.mjs +5 -1
  165. package/dist/presets/h3/preset.d.mts +5 -2
  166. package/dist/presets/h3/preset.mjs +33 -38
  167. package/dist/presets/hono/preset.d.mts +5 -2
  168. package/dist/presets/hono/preset.mjs +28 -35
  169. package/dist/presets/index.d.mts +3 -2
  170. package/dist/presets/index.mjs +3 -1
  171. package/dist/presets/nitro/preset.d.mts +5 -2
  172. package/dist/presets/nitro/preset.mjs +35 -42
  173. package/dist/presets/npmpackage/preset.d.mts +5 -2
  174. package/dist/presets/npmpackage/preset.mjs +27 -32
  175. package/dist/presets/nuxt/preset.d.mts +5 -2
  176. package/dist/presets/nuxt/preset.mjs +39 -44
  177. package/dist/runtime/index.d.mts +4 -3
  178. package/dist/runtime/index.mjs +5 -3
  179. package/dist/runtime/internal/config.d.mts +11 -7
  180. package/dist/runtime/internal/config.mjs +79 -90
  181. package/dist/runtime/internal/debug.d.mts +6 -3
  182. package/dist/runtime/internal/debug.mjs +9 -4
  183. package/dist/runtime/internal/defu.d.mts +4 -1
  184. package/dist/runtime/internal/defu.mjs +7 -2
  185. package/dist/runtime/internal/index.d.mts +7 -6
  186. package/dist/runtime/internal/index.mjs +8 -20
  187. package/dist/runtime/internal/nitro.d.mts +6 -3
  188. package/dist/runtime/internal/nitro.mjs +29 -37
  189. package/dist/runtime/internal/nuxt.d.mts +12 -8
  190. package/dist/runtime/internal/nuxt.mjs +12 -7
  191. package/dist/runtime/internal/ofetch.d.mts +8 -4
  192. package/dist/runtime/internal/ofetch.mjs +33 -34
  193. package/dist/runtime/internal/plugin.d.mts +7 -3
  194. package/dist/runtime/internal/plugin.mjs +7 -3
  195. package/dist/types/cliConfig.d.mts +288 -0
  196. package/dist/types/cliConfig.mjs +0 -0
  197. package/dist/types/cliHooks.d.mts +154 -0
  198. package/dist/types/cliHooks.mjs +0 -0
  199. package/dist/types/compatibility.d.mts +13 -0
  200. package/dist/types/compatibility.mjs +0 -0
  201. package/dist/types/config.d.mts +46 -0
  202. package/dist/types/config.mjs +0 -0
  203. package/dist/types/dotenv.d.mts +29 -0
  204. package/dist/types/dotenv.mjs +0 -0
  205. package/dist/types/event.d.mts +63 -0
  206. package/dist/types/event.mjs +0 -0
  207. package/dist/types/global.d.mts +24 -0
  208. package/dist/types/global.mjs +0 -0
  209. package/dist/types/helper.d.mts +25 -0
  210. package/dist/types/helper.mjs +0 -0
  211. package/dist/types/hooks.d.mts +37 -0
  212. package/dist/types/hooks.mjs +0 -0
  213. package/dist/types/index.d.mts +26 -1306
  214. package/dist/types/index.mjs +0 -1
  215. package/dist/types/kits.d.mts +32 -0
  216. package/dist/types/kits.mjs +0 -0
  217. package/dist/types/middleware.d.mts +31 -0
  218. package/dist/types/middleware.mjs +0 -0
  219. package/dist/types/module.d.mts +102 -0
  220. package/dist/types/module.mjs +0 -0
  221. package/dist/types/preset.d.mts +20 -0
  222. package/dist/types/preset.mjs +0 -0
  223. package/dist/types/route.d.mts +59 -0
  224. package/dist/types/route.mjs +0 -0
  225. package/dist/types/runtime/index.d.mts +5 -0
  226. package/dist/types/runtime/index.mjs +0 -0
  227. package/dist/types/runtime/nuxt.d.mts +13 -0
  228. package/dist/types/runtime/nuxt.mjs +0 -0
  229. package/dist/types/runtime/ofetch.d.mts +14 -0
  230. package/dist/types/runtime/ofetch.mjs +0 -0
  231. package/dist/types/runtime/plugin.d.mts +8 -0
  232. package/dist/types/runtime/plugin.mjs +0 -0
  233. package/dist/types/runtime/silgi.d.mts +11 -0
  234. package/dist/types/runtime/silgi.mjs +0 -0
  235. package/dist/types/schema.d.mts +86 -0
  236. package/dist/types/schema.mjs +0 -0
  237. package/dist/types/service.d.mts +102 -0
  238. package/dist/types/service.mjs +0 -0
  239. package/dist/types/shared.d.mts +19 -0
  240. package/dist/types/shared.mjs +0 -0
  241. package/dist/types/silgi.d.mts +71 -0
  242. package/dist/types/silgi.mjs +0 -0
  243. package/dist/types/silgiCLI.d.mts +118 -0
  244. package/dist/types/silgiCLI.mjs +0 -0
  245. package/dist/types/standard-schema.d.mts +61 -0
  246. package/dist/types/standard-schema.mjs +0 -0
  247. package/dist/types/storage.d.mts +30 -0
  248. package/dist/types/storage.mjs +0 -0
  249. package/package.json +20 -35
  250. package/dist/_chunks/silgiApp.mjs +0 -25
  251. package/dist/cli/build.mjs +0 -2190
  252. package/dist/cli/common.mjs +0 -13
  253. package/dist/cli/compatibility.mjs +0 -30
  254. package/dist/cli/dev.mjs +0 -67
  255. package/dist/cli/init.mjs +0 -112
  256. package/dist/cli/install.mjs +0 -151
  257. package/dist/cli/loader.mjs +0 -618
  258. package/dist/cli/prepare.mjs +0 -188
  259. package/dist/cli/reset.mjs +0 -55
  260. package/dist/cli/run.mjs +0 -159
  261. package/dist/cli/types.mjs +0 -233
  262. package/dist/cli/watch.mjs +0 -91
  263. package/dist/presets/next/preset.d.mts +0 -3
  264. package/dist/presets/next/preset.mjs +0 -38
  265. package/dist/runtime/internal/next.d.mts +0 -9
  266. package/dist/runtime/internal/next.mjs +0 -22
@@ -0,0 +1,82 @@
1
+ import { dirname, isAbsolute, join, normalize, resolve } from "pathe";
2
+ import { tryUseSilgiCLI } from "silgi";
3
+ import { existsSync, promises } from "node:fs";
4
+ import { resolvePath } from "mlly";
5
+ import { fileURLToPath } from "node:url";
6
+ import { resolveAlias } from "pathe/utils";
7
+
8
+ //#region src/kit/resolve.ts
9
+ /**
10
+ * Resolve full path to a file or directory respecting Nuxt alias and extensions options
11
+ *
12
+ * If path could not be resolved, normalized input path will be returned
13
+ */
14
+ async function resolvePath$1(path, opts = {}) {
15
+ const _path = path;
16
+ path = normalize(path);
17
+ if (isAbsolute(path)) {
18
+ if (existsSync(path) && !await isDirectory(path)) return path;
19
+ }
20
+ const cwd = opts.cwd || process.cwd();
21
+ const extensions = opts.extensions || [
22
+ ".ts",
23
+ ".mjs",
24
+ ".cjs",
25
+ ".json"
26
+ ];
27
+ const modulesDir = opts.modulesDir || [];
28
+ path = resolveAlias$1(path);
29
+ if (!isAbsolute(path)) path = resolve(cwd, path);
30
+ let _isDir = false;
31
+ if (existsSync(path)) {
32
+ _isDir = await isDirectory(path);
33
+ if (!_isDir) return path;
34
+ }
35
+ for (const ext of extensions) {
36
+ const pathWithExt = path + ext;
37
+ if (existsSync(pathWithExt)) return pathWithExt;
38
+ const pathWithIndex = join(path, `index${ext}`);
39
+ if (_isDir && existsSync(pathWithIndex)) return pathWithIndex;
40
+ }
41
+ const resolveModulePath = await resolvePath(_path, { url: [cwd, ...modulesDir] }).catch(() => null);
42
+ if (resolveModulePath) return resolveModulePath;
43
+ return opts.fallbackToOriginal ? _path : path;
44
+ }
45
+ async function isDirectory(path) {
46
+ return (await promises.lstat(path)).isDirectory();
47
+ }
48
+ /**
49
+ * Resolve path aliases respecting Nuxt alias options
50
+ */
51
+ function resolveAlias$1(path, alias) {
52
+ alias ||= tryUseSilgiCLI()?.options.alias || {};
53
+ return resolveAlias(path, alias || {});
54
+ }
55
+ /**
56
+ * Create a relative resolver
57
+ */
58
+ function createResolver(base) {
59
+ if (!base) throw new Error("`base` argument is missing for createResolver(base)!");
60
+ base = base.toString();
61
+ if (base.startsWith("file://")) base = dirname(fileURLToPath(base));
62
+ return {
63
+ resolve: (...path) => resolve(base, ...path),
64
+ resolvePath: (path, opts) => resolvePath$1(path, {
65
+ cwd: base,
66
+ ...opts
67
+ })
68
+ };
69
+ }
70
+ async function resolveSilgiModule(base, paths) {
71
+ const resolved = [];
72
+ const resolver = createResolver(base);
73
+ for (const path of paths) if (path.startsWith(base)) resolved.push(path.split("/index.ts")[0]);
74
+ else {
75
+ const resolvedPath = await resolver.resolvePath(path);
76
+ resolved.push(resolvedPath.slice(0, resolvedPath.lastIndexOf(path) + path.length));
77
+ }
78
+ return resolved;
79
+ }
80
+
81
+ //#endregion
82
+ export { createResolver, resolveAlias$1 as resolveAlias, resolvePath$1 as resolvePath, resolveSilgiModule };
@@ -0,0 +1,14 @@
1
+ import { ResolvedSilgiTemplate, SilgiTemplate } from "silgi/types";
2
+
3
+ //#region src/kit/template.d.ts
4
+
5
+ /**
6
+ * Renders given template during build into the virtual file system (and optionally to disk in the project `buildDir`)
7
+ */
8
+ declare function addTemplate<T>(_template: SilgiTemplate<T> | string): ResolvedSilgiTemplate<T>;
9
+ /**
10
+ * Normalize a silgi template object
11
+ */
12
+ declare function normalizeTemplate<T>(template: SilgiTemplate<T> | string, buildDir?: string): ResolvedSilgiTemplate<T>;
13
+ //#endregion
14
+ export { addTemplate as addTemplate$1, normalizeTemplate as normalizeTemplate$1 };
@@ -0,0 +1,59 @@
1
+ import { filterInPlace } from "./utils.mjs";
2
+ import { basename, parse, resolve } from "pathe";
3
+ import { useSilgiCLI } from "silgi";
4
+ import { hash } from "silgi/kit";
5
+ import { existsSync } from "node:fs";
6
+
7
+ //#region src/kit/template.ts
8
+ /**
9
+ * Renders given template during build into the virtual file system (and optionally to disk in the project `buildDir`)
10
+ */
11
+ function addTemplate$1(_template) {
12
+ const silgi = useSilgiCLI();
13
+ const template = normalizeTemplate$1(_template);
14
+ filterInPlace(silgi.options.build.templates, (p) => normalizeTemplate$1(p).dst !== template.dst);
15
+ silgi.options.build.templates.push(template);
16
+ return template;
17
+ }
18
+ /**
19
+ * Normalize a silgi template object
20
+ */
21
+ function normalizeTemplate$1(template, buildDir) {
22
+ if (!template) throw new Error(`Invalid template: ${JSON.stringify(template)}`);
23
+ if (typeof template === "string") template = { src: template };
24
+ else template = { ...template };
25
+ if (template.src) {
26
+ if (!existsSync(template.src)) throw new Error(`Template not found: ${template.src}`);
27
+ if (!template.filename) {
28
+ const srcPath = parse(template.src);
29
+ template.filename = template.fileName || `${basename(srcPath.dir)}.${srcPath.name}.${hash(template.src)}${srcPath.ext}`;
30
+ }
31
+ }
32
+ if (!template.src && !template.getContents) throw new Error(`Invalid template. Either \`getContents\` or \`src\` should be provided: ${JSON.stringify(template)}`);
33
+ if (!template.filename) throw new Error(`Invalid template. \`filename\` must be provided: ${JSON.stringify(template)}`);
34
+ if (template.filename.endsWith(".d.ts")) template.write = true;
35
+ if (!template.dst) {
36
+ const silgi = useSilgiCLI();
37
+ let dir;
38
+ switch (template.where) {
39
+ case ".silgi":
40
+ dir = silgi.options.build.dir;
41
+ break;
42
+ case "server":
43
+ dir = silgi.options.silgi.serverDir;
44
+ break;
45
+ case "client":
46
+ dir = silgi.options.silgi.clientDir;
47
+ break;
48
+ case "root":
49
+ dir = silgi.options.rootDir;
50
+ break;
51
+ default: dir = silgi.options.silgi.serverDir;
52
+ }
53
+ template.dst = resolve(buildDir ?? dir, template.filename);
54
+ }
55
+ return template;
56
+ }
57
+
58
+ //#endregion
59
+ export { addTemplate$1 as addTemplate, normalizeTemplate$1 as normalizeTemplate };
@@ -0,0 +1,19 @@
1
+ import { SilgiEvent } from "silgi/types";
2
+ import { IncomingMessage } from "node:http";
3
+
4
+ //#region src/kit/useRequest.d.ts
5
+
6
+ /**
7
+ * @deprecated
8
+ */
9
+ declare function useRequest<T extends IncomingMessage>(event: SilgiEvent): T | (IncomingMessage & {
10
+ originalUrl?: string;
11
+ });
12
+ /**
13
+ * Extract the client's IP address from request headers with high accuracy
14
+ * @param req - The incoming HTTP request (Fetch API Request)
15
+ * @returns The client's IP address or empty string if not found
16
+ */
17
+ declare function getIpAddress(req: Request): string;
18
+ //#endregion
19
+ export { getIpAddress as getIpAddress$1, useRequest as useRequest$1 };
@@ -0,0 +1,63 @@
1
+ import { useSilgi } from "silgi";
2
+
3
+ //#region src/kit/useRequest.ts
4
+ /**
5
+ * @deprecated
6
+ */
7
+ function useRequest(event) {
8
+ const silgi = useSilgi();
9
+ if (silgi.options.present === "nuxt" || silgi.options.present === "nitro" || silgi.options.present === "h3") return event.node.req;
10
+ return event;
11
+ }
12
+ /**
13
+ * Extract the client's IP address from request headers with high accuracy
14
+ * @param req - The incoming HTTP request (Fetch API Request)
15
+ * @returns The client's IP address or empty string if not found
16
+ */
17
+ function getIpAddress(req) {
18
+ const headers = [
19
+ "cf-connecting-ip",
20
+ "true-client-ip",
21
+ "x-real-ip",
22
+ "x-forwarded-for",
23
+ "x-client-ip",
24
+ "x-forwarded",
25
+ "forwarded",
26
+ "forwarded-for",
27
+ "x-appengine-user-ip",
28
+ "x-cluster-client-ip",
29
+ "fastly-client-ip",
30
+ "x-azure-clientip",
31
+ "x-original-forwarded-for",
32
+ "x-lb-forwarded-for",
33
+ "cdn-loop"
34
+ ];
35
+ for (const header of headers) {
36
+ const value = req.headers.get(header);
37
+ if (!value) continue;
38
+ let ip;
39
+ if (header === "x-forwarded-for" || header === "forwarded-for" || header === "x-original-forwarded-for") ip = value.split(",")[0];
40
+ else if (header === "forwarded") {
41
+ const match = value.match(/for=([^;]+)/);
42
+ ip = match?.[1]?.trim().replace(/^\[|\]$/g, "") ?? "";
43
+ } else ip = value;
44
+ const cleanIp = ip.trim();
45
+ if (cleanIp && isValidIp(cleanIp)) return cleanIp;
46
+ }
47
+ return "";
48
+ }
49
+ /**
50
+ * Validates if a string is a valid IPv4 or IPv6 address
51
+ * Optimized for performance in high-traffic applications
52
+ * @param ip - The IP address to validate
53
+ * @returns true if the IP is valid
54
+ */
55
+ function isValidIp(ip) {
56
+ if (ip === "::1" || ip === "localhost" || ip === "127.0.0.1") return true;
57
+ if (/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(ip)) return true;
58
+ if (/^[0-9a-f:]+$/i.test(ip)) return true;
59
+ return false;
60
+ }
61
+
62
+ //#endregion
63
+ export { getIpAddress, useRequest };
@@ -0,0 +1,34 @@
1
+ import { PresetName } from "silgi/presets";
2
+ import { SilgiCLI } from "silgi/types";
3
+
4
+ //#region src/kit/utils.d.ts
5
+ declare function relativeWithDot(from: string, to: string): string;
6
+ declare function toArray<T>(value: T | T[]): T[];
7
+ /**
8
+ * Filter out items from an array in place. This function mutates the array.
9
+ * `predicate` get through the array from the end to the start for performance.
10
+ *
11
+ * This function should be faster than `Array.prototype.filter` on large arrays.
12
+ */
13
+ declare function filterInPlace<T>(array: T[], predicate: (item: T, index: number, arr: T[]) => unknown): T[];
14
+ declare const MODE_RE: RegExp;
15
+ /**
16
+ * Check if a Silgi module is installed by name.
17
+ *
18
+ * This will check both the installed modules and the modules to be installed. Note
19
+ * that it cannot detect if a module is _going to be_ installed programmatically by another module.
20
+ */
21
+ declare function hasSilgiModule(moduleKey: string, silgi?: SilgiCLI): boolean;
22
+ declare function hasInstalledModule(moduleKey: string, silgi?: SilgiCLI): boolean;
23
+ declare const baseHeaderBannerComment: string[];
24
+ declare function processFilePath(src: string): string;
25
+ declare function isPresents(names: PresetName[]): boolean;
26
+ declare function isRuntimePresents(names: PresetName[]): boolean;
27
+ declare function removeExtension(filePath: string, force?: boolean): string;
28
+ declare function getServicePath(_route: string): {
29
+ method: string;
30
+ type: string;
31
+ route: string;
32
+ };
33
+ //#endregion
34
+ export { MODE_RE as MODE_RE$1, baseHeaderBannerComment as baseHeaderBannerComment$1, filterInPlace as filterInPlace$1, getServicePath as getServicePath$1, hasInstalledModule as hasInstalledModule$2, hasSilgiModule as hasSilgiModule$1, isPresents as isPresents$1, isRuntimePresents as isRuntimePresents$1, processFilePath as processFilePath$1, relativeWithDot as relativeWithDot$1, removeExtension as removeExtension$1, toArray as toArray$1 };
@@ -0,0 +1,90 @@
1
+ import { extname, relative } from "pathe";
2
+ import { useSilgi, useSilgiCLI } from "silgi";
3
+
4
+ //#region src/kit/utils.ts
5
+ const RELATIVE_RE = /^([^.])/;
6
+ function relativeWithDot(from, to) {
7
+ return relative(from, to).replace(RELATIVE_RE, "./$1") || ".";
8
+ }
9
+ function toArray(value) {
10
+ return Array.isArray(value) ? value : [value];
11
+ }
12
+ /**
13
+ * Filter out items from an array in place. This function mutates the array.
14
+ * `predicate` get through the array from the end to the start for performance.
15
+ *
16
+ * This function should be faster than `Array.prototype.filter` on large arrays.
17
+ */
18
+ function filterInPlace(array, predicate) {
19
+ for (let i = array.length; i--;) if (!predicate(array[i], i, array)) array.splice(i, 1);
20
+ return array;
21
+ }
22
+ const MODE_RE = /\.(server|client)(\.\w+)*$/;
23
+ /**
24
+ * Check if a Silgi module is installed by name.
25
+ *
26
+ * This will check both the installed modules and the modules to be installed. Note
27
+ * that it cannot detect if a module is _going to be_ installed programmatically by another module.
28
+ */
29
+ function hasSilgiModule(moduleKey, silgi = useSilgiCLI()) {
30
+ return silgi.scanModules.some(({ meta }) => meta.configKey === moduleKey) || Object.keys(silgi.scanModules).includes(moduleKey);
31
+ }
32
+ function hasInstalledModule(moduleKey, silgi = useSilgiCLI()) {
33
+ const find = silgi.scanModules.find(({ meta }) => meta.configKey === moduleKey);
34
+ return find?.installed ?? false;
35
+ }
36
+ const baseHeaderBannerComment = [
37
+ "// DO NOT EDIT THIS FILE",
38
+ "// This file is generated by Silgi",
39
+ "/* eslint-disable */",
40
+ "/* prettier-ignore */",
41
+ "/* tslint:disable */"
42
+ ];
43
+ function processFilePath(src) {
44
+ const silgi = useSilgiCLI();
45
+ if (silgi.options.typescript.removeFileExtension) {
46
+ src = src.replace(/\.ts$/, "");
47
+ return src;
48
+ }
49
+ return src;
50
+ }
51
+ function isPresents(names) {
52
+ const silgi = useSilgiCLI();
53
+ return names.filter((name) => silgi.options.preset.includes(name)).length > 0;
54
+ }
55
+ function isRuntimePresents(names) {
56
+ const silgi = useSilgi();
57
+ return names.includes(silgi.options.present);
58
+ }
59
+ function removeExtension(filePath, force = false) {
60
+ const silgi = useSilgiCLI();
61
+ if (silgi.options.typescript.removeFileExtension || force) {
62
+ const ext = extname(filePath);
63
+ return ext ? filePath.slice(0, -ext.length) : filePath;
64
+ }
65
+ return filePath;
66
+ }
67
+ function getServicePath(_route) {
68
+ let method = "";
69
+ let type = "";
70
+ let route = _route;
71
+ const parts = route.split(":");
72
+ if (parts.length === 3) {
73
+ type = parts[0] ? parts[0].toLowerCase() : "";
74
+ method = parts[1] ? parts[1].toUpperCase() : "";
75
+ if (method === "GLOBAL" || method === "ALL") method = "";
76
+ route = parts[2] ?? "";
77
+ } else if (parts.length === 2) {
78
+ method = parts[0] ? parts[0].toUpperCase() : "";
79
+ if (method === "GLOBAL" || method === "ALL") method = "";
80
+ route = parts[1] ?? "";
81
+ }
82
+ return {
83
+ method,
84
+ type,
85
+ route
86
+ };
87
+ }
88
+
89
+ //#endregion
90
+ export { MODE_RE, baseHeaderBannerComment, filterInPlace, getServicePath, hasInstalledModule, hasSilgiModule, isPresents, isRuntimePresents, processFilePath, relativeWithDot, removeExtension, toArray };
@@ -0,0 +1,176 @@
1
+ //#region package.json
2
+ var name = "silgi";
3
+ var type = "module";
4
+ var version = "0.43.0";
5
+ var private$1 = false;
6
+ var packageManager = "pnpm@10.11.0";
7
+ var sideEffects = false;
8
+ var exports = {
9
+ "./package.json": "./package.json",
10
+ ".": "./dist/core/index.mjs",
11
+ "./core": "./dist/core/index.mjs",
12
+ "./build": "./dist/build.mjs",
13
+ "./cli": "./dist/cli/index.mjs",
14
+ "./cli/config": "./dist/cli/config/index.mjs",
15
+ "./kit": "./dist/kit/index.mjs",
16
+ "./config": "./lib/config.mjs",
17
+ "./types": "./dist/types/index.d.mts",
18
+ "./meta": "./lib/meta.mjs",
19
+ "./presets": { "import": "./dist/presets/index.mjs" },
20
+ "./runtime": { "import": "./dist/runtime/index.mjs" },
21
+ "./runtime/internal/nitro": { "import": "./dist/runtime/internal/nitro.mjs" },
22
+ "./runtime/internal/debug": { "import": "./dist/runtime/internal/debug.mjs" },
23
+ "./runtime/internal": { "import": "./dist/runtime/internal/index.mjs" },
24
+ "./runtime/internal/nuxt": { "import": "./dist/runtime/internal/nuxt.mjs" },
25
+ "./runtime/meta": "./lib/runtime-meta.mjs"
26
+ };
27
+ var main = "./dist/core/index.mjs";
28
+ var types = "./dist/types/index.d.mts";
29
+ var bin = { "silgi": "./dist/cli/index.mjs" };
30
+ var files = [
31
+ "bin",
32
+ "dist",
33
+ "lib"
34
+ ];
35
+ var scripts = {
36
+ "build:package": "tsdown",
37
+ "build": "pnpm gen-presets && pnpm build:package",
38
+ "build:prepare": "pnpm watch",
39
+ "typecheck": "tsc --noEmit",
40
+ "watch": "pnpm gen-presets && tsdown --watch",
41
+ "dev:k6": "k6 run ./__tests__/k6.js",
42
+ "test": "vitest",
43
+ "test:coverage": "vitest run --coverage.enabled true",
44
+ "lint": "eslint .",
45
+ "lint:fix": "eslint . --fix",
46
+ "silgi": "tsx cli/index.ts",
47
+ "release": "pnpm gen-presets && pnpm tsdown && pnpm publish --no-git-checks --access public",
48
+ "release:beta": "pnpm release --tag beta",
49
+ "generate": "pnpm --filter './examples/**' silgi:prepare",
50
+ "gen-presets": "pnpm jiti scripts/gen-presets.ts",
51
+ "all:delete": "find . -type d \\( -name \"node_modules\" -o -name \"dist\" \\) -prune -exec rm -rf {} +"
52
+ };
53
+ var peerDependencies = {
54
+ "@fastify/deepmerge": ">=3.0.0",
55
+ "@nuxt/kit": ">=3.16.1",
56
+ "@nuxt/schema": ">=3.16.1",
57
+ "@silgi/ecosystem": ">=0.4.4",
58
+ "h3": ">=1.15.1",
59
+ "nitropack": ">=2.11.7",
60
+ "nuxt": ">=3.16.1",
61
+ "typescript": ">=5.8.2",
62
+ "vue": ">=3.5.13",
63
+ "zod": ">=3.24.2"
64
+ };
65
+ var peerDependenciesMeta = {
66
+ "@nuxt/kit": { "optional": true },
67
+ "@nuxt/schema": { "optional": true },
68
+ "h3": { "optional": true },
69
+ "nitropack": { "optional": true },
70
+ "nuxt": { "optional": true },
71
+ "vue": { "optional": true },
72
+ "zod": { "optional": true }
73
+ };
74
+ var dependencies = {
75
+ "@antfu/ni": "^25.0.0",
76
+ "@clack/prompts": "catalog:",
77
+ "@fastify/deepmerge": "catalog:",
78
+ "@graphql-tools/utils": "^10.8.6",
79
+ "@standard-community/standard-json": "^0.2.0",
80
+ "apiful": "^3.1.2",
81
+ "c12": "catalog:",
82
+ "chokidar": "catalog:",
83
+ "citty": "catalog:",
84
+ "compatx": "catalog:",
85
+ "consola": "catalog:",
86
+ "crossws": "^0.4.1",
87
+ "defu": "catalog:",
88
+ "destr": "catalog:",
89
+ "dev-jiti": "catalog:",
90
+ "dot-prop": "catalog:",
91
+ "dotenv": "catalog:",
92
+ "escape-string-regexp": "catalog:",
93
+ "exsolve": "^1.0.5",
94
+ "graphql": "^16.11.0",
95
+ "hookable": "catalog:",
96
+ "ignore": "catalog:",
97
+ "klona": "catalog:",
98
+ "knitwork": "catalog:",
99
+ "magicast": "^0.3.5",
100
+ "micromatch": "^4.0.8",
101
+ "mlly": "catalog:",
102
+ "ofetch": "catalog:",
103
+ "ohash": "catalog:",
104
+ "oxc-parser": "^0.72.0",
105
+ "pathe": "catalog:",
106
+ "perfect-debounce": "^1.0.0",
107
+ "picocolors": "catalog:",
108
+ "pkg-types": "catalog:",
109
+ "rfc6902": "^5.1.2",
110
+ "rou3": "^0.6.1",
111
+ "scule": "catalog:",
112
+ "semver": "catalog:",
113
+ "srvx": "^0.7.2",
114
+ "std-env": "catalog:",
115
+ "tinyexec": "^1.0.1",
116
+ "tinyglobby": "^0.2.14",
117
+ "ufo": "catalog:",
118
+ "unadapter": "^0.1.2",
119
+ "unctx": "catalog:",
120
+ "unimport": "catalog:",
121
+ "unstorage": "catalog:",
122
+ "untyped": "catalog:"
123
+ };
124
+ var devDependencies = {
125
+ "@antfu/eslint-config": "catalog:",
126
+ "@nuxt/kit": "catalog:",
127
+ "@nuxt/schema": "catalog:",
128
+ "@silgi/ecosystem": "catalog:",
129
+ "@types/micromatch": "^4.0.9",
130
+ "@types/node": "catalog:",
131
+ "@types/semver": "catalog:",
132
+ "@vitest/coverage-v8": "catalog:",
133
+ "eslint": "catalog:",
134
+ "h3": "catalog:",
135
+ "nitropack": "catalog:",
136
+ "nuxt": "catalog:",
137
+ "tsdown": "^0.12.4",
138
+ "typescript": "catalog:",
139
+ "vitest": "catalog:",
140
+ "vue": "catalog:",
141
+ "zod": "catalog:"
142
+ };
143
+ var pnpm = {
144
+ "onlyBuiltDependencies": [
145
+ "@parcel/watcher",
146
+ "esbuild",
147
+ "vue-demi"
148
+ ],
149
+ "overrides": { "silgi": "link:." }
150
+ };
151
+ var resolutions = { "silgi": "link:." };
152
+ var publishConfig = { "access": "public" };
153
+ var package_default = {
154
+ name,
155
+ type,
156
+ version,
157
+ private: private$1,
158
+ packageManager,
159
+ sideEffects,
160
+ exports,
161
+ main,
162
+ types,
163
+ bin,
164
+ files,
165
+ scripts,
166
+ peerDependencies,
167
+ peerDependenciesMeta,
168
+ dependencies,
169
+ devDependencies,
170
+ pnpm,
171
+ resolutions,
172
+ publishConfig
173
+ };
174
+
175
+ //#endregion
176
+ export { package_default };
@@ -1,3 +1,6 @@
1
- import type { SilgiPreset } from "silgi/types";
1
+ import { SilgiPreset } from "silgi/types";
2
+
3
+ //#region src/presets/_all.gen.d.ts
2
4
  declare const presets: readonly SilgiPreset[];
3
- export default presets;
5
+ //#endregion
6
+ export { presets as default };
@@ -1,15 +1,18 @@
1
- import _h3 from "./h3/preset.mjs";
2
- import _hono from "./hono/preset.mjs";
3
- import _next from "./next/preset.mjs";
4
- import _nitro from "./nitro/preset.mjs";
5
- import _npmpackage from "./npmpackage/preset.mjs";
6
- import _nuxt from "./nuxt/preset.mjs";
1
+ import preset_default from "./h3/preset.mjs";
2
+ import preset_default$1 from "./hono/preset.mjs";
3
+ import preset_default$2 from "./nitro/preset.mjs";
4
+ import preset_default$3 from "./npmpackage/preset.mjs";
5
+ import preset_default$4 from "./nuxt/preset.mjs";
6
+
7
+ //#region src/presets/_all.gen.ts
7
8
  const presets = [
8
- ..._h3,
9
- ..._hono,
10
- ..._next,
11
- ..._nitro,
12
- ..._npmpackage,
13
- ..._nuxt
9
+ ...preset_default,
10
+ ...preset_default$1,
11
+ ...preset_default$2,
12
+ ...preset_default$3,
13
+ ...preset_default$4
14
14
  ];
15
- export default presets;
15
+ var _all_gen_default = presets;
16
+
17
+ //#endregion
18
+ export { _all_gen_default as default };
@@ -1,8 +1,12 @@
1
- import type { CompatibilityDateSpec } from 'compatx';
2
- import type { SilgiPreset, SilgiPresetMeta } from 'silgi/types';
3
- export declare function resolvePreset(name: string, opts: {
4
- static?: boolean;
5
- compatibilityDate?: false | CompatibilityDateSpec;
1
+ import { CompatibilityDateSpec } from "compatx";
2
+ import { SilgiPreset, SilgiPresetMeta } from "silgi/types";
3
+
4
+ //#region src/presets/_resolve.d.ts
5
+ declare function resolvePreset(name: string, opts: {
6
+ static?: boolean;
7
+ compatibilityDate?: false | CompatibilityDateSpec;
6
8
  }): Promise<(SilgiPreset & {
7
- _meta?: SilgiPresetMeta;
9
+ _meta?: SilgiPresetMeta;
8
10
  }) | undefined>;
11
+ //#endregion
12
+ export { resolvePreset };