nvent 1.0.0-alpha.7 → 1.0.0-alpha.8
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/module.d.mts +49 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +58 -6
- package/dist/types.d.mts +2 -0
- package/package.json +1 -1
package/dist/module.d.mts
CHANGED
|
@@ -338,6 +338,55 @@ interface NventIiiOptions {
|
|
|
338
338
|
};
|
|
339
339
|
}
|
|
340
340
|
|
|
341
|
+
interface LayerInfo {
|
|
342
|
+
rootDir: string;
|
|
343
|
+
serverDir: string;
|
|
344
|
+
/**
|
|
345
|
+
* Prefix prepended to every function ID discovered in this layer.
|
|
346
|
+
* Empty string (or undefined) means no prefix — root project convention.
|
|
347
|
+
* e.g. 'auth' → 'login.ts' becomes 'auth::login'
|
|
348
|
+
*/
|
|
349
|
+
prefix?: string;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
interface NventExtendedFunction {
|
|
353
|
+
/** iii function ID (e.g. `fhir::terminology::lookup`) */
|
|
354
|
+
id: string;
|
|
355
|
+
/** Absolute file path, or root-relative path, to a TS/JS function module */
|
|
356
|
+
absPath: string;
|
|
357
|
+
/** Optional human-readable description */
|
|
358
|
+
description?: string;
|
|
359
|
+
}
|
|
360
|
+
interface NventExtendedPythonFunction {
|
|
361
|
+
/** iii function ID (e.g. `fhir::terminology::expand`) */
|
|
362
|
+
id: string;
|
|
363
|
+
/** Absolute file path, or root-relative path, to a .py file */
|
|
364
|
+
absPath: string;
|
|
365
|
+
/** When true, start this function in a dedicated worker process */
|
|
366
|
+
standalone?: boolean;
|
|
367
|
+
}
|
|
368
|
+
interface NventExtendFunctionsHookPayload {
|
|
369
|
+
/** Push extra TS/JS function files to register */
|
|
370
|
+
functions: NventExtendedFunction[];
|
|
371
|
+
/** Push extra Python function files to register */
|
|
372
|
+
pythonFunctions: NventExtendedPythonFunction[];
|
|
373
|
+
/** Nuxt project root */
|
|
374
|
+
rootDir: string;
|
|
375
|
+
/** Layer scan context (same as nvent internal scan) */
|
|
376
|
+
layerInfos: LayerInfo[];
|
|
377
|
+
/** Configured functions dir relative to each layer's server dir */
|
|
378
|
+
functionsDir: string;
|
|
379
|
+
}
|
|
380
|
+
declare module '@nuxt/schema' {
|
|
381
|
+
interface NuxtHooks {
|
|
382
|
+
/**
|
|
383
|
+
* Extend nvent function discovery with additional TS/JS or Python function files.
|
|
384
|
+
* Useful for Nuxt modules that ship their own iii handlers.
|
|
385
|
+
*/
|
|
386
|
+
'nvent:functions:extend': (payload: NventExtendFunctionsHookPayload) => void | Promise<void>;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
341
389
|
declare const _default: _nuxt_schema.NuxtModule<NventIiiOptions, NventIiiOptions, false>;
|
|
342
390
|
|
|
343
391
|
export { _default as default };
|
|
392
|
+
export type { NventExtendFunctionsHookPayload, NventExtendedFunction, NventExtendedPythonFunction };
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { join, dirname, basename, relative, parse } from 'node:path';
|
|
1
|
+
import { join, dirname, basename, relative, parse, isAbsolute } from 'node:path';
|
|
2
2
|
import { defineNuxtModule, createResolver, extendViteConfig, hasNuxtModule, addTemplate, addServerPlugin, addServerHandler, addServerImports, addImports, addPlugin, updateTemplates } from '@nuxt/kit';
|
|
3
3
|
import { existsSync, mkdirSync, chmodSync, createWriteStream, unlinkSync, writeFileSync, readFileSync, copyFileSync } from 'node:fs';
|
|
4
4
|
import { randomUUID } from 'node:crypto';
|
|
@@ -1368,7 +1368,52 @@ const module$1 = defineNuxtModule({
|
|
|
1368
1368
|
serverDir: l.config?.serverDir ?? join(l.config.rootDir, "server"),
|
|
1369
1369
|
prefix: resolveLayerPrefix(l, i === 0)
|
|
1370
1370
|
}));
|
|
1371
|
-
|
|
1371
|
+
async function scanFunctionsWithExtensions() {
|
|
1372
|
+
const scanned = await scanFunctions({ layerInfos, functionsDir });
|
|
1373
|
+
const payload = {
|
|
1374
|
+
functions: [],
|
|
1375
|
+
pythonFunctions: [],
|
|
1376
|
+
rootDir: nuxt.options.rootDir,
|
|
1377
|
+
layerInfos,
|
|
1378
|
+
functionsDir
|
|
1379
|
+
};
|
|
1380
|
+
await nuxt.callHook("nvent:functions:extend", payload);
|
|
1381
|
+
const normalizePath = (path) => isAbsolute(path) ? path : join(nuxt.options.rootDir, path);
|
|
1382
|
+
const seenTs = new Set(scanned.functions.map((f) => f.id));
|
|
1383
|
+
for (const fn of payload.functions) {
|
|
1384
|
+
if (!fn?.id || !fn?.absPath) continue;
|
|
1385
|
+
if (seenTs.has(fn.id)) {
|
|
1386
|
+
console.warn(`[nvent] skipping extended TS function '${fn.id}' (duplicate id)`);
|
|
1387
|
+
continue;
|
|
1388
|
+
}
|
|
1389
|
+
const absPath = normalizePath(fn.absPath);
|
|
1390
|
+
scanned.functions.push({
|
|
1391
|
+
id: fn.id,
|
|
1392
|
+
absPath,
|
|
1393
|
+
relativePath: basename(absPath),
|
|
1394
|
+
description: fn.description
|
|
1395
|
+
});
|
|
1396
|
+
seenTs.add(fn.id);
|
|
1397
|
+
}
|
|
1398
|
+
const seenPy = new Set(scanned.pythonFunctions.map((f) => f.id));
|
|
1399
|
+
for (const fn of payload.pythonFunctions) {
|
|
1400
|
+
if (!fn?.id || !fn?.absPath) continue;
|
|
1401
|
+
if (seenPy.has(fn.id)) {
|
|
1402
|
+
console.warn(`[nvent] skipping extended Python function '${fn.id}' (duplicate id)`);
|
|
1403
|
+
continue;
|
|
1404
|
+
}
|
|
1405
|
+
const absPath = normalizePath(fn.absPath);
|
|
1406
|
+
scanned.pythonFunctions.push({
|
|
1407
|
+
id: fn.id,
|
|
1408
|
+
absPath,
|
|
1409
|
+
relativePath: basename(absPath),
|
|
1410
|
+
standalone: !!fn.standalone
|
|
1411
|
+
});
|
|
1412
|
+
seenPy.add(fn.id);
|
|
1413
|
+
}
|
|
1414
|
+
return scanned;
|
|
1415
|
+
}
|
|
1416
|
+
let lastScanned = await scanFunctionsWithExtensions();
|
|
1372
1417
|
let pythonPathRewrite;
|
|
1373
1418
|
if (!nuxt.options.dev && !skipPython && lastScanned.pythonFunctions.length > 0) {
|
|
1374
1419
|
pythonPathRewrite = /* @__PURE__ */ new Map();
|
|
@@ -1380,6 +1425,10 @@ const module$1 = defineNuxtModule({
|
|
|
1380
1425
|
break;
|
|
1381
1426
|
}
|
|
1382
1427
|
}
|
|
1428
|
+
if (!pythonPathRewrite.has(fn.absPath)) {
|
|
1429
|
+
const rel = `${fn.id.replace(/::/g, "/")}.py`.replace(/[^a-zA-Z0-9/_\-.]/g, "_");
|
|
1430
|
+
pythonPathRewrite.set(fn.absPath, rel);
|
|
1431
|
+
}
|
|
1383
1432
|
}
|
|
1384
1433
|
}
|
|
1385
1434
|
addTemplate({
|
|
@@ -1490,7 +1539,7 @@ const module$1 = defineNuxtModule({
|
|
|
1490
1539
|
(l) => join(l.serverDir ?? join(l.rootDir, "server"), functionsDir)
|
|
1491
1540
|
);
|
|
1492
1541
|
const refresh = debounce(async (changedPath) => {
|
|
1493
|
-
lastScanned = await
|
|
1542
|
+
lastScanned = await scanFunctionsWithExtensions();
|
|
1494
1543
|
await updateTemplates({ filter: (t) => t.filename === III_REGISTRY_TEMPLATE });
|
|
1495
1544
|
console.log(`[nvent] registry refreshed${changedPath ? ` (${changedPath})` : ""}`);
|
|
1496
1545
|
if (!skipPython && changedPath?.endsWith(".py")) {
|
|
@@ -1526,15 +1575,18 @@ const module$1 = defineNuxtModule({
|
|
|
1526
1575
|
copyFileSync(PYTHON_RUNTIME_SRC, join(workersDir, "_runtime.py"));
|
|
1527
1576
|
copyFileSync(PYTHON_NVENT_HELPER_SRC, join(workersDir, "nvent.py"));
|
|
1528
1577
|
for (const fn of lastScanned.pythonFunctions) {
|
|
1578
|
+
let relativeDest;
|
|
1529
1579
|
for (const layer of layerInfos) {
|
|
1530
1580
|
const fnDir = join(layer.serverDir, functionsDir);
|
|
1531
1581
|
if (fn.absPath.startsWith(fnDir)) {
|
|
1532
|
-
|
|
1533
|
-
mkdirSync(join(dest, ".."), { recursive: true });
|
|
1534
|
-
copyFileSync(fn.absPath, dest);
|
|
1582
|
+
relativeDest = relative(fnDir, fn.absPath);
|
|
1535
1583
|
break;
|
|
1536
1584
|
}
|
|
1537
1585
|
}
|
|
1586
|
+
relativeDest ||= pythonPathRewrite?.get(fn.absPath) ?? `${fn.id.replace(/::/g, "/")}.py`;
|
|
1587
|
+
const dest = join(outputNventDir, "functions", relativeDest);
|
|
1588
|
+
mkdirSync(join(dest, ".."), { recursive: true });
|
|
1589
|
+
copyFileSync(fn.absPath, dest);
|
|
1538
1590
|
}
|
|
1539
1591
|
console.log("[nvent] Python worker files copied to .output/nvent/");
|
|
1540
1592
|
});
|
package/dist/types.d.mts
CHANGED
|
@@ -5,3 +5,5 @@ import type { default as Module } from './module.mjs'
|
|
|
5
5
|
export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
|
|
6
6
|
|
|
7
7
|
export { default } from './module.mjs'
|
|
8
|
+
|
|
9
|
+
export { type NventExtendFunctionsHookPayload, type NventExtendedFunction, type NventExtendedPythonFunction } from './module.mjs'
|