@sincpro/mobile 0.4.3 → 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 (197) 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/ReceiptExporter.adapter.js +10 -2
  5. package/dist/adapters/repositories/database_table.repository.d.ts +3 -2
  6. package/dist/adapters/repositories/database_table.repository.js +1 -1
  7. package/dist/adapters/repositories/document.repository.d.ts +81 -0
  8. package/dist/adapters/repositories/document.repository.js +653 -0
  9. package/dist/adapters/repositories/domain_event.repository.d.ts +17 -17
  10. package/dist/adapters/repositories/domain_event.repository.js +25 -31
  11. package/dist/adapters/repositories/domain_event_dead_letter.repository.d.ts +10 -10
  12. package/dist/adapters/repositories/domain_event_dead_letter.repository.js +14 -13
  13. package/dist/adapters/repositories/event_row.d.ts +13 -0
  14. package/dist/adapters/repositories/event_row.js +22 -0
  15. package/dist/adapters/repositories/sqlite_document_store.d.ts +33 -0
  16. package/dist/adapters/repositories/sqlite_document_store.js +201 -0
  17. package/dist/domain/connectivity/events.d.ts +5 -5
  18. package/dist/domain/connectivity/events.js +3 -3
  19. package/dist/domain/database/criteria.d.ts +19 -0
  20. package/dist/domain/database/criteria.js +36 -0
  21. package/dist/domain/database/criteria_clock.d.ts +8 -0
  22. package/dist/domain/database/criteria_clock.js +305 -0
  23. package/dist/domain/database/criteria_sql.d.ts +61 -0
  24. package/dist/domain/database/criteria_sql.js +476 -0
  25. package/dist/domain/database/database.d.ts +1 -0
  26. package/dist/domain/database/index.d.ts +3 -1
  27. package/dist/domain/database/index.js +3 -1
  28. package/dist/domain/database/migration_plan.d.ts +14 -0
  29. package/dist/domain/database/migration_plan.js +44 -0
  30. package/dist/domain/entity/change_tracking.d.ts +21 -0
  31. package/dist/domain/entity/change_tracking.js +71 -0
  32. package/dist/domain/entity/checks.d.ts +8 -0
  33. package/dist/domain/entity/checks.js +82 -0
  34. package/dist/domain/entity/entity.d.ts +39 -32
  35. package/dist/domain/entity/entity.js +94 -105
  36. package/dist/domain/entity/entity_collection.d.ts +15 -30
  37. package/dist/domain/entity/entity_collection.js +30 -121
  38. package/dist/domain/entity/index.d.ts +5 -0
  39. package/dist/domain/entity/index.js +5 -0
  40. package/dist/domain/entity/reconcile.d.ts +7 -0
  41. package/dist/domain/entity/reconcile.js +12 -0
  42. package/dist/domain/entity/relations.d.ts +27 -0
  43. package/dist/domain/entity/relations.js +69 -0
  44. package/dist/domain/entity/remote_sync.d.ts +4 -0
  45. package/dist/domain/entity/remote_sync.js +19 -0
  46. package/dist/domain/entity/values.d.ts +6 -0
  47. package/dist/domain/entity/values.js +13 -0
  48. package/dist/domain/events/catalog.d.ts +29 -0
  49. package/dist/domain/{events.js → events/catalog.js} +7 -11
  50. package/dist/domain/events/chain.d.ts +5 -0
  51. package/dist/domain/events/chain.js +6 -0
  52. package/dist/domain/{event_sourcing → events}/domain_event.d.ts +20 -22
  53. package/dist/domain/events/domain_event.js +227 -0
  54. package/dist/domain/events/index.d.ts +8 -0
  55. package/dist/domain/events/index.js +8 -0
  56. package/dist/domain/events/integration_event.d.ts +103 -0
  57. package/dist/domain/events/integration_event.js +72 -0
  58. package/dist/domain/events/label.d.ts +2 -0
  59. package/dist/domain/events/label.js +26 -0
  60. package/dist/domain/index.d.ts +0 -1
  61. package/dist/domain/index.js +0 -1
  62. package/dist/domain/print/events.d.ts +8 -4
  63. package/dist/domain/print/events.js +9 -4
  64. package/dist/domain/repositories/document_store.d.ts +33 -0
  65. package/dist/domain/repositories/document_store.js +5 -0
  66. package/dist/domain/repositories/hooks.d.ts +23 -0
  67. package/dist/domain/repositories/hooks.js +32 -0
  68. package/dist/domain/repositories/index.d.ts +4 -0
  69. package/dist/domain/repositories/index.js +4 -0
  70. package/dist/domain/{database → repositories}/repository.d.ts +9 -3
  71. package/dist/domain/settings.d.ts +4 -1
  72. package/dist/domain/settings.js +3 -0
  73. package/dist/domain/webview/events.d.ts +2 -2
  74. package/dist/domain/webview/events.js +2 -2
  75. package/dist/entrypoints/db/migrations.js +10 -10
  76. package/dist/entrypoints/queue/QueueProcessor.d.ts +1 -1
  77. package/dist/entrypoints/queue/activateDomain.subscriber.d.ts +2 -2
  78. package/dist/entrypoints/queue/activateDomain.subscriber.js +2 -2
  79. package/dist/entrypoints/queue/newAppSettings.handler.d.ts +2 -2
  80. package/dist/entrypoints/queue/newAppSettings.handler.js +1 -1
  81. package/dist/entrypoints/queue/printImage.subscriber.d.ts +1 -1
  82. package/dist/entrypoints/queue/printImage.subscriber.js +2 -2
  83. package/dist/entrypoints/queue/processWebViewMessage.subscriber.d.ts +1 -1
  84. package/dist/entrypoints/queue/processWebViewMessage.subscriber.js +1 -1
  85. package/dist/entrypoints/ui/AppShell.js +2 -2
  86. package/dist/entrypoints/ui/common_provider.d.ts +1 -13
  87. package/dist/entrypoints/ui/common_provider.js +4 -133
  88. package/dist/entrypoints/ui/domain_switcher.d.ts +2 -2
  89. package/dist/event_driven/index.d.ts +1 -0
  90. package/dist/event_driven/index.js +1 -0
  91. package/dist/{domain/event_sourcing/event_handler.d.ts → event_driven/subscriber.d.ts} +1 -1
  92. package/dist/exceptions.d.ts +21 -0
  93. package/dist/exceptions.js +30 -0
  94. package/dist/framework/base_module.d.ts +1 -1
  95. package/dist/framework/createApp.d.ts +3 -3
  96. package/dist/framework/domain_module.d.ts +1 -1
  97. package/dist/framework/feature.d.ts +26 -0
  98. package/dist/framework/feature.js +36 -0
  99. package/dist/framework/kernel.d.ts +1 -1
  100. package/dist/framework/kernel.js +17 -8
  101. package/dist/index.d.ts +1 -0
  102. package/dist/index.js +1 -0
  103. package/dist/infrastructure/database/connector.d.ts +2 -0
  104. package/dist/infrastructure/database/connector.js +22 -0
  105. package/dist/infrastructure/database/index.d.ts +1 -0
  106. package/dist/infrastructure/database/index.js +1 -0
  107. package/dist/infrastructure/database/schema.d.ts +9 -0
  108. package/dist/infrastructure/database/schema.js +61 -0
  109. package/dist/infrastructure/database/utils.d.ts +2 -0
  110. package/dist/infrastructure/database/utils.js +12 -4
  111. package/dist/infrastructure/event_chain.d.ts +6 -0
  112. package/dist/infrastructure/event_chain.js +25 -0
  113. package/dist/infrastructure/interceptor/intercept.d.ts +7 -2
  114. package/dist/infrastructure/interceptor/intercept.js +5 -2
  115. package/dist/infrastructure/telemetry/tracing/tracing_hooks.d.ts +9 -6
  116. package/dist/infrastructure/telemetry/tracing/tracing_hooks.js +61 -35
  117. package/dist/infrastructure/ui/UIEventBus.d.ts +3 -1
  118. package/dist/infrastructure/ui/UIEventBus.js +8 -1
  119. package/dist/infrastructure/ui/activity.d.ts +37 -0
  120. package/dist/infrastructure/ui/activity.js +84 -0
  121. package/dist/infrastructure/workers/CronWorker.d.ts +6 -4
  122. package/dist/infrastructure/workers/CronWorker.js +24 -18
  123. package/dist/infrastructure/workers/EventBus.d.ts +9 -5
  124. package/dist/infrastructure/workers/EventBus.js +68 -33
  125. package/dist/services/bluetooth.service.js +16 -14
  126. package/dist/services/dead_letter_queue.service.d.ts +7 -7
  127. package/dist/services/dead_letter_queue.service.js +0 -2
  128. package/dist/services/event.service.d.ts +3 -3
  129. package/dist/services/event.service.js +1 -1
  130. package/dist/services/network.service.d.ts +1 -1
  131. package/dist/services/network.service.js +17 -15
  132. package/dist/services/printer.service.d.ts +1 -1
  133. package/dist/services/printer.service.js +50 -44
  134. package/dist/tools/utils/date.js +4 -3
  135. package/dist/tools/utils/monetary.d.ts +6 -3
  136. package/dist/tools/utils/monetary.js +33 -21
  137. package/dist/tools/utils/serializer.d.ts +1 -1
  138. package/dist/tools/utils/serializer.js +32 -35
  139. package/dist/ui/activity/DeviceNotices.d.ts +1 -0
  140. package/dist/ui/activity/DeviceNotices.js +29 -0
  141. package/dist/ui/activity/ProcessToast.d.ts +2 -0
  142. package/dist/ui/activity/ProcessToast.js +71 -0
  143. package/dist/ui/{components/molecules → activity}/ProcessToastProvider.d.ts +1 -1
  144. package/dist/ui/activity/index.d.ts +4 -0
  145. package/dist/ui/activity/index.js +4 -0
  146. package/dist/ui/activity/useActivity.d.ts +9 -0
  147. package/dist/ui/activity/useActivity.js +48 -0
  148. package/dist/ui/components/atoms/DebugBanner.d.ts +1 -1
  149. package/dist/ui/components/molecules/BluetoothDeviceSelectorModal.d.ts +1 -1
  150. package/dist/ui/components/molecules/BluetoothDeviceSelectorModal.js +8 -2
  151. package/dist/ui/components/molecules/DeadLetterErrorBlock.d.ts +1 -1
  152. package/dist/ui/components/molecules/EventTimelineItem.d.ts +3 -3
  153. package/dist/ui/components/molecules/EventTimelineItem.js +1 -1
  154. package/dist/ui/components/molecules/GeoPermissionCard.d.ts +1 -1
  155. package/dist/ui/components/molecules/TimeZoneSelector.d.ts +1 -1
  156. package/dist/ui/components/molecules/TimeZoneSelectorModal.d.ts +1 -1
  157. package/dist/ui/components/molecules/TimeZoneSelectorModal.js +5 -3
  158. package/dist/ui/components/molecules/index.d.ts +1 -2
  159. package/dist/ui/components/molecules/index.js +1 -2
  160. package/dist/ui/components/organisms/BluetoothPrinterSelector.d.ts +1 -1
  161. package/dist/ui/components/organisms/BluetoothPrinterSelector.js +3 -0
  162. package/dist/ui/components/organisms/DatabaseInfoRow.d.ts +1 -1
  163. package/dist/ui/components/organisms/DeadLetterQueueRow.d.ts +5 -4
  164. package/dist/ui/components/organisms/EventRow.d.ts +4 -4
  165. package/dist/ui/components/organisms/EventRow.js +1 -1
  166. package/dist/ui/components/organisms/InjectableWebView.d.ts +2 -2
  167. package/dist/ui/components/organisms/InjectableWebView.js +6 -3
  168. package/dist/ui/components/organisms/Receipt.d.ts +2 -1
  169. package/dist/ui/components/organisms/TableInfoInfoRow.d.ts +1 -1
  170. package/dist/ui/screens/database/database.context.d.ts +2 -2
  171. package/dist/ui/screens/database/database.context.js +9 -18
  172. package/dist/ui/screens/database/database.json_detail.d.ts +1 -1
  173. package/dist/ui/screens/database/database.list.d.ts +1 -1
  174. package/dist/ui/screens/database/database.table_rows.d.ts +1 -1
  175. package/dist/ui/screens/dead_letter_queue/dead_letter_queue.context.d.ts +7 -7
  176. package/dist/ui/screens/dead_letter_queue/dead_letter_queue.list.d.ts +1 -1
  177. package/dist/ui/screens/events/events.context.d.ts +6 -6
  178. package/dist/ui/screens/events/events.context.js +20 -25
  179. package/dist/ui/screens/events/events.list.d.ts +1 -1
  180. package/package.json +51 -40
  181. package/dist/domain/event_sourcing/domain_event.js +0 -164
  182. package/dist/domain/event_sourcing/event.d.ts +0 -25
  183. package/dist/domain/event_sourcing/event.js +0 -25
  184. package/dist/domain/event_sourcing/index.d.ts +0 -2
  185. package/dist/domain/event_sourcing/index.js +0 -2
  186. package/dist/domain/events.d.ts +0 -33
  187. package/dist/infrastructure/ui/ToastHost.d.ts +0 -6
  188. package/dist/infrastructure/ui/ToastHost.js +0 -28
  189. package/dist/infrastructure/ui/events.d.ts +0 -1
  190. package/dist/infrastructure/ui/events.js +0 -1
  191. package/dist/ui/components/molecules/ProcessToast.d.ts +0 -8
  192. package/dist/ui/components/molecules/ProcessToast.js +0 -52
  193. /package/dist/domain/{repositories.d.ts → repositories/catalog.d.ts} +0 -0
  194. /package/dist/domain/{repositories.js → repositories/catalog.js} +0 -0
  195. /package/dist/domain/{database → repositories}/repository.js +0 -0
  196. /package/dist/{domain/event_sourcing/event_handler.js → event_driven/subscriber.js} +0 -0
  197. /package/dist/ui/{components/molecules → activity}/ProcessToastProvider.js +0 -0
@@ -0,0 +1,227 @@
1
+ import { ValueObject } from "../../domain/entity/value_object";
2
+ import { generateUUID } from "../../infrastructure/database/utils";
3
+ import { currentChain, traceparent } from "../../infrastructure/event_chain";
4
+ import { safeJsonParse, safeJsonStringify } from "../../tools/utils/serializer";
5
+ import { chainAfter } from "./chain";
6
+ import { textOf } from "./label";
7
+ export var EEventStatus;
8
+ (function (EEventStatus) {
9
+ EEventStatus["PENDING"] = "PENDING";
10
+ EEventStatus["PROCESSING"] = "PROCESSING";
11
+ EEventStatus["ACKNOWLEDGED"] = "ACKNOWLEDGED";
12
+ EEventStatus["FAILED"] = "FAILED";
13
+ EEventStatus["CANCELLED"] = "CANCELLED";
14
+ })(EEventStatus || (EEventStatus = {}));
15
+ const ENVELOPE_FIELDS = [
16
+ "name",
17
+ "label",
18
+ "requiresNetwork",
19
+ "uuid",
20
+ "createdAt",
21
+ "status",
22
+ "attempts",
23
+ "errorMessage",
24
+ "acknowledgedAt",
25
+ "failedAt",
26
+ "aggregateId",
27
+ "sourceId",
28
+ "correlationId",
29
+ "causationId",
30
+ "entityType",
31
+ "entityVersion",
32
+ "traceparent",
33
+ "sequence",
34
+ ];
35
+ const ENVELOPE = new Set(ENVELOPE_FIELDS);
36
+ const WIRE_KEYS = new Set([
37
+ ...ENVELOPE_FIELDS,
38
+ "id",
39
+ "created_at",
40
+ "entity_type",
41
+ "entity_id",
42
+ "correlation_id",
43
+ "causation_id",
44
+ "entity_version",
45
+ ]);
46
+ export class DomainEvent extends ValueObject {
47
+ constructor(..._args) {
48
+ super();
49
+ const declared = new.target.label;
50
+ if (declared && typeof declared === "object") {
51
+ this.#label = { ...declared };
52
+ }
53
+ }
54
+ name = "";
55
+ label = "";
56
+ uuid = "";
57
+ createdAt = "";
58
+ aggregateId = null;
59
+ sourceId = null;
60
+ correlationId = null;
61
+ causationId = null;
62
+ entityType = "";
63
+ entityVersion = null;
64
+ traceparent = null;
65
+ sequence = 0;
66
+ #label = null;
67
+ static sanitize(data) {
68
+ if (data === null || data === undefined) {
69
+ return data;
70
+ }
71
+ if (data instanceof ValueObject) {
72
+ return safeJsonParse(data.asJSON());
73
+ }
74
+ if (Array.isArray(data)) {
75
+ return data.map((item) => DomainEvent.sanitize(item));
76
+ }
77
+ if (typeof data === "object" && data !== null) {
78
+ const result = {};
79
+ for (const [key, value] of Object.entries(data)) {
80
+ result[key] = DomainEvent.sanitize(value);
81
+ }
82
+ return result;
83
+ }
84
+ return data;
85
+ }
86
+ static create(data) {
87
+ const instance = new this();
88
+ if (data) {
89
+ const sanitized = DomainEvent.sanitize(data);
90
+ Object.assign(instance, sanitized);
91
+ }
92
+ Object.assign(instance, {
93
+ uuid: generateUUID(),
94
+ createdAt: new Date().toISOString(),
95
+ });
96
+ return instance;
97
+ }
98
+ static from(event) {
99
+ return this.fromJSON(event.asJSON());
100
+ }
101
+ static fromJSON(json) {
102
+ const written = (typeof json === "string" ? safeJsonParse(json) : { ...json });
103
+ if ("created_at" in written && !("createdAt" in written)) {
104
+ return DomainEvent.read(this, written);
105
+ }
106
+ const instance = new this();
107
+ Object.assign(instance, written);
108
+ return instance;
109
+ }
110
+ static read(ctor, written) {
111
+ const instance = new ctor();
112
+ const event = instance;
113
+ const shown = readLabel(written.label);
114
+ Object.assign(event, {
115
+ name: typeof written.name === "string" ? written.name : event.name,
116
+ uuid: asString(written.id, asString(written.uuid, event.uuid)),
117
+ label: shown.text || event.label,
118
+ createdAt: asString(written.created_at, asString(written.createdAt, "")),
119
+ entityType: asString(written.entity_type, ""),
120
+ aggregateId: asString(written.entity_id, null) || asString(written.aggregateId, null),
121
+ correlationId: asString(written.correlation_id, null),
122
+ causationId: asString(written.causation_id, null),
123
+ entityVersion: typeof written.entity_version === "number" ? written.entity_version : null,
124
+ traceparent: asString(written.traceparent, null),
125
+ sequence: typeof written.sequence === "number" ? written.sequence : 0,
126
+ });
127
+ event.#label = shown.label;
128
+ for (const [key, value] of Object.entries(written)) {
129
+ if (!WIRE_KEYS.has(key)) {
130
+ event[key] = value;
131
+ }
132
+ }
133
+ return instance;
134
+ }
135
+ withAggregateId(aggregateId) {
136
+ this.aggregateId = aggregateId;
137
+ return this;
138
+ }
139
+ withSourceId(sourceId) {
140
+ this.sourceId = sourceId;
141
+ return this;
142
+ }
143
+ withCorrelationId(correlationId) {
144
+ this.correlationId = correlationId;
145
+ return this;
146
+ }
147
+ withCausationId(causationId) {
148
+ this.causationId = causationId;
149
+ return this;
150
+ }
151
+ withEntityType(entityType) {
152
+ this.entityType = entityType;
153
+ return this;
154
+ }
155
+ withSequence(sequence) {
156
+ this.sequence = sequence;
157
+ return this;
158
+ }
159
+ causedBy(cause) {
160
+ const chain = chainAfter(cause.uuid, cause.correlationId, this.uuid);
161
+ this.causationId = chain.causationId;
162
+ this.correlationId = chain.correlationId;
163
+ return this;
164
+ }
165
+ applyChain(flowId) {
166
+ const cause = currentChain();
167
+ const chain = cause
168
+ ? chainAfter(cause.causationId, cause.correlationId, this.uuid)
169
+ : chainAfter(null, flowId, this.uuid);
170
+ this.causationId = chain.causationId;
171
+ this.correlationId = chain.correlationId;
172
+ if (!this.traceparent)
173
+ this.traceparent = traceparent();
174
+ return this;
175
+ }
176
+ labelText() {
177
+ return this.#label ?? this.label;
178
+ }
179
+ getBusinessPayload() {
180
+ const payload = {};
181
+ for (const [key, value] of Object.entries(this)) {
182
+ if (!ENVELOPE.has(key))
183
+ payload[key] = value;
184
+ }
185
+ return payload;
186
+ }
187
+ hasSameBusinessPayload(other) {
188
+ if (this.name !== other.name)
189
+ return false;
190
+ return (safeJsonStringify(this.getBusinessPayload()) ===
191
+ safeJsonStringify(other.getBusinessPayload()));
192
+ }
193
+ asJSON(pretty = false) {
194
+ const body = {
195
+ ...this.getBusinessPayload(),
196
+ name: this.name,
197
+ id: this.uuid,
198
+ label: this.#label ?? { default: this.label },
199
+ created_at: this.createdAt,
200
+ entity_type: this.entityType,
201
+ entity_id: this.aggregateId ?? "",
202
+ correlation_id: this.correlationId,
203
+ causation_id: this.causationId,
204
+ entity_version: this.entityVersion,
205
+ sequence: this.sequence,
206
+ };
207
+ if (this.traceparent)
208
+ body.traceparent = this.traceparent;
209
+ return safeJsonStringify(body, pretty);
210
+ }
211
+ }
212
+ function readLabel(label) {
213
+ if (typeof label === "string")
214
+ return { text: label, label: null };
215
+ if (label && typeof label === "object" && !Array.isArray(label)) {
216
+ const record = {};
217
+ for (const [key, value] of Object.entries(label)) {
218
+ if (typeof value === "string")
219
+ record[key] = value;
220
+ }
221
+ return { text: textOf(record), label: record };
222
+ }
223
+ return { text: "", label: null };
224
+ }
225
+ function asString(value, fallback) {
226
+ return typeof value === "string" ? value : fallback;
227
+ }
@@ -0,0 +1,8 @@
1
+ export * from "../../domain/connectivity/events";
2
+ export * from "../../domain/events/catalog";
3
+ export * from "../../domain/events/chain";
4
+ export * from "../../domain/events/domain_event";
5
+ export * from "../../domain/events/integration_event";
6
+ export * from "../../domain/events/label";
7
+ export * from "../../domain/print/events";
8
+ export * from "../../domain/webview/events";
@@ -0,0 +1,8 @@
1
+ export * from "../../domain/connectivity/events";
2
+ export * from "../../domain/events/catalog";
3
+ export * from "../../domain/events/chain";
4
+ export * from "../../domain/events/domain_event";
5
+ export * from "../../domain/events/integration_event";
6
+ export * from "../../domain/events/label";
7
+ export * from "../../domain/print/events";
8
+ export * from "../../domain/webview/events";
@@ -0,0 +1,103 @@
1
+ import { DomainEvent, EEventStatus } from "./domain_event";
2
+ type Constructor<T> = new (...args: any[]) => T;
3
+ export declare function IntegrationEventMixin<TBase extends Constructor<DomainEvent>>(Base: TBase): {
4
+ new (...args: any[]): {
5
+ status: EEventStatus;
6
+ attempts: number;
7
+ errorMessage: string | null;
8
+ acknowledgedAt: string | null;
9
+ failedAt: string | null;
10
+ readonly requiresNetwork: boolean;
11
+ markAsProcessing(): /*elided*/ any;
12
+ markAsAcknowledged(): /*elided*/ any;
13
+ markAsFailed(errorMessage: string): /*elided*/ any;
14
+ markAsCancelled(): /*elided*/ any;
15
+ retry(): /*elided*/ any;
16
+ cloneWithReset(): /*elided*/ any;
17
+ get isPending(): boolean;
18
+ get isProcessing(): boolean;
19
+ get isAcknowledged(): boolean;
20
+ get isFailed(): boolean;
21
+ get isCancelled(): boolean;
22
+ readonly name: string;
23
+ readonly label: string;
24
+ readonly uuid: string;
25
+ readonly createdAt: string;
26
+ aggregateId: string | null;
27
+ sourceId: string | null;
28
+ correlationId: string | null;
29
+ causationId: string | null;
30
+ entityType: string;
31
+ entityVersion: number | null;
32
+ traceparent: string | null;
33
+ sequence: number;
34
+ "__#private@#label": Record<string, string> | null;
35
+ withAggregateId(aggregateId: string): /*elided*/ any;
36
+ withSourceId(sourceId: string): /*elided*/ any;
37
+ withCorrelationId(correlationId: string): /*elided*/ any;
38
+ withCausationId(causationId: string | null): /*elided*/ any;
39
+ withEntityType(entityType: string): /*elided*/ any;
40
+ withSequence(sequence: number): /*elided*/ any;
41
+ causedBy(cause: DomainEvent): /*elided*/ any;
42
+ applyChain(flowId: string): /*elided*/ any;
43
+ labelText(): import("./label").LabelText;
44
+ getBusinessPayload(): Record<string, unknown>;
45
+ hasSameBusinessPayload(other: DomainEvent): boolean;
46
+ asJSON(pretty?: boolean): string;
47
+ fromJSON(json: any): /*elided*/ any;
48
+ clone(): /*elided*/ any;
49
+ equals(other: any): boolean;
50
+ };
51
+ } & TBase;
52
+ declare const IntegrationEvent_base: {
53
+ new (...args: any[]): {
54
+ status: EEventStatus;
55
+ attempts: number;
56
+ errorMessage: string | null;
57
+ acknowledgedAt: string | null;
58
+ failedAt: string | null;
59
+ readonly requiresNetwork: boolean;
60
+ markAsProcessing(): /*elided*/ any;
61
+ markAsAcknowledged(): /*elided*/ any;
62
+ markAsFailed(errorMessage: string): /*elided*/ any;
63
+ markAsCancelled(): /*elided*/ any;
64
+ retry(): /*elided*/ any;
65
+ cloneWithReset(): /*elided*/ any;
66
+ get isPending(): boolean;
67
+ get isProcessing(): boolean;
68
+ get isAcknowledged(): boolean;
69
+ get isFailed(): boolean;
70
+ get isCancelled(): boolean;
71
+ readonly name: string;
72
+ readonly label: string;
73
+ readonly uuid: string;
74
+ readonly createdAt: string;
75
+ aggregateId: string | null;
76
+ sourceId: string | null;
77
+ correlationId: string | null;
78
+ causationId: string | null;
79
+ entityType: string;
80
+ entityVersion: number | null;
81
+ traceparent: string | null;
82
+ sequence: number;
83
+ "__#private@#label": Record<string, string> | null;
84
+ withAggregateId(aggregateId: string): /*elided*/ any;
85
+ withSourceId(sourceId: string): /*elided*/ any;
86
+ withCorrelationId(correlationId: string): /*elided*/ any;
87
+ withCausationId(causationId: string | null): /*elided*/ any;
88
+ withEntityType(entityType: string): /*elided*/ any;
89
+ withSequence(sequence: number): /*elided*/ any;
90
+ causedBy(cause: DomainEvent): /*elided*/ any;
91
+ applyChain(flowId: string): /*elided*/ any;
92
+ labelText(): import("./label").LabelText;
93
+ getBusinessPayload(): Record<string, unknown>;
94
+ hasSameBusinessPayload(other: DomainEvent): boolean;
95
+ asJSON(pretty?: boolean): string;
96
+ fromJSON(json: any): /*elided*/ any;
97
+ clone(): /*elided*/ any;
98
+ equals(other: any): boolean;
99
+ };
100
+ } & typeof DomainEvent;
101
+ export declare class IntegrationEvent extends IntegrationEvent_base {
102
+ }
103
+ export {};
@@ -0,0 +1,72 @@
1
+ import { generateUUID } from "../../infrastructure/database/utils";
2
+ import { DomainEvent, EEventStatus } from "./domain_event";
3
+ export function IntegrationEventMixin(Base) {
4
+ return class extends Base {
5
+ // TS2545: a mixin class must declare a rest constructor.
6
+ // eslint-disable-next-line @typescript-eslint/no-useless-constructor
7
+ constructor(...args) {
8
+ super(...args);
9
+ }
10
+ status = EEventStatus.PENDING;
11
+ attempts = 0;
12
+ errorMessage = null;
13
+ acknowledgedAt = null;
14
+ failedAt = null;
15
+ requiresNetwork = false;
16
+ markAsProcessing() {
17
+ this.status = EEventStatus.PROCESSING;
18
+ this.attempts += 1;
19
+ return this;
20
+ }
21
+ markAsAcknowledged() {
22
+ this.status = EEventStatus.ACKNOWLEDGED;
23
+ this.acknowledgedAt = new Date().toISOString();
24
+ return this;
25
+ }
26
+ markAsFailed(errorMessage) {
27
+ this.status = EEventStatus.FAILED;
28
+ this.errorMessage = errorMessage;
29
+ this.failedAt = new Date().toISOString();
30
+ return this;
31
+ }
32
+ markAsCancelled() {
33
+ this.status = EEventStatus.CANCELLED;
34
+ return this;
35
+ }
36
+ retry() {
37
+ this.status = EEventStatus.PENDING;
38
+ this.errorMessage = null;
39
+ return this;
40
+ }
41
+ cloneWithReset() {
42
+ const clone = this.constructor.from(this);
43
+ Object.assign(clone, {
44
+ uuid: generateUUID(),
45
+ createdAt: new Date().toISOString(),
46
+ status: EEventStatus.PENDING,
47
+ attempts: 0,
48
+ errorMessage: null,
49
+ acknowledgedAt: null,
50
+ failedAt: null,
51
+ });
52
+ return clone;
53
+ }
54
+ get isPending() {
55
+ return this.status === EEventStatus.PENDING;
56
+ }
57
+ get isProcessing() {
58
+ return this.status === EEventStatus.PROCESSING;
59
+ }
60
+ get isAcknowledged() {
61
+ return this.status === EEventStatus.ACKNOWLEDGED;
62
+ }
63
+ get isFailed() {
64
+ return this.status === EEventStatus.FAILED;
65
+ }
66
+ get isCancelled() {
67
+ return this.status === EEventStatus.CANCELLED;
68
+ }
69
+ };
70
+ }
71
+ export class IntegrationEvent extends IntegrationEventMixin(DomainEvent) {
72
+ }
@@ -0,0 +1,2 @@
1
+ export type LabelText = string | Readonly<Record<string, string>>;
2
+ export declare function textOf(label: LabelText | null | undefined, locale?: string | null): string;
@@ -0,0 +1,26 @@
1
+ export function textOf(label, locale) {
2
+ if (typeof label === "string")
3
+ return label;
4
+ if (!label)
5
+ return "";
6
+ const table = label;
7
+ if (locale) {
8
+ const exact = table[locale];
9
+ if (exact)
10
+ return exact;
11
+ const language = locale.split("-")[0];
12
+ if (language && language !== locale && table[language])
13
+ return table[language];
14
+ if (table.default)
15
+ return table.default;
16
+ }
17
+ if (table.es)
18
+ return table.es;
19
+ if (table.default)
20
+ return table.default;
21
+ for (const value of Object.values(table)) {
22
+ if (value)
23
+ return value;
24
+ }
25
+ return "";
26
+ }
@@ -1,7 +1,6 @@
1
1
  export * from "../domain/connectivity";
2
2
  export * from "../domain/database";
3
3
  export * from "../domain/entity";
4
- export * from "../domain/event_sourcing";
5
4
  export * from "../domain/events";
6
5
  export * from "../domain/icon";
7
6
  export * from "../domain/receipt";
@@ -1,7 +1,6 @@
1
1
  export * from "../domain/connectivity";
2
2
  export * from "../domain/database";
3
3
  export * from "../domain/entity";
4
- export * from "../domain/event_sourcing";
5
4
  export * from "../domain/events";
6
5
  export * from "../domain/icon";
7
6
  export * from "../domain/receipt";
@@ -1,10 +1,14 @@
1
- import { DomainEvent } from "../../domain/event_sourcing";
2
- export declare class PrintImageRequestedEvent extends DomainEvent {
1
+ import { IntegrationEvent } from "../../domain/events/integration_event";
2
+ export declare class PrintImageRequestedEvent extends IntegrationEvent {
3
3
  static readonly name = "common.print.v1.image_requested";
4
- static readonly label = "Imprimiendo...";
4
+ static readonly label: {
5
+ es: string;
6
+ en: string;
7
+ };
5
8
  static readonly requiresNetwork = false;
9
+ static readonly ui = true;
6
10
  readonly name = "common.print.v1.image_requested";
7
- readonly label = "Imprimiendo...";
11
+ readonly label: string;
8
12
  readonly requiresNetwork = false;
9
13
  imageBase64: string;
10
14
  width: number;
@@ -1,10 +1,15 @@
1
- import { DomainEvent } from "../../domain/event_sourcing";
2
- export class PrintImageRequestedEvent extends DomainEvent {
1
+ import { IntegrationEvent } from "../../domain/events/integration_event";
2
+ import { textOf } from "../../domain/events/label";
3
+ export class PrintImageRequestedEvent extends IntegrationEvent {
3
4
  static name = "common.print.v1.image_requested";
4
- static label = "Imprimiendo...";
5
+ static label = {
6
+ es: "Imprimiendo...",
7
+ en: "Printing...",
8
+ };
5
9
  static requiresNetwork = false;
10
+ static ui = true;
6
11
  name = PrintImageRequestedEvent.name;
7
- label = PrintImageRequestedEvent.label;
12
+ label = textOf(PrintImageRequestedEvent.label);
8
13
  requiresNetwork = PrintImageRequestedEvent.requiresNetwork;
9
14
  imageBase64 = "";
10
15
  width = 0;
@@ -0,0 +1,33 @@
1
+ import { type CompiledCriteria } from "../../domain/database/criteria_sql";
2
+ import { type IntegrationEvent } from "../../domain/events/integration_event";
3
+ export declare enum StoreMode {
4
+ LOCAL = "local",
5
+ RELAY = "relay"
6
+ }
7
+ export type ColumnValue = string | number | null;
8
+ export interface DocumentRow {
9
+ uuid: string;
10
+ version: number;
11
+ data: string;
12
+ columns: Record<string, ColumnValue>;
13
+ }
14
+ export interface DocumentStore {
15
+ readonly table: string;
16
+ read(uuid: string): Promise<DocumentRow | null>;
17
+ readSync?(uuid: string): DocumentRow | null;
18
+ insert(row: DocumentRow): Promise<void>;
19
+ update(row: DocumentRow, expectedVersion: number): Promise<boolean>;
20
+ upsert(row: DocumentRow): Promise<void>;
21
+ remove(uuid: string): Promise<void>;
22
+ list(): Promise<DocumentRow[]>;
23
+ selectMatching(compiled: CompiledCriteria): Promise<DocumentRow[]>;
24
+ hasColumn(name: string): boolean;
25
+ selectBy(column: string, value: ColumnValue): Promise<DocumentRow[]>;
26
+ selectBySync?(column: string, value: ColumnValue): DocumentRow[];
27
+ inTransaction(): boolean;
28
+ transaction<T>(work: () => Promise<T>): Promise<T>;
29
+ }
30
+ export interface Outbox {
31
+ save(event: IntegrationEvent): Promise<void>;
32
+ schedule(): void;
33
+ }
@@ -0,0 +1,5 @@
1
+ export var StoreMode;
2
+ (function (StoreMode) {
3
+ StoreMode["LOCAL"] = "local";
4
+ StoreMode["RELAY"] = "relay";
5
+ })(StoreMode || (StoreMode = {}));
@@ -0,0 +1,23 @@
1
+ import { type Entity } from "../../domain/entity/entity";
2
+ import { type AnyClass } from "../../domain/entity/relations";
3
+ export interface Hook<T extends Entity = Entity> {
4
+ after_read?(record: T): void | Promise<void>;
5
+ before_save?(record: T): void | Promise<void>;
6
+ after_save?(record: T): void | Promise<void>;
7
+ before_create?(record: T): void | Promise<void>;
8
+ after_create?(record: T): void | Promise<void>;
9
+ before_update?(record: T): void | Promise<void>;
10
+ after_update?(record: T): void | Promise<void>;
11
+ before_remove?(record: T): void | Promise<void>;
12
+ after_remove?(record: T): void | Promise<void>;
13
+ after_search?(records: readonly T[]): void | Promise<void>;
14
+ }
15
+ export type HookMoment = "after_read" | "before_save" | "after_save" | "before_create" | "after_create" | "before_update" | "after_update" | "before_remove" | "after_remove" | "after_search";
16
+ export declare class Hooks {
17
+ private readonly pairs;
18
+ on<T extends Entity>(type: AnyClass<T>, hook: Hook<T>): this;
19
+ of(record: Entity): Hook[];
20
+ ofType(type: AnyClass<Entity>): Hook[];
21
+ }
22
+ export declare function fireHooks(hooks: readonly Hook[], moment: Exclude<HookMoment, "after_search">, record: Entity): Promise<void>;
23
+ export declare function fireSearch(hooks: readonly Hook[], records: readonly Entity[]): Promise<void>;
@@ -0,0 +1,32 @@
1
+ export class Hooks {
2
+ pairs = [];
3
+ on(type, hook) {
4
+ this.pairs.push({ type: type, hook });
5
+ return this;
6
+ }
7
+ of(record) {
8
+ return this.pairs
9
+ .filter((pair) => record instanceof pair.type)
10
+ .map((pair) => pair.hook);
11
+ }
12
+ ofType(type) {
13
+ return this.pairs
14
+ .filter((pair) => type === pair.type ||
15
+ type.prototype instanceof
16
+ pair.type)
17
+ .map((pair) => pair.hook);
18
+ }
19
+ }
20
+ export async function fireHooks(hooks, moment, record) {
21
+ for (const hook of hooks) {
22
+ const method = hook[moment];
23
+ if (method)
24
+ await method.call(hook, record);
25
+ }
26
+ }
27
+ export async function fireSearch(hooks, records) {
28
+ for (const hook of hooks) {
29
+ if (hook.after_search)
30
+ await hook.after_search(records);
31
+ }
32
+ }
@@ -0,0 +1,4 @@
1
+ export * from "../../domain/repositories/catalog";
2
+ export * from "../../domain/repositories/document_store";
3
+ export * from "../../domain/repositories/hooks";
4
+ export * from "../../domain/repositories/repository";
@@ -0,0 +1,4 @@
1
+ export * from "../../domain/repositories/catalog";
2
+ export * from "../../domain/repositories/document_store";
3
+ export * from "../../domain/repositories/hooks";
4
+ export * from "../../domain/repositories/repository";
@@ -1,12 +1,18 @@
1
+ import { type DocumentCriteria } from "../../domain/database/criteria";
1
2
  import { Entity, ERemoteState, RemoteEntity } from "../../domain/entity/entity";
2
- import { EntityCollection, ICriteria, RemoteEntityCollection } from "../../domain/entity/entity_collection";
3
+ import { EntityCollection, RemoteEntityCollection } from "../../domain/entity/entity_collection";
4
+ import { type IntegrationEvent } from "../../domain/events/integration_event";
3
5
  export interface IRepository<T extends Entity, C extends EntityCollection<T>> {
4
- save(entity: T | T[] | C): Promise<void>;
6
+ save(entity: T | T[] | C, options?: {
7
+ deliver?: boolean;
8
+ }): Promise<void>;
9
+ upsert(entity: T | T[] | C): Promise<void>;
5
10
  remove(entity: T | T[]): Promise<void>;
11
+ publish(events: readonly IntegrationEvent[]): Promise<void>;
6
12
  findById(id: string): Promise<T | null>;
7
13
  findByIds(ids: string[]): Promise<C>;
8
14
  findAll(): Promise<C>;
9
- findByCriteria(criteria: ICriteria<T>[]): Promise<C>;
15
+ findByCriteria(criteria: DocumentCriteria<T>): Promise<C>;
10
16
  findByIdSync?(id: string): T | null;
11
17
  findByIdsSync?(ids: string[]): C;
12
18
  }
@@ -1,5 +1,8 @@
1
1
  export declare enum ECommonSetting {
2
- SELECTED_PRINTER = "common.selected_printer"
2
+ SELECTED_PRINTER = "common.selected_printer",
3
+ UI_QUEUE = "ui.queue",
4
+ UI_CRON = "ui.cron",
5
+ UI_DEVICE = "ui.device"
3
6
  }
4
7
  export interface ISetting {
5
8
  key: string;
@@ -1,4 +1,7 @@
1
1
  export var ECommonSetting;
2
2
  (function (ECommonSetting) {
3
3
  ECommonSetting["SELECTED_PRINTER"] = "common.selected_printer";
4
+ ECommonSetting["UI_QUEUE"] = "ui.queue";
5
+ ECommonSetting["UI_CRON"] = "ui.cron";
6
+ ECommonSetting["UI_DEVICE"] = "ui.device";
4
7
  })(ECommonSetting || (ECommonSetting = {}));