silgi 0.29.21 → 0.29.23

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/dev.mjs CHANGED
@@ -6,7 +6,7 @@ import { join } from 'pathe';
6
6
  import { useSilgiCLI } from 'silgi';
7
7
  import { version } from 'silgi/meta';
8
8
  import { a as silgiCLIIClose } from '../_chunks/silgiApp.mjs';
9
- import { c as commonArgs, p as prepare } from './prepare.mjs';
9
+ import { b as commonArgs, a as command$1 } from './prepare.mjs';
10
10
  import 'unctx';
11
11
  import './silgi.mjs';
12
12
  import 'apiful/openapi';
@@ -52,7 +52,7 @@ async function reloadScan(path, _stats) {
52
52
  await silgi.callHook("reload:scan", path, _stats);
53
53
  }
54
54
 
55
- const dev = defineCommand({
55
+ const command = defineCommand({
56
56
  meta: {
57
57
  name: "dev",
58
58
  description: "Start the development server for the project",
@@ -70,7 +70,7 @@ const dev = defineCommand({
70
70
  }
71
71
  },
72
72
  async run() {
73
- await runCommand(prepare, {
73
+ await runCommand(command$1, {
74
74
  rawArgs: ["--commandType", "dev", "--dev", "true"]
75
75
  });
76
76
  const silgi = useSilgiCLI();
@@ -103,7 +103,7 @@ const dev = defineCommand({
103
103
  silgi.errors = [];
104
104
  try {
105
105
  await reloadScan(path, stats);
106
- await runCommand(prepare, {
106
+ await runCommand(command$1, {
107
107
  rawArgs: ["--commands", "run", "--dev", "true"]
108
108
  });
109
109
  } catch (error) {
@@ -132,4 +132,4 @@ const dev = defineCommand({
132
132
  }
133
133
  });
134
134
 
135
- export { dev as default };
135
+ export { command as default };
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { defineCommand, runMain } from 'citty';
3
3
 
4
- const version = "0.29.21";
4
+ const version = "0.29.23";
5
5
  const packageJson = {
6
6
  version: version};
7
7
 
@@ -18,7 +18,7 @@ const main = defineCommand({
18
18
  }
19
19
  },
20
20
  subCommands: {
21
- prepare: () => import('./prepare.mjs').then(function (n) { return n.a; }).then((m) => m.default),
21
+ prepare: () => import('./prepare.mjs').then(function (n) { return n.p; }).then((m) => m.default),
22
22
  init: () => import('./init.mjs').then((m) => m.default),
23
23
  run: () => import('./prepare.mjs').then(function (n) { return n.r; }).then((m) => m.default),
24
24
  install: () => import('./install.mjs').then((m) => m.default),
package/dist/cli/init.mjs CHANGED
@@ -4,11 +4,11 @@ import * as p from '@clack/prompts';
4
4
  import { defineCommand, runCommand } from 'citty';
5
5
  import consola from 'consola';
6
6
  import { dirname } from 'pathe';
7
- import { p as prepare } from './prepare.mjs';
7
+ import { isPresents } from 'silgi/kit';
8
+ import { c as cancelOnCancel, a as command$1 } from './prepare.mjs';
8
9
  import 'silgi/meta';
9
10
  import './silgi.mjs';
10
11
  import 'apiful/openapi';
11
- import 'silgi/kit';
12
12
  import 'knitwork';
13
13
  import 'mlly';
14
14
  import 'pathe/utils';
@@ -45,7 +45,7 @@ import 'node:child_process';
45
45
  import '../_chunks/silgiApp.mjs';
46
46
  import 'unctx';
47
47
 
48
- const init = defineCommand({
48
+ const command = defineCommand({
49
49
  meta: {
50
50
  name: "Silgi Init",
51
51
  description: "Initialize silgi config",
@@ -61,12 +61,10 @@ const init = defineCommand({
61
61
  { label: "Nuxt", value: "nuxt" },
62
62
  { label: "H3", value: "h3" },
63
63
  { label: "NPM Package", value: "npm-package" }
64
- ]
64
+ ],
65
+ initialValue: "h3"
65
66
  });
66
- if (p.isCancel(framework)) {
67
- consola.info("Silgi config initialization canceled");
68
- return;
69
- }
67
+ cancelOnCancel({ value: framework });
70
68
  const context = [
71
69
  `import { defineSilgiConfig } from 'silgi/config'`,
72
70
  "",
@@ -79,20 +77,19 @@ const init = defineCommand({
79
77
  "})",
80
78
  ""
81
79
  ];
82
- if (framework === "nitro" || framework === "nuxt") {
80
+ if (isPresents(["nitro", "nuxt"])) {
83
81
  const plugin = [
84
82
  `import { buildSilgi } from '../silgi/core'`,
85
83
  "",
86
84
  "export default defineNitroPlugin(async (nitro) => {",
87
85
  "",
88
- " const _silgi = buildSilgi(",
89
- " nitro,",
90
- " {},",
91
- " {",
86
+ " await buildSilgi({",
87
+ " framework: nitro,",
88
+ " options: {",
92
89
  " putStorage: useStorage(),",
93
90
  " runtimeConfig: useRuntimeConfig(),",
94
91
  " },",
95
- " )",
92
+ " })",
96
93
  "})",
97
94
  ""
98
95
  ];
@@ -100,7 +97,7 @@ const init = defineCommand({
100
97
  await fsp.mkdir(dirname(file), { recursive: true });
101
98
  writeFileSync(file, plugin.join("\n"));
102
99
  consola.success("Silgi plugin created, see server/plugins/silgi.ts");
103
- runCommand(prepare, {
100
+ runCommand(command$1, {
104
101
  rawArgs: ["--env", ".env"]
105
102
  });
106
103
  }
@@ -109,4 +106,4 @@ const init = defineCommand({
109
106
  }
110
107
  });
111
108
 
112
- export { init as default };
109
+ export { command as default };
@@ -4,7 +4,7 @@ import { consola } from 'consola';
4
4
  import { version } from 'silgi/meta';
5
5
  import { addNPMPackage, addTemplate } from 'silgi/kit';
6
6
  import { u as useSilgiCLI } from '../_chunks/silgiApp.mjs';
7
- import { c as commonArgs, p as prepare } from './prepare.mjs';
7
+ import { b as commonArgs, a as command$1 } from './prepare.mjs';
8
8
  import 'unctx';
9
9
  import 'pathe';
10
10
  import './silgi.mjs';
@@ -79,7 +79,7 @@ async function installPackages(silgi = useSilgiCLI()) {
79
79
  };
80
80
  packages.dependencies = {};
81
81
  }
82
- if (silgi.options.debug === true || silgi.options.debug.install) {
82
+ if (silgi.options.debug === true || silgi.options.debug?.install) {
83
83
  addTemplate({
84
84
  filename: "install.json",
85
85
  where: ".silgi",
@@ -90,7 +90,7 @@ async function installPackages(silgi = useSilgiCLI()) {
90
90
  return packages;
91
91
  }
92
92
 
93
- const install = defineCommand({
93
+ const command = defineCommand({
94
94
  meta: {
95
95
  name: "install",
96
96
  description: "Install dependencies from the install.json file.",
@@ -104,7 +104,7 @@ const install = defineCommand({
104
104
  }
105
105
  },
106
106
  async run() {
107
- await runCommand(prepare, {
107
+ await runCommand(command$1, {
108
108
  rawArgs: ["--commandType", "install"]
109
109
  }).catch(() => {
110
110
  });
@@ -133,4 +133,4 @@ const install = defineCommand({
133
133
  }
134
134
  });
135
135
 
136
- export { install as default };
136
+ export { command as default };
@@ -44,7 +44,7 @@ async function scanCommands(silgi = useSilgiCLI()) {
44
44
  getContents: () => JSON.stringify(commands, null, 2)
45
45
  });
46
46
  }
47
- silgi.hook("prepare:schema.ts", async (object) => {
47
+ silgi.hook("before:schema.ts", async () => {
48
48
  const allTags = commands.reduce((acc, commandGroup) => {
49
49
  Object.values(commandGroup).forEach((command) => {
50
50
  if (command.tags) {
@@ -71,7 +71,12 @@ async function scanCommands(silgi = useSilgiCLI()) {
71
71
  ),
72
72
  ""
73
73
  ];
74
- object.customImports?.push(...data);
74
+ addTemplate({
75
+ filename: "types/commands.d.ts",
76
+ write: true,
77
+ where: ".silgi",
78
+ getContents: () => data.join("\n")
79
+ });
75
80
  });
76
81
  return commands;
77
82
  }
@@ -91,7 +96,7 @@ function cancelOnCancel({
91
96
  handleCancel();
92
97
  }
93
98
 
94
- const run = defineCommand({
99
+ const command$1 = defineCommand({
95
100
  meta: {
96
101
  name: "run",
97
102
  description: "Run a command from the CLI",
@@ -114,7 +119,7 @@ const run = defineCommand({
114
119
  },
115
120
  async run({ args }) {
116
121
  if (args.prepare) {
117
- await runCommand(prepare, {
122
+ await runCommand(command, {
118
123
  rawArgs: ["--commandType", "run"]
119
124
  });
120
125
  }
@@ -189,12 +194,12 @@ const run = defineCommand({
189
194
  }
190
195
  });
191
196
 
192
- const run$1 = {
197
+ const run = {
193
198
  __proto__: null,
194
- default: run
199
+ default: command$1
195
200
  };
196
201
 
197
- const prepare = defineCommand({
202
+ const command = defineCommand({
198
203
  meta: {
199
204
  name: "prepare",
200
205
  description: "Generate types for the project",
@@ -235,16 +240,16 @@ const prepare = defineCommand({
235
240
  });
236
241
  await build(silgi);
237
242
  if (args.commandType !== "run") {
238
- await runCommand(run, {
243
+ await runCommand(command$1, {
239
244
  rawArgs: ["--tag", "init", "--prepare", "false"]
240
245
  });
241
246
  }
242
247
  }
243
248
  });
244
249
 
245
- const prepare$1 = {
250
+ const prepare = {
246
251
  __proto__: null,
247
- default: prepare
252
+ default: command
248
253
  };
249
254
 
250
- export { prepare$1 as a, commonArgs as c, prepare as p, run$1 as r };
255
+ export { command as a, commonArgs as b, cancelOnCancel as c, prepare as p, run as r };
@@ -1,7 +1,7 @@
1
1
  import { generateDTS } from 'apiful/openapi';
2
2
  import consola$1, { consola } from 'consola';
3
- import { join, resolve, dirname, isAbsolute, relative, basename, extname } from 'pathe';
4
- import { hasSilgiModule, addTemplate, normalizeTemplate, useLogger, genEnsureSafeVar, baseHeaderBannerComment, addImports, hash, toArray, writeFile, relativeWithDot, isDirectory, addCoreFile, resolveAlias as resolveAlias$1, directoryToURL, hasError, parseServices, resolveSilgiPath } from 'silgi/kit';
3
+ import { join, resolve, dirname, relative, isAbsolute, basename, extname } from 'pathe';
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
7
  import { genObjectFromRawEntries, genImport, genTypeImport, genObjectFromRaw, genObjectFromValues } from 'knitwork';
@@ -486,80 +486,41 @@ ${methodEntries}
486
486
  return context;
487
487
  }
488
488
 
489
- async function createDTSFramework(silgi) {
490
- const importItems = {
491
- "silgi/types": {
492
- import: [
493
- {
494
- name: "SilgiRuntimeContext",
495
- type: true,
496
- key: "SilgiRuntimeContext"
497
- }
498
- ],
499
- from: "silgi/types"
500
- }
501
- };
502
- const customImports = [];
503
- const customContent = [];
504
- await silgi.callHook("prepare:createDTSFramework", {
505
- importItems,
506
- customImports,
507
- customContent
508
- });
509
- const content = [
510
- ...Object.entries(importItems).map(([_name, { from, import: imports }]) => {
511
- const path = isAbsolute(from) ? relativeWithDot(silgi.options.build.typesDir, from) : from;
512
- if (silgi.options.typescript.removeFileExtension) {
513
- from = from.replace(/\.(js|ts|mjs|cjs|jsx|tsx)$/, "");
514
- }
515
- return `import { ${imports.map(({ type, name }) => type ? `type ${name}` : name).join(", ")} } from '${path}'`;
516
- }),
517
- "",
518
- ...customImports,
519
- "",
520
- ...customContent,
521
- ""
522
- ];
523
- return {
524
- content,
525
- importItems
526
- };
527
- }
528
-
529
489
  async function prepareSchema(silgi) {
530
- const importItems = {
531
- "silgi/types": {
532
- import: [
533
- {
534
- name: "URIsTypes",
535
- type: true,
536
- key: "URIsTypes"
537
- },
538
- {
539
- name: "Namespaces",
540
- type: true,
541
- key: "Namespaces"
542
- },
543
- {
544
- name: "SilgiRuntimeContext",
545
- type: true,
546
- key: "SilgiRuntimeContext"
547
- }
548
- ],
549
- from: "silgi/types"
550
- },
551
- "silgi/scan": {
552
- import: [{
553
- key: "modulesURIs",
554
- name: "modulesURIs",
555
- type: false
556
- }],
557
- from: relativeWithDot(silgi.options.build.typesDir, `${silgi.options.silgi.serverDir}/scan.ts`)
558
- }
559
- };
490
+ const { genImports, genTypeImports, addImportItem, addImportItemType } = addImports({
491
+ imports: [
492
+ {
493
+ specifier: relativeWithDot(
494
+ silgi.options.build.typesDir,
495
+ `${silgi.options.silgi.serverDir}/scan`
496
+ ),
497
+ imports: [
498
+ {
499
+ name: "modulesURIs"
500
+ }
501
+ ]
502
+ }
503
+ ],
504
+ typeImports: [
505
+ {
506
+ specifier: "silgi/types",
507
+ imports: [
508
+ {
509
+ name: "URIsTypes"
510
+ },
511
+ {
512
+ name: "Namespaces"
513
+ },
514
+ {
515
+ name: "SilgiRuntimeContext"
516
+ }
517
+ ]
518
+ }
519
+ ]
520
+ });
560
521
  const data = {
561
- importItems,
562
- customImports: [],
522
+ addImportItem,
523
+ addImportItemType,
563
524
  options: [],
564
525
  contexts: [],
565
526
  actions: [],
@@ -577,26 +538,34 @@ async function prepareSchema(silgi) {
577
538
  routeRules: [],
578
539
  routeRulesConfig: []
579
540
  };
580
- await silgi.callHook("prepare:schema.ts", data);
581
- relativeWithDot(silgi.options.build.typesDir, `${silgi.options.silgi.serverDir}/core.ts`);
582
- const silgiScanTS = relativeWithDot(silgi.options.build.typesDir, `${silgi.options.silgi.serverDir}/scan.ts`);
541
+ await silgi.callHook("before:schema.ts", data);
542
+ relativeWithDot(silgi.options.build.typesDir, `${silgi.options.silgi.serverDir}/core`);
543
+ const silgiScanTS = relativeWithDot(silgi.options.build.typesDir, `${silgi.options.silgi.serverDir}/scan`);
583
544
  let addSilgiContext = false;
584
545
  const importsContent = [
585
- ...Object.entries(importItems).map(([_name, { from, import: imports }]) => {
586
- const path = isAbsolute(from) ? relativeWithDot(silgi.options.build.typesDir, from) : from;
587
- if (silgi.options.typescript.removeFileExtension) {
588
- from = from.replace(/\.(js|ts|mjs|cjs|jsx|tsx)$/, "");
589
- }
590
- return `import { ${imports.map(({ type, name }) => type ? `type ${name}` : name).join(", ")} } from '${path}'`;
546
+ ...genImports.map(({ specifier, imports, options }) => {
547
+ return genImport(specifier, imports, options);
548
+ }),
549
+ ...genTypeImports.map(({ specifier, imports }) => {
550
+ return genTypeImport(specifier, Array.isArray(imports) ? imports : [imports]);
591
551
  }),
592
- "",
593
- ...data.customImports,
594
552
  ""
595
553
  ];
596
554
  const importData = [
597
- "interface InferredNamespaces {",
598
- ...(silgi.options.namespaces || []).map((key) => ` ${key}: string,`),
599
- "}",
555
+ generateTypes(
556
+ await resolveSchema(
557
+ {
558
+ ...silgi.options.namespaces?.reduce((acc, key) => ({ ...acc, [key]: "" }), {}) || {}
559
+ }
560
+ ),
561
+ {
562
+ interfaceName: "InferredNamespaces",
563
+ addExport: false,
564
+ addDefaults: false,
565
+ allowExtraKeys: false,
566
+ indentation: 0
567
+ }
568
+ ),
600
569
  "",
601
570
  `type SchemaExtends = Namespaces<typeof import('${silgiScanTS}')['schemas']>`,
602
571
  "",
@@ -693,7 +662,7 @@ async function prepareSchema(silgi) {
693
662
  "",
694
663
  "export {}"
695
664
  ];
696
- await silgi.callHook("after:prepare:schema.ts", importData);
665
+ await silgi.callHook("after:schema.ts", importData);
697
666
  importData.unshift(...importsContent);
698
667
  return importData;
699
668
  }
@@ -703,10 +672,8 @@ async function writeTypesAndFiles(silgi) {
703
672
  silgi.hook("prepare:types", (opts) => {
704
673
  opts.references.push({ path: "./schema.d.ts" });
705
674
  opts.references.push({ path: "./silgi-routes.d.ts" });
706
- opts.references.push({ path: "./framework.d.ts" });
707
675
  });
708
676
  const schemaContent = await prepareSchema(silgi);
709
- const frameworkDTS = await createDTSFramework(silgi);
710
677
  const { declarations, tsConfig } = await silgiGenerateType(silgi);
711
678
  const tsConfigPath = resolve(
712
679
  silgi.options.rootDir,
@@ -780,10 +747,6 @@ async function writeTypesAndFiles(silgi) {
780
747
  path: tsConfigPath,
781
748
  contents: JSON.stringify(tsConfig, null, 2)
782
749
  });
783
- buildFiles.push({
784
- path: join(typesDir, "framework.d.ts"),
785
- contents: frameworkDTS.content.join("\n")
786
- });
787
750
  for await (const file of buildFiles) {
788
751
  if (!silgi.errors.length) {
789
752
  await writeFile(
@@ -835,9 +798,9 @@ export const routeRules = ${genObjectFromRawEntries(
835
798
  async function build(silgi) {
836
799
  await prepare();
837
800
  await generateApiFul(silgi);
838
- await writeTypesAndFiles(silgi);
839
801
  await writeCoreFile(silgi);
840
802
  await prepareBuild(silgi);
803
+ await writeTypesAndFiles(silgi);
841
804
  await generateApp(silgi);
842
805
  }
843
806
 
@@ -950,41 +913,39 @@ async function prepareEnv(silgiConfig) {
950
913
 
951
914
  async function emptyFramework(silgi) {
952
915
  if (silgi.options.preset === "npm-package" || !silgi.options.preset) {
953
- silgi.hook("after:prepare:schema.ts", (data) => {
916
+ silgi.hook("after:schema.ts", (data) => {
954
917
  data.unshift("type FrameworkContextExtends = {}");
955
918
  });
956
919
  }
957
920
  }
958
921
 
959
922
  async function h3Framework(silgi, skip = false) {
960
- if (silgi.options.preset !== "h3" && skip === false)
923
+ if (!isPresents(["h3"]) && skip === false)
961
924
  return;
962
- if (silgi.options.preset === "h3") {
963
- silgi.hook("after:prepare:schema.ts", (data) => {
925
+ if (isPresents(["h3"])) {
926
+ silgi.hook("after:schema.ts", (data) => {
964
927
  data.unshift("type FrameworkContextExtends = NitroApp");
965
928
  });
966
929
  }
967
- silgi.hook("prepare:schema.ts", (data) => {
968
- data.importItems.nitropack = {
969
- import: [
970
- {
971
- name: "NitroApp",
972
- type: true,
973
- key: "NitroApp"
974
- }
975
- ],
976
- from: "nitropack/types"
977
- };
978
- data.importItems.h3 = {
979
- import: [
980
- {
981
- name: "H3Event",
982
- type: true,
983
- key: "H3Event"
984
- }
985
- ],
986
- from: "h3"
987
- };
930
+ silgi.hook("before:schema.ts", (data) => {
931
+ data.addImportItemType([
932
+ {
933
+ imports: [
934
+ {
935
+ name: "H3Event"
936
+ }
937
+ ],
938
+ specifier: "h3"
939
+ },
940
+ {
941
+ imports: [
942
+ {
943
+ name: "NitroApp"
944
+ }
945
+ ],
946
+ specifier: "nitropack/types"
947
+ }
948
+ ]);
988
949
  data.events.push({
989
950
  key: "H3Event",
990
951
  value: "H3Event",
@@ -992,24 +953,22 @@ async function h3Framework(silgi, skip = false) {
992
953
  isSilgiContext: false
993
954
  });
994
955
  });
995
- silgi.hook("prepare:createDTSFramework", (data) => {
996
- data.importItems["silgi/types"] = {
997
- import: [
998
- {
999
- name: "SilgiRuntimeContext",
1000
- type: true,
1001
- key: "SilgiRuntimeContext"
1002
- }
1003
- ],
1004
- from: "silgi/types"
1005
- };
1006
- data.customContent?.push(
1007
- "",
1008
- 'declare module "h3" {',
1009
- " interface H3EventContext extends SilgiRuntimeContext {}",
1010
- "}",
1011
- ""
1012
- );
956
+ silgi.hook("prepare:types", (opts) => {
957
+ addTemplate({
958
+ filename: "types/h3.d.ts",
959
+ where: ".silgi",
960
+ getContents: () => {
961
+ return [
962
+ "import type { SilgiRuntimeContext } from 'silgi/types'",
963
+ "",
964
+ 'declare module "h3" {',
965
+ " interface H3EventContext extends SilgiRuntimeContext {}",
966
+ "}",
967
+ ""
968
+ ].join("\n");
969
+ }
970
+ });
971
+ opts.references.push({ path: "./h3.d.ts" });
1013
972
  });
1014
973
  addCoreFile({
1015
974
  before: ({ silgiConfigs }) => {
@@ -1047,45 +1006,41 @@ async function h3Framework(silgi, skip = false) {
1047
1006
  }
1048
1007
 
1049
1008
  async function nitroFramework(silgi, skip = false) {
1050
- if (silgi.options.preset !== "nitro" && skip === false)
1009
+ if (!isPresents(["nitro"]) && skip === false)
1051
1010
  return;
1052
- silgi.hook("prepare:schema.ts", (data) => {
1053
- data.importItems.nitropack = {
1054
- import: [
1011
+ silgi.hook("before:schema.ts", (data) => {
1012
+ data.addImportItemType({
1013
+ imports: [
1055
1014
  {
1056
- name: "NitroApp",
1057
- type: true,
1058
- key: "NitroApp"
1015
+ name: "NitroApp"
1059
1016
  }
1060
1017
  ],
1061
- from: "nitropack/types"
1062
- };
1018
+ specifier: "nitropack/types"
1019
+ });
1063
1020
  });
1064
- silgi.hook("after:prepare:schema.ts", (data) => {
1021
+ silgi.hook("after:schema.ts", (data) => {
1065
1022
  data.unshift("type FrameworkContextExtends = NitroApp");
1066
1023
  });
1067
1024
  silgi.options.plugins.push({
1068
1025
  packageImport: "silgi/runtime/internal/nitro",
1069
1026
  path: join(runtimeDir, "internal/nitro")
1070
1027
  });
1071
- silgi.hook("prepare:createDTSFramework", (data) => {
1072
- data.importItems["nitropack/types"] = {
1073
- import: [
1074
- {
1075
- name: "NitroRuntimeConfig",
1076
- type: true,
1077
- key: "NitroRuntimeConfig"
1078
- }
1079
- ],
1080
- from: "nitropack/types"
1081
- };
1082
- data.customContent?.push(
1083
- "",
1084
- 'declare module "silgi/types" {',
1085
- " interface SilgiRuntimeConfig extends NitroRuntimeConfig {}",
1086
- "}",
1087
- ""
1088
- );
1028
+ silgi.hook("prepare:types", (opts) => {
1029
+ addTemplate({
1030
+ filename: "types/nitro.d.ts",
1031
+ where: ".silgi",
1032
+ getContents: () => {
1033
+ return [
1034
+ "import type { NitroRuntimeConfig } from 'nitropack/types'",
1035
+ "",
1036
+ 'declare module "silgi/types" {',
1037
+ " interface SilgiRuntimeConfig extends NitroRuntimeConfig {}",
1038
+ "}",
1039
+ ""
1040
+ ].join("\n");
1041
+ }
1042
+ });
1043
+ opts.references.push({ path: "./nitro.d.ts" });
1089
1044
  });
1090
1045
  if (silgi.options.imports !== false) {
1091
1046
  silgi.options.imports.presets ??= [];
@@ -1107,7 +1062,7 @@ const frameworkSetup = [
1107
1062
  ];
1108
1063
 
1109
1064
  async function registerModuleExportScan(silgi) {
1110
- silgi.hook("prepare:schema.ts", async (options) => {
1065
+ silgi.hook("before:schema.ts", async (options) => {
1111
1066
  for (const module of silgi.scanModules) {
1112
1067
  const moduleReExports = [];
1113
1068
  if (!module.entryPath) {
@@ -1124,106 +1079,147 @@ async function registerModuleExportScan(silgi) {
1124
1079
  const hasTypeExport = (name) => moduleReExports.find((exp) => exp.names?.includes(name));
1125
1080
  const configKey = module.meta.configKey;
1126
1081
  const moduleName = module.meta.name || module.meta._packageName;
1127
- options.importItems[configKey] = {
1128
- import: [],
1129
- from: module.meta._packageName ? moduleName : relativeWithDot(silgi.options.build.typesDir, module.entryPath)
1130
- };
1082
+ const specifier = module.meta._packageName ? moduleName : relativeWithDot(silgi.options.build.typesDir, module.entryPath);
1131
1083
  if (hasTypeExport("ModuleOptions")) {
1132
- const importName = `_${hash(`${configKey}ModuleOptions`)}`;
1133
- options.importItems[configKey].import.push({
1134
- name: `ModuleOptions as ${importName}`,
1135
- type: true,
1136
- key: importName
1084
+ const importName = hash(`${configKey}ModuleOptions`);
1085
+ options.addImportItemType({
1086
+ imports: [
1087
+ {
1088
+ as: importName,
1089
+ name: "ModuleOptions"
1090
+ }
1091
+ ],
1092
+ specifier
1137
1093
  });
1138
1094
  options.options.push({ key: configKey, value: importName });
1139
1095
  }
1140
1096
  if (hasTypeExport("ModuleRuntimeOptions")) {
1141
- const importName = `_${hash(`${configKey}ModuleRuntimeOptions`)}`;
1142
- options.importItems[configKey].import.push({
1143
- name: `ModuleRuntimeOptions as ${importName}`,
1144
- type: true,
1145
- key: importName
1097
+ const importName = hash(`${configKey}ModuleRuntimeOptions`);
1098
+ options.addImportItemType({
1099
+ imports: [
1100
+ {
1101
+ as: importName,
1102
+ name: "ModuleRuntimeOptions"
1103
+ }
1104
+ ],
1105
+ specifier
1146
1106
  });
1147
1107
  options.runtimeOptions.push({ key: configKey, value: importName });
1148
1108
  }
1149
1109
  if (hasTypeExport("ModuleRuntimeShareds")) {
1150
- const importName = `_${hash(`${configKey}ModuleRuntimeShareds`)}`;
1151
- options.importItems[configKey].import.push({
1152
- name: `ModuleRuntimeShareds as ${importName}`,
1153
- type: true,
1154
- key: importName
1110
+ const importName = hash(`${configKey}ModuleRuntimeShareds`);
1111
+ options.addImportItemType({
1112
+ imports: [
1113
+ {
1114
+ as: importName,
1115
+ name: "ModuleRuntimeShareds"
1116
+ }
1117
+ ],
1118
+ specifier
1155
1119
  });
1156
1120
  options.shareds.push({ key: configKey, value: importName });
1157
1121
  }
1158
1122
  if (hasTypeExport("ModuleEvents")) {
1159
- const importName = `_${hash(`${configKey}ModuleEvents`)}`;
1160
- options.importItems[configKey].import.push({
1161
- name: `ModuleEvents as ${importName}`,
1162
- type: true,
1163
- key: importName
1123
+ const importName = hash(`${configKey}ModuleEvents`);
1124
+ options.addImportItemType({
1125
+ imports: [
1126
+ {
1127
+ as: importName,
1128
+ name: "ModuleEvents"
1129
+ }
1130
+ ],
1131
+ specifier
1164
1132
  });
1165
1133
  options.events.push({ key: configKey, value: importName });
1166
1134
  }
1167
1135
  if (hasTypeExport("ModuleRuntimeContexts")) {
1168
- const importName = `_${hash(`${configKey}ModuleRuntimeContexts`)}`;
1169
- options.importItems[configKey].import.push({
1170
- name: `ModuleRuntimeContexts as ${importName}`,
1171
- type: true,
1172
- key: importName
1136
+ const importName = hash(`${configKey}ModuleRuntimeContexts`);
1137
+ options.addImportItemType({
1138
+ imports: [
1139
+ {
1140
+ as: importName,
1141
+ name: "ModuleRuntimeContexts"
1142
+ }
1143
+ ],
1144
+ specifier
1173
1145
  });
1174
1146
  options.contexts.push({ key: configKey, value: importName });
1175
1147
  }
1176
1148
  if (hasTypeExport("ModuleHooks")) {
1177
- const importName = `_${hash(`${configKey}ModuleHooks`)}`;
1178
- options.importItems[configKey].import.push({
1179
- name: `ModuleHooks as ${importName}`,
1180
- type: true,
1181
- key: importName
1149
+ const importName = hash(`${configKey}ModuleHooks`);
1150
+ options.addImportItemType({
1151
+ imports: [
1152
+ {
1153
+ as: importName,
1154
+ name: "ModuleHooks"
1155
+ }
1156
+ ],
1157
+ specifier
1182
1158
  });
1183
1159
  options.hooks.push({ key: configKey, value: importName });
1184
1160
  }
1185
1161
  if (hasTypeExport("ModuleRuntimeHooks")) {
1186
- const importName = `_${hash(`${configKey}RuntimeHooks`)}`;
1187
- options.importItems[configKey].import.push({
1188
- name: `ModuleRuntimeHooks as ${importName}`,
1189
- type: true,
1190
- key: importName
1162
+ const importName = hash(`${configKey}RuntimeHooks`);
1163
+ options.addImportItemType({
1164
+ imports: [
1165
+ {
1166
+ as: importName,
1167
+ name: "ModuleRuntimeHooks"
1168
+ }
1169
+ ],
1170
+ specifier
1191
1171
  });
1192
1172
  options.runtimeHooks.push({ key: configKey, value: importName });
1193
1173
  }
1194
1174
  if (hasTypeExport("ModuleRuntimeActions")) {
1195
- const importName = `_${hash(`${configKey}ModuleRuntimeActions`)}`;
1196
- options.importItems[configKey].import.push({
1197
- name: `ModuleRuntimeActions as ${importName}`,
1198
- type: true,
1199
- key: importName
1175
+ const importName = hash(`${configKey}ModuleRuntimeActions`);
1176
+ options.addImportItemType({
1177
+ imports: [
1178
+ {
1179
+ as: importName,
1180
+ name: "ModuleRuntimeActions"
1181
+ }
1182
+ ],
1183
+ specifier
1200
1184
  });
1201
1185
  options.actions.push({ key: configKey, value: importName });
1202
1186
  }
1203
1187
  if (hasTypeExport("ModuleRuntimeMethods")) {
1204
- const importName = `_${hash(`${configKey}ModuleRuntimeMethods`)}`;
1205
- options.importItems[configKey].import.push({
1206
- name: `ModuleRuntimeMethods as ${importName}`,
1207
- type: true,
1208
- key: importName
1188
+ const importName = hash(`${configKey}ModuleRuntimeMethods`);
1189
+ options.addImportItemType({
1190
+ imports: [
1191
+ {
1192
+ as: importName,
1193
+ name: "ModuleRuntimeMethods"
1194
+ }
1195
+ ],
1196
+ specifier
1209
1197
  });
1210
1198
  options.methods.push({ key: configKey, value: importName });
1211
1199
  }
1212
1200
  if (hasTypeExport("ModuleRuntimeRouteRules")) {
1213
- const importName = `_${hash(`${configKey}ModuleRuntimeRouteRules`)}`;
1214
- options.importItems[configKey].import.push({
1215
- name: `ModuleRuntimeRouteRules as ${importName}`,
1216
- type: true,
1217
- key: importName
1201
+ const importName = hash(`${configKey}ModuleRuntimeRouteRules`);
1202
+ options.addImportItemType({
1203
+ imports: [
1204
+ {
1205
+ as: importName,
1206
+ name: "ModuleRuntimeRouteRules"
1207
+ }
1208
+ ],
1209
+ specifier
1218
1210
  });
1219
1211
  options.routeRules.push({ key: configKey, value: importName });
1220
1212
  }
1221
1213
  if (hasTypeExport("ModuleRuntimeRouteRulesConfig")) {
1222
- const importName = `_${hash(`${configKey}ModuleRuntimeRouteRulesConfig`)}`;
1223
- options.importItems[configKey].import.push({
1224
- name: `ModuleRuntimeRouteRulesConfig as ${importName}`,
1225
- type: true,
1226
- key: importName
1214
+ const importName = hash(`${configKey}ModuleRuntimeRouteRulesConfig`);
1215
+ options.addImportItemType({
1216
+ imports: [
1217
+ {
1218
+ as: importName,
1219
+ name: "ModuleRuntimeRouteRulesConfig"
1220
+ }
1221
+ ],
1222
+ specifier
1227
1223
  });
1228
1224
  options.routeRulesConfig.push({ key: configKey, value: importName });
1229
1225
  }
@@ -1818,7 +1814,7 @@ async function scanExportFile(silgi) {
1818
1814
  });
1819
1815
  }
1820
1816
  });
1821
- silgi.hook("prepare:schema.ts", (options) => {
1817
+ silgi.hook("before:schema.ts", (options) => {
1822
1818
  for (const { exportName, path, _name, type } of schemaTS) {
1823
1819
  if (!path.includes("vfs")) {
1824
1820
  silgi.options.devServer.watch.push(path);
@@ -1835,13 +1831,14 @@ async function scanExportFile(silgi) {
1835
1831
  value: _name
1836
1832
  });
1837
1833
  }
1838
- options.importItems[path] ??= {
1839
- import: [],
1840
- from: relativeWithDot(silgi.options.build.typesDir, path)
1841
- };
1842
- options.importItems[path].import.push({
1843
- name: `${exportName} as ${_name}`,
1844
- key: _name
1834
+ options.addImportItem({
1835
+ imports: [
1836
+ {
1837
+ name: _name,
1838
+ as: exportName
1839
+ }
1840
+ ],
1841
+ specifier: relativeWithDot(silgi.options.build.typesDir, path)
1845
1842
  });
1846
1843
  }
1847
1844
  });
@@ -1952,7 +1949,7 @@ ${injectedResult.code}`;
1952
1949
  }
1953
1950
  }
1954
1951
 
1955
- async function prepareServerFiles(silgi) {
1952
+ async function prepareScanFile(silgi) {
1956
1953
  const { genImports, genTypeImports, addImportItem, addImportItemType } = addImports({
1957
1954
  imports: [
1958
1955
  {
@@ -2073,7 +2070,7 @@ async function prepareServerFiles(silgi) {
2073
2070
  }
2074
2071
 
2075
2072
  async function writeScanFiles(silgi) {
2076
- const data = await prepareServerFiles(silgi);
2073
+ const data = await prepareScanFile(silgi);
2077
2074
  if (!silgi.errors.length) {
2078
2075
  await writeFile(
2079
2076
  resolve(silgi.options.silgi.serverDir, "scan.ts"),
@@ -34,23 +34,6 @@ interface SilgiCompatibilityIssues extends Array<SilgiCompatibilityIssue> {
34
34
  toString: () => string;
35
35
  }
36
36
 
37
- /**
38
- * @deprecated
39
- */
40
- interface ImportItem {
41
- importItems: {
42
- [key: string]: {
43
- import: {
44
- type?: boolean;
45
- name: string;
46
- key: string;
47
- }[];
48
- from: string;
49
- };
50
- };
51
- customImports: string[];
52
- customContent?: string[];
53
- }
54
37
  interface SilgiCLI {
55
38
  _ignore?: Ignore;
56
39
  errors: {
@@ -185,7 +168,6 @@ interface SilgiCLIHooks extends SilgiHooks {
185
168
  */
186
169
  'close': (silgi: SilgiCLI) => HookResult;
187
170
  'reload:scan': (path: string, stats?: Stats) => HookResult;
188
- 'prepare:createDTSFramework': (options: ImportItem) => HookResult;
189
171
  /**
190
172
  * Allows extending compatibility checks.
191
173
  * @param compatibility Compatibility object
@@ -228,7 +210,9 @@ interface SilgiCLIHooks extends SilgiHooks {
228
210
  addImportItemType: (data: GenImport | GenImport[]) => void;
229
211
  }) => HookResult;
230
212
  'after:prepare:scan.ts': (content: string[]) => HookResult;
231
- 'prepare:schema.ts': (options: {
213
+ 'before:schema.ts': (options: {
214
+ addImportItem: (data: GenImport | GenImport[]) => void;
215
+ addImportItemType: (data: GenImport | GenImport[]) => void;
232
216
  options: {
233
217
  key: string;
234
218
  value: string;
@@ -279,9 +263,8 @@ interface SilgiCLIHooks extends SilgiHooks {
279
263
  key: string;
280
264
  value: string;
281
265
  }[];
282
- } & ImportItem) => HookResult;
283
- 'after:prepare:schema.ts': (content: string[]) => HookResult;
284
- 'prepare:framework.d.ts': (options: {} & ImportItem) => HookResult;
266
+ }) => HookResult;
267
+ 'after:schema.ts': (content: string[]) => HookResult;
285
268
  'prepare:configs.ts': (cliOptions: Record<string, any>) => HookResult;
286
269
  /**
287
270
  * Called during `SilgiCLI` generation, to allow customizing, modifying or adding new files to the build directory (either virtually or to written to `.nuxt`).
@@ -1196,4 +1179,4 @@ interface ServiceParseModule {
1196
1179
  (params: ServiceParse): Awaited<void> | void;
1197
1180
  }
1198
1181
 
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, 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 };
1182
+ 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, LoadConfigOptions, MergedSilgiSchema, MethodHandlerType, ModuleDefinition, ModuleHookContext, ModuleMeta, ModuleOptionsCustom, ModuleSetupInstallResult, ModuleSetupReturn, Namespaces, NitroBuildInfo, 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.21",
4
+ "version": "0.29.23",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {