@bonsae/nrg-runtime 0.25.1 → 0.26.1

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.
Files changed (28) hide show
  1. package/package.json +3 -23
  2. package/server/index.cjs +49 -32
  3. package/server/resources/nrg-client.js +6 -6
  4. package/internal/README.md +0 -30
  5. package/internal/client/components.mjs +0 -1287
  6. package/internal/client/index.mjs +0 -229
  7. package/internal/server/index.cjs +0 -298
  8. package/types/client.d.ts +0 -266
  9. package/types/internal/client/components.d.ts +0 -9
  10. package/types/internal/client/index.d.ts +0 -9
  11. package/types/internal/server/index.d.ts +0 -422
  12. package/types/server.d.ts +0 -941
  13. package/types/shims/brands.d.ts +0 -32
  14. package/types/shims/client/form/components/node-red-config-input.vue.d.ts +0 -125
  15. package/types/shims/client/form/components/node-red-editor-input.vue.d.ts +0 -124
  16. package/types/shims/client/form/components/node-red-input-label.vue.d.ts +0 -34
  17. package/types/shims/client/form/components/node-red-input.vue.d.ts +0 -123
  18. package/types/shims/client/form/components/node-red-json-schema-form.vue.d.ts +0 -772
  19. package/types/shims/client/form/components/node-red-select-input.vue.d.ts +0 -132
  20. package/types/shims/client/form/components/node-red-toggle.vue.d.ts +0 -36
  21. package/types/shims/client/form/components/node-red-typed-input.vue.d.ts +0 -151
  22. package/types/shims/client/globals.d.ts +0 -320
  23. package/types/shims/client/types.d.ts +0 -227
  24. package/types/shims/components.d.ts +0 -23
  25. package/types/shims/constants.d.ts +0 -4
  26. package/types/shims/schema-options.d.ts +0 -24
  27. package/types/shims/shims-vue.d.ts +0 -5
  28. package/types/shims/typebox.d.ts +0 -10
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bonsae/nrg-runtime",
3
- "version": "0.25.1",
4
- "description": "Runtime for Node-RED nodes built with @bonsae/nrg — no build tooling.",
3
+ "version": "0.26.1",
4
+ "description": "The runtime for Node-RED nodes built with @bonsae/nrg — node base classes, schemas, AJV validator, and the editor client. Carries no build tooling.",
5
5
  "author": "Allan Oricil <allanoricil@duck.com>",
6
6
  "license": "MIT",
7
7
  "type": "commonjs",
@@ -11,8 +11,7 @@
11
11
  },
12
12
  "repository": {
13
13
  "url": "git+https://github.com/bonsaedev/nrg.git",
14
- "type": "git",
15
- "directory": "packages/runtime"
14
+ "type": "git"
16
15
  },
17
16
  "publishConfig": {
18
17
  "access": "public"
@@ -34,27 +33,8 @@
34
33
  ],
35
34
  "exports": {
36
35
  "./server": {
37
- "types": "./types/server.d.ts",
38
36
  "require": "./server/index.cjs",
39
37
  "default": "./server/index.cjs"
40
- },
41
- "./client": {
42
- "types": "./types/client.d.ts"
43
- },
44
- "./internal/server": {
45
- "types": "./types/internal/server/index.d.ts",
46
- "require": "./internal/server/index.cjs",
47
- "default": "./internal/server/index.cjs"
48
- },
49
- "./internal/client": {
50
- "types": "./types/internal/client/index.d.ts",
51
- "import": "./internal/client/index.mjs",
52
- "default": "./internal/client/index.mjs"
53
- },
54
- "./internal/client/components": {
55
- "types": "./types/internal/client/components.d.ts",
56
- "import": "./internal/client/components.mjs",
57
- "default": "./internal/client/components.mjs"
58
38
  }
59
39
  },
60
40
  "dependencies": {
package/server/index.cjs CHANGED
@@ -27,7 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
 
30
- // src/server/index.ts
30
+ // src/core/server/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
33
  CompletePortSchema: () => CompletePortSchema,
@@ -48,7 +48,7 @@ __export(index_exports, {
48
48
  });
49
49
  module.exports = __toCommonJS(index_exports);
50
50
 
51
- // src/errors.ts
51
+ // src/core/errors.ts
52
52
  var NrgError = class _NrgError extends Error {
53
53
  constructor(message) {
54
54
  super(message);
@@ -57,7 +57,7 @@ var NrgError = class _NrgError extends Error {
57
57
  }
58
58
  };
59
59
 
60
- // src/server/typed-input.ts
60
+ // src/core/server/typed-input.ts
61
61
  var TypedInput = class {
62
62
  constructor(RED, node, input) {
63
63
  this.RED = RED;
@@ -99,7 +99,7 @@ var TypedInput = class {
99
99
  }
100
100
  };
101
101
 
102
- // src/server/nodes/proxy.ts
102
+ // src/core/server/nodes/proxy.ts
103
103
  function setupConfigProxy(opts) {
104
104
  const { RED, node, config, schema } = opts;
105
105
  const SKIP_PROPS = /* @__PURE__ */ new Set(["id", "_id", "_users"]);
@@ -156,7 +156,7 @@ function setupConfigProxy(opts) {
156
156
  return createProxy(config);
157
157
  }
158
158
 
159
- // src/server/utils.ts
159
+ // src/core/server/utils.ts
160
160
  function getCredentialsFromSchema(schema) {
161
161
  const result = {};
162
162
  for (const [key, value] of Object.entries(schema.properties)) {
@@ -171,10 +171,10 @@ function getCredentialsFromSchema(schema) {
171
171
  return result;
172
172
  }
173
173
 
174
- // src/server/nodes/symbols.ts
174
+ // src/core/server/nodes/symbols.ts
175
175
  var WIRE_HANDLERS = Symbol.for("nrg.wireHandlers");
176
176
 
177
- // src/server/nodes/node.ts
177
+ // src/core/server/nodes/node.ts
178
178
  var cachedSettingsMap = /* @__PURE__ */ new WeakMap();
179
179
  var Node = class _Node {
180
180
  static type;
@@ -408,10 +408,10 @@ var Node = class _Node {
408
408
  }
409
409
  };
410
410
 
411
- // src/server/nodes/io-node.ts
411
+ // src/core/server/nodes/io-node.ts
412
412
  var import_typebox = require("@sinclair/typebox");
413
413
 
414
- // src/server/nodes/context.ts
414
+ // src/core/server/nodes/context.ts
415
415
  var updateLocks = /* @__PURE__ */ new WeakMap();
416
416
  function setupContext(context, store) {
417
417
  const get = (key) => new Promise(
@@ -482,15 +482,14 @@ function setupContext(context, store) {
482
482
  return { get, set, keys, update, increment };
483
483
  }
484
484
 
485
- // src/server/nodes/io-node.ts
485
+ // src/core/server/nodes/io-node.ts
486
486
  var import_node_async_hooks = require("node:async_hooks");
487
- var inputInvocation = new import_node_async_hooks.AsyncLocalStorage();
488
487
  function isSchemaLike(obj) {
489
488
  return obj != null && typeof obj === "object" && import_typebox.Kind in obj;
490
489
  }
491
490
  var RETURN_PROPERTY_PATTERN = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
492
491
  var INPUT_KEY = "input";
493
- var IONode = class extends Node {
492
+ var IONode = class _IONode extends Node {
494
493
  static align;
495
494
  static color;
496
495
  static inputSchema;
@@ -534,6 +533,20 @@ var IONode = class extends Node {
534
533
  if (!s || Array.isArray(s) || isSchemaLike(s)) return void 0;
535
534
  return Object.keys(s);
536
535
  }
536
+ /**
537
+ * Per-`input()`-invocation context, scoped via AsyncLocalStorage. One store
538
+ * per class, shared by every instance: each `.run()` isolates one input()
539
+ * call (and everything it `await`s, including detached `.then`/timer
540
+ * continuations it schedules) into its own session, so concurrent inputs on a
541
+ * node never clobber each other's context and a deferred send keeps the
542
+ * context of the input that scheduled it. Real Node-RED never awaits an async
543
+ * input handler before delivering the next message, so two inputs can be in
544
+ * flight at once. `getStore()` is `undefined` only for a send made entirely
545
+ * outside any `input()` (e.g. a timer set up in `created()`): it carries no
546
+ * inherited context and delivers via `node.send`. Server-only — this is part
547
+ * of the node runtime and is never imported in a browser.
548
+ */
549
+ static #invocation = new import_node_async_hooks.AsyncLocalStorage();
537
550
  context;
538
551
  constructor(RED, node, config, credentials) {
539
552
  super(RED, node, config, credentials);
@@ -627,7 +640,7 @@ var IONode = class extends Node {
627
640
  });
628
641
  this.log("Input is valid");
629
642
  }
630
- return await inputInvocation.run(
643
+ return await _IONode.#invocation.run(
631
644
  { inputMsg: msg, send },
632
645
  () => Promise.resolve(this.input(msg))
633
646
  );
@@ -643,7 +656,7 @@ var IONode = class extends Node {
643
656
  this.#deliver(out);
644
657
  }
645
658
  #deliver(out) {
646
- const send = inputInvocation.getStore()?.send;
659
+ const send = _IONode.#invocation.getStore()?.send;
647
660
  if (send) {
648
661
  send(out);
649
662
  } else {
@@ -706,7 +719,7 @@ var IONode = class extends Node {
706
719
  */
707
720
  #wrapOutgoing(value, mode, port) {
708
721
  const key = this.#returnPropertyKey(port);
709
- const input = inputInvocation.getStore()?.inputMsg ?? {};
722
+ const input = _IONode.#invocation.getStore()?.inputMsg ?? {};
710
723
  if (mode === "reset") {
711
724
  return { [key]: value };
712
725
  }
@@ -832,7 +845,7 @@ var IONode = class extends Node {
832
845
  }
833
846
  };
834
847
 
835
- // src/server/nodes/config-node.ts
848
+ // src/core/server/nodes/config-node.ts
836
849
  var ConfigNode = class extends Node {
837
850
  static category = "config";
838
851
  context;
@@ -864,7 +877,7 @@ var ConfigNode = class extends Node {
864
877
  }
865
878
  };
866
879
 
867
- // src/server/nodes/factories.ts
880
+ // src/core/server/nodes/factories.ts
868
881
  function defineIONode(def) {
869
882
  const NodeClass = class extends IONode {
870
883
  static type = def.type;
@@ -926,10 +939,10 @@ function defineConfigNode(def) {
926
939
  return NodeClass;
927
940
  }
928
941
 
929
- // src/validator.ts
930
- var import_ajv = __toESM(require("ajv"));
931
- var import_ajv_formats = __toESM(require("ajv-formats"));
932
- var import_ajv_errors = __toESM(require("ajv-errors"));
942
+ // src/core/validator.ts
943
+ var import_ajv = __toESM(require("ajv"), 1);
944
+ var import_ajv_formats = __toESM(require("ajv-formats"), 1);
945
+ var import_ajv_errors = __toESM(require("ajv-errors"), 1);
933
946
  var Validator = class {
934
947
  ajv;
935
948
  constructor(options) {
@@ -1066,7 +1079,7 @@ var ValidationError = class _ValidationError extends Error {
1066
1079
  }
1067
1080
  };
1068
1081
 
1069
- // src/server/validation.ts
1082
+ // src/core/server/validation.ts
1070
1083
  function initValidator(RED) {
1071
1084
  if (RED.validator) return;
1072
1085
  const nrg = {
@@ -1107,9 +1120,9 @@ function initValidator(RED) {
1107
1120
  });
1108
1121
  }
1109
1122
 
1110
- // src/server/api/assets.ts
1111
- var import_path = __toESM(require("path"));
1112
- var import_fs = __toESM(require("fs"));
1123
+ // src/core/server/api/assets.ts
1124
+ var import_path = __toESM(require("path"), 1);
1125
+ var import_fs = __toESM(require("fs"), 1);
1113
1126
  var import_module = require("module");
1114
1127
  function serveFile(filePath) {
1115
1128
  return (_req, res, next) => {
@@ -1131,7 +1144,7 @@ function initAssetsRoutes(router) {
1131
1144
  router.get("/nrg/assets/vue.esm-browser.js", serveFile(vueFile));
1132
1145
  }
1133
1146
 
1134
- // src/server/api/routes.ts
1147
+ // src/core/server/api/routes.ts
1135
1148
  var _initialized = false;
1136
1149
  function initRoutes(RED) {
1137
1150
  if (_initialized) return;
@@ -1139,7 +1152,7 @@ function initRoutes(RED) {
1139
1152
  initAssetsRoutes(RED.httpAdmin);
1140
1153
  }
1141
1154
 
1142
- // src/server/registration.ts
1155
+ // src/core/server/registration.ts
1143
1156
  async function registerType(RED, NodeClass) {
1144
1157
  RED.log.debug(`Registering Type: ${NodeClass.type}`);
1145
1158
  if (!(NodeClass.prototype instanceof Node)) {
@@ -1174,7 +1187,7 @@ function registerTypes(nodes) {
1174
1187
  return fn;
1175
1188
  }
1176
1189
 
1177
- // src/constants.ts
1190
+ // src/core/constants.ts
1178
1191
  var TYPED_INPUT_TYPES = [
1179
1192
  "msg",
1180
1193
  "flow",
@@ -1192,9 +1205,9 @@ var TYPED_INPUT_TYPES = [
1192
1205
  "cred"
1193
1206
  ];
1194
1207
 
1195
- // src/server/schemas/type.ts
1208
+ // src/core/server/schemas/type.ts
1196
1209
  var import_typebox2 = require("@sinclair/typebox");
1197
- var import_rules = require("ajv/dist/compile/rules");
1210
+ var import_rules = require("ajv/dist/compile/rules.js");
1198
1211
  function NodeRef(nodeClass, options) {
1199
1212
  return {
1200
1213
  ...import_typebox2.Type.String({
@@ -1214,6 +1227,9 @@ function TypedInput2(options) {
1214
1227
  [import_typebox2.Kind]: "TypedInput"
1215
1228
  };
1216
1229
  }
1230
+ function NrgString(options) {
1231
+ return import_typebox2.Type.String(options);
1232
+ }
1217
1233
  function OutputReturnProperties(options) {
1218
1234
  return import_typebox2.Type.Record(
1219
1235
  import_typebox2.Type.Number(),
@@ -1241,6 +1257,7 @@ function OutputContextModes(options) {
1241
1257
  );
1242
1258
  }
1243
1259
  var SchemaType = Object.assign({}, import_typebox2.Type, {
1260
+ String: NrgString,
1244
1261
  NodeRef,
1245
1262
  TypedInput: TypedInput2,
1246
1263
  OutputReturnProperties,
@@ -1281,7 +1298,7 @@ function defineSchema(properties, options) {
1281
1298
  return markNonValidatable(schema);
1282
1299
  }
1283
1300
 
1284
- // src/server/schemas/base.ts
1301
+ // src/core/server/schemas/base.ts
1285
1302
  var NodeConfigSchema = SchemaType.Object({
1286
1303
  id: SchemaType.String(),
1287
1304
  type: SchemaType.String(),
@@ -1372,7 +1389,7 @@ var StatusPortSchema = SchemaType.Object({
1372
1389
  source: NodeSourceSchema
1373
1390
  });
1374
1391
 
1375
- // src/server/index.ts
1392
+ // src/core/server/index.ts
1376
1393
  function defineModule(definition) {
1377
1394
  return definition;
1378
1395
  }