corebasic 1.0.144 → 1.0.145

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/index.js CHANGED
@@ -8,6 +8,7 @@ import * as Session from './libs/session.js'
8
8
  import * as Auth from './libs/auth.js'
9
9
  import * as Features from './libs/features.js'
10
10
  import * as Messaging from './libs/messaging.js'
11
+ import * as Compression from './libs/compression.js'
11
12
 
12
13
  export {
13
14
  Elabase,
@@ -17,5 +18,6 @@ export {
17
18
  Session,
18
19
  Auth,
19
20
  Features,
20
- Messaging
21
+ Messaging,
22
+ Compression
21
23
  }
@@ -0,0 +1,13 @@
1
+ import * as Utils from './utils.js'
2
+ import compression from 'compression'
3
+
4
+ // Compression Notes
5
+ // -----------------
6
+ // Default compression gzip. Compressed server responses will have header set with `Content-Encoding: gzip` before sending to client
7
+ // Curl cpr library by default announces compression capability by specifying header `Accept-Encoding`. Meaning client is able to decompress compressed response. Then server can compress responses if needed
8
+ // Regarding Client compressing data send to server, I think if server has `Content-Encoding: gzip` set, then client might compress before sending. But not sure. Need to check.
9
+ // Http Stream or ServerSideEvents require res.flush() after res.write(). res.flush function is added by the express compression middleware
10
+
11
+ export const start = app => {
12
+ app.use(Utils.excludeMiddleware(compression({threshold: 1024}))) // Response above 1024 bytes should be compressed. Default is also 1KB
13
+ }
package/libs/messaging.js CHANGED
@@ -38,8 +38,11 @@ async function connect({user,req,res, uid}) {
38
38
  const listener = (message, channel) => {
39
39
  if (users_pool[user]) {
40
40
  try {message = JSON.parse(message)} catch {}
41
- for (let {req, res} of users_pool[user].reqres)
41
+ for (let {req, res} of users_pool[user].reqres) {
42
42
  res.write(JSON.stringify({message, channel}) + "\n")
43
+ if (res.flush) // If compression enabled
44
+ res.flush()
45
+ }
43
46
  }
44
47
  }
45
48
  users_pool[user] = users_pool[user] ?? {reqres: [], listeners: {count: 0}}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "corebasic",
3
3
  "type": "module",
4
- "version": "1.0.144",
4
+ "version": "1.0.145",
5
5
  "description": "",
6
6
  "main": "index.js",
7
7
  "scripts": {
@@ -13,6 +13,7 @@
13
13
  "@aws-sdk/client-s3": "^3.398.0",
14
14
  "@aws-sdk/s3-request-presigner": "^3.398.0",
15
15
  "axios": "^1.4.0",
16
+ "compression": "^1.7.4",
16
17
  "jsonminify": "^0.4.2",
17
18
  "jsonwebtoken": "^9.0.1",
18
19
  "otp-generator": "^4.0.1",