@idlizer/core 2.0.17 → 2.0.19

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.
Files changed (39) hide show
  1. package/build/lib/src/LanguageWriters/convertors/CJConvertors.d.ts +30 -0
  2. package/build/lib/src/LanguageWriters/convertors/CJConvertors.js +154 -0
  3. package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +2 -2
  4. package/build/lib/src/LanguageWriters/convertors/ETSConvertors.d.ts +13 -0
  5. package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +118 -0
  6. package/build/lib/src/LanguageWriters/convertors/JavaConvertors.d.ts +32 -0
  7. package/build/lib/src/LanguageWriters/convertors/JavaConvertors.js +175 -0
  8. package/build/lib/src/LanguageWriters/convertors/TSConvertors.d.ts +27 -0
  9. package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +173 -0
  10. package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +1 -1
  11. package/build/lib/src/LibraryInterface.d.ts +2 -0
  12. package/build/lib/src/config.js +14 -0
  13. package/build/lib/src/configMerge.d.ts +2 -0
  14. package/build/lib/src/configMerge.js +42 -0
  15. package/build/lib/src/from-idl/common.d.ts +1 -1
  16. package/build/lib/src/from-idl/common.js +20 -11
  17. package/build/lib/src/idl.d.ts +6 -3
  18. package/build/lib/src/idl.js +14 -10
  19. package/build/lib/src/idlize.d.ts +1 -1
  20. package/build/lib/src/idlize.js +57 -13
  21. package/build/lib/src/index.d.ts +7 -0
  22. package/build/lib/src/index.js +7 -0
  23. package/build/lib/src/options.d.ts +1 -0
  24. package/build/lib/src/peer-generation/LanguageWriters/index.d.ts +2 -0
  25. package/build/lib/src/peer-generation/LanguageWriters/index.js +2 -0
  26. package/build/lib/src/peer-generation/LanguageWriters/nameConvertor.d.ts +25 -0
  27. package/build/lib/src/peer-generation/LanguageWriters/nameConvertor.js +55 -0
  28. package/build/lib/src/peer-generation/LayoutManager.d.ts +15 -0
  29. package/build/lib/src/peer-generation/LayoutManager.js +32 -0
  30. package/build/lib/src/peer-generation/Materialized.d.ts +2 -0
  31. package/build/lib/src/peer-generation/Materialized.js +28 -0
  32. package/build/lib/src/peer-generation/PeerLibrary.d.ts +53 -0
  33. package/build/lib/src/peer-generation/PeerLibrary.js +340 -0
  34. package/build/lib/src/peer-generation/idl/IdlNameConvertor.d.ts +1 -0
  35. package/build/lib/src/peer-generation/idl/IdlNameConvertor.js +3 -0
  36. package/package.json +2 -2
  37. package/webidl2.js/LICENSE +0 -21
  38. package/webidl2.js/README.md +0 -827
  39. package/webidl2.js/dist/package.json +0 -3
@@ -0,0 +1,173 @@
1
+ /*
2
+ * Copyright (c) 2024 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 * as idl from '../../idl';
16
+ import { convertNode } from '../nameConvertor';
17
+ export class TSTypeNameConvertor {
18
+ constructor(resolver) {
19
+ this.resolver = resolver;
20
+ }
21
+ convert(node) {
22
+ return convertNode(this, node);
23
+ }
24
+ convertNamespace(node) {
25
+ return node.name;
26
+ }
27
+ convertInterface(node) {
28
+ return node.name;
29
+ }
30
+ convertEnum(node) {
31
+ return node.name;
32
+ }
33
+ convertTypedef(node) {
34
+ return node.name;
35
+ }
36
+ convertCallback(node) {
37
+ return node.name;
38
+ }
39
+ convertMethod(node) {
40
+ return node.name;
41
+ }
42
+ convertConstant(node) {
43
+ return node.name;
44
+ }
45
+ convertOptional(type) {
46
+ return `${this.convert(type.type)} | undefined`;
47
+ }
48
+ convertUnion(type) {
49
+ return type.types.
50
+ map(it => {
51
+ if (false /* add check if it is function */) {
52
+ return `(${this.convert(it)})`;
53
+ }
54
+ return this.convert(it);
55
+ })
56
+ .join(' | ');
57
+ }
58
+ convertContainer(type) {
59
+ if (idl.IDLContainerUtils.isSequence(type)) {
60
+ switch (type.elementType[0]) {
61
+ case idl.IDLU8Type: return 'Uint8Array'; // should be changed to Array
62
+ case idl.IDLI32Type: return 'Int32Array'; // should be changed to Array
63
+ case idl.IDLF32Type: return 'KFloat32ArrayPtr'; // should be changed to Array
64
+ default: return `Array<${this.convert(type.elementType[0])}>`;
65
+ }
66
+ }
67
+ if (idl.IDLContainerUtils.isRecord(type)) {
68
+ return `Map<${this.convert(type.elementType[0])}, ${this.convert(type.elementType[1])}>`;
69
+ }
70
+ if (idl.IDLContainerUtils.isPromise(type)) {
71
+ return `Promise<${this.convert(type.elementType[0])}>`;
72
+ }
73
+ throw new Error(`Unmapped container type ${idl.DebugUtils.debugPrintType(type)}`);
74
+ }
75
+ convertImport(type, importClause) {
76
+ return type.name;
77
+ }
78
+ convertTypeReference(type) {
79
+ var _a, _b;
80
+ let decl = this.resolver.resolveTypeReference(type);
81
+ if (decl) {
82
+ if (idl.isSyntheticEntry(decl)) {
83
+ if (idl.isCallback(decl)) {
84
+ return this.mapCallback(decl);
85
+ }
86
+ const entity = idl.getExtAttribute(decl, idl.IDLExtendedAttributes.Entity);
87
+ if (entity) {
88
+ const isTuple = entity === idl.IDLEntity.Tuple;
89
+ return this.productType(decl, isTuple, !isTuple);
90
+ }
91
+ }
92
+ }
93
+ // FIXME: isEnumMember is not TYPE!
94
+ if (decl && idl.isEnumMember(decl) && decl.parent) {
95
+ // when `interface A { field?: MyEnum.Value1 }` is generated, it is not possible
96
+ // to deserialize A, because there is no such type information in declaration target
97
+ // (can not cast MyEnum to exact MyEnum.Value1)
98
+ decl = decl.parent;
99
+ }
100
+ let typeSpec = type.name;
101
+ let typeArgs = (_b = (_a = type.typeArguments) === null || _a === void 0 ? void 0 : _a.map(it => idl.printType(it))) !== null && _b !== void 0 ? _b : [];
102
+ if (typeSpec === `Optional`)
103
+ return `${typeArgs} | undefined`;
104
+ if (typeSpec === `Function`)
105
+ return this.mapFunctionType(typeArgs);
106
+ const maybeTypeArguments = !(typeArgs === null || typeArgs === void 0 ? void 0 : typeArgs.length) ? '' : `<${typeArgs.join(', ')}>`;
107
+ if (decl) {
108
+ const path = idl.getNamespacesPathFor(decl).map(it => it.name);
109
+ path.push(decl.name);
110
+ return `${path.join(".")}${maybeTypeArguments}`;
111
+ }
112
+ return `${type.name}${maybeTypeArguments}`;
113
+ }
114
+ convertTypeParameter(type) {
115
+ return type.name;
116
+ }
117
+ convertPrimitiveType(type) {
118
+ switch (type) {
119
+ case idl.IDLUnknownType:
120
+ case idl.IDLCustomObjectType: return 'unknown';
121
+ case idl.IDLThisType: return 'this';
122
+ case idl.IDLAnyType: return 'any';
123
+ case idl.IDLUndefinedType: return 'undefined';
124
+ case idl.IDLPointerType: return 'KPointer';
125
+ case idl.IDLVoidType: return 'void';
126
+ case idl.IDLBooleanType: return 'boolean';
127
+ case idl.IDLI32Type:
128
+ return 'int32';
129
+ case idl.IDLI8Type:
130
+ case idl.IDLU8Type:
131
+ case idl.IDLI16Type:
132
+ case idl.IDLU16Type:
133
+ case idl.IDLU32Type:
134
+ case idl.IDLI64Type:
135
+ case idl.IDLU64Type:
136
+ case idl.IDLF32Type:
137
+ case idl.IDLF64Type:
138
+ case idl.IDLNumberType:
139
+ return 'number';
140
+ case idl.IDLBigintType:
141
+ return 'bigint';
142
+ case idl.IDLStringType:
143
+ return 'string';
144
+ case idl.IDLDate:
145
+ return 'Date';
146
+ case idl.IDLBufferType:
147
+ return `ArrayBuffer`;
148
+ }
149
+ throw new Error(`Unmapped primitive type ${idl.DebugUtils.debugPrintType(type)}`);
150
+ }
151
+ processTupleType(idlProperty) {
152
+ return idlProperty;
153
+ }
154
+ mapCallback(decl) {
155
+ const params = decl.parameters.map(it => `${it.isVariadic ? "..." : ""}${it.name}${it.isOptional ? "?" : ""}: ${this.convert(it.type)}`);
156
+ return `((${params.join(", ")}) => ${this.convert(decl.returnType)})`;
157
+ }
158
+ productType(decl, isTuple, includeFieldNames) {
159
+ const name = `${isTuple ? "[" : "{"} ${decl.properties
160
+ .map(it => isTuple ? this.processTupleType(it) : it)
161
+ .map(it => {
162
+ const type = this.convert(it.type);
163
+ return it.isOptional
164
+ ? includeFieldNames ? `${it.name}?: ${type}` : `(${type})?`
165
+ : includeFieldNames ? `${it.name}: ${type}` : `${type}`;
166
+ }).join(", ")} ${isTuple ? "]" : "}"}`;
167
+ return name;
168
+ }
169
+ mapFunctionType(typeArgs) {
170
+ return `Function${typeArgs.length ? `<${typeArgs.join(",")}>` : ''}`;
171
+ }
172
+ }
173
+ //# sourceMappingURL=TSConvertors.js.map
@@ -315,7 +315,7 @@ export class CppLanguageWriter extends CLikeLanguageWriter {
315
315
  return new CppPointerPropertyAccessExpression(expression, name);
316
316
  }
317
317
  writePrintLog(message) {
318
- this.print(`printf("${message}\n")`);
318
+ this.print(`printf("${message}\\n");`);
319
319
  }
320
320
  makeDefinedCheck(value) {
321
321
  return new CDefinedExpression(value);
@@ -1,5 +1,6 @@
1
1
  import * as idl from "./idl";
2
2
  import { Language } from "./Language";
3
+ import { IdlNameConvertor } from "./LanguageWriters";
3
4
  import { ArgConvertor } from "./LanguageWriters/ArgConvertors";
4
5
  import { ReferenceResolver } from "./peer-generation/ReferenceResolver";
5
6
  export interface LibraryFileInterface {
@@ -11,6 +12,7 @@ export interface LibraryInterface extends ReferenceResolver {
11
12
  typeConvertor(param: string, type: idl.IDLType, isOptionalParam?: boolean): ArgConvertor;
12
13
  declarationConvertor(param: string, type: idl.IDLReferenceType, declaration: idl.IDLEntry | undefined): ArgConvertor;
13
14
  getInteropName(node: idl.IDLNode): string;
15
+ createTypeNameConvertor(language: Language): IdlNameConvertor;
14
16
  createContinuationCallbackReference(continuationType: idl.IDLType): idl.IDLReferenceType;
15
17
  getCurrentContext(): string | undefined;
16
18
  /**
@@ -1,3 +1,17 @@
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
+ */
1
15
  class EmptyGeneratorConfiguration {
2
16
  param(name) {
3
17
  throw new Error(`${name} is unknown`);
@@ -0,0 +1,2 @@
1
+ export declare function deepMergeConfig<T extends object>(defaults: T, custom: Partial<T>): T;
2
+ //# sourceMappingURL=configMerge.d.ts.map
@@ -0,0 +1,42 @@
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
+ function isObject(i) {
16
+ if (typeof i !== 'object')
17
+ return false;
18
+ if (Array.isArray(i))
19
+ return false;
20
+ return true;
21
+ }
22
+ export function deepMergeConfig(defaults, custom) {
23
+ if (custom === undefined)
24
+ return defaults;
25
+ const result = Object.assign({}, defaults);
26
+ for (const key in custom) {
27
+ if (Object.prototype.hasOwnProperty.call(custom, key)) {
28
+ const defaultValue = result[key];
29
+ const customValue = custom[key];
30
+ if (isObject(defaultValue) && isObject(customValue)) {
31
+ Object.assign(result, { [key]: deepMergeConfig(defaultValue, customValue) });
32
+ }
33
+ else {
34
+ if (isObject(defaultValue))
35
+ throw new Error("Replacing default object value with custom non-object");
36
+ Object.assign(result, { [key]: customValue });
37
+ }
38
+ }
39
+ }
40
+ return result;
41
+ }
42
+ //# sourceMappingURL=configMerge.js.map
@@ -1,5 +1,5 @@
1
1
  import { IDLEntry } from "../idl";
2
- export declare function fromIDL(inputDir: string, inputFile: string | undefined, outputDir: string, extension: string, verbose: boolean, transform: (name: string, content: string) => string): void;
2
+ export declare function fromIDL(inputDirs: string | string[], inputFiles: string | string[] | undefined, outputDir: string, extension: string, verbose: boolean, transform: (name: string, content: string) => string): void;
3
3
  export declare function scanIDL(inputDir: string, inputFile: string | undefined): IDLEntry[][];
4
4
  export declare const licence = "/*\n * Copyright (c) 2024 Huawei Device Co., Ltd.\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n";
5
5
  //# sourceMappingURL=common.d.ts.map
@@ -30,18 +30,27 @@ function getFilesRecursive(dirPath, arrayOfFiles = []) {
30
30
  });
31
31
  return arrayOfFiles;
32
32
  }
33
- export function fromIDL(inputDir, inputFile, outputDir, extension, verbose, transform) {
34
- inputDir = path.resolve(inputDir);
35
- const files = inputFile
36
- ? [path.join(inputDir, inputFile)]
37
- : getFilesRecursive(inputDir);
38
- const results = files
39
- .map((file) => transform(file, fs.readFileSync(file).toString()));
40
- zip(files, results)
41
- .forEach(([fileName, output]) => {
33
+ export function fromIDL(inputDirs, inputFiles, outputDir, extension, verbose, transform) {
34
+ const resolvedInputDirs = Array.isArray(inputDirs) ? inputDirs.map(dir => path.resolve(dir)) : [path.resolve(inputDirs)];
35
+ const resolvedInputFiles = Array.isArray(inputFiles)
36
+ ? inputFiles.map(file => path.resolve(file))
37
+ : typeof inputFiles === 'string'
38
+ ? [path.resolve(inputFiles)]
39
+ : [];
40
+ let files = [];
41
+ if (resolvedInputFiles.length > 0) {
42
+ files = resolvedInputFiles;
43
+ }
44
+ else {
45
+ resolvedInputDirs.forEach(dir => {
46
+ files = files.concat(getFilesRecursive(dir));
47
+ });
48
+ }
49
+ const results = files.map(file => transform(file, fs.readFileSync(file).toString()));
50
+ zip(files, results).forEach(([fileName, output]) => {
42
51
  fs.mkdirSync(outputDir, { recursive: true });
43
- console.log('producing', path.relative(inputDir, fileName));
44
- const outFile = path.join(outputDir, path.relative(inputDir, fileName).replace(".idl", extension));
52
+ console.log('producing', path.relative(resolvedInputDirs[0], fileName));
53
+ const outFile = path.join(outputDir, path.relative(resolvedInputDirs[0], fileName).replace(".idl", extension));
45
54
  if (verbose)
46
55
  console.log(output);
47
56
  if (!fs.existsSync(path.dirname(outFile))) {
@@ -36,6 +36,7 @@ export declare enum IDLEntity {
36
36
  export declare enum IDLExtendedAttributes {
37
37
  Accessor = "Accessor",
38
38
  Async = "Async",
39
+ ArkTSType = "ArkTSType",
39
40
  CallSignature = "CallSignature",
40
41
  CJType = "CJType",
41
42
  CommonMethod = "CommonMethod",
@@ -54,14 +55,14 @@ export declare enum IDLExtendedAttributes {
54
55
  NativeModule = "NativeModule",
55
56
  Optional = "Optional",
56
57
  OriginalEnumMemberName = "OriginalEnumMemberName",
58
+ Predefined = "Predefined",
57
59
  Protected = "Protected",
58
60
  Synthetic = "Synthetic",
59
61
  TSType = "TSType",
60
62
  TypeArguments = "TypeArguments",
61
63
  TypeParameters = "TypeParameters",
62
64
  VerbatimDts = "VerbatimDts",
63
- HandWrittenImplementation = "HandWrittenImplementation",
64
- Predefined = "Predefined"
65
+ HandWrittenImplementation = "HandWrittenImplementation"
65
66
  }
66
67
  export declare enum IDLAccessorAttribute {
67
68
  Getter = "Getter",
@@ -296,6 +297,8 @@ export declare function createNamespace(name: string, extendedAttributes?: IDLEx
296
297
  export declare function linkNamespacesBack(node: IDLNode): void;
297
298
  export declare function getNamespacesPathFor(entry: IDLEntry): IDLNamespace[];
298
299
  export declare function isEqualByQualifedName(a?: IDLEntry, b?: IDLEntry): boolean;
300
+ export declare function getNamespaceName(a: IDLEntry): string;
301
+ export declare function getFQName(a: IDLEntry): string;
299
302
  export declare function createVersion(value: string[], extendedAttributes?: IDLExtendedAttribute[], fileName?: string): IDLVersion;
300
303
  export declare function fetchNamespaceFrom(pointOfView?: IDLNode): IDLNamespace | undefined;
301
304
  export declare function createReferenceType(name: string, typeArguments?: IDLType[], pointOfView?: IDLNode): IDLReferenceType;
@@ -304,7 +307,7 @@ export declare function entityToType(entity: IDLNode): IDLType;
304
307
  export declare function createContainerType(container: IDLContainerKind, element: IDLType[]): IDLContainerType;
305
308
  export declare function createUnionType(types: IDLType[], name?: string): IDLUnionType;
306
309
  export declare function createPackage(name: string): IDLPackage;
307
- export declare function createImport(name: string, importClause?: string[]): IDLImport;
310
+ export declare function createImport(name: string, importClause?: string[], nodeInitializer?: IDLNodeInitializer): IDLImport;
308
311
  export declare function createEnum(name: string, elements: IDLEnumMember[], nodeInitializer: IDLNodeInitializer): IDLEnum;
309
312
  export declare function createEnumMember(name: string, parent: IDLEnum, type: IDLPrimitiveType, initializer: number | string | undefined, nodeInitializer?: IDLNodeInitializer): IDLEnumMember;
310
313
  export declare function createInterface(name: string, subkind: IDLInterfaceSubkind, inheritance?: IDLReferenceType[], constructors?: IDLConstructor[], constants?: IDLConstant[], properties?: IDLProperty[], methods?: IDLMethod[], callables?: IDLCallable[], typeParameters?: string[], nodeInitializer?: IDLNodeInitializer): IDLInterface;
@@ -56,6 +56,7 @@ export var IDLExtendedAttributes;
56
56
  (function (IDLExtendedAttributes) {
57
57
  IDLExtendedAttributes["Accessor"] = "Accessor";
58
58
  IDLExtendedAttributes["Async"] = "Async";
59
+ IDLExtendedAttributes["ArkTSType"] = "ArkTSType";
59
60
  IDLExtendedAttributes["CallSignature"] = "CallSignature";
60
61
  IDLExtendedAttributes["CJType"] = "CJType";
61
62
  IDLExtendedAttributes["CommonMethod"] = "CommonMethod";
@@ -74,6 +75,7 @@ export var IDLExtendedAttributes;
74
75
  IDLExtendedAttributes["NativeModule"] = "NativeModule";
75
76
  IDLExtendedAttributes["Optional"] = "Optional";
76
77
  IDLExtendedAttributes["OriginalEnumMemberName"] = "OriginalEnumMemberName";
78
+ IDLExtendedAttributes["Predefined"] = "Predefined";
77
79
  IDLExtendedAttributes["Protected"] = "Protected";
78
80
  IDLExtendedAttributes["Synthetic"] = "Synthetic";
79
81
  IDLExtendedAttributes["TSType"] = "TSType";
@@ -81,7 +83,6 @@ export var IDLExtendedAttributes;
81
83
  IDLExtendedAttributes["TypeParameters"] = "TypeParameters";
82
84
  IDLExtendedAttributes["VerbatimDts"] = "VerbatimDts";
83
85
  IDLExtendedAttributes["HandWrittenImplementation"] = "HandWrittenImplementation";
84
- IDLExtendedAttributes["Predefined"] = "Predefined";
85
86
  })(IDLExtendedAttributes || (IDLExtendedAttributes = {}));
86
87
  export var IDLAccessorAttribute;
87
88
  (function (IDLAccessorAttribute) {
@@ -377,6 +378,16 @@ export function isEqualByQualifedName(a, b) {
377
378
  return false;
378
379
  return isEqualByQualifedName(a.namespace, b.namespace);
379
380
  }
381
+ export function getNamespaceName(a) {
382
+ return getNamespacesPathFor(a).map(it => it.name).join('.');
383
+ }
384
+ export function getFQName(a) {
385
+ let ns = getNamespaceName(a);
386
+ if (ns !== '') {
387
+ ns += '.';
388
+ }
389
+ return ns + a.name;
390
+ }
380
391
  export function createVersion(value, extendedAttributes, fileName) {
381
392
  return {
382
393
  kind: IDLKind.Version,
@@ -455,15 +466,8 @@ export function createPackage(name) {
455
466
  _idlNamedNodeBrand: innerIdlSymbol,
456
467
  };
457
468
  }
458
- export function createImport(name, importClause) {
459
- return {
460
- kind: IDLKind.Import,
461
- name,
462
- importClause: importClause,
463
- _idlNodeBrand: innerIdlSymbol,
464
- _idlEntryBrand: innerIdlSymbol,
465
- _idlNamedNodeBrand: innerIdlSymbol,
466
- };
469
+ export function createImport(name, importClause, nodeInitializer) {
470
+ return Object.assign(Object.assign({ kind: IDLKind.Import, name, importClause: importClause }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
467
471
  }
468
472
  export function createEnum(name, elements, nodeInitializer) {
469
473
  return Object.assign(Object.assign({ kind: IDLKind.Enum, name: name, elements: elements }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
@@ -1,4 +1,4 @@
1
1
  import * as ts from "typescript";
2
2
  import { GenerateOptions, GenericVisitor } from "./options";
3
- export declare function generate<T>(inputDirs: string[], inputFile: string | undefined, outputDir: string, visitorFactory: (sourceFile: ts.SourceFile, typeChecker: ts.TypeChecker) => GenericVisitor<T>, options: GenerateOptions<T>): void;
3
+ export declare function generate<T>(inputDirs: string[], inputFiles: string[], outputDir: string, visitorFactory: (sourceFile: ts.SourceFile, typeChecker: ts.TypeChecker) => GenericVisitor<T>, options: GenerateOptions<T>): void;
4
4
  //# sourceMappingURL=idlize.d.ts.map
@@ -19,27 +19,69 @@ function readdir(dir) {
19
19
  return fs.readdirSync(dir)
20
20
  .map(elem => path.join(dir, elem));
21
21
  }
22
- export function generate(inputDirs, inputFile, outputDir, visitorFactory, options) {
22
+ export function generate(inputDirs, inputFiles, outputDir, visitorFactory, options) {
23
23
  var _a, _b, _c;
24
- let input = inputFile ? [
25
- path.join(inputDirs[0], inputFile)
26
- ] : inputDirs.flatMap(it => readdir(path.resolve(it)));
27
- // Build a program using the set of root file names in fileNames
24
+ if (options.enableLog) {
25
+ console.log("Starting generation process...");
26
+ }
27
+ if (inputDirs.length === 0 && inputFiles.length === 0) {
28
+ console.error("Error: No input specified (no directories and no files).");
29
+ process.exit(1);
30
+ }
31
+ const resolvedInputDirs = inputDirs.map(dir => path.resolve(dir));
32
+ if (options.enableLog) {
33
+ console.log("Resolved input directories:", resolvedInputDirs);
34
+ }
35
+ let input = [];
36
+ if (resolvedInputDirs.length > 0) {
37
+ resolvedInputDirs.forEach(dir => {
38
+ if (fs.existsSync(dir) && fs.statSync(dir).isDirectory()) {
39
+ if (options.enableLog) {
40
+ console.log(`Processing all .d.ts from directory: ${dir}`);
41
+ }
42
+ const files = readdir(dir).filter(file => file.endsWith(".d.ts"));
43
+ input = input.concat(files);
44
+ }
45
+ else {
46
+ console.warn(`Warning: Directory does not exist or is not a directory: ${dir}`);
47
+ }
48
+ });
49
+ }
50
+ if (inputFiles.length > 0) {
51
+ inputFiles.forEach(file => {
52
+ const fullPath = path.resolve(file);
53
+ if (fs.existsSync(fullPath)) {
54
+ if (options.enableLog) {
55
+ console.log(`Including input file: ${fullPath}`);
56
+ }
57
+ input.push(fullPath);
58
+ }
59
+ else {
60
+ console.warn(`Warning: Input file does not exist: ${fullPath}`);
61
+ }
62
+ });
63
+ }
64
+ input = Array.from(new Set(input.map(p => path.resolve(p)))).sort();
28
65
  let program = ts.createProgram(input.concat([path.join(__dirname, "../stdlib.d.ts")]), options.compilerOptions);
29
- // Get the checker, we will use it to find more about classes
66
+ if (options.enableLog) {
67
+ console.log("Initialized TypeScript program with input files:", input);
68
+ }
30
69
  if (outputDir && !fs.existsSync(outputDir))
31
70
  fs.mkdirSync(outputDir, { recursive: true });
32
71
  const typeChecker = program.getTypeChecker();
33
72
  (_a = options.onBegin) === null || _a === void 0 ? void 0 : _a.call(options, outputDir, typeChecker);
34
- // Visit every sourceFile in the program
35
- let cared = inputDirs.map(it => path.resolve(it));
36
73
  for (const sourceFile of program.getSourceFiles()) {
37
- if (!cared.some(it => path.resolve(sourceFile.fileName).indexOf(it) >= 0)) {
38
- // console.log("Ignore ", path.resolve(sourceFile.fileName) , "wrt", inputDirs)
74
+ const resolvedSourceFile = path.resolve(sourceFile.fileName);
75
+ const isInDir = resolvedInputDirs.some(dir => resolvedSourceFile.startsWith(dir));
76
+ const isExplicitFile = input.some(f => path.resolve(f) === resolvedSourceFile);
77
+ if (!isInDir && !isExplicitFile) {
78
+ if (options.enableLog) {
79
+ console.log(`Skipping file: ${resolvedSourceFile}`);
80
+ }
39
81
  continue;
40
82
  }
41
- if (inputFile && path.basename(sourceFile.fileName) != inputFile) {
42
- continue;
83
+ if (options.enableLog) {
84
+ console.log(`Processing file: ${resolvedSourceFile}`);
43
85
  }
44
86
  // Walk the tree to search for classes
45
87
  const visitor = visitorFactory(sourceFile, typeChecker);
@@ -47,6 +89,8 @@ export function generate(inputDirs, inputFile, outputDir, visitorFactory, option
47
89
  (_b = options.onSingleFile) === null || _b === void 0 ? void 0 : _b.call(options, output, outputDir, sourceFile);
48
90
  }
49
91
  (_c = options.onEnd) === null || _c === void 0 ? void 0 : _c.call(options, outputDir);
50
- return;
92
+ if (options.enableLog) {
93
+ console.log("Generation completed.");
94
+ }
51
95
  }
52
96
  //# sourceMappingURL=idlize.js.map
@@ -1,4 +1,5 @@
1
1
  export * from "./config";
2
+ export * from "./configMerge";
2
3
  export * from "./idl";
3
4
  export * from "./library";
4
5
  export * from "./idlize";
@@ -16,6 +17,10 @@ export * from "./LanguageWriters/common";
16
17
  export * from "./LanguageWriters/nameConvertor";
17
18
  export * from "./LanguageWriters/InteropConvertor";
18
19
  export * from "./LanguageWriters/convertors/CppConvertors";
20
+ export * from "./LanguageWriters/convertors/TSConvertors";
21
+ export * from "./LanguageWriters/convertors/ETSConvertors";
22
+ export * from "./LanguageWriters/convertors/JavaConvertors";
23
+ export * from "./LanguageWriters/convertors/CJConvertors";
19
24
  export * from "./LanguageWriters/writers/CJLanguageWriter";
20
25
  export * from "./LanguageWriters/writers/CLikeLanguageWriter";
21
26
  export * from "./LanguageWriters/writers/CppLanguageWriter";
@@ -23,7 +28,9 @@ export * from "./LanguageWriters/writers/JavaLanguageWriter";
23
28
  export * from "./LanguageWriters/writers/TsLanguageWriter";
24
29
  export * from "./LanguageWriters/writers/ETSLanguageWriter";
25
30
  export * from "./peer-generation/idl/IdlNameConvertor";
31
+ export * from "./peer-generation/LayoutManager";
26
32
  export * from "./peer-generation/PrimitiveType";
33
+ export * from "./peer-generation/PeerLibrary";
27
34
  export * from "./peer-generation/PeerFile";
28
35
  export * from "./peer-generation/PeerClass";
29
36
  export * from "./peer-generation/PeerMethod";
@@ -13,6 +13,7 @@
13
13
  * limitations under the License.
14
14
  */
15
15
  export * from "./config";
16
+ export * from "./configMerge";
16
17
  export * from "./idl";
17
18
  export * from "./library";
18
19
  export * from "./idlize";
@@ -30,6 +31,10 @@ export * from "./LanguageWriters/common";
30
31
  export * from "./LanguageWriters/nameConvertor";
31
32
  export * from "./LanguageWriters/InteropConvertor";
32
33
  export * from "./LanguageWriters/convertors/CppConvertors";
34
+ export * from "./LanguageWriters/convertors/TSConvertors";
35
+ export * from "./LanguageWriters/convertors/ETSConvertors";
36
+ export * from "./LanguageWriters/convertors/JavaConvertors";
37
+ export * from "./LanguageWriters/convertors/CJConvertors";
33
38
  export * from "./LanguageWriters/writers/CJLanguageWriter";
34
39
  export * from "./LanguageWriters/writers/CLikeLanguageWriter";
35
40
  export * from "./LanguageWriters/writers/CppLanguageWriter";
@@ -37,7 +42,9 @@ export * from "./LanguageWriters/writers/JavaLanguageWriter";
37
42
  export * from "./LanguageWriters/writers/TsLanguageWriter";
38
43
  export * from "./LanguageWriters/writers/ETSLanguageWriter";
39
44
  export * from "./peer-generation/idl/IdlNameConvertor";
45
+ export * from "./peer-generation/LayoutManager";
40
46
  export * from "./peer-generation/PrimitiveType";
47
+ export * from "./peer-generation/PeerLibrary";
41
48
  export * from "./peer-generation/PeerFile";
42
49
  export * from "./peer-generation/PeerClass";
43
50
  export * from "./peer-generation/PeerMethod";
@@ -4,6 +4,7 @@ export interface GenerateOptions<T> {
4
4
  onBegin?: (outDir: string, typeChecker: ts.TypeChecker) => void;
5
5
  onSingleFile?: (entries: T, outDir: string, inputFile: ts.SourceFile) => void;
6
6
  onEnd?: (outDir: string) => void;
7
+ enableLog?: boolean;
7
8
  }
8
9
  export interface GenericVisitor<T> {
9
10
  visitWholeFile(): T;
@@ -0,0 +1,2 @@
1
+ export * from "./nameConvertor";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,2 @@
1
+ export * from "./nameConvertor";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,25 @@
1
+ import * as idl from '../../idl';
2
+ export interface IdlNameConvertor {
3
+ convert(node: idl.IDLNode): string;
4
+ }
5
+ export interface TypeConvertor<T> {
6
+ convertOptional(type: idl.IDLOptionalType): T;
7
+ convertUnion(type: idl.IDLUnionType): T;
8
+ convertContainer(type: idl.IDLContainerType): T;
9
+ convertImport(type: idl.IDLReferenceType, importClause: string): T;
10
+ convertTypeReference(type: idl.IDLReferenceType): T;
11
+ convertTypeParameter(type: idl.IDLTypeParameterType): T;
12
+ convertPrimitiveType(type: idl.IDLPrimitiveType): T;
13
+ }
14
+ export declare function convertType<T>(convertor: TypeConvertor<T>, type: idl.IDLType): T;
15
+ export interface DeclarationConvertor<T> {
16
+ convertInterface(node: idl.IDLInterface): T;
17
+ convertEnum(node: idl.IDLEnum): T;
18
+ convertTypedef(node: idl.IDLTypedef): T;
19
+ convertCallback(node: idl.IDLCallback): T;
20
+ }
21
+ export declare function convertDeclaration<T>(convertor: DeclarationConvertor<T>, decl: idl.IDLEntry): T;
22
+ export interface NodeConvertor<T> extends TypeConvertor<T>, DeclarationConvertor<T> {
23
+ }
24
+ export declare function convertNode<T>(convertor: NodeConvertor<T>, node: idl.IDLNode): T;
25
+ //# sourceMappingURL=nameConvertor.d.ts.map