@unyt/datex 0.0.10 → 0.0.12

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 (91) hide show
  1. package/README.md +10 -14
  2. package/esm/datex-web/datex_web.d.ts +2 -0
  3. package/esm/datex-web/datex_web.d.ts.map +1 -0
  4. package/esm/datex-web/datex_web.internal.d.ts +383 -0
  5. package/esm/datex-web/datex_web.internal.d.ts.map +1 -0
  6. package/esm/{datex-core/datex_core_js.internal.js → datex-web/datex_web.internal.js} +794 -1141
  7. package/esm/datex-web/datex_web.js +18 -0
  8. package/esm/datex-web/datex_web.wasm +0 -0
  9. package/esm/datex-web/wasm_url.node.js +1 -0
  10. package/esm/{datex-core.d.ts → datex.d.ts} +3 -3
  11. package/esm/datex.d.ts.map +1 -0
  12. package/esm/{datex-core.js → datex.js} +3 -3
  13. package/esm/default.d.ts.map +1 -1
  14. package/esm/default.js +2 -3
  15. package/esm/deno.json +28 -20
  16. package/esm/dif/core.d.ts +5 -3
  17. package/esm/dif/core.d.ts.map +1 -1
  18. package/esm/dif/core.js +7 -5
  19. package/esm/dif/definitions.d.ts +45 -34
  20. package/esm/dif/definitions.d.ts.map +1 -1
  21. package/esm/dif/definitions.js +14 -9
  22. package/esm/dif/dif-handler.d.ts +135 -35
  23. package/esm/dif/dif-handler.d.ts.map +1 -1
  24. package/esm/dif/dif-handler.js +378 -159
  25. package/esm/dif/display.d.ts +3 -3
  26. package/esm/dif/display.d.ts.map +1 -1
  27. package/esm/dif/display.js +5 -7
  28. package/esm/dif/js-lib.d.ts +8 -0
  29. package/esm/dif/js-lib.d.ts.map +1 -0
  30. package/esm/dif/js-lib.js +3 -0
  31. package/esm/dif/mod.d.ts +0 -1
  32. package/esm/dif/mod.d.ts.map +1 -1
  33. package/esm/dif/mod.js +0 -1
  34. package/esm/dif/type-registry.d.ts +80 -0
  35. package/esm/dif/type-registry.d.ts.map +1 -0
  36. package/esm/dif/type-registry.js +166 -0
  37. package/esm/global.d.ts +2 -0
  38. package/esm/global.d.ts.map +1 -0
  39. package/esm/global.js +1 -0
  40. package/esm/{runtime/special-core-types.d.ts → lib/special-core-types/endpoint.d.ts} +3 -1
  41. package/esm/lib/special-core-types/endpoint.d.ts.map +1 -0
  42. package/esm/{runtime/special-core-types.js → lib/special-core-types/endpoint.js} +6 -1
  43. package/esm/mod.d.ts +3 -1
  44. package/esm/mod.d.ts.map +1 -1
  45. package/esm/mod.js +3 -1
  46. package/esm/network/com-hub.d.ts +20 -22
  47. package/esm/network/com-hub.d.ts.map +1 -1
  48. package/esm/network/com-hub.js +30 -49
  49. package/esm/network/interfaces/websocket-server-base.d.ts +8 -0
  50. package/esm/network/interfaces/websocket-server-base.d.ts.map +1 -0
  51. package/esm/network/interfaces/websocket-server-base.js +93 -0
  52. package/esm/network/interfaces/websocket-server-deno.d.ts +4 -0
  53. package/esm/network/interfaces/websocket-server-deno.d.ts.map +1 -0
  54. package/esm/network/interfaces/websocket-server-deno.js +22 -0
  55. package/esm/network/mod.d.ts +0 -1
  56. package/esm/network/mod.d.ts.map +1 -1
  57. package/esm/network/mod.js +0 -1
  58. package/esm/refs/ref.d.ts.map +1 -1
  59. package/esm/refs/ref.js +1 -2
  60. package/esm/runtime/runtime.d.ts +25 -62
  61. package/esm/runtime/runtime.d.ts.map +1 -1
  62. package/esm/runtime/runtime.js +42 -26
  63. package/esm/utils/devtools-formatter.d.ts +2 -0
  64. package/esm/utils/devtools-formatter.d.ts.map +1 -0
  65. package/esm/utils/devtools-formatter.js +40 -0
  66. package/esm/utils/exceptions.d.ts +4 -0
  67. package/esm/utils/exceptions.d.ts.map +1 -0
  68. package/esm/utils/exceptions.js +9 -0
  69. package/esm/utils/js-runtime-compat/js-runtime.d.ts.map +1 -1
  70. package/package.json +7 -7
  71. package/esm/datex-core/datex_core_js.d.ts +0 -2
  72. package/esm/datex-core/datex_core_js.d.ts.map +0 -1
  73. package/esm/datex-core/datex_core_js.internal.d.ts +0 -512
  74. package/esm/datex-core/datex_core_js.internal.d.ts.map +0 -1
  75. package/esm/datex-core/datex_core_js.js +0 -21
  76. package/esm/datex-core/datex_core_js.wasm +0 -0
  77. package/esm/datex-core/wasm_url.node.js +0 -1
  78. package/esm/datex-core.d.ts.map +0 -1
  79. package/esm/dif/builders.d.ts +0 -16
  80. package/esm/dif/builders.d.ts.map +0 -1
  81. package/esm/dif/builders.js +0 -28
  82. package/esm/network/com-interface.d.ts +0 -35
  83. package/esm/network/com-interface.d.ts.map +0 -1
  84. package/esm/network/com-interface.js +0 -75
  85. package/esm/network/interface-impls/base.d.ts +0 -46
  86. package/esm/network/interface-impls/base.d.ts.map +0 -1
  87. package/esm/network/interface-impls/base.js +0 -47
  88. package/esm/network/interface-impls/websocket-client.d.ts +0 -8
  89. package/esm/network/interface-impls/websocket-client.d.ts.map +0 -1
  90. package/esm/network/interface-impls/websocket-client.js +0 -8
  91. package/esm/runtime/special-core-types.d.ts.map +0 -1
@@ -9,67 +9,58 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- var _a, _ComHub_interfaceImpls, _ComHub_interfaceImplsByClass, _ComHub_jsComHub;
13
- import { ComInterface } from "./com-interface.js";
12
+ var _ComHub_jsComHub, _ComHub_runtime;
14
13
  /**
15
14
  * Communication hub for managing communication interfaces.
16
15
  */
17
16
  export class ComHub {
18
- constructor(jsComHub) {
17
+ constructor(jsComHub, runtime) {
19
18
  /** The JS communication hub. */
20
19
  _ComHub_jsComHub.set(this, void 0);
20
+ _ComHub_runtime.set(this, void 0);
21
21
  __classPrivateFieldSet(this, _ComHub_jsComHub, jsComHub, "f");
22
+ __classPrivateFieldSet(this, _ComHub_runtime, runtime, "f");
23
+ }
24
+ registerInterfaceFactory(factoryDefinition) {
25
+ __classPrivateFieldGet(this, _ComHub_jsComHub, "f").register_interface_factory(factoryDefinition.interfaceType, async (setupData) => {
26
+ const setupDataJS = await __classPrivateFieldGet(this, _ComHub_runtime, "f").dif.resolveDIFValueContainer(setupData);
27
+ return factoryDefinition.factory(setupDataJS);
28
+ });
22
29
  }
23
30
  /**
24
- * Registers a communication interface implementation.
25
- * @param interfaceType The type of the interface.
26
- * @param impl The implementation class of the interface.
31
+ * Creates a new communication interface.
32
+ * @param type The type of the interface to create.
33
+ * @param setupData The setup data for the interface.
34
+ * @param priority The priority of the interface (optional).
35
+ * @returns A promise that resolves to the UUID of the created interface.
27
36
  */
28
- static registerInterfaceImpl(interfaceType, impl) {
29
- if (__classPrivateFieldGet(this, _a, "f", _ComHub_interfaceImpls).has(interfaceType)) {
30
- throw new Error(`Interface implementation for ${interfaceType} already registered.`);
31
- }
32
- __classPrivateFieldGet(this, _a, "f", _ComHub_interfaceImpls).set(interfaceType, impl);
33
- __classPrivateFieldGet(this, _a, "f", _ComHub_interfaceImplsByClass).set(impl, interfaceType);
34
- }
35
- async createInterface(interfaceType, setupData) {
36
- const type = typeof interfaceType === "string"
37
- ? interfaceType
38
- : __classPrivateFieldGet(_a, _a, "f", _ComHub_interfaceImplsByClass).get(interfaceType);
39
- if (type === undefined) {
40
- throw new Error(`Interface implementation for ${interfaceType.name} not registered.`);
41
- }
42
- const implClass = __classPrivateFieldGet(_a, _a, "f", _ComHub_interfaceImpls).get(type);
43
- if (implClass === undefined) {
44
- throw new Error(`Interface implementation for ${type} not registered.`);
45
- }
46
- const uuid = await __classPrivateFieldGet(this, _ComHub_jsComHub, "f").create_interface(type, JSON.stringify(setupData));
47
- const impl = new implClass(uuid, setupData, __classPrivateFieldGet(this, _ComHub_jsComHub, "f"));
48
- await impl.init?.();
49
- return new ComInterface(uuid, impl, __classPrivateFieldGet(this, _ComHub_jsComHub, "f"));
37
+ async createInterface(type, setupData, priority) {
38
+ return await __classPrivateFieldGet(this, _ComHub_jsComHub, "f").create_interface(type, __classPrivateFieldGet(this, _ComHub_runtime, "f").dif.convertJSValueToDIFValueContainer(setupData), priority);
50
39
  }
51
- _update() {
52
- return __classPrivateFieldGet(this, _ComHub_jsComHub, "f").update();
40
+ removeInterface(interface_uuid) {
41
+ return __classPrivateFieldGet(this, _ComHub_jsComHub, "f").remove_interface(interface_uuid);
53
42
  }
54
- _drain_incoming_blocks() {
55
- return __classPrivateFieldGet(this, _ComHub_jsComHub, "f")._drain_incoming_blocks();
43
+ removeSocket(socket_uuid) {
44
+ return __classPrivateFieldGet(this, _ComHub_jsComHub, "f").remove_socket(socket_uuid);
56
45
  }
57
46
  /**
58
47
  * Prints the metadata of the ComHub. Only available in debug builds.
48
+ * Only exists in debug builds
59
49
  */
60
50
  printMetadata() {
61
- // as any required because get_metadata_string only exists in debug builds
62
- // deno-lint-ignore no-explicit-any
63
51
  const metadata = __classPrivateFieldGet(this, _ComHub_jsComHub, "f").get_metadata_string();
64
52
  console.log(metadata);
65
53
  }
54
+ getMetadata() {
55
+ // as any required because get_metadata only exists in debug builds
56
+ return __classPrivateFieldGet(this, _ComHub_jsComHub, "f").get_metadata();
57
+ }
66
58
  /**
67
59
  * Prints the trace for a specific endpoint. Only available in debug builds.
68
60
  * @param endpoint The endpoint for which to print the trace.
69
61
  */
70
62
  async printTrace(endpoint) {
71
63
  // as any required because get_trace_string only exists in debug builds
72
- // deno-lint-ignore no-explicit-any
73
64
  const trace = await __classPrivateFieldGet(this, _ComHub_jsComHub, "f").get_trace_string(endpoint);
74
65
  if (trace === undefined) {
75
66
  console.warn(`No trace available for endpoint: ${endpoint}`);
@@ -77,15 +68,9 @@ export class ComHub {
77
68
  }
78
69
  console.log(trace);
79
70
  }
80
- /**
81
- * Sends a block of data to a specific interface and socket.
82
- * @param block The data block to send.
83
- * @param interface_uuid The UUID of the interface to send the block to.
84
- * @param socket_uuid The UUID of the socket to send the block to.
85
- * @returns A promise that resolves to true if the block was sent successfully, false otherwise.
86
- */
87
- sendBlock(block, interface_uuid, socket_uuid) {
88
- return __classPrivateFieldGet(this, _ComHub_jsComHub, "f").send_block(block, interface_uuid, socket_uuid);
71
+ getTrace(endpoint) {
72
+ // as any required because get_trace_string only exists in debug builds
73
+ return __classPrivateFieldGet(this, _ComHub_jsComHub, "f").get_trace(endpoint);
89
74
  }
90
75
  /**
91
76
  * Registers a callback to intercept incoming blocks.
@@ -102,8 +87,4 @@ export class ComHub {
102
87
  __classPrivateFieldGet(this, _ComHub_jsComHub, "f").register_outgoing_block_interceptor(callback);
103
88
  }
104
89
  }
105
- _a = ComHub, _ComHub_jsComHub = new WeakMap();
106
- /** Static map of registered interface implementations. */
107
- _ComHub_interfaceImpls = { value: new Map() };
108
- /** Static map of interface implementations by class. */
109
- _ComHub_interfaceImplsByClass = { value: new Map() };
90
+ _ComHub_jsComHub = new WeakMap(), _ComHub_runtime = new WeakMap();
@@ -0,0 +1,8 @@
1
+ import type { ComInterfaceFactory } from "../com-hub.js";
2
+ import type { WebSocketServerInterfaceSetupData } from "../../datex.js";
3
+ /**
4
+ * Utility function to create a WebSocket server communication interface factory from a given server factory function.
5
+ * @param serverFactory
6
+ */
7
+ export declare function createWebsocketServerComInterfaceFactory(serverFactory: (setupData: WebSocketServerInterfaceSetupData) => ReadableStream<WebSocket>): ComInterfaceFactory<WebSocketServerInterfaceSetupData>;
8
+ //# sourceMappingURL=websocket-server-base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket-server-base.d.ts","sourceRoot":"","sources":["../../../src/network/interfaces/websocket-server-base.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,KAAK,EAAuB,iCAAiC,EAAE,MAAM,gBAAgB,CAAC;AAE7F;;;GAGG;AACH,wBAAgB,wCAAwC,CACpD,aAAa,EAAE,CAAC,SAAS,EAAE,iCAAiC,KAAK,cAAc,CAAC,SAAS,CAAC,GAC3F,mBAAmB,CAAC,iCAAiC,CAAC,CAiDxD"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Utility function to create a WebSocket server communication interface factory from a given server factory function.
3
+ * @param serverFactory
4
+ */
5
+ export function createWebsocketServerComInterfaceFactory(serverFactory) {
6
+ return {
7
+ interfaceType: "websocket-server",
8
+ factory: (setupData) => {
9
+ // FIXME: workaround, convert map to object if map provided as setupData
10
+ if (setupData instanceof Map) {
11
+ setupData = Object.fromEntries(Array.from(setupData.entries()));
12
+ }
13
+ return {
14
+ properties: {
15
+ interface_type: "websocket-server",
16
+ channel: "websocket",
17
+ name: setupData.bind_address,
18
+ direction: "InOut",
19
+ round_trip_time: 0,
20
+ max_bandwidth: 0,
21
+ continuous_connection: false,
22
+ allow_redirects: false,
23
+ is_secure_channel: false,
24
+ reconnection_config: "NoReconnect",
25
+ auto_identify: true,
26
+ connectable_interfaces: [], // TODO add websocket client connections
27
+ },
28
+ has_single_socket: false,
29
+ new_sockets_iterator: serverFactory(setupData).pipeThrough(new TransformStream({
30
+ async transform(socket, controller) {
31
+ const incoming_data_stream = await createSocketDataIterator(socket);
32
+ controller.enqueue({
33
+ properties: {
34
+ direction: "InOut",
35
+ channel_factor: 1,
36
+ connection_timestamp: Date.now(),
37
+ direct_endpoint: undefined,
38
+ },
39
+ iterator: incoming_data_stream,
40
+ send_callback: (data) => {
41
+ socket.send(data);
42
+ },
43
+ });
44
+ },
45
+ })),
46
+ };
47
+ },
48
+ };
49
+ }
50
+ /**
51
+ * Utility function that returns an async generator yielding ArrayBuffers from a WebSocket
52
+ */
53
+ async function createSocketDataIterator(webSocket) {
54
+ const { promise, resolve, reject } = Promise.withResolvers();
55
+ webSocket.addEventListener("open", () => resolve(), { once: true });
56
+ webSocket.addEventListener("error", (event) => reject(new Error(`WebSocket error: ${event}`)), { once: true });
57
+ // wait until the socket is open before starting to yield messages
58
+ if (webSocket.readyState === WebSocket.OPEN) {
59
+ resolve();
60
+ }
61
+ else if (webSocket.readyState === WebSocket.CLOSED || webSocket.readyState === WebSocket.CLOSING) {
62
+ reject(new Error("WebSocket is already closed"));
63
+ }
64
+ else {
65
+ // otherwise, wait for the open event
66
+ console.log("Waiting for WebSocket to open...");
67
+ }
68
+ await promise;
69
+ let closed = false;
70
+ return new ReadableStream({
71
+ start(controller) {
72
+ webSocket.onmessage = (event) => {
73
+ // ignore if not ArrayBuffer
74
+ if (!(event.data instanceof ArrayBuffer)) {
75
+ console.warn("Received non-ArrayBuffer message, ignoring");
76
+ return;
77
+ }
78
+ controller.enqueue(event.data);
79
+ };
80
+ webSocket.onerror = () => {
81
+ controller.error(new Error("WebSocket error"));
82
+ };
83
+ webSocket.onclose = () => {
84
+ if (!closed)
85
+ controller.close();
86
+ };
87
+ },
88
+ cancel() {
89
+ webSocket.close();
90
+ closed = true;
91
+ },
92
+ });
93
+ }
@@ -0,0 +1,4 @@
1
+ import type { WebSocketServerInterfaceSetupData } from "../../datex.js";
2
+ import type { ComInterfaceFactory } from "../com-hub.js";
3
+ export declare const websocketServerDenoComInterfaceFactory: ComInterfaceFactory<WebSocketServerInterfaceSetupData>;
4
+ //# sourceMappingURL=websocket-server-deno.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket-server-deno.d.ts","sourceRoot":"","sources":["../../../src/network/interfaces/websocket-server-deno.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,gBAAgB,CAAC;AAExE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AA4BzD,eAAO,MAAM,sCAAsC,EAAE,mBAAmB,CAAC,iCAAiC,CAC3C,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { createWebsocketServerComInterfaceFactory } from "./websocket-server-base.js";
2
+ function denoServerFactory(setupData) {
3
+ const [hostname, maybe_port] = setupData.bind_address.split(":");
4
+ const port = maybe_port ? parseInt(maybe_port) : undefined;
5
+ let server;
6
+ return new ReadableStream({
7
+ start(controller) {
8
+ server = Deno.serve({ port, hostname }, (req) => {
9
+ if (req.headers.get("upgrade") != "websocket") {
10
+ return new Response(null, { status: 501 });
11
+ }
12
+ const { socket, response } = Deno.upgradeWebSocket(req);
13
+ controller.enqueue(socket);
14
+ return response;
15
+ });
16
+ },
17
+ async cancel() {
18
+ await server.shutdown();
19
+ },
20
+ });
21
+ }
22
+ export const websocketServerDenoComInterfaceFactory = createWebsocketServerComInterfaceFactory(denoServerFactory);
@@ -5,5 +5,4 @@
5
5
  * communication hubs and interfaces.
6
6
  */
7
7
  export * from "./com-hub.js";
8
- export * from "./com-interface.js";
9
8
  //# sourceMappingURL=mod.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/network/mod.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/network/mod.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,cAAc,CAAC"}
@@ -5,4 +5,3 @@
5
5
  * communication hubs and interfaces.
6
6
  */
7
7
  export * from "./com-hub.js";
8
- export * from "./com-interface.js";
@@ -1 +1 @@
1
- {"version":3,"file":"ref.d.ts","sourceRoot":"","sources":["../../src/refs/ref.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAExD;;;GAGG;AACH,qBAAa,GAAG,CAAC,CAAC;;gBAKF,KAAK,EAAE,CAAC,EAAE,cAAc,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU;IAMpE;;OAEG;IACH,IAAI,cAAc,IAAI,MAAM,CAE3B;IAED;;;;OAIG;IACH,mBAAmB,CAAC,QAAQ,EAAE,CAAC;IAI/B;;OAEG;IACH,IAAI,KAAK,IAAI,CAAC,CAEb;IAED;;;;OAIG;IACH,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC,EAUpB;CACJ"}
1
+ {"version":3,"file":"ref.d.ts","sourceRoot":"","sources":["../../src/refs/ref.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAExD;;;GAGG;AACH,qBAAa,GAAG,CAAC,CAAC;;gBAKF,KAAK,EAAE,CAAC,EAAE,cAAc,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU;IAMpE;;OAEG;IACH,IAAI,cAAc,IAAI,MAAM,CAE3B;IAED;;;;OAIG;IACH,mBAAmB,CAAC,QAAQ,EAAE,CAAC;IAI/B;;OAEG;IACH,IAAI,KAAK,IAAI,CAAC,CAEb;IAED;;;;OAIG;IACH,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC,EAOpB;CACJ"}
package/esm/refs/ref.js CHANGED
@@ -10,7 +10,6 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
12
  var _Ref_value, _Ref_pointerAddress, _Ref_difHandler;
13
- import { DIF_Replace } from "../dif/builders.js";
14
13
  /**
15
14
  * The Ref class is a wrapper around a value that is stored in a pointer.
16
15
  * Primitive values (string, number, boolean, null) are always wrapped in a Ref when stored in a pointer.
@@ -54,7 +53,7 @@ export class Ref {
54
53
  if (oldValue === newValue)
55
54
  return;
56
55
  // Try to update the pointer
57
- __classPrivateFieldGet(this, _Ref_difHandler, "f").updatePointer(__classPrivateFieldGet(this, _Ref_pointerAddress, "f"), DIF_Replace(__classPrivateFieldGet(this, _Ref_difHandler, "f"), newValue));
56
+ __classPrivateFieldGet(this, _Ref_difHandler, "f").triggerReplace(__classPrivateFieldGet(this, _Ref_pointerAddress, "f"), newValue);
58
57
  __classPrivateFieldSet(this, _Ref_value, newValue, "f");
59
58
  }
60
59
  }
@@ -1,12 +1,11 @@
1
- import { type JSRuntime } from "../datex-core.js";
1
+ import { type DecompileOptions, type JSRuntime } from "../datex.js";
2
2
  import { ComHub } from "../network/com-hub.js";
3
- import { DIFHandler } from "../dif/dif-handler.js";
4
- import type { DIFReferenceMutability, DIFTypeContainer } from "../dif/definitions.js";
3
+ import { DIFHandler, type PointerOut } from "../dif/dif-handler.js";
4
+ import type { DIFReferenceMutability, DIFTypeDefinition } from "../dif/definitions.js";
5
5
  import type { Ref } from "../refs/ref.js";
6
6
  /** debug flags for the runtime */
7
- interface DebugFlags {
8
- allow_unsigned_blocks?: boolean;
9
- enable_deterministic_behavior?: boolean;
7
+ interface DebugConfig {
8
+ log_level?: "error" | "warn" | "info" | "debug" | "trace" | null;
10
9
  }
11
10
  /** configuration for the runtime */
12
11
  export type RuntimeConfig = {
@@ -15,14 +14,7 @@ export type RuntimeConfig = {
15
14
  type: string;
16
15
  config: unknown;
17
16
  }[];
18
- debug?: boolean;
19
- };
20
- /** options for decompiling values to strings */
21
- export type DecompileOptions = {
22
- formatted?: boolean;
23
- colorized?: boolean;
24
- resolve_slots?: boolean;
25
- json_compat?: boolean;
17
+ env?: Record<string, string>;
26
18
  };
27
19
  /**
28
20
  * The main Runtime class for executing Datex scripts and managing communication interfaces.
@@ -30,20 +22,14 @@ export type DecompileOptions = {
30
22
  export declare class Runtime {
31
23
  #private;
32
24
  readonly js_version: string;
33
- constructor(config: RuntimeConfig, debug_flags?: DebugFlags);
25
+ private constructor();
34
26
  /**
35
27
  * Creates a new Runtime instance.
36
28
  * @param config Runtime configuration
37
- * @param debug_flags Debug flags for the runtime
29
+ * @param debugConfig Debug flags for the runtime
38
30
  * @returns A promise that resolves to the created Runtime instance
39
31
  */
40
- static create(config: RuntimeConfig, debug_flags?: DebugFlags): Promise<Runtime>;
41
- /**
42
- * Starts the runtime.
43
- * @returns A promise that resolves when the runtime has started.
44
- */
45
- start(): Promise<void>;
46
- _stop(): Promise<void>;
32
+ static create(config: RuntimeConfig, debugConfig?: DebugConfig): Promise<Runtime>;
47
33
  /**
48
34
  * Gets the endpoint of the runtime.
49
35
  */
@@ -131,50 +117,27 @@ export declare class Runtime {
131
117
  valueToString(value: unknown, decompileOptions?: DecompileOptions | null): string;
132
118
  _execute_internal(datexScript: string): boolean;
133
119
  /**
134
- * Creates a new pointer containg the given JS value.
135
- * The returned value is a proxy object that behaves like the original object,
136
- * but also propagates changes between JS and the DATEX runtime.
120
+ * Creates a new reference containg the given JS value.
121
+ * For primitive values, a Ref wrapper is returned.
122
+ * For other values (objects, arrays, maps), the returned value is a proxy object that behaves like the original object.
123
+ *
137
124
  * @param value The JS value to store in the pointer.
138
125
  * @param allowedType Optional DIF type container to restrict the type of the pointer.
139
126
  * @param mutability Optional mutability of the reference (default is Mutable).
140
127
  * @returns A proxy object representing the pointer in JS.
141
128
  */
142
- createPointer<V, M extends DIFReferenceMutability = typeof DIFReferenceMutability.Mutable>(value: V & {}, allowedType?: DIFTypeContainer | null, mutability?: M): PointerOut<V, M>;
143
- }
144
- type WidenLiteral<T> = T extends string ? string : T extends number ? number : T extends boolean ? boolean : T extends bigint ? bigint : T extends symbol ? symbol : T;
145
- type IsRef<T> = T extends Ref<unknown> ? true : false;
146
- type ContainsRef<T> = IsRef<T> extends true ? true : T extends object ? {
147
- [K in keyof T]: ContainsRef<T[K]>;
148
- }[keyof T] extends true ? true : false : false;
149
- /** A type representing an assignable reference or a plain value **/
150
- export type AssignableRef<T> = Ref<T> | T & {
151
- value?: T;
152
- };
153
- type Builtins = ((...args: unknown[]) => unknown) | Date | RegExp | Map<unknown, unknown> | Set<unknown> | WeakMap<WeakKey, unknown> | WeakSet<WeakKey> | Array<unknown>;
154
- type IsPlainObject<T> = T extends Builtins ? false : T extends object ? true : false;
155
- type ObjectFieldOut<T, M extends DIFReferenceMutability> = T extends Ref<infer U> ? M extends typeof DIFReferenceMutability.Immutable ? Ref<U> : AssignableRef<U> : IsPlainObject<T> extends true ? (ContainsRef<T> extends true ? M extends typeof DIFReferenceMutability.Immutable ? {
156
- readonly [K in keyof T]: ObjectFieldOut<T[K], M>;
157
- } : {
158
- [K in keyof T]: ObjectFieldOut<T[K], M>;
159
- } : {
160
- readonly [K in keyof T]: ObjectFieldOut<T[K], M>;
161
- }) : T;
162
- type PointerOut<V, M extends DIFReferenceMutability> = V extends Ref<infer U> ? M extends typeof DIFReferenceMutability.Immutable ? Ref<U> : AssignableRef<U> : IsPlainObject<V> extends true ? (ContainsRef<V> extends true ? M extends typeof DIFReferenceMutability.Immutable ? {
163
- readonly [K in keyof V]: ObjectFieldOut<V[K], M>;
164
- } : {
165
- [K in keyof V]: ObjectFieldOut<V[K], M>;
166
- } : {
167
- readonly [K in keyof V]: ObjectFieldOut<V[K], M>;
168
- }) : V extends Builtins ? Pointer<V> : M extends typeof DIFReferenceMutability.Immutable ? Ref<V> : Ref<WidenLiteral<V>>;
169
- type CollectionProps<T> = {
170
- [K in keyof T as K extends "value" ? never : K]: T[K];
171
- };
172
- interface MapRef<K, V> extends Ref<Map<K, V>>, CollectionProps<Map<K, V>> {
173
- }
174
- interface SetRef<T> extends Ref<Set<T>>, CollectionProps<Set<T>> {
175
- }
176
- interface ArrayRef<T> extends Ref<T[]>, CollectionProps<T[]> {
129
+ createTransparentReference<V, M extends DIFReferenceMutability = typeof DIFReferenceMutability.Mutable>(value: V & {}, allowedType?: DIFTypeDefinition | null, mutability?: M): PointerOut<V, M>;
130
+ /**
131
+ * Creates or retrieves a wrapped reference for the given value.
132
+ * If the value is already a reference, it returns the existing reference.
133
+ *
134
+ * @param value
135
+ * @param allowedType
136
+ * @param mutability
137
+ * @returns
138
+ */
139
+ createOrGetWrappedReference<V, M extends DIFReferenceMutability = typeof DIFReferenceMutability.Mutable>(_value: V, _allowedType?: DIFTypeDefinition | null, _mutability?: M): Ref<V>;
140
+ startLSP(callback: (data: string) => void): (data: string) => void;
177
141
  }
178
- type Pointer<T> = T extends Map<infer K, infer V> ? MapRef<K, V> : T extends Set<infer U> ? SetRef<U> : T extends Array<infer U> ? ArrayRef<U> : Ref<T>;
179
142
  export {};
180
143
  //# sourceMappingURL=runtime.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/runtime/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,KAAK,SAAS,EACjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,EACR,sBAAsB,EACtB,gBAAgB,EACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAK1C,kCAAkC;AAClC,UAAU,UAAU;IAChB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,6BAA6B,CAAC,EAAE,OAAO,CAAC;CAC3C;AAED,qCAAqC;AACrC,MAAM,MAAM,aAAa,GAAG;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,OAAO,CAAA;KAAE,EAAE,CAAC;IACjD,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,iDAAiD;AACjD,MAAM,MAAM,gBAAgB,GAAG;IAC3B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,qBAAa,OAAO;;IAChB,SAAgB,UAAU,SAAW;gBAMzB,MAAM,EAAE,aAAa,EAAE,WAAW,CAAC,EAAE,UAAU;IAM3D;;;;;OAKG;WACiB,MAAM,CACtB,MAAM,EAAE,aAAa,EACrB,WAAW,CAAC,EAAE,UAAU,GACzB,OAAO,CAAC,OAAO,CAAC;IAMnB;;;OAGG;IACI,KAAK,IAAI,OAA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8BJ;;;;;OAKG;IACI,aAAa,CAChB,KAAK,EAAE,OAAO,EACd,gBAAgB,GAAE,gBAAgB,GAAG,IAAW,GACjD,MAAM;IA8BF,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO;IAItD;;;;;;;;;OASG;IACI,0BAA0B,CAC7B,CAAC,EACD,CAAC,SAAS,sBAAsB,GAAG,OAAO,sBAAsB,CAAC,OAAO,EAGxE,KAAK,EAAE,CAAC,GAAG,EAAE,EACb,WAAW,CAAC,EAAE,iBAAiB,GAAG,IAAI,EACtC,UAAU,CAAC,EAAE,CAAC,GACf,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC;IAQnB;;;;;;;;OAQG;IACI,2BAA2B,CAC9B,CAAC,EACD,CAAC,SAAS,sBAAsB,GAAG,OAAO,sBAAsB,CAAC,OAAO,EAExE,MAAM,EAAE,CAAC,EACT,YAAY,CAAC,EAAE,iBAAiB,GAAG,IAAI,EACvC,WAAW,CAAC,EAAE,CAAC,GAChB,GAAG,CAAC,CAAC,CAAC;IAIF,QAAQ,CACX,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GACjC,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI;CAY5B"}
@@ -10,16 +10,18 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
12
  var _Runtime_instances, _Runtime_runtime, _Runtime_comHub, _Runtime_difHandler, _Runtime_executeInternal, _Runtime_executeSyncInternal, _Runtime_getScriptAndValues;
13
- import { create_runtime, execute_internal, } from "../datex-core.js";
13
+ import { create_runtime, execute_internal } from "../datex.js";
14
14
  import { ComHub } from "../network/com-hub.js";
15
15
  import { DIFHandler } from "../dif/dif-handler.js";
16
+ import { unimplemented } from "../utils/exceptions.js";
17
+ // TODO: move to global.ts
16
18
  /** auto-generated version - do not edit: */
17
- const VERSION = "0.0.10";
19
+ const VERSION = "0.0.12";
18
20
  /**
19
21
  * The main Runtime class for executing Datex scripts and managing communication interfaces.
20
22
  */
21
23
  export class Runtime {
22
- constructor(config, debug_flags) {
24
+ constructor(jsRuntime) {
23
25
  _Runtime_instances.add(this);
24
26
  Object.defineProperty(this, "js_version", {
25
27
  enumerable: true,
@@ -30,30 +32,21 @@ export class Runtime {
30
32
  _Runtime_runtime.set(this, void 0);
31
33
  _Runtime_comHub.set(this, void 0);
32
34
  _Runtime_difHandler.set(this, void 0);
33
- __classPrivateFieldSet(this, _Runtime_runtime, create_runtime(JSON.stringify(config), debug_flags), "f");
34
- __classPrivateFieldSet(this, _Runtime_comHub, new ComHub(__classPrivateFieldGet(this, _Runtime_runtime, "f").com_hub), "f");
35
+ __classPrivateFieldSet(this, _Runtime_runtime, jsRuntime, "f");
36
+ __classPrivateFieldSet(this, _Runtime_comHub, new ComHub(__classPrivateFieldGet(this, _Runtime_runtime, "f").com_hub, this), "f");
35
37
  __classPrivateFieldSet(this, _Runtime_difHandler, new DIFHandler(__classPrivateFieldGet(this, _Runtime_runtime, "f")), "f");
36
38
  }
37
39
  /**
38
40
  * Creates a new Runtime instance.
39
41
  * @param config Runtime configuration
40
- * @param debug_flags Debug flags for the runtime
42
+ * @param debugConfig Debug flags for the runtime
41
43
  * @returns A promise that resolves to the created Runtime instance
42
44
  */
43
- static async create(config, debug_flags) {
44
- const runtime = new Runtime(config, debug_flags);
45
- await runtime.start();
46
- return runtime;
47
- }
48
- /**
49
- * Starts the runtime.
50
- * @returns A promise that resolves when the runtime has started.
51
- */
52
- start() {
53
- return __classPrivateFieldGet(this, _Runtime_runtime, "f").start();
54
- }
55
- _stop() {
56
- return __classPrivateFieldGet(this, _Runtime_runtime, "f")._stop();
45
+ static async create(config, debugConfig) {
46
+ // workaround: temp dif handler without runtime to convert config to DIF
47
+ const configDIF = DIFHandler.convertJSValueToDIFValueContainer(config);
48
+ const jsRuntime = await create_runtime(configDIF, debugConfig);
49
+ return new Runtime(jsRuntime);
57
50
  }
58
51
  /**
59
52
  * Gets the endpoint of the runtime.
@@ -121,24 +114,47 @@ export class Runtime {
121
114
  * @returns The string representation of the value.
122
115
  */
123
116
  valueToString(value, decompileOptions = null) {
124
- return __classPrivateFieldGet(this, _Runtime_runtime, "f").value_to_string(__classPrivateFieldGet(this, _Runtime_difHandler, "f").convertJSValueToDIFValue(value), decompileOptions);
117
+ return __classPrivateFieldGet(this, _Runtime_runtime, "f").value_to_string(__classPrivateFieldGet(this, _Runtime_difHandler, "f").convertJSValueToDIFValueContainer(value), decompileOptions);
125
118
  }
126
119
  _execute_internal(datexScript) {
127
120
  return execute_internal(datexScript);
128
121
  }
129
122
  /**
130
- * Creates a new pointer containg the given JS value.
131
- * The returned value is a proxy object that behaves like the original object,
132
- * but also propagates changes between JS and the DATEX runtime.
123
+ * Creates a new reference containg the given JS value.
124
+ * For primitive values, a Ref wrapper is returned.
125
+ * For other values (objects, arrays, maps), the returned value is a proxy object that behaves like the original object.
126
+ *
133
127
  * @param value The JS value to store in the pointer.
134
128
  * @param allowedType Optional DIF type container to restrict the type of the pointer.
135
129
  * @param mutability Optional mutability of the reference (default is Mutable).
136
130
  * @returns A proxy object representing the pointer in JS.
137
131
  */
138
- createPointer(
132
+ createTransparentReference(
139
133
  // deno-lint-ignore ban-types
140
134
  value, allowedType, mutability) {
141
- return __classPrivateFieldGet(this, _Runtime_difHandler, "f").createPointerFromJSValue(value, allowedType, mutability);
135
+ return __classPrivateFieldGet(this, _Runtime_difHandler, "f").createTransparentReference(value, allowedType, mutability);
136
+ }
137
+ /**
138
+ * Creates or retrieves a wrapped reference for the given value.
139
+ * If the value is already a reference, it returns the existing reference.
140
+ *
141
+ * @param value
142
+ * @param allowedType
143
+ * @param mutability
144
+ * @returns
145
+ */
146
+ createOrGetWrappedReference(_value, _allowedType, _mutability) {
147
+ unimplemented();
148
+ }
149
+ startLSP(callback) {
150
+ const decoder = new TextDecoder("utf-8");
151
+ const encoder = new TextEncoder();
152
+ const sendToRust = __classPrivateFieldGet(this, _Runtime_runtime, "f").start_lsp((bytes) => {
153
+ callback(decoder.decode(bytes));
154
+ });
155
+ return (data) => {
156
+ sendToRust(encoder.encode(data));
157
+ };
142
158
  }
143
159
  }
144
160
  _Runtime_runtime = new WeakMap(), _Runtime_comHub = new WeakMap(), _Runtime_difHandler = new WeakMap(), _Runtime_instances = new WeakSet(), _Runtime_executeInternal = async function _Runtime_executeInternal(datexScript, values = []) {
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=devtools-formatter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"devtools-formatter.d.ts","sourceRoot":"","sources":["../../src/utils/devtools-formatter.ts"],"names":[],"mappings":""}
@@ -0,0 +1,40 @@
1
+ import { Endpoint } from "../lib/special-core-types/endpoint.js";
2
+ import { Ref } from "../refs/ref.js";
3
+ // @ts-ignore devtoolsFormatters
4
+ globalThis.devtoolsFormatters = [
5
+ {
6
+ header(obj) {
7
+ if (obj instanceof Endpoint) {
8
+ return ["span", { style: "color: #58d452" }, obj.toString()];
9
+ }
10
+ else if (obj instanceof Ref) {
11
+ return [
12
+ "span",
13
+ {},
14
+ [
15
+ "span",
16
+ {},
17
+ [
18
+ "span",
19
+ { style: "color: #1279d5" },
20
+ "&mut ",
21
+ ],
22
+ [
23
+ "span",
24
+ {},
25
+ // TODO: only proof of concept, syntax highlighting does not match JS
26
+ obj.value,
27
+ ],
28
+ ],
29
+ ];
30
+ }
31
+ return null; // fall back to default
32
+ },
33
+ hasBody(_) {
34
+ return false;
35
+ },
36
+ body(_) {
37
+ return null;
38
+ },
39
+ },
40
+ ];
@@ -0,0 +1,4 @@
1
+ export declare function panic(message?: string): never;
2
+ export declare function unreachable(message?: string): never;
3
+ export declare function unimplemented(message?: string): never;
4
+ //# sourceMappingURL=exceptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exceptions.d.ts","sourceRoot":"","sources":["../../src/utils/exceptions.ts"],"names":[],"mappings":"AAAA,wBAAgB,KAAK,CAAC,OAAO,GAAE,MAAkB,GAAG,KAAK,CAExD;AAED,wBAAgB,WAAW,CAAC,OAAO,GAAE,MAAkB,GAAG,KAAK,CAE9D;AAED,wBAAgB,aAAa,CAAC,OAAO,GAAE,MAAkB,GAAG,KAAK,CAEhE"}
@@ -0,0 +1,9 @@
1
+ export function panic(message = "unknown") {
2
+ throw new Error(`Panic: ${message}`);
3
+ }
4
+ export function unreachable(message = "unknown") {
5
+ throw new Error(`Unreachable code reached: ${message}`);
6
+ }
7
+ export function unimplemented(message = "unknown") {
8
+ throw new Error(`Not implemented: ${message}`);
9
+ }