diff --git a/lib/package-lock.json b/lib/package-lock.json new file mode 100644 index 0000000..028d722 --- /dev/null +++ b/lib/package-lock.json @@ -0,0 +1,63 @@ +{ + "name": "prototyp", + "version": "1.0.0", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "prototyp", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "@aas-core-works/aas-core3.0rc02-typescript": "^1.0.0-rc.6" + }, + "devDependencies": { + "@types/node": "^20.8.2", + "typescript": "^5.2.2" + } + }, + "node_modules/@aas-core-works/aas-core3.0rc02-typescript": { + "version": "1.0.0-rc.6", + "resolved": "https://registry.npmjs.org/@aas-core-works/aas-core3.0rc02-typescript/-/aas-core3.0rc02-typescript-1.0.0-rc.6.tgz", + "integrity": "sha512-dNdGOmetHzk5CqRUYNHcjufOe7qFnsvAch5ETgM/49lXf7PSbeYST/Z0MHpUHOkcLagtTUYN5dgj88mQTPUftw==" + }, + "node_modules/@types/node": { + "version": "20.8.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.8.2.tgz", + "integrity": "sha512-Vvycsc9FQdwhxE3y3DzeIxuEJbWGDsnrxvMADzTDF/lcdR9/K+AQIeAghTQsHtotg/q0j3WEOYS/jQgSdWue3w==", + "dev": true + }, + "node_modules/typescript": { + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", + "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + } + }, + "dependencies": { + "@aas-core-works/aas-core3.0rc02-typescript": { + "version": "1.0.0-rc.6", + "resolved": "https://registry.npmjs.org/@aas-core-works/aas-core3.0rc02-typescript/-/aas-core3.0rc02-typescript-1.0.0-rc.6.tgz", + "integrity": "sha512-dNdGOmetHzk5CqRUYNHcjufOe7qFnsvAch5ETgM/49lXf7PSbeYST/Z0MHpUHOkcLagtTUYN5dgj88mQTPUftw==" + }, + "@types/node": { + "version": "20.8.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.8.2.tgz", + "integrity": "sha512-Vvycsc9FQdwhxE3y3DzeIxuEJbWGDsnrxvMADzTDF/lcdR9/K+AQIeAghTQsHtotg/q0j3WEOYS/jQgSdWue3w==", + "dev": true + }, + "typescript": { + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", + "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", + "dev": true + } + } +} diff --git a/package.json b/lib/package.json similarity index 69% rename from package.json rename to lib/package.json index 46cbd6b..0271d0c 100644 --- a/package.json +++ b/lib/package.json @@ -10,6 +10,10 @@ "author": "", "license": "ISC", "devDependencies": { + "@types/node": "^20.8.2", "typescript": "^5.2.2" + }, + "dependencies": { + "@aas-core-works/aas-core3.0rc02-typescript": "^1.0.0-rc.6" } } diff --git a/lib/src/aasStore.ts b/lib/src/aasStore.ts new file mode 100644 index 0000000..e92c27a --- /dev/null +++ b/lib/src/aasStore.ts @@ -0,0 +1,36 @@ +import { types } from "@aas-core-works/aas-core3.0rc02-typescript"; + +export class AASStore { + private static instance: AASStore; + private shells: Array = []; + + private constructor() { } + + public static getInstance(): AASStore { + if (!AASStore.instance) { + AASStore.instance = new AASStore(); + } + + return AASStore.instance; + } + + public addAAS(aas: types.AssetAdministrationShell | types.Environment): void { + if (aas instanceof types.Environment) { + if (aas.assetAdministrationShells) this.shells = this.shells.concat(aas.assetAdministrationShells); + } else { + this.shells.push(aas); + } + } + + public getAAS(id: string): types.AssetAdministrationShell | undefined { + return this.shells.find((aas) => aas.id === id); + } + + public removeAAS(id: string): void { + this.shells = this.shells.filter((aas) => aas.id !== id); + } + + public getAll(): Array { + return this.shells; + } +} \ No newline at end of file diff --git a/lib/src/index.ts b/lib/src/index.ts new file mode 100644 index 0000000..e69de29 diff --git a/lib/src/interfaceConnectionObject.ts b/lib/src/interfaceConnectionObject.ts new file mode 100644 index 0000000..41b5738 --- /dev/null +++ b/lib/src/interfaceConnectionObject.ts @@ -0,0 +1,29 @@ +import type { types } from "@aas-core-works/aas-core3.0rc02-typescript"; + +type ConnectionType = "ON_DEMAND" | "PERMANENT"; + +export abstract class InterfaceConnectionObject { + public abstract readonly name: string; + public abstract readonly connectionType: ConnectionType; + public abstract readonly supportsSubscriptions: boolean; + + public abstract connect(): boolean; + + public abstract disconnect(): void; + + public abstract readProperty(prop: types.Property): void; + + public abstract writeProperty(prop: types.Property, value: any): void; + + public abstract observeProperty(prop: types.Property, callback: (value: any) => void): boolean; + + public abstract callActionSync(action: types.Operation, args: types.OperationVariable[]): any; + + public abstract callActionAsync(action: types.Operation, args: types.OperationVariable[]): Promise; + + public abstract readAsyncActionResponse(action: types.Operation): Promise; + + public abstract subscribeEvent(callback: (event: types.BasicEventElement) => void): boolean; + + public abstract unsubscribeEvent(): void; +} \ No newline at end of file diff --git a/lib/src/parser/aasParser.ts b/lib/src/parser/aasParser.ts new file mode 100644 index 0000000..09d4ab0 --- /dev/null +++ b/lib/src/parser/aasParser.ts @@ -0,0 +1,7 @@ +import type { types } from "@aas-core-works/aas-core3.0rc02-typescript"; + +type AASParsingType = types.Environment | types.AssetAdministrationShell | types.Submodel; + +export interface Parser { + parse(): T | T[]; +} diff --git a/lib/src/parser/helper.ts b/lib/src/parser/helper.ts new file mode 100644 index 0000000..cc1061c --- /dev/null +++ b/lib/src/parser/helper.ts @@ -0,0 +1,21 @@ +import { readdir, readFile } from "fs/promises"; + +export async function getAllAASFiles(aasPath: string): Promise { + const files = await readdir(aasPath); + return files.filter(file => file.endsWith(".json")).map(file => `${aasPath}/${file}`); +} + +export async function getAASFileContent(aasPath: string): Promise { + const content = await readFile(aasPath, { encoding: "utf-8" }); + return content; +} + +export async function getAllAASFileContents(aasPath: string): Promise { + const files = await getAllAASFiles(aasPath) + const content = []; + for (const file of files) { + content.push(await getAASFileContent(file)); + } + + return content; +} \ No newline at end of file diff --git a/lib/src/parser/requestParser.ts b/lib/src/parser/requestParser.ts new file mode 100644 index 0000000..5e09418 --- /dev/null +++ b/lib/src/parser/requestParser.ts @@ -0,0 +1,12 @@ +import type { types } from "@aas-core-works/aas-core3.0rc02-typescript"; + +type AASRequestType = types.Environment | types.Submodel; +type AASResponseType = types.BasicEventElement | types.ValueList; + +interface RequestTransformer { + transform(request: T): U; +} + +interface NorthboundResponseTransformer { + transform(response: T): U; +} \ No newline at end of file diff --git a/lib/src/server.ts b/lib/src/server.ts new file mode 100644 index 0000000..2d9e5e4 --- /dev/null +++ b/lib/src/server.ts @@ -0,0 +1,12 @@ +type ServerConfig = { + bindName: string; + bindPort: number; +} + +export abstract class AASInterfaceServer { + public abstract readonly name: string; + public abstract config: ServerConfig; + + public abstract prepare(): void; + public abstract run(): void; +} \ No newline at end of file diff --git a/tsconfig.json b/lib/tsconfig.json similarity index 97% rename from tsconfig.json rename to lib/tsconfig.json index 44693e4..f0261ab 100644 --- a/tsconfig.json +++ b/lib/tsconfig.json @@ -27,9 +27,11 @@ /* Modules */ "module": "es2022", /* Specify what module code is generated. */ "rootDir": "./src", /* Specify the root folder within your source files. */ - // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ - // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ - // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ + "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ + "baseUrl": "src", /* Specify the base directory to resolve non-relative module names. */ + "paths": { + "types/*": ["types/*"] + }, /* Specify a set of entries that re-map imports to additional lookup locations. */ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ // "types": [], /* Specify type package names to be included without being referenced in a source file. */ diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index 2dbd34a..0000000 --- a/package-lock.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "name": "prototyp", - "version": "1.0.0", - "lockfileVersion": 2, - "requires": true, - "packages": { - "": { - "name": "prototyp", - "version": "1.0.0", - "license": "ISC", - "devDependencies": { - "typescript": "^5.2.2" - } - }, - "node_modules/typescript": { - "version": "5.2.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", - "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", - "dev": true, - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=14.17" - } - } - }, - "dependencies": { - "typescript": { - "version": "5.2.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", - "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", - "dev": true - } - } -}