@managesome/eposmatic-toolkit 0.4.53 → 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/helpers/materialized-reports/index.js +1 -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/lib/helpers/materialized-reports/index.d.ts +1 -0
- package/lib/helpers/materialized-reports/index.js +1 -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/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/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/package.json +4 -2
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { buildMaterializedDrilldownRows, buildMaterializedDrilldownScope, } from '../../materialized-report-drilldown-rows';
|
|
2
|
+
export function buildReportFlatProjectionPlan(input) {
|
|
3
|
+
if (input.entryDocument == null)
|
|
4
|
+
return null;
|
|
5
|
+
const retargeted = {
|
|
6
|
+
...input.entryDocument,
|
|
7
|
+
scope_context: input.scopeContext,
|
|
8
|
+
scope_field: input.scopeField,
|
|
9
|
+
day_index: input.dayIndex ?? null,
|
|
10
|
+
};
|
|
11
|
+
const flattened = buildMaterializedDrilldownRows(input.reportType, retargeted, input.sourceLocalDate ?? null);
|
|
12
|
+
const scope = buildMaterializedDrilldownScope(input.reportType, retargeted, flattened.rows, input.sourceLocalDate ?? null);
|
|
13
|
+
return { rows: flattened.rows, scope };
|
|
14
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { buildMaterializedTenantReportIteration } from '../../materialized-tenant-reports-iterations-helpers';
|
|
2
|
+
/**
|
|
3
|
+
* PHASE 2 — generic iteration-row builder.
|
|
4
|
+
*
|
|
5
|
+
* Thin composition over the existing builder so later phases have one place to
|
|
6
|
+
* pass a registry report type. The existing builder remains the source of truth.
|
|
7
|
+
*/
|
|
8
|
+
export function buildReportIterationRow(report, options) {
|
|
9
|
+
return buildMaterializedTenantReportIteration(report, options);
|
|
10
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export const EMPTY_REPORT_RUN_STATS = {
|
|
2
|
+
reportKey: '',
|
|
3
|
+
localDate: '',
|
|
4
|
+
documents: 0,
|
|
5
|
+
entryDocuments: 0,
|
|
6
|
+
entryPages: 0,
|
|
7
|
+
flatRows: 0,
|
|
8
|
+
flatScopes: 0,
|
|
9
|
+
geoCells: 0,
|
|
10
|
+
iterationRows: 0,
|
|
11
|
+
deletes: 0,
|
|
12
|
+
cappedCells: 0,
|
|
13
|
+
cappedOrders: 0,
|
|
14
|
+
skipped: 0,
|
|
15
|
+
warnings: [],
|
|
16
|
+
};
|
|
17
|
+
export function buildReportRunStats(input) {
|
|
18
|
+
return {
|
|
19
|
+
...EMPTY_REPORT_RUN_STATS,
|
|
20
|
+
...input,
|
|
21
|
+
warnings: [...(input.warnings ?? [])],
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export function mergeReportRunStats(left, right) {
|
|
25
|
+
const sum = (key) => Number(left[key] ?? 0) + Number(right[key] ?? 0);
|
|
26
|
+
return {
|
|
27
|
+
reportKey: left.reportKey === right.reportKey ? left.reportKey : `${left.reportKey}+${right.reportKey}`,
|
|
28
|
+
localDate: left.localDate === right.localDate ? left.localDate : `${left.localDate}+${right.localDate}`,
|
|
29
|
+
documents: sum('documents'),
|
|
30
|
+
entryDocuments: sum('entryDocuments'),
|
|
31
|
+
entryPages: sum('entryPages'),
|
|
32
|
+
flatRows: sum('flatRows'),
|
|
33
|
+
flatScopes: sum('flatScopes'),
|
|
34
|
+
geoCells: sum('geoCells'),
|
|
35
|
+
iterationRows: sum('iterationRows'),
|
|
36
|
+
deletes: sum('deletes'),
|
|
37
|
+
cappedCells: sum('cappedCells'),
|
|
38
|
+
cappedOrders: sum('cappedOrders'),
|
|
39
|
+
skipped: sum('skipped'),
|
|
40
|
+
warnings: [...left.warnings, ...right.warnings],
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { MATERIALIZED_REPORT_SCOPE_ENUM } from '../../../../constants/MATERIALIZED_REPORTS';
|
|
2
|
+
import { getMaterializedHourScopeField, getMaterializedPeriodScopeFields } from '../../scope-helpers';
|
|
3
|
+
export function resolveReportScopeRefsForDay(definition, localDate) {
|
|
4
|
+
const periodFields = getMaterializedPeriodScopeFields(localDate);
|
|
5
|
+
if (periodFields == null)
|
|
6
|
+
return null;
|
|
7
|
+
const refs = [];
|
|
8
|
+
for (const [scopeContext, scopeField] of Object.entries(periodFields)) {
|
|
9
|
+
if (definition.reportScopes.includes(scopeContext)) {
|
|
10
|
+
refs.push({
|
|
11
|
+
scope_context: scopeContext,
|
|
12
|
+
scope_field: scopeField,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (definition.reportScopes.includes(MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_HOUR)) {
|
|
17
|
+
for (let hour = 0; hour < 24; hour += 1) {
|
|
18
|
+
const scopeField = getMaterializedHourScopeField(localDate, hour);
|
|
19
|
+
if (scopeField == null)
|
|
20
|
+
return null;
|
|
21
|
+
refs.push({
|
|
22
|
+
scope_context: MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_HOUR,
|
|
23
|
+
scope_field: scopeField,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return refs;
|
|
28
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** PHASE 2 — deterministic top-N + reserved overflow token. */
|
|
2
|
+
export const REPORT_OTHER_TOKEN = '__OTHER__';
|
|
3
|
+
/**
|
|
4
|
+
* Selects the top-N keys by `count DESC, key ASC` and folds the rest into the
|
|
5
|
+
* reserved `__OTHER__` token. Generic; report-specific mapping stays report-owned.
|
|
6
|
+
*/
|
|
7
|
+
export function selectReportTopN(entries, limit, otherToken = REPORT_OTHER_TOKEN) {
|
|
8
|
+
const counts = new Map();
|
|
9
|
+
for (const entry of entries ?? []) {
|
|
10
|
+
if (entry == null || typeof entry.key !== 'string' || entry.key === '')
|
|
11
|
+
continue;
|
|
12
|
+
counts.set(entry.key, (counts.get(entry.key) ?? 0) + (Number(entry.count) || 0));
|
|
13
|
+
}
|
|
14
|
+
const ranked = [...counts.entries()].sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0));
|
|
15
|
+
if (ranked.length <= Math.max(1, limit)) {
|
|
16
|
+
return { kept: ranked.map(([key]) => key), dropped: [], other: null };
|
|
17
|
+
}
|
|
18
|
+
const kept = ranked.slice(0, Math.max(1, limit)).map(([key]) => key);
|
|
19
|
+
const dropped = ranked.slice(Math.max(1, limit)).map(([key]) => key);
|
|
20
|
+
return { kept, dropped, other: otherToken };
|
|
21
|
+
}
|
|
22
|
+
export function resolveReportTopNKey(selection, key) {
|
|
23
|
+
return selection.other != null && selection.dropped.includes(key) ? selection.other : key;
|
|
24
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ALL_REPORT_KEYS } from '../../reporting-contract/report-contract';
|
|
2
|
+
import { PRODUCTION_REPORT_DEFINITIONS, REPORT_DEFINITIONS, REPORT_DEFINITION_STATUS, REPORT_REGISTRY_EXEMPTIONS, } from './definition';
|
|
3
|
+
/**
|
|
4
|
+
* PHASE 2 — the metadata registry lookup surface.
|
|
5
|
+
*
|
|
6
|
+
* Pure lookups only; no side effects and no service imports.
|
|
7
|
+
*/
|
|
8
|
+
export const REPORT_REGISTRY_KEYS = ALL_REPORT_KEYS;
|
|
9
|
+
export function getReportDefinition(key) {
|
|
10
|
+
return REPORT_DEFINITIONS[String(key)] ?? null;
|
|
11
|
+
}
|
|
12
|
+
export function getReportExemption(key) {
|
|
13
|
+
return REPORT_REGISTRY_EXEMPTIONS[String(key)] ?? null;
|
|
14
|
+
}
|
|
15
|
+
export function isProductionReportKey(key) {
|
|
16
|
+
return getReportDefinition(key)?.status === REPORT_DEFINITION_STATUS.PRODUCTION;
|
|
17
|
+
}
|
|
18
|
+
export function getProductionReportDefinitions() {
|
|
19
|
+
return [...PRODUCTION_REPORT_DEFINITIONS];
|
|
20
|
+
}
|
|
21
|
+
export function getReportDefinitionBySegment(segment) {
|
|
22
|
+
return PRODUCTION_REPORT_DEFINITIONS.find((definition) => definition.segment === segment) ?? null;
|
|
23
|
+
}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { ALL_MATERIALIZED_REPORT_SCOPES, ALL_MATERIALIZED_REPORT_TYPES, } from '../../../constants/MATERIALIZED_REPORTS';
|
|
2
|
+
import { ALL_REPORT_KEYS, REPORT_CAPABILITIES, REPORT_ROUTE_SEGMENTS } from '../../reporting-contract/report-contract';
|
|
3
|
+
import { REPORT_DEFINITIONS, REPORT_DEFINITION_STATUS, REPORT_ENTRY_SPLIT, REPORT_ENTRY_STORAGE, REPORT_PROJECTION, REPORT_REGISTRY_EXEMPTIONS, } from './definition';
|
|
4
|
+
const MATERIALIZED_PREFIX = 'materialized_';
|
|
5
|
+
const isPositiveInteger = (value) => typeof value === 'number' && Number.isInteger(value) && value > 0;
|
|
6
|
+
const isNonEmptyString = (value) => typeof value === 'string' && value.trim() !== '';
|
|
7
|
+
function validateCollection(definition, label, collection, errors, warnings) {
|
|
8
|
+
if (!isNonEmptyString(collection.name)) {
|
|
9
|
+
errors.push(`${definition.key}: ${label} has no collection name`);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (!collection.name.startsWith(MATERIALIZED_PREFIX)) {
|
|
13
|
+
errors.push(`${definition.key}: ${label} collection "${collection.name}" is not a materialized_* collection`);
|
|
14
|
+
}
|
|
15
|
+
if (!isPositiveInteger(collection.schemaVersion)) {
|
|
16
|
+
errors.push(`${definition.key}: ${label} has no positive schema version`);
|
|
17
|
+
}
|
|
18
|
+
if (!isPositiveInteger(collection.budgetBytes)) {
|
|
19
|
+
errors.push(`${definition.key}: ${label} has no positive budget`);
|
|
20
|
+
}
|
|
21
|
+
if (!isNonEmptyString(collection.indexOwner)) {
|
|
22
|
+
errors.push(`${definition.key}: ${label} has no index ownership`);
|
|
23
|
+
}
|
|
24
|
+
if (collection.validatorFile == null && !isNonEmptyString(collection.validatorDebt)) {
|
|
25
|
+
errors.push(`${definition.key}: ${label} has neither a validator file nor a declared validator debt`);
|
|
26
|
+
}
|
|
27
|
+
if (collection.validatorFile == null && isNonEmptyString(collection.validatorDebt)) {
|
|
28
|
+
warnings.push(`${definition.key}: ${label} validator debt: ${collection.validatorDebt}`);
|
|
29
|
+
}
|
|
30
|
+
if (definition.budgets[collection.name] == null || !isPositiveInteger(definition.budgets[collection.name])) {
|
|
31
|
+
errors.push(`${definition.key}: collection "${collection.name}" has no budget declaration in budgets`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function validateScopes(definition, label, scopes, errors) {
|
|
35
|
+
if (scopes.length === 0) {
|
|
36
|
+
errors.push(`${definition.key}: ${label} has no scopes`);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const seen = new Set();
|
|
40
|
+
for (const scope of scopes) {
|
|
41
|
+
if (!ALL_MATERIALIZED_REPORT_SCOPES.includes(scope)) {
|
|
42
|
+
errors.push(`${definition.key}: ${label} has unknown scope "${String(scope)}"`);
|
|
43
|
+
}
|
|
44
|
+
if (seen.has(String(scope))) {
|
|
45
|
+
errors.push(`${definition.key}: ${label} repeats scope "${String(scope)}"`);
|
|
46
|
+
}
|
|
47
|
+
seen.add(String(scope));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export function validateReportRegistry(input = {}) {
|
|
51
|
+
const definitions = input.definitions ?? REPORT_DEFINITIONS;
|
|
52
|
+
const exemptions = input.exemptions ?? REPORT_REGISTRY_EXEMPTIONS;
|
|
53
|
+
const keys = input.keys ?? ALL_REPORT_KEYS;
|
|
54
|
+
const errors = [];
|
|
55
|
+
const warnings = [];
|
|
56
|
+
for (const key of keys) {
|
|
57
|
+
const definition = definitions[key];
|
|
58
|
+
const exemption = exemptions[key];
|
|
59
|
+
if (definition == null && exemption == null) {
|
|
60
|
+
errors.push(`${key}: no report definition and no explicit exemption`);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (definition != null && exemption != null) {
|
|
64
|
+
errors.push(`${key}: both a report definition and an exemption exist`);
|
|
65
|
+
}
|
|
66
|
+
if (definition == null)
|
|
67
|
+
continue;
|
|
68
|
+
if (definition.key !== key) {
|
|
69
|
+
errors.push(`${key}: definition key is "${definition.key}"`);
|
|
70
|
+
}
|
|
71
|
+
if (definition.status !== REPORT_DEFINITION_STATUS.PRODUCTION &&
|
|
72
|
+
definition.status !== REPORT_DEFINITION_STATUS.READ_ONLY) {
|
|
73
|
+
errors.push(`${key}: a concrete definition must be PRODUCTION or READ_ONLY`);
|
|
74
|
+
}
|
|
75
|
+
if (!isNonEmptyString(definition.owner))
|
|
76
|
+
errors.push(`${key}: no owner`);
|
|
77
|
+
if (!ALL_MATERIALIZED_REPORT_TYPES.includes(definition.reportType)) {
|
|
78
|
+
errors.push(`${key}: unknown report type "${String(definition.reportType)}"`);
|
|
79
|
+
}
|
|
80
|
+
if (definition.segment !== REPORT_ROUTE_SEGMENTS[definition.key]) {
|
|
81
|
+
errors.push(`${key}: segment "${definition.segment}" disagrees with REPORT_ROUTE_SEGMENTS`);
|
|
82
|
+
}
|
|
83
|
+
const expectedCapabilities = REPORT_CAPABILITIES[definition.key];
|
|
84
|
+
if (expectedCapabilities == null ||
|
|
85
|
+
expectedCapabilities.live !== definition.capabilities.live ||
|
|
86
|
+
expectedCapabilities.historical !== definition.capabilities.historical ||
|
|
87
|
+
expectedCapabilities.details !== definition.capabilities.details) {
|
|
88
|
+
errors.push(`${key}: capabilities disagree with REPORT_CAPABILITIES`);
|
|
89
|
+
}
|
|
90
|
+
validateCollection(definition, 'report', definition.report, errors, warnings);
|
|
91
|
+
if (definition.entries != null) {
|
|
92
|
+
validateCollection(definition, 'entries', definition.entries, errors, warnings);
|
|
93
|
+
}
|
|
94
|
+
for (const side of definition.sideCollections) {
|
|
95
|
+
validateCollection(definition, 'side', side, errors, warnings);
|
|
96
|
+
}
|
|
97
|
+
const allCollections = [
|
|
98
|
+
definition.report,
|
|
99
|
+
...(definition.entries == null ? [] : [definition.entries]),
|
|
100
|
+
...definition.sideCollections,
|
|
101
|
+
].map((collection) => collection.name);
|
|
102
|
+
for (const collectionName of Object.keys(definition.budgets)) {
|
|
103
|
+
if (!allCollections.includes(collectionName)) {
|
|
104
|
+
warnings.push(`${key}: budget declared for unknown collection "${collectionName}"`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
validateScopes(definition, 'reportScopes', definition.reportScopes, errors);
|
|
108
|
+
if (definition.entryScopes.length > 0 || definition.entryStorage !== REPORT_ENTRY_STORAGE.NONE) {
|
|
109
|
+
validateScopes(definition, 'entryScopes', definition.entryScopes, errors);
|
|
110
|
+
}
|
|
111
|
+
if (!definition.reportScopes.includes(definition.maxReportScope)) {
|
|
112
|
+
errors.push(`${key}: maxReportScope is not a declared report scope`);
|
|
113
|
+
}
|
|
114
|
+
if (definition.maxEntryScope != null && !definition.entryScopes.includes(definition.maxEntryScope)) {
|
|
115
|
+
errors.push(`${key}: maxEntryScope is not a declared entry scope`);
|
|
116
|
+
}
|
|
117
|
+
for (const scope of definition.entryScopes) {
|
|
118
|
+
if (!definition.reportScopes.includes(scope)) {
|
|
119
|
+
errors.push(`${key}: entry scope "${scope}" is outside reportScopes`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (definition.entryStorage === REPORT_ENTRY_STORAGE.NONE) {
|
|
123
|
+
if (definition.entries != null) {
|
|
124
|
+
errors.push(`${key}: entryStorage NONE must not declare an entry collection`);
|
|
125
|
+
}
|
|
126
|
+
if (definition.entryScopes.length !== 0) {
|
|
127
|
+
errors.push(`${key}: entryStorage NONE must not declare entry scopes`);
|
|
128
|
+
}
|
|
129
|
+
if (definition.entrySplit !== REPORT_ENTRY_SPLIT.NONE) {
|
|
130
|
+
errors.push(`${key}: entryStorage NONE must not split pages`);
|
|
131
|
+
}
|
|
132
|
+
if (definition.maxEntryScope != null) {
|
|
133
|
+
errors.push(`${key}: entryStorage NONE must not declare maxEntryScope`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
if (definition.entries == null) {
|
|
138
|
+
errors.push(`${key}: entry storage requires an entry collection`);
|
|
139
|
+
}
|
|
140
|
+
if (definition.entryScopes.length === 0) {
|
|
141
|
+
errors.push(`${key}: entry storage requires entry scopes`);
|
|
142
|
+
}
|
|
143
|
+
if (definition.maxEntryScope == null) {
|
|
144
|
+
errors.push(`${key}: entry storage requires maxEntryScope`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (definition.entrySplit === REPORT_ENTRY_SPLIT.DETERMINISTIC_SUBPAGES &&
|
|
148
|
+
definition.entryStorage !== REPORT_ENTRY_STORAGE.PAGE_PER_SOURCE_DAY) {
|
|
149
|
+
errors.push(`${key}: #N splitting requires page-per-source-day entries`);
|
|
150
|
+
}
|
|
151
|
+
if (definition.projections.includes(REPORT_PROJECTION.FLAT_DRILLDOWN)) {
|
|
152
|
+
const names = definition.sideCollections.map((collection) => collection.name);
|
|
153
|
+
if (!names.includes('materialized_report_drilldown_rows') ||
|
|
154
|
+
!names.includes('materialized_report_drilldown_scopes')) {
|
|
155
|
+
errors.push(`${key}: FLAT_DRILLDOWN requires both flat collections`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (definition.projections.includes(REPORT_PROJECTION.DISCOUNT_SOURCES) &&
|
|
159
|
+
!definition.sideCollections.some((collection) => collection.name === 'materialized_tenant_discount_sources')) {
|
|
160
|
+
errors.push(`${key}: DISCOUNT_SOURCES requires the source collection`);
|
|
161
|
+
}
|
|
162
|
+
if (definition.projections.includes(REPORT_PROJECTION.DELIVERY_GEO)) {
|
|
163
|
+
const names = definition.sideCollections.map((collection) => collection.name);
|
|
164
|
+
if (!names.includes('materialized_tenant_delivery_geo_cells') ||
|
|
165
|
+
!names.includes('materialized_tenant_delivery_geo_scopes')) {
|
|
166
|
+
errors.push(`${key}: DELIVERY_GEO requires cells + cap metadata`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (definition.capabilities.details &&
|
|
170
|
+
(definition.adapters.details == null || !isNonEmptyString(definition.adapters.details))) {
|
|
171
|
+
errors.push(`${key}: capabilities.details is true but no details adapter is declared`);
|
|
172
|
+
}
|
|
173
|
+
if (!definition.capabilities.details && definition.adapters.details != null) {
|
|
174
|
+
errors.push(`${key}: details adapter declared without details capability`);
|
|
175
|
+
}
|
|
176
|
+
if (!isNonEmptyString(definition.adapters.writer))
|
|
177
|
+
errors.push(`${key}: no writer adapter`);
|
|
178
|
+
if (!isNonEmptyString(definition.adapters.live))
|
|
179
|
+
errors.push(`${key}: no live adapter`);
|
|
180
|
+
if (!isNonEmptyString(definition.adapters.historical)) {
|
|
181
|
+
errors.push(`${key}: no historical adapter`);
|
|
182
|
+
}
|
|
183
|
+
if (definition.completeness.details === 'FLAT_PROJECTION' &&
|
|
184
|
+
!definition.projections.includes(REPORT_PROJECTION.FLAT_DRILLDOWN)) {
|
|
185
|
+
errors.push(`${key}: details completeness requires the flat projection`);
|
|
186
|
+
}
|
|
187
|
+
if (definition.filters.length === 0) {
|
|
188
|
+
errors.push(`${key}: no filter definitions`);
|
|
189
|
+
}
|
|
190
|
+
for (const filter of definition.filters) {
|
|
191
|
+
if (!isNonEmptyString(filter.id))
|
|
192
|
+
errors.push(`${key}: filter without an id`);
|
|
193
|
+
if (filter.mode !== 'CLIENT' && filter.mode !== 'SERVER') {
|
|
194
|
+
errors.push(`${key}: filter "${filter.id}" has an invalid mode`);
|
|
195
|
+
}
|
|
196
|
+
if (!['SUMMARY', 'DETAILS', 'BOTH'].includes(filter.appliesTo)) {
|
|
197
|
+
errors.push(`${key}: filter "${filter.id}" has an invalid appliesTo`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (definition.capabilities.details && definition.cursor === 'NONE') {
|
|
201
|
+
warnings.push(`${key}: details capability but cursor NONE`);
|
|
202
|
+
}
|
|
203
|
+
for (const rule of definition.retention) {
|
|
204
|
+
if (!allCollections.includes(rule.collection)) {
|
|
205
|
+
errors.push(`${key}: retention targets an unknown collection "${rule.collection}"`);
|
|
206
|
+
}
|
|
207
|
+
if (!isPositiveInteger(rule.amount)) {
|
|
208
|
+
errors.push(`${key}: retention amount must be a positive integer`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return { ok: errors.length === 0, errors, warnings };
|
|
213
|
+
}
|
|
214
|
+
export const REPORT_REGISTRY_VALIDATION = validateReportRegistry();
|
|
@@ -69,3 +69,4 @@ __exportStar(require("./tenant-delivery-formatter"), exports);
|
|
|
69
69
|
__exportStar(require("./tenant-prep-time-formatter"), exports);
|
|
70
70
|
__exportStar(require("./tenant-sales-overview-formatter"), exports);
|
|
71
71
|
__exportStar(require("./tenant-sales-overview-helpers"), exports);
|
|
72
|
+
__exportStar(require("./report-platform"), exports);
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { MATERIALIZED_REPORT_SCOPE_ENUM, MATERIALIZED_REPORT_TYPE_ENUM } from '../../../constants/MATERIALIZED_REPORTS';
|
|
2
|
+
import { REPORT_KEY_ENUM, type IReportCapabilities } from '../../reporting-contract/report-contract';
|
|
3
|
+
/**
|
|
4
|
+
* PHASE 2 — DECLARATIVE REPORT DEFINITIONS.
|
|
5
|
+
*
|
|
6
|
+
* This module is METADATA ONLY. It must not import Mongoose, Express, database
|
|
7
|
+
* code, workers-service or operations-service. Metric compilation, document
|
|
8
|
+
* schemas and formatters stay report-specific.
|
|
9
|
+
*
|
|
10
|
+
* Schema versions are declared as literals here so this module stays free of
|
|
11
|
+
* schema/model imports. The conformance suite compares every literal with the
|
|
12
|
+
* exported model constant; drift fails the build.
|
|
13
|
+
*/
|
|
14
|
+
export declare enum REPORT_DEFINITION_STATUS {
|
|
15
|
+
PRODUCTION = "PRODUCTION",
|
|
16
|
+
READ_ONLY = "READ_ONLY",
|
|
17
|
+
PLANNED = "PLANNED"
|
|
18
|
+
}
|
|
19
|
+
export declare enum REPORT_ENTRY_STORAGE {
|
|
20
|
+
/** No itemized collection. */
|
|
21
|
+
NONE = "NONE",
|
|
22
|
+
/** One entry document per (tenant, scope, field); Prep Time today. */
|
|
23
|
+
ONE_PER_SCOPE = "ONE_PER_SCOPE",
|
|
24
|
+
/** One entry document per source day; Discounts and Delivery today. */
|
|
25
|
+
PAGE_PER_SOURCE_DAY = "PAGE_PER_SOURCE_DAY"
|
|
26
|
+
}
|
|
27
|
+
export declare enum REPORT_ENTRY_SPLIT {
|
|
28
|
+
NONE = "NONE",
|
|
29
|
+
/** Deterministic `page#0`, `page#1`, ... when one page exceeds its budget. */
|
|
30
|
+
DETERMINISTIC_SUBPAGES = "DETERMINISTIC_SUBPAGES"
|
|
31
|
+
}
|
|
32
|
+
export declare enum REPORT_WRITE_GUARD {
|
|
33
|
+
NONE = "NONE",
|
|
34
|
+
WATERMARK = "WATERMARK",
|
|
35
|
+
WATERMARK_AND_DIGEST = "WATERMARK_AND_DIGEST"
|
|
36
|
+
}
|
|
37
|
+
export declare enum REPORT_LIVE_SOURCE {
|
|
38
|
+
RAW = "RAW",
|
|
39
|
+
RAW_PLUS_MATERIALIZED = "RAW_PLUS_MATERIALIZED"
|
|
40
|
+
}
|
|
41
|
+
export declare enum REPORT_HISTORICAL_LENS {
|
|
42
|
+
DOCUMENT_FOLD = "DOCUMENT_FOLD",
|
|
43
|
+
COUNTER_ROWS = "COUNTER_ROWS"
|
|
44
|
+
}
|
|
45
|
+
export declare enum REPORT_CURSOR_KIND {
|
|
46
|
+
NONE = "NONE",
|
|
47
|
+
KEYSET_STRUCTURED = "KEYSET_STRUCTURED",
|
|
48
|
+
SIGNED_QUERY = "SIGNED_QUERY"
|
|
49
|
+
}
|
|
50
|
+
export declare enum REPORT_PROJECTION {
|
|
51
|
+
FLAT_DRILLDOWN = "FLAT_DRILLDOWN",
|
|
52
|
+
DISCOUNT_SOURCES = "DISCOUNT_SOURCES",
|
|
53
|
+
DELIVERY_GEO = "DELIVERY_GEO"
|
|
54
|
+
}
|
|
55
|
+
export declare enum REPORT_RETENTION_UNIT {
|
|
56
|
+
DAY = "DAY",
|
|
57
|
+
MONTH = "MONTH"
|
|
58
|
+
}
|
|
59
|
+
export type TReportFilterMode = 'CLIENT' | 'SERVER';
|
|
60
|
+
export type TReportFilterKind = 'KEY_COMPONENT' | 'REQUEST' | 'ROW';
|
|
61
|
+
export interface IReportFilterDefinition {
|
|
62
|
+
id: string;
|
|
63
|
+
kind: TReportFilterKind;
|
|
64
|
+
mode: TReportFilterMode;
|
|
65
|
+
appliesTo: 'SUMMARY' | 'DETAILS' | 'BOTH';
|
|
66
|
+
}
|
|
67
|
+
export interface IReportCompletenessDefinition {
|
|
68
|
+
summary: 'NONE' | 'ALL_SCOPES';
|
|
69
|
+
details: 'NONE' | 'FLAT_PROJECTION';
|
|
70
|
+
}
|
|
71
|
+
export interface IReportCollectionDefinition {
|
|
72
|
+
name: string;
|
|
73
|
+
schemaVersion: number;
|
|
74
|
+
/** Declared budget; `enforced: false` means the CURRENT writer does not assert it yet. */
|
|
75
|
+
budgetBytes: number;
|
|
76
|
+
enforced: boolean;
|
|
77
|
+
/** Validator file in the schema repository, or null with an explicit debt note. */
|
|
78
|
+
validatorFile: string | null;
|
|
79
|
+
validatorDebt?: string;
|
|
80
|
+
indexOwner: string;
|
|
81
|
+
migrationId: string | null;
|
|
82
|
+
}
|
|
83
|
+
export interface IReportRetentionRule {
|
|
84
|
+
collection: string;
|
|
85
|
+
unit: REPORT_RETENTION_UNIT;
|
|
86
|
+
amount: number;
|
|
87
|
+
}
|
|
88
|
+
export interface IReportAdapterIds {
|
|
89
|
+
/** Workers close-day materializer. */
|
|
90
|
+
writer: string;
|
|
91
|
+
/** Operations live read adapter. */
|
|
92
|
+
live: string;
|
|
93
|
+
/** Operations historical read adapter. */
|
|
94
|
+
historical: string;
|
|
95
|
+
/** Operations details read adapter (only when capabilities.details). */
|
|
96
|
+
details?: string;
|
|
97
|
+
}
|
|
98
|
+
export interface IReportDefinition {
|
|
99
|
+
key: REPORT_KEY_ENUM;
|
|
100
|
+
segment: string;
|
|
101
|
+
reportType: MATERIALIZED_REPORT_TYPE_ENUM;
|
|
102
|
+
capabilities: IReportCapabilities;
|
|
103
|
+
status: REPORT_DEFINITION_STATUS;
|
|
104
|
+
report: IReportCollectionDefinition;
|
|
105
|
+
entries?: IReportCollectionDefinition;
|
|
106
|
+
sideCollections: IReportCollectionDefinition[];
|
|
107
|
+
reportScopes: MATERIALIZED_REPORT_SCOPE_ENUM[];
|
|
108
|
+
entryScopes: MATERIALIZED_REPORT_SCOPE_ENUM[];
|
|
109
|
+
entryStorage: REPORT_ENTRY_STORAGE;
|
|
110
|
+
entrySplit: REPORT_ENTRY_SPLIT;
|
|
111
|
+
maxReportScope: MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
112
|
+
maxEntryScope: MATERIALIZED_REPORT_SCOPE_ENUM | null;
|
|
113
|
+
projections: REPORT_PROJECTION[];
|
|
114
|
+
budgets: Record<string, number>;
|
|
115
|
+
retention: IReportRetentionRule[];
|
|
116
|
+
writeGuard: REPORT_WRITE_GUARD;
|
|
117
|
+
liveSource: REPORT_LIVE_SOURCE;
|
|
118
|
+
historicalLens: REPORT_HISTORICAL_LENS;
|
|
119
|
+
completeness: IReportCompletenessDefinition;
|
|
120
|
+
filters: IReportFilterDefinition[];
|
|
121
|
+
cursor: REPORT_CURSOR_KIND;
|
|
122
|
+
adapters: IReportAdapterIds;
|
|
123
|
+
owner: string;
|
|
124
|
+
notes?: string[];
|
|
125
|
+
}
|
|
126
|
+
export declare const REPORT_DEFINITIONS: Record<string, IReportDefinition>;
|
|
127
|
+
export declare const PRODUCTION_REPORT_DEFINITIONS: IReportDefinition[];
|
|
128
|
+
export interface IReportRegistryExemption {
|
|
129
|
+
key: REPORT_KEY_ENUM;
|
|
130
|
+
status: REPORT_DEFINITION_STATUS.READ_ONLY | REPORT_DEFINITION_STATUS.PLANNED;
|
|
131
|
+
reason: string;
|
|
132
|
+
}
|
|
133
|
+
export declare const REPORT_REGISTRY_EXEMPTIONS: Record<string, IReportRegistryExemption>;
|