@fctc/interface-logic 1.7.1 → 1.7.2

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.
Files changed (38) hide show
  1. package/dist/{configs.mjs → configs.cjs} +161 -111
  2. package/dist/{configs.d.mts → configs.d.cts} +2 -1
  3. package/dist/configs.d.ts +1 -0
  4. package/dist/configs.js +124 -146
  5. package/dist/{constants.mjs → constants.cjs} +40 -2
  6. package/dist/constants.js +2 -41
  7. package/dist/{environment.mjs → environment.cjs} +2029 -1967
  8. package/dist/environment.d.cts +56 -0
  9. package/dist/environment.d.ts +24 -6
  10. package/dist/environment.js +2235 -2248
  11. package/dist/{hooks.mjs → hooks.cjs} +4021 -3773
  12. package/dist/{hooks.d.mts → hooks.d.cts} +2 -7
  13. package/dist/hooks.d.ts +1 -6
  14. package/dist/hooks.js +3916 -3873
  15. package/dist/{provider.mjs → provider.cjs} +688 -586
  16. package/dist/{provider.d.mts → provider.d.cts} +1 -1
  17. package/dist/provider.d.ts +1 -1
  18. package/dist/provider.js +648 -620
  19. package/dist/{services.mjs → services.cjs} +4186 -3980
  20. package/dist/{services.d.mts → services.d.cts} +1 -2
  21. package/dist/services.d.ts +0 -1
  22. package/dist/services.js +4141 -4021
  23. package/dist/{store.mjs → store.cjs} +149 -33
  24. package/dist/{store.d.mts → store.d.cts} +127 -155
  25. package/dist/store.d.ts +127 -155
  26. package/dist/store.js +44 -134
  27. package/dist/types.cjs +17 -0
  28. package/dist/{types.d.mts → types.d.cts} +1 -1
  29. package/dist/types.js +0 -18
  30. package/dist/{utils.mjs → utils.cjs} +202 -115
  31. package/dist/{utils.d.mts → utils.d.cts} +2 -2
  32. package/dist/utils.d.ts +2 -2
  33. package/dist/utils.js +135 -176
  34. package/package.json +82 -81
  35. package/dist/environment.d.mts +0 -38
  36. package/dist/types.mjs +0 -0
  37. /package/dist/{constants.d.mts → constants.d.cts} +0 -0
  38. /package/dist/{view-type-BGJfDe73.d.mts → view-type-BGJfDe73.d.cts} +0 -0
@@ -1,908 +1,297 @@
1
- "use strict";
2
- var __create = Object.create;
3
1
  var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __pow = Math.pow;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __spreadValues = (a, b) => {
10
+ for (var prop in b || (b = {}))
11
+ if (__hasOwnProp.call(b, prop))
12
+ __defNormalProp(a, prop, b[prop]);
13
+ if (__getOwnPropSymbols)
14
+ for (var prop of __getOwnPropSymbols(b)) {
15
+ if (__propIsEnum.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ }
18
+ return a;
11
19
  };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
20
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
+ var __async = (__this, __arguments, generator) => {
22
+ return new Promise((resolve, reject) => {
23
+ var fulfilled = (value) => {
24
+ try {
25
+ step(generator.next(value));
26
+ } catch (e) {
27
+ reject(e);
28
+ }
29
+ };
30
+ var rejected = (value) => {
31
+ try {
32
+ step(generator.throw(value));
33
+ } catch (e) {
34
+ reject(e);
35
+ }
36
+ };
37
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
38
+ step((generator = generator.apply(__this, __arguments)).next());
39
+ });
19
40
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
41
 
30
- // src/environment.ts
31
- var environment_exports = {};
32
- __export(environment_exports, {
33
- EnvStore: () => EnvStore,
34
- env: () => env,
35
- getEnv: () => getEnv,
36
- initEnv: () => initEnv
37
- });
38
- module.exports = __toCommonJS(environment_exports);
42
+ // src/configs/axios-client.ts
43
+ import axios from "axios";
39
44
 
40
- // src/store/store.ts
41
- var import_toolkit11 = require("@reduxjs/toolkit");
45
+ // src/utils/format.ts
46
+ import moment from "moment";
42
47
 
43
- // node_modules/redux/dist/redux.mjs
44
- function formatProdErrorMessage(code) {
45
- return `Minified Redux error #${code}; visit https://redux.js.org/Errors?code=${code} for the full message or use the non-minified dev environment for full errors. `;
46
- }
47
- var randomString = () => Math.random().toString(36).substring(7).split("").join(".");
48
- var ActionTypes = {
49
- INIT: `@@redux/INIT${/* @__PURE__ */ randomString()}`,
50
- REPLACE: `@@redux/REPLACE${/* @__PURE__ */ randomString()}`,
51
- PROBE_UNKNOWN_ACTION: () => `@@redux/PROBE_UNKNOWN_ACTION${randomString()}`
48
+ // src/utils/domain/py_tokenizer.ts
49
+ var TokenizerError = class extends Error {
52
50
  };
53
- var actionTypes_default = ActionTypes;
54
- function isPlainObject(obj) {
55
- if (typeof obj !== "object" || obj === null)
56
- return false;
57
- let proto = obj;
58
- while (Object.getPrototypeOf(proto) !== null) {
59
- proto = Object.getPrototypeOf(proto);
60
- }
61
- return Object.getPrototypeOf(obj) === proto || Object.getPrototypeOf(obj) === null;
62
- }
63
- function miniKindOf(val) {
64
- if (val === void 0)
65
- return "undefined";
66
- if (val === null)
67
- return "null";
68
- const type = typeof val;
69
- switch (type) {
70
- case "boolean":
71
- case "string":
72
- case "number":
73
- case "symbol":
74
- case "function": {
75
- return type;
76
- }
77
- }
78
- if (Array.isArray(val))
79
- return "array";
80
- if (isDate(val))
81
- return "date";
82
- if (isError(val))
83
- return "error";
84
- const constructorName = ctorName(val);
85
- switch (constructorName) {
86
- case "Symbol":
87
- case "Promise":
88
- case "WeakMap":
89
- case "WeakSet":
90
- case "Map":
91
- case "Set":
92
- return constructorName;
93
- }
94
- return Object.prototype.toString.call(val).slice(8, -1).toLowerCase().replace(/\s/g, "");
95
- }
96
- function ctorName(val) {
97
- return typeof val.constructor === "function" ? val.constructor.name : null;
98
- }
99
- function isError(val) {
100
- return val instanceof Error || typeof val.message === "string" && val.constructor && typeof val.constructor.stackTraceLimit === "number";
101
- }
102
- function isDate(val) {
103
- if (val instanceof Date)
104
- return true;
105
- return typeof val.toDateString === "function" && typeof val.getDate === "function" && typeof val.setDate === "function";
106
- }
107
- function kindOf(val) {
108
- let typeOfVal = typeof val;
109
- if (process.env.NODE_ENV !== "production") {
110
- typeOfVal = miniKindOf(val);
111
- }
112
- return typeOfVal;
113
- }
114
- function warning(message) {
115
- if (typeof console !== "undefined" && typeof console.error === "function") {
116
- console.error(message);
117
- }
118
- try {
119
- throw new Error(message);
120
- } catch (e) {
121
- }
122
- }
123
- function getUnexpectedStateShapeWarningMessage(inputState, reducers, action, unexpectedKeyCache) {
124
- const reducerKeys = Object.keys(reducers);
125
- const argumentName = action && action.type === actionTypes_default.INIT ? "preloadedState argument passed to createStore" : "previous state received by the reducer";
126
- if (reducerKeys.length === 0) {
127
- return "Store does not have a valid reducer. Make sure the argument passed to combineReducers is an object whose values are reducers.";
128
- }
129
- if (!isPlainObject(inputState)) {
130
- return `The ${argumentName} has unexpected type of "${kindOf(inputState)}". Expected argument to be an object with the following keys: "${reducerKeys.join('", "')}"`;
131
- }
132
- const unexpectedKeys = Object.keys(inputState).filter((key) => !reducers.hasOwnProperty(key) && !unexpectedKeyCache[key]);
133
- unexpectedKeys.forEach((key) => {
134
- unexpectedKeyCache[key] = true;
135
- });
136
- if (action && action.type === actionTypes_default.REPLACE)
137
- return;
138
- if (unexpectedKeys.length > 0) {
139
- return `Unexpected ${unexpectedKeys.length > 1 ? "keys" : "key"} "${unexpectedKeys.join('", "')}" found in ${argumentName}. Expected to find one of the known reducer keys instead: "${reducerKeys.join('", "')}". Unexpected keys will be ignored.`;
140
- }
141
- }
142
- function assertReducerShape(reducers) {
143
- Object.keys(reducers).forEach((key) => {
144
- const reducer = reducers[key];
145
- const initialState10 = reducer(void 0, {
146
- type: actionTypes_default.INIT
147
- });
148
- if (typeof initialState10 === "undefined") {
149
- throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(12) : `The slice reducer for key "${key}" returned undefined during initialization. If the state passed to the reducer is undefined, you must explicitly return the initial state. The initial state may not be undefined. If you don't want to set a value for this reducer, you can use null instead of undefined.`);
150
- }
151
- if (typeof reducer(void 0, {
152
- type: actionTypes_default.PROBE_UNKNOWN_ACTION()
153
- }) === "undefined") {
154
- throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(13) : `The slice reducer for key "${key}" returned undefined when probed with a random type. Don't try to handle '${actionTypes_default.INIT}' or other actions in "redux/*" namespace. They are considered private. Instead, you must return the current state for any unknown actions, unless it is undefined, in which case you must return the initial state, regardless of the action type. The initial state may not be undefined, but can be null.`);
51
+ var directMap = {
52
+ "\\": "\\",
53
+ '"': '"',
54
+ "'": "'",
55
+ a: "\x07",
56
+ b: "\b",
57
+ f: "\f",
58
+ n: "\n",
59
+ r: "\r",
60
+ t: " ",
61
+ v: "\v"
62
+ };
63
+ function decodeStringLiteral(str, unicode) {
64
+ const out = [];
65
+ let code;
66
+ for (let i = 0; i < str.length; ++i) {
67
+ if (str[i] !== "\\") {
68
+ out.push(str[i]);
69
+ continue;
155
70
  }
156
- });
157
- }
158
- function combineReducers(reducers) {
159
- const reducerKeys = Object.keys(reducers);
160
- const finalReducers = {};
161
- for (let i = 0; i < reducerKeys.length; i++) {
162
- const key = reducerKeys[i];
163
- if (process.env.NODE_ENV !== "production") {
164
- if (typeof reducers[key] === "undefined") {
165
- warning(`No reducer provided for key "${key}"`);
166
- }
71
+ const escape = str[i + 1];
72
+ if (escape in directMap) {
73
+ out.push(directMap[escape]);
74
+ ++i;
75
+ continue;
167
76
  }
168
- if (typeof reducers[key] === "function") {
169
- finalReducers[key] = reducers[key];
77
+ switch (escape) {
78
+ case "\n":
79
+ ++i;
80
+ continue;
81
+ case "N":
82
+ if (!unicode) {
83
+ break;
84
+ }
85
+ throw new TokenizerError("SyntaxError: \\N{} escape not implemented");
86
+ case "u":
87
+ if (!unicode) {
88
+ break;
89
+ }
90
+ const uni = str.slice(i + 2, i + 6);
91
+ if (!/[0-9a-f]{4}/i.test(uni)) {
92
+ throw new TokenizerError(
93
+ [
94
+ "SyntaxError: (unicode error) 'unicodeescape' codec",
95
+ " can't decode bytes in position ",
96
+ i,
97
+ "-",
98
+ i + 4,
99
+ ": truncated \\uXXXX escape"
100
+ ].join("")
101
+ );
102
+ }
103
+ code = parseInt(uni, 16);
104
+ out.push(String.fromCharCode(code));
105
+ i += 5;
106
+ continue;
107
+ case "U":
108
+ if (!unicode) {
109
+ break;
110
+ }
111
+ throw new TokenizerError("SyntaxError: \\U escape not implemented");
112
+ case "x":
113
+ const hex = str.slice(i + 2, i + 4);
114
+ if (!/[0-9a-f]{2}/i.test(hex)) {
115
+ if (!unicode) {
116
+ throw new TokenizerError("ValueError: invalid \\x escape");
117
+ }
118
+ throw new TokenizerError(
119
+ [
120
+ "SyntaxError: (unicode error) 'unicodeescape'",
121
+ " codec can't decode bytes in position ",
122
+ i,
123
+ "-",
124
+ i + 2,
125
+ ": truncated \\xXX escape"
126
+ ].join("")
127
+ );
128
+ }
129
+ code = parseInt(hex, 16);
130
+ out.push(String.fromCharCode(code));
131
+ i += 3;
132
+ continue;
133
+ default:
134
+ if (!/[0-8]/.test(escape)) {
135
+ break;
136
+ }
137
+ const r = /[0-8]{1,3}/g;
138
+ r.lastIndex = i + 1;
139
+ const m = r.exec(str);
140
+ if (!m) break;
141
+ const oct = m[0];
142
+ code = parseInt(oct, 8);
143
+ out.push(String.fromCharCode(code));
144
+ i += oct.length;
145
+ continue;
170
146
  }
147
+ out.push("\\");
171
148
  }
172
- const finalReducerKeys = Object.keys(finalReducers);
173
- let unexpectedKeyCache;
174
- if (process.env.NODE_ENV !== "production") {
175
- unexpectedKeyCache = {};
176
- }
177
- let shapeAssertionError;
178
- try {
179
- assertReducerShape(finalReducers);
180
- } catch (e) {
181
- shapeAssertionError = e;
182
- }
183
- return function combination(state = {}, action) {
184
- if (shapeAssertionError) {
185
- throw shapeAssertionError;
186
- }
187
- if (process.env.NODE_ENV !== "production") {
188
- const warningMessage = getUnexpectedStateShapeWarningMessage(state, finalReducers, action, unexpectedKeyCache);
189
- if (warningMessage) {
190
- warning(warningMessage);
191
- }
192
- }
193
- let hasChanged = false;
194
- const nextState = {};
195
- for (let i = 0; i < finalReducerKeys.length; i++) {
196
- const key = finalReducerKeys[i];
197
- const reducer = finalReducers[key];
198
- const previousStateForKey = state[key];
199
- const nextStateForKey = reducer(previousStateForKey, action);
200
- if (typeof nextStateForKey === "undefined") {
201
- const actionType = action && action.type;
202
- throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(14) : `When called with an action of type ${actionType ? `"${String(actionType)}"` : "(unknown type)"}, the slice reducer for key "${key}" returned undefined. To ignore an action, you must explicitly return the previous state. If you want this reducer to hold no value, you can return null instead of undefined.`);
149
+ return out.join("");
150
+ }
151
+ var constants = /* @__PURE__ */ new Set(["None", "False", "True"]);
152
+ var comparators = [
153
+ "in",
154
+ "not",
155
+ "not in",
156
+ "is",
157
+ "is not",
158
+ "<",
159
+ "<=",
160
+ ">",
161
+ ">=",
162
+ "<>",
163
+ "!=",
164
+ "=="
165
+ ];
166
+ var binaryOperators = [
167
+ "or",
168
+ "and",
169
+ "|",
170
+ "^",
171
+ "&",
172
+ "<<",
173
+ ">>",
174
+ "+",
175
+ "-",
176
+ "*",
177
+ "/",
178
+ "//",
179
+ "%",
180
+ "~",
181
+ "**",
182
+ "."
183
+ ];
184
+ var unaryOperators = ["-"];
185
+ var symbols = /* @__PURE__ */ new Set([
186
+ ...["(", ")", "[", "]", "{", "}", ":", ","],
187
+ ...["if", "else", "lambda", "="],
188
+ ...comparators,
189
+ ...binaryOperators,
190
+ ...unaryOperators
191
+ ]);
192
+ function group(...args) {
193
+ return "(" + args.join("|") + ")";
194
+ }
195
+ var Name = "[a-zA-Z_]\\w*";
196
+ var Whitespace = "[ \\f\\t]*";
197
+ var DecNumber = "\\d+(L|l)?";
198
+ var IntNumber = DecNumber;
199
+ var Exponent = "[eE][+-]?\\d+";
200
+ var PointFloat = group(`\\d+\\.\\d*(${Exponent})?`, `\\.\\d+(${Exponent})?`);
201
+ var FloatNumber = group(PointFloat, `\\d+${Exponent}`);
202
+ var Number2 = group(FloatNumber, IntNumber);
203
+ var Operator = group(
204
+ "\\*\\*=?",
205
+ ">>=?",
206
+ "<<=?",
207
+ "<>",
208
+ "!=",
209
+ "//=?",
210
+ "[+\\-*/%&|^=<>]=?",
211
+ "~"
212
+ );
213
+ var Bracket = "[\\[\\]\\(\\)\\{\\}]";
214
+ var Special = "[:;.,`@]";
215
+ var Funny = group(Operator, Bracket, Special);
216
+ var ContStr = group(
217
+ "([uU])?'([^\\n'\\\\]*(?:\\\\.[^\\n'\\\\]*)*)'",
218
+ '([uU])?"([^\\n"\\\\]*(?:\\\\.[^\\n"\\\\]*)*)"'
219
+ );
220
+ var PseudoToken = Whitespace + group(Number2, Funny, ContStr, Name);
221
+ var NumberPattern = new RegExp("^" + Number2 + "$");
222
+ var StringPattern = new RegExp("^" + ContStr + "$");
223
+ var NamePattern = new RegExp("^" + Name + "$");
224
+ var strip = new RegExp("^" + Whitespace);
225
+ function tokenize(str) {
226
+ const tokens = [];
227
+ const max = str.length;
228
+ let start = 0;
229
+ let end = 0;
230
+ const pseudoprog = new RegExp(PseudoToken, "g");
231
+ while (pseudoprog.lastIndex < max) {
232
+ const pseudomatch = pseudoprog.exec(str);
233
+ if (!pseudomatch) {
234
+ if (/^\s+$/.test(str.slice(end))) {
235
+ break;
203
236
  }
204
- nextState[key] = nextStateForKey;
205
- hasChanged = hasChanged || nextStateForKey !== previousStateForKey;
237
+ throw new TokenizerError(
238
+ "Failed to tokenize <<" + str + ">> at index " + (end || 0) + "; parsed so far: " + tokens
239
+ );
206
240
  }
207
- hasChanged = hasChanged || finalReducerKeys.length !== Object.keys(state).length;
208
- return hasChanged ? nextState : state;
209
- };
210
- }
211
-
212
- // src/store/reducers/breadcrums-slice/index.ts
213
- var import_toolkit = require("@reduxjs/toolkit");
214
- var initialState = {
215
- breadCrumbs: []
216
- };
217
- var breadcrumbsSlice = (0, import_toolkit.createSlice)({
218
- name: "breadcrumbs",
219
- initialState,
220
- reducers: {
221
- setBreadCrumbs: (state, action) => {
222
- state.breadCrumbs = [...state.breadCrumbs, action.payload];
241
+ if (pseudomatch.index > end) {
242
+ if (str.slice(end, pseudomatch.index).trim()) {
243
+ throw new TokenizerError("Invalid expression");
244
+ }
223
245
  }
224
- }
225
- });
226
- var { setBreadCrumbs } = breadcrumbsSlice.actions;
227
- var breadcrums_slice_default = breadcrumbsSlice.reducer;
228
-
229
- // src/store/reducers/env-slice/index.ts
230
- var import_toolkit2 = require("@reduxjs/toolkit");
231
- var initialState2 = {
232
- baseUrl: "",
233
- companies: [],
234
- user: {},
235
- db: "",
236
- refreshTokenEndpoint: "",
237
- config: null,
238
- envFile: null,
239
- requests: null,
240
- defaultCompany: {
241
- id: null,
242
- logo: "",
243
- secondary_color: "",
244
- primary_color: ""
245
- },
246
- context: {
247
- uid: null,
248
- allowed_company_ids: [],
249
- lang: "vi_VN",
250
- tz: "Asia/Saigon"
251
- }
252
- };
253
- var envSlice = (0, import_toolkit2.createSlice)({
254
- name: "env",
255
- initialState: initialState2,
256
- reducers: {
257
- setEnv: (state, action) => {
258
- Object.assign(state, action.payload);
259
- },
260
- setUid: (state, action) => {
261
- state.context.uid = action.payload;
262
- },
263
- setAllowCompanies: (state, action) => {
264
- state.context.allowed_company_ids = action.payload;
265
- },
266
- setCompanies: (state, action) => {
267
- state.companies = action.payload;
268
- },
269
- setDefaultCompany: (state, action) => {
270
- state.defaultCompany = action.payload;
271
- },
272
- setLang: (state, action) => {
273
- state.context.lang = action.payload;
274
- },
275
- setUser: (state, action) => {
276
- state.user = action.payload;
277
- },
278
- setConfig: (state, action) => {
279
- state.config = action.payload;
280
- },
281
- setEnvFile: (state, action) => {
282
- state.envFile = action.payload;
246
+ start = pseudomatch.index;
247
+ end = pseudoprog.lastIndex;
248
+ let token = str.slice(start, end).replace(strip, "");
249
+ if (NumberPattern.test(token)) {
250
+ tokens.push({
251
+ type: 0,
252
+ value: parseFloat(token)
253
+ });
254
+ } else if (StringPattern.test(token)) {
255
+ const m = StringPattern.exec(token);
256
+ if (!m) throw new TokenizerError("Invalid string match");
257
+ tokens.push({
258
+ type: 1,
259
+ value: decodeStringLiteral(
260
+ m[3] !== void 0 ? m[3] : m[5],
261
+ !!(m[2] || m[4])
262
+ )
263
+ });
264
+ } else if (symbols.has(token)) {
265
+ if (token === "in" && tokens.length > 0 && tokens[tokens.length - 1].value === "not") {
266
+ token = "not in";
267
+ tokens.pop();
268
+ } else if (token === "not" && tokens.length > 0 && tokens[tokens.length - 1].value === "is") {
269
+ token = "is not";
270
+ tokens.pop();
271
+ }
272
+ tokens.push({
273
+ type: 2,
274
+ value: token
275
+ });
276
+ } else if (constants.has(token)) {
277
+ tokens.push({
278
+ type: 4,
279
+ value: token
280
+ });
281
+ } else if (NamePattern.test(token)) {
282
+ tokens.push({
283
+ type: 3,
284
+ value: token
285
+ });
286
+ } else {
287
+ throw new TokenizerError("Invalid expression");
283
288
  }
284
289
  }
285
- });
286
- var {
287
- setEnv,
288
- setUid,
289
- setLang,
290
- setAllowCompanies,
291
- setCompanies,
292
- setDefaultCompany,
293
- setUser,
294
- setConfig,
295
- setEnvFile
296
- } = envSlice.actions;
297
- var env_slice_default = envSlice.reducer;
290
+ return tokens;
291
+ }
298
292
 
299
- // src/store/reducers/excel-slice/index.ts
300
- var import_toolkit3 = require("@reduxjs/toolkit");
301
- var initialState3 = {
302
- dataParse: null,
303
- idFile: null,
304
- isFileLoaded: false,
305
- loadingImport: false,
306
- selectedFile: null,
307
- errorData: null
308
- };
309
- var excelSlice = (0, import_toolkit3.createSlice)({
310
- name: "excel",
311
- initialState: initialState3,
312
- reducers: {
313
- setDataParse: (state, action) => {
314
- state.dataParse = action.payload;
315
- },
316
- setIdFile: (state, action) => {
317
- state.idFile = action.payload;
318
- },
319
- setIsFileLoaded: (state, action) => {
320
- state.isFileLoaded = action.payload;
321
- },
322
- setLoadingImport: (state, action) => {
323
- state.loadingImport = action.payload;
324
- },
325
- setSelectedFile: (state, action) => {
326
- state.selectedFile = action.payload;
327
- },
328
- setErrorData: (state, action) => {
329
- state.errorData = action.payload;
330
- }
331
- }
332
- });
333
- var {
334
- setDataParse,
335
- setIdFile,
336
- setIsFileLoaded,
337
- setLoadingImport,
338
- setSelectedFile,
339
- setErrorData
340
- } = excelSlice.actions;
341
- var excel_slice_default = excelSlice.reducer;
342
-
343
- // src/store/reducers/form-slice/index.ts
344
- var import_toolkit4 = require("@reduxjs/toolkit");
345
- var initialState4 = {
346
- viewDataStore: {},
347
- isShowingModalDetail: false,
348
- isShowModalTranslate: false,
349
- formSubmitComponent: {},
350
- fieldTranslation: null,
351
- listSubject: {},
352
- dataUser: {}
353
- };
354
- var formSlice = (0, import_toolkit4.createSlice)({
355
- name: "form",
356
- initialState: initialState4,
357
- reducers: {
358
- setViewDataStore: (state, action) => {
359
- state.viewDataStore = action.payload;
360
- },
361
- setIsShowingModalDetail: (state, action) => {
362
- state.isShowingModalDetail = action.payload;
363
- },
364
- setIsShowModalTranslate: (state, action) => {
365
- state.isShowModalTranslate = action.payload;
366
- },
367
- setFormSubmitComponent: (state, action) => {
368
- state.formSubmitComponent[action.payload.key] = action.payload.component;
369
- },
370
- setFieldTranslate: (state, action) => {
371
- state.fieldTranslation = action.payload;
372
- },
373
- setListSubject: (state, action) => {
374
- state.listSubject = action.payload;
375
- },
376
- setDataUser: (state, action) => {
377
- state.dataUser = action.payload;
378
- }
379
- }
380
- });
381
- var {
382
- setViewDataStore,
383
- setIsShowingModalDetail,
384
- setIsShowModalTranslate,
385
- setFormSubmitComponent,
386
- setFieldTranslate,
387
- setListSubject,
388
- setDataUser
389
- } = formSlice.actions;
390
- var form_slice_default = formSlice.reducer;
391
-
392
- // src/store/reducers/header-slice/index.ts
393
- var import_toolkit5 = require("@reduxjs/toolkit");
394
- var headerSlice = (0, import_toolkit5.createSlice)({
395
- name: "header",
396
- initialState: {
397
- value: { allowedCompanyIds: [] }
398
- },
399
- reducers: {
400
- setHeader: (state, action) => {
401
- state.value = { ...state.value, ...action.payload };
402
- },
403
- setAllowedCompanyIds: (state, action) => {
404
- state.value.allowedCompanyIds = action.payload;
405
- }
406
- }
407
- });
408
- var { setAllowedCompanyIds, setHeader } = headerSlice.actions;
409
- var header_slice_default = headerSlice.reducer;
410
-
411
- // src/store/reducers/list-slice/index.ts
412
- var import_toolkit6 = require("@reduxjs/toolkit");
413
- var initialState5 = {
414
- pageLimit: 10,
415
- fields: {},
416
- order: "",
417
- selectedRowKeys: [],
418
- selectedRadioKey: 0,
419
- indexRowTableModal: -2,
420
- isUpdateTableModal: false,
421
- footerGroupTable: {},
422
- transferDetail: null,
423
- page: 0,
424
- domainTable: []
425
- };
426
- var listSlice = (0, import_toolkit6.createSlice)({
427
- name: "list",
428
- initialState: initialState5,
429
- reducers: {
430
- setPageLimit: (state, action) => {
431
- state.pageLimit = action.payload;
432
- },
433
- setFields: (state, action) => {
434
- state.fields = action.payload;
435
- },
436
- setOrder: (state, action) => {
437
- state.order = action.payload;
438
- },
439
- setSelectedRowKeys: (state, action) => {
440
- state.selectedRowKeys = action.payload;
441
- },
442
- setSelectedRadioKey: (state, action) => {
443
- state.selectedRadioKey = action.payload;
444
- },
445
- setIndexRowTableModal: (state, action) => {
446
- state.indexRowTableModal = action.payload;
447
- },
448
- setTransferDetail: (state, action) => {
449
- state.transferDetail = action.payload;
450
- },
451
- setIsUpdateTableModal: (state, action) => {
452
- state.isUpdateTableModal = action.payload;
453
- },
454
- setPage: (state, action) => {
455
- state.page = action.payload;
456
- },
457
- setDomainTable: (state, action) => {
458
- state.domainTable = action.payload;
459
- }
460
- }
461
- });
462
- var {
463
- setPageLimit,
464
- setFields,
465
- setOrder,
466
- setSelectedRowKeys,
467
- setIndexRowTableModal,
468
- setIsUpdateTableModal,
469
- setPage,
470
- setSelectedRadioKey,
471
- setTransferDetail,
472
- setDomainTable
473
- } = listSlice.actions;
474
- var list_slice_default = listSlice.reducer;
475
-
476
- // src/store/reducers/login-slice/index.ts
477
- var import_toolkit7 = require("@reduxjs/toolkit");
478
- var initialState6 = {
479
- db: "",
480
- redirectTo: "/",
481
- forgotPasswordUrl: "/"
482
- };
483
- var loginSlice = (0, import_toolkit7.createSlice)({
484
- name: "login",
485
- initialState: initialState6,
486
- reducers: {
487
- setDb: (state, action) => {
488
- state.db = action.payload;
489
- },
490
- setRedirectTo: (state, action) => {
491
- state.redirectTo = action.payload;
492
- },
493
- setForgotPasswordUrl: (state, action) => {
494
- state.forgotPasswordUrl = action.payload;
495
- }
496
- }
497
- });
498
- var { setDb, setRedirectTo, setForgotPasswordUrl } = loginSlice.actions;
499
- var login_slice_default = loginSlice.reducer;
500
-
501
- // src/store/reducers/navbar-slice/index.ts
502
- var import_toolkit8 = require("@reduxjs/toolkit");
503
- var initialState7 = {
504
- menuFocus: {},
505
- menuAction: {},
506
- navbarWidth: 250,
507
- menuList: []
508
- };
509
- var navbarSlice = (0, import_toolkit8.createSlice)({
510
- name: "navbar",
511
- initialState: initialState7,
512
- reducers: {
513
- setMenuFocus: (state, action) => {
514
- state.menuFocus = action.payload;
515
- },
516
- setMenuFocusAction: (state, action) => {
517
- state.menuAction = action.payload;
518
- },
519
- setNavbarWidth: (state, action) => {
520
- state.navbarWidth = action.payload;
521
- },
522
- setMenuList: (state, action) => {
523
- state.menuList = action.payload;
524
- }
525
- }
526
- });
527
- var { setMenuFocus, setMenuFocusAction, setNavbarWidth, setMenuList } = navbarSlice.actions;
528
- var navbar_slice_default = navbarSlice.reducer;
529
-
530
- // src/store/reducers/profile-slice/index.ts
531
- var import_toolkit9 = require("@reduxjs/toolkit");
532
- var initialState8 = {
533
- profile: {}
534
- };
535
- var profileSlice = (0, import_toolkit9.createSlice)({
536
- name: "profile",
537
- initialState: initialState8,
538
- reducers: {
539
- setProfile: (state, action) => {
540
- state.profile = action.payload;
541
- }
542
- }
543
- });
544
- var { setProfile } = profileSlice.actions;
545
- var profile_slice_default = profileSlice.reducer;
546
-
547
- // src/store/reducers/search-slice/index.ts
548
- var import_toolkit10 = require("@reduxjs/toolkit");
549
- var initialState9 = {
550
- groupByDomain: null,
551
- searchBy: [],
552
- searchString: "",
553
- hoveredIndexSearchList: null,
554
- selectedTags: [],
555
- firstDomain: null,
556
- searchMap: {},
557
- filterBy: [],
558
- groupBy: []
559
- };
560
- var searchSlice = (0, import_toolkit10.createSlice)({
561
- name: "search",
562
- initialState: initialState9,
563
- reducers: {
564
- setGroupByDomain: (state, action) => {
565
- state.groupByDomain = action.payload;
566
- },
567
- setSearchBy: (state, action) => {
568
- state.searchBy = action.payload;
569
- },
570
- setSearchString: (state, action) => {
571
- state.searchString = action.payload;
572
- },
573
- setHoveredIndexSearchList: (state, action) => {
574
- state.hoveredIndexSearchList = action.payload;
575
- },
576
- setSelectedTags: (state, action) => {
577
- state.selectedTags = action.payload;
578
- },
579
- setFirstDomain: (state, action) => {
580
- state.firstDomain = action.payload;
581
- },
582
- setFilterBy: (state, action) => {
583
- state.filterBy = action.payload;
584
- },
585
- setGroupBy: (state, action) => {
586
- state.groupBy = action.payload;
587
- },
588
- setSearchMap: (state, action) => {
589
- state.searchMap = action.payload;
590
- },
591
- updateSearchMap: (state, action) => {
592
- if (!state.searchMap[action.payload.key]) {
593
- state.searchMap[action.payload.key] = [];
594
- }
595
- state.searchMap[action.payload.key].push(action.payload.value);
596
- },
597
- removeKeyFromSearchMap: (state, action) => {
598
- const { key, item } = action.payload;
599
- const values = state.searchMap[key];
600
- if (!values) return;
601
- if (item) {
602
- const filtered = values.filter((value) => value.name !== item.name);
603
- if (filtered.length > 0) {
604
- state.searchMap[key] = filtered;
605
- } else {
606
- delete state.searchMap[key];
607
- }
608
- } else {
609
- delete state.searchMap[key];
610
- }
611
- },
612
- clearSearchMap: (state) => {
613
- state.searchMap = {};
614
- }
615
- }
616
- });
617
- var {
618
- setGroupByDomain,
619
- setSelectedTags,
620
- setSearchString,
621
- setHoveredIndexSearchList,
622
- setFirstDomain,
623
- setSearchBy,
624
- setFilterBy,
625
- setSearchMap,
626
- updateSearchMap,
627
- removeKeyFromSearchMap,
628
- setGroupBy,
629
- clearSearchMap
630
- } = searchSlice.actions;
631
- var search_slice_default = searchSlice.reducer;
632
-
633
- // src/store/store.ts
634
- var rootReducer = combineReducers({
635
- env: env_slice_default,
636
- header: header_slice_default,
637
- navbar: navbar_slice_default,
638
- list: list_slice_default,
639
- search: search_slice_default,
640
- form: form_slice_default,
641
- breadcrumbs: breadcrums_slice_default,
642
- login: login_slice_default,
643
- excel: excel_slice_default,
644
- profile: profile_slice_default
645
- });
646
- var envStore = (0, import_toolkit11.configureStore)({
647
- reducer: rootReducer,
648
- middleware: (getDefaultMiddleware) => getDefaultMiddleware({
649
- serializableCheck: false
650
- })
651
- });
652
-
653
- // src/configs/axios-client.ts
654
- var import_axios = __toESM(require("axios"));
655
-
656
- // src/utils/format.ts
657
- var import_moment = __toESM(require("moment"));
658
-
659
- // src/utils/domain/py_tokenizer.ts
660
- var TokenizerError = class extends Error {
661
- };
662
- var directMap = {
663
- "\\": "\\",
664
- '"': '"',
665
- "'": "'",
666
- a: "\x07",
667
- b: "\b",
668
- f: "\f",
669
- n: "\n",
670
- r: "\r",
671
- t: " ",
672
- v: "\v"
673
- };
674
- function decodeStringLiteral(str, unicode) {
675
- const out = [];
676
- let code;
677
- for (let i = 0; i < str.length; ++i) {
678
- if (str[i] !== "\\") {
679
- out.push(str[i]);
680
- continue;
681
- }
682
- const escape = str[i + 1];
683
- if (escape in directMap) {
684
- out.push(directMap[escape]);
685
- ++i;
686
- continue;
687
- }
688
- switch (escape) {
689
- case "\n":
690
- ++i;
691
- continue;
692
- case "N":
693
- if (!unicode) {
694
- break;
695
- }
696
- throw new TokenizerError("SyntaxError: \\N{} escape not implemented");
697
- case "u":
698
- if (!unicode) {
699
- break;
700
- }
701
- const uni = str.slice(i + 2, i + 6);
702
- if (!/[0-9a-f]{4}/i.test(uni)) {
703
- throw new TokenizerError(
704
- [
705
- "SyntaxError: (unicode error) 'unicodeescape' codec",
706
- " can't decode bytes in position ",
707
- i,
708
- "-",
709
- i + 4,
710
- ": truncated \\uXXXX escape"
711
- ].join("")
712
- );
713
- }
714
- code = parseInt(uni, 16);
715
- out.push(String.fromCharCode(code));
716
- i += 5;
717
- continue;
718
- case "U":
719
- if (!unicode) {
720
- break;
721
- }
722
- throw new TokenizerError("SyntaxError: \\U escape not implemented");
723
- case "x":
724
- const hex = str.slice(i + 2, i + 4);
725
- if (!/[0-9a-f]{2}/i.test(hex)) {
726
- if (!unicode) {
727
- throw new TokenizerError("ValueError: invalid \\x escape");
728
- }
729
- throw new TokenizerError(
730
- [
731
- "SyntaxError: (unicode error) 'unicodeescape'",
732
- " codec can't decode bytes in position ",
733
- i,
734
- "-",
735
- i + 2,
736
- ": truncated \\xXX escape"
737
- ].join("")
738
- );
739
- }
740
- code = parseInt(hex, 16);
741
- out.push(String.fromCharCode(code));
742
- i += 3;
743
- continue;
744
- default:
745
- if (!/[0-8]/.test(escape)) {
746
- break;
747
- }
748
- const r = /[0-8]{1,3}/g;
749
- r.lastIndex = i + 1;
750
- const m = r.exec(str);
751
- if (!m) break;
752
- const oct = m[0];
753
- code = parseInt(oct, 8);
754
- out.push(String.fromCharCode(code));
755
- i += oct.length;
756
- continue;
757
- }
758
- out.push("\\");
759
- }
760
- return out.join("");
761
- }
762
- var constants = /* @__PURE__ */ new Set(["None", "False", "True"]);
763
- var comparators = [
764
- "in",
765
- "not",
766
- "not in",
767
- "is",
768
- "is not",
769
- "<",
770
- "<=",
771
- ">",
772
- ">=",
773
- "<>",
774
- "!=",
775
- "=="
776
- ];
777
- var binaryOperators = [
778
- "or",
779
- "and",
780
- "|",
781
- "^",
782
- "&",
783
- "<<",
784
- ">>",
785
- "+",
786
- "-",
787
- "*",
788
- "/",
789
- "//",
790
- "%",
791
- "~",
792
- "**",
793
- "."
794
- ];
795
- var unaryOperators = ["-"];
796
- var symbols = /* @__PURE__ */ new Set([
797
- ...["(", ")", "[", "]", "{", "}", ":", ","],
798
- ...["if", "else", "lambda", "="],
799
- ...comparators,
800
- ...binaryOperators,
801
- ...unaryOperators
802
- ]);
803
- function group(...args) {
804
- return "(" + args.join("|") + ")";
805
- }
806
- var Name = "[a-zA-Z_]\\w*";
807
- var Whitespace = "[ \\f\\t]*";
808
- var DecNumber = "\\d+(L|l)?";
809
- var IntNumber = DecNumber;
810
- var Exponent = "[eE][+-]?\\d+";
811
- var PointFloat = group(`\\d+\\.\\d*(${Exponent})?`, `\\.\\d+(${Exponent})?`);
812
- var FloatNumber = group(PointFloat, `\\d+${Exponent}`);
813
- var Number2 = group(FloatNumber, IntNumber);
814
- var Operator = group(
815
- "\\*\\*=?",
816
- ">>=?",
817
- "<<=?",
818
- "<>",
819
- "!=",
820
- "//=?",
821
- "[+\\-*/%&|^=<>]=?",
822
- "~"
823
- );
824
- var Bracket = "[\\[\\]\\(\\)\\{\\}]";
825
- var Special = "[:;.,`@]";
826
- var Funny = group(Operator, Bracket, Special);
827
- var ContStr = group(
828
- "([uU])?'([^\\n'\\\\]*(?:\\\\.[^\\n'\\\\]*)*)'",
829
- '([uU])?"([^\\n"\\\\]*(?:\\\\.[^\\n"\\\\]*)*)"'
830
- );
831
- var PseudoToken = Whitespace + group(Number2, Funny, ContStr, Name);
832
- var NumberPattern = new RegExp("^" + Number2 + "$");
833
- var StringPattern = new RegExp("^" + ContStr + "$");
834
- var NamePattern = new RegExp("^" + Name + "$");
835
- var strip = new RegExp("^" + Whitespace);
836
- function tokenize(str) {
837
- const tokens = [];
838
- const max = str.length;
839
- let start = 0;
840
- let end = 0;
841
- const pseudoprog = new RegExp(PseudoToken, "g");
842
- while (pseudoprog.lastIndex < max) {
843
- const pseudomatch = pseudoprog.exec(str);
844
- if (!pseudomatch) {
845
- if (/^\s+$/.test(str.slice(end))) {
846
- break;
847
- }
848
- throw new TokenizerError(
849
- "Failed to tokenize <<" + str + ">> at index " + (end || 0) + "; parsed so far: " + tokens
850
- );
851
- }
852
- if (pseudomatch.index > end) {
853
- if (str.slice(end, pseudomatch.index).trim()) {
854
- throw new TokenizerError("Invalid expression");
855
- }
856
- }
857
- start = pseudomatch.index;
858
- end = pseudoprog.lastIndex;
859
- let token = str.slice(start, end).replace(strip, "");
860
- if (NumberPattern.test(token)) {
861
- tokens.push({
862
- type: 0,
863
- value: parseFloat(token)
864
- });
865
- } else if (StringPattern.test(token)) {
866
- const m = StringPattern.exec(token);
867
- if (!m) throw new TokenizerError("Invalid string match");
868
- tokens.push({
869
- type: 1,
870
- value: decodeStringLiteral(
871
- m[3] !== void 0 ? m[3] : m[5],
872
- !!(m[2] || m[4])
873
- )
874
- });
875
- } else if (symbols.has(token)) {
876
- if (token === "in" && tokens.length > 0 && tokens[tokens.length - 1].value === "not") {
877
- token = "not in";
878
- tokens.pop();
879
- } else if (token === "not" && tokens.length > 0 && tokens[tokens.length - 1].value === "is") {
880
- token = "is not";
881
- tokens.pop();
882
- }
883
- tokens.push({
884
- type: 2,
885
- value: token
886
- });
887
- } else if (constants.has(token)) {
888
- tokens.push({
889
- type: 4,
890
- value: token
891
- });
892
- } else if (NamePattern.test(token)) {
893
- tokens.push({
894
- type: 3,
895
- value: token
896
- });
897
- } else {
898
- throw new TokenizerError("Invalid expression");
899
- }
900
- }
901
- return tokens;
902
- }
903
-
904
- // src/utils/domain/py_parser.ts
905
- var ParserError = class extends Error {
293
+ // src/utils/domain/py_parser.ts
294
+ var ParserError = class extends Error {
906
295
  };
907
296
  var chainedOperators = new Set(comparators);
908
297
  var infixOperators = /* @__PURE__ */ new Set([...binaryOperators, ...comparators]);
@@ -1565,1533 +954,2131 @@ var PyTime = class _PyTime extends PyDate {
1565
954
  this.minute = minute;
1566
955
  this.second = second;
1567
956
  }
1568
- static create(...args) {
1569
- const namedArgs = parseArgs(args, ["hour", "minute", "second"]);
1570
- const hour = namedArgs.hour || 0;
1571
- const minute = namedArgs.minute || 0;
1572
- const second = namedArgs.second || 0;
1573
- return new _PyTime(hour, minute, second);
957
+ static create(...args) {
958
+ const namedArgs = parseArgs(args, ["hour", "minute", "second"]);
959
+ const hour = namedArgs.hour || 0;
960
+ const minute = namedArgs.minute || 0;
961
+ const second = namedArgs.second || 0;
962
+ return new _PyTime(hour, minute, second);
963
+ }
964
+ strftime(format) {
965
+ return format.replace(/%([A-Za-z])/g, (m, c) => {
966
+ switch (c) {
967
+ case "Y":
968
+ return fmt4(this.year);
969
+ case "m":
970
+ return fmt2(this.month);
971
+ case "d":
972
+ return fmt2(this.day);
973
+ case "H":
974
+ return fmt2(this.hour);
975
+ case "M":
976
+ return fmt2(this.minute);
977
+ case "S":
978
+ return fmt2(this.second);
979
+ default:
980
+ throw new ValueError(`No known conversion for ${m}`);
981
+ }
982
+ });
983
+ }
984
+ toJSON() {
985
+ return this.strftime("%H:%M:%S");
986
+ }
987
+ };
988
+ var DAYS_IN_YEAR = [
989
+ 31,
990
+ 59,
991
+ 90,
992
+ 120,
993
+ 151,
994
+ 181,
995
+ 212,
996
+ 243,
997
+ 273,
998
+ 304,
999
+ 334,
1000
+ 366
1001
+ ];
1002
+ var TIME_PERIODS = ["hour", "minute", "second"];
1003
+ var PERIODS = ["year", "month", "day", ...TIME_PERIODS];
1004
+ var RELATIVE_KEYS = "years months weeks days hours minutes seconds microseconds leapdays".split(
1005
+ " "
1006
+ );
1007
+ var ABSOLUTE_KEYS = "year month day hour minute second microsecond weekday nlyearday yearday".split(
1008
+ " "
1009
+ );
1010
+ var argsSpec = ["dt1", "dt2"];
1011
+ var PyRelativeDelta = class _PyRelativeDelta {
1012
+ static create(...args) {
1013
+ const params = parseArgs(args, argsSpec);
1014
+ if ("dt1" in params) {
1015
+ throw new Error("relativedelta(dt1, dt2) is not supported for now");
1016
+ }
1017
+ for (const period of PERIODS) {
1018
+ if (period in params) {
1019
+ const val = params[period];
1020
+ assert(val >= 0, `${period} ${val} is out of range`);
1021
+ }
1022
+ }
1023
+ for (const key of RELATIVE_KEYS) {
1024
+ params[key] = params[key] || 0;
1025
+ }
1026
+ for (const key of ABSOLUTE_KEYS) {
1027
+ params[key] = key in params ? params[key] : null;
1028
+ }
1029
+ params.days += 7 * params.weeks;
1030
+ let yearDay = 0;
1031
+ if (params.nlyearday) {
1032
+ yearDay = params.nlyearday;
1033
+ } else if (params.yearday) {
1034
+ yearDay = params.yearday;
1035
+ if (yearDay > 59) {
1036
+ params.leapDays = -1;
1037
+ }
1038
+ }
1039
+ if (yearDay) {
1040
+ for (let monthIndex = 0; monthIndex < DAYS_IN_YEAR.length; monthIndex++) {
1041
+ if (yearDay <= DAYS_IN_YEAR[monthIndex]) {
1042
+ params.month = monthIndex + 1;
1043
+ if (monthIndex === 0) {
1044
+ params.day = yearDay;
1045
+ } else {
1046
+ params.day = yearDay - DAYS_IN_YEAR[monthIndex - 1];
1047
+ }
1048
+ break;
1049
+ }
1050
+ }
1051
+ }
1052
+ return new _PyRelativeDelta(params);
1053
+ }
1054
+ static add(date, delta) {
1055
+ if (!(date instanceof PyDate || date instanceof PyDateTime)) {
1056
+ throw new NotSupportedError();
1057
+ }
1058
+ const s = tmxxx(
1059
+ (delta.year || date.year) + delta.years,
1060
+ (delta.month || date.month) + delta.months,
1061
+ delta.day || date.day,
1062
+ delta.hour || (date instanceof PyDateTime ? date.hour : 0),
1063
+ delta.minute || (date instanceof PyDateTime ? date.minute : 0),
1064
+ delta.second || (date instanceof PyDateTime ? date.second : 0),
1065
+ delta.microseconds || (date instanceof PyDateTime ? date.microsecond : 0)
1066
+ );
1067
+ const newDateTime = new PyDateTime(
1068
+ s.year,
1069
+ s.month,
1070
+ s.day,
1071
+ s.hour,
1072
+ s.minute,
1073
+ s.second,
1074
+ s.microsecond
1075
+ );
1076
+ let leapDays = 0;
1077
+ if (delta.leapDays && newDateTime.month > 2 && isLeap(newDateTime.year)) {
1078
+ leapDays = delta.leapDays;
1079
+ }
1080
+ const temp = newDateTime.add(
1081
+ PyTimeDelta.create({
1082
+ days: delta.days + leapDays,
1083
+ hours: delta.hours,
1084
+ minutes: delta.minutes,
1085
+ seconds: delta.seconds,
1086
+ microseconds: delta.microseconds
1087
+ })
1088
+ );
1089
+ const hasTime = Boolean(
1090
+ temp.hour || temp.minute || temp.second || temp.microsecond
1091
+ );
1092
+ const returnDate = !hasTime && date instanceof PyDate ? new PyDate(temp.year, temp.month, temp.day) : temp;
1093
+ if (delta.weekday !== null) {
1094
+ const wantedDow = delta.weekday + 1;
1095
+ const _date = new Date(
1096
+ returnDate.year,
1097
+ returnDate.month - 1,
1098
+ returnDate.day
1099
+ );
1100
+ const days = (7 - _date.getDay() + wantedDow) % 7;
1101
+ return returnDate.add(new PyTimeDelta(days, 0, 0));
1102
+ }
1103
+ return returnDate;
1104
+ }
1105
+ static substract(date, delta) {
1106
+ return _PyRelativeDelta.add(date, delta.negate());
1107
+ }
1108
+ constructor(params = {}, sign = 1) {
1109
+ this.years = sign * params.years;
1110
+ this.months = sign * params.months;
1111
+ this.days = sign * params.days;
1112
+ this.hours = sign * params.hours;
1113
+ this.minutes = sign * params.minutes;
1114
+ this.seconds = sign * params.seconds;
1115
+ this.microseconds = sign * params.microseconds;
1116
+ this.leapDays = params.leapDays;
1117
+ this.year = params.year;
1118
+ this.month = params.month;
1119
+ this.day = params.day;
1120
+ this.hour = params.hour;
1121
+ this.minute = params.minute;
1122
+ this.second = params.second;
1123
+ this.microsecond = params.microsecond;
1124
+ this.weekday = params.weekday;
1125
+ }
1126
+ negate() {
1127
+ return new _PyRelativeDelta(this, -1);
1128
+ }
1129
+ isEqual() {
1130
+ throw new NotSupportedError();
1131
+ }
1132
+ };
1133
+ var TIME_DELTA_KEYS = "weeks days hours minutes seconds milliseconds microseconds".split(" ");
1134
+ function modf(x) {
1135
+ const mod = x % 1;
1136
+ return [mod < 0 ? mod + 1 : mod, Math.floor(x)];
1137
+ }
1138
+ var PyTimeDelta = class _PyTimeDelta {
1139
+ constructor(days, seconds, microseconds) {
1140
+ this.days = days;
1141
+ this.seconds = seconds;
1142
+ this.microseconds = microseconds;
1143
+ }
1144
+ static create(...args) {
1145
+ const namedArgs = parseArgs(args, ["days", "seconds", "microseconds"]);
1146
+ for (const key of TIME_DELTA_KEYS) {
1147
+ namedArgs[key] = namedArgs[key] || 0;
1148
+ }
1149
+ let d = 0;
1150
+ let s = 0;
1151
+ let us = 0;
1152
+ const days = namedArgs.days + namedArgs.weeks * 7;
1153
+ let seconds = namedArgs.seconds + 60 * namedArgs.minutes + 3600 * namedArgs.hours;
1154
+ let microseconds = namedArgs.microseconds + 1e3 * namedArgs.milliseconds;
1155
+ const [dFrac, dInt] = modf(days);
1156
+ d = dInt;
1157
+ let daysecondsfrac = 0;
1158
+ if (dFrac) {
1159
+ const [dsFrac, dsInt] = modf(dFrac * 24 * 3600);
1160
+ s = dsInt;
1161
+ daysecondsfrac = dsFrac;
1162
+ }
1163
+ const [sFrac, sInt] = modf(seconds);
1164
+ seconds = sInt;
1165
+ const secondsfrac = sFrac + daysecondsfrac;
1166
+ divmod(seconds, 24 * 3600, (days2, seconds2) => {
1167
+ d += days2;
1168
+ s += seconds2;
1169
+ });
1170
+ microseconds += secondsfrac * 1e6;
1171
+ divmod(microseconds, 1e6, (seconds2, microseconds2) => {
1172
+ divmod(seconds2, 24 * 3600, (days2, seconds3) => {
1173
+ d += days2;
1174
+ s += seconds3;
1175
+ us += Math.round(microseconds2);
1176
+ });
1177
+ });
1178
+ return new _PyTimeDelta(d, s, us);
1179
+ }
1180
+ add(other) {
1181
+ return _PyTimeDelta.create({
1182
+ days: this.days + other.days,
1183
+ seconds: this.seconds + other.seconds,
1184
+ microseconds: this.microseconds + other.microseconds
1185
+ });
1186
+ }
1187
+ divide(n) {
1188
+ const us = (this.days * 24 * 3600 + this.seconds) * 1e6 + this.microseconds;
1189
+ return _PyTimeDelta.create({ microseconds: Math.floor(us / n) });
1190
+ }
1191
+ isEqual(other) {
1192
+ if (!(other instanceof _PyTimeDelta)) {
1193
+ return false;
1194
+ }
1195
+ return this.days === other.days && this.seconds === other.seconds && this.microseconds === other.microseconds;
1196
+ }
1197
+ isTrue() {
1198
+ return this.days !== 0 || this.seconds !== 0 || this.microseconds !== 0;
1199
+ }
1200
+ multiply(n) {
1201
+ return _PyTimeDelta.create({
1202
+ days: n * this.days,
1203
+ seconds: n * this.seconds,
1204
+ microseconds: n * this.microseconds
1205
+ });
1206
+ }
1207
+ negate() {
1208
+ return _PyTimeDelta.create({
1209
+ days: -this.days,
1210
+ seconds: -this.seconds,
1211
+ microseconds: -this.microseconds
1212
+ });
1574
1213
  }
1575
- strftime(format) {
1576
- return format.replace(/%([A-Za-z])/g, (m, c) => {
1577
- switch (c) {
1578
- case "Y":
1579
- return fmt4(this.year);
1580
- case "m":
1581
- return fmt2(this.month);
1582
- case "d":
1583
- return fmt2(this.day);
1584
- case "H":
1585
- return fmt2(this.hour);
1586
- case "M":
1587
- return fmt2(this.minute);
1588
- case "S":
1589
- return fmt2(this.second);
1590
- default:
1591
- throw new ValueError(`No known conversion for ${m}`);
1592
- }
1214
+ substract(other) {
1215
+ return _PyTimeDelta.create({
1216
+ days: this.days - other.days,
1217
+ seconds: this.seconds - other.seconds,
1218
+ microseconds: this.microseconds - other.microseconds
1593
1219
  });
1594
1220
  }
1595
- toJSON() {
1596
- return this.strftime("%H:%M:%S");
1221
+ total_seconds() {
1222
+ return this.days * 86400 + this.seconds + this.microseconds / 1e6;
1597
1223
  }
1598
1224
  };
1599
- var DAYS_IN_YEAR = [
1600
- 31,
1601
- 59,
1602
- 90,
1603
- 120,
1604
- 151,
1605
- 181,
1606
- 212,
1607
- 243,
1608
- 273,
1609
- 304,
1610
- 334,
1611
- 366
1612
- ];
1613
- var TIME_PERIODS = ["hour", "minute", "second"];
1614
- var PERIODS = ["year", "month", "day", ...TIME_PERIODS];
1615
- var RELATIVE_KEYS = "years months weeks days hours minutes seconds microseconds leapdays".split(
1616
- " "
1617
- );
1618
- var ABSOLUTE_KEYS = "year month day hour minute second microsecond weekday nlyearday yearday".split(
1619
- " "
1620
- );
1621
- var argsSpec = ["dt1", "dt2"];
1622
- var PyRelativeDelta = class _PyRelativeDelta {
1623
- static create(...args) {
1624
- const params = parseArgs(args, argsSpec);
1625
- if ("dt1" in params) {
1626
- throw new Error("relativedelta(dt1, dt2) is not supported for now");
1627
- }
1628
- for (const period of PERIODS) {
1629
- if (period in params) {
1630
- const val = params[period];
1631
- assert(val >= 0, `${period} ${val} is out of range`);
1632
- }
1225
+
1226
+ // src/utils/domain/py_builtin.ts
1227
+ var EvaluationError = class extends Error {
1228
+ constructor(message) {
1229
+ super(message);
1230
+ this.name = "EvaluationError";
1231
+ }
1232
+ };
1233
+ function execOnIterable(iterable, func) {
1234
+ if (iterable === null) {
1235
+ throw new EvaluationError("value not iterable");
1236
+ }
1237
+ if (typeof iterable === "object" && !Array.isArray(iterable) && !(iterable instanceof Set)) {
1238
+ iterable = Object.keys(iterable);
1239
+ }
1240
+ if (typeof (iterable == null ? void 0 : iterable[Symbol.iterator]) !== "function") {
1241
+ throw new EvaluationError("value not iterable");
1242
+ }
1243
+ return func(iterable);
1244
+ }
1245
+ var BUILTINS = {
1246
+ /**
1247
+ * @param {any} value
1248
+ * @returns {boolean}
1249
+ */
1250
+ bool(value) {
1251
+ switch (typeof value) {
1252
+ case "number":
1253
+ return value !== 0;
1254
+ case "string":
1255
+ return value !== "";
1256
+ case "boolean":
1257
+ return value;
1258
+ case "object":
1259
+ if (value === null || value === void 0) {
1260
+ return false;
1261
+ }
1262
+ if ("isTrue" in value && typeof value.isTrue === "function") {
1263
+ return value.isTrue();
1264
+ }
1265
+ if (value instanceof Array) {
1266
+ return !!value.length;
1267
+ }
1268
+ if (value instanceof Set) {
1269
+ return !!value.size;
1270
+ }
1271
+ return Object.keys(value).length !== 0;
1272
+ default:
1273
+ return true;
1633
1274
  }
1634
- for (const key of RELATIVE_KEYS) {
1635
- params[key] = params[key] || 0;
1275
+ },
1276
+ set(iterable) {
1277
+ if (arguments.length > 2) {
1278
+ throw new EvaluationError(
1279
+ `set expected at most 1 argument, got (${arguments.length - 1})`
1280
+ );
1636
1281
  }
1637
- for (const key of ABSOLUTE_KEYS) {
1638
- params[key] = key in params ? params[key] : null;
1282
+ return execOnIterable(
1283
+ iterable,
1284
+ (iterable2) => new Set(iterable2)
1285
+ );
1286
+ },
1287
+ time: {
1288
+ strftime(format) {
1289
+ return PyDateTime.now().strftime(format);
1639
1290
  }
1640
- params.days += 7 * params.weeks;
1641
- let yearDay = 0;
1642
- if (params.nlyearday) {
1643
- yearDay = params.nlyearday;
1644
- } else if (params.yearday) {
1645
- yearDay = params.yearday;
1646
- if (yearDay > 59) {
1647
- params.leapDays = -1;
1291
+ },
1292
+ context_today() {
1293
+ return PyDate.today();
1294
+ },
1295
+ get current_date() {
1296
+ return this.today;
1297
+ },
1298
+ get today() {
1299
+ return PyDate.today().strftime("%Y-%m-%d");
1300
+ },
1301
+ get now() {
1302
+ return PyDateTime.now().strftime("%Y-%m-%d %H:%M:%S");
1303
+ },
1304
+ datetime: {
1305
+ time: PyTime,
1306
+ timedelta: PyTimeDelta,
1307
+ datetime: PyDateTime,
1308
+ date: PyDate
1309
+ },
1310
+ relativedelta: PyRelativeDelta,
1311
+ true: true,
1312
+ false: false
1313
+ };
1314
+
1315
+ // src/utils/domain/py_utils.ts
1316
+ function toPyValue(value) {
1317
+ switch (typeof value) {
1318
+ case "string":
1319
+ return { type: 1, value };
1320
+ case "number":
1321
+ return { type: 0, value };
1322
+ case "boolean":
1323
+ return { type: 2, value };
1324
+ case "object":
1325
+ if (Array.isArray(value)) {
1326
+ return { type: 4, value: value.map(toPyValue) };
1327
+ } else if (value === null) {
1328
+ return {
1329
+ type: 3
1330
+ /* None */
1331
+ };
1332
+ } else if (value instanceof Date) {
1333
+ return {
1334
+ type: 1,
1335
+ value: String(PyDateTime.convertDate(value))
1336
+ };
1337
+ } else if (value instanceof PyDate || value instanceof PyDateTime) {
1338
+ return { type: 1, value };
1339
+ } else {
1340
+ const content = {};
1341
+ for (const key in value) {
1342
+ content[key] = toPyValue(value[key]);
1343
+ }
1344
+ return { type: 11, value: content };
1345
+ }
1346
+ default:
1347
+ throw new Error("Invalid type");
1348
+ }
1349
+ }
1350
+ function formatAST(ast, lbp = 0) {
1351
+ switch (ast.type) {
1352
+ case 3:
1353
+ return "None";
1354
+ case 1:
1355
+ return JSON.stringify(ast.value);
1356
+ case 0:
1357
+ return String(ast.value);
1358
+ case 2:
1359
+ return ast.value ? "True" : "False";
1360
+ case 4:
1361
+ return `[${ast.value.map(formatAST).join(", ")}]`;
1362
+ case 6:
1363
+ if (ast.op === "not") {
1364
+ return `not ${formatAST(ast.right, 50)}`;
1365
+ }
1366
+ return `${ast.op}${formatAST(ast.right, 130)}`;
1367
+ case 7:
1368
+ const abp = bp(ast.op);
1369
+ const binaryStr = `${formatAST(ast.left, abp)} ${ast.op} ${formatAST(ast.right, abp)}`;
1370
+ return abp < lbp ? `(${binaryStr})` : binaryStr;
1371
+ case 11:
1372
+ const pairs = [];
1373
+ for (const k in ast.value) {
1374
+ pairs.push(`"${k}": ${formatAST(ast.value[k])}`);
1375
+ }
1376
+ return `{${pairs.join(", ")}}`;
1377
+ case 10:
1378
+ return `(${ast.value.map(formatAST).join(", ")})`;
1379
+ case 5:
1380
+ return ast.value;
1381
+ case 12:
1382
+ return `${formatAST(ast.target)}[${formatAST(ast.key)}]`;
1383
+ case 13:
1384
+ const { ifTrue, condition, ifFalse } = ast;
1385
+ return `${formatAST(ifTrue)} if ${formatAST(condition)} else ${formatAST(ifFalse)}`;
1386
+ case 14:
1387
+ const boolAbp = bp(ast.op);
1388
+ const boolStr = `${formatAST(ast.left, boolAbp)} ${ast.op} ${formatAST(ast.right, boolAbp)}`;
1389
+ return boolAbp < lbp ? `(${boolStr})` : boolStr;
1390
+ case 15:
1391
+ return `${formatAST(ast.obj, 150)}.${ast.key}`;
1392
+ case 8:
1393
+ const args = ast.args.map(formatAST);
1394
+ const kwargs = [];
1395
+ for (const kwarg in ast.kwargs) {
1396
+ kwargs.push(`${kwarg} = ${formatAST(ast.kwargs[kwarg])}`);
1648
1397
  }
1398
+ const argStr = args.concat(kwargs).join(", ");
1399
+ return `${formatAST(ast.fn)}(${argStr})`;
1400
+ default:
1401
+ throw new Error("invalid expression: " + JSON.stringify(ast));
1402
+ }
1403
+ }
1404
+ var PY_DICT = /* @__PURE__ */ Object.create(null);
1405
+ function toPyDict(obj) {
1406
+ return new Proxy(obj, {
1407
+ getPrototypeOf() {
1408
+ return PY_DICT;
1649
1409
  }
1650
- if (yearDay) {
1651
- for (let monthIndex = 0; monthIndex < DAYS_IN_YEAR.length; monthIndex++) {
1652
- if (yearDay <= DAYS_IN_YEAR[monthIndex]) {
1653
- params.month = monthIndex + 1;
1654
- if (monthIndex === 0) {
1655
- params.day = yearDay;
1656
- } else {
1657
- params.day = yearDay - DAYS_IN_YEAR[monthIndex - 1];
1658
- }
1659
- break;
1660
- }
1410
+ });
1411
+ }
1412
+
1413
+ // src/utils/domain/py_interpreter.ts
1414
+ var isTrue = BUILTINS.bool;
1415
+ function applyUnaryOp(ast, context) {
1416
+ const value = evaluate(ast.right, context);
1417
+ switch (ast.op) {
1418
+ case "-":
1419
+ if (value instanceof Object && "negate" in value) {
1420
+ return value.negate();
1661
1421
  }
1662
- }
1663
- return new _PyRelativeDelta(params);
1422
+ return -value;
1423
+ case "+":
1424
+ return value;
1425
+ case "not":
1426
+ return !isTrue(value);
1427
+ default:
1428
+ throw new EvaluationError(`Unknown unary operator: ${ast.op}`);
1664
1429
  }
1665
- static add(date, delta) {
1666
- if (!(date instanceof PyDate || date instanceof PyDateTime)) {
1667
- throw new NotSupportedError();
1668
- }
1669
- const s = tmxxx(
1670
- (delta.year || date.year) + delta.years,
1671
- (delta.month || date.month) + delta.months,
1672
- delta.day || date.day,
1673
- delta.hour || (date instanceof PyDateTime ? date.hour : 0),
1674
- delta.minute || (date instanceof PyDateTime ? date.minute : 0),
1675
- delta.second || (date instanceof PyDateTime ? date.second : 0),
1676
- delta.microseconds || (date instanceof PyDateTime ? date.microsecond : 0)
1677
- );
1678
- const newDateTime = new PyDateTime(
1679
- s.year,
1680
- s.month,
1681
- s.day,
1682
- s.hour,
1683
- s.minute,
1684
- s.second,
1685
- s.microsecond
1686
- );
1687
- let leapDays = 0;
1688
- if (delta.leapDays && newDateTime.month > 2 && isLeap(newDateTime.year)) {
1689
- leapDays = delta.leapDays;
1690
- }
1691
- const temp = newDateTime.add(
1692
- PyTimeDelta.create({
1693
- days: delta.days + leapDays,
1694
- hours: delta.hours,
1695
- minutes: delta.minutes,
1696
- seconds: delta.seconds,
1697
- microseconds: delta.microseconds
1698
- })
1699
- );
1700
- const hasTime = Boolean(
1701
- temp.hour || temp.minute || temp.second || temp.microsecond
1702
- );
1703
- const returnDate = !hasTime && date instanceof PyDate ? new PyDate(temp.year, temp.month, temp.day) : temp;
1704
- if (delta.weekday !== null) {
1705
- const wantedDow = delta.weekday + 1;
1706
- const _date = new Date(
1707
- returnDate.year,
1708
- returnDate.month - 1,
1709
- returnDate.day
1710
- );
1711
- const days = (7 - _date.getDay() + wantedDow) % 7;
1712
- return returnDate.add(new PyTimeDelta(days, 0, 0));
1713
- }
1714
- return returnDate;
1430
+ }
1431
+ function pytypeIndex(val) {
1432
+ switch (typeof val) {
1433
+ case "object":
1434
+ return val === null ? 1 : Array.isArray(val) ? 5 : 3;
1435
+ case "number":
1436
+ return 2;
1437
+ case "string":
1438
+ return 4;
1439
+ default:
1440
+ throw new EvaluationError(`Unknown type: ${typeof val}`);
1715
1441
  }
1716
- static substract(date, delta) {
1717
- return _PyRelativeDelta.add(date, delta.negate());
1442
+ }
1443
+ function isLess(left, right) {
1444
+ if (typeof left === "number" && typeof right === "number") {
1445
+ return left < right;
1718
1446
  }
1719
- constructor(params = {}, sign = 1) {
1720
- this.years = sign * params.years;
1721
- this.months = sign * params.months;
1722
- this.days = sign * params.days;
1723
- this.hours = sign * params.hours;
1724
- this.minutes = sign * params.minutes;
1725
- this.seconds = sign * params.seconds;
1726
- this.microseconds = sign * params.microseconds;
1727
- this.leapDays = params.leapDays;
1728
- this.year = params.year;
1729
- this.month = params.month;
1730
- this.day = params.day;
1731
- this.hour = params.hour;
1732
- this.minute = params.minute;
1733
- this.second = params.second;
1734
- this.microsecond = params.microsecond;
1735
- this.weekday = params.weekday;
1447
+ if (typeof left === "boolean") {
1448
+ left = left ? 1 : 0;
1736
1449
  }
1737
- years;
1738
- months;
1739
- days;
1740
- hours;
1741
- minutes;
1742
- seconds;
1743
- microseconds;
1744
- leapDays;
1745
- year;
1746
- month;
1747
- day;
1748
- hour;
1749
- minute;
1750
- second;
1751
- microsecond;
1752
- weekday;
1753
- negate() {
1754
- return new _PyRelativeDelta(this, -1);
1450
+ if (typeof right === "boolean") {
1451
+ right = right ? 1 : 0;
1755
1452
  }
1756
- isEqual() {
1757
- throw new NotSupportedError();
1453
+ const leftIndex = pytypeIndex(left);
1454
+ const rightIndex = pytypeIndex(right);
1455
+ if (leftIndex === rightIndex) {
1456
+ return left < right;
1758
1457
  }
1759
- };
1760
- var TIME_DELTA_KEYS = "weeks days hours minutes seconds milliseconds microseconds".split(" ");
1761
- function modf(x) {
1762
- const mod = x % 1;
1763
- return [mod < 0 ? mod + 1 : mod, Math.floor(x)];
1458
+ return leftIndex < rightIndex;
1764
1459
  }
1765
- var PyTimeDelta = class _PyTimeDelta {
1766
- constructor(days, seconds, microseconds) {
1767
- this.days = days;
1768
- this.seconds = seconds;
1769
- this.microseconds = microseconds;
1770
- }
1771
- static create(...args) {
1772
- const namedArgs = parseArgs(args, ["days", "seconds", "microseconds"]);
1773
- for (const key of TIME_DELTA_KEYS) {
1774
- namedArgs[key] = namedArgs[key] || 0;
1460
+ function isEqual(left, right) {
1461
+ if (typeof left !== typeof right) {
1462
+ if (typeof left === "boolean" && typeof right === "number") {
1463
+ return right === (left ? 1 : 0);
1775
1464
  }
1776
- let d = 0;
1777
- let s = 0;
1778
- let us = 0;
1779
- const days = namedArgs.days + namedArgs.weeks * 7;
1780
- let seconds = namedArgs.seconds + 60 * namedArgs.minutes + 3600 * namedArgs.hours;
1781
- let microseconds = namedArgs.microseconds + 1e3 * namedArgs.milliseconds;
1782
- const [dFrac, dInt] = modf(days);
1783
- d = dInt;
1784
- let daysecondsfrac = 0;
1785
- if (dFrac) {
1786
- const [dsFrac, dsInt] = modf(dFrac * 24 * 3600);
1787
- s = dsInt;
1788
- daysecondsfrac = dsFrac;
1465
+ if (typeof left === "number" && typeof right === "boolean") {
1466
+ return left === (right ? 1 : 0);
1789
1467
  }
1790
- const [sFrac, sInt] = modf(seconds);
1791
- seconds = sInt;
1792
- const secondsfrac = sFrac + daysecondsfrac;
1793
- divmod(seconds, 24 * 3600, (days2, seconds2) => {
1794
- d += days2;
1795
- s += seconds2;
1796
- });
1797
- microseconds += secondsfrac * 1e6;
1798
- divmod(microseconds, 1e6, (seconds2, microseconds2) => {
1799
- divmod(seconds2, 24 * 3600, (days2, seconds3) => {
1800
- d += days2;
1801
- s += seconds3;
1802
- us += Math.round(microseconds2);
1803
- });
1804
- });
1805
- return new _PyTimeDelta(d, s, us);
1468
+ return false;
1806
1469
  }
1807
- add(other) {
1808
- return _PyTimeDelta.create({
1809
- days: this.days + other.days,
1810
- seconds: this.seconds + other.seconds,
1811
- microseconds: this.microseconds + other.microseconds
1812
- });
1470
+ if (left instanceof Object && "isEqual" in left) {
1471
+ return left.isEqual(right);
1813
1472
  }
1814
- divide(n) {
1815
- const us = (this.days * 24 * 3600 + this.seconds) * 1e6 + this.microseconds;
1816
- return _PyTimeDelta.create({ microseconds: Math.floor(us / n) });
1473
+ return left === right;
1474
+ }
1475
+ function isIn(left, right) {
1476
+ if (Array.isArray(right)) {
1477
+ return right.includes(left);
1817
1478
  }
1818
- isEqual(other) {
1819
- if (!(other instanceof _PyTimeDelta)) {
1820
- return false;
1479
+ if (typeof right === "string" && typeof left === "string") {
1480
+ return right.includes(left);
1481
+ }
1482
+ if (typeof right === "object") {
1483
+ return left in right;
1484
+ }
1485
+ return false;
1486
+ }
1487
+ function applyBinaryOp(ast, context) {
1488
+ const left = evaluate(ast.left, context);
1489
+ const right = evaluate(ast.right, context);
1490
+ switch (ast.op) {
1491
+ case "+": {
1492
+ const relativeDeltaOnLeft = left instanceof PyRelativeDelta;
1493
+ const relativeDeltaOnRight = right instanceof PyRelativeDelta;
1494
+ if (relativeDeltaOnLeft || relativeDeltaOnRight) {
1495
+ const date = relativeDeltaOnLeft ? right : left;
1496
+ const delta = relativeDeltaOnLeft ? left : right;
1497
+ return PyRelativeDelta.add(date, delta);
1498
+ }
1499
+ const timeDeltaOnLeft = left instanceof PyTimeDelta;
1500
+ const timeDeltaOnRight = right instanceof PyTimeDelta;
1501
+ if (timeDeltaOnLeft && timeDeltaOnRight) {
1502
+ return left.add(right);
1503
+ }
1504
+ if (timeDeltaOnLeft) {
1505
+ if (right instanceof PyDate || right instanceof PyDateTime) {
1506
+ return right.add(left);
1507
+ } else {
1508
+ throw new NotSupportedError();
1509
+ }
1510
+ }
1511
+ if (timeDeltaOnRight) {
1512
+ if (left instanceof PyDate || left instanceof PyDateTime) {
1513
+ return left.add(right);
1514
+ } else {
1515
+ throw new NotSupportedError();
1516
+ }
1517
+ }
1518
+ if (left instanceof Array && right instanceof Array) {
1519
+ return [...left, ...right];
1520
+ }
1521
+ return left + right;
1522
+ }
1523
+ case "-": {
1524
+ const isRightDelta = right instanceof PyRelativeDelta;
1525
+ if (isRightDelta) {
1526
+ return PyRelativeDelta.substract(left, right);
1527
+ }
1528
+ const timeDeltaOnRight = right instanceof PyTimeDelta;
1529
+ if (timeDeltaOnRight) {
1530
+ if (left instanceof PyTimeDelta) {
1531
+ return left.substract(right);
1532
+ } else if (left instanceof PyDate || left instanceof PyDateTime) {
1533
+ return left.substract(right);
1534
+ } else {
1535
+ throw new NotSupportedError();
1536
+ }
1537
+ }
1538
+ if (left instanceof PyDate) {
1539
+ return left.substract(right);
1540
+ }
1541
+ return left - right;
1821
1542
  }
1822
- return this.days === other.days && this.seconds === other.seconds && this.microseconds === other.microseconds;
1823
- }
1824
- isTrue() {
1825
- return this.days !== 0 || this.seconds !== 0 || this.microseconds !== 0;
1826
- }
1827
- multiply(n) {
1828
- return _PyTimeDelta.create({
1829
- days: n * this.days,
1830
- seconds: n * this.seconds,
1831
- microseconds: n * this.microseconds
1832
- });
1833
- }
1834
- negate() {
1835
- return _PyTimeDelta.create({
1836
- days: -this.days,
1837
- seconds: -this.seconds,
1838
- microseconds: -this.microseconds
1839
- });
1840
- }
1841
- substract(other) {
1842
- return _PyTimeDelta.create({
1843
- days: this.days - other.days,
1844
- seconds: this.seconds - other.seconds,
1845
- microseconds: this.microseconds - other.microseconds
1846
- });
1543
+ case "*": {
1544
+ const timeDeltaOnLeft = left instanceof PyTimeDelta;
1545
+ const timeDeltaOnRight = right instanceof PyTimeDelta;
1546
+ if (timeDeltaOnLeft || timeDeltaOnRight) {
1547
+ const number = timeDeltaOnLeft ? right : left;
1548
+ const delta = timeDeltaOnLeft ? left : right;
1549
+ return delta.multiply(number);
1550
+ }
1551
+ return left * right;
1552
+ }
1553
+ case "/":
1554
+ return left / right;
1555
+ case "%":
1556
+ return left % right;
1557
+ case "//":
1558
+ if (left instanceof PyTimeDelta) {
1559
+ return left.divide(right);
1560
+ }
1561
+ return Math.floor(left / right);
1562
+ case "**":
1563
+ return __pow(left, right);
1564
+ case "==":
1565
+ return isEqual(left, right);
1566
+ case "<>":
1567
+ case "!=":
1568
+ return !isEqual(left, right);
1569
+ case "<":
1570
+ return isLess(left, right);
1571
+ case ">":
1572
+ return isLess(right, left);
1573
+ case ">=":
1574
+ return isEqual(left, right) || isLess(right, left);
1575
+ case "<=":
1576
+ return isEqual(left, right) || isLess(left, right);
1577
+ case "in":
1578
+ return isIn(left, right);
1579
+ case "not in":
1580
+ return !isIn(left, right);
1581
+ default:
1582
+ throw new EvaluationError(`Unknown binary operator: ${ast.op}`);
1847
1583
  }
1848
- total_seconds() {
1849
- return this.days * 86400 + this.seconds + this.microseconds / 1e6;
1584
+ }
1585
+ var DICT = {
1586
+ get(...args) {
1587
+ const { key, defValue } = parseArgs(args, ["key", "defValue"]);
1588
+ const self = this;
1589
+ if (key in self) {
1590
+ return self[key];
1591
+ } else if (defValue !== void 0) {
1592
+ return defValue;
1593
+ }
1594
+ return null;
1850
1595
  }
1851
1596
  };
1852
-
1853
- // src/utils/domain/py_builtin.ts
1854
- var EvaluationError = class extends Error {
1855
- constructor(message) {
1856
- super(message);
1857
- this.name = "EvaluationError";
1597
+ var STRING = {
1598
+ lower() {
1599
+ return this.toLowerCase();
1600
+ },
1601
+ upper() {
1602
+ return this.toUpperCase();
1858
1603
  }
1859
1604
  };
1860
- function execOnIterable(iterable, func) {
1861
- if (iterable === null) {
1862
- throw new EvaluationError("value not iterable");
1605
+ function applyFunc(key, func, set, ...args) {
1606
+ if (args.length === 1) {
1607
+ return new Set(set);
1863
1608
  }
1864
- if (typeof iterable === "object" && !Array.isArray(iterable) && !(iterable instanceof Set)) {
1865
- iterable = Object.keys(iterable);
1609
+ if (args.length > 2) {
1610
+ throw new EvaluationError(
1611
+ `${key}: py_js supports at most 1 argument, got (${args.length - 1})`
1612
+ );
1866
1613
  }
1867
- if (typeof iterable?.[Symbol.iterator] !== "function") {
1868
- throw new EvaluationError("value not iterable");
1614
+ return execOnIterable(args[0], func);
1615
+ }
1616
+ var SET = {
1617
+ intersection(...args) {
1618
+ return applyFunc(
1619
+ "intersection",
1620
+ (iterable) => {
1621
+ const intersection = /* @__PURE__ */ new Set();
1622
+ for (const i of iterable) {
1623
+ if (this.has(i)) {
1624
+ intersection.add(i);
1625
+ }
1626
+ }
1627
+ return intersection;
1628
+ },
1629
+ this,
1630
+ ...args
1631
+ );
1632
+ },
1633
+ difference(...args) {
1634
+ return applyFunc(
1635
+ "difference",
1636
+ (iterable) => {
1637
+ iterable = new Set(iterable);
1638
+ const difference = /* @__PURE__ */ new Set();
1639
+ for (const e of this) {
1640
+ if (!iterable.has(e)) {
1641
+ difference.add(e);
1642
+ }
1643
+ }
1644
+ return difference;
1645
+ },
1646
+ this,
1647
+ ...args
1648
+ );
1649
+ },
1650
+ union(...args) {
1651
+ return applyFunc(
1652
+ "union",
1653
+ (iterable) => {
1654
+ return /* @__PURE__ */ new Set([...this, ...iterable]);
1655
+ },
1656
+ this,
1657
+ ...args
1658
+ );
1869
1659
  }
1870
- return func(iterable);
1660
+ };
1661
+ function methods(_class) {
1662
+ return Object.getOwnPropertyNames(_class.prototype).map(
1663
+ (prop) => _class.prototype[prop]
1664
+ );
1871
1665
  }
1872
- var BUILTINS = {
1873
- /**
1874
- * @param {any} value
1875
- * @returns {boolean}
1876
- */
1877
- bool(value) {
1878
- switch (typeof value) {
1879
- case "number":
1880
- return value !== 0;
1881
- case "string":
1882
- return value !== "";
1883
- case "boolean":
1884
- return value;
1885
- case "object":
1886
- if (value === null || value === void 0) {
1666
+ var allowedFns = /* @__PURE__ */ new Set([
1667
+ BUILTINS.time.strftime,
1668
+ BUILTINS.set,
1669
+ BUILTINS.bool,
1670
+ BUILTINS.context_today,
1671
+ BUILTINS.datetime.datetime.now,
1672
+ BUILTINS.datetime.datetime.combine,
1673
+ BUILTINS.datetime.date.today,
1674
+ ...methods(BUILTINS.relativedelta),
1675
+ ...Object.values(BUILTINS.datetime).flatMap((obj) => methods(obj)),
1676
+ ...Object.values(SET),
1677
+ ...Object.values(DICT),
1678
+ ...Object.values(STRING)
1679
+ ]);
1680
+ var unboundFn = Symbol("unbound function");
1681
+ function evaluate(ast, context = {}) {
1682
+ const dicts = /* @__PURE__ */ new Set();
1683
+ let pyContext;
1684
+ const evalContext = Object.create(context);
1685
+ if (!(evalContext == null ? void 0 : evalContext.context)) {
1686
+ Object.defineProperty(evalContext, "context", {
1687
+ get() {
1688
+ if (!pyContext) {
1689
+ pyContext = toPyDict(context);
1690
+ }
1691
+ return pyContext;
1692
+ }
1693
+ });
1694
+ }
1695
+ function _innerEvaluate(ast2) {
1696
+ var _a, _b, _c;
1697
+ switch (ast2 == null ? void 0 : ast2.type) {
1698
+ case 0:
1699
+ // Number
1700
+ case 1:
1701
+ return ast2.value;
1702
+ case 5:
1703
+ if (ast2.value in evalContext) {
1704
+ if (typeof evalContext[ast2.value] === "object" && ((_a = evalContext[ast2.value]) == null ? void 0 : _a.id)) {
1705
+ return (_b = evalContext[ast2.value]) == null ? void 0 : _b.id;
1706
+ }
1707
+ return (_c = evalContext[ast2.value]) != null ? _c : false;
1708
+ } else if (ast2.value in BUILTINS) {
1709
+ return BUILTINS[ast2.value];
1710
+ } else {
1887
1711
  return false;
1888
1712
  }
1889
- if ("isTrue" in value && typeof value.isTrue === "function") {
1890
- return value.isTrue();
1713
+ case 3:
1714
+ return null;
1715
+ case 2:
1716
+ return ast2.value;
1717
+ case 6:
1718
+ return applyUnaryOp(ast2, evalContext);
1719
+ case 7:
1720
+ return applyBinaryOp(ast2, evalContext);
1721
+ case 14:
1722
+ const left = _evaluate(ast2.left);
1723
+ if (ast2.op === "and") {
1724
+ return isTrue(left) ? _evaluate(ast2.right) : left;
1725
+ } else {
1726
+ return isTrue(left) ? left : _evaluate(ast2.right);
1727
+ }
1728
+ case 4:
1729
+ // List
1730
+ case 10:
1731
+ return ast2.value.map(_evaluate);
1732
+ case 11:
1733
+ const dict = {};
1734
+ for (const key2 in ast2.value) {
1735
+ dict[key2] = _evaluate(ast2.value[key2]);
1736
+ }
1737
+ dicts.add(dict);
1738
+ return dict;
1739
+ case 8:
1740
+ const fnValue = _evaluate(ast2.fn);
1741
+ const args = ast2.args.map(_evaluate);
1742
+ const kwargs = {};
1743
+ for (const kwarg in ast2.kwargs) {
1744
+ kwargs[kwarg] = _evaluate(ast2 == null ? void 0 : ast2.kwargs[kwarg]);
1745
+ }
1746
+ if (fnValue === PyDate || fnValue === PyDateTime || fnValue === PyTime || fnValue === PyRelativeDelta || fnValue === PyTimeDelta) {
1747
+ return fnValue.create(...args, kwargs);
1891
1748
  }
1892
- if (value instanceof Array) {
1893
- return !!value.length;
1749
+ return fnValue(...args, kwargs);
1750
+ case 12:
1751
+ const dictVal = _evaluate(ast2.target);
1752
+ const key = _evaluate(ast2.key);
1753
+ return dictVal[key];
1754
+ case 13:
1755
+ if (isTrue(_evaluate(ast2.condition))) {
1756
+ return _evaluate(ast2.ifTrue);
1757
+ } else {
1758
+ return _evaluate(ast2.ifFalse);
1894
1759
  }
1895
- if (value instanceof Set) {
1896
- return !!value.size;
1760
+ case 15:
1761
+ let leftVal = _evaluate(ast2.obj);
1762
+ let result;
1763
+ if (dicts.has(leftVal) || Object.isPrototypeOf.call(PY_DICT, leftVal)) {
1764
+ result = DICT[ast2.key];
1765
+ } else if (typeof leftVal === "string") {
1766
+ result = STRING[ast2.key];
1767
+ } else if (leftVal instanceof Set) {
1768
+ result = SET[ast2.key];
1769
+ } else if (ast2.key === "get" && typeof leftVal === "object") {
1770
+ result = DICT[ast2.key];
1771
+ leftVal = toPyDict(leftVal);
1772
+ } else {
1773
+ result = leftVal[ast2.key];
1897
1774
  }
1898
- return Object.keys(value).length !== 0;
1775
+ if (typeof result === "function") {
1776
+ const bound = result.bind(leftVal);
1777
+ bound[unboundFn] = result;
1778
+ return bound;
1779
+ }
1780
+ return result;
1899
1781
  default:
1900
- return true;
1901
- }
1902
- },
1903
- set(iterable) {
1904
- if (arguments.length > 2) {
1905
- throw new EvaluationError(
1906
- `set expected at most 1 argument, got (${arguments.length - 1})`
1907
- );
1782
+ throw new EvaluationError(`AST of type ${ast2.type} cannot be evaluated`);
1908
1783
  }
1909
- return execOnIterable(
1910
- iterable,
1911
- (iterable2) => new Set(iterable2)
1912
- );
1913
- },
1914
- time: {
1915
- strftime(format) {
1916
- return PyDateTime.now().strftime(format);
1784
+ }
1785
+ function _evaluate(ast2) {
1786
+ const val = _innerEvaluate(ast2);
1787
+ if (typeof val === "function" && !allowedFns.has(val) && !allowedFns.has(val[unboundFn])) {
1788
+ throw new Error("Invalid Function Call");
1917
1789
  }
1918
- },
1919
- context_today() {
1920
- return PyDate.today();
1921
- },
1922
- get current_date() {
1923
- return this.today;
1924
- },
1925
- get today() {
1926
- return PyDate.today().strftime("%Y-%m-%d");
1927
- },
1928
- get now() {
1929
- return PyDateTime.now().strftime("%Y-%m-%d %H:%M:%S");
1930
- },
1931
- datetime: {
1932
- time: PyTime,
1933
- timedelta: PyTimeDelta,
1934
- datetime: PyDateTime,
1935
- date: PyDate
1936
- },
1937
- relativedelta: PyRelativeDelta,
1938
- true: true,
1939
- false: false
1940
- };
1790
+ return val;
1791
+ }
1792
+ return _evaluate(ast);
1793
+ }
1941
1794
 
1942
- // src/utils/domain/py_utils.ts
1943
- function toPyValue(value) {
1944
- switch (typeof value) {
1945
- case "string":
1946
- return { type: 1, value };
1947
- case "number":
1948
- return { type: 0, value };
1949
- case "boolean":
1950
- return { type: 2, value };
1951
- case "object":
1952
- if (Array.isArray(value)) {
1953
- return { type: 4, value: value.map(toPyValue) };
1954
- } else if (value === null) {
1955
- return {
1956
- type: 3
1957
- /* None */
1958
- };
1959
- } else if (value instanceof Date) {
1960
- return {
1961
- type: 1,
1962
- value: String(PyDateTime.convertDate(value))
1963
- };
1964
- } else if (value instanceof PyDate || value instanceof PyDateTime) {
1965
- return { type: 1, value };
1966
- } else {
1967
- const content = {};
1968
- for (const key in value) {
1969
- content[key] = toPyValue(value[key]);
1970
- }
1971
- return { type: 11, value: content };
1972
- }
1973
- default:
1974
- throw new Error("Invalid type");
1795
+ // src/utils/domain/py.ts
1796
+ function parseExpr(expr) {
1797
+ const tokens = tokenize(expr);
1798
+ return parse(tokens);
1799
+ }
1800
+
1801
+ // src/utils/domain/objects.ts
1802
+ function shallowEqual(obj1, obj2, comparisonFn = (a, b) => a === b) {
1803
+ if (!obj1 || !obj2 || typeof obj1 !== "object" || typeof obj2 !== "object") {
1804
+ return obj1 === obj2;
1975
1805
  }
1806
+ const obj1Keys = Object.keys(obj1);
1807
+ return obj1Keys.length === Object.keys(obj2).length && obj1Keys.every((key) => comparisonFn(obj1[key], obj2[key]));
1976
1808
  }
1977
- function formatAST(ast, lbp = 0) {
1978
- switch (ast.type) {
1979
- case 3:
1980
- return "None";
1981
- case 1:
1982
- return JSON.stringify(ast.value);
1983
- case 0:
1984
- return String(ast.value);
1985
- case 2:
1986
- return ast.value ? "True" : "False";
1987
- case 4:
1988
- return `[${ast.value.map(formatAST).join(", ")}]`;
1989
- case 6:
1990
- if (ast.op === "not") {
1991
- return `not ${formatAST(ast.right, 50)}`;
1809
+
1810
+ // src/utils/domain/arrays.ts
1811
+ var shallowEqual2 = shallowEqual;
1812
+
1813
+ // src/utils/domain/strings.ts
1814
+ var escapeMethod = Symbol("html");
1815
+ function escapeRegExp(str) {
1816
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1817
+ }
1818
+
1819
+ // src/utils/domain/domain.ts
1820
+ var InvalidDomainError = class extends Error {
1821
+ };
1822
+ var Domain = class _Domain {
1823
+ constructor(descr = []) {
1824
+ this.ast = { type: -1, value: null };
1825
+ if (descr instanceof _Domain) {
1826
+ return new _Domain(descr.toString());
1827
+ } else {
1828
+ let rawAST;
1829
+ try {
1830
+ rawAST = typeof descr === "string" ? parseExpr(descr) : toAST(descr);
1831
+ } catch (error) {
1832
+ throw new InvalidDomainError(
1833
+ `Invalid domain representation: ${descr}`,
1834
+ {
1835
+ cause: error
1836
+ }
1837
+ );
1992
1838
  }
1993
- return `${ast.op}${formatAST(ast.right, 130)}`;
1994
- case 7:
1995
- const abp = bp(ast.op);
1996
- const binaryStr = `${formatAST(ast.left, abp)} ${ast.op} ${formatAST(ast.right, abp)}`;
1997
- return abp < lbp ? `(${binaryStr})` : binaryStr;
1998
- case 11:
1999
- const pairs = [];
2000
- for (const k in ast.value) {
2001
- pairs.push(`"${k}": ${formatAST(ast.value[k])}`);
1839
+ this.ast = normalizeDomainAST(rawAST);
1840
+ }
1841
+ }
1842
+ static combine(domains, operator) {
1843
+ if (domains.length === 0) {
1844
+ return new _Domain([]);
1845
+ }
1846
+ const domain1 = domains[0] instanceof _Domain ? domains[0] : new _Domain(domains[0]);
1847
+ if (domains.length === 1) {
1848
+ return domain1;
1849
+ }
1850
+ const domain2 = _Domain.combine(domains.slice(1), operator);
1851
+ const result = new _Domain([]);
1852
+ const astValues1 = domain1.ast.value;
1853
+ const astValues2 = domain2.ast.value;
1854
+ const op = operator === "AND" ? "&" : "|";
1855
+ const combinedAST = {
1856
+ type: 4,
1857
+ value: astValues1.concat(astValues2)
1858
+ };
1859
+ result.ast = normalizeDomainAST(combinedAST, op);
1860
+ return result;
1861
+ }
1862
+ static and(domains) {
1863
+ return _Domain.combine(domains, "AND");
1864
+ }
1865
+ static or(domains) {
1866
+ return _Domain.combine(domains, "OR");
1867
+ }
1868
+ static not(domain) {
1869
+ const result = new _Domain(domain);
1870
+ result.ast.value.unshift({ type: 1, value: "!" });
1871
+ return result;
1872
+ }
1873
+ static removeDomainLeaves(domain, keysToRemove) {
1874
+ function processLeaf(elements, idx, operatorCtx, newDomain2) {
1875
+ const leaf = elements[idx];
1876
+ if (leaf.type === 10) {
1877
+ if (keysToRemove.includes(leaf.value[0].value)) {
1878
+ if (operatorCtx === "&") {
1879
+ newDomain2.ast.value.push(..._Domain.TRUE.ast.value);
1880
+ } else if (operatorCtx === "|") {
1881
+ newDomain2.ast.value.push(..._Domain.FALSE.ast.value);
1882
+ }
1883
+ } else {
1884
+ newDomain2.ast.value.push(leaf);
1885
+ }
1886
+ return 1;
1887
+ } else if (leaf.type === 1) {
1888
+ if (leaf.value === "|" && elements[idx + 1].type === 10 && elements[idx + 2].type === 10 && keysToRemove.includes(elements[idx + 1].value[0].value) && keysToRemove.includes(elements[idx + 2].value[0].value)) {
1889
+ newDomain2.ast.value.push(..._Domain.TRUE.ast.value);
1890
+ return 3;
1891
+ }
1892
+ newDomain2.ast.value.push(leaf);
1893
+ if (leaf.value === "!") {
1894
+ return 1 + processLeaf(elements, idx + 1, "&", newDomain2);
1895
+ }
1896
+ const firstLeafSkip = processLeaf(
1897
+ elements,
1898
+ idx + 1,
1899
+ leaf.value,
1900
+ newDomain2
1901
+ );
1902
+ const secondLeafSkip = processLeaf(
1903
+ elements,
1904
+ idx + 1 + firstLeafSkip,
1905
+ leaf.value,
1906
+ newDomain2
1907
+ );
1908
+ return 1 + firstLeafSkip + secondLeafSkip;
2002
1909
  }
2003
- return `{${pairs.join(", ")}}`;
2004
- case 10:
2005
- return `(${ast.value.map(formatAST).join(", ")})`;
2006
- case 5:
2007
- return ast.value;
2008
- case 12:
2009
- return `${formatAST(ast.target)}[${formatAST(ast.key)}]`;
2010
- case 13:
2011
- const { ifTrue, condition, ifFalse } = ast;
2012
- return `${formatAST(ifTrue)} if ${formatAST(condition)} else ${formatAST(ifFalse)}`;
2013
- case 14:
2014
- const boolAbp = bp(ast.op);
2015
- const boolStr = `${formatAST(ast.left, boolAbp)} ${ast.op} ${formatAST(ast.right, boolAbp)}`;
2016
- return boolAbp < lbp ? `(${boolStr})` : boolStr;
2017
- case 15:
2018
- return `${formatAST(ast.obj, 150)}.${ast.key}`;
2019
- case 8:
2020
- const args = ast.args.map(formatAST);
2021
- const kwargs = [];
2022
- for (const kwarg in ast.kwargs) {
2023
- kwargs.push(`${kwarg} = ${formatAST(ast.kwargs[kwarg])}`);
1910
+ return 0;
1911
+ }
1912
+ const d = new _Domain(domain);
1913
+ if (d.ast.value.length === 0) {
1914
+ return d;
1915
+ }
1916
+ const newDomain = new _Domain([]);
1917
+ processLeaf(d.ast.value, 0, "&", newDomain);
1918
+ return newDomain;
1919
+ }
1920
+ contains(record) {
1921
+ const expr = evaluate(this.ast, record);
1922
+ return matchDomain(record, expr);
1923
+ }
1924
+ toString() {
1925
+ return formatAST(this.ast);
1926
+ }
1927
+ toList(context) {
1928
+ return evaluate(this.ast, context);
1929
+ }
1930
+ toJson() {
1931
+ try {
1932
+ const evaluatedAsList = this.toList({});
1933
+ const evaluatedDomain = new _Domain(evaluatedAsList);
1934
+ if (evaluatedDomain.toString() === this.toString()) {
1935
+ return evaluatedAsList;
2024
1936
  }
2025
- const argStr = args.concat(kwargs).join(", ");
2026
- return `${formatAST(ast.fn)}(${argStr})`;
2027
- default:
2028
- throw new Error("invalid expression: " + JSON.stringify(ast));
1937
+ return this.toString();
1938
+ } catch (e) {
1939
+ return this.toString();
1940
+ }
2029
1941
  }
2030
- }
2031
- var PY_DICT = /* @__PURE__ */ Object.create(null);
2032
- function toPyDict(obj) {
2033
- return new Proxy(obj, {
2034
- getPrototypeOf() {
2035
- return PY_DICT;
1942
+ };
1943
+ var TRUE_LEAF = [1, "=", 1];
1944
+ var FALSE_LEAF = [0, "=", 1];
1945
+ var TRUE_DOMAIN = new Domain([TRUE_LEAF]);
1946
+ var FALSE_DOMAIN = new Domain([FALSE_LEAF]);
1947
+ Domain.TRUE = TRUE_DOMAIN;
1948
+ Domain.FALSE = FALSE_DOMAIN;
1949
+ function toAST(domain) {
1950
+ const elems = domain.map((elem) => {
1951
+ switch (elem) {
1952
+ case "!":
1953
+ case "&":
1954
+ case "|":
1955
+ return { type: 1, value: elem };
1956
+ default:
1957
+ return {
1958
+ type: 10,
1959
+ value: elem.map(toPyValue)
1960
+ };
2036
1961
  }
2037
1962
  });
1963
+ return { type: 4, value: elems };
2038
1964
  }
2039
-
2040
- // src/utils/domain/py_interpreter.ts
2041
- var isTrue = BUILTINS.bool;
2042
- function applyUnaryOp(ast, context) {
2043
- const value = evaluate(ast.right, context);
2044
- switch (ast.op) {
2045
- case "-":
2046
- if (value instanceof Object && "negate" in value) {
2047
- return value.negate();
1965
+ function normalizeDomainAST(domain, op = "&") {
1966
+ if (domain.type !== 4) {
1967
+ if (domain.type === 10) {
1968
+ const value = domain.value;
1969
+ if (value.findIndex((e) => e.type === 10) === -1 || !value.every((e) => e.type === 10 || e.type === 1)) {
1970
+ throw new InvalidDomainError("Invalid domain AST");
2048
1971
  }
2049
- return -value;
2050
- case "+":
2051
- return value;
2052
- case "not":
2053
- return !isTrue(value);
2054
- default:
2055
- throw new EvaluationError(`Unknown unary operator: ${ast.op}`);
2056
- }
2057
- }
2058
- function pytypeIndex(val) {
2059
- switch (typeof val) {
2060
- case "object":
2061
- return val === null ? 1 : Array.isArray(val) ? 5 : 3;
2062
- case "number":
2063
- return 2;
2064
- case "string":
2065
- return 4;
2066
- default:
2067
- throw new EvaluationError(`Unknown type: ${typeof val}`);
1972
+ } else {
1973
+ throw new InvalidDomainError("Invalid domain AST");
1974
+ }
2068
1975
  }
2069
- }
2070
- function isLess(left, right) {
2071
- if (typeof left === "number" && typeof right === "number") {
2072
- return left < right;
1976
+ if (domain.value.length === 0) {
1977
+ return domain;
2073
1978
  }
2074
- if (typeof left === "boolean") {
2075
- left = left ? 1 : 0;
1979
+ let expected = 1;
1980
+ for (const child of domain.value) {
1981
+ switch (child.type) {
1982
+ case 1:
1983
+ if (child.value === "&" || child.value === "|") {
1984
+ expected++;
1985
+ } else if (child.value !== "!") {
1986
+ throw new InvalidDomainError("Invalid domain AST");
1987
+ }
1988
+ break;
1989
+ case 4:
1990
+ /* list */
1991
+ case 10:
1992
+ if (child.value.length === 3) {
1993
+ expected--;
1994
+ break;
1995
+ }
1996
+ throw new InvalidDomainError("Invalid domain AST");
1997
+ default:
1998
+ throw new InvalidDomainError("Invalid domain AST");
1999
+ }
2076
2000
  }
2077
- if (typeof right === "boolean") {
2078
- right = right ? 1 : 0;
2001
+ const values = domain.value.slice();
2002
+ while (expected < 0) {
2003
+ expected++;
2004
+ values.unshift({ type: 1, value: op });
2079
2005
  }
2080
- const leftIndex = pytypeIndex(left);
2081
- const rightIndex = pytypeIndex(right);
2082
- if (leftIndex === rightIndex) {
2083
- return left < right;
2006
+ if (expected > 0) {
2007
+ throw new InvalidDomainError(
2008
+ `invalid domain ${formatAST(domain)} (missing ${expected} segment(s))`
2009
+ );
2084
2010
  }
2085
- return leftIndex < rightIndex;
2011
+ return { type: 4, value: values };
2086
2012
  }
2087
- function isEqual(left, right) {
2088
- if (typeof left !== typeof right) {
2089
- if (typeof left === "boolean" && typeof right === "number") {
2090
- return right === (left ? 1 : 0);
2091
- }
2092
- if (typeof left === "number" && typeof right === "boolean") {
2093
- return left === (right ? 1 : 0);
2013
+ function matchCondition(record, condition) {
2014
+ if (typeof condition === "boolean") {
2015
+ return condition;
2016
+ }
2017
+ const [field, operator, value] = condition;
2018
+ if (typeof field === "string") {
2019
+ const names = field.split(".");
2020
+ if (names.length >= 2) {
2021
+ return matchCondition(record[names[0]], [
2022
+ names.slice(1).join("."),
2023
+ operator,
2024
+ value
2025
+ ]);
2094
2026
  }
2095
- return false;
2096
2027
  }
2097
- if (left instanceof Object && "isEqual" in left) {
2098
- return left.isEqual(right);
2028
+ let likeRegexp, ilikeRegexp;
2029
+ if (["like", "not like", "ilike", "not ilike"].includes(operator)) {
2030
+ likeRegexp = new RegExp(
2031
+ `(.*)${escapeRegExp(value).replaceAll("%", "(.*)")}(.*)`,
2032
+ "g"
2033
+ );
2034
+ ilikeRegexp = new RegExp(
2035
+ `(.*)${escapeRegExp(value).replaceAll("%", "(.*)")}(.*)`,
2036
+ "gi"
2037
+ );
2038
+ }
2039
+ const fieldValue = typeof field === "number" ? field : record[field];
2040
+ switch (operator) {
2041
+ case "=?":
2042
+ if ([false, null].includes(value)) {
2043
+ return true;
2044
+ }
2045
+ // eslint-disable-next-line no-fallthrough
2046
+ case "=":
2047
+ case "==":
2048
+ if (Array.isArray(fieldValue) && Array.isArray(value)) {
2049
+ return shallowEqual2(fieldValue, value);
2050
+ }
2051
+ return fieldValue === value;
2052
+ case "!=":
2053
+ case "<>":
2054
+ return !matchCondition(record, [field, "==", value]);
2055
+ case "<":
2056
+ return fieldValue < value;
2057
+ case "<=":
2058
+ return fieldValue <= value;
2059
+ case ">":
2060
+ return fieldValue > value;
2061
+ case ">=":
2062
+ return fieldValue >= value;
2063
+ case "in": {
2064
+ const val = Array.isArray(value) ? value : [value];
2065
+ const fieldVal = Array.isArray(fieldValue) ? fieldValue : [fieldValue];
2066
+ return fieldVal.some((fv) => val.includes(fv));
2067
+ }
2068
+ case "not in": {
2069
+ const val = Array.isArray(value) ? value : [value];
2070
+ const fieldVal = Array.isArray(fieldValue) ? fieldValue : [fieldValue];
2071
+ return !fieldVal.some((fv) => val.includes(fv));
2072
+ }
2073
+ case "like":
2074
+ if (fieldValue === false) {
2075
+ return false;
2076
+ }
2077
+ return Boolean(fieldValue.match(likeRegexp));
2078
+ case "not like":
2079
+ if (fieldValue === false) {
2080
+ return false;
2081
+ }
2082
+ return Boolean(!fieldValue.match(likeRegexp));
2083
+ case "=like":
2084
+ if (fieldValue === false) {
2085
+ return false;
2086
+ }
2087
+ return new RegExp(escapeRegExp(value).replace(/%/g, ".*")).test(
2088
+ fieldValue
2089
+ );
2090
+ case "ilike":
2091
+ if (fieldValue === false) {
2092
+ return false;
2093
+ }
2094
+ return Boolean(fieldValue.match(ilikeRegexp));
2095
+ case "not ilike":
2096
+ if (fieldValue === false) {
2097
+ return false;
2098
+ }
2099
+ return Boolean(!fieldValue.match(ilikeRegexp));
2100
+ case "=ilike":
2101
+ if (fieldValue === false) {
2102
+ return false;
2103
+ }
2104
+ return new RegExp(escapeRegExp(value).replace(/%/g, ".*"), "i").test(
2105
+ fieldValue
2106
+ );
2099
2107
  }
2100
- return left === right;
2108
+ throw new InvalidDomainError("could not match domain");
2101
2109
  }
2102
- function isIn(left, right) {
2103
- if (Array.isArray(right)) {
2104
- return right.includes(left);
2105
- }
2106
- if (typeof right === "string" && typeof left === "string") {
2107
- return right.includes(left);
2110
+ function makeOperators(record) {
2111
+ const match = matchCondition.bind(null, record);
2112
+ return {
2113
+ "!": (x) => !match(x),
2114
+ "&": (a, b) => match(a) && match(b),
2115
+ "|": (a, b) => match(a) || match(b)
2116
+ };
2117
+ }
2118
+ function matchDomain(record, domain) {
2119
+ if (domain.length === 0) {
2120
+ return true;
2108
2121
  }
2109
- if (typeof right === "object") {
2110
- return left in right;
2122
+ const operators = makeOperators(record);
2123
+ const reversedDomain = Array.from(domain).reverse();
2124
+ const condStack = [];
2125
+ for (const item of reversedDomain) {
2126
+ const operator = typeof item === "string" && operators[item];
2127
+ if (operator) {
2128
+ const operands = condStack.splice(-operator.length);
2129
+ condStack.push(operator(...operands));
2130
+ } else {
2131
+ condStack.push(item);
2132
+ }
2111
2133
  }
2112
- return false;
2134
+ return matchCondition(record, condStack.pop());
2113
2135
  }
2114
- function applyBinaryOp(ast, context) {
2115
- const left = evaluate(ast.left, context);
2116
- const right = evaluate(ast.right, context);
2117
- switch (ast.op) {
2118
- case "+": {
2119
- const relativeDeltaOnLeft = left instanceof PyRelativeDelta;
2120
- const relativeDeltaOnRight = right instanceof PyRelativeDelta;
2121
- if (relativeDeltaOnLeft || relativeDeltaOnRight) {
2122
- const date = relativeDeltaOnLeft ? right : left;
2123
- const delta = relativeDeltaOnLeft ? left : right;
2124
- return PyRelativeDelta.add(date, delta);
2125
- }
2126
- const timeDeltaOnLeft = left instanceof PyTimeDelta;
2127
- const timeDeltaOnRight = right instanceof PyTimeDelta;
2128
- if (timeDeltaOnLeft && timeDeltaOnRight) {
2129
- return left.add(right);
2136
+
2137
+ // src/utils/function.ts
2138
+ import { useEffect, useState } from "react";
2139
+ var updateTokenParamInOriginalRequest = (originalRequest, newAccessToken) => {
2140
+ if (!originalRequest.data) return originalRequest.data;
2141
+ if (typeof originalRequest.data === "string") {
2142
+ try {
2143
+ const parsedData = JSON.parse(originalRequest.data);
2144
+ if (parsedData.with_context && typeof parsedData.with_context === "object") {
2145
+ parsedData.with_context.token = newAccessToken;
2130
2146
  }
2131
- if (timeDeltaOnLeft) {
2132
- if (right instanceof PyDate || right instanceof PyDateTime) {
2133
- return right.add(left);
2147
+ return JSON.stringify(parsedData);
2148
+ } catch (e) {
2149
+ console.warn("Failed to parse originalRequest.data", e);
2150
+ return originalRequest.data;
2151
+ }
2152
+ }
2153
+ if (typeof originalRequest.data === "object" && originalRequest.data.with_context) {
2154
+ originalRequest.data.with_context.token = newAccessToken;
2155
+ }
2156
+ return originalRequest.data;
2157
+ };
2158
+
2159
+ // src/utils/storage/local-storage.ts
2160
+ var localStorageUtils = () => {
2161
+ const setToken = (access_token) => __async(null, null, function* () {
2162
+ localStorage.setItem("accessToken", access_token);
2163
+ });
2164
+ const setRefreshToken = (refresh_token) => __async(null, null, function* () {
2165
+ localStorage.setItem("refreshToken", refresh_token);
2166
+ });
2167
+ const getAccessToken = () => __async(null, null, function* () {
2168
+ return localStorage.getItem("accessToken");
2169
+ });
2170
+ const getRefreshToken = () => __async(null, null, function* () {
2171
+ return localStorage.getItem("refreshToken");
2172
+ });
2173
+ const clearToken = () => __async(null, null, function* () {
2174
+ localStorage.removeItem("accessToken");
2175
+ localStorage.removeItem("refreshToken");
2176
+ });
2177
+ return {
2178
+ setToken,
2179
+ setRefreshToken,
2180
+ getAccessToken,
2181
+ getRefreshToken,
2182
+ clearToken
2183
+ };
2184
+ };
2185
+
2186
+ // src/utils/storage/session-storage.ts
2187
+ var sessionStorageUtils = () => {
2188
+ const getBrowserSession = () => __async(null, null, function* () {
2189
+ return sessionStorage.getItem("browserSession");
2190
+ });
2191
+ return {
2192
+ getBrowserSession
2193
+ };
2194
+ };
2195
+
2196
+ // src/configs/axios-client.ts
2197
+ var axiosClient = {
2198
+ init(config) {
2199
+ var _a, _b;
2200
+ const localStorage2 = (_a = config.localStorageUtils) != null ? _a : localStorageUtils();
2201
+ const sessionStorage2 = (_b = config.sessionStorageUtils) != null ? _b : sessionStorageUtils();
2202
+ const db = config.db;
2203
+ let isRefreshing = false;
2204
+ let failedQueue = [];
2205
+ const processQueue = (error, token = null) => {
2206
+ failedQueue == null ? void 0 : failedQueue.forEach((prom) => {
2207
+ if (error) {
2208
+ prom.reject(error);
2134
2209
  } else {
2135
- throw new NotSupportedError();
2210
+ prom.resolve(token);
2136
2211
  }
2137
- }
2138
- if (timeDeltaOnRight) {
2139
- if (left instanceof PyDate || left instanceof PyDateTime) {
2140
- return left.add(right);
2141
- } else {
2142
- throw new NotSupportedError();
2212
+ });
2213
+ failedQueue = [];
2214
+ };
2215
+ const instance = axios.create({
2216
+ adapter: axios.defaults.adapter,
2217
+ baseURL: config.baseUrl,
2218
+ timeout: 5e4,
2219
+ paramsSerializer: (params) => new URLSearchParams(params).toString()
2220
+ });
2221
+ instance.interceptors.request.use(
2222
+ (config2) => __async(null, null, function* () {
2223
+ const useRefreshToken = config2.useRefreshToken;
2224
+ const token = useRefreshToken ? yield localStorage2.getRefreshToken() : yield localStorage2.getAccessToken();
2225
+ if (token) {
2226
+ config2.headers["Authorization"] = "Bearer " + token;
2143
2227
  }
2228
+ return config2;
2229
+ }),
2230
+ (error) => {
2231
+ Promise.reject(error);
2144
2232
  }
2145
- if (left instanceof Array && right instanceof Array) {
2146
- return [...left, ...right];
2147
- }
2148
- return left + right;
2149
- }
2150
- case "-": {
2151
- const isRightDelta = right instanceof PyRelativeDelta;
2152
- if (isRightDelta) {
2153
- return PyRelativeDelta.substract(left, right);
2154
- }
2155
- const timeDeltaOnRight = right instanceof PyTimeDelta;
2156
- if (timeDeltaOnRight) {
2157
- if (left instanceof PyTimeDelta) {
2158
- return left.substract(right);
2159
- } else if (left instanceof PyDate || left instanceof PyDateTime) {
2160
- return left.substract(right);
2161
- } else {
2162
- throw new NotSupportedError();
2233
+ );
2234
+ instance.interceptors.response.use(
2235
+ (response) => {
2236
+ return handleResponse(response);
2237
+ },
2238
+ (error) => __async(null, null, function* () {
2239
+ var _a2, _b2, _c;
2240
+ const handleError3 = (error2) => __async(null, null, function* () {
2241
+ var _a3;
2242
+ if (!error2.response) {
2243
+ return error2;
2244
+ }
2245
+ const { data } = error2.response;
2246
+ if (data && data.code === 400 && ["invalid_grant"].includes((_a3 = data.data) == null ? void 0 : _a3.error)) {
2247
+ yield clearAuthToken();
2248
+ }
2249
+ return data;
2250
+ });
2251
+ const originalRequest = error.config;
2252
+ if ((((_a2 = error.response) == null ? void 0 : _a2.status) === 403 || ((_b2 = error.response) == null ? void 0 : _b2.status) === 401 || ((_c = error.response) == null ? void 0 : _c.status) === 404) && ["TOKEN_EXPIRED", "AUTHEN_FAIL", 401, "ERR_2FA_006"].includes(
2253
+ error.response.data.code
2254
+ )) {
2255
+ if (isRefreshing) {
2256
+ return new Promise(function(resolve, reject) {
2257
+ failedQueue.push({ resolve, reject });
2258
+ }).then((token) => {
2259
+ originalRequest.headers["Authorization"] = "Bearer " + token;
2260
+ originalRequest.data = updateTokenParamInOriginalRequest(
2261
+ originalRequest,
2262
+ token
2263
+ );
2264
+ return instance.request(originalRequest);
2265
+ }).catch((err) => __async(null, null, function* () {
2266
+ var _a3, _b3;
2267
+ if ((((_a3 = err.response) == null ? void 0 : _a3.status) === 400 || ((_b3 = err.response) == null ? void 0 : _b3.status) === 401) && ["invalid_grant"].includes(err.response.data.error)) {
2268
+ yield clearAuthToken();
2269
+ }
2270
+ }));
2271
+ }
2272
+ const browserSession = yield sessionStorage2.getBrowserSession();
2273
+ const refreshToken = yield localStorage2.getRefreshToken();
2274
+ const accessTokenExp = yield localStorage2.getAccessToken();
2275
+ isRefreshing = true;
2276
+ if (!refreshToken && (!browserSession || browserSession == "unActive")) {
2277
+ yield clearAuthToken();
2278
+ } else {
2279
+ const payload = Object.fromEntries(
2280
+ Object.entries({
2281
+ refresh_token: refreshToken,
2282
+ grant_type: "refresh_token",
2283
+ client_id: config.config.clientId,
2284
+ client_secret: config.config.clientSecret
2285
+ }).filter(([_, value]) => !!value)
2286
+ );
2287
+ return new Promise(function(resolve) {
2288
+ var _a3;
2289
+ axios.post(
2290
+ `${config.baseUrl}${(_a3 = config.refreshTokenEndpoint) != null ? _a3 : "/authentication/oauth2/token" /* AUTH_TOKEN_PATH */}`,
2291
+ payload,
2292
+ {
2293
+ headers: {
2294
+ "Content-Type": config.refreshTokenEndpoint ? "application/x-www-form-urlencoded" : "multipart/form-data",
2295
+ Authorization: `Bearer ${accessTokenExp}`
2296
+ }
2297
+ }
2298
+ ).then((res) => __async(null, null, function* () {
2299
+ const data = res.data;
2300
+ yield localStorage2.setToken(data.access_token);
2301
+ yield localStorage2.setRefreshToken(data.refresh_token);
2302
+ axios.defaults.headers.common["Authorization"] = "Bearer " + data.access_token;
2303
+ originalRequest.headers["Authorization"] = "Bearer " + data.access_token;
2304
+ originalRequest.data = updateTokenParamInOriginalRequest(
2305
+ originalRequest,
2306
+ data.access_token
2307
+ );
2308
+ processQueue(null, data.access_token);
2309
+ resolve(instance.request(originalRequest));
2310
+ })).catch((err) => __async(null, null, function* () {
2311
+ var _a4;
2312
+ if (err && ((err == null ? void 0 : err.error_code) === "AUTHEN_FAIL" || (err == null ? void 0 : err.error_code) === "TOKEN_EXPIRED" || (err == null ? void 0 : err.error_code) === "TOKEN_INCORRECT" || (err == null ? void 0 : err.code) === "ERR_BAD_REQUEST") || (err == null ? void 0 : err.error_code) === "ERR_2FA_006") {
2313
+ yield clearAuthToken();
2314
+ }
2315
+ if (err && err.response) {
2316
+ const { error_code } = ((_a4 = err.response) == null ? void 0 : _a4.data) || {};
2317
+ if (error_code === "AUTHEN_FAIL") {
2318
+ yield clearAuthToken();
2319
+ }
2320
+ }
2321
+ processQueue(err, null);
2322
+ })).finally(() => {
2323
+ isRefreshing = false;
2324
+ });
2325
+ });
2326
+ }
2163
2327
  }
2328
+ return Promise.reject(yield handleError3(error));
2329
+ })
2330
+ );
2331
+ const handleResponse = (res) => {
2332
+ if (res && res.data) {
2333
+ return res.data;
2164
2334
  }
2165
- if (left instanceof PyDate) {
2166
- return left.substract(right);
2167
- }
2168
- return left - right;
2169
- }
2170
- case "*": {
2171
- const timeDeltaOnLeft = left instanceof PyTimeDelta;
2172
- const timeDeltaOnRight = right instanceof PyTimeDelta;
2173
- if (timeDeltaOnLeft || timeDeltaOnRight) {
2174
- const number = timeDeltaOnLeft ? right : left;
2175
- const delta = timeDeltaOnLeft ? left : right;
2176
- return delta.multiply(number);
2177
- }
2178
- return left * right;
2179
- }
2180
- case "/":
2181
- return left / right;
2182
- case "%":
2183
- return left % right;
2184
- case "//":
2185
- if (left instanceof PyTimeDelta) {
2186
- return left.divide(right);
2335
+ return res;
2336
+ };
2337
+ const handleError2 = (error) => {
2338
+ var _a2, _b2, _c;
2339
+ if (error.isAxiosError && error.code === "ECONNABORTED") {
2340
+ console.error("Request Timeout Error:", error);
2341
+ return "Request Timeout Error";
2342
+ } else if (error.isAxiosError && !error.response) {
2343
+ console.error("Network Error:", error);
2344
+ return "Network Error";
2345
+ } else {
2346
+ console.error("Other Error:", error == null ? void 0 : error.response);
2347
+ const errorMessage = ((_b2 = (_a2 = error == null ? void 0 : error.response) == null ? void 0 : _a2.data) == null ? void 0 : _b2.message) || "An error occurred";
2348
+ return { message: errorMessage, status: (_c = error == null ? void 0 : error.response) == null ? void 0 : _c.status };
2187
2349
  }
2188
- return Math.floor(left / right);
2189
- case "**":
2190
- return left ** right;
2191
- case "==":
2192
- return isEqual(left, right);
2193
- case "<>":
2194
- case "!=":
2195
- return !isEqual(left, right);
2196
- case "<":
2197
- return isLess(left, right);
2198
- case ">":
2199
- return isLess(right, left);
2200
- case ">=":
2201
- return isEqual(left, right) || isLess(right, left);
2202
- case "<=":
2203
- return isEqual(left, right) || isLess(left, right);
2204
- case "in":
2205
- return isIn(left, right);
2206
- case "not in":
2207
- return !isIn(left, right);
2208
- default:
2209
- throw new EvaluationError(`Unknown binary operator: ${ast.op}`);
2210
- }
2211
- }
2212
- var DICT = {
2213
- get(...args) {
2214
- const { key, defValue } = parseArgs(args, ["key", "defValue"]);
2215
- const self = this;
2216
- if (key in self) {
2217
- return self[key];
2218
- } else if (defValue !== void 0) {
2219
- return defValue;
2350
+ };
2351
+ const clearAuthToken = () => __async(null, null, function* () {
2352
+ yield localStorage2.clearToken();
2353
+ if (typeof window !== "undefined") {
2354
+ window.location.href = `/login`;
2355
+ }
2356
+ });
2357
+ function formatUrl(url, db2) {
2358
+ return url + (db2 ? "?db=" + db2 : "");
2220
2359
  }
2221
- return null;
2360
+ const responseBody = (response) => response;
2361
+ const requests = {
2362
+ get: (url, headers) => instance.get(formatUrl(url, db), headers).then(responseBody),
2363
+ post: (url, body, headers) => instance.post(formatUrl(url, db), body, headers).then(responseBody),
2364
+ post_excel: (url, body, headers) => instance.post(formatUrl(url, db), body, {
2365
+ responseType: "arraybuffer",
2366
+ headers: {
2367
+ "Content-Type": typeof window !== "undefined" ? "application/json" : "application/javascript",
2368
+ Accept: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
2369
+ }
2370
+ }).then(responseBody),
2371
+ put: (url, body, headers) => instance.put(formatUrl(url, db), body, headers).then(responseBody),
2372
+ patch: (url, body) => instance.patch(formatUrl(url, db), body).then(responseBody),
2373
+ delete: (url, body) => instance.delete(formatUrl(url, db), body).then(responseBody)
2374
+ };
2375
+ return requests;
2222
2376
  }
2223
2377
  };
2224
- var STRING = {
2225
- lower() {
2226
- return this.toLowerCase();
2378
+
2379
+ // src/store/index.ts
2380
+ import { useDispatch, useSelector } from "react-redux";
2381
+
2382
+ // src/store/reducers/breadcrums-slice/index.ts
2383
+ import { createSlice } from "@reduxjs/toolkit";
2384
+ var initialState = {
2385
+ breadCrumbs: []
2386
+ };
2387
+ var breadcrumbsSlice = createSlice({
2388
+ name: "breadcrumbs",
2389
+ initialState,
2390
+ reducers: {
2391
+ setBreadCrumbs: (state, action) => {
2392
+ state.breadCrumbs = [...state.breadCrumbs, action.payload];
2393
+ }
2394
+ }
2395
+ });
2396
+ var { setBreadCrumbs } = breadcrumbsSlice.actions;
2397
+ var breadcrums_slice_default = breadcrumbsSlice.reducer;
2398
+
2399
+ // src/store/reducers/env-slice/index.ts
2400
+ import { createSlice as createSlice2 } from "@reduxjs/toolkit";
2401
+ var initialState2 = {
2402
+ baseUrl: "",
2403
+ requests: null,
2404
+ companies: [],
2405
+ user: {},
2406
+ config: null,
2407
+ envFile: null,
2408
+ defaultCompany: {
2409
+ id: null,
2410
+ logo: "",
2411
+ secondary_color: "",
2412
+ primary_color: ""
2227
2413
  },
2228
- upper() {
2229
- return this.toUpperCase();
2414
+ context: {
2415
+ uid: null,
2416
+ allowed_company_ids: [],
2417
+ lang: "vi_VN",
2418
+ tz: "Asia/Saigon"
2230
2419
  }
2231
2420
  };
2232
- function applyFunc(key, func, set, ...args) {
2233
- if (args.length === 1) {
2234
- return new Set(set);
2421
+ var envSlice = createSlice2({
2422
+ name: "env",
2423
+ initialState: initialState2,
2424
+ reducers: {
2425
+ setEnv: (state, action) => {
2426
+ Object.assign(state, action.payload);
2427
+ },
2428
+ setUid: (state, action) => {
2429
+ state.context.uid = action.payload;
2430
+ },
2431
+ setAllowCompanies: (state, action) => {
2432
+ state.context.allowed_company_ids = action.payload;
2433
+ },
2434
+ setCompanies: (state, action) => {
2435
+ state.companies = action.payload;
2436
+ },
2437
+ setDefaultCompany: (state, action) => {
2438
+ state.defaultCompany = action.payload;
2439
+ },
2440
+ setLang: (state, action) => {
2441
+ state.context.lang = action.payload;
2442
+ },
2443
+ setUser: (state, action) => {
2444
+ state.user = action.payload;
2445
+ },
2446
+ setConfig: (state, action) => {
2447
+ state.config = action.payload;
2448
+ },
2449
+ setEnvFile: (state, action) => {
2450
+ state.envFile = action.payload;
2451
+ }
2235
2452
  }
2236
- if (args.length > 2) {
2237
- throw new EvaluationError(
2238
- `${key}: py_js supports at most 1 argument, got (${args.length - 1})`
2239
- );
2453
+ });
2454
+ var {
2455
+ setEnv,
2456
+ setUid,
2457
+ setLang,
2458
+ setAllowCompanies,
2459
+ setCompanies,
2460
+ setDefaultCompany,
2461
+ setUser,
2462
+ setConfig,
2463
+ setEnvFile
2464
+ } = envSlice.actions;
2465
+ var env_slice_default = envSlice.reducer;
2466
+
2467
+ // src/store/reducers/excel-slice/index.ts
2468
+ import { createSlice as createSlice3 } from "@reduxjs/toolkit";
2469
+ var initialState3 = {
2470
+ dataParse: null,
2471
+ idFile: null,
2472
+ isFileLoaded: false,
2473
+ loadingImport: false,
2474
+ selectedFile: null,
2475
+ errorData: null
2476
+ };
2477
+ var excelSlice = createSlice3({
2478
+ name: "excel",
2479
+ initialState: initialState3,
2480
+ reducers: {
2481
+ setDataParse: (state, action) => {
2482
+ state.dataParse = action.payload;
2483
+ },
2484
+ setIdFile: (state, action) => {
2485
+ state.idFile = action.payload;
2486
+ },
2487
+ setIsFileLoaded: (state, action) => {
2488
+ state.isFileLoaded = action.payload;
2489
+ },
2490
+ setLoadingImport: (state, action) => {
2491
+ state.loadingImport = action.payload;
2492
+ },
2493
+ setSelectedFile: (state, action) => {
2494
+ state.selectedFile = action.payload;
2495
+ },
2496
+ setErrorData: (state, action) => {
2497
+ state.errorData = action.payload;
2498
+ }
2240
2499
  }
2241
- return execOnIterable(args[0], func);
2242
- }
2243
- var SET = {
2244
- intersection(...args) {
2245
- return applyFunc(
2246
- "intersection",
2247
- (iterable) => {
2248
- const intersection = /* @__PURE__ */ new Set();
2249
- for (const i of iterable) {
2250
- if (this.has(i)) {
2251
- intersection.add(i);
2252
- }
2253
- }
2254
- return intersection;
2255
- },
2256
- this,
2257
- ...args
2258
- );
2259
- },
2260
- difference(...args) {
2261
- return applyFunc(
2262
- "difference",
2263
- (iterable) => {
2264
- iterable = new Set(iterable);
2265
- const difference = /* @__PURE__ */ new Set();
2266
- for (const e of this) {
2267
- if (!iterable.has(e)) {
2268
- difference.add(e);
2269
- }
2270
- }
2271
- return difference;
2272
- },
2273
- this,
2274
- ...args
2275
- );
2500
+ });
2501
+ var {
2502
+ setDataParse,
2503
+ setIdFile,
2504
+ setIsFileLoaded,
2505
+ setLoadingImport,
2506
+ setSelectedFile,
2507
+ setErrorData
2508
+ } = excelSlice.actions;
2509
+ var excel_slice_default = excelSlice.reducer;
2510
+
2511
+ // src/store/reducers/form-slice/index.ts
2512
+ import { createSlice as createSlice4 } from "@reduxjs/toolkit";
2513
+ var initialState4 = {
2514
+ viewDataStore: {},
2515
+ isShowingModalDetail: false,
2516
+ isShowModalTranslate: false,
2517
+ formSubmitComponent: {},
2518
+ fieldTranslation: null,
2519
+ listSubject: {},
2520
+ dataUser: {}
2521
+ };
2522
+ var formSlice = createSlice4({
2523
+ name: "form",
2524
+ initialState: initialState4,
2525
+ reducers: {
2526
+ setViewDataStore: (state, action) => {
2527
+ state.viewDataStore = action.payload;
2528
+ },
2529
+ setIsShowingModalDetail: (state, action) => {
2530
+ state.isShowingModalDetail = action.payload;
2531
+ },
2532
+ setIsShowModalTranslate: (state, action) => {
2533
+ state.isShowModalTranslate = action.payload;
2534
+ },
2535
+ setFormSubmitComponent: (state, action) => {
2536
+ state.formSubmitComponent[action.payload.key] = action.payload.component;
2537
+ },
2538
+ setFieldTranslate: (state, action) => {
2539
+ state.fieldTranslation = action.payload;
2540
+ },
2541
+ setListSubject: (state, action) => {
2542
+ state.listSubject = action.payload;
2543
+ },
2544
+ setDataUser: (state, action) => {
2545
+ state.dataUser = action.payload;
2546
+ }
2547
+ }
2548
+ });
2549
+ var {
2550
+ setViewDataStore,
2551
+ setIsShowingModalDetail,
2552
+ setIsShowModalTranslate,
2553
+ setFormSubmitComponent,
2554
+ setFieldTranslate,
2555
+ setListSubject,
2556
+ setDataUser
2557
+ } = formSlice.actions;
2558
+ var form_slice_default = formSlice.reducer;
2559
+
2560
+ // src/store/reducers/header-slice/index.ts
2561
+ import { createSlice as createSlice5 } from "@reduxjs/toolkit";
2562
+ var headerSlice = createSlice5({
2563
+ name: "header",
2564
+ initialState: {
2565
+ value: { allowedCompanyIds: [] }
2276
2566
  },
2277
- union(...args) {
2278
- return applyFunc(
2279
- "union",
2280
- (iterable) => {
2281
- return /* @__PURE__ */ new Set([...this, ...iterable]);
2282
- },
2283
- this,
2284
- ...args
2285
- );
2567
+ reducers: {
2568
+ setHeader: (state, action) => {
2569
+ state.value = __spreadValues(__spreadValues({}, state.value), action.payload);
2570
+ },
2571
+ setAllowedCompanyIds: (state, action) => {
2572
+ state.value.allowedCompanyIds = action.payload;
2573
+ }
2286
2574
  }
2575
+ });
2576
+ var { setAllowedCompanyIds, setHeader } = headerSlice.actions;
2577
+ var header_slice_default = headerSlice.reducer;
2578
+
2579
+ // src/store/reducers/list-slice/index.ts
2580
+ import { createSlice as createSlice6 } from "@reduxjs/toolkit";
2581
+ var initialState5 = {
2582
+ pageLimit: 10,
2583
+ fields: {},
2584
+ order: "",
2585
+ selectedRowKeys: [],
2586
+ selectedRadioKey: 0,
2587
+ indexRowTableModal: -2,
2588
+ isUpdateTableModal: false,
2589
+ footerGroupTable: {},
2590
+ transferDetail: null,
2591
+ page: 0,
2592
+ domainTable: []
2287
2593
  };
2288
- function methods(_class) {
2289
- return Object.getOwnPropertyNames(_class.prototype).map(
2290
- (prop) => _class.prototype[prop]
2291
- );
2292
- }
2293
- var allowedFns = /* @__PURE__ */ new Set([
2294
- BUILTINS.time.strftime,
2295
- BUILTINS.set,
2296
- BUILTINS.bool,
2297
- BUILTINS.context_today,
2298
- BUILTINS.datetime.datetime.now,
2299
- BUILTINS.datetime.datetime.combine,
2300
- BUILTINS.datetime.date.today,
2301
- ...methods(BUILTINS.relativedelta),
2302
- ...Object.values(BUILTINS.datetime).flatMap((obj) => methods(obj)),
2303
- ...Object.values(SET),
2304
- ...Object.values(DICT),
2305
- ...Object.values(STRING)
2306
- ]);
2307
- var unboundFn = Symbol("unbound function");
2308
- function evaluate(ast, context = {}) {
2309
- const dicts = /* @__PURE__ */ new Set();
2310
- let pyContext;
2311
- const evalContext = Object.create(context);
2312
- if (!evalContext?.context) {
2313
- Object.defineProperty(evalContext, "context", {
2314
- get() {
2315
- if (!pyContext) {
2316
- pyContext = toPyDict(context);
2317
- }
2318
- return pyContext;
2319
- }
2320
- });
2594
+ var listSlice = createSlice6({
2595
+ name: "list",
2596
+ initialState: initialState5,
2597
+ reducers: {
2598
+ setPageLimit: (state, action) => {
2599
+ state.pageLimit = action.payload;
2600
+ },
2601
+ setFields: (state, action) => {
2602
+ state.fields = action.payload;
2603
+ },
2604
+ setOrder: (state, action) => {
2605
+ state.order = action.payload;
2606
+ },
2607
+ setSelectedRowKeys: (state, action) => {
2608
+ state.selectedRowKeys = action.payload;
2609
+ },
2610
+ setSelectedRadioKey: (state, action) => {
2611
+ state.selectedRadioKey = action.payload;
2612
+ },
2613
+ setIndexRowTableModal: (state, action) => {
2614
+ state.indexRowTableModal = action.payload;
2615
+ },
2616
+ setTransferDetail: (state, action) => {
2617
+ state.transferDetail = action.payload;
2618
+ },
2619
+ setIsUpdateTableModal: (state, action) => {
2620
+ state.isUpdateTableModal = action.payload;
2621
+ },
2622
+ setPage: (state, action) => {
2623
+ state.page = action.payload;
2624
+ },
2625
+ setDomainTable: (state, action) => {
2626
+ state.domainTable = action.payload;
2627
+ }
2321
2628
  }
2322
- function _innerEvaluate(ast2) {
2323
- switch (ast2?.type) {
2324
- case 0:
2325
- // Number
2326
- case 1:
2327
- return ast2.value;
2328
- case 5:
2329
- if (ast2.value in evalContext) {
2330
- if (typeof evalContext[ast2.value] === "object" && evalContext[ast2.value]?.id) {
2331
- return evalContext[ast2.value]?.id;
2332
- }
2333
- return evalContext[ast2.value] ?? false;
2334
- } else if (ast2.value in BUILTINS) {
2335
- return BUILTINS[ast2.value];
2336
- } else {
2337
- return false;
2338
- }
2339
- case 3:
2340
- return null;
2341
- case 2:
2342
- return ast2.value;
2343
- case 6:
2344
- return applyUnaryOp(ast2, evalContext);
2345
- case 7:
2346
- return applyBinaryOp(ast2, evalContext);
2347
- case 14:
2348
- const left = _evaluate(ast2.left);
2349
- if (ast2.op === "and") {
2350
- return isTrue(left) ? _evaluate(ast2.right) : left;
2351
- } else {
2352
- return isTrue(left) ? left : _evaluate(ast2.right);
2353
- }
2354
- case 4:
2355
- // List
2356
- case 10:
2357
- return ast2.value.map(_evaluate);
2358
- case 11:
2359
- const dict = {};
2360
- for (const key2 in ast2.value) {
2361
- dict[key2] = _evaluate(ast2.value[key2]);
2362
- }
2363
- dicts.add(dict);
2364
- return dict;
2365
- case 8:
2366
- const fnValue = _evaluate(ast2.fn);
2367
- const args = ast2.args.map(_evaluate);
2368
- const kwargs = {};
2369
- for (const kwarg in ast2.kwargs) {
2370
- kwargs[kwarg] = _evaluate(ast2?.kwargs[kwarg]);
2371
- }
2372
- if (fnValue === PyDate || fnValue === PyDateTime || fnValue === PyTime || fnValue === PyRelativeDelta || fnValue === PyTimeDelta) {
2373
- return fnValue.create(...args, kwargs);
2374
- }
2375
- return fnValue(...args, kwargs);
2376
- case 12:
2377
- const dictVal = _evaluate(ast2.target);
2378
- const key = _evaluate(ast2.key);
2379
- return dictVal[key];
2380
- case 13:
2381
- if (isTrue(_evaluate(ast2.condition))) {
2382
- return _evaluate(ast2.ifTrue);
2383
- } else {
2384
- return _evaluate(ast2.ifFalse);
2385
- }
2386
- case 15:
2387
- let leftVal = _evaluate(ast2.obj);
2388
- let result;
2389
- if (dicts.has(leftVal) || Object.isPrototypeOf.call(PY_DICT, leftVal)) {
2390
- result = DICT[ast2.key];
2391
- } else if (typeof leftVal === "string") {
2392
- result = STRING[ast2.key];
2393
- } else if (leftVal instanceof Set) {
2394
- result = SET[ast2.key];
2395
- } else if (ast2.key === "get" && typeof leftVal === "object") {
2396
- result = DICT[ast2.key];
2397
- leftVal = toPyDict(leftVal);
2398
- } else {
2399
- result = leftVal[ast2.key];
2400
- }
2401
- if (typeof result === "function") {
2402
- const bound = result.bind(leftVal);
2403
- bound[unboundFn] = result;
2404
- return bound;
2405
- }
2406
- return result;
2407
- default:
2408
- throw new EvaluationError(`AST of type ${ast2.type} cannot be evaluated`);
2629
+ });
2630
+ var {
2631
+ setPageLimit,
2632
+ setFields,
2633
+ setOrder,
2634
+ setSelectedRowKeys,
2635
+ setIndexRowTableModal,
2636
+ setIsUpdateTableModal,
2637
+ setPage,
2638
+ setSelectedRadioKey,
2639
+ setTransferDetail,
2640
+ setDomainTable
2641
+ } = listSlice.actions;
2642
+ var list_slice_default = listSlice.reducer;
2643
+
2644
+ // src/store/reducers/login-slice/index.ts
2645
+ import { createSlice as createSlice7 } from "@reduxjs/toolkit";
2646
+ var initialState6 = {
2647
+ db: "",
2648
+ redirectTo: "/",
2649
+ forgotPasswordUrl: "/"
2650
+ };
2651
+ var loginSlice = createSlice7({
2652
+ name: "login",
2653
+ initialState: initialState6,
2654
+ reducers: {
2655
+ setDb: (state, action) => {
2656
+ state.db = action.payload;
2657
+ },
2658
+ setRedirectTo: (state, action) => {
2659
+ state.redirectTo = action.payload;
2660
+ },
2661
+ setForgotPasswordUrl: (state, action) => {
2662
+ state.forgotPasswordUrl = action.payload;
2409
2663
  }
2410
2664
  }
2411
- function _evaluate(ast2) {
2412
- const val = _innerEvaluate(ast2);
2413
- if (typeof val === "function" && !allowedFns.has(val) && !allowedFns.has(val[unboundFn])) {
2414
- throw new Error("Invalid Function Call");
2665
+ });
2666
+ var { setDb, setRedirectTo, setForgotPasswordUrl } = loginSlice.actions;
2667
+ var login_slice_default = loginSlice.reducer;
2668
+
2669
+ // src/store/reducers/navbar-slice/index.ts
2670
+ import { createSlice as createSlice8 } from "@reduxjs/toolkit";
2671
+ var initialState7 = {
2672
+ menuFocus: {},
2673
+ menuAction: {},
2674
+ navbarWidth: 250,
2675
+ menuList: []
2676
+ };
2677
+ var navbarSlice = createSlice8({
2678
+ name: "navbar",
2679
+ initialState: initialState7,
2680
+ reducers: {
2681
+ setMenuFocus: (state, action) => {
2682
+ state.menuFocus = action.payload;
2683
+ },
2684
+ setMenuFocusAction: (state, action) => {
2685
+ state.menuAction = action.payload;
2686
+ },
2687
+ setNavbarWidth: (state, action) => {
2688
+ state.navbarWidth = action.payload;
2689
+ },
2690
+ setMenuList: (state, action) => {
2691
+ state.menuList = action.payload;
2415
2692
  }
2416
- return val;
2417
- }
2418
- return _evaluate(ast);
2419
- }
2420
-
2421
- // src/utils/domain/py.ts
2422
- function parseExpr(expr) {
2423
- const tokens = tokenize(expr);
2424
- return parse(tokens);
2425
- }
2426
-
2427
- // src/utils/domain/objects.ts
2428
- function shallowEqual(obj1, obj2, comparisonFn = (a, b) => a === b) {
2429
- if (!obj1 || !obj2 || typeof obj1 !== "object" || typeof obj2 !== "object") {
2430
- return obj1 === obj2;
2431
2693
  }
2432
- const obj1Keys = Object.keys(obj1);
2433
- return obj1Keys.length === Object.keys(obj2).length && obj1Keys.every((key) => comparisonFn(obj1[key], obj2[key]));
2434
- }
2435
-
2436
- // src/utils/domain/arrays.ts
2437
- var shallowEqual2 = shallowEqual;
2438
-
2439
- // src/utils/domain/strings.ts
2440
- var escapeMethod = Symbol("html");
2441
- function escapeRegExp(str) {
2442
- return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
2443
- }
2694
+ });
2695
+ var { setMenuFocus, setMenuFocusAction, setNavbarWidth, setMenuList } = navbarSlice.actions;
2696
+ var navbar_slice_default = navbarSlice.reducer;
2444
2697
 
2445
- // src/utils/domain/domain.ts
2446
- var InvalidDomainError = class extends Error {
2698
+ // src/store/reducers/profile-slice/index.ts
2699
+ import { createSlice as createSlice9 } from "@reduxjs/toolkit";
2700
+ var initialState8 = {
2701
+ profile: {}
2447
2702
  };
2448
- var Domain = class _Domain {
2449
- ast = { type: -1, value: null };
2450
- static TRUE;
2451
- static FALSE;
2452
- static combine(domains, operator) {
2453
- if (domains.length === 0) {
2454
- return new _Domain([]);
2455
- }
2456
- const domain1 = domains[0] instanceof _Domain ? domains[0] : new _Domain(domains[0]);
2457
- if (domains.length === 1) {
2458
- return domain1;
2703
+ var profileSlice = createSlice9({
2704
+ name: "profile",
2705
+ initialState: initialState8,
2706
+ reducers: {
2707
+ setProfile: (state, action) => {
2708
+ state.profile = action.payload;
2459
2709
  }
2460
- const domain2 = _Domain.combine(domains.slice(1), operator);
2461
- const result = new _Domain([]);
2462
- const astValues1 = domain1.ast.value;
2463
- const astValues2 = domain2.ast.value;
2464
- const op = operator === "AND" ? "&" : "|";
2465
- const combinedAST = {
2466
- type: 4,
2467
- value: astValues1.concat(astValues2)
2468
- };
2469
- result.ast = normalizeDomainAST(combinedAST, op);
2470
- return result;
2471
- }
2472
- static and(domains) {
2473
- return _Domain.combine(domains, "AND");
2474
- }
2475
- static or(domains) {
2476
- return _Domain.combine(domains, "OR");
2477
- }
2478
- static not(domain) {
2479
- const result = new _Domain(domain);
2480
- result.ast.value.unshift({ type: 1, value: "!" });
2481
- return result;
2482
2710
  }
2483
- static removeDomainLeaves(domain, keysToRemove) {
2484
- function processLeaf(elements, idx, operatorCtx, newDomain2) {
2485
- const leaf = elements[idx];
2486
- if (leaf.type === 10) {
2487
- if (keysToRemove.includes(leaf.value[0].value)) {
2488
- if (operatorCtx === "&") {
2489
- newDomain2.ast.value.push(..._Domain.TRUE.ast.value);
2490
- } else if (operatorCtx === "|") {
2491
- newDomain2.ast.value.push(..._Domain.FALSE.ast.value);
2492
- }
2711
+ });
2712
+ var { setProfile } = profileSlice.actions;
2713
+ var profile_slice_default = profileSlice.reducer;
2714
+
2715
+ // src/store/reducers/search-slice/index.ts
2716
+ import { createSlice as createSlice10 } from "@reduxjs/toolkit";
2717
+ var initialState9 = {
2718
+ groupByDomain: null,
2719
+ searchBy: [],
2720
+ searchString: "",
2721
+ hoveredIndexSearchList: null,
2722
+ selectedTags: [],
2723
+ firstDomain: null,
2724
+ searchMap: {},
2725
+ filterBy: [],
2726
+ groupBy: []
2727
+ };
2728
+ var searchSlice = createSlice10({
2729
+ name: "search",
2730
+ initialState: initialState9,
2731
+ reducers: {
2732
+ setGroupByDomain: (state, action) => {
2733
+ state.groupByDomain = action.payload;
2734
+ },
2735
+ setSearchBy: (state, action) => {
2736
+ state.searchBy = action.payload;
2737
+ },
2738
+ setSearchString: (state, action) => {
2739
+ state.searchString = action.payload;
2740
+ },
2741
+ setHoveredIndexSearchList: (state, action) => {
2742
+ state.hoveredIndexSearchList = action.payload;
2743
+ },
2744
+ setSelectedTags: (state, action) => {
2745
+ state.selectedTags = action.payload;
2746
+ },
2747
+ setFirstDomain: (state, action) => {
2748
+ state.firstDomain = action.payload;
2749
+ },
2750
+ setFilterBy: (state, action) => {
2751
+ state.filterBy = action.payload;
2752
+ },
2753
+ setGroupBy: (state, action) => {
2754
+ state.groupBy = action.payload;
2755
+ },
2756
+ setSearchMap: (state, action) => {
2757
+ state.searchMap = action.payload;
2758
+ },
2759
+ updateSearchMap: (state, action) => {
2760
+ if (!state.searchMap[action.payload.key]) {
2761
+ state.searchMap[action.payload.key] = [];
2762
+ }
2763
+ state.searchMap[action.payload.key].push(action.payload.value);
2764
+ },
2765
+ removeKeyFromSearchMap: (state, action) => {
2766
+ const { key, item } = action.payload;
2767
+ const values = state.searchMap[key];
2768
+ if (!values) return;
2769
+ if (item) {
2770
+ const filtered = values.filter((value) => value.name !== item.name);
2771
+ if (filtered.length > 0) {
2772
+ state.searchMap[key] = filtered;
2493
2773
  } else {
2494
- newDomain2.ast.value.push(leaf);
2495
- }
2496
- return 1;
2497
- } else if (leaf.type === 1) {
2498
- if (leaf.value === "|" && elements[idx + 1].type === 10 && elements[idx + 2].type === 10 && keysToRemove.includes(elements[idx + 1].value[0].value) && keysToRemove.includes(elements[idx + 2].value[0].value)) {
2499
- newDomain2.ast.value.push(..._Domain.TRUE.ast.value);
2500
- return 3;
2501
- }
2502
- newDomain2.ast.value.push(leaf);
2503
- if (leaf.value === "!") {
2504
- return 1 + processLeaf(elements, idx + 1, "&", newDomain2);
2774
+ delete state.searchMap[key];
2505
2775
  }
2506
- const firstLeafSkip = processLeaf(
2507
- elements,
2508
- idx + 1,
2509
- leaf.value,
2510
- newDomain2
2511
- );
2512
- const secondLeafSkip = processLeaf(
2513
- elements,
2514
- idx + 1 + firstLeafSkip,
2515
- leaf.value,
2516
- newDomain2
2517
- );
2518
- return 1 + firstLeafSkip + secondLeafSkip;
2519
- }
2520
- return 0;
2521
- }
2522
- const d = new _Domain(domain);
2523
- if (d.ast.value.length === 0) {
2524
- return d;
2525
- }
2526
- const newDomain = new _Domain([]);
2527
- processLeaf(d.ast.value, 0, "&", newDomain);
2528
- return newDomain;
2529
- }
2530
- constructor(descr = []) {
2531
- if (descr instanceof _Domain) {
2532
- return new _Domain(descr.toString());
2533
- } else {
2534
- let rawAST;
2535
- try {
2536
- rawAST = typeof descr === "string" ? parseExpr(descr) : toAST(descr);
2537
- } catch (error) {
2538
- throw new InvalidDomainError(
2539
- `Invalid domain representation: ${descr}`,
2540
- {
2541
- cause: error
2542
- }
2543
- );
2776
+ } else {
2777
+ delete state.searchMap[key];
2544
2778
  }
2545
- this.ast = normalizeDomainAST(rawAST);
2779
+ },
2780
+ clearSearchMap: (state) => {
2781
+ state.searchMap = {};
2546
2782
  }
2547
2783
  }
2548
- contains(record) {
2549
- const expr = evaluate(this.ast, record);
2550
- return matchDomain(record, expr);
2551
- }
2552
- toString() {
2553
- return formatAST(this.ast);
2554
- }
2555
- toList(context) {
2556
- return evaluate(this.ast, context);
2557
- }
2558
- toJson() {
2559
- try {
2560
- const evaluatedAsList = this.toList({});
2561
- const evaluatedDomain = new _Domain(evaluatedAsList);
2562
- if (evaluatedDomain.toString() === this.toString()) {
2563
- return evaluatedAsList;
2564
- }
2565
- return this.toString();
2566
- } catch {
2567
- return this.toString();
2568
- }
2784
+ });
2785
+ var {
2786
+ setGroupByDomain,
2787
+ setSelectedTags,
2788
+ setSearchString,
2789
+ setHoveredIndexSearchList,
2790
+ setFirstDomain,
2791
+ setSearchBy,
2792
+ setFilterBy,
2793
+ setSearchMap,
2794
+ updateSearchMap,
2795
+ removeKeyFromSearchMap,
2796
+ setGroupBy,
2797
+ clearSearchMap
2798
+ } = searchSlice.actions;
2799
+ var search_slice_default = searchSlice.reducer;
2800
+
2801
+ // src/store/store.ts
2802
+ import { configureStore } from "@reduxjs/toolkit";
2803
+
2804
+ // node_modules/redux/dist/redux.mjs
2805
+ function formatProdErrorMessage(code) {
2806
+ return `Minified Redux error #${code}; visit https://redux.js.org/Errors?code=${code} for the full message or use the non-minified dev environment for full errors. `;
2807
+ }
2808
+ var randomString = () => Math.random().toString(36).substring(7).split("").join(".");
2809
+ var ActionTypes = {
2810
+ INIT: `@@redux/INIT${/* @__PURE__ */ randomString()}`,
2811
+ REPLACE: `@@redux/REPLACE${/* @__PURE__ */ randomString()}`,
2812
+ PROBE_UNKNOWN_ACTION: () => `@@redux/PROBE_UNKNOWN_ACTION${randomString()}`
2813
+ };
2814
+ var actionTypes_default = ActionTypes;
2815
+ function isPlainObject(obj) {
2816
+ if (typeof obj !== "object" || obj === null)
2817
+ return false;
2818
+ let proto = obj;
2819
+ while (Object.getPrototypeOf(proto) !== null) {
2820
+ proto = Object.getPrototypeOf(proto);
2569
2821
  }
2570
- };
2571
- var TRUE_LEAF = [1, "=", 1];
2572
- var FALSE_LEAF = [0, "=", 1];
2573
- var TRUE_DOMAIN = new Domain([TRUE_LEAF]);
2574
- var FALSE_DOMAIN = new Domain([FALSE_LEAF]);
2575
- Domain.TRUE = TRUE_DOMAIN;
2576
- Domain.FALSE = FALSE_DOMAIN;
2577
- function toAST(domain) {
2578
- const elems = domain.map((elem) => {
2579
- switch (elem) {
2580
- case "!":
2581
- case "&":
2582
- case "|":
2583
- return { type: 1, value: elem };
2584
- default:
2585
- return {
2586
- type: 10,
2587
- value: elem.map(toPyValue)
2588
- };
2589
- }
2590
- });
2591
- return { type: 4, value: elems };
2822
+ return Object.getPrototypeOf(obj) === proto || Object.getPrototypeOf(obj) === null;
2592
2823
  }
2593
- function normalizeDomainAST(domain, op = "&") {
2594
- if (domain.type !== 4) {
2595
- if (domain.type === 10) {
2596
- const value = domain.value;
2597
- if (value.findIndex((e) => e.type === 10) === -1 || !value.every((e) => e.type === 10 || e.type === 1)) {
2598
- throw new InvalidDomainError("Invalid domain AST");
2599
- }
2600
- } else {
2601
- throw new InvalidDomainError("Invalid domain AST");
2824
+ function miniKindOf(val) {
2825
+ if (val === void 0)
2826
+ return "undefined";
2827
+ if (val === null)
2828
+ return "null";
2829
+ const type = typeof val;
2830
+ switch (type) {
2831
+ case "boolean":
2832
+ case "string":
2833
+ case "number":
2834
+ case "symbol":
2835
+ case "function": {
2836
+ return type;
2602
2837
  }
2603
2838
  }
2604
- if (domain.value.length === 0) {
2605
- return domain;
2839
+ if (Array.isArray(val))
2840
+ return "array";
2841
+ if (isDate(val))
2842
+ return "date";
2843
+ if (isError(val))
2844
+ return "error";
2845
+ const constructorName = ctorName(val);
2846
+ switch (constructorName) {
2847
+ case "Symbol":
2848
+ case "Promise":
2849
+ case "WeakMap":
2850
+ case "WeakSet":
2851
+ case "Map":
2852
+ case "Set":
2853
+ return constructorName;
2606
2854
  }
2607
- let expected = 1;
2608
- for (const child of domain.value) {
2609
- switch (child.type) {
2610
- case 1:
2611
- if (child.value === "&" || child.value === "|") {
2612
- expected++;
2613
- } else if (child.value !== "!") {
2614
- throw new InvalidDomainError("Invalid domain AST");
2615
- }
2616
- break;
2617
- case 4:
2618
- /* list */
2619
- case 10:
2620
- if (child.value.length === 3) {
2621
- expected--;
2622
- break;
2623
- }
2624
- throw new InvalidDomainError("Invalid domain AST");
2625
- default:
2626
- throw new InvalidDomainError("Invalid domain AST");
2627
- }
2855
+ return Object.prototype.toString.call(val).slice(8, -1).toLowerCase().replace(/\s/g, "");
2856
+ }
2857
+ function ctorName(val) {
2858
+ return typeof val.constructor === "function" ? val.constructor.name : null;
2859
+ }
2860
+ function isError(val) {
2861
+ return val instanceof Error || typeof val.message === "string" && val.constructor && typeof val.constructor.stackTraceLimit === "number";
2862
+ }
2863
+ function isDate(val) {
2864
+ if (val instanceof Date)
2865
+ return true;
2866
+ return typeof val.toDateString === "function" && typeof val.getDate === "function" && typeof val.setDate === "function";
2867
+ }
2868
+ function kindOf(val) {
2869
+ let typeOfVal = typeof val;
2870
+ if (process.env.NODE_ENV !== "production") {
2871
+ typeOfVal = miniKindOf(val);
2628
2872
  }
2629
- const values = domain.value.slice();
2630
- while (expected < 0) {
2631
- expected++;
2632
- values.unshift({ type: 1, value: op });
2873
+ return typeOfVal;
2874
+ }
2875
+ function warning(message) {
2876
+ if (typeof console !== "undefined" && typeof console.error === "function") {
2877
+ console.error(message);
2633
2878
  }
2634
- if (expected > 0) {
2635
- throw new InvalidDomainError(
2636
- `invalid domain ${formatAST(domain)} (missing ${expected} segment(s))`
2637
- );
2879
+ try {
2880
+ throw new Error(message);
2881
+ } catch (e) {
2638
2882
  }
2639
- return { type: 4, value: values };
2640
2883
  }
2641
- function matchCondition(record, condition) {
2642
- if (typeof condition === "boolean") {
2643
- return condition;
2644
- }
2645
- const [field, operator, value] = condition;
2646
- if (typeof field === "string") {
2647
- const names = field.split(".");
2648
- if (names.length >= 2) {
2649
- return matchCondition(record[names[0]], [
2650
- names.slice(1).join("."),
2651
- operator,
2652
- value
2653
- ]);
2654
- }
2884
+ function getUnexpectedStateShapeWarningMessage(inputState, reducers, action, unexpectedKeyCache) {
2885
+ const reducerKeys = Object.keys(reducers);
2886
+ const argumentName = action && action.type === actionTypes_default.INIT ? "preloadedState argument passed to createStore" : "previous state received by the reducer";
2887
+ if (reducerKeys.length === 0) {
2888
+ return "Store does not have a valid reducer. Make sure the argument passed to combineReducers is an object whose values are reducers.";
2655
2889
  }
2656
- let likeRegexp, ilikeRegexp;
2657
- if (["like", "not like", "ilike", "not ilike"].includes(operator)) {
2658
- likeRegexp = new RegExp(
2659
- `(.*)${escapeRegExp(value).replaceAll("%", "(.*)")}(.*)`,
2660
- "g"
2661
- );
2662
- ilikeRegexp = new RegExp(
2663
- `(.*)${escapeRegExp(value).replaceAll("%", "(.*)")}(.*)`,
2664
- "gi"
2665
- );
2890
+ if (!isPlainObject(inputState)) {
2891
+ return `The ${argumentName} has unexpected type of "${kindOf(inputState)}". Expected argument to be an object with the following keys: "${reducerKeys.join('", "')}"`;
2666
2892
  }
2667
- const fieldValue = typeof field === "number" ? field : record[field];
2668
- switch (operator) {
2669
- case "=?":
2670
- if ([false, null].includes(value)) {
2671
- return true;
2672
- }
2673
- // eslint-disable-next-line no-fallthrough
2674
- case "=":
2675
- case "==":
2676
- if (Array.isArray(fieldValue) && Array.isArray(value)) {
2677
- return shallowEqual2(fieldValue, value);
2678
- }
2679
- return fieldValue === value;
2680
- case "!=":
2681
- case "<>":
2682
- return !matchCondition(record, [field, "==", value]);
2683
- case "<":
2684
- return fieldValue < value;
2685
- case "<=":
2686
- return fieldValue <= value;
2687
- case ">":
2688
- return fieldValue > value;
2689
- case ">=":
2690
- return fieldValue >= value;
2691
- case "in": {
2692
- const val = Array.isArray(value) ? value : [value];
2693
- const fieldVal = Array.isArray(fieldValue) ? fieldValue : [fieldValue];
2694
- return fieldVal.some((fv) => val.includes(fv));
2695
- }
2696
- case "not in": {
2697
- const val = Array.isArray(value) ? value : [value];
2698
- const fieldVal = Array.isArray(fieldValue) ? fieldValue : [fieldValue];
2699
- return !fieldVal.some((fv) => val.includes(fv));
2700
- }
2701
- case "like":
2702
- if (fieldValue === false) {
2703
- return false;
2704
- }
2705
- return Boolean(fieldValue.match(likeRegexp));
2706
- case "not like":
2707
- if (fieldValue === false) {
2708
- return false;
2709
- }
2710
- return Boolean(!fieldValue.match(likeRegexp));
2711
- case "=like":
2712
- if (fieldValue === false) {
2713
- return false;
2714
- }
2715
- return new RegExp(escapeRegExp(value).replace(/%/g, ".*")).test(
2716
- fieldValue
2717
- );
2718
- case "ilike":
2719
- if (fieldValue === false) {
2720
- return false;
2721
- }
2722
- return Boolean(fieldValue.match(ilikeRegexp));
2723
- case "not ilike":
2724
- if (fieldValue === false) {
2725
- return false;
2726
- }
2727
- return Boolean(!fieldValue.match(ilikeRegexp));
2728
- case "=ilike":
2729
- if (fieldValue === false) {
2730
- return false;
2731
- }
2732
- return new RegExp(escapeRegExp(value).replace(/%/g, ".*"), "i").test(
2733
- fieldValue
2734
- );
2893
+ const unexpectedKeys = Object.keys(inputState).filter((key) => !reducers.hasOwnProperty(key) && !unexpectedKeyCache[key]);
2894
+ unexpectedKeys.forEach((key) => {
2895
+ unexpectedKeyCache[key] = true;
2896
+ });
2897
+ if (action && action.type === actionTypes_default.REPLACE)
2898
+ return;
2899
+ if (unexpectedKeys.length > 0) {
2900
+ return `Unexpected ${unexpectedKeys.length > 1 ? "keys" : "key"} "${unexpectedKeys.join('", "')}" found in ${argumentName}. Expected to find one of the known reducer keys instead: "${reducerKeys.join('", "')}". Unexpected keys will be ignored.`;
2735
2901
  }
2736
- throw new InvalidDomainError("could not match domain");
2737
- }
2738
- function makeOperators(record) {
2739
- const match = matchCondition.bind(null, record);
2740
- return {
2741
- "!": (x) => !match(x),
2742
- "&": (a, b) => match(a) && match(b),
2743
- "|": (a, b) => match(a) || match(b)
2744
- };
2745
2902
  }
2746
- function matchDomain(record, domain) {
2747
- if (domain.length === 0) {
2748
- return true;
2749
- }
2750
- const operators = makeOperators(record);
2751
- const reversedDomain = Array.from(domain).reverse();
2752
- const condStack = [];
2753
- for (const item of reversedDomain) {
2754
- const operator = typeof item === "string" && operators[item];
2755
- if (operator) {
2756
- const operands = condStack.splice(-operator.length);
2757
- condStack.push(operator(...operands));
2758
- } else {
2759
- condStack.push(item);
2903
+ function assertReducerShape(reducers) {
2904
+ Object.keys(reducers).forEach((key) => {
2905
+ const reducer = reducers[key];
2906
+ const initialState10 = reducer(void 0, {
2907
+ type: actionTypes_default.INIT
2908
+ });
2909
+ if (typeof initialState10 === "undefined") {
2910
+ throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(12) : `The slice reducer for key "${key}" returned undefined during initialization. If the state passed to the reducer is undefined, you must explicitly return the initial state. The initial state may not be undefined. If you don't want to set a value for this reducer, you can use null instead of undefined.`);
2911
+ }
2912
+ if (typeof reducer(void 0, {
2913
+ type: actionTypes_default.PROBE_UNKNOWN_ACTION()
2914
+ }) === "undefined") {
2915
+ throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(13) : `The slice reducer for key "${key}" returned undefined when probed with a random type. Don't try to handle '${actionTypes_default.INIT}' or other actions in "redux/*" namespace. They are considered private. Instead, you must return the current state for any unknown actions, unless it is undefined, in which case you must return the initial state, regardless of the action type. The initial state may not be undefined, but can be null.`);
2760
2916
  }
2761
- }
2762
- return matchCondition(record, condStack.pop());
2917
+ });
2763
2918
  }
2764
-
2765
- // src/utils/function.ts
2766
- var import_react = require("react");
2767
- var updateTokenParamInOriginalRequest = (originalRequest, newAccessToken) => {
2768
- if (!originalRequest.data) return originalRequest.data;
2769
- if (typeof originalRequest.data === "string") {
2770
- try {
2771
- const parsedData = JSON.parse(originalRequest.data);
2772
- if (parsedData.with_context && typeof parsedData.with_context === "object") {
2773
- parsedData.with_context.token = newAccessToken;
2919
+ function combineReducers(reducers) {
2920
+ const reducerKeys = Object.keys(reducers);
2921
+ const finalReducers = {};
2922
+ for (let i = 0; i < reducerKeys.length; i++) {
2923
+ const key = reducerKeys[i];
2924
+ if (process.env.NODE_ENV !== "production") {
2925
+ if (typeof reducers[key] === "undefined") {
2926
+ warning(`No reducer provided for key "${key}"`);
2774
2927
  }
2775
- return JSON.stringify(parsedData);
2776
- } catch (e) {
2777
- console.warn("Failed to parse originalRequest.data", e);
2778
- return originalRequest.data;
2928
+ }
2929
+ if (typeof reducers[key] === "function") {
2930
+ finalReducers[key] = reducers[key];
2779
2931
  }
2780
2932
  }
2781
- if (typeof originalRequest.data === "object" && originalRequest.data.with_context) {
2782
- originalRequest.data.with_context.token = newAccessToken;
2933
+ const finalReducerKeys = Object.keys(finalReducers);
2934
+ let unexpectedKeyCache;
2935
+ if (process.env.NODE_ENV !== "production") {
2936
+ unexpectedKeyCache = {};
2783
2937
  }
2784
- return originalRequest.data;
2785
- };
2786
-
2787
- // src/utils/storage/local-storage.ts
2788
- var localStorageUtils = () => {
2789
- const setToken = async (access_token) => {
2790
- localStorage.setItem("accessToken", access_token);
2791
- };
2792
- const setRefreshToken = async (refresh_token) => {
2793
- localStorage.setItem("refreshToken", refresh_token);
2794
- };
2795
- const getAccessToken = async () => {
2796
- return localStorage.getItem("accessToken");
2797
- };
2798
- const getRefreshToken = async () => {
2799
- return localStorage.getItem("refreshToken");
2800
- };
2801
- const clearToken = async () => {
2802
- localStorage.removeItem("accessToken");
2803
- localStorage.removeItem("refreshToken");
2804
- };
2805
- return {
2806
- setToken,
2807
- setRefreshToken,
2808
- getAccessToken,
2809
- getRefreshToken,
2810
- clearToken
2811
- };
2812
- };
2813
-
2814
- // src/utils/storage/session-storage.ts
2815
- var sessionStorageUtils = () => {
2816
- const getBrowserSession = async () => {
2817
- return sessionStorage.getItem("browserSession");
2818
- };
2819
- return {
2820
- getBrowserSession
2821
- };
2822
- };
2823
-
2824
- // src/configs/axios-client.ts
2825
- var axiosClient = {
2826
- init(config) {
2827
- const localStorage2 = config.localStorageUtils ?? localStorageUtils();
2828
- const sessionStorage2 = config.sessionStorageUtils ?? sessionStorageUtils();
2829
- const db = config.db;
2830
- let isRefreshing = false;
2831
- let failedQueue = [];
2832
- const processQueue = (error, token = null) => {
2833
- failedQueue?.forEach((prom) => {
2834
- if (error) {
2835
- prom.reject(error);
2836
- } else {
2837
- prom.resolve(token);
2838
- }
2839
- });
2840
- failedQueue = [];
2841
- };
2842
- const instance = import_axios.default.create({
2843
- adapter: import_axios.default.defaults.adapter,
2844
- baseURL: config.baseUrl,
2845
- timeout: 5e4,
2846
- paramsSerializer: (params) => new URLSearchParams(params).toString()
2847
- });
2848
- instance.interceptors.request.use(async (config2) => {
2849
- const { useRefreshToken, useActionToken, actionToken } = config2;
2850
- if (useActionToken && actionToken) {
2851
- config2.headers["Action-Token"] = actionToken;
2852
- }
2853
- const getToken = useRefreshToken ? localStorage2.getRefreshToken : localStorage2.getAccessToken;
2854
- const token = await getToken?.();
2855
- if (token) config2.headers["Authorization"] = `Bearer ${token}`;
2856
- return config2;
2857
- }, Promise.reject);
2858
- instance.interceptors.response.use(
2859
- (response) => {
2860
- return handleResponse(response);
2861
- },
2862
- async (error) => {
2863
- const handleError3 = async (error2) => {
2864
- if (!error2.response) {
2865
- return error2;
2866
- }
2867
- const { data } = error2.response;
2868
- if (data && data.code === 400 && ["invalid_grant"].includes(data.data?.error)) {
2869
- await clearAuthToken();
2870
- }
2871
- return data;
2872
- };
2873
- const originalRequest = error.config;
2874
- if ((error.response?.status === 403 || error.response?.status === 401 || error.response?.status === 404) && ["TOKEN_EXPIRED", "AUTHEN_FAIL", 401, "ERR_2FA_006"].includes(
2875
- error.response.data.code
2876
- )) {
2877
- if (isRefreshing) {
2878
- return new Promise(function(resolve, reject) {
2879
- failedQueue.push({ resolve, reject });
2880
- }).then((token) => {
2881
- originalRequest.headers["Authorization"] = "Bearer " + token;
2882
- originalRequest.data = updateTokenParamInOriginalRequest(
2883
- originalRequest,
2884
- token
2885
- );
2886
- return instance.request(originalRequest);
2887
- }).catch(async (err) => {
2888
- if ((err.response?.status === 400 || err.response?.status === 401) && ["invalid_grant"].includes(err.response.data.error)) {
2889
- await clearAuthToken();
2890
- }
2891
- });
2892
- }
2893
- const browserSession = await sessionStorage2.getBrowserSession();
2894
- const refreshToken = await localStorage2.getRefreshToken();
2895
- const accessTokenExp = await localStorage2.getAccessToken();
2896
- isRefreshing = true;
2897
- if (!refreshToken && (!browserSession || browserSession == "unActive")) {
2898
- await clearAuthToken();
2899
- } else {
2900
- const payload = Object.fromEntries(
2901
- Object.entries({
2902
- refresh_token: refreshToken,
2903
- grant_type: "refresh_token",
2904
- client_id: config.config.clientId,
2905
- client_secret: config.config.clientSecret
2906
- }).filter(([_, value]) => !!value)
2907
- );
2908
- return new Promise(function(resolve) {
2909
- import_axios.default.post(
2910
- `${config.baseUrl}${config.refreshTokenEndpoint ?? "/authentication/oauth2/token" /* AUTH_TOKEN_PATH */}`,
2911
- payload,
2912
- {
2913
- headers: {
2914
- "Content-Type": config.refreshTokenEndpoint ? "application/x-www-form-urlencoded" : "multipart/form-data",
2915
- Authorization: `Bearer ${accessTokenExp}`
2916
- }
2917
- }
2918
- ).then(async (res) => {
2919
- const data = res.data;
2920
- await localStorage2.setToken(data.access_token);
2921
- await localStorage2.setRefreshToken(data.refresh_token);
2922
- import_axios.default.defaults.headers.common["Authorization"] = "Bearer " + data.access_token;
2923
- originalRequest.headers["Authorization"] = "Bearer " + data.access_token;
2924
- originalRequest.data = updateTokenParamInOriginalRequest(
2925
- originalRequest,
2926
- data.access_token
2927
- );
2928
- processQueue(null, data.access_token);
2929
- resolve(instance.request(originalRequest));
2930
- }).catch(async (err) => {
2931
- if (err && (err?.error_code === "AUTHEN_FAIL" || err?.error_code === "TOKEN_EXPIRED" || err?.error_code === "TOKEN_INCORRECT" || err?.code === "ERR_BAD_REQUEST") || err?.error_code === "ERR_2FA_006") {
2932
- await clearAuthToken();
2933
- }
2934
- if (err && err.response) {
2935
- const { error_code } = err.response?.data || {};
2936
- if (error_code === "AUTHEN_FAIL") {
2937
- await clearAuthToken();
2938
- }
2939
- }
2940
- processQueue(err, null);
2941
- }).finally(() => {
2942
- isRefreshing = false;
2943
- });
2944
- });
2945
- }
2946
- }
2947
- return Promise.reject(await handleError3(error));
2948
- }
2949
- );
2950
- const handleResponse = (res) => {
2951
- if (res && res.data) {
2952
- return res.data;
2953
- }
2954
- return res;
2955
- };
2956
- const handleError2 = (error) => {
2957
- if (error.isAxiosError && error.code === "ECONNABORTED") {
2958
- console.error("Request Timeout Error:", error);
2959
- return "Request Timeout Error";
2960
- } else if (error.isAxiosError && !error.response) {
2961
- console.error("Network Error:", error);
2962
- return "Network Error";
2963
- } else {
2964
- console.error("Other Error:", error?.response);
2965
- const errorMessage = error?.response?.data?.message || "An error occurred";
2966
- return { message: errorMessage, status: error?.response?.status };
2938
+ let shapeAssertionError;
2939
+ try {
2940
+ assertReducerShape(finalReducers);
2941
+ } catch (e) {
2942
+ shapeAssertionError = e;
2943
+ }
2944
+ return function combination(state = {}, action) {
2945
+ if (shapeAssertionError) {
2946
+ throw shapeAssertionError;
2947
+ }
2948
+ if (process.env.NODE_ENV !== "production") {
2949
+ const warningMessage = getUnexpectedStateShapeWarningMessage(state, finalReducers, action, unexpectedKeyCache);
2950
+ if (warningMessage) {
2951
+ warning(warningMessage);
2967
2952
  }
2968
- };
2969
- const clearAuthToken = async () => {
2970
- await localStorage2.clearToken();
2971
- if (typeof window !== "undefined") {
2972
- window.location.href = `/login`;
2953
+ }
2954
+ let hasChanged = false;
2955
+ const nextState = {};
2956
+ for (let i = 0; i < finalReducerKeys.length; i++) {
2957
+ const key = finalReducerKeys[i];
2958
+ const reducer = finalReducers[key];
2959
+ const previousStateForKey = state[key];
2960
+ const nextStateForKey = reducer(previousStateForKey, action);
2961
+ if (typeof nextStateForKey === "undefined") {
2962
+ const actionType = action && action.type;
2963
+ throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(14) : `When called with an action of type ${actionType ? `"${String(actionType)}"` : "(unknown type)"}, the slice reducer for key "${key}" returned undefined. To ignore an action, you must explicitly return the previous state. If you want this reducer to hold no value, you can return null instead of undefined.`);
2973
2964
  }
2974
- };
2975
- function formatUrl(url, db2) {
2976
- return url + (db2 ? "?db=" + db2 : "");
2965
+ nextState[key] = nextStateForKey;
2966
+ hasChanged = hasChanged || nextStateForKey !== previousStateForKey;
2977
2967
  }
2978
- const responseBody = (response) => response;
2979
- const requests = {
2980
- get: (url, headers) => instance.get(formatUrl(url, db), headers).then(responseBody),
2981
- post: (url, body, headers) => instance.post(formatUrl(url, db), body, headers).then(responseBody),
2982
- post_excel: (url, body, headers) => instance.post(formatUrl(url, db), body, {
2983
- responseType: "arraybuffer",
2984
- headers: {
2985
- "Content-Type": typeof window !== "undefined" ? "application/json" : "application/javascript",
2986
- Accept: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
2987
- }
2988
- }).then(responseBody),
2989
- put: (url, body, headers) => instance.put(formatUrl(url, db), body, headers).then(responseBody),
2990
- patch: (url, body) => instance.patch(formatUrl(url, db), body).then(responseBody),
2991
- delete: (url, body) => instance.delete(formatUrl(url, db), body).then(responseBody)
2992
- };
2993
- return requests;
2994
- }
2995
- };
2968
+ hasChanged = hasChanged || finalReducerKeys.length !== Object.keys(state).length;
2969
+ return hasChanged ? nextState : state;
2970
+ };
2971
+ }
2996
2972
 
2997
- // src/store/index.ts
2998
- var import_react_redux = require("react-redux");
2973
+ // src/store/store.ts
2974
+ var rootReducer = combineReducers({
2975
+ env: env_slice_default,
2976
+ header: header_slice_default,
2977
+ navbar: navbar_slice_default,
2978
+ list: list_slice_default,
2979
+ search: search_slice_default,
2980
+ form: form_slice_default,
2981
+ breadcrumbs: breadcrums_slice_default,
2982
+ login: login_slice_default,
2983
+ excel: excel_slice_default,
2984
+ profile: profile_slice_default
2985
+ });
2986
+ var envStore = configureStore({
2987
+ reducer: rootReducer,
2988
+ middleware: (getDefaultMiddleware) => getDefaultMiddleware({
2989
+ serializableCheck: false
2990
+ })
2991
+ });
2999
2992
 
3000
2993
  // src/environment/EnvStore.ts
3001
- var EnvStore = class {
3002
- baseUrl;
3003
- requests;
3004
- context;
3005
- defaultCompany;
3006
- config;
3007
- companies;
3008
- user;
3009
- db;
3010
- localStorageUtils;
3011
- sessionStorageUtils;
3012
- refreshTokenEndpoint;
3013
- constructor(localStorageUtils2, sessionStorageUtils2) {
2994
+ var _EnvStore = class _EnvStore {
2995
+ constructor(envStore2, localStorageUtils2, sessionStorageUtils2) {
2996
+ this.envStore = envStore2;
3014
2997
  this.localStorageUtils = localStorageUtils2;
3015
2998
  this.sessionStorageUtils = sessionStorageUtils2;
3016
2999
  this.setup();
3017
3000
  }
3001
+ static getInstance(envStore2, localStorageUtils2, sessionStorageUtils2) {
3002
+ if (!_EnvStore.instance) {
3003
+ _EnvStore.instance = new _EnvStore(
3004
+ envStore2,
3005
+ localStorageUtils2,
3006
+ sessionStorageUtils2
3007
+ );
3008
+ }
3009
+ return _EnvStore.instance;
3010
+ }
3018
3011
  setup() {
3019
- const env2 = envStore.getState().env;
3020
- this.baseUrl = env2?.baseUrl;
3021
- this.context = env2?.context;
3022
- this.defaultCompany = env2?.defaultCompany;
3023
- this.config = env2?.config;
3024
- this.companies = env2?.companies || [];
3025
- this.user = env2?.user;
3026
- this.db = env2?.db;
3027
- this.requests = env2?.requests;
3028
- this.refreshTokenEndpoint = env2?.refreshTokenEndpoint;
3012
+ const env = this.envStore.getState().env;
3013
+ this.baseUrl = env == null ? void 0 : env.baseUrl;
3014
+ this.requests = env == null ? void 0 : env.requests;
3015
+ this.context = env == null ? void 0 : env.context;
3016
+ this.defaultCompany = env == null ? void 0 : env.defaultCompany;
3017
+ this.config = env == null ? void 0 : env.config;
3018
+ this.companies = (env == null ? void 0 : env.companies) || [];
3019
+ this.user = env == null ? void 0 : env.user;
3020
+ this.db = env == null ? void 0 : env.db;
3021
+ this.refreshTokenEndpoint = env == null ? void 0 : env.refreshTokenEndpoint;
3022
+ console.log("Env setup:", this);
3029
3023
  }
3030
3024
  setupEnv(envConfig) {
3031
- let env2 = {
3032
- ...envConfig,
3025
+ const dispatch = this.envStore.dispatch;
3026
+ const env = __spreadProps(__spreadValues({}, envConfig), {
3033
3027
  localStorageUtils: this.localStorageUtils,
3034
3028
  sessionStorageUtils: this.sessionStorageUtils
3035
- };
3036
- const requests = axiosClient.init(env2);
3037
- this.requests = requests;
3038
- const dispatch = envStore.dispatch;
3039
- dispatch(
3040
- setEnv({
3041
- ...env2,
3042
- requests
3043
- })
3044
- );
3029
+ });
3030
+ const requests = axiosClient.init(env);
3031
+ dispatch(setEnv(__spreadProps(__spreadValues({}, env), { requests })));
3045
3032
  this.setup();
3046
- return { ...env2, requests };
3047
3033
  }
3048
3034
  setUid(uid) {
3049
- const dispatch = envStore.dispatch;
3035
+ const dispatch = this.envStore.dispatch;
3050
3036
  dispatch(setUid(uid));
3051
3037
  this.setup();
3052
3038
  }
3053
3039
  setLang(lang) {
3054
- const dispatch = envStore.dispatch;
3040
+ const dispatch = this.envStore.dispatch;
3055
3041
  dispatch(setLang(lang));
3056
3042
  this.setup();
3057
3043
  }
3058
3044
  setAllowCompanies(allowCompanies) {
3059
- const dispatch = envStore.dispatch;
3045
+ const dispatch = this.envStore.dispatch;
3060
3046
  dispatch(setAllowCompanies(allowCompanies));
3061
3047
  this.setup();
3062
3048
  }
3063
3049
  setCompanies(companies) {
3064
- const dispatch = envStore.dispatch;
3050
+ const dispatch = this.envStore.dispatch;
3065
3051
  dispatch(setCompanies(companies));
3066
3052
  this.setup();
3067
3053
  }
3068
3054
  setDefaultCompany(company) {
3069
- const dispatch = envStore.dispatch;
3055
+ const dispatch = this.envStore.dispatch;
3070
3056
  dispatch(setDefaultCompany(company));
3071
3057
  this.setup();
3072
3058
  }
3073
3059
  setUserInfo(userInfo) {
3074
- const dispatch = envStore.dispatch;
3060
+ const dispatch = this.envStore.dispatch;
3075
3061
  dispatch(setUser(userInfo));
3076
3062
  this.setup();
3077
3063
  }
3078
3064
  };
3079
- var env = null;
3065
+ _EnvStore.instance = null;
3066
+ var EnvStore = _EnvStore;
3080
3067
  function initEnv({
3081
3068
  localStorageUtils: localStorageUtils2,
3082
3069
  sessionStorageUtils: sessionStorageUtils2
3083
3070
  }) {
3084
- env = new EnvStore(localStorageUtils2, sessionStorageUtils2);
3085
- return env;
3071
+ return EnvStore.getInstance(envStore, localStorageUtils2, sessionStorageUtils2);
3086
3072
  }
3087
3073
  function getEnv() {
3088
- if (!env) env = new EnvStore(localStorageUtils(), sessionStorageUtils());
3089
- return env;
3074
+ const instance = EnvStore.getInstance(envStore);
3075
+ if (!instance) {
3076
+ throw new Error("EnvStore has not been initialized \u2014 call initEnv() first");
3077
+ }
3078
+ return instance;
3090
3079
  }
3091
- // Annotate the CommonJS export names for ESM import in node:
3092
- 0 && (module.exports = {
3080
+ export {
3093
3081
  EnvStore,
3094
- env,
3095
3082
  getEnv,
3096
3083
  initEnv
3097
- });
3084
+ };