silgi 0.15.0 → 0.16.1
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/_chunks/index.mjs +1 -1
- package/dist/_chunks/routeRules.mjs +37 -23
- package/dist/cli/dev.mjs +1 -1
- package/dist/cli/loader.mjs +2 -1
- package/dist/cli/prepare.mjs +2 -2
- package/dist/cli/writeTypesAndFiles.mjs +156 -173
- package/dist/core/index.mjs +1 -0
- package/dist/kit/index.d.mts +28 -2
- package/dist/kit/index.d.ts +28 -2
- package/dist/kit/index.mjs +72 -1
- package/dist/meta/index.d.mts +1 -1
- package/dist/meta/index.d.ts +1 -1
- package/dist/types/index.d.mts +74 -43
- package/dist/types/index.d.ts +74 -43
- package/package.json +1 -1
package/dist/_chunks/index.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { withoutTrailingSlash, withLeadingSlash } from 'ufo';
|
|
2
|
+
|
|
1
3
|
function patternToRegex(pattern) {
|
|
2
4
|
let regexStr = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&");
|
|
3
5
|
regexStr = regexStr.replace(/\*\*/g, ".+");
|
|
@@ -6,6 +8,8 @@ function patternToRegex(pattern) {
|
|
|
6
8
|
return new RegExp(`^${regexStr}$`);
|
|
7
9
|
}
|
|
8
10
|
function extractParams(url, pattern) {
|
|
11
|
+
url = withoutTrailingSlash(withLeadingSlash(url));
|
|
12
|
+
pattern = withoutTrailingSlash(withLeadingSlash(pattern));
|
|
9
13
|
if (!pattern.includes(":"))
|
|
10
14
|
return null;
|
|
11
15
|
const paramNames = [];
|
|
@@ -24,11 +28,10 @@ function extractParams(url, pattern) {
|
|
|
24
28
|
return Object.keys(params).length > 0 ? params : null;
|
|
25
29
|
}
|
|
26
30
|
function matchesPattern(url, pattern) {
|
|
31
|
+
url = withoutTrailingSlash(withLeadingSlash(url));
|
|
32
|
+
pattern = withoutTrailingSlash(withLeadingSlash(pattern));
|
|
27
33
|
if (url === pattern)
|
|
28
34
|
return true;
|
|
29
|
-
if (url.endsWith("/") && !pattern.endsWith("/") || !url.endsWith("/") && pattern.endsWith("/")) {
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
35
|
if (pattern.endsWith("/**")) {
|
|
33
36
|
const basePath = pattern.slice(0, -3);
|
|
34
37
|
return url === basePath || url.startsWith(`${basePath}/`);
|
|
@@ -86,7 +89,11 @@ function createRouteRules() {
|
|
|
86
89
|
return deepClone(_rules);
|
|
87
90
|
}
|
|
88
91
|
function importRules(config) {
|
|
89
|
-
|
|
92
|
+
const normalizedConfig = {};
|
|
93
|
+
for (const pattern in config) {
|
|
94
|
+
normalizedConfig[withoutTrailingSlash(withLeadingSlash(pattern))] = deepClone(config[pattern]);
|
|
95
|
+
}
|
|
96
|
+
_rules = normalizedConfig;
|
|
90
97
|
_rulesModified = true;
|
|
91
98
|
updateMergeRules();
|
|
92
99
|
}
|
|
@@ -94,29 +101,31 @@ function createRouteRules() {
|
|
|
94
101
|
return deepClone(_rules);
|
|
95
102
|
}
|
|
96
103
|
function addRule(pattern, config) {
|
|
97
|
-
_rules[pattern] = deepClone(config);
|
|
104
|
+
_rules[withoutTrailingSlash(withLeadingSlash(pattern))] = deepClone(config);
|
|
98
105
|
_rulesModified = true;
|
|
99
106
|
updateMergeRules();
|
|
100
107
|
}
|
|
101
108
|
function updateRule(pattern, config) {
|
|
102
|
-
|
|
103
|
-
|
|
109
|
+
const normalizedPattern = withoutTrailingSlash(withLeadingSlash(pattern));
|
|
110
|
+
if (_rules[normalizedPattern]) {
|
|
111
|
+
_rules[normalizedPattern] = { ..._rules[normalizedPattern], ...deepClone(config) };
|
|
104
112
|
} else {
|
|
105
|
-
_rules[
|
|
113
|
+
_rules[normalizedPattern] = deepClone(config);
|
|
106
114
|
}
|
|
107
115
|
_rulesModified = true;
|
|
108
116
|
updateMergeRules();
|
|
109
117
|
}
|
|
110
118
|
function removeRule(pattern) {
|
|
111
|
-
delete _rules[pattern];
|
|
119
|
+
delete _rules[withoutTrailingSlash(withLeadingSlash(pattern))];
|
|
112
120
|
_rulesModified = true;
|
|
113
121
|
updateMergeRules();
|
|
114
122
|
}
|
|
115
123
|
function matchesRule(url, pattern) {
|
|
116
|
-
return matchesPattern(url, pattern);
|
|
124
|
+
return matchesPattern(withoutTrailingSlash(withLeadingSlash(url)), withoutTrailingSlash(withLeadingSlash(pattern)));
|
|
117
125
|
}
|
|
118
126
|
function getMatchingPatterns(url) {
|
|
119
|
-
|
|
127
|
+
const normalizedUrl = withoutTrailingSlash(withLeadingSlash(url));
|
|
128
|
+
return Object.keys(_rules).filter((pattern) => matchesPattern(normalizedUrl, pattern)).sort((a, b) => {
|
|
120
129
|
if (a === url)
|
|
121
130
|
return -1;
|
|
122
131
|
if (b === url)
|
|
@@ -137,13 +146,14 @@ function createRouteRules() {
|
|
|
137
146
|
});
|
|
138
147
|
}
|
|
139
148
|
function getConfig(url) {
|
|
149
|
+
const normalizedUrl = withoutTrailingSlash(withLeadingSlash(url));
|
|
140
150
|
if (_rulesModified) {
|
|
141
151
|
updateMergeRules();
|
|
142
152
|
}
|
|
143
|
-
if (_mergedRules[
|
|
144
|
-
return deepClone(_mergedRules[
|
|
153
|
+
if (_mergedRules[normalizedUrl]) {
|
|
154
|
+
return deepClone(_mergedRules[normalizedUrl]);
|
|
145
155
|
}
|
|
146
|
-
const patterns = getMatchingPatterns(
|
|
156
|
+
const patterns = getMatchingPatterns(normalizedUrl);
|
|
147
157
|
if (!patterns.length)
|
|
148
158
|
return null;
|
|
149
159
|
const mergedConfig = {};
|
|
@@ -152,11 +162,12 @@ function createRouteRules() {
|
|
|
152
162
|
const patternConfig = _mergedRules[pattern] || _rules[pattern];
|
|
153
163
|
Object.assign(mergedConfig, deepClone(patternConfig));
|
|
154
164
|
}
|
|
155
|
-
_mergedRules[
|
|
165
|
+
_mergedRules[normalizedUrl] = deepClone(mergedConfig);
|
|
156
166
|
return mergedConfig;
|
|
157
167
|
}
|
|
158
168
|
function computeMergedConfig(url, patterns) {
|
|
159
|
-
const
|
|
169
|
+
const normalizedUrl = withoutTrailingSlash(withLeadingSlash(url));
|
|
170
|
+
const matchingPatterns = patterns || getMatchingPatterns(normalizedUrl);
|
|
160
171
|
if (!matchingPatterns.length)
|
|
161
172
|
return {};
|
|
162
173
|
const allPatternsHaveCache = matchingPatterns.every((pattern) => !!_mergedRules[pattern]);
|
|
@@ -166,17 +177,18 @@ function createRouteRules() {
|
|
|
166
177
|
return matchingPatterns.reduceRight((result, pattern) => mergeConfigs(result, deepClone(_rules[pattern])), {});
|
|
167
178
|
}
|
|
168
179
|
function getParams(url, pattern) {
|
|
169
|
-
return extractParams(url, pattern);
|
|
180
|
+
return extractParams(withoutTrailingSlash(withLeadingSlash(url)), withoutTrailingSlash(withLeadingSlash(pattern)));
|
|
170
181
|
}
|
|
171
182
|
function match(url) {
|
|
172
|
-
const
|
|
183
|
+
const normalizedUrl = withoutTrailingSlash(withLeadingSlash(url));
|
|
184
|
+
const patterns = getMatchingPatterns(normalizedUrl);
|
|
173
185
|
if (!patterns.length)
|
|
174
186
|
return null;
|
|
175
187
|
const bestPattern = patterns[0];
|
|
176
188
|
return {
|
|
177
189
|
pattern: bestPattern,
|
|
178
190
|
config: deepClone(_rules[bestPattern]),
|
|
179
|
-
params: getParams(
|
|
191
|
+
params: getParams(normalizedUrl, bestPattern)
|
|
180
192
|
};
|
|
181
193
|
}
|
|
182
194
|
function clear() {
|
|
@@ -193,16 +205,18 @@ function createRouteRules() {
|
|
|
193
205
|
updateMergeRules();
|
|
194
206
|
}
|
|
195
207
|
for (const url of urls) {
|
|
196
|
-
|
|
197
|
-
|
|
208
|
+
const normalizedUrl = withoutTrailingSlash(withLeadingSlash(url));
|
|
209
|
+
if (!_mergedRules[normalizedUrl]) {
|
|
210
|
+
const patterns = getMatchingPatterns(normalizedUrl);
|
|
198
211
|
if (patterns.length) {
|
|
199
|
-
_mergedRules[
|
|
212
|
+
_mergedRules[normalizedUrl] = computeMergedConfig(normalizedUrl, patterns);
|
|
200
213
|
}
|
|
201
214
|
}
|
|
202
215
|
}
|
|
203
216
|
}
|
|
204
217
|
function setMergedRule(url, config) {
|
|
205
|
-
|
|
218
|
+
const normalizedUrl = withoutTrailingSlash(withLeadingSlash(url));
|
|
219
|
+
_mergedRules[normalizedUrl] = deepClone(config);
|
|
206
220
|
if (url.includes("*") || url.includes(":")) {
|
|
207
221
|
_rulesModified = false;
|
|
208
222
|
}
|
package/dist/cli/dev.mjs
CHANGED
|
@@ -16,6 +16,7 @@ import 'silgi/runtime/meta';
|
|
|
16
16
|
import 'silgi/types';
|
|
17
17
|
import 'unimport';
|
|
18
18
|
import '../_chunks/routeRules.mjs';
|
|
19
|
+
import 'ufo';
|
|
19
20
|
import './env.mjs';
|
|
20
21
|
import '@clack/prompts';
|
|
21
22
|
import 'dotenv';
|
|
@@ -23,7 +24,6 @@ import 'mlly';
|
|
|
23
24
|
import 'dev-jiti';
|
|
24
25
|
import 'node:url';
|
|
25
26
|
import 'defu';
|
|
26
|
-
import 'ufo';
|
|
27
27
|
import 'globby';
|
|
28
28
|
import 'ignore';
|
|
29
29
|
import '@oxc-parser/wasm';
|
package/dist/cli/loader.mjs
CHANGED
|
@@ -27,6 +27,7 @@ const SilgiCLIDefaults = {
|
|
|
27
27
|
version: "0.0.1"
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
|
+
serviceParseModules: [],
|
|
30
31
|
storages: [],
|
|
31
32
|
devServer: {
|
|
32
33
|
watch: []
|
|
@@ -56,6 +57,7 @@ const SilgiCLIDefaults = {
|
|
|
56
57
|
// Modules
|
|
57
58
|
_modules: [],
|
|
58
59
|
modules: [],
|
|
60
|
+
routeRules: {},
|
|
59
61
|
// Features
|
|
60
62
|
// experimental: {},
|
|
61
63
|
future: {},
|
|
@@ -92,7 +94,6 @@ const SilgiCLIDefaults = {
|
|
|
92
94
|
// handlers: [],
|
|
93
95
|
// devHandlers: [],
|
|
94
96
|
// errorHandler: undefined,
|
|
95
|
-
// routeRules: {},
|
|
96
97
|
// Advanced
|
|
97
98
|
typescript: {
|
|
98
99
|
strict: false,
|
package/dist/cli/prepare.mjs
CHANGED
|
@@ -13,6 +13,7 @@ import 'silgi/runtime/meta';
|
|
|
13
13
|
import 'silgi/types';
|
|
14
14
|
import 'unimport';
|
|
15
15
|
import '../_chunks/routeRules.mjs';
|
|
16
|
+
import 'ufo';
|
|
16
17
|
import './env.mjs';
|
|
17
18
|
import '@clack/prompts';
|
|
18
19
|
import 'dotenv';
|
|
@@ -22,7 +23,6 @@ import './compatibility.mjs';
|
|
|
22
23
|
import 'semver/functions/satisfies.js';
|
|
23
24
|
import 'node:url';
|
|
24
25
|
import 'defu';
|
|
25
|
-
import 'ufo';
|
|
26
26
|
import 'globby';
|
|
27
27
|
import 'ignore';
|
|
28
28
|
import '@oxc-parser/wasm';
|
|
@@ -76,7 +76,7 @@ async function prepareBuild(silgi) {
|
|
|
76
76
|
// This file is auto-generated at build time
|
|
77
77
|
// Contains route rules with preserved functions
|
|
78
78
|
|
|
79
|
-
export const
|
|
79
|
+
export const routeRules = ${serialized}
|
|
80
80
|
`;
|
|
81
81
|
const file = join(silgi.options.silgi.serverDir, "rules.ts");
|
|
82
82
|
await writeFile(file, content);
|
|
@@ -4,7 +4,7 @@ import consola$1, { consola } from 'consola';
|
|
|
4
4
|
import { createHooks, createDebugger } from 'hookable';
|
|
5
5
|
import { join, resolve, isAbsolute, relative, dirname, basename, extname } from 'pathe';
|
|
6
6
|
import { useSilgiCLI, silgiCLICtx } from 'silgi/core';
|
|
7
|
-
import { relativeWithDot, hash, resolveAlias, resolvePath, writeFile, normalizeTemplate, useLogger, addTemplate, initRuntimeConfig, hasError as hasError$1, isDirectory } from 'silgi/kit';
|
|
7
|
+
import { relativeWithDot, hash, resolveAlias, resolvePath, writeFile, parseServices, normalizeTemplate, useLogger, addTemplate, initRuntimeConfig, hasError as hasError$1, isDirectory } from 'silgi/kit';
|
|
8
8
|
import { runtimeDir } from 'silgi/runtime/meta';
|
|
9
9
|
import { autoImportTypes } from 'silgi/types';
|
|
10
10
|
import { scanExports, createUnimport, toExports } from 'unimport';
|
|
@@ -14,7 +14,7 @@ import { resolveModuleExportNames, resolve as resolve$1, resolvePath as resolveP
|
|
|
14
14
|
import { createJiti } from 'dev-jiti';
|
|
15
15
|
import { a as hasInstalledModule, h as hasError } from './compatibility.mjs';
|
|
16
16
|
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
17
|
-
import defu from 'defu';
|
|
17
|
+
import defu, { defu as defu$1 } from 'defu';
|
|
18
18
|
import { isRelative, withTrailingSlash } from 'ufo';
|
|
19
19
|
import { globby } from 'globby';
|
|
20
20
|
import ignore from 'ignore';
|
|
@@ -327,6 +327,15 @@ async function registerModuleExportScan(silgi) {
|
|
|
327
327
|
});
|
|
328
328
|
options.routeRules.push({ key: configKey, value: importName });
|
|
329
329
|
}
|
|
330
|
+
if (exportedTypes.includes("ModuleRuntimeRouteRulesConfig")) {
|
|
331
|
+
const importName = `_${hash(`${configKey}ModuleRuntimeRouteRulesConfig`)}`;
|
|
332
|
+
options.importItems[configKey].import.push({
|
|
333
|
+
name: `ModuleRuntimeRouteRulesConfig as ${importName}`,
|
|
334
|
+
type: true,
|
|
335
|
+
key: importName
|
|
336
|
+
});
|
|
337
|
+
options.routeRulesConfig.push({ key: configKey, value: importName });
|
|
338
|
+
}
|
|
330
339
|
}
|
|
331
340
|
});
|
|
332
341
|
}
|
|
@@ -573,6 +582,113 @@ ${cycleStr}`);
|
|
|
573
582
|
return order;
|
|
574
583
|
}
|
|
575
584
|
|
|
585
|
+
function buildUriMap(silgi, currentPath = []) {
|
|
586
|
+
const uriMap = /* @__PURE__ */ new Map();
|
|
587
|
+
function traverse(node, path = []) {
|
|
588
|
+
if (!node || typeof node !== "object")
|
|
589
|
+
return;
|
|
590
|
+
if (path.length === 4) {
|
|
591
|
+
const basePath = path.join("/");
|
|
592
|
+
let pathString = "";
|
|
593
|
+
if (node.pathParams) {
|
|
594
|
+
let paths = null;
|
|
595
|
+
if (node.pathParams?._def?.typeName !== void 0) {
|
|
596
|
+
try {
|
|
597
|
+
const shape = node.pathParams?.shape;
|
|
598
|
+
paths = shape ? Object.keys(shape) : null;
|
|
599
|
+
} catch {
|
|
600
|
+
paths = null;
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
if (paths?.length) {
|
|
604
|
+
pathString = paths.map((p) => `:${p}`).join("/");
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
uriMap.set(basePath, pathString);
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
for (const key in node) {
|
|
611
|
+
if (!["_type", "fields"].includes(key)) {
|
|
612
|
+
traverse(node[key], [...path, key]);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
traverse(silgi.schemas, currentPath);
|
|
617
|
+
silgi.uris = defu$1(silgi.uris, Object.fromEntries(uriMap));
|
|
618
|
+
return uriMap;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
async function readScanFile(silgi) {
|
|
622
|
+
const path = resolve(silgi.options.silgi.serverDir, "scan.ts");
|
|
623
|
+
const context = await promises.readFile(path, { encoding: "utf-8" });
|
|
624
|
+
silgi.unimport = createUnimport(silgi.options.imports || {});
|
|
625
|
+
await silgi.unimport.init();
|
|
626
|
+
const injectedResult = await silgi.unimport.injectImports(context, path);
|
|
627
|
+
if (!injectedResult) {
|
|
628
|
+
throw new Error("Failed to inject imports");
|
|
629
|
+
}
|
|
630
|
+
const jiti = createJiti(silgi.options.rootDir, {
|
|
631
|
+
fsCache: false,
|
|
632
|
+
moduleCache: false,
|
|
633
|
+
debug: silgi.options.debug,
|
|
634
|
+
alias: silgi.options.alias
|
|
635
|
+
});
|
|
636
|
+
try {
|
|
637
|
+
if (silgi.options.commandType === "prepare") {
|
|
638
|
+
globalThis.$silgiSharedRuntimeConfig = silgi.options.runtimeConfig;
|
|
639
|
+
injectedResult.code = `globalThis.$silgiSharedRuntimeConfig = ${JSON.stringify(silgi.options.runtimeConfig)};
|
|
640
|
+
${injectedResult.code}`;
|
|
641
|
+
injectedResult.code = injectedResult.code.replace(/runtimeConfig: \{\}/, `runtimeConfig: ${JSON.stringify(silgi.options.runtimeConfig)}`);
|
|
642
|
+
}
|
|
643
|
+
const scanFile = await jiti.evalModule(
|
|
644
|
+
injectedResult.code,
|
|
645
|
+
{
|
|
646
|
+
filename: path,
|
|
647
|
+
async: true,
|
|
648
|
+
conditions: silgi.options.conditions
|
|
649
|
+
},
|
|
650
|
+
async (data, name) => {
|
|
651
|
+
return (await silgi.unimport.injectImports(data, name)).code;
|
|
652
|
+
}
|
|
653
|
+
);
|
|
654
|
+
silgi.uris = defu$1(silgi.uris, scanFile.uris) || {};
|
|
655
|
+
silgi.schemas = defu$1(scanFile.schemas, scanFile.uris) || {};
|
|
656
|
+
silgi.services = defu$1(scanFile.services, scanFile.uris) || {};
|
|
657
|
+
silgi.shareds = defu$1(scanFile.shareds, scanFile.shareds) || {};
|
|
658
|
+
silgi.modulesURIs = defu$1(scanFile.modulesURIs, scanFile.modulesURIs) || {};
|
|
659
|
+
return {
|
|
660
|
+
context,
|
|
661
|
+
object: {
|
|
662
|
+
schemas: scanFile.schemas,
|
|
663
|
+
uris: scanFile.uris,
|
|
664
|
+
services: scanFile.services,
|
|
665
|
+
shareds: scanFile.shareds,
|
|
666
|
+
modulesURIs: scanFile.modulesURIs
|
|
667
|
+
},
|
|
668
|
+
path
|
|
669
|
+
};
|
|
670
|
+
} catch (error) {
|
|
671
|
+
if (silgi.options.debug) {
|
|
672
|
+
console.error("Failed to read scan.ts file:", error);
|
|
673
|
+
} else {
|
|
674
|
+
if (error instanceof Error) {
|
|
675
|
+
consola.withTag("silgi").error(error.message);
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
return {
|
|
679
|
+
context,
|
|
680
|
+
object: {
|
|
681
|
+
schemas: {},
|
|
682
|
+
uris: {},
|
|
683
|
+
services: {},
|
|
684
|
+
shareds: {},
|
|
685
|
+
modulesURIs: {}
|
|
686
|
+
},
|
|
687
|
+
path
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
|
|
576
692
|
async function prepareServerFiles(silgi) {
|
|
577
693
|
const importItems = {
|
|
578
694
|
"silgi": {
|
|
@@ -605,14 +721,20 @@ async function prepareServerFiles(silgi) {
|
|
|
605
721
|
}
|
|
606
722
|
};
|
|
607
723
|
const scanned = {
|
|
608
|
-
uris:
|
|
724
|
+
uris: {},
|
|
609
725
|
services: [],
|
|
610
726
|
shareds: [],
|
|
611
727
|
schemas: [],
|
|
612
|
-
modulesURIs:
|
|
728
|
+
modulesURIs: {},
|
|
613
729
|
customImports: [],
|
|
614
730
|
importItems
|
|
615
731
|
};
|
|
732
|
+
if (silgi.uris) {
|
|
733
|
+
defu$1(scanned.uris, silgi.uris);
|
|
734
|
+
}
|
|
735
|
+
if (silgi.modulesURIs) {
|
|
736
|
+
defu$1(scanned.modulesURIs, silgi.modulesURIs);
|
|
737
|
+
}
|
|
616
738
|
await silgi.callHook("prepare:scan.ts", scanned);
|
|
617
739
|
if (importItems["#silgi/vfs"].import.length === 0) {
|
|
618
740
|
delete importItems["#silgi/vfs"];
|
|
@@ -641,10 +763,9 @@ async function prepareServerFiles(silgi) {
|
|
|
641
763
|
""
|
|
642
764
|
];
|
|
643
765
|
const importData = [
|
|
766
|
+
`export const uris = ${JSON.stringify(scanned.uris, null, 2)}`,
|
|
644
767
|
"",
|
|
645
|
-
|
|
646
|
-
"",
|
|
647
|
-
"export const modulesURIs = {}",
|
|
768
|
+
`export const modulesURIs = ${JSON.stringify(scanned.modulesURIs, null, 2)}`,
|
|
648
769
|
"",
|
|
649
770
|
scanned.schemas.length > 0 ? "export const schemas = mergeSchemas([" : "export const schemas = {",
|
|
650
771
|
...scanned.schemas.map((name) => {
|
|
@@ -683,177 +804,25 @@ function deduplicateArray(array) {
|
|
|
683
804
|
return [...new Set(array)];
|
|
684
805
|
}
|
|
685
806
|
|
|
686
|
-
async function readScanFile(silgi) {
|
|
687
|
-
const path = resolve(silgi.options.silgi.serverDir, "scan.ts");
|
|
688
|
-
const context = await promises.readFile(path, { encoding: "utf-8" });
|
|
689
|
-
silgi.unimport = createUnimport(silgi.options.imports || {});
|
|
690
|
-
await silgi.unimport.init();
|
|
691
|
-
const injectedResult = await silgi.unimport.injectImports(context, path);
|
|
692
|
-
if (!injectedResult) {
|
|
693
|
-
throw new Error("Failed to inject imports");
|
|
694
|
-
}
|
|
695
|
-
const jiti = createJiti(silgi.options.rootDir, {
|
|
696
|
-
fsCache: false,
|
|
697
|
-
moduleCache: false,
|
|
698
|
-
debug: silgi.options.debug,
|
|
699
|
-
alias: silgi.options.alias
|
|
700
|
-
});
|
|
701
|
-
try {
|
|
702
|
-
if (silgi.options.commandType === "prepare") {
|
|
703
|
-
globalThis.$silgiSharedRuntimeConfig = silgi.options.runtimeConfig;
|
|
704
|
-
injectedResult.code = `globalThis.$silgiSharedRuntimeConfig = ${JSON.stringify(silgi.options.runtimeConfig)};
|
|
705
|
-
${injectedResult.code}`;
|
|
706
|
-
injectedResult.code = injectedResult.code.replace(/runtimeConfig: \{\}/, `runtimeConfig: ${JSON.stringify(silgi.options.runtimeConfig)}`);
|
|
707
|
-
}
|
|
708
|
-
const scanFile = await jiti.evalModule(
|
|
709
|
-
injectedResult.code,
|
|
710
|
-
{
|
|
711
|
-
filename: path,
|
|
712
|
-
async: true,
|
|
713
|
-
conditions: silgi.options.conditions
|
|
714
|
-
},
|
|
715
|
-
async (data, name) => {
|
|
716
|
-
return (await silgi.unimport.injectImports(data, name)).code;
|
|
717
|
-
}
|
|
718
|
-
);
|
|
719
|
-
silgi.uris = scanFile.uris || {};
|
|
720
|
-
silgi.schemas = scanFile.schemas || {};
|
|
721
|
-
silgi.services = scanFile.services || {};
|
|
722
|
-
silgi.shareds = scanFile.shareds || {};
|
|
723
|
-
silgi.modulesURIs = scanFile.modulesURIs || {};
|
|
724
|
-
return {
|
|
725
|
-
context,
|
|
726
|
-
object: {
|
|
727
|
-
schemas: scanFile.schemas,
|
|
728
|
-
uris: scanFile.uris,
|
|
729
|
-
services: scanFile.services,
|
|
730
|
-
shareds: scanFile.shareds,
|
|
731
|
-
modulesURIs: scanFile.modulesURIs
|
|
732
|
-
},
|
|
733
|
-
path
|
|
734
|
-
};
|
|
735
|
-
} catch (error) {
|
|
736
|
-
if (silgi.options.debug) {
|
|
737
|
-
console.error("Failed to read scan.ts file:", error);
|
|
738
|
-
} else {
|
|
739
|
-
if (error instanceof Error) {
|
|
740
|
-
consola$1.withTag("silgi").error(error.message);
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
return {
|
|
744
|
-
context,
|
|
745
|
-
object: {
|
|
746
|
-
schemas: {},
|
|
747
|
-
uris: {},
|
|
748
|
-
services: {},
|
|
749
|
-
shareds: {},
|
|
750
|
-
modulesURIs: {}
|
|
751
|
-
},
|
|
752
|
-
path
|
|
753
|
-
};
|
|
754
|
-
}
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
function traverseObject(silgi, obj, currentPath = []) {
|
|
758
|
-
const uriMap = /* @__PURE__ */ new Map();
|
|
759
|
-
function traverse(node, path = []) {
|
|
760
|
-
if (!node || typeof node !== "object")
|
|
761
|
-
return;
|
|
762
|
-
if (path.length === 4) {
|
|
763
|
-
const basePath = path.join("/");
|
|
764
|
-
let pathString = "";
|
|
765
|
-
if (node.pathParams) {
|
|
766
|
-
let paths = null;
|
|
767
|
-
if (node.pathParams?._def?.typeName !== void 0) {
|
|
768
|
-
try {
|
|
769
|
-
const shape = node.pathParams?.shape;
|
|
770
|
-
paths = shape ? Object.keys(shape) : null;
|
|
771
|
-
} catch {
|
|
772
|
-
paths = null;
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
if (paths?.length) {
|
|
776
|
-
pathString = paths.map((p) => `:${p}`).join("/");
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
uriMap.set(basePath, pathString);
|
|
780
|
-
return;
|
|
781
|
-
}
|
|
782
|
-
for (const key in node) {
|
|
783
|
-
if (!["_type", "fields"].includes(key)) {
|
|
784
|
-
traverse(node[key], [...path, key]);
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
traverse(obj, currentPath);
|
|
789
|
-
return uriMap;
|
|
790
|
-
}
|
|
791
|
-
function scanActionModulesUris(silgi, obj, currentPath = []) {
|
|
792
|
-
const uriMap = {};
|
|
793
|
-
function traverse(node, path = []) {
|
|
794
|
-
if (!node || typeof node !== "object")
|
|
795
|
-
return;
|
|
796
|
-
if (path.length === 4) {
|
|
797
|
-
const basePath = path.join("/");
|
|
798
|
-
let moduleName = "";
|
|
799
|
-
if (node.modules?.graphql) {
|
|
800
|
-
let field = null;
|
|
801
|
-
if (node.modules?.graphql?.field) {
|
|
802
|
-
moduleName = "graphql";
|
|
803
|
-
field = node.modules?.graphql?.field;
|
|
804
|
-
}
|
|
805
|
-
if (!field) {
|
|
806
|
-
return;
|
|
807
|
-
}
|
|
808
|
-
uriMap[moduleName] ??= {};
|
|
809
|
-
if (typeof uriMap[moduleName].field === "object" && uriMap[moduleName].field[field]) {
|
|
810
|
-
silgi.logger.withTag("scanActionModulesUris").error(`Hata ${moduleName} ${field} ${basePath} bu zaten burada kullanilmis.`);
|
|
811
|
-
}
|
|
812
|
-
uriMap[moduleName].field ??= {};
|
|
813
|
-
uriMap[moduleName].field[field] = basePath;
|
|
814
|
-
}
|
|
815
|
-
return;
|
|
816
|
-
}
|
|
817
|
-
for (const key in node) {
|
|
818
|
-
if (!["_type", "fields"].includes(key)) {
|
|
819
|
-
traverse(node[key], [...path, key]);
|
|
820
|
-
}
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
traverse(obj, currentPath);
|
|
824
|
-
return uriMap;
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
async function scanUris(silgi) {
|
|
828
|
-
const { context, object, path } = await readScanFile(silgi);
|
|
829
|
-
const uriMap = traverseObject(silgi, object.schemas, []);
|
|
830
|
-
const modulesURIs = scanActionModulesUris(silgi, object.services, []);
|
|
831
|
-
const uriContent = Array.from(uriMap.entries()).map(([uri, params]) => ` '${uri}': '${params}',`).join("\n");
|
|
832
|
-
let newContext = "";
|
|
833
|
-
if (uriMap.size > 0) {
|
|
834
|
-
newContext = context.replace(
|
|
835
|
-
/export const uris = \{[^}]*\}/,
|
|
836
|
-
`export const uris = {
|
|
837
|
-
${uriContent}
|
|
838
|
-
}`
|
|
839
|
-
).replace(
|
|
840
|
-
/export const modulesURIs = \{[^}]*\}/,
|
|
841
|
-
`export const modulesURIs = ${JSON.stringify(modulesURIs, null, 2)}`
|
|
842
|
-
);
|
|
843
|
-
} else {
|
|
844
|
-
newContext = context;
|
|
845
|
-
}
|
|
846
|
-
await promises.writeFile(path, newContext);
|
|
847
|
-
await readScanFile(silgi);
|
|
848
|
-
}
|
|
849
|
-
|
|
850
807
|
async function writeScanFiles(silgi) {
|
|
851
808
|
const data = await prepareServerFiles(silgi);
|
|
852
809
|
await writeFile(
|
|
853
810
|
resolve(silgi.options.silgi.serverDir, "scan.ts"),
|
|
854
811
|
data.join("\n")
|
|
855
812
|
);
|
|
856
|
-
await
|
|
813
|
+
await readScanFile(silgi);
|
|
814
|
+
buildUriMap(silgi);
|
|
815
|
+
parseServices(silgi);
|
|
816
|
+
silgi.hook("prepare:scan.ts", (file) => {
|
|
817
|
+
file.uris = {
|
|
818
|
+
...file.uris,
|
|
819
|
+
...silgi.uris
|
|
820
|
+
};
|
|
821
|
+
file.modulesURIs = {
|
|
822
|
+
...file.modulesURIs,
|
|
823
|
+
...silgi.modulesURIs
|
|
824
|
+
};
|
|
825
|
+
});
|
|
857
826
|
}
|
|
858
827
|
|
|
859
828
|
function resolveIgnorePatterns(silgi, relativePath) {
|
|
@@ -1692,6 +1661,15 @@ async function prepareCoreFile(data, frameworkContext, silgi) {
|
|
|
1692
1661
|
}
|
|
1693
1662
|
],
|
|
1694
1663
|
from: "./configs.ts"
|
|
1664
|
+
},
|
|
1665
|
+
"rules.ts": {
|
|
1666
|
+
import: [
|
|
1667
|
+
{
|
|
1668
|
+
name: "routeRules",
|
|
1669
|
+
key: "routeRules"
|
|
1670
|
+
}
|
|
1671
|
+
],
|
|
1672
|
+
from: "./rules.ts"
|
|
1695
1673
|
}
|
|
1696
1674
|
};
|
|
1697
1675
|
importItems = { ...data._importItems, ...importItems };
|
|
@@ -1737,6 +1715,7 @@ async function prepareCoreFile(data, frameworkContext, silgi) {
|
|
|
1737
1715
|
" schemas: schemas as any,",
|
|
1738
1716
|
" uris,",
|
|
1739
1717
|
" modulesURIs,",
|
|
1718
|
+
" routeRules: routeRules as any,",
|
|
1740
1719
|
` plugins: [${plugins.join(", ")}],`,
|
|
1741
1720
|
_data._silgiConfigs.length > 0 ? ` ${_data._silgiConfigs.map((config) => typeof config === "string" ? config : typeof config === "object" ? Object.entries(config).map(([key, value]) => `${key}: ${value}`).join(",\n ") : "").join(",\n ")},` : "",
|
|
1742
1721
|
" options: mergeDeep(",
|
|
@@ -1971,7 +1950,8 @@ async function prepareSchema(silgi) {
|
|
|
1971
1950
|
runtimeHooks: [],
|
|
1972
1951
|
runtimeOptions: [],
|
|
1973
1952
|
methods: [],
|
|
1974
|
-
routeRules: []
|
|
1953
|
+
routeRules: [],
|
|
1954
|
+
routeRulesConfig: []
|
|
1975
1955
|
};
|
|
1976
1956
|
await silgi.callHook("prepare:schema.ts", data);
|
|
1977
1957
|
relativeWithDot(silgi.options.build.typesDir, `${silgi.options.silgi.serverDir}/core.ts`);
|
|
@@ -2012,6 +1992,8 @@ async function prepareSchema(silgi) {
|
|
|
2012
1992
|
"",
|
|
2013
1993
|
`type RuntimeRouteRulesExtends = ${data.routeRules?.length ? data.routeRules.map(({ value }) => `${value}`).join(" & ") : "{}"}`,
|
|
2014
1994
|
"",
|
|
1995
|
+
`type RuntimeRouteRulesConfigExtends = ${data.routeRulesConfig?.length ? data.routeRulesConfig.map(({ value }) => `${value}`).join(" & ") : "{}"}`,
|
|
1996
|
+
"",
|
|
2015
1997
|
`type SilgiModuleSharedExtends = ${data.shareds.length ? data.shareds.map(({ value }) => `${value}`).join(" & ") : "{}"}`,
|
|
2016
1998
|
"",
|
|
2017
1999
|
`type SilgiModuleOptionExtend = ${data.options?.length ? data.options.map(({ value }) => `${value}`).join(" & ") : "{}"}`,
|
|
@@ -2074,6 +2056,7 @@ async function prepareSchema(silgi) {
|
|
|
2074
2056
|
" interface SilgiHooks extends ModuleHooksExtend {}",
|
|
2075
2057
|
" interface SilgiRuntimeMethods extends RuntimeMethodExtends {}",
|
|
2076
2058
|
" interface SilgiRuntimeRouteRules extends RuntimeRouteRulesExtends {}",
|
|
2059
|
+
" interface SilgiRuntimeRouteRulesConfig extends RuntimeRouteRulesConfigExtends {}",
|
|
2077
2060
|
"}",
|
|
2078
2061
|
"",
|
|
2079
2062
|
"export {}"
|
package/dist/core/index.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import { getContext } from 'unctx';
|
|
|
6
6
|
import { Buffer } from 'node:buffer';
|
|
7
7
|
import { klona } from 'klona';
|
|
8
8
|
import { createStorage as createStorage$1, builtinDrivers, prefixStorage } from 'unstorage';
|
|
9
|
+
import 'ufo';
|
|
9
10
|
|
|
10
11
|
const silgiCtx = getContext("silgi");
|
|
11
12
|
function useSilgi() {
|
package/dist/kit/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SilgiCLI, ModuleOptionsCustom, ModuleDefinition, SilgiModule, SilgiPreset, SilgiPresetMeta, EnvOptions, SilgiRuntimeConfig, SilgiEvents, SilgiTemplate, ResolvedSilgiTemplate } from 'silgi/types';
|
|
1
|
+
import { SilgiCLI, ModuleOptionsCustom, ModuleDefinition, SilgiModule, ServiceParseModule, SilgiPreset, SilgiPresetMeta, EnvOptions, SilgiRuntimeConfig, SilgiEvents, SilgiTemplate, ResolvedSilgiTemplate } from 'silgi/types';
|
|
2
2
|
import { Buffer } from 'node:buffer';
|
|
3
3
|
import * as consola from 'consola';
|
|
4
4
|
import { ConsolaOptions } from 'consola';
|
|
@@ -34,6 +34,32 @@ declare function defineSilgiModule<TOptions extends ModuleOptionsCustom>(): {
|
|
|
34
34
|
with: <TOptionsDefaults extends Partial<TOptions>>(definition: ModuleDefinition<TOptions, TOptionsDefaults, true> | SilgiModule<TOptions, TOptionsDefaults, true>) => SilgiModule<TOptions, TOptionsDefaults, true>;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* srnResorce: 'coreApi.basket.post.createBasket'
|
|
42
|
+
* const { namespace, serviceName, action, method } = cliResorceParse(srnResorce)
|
|
43
|
+
*
|
|
44
|
+
* namespace: 'coreApi'
|
|
45
|
+
* serviceName: 'basket'
|
|
46
|
+
* action: 'post'
|
|
47
|
+
* method: 'createBasket'
|
|
48
|
+
*
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
declare function serviceParseModule(params: ServiceParseModule): ServiceParseModule;
|
|
52
|
+
declare function parseServices(silgi: SilgiCLI,
|
|
53
|
+
/**
|
|
54
|
+
* url: /coreApi/basket/post/createBasket
|
|
55
|
+
* pathLength: 4 or [1, 2, 3, 4] to support multiple path depths
|
|
56
|
+
* 1: coreApi
|
|
57
|
+
* 2: basket
|
|
58
|
+
* 3: post
|
|
59
|
+
* 4: createBasket
|
|
60
|
+
*/
|
|
61
|
+
pathLength?: number | number[], servicesObject?: Record<string, any>, currentPath?: string[]): Record<string, Record<string, any>>;
|
|
62
|
+
|
|
37
63
|
declare function prettyPath(p: string, highlight?: boolean): string;
|
|
38
64
|
declare function resolveSilgiPath(path: string, silgiCLIOptions: SilgiCLI['options'], base?: string): string;
|
|
39
65
|
|
|
@@ -123,4 +149,4 @@ declare const MODE_RE: RegExp;
|
|
|
123
149
|
declare function hasSilgiModule(moduleKey: string, silgi?: SilgiCLI): boolean;
|
|
124
150
|
declare function hasInstalledModule(moduleKey: string, silgi?: SilgiCLI): boolean;
|
|
125
151
|
|
|
126
|
-
export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, ipAddress, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, useRequest, useSilgiRuntimeConfig, writeFile };
|
|
152
|
+
export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, ipAddress, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useSilgiRuntimeConfig, writeFile };
|
package/dist/kit/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SilgiCLI, ModuleOptionsCustom, ModuleDefinition, SilgiModule, SilgiPreset, SilgiPresetMeta, EnvOptions, SilgiRuntimeConfig, SilgiEvents, SilgiTemplate, ResolvedSilgiTemplate } from 'silgi/types';
|
|
1
|
+
import { SilgiCLI, ModuleOptionsCustom, ModuleDefinition, SilgiModule, ServiceParseModule, SilgiPreset, SilgiPresetMeta, EnvOptions, SilgiRuntimeConfig, SilgiEvents, SilgiTemplate, ResolvedSilgiTemplate } from 'silgi/types';
|
|
2
2
|
import { Buffer } from 'node:buffer';
|
|
3
3
|
import * as consola from 'consola';
|
|
4
4
|
import { ConsolaOptions } from 'consola';
|
|
@@ -34,6 +34,32 @@ declare function defineSilgiModule<TOptions extends ModuleOptionsCustom>(): {
|
|
|
34
34
|
with: <TOptionsDefaults extends Partial<TOptions>>(definition: ModuleDefinition<TOptions, TOptionsDefaults, true> | SilgiModule<TOptions, TOptionsDefaults, true>) => SilgiModule<TOptions, TOptionsDefaults, true>;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* srnResorce: 'coreApi.basket.post.createBasket'
|
|
42
|
+
* const { namespace, serviceName, action, method } = cliResorceParse(srnResorce)
|
|
43
|
+
*
|
|
44
|
+
* namespace: 'coreApi'
|
|
45
|
+
* serviceName: 'basket'
|
|
46
|
+
* action: 'post'
|
|
47
|
+
* method: 'createBasket'
|
|
48
|
+
*
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
declare function serviceParseModule(params: ServiceParseModule): ServiceParseModule;
|
|
52
|
+
declare function parseServices(silgi: SilgiCLI,
|
|
53
|
+
/**
|
|
54
|
+
* url: /coreApi/basket/post/createBasket
|
|
55
|
+
* pathLength: 4 or [1, 2, 3, 4] to support multiple path depths
|
|
56
|
+
* 1: coreApi
|
|
57
|
+
* 2: basket
|
|
58
|
+
* 3: post
|
|
59
|
+
* 4: createBasket
|
|
60
|
+
*/
|
|
61
|
+
pathLength?: number | number[], servicesObject?: Record<string, any>, currentPath?: string[]): Record<string, Record<string, any>>;
|
|
62
|
+
|
|
37
63
|
declare function prettyPath(p: string, highlight?: boolean): string;
|
|
38
64
|
declare function resolveSilgiPath(path: string, silgiCLIOptions: SilgiCLI['options'], base?: string): string;
|
|
39
65
|
|
|
@@ -123,4 +149,4 @@ declare const MODE_RE: RegExp;
|
|
|
123
149
|
declare function hasSilgiModule(moduleKey: string, silgi?: SilgiCLI): boolean;
|
|
124
150
|
declare function hasInstalledModule(moduleKey: string, silgi?: SilgiCLI): boolean;
|
|
125
151
|
|
|
126
|
-
export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, ipAddress, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, useRequest, useSilgiRuntimeConfig, writeFile };
|
|
152
|
+
export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, ipAddress, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useSilgiRuntimeConfig, writeFile };
|
package/dist/kit/index.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import { hash as hash$1 } from 'ohash';
|
|
|
10
10
|
import { camelCase, snakeCase } from 'scule';
|
|
11
11
|
import { useSilgi, tryUseSilgiCLI, useSilgiCLI, tryUseSilgi } from 'silgi/core';
|
|
12
12
|
import { defu } from 'defu';
|
|
13
|
+
import { withLeadingSlash } from 'ufo';
|
|
13
14
|
import { existsSync, promises } from 'node:fs';
|
|
14
15
|
import { fileURLToPath } from 'node:url';
|
|
15
16
|
import { resolveAlias as resolveAlias$1 } from 'pathe/utils';
|
|
@@ -172,6 +173,76 @@ ${issues.toString()}`);
|
|
|
172
173
|
return silgiNormalizedModule;
|
|
173
174
|
}
|
|
174
175
|
|
|
176
|
+
function serviceParseModule(params) {
|
|
177
|
+
return params;
|
|
178
|
+
}
|
|
179
|
+
const parseGraphQLServices = serviceParseModule(({
|
|
180
|
+
node,
|
|
181
|
+
basePath,
|
|
182
|
+
silgi,
|
|
183
|
+
modulesURIs
|
|
184
|
+
}) => {
|
|
185
|
+
const graphql = node.modules?.graphql;
|
|
186
|
+
if (!graphql)
|
|
187
|
+
return;
|
|
188
|
+
const moduleName = "graphql";
|
|
189
|
+
const field = graphql?.field;
|
|
190
|
+
if (!field)
|
|
191
|
+
return;
|
|
192
|
+
modulesURIs[moduleName] ??= {};
|
|
193
|
+
if (typeof modulesURIs[moduleName].field === "object" && modulesURIs[moduleName]?.field?.[field]) {
|
|
194
|
+
silgi.logger.withTag("handleGraphQLModule").error(
|
|
195
|
+
`Hata ${moduleName} ${field} ${basePath} bu zaten burada kullanilmis.`
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
modulesURIs[moduleName].field ??= {};
|
|
199
|
+
modulesURIs[moduleName].field[field] = basePath;
|
|
200
|
+
});
|
|
201
|
+
const parseRouteRules = serviceParseModule(({
|
|
202
|
+
node,
|
|
203
|
+
basePath,
|
|
204
|
+
silgi
|
|
205
|
+
}) => {
|
|
206
|
+
const routeRules = node.routeRules;
|
|
207
|
+
if (!routeRules)
|
|
208
|
+
return;
|
|
209
|
+
let removeMethod = basePath.split("/").slice(0, -1).join("/");
|
|
210
|
+
removeMethod = withLeadingSlash(removeMethod);
|
|
211
|
+
if (routeRules.splat)
|
|
212
|
+
removeMethod = `${removeMethod}/*`;
|
|
213
|
+
else if (routeRules.doubleSplat)
|
|
214
|
+
removeMethod = `${removeMethod}/**`;
|
|
215
|
+
removeMethod = removeMethod.replace(/\/{2,}/g, "/");
|
|
216
|
+
delete routeRules.splat;
|
|
217
|
+
delete routeRules.doubleSplat;
|
|
218
|
+
silgi.routeRules.addRule(removeMethod, routeRules);
|
|
219
|
+
});
|
|
220
|
+
function parseServices(silgi, pathLength = [4, 3, 2, 1], servicesObject, currentPath = []) {
|
|
221
|
+
const modulesURIs = {};
|
|
222
|
+
silgi.options.serviceParseModules.push(parseGraphQLServices);
|
|
223
|
+
silgi.options.serviceParseModules.push(parseRouteRules);
|
|
224
|
+
const pathLengths = Array.isArray(pathLength) ? pathLength : [pathLength];
|
|
225
|
+
function traverse(node, path = []) {
|
|
226
|
+
if (!node || typeof node !== "object")
|
|
227
|
+
return;
|
|
228
|
+
if (pathLengths.includes(path.length)) {
|
|
229
|
+
const basePath = path.join("/");
|
|
230
|
+
for (const handler of silgi.options.serviceParseModules) {
|
|
231
|
+
handler({ node, basePath, silgi, modulesURIs });
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
for (const key in node) {
|
|
235
|
+
if (!["_type", "fields"].includes(key)) {
|
|
236
|
+
traverse(node[key], [...path, key]);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
traverse(servicesObject || silgi.services, currentPath);
|
|
241
|
+
silgi.options.serviceParseModules = [];
|
|
242
|
+
silgi.modulesURIs = defu(modulesURIs, silgi.modulesURIs);
|
|
243
|
+
return modulesURIs;
|
|
244
|
+
}
|
|
245
|
+
|
|
175
246
|
function defineSilgiPreset(preset, meta) {
|
|
176
247
|
if (meta?.url && typeof preset !== "function") ;
|
|
177
248
|
return { ...preset, _meta: meta };
|
|
@@ -494,4 +565,4 @@ function isValidIp(ip) {
|
|
|
494
565
|
return false;
|
|
495
566
|
}
|
|
496
567
|
|
|
497
|
-
export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, getIpAddress, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, ipAddress, isDirectory$1 as isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, useRequest, useSilgiRuntimeConfig, writeFile };
|
|
568
|
+
export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, getIpAddress, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, ipAddress, isDirectory$1 as isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useSilgiRuntimeConfig, writeFile };
|
package/dist/meta/index.d.mts
CHANGED
package/dist/meta/index.d.ts
CHANGED
package/dist/types/index.d.mts
CHANGED
|
@@ -6,7 +6,7 @@ import { Hookable, NestedHooks } from 'hookable';
|
|
|
6
6
|
import { Ignore, Options } from 'ignore';
|
|
7
7
|
import { TSConfig } from 'pkg-types';
|
|
8
8
|
import { PresetName, PresetOptions, PresetNameInput } from 'silgi/presets';
|
|
9
|
-
import { ResolvedServiceType as ResolvedServiceType$1, SilgiRuntimeShareds as SilgiRuntimeShareds$1, SilgiRuntimeOptions as SilgiRuntimeOptions$1, RouteRules as RouteRules$1, ModuleMeta as ModuleMeta$1,
|
|
9
|
+
import { ResolvedServiceType as ResolvedServiceType$1, SilgiRuntimeShareds as SilgiRuntimeShareds$1, SilgiRuntimeOptions as SilgiRuntimeOptions$1, RouteRules as RouteRules$1, ModuleMeta as ModuleMeta$1, SilgiRouteRules as SilgiRouteRules$1, DotenvOptions as DotenvOptions$1, EnvOptions as EnvOptions$1, SilgiRuntimeConfig as SilgiRuntimeConfig$1, ServiceParseModule as ServiceParseModule$1, SilgiCLIHooks as SilgiCLIHooks$1, StorageMounts as StorageMounts$1, SilgiTemplate as SilgiTemplate$1, SilgiFrameworkInfo as SilgiFrameworkInfo$1 } from 'silgi/types';
|
|
10
10
|
import { UnimportPluginOptions } from 'unimport/unplugin';
|
|
11
11
|
import { Defu } from 'defu';
|
|
12
12
|
import { Unimport } from 'unimport';
|
|
@@ -175,6 +175,10 @@ interface SchemaPreparationOptions extends ImportItem {
|
|
|
175
175
|
key: string;
|
|
176
176
|
value: string;
|
|
177
177
|
}[];
|
|
178
|
+
routeRulesConfig: {
|
|
179
|
+
key: string;
|
|
180
|
+
value: string;
|
|
181
|
+
}[];
|
|
178
182
|
contexts: {
|
|
179
183
|
key: string;
|
|
180
184
|
value: string;
|
|
@@ -247,11 +251,11 @@ interface SilgiCLIHooks extends SilgiHooks {
|
|
|
247
251
|
'prepare:core.ts': (data: PrepareCore) => HookResult;
|
|
248
252
|
'after:prepare:core.ts': (content: string[]) => HookResult;
|
|
249
253
|
'prepare:scan.ts': (data: Pick<ImportItem, 'customImports' | 'importItems'> & {
|
|
250
|
-
uris: string
|
|
254
|
+
uris: Record<string, string>;
|
|
251
255
|
services: string[];
|
|
252
256
|
shareds: string[];
|
|
253
257
|
schemas: string[];
|
|
254
|
-
modulesURIs: string
|
|
258
|
+
modulesURIs: Record<string, string>;
|
|
255
259
|
}) => HookResult;
|
|
256
260
|
'after:prepare:scan.ts': (content: string[]) => HookResult;
|
|
257
261
|
'prepare:schema.ts': (options: SchemaPreparationOptions) => HookResult;
|
|
@@ -568,13 +572,14 @@ interface SilgiCLIOptions extends PresetOptions {
|
|
|
568
572
|
command?: string;
|
|
569
573
|
};
|
|
570
574
|
commandType: CommandType;
|
|
571
|
-
routeRules:
|
|
575
|
+
routeRules: SilgiRouteRules$1;
|
|
572
576
|
environments: DotenvOptions$1[];
|
|
573
577
|
activeEnvironment: string;
|
|
574
578
|
envOptions: EnvOptions$1;
|
|
575
579
|
runtimeConfig: SilgiRuntimeConfig$1 & {
|
|
576
580
|
[key: string]: any;
|
|
577
581
|
};
|
|
582
|
+
serviceParseModules: ServiceParseModule$1[];
|
|
578
583
|
storages: string[];
|
|
579
584
|
namespaces: string[];
|
|
580
585
|
hooks: NestedHooks<SilgiCLIHooks$1>;
|
|
@@ -805,6 +810,51 @@ interface EnvOptions {
|
|
|
805
810
|
envExpansion?: boolean;
|
|
806
811
|
}
|
|
807
812
|
|
|
813
|
+
interface DefaultRouteConfig extends SilgiRuntimeRouteRulesConfig {
|
|
814
|
+
splat?: boolean;
|
|
815
|
+
doubleSplat?: boolean;
|
|
816
|
+
[key: string]: any;
|
|
817
|
+
}
|
|
818
|
+
interface DefaultRouteRules extends SilgiRuntimeRouteRules {
|
|
819
|
+
[key: string]: any;
|
|
820
|
+
}
|
|
821
|
+
type SilgiRouteRules = Record<DefaultRouteRules extends string ? DefaultRouteRules : string, DefaultRouteConfig>;
|
|
822
|
+
type RouteConfig<T extends Record<string, any> = DefaultRouteConfig> = T;
|
|
823
|
+
type RouteRulesConfig<T extends Record<string, any> = DefaultRouteConfig> = Record<string, T>;
|
|
824
|
+
type MergedRulesCache<T extends Record<string, any> = DefaultRouteConfig> = Record<string, T>;
|
|
825
|
+
interface SilgiRuntimeRouteRules {
|
|
826
|
+
}
|
|
827
|
+
interface SilgiRuntimeRouteRulesConfig {
|
|
828
|
+
}
|
|
829
|
+
/**
|
|
830
|
+
* Interface for the object returned by createRouteRules
|
|
831
|
+
*/
|
|
832
|
+
interface RouteRules<T extends Record<string, any> = DefaultRouteRules> {
|
|
833
|
+
readonly rules: RouteRulesConfig<T>;
|
|
834
|
+
readonly mergedRules: MergedRulesCache<T>;
|
|
835
|
+
importRules: (config: RouteRulesConfig<T>) => void;
|
|
836
|
+
exportRules: () => RouteRulesConfig<T>;
|
|
837
|
+
addRule: (pattern: string, config: RouteConfig<T>) => void;
|
|
838
|
+
updateRule: (pattern: string, config: Partial<RouteConfig<T>>) => void;
|
|
839
|
+
removeRule: (pattern: string) => void;
|
|
840
|
+
matchesRule: (url: string, pattern: string) => boolean;
|
|
841
|
+
getMatchingPatterns: (url: string) => string[];
|
|
842
|
+
getConfig: (url: string) => RouteConfig<T> | null;
|
|
843
|
+
getParams: (url: string, pattern: string) => Record<string, string> | null;
|
|
844
|
+
match: (url: string) => {
|
|
845
|
+
pattern: string;
|
|
846
|
+
config: RouteConfig<T>;
|
|
847
|
+
params: Record<string, string> | null;
|
|
848
|
+
} | null;
|
|
849
|
+
clear: () => void;
|
|
850
|
+
clearMergedRules: () => void;
|
|
851
|
+
precomputeMergedRules: (urls: string[]) => void;
|
|
852
|
+
setMergedRule: (url: string, config: RouteConfig<T>) => void;
|
|
853
|
+
getMergedRules: () => MergedRulesCache<T>;
|
|
854
|
+
configure: (config: RouteRulesConfig<T>) => void;
|
|
855
|
+
updateMergeRules: () => MergedRulesCache<T>;
|
|
856
|
+
}
|
|
857
|
+
|
|
808
858
|
type CustomDriverName = string & {
|
|
809
859
|
_custom?: any;
|
|
810
860
|
};
|
|
@@ -843,7 +893,11 @@ interface ExtendShared {
|
|
|
843
893
|
|
|
844
894
|
type EventHandlerResponse<T = undefined> = T extends undefined ? void : void | T | Promise<T>;
|
|
845
895
|
type MethodHandlerType<T> = {
|
|
896
|
+
routeRules?: DefaultRouteConfig;
|
|
897
|
+
} & {
|
|
846
898
|
[Action in keyof T]: T[Action] extends Record<string, any> ? {
|
|
899
|
+
routeRules?: DefaultRouteConfig;
|
|
900
|
+
} & {
|
|
847
901
|
[Method in keyof T[Action]]?: {
|
|
848
902
|
default?: {
|
|
849
903
|
input?: StandardSchemaV1.InferInput<T[Action][Method]['input']> & {
|
|
@@ -856,6 +910,7 @@ type MethodHandlerType<T> = {
|
|
|
856
910
|
parameters: StandardSchemaV1.InferInput<T[Action][Method]['pathParams']> & StandardSchemaV1.InferInput<T[Action][Method]['queryParams']>;
|
|
857
911
|
}, shared: SilgiRuntimeShareds, event: SilgiEvents, source: StandardSchemaV1.InferInput<T[Action][Method]['source']>) => EventHandlerResponse<StandardSchemaV1.InferOutput<T[Action][Method]['output']>>;
|
|
858
912
|
modules?: Partial<SilgiRuntimeActions>;
|
|
913
|
+
routeRules?: DefaultRouteConfig;
|
|
859
914
|
storage?: StorageConfig<T[Action][Method]['input']>;
|
|
860
915
|
};
|
|
861
916
|
} : never;
|
|
@@ -868,46 +923,10 @@ interface ResolvedMethodHandlerType {
|
|
|
868
923
|
}, shared: SilgiRuntimeShareds, event: SilgiEvents, source: StandardSchemaV1.InferInput<any>) => Promise<StandardSchemaV1.InferInput<any>>;
|
|
869
924
|
modules?: Partial<SilgiRuntimeActions>;
|
|
870
925
|
storage?: StorageConfig<StandardSchemaV1.InferInput<any>>;
|
|
926
|
+
routeRules?: SilgiRouteRules;
|
|
871
927
|
execute: (input: StandardSchemaV1.InferInput<any>, shared: SilgiRuntimeShareds, event: SilgiEvents, source: StandardSchemaV1.InferInput<any>) => Promise<StandardSchemaV1.InferInput<any>>;
|
|
872
928
|
}
|
|
873
929
|
|
|
874
|
-
type DefaultRouteConfig = Record<string, any>;
|
|
875
|
-
type DefaultRouterRulesConfig = Record<string, DefaultRouteConfig>;
|
|
876
|
-
type DefaultMergedRulesCache = Record<string, DefaultRouteConfig>;
|
|
877
|
-
type RouteConfig<T extends Record<string, any> = DefaultRouteConfig> = T;
|
|
878
|
-
type RouteRulesConfig<T extends Record<string, any> = DefaultRouteConfig> = Record<string, T>;
|
|
879
|
-
type MergedRulesCache<T extends Record<string, any> = DefaultRouteConfig> = Record<string, T>;
|
|
880
|
-
interface SilgiRuntimeRouteRules extends RouteConfig {
|
|
881
|
-
}
|
|
882
|
-
/**
|
|
883
|
-
* Interface for the object returned by createRouteRules
|
|
884
|
-
*/
|
|
885
|
-
interface RouteRules<T extends Record<string, any> = SilgiRuntimeRouteRules> {
|
|
886
|
-
readonly rules: RouteRulesConfig<T>;
|
|
887
|
-
readonly mergedRules: MergedRulesCache<T>;
|
|
888
|
-
importRules: (config: RouteRulesConfig<T>) => void;
|
|
889
|
-
exportRules: () => RouteRulesConfig<T>;
|
|
890
|
-
addRule: (pattern: string, config: RouteConfig<T>) => void;
|
|
891
|
-
updateRule: (pattern: string, config: Partial<RouteConfig<T>>) => void;
|
|
892
|
-
removeRule: (pattern: string) => void;
|
|
893
|
-
matchesRule: (url: string, pattern: string) => boolean;
|
|
894
|
-
getMatchingPatterns: (url: string) => string[];
|
|
895
|
-
getConfig: (url: string) => RouteConfig<T> | null;
|
|
896
|
-
getParams: (url: string, pattern: string) => Record<string, string> | null;
|
|
897
|
-
match: (url: string) => {
|
|
898
|
-
pattern: string;
|
|
899
|
-
config: RouteConfig<T>;
|
|
900
|
-
params: Record<string, string> | null;
|
|
901
|
-
} | null;
|
|
902
|
-
clear: () => void;
|
|
903
|
-
clearMergedRules: () => void;
|
|
904
|
-
precomputeMergedRules: (urls: string[]) => void;
|
|
905
|
-
setMergedRule: (url: string, config: RouteConfig<T>) => void;
|
|
906
|
-
getMergedRules: () => MergedRulesCache<T>;
|
|
907
|
-
configure: (config: RouteRulesConfig<T>) => void;
|
|
908
|
-
updateMergeRules: () => MergedRulesCache<T>;
|
|
909
|
-
}
|
|
910
|
-
|
|
911
930
|
type SilgiServiceInterface<T extends BaseSchemaType<StandardSchemaV1>> = {
|
|
912
931
|
[Action in keyof T]: T[Action] extends Record<string, any> ? {
|
|
913
932
|
[Method in keyof T[Action]]: {
|
|
@@ -927,6 +946,8 @@ type SilgiServiceInterface<T extends BaseSchemaType<StandardSchemaV1>> = {
|
|
|
927
946
|
};
|
|
928
947
|
type ServiceType<T> = Partial<{
|
|
929
948
|
[Namespace in keyof T]: T[Namespace] extends Record<string, any> ? {
|
|
949
|
+
routeRules?: DefaultRouteConfig;
|
|
950
|
+
} & {
|
|
930
951
|
[Service in keyof T[Namespace]]?: Partial<MethodHandlerType<T[Namespace][Service]>>;
|
|
931
952
|
} : never;
|
|
932
953
|
}>;
|
|
@@ -1030,7 +1051,7 @@ interface SilgiRuntimeConfig {
|
|
|
1030
1051
|
}
|
|
1031
1052
|
interface SilgiOptions {
|
|
1032
1053
|
consolaOptions?: Partial<ConsolaOptions>;
|
|
1033
|
-
routeRules:
|
|
1054
|
+
routeRules: SilgiRouteRules;
|
|
1034
1055
|
present: PresetNameInput;
|
|
1035
1056
|
hooks: Partial<SilgiRuntimeHooks & DefaultHooks>;
|
|
1036
1057
|
/**
|
|
@@ -1098,6 +1119,16 @@ type Namespaces<T extends BaseNamespaceType> = {
|
|
|
1098
1119
|
};
|
|
1099
1120
|
};
|
|
1100
1121
|
|
|
1122
|
+
interface ServiceParse {
|
|
1123
|
+
node: ResolvedMethodHandlerType;
|
|
1124
|
+
basePath: string;
|
|
1125
|
+
silgi: SilgiCLI;
|
|
1126
|
+
modulesURIs: Record<string, Record<string, any>>;
|
|
1127
|
+
}
|
|
1128
|
+
interface ServiceParseModule {
|
|
1129
|
+
(params: ServiceParse): Awaited<void> | void;
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1101
1132
|
declare const autoImportTypes: string[];
|
|
1102
1133
|
|
|
1103
|
-
export { type AppConfig, type Awaitable, type BaseNamespaceType, type BaseSchemaType, type BaseSilgiMethodType, type CaptureError, type CapturedErrorContext, type CommandType, type CreateScope, type DeepPartial, type DefaultHooks, type
|
|
1134
|
+
export { type AppConfig, type Awaitable, type BaseNamespaceType, type BaseSchemaType, type BaseSilgiMethodType, type CaptureError, type CapturedErrorContext, type CommandType, type CreateScope, type DeepPartial, type DefaultHooks, type DefaultNamespaces, type DefaultRouteConfig, type DefaultRouteRules, type DotenvOptions, type EnvOptions, type EventHandlerResponse, type ExtendContext, type ExtendShared, type ExtractInputFromURI, type ExtractOutputFromURI, type ExtractPathParamsFromURI, type ExtractQueryParamsFromURI, type ExtractSourceFromURI, type FrameworkContext, type GenerateAppOptions, type GraphQLJSON, type HookResult, type ImportItem, type LoadConfigOptions, type MergedRulesCache, type MergedSilgiSchema, type MethodHandlerType, type ModuleDefinition, type ModuleHookContext, type ModuleMeta, type ModuleOptionsCustom, type ModuleSetupInstallResult, type ModuleSetupReturn, type Namespaces, type NitroBuildInfo, type PrepareCore, type RequiredServiceType, type ResolvedMethodHandlerType, type ResolvedModuleMeta, type ResolvedModuleOptions, type ResolvedServiceType, type ResolvedSilgiTemplate, type RouteConfig, type RouteRules, type RouteRulesConfig, type ScanFile, type SchemaPreparationOptions, type ServiceParse, type ServiceParseModule, type ServiceType, type Silgi, type SilgiAppPlugin, type SilgiCLI, type SilgiCLIConfig, type SilgiCLIDynamicConfig, type SilgiCLIHooks, type SilgiCLIOptions, type SilgiCompatibility, type SilgiCompatibilityIssue, type SilgiCompatibilityIssues, type SilgiConfig, type SilgiEvents, type SilgiFrameworkInfo, type SilgiFunction, type SilgiHooks, type SilgiModule, type SilgiModuleInput, type SilgiModuleOptions, type SilgiNamespaces, type SilgiOperation, type SilgiOptions, type SilgiPreset, type SilgiPresetMeta, type SilgiRouteRules, type SilgiRouterTypes, type SilgiRuntimeActions, type SilgiRuntimeConfig, type SilgiRuntimeContext, type SilgiRuntimeHooks, type SilgiRuntimeMethods, type SilgiRuntimeOptions, type SilgiRuntimeRouteRules, type SilgiRuntimeRouteRulesConfig, type SilgiRuntimeSharedExtends, type SilgiRuntimeShareds, type SilgiSchema, type SilgiServiceInterface, type SilgiStorageBase, type SilgiTemplate, type SilgiURIs, type StorageConfig, type StorageKeyGenerator, type StorageKeyParams, type StorageMounts, type TSReference, type URIsTypes, autoImportTypes };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { Hookable, NestedHooks } from 'hookable';
|
|
|
6
6
|
import { Ignore, Options } from 'ignore';
|
|
7
7
|
import { TSConfig } from 'pkg-types';
|
|
8
8
|
import { PresetName, PresetOptions, PresetNameInput } from 'silgi/presets';
|
|
9
|
-
import { ResolvedServiceType as ResolvedServiceType$1, SilgiRuntimeShareds as SilgiRuntimeShareds$1, SilgiRuntimeOptions as SilgiRuntimeOptions$1, RouteRules as RouteRules$1, ModuleMeta as ModuleMeta$1,
|
|
9
|
+
import { ResolvedServiceType as ResolvedServiceType$1, SilgiRuntimeShareds as SilgiRuntimeShareds$1, SilgiRuntimeOptions as SilgiRuntimeOptions$1, RouteRules as RouteRules$1, ModuleMeta as ModuleMeta$1, SilgiRouteRules as SilgiRouteRules$1, DotenvOptions as DotenvOptions$1, EnvOptions as EnvOptions$1, SilgiRuntimeConfig as SilgiRuntimeConfig$1, ServiceParseModule as ServiceParseModule$1, SilgiCLIHooks as SilgiCLIHooks$1, StorageMounts as StorageMounts$1, SilgiTemplate as SilgiTemplate$1, SilgiFrameworkInfo as SilgiFrameworkInfo$1 } from 'silgi/types';
|
|
10
10
|
import { UnimportPluginOptions } from 'unimport/unplugin';
|
|
11
11
|
import { Defu } from 'defu';
|
|
12
12
|
import { Unimport } from 'unimport';
|
|
@@ -175,6 +175,10 @@ interface SchemaPreparationOptions extends ImportItem {
|
|
|
175
175
|
key: string;
|
|
176
176
|
value: string;
|
|
177
177
|
}[];
|
|
178
|
+
routeRulesConfig: {
|
|
179
|
+
key: string;
|
|
180
|
+
value: string;
|
|
181
|
+
}[];
|
|
178
182
|
contexts: {
|
|
179
183
|
key: string;
|
|
180
184
|
value: string;
|
|
@@ -247,11 +251,11 @@ interface SilgiCLIHooks extends SilgiHooks {
|
|
|
247
251
|
'prepare:core.ts': (data: PrepareCore) => HookResult;
|
|
248
252
|
'after:prepare:core.ts': (content: string[]) => HookResult;
|
|
249
253
|
'prepare:scan.ts': (data: Pick<ImportItem, 'customImports' | 'importItems'> & {
|
|
250
|
-
uris: string
|
|
254
|
+
uris: Record<string, string>;
|
|
251
255
|
services: string[];
|
|
252
256
|
shareds: string[];
|
|
253
257
|
schemas: string[];
|
|
254
|
-
modulesURIs: string
|
|
258
|
+
modulesURIs: Record<string, string>;
|
|
255
259
|
}) => HookResult;
|
|
256
260
|
'after:prepare:scan.ts': (content: string[]) => HookResult;
|
|
257
261
|
'prepare:schema.ts': (options: SchemaPreparationOptions) => HookResult;
|
|
@@ -568,13 +572,14 @@ interface SilgiCLIOptions extends PresetOptions {
|
|
|
568
572
|
command?: string;
|
|
569
573
|
};
|
|
570
574
|
commandType: CommandType;
|
|
571
|
-
routeRules:
|
|
575
|
+
routeRules: SilgiRouteRules$1;
|
|
572
576
|
environments: DotenvOptions$1[];
|
|
573
577
|
activeEnvironment: string;
|
|
574
578
|
envOptions: EnvOptions$1;
|
|
575
579
|
runtimeConfig: SilgiRuntimeConfig$1 & {
|
|
576
580
|
[key: string]: any;
|
|
577
581
|
};
|
|
582
|
+
serviceParseModules: ServiceParseModule$1[];
|
|
578
583
|
storages: string[];
|
|
579
584
|
namespaces: string[];
|
|
580
585
|
hooks: NestedHooks<SilgiCLIHooks$1>;
|
|
@@ -805,6 +810,51 @@ interface EnvOptions {
|
|
|
805
810
|
envExpansion?: boolean;
|
|
806
811
|
}
|
|
807
812
|
|
|
813
|
+
interface DefaultRouteConfig extends SilgiRuntimeRouteRulesConfig {
|
|
814
|
+
splat?: boolean;
|
|
815
|
+
doubleSplat?: boolean;
|
|
816
|
+
[key: string]: any;
|
|
817
|
+
}
|
|
818
|
+
interface DefaultRouteRules extends SilgiRuntimeRouteRules {
|
|
819
|
+
[key: string]: any;
|
|
820
|
+
}
|
|
821
|
+
type SilgiRouteRules = Record<DefaultRouteRules extends string ? DefaultRouteRules : string, DefaultRouteConfig>;
|
|
822
|
+
type RouteConfig<T extends Record<string, any> = DefaultRouteConfig> = T;
|
|
823
|
+
type RouteRulesConfig<T extends Record<string, any> = DefaultRouteConfig> = Record<string, T>;
|
|
824
|
+
type MergedRulesCache<T extends Record<string, any> = DefaultRouteConfig> = Record<string, T>;
|
|
825
|
+
interface SilgiRuntimeRouteRules {
|
|
826
|
+
}
|
|
827
|
+
interface SilgiRuntimeRouteRulesConfig {
|
|
828
|
+
}
|
|
829
|
+
/**
|
|
830
|
+
* Interface for the object returned by createRouteRules
|
|
831
|
+
*/
|
|
832
|
+
interface RouteRules<T extends Record<string, any> = DefaultRouteRules> {
|
|
833
|
+
readonly rules: RouteRulesConfig<T>;
|
|
834
|
+
readonly mergedRules: MergedRulesCache<T>;
|
|
835
|
+
importRules: (config: RouteRulesConfig<T>) => void;
|
|
836
|
+
exportRules: () => RouteRulesConfig<T>;
|
|
837
|
+
addRule: (pattern: string, config: RouteConfig<T>) => void;
|
|
838
|
+
updateRule: (pattern: string, config: Partial<RouteConfig<T>>) => void;
|
|
839
|
+
removeRule: (pattern: string) => void;
|
|
840
|
+
matchesRule: (url: string, pattern: string) => boolean;
|
|
841
|
+
getMatchingPatterns: (url: string) => string[];
|
|
842
|
+
getConfig: (url: string) => RouteConfig<T> | null;
|
|
843
|
+
getParams: (url: string, pattern: string) => Record<string, string> | null;
|
|
844
|
+
match: (url: string) => {
|
|
845
|
+
pattern: string;
|
|
846
|
+
config: RouteConfig<T>;
|
|
847
|
+
params: Record<string, string> | null;
|
|
848
|
+
} | null;
|
|
849
|
+
clear: () => void;
|
|
850
|
+
clearMergedRules: () => void;
|
|
851
|
+
precomputeMergedRules: (urls: string[]) => void;
|
|
852
|
+
setMergedRule: (url: string, config: RouteConfig<T>) => void;
|
|
853
|
+
getMergedRules: () => MergedRulesCache<T>;
|
|
854
|
+
configure: (config: RouteRulesConfig<T>) => void;
|
|
855
|
+
updateMergeRules: () => MergedRulesCache<T>;
|
|
856
|
+
}
|
|
857
|
+
|
|
808
858
|
type CustomDriverName = string & {
|
|
809
859
|
_custom?: any;
|
|
810
860
|
};
|
|
@@ -843,7 +893,11 @@ interface ExtendShared {
|
|
|
843
893
|
|
|
844
894
|
type EventHandlerResponse<T = undefined> = T extends undefined ? void : void | T | Promise<T>;
|
|
845
895
|
type MethodHandlerType<T> = {
|
|
896
|
+
routeRules?: DefaultRouteConfig;
|
|
897
|
+
} & {
|
|
846
898
|
[Action in keyof T]: T[Action] extends Record<string, any> ? {
|
|
899
|
+
routeRules?: DefaultRouteConfig;
|
|
900
|
+
} & {
|
|
847
901
|
[Method in keyof T[Action]]?: {
|
|
848
902
|
default?: {
|
|
849
903
|
input?: StandardSchemaV1.InferInput<T[Action][Method]['input']> & {
|
|
@@ -856,6 +910,7 @@ type MethodHandlerType<T> = {
|
|
|
856
910
|
parameters: StandardSchemaV1.InferInput<T[Action][Method]['pathParams']> & StandardSchemaV1.InferInput<T[Action][Method]['queryParams']>;
|
|
857
911
|
}, shared: SilgiRuntimeShareds, event: SilgiEvents, source: StandardSchemaV1.InferInput<T[Action][Method]['source']>) => EventHandlerResponse<StandardSchemaV1.InferOutput<T[Action][Method]['output']>>;
|
|
858
912
|
modules?: Partial<SilgiRuntimeActions>;
|
|
913
|
+
routeRules?: DefaultRouteConfig;
|
|
859
914
|
storage?: StorageConfig<T[Action][Method]['input']>;
|
|
860
915
|
};
|
|
861
916
|
} : never;
|
|
@@ -868,46 +923,10 @@ interface ResolvedMethodHandlerType {
|
|
|
868
923
|
}, shared: SilgiRuntimeShareds, event: SilgiEvents, source: StandardSchemaV1.InferInput<any>) => Promise<StandardSchemaV1.InferInput<any>>;
|
|
869
924
|
modules?: Partial<SilgiRuntimeActions>;
|
|
870
925
|
storage?: StorageConfig<StandardSchemaV1.InferInput<any>>;
|
|
926
|
+
routeRules?: SilgiRouteRules;
|
|
871
927
|
execute: (input: StandardSchemaV1.InferInput<any>, shared: SilgiRuntimeShareds, event: SilgiEvents, source: StandardSchemaV1.InferInput<any>) => Promise<StandardSchemaV1.InferInput<any>>;
|
|
872
928
|
}
|
|
873
929
|
|
|
874
|
-
type DefaultRouteConfig = Record<string, any>;
|
|
875
|
-
type DefaultRouterRulesConfig = Record<string, DefaultRouteConfig>;
|
|
876
|
-
type DefaultMergedRulesCache = Record<string, DefaultRouteConfig>;
|
|
877
|
-
type RouteConfig<T extends Record<string, any> = DefaultRouteConfig> = T;
|
|
878
|
-
type RouteRulesConfig<T extends Record<string, any> = DefaultRouteConfig> = Record<string, T>;
|
|
879
|
-
type MergedRulesCache<T extends Record<string, any> = DefaultRouteConfig> = Record<string, T>;
|
|
880
|
-
interface SilgiRuntimeRouteRules extends RouteConfig {
|
|
881
|
-
}
|
|
882
|
-
/**
|
|
883
|
-
* Interface for the object returned by createRouteRules
|
|
884
|
-
*/
|
|
885
|
-
interface RouteRules<T extends Record<string, any> = SilgiRuntimeRouteRules> {
|
|
886
|
-
readonly rules: RouteRulesConfig<T>;
|
|
887
|
-
readonly mergedRules: MergedRulesCache<T>;
|
|
888
|
-
importRules: (config: RouteRulesConfig<T>) => void;
|
|
889
|
-
exportRules: () => RouteRulesConfig<T>;
|
|
890
|
-
addRule: (pattern: string, config: RouteConfig<T>) => void;
|
|
891
|
-
updateRule: (pattern: string, config: Partial<RouteConfig<T>>) => void;
|
|
892
|
-
removeRule: (pattern: string) => void;
|
|
893
|
-
matchesRule: (url: string, pattern: string) => boolean;
|
|
894
|
-
getMatchingPatterns: (url: string) => string[];
|
|
895
|
-
getConfig: (url: string) => RouteConfig<T> | null;
|
|
896
|
-
getParams: (url: string, pattern: string) => Record<string, string> | null;
|
|
897
|
-
match: (url: string) => {
|
|
898
|
-
pattern: string;
|
|
899
|
-
config: RouteConfig<T>;
|
|
900
|
-
params: Record<string, string> | null;
|
|
901
|
-
} | null;
|
|
902
|
-
clear: () => void;
|
|
903
|
-
clearMergedRules: () => void;
|
|
904
|
-
precomputeMergedRules: (urls: string[]) => void;
|
|
905
|
-
setMergedRule: (url: string, config: RouteConfig<T>) => void;
|
|
906
|
-
getMergedRules: () => MergedRulesCache<T>;
|
|
907
|
-
configure: (config: RouteRulesConfig<T>) => void;
|
|
908
|
-
updateMergeRules: () => MergedRulesCache<T>;
|
|
909
|
-
}
|
|
910
|
-
|
|
911
930
|
type SilgiServiceInterface<T extends BaseSchemaType<StandardSchemaV1>> = {
|
|
912
931
|
[Action in keyof T]: T[Action] extends Record<string, any> ? {
|
|
913
932
|
[Method in keyof T[Action]]: {
|
|
@@ -927,6 +946,8 @@ type SilgiServiceInterface<T extends BaseSchemaType<StandardSchemaV1>> = {
|
|
|
927
946
|
};
|
|
928
947
|
type ServiceType<T> = Partial<{
|
|
929
948
|
[Namespace in keyof T]: T[Namespace] extends Record<string, any> ? {
|
|
949
|
+
routeRules?: DefaultRouteConfig;
|
|
950
|
+
} & {
|
|
930
951
|
[Service in keyof T[Namespace]]?: Partial<MethodHandlerType<T[Namespace][Service]>>;
|
|
931
952
|
} : never;
|
|
932
953
|
}>;
|
|
@@ -1030,7 +1051,7 @@ interface SilgiRuntimeConfig {
|
|
|
1030
1051
|
}
|
|
1031
1052
|
interface SilgiOptions {
|
|
1032
1053
|
consolaOptions?: Partial<ConsolaOptions>;
|
|
1033
|
-
routeRules:
|
|
1054
|
+
routeRules: SilgiRouteRules;
|
|
1034
1055
|
present: PresetNameInput;
|
|
1035
1056
|
hooks: Partial<SilgiRuntimeHooks & DefaultHooks>;
|
|
1036
1057
|
/**
|
|
@@ -1098,6 +1119,16 @@ type Namespaces<T extends BaseNamespaceType> = {
|
|
|
1098
1119
|
};
|
|
1099
1120
|
};
|
|
1100
1121
|
|
|
1122
|
+
interface ServiceParse {
|
|
1123
|
+
node: ResolvedMethodHandlerType;
|
|
1124
|
+
basePath: string;
|
|
1125
|
+
silgi: SilgiCLI;
|
|
1126
|
+
modulesURIs: Record<string, Record<string, any>>;
|
|
1127
|
+
}
|
|
1128
|
+
interface ServiceParseModule {
|
|
1129
|
+
(params: ServiceParse): Awaited<void> | void;
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1101
1132
|
declare const autoImportTypes: string[];
|
|
1102
1133
|
|
|
1103
|
-
export { type AppConfig, type Awaitable, type BaseNamespaceType, type BaseSchemaType, type BaseSilgiMethodType, type CaptureError, type CapturedErrorContext, type CommandType, type CreateScope, type DeepPartial, type DefaultHooks, type
|
|
1134
|
+
export { type AppConfig, type Awaitable, type BaseNamespaceType, type BaseSchemaType, type BaseSilgiMethodType, type CaptureError, type CapturedErrorContext, type CommandType, type CreateScope, type DeepPartial, type DefaultHooks, type DefaultNamespaces, type DefaultRouteConfig, type DefaultRouteRules, type DotenvOptions, type EnvOptions, type EventHandlerResponse, type ExtendContext, type ExtendShared, type ExtractInputFromURI, type ExtractOutputFromURI, type ExtractPathParamsFromURI, type ExtractQueryParamsFromURI, type ExtractSourceFromURI, type FrameworkContext, type GenerateAppOptions, type GraphQLJSON, type HookResult, type ImportItem, type LoadConfigOptions, type MergedRulesCache, type MergedSilgiSchema, type MethodHandlerType, type ModuleDefinition, type ModuleHookContext, type ModuleMeta, type ModuleOptionsCustom, type ModuleSetupInstallResult, type ModuleSetupReturn, type Namespaces, type NitroBuildInfo, type PrepareCore, type RequiredServiceType, type ResolvedMethodHandlerType, type ResolvedModuleMeta, type ResolvedModuleOptions, type ResolvedServiceType, type ResolvedSilgiTemplate, type RouteConfig, type RouteRules, type RouteRulesConfig, type ScanFile, type SchemaPreparationOptions, type ServiceParse, type ServiceParseModule, type ServiceType, type Silgi, type SilgiAppPlugin, type SilgiCLI, type SilgiCLIConfig, type SilgiCLIDynamicConfig, type SilgiCLIHooks, type SilgiCLIOptions, type SilgiCompatibility, type SilgiCompatibilityIssue, type SilgiCompatibilityIssues, type SilgiConfig, type SilgiEvents, type SilgiFrameworkInfo, type SilgiFunction, type SilgiHooks, type SilgiModule, type SilgiModuleInput, type SilgiModuleOptions, type SilgiNamespaces, type SilgiOperation, type SilgiOptions, type SilgiPreset, type SilgiPresetMeta, type SilgiRouteRules, type SilgiRouterTypes, type SilgiRuntimeActions, type SilgiRuntimeConfig, type SilgiRuntimeContext, type SilgiRuntimeHooks, type SilgiRuntimeMethods, type SilgiRuntimeOptions, type SilgiRuntimeRouteRules, type SilgiRuntimeRouteRulesConfig, type SilgiRuntimeSharedExtends, type SilgiRuntimeShareds, type SilgiSchema, type SilgiServiceInterface, type SilgiStorageBase, type SilgiTemplate, type SilgiURIs, type StorageConfig, type StorageKeyGenerator, type StorageKeyParams, type StorageMounts, type TSReference, type URIsTypes, autoImportTypes };
|