rura 1.0.2 → 1.0.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/dist/index.cjs +24 -5
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +24 -5
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -19,22 +19,41 @@ async function runRura(ctx, hooks) {
|
|
|
19
19
|
|
|
20
20
|
// src/create-rura.ts
|
|
21
21
|
function createRura(initialHooks = []) {
|
|
22
|
-
const hooks = [...initialHooks];
|
|
22
|
+
const hooks = [...initialHooks].map((el) => applyDefaultOrder(el));
|
|
23
|
+
function applyDefaultOrder(h) {
|
|
24
|
+
return { ...h, order: h.order ?? 0 };
|
|
25
|
+
}
|
|
26
|
+
function sortHooks() {
|
|
27
|
+
hooks.sort((a, b) => a.order - b.order);
|
|
28
|
+
}
|
|
23
29
|
function use(hook) {
|
|
24
|
-
hooks.push(hook);
|
|
30
|
+
hooks.push(applyDefaultOrder(hook));
|
|
31
|
+
sortHooks();
|
|
25
32
|
return api;
|
|
26
33
|
}
|
|
27
34
|
function merge(other) {
|
|
28
|
-
other.getHooks().forEach((h) => hooks.push(h));
|
|
35
|
+
other.getHooks().forEach((h) => hooks.push(applyDefaultOrder(h)));
|
|
36
|
+
sortHooks();
|
|
29
37
|
return api;
|
|
30
38
|
}
|
|
31
39
|
function getHooks() {
|
|
32
|
-
return hooks;
|
|
40
|
+
return [...hooks];
|
|
41
|
+
}
|
|
42
|
+
function debugHooks() {
|
|
43
|
+
console.log(`
|
|
44
|
+
\u{1F4A7} Rura Pipeline (${hooks.length} hooks)`);
|
|
45
|
+
console.log("\u2500\u2500\u2500");
|
|
46
|
+
hooks.forEach(({ name, order }, i) => {
|
|
47
|
+
const paddedOrder = String(order).padStart(4, " ");
|
|
48
|
+
console.log(`${i + 1}. order: ${paddedOrder} | name: ${name}`);
|
|
49
|
+
});
|
|
50
|
+
console.log("\u2500\u2500\u2500\n");
|
|
33
51
|
}
|
|
34
52
|
async function run(ctx) {
|
|
35
53
|
return runRura(ctx, hooks);
|
|
36
54
|
}
|
|
37
|
-
const api = { use, merge, getHooks, run };
|
|
55
|
+
const api = { use, merge, getHooks, debugHooks, run };
|
|
56
|
+
sortHooks();
|
|
38
57
|
return api;
|
|
39
58
|
}
|
|
40
59
|
|
package/dist/index.d.cts
CHANGED
|
@@ -15,6 +15,7 @@ declare function createRura<Context = unknown, Output = unknown>(initialHooks?:
|
|
|
15
15
|
use: (hook: Hook<Context, Output>) => /*elided*/ any;
|
|
16
16
|
merge: (other: ReturnType<typeof createRura<Context, Output>>) => /*elided*/ any;
|
|
17
17
|
getHooks: () => Hook<Context, Output>[];
|
|
18
|
+
debugHooks: () => void;
|
|
18
19
|
run: (ctx: Context) => Promise<Context | Output>;
|
|
19
20
|
};
|
|
20
21
|
|
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ declare function createRura<Context = unknown, Output = unknown>(initialHooks?:
|
|
|
15
15
|
use: (hook: Hook<Context, Output>) => /*elided*/ any;
|
|
16
16
|
merge: (other: ReturnType<typeof createRura<Context, Output>>) => /*elided*/ any;
|
|
17
17
|
getHooks: () => Hook<Context, Output>[];
|
|
18
|
+
debugHooks: () => void;
|
|
18
19
|
run: (ctx: Context) => Promise<Context | Output>;
|
|
19
20
|
};
|
|
20
21
|
|
package/dist/index.js
CHANGED
|
@@ -17,22 +17,41 @@ async function runRura(ctx, hooks) {
|
|
|
17
17
|
|
|
18
18
|
// src/create-rura.ts
|
|
19
19
|
function createRura(initialHooks = []) {
|
|
20
|
-
const hooks = [...initialHooks];
|
|
20
|
+
const hooks = [...initialHooks].map((el) => applyDefaultOrder(el));
|
|
21
|
+
function applyDefaultOrder(h) {
|
|
22
|
+
return { ...h, order: h.order ?? 0 };
|
|
23
|
+
}
|
|
24
|
+
function sortHooks() {
|
|
25
|
+
hooks.sort((a, b) => a.order - b.order);
|
|
26
|
+
}
|
|
21
27
|
function use(hook) {
|
|
22
|
-
hooks.push(hook);
|
|
28
|
+
hooks.push(applyDefaultOrder(hook));
|
|
29
|
+
sortHooks();
|
|
23
30
|
return api;
|
|
24
31
|
}
|
|
25
32
|
function merge(other) {
|
|
26
|
-
other.getHooks().forEach((h) => hooks.push(h));
|
|
33
|
+
other.getHooks().forEach((h) => hooks.push(applyDefaultOrder(h)));
|
|
34
|
+
sortHooks();
|
|
27
35
|
return api;
|
|
28
36
|
}
|
|
29
37
|
function getHooks() {
|
|
30
|
-
return hooks;
|
|
38
|
+
return [...hooks];
|
|
39
|
+
}
|
|
40
|
+
function debugHooks() {
|
|
41
|
+
console.log(`
|
|
42
|
+
\u{1F4A7} Rura Pipeline (${hooks.length} hooks)`);
|
|
43
|
+
console.log("\u2500\u2500\u2500");
|
|
44
|
+
hooks.forEach(({ name, order }, i) => {
|
|
45
|
+
const paddedOrder = String(order).padStart(4, " ");
|
|
46
|
+
console.log(`${i + 1}. order: ${paddedOrder} | name: ${name}`);
|
|
47
|
+
});
|
|
48
|
+
console.log("\u2500\u2500\u2500\n");
|
|
31
49
|
}
|
|
32
50
|
async function run(ctx) {
|
|
33
51
|
return runRura(ctx, hooks);
|
|
34
52
|
}
|
|
35
|
-
const api = { use, merge, getHooks, run };
|
|
53
|
+
const api = { use, merge, getHooks, debugHooks, run };
|
|
54
|
+
sortHooks();
|
|
36
55
|
return api;
|
|
37
56
|
}
|
|
38
57
|
|