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