@unyt/datex 0.0.13 → 0.0.15

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 (147) hide show
  1. package/esm/datex-web/datex_web.d.ts +93 -2
  2. package/esm/datex-web/datex_web.internal.d.ts +221 -188
  3. package/esm/datex-web/datex_web.internal.d.ts.map +1 -1
  4. package/esm/datex-web/datex_web.internal.js +453 -385
  5. package/esm/datex-web/datex_web.wasm +0 -0
  6. package/esm/datex-web/types/decompiler/options.d.ts +17 -0
  7. package/esm/datex-web/types/decompiler/options.d.ts.map +1 -0
  8. package/esm/datex-web/types/decompiler/options.js +4 -0
  9. package/esm/datex-web/types/disassembler/options.d.ts +6 -0
  10. package/esm/datex-web/types/disassembler/options.d.ts.map +1 -0
  11. package/esm/datex-web/types/disassembler/options.js +4 -0
  12. package/esm/datex-web/types/network/com_hub/managers/socket_manager.d.ts +9 -0
  13. package/esm/datex-web/types/network/com_hub/managers/socket_manager.d.ts.map +1 -0
  14. package/esm/datex-web/types/network/com_hub/managers/socket_manager.js +4 -0
  15. package/esm/datex-web/types/network/com_hub/metadata.d.ts +20 -0
  16. package/esm/datex-web/types/network/com_hub/metadata.d.ts.map +1 -0
  17. package/esm/datex-web/types/network/com_hub/metadata.js +4 -0
  18. package/esm/datex-web/types/network/com_hub/mod.d.ts +6 -0
  19. package/esm/datex-web/types/network/com_hub/mod.d.ts.map +1 -0
  20. package/esm/datex-web/types/network/com_hub/mod.js +4 -0
  21. package/esm/datex-web/types/network/com_hub/network_tracing.d.ts +23 -0
  22. package/esm/datex-web/types/network/com_hub/network_tracing.d.ts.map +1 -0
  23. package/esm/datex-web/types/network/com_hub/network_tracing.js +4 -0
  24. package/esm/datex-web/types/network/com_hub.d.ts +8 -0
  25. package/esm/datex-web/types/network/com_hub.d.ts.map +1 -0
  26. package/esm/datex-web/types/network/com_hub.js +4 -0
  27. package/esm/datex-web/types/network/com_interfaces/com_interface/properties.d.ts +27 -0
  28. package/esm/datex-web/types/network/com_interfaces/com_interface/properties.d.ts.map +1 -0
  29. package/esm/datex-web/types/network/com_interfaces/com_interface/properties.js +4 -0
  30. package/esm/datex-web/types/network/com_interfaces/default_setup_data/http_common.d.ts +10 -0
  31. package/esm/datex-web/types/network/com_interfaces/default_setup_data/http_common.d.ts.map +1 -0
  32. package/esm/datex-web/types/network/com_interfaces/default_setup_data/http_common.js +4 -0
  33. package/esm/datex-web/types/network/com_interfaces/default_setup_data/websocket/websocket_server.d.ts +6 -0
  34. package/esm/datex-web/types/network/com_interfaces/default_setup_data/websocket/websocket_server.d.ts.map +1 -0
  35. package/esm/datex-web/types/network/com_interfaces/default_setup_data/websocket/websocket_server.js +4 -0
  36. package/esm/datex-web/types/runtime/config.d.ts +16 -0
  37. package/esm/datex-web/types/runtime/config.d.ts.map +1 -0
  38. package/esm/datex-web/types/runtime/config.js +4 -0
  39. package/esm/default.d.ts.map +1 -1
  40. package/esm/default.js +2 -0
  41. package/esm/deno.json +73 -17
  42. package/esm/dif/core.d.ts +36 -39
  43. package/esm/dif/core.d.ts.map +1 -1
  44. package/esm/dif/core.js +33 -53
  45. package/esm/dif/dif-handler.d.ts +58 -101
  46. package/esm/dif/dif-handler.d.ts.map +1 -1
  47. package/esm/dif/dif-handler.js +417 -345
  48. package/esm/dif/display.d.ts +14 -5
  49. package/esm/dif/display.d.ts.map +1 -1
  50. package/esm/dif/display.js +89 -39
  51. package/esm/dif/helpers/mod.d.ts +6 -0
  52. package/esm/dif/helpers/mod.d.ts.map +1 -0
  53. package/esm/dif/helpers/mod.js +5 -0
  54. package/esm/dif/helpers/typed-integer.d.ts +14 -0
  55. package/esm/dif/helpers/typed-integer.d.ts.map +1 -0
  56. package/esm/dif/helpers/typed-integer.js +37 -0
  57. package/esm/dif/js-lib.d.ts +14 -1
  58. package/esm/dif/js-lib.d.ts.map +1 -1
  59. package/esm/dif/js-lib.js +19 -1
  60. package/esm/dif/mod.d.ts +2 -2
  61. package/esm/dif/mod.d.ts.map +1 -1
  62. package/esm/dif/mod.js +2 -2
  63. package/esm/dif/type-registry.d.ts +30 -21
  64. package/esm/dif/type-registry.d.ts.map +1 -1
  65. package/esm/dif/type-registry.js +45 -33
  66. package/esm/dif/types/mod.d.ts +9 -0
  67. package/esm/dif/types/mod.d.ts.map +1 -0
  68. package/esm/dif/types/mod.js +8 -0
  69. package/esm/dif/types/type.d.ts +91 -0
  70. package/esm/dif/types/type.d.ts.map +1 -0
  71. package/esm/dif/types/type.js +33 -0
  72. package/esm/dif/types/update.d.ts +63 -0
  73. package/esm/dif/types/update.d.ts.map +1 -0
  74. package/esm/dif/types/update.js +16 -0
  75. package/esm/dif/types/value.d.ts +62 -0
  76. package/esm/dif/types/value.d.ts.map +1 -0
  77. package/esm/dif/types/value.js +1 -0
  78. package/esm/dif/update.d.ts +20 -0
  79. package/esm/dif/update.d.ts.map +1 -0
  80. package/esm/dif/update.js +41 -0
  81. package/esm/dif/utils.d.ts +8 -0
  82. package/esm/dif/utils.d.ts.map +1 -0
  83. package/esm/dif/utils.js +67 -0
  84. package/esm/lib/js-core-types/array.d.ts +3 -0
  85. package/esm/lib/js-core-types/array.d.ts.map +1 -0
  86. package/esm/lib/js-core-types/array.js +175 -0
  87. package/esm/lib/js-core-types/map.d.ts +15 -0
  88. package/esm/lib/js-core-types/map.d.ts.map +1 -0
  89. package/esm/lib/js-core-types/map.js +88 -0
  90. package/esm/lib/js-core-types/mod.d.ts +8 -0
  91. package/esm/lib/js-core-types/mod.d.ts.map +1 -0
  92. package/esm/lib/js-core-types/mod.js +7 -0
  93. package/esm/lib/mod.d.ts +8 -0
  94. package/esm/lib/mod.d.ts.map +1 -0
  95. package/esm/lib/mod.js +7 -0
  96. package/esm/lib/special-core-types/endpoint.d.ts.map +1 -1
  97. package/esm/lib/special-core-types/mod.d.ts +9 -0
  98. package/esm/lib/special-core-types/mod.d.ts.map +1 -0
  99. package/esm/lib/special-core-types/mod.js +8 -0
  100. package/esm/lib/special-core-types/range.d.ts +26 -0
  101. package/esm/lib/special-core-types/range.d.ts.map +1 -0
  102. package/esm/lib/special-core-types/range.js +46 -0
  103. package/esm/lib/special-core-types/tagged.d.ts +17 -0
  104. package/esm/lib/special-core-types/tagged.d.ts.map +1 -0
  105. package/esm/lib/special-core-types/tagged.js +37 -0
  106. package/esm/lib/special-core-types/undefined.d.ts +7 -0
  107. package/esm/lib/special-core-types/undefined.d.ts.map +1 -0
  108. package/esm/lib/special-core-types/undefined.js +28 -0
  109. package/esm/mod.d.ts +3 -1
  110. package/esm/mod.d.ts.map +1 -1
  111. package/esm/mod.js +3 -1
  112. package/esm/network/com-hub.d.ts +28 -1
  113. package/esm/network/com-hub.d.ts.map +1 -1
  114. package/esm/network/com-hub.js +6 -2
  115. package/esm/network/interfaces/websocket-server-base.d.ts +1 -1
  116. package/esm/network/interfaces/websocket-server-base.d.ts.map +1 -1
  117. package/esm/network/interfaces/websocket-server-base.js +8 -7
  118. package/esm/network/interfaces/websocket-server-deno.d.ts +1 -1
  119. package/esm/network/interfaces/websocket-server-deno.d.ts.map +1 -1
  120. package/esm/repl/mod.d.ts +8 -0
  121. package/esm/repl/mod.d.ts.map +1 -0
  122. package/esm/repl/mod.js +31 -0
  123. package/esm/runtime/runtime.d.ts +43 -18
  124. package/esm/runtime/runtime.d.ts.map +1 -1
  125. package/esm/runtime/runtime.js +55 -32
  126. package/esm/{refs/ref.d.ts → shared-container/base-shared-container.d.ts} +13 -5
  127. package/esm/shared-container/base-shared-container.d.ts.map +1 -0
  128. package/esm/shared-container/base-shared-container.js +95 -0
  129. package/esm/shared-container/mod.d.ts +36 -0
  130. package/esm/shared-container/mod.d.ts.map +1 -0
  131. package/esm/shared-container/mod.js +29 -0
  132. package/esm/shared-container/owned.d.ts +33 -0
  133. package/esm/shared-container/owned.d.ts.map +1 -0
  134. package/esm/shared-container/owned.js +60 -0
  135. package/esm/shared-container/reference.d.ts +31 -0
  136. package/esm/shared-container/reference.d.ts.map +1 -0
  137. package/esm/shared-container/reference.js +64 -0
  138. package/esm/utils/devtools-formatter.js +24 -2
  139. package/esm/utils/option.d.ts +17 -0
  140. package/esm/utils/option.d.ts.map +1 -0
  141. package/esm/utils/option.js +54 -0
  142. package/package.json +1 -1
  143. package/esm/dif/definitions.d.ts +0 -134
  144. package/esm/dif/definitions.d.ts.map +0 -1
  145. package/esm/dif/definitions.js +0 -38
  146. package/esm/refs/ref.d.ts.map +0 -1
  147. package/esm/refs/ref.js +0 -60
@@ -1 +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"}
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,EAAuB,MAAM,eAAe,CAAC;AAE9E,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,+FAA+F,CAAC;AAGvJ;;;GAGG;AACH,wBAAgB,wCAAwC,CACpD,aAAa,EAAE,CAAC,SAAS,EAAE,iCAAiC,KAAK,cAAc,CAAC,SAAS,CAAC,GAC3F,mBAAmB,CAAC,iCAAiC,CAAC,CAgDxD"}
@@ -1,3 +1,5 @@
1
+ import { tagged } from "../../lib/special-core-types/tagged.js";
2
+ import { DIFHandler } from "../../dif/dif-handler.js";
1
3
  /**
2
4
  * Utility function to create a WebSocket server communication interface factory from a given server factory function.
3
5
  * @param serverFactory
@@ -15,13 +17,13 @@ export function createWebsocketServerComInterfaceFactory(serverFactory) {
15
17
  interface_type: "websocket-server",
16
18
  channel: "websocket",
17
19
  name: setupData.bind_address,
18
- direction: "InOut",
20
+ direction: tagged("InOut"),
19
21
  round_trip_time: 0,
20
22
  max_bandwidth: 0,
21
23
  continuous_connection: false,
22
24
  allow_redirects: false,
23
25
  is_secure_channel: false,
24
- reconnection_config: "NoReconnect",
26
+ reconnection_config: tagged("NoReconnect"),
25
27
  auto_identify: true,
26
28
  connectable_interfaces: [], // TODO add websocket client connections
27
29
  },
@@ -30,12 +32,11 @@ export function createWebsocketServerComInterfaceFactory(serverFactory) {
30
32
  async transform(socket, controller) {
31
33
  const incoming_data_stream = await createSocketDataIterator(socket);
32
34
  controller.enqueue({
33
- properties: {
34
- direction: "InOut",
35
+ properties: DIFHandler.convertJSValueToDIFValueContainer({
36
+ direction: tagged("InOut"),
35
37
  channel_factor: 1,
36
- connection_timestamp: Date.now(),
37
- direct_endpoint: undefined,
38
- },
38
+ direct_endpoint: null,
39
+ }),
39
40
  iterator: incoming_data_stream,
40
41
  send_callback: (data) => {
41
42
  socket.send(data);
@@ -1,4 +1,4 @@
1
- import type { WebSocketServerInterfaceSetupData } from "../../datex.js";
1
+ import type { WebSocketServerInterfaceSetupData } from "../../datex-web/types/network/com_interfaces/default_setup_data/websocket/websocket_server.js";
2
2
  import type { ComInterfaceFactory } from "../com-hub.js";
3
3
  export declare const websocketServerDenoComInterfaceFactory: ComInterfaceFactory<WebSocketServerInterfaceSetupData>;
4
4
  //# sourceMappingURL=websocket-server-deno.d.ts.map
@@ -1 +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"}
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,+FAA+F,CAAC;AAGvJ,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AA4BzD,eAAO,MAAM,sCAAsC,EAAE,mBAAmB,CAAC,iCAAiC,CAC3C,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { Runtime } from "../runtime/runtime.js";
2
+ export declare class Repl {
3
+ #private;
4
+ private runtime;
5
+ constructor(runtime: Runtime, verbose?: boolean);
6
+ execute(script: string): Promise<string>;
7
+ }
8
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/repl/mod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAErD,qBAAa,IAAI;;IAED,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,OAAO,EAAE,OAAO,UAAQ;IAIxC,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAKxD"}
@@ -0,0 +1,31 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _Repl_repl;
13
+ import { Repl as ReplInternal } from "../datex.js";
14
+ export class Repl {
15
+ constructor(runtime, verbose = false) {
16
+ Object.defineProperty(this, "runtime", {
17
+ enumerable: true,
18
+ configurable: true,
19
+ writable: true,
20
+ value: runtime
21
+ });
22
+ _Repl_repl.set(this, void 0);
23
+ __classPrivateFieldSet(this, _Repl_repl, new ReplInternal(runtime._runtime, verbose), "f");
24
+ }
25
+ async execute(script) {
26
+ const result = await __classPrivateFieldGet(this, _Repl_repl, "f").execute(script);
27
+ const jsValue = this.runtime.dif.resolveDIFValueContainer(result);
28
+ return this.runtime.valueToString(jsValue);
29
+ }
30
+ }
31
+ _Repl_repl = new WeakMap();
@@ -1,15 +1,19 @@
1
- import { type DecompileOptions, type JSRuntime } from "../datex.js";
1
+ import { type JSRuntime } from "../datex.js";
2
2
  import { ComHub } from "../network/com-hub.js";
3
- import { DIFHandler, type PointerOut } from "../dif/dif-handler.js";
4
- import type { DIFSharedValueMutability, DIFTypeDefinition } from "../dif/definitions.js";
5
- import type { Ref } from "../refs/ref.js";
3
+ import { DIFHandler } from "../dif/dif-handler.js";
4
+ import { type AsSharedMaybeOwned, SharedContainerMutability } from "../shared-container/mod.js";
5
+ import type { FlatInstruction, InstructionTree } from "./types";
6
+ import type { DIFTypeDefinition } from "../dif/types/mod.js";
7
+ import { Endpoint } from "../lib/mod.js";
8
+ import type { DisassemblerOptions } from "../datex-web/types/disassembler/options.js";
9
+ import type { DecompileOptions } from "../datex-web/types/decompiler/options.js";
6
10
  /** debug flags for the runtime */
7
11
  interface DebugConfig {
8
12
  log_level?: "error" | "warn" | "info" | "debug" | "trace" | null;
9
13
  }
10
14
  /** configuration for the runtime */
11
15
  export type RuntimeConfig = {
12
- endpoint?: string;
16
+ endpoint: Endpoint;
13
17
  interfaces?: {
14
18
  type: string;
15
19
  config: unknown;
@@ -33,7 +37,7 @@ export declare class Runtime {
33
37
  /**
34
38
  * Gets the endpoint of the runtime.
35
39
  */
36
- get endpoint(): string;
40
+ get endpoint(): Endpoint;
37
41
  /**
38
42
  * Gets the version of the runtime.
39
43
  */
@@ -86,7 +90,7 @@ export declare class Runtime {
86
90
  * console.log(result); // 42
87
91
  * ```
88
92
  */
89
- execute<T = unknown>(templateStrings: TemplateStringsArray, ...values: unknown[]): Promise<T>;
93
+ execute<T = unknown>(templateStrings: TemplateStringsArray, ...values: unknown[]): Promise<T | undefined>;
90
94
  /**
91
95
  * Executes a Datex script synchronously and returns the result as a generic type T.
92
96
  * Injected values can be passed as an array in `values`.
@@ -108,6 +112,19 @@ export declare class Runtime {
108
112
  * ```
109
113
  */
110
114
  executeSync<T = unknown>(templateStrings: TemplateStringsArray, ...values: unknown[]): T;
115
+ /**
116
+ * Compiles a DATEX source code and optional injected values to a DXB body
117
+ */
118
+ compile(datexScript: string, values?: unknown[]): Promise<Uint8Array>;
119
+ /**
120
+ * Compiles a DATEX source code and optional injected values to a DXB body.
121
+ * Injected values can be passed to the template string.
122
+ * Example usage:
123
+ * ```ts
124
+ * const dxb = await runtime.compile<number>`1 + ${41}`;
125
+ * ```
126
+ */
127
+ compile(templateStrings: TemplateStringsArray, ...values: unknown[]): Promise<Uint8Array>;
111
128
  /**
112
129
  * Converts a JavaScript value to a string representation.
113
130
  * @param value The value to convert.
@@ -116,7 +133,7 @@ export declare class Runtime {
116
133
  */
117
134
  valueToString(value: unknown, decompileOptions?: DecompileOptions | null): string;
118
135
  /**
119
- * Creates a new reference containg the given JS value.
136
+ * Creates a new reference containing the given JS value.
120
137
  * For primitive values, a Ref wrapper is returned.
121
138
  * For other values (objects, arrays, maps), the returned value is a proxy object that behaves like the original object.
122
139
  *
@@ -125,18 +142,26 @@ export declare class Runtime {
125
142
  * @param mutability Optional mutability of the reference (default is Mutable).
126
143
  * @returns A proxy object representing the pointer in JS.
127
144
  */
128
- createTransparentReference<V, M extends DIFSharedValueMutability = typeof DIFSharedValueMutability.Mutable>(value: V & {}, allowedType?: DIFTypeDefinition | null, mutability?: M): PointerOut<V, M>;
145
+ createSharedValueFromJSValue<V, M extends SharedContainerMutability = SharedContainerMutability.Mutable>(value: V, allowedType?: DIFTypeDefinition | null, mutability?: M): AsSharedMaybeOwned<V, M>;
146
+ startLSP(callback: (data: string) => void): (data: string) => void;
129
147
  /**
130
- * Creates or retrieves a wrapped reference for the given value.
131
- * If the value is already a reference, it returns the existing reference.
132
- *
133
- * @param value
134
- * @param allowedType
135
- * @param mutability
136
- * @returns
148
+ * Returns a disassembled DXB as a list of instructions
149
+ * @param dxb DATEX binary body
150
+ * @returns a tuple of the instruction tree and an optional error message if the disassembly (partially) failed
137
151
  */
138
- createOrGetWrappedReference<V, M extends DIFSharedValueMutability = typeof DIFSharedValueMutability.Mutable>(_value: V, _allowedType?: DIFTypeDefinition | null, _mutability?: M): Ref<V>;
139
- startLSP(callback: (data: string) => void): (data: string) => void;
152
+ disassembleDXBFlat(dxb: Uint8Array): [FlatInstruction[], string | null];
153
+ /**
154
+ * Returns a disassembled DXB as a tree structure, where each instruction can have nested child instructions
155
+ * @param dxb DATEX binary body
156
+ * @returns a tuple of the instruction tree and an optional error message if the disassembly (partially) failed
157
+ */
158
+ disassembleDXBTree(dxb: Uint8Array): [InstructionTree, string | null];
159
+ /**
160
+ * Returns a disassembled DXB as a human-readable string, similar to assembly code.
161
+ * @param dxb
162
+ * @param options
163
+ */
164
+ disassembleDXBToString(dxb: Uint8Array, options?: DisassemblerOptions | null): string;
140
165
  }
141
166
  export {};
142
167
  //# sourceMappingURL=runtime.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/runtime/runtime.ts"],"names":[],"mappings":"A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? 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 _Runtime_instances, _Runtime_runtime, _Runtime_comHub, _Runtime_difHandler, _Runtime_executeInternal, _Runtime_executeSyncInternal, _Runtime_getScriptAndValues;
13
- import { create_runtime } from "../datex.js";
12
+ var _Runtime_instances, _Runtime_runtime, _Runtime_comHub, _Runtime_difHandler, _Runtime_executeWithNormalizedArguments, _Runtime_executeSyncWithNormalizedArguments, _Runtime_normalizeArguments;
13
+ import { create_runtime, disassemble_dxb_flat, disassemble_dxb_to_string, disassemble_dxb_tree, } 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";
16
+ import { SharedContainerMutability } from "../shared-container/mod.js";
17
+ import { Endpoint } from "../lib/mod.js";
17
18
  // TODO: move to global.ts
18
19
  /** auto-generated version - do not edit: */
19
- const VERSION = "0.0.13";
20
+ const VERSION = "0.0.15";
20
21
  /**
21
22
  * The main Runtime class for executing Datex scripts and managing communication interfaces.
22
23
  */
@@ -52,7 +53,7 @@ export class Runtime {
52
53
  * Gets the endpoint of the runtime.
53
54
  */
54
55
  get endpoint() {
55
- return __classPrivateFieldGet(this, _Runtime_runtime, "f").endpoint;
56
+ return Endpoint.get(__classPrivateFieldGet(this, _Runtime_runtime, "f").endpoint);
56
57
  }
57
58
  /**
58
59
  * Gets the version of the runtime.
@@ -99,13 +100,17 @@ export class Runtime {
99
100
  return __classPrivateFieldGet(this, _Runtime_runtime, "f").execute_sync_with_string_result(datexScript, __classPrivateFieldGet(this, _Runtime_difHandler, "f").convertToDIFValues(values), decompileOptions);
100
101
  }
101
102
  execute(datexScriptOrTemplateStrings, ...values) {
102
- const { datexScript, valuesArray } = __classPrivateFieldGet(this, _Runtime_instances, "m", _Runtime_getScriptAndValues).call(this, datexScriptOrTemplateStrings, ...values);
103
- return __classPrivateFieldGet(this, _Runtime_instances, "m", _Runtime_executeInternal).call(this, datexScript, valuesArray);
103
+ const { datexScript, valuesArray } = __classPrivateFieldGet(this, _Runtime_instances, "m", _Runtime_normalizeArguments).call(this, datexScriptOrTemplateStrings, ...values);
104
+ return __classPrivateFieldGet(this, _Runtime_instances, "m", _Runtime_executeWithNormalizedArguments).call(this, datexScript, valuesArray);
104
105
  }
105
106
  executeSync(datexScriptOrTemplateStrings, ...values) {
106
107
  // determine datexScript and valuesArray based on the type of datexScriptOrTemplateStrings
107
- const { datexScript, valuesArray } = __classPrivateFieldGet(this, _Runtime_instances, "m", _Runtime_getScriptAndValues).call(this, datexScriptOrTemplateStrings, ...values);
108
- return __classPrivateFieldGet(this, _Runtime_instances, "m", _Runtime_executeSyncInternal).call(this, datexScript, valuesArray);
108
+ const { datexScript, valuesArray } = __classPrivateFieldGet(this, _Runtime_instances, "m", _Runtime_normalizeArguments).call(this, datexScriptOrTemplateStrings, ...values);
109
+ return __classPrivateFieldGet(this, _Runtime_instances, "m", _Runtime_executeSyncWithNormalizedArguments).call(this, datexScript, valuesArray);
110
+ }
111
+ compile(datexScriptOrTemplateStrings, ...values) {
112
+ const { datexScript, valuesArray } = __classPrivateFieldGet(this, _Runtime_instances, "m", _Runtime_normalizeArguments).call(this, datexScriptOrTemplateStrings, ...values);
113
+ return __classPrivateFieldGet(this, _Runtime_runtime, "f").compile(datexScript, valuesArray);
109
114
  }
110
115
  /**
111
116
  * Converts a JavaScript value to a string representation.
@@ -114,10 +119,10 @@ export class Runtime {
114
119
  * @returns The string representation of the value.
115
120
  */
116
121
  valueToString(value, decompileOptions = null) {
117
- return __classPrivateFieldGet(this, _Runtime_runtime, "f").value_to_string(__classPrivateFieldGet(this, _Runtime_difHandler, "f").convertJSValueToDIFValueContainer(value), decompileOptions);
122
+ return __classPrivateFieldGet(this, _Runtime_runtime, "f").value_to_string(__classPrivateFieldGet(this, _Runtime_difHandler, "f").convertJSValueToDIFValueContainer(value), __classPrivateFieldGet(this, _Runtime_difHandler, "f").convertJSValueToDIFValueContainer(decompileOptions));
118
123
  }
119
124
  /**
120
- * Creates a new reference containg the given JS value.
125
+ * Creates a new reference containing the given JS value.
121
126
  * For primitive values, a Ref wrapper is returned.
122
127
  * For other values (objects, arrays, maps), the returned value is a proxy object that behaves like the original object.
123
128
  *
@@ -126,22 +131,8 @@ export class Runtime {
126
131
  * @param mutability Optional mutability of the reference (default is Mutable).
127
132
  * @returns A proxy object representing the pointer in JS.
128
133
  */
129
- createTransparentReference(
130
- // deno-lint-ignore ban-types
131
- value, allowedType, mutability) {
132
- return __classPrivateFieldGet(this, _Runtime_difHandler, "f").createTransparentReference(value, allowedType, mutability);
133
- }
134
- /**
135
- * Creates or retrieves a wrapped reference for the given value.
136
- * If the value is already a reference, it returns the existing reference.
137
- *
138
- * @param value
139
- * @param allowedType
140
- * @param mutability
141
- * @returns
142
- */
143
- createOrGetWrappedReference(_value, _allowedType, _mutability) {
144
- unimplemented();
134
+ createSharedValueFromJSValue(value, allowedType = null, mutability = SharedContainerMutability.Mutable) {
135
+ return __classPrivateFieldGet(this, _Runtime_difHandler, "f").createSharedValueFromJSValue(value, allowedType, mutability);
145
136
  }
146
137
  startLSP(callback) {
147
138
  const decoder = new TextDecoder("utf-8");
@@ -153,16 +144,48 @@ export class Runtime {
153
144
  sendToRust(encoder.encode(data));
154
145
  };
155
146
  }
147
+ /**
148
+ * Returns a disassembled DXB as a list of instructions
149
+ * @param dxb DATEX binary body
150
+ * @returns a tuple of the instruction tree and an optional error message if the disassembly (partially) failed
151
+ */
152
+ disassembleDXBFlat(dxb) {
153
+ return disassemble_dxb_flat(dxb);
154
+ }
155
+ /**
156
+ * Returns a disassembled DXB as a tree structure, where each instruction can have nested child instructions
157
+ * @param dxb DATEX binary body
158
+ * @returns a tuple of the instruction tree and an optional error message if the disassembly (partially) failed
159
+ */
160
+ disassembleDXBTree(dxb) {
161
+ return disassemble_dxb_tree(dxb);
162
+ }
163
+ /**
164
+ * Returns a disassembled DXB as a human-readable string, similar to assembly code.
165
+ * @param dxb
166
+ * @param options
167
+ */
168
+ disassembleDXBToString(dxb, options) {
169
+ return disassemble_dxb_to_string(dxb, options);
170
+ }
156
171
  }
157
- _Runtime_runtime = new WeakMap(), _Runtime_comHub = new WeakMap(), _Runtime_difHandler = new WeakMap(), _Runtime_instances = new WeakSet(), _Runtime_executeInternal = async function _Runtime_executeInternal(datexScript, values = []) {
172
+ _Runtime_runtime = new WeakMap(), _Runtime_comHub = new WeakMap(), _Runtime_difHandler = new WeakMap(), _Runtime_instances = new WeakSet(), _Runtime_executeWithNormalizedArguments =
173
+ /**
174
+ * Execute a DATEX script with injected values and return the result as a Promise of type T.
175
+ * The result is converted to a JS value. If the script returns no value, it will return `undefined`.
176
+ * @param datexScript The DATEX script to execute.
177
+ * @param values The values to inject into the script, passed as an array.
178
+ * @returns A Promise that resolves to the result of the script execution, converted to type T.
179
+ */
180
+ async function _Runtime_executeWithNormalizedArguments(datexScript, values = []) {
158
181
  const difValueContainer = await __classPrivateFieldGet(this, _Runtime_difHandler, "f").executeDIF(datexScript, values);
159
- if (difValueContainer === null) {
182
+ if (difValueContainer === undefined) {
160
183
  return undefined;
161
184
  }
162
185
  return __classPrivateFieldGet(this, _Runtime_difHandler, "f").resolveDIFValueContainer(difValueContainer);
163
- }, _Runtime_executeSyncInternal = function _Runtime_executeSyncInternal(datexScript, values = []) {
186
+ }, _Runtime_executeSyncWithNormalizedArguments = function _Runtime_executeSyncWithNormalizedArguments(datexScript, values = []) {
164
187
  const difValue = __classPrivateFieldGet(this, _Runtime_difHandler, "f").executeSyncDIF(datexScript, values);
165
- if (difValue === null) {
188
+ if (difValue === undefined) {
166
189
  return undefined;
167
190
  }
168
191
  const result = __classPrivateFieldGet(this, _Runtime_difHandler, "f").resolveDIFValueContainer(difValue);
@@ -170,7 +193,7 @@ _Runtime_runtime = new WeakMap(), _Runtime_comHub = new WeakMap(), _Runtime_difH
170
193
  throw new Error("executeSync cannot return a Promise. Use execute() instead.");
171
194
  }
172
195
  return result;
173
- }, _Runtime_getScriptAndValues = function _Runtime_getScriptAndValues(datexScriptOrTemplateStrings, ...values) {
196
+ }, _Runtime_normalizeArguments = function _Runtime_normalizeArguments(datexScriptOrTemplateStrings, ...values) {
174
197
  let datexScript;
175
198
  let valuesArray;
176
199
  if (typeof datexScriptOrTemplateStrings === "string") {
@@ -1,15 +1,21 @@
1
1
  import type { DIFHandler } from "../dif/dif-handler.js";
2
+ import { DIFSharedContainerOwnership } from "../dif/types/mod.js";
3
+ import { type PointerAddress, type SharedContainer } from "./mod.js";
4
+ export declare enum SharedContainerMutability {
5
+ Immutable = 0,
6
+ Mutable = 1
7
+ }
2
8
  /**
3
9
  * The Ref class is a wrapper around a value that is stored in a pointer.
4
10
  * Primitive values (string, number, boolean, null) are always wrapped in a Ref when stored in a pointer.
5
11
  */
6
- export declare class Ref<T> {
12
+ export declare class BaseSharedContainer<T, Mutability extends SharedContainerMutability> {
7
13
  #private;
8
- constructor(value: T, pointerAddress: string, difHandler: DIFHandler);
14
+ constructor(value: T, pointerAddress: PointerAddress, mutability: Mutability, difHandler: DIFHandler);
9
15
  /**
10
16
  * Gets the address of the pointer storing the reference.
11
17
  */
12
- get pointerAddress(): string;
18
+ get pointerAddress(): PointerAddress;
13
19
  /**
14
20
  * Silently updates the value of the reference without notifying observers.
15
21
  * This should only be used internally.
@@ -25,6 +31,8 @@ export declare class Ref<T> {
25
31
  * Also notifies all observers of the pointer about the change.
26
32
  * @throws If the reference is immutable or the new value is of an incompatible type.
27
33
  */
28
- set value(newValue: T);
34
+ set value(newValue: Mutability extends SharedContainerMutability.Mutable ? T : never);
35
+ isContainerMutable(): this is BaseSharedContainer<T, typeof SharedContainerMutability.Mutable>;
36
+ withOwnership<Ownership extends DIFSharedContainerOwnership>(ownership: Ownership): SharedContainer<T, Mutability>;
29
37
  }
30
- //# sourceMappingURL=ref.d.ts.map
38
+ //# sourceMappingURL=base-shared-container.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-shared-container.d.ts","sourceRoot":"","sources":["../../src/shared-container/base-shared-container.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAwB,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,MAAM,UAAU,CAAC;AAG3F,oBAAY,yBAAyB;IACjC,SAAS,IAAI;IACb,OAAO,IAAI;CACd;AAED;;;GAGG;AACH,qBAAa,mBAAmB,CAAC,CAAC,EAAE,UAAU,SAAS,yBAAyB;;gBAMhE,KAAK,EAAE,CAAC,EAAE,cAAc,EAAE,cAAc,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAOpG;;OAEG;IACH,IAAW,cAAc,IAAI,cAAc,CAE1C;IAED;;;;OAIG;IACH,mBAAmB,CAAC,QAAQ,EAAE,CAAC;IAI/B;;OAEG;IACH,IAAW,KAAK,IAAI,CAAC,CAEpB;IAED;;;;OAIG;IACH,IAAI,KAAK,CAAC,QAAQ,EAAE,UAAU,SAAS,yBAAyB,CAAC,OAAO,GAAG,CAAC,GAAG,KAAK,EAWnF;IAEM,kBAAkB,IAAI,IAAI,IAAI,mBAAmB,CAAC,CAAC,EAAE,OAAO,yBAAyB,CAAC,OAAO,CAAC;IAI9F,aAAa,CAAC,SAAS,SAAS,2BAA2B,EAC9D,SAAS,EAAE,SAAS,GACrB,eAAe,CAAC,CAAC,EAAE,UAAU,CAAC;CAepC"}
@@ -0,0 +1,95 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _BaseSharedContainer_value, _BaseSharedContainer_pointerAddress, _BaseSharedContainer_difHandler, _BaseSharedContainer_containerMutability;
13
+ import { DIFSharedContainerOwnership } from "../dif/types/mod.js";
14
+ import { OwnedSharedContainer } from "./mod.js";
15
+ import { ReferencedSharedContainer } from "./reference.js";
16
+ export var SharedContainerMutability;
17
+ (function (SharedContainerMutability) {
18
+ SharedContainerMutability[SharedContainerMutability["Immutable"] = 0] = "Immutable";
19
+ SharedContainerMutability[SharedContainerMutability["Mutable"] = 1] = "Mutable";
20
+ })(SharedContainerMutability || (SharedContainerMutability = {}));
21
+ /**
22
+ * The Ref class is a wrapper around a value that is stored in a pointer.
23
+ * Primitive values (string, number, boolean, null) are always wrapped in a Ref when stored in a pointer.
24
+ */
25
+ export class BaseSharedContainer {
26
+ constructor(value, pointerAddress, mutability, difHandler) {
27
+ _BaseSharedContainer_value.set(this, void 0);
28
+ _BaseSharedContainer_pointerAddress.set(this, void 0);
29
+ _BaseSharedContainer_difHandler.set(this, void 0);
30
+ _BaseSharedContainer_containerMutability.set(this, void 0);
31
+ __classPrivateFieldSet(this, _BaseSharedContainer_value, value, "f");
32
+ __classPrivateFieldSet(this, _BaseSharedContainer_pointerAddress, pointerAddress, "f");
33
+ __classPrivateFieldSet(this, _BaseSharedContainer_containerMutability, mutability, "f");
34
+ __classPrivateFieldSet(this, _BaseSharedContainer_difHandler, difHandler, "f");
35
+ }
36
+ /**
37
+ * Gets the address of the pointer storing the reference.
38
+ */
39
+ get pointerAddress() {
40
+ return __classPrivateFieldGet(this, _BaseSharedContainer_pointerAddress, "f");
41
+ }
42
+ /**
43
+ * Silently updates the value of the reference without notifying observers.
44
+ * This should only be used internally.
45
+ * @param newValue - The new value to set.
46
+ */
47
+ updateValueSilently(newValue) {
48
+ __classPrivateFieldSet(this, _BaseSharedContainer_value, newValue, "f");
49
+ }
50
+ /**
51
+ * Gets the current value of the reference.
52
+ */
53
+ get value() {
54
+ return __classPrivateFieldGet(this, _BaseSharedContainer_value, "f");
55
+ }
56
+ /**
57
+ * Replaces the current value of the reference with a new value.
58
+ * Also notifies all observers of the pointer about the change.
59
+ * @throws If the reference is immutable or the new value is of an incompatible type.
60
+ */
61
+ set value(newValue) {
62
+ if (!this.isContainerMutable()) {
63
+ throw new Error("Cannot set value of an immutable reference.");
64
+ }
65
+ const oldValue = __classPrivateFieldGet(this, _BaseSharedContainer_value, "f");
66
+ if (oldValue === newValue)
67
+ return;
68
+ // Try to update the pointer
69
+ __classPrivateFieldGet(this, _BaseSharedContainer_difHandler, "f").triggerReplace(__classPrivateFieldGet(this, _BaseSharedContainer_pointerAddress, "f"), newValue);
70
+ __classPrivateFieldSet(this, _BaseSharedContainer_value, newValue, "f");
71
+ }
72
+ isContainerMutable() {
73
+ return __classPrivateFieldGet(this, _BaseSharedContainer_containerMutability, "f") === SharedContainerMutability.Mutable;
74
+ }
75
+ withOwnership(ownership) {
76
+ if (ownership === DIFSharedContainerOwnership.Immutable) {
77
+ return new ReferencedSharedContainer(this, ownership);
78
+ }
79
+ else if (ownership === DIFSharedContainerOwnership.Mutable) {
80
+ if (this.isContainerMutable()) {
81
+ return new ReferencedSharedContainer(this, ownership);
82
+ }
83
+ else {
84
+ throw new Error("Cannot create a mutable reference to an immutable shared container.");
85
+ }
86
+ }
87
+ else if (ownership === DIFSharedContainerOwnership.Owned) {
88
+ return new OwnedSharedContainer(this);
89
+ }
90
+ else {
91
+ throw new Error(`Invalid ownership type: ${ownership}`);
92
+ }
93
+ }
94
+ }
95
+ _BaseSharedContainer_value = new WeakMap(), _BaseSharedContainer_pointerAddress = new WeakMap(), _BaseSharedContainer_difHandler = new WeakMap(), _BaseSharedContainer_containerMutability = new WeakMap();
@@ -0,0 +1,36 @@
1
+ import { DIFSharedContainerOwnership } from "../dif/types/mod.js";
2
+ import type { SharedContainerMutability } from "./base-shared-container.js";
3
+ import type { OwnedSharedContainer } from "./owned.js";
4
+ import type { ReferencedSharedContainer, SharedReferenceMutability } from "./reference.js";
5
+ export * from "./base-shared-container.js";
6
+ export * from "./reference.js";
7
+ export * from "./owned.js";
8
+ declare const PointerAddressBrand: unique symbol;
9
+ declare const PointerAddressWithOwnershipBrand: unique symbol;
10
+ export type PointerAddressWithOwnership = string & {
11
+ [PointerAddressWithOwnershipBrand]: never;
12
+ };
13
+ export type PointerAddress = string & {
14
+ [PointerAddressBrand]: never;
15
+ };
16
+ export declare function splitPointerAddressWithOwnership(address: PointerAddressWithOwnership): [DIFSharedContainerOwnership, PointerAddress];
17
+ export declare function combinePointerAddressWithOwnership(address: PointerAddress, ownership: DIFSharedContainerOwnership): PointerAddressWithOwnership;
18
+ /**
19
+ * Represents a shared container, which can be either an owned container or a referenced container.
20
+ */
21
+ export type SharedContainer<T, Mutability extends SharedContainerMutability = SharedContainerMutability> = OwnedSharedContainer<T, Mutability> | ReferencedSharedContainer<T, Mutability, typeof SharedReferenceMutability.Immutable> | ReferencedSharedContainer<T, Mutability, typeof SharedReferenceMutability.Mutable>;
22
+ declare const SharedReferencedTag: unique symbol;
23
+ /**
24
+ * The SharedReferenced type represents a referenced shared value, which is a reference to a shared value that can be either mutable or immutable.
25
+ * The underlying value can be mutable or not.
26
+ */
27
+ export type SharedRef<T extends object, Mutability extends SharedContainerMutability = SharedContainerMutability, ReferenceMutability extends SharedReferenceMutability = SharedReferenceMutability> = Mutability extends SharedContainerMutability.Immutable ? ReferenceMutability extends SharedReferenceMutability.Mutable ? never : SharedReferenceInner<T, Mutability, ReferenceMutability> : SharedReferenceInner<T, Mutability, ReferenceMutability>;
28
+ type SharedReferenceInner<T extends object, Mutability extends SharedContainerMutability, ReferenceMutability extends SharedReferenceMutability> = T & {
29
+ [SharedReferencedTag]: {
30
+ mutability: Mutability;
31
+ referenceMutability: ReferenceMutability;
32
+ };
33
+ };
34
+ export type AsShared<T, Mutability extends SharedContainerMutability> = T extends object ? SharedRef<T, Mutability> | SharedContainer<T, Mutability> : SharedContainer<T, Mutability>;
35
+ export type AsSharedMaybeOwned<T, Mutability extends SharedContainerMutability> = T extends object ? SharedRef<T, Mutability> | OwnedSharedContainer<T, Mutability> : OwnedSharedContainer<T, Mutability>;
36
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/shared-container/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAC5E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,KAAK,EAAE,yBAAyB,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAE3F,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAE3B,OAAO,CAAC,MAAM,mBAAmB,EAAE,OAAO,MAAM,CAAC;AACjD,OAAO,CAAC,MAAM,gCAAgC,EAAE,OAAO,MAAM,CAAC;AAE9D,MAAM,MAAM,2BAA2B,GAAG,MAAM,GAAG;IAAE,CAAC,gCAAgC,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC;AACjG,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG;IAAE,CAAC,mBAAmB,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC;AAEvE,wBAAgB,gCAAgC,CAC5C,OAAO,EAAE,2BAA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AG,eAAe,CAAC,CAAC,EAAE,UAAU,CAAC,GACzD,eAAe,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;AAErC,MAAM,MAAM,kBAAkB,CAAC,CAAC,EAAE,UAAU,SAAS,yBAAyB,IAAI,CAAC,SAAS,MAAM,GAC5F,SAAS,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG,oBAAoB,CAAC,CAAC,EAAE,UAAU,CAAC,GAC9D,oBAAoB,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC"}
@@ -0,0 +1,29 @@
1
+ import { DIFSharedContainerOwnership } from "../dif/types/mod.js";
2
+ export * from "./base-shared-container.js";
3
+ export * from "./reference.js";
4
+ export * from "./owned.js";
5
+ export function splitPointerAddressWithOwnership(address) {
6
+ const [ownershipStr, addressStr] = address.split("$");
7
+ if (ownershipStr === "") {
8
+ return [DIFSharedContainerOwnership.Owned, addressStr];
9
+ }
10
+ else if (ownershipStr === "'") {
11
+ return [DIFSharedContainerOwnership.Immutable, addressStr];
12
+ }
13
+ else if (ownershipStr === "'mut") {
14
+ return [DIFSharedContainerOwnership.Mutable, addressStr];
15
+ }
16
+ else {
17
+ throw new Error(`Invalid pointer address with ownership: ${address}`);
18
+ }
19
+ }
20
+ export function combinePointerAddressWithOwnership(address, ownership) {
21
+ let ownershipStr = "";
22
+ if (ownership === DIFSharedContainerOwnership.Immutable) {
23
+ ownershipStr = "'";
24
+ }
25
+ else if (ownership === DIFSharedContainerOwnership.Mutable) {
26
+ ownershipStr = "'mut";
27
+ }
28
+ return `${ownershipStr}$${address}`;
29
+ }
@@ -0,0 +1,33 @@
1
+ import { ReferencedSharedContainer, SharedReferenceMutability } from "./reference.js";
2
+ import type { BaseSharedContainer, SharedContainerMutability } from "./base-shared-container.js";
3
+ import type { PointerAddress } from "./mod.js";
4
+ export declare class OwnedSharedContainer<T, Mutability extends SharedContainerMutability> {
5
+ #private;
6
+ constructor(baseSharedContainer: BaseSharedContainer<T, Mutability>);
7
+ /**
8
+ * Gets the address of the pointer storing the reference.
9
+ */
10
+ get pointerAddress(): PointerAddress;
11
+ /**
12
+ * Gets the current value of the reference.
13
+ */
14
+ get value(): T;
15
+ /**
16
+ * Replaces the current value of the reference with a new value.
17
+ * Also notifies all observers of the pointer about the change.
18
+ * @throws If the reference is immutable or the new value is of an incompatible type.
19
+ */
20
+ set value(newValue: Mutability extends SharedContainerMutability.Mutable ? T : never);
21
+ /**
22
+ * Derives a new mutable reference from the current reference if the current reference is mutable.
23
+ * Otherwise returns an error
24
+ * @returns A new mutable reference derived from the current reference if the current reference is mutable, otherwise throws an error.
25
+ */
26
+ deriveMutableReference(): Mutability extends SharedContainerMutability.Mutable ? ReferencedSharedContainer<T, Mutability, SharedReferenceMutability.Mutable> : never;
27
+ /**
28
+ * Derives a new immutable reference from the current reference. The derived reference will have the same underlying shared container,
29
+ * @returns A new ReferencedSharedContainer instance with immutable reference mutability.
30
+ */
31
+ deriveImmutableReference(): ReferencedSharedContainer<T, Mutability, SharedReferenceMutability.Immutable>;
32
+ }
33
+ //# sourceMappingURL=owned.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"owned.d.ts","sourceRoot":"","sources":["../../src/shared-container/owned.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AACtF,OAAO,KAAK,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AACjG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,qBAAa,oBAAoB,CAAC,CAAC,EAAE,UAAU,SAAS,yBAAyB;;gBAG1D,mBAAmB,EAAE,mBAAmB,CAAC,CAAC,EAAE,UAAU,CAAC;IAI1E;;OAEG;IACH,IAAW,cAAc,IAAI,cAAc,CAE1C;IAED;;OAEG;IACH,IAAW,KAAK,IAAI,CAAC,CAEpB;IAED;;;;OAIG;IACH,IAAI,KAAK,CAAC,QAAQ,EAAE,UAAU,SAAS,yBAAyB,CAAC,OAAO,GAAG,CAAC,GAAG,KAAK,EAEnF;IAED;;;;OAIG;IACI,sBAAsB,IAAI,UAAU,SAAS,yBAAyB,CAAC,OAAO,GAAG,yBAAyB,CACzG,CAAC,EACD,UAAU,EACV,yBAAyB,CAAC,OAAO,CACpC,GACC,KAAK;IAgBX;;;OAGG;IACI,wBAAwB,IAAI,yBAAyB,CACxD,CAAC,EACD,UAAU,EACV,yBAAyB,CAAC,SAAS,CACtC;CAOJ"}