Skip to content

Commit

Permalink
Remove additional top level properties code + bump
Browse files Browse the repository at this point in the history
  • Loading branch information
willosborne committed Jun 12, 2024
1 parent 8d98914 commit 601d43a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 110 deletions.
2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
80 changes: 0 additions & 80 deletions cli/src/commands/generate/generate.spec.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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;
Expand Down
31 changes: 2 additions & 29 deletions cli/src/commands/generate/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<CALMInstantiation> {
logger = initLogger(debug);
const schemaDirectory = new SchemaDirectory(debug);
Expand All @@ -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) {
Expand Down

0 comments on commit 601d43a

Please sign in to comment.