@unyt/datex 0.0.14 → 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.
- package/esm/datex-web/datex_web.d.ts +93 -2
- package/esm/datex-web/datex_web.internal.d.ts +215 -197
- package/esm/datex-web/datex_web.internal.d.ts.map +1 -1
- package/esm/datex-web/datex_web.internal.js +437 -407
- package/esm/datex-web/datex_web.wasm +0 -0
- package/esm/datex-web/types/decompiler/options.d.ts +17 -0
- package/esm/datex-web/types/decompiler/options.d.ts.map +1 -0
- package/esm/datex-web/types/decompiler/options.js +4 -0
- package/esm/datex-web/types/disassembler/options.d.ts +6 -0
- package/esm/datex-web/types/disassembler/options.d.ts.map +1 -0
- package/esm/datex-web/types/disassembler/options.js +4 -0
- package/esm/datex-web/types/network/com_hub/managers/socket_manager.d.ts +9 -0
- package/esm/datex-web/types/network/com_hub/managers/socket_manager.d.ts.map +1 -0
- package/esm/datex-web/types/network/com_hub/managers/socket_manager.js +4 -0
- package/esm/datex-web/types/network/com_hub/metadata.d.ts +20 -0
- package/esm/datex-web/types/network/com_hub/metadata.d.ts.map +1 -0
- package/esm/datex-web/types/network/com_hub/metadata.js +4 -0
- package/esm/datex-web/types/network/com_hub/mod.d.ts +6 -0
- package/esm/datex-web/types/network/com_hub/mod.d.ts.map +1 -0
- package/esm/datex-web/types/network/com_hub/mod.js +4 -0
- package/esm/datex-web/types/network/com_hub/network_tracing.d.ts +23 -0
- package/esm/datex-web/types/network/com_hub/network_tracing.d.ts.map +1 -0
- package/esm/datex-web/types/network/com_hub/network_tracing.js +4 -0
- package/esm/datex-web/types/network/com_hub.d.ts +8 -0
- package/esm/datex-web/types/network/com_hub.d.ts.map +1 -0
- package/esm/datex-web/types/network/com_hub.js +4 -0
- package/esm/datex-web/types/network/com_interfaces/com_interface/properties.d.ts +27 -0
- package/esm/datex-web/types/network/com_interfaces/com_interface/properties.d.ts.map +1 -0
- package/esm/datex-web/types/network/com_interfaces/com_interface/properties.js +4 -0
- package/esm/datex-web/types/network/com_interfaces/default_setup_data/http_common.d.ts +10 -0
- package/esm/datex-web/types/network/com_interfaces/default_setup_data/http_common.d.ts.map +1 -0
- package/esm/datex-web/types/network/com_interfaces/default_setup_data/http_common.js +4 -0
- package/esm/datex-web/types/network/com_interfaces/default_setup_data/websocket/websocket_server.d.ts +6 -0
- package/esm/datex-web/types/network/com_interfaces/default_setup_data/websocket/websocket_server.d.ts.map +1 -0
- package/esm/datex-web/types/network/com_interfaces/default_setup_data/websocket/websocket_server.js +4 -0
- package/esm/datex-web/types/runtime/config.d.ts +16 -0
- package/esm/datex-web/types/runtime/config.d.ts.map +1 -0
- package/esm/datex-web/types/runtime/config.js +4 -0
- package/esm/default.d.ts.map +1 -1
- package/esm/default.js +2 -0
- package/esm/deno.json +73 -17
- package/esm/dif/core.d.ts +36 -40
- package/esm/dif/core.d.ts.map +1 -1
- package/esm/dif/core.js +33 -54
- package/esm/dif/dif-handler.d.ts +58 -101
- package/esm/dif/dif-handler.d.ts.map +1 -1
- package/esm/dif/dif-handler.js +411 -365
- package/esm/dif/display.d.ts +14 -5
- package/esm/dif/display.d.ts.map +1 -1
- package/esm/dif/display.js +89 -39
- package/esm/dif/helpers/mod.d.ts +6 -0
- package/esm/dif/helpers/mod.d.ts.map +1 -0
- package/esm/dif/helpers/mod.js +5 -0
- package/esm/dif/helpers/typed-integer.d.ts +14 -0
- package/esm/dif/helpers/typed-integer.d.ts.map +1 -0
- package/esm/dif/helpers/typed-integer.js +37 -0
- package/esm/dif/js-lib.d.ts +14 -1
- package/esm/dif/js-lib.d.ts.map +1 -1
- package/esm/dif/js-lib.js +19 -1
- package/esm/dif/mod.d.ts +2 -2
- package/esm/dif/mod.d.ts.map +1 -1
- package/esm/dif/mod.js +2 -2
- package/esm/dif/type-registry.d.ts +30 -21
- package/esm/dif/type-registry.d.ts.map +1 -1
- package/esm/dif/type-registry.js +45 -33
- package/esm/dif/types/mod.d.ts +9 -0
- package/esm/dif/types/mod.d.ts.map +1 -0
- package/esm/dif/types/mod.js +8 -0
- package/esm/dif/types/type.d.ts +91 -0
- package/esm/dif/types/type.d.ts.map +1 -0
- package/esm/dif/types/type.js +33 -0
- package/esm/dif/types/update.d.ts +63 -0
- package/esm/dif/types/update.d.ts.map +1 -0
- package/esm/dif/types/update.js +16 -0
- package/esm/dif/types/value.d.ts +62 -0
- package/esm/dif/types/value.d.ts.map +1 -0
- package/esm/dif/types/value.js +1 -0
- package/esm/dif/update.d.ts +20 -0
- package/esm/dif/update.d.ts.map +1 -0
- package/esm/dif/update.js +41 -0
- package/esm/dif/utils.d.ts +8 -0
- package/esm/dif/utils.d.ts.map +1 -0
- package/esm/dif/utils.js +67 -0
- package/esm/lib/js-core-types/array.d.ts +3 -0
- package/esm/lib/js-core-types/array.d.ts.map +1 -0
- package/esm/lib/js-core-types/array.js +175 -0
- package/esm/lib/js-core-types/map.d.ts +15 -0
- package/esm/lib/js-core-types/map.d.ts.map +1 -0
- package/esm/lib/js-core-types/map.js +88 -0
- package/esm/lib/js-core-types/mod.d.ts +8 -0
- package/esm/lib/js-core-types/mod.d.ts.map +1 -0
- package/esm/lib/js-core-types/mod.js +7 -0
- package/esm/lib/mod.d.ts +8 -0
- package/esm/lib/mod.d.ts.map +1 -0
- package/esm/lib/mod.js +7 -0
- package/esm/lib/special-core-types/mod.d.ts +9 -0
- package/esm/lib/special-core-types/mod.d.ts.map +1 -0
- package/esm/lib/special-core-types/mod.js +8 -0
- package/esm/lib/special-core-types/tagged.d.ts +17 -0
- package/esm/lib/special-core-types/tagged.d.ts.map +1 -0
- package/esm/lib/special-core-types/tagged.js +37 -0
- package/esm/lib/special-core-types/undefined.d.ts +7 -0
- package/esm/lib/special-core-types/undefined.d.ts.map +1 -0
- package/esm/lib/special-core-types/undefined.js +28 -0
- package/esm/mod.d.ts +2 -3
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +2 -3
- package/esm/network/com-hub.d.ts +28 -1
- package/esm/network/com-hub.d.ts.map +1 -1
- package/esm/network/com-hub.js +6 -2
- package/esm/network/interfaces/websocket-server-base.d.ts +1 -1
- package/esm/network/interfaces/websocket-server-base.d.ts.map +1 -1
- package/esm/network/interfaces/websocket-server-base.js +8 -7
- package/esm/network/interfaces/websocket-server-deno.d.ts +1 -1
- package/esm/network/interfaces/websocket-server-deno.d.ts.map +1 -1
- package/esm/repl/mod.js +1 -1
- package/esm/runtime/runtime.d.ts +43 -18
- package/esm/runtime/runtime.d.ts.map +1 -1
- package/esm/runtime/runtime.js +55 -32
- package/esm/{refs/ref.d.ts → shared-container/base-shared-container.d.ts} +13 -5
- package/esm/shared-container/base-shared-container.d.ts.map +1 -0
- package/esm/shared-container/base-shared-container.js +95 -0
- package/esm/shared-container/mod.d.ts +36 -0
- package/esm/shared-container/mod.d.ts.map +1 -0
- package/esm/shared-container/mod.js +29 -0
- package/esm/shared-container/owned.d.ts +33 -0
- package/esm/shared-container/owned.d.ts.map +1 -0
- package/esm/shared-container/owned.js +60 -0
- package/esm/shared-container/reference.d.ts +31 -0
- package/esm/shared-container/reference.d.ts.map +1 -0
- package/esm/shared-container/reference.js +64 -0
- package/esm/utils/devtools-formatter.js +2 -2
- package/esm/utils/option.d.ts +17 -0
- package/esm/utils/option.d.ts.map +1 -0
- package/esm/utils/option.js +54 -0
- package/package.json +1 -1
- package/esm/dif/definitions.d.ts +0 -134
- package/esm/dif/definitions.d.ts.map +0 -1
- package/esm/dif/definitions.js +0 -38
- package/esm/refs/ref.d.ts.map +0 -1
- package/esm/refs/ref.js +0 -60
package/esm/runtime/runtime.d.ts
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type JSRuntime } from "../datex.js";
|
|
2
2
|
import { ComHub } from "../network/com-hub.js";
|
|
3
|
-
import { DIFHandler
|
|
4
|
-
import type
|
|
5
|
-
import type {
|
|
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
|
|
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():
|
|
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
|
|
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
|
-
|
|
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
|
-
*
|
|
131
|
-
*
|
|
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
|
-
|
|
139
|
-
|
|
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":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/runtime/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAKH,KAAK,SAAS,EACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,KAAK,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAChG,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,mBAA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AAI,EAAE,MAAM,KAAK,IAAI;IAazB;;;;OAIG;IACI,kBAAkB,CAAC,GAAG,EAAE,UAAU,GAAG,CAAC,eAAe,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAI9E;;;;OAIG;IACI,kBAAkB,CAAC,GAAG,EAAE,UAAU,GAAG,CAAC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAI5E;;;;OAIG;IACI,sBAAsB,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,IAAI,GAAG,MAAM;CAG/F"}
|
package/esm/runtime/runtime.js
CHANGED
|
@@ -9,14 +9,15 @@ 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 _Runtime_instances, _Runtime_runtime, _Runtime_comHub, _Runtime_difHandler,
|
|
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 {
|
|
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.
|
|
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",
|
|
103
|
-
return __classPrivateFieldGet(this, _Runtime_instances, "m",
|
|
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",
|
|
108
|
-
return __classPrivateFieldGet(this, _Runtime_instances, "m",
|
|
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
|
|
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
|
-
|
|
130
|
-
|
|
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(),
|
|
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 ===
|
|
182
|
+
if (difValueContainer === undefined) {
|
|
160
183
|
return undefined;
|
|
161
184
|
}
|
|
162
185
|
return __classPrivateFieldGet(this, _Runtime_difHandler, "f").resolveDIFValueContainer(difValueContainer);
|
|
163
|
-
},
|
|
186
|
+
}, _Runtime_executeSyncWithNormalizedArguments = function _Runtime_executeSyncWithNormalizedArguments(datexScript, values = []) {
|
|
164
187
|
const difValue = __classPrivateFieldGet(this, _Runtime_difHandler, "f").executeSyncDIF(datexScript, values);
|
|
165
|
-
if (difValue ===
|
|
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
|
-
},
|
|
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
|
|
12
|
+
export declare class BaseSharedContainer<T, Mutability extends SharedContainerMutability> {
|
|
7
13
|
#private;
|
|
8
|
-
constructor(value: T, pointerAddress:
|
|
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():
|
|
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=
|
|
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,2BAA2B,GACrC,CAAC,2BAA2B,EAAE,cAAc,CAAC,CAW/C;AACD,wBAAgB,kCAAkC,CAC9C,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,2BAA2B,GACvC,2BAA2B,CAQ7B;AAED;;GAEG;A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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"}
|
|
@@ -0,0 +1,60 @@
|
|
|
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 _OwnedSharedContainer_baseSharedContainer;
|
|
13
|
+
import { ReferencedSharedContainer, SharedReferenceMutability } from "./reference.js";
|
|
14
|
+
export class OwnedSharedContainer {
|
|
15
|
+
constructor(baseSharedContainer) {
|
|
16
|
+
_OwnedSharedContainer_baseSharedContainer.set(this, void 0);
|
|
17
|
+
__classPrivateFieldSet(this, _OwnedSharedContainer_baseSharedContainer, baseSharedContainer, "f");
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Gets the address of the pointer storing the reference.
|
|
21
|
+
*/
|
|
22
|
+
get pointerAddress() {
|
|
23
|
+
return __classPrivateFieldGet(this, _OwnedSharedContainer_baseSharedContainer, "f").pointerAddress;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Gets the current value of the reference.
|
|
27
|
+
*/
|
|
28
|
+
get value() {
|
|
29
|
+
return __classPrivateFieldGet(this, _OwnedSharedContainer_baseSharedContainer, "f").value;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Replaces the current value of the reference with a new value.
|
|
33
|
+
* Also notifies all observers of the pointer about the change.
|
|
34
|
+
* @throws If the reference is immutable or the new value is of an incompatible type.
|
|
35
|
+
*/
|
|
36
|
+
set value(newValue) {
|
|
37
|
+
__classPrivateFieldGet(this, _OwnedSharedContainer_baseSharedContainer, "f").value = newValue;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Derives a new mutable reference from the current reference if the current reference is mutable.
|
|
41
|
+
* Otherwise returns an error
|
|
42
|
+
* @returns A new mutable reference derived from the current reference if the current reference is mutable, otherwise throws an error.
|
|
43
|
+
*/
|
|
44
|
+
deriveMutableReference() {
|
|
45
|
+
if (__classPrivateFieldGet(this, _OwnedSharedContainer_baseSharedContainer, "f").isContainerMutable()) {
|
|
46
|
+
return new ReferencedSharedContainer(__classPrivateFieldGet(this, _OwnedSharedContainer_baseSharedContainer, "f"), SharedReferenceMutability.Mutable);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
throw new Error("Cannot derive a mutable reference from an immutable reference.");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Derives a new immutable reference from the current reference. The derived reference will have the same underlying shared container,
|
|
54
|
+
* @returns A new ReferencedSharedContainer instance with immutable reference mutability.
|
|
55
|
+
*/
|
|
56
|
+
deriveImmutableReference() {
|
|
57
|
+
return new ReferencedSharedContainer(__classPrivateFieldGet(this, _OwnedSharedContainer_baseSharedContainer, "f"), SharedReferenceMutability.Immutable);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
_OwnedSharedContainer_baseSharedContainer = new WeakMap();
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { BaseSharedContainer, SharedContainerMutability } from "./base-shared-container.js";
|
|
2
|
+
import type { PointerAddress } from "./mod.js";
|
|
3
|
+
export declare enum SharedReferenceMutability {
|
|
4
|
+
Immutable = 0,
|
|
5
|
+
Mutable = 1
|
|
6
|
+
}
|
|
7
|
+
export declare class ReferencedSharedContainer<T, Mutability extends SharedContainerMutability, ReferenceMutability extends SharedReferenceMutability> {
|
|
8
|
+
#private;
|
|
9
|
+
constructor(baseSharedContainer: BaseSharedContainer<T, Mutability>, referenceMutability: ReferenceMutability);
|
|
10
|
+
/**
|
|
11
|
+
* Gets the address of the pointer storing the reference.
|
|
12
|
+
*/
|
|
13
|
+
get pointerAddress(): PointerAddress;
|
|
14
|
+
/**
|
|
15
|
+
* Gets the current value of the reference.
|
|
16
|
+
*/
|
|
17
|
+
get value(): T;
|
|
18
|
+
/**
|
|
19
|
+
* Replaces the current value of the reference with a new value.
|
|
20
|
+
* Also notifies all observers of the pointer about the change.
|
|
21
|
+
* @throws If the reference is immutable or the new value is of an incompatible type.
|
|
22
|
+
*/
|
|
23
|
+
set value(newValue: Mutability extends SharedContainerMutability.Mutable ? T : never);
|
|
24
|
+
isMutable(): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Derives an immutable reference from the current reference. The derived reference will have the same underlying shared container,
|
|
27
|
+
* @returns A new ReferencedSharedContainer instance with immutable reference mutability.
|
|
28
|
+
*/
|
|
29
|
+
deriveImmutableReference(): ReferencedSharedContainer<T, Mutability, SharedReferenceMutability.Immutable>;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=reference.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reference.d.ts","sourceRoot":"","sources":["../../src/shared-container/reference.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AACjG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,oBAAY,yBAAyB;IACjC,SAAS,IAAI;IACb,OAAO,IAAI;CACd;AACD,qBAAa,yBAAyB,CAClC,CAAC,EACD,UAAU,SAAS,yBAAyB,EAC5C,mBAAmB,SAAS,yBAAyB;;gBAMjD,mBAAmB,EAAE,mBAAmB,CAAC,CAAC,EAAE,UAAU,CAAC,EACvD,mBAAmB,EAAE,mBAAmB;IAM5C;;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;IAEM,SAAS,IAAI,OAAO;IAI3B;;;OAGG;IACI,wBAAwB,IAAI,yBAAyB,CACxD,CAAC,EACD,UAAU,EACV,yBAAyB,CAAC,SAAS,CACtC;CAMJ"}
|