From dfbc54193fd05cd0fa26ca445604eef82a01ef61 Mon Sep 17 00:00:00 2001 From: Brad Banister Date: Mon, 30 Oct 2023 14:38:37 -0500 Subject: [PATCH] [RND-623] fix superclass info extractor bug --- Meadowlark-js/.vscode/launch.json | 15 +++++++++ .../src/extraction/SuperclassInfoExtractor.ts | 31 ++++++++++++++++--- .../src/model/api-schema/ResourceSchema.ts | 4 +-- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/Meadowlark-js/.vscode/launch.json b/Meadowlark-js/.vscode/launch.json index 47e3b5bd..217f528b 100644 --- a/Meadowlark-js/.vscode/launch.json +++ b/Meadowlark-js/.vscode/launch.json @@ -27,6 +27,21 @@ "internalConsoleOptions": "neverOpen", "port": 9229 }, + { + "name": "Jest :: File Linux e2e", + "type": "node", + "request": "launch", + "runtimeArgs": [ + "--inspect-brk", + "${workspaceRoot}/node_modules/.bin/jest", + "--runInBand", + "${relativeFile}", + ], + "env": {"FASTIFY_PORT": "3000", "ADMIN_KEY": "9970b045-f6fe-45b3-bda6-8bcef95695c8", "ADMIN_SECRET": "bf083bde5435ee3318cd741b1dbee86c610b6c7cdee04d5a364a3f2b98a4ad66" }, + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen", + "port": 9229 + }, { "type": "node", "request": "launch", diff --git a/Meadowlark-js/packages/meadowlark-core/src/extraction/SuperclassInfoExtractor.ts b/Meadowlark-js/packages/meadowlark-core/src/extraction/SuperclassInfoExtractor.ts index f8ff64bf..2c3641e4 100644 --- a/Meadowlark-js/packages/meadowlark-core/src/extraction/SuperclassInfoExtractor.ts +++ b/Meadowlark-js/packages/meadowlark-core/src/extraction/SuperclassInfoExtractor.ts @@ -3,7 +3,8 @@ // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. -import { DocumentIdentity } from '../model/DocumentIdentity'; +import invariant from 'ts-invariant'; +import { DocumentIdentity, DocumentIdentityElement } from '../model/DocumentIdentity'; import { SuperclassInfo } from '../model/SuperclassInfo'; import type { ResourceSchema } from '../model/api-schema/ResourceSchema'; @@ -33,11 +34,31 @@ export function deriveSuperclassInfoFrom( } // Copy the DocumentIdentity so the original is not affected - const superclassIdentity: DocumentIdentity = { ...documentIdentity }; + const superclassIdentity: DocumentIdentity = [...documentIdentity]; - // Replace subclassIdentityFullname with superclassIdentityFullname - delete superclassIdentity[resourceSchema.subclassIdentityFullname]; - superclassIdentity[resourceSchema.superclassIdentityFullname] = documentIdentity[resourceSchema.subclassIdentityFullname]; + // Find location of element for rename + const indexForRename = superclassIdentity.findIndex( + (element: DocumentIdentityElement) => element[resourceSchema.subclassIdentityDocumentKey] != null, + ); + invariant( + indexForRename !== -1, + `deriveSuperclassInfoFrom found no identity element with name ${resourceSchema.subclassIdentityDocumentKey}`, + ); + + // Get value for renamed element + const valueForRename: any = superclassIdentity[indexForRename][resourceSchema.subclassIdentityDocumentKey]; + invariant( + valueForRename != null, + `deriveSuperclassInfoFrom found no value for ${resourceSchema.subclassIdentityDocumentKey}`, + ); + + // Create renamed element + const renamedIdentityElement: DocumentIdentityElement = { + [resourceSchema.superclassIdentityDocumentKey]: valueForRename, + }; + + // Overwrite renamed element (array was cloned, so this is ok) + superclassIdentity[indexForRename] = renamedIdentityElement; return { resourceName: resourceSchema.superclassResourceName, diff --git a/Meadowlark-js/packages/meadowlark-core/src/model/api-schema/ResourceSchema.ts b/Meadowlark-js/packages/meadowlark-core/src/model/api-schema/ResourceSchema.ts index 7b9195de..555f014b 100644 --- a/Meadowlark-js/packages/meadowlark-core/src/model/api-schema/ResourceSchema.ts +++ b/Meadowlark-js/packages/meadowlark-core/src/model/api-schema/ResourceSchema.ts @@ -95,8 +95,8 @@ export type DomainEntitySubclassResourceSchema = AssociationSubclassResourceSche * This is found in MetaEd as an "identity rename". MetaEd only allows the super/subclass * relationship of Domain Entities to have a single common identity field. */ - superclassIdentityFullname: MetaEdPropertyFullName; - subclassIdentityFullname: MetaEdPropertyFullName; + superclassIdentityDocumentKey: DocumentObjectKey; + subclassIdentityDocumentKey: DocumentObjectKey; }; /**