Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/FraunhoferIOSB/AASPo…
Browse files Browse the repository at this point in the history
…rtal into development
  • Loading branch information
ralfaron committed Aug 2, 2024
2 parents 3021d2a + 90f70c4 commit a8eb3db
Show file tree
Hide file tree
Showing 10 changed files with 227 additions and 151 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"Qualifiable",
"rechtlich",
"selbstaendige",
"Sematics",
"submodel",
"tsoa",
"tsyringe",
Expand Down
5 changes: 1 addition & 4 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@
"node_modules/bootstrap-icons/font/bootstrap-icons.min.css",
"projects/aas-portal/src/styles.scss"
],
"scripts": [],
"allowedCommonJsDependencies": [
"lodash-es"
]
"scripts": []
},
"configurations": {
"production": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aas-portal-project",
"version": "3.0.0-development.69",
"version": "3.0.0-development.70",
"description": "Web-based visualization and control of asset administration shells.",
"type": "module",
"scripts": {
Expand Down
31 changes: 31 additions & 0 deletions projects/aas-core/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import {
Blob,
Entity,
Environment,
HasSemantics,
Identifiable,
MultiLanguageProperty,
Property,
Referable,
Reference,
ReferenceElement,
RelationshipElement,
Submodel,
Expand Down Expand Up @@ -121,6 +123,35 @@ export function equalArray<T>(a: T[], b: T[]): boolean {
return a.every((_, i) => a[i] === b[i]);
}

/**
* Determines whether the specified value is of type `HasSemantics`.
* @param value The current value.
* @returns `true` if the specified value is of type `HasSemantics`; otherwise, `false`.
*/
export function isReference(value: unknown): value is Reference {
if (!value || typeof value !== 'object') {
return false;
}

return typeof (value as Reference).type === 'string' && Array.isArray((value as Reference).keys);
}

/**
* Determines whether the specified value is of type `HasSemantics`.
* @param value The current value.
* @returns `true` if the specified value is of type `HasSemantics`; otherwise, `false`.
*/
export function isHasSemantics(value: unknown): value is HasSemantics {
if (!value || typeof value !== 'object') {
return false;
}

return (
isReference((value as HasSemantics).semanticId) ||
Array.isArray((value as HasSemantics).supplementalSemanticIds)
);
}

/**
* Determines whether the specified value represents a submodel element.
* @param value The current value.
Expand Down
51 changes: 51 additions & 0 deletions projects/aas-core/src/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import {
getEndpointType,
isAssetAdministrationShell,
isBlob,
isHasSemantics,
isMultiLanguageProperty,
isProperty,
isReference,
isReferenceElement,
isSubmodel,
isSubmodelElement,
Expand All @@ -27,6 +29,7 @@ import {
isValidPassword,
stringFormat,
} from '../lib/index.js';
import { HasSemantics, Reference } from '../lib/aas.js';

describe('index', () => {
describe('isSubmodelElement', () => {
Expand Down Expand Up @@ -355,4 +358,52 @@ describe('index', () => {
expect(getEndpointType('file:///endpoints/samples')).toEqual('FileSystem');
});
});

describe('isReference', () => {
it('indicates that value is of type reference', () => {
const value: Reference = {
keys: [],
type: 'ExternalReference',
};

expect(isReference(value)).toBeTruthy();
});

it('indicates that "{}" is not of type Reference', () => {
expect(isReference({})).toBeFalsy();
});

it('indicates that "undefined" is not of type Reference', () => {
expect(isReference(undefined)).toBeFalsy();
});

it('indicates that "null" is not of type Reference', () => {
expect(isReference(null)).toBeFalsy();
});
});

describe('isHasSemantics', () => {
it('indicates that value is of type HasSemantics', () => {
const value: HasSemantics = {
semanticId: {
keys: [],
type: 'ExternalReference',
},
};

expect(isHasSemantics(value)).toBeTruthy();
});

it('indicates that "{}" is not of type HasSemantics', () => {
expect(isHasSemantics({})).toBeFalsy();
});

it('indicates that "undefined" is not of type HasSemantics', () => {
expect(isHasSemantics(undefined)).toBeFalsy();
});

it('indicates that "null" is not of type HasSemantics', () => {
expect(isHasSemantics(null)).toBeFalsy();
});
});
});
Loading

0 comments on commit a8eb3db

Please sign in to comment.