From f4ee3662e68a7c53e67d127d58d2e4fb14288b3f Mon Sep 17 00:00:00 2001 From: Harald Fischer Date: Mon, 11 Nov 2024 13:17:27 +0100 Subject: [PATCH] progress after rebase Signed-off-by: Harald Fischer --- package.json | 1 + .../open-api-sepcification-generator.ts | 4 +- src/sbvr-api/sbvr-utils.ts | 79 ++++++++++--------- ...8-metadata.test.ts => 09-metadata.test.ts} | 2 +- .../config-full-access.ts | 0 .../config-restricted-access.ts | 0 .../{08-metadata => 09-metadata}/example.sbvr | 0 7 files changed, 45 insertions(+), 41 deletions(-) rename test/{08-metadata.test.ts => 09-metadata.test.ts} (96%) rename test/fixtures/{08-metadata => 09-metadata}/config-full-access.ts (100%) rename test/fixtures/{08-metadata => 09-metadata}/config-restricted-access.ts (100%) rename test/fixtures/{08-metadata => 09-metadata}/example.sbvr (100%) diff --git a/package.json b/package.json index a294b9ec4..d6a0eea1d 100644 --- a/package.json +++ b/package.json @@ -62,6 +62,7 @@ "express-session": "^1.18.1", "lodash": "^4.17.21", "memoizee": "^0.4.17", + "odata-openapi": "^0.28.2", "pinejs-client-core": "^8.1.1", "randomstring": "^1.3.0", "typed-error": "^3.2.2" diff --git a/src/odata-metadata/open-api-sepcification-generator.ts b/src/odata-metadata/open-api-sepcification-generator.ts index 06c9b0da8..ddd6ef8ef 100644 --- a/src/odata-metadata/open-api-sepcification-generator.ts +++ b/src/odata-metadata/open-api-sepcification-generator.ts @@ -5,8 +5,8 @@ import _ = require('lodash'); export const generateODataMetadataAsOpenApi = ( odataCsdl: ReturnType, - versionBasePathUrl: string = '', - hostname: string = '', + versionBasePathUrl = '', + hostname = '', ) => { // console.log(`odataCsdl:${JSON.stringify(odataCsdl, null, 2)}`); const openAPIJson: any = odataMetadata.csdl2openapi(odataCsdl, { diff --git a/src/sbvr-api/sbvr-utils.ts b/src/sbvr-api/sbvr-utils.ts index f664ceede..9a57c1f5f 100644 --- a/src/sbvr-api/sbvr-utils.ts +++ b/src/sbvr-api/sbvr-utils.ts @@ -149,18 +149,18 @@ export interface ApiKey extends Actor { export interface Response { statusCode: number; headers?: - | { - [headerName: string]: any; - } - | undefined; + | { + [headerName: string]: any; + } + | undefined; body?: AnyObject | string; } export type ModelExecutionResult = | undefined | { - migrationExecutionResult?: MigrationExecutionResult; - }; + migrationExecutionResult?: MigrationExecutionResult; + }; const memoizedResolvedSynonym = memoizeWeak( ( @@ -252,9 +252,9 @@ const prettifyConstraintError = ( let keyMatches: RegExpExecArray | null = null; let violatedConstraintInfo: | { - table: AbstractSQLCompiler.AbstractSqlTable; - name: string; - } + table: AbstractSQLCompiler.AbstractSqlTable; + name: string; + } | undefined; if (err instanceof db.UniqueConstraintError) { switch (db.engine) { @@ -292,8 +292,8 @@ const prettifyConstraintError = ( const columns = keyMatches[1].split('_'); throw new db.UniqueConstraintError( '"' + - columns.map(sqlNameToODataName).join('" and "') + - '" must be unique.', + columns.map(sqlNameToODataName).join('" and "') + + '" must be unique.', ); } if (violatedConstraintInfo != null) { @@ -328,16 +328,16 @@ const prettifyConstraintError = ( const tableName = abstractSqlModel.tables[resourceName].name; keyMatches = new RegExp( '"' + - tableName + - '" violates foreign key constraint ".*?" on table "(.*?)"', + tableName + + '" violates foreign key constraint ".*?" on table "(.*?)"', ).exec(err.message); if (keyMatches == null) { keyMatches = new RegExp( '"' + - tableName + - '" violates foreign key constraint "' + - tableName + - '_(.*?)_fkey"', + tableName + + '" violates foreign key constraint "' + + tableName + + '_(.*?)_fkey"', ).exec(err.message); } break; @@ -364,8 +364,8 @@ const prettifyConstraintError = ( case 'postgres': keyMatches = new RegExp( 'new row for relation "' + - table.name + - '" violates check constraint "(.*?)"', + table.name + + '" violates check constraint "(.*?)"', ).exec(err.message); break; } @@ -982,11 +982,11 @@ export const runRule = (() => { const odataResult = (await runURI( 'GET', '/' + - vocab + - '/' + - sqlNameToODataName(table.resourceName) + - '?$filter=' + - filter, + vocab + + '/' + + sqlNameToODataName(table.resourceName) + + '?$filter=' + + filter, undefined, undefined, permissions.rootRead, @@ -1377,7 +1377,10 @@ const runODataRequest = (req: Express.Request, vocabulary: string) => { -'#canAccess'.length, ); } - if (abstractSqlModel.tables[resolvedResourceName] == null && !metadataEndpoints.includes(resolvedResourceName)) { + if ( + abstractSqlModel.tables[resolvedResourceName] == null && + !metadataEndpoints.includes(resolvedResourceName) + ) { throw new UnauthorizedError(); } @@ -1697,19 +1700,19 @@ const runRequest = async ( const runChangeSet = (req: Express.Request, tx: Db.Tx) => - async ( - changeSetResults: Map, - request: uriParser.ODataRequest, - ): Promise => { - request = updateBinds(changeSetResults, request); - const result = await runRequest(req, tx, request); - if (request.id == null) { - throw new Error('No request id'); - } - result.headers ??= {}; - result.headers['content-id'] = request.id; - changeSetResults.set(request.id, result); - }; + async ( + changeSetResults: Map, + request: uriParser.ODataRequest, + ): Promise => { + request = updateBinds(changeSetResults, request); + const result = await runRequest(req, tx, request); + if (request.id == null) { + throw new Error('No request id'); + } + result.headers ??= {}; + result.headers['content-id'] = request.id; + changeSetResults.set(request.id, result); + }; // Requests inside a changeset may refer to resources created inside the // changeset, the generation of the sql query for those requests must be diff --git a/test/08-metadata.test.ts b/test/09-metadata.test.ts similarity index 96% rename from test/08-metadata.test.ts rename to test/09-metadata.test.ts index 7720d7440..2a1344688 100644 --- a/test/08-metadata.test.ts +++ b/test/09-metadata.test.ts @@ -8,7 +8,7 @@ import OpenAPIParser from '@readme/openapi-parser'; describe('08 metadata / openAPI spec', function () { describe('Full model access specification', async function () { const fixturePath = - __dirname + '/fixtures/08-metadata/config-full-access.js'; + __dirname + '/fixtures/09-metadata/config-full-access.js'; let pineServer: Awaited>; before(async () => { pineServer = await testInit({ diff --git a/test/fixtures/08-metadata/config-full-access.ts b/test/fixtures/09-metadata/config-full-access.ts similarity index 100% rename from test/fixtures/08-metadata/config-full-access.ts rename to test/fixtures/09-metadata/config-full-access.ts diff --git a/test/fixtures/08-metadata/config-restricted-access.ts b/test/fixtures/09-metadata/config-restricted-access.ts similarity index 100% rename from test/fixtures/08-metadata/config-restricted-access.ts rename to test/fixtures/09-metadata/config-restricted-access.ts diff --git a/test/fixtures/08-metadata/example.sbvr b/test/fixtures/09-metadata/example.sbvr similarity index 100% rename from test/fixtures/08-metadata/example.sbvr rename to test/fixtures/09-metadata/example.sbvr