silgi 0.6.0 → 0.7.0

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,8 +1,9 @@
1
- import { SilgiCLIConfig, LoadConfigOptions, SilgiCLIOptions, SilgiCLI, SilgiConfig, Silgi, SilgiRouterTypes, SilgiOperation, MergedSilgiSchema, ServiceType, SilgiSchema, RequiredServiceType, SilgiModuleShared, SilgiEvent, DefaultNamespaces, BaseSchemaType } from 'silgi/types';
1
+ import { SilgiCLIConfig, LoadConfigOptions, SilgiCLIOptions, SilgiCLI, SilgiConfig, Silgi, SilgiRouterTypes, SilgiOperation, MergedSilgiSchema, ServiceType, SilgiSchema, RequiredServiceType, ModuleRuntimeShared, SilgiEvent, DefaultNamespaces, BaseSchemaType } from 'silgi/types';
2
2
  import { TSConfig } from 'pkg-types';
3
3
  import { FetchOptions } from 'ofetch';
4
- export { c as createStorage, s as silgi, u as useStorage } from '../shared/silgi.DRWtysQv.mjs';
4
+ export { c as createStorage, s as silgi, u as useSilgiStorage } from '../shared/silgi.BFbL2aof.mjs';
5
5
  import { StandardSchemaV1 } from '@standard-schema/spec';
6
+ import * as unctx from 'unctx';
6
7
  import 'unstorage';
7
8
 
8
9
  declare function loadOptions(configOverrides?: SilgiCLIConfig, opts?: LoadConfigOptions): Promise<SilgiCLIOptions>;
@@ -84,7 +85,7 @@ declare function parseURI(uri: string, uris: Record<string, URITemplate>): Silgi
84
85
  type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
85
86
  declare function mergeSchemas<T extends MergedSilgiSchema[]>(typesOrArray: [...T] | T): UnionToIntersection<T[number]>;
86
87
  declare function mergeServices<T extends ServiceType<SilgiSchema>[]>(servicesOrArray: [...T] | T): RequiredServiceType<SilgiSchema>;
87
- declare function mergeShared<T extends SilgiModuleShared[]>(sharedOrArray: [...T] | T): UnionToIntersection<T[number]>;
88
+ declare function mergeShared<T extends ModuleRuntimeShared[]>(sharedOrArray: [...T] | T): UnionToIntersection<T[number]>;
88
89
 
89
90
  declare function getEvent<T>(event?: SilgiEvent): T;
90
91
 
@@ -96,7 +97,7 @@ declare function createSchema<T extends Partial<Record<keyof DefaultNamespaces,
96
97
 
97
98
  declare function createService<T extends SilgiSchema>(variables: ServiceType<T>): ServiceType<T>;
98
99
 
99
- declare function createShared(shared: Partial<SilgiModuleShared>): SilgiModuleShared;
100
+ declare function createShared(shared: Partial<ModuleRuntimeShared>): ModuleRuntimeShared;
100
101
 
101
102
  declare enum HttpStatus {
102
103
  /** [100] Server has received the request headers and client should proceed to send the request body */
@@ -286,6 +287,36 @@ declare class SilgiError extends Error implements BaseError {
286
287
  }
287
288
  declare function isBaseError(error: unknown): error is BaseError;
288
289
 
290
+ declare const silgiCtx: unctx.UseContext<Silgi>;
289
291
  declare function useSilgi(): Silgi;
292
+ /**
293
+ * Get access to Nuxt instance.
294
+ *
295
+ * Returns null if Nuxt instance is unavailable.
296
+ * @example
297
+ * ```js
298
+ * const silgi = tryUseSilgi()
299
+ * if (silgi) {
300
+ * // Do something
301
+ * }
302
+ * ```
303
+ */
304
+ declare function tryUseSilgi(): Silgi | null;
290
305
 
291
- export { type BaseError, ErrorCategory, ErrorFactory, type ErrorMetadata, ErrorSeverity, HttpStatus, SchemaParser, SilgiError, createSchema, createService, createShared, createSilgi, createSilgiFetch, getEvent, isBaseError, loadOptions, mergeSchemas, mergeServices, mergeShared, parseURI, silgiGenerateType, useSilgi };
306
+ declare const silgiCLICtx: unctx.UseContext<SilgiCLI>;
307
+ declare function useSilgiCLI(): SilgiCLI;
308
+ /**
309
+ * Get access to Nuxt instance.
310
+ *
311
+ * Returns null if Nuxt instance is unavailable.
312
+ * @example
313
+ * ```js
314
+ * const silgi = tryUseSilgi()
315
+ * if (silgi) {
316
+ * // Do something
317
+ * }
318
+ * ```
319
+ */
320
+ declare function tryUseSilgiCLI(): SilgiCLI | null;
321
+
322
+ export { type BaseError, ErrorCategory, ErrorFactory, type ErrorMetadata, ErrorSeverity, HttpStatus, SchemaParser, SilgiError, createSchema, createService, createShared, createSilgi, createSilgiFetch, getEvent, isBaseError, loadOptions, mergeSchemas, mergeServices, mergeShared, parseURI, silgiCLICtx, silgiCtx, silgiGenerateType, tryUseSilgi, tryUseSilgiCLI, useSilgi, useSilgiCLI };
@@ -1,8 +1,9 @@
1
- import { SilgiCLIConfig, LoadConfigOptions, SilgiCLIOptions, SilgiCLI, SilgiConfig, Silgi, SilgiRouterTypes, SilgiOperation, MergedSilgiSchema, ServiceType, SilgiSchema, RequiredServiceType, SilgiModuleShared, SilgiEvent, DefaultNamespaces, BaseSchemaType } from 'silgi/types';
1
+ import { SilgiCLIConfig, LoadConfigOptions, SilgiCLIOptions, SilgiCLI, SilgiConfig, Silgi, SilgiRouterTypes, SilgiOperation, MergedSilgiSchema, ServiceType, SilgiSchema, RequiredServiceType, ModuleRuntimeShared, SilgiEvent, DefaultNamespaces, BaseSchemaType } from 'silgi/types';
2
2
  import { TSConfig } from 'pkg-types';
3
3
  import { FetchOptions } from 'ofetch';
4
- export { c as createStorage, s as silgi, u as useStorage } from '../shared/silgi.DRWtysQv.js';
4
+ export { c as createStorage, s as silgi, u as useSilgiStorage } from '../shared/silgi.BFbL2aof.js';
5
5
  import { StandardSchemaV1 } from '@standard-schema/spec';
6
+ import * as unctx from 'unctx';
6
7
  import 'unstorage';
7
8
 
8
9
  declare function loadOptions(configOverrides?: SilgiCLIConfig, opts?: LoadConfigOptions): Promise<SilgiCLIOptions>;
@@ -84,7 +85,7 @@ declare function parseURI(uri: string, uris: Record<string, URITemplate>): Silgi
84
85
  type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
85
86
  declare function mergeSchemas<T extends MergedSilgiSchema[]>(typesOrArray: [...T] | T): UnionToIntersection<T[number]>;
86
87
  declare function mergeServices<T extends ServiceType<SilgiSchema>[]>(servicesOrArray: [...T] | T): RequiredServiceType<SilgiSchema>;
87
- declare function mergeShared<T extends SilgiModuleShared[]>(sharedOrArray: [...T] | T): UnionToIntersection<T[number]>;
88
+ declare function mergeShared<T extends ModuleRuntimeShared[]>(sharedOrArray: [...T] | T): UnionToIntersection<T[number]>;
88
89
 
89
90
  declare function getEvent<T>(event?: SilgiEvent): T;
90
91
 
@@ -96,7 +97,7 @@ declare function createSchema<T extends Partial<Record<keyof DefaultNamespaces,
96
97
 
97
98
  declare function createService<T extends SilgiSchema>(variables: ServiceType<T>): ServiceType<T>;
98
99
 
99
- declare function createShared(shared: Partial<SilgiModuleShared>): SilgiModuleShared;
100
+ declare function createShared(shared: Partial<ModuleRuntimeShared>): ModuleRuntimeShared;
100
101
 
101
102
  declare enum HttpStatus {
102
103
  /** [100] Server has received the request headers and client should proceed to send the request body */
@@ -286,6 +287,36 @@ declare class SilgiError extends Error implements BaseError {
286
287
  }
287
288
  declare function isBaseError(error: unknown): error is BaseError;
288
289
 
290
+ declare const silgiCtx: unctx.UseContext<Silgi>;
289
291
  declare function useSilgi(): Silgi;
292
+ /**
293
+ * Get access to Nuxt instance.
294
+ *
295
+ * Returns null if Nuxt instance is unavailable.
296
+ * @example
297
+ * ```js
298
+ * const silgi = tryUseSilgi()
299
+ * if (silgi) {
300
+ * // Do something
301
+ * }
302
+ * ```
303
+ */
304
+ declare function tryUseSilgi(): Silgi | null;
290
305
 
291
- export { type BaseError, ErrorCategory, ErrorFactory, type ErrorMetadata, ErrorSeverity, HttpStatus, SchemaParser, SilgiError, createSchema, createService, createShared, createSilgi, createSilgiFetch, getEvent, isBaseError, loadOptions, mergeSchemas, mergeServices, mergeShared, parseURI, silgiGenerateType, useSilgi };
306
+ declare const silgiCLICtx: unctx.UseContext<SilgiCLI>;
307
+ declare function useSilgiCLI(): SilgiCLI;
308
+ /**
309
+ * Get access to Nuxt instance.
310
+ *
311
+ * Returns null if Nuxt instance is unavailable.
312
+ * @example
313
+ * ```js
314
+ * const silgi = tryUseSilgi()
315
+ * if (silgi) {
316
+ * // Do something
317
+ * }
318
+ * ```
319
+ */
320
+ declare function tryUseSilgiCLI(): SilgiCLI | null;
321
+
322
+ export { type BaseError, ErrorCategory, ErrorFactory, type ErrorMetadata, ErrorSeverity, HttpStatus, SchemaParser, SilgiError, createSchema, createService, createShared, createSilgi, createSilgiFetch, getEvent, isBaseError, loadOptions, mergeSchemas, mergeServices, mergeShared, parseURI, silgiCLICtx, silgiCtx, silgiGenerateType, tryUseSilgi, tryUseSilgiCLI, useSilgi, useSilgiCLI };
@@ -36,7 +36,8 @@ const SilgiCLIDefaults = {
36
36
  scanDirs: [],
37
37
  build: {
38
38
  dir: ".silgi",
39
- typesDir: "{{ build.dir }}/types"
39
+ typesDir: "{{ build.dir }}/types",
40
+ templates: []
40
41
  },
41
42
  output: {
42
43
  dir: "{{ rootDir }}/.output",
@@ -50,9 +51,8 @@ const SilgiCLIDefaults = {
50
51
  clientDir: "{{ clientDir }}/silgi",
51
52
  publicDir: "{{ silgi.serverDir }}/public",
52
53
  utilsDir: "{{ silgi.serverDir }}/utils",
53
- composablesDir: "{{ silgi.serverDir }}/composables",
54
- typesDir: "{{ silgi.serverDir }}/types",
55
- servicesDir: "{{ silgi.serverDir }}/services"
54
+ vfsDir: "{{ silgi.serverDir }}/vfs",
55
+ typesDir: "{{ silgi.serverDir }}/types"
56
56
  },
57
57
  // Modules
58
58
  _modules: [],
@@ -62,6 +62,7 @@ const SilgiCLIDefaults = {
62
62
  future: {},
63
63
  storage: {},
64
64
  devStorage: {},
65
+ stub: false,
65
66
  // bundledStorage: [],
66
67
  // publicAssets: [],
67
68
  // serverAssets: [],
@@ -72,7 +73,7 @@ const SilgiCLIDefaults = {
72
73
  exclude: [],
73
74
  dirs: [],
74
75
  presets: [],
75
- virtualImports: ["#imports"]
76
+ virtualImports: ["#silgiImports"]
76
77
  },
77
78
  // virtual: {},
78
79
  // compressPublicAssets: false,
@@ -113,7 +114,7 @@ const SilgiCLIDefaults = {
113
114
  version: ""
114
115
  },
115
116
  extensions: [".js", ".jsx", ".mjs", ".ts", ".tsx", ".vue"],
116
- ignoreOptions: undefined
117
+ ignoreOptions: void 0
117
118
  };
118
119
 
119
120
  const fallbackCompatibilityDate = "2025-02-04";
@@ -206,14 +207,16 @@ async function resolveImportsOptions(options) {
206
207
  }
207
208
  options.imports.presets ??= [];
208
209
  options.imports.presets.push(...getSilgiImportsPreset());
209
- const h3Exports = await resolveModuleExportNames("h3", {
210
- url: import.meta.url
211
- });
212
- options.imports.presets ??= [];
213
- options.imports.presets.push({
214
- from: "h3",
215
- imports: h3Exports.filter((n) => !/^[A-Z]/.test(n) && n !== "use")
216
- });
210
+ if (options.preset === "h3") {
211
+ const h3Exports = await resolveModuleExportNames("h3", {
212
+ url: import.meta.url
213
+ });
214
+ options.imports.presets ??= [];
215
+ options.imports.presets.push({
216
+ from: "h3",
217
+ imports: h3Exports.filter((n) => !/^[A-Z]/.test(n) && n !== "use")
218
+ });
219
+ }
217
220
  options.imports.dirs ??= [];
218
221
  options.imports.dirs.push(
219
222
  ...options.scanDirs.map((dir) => join(dir, "utils/**/*"))
@@ -232,10 +235,15 @@ async function resolveImportsOptions(options) {
232
235
  function getSilgiImportsPreset() {
233
236
  return [
234
237
  // TODO: buraya bizim importlarimiz gelecek.
235
- // {
236
- // from: 'nitropack/runtime',
237
- // imports: ['useNitroApp'],
238
- // },
238
+ {
239
+ from: "silgi",
240
+ imports: [
241
+ "createShared",
242
+ "useSilgi",
243
+ "createService",
244
+ "createSchema"
245
+ ]
246
+ },
239
247
  // {
240
248
  // from: 'nitropack/runtime',
241
249
  // imports: ['useRuntimeConfig', 'useAppConfig'],
@@ -253,10 +261,10 @@ function getSilgiImportsPreset() {
253
261
  // 'cachedEventHandler',
254
262
  // ],
255
263
  // },
256
- // {
257
- // from: 'nitropack/runtime/internal/storage',
258
- // imports: ['useStorage'],
259
- // },
264
+ {
265
+ from: "silgi/core",
266
+ imports: ["useSilgiStorage"]
267
+ }
260
268
  // {
261
269
  // from: 'nitropack/runtime/internal/renderer',
262
270
  // imports: ['defineRenderHandler'],
@@ -302,21 +310,14 @@ async function resolvePathOptions(options) {
302
310
  if (options.preset === "npm-package") {
303
311
  const packageJsonPath = resolve(options.rootDir, "package.json");
304
312
  const packageJson = await readPackageJSON(packageJsonPath);
305
- if (packageJson.name === undefined) {
313
+ if (packageJson.name === void 0) {
306
314
  throw new Error("Package name is undefined");
307
315
  }
308
316
  options.alias ||= {};
309
317
  options.alias[packageJson.name] = join(options.rootDir, "src/module.ts");
310
318
  options.alias[`${packageJson.name}/runtime/`] = join(options.rootDir, "src/runtime/");
311
- options.alias = {
312
- ...options.alias,
313
- "silgi/runtime": join(runtimeDir),
314
- "#internal/silgi": join(runtimeDir),
315
- "silgi/runtime/*": join(runtimeDir, "*"),
316
- "#internal/silgi/*": join(runtimeDir, "*")
317
- };
318
319
  }
319
- if (options.typescript?.internalPaths) {
320
+ if (options.typescript?.internalPaths || options.stub) {
320
321
  options.alias = {
321
322
  ...options.alias,
322
323
  "silgi/runtime": join(runtimeDir),
@@ -338,6 +339,12 @@ async function resolvePathOptions(options) {
338
339
  "~~/": join(options.rootDir, "/"),
339
340
  "@@/": join(options.rootDir, "/")
340
341
  };
342
+ if (options.preset === "npm-package") {
343
+ options.alias = {
344
+ ...options.alias,
345
+ "#silgi/app/": join(options.build.dir, "/")
346
+ };
347
+ }
341
348
  if (options.alias && typeof options.alias === "object") {
342
349
  ((options.typescript.tsConfig ??= {}).compilerOptions ??= {}).paths ??= {};
343
350
  const paths = options.typescript.tsConfig.compilerOptions.paths;
@@ -402,8 +409,8 @@ async function resolvePathOptions(options) {
402
409
  options,
403
410
  options.rootDir
404
411
  );
405
- options.silgi.composablesDir = resolveSilgiPath(
406
- options.silgi.composablesDir || SilgiCLIDefaults.silgi.composablesDir,
412
+ options.silgi.vfsDir = resolveSilgiPath(
413
+ options.silgi.vfsDir || SilgiCLIDefaults.silgi.vfsDir,
407
414
  options,
408
415
  options.rootDir
409
416
  );
@@ -412,11 +419,6 @@ async function resolvePathOptions(options) {
412
419
  options,
413
420
  options.rootDir
414
421
  );
415
- options.silgi.servicesDir = resolveSilgiPath(
416
- options.silgi.servicesDir || SilgiCLIDefaults.silgi.servicesDir,
417
- options,
418
- options.rootDir
419
- );
420
422
  options.nodeModulesDirs.push(resolve(options.workspaceDir, "node_modules"));
421
423
  options.nodeModulesDirs.push(resolve(options.rootDir, "node_modules"));
422
424
  options.nodeModulesDirs.push(resolve(pkgDir, "node_modules"));
@@ -487,7 +489,7 @@ async function resolveStorageOptions(options) {
487
489
  base: fsMounts[p]
488
490
  };
489
491
  }
490
- if (options.dev && options.storage.data === undefined && options.devStorage.data === undefined) {
492
+ if (options.dev && options.storage.data === void 0 && options.devStorage.data === void 0) {
491
493
  options.devStorage.data = {
492
494
  driver: "fs",
493
495
  base: resolve(options.rootDir, ".data/kv")
@@ -522,10 +524,8 @@ async function loadOptions(configOverrides = {}, opts = {}) {
522
524
  return options;
523
525
  }
524
526
  async function _loadUserConfig(configOverrides = {}, opts = {}) {
525
- let presetOverride = configOverrides.preset || process.env.SILGI_PRESET;
526
- if (configOverrides.dev) {
527
- presetOverride = "silgi-dev";
528
- }
527
+ const presetOverride = configOverrides.preset || process.env.SILGI_PRESET;
528
+ if (configOverrides.dev) ;
529
529
  configOverrides = klona(configOverrides);
530
530
  globalThis.defineSilgiConfig = globalThis.defineSilgiConfig || ((c) => c);
531
531
  let compatibilityDate = configOverrides.compatibilityDate || opts.compatibilityDate || (process.env.SILGI_COMPATIBILITY_DATE || process.env.SERVER_COMPATIBILITY_DATE || process.env.COMPATIBILITY_DATE);
@@ -609,7 +609,7 @@ function renderAttr(key, value) {
609
609
  async function silgiGenerateType(silgi) {
610
610
  const rootDirWithSlash = withTrailingSlash(silgi.options.rootDir);
611
611
  const tsConfigPath = resolve(
612
- silgi.options.build.dir,
612
+ silgi.options.rootDir,
613
613
  silgi.options.typescript.tsconfigPath
614
614
  );
615
615
  const tsconfigDir = dirname(tsConfigPath);
@@ -659,9 +659,22 @@ async function silgiGenerateType(silgi) {
659
659
  allowImportingTsExtensions: true,
660
660
  ...silgi.options.typescript.customConditions ? { customConditions: ["silgiTypes"] } : {},
661
661
  paths: {
662
- "#imports": [
662
+ "#silgiImports": [
663
663
  relativeWithDot(tsconfigDir, join(silgi.options.build.typesDir, "silgi-imports"))
664
- ]
664
+ ],
665
+ ...silgi.scanModules.reduce((acc, m) => {
666
+ if (m.entryPath) {
667
+ acc[m.meta.name] = [relativeWithDot(tsconfigDir, m.entryPath)];
668
+ }
669
+ return acc;
670
+ }, {}),
671
+ ...silgi.scanModules.reduce((acc, m) => {
672
+ if (m.entryPath) {
673
+ const directory = getDirectory(m.entryPath);
674
+ acc[`${m.meta.name}/*`] = [`${relativeWithDot(tsconfigDir, directory)}/*`];
675
+ }
676
+ return acc;
677
+ }, {})
665
678
  // ...(silgi.options.typescript?.internalPaths
666
679
  // ? {
667
680
  // 'silgi/runtime': [
@@ -817,6 +830,9 @@ function normalizeResult(result) {
817
830
  }
818
831
  return result;
819
832
  }
833
+ function tryUseSilgi() {
834
+ return silgiCtx.tryUse();
835
+ }
820
836
 
821
837
  var HttpStatus = /* @__PURE__ */ ((HttpStatus2) => {
822
838
  HttpStatus2[HttpStatus2["CONTINUE"] = 100] = "CONTINUE";
@@ -1036,7 +1052,7 @@ ${this.stack}`;
1036
1052
  }
1037
1053
  return ErrorFactory.internalError(
1038
1054
  error instanceof Error ? error.message : String(error),
1039
- error instanceof Error ? error : undefined
1055
+ error instanceof Error ? error : void 0
1040
1056
  );
1041
1057
  }
1042
1058
  }
@@ -1064,8 +1080,8 @@ function parseURI(uri, uris) {
1064
1080
  const parts = path.split("/");
1065
1081
  const query = queryString ? Object.fromEntries(
1066
1082
  queryString.split("&").map((param) => param.split("="))
1067
- ) : undefined;
1068
- const method = query?.method ? query?.method.toLowerCase() : undefined;
1083
+ ) : void 0;
1084
+ const method = query?.method ? query?.method.toLowerCase() : void 0;
1069
1085
  const namespaceName = parts[0];
1070
1086
  const serviceName = parts[1];
1071
1087
  const methodName = method || parts[2];
@@ -1091,7 +1107,7 @@ function parseURI(uri, uris) {
1091
1107
  const parameters = parts.slice(paramStartIndex);
1092
1108
  const normalizedUri = method ? `${namespaceName}/${serviceName}/${method}/${actionName}${parameters.length ? `/${parameters.join("/")}` : ""}` : cleanUri;
1093
1109
  const template = uris[baseUri];
1094
- if (template === undefined) {
1110
+ if (template === void 0) {
1095
1111
  throw ErrorFactory.create({
1096
1112
  message: "No route found for URI",
1097
1113
  httpStatus: HttpStatus.NOT_FOUND,
@@ -1121,12 +1137,12 @@ function parseURI(uri, uris) {
1121
1137
  raw: normalizedUri,
1122
1138
  parts: [namespaceName, serviceName, methodName, actionName],
1123
1139
  routerParams: {},
1124
- query: method ? undefined : query,
1140
+ query: method ? void 0 : query,
1125
1141
  uri: baseUri
1126
1142
  };
1127
1143
  }
1128
1144
  const routeTemplate = typeof template === "string" ? template : template.pattern;
1129
- const validators = typeof template === "string" ? undefined : template.validators;
1145
+ const validators = typeof template === "string" ? void 0 : template.validators;
1130
1146
  const routerParams = {};
1131
1147
  const templateParts = routeTemplate.split("/").filter(Boolean);
1132
1148
  const paramValues = parameters;
@@ -1149,7 +1165,7 @@ function parseURI(uri, uris) {
1149
1165
  });
1150
1166
  }
1151
1167
  }
1152
- routerParams[paramName] = paramValue || undefined;
1168
+ routerParams[paramName] = paramValue || void 0;
1153
1169
  valueIndex++;
1154
1170
  } else if (part && part === paramValues[valueIndex]) {
1155
1171
  valueIndex++;
@@ -1163,7 +1179,7 @@ function parseURI(uri, uris) {
1163
1179
  raw: normalizedUri,
1164
1180
  parts: [namespaceName, serviceName, methodName, actionName],
1165
1181
  routerParams,
1166
- query: method ? undefined : query,
1182
+ query: method ? void 0 : query,
1167
1183
  uri: baseUri
1168
1184
  };
1169
1185
  }
@@ -1215,7 +1231,7 @@ async function createStorage(silgi) {
1215
1231
  }
1216
1232
  return storage;
1217
1233
  }
1218
- function useStorage(base = "/memory:cache") {
1234
+ function useSilgiStorage(base = "/memory:cache") {
1219
1235
  const silgi = useSilgi();
1220
1236
  return base ? prefixStorage(silgi.storage, base) : silgi.storage;
1221
1237
  }
@@ -1276,13 +1292,13 @@ async function createSilgi(config) {
1276
1292
  const silgi = {
1277
1293
  schemas: config.schemas,
1278
1294
  services: config.services ?? {},
1279
- shared: config.shared ?? undefined,
1295
+ shared: config.shared ?? void 0,
1280
1296
  uris: config.uris ?? {},
1281
1297
  modulesURIs: config.modulesURIs ?? {},
1282
1298
  scannedHandlers: /* @__PURE__ */ new Map(),
1283
1299
  plugins: config.plugins ?? [],
1284
- framework: config.framework ?? undefined,
1285
- storage: config.storage ?? undefined,
1300
+ framework: config.framework ?? void 0,
1301
+ storage: config.storage ?? void 0,
1286
1302
  options: config.options,
1287
1303
  hooks,
1288
1304
  callHook: hooks.callHook,
@@ -1316,7 +1332,7 @@ async function createSilgi(config) {
1316
1332
  silgi.storage = await createStorage(silgi);
1317
1333
  }
1318
1334
  silgi.shared.storage = (...data) => {
1319
- return useStorage(...data);
1335
+ return useSilgiStorage(...data);
1320
1336
  };
1321
1337
  if (silgiCtx.tryUse()) {
1322
1338
  silgiCtx.unset();
@@ -1400,7 +1416,7 @@ class SchemaParser {
1400
1416
  const data = [];
1401
1417
  for (const item of this.parseVariableDeclaration(ast)) {
1402
1418
  for (const declaration of item.declaration.declarations) {
1403
- if (declaration.init.callee?.name === find) {
1419
+ if (declaration.init?.callee?.name === find) {
1404
1420
  const options = {};
1405
1421
  if (declaration.init.arguments) {
1406
1422
  for (const argument of declaration.init.arguments) {
@@ -1484,10 +1500,10 @@ class SchemaParser {
1484
1500
  // if (!item?.declaration?.extends)
1485
1501
  // continue
1486
1502
  // for (const declaration of item?.declaration?.extends) {
1487
- // if (declaration.expression.name === 'SilgiModuleOptions') {
1503
+ // if (declaration.expression.name === 'ModuleOptions') {
1488
1504
  // data.export.push({
1489
1505
  // name: item.declaration.id.name,
1490
- // as: camelCase(`${data.name}SilgiModuleOptions`),
1506
+ // as: camelCase(`${data.name}ModuleOptions`),
1491
1507
  // type: true,
1492
1508
  // })
1493
1509
  // }
@@ -1560,7 +1576,7 @@ async function execute(uriString, input, event) {
1560
1576
  });
1561
1577
  if (!cached) {
1562
1578
  if (success && cacheData?.cachedKey && handler.storage) {
1563
- await useStorage(handler.storage.base).setItem(cacheData.cachedKey, result, handler.storage.options);
1579
+ await useSilgiStorage(handler.storage.base).setItem(cacheData.cachedKey, result, handler.storage.options);
1564
1580
  }
1565
1581
  }
1566
1582
  return result;
@@ -1589,7 +1605,7 @@ async function cacheExecute(input, operation, handler, event) {
1589
1605
  requestId: event?.requestId
1590
1606
  }) : null;
1591
1607
  if (cacheKey) {
1592
- const cachedResult = await useStorage(handler.storage.base).getItem(cacheKey);
1608
+ const cachedResult = await useSilgiStorage(handler.storage.base).getItem(cacheKey);
1593
1609
  if (cachedResult !== null) {
1594
1610
  return {
1595
1611
  success: true,
@@ -1647,4 +1663,16 @@ function createShared(shared) {
1647
1663
  return shared;
1648
1664
  }
1649
1665
 
1650
- export { ErrorCategory, ErrorFactory, ErrorSeverity, HttpStatus, SchemaParser, SilgiError, createSchema, createService, createShared, createSilgi, createSilgiFetch, createStorage, getEvent, isBaseError, loadOptions, mergeSchemas, mergeServices, mergeShared, parseURI, silgi, silgiGenerateType, useSilgi, useStorage };
1666
+ const silgiCLICtx = getContext("SilgiCLI");
1667
+ function useSilgiCLI() {
1668
+ const instance = silgiCLICtx.tryUse();
1669
+ if (!instance) {
1670
+ throw new Error("Silgi instance is unavailable!");
1671
+ }
1672
+ return instance;
1673
+ }
1674
+ function tryUseSilgiCLI() {
1675
+ return silgiCLICtx.tryUse();
1676
+ }
1677
+
1678
+ export { ErrorCategory, ErrorFactory, ErrorSeverity, HttpStatus, SchemaParser, SilgiError, createSchema, createService, createShared, createSilgi, createSilgiFetch, createStorage, getEvent, isBaseError, loadOptions, mergeSchemas, mergeServices, mergeShared, parseURI, silgi, silgiCLICtx, silgiCtx, silgiGenerateType, tryUseSilgi, tryUseSilgiCLI, useSilgi, useSilgiCLI, useSilgiStorage };
@@ -23,7 +23,7 @@ const module = {
23
23
  nitro.options.typescript.tsConfig.extends = "./silgi.tsconfig.json";
24
24
  nitro.options.typescript.tsConfig.include ??= [];
25
25
  nitro.options.typescript.tsConfig.exclude ??= [];
26
- if (silgiConfig.typescript.internalPaths) {
26
+ if (silgiConfig.typescript.internalPaths || silgiConfig.stub) {
27
27
  nitro.options.alias ||= {};
28
28
  nitro.options.alias = {
29
29
  ...nitro.options.alias,
@@ -35,8 +35,11 @@ const module = {
35
35
  nitro.options.typescript.tsConfig.compilerOptions ??= {};
36
36
  nitro.options.typescript.tsConfig.compilerOptions.paths ??= {};
37
37
  nitro.hooks.hook("types:extend", async () => {
38
- execSync("pnpm silgi prepare", { stdio: "inherit", cwd: nitro.options.rootDir, env: process.env });
38
+ const isStub = silgiConfig.stub ? "pnpm silgi prepare --stub" : "pnpm silgi prepare";
39
+ execSync(isStub, { stdio: "inherit", cwd: nitro.options.rootDir, env: process.env });
39
40
  });
41
+ nitro.options.exportConditions ??= [];
42
+ nitro.options.exportConditions.push(...silgiConfig.conditions);
40
43
  if (nitro.options.imports) {
41
44
  nitro.options.imports.dirs ??= [];
42
45
  nitro.options.imports.dirs.push(
@@ -1,22 +1,7 @@
1
1
  import { Buffer } from 'node:buffer';
2
- import { GraphQLSchema } from 'graphql';
3
- import { SilgiCLI, GraphQLJSON, SilgiPreset, SilgiPresetMeta } from 'silgi/types';
4
- import { M as ModuleOptions, a as ModuleDefinition, S as SilgiModule } from '../shared/silgi.B4uNbK2m.mjs';
5
- import 'defu';
6
- import '@graphql-tools/utils';
7
- import 'pkg-types';
8
- import '@standard-schema/spec';
9
- import 'consola';
10
- import 'hookable';
11
- import 'ignore';
12
- import 'silgi/presets';
13
- import 'unimport';
14
- import 'unstorage';
15
- import 'c12';
16
- import 'chokidar';
17
- import 'compatx';
18
- import 'unimport/unplugin';
19
- import 'std-env';
2
+ import * as consola from 'consola';
3
+ import { ConsolaOptions } from 'consola';
4
+ import { ModuleOptionsCustom, ModuleDefinition, SilgiModule, SilgiCLI, SilgiPreset, SilgiPresetMeta, SilgiTemplate, ResolvedSilgiTemplate } from 'silgi/types';
20
5
 
21
6
  /**
22
7
  * Resolve a module from a given root path using an algorithm patterned on
@@ -29,20 +14,18 @@ declare function tryResolveModule(id: string, url?: string | string[]): Promise<
29
14
  declare function writeFile(file: string, contents: Buffer | string, log?: boolean): Promise<void>;
30
15
  declare function isDirectory(path: string): Promise<boolean>;
31
16
 
32
- declare function exportGraphQLInterfaceType(silgi: SilgiCLI, schema: GraphQLSchema): void;
33
-
34
- declare function extractGraphQLSchemaToJSON(schema: GraphQLSchema): GraphQLJSON;
35
-
36
17
  declare function isNuxt(): boolean;
37
18
  declare function isNitro(): boolean;
38
19
  declare function isH3(): boolean;
39
20
 
21
+ declare function useLogger(tag?: string, options?: Partial<ConsolaOptions>): consola.ConsolaInstance;
22
+
40
23
  /**
41
24
  * Define a Silgi module, automatically merging defaults with user provided options, installing
42
25
  * any hooks that are provided, and calling an optional setup function for full control.
43
26
  */
44
- declare function defineSilgiModule<TOptions extends ModuleOptions>(definition: ModuleDefinition<TOptions, Partial<TOptions>, false> | SilgiModule<TOptions, Partial<TOptions>, false>): SilgiModule<TOptions, TOptions, false>;
45
- declare function defineSilgiModule<TOptions extends ModuleOptions>(): {
27
+ declare function defineSilgiModule<TOptions extends ModuleOptionsCustom>(definition: ModuleDefinition<TOptions, Partial<TOptions>, false> | SilgiModule<TOptions, Partial<TOptions>, false>): SilgiModule<TOptions, TOptions, false>;
28
+ declare function defineSilgiModule<TOptions extends ModuleOptionsCustom>(): {
46
29
  with: <TOptionsDefaults extends Partial<TOptions>>(definition: ModuleDefinition<TOptions, TOptionsDefaults, true> | SilgiModule<TOptions, TOptionsDefaults, true>) => SilgiModule<TOptions, TOptionsDefaults, true>;
47
30
  };
48
31
 
@@ -88,6 +71,25 @@ interface Resolver {
88
71
  declare function createResolver(base: string | URL): Resolver;
89
72
  declare function resolveSilgiModule(base: string, paths: string[]): Promise<string[]>;
90
73
 
74
+ /**
75
+ * Renders given template during build into the virtual file system (and optionally to disk in the project `buildDir`)
76
+ */
77
+ declare function addTemplate<T>(_template: SilgiTemplate<T> | string): ResolvedSilgiTemplate<T>;
78
+ /**
79
+ * Normalize a silgi template object
80
+ */
81
+ declare function normalizeTemplate<T>(template: SilgiTemplate<T> | string, buildDir?: string): ResolvedSilgiTemplate<T>;
82
+
91
83
  declare function relativeWithDot(from: string, to: string): string;
84
+ /** @since 3.9.0 */
85
+ declare function toArray<T>(value: T | T[]): T[];
86
+ /**
87
+ * Filter out items from an array in place. This function mutates the array.
88
+ * `predicate` get through the array from the end to the start for performance.
89
+ *
90
+ * This function should be faster than `Array.prototype.filter` on large arrays.
91
+ */
92
+ declare function filterInPlace<T>(array: T[], predicate: (item: T, index: number, arr: T[]) => unknown): T[];
93
+ declare const MODE_RE: RegExp;
92
94
 
93
- export { createResolver, defineSilgiModule, defineSilgiPreset, exportGraphQLInterfaceType, extractGraphQLSchemaToJSON, isDirectory, isH3, isNitro, isNuxt, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, tryResolveModule, writeFile };
95
+ export { MODE_RE, addTemplate, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, writeFile };