silgi 0.29.27 → 0.29.29
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 +2 -0
- package/dist/cli/index.mjs +1 -1
- package/dist/cli/init.mjs +2 -2
- package/dist/cli/install.mjs +1 -1
- package/dist/cli/prepare.mjs +4 -62
- package/dist/cli/silgi.mjs +75 -27
- package/dist/cli/types.mjs +1 -0
- package/dist/kit/index.mjs +14 -1
- package/dist/types/index.d.mts +2 -1
- package/package.json +1 -1
package/dist/build.mjs
CHANGED
package/dist/cli/index.mjs
CHANGED
package/dist/cli/init.mjs
CHANGED
|
@@ -10,6 +10,8 @@ import 'silgi/meta';
|
|
|
10
10
|
import './silgi.mjs';
|
|
11
11
|
import 'apiful/openapi';
|
|
12
12
|
import 'knitwork';
|
|
13
|
+
import '../_chunks/silgiApp.mjs';
|
|
14
|
+
import 'unctx';
|
|
13
15
|
import 'mlly';
|
|
14
16
|
import 'pathe/utils';
|
|
15
17
|
import 'silgi/runtime/meta';
|
|
@@ -42,8 +44,6 @@ import 'silgi/runtime';
|
|
|
42
44
|
import 'unstorage';
|
|
43
45
|
import 'scule';
|
|
44
46
|
import 'node:child_process';
|
|
45
|
-
import '../_chunks/silgiApp.mjs';
|
|
46
|
-
import 'unctx';
|
|
47
47
|
|
|
48
48
|
const command = defineCommand({
|
|
49
49
|
meta: {
|
package/dist/cli/install.mjs
CHANGED
|
@@ -116,7 +116,7 @@ const command = defineCommand({
|
|
|
116
116
|
return;
|
|
117
117
|
}
|
|
118
118
|
const cleanPackageName = (name, version) => {
|
|
119
|
-
const cleanVersion = version.replace(/^
|
|
119
|
+
const cleanVersion = version.replace(/^(>=|<=|>|<)/, "^");
|
|
120
120
|
return `${name}@${cleanVersion}`;
|
|
121
121
|
};
|
|
122
122
|
const deps = Object.entries(packages.dependencies || {}).map(([name, version]) => cleanPackageName(name, version)).join(" ");
|
package/dist/cli/prepare.mjs
CHANGED
|
@@ -7,10 +7,8 @@ import * as p from '@clack/prompts';
|
|
|
7
7
|
import { isCancel, cancel } from '@clack/prompts';
|
|
8
8
|
import { consola } from 'consola';
|
|
9
9
|
import { createJiti } from 'dev-jiti';
|
|
10
|
-
import { useSilgiCLI
|
|
11
|
-
import {
|
|
12
|
-
import { addTemplate } from 'silgi/kit';
|
|
13
|
-
import { generateTypes, resolveSchema } from 'untyped';
|
|
10
|
+
import { useSilgiCLI } from 'silgi';
|
|
11
|
+
import { a as silgiCLIIClose } from '../_chunks/silgiApp.mjs';
|
|
14
12
|
import { l as loadOptions } from './types.mjs';
|
|
15
13
|
|
|
16
14
|
const commonArgs = {
|
|
@@ -25,62 +23,6 @@ const commonArgs = {
|
|
|
25
23
|
}
|
|
26
24
|
};
|
|
27
25
|
|
|
28
|
-
function debugMode(name) {
|
|
29
|
-
const silgi = useSilgiCLI();
|
|
30
|
-
if (silgi.options.debug === true || typeof silgi.options.debug === "object" && silgi.options.debug[name]) {
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async function scanCommands(silgi = useSilgiCLI()) {
|
|
37
|
-
const commands = [];
|
|
38
|
-
await silgi.callHook("prepare:commands", commands);
|
|
39
|
-
if (debugMode("command")) {
|
|
40
|
-
addTemplate({
|
|
41
|
-
filename: "cli.json",
|
|
42
|
-
where: ".silgi",
|
|
43
|
-
write: true,
|
|
44
|
-
getContents: () => JSON.stringify(commands, null, 2)
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
silgi.hook("before:schema.ts", async () => {
|
|
48
|
-
const allTags = commands.reduce((acc, commandGroup) => {
|
|
49
|
-
Object.values(commandGroup).forEach((command) => {
|
|
50
|
-
if (command.tags) {
|
|
51
|
-
command.tags.forEach((tag) => acc.add(tag));
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
return acc;
|
|
55
|
-
}, /* @__PURE__ */ new Set());
|
|
56
|
-
const data = [
|
|
57
|
-
"",
|
|
58
|
-
generateTypes(
|
|
59
|
-
await resolveSchema(
|
|
60
|
-
{
|
|
61
|
-
...Object.fromEntries(Array.from(allTags.values()).map((tag) => [tag, "string"]))
|
|
62
|
-
}
|
|
63
|
-
),
|
|
64
|
-
{
|
|
65
|
-
interfaceName: "SilgiCommandsExtended",
|
|
66
|
-
addExport: false,
|
|
67
|
-
addDefaults: false,
|
|
68
|
-
allowExtraKeys: false,
|
|
69
|
-
indentation: 0
|
|
70
|
-
}
|
|
71
|
-
),
|
|
72
|
-
""
|
|
73
|
-
];
|
|
74
|
-
addTemplate({
|
|
75
|
-
filename: "types/commands.d.ts",
|
|
76
|
-
write: true,
|
|
77
|
-
where: ".silgi",
|
|
78
|
-
getContents: () => data.join("\n")
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
return commands;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
26
|
function cancelOnCancel({
|
|
85
27
|
value,
|
|
86
28
|
message = "Cancelled",
|
|
@@ -123,11 +65,11 @@ const command$1 = defineCommand({
|
|
|
123
65
|
rawArgs: ["--commandType", "run"]
|
|
124
66
|
});
|
|
125
67
|
}
|
|
126
|
-
const silgi = useSilgiCLI
|
|
68
|
+
const silgi = useSilgiCLI();
|
|
127
69
|
if (!silgi) {
|
|
128
70
|
throw new Error("Silgi is not initialized");
|
|
129
71
|
}
|
|
130
|
-
const commands =
|
|
72
|
+
const commands = silgi.options.commands;
|
|
131
73
|
globalThis.__nitro__ = globalThis.__nitro__ || {};
|
|
132
74
|
globalThis.__nitro__.useRuntimeConfig = function() {
|
|
133
75
|
return silgi?.options?.runtimeConfig || {};
|
package/dist/cli/silgi.mjs
CHANGED
|
@@ -4,7 +4,8 @@ import { join, resolve, dirname, relative, isAbsolute, basename, extname } from
|
|
|
4
4
|
import { hasSilgiModule, addTemplate, normalizeTemplate, useLogger, genEnsureSafeVar, baseHeaderBannerComment, addImports, hash, toArray, writeFile, relativeWithDot, isDirectory, isPresents, addCoreFile, resolveAlias as resolveAlias$1, directoryToURL, hasError, parseServices, resolveSilgiPath } from 'silgi/kit';
|
|
5
5
|
import { mkdirSync, existsSync, writeFileSync, promises, readFileSync } from 'node:fs';
|
|
6
6
|
import { readdir, readFile } from 'node:fs/promises';
|
|
7
|
-
import { genObjectFromRawEntries, genImport, genTypeImport, genObjectFromRaw, genObjectFromValues } from 'knitwork';
|
|
7
|
+
import { genAugmentation, genObjectFromRawEntries, genImport, genTypeImport, genObjectFromRaw, genObjectFromValues } from 'knitwork';
|
|
8
|
+
import { u as useSilgiCLI } from '../_chunks/silgiApp.mjs';
|
|
8
9
|
import { resolvePath, parseNodeModulePath, lookupNodeModuleSubpath, resolveModuleExportNames, findTypeExports, findExports } from 'mlly';
|
|
9
10
|
import { resolveAlias } from 'pathe/utils';
|
|
10
11
|
import { runtimeDir } from 'silgi/runtime/meta';
|
|
@@ -12,7 +13,7 @@ import { toExports, scanExports, createUnimport } from 'unimport';
|
|
|
12
13
|
import { generateTypes, resolveSchema } from 'untyped';
|
|
13
14
|
import { s as silgiGenerateType, l as loadOptions } from './types.mjs';
|
|
14
15
|
import { createHooks, createDebugger } from 'hookable';
|
|
15
|
-
import { useSilgiCLI, replaceRuntimeValues, silgiCLICtx, autoImportTypes } from 'silgi';
|
|
16
|
+
import { useSilgiCLI as useSilgiCLI$1, replaceRuntimeValues, silgiCLICtx, autoImportTypes } from 'silgi';
|
|
16
17
|
import { c as createRouteRules } from '../_chunks/routeRules.mjs';
|
|
17
18
|
import * as p from '@clack/prompts';
|
|
18
19
|
import * as dotenv from 'dotenv';
|
|
@@ -192,6 +193,55 @@ async function compileTemplate(template, ctx) {
|
|
|
192
193
|
async function prepare(_silgi) {
|
|
193
194
|
}
|
|
194
195
|
|
|
196
|
+
function debugMode(name) {
|
|
197
|
+
const silgi = useSilgiCLI();
|
|
198
|
+
if (silgi.options.debug === true || typeof silgi.options.debug === "object" && silgi.options.debug[name]) {
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
async function prepareCommands(silgi = useSilgiCLI()) {
|
|
205
|
+
const commands = [];
|
|
206
|
+
await silgi.callHook("prepare:commands", commands);
|
|
207
|
+
if (debugMode("command")) {
|
|
208
|
+
addTemplate({
|
|
209
|
+
filename: "cli.json",
|
|
210
|
+
where: ".silgi",
|
|
211
|
+
write: true,
|
|
212
|
+
getContents: () => JSON.stringify(commands, null, 2)
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
silgi.hook("prepare:types", async ({ references }) => {
|
|
216
|
+
const allTags = commands.reduce((acc, commandGroup) => {
|
|
217
|
+
Object.values(commandGroup).forEach((command) => {
|
|
218
|
+
if (command.tags) {
|
|
219
|
+
command.tags.forEach((tag) => acc.add(tag));
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
return acc;
|
|
223
|
+
}, /* @__PURE__ */ new Set());
|
|
224
|
+
const data = [
|
|
225
|
+
genAugmentation("silgi/types", {
|
|
226
|
+
SilgiCommands: {
|
|
227
|
+
...Object.fromEntries(Array.from(allTags.values()).map((tag) => [tag, "string"]))
|
|
228
|
+
}
|
|
229
|
+
}),
|
|
230
|
+
""
|
|
231
|
+
];
|
|
232
|
+
addTemplate({
|
|
233
|
+
filename: "types/commands.d.ts",
|
|
234
|
+
write: true,
|
|
235
|
+
where: ".silgi",
|
|
236
|
+
getContents: () => data.join("\n")
|
|
237
|
+
});
|
|
238
|
+
references.push({
|
|
239
|
+
path: "./commands.d.ts"
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
silgi.options.commands = commands;
|
|
243
|
+
}
|
|
244
|
+
|
|
195
245
|
async function prepareConfigs(silgi) {
|
|
196
246
|
const _data = {
|
|
197
247
|
runtimeConfig: {}
|
|
@@ -539,7 +589,6 @@ async function prepareSchema(silgi) {
|
|
|
539
589
|
routeRulesConfig: []
|
|
540
590
|
};
|
|
541
591
|
await silgi.callHook("before:schema.ts", data);
|
|
542
|
-
relativeWithDot(silgi.options.build.typesDir, `${silgi.options.silgi.serverDir}/core`);
|
|
543
592
|
const silgiScanTS = relativeWithDot(silgi.options.build.typesDir, `${silgi.options.silgi.serverDir}/scan`);
|
|
544
593
|
let addSilgiContext = false;
|
|
545
594
|
const importsContent = [
|
|
@@ -638,27 +687,25 @@ async function prepareSchema(silgi) {
|
|
|
638
687
|
"",
|
|
639
688
|
`type SilgiRuntimeHooksExtends = ${data.runtimeHooks?.length ? data.runtimeHooks.map(({ value }) => `${value}`).join(" & ") : "{}"}`,
|
|
640
689
|
"",
|
|
641
|
-
"
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
"",
|
|
661
|
-
"}",
|
|
690
|
+
genAugmentation("silgi/types", {
|
|
691
|
+
FrameworkContext: [{}, { extends: ["FrameworkContextExtends"] }],
|
|
692
|
+
SilgiSchema: [{}, { extends: ["SchemaExtends"] }],
|
|
693
|
+
SilgiNamespaces: [{}, { extends: ["InferredNamespaces"] }],
|
|
694
|
+
SilgiStorageBase: [{}, { extends: ["SilgiStorageBaseExtends"] }],
|
|
695
|
+
SilgiURIs: [{}, { extends: ["SilgiURIsMerge"] }],
|
|
696
|
+
SilgiRuntimeContext: [{}, { extends: ["SilgiModuleContextExtends"] }],
|
|
697
|
+
SilgiEvents: [{}, { extends: ["SilgiModuleEventsExtends"] }],
|
|
698
|
+
SilgiRuntimeSharedsExtend: [{}, { extends: ["SilgiModuleSharedExtends"] }],
|
|
699
|
+
SilgiRuntimeActions: [{}, { extends: ["RuntimeActionExtends"] }],
|
|
700
|
+
SilgiRuntimeOptions: [{}, { extends: ["SilgiRuntimeOptionExtends"] }],
|
|
701
|
+
SilgiRuntimeHooks: [{}, { extends: ["SilgiRuntimeHooksExtends"] }],
|
|
702
|
+
SilgiRuntimeConfig: [{}, { extends: ["SilgiRuntimeConfigExtends"] }],
|
|
703
|
+
SilgiHooks: [{}, { extends: ["ModuleHooksExtend"] }],
|
|
704
|
+
SilgiRuntimeMethods: [{}, { extends: ["RuntimeMethodExtends"] }],
|
|
705
|
+
SilgiRuntimeRouteRules: [{}, { extends: ["RuntimeRouteRulesExtends"] }],
|
|
706
|
+
SilgiRuntimeRouteRulesConfig: [{}, { extends: ["RuntimeRouteRulesConfigExtends"] }],
|
|
707
|
+
SilgiModuleOptions: [{}, { extends: ["SilgiModuleOptionExtend"] }]
|
|
708
|
+
}).replace(/,\s*/g, "\n"),
|
|
662
709
|
"",
|
|
663
710
|
"export {}"
|
|
664
711
|
];
|
|
@@ -798,6 +845,7 @@ export const routeRules = ${genObjectFromRawEntries(
|
|
|
798
845
|
async function build(silgi) {
|
|
799
846
|
await prepare();
|
|
800
847
|
await generateApiFul(silgi);
|
|
848
|
+
await prepareCommands(silgi);
|
|
801
849
|
await writeCoreFile(silgi);
|
|
802
850
|
await prepareBuild(silgi);
|
|
803
851
|
await writeTypesAndFiles(silgi);
|
|
@@ -1263,7 +1311,7 @@ async function installModules(silgi, prepare = false) {
|
|
|
1263
1311
|
}
|
|
1264
1312
|
silgi.options.isPreparingModules = false;
|
|
1265
1313
|
}
|
|
1266
|
-
async function installModule(moduleToInstall, silgi = useSilgiCLI(), inlineOptions, prepare = false) {
|
|
1314
|
+
async function installModule(moduleToInstall, silgi = useSilgiCLI$1(), inlineOptions, prepare = false) {
|
|
1267
1315
|
const { silgiModule } = await loadSilgiModuleInstance(moduleToInstall);
|
|
1268
1316
|
const res = await silgiModule(inlineOptions || {}, silgi) ?? {};
|
|
1269
1317
|
if (res === false) {
|
|
@@ -1568,7 +1616,7 @@ class SchemaParser {
|
|
|
1568
1616
|
};
|
|
1569
1617
|
}
|
|
1570
1618
|
parseVariableDeclaration(ast, path) {
|
|
1571
|
-
const silgi = useSilgiCLI();
|
|
1619
|
+
const silgi = useSilgiCLI$1();
|
|
1572
1620
|
if (ast.program.body.length === 0) {
|
|
1573
1621
|
if (safeFiles.find((i) => path.includes(i)))
|
|
1574
1622
|
return [];
|
|
@@ -1582,7 +1630,7 @@ class SchemaParser {
|
|
|
1582
1630
|
return variableDeclarations;
|
|
1583
1631
|
}
|
|
1584
1632
|
parseTSInterfaceDeclaration(ast, path = "") {
|
|
1585
|
-
const silgi = useSilgiCLI();
|
|
1633
|
+
const silgi = useSilgiCLI$1();
|
|
1586
1634
|
if (ast.program.body.length === 0) {
|
|
1587
1635
|
if (safeFiles.find((i) => path.includes(i)))
|
|
1588
1636
|
return [];
|
package/dist/cli/types.mjs
CHANGED
package/dist/kit/index.mjs
CHANGED
|
@@ -113,7 +113,20 @@ function addImports(data) {
|
|
|
113
113
|
const index = genTypeImports.findIndex((i) => i.specifier === item.specifier);
|
|
114
114
|
if (Array.isArray(genTypeImports[index].imports)) {
|
|
115
115
|
genTypeImports[index].imports ??= [];
|
|
116
|
-
|
|
116
|
+
const newImports = toArray$1(item.imports);
|
|
117
|
+
for (const newImport of newImports) {
|
|
118
|
+
const isDuplicate = genTypeImports[index].imports.some((existingImport) => {
|
|
119
|
+
if (typeof existingImport === "string" && typeof newImport === "string") {
|
|
120
|
+
return existingImport === newImport;
|
|
121
|
+
} else if (typeof existingImport === "object" && typeof newImport === "object") {
|
|
122
|
+
return existingImport.name === newImport.name && existingImport.as === newImport.as;
|
|
123
|
+
}
|
|
124
|
+
return false;
|
|
125
|
+
});
|
|
126
|
+
if (!isDuplicate) {
|
|
127
|
+
genTypeImports[index].imports.push(newImport);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
117
130
|
} else {
|
|
118
131
|
genTypeImports[index].imports = item.imports;
|
|
119
132
|
}
|
package/dist/types/index.d.mts
CHANGED
|
@@ -7,7 +7,7 @@ import { Hookable, NestedHooks } from 'hookable';
|
|
|
7
7
|
import { Ignore, Options } from 'ignore';
|
|
8
8
|
import { TSConfig } from 'pkg-types';
|
|
9
9
|
import { PresetName, PresetOptions, PresetNameInput } from 'silgi/presets';
|
|
10
|
-
import { ResolvedServiceType as ResolvedServiceType$1, SilgiRuntimeShareds as SilgiRuntimeShareds$1, SilgiRuntimeOptions as SilgiRuntimeOptions$1, RouteRules as RouteRules$1, ModuleMeta as ModuleMeta$1, SilgiModule as SilgiModule$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
|
+
import { ResolvedServiceType as ResolvedServiceType$1, SilgiRuntimeShareds as SilgiRuntimeShareds$1, SilgiRuntimeOptions as SilgiRuntimeOptions$1, RouteRules as RouteRules$1, ModuleMeta as ModuleMeta$1, SilgiModule as SilgiModule$1, Commands as Commands$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';
|
|
11
11
|
import { Adapter, TablesSchema, InferModelTypes } from 'unadapter/types';
|
|
12
12
|
import { UnimportPluginOptions } from 'unimport/unplugin';
|
|
13
13
|
import { H3Event } from 'h3';
|
|
@@ -583,6 +583,7 @@ interface SilgiCLIOptions extends PresetOptions {
|
|
|
583
583
|
command?: string;
|
|
584
584
|
};
|
|
585
585
|
commandType: CommandType;
|
|
586
|
+
commands: Commands$1[];
|
|
586
587
|
routeRules: SilgiRouteRules$1;
|
|
587
588
|
environments: DotenvOptions$1[];
|
|
588
589
|
activeEnvironment: 'prod' | 'docker' | 'staging' | 'testing' | '.env' | (string & {});
|