@muxion/cabi-generate-cli-node 0.0.0-stage → 0.1.0
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 +79 -2
- package/dist/bridges.d.ts +5 -0
- package/dist/bridges.d.ts.map +1 -0
- package/dist/bridges.js +330 -0
- package/dist/bridges.js.map +1 -0
- package/dist/calls.d.ts +4 -0
- package/dist/calls.d.ts.map +1 -0
- package/dist/calls.js +131 -0
- package/dist/calls.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +35 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/names.d.ts +5 -0
- package/dist/names.d.ts.map +1 -0
- package/dist/names.js +56 -0
- package/dist/names.js.map +1 -0
- package/dist/native.d.ts +8 -0
- package/dist/native.d.ts.map +1 -0
- package/dist/native.js +390 -0
- package/dist/native.js.map +1 -0
- package/dist/schema.d.ts +71 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +512 -0
- package/dist/schema.js.map +1 -0
- package/dist/typescript.d.ts +3 -0
- package/dist/typescript.d.ts.map +1 -0
- package/dist/typescript.js +138 -0
- package/dist/typescript.js.map +1 -0
- package/package.json +48 -4
- package/schema/cabi-v2.schema.json +313 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/* oxlint-disable no-continue -- Empty variants and completed methods need no further generated code. */
|
|
2
|
+
/* oxlint-disable no-ternary -- Conditional expressions select generated target syntax. */
|
|
3
|
+
import { generateCalls } from './calls.js';
|
|
4
|
+
import { typeNames } from './names.js';
|
|
5
|
+
import { isPrimitive, resolveNode, variantIdLiteral, variantIdWords, } from './schema.js';
|
|
6
|
+
export const generateTypeScript = (schema) => {
|
|
7
|
+
const names = typeNames(schema);
|
|
8
|
+
const className = (index) => `${names.get(resolveNode(schema, index))}View`;
|
|
9
|
+
const imports = ['BinaryView'];
|
|
10
|
+
if (Object.keys(schema.functions).length > 0) {
|
|
11
|
+
imports.push('CabiError');
|
|
12
|
+
}
|
|
13
|
+
if (schema.nodes.some((node) => node.kind === 'offset_pointer' || node.kind === 'slice' || node.kind === 'array')) {
|
|
14
|
+
imports.push('validateRange');
|
|
15
|
+
}
|
|
16
|
+
if (schema.nodes.some((node) => node.kind === 'u64' ||
|
|
17
|
+
node.kind === 'i64' ||
|
|
18
|
+
node.kind === 'native_pointer' ||
|
|
19
|
+
((node.kind === 'union' || node.kind === 'enum') &&
|
|
20
|
+
(node.tag === 'u64' || node.tag === 'i64')))) {
|
|
21
|
+
imports.push('type Uint64Words');
|
|
22
|
+
}
|
|
23
|
+
const scalarTypes = new Set(['u32']);
|
|
24
|
+
for (const node of schema.nodes) {
|
|
25
|
+
if (isPrimitive(node.kind)) {
|
|
26
|
+
scalarTypes.add(node.kind);
|
|
27
|
+
}
|
|
28
|
+
if (node.kind === 'native_pointer') {
|
|
29
|
+
scalarTypes.add('u64');
|
|
30
|
+
}
|
|
31
|
+
if (node.kind === 'enum') {
|
|
32
|
+
scalarTypes.add(node.tag);
|
|
33
|
+
}
|
|
34
|
+
if (node.kind === 'union') {
|
|
35
|
+
scalarTypes.add(node.tag);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
imports.push(...[...scalarTypes].map((kind) => `type ${kind}`));
|
|
39
|
+
const output = [
|
|
40
|
+
'/* eslint-disable */',
|
|
41
|
+
'/* oxlint-disable */',
|
|
42
|
+
'// prettier-ignore',
|
|
43
|
+
'// Generated by cabi-generate-cli-node. Do not edit. ABI: little endian, version 2.',
|
|
44
|
+
`import { ${imports.join(', ')} } from '@muxion/cabi-runtime-js'`,
|
|
45
|
+
];
|
|
46
|
+
for (const [index, node] of [...schema.nodes.entries()].filter(([_index, value]) => value.kind !== 'ref' && value.kind !== 'unit')) {
|
|
47
|
+
const name = className(index);
|
|
48
|
+
const body = [
|
|
49
|
+
`export class ${name} extends BinaryView {`,
|
|
50
|
+
` static readonly size: u32 = ${node.size} as u32`,
|
|
51
|
+
` static readonly alignment: u32 = ${node.align} as u32`,
|
|
52
|
+
` constructor(buffer: Uint8Array, byteOffset: u32 = 0 as u32) { super(buffer, byteOffset, ${name}.size, ${name}.alignment) }`,
|
|
53
|
+
];
|
|
54
|
+
if (isPrimitive(node.kind) || node.kind === 'native_pointer' || node.kind === 'enum') {
|
|
55
|
+
let type = node.kind;
|
|
56
|
+
if (node.kind === 'native_pointer') {
|
|
57
|
+
type = 'u64';
|
|
58
|
+
}
|
|
59
|
+
if (node.kind === 'enum') {
|
|
60
|
+
type = node.tag;
|
|
61
|
+
}
|
|
62
|
+
body.push(` get value(): ${type} { return this.read${type.toUpperCase()}() }`, ` set value(value: ${type}) { this.write${type.toUpperCase()}(value) }`);
|
|
63
|
+
if (node.kind === 'enum') {
|
|
64
|
+
for (const [enumName, integer] of Object.entries(node.values)) {
|
|
65
|
+
body.push(` static readonly value_${enumName}: ${type} = ${integer}${type === 'u64' || type === 'i64' ? 'n' : ''} as ${type}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (type === 'u64' || type === 'i64') {
|
|
69
|
+
body.push(' get words(): Uint64Words { return this.readWords() }', ' set words(value: Uint64Words) { this.writeWords(value) }');
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else if (node.kind === 'struct') {
|
|
73
|
+
for (const field of node.fields) {
|
|
74
|
+
body.push(` get field_${field.name}(): ${className(field.node)} { return new ${className(field.node)}(this.buffer, (this.byteOffset + ${field.offset}) as u32) }`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else if (node.kind === 'offset_pointer') {
|
|
78
|
+
const item = schema.nodes[node.item];
|
|
79
|
+
body.push(' get offset(): u32 { return this.readU32() }', ' set offset(value: u32) { this.writeU32(value) }', ` deref(): ${className(node.item)} | null {`, ' const offset = this.offset', ' if (offset === 0) return null', ` validateRange(this.buffer, offset, 1 as u32, ${item.size} as u32, ${item.align} as u32)`, ` return new ${className(node.item)}(this.buffer, offset)`, ' }');
|
|
80
|
+
}
|
|
81
|
+
else if (node.kind === 'array' || node.kind === 'slice') {
|
|
82
|
+
const item = schema.nodes[node.item];
|
|
83
|
+
if (node.kind === 'slice') {
|
|
84
|
+
body.push(' get offset(): u32 { return this.readU32() }', ' set offset(value: u32) { this.writeU32(value) }', ' get length(): u32 { return this.readU32(4 as u32) }', ' set length(value: u32) { this.writeU32(value, 4 as u32) }', ` validate(): void { validateRange(this.buffer, this.offset, this.length, ${item.size} as u32, ${item.align} as u32) }`);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
body.push(` get length(): u32 { return ${node.length} as u32 }`);
|
|
88
|
+
}
|
|
89
|
+
body.push(` at(index: u32): ${className(node.item)} {`);
|
|
90
|
+
if (node.kind === 'slice') {
|
|
91
|
+
body.push(' this.validate()');
|
|
92
|
+
}
|
|
93
|
+
body.push(" if (index >= this.length) throw new RangeError('array index out of bounds')", ` return new ${className(node.item)}(this.buffer, (${node.kind === 'slice' ? 'this.offset' : 'this.byteOffset'} + index * ${item.size}) as u32)`, ' }');
|
|
94
|
+
if (node.kind === 'slice') {
|
|
95
|
+
body.push(` get data(): Uint8Array { this.validate(); return this.buffer.subarray(this.offset, this.offset + this.length * ${item.size}) }`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else if (node.kind === 'union') {
|
|
99
|
+
const tagType = node.tag;
|
|
100
|
+
body.push(` get tag(): ${tagType} { return this.read${node.tag.toUpperCase()}() }`, ` set tag(value: ${tagType}) { this.write${node.tag.toUpperCase()}(value) }`);
|
|
101
|
+
if (node.tag === 'u64') {
|
|
102
|
+
body.push(' get tagWords(): Uint64Words { return this.readWords() }', ' set tagWords(value: Uint64Words) { this.writeWords(value) }');
|
|
103
|
+
}
|
|
104
|
+
for (const variant of node.variants) {
|
|
105
|
+
const words = variantIdWords(variant.id);
|
|
106
|
+
body.push(` static readonly tag_${variant.name}: ${node.tag} = ${variantIdLiteral(variant.id)}${node.tag === 'u64' ? 'n' : ''} as ${node.tag}`);
|
|
107
|
+
if (node.tag === 'u64') {
|
|
108
|
+
body.push(` static readonly tagLow_${variant.name}: u32 = ${words.low} as u32`, ` static readonly tagHigh_${variant.name}: u32 = ${words.high} as u32`);
|
|
109
|
+
}
|
|
110
|
+
const matches = `this.tag === ${name}.tag_${variant.name}`;
|
|
111
|
+
if (schema.nodes[resolveNode(schema, variant.node)].kind === 'unit') {
|
|
112
|
+
body.push(` get variant_${variant.name}(): boolean { return ${matches} }`);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
body.push(` get variant_${variant.name}(): ${className(variant.node)} | null {`, ` return ${matches} ? new ${className(variant.node)}(this.buffer, (this.byteOffset + ${node.payloadOffset}) as u32) : null`, ' }');
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
body.push('}');
|
|
119
|
+
output.push(body.join('\n'));
|
|
120
|
+
}
|
|
121
|
+
for (const [name, index] of Object.entries(schema.types)) {
|
|
122
|
+
if (className(index) !== `${name}View`) {
|
|
123
|
+
output.push(`export { ${className(index)} as ${name}View }`);
|
|
124
|
+
}
|
|
125
|
+
const node = schema.nodes[resolveNode(schema, index)];
|
|
126
|
+
if (node.kind === 'union') {
|
|
127
|
+
output.push(`export const ${name}Tags = { ${node.variants.map((variant) => `${variant.name}: ${variantIdLiteral(variant.id)}${node.tag === 'u64' ? 'n' : ''}`).join(', ')} } as const`);
|
|
128
|
+
}
|
|
129
|
+
else if (node.kind === 'enum') {
|
|
130
|
+
output.push(`export const ${name}Values = { ${Object.entries(node.values)
|
|
131
|
+
.map(([valueName, value]) => `${valueName}: ${value}${node.tag === 'u64' || node.tag === 'i64' ? 'n' : ''}`)
|
|
132
|
+
.join(', ')} } as const`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
output.push(generateCalls(schema));
|
|
136
|
+
return `${output.join('\n\n').trimEnd()}\n`;
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AS,KAAK,KAAK,GAAG,IAAI,CAAC,GAAG,KAAK,KAAK,IAAI,IAAI,CAAC,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CACjF;iBACA,IAAI,CAAC,IAAI,CAAC,aAAa,CAC3B,CAAA;QACH,CAAC;IACH,CAAC;IACD,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAA;IAClC,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,IAAI,CAAA;AAC7C,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@muxion/cabi-generate-cli-node",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/vietthang/muxion-common.git"
|
|
8
|
+
},
|
|
9
|
+
"bin": {
|
|
10
|
+
"cabi": "dist/cli.js"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"README.md",
|
|
15
|
+
"schema"
|
|
16
|
+
],
|
|
17
|
+
"type": "module",
|
|
18
|
+
"main": "dist/index.js",
|
|
19
|
+
"types": "dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"default": "./dist/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./schema": "./schema/cabi-v2.schema.json"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsc -p tsconfig.json",
|
|
32
|
+
"test": "vitest run",
|
|
33
|
+
"lint": "oxlint src test --tsconfig tsconfig.test.json --deny-warnings && tsc -p tsconfig.test.json",
|
|
34
|
+
"generate": "node dist/cli.js"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@commander-js/extra-typings": "*",
|
|
38
|
+
"@muxion/cabi-runtime-js": "0.1.1",
|
|
39
|
+
"commander": "*",
|
|
40
|
+
"yaml": "*"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/node": "*",
|
|
44
|
+
"ajv": "*",
|
|
45
|
+
"oxlint": "*",
|
|
46
|
+
"typescript": "*",
|
|
47
|
+
"vite": "*",
|
|
48
|
+
"vitest": "*"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://fluxmux.dev/schema/cabi-v2.schema.json",
|
|
4
|
+
"title": "Muxion JSON ABI version 2",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"version": {
|
|
8
|
+
"const": 2
|
|
9
|
+
},
|
|
10
|
+
"namespace": {
|
|
11
|
+
"type": "string",
|
|
12
|
+
"pattern": "^[a-z][a-z0-9_]*$"
|
|
13
|
+
},
|
|
14
|
+
"abiVersion": {
|
|
15
|
+
"type": "integer",
|
|
16
|
+
"minimum": 1,
|
|
17
|
+
"maximum": 4294967295
|
|
18
|
+
},
|
|
19
|
+
"types": {
|
|
20
|
+
"type": "object",
|
|
21
|
+
"minProperties": 1,
|
|
22
|
+
"propertyNames": {
|
|
23
|
+
"type": "string",
|
|
24
|
+
"pattern": "^[A-Za-z][A-Za-z0-9_]*$"
|
|
25
|
+
},
|
|
26
|
+
"additionalProperties": {
|
|
27
|
+
"anyOf": [
|
|
28
|
+
{
|
|
29
|
+
"$ref": "#/$defs/value"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"type": "object",
|
|
33
|
+
"properties": {
|
|
34
|
+
"type": {
|
|
35
|
+
"const": "native_pointer"
|
|
36
|
+
},
|
|
37
|
+
"target": {
|
|
38
|
+
"type": "string",
|
|
39
|
+
"pattern": "^[A-Za-z][A-Za-z0-9_]*$"
|
|
40
|
+
},
|
|
41
|
+
"release": {
|
|
42
|
+
"type": "string",
|
|
43
|
+
"pattern": "^[a-z][a-z0-9_]*$"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"required": ["type", "target", "release"],
|
|
47
|
+
"additionalProperties": false
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"functions": {
|
|
53
|
+
"type": "object",
|
|
54
|
+
"propertyNames": {
|
|
55
|
+
"type": "string",
|
|
56
|
+
"pattern": "^[a-z][a-z0-9_]*$"
|
|
57
|
+
},
|
|
58
|
+
"additionalProperties": {
|
|
59
|
+
"$ref": "#/$defs/function"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"required": ["version", "namespace", "abiVersion", "types", "functions"],
|
|
64
|
+
"additionalProperties": false,
|
|
65
|
+
"$defs": {
|
|
66
|
+
"value": {
|
|
67
|
+
"oneOf": [
|
|
68
|
+
{
|
|
69
|
+
"type": "object",
|
|
70
|
+
"properties": {
|
|
71
|
+
"$ref": {
|
|
72
|
+
"type": "string",
|
|
73
|
+
"pattern": "^[A-Za-z][A-Za-z0-9_]*$"
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
"required": ["$ref"],
|
|
77
|
+
"additionalProperties": false
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"type": "object",
|
|
81
|
+
"properties": {
|
|
82
|
+
"type": {
|
|
83
|
+
"enum": ["u8", "i8", "u16", "i16", "u32", "i32", "u64", "i64", "f32", "f64"]
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
"required": ["type"],
|
|
87
|
+
"additionalProperties": false
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"type": "object",
|
|
91
|
+
"properties": {
|
|
92
|
+
"type": {
|
|
93
|
+
"const": "array"
|
|
94
|
+
},
|
|
95
|
+
"items": {
|
|
96
|
+
"$ref": "#/$defs/value"
|
|
97
|
+
},
|
|
98
|
+
"length": {
|
|
99
|
+
"type": "integer",
|
|
100
|
+
"minimum": 1,
|
|
101
|
+
"maximum": 4294967295
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
"required": ["type", "items", "length"],
|
|
105
|
+
"additionalProperties": false
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"type": "object",
|
|
109
|
+
"properties": {
|
|
110
|
+
"type": {
|
|
111
|
+
"const": "offset_pointer"
|
|
112
|
+
},
|
|
113
|
+
"items": {
|
|
114
|
+
"$ref": "#/$defs/value"
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
"required": ["type", "items"],
|
|
118
|
+
"additionalProperties": false
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"type": "object",
|
|
122
|
+
"properties": {
|
|
123
|
+
"type": {
|
|
124
|
+
"const": "slice"
|
|
125
|
+
},
|
|
126
|
+
"items": {
|
|
127
|
+
"$ref": "#/$defs/value"
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
"required": ["type", "items"],
|
|
131
|
+
"additionalProperties": false
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
"type": "object",
|
|
135
|
+
"properties": {
|
|
136
|
+
"type": {
|
|
137
|
+
"const": "struct"
|
|
138
|
+
},
|
|
139
|
+
"fields": {
|
|
140
|
+
"type": "array",
|
|
141
|
+
"items": {
|
|
142
|
+
"type": "object",
|
|
143
|
+
"properties": {
|
|
144
|
+
"name": {
|
|
145
|
+
"type": "string",
|
|
146
|
+
"pattern": "^[A-Za-z][A-Za-z0-9_]*$"
|
|
147
|
+
},
|
|
148
|
+
"value": {
|
|
149
|
+
"$ref": "#/$defs/value"
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
"required": ["name", "value"],
|
|
153
|
+
"additionalProperties": false
|
|
154
|
+
},
|
|
155
|
+
"minItems": 1
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
"required": ["type", "fields"],
|
|
159
|
+
"additionalProperties": false
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
"type": "object",
|
|
163
|
+
"properties": {
|
|
164
|
+
"type": {
|
|
165
|
+
"const": "enum"
|
|
166
|
+
},
|
|
167
|
+
"repr": {
|
|
168
|
+
"enum": ["u8", "i8", "u16", "i16", "u32", "i32", "u64", "i64"]
|
|
169
|
+
},
|
|
170
|
+
"values": {
|
|
171
|
+
"type": "object",
|
|
172
|
+
"minProperties": 1,
|
|
173
|
+
"propertyNames": {
|
|
174
|
+
"type": "string",
|
|
175
|
+
"pattern": "^[A-Za-z][A-Za-z0-9_]*$"
|
|
176
|
+
},
|
|
177
|
+
"additionalProperties": {
|
|
178
|
+
"type": "integer",
|
|
179
|
+
"minimum": -9007199254740991,
|
|
180
|
+
"maximum": 9007199254740991
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
"required": ["type", "repr", "values"],
|
|
185
|
+
"additionalProperties": false
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
"type": "object",
|
|
189
|
+
"properties": {
|
|
190
|
+
"type": {
|
|
191
|
+
"const": "union"
|
|
192
|
+
},
|
|
193
|
+
"tag": {
|
|
194
|
+
"type": "object",
|
|
195
|
+
"properties": {
|
|
196
|
+
"type": {
|
|
197
|
+
"enum": ["u8", "u16", "u32", "u64"]
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
"required": ["type"],
|
|
201
|
+
"additionalProperties": false
|
|
202
|
+
},
|
|
203
|
+
"variants": {
|
|
204
|
+
"type": "array",
|
|
205
|
+
"items": {
|
|
206
|
+
"type": "object",
|
|
207
|
+
"properties": {
|
|
208
|
+
"name": {
|
|
209
|
+
"type": "string",
|
|
210
|
+
"pattern": "^[A-Za-z][A-Za-z0-9_]*$"
|
|
211
|
+
},
|
|
212
|
+
"id": {
|
|
213
|
+
"type": "integer",
|
|
214
|
+
"minimum": 0,
|
|
215
|
+
"maximum": 9007199254740991
|
|
216
|
+
},
|
|
217
|
+
"value": {
|
|
218
|
+
"anyOf": [
|
|
219
|
+
{
|
|
220
|
+
"$ref": "#/$defs/value"
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
"type": "object",
|
|
224
|
+
"properties": {
|
|
225
|
+
"type": {
|
|
226
|
+
"const": "unit"
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
"required": ["type"],
|
|
230
|
+
"additionalProperties": false
|
|
231
|
+
}
|
|
232
|
+
]
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
"required": ["name", "id", "value"],
|
|
236
|
+
"additionalProperties": false
|
|
237
|
+
},
|
|
238
|
+
"minItems": 1
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
"required": ["type", "tag", "variants"],
|
|
242
|
+
"additionalProperties": false
|
|
243
|
+
}
|
|
244
|
+
]
|
|
245
|
+
},
|
|
246
|
+
"parameter": {
|
|
247
|
+
"oneOf": [
|
|
248
|
+
{
|
|
249
|
+
"type": "object",
|
|
250
|
+
"properties": {
|
|
251
|
+
"name": {
|
|
252
|
+
"type": "string",
|
|
253
|
+
"pattern": "^[A-Za-z][A-Za-z0-9_]*$"
|
|
254
|
+
},
|
|
255
|
+
"value": {
|
|
256
|
+
"$ref": "#/$defs/value"
|
|
257
|
+
},
|
|
258
|
+
"access": {
|
|
259
|
+
"enum": ["read", "write", "read_write"]
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
"required": ["name", "value"],
|
|
263
|
+
"additionalProperties": false
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
"type": "object",
|
|
267
|
+
"properties": {
|
|
268
|
+
"name": {
|
|
269
|
+
"type": "string",
|
|
270
|
+
"pattern": "^[A-Za-z][A-Za-z0-9_]*$"
|
|
271
|
+
},
|
|
272
|
+
"value": {
|
|
273
|
+
"type": "object",
|
|
274
|
+
"properties": {
|
|
275
|
+
"type": {
|
|
276
|
+
"const": "arena_bytes"
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
"required": ["type"],
|
|
280
|
+
"additionalProperties": false
|
|
281
|
+
}
|
|
282
|
+
},
|
|
283
|
+
"required": ["name", "value"],
|
|
284
|
+
"additionalProperties": false
|
|
285
|
+
}
|
|
286
|
+
]
|
|
287
|
+
},
|
|
288
|
+
"function": {
|
|
289
|
+
"type": "object",
|
|
290
|
+
"properties": {
|
|
291
|
+
"params": {
|
|
292
|
+
"type": "array",
|
|
293
|
+
"items": {
|
|
294
|
+
"$ref": "#/$defs/parameter"
|
|
295
|
+
},
|
|
296
|
+
"minItems": 0
|
|
297
|
+
},
|
|
298
|
+
"returns": {
|
|
299
|
+
"anyOf": [
|
|
300
|
+
{
|
|
301
|
+
"$ref": "#/$defs/value"
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
"type": "null"
|
|
305
|
+
}
|
|
306
|
+
]
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
"required": ["params", "returns"],
|
|
310
|
+
"additionalProperties": false
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|