diff --git a/cli/package.json b/cli/package.json index c86708b9..03d84162 100644 --- a/cli/package.json +++ b/cli/package.json @@ -1,6 +1,6 @@ { "name": "@finos/calm-cli", - "version": "0.1.3", + "version": "0.1.4", "description": "A set of tools for interacting with the Common Architecture Language Model (CALM)", "main": "dist/index.js", "files": [ diff --git a/cli/src/commands/generate/generate.spec.ts b/cli/src/commands/generate/generate.spec.ts index 8a8a0ebc..32e27442 100644 --- a/cli/src/commands/generate/generate.spec.ts +++ b/cli/src/commands/generate/generate.spec.ts @@ -1,11 +1,7 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ - -import { exportedForTesting } from './generate'; import { runGenerate } from './generate'; import { tmpdir } from 'node:os'; import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs'; import path from 'node:path'; -import { SchemaDirectory } from './schema-directory'; jest.mock('../helper', () => { return { @@ -24,82 +20,6 @@ jest.mock('../../consts', () => ({ get CALM_META_SCHEMA_DIRECTORY() { return '../calm/draft/2024-04/meta'; } })); -let mockSchemaDir; - -beforeEach(() => { - mockSchemaDir = new SchemaDirectory(); -}); - -const { - instantiateAdditionalTopLevelProperties -} = exportedForTesting; - - -describe('instantiateAdditionalTopLevelProperties', () => { - it('instantiate an additional top level array property', () => { - const pattern = { - properties: { - 'extra-property': { - properties: { - values: { - type: 'array' - } - } - } - } - }; - - expect(instantiateAdditionalTopLevelProperties(pattern, mockSchemaDir)) - .toEqual({ - 'extra-property': { - values: [ '{{ VALUES }}' ] - } - }); - }); - - it('instantiate an additional top level const property', () => { - const pattern = { - properties: { - 'extra': { - properties: { - 'extra-property': { - const: 'value here' - } - } - } - } - }; - - expect(instantiateAdditionalTopLevelProperties(pattern, mockSchemaDir)) - .toEqual({ - 'extra': { - 'extra-property': 'value here' - } - }); - }); - - it('instantiate an additional top level string property', () => { - const pattern = { - properties: { - 'extra': { - properties: { - 'extra-property': { - 'type': 'string' - } - } - } - } - }; - - expect(instantiateAdditionalTopLevelProperties(pattern, mockSchemaDir)) - .toEqual({ - extra: { - 'extra-property': '{{ EXTRA_PROPERTY }}' - } - }); - }); -}); - describe('runGenerate', () => { let tempDirectoryPath; diff --git a/cli/src/commands/generate/generate.ts b/cli/src/commands/generate/generate.ts index e6b09c23..92f998cc 100644 --- a/cli/src/commands/generate/generate.ts +++ b/cli/src/commands/generate/generate.ts @@ -6,7 +6,7 @@ import * as winston from 'winston'; import { initLogger } from '../helper.js'; import { CALMInstantiation } from '../../types.js'; import { SchemaDirectory } from './schema-directory.js'; -import { instantiateNode, instantiateNodes } from './components/node.js'; +import { instantiateNodes } from './components/node.js'; import { instantiateRelationships } from './components/relationship.js'; import { CALM_META_SCHEMA_DIRECTORY } from '../../consts.js'; import { instantiateAllMetadata } from './components/metadata.js'; @@ -25,31 +25,6 @@ function loadFile(path: string): object { } -function instantiateAdditionalTopLevelProperties(pattern: object, schemaDirectory: SchemaDirectory): object { - if (!('properties' in pattern)) { - logger.error('Warning: pattern has no properties defined.'); - return []; - } - const properties = pattern['properties']; - - const extraProperties = {}; - for (const [additionalProperty, detail] of Object.entries(properties)) { - // additional properties only - if (['nodes', 'relationships'].includes(additionalProperty)) { - continue; - } - - // TODO handle generic top level properties, not just nodes - extraProperties[additionalProperty] = instantiateNode(detail, schemaDirectory); - } - - return extraProperties; -} - -export const exportedForTesting = { - instantiateAdditionalTopLevelProperties -}; - export async function generate(patternPath: string, debug: boolean, instantiateAll: boolean, schemaDirectoryPath?: string): Promise { logger = initLogger(debug); const schemaDirectory = new SchemaDirectory(debug); @@ -64,13 +39,11 @@ export async function generate(patternPath: string, debug: boolean, instantiateA const outputNodes = instantiateNodes(pattern, schemaDirectory, debug, instantiateAll); const relationshipNodes = instantiateRelationships(pattern, schemaDirectory, debug, instantiateAll); - const additionalProperties = instantiateAdditionalTopLevelProperties(pattern, schemaDirectory); const metadata = instantiateAllMetadata(pattern, schemaDirectory, debug, instantiateAll); const final = { 'nodes': outputNodes, - 'relationships': relationshipNodes, - ...additionalProperties // object spread operator to insert additional props at top level + 'relationships': relationshipNodes }; if (metadata) {