@managesome/eposmatic-toolkit 0.4.61 → 0.4.63
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.
- package/esm/constants/MATERIALIZED_REPORTS.js +77 -0
- package/esm/constants/MATERIALIZED_SCHEMA_VERSIONS.js +17 -0
- package/esm/constants/TENANT_ENUMS.js +15 -0
- package/esm/constants/WORKER_ENDPOINTS.js +14 -2
- package/esm/helpers/materialized-reports/index.js +4 -0
- package/esm/helpers/materialized-reports/materialized-credit-bills-helpers.js +3 -3
- package/esm/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +5 -5
- package/esm/helpers/materialized-reports/materialized-delivery-compile-helpers.js +2 -2
- package/esm/helpers/materialized-reports/materialized-dialer-close-day-helpers.js +5 -5
- package/esm/helpers/materialized-reports/materialized-dialer-compile-helpers.js +2 -2
- package/esm/helpers/materialized-reports/materialized-dinein-close-day-helpers.js +5 -5
- package/esm/helpers/materialized-reports/materialized-dinein-compile-helpers.js +2 -2
- package/esm/helpers/materialized-reports/materialized-discount-compile-helpers.js +3 -3
- package/esm/helpers/materialized-reports/materialized-document-size.js +2 -2
- package/esm/helpers/materialized-reports/materialized-index-bootstrap.js +3 -1
- package/esm/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +3 -3
- package/esm/helpers/materialized-reports/materialized-prep-time-compile-helpers.js +3 -3
- package/esm/helpers/materialized-reports/materialized-report-runs.js +143 -0
- package/esm/helpers/materialized-reports/report-compile.js +38 -0
- package/esm/helpers/materialized-reports/tenant-sales-overview-bson.js +27 -0
- package/esm/helpers/materialized-reports/tenant-sales-overview-helpers.js +3 -22
- package/esm/schemas/models/index.js +1 -0
- package/esm/schemas/models/materialized_credit_bills.js +2 -1
- package/esm/schemas/models/materialized_tenant_delivery_entries.js +2 -1
- package/esm/schemas/models/materialized_tenant_delivery_reports.js +2 -1
- package/esm/schemas/models/materialized_tenant_dialer_entries.js +2 -1
- package/esm/schemas/models/materialized_tenant_dialer_reports.js +2 -1
- package/esm/schemas/models/materialized_tenant_dinein_entries.js +2 -1
- package/esm/schemas/models/materialized_tenant_dinein_reports.js +2 -1
- package/esm/schemas/models/materialized_tenant_report_runs.js +105 -0
- package/esm/schemas/models/materialized_tenant_sales_overview_reports.js +2 -1
- package/esm/schemas/models/tenant_active_jobs.js +19 -1
- package/esm/schemas/types/index.js +1 -0
- package/lib/constants/MATERIALIZED_REPORTS.d.ts +69 -0
- package/lib/constants/MATERIALIZED_REPORTS.js +78 -1
- package/lib/constants/MATERIALIZED_SCHEMA_VERSIONS.d.ts +17 -0
- package/lib/constants/MATERIALIZED_SCHEMA_VERSIONS.js +20 -0
- package/lib/constants/TENANT_ENUMS.d.ts +14 -0
- package/lib/constants/TENANT_ENUMS.js +16 -1
- package/lib/constants/WORKER_ENDPOINTS.d.ts +12 -2
- package/lib/constants/WORKER_ENDPOINTS.js +14 -2
- package/lib/helpers/materialized-reports/index.d.ts +3 -0
- package/lib/helpers/materialized-reports/index.js +27 -0
- package/lib/helpers/materialized-reports/materialized-credit-bills-helpers.js +4 -4
- package/lib/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +6 -6
- package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.js +4 -4
- package/lib/helpers/materialized-reports/materialized-dialer-close-day-helpers.js +6 -6
- package/lib/helpers/materialized-reports/materialized-dialer-compile-helpers.js +6 -6
- package/lib/helpers/materialized-reports/materialized-dinein-close-day-helpers.js +6 -6
- package/lib/helpers/materialized-reports/materialized-dinein-compile-helpers.js +6 -6
- package/lib/helpers/materialized-reports/materialized-discount-compile-helpers.js +3 -3
- package/lib/helpers/materialized-reports/materialized-document-size.js +2 -5
- package/lib/helpers/materialized-reports/materialized-index-bootstrap.js +2 -0
- package/lib/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +3 -3
- package/lib/helpers/materialized-reports/materialized-prep-time-compile-helpers.js +3 -3
- package/lib/helpers/materialized-reports/materialized-report-runs.d.ts +105 -0
- package/lib/helpers/materialized-reports/materialized-report-runs.js +156 -0
- package/lib/helpers/materialized-reports/report-compile.d.ts +38 -0
- package/lib/helpers/materialized-reports/report-compile.js +87 -0
- package/lib/helpers/materialized-reports/tenant-sales-overview-bson.d.ts +12 -0
- package/lib/helpers/materialized-reports/tenant-sales-overview-bson.js +33 -0
- package/lib/helpers/materialized-reports/tenant-sales-overview-helpers.d.ts +1 -12
- package/lib/helpers/materialized-reports/tenant-sales-overview-helpers.js +4 -24
- package/lib/helpers/types/workers.d.ts +65 -0
- package/lib/schemas/models/index.d.ts +1 -0
- package/lib/schemas/models/index.js +1 -0
- package/lib/schemas/models/materialized_credit_bills.d.ts +29 -46
- package/lib/schemas/models/materialized_credit_bills.js +3 -2
- package/lib/schemas/models/materialized_tenant_cash_entries.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_cash_reports.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_delivery_entries.d.ts +11 -10
- package/lib/schemas/models/materialized_tenant_delivery_entries.js +3 -2
- package/lib/schemas/models/materialized_tenant_delivery_geo_cells.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_delivery_geo_scopes.d.ts +6 -6
- package/lib/schemas/models/materialized_tenant_delivery_reports.d.ts +11 -10
- package/lib/schemas/models/materialized_tenant_delivery_reports.js +3 -2
- package/lib/schemas/models/materialized_tenant_dialer_entries.d.ts +8 -7
- package/lib/schemas/models/materialized_tenant_dialer_entries.js +3 -2
- package/lib/schemas/models/materialized_tenant_dialer_reports.d.ts +11 -10
- package/lib/schemas/models/materialized_tenant_dialer_reports.js +3 -2
- package/lib/schemas/models/materialized_tenant_dinein_entries.d.ts +8 -7
- package/lib/schemas/models/materialized_tenant_dinein_entries.js +3 -2
- package/lib/schemas/models/materialized_tenant_dinein_reports.d.ts +11 -10
- package/lib/schemas/models/materialized_tenant_dinein_reports.js +3 -2
- package/lib/schemas/models/materialized_tenant_discount_entries.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_discount_reports.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_discount_sources.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_hourly_comparison_entries.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_hourly_comparison_reports.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_payments_comparison_entries.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_payments_comparison_reports.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_prep_time_entries.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_prep_time_reports.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_report_runs.d.ts +97 -0
- package/lib/schemas/models/materialized_tenant_report_runs.js +108 -0
- package/lib/schemas/models/materialized_tenant_sales_comparison_entries.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_sales_comparison_reports.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_sales_overview_reports.d.ts +11 -35
- package/lib/schemas/models/materialized_tenant_sales_overview_reports.js +3 -2
- package/lib/schemas/models/tenant_active_jobs.d.ts +12 -3
- package/lib/schemas/models/tenant_active_jobs.js +18 -0
- package/lib/schemas/types/index.d.ts +1 -0
- package/lib/schemas/types/index.js +1 -0
- package/lib/schemas/types/materialized_tenant_report_runs.d.ts +55 -0
- package/lib/schemas/types/tenant_active_jobs.d.ts +15 -1
- package/lib/tests/materialized-reports/materialized-report-runs.test.js +116 -0
- package/lib/tests/materialized-reports/tenant-dinein-formatter.test.js +159 -0
- package/lib/tests/materialized-reports/tenant-sales-overview-close-day-helpers.test.js +2 -1
- package/lib/tests/materialized-reports/tenant-sales-overview-helpers.test.js +5 -4
- package/lib/tests/reporting-contract/no-live-transport.test.js +106 -0
- package/package.json +2 -1
- package/lib/helpers/order/payment-collection.d.ts +0 -25
- package/lib/helpers/order/payment-collection.js +0 -51
- package/lib/schemas/models/applied_order_discounts.d.ts +0 -80
- package/lib/schemas/models/applied_order_discounts.js +0 -106
- package/lib/schemas/types/applied_order_discounts.d.ts +0 -22
- package/lib/tests/payment-collection-timestamps.test.d.ts +0 -1
- package/lib/tests/payment-collection-timestamps.test.js +0 -71
- /package/{lib/tests/materialized-reports/analytics-growth-helpers.test.d.ts → esm/schemas/types/materialized_tenant_report_runs.js} +0 -0
- /package/lib/schemas/types/{applied_order_discounts.js → materialized_tenant_report_runs.js} +0 -0
- /package/lib/tests/materialized-reports/{analytics-overview-helpers.test.d.ts → materialized-report-runs.test.d.ts} +0 -0
- /package/lib/tests/{materialized-reports/analytics-performance-helpers.test.d.ts → reporting-contract/no-live-transport.test.d.ts} +0 -0
|
@@ -34,8 +34,8 @@ exports.WORKER_ENDPOINTS = {
|
|
|
34
34
|
REMOVE_DINEIN_TABLE: '/remove-dinein-table',
|
|
35
35
|
// ========================>> Modifiers / Catalog <<======================= //
|
|
36
36
|
UPDATE_MODIFIER_NAME_IN_ITEMS: '/update-modifier-name-in-items',
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
// The two catalog reads that used to live here (items-using-modifier and
|
|
38
|
+
// audit-item-modifiers) are OWNED by items-service now and run locally.
|
|
39
39
|
// ========================>> Payment (SwitchPay) <<======================= //
|
|
40
40
|
PROCESS_SWITCHPAY_PAYMENT_FOR_ORDER: '/process-switchpay-payment-for-order',
|
|
41
41
|
COMMIT_SWITCHPAY_PAYMENT_FOR_ORDER: '/commit-switchpay-payment-for-order',
|
|
@@ -80,4 +80,16 @@ exports.WORKER_ENDPOINTS = {
|
|
|
80
80
|
// ========================>> Shift / Business Day / Cash Drawer (compile) <<======================= //
|
|
81
81
|
END_INSTORE_SHIFT: '/end-instore-shift',
|
|
82
82
|
END_TENANT_DAY: '/end-tenant-day',
|
|
83
|
+
/**
|
|
84
|
+
* INTERNAL, report-scoped retry of ONE failed END_TENANT_DAY report.
|
|
85
|
+
* Operations-service is the only caller (POST /materialization/reports/retry).
|
|
86
|
+
* Never a whole-day retry.
|
|
87
|
+
*/
|
|
88
|
+
RETRY_MATERIALIZED_REPORT: '/internal/materialization/reports/retry',
|
|
89
|
+
/**
|
|
90
|
+
* INTERNAL, worker-owned recovery of INTERRUPTED report runs (RUNNING /
|
|
91
|
+
* RETRYING). Called before the retry API rejects a RUNNING report and before
|
|
92
|
+
* listing runs for the admin page. Never fabricates readiness.
|
|
93
|
+
*/
|
|
94
|
+
RECONCILE_MATERIALIZED_REPORT_RUNS: '/internal/materialization/reports/reconcile',
|
|
83
95
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './key-helpers';
|
|
2
2
|
export * from './materialized-credit-bills-helpers';
|
|
3
3
|
export * from './materialized-day-readiness';
|
|
4
|
+
export * from './materialized-report-runs';
|
|
4
5
|
export * from './materialized-index-bootstrap';
|
|
5
6
|
export * from './materialized-integer-contract';
|
|
6
7
|
export * from './materialized-discount-accumulator-helpers';
|
|
@@ -68,4 +69,6 @@ export * from './tenant-dinein-formatter';
|
|
|
68
69
|
export * from './tenant-prep-time-formatter';
|
|
69
70
|
export * from './tenant-sales-overview-formatter';
|
|
70
71
|
export * from './tenant-sales-overview-helpers';
|
|
72
|
+
export * from './tenant-sales-overview-bson';
|
|
71
73
|
export * from './report-platform';
|
|
74
|
+
export * as reportCompile from './report-compile';
|
|
@@ -10,13 +10,37 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
13
18
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
19
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
20
|
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
16
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.reportCompile = void 0;
|
|
17
40
|
__exportStar(require("./key-helpers"), exports);
|
|
18
41
|
__exportStar(require("./materialized-credit-bills-helpers"), exports);
|
|
19
42
|
__exportStar(require("./materialized-day-readiness"), exports);
|
|
43
|
+
__exportStar(require("./materialized-report-runs"), exports);
|
|
20
44
|
__exportStar(require("./materialized-index-bootstrap"), exports);
|
|
21
45
|
__exportStar(require("./materialized-integer-contract"), exports);
|
|
22
46
|
__exportStar(require("./materialized-discount-accumulator-helpers"), exports);
|
|
@@ -84,4 +108,7 @@ __exportStar(require("./tenant-dinein-formatter"), exports);
|
|
|
84
108
|
__exportStar(require("./tenant-prep-time-formatter"), exports);
|
|
85
109
|
__exportStar(require("./tenant-sales-overview-formatter"), exports);
|
|
86
110
|
__exportStar(require("./tenant-sales-overview-helpers"), exports);
|
|
111
|
+
__exportStar(require("./tenant-sales-overview-bson"), exports);
|
|
87
112
|
__exportStar(require("./report-platform"), exports);
|
|
113
|
+
// Worker-only PURE compile surface (also importable via the deep lib path).
|
|
114
|
+
exports.reportCompile = __importStar(require("./report-compile"));
|
|
@@ -16,10 +16,10 @@ exports.getMaterializedCreditBillScopeRefsForIssue = getMaterializedCreditBillSc
|
|
|
16
16
|
exports.computeMaterializedCreditBillTotalsFromReports = computeMaterializedCreditBillTotalsFromReports;
|
|
17
17
|
exports.computeMaterializedCreditBillTotalsFromReportsByKey = computeMaterializedCreditBillTotalsFromReportsByKey;
|
|
18
18
|
exports.buildMaterializedCreditBillSelectionFromScopeGroups = buildMaterializedCreditBillSelectionFromScopeGroups;
|
|
19
|
-
const
|
|
19
|
+
const bson_objectid_1 = __importDefault(require("bson-objectid"));
|
|
20
20
|
const constants_1 = require("../../constants");
|
|
21
21
|
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
22
|
-
const
|
|
22
|
+
const MATERIALIZED_SCHEMA_VERSIONS_1 = require("../../constants/MATERIALIZED_SCHEMA_VERSIONS");
|
|
23
23
|
const time_helpers_1 = require("../utils/time-helpers");
|
|
24
24
|
const key_helpers_1 = require("./key-helpers");
|
|
25
25
|
const materialized_day_input_signature_1 = require("./materialized-day-input-signature");
|
|
@@ -543,7 +543,7 @@ function buildMaterializedCreditBillDayReports(input) {
|
|
|
543
543
|
return [];
|
|
544
544
|
const sourceWatermark = watermark ?? computedAt;
|
|
545
545
|
const makeDoc = (scopeContext, scopeField, sections) => ({
|
|
546
|
-
_id: new
|
|
546
|
+
_id: new bson_objectid_1.default().toHexString(),
|
|
547
547
|
tenant_id: tenantId,
|
|
548
548
|
brand_id: brandId,
|
|
549
549
|
scope_context: scopeContext,
|
|
@@ -555,7 +555,7 @@ function buildMaterializedCreditBillDayReports(input) {
|
|
|
555
555
|
sale_type_key_filters: [...MATERIALIZED_REPORTS_1.SALES_OVERVIEW_KEY_FILTERS],
|
|
556
556
|
credit_bills: sections,
|
|
557
557
|
iteration: 1,
|
|
558
|
-
schema_version:
|
|
558
|
+
schema_version: MATERIALIZED_SCHEMA_VERSIONS_1.MATERIALIZED_CREDIT_BILLS_SCHEMA_VERSION,
|
|
559
559
|
source_watermark: sourceWatermark,
|
|
560
560
|
source_input_signature: sourceInputSignature,
|
|
561
561
|
computed_at: computedAt,
|
|
@@ -9,9 +9,9 @@ exports.needsMaterializedDeliveryReportWrite = needsMaterializedDeliveryReportWr
|
|
|
9
9
|
exports.needsMaterializedDeliveryEntriesWrite = needsMaterializedDeliveryEntriesWrite;
|
|
10
10
|
exports.foldMaterializedDeliveryPeriodCounters = foldMaterializedDeliveryPeriodCounters;
|
|
11
11
|
exports.buildTenantDeliveryCloseDayPlan = buildTenantDeliveryCloseDayPlan;
|
|
12
|
-
const
|
|
12
|
+
const bson_objectid_1 = __importDefault(require("bson-objectid"));
|
|
13
13
|
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
14
|
-
const
|
|
14
|
+
const MATERIALIZED_SCHEMA_VERSIONS_1 = require("../../constants/MATERIALIZED_SCHEMA_VERSIONS");
|
|
15
15
|
const materialized_delivery_accumulator_helpers_1 = require("./materialized-delivery-accumulator-helpers");
|
|
16
16
|
const materialized_delivery_classification_helpers_1 = require("./materialized-delivery-classification-helpers");
|
|
17
17
|
const materialized_delivery_compile_helpers_1 = require("./materialized-delivery-compile-helpers");
|
|
@@ -166,7 +166,7 @@ function buildTenantDeliveryCloseDayPlan(input) {
|
|
|
166
166
|
const existing = storedReportsByScope.get(deliveryScopeKey(compiledDateDoc));
|
|
167
167
|
const next = {
|
|
168
168
|
...compiledDateDoc,
|
|
169
|
-
_id: existing?._id ?? new
|
|
169
|
+
_id: existing?._id ?? new bson_objectid_1.default().toHexString(),
|
|
170
170
|
iteration: Number(existing?.iteration ?? 0) + 1,
|
|
171
171
|
};
|
|
172
172
|
if (force || needsMaterializedDeliveryReportWrite(existing, next))
|
|
@@ -248,7 +248,7 @@ function buildTenantDeliveryCloseDayPlan(input) {
|
|
|
248
248
|
counterRows.push({ key, counters: folded[key] });
|
|
249
249
|
}
|
|
250
250
|
const report = {
|
|
251
|
-
_id: existing?._id ?? new
|
|
251
|
+
_id: existing?._id ?? new bson_objectid_1.default().toHexString(),
|
|
252
252
|
tenant_id: tenantId,
|
|
253
253
|
brand_id: existing?.brand_id ?? compiledDateDoc?.brand_id ?? '',
|
|
254
254
|
scope_context: scope,
|
|
@@ -263,7 +263,7 @@ function buildTenantDeliveryCloseDayPlan(input) {
|
|
|
263
263
|
iteration: existing?.iteration,
|
|
264
264
|
// A folded period is always a CURRENT-shape document. v1 data must be wiped and
|
|
265
265
|
// re-closed; it is never upgraded in place.
|
|
266
|
-
schema_version: compiledDateDoc?.schema_version ??
|
|
266
|
+
schema_version: compiledDateDoc?.schema_version ?? MATERIALIZED_SCHEMA_VERSIONS_1.MATERIALIZED_TENANT_DELIVERY_REPORTS_SCHEMA_VERSION,
|
|
267
267
|
// FROM THE DAYS THAT BELONG TO THIS PERIOD - never the stored watermark, and never
|
|
268
268
|
// an unrelated day from another period. Using every sibling day would rewrite a
|
|
269
269
|
// period whenever any other month moved.
|
|
@@ -287,7 +287,7 @@ function buildTenantDeliveryCloseDayPlan(input) {
|
|
|
287
287
|
const existing = storedEntriesByPage.get(key) ?? null;
|
|
288
288
|
const next = {
|
|
289
289
|
...compiled,
|
|
290
|
-
_id: existing?._id ?? new
|
|
290
|
+
_id: existing?._id ?? new bson_objectid_1.default().toHexString(),
|
|
291
291
|
iteration: Number(existing?.iteration ?? 0) + 1,
|
|
292
292
|
};
|
|
293
293
|
if (existing == null || force || needsMaterializedDeliveryEntriesWrite(existing, next)) {
|
|
@@ -9,8 +9,8 @@ exports.compileTenantDeliveryReports = compileTenantDeliveryReports;
|
|
|
9
9
|
const ENUMS_1 = require("../../constants/ENUMS");
|
|
10
10
|
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
11
11
|
const delivery_1 = require("../../constants/enums/delivery");
|
|
12
|
-
const
|
|
13
|
-
const
|
|
12
|
+
const MATERIALIZED_SCHEMA_VERSIONS_1 = require("../../constants/MATERIALIZED_SCHEMA_VERSIONS");
|
|
13
|
+
const MATERIALIZED_SCHEMA_VERSIONS_2 = require("../../constants/MATERIALIZED_SCHEMA_VERSIONS");
|
|
14
14
|
const materialized_delivery_accumulator_helpers_1 = require("./materialized-delivery-accumulator-helpers");
|
|
15
15
|
const materialized_delivery_classification_helpers_1 = require("./materialized-delivery-classification-helpers");
|
|
16
16
|
const materialized_delivery_entry_pages_1 = require("./materialized-delivery-entry-pages");
|
|
@@ -328,7 +328,7 @@ function compileTenantDeliveryReports(input) {
|
|
|
328
328
|
sale_type_key_filters: [...MATERIALIZED_REPORTS_1.DELIVERY_KEY_FILTERS],
|
|
329
329
|
delivery_counters: deliveryCounters,
|
|
330
330
|
delivery_counter_rows: deliveryCounterRows,
|
|
331
|
-
schema_version:
|
|
331
|
+
schema_version: MATERIALIZED_SCHEMA_VERSIONS_2.MATERIALIZED_TENANT_DELIVERY_REPORTS_SCHEMA_VERSION,
|
|
332
332
|
source_watermark: watermark,
|
|
333
333
|
computed_at: computedAt,
|
|
334
334
|
createdAt: computedAt,
|
|
@@ -359,7 +359,7 @@ function compileTenantDeliveryReports(input) {
|
|
|
359
359
|
sale_type_key_filters: [...MATERIALIZED_REPORTS_1.DELIVERY_KEY_FILTERS],
|
|
360
360
|
delivery_entries: entrySections,
|
|
361
361
|
off_app_order_count: offAppCount,
|
|
362
|
-
schema_version:
|
|
362
|
+
schema_version: MATERIALIZED_SCHEMA_VERSIONS_1.MATERIALIZED_TENANT_DELIVERY_ENTRIES_SCHEMA_VERSION,
|
|
363
363
|
source_watermark: watermark,
|
|
364
364
|
computed_at: computedAt,
|
|
365
365
|
createdAt: computedAt,
|
|
@@ -9,9 +9,9 @@ exports.needsMaterializedDialerReportWrite = needsMaterializedDialerReportWrite;
|
|
|
9
9
|
exports.needsMaterializedDialerEntriesWrite = needsMaterializedDialerEntriesWrite;
|
|
10
10
|
exports.foldMaterializedDialerPeriodCounters = foldMaterializedDialerPeriodCounters;
|
|
11
11
|
exports.buildTenantDialerCloseDayPlan = buildTenantDialerCloseDayPlan;
|
|
12
|
-
const
|
|
12
|
+
const bson_objectid_1 = __importDefault(require("bson-objectid"));
|
|
13
13
|
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
14
|
-
const
|
|
14
|
+
const MATERIALIZED_SCHEMA_VERSIONS_1 = require("../../constants/MATERIALIZED_SCHEMA_VERSIONS");
|
|
15
15
|
const materialized_dialer_accumulator_helpers_1 = require("./materialized-dialer-accumulator-helpers");
|
|
16
16
|
const materialized_dialer_entry_pages_1 = require("./materialized-dialer-entry-pages");
|
|
17
17
|
const materialized_document_size_1 = require("./materialized-document-size");
|
|
@@ -166,7 +166,7 @@ function buildTenantDialerCloseDayPlan(input) {
|
|
|
166
166
|
const existing = storedReportsByScope.get(dialerScopeKey(compiledDateDoc));
|
|
167
167
|
const next = {
|
|
168
168
|
...compiledDateDoc,
|
|
169
|
-
_id: existing?._id ?? new
|
|
169
|
+
_id: existing?._id ?? new bson_objectid_1.default().toHexString(),
|
|
170
170
|
iteration: Number(existing?.iteration ?? 0) + 1,
|
|
171
171
|
};
|
|
172
172
|
if (force || needsMaterializedDialerReportWrite(existing, next))
|
|
@@ -239,7 +239,7 @@ function buildTenantDialerCloseDayPlan(input) {
|
|
|
239
239
|
for (const key of keys)
|
|
240
240
|
counters[key] = folded[key];
|
|
241
241
|
const report = {
|
|
242
|
-
_id: existing?._id ?? new
|
|
242
|
+
_id: existing?._id ?? new bson_objectid_1.default().toHexString(),
|
|
243
243
|
tenant_id: tenantId,
|
|
244
244
|
brand_id: existing?.brand_id ?? compiledDateDoc?.brand_id ?? '',
|
|
245
245
|
scope_context: scope,
|
|
@@ -248,7 +248,7 @@ function buildTenantDialerCloseDayPlan(input) {
|
|
|
248
248
|
sale_type_key_filters: [...MATERIALIZED_REPORTS_1.DIALER_KEY_FILTERS],
|
|
249
249
|
dialer_counters: counters,
|
|
250
250
|
iteration: existing?.iteration,
|
|
251
|
-
schema_version: compiledDateDoc?.schema_version ??
|
|
251
|
+
schema_version: compiledDateDoc?.schema_version ?? MATERIALIZED_SCHEMA_VERSIONS_1.MATERIALIZED_TENANT_DIALER_REPORTS_SCHEMA_VERSION,
|
|
252
252
|
// FROM THE DAYS THAT BELONG TO THIS PERIOD — never the stored watermark,
|
|
253
253
|
// and never an unrelated day from another period.
|
|
254
254
|
source_watermark: watermarkOfDays(nextDayDocs.filter((dayDoc) => {
|
|
@@ -271,7 +271,7 @@ function buildTenantDialerCloseDayPlan(input) {
|
|
|
271
271
|
const existing = storedEntriesByPage.get(key) ?? null;
|
|
272
272
|
const next = {
|
|
273
273
|
...compiled,
|
|
274
|
-
_id: existing?._id ?? new
|
|
274
|
+
_id: existing?._id ?? new bson_objectid_1.default().toHexString(),
|
|
275
275
|
iteration: Number(existing?.iteration ?? 0) + 1,
|
|
276
276
|
};
|
|
277
277
|
if (existing == null || force || needsMaterializedDialerEntriesWrite(existing, next)) {
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.compileTenantDialerReports = compileTenantDialerReports;
|
|
4
4
|
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
5
|
+
const MATERIALIZED_SCHEMA_VERSIONS_1 = require("../../constants/MATERIALIZED_SCHEMA_VERSIONS");
|
|
6
|
+
const MATERIALIZED_SCHEMA_VERSIONS_2 = require("../../constants/MATERIALIZED_SCHEMA_VERSIONS");
|
|
7
|
+
const materialized_tenant_dialer_reports_1 = require("../../schemas/types/materialized_tenant_dialer_reports");
|
|
8
8
|
const materialized_dialer_accumulator_helpers_1 = require("./materialized-dialer-accumulator-helpers");
|
|
9
9
|
const materialized_dialer_entry_pages_1 = require("./materialized-dialer-entry-pages");
|
|
10
10
|
const materialized_dialer_key_helpers_1 = require("./materialized-dialer-key-helpers");
|
|
@@ -116,9 +116,9 @@ function compileTenantDialerReports(input) {
|
|
|
116
116
|
scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE,
|
|
117
117
|
scope_field: localDate,
|
|
118
118
|
day_index: dayIndex,
|
|
119
|
-
sale_type_key_filters: [...
|
|
119
|
+
sale_type_key_filters: [...materialized_tenant_dialer_reports_1.MATERIALIZED_DIALER_REPORT_KEY_FILTERS],
|
|
120
120
|
dialer_counters: dialerCounters,
|
|
121
|
-
schema_version:
|
|
121
|
+
schema_version: MATERIALIZED_SCHEMA_VERSIONS_2.MATERIALIZED_TENANT_DIALER_REPORTS_SCHEMA_VERSION,
|
|
122
122
|
source_watermark: watermark,
|
|
123
123
|
computed_at: computedAt,
|
|
124
124
|
createdAt: computedAt,
|
|
@@ -144,7 +144,7 @@ function compileTenantDialerReports(input) {
|
|
|
144
144
|
page,
|
|
145
145
|
day_index: scope === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE ? dayIndex : null,
|
|
146
146
|
dialer_entries: entrySections,
|
|
147
|
-
schema_version:
|
|
147
|
+
schema_version: MATERIALIZED_SCHEMA_VERSIONS_1.MATERIALIZED_TENANT_DIALER_ENTRIES_SCHEMA_VERSION,
|
|
148
148
|
source_watermark: watermark,
|
|
149
149
|
computed_at: computedAt,
|
|
150
150
|
createdAt: computedAt,
|
|
@@ -9,9 +9,9 @@ exports.needsMaterializedDineinReportWrite = needsMaterializedDineinReportWrite;
|
|
|
9
9
|
exports.needsMaterializedDineinEntriesWrite = needsMaterializedDineinEntriesWrite;
|
|
10
10
|
exports.foldMaterializedDineinPeriodCounters = foldMaterializedDineinPeriodCounters;
|
|
11
11
|
exports.buildTenantDineinCloseDayPlan = buildTenantDineinCloseDayPlan;
|
|
12
|
-
const
|
|
12
|
+
const bson_objectid_1 = __importDefault(require("bson-objectid"));
|
|
13
13
|
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
14
|
-
const
|
|
14
|
+
const MATERIALIZED_SCHEMA_VERSIONS_1 = require("../../constants/MATERIALIZED_SCHEMA_VERSIONS");
|
|
15
15
|
const materialized_dinein_accumulator_helpers_1 = require("./materialized-dinein-accumulator-helpers");
|
|
16
16
|
const materialized_document_size_1 = require("./materialized-document-size");
|
|
17
17
|
const materialized_dinein_entry_pages_1 = require("./materialized-dinein-entry-pages");
|
|
@@ -183,7 +183,7 @@ function buildTenantDineinCloseDayPlan(input) {
|
|
|
183
183
|
const existing = storedReportsByScope.get(dineinScopeKey(compiledDateDoc));
|
|
184
184
|
const next = {
|
|
185
185
|
...compiledDateDoc,
|
|
186
|
-
_id: existing?._id ?? new
|
|
186
|
+
_id: existing?._id ?? new bson_objectid_1.default().toHexString(),
|
|
187
187
|
iteration: Number(existing?.iteration ?? 0) + 1,
|
|
188
188
|
};
|
|
189
189
|
if (force || needsMaterializedDineinReportWrite(existing, next))
|
|
@@ -271,7 +271,7 @@ function buildTenantDineinCloseDayPlan(input) {
|
|
|
271
271
|
for (const key of keys)
|
|
272
272
|
counters[key] = folded.counters[key];
|
|
273
273
|
const report = {
|
|
274
|
-
_id: existing?._id ?? new
|
|
274
|
+
_id: existing?._id ?? new bson_objectid_1.default().toHexString(),
|
|
275
275
|
tenant_id: tenantId,
|
|
276
276
|
brand_id: existing?.brand_id ?? compiledDateDoc?.brand_id ?? '',
|
|
277
277
|
scope_context: scope,
|
|
@@ -287,7 +287,7 @@ function buildTenantDineinCloseDayPlan(input) {
|
|
|
287
287
|
top_edited_checks: folded.topEditedChecks,
|
|
288
288
|
iteration: existing?.iteration,
|
|
289
289
|
// A folded period is always a CURRENT-shape document.
|
|
290
|
-
schema_version: compiledDateDoc?.schema_version ??
|
|
290
|
+
schema_version: compiledDateDoc?.schema_version ?? MATERIALIZED_SCHEMA_VERSIONS_1.MATERIALIZED_TENANT_DINEIN_REPORTS_SCHEMA_VERSION,
|
|
291
291
|
// FROM THE DAYS THAT BELONG TO THIS PERIOD - never the stored watermark.
|
|
292
292
|
source_watermark: watermarkOfDays(nextDayDocs.filter((dayDoc) => {
|
|
293
293
|
const fields = (0, scope_helpers_1.getMaterializedPeriodScopeFields)(String(dayDoc?.scope_field));
|
|
@@ -309,7 +309,7 @@ function buildTenantDineinCloseDayPlan(input) {
|
|
|
309
309
|
const existing = storedEntriesByPage.get(key) ?? null;
|
|
310
310
|
const next = {
|
|
311
311
|
...compiled,
|
|
312
|
-
_id: existing?._id ?? new
|
|
312
|
+
_id: existing?._id ?? new bson_objectid_1.default().toHexString(),
|
|
313
313
|
iteration: Number(existing?.iteration ?? 0) + 1,
|
|
314
314
|
};
|
|
315
315
|
if (existing == null || force || needsMaterializedDineinEntriesWrite(existing, next)) {
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.maskReservationGuestLabel = maskReservationGuestLabel;
|
|
4
4
|
exports.compileTenantDineinReports = compileTenantDineinReports;
|
|
5
5
|
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
6
|
+
const MATERIALIZED_SCHEMA_VERSIONS_1 = require("../../constants/MATERIALIZED_SCHEMA_VERSIONS");
|
|
7
|
+
const MATERIALIZED_SCHEMA_VERSIONS_2 = require("../../constants/MATERIALIZED_SCHEMA_VERSIONS");
|
|
8
|
+
const materialized_tenant_dinein_reports_1 = require("../../schemas/types/materialized_tenant_dinein_reports");
|
|
9
9
|
const materialized_dinein_accumulator_helpers_1 = require("./materialized-dinein-accumulator-helpers");
|
|
10
10
|
const materialized_dinein_classification_helpers_1 = require("./materialized-dinein-classification-helpers");
|
|
11
11
|
const materialized_dinein_entry_pages_1 = require("./materialized-dinein-entry-pages");
|
|
@@ -429,12 +429,12 @@ function compileTenantDineinReports(input) {
|
|
|
429
429
|
scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE,
|
|
430
430
|
scope_field: localDate,
|
|
431
431
|
day_index: dayIndex,
|
|
432
|
-
sale_type_key_filters: [...
|
|
432
|
+
sale_type_key_filters: [...materialized_tenant_dinein_reports_1.MATERIALIZED_DINEIN_REPORT_KEY_FILTERS],
|
|
433
433
|
dinein_counters: dineinCounters,
|
|
434
434
|
reservation_counters: reservationCounters,
|
|
435
435
|
upcoming_reservations: (0, materialized_dinein_accumulator_helpers_1.mergeMaterializedDineinUpcomingReservations)([upcomingReservations], MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_UPCOMING_RESERVATION_LIMIT),
|
|
436
436
|
top_edited_checks: (0, materialized_dinein_accumulator_helpers_1.mergeMaterializedDineinTopEditedChecks)([topEditedChecks], MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_TOP_EDITED_CHECK_LIMIT),
|
|
437
|
-
schema_version:
|
|
437
|
+
schema_version: MATERIALIZED_SCHEMA_VERSIONS_2.MATERIALIZED_TENANT_DINEIN_REPORTS_SCHEMA_VERSION,
|
|
438
438
|
source_watermark: watermark,
|
|
439
439
|
computed_at: computedAt,
|
|
440
440
|
createdAt: computedAt,
|
|
@@ -470,7 +470,7 @@ function compileTenantDineinReports(input) {
|
|
|
470
470
|
page,
|
|
471
471
|
day_index: scope === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE ? dayIndex : null,
|
|
472
472
|
dinein_entries: sections,
|
|
473
|
-
schema_version:
|
|
473
|
+
schema_version: MATERIALIZED_SCHEMA_VERSIONS_1.MATERIALIZED_TENANT_DINEIN_ENTRIES_SCHEMA_VERSION,
|
|
474
474
|
source_watermark: watermark,
|
|
475
475
|
computed_at: computedAt,
|
|
476
476
|
createdAt: computedAt,
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.MATERIALIZED_DISCOUNT_COMPILED_SCOPES = void 0;
|
|
7
7
|
exports.compileTenantDiscountReports = compileTenantDiscountReports;
|
|
8
|
-
const
|
|
8
|
+
const bson_objectid_1 = __importDefault(require("bson-objectid"));
|
|
9
9
|
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
10
10
|
const materialized_discount_accumulator_helpers_1 = require("./materialized-discount-accumulator-helpers");
|
|
11
11
|
const materialized_discount_classification_helpers_1 = require("./materialized-discount-classification-helpers");
|
|
@@ -163,7 +163,7 @@ function compileTenantDiscountReports(input) {
|
|
|
163
163
|
const docWatermark = watermark ?? sourceWatermark;
|
|
164
164
|
const isDateScoped = scope === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE || scope === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_HOUR;
|
|
165
165
|
reports.push({
|
|
166
|
-
_id: new
|
|
166
|
+
_id: new bson_objectid_1.default().toHexString(),
|
|
167
167
|
tenant_id: tenantId,
|
|
168
168
|
brand_id: brandId,
|
|
169
169
|
scope_context: scope,
|
|
@@ -186,7 +186,7 @@ function compileTenantDiscountReports(input) {
|
|
|
186
186
|
// Entries documents exist only when there is at least one row.
|
|
187
187
|
if (Object.keys(entrySections).length > 0) {
|
|
188
188
|
entriesDocs.push({
|
|
189
|
-
_id: new
|
|
189
|
+
_id: new bson_objectid_1.default().toHexString(),
|
|
190
190
|
tenant_id: tenantId,
|
|
191
191
|
brand_id: brandId,
|
|
192
192
|
scope_context: scope,
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.materializedDocumentBsonBytes = materializedDocumentBsonBytes;
|
|
7
4
|
exports.assertMaterializedDocumentSize = assertMaterializedDocumentSize;
|
|
8
5
|
exports.assertMaterializedDocumentsSize = assertMaterializedDocumentsSize;
|
|
9
|
-
const
|
|
6
|
+
const bson_1 = require("bson");
|
|
10
7
|
/**
|
|
11
8
|
* The BSON SIZE BUDGET of a materialized report/entry/geo document.
|
|
12
9
|
*
|
|
@@ -39,7 +36,7 @@ const mongoose_1 = __importDefault(require("mongoose"));
|
|
|
39
36
|
function materializedDocumentBsonBytes(document) {
|
|
40
37
|
if (document == null)
|
|
41
38
|
return 0;
|
|
42
|
-
return
|
|
39
|
+
return (0, bson_1.calculateObjectSize)(document);
|
|
43
40
|
}
|
|
44
41
|
/**
|
|
45
42
|
* Throws when ONE document exceeds its budget.
|
|
@@ -20,6 +20,7 @@ const materialized_tenant_discount_reports_1 = require("../../schemas/models/mat
|
|
|
20
20
|
const materialized_tenant_discount_sources_1 = require("../../schemas/models/materialized_tenant_discount_sources");
|
|
21
21
|
const materialized_tenant_prep_time_entries_1 = require("../../schemas/models/materialized_tenant_prep_time_entries");
|
|
22
22
|
const materialized_tenant_prep_time_reports_1 = require("../../schemas/models/materialized_tenant_prep_time_reports");
|
|
23
|
+
const materialized_tenant_report_runs_1 = require("../../schemas/models/materialized_tenant_report_runs");
|
|
23
24
|
const materialized_tenant_reports_iterations_1 = require("../../schemas/models/materialized_tenant_reports_iterations");
|
|
24
25
|
const materialized_tenant_sales_overview_reports_1 = require("../../schemas/models/materialized_tenant_sales_overview_reports");
|
|
25
26
|
const tenant_active_jobs_1 = require("../../schemas/models/tenant_active_jobs");
|
|
@@ -47,6 +48,7 @@ const INDEXES = {
|
|
|
47
48
|
[materialized_tenant_discount_sources_1.MATERIALIZED_TENANT_DISCOUNT_SOURCES_COLLECTION_NAME]: materialized_tenant_discount_sources_1.MATERIALIZED_TENANT_DISCOUNT_SOURCES_INDEX_OPTIONS,
|
|
48
49
|
[materialized_tenant_prep_time_reports_1.MATERIALIZED_TENANT_PREP_TIME_REPORTS_COLLECTION_NAME]: materialized_tenant_prep_time_reports_1.MATERIALIZED_TENANT_PREP_TIME_REPORTS_INDEX_OPTIONS,
|
|
49
50
|
[materialized_tenant_prep_time_entries_1.MATERIALIZED_TENANT_PREP_TIME_ENTRIES_COLLECTION_NAME]: materialized_tenant_prep_time_entries_1.MATERIALIZED_TENANT_PREP_TIME_ENTRIES_INDEX_OPTIONS,
|
|
51
|
+
[MATERIALIZED_REPORTS_2.MATERIALIZED_TENANT_REPORT_RUNS_COLLECTION_NAME]: materialized_tenant_report_runs_1.MATERIALIZED_TENANT_REPORT_RUNS_INDEX_OPTIONS,
|
|
50
52
|
[materialized_tenant_reports_iterations_1.MATERIALIZED_TENANT_REPORTS_ITERATIONS_COLLECTION_NAME]: materialized_tenant_reports_iterations_1.MATERIALIZED_TENANT_REPORTS_ITERATIONS_INDEX_OPTIONS,
|
|
51
53
|
[materialized_tenant_delivery_geo_cells_1.MATERIALIZED_TENANT_DELIVERY_GEO_CELLS_COLLECTION_NAME]: materialized_tenant_delivery_geo_cells_1.MATERIALIZED_TENANT_DELIVERY_GEO_CELLS_INDEX_OPTIONS,
|
|
52
54
|
[MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_DELIVERY_GEO_SCOPES_COLLECTION_NAME]: materialized_tenant_delivery_geo_scopes_1.MATERIALIZED_TENANT_DELIVERY_GEO_SCOPES_INDEX_OPTIONS,
|
|
@@ -12,7 +12,7 @@ exports.getMaterializedPrepTimePeriodDayScopeFields = getMaterializedPrepTimePer
|
|
|
12
12
|
exports.getMaterializedPrepTimeReportPeriodDayScopeFields = getMaterializedPrepTimeReportPeriodDayScopeFields;
|
|
13
13
|
exports.needsMaterializedPrepTimeReportWrite = needsMaterializedPrepTimeReportWrite;
|
|
14
14
|
exports.buildTenantPrepTimeCloseDayPlan = buildTenantPrepTimeCloseDayPlan;
|
|
15
|
-
const
|
|
15
|
+
const bson_objectid_1 = __importDefault(require("bson-objectid"));
|
|
16
16
|
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
17
17
|
const materialized_prep_time_classification_helpers_1 = require("./materialized-prep-time-classification-helpers");
|
|
18
18
|
const materialized_prep_time_compile_helpers_1 = require("./materialized-prep-time-compile-helpers");
|
|
@@ -375,7 +375,7 @@ function buildTenantPrepTimeCloseDayPlan(input) {
|
|
|
375
375
|
const report = {
|
|
376
376
|
// A period document created by the fold gets a fresh id; an existing one keeps
|
|
377
377
|
// its identity so the upsert targets the same row.
|
|
378
|
-
_id: existingDoc?._id ?? new
|
|
378
|
+
_id: existingDoc?._id ?? new bson_objectid_1.default().toHexString(),
|
|
379
379
|
tenant_id: tenantId,
|
|
380
380
|
brand_id: existingDoc?.brand_id ?? reports[0]?.brand_id ?? '',
|
|
381
381
|
scope_context: scope,
|
|
@@ -486,7 +486,7 @@ function buildTenantPrepTimeCloseDayPlan(input) {
|
|
|
486
486
|
}
|
|
487
487
|
}
|
|
488
488
|
const report = {
|
|
489
|
-
_id: existingDoc?._id ?? new
|
|
489
|
+
_id: existingDoc?._id ?? new bson_objectid_1.default().toHexString(),
|
|
490
490
|
tenant_id: tenantId,
|
|
491
491
|
brand_id: existingDoc?.brand_id ?? entries[0]?.brand_id ?? '',
|
|
492
492
|
scope_context: scope,
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.mergeMaterializedPrepTimeCounters = mergeMaterializedPrepTimeCounters;
|
|
7
7
|
exports.compileTenantPrepTimeReports = compileTenantPrepTimeReports;
|
|
8
|
-
const
|
|
8
|
+
const bson_objectid_1 = __importDefault(require("bson-objectid"));
|
|
9
9
|
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
10
10
|
const materialized_prep_time_classification_helpers_1 = require("./materialized-prep-time-classification-helpers");
|
|
11
11
|
const scope_helpers_1 = require("./scope-helpers");
|
|
@@ -176,7 +176,7 @@ function compileTenantPrepTimeReports(input) {
|
|
|
176
176
|
const docWatermark = watermark ?? sourceWatermark;
|
|
177
177
|
const isDateScoped = scopeContext === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE;
|
|
178
178
|
reports.push({
|
|
179
|
-
_id: new
|
|
179
|
+
_id: new bson_objectid_1.default().toHexString(),
|
|
180
180
|
tenant_id: tenantId,
|
|
181
181
|
brand_id: brandId,
|
|
182
182
|
scope_context: scopeContext,
|
|
@@ -194,7 +194,7 @@ function compileTenantPrepTimeReports(input) {
|
|
|
194
194
|
});
|
|
195
195
|
if (itemScopes.has(scopeContext) && Object.keys(entrySections).length > 0) {
|
|
196
196
|
entries.push({
|
|
197
|
-
_id: new
|
|
197
|
+
_id: new bson_objectid_1.default().toHexString(),
|
|
198
198
|
tenant_id: tenantId,
|
|
199
199
|
brand_id: brandId,
|
|
200
200
|
scope_context: scopeContext,
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM, type TMaterializedReadinessReportKey } from '../../constants/MATERIALIZED_REPORTS';
|
|
2
|
+
/**
|
|
3
|
+
* PURE report-run-ledger helpers shared by the writer (workers-service) and the
|
|
4
|
+
* admin/retry API (operations-service).
|
|
5
|
+
*
|
|
6
|
+
* The ledger row identity is `(tenant_id, localDate, report_key,
|
|
7
|
+
* schema_version)` — the SAME identity as the readiness row, but a DIFFERENT
|
|
8
|
+
* collection with a DIFFERENT lifecycle:
|
|
9
|
+
*
|
|
10
|
+
* - readiness (COMMITTED / NEEDS_RECONCILIATION) is written INSIDE the report
|
|
11
|
+
* transaction, so it can never exist for a failed report;
|
|
12
|
+
* - the run row (PENDING / RUNNING / RETRYING / COMMITTED / FAILED) is written
|
|
13
|
+
* OUTSIDE the transaction, so a rollback cannot hide the attempt.
|
|
14
|
+
*/
|
|
15
|
+
export interface IMaterializedReportRunIdentity {
|
|
16
|
+
tenantId: string;
|
|
17
|
+
localDate: string;
|
|
18
|
+
reportKey: TMaterializedReadinessReportKey | string;
|
|
19
|
+
schemaVersion?: number;
|
|
20
|
+
}
|
|
21
|
+
/** Stable string key of one run row (Map keys / log correlation). */
|
|
22
|
+
export declare function materializedReportRunKey(parts: IMaterializedReportRunIdentity): string;
|
|
23
|
+
/** The Mongo filter of the ONE run row of a report. */
|
|
24
|
+
export declare function buildMaterializedReportRunFilter(parts: IMaterializedReportRunIdentity): {
|
|
25
|
+
tenant_id: string;
|
|
26
|
+
localDate: string;
|
|
27
|
+
report_key: string;
|
|
28
|
+
schema_version: number;
|
|
29
|
+
};
|
|
30
|
+
export declare function isMaterializedReportRunStatus(value: unknown): value is MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM;
|
|
31
|
+
/**
|
|
32
|
+
* Is the report CURRENTLY being executed?
|
|
33
|
+
*
|
|
34
|
+
* Only a run that owns the report may be in this state; the retry API refuses
|
|
35
|
+
* it (409) instead of racing the executor.
|
|
36
|
+
*/
|
|
37
|
+
export declare function isMaterializedReportRunInFlight(status: unknown): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Does this run carry the UNKNOWN-COMMIT marker?
|
|
40
|
+
*
|
|
41
|
+
* Such a run MUST stay non-terminal until recovery settles it from
|
|
42
|
+
* ownership-checked readiness (a ledger error alone must never decide it).
|
|
43
|
+
*/
|
|
44
|
+
export declare function isMaterializedReportRunCommitOutcomeUnknown(run: {
|
|
45
|
+
last_error?: string | null;
|
|
46
|
+
} | null | undefined): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Proves that a readiness row belongs to the run that owns this report.
|
|
49
|
+
*
|
|
50
|
+
* The row identity is the tenant/day/report/schema; ownership is the RUN
|
|
51
|
+
* identity. A row written by an OLDER close/re-close carries a DIFFERENT
|
|
52
|
+
* `run_id` and therefore proves nothing about the current run: it must keep the
|
|
53
|
+
* old report readable while the current run is recorded as FAILED
|
|
54
|
+
* (`INTERRUPTED_RUN`) and stays retryable. Never delete that older row.
|
|
55
|
+
*/
|
|
56
|
+
export declare function isMaterializedReadinessOwnedByRun(args: {
|
|
57
|
+
readiness: {
|
|
58
|
+
run_id?: string | null;
|
|
59
|
+
} | null | undefined;
|
|
60
|
+
run: {
|
|
61
|
+
run_id?: string | null;
|
|
62
|
+
} | null | undefined;
|
|
63
|
+
}): boolean;
|
|
64
|
+
/** COMMITTED / FAILED: the execution reached a terminal state. */
|
|
65
|
+
export declare function isMaterializedReportRunTerminal(status: unknown): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* The instant a run started (its `started_at`, or `updatedAt` when a legacy /
|
|
68
|
+
* partial row has none).
|
|
69
|
+
*/
|
|
70
|
+
export declare function materializedReportRunStartedAt(run: {
|
|
71
|
+
started_at?: Date | string | null;
|
|
72
|
+
updatedAt?: Date | string | null;
|
|
73
|
+
}): Date | null;
|
|
74
|
+
/**
|
|
75
|
+
* Is an IN-FLIGHT run old enough that an interruption is plausible?
|
|
76
|
+
*
|
|
77
|
+
* AGE ALONE IS NEVER ENOUGH: recovery must also observe a STALE
|
|
78
|
+
* `tenant_active_jobs` heartbeat, otherwise a healthy long-running report would
|
|
79
|
+
* be taken over. This helper only answers the age question.
|
|
80
|
+
*/
|
|
81
|
+
export declare function isMaterializedReportRunStale(args: {
|
|
82
|
+
run: {
|
|
83
|
+
status?: unknown;
|
|
84
|
+
started_at?: Date | string | null;
|
|
85
|
+
updatedAt?: Date | string | null;
|
|
86
|
+
};
|
|
87
|
+
now?: Date;
|
|
88
|
+
staleAfterMs?: number;
|
|
89
|
+
}): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* May this report be retried?
|
|
92
|
+
*
|
|
93
|
+
* A MISSING row is retryable (the report never ran: a failed day, a crash
|
|
94
|
+
* before the first attempt, or a pre-ledger day). A FAILED row is retryable.
|
|
95
|
+
* A COMMITTED row is NOT (the retry would be a no-op), and an in-flight row is
|
|
96
|
+
* NOT (the executor owns it).
|
|
97
|
+
*/
|
|
98
|
+
export declare function canRetryMaterializedReportRun(status: unknown): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Sanitizes an execution error for durable storage / API output.
|
|
101
|
+
*
|
|
102
|
+
* Deliberately conservative: the message is single-lined, PII-redacted and
|
|
103
|
+
* bounded. The ERROR STACK and raw driver payload are never stored.
|
|
104
|
+
*/
|
|
105
|
+
export declare function sanitizeMaterializedReportRunError(error: unknown): string | null;
|