nvent 1.0.0-alpha.7 → 1.0.0-alpha.9

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 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nvent",
3
- "version": "1.0.0-alpha.7",
3
+ "version": "1.0.0-alpha.9",
4
4
  "configKey": "nvent",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
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';
@@ -1133,6 +1133,26 @@ function mapPubSubAdapter(a) {
1133
1133
  return { name: "local" };
1134
1134
  }
1135
1135
 
1136
+ function resolveExtendedFunctionAbsPath(absPath) {
1137
+ if (existsSync(absPath)) {
1138
+ return { absPath };
1139
+ }
1140
+ if (!absPath.endsWith(".ts")) {
1141
+ return { absPath };
1142
+ }
1143
+ const base = absPath.slice(0, -3);
1144
+ for (const ext of [".js", ".mjs", ".cjs"]) {
1145
+ const candidate = `${base}${ext}`;
1146
+ if (existsSync(candidate)) {
1147
+ return {
1148
+ absPath: candidate,
1149
+ rewrittenFrom: absPath
1150
+ };
1151
+ }
1152
+ }
1153
+ return { absPath };
1154
+ }
1155
+
1136
1156
  function filePathToFunctionId(relPath) {
1137
1157
  const noExt = relPath.replace(/\.[a-zA-Z]+$/, "");
1138
1158
  return noExt.split(/[\\/]/).join("::");
@@ -1368,7 +1388,56 @@ const module$1 = defineNuxtModule({
1368
1388
  serverDir: l.config?.serverDir ?? join(l.config.rootDir, "server"),
1369
1389
  prefix: resolveLayerPrefix(l, i === 0)
1370
1390
  }));
1371
- let lastScanned = await scanFunctions({ layerInfos, functionsDir });
1391
+ async function scanFunctionsWithExtensions() {
1392
+ const scanned = await scanFunctions({ layerInfos, functionsDir });
1393
+ const payload = {
1394
+ functions: [],
1395
+ pythonFunctions: [],
1396
+ rootDir: nuxt.options.rootDir,
1397
+ layerInfos,
1398
+ functionsDir
1399
+ };
1400
+ await nuxt.callHook("nvent:functions:extend", payload);
1401
+ const normalizePath = (path) => isAbsolute(path) ? path : join(nuxt.options.rootDir, path);
1402
+ const seenTs = new Set(scanned.functions.map((f) => f.id));
1403
+ for (const fn of payload.functions) {
1404
+ if (!fn?.id || !fn?.absPath) continue;
1405
+ if (seenTs.has(fn.id)) {
1406
+ console.warn(`[nvent] skipping extended TS function '${fn.id}' (duplicate id)`);
1407
+ continue;
1408
+ }
1409
+ const requestedPath = normalizePath(fn.absPath);
1410
+ const resolvedPath = resolveExtendedFunctionAbsPath(requestedPath);
1411
+ if (resolvedPath.rewrittenFrom) {
1412
+ console.warn(`[nvent] extended TS function path rewritten for '${fn.id}': ${resolvedPath.rewrittenFrom} -> ${resolvedPath.absPath}`);
1413
+ }
1414
+ scanned.functions.push({
1415
+ id: fn.id,
1416
+ absPath: resolvedPath.absPath,
1417
+ relativePath: basename(resolvedPath.absPath),
1418
+ description: fn.description
1419
+ });
1420
+ seenTs.add(fn.id);
1421
+ }
1422
+ const seenPy = new Set(scanned.pythonFunctions.map((f) => f.id));
1423
+ for (const fn of payload.pythonFunctions) {
1424
+ if (!fn?.id || !fn?.absPath) continue;
1425
+ if (seenPy.has(fn.id)) {
1426
+ console.warn(`[nvent] skipping extended Python function '${fn.id}' (duplicate id)`);
1427
+ continue;
1428
+ }
1429
+ const absPath = normalizePath(fn.absPath);
1430
+ scanned.pythonFunctions.push({
1431
+ id: fn.id,
1432
+ absPath,
1433
+ relativePath: basename(absPath),
1434
+ standalone: !!fn.standalone
1435
+ });
1436
+ seenPy.add(fn.id);
1437
+ }
1438
+ return scanned;
1439
+ }
1440
+ let lastScanned = await scanFunctionsWithExtensions();
1372
1441
  let pythonPathRewrite;
1373
1442
  if (!nuxt.options.dev && !skipPython && lastScanned.pythonFunctions.length > 0) {
1374
1443
  pythonPathRewrite = /* @__PURE__ */ new Map();
@@ -1380,6 +1449,10 @@ const module$1 = defineNuxtModule({
1380
1449
  break;
1381
1450
  }
1382
1451
  }
1452
+ if (!pythonPathRewrite.has(fn.absPath)) {
1453
+ const rel = `${fn.id.replace(/::/g, "/")}.py`.replace(/[^a-zA-Z0-9/_\-.]/g, "_");
1454
+ pythonPathRewrite.set(fn.absPath, rel);
1455
+ }
1383
1456
  }
1384
1457
  }
1385
1458
  addTemplate({
@@ -1490,7 +1563,7 @@ const module$1 = defineNuxtModule({
1490
1563
  (l) => join(l.serverDir ?? join(l.rootDir, "server"), functionsDir)
1491
1564
  );
1492
1565
  const refresh = debounce(async (changedPath) => {
1493
- lastScanned = await scanFunctions({ layerInfos, functionsDir });
1566
+ lastScanned = await scanFunctionsWithExtensions();
1494
1567
  await updateTemplates({ filter: (t) => t.filename === III_REGISTRY_TEMPLATE });
1495
1568
  console.log(`[nvent] registry refreshed${changedPath ? ` (${changedPath})` : ""}`);
1496
1569
  if (!skipPython && changedPath?.endsWith(".py")) {
@@ -1526,15 +1599,18 @@ const module$1 = defineNuxtModule({
1526
1599
  copyFileSync(PYTHON_RUNTIME_SRC, join(workersDir, "_runtime.py"));
1527
1600
  copyFileSync(PYTHON_NVENT_HELPER_SRC, join(workersDir, "nvent.py"));
1528
1601
  for (const fn of lastScanned.pythonFunctions) {
1602
+ let relativeDest;
1529
1603
  for (const layer of layerInfos) {
1530
1604
  const fnDir = join(layer.serverDir, functionsDir);
1531
1605
  if (fn.absPath.startsWith(fnDir)) {
1532
- const dest = join(outputNventDir, "functions", relative(fnDir, fn.absPath));
1533
- mkdirSync(join(dest, ".."), { recursive: true });
1534
- copyFileSync(fn.absPath, dest);
1606
+ relativeDest = relative(fnDir, fn.absPath);
1535
1607
  break;
1536
1608
  }
1537
1609
  }
1610
+ relativeDest ||= pythonPathRewrite?.get(fn.absPath) ?? `${fn.id.replace(/::/g, "/")}.py`;
1611
+ const dest = join(outputNventDir, "functions", relativeDest);
1612
+ mkdirSync(join(dest, ".."), { recursive: true });
1613
+ copyFileSync(fn.absPath, dest);
1538
1614
  }
1539
1615
  console.log("[nvent] Python worker files copied to .output/nvent/");
1540
1616
  });
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'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nvent",
3
- "version": "1.0.0-alpha.7",
3
+ "version": "1.0.0-alpha.9",
4
4
  "description": "Event-driven workflows for Nuxt",
5
5
  "repository": "nhealthorg/nvent",
6
6
  "license": "MIT",