@juki-team/commons 0.1.46 → 0.1.47

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.
@@ -641,7 +641,8 @@ exports.ProblemChannelRole = void 0;
641
641
  ProblemChannelRole["SPECTATORS"] = "spectators";
642
642
  })(exports.ProblemChannelRole || (exports.ProblemChannelRole = {}));
643
643
  /**
644
- * Roles of the public channels of a user: `user:{userId}:{role}` (see `CHANNEL_USER_ROLE`).
644
+ * Roles of the public channels of a user: `user:{userKey}:{role}` (see `CHANNEL_USER_ROLE`), by its public key
645
+ * (`getUserKey(nickname, organizationKey)`) like problems and contests.
645
646
  * There are no per-user permissions: `spectators` is everyone who can list the submissions of the user.
646
647
  * The private channel of the user is `user:{userId}` (see `CHANNEL_USER`).
647
648
  */
@@ -2258,8 +2259,12 @@ const segment = (value) => encodeURIComponent(value);
2258
2259
  const CHANNEL_SESSION = (sessionId) => `session:${segment(sessionId)}`;
2259
2260
  /** private: events of one user (own submissions while the contest is frozen, notifications, own problem crawls) */
2260
2261
  const CHANNEL_USER = (userId) => `user:${segment(userId)}`;
2261
- /** per role: public events of one user (judging of its submissions visible to everyone, see `UserChannelRole`) */
2262
- const CHANNEL_USER_ROLE = (userId, role) => `user:${segment(userId)}:${role}`;
2262
+ /**
2263
+ * per role: public events of one user (judging of its submissions visible to everyone, see `UserChannelRole`).
2264
+ * By its public key (`getUserKey(nickname, organizationKey)`), the one the clients know; the private channel
2265
+ * (`CHANNEL_USER`) is by id. They never collide: the role channel has one more segment.
2266
+ */
2267
+ const CHANNEL_USER_ROLE = (userKey, role) => `user:${segment(userKey)}:${role}`;
2263
2268
  /** public: status of a submission when it is visible to everyone */
2264
2269
  const CHANNEL_SUBMISSION = (submitId) => `submission:${segment(submitId)}`;
2265
2270
  /** per role: events of a problem for one role (judging of its submissions, see `ProblemChannelRole`) */
@@ -2276,7 +2281,7 @@ const CHANNEL_CONTEST = (contestKey, role) => `contest:${segment(contestKey)}:${
2276
2281
  const CHANNEL_ORGANIZATION_PRESENCE = (organizationKey) => `presence:organization:${segment(organizationKey)}`;
2277
2282
  // capability resources (wildcards) of the public channels.
2278
2283
  // Ably: a trailing `*` replaces one or more segments, any other `*` exactly one segment. So `user:*:spectators`
2279
- // matches every `user:{userId}:spectators` but never the private `user:{userId}`.
2284
+ // matches every `user:{userKey}:spectators` but never the private `user:{userId}`.
2280
2285
  // There is no public `problem:*`: it would also match the role channels `problem:{problemKey}:{role}`.
2281
2286
  const CHANNEL_SUBMISSION_ALL = 'submission:*';
2282
2287
  const CHANNEL_USER_SPECTATORS_ALL = `user:*:${exports.UserChannelRole.SPECTATORS}`;
@@ -3013,10 +3018,10 @@ const isUnsubscribeUserNotificationWebSocketEventDto = (event) => {
3013
3018
  };
3014
3019
  const isNonEmptyString = (value) => typeof value === 'string' && !!value;
3015
3020
  /**
3016
- * Exactly one of `problemKey` / `contestKey` / `userId` is set.
3021
+ * Exactly one of `problemKey` / `contestKey` / `userKey` is set.
3017
3022
  */
3018
3023
  const isSubmissionsJudgingScope = (scope) => {
3019
- return [scope?.problemKey, scope?.contestKey, scope?.userId].filter(isNonEmptyString).length === 1;
3024
+ return [scope?.problemKey, scope?.contestKey, scope?.userKey].filter(isNonEmptyString).length === 1;
3020
3025
  };
3021
3026
  const isSubscribeSubmissionsJudgingWebSocketEventDto = (event) => {
3022
3027
  return isWebsocketSubscription(event)
@@ -3055,7 +3060,7 @@ const isSubmissionJudgingWebSocketResponseEventDto = (event) => {
3055
3060
  && isNonEmptyString(event?.submitId)
3056
3061
  && isNonEmptyString(event?.problemKey)
3057
3062
  && (event?.contestKey === null || isNonEmptyString(event?.contestKey))
3058
- && isNonEmptyString(event?.userId)
3063
+ && isNonEmptyString(event?.userKey)
3059
3064
  && typeof event?.judging === 'boolean'
3060
3065
  && event?.status in exports.SubmissionRunStatus
3061
3066
  && event?.verdict in exports.ProblemVerdict
@@ -3195,8 +3200,8 @@ const getChannelOfWebSocketSubscribeEvent = (event) => {
3195
3200
  if ('contestKey' in event && event.contestKey) {
3196
3201
  return CHANNEL_CONTEST(event.contestKey, exports.ContestChannelRole.SPECTATORS);
3197
3202
  }
3198
- if ('userId' in event && event.userId) {
3199
- return CHANNEL_USER_ROLE(event.userId, exports.UserChannelRole.SPECTATORS);
3203
+ if ('userKey' in event && event.userKey) {
3204
+ return CHANNEL_USER_ROLE(event.userKey, exports.UserChannelRole.SPECTATORS);
3200
3205
  }
3201
3206
  }
3202
3207
  return null;
package/dist/esm/index.js CHANGED
@@ -639,7 +639,8 @@ var ProblemChannelRole;
639
639
  ProblemChannelRole["SPECTATORS"] = "spectators";
640
640
  })(ProblemChannelRole || (ProblemChannelRole = {}));
641
641
  /**
642
- * Roles of the public channels of a user: `user:{userId}:{role}` (see `CHANNEL_USER_ROLE`).
642
+ * Roles of the public channels of a user: `user:{userKey}:{role}` (see `CHANNEL_USER_ROLE`), by its public key
643
+ * (`getUserKey(nickname, organizationKey)`) like problems and contests.
643
644
  * There are no per-user permissions: `spectators` is everyone who can list the submissions of the user.
644
645
  * The private channel of the user is `user:{userId}` (see `CHANNEL_USER`).
645
646
  */
@@ -2256,8 +2257,12 @@ const segment = (value) => encodeURIComponent(value);
2256
2257
  const CHANNEL_SESSION = (sessionId) => `session:${segment(sessionId)}`;
2257
2258
  /** private: events of one user (own submissions while the contest is frozen, notifications, own problem crawls) */
2258
2259
  const CHANNEL_USER = (userId) => `user:${segment(userId)}`;
2259
- /** per role: public events of one user (judging of its submissions visible to everyone, see `UserChannelRole`) */
2260
- const CHANNEL_USER_ROLE = (userId, role) => `user:${segment(userId)}:${role}`;
2260
+ /**
2261
+ * per role: public events of one user (judging of its submissions visible to everyone, see `UserChannelRole`).
2262
+ * By its public key (`getUserKey(nickname, organizationKey)`), the one the clients know; the private channel
2263
+ * (`CHANNEL_USER`) is by id. They never collide: the role channel has one more segment.
2264
+ */
2265
+ const CHANNEL_USER_ROLE = (userKey, role) => `user:${segment(userKey)}:${role}`;
2261
2266
  /** public: status of a submission when it is visible to everyone */
2262
2267
  const CHANNEL_SUBMISSION = (submitId) => `submission:${segment(submitId)}`;
2263
2268
  /** per role: events of a problem for one role (judging of its submissions, see `ProblemChannelRole`) */
@@ -2274,7 +2279,7 @@ const CHANNEL_CONTEST = (contestKey, role) => `contest:${segment(contestKey)}:${
2274
2279
  const CHANNEL_ORGANIZATION_PRESENCE = (organizationKey) => `presence:organization:${segment(organizationKey)}`;
2275
2280
  // capability resources (wildcards) of the public channels.
2276
2281
  // Ably: a trailing `*` replaces one or more segments, any other `*` exactly one segment. So `user:*:spectators`
2277
- // matches every `user:{userId}:spectators` but never the private `user:{userId}`.
2282
+ // matches every `user:{userKey}:spectators` but never the private `user:{userId}`.
2278
2283
  // There is no public `problem:*`: it would also match the role channels `problem:{problemKey}:{role}`.
2279
2284
  const CHANNEL_SUBMISSION_ALL = 'submission:*';
2280
2285
  const CHANNEL_USER_SPECTATORS_ALL = `user:*:${UserChannelRole.SPECTATORS}`;
@@ -3011,10 +3016,10 @@ const isUnsubscribeUserNotificationWebSocketEventDto = (event) => {
3011
3016
  };
3012
3017
  const isNonEmptyString = (value) => typeof value === 'string' && !!value;
3013
3018
  /**
3014
- * Exactly one of `problemKey` / `contestKey` / `userId` is set.
3019
+ * Exactly one of `problemKey` / `contestKey` / `userKey` is set.
3015
3020
  */
3016
3021
  const isSubmissionsJudgingScope = (scope) => {
3017
- return [scope?.problemKey, scope?.contestKey, scope?.userId].filter(isNonEmptyString).length === 1;
3022
+ return [scope?.problemKey, scope?.contestKey, scope?.userKey].filter(isNonEmptyString).length === 1;
3018
3023
  };
3019
3024
  const isSubscribeSubmissionsJudgingWebSocketEventDto = (event) => {
3020
3025
  return isWebsocketSubscription(event)
@@ -3053,7 +3058,7 @@ const isSubmissionJudgingWebSocketResponseEventDto = (event) => {
3053
3058
  && isNonEmptyString(event?.submitId)
3054
3059
  && isNonEmptyString(event?.problemKey)
3055
3060
  && (event?.contestKey === null || isNonEmptyString(event?.contestKey))
3056
- && isNonEmptyString(event?.userId)
3061
+ && isNonEmptyString(event?.userKey)
3057
3062
  && typeof event?.judging === 'boolean'
3058
3063
  && event?.status in SubmissionRunStatus
3059
3064
  && event?.verdict in ProblemVerdict
@@ -3193,8 +3198,8 @@ const getChannelOfWebSocketSubscribeEvent = (event) => {
3193
3198
  if ('contestKey' in event && event.contestKey) {
3194
3199
  return CHANNEL_CONTEST(event.contestKey, ContestChannelRole.SPECTATORS);
3195
3200
  }
3196
- if ('userId' in event && event.userId) {
3197
- return CHANNEL_USER_ROLE(event.userId, UserChannelRole.SPECTATORS);
3201
+ if ('userKey' in event && event.userKey) {
3202
+ return CHANNEL_USER_ROLE(event.userKey, UserChannelRole.SPECTATORS);
3198
3203
  }
3199
3204
  }
3200
3205
  return null;
@@ -3,8 +3,12 @@ import { ContestChannelRole, ProblemChannelRole, UserChannelRole } from '../type
3
3
  export declare const CHANNEL_SESSION: (sessionId: string) => string;
4
4
  /** private: events of one user (own submissions while the contest is frozen, notifications, own problem crawls) */
5
5
  export declare const CHANNEL_USER: (userId: string) => string;
6
- /** per role: public events of one user (judging of its submissions visible to everyone, see `UserChannelRole`) */
7
- export declare const CHANNEL_USER_ROLE: (userId: string, role: UserChannelRole) => string;
6
+ /**
7
+ * per role: public events of one user (judging of its submissions visible to everyone, see `UserChannelRole`).
8
+ * By its public key (`getUserKey(nickname, organizationKey)`), the one the clients know; the private channel
9
+ * (`CHANNEL_USER`) is by id. They never collide: the role channel has one more segment.
10
+ */
11
+ export declare const CHANNEL_USER_ROLE: (userKey: string, role: UserChannelRole) => string;
8
12
  /** public: status of a submission when it is visible to everyone */
9
13
  export declare const CHANNEL_SUBMISSION: (submitId: string) => string;
10
14
  /** per role: events of a problem for one role (judging of its submissions, see `ProblemChannelRole`) */
@@ -72,7 +72,7 @@ export type SubmissionsJudgingScope = {
72
72
  } | {
73
73
  contestKey: string;
74
74
  } | {
75
- userId: string;
75
+ userKey: string;
76
76
  };
77
77
  export type SubscribeSubmissionsJudgingWebSocketEventDto = WebsocketSubscription & {
78
78
  event: WebSocketSubscriptionEvent.SUBSCRIBE_SUBMISSIONS_JUDGING;
@@ -114,7 +114,7 @@ export interface SubmissionJudgingWebSocketResponseEventDto extends WebSocketRes
114
114
  submitId: string;
115
115
  problemKey: string;
116
116
  contestKey: string | null;
117
- userId: string;
117
+ userKey: string;
118
118
  judging: boolean;
119
119
  status: SubmissionRunStatus;
120
120
  verdict: ProblemVerdict;
@@ -16,7 +16,7 @@ export declare const isUnsubscribeContestChangesWebSocketEventDto: (event: any)
16
16
  export declare const isSubscribeUserNotificationWebSocketEventDto: (event: any) => event is SubscribeUserNotificationWebsocketEventDto;
17
17
  export declare const isUnsubscribeUserNotificationWebSocketEventDto: (event: any) => event is UnsubscribeUserNotificationWebSocketEventDto;
18
18
  /**
19
- * Exactly one of `problemKey` / `contestKey` / `userId` is set.
19
+ * Exactly one of `problemKey` / `contestKey` / `userKey` is set.
20
20
  */
21
21
  export declare const isSubmissionsJudgingScope: (scope: any) => scope is SubmissionsJudgingScope;
22
22
  export declare const isSubscribeSubmissionsJudgingWebSocketEventDto: (event: any) => event is SubscribeSubmissionsJudgingWebSocketEventDto;
@@ -64,7 +64,8 @@ export declare enum ProblemChannelRole {
64
64
  SPECTATORS = "spectators"
65
65
  }
66
66
  /**
67
- * Roles of the public channels of a user: `user:{userId}:{role}` (see `CHANNEL_USER_ROLE`).
67
+ * Roles of the public channels of a user: `user:{userKey}:{role}` (see `CHANNEL_USER_ROLE`), by its public key
68
+ * (`getUserKey(nickname, organizationKey)`) like problems and contests.
68
69
  * There are no per-user permissions: `spectators` is everyone who can list the submissions of the user.
69
70
  * The private channel of the user is `user:{userId}` (see `CHANNEL_USER`).
70
71
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juki-team/commons",
3
- "version": "0.1.46",
3
+ "version": "0.1.47",
4
4
  "author": "juki-team",
5
5
  "license": "MIT",
6
6
  "type": "module",