@managesome/eposmatic-toolkit 0.4.5 → 0.4.8
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 +33 -0
- package/esm/constants/REPORT_CALENDAR.js +47 -0
- package/esm/constants/index.js +1 -0
- package/esm/helpers/materialized-reports/index.js +2 -0
- package/esm/helpers/materialized-reports/materialized-credit-bills-helpers.js +982 -0
- package/esm/helpers/materialized-reports/materialized-reports-read-helpers.js +1 -76
- package/esm/helpers/materialized-reports/materialized-reports-selection-helpers.js +716 -0
- package/esm/helpers/materialized-reports/tenant-sales-overview-close-day-helpers.js +327 -41
- package/esm/helpers/materialized-reports/tenant-sales-overview-formatter.js +72 -11
- package/esm/helpers/materialized-reports/tenant-sales-overview-helpers.js +118 -235
- package/esm/helpers/types/index.js +1 -0
- package/esm/schemas/models/index.js +1 -0
- package/esm/schemas/models/materialized_credit_bills.js +265 -0
- package/esm/schemas/models/materialized_tenant_reports_iterations.js +13 -0
- package/esm/schemas/models/materialized_tenant_sales_overview_reports.js +39 -97
- package/esm/schemas/types/index.js +1 -0
- package/esm/schemas/types/materialized_credit_bills.js +1 -0
- package/lib/constants/MATERIALIZED_REPORTS.d.ts +28 -2
- package/lib/constants/MATERIALIZED_REPORTS.js +34 -1
- package/lib/constants/REPORT_CALENDAR.d.ts +31 -0
- package/lib/constants/REPORT_CALENDAR.js +50 -0
- package/lib/constants/index.d.ts +1 -0
- package/lib/constants/index.js +1 -0
- package/lib/helpers/materialized-reports/index.d.ts +2 -0
- package/lib/helpers/materialized-reports/index.js +2 -0
- package/lib/helpers/materialized-reports/materialized-credit-bills-helpers.d.ts +307 -0
- package/lib/helpers/materialized-reports/materialized-credit-bills-helpers.js +1003 -0
- package/lib/helpers/materialized-reports/materialized-reports-read-helpers.d.ts +0 -30
- package/lib/helpers/materialized-reports/materialized-reports-read-helpers.js +0 -76
- package/lib/helpers/materialized-reports/materialized-reports-selection-helpers.d.ts +59 -0
- package/lib/helpers/materialized-reports/materialized-reports-selection-helpers.js +723 -0
- package/lib/helpers/materialized-reports/tenant-sales-overview-close-day-helpers.d.ts +66 -8
- package/lib/helpers/materialized-reports/tenant-sales-overview-close-day-helpers.js +326 -40
- package/lib/helpers/materialized-reports/tenant-sales-overview-formatter.d.ts +18 -2
- package/lib/helpers/materialized-reports/tenant-sales-overview-formatter.js +72 -11
- package/lib/helpers/materialized-reports/tenant-sales-overview-helpers.d.ts +46 -37
- package/lib/helpers/materialized-reports/tenant-sales-overview-helpers.js +119 -238
- package/lib/helpers/types/index.d.ts +1 -0
- package/lib/helpers/types/index.js +1 -0
- package/lib/helpers/types/materialized-reports-apis.d.ts +46 -17
- package/lib/helpers/types/report-calendar.d.ts +20 -0
- package/lib/helpers/types/report-calendar.js +2 -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 +337 -0
- package/lib/schemas/models/materialized_credit_bills.js +268 -0
- package/lib/schemas/models/materialized_tenant_reports_iterations.d.ts +20 -6
- package/lib/schemas/models/materialized_tenant_reports_iterations.js +14 -1
- package/lib/schemas/models/materialized_tenant_sales_overview_reports.d.ts +37 -165
- package/lib/schemas/models/materialized_tenant_sales_overview_reports.js +40 -98
- package/lib/schemas/types/index.d.ts +1 -0
- package/lib/schemas/types/index.js +1 -0
- package/lib/schemas/types/materialized_credit_bills.d.ts +139 -0
- package/lib/schemas/types/materialized_credit_bills.js +2 -0
- package/lib/schemas/types/materialized_tenant_sales_overview_reports.d.ts +32 -77
- package/lib/tests/materialized-reports/materialized-credit-bills-helpers.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-credit-bills-helpers.test.js +715 -0
- package/lib/tests/materialized-reports/materialized-reports-selection-helpers.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-reports-selection-helpers.test.js +262 -0
- package/lib/tests/materialized-reports/materialized-tenant-reports-iterations-schema.test.js +9 -0
- package/lib/tests/materialized-reports/materialized-tenant-sales-overview-reports-schema.test.js +23 -24
- package/lib/tests/materialized-reports/tenant-sales-overview-close-day-helpers.test.js +327 -22
- package/lib/tests/materialized-reports/tenant-sales-overview-formatter-aggregated.test.js +27 -2
- package/lib/tests/materialized-reports/tenant-sales-overview-formatter.test.js +12 -27
- package/lib/tests/materialized-reports/tenant-sales-overview-helpers.test.js +79 -146
- package/package.json +1 -1
- package/lib/tests/materialized-reports/materialized-reports-read-helpers.test.js +0 -100
- /package/{lib/tests/materialized-reports/materialized-reports-read-helpers.test.d.ts → esm/helpers/types/report-calendar.js} +0 -0
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MATERIALIZED_TENANT_CREDIT_BILLS_INDEX_OPTIONS = exports.MATERIALIZED_TENANT_CREDIT_BILLS_COLLECTION_INDEXES = exports.MATERIALIZED_TENANT_CREDIT_BILLS_COLLECTION_NAME = exports.MaterializedTenantCreditBillsReportSchema = exports.MATERIALIZED_CREDIT_BILLS_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_credit_bills` — the SHARED
|
|
9
|
+
* credit-bill ledger of the materialized reports (see `MATERIALIZED_REPORTS.md`).
|
|
10
|
+
*
|
|
11
|
+
* ONE document per (tenant, scope context, scope value), scopes CAPPED AT
|
|
12
|
+
* `LOCAL_MONTH` (`MATERIALIZED_CREDIT_BILLS_SCOPES`) so a document can never
|
|
13
|
+
* grow unboundedly: a month bounds its bill volume by construction. Each
|
|
14
|
+
* document carries a per-key `credit_bills` map of slim `issued` / `received`
|
|
15
|
+
* entries (ids + credit facts — the order document stays the single source of
|
|
16
|
+
* the sale). See the type module `schemas/types/materialized_credit_bills.ts`
|
|
17
|
+
* for the entry contract. Amounts are CENTS; reads pin `schema_version`.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Version of the credit-entry rules of this collection. Bump when entry
|
|
21
|
+
* semantics change (e.g. signed REFUND / WRITE_OFF deltas) — historical
|
|
22
|
+
* documents must then be re-materialized. PRE-RELEASE: the collection has no
|
|
23
|
+
* live tenants/consumers yet, so every change so far folds into version `1`.
|
|
24
|
+
*/
|
|
25
|
+
exports.MATERIALIZED_CREDIT_BILLS_SCHEMA_VERSION = 1;
|
|
26
|
+
const CreditBillIssuedEntrySchema = new mongoose_1.Schema({
|
|
27
|
+
order_id: {
|
|
28
|
+
type: String,
|
|
29
|
+
required: true,
|
|
30
|
+
},
|
|
31
|
+
payment_id: {
|
|
32
|
+
type: String,
|
|
33
|
+
required: true,
|
|
34
|
+
},
|
|
35
|
+
amount: {
|
|
36
|
+
type: Number, // cents — the bill's amount at issue
|
|
37
|
+
required: true,
|
|
38
|
+
min: 0,
|
|
39
|
+
},
|
|
40
|
+
issued_at: {
|
|
41
|
+
type: mongoose_1.Schema.Types.Date, // punch time (order.createdAt) — NEVER order_settled_at
|
|
42
|
+
required: true,
|
|
43
|
+
},
|
|
44
|
+
issued_local_hour: {
|
|
45
|
+
type: String, // 'YYYY-MM-DD HH' punch hour (null when unknown)
|
|
46
|
+
default: null,
|
|
47
|
+
},
|
|
48
|
+
// Cents received BEFORE the issue day closed (prepaid partials +
|
|
49
|
+
// same-day settled credit). Carried forward on re-closes — never
|
|
50
|
+
// re-anchored to the current payment state.
|
|
51
|
+
received_at_issue: {
|
|
52
|
+
type: Number,
|
|
53
|
+
required: true,
|
|
54
|
+
default: 0,
|
|
55
|
+
min: 0,
|
|
56
|
+
},
|
|
57
|
+
// Cumulative received so far (NOW state) — patched by collection closes
|
|
58
|
+
// on the ISSUE-scope documents (bounded fan-out).
|
|
59
|
+
received_amount: {
|
|
60
|
+
type: Number,
|
|
61
|
+
required: true,
|
|
62
|
+
default: 0,
|
|
63
|
+
min: 0,
|
|
64
|
+
},
|
|
65
|
+
settled_at: {
|
|
66
|
+
type: mongoose_1.Schema.Types.Date, // the settling receipt's timestamp when known
|
|
67
|
+
default: null,
|
|
68
|
+
},
|
|
69
|
+
settled_local_date: {
|
|
70
|
+
type: String, // 'YYYY-MM-DD' — the settling receipt event's day
|
|
71
|
+
default: null,
|
|
72
|
+
},
|
|
73
|
+
credit_note: {
|
|
74
|
+
type: String, // optional note/reference recorded with the collection
|
|
75
|
+
default: null,
|
|
76
|
+
},
|
|
77
|
+
}, { _id: false, minimize: false });
|
|
78
|
+
const CreditBillReceivedEntrySchema = new mongoose_1.Schema({
|
|
79
|
+
order_id: {
|
|
80
|
+
type: String,
|
|
81
|
+
required: true,
|
|
82
|
+
},
|
|
83
|
+
payment_id: {
|
|
84
|
+
type: String,
|
|
85
|
+
required: true,
|
|
86
|
+
},
|
|
87
|
+
event_local_date: {
|
|
88
|
+
type: String, // 'YYYY-MM-DD' — collection business day (entry identity)
|
|
89
|
+
required: true,
|
|
90
|
+
},
|
|
91
|
+
amount: {
|
|
92
|
+
type: Number, // cents — the bill's amount at issue (receipt context)
|
|
93
|
+
required: true,
|
|
94
|
+
min: 0,
|
|
95
|
+
},
|
|
96
|
+
// Cumulative received right AFTER this event — the idempotent re-close
|
|
97
|
+
// anchor (`prior = received_amount − received_delta`).
|
|
98
|
+
received_amount: {
|
|
99
|
+
type: Number,
|
|
100
|
+
required: true,
|
|
101
|
+
default: 0,
|
|
102
|
+
min: 0,
|
|
103
|
+
},
|
|
104
|
+
// Cents collected BY this event (incremental — resolved against the
|
|
105
|
+
// stored pre-event cumulative at close-plan time). REFUND / WRITE_OFF
|
|
106
|
+
// would carry a SIGNED delta — reserved, unimplemented.
|
|
107
|
+
received_delta: {
|
|
108
|
+
type: Number,
|
|
109
|
+
required: true,
|
|
110
|
+
default: 0,
|
|
111
|
+
},
|
|
112
|
+
received_at: {
|
|
113
|
+
type: mongoose_1.Schema.Types.Date, // collection timestamp (order_settled_at) when known — ordering anchor
|
|
114
|
+
default: null,
|
|
115
|
+
},
|
|
116
|
+
event_local_hour: {
|
|
117
|
+
type: String, // 'YYYY-MM-DD HH' tenant-local collection hour (null when unknown)
|
|
118
|
+
default: null,
|
|
119
|
+
},
|
|
120
|
+
credit_note: {
|
|
121
|
+
type: String,
|
|
122
|
+
default: null,
|
|
123
|
+
},
|
|
124
|
+
issued_local_date: {
|
|
125
|
+
type: String, // 'YYYY-MM-DD' — the bill's issue day (display anchor)
|
|
126
|
+
required: true,
|
|
127
|
+
},
|
|
128
|
+
}, { _id: false, minimize: false });
|
|
129
|
+
const CreditBillKeySectionSchema = new mongoose_1.Schema({
|
|
130
|
+
issued: {
|
|
131
|
+
type: [CreditBillIssuedEntrySchema],
|
|
132
|
+
default: [],
|
|
133
|
+
},
|
|
134
|
+
received: {
|
|
135
|
+
type: [CreditBillReceivedEntrySchema],
|
|
136
|
+
default: [],
|
|
137
|
+
},
|
|
138
|
+
}, { _id: false, minimize: false });
|
|
139
|
+
exports.MaterializedTenantCreditBillsReportSchema = new mongoose_1.Schema({
|
|
140
|
+
_id: {
|
|
141
|
+
type: mongoose_1.Schema.Types.ObjectId,
|
|
142
|
+
required: true,
|
|
143
|
+
immutable: true,
|
|
144
|
+
},
|
|
145
|
+
tenant_id: {
|
|
146
|
+
type: String,
|
|
147
|
+
required: true,
|
|
148
|
+
immutable: true,
|
|
149
|
+
ref: 'tenants',
|
|
150
|
+
},
|
|
151
|
+
brand_id: {
|
|
152
|
+
type: String,
|
|
153
|
+
required: true,
|
|
154
|
+
},
|
|
155
|
+
scope_context: {
|
|
156
|
+
type: String,
|
|
157
|
+
enum: MATERIALIZED_REPORTS_1.MATERIALIZED_CREDIT_BILLS_SCOPES,
|
|
158
|
+
required: true,
|
|
159
|
+
},
|
|
160
|
+
scope_field: {
|
|
161
|
+
type: String, // format depends on scope_context — see MATERIALIZED_REPORT_SCOPE_ENUM
|
|
162
|
+
required: true,
|
|
163
|
+
},
|
|
164
|
+
// Denormalized weekday of scope_field — set ONLY on LOCAL_HOUR /
|
|
165
|
+
// LOCAL_DATE documents (MATERIALIZED_REPORT_SCOPES_WITH_DAY_INDEX);
|
|
166
|
+
// null elsewhere.
|
|
167
|
+
day_index: {
|
|
168
|
+
type: String,
|
|
169
|
+
enum: ENUMS_1.ALL_DAY_INDEX,
|
|
170
|
+
default: null,
|
|
171
|
+
},
|
|
172
|
+
sale_type_key_filters: {
|
|
173
|
+
type: [String],
|
|
174
|
+
enum: MATERIALIZED_REPORTS_1.ALL_MATERIALIZED_REPORT_KEY_FILTERS,
|
|
175
|
+
required: true,
|
|
176
|
+
default: () => [...MATERIALIZED_REPORTS_1.SALES_OVERVIEW_KEY_FILTERS],
|
|
177
|
+
},
|
|
178
|
+
// Map key = the ordered filter combination, e.g. "COMPLETED:POS_WALK-IN" —
|
|
179
|
+
// the grammar is declared by `sale_type_key_filters` and must be built /
|
|
180
|
+
// parsed through the shared key helper, never ad hoc.
|
|
181
|
+
credit_bills: {
|
|
182
|
+
type: Map,
|
|
183
|
+
of: CreditBillKeySectionSchema,
|
|
184
|
+
required: true,
|
|
185
|
+
default: {},
|
|
186
|
+
},
|
|
187
|
+
// Versioned writes: bumped on replacement / period deltas / settlement
|
|
188
|
+
// patches; 1 = first materialization. Every bump is recorded in the
|
|
189
|
+
// shared `materialized_tenant_reports_iterations` history (full post-write
|
|
190
|
+
// snapshot + reason) — this document carries no embedded snapshot.
|
|
191
|
+
iteration: {
|
|
192
|
+
type: Number,
|
|
193
|
+
required: true,
|
|
194
|
+
min: 1,
|
|
195
|
+
default: 1,
|
|
196
|
+
},
|
|
197
|
+
schema_version: {
|
|
198
|
+
type: Number,
|
|
199
|
+
required: true,
|
|
200
|
+
immutable: true,
|
|
201
|
+
default: exports.MATERIALIZED_CREDIT_BILLS_SCHEMA_VERSION,
|
|
202
|
+
},
|
|
203
|
+
source_watermark: {
|
|
204
|
+
type: mongoose_1.Schema.Types.Date,
|
|
205
|
+
required: true,
|
|
206
|
+
},
|
|
207
|
+
computed_at: {
|
|
208
|
+
type: mongoose_1.Schema.Types.Date,
|
|
209
|
+
required: true,
|
|
210
|
+
},
|
|
211
|
+
createdAt: {
|
|
212
|
+
type: mongoose_1.Schema.Types.Date,
|
|
213
|
+
required: true,
|
|
214
|
+
default: () => new Date(),
|
|
215
|
+
immutable: true,
|
|
216
|
+
},
|
|
217
|
+
updatedAt: {
|
|
218
|
+
type: mongoose_1.Schema.Types.Date,
|
|
219
|
+
required: true,
|
|
220
|
+
default: () => new Date(),
|
|
221
|
+
},
|
|
222
|
+
}, {
|
|
223
|
+
timestamps: true,
|
|
224
|
+
versionKey: false,
|
|
225
|
+
minimize: false,
|
|
226
|
+
});
|
|
227
|
+
exports.MATERIALIZED_TENANT_CREDIT_BILLS_COLLECTION_NAME = 'materialized_tenant_credit_bills';
|
|
228
|
+
/**
|
|
229
|
+
* Describes the indexes for `materialized_tenant_credit_bills`. Values are
|
|
230
|
+
* Mongo key patterns that can be passed straight to `.hint()`.
|
|
231
|
+
*
|
|
232
|
+
* ONE compound index carries the whole read story (plus `_id`) — same shape
|
|
233
|
+
* as the other materialized collections:
|
|
234
|
+
* `tenant_id__scope_context__scope_field__day_index` — UNIQUE:
|
|
235
|
+
* - identity — one document per (tenant, scope context, scope value);
|
|
236
|
+
* `day_index` is a deterministic function of `scope_field` (null for period
|
|
237
|
+
* scopes), so including it keeps the uniqueness exactly on that identity;
|
|
238
|
+
* - the drill-down read — the `{ tenant_id, scope_context, scope_field }`
|
|
239
|
+
* prefix serves exact and ranged scope-field queries (covering-set
|
|
240
|
+
* resolution) for single tenants and `$in` tenant lists.
|
|
241
|
+
*
|
|
242
|
+
* There are NO `brand_id` indexes: brand-level reads always pass the brand's
|
|
243
|
+
* explicit tenant list (`tenant_id: { $in }`).
|
|
244
|
+
*/
|
|
245
|
+
exports.MATERIALIZED_TENANT_CREDIT_BILLS_COLLECTION_INDEXES = {
|
|
246
|
+
_id: { _id: 1 }, // Unique Index
|
|
247
|
+
tenant_id__scope_context__scope_field__day_index: {
|
|
248
|
+
tenant_id: 1,
|
|
249
|
+
scope_context: 1,
|
|
250
|
+
scope_field: 1,
|
|
251
|
+
day_index: 1,
|
|
252
|
+
},
|
|
253
|
+
};
|
|
254
|
+
/**
|
|
255
|
+
* Index OPTIONS the materializer must CREATE — the identity index is a UNIQUE
|
|
256
|
+
* business invariant (one document per tenant × scope context × scope value;
|
|
257
|
+
* the close-day writes upsert against it and silently degrade without it),
|
|
258
|
+
* so it must be created with `unique: true`. The key patterns above are what
|
|
259
|
+
* the read `.hint()` consumes; these options are what creation must apply.
|
|
260
|
+
* The materializer boot should assert them (`listIndexes`, fail closed).
|
|
261
|
+
*/
|
|
262
|
+
exports.MATERIALIZED_TENANT_CREDIT_BILLS_INDEX_OPTIONS = [
|
|
263
|
+
{
|
|
264
|
+
key: { tenant_id: 1, scope_context: 1, scope_field: 1, day_index: 1 },
|
|
265
|
+
name: 'tenant_id__scope_context__scope_field__day_index',
|
|
266
|
+
unique: true,
|
|
267
|
+
},
|
|
268
|
+
];
|
|
@@ -24,9 +24,9 @@ export declare const MaterializedTenantReportIterationSchema: Schema<any, import
|
|
|
24
24
|
createdAt: NativeDate;
|
|
25
25
|
updatedAt: NativeDate;
|
|
26
26
|
iteration: number;
|
|
27
|
-
report_type: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_TYPE_ENUM.TENANT_SALES_OVERVIEW;
|
|
28
|
-
report_id: import("mongoose").Types.ObjectId;
|
|
29
27
|
schema_version: number;
|
|
28
|
+
report_type: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_TYPE_ENUM;
|
|
29
|
+
report_id: import("mongoose").Types.ObjectId;
|
|
30
30
|
snapshot: any;
|
|
31
31
|
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
32
32
|
createdAt: NativeDate;
|
|
@@ -37,9 +37,9 @@ export declare const MaterializedTenantReportIterationSchema: Schema<any, import
|
|
|
37
37
|
createdAt: NativeDate;
|
|
38
38
|
updatedAt: NativeDate;
|
|
39
39
|
iteration: number;
|
|
40
|
-
report_type: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_TYPE_ENUM.TENANT_SALES_OVERVIEW;
|
|
41
|
-
report_id: import("mongoose").Types.ObjectId;
|
|
42
40
|
schema_version: number;
|
|
41
|
+
report_type: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_TYPE_ENUM;
|
|
42
|
+
report_id: import("mongoose").Types.ObjectId;
|
|
43
43
|
snapshot: any;
|
|
44
44
|
}>> & import("mongoose").FlatRecord<{
|
|
45
45
|
createdAt: NativeDate;
|
|
@@ -50,9 +50,9 @@ export declare const MaterializedTenantReportIterationSchema: Schema<any, import
|
|
|
50
50
|
createdAt: NativeDate;
|
|
51
51
|
updatedAt: NativeDate;
|
|
52
52
|
iteration: number;
|
|
53
|
-
report_type: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_TYPE_ENUM.TENANT_SALES_OVERVIEW;
|
|
54
|
-
report_id: import("mongoose").Types.ObjectId;
|
|
55
53
|
schema_version: number;
|
|
54
|
+
report_type: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_TYPE_ENUM;
|
|
55
|
+
report_id: import("mongoose").Types.ObjectId;
|
|
56
56
|
snapshot: any;
|
|
57
57
|
}> & Required<{
|
|
58
58
|
_id: import("mongoose").Types.ObjectId;
|
|
@@ -78,3 +78,17 @@ export declare const MATERIALIZED_TENANT_REPORTS_ITERATIONS_COLLECTION_INDEXES:
|
|
|
78
78
|
iteration: number;
|
|
79
79
|
};
|
|
80
80
|
};
|
|
81
|
+
/**
|
|
82
|
+
* Index OPTIONS the materializer must CREATE — `report_id__iteration` is a
|
|
83
|
+
* UNIQUE business invariant: one history row per (report, iteration), and the
|
|
84
|
+
* idempotent upsert key (`replaceOne({ report_id, iteration }, row, { upsert: true })`)
|
|
85
|
+
* silently degrades into duplicates without it.
|
|
86
|
+
*/
|
|
87
|
+
export declare const MATERIALIZED_TENANT_REPORTS_ITERATIONS_INDEX_OPTIONS: {
|
|
88
|
+
key: {
|
|
89
|
+
report_id: number;
|
|
90
|
+
iteration: number;
|
|
91
|
+
};
|
|
92
|
+
name: string;
|
|
93
|
+
unique: boolean;
|
|
94
|
+
}[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MATERIALIZED_TENANT_REPORTS_ITERATIONS_COLLECTION_INDEXES = exports.MATERIALIZED_TENANT_REPORTS_ITERATIONS_COLLECTION_NAME = exports.MaterializedTenantReportIterationSchema = void 0;
|
|
3
|
+
exports.MATERIALIZED_TENANT_REPORTS_ITERATIONS_INDEX_OPTIONS = exports.MATERIALIZED_TENANT_REPORTS_ITERATIONS_COLLECTION_INDEXES = exports.MATERIALIZED_TENANT_REPORTS_ITERATIONS_COLLECTION_NAME = exports.MaterializedTenantReportIterationSchema = void 0;
|
|
4
4
|
const mongoose_1 = require("mongoose");
|
|
5
5
|
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
6
6
|
/**
|
|
@@ -83,3 +83,16 @@ exports.MATERIALIZED_TENANT_REPORTS_ITERATIONS_COLLECTION_INDEXES = {
|
|
|
83
83
|
_id: { _id: 1 }, // Unique Index
|
|
84
84
|
report_id__iteration: { report_id: 1, iteration: -1 }, // unique — one row per (report, iteration)
|
|
85
85
|
};
|
|
86
|
+
/**
|
|
87
|
+
* Index OPTIONS the materializer must CREATE — `report_id__iteration` is a
|
|
88
|
+
* UNIQUE business invariant: one history row per (report, iteration), and the
|
|
89
|
+
* idempotent upsert key (`replaceOne({ report_id, iteration }, row, { upsert: true })`)
|
|
90
|
+
* silently degrades into duplicates without it.
|
|
91
|
+
*/
|
|
92
|
+
exports.MATERIALIZED_TENANT_REPORTS_ITERATIONS_INDEX_OPTIONS = [
|
|
93
|
+
{
|
|
94
|
+
key: { report_id: 1, iteration: -1 },
|
|
95
|
+
name: 'report_id__iteration',
|
|
96
|
+
unique: true,
|
|
97
|
+
},
|
|
98
|
+
];
|
|
@@ -9,17 +9,20 @@ import { Schema } from 'mongoose';
|
|
|
9
9
|
* `MATERIALIZED_REPORTS.md`). The report's time-bias toggle (Punched At /
|
|
10
10
|
* `createdAt`) is out of scope. `scope_field` formats are documented on
|
|
11
11
|
* `MATERIALIZED_REPORT_SCOPE_ENUM` and in `MATERIALIZED_REPORTS.md`.
|
|
12
|
-
*
|
|
13
|
-
* `CREDIT_BILLS` slot
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
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.
|
|
17
19
|
*/
|
|
18
20
|
/**
|
|
19
21
|
* Version of the key grammar + metric rules of this collection. Bump when
|
|
20
22
|
* `sale_type_key_filters`, their order, or metric semantics change —
|
|
21
23
|
* historical documents must then be re-materialized (readers may branch on
|
|
22
|
-
* this value during a rollout).
|
|
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`.
|
|
23
26
|
*/
|
|
24
27
|
export declare const MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_SCHEMA_VERSION = 1;
|
|
25
28
|
export declare const MaterializedTenantSalesOverviewReportSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
@@ -38,9 +41,11 @@ export declare const MaterializedTenantSalesOverviewReportSchema: Schema<any, im
|
|
|
38
41
|
day_index: import("../../constants").DAY_INDEX_ENUM;
|
|
39
42
|
iteration: number;
|
|
40
43
|
scope_context: import("../../constants").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
41
|
-
schema_version: number;
|
|
42
44
|
scope_field: string;
|
|
43
45
|
sale_type_key_filters: string[];
|
|
46
|
+
schema_version: number;
|
|
47
|
+
source_watermark: NativeDate;
|
|
48
|
+
computed_at: NativeDate;
|
|
44
49
|
sale_type_metrics: Map<string, {
|
|
45
50
|
TOTAL_SALES: {
|
|
46
51
|
orders: {
|
|
@@ -132,65 +137,13 @@ export declare const MaterializedTenantSalesOverviewReportSchema: Schema<any, im
|
|
|
132
137
|
amount: number;
|
|
133
138
|
settled_count: number;
|
|
134
139
|
settled_amount: number;
|
|
135
|
-
bills: import("mongoose").Types.DocumentArray<{
|
|
136
|
-
order_id: string;
|
|
137
|
-
payment_id: string;
|
|
138
|
-
amount: number;
|
|
139
|
-
received_amount: number;
|
|
140
|
-
credit_note: string;
|
|
141
|
-
issued_at: NativeDate;
|
|
142
|
-
settled_at: NativeDate;
|
|
143
|
-
}, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
|
|
144
|
-
order_id: string;
|
|
145
|
-
payment_id: string;
|
|
146
|
-
amount: number;
|
|
147
|
-
received_amount: number;
|
|
148
|
-
credit_note: string;
|
|
149
|
-
issued_at: NativeDate;
|
|
150
|
-
settled_at: NativeDate;
|
|
151
|
-
}> & {
|
|
152
|
-
order_id: string;
|
|
153
|
-
payment_id: string;
|
|
154
|
-
amount: number;
|
|
155
|
-
received_amount: number;
|
|
156
|
-
credit_note: string;
|
|
157
|
-
issued_at: NativeDate;
|
|
158
|
-
settled_at: NativeDate;
|
|
159
|
-
}>;
|
|
160
140
|
} | null | undefined;
|
|
161
141
|
received?: {
|
|
162
142
|
count: number;
|
|
163
143
|
amount: number;
|
|
164
|
-
bills: import("mongoose").Types.DocumentArray<{
|
|
165
|
-
order_id: string;
|
|
166
|
-
payment_id: string;
|
|
167
|
-
amount: number;
|
|
168
|
-
received_amount: number;
|
|
169
|
-
credit_note: string;
|
|
170
|
-
settled_at: NativeDate;
|
|
171
|
-
issued_local_date: string;
|
|
172
|
-
}, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
|
|
173
|
-
order_id: string;
|
|
174
|
-
payment_id: string;
|
|
175
|
-
amount: number;
|
|
176
|
-
received_amount: number;
|
|
177
|
-
credit_note: string;
|
|
178
|
-
settled_at: NativeDate;
|
|
179
|
-
issued_local_date: string;
|
|
180
|
-
}> & {
|
|
181
|
-
order_id: string;
|
|
182
|
-
payment_id: string;
|
|
183
|
-
amount: number;
|
|
184
|
-
received_amount: number;
|
|
185
|
-
credit_note: string;
|
|
186
|
-
settled_at: NativeDate;
|
|
187
|
-
issued_local_date: string;
|
|
188
|
-
}>;
|
|
189
144
|
} | null | undefined;
|
|
190
145
|
};
|
|
191
146
|
}>;
|
|
192
|
-
source_watermark: NativeDate;
|
|
193
|
-
computed_at: NativeDate;
|
|
194
147
|
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
195
148
|
createdAt: NativeDate;
|
|
196
149
|
updatedAt: NativeDate;
|
|
@@ -203,9 +156,11 @@ export declare const MaterializedTenantSalesOverviewReportSchema: Schema<any, im
|
|
|
203
156
|
day_index: import("../../constants").DAY_INDEX_ENUM;
|
|
204
157
|
iteration: number;
|
|
205
158
|
scope_context: import("../../constants").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
206
|
-
schema_version: number;
|
|
207
159
|
scope_field: string;
|
|
208
160
|
sale_type_key_filters: string[];
|
|
161
|
+
schema_version: number;
|
|
162
|
+
source_watermark: NativeDate;
|
|
163
|
+
computed_at: NativeDate;
|
|
209
164
|
sale_type_metrics: Map<string, {
|
|
210
165
|
TOTAL_SALES: {
|
|
211
166
|
orders: {
|
|
@@ -297,65 +252,13 @@ export declare const MaterializedTenantSalesOverviewReportSchema: Schema<any, im
|
|
|
297
252
|
amount: number;
|
|
298
253
|
settled_count: number;
|
|
299
254
|
settled_amount: number;
|
|
300
|
-
bills: import("mongoose").Types.DocumentArray<{
|
|
301
|
-
order_id: string;
|
|
302
|
-
payment_id: string;
|
|
303
|
-
amount: number;
|
|
304
|
-
received_amount: number;
|
|
305
|
-
credit_note: string;
|
|
306
|
-
issued_at: NativeDate;
|
|
307
|
-
settled_at: NativeDate;
|
|
308
|
-
}, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
|
|
309
|
-
order_id: string;
|
|
310
|
-
payment_id: string;
|
|
311
|
-
amount: number;
|
|
312
|
-
received_amount: number;
|
|
313
|
-
credit_note: string;
|
|
314
|
-
issued_at: NativeDate;
|
|
315
|
-
settled_at: NativeDate;
|
|
316
|
-
}> & {
|
|
317
|
-
order_id: string;
|
|
318
|
-
payment_id: string;
|
|
319
|
-
amount: number;
|
|
320
|
-
received_amount: number;
|
|
321
|
-
credit_note: string;
|
|
322
|
-
issued_at: NativeDate;
|
|
323
|
-
settled_at: NativeDate;
|
|
324
|
-
}>;
|
|
325
255
|
} | null | undefined;
|
|
326
256
|
received?: {
|
|
327
257
|
count: number;
|
|
328
258
|
amount: number;
|
|
329
|
-
bills: import("mongoose").Types.DocumentArray<{
|
|
330
|
-
order_id: string;
|
|
331
|
-
payment_id: string;
|
|
332
|
-
amount: number;
|
|
333
|
-
received_amount: number;
|
|
334
|
-
credit_note: string;
|
|
335
|
-
settled_at: NativeDate;
|
|
336
|
-
issued_local_date: string;
|
|
337
|
-
}, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
|
|
338
|
-
order_id: string;
|
|
339
|
-
payment_id: string;
|
|
340
|
-
amount: number;
|
|
341
|
-
received_amount: number;
|
|
342
|
-
credit_note: string;
|
|
343
|
-
settled_at: NativeDate;
|
|
344
|
-
issued_local_date: string;
|
|
345
|
-
}> & {
|
|
346
|
-
order_id: string;
|
|
347
|
-
payment_id: string;
|
|
348
|
-
amount: number;
|
|
349
|
-
received_amount: number;
|
|
350
|
-
credit_note: string;
|
|
351
|
-
settled_at: NativeDate;
|
|
352
|
-
issued_local_date: string;
|
|
353
|
-
}>;
|
|
354
259
|
} | null | undefined;
|
|
355
260
|
};
|
|
356
261
|
}>;
|
|
357
|
-
source_watermark: NativeDate;
|
|
358
|
-
computed_at: NativeDate;
|
|
359
262
|
}>> & import("mongoose").FlatRecord<{
|
|
360
263
|
createdAt: NativeDate;
|
|
361
264
|
updatedAt: NativeDate;
|
|
@@ -368,9 +271,11 @@ export declare const MaterializedTenantSalesOverviewReportSchema: Schema<any, im
|
|
|
368
271
|
day_index: import("../../constants").DAY_INDEX_ENUM;
|
|
369
272
|
iteration: number;
|
|
370
273
|
scope_context: import("../../constants").MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
371
|
-
schema_version: number;
|
|
372
274
|
scope_field: string;
|
|
373
275
|
sale_type_key_filters: string[];
|
|
276
|
+
schema_version: number;
|
|
277
|
+
source_watermark: NativeDate;
|
|
278
|
+
computed_at: NativeDate;
|
|
374
279
|
sale_type_metrics: Map<string, {
|
|
375
280
|
TOTAL_SALES: {
|
|
376
281
|
orders: {
|
|
@@ -462,65 +367,13 @@ export declare const MaterializedTenantSalesOverviewReportSchema: Schema<any, im
|
|
|
462
367
|
amount: number;
|
|
463
368
|
settled_count: number;
|
|
464
369
|
settled_amount: number;
|
|
465
|
-
bills: import("mongoose").Types.DocumentArray<{
|
|
466
|
-
order_id: string;
|
|
467
|
-
payment_id: string;
|
|
468
|
-
amount: number;
|
|
469
|
-
received_amount: number;
|
|
470
|
-
credit_note: string;
|
|
471
|
-
issued_at: NativeDate;
|
|
472
|
-
settled_at: NativeDate;
|
|
473
|
-
}, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
|
|
474
|
-
order_id: string;
|
|
475
|
-
payment_id: string;
|
|
476
|
-
amount: number;
|
|
477
|
-
received_amount: number;
|
|
478
|
-
credit_note: string;
|
|
479
|
-
issued_at: NativeDate;
|
|
480
|
-
settled_at: NativeDate;
|
|
481
|
-
}> & {
|
|
482
|
-
order_id: string;
|
|
483
|
-
payment_id: string;
|
|
484
|
-
amount: number;
|
|
485
|
-
received_amount: number;
|
|
486
|
-
credit_note: string;
|
|
487
|
-
issued_at: NativeDate;
|
|
488
|
-
settled_at: NativeDate;
|
|
489
|
-
}>;
|
|
490
370
|
} | null | undefined;
|
|
491
371
|
received?: {
|
|
492
372
|
count: number;
|
|
493
373
|
amount: number;
|
|
494
|
-
bills: import("mongoose").Types.DocumentArray<{
|
|
495
|
-
order_id: string;
|
|
496
|
-
payment_id: string;
|
|
497
|
-
amount: number;
|
|
498
|
-
received_amount: number;
|
|
499
|
-
credit_note: string;
|
|
500
|
-
settled_at: NativeDate;
|
|
501
|
-
issued_local_date: string;
|
|
502
|
-
}, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
|
|
503
|
-
order_id: string;
|
|
504
|
-
payment_id: string;
|
|
505
|
-
amount: number;
|
|
506
|
-
received_amount: number;
|
|
507
|
-
credit_note: string;
|
|
508
|
-
settled_at: NativeDate;
|
|
509
|
-
issued_local_date: string;
|
|
510
|
-
}> & {
|
|
511
|
-
order_id: string;
|
|
512
|
-
payment_id: string;
|
|
513
|
-
amount: number;
|
|
514
|
-
received_amount: number;
|
|
515
|
-
credit_note: string;
|
|
516
|
-
settled_at: NativeDate;
|
|
517
|
-
issued_local_date: string;
|
|
518
|
-
}>;
|
|
519
374
|
} | null | undefined;
|
|
520
375
|
};
|
|
521
376
|
}>;
|
|
522
|
-
source_watermark: NativeDate;
|
|
523
|
-
computed_at: NativeDate;
|
|
524
377
|
}> & Required<{
|
|
525
378
|
_id: import("mongoose").Types.ObjectId;
|
|
526
379
|
}> & {
|
|
@@ -559,3 +412,22 @@ export declare const MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_COLLECTION_INDEX
|
|
|
559
412
|
day_index: number;
|
|
560
413
|
};
|
|
561
414
|
};
|
|
415
|
+
/**
|
|
416
|
+
* Index OPTIONS the materializer must CREATE — the identity index is a UNIQUE
|
|
417
|
+
* business invariant (one document per tenant × scope context × scope value;
|
|
418
|
+
* the close-day writes upsert against it and silently degrade without it),
|
|
419
|
+
* so it must be created with `unique: true`. The key patterns above are what
|
|
420
|
+
* the read `.hint()` consumes; these options are what creation must apply.
|
|
421
|
+
* The materializer boot should assert them (`listIndexes`, fail closed — the
|
|
422
|
+
* read hint already fails closed without the index itself).
|
|
423
|
+
*/
|
|
424
|
+
export declare const MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_INDEX_OPTIONS: {
|
|
425
|
+
key: {
|
|
426
|
+
tenant_id: number;
|
|
427
|
+
scope_context: number;
|
|
428
|
+
scope_field: number;
|
|
429
|
+
day_index: number;
|
|
430
|
+
};
|
|
431
|
+
name: string;
|
|
432
|
+
unique: boolean;
|
|
433
|
+
}[];
|