@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
@@ -0,0 +1,305 @@
1
+ import { InvalidCriteria } from "@sincpro/criteria";
2
+ const UNITS = ["minutes", "hours", "days", "weeks", "months", "years"];
3
+ const GRAINS = ["day", "week", "month", "quarter", "year"];
4
+ export function deviceClock(now = new Date()) {
5
+ return {
6
+ now,
7
+ timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC",
8
+ };
9
+ }
10
+ export function readCriteriaValue(value, clock, field = "") {
11
+ if (Array.isArray(value)) {
12
+ return value.map((item) => readCriteriaValue(item, clock, field));
13
+ }
14
+ if (!isDynamic(value) || value.$ === "field")
15
+ return value;
16
+ if (value.$ === "today")
17
+ return resolveToday(value, clock);
18
+ if (value.$ === "now")
19
+ return resolveNow(value, clock);
20
+ if (value.$ === "period") {
21
+ const who = field.length > 0 ? `; '${field}' asked for it so` : "";
22
+ throw new InvalidCriteria(`a period is a range and cannot be one item of a list${who}`);
23
+ }
24
+ if (value.$ === "context" || value.$ === "param") {
25
+ throw new InvalidCriteria("a context or parameter value is not read on the device");
26
+ }
27
+ throw new InvalidCriteria(`'${value.$}' is not read on the device`);
28
+ }
29
+ function resolveToday(value, clock) {
30
+ const span = spanOf(value.plus);
31
+ if ((span.hours ?? 0) !== 0 || (span.minutes ?? 0) !== 0) {
32
+ throw new InvalidCriteria("a date has no hours or minutes; use `now` to move by them");
33
+ }
34
+ const moved = value.plus === undefined ? zonedDay(clock) : shiftCalendar(zonedDay(clock), span);
35
+ const snapped = snap(moved, grainOf(value.start_of));
36
+ return formatDay(snapped);
37
+ }
38
+ function resolveNow(value, clock) {
39
+ const span = spanOf(value.plus);
40
+ const grain = grainOf(value.start_of);
41
+ let utc = clock.now;
42
+ if (value.plus !== undefined) {
43
+ const wall = zonedWall(clock);
44
+ const shifted = {
45
+ ...shiftCalendar(wall, span),
46
+ hour: wall.hour,
47
+ minute: wall.minute,
48
+ second: wall.second,
49
+ milli: wall.milli,
50
+ };
51
+ const elapsed = ((span.hours ?? 0) * 60 + (span.minutes ?? 0)) * 60_000;
52
+ utc = new Date(wallToUtc(shifted, clock.timeZone).getTime() + elapsed);
53
+ }
54
+ if (grain === undefined)
55
+ return utc.toISOString();
56
+ const start = snap(zonedWall({ now: utc, timeZone: clock.timeZone }), grain);
57
+ return wallToUtc({ ...start, hour: 0, minute: 0, second: 0, milli: 0 }, clock.timeZone).toISOString();
58
+ }
59
+ function zonedDay(clock) {
60
+ const wall = zonedWall(clock);
61
+ return { year: wall.year, month: wall.month, day: wall.day };
62
+ }
63
+ function zonedWall(clock) {
64
+ let parts;
65
+ try {
66
+ parts = new Intl.DateTimeFormat("en-US", {
67
+ timeZone: clock.timeZone,
68
+ hourCycle: "h23",
69
+ year: "numeric",
70
+ month: "2-digit",
71
+ day: "2-digit",
72
+ hour: "2-digit",
73
+ minute: "2-digit",
74
+ second: "2-digit",
75
+ }).formatToParts(clock.now);
76
+ }
77
+ catch {
78
+ throw new InvalidCriteria(`unknown timezone '${clock.timeZone}'`);
79
+ }
80
+ const read = (type) => {
81
+ const found = parts.find((part) => part.type === type)?.value;
82
+ if (found === undefined || !/^\d+$/.test(found)) {
83
+ throw new InvalidCriteria(`unknown timezone '${clock.timeZone}'`);
84
+ }
85
+ return Number(found);
86
+ };
87
+ return {
88
+ year: read("year"),
89
+ month: read("month"),
90
+ day: read("day"),
91
+ hour: read("hour") % 24,
92
+ minute: read("minute"),
93
+ second: read("second"),
94
+ milli: clock.now.getUTCMilliseconds(),
95
+ };
96
+ }
97
+ function shiftCalendar(day, span) {
98
+ const months = (span.months ?? 0) + (span.years ?? 0) * 12;
99
+ const index = day.year * 12 + day.month - 1 + months;
100
+ const year = Math.floor(index / 12);
101
+ const month = index - year * 12 + 1;
102
+ const last = new Date(Date.UTC(year, month, 0)).getUTCDate();
103
+ const moved = new Date(Date.UTC(year, month - 1, Math.min(day.day, last) + (span.days ?? 0) + 7 * (span.weeks ?? 0)));
104
+ return {
105
+ year: moved.getUTCFullYear(),
106
+ month: moved.getUTCMonth() + 1,
107
+ day: moved.getUTCDate(),
108
+ };
109
+ }
110
+ function snap(day, grain) {
111
+ if (grain === undefined || grain === "day")
112
+ return day;
113
+ if (grain === "year")
114
+ return { year: day.year, month: 1, day: 1 };
115
+ if (grain === "month")
116
+ return { year: day.year, month: day.month, day: 1 };
117
+ if (grain === "quarter") {
118
+ return {
119
+ year: day.year,
120
+ month: 3 * Math.floor((day.month - 1) / 3) + 1,
121
+ day: 1,
122
+ };
123
+ }
124
+ const utc = new Date(Date.UTC(day.year, day.month - 1, day.day));
125
+ const mondayBased = (utc.getUTCDay() + 6) % 7;
126
+ const start = new Date(utc.getTime() - mondayBased * 86_400_000);
127
+ return {
128
+ year: start.getUTCFullYear(),
129
+ month: start.getUTCMonth() + 1,
130
+ day: start.getUTCDate(),
131
+ };
132
+ }
133
+ function wallToUtc(wall, timeZone) {
134
+ const guess = Date.UTC(wall.year, wall.month - 1, wall.day, wall.hour, wall.minute, wall.second);
135
+ const corrected = guess - zoneOffset(new Date(guess), timeZone);
136
+ const again = guess - zoneOffset(new Date(corrected), timeZone);
137
+ return new Date(again + wall.milli);
138
+ }
139
+ function zoneOffset(instant, timeZone) {
140
+ const wall = zonedWall({ now: instant, timeZone });
141
+ return (Date.UTC(wall.year, wall.month - 1, wall.day, wall.hour, wall.minute, wall.second) -
142
+ (instant.getTime() - wall.milli));
143
+ }
144
+ function formatDay(day) {
145
+ const month = String(day.month).padStart(2, "0");
146
+ const date = String(day.day).padStart(2, "0");
147
+ return `${day.year}-${month}-${date}`;
148
+ }
149
+ const PERIOD_NAMES = [
150
+ "today",
151
+ "yesterday",
152
+ "tomorrow",
153
+ "this_week",
154
+ "last_week",
155
+ "next_week",
156
+ "this_month",
157
+ "last_month",
158
+ "next_month",
159
+ "this_quarter",
160
+ "last_quarter",
161
+ "next_quarter",
162
+ "this_year",
163
+ "last_year",
164
+ "next_year",
165
+ ];
166
+ const PERIOD_STARTS = {
167
+ today: ["day", 0],
168
+ yesterday: ["day", -1],
169
+ tomorrow: ["day", 1],
170
+ this_week: ["week", 0],
171
+ last_week: ["week", -1],
172
+ next_week: ["week", 1],
173
+ this_month: ["month", 0],
174
+ last_month: ["month", -1],
175
+ next_month: ["month", 1],
176
+ this_quarter: ["quarter", 0],
177
+ last_quarter: ["quarter", -1],
178
+ next_quarter: ["quarter", 1],
179
+ this_year: ["year", 0],
180
+ last_year: ["year", -1],
181
+ next_year: ["year", 1],
182
+ };
183
+ export function periodBounds(value, clock) {
184
+ const period = parsePeriod(value);
185
+ const today = zonedDay(clock);
186
+ if (period.kind === "name") {
187
+ const [grain, away] = PERIOD_STARTS[period.name];
188
+ const start = snap(shiftCalendar(today, scale(grainSpan(grain), away)), grain);
189
+ return [formatDay(start), formatDay(shiftCalendar(start, grainSpan(grain)))];
190
+ }
191
+ const current = snap(today, period.unit);
192
+ const step = grainSpan(period.unit);
193
+ const at = (amount) => shiftCalendar(current, scale(step, amount));
194
+ if (period.side === "last") {
195
+ return [
196
+ formatDay(at(period.includeCurrent ? -(period.count - 1) : -period.count)),
197
+ formatDay(at(period.includeCurrent ? 1 : 0)),
198
+ ];
199
+ }
200
+ return [
201
+ formatDay(at(period.includeCurrent ? 0 : 1)),
202
+ formatDay(at(period.includeCurrent ? period.count : period.count + 1)),
203
+ ];
204
+ }
205
+ function grainSpan(grain) {
206
+ if (grain === "day")
207
+ return { days: 1 };
208
+ if (grain === "week")
209
+ return { weeks: 1 };
210
+ if (grain === "month")
211
+ return { months: 1 };
212
+ if (grain === "quarter")
213
+ return { months: 3 };
214
+ return { years: 1 };
215
+ }
216
+ function scale(span, amount) {
217
+ const scaled = {};
218
+ for (const unit of UNITS) {
219
+ const step = span[unit];
220
+ if (step !== undefined)
221
+ scaled[unit] = step * amount;
222
+ }
223
+ return scaled;
224
+ }
225
+ function parsePeriod(value) {
226
+ if (!isDynamic(value) || value.$ !== "period") {
227
+ throw new InvalidCriteria("a period is a name, or a unit with `last` or `next`");
228
+ }
229
+ const record = value;
230
+ for (const key of Object.keys(record)) {
231
+ if (!["$", "name", "unit", "last", "next", "include_current"].includes(key)) {
232
+ throw new InvalidCriteria(`'${key}' is not part of a period`);
233
+ }
234
+ }
235
+ const name = record.name;
236
+ const unit = record.unit;
237
+ const last = record.last;
238
+ const next = record.next;
239
+ const include = record.include_current;
240
+ const counted = [last, next].filter((one) => one !== undefined);
241
+ if (name !== undefined) {
242
+ if (typeof name !== "string" || !PERIOD_NAMES.includes(name)) {
243
+ throw new InvalidCriteria(`'${String(name)}' is not a period the engine declares; use one of ${PERIOD_NAMES.join(", ")}`);
244
+ }
245
+ if (unit !== undefined || counted.length > 0 || include) {
246
+ throw new InvalidCriteria("a named period takes nothing else; `unit`, `last`, `next` and `include_current` describe a window");
247
+ }
248
+ return { kind: "name", name: name };
249
+ }
250
+ if (grainOf(unit) === undefined || counted.length !== 1) {
251
+ throw new InvalidCriteria('a period is a name, or a unit with `last` or `next`: {"$": "period", "unit": "day", "last": 30}');
252
+ }
253
+ const count = counted[0];
254
+ if (typeof count !== "number" || !Number.isInteger(count) || count < 1) {
255
+ throw new InvalidCriteria(`a period counts at least one unit; got ${String(count)}`);
256
+ }
257
+ if (include !== undefined && typeof include !== "boolean") {
258
+ throw new InvalidCriteria("include_current is true or false");
259
+ }
260
+ return {
261
+ kind: "window",
262
+ unit: unit,
263
+ side: last === undefined ? "next" : "last",
264
+ count,
265
+ includeCurrent: include === true,
266
+ };
267
+ }
268
+ function spanOf(plus) {
269
+ if (plus === undefined)
270
+ return {};
271
+ if (plus === null || typeof plus !== "object" || Array.isArray(plus)) {
272
+ throw new InvalidCriteria("a span names calendar units");
273
+ }
274
+ const record = plus;
275
+ for (const key of Object.keys(record)) {
276
+ if (!UNITS.includes(key)) {
277
+ throw new InvalidCriteria(`'${key}' is not a span unit`);
278
+ }
279
+ }
280
+ const span = {};
281
+ for (const unit of UNITS) {
282
+ const amount = record[unit];
283
+ if (amount === undefined)
284
+ continue;
285
+ if (typeof amount !== "number" || !Number.isInteger(amount)) {
286
+ throw new InvalidCriteria("a span counts whole units");
287
+ }
288
+ span[unit] = amount;
289
+ }
290
+ return span;
291
+ }
292
+ function grainOf(value) {
293
+ if (value === undefined)
294
+ return undefined;
295
+ if (typeof value === "string" && GRAINS.includes(value))
296
+ return value;
297
+ throw new InvalidCriteria(`'${String(value)}' is not a calendar grain`);
298
+ }
299
+ function isDynamic(value) {
300
+ return (value !== null &&
301
+ typeof value === "object" &&
302
+ !Array.isArray(value) &&
303
+ !(value instanceof Date) &&
304
+ "$" in value);
305
+ }
@@ -0,0 +1,61 @@
1
+ import { type Operator } from "@sincpro/criteria";
2
+ import { type DocumentCriteria } from "./criteria";
3
+ import { type CriteriaClock, deviceClock } from "./criteria_clock";
4
+ export type SqlParam = string | number | null;
5
+ export interface CriteriaSqlTarget {
6
+ table: string;
7
+ column(field: string): boolean;
8
+ relation?(name: string): CriteriaSqlTarget | undefined;
9
+ }
10
+ export interface FieldRef {
11
+ kind: "column" | "json";
12
+ name: string;
13
+ path: string;
14
+ }
15
+ export type Predicate = {
16
+ op: "true";
17
+ } | {
18
+ op: "false";
19
+ } | {
20
+ op: "not";
21
+ item: Predicate;
22
+ } | {
23
+ op: "and" | "or";
24
+ items: Predicate[];
25
+ } | {
26
+ op: "exists";
27
+ table: string;
28
+ link: string;
29
+ item: Predicate;
30
+ } | {
31
+ op: "cmp";
32
+ left: FieldRef;
33
+ operator: Operator;
34
+ right: {
35
+ field: FieldRef;
36
+ } | {
37
+ value: SqlParam | SqlParam[];
38
+ };
39
+ };
40
+ export interface CompiledCriteria {
41
+ whereSql: string;
42
+ params: SqlParam[];
43
+ orderSql: string;
44
+ order: {
45
+ ref: FieldRef;
46
+ descending: boolean;
47
+ }[];
48
+ limit?: number;
49
+ offset: number;
50
+ predicate: Predicate;
51
+ }
52
+ export interface SqlDocument {
53
+ uuid: string;
54
+ version: number;
55
+ data: string;
56
+ columns: Record<string, SqlParam>;
57
+ }
58
+ export type { CriteriaClock };
59
+ export { deviceClock };
60
+ export declare function compileCriteria<T>(asked: DocumentCriteria<T>, target: CriteriaSqlTarget, clock?: CriteriaClock): CompiledCriteria;
61
+ export declare function rowsFor(compiled: CompiledCriteria, rows: readonly SqlDocument[], others?: (table: string) => readonly SqlDocument[]): SqlDocument[];