From b243cbc45c291c21c54422ec24731687396468da Mon Sep 17 00:00:00 2001 From: jagzmz Date: Sun, 17 Nov 2024 21:23:23 +0530 Subject: [PATCH 1/2] Update runtime verb parameters --- .gitignore | 1 + src/SklEngine.ts | 38 ++++++++++++++++++++++++++++++++++++-- src/util/Vocabularies.ts | 8 ++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 28985ef..c75052f 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ rmlmapper-5.0.0-r362-all.jar tmp comake-skl-js-engine-*.tgz test/deploy/package-lock.json +.env \ No newline at end of file diff --git a/src/SklEngine.ts b/src/SklEngine.ts index 2fafddf..fa6be96 100644 --- a/src/SklEngine.ts +++ b/src/SklEngine.ts @@ -53,7 +53,7 @@ import { getValueIfDefined, ensureArray, } from './util/Util'; -import { SKL, SHACL, RDFS, SKL_ENGINE, XSD, RDF } from './util/Vocabularies'; +import { SKL, SHACL, RDFS, SKL_ENGINE, XSD, RDF, SKLSO_PROPERTY, SKLSO_DATA_NAMESPACE } from './util/Vocabularies'; import { GroupByOptions, GroupByResponse } from './storage/GroupOptionTypes'; import { AxiosRequestConfig } from 'axios'; @@ -630,15 +630,49 @@ export class SKLEngine { return args; } + + + private replaceTypeAndId(entity: Record): Record { + if (typeof entity !== 'object') { + throw new Error('Entity is not an object'); + } + const clonedEntity = structuredClone(entity); + if (clonedEntity[SKLSO_PROPERTY.type]) { + clonedEntity['@type'] = clonedEntity[SKLSO_PROPERTY.type]; + } + if (clonedEntity[SKLSO_PROPERTY.identifier]) { + clonedEntity['@id'] = SKLSO_DATA_NAMESPACE + clonedEntity[SKLSO_PROPERTY.identifier]; + } + return clonedEntity; + } + private async updateEntityFromVerbArgs(args: Record): Promise { - await this.update(args.id ?? args.ids, args.attributes); + let ids = args.id ?? args.ids; + if (!Array.isArray(ids)) { + ids = [ids]; + } + ids = ids.map((id: string) => `${SKLSO_DATA_NAMESPACE}${id}`); + await this.update(ids, args.attributes); } private async saveEntityOrEntitiesFromVerbArgs(args: Record): Promise> { + + if (args.entity && typeof args.entity === 'object') { + args.entity = this.replaceTypeAndId(args.entity); + } + if (args.entities && Array.isArray(args.entities)) { + args.entities = args.entities.map(this.replaceTypeAndId); + } return await this.save(args.entity ?? args.entities); } private async destroyEntityOrEntitiesFromVerbArgs(args: Record): Promise> { + if (args.entity && typeof args.entity === 'object') { + args.entity = this.replaceTypeAndId(args.entity); + } + if (args.entities && Array.isArray(args.entities)) { + args.entities = args.entities.map(this.replaceTypeAndId); + } return await this.destroy(args.entity ?? args.entities); } diff --git a/src/util/Vocabularies.ts b/src/util/Vocabularies.ts index aba1fff..5317017 100644 --- a/src/util/Vocabularies.ts +++ b/src/util/Vocabularies.ts @@ -97,6 +97,14 @@ export const SKL = createNamespace(SKL_NAMESPACE, [ 'headers', ]); +export const SKLSO_DATA_NAMESPACE = 'https://skl.so/d/'; + +export const SKLSO_PROPERTY_NAMESPACE = 'https://skl.so/p/'; +export const SKLSO_PROPERTY = createNamespace(SKLSO_PROPERTY_NAMESPACE, [ + 'type', + 'identifier', +]); + export const SKL_ENGINE_NAMESPACE = 'https://standardknowledge.com/ontologies/skl-engine/'; export const SKL_ENGINE = createNamespace(SKL_ENGINE_NAMESPACE, [ 'update', From bcd446508a70c3cc429ee0c5d3e2dba7388e8f08 Mon Sep 17 00:00:00 2001 From: jagzmz Date: Sun, 17 Nov 2024 21:26:24 +0530 Subject: [PATCH 2/2] Update patch version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0816eaf..a1e4a72 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@comake/skl-js-engine", - "version": "0.25.0", + "version": "0.25.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@comake/skl-js-engine", - "version": "0.25.0", + "version": "0.25.1", "license": "BSD-4-Clause", "dependencies": { "@comake/openapi-operation-executor": "^0.12.1", diff --git a/package.json b/package.json index e4d1ae0..425aee4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@comake/skl-js-engine", - "version": "0.25.0", + "version": "0.25.1", "description": "Standard Knowledge Language Javascript Engine", "keywords": [ "skl",