space-data-module-sdk 0.2.6 → 0.2.8
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/README.md +73 -0
- package/package.json +5 -1
- package/schemas/PluginManifest.fbs +10 -0
- package/src/bundle/constants.js +4 -1
- package/src/bundle/wasm.js +30 -2
- package/src/compliance/index.js +2 -1
- package/src/compliance/pluginCompliance.js +391 -2
- package/src/deployment/index.d.ts +224 -0
- package/src/deployment/index.js +1552 -0
- package/src/generated/orbpro/manifest/plugin-manifest.d.ts +10 -3
- package/src/generated/orbpro/manifest/plugin-manifest.js +32 -6
- package/src/generated/orbpro/manifest/plugin-manifest.ts +42 -5
- package/src/generated/orbpro/manifest/protocol-spec.d.ts +35 -3
- package/src/generated/orbpro/manifest/protocol-spec.js +120 -6
- package/src/generated/orbpro/manifest/protocol-spec.ts +191 -1
- package/src/index.d.ts +138 -3
- package/src/index.js +4 -0
- package/src/manifest/index.js +7 -0
- package/src/manifest/normalize.js +82 -11
- package/src/manifest/typeRefs.js +143 -0
- package/src/runtime/constants.js +14 -0
- package/src/runtime/index.d.ts +2 -0
- package/src/testing/index.d.ts +86 -0
- package/src/testing/index.js +473 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
function cloneSchemaHash(value) {
|
|
2
|
+
if (value instanceof Uint8Array) {
|
|
3
|
+
return new Uint8Array(value);
|
|
4
|
+
}
|
|
5
|
+
if (Array.isArray(value)) {
|
|
6
|
+
return [...value];
|
|
7
|
+
}
|
|
8
|
+
return value ?? undefined;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function clonePayloadTypeRef(value = null) {
|
|
12
|
+
if (!value || typeof value !== "object") {
|
|
13
|
+
return { acceptsAnyFlatbuffer: true };
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
schemaName: value.schemaName ?? value.schema_name ?? undefined,
|
|
17
|
+
fileIdentifier: value.fileIdentifier ?? value.file_identifier ?? undefined,
|
|
18
|
+
schemaHash: cloneSchemaHash(value.schemaHash ?? value.schema_hash),
|
|
19
|
+
acceptsAnyFlatbuffer: Boolean(
|
|
20
|
+
value.acceptsAnyFlatbuffer ?? value.accepts_any_flatbuffer ?? false,
|
|
21
|
+
),
|
|
22
|
+
wireFormat: value.wireFormat ?? value.wire_format ?? undefined,
|
|
23
|
+
rootTypeName: value.rootTypeName ?? value.root_type_name ?? undefined,
|
|
24
|
+
fixedStringLength:
|
|
25
|
+
value.fixedStringLength ?? value.fixed_string_length ?? undefined,
|
|
26
|
+
byteLength: value.byteLength ?? value.byte_length ?? undefined,
|
|
27
|
+
requiredAlignment:
|
|
28
|
+
value.requiredAlignment ?? value.required_alignment ?? undefined,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function normalizePayloadWireFormatName(value) {
|
|
33
|
+
if (value === undefined || value === null || value === "") {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const normalized = String(value).trim().toLowerCase().replace(/_/g, "-");
|
|
37
|
+
if (normalized === "aligned-binary") {
|
|
38
|
+
return "aligned-binary";
|
|
39
|
+
}
|
|
40
|
+
if (normalized === "flatbuffer") {
|
|
41
|
+
return "flatbuffer";
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function getPayloadTypeWireFormat(typeRef = {}) {
|
|
47
|
+
return normalizePayloadWireFormatName(typeRef.wireFormat) ?? "flatbuffer";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function schemaHashMatches(expected, actual) {
|
|
51
|
+
if (!Array.isArray(expected) && !(expected instanceof Uint8Array)) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
const expectedArray = Array.from(expected);
|
|
55
|
+
if (expectedArray.length === 0) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
const actualArray =
|
|
59
|
+
Array.isArray(actual) || actual instanceof Uint8Array
|
|
60
|
+
? Array.from(actual)
|
|
61
|
+
: null;
|
|
62
|
+
if (!actualArray || actualArray.length !== expectedArray.length) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
for (let index = 0; index < expectedArray.length; index += 1) {
|
|
66
|
+
if (expectedArray[index] !== actualArray[index]) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function optionalScalarMatches(expected, actual) {
|
|
74
|
+
return expected === undefined || expected === null || expected === actual;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function payloadTypeRefsMatch(expectedTypeRef = {}, actualTypeRef = {}) {
|
|
78
|
+
const expected = clonePayloadTypeRef(expectedTypeRef);
|
|
79
|
+
const actual = clonePayloadTypeRef(actualTypeRef);
|
|
80
|
+
const expectedWireFormat = getPayloadTypeWireFormat(expected);
|
|
81
|
+
const actualWireFormat = getPayloadTypeWireFormat(actual);
|
|
82
|
+
|
|
83
|
+
if (expected.acceptsAnyFlatbuffer === true) {
|
|
84
|
+
return actualWireFormat === "flatbuffer";
|
|
85
|
+
}
|
|
86
|
+
if (expectedWireFormat !== actualWireFormat) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
if (expected.schemaName && expected.schemaName !== actual.schemaName) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
if (
|
|
93
|
+
expected.fileIdentifier &&
|
|
94
|
+
expected.fileIdentifier !== actual.fileIdentifier
|
|
95
|
+
) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
if (!schemaHashMatches(expected.schemaHash, actual.schemaHash)) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
if (expectedWireFormat === "aligned-binary") {
|
|
102
|
+
if (!optionalScalarMatches(expected.rootTypeName, actual.rootTypeName)) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
if (!optionalScalarMatches(expected.fixedStringLength, actual.fixedStringLength)) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
if (!optionalScalarMatches(expected.byteLength, actual.byteLength)) {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
if (
|
|
112
|
+
!optionalScalarMatches(expected.requiredAlignment, actual.requiredAlignment)
|
|
113
|
+
) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function selectPreferredPayloadTypeRef(port = {}, options = {}) {
|
|
121
|
+
const preferredWireFormat = normalizePayloadWireFormatName(
|
|
122
|
+
options.preferredWireFormat,
|
|
123
|
+
);
|
|
124
|
+
let fallback = null;
|
|
125
|
+
for (const typeSet of Array.isArray(port.acceptedTypeSets) ? port.acceptedTypeSets : []) {
|
|
126
|
+
const allowedTypes = Array.isArray(typeSet.allowedTypes)
|
|
127
|
+
? typeSet.allowedTypes
|
|
128
|
+
: [];
|
|
129
|
+
for (const allowedType of allowedTypes) {
|
|
130
|
+
const candidate = clonePayloadTypeRef(allowedType);
|
|
131
|
+
if (fallback === null) {
|
|
132
|
+
fallback = candidate;
|
|
133
|
+
}
|
|
134
|
+
if (
|
|
135
|
+
preferredWireFormat !== null &&
|
|
136
|
+
getPayloadTypeWireFormat(candidate) === preferredWireFormat
|
|
137
|
+
) {
|
|
138
|
+
return candidate;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return fallback ?? clonePayloadTypeRef(null);
|
|
143
|
+
}
|
package/src/runtime/constants.js
CHANGED
|
@@ -38,6 +38,7 @@ export const RuntimeTarget = Object.freeze({
|
|
|
38
38
|
NODE: "node",
|
|
39
39
|
BROWSER: "browser",
|
|
40
40
|
WASI: "wasi",
|
|
41
|
+
WASMEDGE: "wasmedge",
|
|
41
42
|
SERVER: "server",
|
|
42
43
|
DESKTOP: "desktop",
|
|
43
44
|
EDGE: "edge",
|
|
@@ -48,6 +49,19 @@ export const InvokeSurface = Object.freeze({
|
|
|
48
49
|
COMMAND: "command",
|
|
49
50
|
});
|
|
50
51
|
|
|
52
|
+
export const ProtocolTransportKind = Object.freeze({
|
|
53
|
+
LIBP2P: "libp2p",
|
|
54
|
+
HTTP: "http",
|
|
55
|
+
WS: "ws",
|
|
56
|
+
WASI_PIPE: "wasi-pipe",
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
export const ProtocolRole = Object.freeze({
|
|
60
|
+
HANDLE: "handle",
|
|
61
|
+
DIAL: "dial",
|
|
62
|
+
BOTH: "both",
|
|
63
|
+
});
|
|
64
|
+
|
|
51
65
|
export const DefaultManifestExports = Object.freeze({
|
|
52
66
|
pluginBytesSymbol: "plugin_get_manifest_flatbuffer",
|
|
53
67
|
pluginSizeSymbol: "plugin_get_manifest_flatbuffer_size",
|
package/src/runtime/index.d.ts
CHANGED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
InvokeSurface,
|
|
3
|
+
PayloadTypeRef,
|
|
4
|
+
PayloadWireFormat,
|
|
5
|
+
PluginManifest,
|
|
6
|
+
} from "../index.js";
|
|
7
|
+
|
|
8
|
+
export interface HarnessInputFrame {
|
|
9
|
+
portId?: string | null;
|
|
10
|
+
typeRef?: PayloadTypeRef | null;
|
|
11
|
+
payload?: Uint8Array | ArrayBuffer | ArrayBufferView | string | null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface HarnessInvokeScenario {
|
|
15
|
+
id: string;
|
|
16
|
+
kind: "invoke";
|
|
17
|
+
surface: InvokeSurface;
|
|
18
|
+
methodId: string;
|
|
19
|
+
displayName?: string | null;
|
|
20
|
+
inputs?: HarnessInputFrame[];
|
|
21
|
+
requiredPortIds?: string[];
|
|
22
|
+
expectedStatusCode?: number;
|
|
23
|
+
notes?: string[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface HarnessRawScenario {
|
|
27
|
+
id: string;
|
|
28
|
+
kind: string;
|
|
29
|
+
stdinBytes?: Uint8Array | ArrayBuffer | ArrayBufferView | string | null;
|
|
30
|
+
notes?: string[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface CapabilityRuntimeSurface {
|
|
34
|
+
capability: string;
|
|
35
|
+
wasi: boolean;
|
|
36
|
+
standaloneWasi: boolean;
|
|
37
|
+
wasmedge: boolean;
|
|
38
|
+
syncHostcall: boolean;
|
|
39
|
+
nodeHostApi: boolean;
|
|
40
|
+
notes: string[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface ManifestHarnessPlan {
|
|
44
|
+
moduleKind: "module" | "flow";
|
|
45
|
+
pluginId: string | null;
|
|
46
|
+
name: string | null;
|
|
47
|
+
version: string | null;
|
|
48
|
+
invokeSurfaces: InvokeSurface[];
|
|
49
|
+
methods: Array<{
|
|
50
|
+
methodId: string | null;
|
|
51
|
+
displayName: string | null;
|
|
52
|
+
inputPorts: number;
|
|
53
|
+
outputPorts: number;
|
|
54
|
+
}>;
|
|
55
|
+
capabilities: CapabilityRuntimeSurface[];
|
|
56
|
+
generatedCases: HarnessInvokeScenario[];
|
|
57
|
+
scenarios: Array<HarnessInvokeScenario | HarnessRawScenario>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function describeCapabilityRuntimeSurface(
|
|
61
|
+
capability: string,
|
|
62
|
+
): CapabilityRuntimeSurface;
|
|
63
|
+
|
|
64
|
+
export function generateManifestHarnessPlan(options: {
|
|
65
|
+
manifest: PluginManifest;
|
|
66
|
+
includeOptionalInputs?: boolean;
|
|
67
|
+
expectedStatusCode?: number;
|
|
68
|
+
preferredWireFormat?: PayloadWireFormat;
|
|
69
|
+
payloadForPort?: (context: {
|
|
70
|
+
methodId: string | null;
|
|
71
|
+
portId: string | null;
|
|
72
|
+
port: unknown;
|
|
73
|
+
required: boolean;
|
|
74
|
+
typeRef: PayloadTypeRef;
|
|
75
|
+
}) => Uint8Array | ArrayBuffer | ArrayBufferView | string | null | undefined;
|
|
76
|
+
scenarios?: Array<HarnessInvokeScenario | HarnessRawScenario>;
|
|
77
|
+
}): ManifestHarnessPlan;
|
|
78
|
+
|
|
79
|
+
export function materializeHarnessScenario(
|
|
80
|
+
scenario: HarnessInvokeScenario | HarnessRawScenario,
|
|
81
|
+
): (HarnessInvokeScenario | HarnessRawScenario) & {
|
|
82
|
+
stdinBytes?: Uint8Array;
|
|
83
|
+
requestBytes?: Uint8Array;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export function serializeHarnessPlan(plan: ManifestHarnessPlan): unknown;
|