@sincpro/mobile 0.4.4 → 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/README.md +3 -3
- package/dist/adapters/JsonSerializer.adapter.d.ts +1 -1
- package/dist/adapters/JsonSerializer.adapter.js +2 -2
- package/dist/adapters/repositories/database_table.repository.d.ts +3 -2
- package/dist/adapters/repositories/database_table.repository.js +1 -1
- package/dist/adapters/repositories/document.repository.d.ts +81 -0
- package/dist/adapters/repositories/document.repository.js +653 -0
- package/dist/adapters/repositories/domain_event.repository.d.ts +17 -17
- package/dist/adapters/repositories/domain_event.repository.js +25 -31
- package/dist/adapters/repositories/domain_event_dead_letter.repository.d.ts +10 -10
- package/dist/adapters/repositories/domain_event_dead_letter.repository.js +14 -13
- package/dist/adapters/repositories/event_row.d.ts +13 -0
- package/dist/adapters/repositories/event_row.js +22 -0
- package/dist/adapters/repositories/sqlite_document_store.d.ts +33 -0
- package/dist/adapters/repositories/sqlite_document_store.js +201 -0
- package/dist/domain/connectivity/events.d.ts +5 -5
- package/dist/domain/connectivity/events.js +3 -3
- package/dist/domain/database/criteria.d.ts +19 -0
- package/dist/domain/database/criteria.js +36 -0
- package/dist/domain/database/criteria_clock.d.ts +8 -0
- package/dist/domain/database/criteria_clock.js +305 -0
- package/dist/domain/database/criteria_sql.d.ts +61 -0
- package/dist/domain/database/criteria_sql.js +476 -0
- package/dist/domain/database/database.d.ts +1 -0
- package/dist/domain/database/index.d.ts +3 -1
- package/dist/domain/database/index.js +3 -1
- package/dist/domain/database/migration_plan.d.ts +14 -0
- package/dist/domain/database/migration_plan.js +44 -0
- package/dist/domain/entity/change_tracking.d.ts +21 -0
- package/dist/domain/entity/change_tracking.js +71 -0
- package/dist/domain/entity/checks.d.ts +8 -0
- package/dist/domain/entity/checks.js +82 -0
- package/dist/domain/entity/entity.d.ts +39 -32
- package/dist/domain/entity/entity.js +94 -105
- package/dist/domain/entity/entity_collection.d.ts +15 -30
- package/dist/domain/entity/entity_collection.js +30 -121
- package/dist/domain/entity/index.d.ts +5 -0
- package/dist/domain/entity/index.js +5 -0
- package/dist/domain/entity/reconcile.d.ts +7 -0
- package/dist/domain/entity/reconcile.js +12 -0
- package/dist/domain/entity/relations.d.ts +27 -0
- package/dist/domain/entity/relations.js +69 -0
- package/dist/domain/entity/remote_sync.d.ts +4 -0
- package/dist/domain/entity/remote_sync.js +19 -0
- package/dist/domain/entity/values.d.ts +6 -0
- package/dist/domain/entity/values.js +13 -0
- package/dist/domain/events/catalog.d.ts +29 -0
- package/dist/domain/{events.js → events/catalog.js} +7 -11
- package/dist/domain/events/chain.d.ts +5 -0
- package/dist/domain/events/chain.js +6 -0
- package/dist/domain/{event_sourcing → events}/domain_event.d.ts +20 -22
- package/dist/domain/events/domain_event.js +227 -0
- package/dist/domain/events/index.d.ts +8 -0
- package/dist/domain/events/index.js +8 -0
- package/dist/domain/events/integration_event.d.ts +103 -0
- package/dist/domain/events/integration_event.js +72 -0
- package/dist/domain/events/label.d.ts +2 -0
- package/dist/domain/events/label.js +26 -0
- package/dist/domain/index.d.ts +0 -1
- package/dist/domain/index.js +0 -1
- package/dist/domain/print/events.d.ts +8 -4
- package/dist/domain/print/events.js +9 -4
- package/dist/domain/repositories/document_store.d.ts +33 -0
- package/dist/domain/repositories/document_store.js +5 -0
- package/dist/domain/repositories/hooks.d.ts +23 -0
- package/dist/domain/repositories/hooks.js +32 -0
- package/dist/domain/repositories/index.d.ts +4 -0
- package/dist/domain/repositories/index.js +4 -0
- package/dist/domain/{database → repositories}/repository.d.ts +9 -3
- package/dist/domain/settings.d.ts +4 -1
- package/dist/domain/settings.js +3 -0
- package/dist/domain/webview/events.d.ts +2 -2
- package/dist/domain/webview/events.js +2 -2
- package/dist/entrypoints/db/migrations.js +10 -10
- package/dist/entrypoints/queue/QueueProcessor.d.ts +1 -1
- package/dist/entrypoints/queue/activateDomain.subscriber.d.ts +2 -2
- package/dist/entrypoints/queue/activateDomain.subscriber.js +2 -2
- package/dist/entrypoints/queue/newAppSettings.handler.d.ts +2 -2
- package/dist/entrypoints/queue/newAppSettings.handler.js +1 -1
- package/dist/entrypoints/queue/printImage.subscriber.d.ts +1 -1
- package/dist/entrypoints/queue/printImage.subscriber.js +2 -2
- package/dist/entrypoints/queue/processWebViewMessage.subscriber.d.ts +1 -1
- package/dist/entrypoints/queue/processWebViewMessage.subscriber.js +1 -1
- package/dist/entrypoints/ui/AppShell.js +2 -2
- package/dist/entrypoints/ui/common_provider.d.ts +0 -12
- package/dist/entrypoints/ui/common_provider.js +2 -131
- package/dist/event_driven/index.d.ts +1 -0
- package/dist/event_driven/index.js +1 -0
- package/dist/{domain/event_sourcing/event_handler.d.ts → event_driven/subscriber.d.ts} +1 -1
- package/dist/exceptions.d.ts +21 -0
- package/dist/exceptions.js +30 -0
- package/dist/framework/base_module.d.ts +1 -1
- package/dist/framework/createApp.d.ts +3 -3
- package/dist/framework/domain_module.d.ts +1 -1
- package/dist/framework/kernel.d.ts +1 -1
- package/dist/framework/kernel.js +17 -8
- package/dist/infrastructure/database/connector.d.ts +2 -0
- package/dist/infrastructure/database/connector.js +22 -0
- package/dist/infrastructure/database/index.d.ts +1 -0
- package/dist/infrastructure/database/index.js +1 -0
- package/dist/infrastructure/database/schema.d.ts +9 -0
- package/dist/infrastructure/database/schema.js +61 -0
- package/dist/infrastructure/database/utils.d.ts +2 -0
- package/dist/infrastructure/database/utils.js +12 -4
- package/dist/infrastructure/event_chain.d.ts +6 -0
- package/dist/infrastructure/event_chain.js +25 -0
- package/dist/infrastructure/telemetry/tracing/tracing_hooks.js +8 -5
- package/dist/infrastructure/ui/UIEventBus.d.ts +3 -1
- package/dist/infrastructure/ui/UIEventBus.js +8 -1
- package/dist/infrastructure/ui/activity.d.ts +37 -0
- package/dist/infrastructure/ui/activity.js +84 -0
- package/dist/infrastructure/workers/CronWorker.d.ts +6 -4
- package/dist/infrastructure/workers/CronWorker.js +24 -18
- package/dist/infrastructure/workers/EventBus.d.ts +9 -5
- package/dist/infrastructure/workers/EventBus.js +68 -33
- package/dist/services/bluetooth.service.js +16 -14
- package/dist/services/dead_letter_queue.service.d.ts +7 -7
- package/dist/services/dead_letter_queue.service.js +0 -2
- package/dist/services/event.service.d.ts +3 -3
- package/dist/services/event.service.js +1 -1
- package/dist/services/network.service.d.ts +1 -1
- package/dist/services/network.service.js +17 -15
- package/dist/services/printer.service.d.ts +1 -1
- package/dist/services/printer.service.js +50 -44
- package/dist/tools/utils/date.js +4 -3
- package/dist/tools/utils/monetary.d.ts +6 -3
- package/dist/tools/utils/monetary.js +33 -21
- package/dist/tools/utils/serializer.d.ts +1 -1
- package/dist/tools/utils/serializer.js +32 -35
- package/dist/ui/activity/DeviceNotices.d.ts +1 -0
- package/dist/ui/activity/DeviceNotices.js +29 -0
- package/dist/ui/activity/ProcessToast.d.ts +2 -0
- package/dist/ui/activity/ProcessToast.js +71 -0
- package/dist/ui/activity/index.d.ts +4 -0
- package/dist/ui/activity/index.js +4 -0
- package/dist/ui/activity/useActivity.d.ts +9 -0
- package/dist/ui/activity/useActivity.js +48 -0
- package/dist/ui/components/molecules/EventTimelineItem.d.ts +2 -2
- package/dist/ui/components/molecules/EventTimelineItem.js +1 -1
- package/dist/ui/components/molecules/index.d.ts +1 -2
- package/dist/ui/components/molecules/index.js +1 -2
- package/dist/ui/components/organisms/DeadLetterQueueRow.d.ts +3 -3
- package/dist/ui/components/organisms/EventRow.d.ts +3 -3
- package/dist/ui/components/organisms/EventRow.js +1 -1
- package/dist/ui/screens/dead_letter_queue/dead_letter_queue.context.d.ts +5 -5
- package/dist/ui/screens/events/events.context.d.ts +4 -4
- package/package.json +13 -8
- package/dist/domain/event_sourcing/domain_event.js +0 -164
- package/dist/domain/event_sourcing/event.d.ts +0 -25
- package/dist/domain/event_sourcing/event.js +0 -25
- package/dist/domain/event_sourcing/index.d.ts +0 -2
- package/dist/domain/event_sourcing/index.js +0 -2
- package/dist/domain/events.d.ts +0 -33
- package/dist/infrastructure/ui/ToastHost.d.ts +0 -6
- package/dist/infrastructure/ui/ToastHost.js +0 -28
- package/dist/infrastructure/ui/events.d.ts +0 -1
- package/dist/infrastructure/ui/events.js +0 -1
- package/dist/ui/components/molecules/ProcessToast.d.ts +0 -8
- package/dist/ui/components/molecules/ProcessToast.js +0 -52
- /package/dist/domain/{repositories.d.ts → repositories/catalog.d.ts} +0 -0
- /package/dist/domain/{repositories.js → repositories/catalog.js} +0 -0
- /package/dist/domain/{database → repositories}/repository.js +0 -0
- /package/dist/{domain/event_sourcing/event_handler.js → event_driven/subscriber.js} +0 -0
- /package/dist/ui/{components/molecules → activity}/ProcessToastProvider.d.ts +0 -0
- /package/dist/ui/{components/molecules → activity}/ProcessToastProvider.js +0 -0
|
@@ -1,12 +1,11 @@
|
|
|
1
|
+
import { rowsMatching, } from "../../domain/database/criteria";
|
|
1
2
|
import { generateUUID } from "../../infrastructure/database/utils";
|
|
2
3
|
import { loggerQueueProcessor } from "../../infrastructure/logger";
|
|
3
|
-
import { EventBus } from "../../infrastructure/workers";
|
|
4
4
|
import { convertToArray } from "../../tools/utils/collections";
|
|
5
5
|
import { safeJsonStringify } from "../../tools/utils/serializer";
|
|
6
6
|
import { ValueObject } from "./value_object";
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
* Implements IEventSourced for domain event publishing and provides functional operations.
|
|
8
|
+
* Collection of aggregates. Records integration events for the set and offers the list operations.
|
|
10
9
|
*
|
|
11
10
|
* @example
|
|
12
11
|
* const collection = new EntityCollection([priceList1, priceList2]);
|
|
@@ -22,15 +21,15 @@ import { ValueObject } from "./value_object";
|
|
|
22
21
|
* const union = collection1.union(collection2);
|
|
23
22
|
* const common = collection1.intersect(collection2);
|
|
24
23
|
*
|
|
25
|
-
* //
|
|
26
|
-
*
|
|
24
|
+
* // Record an integration event for the set
|
|
25
|
+
* collection.record(PriceListsSynced, { count: collection.length });
|
|
27
26
|
*/
|
|
28
27
|
export class EntityCollection extends ValueObject {
|
|
29
28
|
uuid;
|
|
30
29
|
eventIds = [];
|
|
31
30
|
entities = [];
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
_recordedEvents = [];
|
|
32
|
+
_correlationId = null;
|
|
34
33
|
constructor(entities = []) {
|
|
35
34
|
super();
|
|
36
35
|
this.uuid = generateUUID();
|
|
@@ -457,100 +456,43 @@ export class EntityCollection extends ValueObject {
|
|
|
457
456
|
toMapByUuid() {
|
|
458
457
|
return this.toMap((e) => e.uuid);
|
|
459
458
|
}
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
// ============================================
|
|
463
|
-
addDomainEvent(EventClass, payload) {
|
|
464
|
-
const event = EventClass.create(payload);
|
|
465
|
-
const existingEvent = this._domainEventsV2.find((e) => e.hasSameBusinessPayload(event));
|
|
466
|
-
if (existingEvent) {
|
|
467
|
-
loggerQueueProcessor.warn(`EntityCollection - V2 Event: '${event.name}' with identical payload already exists. Skipping duplicate.`);
|
|
468
|
-
return existingEvent.uuid;
|
|
469
|
-
}
|
|
470
|
-
if (!this._correlationIdV2) {
|
|
471
|
-
this._correlationIdV2 = generateUUID();
|
|
472
|
-
}
|
|
473
|
-
event
|
|
474
|
-
.withAggregateId(this.uuid)
|
|
475
|
-
.withCorrelationId(this._correlationIdV2)
|
|
476
|
-
.withSequence(this._domainEventsV2.length + 1);
|
|
477
|
-
this._domainEventsV2.push(event);
|
|
478
|
-
this.eventIds.push(event.uuid);
|
|
479
|
-
for (const entity of this.entities) {
|
|
480
|
-
entity.eventIds.push(event.uuid);
|
|
481
|
-
}
|
|
482
|
-
return event.uuid;
|
|
459
|
+
record(EventClass, payload) {
|
|
460
|
+
return this.stageDomainEvent(EventClass.create(payload));
|
|
483
461
|
}
|
|
484
|
-
|
|
485
|
-
|
|
462
|
+
recordEntities(EventClass) {
|
|
463
|
+
return this.stageDomainEvent(EventClass.create({
|
|
486
464
|
records: this.entities.map((e) => e.asJSON()),
|
|
487
|
-
});
|
|
488
|
-
|
|
465
|
+
}));
|
|
466
|
+
}
|
|
467
|
+
stageDomainEvent(event) {
|
|
468
|
+
const existingEvent = this._recordedEvents.find((e) => e.hasSameBusinessPayload(event));
|
|
489
469
|
if (existingEvent) {
|
|
490
|
-
loggerQueueProcessor.warn(`EntityCollection -
|
|
470
|
+
loggerQueueProcessor.warn(`EntityCollection - Event '${event.name}' is already recorded with the same payload. Skipping.`);
|
|
491
471
|
return existingEvent.uuid;
|
|
492
472
|
}
|
|
493
|
-
if (!this.
|
|
494
|
-
this.
|
|
473
|
+
if (!this._correlationId) {
|
|
474
|
+
this._correlationId = generateUUID();
|
|
495
475
|
}
|
|
496
476
|
event
|
|
477
|
+
.withEntityType(this.constructor.name)
|
|
497
478
|
.withAggregateId(this.uuid)
|
|
498
|
-
.
|
|
499
|
-
.
|
|
500
|
-
this.
|
|
479
|
+
.withSequence(this._recordedEvents.length + 1)
|
|
480
|
+
.applyChain(this._correlationId);
|
|
481
|
+
this._recordedEvents.push(event);
|
|
501
482
|
this.eventIds.push(event.uuid);
|
|
502
483
|
for (const entity of this.entities) {
|
|
503
484
|
entity.eventIds.push(event.uuid);
|
|
504
485
|
}
|
|
505
486
|
return event.uuid;
|
|
506
487
|
}
|
|
507
|
-
|
|
508
|
-
return this.
|
|
488
|
+
recordedEvents() {
|
|
489
|
+
return this._recordedEvents.map((event) => event.clone());
|
|
509
490
|
}
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
this.
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
const events = this._domainEventsV2;
|
|
516
|
-
for (const event of events) {
|
|
517
|
-
await EventBus.publish(event);
|
|
518
|
-
}
|
|
519
|
-
this.clearDomainEvents();
|
|
520
|
-
}
|
|
521
|
-
async publishAllDomainEventsSync() {
|
|
522
|
-
const events = this._domainEventsV2;
|
|
523
|
-
const errors = [];
|
|
524
|
-
for (const event of events) {
|
|
525
|
-
try {
|
|
526
|
-
await EventBus.publishSync(event);
|
|
527
|
-
}
|
|
528
|
-
catch (error) {
|
|
529
|
-
loggerQueueProcessor.warn(`EntityCollection - Error publishing V2 domain event '${event.name}': ${error.message}`);
|
|
530
|
-
errors.push(error);
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
this.clearDomainEvents();
|
|
534
|
-
if (errors.length > 0) {
|
|
535
|
-
const errorList = errors.map((e) => ` - ${e.message}`).join("\n");
|
|
536
|
-
throw new Error(`Errors occurred while publishing V2 domain events synchronously:\n${errorList}`);
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
async publishDomainEvent(EventClass, payload) {
|
|
540
|
-
this.addDomainEvent(EventClass, payload);
|
|
541
|
-
await this.publishAllDomainEvents();
|
|
542
|
-
}
|
|
543
|
-
async publishDomainEventSync(EventClass, payload) {
|
|
544
|
-
this.addDomainEvent(EventClass, payload);
|
|
545
|
-
await this.publishAllDomainEventsSync();
|
|
546
|
-
}
|
|
547
|
-
async publishDomainEventWithEntities(EventClass) {
|
|
548
|
-
this.addDomainEventWithEntities(EventClass);
|
|
549
|
-
await this.publishAllDomainEvents();
|
|
550
|
-
}
|
|
551
|
-
async publishDomainEventWithEntitiesSync(EventClass) {
|
|
552
|
-
this.addDomainEventWithEntities(EventClass);
|
|
553
|
-
await this.publishAllDomainEventsSync();
|
|
491
|
+
pullEvents() {
|
|
492
|
+
const events = this._recordedEvents;
|
|
493
|
+
this._recordedEvents = [];
|
|
494
|
+
this._correlationId = null;
|
|
495
|
+
return events;
|
|
554
496
|
}
|
|
555
497
|
/**
|
|
556
498
|
* Serializes collection as array of entity JSONs.
|
|
@@ -566,43 +508,10 @@ export class EntityCollection extends ValueObject {
|
|
|
566
508
|
return this.entities.map((e) => e.asJSON(pretty));
|
|
567
509
|
}
|
|
568
510
|
/**
|
|
569
|
-
*
|
|
570
|
-
* @example
|
|
571
|
-
* const filtered = collection.findByCriteria([
|
|
572
|
-
* { field: 'customerId', operator: '=', value: 123 },
|
|
573
|
-
* { field: 'state', operator: 'in', value: ['draft', 'posted'] }
|
|
574
|
-
* ]);
|
|
511
|
+
* The entities that answer a criteria. The filter is `selection`.
|
|
575
512
|
*/
|
|
576
513
|
findByCriteria(criteria) {
|
|
577
|
-
|
|
578
|
-
return criteria.every((c) => {
|
|
579
|
-
const fieldValue = entity[c.field];
|
|
580
|
-
switch (c.operator) {
|
|
581
|
-
case "=":
|
|
582
|
-
return fieldValue === c.value;
|
|
583
|
-
case "!=":
|
|
584
|
-
return fieldValue !== c.value;
|
|
585
|
-
case "in":
|
|
586
|
-
return Array.isArray(c.value) && c.value.includes(fieldValue);
|
|
587
|
-
case "not_in":
|
|
588
|
-
return Array.isArray(c.value) && !c.value.includes(fieldValue);
|
|
589
|
-
case "like":
|
|
590
|
-
return (typeof fieldValue === "string" &&
|
|
591
|
-
fieldValue.toLowerCase().includes(String(c.value).toLowerCase()));
|
|
592
|
-
case ">":
|
|
593
|
-
return fieldValue > c.value;
|
|
594
|
-
case "<":
|
|
595
|
-
return fieldValue < c.value;
|
|
596
|
-
case ">=":
|
|
597
|
-
return fieldValue >= c.value;
|
|
598
|
-
case "<=":
|
|
599
|
-
return fieldValue <= c.value;
|
|
600
|
-
default:
|
|
601
|
-
return false;
|
|
602
|
-
}
|
|
603
|
-
});
|
|
604
|
-
});
|
|
605
|
-
return this.createInstance(filtered.toArray());
|
|
514
|
+
return this.createInstance(rowsMatching(this.toArray(), criteria));
|
|
606
515
|
}
|
|
607
516
|
/**
|
|
608
517
|
* Deserializes collection from array of entity JSONs.
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
export * from "../../domain/entity/change_tracking";
|
|
2
|
+
export * from "../../domain/entity/checks";
|
|
1
3
|
export * from "../../domain/entity/entity";
|
|
2
4
|
export * from "../../domain/entity/entity_collection";
|
|
5
|
+
export * from "../../domain/entity/reconcile";
|
|
6
|
+
export * from "../../domain/entity/relations";
|
|
3
7
|
export * from "../../domain/entity/value_object";
|
|
8
|
+
export * from "../../domain/entity/values";
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
export * from "../../domain/entity/change_tracking";
|
|
2
|
+
export * from "../../domain/entity/checks";
|
|
1
3
|
export * from "../../domain/entity/entity";
|
|
2
4
|
export * from "../../domain/entity/entity_collection";
|
|
5
|
+
export * from "../../domain/entity/reconcile";
|
|
6
|
+
export * from "../../domain/entity/relations";
|
|
3
7
|
export * from "../../domain/entity/value_object";
|
|
8
|
+
export * from "../../domain/entity/values";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { RemoteEntity } from "./entity";
|
|
2
|
+
export type ReconciliationWrite = "insert" | "replace" | "keep";
|
|
3
|
+
export interface Reconciliation<T extends RemoteEntity> {
|
|
4
|
+
entity: T;
|
|
5
|
+
write: ReconciliationWrite;
|
|
6
|
+
}
|
|
7
|
+
export declare function reconcile<T extends RemoteEntity>(local: T | null, incoming: T): Reconciliation<T>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { acceptNextWrite } from "./remote_sync";
|
|
2
|
+
export function reconcile(local, incoming) {
|
|
3
|
+
if (!local) {
|
|
4
|
+
acceptNextWrite(incoming, incoming.remoteId);
|
|
5
|
+
return { entity: incoming, write: "insert" };
|
|
6
|
+
}
|
|
7
|
+
if (local.isDirty)
|
|
8
|
+
return { entity: local, write: "keep" };
|
|
9
|
+
local.mergeWithRemote(incoming);
|
|
10
|
+
acceptNextWrite(local, incoming.remoteId ?? local.remoteId);
|
|
11
|
+
return { entity: local, write: "replace" };
|
|
12
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare enum RelationCascade {
|
|
2
|
+
SAVE_AND_REMOVE = "save_and_remove",
|
|
3
|
+
SAVE = "save",
|
|
4
|
+
UPDATE = "update",
|
|
5
|
+
REMOVE = "remove",
|
|
6
|
+
UPDATE_AND_REMOVE = "update_and_remove"
|
|
7
|
+
}
|
|
8
|
+
export interface Relation {
|
|
9
|
+
field: string;
|
|
10
|
+
type: AnyClass<{
|
|
11
|
+
uuid: string;
|
|
12
|
+
}>;
|
|
13
|
+
cascade: RelationCascade;
|
|
14
|
+
}
|
|
15
|
+
export type AnyClass<T> = Function & {
|
|
16
|
+
prototype: T;
|
|
17
|
+
};
|
|
18
|
+
export declare function relation(type: AnyClass<{
|
|
19
|
+
uuid: string;
|
|
20
|
+
}>, cascade?: RelationCascade): (target: object, propertyKey: string) => void;
|
|
21
|
+
export declare function relations(entity: object): Relation[];
|
|
22
|
+
export declare function relationWrites(relation: Relation): boolean;
|
|
23
|
+
export declare function relationPersists(relation: Relation, isNew: boolean): boolean;
|
|
24
|
+
export declare function relationRemoves(relation: Relation): boolean;
|
|
25
|
+
export declare function heldEntities(value: unknown): {
|
|
26
|
+
uuid: string;
|
|
27
|
+
}[];
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const RELATION = Symbol("relation");
|
|
2
|
+
export var RelationCascade;
|
|
3
|
+
(function (RelationCascade) {
|
|
4
|
+
RelationCascade["SAVE_AND_REMOVE"] = "save_and_remove";
|
|
5
|
+
RelationCascade["SAVE"] = "save";
|
|
6
|
+
RelationCascade["UPDATE"] = "update";
|
|
7
|
+
RelationCascade["REMOVE"] = "remove";
|
|
8
|
+
RelationCascade["UPDATE_AND_REMOVE"] = "update_and_remove";
|
|
9
|
+
})(RelationCascade || (RelationCascade = {}));
|
|
10
|
+
export function relation(type, cascade = RelationCascade.SAVE_AND_REMOVE) {
|
|
11
|
+
return function (target, propertyKey) {
|
|
12
|
+
const ctor = target.constructor;
|
|
13
|
+
const relationsOfCtor = ctor[RELATION] ?? [];
|
|
14
|
+
if (!relationsOfCtor.some((item) => item.field === propertyKey)) {
|
|
15
|
+
relationsOfCtor.push({ field: propertyKey, type, cascade });
|
|
16
|
+
}
|
|
17
|
+
ctor[RELATION] = relationsOfCtor;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export function relations(entity) {
|
|
21
|
+
const found = [];
|
|
22
|
+
let ctor = entity.constructor;
|
|
23
|
+
while (ctor && ctor !== Function.prototype) {
|
|
24
|
+
const declared = ctor[RELATION];
|
|
25
|
+
if (declared)
|
|
26
|
+
found.push(...declared);
|
|
27
|
+
ctor = Object.getPrototypeOf(ctor);
|
|
28
|
+
}
|
|
29
|
+
return found;
|
|
30
|
+
}
|
|
31
|
+
export function relationWrites(relation) {
|
|
32
|
+
return relation.cascade !== RelationCascade.REMOVE;
|
|
33
|
+
}
|
|
34
|
+
export function relationPersists(relation, isNew) {
|
|
35
|
+
switch (relation.cascade) {
|
|
36
|
+
case RelationCascade.SAVE:
|
|
37
|
+
case RelationCascade.SAVE_AND_REMOVE:
|
|
38
|
+
return true;
|
|
39
|
+
case RelationCascade.UPDATE:
|
|
40
|
+
case RelationCascade.UPDATE_AND_REMOVE:
|
|
41
|
+
return !isNew;
|
|
42
|
+
case RelationCascade.REMOVE:
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export function relationRemoves(relation) {
|
|
47
|
+
switch (relation.cascade) {
|
|
48
|
+
case RelationCascade.SAVE_AND_REMOVE:
|
|
49
|
+
case RelationCascade.UPDATE_AND_REMOVE:
|
|
50
|
+
case RelationCascade.REMOVE:
|
|
51
|
+
return true;
|
|
52
|
+
case RelationCascade.SAVE:
|
|
53
|
+
case RelationCascade.UPDATE:
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export function heldEntities(value) {
|
|
58
|
+
if (Array.isArray(value))
|
|
59
|
+
return value.filter(isEntity);
|
|
60
|
+
if (isEntity(value))
|
|
61
|
+
return [value];
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
function isEntity(value) {
|
|
65
|
+
return (typeof value === "object" &&
|
|
66
|
+
value !== null &&
|
|
67
|
+
"uuid" in value &&
|
|
68
|
+
typeof value.uuid === "string");
|
|
69
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { RemoteEntity } from "./entity";
|
|
2
|
+
export declare function acceptNextWrite(entity: RemoteEntity, remoteId?: number): void;
|
|
3
|
+
export declare function takeAcceptedWrite(entity: RemoteEntity): boolean;
|
|
4
|
+
export declare function applyAcknowledgement(entity: RemoteEntity, remoteId?: number): void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ERemoteState } from "./entity";
|
|
2
|
+
const acceptedWrites = new WeakSet();
|
|
3
|
+
export function acceptNextWrite(entity, remoteId) {
|
|
4
|
+
if (remoteId !== undefined)
|
|
5
|
+
entity.remoteId = remoteId;
|
|
6
|
+
acceptedWrites.add(entity);
|
|
7
|
+
}
|
|
8
|
+
export function takeAcceptedWrite(entity) {
|
|
9
|
+
if (!acceptedWrites.has(entity))
|
|
10
|
+
return false;
|
|
11
|
+
acceptedWrites.delete(entity);
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
export function applyAcknowledgement(entity, remoteId) {
|
|
15
|
+
if (remoteId !== undefined)
|
|
16
|
+
entity.remoteId = remoteId;
|
|
17
|
+
entity.ackedVersion = entity.version;
|
|
18
|
+
entity.remoteState = ERemoteState.SYNCED;
|
|
19
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DomainValidationError } from "../../exceptions";
|
|
2
|
+
export function valueRule(name, holds) {
|
|
3
|
+
return {
|
|
4
|
+
name,
|
|
5
|
+
holds,
|
|
6
|
+
parse(value) {
|
|
7
|
+
if (!holds(value)) {
|
|
8
|
+
throw new DomainValidationError(`${name} does not hold`);
|
|
9
|
+
}
|
|
10
|
+
return value;
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { IntegrationEvent } from "../../domain/events/integration_event";
|
|
2
|
+
import { ISetting } from "../../domain/settings";
|
|
3
|
+
export declare class ActivateDomainEvent extends IntegrationEvent {
|
|
4
|
+
static readonly name = "common.domain.activate";
|
|
5
|
+
static readonly label = "Activar dominio";
|
|
6
|
+
static readonly requiresNetwork = false;
|
|
7
|
+
readonly name = "common.domain.activate";
|
|
8
|
+
readonly label = "Activar dominio";
|
|
9
|
+
readonly requiresNetwork = false;
|
|
10
|
+
domain: string;
|
|
11
|
+
}
|
|
12
|
+
export declare class DeactivateDomainEvent extends IntegrationEvent {
|
|
13
|
+
static readonly name = "common.domain.deactivate";
|
|
14
|
+
static readonly label = "Desactivar dominio";
|
|
15
|
+
static readonly requiresNetwork = false;
|
|
16
|
+
readonly name = "common.domain.deactivate";
|
|
17
|
+
readonly label = "Desactivar dominio";
|
|
18
|
+
readonly requiresNetwork = false;
|
|
19
|
+
domain: string;
|
|
20
|
+
}
|
|
21
|
+
export declare class NewAppSettingsEvent extends IntegrationEvent {
|
|
22
|
+
static readonly name = "common.settings.added";
|
|
23
|
+
static readonly label = "Nuevas configuraciones";
|
|
24
|
+
static readonly requiresNetwork = false;
|
|
25
|
+
readonly name = "common.settings.added";
|
|
26
|
+
readonly label = "Nuevas configuraciones";
|
|
27
|
+
readonly requiresNetwork = false;
|
|
28
|
+
settings: ISetting[];
|
|
29
|
+
}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
export * from "../domain/print/events";
|
|
5
|
-
export * from "../domain/webview/events";
|
|
6
|
-
export class ActivateDomainEvent extends DomainEvent {
|
|
7
|
-
static name = "common.domain.v2.activate";
|
|
1
|
+
import { IntegrationEvent } from "../../domain/events/integration_event";
|
|
2
|
+
export class ActivateDomainEvent extends IntegrationEvent {
|
|
3
|
+
static name = "common.domain.activate";
|
|
8
4
|
static label = "Activar dominio";
|
|
9
5
|
static requiresNetwork = false;
|
|
10
6
|
name = ActivateDomainEvent.name;
|
|
@@ -12,8 +8,8 @@ export class ActivateDomainEvent extends DomainEvent {
|
|
|
12
8
|
requiresNetwork = ActivateDomainEvent.requiresNetwork;
|
|
13
9
|
domain = "";
|
|
14
10
|
}
|
|
15
|
-
export class DeactivateDomainEvent extends
|
|
16
|
-
static name = "common.domain.
|
|
11
|
+
export class DeactivateDomainEvent extends IntegrationEvent {
|
|
12
|
+
static name = "common.domain.deactivate";
|
|
17
13
|
static label = "Desactivar dominio";
|
|
18
14
|
static requiresNetwork = false;
|
|
19
15
|
name = DeactivateDomainEvent.name;
|
|
@@ -21,8 +17,8 @@ export class DeactivateDomainEvent extends DomainEvent {
|
|
|
21
17
|
requiresNetwork = DeactivateDomainEvent.requiresNetwork;
|
|
22
18
|
domain = "";
|
|
23
19
|
}
|
|
24
|
-
export class NewAppSettingsEvent extends
|
|
25
|
-
static name = "common.settings.
|
|
20
|
+
export class NewAppSettingsEvent extends IntegrationEvent {
|
|
21
|
+
static name = "common.settings.added";
|
|
26
22
|
static label = "Nuevas configuraciones";
|
|
27
23
|
static requiresNetwork = false;
|
|
28
24
|
name = NewAppSettingsEvent.name;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ValueObject } from "../../domain/entity/value_object";
|
|
2
|
+
import { type LabelText } from "./label";
|
|
2
3
|
export type HandlerFn<T> = (payload: T) => Promise<void>;
|
|
3
4
|
export type EventName = string;
|
|
4
5
|
export interface IEventHandler<Payload = any> {
|
|
@@ -12,47 +13,44 @@ export declare enum EEventStatus {
|
|
|
12
13
|
FAILED = "FAILED",
|
|
13
14
|
CANCELLED = "CANCELLED"
|
|
14
15
|
}
|
|
15
|
-
|
|
16
|
+
declare const ENVELOPE_FIELDS: readonly ["name", "label", "requiresNetwork", "uuid", "createdAt", "status", "attempts", "errorMessage", "acknowledgedAt", "failedAt", "aggregateId", "sourceId", "correlationId", "causationId", "entityType", "entityVersion", "traceparent", "sequence"];
|
|
17
|
+
type EnvelopeFields = (typeof ENVELOPE_FIELDS)[number];
|
|
16
18
|
export type DomainEventClass<T extends DomainEvent> = {
|
|
17
|
-
new (): T;
|
|
19
|
+
new (...args: any[]): T;
|
|
18
20
|
create(data?: EventData<T>): T;
|
|
19
21
|
};
|
|
20
|
-
export type EventData<T extends DomainEvent> = Omit<Partial<T>,
|
|
22
|
+
export type EventData<T extends DomainEvent> = Omit<Partial<T>, EnvelopeFields>;
|
|
21
23
|
export declare class DomainEvent extends ValueObject {
|
|
24
|
+
#private;
|
|
25
|
+
constructor(..._args: any[]);
|
|
22
26
|
readonly name: string;
|
|
23
27
|
readonly label: string;
|
|
24
|
-
readonly requiresNetwork: boolean;
|
|
25
28
|
readonly uuid: string;
|
|
26
29
|
readonly createdAt: string;
|
|
27
|
-
status: EEventStatus;
|
|
28
|
-
attempts: number;
|
|
29
|
-
errorMessage: string | null;
|
|
30
|
-
acknowledgedAt: string | null;
|
|
31
|
-
failedAt: string | null;
|
|
32
30
|
aggregateId: string | null;
|
|
33
31
|
sourceId: string | null;
|
|
34
32
|
correlationId: string | null;
|
|
33
|
+
causationId: string | null;
|
|
34
|
+
entityType: string;
|
|
35
|
+
entityVersion: number | null;
|
|
36
|
+
traceparent: string | null;
|
|
35
37
|
sequence: number;
|
|
36
38
|
private static sanitize;
|
|
37
|
-
static create<T extends DomainEvent>(this: new () => T, data?: EventData<T>): T;
|
|
39
|
+
static create<T extends DomainEvent>(this: new (...args: any[]) => T, data?: EventData<T>): T;
|
|
38
40
|
static from<T extends DomainEvent>(this: new () => T, event: DomainEvent): T;
|
|
39
|
-
|
|
41
|
+
static fromJSON<T>(this: new () => T, json: unknown): T;
|
|
42
|
+
private static read;
|
|
40
43
|
withAggregateId(aggregateId: string): this;
|
|
41
44
|
withSourceId(sourceId: string): this;
|
|
42
45
|
withCorrelationId(correlationId: string): this;
|
|
46
|
+
withCausationId(causationId: string | null): this;
|
|
47
|
+
withEntityType(entityType: string): this;
|
|
43
48
|
withSequence(sequence: number): this;
|
|
49
|
+
causedBy(cause: DomainEvent): this;
|
|
50
|
+
applyChain(flowId: string): this;
|
|
51
|
+
labelText(): LabelText;
|
|
44
52
|
getBusinessPayload(): Record<string, unknown>;
|
|
45
53
|
hasSameBusinessPayload(other: DomainEvent): boolean;
|
|
46
|
-
|
|
47
|
-
markAsAcknowledged(): this;
|
|
48
|
-
markAsFailed(errorMessage: string): this;
|
|
49
|
-
markAsCancelled(): this;
|
|
50
|
-
retry(): this;
|
|
51
|
-
get isPending(): boolean;
|
|
52
|
-
get isProcessing(): boolean;
|
|
53
|
-
get isAcknowledged(): boolean;
|
|
54
|
-
get isFailed(): boolean;
|
|
55
|
-
get isCancelled(): boolean;
|
|
56
|
-
get isPartOfTransaction(): boolean;
|
|
54
|
+
asJSON(pretty?: boolean): string;
|
|
57
55
|
}
|
|
58
56
|
export {};
|