silgi 0.15.0 → 0.16.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/_chunks/index.mjs +1 -1
- package/dist/cli/loader.mjs +2 -1
- package/dist/cli/prepare.mjs +1 -1
- package/dist/cli/writeTypesAndFiles.mjs +156 -173
- package/dist/kit/index.d.mts +28 -2
- package/dist/kit/index.d.ts +28 -2
- package/dist/kit/index.mjs +63 -1
- package/dist/meta/index.d.mts +1 -1
- package/dist/meta/index.d.ts +1 -1
- package/dist/types/index.d.mts +66 -43
- package/dist/types/index.d.ts +66 -43
- package/package.json +1 -1
package/dist/_chunks/index.mjs
CHANGED
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
|
@@ -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/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
|
|
56
|
+
* 1: coreApi
|
|
57
|
+
* 2: basket
|
|
58
|
+
* 3: post
|
|
59
|
+
* 4: createBasket
|
|
60
|
+
*/
|
|
61
|
+
pathLength?: 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
|
|
56
|
+
* 1: coreApi
|
|
57
|
+
* 2: basket
|
|
58
|
+
* 3: post
|
|
59
|
+
* 4: createBasket
|
|
60
|
+
*/
|
|
61
|
+
pathLength?: 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
|
@@ -172,6 +172,68 @@ ${issues.toString()}`);
|
|
|
172
172
|
return silgiNormalizedModule;
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
+
function serviceParseModule(params) {
|
|
176
|
+
return params;
|
|
177
|
+
}
|
|
178
|
+
const parseGraphQLServices = serviceParseModule(({
|
|
179
|
+
node,
|
|
180
|
+
basePath,
|
|
181
|
+
silgi,
|
|
182
|
+
modulesURIs
|
|
183
|
+
}) => {
|
|
184
|
+
const graphql = node.modules?.graphql;
|
|
185
|
+
if (!graphql)
|
|
186
|
+
return;
|
|
187
|
+
const moduleName = "graphql";
|
|
188
|
+
const field = graphql?.field;
|
|
189
|
+
if (!field)
|
|
190
|
+
return;
|
|
191
|
+
modulesURIs[moduleName] ??= {};
|
|
192
|
+
if (typeof modulesURIs[moduleName].field === "object" && modulesURIs[moduleName]?.field?.[field]) {
|
|
193
|
+
silgi.logger.withTag("handleGraphQLModule").error(
|
|
194
|
+
`Hata ${moduleName} ${field} ${basePath} bu zaten burada kullanilmis.`
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
modulesURIs[moduleName].field ??= {};
|
|
198
|
+
modulesURIs[moduleName].field[field] = basePath;
|
|
199
|
+
});
|
|
200
|
+
const parseRouteRules = serviceParseModule(({
|
|
201
|
+
node,
|
|
202
|
+
basePath,
|
|
203
|
+
silgi
|
|
204
|
+
}) => {
|
|
205
|
+
const routeRules = node.routeRules;
|
|
206
|
+
if (!routeRules)
|
|
207
|
+
return;
|
|
208
|
+
const removeMethod = basePath.split("/").slice(0, -1).join("/");
|
|
209
|
+
silgi.routeRules.addRule(removeMethod, routeRules);
|
|
210
|
+
});
|
|
211
|
+
function parseServices(silgi, pathLength = 4, servicesObject, currentPath = []) {
|
|
212
|
+
const modulesURIs = {};
|
|
213
|
+
silgi.options.serviceParseModules.push(parseGraphQLServices);
|
|
214
|
+
silgi.options.serviceParseModules.push(parseRouteRules);
|
|
215
|
+
function traverse(node, path = []) {
|
|
216
|
+
if (!node || typeof node !== "object")
|
|
217
|
+
return;
|
|
218
|
+
if (path.length === pathLength) {
|
|
219
|
+
const basePath = path.join("/");
|
|
220
|
+
for (const handler of silgi.options.serviceParseModules) {
|
|
221
|
+
handler({ node, basePath, silgi, modulesURIs });
|
|
222
|
+
}
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
for (const key in node) {
|
|
226
|
+
if (!["_type", "fields"].includes(key)) {
|
|
227
|
+
traverse(node[key], [...path, key]);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
traverse(servicesObject || silgi.services, currentPath);
|
|
232
|
+
silgi.options.serviceParseModules = [];
|
|
233
|
+
silgi.modulesURIs = defu(modulesURIs, silgi.modulesURIs);
|
|
234
|
+
return modulesURIs;
|
|
235
|
+
}
|
|
236
|
+
|
|
175
237
|
function defineSilgiPreset(preset, meta) {
|
|
176
238
|
if (meta?.url && typeof preset !== "function") ;
|
|
177
239
|
return { ...preset, _meta: meta };
|
|
@@ -494,4 +556,4 @@ function isValidIp(ip) {
|
|
|
494
556
|
return false;
|
|
495
557
|
}
|
|
496
558
|
|
|
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 };
|
|
559
|
+
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,49 @@ interface EnvOptions {
|
|
|
805
810
|
envExpansion?: boolean;
|
|
806
811
|
}
|
|
807
812
|
|
|
813
|
+
interface DefaultRouteConfig extends SilgiRuntimeRouteRulesConfig {
|
|
814
|
+
[key: string]: any;
|
|
815
|
+
}
|
|
816
|
+
interface DefaultRouteRules extends SilgiRuntimeRouteRules {
|
|
817
|
+
[key: string]: any;
|
|
818
|
+
}
|
|
819
|
+
type SilgiRouteRules = Record<DefaultRouteRules extends string ? DefaultRouteRules : string, DefaultRouteConfig>;
|
|
820
|
+
type RouteConfig<T extends Record<string, any> = DefaultRouteConfig> = T;
|
|
821
|
+
type RouteRulesConfig<T extends Record<string, any> = DefaultRouteConfig> = Record<string, T>;
|
|
822
|
+
type MergedRulesCache<T extends Record<string, any> = DefaultRouteConfig> = Record<string, T>;
|
|
823
|
+
interface SilgiRuntimeRouteRules {
|
|
824
|
+
}
|
|
825
|
+
interface SilgiRuntimeRouteRulesConfig {
|
|
826
|
+
}
|
|
827
|
+
/**
|
|
828
|
+
* Interface for the object returned by createRouteRules
|
|
829
|
+
*/
|
|
830
|
+
interface RouteRules<T extends Record<string, any> = DefaultRouteRules> {
|
|
831
|
+
readonly rules: RouteRulesConfig<T>;
|
|
832
|
+
readonly mergedRules: MergedRulesCache<T>;
|
|
833
|
+
importRules: (config: RouteRulesConfig<T>) => void;
|
|
834
|
+
exportRules: () => RouteRulesConfig<T>;
|
|
835
|
+
addRule: (pattern: string, config: RouteConfig<T>) => void;
|
|
836
|
+
updateRule: (pattern: string, config: Partial<RouteConfig<T>>) => void;
|
|
837
|
+
removeRule: (pattern: string) => void;
|
|
838
|
+
matchesRule: (url: string, pattern: string) => boolean;
|
|
839
|
+
getMatchingPatterns: (url: string) => string[];
|
|
840
|
+
getConfig: (url: string) => RouteConfig<T> | null;
|
|
841
|
+
getParams: (url: string, pattern: string) => Record<string, string> | null;
|
|
842
|
+
match: (url: string) => {
|
|
843
|
+
pattern: string;
|
|
844
|
+
config: RouteConfig<T>;
|
|
845
|
+
params: Record<string, string> | null;
|
|
846
|
+
} | null;
|
|
847
|
+
clear: () => void;
|
|
848
|
+
clearMergedRules: () => void;
|
|
849
|
+
precomputeMergedRules: (urls: string[]) => void;
|
|
850
|
+
setMergedRule: (url: string, config: RouteConfig<T>) => void;
|
|
851
|
+
getMergedRules: () => MergedRulesCache<T>;
|
|
852
|
+
configure: (config: RouteRulesConfig<T>) => void;
|
|
853
|
+
updateMergeRules: () => MergedRulesCache<T>;
|
|
854
|
+
}
|
|
855
|
+
|
|
808
856
|
type CustomDriverName = string & {
|
|
809
857
|
_custom?: any;
|
|
810
858
|
};
|
|
@@ -856,6 +904,7 @@ type MethodHandlerType<T> = {
|
|
|
856
904
|
parameters: StandardSchemaV1.InferInput<T[Action][Method]['pathParams']> & StandardSchemaV1.InferInput<T[Action][Method]['queryParams']>;
|
|
857
905
|
}, shared: SilgiRuntimeShareds, event: SilgiEvents, source: StandardSchemaV1.InferInput<T[Action][Method]['source']>) => EventHandlerResponse<StandardSchemaV1.InferOutput<T[Action][Method]['output']>>;
|
|
858
906
|
modules?: Partial<SilgiRuntimeActions>;
|
|
907
|
+
routeRules?: SilgiRouteRules;
|
|
859
908
|
storage?: StorageConfig<T[Action][Method]['input']>;
|
|
860
909
|
};
|
|
861
910
|
} : never;
|
|
@@ -868,46 +917,10 @@ interface ResolvedMethodHandlerType {
|
|
|
868
917
|
}, shared: SilgiRuntimeShareds, event: SilgiEvents, source: StandardSchemaV1.InferInput<any>) => Promise<StandardSchemaV1.InferInput<any>>;
|
|
869
918
|
modules?: Partial<SilgiRuntimeActions>;
|
|
870
919
|
storage?: StorageConfig<StandardSchemaV1.InferInput<any>>;
|
|
920
|
+
routeRules?: SilgiRouteRules;
|
|
871
921
|
execute: (input: StandardSchemaV1.InferInput<any>, shared: SilgiRuntimeShareds, event: SilgiEvents, source: StandardSchemaV1.InferInput<any>) => Promise<StandardSchemaV1.InferInput<any>>;
|
|
872
922
|
}
|
|
873
923
|
|
|
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
924
|
type SilgiServiceInterface<T extends BaseSchemaType<StandardSchemaV1>> = {
|
|
912
925
|
[Action in keyof T]: T[Action] extends Record<string, any> ? {
|
|
913
926
|
[Method in keyof T[Action]]: {
|
|
@@ -1030,7 +1043,7 @@ interface SilgiRuntimeConfig {
|
|
|
1030
1043
|
}
|
|
1031
1044
|
interface SilgiOptions {
|
|
1032
1045
|
consolaOptions?: Partial<ConsolaOptions>;
|
|
1033
|
-
routeRules:
|
|
1046
|
+
routeRules: SilgiRouteRules;
|
|
1034
1047
|
present: PresetNameInput;
|
|
1035
1048
|
hooks: Partial<SilgiRuntimeHooks & DefaultHooks>;
|
|
1036
1049
|
/**
|
|
@@ -1098,6 +1111,16 @@ type Namespaces<T extends BaseNamespaceType> = {
|
|
|
1098
1111
|
};
|
|
1099
1112
|
};
|
|
1100
1113
|
|
|
1114
|
+
interface ServiceParse {
|
|
1115
|
+
node: ResolvedMethodHandlerType;
|
|
1116
|
+
basePath: string;
|
|
1117
|
+
silgi: SilgiCLI;
|
|
1118
|
+
modulesURIs: Record<string, Record<string, any>>;
|
|
1119
|
+
}
|
|
1120
|
+
interface ServiceParseModule {
|
|
1121
|
+
(params: ServiceParse): Awaited<void> | void;
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1101
1124
|
declare const autoImportTypes: string[];
|
|
1102
1125
|
|
|
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
|
|
1126
|
+
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 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,49 @@ interface EnvOptions {
|
|
|
805
810
|
envExpansion?: boolean;
|
|
806
811
|
}
|
|
807
812
|
|
|
813
|
+
interface DefaultRouteConfig extends SilgiRuntimeRouteRulesConfig {
|
|
814
|
+
[key: string]: any;
|
|
815
|
+
}
|
|
816
|
+
interface DefaultRouteRules extends SilgiRuntimeRouteRules {
|
|
817
|
+
[key: string]: any;
|
|
818
|
+
}
|
|
819
|
+
type SilgiRouteRules = Record<DefaultRouteRules extends string ? DefaultRouteRules : string, DefaultRouteConfig>;
|
|
820
|
+
type RouteConfig<T extends Record<string, any> = DefaultRouteConfig> = T;
|
|
821
|
+
type RouteRulesConfig<T extends Record<string, any> = DefaultRouteConfig> = Record<string, T>;
|
|
822
|
+
type MergedRulesCache<T extends Record<string, any> = DefaultRouteConfig> = Record<string, T>;
|
|
823
|
+
interface SilgiRuntimeRouteRules {
|
|
824
|
+
}
|
|
825
|
+
interface SilgiRuntimeRouteRulesConfig {
|
|
826
|
+
}
|
|
827
|
+
/**
|
|
828
|
+
* Interface for the object returned by createRouteRules
|
|
829
|
+
*/
|
|
830
|
+
interface RouteRules<T extends Record<string, any> = DefaultRouteRules> {
|
|
831
|
+
readonly rules: RouteRulesConfig<T>;
|
|
832
|
+
readonly mergedRules: MergedRulesCache<T>;
|
|
833
|
+
importRules: (config: RouteRulesConfig<T>) => void;
|
|
834
|
+
exportRules: () => RouteRulesConfig<T>;
|
|
835
|
+
addRule: (pattern: string, config: RouteConfig<T>) => void;
|
|
836
|
+
updateRule: (pattern: string, config: Partial<RouteConfig<T>>) => void;
|
|
837
|
+
removeRule: (pattern: string) => void;
|
|
838
|
+
matchesRule: (url: string, pattern: string) => boolean;
|
|
839
|
+
getMatchingPatterns: (url: string) => string[];
|
|
840
|
+
getConfig: (url: string) => RouteConfig<T> | null;
|
|
841
|
+
getParams: (url: string, pattern: string) => Record<string, string> | null;
|
|
842
|
+
match: (url: string) => {
|
|
843
|
+
pattern: string;
|
|
844
|
+
config: RouteConfig<T>;
|
|
845
|
+
params: Record<string, string> | null;
|
|
846
|
+
} | null;
|
|
847
|
+
clear: () => void;
|
|
848
|
+
clearMergedRules: () => void;
|
|
849
|
+
precomputeMergedRules: (urls: string[]) => void;
|
|
850
|
+
setMergedRule: (url: string, config: RouteConfig<T>) => void;
|
|
851
|
+
getMergedRules: () => MergedRulesCache<T>;
|
|
852
|
+
configure: (config: RouteRulesConfig<T>) => void;
|
|
853
|
+
updateMergeRules: () => MergedRulesCache<T>;
|
|
854
|
+
}
|
|
855
|
+
|
|
808
856
|
type CustomDriverName = string & {
|
|
809
857
|
_custom?: any;
|
|
810
858
|
};
|
|
@@ -856,6 +904,7 @@ type MethodHandlerType<T> = {
|
|
|
856
904
|
parameters: StandardSchemaV1.InferInput<T[Action][Method]['pathParams']> & StandardSchemaV1.InferInput<T[Action][Method]['queryParams']>;
|
|
857
905
|
}, shared: SilgiRuntimeShareds, event: SilgiEvents, source: StandardSchemaV1.InferInput<T[Action][Method]['source']>) => EventHandlerResponse<StandardSchemaV1.InferOutput<T[Action][Method]['output']>>;
|
|
858
906
|
modules?: Partial<SilgiRuntimeActions>;
|
|
907
|
+
routeRules?: SilgiRouteRules;
|
|
859
908
|
storage?: StorageConfig<T[Action][Method]['input']>;
|
|
860
909
|
};
|
|
861
910
|
} : never;
|
|
@@ -868,46 +917,10 @@ interface ResolvedMethodHandlerType {
|
|
|
868
917
|
}, shared: SilgiRuntimeShareds, event: SilgiEvents, source: StandardSchemaV1.InferInput<any>) => Promise<StandardSchemaV1.InferInput<any>>;
|
|
869
918
|
modules?: Partial<SilgiRuntimeActions>;
|
|
870
919
|
storage?: StorageConfig<StandardSchemaV1.InferInput<any>>;
|
|
920
|
+
routeRules?: SilgiRouteRules;
|
|
871
921
|
execute: (input: StandardSchemaV1.InferInput<any>, shared: SilgiRuntimeShareds, event: SilgiEvents, source: StandardSchemaV1.InferInput<any>) => Promise<StandardSchemaV1.InferInput<any>>;
|
|
872
922
|
}
|
|
873
923
|
|
|
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
924
|
type SilgiServiceInterface<T extends BaseSchemaType<StandardSchemaV1>> = {
|
|
912
925
|
[Action in keyof T]: T[Action] extends Record<string, any> ? {
|
|
913
926
|
[Method in keyof T[Action]]: {
|
|
@@ -1030,7 +1043,7 @@ interface SilgiRuntimeConfig {
|
|
|
1030
1043
|
}
|
|
1031
1044
|
interface SilgiOptions {
|
|
1032
1045
|
consolaOptions?: Partial<ConsolaOptions>;
|
|
1033
|
-
routeRules:
|
|
1046
|
+
routeRules: SilgiRouteRules;
|
|
1034
1047
|
present: PresetNameInput;
|
|
1035
1048
|
hooks: Partial<SilgiRuntimeHooks & DefaultHooks>;
|
|
1036
1049
|
/**
|
|
@@ -1098,6 +1111,16 @@ type Namespaces<T extends BaseNamespaceType> = {
|
|
|
1098
1111
|
};
|
|
1099
1112
|
};
|
|
1100
1113
|
|
|
1114
|
+
interface ServiceParse {
|
|
1115
|
+
node: ResolvedMethodHandlerType;
|
|
1116
|
+
basePath: string;
|
|
1117
|
+
silgi: SilgiCLI;
|
|
1118
|
+
modulesURIs: Record<string, Record<string, any>>;
|
|
1119
|
+
}
|
|
1120
|
+
interface ServiceParseModule {
|
|
1121
|
+
(params: ServiceParse): Awaited<void> | void;
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1101
1124
|
declare const autoImportTypes: string[];
|
|
1102
1125
|
|
|
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
|
|
1126
|
+
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 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 };
|