@idlizer/core 2.0.41 → 2.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/build/lib/src/LanguageWriters/ArgConvertors.d.ts +4 -1
- package/build/lib/src/LanguageWriters/ArgConvertors.js +61 -13
- package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +7 -5
- package/build/lib/src/LanguageWriters/LanguageWriter.js +8 -3
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.d.ts +2 -1
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +27 -12
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.d.ts +3 -1
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +3 -1
- package/build/lib/src/LanguageWriters/convertors/InteropConvertors.js +4 -4
- package/build/lib/src/LanguageWriters/convertors/TSConvertors.d.ts +11 -1
- package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +44 -1
- package/build/lib/src/LanguageWriters/index.d.ts +2 -2
- package/build/lib/src/LanguageWriters/index.js +4 -5
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +4 -4
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +6 -5
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.d.ts +4 -3
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +5 -8
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.d.ts +6 -5
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +26 -30
- package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.d.ts +3 -3
- package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.js +4 -4
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +3 -3
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +21 -12
- package/build/lib/src/config.d.ts +958 -12
- package/build/lib/src/config.js +24 -2
- package/build/lib/src/configDescriber.d.ts +85 -0
- package/build/lib/src/configDescriber.js +297 -0
- package/build/lib/src/from-idl/DtsPrinter.js +4 -2
- package/build/lib/src/from-idl/IDLLinter.d.ts +24 -0
- package/build/lib/src/from-idl/IDLLinter.js +81 -0
- package/build/lib/src/from-idl/deserialize.js +41 -4
- package/build/lib/src/from-idl/webidl2-utils.d.ts +1 -0
- package/build/lib/src/from-idl/webidl2-utils.js +3 -0
- package/build/lib/src/idl.d.ts +23 -26
- package/build/lib/src/idl.js +31 -29
- package/build/lib/src/idlize.d.ts +10 -1
- package/build/lib/src/idlize.js +54 -26
- package/build/lib/src/index.d.ts +2 -0
- package/build/lib/src/index.js +2 -0
- package/build/lib/src/options.d.ts +1 -0
- package/build/lib/src/peer-generation/Materialized.d.ts +2 -1
- package/build/lib/src/peer-generation/Materialized.js +3 -2
- package/build/lib/src/peer-generation/PeerFile.d.ts +1 -2
- package/build/lib/src/peer-generation/PeerFile.js +1 -2
- package/build/lib/src/peer-generation/PeerLibrary.d.ts +0 -1
- package/build/lib/src/peer-generation/PeerLibrary.js +16 -3
- package/build/lib/src/peer-generation/PeerMethod.js +2 -16
- package/build/lib/src/peer-generation/idl/common.js +2 -2
- package/build/lib/src/peer-generation/isMaterialized.d.ts +1 -0
- package/build/lib/src/peer-generation/isMaterialized.js +21 -0
- package/build/lib/src/util.d.ts +1 -0
- package/build/lib/src/util.js +9 -0
- package/package.json +2 -2
package/build/lib/src/config.js
CHANGED
|
@@ -12,7 +12,24 @@
|
|
|
12
12
|
* See the License for the specific language governing permissions and
|
|
13
13
|
* limitations under the License.
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
import { D } from "./configDescriber";
|
|
16
|
+
const T = {
|
|
17
|
+
stringArray: () => D.array(D.string())
|
|
18
|
+
};
|
|
19
|
+
export const CoreConfigurationSchema = D.object({
|
|
20
|
+
TypePrefix: D.string(),
|
|
21
|
+
LibraryPrefix: D.string(),
|
|
22
|
+
OptionalPrefix: D.string(),
|
|
23
|
+
rootComponents: T.stringArray(),
|
|
24
|
+
standaloneComponents: T.stringArray(),
|
|
25
|
+
parameterized: T.stringArray(),
|
|
26
|
+
ignoreMaterialized: T.stringArray(),
|
|
27
|
+
builderClasses: T.stringArray(),
|
|
28
|
+
forceMaterialized: T.stringArray(),
|
|
29
|
+
forceCallback: T.stringArray(),
|
|
30
|
+
forceContext: T.stringArray(),
|
|
31
|
+
});
|
|
32
|
+
export const defaultCoreConfiguration = {
|
|
16
33
|
TypePrefix: "",
|
|
17
34
|
LibraryPrefix: "",
|
|
18
35
|
OptionalPrefix: "",
|
|
@@ -22,11 +39,16 @@ export const defaultCoreConfuguration = {
|
|
|
22
39
|
ignoreMaterialized: [],
|
|
23
40
|
builderClasses: [],
|
|
24
41
|
forceMaterialized: [],
|
|
42
|
+
forceCallback: [],
|
|
43
|
+
forceContext: [],
|
|
25
44
|
};
|
|
26
|
-
let currentConfig =
|
|
45
|
+
let currentConfig = defaultCoreConfiguration;
|
|
27
46
|
export function setDefaultConfiguration(config) {
|
|
28
47
|
currentConfig = config;
|
|
29
48
|
}
|
|
49
|
+
export function patchDefaultConfiguration(config) {
|
|
50
|
+
currentConfig = Object.assign({}, currentConfig, config);
|
|
51
|
+
}
|
|
30
52
|
export function generatorConfiguration() {
|
|
31
53
|
return currentConfig;
|
|
32
54
|
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
export interface JsonSchemaLeaf {
|
|
2
|
+
type?: string;
|
|
3
|
+
description?: string;
|
|
4
|
+
}
|
|
5
|
+
export interface JsonSchemaArray extends JsonSchemaLeaf {
|
|
6
|
+
items: JsonSchemaNode;
|
|
7
|
+
}
|
|
8
|
+
export interface JsonSchemaTuple extends JsonSchemaLeaf {
|
|
9
|
+
items: JsonSchemaNode[];
|
|
10
|
+
}
|
|
11
|
+
export interface JsonSchemaMap extends JsonSchemaLeaf {
|
|
12
|
+
additionalProperties: JsonSchemaNode;
|
|
13
|
+
}
|
|
14
|
+
export interface JsonSchemaObject extends JsonSchemaLeaf {
|
|
15
|
+
properties: Record<string, JsonSchemaNode>;
|
|
16
|
+
required: string[];
|
|
17
|
+
additionalProperties: boolean;
|
|
18
|
+
}
|
|
19
|
+
export type JsonSchemaNode = JsonSchemaLeaf | JsonSchemaArray | JsonSchemaTuple | JsonSchemaMap | JsonSchemaObject;
|
|
20
|
+
export interface JsonSchema {
|
|
21
|
+
$ref: string;
|
|
22
|
+
$schema: string;
|
|
23
|
+
definitions: Record<string, JsonSchemaNode>;
|
|
24
|
+
}
|
|
25
|
+
type UnwrapConfigDescriberLeaf<T> = T extends ConfigDescriberLeaf<infer K> ? K : never;
|
|
26
|
+
type ObjectDescriptionToType<T extends {}> = {
|
|
27
|
+
readonly [x in keyof T]: UnwrapConfigDescriberLeaf<T[x]>;
|
|
28
|
+
};
|
|
29
|
+
type TraverseTuple<Ts extends any[]> = Ts extends [] ? [] : Ts extends [infer Head, ...infer Rest] ? [UnwrapConfigDescriberLeaf<Head>, ...TraverseTuple<Rest>] : never;
|
|
30
|
+
export interface ValidationSuccess<T> {
|
|
31
|
+
success: true;
|
|
32
|
+
value: T;
|
|
33
|
+
}
|
|
34
|
+
export interface ValidationFailure {
|
|
35
|
+
success: false;
|
|
36
|
+
errorMessage: string;
|
|
37
|
+
}
|
|
38
|
+
export type ValidationResult<T> = ValidationSuccess<T> | ValidationFailure;
|
|
39
|
+
declare class ValidationBox<T> {
|
|
40
|
+
box: ValidationResult<T>;
|
|
41
|
+
constructor(box: ValidationResult<T>);
|
|
42
|
+
static fail<T>(errorMessage: string): ValidationBox<T>;
|
|
43
|
+
static ok<T>(value: T): ValidationBox<T>;
|
|
44
|
+
success(): boolean;
|
|
45
|
+
unwrap(): T;
|
|
46
|
+
error(): string;
|
|
47
|
+
get(): ValidationResult<T>;
|
|
48
|
+
or<U>(x: U): ValidationBox<U | T>;
|
|
49
|
+
}
|
|
50
|
+
declare class ConfigDescriberLeaf<T> {
|
|
51
|
+
validate: (x: unknown) => ValidationBox<T>;
|
|
52
|
+
printSchema: () => JsonSchemaNode;
|
|
53
|
+
constructor(validate: (x: unknown) => ValidationBox<T>, printSchema: () => JsonSchemaNode);
|
|
54
|
+
}
|
|
55
|
+
declare class ConfigDescriberOptionalLeaf<T> extends ConfigDescriberLeaf<T> {
|
|
56
|
+
constructor(validate: (x: unknown) => ValidationBox<T>, printSchema: () => JsonSchemaNode);
|
|
57
|
+
}
|
|
58
|
+
declare class ConfigDescriberObjectLeaf<T> extends ConfigDescriberLeaf<T> {
|
|
59
|
+
schema: Record<string, ConfigDescriberLeaf<T>>;
|
|
60
|
+
constructor(validate: (x: unknown) => ValidationBox<T>, printSchema: () => JsonSchemaNode, schema: Record<string, ConfigDescriberLeaf<T>>);
|
|
61
|
+
}
|
|
62
|
+
export type ConfigSchema<T> = ConfigDescriberLeaf<T>;
|
|
63
|
+
export interface CommonBuilderConfig<T> {
|
|
64
|
+
default?: T;
|
|
65
|
+
description?: string;
|
|
66
|
+
}
|
|
67
|
+
export declare const D: {
|
|
68
|
+
number(config?: CommonBuilderConfig<number>): ConfigDescriberLeaf<number>;
|
|
69
|
+
string(config?: CommonBuilderConfig<string>): ConfigDescriberLeaf<string>;
|
|
70
|
+
boolean(config?: CommonBuilderConfig<boolean>): ConfigDescriberLeaf<boolean>;
|
|
71
|
+
bigint(config?: CommonBuilderConfig<bigint>): ConfigDescriberLeaf<bigint>;
|
|
72
|
+
null(config?: CommonBuilderConfig<null>): ConfigDescriberLeaf<null>;
|
|
73
|
+
undefined(config?: CommonBuilderConfig<undefined>): ConfigDescriberLeaf<undefined>;
|
|
74
|
+
object<K extends Record<string, ConfigDescriberLeaf<any>>>(schema: K): ConfigDescriberObjectLeaf<ObjectDescriptionToType<K>>;
|
|
75
|
+
maybe<T>(type: ConfigDescriberLeaf<T>): ConfigDescriberOptionalLeaf<T | undefined>;
|
|
76
|
+
default<T_1>(type: ConfigDescriberLeaf<T_1>, def: T_1): ConfigDescriberOptionalLeaf<T_1>;
|
|
77
|
+
array<T_2>(type: ConfigDescriberLeaf<T_2>, initAsEmpty?: boolean): ConfigDescriberLeaf<T_2[]>;
|
|
78
|
+
map<K_1, V>(keySchema: ConfigDescriberLeaf<K_1>, valSchema: ConfigDescriberLeaf<V>): ConfigDescriberLeaf<Map<K_1, V>>;
|
|
79
|
+
tuple<Ts extends ConfigDescriberLeaf<any>[]>(...items: Ts): ConfigDescriberLeaf<TraverseTuple<Ts>>;
|
|
80
|
+
combine<A, B>(a: ConfigDescriberObjectLeaf<A>, b: ConfigDescriberObjectLeaf<B>): ConfigDescriberObjectLeaf<A & B>;
|
|
81
|
+
printJSONSchema<T_3>(schema: ConfigDescriberLeaf<T_3>): string;
|
|
82
|
+
};
|
|
83
|
+
export type ConfigTypeInfer<T> = UnwrapConfigDescriberLeaf<T>;
|
|
84
|
+
export {};
|
|
85
|
+
//# sourceMappingURL=configDescriber.d.ts.map
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Huawei Device Co., Ltd.
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
import { zip } from "./util";
|
|
16
|
+
class ValidationBox {
|
|
17
|
+
constructor(box) {
|
|
18
|
+
this.box = box;
|
|
19
|
+
}
|
|
20
|
+
static fail(errorMessage) {
|
|
21
|
+
return new ValidationBox({ success: false, errorMessage });
|
|
22
|
+
}
|
|
23
|
+
static ok(value) {
|
|
24
|
+
return new ValidationBox({ success: true, value });
|
|
25
|
+
}
|
|
26
|
+
success() {
|
|
27
|
+
return this.box.success;
|
|
28
|
+
}
|
|
29
|
+
unwrap() {
|
|
30
|
+
if (this.box.success) {
|
|
31
|
+
return this.box.value;
|
|
32
|
+
}
|
|
33
|
+
throw new Error("");
|
|
34
|
+
}
|
|
35
|
+
error() {
|
|
36
|
+
if (!this.box.success) {
|
|
37
|
+
return this.box.errorMessage;
|
|
38
|
+
}
|
|
39
|
+
throw new Error("");
|
|
40
|
+
}
|
|
41
|
+
get() {
|
|
42
|
+
return this.box;
|
|
43
|
+
}
|
|
44
|
+
or(x) {
|
|
45
|
+
if (this.box.success) {
|
|
46
|
+
return new ValidationBox(this.box);
|
|
47
|
+
}
|
|
48
|
+
return new ValidationBox({
|
|
49
|
+
success: true,
|
|
50
|
+
value: x
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
class ConfigDescriberLeaf {
|
|
55
|
+
constructor(validate, printSchema) {
|
|
56
|
+
this.validate = validate;
|
|
57
|
+
this.printSchema = printSchema;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
class ConfigDescriberOptionalLeaf extends ConfigDescriberLeaf {
|
|
61
|
+
constructor(validate, printSchema) { super(validate, printSchema); }
|
|
62
|
+
}
|
|
63
|
+
class ConfigDescriberObjectLeaf extends ConfigDescriberLeaf {
|
|
64
|
+
constructor(validate, printSchema, schema) {
|
|
65
|
+
super(validate, printSchema);
|
|
66
|
+
this.schema = schema;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function mk(typeName, check, config) {
|
|
70
|
+
return new ConfigDescriberLeaf(x => {
|
|
71
|
+
if (check(x)) {
|
|
72
|
+
return new ValidationBox({
|
|
73
|
+
success: true,
|
|
74
|
+
value: x
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
if (config !== undefined && 'default' in config) {
|
|
78
|
+
return new ValidationBox({
|
|
79
|
+
success: true,
|
|
80
|
+
value: config.default
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return new ValidationBox({
|
|
84
|
+
success: false,
|
|
85
|
+
errorMessage: `Expected "${typeName}"`
|
|
86
|
+
});
|
|
87
|
+
}, () => {
|
|
88
|
+
const base = {
|
|
89
|
+
type: typeName,
|
|
90
|
+
};
|
|
91
|
+
if (config === null || config === void 0 ? void 0 : config.description) {
|
|
92
|
+
base.description = config === null || config === void 0 ? void 0 : config.description;
|
|
93
|
+
}
|
|
94
|
+
return base;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
export const D = {
|
|
98
|
+
////////////////////////////////////////
|
|
99
|
+
// Basics
|
|
100
|
+
number(config) {
|
|
101
|
+
return mk('number', x => typeof x === 'number', config);
|
|
102
|
+
},
|
|
103
|
+
string(config) {
|
|
104
|
+
return mk('string', x => typeof x === 'string', config);
|
|
105
|
+
},
|
|
106
|
+
boolean(config) {
|
|
107
|
+
return mk('boolean', x => typeof x === 'boolean', config);
|
|
108
|
+
},
|
|
109
|
+
bigint(config) {
|
|
110
|
+
return mk('bigint', x => typeof x === 'bigint', config);
|
|
111
|
+
},
|
|
112
|
+
null(config) {
|
|
113
|
+
return mk('null', x => x === null, config);
|
|
114
|
+
},
|
|
115
|
+
undefined(config) {
|
|
116
|
+
return mk('undefined', x => x === undefined, config);
|
|
117
|
+
},
|
|
118
|
+
object(schema) {
|
|
119
|
+
return new ConfigDescriberObjectLeaf(x => {
|
|
120
|
+
if (x !== undefined) {
|
|
121
|
+
if (typeof x !== 'object') {
|
|
122
|
+
return ValidationBox.fail(`Expected object, but got "${typeof x}"`);
|
|
123
|
+
}
|
|
124
|
+
if (x === null) {
|
|
125
|
+
return ValidationBox.fail(`Expected object, but got "null"`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
const obj = x;
|
|
129
|
+
const sh = schema;
|
|
130
|
+
const result = {};
|
|
131
|
+
const errors = [];
|
|
132
|
+
for (const key in schema) {
|
|
133
|
+
const box = sh[key].validate(obj === undefined ? undefined : obj[key]);
|
|
134
|
+
if (box.success()) {
|
|
135
|
+
const val = box.unwrap();
|
|
136
|
+
if (val === undefined && obj !== undefined && !(key in obj)) {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
result[key] = val;
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
errors.push(`"${key}":\n${box.error().split('\n').map(s => '\t' + s).join('\n')}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (errors.length) {
|
|
146
|
+
return ValidationBox.fail(errors.join('\n'));
|
|
147
|
+
}
|
|
148
|
+
return new ValidationBox({
|
|
149
|
+
success: true,
|
|
150
|
+
value: result
|
|
151
|
+
});
|
|
152
|
+
}, () => {
|
|
153
|
+
const properties = {};
|
|
154
|
+
const required = [];
|
|
155
|
+
for (const key in schema) {
|
|
156
|
+
const leaf = schema[key];
|
|
157
|
+
properties[key] = leaf.printSchema();
|
|
158
|
+
if (!(leaf instanceof ConfigDescriberOptionalLeaf)) {
|
|
159
|
+
required.push(key);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return {
|
|
163
|
+
additionalProperties: false,
|
|
164
|
+
properties,
|
|
165
|
+
required,
|
|
166
|
+
type: "object"
|
|
167
|
+
};
|
|
168
|
+
}, schema);
|
|
169
|
+
},
|
|
170
|
+
////////////////////////////////////////
|
|
171
|
+
// Advanced
|
|
172
|
+
maybe(type) {
|
|
173
|
+
return new ConfigDescriberOptionalLeaf(x => {
|
|
174
|
+
if (x === undefined) {
|
|
175
|
+
return ValidationBox.ok(undefined);
|
|
176
|
+
}
|
|
177
|
+
return type.validate(x);
|
|
178
|
+
}, () => {
|
|
179
|
+
return type.printSchema();
|
|
180
|
+
});
|
|
181
|
+
},
|
|
182
|
+
default(type, def) {
|
|
183
|
+
return new ConfigDescriberOptionalLeaf(x => {
|
|
184
|
+
return type.validate(x).or(def);
|
|
185
|
+
}, () => {
|
|
186
|
+
return type.printSchema();
|
|
187
|
+
});
|
|
188
|
+
},
|
|
189
|
+
array(type, initAsEmpty = true) {
|
|
190
|
+
return new ConfigDescriberLeaf(xs => {
|
|
191
|
+
if ((xs === undefined || xs === null) && initAsEmpty) {
|
|
192
|
+
return ValidationBox.ok([]);
|
|
193
|
+
}
|
|
194
|
+
if (!Array.isArray(xs)) {
|
|
195
|
+
return ValidationBox.fail("Expected array");
|
|
196
|
+
}
|
|
197
|
+
const result = [];
|
|
198
|
+
for (const x of xs) {
|
|
199
|
+
const box = type.validate(x);
|
|
200
|
+
if (!box.success()) {
|
|
201
|
+
return ValidationBox.fail("Array item: " + box.error());
|
|
202
|
+
}
|
|
203
|
+
result.push(box.unwrap());
|
|
204
|
+
}
|
|
205
|
+
return ValidationBox.ok(result);
|
|
206
|
+
}, () => {
|
|
207
|
+
return {
|
|
208
|
+
type: 'array',
|
|
209
|
+
items: type.printSchema()
|
|
210
|
+
};
|
|
211
|
+
});
|
|
212
|
+
},
|
|
213
|
+
map(keySchema, valSchema) {
|
|
214
|
+
return new ConfigDescriberLeaf(x => {
|
|
215
|
+
if (x === undefined) {
|
|
216
|
+
return ValidationBox.fail(`Expected Map, but got "undefined"`);
|
|
217
|
+
}
|
|
218
|
+
if (typeof x !== 'object' || x === null) {
|
|
219
|
+
return ValidationBox.fail(`Expected Map, but got "${x === null ? 'null' : typeof x}"`);
|
|
220
|
+
}
|
|
221
|
+
const result = new Map();
|
|
222
|
+
const iterable = x instanceof Map ? x : Object.entries(x);
|
|
223
|
+
for (const [key, val] of iterable) {
|
|
224
|
+
const keyResult = keySchema.validate(key);
|
|
225
|
+
if (!keyResult.success()) {
|
|
226
|
+
return ValidationBox.fail("Map key: " + keyResult.error());
|
|
227
|
+
}
|
|
228
|
+
const valResult = valSchema.validate(val);
|
|
229
|
+
if (!valResult.success()) {
|
|
230
|
+
return ValidationBox.fail("Map value: " + valResult.error());
|
|
231
|
+
}
|
|
232
|
+
result.set(keyResult.unwrap(), valResult.unwrap());
|
|
233
|
+
}
|
|
234
|
+
return ValidationBox.ok(result);
|
|
235
|
+
}, () => {
|
|
236
|
+
return {
|
|
237
|
+
type: 'object',
|
|
238
|
+
additionalProperties: valSchema.printSchema()
|
|
239
|
+
};
|
|
240
|
+
});
|
|
241
|
+
},
|
|
242
|
+
tuple(...items) {
|
|
243
|
+
return new ConfigDescriberLeaf(xs => {
|
|
244
|
+
if (!Array.isArray(xs)) {
|
|
245
|
+
return ValidationBox.fail('Expected tuple');
|
|
246
|
+
}
|
|
247
|
+
if (xs.length !== items.length) {
|
|
248
|
+
return ValidationBox.fail(`Expected tuple of size ${items.length}, but size was ${xs.length}`);
|
|
249
|
+
}
|
|
250
|
+
const result = [];
|
|
251
|
+
zip(xs, items).forEach(([val, leaf], i) => {
|
|
252
|
+
const r = leaf.validate(val);
|
|
253
|
+
if (!r.success()) {
|
|
254
|
+
return ValidationBox.fail(`Tuple position ${i}: ${r.error()}`);
|
|
255
|
+
}
|
|
256
|
+
result.push(r.unwrap());
|
|
257
|
+
});
|
|
258
|
+
return ValidationBox.ok(result);
|
|
259
|
+
}, () => {
|
|
260
|
+
return {
|
|
261
|
+
items: items.map(it => it.printSchema())
|
|
262
|
+
};
|
|
263
|
+
});
|
|
264
|
+
},
|
|
265
|
+
////////////////////////////////////////
|
|
266
|
+
// Utils
|
|
267
|
+
combine(a, b) {
|
|
268
|
+
const keysA = new Set(Object.keys(a.schema));
|
|
269
|
+
const keysB = Object.keys(b.schema);
|
|
270
|
+
for (const key of keysB) {
|
|
271
|
+
if (keysA.has(key)) {
|
|
272
|
+
throw new Error(`Can not combine objects with same keys. Key: "${key}"`);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return D.object(Object.assign(Object.assign({}, a.schema), b.schema));
|
|
276
|
+
},
|
|
277
|
+
////////////////////////////////////////
|
|
278
|
+
// Helpers
|
|
279
|
+
printJSONSchema(schema) {
|
|
280
|
+
const configSchema = schema.printSchema();
|
|
281
|
+
if ("properties" in configSchema) {
|
|
282
|
+
configSchema.properties.$schema = {
|
|
283
|
+
type: "string",
|
|
284
|
+
description: "The schema to verify this document against."
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
const json = {
|
|
288
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
289
|
+
$ref: "#/definitions/configSchema",
|
|
290
|
+
definitions: {
|
|
291
|
+
configSchema
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
return JSON.stringify(json, null, 4);
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
//# sourceMappingURL=configDescriber.js.map
|
|
@@ -13,10 +13,11 @@
|
|
|
13
13
|
* limitations under the License.
|
|
14
14
|
*/
|
|
15
15
|
import { indentedBy, isInNamespace } from "../util";
|
|
16
|
-
import { IDLEntity, IDLKind, getExtAttribute, getVerbatimDts, hasExtAttribute, isCallback, isConstructor, isContainerType, isEnum, isInterface, isMethod, isPrimitiveType, isProperty, isReferenceType, isSyntheticEntry, isTypeParameterType, isTypedef, isUnionType, isImport, isVersion, isNamespace, IDLExtendedAttributes, IDLAccessorAttribute, IDLVoidType, IDLStringType, IDLUndefinedType, isCallable, getSuperType, IDLAnyType, IDLContainerUtils, DebugUtils, mixMethodParametersAndTags, createReferenceType, transformMethodsAsync2ReturnPromise, isNamedNode, IDLThisType, isOptionalType, IDLI8Type, IDLU8Type, IDLI16Type, IDLU16Type, IDLI32Type, IDLU32Type, IDLI64Type, IDLU64Type, IDLF16Type, IDLF32Type, IDLF64Type, IDLBufferType, isUnspecifiedGenericType, IDLUnknownType, IDLBooleanType, IDLNumberType, IDLPointerType, IDLInterfaceSubkind, escapeIDLKeyword, getNamespacesPathFor, IDLBigintType } from "../idl";
|
|
16
|
+
import { IDLEntity, IDLKind, getExtAttribute, getVerbatimDts, hasExtAttribute, isCallback, isConstructor, isContainerType, isEnum, isInterface, isMethod, isPrimitiveType, isProperty, isReferenceType, isSyntheticEntry, isTypeParameterType, isTypedef, isUnionType, isImport, isVersion, isNamespace, IDLExtendedAttributes, IDLAccessorAttribute, IDLVoidType, IDLStringType, IDLUndefinedType, isCallable, getSuperType, IDLAnyType, IDLContainerUtils, DebugUtils, mixMethodParametersAndTags, createReferenceType, transformMethodsAsync2ReturnPromise, isNamedNode, IDLThisType, isOptionalType, IDLI8Type, IDLU8Type, IDLI16Type, IDLU16Type, IDLI32Type, IDLU32Type, IDLI64Type, IDLU64Type, IDLF16Type, IDLF32Type, IDLF64Type, IDLBufferType, isUnspecifiedGenericType, IDLUnknownType, IDLBooleanType, IDLNumberType, IDLPointerType, IDLInterfaceSubkind, escapeIDLKeyword, getNamespacesPathFor, IDLBigintType, IDLDate } from "../idl";
|
|
17
17
|
import { resolveSyntheticType, toIDLFile } from "./deserialize";
|
|
18
18
|
import { Language } from "../Language";
|
|
19
19
|
import { warn } from "../util";
|
|
20
|
+
import { isInIdlize } from "../idlize";
|
|
20
21
|
export class CustomPrintVisitor {
|
|
21
22
|
constructor(resolver, language) {
|
|
22
23
|
this.resolver = resolver;
|
|
@@ -31,7 +32,7 @@ export class CustomPrintVisitor {
|
|
|
31
32
|
this.print(`${!isTopmost ? "" : "declare "}namespace ${namespace.name} {`);
|
|
32
33
|
this.pushIndent();
|
|
33
34
|
}
|
|
34
|
-
if (
|
|
35
|
+
if (isInIdlize(node))
|
|
35
36
|
return;
|
|
36
37
|
if (isInterface(node)) {
|
|
37
38
|
this.printInterface(node);
|
|
@@ -288,6 +289,7 @@ export class CustomPrintVisitor {
|
|
|
288
289
|
case IDLThisType: return "T";
|
|
289
290
|
case IDLBigintType:
|
|
290
291
|
case IDLPointerType: return "number|bigint";
|
|
292
|
+
case IDLDate: return "Date";
|
|
291
293
|
default: throw new Error(`Unknown primitive type ${DebugUtils.debugPrintType(type)}`);
|
|
292
294
|
}
|
|
293
295
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as idl from "../idl";
|
|
2
|
+
import { ReferenceResolver } from "../peer-generation/ReferenceResolver";
|
|
3
|
+
export interface IDLLinterOptions {
|
|
4
|
+
validEntryAttributes: Map<idl.IDLKind, string[]>;
|
|
5
|
+
checkEnumsConsistency: boolean;
|
|
6
|
+
checkReferencesResolved: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare class IDLLinter {
|
|
9
|
+
protected node: idl.IDLNode;
|
|
10
|
+
protected resolver: ReferenceResolver;
|
|
11
|
+
protected options: IDLLinterOptions;
|
|
12
|
+
constructor(node: idl.IDLNode, resolver: ReferenceResolver, options: IDLLinterOptions);
|
|
13
|
+
private entryErrors;
|
|
14
|
+
private pushError;
|
|
15
|
+
result: string;
|
|
16
|
+
visit(): string;
|
|
17
|
+
protected check(node: idl.IDLNode): void;
|
|
18
|
+
protected checkValidAttributes(entry: idl.IDLEntry, validAttributes: string[]): void;
|
|
19
|
+
protected checkEnumConsistency(entry: idl.IDLEnum): void;
|
|
20
|
+
private static builtinReferences;
|
|
21
|
+
protected checkReferenceResolved(reference: idl.IDLReferenceType): void;
|
|
22
|
+
}
|
|
23
|
+
export declare function verifyIDLLinter(node: idl.IDLNode, resolver: ReferenceResolver, options: IDLLinterOptions): true;
|
|
24
|
+
//# sourceMappingURL=IDLLinter.d.ts.map
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import * as idl from "../idl";
|
|
2
|
+
export class IDLLinter {
|
|
3
|
+
constructor(node, resolver, options) {
|
|
4
|
+
this.node = node;
|
|
5
|
+
this.resolver = resolver;
|
|
6
|
+
this.options = options;
|
|
7
|
+
this.result = "";
|
|
8
|
+
}
|
|
9
|
+
pushError(node, error) {
|
|
10
|
+
const name = typeof node === 'string' ? node : idl.getFQName(node);
|
|
11
|
+
if (!this.entryErrors)
|
|
12
|
+
this.entryErrors = {};
|
|
13
|
+
if (!this.entryErrors[name])
|
|
14
|
+
this.entryErrors[name] = [];
|
|
15
|
+
this.entryErrors[name].push(error);
|
|
16
|
+
}
|
|
17
|
+
visit() {
|
|
18
|
+
this.check(this.node);
|
|
19
|
+
idl.forEachChild(this.node, node => {
|
|
20
|
+
this.check(node);
|
|
21
|
+
});
|
|
22
|
+
this.result = !this.entryErrors ? "" : JSON.stringify(this.entryErrors, undefined, 2);
|
|
23
|
+
return this.result;
|
|
24
|
+
}
|
|
25
|
+
check(node) {
|
|
26
|
+
var _a;
|
|
27
|
+
if (idl.isEntry(node)) {
|
|
28
|
+
this.checkValidAttributes(node, (_a = this.options.validEntryAttributes.get(node.kind)) !== null && _a !== void 0 ? _a : []);
|
|
29
|
+
}
|
|
30
|
+
if (this.options.checkEnumsConsistency && idl.isEnum(node)) {
|
|
31
|
+
this.checkEnumConsistency(node);
|
|
32
|
+
}
|
|
33
|
+
if (this.options.checkReferencesResolved && idl.isReferenceType(node)) {
|
|
34
|
+
this.checkReferenceResolved(node);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
checkValidAttributes(entry, validAttributes) {
|
|
38
|
+
if (!entry.extendedAttributes)
|
|
39
|
+
return;
|
|
40
|
+
for (const attr of entry.extendedAttributes) {
|
|
41
|
+
if (!validAttributes.includes(attr.name))
|
|
42
|
+
this.pushError(entry, `${entry.kind}: Invalid attribute '${attr.name}'`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
checkEnumConsistency(entry) {
|
|
46
|
+
let hasNumber = false;
|
|
47
|
+
let hasString = false;
|
|
48
|
+
for (const element of entry.elements) {
|
|
49
|
+
if (typeof element.initializer === 'string')
|
|
50
|
+
hasString = true;
|
|
51
|
+
if (typeof element.initializer === 'number')
|
|
52
|
+
hasNumber = true;
|
|
53
|
+
}
|
|
54
|
+
if (hasNumber && hasString)
|
|
55
|
+
this.pushError(entry, "Enum includes both string and number values");
|
|
56
|
+
}
|
|
57
|
+
checkReferenceResolved(reference) {
|
|
58
|
+
if (IDLLinter.builtinReferences.includes(reference.name))
|
|
59
|
+
return;
|
|
60
|
+
const resolved = this.resolver.resolveTypeReference(reference);
|
|
61
|
+
if (resolved === undefined) {
|
|
62
|
+
const parentFile = idl.getFileFor(reference);
|
|
63
|
+
const parentNamespace = idl.fetchNamespaceFrom(reference);
|
|
64
|
+
const scopeName = parentNamespace ? idl.getFQName(parentNamespace) : idl.getPackageName(parentFile);
|
|
65
|
+
this.pushError(scopeName, `Can not resolve reference '${reference.name}' defined in scope '${scopeName}' in file '${parentFile.fileName}''`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
IDLLinter.builtinReferences = [
|
|
70
|
+
idl.IDLTopType.name,
|
|
71
|
+
idl.IDLObjectType.name,
|
|
72
|
+
];
|
|
73
|
+
class IDLLinterError extends Error {
|
|
74
|
+
}
|
|
75
|
+
export function verifyIDLLinter(node, resolver, options) {
|
|
76
|
+
const result = new IDLLinter(node, resolver, options).visit();
|
|
77
|
+
if (result.length)
|
|
78
|
+
throw new IDLLinterError(result);
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=IDLLinter.js.map
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import * as webidl2 from "webidl2";
|
|
16
16
|
import * as fs from "fs";
|
|
17
|
-
import { isAttribute, isCallback, isClass, isConstructor, isDictionary, isEnum, isInterface, isOperation, isOptional, isPromiseTypeDescription, isRecordTypeDescription, isSequenceTypeDescription, isSingleTypeDescription, isTypedef, isUnionTypeDescription, isUnspecifiedGenericTypeDescription } from "./webidl2-utils";
|
|
17
|
+
import { isAttribute, isCallback, isClass, isConstant, isConstructor, isDictionary, isEnum, isInterface, isOperation, isOptional, isPromiseTypeDescription, isRecordTypeDescription, isSequenceTypeDescription, isSingleTypeDescription, isTypedef, isUnionTypeDescription, isUnspecifiedGenericTypeDescription } from "./webidl2-utils";
|
|
18
18
|
import { toString } from "./toString";
|
|
19
19
|
import * as idl from "../idl";
|
|
20
20
|
import { isDefined, warn } from "../util";
|
|
@@ -65,6 +65,9 @@ function toIDLNodeForward(file, node) {
|
|
|
65
65
|
if (isOperation(node)) {
|
|
66
66
|
return toIDLMethod(file, node);
|
|
67
67
|
}
|
|
68
|
+
if (isConstant(node)) {
|
|
69
|
+
return toIDLConstant(file, node);
|
|
70
|
+
}
|
|
68
71
|
throw new Error(`unexpected node type: ${toString(node)}`);
|
|
69
72
|
}
|
|
70
73
|
function isNamespace(node) {
|
|
@@ -86,9 +89,20 @@ function toIDLImport(node) {
|
|
|
86
89
|
// console.log(node)
|
|
87
90
|
return idl.createImport(node.clause.split("."), node.alias || undefined);
|
|
88
91
|
}
|
|
92
|
+
function interfaceSubkind(node) {
|
|
93
|
+
var _a, _b;
|
|
94
|
+
const nodeIDLEntity = (_b = (_a = node.extAttrs.find(it => it.name === "Entity")) === null || _a === void 0 ? void 0 : _a.rhs) === null || _b === void 0 ? void 0 : _b.value;
|
|
95
|
+
if (nodeIDLEntity == idl.IDLEntity.Class)
|
|
96
|
+
return idl.IDLInterfaceSubkind.Class;
|
|
97
|
+
if (nodeIDLEntity == idl.IDLEntity.Interface)
|
|
98
|
+
return idl.IDLInterfaceSubkind.Interface;
|
|
99
|
+
if (nodeIDLEntity == idl.IDLEntity.Tuple)
|
|
100
|
+
return idl.IDLInterfaceSubkind.Tuple;
|
|
101
|
+
return idl.IDLInterfaceSubkind.Interface;
|
|
102
|
+
}
|
|
89
103
|
function toIDLInterface(file, node) {
|
|
90
104
|
var _a;
|
|
91
|
-
const result = idl.createInterface(node.name,
|
|
105
|
+
const result = idl.createInterface(node.name, interfaceSubkind(node), (() => {
|
|
92
106
|
var _a, _b;
|
|
93
107
|
if (!node.inheritance)
|
|
94
108
|
return [];
|
|
@@ -113,8 +127,6 @@ function toIDLInterface(file, node) {
|
|
|
113
127
|
documentation: makeDocs(node),
|
|
114
128
|
extendedAttributes: toExtendedAttributes(node.extAttrs),
|
|
115
129
|
});
|
|
116
|
-
if (result.inheritance.length && idl.isReferenceType(result.inheritance[0]))
|
|
117
|
-
result.inheritance[0].typeArguments = extractTypeArguments(file, node.extAttrs, idl.IDLExtendedAttributes.TypeArguments);
|
|
118
130
|
if (node.extAttrs.find(it => it.name === "Synthetic"))
|
|
119
131
|
addSyntheticType(node.name, result);
|
|
120
132
|
return result;
|
|
@@ -249,6 +261,31 @@ function toIDLTypedef(file, node) {
|
|
|
249
261
|
fileName: file,
|
|
250
262
|
});
|
|
251
263
|
}
|
|
264
|
+
function toIDLConstant(file, node) {
|
|
265
|
+
return idl.createConstant(node.name, toIDLType(file, node.idlType), constantValue(node));
|
|
266
|
+
}
|
|
267
|
+
function constantValue(node) {
|
|
268
|
+
switch (node.value.type) {
|
|
269
|
+
case "string":
|
|
270
|
+
return `"${node.value.value}"`;
|
|
271
|
+
case "number":
|
|
272
|
+
return node.value.value;
|
|
273
|
+
case "boolean":
|
|
274
|
+
return node.value.value.toString();
|
|
275
|
+
case "null":
|
|
276
|
+
return "null";
|
|
277
|
+
case "Infinity":
|
|
278
|
+
return "Infinity";
|
|
279
|
+
case "NaN":
|
|
280
|
+
return "NaN";
|
|
281
|
+
case "sequence":
|
|
282
|
+
return `[${node.value.value.join(',')}]`;
|
|
283
|
+
case "dictionary":
|
|
284
|
+
return `new Map()`;
|
|
285
|
+
default:
|
|
286
|
+
return "undefined";
|
|
287
|
+
}
|
|
288
|
+
}
|
|
252
289
|
function toIDLDictionary(file, node) {
|
|
253
290
|
const result = idl.createEnum(node.name, [], {
|
|
254
291
|
documentation: makeDocs(node),
|
|
@@ -15,6 +15,7 @@ export declare function isSingleTypeDescription(node: webidl2.IDLTypeDescription
|
|
|
15
15
|
export declare function isSequenceTypeDescription(node: webidl2.IDLTypeDescription): node is webidl2.SequenceTypeDescription;
|
|
16
16
|
export declare function isPromiseTypeDescription(node: webidl2.IDLTypeDescription): node is webidl2.PromiseTypeDescription;
|
|
17
17
|
export declare function isRecordTypeDescription(node: webidl2.IDLTypeDescription): node is webidl2.RecordTypeDescription;
|
|
18
|
+
export declare function isConstant(node: webidl2.IDLRootType): node is webidl2.ConstantMemberType;
|
|
18
19
|
export declare function isUnspecifiedGenericTypeDescription(node: webidl2.IDLTypeDescription): node is webidl2.UnspecifiedGenericTypeDescription;
|
|
19
20
|
export declare function isOptional(node: webidl2.AttributeMemberType | webidl2.OperationMemberType): boolean;
|
|
20
21
|
//# sourceMappingURL=webidl2-utils.d.ts.map
|
|
@@ -63,6 +63,9 @@ export function isPromiseTypeDescription(node) {
|
|
|
63
63
|
export function isRecordTypeDescription(node) {
|
|
64
64
|
return node.generic === "record";
|
|
65
65
|
}
|
|
66
|
+
export function isConstant(node) {
|
|
67
|
+
return node.type === "const";
|
|
68
|
+
}
|
|
66
69
|
export function isUnspecifiedGenericTypeDescription(node) {
|
|
67
70
|
switch (node.generic) {
|
|
68
71
|
case "FrozenArray":
|