@quark-fw/plugin 0.0.1 → 0.0.2

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.
Files changed (2) hide show
  1. package/README.md +43 -0
  2. package/package.json +8 -4
package/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # @quark-fw/plugin
2
+
3
+ Plugin contract for the Quark framework, plus a shared registry of Express HTTP middleware that server plugins mount into.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm i @quark-fw/plugin
9
+ ```
10
+
11
+ ## Plugin contract
12
+
13
+ A Quark plugin is a plain object registered on the global `quark` (created by [`@quark-fw/core`](https://www.npmjs.com/package/@quark-fw/core)):
14
+
15
+ ```ts
16
+ import type { QuarkPlugin } from "@quark-fw/plugin";
17
+
18
+ const myPlugin: QuarkPlugin = {
19
+ name: "my-plugin",
20
+ dependsOn: ["prisma"], // optional: plugins that must load first
21
+ atoms: {}, // atoms the plugin contributes to quark
22
+ extend(quark) {}, // add methods/fields to quark
23
+ onInit(quark) {}, // lifecycle hooks
24
+ onReady(quark) {},
25
+ onDestroy(quark) {},
26
+ onEvent: { "plugin:init": (p) => {} },
27
+ };
28
+
29
+ await quark.registerPlugin(myPlugin);
30
+ ```
31
+
32
+ ## HTTP middleware registry
33
+
34
+ `@quark-fw/plugin/http.js` is a side-effect-free module holding two live Express routers. Plugins register routes at any time; the HTTP server mounts the routers once:
35
+
36
+ ```ts
37
+ import { registerHttpMiddleware, registerHttpPreMiddleware } from "@quark-fw/plugin/http.js";
38
+
39
+ registerHttpPreMiddleware(sessionMiddleware); // runs before all handlers
40
+ registerHttpMiddleware("/api/hello", (req, res) => res.json({ ok: true }));
41
+ ```
42
+
43
+ `express` is an optional peer dependency — it is only required if you import the `http.js` module.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quark-fw/plugin",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Plugin contract and loader for the Quark framework",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -14,19 +14,23 @@
14
14
  "./src/*": "./dist/*",
15
15
  "./*": "./dist/*"
16
16
  },
17
- "files": ["dist"],
17
+ "files": [
18
+ "dist"
19
+ ],
18
20
  "scripts": {
19
21
  "dev": "tsx watch src/index.ts",
20
22
  "build": "tsc -p tsconfig.build.json && node ../../scripts/postbuild.mjs"
21
23
  },
22
- "keywords": ["quark"],
24
+ "keywords": [
25
+ "quark"
26
+ ],
23
27
  "author": "",
24
28
  "license": "ISC",
25
29
  "publishConfig": {
26
30
  "access": "public"
27
31
  },
28
32
  "dependencies": {
29
- "@quark-fw/atom": "0.0.1"
33
+ "@quark-fw/atom": "0.0.2"
30
34
  },
31
35
  "peerDependencies": {
32
36
  "express": "^5.0.0"