@wooksjs/express-adapter 0.0.1-alpha.0 → 0.1.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 CHANGED
@@ -9,28 +9,28 @@
9
9
  </a>
10
10
  </p>
11
11
 
12
- Want to use [Wooks Composables](https://github.com/wooksjs/composables) but your project is coupled with express? ✅ This is not a problem with this Express Adapter for [Wooks Composables](https://github.com/wooksjs/composables)
13
-
14
- 🔥 Get power of [Wooks Composables](https://github.com/wooksjs/composables) in your express project!
12
+ Want to use [@wooksjs/event-http](https://www.npmjs.com/package/@wooksjs/event-http) but your project is coupled with express? ✅ This is not a problem with this Express Adapter for [wooks](https://www.npmjs.com/package/wooks)
15
13
 
16
14
  ## Install
17
15
 
18
- `npm install @wooksjs/express-adapter`
16
+ `npm install @wooksjs/express-adapter @wooksjs/event-http`
19
17
 
20
18
  ## Usage
21
19
 
22
20
  ```ts
21
+ import express from 'express'
23
22
  import { applyExpressAdapter } from '@wooksjs/express-adapter'
24
- import { useBody } from '@wooksjs/body'
25
- import { useRouteParams, WooksError } from '@wooksjs/composables'
23
+ import { useBody } from '@wooksjs/http-body'
24
+ import { WooksError } from '@wooksjs/event-http'
25
+ import { useRouteParams } = from '@wooksjs/event-core'
26
26
 
27
27
  const app = express()
28
28
 
29
29
  applyExpressAdapter(app)
30
30
 
31
31
  app.get('/test/:param', () => {
32
- const { getRouteParam } = useRouteParams()
33
- return { message: 'it works', param: getRouteParam('param') }
32
+ const { get } = useRouteParams()
33
+ return { message: 'it works', param: get('param') }
34
34
  })
35
35
 
36
36
  app.post('/post', () => {
package/dist/index.cjs CHANGED
@@ -1,25 +1,29 @@
1
1
  'use strict';
2
2
 
3
- const composables = require('@wooksjs/composables');
3
+ const eventHttp = require('@wooksjs/event-http');
4
4
 
5
5
  const methods = [
6
6
  "get",
7
7
  "post",
8
8
  "delete",
9
+ "put",
9
10
  "patch",
10
- "options"
11
+ "options",
12
+ "head",
13
+ "all"
11
14
  ];
12
15
  function applyExpressAdapter(app) {
13
- const responder = composables.createWooksResponder();
16
+ const responder = eventHttp.createWooksResponder();
14
17
  function useWooksDecorator(fn) {
15
18
  return async () => {
16
- const { restoreCtx, clearCtx } = composables.useWooksCtx();
19
+ const { restoreCtx, clearCtx } = eventHttp.useHttpContext();
17
20
  try {
18
21
  const result = await fn();
19
22
  restoreCtx();
20
- responder.respond(result);
23
+ await responder.respond(result);
21
24
  } catch (e) {
22
- responder.respond(e);
25
+ restoreCtx();
26
+ await responder.respond(e);
23
27
  }
24
28
  clearCtx();
25
29
  };
@@ -34,7 +38,12 @@ function applyExpressAdapter(app) {
34
38
  }
35
39
  }
36
40
  function wooksContext(req, res, next) {
37
- composables.createWooksCtx({ req, res });
41
+ const { store } = eventHttp.createHttpContext({ req, res });
42
+ store("routeParams").value = new Proxy({}, {
43
+ get(target, prop, receiver) {
44
+ return req.params && req.params[prop];
45
+ }
46
+ });
38
47
  next();
39
48
  }
40
49
 
package/dist/index.mjs CHANGED
@@ -1,23 +1,27 @@
1
- import { createWooksResponder, createWooksCtx, useWooksCtx } from '@wooksjs/composables';
1
+ import { createWooksResponder, createHttpContext, useHttpContext } from '@wooksjs/event-http';
2
2
 
3
3
  const methods = [
4
4
  "get",
5
5
  "post",
6
6
  "delete",
7
+ "put",
7
8
  "patch",
8
- "options"
9
+ "options",
10
+ "head",
11
+ "all"
9
12
  ];
10
13
  function applyExpressAdapter(app) {
11
14
  const responder = createWooksResponder();
12
15
  function useWooksDecorator(fn) {
13
16
  return async () => {
14
- const { restoreCtx, clearCtx } = useWooksCtx();
17
+ const { restoreCtx, clearCtx } = useHttpContext();
15
18
  try {
16
19
  const result = await fn();
17
20
  restoreCtx();
18
- responder.respond(result);
21
+ await responder.respond(result);
19
22
  } catch (e) {
20
- responder.respond(e);
23
+ restoreCtx();
24
+ await responder.respond(e);
21
25
  }
22
26
  clearCtx();
23
27
  };
@@ -32,7 +36,12 @@ function applyExpressAdapter(app) {
32
36
  }
33
37
  }
34
38
  function wooksContext(req, res, next) {
35
- createWooksCtx({ req, res });
39
+ const { store } = createHttpContext({ req, res });
40
+ store("routeParams").value = new Proxy({}, {
41
+ get(target, prop, receiver) {
42
+ return req.params && req.params[prop];
43
+ }
44
+ });
36
45
  next();
37
46
  }
38
47
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wooksjs/express-adapter",
3
- "version": "0.0.1-alpha.0",
3
+ "version": "0.1.0",
4
4
  "description": "Express Adapter for Wooks Composables",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -59,7 +59,7 @@
59
59
  },
60
60
  "homepage": "https://github.com/wooksjs/express-adapter#readme",
61
61
  "peerDependencies": {
62
- "@wooksjs/composables": "^0.0.1-alpha.8",
62
+ "@wooksjs/event-http": "^0.1.0",
63
63
  "express": "^4.0.0"
64
64
  },
65
65
  "devDependencies": {
@@ -69,7 +69,8 @@
69
69
  "@types/node": "^18.11.0",
70
70
  "@typescript-eslint/eslint-plugin": "^5.42.0",
71
71
  "@typescript-eslint/parser": "^5.0.0",
72
- "@wooksjs/composables": "^0.0.1-alpha.8",
72
+ "@wooksjs/event-http": "^0.1.0",
73
+ "@wooksjs/http-body": "^0.1.0",
73
74
  "conventional-changelog": "^3.1.24",
74
75
  "conventional-changelog-cli": "^2.1.1",
75
76
  "enquirer": "^2.3.6",