silgi 0.29.8 → 0.29.10
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/cli/index.mjs +1 -1
- package/dist/cli/silgi.mjs +220 -206
- package/dist/kit/index.d.mts +7 -2
- package/dist/kit/index.mjs +10 -2
- package/dist/types/index.d.mts +27 -18
- package/package.json +22 -9
package/dist/cli/index.mjs
CHANGED
package/dist/cli/silgi.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { generateDTS } from 'apiful/openapi';
|
|
2
2
|
import consola$1, { consola } from 'consola';
|
|
3
3
|
import { join, resolve, dirname, isAbsolute, relative, basename, extname } from 'pathe';
|
|
4
|
-
import { hasSilgiModule, addTemplate, normalizeTemplate, useLogger, genEnsureSafeVar,
|
|
4
|
+
import { hasSilgiModule, addTemplate, normalizeTemplate, useLogger, genEnsureSafeVar, toArray, hash, writeFile, relativeWithDot, isDirectory, 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, genObjectFromRaw, genObjectFromValues } from 'knitwork';
|
|
7
|
+
import { genObjectFromRawEntries, genImport, genTypeImport, genObjectFromRaw, genObjectFromValues } from 'knitwork';
|
|
8
8
|
import { resolvePath, parseNodeModulePath, lookupNodeModuleSubpath, resolveModuleExportNames, findTypeExports, findExports } from 'mlly';
|
|
9
9
|
import { resolveAlias } from 'pathe/utils';
|
|
10
10
|
import { runtimeDir } from 'silgi/runtime/meta';
|
|
@@ -233,237 +233,209 @@ async function prepareConfigs(silgi) {
|
|
|
233
233
|
return importData;
|
|
234
234
|
}
|
|
235
235
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
},
|
|
254
|
-
{
|
|
255
|
-
name: "FrameworkContext",
|
|
256
|
-
type: true,
|
|
257
|
-
key: "FrameworkContext"
|
|
258
|
-
},
|
|
259
|
-
{
|
|
260
|
-
name: "SilgiOptions",
|
|
261
|
-
type: true,
|
|
262
|
-
key: "SilgiOptions"
|
|
263
|
-
}
|
|
264
|
-
],
|
|
265
|
-
from: "silgi/types"
|
|
266
|
-
},
|
|
267
|
-
"#silgi/vfs": {
|
|
268
|
-
import: [],
|
|
269
|
-
from: "./vfs"
|
|
270
|
-
},
|
|
271
|
-
"scan.ts": {
|
|
272
|
-
import: [
|
|
273
|
-
{
|
|
274
|
-
name: "uris",
|
|
275
|
-
type: false,
|
|
276
|
-
key: "uris"
|
|
277
|
-
},
|
|
278
|
-
{
|
|
279
|
-
name: "services",
|
|
280
|
-
type: false,
|
|
281
|
-
key: "services"
|
|
282
|
-
},
|
|
283
|
-
{
|
|
284
|
-
name: "shareds",
|
|
285
|
-
type: false,
|
|
286
|
-
key: "shareds"
|
|
287
|
-
},
|
|
288
|
-
{
|
|
289
|
-
name: "schemas",
|
|
290
|
-
type: false,
|
|
291
|
-
key: "schemas"
|
|
292
|
-
},
|
|
293
|
-
{
|
|
294
|
-
name: "modulesURIs",
|
|
295
|
-
type: false,
|
|
296
|
-
key: "modulesURIs"
|
|
297
|
-
}
|
|
298
|
-
],
|
|
299
|
-
from: "./scan.ts"
|
|
300
|
-
},
|
|
301
|
-
"configs.ts": {
|
|
302
|
-
import: [
|
|
303
|
-
{
|
|
304
|
-
name: "cliConfigs",
|
|
305
|
-
type: false,
|
|
306
|
-
key: "cliConfigs"
|
|
236
|
+
function scanImports(data) {
|
|
237
|
+
const genImports = [
|
|
238
|
+
...data.imports ?? []
|
|
239
|
+
];
|
|
240
|
+
const genTypeImports = [
|
|
241
|
+
...data.typeImports ?? []
|
|
242
|
+
];
|
|
243
|
+
function addImportItem(data2) {
|
|
244
|
+
for (const item of toArray(data2)) {
|
|
245
|
+
const isSpecifier = genImports.some((i) => i.specifier === item.specifier);
|
|
246
|
+
if (isSpecifier) {
|
|
247
|
+
const index = genImports.findIndex((i) => i.specifier === item.specifier);
|
|
248
|
+
if (Array.isArray(genImports[index].imports)) {
|
|
249
|
+
genImports[index].imports ??= [];
|
|
250
|
+
genImports[index].imports.push(...toArray(item.imports));
|
|
251
|
+
} else {
|
|
252
|
+
genImports[index].imports = item.imports;
|
|
307
253
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
254
|
+
} else {
|
|
255
|
+
genImports.push({
|
|
256
|
+
specifier: item.specifier,
|
|
257
|
+
imports: item.imports,
|
|
258
|
+
options: item.options
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
function addImportItemType(data2) {
|
|
264
|
+
for (const item of toArray(data2)) {
|
|
265
|
+
const isSpecifier = genTypeImports.some((i) => i.specifier === item.specifier);
|
|
266
|
+
if (isSpecifier) {
|
|
267
|
+
const index = genTypeImports.findIndex((i) => i.specifier === item.specifier);
|
|
268
|
+
if (Array.isArray(genTypeImports[index].imports)) {
|
|
269
|
+
genTypeImports[index].imports ??= [];
|
|
270
|
+
genTypeImports[index].imports.push(...toArray(item.imports));
|
|
271
|
+
} else {
|
|
272
|
+
genTypeImports[index].imports = item.imports;
|
|
316
273
|
}
|
|
317
|
-
|
|
318
|
-
|
|
274
|
+
} else {
|
|
275
|
+
genTypeImports.push({
|
|
276
|
+
specifier: item.specifier,
|
|
277
|
+
imports: item.imports,
|
|
278
|
+
options: item.options
|
|
279
|
+
});
|
|
280
|
+
}
|
|
319
281
|
}
|
|
282
|
+
}
|
|
283
|
+
return {
|
|
284
|
+
genImports,
|
|
285
|
+
genTypeImports,
|
|
286
|
+
addImportItem,
|
|
287
|
+
addImportItemType
|
|
320
288
|
};
|
|
321
|
-
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
async function prepareCoreFile(silgi) {
|
|
292
|
+
const { genImports, genTypeImports, addImportItem, addImportItemType } = scanImports({
|
|
293
|
+
imports: [
|
|
294
|
+
{
|
|
295
|
+
specifier: "silgi/runtime",
|
|
296
|
+
imports: [
|
|
297
|
+
{
|
|
298
|
+
name: "mergeDeep"
|
|
299
|
+
}
|
|
300
|
+
]
|
|
301
|
+
},
|
|
302
|
+
{
|
|
303
|
+
specifier: "silgi",
|
|
304
|
+
imports: [
|
|
305
|
+
{
|
|
306
|
+
name: "createSilgi"
|
|
307
|
+
}
|
|
308
|
+
]
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
specifier: "./scan",
|
|
312
|
+
imports: [
|
|
313
|
+
{
|
|
314
|
+
name: "uris"
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
name: "services"
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
name: "shareds"
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
name: "schemas"
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
name: "modulesURIs"
|
|
327
|
+
}
|
|
328
|
+
]
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
specifier: "./configs",
|
|
332
|
+
imports: [
|
|
333
|
+
{
|
|
334
|
+
name: "cliConfigs"
|
|
335
|
+
}
|
|
336
|
+
]
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
specifier: "./rules",
|
|
340
|
+
imports: [
|
|
341
|
+
{
|
|
342
|
+
name: "routeRules"
|
|
343
|
+
}
|
|
344
|
+
]
|
|
345
|
+
}
|
|
346
|
+
],
|
|
347
|
+
typeImports: [
|
|
348
|
+
{
|
|
349
|
+
specifier: "silgi/types",
|
|
350
|
+
imports: [
|
|
351
|
+
{
|
|
352
|
+
name: "SilgiRuntimeOptions"
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
name: "BuildSilgi"
|
|
356
|
+
}
|
|
357
|
+
]
|
|
358
|
+
}
|
|
359
|
+
]
|
|
360
|
+
});
|
|
361
|
+
const before = [];
|
|
362
|
+
const after = [];
|
|
322
363
|
const _data = {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
364
|
+
silgiConfigs: [],
|
|
365
|
+
addImportItem,
|
|
366
|
+
addImportItemType,
|
|
367
|
+
addFunction: (data) => {
|
|
368
|
+
for (const item of data) {
|
|
369
|
+
if (item.where === "after") {
|
|
370
|
+
after.push(item.params?.length ? ` await ${item.name}(option, ${item.params.join(",")})` : ` await ${item.name}(framework)`);
|
|
371
|
+
}
|
|
372
|
+
if (item.where === "before") {
|
|
373
|
+
before.push(item.params?.length ? ` await ${item.name}(option, ${item.params.join(",")})` : ` await ${item.name}(framework)`);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
330
377
|
};
|
|
331
|
-
await silgi.callHook("
|
|
332
|
-
if (importItems["#silgi/vfs"].import.length === 0) {
|
|
333
|
-
delete importItems["#silgi/vfs"];
|
|
334
|
-
}
|
|
378
|
+
await silgi.callHook("before:core.ts", _data);
|
|
335
379
|
const plugins = [];
|
|
336
380
|
for (const plugin of silgi.options.plugins) {
|
|
337
|
-
const pluginImportName =
|
|
338
|
-
|
|
381
|
+
const pluginImportName = hash(plugin.packageImport);
|
|
382
|
+
addImportItem({
|
|
383
|
+
specifier: plugin.packageImport,
|
|
384
|
+
imports: pluginImportName
|
|
385
|
+
});
|
|
339
386
|
plugins.push(pluginImportName);
|
|
340
387
|
}
|
|
341
388
|
const importsContent = [
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
return `import { ${imports.map(({ type, name }) => type ? `type ${name}` : name).join(", ")} } from '${from}'`;
|
|
389
|
+
...genImports.map(({ specifier, imports, options }) => {
|
|
390
|
+
return genImport(specifier, imports, options);
|
|
391
|
+
}),
|
|
392
|
+
...genTypeImports.map(({ specifier, imports }) => {
|
|
393
|
+
return genTypeImport(specifier, Array.isArray(imports) ? imports : [imports]);
|
|
348
394
|
}),
|
|
349
|
-
"",
|
|
350
|
-
..._data.customImports,
|
|
351
395
|
""
|
|
352
396
|
];
|
|
353
397
|
const importData = [
|
|
354
398
|
"",
|
|
355
|
-
"export async function buildSilgi(
|
|
399
|
+
"export async function buildSilgi(option: BuildSilgi) {",
|
|
400
|
+
"",
|
|
401
|
+
...before,
|
|
356
402
|
"",
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
403
|
+
"const silgi = await createSilgi({",
|
|
404
|
+
" framework: option.framework,",
|
|
405
|
+
" shared: shareds,",
|
|
406
|
+
" services: services,",
|
|
407
|
+
" schemas: schemas,",
|
|
408
|
+
" uris,",
|
|
409
|
+
" modulesURIs,",
|
|
410
|
+
` plugins: [${plugins.join(", ")}],`,
|
|
360
411
|
"",
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
"
|
|
365
|
-
" schemas: schemas as any,",
|
|
366
|
-
" uris,",
|
|
367
|
-
" modulesURIs,",
|
|
368
|
-
` plugins: [${plugins.join(", ")}],`,
|
|
369
|
-
_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 ")},` : "",
|
|
370
|
-
" options: mergeDeep(cliConfigs, {",
|
|
371
|
-
" runtimeConfig: {} as SilgiRuntimeOptions,",
|
|
372
|
-
" routeRules: routeRules as any,",
|
|
373
|
-
` present: '${silgi.options.preset}',`,
|
|
374
|
-
" ...moduleOptions,",
|
|
375
|
-
" ...buildOptions,",
|
|
376
|
-
" }) as any,",
|
|
377
|
-
" })",
|
|
412
|
+
_data.silgiConfigs.length > 0 ? _data.silgiConfigs.map((item) => {
|
|
413
|
+
const code = genObjectFromRawEntries(Object.entries(item));
|
|
414
|
+
return ` ${code.slice(1, -1).trim()},`;
|
|
415
|
+
}).filter(Boolean).join("\n") : "",
|
|
378
416
|
"",
|
|
379
|
-
|
|
417
|
+
" options: mergeDeep(cliConfigs, {",
|
|
418
|
+
" runtimeConfig: {} as SilgiRuntimeOptions,",
|
|
419
|
+
" routeRules: routeRules as any,",
|
|
420
|
+
` present: '${silgi.options.preset}',`,
|
|
421
|
+
" ...option.modules,",
|
|
422
|
+
" ...option.options,",
|
|
423
|
+
" }) as any,",
|
|
424
|
+
" })",
|
|
380
425
|
"",
|
|
381
|
-
...
|
|
426
|
+
...after,
|
|
382
427
|
"",
|
|
383
428
|
" return silgi",
|
|
384
429
|
"}",
|
|
385
430
|
""
|
|
386
431
|
];
|
|
387
|
-
await silgi.callHook("after:
|
|
432
|
+
await silgi.callHook("after:core.ts", importData);
|
|
388
433
|
importData.unshift(...importsContent);
|
|
389
434
|
return importData;
|
|
390
435
|
}
|
|
391
436
|
|
|
392
|
-
async function prepareFramework(silgi) {
|
|
393
|
-
const importItems = {
|
|
394
|
-
"silgi/types": {
|
|
395
|
-
import: [
|
|
396
|
-
{
|
|
397
|
-
name: "SilgiRuntimeContext",
|
|
398
|
-
type: true,
|
|
399
|
-
key: "SilgiRuntimeContext"
|
|
400
|
-
}
|
|
401
|
-
],
|
|
402
|
-
from: "silgi/types"
|
|
403
|
-
}
|
|
404
|
-
};
|
|
405
|
-
const customImports = [];
|
|
406
|
-
const functions = [];
|
|
407
|
-
await silgi.callHook("prepare:createCoreFramework", {
|
|
408
|
-
importItems,
|
|
409
|
-
customImports,
|
|
410
|
-
functions
|
|
411
|
-
});
|
|
412
|
-
const content = [
|
|
413
|
-
...functions.map((f) => f.params?.length ? ` await ${f.name}(framework, ${f.params.join(",")})` : ` await ${f.name}(framework)`)
|
|
414
|
-
];
|
|
415
|
-
return {
|
|
416
|
-
content,
|
|
417
|
-
importItems,
|
|
418
|
-
customImports
|
|
419
|
-
};
|
|
420
|
-
}
|
|
421
|
-
async function createDTSFramework(silgi) {
|
|
422
|
-
const importItems = {
|
|
423
|
-
"silgi/types": {
|
|
424
|
-
import: [
|
|
425
|
-
{
|
|
426
|
-
name: "SilgiRuntimeContext",
|
|
427
|
-
type: true,
|
|
428
|
-
key: "SilgiRuntimeContext"
|
|
429
|
-
}
|
|
430
|
-
],
|
|
431
|
-
from: "silgi/types"
|
|
432
|
-
}
|
|
433
|
-
};
|
|
434
|
-
const customImports = [];
|
|
435
|
-
const customContent = [];
|
|
436
|
-
await silgi.callHook("prepare:createDTSFramework", {
|
|
437
|
-
importItems,
|
|
438
|
-
customImports,
|
|
439
|
-
customContent
|
|
440
|
-
});
|
|
441
|
-
const content = [
|
|
442
|
-
...Object.entries(importItems).map(([_name, { from, import: imports }]) => {
|
|
443
|
-
const path = isAbsolute(from) ? relativeWithDot(silgi.options.build.typesDir, from) : from;
|
|
444
|
-
if (silgi.options.typescript.removeFileExtension) {
|
|
445
|
-
from = from.replace(/\.(js|ts|mjs|cjs|jsx|tsx)$/, "");
|
|
446
|
-
}
|
|
447
|
-
return `import { ${imports.map(({ type, name }) => type ? `type ${name}` : name).join(", ")} } from '${path}'`;
|
|
448
|
-
}),
|
|
449
|
-
"",
|
|
450
|
-
...customImports,
|
|
451
|
-
"",
|
|
452
|
-
...customContent,
|
|
453
|
-
""
|
|
454
|
-
];
|
|
455
|
-
return {
|
|
456
|
-
content,
|
|
457
|
-
importItems
|
|
458
|
-
};
|
|
459
|
-
}
|
|
460
|
-
|
|
461
437
|
async function writeCoreFile(silgi) {
|
|
462
|
-
const
|
|
463
|
-
const coreContent = await prepareCoreFile({
|
|
464
|
-
_importItems: data?.importItems ?? {},
|
|
465
|
-
_customImports: data?.customImports ?? []
|
|
466
|
-
}, data?.content ?? [], silgi);
|
|
438
|
+
const coreContent = await prepareCoreFile(silgi);
|
|
467
439
|
const configs = await prepareConfigs(silgi);
|
|
468
440
|
const silgiDir = resolve(silgi.options.silgi.serverDir);
|
|
469
441
|
const buildFiles = [];
|
|
@@ -564,6 +536,46 @@ ${methodEntries}
|
|
|
564
536
|
return context;
|
|
565
537
|
}
|
|
566
538
|
|
|
539
|
+
async function createDTSFramework(silgi) {
|
|
540
|
+
const importItems = {
|
|
541
|
+
"silgi/types": {
|
|
542
|
+
import: [
|
|
543
|
+
{
|
|
544
|
+
name: "SilgiRuntimeContext",
|
|
545
|
+
type: true,
|
|
546
|
+
key: "SilgiRuntimeContext"
|
|
547
|
+
}
|
|
548
|
+
],
|
|
549
|
+
from: "silgi/types"
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
const customImports = [];
|
|
553
|
+
const customContent = [];
|
|
554
|
+
await silgi.callHook("prepare:createDTSFramework", {
|
|
555
|
+
importItems,
|
|
556
|
+
customImports,
|
|
557
|
+
customContent
|
|
558
|
+
});
|
|
559
|
+
const content = [
|
|
560
|
+
...Object.entries(importItems).map(([_name, { from, import: imports }]) => {
|
|
561
|
+
const path = isAbsolute(from) ? relativeWithDot(silgi.options.build.typesDir, from) : from;
|
|
562
|
+
if (silgi.options.typescript.removeFileExtension) {
|
|
563
|
+
from = from.replace(/\.(js|ts|mjs|cjs|jsx|tsx)$/, "");
|
|
564
|
+
}
|
|
565
|
+
return `import { ${imports.map(({ type, name }) => type ? `type ${name}` : name).join(", ")} } from '${path}'`;
|
|
566
|
+
}),
|
|
567
|
+
"",
|
|
568
|
+
...customImports,
|
|
569
|
+
"",
|
|
570
|
+
...customContent,
|
|
571
|
+
""
|
|
572
|
+
];
|
|
573
|
+
return {
|
|
574
|
+
content,
|
|
575
|
+
importItems
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
|
|
567
579
|
async function prepareSchema(silgi) {
|
|
568
580
|
const importItems = {
|
|
569
581
|
"silgi/types": {
|
|
@@ -1049,8 +1061,9 @@ async function h3Framework(silgi, skip = false) {
|
|
|
1049
1061
|
""
|
|
1050
1062
|
);
|
|
1051
1063
|
});
|
|
1052
|
-
silgi.hook("
|
|
1053
|
-
data.
|
|
1064
|
+
silgi.hook("before:core.ts", (data) => {
|
|
1065
|
+
data.createSilgiParams.push({
|
|
1066
|
+
captureError: `(silgi, error, context = {}) => {
|
|
1054
1067
|
const promise = silgi.hooks
|
|
1055
1068
|
.callHookParallel('error', silgi, error, context)
|
|
1056
1069
|
.catch((error_) => {
|
|
@@ -1066,7 +1079,8 @@ async function h3Framework(silgi, skip = false) {
|
|
|
1066
1079
|
context.event.waitUntil(promise)
|
|
1067
1080
|
}
|
|
1068
1081
|
}
|
|
1069
|
-
}`
|
|
1082
|
+
}`
|
|
1083
|
+
});
|
|
1070
1084
|
});
|
|
1071
1085
|
if (silgi.options.imports !== false) {
|
|
1072
1086
|
const h3Exports = await resolveModuleExportNames("h3", {
|
package/dist/kit/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Commands, SilgiCLI, ModuleOptionsCustom, ModuleDefinition, SilgiModule, ServiceParseModule, SilgiPreset, SilgiPresetMeta, SilgiTemplate, ResolvedSilgiTemplate, SilgiEvents } from 'silgi/types';
|
|
1
|
+
import { Commands, SilgiCLIHooks, SilgiCLI, ModuleOptionsCustom, ModuleDefinition, SilgiModule, ServiceParseModule, SilgiPreset, SilgiPresetMeta, SilgiTemplate, ResolvedSilgiTemplate, SilgiEvents } from 'silgi/types';
|
|
2
2
|
import { Buffer } from 'node:buffer';
|
|
3
3
|
import { ConsolaOptions, ConsolaInstance } from 'consola';
|
|
4
4
|
import * as rfc6902 from 'rfc6902';
|
|
@@ -6,6 +6,11 @@ import { IncomingMessage, ServerResponse } from 'node:http';
|
|
|
6
6
|
|
|
7
7
|
declare function addCommands(data: Commands | Commands[]): Promise<void>;
|
|
8
8
|
|
|
9
|
+
declare function addCoreFile(data: {
|
|
10
|
+
before?: SilgiCLIHooks['before:core.ts'];
|
|
11
|
+
after?: SilgiCLIHooks['after:core.ts'];
|
|
12
|
+
}): Promise<void>;
|
|
13
|
+
|
|
9
14
|
declare function addNPMPackage(data: {
|
|
10
15
|
name: string;
|
|
11
16
|
version?: string;
|
|
@@ -296,5 +301,5 @@ declare function hasInstalledModule(moduleKey: string, silgi?: SilgiCLI): boolea
|
|
|
296
301
|
declare const baseHeaderBannerComment: string[];
|
|
297
302
|
declare function processFilePath(src: string): string;
|
|
298
303
|
|
|
299
|
-
export { MODE_RE, MigrationStatus, addCommands, addNPMPackage, addTemplate, baseHeaderBannerComment, createFunction, createFunctionConfigs, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, formatFunctions, genEnsureSafeVar, generateMigration, getAllEntries, getIpAddress, getMigration, hasError, hasInstalledModule, hasSilgiModule, hash, ipAddress, isDirectory, isH3, isNitro, isNuxt, listMigrations, migrationDown, migrationUp, normalizeTemplate, parseServices, prettyPath, processFilePath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, writeFile };
|
|
304
|
+
export { MODE_RE, MigrationStatus, addCommands, addCoreFile, addNPMPackage, addTemplate, baseHeaderBannerComment, createFunction, createFunctionConfigs, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, formatFunctions, genEnsureSafeVar, generateMigration, getAllEntries, getIpAddress, getMigration, hasError, hasInstalledModule, hasSilgiModule, hash, ipAddress, isDirectory, isH3, isNitro, isNuxt, listMigrations, migrationDown, migrationUp, normalizeTemplate, parseServices, prettyPath, processFilePath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, writeFile };
|
|
300
305
|
export type { FunctionConfig, JsonPatch, MigrationData, MigrationInfo, MigrationOptions, MigrationResult };
|
package/dist/kit/index.mjs
CHANGED
|
@@ -67,6 +67,14 @@ async function addCommands(data) {
|
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
async function addCoreFile(data) {
|
|
71
|
+
const silgi = useSilgiCLI$1();
|
|
72
|
+
if (data.before)
|
|
73
|
+
silgi.hook("before:core.ts", data.before);
|
|
74
|
+
if (data.after)
|
|
75
|
+
silgi.hook("after:core.ts", data.after);
|
|
76
|
+
}
|
|
77
|
+
|
|
70
78
|
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
71
79
|
async function addNPMPackage(data) {
|
|
72
80
|
const silgi = useSilgiCLI$1();
|
|
@@ -287,7 +295,7 @@ function getAllEntries(obj) {
|
|
|
287
295
|
}
|
|
288
296
|
|
|
289
297
|
function hash(data) {
|
|
290
|
-
return camelCase(hash$1(data))
|
|
298
|
+
return `_${camelCase(hash$1(data))}`;
|
|
291
299
|
}
|
|
292
300
|
|
|
293
301
|
function isNuxt() {
|
|
@@ -961,4 +969,4 @@ function isValidIp(ip) {
|
|
|
961
969
|
return false;
|
|
962
970
|
}
|
|
963
971
|
|
|
964
|
-
export { MODE_RE, MigrationStatus, addCommands, addNPMPackage, addTemplate, baseHeaderBannerComment, createFunction, createFunctionConfigs, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, formatFunctions, genEnsureSafeVar, generateMigration, getAllEntries, getIpAddress, getMigration, hasError, hasInstalledModule, hasSilgiModule, hash, ipAddress, isDirectory$1 as isDirectory, isH3, isNitro, isNuxt, listMigrations, migrationDown, migrationUp, normalizeTemplate, parseServices, prettyPath, processFilePath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, writeFile };
|
|
972
|
+
export { MODE_RE, MigrationStatus, addCommands, addCoreFile, addNPMPackage, addTemplate, baseHeaderBannerComment, createFunction, createFunctionConfigs, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, formatFunctions, genEnsureSafeVar, generateMigration, getAllEntries, getIpAddress, getMigration, hasError, hasInstalledModule, hasSilgiModule, hash, ipAddress, isDirectory$1 as isDirectory, isH3, isNitro, isNuxt, listMigrations, migrationDown, migrationUp, normalizeTemplate, parseServices, prettyPath, processFilePath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, writeFile };
|
package/dist/types/index.d.mts
CHANGED
|
@@ -14,6 +14,7 @@ import { H3Event } from 'h3';
|
|
|
14
14
|
import { NitroRuntimeConfig } from 'nitropack/types';
|
|
15
15
|
import { Defu } from 'defu';
|
|
16
16
|
import { Stats } from 'node:fs';
|
|
17
|
+
import { ESMImport, ESMCodeGenOptions } from 'knitwork';
|
|
17
18
|
import { Unimport } from 'unimport';
|
|
18
19
|
import { Storage, TransactionOptions, BuiltinDriverName, StorageValue } from 'unstorage';
|
|
19
20
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
@@ -33,6 +34,9 @@ interface SilgiCompatibilityIssues extends Array<SilgiCompatibilityIssue> {
|
|
|
33
34
|
toString: () => string;
|
|
34
35
|
}
|
|
35
36
|
|
|
37
|
+
/**
|
|
38
|
+
* @deprecated
|
|
39
|
+
*/
|
|
36
40
|
interface ImportItem {
|
|
37
41
|
importItems: {
|
|
38
42
|
[key: string]: {
|
|
@@ -161,6 +165,11 @@ interface Commands {
|
|
|
161
165
|
}) => string;
|
|
162
166
|
order?: number;
|
|
163
167
|
}
|
|
168
|
+
interface GenImport {
|
|
169
|
+
specifier: string;
|
|
170
|
+
imports: ESMImport | ESMImport[];
|
|
171
|
+
options?: ESMCodeGenOptions;
|
|
172
|
+
}
|
|
164
173
|
|
|
165
174
|
interface SilgiCLIHooks extends SilgiHooks {
|
|
166
175
|
/**
|
|
@@ -176,12 +185,6 @@ interface SilgiCLIHooks extends SilgiHooks {
|
|
|
176
185
|
*/
|
|
177
186
|
'close': (silgi: SilgiCLI) => HookResult;
|
|
178
187
|
'reload:scan': (path: string, stats?: Stats) => HookResult;
|
|
179
|
-
'prepare:createCoreFramework': (options: Pick<ImportItem, 'customImports' | 'importItems'> & {
|
|
180
|
-
functions?: {
|
|
181
|
-
name: string;
|
|
182
|
-
params?: string[];
|
|
183
|
-
}[];
|
|
184
|
-
}) => HookResult;
|
|
185
188
|
'prepare:createDTSFramework': (options: ImportItem) => HookResult;
|
|
186
189
|
/**
|
|
187
190
|
* Allows extending compatibility checks.
|
|
@@ -200,8 +203,8 @@ interface SilgiCLIHooks extends SilgiHooks {
|
|
|
200
203
|
declarations: string[];
|
|
201
204
|
tsConfig: TSConfig;
|
|
202
205
|
}) => HookResult;
|
|
203
|
-
'
|
|
204
|
-
'after:
|
|
206
|
+
'before:core.ts': (data: PrepareCore) => HookResult;
|
|
207
|
+
'after:core.ts': (content: string[]) => HookResult;
|
|
205
208
|
'prepare:scan.ts': (data: Pick<ImportItem, 'customImports' | 'importItems'> & {
|
|
206
209
|
uris: Record<string, string>;
|
|
207
210
|
services: string[];
|
|
@@ -290,14 +293,15 @@ interface SilgiHooks {
|
|
|
290
293
|
interface GenerateAppOptions {
|
|
291
294
|
filter?: (template: ResolvedSilgiTemplate<any>) => boolean;
|
|
292
295
|
}
|
|
293
|
-
interface PrepareCore
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
296
|
+
interface PrepareCore {
|
|
297
|
+
silgiConfigs: Record<string, any>[];
|
|
298
|
+
addImportItem: (data: GenImport | GenImport[]) => void;
|
|
299
|
+
addImportItemType: (data: GenImport | GenImport[]) => void;
|
|
300
|
+
addFunction: (data: {
|
|
301
|
+
name: string;
|
|
302
|
+
params?: string[];
|
|
303
|
+
where: 'before' | 'after';
|
|
304
|
+
}[]) => void;
|
|
301
305
|
}
|
|
302
306
|
|
|
303
307
|
/**
|
|
@@ -1030,7 +1034,7 @@ interface FrameworkContext {
|
|
|
1030
1034
|
}
|
|
1031
1035
|
interface Silgi {
|
|
1032
1036
|
schemas: any;
|
|
1033
|
-
services:
|
|
1037
|
+
services: RequiredServiceType<SilgiSchema>;
|
|
1034
1038
|
shared: SilgiRuntimeShareds;
|
|
1035
1039
|
uris: Record<string, any>;
|
|
1036
1040
|
modulesURIs: Partial<Record<keyof SilgiRuntimeOptions | (string & {}), any>>;
|
|
@@ -1057,6 +1061,11 @@ interface SilgiConfig extends Partial<Omit<Silgi, 'options'>>, Partial<SilgiRunt
|
|
|
1057
1061
|
interface SilgiFunction {
|
|
1058
1062
|
execute: <TURI extends keyof SilgiURIs>(uriString: TURI, input: ExtractInputFromURI<TURI>, source?: ExtractSourceFromURI<TURI>, queryParams?: Record<string, string>) => Promise<ExtractOutputFromURI<TURI>>;
|
|
1059
1063
|
}
|
|
1064
|
+
interface BuildSilgi {
|
|
1065
|
+
framework: FrameworkContext;
|
|
1066
|
+
modules?: Partial<SilgiRuntimeOptions>;
|
|
1067
|
+
options?: Partial<SilgiOptions>;
|
|
1068
|
+
}
|
|
1060
1069
|
|
|
1061
1070
|
interface SilgiAppPlugin {
|
|
1062
1071
|
(silgi: Silgi): Promise<void> | void;
|
|
@@ -1181,4 +1190,4 @@ interface ServiceParseModule {
|
|
|
1181
1190
|
(params: ServiceParse): Awaited<void> | void;
|
|
1182
1191
|
}
|
|
1183
1192
|
|
|
1184
|
-
export type { AllPaths, AppConfig, Awaitable, BaseNamespaceType, BaseSchemaType, BaseSilgiMethodType, CaptureError, CapturedErrorContext, CommandType, Commands, CreateScope, DeepPartial, DeepRequired, DefaultHooks, DefaultNamespaces, DefaultRouteConfig, DefaultRouteRules, DotenvOptions, EnvOptions, EventHandlerResponse, ExtendContext, ExtendShared, ExtractInputFromURI, ExtractOutputFromURI, ExtractPathParams, ExtractPathParamsFromURI, ExtractQueryParamsFromURI, ExtractSourceFromURI, FrameworkContext, GenerateAppOptions, GraphQLJSON, HookResult, HttpMethod, ImportItem, LoadConfigOptions, MergedSilgiSchema, MethodHandlerType, ModuleDefinition, ModuleHookContext, ModuleMeta, ModuleOptionsCustom, ModuleSetupInstallResult, ModuleSetupReturn, Namespaces, NitroBuildInfo, PrepareCore, RequiredServiceType, ResolvedMethodHandlerType, ResolvedModuleMeta, ResolvedModuleOptions, ResolvedServiceType, ResolvedSilgiTemplate, RouteRules, RouterParams, ScanFile, ServiceParse, ServiceParseModule, ServiceType, Silgi, SilgiAppPlugin, SilgiCLI, SilgiCLIConfig, SilgiCLIDynamicConfig, SilgiCLIHooks, SilgiCLIOptions, SilgiCommands, SilgiCompatibility, SilgiCompatibilityIssue, SilgiCompatibilityIssues, SilgiConfig, SilgiEvents, SilgiFetchClient, SilgiFetchOptions, SilgiFrameworkInfo, SilgiFunction, SilgiHooks, SilgiModule, SilgiModuleInput, SilgiModuleOptions, SilgiNamespaces, SilgiOperation, SilgiOptions, SilgiPreset, SilgiPresetMeta, SilgiRouteRules, SilgiRouterTypes, SilgiRuntimeActions, SilgiRuntimeConfig, SilgiRuntimeContext, SilgiRuntimeHooks, SilgiRuntimeMethods, SilgiRuntimeOptions, SilgiRuntimeRouteRules, SilgiRuntimeRouteRulesConfig, SilgiRuntimeShareds, SilgiRuntimeSharedsExtend, SilgiSchema, SilgiServiceInterface, SilgiStorageBase, SilgiTemplate, SilgiURIs, StorageConfig, StorageKeyGenerator, StorageKeyParams, StorageMounts, TSReference, TrimAfterFourSlashes, URIsTypes };
|
|
1193
|
+
export type { AllPaths, AppConfig, Awaitable, BaseNamespaceType, BaseSchemaType, BaseSilgiMethodType, BuildSilgi, CaptureError, CapturedErrorContext, CommandType, Commands, CreateScope, DeepPartial, DeepRequired, DefaultHooks, DefaultNamespaces, DefaultRouteConfig, DefaultRouteRules, DotenvOptions, EnvOptions, EventHandlerResponse, ExtendContext, ExtendShared, ExtractInputFromURI, ExtractOutputFromURI, ExtractPathParams, ExtractPathParamsFromURI, ExtractQueryParamsFromURI, ExtractSourceFromURI, FrameworkContext, GenImport, GenerateAppOptions, GraphQLJSON, HookResult, HttpMethod, ImportItem, LoadConfigOptions, MergedSilgiSchema, MethodHandlerType, ModuleDefinition, ModuleHookContext, ModuleMeta, ModuleOptionsCustom, ModuleSetupInstallResult, ModuleSetupReturn, Namespaces, NitroBuildInfo, PrepareCore, RequiredServiceType, ResolvedMethodHandlerType, ResolvedModuleMeta, ResolvedModuleOptions, ResolvedServiceType, ResolvedSilgiTemplate, RouteRules, RouterParams, ScanFile, ServiceParse, ServiceParseModule, ServiceType, Silgi, SilgiAppPlugin, SilgiCLI, SilgiCLIConfig, SilgiCLIDynamicConfig, SilgiCLIHooks, SilgiCLIOptions, SilgiCommands, SilgiCompatibility, SilgiCompatibilityIssue, SilgiCompatibilityIssues, SilgiConfig, SilgiEvents, SilgiFetchClient, SilgiFetchOptions, SilgiFrameworkInfo, SilgiFunction, SilgiHooks, SilgiModule, SilgiModuleInput, SilgiModuleOptions, SilgiNamespaces, SilgiOperation, SilgiOptions, SilgiPreset, SilgiPresetMeta, SilgiRouteRules, SilgiRouterTypes, SilgiRuntimeActions, SilgiRuntimeConfig, SilgiRuntimeContext, SilgiRuntimeHooks, SilgiRuntimeMethods, SilgiRuntimeOptions, SilgiRuntimeRouteRules, SilgiRuntimeRouteRulesConfig, SilgiRuntimeShareds, SilgiRuntimeSharedsExtend, SilgiSchema, SilgiServiceInterface, SilgiStorageBase, SilgiTemplate, SilgiURIs, StorageConfig, StorageKeyGenerator, StorageKeyParams, StorageMounts, TSReference, TrimAfterFourSlashes, URIsTypes };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "silgi",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.29.
|
|
4
|
+
"version": "0.29.10",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"exports": {
|
|
@@ -15,10 +15,22 @@
|
|
|
15
15
|
"./config": "./lib/config.mjs",
|
|
16
16
|
"./types": "./dist/types/index.d.mts",
|
|
17
17
|
"./meta": "./lib/meta.mjs",
|
|
18
|
-
"./presets":
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
"./presets": {
|
|
19
|
+
"import": "./dist/presets/index.mjs",
|
|
20
|
+
"silgiDev": "./dist/presets/index.ts"
|
|
21
|
+
},
|
|
22
|
+
"./runtime": {
|
|
23
|
+
"import": "./dist/runtime/index.mjs",
|
|
24
|
+
"silgiDev": "./dist/runtime/index.ts"
|
|
25
|
+
},
|
|
26
|
+
"./runtime/internal/nitro": {
|
|
27
|
+
"import": "./dist/runtime/internal/nitro.mjs",
|
|
28
|
+
"silgiDev": "./dist/runtime/internal/nitro.ts"
|
|
29
|
+
},
|
|
30
|
+
"./runtime/internal": {
|
|
31
|
+
"import": "./dist/runtime/internal/index.mjs",
|
|
32
|
+
"silgiDev": "./dist/runtime/internal/index.ts"
|
|
33
|
+
},
|
|
22
34
|
"./runtime/meta": "./lib/runtime-meta.mjs"
|
|
23
35
|
},
|
|
24
36
|
"main": "./dist/core/index.mjs",
|
|
@@ -71,7 +83,7 @@
|
|
|
71
83
|
"@fastify/deepmerge": "^3.1.0",
|
|
72
84
|
"@oxc-parser/wasm": "^0.60.0",
|
|
73
85
|
"@standard-schema/spec": "^1.0.0",
|
|
74
|
-
"apiful": "^2.0
|
|
86
|
+
"apiful": "^2.1.0",
|
|
75
87
|
"c12": "^3.0.3",
|
|
76
88
|
"chokidar": "^4.0.3",
|
|
77
89
|
"citty": "^0.1.6",
|
|
@@ -89,6 +101,7 @@
|
|
|
89
101
|
"ignore": "^7.0.3",
|
|
90
102
|
"klona": "^2.0.6",
|
|
91
103
|
"knitwork": "^1.2.0",
|
|
104
|
+
"magicast": "^0.3.5",
|
|
92
105
|
"mlly": "^1.7.4",
|
|
93
106
|
"ofetch": "^1.4.1",
|
|
94
107
|
"ohash": "^2.0.11",
|
|
@@ -110,17 +123,17 @@
|
|
|
110
123
|
"@antfu/eslint-config": "^4.12.0",
|
|
111
124
|
"@nuxt/kit": "^3.16.2",
|
|
112
125
|
"@nuxt/schema": "^3.16.2",
|
|
113
|
-
"@silgi/ecosystem": "^0.
|
|
126
|
+
"@silgi/ecosystem": "^0.5.0",
|
|
114
127
|
"@types/node": "^22.14.1",
|
|
115
128
|
"@types/semver": "^7.7.0",
|
|
116
129
|
"@vitest/coverage-v8": "3.0.5",
|
|
117
|
-
"eslint": "^9.25.
|
|
130
|
+
"eslint": "^9.25.1",
|
|
118
131
|
"h3": "^1.15.1",
|
|
119
132
|
"nitropack": "^2.11.9",
|
|
120
133
|
"nuxt": "^3.16.2",
|
|
121
134
|
"typescript": "^5.8.3",
|
|
122
135
|
"unbuild": "^3.5.0",
|
|
123
|
-
"vitest": "^3.1.
|
|
136
|
+
"vitest": "^3.1.2",
|
|
124
137
|
"vue": "^3.5.13",
|
|
125
138
|
"zod": "^3.24.3"
|
|
126
139
|
},
|