@quesmed/types 2.6.292 → 2.6.293

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.
@@ -1,5 +1,6 @@
1
1
  export declare const VIDEO_FILE_FIELDS: import("@apollo/client").DocumentNode;
2
2
  export declare const VIDEO_FIELDS: import("@apollo/client").DocumentNode;
3
+ export declare const VIDEO_LIBRARY_FIELDS: import("@apollo/client").DocumentNode;
3
4
  export declare const VIDEO_TOKENS_FIELDS: import("@apollo/client").DocumentNode;
4
5
  export declare const VIDEO_STATUS_FRAGMENT: import("@apollo/client").DocumentNode;
5
6
  export declare const VIDEO_USER_VIEWED_FRAGMENT: import("@apollo/client").DocumentNode;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VIDEO_WATCH_LATER_FRAGMENT = exports.VIDEO_USER_VIEWED_FRAGMENT = exports.VIDEO_STATUS_FRAGMENT = exports.VIDEO_TOKENS_FIELDS = exports.VIDEO_FIELDS = exports.VIDEO_FILE_FIELDS = void 0;
3
+ exports.VIDEO_WATCH_LATER_FRAGMENT = exports.VIDEO_USER_VIEWED_FRAGMENT = exports.VIDEO_STATUS_FRAGMENT = exports.VIDEO_TOKENS_FIELDS = exports.VIDEO_LIBRARY_FIELDS = exports.VIDEO_FIELDS = exports.VIDEO_FILE_FIELDS = void 0;
4
4
  const client_1 = require("@apollo/client");
5
5
  exports.VIDEO_FILE_FIELDS = (0, client_1.gql) `
6
6
  fragment VideoFileFields on File {
@@ -46,6 +46,40 @@ exports.VIDEO_FIELDS = (0, client_1.gql) `
46
46
  }
47
47
  }
48
48
  `;
49
+ // The VIDEO_LIBRARY selection, named so the cache updater can rebuild a list
50
+ // entry from the normalized Video entity without drifting from the query.
51
+ exports.VIDEO_LIBRARY_FIELDS = (0, client_1.gql) `
52
+ fragment VideoLibraryFields on Video {
53
+ id
54
+ title
55
+ # legacy videos.thumbnail — fallback for videos with no bunnyId
56
+ thumbnail
57
+ # signed Bunny assets, 6h expiry — prefer tokens.thumbnail when present
58
+ tokens {
59
+ thumbnail
60
+ gif
61
+ bunnyUrl
62
+ }
63
+ duration
64
+ status
65
+ watchLater
66
+ userViewed
67
+ demo
68
+ entitlement {
69
+ id
70
+ name
71
+ }
72
+ topic {
73
+ id
74
+ name
75
+ }
76
+ osceStation {
77
+ id
78
+ name
79
+ hiddenName
80
+ }
81
+ }
82
+ `;
49
83
  exports.VIDEO_TOKENS_FIELDS = (0, client_1.gql) `
50
84
  fragment VideoTokensFields on Video {
51
85
  tokens {
@@ -93,18 +93,37 @@ const updateCacheOnToggleVideoWatchLater = (cache, result) => {
93
93
  });
94
94
  // Keep the saved-only view of the library in step. Apollo caches per field
95
95
  // and args, so videoLibrary(watchLater: true) is its own entry — and only
96
- // when the Watch Later page has actually fetched it; reading an absent query
97
- // would throw. Unsaving splices the video out; saving is left to a refetch,
98
- // since the list is ordered by saved-at and this cache has no place to put it.
96
+ // when the Watch Later page has actually fetched it; there is nothing to
97
+ // reconcile before then, and the page's first fetch covers it.
99
98
  const variables = { watchLater: true };
100
99
  const prev = cache.readQuery({
101
100
  query: video_1.VIDEO_LIBRARY,
102
101
  variables,
103
102
  });
104
- if (!prev || watchLater) {
103
+ if (!prev) {
105
104
  return;
106
105
  }
107
106
  const { videoLibrary } = prev.restricted;
107
+ let nextVideoLibrary;
108
+ if (watchLater) {
109
+ if (videoLibrary.some((video) => Number(video.id) === Number(id))) {
110
+ return;
111
+ }
112
+ // The list is ordered saved-at descending, so the video just saved belongs
113
+ // at the top. Its fields are already normalized under Video:id by the
114
+ // library query, so the entry is rebuilt from the cache, not the wire.
115
+ const video = cache.readFragment({
116
+ id: cache.identify({ id, __typename: 'Video' }),
117
+ fragment: fragments_1.VIDEO_LIBRARY_FIELDS,
118
+ });
119
+ if (!video) {
120
+ return;
121
+ }
122
+ nextVideoLibrary = [{ ...video, watchLater: true }, ...videoLibrary];
123
+ }
124
+ else {
125
+ nextVideoLibrary = videoLibrary.filter((video) => Number(video.id) !== Number(id));
126
+ }
108
127
  cache.writeQuery({
109
128
  query: video_1.VIDEO_LIBRARY,
110
129
  variables,
@@ -112,7 +131,7 @@ const updateCacheOnToggleVideoWatchLater = (cache, result) => {
112
131
  ...prev,
113
132
  restricted: {
114
133
  ...prev.restricted,
115
- videoLibrary: videoLibrary.filter((video) => Number(video.id) !== Number(id)),
134
+ videoLibrary: nextVideoLibrary,
116
135
  },
117
136
  },
118
137
  });
@@ -120,37 +120,11 @@ exports.VIDEO = (0, client_1.gql) `
120
120
  // products) or topic (everything else) the category dropdown is built from.
121
121
  // Also serves the Watch Later page via the watchLater argument.
122
122
  exports.VIDEO_LIBRARY = (0, client_1.gql) `
123
+ ${fragments_1.VIDEO_LIBRARY_FIELDS}
123
124
  query VideoLibrary($watchLater: Boolean) {
124
125
  restricted {
125
126
  videoLibrary(watchLater: $watchLater) {
126
- id
127
- title
128
- # legacy videos.thumbnail — fallback for videos with no bunnyId
129
- thumbnail
130
- # signed Bunny assets, 6h expiry — prefer tokens.thumbnail when present
131
- tokens {
132
- thumbnail
133
- gif
134
- bunnyUrl
135
- }
136
- duration
137
- status
138
- watchLater
139
- userViewed
140
- demo
141
- entitlement {
142
- id
143
- name
144
- }
145
- topic {
146
- id
147
- name
148
- }
149
- osceStation {
150
- id
151
- name
152
- hiddenName
153
- }
127
+ ...VideoLibraryFields
154
128
  }
155
129
  }
156
130
  }
@@ -1,5 +1,6 @@
1
1
  export declare const VIDEO_FILE_FIELDS: import("@apollo/client").DocumentNode;
2
2
  export declare const VIDEO_FIELDS: import("@apollo/client").DocumentNode;
3
+ export declare const VIDEO_LIBRARY_FIELDS: import("@apollo/client").DocumentNode;
3
4
  export declare const VIDEO_TOKENS_FIELDS: import("@apollo/client").DocumentNode;
4
5
  export declare const VIDEO_STATUS_FRAGMENT: import("@apollo/client").DocumentNode;
5
6
  export declare const VIDEO_USER_VIEWED_FRAGMENT: import("@apollo/client").DocumentNode;
@@ -43,6 +43,40 @@ export const VIDEO_FIELDS = gql `
43
43
  }
44
44
  }
45
45
  `;
46
+ // The VIDEO_LIBRARY selection, named so the cache updater can rebuild a list
47
+ // entry from the normalized Video entity without drifting from the query.
48
+ export const VIDEO_LIBRARY_FIELDS = gql `
49
+ fragment VideoLibraryFields on Video {
50
+ id
51
+ title
52
+ # legacy videos.thumbnail — fallback for videos with no bunnyId
53
+ thumbnail
54
+ # signed Bunny assets, 6h expiry — prefer tokens.thumbnail when present
55
+ tokens {
56
+ thumbnail
57
+ gif
58
+ bunnyUrl
59
+ }
60
+ duration
61
+ status
62
+ watchLater
63
+ userViewed
64
+ demo
65
+ entitlement {
66
+ id
67
+ name
68
+ }
69
+ topic {
70
+ id
71
+ name
72
+ }
73
+ osceStation {
74
+ id
75
+ name
76
+ hiddenName
77
+ }
78
+ }
79
+ `;
46
80
  export const VIDEO_TOKENS_FIELDS = gql `
47
81
  fragment VideoTokensFields on Video {
48
82
  tokens {
@@ -1,5 +1,5 @@
1
1
  import { gql } from '@apollo/client';
2
- import { VIDEO_USER_VIEWED_FRAGMENT, VIDEO_WATCH_LATER_FRAGMENT, } from '../../fragments';
2
+ import { VIDEO_LIBRARY_FIELDS, VIDEO_USER_VIEWED_FRAGMENT, VIDEO_WATCH_LATER_FRAGMENT, } from '../../fragments';
3
3
  import { VIDEO_LIBRARY, } from '../../query/restricted/video';
4
4
  import { OSCE_STATS, } from '../../query/restricted/osce';
5
5
  export const VIDEO_WATCHED = gql `
@@ -88,18 +88,37 @@ export const updateCacheOnToggleVideoWatchLater = (cache, result) => {
88
88
  });
89
89
  // Keep the saved-only view of the library in step. Apollo caches per field
90
90
  // and args, so videoLibrary(watchLater: true) is its own entry — and only
91
- // when the Watch Later page has actually fetched it; reading an absent query
92
- // would throw. Unsaving splices the video out; saving is left to a refetch,
93
- // since the list is ordered by saved-at and this cache has no place to put it.
91
+ // when the Watch Later page has actually fetched it; there is nothing to
92
+ // reconcile before then, and the page's first fetch covers it.
94
93
  const variables = { watchLater: true };
95
94
  const prev = cache.readQuery({
96
95
  query: VIDEO_LIBRARY,
97
96
  variables,
98
97
  });
99
- if (!prev || watchLater) {
98
+ if (!prev) {
100
99
  return;
101
100
  }
102
101
  const { videoLibrary } = prev.restricted;
102
+ let nextVideoLibrary;
103
+ if (watchLater) {
104
+ if (videoLibrary.some((video) => Number(video.id) === Number(id))) {
105
+ return;
106
+ }
107
+ // The list is ordered saved-at descending, so the video just saved belongs
108
+ // at the top. Its fields are already normalized under Video:id by the
109
+ // library query, so the entry is rebuilt from the cache, not the wire.
110
+ const video = cache.readFragment({
111
+ id: cache.identify({ id, __typename: 'Video' }),
112
+ fragment: VIDEO_LIBRARY_FIELDS,
113
+ });
114
+ if (!video) {
115
+ return;
116
+ }
117
+ nextVideoLibrary = [{ ...video, watchLater: true }, ...videoLibrary];
118
+ }
119
+ else {
120
+ nextVideoLibrary = videoLibrary.filter((video) => Number(video.id) !== Number(id));
121
+ }
103
122
  cache.writeQuery({
104
123
  query: VIDEO_LIBRARY,
105
124
  variables,
@@ -107,7 +126,7 @@ export const updateCacheOnToggleVideoWatchLater = (cache, result) => {
107
126
  ...prev,
108
127
  restricted: {
109
128
  ...prev.restricted,
110
- videoLibrary: videoLibrary.filter((video) => Number(video.id) !== Number(id)),
129
+ videoLibrary: nextVideoLibrary,
111
130
  },
112
131
  },
113
132
  });
@@ -1,5 +1,5 @@
1
1
  import { gql } from '@apollo/client';
2
- import { CHAPTER_FIELDS, PICTURE_FIELDS, VIDEO_TOKENS_FIELDS } from '../../fragments';
2
+ import { CHAPTER_FIELDS, PICTURE_FIELDS, VIDEO_LIBRARY_FIELDS, VIDEO_TOKENS_FIELDS, } from '../../fragments';
3
3
  export const VIDEO = gql `
4
4
  ${PICTURE_FIELDS}
5
5
  ${CHAPTER_FIELDS}
@@ -117,37 +117,11 @@ export const VIDEO = gql `
117
117
  // products) or topic (everything else) the category dropdown is built from.
118
118
  // Also serves the Watch Later page via the watchLater argument.
119
119
  export const VIDEO_LIBRARY = gql `
120
+ ${VIDEO_LIBRARY_FIELDS}
120
121
  query VideoLibrary($watchLater: Boolean) {
121
122
  restricted {
122
123
  videoLibrary(watchLater: $watchLater) {
123
- id
124
- title
125
- # legacy videos.thumbnail — fallback for videos with no bunnyId
126
- thumbnail
127
- # signed Bunny assets, 6h expiry — prefer tokens.thumbnail when present
128
- tokens {
129
- thumbnail
130
- gif
131
- bunnyUrl
132
- }
133
- duration
134
- status
135
- watchLater
136
- userViewed
137
- demo
138
- entitlement {
139
- id
140
- name
141
- }
142
- topic {
143
- id
144
- name
145
- }
146
- osceStation {
147
- id
148
- name
149
- hiddenName
150
- }
124
+ ...VideoLibraryFields
151
125
  }
152
126
  }
153
127
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quesmed/types",
3
- "version": "2.6.292",
3
+ "version": "2.6.293",
4
4
  "description": "Typescript types for Quesmed",
5
5
  "keywords": [
6
6
  "quesmed",