@komaci/common-shared 248.1.2 → 248.1.3
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/moduleMetadata.d.ts +9 -0
- package/build/moduleMetadata.js +29 -1
- package/build/types.d.ts +21 -0
- package/build/utils.d.ts +24 -1
- package/build/utils.js +53 -1
- package/package.json +2 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { FunctionType, KomaciDocument } from '@komaci/types';
|
|
2
2
|
import * as t from '@babel/types';
|
|
3
3
|
import { AdgMetadata, ImportDetail, ImportMetadata, ModuleMetadata, PrimingAdapterDefinition, TemplateImportMetadata, WireFunctionMetadata } from './types';
|
|
4
|
+
import { GQLTag } from '@lwc/metadata/dist/schema/typescript-types/luvio-metadata-types';
|
|
4
5
|
/** not all imports are consumed in a statically analyzable way. when we add their metadata, we use this to ack that the komaciDocImportRef for this import is nil */
|
|
5
6
|
export declare const NO_KOMACI_DOC_REF = "nil";
|
|
6
7
|
/**
|
|
@@ -189,4 +190,12 @@ export declare function upliftFakePropsFromTemplate(adg: AdgMetadata): void;
|
|
|
189
190
|
* @returns true or false;
|
|
190
191
|
*/
|
|
191
192
|
export declare function isTemplateImport(importMetadata: ImportMetadata): importMetadata is TemplateImportMetadata;
|
|
193
|
+
/**
|
|
194
|
+
* Function to initalize the gqlMetadata from the luvioMetadata.
|
|
195
|
+
* NOTE: To generate the key for the map, we use the location.start and location.end from the luvio metadata
|
|
196
|
+
* which is equivalent to the start and end field of the templateLiteral of a tagged template expression.
|
|
197
|
+
* @param gqlTags the gql tags from the luvio metadata
|
|
198
|
+
* @param moduleMetadata the module metadata object.
|
|
199
|
+
*/
|
|
200
|
+
export declare const initGqlMetadata: (gqlTags: GQLTag[], moduleMetadata: ModuleMetadata) => void;
|
|
192
201
|
//# sourceMappingURL=moduleMetadata.d.ts.map
|
package/build/moduleMetadata.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isTemplateImport = exports.upliftFakePropsFromTemplate = exports.reconcileDefaultAdg = exports.isImportInvalid = exports.reconcilePrimingAdapater = exports.reconcileWireReference = exports.composeWireFunctionMetadata = exports.addTemplateUsageForAdg = exports.mapExportNamesToAdgs = exports.initalizeAdgMetadata = exports.findOtherAlias = exports.collectImportMetadataFromAst = exports.getImportFromNamespace = exports.getImportTemplateKomaciDocByResourceName = exports.updateAliasForImport = exports.addNewImportFromAst = exports.reconcileImport = exports.reconcileNamespace = exports.traverseAstImports = exports.composeImportMetadata = exports.initializeImportMetdataFromKomaciDocument = exports.initAdgMetadataObject = exports.initModuleMetadataObject = exports.NO_KOMACI_DOC_REF = void 0;
|
|
3
|
+
exports.initGqlMetadata = exports.isTemplateImport = exports.upliftFakePropsFromTemplate = exports.reconcileDefaultAdg = exports.isImportInvalid = exports.reconcilePrimingAdapater = exports.reconcileWireReference = exports.composeWireFunctionMetadata = exports.addTemplateUsageForAdg = exports.mapExportNamesToAdgs = exports.initalizeAdgMetadata = exports.findOtherAlias = exports.collectImportMetadataFromAst = exports.getImportFromNamespace = exports.getImportTemplateKomaciDocByResourceName = exports.updateAliasForImport = exports.addNewImportFromAst = exports.reconcileImport = exports.reconcileNamespace = exports.traverseAstImports = exports.composeImportMetadata = exports.initializeImportMetdataFromKomaciDocument = exports.initAdgMetadataObject = exports.initModuleMetadataObject = exports.NO_KOMACI_DOC_REF = void 0;
|
|
4
4
|
const allowlistNamespaces_1 = require("./allowlistNamespaces");
|
|
5
5
|
const komaciDocumentIntrospection_1 = require("./komaciDocumentIntrospection");
|
|
6
6
|
const types_1 = require("./types");
|
|
@@ -22,6 +22,7 @@ const initModuleMetadataObject = () => ({
|
|
|
22
22
|
exports: {},
|
|
23
23
|
templateKomaciDocMap: {},
|
|
24
24
|
staticMetadataId: '',
|
|
25
|
+
gqlMetadata: new Map(),
|
|
25
26
|
});
|
|
26
27
|
exports.initModuleMetadataObject = initModuleMetadataObject;
|
|
27
28
|
/**
|
|
@@ -732,4 +733,31 @@ function isTemplateImport(importMetadata) {
|
|
|
732
733
|
return temp != undefined;
|
|
733
734
|
}
|
|
734
735
|
exports.isTemplateImport = isTemplateImport;
|
|
736
|
+
/**
|
|
737
|
+
* Function to initalize the gqlMetadata from the luvioMetadata.
|
|
738
|
+
* NOTE: To generate the key for the map, we use the location.start and location.end from the luvio metadata
|
|
739
|
+
* which is equivalent to the start and end field of the templateLiteral of a tagged template expression.
|
|
740
|
+
* @param gqlTags the gql tags from the luvio metadata
|
|
741
|
+
* @param moduleMetadata the module metadata object.
|
|
742
|
+
*/
|
|
743
|
+
const initGqlMetadata = (gqlTags, moduleMetadata) => {
|
|
744
|
+
const sfNamespace = '@salesforce';
|
|
745
|
+
const gqlNamespace = 'gql';
|
|
746
|
+
gqlTags.forEach((tag, index) => {
|
|
747
|
+
const importAlias = `gql${index}`;
|
|
748
|
+
const importPath = `${sfNamespace}/${gqlNamespace}/${tag.hash}`;
|
|
749
|
+
const gqlMetadata = {
|
|
750
|
+
hash: tag.hash,
|
|
751
|
+
hasExpressions: tag.hasExpressions,
|
|
752
|
+
location: tag.location,
|
|
753
|
+
isHoisted: false,
|
|
754
|
+
valid: false,
|
|
755
|
+
generatedImportAlias: importAlias,
|
|
756
|
+
importPath: importPath,
|
|
757
|
+
};
|
|
758
|
+
const key = (0, utils_1.generateLocationKey)(tag.location.start, tag.location.end);
|
|
759
|
+
moduleMetadata.gqlMetadata.set(key, gqlMetadata);
|
|
760
|
+
});
|
|
761
|
+
};
|
|
762
|
+
exports.initGqlMetadata = initGqlMetadata;
|
|
735
763
|
//# sourceMappingURL=moduleMetadata.js.map
|
package/build/types.d.ts
CHANGED
|
@@ -38,6 +38,7 @@ export declare enum IdKeys {
|
|
|
38
38
|
HOISTED_RENDER_FUNC_ID = "HOISTED_RENDER_FUNC_ID",
|
|
39
39
|
CONDITION_FUNC = "CONDITION_FUNC"
|
|
40
40
|
}
|
|
41
|
+
import { SourceLocation } from '@lwc/metadata/dist/schema/typescript-types/common-metadata-types';
|
|
41
42
|
/**
|
|
42
43
|
* @typedef AstContext is an object that holds meta data information about the ast.
|
|
43
44
|
* @property {string[]} moduleFunctions is a collection of function names that are defined on the module level.
|
|
@@ -291,6 +292,7 @@ export declare type ModuleMetadata = {
|
|
|
291
292
|
staticMetadataId: string;
|
|
292
293
|
includePropsMetadata?: boolean;
|
|
293
294
|
moduleType?: ModuleTypes.BUNDLE_MODULE | ModuleTypes.SCRIPT_ONLY | ModuleTypes.TEMPLATE_ONLY;
|
|
295
|
+
gqlMetadata: Map<string, GqlMetadata>;
|
|
294
296
|
};
|
|
295
297
|
export declare type ImportBinding = {
|
|
296
298
|
importPath: string;
|
|
@@ -346,4 +348,23 @@ export declare type ValidTemplateContext = {
|
|
|
346
348
|
export declare type Visited<T> = T & {
|
|
347
349
|
visited?: boolean;
|
|
348
350
|
};
|
|
351
|
+
/**
|
|
352
|
+
* Type for metadata about a gql query
|
|
353
|
+
*/
|
|
354
|
+
export declare type GqlMetadata = {
|
|
355
|
+
/** Hash generated by LWC */
|
|
356
|
+
hash: string;
|
|
357
|
+
/** Boolean to determine if the gql query contains an expression */
|
|
358
|
+
hasExpressions: boolean;
|
|
359
|
+
/** Location info for the gql tag */
|
|
360
|
+
location: SourceLocation;
|
|
361
|
+
/** Boolean for if the gql tag has been hoisted in the resolvable module */
|
|
362
|
+
isHoisted: boolean;
|
|
363
|
+
/** The AST identifier for the generated import ailias */
|
|
364
|
+
generatedImportAlias: string;
|
|
365
|
+
/** The import path string */
|
|
366
|
+
importPath: string;
|
|
367
|
+
/** if this is a valid template string */
|
|
368
|
+
valid: boolean;
|
|
369
|
+
};
|
|
349
370
|
//# sourceMappingURL=types.d.ts.map
|
package/build/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as t from '@babel/types';
|
|
2
2
|
import { NodePath } from '@babel/core';
|
|
3
|
-
import { AstContext, ClassPropertyContext, ClassPropertyContexts, ClassPropertyNodes, ImplicitConsumption, ImportMetadata, ModuleMetadata, ValidGetterContext, ValidTemplateContext } from './types';
|
|
3
|
+
import { AstContext, ClassPropertyContext, ClassPropertyContexts, ClassPropertyNodes, GqlMetadata, ImplicitConsumption, ImportMetadata, ModuleMetadata, ValidGetterContext, ValidTemplateContext } from './types';
|
|
4
4
|
import { Adg, FunctionType, KomaciDocument } from '@komaci/types';
|
|
5
5
|
export declare const LIGHTNING_NS = "lightning";
|
|
6
6
|
export declare const FORCE_NS = "force";
|
|
@@ -172,4 +172,27 @@ export declare function getComponentId(namespace: string, name: string): string;
|
|
|
172
172
|
* @param moduleMetadata the module metadata object.
|
|
173
173
|
*/
|
|
174
174
|
export declare function setGetterPropertyTypeBeforeProcessing(properties: NodePath<t.ClassMethod>[], adgIndex: number, moduleMetadata: ModuleMetadata): void;
|
|
175
|
+
/**
|
|
176
|
+
* Helper function to generate a key to retrieve a gql metadata object based on the start and
|
|
177
|
+
* end field on the TemplateLiteral Object. Luvio metadata privodes a start and end field which
|
|
178
|
+
* coorelates to the start and end position of a templateLiteral on a taggedTemplate Expression.
|
|
179
|
+
* @param start the start field which correlates to the index of the starting character on the TemplateLiteral object in a TaggedTemplate which.
|
|
180
|
+
* @param end the end field which correlatest to the index of the ending character on the TemplateLiteral object in a TaggedTemplate
|
|
181
|
+
* @returns the key
|
|
182
|
+
*/
|
|
183
|
+
export declare function generateLocationKey(start: number, end: number): string;
|
|
184
|
+
/**
|
|
185
|
+
* Function to validate gql tagged template expressions.
|
|
186
|
+
* @param taggedTemplateExpression the tagged template expression to evaluate
|
|
187
|
+
* @param moduleMetadata the module metadata object
|
|
188
|
+
* @returns true or false if the gql query is valid
|
|
189
|
+
*/
|
|
190
|
+
export declare function validateTaggedTemplateExpression(taggedTemplateExpression: t.TaggedTemplateExpression, moduleMetadata: ModuleMetadata): boolean;
|
|
191
|
+
/**
|
|
192
|
+
* Get a Gql Metadata object based on a tagged templates tempalte literal
|
|
193
|
+
* @param taggedTmplQuasi a tagged templates template literal
|
|
194
|
+
* @param gqlMetadata the gql metadata map
|
|
195
|
+
* @returns the Gql Metadata object or undefined.
|
|
196
|
+
*/
|
|
197
|
+
export declare function getGqlMetadataForTaggedTemplate(taggedTmplQuasi: t.TemplateLiteral, gqlMetadata: Map<string, GqlMetadata>): GqlMetadata | undefined;
|
|
175
198
|
//# sourceMappingURL=utils.d.ts.map
|
package/build/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setGetterPropertyTypeBeforeProcessing = exports.getComponentId = exports.getFilepathSegments = exports.addPropertyFunction = exports.updateKomaciDocumentWithValidTemplatedStrings = exports.updateKomaciDocumentWithValidGetters = exports.isDeclaredInAst = exports.isExpressionThisOrAlias = exports.getThisAliasDeclaredInFunction = exports.isPropertyNodeUsed = exports.isGetterNodeUsed = exports.isPropertyUsed = exports.getClassMethodName = exports.getVariablesDeclaredInFunction = 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;
|
|
3
|
+
exports.getGqlMetadataForTaggedTemplate = exports.validateTaggedTemplateExpression = exports.generateLocationKey = exports.setGetterPropertyTypeBeforeProcessing = exports.getComponentId = exports.getFilepathSegments = exports.addPropertyFunction = exports.updateKomaciDocumentWithValidTemplatedStrings = exports.updateKomaciDocumentWithValidGetters = exports.isDeclaredInAst = exports.isExpressionThisOrAlias = exports.getThisAliasDeclaredInFunction = exports.isPropertyNodeUsed = exports.isGetterNodeUsed = exports.isPropertyUsed = exports.getClassMethodName = exports.getVariablesDeclaredInFunction = 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;
|
|
4
4
|
const core_1 = require("@babel/core");
|
|
5
5
|
const types_1 = require("./types");
|
|
6
6
|
const allowlistNamespaces_1 = require("./allowlistNamespaces");
|
|
@@ -86,6 +86,12 @@ function implicitConsumptionMetadata(node, adgIndex, moduleMetadata) {
|
|
|
86
86
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
87
87
|
moduleMetadata.adgs.get(adgIndex).properties);
|
|
88
88
|
},
|
|
89
|
+
TaggedTemplateExpression(path) {
|
|
90
|
+
const taggedTmplExpr = path.node;
|
|
91
|
+
if (validateTaggedTemplateExpression(taggedTmplExpr, moduleMetadata)) {
|
|
92
|
+
path.stop();
|
|
93
|
+
}
|
|
94
|
+
},
|
|
89
95
|
};
|
|
90
96
|
node.traverse(Visitors);
|
|
91
97
|
return { identifiers: Array.from(identifiers) };
|
|
@@ -554,4 +560,50 @@ function setGetterPropertyTypeBeforeProcessing(properties, adgIndex, moduleMetad
|
|
|
554
560
|
});
|
|
555
561
|
}
|
|
556
562
|
exports.setGetterPropertyTypeBeforeProcessing = setGetterPropertyTypeBeforeProcessing;
|
|
563
|
+
/**
|
|
564
|
+
* Helper function to generate a key to retrieve a gql metadata object based on the start and
|
|
565
|
+
* end field on the TemplateLiteral Object. Luvio metadata privodes a start and end field which
|
|
566
|
+
* coorelates to the start and end position of a templateLiteral on a taggedTemplate Expression.
|
|
567
|
+
* @param start the start field which correlates to the index of the starting character on the TemplateLiteral object in a TaggedTemplate which.
|
|
568
|
+
* @param end the end field which correlatest to the index of the ending character on the TemplateLiteral object in a TaggedTemplate
|
|
569
|
+
* @returns the key
|
|
570
|
+
*/
|
|
571
|
+
function generateLocationKey(start, end) {
|
|
572
|
+
return `loc_${start}_${end}`;
|
|
573
|
+
}
|
|
574
|
+
exports.generateLocationKey = generateLocationKey;
|
|
575
|
+
/**
|
|
576
|
+
* Function to validate gql tagged template expressions.
|
|
577
|
+
* @param taggedTemplateExpression the tagged template expression to evaluate
|
|
578
|
+
* @param moduleMetadata the module metadata object
|
|
579
|
+
* @returns true or false if the gql query is valid
|
|
580
|
+
*/
|
|
581
|
+
function validateTaggedTemplateExpression(taggedTemplateExpression, moduleMetadata) {
|
|
582
|
+
const taggedTmplQuasi = taggedTemplateExpression.quasi;
|
|
583
|
+
const gqlMetadata = getGqlMetadataForTaggedTemplate(taggedTmplQuasi, moduleMetadata.gqlMetadata);
|
|
584
|
+
if (gqlMetadata) {
|
|
585
|
+
if (!gqlMetadata.hasExpressions) {
|
|
586
|
+
gqlMetadata.valid = true;
|
|
587
|
+
return true;
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
return false;
|
|
591
|
+
}
|
|
592
|
+
exports.validateTaggedTemplateExpression = validateTaggedTemplateExpression;
|
|
593
|
+
/**
|
|
594
|
+
* Get a Gql Metadata object based on a tagged templates tempalte literal
|
|
595
|
+
* @param taggedTmplQuasi a tagged templates template literal
|
|
596
|
+
* @param gqlMetadata the gql metadata map
|
|
597
|
+
* @returns the Gql Metadata object or undefined.
|
|
598
|
+
*/
|
|
599
|
+
function getGqlMetadataForTaggedTemplate(taggedTmplQuasi, gqlMetadata) {
|
|
600
|
+
if (taggedTmplQuasi && taggedTmplQuasi.start && taggedTmplQuasi.end) {
|
|
601
|
+
const start = taggedTmplQuasi.start;
|
|
602
|
+
const end = taggedTmplQuasi.end;
|
|
603
|
+
const locationKey = generateLocationKey(start, end);
|
|
604
|
+
return gqlMetadata.get(locationKey);
|
|
605
|
+
}
|
|
606
|
+
return undefined;
|
|
607
|
+
}
|
|
608
|
+
exports.getGqlMetadataForTaggedTemplate = getGqlMetadataForTaggedTemplate;
|
|
557
609
|
//# sourceMappingURL=utils.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@komaci/common-shared",
|
|
3
|
-
"version": "248.1.
|
|
3
|
+
"version": "248.1.3",
|
|
4
4
|
"description": "Assets that are shared across Komaci commonjs packages",
|
|
5
5
|
"homepage": "https://komaci.dev/",
|
|
6
6
|
"repository": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"build/komaci-mapping.json"
|
|
30
30
|
],
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@komaci/types": "248.1.
|
|
32
|
+
"@komaci/types": "248.1.3"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@babel/core": "^7.9.0",
|