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,106 @@
1
+ import { hasProp } from "./utils/internal/object.mjs";
2
+ import { sanitizeStatusCode, sanitizeStatusMessage } from "./utils/sanitize.mjs";
3
+ import consola from "consola";
4
+ import { isDevelopment } from "std-env";
5
+
6
+ //#region src/core/error.ts
7
+ /**
8
+ * Silgi Runtime Error
9
+ * @class
10
+ * @extends Error
11
+ * @property {number} statusCode - An integer indicating the HTTP response status code.
12
+ * @property {string} statusMessage - A string representing the HTTP status message.
13
+ * @property {boolean} fatal - Indicates if the error is a fatal error.
14
+ * @property {boolean} unhandled - Indicates if the error was unhandled and auto-captured.
15
+ * @property {DataT} data - An extra data that will be included in the response.
16
+ * This can be used to pass additional information about the error.
17
+ */
18
+ var SilgiError = class extends Error {
19
+ static __silgi_error__ = true;
20
+ statusCode = 500;
21
+ fatal = false;
22
+ unhandled = false;
23
+ statusMessage;
24
+ data;
25
+ cause;
26
+ constructor(message, opts = {}) {
27
+ super(message, opts);
28
+ if (opts.cause && !this.cause) this.cause = opts.cause;
29
+ if (isDevelopment && opts.cause && opts.cause instanceof Error && opts.cause.stack && this.stack) {
30
+ this.stack += `\nCaused by: ${opts.cause.stack}`;
31
+ consola.warn(opts.cause);
32
+ }
33
+ }
34
+ toJSON() {
35
+ const obj = {
36
+ message: this.message,
37
+ statusCode: sanitizeStatusCode(this.statusCode, 500)
38
+ };
39
+ if (this.statusMessage) obj.statusMessage = sanitizeStatusMessage(this.statusMessage);
40
+ if (this.data !== void 0) obj.data = this.data;
41
+ return obj;
42
+ }
43
+ };
44
+ /**
45
+ * Creates a new `Error` that can be used to handle both internal and runtime errors.
46
+ *
47
+ * @param input {string | (Partial<SilgiError> & { status?: number; statusText?: string })} - The error message or an object containing error properties.
48
+ * If a string is provided, it will be used as the error `message`.
49
+ *
50
+ * @example
51
+ * // String error where `statusCode` defaults to `500`
52
+ * throw createError("An error occurred");
53
+ * // Object error
54
+ * throw createError({
55
+ * statusCode: 400,
56
+ * statusMessage: "Bad Request",
57
+ * message: "Invalid input",
58
+ * data: { field: "email" }
59
+ * });
60
+ *
61
+ *
62
+ * @return {SilgiError} - An instance of SilgiError.
63
+ *
64
+ * @remarks
65
+ * - Typically, `message` contains a brief, human-readable description of the error, while `statusMessage` is specific to HTTP responses and describes
66
+ * the status text related to the response status code.
67
+ * - In a client-server context, using a short `statusMessage` is recommended because it can be accessed on the client side. Otherwise, a `message`
68
+ * passed to `createError` on the server will not propagate to the client.
69
+ * - Consider avoiding putting dynamic user input in the `message` to prevent potential security issues.
70
+ */
71
+ function createError(input) {
72
+ if (typeof input === "string") return new SilgiError(input);
73
+ const cause = input.cause;
74
+ const err = new SilgiError(input.message ?? input.statusMessage ?? "", { cause: cause || input });
75
+ if (hasProp(input, "stack")) try {
76
+ Object.defineProperty(err, "stack", { get() {
77
+ return input.stack;
78
+ } });
79
+ } catch {
80
+ try {
81
+ err.stack = input.stack;
82
+ } catch {}
83
+ }
84
+ if (input.data) err.data = input.data;
85
+ const statusCode = input.statusCode ?? input.status ?? cause?.statusCode ?? cause?.status;
86
+ if (typeof statusCode === "number") err.statusCode = sanitizeStatusCode(statusCode);
87
+ const statusMessage = input.statusMessage ?? input.statusText ?? cause?.statusMessage ?? cause?.statusText;
88
+ if (statusMessage) err.statusMessage = sanitizeStatusMessage(statusMessage);
89
+ const fatal = input.fatal ?? cause?.fatal;
90
+ if (fatal !== void 0) err.fatal = fatal;
91
+ const unhandled = input.unhandled ?? cause?.unhandled;
92
+ if (unhandled !== void 0) err.unhandled = unhandled;
93
+ return err;
94
+ }
95
+ /**
96
+ * Checks if the given input is an instance of SilgiError.
97
+ *
98
+ * @param input {*} - The input to check.
99
+ * @return {boolean} - Returns true if the input is an instance of SilgiError, false otherwise.
100
+ */
101
+ function isError(input) {
102
+ return input?.constructor?.__silgi_error__ === true;
103
+ }
104
+
105
+ //#endregion
106
+ export { SilgiError, createError, isError };
@@ -0,0 +1,26 @@
1
+ import { ServerRequest, ServerRuntimeContext } from "srvx";
2
+ import { SilgiEvent, SilgiRuntimeContext } from "silgi/types";
3
+
4
+ //#region src/core/event.d.ts
5
+ declare class SilgiHttpEvent implements SilgiEvent {
6
+ static __is_event__: boolean;
7
+ req: ServerRequest;
8
+ url: URL;
9
+ context: SilgiRuntimeContext;
10
+ _res?: SilgiEventResponse;
11
+ constructor(req: ServerRequest, context?: SilgiRuntimeContext);
12
+ _chain: Promise<unknown> | undefined;
13
+ [x: string]: unknown;
14
+ get res(): SilgiEventResponse;
15
+ get runtime(): ServerRuntimeContext | undefined;
16
+ toString(): string;
17
+ toJSON(): string;
18
+ }
19
+ declare class SilgiEventResponse {
20
+ status?: number;
21
+ statusText?: string;
22
+ _headers?: Headers;
23
+ get headers(): Headers;
24
+ }
25
+ //#endregion
26
+ export { SilgiHttpEvent as SilgiHttpEvent$1 };
@@ -0,0 +1,44 @@
1
+ import { EmptyObject } from "./utils/internal/obj.mjs";
2
+ import { FastURL } from "srvx";
3
+
4
+ //#region src/core/event.ts
5
+ var SilgiHttpEvent = class {
6
+ static __is_event__ = true;
7
+ req;
8
+ url;
9
+ context;
10
+ _res;
11
+ constructor(req, context) {
12
+ this.context = context || new EmptyObject();
13
+ this.context.protocol = "HTTP";
14
+ this.req = req;
15
+ const _url = req._url;
16
+ this.url = _url && _url instanceof URL ? _url : new FastURL(req.url);
17
+ }
18
+ _chain;
19
+ get res() {
20
+ if (!this._res) this._res = new SilgiEventResponse();
21
+ return this._res;
22
+ }
23
+ get runtime() {
24
+ return this.req.runtime;
25
+ }
26
+ toString() {
27
+ return `[${this.req.method}] ${this.req.url}`;
28
+ }
29
+ toJSON() {
30
+ return this.toString();
31
+ }
32
+ };
33
+ var SilgiEventResponse = class {
34
+ status;
35
+ statusText;
36
+ _headers;
37
+ get headers() {
38
+ if (!this._headers) this._headers = new Headers();
39
+ return this._headers;
40
+ }
41
+ };
42
+
43
+ //#endregion
44
+ export { SilgiHttpEvent };
@@ -1,317 +1,25 @@
1
- import { SilgiRuntimeConfig, SilgiConfig, Silgi, SilgiEvent, SilgiRuntimeContext, WebSocketOptions, SilgiSchema, RouteEntry, CustomRequestInit, SilgiCLI, SilgiStorageBase, MergeAll, Resolvers, SilgiURL, BaseMethodSchema, HTTPMethod, StandardSchemaV1, ServiceSetup, WebSocketServiceSetup, Routers, SilgiRuntimeShareds, StorageConfig } from 'silgi/types';
2
- import { ServerRequest, ServerRuntimeContext } from 'srvx';
3
- import { UseContext } from 'unctx';
4
- import { Storage, StorageValue } from 'unstorage';
5
- export { c as createMiddleware } from '../shared/silgi.DTwQEdSr.mjs';
6
-
7
- declare function updateRuntimeStorage(runtime: any): void;
8
- /**
9
- * Get access to silgi instance.
10
- *
11
- * Throws an error if silgi instance is unavailable.
12
- * @example
13
- * ```js
14
- * const runtime = useRuntime()
15
- * ```
16
- */
17
- declare function useRuntime(): SilgiRuntimeConfig;
18
-
19
- declare function createSilgi(config: SilgiConfig): Promise<Silgi>;
20
-
21
- /**
22
- * LICENSE: MIT
23
- * Credits:
24
- * - H3 - https://github.com/h3js/h3
25
- */
26
- /**
27
- * Silgi Runtime Error
28
- * @class
29
- * @extends Error
30
- * @property {number} statusCode - An integer indicating the HTTP response status code.
31
- * @property {string} statusMessage - A string representing the HTTP status message.
32
- * @property {boolean} fatal - Indicates if the error is a fatal error.
33
- * @property {boolean} unhandled - Indicates if the error was unhandled and auto-captured.
34
- * @property {DataT} data - An extra data that will be included in the response.
35
- * This can be used to pass additional information about the error.
36
- */
37
- declare class SilgiError<DataT = unknown> extends Error {
38
- static __silgi_error__: boolean;
39
- statusCode: number;
40
- fatal: boolean;
41
- unhandled: boolean;
42
- statusMessage?: string;
43
- data?: DataT;
44
- cause?: unknown;
45
- constructor(message: string, opts?: {
46
- cause?: unknown;
47
- });
48
- toJSON(): Pick<SilgiError<DataT>, 'message' | 'statusCode' | 'statusMessage' | 'data'>;
49
- }
50
- /**
51
- * Creates a new `Error` that can be used to handle both internal and runtime errors.
52
- *
53
- * @param input {string | (Partial<SilgiError> & { status?: number; statusText?: string })} - The error message or an object containing error properties.
54
- * If a string is provided, it will be used as the error `message`.
55
- *
56
- * @example
57
- * // String error where `statusCode` defaults to `500`
58
- * throw createError("An error occurred");
59
- * // Object error
60
- * throw createError({
61
- * statusCode: 400,
62
- * statusMessage: "Bad Request",
63
- * message: "Invalid input",
64
- * data: { field: "email" }
65
- * });
66
- *
67
- *
68
- * @return {SilgiError} - An instance of SilgiError.
69
- *
70
- * @remarks
71
- * - Typically, `message` contains a brief, human-readable description of the error, while `statusMessage` is specific to HTTP responses and describes
72
- * the status text related to the response status code.
73
- * - In a client-server context, using a short `statusMessage` is recommended because it can be accessed on the client side. Otherwise, a `message`
74
- * passed to `createError` on the server will not propagate to the client.
75
- * - Consider avoiding putting dynamic user input in the `message` to prevent potential security issues.
76
- */
77
- declare function createError<DataT = unknown>(input: string | (Partial<SilgiError<DataT>> & {
78
- status?: number;
79
- statusText?: string;
80
- })): SilgiError<DataT>;
81
- /**
82
- * Checks if the given input is an instance of SilgiError.
83
- *
84
- * @param input {*} - The input to check.
85
- * @return {boolean} - Returns true if the input is an instance of SilgiError, false otherwise.
86
- */
87
- declare function isError<DataT = unknown>(input: any): input is SilgiError<DataT>;
88
-
89
- declare class SilgiHttpEvent implements SilgiEvent {
90
- static __is_event__: boolean;
91
- req: ServerRequest;
92
- url: URL;
93
- context: SilgiRuntimeContext;
94
- _res?: SilgiEventResponse;
95
- constructor(req: ServerRequest, context?: SilgiRuntimeContext);
96
- _chain: Promise<unknown> | undefined;
97
- [x: string]: unknown;
98
- get res(): SilgiEventResponse;
99
- get runtime(): ServerRuntimeContext | undefined;
100
- toString(): string;
101
- toJSON(): string;
102
- }
103
- declare class SilgiEventResponse {
104
- status?: number;
105
- statusText?: string;
106
- _headers?: Headers;
107
- get headers(): Headers;
108
- }
109
-
110
- type MaybePromise<T> = T | Promise<T>;
111
- interface SilgiHandlerConfig {
112
- debug?: boolean;
113
- onError?: (error: SilgiError, event: SilgiEvent) => MaybePromise<void | unknown>;
114
- onRequest?: (event: SilgiEvent) => MaybePromise<void>;
115
- onBeforeResponse?: (event: SilgiEvent, response: Response | PreparedResponse) => MaybePromise<void>;
116
- }
117
- type PreparedResponse = ResponseInit & {
118
- body?: BodyInit | null;
119
- };
120
- declare const kNotFound: symbol;
121
- declare const kHandled: symbol;
122
- declare function handleResponse(val: unknown, event: SilgiEvent, config: SilgiHandlerConfig): Response | Promise<Response>;
123
-
124
- /**
125
- * Fetch API for Silgi framework
126
- */
127
- declare function silgiFetch<Schema extends SilgiSchema = SilgiSchema, Method extends RouteEntry<Schema>['method'] = RouteEntry<Schema>['method'], Path extends Extract<RouteEntry<Schema>, {
128
- method: Method;
129
- }>['path'] = Extract<RouteEntry<Schema>, {
130
- method: Method;
131
- }>['path'], Resolved extends boolean = true, HiddenParameters extends boolean = true>(_request: Path, options?: CustomRequestInit<Schema, Method, Path, Resolved, HiddenParameters>, context?: SilgiRuntimeContext): Promise<Response | Promise<Response>>;
132
- /**
133
- * Fetch API for Silgi framework using standard Request options
134
- */
135
- declare function silgiFetch(_request: Request | URL, options?: RequestInit & {
136
- pathParams?: Record<string, any>;
137
- }, context?: SilgiRuntimeContext): Promise<Response | Promise<Response>>;
138
- declare function middleware(event: SilgiEvent): Promise<any>;
139
- declare function handler(event: SilgiEvent): Promise<any>;
140
- declare function getWebsocket(silgi?: Silgi): WebSocketOptions;
141
-
142
- declare const silgiCLICtx: UseContext<SilgiCLI>;
143
- declare function useSilgiCLI(): SilgiCLI;
144
- declare function tryUseSilgiCLI(): SilgiCLI | null;
145
-
146
- declare function storageMount<T extends Storage = Storage>(silgi?: Silgi): (base: keyof SilgiStorageBase, driver: Parameters<Storage['mount']>[1]) => T;
147
-
148
- declare const silgiCtx: UseContext<Silgi>;
149
- declare function useSilgi(): Silgi;
150
- /**
151
- * Get access to Nuxt instance.
152
- *
153
- * Returns null if Nuxt instance is unavailable.
154
- * @example
155
- * ```js
156
- * const silgi = tryUseSilgi()
157
- * if (silgi) {
158
- * // Do something
159
- * }
160
- * ```
161
- */
162
- declare function tryUseSilgi(): Silgi | null;
163
-
164
- /**
165
- * A helper class for [server sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#event_stream_format)
166
- */
167
- declare class EventStream {
168
- private readonly _event;
169
- private readonly _transformStream;
170
- private readonly _writer;
171
- private readonly _encoder;
172
- private _writerIsClosed;
173
- private _paused;
174
- private _unsentData;
175
- private _disposed;
176
- private _handled;
177
- constructor(event: SilgiEvent, opts?: EventStreamOptions);
178
- /**
179
- * Publish new event(s) for the client
180
- */
181
- push(message: string): Promise<void>;
182
- push(message: string[]): Promise<void>;
183
- push(message: EventStreamMessage): Promise<void>;
184
- push(message: EventStreamMessage[]): Promise<void>;
185
- private _sendEvent;
186
- private _sendEvents;
187
- pause(): void;
188
- get isPaused(): boolean;
189
- resume(): Promise<void>;
190
- flush(): Promise<void>;
191
- /**
192
- * Close the stream and the connection if the stream is being sent to the client
193
- */
194
- close(): Promise<void>;
195
- /**
196
- * Triggers callback when the writable stream is closed.
197
- * It is also triggered after calling the `close()` method.
198
- */
199
- onClosed(cb: () => any): void;
200
- send(): Promise<BodyInit>;
201
- }
202
-
203
- interface EventStreamOptions {
204
- /**
205
- * Automatically close the writable stream when the request is closed
206
- *
207
- * Default is `true`
208
- */
209
- autoclose?: boolean;
210
- }
211
- /**
212
- * See https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#fields
213
- */
214
- interface EventStreamMessage {
215
- id?: string;
216
- event?: string;
217
- retry?: number;
218
- data: string;
219
- }
220
- /**
221
- * Initialize an EventStream instance for creating [server sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)
222
- *
223
- * @experimental This function is experimental and might be unstable in some environments.
224
- *
225
- * @example
226
- *
227
- * ```ts
228
- * import { createEventStream, sendEventStream } from "h3";
229
- *
230
- * app.get("/sse", (event) => {
231
- * const eventStream = createEventStream(event);
232
- *
233
- * // Send a message every second
234
- * const interval = setInterval(async () => {
235
- * await eventStream.push("Hello world");
236
- * }, 1000);
237
- *
238
- * // cleanup the interval and close the stream when the connection is terminated
239
- * eventStream.onClosed(async () => {
240
- * console.log("closing SSE...");
241
- * clearInterval(interval);
242
- * await eventStream.close();
243
- * });
244
- *
245
- * return eventStream.send();
246
- * });
247
- * ```
248
- */
249
- declare function createEventStream(event: SilgiEvent, opts?: EventStreamOptions): EventStream;
250
-
251
- declare function getEvent<T extends SilgiEvent>(event?: SilgiEvent): T;
252
- declare function getEventContext<T extends SilgiRuntimeContext>(event?: SilgiEvent): T;
253
-
254
- /**
255
- * Merges multiple service definition objects into a single object.
256
- * Performs a complete deep merge of all service definition objects.
257
- * @template T - A tuple type representing the array of service definition objects to merge.
258
- * @param {T} schemas - An array of service definition objects created by `createSchema`.
259
- * @returns {MergeAll<T>} A single object containing all merged service definitions.
260
- */
261
- declare function deepMergeObjects<T extends readonly Record<string, any>[]>(schemas: [...T]): MergeAll<T>;
262
-
263
- declare function createResolver(resolver: Resolvers): Resolvers;
264
- declare function getUrlPrefix(path: string, method?: string): SilgiURL;
265
-
266
- /**
267
- * Recursively replaces values starting with 'runtime.' with their actual values from runtime config
268
- */
269
- declare function replaceRuntimeValues(obj: any, runtime: any): any;
270
-
271
- /**
272
- * Creates a type-safe API route schema definition.
273
- *
274
- * This utility function helps you define API schemas with proper typing for
275
- * input, output, path parameters, and query parameters.
276
- *
277
- * @template Key - API key
278
- * @template Schema - Schema definition type
279
- *
280
- * @param params - Schema configuration parameters
281
- * @param params.key - Unique key for the schema
282
- * @param params.setup - Schema definition for the specified methods
283
- * @returns Route schema object with complete type information
284
- *
285
- * @example
286
- * // Define a user API schema
287
- * const userSchema = createSchema({
288
- * key: '/api/v1/users',
289
- * setup: {
290
- * output: z.object({
291
- * users: z.array(z.object({ id: z.string(), name: z.string() }))
292
- * })
293
- * }
294
- * });
295
- */
296
- declare function createSchema<Key extends string, Schema extends BaseMethodSchema>(params: {
297
- key: Key;
298
- } & Schema): {
299
- [K in Key]: Schema;
300
- };
301
-
302
- /**
303
- * ServiceSetup tipinden oluşan bir yardımcı fonksiyon.
304
- * Tip güvenliğini artırmak için ServiceSetup objesini doğrudan döndürür.
305
- */
306
- declare function defineServiceSetup<Method extends HTTPMethod, Path extends keyof Routers, Input extends StandardSchemaV1 = StandardSchemaV1, Output extends StandardSchemaV1 = StandardSchemaV1, PathParams extends StandardSchemaV1 | undefined | never = undefined, QueryParams extends StandardSchemaV1 | undefined | never = undefined, Resolved extends boolean = false, HiddenParameters extends boolean = false>(setup: Omit<ServiceSetup<Method, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>, 'method' | 'path'>): Omit<ServiceSetup<Method, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>, 'method' | 'path'>;
307
- declare function createService<Path extends string, Method extends HTTPMethod, Input extends StandardSchemaV1 = StandardSchemaV1, Output extends StandardSchemaV1 = StandardSchemaV1, PathParams extends StandardSchemaV1 | undefined | never = undefined, QueryParams extends StandardSchemaV1 | undefined | never = undefined, Resolved extends boolean = false, HiddenParameters extends boolean = false>(params: ServiceSetup<Method, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>): Record<`http:${Method}:${Path}`, ServiceSetup<Method, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>>;
308
- declare function createWebSocket<Path extends string, Method extends HTTPMethod>(params: WebSocketServiceSetup<Method, Path>): Record<`websocket:${Method}:${Path}`, WebSocketServiceSetup<Method, Path>>;
309
-
310
- declare function createShared(shared: Partial<SilgiRuntimeShareds>): SilgiRuntimeShareds;
311
-
312
- declare function createStorage(silgi: Silgi): Promise<Storage<StorageValue>>;
313
- declare function useSilgiStorage<T extends StorageValue = StorageValue>(base?: StorageConfig<T>['base'] | (string & {})): Storage<T>;
314
-
1
+ import { updateRuntimeStorage$1 as updateRuntimeStorage, useRuntime$1 as useRuntime } from "./context.mjs";
2
+ import { createSilgi$1 as createSilgi } from "./createSilgi.mjs";
3
+ import { SilgiError$1 as SilgiError, createError$1 as createError, isError$1 as isError } from "./error.mjs";
4
+ import { SilgiHttpEvent$1 as SilgiHttpEvent } from "./event.mjs";
5
+ import { handleResponse$1 as handleResponse, kHandled$1 as kHandled, kNotFound$1 as kNotFound } from "./response.mjs";
6
+ import { getWebsocket$1 as getWebsocket, handler$1 as handler, middleware$1 as middleware, silgiFetch$1 as silgiFetch } from "./silgi.mjs";
7
+ import { silgiCLICtx$1 as silgiCLICtx, tryUseSilgiCLI$1 as tryUseSilgiCLI, useSilgiCLI$1 as useSilgiCLI } from "./silgiApp.mjs";
8
+ import { storageMount$1 as storageMount } from "./storage.mjs";
9
+ import { silgiCtx$1 as silgiCtx, tryUseSilgi$1 as tryUseSilgi, useSilgi$1 as useSilgi } from "./unctx.mjs";
10
+ import { createEventStream$1 as createEventStream } from "./utils/event-stream.mjs";
11
+ import { getEvent$1 as getEvent, getEventContext$1 as getEventContext } from "./utils/event.mjs";
12
+ import { deepMergeObjects$1 as deepMergeObjects } from "./utils/merge.mjs";
13
+ import { createMiddleware$1 as createMiddleware } from "./utils/middleware.mjs";
14
+ import { createResolver$3 as createResolver, getUrlPrefix$1 as getUrlPrefix } from "./utils/resolver.mjs";
15
+ import { replaceRuntimeValues$1 as replaceRuntimeValues } from "./utils/runtime.mjs";
16
+ import { createSchema$1 as createSchema } from "./utils/schema.mjs";
17
+ import { createService$1 as createService, createWebSocket$1 as createWebSocket, defineServiceSetup$1 as defineServiceSetup } from "./utils/service.mjs";
18
+ import { createShared$1 as createShared } from "./utils/shared.mjs";
19
+ import { createStorage$1 as createStorage, useSilgiStorage$1 as useSilgiStorage } from "./utils/storage.mjs";
20
+
21
+ //#region src/core/index.d.ts
22
+ // TODO: bunlari yinede destekle.
315
23
  declare const autoImportTypes: string[];
316
-
317
- 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 };
24
+ //#endregion
25
+ 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 };