@orion-js/helpers 4.0.0-next.1 → 4.0.0-next.3
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/LICENSE +21 -0
- package/dist/index.cjs +209 -795
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +373 -0
- package/dist/index.d.ts +110 -99
- package/dist/index.js +159 -778
- package/dist/index.js.map +1 -0
- package/package.json +14 -11
package/dist/index.cjs
CHANGED
|
@@ -1,760 +1,60 @@
|
|
|
1
1
|
var __create = Object.create;
|
|
2
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __toESM = (mod, isNodeMode, target) => {
|
|
8
|
-
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
|
-
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
|
-
for (let key of __getOwnPropNames(mod))
|
|
11
|
-
if (!__hasOwnProp.call(to, key))
|
|
12
|
-
__defProp(to, key, {
|
|
13
|
-
get: () => mod[key],
|
|
14
|
-
enumerable: true
|
|
15
|
-
});
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
19
|
-
var __toCommonJS = (from) => {
|
|
20
|
-
var entry = __moduleCache.get(from), desc;
|
|
21
|
-
if (entry)
|
|
22
|
-
return entry;
|
|
23
|
-
entry = __defProp({}, "__esModule", { value: true });
|
|
24
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
25
|
-
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
26
|
-
get: () => from[key],
|
|
27
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
28
|
-
}));
|
|
29
|
-
__moduleCache.set(from, entry);
|
|
30
|
-
return entry;
|
|
31
|
-
};
|
|
32
|
-
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
33
7
|
var __export = (target, all) => {
|
|
34
8
|
for (var name in all)
|
|
35
|
-
__defProp(target, name, {
|
|
36
|
-
get: all[name],
|
|
37
|
-
enumerable: true,
|
|
38
|
-
configurable: true,
|
|
39
|
-
set: (newValue) => all[name] = () => newValue
|
|
40
|
-
});
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
41
10
|
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
function objectHash(object, options) {
|
|
48
|
-
options = applyDefaults(object, options);
|
|
49
|
-
return hash(object, options);
|
|
50
|
-
}
|
|
51
|
-
exports2.sha1 = function(object) {
|
|
52
|
-
return objectHash(object);
|
|
53
|
-
};
|
|
54
|
-
exports2.keys = function(object) {
|
|
55
|
-
return objectHash(object, { excludeValues: true, algorithm: "sha1", encoding: "hex" });
|
|
56
|
-
};
|
|
57
|
-
exports2.MD5 = function(object) {
|
|
58
|
-
return objectHash(object, { algorithm: "md5", encoding: "hex" });
|
|
59
|
-
};
|
|
60
|
-
exports2.keysMD5 = function(object) {
|
|
61
|
-
return objectHash(object, { algorithm: "md5", encoding: "hex", excludeValues: true });
|
|
62
|
-
};
|
|
63
|
-
var hashes = crypto.getHashes ? crypto.getHashes().slice() : ["sha1", "md5"];
|
|
64
|
-
hashes.push("passthrough");
|
|
65
|
-
var encodings = ["buffer", "hex", "binary", "base64"];
|
|
66
|
-
function applyDefaults(object, sourceOptions) {
|
|
67
|
-
sourceOptions = sourceOptions || {};
|
|
68
|
-
var options = {};
|
|
69
|
-
options.algorithm = sourceOptions.algorithm || "sha1";
|
|
70
|
-
options.encoding = sourceOptions.encoding || "hex";
|
|
71
|
-
options.excludeValues = sourceOptions.excludeValues ? true : false;
|
|
72
|
-
options.algorithm = options.algorithm.toLowerCase();
|
|
73
|
-
options.encoding = options.encoding.toLowerCase();
|
|
74
|
-
options.ignoreUnknown = sourceOptions.ignoreUnknown !== true ? false : true;
|
|
75
|
-
options.respectType = sourceOptions.respectType === false ? false : true;
|
|
76
|
-
options.respectFunctionNames = sourceOptions.respectFunctionNames === false ? false : true;
|
|
77
|
-
options.respectFunctionProperties = sourceOptions.respectFunctionProperties === false ? false : true;
|
|
78
|
-
options.unorderedArrays = sourceOptions.unorderedArrays !== true ? false : true;
|
|
79
|
-
options.unorderedSets = sourceOptions.unorderedSets === false ? false : true;
|
|
80
|
-
options.unorderedObjects = sourceOptions.unorderedObjects === false ? false : true;
|
|
81
|
-
options.replacer = sourceOptions.replacer || undefined;
|
|
82
|
-
options.excludeKeys = sourceOptions.excludeKeys || undefined;
|
|
83
|
-
if (typeof object === "undefined") {
|
|
84
|
-
throw new Error("Object argument required.");
|
|
85
|
-
}
|
|
86
|
-
for (var i = 0;i < hashes.length; ++i) {
|
|
87
|
-
if (hashes[i].toLowerCase() === options.algorithm.toLowerCase()) {
|
|
88
|
-
options.algorithm = hashes[i];
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
if (hashes.indexOf(options.algorithm) === -1) {
|
|
92
|
-
throw new Error('Algorithm "' + options.algorithm + '" not supported. ' + "supported values: " + hashes.join(", "));
|
|
93
|
-
}
|
|
94
|
-
if (encodings.indexOf(options.encoding) === -1 && options.algorithm !== "passthrough") {
|
|
95
|
-
throw new Error('Encoding "' + options.encoding + '" not supported. ' + "supported values: " + encodings.join(", "));
|
|
96
|
-
}
|
|
97
|
-
return options;
|
|
98
|
-
}
|
|
99
|
-
function isNativeFunction(f) {
|
|
100
|
-
if (typeof f !== "function") {
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
var exp = /^function\s+\w*\s*\(\s*\)\s*{\s+\[native code\]\s+}$/i;
|
|
104
|
-
return exp.exec(Function.prototype.toString.call(f)) != null;
|
|
105
|
-
}
|
|
106
|
-
function hash(object, options) {
|
|
107
|
-
var hashingStream;
|
|
108
|
-
if (options.algorithm !== "passthrough") {
|
|
109
|
-
hashingStream = crypto.createHash(options.algorithm);
|
|
110
|
-
} else {
|
|
111
|
-
hashingStream = new PassThrough;
|
|
112
|
-
}
|
|
113
|
-
if (typeof hashingStream.write === "undefined") {
|
|
114
|
-
hashingStream.write = hashingStream.update;
|
|
115
|
-
hashingStream.end = hashingStream.update;
|
|
116
|
-
}
|
|
117
|
-
var hasher = typeHasher(options, hashingStream);
|
|
118
|
-
hasher.dispatch(object);
|
|
119
|
-
if (!hashingStream.update) {
|
|
120
|
-
hashingStream.end("");
|
|
121
|
-
}
|
|
122
|
-
if (hashingStream.digest) {
|
|
123
|
-
return hashingStream.digest(options.encoding === "buffer" ? undefined : options.encoding);
|
|
124
|
-
}
|
|
125
|
-
var buf = hashingStream.read();
|
|
126
|
-
if (options.encoding === "buffer") {
|
|
127
|
-
return buf;
|
|
128
|
-
}
|
|
129
|
-
return buf.toString(options.encoding);
|
|
130
|
-
}
|
|
131
|
-
exports2.writeToStream = function(object, options, stream) {
|
|
132
|
-
if (typeof stream === "undefined") {
|
|
133
|
-
stream = options;
|
|
134
|
-
options = {};
|
|
135
|
-
}
|
|
136
|
-
options = applyDefaults(object, options);
|
|
137
|
-
return typeHasher(options, stream).dispatch(object);
|
|
138
|
-
};
|
|
139
|
-
function typeHasher(options, writeTo, context) {
|
|
140
|
-
context = context || [];
|
|
141
|
-
var write = function(str) {
|
|
142
|
-
if (writeTo.update) {
|
|
143
|
-
return writeTo.update(str, "utf8");
|
|
144
|
-
} else {
|
|
145
|
-
return writeTo.write(str, "utf8");
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
return {
|
|
149
|
-
dispatch: function(value) {
|
|
150
|
-
if (options.replacer) {
|
|
151
|
-
value = options.replacer(value);
|
|
152
|
-
}
|
|
153
|
-
var type = typeof value;
|
|
154
|
-
if (value === null) {
|
|
155
|
-
type = "null";
|
|
156
|
-
}
|
|
157
|
-
return this["_" + type](value);
|
|
158
|
-
},
|
|
159
|
-
_object: function(object) {
|
|
160
|
-
var pattern = /\[object (.*)\]/i;
|
|
161
|
-
var objString = Object.prototype.toString.call(object);
|
|
162
|
-
var objType = pattern.exec(objString);
|
|
163
|
-
if (!objType) {
|
|
164
|
-
objType = "unknown:[" + objString + "]";
|
|
165
|
-
} else {
|
|
166
|
-
objType = objType[1];
|
|
167
|
-
}
|
|
168
|
-
objType = objType.toLowerCase();
|
|
169
|
-
var objectNumber = null;
|
|
170
|
-
if ((objectNumber = context.indexOf(object)) >= 0) {
|
|
171
|
-
return this.dispatch("[CIRCULAR:" + objectNumber + "]");
|
|
172
|
-
} else {
|
|
173
|
-
context.push(object);
|
|
174
|
-
}
|
|
175
|
-
if (typeof Buffer !== "undefined" && Buffer.isBuffer && Buffer.isBuffer(object)) {
|
|
176
|
-
write("buffer:");
|
|
177
|
-
return write(object);
|
|
178
|
-
}
|
|
179
|
-
if (objType !== "object" && objType !== "function" && objType !== "asyncfunction") {
|
|
180
|
-
if (this["_" + objType]) {
|
|
181
|
-
this["_" + objType](object);
|
|
182
|
-
} else if (options.ignoreUnknown) {
|
|
183
|
-
return write("[" + objType + "]");
|
|
184
|
-
} else {
|
|
185
|
-
throw new Error('Unknown object type "' + objType + '"');
|
|
186
|
-
}
|
|
187
|
-
} else {
|
|
188
|
-
var keys = Object.keys(object);
|
|
189
|
-
if (options.unorderedObjects) {
|
|
190
|
-
keys = keys.sort();
|
|
191
|
-
}
|
|
192
|
-
if (options.respectType !== false && !isNativeFunction(object)) {
|
|
193
|
-
keys.splice(0, 0, "prototype", "__proto__", "constructor");
|
|
194
|
-
}
|
|
195
|
-
if (options.excludeKeys) {
|
|
196
|
-
keys = keys.filter(function(key) {
|
|
197
|
-
return !options.excludeKeys(key);
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
write("object:" + keys.length + ":");
|
|
201
|
-
var self = this;
|
|
202
|
-
return keys.forEach(function(key) {
|
|
203
|
-
self.dispatch(key);
|
|
204
|
-
write(":");
|
|
205
|
-
if (!options.excludeValues) {
|
|
206
|
-
self.dispatch(object[key]);
|
|
207
|
-
}
|
|
208
|
-
write(",");
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
},
|
|
212
|
-
_array: function(arr, unordered) {
|
|
213
|
-
unordered = typeof unordered !== "undefined" ? unordered : options.unorderedArrays !== false;
|
|
214
|
-
var self = this;
|
|
215
|
-
write("array:" + arr.length + ":");
|
|
216
|
-
if (!unordered || arr.length <= 1) {
|
|
217
|
-
return arr.forEach(function(entry) {
|
|
218
|
-
return self.dispatch(entry);
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
var contextAdditions = [];
|
|
222
|
-
var entries = arr.map(function(entry) {
|
|
223
|
-
var strm = new PassThrough;
|
|
224
|
-
var localContext = context.slice();
|
|
225
|
-
var hasher = typeHasher(options, strm, localContext);
|
|
226
|
-
hasher.dispatch(entry);
|
|
227
|
-
contextAdditions = contextAdditions.concat(localContext.slice(context.length));
|
|
228
|
-
return strm.read().toString();
|
|
229
|
-
});
|
|
230
|
-
context = context.concat(contextAdditions);
|
|
231
|
-
entries.sort();
|
|
232
|
-
return this._array(entries, false);
|
|
233
|
-
},
|
|
234
|
-
_date: function(date) {
|
|
235
|
-
return write("date:" + date.toJSON());
|
|
236
|
-
},
|
|
237
|
-
_symbol: function(sym) {
|
|
238
|
-
return write("symbol:" + sym.toString());
|
|
239
|
-
},
|
|
240
|
-
_error: function(err) {
|
|
241
|
-
return write("error:" + err.toString());
|
|
242
|
-
},
|
|
243
|
-
_boolean: function(bool) {
|
|
244
|
-
return write("bool:" + bool.toString());
|
|
245
|
-
},
|
|
246
|
-
_string: function(string) {
|
|
247
|
-
write("string:" + string.length + ":");
|
|
248
|
-
write(string.toString());
|
|
249
|
-
},
|
|
250
|
-
_function: function(fn) {
|
|
251
|
-
write("fn:");
|
|
252
|
-
if (isNativeFunction(fn)) {
|
|
253
|
-
this.dispatch("[native]");
|
|
254
|
-
} else {
|
|
255
|
-
this.dispatch(fn.toString());
|
|
256
|
-
}
|
|
257
|
-
if (options.respectFunctionNames !== false) {
|
|
258
|
-
this.dispatch("function-name:" + String(fn.name));
|
|
259
|
-
}
|
|
260
|
-
if (options.respectFunctionProperties) {
|
|
261
|
-
this._object(fn);
|
|
262
|
-
}
|
|
263
|
-
},
|
|
264
|
-
_number: function(number) {
|
|
265
|
-
return write("number:" + number.toString());
|
|
266
|
-
},
|
|
267
|
-
_xml: function(xml) {
|
|
268
|
-
return write("xml:" + xml.toString());
|
|
269
|
-
},
|
|
270
|
-
_null: function() {
|
|
271
|
-
return write("Null");
|
|
272
|
-
},
|
|
273
|
-
_undefined: function() {
|
|
274
|
-
return write("Undefined");
|
|
275
|
-
},
|
|
276
|
-
_regexp: function(regex) {
|
|
277
|
-
return write("regex:" + regex.toString());
|
|
278
|
-
},
|
|
279
|
-
_uint8array: function(arr) {
|
|
280
|
-
write("uint8array:");
|
|
281
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
282
|
-
},
|
|
283
|
-
_uint8clampedarray: function(arr) {
|
|
284
|
-
write("uint8clampedarray:");
|
|
285
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
286
|
-
},
|
|
287
|
-
_int8array: function(arr) {
|
|
288
|
-
write("uint8array:");
|
|
289
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
290
|
-
},
|
|
291
|
-
_uint16array: function(arr) {
|
|
292
|
-
write("uint16array:");
|
|
293
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
294
|
-
},
|
|
295
|
-
_int16array: function(arr) {
|
|
296
|
-
write("uint16array:");
|
|
297
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
298
|
-
},
|
|
299
|
-
_uint32array: function(arr) {
|
|
300
|
-
write("uint32array:");
|
|
301
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
302
|
-
},
|
|
303
|
-
_int32array: function(arr) {
|
|
304
|
-
write("uint32array:");
|
|
305
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
306
|
-
},
|
|
307
|
-
_float32array: function(arr) {
|
|
308
|
-
write("float32array:");
|
|
309
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
310
|
-
},
|
|
311
|
-
_float64array: function(arr) {
|
|
312
|
-
write("float64array:");
|
|
313
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
314
|
-
},
|
|
315
|
-
_arraybuffer: function(arr) {
|
|
316
|
-
write("arraybuffer:");
|
|
317
|
-
return this.dispatch(new Uint8Array(arr));
|
|
318
|
-
},
|
|
319
|
-
_url: function(url) {
|
|
320
|
-
return write("url:" + url.toString(), "utf8");
|
|
321
|
-
},
|
|
322
|
-
_map: function(map) {
|
|
323
|
-
write("map:");
|
|
324
|
-
var arr = Array.from(map);
|
|
325
|
-
return this._array(arr, options.unorderedSets !== false);
|
|
326
|
-
},
|
|
327
|
-
_set: function(set) {
|
|
328
|
-
write("set:");
|
|
329
|
-
var arr = Array.from(set);
|
|
330
|
-
return this._array(arr, options.unorderedSets !== false);
|
|
331
|
-
},
|
|
332
|
-
_file: function(file) {
|
|
333
|
-
write("file:");
|
|
334
|
-
return this.dispatch([file.name, file.size, file.type, file.lastModfied]);
|
|
335
|
-
},
|
|
336
|
-
_blob: function() {
|
|
337
|
-
if (options.ignoreUnknown) {
|
|
338
|
-
return write("[blob]");
|
|
339
|
-
}
|
|
340
|
-
throw Error(`Hashing Blob objects is currently not supported
|
|
341
|
-
` + `(see https://github.com/puleos/object-hash/issues/26)
|
|
342
|
-
` + `Use "options.replacer" or "options.ignoreUnknown"
|
|
343
|
-
`);
|
|
344
|
-
},
|
|
345
|
-
_domwindow: function() {
|
|
346
|
-
return write("domwindow");
|
|
347
|
-
},
|
|
348
|
-
_bigint: function(number) {
|
|
349
|
-
return write("bigint:" + number.toString());
|
|
350
|
-
},
|
|
351
|
-
_process: function() {
|
|
352
|
-
return write("process");
|
|
353
|
-
},
|
|
354
|
-
_timer: function() {
|
|
355
|
-
return write("timer");
|
|
356
|
-
},
|
|
357
|
-
_pipe: function() {
|
|
358
|
-
return write("pipe");
|
|
359
|
-
},
|
|
360
|
-
_tcp: function() {
|
|
361
|
-
return write("tcp");
|
|
362
|
-
},
|
|
363
|
-
_udp: function() {
|
|
364
|
-
return write("udp");
|
|
365
|
-
},
|
|
366
|
-
_tty: function() {
|
|
367
|
-
return write("tty");
|
|
368
|
-
},
|
|
369
|
-
_statwatcher: function() {
|
|
370
|
-
return write("statwatcher");
|
|
371
|
-
},
|
|
372
|
-
_securecontext: function() {
|
|
373
|
-
return write("securecontext");
|
|
374
|
-
},
|
|
375
|
-
_connection: function() {
|
|
376
|
-
return write("connection");
|
|
377
|
-
},
|
|
378
|
-
_zlib: function() {
|
|
379
|
-
return write("zlib");
|
|
380
|
-
},
|
|
381
|
-
_context: function() {
|
|
382
|
-
return write("context");
|
|
383
|
-
},
|
|
384
|
-
_nodescript: function() {
|
|
385
|
-
return write("nodescript");
|
|
386
|
-
},
|
|
387
|
-
_httpparser: function() {
|
|
388
|
-
return write("httpparser");
|
|
389
|
-
},
|
|
390
|
-
_dataview: function() {
|
|
391
|
-
return write("dataview");
|
|
392
|
-
},
|
|
393
|
-
_signal: function() {
|
|
394
|
-
return write("signal");
|
|
395
|
-
},
|
|
396
|
-
_fsevent: function() {
|
|
397
|
-
return write("fsevent");
|
|
398
|
-
},
|
|
399
|
-
_tlswrap: function() {
|
|
400
|
-
return write("tlswrap");
|
|
401
|
-
}
|
|
402
|
-
};
|
|
403
|
-
}
|
|
404
|
-
function PassThrough() {
|
|
405
|
-
return {
|
|
406
|
-
buf: "",
|
|
407
|
-
write: function(b) {
|
|
408
|
-
this.buf += b;
|
|
409
|
-
},
|
|
410
|
-
end: function(b) {
|
|
411
|
-
this.buf += b;
|
|
412
|
-
},
|
|
413
|
-
read: function() {
|
|
414
|
-
return this.buf;
|
|
415
|
-
}
|
|
416
|
-
};
|
|
417
|
-
}
|
|
418
|
-
});
|
|
419
|
-
|
|
420
|
-
// ../../node_modules/uuid/dist/rng.js
|
|
421
|
-
var require_rng = __commonJS((exports2) => {
|
|
422
|
-
Object.defineProperty(exports2, "__esModule", {
|
|
423
|
-
value: true
|
|
424
|
-
});
|
|
425
|
-
exports2.default = rng;
|
|
426
|
-
var _crypto = _interopRequireDefault(require("crypto"));
|
|
427
|
-
function _interopRequireDefault(obj) {
|
|
428
|
-
return obj && obj.__esModule ? obj : { default: obj };
|
|
429
|
-
}
|
|
430
|
-
function rng() {
|
|
431
|
-
return _crypto.default.randomBytes(16);
|
|
432
|
-
}
|
|
433
|
-
});
|
|
434
|
-
|
|
435
|
-
// ../../node_modules/uuid/dist/bytesToUuid.js
|
|
436
|
-
var require_bytesToUuid = __commonJS((exports2) => {
|
|
437
|
-
Object.defineProperty(exports2, "__esModule", {
|
|
438
|
-
value: true
|
|
439
|
-
});
|
|
440
|
-
exports2.default = undefined;
|
|
441
|
-
var byteToHex = [];
|
|
442
|
-
for (i = 0;i < 256; ++i) {
|
|
443
|
-
byteToHex[i] = (i + 256).toString(16).substr(1);
|
|
444
|
-
}
|
|
445
|
-
var i;
|
|
446
|
-
function bytesToUuid(buf, offset) {
|
|
447
|
-
var i2 = offset || 0;
|
|
448
|
-
var bth = byteToHex;
|
|
449
|
-
return [bth[buf[i2++]], bth[buf[i2++]], bth[buf[i2++]], bth[buf[i2++]], "-", bth[buf[i2++]], bth[buf[i2++]], "-", bth[buf[i2++]], bth[buf[i2++]], "-", bth[buf[i2++]], bth[buf[i2++]], "-", bth[buf[i2++]], bth[buf[i2++]], bth[buf[i2++]], bth[buf[i2++]], bth[buf[i2++]], bth[buf[i2++]]].join("");
|
|
450
|
-
}
|
|
451
|
-
var _default = bytesToUuid;
|
|
452
|
-
exports2.default = _default;
|
|
453
|
-
});
|
|
454
|
-
|
|
455
|
-
// ../../node_modules/uuid/dist/v1.js
|
|
456
|
-
var require_v1 = __commonJS((exports2) => {
|
|
457
|
-
Object.defineProperty(exports2, "__esModule", {
|
|
458
|
-
value: true
|
|
459
|
-
});
|
|
460
|
-
exports2.default = undefined;
|
|
461
|
-
var _rng = _interopRequireDefault(require_rng());
|
|
462
|
-
var _bytesToUuid = _interopRequireDefault(require_bytesToUuid());
|
|
463
|
-
function _interopRequireDefault(obj) {
|
|
464
|
-
return obj && obj.__esModule ? obj : { default: obj };
|
|
465
|
-
}
|
|
466
|
-
var _nodeId;
|
|
467
|
-
var _clockseq;
|
|
468
|
-
var _lastMSecs = 0;
|
|
469
|
-
var _lastNSecs = 0;
|
|
470
|
-
function v1(options, buf, offset) {
|
|
471
|
-
var i = buf && offset || 0;
|
|
472
|
-
var b = buf || [];
|
|
473
|
-
options = options || {};
|
|
474
|
-
var node = options.node || _nodeId;
|
|
475
|
-
var clockseq = options.clockseq !== undefined ? options.clockseq : _clockseq;
|
|
476
|
-
if (node == null || clockseq == null) {
|
|
477
|
-
var seedBytes = options.random || (options.rng || _rng.default)();
|
|
478
|
-
if (node == null) {
|
|
479
|
-
node = _nodeId = [seedBytes[0] | 1, seedBytes[1], seedBytes[2], seedBytes[3], seedBytes[4], seedBytes[5]];
|
|
480
|
-
}
|
|
481
|
-
if (clockseq == null) {
|
|
482
|
-
clockseq = _clockseq = (seedBytes[6] << 8 | seedBytes[7]) & 16383;
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
var msecs = options.msecs !== undefined ? options.msecs : new Date().getTime();
|
|
486
|
-
var nsecs = options.nsecs !== undefined ? options.nsecs : _lastNSecs + 1;
|
|
487
|
-
var dt = msecs - _lastMSecs + (nsecs - _lastNSecs) / 1e4;
|
|
488
|
-
if (dt < 0 && options.clockseq === undefined) {
|
|
489
|
-
clockseq = clockseq + 1 & 16383;
|
|
490
|
-
}
|
|
491
|
-
if ((dt < 0 || msecs > _lastMSecs) && options.nsecs === undefined) {
|
|
492
|
-
nsecs = 0;
|
|
493
|
-
}
|
|
494
|
-
if (nsecs >= 1e4) {
|
|
495
|
-
throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");
|
|
496
|
-
}
|
|
497
|
-
_lastMSecs = msecs;
|
|
498
|
-
_lastNSecs = nsecs;
|
|
499
|
-
_clockseq = clockseq;
|
|
500
|
-
msecs += 12219292800000;
|
|
501
|
-
var tl = ((msecs & 268435455) * 1e4 + nsecs) % 4294967296;
|
|
502
|
-
b[i++] = tl >>> 24 & 255;
|
|
503
|
-
b[i++] = tl >>> 16 & 255;
|
|
504
|
-
b[i++] = tl >>> 8 & 255;
|
|
505
|
-
b[i++] = tl & 255;
|
|
506
|
-
var tmh = msecs / 4294967296 * 1e4 & 268435455;
|
|
507
|
-
b[i++] = tmh >>> 8 & 255;
|
|
508
|
-
b[i++] = tmh & 255;
|
|
509
|
-
b[i++] = tmh >>> 24 & 15 | 16;
|
|
510
|
-
b[i++] = tmh >>> 16 & 255;
|
|
511
|
-
b[i++] = clockseq >>> 8 | 128;
|
|
512
|
-
b[i++] = clockseq & 255;
|
|
513
|
-
for (var n = 0;n < 6; ++n) {
|
|
514
|
-
b[i + n] = node[n];
|
|
515
|
-
}
|
|
516
|
-
return buf ? buf : (0, _bytesToUuid.default)(b);
|
|
517
|
-
}
|
|
518
|
-
var _default = v1;
|
|
519
|
-
exports2.default = _default;
|
|
520
|
-
});
|
|
521
|
-
|
|
522
|
-
// ../../node_modules/uuid/dist/v35.js
|
|
523
|
-
var require_v35 = __commonJS((exports2) => {
|
|
524
|
-
Object.defineProperty(exports2, "__esModule", {
|
|
525
|
-
value: true
|
|
526
|
-
});
|
|
527
|
-
exports2.default = _default;
|
|
528
|
-
exports2.URL = exports2.DNS = undefined;
|
|
529
|
-
var _bytesToUuid = _interopRequireDefault(require_bytesToUuid());
|
|
530
|
-
function _interopRequireDefault(obj) {
|
|
531
|
-
return obj && obj.__esModule ? obj : { default: obj };
|
|
532
|
-
}
|
|
533
|
-
function uuidToBytes(uuid) {
|
|
534
|
-
var bytes = [];
|
|
535
|
-
uuid.replace(/[a-fA-F0-9]{2}/g, function(hex) {
|
|
536
|
-
bytes.push(parseInt(hex, 16));
|
|
537
|
-
});
|
|
538
|
-
return bytes;
|
|
539
|
-
}
|
|
540
|
-
function stringToBytes(str) {
|
|
541
|
-
str = unescape(encodeURIComponent(str));
|
|
542
|
-
var bytes = new Array(str.length);
|
|
543
|
-
for (var i = 0;i < str.length; i++) {
|
|
544
|
-
bytes[i] = str.charCodeAt(i);
|
|
545
|
-
}
|
|
546
|
-
return bytes;
|
|
547
|
-
}
|
|
548
|
-
var DNS = "6ba7b810-9dad-11d1-80b4-00c04fd430c8";
|
|
549
|
-
exports2.DNS = DNS;
|
|
550
|
-
var URL = "6ba7b811-9dad-11d1-80b4-00c04fd430c8";
|
|
551
|
-
exports2.URL = URL;
|
|
552
|
-
function _default(name, version, hashfunc) {
|
|
553
|
-
var generateUUID = function(value, namespace, buf, offset) {
|
|
554
|
-
var off = buf && offset || 0;
|
|
555
|
-
if (typeof value == "string")
|
|
556
|
-
value = stringToBytes(value);
|
|
557
|
-
if (typeof namespace == "string")
|
|
558
|
-
namespace = uuidToBytes(namespace);
|
|
559
|
-
if (!Array.isArray(value))
|
|
560
|
-
throw TypeError("value must be an array of bytes");
|
|
561
|
-
if (!Array.isArray(namespace) || namespace.length !== 16)
|
|
562
|
-
throw TypeError("namespace must be uuid string or an Array of 16 byte values");
|
|
563
|
-
var bytes = hashfunc(namespace.concat(value));
|
|
564
|
-
bytes[6] = bytes[6] & 15 | version;
|
|
565
|
-
bytes[8] = bytes[8] & 63 | 128;
|
|
566
|
-
if (buf) {
|
|
567
|
-
for (var idx = 0;idx < 16; ++idx) {
|
|
568
|
-
buf[off + idx] = bytes[idx];
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
return buf || (0, _bytesToUuid.default)(bytes);
|
|
572
|
-
};
|
|
573
|
-
try {
|
|
574
|
-
generateUUID.name = name;
|
|
575
|
-
} catch (err) {
|
|
576
|
-
}
|
|
577
|
-
generateUUID.DNS = DNS;
|
|
578
|
-
generateUUID.URL = URL;
|
|
579
|
-
return generateUUID;
|
|
580
|
-
}
|
|
581
|
-
});
|
|
582
|
-
|
|
583
|
-
// ../../node_modules/uuid/dist/md5.js
|
|
584
|
-
var require_md5 = __commonJS((exports2) => {
|
|
585
|
-
Object.defineProperty(exports2, "__esModule", {
|
|
586
|
-
value: true
|
|
587
|
-
});
|
|
588
|
-
exports2.default = undefined;
|
|
589
|
-
var _crypto = _interopRequireDefault(require("crypto"));
|
|
590
|
-
function _interopRequireDefault(obj) {
|
|
591
|
-
return obj && obj.__esModule ? obj : { default: obj };
|
|
592
|
-
}
|
|
593
|
-
function md5(bytes) {
|
|
594
|
-
if (Array.isArray(bytes)) {
|
|
595
|
-
bytes = Buffer.from(bytes);
|
|
596
|
-
} else if (typeof bytes === "string") {
|
|
597
|
-
bytes = Buffer.from(bytes, "utf8");
|
|
598
|
-
}
|
|
599
|
-
return _crypto.default.createHash("md5").update(bytes).digest();
|
|
600
|
-
}
|
|
601
|
-
var _default = md5;
|
|
602
|
-
exports2.default = _default;
|
|
603
|
-
});
|
|
604
|
-
|
|
605
|
-
// ../../node_modules/uuid/dist/v3.js
|
|
606
|
-
var require_v3 = __commonJS((exports2) => {
|
|
607
|
-
Object.defineProperty(exports2, "__esModule", {
|
|
608
|
-
value: true
|
|
609
|
-
});
|
|
610
|
-
exports2.default = undefined;
|
|
611
|
-
var _v = _interopRequireDefault(require_v35());
|
|
612
|
-
var _md = _interopRequireDefault(require_md5());
|
|
613
|
-
function _interopRequireDefault(obj) {
|
|
614
|
-
return obj && obj.__esModule ? obj : { default: obj };
|
|
615
|
-
}
|
|
616
|
-
var v3 = (0, _v.default)("v3", 48, _md.default);
|
|
617
|
-
var _default = v3;
|
|
618
|
-
exports2.default = _default;
|
|
619
|
-
});
|
|
620
|
-
|
|
621
|
-
// ../../node_modules/uuid/dist/v4.js
|
|
622
|
-
var require_v4 = __commonJS((exports2) => {
|
|
623
|
-
Object.defineProperty(exports2, "__esModule", {
|
|
624
|
-
value: true
|
|
625
|
-
});
|
|
626
|
-
exports2.default = undefined;
|
|
627
|
-
var _rng = _interopRequireDefault(require_rng());
|
|
628
|
-
var _bytesToUuid = _interopRequireDefault(require_bytesToUuid());
|
|
629
|
-
function _interopRequireDefault(obj) {
|
|
630
|
-
return obj && obj.__esModule ? obj : { default: obj };
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
631
16
|
}
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
for (var ii = 0;ii < 16; ++ii) {
|
|
644
|
-
buf[i + ii] = rnds[ii];
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
return buf || (0, _bytesToUuid.default)(rnds);
|
|
648
|
-
}
|
|
649
|
-
var _default = v4;
|
|
650
|
-
exports2.default = _default;
|
|
651
|
-
});
|
|
652
|
-
|
|
653
|
-
// ../../node_modules/uuid/dist/sha1.js
|
|
654
|
-
var require_sha1 = __commonJS((exports2) => {
|
|
655
|
-
Object.defineProperty(exports2, "__esModule", {
|
|
656
|
-
value: true
|
|
657
|
-
});
|
|
658
|
-
exports2.default = undefined;
|
|
659
|
-
var _crypto = _interopRequireDefault(require("crypto"));
|
|
660
|
-
function _interopRequireDefault(obj) {
|
|
661
|
-
return obj && obj.__esModule ? obj : { default: obj };
|
|
662
|
-
}
|
|
663
|
-
function sha1(bytes) {
|
|
664
|
-
if (Array.isArray(bytes)) {
|
|
665
|
-
bytes = Buffer.from(bytes);
|
|
666
|
-
} else if (typeof bytes === "string") {
|
|
667
|
-
bytes = Buffer.from(bytes, "utf8");
|
|
668
|
-
}
|
|
669
|
-
return _crypto.default.createHash("sha1").update(bytes).digest();
|
|
670
|
-
}
|
|
671
|
-
var _default = sha1;
|
|
672
|
-
exports2.default = _default;
|
|
673
|
-
});
|
|
674
|
-
|
|
675
|
-
// ../../node_modules/uuid/dist/v5.js
|
|
676
|
-
var require_v5 = __commonJS((exports2) => {
|
|
677
|
-
Object.defineProperty(exports2, "__esModule", {
|
|
678
|
-
value: true
|
|
679
|
-
});
|
|
680
|
-
exports2.default = undefined;
|
|
681
|
-
var _v = _interopRequireDefault(require_v35());
|
|
682
|
-
var _sha = _interopRequireDefault(require_sha1());
|
|
683
|
-
function _interopRequireDefault(obj) {
|
|
684
|
-
return obj && obj.__esModule ? obj : { default: obj };
|
|
685
|
-
}
|
|
686
|
-
var v5 = (0, _v.default)("v5", 80, _sha.default);
|
|
687
|
-
var _default = v5;
|
|
688
|
-
exports2.default = _default;
|
|
689
|
-
});
|
|
690
|
-
|
|
691
|
-
// ../../node_modules/uuid/dist/index.js
|
|
692
|
-
var require_dist = __commonJS((exports2) => {
|
|
693
|
-
Object.defineProperty(exports2, "__esModule", {
|
|
694
|
-
value: true
|
|
695
|
-
});
|
|
696
|
-
Object.defineProperty(exports2, "v1", {
|
|
697
|
-
enumerable: true,
|
|
698
|
-
get: function() {
|
|
699
|
-
return _v.default;
|
|
700
|
-
}
|
|
701
|
-
});
|
|
702
|
-
Object.defineProperty(exports2, "v3", {
|
|
703
|
-
enumerable: true,
|
|
704
|
-
get: function() {
|
|
705
|
-
return _v2.default;
|
|
706
|
-
}
|
|
707
|
-
});
|
|
708
|
-
Object.defineProperty(exports2, "v4", {
|
|
709
|
-
enumerable: true,
|
|
710
|
-
get: function() {
|
|
711
|
-
return _v3.default;
|
|
712
|
-
}
|
|
713
|
-
});
|
|
714
|
-
Object.defineProperty(exports2, "v5", {
|
|
715
|
-
enumerable: true,
|
|
716
|
-
get: function() {
|
|
717
|
-
return _v4.default;
|
|
718
|
-
}
|
|
719
|
-
});
|
|
720
|
-
var _v = _interopRequireDefault(require_v1());
|
|
721
|
-
var _v2 = _interopRequireDefault(require_v3());
|
|
722
|
-
var _v3 = _interopRequireDefault(require_v4());
|
|
723
|
-
var _v4 = _interopRequireDefault(require_v5());
|
|
724
|
-
function _interopRequireDefault(obj) {
|
|
725
|
-
return obj && obj.__esModule ? obj : { default: obj };
|
|
726
|
-
}
|
|
727
|
-
});
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
728
28
|
|
|
729
29
|
// src/index.ts
|
|
730
|
-
var
|
|
731
|
-
__export(
|
|
732
|
-
|
|
733
|
-
shortenMongoId: () => shortenMongoId,
|
|
734
|
-
removeAccentsOnly: () => removeAccentsOnly,
|
|
735
|
-
removeAccentsAndTrim: () => removeAccentsAndTrim,
|
|
736
|
-
normalizeForSearchToken: () => normalizeForSearchToken,
|
|
737
|
-
normalizeForSearch: () => normalizeForSearch,
|
|
738
|
-
normalizeForFileKey: () => normalizeForFileKey,
|
|
739
|
-
normalizeForCompactSearch: () => normalizeForCompactSearch,
|
|
740
|
-
isUserError: () => isUserError,
|
|
741
|
-
isPermissionsError: () => isPermissionsError,
|
|
742
|
-
isOrionError: () => isOrionError,
|
|
743
|
-
hashObject: () => hashObject_default,
|
|
744
|
-
getSearchTokens: () => getSearchTokens,
|
|
745
|
-
getSearchQueryForTokens: () => getSearchQueryForTokens,
|
|
746
|
-
generateUUIDWithPrefix: () => generateUUIDWithPrefix,
|
|
747
|
-
generateUUID: () => generateUUID,
|
|
748
|
-
generateId: () => generateId,
|
|
749
|
-
executeWithRetries: () => executeWithRetries,
|
|
750
|
-
createMapArray: () => createMapArray,
|
|
751
|
-
createMap: () => createMap,
|
|
752
|
-
composeMiddlewares: () => composeMiddlewares,
|
|
753
|
-
UserError: () => UserError,
|
|
30
|
+
var index_exports = {};
|
|
31
|
+
__export(index_exports, {
|
|
32
|
+
OrionError: () => OrionError,
|
|
754
33
|
PermissionsError: () => PermissionsError,
|
|
755
|
-
|
|
34
|
+
UserError: () => UserError,
|
|
35
|
+
composeMiddlewares: () => composeMiddlewares,
|
|
36
|
+
createMap: () => createMap,
|
|
37
|
+
createMapArray: () => createMapArray,
|
|
38
|
+
executeWithRetries: () => executeWithRetries,
|
|
39
|
+
generateId: () => generateId,
|
|
40
|
+
generateUUID: () => generateUUID,
|
|
41
|
+
generateUUIDWithPrefix: () => generateUUIDWithPrefix,
|
|
42
|
+
getSearchQueryForTokens: () => getSearchQueryForTokens,
|
|
43
|
+
getSearchTokens: () => getSearchTokens,
|
|
44
|
+
hashObject: () => hashObject_default,
|
|
45
|
+
isOrionError: () => isOrionError,
|
|
46
|
+
isPermissionsError: () => isPermissionsError,
|
|
47
|
+
isUserError: () => isUserError,
|
|
48
|
+
normalizeForCompactSearch: () => normalizeForCompactSearch,
|
|
49
|
+
normalizeForFileKey: () => normalizeForFileKey,
|
|
50
|
+
normalizeForSearch: () => normalizeForSearch,
|
|
51
|
+
normalizeForSearchToken: () => normalizeForSearchToken,
|
|
52
|
+
removeAccentsAndTrim: () => removeAccentsAndTrim,
|
|
53
|
+
removeAccentsOnly: () => removeAccentsOnly,
|
|
54
|
+
shortenMongoId: () => shortenMongoId,
|
|
55
|
+
sleep: () => sleep_default
|
|
756
56
|
});
|
|
757
|
-
module.exports = __toCommonJS(
|
|
57
|
+
module.exports = __toCommonJS(index_exports);
|
|
758
58
|
|
|
759
59
|
// src/sleep.ts
|
|
760
60
|
var sleep_default = (time) => {
|
|
@@ -762,13 +62,13 @@ var sleep_default = (time) => {
|
|
|
762
62
|
};
|
|
763
63
|
|
|
764
64
|
// src/hashObject.ts
|
|
765
|
-
var import_object_hash = __toESM(
|
|
65
|
+
var import_object_hash = __toESM(require("object-hash"), 1);
|
|
766
66
|
function hashObject_default(object) {
|
|
767
|
-
return import_object_hash.default(object);
|
|
67
|
+
return (0, import_object_hash.default)(object);
|
|
768
68
|
}
|
|
769
69
|
|
|
770
70
|
// src/generateId.ts
|
|
771
|
-
var import_crypto = __toESM(require("crypto"));
|
|
71
|
+
var import_crypto = __toESM(require("crypto"), 1);
|
|
772
72
|
var UNMISTAKABLE_CHARS = "23456789ABCDEFGHJKLMNPQRSTWXYZabcdefghjkmnopqrstuvwxyz";
|
|
773
73
|
var hexString = function(digits) {
|
|
774
74
|
var numBytes = Math.ceil(digits / 2);
|
|
@@ -783,18 +83,16 @@ var hexString = function(digits) {
|
|
|
783
83
|
};
|
|
784
84
|
var fraction = function() {
|
|
785
85
|
var numerator = parseInt(hexString(8), 16);
|
|
786
|
-
return numerator *
|
|
86
|
+
return numerator * 23283064365386963e-26;
|
|
787
87
|
};
|
|
788
88
|
var choice = function(arrayOrString) {
|
|
789
89
|
var index = Math.floor(fraction() * arrayOrString.length);
|
|
790
|
-
if (typeof arrayOrString === "string")
|
|
791
|
-
|
|
792
|
-
else
|
|
793
|
-
return arrayOrString[index];
|
|
90
|
+
if (typeof arrayOrString === "string") return arrayOrString.substr(index, 1);
|
|
91
|
+
else return arrayOrString[index];
|
|
794
92
|
};
|
|
795
93
|
var randomString = function(charsCount, alphabet) {
|
|
796
94
|
var digits = [];
|
|
797
|
-
for (var i = 0;i < charsCount; i++) {
|
|
95
|
+
for (var i = 0; i < charsCount; i++) {
|
|
798
96
|
digits[i] = choice(alphabet);
|
|
799
97
|
}
|
|
800
98
|
return digits.join("");
|
|
@@ -826,17 +124,44 @@ function createMapArray(array, key = "_id") {
|
|
|
826
124
|
}
|
|
827
125
|
|
|
828
126
|
// src/Errors/OrionError.ts
|
|
829
|
-
|
|
127
|
+
var OrionError = class extends Error {
|
|
830
128
|
isOrionError = true;
|
|
831
129
|
isUserError;
|
|
832
130
|
isPermissionsError;
|
|
833
131
|
code;
|
|
834
132
|
extra;
|
|
133
|
+
/**
|
|
134
|
+
* Returns a standardized representation of the error information.
|
|
135
|
+
* @returns An object containing error details in a consistent format
|
|
136
|
+
*/
|
|
835
137
|
getInfo;
|
|
836
|
-
}
|
|
138
|
+
};
|
|
837
139
|
|
|
838
140
|
// src/Errors/PermissionsError.ts
|
|
839
|
-
|
|
141
|
+
var PermissionsError = class extends OrionError {
|
|
142
|
+
/**
|
|
143
|
+
* Creates a new PermissionsError instance.
|
|
144
|
+
*
|
|
145
|
+
* @param permissionErrorType - Identifies the specific permission that was violated
|
|
146
|
+
* (e.g., 'read', 'write', 'admin')
|
|
147
|
+
* @param extra - Additional error context or metadata. Can include a custom message
|
|
148
|
+
* via the message property.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* // Basic usage
|
|
152
|
+
* throw new PermissionsError('delete_document')
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* // With custom message
|
|
156
|
+
* throw new PermissionsError('access_admin', { message: 'Admin access required' })
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* // With additional context
|
|
160
|
+
* throw new PermissionsError('edit_user', {
|
|
161
|
+
* userId: 'user123',
|
|
162
|
+
* requiredRole: 'admin'
|
|
163
|
+
* })
|
|
164
|
+
*/
|
|
840
165
|
constructor(permissionErrorType, extra = {}) {
|
|
841
166
|
const message = extra.message || `Client is not allowed to perform this action [${permissionErrorType}]`;
|
|
842
167
|
super(message);
|
|
@@ -854,10 +179,30 @@ class PermissionsError extends OrionError {
|
|
|
854
179
|
};
|
|
855
180
|
};
|
|
856
181
|
}
|
|
857
|
-
}
|
|
182
|
+
};
|
|
858
183
|
|
|
859
184
|
// src/Errors/UserError.ts
|
|
860
|
-
|
|
185
|
+
var UserError = class extends OrionError {
|
|
186
|
+
/**
|
|
187
|
+
* Creates a new UserError instance.
|
|
188
|
+
*
|
|
189
|
+
* @param code - Error code identifier. If only one parameter is provided,
|
|
190
|
+
* this will be used as the message and code will default to 'error'.
|
|
191
|
+
* @param message - Human-readable error message. Optional if code is provided.
|
|
192
|
+
* @param extra - Additional error context or metadata.
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* // Basic usage
|
|
196
|
+
* throw new UserError('invalid_input', 'The provided email is invalid')
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* // Using only a message (code will be 'error')
|
|
200
|
+
* throw new UserError('Input validation failed')
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* // With extra metadata
|
|
204
|
+
* throw new UserError('rate_limit', 'Too many requests', { maxRequests: 100 })
|
|
205
|
+
*/
|
|
861
206
|
constructor(code, message, extra) {
|
|
862
207
|
if (!message && code) {
|
|
863
208
|
message = code;
|
|
@@ -877,39 +222,38 @@ class UserError extends OrionError {
|
|
|
877
222
|
};
|
|
878
223
|
};
|
|
879
224
|
}
|
|
880
|
-
}
|
|
225
|
+
};
|
|
881
226
|
|
|
882
227
|
// src/Errors/index.ts
|
|
883
228
|
function isOrionError(error) {
|
|
884
229
|
return Boolean(error && typeof error === "object" && error.isOrionError === true);
|
|
885
230
|
}
|
|
886
231
|
function isUserError(error) {
|
|
887
|
-
return Boolean(
|
|
232
|
+
return Boolean(
|
|
233
|
+
error && typeof error === "object" && error.isOrionError === true && error.isUserError === true
|
|
234
|
+
);
|
|
888
235
|
}
|
|
889
236
|
function isPermissionsError(error) {
|
|
890
|
-
return Boolean(
|
|
237
|
+
return Boolean(
|
|
238
|
+
error && typeof error === "object" && error.isOrionError === true && error.isPermissionsError === true
|
|
239
|
+
);
|
|
891
240
|
}
|
|
892
241
|
|
|
893
242
|
// src/composeMiddlewares.ts
|
|
894
243
|
function composeMiddlewares(middleware) {
|
|
895
|
-
if (!Array.isArray(middleware))
|
|
896
|
-
throw new TypeError("Middleware stack must be an array!");
|
|
244
|
+
if (!Array.isArray(middleware)) throw new TypeError("Middleware stack must be an array!");
|
|
897
245
|
for (const fn of middleware) {
|
|
898
|
-
if (typeof fn !== "function")
|
|
899
|
-
throw new TypeError("Middleware must be composed of functions!");
|
|
246
|
+
if (typeof fn !== "function") throw new TypeError("Middleware must be composed of functions!");
|
|
900
247
|
}
|
|
901
248
|
return function(context, next) {
|
|
902
249
|
let index = -1;
|
|
903
250
|
return dispatch(0);
|
|
904
251
|
function dispatch(i) {
|
|
905
|
-
if (i <= index)
|
|
906
|
-
return Promise.reject(new Error("next() called multiple times"));
|
|
252
|
+
if (i <= index) return Promise.reject(new Error("next() called multiple times"));
|
|
907
253
|
index = i;
|
|
908
254
|
let fn = middleware[i];
|
|
909
|
-
if (i === middleware.length)
|
|
910
|
-
|
|
911
|
-
if (!fn)
|
|
912
|
-
return Promise.resolve();
|
|
255
|
+
if (i === middleware.length) fn = next;
|
|
256
|
+
if (!fn) return Promise.resolve();
|
|
913
257
|
try {
|
|
914
258
|
return Promise.resolve(fn(context, dispatch.bind(null, i + 1)));
|
|
915
259
|
} catch (err) {
|
|
@@ -918,6 +262,7 @@ function composeMiddlewares(middleware) {
|
|
|
918
262
|
}
|
|
919
263
|
};
|
|
920
264
|
}
|
|
265
|
+
|
|
921
266
|
// src/retries.ts
|
|
922
267
|
function executeWithRetries(fn, retries, timeout) {
|
|
923
268
|
return new Promise((resolve, reject) => {
|
|
@@ -936,51 +281,93 @@ function executeWithRetries(fn, retries, timeout) {
|
|
|
936
281
|
retry(retries);
|
|
937
282
|
});
|
|
938
283
|
}
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
var
|
|
942
|
-
var
|
|
943
|
-
var
|
|
944
|
-
|
|
284
|
+
|
|
285
|
+
// ../../node_modules/uuid/dist/esm-node/rng.js
|
|
286
|
+
var import_crypto2 = __toESM(require("crypto"));
|
|
287
|
+
var rnds8Pool = new Uint8Array(256);
|
|
288
|
+
var poolPtr = rnds8Pool.length;
|
|
289
|
+
function rng() {
|
|
290
|
+
if (poolPtr > rnds8Pool.length - 16) {
|
|
291
|
+
import_crypto2.default.randomFillSync(rnds8Pool);
|
|
292
|
+
poolPtr = 0;
|
|
293
|
+
}
|
|
294
|
+
return rnds8Pool.slice(poolPtr, poolPtr += 16);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// ../../node_modules/uuid/dist/esm-node/regex.js
|
|
298
|
+
var regex_default = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
|
|
299
|
+
|
|
300
|
+
// ../../node_modules/uuid/dist/esm-node/validate.js
|
|
301
|
+
function validate(uuid) {
|
|
302
|
+
return typeof uuid === "string" && regex_default.test(uuid);
|
|
303
|
+
}
|
|
304
|
+
var validate_default = validate;
|
|
305
|
+
|
|
306
|
+
// ../../node_modules/uuid/dist/esm-node/stringify.js
|
|
307
|
+
var byteToHex = [];
|
|
308
|
+
for (let i = 0; i < 256; ++i) {
|
|
309
|
+
byteToHex.push((i + 256).toString(16).substr(1));
|
|
310
|
+
}
|
|
311
|
+
function stringify(arr, offset = 0) {
|
|
312
|
+
const uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
|
|
313
|
+
if (!validate_default(uuid)) {
|
|
314
|
+
throw TypeError("Stringified UUID is invalid");
|
|
315
|
+
}
|
|
316
|
+
return uuid;
|
|
317
|
+
}
|
|
318
|
+
var stringify_default = stringify;
|
|
319
|
+
|
|
320
|
+
// ../../node_modules/uuid/dist/esm-node/v4.js
|
|
321
|
+
function v4(options, buf, offset) {
|
|
322
|
+
options = options || {};
|
|
323
|
+
const rnds = options.random || (options.rng || rng)();
|
|
324
|
+
rnds[6] = rnds[6] & 15 | 64;
|
|
325
|
+
rnds[8] = rnds[8] & 63 | 128;
|
|
326
|
+
if (buf) {
|
|
327
|
+
offset = offset || 0;
|
|
328
|
+
for (let i = 0; i < 16; ++i) {
|
|
329
|
+
buf[offset + i] = rnds[i];
|
|
330
|
+
}
|
|
331
|
+
return buf;
|
|
332
|
+
}
|
|
333
|
+
return stringify_default(rnds);
|
|
334
|
+
}
|
|
335
|
+
var v4_default = v4;
|
|
945
336
|
|
|
946
337
|
// src/generateUUID.ts
|
|
947
338
|
function generateUUID() {
|
|
948
|
-
return
|
|
339
|
+
return v4_default();
|
|
949
340
|
}
|
|
950
341
|
function generateUUIDWithPrefix(prefix) {
|
|
951
342
|
return `${prefix}-${generateUUID()}`;
|
|
952
343
|
}
|
|
344
|
+
|
|
953
345
|
// src/normalize.ts
|
|
954
346
|
function removeAccentsOnly(text) {
|
|
955
|
-
if (!text)
|
|
956
|
-
return "";
|
|
347
|
+
if (!text) return "";
|
|
957
348
|
return text.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
|
958
349
|
}
|
|
959
350
|
function removeAccentsAndTrim(text) {
|
|
960
|
-
if (!text)
|
|
961
|
-
return "";
|
|
351
|
+
if (!text) return "";
|
|
962
352
|
return removeAccentsOnly(text).trim();
|
|
963
353
|
}
|
|
964
354
|
function normalizeForSearch(text) {
|
|
965
|
-
if (!text)
|
|
966
|
-
return "";
|
|
355
|
+
if (!text) return "";
|
|
967
356
|
return removeAccentsAndTrim(text).toLowerCase();
|
|
968
357
|
}
|
|
969
358
|
function normalizeForCompactSearch(text) {
|
|
970
|
-
if (!text)
|
|
971
|
-
return "";
|
|
359
|
+
if (!text) return "";
|
|
972
360
|
return normalizeForSearch(text).replace(/\s/g, "");
|
|
973
361
|
}
|
|
974
362
|
function normalizeForSearchToken(text) {
|
|
975
|
-
if (!text)
|
|
976
|
-
return "";
|
|
363
|
+
if (!text) return "";
|
|
977
364
|
return normalizeForSearch(text).replace(/[^0-9a-z]/gi, " ");
|
|
978
365
|
}
|
|
979
366
|
function normalizeForFileKey(text) {
|
|
980
|
-
if (!text)
|
|
981
|
-
return "";
|
|
367
|
+
if (!text) return "";
|
|
982
368
|
return removeAccentsOnly(text).replace(/[^a-zA-Z0-9-._]/g, "-").replace(/-+/g, "-").trim().replace(/^-+|-+$/g, "");
|
|
983
369
|
}
|
|
370
|
+
|
|
984
371
|
// src/searchTokens.ts
|
|
985
372
|
function getSearchTokens(text, meta) {
|
|
986
373
|
const stringArray = Array.isArray(text) ? text : [text];
|
|
@@ -1001,14 +388,13 @@ function getSearchQueryForTokens(params = {}, _options = {}) {
|
|
|
1001
388
|
searchTokens.push(...filterTokens);
|
|
1002
389
|
}
|
|
1003
390
|
for (const key in params) {
|
|
1004
|
-
if (key === "filter")
|
|
1005
|
-
|
|
1006
|
-
if (!params[key])
|
|
1007
|
-
continue;
|
|
391
|
+
if (key === "filter") continue;
|
|
392
|
+
if (!params[key]) continue;
|
|
1008
393
|
searchTokens.push(`_${key}:${params[key]}`);
|
|
1009
394
|
}
|
|
1010
395
|
return { $all: searchTokens };
|
|
1011
396
|
}
|
|
397
|
+
|
|
1012
398
|
// src/shortenMongoId.ts
|
|
1013
399
|
function lastOfString(string, last) {
|
|
1014
400
|
return string.substring(string.length - last, string.length);
|
|
@@ -1016,3 +402,31 @@ function lastOfString(string, last) {
|
|
|
1016
402
|
function shortenMongoId(string) {
|
|
1017
403
|
return lastOfString(string, 5).toUpperCase();
|
|
1018
404
|
}
|
|
405
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
406
|
+
0 && (module.exports = {
|
|
407
|
+
OrionError,
|
|
408
|
+
PermissionsError,
|
|
409
|
+
UserError,
|
|
410
|
+
composeMiddlewares,
|
|
411
|
+
createMap,
|
|
412
|
+
createMapArray,
|
|
413
|
+
executeWithRetries,
|
|
414
|
+
generateId,
|
|
415
|
+
generateUUID,
|
|
416
|
+
generateUUIDWithPrefix,
|
|
417
|
+
getSearchQueryForTokens,
|
|
418
|
+
getSearchTokens,
|
|
419
|
+
hashObject,
|
|
420
|
+
isOrionError,
|
|
421
|
+
isPermissionsError,
|
|
422
|
+
isUserError,
|
|
423
|
+
normalizeForCompactSearch,
|
|
424
|
+
normalizeForFileKey,
|
|
425
|
+
normalizeForSearch,
|
|
426
|
+
normalizeForSearchToken,
|
|
427
|
+
removeAccentsAndTrim,
|
|
428
|
+
removeAccentsOnly,
|
|
429
|
+
shortenMongoId,
|
|
430
|
+
sleep
|
|
431
|
+
});
|
|
432
|
+
//# sourceMappingURL=index.cjs.map
|