From 7e2a71785057a09bd693c1d191a777554f7e96b0 Mon Sep 17 00:00:00 2001 From: Thels Date: Fri, 20 Dec 2024 13:04:47 +0000 Subject: [PATCH] #446 - Upgrade CLI to 2024-10. (#696) * #446 - Upgrade CLI to 2024-10. For now this is only ensuring that the draft version is updated - not that the examples/functionality exposed by the upgraded CALM version would provide - these are covered by other issues. * PR review fixes. --- calm/pattern/api-gateway.json | 22 ++++++++-------- cli/package.json | 4 +-- cli/src/index.ts | 3 ++- cli/tsconfig.json | 4 ++- package-lock.json | 8 +++--- shared/src/commands/generate/generate.spec.ts | 2 +- .../generate/schema-directory.spec.ts | 25 +++++++++++++++++++ .../src/commands/generate/schema-directory.ts | 3 +++ shared/src/commands/validate/validate.spec.ts | 4 +-- .../src/commands/visualize/visualize.spec.ts | 2 +- 10 files changed, 54 insertions(+), 23 deletions(-) diff --git a/calm/pattern/api-gateway.json b/calm/pattern/api-gateway.json index 2c180a4f..245fb5b5 100644 --- a/calm/pattern/api-gateway.json +++ b/calm/pattern/api-gateway.json @@ -1,5 +1,5 @@ { - "$schema": "https://raw.githubusercontent.com/finos/architecture-as-code/main/calm/draft/2024-04/meta/calm.json", + "$schema": "https://calm.finos.org/draft/2024-10/meta/calm.json", "$id": "https://raw.githubusercontent.com/finos/architecture-as-code/main/calm/pattern/api-gateway", "title": "API Gateway Pattern", "type": "object", @@ -9,7 +9,7 @@ "minItems": 4, "prefixItems": [ { - "$ref": "https://raw.githubusercontent.com/finos/architecture-as-code/main/calm/draft/2024-04/meta/core.json#/defs/node", + "$ref": "https://calm.finos.org/draft/2024-10/meta/core.json#/defs/node", "properties": { "well-known-endpoint": { "type": "string" @@ -31,7 +31,7 @@ "minItems": 1, "prefixItems": [ { - "$ref": "https://raw.githubusercontent.com/finos/architecture-as-code/main/calm/draft/2024-04/meta/interface.json#/defs/host-port-interface", + "$ref": "https://calm.finos.org/draft/2024-10/meta/interface.json#/defs/host-port-interface", "properties": { "unique-id": { "const": "api-gateway-ingress" @@ -47,7 +47,7 @@ ] }, { - "$ref": "https://raw.githubusercontent.com/finos/architecture-as-code/main/calm/draft/2024-04/meta/core.json#/defs/node", + "$ref": "https://calm.finos.org/draft/2024-10/meta/core.json#/defs/node", "properties": { "description": { "const": "The API Consumer making an authenticated and authorized request" @@ -64,7 +64,7 @@ } }, { - "$ref": "https://raw.githubusercontent.com/finos/architecture-as-code/main/calm/draft/2024-04/meta/core.json#/defs/node", + "$ref": "https://calm.finos.org/draft/2024-10/meta/core.json#/defs/node", "properties": { "description": { "const": "The API Producer serving content" @@ -83,7 +83,7 @@ "minItems": 1, "prefixItems": [ { - "$ref": "https://raw.githubusercontent.com/finos/architecture-as-code/main/calm/draft/2024-04/meta/interface.json#/defs/host-port-interface", + "$ref": "https://calm.finos.org/draft/2024-10/meta/interface.json#/defs/host-port-interface", "properties": { "unique-id": { "const": "producer-ingress" @@ -98,7 +98,7 @@ ] }, { - "$ref": "https://raw.githubusercontent.com/finos/architecture-as-code/main/calm/draft/2024-04/meta/core.json#/defs/node", + "$ref": "https://calm.finos.org/draft/2024-10/meta/core.json#/defs/node", "properties": { "description": { "const": "The Identity Provider used to verify the bearer token" @@ -121,7 +121,7 @@ "minItems": 4, "prefixItems": [ { - "$ref": "https://raw.githubusercontent.com/finos/architecture-as-code/main/calm/draft/2024-04/meta/core.json#/defs/relationship", + "$ref": "https://calm.finos.org/draft/2024-10/meta/core.json#/defs/relationship", "properties": { "unique-id": { "const": "api-consumer-api-gateway" @@ -154,7 +154,7 @@ } }, { - "$ref": "https://raw.githubusercontent.com/finos/architecture-as-code/main/calm/draft/2024-04/meta/core.json#/defs/relationship", + "$ref": "https://calm.finos.org/draft/2024-10/meta/core.json#/defs/relationship", "properties": { "unique-id": { "const": "api-gateway-idp" @@ -180,7 +180,7 @@ } }, { - "$ref": "https://raw.githubusercontent.com/finos/architecture-as-code/main/calm/draft/2024-04/meta/core.json#/defs/relationship", + "$ref": "https://calm.finos.org/draft/2024-10/meta/core.json#/defs/relationship", "properties": { "unique-id": { "const": "api-gateway-api-producer" @@ -209,7 +209,7 @@ } }, { - "$ref": "https://raw.githubusercontent.com/finos/architecture-as-code/main/calm/draft/2024-04/meta/core.json#/defs/relationship", + "$ref": "https://calm.finos.org/draft/2024-10/meta/core.json#/defs/relationship", "properties": { "unique-id": { "const": "api-consumer-idp" diff --git a/cli/package.json b/cli/package.json index 192905d5..2a5c6f61 100644 --- a/cli/package.json +++ b/cli/package.json @@ -1,6 +1,6 @@ { "name": "@finos/calm-cli", - "version": "0.2.7", + "version": "0.3.0", "description": "A set of tools for interacting with the Common Architecture Language Model (CALM)", "main": "dist/index.js", "files": [ @@ -12,7 +12,7 @@ "scripts": { "build": "tsup && npm run copy-calm-schema", "watch": "node watch.mjs", - "copy-calm-schema": "copyfiles \"../calm/draft/2024-04/meta/*\" dist/calm/", + "copy-calm-schema": "copyfiles \"../calm/draft/2024-10/meta/*\" dist/calm/", "test": "jest", "lint": "eslint src", "lint-fix": "eslint src --fix", diff --git a/cli/src/index.ts b/cli/src/index.ts index 60fe59a7..5f128c66 100644 --- a/cli/src/index.ts +++ b/cli/src/index.ts @@ -5,6 +5,7 @@ import { Option, program } from 'commander'; import path from 'path'; import { mkdirp } from 'mkdirp'; import { writeFileSync } from 'fs'; +import { version } from '../package.json'; const FORMAT_OPTION = '-f, --format '; const ARCHITECTURE_OPTION = '-a, --architecture '; @@ -17,7 +18,7 @@ const VERBOSE_OPTION = '-v, --verbose'; program .name('calm') - .version('0.2.5') + .version(version) .description('A set of tools for interacting with the Common Architecture Language Model (CALM)'); program diff --git a/cli/tsconfig.json b/cli/tsconfig.json index 006b4cdb..c3aa10b1 100644 --- a/cli/tsconfig.json +++ b/cli/tsconfig.json @@ -6,6 +6,7 @@ "target": "ES6", "esModuleInterop": true, "forceConsistentCasingInFileNames": true, + "resolveJsonModule": true, "skipLibCheck": true, "moduleResolution": "node", "types": [ @@ -23,6 +24,7 @@ } ], "include": [ - "src/**/*" + "src/**/*", + "package.json" ] } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 0204365d..06106253 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,7 @@ }, "cli": { "name": "@finos/calm-cli", - "version": "0.2.7", + "version": "0.3.0", "license": "ISC", "dependencies": { "canvas": "^2.11.2", @@ -39,9 +39,9 @@ "@types/xml2js": "^0.4.14", "@typescript-eslint/eslint-plugin": "^8.0.0", "@typescript-eslint/parser": "^8.15.0", - "chokidar": "^4.0.3", + "chokidar": "^4.0.1", "eslint": "^9.13.0", - "globals": "^15.14.0", + "globals": "^15.12.0", "jest": "^29.7.0", "ts-jest": "^29.2.5", "ts-node": "10.9.2", @@ -26896,7 +26896,7 @@ "@typescript-eslint/parser": "^8.15.0", "eslint": "^9.13.0", "fetch-mock": "^9.11.0", - "globals": "^15.14.0", + "globals": "^15.12.0", "jest": "^29.7.0", "ts-jest": "^29.2.5", "ts-node": "10.9.2", diff --git a/shared/src/commands/generate/generate.spec.ts b/shared/src/commands/generate/generate.spec.ts index 0a0048b9..870e977d 100644 --- a/shared/src/commands/generate/generate.spec.ts +++ b/shared/src/commands/generate/generate.spec.ts @@ -17,7 +17,7 @@ jest.mock('../helper', () => { jest.mock('./schema-directory'); jest.mock('../../consts', () => ({ - get CALM_META_SCHEMA_DIRECTORY() { return '../calm/draft/2024-04/meta'; } + get CALM_META_SCHEMA_DIRECTORY() { return '../calm/draft/2024-10/meta'; } })); diff --git a/shared/src/commands/generate/schema-directory.spec.ts b/shared/src/commands/generate/schema-directory.spec.ts index a50535b9..421a72c6 100644 --- a/shared/src/commands/generate/schema-directory.spec.ts +++ b/shared/src/commands/generate/schema-directory.spec.ts @@ -22,6 +22,29 @@ describe('SchemaDirectory', () => { expect(schemaDir.getLoadedSchemas().length).toBe(2); }); + it('loads all specs from given directory including subdirectories - 2024-10 schema', async () => { + const schemaDir = new SchemaDirectory(); + + await schemaDir.loadSchemas('../calm/draft/2024-10'); + expect(schemaDir.getLoadedSchemas().length).toBe(8); + + const loadedSchemas = schemaDir.getLoadedSchemas(); + const expectedFileNames = [ + 'https://calm.finos.org/draft/2024-10/meta/calm.json', + 'https://calm.finos.org/draft/2024-10/meta/control-requirement.json', + 'https://calm.finos.org/draft/2024-10/meta/control.json', + 'https://calm.finos.org/draft/2024-10/meta/core.json', + 'https://calm.finos.org/draft/2024-10/meta/evidence.json', + 'https://calm.finos.org/draft/2024-10/meta/flow.json', + 'https://calm.finos.org/draft/2024-10/meta/interface.json', + 'https://calm.finos.org/draft/2024-10/meta/units.json' + ]; + + expectedFileNames.forEach((fileName, index) => { + expect(loadedSchemas[index]).toBe(fileName); + }); + }); + it('resolves a reference from a loaded schema', async () => { const schemaDir = new SchemaDirectory(); @@ -67,6 +90,8 @@ describe('SchemaDirectory', () => { expect(interfaceDef.properties['missing-value']).toEqual('MISSING OBJECT, ref: ' + interfaceRef + ' could not be resolved'); }); + + it('terminate early in the case of a circular reference', async () => { const schemaDir = new SchemaDirectory(); diff --git a/shared/src/commands/generate/schema-directory.ts b/shared/src/commands/generate/schema-directory.ts index bb95e907..91ba6137 100644 --- a/shared/src/commands/generate/schema-directory.ts +++ b/shared/src/commands/generate/schema-directory.ts @@ -48,6 +48,9 @@ export class SchemaDirectory { map.forEach((val, key) => this.schemas.set(key, val)); this.logger.info(`Loaded ${this.schemas.size} schemas.`); + this.schemas.forEach((_schema, id) => { + this.logger.debug(`Schema ID: ${id}`); + }); } catch (err) { if (err.code === 'ENOENT') { this.logger.error('Schema Path not found: ', dir, ', error: ', err); diff --git a/shared/src/commands/validate/validate.spec.ts b/shared/src/commands/validate/validate.spec.ts index 015b4830..84358190 100644 --- a/shared/src/commands/validate/validate.spec.ts +++ b/shared/src/commands/validate/validate.spec.ts @@ -354,7 +354,7 @@ describe('validate-all', () => { const given: ErrorObject[] = [ { 'instancePath': '/nodes/0/interfaces/0/port', - 'schemaPath': 'https://raw.githubusercontent.com/finos/architecture-as-code/main/calm/draft/2024-04/meta/interface.json#/defs/host-port-interface/properties/port/type', + 'schemaPath': 'https://calm.finos.org/draft/2024-10/meta/interface.json#/defs/host-port-interface/properties/port/type', 'keyword': 'type', 'params': { 'type': 'integer' @@ -369,7 +369,7 @@ describe('validate-all', () => { 'error', 'must be integer', '/nodes/0/interfaces/0/port', - 'https://raw.githubusercontent.com/finos/architecture-as-code/main/calm/draft/2024-04/meta/interface.json#/defs/host-port-interface/properties/port/type' + 'https://calm.finos.org/draft/2024-10/meta/interface.json#/defs/host-port-interface/properties/port/type' ) ]; diff --git a/shared/src/commands/visualize/visualize.spec.ts b/shared/src/commands/visualize/visualize.spec.ts index 927dbb25..0ca36f24 100644 --- a/shared/src/commands/visualize/visualize.spec.ts +++ b/shared/src/commands/visualize/visualize.spec.ts @@ -32,7 +32,7 @@ jest.mock('../helper.js', () => { jest.mock('../generate/generate'); jest.mock('../../consts', () => ({ - get CALM_META_SCHEMA_DIRECTORY() { return '../calm/draft/2024-04/meta'; } + get CALM_META_SCHEMA_DIRECTORY() { return '../calm/draft/2024-10/meta'; } })); describe('visualizer', () => {