@thzero/black-meridian-library_common 0.0.0-stage → 0.1.6
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 +71 -2
- package/constants.js +35 -0
- package/data/settingsUser.js +12 -0
- package/data/user.js +28 -0
- package/data/userGame.js +17 -0
- package/license.md +9 -0
- package/package.json +26 -3
- package/test/constants.test.js +32 -0
- package/test/user.test.js +32 -0
package/README.md
CHANGED
|
@@ -1,3 +1,72 @@
|
|
|
1
|
-
|
|
1
|
+

|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# black-meridian-library_common
|
|
4
|
+
|
|
5
|
+
Shared constants and data classes for the Black Meridian servers. It has no server or browser dependencies beyond `@thzero/library_common`, so both servers and clients can import it.
|
|
6
|
+
|
|
7
|
+
Used by `server_auth`, `server_vessel` and `server_zone`.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
[](https://npmjs.org/package/@thzero/black-meridian-library_common)
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @thzero/black-meridian-library_common
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Requires Node.js 24 or later. The package is an ES module.
|
|
18
|
+
|
|
19
|
+
## Contents
|
|
20
|
+
|
|
21
|
+
| Path | What it is |
|
|
22
|
+
| --- | --- |
|
|
23
|
+
| `constants.js` | `PubSub.Channels`: the channel names vessels and zones use (`enter`, plus builders for `changes`, `space`, `vessel` and `zone`). `Timing`: tick and message rates (Hz) and the enter, lost and drop timeouts (seconds). |
|
|
24
|
+
| `data/user.js` | `UserData`, which extends `@thzero/library_common`'s base user with `gameData`, and creates `Settings` for its settings. |
|
|
25
|
+
| `data/settingsUser.js` | `Settings`, the user settings with `games` and `gameSystems`. |
|
|
26
|
+
| `data/userGame.js` | `UserGameData`, a player's stats: badges, kills, deaths, victories, rating and the factions, mechs and scenarios played. |
|
|
27
|
+
|
|
28
|
+
There is no `index.js`, so import files by path:
|
|
29
|
+
|
|
30
|
+
```js
|
|
31
|
+
import Constants from '@thzero/black-meridian-library_common/constants.js';
|
|
32
|
+
import UserData from '@thzero/black-meridian-library_common/data/user.js';
|
|
33
|
+
|
|
34
|
+
const channel = Constants.PubSub.Channels.zone(gameId, zoneId);
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Development
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm install
|
|
41
|
+
npm test
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Tests use the built-in `node --test` runner and live in `test/`.
|
|
45
|
+
|
|
46
|
+
| Script | What it does |
|
|
47
|
+
| --- | --- |
|
|
48
|
+
| `version.sh` / `version.bat` | Bumps the version in `package.json` with `library-cli` (`npm install -g @thzero/library_cli`). |
|
|
49
|
+
| `push.sh` / `push.bat` | Adds, commits and pushes with the given message. |
|
|
50
|
+
| `pushversion.sh` / `pushversion.bat` | Bumps the version, then pushes. |
|
|
51
|
+
| `ncupd.sh` / `ncupd.bat` | Reinstalls with every dependency upgraded to latest (`npm install -g npm-check-updates`). |
|
|
52
|
+
| `pushnpm.bat` | `ncupd`, then `pushversion` with "npm updates". |
|
|
53
|
+
|
|
54
|
+
## Release
|
|
55
|
+
|
|
56
|
+
Work happens on `dev`. Both workflows check out `dev`, push to it, open a pull request from `dev` to `master`, merge it, and publish to npm. Only the repository owner can run them.
|
|
57
|
+
|
|
58
|
+
- **Publish CI** (`.github/workflows/publish.yaml`): run it by hand from the Actions tab (Run workflow). It installs, tests, bumps the version, commits with the label you give, merges to `master` and publishes.
|
|
59
|
+
- **Build CI** (`.github/workflows/build.yaml`): starts on a `repository_dispatch` event. With `client_payload.action` set to `npm` it upgrades dependencies first; with the event type `version` it bumps the version. It tests, then commits, merges and publishes only when something changed.
|
|
60
|
+
|
|
61
|
+
The workflows need these repository secrets:
|
|
62
|
+
|
|
63
|
+
| Secret | Used for |
|
|
64
|
+
| --- | --- |
|
|
65
|
+
| `NPM_TOKEN` | `npm publish`. A granular access token with read and write on `@thzero` packages and 2FA bypass. |
|
|
66
|
+
| `ACCESS_TOKEN` | Build CI only, for the `build_all` event: a personal access token that can dispatch to `thzero/library_build`. |
|
|
67
|
+
|
|
68
|
+
Under Settings, Actions, General, set Workflow permissions to "Read and write permissions" and check "Allow GitHub Actions to create and approve pull requests". Without these the push and pull request steps fail.
|
|
69
|
+
|
|
70
|
+
## License
|
|
71
|
+
|
|
72
|
+
See [license.md](license.md).
|
package/constants.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const Constants = {
|
|
2
|
+
// Pub/sub between vessels (server_vessel) and zones (server_zone).
|
|
3
|
+
PubSub: {
|
|
4
|
+
Channels: {
|
|
5
|
+
// A vessel coming online says which game and system it's in, and that system's zone answers.
|
|
6
|
+
enter: 'meridian:enter',
|
|
7
|
+
// A zone's channels are its game's: every game's zones have the same ids.
|
|
8
|
+
// What changes, as a zone tells everyone in it: in all of it, and in one system.
|
|
9
|
+
changes: (gameId, zoneId) => `meridian:game:${gameId}:zone:${zoneId}:changes`,
|
|
10
|
+
space: (gameId, zoneId, systemId) => `meridian:game:${gameId}:zone:${zoneId}:system:${systemId}`,
|
|
11
|
+
vessel: vesselId => `meridian:vessel:${vesselId}`,
|
|
12
|
+
zone: (gameId, zoneId) => `meridian:game:${gameId}:zone:${zoneId}`
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
// Message rates (a second) and timeouts (seconds).
|
|
16
|
+
Timing: {
|
|
17
|
+
// How often a vessel and a zone tick.
|
|
18
|
+
tickHz: 10,
|
|
19
|
+
// How often a vessel tells its zone where it is, and a zone tells what has changed in a system,
|
|
20
|
+
// and in all of it.
|
|
21
|
+
statusHz: 5,
|
|
22
|
+
changesHz: 5,
|
|
23
|
+
zoneChangesHz: 0.5,
|
|
24
|
+
// With nothing changed in a system, the zone says so this often.
|
|
25
|
+
quietSeconds: 1,
|
|
26
|
+
// A vessel that hasn't heard from its zone for this long holds where it is and enters again.
|
|
27
|
+
lostSeconds: 3,
|
|
28
|
+
// Between a vessel's tries to enter, and to get what it hasn't been told yet.
|
|
29
|
+
enterSeconds: 2,
|
|
30
|
+
// A vessel its zone hasn't heard from for this long is dropped.
|
|
31
|
+
dropSeconds: 10
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export default Constants;
|
package/data/user.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import BaseUserData from '@thzero/library_common/data/baseUser.js';
|
|
2
|
+
|
|
3
|
+
import UserSettings from './settingsUser.js';
|
|
4
|
+
|
|
5
|
+
import UserGameData from './userGame.js';
|
|
6
|
+
|
|
7
|
+
class UserData extends BaseUserData {
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
|
|
11
|
+
this.gameData = new UserGameData();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
map(requested) {
|
|
15
|
+
super.map(requested);
|
|
16
|
+
|
|
17
|
+
if (!requested)
|
|
18
|
+
return;
|
|
19
|
+
|
|
20
|
+
this.gameData = requested.gameData;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
_initUserSettings() {
|
|
24
|
+
return new UserSettings();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default UserData;
|
package/data/userGame.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
class UserGameData {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.badges = [];
|
|
4
|
+
this.deaths = 0;
|
|
5
|
+
this.defeats = 0;
|
|
6
|
+
this.drops = 0;
|
|
7
|
+
this.kills = 0;
|
|
8
|
+
this.playedFactions = [];
|
|
9
|
+
this.playedMechs = [];
|
|
10
|
+
this.playedScenarios = [];
|
|
11
|
+
this.rating = 0;
|
|
12
|
+
this.victories = 0;
|
|
13
|
+
this.victoryPoints = 0;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default UserGameData;
|
package/license.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020-2024 thZero.com
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thzero/black-meridian-library_common",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.1.6",
|
|
5
|
+
"version_major": 0,
|
|
6
|
+
"version_minor": 1,
|
|
7
|
+
"version_patch": 6,
|
|
8
|
+
"version_date": "11/28/2026",
|
|
9
|
+
"description": "",
|
|
10
|
+
"author": "thZero",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/thzero/black-meridian-library_common.git"
|
|
14
|
+
},
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/thzero/black-meridian-library_common/issues"
|
|
17
|
+
},
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=24"
|
|
20
|
+
},
|
|
21
|
+
"main": "index.js",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"cli-update": "library-cli --updateversion --pi",
|
|
24
|
+
"test": "node --test"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@thzero/library_common": "^0.19"
|
|
28
|
+
}
|
|
6
29
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { describe, it } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
|
|
4
|
+
import Constants from '../constants.js';
|
|
5
|
+
|
|
6
|
+
describe('Constants', () => {
|
|
7
|
+
it('names a channel for each vessel, and for the zones of each game', () => {
|
|
8
|
+
assert.equal(Constants.PubSub.Channels.vessel('v1'), 'meridian:vessel:v1');
|
|
9
|
+
assert.equal(Constants.PubSub.Channels.zone('g1', 'z1'), 'meridian:game:g1:zone:z1');
|
|
10
|
+
assert.equal(Constants.PubSub.Channels.changes('g1', 'z1'), 'meridian:game:g1:zone:z1:changes');
|
|
11
|
+
assert.equal(Constants.PubSub.Channels.space('g1', 'z1', 's1'), 'meridian:game:g1:zone:z1:system:s1');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('keeps the zones of one game apart from those of another with the same id', () => {
|
|
15
|
+
assert.notEqual(Constants.PubSub.Channels.zone('g1', 'galaxy'), Constants.PubSub.Channels.zone('g2', 'galaxy'));
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('tells of a whole zone less often than of one system', () => {
|
|
19
|
+
const { changesHz, zoneChangesHz } = Constants.Timing;
|
|
20
|
+
assert.ok(zoneChangesHz < changesHz);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('is never quiet for so long that a vessel takes its zone for lost', () => {
|
|
24
|
+
const { lostSeconds, quietSeconds } = Constants.Timing;
|
|
25
|
+
assert.ok(quietSeconds * 2 < lostSeconds);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('gives a vessel up only after it would have noticed its zone was lost', () => {
|
|
29
|
+
const { dropSeconds, enterSeconds, lostSeconds } = Constants.Timing;
|
|
30
|
+
assert.ok(dropSeconds > lostSeconds + enterSeconds);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { describe, it } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
|
|
4
|
+
import UserData from '../data/user.js';
|
|
5
|
+
import UserSettings from '../data/settingsUser.js';
|
|
6
|
+
import UserGameData from '../data/userGame.js';
|
|
7
|
+
|
|
8
|
+
describe('UserData', () => {
|
|
9
|
+
it('initializes settings and game data', () => {
|
|
10
|
+
const user = new UserData();
|
|
11
|
+
assert.ok(user.settings instanceof UserSettings);
|
|
12
|
+
assert.deepEqual(user.settings.games, {});
|
|
13
|
+
assert.deepEqual(user.settings.gameSystems, []);
|
|
14
|
+
assert.ok(user.gameData instanceof UserGameData);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('maps game data from a request', () => {
|
|
18
|
+
const user = new UserData();
|
|
19
|
+
const gameData = new UserGameData();
|
|
20
|
+
gameData.kills = 3;
|
|
21
|
+
user.map({ email: 'a@b.c', roles: [ 'user' ], gameData });
|
|
22
|
+
assert.equal(user.email, 'a@b.c');
|
|
23
|
+
assert.deepEqual(user.roles, [ 'user' ]);
|
|
24
|
+
assert.equal(user.gameData.kills, 3);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('ignores an empty request', () => {
|
|
28
|
+
const user = new UserData();
|
|
29
|
+
user.map(null);
|
|
30
|
+
assert.ok(user.gameData instanceof UserGameData);
|
|
31
|
+
});
|
|
32
|
+
});
|