@managesome/eposmatic-toolkit 0.4.52 → 0.4.54
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 +106 -2
- package/esm/constants/enums/delivery.js +13 -0
- package/esm/helpers/materialized-reports/index.js +6 -0
- package/esm/helpers/materialized-reports/materialized-delivery-accumulator-helpers.js +8 -62
- package/esm/helpers/materialized-reports/materialized-delivery-classification-helpers.js +95 -73
- package/esm/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +118 -146
- package/esm/helpers/materialized-reports/materialized-delivery-compile-helpers.js +304 -71
- package/esm/helpers/materialized-reports/materialized-delivery-entry-pages.js +307 -0
- package/esm/helpers/materialized-reports/materialized-delivery-index-migration.js +103 -0
- package/esm/helpers/materialized-reports/materialized-delivery-rows.js +109 -0
- package/esm/helpers/materialized-reports/materialized-delivery-wipe-targets.js +32 -0
- package/esm/helpers/materialized-reports/materialized-document-size.js +65 -0
- package/esm/helpers/materialized-reports/materialized-index-bootstrap.js +31 -16
- package/esm/helpers/materialized-reports/materialized-integer-contract.js +10 -1
- package/esm/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +3 -91
- package/esm/helpers/materialized-reports/materialized-tenant-delivery-geo-helpers.js +597 -0
- package/esm/helpers/materialized-reports/report-platform/definition.js +508 -0
- package/esm/helpers/materialized-reports/report-platform/index.js +4 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/budget.js +27 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/cap-metadata.js +12 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/entry-pages.js +121 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/flat-projection.js +14 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/index.js +8 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/iteration-row.js +10 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/run-stats.js +42 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/scope-refs.js +28 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/top-n.js +24 -0
- package/esm/helpers/materialized-reports/report-platform/registry.js +23 -0
- package/esm/helpers/materialized-reports/report-platform/validate-report-registry.js +214 -0
- package/esm/helpers/materialized-reports/scope-helpers.js +98 -0
- package/esm/helpers/materialized-reports/tenant-delivery-formatter.js +70 -20
- package/esm/schemas/models/applied_order_discounts.js +103 -0
- package/esm/schemas/models/index.js +12 -10
- package/esm/schemas/models/materialized_tenant_delivery_entries.js +33 -12
- package/esm/schemas/models/materialized_tenant_delivery_geo_cells.js +83 -0
- package/esm/schemas/models/materialized_tenant_delivery_geo_scopes.js +35 -0
- package/esm/schemas/models/materialized_tenant_delivery_reports.js +10 -1
- package/esm/schemas/types/applied_order_discounts.js +1 -0
- package/esm/schemas/types/index.js +14 -12
- package/esm/schemas/types/materialized_tenant_delivery_geo_cells.js +1 -0
- package/esm/schemas/types/materialized_tenant_delivery_geo_scopes.js +1 -0
- package/lib/constants/MATERIALIZED_REPORTS.d.ts +95 -1
- package/lib/constants/MATERIALIZED_REPORTS.js +108 -4
- package/lib/constants/enums/delivery.d.ts +9 -0
- package/lib/constants/enums/delivery.js +14 -1
- package/lib/helpers/materialized-reports/index.d.ts +6 -0
- package/lib/helpers/materialized-reports/index.js +6 -0
- package/lib/helpers/materialized-reports/materialized-delivery-accumulator-helpers.js +8 -62
- package/lib/helpers/materialized-reports/materialized-delivery-classification-helpers.d.ts +36 -9
- package/lib/helpers/materialized-reports/materialized-delivery-classification-helpers.js +94 -72
- package/lib/helpers/materialized-reports/materialized-delivery-close-day-helpers.d.ts +23 -26
- package/lib/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +121 -150
- package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.d.ts +44 -5
- package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.js +306 -69
- package/lib/helpers/materialized-reports/materialized-delivery-entry-pages.d.ts +128 -0
- package/lib/helpers/materialized-reports/materialized-delivery-entry-pages.js +322 -0
- package/lib/helpers/materialized-reports/materialized-delivery-index-migration.d.ts +48 -0
- package/lib/helpers/materialized-reports/materialized-delivery-index-migration.js +108 -0
- package/lib/helpers/materialized-reports/materialized-delivery-rows.d.ts +15 -0
- package/lib/helpers/materialized-reports/materialized-delivery-rows.js +115 -0
- package/lib/helpers/materialized-reports/materialized-delivery-wipe-targets.d.ts +17 -0
- package/lib/helpers/materialized-reports/materialized-delivery-wipe-targets.js +35 -0
- package/lib/helpers/materialized-reports/materialized-document-size.d.ts +47 -0
- package/lib/helpers/materialized-reports/materialized-document-size.js +73 -0
- package/lib/helpers/materialized-reports/materialized-index-bootstrap.js +28 -13
- package/lib/helpers/materialized-reports/materialized-integer-contract.js +10 -1
- package/lib/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +2 -90
- package/lib/helpers/materialized-reports/materialized-tenant-delivery-geo-helpers.d.ts +186 -0
- package/lib/helpers/materialized-reports/materialized-tenant-delivery-geo-helpers.js +620 -0
- package/lib/helpers/materialized-reports/report-platform/definition.d.ts +133 -0
- package/lib/helpers/materialized-reports/report-platform/definition.js +511 -0
- package/lib/helpers/materialized-reports/report-platform/index.d.ts +4 -0
- package/lib/helpers/materialized-reports/report-platform/index.js +20 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/budget.d.ts +8 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/budget.js +31 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/cap-metadata.d.ts +8 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/cap-metadata.js +16 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/entry-pages.d.ts +40 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/entry-pages.js +130 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/flat-projection.d.ts +22 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/flat-projection.js +17 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/index.d.ts +8 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/index.js +24 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/iteration-row.d.ts +13 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/iteration-row.js +13 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/run-stats.d.ts +20 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/run-stats.js +47 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/scope-refs.d.ts +13 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/scope-refs.js +31 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/top-n.d.ts +16 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/top-n.js +29 -0
- package/lib/helpers/materialized-reports/report-platform/registry.d.ts +13 -0
- package/lib/helpers/materialized-reports/report-platform/registry.js +31 -0
- package/lib/helpers/materialized-reports/report-platform/validate-report-registry.d.ts +20 -0
- package/lib/helpers/materialized-reports/report-platform/validate-report-registry.js +218 -0
- package/lib/helpers/materialized-reports/scope-helpers.d.ts +8 -0
- package/lib/helpers/materialized-reports/scope-helpers.js +99 -0
- package/lib/helpers/materialized-reports/tenant-delivery-formatter.d.ts +41 -0
- package/lib/helpers/materialized-reports/tenant-delivery-formatter.js +70 -20
- package/lib/helpers/order/payment-collection.d.ts +25 -0
- package/lib/helpers/order/payment-collection.js +51 -0
- package/lib/schemas/models/applied_order_discounts.d.ts +80 -0
- package/lib/schemas/models/applied_order_discounts.js +106 -0
- package/lib/schemas/models/index.d.ts +12 -10
- package/lib/schemas/models/index.js +12 -10
- package/lib/schemas/models/materialized_tenant_delivery_entries.d.ts +31 -9
- package/lib/schemas/models/materialized_tenant_delivery_entries.js +32 -11
- package/lib/schemas/models/materialized_tenant_delivery_geo_cells.d.ts +129 -0
- package/lib/schemas/models/materialized_tenant_delivery_geo_cells.js +86 -0
- package/lib/schemas/models/materialized_tenant_delivery_geo_scopes.d.ts +71 -0
- package/lib/schemas/models/materialized_tenant_delivery_geo_scopes.js +38 -0
- package/lib/schemas/models/materialized_tenant_delivery_reports.d.ts +10 -1
- package/lib/schemas/models/materialized_tenant_delivery_reports.js +10 -1
- package/lib/schemas/models/materialized_tenant_discount_sources.d.ts +15 -15
- package/lib/schemas/types/applied_order_discounts.d.ts +22 -0
- package/lib/schemas/types/applied_order_discounts.js +2 -0
- package/lib/schemas/types/index.d.ts +14 -12
- package/lib/schemas/types/index.js +14 -12
- package/lib/schemas/types/materialized_tenant_delivery_entries.d.ts +36 -4
- package/lib/schemas/types/materialized_tenant_delivery_geo_cells.d.ts +178 -0
- package/lib/schemas/types/materialized_tenant_delivery_geo_cells.js +2 -0
- package/lib/schemas/types/materialized_tenant_delivery_geo_scopes.d.ts +21 -0
- package/lib/schemas/types/materialized_tenant_delivery_geo_scopes.js +2 -0
- package/lib/schemas/types/materialized_tenant_delivery_reports.d.ts +49 -7
- package/lib/tests/materialized-reports/analytics-growth-helpers.test.d.ts +1 -0
- package/lib/tests/materialized-reports/analytics-overview-helpers.test.d.ts +1 -0
- package/lib/tests/materialized-reports/analytics-performance-helpers.test.d.ts +1 -0
- package/lib/tests/materialized-reports/characterization/delivery.characterization.test.d.ts +1 -0
- package/lib/tests/materialized-reports/characterization/delivery.characterization.test.js +229 -0
- package/lib/tests/materialized-reports/characterization/discount.characterization.test.d.ts +1 -0
- package/lib/tests/materialized-reports/characterization/discount.characterization.test.js +99 -0
- package/lib/tests/materialized-reports/characterization/fixtures.d.ts +30 -0
- package/lib/tests/materialized-reports/characterization/fixtures.js +402 -0
- package/lib/tests/materialized-reports/characterization/golden.d.ts +18 -0
- package/lib/tests/materialized-reports/characterization/golden.js +127 -0
- package/lib/tests/materialized-reports/characterization/overview.characterization.test.d.ts +1 -0
- package/lib/tests/materialized-reports/characterization/overview.characterization.test.js +69 -0
- package/lib/tests/materialized-reports/characterization/prep-time.characterization.test.d.ts +1 -0
- package/lib/tests/materialized-reports/characterization/prep-time.characterization.test.js +102 -0
- package/lib/tests/materialized-reports/materialized-delivery-accumulation.test.js +56 -19
- package/lib/tests/materialized-reports/materialized-delivery-budgets.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-delivery-budgets.test.js +91 -0
- package/lib/tests/materialized-reports/materialized-delivery-compile.test.js +271 -15
- package/lib/tests/materialized-reports/materialized-delivery-final-audit.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-delivery-final-audit.test.js +128 -0
- package/lib/tests/materialized-reports/materialized-delivery-fold.test.js +42 -5
- package/lib/tests/materialized-reports/materialized-delivery-formatter.test.js +13 -1
- package/lib/tests/materialized-reports/materialized-delivery-geo.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-delivery-geo.test.js +446 -0
- package/lib/tests/materialized-reports/materialized-delivery-plan.test.js +117 -25
- package/lib/tests/materialized-reports/materialized-delivery-practical.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-delivery-practical.test.js +344 -0
- package/lib/tests/materialized-reports/materialized-integer-contract.test.js +14 -0
- package/lib/tests/materialized-reports/materialized-tenant-sales-overview-reports-schema.test.js +1 -1
- package/lib/tests/materialized-reports/report-platform/lifecycle-primitives.test.d.ts +1 -0
- package/lib/tests/materialized-reports/report-platform/lifecycle-primitives.test.js +177 -0
- package/lib/tests/materialized-reports/report-platform/registry-conformance.test.d.ts +1 -0
- package/lib/tests/materialized-reports/report-platform/registry-conformance.test.js +214 -0
- package/lib/tests/materialized-reports/report-platform/registry-validation.test.d.ts +1 -0
- package/lib/tests/materialized-reports/report-platform/registry-validation.test.js +103 -0
- package/lib/tests/offer-item-resolution.test.js +1 -4
- package/lib/tests/payment-collection-timestamps.test.d.ts +1 -0
- package/lib/tests/payment-collection-timestamps.test.js +71 -0
- package/package.json +6 -2
|
@@ -1,23 +1,31 @@
|
|
|
1
|
+
import { MATERIALIZED_TENANT_DELIVERY_GEO_SCOPES_COLLECTION_NAME } from '../../constants/MATERIALIZED_REPORTS';
|
|
1
2
|
import { MATERIALIZED_TENANT_CREDIT_BILLS_COLLECTION_NAME, MATERIALIZED_TENANT_CREDIT_BILLS_INDEX_OPTIONS, } from '../../schemas/models/materialized_credit_bills';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { MATERIALIZED_REPORT_DRILLDOWN_ROWS_COLLECTION_NAME, MATERIALIZED_REPORT_DRILLDOWN_ROWS_INDEX_OPTIONS, MATERIALIZED_REPORT_DRILLDOWN_SCOPES_COLLECTION_NAME, MATERIALIZED_REPORT_DRILLDOWN_SCOPES_INDEX_OPTIONS, } from '../../schemas/models/materialized_report_drilldown_rows';
|
|
4
|
+
import { MATERIALIZED_TENANT_DELIVERY_ENTRIES_COLLECTION_NAME, MATERIALIZED_TENANT_DELIVERY_ENTRIES_INDEX_OPTIONS, } from '../../schemas/models/materialized_tenant_delivery_entries';
|
|
5
|
+
import { MATERIALIZED_TENANT_DELIVERY_GEO_CELLS_COLLECTION_NAME, MATERIALIZED_TENANT_DELIVERY_GEO_CELLS_INDEX_OPTIONS, } from '../../schemas/models/materialized_tenant_delivery_geo_cells';
|
|
6
|
+
import { MATERIALIZED_TENANT_DELIVERY_GEO_SCOPES_INDEX_OPTIONS } from '../../schemas/models/materialized_tenant_delivery_geo_scopes';
|
|
7
|
+
import { MATERIALIZED_TENANT_DELIVERY_REPORTS_COLLECTION_NAME, MATERIALIZED_TENANT_DELIVERY_REPORTS_INDEX_OPTIONS, } from '../../schemas/models/materialized_tenant_delivery_reports';
|
|
8
|
+
import { MATERIALIZED_TENANT_DISCOUNT_ENTRIES_COLLECTION_NAME, MATERIALIZED_TENANT_DISCOUNT_ENTRIES_INDEX_OPTIONS, } from '../../schemas/models/materialized_tenant_discount_entries';
|
|
9
|
+
import { MATERIALIZED_TENANT_DISCOUNT_REPORTS_COLLECTION_NAME, MATERIALIZED_TENANT_DISCOUNT_REPORTS_INDEX_OPTIONS, } from '../../schemas/models/materialized_tenant_discount_reports';
|
|
10
|
+
import { MATERIALIZED_TENANT_DISCOUNT_SOURCES_COLLECTION_NAME, MATERIALIZED_TENANT_DISCOUNT_SOURCES_INDEX_OPTIONS, } from '../../schemas/models/materialized_tenant_discount_sources';
|
|
6
11
|
import { MATERIALIZED_TENANT_PREP_TIME_ENTRIES_COLLECTION_NAME, MATERIALIZED_TENANT_PREP_TIME_ENTRIES_INDEX_OPTIONS, } from '../../schemas/models/materialized_tenant_prep_time_entries';
|
|
7
12
|
import { MATERIALIZED_TENANT_PREP_TIME_REPORTS_COLLECTION_NAME, MATERIALIZED_TENANT_PREP_TIME_REPORTS_INDEX_OPTIONS, } from '../../schemas/models/materialized_tenant_prep_time_reports';
|
|
13
|
+
import { MATERIALIZED_TENANT_REPORTS_ITERATIONS_COLLECTION_NAME, MATERIALIZED_TENANT_REPORTS_ITERATIONS_INDEX_OPTIONS, } from '../../schemas/models/materialized_tenant_reports_iterations';
|
|
8
14
|
import { MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_COLLECTION_NAME, MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_INDEX_OPTIONS, } from '../../schemas/models/materialized_tenant_sales_overview_reports';
|
|
9
|
-
import { MATERIALIZED_REPORT_DRILLDOWN_ROWS_COLLECTION_NAME, MATERIALIZED_REPORT_DRILLDOWN_ROWS_INDEX_OPTIONS, MATERIALIZED_REPORT_DRILLDOWN_SCOPES_COLLECTION_NAME, MATERIALIZED_REPORT_DRILLDOWN_SCOPES_INDEX_OPTIONS, } from '../../schemas/models/materialized_report_drilldown_rows';
|
|
10
|
-
import { TENANT_CALENDAR_COLLECTION_NAME, TENANT_CALENDAR_INDEX_OPTIONS } from '../../schemas/models/tenant_calendar';
|
|
11
15
|
import { TENANT_ACTIVE_JOBS_COLLECTION_NAME, TENANT_ACTIVE_JOBS_INDEX_OPTIONS, } from '../../schemas/models/tenant_active_jobs';
|
|
16
|
+
import { TENANT_CALENDAR_COLLECTION_NAME, TENANT_CALENDAR_INDEX_OPTIONS } from '../../schemas/models/tenant_calendar';
|
|
12
17
|
/**
|
|
13
|
-
*
|
|
18
|
+
* MANUAL index helper for the materialized reads/writes.
|
|
19
|
+
*
|
|
20
|
+
* The services run with `autoIndex: false`, and the model schemas deliberately do not
|
|
21
|
+
* declare these compound indexes. This module is available for an explicit maintenance
|
|
22
|
+
* run / tests, but it is NOT called automatically after `mongoose.connect` by
|
|
23
|
+
* items/workers/operations. Indexes are an OWNER DEPLOY STEP, applied with the migration
|
|
24
|
+
* scripts before the first close/read. Do not describe this as a runtime bootstrap.
|
|
14
25
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* `.hint()` read and could create duplicate scope/year documents. This helper
|
|
19
|
-
* is called after `mongoose.connect` by items/workers/operations and fails the
|
|
20
|
-
* startup if an expected unique index is missing afterwards.
|
|
26
|
+
* For the Delivery page model, use
|
|
27
|
+
* `simulations/migrate-delivery-report-indexes.ts --apply` (it also drops the legacy
|
|
28
|
+
* entry index and creates the deliveries source and geo-scope indexes).
|
|
21
29
|
*
|
|
22
30
|
* It creates indexes with `createIndexes` (never drops unrelated indexes).
|
|
23
31
|
*/
|
|
@@ -30,6 +38,10 @@ const INDEXES = {
|
|
|
30
38
|
[MATERIALIZED_TENANT_PREP_TIME_REPORTS_COLLECTION_NAME]: MATERIALIZED_TENANT_PREP_TIME_REPORTS_INDEX_OPTIONS,
|
|
31
39
|
[MATERIALIZED_TENANT_PREP_TIME_ENTRIES_COLLECTION_NAME]: MATERIALIZED_TENANT_PREP_TIME_ENTRIES_INDEX_OPTIONS,
|
|
32
40
|
[MATERIALIZED_TENANT_REPORTS_ITERATIONS_COLLECTION_NAME]: MATERIALIZED_TENANT_REPORTS_ITERATIONS_INDEX_OPTIONS,
|
|
41
|
+
[MATERIALIZED_TENANT_DELIVERY_GEO_CELLS_COLLECTION_NAME]: MATERIALIZED_TENANT_DELIVERY_GEO_CELLS_INDEX_OPTIONS,
|
|
42
|
+
[MATERIALIZED_TENANT_DELIVERY_GEO_SCOPES_COLLECTION_NAME]: MATERIALIZED_TENANT_DELIVERY_GEO_SCOPES_INDEX_OPTIONS,
|
|
43
|
+
[MATERIALIZED_TENANT_DELIVERY_ENTRIES_COLLECTION_NAME]: MATERIALIZED_TENANT_DELIVERY_ENTRIES_INDEX_OPTIONS,
|
|
44
|
+
[MATERIALIZED_TENANT_DELIVERY_REPORTS_COLLECTION_NAME]: MATERIALIZED_TENANT_DELIVERY_REPORTS_INDEX_OPTIONS,
|
|
33
45
|
[MATERIALIZED_REPORT_DRILLDOWN_ROWS_COLLECTION_NAME]: MATERIALIZED_REPORT_DRILLDOWN_ROWS_INDEX_OPTIONS,
|
|
34
46
|
[MATERIALIZED_REPORT_DRILLDOWN_SCOPES_COLLECTION_NAME]: MATERIALIZED_REPORT_DRILLDOWN_SCOPES_INDEX_OPTIONS,
|
|
35
47
|
[TENANT_CALENDAR_COLLECTION_NAME]: TENANT_CALENDAR_INDEX_OPTIONS,
|
|
@@ -48,9 +60,12 @@ export async function ensureMaterializedReportIndexes(connection, options = {})
|
|
|
48
60
|
}
|
|
49
61
|
const collection = db.collection(collectionName);
|
|
50
62
|
const indexes = definitions.filter((definition) => definition.name !== '_id_');
|
|
51
|
-
// One-time migration for
|
|
52
|
-
//
|
|
53
|
-
|
|
63
|
+
// One-time migration for a per-SCOPE entry identity index. A PAGE design cannot
|
|
64
|
+
// coexist with a unique index that omits `page` (all period pages share
|
|
65
|
+
// `day_index: null`, so the legacy index would reject the second page of a month).
|
|
66
|
+
// Discounts and Delivery entries have the same migration.
|
|
67
|
+
if (collectionName === MATERIALIZED_TENANT_DISCOUNT_ENTRIES_COLLECTION_NAME ||
|
|
68
|
+
collectionName === MATERIALIZED_TENANT_DELIVERY_ENTRIES_COLLECTION_NAME) {
|
|
54
69
|
const existing = await collection
|
|
55
70
|
.listIndexes()
|
|
56
71
|
.toArray()
|
|
@@ -44,6 +44,15 @@ const IDENTIFIER_FIELD = /^(scope_field|day_index|key|_id|.*_id)$/;
|
|
|
44
44
|
* numeric-looking string when it sits in a field that is not one of these.
|
|
45
45
|
*/
|
|
46
46
|
const TEXT_FIELD = /(name|label|title|reason|note|description|reference|reference_number|code|currency|platform|status|type|source_key|order_number)$/i;
|
|
47
|
+
/**
|
|
48
|
+
* GEOMETRY leaves are the one exception to the integer-only contract.
|
|
49
|
+
*
|
|
50
|
+
* `location.coordinates` is a GeoJSON `[lng, lat]` pair - a POSITION, not a stored
|
|
51
|
+
* measurement. Rounding it to an integer would move a heat cell's centroid by up to a
|
|
52
|
+
* degree, and the 2dsphere index needs the real value. Every OTHER numeric leaf of a
|
|
53
|
+
* materialized document (counts, cents, minutes, basis points) stays integer-only.
|
|
54
|
+
*/
|
|
55
|
+
const GEOMETRY_COORDINATE_PATH = /(^|\.)coordinates\[\d+\]$/;
|
|
47
56
|
/**
|
|
48
57
|
* BSON values: only IDENTITY types are ignored. A numeric BSON value
|
|
49
58
|
* (Decimal128 / Long / Double / Int32) is storage of a number and must obey the
|
|
@@ -106,7 +115,7 @@ export function findNonIntegerNumericLeaves(document) {
|
|
|
106
115
|
violations.push({ path, value: node, reason: 'non-finite' });
|
|
107
116
|
return;
|
|
108
117
|
}
|
|
109
|
-
if (!Number.isInteger(node)) {
|
|
118
|
+
if (!Number.isInteger(node) && !GEOMETRY_COORDINATE_PATH.test(path)) {
|
|
110
119
|
violations.push({ path, value: node, reason: 'decimal' });
|
|
111
120
|
}
|
|
112
121
|
return;
|
|
@@ -3,7 +3,7 @@ import { MATERIALIZED_PREP_TIME_ITEM_SCOPES, MATERIALIZED_PREP_TIME_REPORT_SCOPE
|
|
|
3
3
|
import { freshMaterializedPrepTimeCounters } from './materialized-prep-time-classification-helpers';
|
|
4
4
|
import { mergeMaterializedPrepTimeCounters } from './materialized-prep-time-compile-helpers';
|
|
5
5
|
import { buildMaterializedTenantReportIteration } from './materialized-tenant-reports-iterations-helpers';
|
|
6
|
-
import {
|
|
6
|
+
import { enumerateMaterializedPeriodDays, getMaterializedPeriodScopeFields, } from './scope-helpers';
|
|
7
7
|
/**
|
|
8
8
|
* M2 close-day helpers.
|
|
9
9
|
*
|
|
@@ -159,94 +159,6 @@ export const MATERIALIZED_PREP_TIME_ITEM_PERIOD_SCOPES = MATERIALIZED_PREP_TIME_
|
|
|
159
159
|
/* ------------------------------------------------------------------------ */
|
|
160
160
|
/* Period sibling-day enumeration */
|
|
161
161
|
/* ------------------------------------------------------------------------ */
|
|
162
|
-
const pad2 = (value) => String(value).padStart(2, '0');
|
|
163
|
-
const toLocalDateKey = (date) => `${date.getUTCFullYear()}-${pad2(date.getUTCMonth() + 1)}-${pad2(date.getUTCDate())}`;
|
|
164
|
-
const addUtcDays = (date, amount) => new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate() + amount));
|
|
165
|
-
const addMonthDays = (year, month, count, days) => {
|
|
166
|
-
if (!Number.isInteger(year) || !Number.isInteger(month) || month < 1 || month > 12)
|
|
167
|
-
return false;
|
|
168
|
-
for (let offset = 0; offset < count; offset += 1) {
|
|
169
|
-
const date = new Date(Date.UTC(year, month - 1 + offset, 1));
|
|
170
|
-
const monthYear = date.getUTCFullYear();
|
|
171
|
-
const monthNumber = date.getUTCMonth() + 1;
|
|
172
|
-
const last = new Date(Date.UTC(monthYear, monthNumber, 0)).getUTCDate();
|
|
173
|
-
for (let day = 1; day <= last; day += 1) {
|
|
174
|
-
days.add(`${monthYear}-${pad2(monthNumber)}-${pad2(day)}`);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return true;
|
|
178
|
-
};
|
|
179
|
-
const addPeriodDays = (scope, scopeField, days) => {
|
|
180
|
-
switch (scope) {
|
|
181
|
-
case MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_WEEK: {
|
|
182
|
-
const parts = parseMaterializedLocalDate(scopeField);
|
|
183
|
-
if (parts == null)
|
|
184
|
-
return false;
|
|
185
|
-
const start = new Date(Date.UTC(parts.year, parts.month - 1, parts.day));
|
|
186
|
-
if (start.getUTCDay() !== 0)
|
|
187
|
-
return false;
|
|
188
|
-
for (let offset = 0; offset < 7; offset += 1)
|
|
189
|
-
days.add(toLocalDateKey(addUtcDays(start, offset)));
|
|
190
|
-
return true;
|
|
191
|
-
}
|
|
192
|
-
case MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_WEEK_OF_YEAR: {
|
|
193
|
-
const match = /^(\d{4})-W(\d{2})$/.exec(scopeField);
|
|
194
|
-
if (match == null)
|
|
195
|
-
return false;
|
|
196
|
-
const weekYear = Number(match[1]);
|
|
197
|
-
const week = Number(match[2]);
|
|
198
|
-
if (!Number.isInteger(week) || week < 1 || week > 53)
|
|
199
|
-
return false;
|
|
200
|
-
const jan4 = new Date(Date.UTC(weekYear, 0, 4));
|
|
201
|
-
const isoWeekday = jan4.getUTCDay() || 7;
|
|
202
|
-
const weekOneMonday = addUtcDays(jan4, 1 - isoWeekday);
|
|
203
|
-
const start = addUtcDays(weekOneMonday, (week - 1) * 7);
|
|
204
|
-
for (let offset = 0; offset < 7; offset += 1)
|
|
205
|
-
days.add(toLocalDateKey(addUtcDays(start, offset)));
|
|
206
|
-
return true;
|
|
207
|
-
}
|
|
208
|
-
case MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_MONTH: {
|
|
209
|
-
const match = /^(\d{4})-(\d{2})$/.exec(scopeField);
|
|
210
|
-
if (match == null)
|
|
211
|
-
return false;
|
|
212
|
-
return addMonthDays(Number(match[1]), Number(match[2]), 1, days);
|
|
213
|
-
}
|
|
214
|
-
case MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_QUARTER: {
|
|
215
|
-
const match = /^(\d{4})-Q([1-4])$/.exec(scopeField);
|
|
216
|
-
if (match == null)
|
|
217
|
-
return false;
|
|
218
|
-
return addMonthDays(Number(match[1]), (Number(match[2]) - 1) * 3 + 1, 3, days);
|
|
219
|
-
}
|
|
220
|
-
case MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_SEMESTER: {
|
|
221
|
-
const match = /^(\d{4})-S([12])$/.exec(scopeField);
|
|
222
|
-
if (match == null)
|
|
223
|
-
return false;
|
|
224
|
-
return addMonthDays(Number(match[1]), (Number(match[2]) - 1) * 6 + 1, 6, days);
|
|
225
|
-
}
|
|
226
|
-
case MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_YEAR: {
|
|
227
|
-
const match = /^(\d{4})$/.exec(scopeField);
|
|
228
|
-
if (match == null)
|
|
229
|
-
return false;
|
|
230
|
-
return addMonthDays(Number(match[1]), 1, 12, days);
|
|
231
|
-
}
|
|
232
|
-
default:
|
|
233
|
-
return false;
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
const enumeratePeriodDays = (localDate, scopes) => {
|
|
237
|
-
const periodFields = getMaterializedPeriodScopeFields(localDate);
|
|
238
|
-
if (periodFields == null)
|
|
239
|
-
return null;
|
|
240
|
-
const days = new Set([localDate]);
|
|
241
|
-
for (const scope of scopes) {
|
|
242
|
-
const scopeField = periodFields[scope];
|
|
243
|
-
if (typeof scopeField !== 'string' || scopeField.length === 0)
|
|
244
|
-
return null;
|
|
245
|
-
if (!addPeriodDays(scope, scopeField, days))
|
|
246
|
-
return null;
|
|
247
|
-
}
|
|
248
|
-
return [...days].sort();
|
|
249
|
-
};
|
|
250
162
|
/**
|
|
251
163
|
* Every `localDate` label whose DAY entry document can contribute to a
|
|
252
164
|
* month-capped period (week / ISO week / month). The worker uses this to fetch
|
|
@@ -254,7 +166,7 @@ const enumeratePeriodDays = (localDate, scopes) => {
|
|
|
254
166
|
* entry document and never a year-wide scan.
|
|
255
167
|
*/
|
|
256
168
|
export function getMaterializedPrepTimePeriodDayScopeFields(localDate) {
|
|
257
|
-
return
|
|
169
|
+
return enumerateMaterializedPeriodDays(localDate, MATERIALIZED_PREP_TIME_ITEM_PERIOD_SCOPES);
|
|
258
170
|
}
|
|
259
171
|
/**
|
|
260
172
|
* Every `localDate` label whose DAY counter document can contribute to ANY
|
|
@@ -263,7 +175,7 @@ export function getMaterializedPrepTimePeriodDayScopeFields(localDate) {
|
|
|
263
175
|
* month-capped.
|
|
264
176
|
*/
|
|
265
177
|
export function getMaterializedPrepTimeReportPeriodDayScopeFields(localDate) {
|
|
266
|
-
return
|
|
178
|
+
return enumerateMaterializedPeriodDays(localDate, MATERIALIZED_PREP_TIME_PERIOD_SCOPES);
|
|
267
179
|
}
|
|
268
180
|
/** True when a stored prep counter document equals the incoming one (skip write). */
|
|
269
181
|
export function needsMaterializedPrepTimeReportWrite(existing, incoming) {
|