1 /* eslint-disable @typescript-eslint/no-loss-of-precision */
2 /* eslint-disable @typescript-eslint/no-unused-expressions */
3 /* eslint-disable @typescript-eslint/naming-convention */
5 * ============LICENSE_START========================================================================
6 * ONAP : ccsdk feature sdnr wt odlux
7 * =================================================================================================
8 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
9 * =================================================================================================
10 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
11 * in compliance with the License. You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software distributed under the License
16 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
17 * or implied. See the License for the specific language governing permissions and limitations under
19 * ============LICENSE_END==========================================================================
21 import { Token, Statement, Module, Identity, ModuleState } from '../models/yang';
32 isViewElementObjectOrList,
38 } from '../models/uiModels';
39 import { yangService } from '../services/yangService';
41 const LOGLEVEL = +(localStorage.getItem('log.odlux.app.configuration.yang.yangParser') || 0);
43 import { LogLevel } from '../../../../framework/src/utilities/logLevel';
44 import { parseWhen, WhenAST, WhenTokenType } from './whenParser';
46 export const splitVPath = (vPath: string, vPathParser: RegExp): RegExpMatchArray[] => {
47 const pathParts: RegExpMatchArray[] = [];
48 let partMatch: RegExpExecArray | null;
50 partMatch = vPathParser.exec(vPath);
52 pathParts.push(partMatch);
60 private pos: number = 0;
62 private buf: string = '';
64 constructor(input: string) {
69 private _opTable: { [key: string]: string } = {
75 private _isNewline(char: string): boolean {
76 return char === '\r' || char === '\n';
79 private _isWhitespace(char: string): boolean {
80 return char === ' ' || char === '\t' || this._isNewline(char);
83 private _isDigit(char: string): boolean {
84 return char >= '0' && char <= '9';
87 private _isAlpha(char: string): boolean {
88 return (char >= 'a' && char <= 'z') ||
89 (char >= 'A' && char <= 'Z');
92 private _isAlphanum(char: string): boolean {
93 return this._isAlpha(char) || this._isDigit(char) ||
94 char === '_' || char === '-' || char === '.';
97 private _skipNonTokens() {
98 while (this.pos < this.buf.length) {
99 const char = this.buf.charAt(this.pos);
100 if (this._isWhitespace(char)) {
108 private _processString(terminator: string | null): Token {
109 // this.pos points at the opening quote. Find the ending quote.
110 let end_index = this.pos + 1;
111 while (end_index < this.buf.length) {
112 const char = this.buf.charAt(end_index);
117 if (terminator === null && (this._isWhitespace(char) || this._opTable[char] !== undefined) || char === terminator) {
123 if (end_index >= this.buf.length) {
124 throw Error('Unterminated quote at ' + this.pos);
126 const start = this.pos + (terminator ? 1 : 0);
127 const end = end_index;
130 value: this.buf.substring(start, end),
134 this.pos = terminator ? end + 1 : end;
139 private _processIdentifier(): Token {
140 let endpos = this.pos + 1;
141 while (endpos < this.buf.length && this._isAlphanum(this.buf.charAt(endpos))) {
145 let name = 'IDENTIFIER';
146 if (this.buf.charAt(endpos) === ':') {
147 name = 'IDENTIFIERREF';
149 while (endpos < this.buf.length && this._isAlphanum(this.buf.charAt(endpos))) {
156 value: this.buf.substring(this.pos, endpos),
165 private _processNumber(): Token {
166 let endpos = this.pos + 1;
167 while (endpos < this.buf.length &&
168 this._isDigit(this.buf.charAt(endpos))) {
174 value: this.buf.substring(this.pos, endpos),
182 private _processLineComment() {
183 var endpos = this.pos + 2;
184 // Skip until the end of the line
185 while (endpos < this.buf.length && !this._isNewline(this.buf.charAt(endpos))) {
188 this.pos = endpos + 1;
191 private _processBlockComment() {
192 var endpos = this.pos + 2;
193 // Skip until the end of the line
194 while (endpos < this.buf.length && !((this.buf.charAt(endpos) === '/' && this.buf.charAt(endpos - 1) === '*'))) {
197 this.pos = endpos + 1;
200 public tokenize(): Token[] {
201 const result: Token[] = [];
202 this._skipNonTokens();
203 while (this.pos < this.buf.length) {
205 const char = this.buf.charAt(this.pos);
206 const op = this._opTable[char];
208 if (op !== undefined) {
209 result.push({ name: op, value: char, start: this.pos, end: ++this.pos });
210 } else if (this._isAlpha(char)) {
211 result.push(this._processIdentifier());
212 this._skipNonTokens();
213 const peekChar = this.buf.charAt(this.pos);
214 if (this._opTable[peekChar] === undefined) {
215 result.push((peekChar !== '\'' && peekChar !== '"')
216 ? this._processString(null)
217 : this._processString(peekChar));
219 } else if (char === '/' && this.buf.charAt(this.pos + 1) === '/') {
220 this._processLineComment();
221 } else if (char === '/' && this.buf.charAt(this.pos + 1) === '*') {
222 this._processBlockComment();
224 throw Error('Token error at ' + this.pos + ' ' + this.buf[this.pos]);
226 this._skipNonTokens();
231 public tokenize2(): Statement {
232 let stack: Statement[] = [{ key: 'ROOT', sub: [] }];
233 let current: Statement | null = null;
235 this._skipNonTokens();
236 while (this.pos < this.buf.length) {
238 const char = this.buf.charAt(this.pos);
239 const op = this._opTable[char];
241 if (op !== undefined) {
242 if (op === 'L_BRACE') {
243 current && stack.unshift(current);
245 } else if (op === 'R_BRACE') {
246 current = stack.shift() || null;
249 } else if (this._isAlpha(char) || char === '_') {
250 const key = this._processIdentifier().value;
251 this._skipNonTokens();
252 let peekChar = this.buf.charAt(this.pos);
254 if (this._opTable[peekChar] === undefined) {
255 arg = (peekChar === '"' || peekChar === '\'')
256 ? this._processString(peekChar).value
257 : this._processString(null).value;
260 this._skipNonTokens();
261 peekChar = this.buf.charAt(this.pos);
262 if (peekChar !== '+') break;
264 this._skipNonTokens();
265 peekChar = this.buf.charAt(this.pos);
266 arg += (peekChar === '"' || peekChar === '\'')
267 ? this._processString(peekChar).value
268 : this._processString(null).value;
270 current = { key, arg, sub: [] };
271 stack[0].sub!.push(current);
272 } else if (char === '/' && this.buf.charAt(this.pos + 1) === '/') {
273 this._processLineComment();
274 } else if (char === '/' && this.buf.charAt(this.pos + 1) === '*') {
275 this._processBlockComment();
277 throw Error('Token error at ' + this.pos + ' ' + this.buf.slice(this.pos - 10, this.pos + 10));
279 this._skipNonTokens();
281 if (stack[0].key !== 'ROOT' || !stack[0].sub![0]) {
282 throw new Error('Internal Perser Error');
284 return stack[0].sub![0];
288 export class YangParser {
289 private _groupingsToResolve: ViewSpecification[] = [];
291 private _typeRefToResolve: (() => void)[] = [];
293 private _identityToResolve: (() => void)[] = [];
295 private _unionsToResolve: (() => void)[] = [];
297 private _modulesToResolve: (() => void)[] = [];
299 private _modules: { [name: string]: Module } = {};
301 private _views: ViewSpecification[] = [{
312 public static ResolveStack = Symbol('ResolveStack');
315 private nodeId: string,
316 private _capabilityRevisionMap: { [capability: string]: string } = {},
317 private _unavailableCapabilities: { failureReason: string; capability: string }[] = [],
318 private _importOnlyModules: { name: string; revision: string }[] = [],
323 public get modules() {
324 return this._modules;
331 public async addCapability(capability: string, version?: string, parentImportOnlyModule?: boolean) {
333 const existingCapability = this._modules[capability];
334 const latestVersionExisting = existingCapability && Object.keys(existingCapability.revisions).sort().reverse()[0];
335 if ((latestVersionExisting && version) && (version <= latestVersionExisting)) {
336 if (LOGLEVEL == LogLevel.Warning) {
337 console.warn(`Skipped capability: ${capability}:${version || ''} since already contained.`);
342 // // do not add unavailable capabilities
343 // if (this._unavailableCapabilities.some(c => c.capability === capability)) {
344 // // console.warn(`Skipped capability: ${capability} since it is marked as unavailable.` );
348 const data = await yangService.getCapability(capability, this.nodeId, version);
350 throw new Error(`Could not load yang file for ${capability}:${version || ''}.`);
353 const rootStatement = new YangLexer(data).tokenize2();
355 if (rootStatement.key !== 'module') {
356 throw new Error(`Root element of ${capability} is not a module.`);
358 if (rootStatement.arg !== capability) {
359 throw new Error(`Root element capability ${rootStatement.arg} does not requested ${capability}.`);
362 const isUnavailable = this._unavailableCapabilities.some(c => c.capability === capability);
363 const isImportOnly = parentImportOnlyModule === true || this._importOnlyModules.some(c => c.name === capability);
366 const revisions = this.extractNodes(rootStatement, 'revision').reduce<{ [version: string]: {} }>((acc, revision) => {
368 throw new Error(`Module [${rootStatement.arg}] has a version w/o version number.`);
370 const description = this.extractValue(revision, 'description');
371 const reference = this.extractValue(revision, 'reference');
372 acc[revision.arg] = {
379 const latestVersionLoaded = Object.keys(revisions).sort().reverse()[0];
380 if (existingCapability && latestVersionExisting >= latestVersionLoaded) {
381 if (LOGLEVEL == LogLevel.Warning) {
382 console.warn(`Skipped capability: ${capability}:${latestVersionLoaded} since ${capability}:${latestVersionExisting} already contained.`);
387 const module = this._modules[capability] = {
388 name: rootStatement.arg,
399 ? ModuleState.unavailable
401 ? ModuleState.importOnly
402 : ModuleState.stable,
405 await this.handleModule(module, rootStatement, capability);
408 private async handleModule(module: Module, rootStatement: Statement, capability: string) {
410 // extract namespace && prefix
411 module.namespace = this.extractValue(rootStatement, 'namespace');
412 module.prefix = this.extractValue(rootStatement, 'prefix');
414 module.imports[module.prefix] = capability;
418 const features = this.extractNodes(rootStatement, 'feature');
421 ...features.reduce<{ [version: string]: {} }>((acc, feature) => {
423 throw new Error(`Module [${module.name}] has a feature w/o name.`);
425 const description = this.extractValue(feature, 'description');
434 const imports = this.extractNodes(rootStatement, 'import');
437 ...imports.reduce<{ [key: string]: string }>((acc, imp) => {
438 const prefix = imp.sub && imp.sub.filter(s => s.key === 'prefix');
440 throw new Error(`Module [${module.name}] has an import with neither name nor prefix.`);
442 acc[prefix && prefix.length === 1 && prefix[0].arg || imp.arg] = imp.arg;
447 // import all required files and set module state
448 if (imports) for (let ind = 0; ind < imports.length; ++ind) {
449 const moduleName = imports[ind].arg!;
451 const revision = this._capabilityRevisionMap[moduleName] || undefined;
452 await this.addCapability(moduleName, revision, module.state === ModuleState.importOnly);
453 const importedModule = this._modules[imports[ind].arg!];
454 if (importedModule && importedModule.state > ModuleState.stable) {
455 module.state = Math.max(module.state, ModuleState.instable);
459 this.extractTypeDefinitions(rootStatement, module, '');
461 this.extractIdentities(rootStatement, 0, module, '');
463 const groupings = this.extractGroupings(rootStatement, 0, module, '');
464 this._views.push(...groupings);
466 const augments = this.extractAugments(rootStatement, 0, module, '');
467 this._views.push(...augments);
469 // the default for config on module level is config = true;
470 const [currentView, subViews] = this.extractSubViews(rootStatement, 0, module, '');
471 this._views.push(currentView, ...subViews);
473 // create the root elements for this module
474 module.elements = currentView.elements;
475 this._modulesToResolve.push(() => {
476 Object.keys(module.elements).forEach(key => {
477 const viewElement = module.elements[key];
478 if (!(isViewElementObjectOrList(viewElement) || isViewElementRpc(viewElement))) {
479 console.error(new Error(`Module: [${module}]. Only Object, List or RPC are allowed on root level.`));
481 if (isViewElementObjectOrList(viewElement)) {
482 const viewIdIndex = Number(viewElement.viewId);
483 module.views[key] = this._views[viewIdIndex];
486 // add only the UI View if the module is available
487 if (module.state === ModuleState.stable || module.state === ModuleState.instable) this._views[0].elements[key] = module.elements[key];
493 public postProcess() {
495 // execute all post processes like resolving in proper order
496 this._unionsToResolve.forEach(cb => {
497 try { cb(); } catch (error) {
498 console.warn(error.message);
502 // process all groupings
503 this._groupingsToResolve.filter(vs => vs.uses && vs.uses[ResolveFunction]).forEach(vs => {
504 try { vs.uses![ResolveFunction] !== undefined && vs.uses![ResolveFunction]!('|'); } catch (error) {
505 console.warn(`Error resolving: [${vs.name}] [${error.message}]`);
510 * This is to fix the issue for sequential execution of modules based on their child and parent relationship
511 * We are sorting the module object based on their augment status
513 Object.keys(this.modules)
515 if (this.modules[elem].augments && Object.keys(this.modules[elem].augments).length > 0) {
516 const { augments, ..._rest } = this.modules[elem];
517 const partsOfKeys = Object.keys(augments).map((key) => (key.split('/').length - 1));
518 this.modules[elem].executionOrder = Math.max(...partsOfKeys);
520 this.modules[elem].executionOrder = 0;
524 // process all augmentations / sort by namespace changes to ensure proper order
525 Object.keys(this.modules).sort((a, b) => this.modules[a].executionOrder! - this.modules[b].executionOrder!).forEach(modKey => {
526 const module = this.modules[modKey];
527 const augmentKeysWithCounter = Object.keys(module.augments).map((key) => {
528 const pathParts = splitVPath(key, /(?:(?:([^\/\:]+):)?([^\/]+))/g); // 1 = opt: namespace / 2 = property
529 let nameSpaceChangeCounter = 0;
530 let currentNS = module.name; // init namespace
531 pathParts.forEach(([ns, _]) => {
532 if (ns === currentNS) {
534 nameSpaceChangeCounter++;
539 nameSpaceChangeCounter,
543 const augmentKeys = augmentKeysWithCounter
544 .sort((a, b) => a.nameSpaceChangeCounter > b.nameSpaceChangeCounter ? 1 : a.nameSpaceChangeCounter === b.nameSpaceChangeCounter ? 0 : -1)
547 augmentKeys.forEach(augKey => {
548 const augments = module.augments[augKey];
549 const viewSpec = this.resolveView(augKey);
550 if (!viewSpec) console.warn(`Could not find view to augment [${augKey}] in [${module.name}].`);
551 if (augments && viewSpec) {
552 augments.forEach(augment => Object.keys(augment.elements).forEach(key => {
553 const elm = augment.elements[key];
555 const when = elm.when && augment.when
557 type: WhenTokenType.AND,
561 : elm.when || augment.when;
563 const ifFeature = elm.ifFeature
564 ? `(${augment.ifFeature}) and (${elm.ifFeature})`
567 viewSpec.elements[key] = {
568 ...augment.elements[key],
577 // process Identities
578 const traverseIdentity = (identities: Identity[]) => {
579 const result: Identity[] = [];
580 for (let identity of identities) {
581 if (identity.children && identity.children.length > 0) {
582 result.push(...traverseIdentity(identity.children));
584 result.push(identity);
590 const baseIdentities: Identity[] = [];
591 Object.keys(this.modules).forEach(modKey => {
592 const module = this.modules[modKey];
593 Object.keys(module.identities).forEach(idKey => {
594 const identity = module.identities[idKey];
595 if (identity.base != null) {
596 const base = this.resolveIdentity(identity.base, module);
597 base.children?.push(identity);
599 baseIdentities.push(identity);
603 baseIdentities.forEach(identity => {
604 identity.values = identity.children && traverseIdentity(identity.children) || [];
607 this._identityToResolve.forEach(cb => {
608 try { cb(); } catch (error) {
609 console.warn(error.message);
613 this._typeRefToResolve.forEach(cb => {
614 try { cb(); } catch (error) {
615 console.warn(error.message);
619 this._modulesToResolve.forEach(cb => {
620 try { cb(); } catch (error) {
621 console.warn(error.message);
626 const resolveReadOnly = (view: ViewSpecification, parentConfig: boolean) => {
628 // update view config
629 view.config = view.config && parentConfig;
631 Object.keys(view.elements).forEach((key) => {
632 const elm = view.elements[key];
634 // update element config
635 elm.config = elm.config && view.config;
637 // update all sub-elements of objects
638 if (elm.uiType === 'object') {
639 resolveReadOnly(this.views[+elm.viewId], elm.config);
645 const dump = resolveReadOnly(this.views[0], true);
647 console.log('Resolved views:', dump);
653 private get nextId() {
654 return this._nextId++;
657 private extractNodes(statement: Statement, key: string): Statement[] {
658 return statement.sub && statement.sub.filter(s => s.key === key) || [];
661 private extractValue(statement: Statement, key: string): string | undefined;
662 private extractValue(statement: Statement, key: string, parser: RegExp): RegExpExecArray | undefined;
663 private extractValue(statement: Statement, key: string, parser?: RegExp): string | RegExpExecArray | undefined {
664 const typeNodes = this.extractNodes(statement, key);
665 const rawValue = typeNodes.length > 0 && typeNodes[0].arg || undefined;
667 ? rawValue && parser.exec(rawValue) || undefined
671 private extractTypeDefinitions(statement: Statement, module: Module, currentPath: string): void {
672 const typedefs = this.extractNodes(statement, 'typedef');
673 typedefs && typedefs.forEach(def => {
675 throw new Error(`Module: [${module.name}]. Found typedef without name.`);
677 module.typedefs[def.arg] = this.getViewElement(def, module, 0, currentPath, false);
681 /** Handles groupings like named Container */
682 private extractGroupings(statement: Statement, parentId: number, module: Module, currentPath: string): ViewSpecification[] {
683 const subViews: ViewSpecification[] = [];
684 const groupings = this.extractNodes(statement, 'grouping');
685 if (groupings && groupings.length > 0) {
686 subViews.push(...groupings.reduce<ViewSpecification[]>((acc, cur) => {
688 throw new Error(`Module: [${module.name}][${currentPath}]. Found grouping without name.`);
690 const grouping = cur.arg;
692 // the default for config on module level is config = true;
693 const [currentView, currentSubViews] = this.extractSubViews(cur, /* parentId */ -1, module, currentPath);
694 grouping && (module.groupings[grouping] = currentView);
695 acc.push(currentView, ...currentSubViews);
703 /** Handles augments also like named container */
704 private extractAugments(statement: Statement, parentId: number, module: Module, currentPath: string): ViewSpecification[] {
705 const subViews: ViewSpecification[] = [];
706 const augments = this.extractNodes(statement, 'augment');
707 if (augments && augments.length > 0) {
708 subViews.push(...augments.reduce<ViewSpecification[]>((acc, cur) => {
710 throw new Error(`Module: [${module.name}][${currentPath}]. Found augment without path.`);
712 const augment = this.resolveReferencePath(cur.arg, module);
714 // the default for config on module level is config = true;
715 const [currentView, currentSubViews] = this.extractSubViews(cur, parentId, module, currentPath);
717 module.augments[augment] = module.augments[augment] || [];
718 module.augments[augment].push(currentView);
720 acc.push(currentView, ...currentSubViews);
728 /** Handles identities */
729 private extractIdentities(statement: Statement, parentId: number, module: Module, currentPath: string) {
730 const identities = this.extractNodes(statement, 'identity');
731 module.identities = identities.reduce<{ [name: string]: Identity }>((acc, cur) => {
733 throw new Error(`Module: [${module.name}][${currentPath}]. Found identity without name.`);
736 id: `${module.name}:${cur.arg}`,
738 base: this.extractValue(cur, 'base'),
739 description: this.extractValue(cur, 'description'),
740 reference: this.extractValue(cur, 'reference'),
747 // Hint: use 0 as parentId for rootElements and -1 for rootGroupings.
748 private extractSubViews(statement: Statement, parentId: number, module: Module, currentPath: string): [ViewSpecification, ViewSpecification[]] {
749 // used for scoped definitions
750 const context: Module = {
757 const currentId = this.nextId;
758 const subViews: ViewSpecification[] = [];
759 let elements: ViewElement[] = [];
761 const configValue = this.extractValue(statement, 'config');
762 const config = configValue == null ? true : configValue.toLocaleLowerCase() !== 'false';
764 // extract conditions
765 const ifFeature = this.extractValue(statement, 'if-feature');
766 const whenCondition = this.extractValue(statement, 'when');
767 if (whenCondition) console.warn('Found in [' + context.name + ']' + currentPath + ' when: ' + whenCondition);
769 // extract all scoped typedefs
770 this.extractTypeDefinitions(statement, context, currentPath);
772 // extract all scoped groupings
774 ...this.extractGroupings(statement, parentId, context, currentPath),
777 // extract all container
778 const container = this.extractNodes(statement, 'container');
779 if (container && container.length > 0) {
780 subViews.push(...container.reduce<ViewSpecification[]>((acc, cur) => {
782 throw new Error(`Module: [${context.name}]${currentPath}. Found container without name.`);
784 const [currentView, currentSubViews] = this.extractSubViews(cur, currentId, context, `${currentPath}/${context.name}:${cur.arg}`);
786 id: parentId === 0 ? `${context.name}:${cur.arg}` : cur.arg,
789 module: context.name || module.name || '',
791 viewId: currentView.id,
792 config: currentView.config,
794 acc.push(currentView, ...currentSubViews);
800 // a list is a list of containers with the leafs contained in the list
801 const lists = this.extractNodes(statement, 'list');
802 if (lists && lists.length > 0) {
803 subViews.push(...lists.reduce<ViewSpecification[]>((acc, cur) => {
804 let elmConfig = config;
806 throw new Error(`Module: [${context.name}]${currentPath}. Found list without name.`);
808 const key = this.extractValue(cur, 'key') || undefined;
809 if (elmConfig && !key) {
810 console.warn(`Module: [${context.name}]${currentPath}. Found configurable list without key. Assume config shell be false.`);
813 const [currentView, currentSubViews] = this.extractSubViews(cur, currentId, context, `${currentPath}/${context.name}:${cur.arg}`);
815 id: parentId === 0 ? `${context.name}:${cur.arg}` : cur.arg,
818 module: context.name || module.name || '',
821 viewId: currentView.id,
823 config: elmConfig && currentView.config,
825 acc.push(currentView, ...currentSubViews);
830 // process all leaf-lists
831 // a leaf-list is a list of some type
832 const leafLists = this.extractNodes(statement, 'leaf-list');
833 if (leafLists && leafLists.length > 0) {
834 elements.push(...leafLists.reduce<ViewElement[]>((acc, cur) => {
835 const element = this.getViewElement(cur, context, parentId, currentPath, true);
836 element && acc.push(element);
842 // a leaf is mainly a property of an object
843 const leafs = this.extractNodes(statement, 'leaf');
844 if (leafs && leafs.length > 0) {
845 elements.push(...leafs.reduce<ViewElement[]>((acc, cur) => {
846 const element = this.getViewElement(cur, context, parentId, currentPath, false);
847 element && acc.push(element);
853 const choiceStms = this.extractNodes(statement, 'choice');
854 if (choiceStms && choiceStms.length > 0) {
855 elements.push(...choiceStms.reduce<ViewElementChoice[]>((accChoice, curChoice) => {
856 if (!curChoice.arg) {
857 throw new Error(`Module: [${context.name}]${currentPath}. Found choise without name.`);
859 // extract all cases like containers
860 const cases: { id: string; label: string; description?: string; elements: { [name: string]: ViewElement } }[] = [];
861 const caseStms = this.extractNodes(curChoice, 'case');
862 if (caseStms && caseStms.length > 0) {
863 cases.push(...caseStms.reduce((accCase, curCase) => {
865 throw new Error(`Module: [${context.name}]${currentPath}/${curChoice.arg}. Found case without name.`);
867 const description = this.extractValue(curCase, 'description') || undefined;
868 const [caseView, caseSubViews] = this.extractSubViews(curCase, parentId, context, `${currentPath}/${context.name}:${curChoice.arg}`);
869 subViews.push(caseView, ...caseSubViews);
871 const caseDef: { id: string; label: string; description?: string; elements: { [name: string]: ViewElement } } = {
872 id: parentId === 0 ? `${context.name}:${curCase.arg}` : curCase.arg,
874 description: description,
875 elements: caseView.elements,
877 accCase.push(caseDef);
879 }, [] as { id: string; label: string; description?: string; elements: { [name: string]: ViewElement } }[]));
882 // extract all simple cases (one case per leaf, container, etc.)
883 const [choiceView, choiceSubViews] = this.extractSubViews(curChoice, parentId, context, `${currentPath}/${context.name}:${curChoice.arg}`);
884 subViews.push(choiceView, ...choiceSubViews);
885 cases.push(...Object.keys(choiceView.elements).reduce((accElm, curElm) => {
886 const elm = choiceView.elements[curElm];
887 const caseDef: { id: string; label: string; description?: string; elements: { [name: string]: ViewElement } } = {
890 description: elm.description,
891 elements: { [elm.id]: elm },
893 accElm.push(caseDef);
895 }, [] as { id: string; label: string; description?: string; elements: { [name: string]: ViewElement } }[]));
897 const choiceDescription = this.extractValue(curChoice, 'description') || undefined;
898 const choiceConfigValue = this.extractValue(curChoice, 'config');
899 const choiceConfig = choiceConfigValue == null ? true : choiceConfigValue.toLocaleLowerCase() !== 'false';
901 const mandatory = this.extractValue(curChoice, 'mandatory') === 'true' || false;
903 const element: ViewElementChoice = {
905 id: parentId === 0 ? `${context.name}:${curChoice.arg}` : curChoice.arg,
906 label: curChoice.arg,
908 module: context.name || module.name || '',
909 config: choiceConfig,
910 mandatory: mandatory,
911 description: choiceDescription,
912 cases: cases.reduce((acc, cur) => {
915 }, {} as { [name: string]: { id: string; label: string; description?: string; elements: { [name: string]: ViewElement } } }),
918 accChoice.push(element);
923 const rpcStms = this.extractNodes(statement, 'rpc');
924 if (rpcStms && rpcStms.length > 0) {
925 elements.push(...rpcStms.reduce<ViewElementRpc[]>((accRpc, curRpc) => {
927 throw new Error(`Module: [${context.name}]${currentPath}. Found rpc without name.`);
930 const rpcDescription = this.extractValue(curRpc, 'description') || undefined;
931 const rpcConfigValue = this.extractValue(curRpc, 'config');
932 const rpcConfig = rpcConfigValue == null ? true : rpcConfigValue.toLocaleLowerCase() !== 'false';
934 let inputViewId: string | undefined = undefined;
935 let outputViewId: string | undefined = undefined;
937 const input = this.extractNodes(curRpc, 'input') || undefined;
938 const output = this.extractNodes(curRpc, 'output') || undefined;
940 if (input && input.length > 0) {
941 const [inputView, inputSubViews] = this.extractSubViews(input[0], parentId, context, `${currentPath}/${context.name}:${curRpc.arg}`);
942 subViews.push(inputView, ...inputSubViews);
943 inputViewId = inputView.id;
946 if (output && output.length > 0) {
947 const [outputView, outputSubViews] = this.extractSubViews(output[0], parentId, context, `${currentPath}/${context.name}:${curRpc.arg}`);
948 subViews.push(outputView, ...outputSubViews);
949 outputViewId = outputView.id;
952 const element: ViewElementRpc = {
954 id: parentId === 0 ? `${context.name}:${curRpc.arg}` : curRpc.arg,
957 module: context.name || module.name || '',
959 description: rpcDescription,
960 inputViewId: inputViewId,
961 outputViewId: outputViewId,
964 accRpc.push(element);
970 if (!statement.arg) {
971 console.error(new Error(`Module: [${context.name}]. Found statement without name.`));
974 let whenParsed: WhenAST | undefined = undefined;
976 whenParsed = whenCondition && parseWhen(whenCondition) || undefined;
978 console.error(new Error(`Module: [${context.name}]. Found invalid when condition: ${whenCondition}`));
981 const viewSpec: ViewSpecification = {
982 id: String(currentId),
983 parentView: String(parentId),
985 name: statement.arg != null ? statement.arg : undefined,
986 title: statement.arg != null ? statement.arg : undefined,
990 ifFeature: ifFeature,
992 elements: elements.reduce<{ [name: string]: ViewElement }>((acc, cur) => {
998 // evaluate canEdit depending on all conditions
999 Object.defineProperty(viewSpec, 'canEdit', {
1001 return Object.keys(viewSpec.elements).some(key => {
1002 const elm = viewSpec.elements[key];
1003 return (!isViewElementObjectOrList(elm) && elm.config);
1008 // merge in all uses references and resolve groupings
1009 const usesRefs = this.extractNodes(statement, 'uses');
1010 if (usesRefs && usesRefs.length > 0) {
1012 viewSpec.uses = (viewSpec.uses || []);
1013 const resolveFunctions: ((parentElementPath: string) => void)[] = [];
1015 for (let i = 0; i < usesRefs.length; ++i) {
1016 const groupingName = usesRefs[i].arg;
1017 if (!groupingName) {
1018 throw new Error(`Module: [${context.name}]. Found an uses statement without a grouping name.`);
1021 viewSpec.uses.push(this.resolveReferencePath(groupingName, context));
1023 resolveFunctions.push((parentElementPath: string) => {
1024 const groupingViewSpec = this.resolveGrouping(groupingName, context);
1025 if (groupingViewSpec) {
1027 // resolve recursive
1028 const resolveFunc = groupingViewSpec.uses && groupingViewSpec.uses[ResolveFunction];
1029 resolveFunc && resolveFunc(parentElementPath);
1031 Object.keys(groupingViewSpec.elements).forEach(key => {
1032 const elm = groupingViewSpec.elements[key];
1033 // a useRef on root level need a namespace
1034 const resolvedWhen = elm.when && groupingViewSpec.when
1036 type: WhenTokenType.AND,
1038 right: groupingViewSpec.when,
1040 : elm.when || groupingViewSpec.when;
1042 const resolvedIfFeature = elm.ifFeature
1043 ? `(${groupingViewSpec.ifFeature}) and (${elm.ifFeature})`
1044 : groupingViewSpec.ifFeature;
1046 viewSpec.elements[parentId === 0 ? `${module.name}:${key}` : key] = {
1049 ifFeature: resolvedIfFeature,
1056 viewSpec.uses[ResolveFunction] = (parentElementPath: string) => {
1057 const currentElementPath = `${parentElementPath} -> ${viewSpec.ns}:${viewSpec.name}`;
1058 resolveFunctions.forEach(resolve => {
1060 resolve(currentElementPath);
1062 console.error(error);
1065 // console.log("Resolved "+currentElementPath, viewSpec);
1066 if (viewSpec?.uses) {
1067 viewSpec.uses[ResolveFunction] = undefined;
1071 this._groupingsToResolve.push(viewSpec);
1074 return [viewSpec, subViews];
1077 // https://tools.ietf.org/html/rfc7950#section-9.3.4
1078 private static decimalRange = [
1079 { min: -9223372036854775808, max: 9223372036854775807 },
1080 { min: -922337203685477580.8, max: 922337203685477580.7 },
1081 { min: -92233720368547758.08, max: 92233720368547758.07 },
1082 { min: -9223372036854775.808, max: 9223372036854775.807 },
1083 { min: -922337203685477.5808, max: 922337203685477.5807 },
1084 { min: -92233720368547.75808, max: 92233720368547.75807 },
1085 { min: -9223372036854.775808, max: 9223372036854.775807 },
1086 { min: -922337203685.4775808, max: 922337203685.4775807 },
1087 { min: -92233720368.54775808, max: 92233720368.54775807 },
1088 { min: -9223372036.854775808, max: 9223372036.854775807 },
1089 { min: -922337203.6854775808, max: 922337203.6854775807 },
1090 { min: -92233720.36854775808, max: 92233720.36854775807 },
1091 { min: -9223372.036854775808, max: 9223372.036854775807 },
1092 { min: -922337.2036854775808, max: 922337.2036854775807 },
1093 { min: -92233.72036854775808, max: 92233.72036854775807 },
1094 { min: -9223.372036854775808, max: 9223.372036854775807 },
1095 { min: -922.3372036854775808, max: 922.3372036854775807 },
1096 { min: -92.23372036854775808, max: 92.23372036854775807 },
1097 { min: -9.223372036854775808, max: 9.223372036854775807 },
1100 /** Extracts the UI View from the type in the cur statement. */
1101 private getViewElement(cur: Statement, module: Module, parentId: number, currentPath: string, isList: boolean): ViewElement {
1103 const type = this.extractValue(cur, 'type');
1104 const defaultVal = this.extractValue(cur, 'default') || undefined;
1105 const description = this.extractValue(cur, 'description') || undefined;
1107 const configValue = this.extractValue(cur, 'config');
1108 const config = configValue == null ? true : configValue.toLocaleLowerCase() !== 'false';
1110 const extractRange = (min: number, max: number, property: string = 'range'): { expression: Expression<YangRange> | undefined; min: number; max: number } => {
1111 const ranges = this.extractValue(this.extractNodes(cur, 'type')[0]!, property) || undefined;
1112 const range = ranges?.replace(/min/i, String(min)).replace(/max/i, String(max)).split('|').map(r => {
1113 let minValue: number;
1114 let maxValue: number;
1116 if (r.indexOf('..') > -1) {
1117 const [minStr, maxStr] = r.split('..');
1118 minValue = Number(minStr);
1119 maxValue = Number(maxStr);
1120 } else if (!isNaN(maxValue = Number(r && r.trim()))) {
1121 minValue = maxValue;
1127 if (minValue > min) min = minValue;
1128 if (maxValue < max) max = maxValue;
1138 expression: range && range.length === 1
1140 : range && range.length > 1
1141 ? { operation: 'OR', arguments: range }
1146 const extractPattern = (): Expression<RegExp> | undefined => {
1147 // 2023.01.26 decision MF & SKO: we will no longer remove the backslashes from the pattern, seems to be a bug in the original code
1148 const pattern = this.extractNodes(this.extractNodes(cur, 'type')[0]!, 'pattern').map(p => p.arg!).filter(p => !!p).map(p => `^${p/*.replace(/(?:\\(.))/g, '$1')*/}$`);
1149 return pattern && pattern.length == 1
1150 ? new RegExp(pattern[0])
1151 : pattern && pattern.length > 1
1152 ? { operation: 'AND', arguments: pattern.map(p => new RegExp(p)) }
1156 const mandatory = this.extractValue(cur, 'mandatory') === 'true' || false;
1159 throw new Error(`Module: [${module.name}]. Found element without name.`);
1163 throw new Error(`Module: [${module.name}].[${cur.arg}]. Found element without type.`);
1166 const element: ViewElementBase = {
1167 id: parentId === 0 ? `${module.name}:${cur.arg}` : cur.arg,
1170 module: module.name || '',
1172 mandatory: mandatory,
1174 default: defaultVal,
1175 description: description,
1178 if (type === 'string') {
1179 const length = extractRange(0, +18446744073709551615, 'length');
1183 length: length.expression,
1184 pattern: extractPattern(),
1186 } else if (type === 'boolean') {
1191 } else if (type === 'uint8') {
1192 const range = extractRange(0, +255);
1196 range: range.expression,
1199 units: this.extractValue(cur, 'units') || undefined,
1200 format: this.extractValue(cur, 'format') || undefined,
1202 } else if (type === 'uint16') {
1203 const range = extractRange(0, +65535);
1207 range: range.expression,
1210 units: this.extractValue(cur, 'units') || undefined,
1211 format: this.extractValue(cur, 'format') || undefined,
1213 } else if (type === 'uint32') {
1214 const range = extractRange(0, +4294967295);
1218 range: range.expression,
1221 units: this.extractValue(cur, 'units') || undefined,
1222 format: this.extractValue(cur, 'format') || undefined,
1224 } else if (type === 'uint64') {
1225 const range = extractRange(0, +18446744073709551615);
1229 range: range.expression,
1232 units: this.extractValue(cur, 'units') || undefined,
1233 format: this.extractValue(cur, 'format') || undefined,
1235 } else if (type === 'int8') {
1236 const range = extractRange(-128, +127);
1240 range: range.expression,
1243 units: this.extractValue(cur, 'units') || undefined,
1244 format: this.extractValue(cur, 'format') || undefined,
1246 } else if (type === 'int16') {
1247 const range = extractRange(-32768, +32767);
1251 range: range.expression,
1254 units: this.extractValue(cur, 'units') || undefined,
1255 format: this.extractValue(cur, 'format') || undefined,
1257 } else if (type === 'int32') {
1258 const range = extractRange(-2147483648, +2147483647);
1262 range: range.expression,
1265 units: this.extractValue(cur, 'units') || undefined,
1266 format: this.extractValue(cur, 'format') || undefined,
1268 } else if (type === 'int64') {
1269 const range = extractRange(-9223372036854775808, +9223372036854775807);
1273 range: range.expression,
1276 units: this.extractValue(cur, 'units') || undefined,
1277 format: this.extractValue(cur, 'format') || undefined,
1279 } else if (type === 'decimal64') {
1281 const fDigits = Number(this.extractValue(this.extractNodes(cur, 'type')[0]!, 'fraction-digits')) || -1;
1282 if (fDigits === -1) {
1283 throw new Error(`Module: [${module.name}][${currentPath}][${cur.arg}]. Found decimal64 with invalid fraction-digits.`);
1285 const range = extractRange(YangParser.decimalRange[fDigits].min, YangParser.decimalRange[fDigits].max);
1290 range: range.expression,
1293 units: this.extractValue(cur, 'units') || undefined,
1294 format: this.extractValue(cur, 'format') || undefined,
1296 } else if (type === 'enumeration') {
1297 const typeNode = this.extractNodes(cur, 'type')[0]!;
1298 const enumNodes = this.extractNodes(typeNode, 'enum');
1301 uiType: 'selection',
1302 options: enumNodes.reduce<{ key: string; value: string; description?: string }[]>((acc, enumNode) => {
1303 if (!enumNode.arg) {
1304 throw new Error(`Module: [${module.name}][${currentPath}][${cur.arg}]. Found option without name.`);
1306 // const ifClause = this.extractValue(enumNode, 'if-feature');
1307 const value = this.extractValue(enumNode, 'value');
1308 const enumOption = {
1310 value: value != null ? value : enumNode.arg,
1311 description: this.extractValue(enumNode, 'description') || undefined,
1313 // todo: ❗ handle the if clause ⚡
1314 acc.push(enumOption);
1318 } else if (type === 'leafref') {
1319 const typeNode = this.extractNodes(cur, 'type')[0]!;
1320 const vPath = this.extractValue(typeNode, 'path');
1322 throw new Error(`Module: [${module.name}][${currentPath}][${cur.arg}]. Found leafref without path.`);
1324 const refPath = this.resolveReferencePath(vPath, module);
1325 const resolve = this.resolveReference.bind(this);
1326 const res: ViewElement = {
1328 uiType: 'reference',
1329 referencePath: refPath,
1330 ref(this: ViewElement, basePath: string) {
1331 const elementPath = `${basePath}/${cur.arg}`;
1333 const result = resolve(refPath, elementPath);
1334 if (!result) return undefined;
1336 const [resolvedElement, resolvedPath] = result;
1337 return resolvedElement && [{
1341 config: this.config,
1342 mandatory: this.mandatory,
1343 isList: this.isList,
1344 default: this.default,
1345 description: this.description,
1346 } as ViewElement, resolvedPath] || undefined;
1350 } else if (type === 'identityref') {
1351 const typeNode = this.extractNodes(cur, 'type')[0]!;
1352 const base = this.extractValue(typeNode, 'base');
1354 throw new Error(`Module: [${module.name}][${currentPath}][${cur.arg}]. Found identityref without base.`);
1356 const res: ViewElement = {
1358 uiType: 'selection',
1361 this._identityToResolve.push(() => {
1362 const identity: Identity = this.resolveIdentity(base, module);
1364 throw new Error(`Module: [${module.name}][${currentPath}][${cur.arg}]. Could not resolve identity [${base}].`);
1366 if (!identity.values || identity.values.length === 0) {
1367 throw new Error(`Identity: [${base}] has no values.`);
1369 res.options = identity.values.map(val => ({
1372 description: val.description,
1376 } else if (type === 'empty') {
1377 // todo: ❗ handle empty ⚡
1378 /* 9.11. The empty Built-In Type
1379 The empty built-in type represents a leaf that does not have any
1380 value, it conveys information by its presence or absence. */
1385 } else if (type === 'union') {
1386 // todo: ❗ handle union ⚡
1387 /* 9.12. The union Built-In Type */
1388 const typeNode = this.extractNodes(cur, 'type')[0]!;
1389 const typeNodes = this.extractNodes(typeNode, 'type');
1391 const resultingElement = {
1395 } as ViewElementUnion;
1397 const resolveUnion = () => {
1398 resultingElement.elements.push(...typeNodes.map(node => {
1399 const stm: Statement = {
1402 ...(cur.sub?.filter(s => s.key !== 'type') || []),
1407 ...this.getViewElement(stm, module, parentId, currentPath, isList),
1413 this._unionsToResolve.push(resolveUnion);
1415 return resultingElement;
1416 } else if (type === 'bits') {
1417 const typeNode = this.extractNodes(cur, 'type')[0]!;
1418 const bitNodes = this.extractNodes(typeNode, 'bit');
1422 flags: bitNodes.reduce<{ [name: string]: number | undefined }>((acc, bitNode) => {
1424 throw new Error(`Module: [${module.name}][${currentPath}][${cur.arg}]. Found bit without name.`);
1426 // const ifClause = this.extractValue(bitNode, 'if-feature');
1427 const pos = Number(this.extractValue(bitNode, 'position'));
1428 acc[bitNode.arg] = pos === pos ? pos : undefined;
1432 } else if (type === 'binary') {
1436 length: extractRange(0, +18446744073709551615, 'length'),
1438 } else if (type === 'instance-identifier') {
1439 // https://tools.ietf.org/html/rfc7950#page-168
1443 length: extractRange(0, +18446744073709551615, 'length'),
1446 // not a build in type, need to resolve type
1447 let typeRef = this.resolveType(type, module);
1448 if (typeRef == null) console.error(new Error(`Could not resolve type ${type} in [${module.name}][${currentPath}].`));
1450 if (isViewElementString(typeRef)) {
1451 typeRef = this.resolveStringType(typeRef, extractPattern(), extractRange(0, +18446744073709551615));
1452 } else if (isViewElementNumber(typeRef)) {
1453 typeRef = this.resolveNumberType(typeRef, extractRange(typeRef.min, typeRef.max));
1460 this._typeRefToResolve.push(() => {
1461 // spoof date type here from special string type
1462 if ((type === 'date-and-time' || type.endsWith(':date-and-time')) && typeRef.module === 'ietf-yang-types') {
1463 Object.assign(res, {
1466 description: description,
1470 Object.assign(res, {
1473 description: description,
1482 private resolveStringType(parentElement: ViewElementString, pattern: Expression<RegExp> | undefined, length: { expression: Expression<YangRange> | undefined; min: number; max: number }) {
1485 pattern: pattern != null && parentElement.pattern
1486 ? { operation: 'AND', arguments: [pattern, parentElement.pattern] }
1487 : parentElement.pattern
1488 ? parentElement.pattern
1490 length: length.expression != null && parentElement.length
1491 ? { operation: 'AND', arguments: [length.expression, parentElement.length] }
1492 : parentElement.length
1493 ? parentElement.length
1494 : length?.expression,
1495 } as ViewElementString;
1498 private resolveNumberType(parentElement: ViewElementNumber, range: { expression: Expression<YangRange> | undefined; min: number; max: number }) {
1501 range: range.expression != null && parentElement.range
1502 ? { operation: 'AND', arguments: [range.expression, parentElement.range] }
1503 : parentElement.range
1504 ? parentElement.range
1508 } as ViewElementNumber;
1511 private resolveReferencePath(vPath: string, module: Module) {
1512 const vPathParser = /(?:(?:([^\/\:]+):)?([^\/]+))/g; // 1 = opt: namespace / 2 = property
1513 return vPath.replace(vPathParser, (_, ns, property) => {
1514 const nameSpace = ns && module.imports[ns] || module.name;
1515 return `${nameSpace}:${property}`;
1519 private resolveReference(vPath: string, currentPath: string) {
1520 const vPathParser = /(?:(?:([^\/\[\]\:]+):)?([^\/\[\]]+)(\[[^\]]+\])?)/g; // 1 = opt: namespace / 2 = property / 3 = opt: indexPath
1521 let element: ViewElement | null = null;
1522 let moduleName = '';
1524 const vPathParts = splitVPath(vPath, vPathParser).map(p => ({ ns: p[1], property: p[2], ind: p[3] }));
1525 const resultPathParts = !vPath.startsWith('/')
1526 ? splitVPath(currentPath, vPathParser).map(p => { moduleName = p[1] || moduleName; return { ns: moduleName, property: p[2], ind: p[3] }; })
1529 for (let i = 0; i < vPathParts.length; ++i) {
1530 const vPathPart = vPathParts[i];
1531 if (vPathPart.property === '..') {
1532 resultPathParts.pop();
1533 } else if (vPathPart.property !== '.') {
1534 resultPathParts.push(vPathPart);
1538 // resolve element by path
1539 for (let j = 0; j < resultPathParts.length; ++j) {
1540 const pathPart = resultPathParts[j];
1542 moduleName = pathPart.ns;
1543 const rootModule = this._modules[moduleName];
1544 if (!rootModule) throw new Error('Could not resolve module [' + moduleName + '].\r\n' + vPath);
1545 element = rootModule.elements[`${pathPart.ns}:${pathPart.property}`];
1546 } else if (element && isViewElementObjectOrList(element)) {
1547 const view: ViewSpecification = this._views[+element.viewId];
1548 if (moduleName !== pathPart.ns) {
1549 moduleName = pathPart.ns;
1551 element = view.elements[pathPart.property] || view.elements[`${moduleName}:${pathPart.property}`];
1553 throw new Error('Could not resolve reference.\r\n' + vPath);
1555 if (!element) throw new Error('Could not resolve path [' + pathPart.property + '] in [' + currentPath + '] \r\n' + vPath);
1558 moduleName = ''; // create the vPath for the resolved element, do not add the element itself this will be done later in the res(...) function
1559 return [element, resultPathParts.slice(0, -1).map(p => `${moduleName !== p.ns ? `${moduleName = p.ns}:` : ''}${p.property}${p.ind || ''}`).join('/')];
1562 private resolveView(vPath: string) {
1563 const vPathParser = /(?:(?:([^\/\[\]\:]+):)?([^\/\[\]]+)(\[[^\]]+\])?)/g; // 1 = opt: namespace / 2 = property / 3 = opt: indexPath
1564 let element: ViewElement | null = null;
1565 let partMatch: RegExpExecArray | null;
1566 let view: ViewSpecification | null = null;
1567 let moduleName = '';
1569 partMatch = vPathParser.exec(vPath);
1571 if (element === null) {
1572 moduleName = partMatch[1]!;
1573 const rootModule = this._modules[moduleName];
1574 if (!rootModule) return null;
1575 element = rootModule.elements[`${moduleName}:${partMatch[2]!}`];
1576 } else if (isViewElementObjectOrList(element)) {
1577 view = this._views[+element.viewId];
1578 if (moduleName !== partMatch[1]) {
1579 moduleName = partMatch[1];
1580 element = view.elements[`${moduleName}:${partMatch[2]}`];
1582 element = view.elements[partMatch[2]];
1587 if (!element) return null;
1589 } while (partMatch);
1590 return element && isViewElementObjectOrList(element) && this._views[+element.viewId] || null;
1593 private resolveType(type: string, module: Module) {
1594 const colonInd = type.indexOf(':');
1595 const preFix = colonInd > -1 ? type.slice(0, colonInd) : '';
1596 const typeName = colonInd > -1 ? type.slice(colonInd + 1) : type;
1599 ? this._modules[module.imports[preFix]].typedefs[typeName]
1600 : module.typedefs[typeName];
1604 private resolveGrouping(grouping: string, module: Module) {
1605 const collonInd = grouping.indexOf(':');
1606 const preFix = collonInd > -1 ? grouping.slice(0, collonInd) : '';
1607 const groupingName = collonInd > -1 ? grouping.slice(collonInd + 1) : grouping;
1610 ? this._modules[module.imports[preFix]].groupings[groupingName]
1611 : module.groupings[groupingName];
1615 private resolveIdentity(identity: string, module: Module) {
1616 const collonInd = identity.indexOf(':');
1617 const preFix = collonInd > -1 ? identity.slice(0, collonInd) : '';
1618 const identityName = collonInd > -1 ? identity.slice(collonInd + 1) : identity;
1621 ? this._modules[module.imports[preFix]].identities[identityName]
1622 : module.identities[identityName];