@komaci/common-shared 240.1.5 → 242.1.1
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 +7 -0
- package/build/allowlistNamespaces.js +27 -1
- package/build/index.d.ts +3 -0
- package/build/index.js +8 -1
- package/build/internal-namespaces.json +4 -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 +175 -0
- package/build/moduleMetadata.js +646 -0
- package/build/types.d.ts +217 -82
- package/build/types.js +54 -3
- package/build/utils.d.ts +33 -26
- package/build/utils.js +157 -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,13 @@
|
|
|
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.getFilepathSegments = 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
|
|
5
|
+
const types_1 = require("./types");
|
|
26
6
|
exports.LIGHTNING_NS = 'lightning';
|
|
27
7
|
exports.FORCE_NS = 'force';
|
|
28
8
|
exports.ONE_NS = 'one';
|
|
9
|
+
exports.GETTER_FUNCTION = 'GetterFunction';
|
|
10
|
+
exports.TEMPLATED_STRING_FUNCTION = 'TemplatedStringFunction';
|
|
29
11
|
/**
|
|
30
12
|
* collect node paths for different pieces of a given class so we can more effectively traverse them in the future
|
|
31
13
|
*
|
|
@@ -71,80 +53,6 @@ function getPropertyMetadataFromAst(ast) {
|
|
|
71
53
|
return nodes;
|
|
72
54
|
}
|
|
73
55
|
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
56
|
/**
|
|
149
57
|
* Given a valid functional node (tempalte string or getter function), collect information that we may not have been able to collect via KomaciDocument
|
|
150
58
|
* and return a list of class member variables that are properly used in the method body.
|
|
@@ -159,8 +67,7 @@ exports.getClassPropertyInfos = getClassPropertyInfos;
|
|
|
159
67
|
* @returns ImplicitConsumption, which contains an array representing the properly-used member variables.
|
|
160
68
|
* Returns ImplicitConsumption with an empty array if none were found.
|
|
161
69
|
*/
|
|
162
|
-
function implicitConsumptionMetadata(node,
|
|
163
|
-
moduleLevelConsumption) {
|
|
70
|
+
function implicitConsumptionMetadata(node, adgIndex, moduleMetadata) {
|
|
164
71
|
const identifiers = new Set();
|
|
165
72
|
const Visitors = {
|
|
166
73
|
// visitor for each type
|
|
@@ -168,7 +75,9 @@ moduleLevelConsumption) {
|
|
|
168
75
|
getMemberVarsFromGetter(path, identifiers);
|
|
169
76
|
},
|
|
170
77
|
Identifier(path) {
|
|
171
|
-
collectImportUsage(path,
|
|
78
|
+
collectImportUsage(path, moduleMetadata,
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
80
|
+
moduleMetadata.adgs.get(adgIndex).properties);
|
|
172
81
|
},
|
|
173
82
|
};
|
|
174
83
|
node.traverse(Visitors);
|
|
@@ -202,61 +111,32 @@ exports.getMemberVarsFromGetter = getMemberVarsFromGetter;
|
|
|
202
111
|
* @param consumedImports The map to add info to about this identifier, whether it is an import that is being used
|
|
203
112
|
* in the getter, or if it is assigned an import being used in the getter.
|
|
204
113
|
*/
|
|
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);
|
|
114
|
+
function collectImportUsage(path, moduleMetadata, properties) {
|
|
115
|
+
if (path.parent.type === 'MemberExpression' &&
|
|
116
|
+
path.parent.object.type === 'ThisExpression' &&
|
|
117
|
+
path.parent.property.type === 'Identifier') {
|
|
118
|
+
const identifier = path.parent.property;
|
|
119
|
+
const referencedProperty = properties.get(identifier.name);
|
|
120
|
+
if (referencedProperty && referencedProperty.inital?.type === 'ImportReference') {
|
|
121
|
+
const importMetadata = moduleMetadata.importsByName.get(moduleMetadata.importIndexReference.get(referencedProperty.inital.value) || '');
|
|
122
|
+
if (importMetadata) {
|
|
123
|
+
importMetadata.usedInPriming = true;
|
|
230
124
|
}
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
if (importInfo) {
|
|
234
|
-
if (importInfo.isDefault) {
|
|
235
|
-
nameToReference = 'default';
|
|
236
125
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
const name = path.node.name;
|
|
129
|
+
let importInfo = moduleMetadata.importsByName.get(name); // finds direct references of import specifiers in the getter
|
|
130
|
+
// i.e. find `MyID1.CONST` in the getter, where `MyID1` is an import specifier
|
|
131
|
+
if (!importInfo &&
|
|
132
|
+
path.parent.type === 'MemberExpression' &&
|
|
133
|
+
path.parent.object.type === 'Identifier' &&
|
|
134
|
+
path.parent.object === path.node) {
|
|
135
|
+
importInfo = moduleMetadata.importsByName.get(path.parent.object.name);
|
|
247
136
|
}
|
|
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
|
-
};
|
|
137
|
+
if (importInfo) {
|
|
138
|
+
importInfo.usedInPriming = true;
|
|
258
139
|
}
|
|
259
|
-
consumedImports.set(importInfo.namespace, fullImportContext);
|
|
260
140
|
}
|
|
261
141
|
}
|
|
262
142
|
exports.collectImportUsage = collectImportUsage;
|
|
@@ -270,53 +150,6 @@ function getFromIdentifierOrStringLiteral(node) {
|
|
|
270
150
|
return node.type === 'Identifier' ? node.name : node.value;
|
|
271
151
|
}
|
|
272
152
|
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
153
|
/**
|
|
321
154
|
* Function to get an array of function names that are defined at the module level.
|
|
322
155
|
* @returns an array of function names that are defined at the module level.
|
|
@@ -414,12 +247,9 @@ exports.getAllClassMethods = getAllClassMethods;
|
|
|
414
247
|
* @returns a context object containing meta data about the ast.
|
|
415
248
|
*/
|
|
416
249
|
function getAstContextObject(ast) {
|
|
417
|
-
const props = getClassProperties(ast);
|
|
418
250
|
const context = {
|
|
419
|
-
importDeclarations: getAllImportReferences(ast),
|
|
420
251
|
moduleFunctions: getAllModuleFunctions(ast),
|
|
421
252
|
moduleVariables: getAllModuleVaraibles(ast),
|
|
422
|
-
classProperties: getClassPropertyInfos(props),
|
|
423
253
|
classFunctions: getAllClassMethods(ast),
|
|
424
254
|
};
|
|
425
255
|
return context;
|
|
@@ -543,12 +373,136 @@ exports.isExpressionThisOrAlias = isExpressionThisOrAlias;
|
|
|
543
373
|
* @param declaredGetterVars a collection of variables declared within the getter
|
|
544
374
|
* @param id the id of the member we are referencing.
|
|
545
375
|
*/
|
|
546
|
-
function isDeclaredInAst(astContext, declaredGetterVars, id) {
|
|
547
|
-
const {
|
|
548
|
-
return (classProperties.
|
|
376
|
+
function isDeclaredInAst(astContext, importDeclarations, classProperties, declaredGetterVars, id) {
|
|
377
|
+
const { moduleVariables } = astContext;
|
|
378
|
+
return (classProperties.has(id) ||
|
|
549
379
|
importDeclarations.has(id) ||
|
|
550
380
|
moduleVariables.find((varId) => varId === id) !== undefined ||
|
|
551
381
|
(declaredGetterVars || []).find((varId) => varId === id) !== undefined);
|
|
552
382
|
}
|
|
553
383
|
exports.isDeclaredInAst = isDeclaredInAst;
|
|
384
|
+
/**
|
|
385
|
+
* Function to update the Komaci Document with validated getter information. This function will update the functions array in the
|
|
386
|
+
* export default adg along with the property references in the property array.
|
|
387
|
+
* @param komaciScriptDoc the komaci document
|
|
388
|
+
* @param validGetterContext a collection
|
|
389
|
+
*/
|
|
390
|
+
function updateKomaciDocumentWithValidGetters(komaciScriptDoc, validGetterContext) {
|
|
391
|
+
if (komaciScriptDoc.exports) {
|
|
392
|
+
//get the exort mapping for the export default
|
|
393
|
+
const defaultExportMapping = komaciScriptDoc.exports['default'];
|
|
394
|
+
if (defaultExportMapping && defaultExportMapping.type === 'AdgReference') {
|
|
395
|
+
const defaultExportAdg = komaciScriptDoc.adgs?.[defaultExportMapping.value];
|
|
396
|
+
//foreach getter in the context.
|
|
397
|
+
validGetterContext.forEach((getter) => {
|
|
398
|
+
//Get the name of the getter.
|
|
399
|
+
const getterName = getter.getter.node.key.name;
|
|
400
|
+
const inputArr = {
|
|
401
|
+
type: 'ArrayValue',
|
|
402
|
+
value: [],
|
|
403
|
+
};
|
|
404
|
+
getter.memberUsage.forEach((member) => {
|
|
405
|
+
const primVal = {
|
|
406
|
+
type: 'PrimitiveValue',
|
|
407
|
+
value: member,
|
|
408
|
+
};
|
|
409
|
+
inputArr.value.push(primVal);
|
|
410
|
+
});
|
|
411
|
+
//create a new functionType obj with getter information.
|
|
412
|
+
const validGetterFunction = {
|
|
413
|
+
type: exports.GETTER_FUNCTION,
|
|
414
|
+
reference: { type: 'InternalReference', value: getter.generatedName },
|
|
415
|
+
input: [inputArr],
|
|
416
|
+
location: undefined,
|
|
417
|
+
};
|
|
418
|
+
//if we have an adg make changes to it.
|
|
419
|
+
if (defaultExportAdg) {
|
|
420
|
+
getter.f_index = addPropertyFunction(defaultExportAdg, getterName, validGetterFunction);
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
exports.updateKomaciDocumentWithValidGetters = updateKomaciDocumentWithValidGetters;
|
|
427
|
+
/**
|
|
428
|
+
* Function to update the Komaci Document with validated template information. This function will update the functions array in the
|
|
429
|
+
* export default adg along with the property references in the property array.
|
|
430
|
+
* @param komaciScriptDoc the komaci document
|
|
431
|
+
* @param ValidTemplateContext details about the templates we've deemed to be valid
|
|
432
|
+
*/
|
|
433
|
+
function updateKomaciDocumentWithValidTemplatedStrings(komaciScriptDoc, templateStrings) {
|
|
434
|
+
if (komaciScriptDoc.exports?.default?.type === 'AdgReference') {
|
|
435
|
+
const adg = komaciScriptDoc.adgs?.[komaciScriptDoc.exports.default.value];
|
|
436
|
+
if (adg) {
|
|
437
|
+
templateStrings.forEach((template) => {
|
|
438
|
+
const propertyName = template.template.node.key.name;
|
|
439
|
+
const inputArr = {
|
|
440
|
+
type: 'ArrayValue',
|
|
441
|
+
value: [],
|
|
442
|
+
};
|
|
443
|
+
template.memberUsage.forEach((member) => {
|
|
444
|
+
const primVal = {
|
|
445
|
+
type: 'PrimitiveValue',
|
|
446
|
+
value: member,
|
|
447
|
+
};
|
|
448
|
+
inputArr.value.push(primVal);
|
|
449
|
+
});
|
|
450
|
+
const validTemplateStringFunction = {
|
|
451
|
+
type: exports.TEMPLATED_STRING_FUNCTION,
|
|
452
|
+
reference: {
|
|
453
|
+
type: 'InternalReference',
|
|
454
|
+
value: template.generatedName,
|
|
455
|
+
},
|
|
456
|
+
input: [inputArr],
|
|
457
|
+
location: undefined,
|
|
458
|
+
};
|
|
459
|
+
//if we have an adg make changes to it.
|
|
460
|
+
if (adg) {
|
|
461
|
+
template.f_index = addPropertyFunction(adg, propertyName, validTemplateStringFunction);
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
exports.updateKomaciDocumentWithValidTemplatedStrings = updateKomaciDocumentWithValidTemplatedStrings;
|
|
468
|
+
/**
|
|
469
|
+
* Update the functions array with the newly formed function reference and point the property to it
|
|
470
|
+
* @param adg The adg to update
|
|
471
|
+
* @param propertyName name of the property to update
|
|
472
|
+
*/
|
|
473
|
+
function addPropertyFunction(adg, propertyName, func) {
|
|
474
|
+
if (!adg.functions) {
|
|
475
|
+
adg.functions = [];
|
|
476
|
+
}
|
|
477
|
+
if (!adg.properties) {
|
|
478
|
+
adg.properties = {};
|
|
479
|
+
}
|
|
480
|
+
//push getter onto array get the length.
|
|
481
|
+
const fIndex = adg.functions.push(func);
|
|
482
|
+
const refIndex = fIndex - 1;
|
|
483
|
+
//create new property to reference function array.
|
|
484
|
+
const property = {
|
|
485
|
+
isPublic: adg.properties[propertyName]?.isPublic || false,
|
|
486
|
+
input: {
|
|
487
|
+
type: 'FunctionReference',
|
|
488
|
+
value: refIndex,
|
|
489
|
+
},
|
|
490
|
+
};
|
|
491
|
+
adg.properties[propertyName] = property;
|
|
492
|
+
return refIndex;
|
|
493
|
+
}
|
|
494
|
+
exports.addPropertyFunction = addPropertyFunction;
|
|
495
|
+
/**
|
|
496
|
+
* Function to slpit an import path seperated by . EX: ./test.html = [, /test, html ]
|
|
497
|
+
* @param fullFilename the full file name
|
|
498
|
+
* @returns the full file name separated into segments.
|
|
499
|
+
*/
|
|
500
|
+
function getFilepathSegments(fullFilename) {
|
|
501
|
+
const segments = fullFilename.split('.');
|
|
502
|
+
if (segments.length < 2) {
|
|
503
|
+
throw new Error(types_1.ERROR_PREFIX + 'unable to determine file type');
|
|
504
|
+
}
|
|
505
|
+
return segments;
|
|
506
|
+
}
|
|
507
|
+
exports.getFilepathSegments = getFilepathSegments;
|
|
554
508
|
//# 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.1",
|
|
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.1"
|
|
32
33
|
},
|
|
33
34
|
"dependencies": {
|
|
34
35
|
"@babel/core": "^7.9.0",
|