@rhythmjs/rhythm 0.0.21 → 0.0.22
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/compose.js +1 -1
- package/dist/mount.js +1 -1
- package/dist/pipeline.js +2 -2
- package/dist/{rhythm-vpajpf9k.js → rhythm-5wyfm5pt.js} +1 -1
- package/dist/rhythm-eybt80rf.js +31 -0
- package/dist/rhythm-yg6xk73t.js +28 -0
- package/dist/rhythm.js +11 -9
- package/package.json +10 -7
- package/dist/rhythm-5w3dm83b.js +0 -20
- package/dist/rhythm-bhjtktgq.js +0 -25
package/dist/compose.js
CHANGED
package/dist/mount.js
CHANGED
package/dist/pipeline.js
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
withSource2
|
|
4
|
+
} from "./rhythm-7z989406.js";
|
|
5
|
+
import {
|
|
6
|
+
wrapFailure
|
|
7
|
+
} from "./rhythm-vd616d70.js";
|
|
8
|
+
|
|
9
|
+
// src/mount.ts
|
|
10
|
+
function mount2(plugin, condition) {
|
|
11
|
+
const handler = plugin.callback();
|
|
12
|
+
const wrap = (cause) => {
|
|
13
|
+
throw wrapFailure("mounted", plugin, cause);
|
|
14
|
+
};
|
|
15
|
+
const middleware = (ctx, next) => {
|
|
16
|
+
try {
|
|
17
|
+
if (condition && !condition(ctx))
|
|
18
|
+
return next();
|
|
19
|
+
} catch (cause) {
|
|
20
|
+
return Promise.reject(cause);
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
return handler(ctx).then(() => next(), wrap);
|
|
24
|
+
} catch (cause) {
|
|
25
|
+
return Promise.reject(wrapFailure("mounted", plugin, cause));
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
return withSource2(middleware, plugin);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { mount2 };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/compose.ts
|
|
3
|
+
var done = Promise.resolve();
|
|
4
|
+
function compose2(middleware) {
|
|
5
|
+
const last = middleware.length;
|
|
6
|
+
return (ctx, next) => {
|
|
7
|
+
if (last === 0)
|
|
8
|
+
return next ? next() : done;
|
|
9
|
+
let index = -1;
|
|
10
|
+
function dispatch(i) {
|
|
11
|
+
if (i <= index)
|
|
12
|
+
return Promise.reject(new Error("next() called multiple times"));
|
|
13
|
+
index = i;
|
|
14
|
+
const fn = i === last ? next : middleware[i];
|
|
15
|
+
if (!fn)
|
|
16
|
+
return done;
|
|
17
|
+
try {
|
|
18
|
+
const result = fn(ctx, () => dispatch(i + 1));
|
|
19
|
+
return result instanceof Promise ? result : Promise.resolve(result);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
return Promise.reject(error);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return dispatch(0);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { compose2 };
|
package/dist/rhythm.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
3
|
compose2
|
|
4
|
-
} from "./rhythm-
|
|
4
|
+
} from "./rhythm-yg6xk73t.js";
|
|
5
5
|
import {
|
|
6
6
|
withSource2,
|
|
7
7
|
sourceOf2
|
|
8
8
|
} from "./rhythm-7z989406.js";
|
|
9
9
|
import {
|
|
10
10
|
Pipeline2
|
|
11
|
-
} from "./rhythm-
|
|
11
|
+
} from "./rhythm-5wyfm5pt.js";
|
|
12
12
|
import {
|
|
13
13
|
decorate2
|
|
14
14
|
} from "./rhythm-k0635rcp.js";
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
} from "./rhythm-bq68je0h.js";
|
|
21
21
|
import {
|
|
22
22
|
mount2
|
|
23
|
-
} from "./rhythm-
|
|
23
|
+
} from "./rhythm-eybt80rf.js";
|
|
24
24
|
|
|
25
25
|
// src/rhythm.ts
|
|
26
26
|
class Rhythm extends Pipeline2 {
|
|
@@ -76,13 +76,15 @@ class Rhythm extends Pipeline2 {
|
|
|
76
76
|
}
|
|
77
77
|
callback() {
|
|
78
78
|
const fn = this.chain();
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
const run = (input) => {
|
|
80
|
+
try {
|
|
81
|
+
const ctx = Object.assign({}, this.#ctx, input);
|
|
82
|
+
return fn(ctx).then(() => ctx);
|
|
83
|
+
} catch (error) {
|
|
84
|
+
return Promise.reject(error);
|
|
85
|
+
}
|
|
85
86
|
};
|
|
87
|
+
return (input) => this.#ready ? this.#ready.then(() => run(input)) : run(input);
|
|
86
88
|
}
|
|
87
89
|
}
|
|
88
90
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rhythmjs/rhythm",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.22",
|
|
4
4
|
"description": "A minimal, type-safe middleware and startup-composition kernel: register() at startup, use() per request, with derive, decorate, mount and include.",
|
|
5
5
|
"homepage": "https://rhythm.js.org/rhythm",
|
|
6
6
|
"license": "ISC",
|
|
@@ -56,6 +56,14 @@
|
|
|
56
56
|
"publishConfig": {
|
|
57
57
|
"access": "public"
|
|
58
58
|
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"clean": "rm -rf dist",
|
|
61
|
+
"prebuild": "bun run clean",
|
|
62
|
+
"build": "bun build src/rhythm.ts src/compose.ts src/pipeline.ts src/derive.ts src/decorate.ts src/mount.ts src/include.ts src/source.ts src/types.ts --outdir dist --root src --format esm --target bun --packages external --splitting && tsc -p tsconfig.build.json",
|
|
63
|
+
"prepublishOnly": "bun run typecheck && bun test && bun run build",
|
|
64
|
+
"typecheck": "tsc --noEmit",
|
|
65
|
+
"test": "bun test"
|
|
66
|
+
},
|
|
59
67
|
"devDependencies": {
|
|
60
68
|
"@types/bun": "^1.4.2",
|
|
61
69
|
"@types/node": "^26.6.3",
|
|
@@ -63,10 +71,5 @@
|
|
|
63
71
|
},
|
|
64
72
|
"engines": {
|
|
65
73
|
"bun": ">=1.2.0"
|
|
66
|
-
},
|
|
67
|
-
"scripts": {
|
|
68
|
-
"build": "rm -rf dist && bun build src/rhythm.ts src/compose.ts src/pipeline.ts src/derive.ts src/decorate.ts src/mount.ts src/include.ts src/source.ts src/types.ts --outdir dist --root src --format esm --target bun --packages external --splitting && tsc -p tsconfig.build.json",
|
|
69
|
-
"typecheck": "tsc --noEmit",
|
|
70
|
-
"test": "bun test"
|
|
71
74
|
}
|
|
72
|
-
}
|
|
75
|
+
}
|
package/dist/rhythm-5w3dm83b.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
// src/compose.ts
|
|
3
|
-
function compose2(middleware) {
|
|
4
|
-
return (ctx, next) => {
|
|
5
|
-
let index = -1;
|
|
6
|
-
async function dispatch(i) {
|
|
7
|
-
if (i <= index) {
|
|
8
|
-
throw new Error("next() called multiple times");
|
|
9
|
-
}
|
|
10
|
-
index = i;
|
|
11
|
-
const fn = i === middleware.length ? next : middleware[i];
|
|
12
|
-
if (!fn)
|
|
13
|
-
return;
|
|
14
|
-
await fn(ctx, () => dispatch(i + 1));
|
|
15
|
-
}
|
|
16
|
-
return dispatch(0);
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export { compose2 };
|
package/dist/rhythm-bhjtktgq.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import {
|
|
3
|
-
withSource2
|
|
4
|
-
} from "./rhythm-7z989406.js";
|
|
5
|
-
import {
|
|
6
|
-
wrapFailure
|
|
7
|
-
} from "./rhythm-vd616d70.js";
|
|
8
|
-
|
|
9
|
-
// src/mount.ts
|
|
10
|
-
function mount2(plugin, condition) {
|
|
11
|
-
const handler = plugin.callback();
|
|
12
|
-
const middleware = async (ctx, next) => {
|
|
13
|
-
if (!condition || condition(ctx)) {
|
|
14
|
-
try {
|
|
15
|
-
await handler(ctx);
|
|
16
|
-
} catch (cause) {
|
|
17
|
-
throw wrapFailure("mounted", plugin, cause);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
await next();
|
|
21
|
-
};
|
|
22
|
-
return withSource2(middleware, plugin);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export { mount2 };
|