@peabody-soft/mbs-model-ts 1.3.0 → 1.4.0
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/dist/ProtoMap.js +2 -1
- package/dist/WorkingDays.d.ts +3 -2
- package/dist/WorkingDays.js +16 -12
- package/dist/generated/WorkingDays.d.ts +9 -1
- package/dist/generated/WorkingDays.js +12 -4
- package/package.json +2 -2
package/dist/ProtoMap.js
CHANGED
|
@@ -1075,7 +1075,8 @@ function workingHoursFromProto(workingHours) {
|
|
|
1075
1075
|
function workingDaysFromProto(workingDays) {
|
|
1076
1076
|
if (workingDays === undefined)
|
|
1077
1077
|
return WorkingDays.ALL_DAYS;
|
|
1078
|
-
|
|
1078
|
+
// Not an optional field, so an unspecified zone arrives as an empty string rather than absent
|
|
1079
|
+
return new WorkingDays(Object.freeze([...workingDays.days]), workingDays.timeZone.length === 0 ? null : workingDays.timeZone, Object.freeze(workingDays.workingHours.map(workingHoursFromProto)));
|
|
1079
1080
|
}
|
|
1080
1081
|
function shoppingListItemFromProto(item) {
|
|
1081
1082
|
return ShoppingListItem.fromScaledValues(item.packageId, item.quantity, item.unitPrice, item.shoppingListOrder, item.isOriginal, item.isModified, item.isStockKeepingRequired, item.priceDiscount, item.discount, Object.freeze(item.taxes.map(taxFromProto)), item.expiry, stringFromProto(item.description));
|
package/dist/WorkingDays.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
export default class WorkingDays {
|
|
2
2
|
private readonly _days;
|
|
3
|
+
private readonly _timeZone;
|
|
3
4
|
private readonly _workingHours;
|
|
4
|
-
constructor(_days: ReadonlyArray<boolean>, _workingHours: ReadonlyArray<WorkingHours>);
|
|
5
|
+
constructor(_days: ReadonlyArray<boolean>, _timeZone: string | null, _workingHours: ReadonlyArray<WorkingHours>);
|
|
5
6
|
get days(): ReadonlyArray<boolean>;
|
|
7
|
+
get timeZone(): string | null;
|
|
6
8
|
get workingHours(): ReadonlyArray<WorkingHours>;
|
|
7
9
|
get includesAllDaysOfWeek(): boolean;
|
|
8
10
|
isWorkingDay(dayOfWeek: number): boolean;
|
|
9
11
|
getWorkingHours(dayOfWeek: number): WorkingHours | null;
|
|
10
12
|
isOpenAllDay(dayOfWeek: number): boolean;
|
|
11
|
-
isOpenAt(dayOfWeek: number, minuteOfDay: number): boolean;
|
|
12
13
|
private static checkDayOfWeek;
|
|
13
14
|
static readonly ALL_DAYS: WorkingDays;
|
|
14
15
|
}
|
package/dist/WorkingDays.js
CHANGED
|
@@ -2,11 +2,12 @@ import { Constants as proto_Constants } from "./generated/Constants";
|
|
|
2
2
|
import { InvalidArgumentException } from "./Exceptions";
|
|
3
3
|
// Days and hours a business works. Absence is the permissive value throughout: no WorkingDays
|
|
4
4
|
// means every day (ALL_DAYS); a day with no hours/ranges means worked all day.
|
|
5
|
-
//
|
|
6
|
-
//
|
|
5
|
+
// The hours are minutes after local midnight in timeZone, so a caller asking about a moment reads
|
|
6
|
+
// it in that zone first, as a day and a minute.
|
|
7
7
|
class WorkingDays {
|
|
8
|
-
constructor(_days, _workingHours) {
|
|
8
|
+
constructor(_days, _timeZone, _workingHours) {
|
|
9
9
|
this._days = _days;
|
|
10
|
+
this._timeZone = _timeZone;
|
|
10
11
|
this._workingHours = _workingHours;
|
|
11
12
|
}
|
|
12
13
|
// Index 0 is Sunday and index 6 is Saturday, the same numbering as Date.getDay. Shorter than
|
|
@@ -14,6 +15,13 @@ class WorkingDays {
|
|
|
14
15
|
get days() {
|
|
15
16
|
return this._days;
|
|
16
17
|
}
|
|
18
|
+
// The IANA ID of the zone the hours are in, for example "Asia/Kolkata" - never an abbreviation
|
|
19
|
+
// like "IST". Null when none was specified: settings saved before the protocol carried one, and
|
|
20
|
+
// ALL_DAYS. Then the hours cannot be placed on a clock, and only a caller that knows the
|
|
21
|
+
// business's zone can read a moment into them.
|
|
22
|
+
get timeZone() {
|
|
23
|
+
return this._timeZone;
|
|
24
|
+
}
|
|
17
25
|
// Indexed exactly as days above. Shorter than days, or empty, is normal: see the comment on
|
|
18
26
|
// this class for what a missing entry means.
|
|
19
27
|
get workingHours() {
|
|
@@ -41,20 +49,14 @@ class WorkingDays {
|
|
|
41
49
|
isOpenAllDay(dayOfWeek) {
|
|
42
50
|
return this.isWorkingDay(dayOfWeek) && this.getWorkingHours(dayOfWeek) === null;
|
|
43
51
|
}
|
|
44
|
-
// minuteOfDay is minutes after local midnight, from 0 to Constants.MINUTES_PER_DAY - 1
|
|
45
|
-
isOpenAt(dayOfWeek, minuteOfDay) {
|
|
46
|
-
if (!this.isWorkingDay(dayOfWeek))
|
|
47
|
-
return false;
|
|
48
|
-
const workingHours = this.getWorkingHours(dayOfWeek);
|
|
49
|
-
return workingHours === null || workingHours.contains(minuteOfDay);
|
|
50
|
-
}
|
|
51
52
|
static checkDayOfWeek(dayOfWeek) {
|
|
52
53
|
if (!Number.isInteger(dayOfWeek) || dayOfWeek < 0 || dayOfWeek >= proto_Constants.DAYS_IN_WEEK)
|
|
53
54
|
throw new InvalidArgumentException(`Not a day of the week: ${dayOfWeek}`);
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
|
-
// What an absent WorkingDays means: the business works every day, all day long
|
|
57
|
-
|
|
57
|
+
// What an absent WorkingDays means: the business works every day, all day long. With no hours
|
|
58
|
+
// there is nothing for a zone to place, so it has none.
|
|
59
|
+
WorkingDays.ALL_DAYS = new WorkingDays(Object.freeze([true, true, true, true, true, true, true]), null, Object.freeze([]));
|
|
58
60
|
export default WorkingDays;
|
|
59
61
|
// The hours of a single day that are worked, as the stretches of it that are.
|
|
60
62
|
export class WorkingHours {
|
|
@@ -73,6 +75,8 @@ export class WorkingHours {
|
|
|
73
75
|
get isAllDay() {
|
|
74
76
|
return (this._ranges.length === 0 || (this._ranges.length === 1 && this._ranges[0].isAllDay));
|
|
75
77
|
}
|
|
78
|
+
// minuteOfDay is minutes after local midnight in the zone of the WorkingDays these hours belong
|
|
79
|
+
// to, from 0 to Constants.MINUTES_PER_DAY - 1
|
|
76
80
|
contains(minuteOfDay) {
|
|
77
81
|
if (this.isAllDay)
|
|
78
82
|
return true;
|
|
@@ -20,12 +20,20 @@ export interface WorkingDays {
|
|
|
20
20
|
* @generated from protobuf field: repeated bool days = 1
|
|
21
21
|
*/
|
|
22
22
|
days: boolean[];
|
|
23
|
+
/**
|
|
24
|
+
* The IANA ID of the time zone the working hours are specified in, for example "Asia/Kolkata";
|
|
25
|
+
* never an abbreviation like "IST", which is ambiguous. At most 64 characters. Empty means it
|
|
26
|
+
* was never specified, as in settings saved before this field existed.
|
|
27
|
+
*
|
|
28
|
+
* @generated from protobuf field: string timeZone = 2
|
|
29
|
+
*/
|
|
30
|
+
timeZone: string;
|
|
23
31
|
/**
|
|
24
32
|
* Working hours of each day, indexed as days above (entry 0 = Sunday); up to
|
|
25
33
|
* Constants.DAYS_IN_WEEK entries, fewer is normal. A missing entry, or one with no ranges, means
|
|
26
34
|
* work all day; only meaningful on a day whose days entry is true.
|
|
27
35
|
*
|
|
28
|
-
* @generated from protobuf field: repeated com.merabills.storefront.WorkingHours workingHours =
|
|
36
|
+
* @generated from protobuf field: repeated com.merabills.storefront.WorkingHours workingHours = 3
|
|
29
37
|
*/
|
|
30
38
|
workingHours: WorkingHours[];
|
|
31
39
|
}
|
|
@@ -8,12 +8,14 @@ class WorkingDays$Type extends MessageType {
|
|
|
8
8
|
constructor() {
|
|
9
9
|
super("com.merabills.storefront.WorkingDays", [
|
|
10
10
|
{ no: 1, name: "days", kind: "scalar", repeat: 1 /*RepeatType.PACKED*/, T: 8 /*ScalarType.BOOL*/ },
|
|
11
|
-
{ no: 2, name: "
|
|
11
|
+
{ no: 2, name: "timeZone", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
|
|
12
|
+
{ no: 3, name: "workingHours", kind: "message", repeat: 2 /*RepeatType.UNPACKED*/, T: () => WorkingHours }
|
|
12
13
|
]);
|
|
13
14
|
}
|
|
14
15
|
create(value) {
|
|
15
16
|
const message = globalThis.Object.create((this.messagePrototype));
|
|
16
17
|
message.days = [];
|
|
18
|
+
message.timeZone = "";
|
|
17
19
|
message.workingHours = [];
|
|
18
20
|
if (value !== undefined)
|
|
19
21
|
reflectionMergePartial(this, message, value);
|
|
@@ -31,7 +33,10 @@ class WorkingDays$Type extends MessageType {
|
|
|
31
33
|
else
|
|
32
34
|
message.days.push(reader.bool());
|
|
33
35
|
break;
|
|
34
|
-
case /*
|
|
36
|
+
case /* string timeZone */ 2:
|
|
37
|
+
message.timeZone = reader.string();
|
|
38
|
+
break;
|
|
39
|
+
case /* repeated com.merabills.storefront.WorkingHours workingHours */ 3:
|
|
35
40
|
message.workingHours.push(WorkingHours.internalBinaryRead(reader, reader.uint32(), options));
|
|
36
41
|
break;
|
|
37
42
|
default:
|
|
@@ -53,9 +58,12 @@ class WorkingDays$Type extends MessageType {
|
|
|
53
58
|
writer.bool(message.days[i]);
|
|
54
59
|
writer.join();
|
|
55
60
|
}
|
|
56
|
-
/*
|
|
61
|
+
/* string timeZone = 2; */
|
|
62
|
+
if (message.timeZone !== "")
|
|
63
|
+
writer.tag(2, WireType.LengthDelimited).string(message.timeZone);
|
|
64
|
+
/* repeated com.merabills.storefront.WorkingHours workingHours = 3; */
|
|
57
65
|
for (let i = 0; i < message.workingHours.length; i++)
|
|
58
|
-
WorkingHours.internalBinaryWrite(message.workingHours[i], writer.tag(
|
|
66
|
+
WorkingHours.internalBinaryWrite(message.workingHours[i], writer.tag(3, WireType.LengthDelimited).fork(), options).join();
|
|
59
67
|
let u = options.writeUnknownFields;
|
|
60
68
|
if (u !== false)
|
|
61
69
|
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peabody-soft/mbs-model-ts",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "MeraBills storefront client-side model (TypeScript)",
|
|
5
5
|
"author": "Peabody Soft",
|
|
6
6
|
"license": "AGPL-3.0-or-later",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"typescript": "^7.0.2"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@peabody-soft/mbs-protos": "^1.
|
|
52
|
+
"@peabody-soft/mbs-protos": "^1.10.0",
|
|
53
53
|
"@protobuf-ts/runtime": "^2.11.1"
|
|
54
54
|
}
|
|
55
55
|
}
|