@jayfong/x-server 1.20.0 → 1.22.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/CHANGELOG.md CHANGED
@@ -2,6 +2,27 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [1.22.0](https://github.com/jfWorks/x-server/compare/v1.21.0...v1.22.0) (2022-05-01)
6
+
7
+
8
+ ### Features
9
+
10
+ * **cors:** allowAll ([5ce4b5d](https://github.com/jfWorks/x-server/commit/5ce4b5d9183f68a32173d77de569f00c5409ccdc))
11
+
12
+ ## [1.21.0](https://github.com/jfWorks/x-server/compare/v1.20.1...v1.21.0) (2022-04-29)
13
+
14
+
15
+ ### Features
16
+
17
+ * export * from '@prisma/client' ([3e6c707](https://github.com/jfWorks/x-server/commit/3e6c707d55bad0cbb719f1b76bdd306ef0527ba1))
18
+
19
+ ### [1.20.1](https://github.com/jfWorks/x-server/compare/v1.20.0...v1.20.1) (2022-04-27)
20
+
21
+
22
+ ### Bug Fixes
23
+
24
+ * res == null ? ({} as any) : res ([ea0c531](https://github.com/jfWorks/x-server/commit/ea0c531524636cf9a92e43646fb37bd57b6148d7))
25
+
5
26
  ## [1.20.0](https://github.com/jfWorks/x-server/compare/v1.19.0...v1.20.0) (2022-04-27)
6
27
 
7
28
 
@@ -20,3 +20,5 @@ function makeBaseModel<TModelName extends ModelName>(name: TModelName) {
20
20
 
21
21
  // @index('../.prisma/client/index.d.ts', /(?<=const ModelName:).+?(?=\})/s, /(\S+?):/g, (m, _) => `export const ${_.pascal(m[1])}BaseModel = makeBaseModel('${_.camel(m[1])}')`)
22
22
  // @endindex
23
+
24
+ export * from '@prisma/client'
@@ -54,7 +54,7 @@ class Handler {
54
54
  res = _vtils.DataPacker.packAsRawType(res);
55
55
  }
56
56
 
57
- return res;
57
+ return res == null ? {} : res;
58
58
  };
59
59
 
60
60
  this.handleWs = async (data, ctx) => {
@@ -21,9 +21,10 @@ class CorsPlugin {
21
21
 
22
22
  register(fastify) {
23
23
  const allows = this.options.allow.map(item => ({
24
- type: item.startsWith('*.') ? 'endsWith' : 'equal',
24
+ type: item === '*' ? 'all' : item.startsWith('*.') ? 'endsWith' : 'equal',
25
25
  domain: item.startsWith('*.') ? item.replace('*.', '.') : item
26
26
  }));
27
+ const allowAll = allows.length === 1 && allows[0].type === 'all';
27
28
  const check = (0, _vtils.memoize)(origin => {
28
29
  let i = origin.indexOf(':');
29
30
  let j = origin.indexOf(':', i + 1);
@@ -34,7 +35,7 @@ class CorsPlugin {
34
35
  return pass;
35
36
  });
36
37
  fastify.register(_fastifyCors.default, {
37
- origin: (origin, cb) => cb(null, origin ? check(origin) : true),
38
+ origin: (origin, cb) => allowAll ? cb(null, true) : cb(null, origin ? check(origin) : true),
38
39
  maxAge: (0, _date.ms)(this.options.ttl, true)
39
40
  });
40
41
  }
@@ -20,3 +20,5 @@ function makeBaseModel<TModelName extends ModelName>(name: TModelName) {
20
20
 
21
21
  // @index('../.prisma/client/index.d.ts', /(?<=const ModelName:).+?(?=\})/s, /(\S+?):/g, (m, _) => `export const ${_.pascal(m[1])}BaseModel = makeBaseModel('${_.camel(m[1])}')`)
22
22
  // @endindex
23
+
24
+ export * from '@prisma/client'
@@ -45,7 +45,7 @@ export class Handler {
45
45
  res = DataPacker.packAsRawType(res);
46
46
  }
47
47
 
48
- return res;
48
+ return res == null ? {} : res;
49
49
  };
50
50
 
51
51
  this.handleWs = async (data, ctx) => {
@@ -12,9 +12,10 @@ export class CorsPlugin {
12
12
 
13
13
  register(fastify) {
14
14
  const allows = this.options.allow.map(item => ({
15
- type: item.startsWith('*.') ? 'endsWith' : 'equal',
15
+ type: item === '*' ? 'all' : item.startsWith('*.') ? 'endsWith' : 'equal',
16
16
  domain: item.startsWith('*.') ? item.replace('*.', '.') : item
17
17
  }));
18
+ const allowAll = allows.length === 1 && allows[0].type === 'all';
18
19
  const check = memoize(origin => {
19
20
  let i = origin.indexOf(':');
20
21
  let j = origin.indexOf(':', i + 1);
@@ -25,7 +26,7 @@ export class CorsPlugin {
25
26
  return pass;
26
27
  });
27
28
  fastify.register(FastifyCors, {
28
- origin: (origin, cb) => cb(null, origin ? check(origin) : true),
29
+ origin: (origin, cb) => allowAll ? cb(null, true) : cb(null, origin ? check(origin) : true),
29
30
  maxAge: ms(this.options.ttl, true)
30
31
  });
31
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "1.20.0",
3
+ "version": "1.22.0",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",