@molopos/shared 2.0.22 → 2.0.23

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/enum/index.d.ts CHANGED
@@ -190,9 +190,9 @@ export declare enum PricingTypeEnum {
190
190
  PremiumYearStripe = "premium-year-stripe"
191
191
  }
192
192
  /**
193
- * Quote status module enum
193
+ * Quote status enum
194
194
  */
195
- export declare enum QuoteStatusModuleEnum {
195
+ export declare enum QuoteStatusEnum {
196
196
  Signed = "SIGNED",
197
197
  Pending = "PENDING",
198
198
  Confirmed = "CONFIRMED",
package/enum/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.QuoteStatusModuleEnum = exports.PricingTypeEnum = exports.UserStatusEnum = exports.ApplicationSectionModuleEnum = exports.PagesProviderEnum = exports.PrivatePublicEnum = exports.StatusQuoteItemEnum = exports.ContributorRoleEnum = exports.QuoteSignedViewEnum = exports.CurrencyEnum = exports.ExportExtEnum = exports.SortOrderEnum = exports.BooleanStringEnum = exports.TransactionModelEnum = exports.TransactionDirectionEnum = exports.QueryTypeEnum = exports.ProductTypeEnum = exports.PaymentMethodEnum = exports.DiscountTypeEnum = exports.CustomerTypeEnum = void 0;
3
+ exports.QuoteStatusEnum = exports.PricingTypeEnum = exports.UserStatusEnum = exports.ApplicationSectionModuleEnum = exports.PagesProviderEnum = exports.PrivatePublicEnum = exports.StatusQuoteItemEnum = exports.ContributorRoleEnum = exports.QuoteSignedViewEnum = exports.CurrencyEnum = exports.ExportExtEnum = exports.SortOrderEnum = exports.BooleanStringEnum = exports.TransactionModelEnum = exports.TransactionDirectionEnum = exports.QueryTypeEnum = exports.ProductTypeEnum = exports.PaymentMethodEnum = exports.DiscountTypeEnum = exports.CustomerTypeEnum = void 0;
4
4
  /**
5
5
  * Customer type enum
6
6
  */
@@ -212,12 +212,12 @@ var PricingTypeEnum;
212
212
  PricingTypeEnum["PremiumYearStripe"] = "premium-year-stripe";
213
213
  })(PricingTypeEnum || (exports.PricingTypeEnum = PricingTypeEnum = {}));
214
214
  /**
215
- * Quote status module enum
215
+ * Quote status enum
216
216
  */
217
- var QuoteStatusModuleEnum;
218
- (function (QuoteStatusModuleEnum) {
219
- QuoteStatusModuleEnum["Signed"] = "SIGNED";
220
- QuoteStatusModuleEnum["Pending"] = "PENDING";
221
- QuoteStatusModuleEnum["Confirmed"] = "CONFIRMED";
222
- QuoteStatusModuleEnum["Cancelled"] = "CANCELLED";
223
- })(QuoteStatusModuleEnum || (exports.QuoteStatusModuleEnum = QuoteStatusModuleEnum = {}));
217
+ var QuoteStatusEnum;
218
+ (function (QuoteStatusEnum) {
219
+ QuoteStatusEnum["Signed"] = "SIGNED";
220
+ QuoteStatusEnum["Pending"] = "PENDING";
221
+ QuoteStatusEnum["Confirmed"] = "CONFIRMED";
222
+ QuoteStatusEnum["Cancelled"] = "CANCELLED";
223
+ })(QuoteStatusEnum || (exports.QuoteStatusEnum = QuoteStatusEnum = {}));
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@molopos/shared","publishConfig":{"access":"public"},"version":"2.0.22","description":"Shared between backend and frontend repos","license":"ISC","repository":{"type":"git","url":"https://github.com/unicubate/molopos-shared.git"},"dependencies":{"date-fns":"^4.1.0","luxon":"^3.7.2"}}
1
+ {"name":"@molopos/shared","publishConfig":{"access":"public"},"version":"2.0.23","description":"Shared between backend and frontend repos","license":"ISC","repository":{"type":"git","url":"https://github.com/unicubate/molopos-shared.git"},"dependencies":{"date-fns":"^4.1.0","luxon":"^3.7.2"}}
@@ -1,59 +0,0 @@
1
- export declare enum Action {
2
- Number = "NUM",
3
- String = "STR",
4
- Date = "DATE"
5
- }
6
- export declare enum Operation {
7
- Eq = "=",
8
- Neq = "!=",
9
- Gt = ">",
10
- Gte = ">=",
11
- Lt = "<",
12
- Lte = "<=",
13
- Range = "<>",
14
- Contains = "~",
15
- Regex = "$",
16
- In = "IN"
17
- }
18
- export type Payload<A extends Action = Action> = A extends Action.Number ? number : A extends Action.String ? string : A extends Action.Date ? Date : never;
19
- /**
20
- * ### Serialize
21
- *
22
- * ```typescript
23
- * const filter = new Filter(Action.Number, Operation.Gt, 10);
24
- *
25
- * filter.toString(); // 'NUM|>|10'
26
- * ```
27
- *
28
- * ### Deserialize
29
- *
30
- * ```typescript
31
- * const filter = Filter.parse('NUM|>|10', Action.Number);
32
- *
33
- * filter.action; // Action.Number
34
- * filter.operation; // Operation.Gt
35
- * filter.payload; // [10]
36
- *
37
- * Filter.parse('NUM|>|10', Action.Date);
38
- * // Error: Expected action DATE but got NUM
39
- *
40
- * Filter.parse('NUM|>|Hello World', Action.Number);
41
- * // Error: Invalid number payload: Hello World
42
- *
43
- * Filter.parse('NUM|>|10', Action.Number, [1, 2, 3]);
44
- * // Error: Invalid option: 10
45
- * ```
46
- */
47
- export declare class Filter<A extends Action = Action> {
48
- action: A;
49
- operation: Operation;
50
- payload: Payload<A>[];
51
- constructor(action: A, operation: Operation, ...payload: Payload<A>[]);
52
- get ok(): boolean;
53
- as(f: (payload: Payload<A>) => Payload<A>): Filter<A>;
54
- toString(): string;
55
- /**
56
- * @throws {Error}
57
- */
58
- static parse<A extends Action = Action>(str: string, action?: A, allowed?: Payload<A>[]): Filter<A>;
59
- }
@@ -1,122 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Filter = exports.Operation = exports.Action = void 0;
4
- var Action;
5
- (function (Action) {
6
- Action["Number"] = "NUM";
7
- Action["String"] = "STR";
8
- Action["Date"] = "DATE";
9
- })(Action || (exports.Action = Action = {}));
10
- ;
11
- var Operation;
12
- (function (Operation) {
13
- Operation["Eq"] = "=";
14
- Operation["Neq"] = "!=";
15
- Operation["Gt"] = ">";
16
- Operation["Gte"] = ">=";
17
- Operation["Lt"] = "<";
18
- Operation["Lte"] = "<=";
19
- Operation["Range"] = "<>";
20
- Operation["Contains"] = "~";
21
- Operation["Regex"] = "$";
22
- Operation["In"] = "IN";
23
- })(Operation || (exports.Operation = Operation = {}));
24
- ;
25
- /**
26
- * ### Serialize
27
- *
28
- * ```typescript
29
- * const filter = new Filter(Action.Number, Operation.Gt, 10);
30
- *
31
- * filter.toString(); // 'NUM|>|10'
32
- * ```
33
- *
34
- * ### Deserialize
35
- *
36
- * ```typescript
37
- * const filter = Filter.parse('NUM|>|10', Action.Number);
38
- *
39
- * filter.action; // Action.Number
40
- * filter.operation; // Operation.Gt
41
- * filter.payload; // [10]
42
- *
43
- * Filter.parse('NUM|>|10', Action.Date);
44
- * // Error: Expected action DATE but got NUM
45
- *
46
- * Filter.parse('NUM|>|Hello World', Action.Number);
47
- * // Error: Invalid number payload: Hello World
48
- *
49
- * Filter.parse('NUM|>|10', Action.Number, [1, 2, 3]);
50
- * // Error: Invalid option: 10
51
- * ```
52
- */
53
- class Filter {
54
- constructor(action, operation, ...payload) {
55
- this.action = action;
56
- this.operation = operation;
57
- this.payload = payload;
58
- }
59
- get ok() {
60
- return this.operation === Operation.Range
61
- ? this.payload.length > 1
62
- : this.payload.length > 0;
63
- }
64
- as(f) {
65
- return new Filter(this.action, this.operation, ...this.payload.map(f));
66
- }
67
- toString() {
68
- return this.action
69
- + "|" + this.operation
70
- + "|" + this.payload.map((p) => p instanceof Date ? p.toISOString() : p.toString()).join('|');
71
- }
72
- /**
73
- * @throws {Error}
74
- */
75
- static parse(str, action, allowed) {
76
- const [_action, operation, ...raw] = str.split('|');
77
- const payload = raw;
78
- if (!_action || !operation || !payload.length) {
79
- throw new Error('Invalid filter string');
80
- }
81
- if (action && _action !== action) {
82
- throw new Error('Expected action ' + action + ' but got ' + _action);
83
- }
84
- switch (_action) {
85
- case Action.Number:
86
- raw.forEach((p, i) => {
87
- if (!/^-?(\d_?)+$|^-?(\d_?)*\.(\d_?)+$/.test(p)) {
88
- throw new Error('Invalid number payload: ' + p);
89
- }
90
- payload[i] = Number(p);
91
- if (allowed && !allowed.some((p) => p === payload[i])) {
92
- throw new Error('Invalid option: ' + p);
93
- }
94
- });
95
- break;
96
- case Action.Date:
97
- raw.forEach((p, i) => {
98
- if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/.test(p)) {
99
- throw new Error('Invalid date payload: ' + p);
100
- }
101
- payload[i] = new Date(p);
102
- if (allowed && !allowed.some((p) => p === payload[i])) {
103
- throw new Error('Invalid option: ' + p);
104
- }
105
- });
106
- break;
107
- case Action.String:
108
- if (allowed) {
109
- raw.forEach((p, i) => {
110
- if (!allowed.some((p) => p === payload[i])) {
111
- throw new Error('Invalid option: ' + p);
112
- }
113
- });
114
- }
115
- break;
116
- default:
117
- throw new Error('Unknown action: ' + _action);
118
- }
119
- return new Filter(_action, operation, ...payload);
120
- }
121
- }
122
- exports.Filter = Filter;