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.
- package/dist/_virtual/rolldown_runtime.mjs +11 -0
- package/dist/build.d.mts +3 -11
- package/dist/build.mjs +4 -48
- package/dist/cli/build/build.mjs +17 -0
- package/dist/cli/build/dev.d.mts +9 -0
- package/dist/cli/build/dev.mjs +59 -0
- package/dist/cli/build/prepare.d.mts +6 -0
- package/dist/cli/build/prepare.mjs +15 -0
- package/dist/cli/commands/commands.mjs +90 -0
- package/dist/cli/commands/env.mjs +53 -0
- package/dist/cli/commands/init.mjs +84 -0
- package/dist/cli/commands/install.mjs +52 -0
- package/dist/cli/commands/prepare.mjs +65 -0
- package/dist/cli/commands/reset.mjs +46 -0
- package/dist/cli/commands/run.mjs +105 -0
- package/dist/cli/commands/watch.mjs +48 -0
- package/dist/cli/config/defaults.mjs +117 -0
- package/dist/cli/config/index.d.mts +3 -11
- package/dist/cli/config/index.mjs +4 -17
- package/dist/cli/config/loader.d.mts +6 -0
- package/dist/cli/config/loader.mjs +71 -0
- package/dist/cli/config/resolvers/compatibility.mjs +71 -0
- package/dist/cli/config/resolvers/imports.mjs +35 -0
- package/dist/cli/config/resolvers/paths.mjs +98 -0
- package/dist/cli/config/resolvers/storage.mjs +23 -0
- package/dist/cli/config/resolvers/url.mjs +9 -0
- package/dist/cli/config/types.d.mts +14 -0
- package/dist/cli/config/types.mjs +147 -0
- package/dist/cli/core/apiful.mjs +36 -0
- package/dist/cli/core/app.mjs +105 -0
- package/dist/cli/core/devServer.mjs +10 -0
- package/dist/cli/core/env.mjs +68 -0
- package/dist/cli/core/installPackage.mjs +60 -0
- package/dist/cli/core/runtimeConfig.mjs +70 -0
- package/dist/cli/core/scan.mjs +35 -0
- package/dist/cli/core/silgi.mjs +111 -0
- package/dist/cli/core/templates.mjs +38 -0
- package/dist/cli/framework/emptyFramework.mjs +7 -0
- package/dist/cli/framework/h3.mjs +55 -0
- package/dist/cli/framework/index.mjs +15 -0
- package/dist/cli/framework/nitro.mjs +24 -0
- package/dist/cli/framework/nuxt.mjs +10 -0
- package/dist/cli/index.d.mts +1 -1
- package/dist/cli/index.mjs +24 -27
- package/dist/cli/module/exportScan.mjs +180 -0
- package/dist/cli/module/install.mjs +49 -0
- package/dist/cli/module/scan.mjs +195 -0
- package/dist/cli/scan/prepareCommands.mjs +40 -0
- package/dist/cli/scan/prepareConfigs.mjs +33 -0
- package/dist/cli/scan/prepareCoreFile.mjs +118 -0
- package/dist/cli/scan/prepareScanFile.mjs +59 -0
- package/dist/cli/scan/prepareSchema.mjs +140 -0
- package/dist/cli/scan/scanExportFile.mjs +312 -0
- package/dist/cli/scan/writeCoreFile.mjs +22 -0
- package/dist/cli/scan/writeTypesAndFiles.mjs +72 -0
- package/dist/cli/utils/cancel.mjs +14 -0
- package/dist/cli/utils/common.mjs +15 -0
- package/dist/cli/utils/compatibility.mjs +33 -0
- package/dist/cli/utils/debug.mjs +11 -0
- package/dist/cli/utils/ignore.mjs +56 -0
- package/dist/cli/utils/readScanFile.mjs +58 -0
- package/dist/cli/utils/storage.mjs +23 -0
- package/dist/core/context.d.mts +30 -0
- package/dist/core/context.mjs +32 -0
- package/dist/core/createSilgi.d.mts +6 -0
- package/dist/core/createSilgi.mjs +152 -0
- package/dist/core/error.d.mts +65 -0
- package/dist/core/error.mjs +106 -0
- package/dist/core/event.d.mts +26 -0
- package/dist/core/event.mjs +44 -0
- package/dist/core/index.d.mts +24 -316
- package/dist/core/index.mjs +27 -1345
- package/dist/core/orchestrate.mjs +113 -0
- package/dist/core/response.d.mts +20 -0
- package/dist/core/response.mjs +105 -0
- package/dist/core/silgi.d.mts +19 -0
- package/dist/core/silgi.mjs +141 -0
- package/dist/core/silgiApp.d.mts +9 -0
- package/dist/core/silgiApp.mjs +23 -0
- package/dist/core/storage.d.mts +7 -0
- package/dist/core/storage.mjs +15 -0
- package/dist/core/unctx.d.mts +21 -0
- package/dist/core/unctx.mjs +35 -0
- package/dist/core/utils/event-stream.d.mts +53 -0
- package/dist/core/utils/event-stream.mjs +38 -0
- package/dist/core/utils/event.d.mts +8 -0
- package/dist/core/utils/event.mjs +12 -0
- package/dist/core/utils/internal/event-stream.d.mts +45 -0
- package/dist/core/utils/internal/event-stream.mjs +137 -0
- package/dist/core/utils/internal/obj.mjs +9 -0
- package/dist/core/utils/internal/object.mjs +29 -0
- package/dist/core/utils/internal/query.mjs +73 -0
- package/dist/core/utils/internal/req.mjs +35 -0
- package/dist/core/utils/merge.d.mts +14 -0
- package/dist/core/utils/merge.mjs +27 -0
- package/dist/{shared/silgi.DTwQEdSr.d.mts → core/utils/middleware.d.mts} +11 -13
- package/dist/core/utils/middleware.mjs +12 -0
- package/dist/core/utils/request.mjs +35 -0
- package/dist/core/utils/resolver.d.mts +7 -0
- package/dist/core/utils/resolver.mjs +29 -0
- package/dist/core/utils/runtime.d.mts +7 -0
- package/dist/core/utils/runtime.mjs +20 -0
- package/dist/core/utils/sanitize.mjs +22 -0
- package/dist/core/utils/schema.d.mts +34 -0
- package/dist/core/utils/schema.mjs +33 -0
- package/dist/core/utils/service.d.mts +13 -0
- package/dist/core/utils/service.mjs +19 -0
- package/dist/core/utils/shared.d.mts +6 -0
- package/dist/core/utils/shared.mjs +7 -0
- package/dist/core/utils/storage.d.mts +24 -0
- package/dist/core/utils/storage.mjs +54 -0
- package/dist/index.d.mts +21 -6
- package/dist/index.mjs +22 -16
- package/dist/kit/add/add-commands.d.mts +6 -0
- package/dist/kit/add/add-commands.mjs +12 -0
- package/dist/kit/add/add-core-file.d.mts +9 -0
- package/dist/kit/add/add-core-file.mjs +11 -0
- package/dist/kit/add/add-imports.d.mts +14 -0
- package/dist/kit/add/add-imports.mjs +56 -0
- package/dist/kit/add/add-npm.d.mts +14 -0
- package/dist/kit/add/add-npm.mjs +23 -0
- package/dist/kit/define.d.mts +28 -0
- package/dist/kit/define.mjs +25 -0
- package/dist/kit/errors.d.mts +6 -0
- package/dist/kit/errors.mjs +11 -0
- package/dist/kit/esm.d.mts +11 -0
- package/dist/kit/esm.mjs +21 -0
- package/dist/kit/fs.d.mts +7 -0
- package/dist/kit/fs.mjs +23 -0
- package/dist/kit/function-utils.d.mts +27 -0
- package/dist/kit/function-utils.mjs +75 -0
- package/dist/kit/gen.d.mts +5 -0
- package/dist/kit/gen.mjs +26 -0
- package/dist/kit/hash.d.mts +4 -0
- package/dist/kit/hash.mjs +10 -0
- package/dist/kit/index.d.mts +22 -321
- package/dist/kit/index.mjs +23 -1039
- package/dist/kit/isFramework.d.mts +6 -0
- package/dist/kit/isFramework.mjs +21 -0
- package/dist/kit/logger.d.mts +6 -0
- package/dist/kit/logger.mjs +10 -0
- package/dist/kit/migration.d.mts +113 -0
- package/dist/kit/migration.mjs +301 -0
- package/dist/kit/module.d.mts +14 -0
- package/dist/kit/module.mjs +53 -0
- package/dist/kit/path.d.mts +7 -0
- package/dist/kit/path.mjs +26 -0
- package/dist/kit/preset.d.mts +8 -0
- package/dist/kit/preset.mjs +11 -0
- package/dist/kit/resolve.d.mts +37 -0
- package/dist/kit/resolve.mjs +82 -0
- package/dist/kit/template.d.mts +14 -0
- package/dist/kit/template.mjs +59 -0
- package/dist/kit/useRequest.d.mts +19 -0
- package/dist/kit/useRequest.mjs +63 -0
- package/dist/kit/utils.d.mts +34 -0
- package/dist/kit/utils.mjs +90 -0
- package/dist/package.mjs +176 -0
- package/dist/presets/_all.gen.d.mts +5 -2
- package/dist/presets/_all.gen.mjs +16 -13
- package/dist/presets/_resolve.d.mts +10 -6
- package/dist/presets/_resolve.mjs +51 -65
- package/dist/presets/_types.gen.d.mts +8 -5
- package/dist/presets/_types.gen.mjs +5 -1
- package/dist/presets/h3/preset.d.mts +5 -2
- package/dist/presets/h3/preset.mjs +33 -38
- package/dist/presets/hono/preset.d.mts +5 -2
- package/dist/presets/hono/preset.mjs +28 -35
- package/dist/presets/index.d.mts +3 -2
- package/dist/presets/index.mjs +3 -1
- package/dist/presets/nitro/preset.d.mts +5 -2
- package/dist/presets/nitro/preset.mjs +35 -42
- package/dist/presets/npmpackage/preset.d.mts +5 -2
- package/dist/presets/npmpackage/preset.mjs +27 -32
- package/dist/presets/nuxt/preset.d.mts +5 -2
- package/dist/presets/nuxt/preset.mjs +39 -44
- package/dist/runtime/index.d.mts +4 -3
- package/dist/runtime/index.mjs +5 -3
- package/dist/runtime/internal/config.d.mts +11 -7
- package/dist/runtime/internal/config.mjs +79 -90
- package/dist/runtime/internal/debug.d.mts +6 -3
- package/dist/runtime/internal/debug.mjs +9 -4
- package/dist/runtime/internal/defu.d.mts +4 -1
- package/dist/runtime/internal/defu.mjs +7 -2
- package/dist/runtime/internal/index.d.mts +7 -6
- package/dist/runtime/internal/index.mjs +8 -20
- package/dist/runtime/internal/nitro.d.mts +6 -3
- package/dist/runtime/internal/nitro.mjs +29 -37
- package/dist/runtime/internal/nuxt.d.mts +12 -8
- package/dist/runtime/internal/nuxt.mjs +12 -7
- package/dist/runtime/internal/ofetch.d.mts +8 -4
- package/dist/runtime/internal/ofetch.mjs +33 -34
- package/dist/runtime/internal/plugin.d.mts +7 -3
- package/dist/runtime/internal/plugin.mjs +7 -3
- package/dist/types/cliConfig.d.mts +288 -0
- package/dist/types/cliConfig.mjs +0 -0
- package/dist/types/cliHooks.d.mts +154 -0
- package/dist/types/cliHooks.mjs +0 -0
- package/dist/types/compatibility.d.mts +13 -0
- package/dist/types/compatibility.mjs +0 -0
- package/dist/types/config.d.mts +46 -0
- package/dist/types/config.mjs +0 -0
- package/dist/types/dotenv.d.mts +29 -0
- package/dist/types/dotenv.mjs +0 -0
- package/dist/types/event.d.mts +63 -0
- package/dist/types/event.mjs +0 -0
- package/dist/types/global.d.mts +24 -0
- package/dist/types/global.mjs +0 -0
- package/dist/types/helper.d.mts +25 -0
- package/dist/types/helper.mjs +0 -0
- package/dist/types/hooks.d.mts +37 -0
- package/dist/types/hooks.mjs +0 -0
- package/dist/types/index.d.mts +26 -1306
- package/dist/types/index.mjs +0 -1
- package/dist/types/kits.d.mts +32 -0
- package/dist/types/kits.mjs +0 -0
- package/dist/types/middleware.d.mts +31 -0
- package/dist/types/middleware.mjs +0 -0
- package/dist/types/module.d.mts +102 -0
- package/dist/types/module.mjs +0 -0
- package/dist/types/preset.d.mts +20 -0
- package/dist/types/preset.mjs +0 -0
- package/dist/types/route.d.mts +59 -0
- package/dist/types/route.mjs +0 -0
- package/dist/types/runtime/index.d.mts +5 -0
- package/dist/types/runtime/index.mjs +0 -0
- package/dist/types/runtime/nuxt.d.mts +13 -0
- package/dist/types/runtime/nuxt.mjs +0 -0
- package/dist/types/runtime/ofetch.d.mts +14 -0
- package/dist/types/runtime/ofetch.mjs +0 -0
- package/dist/types/runtime/plugin.d.mts +8 -0
- package/dist/types/runtime/plugin.mjs +0 -0
- package/dist/types/runtime/silgi.d.mts +11 -0
- package/dist/types/runtime/silgi.mjs +0 -0
- package/dist/types/schema.d.mts +86 -0
- package/dist/types/schema.mjs +0 -0
- package/dist/types/service.d.mts +102 -0
- package/dist/types/service.mjs +0 -0
- package/dist/types/shared.d.mts +19 -0
- package/dist/types/shared.mjs +0 -0
- package/dist/types/silgi.d.mts +71 -0
- package/dist/types/silgi.mjs +0 -0
- package/dist/types/silgiCLI.d.mts +118 -0
- package/dist/types/silgiCLI.mjs +0 -0
- package/dist/types/standard-schema.d.mts +61 -0
- package/dist/types/standard-schema.mjs +0 -0
- package/dist/types/storage.d.mts +30 -0
- package/dist/types/storage.mjs +0 -0
- package/package.json +20 -35
- package/dist/_chunks/silgiApp.mjs +0 -25
- package/dist/cli/build.mjs +0 -2190
- package/dist/cli/common.mjs +0 -13
- package/dist/cli/compatibility.mjs +0 -30
- package/dist/cli/dev.mjs +0 -67
- package/dist/cli/init.mjs +0 -112
- package/dist/cli/install.mjs +0 -151
- package/dist/cli/loader.mjs +0 -618
- package/dist/cli/prepare.mjs +0 -188
- package/dist/cli/reset.mjs +0 -55
- package/dist/cli/run.mjs +0 -159
- package/dist/cli/types.mjs +0 -232
- package/dist/cli/watch.mjs +0 -91
- package/dist/presets/next/preset.d.mts +0 -3
- package/dist/presets/next/preset.mjs +0 -38
- package/dist/runtime/internal/next.d.mts +0 -9
- package/dist/runtime/internal/next.mjs +0 -22
|
@@ -1,108 +1,97 @@
|
|
|
1
|
+
import { updateRuntimeStorage, useRuntime, useSilgi } from "silgi";
|
|
1
2
|
import { defu } from "defu";
|
|
2
|
-
import destr from "destr";
|
|
3
|
-
import { klona } from "klona";
|
|
4
3
|
import { snakeCase } from "scule";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
import { klona } from "klona";
|
|
5
|
+
import destr from "destr";
|
|
6
|
+
|
|
7
|
+
//#region src/runtime/internal/config.ts
|
|
8
|
+
function updateEnvOptions(runtime) {
|
|
9
|
+
const envOptions = {
|
|
10
|
+
prefix: "NITRO_",
|
|
11
|
+
altPrefix: runtime?.silgi?.envPrefix ?? process.env.NITRO_ENV_PREFIX ?? "_",
|
|
12
|
+
silgiPrefix: "SILGI_",
|
|
13
|
+
envExpansion: runtime?.silgi?.envExpansion ?? process.env.NITRO_ENV_EXPANSION ?? false
|
|
14
|
+
};
|
|
15
|
+
return envOptions;
|
|
14
16
|
}
|
|
15
17
|
let inlineRuntimeConfig;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
applyEnv(klona(runtime ?? {}), updateEnvOptions(runtime))
|
|
22
|
-
);
|
|
23
|
-
updateRuntimeStorage(inlineRuntimeConfig);
|
|
24
|
-
return inlineRuntimeConfig;
|
|
18
|
+
function sharedRuntimeConfig(runtime, force) {
|
|
19
|
+
if (inlineRuntimeConfig && !force) return inlineRuntimeConfig;
|
|
20
|
+
inlineRuntimeConfig = _deepFreeze(applyEnv(klona(runtime ?? {}), updateEnvOptions(runtime)));
|
|
21
|
+
updateRuntimeStorage(inlineRuntimeConfig);
|
|
22
|
+
return inlineRuntimeConfig;
|
|
25
23
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
const runtimeConfig = klona(runtime);
|
|
38
|
-
const envOptions = updateEnvOptions(runtime);
|
|
39
|
-
applyEnv(runtimeConfig, envOptions);
|
|
40
|
-
event.context.silgi.runtimeConfig = runtimeConfig;
|
|
41
|
-
return runtimeConfig;
|
|
24
|
+
function useRuntimeConfig(event, localRuntimeConfig, force) {
|
|
25
|
+
if (localRuntimeConfig) return sharedRuntimeConfig(localRuntimeConfig, force);
|
|
26
|
+
const runtime = useRuntime();
|
|
27
|
+
if (!event) return sharedRuntimeConfig(runtime);
|
|
28
|
+
if (event.context.silgi.runtimeConfig) return event.context.silgi.runtimeConfig;
|
|
29
|
+
const runtimeConfig = klona(runtime);
|
|
30
|
+
const envOptions = updateEnvOptions(runtime);
|
|
31
|
+
applyEnv(runtimeConfig, envOptions);
|
|
32
|
+
event.context.silgi.runtimeConfig = runtimeConfig;
|
|
33
|
+
return runtimeConfig;
|
|
42
34
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
applyEnv(klona(inlineRuntimeConfig2), finalEnvOptions)
|
|
53
|
-
);
|
|
35
|
+
function initRuntimeConfig(envOptions = {}, inlineRuntimeConfig$1 = {}) {
|
|
36
|
+
const finalEnvOptions = {
|
|
37
|
+
prefix: "NITRO_",
|
|
38
|
+
altPrefix: inlineRuntimeConfig$1?.nitro?.envPrefix ?? process.env.NITRO_ENV_PREFIX ?? "_",
|
|
39
|
+
silgiPrefix: "SILGI_",
|
|
40
|
+
envExpansion: inlineRuntimeConfig$1?.nitro?.envExpansion ?? process.env.NITRO_ENV_EXPANSION ?? false,
|
|
41
|
+
...envOptions
|
|
42
|
+
};
|
|
43
|
+
return _deepFreeze(applyEnv(klona(inlineRuntimeConfig$1), finalEnvOptions));
|
|
54
44
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
try {
|
|
59
|
-
} catch {
|
|
60
|
-
}
|
|
45
|
+
function updateRuntimeConfig(runtimeConfig) {
|
|
46
|
+
const nuxt = useSilgi();
|
|
47
|
+
Object.assign(nuxt.options.nitro.runtimeConfig, defu(runtimeConfig, nuxt.options.nitro.runtimeConfig));
|
|
61
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* https://github.com/nitrojs/nitro/blob/main/src/runtime/internal/utils.env.ts.
|
|
51
|
+
*
|
|
52
|
+
* These utils will be replaced by util exposed from nitropack. See https://github.com/nitrojs/nitro/pull/2404
|
|
53
|
+
* for more context and future plans.)
|
|
54
|
+
*
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
62
57
|
function getEnv(key, opts, env = process.env) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
env[opts.prefix + envKey] ?? env[opts.altPrefix + envKey] ?? env[opts.silgiPrefix + envKey]
|
|
66
|
-
);
|
|
58
|
+
const envKey = snakeCase(key).toUpperCase();
|
|
59
|
+
return destr(env[opts.prefix + envKey] ?? env[opts.altPrefix + envKey] ?? env[opts.silgiPrefix + envKey]);
|
|
67
60
|
}
|
|
68
61
|
function _isObject(input) {
|
|
69
|
-
|
|
62
|
+
return typeof input === "object" && !Array.isArray(input);
|
|
70
63
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (opts.envExpansion && typeof obj[key] === "string") {
|
|
88
|
-
obj[key] = _expandFromEnv(obj[key]);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return obj;
|
|
64
|
+
function applyEnv(obj, opts, parentKey = "") {
|
|
65
|
+
for (const key in obj) {
|
|
66
|
+
const subKey = parentKey ? `${parentKey}_${key}` : key;
|
|
67
|
+
const envValue = getEnv(subKey, opts);
|
|
68
|
+
if (_isObject(obj[key])) if (_isObject(envValue)) {
|
|
69
|
+
obj[key] = {
|
|
70
|
+
...obj[key],
|
|
71
|
+
...envValue
|
|
72
|
+
};
|
|
73
|
+
applyEnv(obj[key], opts, subKey);
|
|
74
|
+
} else if (envValue === void 0) applyEnv(obj[key], opts, subKey);
|
|
75
|
+
else obj[key] = envValue ?? obj[key];
|
|
76
|
+
else obj[key] = envValue ?? obj[key];
|
|
77
|
+
if (opts.envExpansion && typeof obj[key] === "string") obj[key] = _expandFromEnv(obj[key]);
|
|
78
|
+
}
|
|
79
|
+
return obj;
|
|
92
80
|
}
|
|
93
81
|
const envExpandRx = /\{\{([^{}]*)\}\}/g;
|
|
94
82
|
function _expandFromEnv(value, env = process.env) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
83
|
+
return value.replace(envExpandRx, (match, key) => {
|
|
84
|
+
return env[key] || match;
|
|
85
|
+
});
|
|
98
86
|
}
|
|
99
87
|
function _deepFreeze(object) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
return Object.freeze(object);
|
|
88
|
+
const propNames = Object.getOwnPropertyNames(object);
|
|
89
|
+
for (const name of propNames) {
|
|
90
|
+
const value = object[name];
|
|
91
|
+
if (value && typeof value === "object") _deepFreeze(value);
|
|
92
|
+
}
|
|
93
|
+
return Object.freeze(object);
|
|
108
94
|
}
|
|
95
|
+
|
|
96
|
+
//#endregion
|
|
97
|
+
export { applyEnv, initRuntimeConfig, sharedRuntimeConfig, updateEnvOptions, updateRuntimeConfig, useRuntimeConfig };
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { SilgiAppPlugin } from "silgi/types";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/internal/debug.d.ts
|
|
4
|
+
declare const debugPlugin: SilgiAppPlugin;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { debugPlugin, debugPlugin as default };
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import { defineSilgiPlugin } from "./plugin.mjs";
|
|
1
2
|
import { createDebugger } from "hookable";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
|
|
4
|
+
//#region src/runtime/internal/debug.ts
|
|
5
|
+
const debugPlugin = defineSilgiPlugin((silgi) => {
|
|
6
|
+
createDebugger(silgi.hooks, { tag: "silgi-runtime" });
|
|
5
7
|
});
|
|
6
|
-
|
|
8
|
+
var debug_default = debugPlugin;
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { debugPlugin, debug_default as default };
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { defu } from "defu";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/internal/defu.ts
|
|
4
|
+
function mergeDeep(source, ...defaults) {
|
|
5
|
+
return defu(source, ...defaults);
|
|
4
6
|
}
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
export { mergeDeep };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { defineSilgiPlugin, silgiPlugin } from "./plugin.mjs";
|
|
2
|
+
import { mergeDeep } from "./defu.mjs";
|
|
3
|
+
import { debugPlugin } from "./debug.mjs";
|
|
4
|
+
import { addNitroApp } from "./nitro.mjs";
|
|
5
|
+
import { useSilgiFetch } from "./nuxt.mjs";
|
|
6
|
+
import { createSilgiFetch, silgi$fetch } from "./ofetch.mjs";
|
|
7
|
+
export { addNitroApp, createSilgiFetch, debugPlugin, defineSilgiPlugin, mergeDeep, silgi$fetch, silgiPlugin, useSilgiFetch };
|
|
@@ -1,20 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from "./nitro.mjs";
|
|
10
|
-
export {
|
|
11
|
-
useSilgiFetch
|
|
12
|
-
} from "./nuxt.mjs";
|
|
13
|
-
export {
|
|
14
|
-
createSilgiFetch,
|
|
15
|
-
silgi$fetch
|
|
16
|
-
} from "./ofetch.mjs";
|
|
17
|
-
export {
|
|
18
|
-
defineSilgiPlugin,
|
|
19
|
-
silgiPlugin
|
|
20
|
-
} from "./plugin.mjs";
|
|
1
|
+
import { defineSilgiPlugin, silgiPlugin } from "./plugin.mjs";
|
|
2
|
+
import { mergeDeep } from "./defu.mjs";
|
|
3
|
+
import { debugPlugin } from "./debug.mjs";
|
|
4
|
+
import { addNitroApp } from "./nitro.mjs";
|
|
5
|
+
import { useSilgiFetch } from "./nuxt.mjs";
|
|
6
|
+
import { createSilgiFetch, silgi$fetch } from "./ofetch.mjs";
|
|
7
|
+
|
|
8
|
+
export { addNitroApp, createSilgiFetch, debugPlugin, defineSilgiPlugin, mergeDeep, silgi$fetch, silgiPlugin, useSilgiFetch };
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { Silgi } from "silgi/types";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/internal/nitro.d.ts
|
|
4
|
+
declare function addNitroApp(silgiContext?: Silgi): Promise<void>;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { addNitroApp, addNitroApp as default };
|
|
@@ -1,38 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}));
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
const webhookServices = Object.entries(silgiContext.services).filter(([key]) => key.startsWith("websocket:")).map(([, value]) => value);
|
|
30
|
-
for (const webhook of webhookServices) {
|
|
31
|
-
nitro.router.use(webhook.path, defineEventHandler({
|
|
32
|
-
handler: () => {
|
|
33
|
-
},
|
|
34
|
-
websocket: webhook.websocket || {}
|
|
35
|
-
}));
|
|
36
|
-
}
|
|
1
|
+
import { silgiFetch, useSilgi } from "silgi";
|
|
2
|
+
import { defineEventHandler, toWebRequest } from "h3";
|
|
3
|
+
|
|
4
|
+
//#region src/runtime/internal/nitro.ts
|
|
5
|
+
async function addNitroApp(silgiContext = useSilgi()) {
|
|
6
|
+
const nitro = silgiContext.framework?.nitro;
|
|
7
|
+
if (!nitro) throw new Error("Nitro framework not found");
|
|
8
|
+
const prefixs = silgiContext.routerPrefixs;
|
|
9
|
+
for (const prefix of prefixs) {
|
|
10
|
+
let type = "http";
|
|
11
|
+
let path = "";
|
|
12
|
+
const parts = prefix.split(":");
|
|
13
|
+
type = parts[0] ? parts[0].toUpperCase() : "HTTP";
|
|
14
|
+
path = parts[1] ?? "";
|
|
15
|
+
if (type === "HTTP") nitro.router.use(`${path}/**`, defineEventHandler(async (event) => {
|
|
16
|
+
const evet = toWebRequest(event);
|
|
17
|
+
const resolvedRoute = await silgiFetch(evet);
|
|
18
|
+
return resolvedRoute;
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
const webhookServices = Object.entries(silgiContext.services).filter(([key]) => key.startsWith("websocket:")).map(([, value]) => value);
|
|
22
|
+
for (const webhook of webhookServices) nitro.router.use(webhook.path, defineEventHandler({
|
|
23
|
+
handler: () => {},
|
|
24
|
+
websocket: webhook.websocket || {}
|
|
25
|
+
}));
|
|
37
26
|
}
|
|
38
|
-
|
|
27
|
+
var nitro_default = addNitroApp;
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
export { addNitroApp, nitro_default as default };
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { AsyncData, UseFetchOptions } from "nuxt/app";
|
|
2
|
+
import { AllPaths, ExtractPathParams, SilgiRouterTypes, TrimAfterFourSlashes } from "silgi/types";
|
|
3
|
+
import { FetchError } from "ofetch";
|
|
4
|
+
|
|
5
|
+
//#region src/runtime/internal/nuxt.d.ts
|
|
6
|
+
declare function useSilgiFetch<T, P extends AllPaths | (string & {}), BasePath extends keyof SilgiRouterTypes = (TrimAfterFourSlashes<P> extends keyof SilgiRouterTypes ? TrimAfterFourSlashes<P> : never), M extends keyof SilgiRouterTypes[BasePath] = keyof SilgiRouterTypes[BasePath]>(path: P, options?: {
|
|
7
|
+
method?: M;
|
|
8
|
+
params?: ExtractPathParams<P>;
|
|
9
|
+
body?: SilgiRouterTypes[BasePath][M]["input"];
|
|
10
|
+
} & Omit<UseFetchOptions<T>, "method" | "body" | "params">): AsyncData<SilgiRouterTypes[BasePath][M]["output"], FetchError | null>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { useSilgiFetch };
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { useFetch } from "nuxt/app";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/internal/nuxt.ts
|
|
2
4
|
function replacePathParams(template, params) {
|
|
3
|
-
|
|
5
|
+
return template.replace(/:([^/]+)/g, (_, param) => params[param] || `:${param}`);
|
|
4
6
|
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
function useSilgiFetch(path, options) {
|
|
8
|
+
const resolvedPath = options?.params ? replacePathParams(path, options.params) : path;
|
|
9
|
+
return useFetch(resolvedPath, {
|
|
10
|
+
method: options?.method,
|
|
11
|
+
body: options?.body
|
|
12
|
+
});
|
|
11
13
|
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { useSilgiFetch };
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { AllPaths, SilgiFetchClient, SilgiFetchOptions, SilgiRouterTypes, TrimAfterFourSlashes } from "silgi/types";
|
|
2
|
+
import { FetchOptions, FetchResponse } from "ofetch";
|
|
3
|
+
|
|
4
|
+
//#region src/runtime/internal/ofetch.d.ts
|
|
5
|
+
declare function createSilgiFetch(options: FetchOptions | ((options: FetchOptions) => FetchOptions), localFetch?: typeof globalThis.$fetch): SilgiFetchClient;
|
|
6
|
+
declare function silgi$fetch<P extends AllPaths | (string & {}), BasePath extends keyof SilgiRouterTypes = (TrimAfterFourSlashes<P> extends keyof SilgiRouterTypes ? TrimAfterFourSlashes<P> : never), M extends keyof SilgiRouterTypes[BasePath] = keyof SilgiRouterTypes[BasePath]>(url: P, opts?: SilgiFetchOptions<P, BasePath, M>): Promise<FetchResponse<SilgiRouterTypes[BasePath][M]["output"]>>;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { createSilgiFetch, silgi$fetch };
|
|
@@ -1,40 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
//#region src/runtime/internal/ofetch.ts
|
|
2
|
+
function createSilgiFetch(options, localFetch) {
|
|
3
|
+
return (url, opts) => {
|
|
4
|
+
const finalOpts = {
|
|
5
|
+
...typeof options === "function" ? options(opts) : options,
|
|
6
|
+
...opts,
|
|
7
|
+
method: opts?.method || "get"
|
|
8
|
+
};
|
|
9
|
+
const $fetch = getFetch(url, finalOpts, localFetch);
|
|
10
|
+
return $fetch(fillPath(url, opts?.params), finalOpts);
|
|
11
|
+
};
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
function silgi$fetch(url, opts) {
|
|
14
|
+
const finalOpts = {
|
|
15
|
+
...opts,
|
|
16
|
+
method: opts?.method || "get"
|
|
17
|
+
};
|
|
18
|
+
const $fetch = getFetch(url, finalOpts);
|
|
19
|
+
return $fetch(fillPath(url, opts?.params), finalOpts);
|
|
19
20
|
}
|
|
20
21
|
function getFetch(url, opts, localFetch) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return globalThis.$fetch;
|
|
22
|
+
if (import.meta.server && localFetch) {
|
|
23
|
+
const isLocalFetch = url[0] === "/" && (!opts.baseURL || opts.baseURL[0] === "/");
|
|
24
|
+
if (isLocalFetch) return localFetch;
|
|
25
|
+
}
|
|
26
|
+
return globalThis.$fetch;
|
|
27
27
|
}
|
|
28
28
|
function fillPath(path, params) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
result = result.replace(pattern, value);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return result;
|
|
29
|
+
if (!params || Object.keys(params).length === 0) return path;
|
|
30
|
+
let result = path;
|
|
31
|
+
for (const [key, value] of Object.entries(params)) {
|
|
32
|
+
const pattern = `:${key}`;
|
|
33
|
+
if (result.includes(pattern)) result = result.replace(pattern, value);
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
40
36
|
}
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { createSilgiFetch, silgi$fetch };
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { SilgiAppPlugin } from "silgi/types";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/internal/plugin.d.ts
|
|
4
|
+
declare function defineSilgiPlugin(def: SilgiAppPlugin): SilgiAppPlugin;
|
|
5
|
+
declare const silgiPlugin: typeof defineSilgiPlugin;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { defineSilgiPlugin, silgiPlugin };
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/runtime/internal/plugin.ts
|
|
2
|
+
function defineSilgiPlugin(def) {
|
|
3
|
+
return def;
|
|
3
4
|
}
|
|
4
|
-
|
|
5
|
+
const silgiPlugin = defineSilgiPlugin;
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
export { defineSilgiPlugin, silgiPlugin };
|