silgi 0.42.5 → 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 -232
  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,54 @@
1
+ import { useSilgi } from "../unctx.mjs";
2
+ import { createError } from "../error.mjs";
3
+ import { replaceRuntimeValues } from "./runtime.mjs";
4
+ import { useRuntimeConfig } from "silgi/runtime";
5
+ import { klona } from "klona";
6
+ import { builtinDrivers, createStorage, prefixStorage } from "unstorage";
7
+ import { Buffer } from "node:buffer";
8
+
9
+ //#region src/core/utils/storage.ts
10
+ async function createStorage$1(silgi) {
11
+ const storage = createStorage();
12
+ const runtime = useRuntimeConfig();
13
+ const mounts = klona({
14
+ ...silgi.options.storage,
15
+ ...silgi.options.devStorage
16
+ });
17
+ for (const [path, opts] of Object.entries(mounts)) if (opts.driver) {
18
+ const driver = await import(builtinDrivers[opts.driver] || opts.driver).then((r) => r.default || r);
19
+ const processedOpts = replaceRuntimeValues({ ...opts }, runtime);
20
+ storage.mount(path, driver(processedOpts));
21
+ } else silgi.logger.warn(`No \`driver\` set for storage mount point "${path}".`);
22
+ return storage;
23
+ }
24
+ function useSilgiStorage(base = "/memory:cache") {
25
+ const silgi = useSilgi();
26
+ return base ? prefixStorage(silgi.storage, base) : silgi.storage;
27
+ }
28
+ async function generateStorageKey(params) {
29
+ const { url, input, keyGenerator, requestId, storageOptions } = params;
30
+ const cacheScopePrefix = storageOptions?.scope === "request" ? "req" : "global";
31
+ const parts = [cacheScopePrefix, url.raw].filter(Boolean);
32
+ if (storageOptions?.scope === "request") {
33
+ if (!requestId) throw createError({
34
+ statusCode: 400,
35
+ statusMessage: "Request ID is required for request-scoped cache",
36
+ data: {
37
+ requestId,
38
+ url,
39
+ input,
40
+ storageOptions,
41
+ keyGenerator
42
+ }
43
+ });
44
+ parts.push(requestId);
45
+ }
46
+ if (keyGenerator) {
47
+ const customKey = await Promise.resolve(keyGenerator(input));
48
+ parts.push(customKey);
49
+ } else parts.push(typeof input === "object" ? JSON.stringify(input) : String(input));
50
+ return Buffer.from(parts.join(":")).toString("base64");
51
+ }
52
+
53
+ //#endregion
54
+ export { createStorage$1 as createStorage, generateStorageKey, useSilgiStorage };
package/dist/index.d.mts CHANGED
@@ -1,6 +1,21 @@
1
- export { SilgiError, SilgiHttpEvent, autoImportTypes, createError, createEventStream, createResolver, createSchema, createService, createShared, createSilgi, createStorage, createWebSocket, deepMergeObjects, defineServiceSetup, getEvent, getEventContext, getUrlPrefix, getWebsocket, handleResponse, handler, isError, kHandled, kNotFound, middleware, replaceRuntimeValues, silgiCLICtx, silgiCtx, silgiFetch, storageMount, tryUseSilgi, tryUseSilgiCLI, updateRuntimeStorage, useRuntime, useSilgi, useSilgiCLI, useSilgiStorage } from './core/index.mjs';
2
- export { c as createMiddleware } from './shared/silgi.DTwQEdSr.mjs';
3
- import 'silgi/types';
4
- import 'srvx';
5
- import 'unctx';
6
- import 'unstorage';
1
+ import { updateRuntimeStorage$1 as updateRuntimeStorage, useRuntime$1 as useRuntime } from "./core/context.mjs";
2
+ import { createSilgi$1 as createSilgi } from "./core/createSilgi.mjs";
3
+ import { SilgiError$1 as SilgiError, createError$1 as createError, isError$1 as isError } from "./core/error.mjs";
4
+ import { SilgiHttpEvent$1 as SilgiHttpEvent } from "./core/event.mjs";
5
+ import { handleResponse$1 as handleResponse, kHandled$1 as kHandled, kNotFound$1 as kNotFound } from "./core/response.mjs";
6
+ import { getWebsocket$1 as getWebsocket, handler$1 as handler, middleware$1 as middleware, silgiFetch$1 as silgiFetch } from "./core/silgi.mjs";
7
+ import { silgiCLICtx$1 as silgiCLICtx, tryUseSilgiCLI$1 as tryUseSilgiCLI, useSilgiCLI$1 as useSilgiCLI } from "./core/silgiApp.mjs";
8
+ import { storageMount$1 as storageMount } from "./core/storage.mjs";
9
+ import { silgiCtx$1 as silgiCtx, tryUseSilgi$1 as tryUseSilgi, useSilgi$1 as useSilgi } from "./core/unctx.mjs";
10
+ import { createEventStream$1 as createEventStream } from "./core/utils/event-stream.mjs";
11
+ import { getEvent$1 as getEvent, getEventContext$1 as getEventContext } from "./core/utils/event.mjs";
12
+ import { deepMergeObjects$1 as deepMergeObjects } from "./core/utils/merge.mjs";
13
+ import { createMiddleware$1 as createMiddleware } from "./core/utils/middleware.mjs";
14
+ import { createResolver$3 as createResolver, getUrlPrefix$1 as getUrlPrefix } from "./core/utils/resolver.mjs";
15
+ import { replaceRuntimeValues$1 as replaceRuntimeValues } from "./core/utils/runtime.mjs";
16
+ import { createSchema$1 as createSchema } from "./core/utils/schema.mjs";
17
+ import { createService$1 as createService, createWebSocket$1 as createWebSocket, defineServiceSetup$1 as defineServiceSetup } from "./core/utils/service.mjs";
18
+ import { createShared$1 as createShared } from "./core/utils/shared.mjs";
19
+ import { createStorage$1 as createStorage, useSilgiStorage$1 as useSilgiStorage } from "./core/utils/storage.mjs";
20
+ import { autoImportTypes } from "./core/index.mjs";
21
+ export { SilgiError, SilgiHttpEvent, autoImportTypes, createError, createEventStream, createMiddleware, createResolver, createSchema, createService, createShared, createSilgi, createStorage, createWebSocket, deepMergeObjects, defineServiceSetup, getEvent, getEventContext, getUrlPrefix, getWebsocket, handleResponse, handler, isError, kHandled, kNotFound, middleware, replaceRuntimeValues, silgiCLICtx, silgiCtx, silgiFetch, storageMount, tryUseSilgi, tryUseSilgiCLI, updateRuntimeStorage, useRuntime, useSilgi, useSilgiCLI, useSilgiStorage };
package/dist/index.mjs CHANGED
@@ -1,16 +1,22 @@
1
- export { SilgiError, SilgiHttpEvent, autoImportTypes, createError, createEventStream, createMiddleware, createResolver, createSchema, createService, createShared, createSilgi, createStorage, createWebSocket, deepMergeObjects, defineServiceSetup, getEvent, getEventContext, getUrlPrefix, getWebsocket, handleResponse, handler, isError, kHandled, kNotFound, middleware, replaceRuntimeValues, silgiCtx, silgiFetch, storageMount, tryUseSilgi, updateRuntimeStorage, useRuntime, useSilgi, useSilgiStorage } from './core/index.mjs';
2
- export { s as silgiCLICtx, t as tryUseSilgiCLI, u as useSilgiCLI } from './_chunks/silgiApp.mjs';
3
- import 'node:async_hooks';
4
- import 'unctx';
5
- import '@standard-community/standard-json';
6
- import 'consola';
7
- import 'defu';
8
- import 'hookable';
9
- import 'rou3';
10
- import 'silgi/kit';
11
- import 'silgi/runtime';
12
- import 'node:buffer';
13
- import 'klona';
14
- import 'unstorage';
15
- import 'std-env';
16
- import 'srvx';
1
+ import { silgiCLICtx, tryUseSilgiCLI, useSilgiCLI } from "./core/silgiApp.mjs";
2
+ import { updateRuntimeStorage, useRuntime } from "./core/context.mjs";
3
+ import { silgiCtx, tryUseSilgi, useSilgi } from "./core/unctx.mjs";
4
+ import { SilgiError, createError, isError } from "./core/error.mjs";
5
+ import { replaceRuntimeValues } from "./core/utils/runtime.mjs";
6
+ import { createStorage, useSilgiStorage } from "./core/utils/storage.mjs";
7
+ import { createSilgi } from "./core/createSilgi.mjs";
8
+ import { SilgiHttpEvent } from "./core/event.mjs";
9
+ import { handleResponse, kHandled, kNotFound } from "./core/response.mjs";
10
+ import { createResolver$1 as createResolver, getUrlPrefix } from "./core/utils/resolver.mjs";
11
+ import { getWebsocket, handler, middleware, silgiFetch } from "./core/silgi.mjs";
12
+ import { storageMount } from "./core/storage.mjs";
13
+ import { createEventStream } from "./core/utils/event-stream.mjs";
14
+ import { getEvent, getEventContext } from "./core/utils/event.mjs";
15
+ import { deepMergeObjects } from "./core/utils/merge.mjs";
16
+ import { createMiddleware } from "./core/utils/middleware.mjs";
17
+ import { createSchema } from "./core/utils/schema.mjs";
18
+ import { createService, createWebSocket, defineServiceSetup } from "./core/utils/service.mjs";
19
+ import { createShared } from "./core/utils/shared.mjs";
20
+ import { autoImportTypes } from "./core/index.mjs";
21
+
22
+ export { SilgiError, SilgiHttpEvent, autoImportTypes, createError, createEventStream, createMiddleware, createResolver, createSchema, createService, createShared, createSilgi, createStorage, createWebSocket, deepMergeObjects, defineServiceSetup, getEvent, getEventContext, getUrlPrefix, getWebsocket, handleResponse, handler, isError, kHandled, kNotFound, middleware, replaceRuntimeValues, silgiCLICtx, silgiCtx, silgiFetch, storageMount, tryUseSilgi, tryUseSilgiCLI, updateRuntimeStorage, useRuntime, useSilgi, useSilgiCLI, useSilgiStorage };
@@ -0,0 +1,6 @@
1
+ import { Commands } from "silgi/types";
2
+
3
+ //#region src/kit/add/add-commands.d.ts
4
+ declare function addCommands(data: Commands | Commands[]): Promise<void>;
5
+ //#endregion
6
+ export { addCommands as addCommands$1 };
@@ -0,0 +1,12 @@
1
+ import { useSilgiCLI } from "../../core/silgiApp.mjs";
2
+ import { toArray } from "../utils.mjs";
3
+
4
+ //#region src/kit/add/add-commands.ts
5
+ async function addCommands(data) {
6
+ useSilgiCLI().hook("prepare:commands", (commads) => {
7
+ commads.push(...toArray(data));
8
+ });
9
+ }
10
+
11
+ //#endregion
12
+ export { addCommands };
@@ -0,0 +1,9 @@
1
+ import { SilgiCLIHooks } from "silgi/types";
2
+
3
+ //#region src/kit/add/add-core-file.d.ts
4
+ declare function addCoreFile(data: {
5
+ before?: SilgiCLIHooks["before:core.ts"];
6
+ after?: SilgiCLIHooks["after:core.ts"];
7
+ }): Promise<void>;
8
+ //#endregion
9
+ export { addCoreFile as addCoreFile$1 };
@@ -0,0 +1,11 @@
1
+ import { useSilgiCLI } from "../../core/silgiApp.mjs";
2
+
3
+ //#region src/kit/add/add-core-file.ts
4
+ async function addCoreFile(data) {
5
+ const silgi = useSilgiCLI();
6
+ if (data.before) silgi.hook("before:core.ts", data.before);
7
+ if (data.after) silgi.hook("after:core.ts", data.after);
8
+ }
9
+
10
+ //#endregion
11
+ export { addCoreFile };
@@ -0,0 +1,14 @@
1
+ import { GenImport } from "silgi/types";
2
+
3
+ //#region src/kit/add/add-imports.d.ts
4
+ declare function addImports(data?: {
5
+ imports?: GenImport[];
6
+ typeImports?: GenImport[];
7
+ }): {
8
+ genImports: GenImport[];
9
+ genTypeImports: GenImport[];
10
+ addImportItem: (data: GenImport | GenImport[]) => void;
11
+ addImportItemType: (data: GenImport | GenImport[]) => void;
12
+ };
13
+ //#endregion
14
+ export { addImports as addImports$1 };
@@ -0,0 +1,56 @@
1
+ import { toArray } from "silgi/kit";
2
+
3
+ //#region src/kit/add/add-imports.ts
4
+ function addImports$1(data) {
5
+ const genImports = [...data?.imports ?? []];
6
+ const genTypeImports = [...data?.typeImports ?? []];
7
+ function addImportItem(data$1) {
8
+ for (const item of toArray(data$1)) {
9
+ const isSpecifier = genImports.some((i) => i.specifier === item.specifier);
10
+ if (isSpecifier) {
11
+ const index = genImports.findIndex((i) => i.specifier === item.specifier);
12
+ if (index !== -1 && Array.isArray(genImports[index]?.imports)) {
13
+ genImports[index].imports ??= [];
14
+ genImports[index].imports.push(...toArray(item.imports));
15
+ } else if (index !== -1) genImports[index].imports = item.imports;
16
+ } else genImports.push({
17
+ specifier: item.specifier,
18
+ imports: item.imports,
19
+ options: item.options
20
+ });
21
+ }
22
+ }
23
+ function addImportItemType(data$1) {
24
+ for (const item of toArray(data$1)) {
25
+ const isSpecifier = genTypeImports.some((i) => i.specifier === item.specifier);
26
+ if (isSpecifier) {
27
+ const index = genTypeImports.findIndex((i) => i.specifier === item.specifier);
28
+ if (index !== -1 && genTypeImports[index] && Array.isArray(genTypeImports[index].imports)) {
29
+ genTypeImports[index].imports ??= [];
30
+ const newImports = toArray(item.imports);
31
+ for (const newImport of newImports) {
32
+ const isDuplicate = genTypeImports[index].imports.some((existingImport) => {
33
+ if (typeof existingImport === "string" && typeof newImport === "string") return existingImport === newImport;
34
+ else if (typeof existingImport === "object" && typeof newImport === "object") return existingImport.name === newImport.name && existingImport.as === newImport.as;
35
+ return false;
36
+ });
37
+ if (!isDuplicate) genTypeImports[index].imports.push(newImport);
38
+ }
39
+ } else if (index !== -1 && genTypeImports[index]) genTypeImports[index].imports = item.imports;
40
+ } else genTypeImports.push({
41
+ specifier: item.specifier,
42
+ imports: item.imports,
43
+ options: item.options
44
+ });
45
+ }
46
+ }
47
+ return {
48
+ genImports,
49
+ genTypeImports,
50
+ addImportItem,
51
+ addImportItemType
52
+ };
53
+ }
54
+
55
+ //#endregion
56
+ export { addImports$1 as addImports };
@@ -0,0 +1,14 @@
1
+ //#region src/kit/add/add-npm.d.ts
2
+ declare function addNPMPackage(data: {
3
+ name: string;
4
+ version?: string;
5
+ isDev?: boolean;
6
+ when?: boolean;
7
+ }[] | {
8
+ name: string;
9
+ version?: string;
10
+ isDev?: boolean;
11
+ when?: boolean;
12
+ }): Promise<void>;
13
+ //#endregion
14
+ export { addNPMPackage as addNPMPackage$1 };
@@ -0,0 +1,23 @@
1
+ import { useSilgiCLI } from "../../core/silgiApp.mjs";
2
+ import { toArray } from "../utils.mjs";
3
+ import { execSync } from "node:child_process";
4
+
5
+ //#region src/kit/add/add-npm.ts
6
+ const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
7
+ async function addNPMPackage(data) {
8
+ const silgi = useSilgiCLI();
9
+ if (silgi.options.commandType !== "install") return;
10
+ for (const item of toArray(data)) {
11
+ if (item.when === false) continue;
12
+ const getPackageVersion = execSync(`pnpm info ${item.name} version`, { encoding: "utf-8" });
13
+ silgi.logger.withTag("add-npm").success("Checking package version", item.name, getPackageVersion.trim());
14
+ let version = item.version || getPackageVersion.trim();
15
+ version = `^${version}`;
16
+ if (item.isDev) silgi.options.installPackages.devDependencies[item.name] = version;
17
+ else silgi.options.installPackages.dependencies[item.name] = version;
18
+ await delay(50);
19
+ }
20
+ }
21
+
22
+ //#endregion
23
+ export { addNPMPackage };
@@ -0,0 +1,28 @@
1
+ import { PresetName } from "silgi/presets";
2
+ import { DefineFrameworkOptions } from "silgi/types";
3
+
4
+ //#region src/kit/define.d.ts
5
+
6
+ /**
7
+ * Define a framework handler with proper type safety using a fluent API
8
+ *
9
+ * @param preset The framework preset to use
10
+ * @example
11
+ * ```ts
12
+ * const h3Handler = defineFramework('h3').build(async (options) => {
13
+ * // Type-safe access to h3 router
14
+ * const router = options.framework
15
+ * // Implementation here with async/await support
16
+ * await someAsyncOperation()
17
+ * })
18
+ * ```
19
+ */
20
+ declare function defineFramework<T extends PresetName>(preset: T): {
21
+ /**
22
+ * Build the framework handler
23
+ * @param callback The callback function that will receive typed options (can be async)
24
+ */
25
+ build(callback: (options: DefineFrameworkOptions<T>) => void | Promise<void>): (options: DefineFrameworkOptions<T>) => Promise<void>;
26
+ };
27
+ //#endregion
28
+ export { defineFramework as defineFramework$1 };
@@ -0,0 +1,25 @@
1
+ //#region src/kit/define.ts
2
+ /**
3
+ * Define a framework handler with proper type safety using a fluent API
4
+ *
5
+ * @param preset The framework preset to use
6
+ * @example
7
+ * ```ts
8
+ * const h3Handler = defineFramework('h3').build(async (options) => {
9
+ * // Type-safe access to h3 router
10
+ * const router = options.framework
11
+ * // Implementation here with async/await support
12
+ * await someAsyncOperation()
13
+ * })
14
+ * ```
15
+ */
16
+ function defineFramework(preset) {
17
+ return { build(callback) {
18
+ return async function handler(options) {
19
+ await callback(options);
20
+ };
21
+ } };
22
+ }
23
+
24
+ //#endregion
25
+ export { defineFramework };
@@ -0,0 +1,6 @@
1
+ import { SilgiCLI } from "silgi/types";
2
+
3
+ //#region src/kit/errors.d.ts
4
+ declare function hasError(type: SilgiCLI["errors"][0]["type"], silgi?: SilgiCLI): boolean;
5
+ //#endregion
6
+ export { hasError as hasError$1 };
@@ -0,0 +1,11 @@
1
+ import { tryUseSilgiCLI } from "silgi";
2
+
3
+ //#region src/kit/errors.ts
4
+ function hasError(type, silgi) {
5
+ silgi = silgi ?? tryUseSilgiCLI() ?? void 0;
6
+ if (silgi && silgi.errors.some((error) => error.type === type)) return true;
7
+ return false;
8
+ }
9
+
10
+ //#endregion
11
+ export { hasError };
@@ -0,0 +1,11 @@
1
+ //#region src/kit/esm.d.ts
2
+ declare function directoryToURL(dir: string): URL;
3
+ /**
4
+ * Resolve a module from a given root path using an algorithm patterned on
5
+ * the upcoming `import.meta.resolve`. It returns a file URL
6
+ *
7
+ * @internal
8
+ */
9
+ declare function tryResolveModule(id: string, url?: string | string[]): Promise<string | undefined>;
10
+ //#endregion
11
+ export { directoryToURL as directoryToURL$1, tryResolveModule as tryResolveModule$1 };
@@ -0,0 +1,21 @@
1
+ import { resolvePath } from "mlly";
2
+ import { pathToFileURL } from "node:url";
3
+
4
+ //#region src/kit/esm.ts
5
+ function directoryToURL(dir) {
6
+ return pathToFileURL(`${dir}/`);
7
+ }
8
+ /**
9
+ * Resolve a module from a given root path using an algorithm patterned on
10
+ * the upcoming `import.meta.resolve`. It returns a file URL
11
+ *
12
+ * @internal
13
+ */
14
+ async function tryResolveModule(id, url = import.meta.url) {
15
+ try {
16
+ return await resolvePath(id, { url });
17
+ } catch {}
18
+ }
19
+
20
+ //#endregion
21
+ export { directoryToURL, tryResolveModule };
@@ -0,0 +1,7 @@
1
+ import { Buffer } from "node:buffer";
2
+
3
+ //#region src/kit/fs.d.ts
4
+ declare function writeFile(file: string, contents: Buffer | string, log?: boolean): Promise<void>;
5
+ declare function isDirectory(path: string): Promise<boolean>;
6
+ //#endregion
7
+ export { isDirectory as isDirectory$1, writeFile as writeFile$1 };
@@ -0,0 +1,23 @@
1
+ import { prettyPath } from "./path.mjs";
2
+ import { dirname } from "pathe";
3
+ import { useSilgiCLI } from "silgi";
4
+ import fsp from "node:fs/promises";
5
+
6
+ //#region src/kit/fs.ts
7
+ async function writeFile$1(file, contents, log = false) {
8
+ const silgi = useSilgiCLI();
9
+ if (silgi.errors.length) return;
10
+ await fsp.mkdir(dirname(file), { recursive: true });
11
+ await fsp.writeFile(file, contents, typeof contents === "string" ? "utf8" : void 0);
12
+ if (log) silgi.logger.info("Generated", prettyPath(file));
13
+ }
14
+ async function isDirectory(path) {
15
+ try {
16
+ return (await fsp.stat(path)).isDirectory();
17
+ } catch {
18
+ return false;
19
+ }
20
+ }
21
+
22
+ //#endregion
23
+ export { isDirectory, writeFile$1 as writeFile };
@@ -0,0 +1,27 @@
1
+ //#region src/kit/function-utils.d.ts
2
+ /**
3
+ * Interface for function call configurations
4
+ */
5
+ interface FunctionConfig {
6
+ name: string;
7
+ args: any[];
8
+ }
9
+ declare function createFunctionConfigs(configs: FunctionConfig[]): FunctionConfig[];
10
+ /**
11
+ * Generic utility function to create function call configurations
12
+ * @param name Function name
13
+ * @param args Function arguments (default empty object)
14
+ * @returns Structured function configuration
15
+ */
16
+ declare function createFunction(name: string, args?: any): FunctionConfig;
17
+ /**
18
+ * Format function calls with consistent indentation for code generation
19
+ * @param configs Array of function configurations
20
+ * @param indentation Spaces for indentation (default 4)
21
+ * @param specialVars Array of variable names that should be treated as code references not strings
22
+ * @param deduplicateArgs Whether to extract duplicate arguments into variables (default false)
23
+ * @returns Formatted string of function calls
24
+ */
25
+ declare function formatFunctions(configs: FunctionConfig[], indentation?: number, specialVars?: string[], deduplicateArgs?: boolean): string;
26
+ //#endregion
27
+ export { FunctionConfig, createFunction as createFunction$1, createFunctionConfigs as createFunctionConfigs$1, formatFunctions as formatFunctions$1 };
@@ -0,0 +1,75 @@
1
+ //#region src/kit/function-utils.ts
2
+ function createFunctionConfigs(configs) {
3
+ return configs;
4
+ }
5
+ /**
6
+ * Generic utility function to create function call configurations
7
+ * @param name Function name
8
+ * @param args Function arguments (default empty object)
9
+ * @returns Structured function configuration
10
+ */
11
+ function createFunction(name, args = {}) {
12
+ return {
13
+ name,
14
+ args: Object.keys(args).length > 0 ? [args] : []
15
+ };
16
+ }
17
+ /**
18
+ * Format function calls with consistent indentation for code generation
19
+ * @param configs Array of function configurations
20
+ * @param indentation Spaces for indentation (default 4)
21
+ * @param specialVars Array of variable names that should be treated as code references not strings
22
+ * @param deduplicateArgs Whether to extract duplicate arguments into variables (default false)
23
+ * @returns Formatted string of function calls
24
+ */
25
+ function formatFunctions(configs, indentation = 4, specialVars = [], deduplicateArgs = false) {
26
+ const indent = " ".repeat(indentation);
27
+ const argMap = new Map();
28
+ const argVarDeclarations = [];
29
+ let argCounter = 0;
30
+ if (deduplicateArgs) configs.forEach((config) => {
31
+ if (config.args.length > 0) {
32
+ const argStr = JSON.stringify(config.args[0]);
33
+ if (!argMap.has(argStr) && argStr.length > 20) {
34
+ const varName = `args${argCounter++}`;
35
+ argMap.set(argStr, varName);
36
+ argVarDeclarations.push(`const ${varName} = ${processArgString(argStr, specialVars, indentation)}`);
37
+ }
38
+ }
39
+ });
40
+ function processArgString(argStr, specialVars$1, indentLevel) {
41
+ const parsed = JSON.parse(argStr);
42
+ const prettified = formatObjectWithIndentation(parsed, indentLevel);
43
+ let processed = prettified;
44
+ specialVars$1.forEach((varName) => {
45
+ processed = processed.replace(new RegExp(`"${varName}"`, "g"), varName);
46
+ });
47
+ return processed;
48
+ }
49
+ function formatObjectWithIndentation(obj, indentLevel) {
50
+ const baseIndent = " ".repeat(indentLevel);
51
+ const innerIndent = " ".repeat(indentLevel + 2);
52
+ if (typeof obj !== "object" || obj === null) return JSON.stringify(obj);
53
+ if (Array.isArray(obj)) {
54
+ if (obj.length === 0) return "[]";
55
+ const items = obj.map((item) => `${innerIndent}${formatObjectWithIndentation(item, indentLevel + 2)}`).join(",\n");
56
+ return `[\n${items}\n${baseIndent}]`;
57
+ }
58
+ if (Object.keys(obj).length === 0) return "{}";
59
+ const entries = Object.entries(obj).map(([key, value]) => {
60
+ return `${innerIndent}${key}: ${formatObjectWithIndentation(value, indentLevel + 2)}`;
61
+ }).join(",\n");
62
+ return `{\n${entries}\n${baseIndent}}`;
63
+ }
64
+ const formattedCalls = configs.map((config) => {
65
+ if (config.args.length === 0) return `${indent}${config.name}()`;
66
+ const argStr = JSON.stringify(config.args[0]);
67
+ if (deduplicateArgs && argMap.has(argStr) && argStr.length > 20) return `${indent}${config.name}(${argMap.get(argStr)})`;
68
+ else return `${indent}${config.name}(${processArgString(argStr, specialVars, indentation)})`;
69
+ }).join(",\n");
70
+ if (deduplicateArgs && argVarDeclarations.length > 0) return `${argVarDeclarations.join(";\n")};\n\n${formattedCalls}`;
71
+ return formattedCalls;
72
+ }
73
+
74
+ //#endregion
75
+ export { createFunction, createFunctionConfigs, formatFunctions };
@@ -0,0 +1,5 @@
1
+ //#region src/kit/gen.d.ts
2
+ declare function genEnsureSafeVar(name: string | any): string;
3
+ declare function getAllEntries(obj: object): [string, any][];
4
+ //#endregion
5
+ export { genEnsureSafeVar as genEnsureSafeVar$1, getAllEntries as getAllEntries$1 };
@@ -0,0 +1,26 @@
1
+ import { genObjectFromRaw, genObjectFromRawEntries, genObjectFromValues, genString } from "knitwork";
2
+
3
+ //#region src/kit/gen.ts
4
+ const reservedCode = new Set([
5
+ "process",
6
+ "global",
7
+ "runtime",
8
+ "runtimeConfig"
9
+ ]);
10
+ function genEnsureSafeVar(name) {
11
+ if (typeof name !== "string") return genString(name);
12
+ for (const reserved of reservedCode) if (name === reserved || name.startsWith(`${reserved}.`)) return name;
13
+ return genString(name);
14
+ }
15
+ function getAllEntries(obj) {
16
+ return Object.entries(obj).map(([key, value]) => {
17
+ if (typeof value === "function") return [key, genObjectFromRaw(value)];
18
+ if (typeof value === "string") return [key, genEnsureSafeVar(value)];
19
+ if (typeof value === "object" && value !== null) if (Array.isArray(value)) return [key, genObjectFromValues(value.map((item) => typeof item === "object" && item !== null ? genObjectFromRawEntries(getAllEntries(item)) : item))];
20
+ else return [key, genObjectFromRawEntries(getAllEntries(value))];
21
+ return [key, value];
22
+ });
23
+ }
24
+
25
+ //#endregion
26
+ export { genEnsureSafeVar, getAllEntries };
@@ -0,0 +1,4 @@
1
+ //#region src/kit/hash.d.ts
2
+ declare function hash(data: any): string;
3
+ //#endregion
4
+ export { hash as hash$1 };
@@ -0,0 +1,10 @@
1
+ import { camelCase } from "scule";
2
+ import { hash } from "ohash";
3
+
4
+ //#region src/kit/hash.ts
5
+ function hash$1(data) {
6
+ return `_${camelCase(hash(data))}`;
7
+ }
8
+
9
+ //#endregion
10
+ export { hash$1 as hash };