polfan-server-js-client 0.3.2 → 0.4.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.
Files changed (39) hide show
  1. package/.gitmodules +3 -3
  2. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_05_08_2026_17_28_[Changes]/shelved.patch +447 -0
  3. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_05_08_2026_17_28_[Changes]1/shelved.patch +0 -0
  4. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_05_08_2026_17_28__Changes_.xml +4 -0
  5. package/.idea/workspace.xml +228 -49
  6. package/CODE_OF_CONDUCT.md +76 -76
  7. package/README.md +44 -44
  8. package/babel.config.js +5 -5
  9. package/build/index.cjs.js +181 -15
  10. package/build/index.cjs.js.map +1 -1
  11. package/build/index.umd.js +1 -1
  12. package/build/index.umd.js.map +1 -1
  13. package/build/types/index.d.ts +2 -1
  14. package/build/types/types/src/index.d.ts +3 -3
  15. package/build/types/types/src/schemes/SessionData.d.ts +6 -0
  16. package/build/types/types/src/schemes/User.d.ts +15 -0
  17. package/build/types/types/src/schemes/UserData.d.ts +5 -0
  18. package/build/types/types/src/schemes/commands/SetSessionData.d.ts +9 -1
  19. package/build/types/types/src/schemes/commands/SetUserData.d.ts +1 -0
  20. package/jest.config.ts +199 -199
  21. package/package.json +43 -43
  22. package/scripts/getPackageJson.js +24 -24
  23. package/src/FilesClient.ts +42 -42
  24. package/src/index.ts +31 -29
  25. package/src/state-tracker/ChatStateTracker.ts +71 -71
  26. package/src/state-tracker/UsersManager.ts +51 -51
  27. package/src/state-tracker/functions.ts +28 -28
  28. package/src/types/src/index.ts +313 -311
  29. package/src/types/src/schemes/SessionData.ts +8 -1
  30. package/src/types/src/schemes/User.ts +17 -1
  31. package/src/types/src/schemes/UserData.ts +5 -0
  32. package/src/types/src/schemes/commands/SetSessionData.ts +11 -2
  33. package/src/types/src/schemes/commands/SetUserData.ts +1 -0
  34. package/tests/async-utils.test.ts +29 -29
  35. package/tests/space-roles.test.ts +42 -42
  36. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_26_07_2026_21_26_[Changes]/shelved.patch +0 -174
  37. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_26_07_2026_21_26__Changes_.xml +0 -4
  38. package/.idea/shelf/Uncommitted_changes_before_rebase_[Changes]/shelved.patch +0 -18
  39. package/.idea/shelf/Uncommitted_changes_before_rebase__Changes_.xml +0 -4
@@ -1,9 +1,25 @@
1
1
  export type UserTags = 'bot' | 'temp' | string;
2
2
 
3
+ /**
4
+ * Availability of a user, aggregated over all of their sessions.
5
+ *
6
+ * - `Offline` - no session is connected and none can be reached asynchronously.
7
+ * - `Online` - at least one session holds a live connection.
8
+ * - `OnlineAsync` - no live connection, but a push-registered device was active
9
+ * recently, so a message will still reach the user.
10
+ */
11
+ export enum UserStatus {
12
+ Offline = 0,
13
+ Online = 1,
14
+ OnlineAsync = 2,
15
+ }
16
+
3
17
  export interface User {
4
18
  id: string;
5
19
  nick: string;
6
20
  avatar: string;
7
21
  tags: UserTags[];
22
+ status: UserStatus;
23
+ /** @deprecated Use {@link status}. Kept for clients older than the numeric status. */
8
24
  online: boolean;
9
- }
25
+ }
@@ -2,4 +2,9 @@ export type PrivateMessagePolicy = 'None' | 'Mutual' | 'All';
2
2
 
3
3
  export interface UserData {
4
4
  privateMessagePolicy: PrivateMessagePolicy;
5
+ /**
6
+ * Whether others may see that the user is reachable on a push-registered
7
+ * device while disconnected. When false the user simply reads as offline.
8
+ */
9
+ showAsyncPresence: boolean;
5
10
  }
@@ -1,10 +1,19 @@
1
+ import {SessionPlatform} from "../SessionData";
2
+
1
3
  export interface SessionPush {
2
4
  token?: string;
3
- platform?: 'ios' | 'android' | 'web';
4
5
  active?: boolean;
6
+ /**
7
+ * @deprecated The platform describes the session, not its push registration.
8
+ * Use {@link SetSessionData.platform} (or the `platform` connection query
9
+ * parameter). Still accepted by the server, but the top-level field wins.
10
+ */
11
+ platform?: SessionPlatform;
5
12
  }
6
13
 
7
14
  export interface SetSessionData {
8
15
  clientFocused?: boolean;
9
16
  push?: SessionPush;
10
- }
17
+ /** Client platform of this session; null leaves the stored value unchanged. */
18
+ platform?: SessionPlatform;
19
+ }
@@ -2,4 +2,5 @@ import {PrivateMessagePolicy} from "../UserData";
2
2
 
3
3
  export interface SetUserData {
4
4
  privateMessagePolicy?: PrivateMessagePolicy;
5
+ showAsyncPresence?: boolean;
5
6
  }
@@ -1,30 +1,30 @@
1
- import {PromiseRegistry} from "../src/state-tracker/AsyncUtils";
2
-
3
- test('promise registry - limit the calling of async process', async () => {
4
- const pr = new PromiseRegistry();
5
- let generationCount = 0;
6
-
7
- async function generateResult() {
8
- return ++generationCount;
9
- }
10
-
11
- async function getResult() {
12
- const resultKey = 'test';
13
-
14
- if (pr.notExist('test')) {
15
- pr.registerByFunction(generateResult, resultKey);
16
- }
17
-
18
- await pr.get(resultKey);
19
- return generationCount;
20
- }
21
-
22
- const call1 = await getResult();
23
- expect(call1).toBe(1);
24
- const call2 = await getResult();
25
- expect(call2).toBe(1);
26
- const call3 = await getResult();
27
- expect(call3).toBe(1);
28
-
29
- expect(generationCount).toBe(1);
1
+ import {PromiseRegistry} from "../src/state-tracker/AsyncUtils";
2
+
3
+ test('promise registry - limit the calling of async process', async () => {
4
+ const pr = new PromiseRegistry();
5
+ let generationCount = 0;
6
+
7
+ async function generateResult() {
8
+ return ++generationCount;
9
+ }
10
+
11
+ async function getResult() {
12
+ const resultKey = 'test';
13
+
14
+ if (pr.notExist('test')) {
15
+ pr.registerByFunction(generateResult, resultKey);
16
+ }
17
+
18
+ await pr.get(resultKey);
19
+ return generationCount;
20
+ }
21
+
22
+ const call1 = await getResult();
23
+ expect(call1).toBe(1);
24
+ const call2 = await getResult();
25
+ expect(call2).toBe(1);
26
+ const call3 = await getResult();
27
+ expect(call3).toBe(1);
28
+
29
+ expect(generationCount).toBe(1);
30
30
  });
@@ -1,43 +1,43 @@
1
- import {IndexedObjectCollection} from "../src";
2
- import {Role} from "pserv-ts-types";
3
- import {reorderRolesOnPriorityUpdate} from "../src/state-tracker/functions";
4
-
5
- const createCollection = () => new IndexedObjectCollection<Role>(
6
- role => role.id,
7
- [
8
- {id: 'id1', name: 'everyone', priority: 0, color: '#ff0000'},
9
- {id: 'id2', name: 'roleA', priority: 1, color: '#ff0000'},
10
- {id: 'id3', name: 'roleB', priority: 2, color: '#ff0000'},
11
- {id: 'id4', name: 'roleC', priority: 3, color: '#ff0000'},
12
- {id: 'id5', name: 'roleD', priority: 4, color: '#ff0000'},
13
- ],
14
- );
15
-
16
- test('roles reorder - increase', () => {
17
- const collection = createCollection();
18
- const oldRole = collection.get('id2');
19
- const newRole: Role = {...oldRole, priority: 4};
20
- const result = reorderRolesOnPriorityUpdate(collection.items, oldRole, newRole);
21
- collection.set(newRole, ...result);
22
-
23
- //expect(result.length).toBe(3);
24
- expect(collection.get('id1').priority).toBe(0);
25
- expect(collection.get('id2').priority).toBe(4);
26
- expect(collection.get('id3').priority).toBe(1);
27
- expect(collection.get('id4').priority).toBe(2);
28
- expect(collection.get('id5').priority).toBe(3);
29
- });
30
-
31
- test('roles reorder - decrease', () => {
32
- const collection = createCollection();
33
- const oldRole = collection.get('id5');
34
- const newRole: Role = {...oldRole, priority: 0};
35
- const result = reorderRolesOnPriorityUpdate(collection.items, oldRole, newRole);
36
- collection.set(newRole, ...result);
37
-
38
- expect(collection.get('id1').priority).toBe(1);
39
- expect(collection.get('id2').priority).toBe(2);
40
- expect(collection.get('id3').priority).toBe(3);
41
- expect(collection.get('id4').priority).toBe(4);
42
- expect(collection.get('id5').priority).toBe(0);
1
+ import {IndexedObjectCollection} from "../src";
2
+ import {Role} from "pserv-ts-types";
3
+ import {reorderRolesOnPriorityUpdate} from "../src/state-tracker/functions";
4
+
5
+ const createCollection = () => new IndexedObjectCollection<Role>(
6
+ role => role.id,
7
+ [
8
+ {id: 'id1', name: 'everyone', priority: 0, color: '#ff0000'},
9
+ {id: 'id2', name: 'roleA', priority: 1, color: '#ff0000'},
10
+ {id: 'id3', name: 'roleB', priority: 2, color: '#ff0000'},
11
+ {id: 'id4', name: 'roleC', priority: 3, color: '#ff0000'},
12
+ {id: 'id5', name: 'roleD', priority: 4, color: '#ff0000'},
13
+ ],
14
+ );
15
+
16
+ test('roles reorder - increase', () => {
17
+ const collection = createCollection();
18
+ const oldRole = collection.get('id2');
19
+ const newRole: Role = {...oldRole, priority: 4};
20
+ const result = reorderRolesOnPriorityUpdate(collection.items, oldRole, newRole);
21
+ collection.set(newRole, ...result);
22
+
23
+ //expect(result.length).toBe(3);
24
+ expect(collection.get('id1').priority).toBe(0);
25
+ expect(collection.get('id2').priority).toBe(4);
26
+ expect(collection.get('id3').priority).toBe(1);
27
+ expect(collection.get('id4').priority).toBe(2);
28
+ expect(collection.get('id5').priority).toBe(3);
29
+ });
30
+
31
+ test('roles reorder - decrease', () => {
32
+ const collection = createCollection();
33
+ const oldRole = collection.get('id5');
34
+ const newRole: Role = {...oldRole, priority: 0};
35
+ const result = reorderRolesOnPriorityUpdate(collection.items, oldRole, newRole);
36
+ collection.set(newRole, ...result);
37
+
38
+ expect(collection.get('id1').priority).toBe(1);
39
+ expect(collection.get('id2').priority).toBe(2);
40
+ expect(collection.get('id3').priority).toBe(3);
41
+ expect(collection.get('id4').priority).toBe(4);
42
+ expect(collection.get('id5').priority).toBe(0);
43
43
  });