@idlizer/core 2.0.37 → 2.0.38

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.
@@ -0,0 +1,36 @@
1
+ import * as idl from '../idl';
2
+ import { IdlNameConvertor, NodeConvertor } from "./nameConvertor";
3
+ import { ReferenceResolver } from "../peer-generation/ReferenceResolver";
4
+ export interface ConvertResult {
5
+ text: string;
6
+ noPrefix: boolean;
7
+ }
8
+ export declare class InteropConvertor implements NodeConvertor<ConvertResult> {
9
+ protected resolver: ReferenceResolver;
10
+ constructor(resolver: ReferenceResolver);
11
+ private make;
12
+ convertNode(node: idl.IDLNode): ConvertResult;
13
+ convertNamespace(node: idl.IDLNamespace): ConvertResult;
14
+ convertInterface(node: idl.IDLInterface): ConvertResult;
15
+ convertEnum(node: idl.IDLEnum): ConvertResult;
16
+ convertTypedef(node: idl.IDLTypedef): ConvertResult;
17
+ convertCallback(node: idl.IDLCallback): ConvertResult;
18
+ convertMethod(node: idl.IDLMethod): ConvertResult;
19
+ convertConstant(node: idl.IDLConstant): ConvertResult;
20
+ convertOptional(type: idl.IDLOptionalType): ConvertResult;
21
+ convertUnion(type: idl.IDLUnionType): ConvertResult;
22
+ convertContainer(type: idl.IDLContainerType): ConvertResult;
23
+ convertImport(type: idl.IDLReferenceType, _: string): ConvertResult;
24
+ convertTypeReference(type: idl.IDLReferenceType): ConvertResult;
25
+ convertTypeParameter(type: idl.IDLTypeParameterType): ConvertResult;
26
+ convertPrimitiveType(type: idl.IDLPrimitiveType): ConvertResult;
27
+ private enumName;
28
+ private computeTargetTypeLiteralName;
29
+ }
30
+ export declare class InteropNameConvertor implements IdlNameConvertor {
31
+ protected resolver: ReferenceResolver;
32
+ private readonly interopConvertor;
33
+ constructor(resolver: ReferenceResolver);
34
+ convert(node: idl.IDLNode): string;
35
+ }
36
+ //# sourceMappingURL=InteropConvertor.d.ts.map
@@ -0,0 +1,174 @@
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 * as idl from '../idl';
16
+ import { convertNode } from "./nameConvertor";
17
+ import { generatorConfiguration } from '../config';
18
+ import { capitalize } from '../util';
19
+ import { qualifiedName } from '../peer-generation/idl/common';
20
+ import { maybeTransformManagedCallback } from './ArgConvertors';
21
+ export class InteropConvertor {
22
+ constructor(resolver) {
23
+ this.resolver = resolver;
24
+ }
25
+ make(text, noPrefix = false) {
26
+ return { text, noPrefix };
27
+ }
28
+ convertNode(node) {
29
+ return convertNode(this, node);
30
+ }
31
+ convertNamespace(node) {
32
+ throw new Error("Internal error: namespaces are not allowed on the interop layer");
33
+ }
34
+ convertInterface(node) {
35
+ switch (node.subkind) {
36
+ case idl.IDLInterfaceSubkind.AnonymousInterface:
37
+ return node.name
38
+ ? this.make(node.name)
39
+ : this.make(this.computeTargetTypeLiteralName(node), true);
40
+ case idl.IDLInterfaceSubkind.Interface:
41
+ case idl.IDLInterfaceSubkind.Class:
42
+ if (idl.hasExtAttribute(node, idl.IDLExtendedAttributes.Predefined)) {
43
+ return this.make(node.name, true);
44
+ }
45
+ return this.make(node.name);
46
+ case idl.IDLInterfaceSubkind.Tuple:
47
+ return node.name
48
+ ? this.make(node.name)
49
+ : this.make(`Tuple_${node.properties.map(it => this.convertNode(idl.maybeOptional(it.type, it.isOptional)).text).join("_")}`, true);
50
+ }
51
+ }
52
+ convertEnum(node) {
53
+ return this.make(this.enumName(node));
54
+ }
55
+ convertTypedef(node) {
56
+ return this.make(node.name);
57
+ }
58
+ convertCallback(node) {
59
+ return this.make(generatorConfiguration().param("LibraryPrefix") + node.name, true);
60
+ }
61
+ convertMethod(node) {
62
+ return this.make(node.name);
63
+ }
64
+ convertConstant(node) {
65
+ return this.make(node.name);
66
+ }
67
+ /////////////////////////////////////////////////////////////////////////////////////////
68
+ convertOptional(type) {
69
+ return this.convertNode(type.type);
70
+ }
71
+ convertUnion(type) {
72
+ return this.make(type.name, false);
73
+ }
74
+ convertContainer(type) {
75
+ if (idl.IDLContainerUtils.isPromise(type)) {
76
+ return this.make(`Promise_${this.convertNode(type.elementType[0]).text}`);
77
+ }
78
+ if (idl.IDLContainerUtils.isSequence(type)) {
79
+ if (type.elementType[0] === idl.IDLU8Type) {
80
+ return this.make(`uint8_t*`, true);
81
+ }
82
+ return this.make(`Array_${this.convertNode(type.elementType[0]).text}`, true);
83
+ }
84
+ if (idl.IDLContainerUtils.isRecord(type)) {
85
+ return this.make(`Map_${this.convertNode(type.elementType[0]).text}_${this.convertNode(type.elementType[1]).text}`, true);
86
+ }
87
+ throw new Error(`Unmapped container type ${idl.DebugUtils.debugPrintType(type)}`);
88
+ }
89
+ convertImport(type, _) {
90
+ return this.make(idl.IDLCustomObjectType.name);
91
+ }
92
+ convertTypeReference(type) {
93
+ var _a;
94
+ const refName = type.name;
95
+ switch (refName) {
96
+ case "object":
97
+ case "Object":
98
+ return this.make('CustomObject');
99
+ }
100
+ if (generatorConfiguration().paramArray("knownParameterized").includes(refName)) {
101
+ return this.make('CustomObject');
102
+ }
103
+ let decl = this.resolver.toDeclaration(type);
104
+ if (idl.isCallback(decl)) {
105
+ decl = (_a = maybeTransformManagedCallback(decl)) !== null && _a !== void 0 ? _a : decl;
106
+ }
107
+ if (idl.isType(decl)) {
108
+ if (idl.isReferenceType(decl)) {
109
+ return this.make(`${capitalize(decl.name)}`);
110
+ }
111
+ return this.convertNode(decl);
112
+ }
113
+ let res = this.convertNode(decl);
114
+ if (type.name === "Optional")
115
+ res = this.make("Opt_" + res.text, true);
116
+ return res;
117
+ }
118
+ convertTypeParameter(type) {
119
+ return this.make('CustomObject');
120
+ }
121
+ convertPrimitiveType(type) {
122
+ switch (type) {
123
+ case idl.IDLVoidType: return this.make('void', true);
124
+ case idl.IDLI8Type: return this.make(`Int8`);
125
+ case idl.IDLU8Type: return this.make(`UInt8`);
126
+ case idl.IDLI16Type: return this.make(`Int16`);
127
+ case idl.IDLU16Type: return this.make(`UInt16`);
128
+ case idl.IDLI32Type: return this.make(`Int32`);
129
+ case idl.IDLU32Type: return this.make(`UInt32`);
130
+ case idl.IDLI64Type: return this.make(`Int64`);
131
+ case idl.IDLU64Type: return this.make(`UInt64`);
132
+ case idl.IDLF32Type: return this.make(`Float32`);
133
+ case idl.IDLF64Type: return this.make(`Float64`);
134
+ case idl.IDLNumberType: return this.make(`Number`);
135
+ case idl.IDLStringType: return this.make(`String`);
136
+ case idl.IDLBooleanType: return this.make(`Boolean`);
137
+ case idl.IDLPointerType: return this.make('NativePointer');
138
+ case idl.IDLUnknownType:
139
+ case idl.IDLCustomObjectType:
140
+ case idl.IDLAnyType: return this.make(`CustomObject`);
141
+ case idl.IDLUndefinedType: return this.make(`Undefined`);
142
+ case idl.IDLLengthType: return this.make(`Length`);
143
+ case idl.IDLFunctionType: return this.make(`Function`);
144
+ case idl.IDLDate: return this.make(`Date`);
145
+ case idl.IDLBufferType: return this.make('Buffer');
146
+ case idl.IDLPointerType: return this.make('Pointer');
147
+ }
148
+ throw new Error(`Unmapped primitive type ${idl.DebugUtils.debugPrintType(type)}`);
149
+ }
150
+ enumName(target) {
151
+ return qualifiedName(target, "_");
152
+ }
153
+ computeTargetTypeLiteralName(decl) {
154
+ const map = new Map();
155
+ for (const prop of decl.properties) {
156
+ const type = this.convertNode(prop.type);
157
+ const values = map.has(type.text) ? map.get(type.text) : [];
158
+ values.push(prop.name);
159
+ map.set(type.text, values);
160
+ }
161
+ const names = Array.from(map.keys()).map(key => `${key}_${map.get(key).join('_')}`);
162
+ return `Literal_${names.join('_')}`;
163
+ }
164
+ }
165
+ export class InteropNameConvertor {
166
+ constructor(resolver) {
167
+ this.resolver = resolver;
168
+ this.interopConvertor = new InteropConvertor(resolver);
169
+ }
170
+ convert(node) {
171
+ return this.interopConvertor.convertNode(node).text;
172
+ }
173
+ }
174
+ //# sourceMappingURL=InteropConvertor.js.map
@@ -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
@@ -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
@@ -0,0 +1,55 @@
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
+ export function convertType(convertor, type) {
17
+ if (idl.isOptionalType(type))
18
+ return convertor.convertOptional(type);
19
+ if (idl.isUnionType(type))
20
+ return convertor.convertUnion(type);
21
+ if (idl.isContainerType(type))
22
+ return convertor.convertContainer(type);
23
+ if (idl.isReferenceType(type)) {
24
+ const importAttr = idl.getExtAttribute(type, idl.IDLExtendedAttributes.Import);
25
+ return importAttr
26
+ ? convertor.convertImport(type, importAttr)
27
+ : convertor.convertTypeReference(type);
28
+ }
29
+ if (idl.isTypeParameterType(type))
30
+ return convertor.convertTypeParameter(type);
31
+ if (idl.isPrimitiveType(type))
32
+ return convertor.convertPrimitiveType(type);
33
+ throw new Error(`Unknown type ${idl.IDLKind[type.kind]}`);
34
+ }
35
+ export function convertDeclaration(convertor, decl) {
36
+ if (idl.isInterface(decl))
37
+ return convertor.convertInterface(decl);
38
+ if (idl.isEnum(decl))
39
+ return convertor.convertEnum(decl);
40
+ if (idl.isEnumMember(decl))
41
+ return convertor.convertEnum(decl.parent);
42
+ if (idl.isTypedef(decl))
43
+ return convertor.convertTypedef(decl);
44
+ if (idl.isCallback(decl))
45
+ return convertor.convertCallback(decl);
46
+ throw new Error(`Unknown declaration type ${decl.kind ? idl.IDLKind[decl.kind] : "(undefined kind)"}`);
47
+ }
48
+ export function convertNode(convertor, node) {
49
+ if (idl.isEntry(node))
50
+ return convertDeclaration(convertor, node);
51
+ if (idl.isType(node))
52
+ return convertType(convertor, node);
53
+ throw new Error(`Unknown node type ${idl.IDLKind[node.kind]}`);
54
+ }
55
+ //# sourceMappingURL=nameConvertor.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idlizer/core",
3
- "version": "2.0.37",
3
+ "version": "2.0.38",
4
4
  "description": "",
5
5
  "types": "build/lib/src/index.d.ts",
6
6
  "exports": {