@bonsae/nrg 0.22.2 → 0.24.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bonsae/nrg",
3
- "version": "0.22.2",
3
+ "version": "0.24.0",
4
4
  "description": "NRG framework — build Node-RED nodes with Vue 3, TypeScript, and JSON Schema",
5
5
  "author": "Allan Oricil <allanoricil@duck.com>",
6
6
  "license": "MIT",
@@ -119,7 +119,7 @@
119
119
  }
120
120
  },
121
121
  "dependencies": {
122
- "@bonsae/nrg-runtime": "0.22.2",
122
+ "@bonsae/nrg-runtime": "0.24.0",
123
123
  "@clack/prompts": "^1.0.1",
124
124
  "@sinclair/typebox": "^0.34.33",
125
125
  "@vitejs/plugin-vue": "^5.2.3",
@@ -298,9 +298,7 @@ function attachHelpers(node, nodeRedNode, NodeClass) {
298
298
  if (idx === -1) return [];
299
299
  return sentMessages.map((msg) => Array.isArray(msg) ? msg[idx] : void 0).filter((msg) => msg != null);
300
300
  }
301
- return sentMessages.map(
302
- (msg) => Array.isArray(msg) ? msg[port] : port === 0 ? msg : void 0
303
- ).filter((msg) => msg != null);
301
+ return sentMessages.map((msg) => Array.isArray(msg) ? msg[port] : void 0).filter((msg) => msg != null);
304
302
  },
305
303
  statuses() {
306
304
  return [...statusCalls];
package/types/server.d.ts CHANGED
@@ -727,7 +727,7 @@ export declare abstract class IONode<TConfig = any, TCredentials = any, TInput =
727
727
  protected readonly context: IONodeContext;
728
728
  constructor(RED: RED, node: NodeRedNode, config: IONodeConfig<TConfig>, credentials: IONodeCredentials<TCredentials>);
729
729
  [WIRE_HANDLERS](nodeRedNode: NodeRedNode, createdPromise: Promise<void>): void;
730
- input(msg: TInput): void | Promise<void>;
730
+ input(msg: TInput): unknown;
731
731
  send(msg: TOutput): void;
732
732
  get baseOutputs(): number;
733
733
  get totalOutputs(): number;
@@ -787,7 +787,7 @@ export interface IIONode<TConfig = any, TCredentials = any, TInput = any, TOutpu
787
787
  readonly y: number;
788
788
  readonly g: string | undefined;
789
789
  readonly wires: string[][];
790
- input(msg: TInput): void | Promise<void>;
790
+ input(msg: TInput): unknown;
791
791
  send(msg: TOutput): void;
792
792
  status(status: IONodeStatus): void;
793
793
  updateWires(wires: string[][]): void;
@@ -811,7 +811,7 @@ interface IONodeDefinition<TConfigSchema extends TSchema | undefined = undefined
811
811
  registered?(RED: RED): void | Promise<void>;
812
812
  created?(this: BoundIONode<TConfigSchema, TCredsSchema, TSettingsSchema, TInputSchema, TOutputsSchema>): void | Promise<void>;
813
813
  closed?(this: BoundIONode<TConfigSchema, TCredsSchema, TSettingsSchema, TInputSchema, TOutputsSchema>, removed?: boolean): void | Promise<void>;
814
- input?(this: BoundIONode<TConfigSchema, TCredsSchema, TSettingsSchema, TInputSchema, TOutputsSchema>, msg: InferOr<TInputSchema, any>): void | Promise<void>;
814
+ input?(this: BoundIONode<TConfigSchema, TCredsSchema, TSettingsSchema, TInputSchema, TOutputsSchema>, msg: InferOr<TInputSchema, any>): unknown;
815
815
  }
816
816
  /**
817
817
  * Base class for configuration nodes that are shared across multiple nodes
@@ -899,7 +899,7 @@ export declare function registerTypes(nodes: NodeConstructor[]): RegistrationFun
899
899
  * });
900
900
  * ```
901
901
  */
902
- export declare function defineIONode<TConfigSchema extends TSchema | undefined = undefined, TCredsSchema extends TSchema | undefined = undefined, TSettingsSchema extends TSchema | undefined = undefined, TInputSchema extends TSchema | undefined = undefined, TOutputsSchema extends TSchema | readonly TSchema[] | Record<string, TSchema> | undefined = undefined>(def: IONodeDefinition<TConfigSchema, TCredsSchema, TSettingsSchema, TInputSchema, TOutputsSchema>): NodeConstructor<IIONode<InferOr<TConfigSchema, any>, InferOr<TCredsSchema, any>, InferOr<TInputSchema, any>, InferOutputs<TOutputsSchema>>>;
902
+ export declare function defineIONode<TConfigSchema extends TSchema | undefined = undefined, TCredsSchema extends TSchema | undefined = undefined, TSettingsSchema extends TSchema | undefined = undefined, TInputSchema extends TSchema | undefined = undefined, const TOutputsSchema extends TSchema | readonly TSchema[] | Record<string, TSchema> | undefined = undefined>(def: IONodeDefinition<TConfigSchema, TCredsSchema, TSettingsSchema, TInputSchema, TOutputsSchema>): NodeConstructor<IIONode<InferOr<TConfigSchema, any>, InferOr<TCredsSchema, any>, InferOr<TInputSchema, any>, InferOutputs<TOutputsSchema>>>;
903
903
  /**
904
904
  * Creates a config node class from a definition object.
905
905
  *
@@ -427,13 +427,41 @@ type PortNames<T> = [
427
427
  Record<string, Record<string, any>>
428
428
  ] ? string extends keyof T ? never : keyof T & string : never;
429
429
  type PortMessage<T, P extends string> = T extends Record<string, any> ? (P extends keyof T ? T[P] : never) : never;
430
+ type IsAny<T> = 0 extends 1 & T ? true : false;
431
+ type WrappedPort<V, TInput> = {
432
+ output: V;
433
+ } & (unknown extends TInput ? unknown : Partial<TInput>);
434
+ type PortTuple<TOutput, TInput> = IsAny<TOutput> extends true ? any[] : TOutput extends readonly [
435
+ any,
436
+ ...any[]
437
+ ] ? {
438
+ [K in keyof TOutput]: WrappedPort<TOutput[K], TInput>;
439
+ } : [
440
+ TOutput
441
+ ] extends [
442
+ Record<string, Record<string, any>>
443
+ ] ? keyof TOutput extends never ? [
444
+ WrappedPort<TOutput, TInput>
445
+ ] : string extends keyof TOutput ? WrappedPort<unknown, TInput>[] : WrappedPort<TOutput[keyof TOutput], TInput>[] : [
446
+ WrappedPort<TOutput, TInput>
447
+ ];
430
448
  interface TestNodeHelpers<TInput = any, TOutput = any> {
431
- receive(msg: TInput): Promise<void>;
449
+ /** Drive the node's input handler with a Node-RED message. For an object
450
+ * input the declared shape is required while arbitrary extra message
451
+ * properties (`topic`, `_msgid`, correlation ids, …) are allowed — a real
452
+ * Node-RED message always carries more than the validated input schema. A
453
+ * non-object input type passes through unchanged. */
454
+ receive(msg: TInput extends object ? TInput & Record<string, unknown> : TInput): Promise<void>;
432
455
  close(removed?: boolean): Promise<void>;
433
456
  reset(): void;
434
- sent(): TOutput[];
435
- sent<P extends PortNames<TOutput>>(port: P): PortMessage<TOutput, P>[];
436
- sent(port: number): any[];
457
+ /** All raw emissions, each a positional array — `sent()[i][0]` is port 0 of
458
+ * emission `i`, typed from the node's declared output. Built-in lifecycle
459
+ * ports (error/complete/status) are emitted as their own entries here, with
460
+ * slots beyond the declared ports; use `sent(port)` / `sent(name)` for typed,
461
+ * per-port assertions. */
462
+ sent(): PortTuple<TOutput, TInput>[];
463
+ sent<P extends PortNames<TOutput>>(port: P): WrappedPort<PortMessage<TOutput, P>, TInput>[];
464
+ sent(port: number): WrappedPort<unknown, TInput>[];
437
465
  statuses(): any[];
438
466
  logged(level?: "info" | "warn" | "error" | "debug"): string[];
439
467
  warned(): string[];