@budibase/shared-core 2.9.18 → 2.9.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.d.ts +93 -0
- package/dist/filters.d.ts +94 -0
- package/dist/helpers/helpers.d.ts +29 -0
- package/dist/helpers/index.d.ts +2 -0
- package/dist/helpers/integrations.d.ts +3 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +746 -0
- package/dist/index.js.map +7 -0
- package/dist/index.js.meta.json +1 -0
- package/dist/sdk/documents/applications.d.ts +5 -0
- package/dist/sdk/documents/index.d.ts +2 -0
- package/dist/sdk/documents/users.d.ts +8 -0
- package/dist/sdk/index.d.ts +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/utils.d.ts +2 -0
- package/package.json +3 -3
- package/tsconfig.build.json +0 -28
- package/tsconfig.json +0 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,746 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
BuilderSocketEvent: () => BuilderSocketEvent,
|
|
24
|
+
GridSocketEvent: () => GridSocketEvent,
|
|
25
|
+
OperatorOptions: () => OperatorOptions,
|
|
26
|
+
SocketEvent: () => SocketEvent,
|
|
27
|
+
SocketSessionTTL: () => SocketSessionTTL,
|
|
28
|
+
SqlNumberTypeRangeMap: () => SqlNumberTypeRangeMap,
|
|
29
|
+
ValidColumnNameRegex: () => ValidColumnNameRegex,
|
|
30
|
+
ValidQueryNameRegex: () => ValidQueryNameRegex,
|
|
31
|
+
dataFilters: () => filters_exports,
|
|
32
|
+
helpers: () => helpers_exports,
|
|
33
|
+
sdk: () => sdk_exports,
|
|
34
|
+
utils: () => utils_exports
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(src_exports);
|
|
37
|
+
|
|
38
|
+
// src/constants.ts
|
|
39
|
+
var OperatorOptions = {
|
|
40
|
+
Equals: {
|
|
41
|
+
value: "equal",
|
|
42
|
+
label: "Equals"
|
|
43
|
+
},
|
|
44
|
+
NotEquals: {
|
|
45
|
+
value: "notEqual",
|
|
46
|
+
label: "Not equals"
|
|
47
|
+
},
|
|
48
|
+
Empty: {
|
|
49
|
+
value: "empty",
|
|
50
|
+
label: "Is empty"
|
|
51
|
+
},
|
|
52
|
+
NotEmpty: {
|
|
53
|
+
value: "notEmpty",
|
|
54
|
+
label: "Is not empty"
|
|
55
|
+
},
|
|
56
|
+
StartsWith: {
|
|
57
|
+
value: "string",
|
|
58
|
+
label: "Starts with"
|
|
59
|
+
},
|
|
60
|
+
Like: {
|
|
61
|
+
value: "fuzzy",
|
|
62
|
+
label: "Like"
|
|
63
|
+
},
|
|
64
|
+
MoreThan: {
|
|
65
|
+
value: "rangeLow",
|
|
66
|
+
label: "More than or equal to"
|
|
67
|
+
},
|
|
68
|
+
LessThan: {
|
|
69
|
+
value: "rangeHigh",
|
|
70
|
+
label: "Less than or equal to"
|
|
71
|
+
},
|
|
72
|
+
Contains: {
|
|
73
|
+
value: "contains",
|
|
74
|
+
label: "Contains"
|
|
75
|
+
},
|
|
76
|
+
NotContains: {
|
|
77
|
+
value: "notContains",
|
|
78
|
+
label: "Does not contain"
|
|
79
|
+
},
|
|
80
|
+
In: {
|
|
81
|
+
value: "oneOf",
|
|
82
|
+
label: "Is in"
|
|
83
|
+
},
|
|
84
|
+
ContainsAny: {
|
|
85
|
+
value: "containsAny",
|
|
86
|
+
label: "Has any"
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
var SqlNumberTypeRangeMap = {
|
|
90
|
+
integer: {
|
|
91
|
+
max: 2147483647,
|
|
92
|
+
min: -2147483648
|
|
93
|
+
},
|
|
94
|
+
int: {
|
|
95
|
+
max: 2147483647,
|
|
96
|
+
min: -2147483648
|
|
97
|
+
},
|
|
98
|
+
smallint: {
|
|
99
|
+
max: 32767,
|
|
100
|
+
min: -32768
|
|
101
|
+
},
|
|
102
|
+
mediumint: {
|
|
103
|
+
max: 8388607,
|
|
104
|
+
min: -8388608
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
var SocketEvent = /* @__PURE__ */ ((SocketEvent2) => {
|
|
108
|
+
SocketEvent2["UserUpdate"] = "UserUpdate";
|
|
109
|
+
SocketEvent2["UserDisconnect"] = "UserDisconnect";
|
|
110
|
+
SocketEvent2["Heartbeat"] = "Heartbeat";
|
|
111
|
+
return SocketEvent2;
|
|
112
|
+
})(SocketEvent || {});
|
|
113
|
+
var GridSocketEvent = /* @__PURE__ */ ((GridSocketEvent2) => {
|
|
114
|
+
GridSocketEvent2["RowChange"] = "RowChange";
|
|
115
|
+
GridSocketEvent2["TableChange"] = "TableChange";
|
|
116
|
+
GridSocketEvent2["SelectTable"] = "SelectTable";
|
|
117
|
+
GridSocketEvent2["SelectCell"] = "SelectCell";
|
|
118
|
+
return GridSocketEvent2;
|
|
119
|
+
})(GridSocketEvent || {});
|
|
120
|
+
var BuilderSocketEvent = /* @__PURE__ */ ((BuilderSocketEvent2) => {
|
|
121
|
+
BuilderSocketEvent2["SelectApp"] = "SelectApp";
|
|
122
|
+
BuilderSocketEvent2["TableChange"] = "TableChange";
|
|
123
|
+
BuilderSocketEvent2["DatasourceChange"] = "DatasourceChange";
|
|
124
|
+
BuilderSocketEvent2["LockTransfer"] = "LockTransfer";
|
|
125
|
+
BuilderSocketEvent2["ScreenChange"] = "ScreenChange";
|
|
126
|
+
BuilderSocketEvent2["AppMetadataChange"] = "AppMetadataChange";
|
|
127
|
+
BuilderSocketEvent2["SelectResource"] = "SelectResource";
|
|
128
|
+
BuilderSocketEvent2["AppPublishChange"] = "AppPublishChange";
|
|
129
|
+
BuilderSocketEvent2["AutomationChange"] = "AutomationChange";
|
|
130
|
+
return BuilderSocketEvent2;
|
|
131
|
+
})(BuilderSocketEvent || {});
|
|
132
|
+
var SocketSessionTTL = 60;
|
|
133
|
+
var ValidQueryNameRegex = /^[^()]*$/;
|
|
134
|
+
var ValidColumnNameRegex = /^[_a-zA-Z0-9\s]*$/g;
|
|
135
|
+
|
|
136
|
+
// src/filters.ts
|
|
137
|
+
var filters_exports = {};
|
|
138
|
+
__export(filters_exports, {
|
|
139
|
+
NoEmptyFilterStrings: () => NoEmptyFilterStrings,
|
|
140
|
+
buildLuceneQuery: () => buildLuceneQuery,
|
|
141
|
+
getValidOperatorsForType: () => getValidOperatorsForType,
|
|
142
|
+
hasFilters: () => hasFilters,
|
|
143
|
+
luceneLimit: () => luceneLimit,
|
|
144
|
+
luceneSort: () => luceneSort,
|
|
145
|
+
runLuceneQuery: () => runLuceneQuery
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// ../types/src/sdk/events/event.ts
|
|
149
|
+
var UserGroupSyncEvents = [
|
|
150
|
+
"user:created" /* USER_CREATED */,
|
|
151
|
+
"user:updated" /* USER_UPDATED */,
|
|
152
|
+
"user:deleted" /* USER_DELETED */,
|
|
153
|
+
"user:admin:assigned" /* USER_PERMISSION_ADMIN_ASSIGNED */,
|
|
154
|
+
"user:admin:removed" /* USER_PERMISSION_ADMIN_REMOVED */,
|
|
155
|
+
"user:builder:assigned" /* USER_PERMISSION_BUILDER_ASSIGNED */,
|
|
156
|
+
"user:builder:removed" /* USER_PERMISSION_BUILDER_REMOVED */,
|
|
157
|
+
"user_group:created" /* USER_GROUP_CREATED */,
|
|
158
|
+
"user_group:updated" /* USER_GROUP_UPDATED */,
|
|
159
|
+
"user_group:deleted" /* USER_GROUP_DELETED */,
|
|
160
|
+
"user_group:user_added" /* USER_GROUP_USERS_ADDED */,
|
|
161
|
+
"user_group:users_deleted" /* USER_GROUP_USERS_REMOVED */,
|
|
162
|
+
"user_group:permissions_edited" /* USER_GROUP_PERMISSIONS_EDITED */
|
|
163
|
+
];
|
|
164
|
+
var AsyncEvents = [...UserGroupSyncEvents];
|
|
165
|
+
|
|
166
|
+
// ../types/src/sdk/cli/constants.ts
|
|
167
|
+
var AnalyticsEvent = {
|
|
168
|
+
OptOut: "analytics:opt:out",
|
|
169
|
+
OptIn: "analytics:opt:in",
|
|
170
|
+
SelfHostInit: "hosting:init",
|
|
171
|
+
PluginInit: "plugin:init" /* PLUGIN_INIT */
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// ../types/src/documents/app/automation.ts
|
|
175
|
+
var AutomationTriggerStepId = /* @__PURE__ */ ((AutomationTriggerStepId2) => {
|
|
176
|
+
AutomationTriggerStepId2["ROW_SAVED"] = "ROW_SAVED";
|
|
177
|
+
AutomationTriggerStepId2["ROW_UPDATED"] = "ROW_UPDATED";
|
|
178
|
+
AutomationTriggerStepId2["ROW_DELETED"] = "ROW_DELETED";
|
|
179
|
+
AutomationTriggerStepId2["WEBHOOK"] = "WEBHOOK";
|
|
180
|
+
AutomationTriggerStepId2["APP"] = "APP";
|
|
181
|
+
AutomationTriggerStepId2["CRON"] = "CRON";
|
|
182
|
+
return AutomationTriggerStepId2;
|
|
183
|
+
})(AutomationTriggerStepId || {});
|
|
184
|
+
var AutomationActionStepId = /* @__PURE__ */ ((AutomationActionStepId2) => {
|
|
185
|
+
AutomationActionStepId2["SEND_EMAIL_SMTP"] = "SEND_EMAIL_SMTP";
|
|
186
|
+
AutomationActionStepId2["CREATE_ROW"] = "CREATE_ROW";
|
|
187
|
+
AutomationActionStepId2["UPDATE_ROW"] = "UPDATE_ROW";
|
|
188
|
+
AutomationActionStepId2["DELETE_ROW"] = "DELETE_ROW";
|
|
189
|
+
AutomationActionStepId2["EXECUTE_BASH"] = "EXECUTE_BASH";
|
|
190
|
+
AutomationActionStepId2["OUTGOING_WEBHOOK"] = "OUTGOING_WEBHOOK";
|
|
191
|
+
AutomationActionStepId2["EXECUTE_SCRIPT"] = "EXECUTE_SCRIPT";
|
|
192
|
+
AutomationActionStepId2["EXECUTE_QUERY"] = "EXECUTE_QUERY";
|
|
193
|
+
AutomationActionStepId2["SERVER_LOG"] = "SERVER_LOG";
|
|
194
|
+
AutomationActionStepId2["DELAY"] = "DELAY";
|
|
195
|
+
AutomationActionStepId2["FILTER"] = "FILTER";
|
|
196
|
+
AutomationActionStepId2["QUERY_ROWS"] = "QUERY_ROWS";
|
|
197
|
+
AutomationActionStepId2["LOOP"] = "LOOP";
|
|
198
|
+
AutomationActionStepId2["COLLECT"] = "COLLECT";
|
|
199
|
+
AutomationActionStepId2["OPENAI"] = "OPENAI";
|
|
200
|
+
AutomationActionStepId2["discord"] = "discord";
|
|
201
|
+
AutomationActionStepId2["slack"] = "slack";
|
|
202
|
+
AutomationActionStepId2["zapier"] = "zapier";
|
|
203
|
+
AutomationActionStepId2["integromat"] = "integromat";
|
|
204
|
+
return AutomationActionStepId2;
|
|
205
|
+
})(AutomationActionStepId || {});
|
|
206
|
+
var AutomationStepIdArray = [
|
|
207
|
+
...Object.values(AutomationActionStepId),
|
|
208
|
+
...Object.values(AutomationTriggerStepId)
|
|
209
|
+
];
|
|
210
|
+
|
|
211
|
+
// ../types/src/documents/document.ts
|
|
212
|
+
var SEPARATOR = "_";
|
|
213
|
+
var prefixed = (type) => `${type}${SEPARATOR}`;
|
|
214
|
+
|
|
215
|
+
// ../types/src/documents/global/plugin.ts
|
|
216
|
+
var PluginType = /* @__PURE__ */ ((PluginType2) => {
|
|
217
|
+
PluginType2["DATASOURCE"] = "datasource";
|
|
218
|
+
PluginType2["COMPONENT"] = "component";
|
|
219
|
+
PluginType2["AUTOMATION"] = "automation";
|
|
220
|
+
return PluginType2;
|
|
221
|
+
})(PluginType || {});
|
|
222
|
+
var PLUGIN_TYPE_ARR = Object.values(PluginType);
|
|
223
|
+
|
|
224
|
+
// ../types/src/documents/global/quotas.ts
|
|
225
|
+
var APP_QUOTA_NAMES = [
|
|
226
|
+
"rows" /* ROWS */,
|
|
227
|
+
"queries" /* QUERIES */,
|
|
228
|
+
"automations" /* AUTOMATIONS */
|
|
229
|
+
];
|
|
230
|
+
var BREAKDOWN_QUOTA_NAMES = [
|
|
231
|
+
"queries" /* QUERIES */,
|
|
232
|
+
"automations" /* AUTOMATIONS */
|
|
233
|
+
];
|
|
234
|
+
|
|
235
|
+
// src/helpers/index.ts
|
|
236
|
+
var helpers_exports = {};
|
|
237
|
+
__export(helpers_exports, {
|
|
238
|
+
deepGet: () => deepGet,
|
|
239
|
+
getUserColor: () => getUserColor,
|
|
240
|
+
getUserInitials: () => getUserInitials,
|
|
241
|
+
getUserLabel: () => getUserLabel,
|
|
242
|
+
isGoogleSheets: () => isGoogleSheets,
|
|
243
|
+
isSQL: () => isSQL
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
// src/helpers/helpers.ts
|
|
247
|
+
var deepGet = (obj, key) => {
|
|
248
|
+
if (!obj || !key) {
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
252
|
+
return obj[key];
|
|
253
|
+
}
|
|
254
|
+
const split = key.split(".");
|
|
255
|
+
for (let i = 0; i < split.length; i++) {
|
|
256
|
+
obj = obj == null ? void 0 : obj[split[i]];
|
|
257
|
+
}
|
|
258
|
+
return obj;
|
|
259
|
+
};
|
|
260
|
+
var getUserInitials = (user) => {
|
|
261
|
+
var _a;
|
|
262
|
+
if (!user) {
|
|
263
|
+
return "?";
|
|
264
|
+
}
|
|
265
|
+
let initials = "";
|
|
266
|
+
initials += user.firstName ? user.firstName[0] : "";
|
|
267
|
+
initials += user.lastName ? user.lastName[0] : "";
|
|
268
|
+
if (initials !== "") {
|
|
269
|
+
return initials;
|
|
270
|
+
}
|
|
271
|
+
return ((_a = user.email) == null ? void 0 : _a[0]) || "U";
|
|
272
|
+
};
|
|
273
|
+
var getUserColor = (user) => {
|
|
274
|
+
let id = user == null ? void 0 : user._id;
|
|
275
|
+
if (!id) {
|
|
276
|
+
return "var(--spectrum-global-color-blue-400)";
|
|
277
|
+
}
|
|
278
|
+
id = id.replace("ro_ta_users_", "");
|
|
279
|
+
let hue = 1;
|
|
280
|
+
for (let i = 0; i < id.length; i++) {
|
|
281
|
+
hue += id.charCodeAt(i);
|
|
282
|
+
hue = hue % 36;
|
|
283
|
+
}
|
|
284
|
+
return `hsl(${hue * 10}, 50%, 40%)`;
|
|
285
|
+
};
|
|
286
|
+
var getUserLabel = (user) => {
|
|
287
|
+
if (!user) {
|
|
288
|
+
return "";
|
|
289
|
+
}
|
|
290
|
+
const { firstName, lastName, email } = user;
|
|
291
|
+
if (firstName && lastName) {
|
|
292
|
+
return `${firstName} ${lastName}`;
|
|
293
|
+
} else if (firstName) {
|
|
294
|
+
return firstName;
|
|
295
|
+
} else if (lastName) {
|
|
296
|
+
return lastName;
|
|
297
|
+
} else {
|
|
298
|
+
return email;
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
// src/helpers/integrations.ts
|
|
303
|
+
function isGoogleSheets(type) {
|
|
304
|
+
return type === "GOOGLE_SHEETS" /* GOOGLE_SHEETS */;
|
|
305
|
+
}
|
|
306
|
+
function isSQL(datasource) {
|
|
307
|
+
if (!datasource || !datasource.source) {
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
310
|
+
const SQL = [
|
|
311
|
+
"POSTGRES" /* POSTGRES */,
|
|
312
|
+
"SQL_SERVER" /* SQL_SERVER */,
|
|
313
|
+
"MYSQL" /* MYSQL */,
|
|
314
|
+
"ORACLE" /* ORACLE */
|
|
315
|
+
];
|
|
316
|
+
return SQL.indexOf(datasource.source) !== -1;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// src/filters.ts
|
|
320
|
+
var HBS_REGEX = /{{([^{].*?)}}/g;
|
|
321
|
+
var getValidOperatorsForType = (type, field, datasource) => {
|
|
322
|
+
var _a;
|
|
323
|
+
const Op = OperatorOptions;
|
|
324
|
+
const stringOps = [
|
|
325
|
+
Op.Equals,
|
|
326
|
+
Op.NotEquals,
|
|
327
|
+
Op.StartsWith,
|
|
328
|
+
Op.Like,
|
|
329
|
+
Op.Empty,
|
|
330
|
+
Op.NotEmpty,
|
|
331
|
+
Op.In
|
|
332
|
+
];
|
|
333
|
+
const numOps = [
|
|
334
|
+
Op.Equals,
|
|
335
|
+
Op.NotEquals,
|
|
336
|
+
Op.MoreThan,
|
|
337
|
+
Op.LessThan,
|
|
338
|
+
Op.Empty,
|
|
339
|
+
Op.NotEmpty,
|
|
340
|
+
Op.In
|
|
341
|
+
];
|
|
342
|
+
let ops = [];
|
|
343
|
+
if (type === "string") {
|
|
344
|
+
ops = stringOps;
|
|
345
|
+
} else if (type === "number" || type === "bigint") {
|
|
346
|
+
ops = numOps;
|
|
347
|
+
} else if (type === "options") {
|
|
348
|
+
ops = [Op.Equals, Op.NotEquals, Op.Empty, Op.NotEmpty, Op.In];
|
|
349
|
+
} else if (type === "array") {
|
|
350
|
+
ops = [Op.Contains, Op.NotContains, Op.Empty, Op.NotEmpty, Op.ContainsAny];
|
|
351
|
+
} else if (type === "boolean") {
|
|
352
|
+
ops = [Op.Equals, Op.NotEquals, Op.Empty, Op.NotEmpty];
|
|
353
|
+
} else if (type === "longform") {
|
|
354
|
+
ops = stringOps;
|
|
355
|
+
} else if (type === "datetime") {
|
|
356
|
+
ops = numOps;
|
|
357
|
+
} else if (type === "formula") {
|
|
358
|
+
ops = stringOps.concat([Op.MoreThan, Op.LessThan]);
|
|
359
|
+
}
|
|
360
|
+
const externalTable = (_a = datasource == null ? void 0 : datasource.tableId) == null ? void 0 : _a.includes("datasource_plus");
|
|
361
|
+
if (field === "_id" && externalTable) {
|
|
362
|
+
ops = [Op.Equals, Op.NotEquals, Op.In];
|
|
363
|
+
}
|
|
364
|
+
return ops;
|
|
365
|
+
};
|
|
366
|
+
var NoEmptyFilterStrings = [
|
|
367
|
+
OperatorOptions.StartsWith.value,
|
|
368
|
+
OperatorOptions.Like.value,
|
|
369
|
+
OperatorOptions.Equals.value,
|
|
370
|
+
OperatorOptions.NotEquals.value,
|
|
371
|
+
OperatorOptions.Contains.value,
|
|
372
|
+
OperatorOptions.NotContains.value
|
|
373
|
+
];
|
|
374
|
+
var cleanupQuery = (query) => {
|
|
375
|
+
if (!query) {
|
|
376
|
+
return query;
|
|
377
|
+
}
|
|
378
|
+
for (let filterField of NoEmptyFilterStrings) {
|
|
379
|
+
if (!query[filterField]) {
|
|
380
|
+
continue;
|
|
381
|
+
}
|
|
382
|
+
for (let [key, value] of Object.entries(query[filterField])) {
|
|
383
|
+
if (value == null || value === "") {
|
|
384
|
+
delete query[filterField][key];
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
return query;
|
|
389
|
+
};
|
|
390
|
+
var removeKeyNumbering = (key) => {
|
|
391
|
+
if (typeof key === "string" && key.match(/\d[0-9]*:/g) != null) {
|
|
392
|
+
const parts = key.split(":");
|
|
393
|
+
parts.shift();
|
|
394
|
+
return parts.join(":");
|
|
395
|
+
} else {
|
|
396
|
+
return key;
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
var buildLuceneQuery = (filter) => {
|
|
400
|
+
let query = {
|
|
401
|
+
string: {},
|
|
402
|
+
fuzzy: {},
|
|
403
|
+
range: {},
|
|
404
|
+
equal: {},
|
|
405
|
+
notEqual: {},
|
|
406
|
+
empty: {},
|
|
407
|
+
notEmpty: {},
|
|
408
|
+
contains: {},
|
|
409
|
+
notContains: {},
|
|
410
|
+
oneOf: {},
|
|
411
|
+
containsAny: {}
|
|
412
|
+
};
|
|
413
|
+
if (Array.isArray(filter)) {
|
|
414
|
+
filter.forEach((expression) => {
|
|
415
|
+
var _a, _b, _c;
|
|
416
|
+
let { operator, field, type, value, externalType } = expression;
|
|
417
|
+
const isHbs = typeof value === "string" && (value.match(HBS_REGEX) || []).length > 0;
|
|
418
|
+
if (operator === "allOr") {
|
|
419
|
+
query.allOr = true;
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
if (type === "datetime" && !isHbs && operator !== "empty" && operator !== "notEmpty") {
|
|
423
|
+
if (!value) {
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
try {
|
|
427
|
+
value = new Date(value).toISOString();
|
|
428
|
+
} catch (error) {
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
if (type === "number" && typeof value === "string") {
|
|
433
|
+
if (operator === "oneOf") {
|
|
434
|
+
value = value.split(",").map((item) => parseFloat(item));
|
|
435
|
+
} else if (!isHbs) {
|
|
436
|
+
value = parseFloat(value);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
if (type === "boolean") {
|
|
440
|
+
value = ((_a = `${value}`) == null ? void 0 : _a.toLowerCase()) === "true";
|
|
441
|
+
}
|
|
442
|
+
if (["contains", "notContains", "containsAny"].includes(operator) && type === "array" && typeof value === "string") {
|
|
443
|
+
value = value.split(",");
|
|
444
|
+
}
|
|
445
|
+
if (operator.startsWith("range") && query.range) {
|
|
446
|
+
const minint = ((_b = SqlNumberTypeRangeMap[externalType]) == null ? void 0 : _b.min) || Number.MIN_SAFE_INTEGER;
|
|
447
|
+
const maxint = ((_c = SqlNumberTypeRangeMap[externalType]) == null ? void 0 : _c.max) || Number.MAX_SAFE_INTEGER;
|
|
448
|
+
if (!query.range[field]) {
|
|
449
|
+
query.range[field] = {
|
|
450
|
+
low: type === "number" ? minint : "0000-00-00T00:00:00.000Z",
|
|
451
|
+
high: type === "number" ? maxint : "9999-00-00T00:00:00.000Z"
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
if (operator === "rangeLow" && value != null && value !== "") {
|
|
455
|
+
query.range[field].low = value;
|
|
456
|
+
} else if (operator === "rangeHigh" && value != null && value !== "") {
|
|
457
|
+
query.range[field].high = value;
|
|
458
|
+
}
|
|
459
|
+
} else if (query[operator]) {
|
|
460
|
+
if (type === "boolean") {
|
|
461
|
+
if (operator === "equal" && value === false) {
|
|
462
|
+
query.notEqual = query.notEqual || {};
|
|
463
|
+
query.notEqual[field] = true;
|
|
464
|
+
} else if (operator === "notEqual" && value === false) {
|
|
465
|
+
query.equal = query.equal || {};
|
|
466
|
+
query.equal[field] = true;
|
|
467
|
+
} else {
|
|
468
|
+
query[operator] = query[operator] || {};
|
|
469
|
+
query[operator][field] = value;
|
|
470
|
+
}
|
|
471
|
+
} else {
|
|
472
|
+
query[operator] = query[operator] || {};
|
|
473
|
+
query[operator][field] = value;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
return query;
|
|
479
|
+
};
|
|
480
|
+
var runLuceneQuery = (docs, query) => {
|
|
481
|
+
if (!docs || !Array.isArray(docs)) {
|
|
482
|
+
return [];
|
|
483
|
+
}
|
|
484
|
+
if (!query) {
|
|
485
|
+
return docs;
|
|
486
|
+
}
|
|
487
|
+
query = cleanupQuery(query);
|
|
488
|
+
const match = (type, failFn) => (doc) => {
|
|
489
|
+
const filters = Object.entries(query[type] || {});
|
|
490
|
+
for (let i = 0; i < filters.length; i++) {
|
|
491
|
+
const [key, testValue] = filters[i];
|
|
492
|
+
const docValue = deepGet(doc, removeKeyNumbering(key));
|
|
493
|
+
if (failFn(docValue, testValue)) {
|
|
494
|
+
return false;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
return true;
|
|
498
|
+
};
|
|
499
|
+
const stringMatch = match("string", (docValue, testValue) => {
|
|
500
|
+
return !docValue || !(docValue == null ? void 0 : docValue.toLowerCase().startsWith(testValue == null ? void 0 : testValue.toLowerCase()));
|
|
501
|
+
});
|
|
502
|
+
const fuzzyMatch = match("fuzzy", (docValue, testValue) => {
|
|
503
|
+
return !docValue || !(docValue == null ? void 0 : docValue.toLowerCase().startsWith(testValue == null ? void 0 : testValue.toLowerCase()));
|
|
504
|
+
});
|
|
505
|
+
const rangeMatch = match(
|
|
506
|
+
"range",
|
|
507
|
+
(docValue, testValue) => {
|
|
508
|
+
return docValue == null || docValue === "" || +docValue < testValue.low || +docValue > testValue.high;
|
|
509
|
+
}
|
|
510
|
+
);
|
|
511
|
+
const equalMatch = match(
|
|
512
|
+
"equal",
|
|
513
|
+
(docValue, testValue) => {
|
|
514
|
+
return testValue != null && testValue !== "" && docValue !== testValue;
|
|
515
|
+
}
|
|
516
|
+
);
|
|
517
|
+
const notEqualMatch = match(
|
|
518
|
+
"notEqual",
|
|
519
|
+
(docValue, testValue) => {
|
|
520
|
+
return testValue != null && testValue !== "" && docValue === testValue;
|
|
521
|
+
}
|
|
522
|
+
);
|
|
523
|
+
const emptyMatch = match("empty", (docValue) => {
|
|
524
|
+
return docValue != null && docValue !== "";
|
|
525
|
+
});
|
|
526
|
+
const notEmptyMatch = match("notEmpty", (docValue) => {
|
|
527
|
+
return docValue == null || docValue === "";
|
|
528
|
+
});
|
|
529
|
+
const oneOf = match("oneOf", (docValue, testValue) => {
|
|
530
|
+
if (typeof testValue === "string") {
|
|
531
|
+
testValue = testValue.split(",");
|
|
532
|
+
if (typeof docValue === "number") {
|
|
533
|
+
testValue = testValue.map((item) => parseFloat(item));
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
return !(testValue == null ? void 0 : testValue.includes(docValue));
|
|
537
|
+
});
|
|
538
|
+
const containsAny = match("containsAny", (docValue, testValue) => {
|
|
539
|
+
return !(docValue == null ? void 0 : docValue.includes(...testValue));
|
|
540
|
+
});
|
|
541
|
+
const contains = match(
|
|
542
|
+
"contains",
|
|
543
|
+
(docValue, testValue) => {
|
|
544
|
+
return !(testValue == null ? void 0 : testValue.every((item) => docValue == null ? void 0 : docValue.includes(item)));
|
|
545
|
+
}
|
|
546
|
+
);
|
|
547
|
+
const notContains = match(
|
|
548
|
+
"notContains",
|
|
549
|
+
(docValue, testValue) => {
|
|
550
|
+
return testValue == null ? void 0 : testValue.every((item) => docValue == null ? void 0 : docValue.includes(item));
|
|
551
|
+
}
|
|
552
|
+
);
|
|
553
|
+
const docMatch = (doc) => {
|
|
554
|
+
return stringMatch(doc) && fuzzyMatch(doc) && rangeMatch(doc) && equalMatch(doc) && notEqualMatch(doc) && emptyMatch(doc) && notEmptyMatch(doc) && oneOf(doc) && contains(doc) && containsAny(doc) && notContains(doc);
|
|
555
|
+
};
|
|
556
|
+
return docs.filter(docMatch);
|
|
557
|
+
};
|
|
558
|
+
var luceneSort = (docs, sort, sortOrder, sortType = "string" /* STRING */) => {
|
|
559
|
+
if (!sort || !sortOrder || !sortType) {
|
|
560
|
+
return docs;
|
|
561
|
+
}
|
|
562
|
+
const parse = sortType === "string" ? (x) => `${x}` : (x) => parseFloat(x);
|
|
563
|
+
return docs.slice().sort((a, b) => {
|
|
564
|
+
const colA = parse(a[sort]);
|
|
565
|
+
const colB = parse(b[sort]);
|
|
566
|
+
if (sortOrder.toLowerCase() === "descending") {
|
|
567
|
+
return colA > colB ? -1 : 1;
|
|
568
|
+
} else {
|
|
569
|
+
return colA > colB ? 1 : -1;
|
|
570
|
+
}
|
|
571
|
+
});
|
|
572
|
+
};
|
|
573
|
+
var luceneLimit = (docs, limit) => {
|
|
574
|
+
const numLimit = parseFloat(limit);
|
|
575
|
+
if (isNaN(numLimit)) {
|
|
576
|
+
return docs;
|
|
577
|
+
}
|
|
578
|
+
return docs.slice(0, numLimit);
|
|
579
|
+
};
|
|
580
|
+
var hasFilters = (query) => {
|
|
581
|
+
if (!query) {
|
|
582
|
+
return false;
|
|
583
|
+
}
|
|
584
|
+
const skipped = ["allOr"];
|
|
585
|
+
for (let [key, value] of Object.entries(query)) {
|
|
586
|
+
if (skipped.includes(key) || typeof value !== "object") {
|
|
587
|
+
continue;
|
|
588
|
+
}
|
|
589
|
+
if (Object.keys(value).length !== 0) {
|
|
590
|
+
return true;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
return false;
|
|
594
|
+
};
|
|
595
|
+
|
|
596
|
+
// src/utils.ts
|
|
597
|
+
var utils_exports = {};
|
|
598
|
+
__export(utils_exports, {
|
|
599
|
+
parallelForeach: () => parallelForeach,
|
|
600
|
+
unreachable: () => unreachable
|
|
601
|
+
});
|
|
602
|
+
function unreachable(value, message = `No such case in exhaustive switch: ${value}`) {
|
|
603
|
+
throw new Error(message);
|
|
604
|
+
}
|
|
605
|
+
async function parallelForeach(items, task, maxConcurrency) {
|
|
606
|
+
const promises = [];
|
|
607
|
+
let index = 0;
|
|
608
|
+
const processItem = async (item) => {
|
|
609
|
+
try {
|
|
610
|
+
await task(item);
|
|
611
|
+
} finally {
|
|
612
|
+
processNext();
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
const processNext = () => {
|
|
616
|
+
if (index >= items.length) {
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
619
|
+
const item = items[index];
|
|
620
|
+
index++;
|
|
621
|
+
const promise = processItem(item);
|
|
622
|
+
promises.push(promise);
|
|
623
|
+
if (promises.length >= maxConcurrency) {
|
|
624
|
+
Promise.race(promises).then(processNext);
|
|
625
|
+
} else {
|
|
626
|
+
processNext();
|
|
627
|
+
}
|
|
628
|
+
};
|
|
629
|
+
processNext();
|
|
630
|
+
await Promise.all(promises);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
// src/sdk/index.ts
|
|
634
|
+
var sdk_exports = {};
|
|
635
|
+
__export(sdk_exports, {
|
|
636
|
+
applications: () => applications_exports,
|
|
637
|
+
users: () => users_exports
|
|
638
|
+
});
|
|
639
|
+
|
|
640
|
+
// src/sdk/documents/applications.ts
|
|
641
|
+
var applications_exports = {};
|
|
642
|
+
__export(applications_exports, {
|
|
643
|
+
getDevAppID: () => getDevAppID,
|
|
644
|
+
getProdAppID: () => getProdAppID
|
|
645
|
+
});
|
|
646
|
+
var APP_PREFIX = prefixed("app" /* APP */);
|
|
647
|
+
var APP_DEV_PREFIX = prefixed("app_dev" /* APP_DEV */);
|
|
648
|
+
function getDevAppID(appId) {
|
|
649
|
+
if (!appId) {
|
|
650
|
+
throw new Error("No app ID provided");
|
|
651
|
+
}
|
|
652
|
+
if (appId.startsWith(APP_DEV_PREFIX)) {
|
|
653
|
+
return appId;
|
|
654
|
+
}
|
|
655
|
+
const split = appId.split(APP_PREFIX);
|
|
656
|
+
split.shift();
|
|
657
|
+
const rest = split.join(APP_PREFIX);
|
|
658
|
+
return `${APP_DEV_PREFIX}${rest}`;
|
|
659
|
+
}
|
|
660
|
+
function getProdAppID(appId) {
|
|
661
|
+
if (!appId) {
|
|
662
|
+
throw new Error("No app ID provided");
|
|
663
|
+
}
|
|
664
|
+
if (!appId.startsWith(APP_DEV_PREFIX)) {
|
|
665
|
+
return appId;
|
|
666
|
+
}
|
|
667
|
+
const split = appId.split(APP_DEV_PREFIX);
|
|
668
|
+
split.shift();
|
|
669
|
+
const rest = split.join(APP_DEV_PREFIX);
|
|
670
|
+
return `${APP_PREFIX}${rest}`;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
// src/sdk/documents/users.ts
|
|
674
|
+
var users_exports = {};
|
|
675
|
+
__export(users_exports, {
|
|
676
|
+
hasAdminPermissions: () => hasAdminPermissions,
|
|
677
|
+
hasAppBuilderPermissions: () => hasAppBuilderPermissions,
|
|
678
|
+
hasBuilderPermissions: () => hasBuilderPermissions,
|
|
679
|
+
isAdmin: () => isAdmin,
|
|
680
|
+
isAdminOrBuilder: () => isAdminOrBuilder,
|
|
681
|
+
isBuilder: () => isBuilder,
|
|
682
|
+
isGlobalBuilder: () => isGlobalBuilder
|
|
683
|
+
});
|
|
684
|
+
function isBuilder(user, appId) {
|
|
685
|
+
var _a, _b, _c;
|
|
686
|
+
if (!user) {
|
|
687
|
+
return false;
|
|
688
|
+
}
|
|
689
|
+
if ((_a = user.builder) == null ? void 0 : _a.global) {
|
|
690
|
+
return true;
|
|
691
|
+
} else if (appId && ((_c = (_b = user.builder) == null ? void 0 : _b.apps) == null ? void 0 : _c.includes(getProdAppID(appId)))) {
|
|
692
|
+
return true;
|
|
693
|
+
}
|
|
694
|
+
return false;
|
|
695
|
+
}
|
|
696
|
+
function isGlobalBuilder(user) {
|
|
697
|
+
return isBuilder(user) && !hasAppBuilderPermissions(user) || isAdmin(user);
|
|
698
|
+
}
|
|
699
|
+
function isAdmin(user) {
|
|
700
|
+
if (!user) {
|
|
701
|
+
return false;
|
|
702
|
+
}
|
|
703
|
+
return hasAdminPermissions(user);
|
|
704
|
+
}
|
|
705
|
+
function isAdminOrBuilder(user, appId) {
|
|
706
|
+
return isBuilder(user, appId) || isAdmin(user);
|
|
707
|
+
}
|
|
708
|
+
function hasAppBuilderPermissions(user) {
|
|
709
|
+
var _a, _b, _c;
|
|
710
|
+
if (!user) {
|
|
711
|
+
return false;
|
|
712
|
+
}
|
|
713
|
+
const appLength = (_b = (_a = user.builder) == null ? void 0 : _a.apps) == null ? void 0 : _b.length;
|
|
714
|
+
const isGlobalBuilder2 = !!((_c = user.builder) == null ? void 0 : _c.global);
|
|
715
|
+
return !isGlobalBuilder2 && appLength != null && appLength > 0;
|
|
716
|
+
}
|
|
717
|
+
function hasBuilderPermissions(user) {
|
|
718
|
+
var _a;
|
|
719
|
+
if (!user) {
|
|
720
|
+
return false;
|
|
721
|
+
}
|
|
722
|
+
return ((_a = user.builder) == null ? void 0 : _a.global) || hasAppBuilderPermissions(user);
|
|
723
|
+
}
|
|
724
|
+
function hasAdminPermissions(user) {
|
|
725
|
+
var _a;
|
|
726
|
+
if (!user) {
|
|
727
|
+
return false;
|
|
728
|
+
}
|
|
729
|
+
return !!((_a = user.admin) == null ? void 0 : _a.global);
|
|
730
|
+
}
|
|
731
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
732
|
+
0 && (module.exports = {
|
|
733
|
+
BuilderSocketEvent,
|
|
734
|
+
GridSocketEvent,
|
|
735
|
+
OperatorOptions,
|
|
736
|
+
SocketEvent,
|
|
737
|
+
SocketSessionTTL,
|
|
738
|
+
SqlNumberTypeRangeMap,
|
|
739
|
+
ValidColumnNameRegex,
|
|
740
|
+
ValidQueryNameRegex,
|
|
741
|
+
dataFilters,
|
|
742
|
+
helpers,
|
|
743
|
+
sdk,
|
|
744
|
+
utils
|
|
745
|
+
});
|
|
746
|
+
//# sourceMappingURL=index.js.map
|