@atom8n/utils 1.21.0
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/README.md +25 -0
- package/dist/assert.cjs +3 -0
- package/dist/assert.d.cts +2 -0
- package/dist/assert.d.mts +2 -0
- package/dist/assert.mjs +3 -0
- package/dist/assert2.cjs +17 -0
- package/dist/assert2.cjs.map +1 -0
- package/dist/assert2.d.cts +5 -0
- package/dist/assert2.d.mts +5 -0
- package/dist/assert2.mjs +11 -0
- package/dist/assert2.mjs.map +1 -0
- package/dist/event-bus.cjs +3 -0
- package/dist/event-bus.d.cts +2 -0
- package/dist/event-bus.d.mts +2 -0
- package/dist/event-bus.mjs +3 -0
- package/dist/event-bus2.cjs +49 -0
- package/dist/event-bus2.cjs.map +1 -0
- package/dist/event-bus2.d.cts +14 -0
- package/dist/event-bus2.d.mts +14 -0
- package/dist/event-bus2.mjs +43 -0
- package/dist/event-bus2.mjs.map +1 -0
- package/dist/event-queue.cjs +3 -0
- package/dist/event-queue.d.cts +2 -0
- package/dist/event-queue.d.mts +2 -0
- package/dist/event-queue.mjs +3 -0
- package/dist/event-queue2.cjs +46 -0
- package/dist/event-queue2.cjs.map +1 -0
- package/dist/event-queue2.d.cts +7 -0
- package/dist/event-queue2.d.mts +7 -0
- package/dist/event-queue2.mjs +40 -0
- package/dist/event-queue2.mjs.map +1 -0
- package/dist/files/sanitize.cjs +3 -0
- package/dist/files/sanitize.d.cts +2 -0
- package/dist/files/sanitize.d.mts +2 -0
- package/dist/files/sanitize.mjs +3 -0
- package/dist/index.cjs +23 -0
- package/dist/index.d.cts +11 -0
- package/dist/index.d.mts +11 -0
- package/dist/index.mjs +12 -0
- package/dist/number/smartDecimal.cjs +3 -0
- package/dist/number/smartDecimal.d.cts +2 -0
- package/dist/number/smartDecimal.d.mts +2 -0
- package/dist/number/smartDecimal.mjs +3 -0
- package/dist/reRankSearchResults.cjs +25 -0
- package/dist/reRankSearchResults.cjs.map +1 -0
- package/dist/reRankSearchResults.d.cts +13 -0
- package/dist/reRankSearchResults.d.mts +13 -0
- package/dist/reRankSearchResults.mjs +19 -0
- package/dist/reRankSearchResults.mjs.map +1 -0
- package/dist/retry.cjs +3 -0
- package/dist/retry.d.cts +2 -0
- package/dist/retry.d.mts +2 -0
- package/dist/retry.mjs +3 -0
- package/dist/retry2.cjs +45 -0
- package/dist/retry2.cjs.map +1 -0
- package/dist/retry2.d.cts +6 -0
- package/dist/retry2.d.mts +6 -0
- package/dist/retry2.mjs +39 -0
- package/dist/retry2.mjs.map +1 -0
- package/dist/sanitize.cjs +67 -0
- package/dist/sanitize.cjs.map +1 -0
- package/dist/sanitize.d.cts +5 -0
- package/dist/sanitize.d.mts +5 -0
- package/dist/sanitize.mjs +61 -0
- package/dist/sanitize.mjs.map +1 -0
- package/dist/search/reRankSearchResults.cjs +3 -0
- package/dist/search/reRankSearchResults.d.cts +2 -0
- package/dist/search/reRankSearchResults.d.mts +2 -0
- package/dist/search/reRankSearchResults.mjs +3 -0
- package/dist/search/sublimeSearch.cjs +4 -0
- package/dist/search/sublimeSearch.d.cts +2 -0
- package/dist/search/sublimeSearch.d.mts +2 -0
- package/dist/search/sublimeSearch.mjs +3 -0
- package/dist/smartDecimal.cjs +16 -0
- package/dist/smartDecimal.cjs.map +1 -0
- package/dist/smartDecimal.d.cts +5 -0
- package/dist/smartDecimal.d.mts +5 -0
- package/dist/smartDecimal.mjs +10 -0
- package/dist/smartDecimal.mjs.map +1 -0
- package/dist/sort/sortByProperty.cjs +3 -0
- package/dist/sort/sortByProperty.d.cts +2 -0
- package/dist/sort/sortByProperty.d.mts +2 -0
- package/dist/sort/sortByProperty.mjs +3 -0
- package/dist/sortByProperty.cjs +18 -0
- package/dist/sortByProperty.cjs.map +1 -0
- package/dist/sortByProperty.d.cts +5 -0
- package/dist/sortByProperty.d.mts +5 -0
- package/dist/sortByProperty.mjs +12 -0
- package/dist/sortByProperty.mjs.map +1 -0
- package/dist/string/truncate.cjs +4 -0
- package/dist/string/truncate.d.cts +2 -0
- package/dist/string/truncate.d.mts +2 -0
- package/dist/string/truncate.mjs +3 -0
- package/dist/sublimeSearch.cjs +183 -0
- package/dist/sublimeSearch.cjs.map +1 -0
- package/dist/sublimeSearch.d.cts +15 -0
- package/dist/sublimeSearch.d.mts +15 -0
- package/dist/sublimeSearch.mjs +171 -0
- package/dist/sublimeSearch.mjs.map +1 -0
- package/dist/truncate.cjs +42 -0
- package/dist/truncate.cjs.map +1 -0
- package/dist/truncate.d.cts +6 -0
- package/dist/truncate.d.mts +6 -0
- package/dist/truncate.mjs +30 -0
- package/dist/truncate.mjs.map +1 -0
- package/package.json +53 -0
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# @n8n/utils
|
|
2
|
+
|
|
3
|
+
A collection of utility functions that provide common functionality for both Front-End and Back-End packages.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Features](#features)
|
|
8
|
+
- [Contributing](#contributing)
|
|
9
|
+
- [License](#license)
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Reusable Logic**: Build complex, stateful functionality using modular composable functions that you can easily reuse.
|
|
14
|
+
- **Consistent Patterns**: Enjoy a unified approach across n8n packages, making integration and maintenance a breeze.
|
|
15
|
+
- **Type-Safe & Reliable**: Benefit from TypeScript support, which improves the developer experience and code robustness.
|
|
16
|
+
- **Universal Functionality**: Designed to work seamlessly on both the front-end and back-end.
|
|
17
|
+
- **Easily Testable**: A modular design that simplifies testing, maintenance, and rapid development.
|
|
18
|
+
|
|
19
|
+
## Contributing
|
|
20
|
+
|
|
21
|
+
For more details, please read our [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
22
|
+
|
|
23
|
+
## License
|
|
24
|
+
|
|
25
|
+
For more details, please read our [LICENSE.md](LICENSE.md).
|
package/dist/assert.cjs
ADDED
package/dist/assert.mjs
ADDED
package/dist/assert2.cjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/assert.ts
|
|
3
|
+
/**
|
|
4
|
+
* Asserts given condition
|
|
5
|
+
*/
|
|
6
|
+
function assert(condition, message) {
|
|
7
|
+
if (!condition) throw new Error(message ?? "Assertion failed");
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
Object.defineProperty(exports, 'assert', {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () {
|
|
14
|
+
return assert;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
//# sourceMappingURL=assert2.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert2.cjs","names":[],"sources":["../src/assert.ts"],"sourcesContent":["/**\n * Asserts given condition\n */\nexport function assert(condition: unknown, message?: string): asserts condition {\n\tif (!condition) {\n\t\t// eslint-disable-next-line n8n-local-rules/no-plain-errors\n\t\tthrow new Error(message ?? 'Assertion failed');\n\t}\n}\n"],"mappings":";;;;;AAGA,SAAgB,OAAO,WAAoB,SAAqC;AAC/E,KAAI,CAAC,UAEJ,OAAM,IAAI,MAAM,WAAW,mBAAmB"}
|
package/dist/assert2.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert2.mjs","names":[],"sources":["../src/assert.ts"],"sourcesContent":["/**\n * Asserts given condition\n */\nexport function assert(condition: unknown, message?: string): asserts condition {\n\tif (!condition) {\n\t\t// eslint-disable-next-line n8n-local-rules/no-plain-errors\n\t\tthrow new Error(message ?? 'Assertion failed');\n\t}\n}\n"],"mappings":";;;;AAGA,SAAgB,OAAO,WAAoB,SAAqC;AAC/E,KAAI,CAAC,UAEJ,OAAM,IAAI,MAAM,WAAW,mBAAmB"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/event-bus.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates an event bus with the given listener map.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* const eventBus = createEventBus<{
|
|
9
|
+
* 'user-logged-in': { username: string };
|
|
10
|
+
* 'user-logged-out': never;
|
|
11
|
+
* }>();
|
|
12
|
+
*/
|
|
13
|
+
function createEventBus() {
|
|
14
|
+
const handlers = /* @__PURE__ */ new Map();
|
|
15
|
+
return {
|
|
16
|
+
on(eventName, fn) {
|
|
17
|
+
let eventFns = handlers.get(eventName);
|
|
18
|
+
if (!eventFns) eventFns = [fn];
|
|
19
|
+
else eventFns.push(fn);
|
|
20
|
+
handlers.set(eventName, eventFns);
|
|
21
|
+
},
|
|
22
|
+
once(eventName, fn) {
|
|
23
|
+
const handler = (payload) => {
|
|
24
|
+
this.off(eventName, handler);
|
|
25
|
+
fn(payload);
|
|
26
|
+
};
|
|
27
|
+
this.on(eventName, handler);
|
|
28
|
+
},
|
|
29
|
+
off(eventName, fn) {
|
|
30
|
+
const eventFns = handlers.get(eventName);
|
|
31
|
+
if (eventFns) eventFns.splice(eventFns.indexOf(fn) >>> 0, 1);
|
|
32
|
+
},
|
|
33
|
+
emit(eventName, event) {
|
|
34
|
+
const eventFns = handlers.get(eventName);
|
|
35
|
+
if (eventFns) eventFns.slice().forEach((handler) => {
|
|
36
|
+
handler(event);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
Object.defineProperty(exports, 'createEventBus', {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () {
|
|
46
|
+
return createEventBus;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=event-bus2.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-bus2.cjs","names":["handler: typeof fn"],"sources":["../src/event-bus.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type CallbackFn = (...args: any[]) => any;\n\ntype Payloads<ListenerMap> = {\n\t[E in keyof ListenerMap]: unknown;\n};\n\ntype Listener<Payload> = (payload: Payload) => void;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface EventBus<ListenerMap extends Payloads<ListenerMap> = Record<string, any>> {\n\ton<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tfn: Listener<ListenerMap[EventName]>,\n\t): void;\n\n\tonce<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tfn: Listener<ListenerMap[EventName]>,\n\t): void;\n\n\toff<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tfn: Listener<ListenerMap[EventName]>,\n\t): void;\n\n\temit<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tevent?: ListenerMap[EventName],\n\t): void;\n}\n\n/**\n * Creates an event bus with the given listener map.\n *\n * @example\n * ```ts\n * const eventBus = createEventBus<{\n * 'user-logged-in': { username: string };\n * 'user-logged-out': never;\n * }>();\n */\nexport function createEventBus<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tListenerMap extends Payloads<ListenerMap> = Record<string, any>,\n>(): EventBus<ListenerMap> {\n\tconst handlers = new Map<string, CallbackFn[]>();\n\n\treturn {\n\t\ton(eventName, fn) {\n\t\t\tlet eventFns = handlers.get(eventName);\n\t\t\tif (!eventFns) {\n\t\t\t\teventFns = [fn];\n\t\t\t} else {\n\t\t\t\teventFns.push(fn);\n\t\t\t}\n\t\t\thandlers.set(eventName, eventFns);\n\t\t},\n\n\t\tonce(eventName, fn) {\n\t\t\tconst handler: typeof fn = (payload) => {\n\t\t\t\tthis.off(eventName, handler);\n\t\t\t\tfn(payload);\n\t\t\t};\n\t\t\tthis.on(eventName, handler);\n\t\t},\n\n\t\toff(eventName, fn) {\n\t\t\tconst eventFns = handlers.get(eventName);\n\t\t\tif (eventFns) {\n\t\t\t\teventFns.splice(eventFns.indexOf(fn) >>> 0, 1);\n\t\t\t}\n\t\t},\n\n\t\temit(eventName, event) {\n\t\t\tconst eventFns = handlers.get(eventName);\n\t\t\tif (eventFns) {\n\t\t\t\teventFns.slice().forEach((handler) => {\n\t\t\t\t\thandler(event);\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;;;;;;AA0CA,SAAgB,iBAGW;CAC1B,MAAM,2BAAW,IAAI,KAA2B;AAEhD,QAAO;EACN,GAAG,WAAW,IAAI;GACjB,IAAI,WAAW,SAAS,IAAI,UAAU;AACtC,OAAI,CAAC,SACJ,YAAW,CAAC,GAAG;OAEf,UAAS,KAAK,GAAG;AAElB,YAAS,IAAI,WAAW,SAAS;;EAGlC,KAAK,WAAW,IAAI;GACnB,MAAMA,WAAsB,YAAY;AACvC,SAAK,IAAI,WAAW,QAAQ;AAC5B,OAAG,QAAQ;;AAEZ,QAAK,GAAG,WAAW,QAAQ;;EAG5B,IAAI,WAAW,IAAI;GAClB,MAAM,WAAW,SAAS,IAAI,UAAU;AACxC,OAAI,SACH,UAAS,OAAO,SAAS,QAAQ,GAAG,KAAK,GAAG,EAAE;;EAIhD,KAAK,WAAW,OAAO;GACtB,MAAM,WAAW,SAAS,IAAI,UAAU;AACxC,OAAI,SACH,UAAS,OAAO,CAAC,SAAS,YAAY;AACrC,YAAQ,MAAM;KACb;;EAGJ"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/event-bus.d.ts
|
|
2
|
+
type CallbackFn = (...args: any[]) => any;
|
|
3
|
+
type Payloads<ListenerMap> = { [E in keyof ListenerMap]: unknown };
|
|
4
|
+
type Listener<Payload> = (payload: Payload) => void;
|
|
5
|
+
interface EventBus<ListenerMap extends Payloads<ListenerMap> = Record<string, any>> {
|
|
6
|
+
on<EventName extends keyof ListenerMap & string>(eventName: EventName, fn: Listener<ListenerMap[EventName]>): void;
|
|
7
|
+
once<EventName extends keyof ListenerMap & string>(eventName: EventName, fn: Listener<ListenerMap[EventName]>): void;
|
|
8
|
+
off<EventName extends keyof ListenerMap & string>(eventName: EventName, fn: Listener<ListenerMap[EventName]>): void;
|
|
9
|
+
emit<EventName extends keyof ListenerMap & string>(eventName: EventName, event?: ListenerMap[EventName]): void;
|
|
10
|
+
}
|
|
11
|
+
declare function createEventBus<ListenerMap extends Payloads<ListenerMap> = Record<string, any>>(): EventBus<ListenerMap>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { EventBus as n, createEventBus as r, CallbackFn as t };
|
|
14
|
+
//# sourceMappingURL=event-bus2.d.cts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/event-bus.d.ts
|
|
2
|
+
type CallbackFn = (...args: any[]) => any;
|
|
3
|
+
type Payloads<ListenerMap> = { [E in keyof ListenerMap]: unknown };
|
|
4
|
+
type Listener<Payload> = (payload: Payload) => void;
|
|
5
|
+
interface EventBus<ListenerMap extends Payloads<ListenerMap> = Record<string, any>> {
|
|
6
|
+
on<EventName extends keyof ListenerMap & string>(eventName: EventName, fn: Listener<ListenerMap[EventName]>): void;
|
|
7
|
+
once<EventName extends keyof ListenerMap & string>(eventName: EventName, fn: Listener<ListenerMap[EventName]>): void;
|
|
8
|
+
off<EventName extends keyof ListenerMap & string>(eventName: EventName, fn: Listener<ListenerMap[EventName]>): void;
|
|
9
|
+
emit<EventName extends keyof ListenerMap & string>(eventName: EventName, event?: ListenerMap[EventName]): void;
|
|
10
|
+
}
|
|
11
|
+
declare function createEventBus<ListenerMap extends Payloads<ListenerMap> = Record<string, any>>(): EventBus<ListenerMap>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { EventBus as n, createEventBus as r, CallbackFn as t };
|
|
14
|
+
//# sourceMappingURL=event-bus2.d.mts.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
//#region src/event-bus.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates an event bus with the given listener map.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* const eventBus = createEventBus<{
|
|
8
|
+
* 'user-logged-in': { username: string };
|
|
9
|
+
* 'user-logged-out': never;
|
|
10
|
+
* }>();
|
|
11
|
+
*/
|
|
12
|
+
function createEventBus() {
|
|
13
|
+
const handlers = /* @__PURE__ */ new Map();
|
|
14
|
+
return {
|
|
15
|
+
on(eventName, fn) {
|
|
16
|
+
let eventFns = handlers.get(eventName);
|
|
17
|
+
if (!eventFns) eventFns = [fn];
|
|
18
|
+
else eventFns.push(fn);
|
|
19
|
+
handlers.set(eventName, eventFns);
|
|
20
|
+
},
|
|
21
|
+
once(eventName, fn) {
|
|
22
|
+
const handler = (payload) => {
|
|
23
|
+
this.off(eventName, handler);
|
|
24
|
+
fn(payload);
|
|
25
|
+
};
|
|
26
|
+
this.on(eventName, handler);
|
|
27
|
+
},
|
|
28
|
+
off(eventName, fn) {
|
|
29
|
+
const eventFns = handlers.get(eventName);
|
|
30
|
+
if (eventFns) eventFns.splice(eventFns.indexOf(fn) >>> 0, 1);
|
|
31
|
+
},
|
|
32
|
+
emit(eventName, event) {
|
|
33
|
+
const eventFns = handlers.get(eventName);
|
|
34
|
+
if (eventFns) eventFns.slice().forEach((handler) => {
|
|
35
|
+
handler(event);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
export { createEventBus as t };
|
|
43
|
+
//# sourceMappingURL=event-bus2.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-bus2.mjs","names":["handler: typeof fn"],"sources":["../src/event-bus.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type CallbackFn = (...args: any[]) => any;\n\ntype Payloads<ListenerMap> = {\n\t[E in keyof ListenerMap]: unknown;\n};\n\ntype Listener<Payload> = (payload: Payload) => void;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface EventBus<ListenerMap extends Payloads<ListenerMap> = Record<string, any>> {\n\ton<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tfn: Listener<ListenerMap[EventName]>,\n\t): void;\n\n\tonce<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tfn: Listener<ListenerMap[EventName]>,\n\t): void;\n\n\toff<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tfn: Listener<ListenerMap[EventName]>,\n\t): void;\n\n\temit<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tevent?: ListenerMap[EventName],\n\t): void;\n}\n\n/**\n * Creates an event bus with the given listener map.\n *\n * @example\n * ```ts\n * const eventBus = createEventBus<{\n * 'user-logged-in': { username: string };\n * 'user-logged-out': never;\n * }>();\n */\nexport function createEventBus<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tListenerMap extends Payloads<ListenerMap> = Record<string, any>,\n>(): EventBus<ListenerMap> {\n\tconst handlers = new Map<string, CallbackFn[]>();\n\n\treturn {\n\t\ton(eventName, fn) {\n\t\t\tlet eventFns = handlers.get(eventName);\n\t\t\tif (!eventFns) {\n\t\t\t\teventFns = [fn];\n\t\t\t} else {\n\t\t\t\teventFns.push(fn);\n\t\t\t}\n\t\t\thandlers.set(eventName, eventFns);\n\t\t},\n\n\t\tonce(eventName, fn) {\n\t\t\tconst handler: typeof fn = (payload) => {\n\t\t\t\tthis.off(eventName, handler);\n\t\t\t\tfn(payload);\n\t\t\t};\n\t\t\tthis.on(eventName, handler);\n\t\t},\n\n\t\toff(eventName, fn) {\n\t\t\tconst eventFns = handlers.get(eventName);\n\t\t\tif (eventFns) {\n\t\t\t\teventFns.splice(eventFns.indexOf(fn) >>> 0, 1);\n\t\t\t}\n\t\t},\n\n\t\temit(eventName, event) {\n\t\t\tconst eventFns = handlers.get(eventName);\n\t\t\tif (eventFns) {\n\t\t\t\teventFns.slice().forEach((handler) => {\n\t\t\t\t\thandler(event);\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;;;;;AA0CA,SAAgB,iBAGW;CAC1B,MAAM,2BAAW,IAAI,KAA2B;AAEhD,QAAO;EACN,GAAG,WAAW,IAAI;GACjB,IAAI,WAAW,SAAS,IAAI,UAAU;AACtC,OAAI,CAAC,SACJ,YAAW,CAAC,GAAG;OAEf,UAAS,KAAK,GAAG;AAElB,YAAS,IAAI,WAAW,SAAS;;EAGlC,KAAK,WAAW,IAAI;GACnB,MAAMA,WAAsB,YAAY;AACvC,SAAK,IAAI,WAAW,QAAQ;AAC5B,OAAG,QAAQ;;AAEZ,QAAK,GAAG,WAAW,QAAQ;;EAG5B,IAAI,WAAW,IAAI;GAClB,MAAM,WAAW,SAAS,IAAI,UAAU;AACxC,OAAI,SACH,UAAS,OAAO,SAAS,QAAQ,GAAG,KAAK,GAAG,EAAE;;EAIhD,KAAK,WAAW,OAAO;GACtB,MAAM,WAAW,SAAS,IAAI,UAAU;AACxC,OAAI,SACH,UAAS,OAAO,CAAC,SAAS,YAAY;AACrC,YAAQ,MAAM;KACb;;EAGJ"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/event-queue.ts
|
|
3
|
+
/**
|
|
4
|
+
* Create an event queue that processes events sequentially.
|
|
5
|
+
*
|
|
6
|
+
* @param processEvent - Async function that processes a single event.
|
|
7
|
+
* @returns A function that enqueues events for processing.
|
|
8
|
+
*/
|
|
9
|
+
function createEventQueue(processEvent) {
|
|
10
|
+
const queue = [];
|
|
11
|
+
let processing = false;
|
|
12
|
+
/**
|
|
13
|
+
* Process the next event in the queue (if not already processing).
|
|
14
|
+
*/
|
|
15
|
+
async function processNext() {
|
|
16
|
+
if (processing || queue.length === 0) return;
|
|
17
|
+
processing = true;
|
|
18
|
+
const currentEvent = queue.shift();
|
|
19
|
+
if (currentEvent !== void 0) try {
|
|
20
|
+
await processEvent(currentEvent);
|
|
21
|
+
} catch (error) {
|
|
22
|
+
console.error("Error processing event:", error);
|
|
23
|
+
}
|
|
24
|
+
processing = false;
|
|
25
|
+
await processNext();
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Enqueue an event and trigger processing.
|
|
29
|
+
*
|
|
30
|
+
* @param event - The event to enqueue.
|
|
31
|
+
*/
|
|
32
|
+
function enqueue(event) {
|
|
33
|
+
queue.push(event);
|
|
34
|
+
processNext();
|
|
35
|
+
}
|
|
36
|
+
return { enqueue };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
Object.defineProperty(exports, 'createEventQueue', {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
get: function () {
|
|
43
|
+
return createEventQueue;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
//# sourceMappingURL=event-queue2.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-queue2.cjs","names":["queue: T[]"],"sources":["../src/event-queue.ts"],"sourcesContent":["/**\n * Create an event queue that processes events sequentially.\n *\n * @param processEvent - Async function that processes a single event.\n * @returns A function that enqueues events for processing.\n */\nexport function createEventQueue<T>(processEvent: (event: T) => Promise<void>) {\n\t// The internal queue holding events.\n\tconst queue: T[] = [];\n\n\t// Flag to indicate whether an event is currently being processed.\n\tlet processing = false;\n\n\t/**\n\t * Process the next event in the queue (if not already processing).\n\t */\n\tasync function processNext(): Promise<void> {\n\t\tif (processing || queue.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tprocessing = true;\n\t\tconst currentEvent = queue.shift();\n\n\t\tif (currentEvent !== undefined) {\n\t\t\ttry {\n\t\t\t\tawait processEvent(currentEvent);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error('Error processing event:', error);\n\t\t\t}\n\t\t}\n\n\t\tprocessing = false;\n\n\t\t// Recursively process the next event.\n\t\tawait processNext();\n\t}\n\n\t/**\n\t * Enqueue an event and trigger processing.\n\t *\n\t * @param event - The event to enqueue.\n\t */\n\tfunction enqueue(event: T): void {\n\t\tqueue.push(event);\n\t\tvoid processNext();\n\t}\n\n\treturn { enqueue };\n}\n"],"mappings":";;;;;;;;AAMA,SAAgB,iBAAoB,cAA2C;CAE9E,MAAMA,QAAa,EAAE;CAGrB,IAAI,aAAa;;;;CAKjB,eAAe,cAA6B;AAC3C,MAAI,cAAc,MAAM,WAAW,EAClC;AAGD,eAAa;EACb,MAAM,eAAe,MAAM,OAAO;AAElC,MAAI,iBAAiB,OACpB,KAAI;AACH,SAAM,aAAa,aAAa;WACxB,OAAO;AACf,WAAQ,MAAM,2BAA2B,MAAM;;AAIjD,eAAa;AAGb,QAAM,aAAa;;;;;;;CAQpB,SAAS,QAAQ,OAAgB;AAChC,QAAM,KAAK,MAAM;AACjB,EAAK,aAAa;;AAGnB,QAAO,EAAE,SAAS"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
//#region src/event-queue.ts
|
|
2
|
+
/**
|
|
3
|
+
* Create an event queue that processes events sequentially.
|
|
4
|
+
*
|
|
5
|
+
* @param processEvent - Async function that processes a single event.
|
|
6
|
+
* @returns A function that enqueues events for processing.
|
|
7
|
+
*/
|
|
8
|
+
function createEventQueue(processEvent) {
|
|
9
|
+
const queue = [];
|
|
10
|
+
let processing = false;
|
|
11
|
+
/**
|
|
12
|
+
* Process the next event in the queue (if not already processing).
|
|
13
|
+
*/
|
|
14
|
+
async function processNext() {
|
|
15
|
+
if (processing || queue.length === 0) return;
|
|
16
|
+
processing = true;
|
|
17
|
+
const currentEvent = queue.shift();
|
|
18
|
+
if (currentEvent !== void 0) try {
|
|
19
|
+
await processEvent(currentEvent);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
console.error("Error processing event:", error);
|
|
22
|
+
}
|
|
23
|
+
processing = false;
|
|
24
|
+
await processNext();
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Enqueue an event and trigger processing.
|
|
28
|
+
*
|
|
29
|
+
* @param event - The event to enqueue.
|
|
30
|
+
*/
|
|
31
|
+
function enqueue(event) {
|
|
32
|
+
queue.push(event);
|
|
33
|
+
processNext();
|
|
34
|
+
}
|
|
35
|
+
return { enqueue };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { createEventQueue as t };
|
|
40
|
+
//# sourceMappingURL=event-queue2.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-queue2.mjs","names":["queue: T[]"],"sources":["../src/event-queue.ts"],"sourcesContent":["/**\n * Create an event queue that processes events sequentially.\n *\n * @param processEvent - Async function that processes a single event.\n * @returns A function that enqueues events for processing.\n */\nexport function createEventQueue<T>(processEvent: (event: T) => Promise<void>) {\n\t// The internal queue holding events.\n\tconst queue: T[] = [];\n\n\t// Flag to indicate whether an event is currently being processed.\n\tlet processing = false;\n\n\t/**\n\t * Process the next event in the queue (if not already processing).\n\t */\n\tasync function processNext(): Promise<void> {\n\t\tif (processing || queue.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tprocessing = true;\n\t\tconst currentEvent = queue.shift();\n\n\t\tif (currentEvent !== undefined) {\n\t\t\ttry {\n\t\t\t\tawait processEvent(currentEvent);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error('Error processing event:', error);\n\t\t\t}\n\t\t}\n\n\t\tprocessing = false;\n\n\t\t// Recursively process the next event.\n\t\tawait processNext();\n\t}\n\n\t/**\n\t * Enqueue an event and trigger processing.\n\t *\n\t * @param event - The event to enqueue.\n\t */\n\tfunction enqueue(event: T): void {\n\t\tqueue.push(event);\n\t\tvoid processNext();\n\t}\n\n\treturn { enqueue };\n}\n"],"mappings":";;;;;;;AAMA,SAAgB,iBAAoB,cAA2C;CAE9E,MAAMA,QAAa,EAAE;CAGrB,IAAI,aAAa;;;;CAKjB,eAAe,cAA6B;AAC3C,MAAI,cAAc,MAAM,WAAW,EAClC;AAGD,eAAa;EACb,MAAM,eAAe,MAAM,OAAO;AAElC,MAAI,iBAAiB,OACpB,KAAI;AACH,SAAM,aAAa,aAAa;WACxB,OAAO;AACf,WAAQ,MAAM,2BAA2B,MAAM;;AAIjD,eAAa;AAGb,QAAM,aAAa;;;;;;;CAQpB,SAAS,QAAQ,OAAgB;AAChC,QAAM,KAAK,MAAM;AACjB,EAAK,aAAa;;AAGnB,QAAO,EAAE,SAAS"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const require_assert = require('./assert2.cjs');
|
|
2
|
+
const require_event_bus = require('./event-bus2.cjs');
|
|
3
|
+
const require_event_queue = require('./event-queue2.cjs');
|
|
4
|
+
const require_retry = require('./retry2.cjs');
|
|
5
|
+
const require_smartDecimal = require('./smartDecimal.cjs');
|
|
6
|
+
const require_reRankSearchResults = require('./reRankSearchResults.cjs');
|
|
7
|
+
const require_sublimeSearch = require('./sublimeSearch.cjs');
|
|
8
|
+
const require_sortByProperty = require('./sortByProperty.cjs');
|
|
9
|
+
const require_truncate = require('./truncate.cjs');
|
|
10
|
+
const require_sanitize = require('./sanitize.cjs');
|
|
11
|
+
|
|
12
|
+
exports.DEFAULT_KEYS = require_sublimeSearch.DEFAULT_KEYS;
|
|
13
|
+
exports.assert = require_assert.assert;
|
|
14
|
+
exports.createEventBus = require_event_bus.createEventBus;
|
|
15
|
+
exports.createEventQueue = require_event_queue.createEventQueue;
|
|
16
|
+
exports.reRankSearchResults = require_reRankSearchResults.reRankSearchResults;
|
|
17
|
+
exports.retry = require_retry.retry;
|
|
18
|
+
exports.sanitizeFilename = require_sanitize.sanitizeFilename;
|
|
19
|
+
exports.smartDecimal = require_smartDecimal.smartDecimal;
|
|
20
|
+
exports.sortByProperty = require_sortByProperty.sortByProperty;
|
|
21
|
+
exports.sublimeSearch = require_sublimeSearch.sublimeSearch;
|
|
22
|
+
exports.truncate = require_truncate.truncate;
|
|
23
|
+
exports.truncateBeforeLast = require_truncate.truncateBeforeLast;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { t as assert } from "./assert2.cjs";
|
|
2
|
+
import { n as EventBus, r as createEventBus, t as CallbackFn } from "./event-bus2.cjs";
|
|
3
|
+
import { t as createEventQueue } from "./event-queue2.cjs";
|
|
4
|
+
import { t as sanitizeFilename } from "./sanitize.cjs";
|
|
5
|
+
import { t as retry } from "./retry2.cjs";
|
|
6
|
+
import { t as smartDecimal } from "./smartDecimal.cjs";
|
|
7
|
+
import { t as reRankSearchResults } from "./reRankSearchResults.cjs";
|
|
8
|
+
import { n as sublimeSearch, t as DEFAULT_KEYS } from "./sublimeSearch.cjs";
|
|
9
|
+
import { t as sortByProperty } from "./sortByProperty.cjs";
|
|
10
|
+
import { n as truncateBeforeLast, t as truncate } from "./truncate.cjs";
|
|
11
|
+
export { CallbackFn, DEFAULT_KEYS, EventBus, assert, createEventBus, createEventQueue, reRankSearchResults, retry, sanitizeFilename, smartDecimal, sortByProperty, sublimeSearch, truncate, truncateBeforeLast };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { t as assert } from "./assert2.mjs";
|
|
2
|
+
import { n as EventBus, r as createEventBus, t as CallbackFn } from "./event-bus2.mjs";
|
|
3
|
+
import { t as createEventQueue } from "./event-queue2.mjs";
|
|
4
|
+
import { t as sanitizeFilename } from "./sanitize.mjs";
|
|
5
|
+
import { t as retry } from "./retry2.mjs";
|
|
6
|
+
import { t as smartDecimal } from "./smartDecimal.mjs";
|
|
7
|
+
import { t as reRankSearchResults } from "./reRankSearchResults.mjs";
|
|
8
|
+
import { n as sublimeSearch, t as DEFAULT_KEYS } from "./sublimeSearch.mjs";
|
|
9
|
+
import { t as sortByProperty } from "./sortByProperty.mjs";
|
|
10
|
+
import { n as truncateBeforeLast, t as truncate } from "./truncate.mjs";
|
|
11
|
+
export { CallbackFn, DEFAULT_KEYS, EventBus, assert, createEventBus, createEventQueue, reRankSearchResults, retry, sanitizeFilename, smartDecimal, sortByProperty, sublimeSearch, truncate, truncateBeforeLast };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { t as assert } from "./assert2.mjs";
|
|
2
|
+
import { t as createEventBus } from "./event-bus2.mjs";
|
|
3
|
+
import { t as createEventQueue } from "./event-queue2.mjs";
|
|
4
|
+
import { t as retry } from "./retry2.mjs";
|
|
5
|
+
import { t as smartDecimal } from "./smartDecimal.mjs";
|
|
6
|
+
import { t as reRankSearchResults } from "./reRankSearchResults.mjs";
|
|
7
|
+
import { n as sublimeSearch, t as DEFAULT_KEYS } from "./sublimeSearch.mjs";
|
|
8
|
+
import { t as sortByProperty } from "./sortByProperty.mjs";
|
|
9
|
+
import { n as truncateBeforeLast, t as truncate } from "./truncate.mjs";
|
|
10
|
+
import { t as sanitizeFilename } from "./sanitize.mjs";
|
|
11
|
+
|
|
12
|
+
export { DEFAULT_KEYS, assert, createEventBus, createEventQueue, reRankSearchResults, retry, sanitizeFilename, smartDecimal, sortByProperty, sublimeSearch, truncate, truncateBeforeLast };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/search/reRankSearchResults.ts
|
|
3
|
+
function reRankSearchResults(searchResults, additionalFactors) {
|
|
4
|
+
return searchResults.map(({ score, item }) => {
|
|
5
|
+
return {
|
|
6
|
+
score: score + Object.entries(additionalFactors).reduce((acc, [_, factorScores]) => {
|
|
7
|
+
const factorScore = factorScores[item.key];
|
|
8
|
+
if (factorScore) return acc + factorScore;
|
|
9
|
+
return acc;
|
|
10
|
+
}, 0),
|
|
11
|
+
item
|
|
12
|
+
};
|
|
13
|
+
}).sort((a, b) => {
|
|
14
|
+
return b.score - a.score;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
Object.defineProperty(exports, 'reRankSearchResults', {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () {
|
|
22
|
+
return reRankSearchResults;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
//# sourceMappingURL=reRankSearchResults.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reRankSearchResults.cjs","names":[],"sources":["../src/search/reRankSearchResults.ts"],"sourcesContent":["export function reRankSearchResults<T extends { key: string }>(\n\tsearchResults: Array<{ score: number; item: T }>,\n\tadditionalFactors: Record<string, Record<string, number>>,\n): Array<{ score: number; item: T }> {\n\treturn searchResults\n\t\t.map(({ score, item }) => {\n\t\t\t// For each additional factor, we check if it exists for the item and type,\n\t\t\t// and if so, we add the score to the item's score.\n\t\t\tconst additionalScore = Object.entries(additionalFactors).reduce((acc, [_, factorScores]) => {\n\t\t\t\tconst factorScore = factorScores[item.key];\n\t\t\t\tif (factorScore) {\n\t\t\t\t\treturn acc + factorScore;\n\t\t\t\t}\n\n\t\t\t\treturn acc;\n\t\t\t}, 0);\n\n\t\t\treturn {\n\t\t\t\tscore: score + additionalScore,\n\t\t\t\titem,\n\t\t\t};\n\t\t})\n\t\t.sort((a, b) => {\n\t\t\treturn b.score - a.score;\n\t\t});\n}\n"],"mappings":";;AAAA,SAAgB,oBACf,eACA,mBACoC;AACpC,QAAO,cACL,KAAK,EAAE,OAAO,WAAW;AAYzB,SAAO;GACN,OAAO,QAVgB,OAAO,QAAQ,kBAAkB,CAAC,QAAQ,KAAK,CAAC,GAAG,kBAAkB;IAC5F,MAAM,cAAc,aAAa,KAAK;AACtC,QAAI,YACH,QAAO,MAAM;AAGd,WAAO;MACL,EAAE;GAIJ;GACA;GACA,CACD,MAAM,GAAG,MAAM;AACf,SAAO,EAAE,QAAQ,EAAE;GAClB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/search/reRankSearchResults.d.ts
|
|
2
|
+
declare function reRankSearchResults<T extends {
|
|
3
|
+
key: string;
|
|
4
|
+
}>(searchResults: Array<{
|
|
5
|
+
score: number;
|
|
6
|
+
item: T;
|
|
7
|
+
}>, additionalFactors: Record<string, Record<string, number>>): Array<{
|
|
8
|
+
score: number;
|
|
9
|
+
item: T;
|
|
10
|
+
}>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { reRankSearchResults as t };
|
|
13
|
+
//# sourceMappingURL=reRankSearchResults.d.cts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/search/reRankSearchResults.d.ts
|
|
2
|
+
declare function reRankSearchResults<T extends {
|
|
3
|
+
key: string;
|
|
4
|
+
}>(searchResults: Array<{
|
|
5
|
+
score: number;
|
|
6
|
+
item: T;
|
|
7
|
+
}>, additionalFactors: Record<string, Record<string, number>>): Array<{
|
|
8
|
+
score: number;
|
|
9
|
+
item: T;
|
|
10
|
+
}>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { reRankSearchResults as t };
|
|
13
|
+
//# sourceMappingURL=reRankSearchResults.d.mts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/search/reRankSearchResults.ts
|
|
2
|
+
function reRankSearchResults(searchResults, additionalFactors) {
|
|
3
|
+
return searchResults.map(({ score, item }) => {
|
|
4
|
+
return {
|
|
5
|
+
score: score + Object.entries(additionalFactors).reduce((acc, [_, factorScores]) => {
|
|
6
|
+
const factorScore = factorScores[item.key];
|
|
7
|
+
if (factorScore) return acc + factorScore;
|
|
8
|
+
return acc;
|
|
9
|
+
}, 0),
|
|
10
|
+
item
|
|
11
|
+
};
|
|
12
|
+
}).sort((a, b) => {
|
|
13
|
+
return b.score - a.score;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { reRankSearchResults as t };
|
|
19
|
+
//# sourceMappingURL=reRankSearchResults.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reRankSearchResults.mjs","names":[],"sources":["../src/search/reRankSearchResults.ts"],"sourcesContent":["export function reRankSearchResults<T extends { key: string }>(\n\tsearchResults: Array<{ score: number; item: T }>,\n\tadditionalFactors: Record<string, Record<string, number>>,\n): Array<{ score: number; item: T }> {\n\treturn searchResults\n\t\t.map(({ score, item }) => {\n\t\t\t// For each additional factor, we check if it exists for the item and type,\n\t\t\t// and if so, we add the score to the item's score.\n\t\t\tconst additionalScore = Object.entries(additionalFactors).reduce((acc, [_, factorScores]) => {\n\t\t\t\tconst factorScore = factorScores[item.key];\n\t\t\t\tif (factorScore) {\n\t\t\t\t\treturn acc + factorScore;\n\t\t\t\t}\n\n\t\t\t\treturn acc;\n\t\t\t}, 0);\n\n\t\t\treturn {\n\t\t\t\tscore: score + additionalScore,\n\t\t\t\titem,\n\t\t\t};\n\t\t})\n\t\t.sort((a, b) => {\n\t\t\treturn b.score - a.score;\n\t\t});\n}\n"],"mappings":";AAAA,SAAgB,oBACf,eACA,mBACoC;AACpC,QAAO,cACL,KAAK,EAAE,OAAO,WAAW;AAYzB,SAAO;GACN,OAAO,QAVgB,OAAO,QAAQ,kBAAkB,CAAC,QAAQ,KAAK,CAAC,GAAG,kBAAkB;IAC5F,MAAM,cAAc,aAAa,KAAK;AACtC,QAAI,YACH,QAAO,MAAM;AAGd,WAAO;MACL,EAAE;GAIJ;GACA;GACA,CACD,MAAM,GAAG,MAAM;AACf,SAAO,EAAE,QAAQ,EAAE;GAClB"}
|
package/dist/retry.cjs
ADDED
package/dist/retry.d.cts
ADDED
package/dist/retry.d.mts
ADDED
package/dist/retry.mjs
ADDED