@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
|
@@ -36,12 +36,12 @@ export declare const MaterializedTenantPrepTimeReportSchema: Schema<any, import(
|
|
|
36
36
|
tenant_id: string;
|
|
37
37
|
day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
|
|
38
38
|
iteration: number;
|
|
39
|
-
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
40
|
-
scope_field: string;
|
|
41
|
-
sale_type_key_filters: string[];
|
|
42
39
|
schema_version: number;
|
|
43
40
|
source_watermark: NativeDate;
|
|
44
41
|
computed_at: NativeDate;
|
|
42
|
+
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
43
|
+
scope_field: string;
|
|
44
|
+
sale_type_key_filters: string[];
|
|
45
45
|
prep_time_counters: any;
|
|
46
46
|
prep_time_counter_rows: any;
|
|
47
47
|
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
@@ -54,12 +54,12 @@ export declare const MaterializedTenantPrepTimeReportSchema: Schema<any, import(
|
|
|
54
54
|
tenant_id: string;
|
|
55
55
|
day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
|
|
56
56
|
iteration: number;
|
|
57
|
-
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
58
|
-
scope_field: string;
|
|
59
|
-
sale_type_key_filters: string[];
|
|
60
57
|
schema_version: number;
|
|
61
58
|
source_watermark: NativeDate;
|
|
62
59
|
computed_at: NativeDate;
|
|
60
|
+
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
61
|
+
scope_field: string;
|
|
62
|
+
sale_type_key_filters: string[];
|
|
63
63
|
prep_time_counters: any;
|
|
64
64
|
prep_time_counter_rows: any;
|
|
65
65
|
}>> & import("mongoose").FlatRecord<{
|
|
@@ -72,12 +72,12 @@ export declare const MaterializedTenantPrepTimeReportSchema: Schema<any, import(
|
|
|
72
72
|
tenant_id: string;
|
|
73
73
|
day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
|
|
74
74
|
iteration: number;
|
|
75
|
-
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
76
|
-
scope_field: string;
|
|
77
|
-
sale_type_key_filters: string[];
|
|
78
75
|
schema_version: number;
|
|
79
76
|
source_watermark: NativeDate;
|
|
80
77
|
computed_at: NativeDate;
|
|
78
|
+
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
79
|
+
scope_field: string;
|
|
80
|
+
sale_type_key_filters: string[];
|
|
81
81
|
prep_time_counters: any;
|
|
82
82
|
prep_time_counter_rows: any;
|
|
83
83
|
}> & {
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Schema } from 'mongoose';
|
|
2
|
+
import { MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM } from '../../constants/MATERIALIZED_REPORTS';
|
|
3
|
+
/**
|
|
4
|
+
* Mongoose schema for `materialized_tenant_report_runs` — the OPERATIONAL
|
|
5
|
+
* per-report execution ledger (PENDING / RUNNING / RETRYING / COMMITTED /
|
|
6
|
+
* FAILED).
|
|
7
|
+
*
|
|
8
|
+
* It is deliberately SEPARATE from `materialized_tenant_day_readiness`:
|
|
9
|
+
* readiness is the historical read gate and only ever carries COMMITTED /
|
|
10
|
+
* NEEDS_RECONCILIATION. A failed report must never look materialized, so its
|
|
11
|
+
* failure is recorded here, together with `attempts` and the redacted
|
|
12
|
+
* `last_error`.
|
|
13
|
+
*
|
|
14
|
+
* The row is written OUTSIDE the report transaction (a rollback must not erase
|
|
15
|
+
* the attempt), keyed by the unique compound
|
|
16
|
+
* `(tenant_id, localDate, report_key, schema_version)`.
|
|
17
|
+
*/
|
|
18
|
+
export declare const MaterializedTenantReportRunSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
19
|
+
timestamps: true;
|
|
20
|
+
versionKey: false;
|
|
21
|
+
minimize: false;
|
|
22
|
+
}, {
|
|
23
|
+
createdAt: NativeDate;
|
|
24
|
+
updatedAt: NativeDate;
|
|
25
|
+
} & {
|
|
26
|
+
localDate: string;
|
|
27
|
+
createdAt: NativeDate;
|
|
28
|
+
updatedAt: NativeDate;
|
|
29
|
+
tenant_id: string;
|
|
30
|
+
status: MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM;
|
|
31
|
+
schema_version: number;
|
|
32
|
+
report_key: "DELIVERY" | "DISCOUNTS" | "OVERVIEW" | "PREP_TIME" | "DIALER" | "DINEIN";
|
|
33
|
+
attempts: number;
|
|
34
|
+
total_attempts: number;
|
|
35
|
+
run_id?: string | null | undefined;
|
|
36
|
+
last_error?: string | null | undefined;
|
|
37
|
+
started_at?: NativeDate | null | undefined;
|
|
38
|
+
finished_at?: NativeDate | null | undefined;
|
|
39
|
+
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
40
|
+
createdAt: NativeDate;
|
|
41
|
+
updatedAt: NativeDate;
|
|
42
|
+
} & {
|
|
43
|
+
localDate: string;
|
|
44
|
+
createdAt: NativeDate;
|
|
45
|
+
updatedAt: NativeDate;
|
|
46
|
+
tenant_id: string;
|
|
47
|
+
status: MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM;
|
|
48
|
+
schema_version: number;
|
|
49
|
+
report_key: "DELIVERY" | "DISCOUNTS" | "OVERVIEW" | "PREP_TIME" | "DIALER" | "DINEIN";
|
|
50
|
+
attempts: number;
|
|
51
|
+
total_attempts: number;
|
|
52
|
+
run_id?: string | null | undefined;
|
|
53
|
+
last_error?: string | null | undefined;
|
|
54
|
+
started_at?: NativeDate | null | undefined;
|
|
55
|
+
finished_at?: NativeDate | null | undefined;
|
|
56
|
+
}>> & import("mongoose").FlatRecord<{
|
|
57
|
+
createdAt: NativeDate;
|
|
58
|
+
updatedAt: NativeDate;
|
|
59
|
+
} & {
|
|
60
|
+
localDate: string;
|
|
61
|
+
createdAt: NativeDate;
|
|
62
|
+
updatedAt: NativeDate;
|
|
63
|
+
tenant_id: string;
|
|
64
|
+
status: MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM;
|
|
65
|
+
schema_version: number;
|
|
66
|
+
report_key: "DELIVERY" | "DISCOUNTS" | "OVERVIEW" | "PREP_TIME" | "DIALER" | "DINEIN";
|
|
67
|
+
attempts: number;
|
|
68
|
+
total_attempts: number;
|
|
69
|
+
run_id?: string | null | undefined;
|
|
70
|
+
last_error?: string | null | undefined;
|
|
71
|
+
started_at?: NativeDate | null | undefined;
|
|
72
|
+
finished_at?: NativeDate | null | undefined;
|
|
73
|
+
}> & {
|
|
74
|
+
_id: import("mongoose").Types.ObjectId;
|
|
75
|
+
} & {
|
|
76
|
+
__v: number;
|
|
77
|
+
}>;
|
|
78
|
+
export declare const MATERIALIZED_TENANT_REPORT_RUNS_COLLECTION_INDEXES: {
|
|
79
|
+
_id: {
|
|
80
|
+
_id: number;
|
|
81
|
+
};
|
|
82
|
+
tenant_id__localDate__report_key__schema_version: {
|
|
83
|
+
tenant_id: number;
|
|
84
|
+
localDate: number;
|
|
85
|
+
report_key: number;
|
|
86
|
+
schema_version: number;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Index OPTIONS the owner must CREATE (declared here, applied by a separate
|
|
91
|
+
* migration/deploy step — never by a read, a close or a retry at runtime).
|
|
92
|
+
*/
|
|
93
|
+
export declare const MATERIALIZED_TENANT_REPORT_RUNS_INDEX_OPTIONS: readonly {
|
|
94
|
+
key: Record<string, 1 | -1>;
|
|
95
|
+
name: string;
|
|
96
|
+
unique?: boolean;
|
|
97
|
+
}[];
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MATERIALIZED_TENANT_REPORT_RUNS_INDEX_OPTIONS = exports.MATERIALIZED_TENANT_REPORT_RUNS_COLLECTION_INDEXES = exports.MaterializedTenantReportRunSchema = void 0;
|
|
4
|
+
const mongoose_1 = require("mongoose");
|
|
5
|
+
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
6
|
+
/**
|
|
7
|
+
* Mongoose schema for `materialized_tenant_report_runs` — the OPERATIONAL
|
|
8
|
+
* per-report execution ledger (PENDING / RUNNING / RETRYING / COMMITTED /
|
|
9
|
+
* FAILED).
|
|
10
|
+
*
|
|
11
|
+
* It is deliberately SEPARATE from `materialized_tenant_day_readiness`:
|
|
12
|
+
* readiness is the historical read gate and only ever carries COMMITTED /
|
|
13
|
+
* NEEDS_RECONCILIATION. A failed report must never look materialized, so its
|
|
14
|
+
* failure is recorded here, together with `attempts` and the redacted
|
|
15
|
+
* `last_error`.
|
|
16
|
+
*
|
|
17
|
+
* The row is written OUTSIDE the report transaction (a rollback must not erase
|
|
18
|
+
* the attempt), keyed by the unique compound
|
|
19
|
+
* `(tenant_id, localDate, report_key, schema_version)`.
|
|
20
|
+
*/
|
|
21
|
+
exports.MaterializedTenantReportRunSchema = new mongoose_1.Schema({
|
|
22
|
+
tenant_id: { type: String, required: true },
|
|
23
|
+
localDate: { type: String, required: true },
|
|
24
|
+
report_key: {
|
|
25
|
+
type: String,
|
|
26
|
+
required: true,
|
|
27
|
+
enum: [...MATERIALIZED_REPORTS_1.MATERIALIZED_READINESS_REPORT_KEYS],
|
|
28
|
+
},
|
|
29
|
+
schema_version: {
|
|
30
|
+
type: Number,
|
|
31
|
+
required: true,
|
|
32
|
+
immutable: true,
|
|
33
|
+
default: MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_REPORT_RUNS_SCHEMA_VERSION,
|
|
34
|
+
},
|
|
35
|
+
status: {
|
|
36
|
+
type: String,
|
|
37
|
+
required: true,
|
|
38
|
+
enum: MATERIALIZED_REPORTS_1.ALL_MATERIALIZED_TENANT_REPORT_RUN_STATUSES,
|
|
39
|
+
default: MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM.PENDING,
|
|
40
|
+
},
|
|
41
|
+
attempts: {
|
|
42
|
+
type: Number,
|
|
43
|
+
required: true,
|
|
44
|
+
default: 0,
|
|
45
|
+
// Stored counters remain integers.
|
|
46
|
+
validate: {
|
|
47
|
+
validator: (value) => Number.isInteger(value) && value >= 0,
|
|
48
|
+
message: 'attempts must be a non-negative integer',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
total_attempts: {
|
|
52
|
+
type: Number,
|
|
53
|
+
required: true,
|
|
54
|
+
default: 0,
|
|
55
|
+
// Stored counters remain integers.
|
|
56
|
+
validate: {
|
|
57
|
+
validator: (value) => Number.isInteger(value) && value >= 0,
|
|
58
|
+
message: 'total_attempts must be a non-negative integer',
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
last_error: { type: String, required: false, default: null },
|
|
62
|
+
run_id: { type: String, required: false, default: null },
|
|
63
|
+
started_at: { type: mongoose_1.Schema.Types.Date, required: false, default: null },
|
|
64
|
+
finished_at: { type: mongoose_1.Schema.Types.Date, required: false, default: null },
|
|
65
|
+
createdAt: {
|
|
66
|
+
type: mongoose_1.Schema.Types.Date,
|
|
67
|
+
required: true,
|
|
68
|
+
default: () => new Date(),
|
|
69
|
+
immutable: true,
|
|
70
|
+
},
|
|
71
|
+
updatedAt: {
|
|
72
|
+
type: mongoose_1.Schema.Types.Date,
|
|
73
|
+
required: true,
|
|
74
|
+
default: () => new Date(),
|
|
75
|
+
},
|
|
76
|
+
}, { timestamps: true, versionKey: false, minimize: false });
|
|
77
|
+
exports.MATERIALIZED_TENANT_REPORT_RUNS_COLLECTION_INDEXES = {
|
|
78
|
+
_id: { _id: 1 },
|
|
79
|
+
tenant_id__localDate__report_key__schema_version: {
|
|
80
|
+
tenant_id: 1,
|
|
81
|
+
localDate: 1,
|
|
82
|
+
report_key: 1,
|
|
83
|
+
schema_version: 1,
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Index OPTIONS the owner must CREATE (declared here, applied by a separate
|
|
88
|
+
* migration/deploy step — never by a read, a close or a retry at runtime).
|
|
89
|
+
*/
|
|
90
|
+
exports.MATERIALIZED_TENANT_REPORT_RUNS_INDEX_OPTIONS = [
|
|
91
|
+
{
|
|
92
|
+
key: { tenant_id: 1, localDate: 1, report_key: 1, schema_version: 1 },
|
|
93
|
+
name: 'tenant_id__localDate__report_key__schema_version',
|
|
94
|
+
unique: true,
|
|
95
|
+
},
|
|
96
|
+
// Admin materialization page: one tenant-day's reports, newest first.
|
|
97
|
+
{
|
|
98
|
+
key: { tenant_id: 1, localDate: 1, report_key: 1 },
|
|
99
|
+
name: 'tenant_id__localDate__report_key',
|
|
100
|
+
unique: false,
|
|
101
|
+
},
|
|
102
|
+
// Admin materialization page: the failed/running filters across tenants.
|
|
103
|
+
{
|
|
104
|
+
key: { status: 1, updatedAt: -1 },
|
|
105
|
+
name: 'status__updatedAt',
|
|
106
|
+
unique: false,
|
|
107
|
+
},
|
|
108
|
+
];
|
|
@@ -63,12 +63,12 @@ export declare const MaterializedTenantSalesComparisonEntriesSchema: Schema<any,
|
|
|
63
63
|
tenant_id: string;
|
|
64
64
|
day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
|
|
65
65
|
iteration: number;
|
|
66
|
-
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
67
|
-
scope_field: string;
|
|
68
|
-
sale_type_key_filters: string[];
|
|
69
66
|
schema_version: number;
|
|
70
67
|
source_watermark: NativeDate;
|
|
71
68
|
computed_at: NativeDate;
|
|
69
|
+
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
70
|
+
scope_field: string;
|
|
71
|
+
sale_type_key_filters: string[];
|
|
72
72
|
sales_entries: any;
|
|
73
73
|
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
74
74
|
createdAt: NativeDate;
|
|
@@ -81,12 +81,12 @@ export declare const MaterializedTenantSalesComparisonEntriesSchema: Schema<any,
|
|
|
81
81
|
tenant_id: string;
|
|
82
82
|
day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
|
|
83
83
|
iteration: number;
|
|
84
|
-
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
85
|
-
scope_field: string;
|
|
86
|
-
sale_type_key_filters: string[];
|
|
87
84
|
schema_version: number;
|
|
88
85
|
source_watermark: NativeDate;
|
|
89
86
|
computed_at: NativeDate;
|
|
87
|
+
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
88
|
+
scope_field: string;
|
|
89
|
+
sale_type_key_filters: string[];
|
|
90
90
|
sales_entries: any;
|
|
91
91
|
}>> & import("mongoose").FlatRecord<{
|
|
92
92
|
createdAt: NativeDate;
|
|
@@ -99,12 +99,12 @@ export declare const MaterializedTenantSalesComparisonEntriesSchema: Schema<any,
|
|
|
99
99
|
tenant_id: string;
|
|
100
100
|
day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
|
|
101
101
|
iteration: number;
|
|
102
|
-
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
103
|
-
scope_field: string;
|
|
104
|
-
sale_type_key_filters: string[];
|
|
105
102
|
schema_version: number;
|
|
106
103
|
source_watermark: NativeDate;
|
|
107
104
|
computed_at: NativeDate;
|
|
105
|
+
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
106
|
+
scope_field: string;
|
|
107
|
+
sale_type_key_filters: string[];
|
|
108
108
|
sales_entries: any;
|
|
109
109
|
}> & Required<{
|
|
110
110
|
_id: import("mongoose").Types.ObjectId;
|
|
@@ -80,12 +80,12 @@ export declare const MaterializedTenantSalesComparisonReportSchema: Schema<any,
|
|
|
80
80
|
tenant_id: string;
|
|
81
81
|
day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
|
|
82
82
|
iteration: number;
|
|
83
|
-
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
84
|
-
scope_field: string;
|
|
85
|
-
sale_type_key_filters: string[];
|
|
86
83
|
schema_version: number;
|
|
87
84
|
source_watermark: NativeDate;
|
|
88
85
|
computed_at: NativeDate;
|
|
86
|
+
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
87
|
+
scope_field: string;
|
|
88
|
+
sale_type_key_filters: string[];
|
|
89
89
|
sales_counters: any;
|
|
90
90
|
sales_counter_rows: any;
|
|
91
91
|
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
@@ -99,12 +99,12 @@ export declare const MaterializedTenantSalesComparisonReportSchema: Schema<any,
|
|
|
99
99
|
tenant_id: string;
|
|
100
100
|
day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
|
|
101
101
|
iteration: number;
|
|
102
|
-
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
103
|
-
scope_field: string;
|
|
104
|
-
sale_type_key_filters: string[];
|
|
105
102
|
schema_version: number;
|
|
106
103
|
source_watermark: NativeDate;
|
|
107
104
|
computed_at: NativeDate;
|
|
105
|
+
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
106
|
+
scope_field: string;
|
|
107
|
+
sale_type_key_filters: string[];
|
|
108
108
|
sales_counters: any;
|
|
109
109
|
sales_counter_rows: any;
|
|
110
110
|
}>> & import("mongoose").FlatRecord<{
|
|
@@ -118,12 +118,12 @@ export declare const MaterializedTenantSalesComparisonReportSchema: Schema<any,
|
|
|
118
118
|
tenant_id: string;
|
|
119
119
|
day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
|
|
120
120
|
iteration: number;
|
|
121
|
-
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
122
|
-
scope_field: string;
|
|
123
|
-
sale_type_key_filters: string[];
|
|
124
121
|
schema_version: number;
|
|
125
122
|
source_watermark: NativeDate;
|
|
126
123
|
computed_at: NativeDate;
|
|
124
|
+
scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
125
|
+
scope_field: string;
|
|
126
|
+
sale_type_key_filters: string[];
|
|
127
127
|
sales_counters: any;
|
|
128
128
|
sales_counter_rows: any;
|
|
129
129
|
}> & Required<{
|
|
@@ -1,30 +1,6 @@
|
|
|
1
|
+
import { MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_SCHEMA_VERSION } from '../../constants/MATERIALIZED_SCHEMA_VERSIONS';
|
|
2
|
+
export { MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_SCHEMA_VERSION };
|
|
1
3
|
import { Schema } from 'mongoose';
|
|
2
|
-
/**
|
|
3
|
-
* Mongoose schema for `materialized_tenant_sales_overview_reports` — the
|
|
4
|
-
* materialized Reports > Overview data (one document per tenant × scope
|
|
5
|
-
* context × scope value), maintained by the day-end materialization job and
|
|
6
|
-
* read by the analytics API. Scope slices are stamped from the order's
|
|
7
|
-
* business day (`order.localDate`); hour buckets use the punch hour for sales
|
|
8
|
-
* and the settlement hour for credit-bill collections (see
|
|
9
|
-
* `MATERIALIZED_REPORTS.md`). The report's time-bias toggle (Punched At /
|
|
10
|
-
* `createdAt`) is out of scope. `scope_field` formats are documented on
|
|
11
|
-
* `MATERIALIZED_REPORT_SCOPE_ENUM` and in `MATERIALIZED_REPORTS.md`.
|
|
12
|
-
* NUMBERS ONLY: credit-bill COUNTERS (issued / settled / received) live in
|
|
13
|
-
* each `sale_type_metrics` key's `CREDIT_BILLS` slot — constant-size numbers.
|
|
14
|
-
* The ITEMIZED ledger (one row per bill + its receipt events) lives in the
|
|
15
|
-
* SHARED `materialized_tenant_credit_bills` collection, so these documents carry no
|
|
16
|
-
* bill rows/ids and their size no longer grows with the ledger over time.
|
|
17
|
-
* Iteration history (every structural write's full post-write snapshot)
|
|
18
|
-
* lives in the shared `materialized_tenant_reports_iterations` collection.
|
|
19
|
-
*/
|
|
20
|
-
/**
|
|
21
|
-
* Version of the key grammar + metric rules of this collection. Bump when
|
|
22
|
-
* `sale_type_key_filters`, their order, or metric semantics change —
|
|
23
|
-
* historical documents must then be re-materialized (readers may branch on
|
|
24
|
-
* this value during a rollout). PRE-RELEASE: the collection has no live
|
|
25
|
-
* tenants/consumers yet, so every change so far folds into version `1`.
|
|
26
|
-
*/
|
|
27
|
-
export declare const MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_SCHEMA_VERSION = 1;
|
|
28
4
|
export declare const MaterializedTenantSalesOverviewReportSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
29
5
|
timestamps: true;
|
|
30
6
|
versionKey: false;
|
|
@@ -40,12 +16,12 @@ export declare const MaterializedTenantSalesOverviewReportSchema: Schema<any, im
|
|
|
40
16
|
tenant_id: string;
|
|
41
17
|
day_index: import("../../constants").DAY_INDEX_ENUM | null;
|
|
42
18
|
iteration: number;
|
|
43
|
-
scope_context: import("../../constants").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
44
|
-
scope_field: string;
|
|
45
|
-
sale_type_key_filters: string[];
|
|
46
19
|
schema_version: number;
|
|
47
20
|
source_watermark: NativeDate;
|
|
48
21
|
computed_at: NativeDate;
|
|
22
|
+
scope_context: import("../../constants").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
23
|
+
scope_field: string;
|
|
24
|
+
sale_type_key_filters: string[];
|
|
49
25
|
sale_type_metrics: Map<string, {
|
|
50
26
|
TOTAL_SALES: {
|
|
51
27
|
orders: {
|
|
@@ -156,12 +132,12 @@ export declare const MaterializedTenantSalesOverviewReportSchema: Schema<any, im
|
|
|
156
132
|
tenant_id: string;
|
|
157
133
|
day_index: import("../../constants").DAY_INDEX_ENUM | null;
|
|
158
134
|
iteration: number;
|
|
159
|
-
scope_context: import("../../constants").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
160
|
-
scope_field: string;
|
|
161
|
-
sale_type_key_filters: string[];
|
|
162
135
|
schema_version: number;
|
|
163
136
|
source_watermark: NativeDate;
|
|
164
137
|
computed_at: NativeDate;
|
|
138
|
+
scope_context: import("../../constants").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
139
|
+
scope_field: string;
|
|
140
|
+
sale_type_key_filters: string[];
|
|
165
141
|
sale_type_metrics: Map<string, {
|
|
166
142
|
TOTAL_SALES: {
|
|
167
143
|
orders: {
|
|
@@ -272,12 +248,12 @@ export declare const MaterializedTenantSalesOverviewReportSchema: Schema<any, im
|
|
|
272
248
|
tenant_id: string;
|
|
273
249
|
day_index: import("../../constants").DAY_INDEX_ENUM | null;
|
|
274
250
|
iteration: number;
|
|
275
|
-
scope_context: import("../../constants").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
276
|
-
scope_field: string;
|
|
277
|
-
sale_type_key_filters: string[];
|
|
278
251
|
schema_version: number;
|
|
279
252
|
source_watermark: NativeDate;
|
|
280
253
|
computed_at: NativeDate;
|
|
254
|
+
scope_context: import("../../constants").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
255
|
+
scope_field: string;
|
|
256
|
+
sale_type_key_filters: string[];
|
|
281
257
|
sale_type_metrics: Map<string, {
|
|
282
258
|
TOTAL_SALES: {
|
|
283
259
|
orders: {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_INDEX_OPTIONS = exports.MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_COLLECTION_INDEXES = exports.MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_COLLECTION_NAME = exports.MaterializedTenantSalesOverviewReportSchema = exports.MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_SCHEMA_VERSION = void 0;
|
|
4
|
+
const MATERIALIZED_SCHEMA_VERSIONS_1 = require("../../constants/MATERIALIZED_SCHEMA_VERSIONS");
|
|
5
|
+
Object.defineProperty(exports, "MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_SCHEMA_VERSION", { enumerable: true, get: function () { return MATERIALIZED_SCHEMA_VERSIONS_1.MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_SCHEMA_VERSION; } });
|
|
4
6
|
const mongoose_1 = require("mongoose");
|
|
5
7
|
const constants_1 = require("../../constants");
|
|
6
8
|
const ENUMS_1 = require("../../constants/ENUMS");
|
|
@@ -30,7 +32,6 @@ const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
|
30
32
|
* this value during a rollout). PRE-RELEASE: the collection has no live
|
|
31
33
|
* tenants/consumers yet, so every change so far folds into version `1`.
|
|
32
34
|
*/
|
|
33
|
-
exports.MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_SCHEMA_VERSION = 1;
|
|
34
35
|
const ReportDiscountByTypeSchema = new mongoose_1.Schema({
|
|
35
36
|
special_discount: {
|
|
36
37
|
type: Number, // cents — Σ order_discount_details.special_discount
|
|
@@ -261,7 +262,7 @@ exports.MaterializedTenantSalesOverviewReportSchema = new mongoose_1.Schema({
|
|
|
261
262
|
type: Number,
|
|
262
263
|
required: true,
|
|
263
264
|
immutable: true,
|
|
264
|
-
default:
|
|
265
|
+
default: MATERIALIZED_SCHEMA_VERSIONS_1.MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_SCHEMA_VERSION,
|
|
265
266
|
},
|
|
266
267
|
source_watermark: {
|
|
267
268
|
type: mongoose_1.Schema.Types.Date,
|
|
@@ -14,12 +14,15 @@ export declare const TenantActiveJobSchema: Schema<any, import("mongoose").Model
|
|
|
14
14
|
tenant_id: string;
|
|
15
15
|
progress: number;
|
|
16
16
|
completed_at: NativeDate;
|
|
17
|
+
started_at: NativeDate;
|
|
17
18
|
jobs_status: Map<string, boolean>;
|
|
18
19
|
active_job: import("../../constants").TENANT_ACTIVE_JOBS_ENUM;
|
|
19
20
|
failed_jobs: string[];
|
|
20
|
-
started_at: NativeDate;
|
|
21
21
|
last_heartbeat_at: NativeDate;
|
|
22
22
|
lease_id?: string | null | undefined;
|
|
23
|
+
current_report_key?: string | null | undefined;
|
|
24
|
+
current_report_progress?: number | null | undefined;
|
|
25
|
+
outcome?: import("../../constants").TENANT_DAY_JOB_OUTCOME_ENUM | null | undefined;
|
|
23
26
|
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
24
27
|
createdAt: NativeDate;
|
|
25
28
|
updatedAt: NativeDate;
|
|
@@ -31,12 +34,15 @@ export declare const TenantActiveJobSchema: Schema<any, import("mongoose").Model
|
|
|
31
34
|
tenant_id: string;
|
|
32
35
|
progress: number;
|
|
33
36
|
completed_at: NativeDate;
|
|
37
|
+
started_at: NativeDate;
|
|
34
38
|
jobs_status: Map<string, boolean>;
|
|
35
39
|
active_job: import("../../constants").TENANT_ACTIVE_JOBS_ENUM;
|
|
36
40
|
failed_jobs: string[];
|
|
37
|
-
started_at: NativeDate;
|
|
38
41
|
last_heartbeat_at: NativeDate;
|
|
39
42
|
lease_id?: string | null | undefined;
|
|
43
|
+
current_report_key?: string | null | undefined;
|
|
44
|
+
current_report_progress?: number | null | undefined;
|
|
45
|
+
outcome?: import("../../constants").TENANT_DAY_JOB_OUTCOME_ENUM | null | undefined;
|
|
40
46
|
}>> & import("mongoose").FlatRecord<{
|
|
41
47
|
createdAt: NativeDate;
|
|
42
48
|
updatedAt: NativeDate;
|
|
@@ -48,12 +54,15 @@ export declare const TenantActiveJobSchema: Schema<any, import("mongoose").Model
|
|
|
48
54
|
tenant_id: string;
|
|
49
55
|
progress: number;
|
|
50
56
|
completed_at: NativeDate;
|
|
57
|
+
started_at: NativeDate;
|
|
51
58
|
jobs_status: Map<string, boolean>;
|
|
52
59
|
active_job: import("../../constants").TENANT_ACTIVE_JOBS_ENUM;
|
|
53
60
|
failed_jobs: string[];
|
|
54
|
-
started_at: NativeDate;
|
|
55
61
|
last_heartbeat_at: NativeDate;
|
|
56
62
|
lease_id?: string | null | undefined;
|
|
63
|
+
current_report_key?: string | null | undefined;
|
|
64
|
+
current_report_progress?: number | null | undefined;
|
|
65
|
+
outcome?: import("../../constants").TENANT_DAY_JOB_OUTCOME_ENUM | null | undefined;
|
|
57
66
|
}> & Required<{
|
|
58
67
|
_id: import("mongoose").Types.ObjectId;
|
|
59
68
|
}> & {
|
|
@@ -47,6 +47,24 @@ exports.TenantActiveJobSchema = new mongoose_1.Schema({
|
|
|
47
47
|
type: Number,
|
|
48
48
|
default: 0,
|
|
49
49
|
},
|
|
50
|
+
// Per-report progress of the current run (Phase 1 per-report model).
|
|
51
|
+
current_report_key: {
|
|
52
|
+
type: String,
|
|
53
|
+
required: false,
|
|
54
|
+
default: null,
|
|
55
|
+
},
|
|
56
|
+
current_report_progress: {
|
|
57
|
+
type: Number,
|
|
58
|
+
required: false,
|
|
59
|
+
default: 0,
|
|
60
|
+
},
|
|
61
|
+
// Terminal outcome of the last run: COMPLETED | PARTIAL | FAILED.
|
|
62
|
+
outcome: {
|
|
63
|
+
type: String,
|
|
64
|
+
enum: [...constants_1.ALL_TENANT_DAY_JOB_OUTCOMES, null],
|
|
65
|
+
required: false,
|
|
66
|
+
default: null,
|
|
67
|
+
},
|
|
50
68
|
started_at: {
|
|
51
69
|
type: mongoose_1.Schema.Types.Date,
|
|
52
70
|
default: null,
|
|
@@ -53,6 +53,7 @@ export * from './materialized_tenant_payments_comparison_entries';
|
|
|
53
53
|
export * from './materialized_tenant_payments_comparison_reports';
|
|
54
54
|
export * from './materialized_tenant_prep_time_entries';
|
|
55
55
|
export * from './materialized_tenant_prep_time_reports';
|
|
56
|
+
export * from './materialized_tenant_report_runs';
|
|
56
57
|
export * from './materialized_tenant_reports_iterations';
|
|
57
58
|
export * from './materialized_tenant_sales_comparison_entries';
|
|
58
59
|
export * from './materialized_tenant_sales_comparison_reports';
|
|
@@ -69,6 +69,7 @@ __exportStar(require("./materialized_tenant_payments_comparison_entries"), expor
|
|
|
69
69
|
__exportStar(require("./materialized_tenant_payments_comparison_reports"), exports);
|
|
70
70
|
__exportStar(require("./materialized_tenant_prep_time_entries"), exports);
|
|
71
71
|
__exportStar(require("./materialized_tenant_prep_time_reports"), exports);
|
|
72
|
+
__exportStar(require("./materialized_tenant_report_runs"), exports);
|
|
72
73
|
__exportStar(require("./materialized_tenant_reports_iterations"), exports);
|
|
73
74
|
__exportStar(require("./materialized_tenant_sales_comparison_entries"), exports);
|
|
74
75
|
__exportStar(require("./materialized_tenant_sales_comparison_reports"), exports);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM, type TMaterializedReadinessReportKey } from '../../constants/MATERIALIZED_REPORTS';
|
|
2
|
+
/**
|
|
3
|
+
* One OPERATIONAL run row per
|
|
4
|
+
* `(tenant_id, localDate, report_key, schema_version)`.
|
|
5
|
+
*
|
|
6
|
+
* This is the durable execution ledger of the per-report materialization model
|
|
7
|
+
* (Phase 1 of END_TENANT_DAY): every report runs in ITS OWN transaction and
|
|
8
|
+
* commits or fails on its own. Readiness (`materialized_tenant_day_readiness`)
|
|
9
|
+
* stays the read gate and keeps only COMMITTED / NEEDS_RECONCILIATION; a failed
|
|
10
|
+
* report is visible HERE and nowhere else.
|
|
11
|
+
*
|
|
12
|
+
* Lifecycle:
|
|
13
|
+
* - `PENDING` row created before the first attempt (optional);
|
|
14
|
+
* - `RUNNING` an attempt is executing (`attempts` = attempts started);
|
|
15
|
+
* - `RETRYING` a TRANSIENT failure happened and another attempt is starting;
|
|
16
|
+
* - `COMMITTED` the report transaction committed (documents + readiness);
|
|
17
|
+
* - `FAILED` every allowed attempt was exhausted (`last_error` is set,
|
|
18
|
+
* readiness was NOT written).
|
|
19
|
+
*
|
|
20
|
+
* The row is operational state: it is written OUTSIDE the report transaction so
|
|
21
|
+
* a rollback cannot erase the failed attempt.
|
|
22
|
+
*/
|
|
23
|
+
export interface IMaterializedTenantReportRun {
|
|
24
|
+
tenant_id: string;
|
|
25
|
+
/** Tenant-local business day, `YYYY-MM-DD`. */
|
|
26
|
+
localDate: string;
|
|
27
|
+
/** One of the SIX production report keys; never an out-of-scope report. */
|
|
28
|
+
report_key: TMaterializedReadinessReportKey | string;
|
|
29
|
+
/** Pinned run-ledger contract version (1). */
|
|
30
|
+
schema_version: number;
|
|
31
|
+
status: MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM;
|
|
32
|
+
/**
|
|
33
|
+
* Number of attempts STARTED by the LATEST execution (manual retry resets
|
|
34
|
+
* this to 1). The admin page shows it as "attempts this run".
|
|
35
|
+
*/
|
|
36
|
+
attempts: number;
|
|
37
|
+
/**
|
|
38
|
+
* LIFETIME attempts across every manual retry of this report identity.
|
|
39
|
+
* Never reset by a retry, so failure history is never silently lost.
|
|
40
|
+
*/
|
|
41
|
+
total_attempts: number;
|
|
42
|
+
/**
|
|
43
|
+
* PII-REDACTED, single-line, bounded explanation of the last failure.
|
|
44
|
+
* `null` while no attempt failed.
|
|
45
|
+
*/
|
|
46
|
+
last_error: string | null;
|
|
47
|
+
/** Identity of the run that most recently owned this report (lease/run id). */
|
|
48
|
+
run_id: string | null;
|
|
49
|
+
/** When the latest execution started (first attempt). */
|
|
50
|
+
started_at: Date | null;
|
|
51
|
+
/** When the latest execution reached COMMITTED or FAILED. */
|
|
52
|
+
finished_at: Date | null;
|
|
53
|
+
createdAt: Date;
|
|
54
|
+
updatedAt: Date;
|
|
55
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TENANT_ACTIVE_JOBS_ENUM } from '../../constants';
|
|
1
|
+
import { TENANT_ACTIVE_JOBS_ENUM, TENANT_DAY_JOB_OUTCOME_ENUM } from '../../constants';
|
|
2
2
|
export interface ITenantActiveJob {
|
|
3
3
|
_id: string;
|
|
4
4
|
tenant_id: string;
|
|
@@ -15,6 +15,20 @@ export interface ITenantActiveJob {
|
|
|
15
15
|
lease_id?: string | null;
|
|
16
16
|
failed_jobs: TENANT_ACTIVE_JOBS_ENUM[];
|
|
17
17
|
progress: number;
|
|
18
|
+
/**
|
|
19
|
+
* The report the current close/retry run is executing (PENDING -> COMMITTED
|
|
20
|
+
* in the report run ledger order). `null` when no report is in flight.
|
|
21
|
+
*/
|
|
22
|
+
current_report_key?: string | null;
|
|
23
|
+
/** 0–100 progress INSIDE `current_report_key`. */
|
|
24
|
+
current_report_progress?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Terminal outcome of the last run that owned the job: COMPLETED when every
|
|
27
|
+
* report committed, PARTIAL when at least one report FAILED (it stays
|
|
28
|
+
* retryable through the run ledger), FAILED when the run itself failed before
|
|
29
|
+
* any report work could be committed. `null` while a run is active.
|
|
30
|
+
*/
|
|
31
|
+
outcome?: TENANT_DAY_JOB_OUTCOME_ENUM | null;
|
|
18
32
|
started_at: Date | null;
|
|
19
33
|
completed_at: Date | null;
|
|
20
34
|
last_heartbeat_at: Date | null;
|