silgi 0.33.2 → 0.34.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/build.mjs +1 -2
- package/dist/cli/build.mjs +35 -309
- package/dist/cli/index.mjs +1 -1
- package/dist/cli/init.mjs +1 -2
- package/dist/cli/install.mjs +13 -2
- package/dist/cli/types.mjs +2 -10
- package/dist/cli/watch.mjs +1 -2
- package/dist/core/index.d.mts +293 -210
- package/dist/core/index.mjs +670 -465
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +3 -3
- package/dist/kit/index.d.mts +5 -31
- package/dist/kit/index.mjs +1 -55
- package/dist/runtime/internal/config.d.mts +2 -2
- package/dist/runtime/internal/next.d.mts +1 -1
- package/dist/runtime/internal/next.mjs +51 -37
- package/dist/runtime/internal/nitro.d.mts +1 -1
- package/dist/runtime/internal/nitro.mjs +87 -61
- package/dist/types/index.d.mts +418 -448
- package/package.json +6 -2
- package/dist/_chunks/routeRules.mjs +0 -288
package/dist/build.mjs
CHANGED
|
@@ -11,8 +11,6 @@ import 'hookable';
|
|
|
11
11
|
import 'silgi/kit';
|
|
12
12
|
import 'silgi/runtime/meta';
|
|
13
13
|
import 'unimport';
|
|
14
|
-
import './_chunks/routeRules.mjs';
|
|
15
|
-
import 'ufo';
|
|
16
14
|
import '@clack/prompts';
|
|
17
15
|
import 'node:fs';
|
|
18
16
|
import 'dotenv';
|
|
@@ -24,6 +22,7 @@ import 'silgi/meta';
|
|
|
24
22
|
import 'node:url';
|
|
25
23
|
import 'defu';
|
|
26
24
|
import 'exsolve';
|
|
25
|
+
import 'ufo';
|
|
27
26
|
import 'node:fs/promises';
|
|
28
27
|
import 'globby';
|
|
29
28
|
import 'ignore';
|
package/dist/cli/build.mjs
CHANGED
|
@@ -2,10 +2,9 @@ import { consola } from 'consola';
|
|
|
2
2
|
import { createHooks, createDebugger } from 'hookable';
|
|
3
3
|
import { resolve, join, relative, extname, basename, dirname, isAbsolute } from 'pathe';
|
|
4
4
|
import { useSilgiCLI, replaceRuntimeValues, silgiCLICtx, autoImportTypes } from 'silgi';
|
|
5
|
-
import { isPresents, addTemplate, addCoreFile, relativeWithDot, hash, resolveAlias, directoryToURL, removeExtension, addImports, baseHeaderBannerComment, writeFile,
|
|
5
|
+
import { isPresents, addTemplate, addCoreFile, relativeWithDot, hash, resolveAlias, directoryToURL, removeExtension, addImports, baseHeaderBannerComment, writeFile, normalizeTemplate, useLogger, resolveSilgiPath, hasSilgiModule, genEnsureSafeVar, toArray, isDirectory } from 'silgi/kit';
|
|
6
6
|
import { runtimeDir } from 'silgi/runtime/meta';
|
|
7
7
|
import { scanExports, createUnimport, toExports } from 'unimport';
|
|
8
|
-
import { c as createRouteRules } from '../_chunks/routeRules.mjs';
|
|
9
8
|
import * as p from '@clack/prompts';
|
|
10
9
|
import { existsSync, promises, readFileSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
11
10
|
import * as dotenv from 'dotenv';
|
|
@@ -19,7 +18,7 @@ import { isRelative, withTrailingSlash } from 'ufo';
|
|
|
19
18
|
import { readFile, readdir } from 'node:fs/promises';
|
|
20
19
|
import { globby } from 'globby';
|
|
21
20
|
import ignore from 'ignore';
|
|
22
|
-
import { genImport, genTypeImport,
|
|
21
|
+
import { genImport, genTypeImport, genAugmentation, genObjectFromRawEntries } from 'knitwork';
|
|
23
22
|
import { klona } from 'klona';
|
|
24
23
|
import { useSilgiRuntimeConfig, initRuntimeConfig } from 'silgi/runtime';
|
|
25
24
|
import { createStorage, builtinDrivers } from 'unstorage';
|
|
@@ -416,32 +415,6 @@ async function registerModuleExportScan(silgi) {
|
|
|
416
415
|
});
|
|
417
416
|
options.methods.push({ key: configKey, value: importName });
|
|
418
417
|
}
|
|
419
|
-
if (hasTypeExport("ModuleRuntimeRouteRules")) {
|
|
420
|
-
const importName = hash(`${configKey}ModuleRuntimeRouteRules`);
|
|
421
|
-
options.addImportItemType({
|
|
422
|
-
imports: [
|
|
423
|
-
{
|
|
424
|
-
as: importName,
|
|
425
|
-
name: "ModuleRuntimeRouteRules"
|
|
426
|
-
}
|
|
427
|
-
],
|
|
428
|
-
specifier
|
|
429
|
-
});
|
|
430
|
-
options.routeRules.push({ key: configKey, value: importName });
|
|
431
|
-
}
|
|
432
|
-
if (hasTypeExport("ModuleRuntimeRouteRulesConfig")) {
|
|
433
|
-
const importName = hash(`${configKey}ModuleRuntimeRouteRulesConfig`);
|
|
434
|
-
options.addImportItemType({
|
|
435
|
-
imports: [
|
|
436
|
-
{
|
|
437
|
-
as: importName,
|
|
438
|
-
name: "ModuleRuntimeRouteRulesConfig"
|
|
439
|
-
}
|
|
440
|
-
],
|
|
441
|
-
specifier
|
|
442
|
-
});
|
|
443
|
-
options.routeRulesConfig.push({ key: configKey, value: importName });
|
|
444
|
-
}
|
|
445
418
|
}
|
|
446
419
|
});
|
|
447
420
|
}
|
|
@@ -791,7 +764,8 @@ function categorizeExports(exportedEntities, filePath) {
|
|
|
791
764
|
const functionExportCategories = {
|
|
792
765
|
createService: "service",
|
|
793
766
|
createSchema: "schema",
|
|
794
|
-
createShared: "shared"
|
|
767
|
+
createShared: "shared",
|
|
768
|
+
createRoute: "route"
|
|
795
769
|
};
|
|
796
770
|
for (const [functionName, category] of Object.entries(functionExportCategories)) {
|
|
797
771
|
const matchingExports = exportedEntities.filter((entity) => entity.funcName === functionName);
|
|
@@ -843,6 +817,9 @@ function registerExportsWithHooks(silgiInstance, runtimeExports, typeExports) {
|
|
|
843
817
|
case "schema":
|
|
844
818
|
options.schemas.push(uniqueId);
|
|
845
819
|
break;
|
|
820
|
+
case "route":
|
|
821
|
+
options.routers.push(uniqueId);
|
|
822
|
+
break;
|
|
846
823
|
}
|
|
847
824
|
options.addImportItem({
|
|
848
825
|
specifier: removeExtension(relativeWithDot(silgiInstance.options.silgi.serverDir, path)),
|
|
@@ -946,42 +923,6 @@ async function scanExportFile(silgiInstance) {
|
|
|
946
923
|
}
|
|
947
924
|
}
|
|
948
925
|
|
|
949
|
-
function buildUriMap(silgi, currentPath = []) {
|
|
950
|
-
const uriMap = /* @__PURE__ */ new Map();
|
|
951
|
-
function traverse(node, path = []) {
|
|
952
|
-
if (!node || typeof node !== "object")
|
|
953
|
-
return;
|
|
954
|
-
if (path.length === 4) {
|
|
955
|
-
const basePath = path.join("/");
|
|
956
|
-
let pathString = "";
|
|
957
|
-
if (node.pathParams) {
|
|
958
|
-
let paths = null;
|
|
959
|
-
if (node.pathParams?._def?.typeName !== void 0) {
|
|
960
|
-
try {
|
|
961
|
-
const shape = node.pathParams?.shape;
|
|
962
|
-
paths = shape ? Object.keys(shape) : null;
|
|
963
|
-
} catch {
|
|
964
|
-
paths = null;
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
if (paths?.length) {
|
|
968
|
-
pathString = paths.map((p) => `:${p}`).join("/");
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
uriMap.set(basePath, pathString);
|
|
972
|
-
return;
|
|
973
|
-
}
|
|
974
|
-
for (const key in node) {
|
|
975
|
-
if (!["_type", "fields"].includes(key)) {
|
|
976
|
-
traverse(node[key], [...path, key]);
|
|
977
|
-
}
|
|
978
|
-
}
|
|
979
|
-
}
|
|
980
|
-
traverse(silgi.schemas, currentPath);
|
|
981
|
-
silgi.uris = defu(silgi.uris, Object.fromEntries(uriMap));
|
|
982
|
-
return uriMap;
|
|
983
|
-
}
|
|
984
|
-
|
|
985
926
|
async function readScanFile(silgi) {
|
|
986
927
|
const path = resolve(silgi.options.silgi.serverDir, "scan.ts");
|
|
987
928
|
const context = await promises.readFile(path, { encoding: "utf-8" });
|
|
@@ -1013,19 +954,15 @@ ${injectedResult.code}`;
|
|
|
1013
954
|
return (await silgi.unimport.injectImports(data, name)).code;
|
|
1014
955
|
}
|
|
1015
956
|
);
|
|
1016
|
-
silgi.
|
|
1017
|
-
silgi.
|
|
1018
|
-
silgi.
|
|
1019
|
-
silgi.shareds = defu(scanFile.shareds, scanFile.shareds) || {};
|
|
1020
|
-
silgi.modulesURIs = defu(scanFile.modulesURIs, scanFile.modulesURIs) || {};
|
|
957
|
+
silgi.schemas = scanFile.schemas || {};
|
|
958
|
+
silgi.services = scanFile.services || {};
|
|
959
|
+
silgi.shareds = scanFile.shareds || {};
|
|
1021
960
|
return {
|
|
1022
961
|
context,
|
|
1023
962
|
object: {
|
|
1024
963
|
schemas: scanFile.schemas,
|
|
1025
|
-
uris: scanFile.uris,
|
|
1026
964
|
services: scanFile.services,
|
|
1027
|
-
shareds: scanFile.shareds
|
|
1028
|
-
modulesURIs: scanFile.modulesURIs
|
|
965
|
+
shareds: scanFile.shareds
|
|
1029
966
|
},
|
|
1030
967
|
path
|
|
1031
968
|
};
|
|
@@ -1039,10 +976,8 @@ ${injectedResult.code}`;
|
|
|
1039
976
|
context,
|
|
1040
977
|
object: {
|
|
1041
978
|
schemas: {},
|
|
1042
|
-
uris: {},
|
|
1043
979
|
services: {},
|
|
1044
|
-
shareds: {}
|
|
1045
|
-
modulesURIs: {}
|
|
980
|
+
shareds: {}
|
|
1046
981
|
},
|
|
1047
982
|
path
|
|
1048
983
|
};
|
|
@@ -1060,6 +995,9 @@ async function prepareScanFile(silgi) {
|
|
|
1060
995
|
},
|
|
1061
996
|
{
|
|
1062
997
|
name: "createShared"
|
|
998
|
+
},
|
|
999
|
+
{
|
|
1000
|
+
name: "deepMergeObjects"
|
|
1063
1001
|
}
|
|
1064
1002
|
]
|
|
1065
1003
|
},
|
|
@@ -1087,50 +1025,14 @@ async function prepareScanFile(silgi) {
|
|
|
1087
1025
|
]
|
|
1088
1026
|
});
|
|
1089
1027
|
const scanned = {
|
|
1090
|
-
uris: {},
|
|
1091
1028
|
services: [],
|
|
1092
1029
|
shareds: [],
|
|
1030
|
+
routers: [],
|
|
1093
1031
|
schemas: [],
|
|
1094
|
-
modulesURIs: {},
|
|
1095
1032
|
addImportItem,
|
|
1096
1033
|
addImportItemType
|
|
1097
1034
|
};
|
|
1098
|
-
if (silgi.uris) {
|
|
1099
|
-
defu(scanned.uris, silgi.uris);
|
|
1100
|
-
}
|
|
1101
|
-
if (silgi.modulesURIs) {
|
|
1102
|
-
scanned.shareds.push(
|
|
1103
|
-
`createShared({
|
|
1104
|
-
modulesURIs,
|
|
1105
|
-
})`
|
|
1106
|
-
);
|
|
1107
|
-
defu(scanned.modulesURIs, silgi.modulesURIs);
|
|
1108
|
-
}
|
|
1109
1035
|
await silgi.callHook("before:scan.ts", scanned);
|
|
1110
|
-
if (scanned.services.length > 0) {
|
|
1111
|
-
addImportItem({
|
|
1112
|
-
specifier: "silgi",
|
|
1113
|
-
imports: {
|
|
1114
|
-
name: "mergeServices"
|
|
1115
|
-
}
|
|
1116
|
-
});
|
|
1117
|
-
}
|
|
1118
|
-
if (scanned.shareds.length > 0) {
|
|
1119
|
-
addImportItem({
|
|
1120
|
-
specifier: "silgi",
|
|
1121
|
-
imports: {
|
|
1122
|
-
name: "mergeShared"
|
|
1123
|
-
}
|
|
1124
|
-
});
|
|
1125
|
-
}
|
|
1126
|
-
if (scanned.schemas.length > 0) {
|
|
1127
|
-
addImportItem({
|
|
1128
|
-
specifier: "silgi",
|
|
1129
|
-
imports: {
|
|
1130
|
-
name: "mergeSchemas"
|
|
1131
|
-
}
|
|
1132
|
-
});
|
|
1133
|
-
}
|
|
1134
1036
|
const importsContent = [
|
|
1135
1037
|
...genImports.map(({ specifier, imports, options }) => {
|
|
1136
1038
|
return genImport(specifier, imports, options);
|
|
@@ -1141,27 +1043,31 @@ async function prepareScanFile(silgi) {
|
|
|
1141
1043
|
""
|
|
1142
1044
|
];
|
|
1143
1045
|
const importData = [
|
|
1144
|
-
`export const uris = ${JSON.stringify(scanned.uris, null, 2)}`,
|
|
1145
1046
|
"",
|
|
1146
|
-
|
|
1147
|
-
"",
|
|
1148
|
-
scanned.schemas.length > 0 ? "export const schemas = mergeSchemas([" : "export const schemas = {",
|
|
1047
|
+
scanned.schemas.length > 0 ? "export const schemas = deepMergeObjects([" : "export const schemas = {",
|
|
1149
1048
|
...scanned.schemas.map((name) => {
|
|
1150
1049
|
return ` ${name},`;
|
|
1151
1050
|
}),
|
|
1152
1051
|
scanned.schemas.length > 0 ? "])" : "}",
|
|
1153
1052
|
"",
|
|
1154
|
-
scanned.services.length > 0 ? "export const services =
|
|
1053
|
+
scanned.services.length > 0 ? "export const services = deepMergeObjects([" : "export const services = {",
|
|
1155
1054
|
...scanned.services.map((name) => {
|
|
1156
1055
|
return ` ${name},`;
|
|
1157
1056
|
}),
|
|
1158
1057
|
scanned.services.length > 0 ? "])" : "}",
|
|
1159
1058
|
"",
|
|
1160
|
-
scanned.shareds.length > 0 ? "export const shareds =
|
|
1059
|
+
scanned.shareds.length > 0 ? "export const shareds = deepMergeObjects([" : "export const shareds = {",
|
|
1161
1060
|
...scanned.shareds.map((name) => {
|
|
1162
1061
|
return ` ${name},`;
|
|
1163
1062
|
}),
|
|
1063
|
+
"",
|
|
1164
1064
|
scanned.shareds.length > 0 ? "])" : "}",
|
|
1065
|
+
"",
|
|
1066
|
+
scanned.routers.length > 0 ? "export const routers = deepMergeObjects([" : "export const routers = {",
|
|
1067
|
+
...scanned.routers.map((name) => {
|
|
1068
|
+
return ` ${name},`;
|
|
1069
|
+
}),
|
|
1070
|
+
scanned.routers.length > 0 ? "])" : "}",
|
|
1165
1071
|
""
|
|
1166
1072
|
];
|
|
1167
1073
|
await silgi.callHook("after:scan.ts", importData);
|
|
@@ -1179,18 +1085,6 @@ async function writeScanFiles(silgi) {
|
|
|
1179
1085
|
);
|
|
1180
1086
|
}
|
|
1181
1087
|
await readScanFile(silgi);
|
|
1182
|
-
buildUriMap(silgi);
|
|
1183
|
-
parseServices(silgi);
|
|
1184
|
-
silgi.hook("before:scan.ts", (file) => {
|
|
1185
|
-
file.uris = {
|
|
1186
|
-
...file.uris,
|
|
1187
|
-
...silgi.uris
|
|
1188
|
-
};
|
|
1189
|
-
file.modulesURIs = {
|
|
1190
|
-
...file.modulesURIs,
|
|
1191
|
-
...silgi.modulesURIs
|
|
1192
|
-
};
|
|
1193
|
-
});
|
|
1194
1088
|
}
|
|
1195
1089
|
|
|
1196
1090
|
async function createStorageCLI(silgi) {
|
|
@@ -1441,10 +1335,8 @@ async function createSilgiCLI(config = {}, opts = {}) {
|
|
|
1441
1335
|
const options = await loadOptions(config, opts);
|
|
1442
1336
|
const hooks = createHooks();
|
|
1443
1337
|
const silgi = {
|
|
1444
|
-
modulesURIs: {},
|
|
1445
1338
|
scannedURIs: /* @__PURE__ */ new Map(),
|
|
1446
1339
|
services: {},
|
|
1447
|
-
uris: {},
|
|
1448
1340
|
shareds: {},
|
|
1449
1341
|
schemas: {},
|
|
1450
1342
|
unimport: void 0,
|
|
@@ -1462,7 +1354,6 @@ async function createSilgiCLI(config = {}, opts = {}) {
|
|
|
1462
1354
|
hook: hooks.hook,
|
|
1463
1355
|
async updateConfig(_config) {
|
|
1464
1356
|
},
|
|
1465
|
-
routeRules: void 0,
|
|
1466
1357
|
adapters: {}
|
|
1467
1358
|
};
|
|
1468
1359
|
if (silgi.options.adapters && Object.keys(silgi.options.adapters)?.length > 0) {
|
|
@@ -1471,9 +1362,6 @@ async function createSilgiCLI(config = {}, opts = {}) {
|
|
|
1471
1362
|
}
|
|
1472
1363
|
}
|
|
1473
1364
|
await prepareEnv(options);
|
|
1474
|
-
const routeRules = createRouteRules();
|
|
1475
|
-
routeRules.importRules(options.routeRules ?? {});
|
|
1476
|
-
silgi.routeRules = routeRules;
|
|
1477
1365
|
if (silgiCLICtx.tryUse()) {
|
|
1478
1366
|
silgiCLICtx.unset();
|
|
1479
1367
|
silgiCLICtx.set(silgi);
|
|
@@ -1525,11 +1413,6 @@ async function createSilgiCLI(config = {}, opts = {}) {
|
|
|
1525
1413
|
imports: autoImportTypes.map((type) => type),
|
|
1526
1414
|
type: true
|
|
1527
1415
|
});
|
|
1528
|
-
silgi.options.imports.presets.push({
|
|
1529
|
-
from: "silgi/types",
|
|
1530
|
-
imports: autoImportTypes.map((type) => type),
|
|
1531
|
-
type: true
|
|
1532
|
-
});
|
|
1533
1416
|
silgi.options.imports.presets.push({
|
|
1534
1417
|
from: "silgi/runtime/internal/ofetch",
|
|
1535
1418
|
imports: ["createSilgiFetch", "silgi$fetch"]
|
|
@@ -1583,44 +1466,6 @@ async function generateApiFul(silgi) {
|
|
|
1583
1466
|
async function prepare(_silgi) {
|
|
1584
1467
|
}
|
|
1585
1468
|
|
|
1586
|
-
async function exportRules(silgi) {
|
|
1587
|
-
try {
|
|
1588
|
-
if (!silgi?.routeRules?.exportRules) {
|
|
1589
|
-
throw new Error("Invalid silgi configuration: routeRules or exportRules is undefined");
|
|
1590
|
-
}
|
|
1591
|
-
const exportedRules = silgi.routeRules.exportRules();
|
|
1592
|
-
if (!exportedRules || typeof exportedRules !== "object") {
|
|
1593
|
-
throw new Error("No valid route rules to export");
|
|
1594
|
-
}
|
|
1595
|
-
const content = `/* eslint-disable */
|
|
1596
|
-
// @ts-nocheck
|
|
1597
|
-
// This file is auto-generated at build time by Silgi
|
|
1598
|
-
// Contains route rules with preserved functions
|
|
1599
|
-
// DO NOT MODIFY THIS FILE DIRECTLY
|
|
1600
|
-
|
|
1601
|
-
export const routeRules = ${genObjectFromRawEntries(
|
|
1602
|
-
Object.entries(exportedRules).map(([key, value]) => {
|
|
1603
|
-
if (typeof value === "function") {
|
|
1604
|
-
return [key, genObjectFromRaw(value)];
|
|
1605
|
-
}
|
|
1606
|
-
return [key, genObjectFromValues(value)];
|
|
1607
|
-
})
|
|
1608
|
-
)}
|
|
1609
|
-
`;
|
|
1610
|
-
const serverDir = silgi.options.silgi.serverDir;
|
|
1611
|
-
if (!serverDir) {
|
|
1612
|
-
throw new Error("Server directory not defined in configuration");
|
|
1613
|
-
}
|
|
1614
|
-
const file = join(serverDir, "rules.ts");
|
|
1615
|
-
if (!silgi.errors.length) {
|
|
1616
|
-
await writeFile(file, content);
|
|
1617
|
-
}
|
|
1618
|
-
} catch (error) {
|
|
1619
|
-
console.error("\u274C Failed to prepare build:", error instanceof Error ? error.message : String(error));
|
|
1620
|
-
throw error;
|
|
1621
|
-
}
|
|
1622
|
-
}
|
|
1623
|
-
|
|
1624
1469
|
function debugMode(name) {
|
|
1625
1470
|
const silgi = useSilgiCLI$1();
|
|
1626
1471
|
if (silgi.options.debug === true || typeof silgi.options.debug === "object" && silgi.options.debug[name]) {
|
|
@@ -1736,9 +1581,6 @@ async function prepareCoreFile(silgi) {
|
|
|
1736
1581
|
{
|
|
1737
1582
|
specifier: "./scan",
|
|
1738
1583
|
imports: [
|
|
1739
|
-
{
|
|
1740
|
-
name: "uris"
|
|
1741
|
-
},
|
|
1742
1584
|
{
|
|
1743
1585
|
name: "services"
|
|
1744
1586
|
},
|
|
@@ -1747,9 +1589,6 @@ async function prepareCoreFile(silgi) {
|
|
|
1747
1589
|
},
|
|
1748
1590
|
{
|
|
1749
1591
|
name: "schemas"
|
|
1750
|
-
},
|
|
1751
|
-
{
|
|
1752
|
-
name: "modulesURIs"
|
|
1753
1592
|
}
|
|
1754
1593
|
]
|
|
1755
1594
|
},
|
|
@@ -1840,8 +1679,6 @@ async function prepareCoreFile(silgi) {
|
|
|
1840
1679
|
" shared: shareds,",
|
|
1841
1680
|
" services: services,",
|
|
1842
1681
|
" schemas: schemas,",
|
|
1843
|
-
" uris,",
|
|
1844
|
-
" modulesURIs,",
|
|
1845
1682
|
` plugins: [${plugins.join(", ")}],`,
|
|
1846
1683
|
"",
|
|
1847
1684
|
_data.silgiConfigs.length > 0 ? _data.silgiConfigs.map((item) => {
|
|
@@ -1894,100 +1731,9 @@ async function writeCoreFile(silgi) {
|
|
|
1894
1731
|
}
|
|
1895
1732
|
}
|
|
1896
1733
|
|
|
1897
|
-
async function generateRouterDTS(silgi) {
|
|
1898
|
-
const uris = silgi.uris;
|
|
1899
|
-
const subPath = "srn";
|
|
1900
|
-
const groupedPaths = /* @__PURE__ */ new Map();
|
|
1901
|
-
Object.entries(uris || {}).forEach(([key, params]) => {
|
|
1902
|
-
const [service, resource, method, action] = key.split("/");
|
|
1903
|
-
const basePath = params ? `${subPath}/${service}/${resource}/${action}/${params}` : `${subPath}/${service}/${resource}/${action}`;
|
|
1904
|
-
const fullPath = `${subPath}/${service}/${resource}/${action}`;
|
|
1905
|
-
if (!groupedPaths.has(basePath)) {
|
|
1906
|
-
groupedPaths.set(basePath, /* @__PURE__ */ new Map());
|
|
1907
|
-
}
|
|
1908
|
-
groupedPaths.get(basePath)?.set(method.toLowerCase(), fullPath);
|
|
1909
|
-
});
|
|
1910
|
-
const keys = [
|
|
1911
|
-
" keys: {",
|
|
1912
|
-
Array.from(groupedPaths.entries()).map(([basePath, methods]) => {
|
|
1913
|
-
return ` '/${basePath}': {${Array.from(methods.entries()).map(([method, path]) => `
|
|
1914
|
-
${method}: '/${path}'`).join(",")}
|
|
1915
|
-
}`;
|
|
1916
|
-
}).join(",\n"),
|
|
1917
|
-
" }",
|
|
1918
|
-
""
|
|
1919
|
-
].join("\n");
|
|
1920
|
-
const groupedRoutes = Object.entries(uris || {}).reduce((acc, [key, _params]) => {
|
|
1921
|
-
const [service, resource, method, action] = key.split("/");
|
|
1922
|
-
const routePath = `${subPath}/${service}/${resource}/${action}`;
|
|
1923
|
-
if (!acc[routePath]) {
|
|
1924
|
-
acc[routePath] = {};
|
|
1925
|
-
}
|
|
1926
|
-
acc[routePath][method] = {
|
|
1927
|
-
input: `ExtractInputFromURI<'${key}'>`,
|
|
1928
|
-
output: `ExtractOutputFromURI<'${key}'>`,
|
|
1929
|
-
queryParams: `ExtractQueryParamsFromURI<'${key}'>`,
|
|
1930
|
-
pathParams: `ExtractPathParamsFromURI<'${key}'>`
|
|
1931
|
-
};
|
|
1932
|
-
return acc;
|
|
1933
|
-
}, {});
|
|
1934
|
-
const routerTypes = Object.entries(groupedRoutes).map(([path, methods]) => {
|
|
1935
|
-
const methodEntries = Object.entries(methods).map(([method, { input, output, queryParams, pathParams }]) => {
|
|
1936
|
-
return ` '${method}': {
|
|
1937
|
-
input: ${input},
|
|
1938
|
-
output: ${output},
|
|
1939
|
-
queryParams: ${queryParams},
|
|
1940
|
-
pathParams: ${pathParams}
|
|
1941
|
-
}`;
|
|
1942
|
-
}).join(",\n");
|
|
1943
|
-
return ` '/${path}': {
|
|
1944
|
-
${methodEntries}
|
|
1945
|
-
}`;
|
|
1946
|
-
});
|
|
1947
|
-
const nitro = [
|
|
1948
|
-
"declare module 'nitropack/types' {",
|
|
1949
|
-
" interface InternalApi extends RouterTypes {}",
|
|
1950
|
-
"}"
|
|
1951
|
-
];
|
|
1952
|
-
const content = [
|
|
1953
|
-
keys.slice(0, -1),
|
|
1954
|
-
// son satırdaki boş satırı kaldır
|
|
1955
|
-
...routerTypes
|
|
1956
|
-
].join(",\n");
|
|
1957
|
-
const context = [
|
|
1958
|
-
"import type { ExtractInputFromURI, ExtractOutputFromURI, ExtractQueryParamsFromURI, ExtractPathParamsFromURI } from 'silgi/types'",
|
|
1959
|
-
"",
|
|
1960
|
-
"export interface RouterTypes {",
|
|
1961
|
-
content,
|
|
1962
|
-
"}",
|
|
1963
|
-
"",
|
|
1964
|
-
"declare module 'silgi/types' {",
|
|
1965
|
-
" interface SilgiRouterTypes extends RouterTypes {",
|
|
1966
|
-
" }",
|
|
1967
|
-
"}",
|
|
1968
|
-
"",
|
|
1969
|
-
silgi.options.preset === "h3" || silgi.options.preset === "nitro" ? nitro.join("\n") : "",
|
|
1970
|
-
"",
|
|
1971
|
-
"export {}"
|
|
1972
|
-
];
|
|
1973
|
-
return context;
|
|
1974
|
-
}
|
|
1975
|
-
|
|
1976
1734
|
async function prepareSchema(silgi) {
|
|
1977
1735
|
const { genImports, genTypeImports, addImportItem, addImportItemType } = addImports({
|
|
1978
|
-
imports: [
|
|
1979
|
-
{
|
|
1980
|
-
specifier: relativeWithDot(
|
|
1981
|
-
silgi.options.build.typesDir,
|
|
1982
|
-
`${silgi.options.silgi.serverDir}/scan`
|
|
1983
|
-
),
|
|
1984
|
-
imports: [
|
|
1985
|
-
{
|
|
1986
|
-
name: "modulesURIs"
|
|
1987
|
-
}
|
|
1988
|
-
]
|
|
1989
|
-
}
|
|
1990
|
-
],
|
|
1736
|
+
imports: [],
|
|
1991
1737
|
typeImports: [
|
|
1992
1738
|
{
|
|
1993
1739
|
specifier: "silgi/types",
|
|
@@ -1995,9 +1741,6 @@ async function prepareSchema(silgi) {
|
|
|
1995
1741
|
{
|
|
1996
1742
|
name: "URIsTypes"
|
|
1997
1743
|
},
|
|
1998
|
-
{
|
|
1999
|
-
name: "Namespaces"
|
|
2000
|
-
},
|
|
2001
1744
|
{
|
|
2002
1745
|
name: "SilgiRuntimeContext"
|
|
2003
1746
|
}
|
|
@@ -2011,19 +1754,12 @@ async function prepareSchema(silgi) {
|
|
|
2011
1754
|
options: [],
|
|
2012
1755
|
contexts: [],
|
|
2013
1756
|
actions: [],
|
|
2014
|
-
shareds: [
|
|
2015
|
-
{
|
|
2016
|
-
key: "modulesURIs",
|
|
2017
|
-
value: "{ modulesURIs: typeof modulesURIs }"
|
|
2018
|
-
}
|
|
2019
|
-
],
|
|
1757
|
+
shareds: [],
|
|
2020
1758
|
events: [],
|
|
2021
1759
|
hooks: [],
|
|
2022
1760
|
runtimeHooks: [],
|
|
2023
1761
|
runtimeOptions: [],
|
|
2024
|
-
methods: []
|
|
2025
|
-
routeRules: [],
|
|
2026
|
-
routeRulesConfig: []
|
|
1762
|
+
methods: []
|
|
2027
1763
|
};
|
|
2028
1764
|
await silgi.callHook("before:schema.ts", data);
|
|
2029
1765
|
const silgiScanTS = relativeWithDot(silgi.options.build.typesDir, `${silgi.options.silgi.serverDir}/scan`);
|
|
@@ -2053,9 +1789,9 @@ async function prepareSchema(silgi) {
|
|
|
2053
1789
|
}
|
|
2054
1790
|
),
|
|
2055
1791
|
"",
|
|
2056
|
-
`type SchemaExtends =
|
|
2057
|
-
|
|
2058
|
-
`type
|
|
1792
|
+
`type SchemaExtends = typeof import('${silgiScanTS}')['schemas']`,
|
|
1793
|
+
`type BaseServices = typeof import('${silgiScanTS}')['services']`,
|
|
1794
|
+
`type RoutersExtend = typeof import('${silgiScanTS}')['routers']`,
|
|
2059
1795
|
"",
|
|
2060
1796
|
`type SilgiModuleContextExtends = ${data.contexts.length ? data.contexts.map(({ value }) => value).join(" & ") : "{}"}`,
|
|
2061
1797
|
"",
|
|
@@ -2072,10 +1808,6 @@ async function prepareSchema(silgi) {
|
|
|
2072
1808
|
"",
|
|
2073
1809
|
`type RuntimeMethodExtends = ${data.methods?.length ? data.methods.map(({ value }) => `${value}`).join(" & ") : "{}"}`,
|
|
2074
1810
|
"",
|
|
2075
|
-
`type RuntimeRouteRulesExtends = ${data.routeRules?.length ? data.routeRules.map(({ value }) => `${value}`).join(" & ") : "{}"}`,
|
|
2076
|
-
"",
|
|
2077
|
-
`type RuntimeRouteRulesConfigExtends = ${data.routeRulesConfig?.length ? data.routeRulesConfig.map(({ value }) => `${value}`).join(" & ") : "{}"}`,
|
|
2078
|
-
"",
|
|
2079
1811
|
`type SilgiModuleSharedExtends = ${data.shareds.length ? data.shareds.map(({ value }) => `${value}`).join(" & ") : "{}"}`,
|
|
2080
1812
|
"",
|
|
2081
1813
|
`type SilgiModuleOptionExtend = ${data.options?.length ? data.options.map(({ value }) => `${value}`).join(" & ") : "{}"}`,
|
|
@@ -2127,11 +1859,12 @@ async function prepareSchema(silgi) {
|
|
|
2127
1859
|
genAugmentation("silgi/types", {
|
|
2128
1860
|
FrameworkContext: [{}, { extends: ["FrameworkContextExtends"] }],
|
|
2129
1861
|
SilgiSchema: [{}, { extends: ["SchemaExtends"] }],
|
|
1862
|
+
ServicesObject: [{}, { extends: ["BaseServices"] }],
|
|
2130
1863
|
SilgiNamespaces: [{}, { extends: ["InferredNamespaces"] }],
|
|
2131
1864
|
SilgiStorageBase: [{}, { extends: ["SilgiStorageBaseExtends"] }],
|
|
2132
1865
|
SilgiURIs: [{}, { extends: ["SilgiURIsMerge"] }],
|
|
2133
1866
|
SilgiRuntimeContext: [{}, { extends: ["SilgiModuleContextExtends"] }],
|
|
2134
|
-
|
|
1867
|
+
SilgiEvent: [{}, { extends: ["SilgiModuleEventsExtends"] }],
|
|
2135
1868
|
SilgiRuntimeSharedsExtend: [{}, { extends: ["SilgiModuleSharedExtends"] }],
|
|
2136
1869
|
SilgiRuntimeActions: [{}, { extends: ["RuntimeActionExtends"] }],
|
|
2137
1870
|
SilgiRuntimeOptions: [{}, { extends: ["SilgiRuntimeOptionExtends"] }],
|
|
@@ -2139,8 +1872,7 @@ async function prepareSchema(silgi) {
|
|
|
2139
1872
|
SilgiRuntimeConfig: [{}, { extends: ["SilgiRuntimeConfigExtends"] }],
|
|
2140
1873
|
SilgiHooks: [{}, { extends: ["ModuleHooksExtend"] }],
|
|
2141
1874
|
SilgiRuntimeMethods: [{}, { extends: ["RuntimeMethodExtends"] }],
|
|
2142
|
-
|
|
2143
|
-
SilgiRuntimeRouteRulesConfig: [{}, { extends: ["RuntimeRouteRulesConfigExtends"] }],
|
|
1875
|
+
Routers: [{}, { extends: ["RoutersExtend"] }],
|
|
2144
1876
|
SilgiModuleOptions: [{}, { extends: ["SilgiModuleOptionExtend"] }]
|
|
2145
1877
|
}).replace(/,\s*/g, "\n"),
|
|
2146
1878
|
"",
|
|
@@ -2152,7 +1884,6 @@ async function prepareSchema(silgi) {
|
|
|
2152
1884
|
}
|
|
2153
1885
|
|
|
2154
1886
|
async function writeTypesAndFiles(silgi) {
|
|
2155
|
-
const routerDTS = await generateRouterDTS(silgi);
|
|
2156
1887
|
silgi.hook("prepare:types", (opts) => {
|
|
2157
1888
|
opts.references.push({ path: "./schema.d.ts" });
|
|
2158
1889
|
opts.references.push({ path: "./silgi-routes.d.ts" });
|
|
@@ -2209,10 +1940,6 @@ async function writeTypesAndFiles(silgi) {
|
|
|
2209
1940
|
];
|
|
2210
1941
|
}
|
|
2211
1942
|
const buildFiles = [];
|
|
2212
|
-
buildFiles.push({
|
|
2213
|
-
path: join(typesDir, "silgi-routes.d.ts"),
|
|
2214
|
-
contents: routerDTS.join("\n")
|
|
2215
|
-
});
|
|
2216
1943
|
buildFiles.push({
|
|
2217
1944
|
path: join(typesDir, "silgi-imports.d.ts"),
|
|
2218
1945
|
contents: [...autoImportedTypes, autoImportExports || "export {}"].join(
|
|
@@ -2246,7 +1973,6 @@ async function build(silgi) {
|
|
|
2246
1973
|
await generateApiFul(silgi);
|
|
2247
1974
|
await prepareCommands(silgi);
|
|
2248
1975
|
await writeCoreFile(silgi);
|
|
2249
|
-
await exportRules(silgi);
|
|
2250
1976
|
await writeTypesAndFiles(silgi);
|
|
2251
1977
|
await generateApp(silgi);
|
|
2252
1978
|
}
|
package/dist/cli/index.mjs
CHANGED
package/dist/cli/init.mjs
CHANGED
|
@@ -12,8 +12,6 @@ import 'silgi';
|
|
|
12
12
|
import 'silgi/kit';
|
|
13
13
|
import 'silgi/runtime/meta';
|
|
14
14
|
import 'unimport';
|
|
15
|
-
import '../_chunks/routeRules.mjs';
|
|
16
|
-
import 'ufo';
|
|
17
15
|
import 'dotenv';
|
|
18
16
|
import 'mlly';
|
|
19
17
|
import 'dev-jiti';
|
|
@@ -22,6 +20,7 @@ import 'semver/functions/satisfies.js';
|
|
|
22
20
|
import 'node:url';
|
|
23
21
|
import 'defu';
|
|
24
22
|
import 'exsolve';
|
|
23
|
+
import 'ufo';
|
|
25
24
|
import 'globby';
|
|
26
25
|
import 'ignore';
|
|
27
26
|
import 'knitwork';
|
package/dist/cli/install.mjs
CHANGED
|
@@ -12,8 +12,6 @@ import 'hookable';
|
|
|
12
12
|
import 'silgi';
|
|
13
13
|
import 'silgi/runtime/meta';
|
|
14
14
|
import 'unimport';
|
|
15
|
-
import '../_chunks/routeRules.mjs';
|
|
16
|
-
import 'ufo';
|
|
17
15
|
import '@clack/prompts';
|
|
18
16
|
import 'node:fs';
|
|
19
17
|
import 'dotenv';
|
|
@@ -24,6 +22,7 @@ import 'semver/functions/satisfies.js';
|
|
|
24
22
|
import 'node:url';
|
|
25
23
|
import 'defu';
|
|
26
24
|
import 'exsolve';
|
|
25
|
+
import 'ufo';
|
|
27
26
|
import 'node:fs/promises';
|
|
28
27
|
import 'globby';
|
|
29
28
|
import 'ignore';
|
|
@@ -45,6 +44,18 @@ import 'pathe/utils';
|
|
|
45
44
|
import 'untyped';
|
|
46
45
|
|
|
47
46
|
async function installPackages(silgi = useSilgiCLI()) {
|
|
47
|
+
await addNPMPackage([
|
|
48
|
+
{
|
|
49
|
+
name: "zod-to-json-schema",
|
|
50
|
+
isDev: false,
|
|
51
|
+
when: silgi.options.schemaVendor === "zod"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: "@valibot/to-json-schema",
|
|
55
|
+
isDev: false,
|
|
56
|
+
when: silgi.options.schemaVendor === "valibot"
|
|
57
|
+
}
|
|
58
|
+
]);
|
|
48
59
|
await addNPMPackage([
|
|
49
60
|
{
|
|
50
61
|
name: "@fastify/deepmerge",
|