@managesome/eposmatic-toolkit 0.4.3 → 0.4.4
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/schemas/models/materialized_tenant_sales_overview_reports.js +20 -26
- package/lib/schemas/models/materialized_tenant_sales_overview_reports.d.ts +17 -25
- package/lib/schemas/models/materialized_tenant_sales_overview_reports.js +20 -26
- package/lib/tests/materialized-reports/materialized-tenant-sales-overview-reports-schema.test.js +11 -0
- package/package.json +1 -1
|
@@ -362,38 +362,32 @@ export const MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_COLLECTION_NAME = 'mater
|
|
|
362
362
|
/**
|
|
363
363
|
* Describes the indexes for `materialized_tenant_sales_overview_reports`.
|
|
364
364
|
* Values are Mongo key patterns that can be passed straight to `.hint()`.
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
* - `
|
|
372
|
-
*
|
|
373
|
-
*
|
|
365
|
+
*
|
|
366
|
+
* ONE compound index carries the whole read story (plus `_id`):
|
|
367
|
+
* `tenant_id__scope_context__scope_field__day_index` — UNIQUE:
|
|
368
|
+
* - identity — one document per (tenant, scope context, scope value);
|
|
369
|
+
* `day_index` is a deterministic function of `scope_field` (null for period
|
|
370
|
+
* scopes), so including it keeps the uniqueness exactly on that identity;
|
|
371
|
+
* - the standardized read — the `{ tenant_id, scope_context, scope_field }`
|
|
372
|
+
* PREFIX serves single-tenant and `$in` tenant-list queries (exact or range
|
|
373
|
+
* on `scope_field`) without a second index;
|
|
374
|
+
* - weekday queries — a `scope_field` range bounded by the prefix, with
|
|
375
|
+
* `day_index` filtered straight from the index keys.
|
|
376
|
+
*
|
|
377
|
+
* There are NO `brand_id` indexes: brand-level reads always pass the brand's
|
|
378
|
+
* explicit tenant list (`tenant_id: { $in }` — including user-filtered tenant
|
|
379
|
+
* subsets, which a `brand_id` index could not serve at all). Add a brand
|
|
380
|
+
* index only if a future reader genuinely scans whole brands without a
|
|
381
|
+
* tenant list.
|
|
374
382
|
*/
|
|
375
383
|
export const MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_COLLECTION_INDEXES = {
|
|
376
384
|
_id: { _id: 1 }, // Unique Index
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
scope_context: 1,
|
|
380
|
-
scope_field: 1,
|
|
381
|
-
}, // unique — one document per (tenant, scope context, scope value)
|
|
382
|
-
brand_id__scope_context__scope_field: {
|
|
383
|
-
brand_id: 1,
|
|
384
|
-
scope_context: 1,
|
|
385
|
-
scope_field: 1,
|
|
386
|
-
}, // brand-level reads across the brand's tenants
|
|
385
|
+
// unique — one document per (tenant, scope context, scope value); the prefix
|
|
386
|
+
// serves the standardized query, the trailing day_index covers weekday reads
|
|
387
387
|
tenant_id__scope_context__scope_field__day_index: {
|
|
388
388
|
tenant_id: 1,
|
|
389
389
|
scope_context: 1,
|
|
390
390
|
scope_field: 1,
|
|
391
391
|
day_index: 1,
|
|
392
|
-
},
|
|
393
|
-
brand_id__scope_context__scope_field__day_index: {
|
|
394
|
-
brand_id: 1,
|
|
395
|
-
scope_context: 1,
|
|
396
|
-
scope_field: 1,
|
|
397
|
-
day_index: 1,
|
|
398
|
-
}, // brand-level weekday queries over LOCAL_HOUR / LOCAL_DATE slices
|
|
392
|
+
},
|
|
399
393
|
};
|
|
@@ -530,40 +530,32 @@ export declare const MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_COLLECTION_NAME
|
|
|
530
530
|
/**
|
|
531
531
|
* Describes the indexes for `materialized_tenant_sales_overview_reports`.
|
|
532
532
|
* Values are Mongo key patterns that can be passed straight to `.hint()`.
|
|
533
|
-
*
|
|
534
|
-
*
|
|
535
|
-
*
|
|
536
|
-
*
|
|
537
|
-
*
|
|
538
|
-
*
|
|
539
|
-
* - `
|
|
540
|
-
*
|
|
541
|
-
*
|
|
533
|
+
*
|
|
534
|
+
* ONE compound index carries the whole read story (plus `_id`):
|
|
535
|
+
* `tenant_id__scope_context__scope_field__day_index` — UNIQUE:
|
|
536
|
+
* - identity — one document per (tenant, scope context, scope value);
|
|
537
|
+
* `day_index` is a deterministic function of `scope_field` (null for period
|
|
538
|
+
* scopes), so including it keeps the uniqueness exactly on that identity;
|
|
539
|
+
* - the standardized read — the `{ tenant_id, scope_context, scope_field }`
|
|
540
|
+
* PREFIX serves single-tenant and `$in` tenant-list queries (exact or range
|
|
541
|
+
* on `scope_field`) without a second index;
|
|
542
|
+
* - weekday queries — a `scope_field` range bounded by the prefix, with
|
|
543
|
+
* `day_index` filtered straight from the index keys.
|
|
544
|
+
*
|
|
545
|
+
* There are NO `brand_id` indexes: brand-level reads always pass the brand's
|
|
546
|
+
* explicit tenant list (`tenant_id: { $in }` — including user-filtered tenant
|
|
547
|
+
* subsets, which a `brand_id` index could not serve at all). Add a brand
|
|
548
|
+
* index only if a future reader genuinely scans whole brands without a
|
|
549
|
+
* tenant list.
|
|
542
550
|
*/
|
|
543
551
|
export declare const MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_COLLECTION_INDEXES: {
|
|
544
552
|
_id: {
|
|
545
553
|
_id: number;
|
|
546
554
|
};
|
|
547
|
-
tenant_id__scope_context__scope_field: {
|
|
548
|
-
tenant_id: number;
|
|
549
|
-
scope_context: number;
|
|
550
|
-
scope_field: number;
|
|
551
|
-
};
|
|
552
|
-
brand_id__scope_context__scope_field: {
|
|
553
|
-
brand_id: number;
|
|
554
|
-
scope_context: number;
|
|
555
|
-
scope_field: number;
|
|
556
|
-
};
|
|
557
555
|
tenant_id__scope_context__scope_field__day_index: {
|
|
558
556
|
tenant_id: number;
|
|
559
557
|
scope_context: number;
|
|
560
558
|
scope_field: number;
|
|
561
559
|
day_index: number;
|
|
562
560
|
};
|
|
563
|
-
brand_id__scope_context__scope_field__day_index: {
|
|
564
|
-
brand_id: number;
|
|
565
|
-
scope_context: number;
|
|
566
|
-
scope_field: number;
|
|
567
|
-
day_index: number;
|
|
568
|
-
};
|
|
569
561
|
};
|
|
@@ -365,38 +365,32 @@ exports.MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_COLLECTION_NAME = 'materializ
|
|
|
365
365
|
/**
|
|
366
366
|
* Describes the indexes for `materialized_tenant_sales_overview_reports`.
|
|
367
367
|
* Values are Mongo key patterns that can be passed straight to `.hint()`.
|
|
368
|
-
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
* - `
|
|
375
|
-
*
|
|
376
|
-
*
|
|
368
|
+
*
|
|
369
|
+
* ONE compound index carries the whole read story (plus `_id`):
|
|
370
|
+
* `tenant_id__scope_context__scope_field__day_index` — UNIQUE:
|
|
371
|
+
* - identity — one document per (tenant, scope context, scope value);
|
|
372
|
+
* `day_index` is a deterministic function of `scope_field` (null for period
|
|
373
|
+
* scopes), so including it keeps the uniqueness exactly on that identity;
|
|
374
|
+
* - the standardized read — the `{ tenant_id, scope_context, scope_field }`
|
|
375
|
+
* PREFIX serves single-tenant and `$in` tenant-list queries (exact or range
|
|
376
|
+
* on `scope_field`) without a second index;
|
|
377
|
+
* - weekday queries — a `scope_field` range bounded by the prefix, with
|
|
378
|
+
* `day_index` filtered straight from the index keys.
|
|
379
|
+
*
|
|
380
|
+
* There are NO `brand_id` indexes: brand-level reads always pass the brand's
|
|
381
|
+
* explicit tenant list (`tenant_id: { $in }` — including user-filtered tenant
|
|
382
|
+
* subsets, which a `brand_id` index could not serve at all). Add a brand
|
|
383
|
+
* index only if a future reader genuinely scans whole brands without a
|
|
384
|
+
* tenant list.
|
|
377
385
|
*/
|
|
378
386
|
exports.MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_COLLECTION_INDEXES = {
|
|
379
387
|
_id: { _id: 1 }, // Unique Index
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
scope_context: 1,
|
|
383
|
-
scope_field: 1,
|
|
384
|
-
}, // unique — one document per (tenant, scope context, scope value)
|
|
385
|
-
brand_id__scope_context__scope_field: {
|
|
386
|
-
brand_id: 1,
|
|
387
|
-
scope_context: 1,
|
|
388
|
-
scope_field: 1,
|
|
389
|
-
}, // brand-level reads across the brand's tenants
|
|
388
|
+
// unique — one document per (tenant, scope context, scope value); the prefix
|
|
389
|
+
// serves the standardized query, the trailing day_index covers weekday reads
|
|
390
390
|
tenant_id__scope_context__scope_field__day_index: {
|
|
391
391
|
tenant_id: 1,
|
|
392
392
|
scope_context: 1,
|
|
393
393
|
scope_field: 1,
|
|
394
394
|
day_index: 1,
|
|
395
|
-
},
|
|
396
|
-
brand_id__scope_context__scope_field__day_index: {
|
|
397
|
-
brand_id: 1,
|
|
398
|
-
scope_context: 1,
|
|
399
|
-
scope_field: 1,
|
|
400
|
-
day_index: 1,
|
|
401
|
-
}, // brand-level weekday queries over LOCAL_HOUR / LOCAL_DATE slices
|
|
395
|
+
},
|
|
402
396
|
};
|
package/lib/tests/materialized-reports/materialized-tenant-sales-overview-reports-schema.test.js
CHANGED
|
@@ -76,6 +76,17 @@ describe('materialized_tenant_sales_overview_reports schema', () => {
|
|
|
76
76
|
it('exposes the agreed collection name', () => {
|
|
77
77
|
expect(materialized_tenant_sales_overview_reports_1.MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_COLLECTION_NAME).toBe('materialized_tenant_sales_overview_reports');
|
|
78
78
|
});
|
|
79
|
+
it('declares one compound tenant index — brand reads pass explicit tenant lists ($in)', () => {
|
|
80
|
+
expect(materialized_tenant_sales_overview_reports_1.MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_COLLECTION_INDEXES).toEqual({
|
|
81
|
+
_id: { _id: 1 },
|
|
82
|
+
tenant_id__scope_context__scope_field__day_index: {
|
|
83
|
+
tenant_id: 1,
|
|
84
|
+
scope_context: 1,
|
|
85
|
+
scope_field: 1,
|
|
86
|
+
day_index: 1,
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
});
|
|
79
90
|
it('validates a well-formed scope document and casts metrics to a Map', () => {
|
|
80
91
|
const doc = new Model(validDocument());
|
|
81
92
|
expect(doc.validateSync()).toBeUndefined();
|