@komaci/common-shared 242.0.0 → 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/utils.js CHANGED
@@ -1,32 +1,7 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
- 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.getAllImportReferences = exports.getFromIdentifierOrStringLiteral = exports.collectImportUsage = exports.getMemberVarsFromGetter = exports.implicitConsumptionMetadata = exports.getClassPropertyInfos = exports.getClassProperties = exports.getPropertyMetadataFromAst = exports.TEMPLATED_STRING_FUNCTION = exports.GETTER_FUNCTION = exports.ONE_NS = exports.FORCE_NS = exports.LIGHTNING_NS = void 0;
27
- 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;
28
4
  const core_1 = require("@babel/core");
29
- const allowlistNamespaces_1 = require("./allowlistNamespaces");
30
5
  exports.LIGHTNING_NS = 'lightning';
31
6
  exports.FORCE_NS = 'force';
32
7
  exports.ONE_NS = 'one';
@@ -77,80 +52,6 @@ function getPropertyMetadataFromAst(ast) {
77
52
  return nodes;
78
53
  }
79
54
  exports.getPropertyMetadataFromAst = getPropertyMetadataFromAst;
80
- /**
81
- * @param node
82
- * @returns true if node is a ClassBody
83
- */
84
- function isNodeClassBody(node) {
85
- return node?.type === 'ClassBody';
86
- }
87
- /**
88
- * Given the AST of an entire JS source file, this method looks for class member properties.
89
- * If there is no default export in the AST, no class properties will be returned (empty array is returned).
90
- * @param astRoot AST representing an entire Program, as a @babel/types File object
91
- * @returns Array of NodePath<ClassProperty> representing the @babel NodePaths for all class member
92
- * properties, if any exist. Otherwise, returns an empty array.
93
- */
94
- function getClassProperties(astRoot) {
95
- let classProperties = [];
96
- const prog = astRoot.program;
97
- const body = prog.body;
98
- const exportDefaultDecl = body.filter((child) => child.type === 'ExportDefaultDeclaration');
99
- if (exportDefaultDecl.length > 0) {
100
- const classDecl = exportDefaultDecl[0]
101
- .declaration; // there can only be one export default declaration
102
- if (isNodeClassBody(classDecl.body)) {
103
- const classBody = classDecl.body;
104
- classProperties = classBody.body.filter((classChild) => classChild.type === 'ClassProperty' ||
105
- (classChild.type === 'ClassMethod' && classChild.kind === 'get'));
106
- }
107
- }
108
- return classProperties;
109
- }
110
- exports.getClassProperties = getClassProperties;
111
- /**
112
- * Utility method that takes in an @babel/types ClassProperty array, and returns an array of ClassPropertyInfo
113
- * objects containing information about each ClassProperty from the input array.
114
- * @param classProperties
115
- * @returns Array of ClassPropertyInfo, where each element corresponds to the input ClassProperty array.
116
- */
117
- function getClassPropertyInfos(classProperties = []) {
118
- const classPropInfos = [];
119
- classProperties
120
- .filter((classProp) => t.isIdentifier(classProp.key))
121
- .forEach((classProp) => {
122
- const id = classProp.key;
123
- const decorators = classProp.decorators;
124
- let decoratorType = undefined;
125
- if (decorators) {
126
- // non-annotated class properties won't have a decorator
127
- const expr = decorators[0].expression;
128
- if (expr.type === 'CallExpression') {
129
- const callee = expr.callee;
130
- decoratorType = callee.name;
131
- }
132
- else if (expr.type === 'Identifier') {
133
- decoratorType = expr.name;
134
- }
135
- }
136
- const classPropInfo = {
137
- classProp: classProp,
138
- classPropId: id.name,
139
- isDecorated: decorators !== undefined &&
140
- decorators !== null &&
141
- decorators.length > 0,
142
- hasInitialValue: t.isClassProperty(classProp)
143
- ? classProp.value !== null
144
- : false,
145
- };
146
- if (classPropInfo.isDecorated) {
147
- classPropInfo.decoratorType = decoratorType;
148
- }
149
- classPropInfos.push(classPropInfo);
150
- });
151
- return classPropInfos;
152
- }
153
- exports.getClassPropertyInfos = getClassPropertyInfos;
154
55
  /**
155
56
  * Given a valid functional node (tempalte string or getter function), collect information that we may not have been able to collect via KomaciDocument
156
57
  * and return a list of class member variables that are properly used in the method body.
@@ -165,8 +66,7 @@ exports.getClassPropertyInfos = getClassPropertyInfos;
165
66
  * @returns ImplicitConsumption, which contains an array representing the properly-used member variables.
166
67
  * Returns ImplicitConsumption with an empty array if none were found.
167
68
  */
168
- function implicitConsumptionMetadata(node, classPropInfos, importDeclarations, // import metadata
169
- moduleLevelConsumption) {
69
+ function implicitConsumptionMetadata(node, adgIndex, moduleMetadata) {
170
70
  const identifiers = new Set();
171
71
  const Visitors = {
172
72
  // visitor for each type
@@ -174,7 +74,9 @@ moduleLevelConsumption) {
174
74
  getMemberVarsFromGetter(path, identifiers);
175
75
  },
176
76
  Identifier(path) {
177
- collectImportUsage(path, classPropInfos, importDeclarations, moduleLevelConsumption.consumedImports);
77
+ collectImportUsage(path, moduleMetadata,
78
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
79
+ moduleMetadata.adgs.get(adgIndex).properties);
178
80
  },
179
81
  };
180
82
  node.traverse(Visitors);
@@ -208,61 +110,32 @@ exports.getMemberVarsFromGetter = getMemberVarsFromGetter;
208
110
  * @param consumedImports The map to add info to about this identifier, whether it is an import that is being used
209
111
  * in the getter, or if it is assigned an import being used in the getter.
210
112
  */
211
- function collectImportUsage(path, classPropInfos, importDeclarations, consumedImports) {
212
- const name = path.node.name;
213
- let nameToReference = name;
214
- let importInfo = importDeclarations.get(name); // finds direct references of import specifiers in the getter
215
- // i.e. find `MyID1.CONST` in the getter, where `MyID1` is an import specifier
216
- if (!importInfo &&
217
- path.parent.type === 'MemberExpression' &&
218
- path.parent.object.type === 'Identifier' &&
219
- path.parent.object === path.node) {
220
- importInfo = importDeclarations.get(path.parent.object.name);
221
- }
222
- // find indirect import references (where import was assigned to a class member variable)
223
- if (!importInfo) {
224
- const importSpecifierNames = new Set(Array.from(importDeclarations.keys()));
225
- classPropInfos.forEach((classPropInfo) => {
226
- // check for type NodePath<t.ClassProperty> vs. t.ClassProperty. The former has a .node property
227
- const isNodePath = classPropInfo.classProp.node !== undefined;
228
- const classProp = isNodePath
229
- ? classPropInfo.classProp.node
230
- : classPropInfo.classProp;
231
- if (classProp.key.type === 'Identifier' &&
232
- classProp.key.name === name &&
233
- classProp.value?.type === 'Identifier' &&
234
- importSpecifierNames.has(classProp.value.name)) {
235
- 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;
236
123
  }
237
- });
238
- }
239
- if (importInfo) {
240
- if (importInfo.isDefault) {
241
- nameToReference = 'default';
242
- }
243
- else if (importInfo.isNamespaceSpecifier) {
244
- // this case needs to be handled separately as it always has an alias
245
- nameToReference = '*';
246
124
  }
247
- else if (importInfo.trueName) {
248
- nameToReference = importInfo.trueName;
249
- }
250
- let fullImportContext = consumedImports.get(importInfo.namespace);
251
- if (fullImportContext && !fullImportContext.names.has(name)) {
252
- fullImportContext.names.add(nameToReference);
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);
253
135
  }
254
- else if (!fullImportContext) {
255
- const names = new Set();
256
- names.add(nameToReference);
257
- fullImportContext = {
258
- names,
259
- resourceName: importInfo.namespace,
260
- isNamespaceSpecifier: importInfo.isNamespaceSpecifier,
261
- isDefaultSpecifier: importInfo.isDefault,
262
- isSupported: importInfo.isSupported,
263
- };
136
+ if (importInfo) {
137
+ importInfo.usedInPriming = true;
264
138
  }
265
- consumedImports.set(importInfo.namespace, fullImportContext);
266
139
  }
267
140
  }
268
141
  exports.collectImportUsage = collectImportUsage;
@@ -276,53 +149,6 @@ function getFromIdentifierOrStringLiteral(node) {
276
149
  return node.type === 'Identifier' ? node.name : node.value;
277
150
  }
278
151
  exports.getFromIdentifierOrStringLiteral = getFromIdentifierOrStringLiteral;
279
- /**
280
- * Function for getting an array of supported namesapce references.
281
- * @param astRoot the root of the ast
282
- * @returns an Array of supported namespace references.
283
- */
284
- function getAllImportReferences(astRoot) {
285
- const importReferences = new Map();
286
- const program = astRoot.program;
287
- const body = program.body;
288
- const importDeclarations = body.filter((currentDec) => currentDec.type === 'ImportDeclaration');
289
- importDeclarations.forEach((currentDec) => {
290
- const isValid = isValidNamespace(currentDec.source.value) &&
291
- (0, allowlistNamespaces_1.isLibraryValid)(currentDec.source.value);
292
- const specifiers = currentDec.specifiers;
293
- specifiers.forEach((currentSpecifier) => {
294
- let importName = undefined;
295
- if (currentSpecifier.type === 'ImportSpecifier') {
296
- importName = currentSpecifier.local // local is alias (the most specific name)
297
- ? getFromIdentifierOrStringLiteral(currentSpecifier.local)
298
- : getFromIdentifierOrStringLiteral(currentSpecifier.imported);
299
- }
300
- else {
301
- importName = getFromIdentifierOrStringLiteral(currentSpecifier.local);
302
- }
303
- importReferences.set(importName, {
304
- namespace: currentDec.source.value,
305
- identifierName: importName,
306
- isSupported: isValid,
307
- isDefault: currentSpecifier.type === 'ImportDefaultSpecifier',
308
- isNamespaceSpecifier: currentSpecifier.type === 'ImportNamespaceSpecifier',
309
- trueName: currentSpecifier.type === 'ImportSpecifier'
310
- ? getFromIdentifierOrStringLiteral(currentSpecifier.imported)
311
- : undefined,
312
- });
313
- });
314
- });
315
- return importReferences;
316
- }
317
- exports.getAllImportReferences = getAllImportReferences;
318
- /**
319
- * Helper function to validate if a namespace is in our allowed namespace list.
320
- * @param namespace the namespace to validate.
321
- * @returns true of the namespace is supported, false if unsupported.
322
- */
323
- function isValidNamespace(importPath) {
324
- return (0, allowlistNamespaces_1.isNamespaceInternal)((0, allowlistNamespaces_1.getNamespaceFromImport)(importPath));
325
- }
326
152
  /**
327
153
  * Function to get an array of function names that are defined at the module level.
328
154
  * @returns an array of function names that are defined at the module level.
@@ -420,12 +246,9 @@ exports.getAllClassMethods = getAllClassMethods;
420
246
  * @returns a context object containing meta data about the ast.
421
247
  */
422
248
  function getAstContextObject(ast) {
423
- const props = getClassProperties(ast);
424
249
  const context = {
425
- importDeclarations: getAllImportReferences(ast),
426
250
  moduleFunctions: getAllModuleFunctions(ast),
427
251
  moduleVariables: getAllModuleVaraibles(ast),
428
- classProperties: getClassPropertyInfos(props),
429
252
  classFunctions: getAllClassMethods(ast),
430
253
  };
431
254
  return context;
@@ -549,9 +372,9 @@ exports.isExpressionThisOrAlias = isExpressionThisOrAlias;
549
372
  * @param declaredGetterVars a collection of variables declared within the getter
550
373
  * @param id the id of the member we are referencing.
551
374
  */
552
- function isDeclaredInAst(astContext, declaredGetterVars, id) {
553
- const { classProperties, importDeclarations, moduleVariables } = astContext;
554
- return (classProperties.find((prop) => prop.classPropId === id) !== undefined ||
375
+ function isDeclaredInAst(astContext, importDeclarations, classProperties, declaredGetterVars, id) {
376
+ const { moduleVariables } = astContext;
377
+ return (classProperties.has(id) ||
555
378
  importDeclarations.has(id) ||
556
379
  moduleVariables.find((varId) => varId === id) !== undefined ||
557
380
  (declaredGetterVars || []).find((varId) => varId === id) !== undefined);
@@ -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": "242.0.0",
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": "242.0.0"
32
+ "@komaci/types": "242.1.0"
32
33
  },
33
34
  "dependencies": {
34
35
  "@babel/core": "^7.9.0",