@rvoh/psychic-websockets 0.2.2 → 0.2.4

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.
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const psychic_1 = require("@rvoh/psychic");
4
4
  const redis_adapter_1 = require("@socket.io/redis-adapter");
5
- const yoctocolors_1 = require("yoctocolors");
6
5
  const socketio = require("socket.io");
6
+ const yoctocolors_1 = require("yoctocolors");
7
7
  const MissingWsRedisConnection_js_1 = require("../error/ws/MissingWsRedisConnection.js");
8
8
  const EnvInternal_js_1 = require("../helpers/EnvInternal.js");
9
9
  const index_js_1 = require("../psychic-application-websockets/index.js");
@@ -3,10 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InvalidWsPathError = void 0;
4
4
  const dream_1 = require("@rvoh/dream");
5
5
  const redis_emitter_1 = require("@socket.io/redis-emitter");
6
- const luxon_1 = require("luxon");
7
6
  const EnvInternal_js_1 = require("../helpers/EnvInternal.js");
8
- const redisWsKey_js_1 = require("./redisWsKey.js");
9
7
  const index_js_1 = require("../psychic-application-websockets/index.js");
8
+ const redisWsKey_js_1 = require("./redisWsKey.js");
10
9
  class Ws {
11
10
  allowedPaths;
12
11
  io;
@@ -26,7 +25,7 @@ class Ws {
26
25
  .rpush(key, ...socketIdsToKeep, socket.id)
27
26
  .expireat(key,
28
27
  // TODO: make this configurable in non-test environments
29
- luxon_1.DateTime.now()
28
+ dream_1.DateTime.now()
30
29
  .plus(EnvInternal_js_1.default.isTest ? { seconds: 15 } : { day: 1 })
31
30
  .toSeconds())
32
31
  .exec();
@@ -8,7 +8,11 @@ class PsychicApplicationWebsockets {
8
8
  await cb(psychicWsApp);
9
9
  psychicApp.on('server:shutdown', async (psychicServer) => {
10
10
  const cable = psychicServer.$attached.cable;
11
- await cable?.stop();
11
+ if (cable) {
12
+ await cable.stop();
13
+ await psychicWsApp.websocketOptions.subConnection?.quit();
14
+ psychicServer.$attached.cable = undefined;
15
+ }
12
16
  });
13
17
  psychicApp.override('server:start', async (psychicServer, { port }) => {
14
18
  const cable = new index_js_1.default(psychicServer.expressApp, psychicWsApp);
@@ -63,6 +67,12 @@ class PsychicApplicationWebsockets {
63
67
  set(option, value) {
64
68
  switch (option) {
65
69
  case 'websockets':
70
+ if (this.websocketOptions?.connection) {
71
+ this.websocketOptions.connection.disconnect();
72
+ }
73
+ if (this.websocketOptions?.subConnection) {
74
+ this.websocketOptions.subConnection.disconnect();
75
+ }
66
76
  this._websocketOptions = {
67
77
  ...value,
68
78
  subConnection: value?.connection?.duplicate(),
@@ -1,7 +1,7 @@
1
1
  import { PsychicServer } from '@rvoh/psychic';
2
2
  import { createAdapter } from '@socket.io/redis-adapter';
3
- import colors from 'yoctocolors';
4
3
  import * as socketio from 'socket.io';
4
+ import colors from 'yoctocolors';
5
5
  import MissingWsRedisConnection from '../error/ws/MissingWsRedisConnection.js';
6
6
  import EnvInternal from '../helpers/EnvInternal.js';
7
7
  import PsychicApplicationWebsockets from '../psychic-application-websockets/index.js';
@@ -1,9 +1,8 @@
1
- import { uniq } from '@rvoh/dream';
1
+ import { DateTime, uniq } from '@rvoh/dream';
2
2
  import { Emitter } from '@socket.io/redis-emitter';
3
- import { DateTime } from 'luxon';
4
3
  import EnvInternal from '../helpers/EnvInternal.js';
5
- import redisWsKey from './redisWsKey.js';
6
4
  import PsychicApplicationWebsockets from '../psychic-application-websockets/index.js';
5
+ import redisWsKey from './redisWsKey.js';
7
6
  export default class Ws {
8
7
  allowedPaths;
9
8
  io;
@@ -6,7 +6,11 @@ export default class PsychicApplicationWebsockets {
6
6
  await cb(psychicWsApp);
7
7
  psychicApp.on('server:shutdown', async (psychicServer) => {
8
8
  const cable = psychicServer.$attached.cable;
9
- await cable?.stop();
9
+ if (cable) {
10
+ await cable.stop();
11
+ await psychicWsApp.websocketOptions.subConnection?.quit();
12
+ psychicServer.$attached.cable = undefined;
13
+ }
10
14
  });
11
15
  psychicApp.override('server:start', async (psychicServer, { port }) => {
12
16
  const cable = new Cable(psychicServer.expressApp, psychicWsApp);
@@ -61,6 +65,12 @@ export default class PsychicApplicationWebsockets {
61
65
  set(option, value) {
62
66
  switch (option) {
63
67
  case 'websockets':
68
+ if (this.websocketOptions?.connection) {
69
+ this.websocketOptions.connection.disconnect();
70
+ }
71
+ if (this.websocketOptions?.subConnection) {
72
+ this.websocketOptions.subConnection.disconnect();
73
+ }
64
74
  this._websocketOptions = {
65
75
  ...value,
66
76
  subConnection: value?.connection?.duplicate(),
package/package.json CHANGED
@@ -2,9 +2,12 @@
2
2
  "type": "module",
3
3
  "name": "@rvoh/psychic-websockets",
4
4
  "description": "Websocket system for Psychic applications",
5
- "version": "0.2.2",
6
- "author": "RVOHealth",
7
- "repository": "https://github.com/rvohealth/psychic-websockets.git",
5
+ "version": "0.2.4",
6
+ "author": "RVO Health",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/rvohealth/psychic-websockets.git"
10
+ },
8
11
  "license": "MIT",
9
12
  "main": "./dist/cjs/src/index.js",
10
13
  "module": "./dist/esm/src/index.js",
@@ -21,12 +24,14 @@
21
24
  ],
22
25
  "scripts": {
23
26
  "client": "yarn --cwd=./client start",
24
- "psy": "yarn psyts",
27
+ "client:fspec": "BROWSER=none VITE_PSYCHIC_ENV=test yarn --cwd=./client start",
28
+ "psy": "NODE_ENV=${NODE_ENV:-test} yarn psyts",
25
29
  "psyjs": "node ./dist/test-app/src/cli/index.js",
26
30
  "psyts": "node --experimental-specifier-resolution=node --import ./bin/esm.js ./test-app/src/cli/index.ts",
27
31
  "build": "echo \"building cjs...\" && rm -rf dist && npx tsc -p ./tsconfig.cjs.build.json && echo \"building esm...\" && npx tsc -p ./tsconfig.esm.build.json",
28
32
  "uspec": "vitest --config ./spec/unit/vite.config.ts",
29
33
  "fspec": "vitest run --config=./spec/features/vite.config.ts",
34
+ "fspec:hanging": "vitest run --config=./spec/features/vite.config.ts --reporter=hanging-process",
30
35
  "format": "yarn run prettier . --write",
31
36
  "lint": "yarn run eslint --no-warn-ignored \"src/**/*.ts\" && yarn run prettier . --check",
32
37
  "dev": "NODE_ENV=development WORKER_COUNT=0 ts-node --transpile-only ./test-app/main.ts",
@@ -43,14 +48,13 @@
43
48
  },
44
49
  "devDependencies": {
45
50
  "@eslint/js": "=9.0.0",
46
- "@rvoh/dream": "^0.31.0",
51
+ "@rvoh/dream": "^0.35.0",
47
52
  "@rvoh/dream-spec-helpers": "^0.2.0",
48
- "@rvoh/psychic": "^0.25.0",
53
+ "@rvoh/psychic": "^0.28.3",
49
54
  "@rvoh/psychic-spec-helpers": "^0.2.0",
50
55
  "@socket.io/redis-adapter": "^8.3.0",
51
56
  "@socket.io/redis-emitter": "^5.1.0",
52
57
  "@types/express": "^4",
53
- "@types/luxon": "^3.4.2",
54
58
  "@types/node": "^22.5.1",
55
59
  "@types/pg": "^8",
56
60
  "@types/supertest": "^6.0.2",
@@ -60,7 +64,6 @@
60
64
  "ioredis": "^5.4.1",
61
65
  "kysely": "^0.27.5",
62
66
  "kysely-codegen": "^0.17.0",
63
- "luxon": "^3.5.0",
64
67
  "luxon-jest-matchers": "^0.1.14",
65
68
  "pg": "^8.13.1",
66
69
  "prettier": "^3.3.3",
@@ -72,11 +75,11 @@
72
75
  "ts-node": "^10.9.2",
73
76
  "tslib": "^2.7.0",
74
77
  "typedoc": "^0.26.6",
75
- "typescript": "^5.5.4",
78
+ "typescript": "^5.8.2",
76
79
  "typescript-eslint": "=7.18.0",
77
- "vitest": "^3.0.8"
80
+ "vitest": "^3.1.1"
78
81
  },
79
- "packageManager": "yarn@4.4.1",
82
+ "packageManager": "yarn@4.7.0",
80
83
  "dependencies": {
81
84
  "yoctocolors": "^2.1.1"
82
85
  }