Skip to content
Draft
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
6 changes: 1 addition & 5 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"plugins": [
{
"plugin": "@nx/vite/plugin",
"buildTargetName": "vite:build",
"options": {
"buildTargetName": "vite:build",
"testTargetName": "test",
"serveTargetName": "serve",
"devTargetName": "vite:dev",
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
"compile": "yarn build"
},
"devDependencies": {
"@nx/eslint": "20.4.1",
"@nx/vite": "20.4.1",
"@nx/web": "20.4.1",
"@vitest/ui": "^1.3.1",
"nx": "20.4.1",
"prettier": "^3.4.2",
"typescript": "^5.7.3",
"vite": "^5.0.0",
"vitest": "^1.3.1"
"@nx/eslint": "^21.6.4",
"@nx/vite": "^21.6.4",
"@nx/web": "^21.6.4",
"@vitest/ui": "^3.2.4",
"nx": "^21.6.4",
"prettier": "^3.6.2",
"typescript": "^5.9.3",
"vite": "^7.1.9",
"vitest": "^3.2.4"
}
}
2 changes: 1 addition & 1 deletion packages/executor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ COPY packages/storage ./packages/storage
COPY packages/executor ./packages/executor

ENV NX_DAEMON=false
RUN yarn nx run executor:build
RUN yarn nx run build extension-a11y-checker-executor


FROM --platform=amd64 node:22-slim
Expand Down
24 changes: 12 additions & 12 deletions packages/executor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@
"format:check": "prettier $@ '**/*.{ts,tsx,yaml,yml,json,md,mdx}' --check"
},
"dependencies": {
"extension-a11y-checker-storage": "workspace:*",
"lighthouse": "^12.3.0",
"node-cron": "^3.0.3",
"pa11y": "^8.0.0",
"pino": "^9.6.0",
"pino-pretty": "^13.0.0",
"puppeteer": "^24.2.1",
"extension-a11y-checker-storage": "workspace:^",
"lighthouse": "^13.0.0",
"node-cron": "^4.2.1",
"pa11y": "^9.0.1",
"pino": "^10.0.0",
"pino-pretty": "^13.1.2",
"puppeteer": "^24.24.0",
"reflect-metadata": "^0.2.2"
},
"devDependencies": {
"@eslint/eslintrc": "^3",
"@types/node": "^20",
"@eslint/eslintrc": "^3.3.1",
"@types/node": "^24.7.2",
"@types/node-cron": "^3.0.11",
"eslint": "^9",
"nodemon": "^3.1.9",
"typescript": "^5"
"eslint": "^9.37.0",
"nodemon": "^3.1.10",
"typescript": "^5.9.3"
},
"packageManager": "[email protected]"
}
16 changes: 8 additions & 8 deletions packages/storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@
"format:check": "prettier $@ '**/*.{ts,tsx,yaml,yml,json,md,mdx}' --check"
},
"dependencies": {
"@typegoose/typegoose": "^12.11.0",
"cron-parser": "^4.9.0",
"mongodb": "^6.12.0",
"mongoose": "^8.10.0"
"@typegoose/typegoose": "^12.20.0",
"cron-parser": "^5.4.0",
"mongodb": "^6.20.0",
"mongoose": "^8.19.1"
},
"devDependencies": {
"@eslint/eslintrc": "^3",
"@types/node": "^20",
"eslint": "^9",
"typescript": "^5"
"@eslint/eslintrc": "^3.3.1",
"@types/node": "^24.7.2",
"eslint": "^9.37.0",
"typescript": "^5.9.3"
},
"packageManager": "[email protected]"
}
14 changes: 9 additions & 5 deletions packages/storage/src/context/context.model.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { prop, modelOptions } from "@typegoose/typegoose";
import { ObjectId } from "mongoose";
import { getModel } from "../lib/mongoose.js";
import { getModel, serializeObjectWithIds } from "../lib/mongoose.js";
import { ReturnModelType } from "@typegoose/typegoose/lib/types";
import { ScanProfileModel } from "../scanProfile/scanProfile.model.js";
import { ScanModel } from "../scan/scan.model.js";

@modelOptions({
schemaOptions: { versionKey: false, collection: "contexts" },
schemaOptions: {
versionKey: false,
collection: "contexts",
toJSON: {
transform: (doc, ret) => serializeObjectWithIds(ret),
},
},
options: { automaticName: false },
})
export class Context {
Expand All @@ -29,7 +33,7 @@ export class Context {
this: ReturnModelType<typeof Context>,
contextId: string,
) {
return this.updateOne(
return this.findOneAndUpdate(
Copy link
Member

Choose a reason for hiding this comment

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

damit ändert sich der Return-Value der Method. War das Absicht?

Copy link
Member Author

Choose a reason for hiding this comment

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

Der return type wird nie genutzt, daher erstmal egal 🤷

{ _id: contextId },
{
$setOnInsert: { _id: contextId },
Expand Down
1 change: 1 addition & 0 deletions packages/storage/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export { dbConnect };
export * from "./context/context.model.js";
export * from "./scan/scan.model.js";
export * from "./scanProfile/scanProfile.model.js";
export { serializeObjectWithIds } from "./lib/mongoose.js";
48 changes: 47 additions & 1 deletion packages/storage/src/lib/mongoose.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mongoose from "mongoose";
import mongoose, { ObjectId } from "mongoose";
import type {
AnyParamConstructor,
ReturnModelType,
Expand All @@ -14,3 +14,49 @@ export function getModel<U extends AnyParamConstructor<any>>(
getModelForClass(modelClass, { options: { customName: modelName } })
);
}

export type Serialize<T> = T extends ObjectId
? string
: T extends (infer U)[]
? Serialize<U>[]
: T extends object
? { [K in keyof T]: Serialize<T[K]> }
: T;

function isObjectId(value: unknown): value is ObjectId {
return (
!!value &&
typeof value === "object" &&
((value as any).toHexString instanceof Function ||
((value as any).toString instanceof Function &&
(value as any).constructor?.name === "ObjectId"))
);
}

function isPlainObject(value: unknown): value is Record<string, unknown> {
if (Object.prototype.toString.call(value) !== "[object Object]") return false;
const proto = Object.getPrototypeOf(value);
return proto === Object.prototype || proto === null;
}

export function serializeObjectWithIds<T>(obj: T): Serialize<T> {
if (obj == null) return obj as Serialize<T>;

if (isObjectId(obj)) return obj.toString() as Serialize<T>;

if (Array.isArray(obj)) {
return (obj as unknown[]).map(serializeObjectWithIds) as Serialize<T>;
}

if (isPlainObject(obj)) {
const result: Record<string, unknown> = {};
for (const key of Object.keys(obj as Record<string, unknown>)) {
result[key] = serializeObjectWithIds(
(obj as Record<string, unknown>)[key],
);
}
return result as Serialize<T>;
}

return obj as Serialize<T>;
}
36 changes: 31 additions & 5 deletions packages/storage/src/scan/scan.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@ import { isDocument } from "@typegoose/typegoose";
import { index, modelOptions, prop } from "@typegoose/typegoose";
import { ObjectId } from "mongodb";
import { ScanProfile } from "../scanProfile/scanProfile.model.js";
import { getModel } from "../lib/mongoose.js";
import { getModel, serializeObjectWithIds } from "../lib/mongoose.js";

@modelOptions({ schemaOptions: { _id: false } })
@modelOptions({
schemaOptions: {
_id: false,
toJSON: {
transform: (doc, ret) => serializeObjectWithIds(ret),
},
},
})
export class Issue {
@prop({ required: true })
public url: string;
Expand All @@ -27,7 +34,13 @@ export class Issue {
}

@modelOptions({
schemaOptions: { _id: false, suppressReservedKeysWarning: true },
schemaOptions: {
_id: false,
suppressReservedKeysWarning: true,
toJSON: {
transform: (doc, ret) => serializeObjectWithIds(ret),
},
},
})
export class Issues {
@prop({ required: true })
Expand All @@ -38,7 +51,14 @@ export class Issues {
public notices: number = 0;
}

@modelOptions({ schemaOptions: { _id: false } })
@modelOptions({
schemaOptions: {
_id: false,
toJSON: {
transform: (doc, ret) => serializeObjectWithIds(ret),
},
},
})
export class Page {
@prop({ required: true })
public url: string;
Expand All @@ -56,7 +76,13 @@ export class Page {

@index({ status: 1, executionScheduledFor: 1 })
@modelOptions({
schemaOptions: { collection: "scans", versionKey: false },
schemaOptions: {
collection: "scans",
versionKey: false,
toJSON: {
transform: (doc, ret) => serializeObjectWithIds(ret),
},
},
options: { automaticName: false },
})
export class Scan {
Expand Down
28 changes: 13 additions & 15 deletions packages/storage/src/scanProfile/scanProfile.model.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { DocumentType, Ref } from "@typegoose/typegoose";
import { modelOptions, prop } from "@typegoose/typegoose";
import cronParser from "cron-parser";
import { CronExpressionParser } from "cron-parser";
import { ObjectId } from "mongodb";
import { Context, ContextModel } from "../context/context.model.js";
import { getModel } from "../lib/mongoose.js";
import { getModel, serializeObjectWithIds } from "../lib/mongoose.js";
import { ReturnModelType } from "@typegoose/typegoose/lib/types";
import { Scan, ScanModel } from "../scan/scan.model.js";

Expand All @@ -17,7 +17,10 @@ class CronSchedule {
schemaOptions: {
collection: "scanprofiles",
versionKey: false,
toJSON: { virtuals: true },
toJSON: {
virtuals: true,
transform: (doc, ret) => serializeObjectWithIds(ret),
},
toObject: { virtuals: true },
},
options: { automaticName: false },
Expand Down Expand Up @@ -79,7 +82,7 @@ export class ScanProfile {
match: { completedAt: { $exists: true } },
options: { sort: { completedAt: -1 } },
})
public lastScan: Scan | null = null;
public lastScan: Ref<Scan>;

@prop({
ref: () => "Scan",
Expand All @@ -89,7 +92,7 @@ export class ScanProfile {
match: { status: { $in: ["queued", "running"] } },
options: { sort: { executionScheduledFor: 1 } },
})
public nextScan: Scan | null = null;
public nextScan: Ref<Scan>;

public static async delete(
this: ReturnModelType<typeof ScanProfile>,
Expand All @@ -107,23 +110,18 @@ export class ScanProfile {
if (!context) {
return null;
}
const profiles = await ScanProfileModel.find({ context: contextId }).exec();
await Promise.all(
profiles.map(async (p) => {
await p.populate("nextScan");
await p.populate({ path: "lastScan", select: "-issues" });
}),
);
return profiles;
return await ScanProfileModel.find({ context: contextId })
.populate("nextScan")
.populate({ path: "lastScan", select: "-issues" })
.exec();
}

public nextExecution(this: DocumentType<ScanProfile>) {
if (!this.cronSchedule) {
return null;
}

return cronParser
.parseExpression(this.cronSchedule.expression)
return CronExpressionParser.parse(this.cronSchedule.expression)
.next()
.toDate();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/web2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ COPY packages/storage ./packages/storage
RUN corepack enable && yarn install

ENV NX_DAEMON=false
RUN yarn nx run web2:build
RUN yarn nx run build extension-a11y-checker-web2

FROM node:22-slim

Expand Down
32 changes: 0 additions & 32 deletions packages/web2/app.config.ts

This file was deleted.

Loading