@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.
Files changed (165) hide show
  1. package/README.md +3 -3
  2. package/dist/adapters/JsonSerializer.adapter.d.ts +1 -1
  3. package/dist/adapters/JsonSerializer.adapter.js +2 -2
  4. package/dist/adapters/repositories/database_table.repository.d.ts +3 -2
  5. package/dist/adapters/repositories/database_table.repository.js +1 -1
  6. package/dist/adapters/repositories/document.repository.d.ts +81 -0
  7. package/dist/adapters/repositories/document.repository.js +653 -0
  8. package/dist/adapters/repositories/domain_event.repository.d.ts +17 -17
  9. package/dist/adapters/repositories/domain_event.repository.js +25 -31
  10. package/dist/adapters/repositories/domain_event_dead_letter.repository.d.ts +10 -10
  11. package/dist/adapters/repositories/domain_event_dead_letter.repository.js +14 -13
  12. package/dist/adapters/repositories/event_row.d.ts +13 -0
  13. package/dist/adapters/repositories/event_row.js +22 -0
  14. package/dist/adapters/repositories/sqlite_document_store.d.ts +33 -0
  15. package/dist/adapters/repositories/sqlite_document_store.js +201 -0
  16. package/dist/domain/connectivity/events.d.ts +5 -5
  17. package/dist/domain/connectivity/events.js +3 -3
  18. package/dist/domain/database/criteria.d.ts +19 -0
  19. package/dist/domain/database/criteria.js +36 -0
  20. package/dist/domain/database/criteria_clock.d.ts +8 -0
  21. package/dist/domain/database/criteria_clock.js +305 -0
  22. package/dist/domain/database/criteria_sql.d.ts +61 -0
  23. package/dist/domain/database/criteria_sql.js +476 -0
  24. package/dist/domain/database/database.d.ts +1 -0
  25. package/dist/domain/database/index.d.ts +3 -1
  26. package/dist/domain/database/index.js +3 -1
  27. package/dist/domain/database/migration_plan.d.ts +14 -0
  28. package/dist/domain/database/migration_plan.js +44 -0
  29. package/dist/domain/entity/change_tracking.d.ts +21 -0
  30. package/dist/domain/entity/change_tracking.js +71 -0
  31. package/dist/domain/entity/checks.d.ts +8 -0
  32. package/dist/domain/entity/checks.js +82 -0
  33. package/dist/domain/entity/entity.d.ts +39 -32
  34. package/dist/domain/entity/entity.js +94 -105
  35. package/dist/domain/entity/entity_collection.d.ts +15 -30
  36. package/dist/domain/entity/entity_collection.js +30 -121
  37. package/dist/domain/entity/index.d.ts +5 -0
  38. package/dist/domain/entity/index.js +5 -0
  39. package/dist/domain/entity/reconcile.d.ts +7 -0
  40. package/dist/domain/entity/reconcile.js +12 -0
  41. package/dist/domain/entity/relations.d.ts +27 -0
  42. package/dist/domain/entity/relations.js +69 -0
  43. package/dist/domain/entity/remote_sync.d.ts +4 -0
  44. package/dist/domain/entity/remote_sync.js +19 -0
  45. package/dist/domain/entity/values.d.ts +6 -0
  46. package/dist/domain/entity/values.js +13 -0
  47. package/dist/domain/events/catalog.d.ts +29 -0
  48. package/dist/domain/{events.js → events/catalog.js} +7 -11
  49. package/dist/domain/events/chain.d.ts +5 -0
  50. package/dist/domain/events/chain.js +6 -0
  51. package/dist/domain/{event_sourcing → events}/domain_event.d.ts +20 -22
  52. package/dist/domain/events/domain_event.js +227 -0
  53. package/dist/domain/events/index.d.ts +8 -0
  54. package/dist/domain/events/index.js +8 -0
  55. package/dist/domain/events/integration_event.d.ts +103 -0
  56. package/dist/domain/events/integration_event.js +72 -0
  57. package/dist/domain/events/label.d.ts +2 -0
  58. package/dist/domain/events/label.js +26 -0
  59. package/dist/domain/index.d.ts +0 -1
  60. package/dist/domain/index.js +0 -1
  61. package/dist/domain/print/events.d.ts +8 -4
  62. package/dist/domain/print/events.js +9 -4
  63. package/dist/domain/repositories/document_store.d.ts +33 -0
  64. package/dist/domain/repositories/document_store.js +5 -0
  65. package/dist/domain/repositories/hooks.d.ts +23 -0
  66. package/dist/domain/repositories/hooks.js +32 -0
  67. package/dist/domain/repositories/index.d.ts +4 -0
  68. package/dist/domain/repositories/index.js +4 -0
  69. package/dist/domain/{database → repositories}/repository.d.ts +9 -3
  70. package/dist/domain/settings.d.ts +4 -1
  71. package/dist/domain/settings.js +3 -0
  72. package/dist/domain/webview/events.d.ts +2 -2
  73. package/dist/domain/webview/events.js +2 -2
  74. package/dist/entrypoints/db/migrations.js +10 -10
  75. package/dist/entrypoints/queue/QueueProcessor.d.ts +1 -1
  76. package/dist/entrypoints/queue/activateDomain.subscriber.d.ts +2 -2
  77. package/dist/entrypoints/queue/activateDomain.subscriber.js +2 -2
  78. package/dist/entrypoints/queue/newAppSettings.handler.d.ts +2 -2
  79. package/dist/entrypoints/queue/newAppSettings.handler.js +1 -1
  80. package/dist/entrypoints/queue/printImage.subscriber.d.ts +1 -1
  81. package/dist/entrypoints/queue/printImage.subscriber.js +2 -2
  82. package/dist/entrypoints/queue/processWebViewMessage.subscriber.d.ts +1 -1
  83. package/dist/entrypoints/queue/processWebViewMessage.subscriber.js +1 -1
  84. package/dist/entrypoints/ui/AppShell.js +2 -2
  85. package/dist/entrypoints/ui/common_provider.d.ts +0 -12
  86. package/dist/entrypoints/ui/common_provider.js +2 -131
  87. package/dist/event_driven/index.d.ts +1 -0
  88. package/dist/event_driven/index.js +1 -0
  89. package/dist/{domain/event_sourcing/event_handler.d.ts → event_driven/subscriber.d.ts} +1 -1
  90. package/dist/exceptions.d.ts +21 -0
  91. package/dist/exceptions.js +30 -0
  92. package/dist/framework/base_module.d.ts +1 -1
  93. package/dist/framework/createApp.d.ts +3 -3
  94. package/dist/framework/domain_module.d.ts +1 -1
  95. package/dist/framework/kernel.d.ts +1 -1
  96. package/dist/framework/kernel.js +17 -8
  97. package/dist/infrastructure/database/connector.d.ts +2 -0
  98. package/dist/infrastructure/database/connector.js +22 -0
  99. package/dist/infrastructure/database/index.d.ts +1 -0
  100. package/dist/infrastructure/database/index.js +1 -0
  101. package/dist/infrastructure/database/schema.d.ts +9 -0
  102. package/dist/infrastructure/database/schema.js +61 -0
  103. package/dist/infrastructure/database/utils.d.ts +2 -0
  104. package/dist/infrastructure/database/utils.js +12 -4
  105. package/dist/infrastructure/event_chain.d.ts +6 -0
  106. package/dist/infrastructure/event_chain.js +25 -0
  107. package/dist/infrastructure/telemetry/tracing/tracing_hooks.js +8 -5
  108. package/dist/infrastructure/ui/UIEventBus.d.ts +3 -1
  109. package/dist/infrastructure/ui/UIEventBus.js +8 -1
  110. package/dist/infrastructure/ui/activity.d.ts +37 -0
  111. package/dist/infrastructure/ui/activity.js +84 -0
  112. package/dist/infrastructure/workers/CronWorker.d.ts +6 -4
  113. package/dist/infrastructure/workers/CronWorker.js +24 -18
  114. package/dist/infrastructure/workers/EventBus.d.ts +9 -5
  115. package/dist/infrastructure/workers/EventBus.js +68 -33
  116. package/dist/services/bluetooth.service.js +16 -14
  117. package/dist/services/dead_letter_queue.service.d.ts +7 -7
  118. package/dist/services/dead_letter_queue.service.js +0 -2
  119. package/dist/services/event.service.d.ts +3 -3
  120. package/dist/services/event.service.js +1 -1
  121. package/dist/services/network.service.d.ts +1 -1
  122. package/dist/services/network.service.js +17 -15
  123. package/dist/services/printer.service.d.ts +1 -1
  124. package/dist/services/printer.service.js +50 -44
  125. package/dist/tools/utils/date.js +4 -3
  126. package/dist/tools/utils/monetary.d.ts +6 -3
  127. package/dist/tools/utils/monetary.js +33 -21
  128. package/dist/tools/utils/serializer.d.ts +1 -1
  129. package/dist/tools/utils/serializer.js +32 -35
  130. package/dist/ui/activity/DeviceNotices.d.ts +1 -0
  131. package/dist/ui/activity/DeviceNotices.js +29 -0
  132. package/dist/ui/activity/ProcessToast.d.ts +2 -0
  133. package/dist/ui/activity/ProcessToast.js +71 -0
  134. package/dist/ui/activity/index.d.ts +4 -0
  135. package/dist/ui/activity/index.js +4 -0
  136. package/dist/ui/activity/useActivity.d.ts +9 -0
  137. package/dist/ui/activity/useActivity.js +48 -0
  138. package/dist/ui/components/molecules/EventTimelineItem.d.ts +2 -2
  139. package/dist/ui/components/molecules/EventTimelineItem.js +1 -1
  140. package/dist/ui/components/molecules/index.d.ts +1 -2
  141. package/dist/ui/components/molecules/index.js +1 -2
  142. package/dist/ui/components/organisms/DeadLetterQueueRow.d.ts +3 -3
  143. package/dist/ui/components/organisms/EventRow.d.ts +3 -3
  144. package/dist/ui/components/organisms/EventRow.js +1 -1
  145. package/dist/ui/screens/dead_letter_queue/dead_letter_queue.context.d.ts +5 -5
  146. package/dist/ui/screens/events/events.context.d.ts +4 -4
  147. package/package.json +13 -8
  148. package/dist/domain/event_sourcing/domain_event.js +0 -164
  149. package/dist/domain/event_sourcing/event.d.ts +0 -25
  150. package/dist/domain/event_sourcing/event.js +0 -25
  151. package/dist/domain/event_sourcing/index.d.ts +0 -2
  152. package/dist/domain/event_sourcing/index.js +0 -2
  153. package/dist/domain/events.d.ts +0 -33
  154. package/dist/infrastructure/ui/ToastHost.d.ts +0 -6
  155. package/dist/infrastructure/ui/ToastHost.js +0 -28
  156. package/dist/infrastructure/ui/events.d.ts +0 -1
  157. package/dist/infrastructure/ui/events.js +0 -1
  158. package/dist/ui/components/molecules/ProcessToast.d.ts +0 -8
  159. package/dist/ui/components/molecules/ProcessToast.js +0 -52
  160. /package/dist/domain/{repositories.d.ts → repositories/catalog.d.ts} +0 -0
  161. /package/dist/domain/{repositories.js → repositories/catalog.js} +0 -0
  162. /package/dist/domain/{database → repositories}/repository.js +0 -0
  163. /package/dist/{domain/event_sourcing/event_handler.js → event_driven/subscriber.js} +0 -0
  164. /package/dist/ui/{components/molecules → activity}/ProcessToastProvider.d.ts +0 -0
  165. /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
- * Type-safe, immutable collection for Entity aggregates with event sourcing support.
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
- * // Event sourcing
26
- * await collection.publishEventWith(PRICE_LISTS_SYNCED, pl => ({ id: pl.remoteId, name: pl.name }));
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
- _domainEventsV2 = [];
33
- _correlationIdV2 = null;
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
- // V2 METHODS - DomainEvent class-based system
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
- addDomainEventWithEntities(EventClass) {
485
- const event = EventClass.create({
462
+ recordEntities(EventClass) {
463
+ return this.stageDomainEvent(EventClass.create({
486
464
  records: this.entities.map((e) => e.asJSON()),
487
- });
488
- const existingEvent = this._domainEventsV2.find((e) => e.hasSameBusinessPayload(event));
465
+ }));
466
+ }
467
+ stageDomainEvent(event) {
468
+ const existingEvent = this._recordedEvents.find((e) => e.hasSameBusinessPayload(event));
489
469
  if (existingEvent) {
490
- loggerQueueProcessor.warn(`EntityCollection - V2 Event: '${event.name}' with identical payload already exists. Skipping duplicate.`);
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._correlationIdV2) {
494
- this._correlationIdV2 = generateUUID();
473
+ if (!this._correlationId) {
474
+ this._correlationId = generateUUID();
495
475
  }
496
476
  event
477
+ .withEntityType(this.constructor.name)
497
478
  .withAggregateId(this.uuid)
498
- .withCorrelationId(this._correlationIdV2)
499
- .withSequence(this._domainEventsV2.length + 1);
500
- this._domainEventsV2.push(event);
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
- getDomainEvents() {
508
- return this._domainEventsV2.map((e) => e.clone());
488
+ recordedEvents() {
489
+ return this._recordedEvents.map((event) => event.clone());
509
490
  }
510
- clearDomainEvents() {
511
- this._domainEventsV2 = [];
512
- this._correlationIdV2 = null;
513
- }
514
- async publishAllDomainEvents() {
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
- * Filters entities using criteria array. All criteria must match (AND).
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
- const filtered = this.filter((entity) => {
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,6 @@
1
+ export interface ValueRule<T> {
2
+ readonly name: string;
3
+ holds(value: T): boolean;
4
+ parse(value: T): T;
5
+ }
6
+ export declare function valueRule<T>(name: string, holds: (value: T) => boolean): ValueRule<T>;
@@ -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 { DomainEvent } from "../domain/event_sourcing/domain_event";
2
- export * from "../domain/connectivity/events";
3
- export * from "../domain/event_sourcing/event";
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 DomainEvent {
16
- static name = "common.domain.v2.deactivate";
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 DomainEvent {
25
- static name = "common.settings.v2.added_new_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;
@@ -0,0 +1,5 @@
1
+ export type Chain = {
2
+ causationId: string | null;
3
+ correlationId: string;
4
+ };
5
+ export declare function chainAfter(causeId: string | null, causeCorrelation: string | null, ownId: string): Chain;
@@ -0,0 +1,6 @@
1
+ export function chainAfter(causeId, causeCorrelation, ownId) {
2
+ return {
3
+ causationId: causeId,
4
+ correlationId: causeCorrelation || causeId || ownId,
5
+ };
6
+ }
@@ -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
- type InfrastructureFields = "name" | "label" | "requiresNetwork" | "uuid" | "createdAt" | "status" | "attempts" | "errorMessage" | "acknowledgedAt" | "failedAt" | "aggregateId" | "sourceId" | "correlationId" | "sequence";
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>, InfrastructureFields>;
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
- cloneWithReset(): this;
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
- markAsProcessing(): this;
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 {};