Skip to content

Commit

Permalink
progress after rebase
Browse files Browse the repository at this point in the history
Signed-off-by: Harald Fischer <[email protected]>
  • Loading branch information
fisehara committed Nov 11, 2024
1 parent e4d0c5c commit f4ee366
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 41 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/odata-metadata/open-api-sepcification-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import _ = require('lodash');

export const generateODataMetadataAsOpenApi = (
odataCsdl: ReturnType<typeof generateODataMetadata>,
versionBasePathUrl: string = '',
hostname: string = '',
versionBasePathUrl = '',
hostname = '',
) => {
// console.log(`odataCsdl:${JSON.stringify(odataCsdl, null, 2)}`);
const openAPIJson: any = odataMetadata.csdl2openapi(odataCsdl, {
Expand Down
79 changes: 41 additions & 38 deletions src/sbvr-api/sbvr-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
(
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -1697,19 +1700,19 @@ const runRequest = async (

const runChangeSet =
(req: Express.Request, tx: Db.Tx) =>
async (
changeSetResults: Map<number, Response>,
request: uriParser.ODataRequest,
): Promise<void> => {
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<number, Response>,
request: uriParser.ODataRequest,
): Promise<void> => {
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
Expand Down
2 changes: 1 addition & 1 deletion test/08-metadata.test.ts → test/09-metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReturnType<typeof testInit>>;
before(async () => {
pineServer = await testInit({
Expand Down
File renamed without changes.

0 comments on commit f4ee366

Please sign in to comment.