@schorts/shared-kernel 4.2.1 → 4.2.3
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/README.md +2 -0
- package/dist/cjs/value-objects/array-value.js +8 -0
- package/dist/cjs/value-objects/array-value.js.map +1 -1
- package/dist/cjs/value-objects/index.js +3 -1
- package/dist/cjs/value-objects/index.js.map +1 -1
- package/dist/cjs/value-objects/object-value.js +2 -0
- package/dist/cjs/value-objects/object-value.js.map +1 -1
- package/dist/cjs/value-objects/url-value.js +23 -0
- package/dist/cjs/value-objects/url-value.js.map +1 -0
- package/dist/esm/value-objects/array-value.js +8 -0
- package/dist/esm/value-objects/array-value.js.map +1 -1
- package/dist/esm/value-objects/index.js +3 -1
- package/dist/esm/value-objects/index.js.map +1 -1
- package/dist/esm/value-objects/object-value.js +2 -0
- package/dist/esm/value-objects/object-value.js.map +1 -1
- package/dist/esm/value-objects/url-value.js +23 -0
- package/dist/esm/value-objects/url-value.js.map +1 -0
- package/dist/types/value-objects/array-value.d.ts +5 -1
- package/dist/types/value-objects/array-value.d.ts.map +1 -1
- package/dist/types/value-objects/index.d.ts +1 -0
- package/dist/types/value-objects/index.d.ts.map +1 -1
- package/dist/types/value-objects/object-value.d.ts +2 -0
- package/dist/types/value-objects/object-value.d.ts.map +1 -1
- package/dist/types/value-objects/url-value.d.ts +11 -0
- package/dist/types/value-objects/url-value.d.ts.map +1 -0
- package/package.json +11 -3
- package/.idx/airules.md +0 -186
- package/.idx/dev.nix +0 -54
- package/.vscode/settings.json +0 -7
- package/CHANGELOG +0 -363
- package/__tests__/auth/auth-provider.test.ts +0 -50
- package/__tests__/auth/require-auth.decorator.test.ts +0 -88
- package/__tests__/criteria/criteria.test.ts +0 -159
- package/__tests__/criteria/direction.test.ts +0 -11
- package/__tests__/criteria/filter-criterion.test.ts +0 -15
- package/__tests__/criteria/operator.test.ts +0 -22
- package/__tests__/criteria/order.test.ts +0 -14
- package/__tests__/dao/dao.test.ts +0 -126
- package/__tests__/domain-events/domain-event-primitives.test.ts +0 -34
- package/__tests__/domain-events/domain-event.test.ts +0 -50
- package/__tests__/entities/entity-registry.test.ts +0 -71
- package/__tests__/entities/entity.test.ts +0 -114
- package/__tests__/entities/register-entity.decorator.test.ts +0 -54
- package/__tests__/formatters/pascal-camel-to-snake.test.ts +0 -19
- package/__tests__/http/fetch-http-provider.test.ts +0 -155
- package/__tests__/http/http-provider.test.ts +0 -55
- package/__tests__/json-api/json-api-connector.test.ts +0 -78
- package/__tests__/json-api/json-api-list.test.ts +0 -24
- package/__tests__/json-api/json-api-single.test.ts +0 -24
- package/__tests__/json-api/url-criteria-builder.test.ts +0 -74
- package/__tests__/messages/message.test.ts +0 -16
- package/__tests__/models/base-model.test.ts +0 -10
- package/__tests__/state-manager/state-manager.test.ts +0 -101
- package/__tests__/unit-of-work/unit-of-work.test.ts +0 -47
- package/__tests__/utils/url/url-with-params-builder.test.ts +0 -39
- package/__tests__/value-objects/coordinates-value.test.ts +0 -68
- package/__tests__/value-objects/email-value.test.ts +0 -43
- package/__tests__/value-objects/enum-value.test.ts +0 -51
- package/__tests__/value-objects/integer-value.test.ts +0 -115
- package/__tests__/value-objects/phone-value.test.ts +0 -82
- package/__tests__/value-objects/slug-value.test.ts +0 -43
- package/__tests__/value-objects/string-value.test.ts +0 -121
- package/__tests__/value-objects/uuid-value.test.ts +0 -67
- package/__tests__/value-objects/value-object.test.ts +0 -25
- package/jest.config.js +0 -25
- package/src/abac/index.ts +0 -1
- package/src/abac/predicate.ts +0 -3
- package/src/auth/auth-provider.ts +0 -11
- package/src/auth/exceptions/index.ts +0 -2
- package/src/auth/exceptions/not-authenticated.ts +0 -11
- package/src/auth/exceptions/require-auth-not-implemented-correctly.ts +0 -11
- package/src/auth/index.ts +0 -3
- package/src/auth/require-auth.decorator.ts +0 -42
- package/src/converters/index.ts +0 -1
- package/src/converters/remote-file-to-base64.ts +0 -19
- package/src/criteria/criteria.ts +0 -46
- package/src/criteria/direction.ts +0 -1
- package/src/criteria/exceptions/index.ts +0 -2
- package/src/criteria/exceptions/limit-not-valid.ts +0 -11
- package/src/criteria/exceptions/offset-not-valid.ts +0 -11
- package/src/criteria/index.ts +0 -5
- package/src/criteria/operator.ts +0 -12
- package/src/criteria/order.ts +0 -4
- package/src/dao/dao.ts +0 -16
- package/src/dao/index.ts +0 -1
- package/src/domain-events/domain-event-primitives.ts +0 -10
- package/src/domain-events/domain-event-registry.ts +0 -40
- package/src/domain-events/domain-event.ts +0 -29
- package/src/domain-events/exceptions/domain-event-not-registered.ts +0 -11
- package/src/domain-events/exceptions/index.ts +0 -1
- package/src/domain-events/index.ts +0 -4
- package/src/entities/entity-registry.ts +0 -30
- package/src/entities/entity.ts +0 -25
- package/src/entities/exceptions/entity-not-registered.ts +0 -11
- package/src/entities/exceptions/index.ts +0 -1
- package/src/entities/index.ts +0 -4
- package/src/entities/register-entity.decorator.ts +0 -16
- package/src/event-bus/event-store.ts +0 -9
- package/src/event-bus/event-subscriber.ts +0 -5
- package/src/event-bus/in-memory/async-in-memory-event-bus.ts +0 -67
- package/src/event-bus/in-memory/in-memory-event-store.ts +0 -28
- package/src/event-bus/in-memory/index.ts +0 -2
- package/src/event-bus/index.ts +0 -3
- package/src/formatters/index.ts +0 -1
- package/src/formatters/pascal-camel-to-snake.ts +0 -8
- package/src/http/exceptions/http-exception.ts +0 -8
- package/src/http/exceptions/index.ts +0 -1
- package/src/http/fetch-http-provider.ts +0 -151
- package/src/http/http-interceptor.ts +0 -3
- package/src/http/http-provider.ts +0 -7
- package/src/http/index.ts +0 -5
- package/src/i18n/index.ts +0 -2
- package/src/i18n/shared-kernel-translation-keys.ts +0 -19
- package/src/i18n/translation-resolver.ts +0 -3
- package/src/index.ts +0 -21
- package/src/json-api/exceptions/index.ts +0 -1
- package/src/json-api/exceptions/json-api-errors.ts +0 -17
- package/src/json-api/index.ts +0 -5
- package/src/json-api/json-api-connector.ts +0 -97
- package/src/json-api/json-api-list.ts +0 -13
- package/src/json-api/json-api-single.ts +0 -13
- package/src/json-api/url-criteria-builder.ts +0 -49
- package/src/messages/index.ts +0 -1
- package/src/messages/message.ts +0 -3
- package/src/models/base-model.ts +0 -3
- package/src/models/index.ts +0 -1
- package/src/pub-sub/index.ts +0 -2
- package/src/pub-sub/publisher.ts +0 -3
- package/src/pub-sub/subscription.ts +0 -6
- package/src/rbac/base-resource.ts +0 -3
- package/src/rbac/exceptions/index.ts +0 -1
- package/src/rbac/exceptions/not-authorized.ts +0 -1
- package/src/rbac/index.ts +0 -5
- package/src/rbac/permission.ts +0 -4
- package/src/rbac/rbac-policy.ts +0 -41
- package/src/result/index.ts +0 -1
- package/src/result/result.ts +0 -35
- package/src/state-manager/in-memory-state-manager.ts +0 -22
- package/src/state-manager/index.ts +0 -3
- package/src/state-manager/session-storage-state-manager.ts +0 -47
- package/src/state-manager/state-manager.ts +0 -28
- package/src/telemetry/console-telemetry.ts +0 -27
- package/src/telemetry/index.ts +0 -2
- package/src/telemetry/telemetry.ts +0 -5
- package/src/unit-of-work/index.ts +0 -1
- package/src/unit-of-work/unit-of-work.ts +0 -5
- package/src/utils/index.ts +0 -2
- package/src/utils/url/index.ts +0 -1
- package/src/utils/url/url-with-params-builder.ts +0 -19
- package/src/utils/value-objects/index.ts +0 -1
- package/src/utils/value-objects/rule.ts +0 -3
- package/src/value-objects/array-value.ts +0 -92
- package/src/value-objects/boolean-value.ts +0 -23
- package/src/value-objects/coordinates-value.ts +0 -50
- package/src/value-objects/date-value.ts +0 -36
- package/src/value-objects/email-value.ts +0 -25
- package/src/value-objects/enum-value.ts +0 -27
- package/src/value-objects/exceptions/index.ts +0 -2
- package/src/value-objects/exceptions/value-not-valid.ts +0 -3
- package/src/value-objects/exceptions/values-not-valid.ts +0 -11
- package/src/value-objects/float-valuet.ts +0 -39
- package/src/value-objects/index.ts +0 -17
- package/src/value-objects/integer-value.ts +0 -29
- package/src/value-objects/object-value.ts +0 -84
- package/src/value-objects/phone-value.ts +0 -53
- package/src/value-objects/slug-value.ts +0 -25
- package/src/value-objects/string-value.ts +0 -27
- package/src/value-objects/uuid-value.ts +0 -34
- package/src/value-objects/value-object.ts +0 -7
- package/tsconfig.cjs.json +0 -13
- package/tsconfig.esm.json +0 -12
- package/tsconfig.json +0 -47
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { TranslationResolver } from "../../i18n";
|
|
2
|
-
|
|
3
|
-
export class OffsetNotValid extends Error {
|
|
4
|
-
constructor(offset: number, translationResolver?: TranslationResolver) {
|
|
5
|
-
const message = translationResolver
|
|
6
|
-
? translationResolver.resolve("criteria.errors.offset_not_valid", { offset })
|
|
7
|
-
: `Offset Not Valid: ${offset}`;
|
|
8
|
-
|
|
9
|
-
super(message);
|
|
10
|
-
}
|
|
11
|
-
}
|
package/src/criteria/index.ts
DELETED
package/src/criteria/operator.ts
DELETED
package/src/criteria/order.ts
DELETED
package/src/dao/dao.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { BaseModel } from "../models";
|
|
2
|
-
import { Entity as BaseEntity } from "../entities";
|
|
3
|
-
import { Criteria } from "../criteria";
|
|
4
|
-
import { UnitOfWork } from "../unit-of-work";
|
|
5
|
-
import { ValueObject } from "../value-objects";
|
|
6
|
-
|
|
7
|
-
export interface DAO<Model extends BaseModel, Entity extends BaseEntity<ValueObject, Model>> {
|
|
8
|
-
getAll(): Promise<Entity[]>;
|
|
9
|
-
findByID(id: Entity["id"]["value"]): Promise<Entity | null>;
|
|
10
|
-
findOneBy(criteria: Criteria): Promise<Entity | null>;
|
|
11
|
-
search(criteria: Criteria): Promise<Entity[]>;
|
|
12
|
-
countBy(criteria: Criteria): Promise<number>;
|
|
13
|
-
create(entity: Entity, uow?: UnitOfWork): Promise<Entity>;
|
|
14
|
-
update(entity: Entity, uow?: UnitOfWork): Promise<Entity>;
|
|
15
|
-
delete(entity: Entity, uow?: UnitOfWork): Promise<Entity>;
|
|
16
|
-
}
|
package/src/dao/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type { DAO } from "./dao";
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { DomainEvent, DomainEventPrimitives } from ".";
|
|
2
|
-
import { DomainEventNotRegistered } from "./exceptions";
|
|
3
|
-
|
|
4
|
-
type DomainEventConstructor<PayloadSchema = any> = {
|
|
5
|
-
new (
|
|
6
|
-
id: string,
|
|
7
|
-
occurredAt: Date,
|
|
8
|
-
type: string,
|
|
9
|
-
version: number,
|
|
10
|
-
payload: PayloadSchema,
|
|
11
|
-
meta: {
|
|
12
|
-
retries: number,
|
|
13
|
-
},
|
|
14
|
-
): DomainEvent<PayloadSchema>;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export class DomainEventRegistry {
|
|
18
|
-
private static registry = new Map<string, DomainEventConstructor>();
|
|
19
|
-
|
|
20
|
-
static register(eventName: string, constructor: DomainEventConstructor): void {
|
|
21
|
-
this.registry.set(eventName, constructor);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
static create(primitives: DomainEventPrimitives): DomainEvent {
|
|
25
|
-
const Constructor = this.registry.get(primitives.type);
|
|
26
|
-
|
|
27
|
-
if (!Constructor) {
|
|
28
|
-
throw new DomainEventNotRegistered(primitives.type);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return new Constructor(
|
|
32
|
-
primitives.id,
|
|
33
|
-
new Date(primitives.occurred_at),
|
|
34
|
-
primitives.type,
|
|
35
|
-
primitives.version,
|
|
36
|
-
primitives.payload,
|
|
37
|
-
primitives.meta,
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Message } from "../messages";
|
|
2
|
-
import { DomainEventPrimitives } from "./domain-event-primitives";
|
|
3
|
-
|
|
4
|
-
export abstract class DomainEvent<PayloadSchema = {}> implements Message<DomainEventPrimitives<PayloadSchema>> {
|
|
5
|
-
constructor(
|
|
6
|
-
readonly id: string,
|
|
7
|
-
readonly occurredAt: Date,
|
|
8
|
-
readonly type: string,
|
|
9
|
-
readonly version: number,
|
|
10
|
-
readonly payload: PayloadSchema,
|
|
11
|
-
public meta = { retries: 0 },
|
|
12
|
-
) {}
|
|
13
|
-
|
|
14
|
-
abstract getEventName(): string;
|
|
15
|
-
|
|
16
|
-
toPrimitives(): DomainEventPrimitives<PayloadSchema> {
|
|
17
|
-
return {
|
|
18
|
-
id: this.id,
|
|
19
|
-
occurred_at: this.occurredAt.toString(),
|
|
20
|
-
type: this.type,
|
|
21
|
-
version: this.version,
|
|
22
|
-
payload: this.payload,
|
|
23
|
-
meta: this.meta,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
ack?: () => void;
|
|
28
|
-
requeue?: () => void;
|
|
29
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { TranslationResolver } from "../../i18n";
|
|
2
|
-
|
|
3
|
-
export class DomainEventNotRegistered extends Error {
|
|
4
|
-
constructor(domainEventName: string, translationResolver?: TranslationResolver) {
|
|
5
|
-
const message = translationResolver
|
|
6
|
-
? translationResolver.resolve("domain_events.errors.domain_event_not_registered")
|
|
7
|
-
: `DomainEvent Not Registered: ${domainEventName}`;
|
|
8
|
-
|
|
9
|
-
super(message);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { DomainEventNotRegistered } from "./domain-event-not-registered";
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { BaseModel } from "../models";
|
|
2
|
-
import { Entity } from "./entity";
|
|
3
|
-
import { EntityNotRegistered } from "./exceptions";
|
|
4
|
-
import { ValueObject } from "../value-objects";
|
|
5
|
-
|
|
6
|
-
type EntityConstructor<Model extends BaseModel = BaseModel> = {
|
|
7
|
-
fromPrimitives(model: Model): Entity<ValueObject, Model>;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export class EntityRegistry {
|
|
11
|
-
private static registry = new Map<string, EntityConstructor>();
|
|
12
|
-
|
|
13
|
-
static register<Model extends BaseModel>(tableOrCollectionName: string, entity: EntityConstructor<Model>): void {
|
|
14
|
-
this.registry.set(tableOrCollectionName, entity);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
static resolve<Model extends BaseModel>(tableOrCollectionName: string): EntityConstructor<Model> | null {
|
|
18
|
-
return (this.registry.get(tableOrCollectionName) || null) as EntityConstructor<Model> | null;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
static create<Model extends BaseModel>(tableOrCollectionName: string, model: Model): Entity<ValueObject, Model> {
|
|
22
|
-
const entity = this.resolve<Model>(tableOrCollectionName);
|
|
23
|
-
|
|
24
|
-
if (!entity) {
|
|
25
|
-
throw new EntityNotRegistered(tableOrCollectionName);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return entity.fromPrimitives(model);
|
|
29
|
-
}
|
|
30
|
-
}
|
package/src/entities/entity.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { ValueObject } from "../value-objects";
|
|
2
|
-
import { BaseModel } from "../models";
|
|
3
|
-
import { DomainEvent } from "../domain-events";
|
|
4
|
-
|
|
5
|
-
export abstract class Entity<IDValue extends ValueObject, Model extends BaseModel> {
|
|
6
|
-
private domainEvents: Array<DomainEvent> = [];
|
|
7
|
-
|
|
8
|
-
constructor(readonly id: IDValue) {}
|
|
9
|
-
|
|
10
|
-
pullDomainEvents(): Array<DomainEvent> {
|
|
11
|
-
const domainEvents = [...this.domainEvents];
|
|
12
|
-
this.domainEvents = [];
|
|
13
|
-
|
|
14
|
-
return domainEvents;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
recordDomainEvent(domainEvent: DomainEvent): void {
|
|
18
|
-
this.domainEvents.push(domainEvent);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
abstract toPrimitives(): Model;
|
|
22
|
-
static fromPrimitives<Model extends BaseModel>(_model: Model) {
|
|
23
|
-
throw new Error("Method not implemented.");
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { TranslationResolver } from "../../i18n";
|
|
2
|
-
|
|
3
|
-
export class EntityNotRegistered extends Error {
|
|
4
|
-
constructor(tableOrCollectionName: string, translationResolver?: TranslationResolver) {
|
|
5
|
-
const message = translationResolver
|
|
6
|
-
? translationResolver.resolve("entities.errors.entity_not_registered")
|
|
7
|
-
: `Entity Not Registered: ${tableOrCollectionName}`;
|
|
8
|
-
|
|
9
|
-
super(message);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { EntityNotRegistered } from "./entity-not-registered";
|
package/src/entities/index.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { EntityRegistry } from "./entity-registry";
|
|
2
|
-
import { BaseModel } from "../models";
|
|
3
|
-
import { Entity as BaseEntity } from "./entity";
|
|
4
|
-
import { ValueObject } from "../value-objects";
|
|
5
|
-
|
|
6
|
-
type EntityConstructor<Model extends BaseModel = BaseModel> = {
|
|
7
|
-
fromPrimitives(model: Model): BaseEntity<ValueObject, Model>;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export function RegisterEntity<Model extends BaseModel = BaseModel>(type: string) {
|
|
11
|
-
return function <Entity extends EntityConstructor<Model>>(entity: Entity): Entity {
|
|
12
|
-
EntityRegistry.register(type, entity);
|
|
13
|
-
|
|
14
|
-
return entity;
|
|
15
|
-
};
|
|
16
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { DomainEventPrimitives } from "../domain-events";
|
|
2
|
-
|
|
3
|
-
export interface EventStore {
|
|
4
|
-
save(primitives: DomainEventPrimitives): void;
|
|
5
|
-
all(): DomainEventPrimitives[];
|
|
6
|
-
delete(id: string): void;
|
|
7
|
-
requeue(primitives: DomainEventPrimitives): void;
|
|
8
|
-
clear(): void;
|
|
9
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { DomainEvent, DomainEventRegistry } from "../../domain-events";
|
|
2
|
-
import { InMemoryEventStore } from "./in-memory-event-store";
|
|
3
|
-
import { EventStore } from "../event-store";
|
|
4
|
-
import { EventSubscriber } from "../event-subscriber";
|
|
5
|
-
|
|
6
|
-
export class AsyncInMemoryEventBus {
|
|
7
|
-
private readonly subscribers = new Map<string, EventSubscriber[]>();
|
|
8
|
-
private readonly store: EventStore;
|
|
9
|
-
private readonly maxRetries: number;
|
|
10
|
-
|
|
11
|
-
constructor(store: EventStore = new InMemoryEventStore(), maxRetries = 3) {
|
|
12
|
-
this.store = store;
|
|
13
|
-
this.maxRetries = maxRetries;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
subscribe<Event extends DomainEvent>(eventName: string, subscriber: EventSubscriber<Event>): void {
|
|
17
|
-
if (!this.subscribers.has(eventName)) {
|
|
18
|
-
this.subscribers.set(eventName, []);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
this.subscribers.get(eventName)!.push(subscriber);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async publish<Event extends DomainEvent>(event: Event): Promise<void> {
|
|
25
|
-
const primitives = event.toPrimitives();
|
|
26
|
-
|
|
27
|
-
this.store.save(primitives);
|
|
28
|
-
|
|
29
|
-
await this.dispatch(event);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
private async dispatch(event: DomainEvent): Promise<void> {
|
|
33
|
-
const eventName = event.getEventName();
|
|
34
|
-
const subs = this.subscribers.get(eventName) ?? [];
|
|
35
|
-
const primitives = event.toPrimitives();
|
|
36
|
-
|
|
37
|
-
event.ack = () => this.store.delete(event.id);
|
|
38
|
-
event.requeue = () => {
|
|
39
|
-
event.ack?.();
|
|
40
|
-
|
|
41
|
-
if (event.meta.retries < this.maxRetries) {
|
|
42
|
-
const updatedPrimitives = {
|
|
43
|
-
...primitives,
|
|
44
|
-
meta: { ...primitives.meta, retries: event.meta.retries + 1 },
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
this.store.requeue(updatedPrimitives);
|
|
48
|
-
this.publish(DomainEventRegistry.create(updatedPrimitives));
|
|
49
|
-
} else {
|
|
50
|
-
console.warn(`Event ${event.id} exceeded max retries (${this.maxRetries}). Dropping.`);
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
for (const sub of subs) {
|
|
55
|
-
await sub.handle(event);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async replay(): Promise<void> {
|
|
60
|
-
const events = this.store.all();
|
|
61
|
-
|
|
62
|
-
for (const primitives of events) {
|
|
63
|
-
const event = DomainEventRegistry.create(primitives);
|
|
64
|
-
await this.dispatch(event);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { DomainEventPrimitives } from "../../domain-events";
|
|
2
|
-
import { EventStore } from "../event-store";
|
|
3
|
-
|
|
4
|
-
export class InMemoryEventStore implements EventStore {
|
|
5
|
-
private readonly events: DomainEventPrimitives[] = [];
|
|
6
|
-
|
|
7
|
-
save(primitives: DomainEventPrimitives): void {
|
|
8
|
-
this.events.push(primitives);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
all(): DomainEventPrimitives[] {
|
|
12
|
-
return [...this.events];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
delete(id: string): void {
|
|
16
|
-
const index = this.events.findIndex(e => e.id === id);
|
|
17
|
-
|
|
18
|
-
if (index !== -1) this.events.splice(index, 1);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
requeue(primitives: DomainEventPrimitives): void {
|
|
22
|
-
this.events.push(primitives);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
clear(): void {
|
|
26
|
-
this.events.length = 0;
|
|
27
|
-
}
|
|
28
|
-
}
|
package/src/event-bus/index.ts
DELETED
package/src/formatters/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { PascalCamelToSnake } from "./pascal-camel-to-snake";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { HTTPException } from "./http-exception";
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import type { HTTPProvider } from "./http-provider";
|
|
2
|
-
import { HTTPException } from "./exceptions";
|
|
3
|
-
import type { HTTPInterceptor } from "./http-interceptor";
|
|
4
|
-
|
|
5
|
-
export class FetchHTTPProvider implements HTTPProvider {
|
|
6
|
-
private ongoingRequests = new Map<string, Promise<any>>();
|
|
7
|
-
private readonly init: {
|
|
8
|
-
credentials?: RequestCredentials;
|
|
9
|
-
headers?: HeadersInit;
|
|
10
|
-
} | undefined;
|
|
11
|
-
private readonly getAuthorization: (() => string) | undefined;
|
|
12
|
-
private readonly interceptors: HTTPInterceptor[] = [];
|
|
13
|
-
|
|
14
|
-
constructor(
|
|
15
|
-
getAuthorization?: () => string,
|
|
16
|
-
init?: {
|
|
17
|
-
credentials?: RequestCredentials;
|
|
18
|
-
headers?: HeadersInit;
|
|
19
|
-
}
|
|
20
|
-
) {
|
|
21
|
-
this.getAuthorization = getAuthorization;
|
|
22
|
-
this.init = init;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
useInterceptor(interceptor: HTTPInterceptor) {
|
|
26
|
-
this.interceptors.push(interceptor);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
get<ResponseType>(url: URL): Promise<ResponseType> {
|
|
30
|
-
return this.request("GET", url);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
post<RequestBodySchema, ResponseType>(
|
|
34
|
-
url: URL,
|
|
35
|
-
body: RequestBodySchema
|
|
36
|
-
): Promise<ResponseType> {
|
|
37
|
-
return this.request("POST", url, body);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
put<RequestBodySchema, ResponseType>(
|
|
41
|
-
url: URL,
|
|
42
|
-
body: RequestBodySchema
|
|
43
|
-
): Promise<ResponseType> {
|
|
44
|
-
return this.request("PUT", url, body);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
patch<RequestBodySchema, ResponseType>(
|
|
48
|
-
url: URL,
|
|
49
|
-
body: RequestBodySchema
|
|
50
|
-
): Promise<ResponseType> {
|
|
51
|
-
return this.request("PATCH", url, body);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
delete<ResponseType>(url: URL): Promise<ResponseType> {
|
|
55
|
-
return this.request("DELETE", url);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
private async request<ResponseType>(
|
|
59
|
-
method: string,
|
|
60
|
-
url: URL,
|
|
61
|
-
body?: unknown
|
|
62
|
-
): Promise<ResponseType> {
|
|
63
|
-
const key = this.generateRequestKey(method, url, body);
|
|
64
|
-
|
|
65
|
-
if (this.ongoingRequests.has(key)) {
|
|
66
|
-
return this.ongoingRequests.get(key) as Promise<ResponseType>;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const baseHeaders = this.init?.headers ?? {};
|
|
70
|
-
const authHeader = this.getAuthorization ? { Authorization: this.getAuthorization() } : {};
|
|
71
|
-
const contentTypeHeader = body !== undefined ? { "Content-Type": "application/json" } : {};
|
|
72
|
-
|
|
73
|
-
const headers: HeadersInit = {
|
|
74
|
-
...baseHeaders,
|
|
75
|
-
...contentTypeHeader,
|
|
76
|
-
...authHeader,
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
let init: RequestInit = {
|
|
80
|
-
method,
|
|
81
|
-
body: body !== undefined ? JSON.stringify(body) : null,
|
|
82
|
-
headers,
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
if (this.init?.credentials !== undefined) {
|
|
86
|
-
init.credentials = this.init.credentials;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
for (const interceptor of this.interceptors) {
|
|
90
|
-
init = interceptor.intercept(init, url);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const request = (async () => {
|
|
94
|
-
const response = await fetch(url.href, init);
|
|
95
|
-
|
|
96
|
-
if (!response) {
|
|
97
|
-
throw new HTTPException(0, undefined);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (response.status === 204) {
|
|
101
|
-
return undefined as ResponseType;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const contentType = response.headers.get("Content-Type") ?? "";
|
|
105
|
-
let parsed: any;
|
|
106
|
-
|
|
107
|
-
try {
|
|
108
|
-
if (contentType.includes("application/json")) {
|
|
109
|
-
parsed = await response.json();
|
|
110
|
-
} else if (contentType.includes("text/")) {
|
|
111
|
-
parsed = await response.text();
|
|
112
|
-
} else {
|
|
113
|
-
parsed = await response.blob();
|
|
114
|
-
}
|
|
115
|
-
} catch {
|
|
116
|
-
parsed = undefined;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (!response.ok) {
|
|
120
|
-
throw new HTTPException(response.status, parsed);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return parsed as ResponseType;
|
|
124
|
-
})().finally(() => {
|
|
125
|
-
this.ongoingRequests.delete(key);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
this.ongoingRequests.set(key, request);
|
|
129
|
-
|
|
130
|
-
return request;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
private generateRequestKey(method: string, url: URL, body?: unknown): string {
|
|
134
|
-
const base = `${method}:${url.href}`;
|
|
135
|
-
const bodyHash = body !== undefined ? this.hashString(JSON.stringify(body)) : "";
|
|
136
|
-
|
|
137
|
-
return `${base}:${bodyHash}`;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
private hashString(input: string): string {
|
|
141
|
-
let hash = 0;
|
|
142
|
-
|
|
143
|
-
for (let i = 0; i < input.length; i++) {
|
|
144
|
-
const chr = input.charCodeAt(i);
|
|
145
|
-
hash = (hash << 5) - hash + chr;
|
|
146
|
-
hash |= 0;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return hash.toString();
|
|
150
|
-
}
|
|
151
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export interface HTTPProvider {
|
|
2
|
-
get<ResponseType>(url: URL): Promise<ResponseType>;
|
|
3
|
-
post<RequestBodySchema, ResponseType>(url: URL, body: RequestBodySchema): Promise<ResponseType>;
|
|
4
|
-
put<RequestBodySchema, ResponseType>(url: URL, body: RequestBodySchema): Promise<ResponseType>;
|
|
5
|
-
patch<RequestBodySchema, ResponseType>(url: URL, body: RequestBodySchema): Promise<ResponseType>;
|
|
6
|
-
delete<ResponseType>(url: URL): Promise<ResponseType>;
|
|
7
|
-
}
|
package/src/http/index.ts
DELETED
package/src/i18n/index.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export const SharedKernelTranslationKeys = {
|
|
2
|
-
auth: {
|
|
3
|
-
errors: {
|
|
4
|
-
NotAuthenticated: "auth.errors.not_authenticated",
|
|
5
|
-
RequireAuthNotImplementedCorrectly: "auth.errors.require_auth_not_implemented_correctly",
|
|
6
|
-
},
|
|
7
|
-
},
|
|
8
|
-
criteria: {
|
|
9
|
-
errors: {
|
|
10
|
-
LimitNotValid: "criteria.errors.limit_not_valid",
|
|
11
|
-
OffsetNotValid: "criteria.errors.offset_not_valid",
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
entities: {
|
|
15
|
-
errors: {
|
|
16
|
-
EntityNotRegistered: "entities.errors.entity_not_registered",
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
};
|
package/src/index.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export * from "./auth";
|
|
2
|
-
export * from "./converters";
|
|
3
|
-
export * from "./criteria";
|
|
4
|
-
export * from "./dao";
|
|
5
|
-
export * from "./domain-events";
|
|
6
|
-
export * from "./entities";
|
|
7
|
-
export * from "./event-bus";
|
|
8
|
-
export * from "./formatters";
|
|
9
|
-
export * from "./http";
|
|
10
|
-
export * from "./i18n";
|
|
11
|
-
export * from "./json-api";
|
|
12
|
-
export * from "./messages";
|
|
13
|
-
export * from "./models";
|
|
14
|
-
export * from "./pub-sub";
|
|
15
|
-
export * from "./rbac";
|
|
16
|
-
export * from "./result";
|
|
17
|
-
export * from "./state-manager";
|
|
18
|
-
export * from "./telemetry";
|
|
19
|
-
export * from "./unit-of-work";
|
|
20
|
-
export * from "./utils";
|
|
21
|
-
export * from "./value-objects";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { JSONAPIErrors } from "./json-api-errors";
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export class JSONAPIErrors extends Error {
|
|
2
|
-
readonly errors: Array<{
|
|
3
|
-
id?: string;
|
|
4
|
-
status: string;
|
|
5
|
-
code: string;
|
|
6
|
-
title: string;
|
|
7
|
-
detail: string;
|
|
8
|
-
source?: { pointer: string } | { parameter: string } | { header: string };
|
|
9
|
-
meta?: Record<string, any>;
|
|
10
|
-
}>;
|
|
11
|
-
|
|
12
|
-
constructor(errors: JSONAPIErrors["errors"]) {
|
|
13
|
-
super();
|
|
14
|
-
|
|
15
|
-
this.errors = errors;
|
|
16
|
-
}
|
|
17
|
-
}
|
package/src/json-api/index.ts
DELETED