silgi 0.5.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 } from '../shared/silgi.DGmIWx95.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 } from '../shared/silgi.DGmIWx95.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
  }
@@ -1049,18 +1065,14 @@ function parseURI(uri, uris) {
1049
1065
  throw ErrorFactory.create({
1050
1066
  message: "URI cannot be empty",
1051
1067
  httpStatus: HttpStatus.BAD_REQUEST,
1052
- context: {
1053
- uri
1054
- }
1068
+ context: { uri }
1055
1069
  });
1056
1070
  }
1057
1071
  if (!uris) {
1058
1072
  throw ErrorFactory.create({
1059
1073
  message: "URIs configuration is not provided",
1060
1074
  httpStatus: HttpStatus.INTERNAL_SERVER_ERROR,
1061
- context: {
1062
- uri
1063
- }
1075
+ context: { uri }
1064
1076
  });
1065
1077
  }
1066
1078
  const cleanUri = uri.replace(/^\/*(srn\/)?/, "").replace(/\/*$/, "");
@@ -1068,31 +1080,21 @@ function parseURI(uri, uris) {
1068
1080
  const parts = path.split("/");
1069
1081
  const query = queryString ? Object.fromEntries(
1070
1082
  queryString.split("&").map((param) => param.split("="))
1071
- ) : undefined;
1072
- const method = query?.method ? query?.method.toLowerCase() : undefined;
1073
- if (method && parts.length < 3 || !method && parts.length < 4) {
1074
- throw ErrorFactory.create({
1075
- message: "Invalid URI format: Insufficient path segments",
1076
- httpStatus: HttpStatus.BAD_REQUEST,
1077
- context: {
1078
- uri,
1079
- cleanUri,
1080
- partsLength: parts.length,
1081
- method,
1082
- expectedMinLength: method ? 3 : 4
1083
- }
1084
- });
1085
- }
1083
+ ) : void 0;
1084
+ const method = query?.method ? query?.method.toLowerCase() : void 0;
1086
1085
  const namespaceName = parts[0];
1087
1086
  const serviceName = parts[1];
1088
1087
  const methodName = method || parts[2];
1089
1088
  const actionName = method ? parts[2] : parts[3];
1090
1089
  if (!namespaceName || !serviceName || !methodName || !actionName) {
1091
1090
  throw ErrorFactory.create({
1092
- message: "Invalid URI format: Missing required path segments",
1091
+ message: "Invalid URI format: Insufficient path segments",
1093
1092
  httpStatus: HttpStatus.BAD_REQUEST,
1094
1093
  context: {
1095
1094
  uri,
1095
+ cleanUri,
1096
+ partsLength: parts.length,
1097
+ method,
1096
1098
  namespaceName,
1097
1099
  serviceName,
1098
1100
  methodName,
@@ -1100,24 +1102,14 @@ function parseURI(uri, uris) {
1100
1102
  }
1101
1103
  });
1102
1104
  }
1103
- const hasParameters = parts.length > 4;
1104
1105
  const baseUri = `${namespaceName}/${serviceName}/${methodName}/${actionName}`;
1106
+ const paramStartIndex = method ? 3 : 4;
1107
+ const parameters = parts.slice(paramStartIndex);
1108
+ const normalizedUri = method ? `${namespaceName}/${serviceName}/${method}/${actionName}${parameters.length ? `/${parameters.join("/")}` : ""}` : cleanUri;
1105
1109
  const template = uris[baseUri];
1106
- if (template === "") {
1107
- if (hasParameters) {
1108
- throw ErrorFactory.create({
1109
- message: "Parameters are not allowed for this route",
1110
- httpStatus: HttpStatus.BAD_REQUEST,
1111
- context: {
1112
- uri,
1113
- baseUri,
1114
- extraParams: parts.slice(4)
1115
- }
1116
- });
1117
- }
1118
- } else if (!template) {
1110
+ if (template === void 0) {
1119
1111
  throw ErrorFactory.create({
1120
- message: "Route not found",
1112
+ message: "No route found for URI",
1121
1113
  httpStatus: HttpStatus.NOT_FOUND,
1122
1114
  context: {
1123
1115
  uri,
@@ -1125,59 +1117,69 @@ function parseURI(uri, uris) {
1125
1117
  }
1126
1118
  });
1127
1119
  }
1128
- const routeTemplate = typeof template === "string" ? template : template.pattern;
1129
- const validators = typeof template === "string" ? undefined : template.validators;
1130
- const routerParams = {};
1131
- if (routeTemplate === "") {
1132
- if (parts.length > 4) {
1120
+ if (template === "") {
1121
+ if (parameters.length > 0) {
1133
1122
  throw ErrorFactory.create({
1134
- message: "Parameters are not allowed for this route",
1123
+ message: "No parameters expected for this route",
1135
1124
  httpStatus: HttpStatus.BAD_REQUEST,
1136
1125
  context: {
1137
1126
  uri,
1138
1127
  baseUri,
1139
- extraParams: parts.slice(4)
1128
+ extraParams: parameters
1140
1129
  }
1141
1130
  });
1142
1131
  }
1143
- } else {
1144
- const templateParts = routeTemplate.split("/").filter(Boolean);
1145
- const paramValues = parts.slice(4);
1146
- let valueIndex = 0;
1147
- templateParts.forEach((part) => {
1148
- if (part.startsWith(":")) {
1149
- const paramName = part.substring(1);
1150
- const paramValue = paramValues[valueIndex];
1151
- if (validators?.[paramName] && paramValue) {
1152
- if (!validators[paramName](paramValue)) {
1153
- throw ErrorFactory.create({
1154
- message: `Invalid parameter value: ${paramName}`,
1155
- httpStatus: HttpStatus.UNPROCESSABLE_ENTITY,
1156
- context: {
1157
- uri,
1158
- paramName,
1159
- paramValue,
1160
- validatorName: paramName
1161
- }
1162
- });
1163
- }
1132
+ return {
1133
+ namespaceName,
1134
+ serviceName,
1135
+ methodName,
1136
+ actionName,
1137
+ raw: normalizedUri,
1138
+ parts: [namespaceName, serviceName, methodName, actionName],
1139
+ routerParams: {},
1140
+ query: method ? void 0 : query,
1141
+ uri: baseUri
1142
+ };
1143
+ }
1144
+ const routeTemplate = typeof template === "string" ? template : template.pattern;
1145
+ const validators = typeof template === "string" ? void 0 : template.validators;
1146
+ const routerParams = {};
1147
+ const templateParts = routeTemplate.split("/").filter(Boolean);
1148
+ const paramValues = parameters;
1149
+ let valueIndex = 0;
1150
+ templateParts.forEach((part) => {
1151
+ if (part.startsWith(":")) {
1152
+ const paramName = part.substring(1);
1153
+ const paramValue = paramValues[valueIndex];
1154
+ if (validators?.[paramName] && paramValue) {
1155
+ if (!validators[paramName](paramValue)) {
1156
+ throw ErrorFactory.create({
1157
+ message: "Invalid value for parameter",
1158
+ httpStatus: HttpStatus.UNPROCESSABLE_ENTITY,
1159
+ context: {
1160
+ uri,
1161
+ paramName,
1162
+ paramValue,
1163
+ validatorName: paramName
1164
+ }
1165
+ });
1164
1166
  }
1165
- routerParams[paramName] = paramValue || undefined;
1166
- valueIndex++;
1167
- } else if (part && part === paramValues[valueIndex]) {
1168
- valueIndex++;
1169
1167
  }
1170
- });
1171
- }
1168
+ routerParams[paramName] = paramValue || void 0;
1169
+ valueIndex++;
1170
+ } else if (part && part === paramValues[valueIndex]) {
1171
+ valueIndex++;
1172
+ }
1173
+ });
1172
1174
  return {
1173
1175
  namespaceName,
1174
1176
  serviceName,
1175
1177
  methodName,
1176
1178
  actionName,
1177
- raw: cleanUri,
1179
+ raw: normalizedUri,
1178
1180
  parts: [namespaceName, serviceName, methodName, actionName],
1179
1181
  routerParams,
1180
- query,
1182
+ query: method ? void 0 : query,
1181
1183
  uri: baseUri
1182
1184
  };
1183
1185
  }
@@ -1229,7 +1231,7 @@ async function createStorage(silgi) {
1229
1231
  }
1230
1232
  return storage;
1231
1233
  }
1232
- function useStorage(base = "/memory:cache") {
1234
+ function useSilgiStorage(base = "/memory:cache") {
1233
1235
  const silgi = useSilgi();
1234
1236
  return base ? prefixStorage(silgi.storage, base) : silgi.storage;
1235
1237
  }
@@ -1289,14 +1291,14 @@ async function createSilgi(config) {
1289
1291
  await applyDefaults(SilgiConfigSchema, config.options);
1290
1292
  const silgi = {
1291
1293
  schemas: config.schemas,
1292
- services: config.services,
1293
- shared: config.shared,
1294
- uris: config.uris,
1295
- modulesURIs: config.modulesURIs,
1294
+ services: config.services ?? {},
1295
+ shared: config.shared ?? void 0,
1296
+ uris: config.uris ?? {},
1297
+ modulesURIs: config.modulesURIs ?? {},
1296
1298
  scannedHandlers: /* @__PURE__ */ new Map(),
1297
1299
  plugins: config.plugins ?? [],
1298
- framework: config.framework,
1299
- storage: undefined,
1300
+ framework: config.framework ?? void 0,
1301
+ storage: config.storage ?? void 0,
1300
1302
  options: config.options,
1301
1303
  hooks,
1302
1304
  callHook: hooks.callHook,
@@ -1326,9 +1328,11 @@ async function createSilgi(config) {
1326
1328
  };
1327
1329
  await runSilgiPlugins(silgi);
1328
1330
  await scanAction(silgi);
1329
- silgi.storage = await createStorage(silgi);
1331
+ if (!silgi.storage) {
1332
+ silgi.storage = await createStorage(silgi);
1333
+ }
1330
1334
  silgi.shared.storage = (...data) => {
1331
- return useStorage(...data);
1335
+ return useSilgiStorage(...data);
1332
1336
  };
1333
1337
  if (silgiCtx.tryUse()) {
1334
1338
  silgiCtx.unset();
@@ -1412,7 +1416,7 @@ class SchemaParser {
1412
1416
  const data = [];
1413
1417
  for (const item of this.parseVariableDeclaration(ast)) {
1414
1418
  for (const declaration of item.declaration.declarations) {
1415
- if (declaration.init.callee?.name === find) {
1419
+ if (declaration.init?.callee?.name === find) {
1416
1420
  const options = {};
1417
1421
  if (declaration.init.arguments) {
1418
1422
  for (const argument of declaration.init.arguments) {
@@ -1496,10 +1500,10 @@ class SchemaParser {
1496
1500
  // if (!item?.declaration?.extends)
1497
1501
  // continue
1498
1502
  // for (const declaration of item?.declaration?.extends) {
1499
- // if (declaration.expression.name === 'SilgiModuleOptions') {
1503
+ // if (declaration.expression.name === 'ModuleOptions') {
1500
1504
  // data.export.push({
1501
1505
  // name: item.declaration.id.name,
1502
- // as: camelCase(`${data.name}SilgiModuleOptions`),
1506
+ // as: camelCase(`${data.name}ModuleOptions`),
1503
1507
  // type: true,
1504
1508
  // })
1505
1509
  // }
@@ -1572,7 +1576,7 @@ async function execute(uriString, input, event) {
1572
1576
  });
1573
1577
  if (!cached) {
1574
1578
  if (success && cacheData?.cachedKey && handler.storage) {
1575
- 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);
1576
1580
  }
1577
1581
  }
1578
1582
  return result;
@@ -1601,7 +1605,7 @@ async function cacheExecute(input, operation, handler, event) {
1601
1605
  requestId: event?.requestId
1602
1606
  }) : null;
1603
1607
  if (cacheKey) {
1604
- const cachedResult = await useStorage(handler.storage.base).getItem(cacheKey);
1608
+ const cachedResult = await useSilgiStorage(handler.storage.base).getItem(cacheKey);
1605
1609
  if (cachedResult !== null) {
1606
1610
  return {
1607
1611
  success: true,
@@ -1659,4 +1663,16 @@ function createShared(shared) {
1659
1663
  return shared;
1660
1664
  }
1661
1665
 
1662
- export { ErrorCategory, ErrorFactory, ErrorSeverity, HttpStatus, SchemaParser, SilgiError, createSchema, createService, createShared, createSilgi, createSilgiFetch, createStorage, getEvent, isBaseError, loadOptions, mergeSchemas, mergeServices, mergeShared, parseURI, silgi, silgiGenerateType, useSilgi };
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 };