Skip to content

Commit

Permalink
fix: bug fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfaron committed Dec 4, 2024
1 parent 71a1af4 commit 6c0ff7c
Show file tree
Hide file tree
Showing 17 changed files with 32 additions and 31 deletions.
2 changes: 0 additions & 2 deletions projects/aas-lib/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"declaration": false,
"module": "ES2022",
"moduleResolution": "node",
"importHelpers": true,
"lib": [
"ES2022",
Expand Down
2 changes: 0 additions & 2 deletions projects/aas-portal/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"declaration": false,
"module": "ES2022",
"moduleResolution": "node",
"importHelpers": true,
"lib": [
"ES2022",
Expand Down
5 changes: 5 additions & 0 deletions projects/aas-server/src/app/aas-index/aas-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import {
AASCursor,
AASDocument,
AASDocumentId,
AASEndpoint,
AASPagedResult,
aas,
Expand Down Expand Up @@ -144,6 +145,10 @@ export abstract class AASIndex {
return BigInt(referable.value);
}

protected toDocumentId(document: AASDocument): AASDocumentId {
return { endpoint: document.endpoint, id: document.id };
}

private preprocessString(value: string | LangString[] | undefined, max: number = 512): string | undefined {
if (value === undefined) {
return undefined;
Expand Down
10 changes: 5 additions & 5 deletions projects/aas-server/src/app/aas-index/lowdb/lowdb-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ export class LowDbIndex extends AASIndex {
return {
previous: null,
documents: documents.slice(0, limit),
next: documents.length >= 0 ? documents[limit] : null,
next: documents.length >= 0 ? this.toDocumentId(documents[limit]) : null,
};
}

Expand All @@ -348,7 +348,7 @@ export class LowDbIndex extends AASIndex {

const n = limit + 1;
const items = this.db.data.documents;
let i = items.findIndex(item => this.compare(current, item) < 0);
let i = items.findIndex(item => this.compare(current, item) <= 0);
if (i < 0) {
return this.getLastPage(limit, filter);
}
Expand All @@ -374,7 +374,7 @@ export class LowDbIndex extends AASIndex {
return {
previous: current,
documents: documents.slice(0, limit),
next: documents.length >= n ? documents[limit] : null,
next: documents.length >= n ? this.toDocumentId(documents[limit]) : null,
};
}

Expand Down Expand Up @@ -410,7 +410,7 @@ export class LowDbIndex extends AASIndex {
}

return {
previous: documents.length >= n ? documents[0] : null,
previous: documents.length >= n ? this.toDocumentId(documents[0]) : null,
documents: documents.slice(0, limit).reverse(),
next: current,
};
Expand Down Expand Up @@ -443,7 +443,7 @@ export class LowDbIndex extends AASIndex {
}

return {
previous: documents.length >= n ? documents[0] : null,
previous: documents.length >= n ? this.toDocumentId(documents[0]) : null,
documents: documents.slice(0, limit).reverse(),
next: null,
};
Expand Down
4 changes: 0 additions & 4 deletions projects/aas-server/src/app/aas-index/mysql/mysql-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,8 +604,4 @@ export class MySqlIndex extends AASIndex {

return document;
}

private toDocumentId(document: AASDocument): AASDocumentId {
return { endpoint: document.endpoint, id: document.id };
}
}
3 changes: 2 additions & 1 deletion projects/aas-server/src/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { RegisterRoutes } from './routes/routes.js';
import { ERRORS } from './errors.js';
import { Variable } from './variable.js';
import { Logger } from './logging/logger.js';
import multer from 'multer';

@singleton()
export class App {
Expand Down Expand Up @@ -64,7 +65,7 @@ export class App {
return res.send(swaggerUi.generateHTML(this.swaggerDoc));
});

RegisterRoutes(this.app);
RegisterRoutes(this.app, { multer: multer({ dest: './temp' }) });

this.app.get('/', this.getIndex);
this.app.use(express.static(this.variable.WEB_ROOT));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('LowDbIndex', () => {
expect(page.next).toBeDefined();
let n = page.documents.length;
while (page.next !== null) {
cursor = { ...cursor, next: getId(page.documents[page.documents.length - 1]) };
cursor = { ...cursor, next: page.next };
page = await index.getDocuments(cursor);
n += page.documents.length;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import 'reflect-metadata';
import { container } from 'tsyringe';
import express, { Express, json, urlencoded } from 'express';
import multer from 'multer';
import morgan from 'morgan';
import request from 'supertest';
import { Logger } from '../../app/logging/logger.js';
Expand Down Expand Up @@ -61,7 +62,7 @@ describe('AppController', function () {
app.use(morgan('dev'));
app.set('trust proxy', 1);

RegisterRoutes(app);
RegisterRoutes(app, { multer: multer({ dest: './temp' }) });
app.use(errorHandler);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import 'reflect-metadata';
import { container } from 'tsyringe';
import express, { Express, json, urlencoded } from 'express';
import multer from 'multer';
import morgan from 'morgan';
import request from 'supertest';
import { ApplicationError, AuthResult, Cookie, Credentials } from 'aas-core';
Expand Down Expand Up @@ -58,7 +59,7 @@ describe('AuthController', () => {
app.use(morgan('dev'));
app.set('trust proxy', 1);

RegisterRoutes(app);
RegisterRoutes(app, { multer: multer({ dest: './temp' }) });
app.use(errorHandler);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'reflect-metadata';
import { container } from 'tsyringe';
import { describe, beforeEach, it, expect, jest } from '@jest/globals';
import express, { Express, json, urlencoded } from 'express';
import multer from 'multer';
import morgan from 'morgan';
import request from 'supertest';
import { Readable } from 'stream';
Expand Down Expand Up @@ -74,7 +75,7 @@ describe('ContainersController', () => {
app.use(morgan('dev'));
app.set('trust proxy', 1);

RegisterRoutes(app);
RegisterRoutes(app, { multer: multer({ dest: './temp' }) });
app.use(errorHandler);
});

Expand Down Expand Up @@ -208,15 +209,15 @@ describe('ContainersController', () => {
});
});

it('updateDocument: /api/v1/containers/:url/documents/:id', async () => {
it('updateDocument: /api/v1/containers/{endpoint}/documents/{id}', async () => {
aasProvider.updateDocumentAsync.mockReturnValue(Promise.resolve([]));
auth.hasUserAsync.mockReturnValue(new Promise<boolean>(resolve => resolve(true)));

const url = Buffer.from('http://localhost/container').toString('base64url');
const endpoint = Buffer.from('Endpoint 1').toString('base64url');
const id = Buffer.from('http://localhost/document').toString('base64url');

const response = await request(app)
.put(`/api/v1/containers/${url}/documents/${id}`)
.put(`/api/v1/containers/${endpoint}/documents/${id}`)
.set('Authorization', `Bearer ${getToken('John')}`)
.attach('content', resolve('./src/test/assets/aas-example.json'));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { container } from 'tsyringe';
import { describe, beforeEach, it, expect, jest } from '@jest/globals';
import express, { Express, json, urlencoded } from 'express';
import morgan from 'morgan';
import multer from 'multer';
import request from 'supertest';
import { AASCursor, AASPagedResult } from 'aas-core';

Expand Down Expand Up @@ -74,7 +75,7 @@ describe('DocumentsController', function () {
app.use(morgan('dev'));
app.set('trust proxy', 1);

RegisterRoutes(app);
RegisterRoutes(app, { multer: multer({ dest: './temp' }) });
app.use(errorHandler);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { container } from 'tsyringe';
import { describe, beforeEach, it, expect, jest } from '@jest/globals';
import express, { Express, json, urlencoded } from 'express';
import morgan from 'morgan';
import multer from 'multer';
import request from 'supertest';
import { AASEndpoint } from 'aas-core';

Expand Down Expand Up @@ -70,7 +71,7 @@ describe('EndpointsController', function () {
app.use(morgan('dev'));
app.set('trust proxy', 1);

RegisterRoutes(app);
RegisterRoutes(app, { multer: multer({ dest: './temp' }) });
app.use(errorHandler);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import 'reflect-metadata';
import { container } from 'tsyringe';
import multer from 'multer';
import { describe, beforeEach, it, expect, jest } from '@jest/globals';
import express, { Express, json, urlencoded } from 'express';
import morgan from 'morgan';
Expand Down Expand Up @@ -60,7 +61,7 @@ describe('TemplateController', () => {
app.use(morgan('dev'));
app.set('trust proxy', 1);

RegisterRoutes(app);
RegisterRoutes(app, { multer: multer({ dest: './temp' }) });
app.use(errorHandler);
});

Expand Down
2 changes: 2 additions & 0 deletions projects/aas-server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"emitDecoratorMetadata": true,
"alwaysStrict": true,
"useUnknownInCatchVariables": false,
"module": "NodeNext",
"moduleResolution": "NodeNext",
"lib": [
"ES2022"
],
Expand Down
3 changes: 0 additions & 3 deletions projects/aas-server/tsoa.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
"controllerPathGlobs": [
"src/app/controller/**/*controller.ts"
],
"multerOpts": {
"dest": "./temp"
},
"spec": {
"outputDirectory": "./src/assets",
"specVersion": 3,
Expand Down
2 changes: 0 additions & 2 deletions projects/fhg-jest/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
"outDir": "./build",
"noImplicitAny": true,
"skipLibCheck": true,
"module": "NodeNext",
"moduleResolution": "NodeNext",
"emitDecoratorMetadata": true,
"alwaysStrict": true,
"useUnknownInCatchVariables": false,
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"moduleResolution": "NodeNext",
"module": "NodeNext"
"moduleResolution": "bundler",
"module": "ES2022"
},
"ts-node": {
"esm": true
Expand Down

0 comments on commit 6c0ff7c

Please sign in to comment.