@managesome/eposmatic-toolkit 0.4.60 → 0.4.62

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 (96) hide show
  1. package/esm/constants/MATERIALIZED_REPORTS.js +254 -4
  2. package/esm/constants/TENANT_ENUMS.js +15 -0
  3. package/esm/constants/WORKER_ENDPOINTS.js +12 -0
  4. package/esm/helpers/materialized-reports/index.js +8 -0
  5. package/esm/helpers/materialized-reports/materialized-day-readiness.js +2 -2
  6. package/esm/helpers/materialized-reports/materialized-dinein-accumulator-helpers.js +557 -0
  7. package/esm/helpers/materialized-reports/materialized-dinein-classification-helpers.js +447 -0
  8. package/esm/helpers/materialized-reports/materialized-dinein-close-day-helpers.js +372 -0
  9. package/esm/helpers/materialized-reports/materialized-dinein-compile-helpers.js +500 -0
  10. package/esm/helpers/materialized-reports/materialized-dinein-entry-pages.js +218 -0
  11. package/esm/helpers/materialized-reports/materialized-dinein-key-helpers.js +87 -0
  12. package/esm/helpers/materialized-reports/materialized-index-bootstrap.js +7 -1
  13. package/esm/helpers/materialized-reports/materialized-report-drilldown-rows.js +8 -0
  14. package/esm/helpers/materialized-reports/materialized-report-runs.js +143 -0
  15. package/esm/helpers/materialized-reports/report-platform/definition.js +93 -1
  16. package/esm/helpers/materialized-reports/tenant-dinein-formatter.js +240 -0
  17. package/esm/helpers/reporting-contract/report-contract.js +3 -0
  18. package/esm/schemas/models/index.js +3 -0
  19. package/esm/schemas/models/materialized_tenant_dinein_entries.js +57 -0
  20. package/esm/schemas/models/materialized_tenant_dinein_reports.js +73 -0
  21. package/esm/schemas/models/materialized_tenant_report_runs.js +105 -0
  22. package/esm/schemas/models/tenant_active_jobs.js +19 -1
  23. package/esm/schemas/types/index.js +3 -0
  24. package/esm/schemas/types/materialized_report_drilldown_rows.js +1 -0
  25. package/esm/schemas/types/materialized_tenant_dinein_entries.js +1 -0
  26. package/esm/schemas/types/materialized_tenant_dinein_reports.js +6 -0
  27. package/esm/schemas/types/materialized_tenant_report_runs.js +1 -0
  28. package/lib/constants/MATERIALIZED_REPORTS.d.ts +229 -4
  29. package/lib/constants/MATERIALIZED_REPORTS.js +255 -5
  30. package/lib/constants/TENANT_ENUMS.d.ts +14 -0
  31. package/lib/constants/TENANT_ENUMS.js +16 -1
  32. package/lib/constants/WORKER_ENDPOINTS.d.ts +12 -0
  33. package/lib/constants/WORKER_ENDPOINTS.js +12 -0
  34. package/lib/helpers/materialized-reports/index.d.ts +8 -0
  35. package/lib/helpers/materialized-reports/index.js +8 -0
  36. package/lib/helpers/materialized-reports/materialized-day-readiness.d.ts +1 -1
  37. package/lib/helpers/materialized-reports/materialized-day-readiness.js +2 -2
  38. package/lib/helpers/materialized-reports/materialized-dinein-accumulator-helpers.d.ts +67 -0
  39. package/lib/helpers/materialized-reports/materialized-dinein-accumulator-helpers.js +582 -0
  40. package/lib/helpers/materialized-reports/materialized-dinein-classification-helpers.d.ts +245 -0
  41. package/lib/helpers/materialized-reports/materialized-dinein-classification-helpers.js +469 -0
  42. package/lib/helpers/materialized-reports/materialized-dinein-close-day-helpers.d.ts +110 -0
  43. package/lib/helpers/materialized-reports/materialized-dinein-close-day-helpers.js +384 -0
  44. package/lib/helpers/materialized-reports/materialized-dinein-compile-helpers.d.ts +73 -0
  45. package/lib/helpers/materialized-reports/materialized-dinein-compile-helpers.js +504 -0
  46. package/lib/helpers/materialized-reports/materialized-dinein-entry-pages.d.ts +69 -0
  47. package/lib/helpers/materialized-reports/materialized-dinein-entry-pages.js +231 -0
  48. package/lib/helpers/materialized-reports/materialized-dinein-key-helpers.d.ts +44 -0
  49. package/lib/helpers/materialized-reports/materialized-dinein-key-helpers.js +96 -0
  50. package/lib/helpers/materialized-reports/materialized-index-bootstrap.js +6 -0
  51. package/lib/helpers/materialized-reports/materialized-report-drilldown-rows.js +8 -0
  52. package/lib/helpers/materialized-reports/materialized-report-runs.d.ts +105 -0
  53. package/lib/helpers/materialized-reports/materialized-report-runs.js +156 -0
  54. package/lib/helpers/materialized-reports/report-platform/definition.js +92 -0
  55. package/lib/helpers/materialized-reports/tenant-dinein-formatter.d.ts +225 -0
  56. package/lib/helpers/materialized-reports/tenant-dinein-formatter.js +243 -0
  57. package/lib/helpers/reporting-contract/report-contract.d.ts +1 -0
  58. package/lib/helpers/reporting-contract/report-contract.js +3 -0
  59. package/lib/helpers/types/workers.d.ts +65 -0
  60. package/lib/schemas/models/index.d.ts +3 -0
  61. package/lib/schemas/models/index.js +3 -0
  62. package/lib/schemas/models/materialized_tenant_day_readiness.d.ts +3 -3
  63. package/lib/schemas/models/materialized_tenant_dinein_entries.d.ts +100 -0
  64. package/lib/schemas/models/materialized_tenant_dinein_entries.js +60 -0
  65. package/lib/schemas/models/materialized_tenant_dinein_reports.d.ts +111 -0
  66. package/lib/schemas/models/materialized_tenant_dinein_reports.js +76 -0
  67. package/lib/schemas/models/materialized_tenant_report_runs.d.ts +97 -0
  68. package/lib/schemas/models/materialized_tenant_report_runs.js +108 -0
  69. package/lib/schemas/models/tenant_active_jobs.d.ts +12 -3
  70. package/lib/schemas/models/tenant_active_jobs.js +18 -0
  71. package/lib/schemas/types/index.d.ts +3 -0
  72. package/lib/schemas/types/index.js +3 -0
  73. package/lib/schemas/types/materialized_report_drilldown_rows.d.ts +1 -1
  74. package/lib/schemas/types/materialized_report_drilldown_rows.js +1 -0
  75. package/lib/schemas/types/materialized_tenant_dinein_entries.d.ts +127 -0
  76. package/lib/schemas/types/materialized_tenant_dinein_entries.js +2 -0
  77. package/lib/schemas/types/materialized_tenant_dinein_reports.d.ts +326 -0
  78. package/lib/schemas/types/materialized_tenant_dinein_reports.js +9 -0
  79. package/lib/schemas/types/materialized_tenant_report_runs.d.ts +55 -0
  80. package/lib/schemas/types/materialized_tenant_report_runs.js +2 -0
  81. package/lib/schemas/types/tenant_active_jobs.d.ts +15 -1
  82. package/lib/tests/materialized-reports/dinein-fixtures.d.ts +29 -0
  83. package/lib/tests/materialized-reports/dinein-fixtures.js +130 -0
  84. package/lib/tests/materialized-reports/materialized-day-readiness.test.js +3 -2
  85. package/lib/tests/materialized-reports/materialized-dinein-compile.test.d.ts +1 -0
  86. package/lib/tests/materialized-reports/materialized-dinein-compile.test.js +807 -0
  87. package/lib/tests/materialized-reports/materialized-dinein-plan.test.d.ts +1 -0
  88. package/lib/tests/materialized-reports/materialized-dinein-plan.test.js +419 -0
  89. package/lib/tests/materialized-reports/materialized-report-runs.test.d.ts +1 -0
  90. package/lib/tests/materialized-reports/materialized-report-runs.test.js +116 -0
  91. package/lib/tests/materialized-reports/materialized-tenant-dinein-schema.test.d.ts +1 -0
  92. package/lib/tests/materialized-reports/materialized-tenant-dinein-schema.test.js +185 -0
  93. package/lib/tests/materialized-reports/report-platform/registry-conformance.test.js +15 -2
  94. package/lib/tests/materialized-reports/tenant-dinein-formatter.test.d.ts +1 -0
  95. package/lib/tests/materialized-reports/tenant-dinein-formatter.test.js +458 -0
  96. package/package.json +1 -1
@@ -0,0 +1,111 @@
1
+ import { Schema } from 'mongoose';
2
+ /**
3
+ * Mongoose schema for `materialized_tenant_dinein_reports`.
4
+ *
5
+ * `dinein_counters` is `Mixed` on purpose: it is a key-addressed map of bounded
6
+ * counter blocks (`<ORDER_STATUS>:<PLATFORM>` → counters + bounded dimension
7
+ * maps), and the keys ARE the data — Mongoose cannot type them without a fixed
8
+ * key set. `reservation_counters` is a DOCUMENT-level block because a
9
+ * reservation has no order and must survive any order-status/platform filter.
10
+ *
11
+ * The collection holds COUNTERS only. Itemized check rows live in the sibling
12
+ * `materialized_tenant_dinein_entries` collection (one page per source day).
13
+ */
14
+ /** Document shape version. Bump on a key-grammar/metric change + backfill. */
15
+ export declare const MATERIALIZED_TENANT_DINEIN_REPORTS_SCHEMA_VERSION = 1;
16
+ export declare const MaterializedTenantDineinReportSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
17
+ timestamps: true;
18
+ versionKey: false;
19
+ minimize: false;
20
+ }, {
21
+ createdAt: NativeDate;
22
+ updatedAt: NativeDate;
23
+ } & {
24
+ createdAt: NativeDate;
25
+ updatedAt: NativeDate;
26
+ brand_id: string;
27
+ tenant_id: string;
28
+ day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
29
+ iteration: number;
30
+ scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
31
+ scope_field: string;
32
+ sale_type_key_filters: string[];
33
+ schema_version: number;
34
+ source_watermark: NativeDate;
35
+ computed_at: NativeDate;
36
+ dinein_counters: any;
37
+ reservation_counters: any;
38
+ upcoming_reservations: any;
39
+ top_edited_checks: any;
40
+ }, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
41
+ createdAt: NativeDate;
42
+ updatedAt: NativeDate;
43
+ } & {
44
+ createdAt: NativeDate;
45
+ updatedAt: NativeDate;
46
+ brand_id: string;
47
+ tenant_id: string;
48
+ day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
49
+ iteration: number;
50
+ scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
51
+ scope_field: string;
52
+ sale_type_key_filters: string[];
53
+ schema_version: number;
54
+ source_watermark: NativeDate;
55
+ computed_at: NativeDate;
56
+ dinein_counters: any;
57
+ reservation_counters: any;
58
+ upcoming_reservations: any;
59
+ top_edited_checks: any;
60
+ }>> & import("mongoose").FlatRecord<{
61
+ createdAt: NativeDate;
62
+ updatedAt: NativeDate;
63
+ } & {
64
+ createdAt: NativeDate;
65
+ updatedAt: NativeDate;
66
+ brand_id: string;
67
+ tenant_id: string;
68
+ day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
69
+ iteration: number;
70
+ scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
71
+ scope_field: string;
72
+ sale_type_key_filters: string[];
73
+ schema_version: number;
74
+ source_watermark: NativeDate;
75
+ computed_at: NativeDate;
76
+ dinein_counters: any;
77
+ reservation_counters: any;
78
+ upcoming_reservations: any;
79
+ top_edited_checks: any;
80
+ }> & {
81
+ _id: import("mongoose").Types.ObjectId;
82
+ } & {
83
+ __v: number;
84
+ }>;
85
+ export declare const MATERIALIZED_TENANT_DINEIN_REPORTS_COLLECTION_NAME = "materialized_tenant_dinein_reports";
86
+ /**
87
+ * The single UNIQUE compound identity index, like every materialized report
88
+ * collection. Declared ONLY — no service calls `index()` or `ensureIndexes`, and
89
+ * the services run with `autoIndex: false`. Applying it is an owner deploy step.
90
+ */
91
+ export declare const MATERIALIZED_TENANT_DINEIN_REPORTS_COLLECTION_INDEXES: {
92
+ _id: {
93
+ _id: number;
94
+ };
95
+ tenant_id__scope_context__scope_field__day_index: {
96
+ tenant_id: number;
97
+ scope_context: number;
98
+ scope_field: number;
99
+ day_index: number;
100
+ };
101
+ };
102
+ export declare const MATERIALIZED_TENANT_DINEIN_REPORTS_INDEX_OPTIONS: {
103
+ key: {
104
+ tenant_id: number;
105
+ scope_context: number;
106
+ scope_field: number;
107
+ day_index: number;
108
+ };
109
+ name: string;
110
+ unique: boolean;
111
+ }[];
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MATERIALIZED_TENANT_DINEIN_REPORTS_INDEX_OPTIONS = exports.MATERIALIZED_TENANT_DINEIN_REPORTS_COLLECTION_INDEXES = exports.MATERIALIZED_TENANT_DINEIN_REPORTS_COLLECTION_NAME = exports.MaterializedTenantDineinReportSchema = exports.MATERIALIZED_TENANT_DINEIN_REPORTS_SCHEMA_VERSION = void 0;
4
+ const mongoose_1 = require("mongoose");
5
+ const ENUMS_1 = require("../../constants/ENUMS");
6
+ const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
7
+ /**
8
+ * Mongoose schema for `materialized_tenant_dinein_reports`.
9
+ *
10
+ * `dinein_counters` is `Mixed` on purpose: it is a key-addressed map of bounded
11
+ * counter blocks (`<ORDER_STATUS>:<PLATFORM>` → counters + bounded dimension
12
+ * maps), and the keys ARE the data — Mongoose cannot type them without a fixed
13
+ * key set. `reservation_counters` is a DOCUMENT-level block because a
14
+ * reservation has no order and must survive any order-status/platform filter.
15
+ *
16
+ * The collection holds COUNTERS only. Itemized check rows live in the sibling
17
+ * `materialized_tenant_dinein_entries` collection (one page per source day).
18
+ */
19
+ /** Document shape version. Bump on a key-grammar/metric change + backfill. */
20
+ exports.MATERIALIZED_TENANT_DINEIN_REPORTS_SCHEMA_VERSION = 1;
21
+ exports.MaterializedTenantDineinReportSchema = new mongoose_1.Schema({
22
+ tenant_id: { type: String, required: true },
23
+ brand_id: { type: String, required: true },
24
+ scope_context: { type: String, required: true, enum: MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_REPORT_SCOPES },
25
+ scope_field: { type: String, required: true },
26
+ day_index: { type: String, default: null, enum: [...ENUMS_1.ALL_DAY_INDEX, null] },
27
+ sale_type_key_filters: {
28
+ type: [String],
29
+ required: true,
30
+ default: () => [...MATERIALIZED_REPORTS_1.DINEIN_KEY_FILTERS],
31
+ validate: {
32
+ validator: (value) => value.length > 0 &&
33
+ value.every((entry) => MATERIALIZED_REPORTS_1.ALL_MATERIALIZED_REPORT_KEY_FILTERS.includes(entry)),
34
+ message: 'sale_type_key_filters must be a non-empty subset of the known key filters',
35
+ },
36
+ },
37
+ dinein_counters: { type: mongoose_1.Schema.Types.Mixed, required: true, default: null },
38
+ reservation_counters: { type: mongoose_1.Schema.Types.Mixed, required: true, default: null },
39
+ // Bounded, masked display snapshots. `Mixed` for the same reason as the
40
+ // counters: the arrays are written whole and never queried element-wise.
41
+ upcoming_reservations: { type: mongoose_1.Schema.Types.Mixed, default: null },
42
+ top_edited_checks: { type: mongoose_1.Schema.Types.Mixed, default: null },
43
+ iteration: { type: Number, required: true, min: 1, default: 1 },
44
+ schema_version: {
45
+ type: Number,
46
+ required: true,
47
+ immutable: true,
48
+ default: exports.MATERIALIZED_TENANT_DINEIN_REPORTS_SCHEMA_VERSION,
49
+ },
50
+ source_watermark: { type: mongoose_1.Schema.Types.Date, required: true },
51
+ computed_at: { type: mongoose_1.Schema.Types.Date, required: true },
52
+ createdAt: { type: mongoose_1.Schema.Types.Date, required: true, default: () => new Date(), immutable: true },
53
+ updatedAt: { type: mongoose_1.Schema.Types.Date, required: true, default: () => new Date() },
54
+ }, { timestamps: true, versionKey: false, minimize: false });
55
+ exports.MATERIALIZED_TENANT_DINEIN_REPORTS_COLLECTION_NAME = 'materialized_tenant_dinein_reports';
56
+ /**
57
+ * The single UNIQUE compound identity index, like every materialized report
58
+ * collection. Declared ONLY — no service calls `index()` or `ensureIndexes`, and
59
+ * the services run with `autoIndex: false`. Applying it is an owner deploy step.
60
+ */
61
+ exports.MATERIALIZED_TENANT_DINEIN_REPORTS_COLLECTION_INDEXES = {
62
+ _id: { _id: 1 },
63
+ tenant_id__scope_context__scope_field__day_index: {
64
+ tenant_id: 1,
65
+ scope_context: 1,
66
+ scope_field: 1,
67
+ day_index: 1,
68
+ },
69
+ };
70
+ exports.MATERIALIZED_TENANT_DINEIN_REPORTS_INDEX_OPTIONS = [
71
+ {
72
+ key: { tenant_id: 1, scope_context: 1, scope_field: 1, day_index: 1 },
73
+ name: 'tenant_id__scope_context__scope_field__day_index',
74
+ unique: true,
75
+ },
76
+ ];
@@ -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
+ ];
@@ -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,
@@ -44,6 +44,8 @@ export * from './materialized_tenant_discount_entries';
44
44
  export * from './materialized_tenant_discount_reports';
45
45
  export * from './materialized_tenant_dialer_entries';
46
46
  export * from './materialized_tenant_dialer_reports';
47
+ export * from './materialized_tenant_dinein_entries';
48
+ export * from './materialized_tenant_dinein_reports';
47
49
  export * from './materialized_tenant_discount_sources';
48
50
  export * from './materialized_tenant_hourly_comparison_entries';
49
51
  export * from './materialized_tenant_hourly_comparison_reports';
@@ -51,6 +53,7 @@ export * from './materialized_tenant_payments_comparison_entries';
51
53
  export * from './materialized_tenant_payments_comparison_reports';
52
54
  export * from './materialized_tenant_prep_time_entries';
53
55
  export * from './materialized_tenant_prep_time_reports';
56
+ export * from './materialized_tenant_report_runs';
54
57
  export * from './materialized_tenant_reports_iterations';
55
58
  export * from './materialized_tenant_sales_comparison_entries';
56
59
  export * from './materialized_tenant_sales_comparison_reports';
@@ -60,6 +60,8 @@ __exportStar(require("./materialized_tenant_discount_entries"), exports);
60
60
  __exportStar(require("./materialized_tenant_discount_reports"), exports);
61
61
  __exportStar(require("./materialized_tenant_dialer_entries"), exports);
62
62
  __exportStar(require("./materialized_tenant_dialer_reports"), exports);
63
+ __exportStar(require("./materialized_tenant_dinein_entries"), exports);
64
+ __exportStar(require("./materialized_tenant_dinein_reports"), exports);
63
65
  __exportStar(require("./materialized_tenant_discount_sources"), exports);
64
66
  __exportStar(require("./materialized_tenant_hourly_comparison_entries"), exports);
65
67
  __exportStar(require("./materialized_tenant_hourly_comparison_reports"), exports);
@@ -67,6 +69,7 @@ __exportStar(require("./materialized_tenant_payments_comparison_entries"), expor
67
69
  __exportStar(require("./materialized_tenant_payments_comparison_reports"), exports);
68
70
  __exportStar(require("./materialized_tenant_prep_time_entries"), exports);
69
71
  __exportStar(require("./materialized_tenant_prep_time_reports"), exports);
72
+ __exportStar(require("./materialized_tenant_report_runs"), exports);
70
73
  __exportStar(require("./materialized_tenant_reports_iterations"), exports);
71
74
  __exportStar(require("./materialized_tenant_sales_comparison_entries"), exports);
72
75
  __exportStar(require("./materialized_tenant_sales_comparison_reports"), exports);
@@ -13,7 +13,7 @@ import { MATERIALIZED_REPORT_SCOPE_ENUM, MATERIALIZED_REPORT_TYPE_ENUM } from '.
13
13
  * fields a page query needs: selection identity, sort anchor, and cursor
14
14
  * tie-break.
15
15
  */
16
- export type TDrilldownReportType = MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DISCOUNT_ENTRIES | MATERIALIZED_REPORT_TYPE_ENUM.TENANT_PREP_TIME_ENTRIES | MATERIALIZED_REPORT_TYPE_ENUM.TENANT_CASH_ENTRIES | MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DELIVERY_ENTRIES | MATERIALIZED_REPORT_TYPE_ENUM.TENANT_SALES_COMPARISON_ENTRIES | MATERIALIZED_REPORT_TYPE_ENUM.TENANT_HOURLY_COMPARISON_ENTRIES | MATERIALIZED_REPORT_TYPE_ENUM.TENANT_PAYMENTS_COMPARISON_ENTRIES | MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DIALER_ENTRIES;
16
+ export type TDrilldownReportType = MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DISCOUNT_ENTRIES | MATERIALIZED_REPORT_TYPE_ENUM.TENANT_PREP_TIME_ENTRIES | MATERIALIZED_REPORT_TYPE_ENUM.TENANT_CASH_ENTRIES | MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DELIVERY_ENTRIES | MATERIALIZED_REPORT_TYPE_ENUM.TENANT_SALES_COMPARISON_ENTRIES | MATERIALIZED_REPORT_TYPE_ENUM.TENANT_HOURLY_COMPARISON_ENTRIES | MATERIALIZED_REPORT_TYPE_ENUM.TENANT_PAYMENTS_COMPARISON_ENTRIES | MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DIALER_ENTRIES | MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DINEIN_ENTRIES;
17
17
  export declare const ALL_DRILLDOWN_REPORT_TYPES: TDrilldownReportType[];
18
18
  /** One flattened itemized row. */
19
19
  export interface IMaterializedReportDrilldownRow {
@@ -11,4 +11,5 @@ exports.ALL_DRILLDOWN_REPORT_TYPES = [
11
11
  MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_HOURLY_COMPARISON_ENTRIES,
12
12
  MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_PAYMENTS_COMPARISON_ENTRIES,
13
13
  MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DIALER_ENTRIES,
14
+ MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DINEIN_ENTRIES,
14
15
  ];
@@ -0,0 +1,127 @@
1
+ import { DAY_INDEX_ENUM } from '../../constants/ENUMS';
2
+ import { MATERIALIZED_REPORT_SCOPE_ENUM } from '../../constants/MATERIALIZED_REPORTS';
3
+ /**
4
+ * Types for `materialized_tenant_dinein_entries`.
5
+ *
6
+ * ## One page per source day
7
+ *
8
+ * | scope | page |
9
+ * | --- | --- |
10
+ * | `localDate` | `'all'` (the scope is already one day) |
11
+ * | `localWeek` | `<source localDate>` |
12
+ * | `localWeekOfYear` | `<source localDate>` |
13
+ * | `localMonth` | `<source localDate>` |
14
+ *
15
+ * An oversized page splits into deterministic `page#0`, `page#1`, … sub-pages;
16
+ * the unsuffixed identity is used while the page fits.
17
+ *
18
+ * ## One row per collectable check
19
+ *
20
+ * A split CHILD is its own row and the deleted split PARENT is never a row
21
+ * ("split children are rows; the parent is hidden"). The per-row `covers` is the
22
+ * check's settled fingerprint covers, never the child's `num_of_guests`.
23
+ *
24
+ * ## Privacy
25
+ *
26
+ * A row carries NO customer name, phone or email and NO review text. Only the
27
+ * numeric `rating` is stored, and the review itself is reduced to the
28
+ * document-level `review_count`.
29
+ */
30
+ export interface IDineinEntryRow {
31
+ /** Source order `_id` — the row identity and the keyset cursor tie-break. */
32
+ order_id: string;
33
+ order_number: number | null;
34
+ /** The order's own tenant-local business day. */
35
+ localDate: string;
36
+ /** ISO-8601 instant of the check (`order.createdAt`) — newest-first cursor. */
37
+ time: string;
38
+ table_id: string | null;
39
+ table_name: string | null;
40
+ floor_id: string | null;
41
+ /** Fingerprint covers of the check's settled session; 0 when it had no session. */
42
+ covers: number;
43
+ status: string;
44
+ platform: string;
45
+ /** `POS_DIRECT` | `STAFF_TABLET` | `QR_SELF_ORDER` | `UNKNOWN_ORIGIN`. */
46
+ origin: string;
47
+ /** `split_type` of the split group, or null for a non-split check. */
48
+ split_type: string | null;
49
+ /** `NONE` | `CHILD` — a parent is never a row. */
50
+ split_role: string;
51
+ offline: boolean;
52
+ rating: number | null;
53
+ /** `amount_earned` (cents) — already includes the service charge. */
54
+ sales: number;
55
+ /** `service_fee_amount` (cents) — a COMPONENT of `sales`. */
56
+ service_charge: number;
57
+ items: number;
58
+ /** `iterations.length` — the current order is not an edit. */
59
+ edits: number;
60
+ }
61
+ /** Per-key row section of one entry page. */
62
+ export interface IDineinEntrySection {
63
+ rows: IDineinEntryRow[];
64
+ }
65
+ /** One `materialized_tenant_dinein_entries` PAGE. */
66
+ export interface IMaterializedTenantDineinEntry {
67
+ _id: string;
68
+ tenant_id: string;
69
+ brand_id: string;
70
+ /** One of `MATERIALIZED_DINEIN_ENTRY_SCOPES`. */
71
+ scope_context: MATERIALIZED_REPORT_SCOPE_ENUM;
72
+ scope_field: string;
73
+ /** `'all'` for the day scope; the source `YYYY-MM-DD` for a period scope. */
74
+ page: string;
75
+ /** Denormalized weekday — set ONLY on the `localDate` page. */
76
+ day_index: DAY_INDEX_ENUM | null;
77
+ /** One row section per observed `<ORDER_STATUS>:<PLATFORM>` key. */
78
+ dinein_entries: Record<string, IDineinEntrySection> | null;
79
+ /** Shared materialized-envelope field (structural version of THIS document). */
80
+ iteration?: number;
81
+ schema_version: number;
82
+ source_watermark: Date;
83
+ computed_at: Date;
84
+ createdAt: Date;
85
+ updatedAt: Date;
86
+ }
87
+ /**
88
+ * The explicit COVERAGE GAP counters of one closing day.
89
+ *
90
+ * A missing fingerprint never becomes a fabricated session: the gap is counted
91
+ * here and surfaced by the writer, so "no table sessions" can never be confused
92
+ * with "no dine-in orders".
93
+ */
94
+ export interface IDineinSourceDayCounts {
95
+ /** Dine-in checks folded into this day (children + non-split orders). */
96
+ orders_counted: number;
97
+ /** Dine-in checks that carry ANOTHER business day — never moved into this one. */
98
+ orders_out_of_day: number;
99
+ /** Deleted split parents excluded from sales/order counts. */
100
+ deleted_split_parents_excluded: number;
101
+ /** Ratings inherited from a deleted split parent (counted at most once per group). */
102
+ ratings_from_deleted_parents: number;
103
+ /** Counted checks with NO joined fingerprint: their covers/occupancy are unknown. */
104
+ orders_without_fingerprint: number;
105
+ /** Fingerprint rows supplied for the day. */
106
+ fingerprints_total: number;
107
+ /** Distinct fingerprints joined to a counted check (one = one table session). */
108
+ fingerprints_joined: number;
109
+ /** Duplicate `fingerprint._id` rows dropped (dedupe). */
110
+ fingerprints_duplicate: number;
111
+ /** Fingerprints whose `order_id` is not a counted check of this day. */
112
+ fingerprints_unattached: number;
113
+ /** Fingerprints with no seated start AND no `order.createdAt` fallback. */
114
+ fingerprints_missing_start: number;
115
+ /** Fingerprints with no usable `createdAt` (session end) — session skipped. */
116
+ fingerprints_missing_end: number;
117
+ /** Fingerprints whose seated time is AFTER the close, or otherwise negative. */
118
+ fingerprints_negative_duration: number;
119
+ /** Sessions whose start fell back to `order.createdAt` (missing `start_time`). */
120
+ fingerprints_fallback_start: number;
121
+ /** Reservations folded into this day. */
122
+ reservations_counted: number;
123
+ /** Reservations whose resolved tenant-local day is another day. */
124
+ reservations_out_of_day: number;
125
+ /** Reservations with no usable `reservation_time`. */
126
+ reservations_missing_time: number;
127
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });