@komaci/common-shared 240.1.3 → 242.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/adaptersMapping.d.ts +3 -0
- package/build/adaptersMapping.js +29 -0
- package/build/allowlistAdapters.d.ts +6 -0
- package/build/allowlistAdapters.js +10 -0
- package/build/allowlistNamespaces.d.ts +6 -0
- package/build/allowlistNamespaces.js +21 -1
- package/build/index.d.ts +3 -0
- package/build/index.js +8 -1
- package/build/internal-namespaces.json +31 -0
- package/build/komaci-mapping.json +288 -0
- package/build/komaciDocumentIntrospection.d.ts +45 -20
- package/build/komaciDocumentIntrospection.js +224 -121
- package/build/moduleMetadata.d.ts +160 -0
- package/build/moduleMetadata.js +591 -0
- package/build/types.d.ts +203 -81
- package/build/types.js +54 -3
- package/build/utils.d.ts +27 -26
- package/build/utils.js +143 -203
- package/build/wires.d.ts +12 -0
- package/build/wires.js +56 -0
- package/package.json +4 -3
package/build/utils.js
CHANGED
|
@@ -1,31 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.isDeclaredInAst = exports.isExpressionThisOrAlias = exports.getThisAliasDeclaredInGetter = exports.isPropertyNodeUsed = exports.isGetterNodeUsed = exports.isPropertyUsed = exports.getClassMethodName = exports.getVariablesDeclaredInGetter = exports.isExternalModule = exports.getAstContextObject = exports.getAllClassMethods = exports.getAllModuleVaraibles = exports.getAllModuleFunctions = exports.
|
|
23
|
-
const t = __importStar(require("@babel/types"));
|
|
3
|
+
exports.addPropertyFunction = exports.updateKomaciDocumentWithValidTemplatedStrings = exports.updateKomaciDocumentWithValidGetters = exports.isDeclaredInAst = exports.isExpressionThisOrAlias = exports.getThisAliasDeclaredInGetter = exports.isPropertyNodeUsed = exports.isGetterNodeUsed = exports.isPropertyUsed = exports.getClassMethodName = exports.getVariablesDeclaredInGetter = exports.isExternalModule = exports.getAstContextObject = exports.getAllClassMethods = exports.getAllModuleVaraibles = exports.getAllModuleFunctions = exports.getFromIdentifierOrStringLiteral = exports.collectImportUsage = exports.getMemberVarsFromGetter = exports.implicitConsumptionMetadata = exports.getPropertyMetadataFromAst = exports.TEMPLATED_STRING_FUNCTION = exports.GETTER_FUNCTION = exports.ONE_NS = exports.FORCE_NS = exports.LIGHTNING_NS = void 0;
|
|
24
4
|
const core_1 = require("@babel/core");
|
|
25
|
-
const allowlistNamespaces_1 = require("./allowlistNamespaces");
|
|
26
5
|
exports.LIGHTNING_NS = 'lightning';
|
|
27
6
|
exports.FORCE_NS = 'force';
|
|
28
7
|
exports.ONE_NS = 'one';
|
|
8
|
+
exports.GETTER_FUNCTION = 'GetterFunction';
|
|
9
|
+
exports.TEMPLATED_STRING_FUNCTION = 'TemplatedStringFunction';
|
|
29
10
|
/**
|
|
30
11
|
* collect node paths for different pieces of a given class so we can more effectively traverse them in the future
|
|
31
12
|
*
|
|
@@ -71,80 +52,6 @@ function getPropertyMetadataFromAst(ast) {
|
|
|
71
52
|
return nodes;
|
|
72
53
|
}
|
|
73
54
|
exports.getPropertyMetadataFromAst = getPropertyMetadataFromAst;
|
|
74
|
-
/**
|
|
75
|
-
* @param node
|
|
76
|
-
* @returns true if node is a ClassBody
|
|
77
|
-
*/
|
|
78
|
-
function isNodeClassBody(node) {
|
|
79
|
-
return node?.type === 'ClassBody';
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Given the AST of an entire JS source file, this method looks for class member properties.
|
|
83
|
-
* If there is no default export in the AST, no class properties will be returned (empty array is returned).
|
|
84
|
-
* @param astRoot AST representing an entire Program, as a @babel/types File object
|
|
85
|
-
* @returns Array of NodePath<ClassProperty> representing the @babel NodePaths for all class member
|
|
86
|
-
* properties, if any exist. Otherwise, returns an empty array.
|
|
87
|
-
*/
|
|
88
|
-
function getClassProperties(astRoot) {
|
|
89
|
-
let classProperties = [];
|
|
90
|
-
const prog = astRoot.program;
|
|
91
|
-
const body = prog.body;
|
|
92
|
-
const exportDefaultDecl = body.filter((child) => child.type === 'ExportDefaultDeclaration');
|
|
93
|
-
if (exportDefaultDecl.length > 0) {
|
|
94
|
-
const classDecl = exportDefaultDecl[0]
|
|
95
|
-
.declaration; // there can only be one export default declaration
|
|
96
|
-
if (isNodeClassBody(classDecl.body)) {
|
|
97
|
-
const classBody = classDecl.body;
|
|
98
|
-
classProperties = classBody.body.filter((classChild) => classChild.type === 'ClassProperty' ||
|
|
99
|
-
(classChild.type === 'ClassMethod' && classChild.kind === 'get'));
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return classProperties;
|
|
103
|
-
}
|
|
104
|
-
exports.getClassProperties = getClassProperties;
|
|
105
|
-
/**
|
|
106
|
-
* Utility method that takes in an @babel/types ClassProperty array, and returns an array of ClassPropertyInfo
|
|
107
|
-
* objects containing information about each ClassProperty from the input array.
|
|
108
|
-
* @param classProperties
|
|
109
|
-
* @returns Array of ClassPropertyInfo, where each element corresponds to the input ClassProperty array.
|
|
110
|
-
*/
|
|
111
|
-
function getClassPropertyInfos(classProperties = []) {
|
|
112
|
-
const classPropInfos = [];
|
|
113
|
-
classProperties
|
|
114
|
-
.filter((classProp) => t.isIdentifier(classProp.key))
|
|
115
|
-
.forEach((classProp) => {
|
|
116
|
-
const id = classProp.key;
|
|
117
|
-
const decorators = classProp.decorators;
|
|
118
|
-
let decoratorType = undefined;
|
|
119
|
-
if (decorators) {
|
|
120
|
-
// non-annotated class properties won't have a decorator
|
|
121
|
-
const expr = decorators[0].expression;
|
|
122
|
-
if (expr.type === 'CallExpression') {
|
|
123
|
-
const callee = expr.callee;
|
|
124
|
-
decoratorType = callee.name;
|
|
125
|
-
}
|
|
126
|
-
else if (expr.type === 'Identifier') {
|
|
127
|
-
decoratorType = expr.name;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
const classPropInfo = {
|
|
131
|
-
classProp: classProp,
|
|
132
|
-
classPropId: id.name,
|
|
133
|
-
isDecorated: decorators !== undefined &&
|
|
134
|
-
decorators !== null &&
|
|
135
|
-
decorators.length > 0,
|
|
136
|
-
hasInitialValue: t.isClassProperty(classProp)
|
|
137
|
-
? classProp.value !== null
|
|
138
|
-
: false,
|
|
139
|
-
};
|
|
140
|
-
if (classPropInfo.isDecorated) {
|
|
141
|
-
classPropInfo.decoratorType = decoratorType;
|
|
142
|
-
}
|
|
143
|
-
classPropInfos.push(classPropInfo);
|
|
144
|
-
});
|
|
145
|
-
return classPropInfos;
|
|
146
|
-
}
|
|
147
|
-
exports.getClassPropertyInfos = getClassPropertyInfos;
|
|
148
55
|
/**
|
|
149
56
|
* Given a valid functional node (tempalte string or getter function), collect information that we may not have been able to collect via KomaciDocument
|
|
150
57
|
* and return a list of class member variables that are properly used in the method body.
|
|
@@ -159,8 +66,7 @@ exports.getClassPropertyInfos = getClassPropertyInfos;
|
|
|
159
66
|
* @returns ImplicitConsumption, which contains an array representing the properly-used member variables.
|
|
160
67
|
* Returns ImplicitConsumption with an empty array if none were found.
|
|
161
68
|
*/
|
|
162
|
-
function implicitConsumptionMetadata(node,
|
|
163
|
-
moduleLevelConsumption) {
|
|
69
|
+
function implicitConsumptionMetadata(node, adgIndex, moduleMetadata) {
|
|
164
70
|
const identifiers = new Set();
|
|
165
71
|
const Visitors = {
|
|
166
72
|
// visitor for each type
|
|
@@ -168,7 +74,9 @@ moduleLevelConsumption) {
|
|
|
168
74
|
getMemberVarsFromGetter(path, identifiers);
|
|
169
75
|
},
|
|
170
76
|
Identifier(path) {
|
|
171
|
-
collectImportUsage(path,
|
|
77
|
+
collectImportUsage(path, moduleMetadata,
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
79
|
+
moduleMetadata.adgs.get(adgIndex).properties);
|
|
172
80
|
},
|
|
173
81
|
};
|
|
174
82
|
node.traverse(Visitors);
|
|
@@ -202,61 +110,32 @@ exports.getMemberVarsFromGetter = getMemberVarsFromGetter;
|
|
|
202
110
|
* @param consumedImports The map to add info to about this identifier, whether it is an import that is being used
|
|
203
111
|
* in the getter, or if it is assigned an import being used in the getter.
|
|
204
112
|
*/
|
|
205
|
-
function collectImportUsage(path,
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}
|
|
216
|
-
// find indirect import references (where import was assigned to a class member variable)
|
|
217
|
-
if (!importInfo) {
|
|
218
|
-
const importSpecifierNames = new Set(Array.from(importDeclarations.keys()));
|
|
219
|
-
classPropInfos.forEach((classPropInfo) => {
|
|
220
|
-
// check for type NodePath<t.ClassProperty> vs. t.ClassProperty. The former has a .node property
|
|
221
|
-
const isNodePath = classPropInfo.classProp.node !== undefined;
|
|
222
|
-
const classProp = isNodePath
|
|
223
|
-
? classPropInfo.classProp.node
|
|
224
|
-
: classPropInfo.classProp;
|
|
225
|
-
if (classProp.key.type === 'Identifier' &&
|
|
226
|
-
classProp.key.name === name &&
|
|
227
|
-
classProp.value?.type === 'Identifier' &&
|
|
228
|
-
importSpecifierNames.has(classProp.value.name)) {
|
|
229
|
-
importInfo = importDeclarations.get(classProp.value.name);
|
|
113
|
+
function collectImportUsage(path, moduleMetadata, properties) {
|
|
114
|
+
if (path.parent.type === 'MemberExpression' &&
|
|
115
|
+
path.parent.object.type === 'ThisExpression' &&
|
|
116
|
+
path.parent.property.type === 'Identifier') {
|
|
117
|
+
const identifier = path.parent.property;
|
|
118
|
+
const referencedProperty = properties.get(identifier.name);
|
|
119
|
+
if (referencedProperty && referencedProperty.inital?.type === 'ImportReference') {
|
|
120
|
+
const importMetadata = moduleMetadata.importsByName.get(moduleMetadata.importIndexReference.get(referencedProperty.inital.value) || '');
|
|
121
|
+
if (importMetadata) {
|
|
122
|
+
importMetadata.usedInPriming = true;
|
|
230
123
|
}
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
if (importInfo) {
|
|
234
|
-
if (importInfo.isDefault) {
|
|
235
|
-
nameToReference = 'default';
|
|
236
|
-
}
|
|
237
|
-
else if (importInfo.isNamespaceSpecifier) {
|
|
238
|
-
// this case needs to be handled separately as it always has an alias
|
|
239
|
-
nameToReference = '*';
|
|
240
124
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
let
|
|
245
|
-
|
|
246
|
-
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
const name = path.node.name;
|
|
128
|
+
let importInfo = moduleMetadata.importsByName.get(name); // finds direct references of import specifiers in the getter
|
|
129
|
+
// i.e. find `MyID1.CONST` in the getter, where `MyID1` is an import specifier
|
|
130
|
+
if (!importInfo &&
|
|
131
|
+
path.parent.type === 'MemberExpression' &&
|
|
132
|
+
path.parent.object.type === 'Identifier' &&
|
|
133
|
+
path.parent.object === path.node) {
|
|
134
|
+
importInfo = moduleMetadata.importsByName.get(path.parent.object.name);
|
|
247
135
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
names.add(nameToReference);
|
|
251
|
-
fullImportContext = {
|
|
252
|
-
names,
|
|
253
|
-
resourceName: importInfo.namespace,
|
|
254
|
-
isNamespaceSpecifier: importInfo.isNamespaceSpecifier,
|
|
255
|
-
isDefaultSpecifier: importInfo.isDefault,
|
|
256
|
-
isSupported: importInfo.isSupported,
|
|
257
|
-
};
|
|
136
|
+
if (importInfo) {
|
|
137
|
+
importInfo.usedInPriming = true;
|
|
258
138
|
}
|
|
259
|
-
consumedImports.set(importInfo.namespace, fullImportContext);
|
|
260
139
|
}
|
|
261
140
|
}
|
|
262
141
|
exports.collectImportUsage = collectImportUsage;
|
|
@@ -270,53 +149,6 @@ function getFromIdentifierOrStringLiteral(node) {
|
|
|
270
149
|
return node.type === 'Identifier' ? node.name : node.value;
|
|
271
150
|
}
|
|
272
151
|
exports.getFromIdentifierOrStringLiteral = getFromIdentifierOrStringLiteral;
|
|
273
|
-
/**
|
|
274
|
-
* Function for getting an array of supported namesapce references.
|
|
275
|
-
* @param astRoot the root of the ast
|
|
276
|
-
* @returns an Array of supported namespace references.
|
|
277
|
-
*/
|
|
278
|
-
function getAllImportReferences(astRoot) {
|
|
279
|
-
const importReferences = new Map();
|
|
280
|
-
const program = astRoot.program;
|
|
281
|
-
const body = program.body;
|
|
282
|
-
const importDeclarations = body.filter((currentDec) => currentDec.type === 'ImportDeclaration');
|
|
283
|
-
importDeclarations.forEach((currentDec) => {
|
|
284
|
-
const isValid = isValidNamespace(currentDec.source.value) &&
|
|
285
|
-
(0, allowlistNamespaces_1.isLibraryValid)(currentDec.source.value);
|
|
286
|
-
const specifiers = currentDec.specifiers;
|
|
287
|
-
specifiers.forEach((currentSpecifier) => {
|
|
288
|
-
let importName = undefined;
|
|
289
|
-
if (currentSpecifier.type === 'ImportSpecifier') {
|
|
290
|
-
importName = currentSpecifier.local // local is alias (the most specific name)
|
|
291
|
-
? getFromIdentifierOrStringLiteral(currentSpecifier.local)
|
|
292
|
-
: getFromIdentifierOrStringLiteral(currentSpecifier.imported);
|
|
293
|
-
}
|
|
294
|
-
else {
|
|
295
|
-
importName = getFromIdentifierOrStringLiteral(currentSpecifier.local);
|
|
296
|
-
}
|
|
297
|
-
importReferences.set(importName, {
|
|
298
|
-
namespace: currentDec.source.value,
|
|
299
|
-
identifierName: importName,
|
|
300
|
-
isSupported: isValid,
|
|
301
|
-
isDefault: currentSpecifier.type === 'ImportDefaultSpecifier',
|
|
302
|
-
isNamespaceSpecifier: currentSpecifier.type === 'ImportNamespaceSpecifier',
|
|
303
|
-
trueName: currentSpecifier.type === 'ImportSpecifier'
|
|
304
|
-
? getFromIdentifierOrStringLiteral(currentSpecifier.imported)
|
|
305
|
-
: undefined,
|
|
306
|
-
});
|
|
307
|
-
});
|
|
308
|
-
});
|
|
309
|
-
return importReferences;
|
|
310
|
-
}
|
|
311
|
-
exports.getAllImportReferences = getAllImportReferences;
|
|
312
|
-
/**
|
|
313
|
-
* Helper function to validate if a namespace is in our allowed namespace list.
|
|
314
|
-
* @param namespace the namespace to validate.
|
|
315
|
-
* @returns true of the namespace is supported, false if unsupported.
|
|
316
|
-
*/
|
|
317
|
-
function isValidNamespace(importPath) {
|
|
318
|
-
return (0, allowlistNamespaces_1.isNamespaceInternal)((0, allowlistNamespaces_1.getNamespaceFromImport)(importPath));
|
|
319
|
-
}
|
|
320
152
|
/**
|
|
321
153
|
* Function to get an array of function names that are defined at the module level.
|
|
322
154
|
* @returns an array of function names that are defined at the module level.
|
|
@@ -414,12 +246,9 @@ exports.getAllClassMethods = getAllClassMethods;
|
|
|
414
246
|
* @returns a context object containing meta data about the ast.
|
|
415
247
|
*/
|
|
416
248
|
function getAstContextObject(ast) {
|
|
417
|
-
const props = getClassProperties(ast);
|
|
418
249
|
const context = {
|
|
419
|
-
importDeclarations: getAllImportReferences(ast),
|
|
420
250
|
moduleFunctions: getAllModuleFunctions(ast),
|
|
421
251
|
moduleVariables: getAllModuleVaraibles(ast),
|
|
422
|
-
classProperties: getClassPropertyInfos(props),
|
|
423
252
|
classFunctions: getAllClassMethods(ast),
|
|
424
253
|
};
|
|
425
254
|
return context;
|
|
@@ -543,12 +372,123 @@ exports.isExpressionThisOrAlias = isExpressionThisOrAlias;
|
|
|
543
372
|
* @param declaredGetterVars a collection of variables declared within the getter
|
|
544
373
|
* @param id the id of the member we are referencing.
|
|
545
374
|
*/
|
|
546
|
-
function isDeclaredInAst(astContext, declaredGetterVars, id) {
|
|
547
|
-
const {
|
|
548
|
-
return (classProperties.
|
|
375
|
+
function isDeclaredInAst(astContext, importDeclarations, classProperties, declaredGetterVars, id) {
|
|
376
|
+
const { moduleVariables } = astContext;
|
|
377
|
+
return (classProperties.has(id) ||
|
|
549
378
|
importDeclarations.has(id) ||
|
|
550
379
|
moduleVariables.find((varId) => varId === id) !== undefined ||
|
|
551
380
|
(declaredGetterVars || []).find((varId) => varId === id) !== undefined);
|
|
552
381
|
}
|
|
553
382
|
exports.isDeclaredInAst = isDeclaredInAst;
|
|
383
|
+
/**
|
|
384
|
+
* Function to update the Komaci Document with validated getter information. This function will update the functions array in the
|
|
385
|
+
* export default adg along with the property references in the property array.
|
|
386
|
+
* @param komaciScriptDoc the komaci document
|
|
387
|
+
* @param validGetterContext a collection
|
|
388
|
+
*/
|
|
389
|
+
function updateKomaciDocumentWithValidGetters(komaciScriptDoc, validGetterContext) {
|
|
390
|
+
if (komaciScriptDoc.exports) {
|
|
391
|
+
//get the exort mapping for the export default
|
|
392
|
+
const defaultExportMapping = komaciScriptDoc.exports['default'];
|
|
393
|
+
if (defaultExportMapping && defaultExportMapping.type === 'AdgReference') {
|
|
394
|
+
const defaultExportAdg = komaciScriptDoc.adgs?.[defaultExportMapping.value];
|
|
395
|
+
//foreach getter in the context.
|
|
396
|
+
validGetterContext.forEach((getter) => {
|
|
397
|
+
//Get the name of the getter.
|
|
398
|
+
const getterName = getter.getter.node.key.name;
|
|
399
|
+
const inputArr = {
|
|
400
|
+
type: 'ArrayValue',
|
|
401
|
+
value: [],
|
|
402
|
+
};
|
|
403
|
+
getter.memberUsage.forEach((member) => {
|
|
404
|
+
const primVal = {
|
|
405
|
+
type: 'PrimitiveValue',
|
|
406
|
+
value: member,
|
|
407
|
+
};
|
|
408
|
+
inputArr.value.push(primVal);
|
|
409
|
+
});
|
|
410
|
+
//create a new functionType obj with getter information.
|
|
411
|
+
const validGetterFunction = {
|
|
412
|
+
type: exports.GETTER_FUNCTION,
|
|
413
|
+
reference: { type: 'InternalReference', value: getter.generatedName },
|
|
414
|
+
input: [inputArr],
|
|
415
|
+
location: undefined,
|
|
416
|
+
};
|
|
417
|
+
//if we have an adg make changes to it.
|
|
418
|
+
if (defaultExportAdg) {
|
|
419
|
+
getter.f_index = addPropertyFunction(defaultExportAdg, getterName, validGetterFunction);
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
exports.updateKomaciDocumentWithValidGetters = updateKomaciDocumentWithValidGetters;
|
|
426
|
+
/**
|
|
427
|
+
* Function to update the Komaci Document with validated template information. This function will update the functions array in the
|
|
428
|
+
* export default adg along with the property references in the property array.
|
|
429
|
+
* @param komaciScriptDoc the komaci document
|
|
430
|
+
* @param ValidTemplateContext details about the templates we've deemed to be valid
|
|
431
|
+
*/
|
|
432
|
+
function updateKomaciDocumentWithValidTemplatedStrings(komaciScriptDoc, templateStrings) {
|
|
433
|
+
if (komaciScriptDoc.exports?.default?.type === 'AdgReference') {
|
|
434
|
+
const adg = komaciScriptDoc.adgs?.[komaciScriptDoc.exports.default.value];
|
|
435
|
+
if (adg) {
|
|
436
|
+
templateStrings.forEach((template) => {
|
|
437
|
+
const propertyName = template.template.node.key.name;
|
|
438
|
+
const inputArr = {
|
|
439
|
+
type: 'ArrayValue',
|
|
440
|
+
value: [],
|
|
441
|
+
};
|
|
442
|
+
template.memberUsage.forEach((member) => {
|
|
443
|
+
const primVal = {
|
|
444
|
+
type: 'PrimitiveValue',
|
|
445
|
+
value: member,
|
|
446
|
+
};
|
|
447
|
+
inputArr.value.push(primVal);
|
|
448
|
+
});
|
|
449
|
+
const validTemplateStringFunction = {
|
|
450
|
+
type: exports.TEMPLATED_STRING_FUNCTION,
|
|
451
|
+
reference: {
|
|
452
|
+
type: 'InternalReference',
|
|
453
|
+
value: template.generatedName,
|
|
454
|
+
},
|
|
455
|
+
input: [inputArr],
|
|
456
|
+
location: undefined,
|
|
457
|
+
};
|
|
458
|
+
//if we have an adg make changes to it.
|
|
459
|
+
if (adg) {
|
|
460
|
+
template.f_index = addPropertyFunction(adg, propertyName, validTemplateStringFunction);
|
|
461
|
+
}
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
exports.updateKomaciDocumentWithValidTemplatedStrings = updateKomaciDocumentWithValidTemplatedStrings;
|
|
467
|
+
/**
|
|
468
|
+
* Update the functions array with the newly formed function reference and point the property to it
|
|
469
|
+
* @param adg The adg to update
|
|
470
|
+
* @param propertyName name of the property to update
|
|
471
|
+
*/
|
|
472
|
+
function addPropertyFunction(adg, propertyName, func) {
|
|
473
|
+
if (!adg.functions) {
|
|
474
|
+
adg.functions = [];
|
|
475
|
+
}
|
|
476
|
+
if (!adg.properties) {
|
|
477
|
+
adg.properties = {};
|
|
478
|
+
}
|
|
479
|
+
//push getter onto array get the length.
|
|
480
|
+
const fIndex = adg.functions.push(func);
|
|
481
|
+
const refIndex = fIndex - 1;
|
|
482
|
+
//create new property to reference function array.
|
|
483
|
+
const property = {
|
|
484
|
+
isPublic: adg.properties[propertyName]?.isPublic || false,
|
|
485
|
+
input: {
|
|
486
|
+
type: 'FunctionReference',
|
|
487
|
+
value: refIndex,
|
|
488
|
+
},
|
|
489
|
+
};
|
|
490
|
+
adg.properties[propertyName] = property;
|
|
491
|
+
return refIndex;
|
|
492
|
+
}
|
|
493
|
+
exports.addPropertyFunction = addPropertyFunction;
|
|
554
494
|
//# sourceMappingURL=utils.js.map
|
package/build/wires.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { GetPrimingAdapter } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Determine whether the wire adapter is supported
|
|
4
|
+
* @param resourceName the resource name of the Import, as a string
|
|
5
|
+
* @param adapterName the wire adapter variable name (import specifier export name) from a single
|
|
6
|
+
* Import statement (which can have more than one of these export names)
|
|
7
|
+
* @returns boolean true if the adapterName represents is a supported wire adapter (note that some
|
|
8
|
+
* resourceNames allow any adapterName as valid wire adapters)
|
|
9
|
+
*/
|
|
10
|
+
export declare function isSupportedWireAdapter(resourceName: string | undefined, adapterName: string | undefined): boolean;
|
|
11
|
+
export declare const getPrimingAdapter: GetPrimingAdapter;
|
|
12
|
+
//# sourceMappingURL=wires.d.ts.map
|
package/build/wires.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPrimingAdapter = exports.isSupportedWireAdapter = void 0;
|
|
4
|
+
const adaptersMapping_1 = require("./adaptersMapping");
|
|
5
|
+
const allowlistAdapters_1 = require("./allowlistAdapters");
|
|
6
|
+
/**
|
|
7
|
+
* Determine whether the wire adapter is supported
|
|
8
|
+
* @param resourceName the resource name of the Import, as a string
|
|
9
|
+
* @param adapterName the wire adapter variable name (import specifier export name) from a single
|
|
10
|
+
* Import statement (which can have more than one of these export names)
|
|
11
|
+
* @returns boolean true if the adapterName represents is a supported wire adapter (note that some
|
|
12
|
+
* resourceNames allow any adapterName as valid wire adapters)
|
|
13
|
+
*/
|
|
14
|
+
function isSupportedWireAdapter(resourceName, adapterName) {
|
|
15
|
+
if (!resourceName || !adapterName) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
// check if the resourceName is one of the types that can have any wire adapter name. If so, return true.
|
|
19
|
+
// allow list of ResourceName that can be a "starsWith" match
|
|
20
|
+
for (const allowedResourceNamePrefix of allowlistAdapters_1.allowlistResourceNamesStartsWith) {
|
|
21
|
+
if (resourceName.startsWith(allowedResourceNamePrefix)) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
// allow list of ResourceNames that need to be an exact match
|
|
26
|
+
for (const allowedResourceName of allowlistAdapters_1.allowlistResourceNamesExact) {
|
|
27
|
+
if (resourceName === allowedResourceName) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// check the allowlist of wire adapters for certain various resourceNames that all start with "lightning".
|
|
32
|
+
for (const [resourceNameKey, adapterList] of Object.entries(allowlistAdapters_1.allowlistAdapters)) {
|
|
33
|
+
if (resourceNameKey === resourceName && adapterList.includes(adapterName)) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// check if there's an associated LDS priming adapter.
|
|
38
|
+
if ((0, exports.getPrimingAdapter)(resourceName, adapterName)) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
exports.isSupportedWireAdapter = isSupportedWireAdapter;
|
|
44
|
+
const getPrimingAdapter = (importPath, identifier) => {
|
|
45
|
+
const adapterMap = adaptersMapping_1.wireAdaptersMap[importPath];
|
|
46
|
+
if (adapterMap === undefined) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
const primingAdapter = adapterMap[identifier];
|
|
50
|
+
if (primingAdapter === undefined) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
return primingAdapter;
|
|
54
|
+
};
|
|
55
|
+
exports.getPrimingAdapter = getPrimingAdapter;
|
|
56
|
+
//# sourceMappingURL=wires.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@komaci/common-shared",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "242.1.0",
|
|
4
4
|
"description": "Assets that are shared across Komaci commonjs packages",
|
|
5
5
|
"homepage": "https://komaci.dev/",
|
|
6
6
|
"repository": {
|
|
@@ -25,10 +25,11 @@
|
|
|
25
25
|
"files": [
|
|
26
26
|
"build/**/*.js",
|
|
27
27
|
"build/**/*.d.ts",
|
|
28
|
-
"build/internal-namespaces.json"
|
|
28
|
+
"build/internal-namespaces.json",
|
|
29
|
+
"build/komaci-mapping.json"
|
|
29
30
|
],
|
|
30
31
|
"devDependencies": {
|
|
31
|
-
"@komaci/types": "
|
|
32
|
+
"@komaci/types": "242.1.0"
|
|
32
33
|
},
|
|
33
34
|
"dependencies": {
|
|
34
35
|
"@babel/core": "^7.9.0",
|