Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Created by https://www.toptal.com/developers/gitignore/api/windows,linux,macos,visualstudiocode,git,node
# Edit at https://www.toptal.com/developers/gitignore?templates=windows,linux,macos,visualstudiocode,git,node

.vscode/

### Custom ##
build/
reports/
Expand Down
9 changes: 5 additions & 4 deletions packages/architectura/docker/services/node/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
FROM node:lts-bullseye

RUN apt-get update && apt-get install -y --no-install-recommends \
nano \
screen \
htop \
bash
bash \
htop \
nano \
screen \
&& apt-get clean

USER root

Expand Down
50 changes: 28 additions & 22 deletions packages/architectura/src/core/server/rich-client-request.mts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class RichClientRequest extends IncomingMessage
private query: ParsedUrlQuery;
private contentType: string | undefined;
private boundary: string | undefined;
private rawBody: Promise<Buffer>;
private rawBody: Promise<Buffer> = Promise.resolve(Buffer.alloc(0));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We ruled against initializing properties outside the constructor.


/**
* Create a new rich client request.
Expand All @@ -42,7 +42,6 @@ class RichClientRequest extends IncomingMessage
this.query = parseQuery("");
this.contentType = undefined;
this.boundary = undefined;
this.rawBody = Promise.resolve(Buffer.alloc(0));
}

/**
Expand All @@ -59,26 +58,7 @@ class RichClientRequest extends IncomingMessage

this.initialized = true;

const CONTENT_TYPE_HEADER: string | undefined = this.getHeader("Content-Type");

if (CONTENT_TYPE_HEADER !== undefined)
{
this.contentType = CONTENT_TYPE_HEADER;

if (CONTENT_TYPE_HEADER.startsWith("multipart/form-data; boundary="))
{
this.contentType = ContentTypeEnum.FORM_DATA;

const BOUNDARY_IDENTIFIER: string = CONTENT_TYPE_HEADER.replace("multipart/form-data; boundary=", "");

if (BOUNDARY_IDENTIFIER.length === 0)
{
throw new Error(`Received invalid multipart/form-data header: ${this.contentType}.`);
}

this.boundary = `--${BOUNDARY_IDENTIFIER}`;
}
}
this.parseContentType();

const COOKIE_HEADER: string | undefined = this.getHeader("Cookie");

Expand Down Expand Up @@ -450,6 +430,32 @@ class RichClientRequest extends IncomingMessage
}
*/

private parseContentType(): void
{
const CONTENT_TYPE_HEADER: string | undefined = this.getHeader("Content-Type");

if (CONTENT_TYPE_HEADER === undefined)
{
return;
}

this.contentType = CONTENT_TYPE_HEADER;

if (CONTENT_TYPE_HEADER.startsWith("multipart/form-data; boundary="))
{
this.contentType = ContentTypeEnum.FORM_DATA;

const BOUNDARY_IDENTIFIER: string = CONTENT_TYPE_HEADER.replace("multipart/form-data; boundary=", "");

if (BOUNDARY_IDENTIFIER.length === 0)
{
throw new Error(`Received invalid multipart/form-data header: ${this.contentType}.`);
}

this.boundary = `--${BOUNDARY_IDENTIFIER}`;
}
}

private async listenForContent(): Promise<Buffer>
{
return await new Promise(
Expand Down
21 changes: 21 additions & 0 deletions packages/instrumenta/.c8rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"src": "./src",
"exclude": [
"mock",
"test"
],
"extension": [
".mts"
],
"reporter": [
"html"
],
"report-dir": "./coverage",
"skip-full": true,
"check-coverage": true,
"all": true,
"statements": 100,
"branches": 100,
"functions": 100,
"lines": 100
}
16 changes: 16 additions & 0 deletions packages/instrumenta/.mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extension": [
"mts"
],
"node-option": [
"loader=tsx"
],
"spec": [
"test/**/*.spec.mts"
],
"timeout": 5000,
"parallel": true,
"checkLeaks": true,
"diff": true,
"forbidPending": true
}
21 changes: 21 additions & 0 deletions packages/instrumenta/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 VitruviusLabs

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 changes: 3 additions & 0 deletions packages/instrumenta/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import configurations from "../../eslint.config.mjs";

export default configurations;
15 changes: 15 additions & 0 deletions packages/instrumenta/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@vitruvius-labs/instrumenta",
"version": "0.1.0",
"description": "A package providing tools to work with the Architectura framework.",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "Vitruvius Labs",
"contributors": [
"Nicolas \"SmashingQuasar\" Lebacq"
],
"license": "ISC",
"packageManager": "pnpm@10.10.0"
}
25 changes: 25 additions & 0 deletions packages/instrumenta/src/main.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { extractInterfaceName } from "./utility/open-api/extract-interface-name.mjs";
import { extractInterfaceProperties } from "./utility/open-api/extract-interface-properties.mjs";
// import { interfaceToOpenAPISchema } from "./utility/open-api/interface-to-open-api-schema.mjs";

const interfaceContent: string = `
import type { SearchFragmentDateInterface } from "../../entity/auxiliary/search-fragment-date/definition/interface/search-fragment-date.interface.mjs";

interface BaseSearchPayloadInterface
{
page?: number;
limit?: number;
uuids?: Array<string>;
createdAt?: SearchFragmentDateInterface;
}

export type { BaseSearchPayloadInterface };
`;

const name: string | undefined = extractInterfaceName(interfaceContent);
const properties: Record<string, string> = extractInterfaceProperties(interfaceContent);
// const fullResult: string = interfaceToOpenAPISchema(interfaceContent);

console.debug(name);
console.debug(properties);
// console.debug(fullResult);
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
interface InterfaceInstantiationInterface
{
content: string;
}

export type { InterfaceInstantiationInterface };
59 changes: 59 additions & 0 deletions packages/instrumenta/src/utility/open-api/interface/interface.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import type { InterfaceInstantiationInterface } from "./definition/interface/interface-instantiation.interface.mjs";

class Interface
{
private static readonly NameRegularExpression: RegExp = /interface\s+(?<name>\w+)\s*\{?/g;
private static readonly PropertiesRegularExpression: RegExp = /(?<property>[a-zA-Z]\w*)\??:\s*(?<type>[a-zA-Z][\w<>]*)/g;

private readonly contents: string;
private name: string | undefined;
private readonly properties: Record<string, string> = {};

public constructor(parameters: InterfaceInstantiationInterface)
{
this.contents = parameters.content;
}

protected extractName(): void
{
const match: RegExpExecArray | null = Interface.NameRegularExpression.exec(this.contents);

if (match === null)
{
return undefined;
}

const name: string | undefined = match.groups?.["name"];

Interface.NameRegularExpression.lastIndex = 0;

this.name = name;
}

protected extractProperties(): void
{
let match: RegExpExecArray | null = Interface.PropertiesRegularExpression.exec(this.contents);

if (match === null)
{
return;
}

while (match !== null)
{
const property: string | undefined = match.groups?.["property"];
const type: string | undefined = match.groups?.["type"];

if (property !== undefined && type !== undefined)
{
this.properties[property] = type;
}

match = Interface.PropertiesRegularExpression.exec(this.contents);
}

Interface.PropertiesRegularExpression.lastIndex = 0;
}
}

export { Interface };
18 changes: 18 additions & 0 deletions packages/instrumenta/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./build/esm",
"declarationDir": "./build/types",
"rootDir": "./src",
"declaration": true,
"declarationMap": false,
"removeComments": false,
"sourceMap": false,
"noEmit": false,
"listFiles": false,
"listEmittedFiles": false
},
"include": [
"./src"
]
}
9 changes: 9 additions & 0 deletions packages/instrumenta/tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {},
"include": [
"./src",
"./test",
"./mock"
]
}
15 changes: 15 additions & 0 deletions packages/instrumenta/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "../../tsconfig.json",
"compilerOptions": {
"allowSyntheticDefaultImports": true
},
"include": [
"./src",
"./test",
"./mock"
],
"exclude": [
"./node_modules"
]
}
12 changes: 12 additions & 0 deletions packages/instrumenta/tsconfig.mocha.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "./tsconfig.json",
"include": [
".",
"./**/.*",
"./**/*.json"
],
"ts-node": {
"files": true,
"swc": true
}
}
Loading