Skip to content
Merged
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
5 changes: 4 additions & 1 deletion cspell.words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ esnext
SEPA
hsts
nosniff
csrf
csrf
jwtid
ILIKE
alice
239 changes: 119 additions & 120 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zibri",
"version": "2.4.0",
"version": "2.4.1",
"main": "./dist/cjs/index.js",
"types": "./dist/cjs/index.d.ts",
"module": "./dist/esm/index.mjs",
Expand Down Expand Up @@ -49,20 +49,20 @@
"license": "MIT",
"description": "TS Backend Framework",
"peerDependencies": {
"axios": "^1.15.0",
"axios": "^1.16.0",
"bcryptjs": "^3.0.3",
"bignumber.js": "^10.0.2",
"bignumber.js": "^11.1.1",
"handlebars": "^4.7.9",
"hi-base32": "^0.5.1",
"jsonwebtoken": "^9.0.3",
"otpauth": "^9.5.0",
"otpauth": "^9.5.1",
"pdfmake": "^0.2.2",
"preact": "^10.29.1",
"preact-render-to-string": "^6.6.7",
"rxjs": "^7.8.2",
"socket.io": "^4.8.3",
"ts-node": "^10.9.2",
"uuid": "^11.1.0",
"uuid": "^11.1.1",
"xmlbuilder2": "^4.0.3",
"cookie-parser": "^1.4.7"
},
Expand All @@ -72,19 +72,19 @@
"express": "^5.2.1",
"glob": "^13.0.6",
"node-cron": "^4.2.1",
"nodemailer": "^8.0.5",
"nodemailer": "^8.0.7",
"pg": "^8.20.0",
"prom-client": "^15.1.3",
"reflect-metadata": "^0.2.2",
"swagger-ui-express": "^5.0.1",
"swagger2openapi": "^7.0.8",
"systeminformation": "^5.31.5",
"typeorm": "^0.3.28"
"systeminformation": "^5.31.6",
"typeorm": "^0.3.29"
},
"devDependencies": {
"@faker-js/faker": "^9.9.0",
"@jest/globals": "^30.3.0",
"@swc/core": "^1.15.24",
"@swc/core": "^1.15.33",
"@testcontainers/postgresql": "^11.14.0",
"@types/cookie-parser": "^1.4.10",
"@types/cors": "^2.8.19",
Expand Down
5 changes: 2 additions & 3 deletions sandbox/src/create-default-data.function.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DataSourceInterface, HashServiceInterface, inject, JwtCredentials, JwtCredentialsCreateData, Newable, Repository, repositoryTokenFor, Transaction, ZIBRI_DI_TOKENS } from 'zibri';
import { DataSourceInterface, inject, JwtCredentials, JwtCredentialsCreateData, Newable, Repository, repositoryTokenFor, Transaction } from 'zibri';

import { logger } from '.';
import { Roles, User } from './models';
Expand All @@ -15,7 +15,6 @@ export async function createDefaultData(dataSourceClass: Newable<DataSourceInter
async function createDefaultAdmin(dataSource: DataSourceInterface): Promise<void> {
const userRepository: UserRepository = inject(UserRepository);
const credentialsRepository: Repository<JwtCredentials, JwtCredentialsCreateData> = inject(repositoryTokenFor(JwtCredentials));
const hashService: HashServiceInterface = inject(ZIBRI_DI_TOKENS.HASH_SERVICE);

const defaultUser: User | undefined = await userRepository.findOne({ where: { email: 'admin@test.com' } }, false);
if (defaultUser) {
Expand All @@ -27,7 +26,7 @@ async function createDefaultAdmin(dataSource: DataSourceInterface): Promise<void
try {
const user: User = await userRepository.create({ name: 'root', email: 'admin@test.com', roles: [Roles.ADMIN] }, { transaction });
await credentialsRepository.create(
{ email: user.email, password: await hashService.hash('password'), userId: user.id },
{ email: user.email, password: 'password', userId: user.id },
{ transaction }
);
await transaction.commit();
Expand Down
4 changes: 2 additions & 2 deletions sandbox/src/data-sources/db/db.data-source.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PostgresDataSource, PostgresOptions, BaseEntity, DataSource, Newable, MigrationEntity, JwtRefreshToken, JwtCredentials, PasswordResetToken, MailingList, MailingListSubscriber, MailingListSubscriptionConfirmationToken, Log, Change, ChangeSet, Entity, OmitClass, OtpCredentials, BackupResourceEntity, BackupEntity, Invoice, NumberInvoices, Email, CronJobEntity, ThreadJobEntity, WebsocketChannel, WebsocketMessage, Event, EventSubscriberRun, HashStrategyEntity, EncryptionStrategyEntity, EncryptionKey } from 'zibri';
import { PostgresDataSource, PostgresOptions, BaseEntity, DataSource, Newable, MigrationEntity, JwtRefreshToken, JwtCredentials, PasswordResetToken, MailingList, MailingListSubscriber, MailingListSubscriptionConfirmationToken, Log, Change, ChangeSet, Entity, OmitClass, OtpCredentials, BackupResourceEntity, BackupEntity, Invoice, NumberInvoices, Email, CronJobEntity, ThreadJobEntity, WebsocketChannel, WebsocketMessage, Event, EventSubscriberRun, HashStrategyEntity, EncryptionStrategyEntity, EncryptionKey, OmitStrict } from 'zibri';

import { Company, Test, User } from '../../models';

Expand All @@ -10,7 +10,7 @@ export class DbDataSource extends PostgresDataSource {
rootPw: string = 'password';
rootUsername: string = 'postgres';

options: PostgresOptions = {
options: OmitStrict<PostgresOptions, 'type' | 'entities'> = {
host: 'localhost',
port: 5432,
username: 'postgres',
Expand Down
2 changes: 1 addition & 1 deletion sandbox/src/models/company.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BaseEntity, Entity, Property } from 'zibri';

import { User } from './user.model';

@Entity()
@Entity({ defaultOrder: { workers: 'ASC' } })
export class Company extends BaseEntity {
@Property.oneToMany({ target: () => User, inverseSide: 'company' })
workers!: User[];
Expand Down
8 changes: 5 additions & 3 deletions sandbox/src/models/user.model.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { Entity, JwtCredentials, Property, BaseUserEntity, IntersectionClass, OmitClass } from 'zibri';
import { Entity, JwtCredentials, Property, BaseUserEntity, IntersectionClass, OmitClass, OmitStrict } from 'zibri';

import { Company } from './company.model';
import { Roles } from './roles.enum';
import { OmitStrict } from '../types';

@Entity()
export class User extends BaseUserEntity(Roles) {
@Property.string()
name!: string;

@Property.manyToOne({ target: () => Company, inverseSide: 'workers', required: false })
@Property.manyToOne({ target: () => Company, inverseSide: 'workers', joinColumn: 'companyId', required: false })
company?: Company;

@Property.string({ format: 'uuid', required: false })
companyId?: string;
}

export class UserCreateDto extends IntersectionClass(
Expand Down
1 change: 0 additions & 1 deletion sandbox/src/templates/components/cache-details-section.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// cache-detail-section.tsx
import type { Chart as ChartJsChart } from 'chart.js';
import { MetricsSnapshot, PreactComponent } from 'zibri';

Expand Down
1 change: 0 additions & 1 deletion sandbox/src/templates/components/stat-card.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// stat-card.tsx
import { ComponentChildren } from 'preact';
import { PreactComponent } from 'zibri';

Expand Down
1 change: 0 additions & 1 deletion sandbox/src/types/index.ts

This file was deleted.

4 changes: 0 additions & 4 deletions sandbox/src/types/omit-strict.type.ts

This file was deleted.

5 changes: 4 additions & 1 deletion src/__testing__/mocks/entities/child.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export class Child {
@Property.string()
name!: string;

@Property.manyToOne({ target: () => Parent, inverseSide: 'children' })
@Property.manyToOne({ target: () => Parent, joinColumn: 'parentId', inverseSide: 'children' })
parent!: Parent;

@Property.string({ format: 'uuid' })
parentId!: string;
}
7 changes: 5 additions & 2 deletions src/__testing__/mocks/entities/company.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import { BaseEntity } from '../../../entity/base-entity.model';
import { Entity } from '../../../entity/decorators/entity.decorator';
import { Property } from '../../../entity/decorators/property.decorator';

@Entity()
@Entity({ allowOrphan: true })
export class Company extends BaseEntity {
@Property.belongsToOne({ target: () => User, inverseSide: 'company' })
@Property.belongsToOne({ target: () => User, joinColumn: 'ownerId', inverseSide: 'company' })
owner!: User;

@Property.string({ format: 'uuid' })
ownerId!: string;
}
7 changes: 5 additions & 2 deletions src/__testing__/mocks/entities/profile.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ import { User } from './user.entity';
import { Entity } from '../../../entity/decorators/entity.decorator';
import { Property } from '../../../entity/decorators/property.decorator';

@Entity()
@Entity({ allowOrphan: true })
export class Profile {
@Property.string({ primary: true })
id!: string;

@Property.string()
bio!: string;

@Property.belongsToOne({ target: () => User, inverseSide: 'profile' })
@Property.belongsToOne({ target: () => User, joinColumn: 'userId', inverseSide: 'profile' })
user!: User;

@Property.string({ format: 'uuid' })
userId!: string;
}
2 changes: 1 addition & 1 deletion src/__testing__/mocks/entities/role.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { User } from './user.entity';
import { Entity } from '../../../entity/decorators/entity.decorator';
import { Property } from '../../../entity/decorators/property.decorator';

@Entity()
@Entity({ allowOrphan: true })
export class Role {
@Property.string({ primary: true })
id!: string;
Expand Down
2 changes: 1 addition & 1 deletion src/__testing__/mocks/entities/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Entity } from '../../../entity/decorators/entity.decorator';
import { Property } from '../../../entity/decorators/property.decorator';
import { OmitStrict } from '../../../types/omit-strict.type';

@Entity()
@Entity({ allowOrphan: true })
export class User {
@Property.string({ primary: true })
id!: string;
Expand Down
10 changes: 5 additions & 5 deletions src/__testing__/test-server/create-test-data-source.function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { JwtRefreshToken } from '../../auth/strategies/jwt/jwt-refresh-token.mod
import { ChangeSet } from '../../change-sets/models/change-set.model';
import { Change } from '../../change-sets/models/change.model';
import { CronJobEntity } from '../../cron/cron-job-entity.model';
import { PostgresDataSource, PostgresOptions } from '../../data-source/data-sources/postgres-data-source.model';
import { PostgresDataSource, PostgresOptions } from '../../data-source/data-sources/postgres-typeorm-data-source.model';
import { DataSource } from '../../data-source/decorators/data-source.decorator';
import { MigrationEntity } from '../../data-source/migration/migration-entity.model';
import { Email } from '../../email/models/email.model';
Expand All @@ -18,6 +18,7 @@ import { Event } from '../../event/event.model';
import { Log } from '../../logging/log.model';
import { ThreadJobEntity } from '../../multithreading/models/thread-job-entity.model';
import { Newable } from '../../types/newable.type';
import { OmitStrict } from '../../types/omit-strict.type';
import { WebsocketChannel } from '../../websocket/models/websocket-channel.model';
import { WebsocketMessage } from '../../websocket/models/websocket-message.model';
import { JwtUser } from '../mocks/entities/jwt-user.entity';
Expand Down Expand Up @@ -59,16 +60,15 @@ export function createTestDataSource({
username = 'postgres',
password = 'password',
database = 'db'
}: CreateTestDataSourceOptions = {}): Newable<PostgresDataSource> {
}: CreateTestDataSourceOptions = {}): Newable<PostgresDataSource & { entities: Newable<BaseEntity>[] }> {

@DataSource()
class DbDataSource extends PostgresDataSource {
options: PostgresOptions = {
options: OmitStrict<PostgresOptions, 'type' | 'entities'> = {
host,
username,
password,
database,
synchronize: true
database
};
entities: Newable<BaseEntity>[] = entities;
}
Expand Down
14 changes: 8 additions & 6 deletions src/__testing__/test-server/start-test-server.function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { defaultTestServerProviders } from './providers';
import './user-repository'; // this import is needed so that the DI system can pick up the user repository.
import { ZibriApplication } from '../../application';
import { ZibriApplicationOptions } from '../../application-options.model';
import { PostgresDataSource, PostgresOptions } from '../../data-source/data-sources/postgres-data-source.model';
import { PostgresDataSource, PostgresOptions } from '../../data-source/data-sources/postgres-typeorm-data-source.model';
import { ZIBRI_DI_TOKENS } from '../../di/default/zibri-di-tokens.default';
import { DiContainer } from '../../di/di-container';
import { inject } from '../../di/inject.function';
Expand All @@ -20,8 +20,9 @@ import { Newable } from '../../types/newable.type';
import { noOp, POSTGRES_TEST_IMAGE, testAssetsFolder } from '../constants';
import { createTestDataSource } from './create-test-data-source.function';
import { AssetServiceInterface } from '../../assets/asset-service.interface';
import { OmitStrict } from '../../types/omit-strict.type';

type StartTestServerOptions = Partial<Pick<ZibriApplicationOptions, 'providers' | 'plugins' | 'controllers'>> & {
type StartTestServerOptions = Partial<Pick<ZibriApplicationOptions, 'providers' | 'plugins' | 'controllers' | 'cronJobs'>> & {
dataSources?: Newable<PostgresDataSource>[]
};

Expand Down Expand Up @@ -56,7 +57,8 @@ export async function startTestServer(
dataSources = [createTestDataSource()],
providers = defaultTestServerProviders,
plugins = defaultTestServerPlugins,
controllers = []
controllers = [],
cronJobs = []
}: StartTestServerOptions = {}
): Promise<StartedTestServer> {
// Reset singleton — every test file gets a clean container with no stale instances.
Expand All @@ -69,8 +71,7 @@ export async function startTestServer(
.withUsername(dataSource.options.username ?? 'postgres')
.withPassword(dataSource.options.password?.toString() ?? 'password')
.start();
// eslint-disable-next-line typescript/no-unnecessary-type-assertion
(dataSource.options as PostgresOptions) = {
(dataSource.options as OmitStrict<PostgresOptions, 'type' | 'entities'>) = {
...dataSource.options,
port: container.getMappedPort(5432)
};
Expand All @@ -93,7 +94,8 @@ export async function startTestServer(
websocketControllers: [],
dataSources,
providers,
plugins
plugins,
cronJobs
});

await app.init(H);
Expand Down
7 changes: 4 additions & 3 deletions src/__testing__/test-server/user-repository.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { UserRepo } from '../../auth/decorators/user-repo.decorator';
import { JwtCredentials } from '../../auth/strategies/jwt/jwt-credentials.model';
import { UserRepositoryInterface } from '../../auth/user/user-repository.interface';
import { getDefaultBeforeReturnHook, getDefaultBeforeSaveHook } from '../../data-source/hooks/hooks.default';
import { Repository } from '../../data-source/repository';
import { InjectRepository } from '../../di/decorators/inject-repository.decorator';
import { Inject } from '../../di/decorators/inject.decorator';
Expand All @@ -18,17 +19,17 @@ export class DefaultTestServerUserRepository extends Repository<JwtUser>
repo: Repository<JwtUser>,
@Inject(ZIBRI_DI_TOKENS.LOGGER)
logger: LoggerInterface,
@InjectRepository(JwtUser)
@InjectRepository(JwtCredentials)
private readonly credentialsRepository: Repository<JwtCredentials>
) {
super(JwtUser, repo, logger, repo.dataSource);
super(JwtUser, repo, logger, repo.dataSource, getDefaultBeforeSaveHook(), getDefaultBeforeReturnHook());
}

async findByEmail(email: string): Promise<JwtUser> {
return await this.findOne({ where: { email } });
}

async resolveCredentialsFor(user: JwtUser): Promise<JwtCredentials> {
return this.credentialsRepository.findOne({ where: { userId: user.id } });
return await this.credentialsRepository.findOne({ where: { userId: user.id } });
}
}
10 changes: 8 additions & 2 deletions src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,10 @@ export class ZibriApplication {
for (const [signal, handler] of this.signalHandlers) {
process.off(signal, handler);
}
process.exit(0);
if (signal != undefined) {
process.exit(0);
}
return;
}
case AppState.INITIALIZED:
case AppState.STARTED: {
Expand All @@ -256,7 +259,10 @@ export class ZibriApplication {
await this.onAppShutdown(injectables, signal);
await this.afterAppShutdown(injectables, signal);

process.exit(0);
if (signal != undefined) {
process.exit(0);
}
return;
}
}
}
Expand Down
Loading
Loading