@velony/domain 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.prettierrc ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "singleQuote": true,
3
+ "trailingComma": "all"
4
+ }
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 VelonY
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,55 @@
1
+ import eslint from '@eslint/js';
2
+ import tseslint from 'typescript-eslint';
3
+ import securityPlugin from 'eslint-plugin-security';
4
+ import prettierPlugin from 'eslint-plugin-prettier/recommended';
5
+ import prettierConfig from 'eslint-config-prettier';
6
+
7
+ export default [
8
+ // Base configs
9
+ eslint.configs.recommended,
10
+ ...tseslint.configs.recommended,
11
+
12
+ {
13
+ settings: {
14
+ 'import/resolver': {
15
+ typescript: {
16
+ project: './tsconfig.json',
17
+ },
18
+ },
19
+ },
20
+ },
21
+
22
+ // Security
23
+ securityPlugin.configs.recommended,
24
+
25
+ // TypeScript-specific rules
26
+ {
27
+ files: ['**/*.ts'],
28
+ rules: {
29
+ 'no-console': 'warn',
30
+ '@typescript-eslint/no-unused-vars': [
31
+ 'warn',
32
+ {
33
+ argsIgnorePattern: '^_',
34
+ varsIgnorePattern: '^_',
35
+ caughtErrorsIgnorePattern: '^_',
36
+ },
37
+ ],
38
+ '@typescript-eslint/interface-name-prefix': 'off',
39
+ '@typescript-eslint/explicit-function-return-type': 'off',
40
+ '@typescript-eslint/explicit-module-boundary-types': 'off',
41
+ '@typescript-eslint/no-explicit-any': 'off',
42
+ },
43
+ },
44
+
45
+ // Prettier integration
46
+ prettierPlugin,
47
+
48
+ // Ignore patterns
49
+ {
50
+ ignores: ['node_modules/', 'dist/', '.eslintrc.js', 'eslint.config.mjs'],
51
+ },
52
+
53
+ // Disable rules conflicting with Prettier (must be last)
54
+ prettierConfig,
55
+ ];
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@velony/domain",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "build": "tsc",
8
+ "lint": "eslint src"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/velony-ai/domain.git"
13
+ },
14
+ "author": "velony-ai",
15
+ "license": "MIT",
16
+ "bugs": {
17
+ "url": "https://github.com/velony-ai/domain/issues"
18
+ },
19
+ "homepage": "https://github.com/velony-ai/domain#readme",
20
+ "devDependencies": {
21
+ "@eslint/js": "^9.39.2",
22
+ "eslint": "^9.39.2",
23
+ "eslint-config-prettier": "^10.1.8",
24
+ "eslint-plugin-prettier": "^5.5.4",
25
+ "eslint-plugin-security": "^3.0.1",
26
+ "typescript": "^5.9.3",
27
+ "typescript-eslint": "^8.51.0"
28
+ },
29
+ "dependencies": {
30
+ "uuid": "^13.0.0"
31
+ }
32
+ }
package/src/Id.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { PrimitiveValueObject } from './primitive-value-object';
2
+
3
+ declare const ID_BRAND: unique symbol;
4
+
5
+ export abstract class Id<
6
+ T extends string | number,
7
+ > extends PrimitiveValueObject<T> {
8
+ private readonly [ID_BRAND]: void;
9
+ }
@@ -0,0 +1,23 @@
1
+ import { DomainEvent } from './domain-event';
2
+ import { Entity } from './entity';
3
+ import { Id } from './Id';
4
+
5
+ declare const AGGREGATE_ROOT_BRAND: unique symbol;
6
+
7
+ export abstract class AggregateRoot<
8
+ TIdentifier extends Id<string | number>,
9
+ > extends Entity<TIdentifier> {
10
+ private readonly [AGGREGATE_ROOT_BRAND]: void;
11
+
12
+ private _domainEvents: DomainEvent<any>[] = [];
13
+
14
+ public pullDomainEvents(): DomainEvent<any>[] {
15
+ const events = [...this._domainEvents];
16
+ this._domainEvents = [];
17
+ return events;
18
+ }
19
+
20
+ protected addDomainEvent(event: DomainEvent<any>): void {
21
+ this._domainEvents.push(event);
22
+ }
23
+ }
@@ -0,0 +1,25 @@
1
+ import { v7 as uuidv7 } from 'uuid';
2
+
3
+ export declare const DOMAIN_EVENT_BRAND: unique symbol;
4
+
5
+ export abstract class DomainEvent<TPayload> {
6
+ private readonly [DOMAIN_EVENT_BRAND]: void;
7
+
8
+ public static readonly type: string;
9
+
10
+ public readonly id: string;
11
+ public readonly aggregateId: string;
12
+ public readonly payload: TPayload;
13
+ public readonly occurredAt: Date;
14
+
15
+ protected constructor(aggregateId: string, payload: TPayload) {
16
+ this.id = uuidv7();
17
+ this.aggregateId = aggregateId;
18
+ this.occurredAt = new Date();
19
+ this.payload = payload;
20
+ }
21
+
22
+ public get type(): string {
23
+ return (this.constructor as typeof DomainEvent<TPayload>).type;
24
+ }
25
+ }
package/src/entity.ts ADDED
@@ -0,0 +1,21 @@
1
+ import { Id } from './Id';
2
+
3
+ declare const ENTITY_BRAND: unique symbol;
4
+
5
+ export abstract class Entity<TIdentifier extends Id<string | number>> {
6
+ private readonly [ENTITY_BRAND]: void;
7
+
8
+ protected readonly _id: TIdentifier;
9
+
10
+ protected constructor(id: TIdentifier) {
11
+ this._id = id;
12
+ }
13
+
14
+ public get id(): TIdentifier {
15
+ return this._id;
16
+ }
17
+
18
+ public equals(other: this): boolean {
19
+ return this._id.equals(other._id);
20
+ }
21
+ }
@@ -0,0 +1,17 @@
1
+ import { ValueObject } from './value-object';
2
+
3
+ declare const PRIMITIVE_VO_BRAND: unique symbol;
4
+
5
+ export abstract class PrimitiveValueObject<
6
+ T extends string | number | boolean,
7
+ > extends ValueObject<T> {
8
+ private readonly [PRIMITIVE_VO_BRAND]: void;
9
+
10
+ public equals(other: this): boolean {
11
+ return this._value === other.value;
12
+ }
13
+
14
+ public toString(): string {
15
+ return String(this._value);
16
+ }
17
+ }
@@ -0,0 +1,19 @@
1
+ declare const VO_BRAND: unique symbol;
2
+
3
+ export abstract class ValueObject<TValue> {
4
+ private readonly [VO_BRAND]: void;
5
+
6
+ protected readonly _value: TValue;
7
+
8
+ protected constructor(value: TValue) {
9
+ this._value = value;
10
+ }
11
+
12
+ public get value(): TValue {
13
+ return this._value;
14
+ }
15
+
16
+ public abstract equals(other: this): boolean;
17
+
18
+ public abstract toString(): string;
19
+ }
@@ -0,0 +1,34 @@
1
+ import { PrimitiveValueObject } from '../primitive-value-object';
2
+
3
+ declare const STORAGE_PATH_VO_BRAND: unique symbol;
4
+
5
+ export class StoragePath extends PrimitiveValueObject<string> {
6
+ private readonly [STORAGE_PATH_VO_BRAND]: void;
7
+
8
+ private constructor(value: string) {
9
+ super(value);
10
+ }
11
+
12
+ public static create(value: string): StoragePath {
13
+ if (value.startsWith('/')) {
14
+ throw new Error('Storage path should not start with /');
15
+ }
16
+ if (value.includes('//')) {
17
+ throw new Error('Storage path contains invalid double slashes');
18
+ }
19
+ if (value.includes('..')) {
20
+ throw new Error('Storage path cannot contain ..');
21
+ }
22
+
23
+ return new StoragePath(value);
24
+ }
25
+
26
+ public toUrl(baseUrl: string): string {
27
+ return `${baseUrl.replace(/\/$/, '')}/${this._value}`;
28
+ }
29
+
30
+ public get extension(): string {
31
+ const parts = this._value.split('.');
32
+ return parts.at(-1)?.toLowerCase() ?? '';
33
+ }
34
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "nodenext",
4
+ "moduleResolution": "nodenext",
5
+ "resolvePackageJsonExports": true,
6
+ "esModuleInterop": true,
7
+ "isolatedModules": true,
8
+ "declaration": true,
9
+ "removeComments": true,
10
+ "allowSyntheticDefaultImports": true,
11
+ "target": "ES2023",
12
+ "sourceMap": true,
13
+ "outDir": "./dist",
14
+ "rootDir": "./src",
15
+ "baseUrl": "./",
16
+ "incremental": true,
17
+ "skipLibCheck": true,
18
+ "strictNullChecks": true,
19
+ "forceConsistentCasingInFileNames": true
20
+ },
21
+ "include": ["src"],
22
+ "exclude": ["node_modules", "dist"]
23
+ }