silgi 0.43.3 → 0.43.4
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/scan/scanExportFile.mjs +0 -59
- package/dist/core/createSilgi.mjs +2 -1
- package/dist/core/index.mjs +1 -1
- package/dist/core/utils/resolver.mjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/kit/index.mjs +1 -1
- package/dist/kit/resolve.mjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/runtime/internal/nitro.mjs +8 -2
- package/package.json +1 -1
|
@@ -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
|
-
|
|
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 = {};
|
package/dist/core/index.mjs
CHANGED
|
@@ -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
|
|
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";
|
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
|
|
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";
|
package/dist/kit/index.mjs
CHANGED
|
@@ -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
|
|
package/dist/kit/resolve.mjs
CHANGED
|
@@ -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,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
|
-
|
|
18
|
-
|
|
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);
|