@managesome/eposmatic-toolkit 0.4.36 → 0.4.37

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.
@@ -208,9 +208,7 @@ export function accumulateOrderPrepTime({ order, context, tenantDefaultMinutes =
208
208
  // order-line id is a DIFFERENT identity and is preserved as line_id, so
209
209
  // two lines of one menu item remain two served events.
210
210
  const lineId = item?._id != null ? String(item._id) : null;
211
- const catalogueItemId = item?.item_id != null && String(item.item_id) !== ''
212
- ? String(item.item_id)
213
- : lineId;
211
+ const catalogueItemId = item?.item_id != null && String(item.item_id) !== '' ? String(item.item_id) : lineId;
214
212
  const row = {
215
213
  entry_key: buildMaterializedPrepTimeEntryKey(catalogueItemId, lineId),
216
214
  order_id: orderId,
@@ -178,9 +178,7 @@ export function matchesMaterializedPrepTimeReadFilters(row, filters) {
178
178
  if (platforms != null && platforms.length > 0 && !platforms.includes(asString(row.platform))) {
179
179
  return false;
180
180
  }
181
- if (orderStatuses != null &&
182
- orderStatuses.length > 0 &&
183
- !orderStatuses.includes(asString(row.order_status))) {
181
+ if (orderStatuses != null && orderStatuses.length > 0 && !orderStatuses.includes(asString(row.order_status))) {
184
182
  return false;
185
183
  }
186
184
  if (categoryNames != null && categoryNames.length > 0) {
@@ -420,8 +418,7 @@ export function groupMaterializedPrepTimeItemRows(rows, filters) {
420
418
  }
421
419
  /** True when `value` is one of the frozen item sort modes. */
422
420
  export function isMaterializedPrepTimeItemSort(value) {
423
- return (typeof value === 'string' &&
424
- ALL_MATERIALIZED_PREP_TIME_ITEM_SORTS.includes(value));
421
+ return typeof value === 'string' && ALL_MATERIALIZED_PREP_TIME_ITEM_SORTS.includes(value);
425
422
  }
426
423
  /** The sort value of one item row (the cursor stores it verbatim). */
427
424
  export function getMaterializedPrepTimeItemSortValue(row, sort) {
@@ -478,9 +475,7 @@ export function compareMaterializedPrepTimeItemRows(a, b, sort) {
478
475
  }
479
476
  /** Stable sort (never mutates the input array). */
480
477
  export function sortMaterializedPrepTimeItemRows(rows, sort) {
481
- const mode = isMaterializedPrepTimeItemSort(sort)
482
- ? sort
483
- : DEFAULT_MATERIALIZED_PREP_TIME_ITEM_SORT;
478
+ const mode = isMaterializedPrepTimeItemSort(sort) ? sort : DEFAULT_MATERIALIZED_PREP_TIME_ITEM_SORT;
484
479
  return (Array.isArray(rows) ? rows : []).slice().sort((a, b) => {
485
480
  const compared = compareSortValues(getMaterializedPrepTimeItemSortValue(a, mode), getMaterializedPrepTimeItemSortValue(b, mode), mode);
486
481
  if (compared !== 0)
@@ -499,9 +494,7 @@ const compareItemToCursor = (row, sort, cursor) => {
499
494
  * row can be duplicated or skipped between pages.
500
495
  */
501
496
  export function getMaterializedPrepTimeItemPage(rows, sort, cursor, limit = 25) {
502
- const mode = isMaterializedPrepTimeItemSort(sort)
503
- ? sort
504
- : DEFAULT_MATERIALIZED_PREP_TIME_ITEM_SORT;
497
+ const mode = isMaterializedPrepTimeItemSort(sort) ? sort : DEFAULT_MATERIALIZED_PREP_TIME_ITEM_SORT;
505
498
  const size = Number.isFinite(limit) && limit > 0 ? Math.floor(limit) : 0;
506
499
  const all = Array.isArray(rows) ? rows : [];
507
500
  const remaining = cursor == null ? all.slice() : all.filter((row) => compareItemToCursor(row, mode, cursor) > 0);
@@ -525,9 +518,7 @@ export function getMaterializedPrepTimeItemPage(rows, sort, cursor, limit = 25)
525
518
  export function buildMaterializedPrepTimeItemsPage(args) {
526
519
  const filtered = applyMaterializedPrepTimeReadFilters(args.rows, args.filters);
527
520
  const coverage = buildMaterializedPrepTimeCoverage(applyMaterializedPrepTimeReadFilters(args.rows, withoutMaterializedPrepTimeAnchorFilter(args.filters)));
528
- const sort = isMaterializedPrepTimeItemSort(args.sort)
529
- ? args.sort
530
- : DEFAULT_MATERIALIZED_PREP_TIME_ITEM_SORT;
521
+ const sort = isMaterializedPrepTimeItemSort(args.sort) ? args.sort : DEFAULT_MATERIALIZED_PREP_TIME_ITEM_SORT;
531
522
  const grouped = groupMaterializedPrepTimeItemRows(filtered);
532
523
  const sorted = sortMaterializedPrepTimeItemRows(grouped, sort);
533
524
  const page = getMaterializedPrepTimeItemPage(sorted, sort, args.cursor ?? null, args.limit ?? 25);
@@ -217,9 +217,7 @@ function accumulateOrderPrepTime({ order, context, tenantDefaultMinutes = null,
217
217
  // order-line id is a DIFFERENT identity and is preserved as line_id, so
218
218
  // two lines of one menu item remain two served events.
219
219
  const lineId = item?._id != null ? String(item._id) : null;
220
- const catalogueItemId = item?.item_id != null && String(item.item_id) !== ''
221
- ? String(item.item_id)
222
- : lineId;
220
+ const catalogueItemId = item?.item_id != null && String(item.item_id) !== '' ? String(item.item_id) : lineId;
223
221
  const row = {
224
222
  entry_key: (0, exports.buildMaterializedPrepTimeEntryKey)(catalogueItemId, lineId),
225
223
  order_id: orderId,
@@ -205,9 +205,7 @@ function matchesMaterializedPrepTimeReadFilters(row, filters) {
205
205
  if (platforms != null && platforms.length > 0 && !platforms.includes(asString(row.platform))) {
206
206
  return false;
207
207
  }
208
- if (orderStatuses != null &&
209
- orderStatuses.length > 0 &&
210
- !orderStatuses.includes(asString(row.order_status))) {
208
+ if (orderStatuses != null && orderStatuses.length > 0 && !orderStatuses.includes(asString(row.order_status))) {
211
209
  return false;
212
210
  }
213
211
  if (categoryNames != null && categoryNames.length > 0) {
@@ -448,8 +446,7 @@ function groupMaterializedPrepTimeItemRows(rows, filters) {
448
446
  }
449
447
  /** True when `value` is one of the frozen item sort modes. */
450
448
  function isMaterializedPrepTimeItemSort(value) {
451
- return (typeof value === 'string' &&
452
- materialized_reports_apis_1.ALL_MATERIALIZED_PREP_TIME_ITEM_SORTS.includes(value));
449
+ return typeof value === 'string' && materialized_reports_apis_1.ALL_MATERIALIZED_PREP_TIME_ITEM_SORTS.includes(value);
453
450
  }
454
451
  /** The sort value of one item row (the cursor stores it verbatim). */
455
452
  function getMaterializedPrepTimeItemSortValue(row, sort) {
@@ -506,9 +503,7 @@ function compareMaterializedPrepTimeItemRows(a, b, sort) {
506
503
  }
507
504
  /** Stable sort (never mutates the input array). */
508
505
  function sortMaterializedPrepTimeItemRows(rows, sort) {
509
- const mode = isMaterializedPrepTimeItemSort(sort)
510
- ? sort
511
- : materialized_reports_apis_1.DEFAULT_MATERIALIZED_PREP_TIME_ITEM_SORT;
506
+ const mode = isMaterializedPrepTimeItemSort(sort) ? sort : materialized_reports_apis_1.DEFAULT_MATERIALIZED_PREP_TIME_ITEM_SORT;
512
507
  return (Array.isArray(rows) ? rows : []).slice().sort((a, b) => {
513
508
  const compared = compareSortValues(getMaterializedPrepTimeItemSortValue(a, mode), getMaterializedPrepTimeItemSortValue(b, mode), mode);
514
509
  if (compared !== 0)
@@ -527,9 +522,7 @@ const compareItemToCursor = (row, sort, cursor) => {
527
522
  * row can be duplicated or skipped between pages.
528
523
  */
529
524
  function getMaterializedPrepTimeItemPage(rows, sort, cursor, limit = 25) {
530
- const mode = isMaterializedPrepTimeItemSort(sort)
531
- ? sort
532
- : materialized_reports_apis_1.DEFAULT_MATERIALIZED_PREP_TIME_ITEM_SORT;
525
+ const mode = isMaterializedPrepTimeItemSort(sort) ? sort : materialized_reports_apis_1.DEFAULT_MATERIALIZED_PREP_TIME_ITEM_SORT;
533
526
  const size = Number.isFinite(limit) && limit > 0 ? Math.floor(limit) : 0;
534
527
  const all = Array.isArray(rows) ? rows : [];
535
528
  const remaining = cursor == null ? all.slice() : all.filter((row) => compareItemToCursor(row, mode, cursor) > 0);
@@ -553,9 +546,7 @@ function getMaterializedPrepTimeItemPage(rows, sort, cursor, limit = 25) {
553
546
  function buildMaterializedPrepTimeItemsPage(args) {
554
547
  const filtered = applyMaterializedPrepTimeReadFilters(args.rows, args.filters);
555
548
  const coverage = buildMaterializedPrepTimeCoverage(applyMaterializedPrepTimeReadFilters(args.rows, (0, exports.withoutMaterializedPrepTimeAnchorFilter)(args.filters)));
556
- const sort = isMaterializedPrepTimeItemSort(args.sort)
557
- ? args.sort
558
- : materialized_reports_apis_1.DEFAULT_MATERIALIZED_PREP_TIME_ITEM_SORT;
549
+ const sort = isMaterializedPrepTimeItemSort(args.sort) ? args.sort : materialized_reports_apis_1.DEFAULT_MATERIALIZED_PREP_TIME_ITEM_SORT;
559
550
  const grouped = groupMaterializedPrepTimeItemRows(filtered);
560
551
  const sorted = sortMaterializedPrepTimeItemRows(grouped, sort);
561
552
  const page = getMaterializedPrepTimeItemPage(sorted, sort, args.cursor ?? null, args.limit ?? 25);
@@ -74,11 +74,7 @@ describe('day vs period scope classification', () => {
74
74
  'localWeekOfYear',
75
75
  'localYear',
76
76
  ]);
77
- expect(materialized_prep_time_close_day_helpers_1.MATERIALIZED_PREP_TIME_ITEM_PERIOD_SCOPES.sort()).toEqual([
78
- 'localMonth',
79
- 'localWeek',
80
- 'localWeekOfYear',
81
- ]);
77
+ expect(materialized_prep_time_close_day_helpers_1.MATERIALIZED_PREP_TIME_ITEM_PERIOD_SCOPES.sort()).toEqual(['localMonth', 'localWeek', 'localWeekOfYear']);
82
78
  });
83
79
  it('enumerates the FULL report sibling days (through year) separately from the item days', () => {
84
80
  // Item period days stay month-bounded (Sep 1..30 for this Monday).
@@ -44,7 +44,11 @@ const order = () => ({
44
44
  },
45
45
  {
46
46
  name: 'Other',
47
- items: [item('b', 20), item('invalid-high', MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_MAX_MINUTES + 1), item('invalid-negative', -3)],
47
+ items: [
48
+ item('b', 20),
49
+ item('invalid-high', MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_MAX_MINUTES + 1),
50
+ item('invalid-negative', -3),
51
+ ],
48
52
  },
49
53
  ],
50
54
  });
@@ -55,10 +59,8 @@ const compiled = (0, materialized_prep_time_compile_helpers_1.compileTenantPrepT
55
59
  orders: [order()],
56
60
  computedAt: new Date(`${DAY}T23:00:00.000Z`),
57
61
  });
58
- const dayReport = compiled.reports.find((report) => report.scope_context === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE &&
59
- report.scope_field === DAY);
60
- const dayEntry = compiled.entries.find((entry) => entry.scope_context === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE &&
61
- entry.scope_field === DAY);
62
+ const dayReport = compiled.reports.find((report) => report.scope_context === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE && report.scope_field === DAY);
63
+ const dayEntry = compiled.entries.find((entry) => entry.scope_context === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE && entry.scope_field === DAY);
62
64
  const readRows = Object.values(dayEntry.prep_time_entries ?? {}).flatMap((section) => (section.rows ?? []).map((row) => ({
63
65
  tenant_id: TENANT,
64
66
  order_id: row.order_id,
@@ -111,16 +111,8 @@ describe('prep time catalogue identity and coverage population', () => {
111
111
  const { compiled } = readRows([first, second]);
112
112
  const dayEntry = compiled.entries.find((entry) => entry.scope_context === 'localDate');
113
113
  const events = Object.values(dayEntry.prep_time_entries ?? {}).flatMap((section) => section.rows);
114
- expect(events.map((event) => event.item_id)).toEqual([
115
- 'menu-burger',
116
- 'menu-burger',
117
- 'menu-burger',
118
- ]);
119
- expect(events.map((event) => event.order_id)).toEqual([
120
- 'order-a',
121
- 'order-a',
122
- 'order-b',
123
- ]);
114
+ expect(events.map((event) => event.item_id)).toEqual(['menu-burger', 'menu-burger', 'menu-burger']);
115
+ expect(events.map((event) => event.order_id)).toEqual(['order-a', 'order-a', 'order-b']);
124
116
  expect(new Set(events.map((event) => event.entry_key)).size).toBe(3);
125
117
  expect(events.map((event) => event.line_id)).toEqual(['line-a', 'line-b', 'line-c']);
126
118
  });
@@ -432,12 +432,12 @@ describe('prep time item sorting + cursor paging', () => {
432
432
  }
433
433
  });
434
434
  it('breaks exact sort-value ties by item_id ascending', () => {
435
- const tied = [
436
- items()[0],
437
- { ...items()[0], item_id: 'i-0' },
438
- { ...items()[0], item_id: 'i-z' },
439
- ];
440
- expect((0, materialized_prep_time_read_helpers_1.sortMaterializedPrepTimeItemRows)(tied, 'late_desc').map((item) => item.item_id)).toEqual(['i-0', 'i-a', 'i-z']);
435
+ const tied = [items()[0], { ...items()[0], item_id: 'i-0' }, { ...items()[0], item_id: 'i-z' }];
436
+ expect((0, materialized_prep_time_read_helpers_1.sortMaterializedPrepTimeItemRows)(tied, 'late_desc').map((item) => item.item_id)).toEqual([
437
+ 'i-0',
438
+ 'i-a',
439
+ 'i-z',
440
+ ]);
441
441
  });
442
442
  it('never mutates the input rows when sorting', () => {
443
443
  const input = items();
@@ -527,9 +527,7 @@ describe('prep time categories', () => {
527
527
  });
528
528
  it('returns null stats for a measured-empty category', () => {
529
529
  const result = (0, materialized_prep_time_read_helpers_1.buildMaterializedPrepTimeCategoriesResult)({
530
- rows: [
531
- row({ anchor: 'UNMEASURED', duration_minutes: null, category_name: 'Cold' }),
532
- ],
530
+ rows: [row({ anchor: 'UNMEASURED', duration_minutes: null, category_name: 'Cold' })],
533
531
  });
534
532
  expect(result.rows[0].avg_minutes).toBeNull();
535
533
  expect(result.rows[0].median_minutes).toBeNull();
@@ -568,10 +566,7 @@ describe('prep time series', () => {
568
566
  ];
569
567
  it('groups by source local date ascending and never emits empty dates', () => {
570
568
  const result = (0, materialized_prep_time_read_helpers_1.buildMaterializedPrepTimeSeriesResult)({ rows });
571
- expect(result.points.map((point) => point.local_date)).toEqual([
572
- '2026-09-10',
573
- '2026-09-11',
574
- ]);
569
+ expect(result.points.map((point) => point.local_date)).toEqual(['2026-09-10', '2026-09-11']);
575
570
  expect(result.points[0]).toMatchObject({
576
571
  served_count: 2,
577
572
  measured_count: 1,
@@ -55,10 +55,7 @@ describe('flat drill-down row projection', () => {
55
55
  },
56
56
  },
57
57
  });
58
- expect(result.rows.map((entry) => entry.cursor_id)).toEqual([
59
- 'item:menu-1:line-a',
60
- 'item:menu-1:line-b',
61
- ]);
58
+ expect(result.rows.map((entry) => entry.cursor_id)).toEqual(['item:menu-1:line-a', 'item:menu-1:line-b']);
62
59
  });
63
60
  test('projects cash rows as drawer-ledger rows (no order id)', () => {
64
61
  const result = (0, materialized_report_drilldown_rows_1.buildMaterializedDrilldownRows)(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_CASH_ENTRIES, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.4.36",
3
+ "version": "0.4.37",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",