@idlizer/core 2.0.15

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 (78) hide show
  1. package/build/lib/src/IndentedPrinter.d.ts +28 -0
  2. package/build/lib/src/IndentedPrinter.js +81 -0
  3. package/build/lib/src/Language.d.ts +15 -0
  4. package/build/lib/src/Language.js +42 -0
  5. package/build/lib/src/LanguageWriters/ArgConvertors.d.ts +318 -0
  6. package/build/lib/src/LanguageWriters/ArgConvertors.js +1015 -0
  7. package/build/lib/src/LanguageWriters/InteropConvertor.d.ts +36 -0
  8. package/build/lib/src/LanguageWriters/InteropConvertor.js +174 -0
  9. package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +386 -0
  10. package/build/lib/src/LanguageWriters/LanguageWriter.js +746 -0
  11. package/build/lib/src/LanguageWriters/common.d.ts +17 -0
  12. package/build/lib/src/LanguageWriters/common.js +33 -0
  13. package/build/lib/src/LanguageWriters/convertors/CppConvertors.d.ts +8 -0
  14. package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +35 -0
  15. package/build/lib/src/LanguageWriters/index.d.ts +3 -0
  16. package/build/lib/src/LanguageWriters/index.js +3 -0
  17. package/build/lib/src/LanguageWriters/nameConvertor.d.ts +28 -0
  18. package/build/lib/src/LanguageWriters/nameConvertor.js +61 -0
  19. package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +147 -0
  20. package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +578 -0
  21. package/build/lib/src/LanguageWriters/writers/CLikeLanguageWriter.d.ts +46 -0
  22. package/build/lib/src/LanguageWriters/writers/CLikeLanguageWriter.js +121 -0
  23. package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.d.ts +116 -0
  24. package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +472 -0
  25. package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.d.ts +72 -0
  26. package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +329 -0
  27. package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.d.ts +83 -0
  28. package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.js +275 -0
  29. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +93 -0
  30. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +390 -0
  31. package/build/lib/src/LibraryInterface.d.ts +21 -0
  32. package/build/lib/src/LibraryInterface.js +2 -0
  33. package/build/lib/src/config.d.ts +8 -0
  34. package/build/lib/src/config.js +20 -0
  35. package/build/lib/src/from-idl/DtsPrinter.d.ts +35 -0
  36. package/build/lib/src/from-idl/DtsPrinter.js +375 -0
  37. package/build/lib/src/from-idl/common.d.ts +5 -0
  38. package/build/lib/src/from-idl/common.js +83 -0
  39. package/build/lib/src/from-idl/deserialize.d.ts +9 -0
  40. package/build/lib/src/from-idl/deserialize.js +384 -0
  41. package/build/lib/src/from-idl/toString.d.ts +2 -0
  42. package/build/lib/src/from-idl/toString.js +18 -0
  43. package/build/lib/src/from-idl/webidl2-utils.d.ts +20 -0
  44. package/build/lib/src/from-idl/webidl2-utils.js +84 -0
  45. package/build/lib/src/idl.d.ts +404 -0
  46. package/build/lib/src/idl.js +1015 -0
  47. package/build/lib/src/idlize.d.ts +4 -0
  48. package/build/lib/src/idlize.js +52 -0
  49. package/build/lib/src/index.d.ts +34 -0
  50. package/build/lib/src/index.js +48 -0
  51. package/build/lib/src/inheritance.d.ts +16 -0
  52. package/build/lib/src/inheritance.js +76 -0
  53. package/build/lib/src/languageSpecificKeywords.d.ts +5 -0
  54. package/build/lib/src/languageSpecificKeywords.js +51 -0
  55. package/build/lib/src/library.d.ts +67 -0
  56. package/build/lib/src/library.js +190 -0
  57. package/build/lib/src/options.d.ts +11 -0
  58. package/build/lib/src/options.js +16 -0
  59. package/build/lib/src/peer-generation/PrimitiveType.d.ts +24 -0
  60. package/build/lib/src/peer-generation/PrimitiveType.js +52 -0
  61. package/build/lib/src/peer-generation/ReferenceResolver.d.ts +9 -0
  62. package/build/lib/src/peer-generation/ReferenceResolver.js +37 -0
  63. package/build/lib/src/peer-generation/idl/IdlNameConvertor.d.ts +28 -0
  64. package/build/lib/src/peer-generation/idl/IdlNameConvertor.js +82 -0
  65. package/build/lib/src/peer-generation/idl/common.d.ts +9 -0
  66. package/build/lib/src/peer-generation/idl/common.js +70 -0
  67. package/build/lib/src/peer-generation/unions.d.ts +29 -0
  68. package/build/lib/src/peer-generation/unions.js +111 -0
  69. package/build/lib/src/rand_utils.d.ts +6 -0
  70. package/build/lib/src/rand_utils.js +100 -0
  71. package/build/lib/src/util.d.ts +75 -0
  72. package/build/lib/src/util.js +622 -0
  73. package/package.json +49 -0
  74. package/webidl2.js/LICENSE +21 -0
  75. package/webidl2.js/README.md +827 -0
  76. package/webidl2.js/dist/package.json +3 -0
  77. package/webidl2.js/dist/webidl2.js +4547 -0
  78. package/webidl2.js/package.json +55 -0
@@ -0,0 +1,4 @@
1
+ import * as ts from "typescript";
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;
4
+ //# sourceMappingURL=idlize.d.ts.map
@@ -0,0 +1,52 @@
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 ts from "typescript";
16
+ import * as fs from "fs";
17
+ import * as path from "path";
18
+ function readdir(dir) {
19
+ return fs.readdirSync(dir)
20
+ .map(elem => path.join(dir, elem));
21
+ }
22
+ export function generate(inputDirs, inputFile, outputDir, visitorFactory, options) {
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
28
+ 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
30
+ if (outputDir && !fs.existsSync(outputDir))
31
+ fs.mkdirSync(outputDir, { recursive: true });
32
+ const typeChecker = program.getTypeChecker();
33
+ (_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
+ 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)
39
+ continue;
40
+ }
41
+ if (inputFile && path.basename(sourceFile.fileName) != inputFile) {
42
+ continue;
43
+ }
44
+ // Walk the tree to search for classes
45
+ const visitor = visitorFactory(sourceFile, typeChecker);
46
+ const output = visitor.visitWholeFile();
47
+ (_b = options.onSingleFile) === null || _b === void 0 ? void 0 : _b.call(options, output, outputDir, sourceFile);
48
+ }
49
+ (_c = options.onEnd) === null || _c === void 0 ? void 0 : _c.call(options, outputDir);
50
+ return;
51
+ }
52
+ //# sourceMappingURL=idlize.js.map
@@ -0,0 +1,34 @@
1
+ export * from "./config";
2
+ export * from "./idl";
3
+ export * from "./library";
4
+ export * from "./idlize";
5
+ export * from "./inheritance";
6
+ export * from "./Language";
7
+ export * from "./languageSpecificKeywords";
8
+ export * from "./options";
9
+ export * from "./util";
10
+ export * from "./rand_utils";
11
+ export * from "./IndentedPrinter";
12
+ export * from "./LibraryInterface";
13
+ export * from "./LanguageWriters/LanguageWriter";
14
+ export * from "./LanguageWriters/ArgConvertors";
15
+ export * from "./LanguageWriters/common";
16
+ export * from "./LanguageWriters/nameConvertor";
17
+ export * from "./LanguageWriters/InteropConvertor";
18
+ export * from "./LanguageWriters/convertors/CppConvertors";
19
+ export * from "./LanguageWriters/writers/CJLanguageWriter";
20
+ export * from "./LanguageWriters/writers/CLikeLanguageWriter";
21
+ export * from "./LanguageWriters/writers/CppLanguageWriter";
22
+ export * from "./LanguageWriters/writers/JavaLanguageWriter";
23
+ export * from "./LanguageWriters/writers/TsLanguageWriter";
24
+ export * from "./LanguageWriters/writers/ETSLanguageWriter";
25
+ export * from "./peer-generation/idl/IdlNameConvertor";
26
+ export * from "./peer-generation/PrimitiveType";
27
+ export * from "./peer-generation/unions";
28
+ export * from "./LanguageWriters";
29
+ export * from "./peer-generation/ReferenceResolver";
30
+ export * from "./peer-generation/idl/common";
31
+ export { fromIDL } from "./from-idl/common";
32
+ export { idlToDtsString, CustomPrintVisitor } from "./from-idl/DtsPrinter";
33
+ export { toIDL, toIDLFile, addSyntheticType, resolveSyntheticType } from "./from-idl/deserialize";
34
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,48 @@
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
+ export * from "./config";
16
+ export * from "./idl";
17
+ export * from "./library";
18
+ export * from "./idlize";
19
+ export * from "./inheritance";
20
+ export * from "./Language";
21
+ export * from "./languageSpecificKeywords";
22
+ export * from "./options";
23
+ export * from "./util";
24
+ export * from "./rand_utils";
25
+ export * from "./IndentedPrinter";
26
+ export * from "./LibraryInterface";
27
+ export * from "./LanguageWriters/LanguageWriter";
28
+ export * from "./LanguageWriters/ArgConvertors";
29
+ export * from "./LanguageWriters/common";
30
+ export * from "./LanguageWriters/nameConvertor";
31
+ export * from "./LanguageWriters/InteropConvertor";
32
+ export * from "./LanguageWriters/convertors/CppConvertors";
33
+ export * from "./LanguageWriters/writers/CJLanguageWriter";
34
+ export * from "./LanguageWriters/writers/CLikeLanguageWriter";
35
+ export * from "./LanguageWriters/writers/CppLanguageWriter";
36
+ export * from "./LanguageWriters/writers/JavaLanguageWriter";
37
+ export * from "./LanguageWriters/writers/TsLanguageWriter";
38
+ export * from "./LanguageWriters/writers/ETSLanguageWriter";
39
+ export * from "./peer-generation/idl/IdlNameConvertor";
40
+ export * from "./peer-generation/PrimitiveType";
41
+ export * from "./peer-generation/unions";
42
+ export * from "./LanguageWriters";
43
+ export * from "./peer-generation/ReferenceResolver";
44
+ export * from "./peer-generation/idl/common";
45
+ export { fromIDL } from "./from-idl/common";
46
+ export { idlToDtsString, CustomPrintVisitor } from "./from-idl/DtsPrinter";
47
+ export { toIDL, toIDLFile, addSyntheticType, resolveSyntheticType } from "./from-idl/deserialize";
48
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,16 @@
1
+ import * as ts from "typescript";
2
+ export declare enum InheritanceRole {
3
+ Finalizable = 0,
4
+ PeerNode = 1,
5
+ Root = 2,
6
+ Heir = 3,
7
+ Standalone = 4
8
+ }
9
+ export declare function isCommonMethodOrSubclass(typeChecker: ts.TypeChecker, decl: ts.ClassDeclaration): boolean;
10
+ export declare function determineInheritanceRole(name: string): InheritanceRole;
11
+ export declare function determineParentRole(name: string | undefined, parent: string | undefined): InheritanceRole;
12
+ export declare function isCommonMethod(name: string): boolean;
13
+ export declare function isRoot(name: string): boolean;
14
+ export declare function isStandalone(name: string): boolean;
15
+ export declare function isHeir(name: string): boolean;
16
+ //# sourceMappingURL=inheritance.d.ts.map
@@ -0,0 +1,76 @@
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 ts from "typescript";
16
+ import { generatorConfiguration } from "./config";
17
+ import { asString, heritageDeclarations, identName } from "./util";
18
+ export var InheritanceRole;
19
+ (function (InheritanceRole) {
20
+ InheritanceRole[InheritanceRole["Finalizable"] = 0] = "Finalizable";
21
+ InheritanceRole[InheritanceRole["PeerNode"] = 1] = "PeerNode";
22
+ InheritanceRole[InheritanceRole["Root"] = 2] = "Root";
23
+ InheritanceRole[InheritanceRole["Heir"] = 3] = "Heir";
24
+ InheritanceRole[InheritanceRole["Standalone"] = 4] = "Standalone";
25
+ })(InheritanceRole || (InheritanceRole = {}));
26
+ export function isCommonMethodOrSubclass(typeChecker, decl) {
27
+ var _a;
28
+ let name = identName(decl.name);
29
+ let isSubclass = isRoot(name);
30
+ (_a = decl.heritageClauses) === null || _a === void 0 ? void 0 : _a.forEach(it => {
31
+ heritageDeclarations(typeChecker, it).forEach(it => {
32
+ let name = asString(it.name);
33
+ isSubclass = isSubclass || isRoot(name);
34
+ if (!ts.isClassDeclaration(it))
35
+ return isSubclass;
36
+ isSubclass = isSubclass || isCommonMethodOrSubclass(typeChecker, it);
37
+ });
38
+ });
39
+ return isSubclass;
40
+ }
41
+ export function determineInheritanceRole(name) {
42
+ if (generatorConfiguration().paramArray("rootComponents").includes(name))
43
+ return InheritanceRole.Root;
44
+ if (generatorConfiguration().paramArray("standaloneComponents").includes(name))
45
+ return InheritanceRole.Standalone;
46
+ return InheritanceRole.Heir;
47
+ }
48
+ export function determineParentRole(name, parent) {
49
+ if (!name)
50
+ throw new Error(`name must be known: ${parent}`);
51
+ if (parent === undefined) {
52
+ if (isStandalone(name))
53
+ return InheritanceRole.PeerNode;
54
+ if (isCommonMethod(name))
55
+ return InheritanceRole.PeerNode;
56
+ if (isRoot(name))
57
+ return InheritanceRole.PeerNode;
58
+ throw new Error(`Expected check to be exhaustive. node: ${name}`);
59
+ }
60
+ if (isRoot(parent))
61
+ return InheritanceRole.Root;
62
+ return InheritanceRole.Heir;
63
+ }
64
+ export function isCommonMethod(name) {
65
+ return name === "CommonMethod";
66
+ }
67
+ export function isRoot(name) {
68
+ return determineInheritanceRole(name) === InheritanceRole.Root;
69
+ }
70
+ export function isStandalone(name) {
71
+ return determineInheritanceRole(name) === InheritanceRole.Standalone;
72
+ }
73
+ export function isHeir(name) {
74
+ return determineInheritanceRole(name) === InheritanceRole.Heir;
75
+ }
76
+ //# sourceMappingURL=inheritance.js.map
@@ -0,0 +1,5 @@
1
+ export declare const cppKeywords: Set<string>;
2
+ export declare const CJKeywords: Set<string>;
3
+ export declare const IDLKeywords: Set<string>;
4
+ export declare const TSKeywords: Set<string>;
5
+ //# sourceMappingURL=languageSpecificKeywords.d.ts.map
@@ -0,0 +1,51 @@
1
+ // See https://en.cppreference.com/w/cpp/keyword.
2
+ export const cppKeywords = new Set([
3
+ `alignas`, `alignof`, `and`,
4
+ `and_eq`, `asm`, `atomic_cancel`, `atomic_commit`,
5
+ `atomic_noexcept`, `auto`, `bitand`, `bitor`, `bool`,
6
+ `break`, `case`, `catch`, `char`, `char8_t`, `char16_t`,
7
+ `char32_t`, `class`, `compl`, `concept`, `const`, `consteval`,
8
+ `constexpr`, `constinit`, `const_cast`, `continue`, `co_await`,
9
+ `co_return`, `co_yield`, `decltype`, `default`, `delete`, `do`,
10
+ `double`, `dynamic_cast`, `else`, `enum`, `explicit`, `export`,
11
+ `extern`, `false`, `float`, `for`, `friend`, `goto`, `if`,
12
+ `inline`, `int`, `long`, `mutable`, `namespace`, `new`, `noexcept`,
13
+ `not`, `not_eq`, `nullptr`, `operator`, `or`, `or_eq`, `private`,
14
+ `protected`, `public`, `reflexpr`, `register`, `reinterpret_cast`,
15
+ `requires`, `return`, `short`, `signed`,
16
+ `sizeof`, `static`, `static_assert`, `static_cast`,
17
+ `struct`, `switch`, `synchronized`, `template`,
18
+ `this`, `thread_local`, `throw`, `true`, `try`,
19
+ `typedef`, `typeid`, `typename`, `union`,
20
+ `unsigned`, `using`, `virtual`, `void`,
21
+ `volatile`, `wchar_t`, `while`, `xor`,
22
+ `xor_eq`
23
+ ]);
24
+ export const CJKeywords = new Set([
25
+ 'Int8', 'Int16', 'Int32', 'Int64', 'IntNative',
26
+ 'UInt8', 'UInt16', 'UInt32', 'UInt64', 'UIntNative',
27
+ 'Float16', 'Float32', 'Float64', 'Rune',
28
+ 'Bool', 'Unit', 'Nothing', 'struct',
29
+ 'enum', 'This', 'package', 'import',
30
+ 'class', 'interface', 'func', 'main',
31
+ 'let', 'var', 'const', 'type', 'init',
32
+ 'this', 'super', 'if', 'else', 'case',
33
+ 'try', 'catch', 'finally', 'for', 'do',
34
+ 'while', 'throw', 'return', 'continue',
35
+ 'break', 'is', 'as', 'in', 'match',
36
+ 'from', 'where', 'extend', 'spawn',
37
+ 'synchronized', 'macro', 'quote', 'true',
38
+ 'false', 'static', 'public', 'private',
39
+ 'protected', 'override', 'redef', 'abstract',
40
+ 'open', 'operator', 'foreign', 'inout',
41
+ 'prop', 'mut', 'unsafe', 'get', 'set'
42
+ ]);
43
+ export const IDLKeywords = new Set([
44
+ "attribute", "callback", "object", "toString",
45
+ 'sequence', 'record', 'or', 'Int8Array',
46
+ 'interface', 'number', 'undefined'
47
+ ]);
48
+ export const TSKeywords = new Set([
49
+ "namespace"
50
+ ]);
51
+ //# sourceMappingURL=languageSpecificKeywords.js.map
@@ -0,0 +1,67 @@
1
+ import * as idl from './idl';
2
+ export interface IDLLibrary {
3
+ readonly files: readonly IDLFile[];
4
+ }
5
+ export interface IDLFile {
6
+ fileName: string;
7
+ package?: idl.IDLPackage;
8
+ entities: idl.IDLNode[];
9
+ }
10
+ declare function createLibrary(files: IDLFile[]): IDLLibrary;
11
+ declare function toLibrary(ii: Iterable<IDLFile>): IDLLibrary;
12
+ declare function serializeParam(params: unknown): string;
13
+ export interface LibraryQuery<A, R> {
14
+ fn: (x: A) => R;
15
+ key: string;
16
+ _reqBrand: unknown;
17
+ }
18
+ export interface LibraryReducer<R> {
19
+ fn: (x: IDLLibrary) => R;
20
+ key: string;
21
+ _redBrand: unknown;
22
+ }
23
+ declare function req<A, R>(key: string, fn: (x: A) => R): LibraryQuery<A, R>;
24
+ declare function compose<B, R>(base: LibraryReducer<B>, next: LibraryQuery<B, R>): LibraryReducer<R>;
25
+ declare function concat<A, R1, R2>(f: LibraryQuery<A, R1>, g: LibraryQuery<A, R2>): LibraryQuery<A, [R1, R2]>;
26
+ declare class LensBuilder<R> {
27
+ private req;
28
+ private constructor();
29
+ static make<R>(r: LibraryReducer<R>): LensBuilder<R>;
30
+ pipe<T>(r: LibraryQuery<R, T>): LensBuilder<T>;
31
+ row<T>(key: string, f: (x: R) => T): LensBuilder<T>;
32
+ query(): LibraryReducer<R>;
33
+ }
34
+ export declare function lens<R>(r: LibraryReducer<R>): LensBuilder<R>;
35
+ export type QueryType<T> = LibraryQuery<IDLLibrary, T> | LensBuilder<T>;
36
+ export declare function query<T>(lib: IDLLibrary, input: QueryType<T>): T;
37
+ interface EntitiesParams {
38
+ expandNamespaces?: boolean;
39
+ slipPackage?: boolean;
40
+ }
41
+ export declare const lib: {
42
+ createLibrary: typeof createLibrary;
43
+ toLibrary: typeof toLibrary;
44
+ lens: typeof lens;
45
+ query: typeof query;
46
+ select: {
47
+ files(): LibraryReducer<readonly IDLFile[]>;
48
+ nodes(params: EntitiesParams): LibraryQuery<readonly IDLFile[], idl.IDLNode[]>;
49
+ entries(): LibraryQuery<idl.IDLNode[], idl.IDLEntry[]>;
50
+ interfaces(): LibraryQuery<idl.IDLNode[], idl.IDLInterface[]>;
51
+ names(): LibraryQuery<idl.IDLNode[], string[]>;
52
+ name(name: string): LibraryReducer<idl.IDLNode[]>;
53
+ };
54
+ utils: {
55
+ idx: <T>(x: number) => LibraryQuery<T[], T | undefined>;
56
+ fst: <T_1>() => LibraryQuery<T_1[], T_1 | undefined>;
57
+ lst: <T_2>() => LibraryQuery<T_2[], T_2 | undefined>;
58
+ };
59
+ req: typeof req;
60
+ compose: typeof compose;
61
+ concat: typeof concat;
62
+ other: {
63
+ serializeParam: typeof serializeParam;
64
+ };
65
+ };
66
+ export {};
67
+ //# sourceMappingURL=library.d.ts.map
@@ -0,0 +1,190 @@
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
+ function createLibrary(files) {
17
+ return {
18
+ files
19
+ };
20
+ }
21
+ function toLibrary(ii) {
22
+ return {
23
+ files: Array.from(ii)
24
+ };
25
+ }
26
+ function serializeParam(params) {
27
+ if (typeof params === 'undefined') {
28
+ return 'undefined';
29
+ }
30
+ if (typeof params === 'boolean') {
31
+ return params ? 'true' : 'false';
32
+ }
33
+ if (typeof params === 'string') {
34
+ return `"${params}"`;
35
+ }
36
+ if (typeof params === 'number') {
37
+ return params.toString();
38
+ }
39
+ if (typeof params === 'object') {
40
+ if (params === null) {
41
+ return 'null';
42
+ }
43
+ if (Array.isArray(params)) {
44
+ return '[' + params.map(serializeParam).join(', ') + ']';
45
+ }
46
+ const keys = Object.keys(params);
47
+ keys.sort();
48
+ return '{' +
49
+ keys.map((key) => {
50
+ if (typeof key !== 'string') {
51
+ throw new Error(`Unsupported key! "${typeof key}"`);
52
+ }
53
+ const objectKey = key;
54
+ return `${key}=${serializeParam(params[objectKey])}`;
55
+ }).join(',')
56
+ + '}';
57
+ }
58
+ throw new Error(`Unsupported type! "${typeof params}"`);
59
+ }
60
+ const queryCache = new Map();
61
+ function cached(key, f) {
62
+ return x => {
63
+ if (queryCache.has(key)) {
64
+ return queryCache.get(key);
65
+ }
66
+ const v = f(x);
67
+ queryCache.set(key, v);
68
+ return v;
69
+ };
70
+ }
71
+ function reduce(key, f) {
72
+ return {
73
+ fn: cached(key, f),
74
+ key,
75
+ _redBrand: {}
76
+ };
77
+ }
78
+ function req(key, fn) {
79
+ return {
80
+ fn,
81
+ key,
82
+ _reqBrand: {}
83
+ };
84
+ }
85
+ function compose(base, next) {
86
+ const key = base.key + '.' + next.key;
87
+ return {
88
+ fn: cached(key, x => next.fn(base.fn(x))),
89
+ key,
90
+ _redBrand: {}
91
+ };
92
+ }
93
+ function concat(f, g) {
94
+ const key = `$pair{${f.key},${g.key}}`;
95
+ return {
96
+ fn: cached(key, x => {
97
+ const r1 = f.fn(x);
98
+ const r2 = g.fn(x);
99
+ return [r1, r2];
100
+ }),
101
+ key,
102
+ _reqBrand: {}
103
+ };
104
+ }
105
+ class LensBuilder {
106
+ constructor(req) {
107
+ this.req = req;
108
+ }
109
+ static make(r) {
110
+ return new LensBuilder(r);
111
+ }
112
+ pipe(r) {
113
+ return new LensBuilder(compose(this.req, r));
114
+ }
115
+ row(key, f) {
116
+ return this.pipe(req(key, f));
117
+ }
118
+ query() {
119
+ return this.req;
120
+ }
121
+ }
122
+ export function lens(r) {
123
+ return LensBuilder.make(r);
124
+ }
125
+ export function query(lib, input) {
126
+ const request = input instanceof LensBuilder ? input.query() : input;
127
+ return request.fn(lib);
128
+ }
129
+ // UTILS
130
+ const utils = {
131
+ idx: (x) => req('idx', xs => xs.at(x)),
132
+ fst: () => req('fst', xs => xs.at(0)),
133
+ lst: () => req('lst', xs => xs.at(-1)),
134
+ };
135
+ const select = {
136
+ files() {
137
+ return reduce('files', x => x.files);
138
+ },
139
+ nodes(params) {
140
+ const key = 'entities' + serializeParam(params);
141
+ function go(node) {
142
+ if (idl.isNamespace(node) && params.expandNamespaces) {
143
+ return node.members.flatMap(go);
144
+ }
145
+ if (idl.isPackage(node) && params.slipPackage) {
146
+ return [];
147
+ }
148
+ return [node];
149
+ }
150
+ return req(key, xs => {
151
+ return xs.flatMap(x => x.entities).flatMap(go);
152
+ });
153
+ },
154
+ entries() {
155
+ return req('entries', xs => xs.filter(idl.isEntry));
156
+ },
157
+ interfaces() {
158
+ return req('interfaces', it => it.filter(idl.isInterface));
159
+ },
160
+ names() {
161
+ return req('names', xs => xs.flatMap(x => idl.isNamedNode(x) ? [x.name] : []));
162
+ },
163
+ name(name) {
164
+ return reduce(`select.by.name.${name}`, lib => {
165
+ return lib.files.flatMap(it => {
166
+ return it.entities.flatMap(it => {
167
+ if (idl.isNamedNode(it) && it.name === name) {
168
+ return [it];
169
+ }
170
+ return [];
171
+ });
172
+ });
173
+ });
174
+ },
175
+ };
176
+ export const lib = {
177
+ createLibrary,
178
+ toLibrary,
179
+ lens,
180
+ query,
181
+ select,
182
+ utils,
183
+ req,
184
+ compose,
185
+ concat,
186
+ other: {
187
+ serializeParam
188
+ }
189
+ };
190
+ //# sourceMappingURL=library.js.map
@@ -0,0 +1,11 @@
1
+ import * as ts from "typescript";
2
+ export interface GenerateOptions<T> {
3
+ compilerOptions: ts.CompilerOptions;
4
+ onBegin?: (outDir: string, typeChecker: ts.TypeChecker) => void;
5
+ onSingleFile?: (entries: T, outDir: string, inputFile: ts.SourceFile) => void;
6
+ onEnd?: (outDir: string) => void;
7
+ }
8
+ export interface GenericVisitor<T> {
9
+ visitWholeFile(): T;
10
+ }
11
+ //# sourceMappingURL=options.d.ts.map
@@ -0,0 +1,16 @@
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
+ export {};
16
+ //# sourceMappingURL=options.js.map
@@ -0,0 +1,24 @@
1
+ export declare class PrimitiveType {
2
+ protected name: string;
3
+ protected isPointer: boolean;
4
+ constructor(name: string, isPointer?: boolean);
5
+ getText(): string;
6
+ toString(): string;
7
+ }
8
+ export declare class PrimitiveTypeList {
9
+ static get UndefinedTag(): string;
10
+ static get UndefinedRuntime(): string;
11
+ static get ObjectTag(): string;
12
+ readonly Int32: PrimitiveType;
13
+ readonly Int64: PrimitiveType;
14
+ readonly Boolean: PrimitiveType;
15
+ readonly Function: PrimitiveType;
16
+ readonly Undefined: PrimitiveType;
17
+ readonly Void: PrimitiveType;
18
+ readonly NativePointer: PrimitiveType;
19
+ readonly Tag: PrimitiveType;
20
+ readonly Materialized: PrimitiveType;
21
+ readonly CustomObject: PrimitiveType;
22
+ }
23
+ export declare const PrimitiveTypesInstance: PrimitiveTypeList;
24
+ //# sourceMappingURL=PrimitiveType.d.ts.map
@@ -0,0 +1,52 @@
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 { generatorConfiguration } from "../config";
16
+ export class PrimitiveType {
17
+ constructor(name, isPointer = false) {
18
+ this.name = name;
19
+ this.isPointer = isPointer;
20
+ }
21
+ getText() {
22
+ return generatorConfiguration().param("TypePrefix") + this.name;
23
+ }
24
+ toString() {
25
+ return this.getText();
26
+ }
27
+ }
28
+ export class PrimitiveTypeList {
29
+ constructor() {
30
+ this.Int32 = new PrimitiveType(`Int32`);
31
+ this.Int64 = new PrimitiveType(`Int64`);
32
+ this.Boolean = new PrimitiveType(`Boolean`);
33
+ this.Function = new PrimitiveType(`Function`);
34
+ this.Undefined = new PrimitiveType(`Undefined`);
35
+ this.Void = new PrimitiveType(`Void`);
36
+ this.NativePointer = new PrimitiveType(`NativePointer`);
37
+ this.Tag = new PrimitiveType(`Tag`);
38
+ this.Materialized = new PrimitiveType(`Materialized`, true);
39
+ this.CustomObject = new PrimitiveType(`CustomObject`, true);
40
+ }
41
+ static get UndefinedTag() {
42
+ return "INTEROP_TAG_UNDEFINED";
43
+ }
44
+ static get UndefinedRuntime() {
45
+ return "INTEROP_RUNTIME_UNDEFINED";
46
+ }
47
+ static get ObjectTag() {
48
+ return "INTEROP_TAG_OBJECT";
49
+ }
50
+ }
51
+ export const PrimitiveTypesInstance = new PrimitiveTypeList();
52
+ //# sourceMappingURL=PrimitiveType.js.map
@@ -0,0 +1,9 @@
1
+ import * as idl from '../idl';
2
+ export interface ReferenceResolver {
3
+ resolveTypeReference(type: idl.IDLReferenceType, pointOfView?: idl.IDLEntry, rootEntries?: idl.IDLEntry[]): idl.IDLEntry | undefined;
4
+ toDeclaration(type: idl.IDLNode): idl.IDLNode;
5
+ }
6
+ export declare function createEmptyReferenceResolver(): ReferenceResolver;
7
+ /** Please do not store any global instances */
8
+ export declare function createAlternativeReferenceResolver(mainResolver: ReferenceResolver, alternatives: Map<string, idl.IDLEntry>): ReferenceResolver;
9
+ //# sourceMappingURL=ReferenceResolver.d.ts.map