silgi 0.43.3 → 0.43.5

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.
@@ -19,29 +19,11 @@ const DEFAULT_FUNCTION_EXPORT_NAMES = [
19
19
  "createMiddleware"
20
20
  ];
21
21
  const DEFAULT_INTERFACE_EXTENDS_NAMES = ["ExtendShared", "ExtendContext"];
22
- /**
23
- * Generate a unique identifier for an export based on its file path and name
24
- * Used to prevent naming collisions when registering exports
25
- *
26
- * @param filePath - Path to the file containing the export
27
- * @param exportName - Name of the exported entity
28
- * @returns A unique string identifier
29
- */
30
22
  function generateUniqueIdentifier(filePath, exportName) {
31
23
  const fileBaseName = basename(filePath);
32
24
  const uniqueString = `${fileBaseName}${exportName}`;
33
25
  return hash(uniqueString);
34
26
  }
35
- /**
36
- * Process extracted exports and categorize them for use in Silgi
37
- * Separates exports into runtime (scannable) and type-only (schema) groups
38
- *
39
- * @param exportedEntities - List of entities exported from a file
40
- * @param filePath - Path to the source file
41
- * @param functionExportCategories - Map of function names to categories
42
- * @param interfaceExportCategories - Map of interface extends names to categories
43
- * @returns Object containing runtime exports and type-only exports
44
- */
45
27
  function categorizeExports(exportedEntities, filePath, functionExportCategories = {
46
28
  createService: "service",
47
29
  createWebSocket: "websocket",
@@ -84,15 +66,6 @@ function categorizeExports(exportedEntities, filePath, functionExportCategories
84
66
  typeExports
85
67
  };
86
68
  }
87
- /**
88
- * Transform an import path based on package information
89
- * If a package name is provided, replace dist and preceding directories with the package name
90
- *
91
- * @param path - Original file path
92
- * @param packageName - Optional package name to use in import path
93
- * @param relativeTo - Directory to make the path relative to if no package name
94
- * @returns Transformed import path
95
- */
96
69
  function transformImportPath(path, packageName, relativeTo) {
97
70
  let importPath = path;
98
71
  if (packageName) {
@@ -104,15 +77,6 @@ function transformImportPath(path, packageName, relativeTo) {
104
77
  } else if (relativeTo) importPath = removeExtension(relativeWithDot(relativeTo, path));
105
78
  return importPath;
106
79
  }
107
- /**
108
- * Register discovered exports with the Silgi CLI via hooks
109
- * This enables Silgi to use these exports in code generation
110
- *
111
- * @param silgiInstance - The Silgi CLI instance
112
- * @param runtimeExports - Runtime exports to register
113
- * @param typeExports - Type-only exports to register
114
- * @param packageName - Optional package name for imports
115
- */
116
80
  function registerExportsWithHooks(silgiInstance, runtimeExports, typeExports, packageName) {
117
81
  silgiInstance.hook("before:scan.ts", (options) => {
118
82
  const ignored = Array.isArray(silgiInstance.options.watchOptions?.ignored) ? silgiInstance.options.watchOptions.ignored : [];
@@ -168,13 +132,6 @@ function registerExportsWithHooks(silgiInstance, runtimeExports, typeExports, pa
168
132
  }
169
133
  });
170
134
  }
171
- /**
172
- * Check for case sensitivity issues in directory paths
173
- * This helps users identify path issues on case-insensitive file systems
174
- *
175
- * @param directoryPath - The directory path to verify
176
- * @param rootDirectory - The root directory for relative path calculation
177
- */
178
135
  async function verifyDirectoryCaseSensitivity(directoryPath, rootDirectory) {
179
136
  const directoryName = basename(directoryPath);
180
137
  const parentDirectory = dirname(directoryPath);
@@ -191,13 +148,6 @@ async function verifyDirectoryCaseSensitivity(directoryPath, rootDirectory) {
191
148
  }
192
149
  } catch {}
193
150
  }
194
- /**
195
- * Parse a file and extract exported entities (interfaces and function exports)
196
- * @param absoluteFilePath - Absolute path to the file
197
- * @param functionExportNames - Function export names to look for
198
- * @param interfaceExtendsNames - Interface extends names to look for
199
- * @returns Array of ExportedEntity
200
- */
201
151
  async function extractExportEntitiesFromFile(absoluteFilePath, functionExportNames = DEFAULT_FUNCTION_EXPORT_NAMES, interfaceExtendsNames = DEFAULT_INTERFACE_EXTENDS_NAMES) {
202
152
  const exportEntities = [];
203
153
  const fileContent = await readFile(absoluteFilePath, "utf-8");
@@ -273,15 +223,6 @@ async function extractExportEntitiesFromFile(absoluteFilePath, functionExportNam
273
223
  }
274
224
  return exportEntities;
275
225
  }
276
- /**
277
- * Main function to scan files for exports and register them with the Silgi CLI
278
- * This enables automatic discovery and registration of services, schemas, etc.
279
- *
280
- * @param path - The path to scan for exports
281
- * @param packageName - Optional package name for import path transformation
282
- * @param silgiInstance - The Silgi CLI instance
283
- * @param scanOptions - Options for scanning
284
- */
285
226
  async function scanSilgiExports(path, packageName, silgiInstance = useSilgiCLI(), scanOptions = {}) {
286
227
  const processedFilePaths = new Set();
287
228
  const alreadyScannedPaths = [];
@@ -55,7 +55,8 @@ async function createSilgi(config) {
55
55
  const routeParts = path.split("/").filter(Boolean);
56
56
  if (routeParts.length > 0) {
57
57
  const prefix = `/${routeParts[0]}`;
58
- if (!silgi.routerPrefixs.includes(prefix)) silgi.routerPrefixs.push(`${type}:${prefix}`);
58
+ const prefixKey = `${type}:${prefix}`;
59
+ if (!silgi.routerPrefixs.includes(prefixKey)) silgi.routerPrefixs.push(prefixKey);
59
60
  }
60
61
  let routeWithParams = path;
61
62
  let pathParamNames = {};
@@ -11,7 +11,7 @@ import { createEventStream$1 as createEventStream } from "./utils/event-stream.m
11
11
  import { getEvent$1 as getEvent, getEventContext$1 as getEventContext } from "./utils/event.mjs";
12
12
  import { deepMergeObjects$1 as deepMergeObjects } from "./utils/merge.mjs";
13
13
  import { createMiddleware$1 as createMiddleware } from "./utils/middleware.mjs";
14
- import { createResolver$3 as createResolver, getUrlPrefix$1 as getUrlPrefix } from "./utils/resolver.mjs";
14
+ import { createResolver$2 as createResolver, getUrlPrefix$1 as getUrlPrefix } from "./utils/resolver.mjs";
15
15
  import { replaceRuntimeValues$1 as replaceRuntimeValues } from "./utils/runtime.mjs";
16
16
  import { createSchema$1 as createSchema } from "./utils/schema.mjs";
17
17
  import { createService$1 as createService, createWebSocket$1 as createWebSocket, defineServiceSetup$1 as defineServiceSetup } from "./utils/service.mjs";
@@ -7,7 +7,7 @@ import { createStorage, useSilgiStorage } from "./utils/storage.mjs";
7
7
  import { createSilgi } from "./createSilgi.mjs";
8
8
  import { SilgiHttpEvent } from "./event.mjs";
9
9
  import { handleResponse, kHandled, kNotFound } from "./response.mjs";
10
- import { createResolver$1 as createResolver, getUrlPrefix } from "./utils/resolver.mjs";
10
+ import { createResolver, getUrlPrefix } from "./utils/resolver.mjs";
11
11
  import { getWebsocket, handler, middleware, silgiFetch } from "./silgi.mjs";
12
12
  import { storageMount } from "./storage.mjs";
13
13
  import { createEventStream } from "./utils/event-stream.mjs";
@@ -5,6 +5,7 @@ import { parseRequestInput } from "./utils/internal/req.mjs";
5
5
  import { getQuery, getRouterParams } from "./utils/request.mjs";
6
6
  import { getUrlPrefix } from "./utils/resolver.mjs";
7
7
  import { silgiFetch } from "./silgi.mjs";
8
+ import consola from "consola";
8
9
 
9
10
  //#region src/core/orchestrate.ts
10
11
  async function orchestrate(route, event) {
@@ -63,6 +64,7 @@ async function orchestrate(route, event) {
63
64
  if (route.service?.storage && cacheData?.cachedKey) await useSilgiStorage(route.service.storage.base).setItem(cacheData.cachedKey, result, route.service.storage.options);
64
65
  return result;
65
66
  } catch (err) {
67
+ consola.error("Error in orchestrate:", err);
66
68
  await silgiCtx.callHook("fetch:error", {
67
69
  event,
68
70
  input: inputData,
@@ -4,4 +4,4 @@ import { Resolvers, SilgiURL } from "silgi/types";
4
4
  declare function createResolver(resolver: Resolvers): Resolvers;
5
5
  declare function getUrlPrefix(path: string, method?: string): SilgiURL;
6
6
  //#endregion
7
- export { createResolver as createResolver$3, getUrlPrefix as getUrlPrefix$1 };
7
+ export { createResolver as createResolver$2, getUrlPrefix as getUrlPrefix$1 };
@@ -26,4 +26,4 @@ function getUrlPrefix(path, method) {
26
26
  }
27
27
 
28
28
  //#endregion
29
- export { createResolver as createResolver$1, getUrlPrefix };
29
+ export { createResolver, getUrlPrefix };
package/dist/index.d.mts CHANGED
@@ -11,7 +11,7 @@ import { createEventStream$1 as createEventStream } from "./core/utils/event-str
11
11
  import { getEvent$1 as getEvent, getEventContext$1 as getEventContext } from "./core/utils/event.mjs";
12
12
  import { deepMergeObjects$1 as deepMergeObjects } from "./core/utils/merge.mjs";
13
13
  import { createMiddleware$1 as createMiddleware } from "./core/utils/middleware.mjs";
14
- import { createResolver$3 as createResolver, getUrlPrefix$1 as getUrlPrefix } from "./core/utils/resolver.mjs";
14
+ import { createResolver$2 as createResolver, getUrlPrefix$1 as getUrlPrefix } from "./core/utils/resolver.mjs";
15
15
  import { replaceRuntimeValues$1 as replaceRuntimeValues } from "./core/utils/runtime.mjs";
16
16
  import { createSchema$1 as createSchema } from "./core/utils/schema.mjs";
17
17
  import { createService$1 as createService, createWebSocket$1 as createWebSocket, defineServiceSetup$1 as defineServiceSetup } from "./core/utils/service.mjs";
package/dist/index.mjs CHANGED
@@ -7,7 +7,7 @@ import { createStorage, useSilgiStorage } from "./core/utils/storage.mjs";
7
7
  import { createSilgi } from "./core/createSilgi.mjs";
8
8
  import { SilgiHttpEvent } from "./core/event.mjs";
9
9
  import { handleResponse, kHandled, kNotFound } from "./core/response.mjs";
10
- import { createResolver$1 as createResolver, getUrlPrefix } from "./core/utils/resolver.mjs";
10
+ import { createResolver, getUrlPrefix } from "./core/utils/resolver.mjs";
11
11
  import { getWebsocket, handler, middleware, silgiFetch } from "./core/silgi.mjs";
12
12
  import { storageMount } from "./core/storage.mjs";
13
13
  import { createEventStream } from "./core/utils/event-stream.mjs";
@@ -15,7 +15,7 @@ import { JsonPatch, MigrationData, MigrationInfo, MigrationOptions, MigrationRes
15
15
  import { defineSilgiModule$1 as defineSilgiModule } from "./module.mjs";
16
16
  import { prettyPath$1 as prettyPath, resolveSilgiPath$1 as resolveSilgiPath } from "./path.mjs";
17
17
  import { defineSilgiPreset$1 as defineSilgiPreset } from "./preset.mjs";
18
- import { createResolver$2 as createResolver, resolveAlias$1 as resolveAlias, resolvePath$1 as resolvePath, resolveSilgiModule$1 as resolveSilgiModule } from "./resolve.mjs";
18
+ import { createResolver$3 as createResolver, resolveAlias$1 as resolveAlias, resolvePath$1 as resolvePath, resolveSilgiModule$1 as resolveSilgiModule } from "./resolve.mjs";
19
19
  import { addTemplate$1 as addTemplate, normalizeTemplate$1 as normalizeTemplate } from "./template.mjs";
20
20
  import { getIpAddress$1 as getIpAddress, useRequest$1 as useRequest } from "./useRequest.mjs";
21
21
  import { MODE_RE$1 as MODE_RE, baseHeaderBannerComment$1 as baseHeaderBannerComment, filterInPlace$1 as filterInPlace, getServicePath$1 as getServicePath, hasInstalledModule$2 as hasInstalledModule, hasSilgiModule$1 as hasSilgiModule, isPresents$1 as isPresents, isRuntimePresents$1 as isRuntimePresents, processFilePath$1 as processFilePath, relativeWithDot$1 as relativeWithDot, removeExtension$1 as removeExtension, toArray$1 as toArray } from "./utils.mjs";
@@ -16,7 +16,7 @@ import { useLogger } from "./logger.mjs";
16
16
  import { MigrationStatus, generateMigration, getMigration, listMigrations, migrationDown, migrationUp } from "./migration.mjs";
17
17
  import { defineSilgiModule } from "./module.mjs";
18
18
  import { defineSilgiPreset } from "./preset.mjs";
19
- import { createResolver, resolveAlias, resolvePath, resolveSilgiModule } from "./resolve.mjs";
19
+ import { createResolver$1 as createResolver, resolveAlias, resolvePath, resolveSilgiModule } from "./resolve.mjs";
20
20
  import { addTemplate, normalizeTemplate } from "./template.mjs";
21
21
  import { getIpAddress, useRequest } from "./useRequest.mjs";
22
22
 
@@ -34,4 +34,4 @@ interface Resolver {
34
34
  declare function createResolver(base: string | URL): Resolver;
35
35
  declare function resolveSilgiModule(base: string, paths: string[]): Promise<string[]>;
36
36
  //#endregion
37
- export { createResolver as createResolver$2, resolveAlias as resolveAlias$1, resolvePath as resolvePath$1, resolveSilgiModule as resolveSilgiModule$1 };
37
+ export { createResolver as createResolver$3, resolveAlias as resolveAlias$1, resolvePath as resolvePath$1, resolveSilgiModule as resolveSilgiModule$1 };
@@ -79,4 +79,4 @@ async function resolveSilgiModule(base, paths) {
79
79
  }
80
80
 
81
81
  //#endregion
82
- export { createResolver, resolveAlias$1 as resolveAlias, resolvePath$1 as resolvePath, resolveSilgiModule };
82
+ export { createResolver as createResolver$1, resolveAlias$1 as resolveAlias, resolvePath$1 as resolvePath, resolveSilgiModule };
package/dist/package.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  //#region package.json
2
2
  var name = "silgi";
3
3
  var type = "module";
4
- var version = "0.43.3";
4
+ var version = "0.43.5";
5
5
  var private$1 = false;
6
6
  var packageManager = "pnpm@10.11.0";
7
7
  var sideEffects = false;
@@ -1,3 +1,4 @@
1
+ import consola from "consola";
1
2
  import { silgiFetch, useSilgi } from "silgi";
2
3
  import { defineEventHandler, toWebRequest } from "h3";
3
4
 
@@ -14,8 +15,13 @@ async function addNitroApp(silgiContext = useSilgi()) {
14
15
  path = parts[1] ?? "";
15
16
  if (type === "HTTP") nitro.router.use(`${path}/**`, defineEventHandler(async (event) => {
16
17
  const evet = toWebRequest(event);
17
- const resolvedRoute = await silgiFetch(evet);
18
- return resolvedRoute;
18
+ try {
19
+ const resolvedRoute = await silgiFetch(evet);
20
+ return resolvedRoute;
21
+ } catch (error) {
22
+ consola.error("Error in Nitro route:", error);
23
+ throw error;
24
+ }
19
25
  }));
20
26
  }
21
27
  const webhookServices = Object.entries(silgiContext.services).filter(([key]) => key.startsWith("websocket:")).map(([, value]) => value);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.43.3",
4
+ "version": "0.43.5",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {