@ancon/wildcat-utils 1.40.9 → 1.40.10

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.
@@ -1 +1 @@
1
- "use strict";const F=require("moment"),r=require("@ancon/wildcat-types"),g=require("../shared/isWithinFlag.js"),I=require("../shared/generateId.js"),c=[{id:r.OrderFormat.EatIn,name:"eatIn"},{id:r.OrderFormat.TakeAway,name:"takeaway"},{id:r.OrderFormat.TableOrder,name:"tableOrder"},{id:r.OrderFormat.Delivery,name:"delivery"}];function v(e){const o=F.utc(e).subtract(1,"day").startOf("day"),t=[];for(let s=0,d=o;s<7;s+=1)d=d.clone().add(1,"day").startOf("day"),t.push(d.clone());return t}function W(e){return[...e].sort((o,t)=>o.isoWeekday()-t.isoWeekday())}function k(e){return e.split(":").map(Number)}function T(e,o,t){const[s,d]=k(e.start),[p,m]=k(e.duration),[n,y]=k(t||"00:00:00");if(e.type===r.IntervalType.Interval){let i=o.clone().add(s,"hour").add(d,"minute");const a=i.clone().add(n,"hour").add(y,"minute").date()-o.date();a!==0&&(i=i.subtract(a,"day"));const f=i.clone().add(p,"hour").add(m,"minute");return{id:e.id,start:i.toISOString(),end:f.toISOString()}}if(e.type===r.IntervalType.Exception){const i=F(e.fromDate),u=F(e.toDate);if(o.isBetween(i,u,void 0,"[]")){const a=o.clone().add(s,"hour").add(d,"minute"),f=a.clone().add(p,"hour").add(m,"minute");return{id:e.id,start:a.toISOString(),end:f.toISOString(),reason:e.reason}}return null}throw new Error("Invalid interval type")}function S(e,o,t,s){const d={[r.DayOfWeek.Monday]:1,[r.DayOfWeek.Tuesday]:2,[r.DayOfWeek.Wednesday]:3,[r.DayOfWeek.Thursday]:4,[r.DayOfWeek.Friday]:5,[r.DayOfWeek.Saturday]:6,[r.DayOfWeek.Sunday]:7,[r.DayOfWeek.Everyday]:null};for(let p=0;p<o.length;p+=1){const m=o[p],n=m.isoWeekday(),y=e.dayOfWeek,u=(d[y]??null)===n||y===r.DayOfWeek.Everyday;if(t[n]||(t[n]={isoWeekday:n,key:"",open:[],adjusted:[],closed:[]}),u){const a=T(e,m,s);a&&(t[n].key+=a.id,e.type===r.IntervalType.Interval&&e.state===r.IntervalState.Open?t[n].open.push(a):e.type===r.IntervalType.Interval&&e.state===r.IntervalState.Closed?t[n].closed.push(a):e.type===r.IntervalType.Exception&&e.state===r.IntervalState.Open?t[n].adjusted.push(a):e.type===r.IntervalType.Exception&&e.state===r.IntervalState.Closed&&t[n].closed.push(a))}}}function h(e){switch(e.type){case r.IntervalType.Exception:return I("interval-exception");case r.IntervalType.Interval:return I("interval-normal");default:return I("interval-unknown")}}function D(e){const o=e.reduce((t,s)=>(c.forEach(d=>{g(d.id,s.orderFormats)&&(t[d.id]||(t[d.id]={orderFormat:d,intervals:[]}),t[d.id].intervals.push(...s.intervals.sort((p,m)=>p.dayOfWeek-m.dayOfWeek)))}),t),{});return Object.values(o)}function M(e,o){const t=o.reduce((s,d)=>d<=e?s+1:s,0);return e-t}function H(e){const{mergedTables:o}=e.reduce((t,s,d)=>{const p=t.mergedTables.findIndex(m=>m!==s&&!m.orderFormats.some(n=>s.orderFormats.some(y=>y.id===n.id))&&m.openingHours.every(n=>s.openingHours.some(y=>y.key===n.key))&&s.openingHours.every(n=>m.openingHours.some(y=>y.key===n.key)));if(p>=0){if(t.skipOrderFormats.some(u=>s.orderFormats.every(a=>a.id===u.id)))return t;const n=t.mergedTables[p];t.mergedTables.splice(p,1,{...n,orderFormats:[...s.orderFormats,...n.orderFormats]});const y=n.orderFormats.filter(u=>!t.skipOrderFormats.some(a=>a.id===u.id));y.length>0&&t.skipOrderFormats.push(...y);const i=M(d,[...t.removedIndexes]);return t.mergedTables.splice(i,1),t.removedIndexes.push(d),t}return t},{mergedTables:[...e],removedIndexes:[],skipOrderFormats:[]});return o}function x(e){return e.map(o=>({...o,intervals:o.intervals.map(t=>({...t,id:h(t)}))}))}function E(e,o){const t=D(x(e.serviceDateTimes)),s=v(o),d=W(s),p=t.reduce((i,u)=>(i[u.orderFormat.id]||(i[u.orderFormat.id]={}),u.intervals.reduce((a,f)=>(S(f,d,a,e.timeZoneOffset),a),i[u.orderFormat.id]),i),{}),m={[r.OrderFormat.EatIn]:c[0],[r.OrderFormat.TakeAway]:c[1],[r.OrderFormat.TableOrder]:c[2],[r.OrderFormat.Delivery]:c[3]},n=Object.entries(p).map(([i,u])=>({orderFormats:[m[Number(i)]],openingHours:Object.entries(u).map(([a,f])=>({isoWeekday:Number(a),key:f.key,open:f.open.sort((l,O)=>l.start.localeCompare(O.start)),adjusted:f.adjusted.sort((l,O)=>l.start.localeCompare(O.start)),closed:f.closed.sort((l,O)=>l.start.localeCompare(O.start))}))}));return H(n).sort((i,u)=>i.orderFormats[0].id-u.orderFormats[0].id)}module.exports=E;
1
+ "use strict";const F=require("moment"),r=require("@ancon/wildcat-types"),g=require("../shared/isWithinFlag.js"),k=require("../shared/generateId.js"),l=[{id:r.OrderFormat.EatIn,name:"eatIn"},{id:r.OrderFormat.TakeAway,name:"takeaway"},{id:r.OrderFormat.TableOrder,name:"tableOrder"},{id:r.OrderFormat.Delivery,name:"delivery"},{id:r.OrderFormat.BoxPickup,name:"boxPickup"}];function v(e){const o=F.utc(e).subtract(1,"day").startOf("day"),t=[];for(let s=0,d=o;s<7;s+=1)d=d.clone().add(1,"day").startOf("day"),t.push(d.clone());return t}function W(e){return[...e].sort((o,t)=>o.isoWeekday()-t.isoWeekday())}function I(e){return e.split(":").map(Number)}function T(e,o,t){const[s,d]=I(e.start),[p,m]=I(e.duration),[n,y]=I(t||"00:00:00");if(e.type===r.IntervalType.Interval){let i=o.clone().add(s,"hour").add(d,"minute");const a=i.clone().add(n,"hour").add(y,"minute").date()-o.date();a!==0&&(i=i.subtract(a,"day"));const f=i.clone().add(p,"hour").add(m,"minute");return{id:e.id,start:i.toISOString(),end:f.toISOString()}}if(e.type===r.IntervalType.Exception){const i=F(e.fromDate),u=F(e.toDate);if(o.isBetween(i,u,void 0,"[]")){const a=o.clone().add(s,"hour").add(d,"minute"),f=a.clone().add(p,"hour").add(m,"minute");return{id:e.id,start:a.toISOString(),end:f.toISOString(),reason:e.reason}}return null}throw new Error("Invalid interval type")}function S(e,o,t,s){const d={[r.DayOfWeek.Monday]:1,[r.DayOfWeek.Tuesday]:2,[r.DayOfWeek.Wednesday]:3,[r.DayOfWeek.Thursday]:4,[r.DayOfWeek.Friday]:5,[r.DayOfWeek.Saturday]:6,[r.DayOfWeek.Sunday]:7,[r.DayOfWeek.Everyday]:null};for(let p=0;p<o.length;p+=1){const m=o[p],n=m.isoWeekday(),y=e.dayOfWeek,u=(d[y]??null)===n||y===r.DayOfWeek.Everyday;if(t[n]||(t[n]={isoWeekday:n,key:"",open:[],adjusted:[],closed:[]}),u){const a=T(e,m,s);a&&(t[n].key+=a.id,e.type===r.IntervalType.Interval&&e.state===r.IntervalState.Open?t[n].open.push(a):e.type===r.IntervalType.Interval&&e.state===r.IntervalState.Closed?t[n].closed.push(a):e.type===r.IntervalType.Exception&&e.state===r.IntervalState.Open?t[n].adjusted.push(a):e.type===r.IntervalType.Exception&&e.state===r.IntervalState.Closed&&t[n].closed.push(a))}}}function h(e){switch(e.type){case r.IntervalType.Exception:return k("interval-exception");case r.IntervalType.Interval:return k("interval-normal");default:return k("interval-unknown")}}function D(e){const o=e.reduce((t,s)=>(l.forEach(d=>{g(d.id,s.orderFormats)&&(t[d.id]||(t[d.id]={orderFormat:d,intervals:[]}),t[d.id].intervals.push(...s.intervals.sort((p,m)=>p.dayOfWeek-m.dayOfWeek)))}),t),{});return Object.values(o)}function x(e,o){const t=o.reduce((s,d)=>d<=e?s+1:s,0);return e-t}function M(e){const{mergedTables:o}=e.reduce((t,s,d)=>{const p=t.mergedTables.findIndex(m=>m!==s&&!m.orderFormats.some(n=>s.orderFormats.some(y=>y.id===n.id))&&m.openingHours.every(n=>s.openingHours.some(y=>y.key===n.key))&&s.openingHours.every(n=>m.openingHours.some(y=>y.key===n.key)));if(p>=0){if(t.skipOrderFormats.some(u=>s.orderFormats.every(a=>a.id===u.id)))return t;const n=t.mergedTables[p];t.mergedTables.splice(p,1,{...n,orderFormats:[...s.orderFormats,...n.orderFormats]});const y=n.orderFormats.filter(u=>!t.skipOrderFormats.some(a=>a.id===u.id));y.length>0&&t.skipOrderFormats.push(...y);const i=x(d,[...t.removedIndexes]);return t.mergedTables.splice(i,1),t.removedIndexes.push(d),t}return t},{mergedTables:[...e],removedIndexes:[],skipOrderFormats:[]});return o}function H(e){return e.map(o=>({...o,intervals:o.intervals.map(t=>({...t,id:h(t)}))}))}function E(e,o){const t=D(H(e.serviceDateTimes)),s=v(o),d=W(s),p=t.reduce((i,u)=>(i[u.orderFormat.id]||(i[u.orderFormat.id]={}),u.intervals.reduce((a,f)=>(S(f,d,a,e.timeZoneOffset),a),i[u.orderFormat.id]),i),{}),m={[r.OrderFormat.EatIn]:l[0],[r.OrderFormat.TakeAway]:l[1],[r.OrderFormat.TableOrder]:l[2],[r.OrderFormat.Delivery]:l[3],[r.OrderFormat.BoxPickup]:l[4]},n=Object.entries(p).map(([i,u])=>({orderFormats:[m[Number(i)]],openingHours:Object.entries(u).map(([a,f])=>({isoWeekday:Number(a),key:f.key,open:f.open.sort((O,c)=>O.start.localeCompare(c.start)),adjusted:f.adjusted.sort((O,c)=>O.start.localeCompare(c.start)),closed:f.closed.sort((O,c)=>O.start.localeCompare(c.start))}))}));return M(n).sort((i,u)=>i.orderFormats[0].id-u.orderFormats[0].id)}module.exports=E;
@@ -1,12 +1,13 @@
1
1
  import S from "moment";
2
- import { OrderFormat as l, DayOfWeek as y, IntervalType as c, IntervalState as g } from "@ancon/wildcat-types";
2
+ import { OrderFormat as y, DayOfWeek as l, IntervalType as c, IntervalState as g } from "@ancon/wildcat-types";
3
3
  import h from "../shared/isWithinFlag.mjs";
4
4
  import F from "../shared/generateId.mjs";
5
- const I = [
6
- { id: l.EatIn, name: "eatIn" },
7
- { id: l.TakeAway, name: "takeaway" },
8
- { id: l.TableOrder, name: "tableOrder" },
9
- { id: l.Delivery, name: "delivery" }
5
+ const k = [
6
+ { id: y.EatIn, name: "eatIn" },
7
+ { id: y.TakeAway, name: "takeaway" },
8
+ { id: y.TableOrder, name: "tableOrder" },
9
+ { id: y.Delivery, name: "delivery" },
10
+ { id: y.BoxPickup, name: "boxPickup" }
10
11
  ];
11
12
  function v(e) {
12
13
  const o = S.utc(e).subtract(1, "day").startOf("day"), t = [];
@@ -20,7 +21,7 @@ function T(e) {
20
21
  function W(e) {
21
22
  return e.split(":").map(Number);
22
23
  }
23
- function M(e, o, t) {
24
+ function x(e, o, t) {
24
25
  const [n, s] = W(e.start), [m, u] = W(
25
26
  e.duration
26
27
  ), [r, p] = W(t || "00:00:00");
@@ -50,19 +51,19 @@ function M(e, o, t) {
50
51
  }
51
52
  throw new Error("Invalid interval type");
52
53
  }
53
- function H(e, o, t, n) {
54
+ function M(e, o, t, n) {
54
55
  const s = {
55
- [y.Monday]: 1,
56
- [y.Tuesday]: 2,
57
- [y.Wednesday]: 3,
58
- [y.Thursday]: 4,
59
- [y.Friday]: 5,
60
- [y.Saturday]: 6,
61
- [y.Sunday]: 7,
62
- [y.Everyday]: null
56
+ [l.Monday]: 1,
57
+ [l.Tuesday]: 2,
58
+ [l.Wednesday]: 3,
59
+ [l.Thursday]: 4,
60
+ [l.Friday]: 5,
61
+ [l.Saturday]: 6,
62
+ [l.Sunday]: 7,
63
+ [l.Everyday]: null
63
64
  };
64
65
  for (let m = 0; m < o.length; m += 1) {
65
- const u = o[m], r = u.isoWeekday(), p = e.dayOfWeek, i = (s[p] ?? null) === r || p === y.Everyday;
66
+ const u = o[m], r = u.isoWeekday(), p = e.dayOfWeek, i = (s[p] ?? null) === r || p === l.Everyday;
66
67
  if (t[r] || (t[r] = {
67
68
  isoWeekday: r,
68
69
  key: "",
@@ -70,7 +71,7 @@ function H(e, o, t, n) {
70
71
  adjusted: [],
71
72
  closed: []
72
73
  }), i) {
73
- const d = M(
74
+ const d = x(
74
75
  e,
75
76
  u,
76
77
  n
@@ -79,7 +80,7 @@ function H(e, o, t, n) {
79
80
  }
80
81
  }
81
82
  }
82
- function x(e) {
83
+ function H(e) {
83
84
  switch (e.type) {
84
85
  case c.Exception:
85
86
  return F("interval-exception");
@@ -91,7 +92,7 @@ function x(e) {
91
92
  }
92
93
  function E(e) {
93
94
  const o = e.reduce(
94
- (t, n) => (I.forEach((s) => {
95
+ (t, n) => (k.forEach((s) => {
95
96
  h(s.id, n.orderFormats) && (t[s.id] || (t[s.id] = {
96
97
  orderFormat: s,
97
98
  intervals: []
@@ -105,11 +106,11 @@ function E(e) {
105
106
  );
106
107
  return Object.values(o);
107
108
  }
108
- function D(e, o) {
109
+ function b(e, o) {
109
110
  const t = o.reduce((n, s) => s <= e ? n + 1 : n, 0);
110
111
  return e - t;
111
112
  }
112
- function b(e) {
113
+ function D(e) {
113
114
  const { mergedTables: o } = e.reduce(
114
115
  (t, n, s) => {
115
116
  const m = t.mergedTables.findIndex(
@@ -137,7 +138,7 @@ function b(e) {
137
138
  (i) => !t.skipOrderFormats.some((d) => d.id === i.id)
138
139
  );
139
140
  p.length > 0 && t.skipOrderFormats.push(...p);
140
- const a = D(s, [...t.removedIndexes]);
141
+ const a = b(s, [...t.removedIndexes]);
141
142
  return t.mergedTables.splice(a, 1), t.removedIndexes.push(s), t;
142
143
  }
143
144
  return t;
@@ -151,15 +152,15 @@ function j(e) {
151
152
  ...o,
152
153
  intervals: o.intervals.map((t) => ({
153
154
  ...t,
154
- id: x(t)
155
+ id: H(t)
155
156
  }))
156
157
  }));
157
158
  }
158
- function R(e, o) {
159
+ function N(e, o) {
159
160
  const t = E(
160
161
  j(e.serviceDateTimes)
161
162
  ), n = v(o), s = T(n), m = t.reduce(
162
- (a, i) => (a[i.orderFormat.id] || (a[i.orderFormat.id] = {}), i.intervals.reduce((d, f) => (H(
163
+ (a, i) => (a[i.orderFormat.id] || (a[i.orderFormat.id] = {}), i.intervals.reduce((d, f) => (M(
163
164
  f,
164
165
  s,
165
166
  d,
@@ -167,10 +168,11 @@ function R(e, o) {
167
168
  ), d), a[i.orderFormat.id]), a),
168
169
  {}
169
170
  ), u = {
170
- [l.EatIn]: I[0],
171
- [l.TakeAway]: I[1],
172
- [l.TableOrder]: I[2],
173
- [l.Delivery]: I[3]
171
+ [y.EatIn]: k[0],
172
+ [y.TakeAway]: k[1],
173
+ [y.TableOrder]: k[2],
174
+ [y.Delivery]: k[3],
175
+ [y.BoxPickup]: k[4]
174
176
  }, r = Object.entries(
175
177
  m
176
178
  ).map(([a, i]) => ({
@@ -180,21 +182,21 @@ function R(e, o) {
180
182
  isoWeekday: Number(d),
181
183
  key: f.key,
182
184
  open: f.open.sort(
183
- (O, k) => O.start.localeCompare(k.start)
185
+ (O, I) => O.start.localeCompare(I.start)
184
186
  ),
185
187
  adjusted: f.adjusted.sort(
186
- (O, k) => O.start.localeCompare(k.start)
188
+ (O, I) => O.start.localeCompare(I.start)
187
189
  ),
188
190
  closed: f.closed.sort(
189
- (O, k) => O.start.localeCompare(k.start)
191
+ (O, I) => O.start.localeCompare(I.start)
190
192
  )
191
193
  })
192
194
  )
193
195
  }));
194
- return b(r).sort(
196
+ return D(r).sort(
195
197
  (a, i) => a.orderFormats[0].id - i.orderFormats[0].id
196
198
  );
197
199
  }
198
200
  export {
199
- R as default
201
+ N as default
200
202
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ancon/wildcat-utils",
3
- "version": "1.40.9",
3
+ "version": "1.40.10",
4
4
  "private": false,
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",