@mermanjs/node-wasm 0.8.0-alpha.6
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/CHANGELOG.md +24 -0
- package/LICENSE-APACHE +201 -0
- package/LICENSE-MIT +21 -0
- package/README.md +47 -0
- package/THIRD_PARTY_LICENSES/beautiful-mermaid/LICENSE +21 -0
- package/THIRD_PARTY_LICENSES/cose-base-v1/LICENSE +21 -0
- package/THIRD_PARTY_LICENSES/cose-base-v2/LICENSE +21 -0
- package/THIRD_PARTY_LICENSES/cytoscape/LICENSE +19 -0
- package/THIRD_PARTY_LICENSES/cytoscape-cose-bilkent/LICENSE +21 -0
- package/THIRD_PARTY_LICENSES/cytoscape-fcose/LICENSE +19 -0
- package/THIRD_PARTY_LICENSES/d3-shape/LICENSE +13 -0
- package/THIRD_PARTY_LICENSES/dagre/LICENSE +19 -0
- package/THIRD_PARTY_LICENSES/dompurify/LICENSE +202 -0
- package/THIRD_PARTY_LICENSES/eclipse-elk/LICENSE.md +264 -0
- package/THIRD_PARTY_LICENSES/elkjs/LICENSE.md +264 -0
- package/THIRD_PARTY_LICENSES/fmin/LICENSE +27 -0
- package/THIRD_PARTY_LICENSES/graphlib/LICENSE +19 -0
- package/THIRD_PARTY_LICENSES/katex-fonts/FONT_NOTICE.txt +12 -0
- package/THIRD_PARTY_LICENSES/katex-fonts/OFL.txt +85 -0
- package/THIRD_PARTY_LICENSES/layout-base-v1/LICENSE +21 -0
- package/THIRD_PARTY_LICENSES/layout-base-v2/LICENSE +21 -0
- package/THIRD_PARTY_LICENSES/mermaid/LICENSE +21 -0
- package/THIRD_PARTY_LICENSES/mermaid-ascii/LICENSE +21 -0
- package/THIRD_PARTY_LICENSES/mermaid-rs-renderer/LICENSE +21 -0
- package/THIRD_PARTY_LICENSES/non-layered-tidy-tree-layout/LICENSE +21 -0
- package/THIRD_PARTY_LICENSES/ratex/LICENSE +27 -0
- package/THIRD_PARTY_LICENSES/ratex/THIRD_PARTY_NOTICES.txt +19 -0
- package/THIRD_PARTY_LICENSES/rough-rs/LICENSE +21 -0
- package/THIRD_PARTY_LICENSES/roughjs/LICENSE +21 -0
- package/THIRD_PARTY_LICENSES/rust-cargo-dependencies.json +5581 -0
- package/THIRD_PARTY_LICENSES/sanitize-url/LICENSE +21 -0
- package/THIRD_PARTY_LICENSES/tree-sitter/LICENSE +21 -0
- package/THIRD_PARTY_LICENSES/tree-sitter-mermaid-monaqa/LICENSE +21 -0
- package/THIRD_PARTY_LICENSES/tree-sitter-mermaid-pappasam/LICENSE +21 -0
- package/THIRD_PARTY_LICENSES/tree-sitter-mermaid-singularity/LICENSE +22 -0
- package/THIRD_PARTY_LICENSES/venn-js/LICENSE +22 -0
- package/THIRD_PARTY_LICENSES/wasm-minimal-protocol/LICENSE +24 -0
- package/THIRD_PARTY_LICENSES/zenuml-core/LICENSE +21 -0
- package/THIRD_PARTY_NOTICES.md +648 -0
- package/artifact/merman_node.cjs +302 -0
- package/artifact/merman_node_bg.wasm +0 -0
- package/dist/bounded-executor.mjs +135 -0
- package/dist/candidates/wasm.mjs +87 -0
- package/dist/candidates/wrap-engine.mjs +36 -0
- package/dist/engine.mjs +1340 -0
- package/dist/errors.mjs +1318 -0
- package/dist/generated/binding-contract.mjs +1019 -0
- package/dist/generated/capability-surface.mjs +66 -0
- package/dist/generated/node-wire-contract.json +122 -0
- package/dist/index.d.ts +283 -0
- package/dist/index.mjs +37 -0
- package/dist/native-loader.mjs +125 -0
- package/dist/transport-contract.mjs +87 -0
- package/package.json +44 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// @generated by `cargo run -p xtask -- gen-capability-surface`.
|
|
2
|
+
// Source: capabilities/feature-surface-v1.json. Do not edit directly.
|
|
3
|
+
|
|
4
|
+
export const CAPABILITY_DESCRIPTOR_SCHEMA_VERSION = 1;
|
|
5
|
+
export const CAPABILITY_DESCRIPTOR_DIGEST = "sha256:e3dfc678c1ccd830bb4e2a10b24b0e5957c6cb6112c9e1c9f75d847317ba31d7";
|
|
6
|
+
|
|
7
|
+
export const NODE_BINDING_OPERATIONS = [
|
|
8
|
+
{
|
|
9
|
+
"id": "analysis-facts-json",
|
|
10
|
+
"compiled_prerequisites": []
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"id": "analysis-json",
|
|
14
|
+
"compiled_prerequisites": []
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"id": "ascii",
|
|
18
|
+
"compiled_prerequisites": []
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"id": "document-analysis-facts-json",
|
|
22
|
+
"compiled_prerequisites": []
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"id": "document-analysis-json",
|
|
26
|
+
"compiled_prerequisites": []
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"id": "jpeg",
|
|
30
|
+
"compiled_prerequisites": [
|
|
31
|
+
"svg"
|
|
32
|
+
]
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"id": "layout-json",
|
|
36
|
+
"compiled_prerequisites": []
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"id": "pdf",
|
|
40
|
+
"compiled_prerequisites": [
|
|
41
|
+
"svg"
|
|
42
|
+
]
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"id": "png",
|
|
46
|
+
"compiled_prerequisites": [
|
|
47
|
+
"svg"
|
|
48
|
+
]
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"id": "semantic-json",
|
|
52
|
+
"compiled_prerequisites": []
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"id": "svg",
|
|
56
|
+
"compiled_prerequisites": []
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"id": "svg-plan-json",
|
|
60
|
+
"compiled_prerequisites": []
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"id": "validation-json",
|
|
64
|
+
"compiled_prerequisites": []
|
|
65
|
+
}
|
|
66
|
+
];
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schema_version": 1,
|
|
3
|
+
"package_id": "@mermanjs/node",
|
|
4
|
+
"artifact_id": "merman-node-static-svg",
|
|
5
|
+
"transport_api_version": 1,
|
|
6
|
+
"binding_result_payload_version": 1,
|
|
7
|
+
"artifact": {
|
|
8
|
+
"capability_ids": [
|
|
9
|
+
"layout-cytoscape",
|
|
10
|
+
"layout-elk",
|
|
11
|
+
"svg"
|
|
12
|
+
],
|
|
13
|
+
"output_ids": [
|
|
14
|
+
"svg"
|
|
15
|
+
],
|
|
16
|
+
"output_contracts": [
|
|
17
|
+
{
|
|
18
|
+
"id": "svg",
|
|
19
|
+
"media_type": "image/svg+xml",
|
|
20
|
+
"system_fonts": null,
|
|
21
|
+
"embedded_images": null
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"system_adapter_ids": [],
|
|
25
|
+
"operation_ids": [
|
|
26
|
+
"layout-json",
|
|
27
|
+
"semantic-json",
|
|
28
|
+
"svg",
|
|
29
|
+
"svg-plan-json"
|
|
30
|
+
],
|
|
31
|
+
"metadata_ids": [
|
|
32
|
+
"diagram-family-capabilities",
|
|
33
|
+
"presentation-catalog",
|
|
34
|
+
"supported-diagrams",
|
|
35
|
+
"supported-themes"
|
|
36
|
+
],
|
|
37
|
+
"option_group_ids": [
|
|
38
|
+
"environment",
|
|
39
|
+
"fixed_local_offset_minutes",
|
|
40
|
+
"fixed_today",
|
|
41
|
+
"layout",
|
|
42
|
+
"parse",
|
|
43
|
+
"presentation",
|
|
44
|
+
"resources",
|
|
45
|
+
"runtime_policy",
|
|
46
|
+
"site_config",
|
|
47
|
+
"svg",
|
|
48
|
+
"version"
|
|
49
|
+
],
|
|
50
|
+
"constructor_service_ids": [],
|
|
51
|
+
"text_measurement_provider_ids": [
|
|
52
|
+
"deterministic"
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
"documents": {
|
|
56
|
+
"identity": {
|
|
57
|
+
"max_utf8_bytes": 4096,
|
|
58
|
+
"max_depth": 8,
|
|
59
|
+
"max_members": 128,
|
|
60
|
+
"max_tokens": 256,
|
|
61
|
+
"max_string_utf8_bytes": 1024
|
|
62
|
+
},
|
|
63
|
+
"binding_options": {
|
|
64
|
+
"max_utf8_bytes": 1048576,
|
|
65
|
+
"max_depth": 64,
|
|
66
|
+
"max_members": 65536,
|
|
67
|
+
"max_tokens": 262144,
|
|
68
|
+
"max_string_utf8_bytes": 1048576
|
|
69
|
+
},
|
|
70
|
+
"request": {
|
|
71
|
+
"max_utf8_bytes": 10485760,
|
|
72
|
+
"max_depth": 8,
|
|
73
|
+
"max_members": 16,
|
|
74
|
+
"max_tokens": 64,
|
|
75
|
+
"max_string_utf8_bytes": 8388608
|
|
76
|
+
},
|
|
77
|
+
"runtime_catalog": {
|
|
78
|
+
"max_utf8_bytes": 1048576,
|
|
79
|
+
"max_depth": 64,
|
|
80
|
+
"max_members": 65536,
|
|
81
|
+
"max_tokens": 262144,
|
|
82
|
+
"max_string_utf8_bytes": 1048576
|
|
83
|
+
},
|
|
84
|
+
"response": {
|
|
85
|
+
"max_utf8_bytes": 27262976,
|
|
86
|
+
"max_depth": 8,
|
|
87
|
+
"max_members": 32,
|
|
88
|
+
"max_tokens": 128,
|
|
89
|
+
"max_string_utf8_bytes": 16777216
|
|
90
|
+
},
|
|
91
|
+
"error": {
|
|
92
|
+
"max_utf8_bytes": 262144,
|
|
93
|
+
"max_depth": 8,
|
|
94
|
+
"max_members": 32,
|
|
95
|
+
"max_tokens": 128,
|
|
96
|
+
"max_string_utf8_bytes": 65536
|
|
97
|
+
},
|
|
98
|
+
"metadata": {
|
|
99
|
+
"max_utf8_bytes": 8388608,
|
|
100
|
+
"max_depth": 64,
|
|
101
|
+
"max_members": 131072,
|
|
102
|
+
"max_tokens": 524288,
|
|
103
|
+
"max_string_utf8_bytes": 8388608
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
"fields": {
|
|
107
|
+
"operation_id_utf8_bytes": 128,
|
|
108
|
+
"media_type_utf8_bytes": 128,
|
|
109
|
+
"metadata_id_utf8_bytes": 128,
|
|
110
|
+
"uri_utf8_bytes": 16384,
|
|
111
|
+
"source_utf8_bytes": 8388608,
|
|
112
|
+
"options_json_utf8_bytes": 1048576,
|
|
113
|
+
"data_utf8_bytes": 16777216,
|
|
114
|
+
"metadata_json_utf8_bytes": 8388608,
|
|
115
|
+
"error_code_name_utf8_bytes": 128,
|
|
116
|
+
"error_kind_utf8_bytes": 128,
|
|
117
|
+
"error_message_utf8_bytes": 65536,
|
|
118
|
+
"capability_id_utf8_bytes": 128,
|
|
119
|
+
"package_version_utf8_bytes": 128,
|
|
120
|
+
"contract_digest_utf8_bytes": 128
|
|
121
|
+
}
|
|
122
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
export type MermanResourceProfile =
|
|
2
|
+
| "interactive"
|
|
3
|
+
| "constrained"
|
|
4
|
+
| "trusted-native"
|
|
5
|
+
| "unbounded-for-trusted-input";
|
|
6
|
+
|
|
7
|
+
export interface MermanBindingOptions {
|
|
8
|
+
version?: 2;
|
|
9
|
+
runtime_policy?: "deterministic";
|
|
10
|
+
environment?: {
|
|
11
|
+
text_measurement?: "deterministic";
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
};
|
|
14
|
+
resources?: {
|
|
15
|
+
profile?: MermanResourceProfile;
|
|
16
|
+
limits?: Record<string, number>;
|
|
17
|
+
};
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface CreateNodeEngineOptions {
|
|
22
|
+
bindingOptions?: MermanBindingOptions;
|
|
23
|
+
concurrency?: number;
|
|
24
|
+
maxQueue?: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface RenderSvgOptions {
|
|
28
|
+
/**
|
|
29
|
+
* Cancels queued work immediately and requests cooperative cancellation after Rust work starts.
|
|
30
|
+
* A queued request rejects with AbortError; a started request rejects with MermanOperationError
|
|
31
|
+
* carrying canonical cancellation details once transport admission or a renderer checkpoint
|
|
32
|
+
* observes the request.
|
|
33
|
+
*/
|
|
34
|
+
signal?: AbortSignal;
|
|
35
|
+
/**
|
|
36
|
+
* Relative monotonic deadline in milliseconds, starting when the Rust transport admits the
|
|
37
|
+
* operation. Values must be integers from 0 through 4,294,967,295.
|
|
38
|
+
*/
|
|
39
|
+
timeoutMs?: number;
|
|
40
|
+
/** Raw per-request options JSON merged by the shared binding contract. */
|
|
41
|
+
optionsJson?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface MermanOperationRequest {
|
|
45
|
+
operationId: string;
|
|
46
|
+
source: string;
|
|
47
|
+
uri?: string | null;
|
|
48
|
+
/** Raw per-request options JSON merged over the reusable engine baseline. */
|
|
49
|
+
optionsJson?: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface MermanOperationResult {
|
|
53
|
+
operation_id: string;
|
|
54
|
+
media_type: string;
|
|
55
|
+
data: string;
|
|
56
|
+
metadata_json: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface MermanTextMeasurementCatalog {
|
|
60
|
+
protocol_version: number;
|
|
61
|
+
provider_ids: string[];
|
|
62
|
+
[key: string]: unknown;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface MermanRuntimeResourceLimit {
|
|
66
|
+
id: string;
|
|
67
|
+
phase: string;
|
|
68
|
+
description: string;
|
|
69
|
+
overridable: boolean;
|
|
70
|
+
hard_cap: boolean;
|
|
71
|
+
minimum_value: number;
|
|
72
|
+
operation_ids: string[];
|
|
73
|
+
[key: string]: unknown;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface MermanRuntimeResourceProfile {
|
|
77
|
+
id: string;
|
|
78
|
+
purpose: string;
|
|
79
|
+
trust_assumption: string;
|
|
80
|
+
recommended_binding_default: boolean;
|
|
81
|
+
limits: Record<string, number | null>;
|
|
82
|
+
[key: string]: unknown;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface MermanRuntimeSystemFontContract {
|
|
86
|
+
source_id: string;
|
|
87
|
+
discovery: string;
|
|
88
|
+
cache_scope: string;
|
|
89
|
+
host_dependent: boolean;
|
|
90
|
+
caller_configurable: boolean;
|
|
91
|
+
resource_bounded: boolean;
|
|
92
|
+
[key: string]: unknown;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface MermanRuntimeEmbeddedImageLimits {
|
|
96
|
+
max_bytes_per_image: number | null;
|
|
97
|
+
max_total_bytes: number | null;
|
|
98
|
+
max_pixels_per_image: number | null;
|
|
99
|
+
max_total_pixels: number | null;
|
|
100
|
+
[key: string]: unknown;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface MermanRuntimeEmbeddedImageContract {
|
|
104
|
+
source_ids: string[];
|
|
105
|
+
filesystem_access: boolean;
|
|
106
|
+
network_access: boolean;
|
|
107
|
+
caller_configurable: boolean;
|
|
108
|
+
limits: MermanRuntimeEmbeddedImageLimits;
|
|
109
|
+
[key: string]: unknown;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface MermanRuntimeOutputContract {
|
|
113
|
+
id: string;
|
|
114
|
+
media_type: string;
|
|
115
|
+
system_fonts: MermanRuntimeSystemFontContract | null;
|
|
116
|
+
embedded_images: MermanRuntimeEmbeddedImageContract | null;
|
|
117
|
+
[key: string]: unknown;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface MermanRuntimePayloadSchema {
|
|
121
|
+
id: string;
|
|
122
|
+
version: number;
|
|
123
|
+
[key: string]: unknown;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface MermanRuntimeConstructorResourceLimit {
|
|
127
|
+
id: string;
|
|
128
|
+
phase: string;
|
|
129
|
+
unit: string;
|
|
130
|
+
description: string;
|
|
131
|
+
value: number;
|
|
132
|
+
[key: string]: unknown;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface MermanRuntimeConstructorServiceContract {
|
|
136
|
+
id: string;
|
|
137
|
+
provided_text_measurement_provider_ids: string[];
|
|
138
|
+
resource_limits: MermanRuntimeConstructorResourceLimit[];
|
|
139
|
+
[key: string]: unknown;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export interface MermanRuntimeCatalog {
|
|
143
|
+
schema_version: 1;
|
|
144
|
+
transport_api_version: 1;
|
|
145
|
+
package_version: string;
|
|
146
|
+
options_schema_versions: number[];
|
|
147
|
+
payload_schemas: MermanRuntimePayloadSchema[];
|
|
148
|
+
metadata_ids: string[];
|
|
149
|
+
option_group_ids: string[];
|
|
150
|
+
constructor_service_ids: string[];
|
|
151
|
+
constructor_service_contracts: MermanRuntimeConstructorServiceContract[];
|
|
152
|
+
capabilities: {
|
|
153
|
+
capability_ids: string[];
|
|
154
|
+
output_ids: string[];
|
|
155
|
+
operation_ids: string[];
|
|
156
|
+
system_adapter_ids: string[];
|
|
157
|
+
text_measurement: MermanTextMeasurementCatalog | null;
|
|
158
|
+
[key: string]: unknown;
|
|
159
|
+
};
|
|
160
|
+
output_contracts: MermanRuntimeOutputContract[];
|
|
161
|
+
registry: {
|
|
162
|
+
diagram_family_count: number;
|
|
163
|
+
[key: string]: unknown;
|
|
164
|
+
};
|
|
165
|
+
resources: {
|
|
166
|
+
general_binding_default_profile: string;
|
|
167
|
+
cli_default_profile: string;
|
|
168
|
+
limits: MermanRuntimeResourceLimit[];
|
|
169
|
+
profiles: MermanRuntimeResourceProfile[];
|
|
170
|
+
[key: string]: unknown;
|
|
171
|
+
};
|
|
172
|
+
[key: string]: unknown;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export interface MermanQueueState {
|
|
176
|
+
readonly active: number;
|
|
177
|
+
readonly pending: number;
|
|
178
|
+
readonly concurrency: number;
|
|
179
|
+
readonly maxQueue: number;
|
|
180
|
+
readonly state: "open" | "disposing" | "disposed";
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export declare class MermanEngine {
|
|
184
|
+
private constructor();
|
|
185
|
+
readonly queueState: MermanQueueState;
|
|
186
|
+
readonly runtimeCatalog: MermanRuntimeCatalog;
|
|
187
|
+
renderSvg(source: string, options?: RenderSvgOptions): Promise<string>;
|
|
188
|
+
/** Synchronous rendering is intended only for explicit SSG build paths. */
|
|
189
|
+
renderSvgSync(source: string, options?: Omit<RenderSvgOptions, "signal">): string;
|
|
190
|
+
svgPlanJson(source: string, options?: RenderSvgOptions): Promise<string>;
|
|
191
|
+
svgPlanJsonSync(
|
|
192
|
+
source: string,
|
|
193
|
+
options?: Omit<RenderSvgOptions, "signal">,
|
|
194
|
+
): string;
|
|
195
|
+
metadataJson(id: string): string;
|
|
196
|
+
executeOperation(
|
|
197
|
+
request: MermanOperationRequest,
|
|
198
|
+
options?: Pick<RenderSvgOptions, "signal" | "timeoutMs">,
|
|
199
|
+
): Promise<MermanOperationResult>;
|
|
200
|
+
executeOperationSync(
|
|
201
|
+
request: MermanOperationRequest,
|
|
202
|
+
options?: Pick<RenderSvgOptions, "timeoutMs">,
|
|
203
|
+
): MermanOperationResult;
|
|
204
|
+
dispose(): Promise<void>;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export declare function createNodeEngine(
|
|
208
|
+
options?: CreateNodeEngineOptions,
|
|
209
|
+
): Promise<MermanEngine>;
|
|
210
|
+
|
|
211
|
+
export declare class MermanError extends Error {
|
|
212
|
+
readonly code: string;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* A lossless unsigned resource count. Safe integers use `number`; wider `u64` values use a
|
|
217
|
+
* canonical decimal `string`.
|
|
218
|
+
*/
|
|
219
|
+
export type MermanResourceCount = number | string;
|
|
220
|
+
|
|
221
|
+
export interface MermanResourceErrorDetails {
|
|
222
|
+
readonly cause: string;
|
|
223
|
+
readonly limit_id: string;
|
|
224
|
+
readonly phase: string;
|
|
225
|
+
readonly actual: MermanResourceCount;
|
|
226
|
+
readonly max: MermanResourceCount;
|
|
227
|
+
readonly profile: string;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export interface MermanDiagnosticSpan {
|
|
231
|
+
readonly start: number;
|
|
232
|
+
readonly end: number;
|
|
233
|
+
readonly kind: "exact" | "insertion-point" | "fallback" | string;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export interface MermanDiagnosticErrorDetails {
|
|
237
|
+
readonly code: string;
|
|
238
|
+
readonly span: MermanDiagnosticSpan | null;
|
|
239
|
+
readonly field: string | null;
|
|
240
|
+
readonly diagram_type: string | null;
|
|
241
|
+
readonly requested_max_width?: number | null;
|
|
242
|
+
readonly actual_width?: number | null;
|
|
243
|
+
readonly width_profile?: string | null;
|
|
244
|
+
readonly fallback_reason?: string | null;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export interface MermanCancellationErrorDetails {
|
|
248
|
+
readonly reason: "requested" | "deadline_exceeded";
|
|
249
|
+
/** Renderer phase identifier; new Merman versions may add phases. */
|
|
250
|
+
readonly phase: string;
|
|
251
|
+
readonly [key: string]: unknown;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export declare class MermanOperationError extends MermanError {
|
|
255
|
+
readonly status: number | null;
|
|
256
|
+
readonly codeName: string | null;
|
|
257
|
+
readonly kind: "generic" | "unknown-operation" | "missing-capability" | string;
|
|
258
|
+
readonly capabilityId: string | null;
|
|
259
|
+
readonly resourceDetails: MermanResourceErrorDetails | null;
|
|
260
|
+
readonly diagnosticDetails: MermanDiagnosticErrorDetails | null;
|
|
261
|
+
readonly cancellationDetails: MermanCancellationErrorDetails | null;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export declare class MermanQueueSaturatedError extends MermanError {
|
|
265
|
+
readonly maxQueue: number;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export declare class MermanDisposedError extends MermanError {}
|
|
269
|
+
export declare class MermanInvalidTransportError extends MermanError {}
|
|
270
|
+
export declare class MermanLifecycleError extends MermanError {}
|
|
271
|
+
export declare class MermanMissingPlatformPackageError extends MermanError {
|
|
272
|
+
readonly packageName: string;
|
|
273
|
+
readonly target: string;
|
|
274
|
+
}
|
|
275
|
+
export declare class MermanNativeLoadError extends MermanError {
|
|
276
|
+
readonly packageName: string;
|
|
277
|
+
readonly target: string;
|
|
278
|
+
}
|
|
279
|
+
export declare class MermanUnsupportedTargetError extends MermanError {
|
|
280
|
+
readonly platform: string;
|
|
281
|
+
readonly arch: string;
|
|
282
|
+
readonly libc: string | null;
|
|
283
|
+
}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
MermanEngine,
|
|
6
|
+
createNodeEngine as createEngineWithTransport,
|
|
7
|
+
} from "./engine.mjs";
|
|
8
|
+
import { loadNodeWasmTransport } from "./candidates/wasm.mjs";
|
|
9
|
+
|
|
10
|
+
const wasmBindingPath = fileURLToPath(
|
|
11
|
+
new URL("../artifact/merman_node.cjs", import.meta.url),
|
|
12
|
+
);
|
|
13
|
+
const requireFromPackage = createRequire(import.meta.url);
|
|
14
|
+
|
|
15
|
+
export { MermanEngine };
|
|
16
|
+
|
|
17
|
+
export function createNodeEngine(options) {
|
|
18
|
+
return createEngineWithTransport(options, {
|
|
19
|
+
loadTransport: (optionsJson) =>
|
|
20
|
+
loadNodeWasmTransport(optionsJson, {
|
|
21
|
+
modulePath: wasmBindingPath,
|
|
22
|
+
loadModule: () => Promise.resolve(requireFromPackage(wasmBindingPath)),
|
|
23
|
+
}),
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
MermanDisposedError,
|
|
29
|
+
MermanError,
|
|
30
|
+
MermanInvalidTransportError,
|
|
31
|
+
MermanLifecycleError,
|
|
32
|
+
MermanMissingPlatformPackageError,
|
|
33
|
+
MermanNativeLoadError,
|
|
34
|
+
MermanOperationError,
|
|
35
|
+
MermanQueueSaturatedError,
|
|
36
|
+
MermanUnsupportedTargetError,
|
|
37
|
+
} from "./errors.mjs";
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
MermanInvalidTransportError,
|
|
5
|
+
MermanMissingPlatformPackageError,
|
|
6
|
+
MermanNativeLoadError,
|
|
7
|
+
MermanUnsupportedTargetError,
|
|
8
|
+
parseRuntimeCatalogJsonText,
|
|
9
|
+
} from "./errors.mjs";
|
|
10
|
+
|
|
11
|
+
const TARGET_PACKAGES = Object.freeze({
|
|
12
|
+
"darwin-arm64": "@mermanjs/node-darwin-arm64",
|
|
13
|
+
"darwin-x64": "@mermanjs/node-darwin-x64",
|
|
14
|
+
"linux-x64-gnu": "@mermanjs/node-linux-x64-gnu",
|
|
15
|
+
"linux-x64-musl": "@mermanjs/node-linux-x64-musl",
|
|
16
|
+
"win32-x64-msvc": "@mermanjs/node-win32-x64-msvc",
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const requireFromPackage = createRequire(import.meta.url);
|
|
20
|
+
const loaderPackageManifest = requireFromPackage("../package.json");
|
|
21
|
+
const loaderPackageVersion = loaderPackageManifest?.version;
|
|
22
|
+
|
|
23
|
+
if (typeof loaderPackageVersion !== "string" || loaderPackageVersion.length === 0) {
|
|
24
|
+
throw new Error("The Merman Node package manifest must declare a non-empty version.");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function nodeLoaderPackageVersion() {
|
|
28
|
+
return loaderPackageVersion;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function assertRuntimePackageVersion(value) {
|
|
32
|
+
const catalog = parseRuntimeCatalogJsonText(value);
|
|
33
|
+
if (catalog?.package_version !== loaderPackageVersion) {
|
|
34
|
+
throw new MermanInvalidTransportError(
|
|
35
|
+
`The Merman runtime package version ${JSON.stringify(catalog?.package_version)} does not match the loader package version ${JSON.stringify(loaderPackageVersion)}.`,
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function nativePackageName(target) {
|
|
42
|
+
const packageName = TARGET_PACKAGES[target];
|
|
43
|
+
if (!packageName) {
|
|
44
|
+
throw new MermanUnsupportedTargetError({
|
|
45
|
+
platform: target,
|
|
46
|
+
arch: "unknown",
|
|
47
|
+
reason: `Unknown Merman Node target id: ${target}.`,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return packageName;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function resolveNodeTarget({
|
|
54
|
+
platform = process.platform,
|
|
55
|
+
arch = process.arch,
|
|
56
|
+
report = platform === "linux" ? currentProcessReport() : null,
|
|
57
|
+
} = {}) {
|
|
58
|
+
if (platform === "darwin" && (arch === "arm64" || arch === "x64")) {
|
|
59
|
+
return `darwin-${arch}`;
|
|
60
|
+
}
|
|
61
|
+
if (platform === "win32" && arch === "x64") return "win32-x64-msvc";
|
|
62
|
+
if (platform === "linux" && arch === "x64") {
|
|
63
|
+
const libc = linuxLibc(report);
|
|
64
|
+
return `linux-x64-${libc}`;
|
|
65
|
+
}
|
|
66
|
+
throw new MermanUnsupportedTargetError({ platform, arch });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function loadNativeBinding({
|
|
70
|
+
platform = process.platform,
|
|
71
|
+
arch = process.arch,
|
|
72
|
+
report = platform === "linux" ? currentProcessReport() : null,
|
|
73
|
+
loadPackage = requireFromPackage,
|
|
74
|
+
} = {}) {
|
|
75
|
+
const target = resolveNodeTarget({ platform, arch, report });
|
|
76
|
+
const packageName = nativePackageName(target);
|
|
77
|
+
try {
|
|
78
|
+
return loadPackage(packageName);
|
|
79
|
+
} catch (cause) {
|
|
80
|
+
if (isMissingModule(cause)) {
|
|
81
|
+
throw new MermanMissingPlatformPackageError({ packageName, target, cause });
|
|
82
|
+
}
|
|
83
|
+
if (isNativeLoadFailure(cause)) {
|
|
84
|
+
throw new MermanNativeLoadError({ packageName, target, cause });
|
|
85
|
+
}
|
|
86
|
+
throw cause;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function linuxLibc(report) {
|
|
91
|
+
if (report?.header?.glibcVersionRuntime) return "gnu";
|
|
92
|
+
if (
|
|
93
|
+
Array.isArray(report?.sharedObjects) &&
|
|
94
|
+
report.sharedObjects.some((item) => /(?:^|[/\\])ld-musl-[^/\\]+\.so(?:\.1)?$/.test(item))
|
|
95
|
+
) {
|
|
96
|
+
return "musl";
|
|
97
|
+
}
|
|
98
|
+
throw new MermanUnsupportedTargetError({
|
|
99
|
+
platform: "linux",
|
|
100
|
+
arch: "x64",
|
|
101
|
+
reason:
|
|
102
|
+
"Cannot determine Linux libc from process.report; refusing to guess a platform package.",
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function currentProcessReport() {
|
|
107
|
+
return typeof process.report?.getReport === "function" ? process.report.getReport() : null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function isMissingModule(error) {
|
|
111
|
+
return Boolean(
|
|
112
|
+
error &&
|
|
113
|
+
typeof error === "object" &&
|
|
114
|
+
(error.code === "MODULE_NOT_FOUND" || error.code === "ERR_MODULE_NOT_FOUND"),
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function isNativeLoadFailure(error) {
|
|
119
|
+
if (!error || typeof error !== "object") return false;
|
|
120
|
+
if (error.code === "ERR_DLOPEN_FAILED") return true;
|
|
121
|
+
return typeof error.message === "string" &&
|
|
122
|
+
/(?:GLIBC(?:XX)?_|CXXABI_|invalid ELF|wrong ELF|shared object file|not a valid Win32|mach-?o)/i.test(
|
|
123
|
+
error.message,
|
|
124
|
+
);
|
|
125
|
+
}
|