@managesome/eposmatic-toolkit 0.4.59 → 0.4.61

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 (74) hide show
  1. package/esm/constants/MATERIALIZED_REPORTS.js +177 -8
  2. package/esm/helpers/materialized-reports/index.js +7 -0
  3. package/esm/helpers/materialized-reports/materialized-day-readiness.js +2 -2
  4. package/esm/helpers/materialized-reports/materialized-dinein-accumulator-helpers.js +557 -0
  5. package/esm/helpers/materialized-reports/materialized-dinein-classification-helpers.js +447 -0
  6. package/esm/helpers/materialized-reports/materialized-dinein-close-day-helpers.js +372 -0
  7. package/esm/helpers/materialized-reports/materialized-dinein-compile-helpers.js +500 -0
  8. package/esm/helpers/materialized-reports/materialized-dinein-entry-pages.js +218 -0
  9. package/esm/helpers/materialized-reports/materialized-dinein-key-helpers.js +87 -0
  10. package/esm/helpers/materialized-reports/materialized-index-bootstrap.js +4 -0
  11. package/esm/helpers/materialized-reports/materialized-report-drilldown-rows.js +8 -0
  12. package/esm/helpers/materialized-reports/report-platform/definition.js +93 -1
  13. package/esm/helpers/materialized-reports/tenant-dinein-formatter.js +240 -0
  14. package/esm/helpers/reporting-contract/report-contract.js +3 -0
  15. package/esm/schemas/models/index.js +2 -0
  16. package/esm/schemas/models/materialized_tenant_dinein_entries.js +57 -0
  17. package/esm/schemas/models/materialized_tenant_dinein_reports.js +73 -0
  18. package/esm/schemas/types/index.js +2 -0
  19. package/esm/schemas/types/materialized_report_drilldown_rows.js +1 -0
  20. package/esm/schemas/types/materialized_tenant_dinein_entries.js +1 -0
  21. package/esm/schemas/types/materialized_tenant_dinein_reports.js +6 -0
  22. package/lib/constants/MATERIALIZED_REPORTS.d.ts +160 -8
  23. package/lib/constants/MATERIALIZED_REPORTS.js +178 -9
  24. package/lib/helpers/materialized-reports/index.d.ts +7 -0
  25. package/lib/helpers/materialized-reports/index.js +7 -0
  26. package/lib/helpers/materialized-reports/materialized-day-readiness.d.ts +1 -1
  27. package/lib/helpers/materialized-reports/materialized-day-readiness.js +2 -2
  28. package/lib/helpers/materialized-reports/materialized-dinein-accumulator-helpers.d.ts +67 -0
  29. package/lib/helpers/materialized-reports/materialized-dinein-accumulator-helpers.js +582 -0
  30. package/lib/helpers/materialized-reports/materialized-dinein-classification-helpers.d.ts +245 -0
  31. package/lib/helpers/materialized-reports/materialized-dinein-classification-helpers.js +469 -0
  32. package/lib/helpers/materialized-reports/materialized-dinein-close-day-helpers.d.ts +110 -0
  33. package/lib/helpers/materialized-reports/materialized-dinein-close-day-helpers.js +384 -0
  34. package/lib/helpers/materialized-reports/materialized-dinein-compile-helpers.d.ts +73 -0
  35. package/lib/helpers/materialized-reports/materialized-dinein-compile-helpers.js +504 -0
  36. package/lib/helpers/materialized-reports/materialized-dinein-entry-pages.d.ts +69 -0
  37. package/lib/helpers/materialized-reports/materialized-dinein-entry-pages.js +231 -0
  38. package/lib/helpers/materialized-reports/materialized-dinein-key-helpers.d.ts +44 -0
  39. package/lib/helpers/materialized-reports/materialized-dinein-key-helpers.js +96 -0
  40. package/lib/helpers/materialized-reports/materialized-index-bootstrap.js +4 -0
  41. package/lib/helpers/materialized-reports/materialized-report-drilldown-rows.js +8 -0
  42. package/lib/helpers/materialized-reports/report-platform/definition.js +92 -0
  43. package/lib/helpers/materialized-reports/tenant-dinein-formatter.d.ts +225 -0
  44. package/lib/helpers/materialized-reports/tenant-dinein-formatter.js +243 -0
  45. package/lib/helpers/reporting-contract/report-contract.d.ts +1 -0
  46. package/lib/helpers/reporting-contract/report-contract.js +3 -0
  47. package/lib/schemas/models/index.d.ts +2 -0
  48. package/lib/schemas/models/index.js +2 -0
  49. package/lib/schemas/models/materialized_tenant_day_readiness.d.ts +3 -3
  50. package/lib/schemas/models/materialized_tenant_dinein_entries.d.ts +100 -0
  51. package/lib/schemas/models/materialized_tenant_dinein_entries.js +60 -0
  52. package/lib/schemas/models/materialized_tenant_dinein_reports.d.ts +111 -0
  53. package/lib/schemas/models/materialized_tenant_dinein_reports.js +76 -0
  54. package/lib/schemas/types/index.d.ts +2 -0
  55. package/lib/schemas/types/index.js +2 -0
  56. package/lib/schemas/types/materialized_report_drilldown_rows.d.ts +1 -1
  57. package/lib/schemas/types/materialized_report_drilldown_rows.js +1 -0
  58. package/lib/schemas/types/materialized_tenant_dinein_entries.d.ts +127 -0
  59. package/lib/schemas/types/materialized_tenant_dinein_entries.js +2 -0
  60. package/lib/schemas/types/materialized_tenant_dinein_reports.d.ts +326 -0
  61. package/lib/schemas/types/materialized_tenant_dinein_reports.js +9 -0
  62. package/lib/tests/materialized-reports/dinein-fixtures.d.ts +29 -0
  63. package/lib/tests/materialized-reports/dinein-fixtures.js +130 -0
  64. package/lib/tests/materialized-reports/materialized-day-readiness.test.js +3 -2
  65. package/lib/tests/materialized-reports/materialized-dinein-compile.test.d.ts +1 -0
  66. package/lib/tests/materialized-reports/materialized-dinein-compile.test.js +807 -0
  67. package/lib/tests/materialized-reports/materialized-dinein-plan.test.d.ts +1 -0
  68. package/lib/tests/materialized-reports/materialized-dinein-plan.test.js +419 -0
  69. package/lib/tests/materialized-reports/materialized-tenant-dinein-schema.test.d.ts +1 -0
  70. package/lib/tests/materialized-reports/materialized-tenant-dinein-schema.test.js +185 -0
  71. package/lib/tests/materialized-reports/report-platform/registry-conformance.test.js +15 -2
  72. package/lib/tests/materialized-reports/tenant-dinein-formatter.test.d.ts +1 -0
  73. package/lib/tests/materialized-reports/tenant-dinein-formatter.test.js +299 -0
  74. package/package.json +1 -1
@@ -0,0 +1,231 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isMaterializedDineinEntryScope = isMaterializedDineinEntryScope;
4
+ exports.dineinEntryPageOf = dineinEntryPageOf;
5
+ exports.dineinEntryPageBase = dineinEntryPageBase;
6
+ exports.isDineinEntryPageForSourceDay = isDineinEntryPageForSourceDay;
7
+ exports.materializedDineinEntrySubPage = materializedDineinEntrySubPage;
8
+ exports.materializedDineinEntryPageKey = materializedDineinEntryPageKey;
9
+ exports.splitMaterializedDineinEntryPage = splitMaterializedDineinEntryPage;
10
+ exports.mergeMaterializedDineinEntryPages = mergeMaterializedDineinEntryPages;
11
+ exports.buildMaterializedDineinEntryPageRefs = buildMaterializedDineinEntryPageRefs;
12
+ exports.dineinMonthScopeFieldsOfDays = dineinMonthScopeFieldsOfDays;
13
+ exports.buildMaterializedDineinDetailsScopeGroups = buildMaterializedDineinDetailsScopeGroups;
14
+ const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
15
+ const materialized_document_size_1 = require("./materialized-document-size");
16
+ const scope_helpers_1 = require("./scope-helpers");
17
+ /**
18
+ * Dinein ENTRY PAGES — the page identity of
19
+ * `materialized_tenant_dinein_entries`.
20
+ *
21
+ * ## One page per source day
22
+ *
23
+ * | scope | page |
24
+ * | --- | --- |
25
+ * | `localDate` | `'all'` (the scope is already one day) |
26
+ * | `localWeek` | `<source localDate>` |
27
+ * | `localWeekOfYear` | `<source localDate>` |
28
+ * | `localMonth` | `<source localDate>` |
29
+ *
30
+ * There is NO quarter / semester / year entry document. A month is covered by
31
+ * its 28-31 pages, and a broad details selection is served from the month pages
32
+ * it touches (`buildMaterializedDineinDetailsScopeGroups`).
33
+ *
34
+ * ## Deterministic `#N` sub-pages, only when needed
35
+ *
36
+ * An oversized page splits into `page#0`, `page#1`, … . A page that fits keeps
37
+ * its ORIGINAL identity (no suffix), so existing pages are untouched until they
38
+ * actually grow. The sub-pages are disjoint — every check appears exactly once —
39
+ * and the reader unions them.
40
+ */
41
+ const SUB_PAGE_PATTERN = /^(.*)#(\d+)$/;
42
+ /** True when a scope context carries entry pages (day + the three period scopes). */
43
+ function isMaterializedDineinEntryScope(scope) {
44
+ return MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_ENTRY_SCOPES.includes(String(scope));
45
+ }
46
+ /** The `page` value a compiled entry document of `scopeContext` must carry. */
47
+ function dineinEntryPageOf(scopeContext, localDate) {
48
+ const scope = String(scopeContext);
49
+ if (!isMaterializedDineinEntryScope(scope))
50
+ return null;
51
+ if (scope === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE) {
52
+ return MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_ENTRY_PAGE_ALL;
53
+ }
54
+ if (typeof localDate !== 'string' || localDate === '')
55
+ return null;
56
+ return localDate;
57
+ }
58
+ /** The unsuffixed source-day page (`all` / `YYYY-MM-DD`). */
59
+ function dineinEntryPageBase(page) {
60
+ const text = String(page ?? '');
61
+ const match = SUB_PAGE_PATTERN.exec(text);
62
+ return match == null ? text : match[1];
63
+ }
64
+ /** True when a stored page belongs to the source day (`all` / `YYYY-MM-DD` + `#N`). */
65
+ function isDineinEntryPageForSourceDay(scopeContext, page, localDate) {
66
+ const base = dineinEntryPageOf(scopeContext, localDate);
67
+ if (base == null)
68
+ return false;
69
+ return dineinEntryPageBase(page) === base;
70
+ }
71
+ /** The deterministic identity of one chunk. */
72
+ function materializedDineinEntrySubPage(basePage, index) {
73
+ return `${basePage}#${Math.max(0, Math.floor(index))}`;
74
+ }
75
+ /** Stable identity string of one entry page (tests / diagnostics / map keys). */
76
+ function materializedDineinEntryPageKey(ref) {
77
+ return `${String(ref?.scope_context)}|${String(ref?.scope_field)}|${String(ref?.page)}`;
78
+ }
79
+ const countRows = (sections) => {
80
+ let rows = 0;
81
+ for (const section of Object.values(sections ?? {}))
82
+ rows += section?.rows?.length ?? 0;
83
+ return rows;
84
+ };
85
+ /**
86
+ * Splits ONE source-day entry page when it exceeds the budget.
87
+ *
88
+ * Rows are walked in their stored (deterministic) key/row order and packed until
89
+ * the next row would cross the budget. A page that fits keeps its original
90
+ * identity. Throws when a single row cannot fit, because silently dropping a
91
+ * check would understate the statement.
92
+ */
93
+ function splitMaterializedDineinEntryPage(doc, maxBytes = MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_ENTRY_MAX_BSON_BYTES) {
94
+ if (doc == null)
95
+ return [];
96
+ if ((0, materialized_document_size_1.materializedDocumentBsonBytes)(doc) <= maxBytes)
97
+ return [doc];
98
+ const sections = doc.dinein_entries ?? null;
99
+ if (sections == null || countRows(sections) === 0)
100
+ return [doc];
101
+ const basePage = dineinEntryPageBase(doc.page);
102
+ const envelope = { ...doc, page: basePage, dinein_entries: {} };
103
+ const envelopeBytes = (0, materialized_document_size_1.materializedDocumentBsonBytes)(envelope);
104
+ const chunks = [];
105
+ let current = {};
106
+ let currentBytes = envelopeBytes;
107
+ let currentRows = 0;
108
+ const flush = () => {
109
+ if (currentRows > 0)
110
+ chunks.push(current);
111
+ current = {};
112
+ currentBytes = envelopeBytes;
113
+ currentRows = 0;
114
+ };
115
+ for (const key of Object.keys(sections)) {
116
+ for (const row of sections[key]?.rows ?? []) {
117
+ const rowBytes = (0, materialized_document_size_1.materializedDocumentBsonBytes)(row) + key.length + 24;
118
+ if (currentRows > 0 && currentBytes + rowBytes > maxBytes - 512)
119
+ flush();
120
+ if (current[key] == null)
121
+ current[key] = { rows: [] };
122
+ current[key].rows.push(row);
123
+ currentBytes += rowBytes;
124
+ currentRows += 1;
125
+ if (currentBytes > maxBytes) {
126
+ throw new Error(`Dinein entry page ${String(doc.scope_context)}:${String(doc.scope_field)}:${basePage} ` +
127
+ 'cannot split below the budget (one row is too large)');
128
+ }
129
+ }
130
+ }
131
+ flush();
132
+ return chunks.map((chunk, index) => {
133
+ const page = {
134
+ ...doc,
135
+ page: materializedDineinEntrySubPage(basePage, index),
136
+ dinein_entries: chunk,
137
+ };
138
+ if ((0, materialized_document_size_1.materializedDocumentBsonBytes)(page) > maxBytes) {
139
+ throw new Error(`Dinein entry sub-page ${String(doc.scope_context)}:${String(doc.scope_field)}:${page.page} ` +
140
+ 'exceeds the entry-page budget');
141
+ }
142
+ return page;
143
+ });
144
+ }
145
+ /**
146
+ * Unions all pages of ONE source day (the base page or its `#N` sub-pages) into
147
+ * one logical document. Rows are disjoint by construction; the `order_id`
148
+ * dedupe makes a duplicated page harmless instead of doubling a check.
149
+ */
150
+ function mergeMaterializedDineinEntryPages(pages, identity) {
151
+ const list = (pages ?? []).filter((page) => page != null);
152
+ if (list.length === 0)
153
+ return null;
154
+ const sections = {};
155
+ const seen = new Set();
156
+ for (const page of list) {
157
+ for (const [key, section] of Object.entries(page.dinein_entries ?? {})) {
158
+ for (const row of section?.rows ?? []) {
159
+ const rowIdentity = String(row.order_id ?? '');
160
+ if (rowIdentity !== '') {
161
+ if (seen.has(rowIdentity))
162
+ continue;
163
+ seen.add(rowIdentity);
164
+ }
165
+ if (sections[key] == null)
166
+ sections[key] = { rows: [] };
167
+ sections[key].rows.push(row);
168
+ }
169
+ }
170
+ }
171
+ const first = list[0];
172
+ return {
173
+ ...first,
174
+ ...(identity ?? {}),
175
+ dinein_entries: Object.keys(sections).length === 0 ? null : sections,
176
+ };
177
+ }
178
+ /**
179
+ * The BASE page refs belonging to ONE source day. The close reader expands each
180
+ * ref to the base plus any deterministic `#N` sub-pages; no other day's page is
181
+ * ever fetched.
182
+ *
183
+ * Returns `null` for a malformed date.
184
+ */
185
+ function buildMaterializedDineinEntryPageRefs(localDate) {
186
+ const fields = (0, scope_helpers_1.getMaterializedPeriodScopeFields)(localDate);
187
+ if (fields == null)
188
+ return null;
189
+ const refs = [];
190
+ for (const scope of MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_ENTRY_SCOPES) {
191
+ const scopeField = fields[String(scope)];
192
+ const page = dineinEntryPageOf(scope, localDate);
193
+ if (typeof scopeField !== 'string' || scopeField === '' || page == null)
194
+ return null;
195
+ refs.push({ scope_context: scope, scope_field: scopeField, page });
196
+ }
197
+ return refs;
198
+ }
199
+ /** The distinct `YYYY-MM` scope values of a day set, ascending. */
200
+ function dineinMonthScopeFieldsOfDays(days) {
201
+ const months = new Set();
202
+ for (const day of days ?? []) {
203
+ const match = /^(\d{4})-(\d{2})-\d{2}$/.exec(String(day));
204
+ if (match == null)
205
+ continue;
206
+ months.add(`${match[1]}-${match[2]}`);
207
+ }
208
+ return [...months].sort();
209
+ }
210
+ /**
211
+ * Resolves the EXACT selected days into the scope groups a DINEIN DETAILS read
212
+ * uses:
213
+ *
214
+ * - one day → the `localDate` page (`page='all'`) — the direct path;
215
+ * - many days → the `localMonth` groups that contain them. The reader scans the
216
+ * pages of those months and filters rows to the EXACT days via
217
+ * `source_local_date`, so a quarter / semester / year / custom multi-month
218
+ * range is served, never refused.
219
+ */
220
+ function buildMaterializedDineinDetailsScopeGroups(days) {
221
+ const unique = [...new Set((days ?? []).map((day) => String(day)))].sort();
222
+ if (unique.length === 0)
223
+ return null;
224
+ if (unique.length === 1) {
225
+ return [{ scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE, scope_field: [unique[0]] }];
226
+ }
227
+ const months = dineinMonthScopeFieldsOfDays(unique);
228
+ if (months.length === 0)
229
+ return null;
230
+ return [{ scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_MONTH, scope_field: months }];
231
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Key helpers for the dinein report.
3
+ *
4
+ * The key grammar is `<ORDER_STATUS>:<PLATFORM>` — the two dimensions every
5
+ * order-shaped materialized counter document declares (the same grammar as the
6
+ * sales overview and the discounts report). A component the source does not
7
+ * carry is encoded as `UNKNOWN`, never omitted, so a check without a platform
8
+ * still shows up in the totals.
9
+ */
10
+ /** The key-component filters a dinein read may carry. */
11
+ export interface IDineinKeyFilters {
12
+ /** Selected order statuses (key components). */
13
+ order_statuses?: string[] | null;
14
+ /** Selected platforms (key components). */
15
+ platforms?: string[] | null;
16
+ }
17
+ /** Normalizes one key component: blank/missing -> `UNKNOWN`, `:` -> `-`. */
18
+ export declare function normalizeMaterializedDineinDimension(value: unknown): string;
19
+ /** Builds `<ORDER_STATUS>:<PLATFORM>`. */
20
+ export declare function buildMaterializedDineinKey(orderStatus: unknown, platform: unknown): string;
21
+ /** Splits a key back into its components, or null when it is malformed. */
22
+ export declare function parseMaterializedDineinKey(key: unknown): {
23
+ order_status: string;
24
+ platform: string;
25
+ } | null;
26
+ /**
27
+ * Whether one compiled KEY passes the request filters.
28
+ *
29
+ * Only whole key components are compared, so this is exactly the predicate the
30
+ * historical aggregation applies. `UNKNOWN` means "the source carried no
31
+ * value", never "everything the filter excluded".
32
+ */
33
+ export declare function dineinKeyPassesFilters(key: unknown, filters?: IDineinKeyFilters | null): boolean;
34
+ /** True when the filter object selects no key component. */
35
+ export declare function isDineinKeyFilterEmpty(filters?: IDineinKeyFilters | null): boolean;
36
+ /**
37
+ * The Mongo key regex for the `<ORDER_STATUS>:<PLATFORM>` grammar.
38
+ *
39
+ * Used by the historical aggregation so a filtered read never sums excluded
40
+ * keys. Returns null when the filters select nothing (no regex constraint).
41
+ */
42
+ export declare function buildDineinKeyFilterRegex(filters?: IDineinKeyFilters | null): RegExp | null;
43
+ /** Restricts a counter map to the keys the filters accept. */
44
+ export declare function filterMaterializedDineinCounters<T>(counters: Record<string, T> | null | undefined, filters?: IDineinKeyFilters | null): Record<string, T>;
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeMaterializedDineinDimension = normalizeMaterializedDineinDimension;
4
+ exports.buildMaterializedDineinKey = buildMaterializedDineinKey;
5
+ exports.parseMaterializedDineinKey = parseMaterializedDineinKey;
6
+ exports.dineinKeyPassesFilters = dineinKeyPassesFilters;
7
+ exports.isDineinKeyFilterEmpty = isDineinKeyFilterEmpty;
8
+ exports.buildDineinKeyFilterRegex = buildDineinKeyFilterRegex;
9
+ exports.filterMaterializedDineinCounters = filterMaterializedDineinCounters;
10
+ const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
11
+ /** Normalizes one key component: blank/missing -> `UNKNOWN`, `:` -> `-`. */
12
+ function normalizeMaterializedDineinDimension(value) {
13
+ if (value == null)
14
+ return MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_UNKNOWN_TOKEN;
15
+ const text = String(value).trim();
16
+ if (text === '')
17
+ return MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_UNKNOWN_TOKEN;
18
+ // The separator must never appear inside a component, or the key is ambiguous.
19
+ return text.split(MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_KEY_SEPARATOR).join('-');
20
+ }
21
+ /** Builds `<ORDER_STATUS>:<PLATFORM>`. */
22
+ function buildMaterializedDineinKey(orderStatus, platform) {
23
+ return (normalizeMaterializedDineinDimension(orderStatus) +
24
+ MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_KEY_SEPARATOR +
25
+ normalizeMaterializedDineinDimension(platform));
26
+ }
27
+ /** Splits a key back into its components, or null when it is malformed. */
28
+ function parseMaterializedDineinKey(key) {
29
+ if (key == null)
30
+ return null;
31
+ const parts = String(key).split(MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_KEY_SEPARATOR);
32
+ if (parts.length !== 2)
33
+ return null;
34
+ const [order_status, platform] = parts;
35
+ if (order_status === '' || platform === '')
36
+ return null;
37
+ return { order_status, platform };
38
+ }
39
+ /**
40
+ * Whether one compiled KEY passes the request filters.
41
+ *
42
+ * Only whole key components are compared, so this is exactly the predicate the
43
+ * historical aggregation applies. `UNKNOWN` means "the source carried no
44
+ * value", never "everything the filter excluded".
45
+ */
46
+ function dineinKeyPassesFilters(key, filters) {
47
+ if (filters == null)
48
+ return true;
49
+ const parsed = parseMaterializedDineinKey(key);
50
+ if (parsed == null)
51
+ return false;
52
+ const orderStatuses = (filters.order_statuses ?? []).map((value) => String(value));
53
+ if (orderStatuses.length > 0 && !orderStatuses.includes(parsed.order_status))
54
+ return false;
55
+ const platforms = (filters.platforms ?? []).map((value) => String(value));
56
+ if (platforms.length > 0 && !platforms.includes(parsed.platform))
57
+ return false;
58
+ return true;
59
+ }
60
+ const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
61
+ /** True when the filter object selects no key component. */
62
+ function isDineinKeyFilterEmpty(filters) {
63
+ if (filters == null)
64
+ return true;
65
+ const orderStatuses = filters.order_statuses ?? [];
66
+ const platforms = filters.platforms ?? [];
67
+ return orderStatuses.length === 0 && platforms.length === 0;
68
+ }
69
+ /**
70
+ * The Mongo key regex for the `<ORDER_STATUS>:<PLATFORM>` grammar.
71
+ *
72
+ * Used by the historical aggregation so a filtered read never sums excluded
73
+ * keys. Returns null when the filters select nothing (no regex constraint).
74
+ */
75
+ function buildDineinKeyFilterRegex(filters) {
76
+ if (isDineinKeyFilterEmpty(filters))
77
+ return null;
78
+ const component = (values) => {
79
+ if (values == null || values.length === 0)
80
+ return '[^:]+';
81
+ return '(?:' + values.map((value) => escapeRegExp(String(value))).join('|') + ')';
82
+ };
83
+ return new RegExp('^' + component(filters?.order_statuses) + ':' + component(filters?.platforms) + '$');
84
+ }
85
+ /** Restricts a counter map to the keys the filters accept. */
86
+ function filterMaterializedDineinCounters(counters, filters) {
87
+ const source = counters ?? {};
88
+ if (filters == null)
89
+ return source;
90
+ const filtered = {};
91
+ for (const [key, block] of Object.entries(source)) {
92
+ if (dineinKeyPassesFilters(key, filters))
93
+ filtered[key] = block;
94
+ }
95
+ return filtered;
96
+ }
@@ -13,6 +13,8 @@ const MATERIALIZED_REPORTS_2 = require("../../constants/MATERIALIZED_REPORTS");
13
13
  const materialized_tenant_day_readiness_1 = require("../../schemas/models/materialized_tenant_day_readiness");
14
14
  const materialized_tenant_dialer_entries_1 = require("../../schemas/models/materialized_tenant_dialer_entries");
15
15
  const materialized_tenant_dialer_reports_1 = require("../../schemas/models/materialized_tenant_dialer_reports");
16
+ const materialized_tenant_dinein_entries_1 = require("../../schemas/models/materialized_tenant_dinein_entries");
17
+ const materialized_tenant_dinein_reports_1 = require("../../schemas/models/materialized_tenant_dinein_reports");
16
18
  const materialized_tenant_discount_entries_1 = require("../../schemas/models/materialized_tenant_discount_entries");
17
19
  const materialized_tenant_discount_reports_1 = require("../../schemas/models/materialized_tenant_discount_reports");
18
20
  const materialized_tenant_discount_sources_1 = require("../../schemas/models/materialized_tenant_discount_sources");
@@ -53,6 +55,8 @@ const INDEXES = {
53
55
  [MATERIALIZED_REPORTS_2.MATERIALIZED_TENANT_DAY_READINESS_COLLECTION_NAME]: materialized_tenant_day_readiness_1.MATERIALIZED_TENANT_DAY_READINESS_INDEX_OPTIONS,
54
56
  [materialized_tenant_dialer_reports_1.MATERIALIZED_TENANT_DIALER_REPORTS_COLLECTION_NAME]: materialized_tenant_dialer_reports_1.MATERIALIZED_TENANT_DIALER_REPORTS_INDEX_OPTIONS,
55
57
  [materialized_tenant_dialer_entries_1.MATERIALIZED_TENANT_DIALER_ENTRIES_COLLECTION_NAME]: materialized_tenant_dialer_entries_1.MATERIALIZED_TENANT_DIALER_ENTRIES_INDEX_OPTIONS,
58
+ [materialized_tenant_dinein_reports_1.MATERIALIZED_TENANT_DINEIN_REPORTS_COLLECTION_NAME]: materialized_tenant_dinein_reports_1.MATERIALIZED_TENANT_DINEIN_REPORTS_INDEX_OPTIONS,
59
+ [materialized_tenant_dinein_entries_1.MATERIALIZED_TENANT_DINEIN_ENTRIES_COLLECTION_NAME]: materialized_tenant_dinein_entries_1.MATERIALIZED_TENANT_DINEIN_ENTRIES_INDEX_OPTIONS,
56
60
  [materialized_report_drilldown_rows_1.MATERIALIZED_REPORT_DRILLDOWN_ROWS_COLLECTION_NAME]: materialized_report_drilldown_rows_1.MATERIALIZED_REPORT_DRILLDOWN_ROWS_INDEX_OPTIONS,
57
61
  [materialized_report_drilldown_rows_1.MATERIALIZED_REPORT_DRILLDOWN_SCOPES_COLLECTION_NAME]: materialized_report_drilldown_rows_1.MATERIALIZED_REPORT_DRILLDOWN_SCOPES_INDEX_OPTIONS,
58
62
  [tenant_calendar_1.TENANT_CALENDAR_COLLECTION_NAME]: tenant_calendar_1.TENANT_CALENDAR_INDEX_OPTIONS,
@@ -74,6 +74,14 @@ const ROW_SPECS = {
74
74
  orderId: () => '',
75
75
  cursorId: (row) => row.event_id,
76
76
  },
77
+ [MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DINEIN_ENTRIES]: {
78
+ rowsKey: 'dinein_entries',
79
+ // `time` is an ISO string on the check row; `toDate` accepts both.
80
+ time: (row) => row.time,
81
+ orderId: (row) => row.order_id,
82
+ // One row per collectable check, so the order itself is the row identity.
83
+ cursorId: (row) => row.order_id,
84
+ },
77
85
  };
78
86
  /** The nested map key an entry collection uses for its row sections. */
79
87
  const getDrilldownRowsKey = (reportType) => ROW_SPECS[reportType].rowsKey;
@@ -522,12 +522,103 @@ const DIALER_DEFINITION = {
522
522
  'Writes a COMMITTED materialized_tenant_day_readiness row in the SAME transaction.',
523
523
  ],
524
524
  };
525
+ const DINEIN_DEFINITION = {
526
+ key: report_contract_1.REPORT_KEY_ENUM.DINEIN,
527
+ segment: 'dinein',
528
+ reportType: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DINEIN_REPORTS,
529
+ capabilities: { live: true, historical: true, details: true },
530
+ status: REPORT_DEFINITION_STATUS.PRODUCTION,
531
+ report: {
532
+ name: 'materialized_tenant_dinein_reports',
533
+ schemaVersion: 1,
534
+ budgetBytes: MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_REPORT_MAX_BSON_BYTES,
535
+ enforced: true,
536
+ validatorFile: null,
537
+ validatorDebt: 'No schema validator exists for the dinein report collection yet.',
538
+ indexOwner: 'toolkit:MATERIALIZED_TENANT_DINEIN_REPORTS_INDEX_OPTIONS',
539
+ migrationId: null,
540
+ },
541
+ entries: {
542
+ name: 'materialized_tenant_dinein_entries',
543
+ schemaVersion: 1,
544
+ budgetBytes: MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_ENTRY_MAX_BSON_BYTES,
545
+ enforced: true,
546
+ validatorFile: null,
547
+ validatorDebt: 'No schema validator exists for the dinein entry collection yet.',
548
+ indexOwner: 'toolkit:MATERIALIZED_TENANT_DINEIN_ENTRIES_INDEX_OPTIONS',
549
+ migrationId: null,
550
+ },
551
+ sideCollections: [FLAT_ROWS, FLAT_SCOPES],
552
+ reportScopes: [...MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_REPORT_SCOPES],
553
+ entryScopes: [...MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_ENTRY_SCOPES],
554
+ entryStorage: REPORT_ENTRY_STORAGE.PAGE_PER_SOURCE_DAY,
555
+ entrySplit: REPORT_ENTRY_SPLIT.DETERMINISTIC_SUBPAGES,
556
+ maxReportScope: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_YEAR,
557
+ maxEntryScope: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_MONTH,
558
+ projections: [REPORT_PROJECTION.FLAT_DRILLDOWN],
559
+ budgets: {
560
+ materialized_tenant_dinein_reports: MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_REPORT_MAX_BSON_BYTES,
561
+ materialized_tenant_dinein_entries: MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_ENTRY_MAX_BSON_BYTES,
562
+ materialized_report_drilldown_rows: DOCUMENT_BUDGET,
563
+ materialized_report_drilldown_scopes: DOCUMENT_BUDGET,
564
+ },
565
+ retention: [],
566
+ writeGuard: REPORT_WRITE_GUARD.WATERMARK,
567
+ liveSource: REPORT_LIVE_SOURCE.RAW,
568
+ historicalLens: REPORT_HISTORICAL_LENS.COUNTER_ROWS,
569
+ completeness: { summary: 'NONE', details: 'FLAT_PROJECTION' },
570
+ filters: [
571
+ {
572
+ id: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_KEY_FILTER_ENUM.ORDER_STATUS,
573
+ kind: 'KEY_COMPONENT',
574
+ mode: 'SERVER',
575
+ appliesTo: 'BOTH',
576
+ },
577
+ {
578
+ id: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_KEY_FILTER_ENUM.PLATFORM,
579
+ kind: 'KEY_COMPONENT',
580
+ mode: 'SERVER',
581
+ appliesTo: 'BOTH',
582
+ },
583
+ // Origin / table / floor / split / offline are ROW filters: the SUMMARY
584
+ // cannot answer them exactly (the counters are keyed only by
585
+ // ORDER_STATUS:PLATFORM), so a summary request that sends one is REJECTED
586
+ // with 400 INVALID_REQUEST + details.unsupported_filters - never silently
587
+ // answered unfiltered.
588
+ { id: 'origins', kind: 'ROW', mode: 'SERVER', appliesTo: 'DETAILS' },
589
+ { id: 'table_ids', kind: 'ROW', mode: 'SERVER', appliesTo: 'DETAILS' },
590
+ { id: 'floor_ids', kind: 'ROW', mode: 'SERVER', appliesTo: 'DETAILS' },
591
+ { id: 'split_types', kind: 'ROW', mode: 'SERVER', appliesTo: 'DETAILS' },
592
+ { id: 'offline', kind: 'ROW', mode: 'SERVER', appliesTo: 'DETAILS' },
593
+ { id: 'DETAILS_VIEW', kind: 'REQUEST', mode: 'SERVER', appliesTo: 'DETAILS' },
594
+ ],
595
+ cursor: REPORT_CURSOR_KIND.KEYSET_STRUCTURED,
596
+ adapters: {
597
+ writer: 'materializeDineinReport',
598
+ live: 'getLiveTenantDineinReports',
599
+ historical: 'getMaterializedTenantDineinReports',
600
+ details: 'getMaterializedDineinDetailsPage',
601
+ },
602
+ owner: 'reporting-platform',
603
+ notes: [
604
+ 'Source day is order.localDate; a fingerprint never moves a check to the day its table closed.',
605
+ 'Deleted split parents are excluded from sales/order counts and read only for rating discovery.',
606
+ 'Covers come from the table-close fingerprint of the check, never from num_of_guests.',
607
+ 'Sales = amount_earned, which already includes the service charge; the charge is a component.',
608
+ 'Courses are current-state counts only: the order stores no call history or call timestamp.',
609
+ 'Reservations are a document-level block with no order link and no seated/no-show state.',
610
+ 'Origin / table / floor / split / offline are DETAILS row filters; the summary rejects them.',
611
+ 'Page entries split deterministically into #N sub-pages; no quarter/semester/year entry scope.',
612
+ 'Writes a COMMITTED materialized_tenant_day_readiness row in the SAME transaction.',
613
+ ],
614
+ };
525
615
  exports.REPORT_DEFINITIONS = {
526
616
  [OVERVIEW_DEFINITION.key]: OVERVIEW_DEFINITION,
527
617
  [DISCOUNTS_DEFINITION.key]: DISCOUNTS_DEFINITION,
528
618
  [PREP_TIME_DEFINITION.key]: PREP_TIME_DEFINITION,
529
619
  [DELIVERY_DEFINITION.key]: DELIVERY_DEFINITION,
530
620
  [DIALER_DEFINITION.key]: DIALER_DEFINITION,
621
+ [DINEIN_DEFINITION.key]: DINEIN_DEFINITION,
531
622
  };
532
623
  exports.PRODUCTION_REPORT_DEFINITIONS = [
533
624
  OVERVIEW_DEFINITION,
@@ -535,6 +626,7 @@ exports.PRODUCTION_REPORT_DEFINITIONS = [
535
626
  PREP_TIME_DEFINITION,
536
627
  DELIVERY_DEFINITION,
537
628
  DIALER_DEFINITION,
629
+ DINEIN_DEFINITION,
538
630
  ];
539
631
  exports.REPORT_REGISTRY_EXEMPTIONS = {
540
632
  [report_contract_1.REPORT_KEY_ENUM.CASH_IN_OUT]: {