@lwc-bolts/sf2ts 0.0.5 → 1.0.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/LICENSE.md +7 -0
- package/README.md +285 -0
- package/dist/apex/apexdoc.d.ts +19 -0
- package/dist/apex/apexdoc.js +79 -0
- package/dist/apex/file.d.ts +37 -0
- package/dist/apex/file.js +623 -0
- package/dist/apex/library.config.d.ts +23 -0
- package/dist/apex/library.config.js +17 -0
- package/dist/apex/library.d.ts +54 -0
- package/dist/apex/library.generated.d.ts +2 -0
- package/dist/apex/library.generated.js +215 -0
- package/dist/apex/library.js +47 -0
- package/dist/apex/namespace.d.ts +32 -0
- package/dist/apex/namespace.js +41 -0
- package/dist/apex/resolution.d.ts +77 -0
- package/dist/apex/resolution.js +306 -0
- package/dist/apex/sobjects.d.ts +45 -0
- package/dist/apex/sobjects.js +141 -0
- package/dist/context.d.ts +16 -0
- package/dist/context.js +28 -0
- package/dist/converters/apex-class.d.ts +7 -0
- package/dist/converters/apex-class.js +23 -0
- package/dist/converters/content-asset.d.ts +3 -0
- package/dist/converters/content-asset.js +20 -0
- package/dist/converters/custom-field.d.ts +3 -0
- package/dist/converters/custom-field.js +107 -0
- package/dist/converters/custom-label.d.ts +10 -0
- package/dist/converters/custom-label.js +36 -0
- package/dist/converters/custom-labels.d.ts +3 -0
- package/dist/converters/custom-labels.js +10 -0
- package/dist/converters/custom-object.d.ts +3 -0
- package/dist/converters/custom-object.js +37 -0
- package/dist/converters/custom-permission.d.ts +3 -0
- package/dist/converters/custom-permission.js +21 -0
- package/dist/converters/lightning-component-bundle.d.ts +7 -0
- package/dist/converters/lightning-component-bundle.js +31 -0
- package/dist/converters/lightning-message-channel.d.ts +10 -0
- package/dist/converters/lightning-message-channel.js +39 -0
- package/dist/converters/registry.d.ts +22 -0
- package/dist/converters/registry.js +18 -0
- package/dist/converters/static-resource.d.ts +3 -0
- package/dist/converters/static-resource.js +20 -0
- package/dist/diagnostics.d.ts +5 -0
- package/dist/diagnostics.js +18 -0
- package/dist/identifiers.d.ts +12 -0
- package/dist/identifiers.js +19 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +47 -0
- package/dist/jsdoc.d.ts +14 -0
- package/dist/jsdoc.js +28 -0
- package/dist/lightning-component-bundle/component-source.d.ts +6 -0
- package/dist/lightning-component-bundle/component-source.js +21 -0
- package/dist/lightning-component-bundle/metadata.d.ts +36 -0
- package/dist/lightning-component-bundle/metadata.js +93 -0
- package/dist/lightning-component-bundle/templates/ast.d.ts +47 -0
- package/dist/lightning-component-bundle/templates/ast.js +46 -0
- package/dist/lightning-component-bundle/templates/base-components.d.ts +6 -0
- package/dist/lightning-component-bundle/templates/base-components.js +17 -0
- package/dist/lightning-component-bundle/templates/declarations.d.ts +30 -0
- package/dist/lightning-component-bundle/templates/declarations.js +82 -0
- package/dist/lightning-component-bundle/templates/expressions.d.ts +16 -0
- package/dist/lightning-component-bundle/templates/expressions.js +33 -0
- package/dist/lightning-component-bundle/templates/helpers.d.ts +10 -0
- package/dist/lightning-component-bundle/templates/helpers.js +47 -0
- package/dist/lightning-component-bundle/templates/slots.d.ts +24 -0
- package/dist/lightning-component-bundle/templates/slots.js +78 -0
- package/dist/lightning-component-bundle/templates/source.d.ts +36 -0
- package/dist/lightning-component-bundle/templates/source.js +81 -0
- package/dist/lightning-component-bundle/templates/tags.d.ts +41 -0
- package/dist/lightning-component-bundle/templates/tags.js +36 -0
- package/dist/lightning-component-bundle/templates/template.d.ts +53 -0
- package/dist/lightning-component-bundle/templates/template.js +518 -0
- package/dist/lightning-component-bundle/templates/writer.d.ts +9 -0
- package/dist/lightning-component-bundle/templates/writer.js +32 -0
- package/dist/module-declaration.d.ts +27 -0
- package/dist/module-declaration.js +28 -0
- package/dist/names.d.ts +39 -0
- package/dist/names.js +67 -0
- package/dist/text-builder.d.ts +34 -0
- package/dist/text-builder.js +46 -0
- package/dist/types.d.ts +128 -0
- package/dist/types.js +3 -0
- package/dist/xml.d.ts +32 -0
- package/dist/xml.js +80 -0
- package/package.json +37 -26
- package/README.MD +0 -5
- package/lib/converts/_index.mjs +0 -8
- package/lib/converts/apex-class.mjs +0 -469
- package/lib/converts/content-asset.mjs +0 -48
- package/lib/converts/custom-field.mjs +0 -63
- package/lib/converts/custom-label.mjs +0 -61
- package/lib/converts/custom-labels.mjs +0 -34
- package/lib/converts/custom-object.mjs +0 -51
- package/lib/converts/custom-permission.mjs +0 -51
- package/lib/converts/static-resource.mjs +0 -56
- package/lib/index.mjs +0 -51
- package/lib/util.mjs +0 -68
- package/lib-cjs/bundle.cjs +0 -962
|
@@ -1,469 +0,0 @@
|
|
|
1
|
-
/** @import Parser from "web-tree-sitter" */
|
|
2
|
-
/** @import { Component, ConvertedComponent, MapPair } from "../index.mjs" */
|
|
3
|
-
import { getApexParser } from "web-tree-sitter-sfapex";
|
|
4
|
-
import { PositionAwareTextBuilder } from "../util.mjs";
|
|
5
|
-
|
|
6
|
-
/** @type { Parser } */
|
|
7
|
-
let prsr;
|
|
8
|
-
|
|
9
|
-
const getParserPromise = getApexParser().then((newParser) => {
|
|
10
|
-
prsr = newParser;
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
*
|
|
15
|
-
* @param {Component} comp
|
|
16
|
-
* @returns {ConvertedComponent}
|
|
17
|
-
*/
|
|
18
|
-
export function ApexClass(comp) {
|
|
19
|
-
// generate d.ts
|
|
20
|
-
if (prsr === undefined) {
|
|
21
|
-
/** @type { any } */
|
|
22
|
-
const err = new Error("Apex parser not ready yet");
|
|
23
|
-
err.waitFor = getParserPromise; // smuggle a "ready" signal out to the invoker
|
|
24
|
-
throw err;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const [declarationContent, mappingContent] = buildDeclarationForApexFile(
|
|
28
|
-
prsr,
|
|
29
|
-
comp.content,
|
|
30
|
-
false
|
|
31
|
-
);
|
|
32
|
-
if (declarationContent === undefined) {
|
|
33
|
-
throw new Error("Problem building declaration content");
|
|
34
|
-
}
|
|
35
|
-
if (mappingContent === undefined) {
|
|
36
|
-
throw new Error("Problem building declaration content mappings");
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
...comp,
|
|
41
|
-
declarationContent: declarationContent,
|
|
42
|
-
mapData: mappingContent,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** @type { Record<string, string> } */
|
|
47
|
-
const typeOverrides = {
|
|
48
|
-
string: "string",
|
|
49
|
-
datetime: "Date",
|
|
50
|
-
decimal: "number",
|
|
51
|
-
integer: "number",
|
|
52
|
-
boolean: "boolean",
|
|
53
|
-
id: "string",
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
/** @type { string[] } */
|
|
57
|
-
let localNestedClasses = [];
|
|
58
|
-
/** @type { string? } */
|
|
59
|
-
let outerClassName;
|
|
60
|
-
|
|
61
|
-
// TODO: probably don't want this to be a global
|
|
62
|
-
let builder = new PositionAwareTextBuilder();
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
*
|
|
66
|
-
* @param {Parser} parser
|
|
67
|
-
* @param {string} apexText
|
|
68
|
-
* @param {boolean} isSobject
|
|
69
|
-
* @returns { [string, MapPair[]] | [] }
|
|
70
|
-
*/
|
|
71
|
-
export function buildDeclarationForApexFile(
|
|
72
|
-
parser,
|
|
73
|
-
apexText,
|
|
74
|
-
isSobject = false
|
|
75
|
-
) {
|
|
76
|
-
builder = new PositionAwareTextBuilder();
|
|
77
|
-
try {
|
|
78
|
-
const tree = parser.parse(apexText);
|
|
79
|
-
// step into top-level class, if any
|
|
80
|
-
// if outer-most thing isn't a class the leave
|
|
81
|
-
const classes = tree.rootNode.descendantsOfType("class_declaration");
|
|
82
|
-
|
|
83
|
-
if (classes.length === 0 || !classes[0]) {
|
|
84
|
-
return []; // this isn't a class
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
processClass(classes[0], isSobject);
|
|
88
|
-
localNestedClasses = [];
|
|
89
|
-
outerClassName = null;
|
|
90
|
-
return [builder.build(), builder.getMappings()];
|
|
91
|
-
} catch (error) {
|
|
92
|
-
console.error(error);
|
|
93
|
-
|
|
94
|
-
localNestedClasses = [];
|
|
95
|
-
outerClassName = null;
|
|
96
|
-
return [];
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
*
|
|
102
|
-
* @param {Parser.SyntaxNode} classNode
|
|
103
|
-
* @param {boolean} isSobject
|
|
104
|
-
*/
|
|
105
|
-
function processClass(classNode, isSobject) {
|
|
106
|
-
const classNameNode = classNode.childForFieldName("name");
|
|
107
|
-
if (!classNameNode) {
|
|
108
|
-
throw new Error("Class Name Node not found");
|
|
109
|
-
}
|
|
110
|
-
let className = classNameNode?.text ?? "";
|
|
111
|
-
if (!outerClassName) {
|
|
112
|
-
outerClassName = className;
|
|
113
|
-
}
|
|
114
|
-
let classBody = classNode.childForFieldName("body");
|
|
115
|
-
if (!classBody) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const methodsToProcess = [];
|
|
120
|
-
const fieldsToProcess = [];
|
|
121
|
-
const classesToProcess = [];
|
|
122
|
-
|
|
123
|
-
for (const cNode of classBody.children) {
|
|
124
|
-
switch (cNode.type) {
|
|
125
|
-
case "method_declaration":
|
|
126
|
-
// gather methods because AuraEnabled methods create their own exports
|
|
127
|
-
methodsToProcess.push(cNode);
|
|
128
|
-
break;
|
|
129
|
-
case "field_declaration":
|
|
130
|
-
fieldsToProcess.push(cNode);
|
|
131
|
-
break;
|
|
132
|
-
case "class_declaration":
|
|
133
|
-
classesToProcess.push(cNode);
|
|
134
|
-
const innerNameNode = cNode.childForFieldName("name");
|
|
135
|
-
if (innerNameNode) {
|
|
136
|
-
// queue up nested class names so type resolution can use them
|
|
137
|
-
localNestedClasses.push(innerNameNode.text);
|
|
138
|
-
}
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
if (fieldsToProcess.length > 0) {
|
|
143
|
-
builder.addText("declare interface ");
|
|
144
|
-
builder.addText(
|
|
145
|
-
className,
|
|
146
|
-
classNameNode.startIndex,
|
|
147
|
-
classNameNode.endIndex
|
|
148
|
-
);
|
|
149
|
-
builder.addText(" {\n");
|
|
150
|
-
for (let fNode of fieldsToProcess) {
|
|
151
|
-
transformFieldDeclaration(fNode, isSobject);
|
|
152
|
-
}
|
|
153
|
-
builder.addText("}\n");
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (classesToProcess.length > 0) {
|
|
157
|
-
builder.addText("declare namespace ");
|
|
158
|
-
builder.addText(
|
|
159
|
-
className,
|
|
160
|
-
classNameNode.startIndex,
|
|
161
|
-
classNameNode.endIndex
|
|
162
|
-
);
|
|
163
|
-
builder.addText(" {\n");
|
|
164
|
-
for (const cNode of classesToProcess) {
|
|
165
|
-
processClass(cNode, isSobject);
|
|
166
|
-
// TODO: somehow queue up local classes for type resolution
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
builder.addText("}\n");
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
for (const mNode of methodsToProcess) {
|
|
173
|
-
transformMethodDeclaration(classNameNode, mNode);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
*
|
|
179
|
-
* @param {Parser.SyntaxNode} classNameNode
|
|
180
|
-
* @param {Parser.SyntaxNode} methodNode
|
|
181
|
-
*/
|
|
182
|
-
function transformMethodDeclaration(classNameNode, methodNode) {
|
|
183
|
-
const methodNameNode = methodNode.childForFieldName("name");
|
|
184
|
-
if (!methodNameNode) {
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
const methodName = methodNameNode.text;
|
|
188
|
-
const returnType = methodNode.childForFieldName("type");
|
|
189
|
-
if (!returnType) {
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
const parameters = getMethodParameters(methodNode);
|
|
193
|
-
|
|
194
|
-
const auraEnabledNode = getAuraEnabledAnnotation(methodNode);
|
|
195
|
-
if (!auraEnabledNode) {
|
|
196
|
-
// method doesn't hold the AuraEnabled Annotation
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
const isCacheableEnabled = getAuraEnabledIsCacheable(auraEnabledNode);
|
|
200
|
-
const isContinuation = getAuraEnabledIsContinuation(auraEnabledNode);
|
|
201
|
-
|
|
202
|
-
// TODO: continuation return type is actually the return type of the `continuationMethod` referenced in the Continuation object
|
|
203
|
-
declarationString(
|
|
204
|
-
classNameNode,
|
|
205
|
-
methodNameNode,
|
|
206
|
-
getType(returnType),
|
|
207
|
-
parameters,
|
|
208
|
-
isCacheableEnabled,
|
|
209
|
-
isContinuation
|
|
210
|
-
);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
*
|
|
215
|
-
* @param {Parser.SyntaxNode} node
|
|
216
|
-
* @param {boolean} isSobject
|
|
217
|
-
*/
|
|
218
|
-
function transformFieldDeclaration(node, isSobject) {
|
|
219
|
-
/** @type {string[]} */
|
|
220
|
-
let deprecatedReasons = [];
|
|
221
|
-
const modifiers = node.descendantsOfType("modifiers");
|
|
222
|
-
|
|
223
|
-
if (modifiers.length === 0 || !modifiers[0]) {
|
|
224
|
-
deprecatedReasons.push("public or global");
|
|
225
|
-
} else {
|
|
226
|
-
// initialize so the generated SObjects don't flag missing AuraEnabled
|
|
227
|
-
let isAuraEnabled = isSobject;
|
|
228
|
-
for (const aNode of modifiers[0].descendantsOfType("annotation")) {
|
|
229
|
-
const aNameNode = aNode.childForFieldName("name");
|
|
230
|
-
if (aNameNode && aNameNode.text.toLowerCase() === "auraenabled") {
|
|
231
|
-
isAuraEnabled = true;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
if (!isAuraEnabled) {
|
|
235
|
-
deprecatedReasons.push("@AuraEnabled");
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
let isAtLeastPublic = false;
|
|
239
|
-
for (const mNode of modifiers[0].descendantsOfType("modifier")) {
|
|
240
|
-
switch (mNode.text.toLowerCase()) {
|
|
241
|
-
case "public":
|
|
242
|
-
case "global":
|
|
243
|
-
isAtLeastPublic = true;
|
|
244
|
-
break;
|
|
245
|
-
case "static":
|
|
246
|
-
deprecatedReasons.push("non-static");
|
|
247
|
-
break;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
if (!isAtLeastPublic) {
|
|
251
|
-
deprecatedReasons.push("public or global");
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* determine if AuraEnabled & public or global & not static
|
|
256
|
-
* otherwise mark as deprecated with note (dynamic based on missing access component)
|
|
257
|
-
* {property}: {getType({type})}?;
|
|
258
|
-
*/
|
|
259
|
-
if (deprecatedReasons.length > 0) {
|
|
260
|
-
builder.addText(
|
|
261
|
-
` /** @deprecated not exposed; property must be ${deprecatedReasons.join(
|
|
262
|
-
", "
|
|
263
|
-
)} */\n`
|
|
264
|
-
);
|
|
265
|
-
}
|
|
266
|
-
const nameNode = node
|
|
267
|
-
.childForFieldName("declarator")
|
|
268
|
-
?.childForFieldName("name");
|
|
269
|
-
builder.addText(" ");
|
|
270
|
-
if (!nameNode) {
|
|
271
|
-
throw new Error("Field doesn't have a name");
|
|
272
|
-
}
|
|
273
|
-
builder.addText(
|
|
274
|
-
`${nameNode?.text ?? ""}`,
|
|
275
|
-
nameNode.startIndex,
|
|
276
|
-
nameNode.endIndex
|
|
277
|
-
);
|
|
278
|
-
builder.addText("?: ");
|
|
279
|
-
const typeNode = node.childForFieldName("type");
|
|
280
|
-
if (!typeNode) {
|
|
281
|
-
throw new Error("Type node not found");
|
|
282
|
-
}
|
|
283
|
-
const typeText = getType(typeNode);
|
|
284
|
-
builder.addText(typeText, typeNode.startIndex, typeNode.endIndex);
|
|
285
|
-
builder.addText(";\n");
|
|
286
|
-
const moreText = `;\n`;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
*
|
|
291
|
-
* @param {Parser.SyntaxNode} node
|
|
292
|
-
* @returns {boolean}
|
|
293
|
-
*/
|
|
294
|
-
function getAuraEnabledIsCacheable(node) {
|
|
295
|
-
const args = node.childForFieldName("arguments");
|
|
296
|
-
if (args) {
|
|
297
|
-
for (const a of args.descendantsOfType("annotation_key_value")) {
|
|
298
|
-
const k = a.childForFieldName("key");
|
|
299
|
-
const v = a.childForFieldName("value");
|
|
300
|
-
if (
|
|
301
|
-
k &&
|
|
302
|
-
v &&
|
|
303
|
-
k.text.toLowerCase() === "cacheable" &&
|
|
304
|
-
v.text.toLowerCase() === "true"
|
|
305
|
-
) {
|
|
306
|
-
return true;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
return false;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
*
|
|
315
|
-
* @param {Parser.SyntaxNode} node
|
|
316
|
-
* @returns {boolean}
|
|
317
|
-
*/
|
|
318
|
-
function getAuraEnabledIsContinuation(node) {
|
|
319
|
-
const args = node.childForFieldName("arguments");
|
|
320
|
-
if (args) {
|
|
321
|
-
for (const a of args.descendantsOfType("annotation_key_value")) {
|
|
322
|
-
const k = a.childForFieldName("key");
|
|
323
|
-
const v = a.childForFieldName("value");
|
|
324
|
-
if (
|
|
325
|
-
k &&
|
|
326
|
-
v &&
|
|
327
|
-
k.text.toLowerCase() === "continuation" &&
|
|
328
|
-
v.text.toLowerCase() === "true"
|
|
329
|
-
) {
|
|
330
|
-
return true;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
return false;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
*
|
|
339
|
-
* @param {Parser.SyntaxNode} node
|
|
340
|
-
* @returns {Parser.SyntaxNode | null}
|
|
341
|
-
*/
|
|
342
|
-
function getAuraEnabledAnnotation(node) {
|
|
343
|
-
for (const m of node.descendantsOfType("modifiers")) {
|
|
344
|
-
for (const a of m.descendantsOfType("annotation")) {
|
|
345
|
-
if (a.childForFieldName("name")?.text.toLowerCase() === "auraenabled") {
|
|
346
|
-
return a;
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
return null;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
/**
|
|
354
|
-
*
|
|
355
|
-
* @param {Parser.SyntaxNode} node
|
|
356
|
-
* @returns {Map<string, string>}
|
|
357
|
-
*/
|
|
358
|
-
function getMethodParameters(node) {
|
|
359
|
-
const params = new Map();
|
|
360
|
-
const parameters = node.childForFieldName("parameters");
|
|
361
|
-
if (!parameters) {
|
|
362
|
-
return params;
|
|
363
|
-
}
|
|
364
|
-
for (const p of parameters.namedChildren) {
|
|
365
|
-
params.set(
|
|
366
|
-
p.childForFieldName("name")?.text,
|
|
367
|
-
getType(p.childForFieldName("type"))
|
|
368
|
-
);
|
|
369
|
-
}
|
|
370
|
-
return params;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
*
|
|
375
|
-
* @param {Parser.SyntaxNode} classNameNode
|
|
376
|
-
* @param {Parser.SyntaxNode} methodNameNode
|
|
377
|
-
* @param {string} returnType
|
|
378
|
-
* @param {Map<string, string>} params
|
|
379
|
-
* @param {boolean} isCacheable
|
|
380
|
-
* @param {boolean} isContinuation
|
|
381
|
-
*/
|
|
382
|
-
function declarationString(
|
|
383
|
-
classNameNode,
|
|
384
|
-
methodNameNode,
|
|
385
|
-
returnType,
|
|
386
|
-
params,
|
|
387
|
-
isCacheable,
|
|
388
|
-
isContinuation
|
|
389
|
-
) {
|
|
390
|
-
builder.addText("declare module ");
|
|
391
|
-
// if method has Containuation
|
|
392
|
-
builder.addText(
|
|
393
|
-
`"@salesforce/apex${isContinuation ? "Continuation" : ""}/${classNameNode.text}.${methodNameNode.text}"`,
|
|
394
|
-
methodNameNode.startIndex,
|
|
395
|
-
methodNameNode.endIndex
|
|
396
|
-
);
|
|
397
|
-
builder.addText(` {
|
|
398
|
-
const `);
|
|
399
|
-
builder.addText(
|
|
400
|
-
methodNameNode.text,
|
|
401
|
-
methodNameNode.startIndex,
|
|
402
|
-
methodNameNode.endIndex
|
|
403
|
-
);
|
|
404
|
-
builder.addText(`: {
|
|
405
|
-
(${
|
|
406
|
-
params.size === 0
|
|
407
|
-
? ""
|
|
408
|
-
: `param: { ${Array.from(params.entries())
|
|
409
|
-
.map(([name, type]) => `${name}: ${type}`)
|
|
410
|
-
.join("; ")} }`
|
|
411
|
-
}): Promise<${returnType}>;${
|
|
412
|
-
// Apex can only be wired if it is cacheable
|
|
413
|
-
// the adapter is the WireAdapterConstructor that the @wire decorator consumes
|
|
414
|
-
!isCacheable
|
|
415
|
-
? ""
|
|
416
|
-
: `
|
|
417
|
-
adapter: import("lwc").WireAdapterConstructor<
|
|
418
|
-
${
|
|
419
|
-
params.size === 0
|
|
420
|
-
? "never"
|
|
421
|
-
: `{ ${Array.from(params.entries())
|
|
422
|
-
.map(([name, type]) => `${name}: ${type}`)
|
|
423
|
-
.join("; ")} }`
|
|
424
|
-
},
|
|
425
|
-
{ error?: any; data?: ${returnType}; }
|
|
426
|
-
>;`
|
|
427
|
-
}
|
|
428
|
-
};
|
|
429
|
-
export default ${methodNameNode.text};
|
|
430
|
-
}
|
|
431
|
-
`);
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
/**
|
|
435
|
-
*
|
|
436
|
-
* @param {Parser.SyntaxNode | null} node
|
|
437
|
-
* @returns {string}
|
|
438
|
-
*/
|
|
439
|
-
function getType(node) {
|
|
440
|
-
if (!node) {
|
|
441
|
-
return "";
|
|
442
|
-
}
|
|
443
|
-
// if generic type, see if it is a list or map
|
|
444
|
-
switch (node.type) {
|
|
445
|
-
case "generic_type":
|
|
446
|
-
const genType = getType(node.namedChildren[0]);
|
|
447
|
-
let typeNode = node.namedChildren[1];
|
|
448
|
-
if (!typeNode) {
|
|
449
|
-
return "";
|
|
450
|
-
}
|
|
451
|
-
switch (genType.toLowerCase()) {
|
|
452
|
-
case "list":
|
|
453
|
-
return getType(typeNode.namedChildren[0]) + "[]";
|
|
454
|
-
case "map":
|
|
455
|
-
return `Record<${getType(typeNode.namedChildren[0])}, ${getType(
|
|
456
|
-
typeNode.namedChildren[1]
|
|
457
|
-
)}>`;
|
|
458
|
-
case "set":
|
|
459
|
-
return `Set<${getType(typeNode.namedChildren[0])}>`;
|
|
460
|
-
|
|
461
|
-
default:
|
|
462
|
-
console.error("Unexpected generic type", genType);
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
if (localNestedClasses.includes(node.text)) {
|
|
466
|
-
return `${outerClassName}.${node.text}`;
|
|
467
|
-
}
|
|
468
|
-
return typeOverrides[node.text.toLowerCase()] ?? node.text;
|
|
469
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/** @import { Component, ConvertedComponent } from "../index.mjs" */
|
|
2
|
-
import { parseString } from "xml2js";
|
|
3
|
-
import { PositionAwareTextBuilder } from "../util.mjs";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
* @param {Component} component
|
|
8
|
-
* @returns {ConvertedComponent}
|
|
9
|
-
*/
|
|
10
|
-
export function ContentAsset(component) {
|
|
11
|
-
// generate d.ts
|
|
12
|
-
/** @type {any} */
|
|
13
|
-
let asset;
|
|
14
|
-
parseString(component.content, (error, result) => {
|
|
15
|
-
if (error) {
|
|
16
|
-
throw error;
|
|
17
|
-
}
|
|
18
|
-
asset = result;
|
|
19
|
-
});
|
|
20
|
-
const label = asset.ContentAsset.masterLabel[0];
|
|
21
|
-
const namePosStart =
|
|
22
|
-
component.content.indexOf("<masterLabel>") + "<masterLabel>".length;
|
|
23
|
-
const namePosEnd = namePosStart + label.length;
|
|
24
|
-
|
|
25
|
-
const builder = new PositionAwareTextBuilder();
|
|
26
|
-
|
|
27
|
-
builder.addText(`declare module `);
|
|
28
|
-
builder.addText(
|
|
29
|
-
`"@salesforce/contentAssetUrl/${label}"`,
|
|
30
|
-
namePosStart,
|
|
31
|
-
namePosEnd
|
|
32
|
-
);
|
|
33
|
-
builder.addText(
|
|
34
|
-
` {
|
|
35
|
-
const `
|
|
36
|
-
);
|
|
37
|
-
builder.addText(label, namePosStart, namePosEnd);
|
|
38
|
-
builder.addText(
|
|
39
|
-
`: string;
|
|
40
|
-
export default ${label};
|
|
41
|
-
}`
|
|
42
|
-
);
|
|
43
|
-
return {
|
|
44
|
-
declarationContent: builder.build(),
|
|
45
|
-
mapData: builder.getMappings(),
|
|
46
|
-
...component,
|
|
47
|
-
};
|
|
48
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/** @import { Component, ConvertedComponent } from "../index.mjs" */
|
|
2
|
-
import { parseString } from "xml2js";
|
|
3
|
-
import { PositionAwareTextBuilder } from "../util.mjs";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
* @param {Component} component
|
|
8
|
-
* @returns {ConvertedComponent}
|
|
9
|
-
*/
|
|
10
|
-
export function CustomField(component) {
|
|
11
|
-
// generate d.ts
|
|
12
|
-
/** @type {any} */
|
|
13
|
-
let field;
|
|
14
|
-
parseString(component.content, (error, result) => {
|
|
15
|
-
if (error) {
|
|
16
|
-
throw error;
|
|
17
|
-
}
|
|
18
|
-
field = result;
|
|
19
|
-
});
|
|
20
|
-
const pathParts = component.path.split("/");
|
|
21
|
-
const fieldName = pathParts.pop()?.split(".")[0];
|
|
22
|
-
if (!fieldName) {
|
|
23
|
-
throw new Error("Unable to resolve field name from file path");
|
|
24
|
-
}
|
|
25
|
-
pathParts?.pop(); // discard `fields`
|
|
26
|
-
const objectName = pathParts.pop();
|
|
27
|
-
|
|
28
|
-
const namePosStart =
|
|
29
|
-
component.content.indexOf("<fullName>") + "<fullName>".length;
|
|
30
|
-
const namePosEnd = namePosStart + fieldName.length;
|
|
31
|
-
|
|
32
|
-
const builder = new PositionAwareTextBuilder();
|
|
33
|
-
builder.addText(`declare module `);
|
|
34
|
-
builder.addText(
|
|
35
|
-
`"@salesforce/schema/${objectName}.${fieldName}"`,
|
|
36
|
-
namePosStart,
|
|
37
|
-
namePosEnd
|
|
38
|
-
);
|
|
39
|
-
builder.addText(
|
|
40
|
-
` {
|
|
41
|
-
/**
|
|
42
|
-
* @description ${field.CustomField.inlineHelpText}
|
|
43
|
-
* @description ${field.CustomField.description}
|
|
44
|
-
*/
|
|
45
|
-
const `
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
builder.addText(`${fieldName}`, namePosStart, namePosEnd);
|
|
49
|
-
|
|
50
|
-
builder.addText(
|
|
51
|
-
`: {
|
|
52
|
-
fieldApiName: '${fieldName}';
|
|
53
|
-
objectApiName: '${objectName}';
|
|
54
|
-
}
|
|
55
|
-
export default ${fieldName};
|
|
56
|
-
}`
|
|
57
|
-
);
|
|
58
|
-
return {
|
|
59
|
-
declarationContent: builder.build(),
|
|
60
|
-
mapData: builder.getMappings(),
|
|
61
|
-
...component,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/** @import { Component, ConvertedComponent } from "../index.mjs" */
|
|
2
|
-
import { parseString } from "xml2js";
|
|
3
|
-
import { PositionAwareTextBuilder } from "../util.mjs";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
* @param {Component} component
|
|
8
|
-
* @returns {ConvertedComponent}
|
|
9
|
-
*/
|
|
10
|
-
export function CustomLabel(component) {
|
|
11
|
-
// generate d.ts
|
|
12
|
-
/** @type {any} */
|
|
13
|
-
let labels;
|
|
14
|
-
parseString(component.content, (error, result) => {
|
|
15
|
-
if (error) {
|
|
16
|
-
throw error;
|
|
17
|
-
}
|
|
18
|
-
labels = result;
|
|
19
|
-
});
|
|
20
|
-
const builder = new PositionAwareTextBuilder();
|
|
21
|
-
getDtsFromLabel(builder, component.content, labels.CustomLabel);
|
|
22
|
-
return {
|
|
23
|
-
declarationContent: builder.build(),
|
|
24
|
-
mapData: builder.getMappings(),
|
|
25
|
-
...component,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
*
|
|
31
|
-
* @param {PositionAwareTextBuilder} builder
|
|
32
|
-
* @param {string} content
|
|
33
|
-
* @param {any} label
|
|
34
|
-
*/
|
|
35
|
-
export function getDtsFromLabel(builder, content, label) {
|
|
36
|
-
const labelName = label.fullName[0];
|
|
37
|
-
const namePosStart =
|
|
38
|
-
content.indexOf(`<fullName>${labelName}`) + `<fullName>`.length;
|
|
39
|
-
const namePosEnd = namePosStart + labelName.length;
|
|
40
|
-
|
|
41
|
-
builder.addText(`declare module `);
|
|
42
|
-
builder.addText(
|
|
43
|
-
`"@salesforce/label/c.${labelName}"`,
|
|
44
|
-
namePosStart,
|
|
45
|
-
namePosEnd
|
|
46
|
-
);
|
|
47
|
-
builder.addText(
|
|
48
|
-
` {
|
|
49
|
-
/**
|
|
50
|
-
* @description ${label.shortDescription}
|
|
51
|
-
*/
|
|
52
|
-
const `
|
|
53
|
-
);
|
|
54
|
-
builder.addText(`lbl${label.fullName}`, namePosStart, namePosEnd);
|
|
55
|
-
builder.addText(
|
|
56
|
-
` = '${label.value}';
|
|
57
|
-
export default lbl${label.fullName};
|
|
58
|
-
}
|
|
59
|
-
`
|
|
60
|
-
);
|
|
61
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/** @import { Component, ConvertedComponent } from "../index.mjs" */
|
|
2
|
-
import { parseString } from "xml2js";
|
|
3
|
-
import { PositionAwareTextBuilder } from "../util.mjs";
|
|
4
|
-
import { getDtsFromLabel } from "./custom-label.mjs";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
*
|
|
8
|
-
* @param {Component} component
|
|
9
|
-
* @returns {ConvertedComponent}
|
|
10
|
-
*/
|
|
11
|
-
export function CustomLabels(component) {
|
|
12
|
-
// generate d.ts
|
|
13
|
-
/** @type {any} */
|
|
14
|
-
let labels;
|
|
15
|
-
parseString(component.content, (error, result) => {
|
|
16
|
-
if (error) {
|
|
17
|
-
throw error;
|
|
18
|
-
}
|
|
19
|
-
labels = result;
|
|
20
|
-
});
|
|
21
|
-
if (!Array.isArray(labels.CustomLabels.labels)) {
|
|
22
|
-
labels.CustomLabels.labels = [labels.CustomLabels.labels];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const builder = new PositionAwareTextBuilder();
|
|
26
|
-
for (let label of labels.CustomLabels.labels) {
|
|
27
|
-
getDtsFromLabel(builder, component.content, label);
|
|
28
|
-
}
|
|
29
|
-
return {
|
|
30
|
-
declarationContent: builder.build(),
|
|
31
|
-
mapData: builder.getMappings(),
|
|
32
|
-
...component,
|
|
33
|
-
};
|
|
34
|
-
}
|