@molopos/shared 2.0.22 → 2.0.24

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
@@ -58,6 +58,7 @@ export declare enum QueryTypeEnum {
58
58
  QuoteOption = "QUOTEOPTION",
59
59
  Section = "SECTION",
60
60
  Discount = "DISCOUNT",
61
+ Project = "PROJECT",
61
62
  UserAddress = "USERADDRESS",
62
63
  Subcategory = "SUBCATEGORY",
63
64
  ExpenseItem = "EXPENSEITEM",
@@ -190,9 +191,9 @@ export declare enum PricingTypeEnum {
190
191
  PremiumYearStripe = "premium-year-stripe"
191
192
  }
192
193
  /**
193
- * Quote status module enum
194
+ * Quote status enum
194
195
  */
195
- export declare enum QuoteStatusModuleEnum {
196
+ export declare enum QuoteStatusEnum {
196
197
  Signed = "SIGNED",
197
198
  Pending = "PENDING",
198
199
  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
  */
@@ -66,6 +66,7 @@ var QueryTypeEnum;
66
66
  QueryTypeEnum["QuoteOption"] = "QUOTEOPTION";
67
67
  QueryTypeEnum["Section"] = "SECTION";
68
68
  QueryTypeEnum["Discount"] = "DISCOUNT";
69
+ QueryTypeEnum["Project"] = "PROJECT";
69
70
  QueryTypeEnum["UserAddress"] = "USERADDRESS";
70
71
  QueryTypeEnum["Subcategory"] = "SUBCATEGORY";
71
72
  QueryTypeEnum["ExpenseItem"] = "EXPENSEITEM";
@@ -212,12 +213,12 @@ var PricingTypeEnum;
212
213
  PricingTypeEnum["PremiumYearStripe"] = "premium-year-stripe";
213
214
  })(PricingTypeEnum || (exports.PricingTypeEnum = PricingTypeEnum = {}));
214
215
  /**
215
- * Quote status module enum
216
+ * Quote status enum
216
217
  */
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 = {}));
218
+ var QuoteStatusEnum;
219
+ (function (QuoteStatusEnum) {
220
+ QuoteStatusEnum["Signed"] = "SIGNED";
221
+ QuoteStatusEnum["Pending"] = "PENDING";
222
+ QuoteStatusEnum["Confirmed"] = "CONFIRMED";
223
+ QuoteStatusEnum["Cancelled"] = "CANCELLED";
224
+ })(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.24","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;