silgi 0.29.8 → 0.29.9

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.
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { defineCommand, runMain } from 'citty';
3
3
 
4
- const version = "0.29.8";
4
+ const version = "0.29.9";
5
5
  const packageJson = {
6
6
  version: version};
7
7
 
@@ -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, hash, relativeWithDot, writeFile, isDirectory, resolveAlias as resolveAlias$1, directoryToURL, hasError, parseServices, resolveSilgiPath } from 'silgi/kit';
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
- async function prepareCoreFile(data, frameworkContext, silgi) {
237
- let importItems = {
238
- "silgi": {
239
- import: [
240
- {
241
- name: "createSilgi",
242
- key: "createSilgi"
243
- }
244
- ],
245
- from: "silgi"
246
- },
247
- "silgi/types": {
248
- import: [
249
- {
250
- name: "SilgiRuntimeOptions",
251
- type: true,
252
- key: "SilgiRuntimeOptions"
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
- from: "./configs.ts"
310
- },
311
- "rules.ts": {
312
- import: [
313
- {
314
- name: "routeRules",
315
- key: "routeRules"
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
- from: "./rules.ts"
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
- importItems = { ...data._importItems, ...importItems };
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
- customImports: data._customImports || [],
324
- buildSilgiExtraContent: [],
325
- beforeBuildSilgiExtraContent: [],
326
- afterCliOptions: [],
327
- _silgiConfigs: [],
328
- customContent: [],
329
- importItems
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("prepare:core.ts", _data);
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 = `_${hash(plugin.packageImport)}`;
338
- _data.customImports.push(`import ${pluginImportName} from '${plugin.packageImport}'`);
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
- 'import { mergeDeep } from "silgi/runtime"',
343
- ...Object.entries(importItems).map(([_name, { from, import: imports }]) => {
344
- if (silgi.options.typescript.removeFileExtension) {
345
- from = from.replace(/\.(js|ts|mjs|cjs|jsx|tsx)$/, "");
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(framework: FrameworkContext, moduleOptions?: Partial<SilgiRuntimeOptions>,buildOptions?: Partial<SilgiOptions>) {",
399
+ "export async function buildSilgi(option: BuildSilgi) {",
400
+ "",
401
+ ...before,
356
402
  "",
357
- _data.beforeBuildSilgiExtraContent.length > 0 ? _data.beforeBuildSilgiExtraContent.map(({ value, type }) => {
358
- return type === "function" ? value : `const ${value}`;
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
- " const silgi = await createSilgi({",
362
- " framework,",
363
- " shared: shareds as any,",
364
- " services: services as any,",
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
- ...frameworkContext,
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
- ..._data.buildSilgiExtraContent,
426
+ ...after,
382
427
  "",
383
428
  " return silgi",
384
429
  "}",
385
430
  ""
386
431
  ];
387
- await silgi.callHook("after:prepare:core.ts", importData);
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 data = await prepareFramework(silgi);
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("prepare:core.ts", (data) => {
1053
- data._silgiConfigs.push(`captureError: (silgi, error, context = {}) => {
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", {
@@ -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 };
@@ -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 };
@@ -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
  /**
@@ -200,8 +209,8 @@ interface SilgiCLIHooks extends SilgiHooks {
200
209
  declarations: string[];
201
210
  tsConfig: TSConfig;
202
211
  }) => HookResult;
203
- 'prepare:core.ts': (data: PrepareCore) => HookResult;
204
- 'after:prepare:core.ts': (content: string[]) => HookResult;
212
+ 'before:core.ts': (data: PrepareCore) => HookResult;
213
+ 'after:core.ts': (content: string[]) => HookResult;
205
214
  'prepare:scan.ts': (data: Pick<ImportItem, 'customImports' | 'importItems'> & {
206
215
  uris: Record<string, string>;
207
216
  services: string[];
@@ -290,14 +299,15 @@ interface SilgiHooks {
290
299
  interface GenerateAppOptions {
291
300
  filter?: (template: ResolvedSilgiTemplate<any>) => boolean;
292
301
  }
293
- interface PrepareCore extends ImportItem {
294
- buildSilgiExtraContent: string[];
295
- beforeBuildSilgiExtraContent: {
296
- value: string;
297
- type: 'function' | 'variable';
298
- }[];
299
- afterCliOptions: string[];
300
- _silgiConfigs: any[];
302
+ interface PrepareCore {
303
+ silgiConfigs: Record<string, any>[];
304
+ addImportItem: (data: GenImport | GenImport[]) => void;
305
+ addImportItemType: (data: GenImport | GenImport[]) => void;
306
+ addFunction: (data: {
307
+ name: string;
308
+ params?: string[];
309
+ where: 'before' | 'after';
310
+ }[]) => void;
301
311
  }
302
312
 
303
313
  /**
@@ -1030,7 +1040,7 @@ interface FrameworkContext {
1030
1040
  }
1031
1041
  interface Silgi {
1032
1042
  schemas: any;
1033
- services: ResolvedServiceType;
1043
+ services: RequiredServiceType<SilgiSchema>;
1034
1044
  shared: SilgiRuntimeShareds;
1035
1045
  uris: Record<string, any>;
1036
1046
  modulesURIs: Partial<Record<keyof SilgiRuntimeOptions | (string & {}), any>>;
@@ -1057,6 +1067,11 @@ interface SilgiConfig extends Partial<Omit<Silgi, 'options'>>, Partial<SilgiRunt
1057
1067
  interface SilgiFunction {
1058
1068
  execute: <TURI extends keyof SilgiURIs>(uriString: TURI, input: ExtractInputFromURI<TURI>, source?: ExtractSourceFromURI<TURI>, queryParams?: Record<string, string>) => Promise<ExtractOutputFromURI<TURI>>;
1059
1069
  }
1070
+ interface BuildSilgi {
1071
+ framework: FrameworkContext;
1072
+ modules?: Partial<SilgiRuntimeOptions>;
1073
+ options?: Partial<SilgiOptions>;
1074
+ }
1060
1075
 
1061
1076
  interface SilgiAppPlugin {
1062
1077
  (silgi: Silgi): Promise<void> | void;
@@ -1181,4 +1196,4 @@ interface ServiceParseModule {
1181
1196
  (params: ServiceParse): Awaited<void> | void;
1182
1197
  }
1183
1198
 
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 };
1199
+ 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.8",
4
+ "version": "0.29.9",
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": "./dist/presets/index.mjs",
19
- "./runtime": "./dist/runtime/index.mjs",
20
- "./runtime/internal": "./dist/runtime/internal/index.mjs",
21
- "./runtime/internal/*": "./dist/runtime/internal/*.mjs",
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",
@@ -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",