@quesmed/types 1.0.2 → 1.0.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.
Files changed (180) hide show
  1. package/gql_input_output_types/User.d.ts +12 -0
  2. package/gql_input_output_types/User.js +2 -0
  3. package/gql_input_output_types/index.d.ts +74 -0
  4. package/gql_input_output_types/index.js +2 -0
  5. package/index.d.ts +16 -0
  6. package/index.js +20 -0
  7. package/models/Card.d.ts +15 -0
  8. package/models/Card.js +2 -0
  9. package/models/Chapter.d.ts +12 -0
  10. package/models/Chapter.js +2 -0
  11. package/models/Concept.d.ts +23 -0
  12. package/models/Concept.js +2 -0
  13. package/models/File.d.ts +10 -0
  14. package/models/File.js +2 -0
  15. package/models/Marksheet.d.ts +43 -0
  16. package/models/Marksheet.js +9 -0
  17. package/models/MockTest.d.ts +18 -0
  18. package/models/MockTest.js +2 -0
  19. package/models/OsceMarksheet.d.ts +55 -0
  20. package/models/OsceMarksheet.js +19 -0
  21. package/models/OsceStation.d.ts +39 -0
  22. package/models/OsceStation.js +12 -0
  23. package/models/Picture.d.ts +33 -0
  24. package/models/Picture.js +2 -0
  25. package/models/Promo.d.ts +14 -0
  26. package/models/Promo.js +2 -0
  27. package/models/Question.d.ts +54 -0
  28. package/models/Question.js +10 -0
  29. package/models/Subscription.d.ts +11 -0
  30. package/models/Subscription.js +2 -0
  31. package/models/Todo.d.ts +24 -0
  32. package/models/Todo.js +2 -0
  33. package/models/Token.d.ts +7 -0
  34. package/models/Token.js +2 -0
  35. package/models/{Topic.ts → Topic.d.ts} +4 -5
  36. package/models/Topic.js +2 -0
  37. package/models/Type.d.ts +7 -0
  38. package/models/Type.js +2 -0
  39. package/models/University.d.ts +5 -0
  40. package/models/University.js +2 -0
  41. package/models/User.d.ts +73 -0
  42. package/models/User.js +2 -0
  43. package/models/Video.d.ts +19 -0
  44. package/models/Video.js +2 -0
  45. package/models/{index.ts → index.d.ts} +0 -0
  46. package/models/index.js +31 -0
  47. package/package.json +6 -6
  48. package/resolvers/mutation/admin/algoliaSync.d.ts +10 -0
  49. package/resolvers/mutation/admin/algoliaSync.js +2 -0
  50. package/resolvers/mutation/admin/{index.ts → index.d.ts} +0 -0
  51. package/resolvers/mutation/admin/index.js +14 -0
  52. package/resolvers/mutation/admin/token.d.ts +24 -0
  53. package/resolvers/mutation/admin/token.js +2 -0
  54. package/resolvers/mutation/{index.ts → index.d.ts} +0 -0
  55. package/resolvers/mutation/index.js +14 -0
  56. package/resolvers/mutation/restricted/{agora.ts → agora.d.ts} +4 -6
  57. package/resolvers/mutation/restricted/agora.js +2 -0
  58. package/resolvers/mutation/restricted/contactUs.d.ts +16 -0
  59. package/resolvers/mutation/restricted/contactUs.js +2 -0
  60. package/resolvers/mutation/restricted/{index.ts → index.d.ts} +0 -0
  61. package/resolvers/mutation/restricted/index.js +22 -0
  62. package/resolvers/mutation/restricted/marksheet.d.ts +43 -0
  63. package/resolvers/mutation/restricted/marksheet.js +2 -0
  64. package/resolvers/mutation/restricted/mockTest.d.ts +15 -0
  65. package/resolvers/mutation/restricted/mockTest.js +2 -0
  66. package/resolvers/mutation/restricted/osce.d.ts +52 -0
  67. package/resolvers/mutation/restricted/osce.js +2 -0
  68. package/resolvers/mutation/restricted/questionDiscussion.d.ts +28 -0
  69. package/resolvers/mutation/restricted/questionDiscussion.js +2 -0
  70. package/resolvers/mutation/restricted/todo.d.ts +43 -0
  71. package/resolvers/mutation/restricted/todo.js +2 -0
  72. package/resolvers/mutation/restricted/token.d.ts +21 -0
  73. package/resolvers/mutation/restricted/token.js +2 -0
  74. package/resolvers/mutation/restricted/users.d.ts +25 -0
  75. package/resolvers/mutation/restricted/users.js +2 -0
  76. package/resolvers/mutation/restricted/{video.ts → video.d.ts} +3 -5
  77. package/resolvers/mutation/restricted/video.js +2 -0
  78. package/resolvers/mutation/stripe.d.ts +2 -0
  79. package/resolvers/mutation/stripe.js +2 -0
  80. package/resolvers/mutation/users.d.ts +30 -0
  81. package/resolvers/mutation/users.js +2 -0
  82. package/resolvers/mutation/validUserToken/{index.ts → index.d.ts} +0 -0
  83. package/resolvers/mutation/validUserToken/index.js +13 -0
  84. package/resolvers/mutation/validUserToken/user.d.ts +8 -0
  85. package/resolvers/mutation/validUserToken/user.js +2 -0
  86. package/resolvers/query/admin/getUserToken.d.ts +4 -0
  87. package/resolvers/query/admin/getUserToken.js +2 -0
  88. package/resolvers/query/admin/{index.ts → index.d.ts} +0 -0
  89. package/resolvers/query/admin/index.js +13 -0
  90. package/resolvers/query/{index.ts → index.d.ts} +0 -0
  91. package/resolvers/query/index.js +17 -0
  92. package/resolvers/query/restricted/anatomy.d.ts +3 -0
  93. package/resolvers/query/restricted/anatomy.js +2 -0
  94. package/resolvers/query/restricted/{index.ts → index.d.ts} +0 -0
  95. package/resolvers/query/restricted/index.js +22 -0
  96. package/resolvers/query/restricted/marksheet.d.ts +59 -0
  97. package/resolvers/query/restricted/marksheet.js +2 -0
  98. package/resolvers/query/restricted/mockTests.d.ts +9 -0
  99. package/resolvers/query/restricted/mockTests.js +2 -0
  100. package/resolvers/query/restricted/osce.d.ts +35 -0
  101. package/resolvers/query/restricted/osce.js +2 -0
  102. package/resolvers/query/restricted/quesBook.d.ts +3 -0
  103. package/resolvers/query/restricted/quesBook.js +2 -0
  104. package/resolvers/query/restricted/todos.d.ts +28 -0
  105. package/resolvers/query/restricted/todos.js +2 -0
  106. package/resolvers/query/restricted/topics.d.ts +20 -0
  107. package/resolvers/query/restricted/topics.js +2 -0
  108. package/resolvers/query/restricted/university.d.ts +15 -0
  109. package/resolvers/query/restricted/university.js +2 -0
  110. package/resolvers/query/restricted/user.d.ts +25 -0
  111. package/resolvers/query/restricted/user.js +2 -0
  112. package/resolvers/query/restricted/video.d.ts +10 -0
  113. package/resolvers/query/restricted/video.js +2 -0
  114. package/resolvers/query/sampleCards.d.ts +6 -0
  115. package/resolvers/query/sampleCards.js +2 -0
  116. package/resolvers/query/sampleQuestions.d.ts +6 -0
  117. package/resolvers/query/sampleQuestions.js +2 -0
  118. package/resolvers/query/{university.ts → university.d.ts} +2 -4
  119. package/resolvers/query/university.js +2 -0
  120. package/resolvers/query/user.d.ts +12 -0
  121. package/resolvers/query/user.js +2 -0
  122. package/resolvers/query/video.d.ts +14 -0
  123. package/resolvers/query/video.js +2 -0
  124. package/resolvers/subscription/{index.ts → index.d.ts} +0 -0
  125. package/resolvers/subscription/index.js +13 -0
  126. package/resolvers/subscription/osce.d.ts +44 -0
  127. package/resolvers/subscription/osce.js +24 -0
  128. package/utils/uuid4.d.ts +107 -0
  129. package/utils/uuid4.js +287 -0
  130. package/gql_input_output_types/User.ts +0 -12
  131. package/gql_input_output_types/index.ts +0 -87
  132. package/index.ts +0 -18
  133. package/models/Card.ts +0 -16
  134. package/models/Chapter.ts +0 -13
  135. package/models/Concept.ts +0 -25
  136. package/models/File.ts +0 -11
  137. package/models/Marksheet.ts +0 -48
  138. package/models/MockTest.ts +0 -20
  139. package/models/OsceMarksheet.ts +0 -61
  140. package/models/OsceStation.ts +0 -44
  141. package/models/Picture.ts +0 -37
  142. package/models/Promo.ts +0 -16
  143. package/models/Question.ts +0 -62
  144. package/models/Subscription.ts +0 -12
  145. package/models/Todo.ts +0 -26
  146. package/models/Token.ts +0 -8
  147. package/models/Type.ts +0 -5
  148. package/models/University.ts +0 -5
  149. package/models/User.ts +0 -78
  150. package/models/Video.ts +0 -20
  151. package/resolvers/mutation/admin/algoliaSync.ts +0 -19
  152. package/resolvers/mutation/admin/token.ts +0 -32
  153. package/resolvers/mutation/restricted/contactUs.ts +0 -18
  154. package/resolvers/mutation/restricted/marksheet.ts +0 -57
  155. package/resolvers/mutation/restricted/mockTest.ts +0 -21
  156. package/resolvers/mutation/restricted/osce.ts +0 -72
  157. package/resolvers/mutation/restricted/questionDiscussion.ts +0 -39
  158. package/resolvers/mutation/restricted/todo.ts +0 -55
  159. package/resolvers/mutation/restricted/token.ts +0 -28
  160. package/resolvers/mutation/restricted/users.ts +0 -31
  161. package/resolvers/mutation/stripe.ts +0 -3
  162. package/resolvers/mutation/users.ts +0 -38
  163. package/resolvers/mutation/validUserToken/user.ts +0 -11
  164. package/resolvers/query/admin/getUserToken.ts +0 -5
  165. package/resolvers/query/restricted/anatomy.ts +0 -5
  166. package/resolvers/query/restricted/marksheet.ts +0 -71
  167. package/resolvers/query/restricted/mockTests.ts +0 -13
  168. package/resolvers/query/restricted/osce.ts +0 -52
  169. package/resolvers/query/restricted/quesBook.ts +0 -4
  170. package/resolvers/query/restricted/todos.ts +0 -35
  171. package/resolvers/query/restricted/topics.ts +0 -25
  172. package/resolvers/query/restricted/university.ts +0 -16
  173. package/resolvers/query/restricted/user.ts +0 -31
  174. package/resolvers/query/restricted/video.ts +0 -13
  175. package/resolvers/query/sampleCards.ts +0 -7
  176. package/resolvers/query/sampleQuestions.ts +0 -7
  177. package/resolvers/query/user.ts +0 -17
  178. package/resolvers/query/video.ts +0 -20
  179. package/resolvers/subscription/osce.ts +0 -68
  180. package/utils/uuid4.ts +0 -286
@@ -1,71 +0,0 @@
1
- import { Id, IMarksheet, IUserFlaggedQuestions } from '../../../models';
2
- import { IPreBuildMarksheet } from '../../mutation/restricted';
3
-
4
- export interface IMarksheetVar {
5
- id: Id;
6
- }
7
-
8
- export interface IMarksheetData extends IMarksheet {}
9
-
10
- export interface IPreBuildMarksheetVar {
11
- topics: number[];
12
- conceptIds: number[];
13
- search: string;
14
- source: string;
15
- difficulty?: number[];
16
- }
17
-
18
- export interface IPreBuildMarksheetData extends IPreBuildMarksheet {}
19
-
20
- interface IDashboardPastQuizzesFilter {
21
- limit: number;
22
- date?: string;
23
- offset?: number;
24
- }
25
-
26
- export interface IDashboardPastQuizzesInfoVar {
27
- pastQuizzesFilter: IDashboardPastQuizzesFilter;
28
- }
29
-
30
- export interface IDashboardPastQuizzesInfoRes {
31
- marksheetId: number;
32
- topicName: string[];
33
- correct: number;
34
- incorrect: number;
35
- totalQuestions: number;
36
- totalMarksheet: number;
37
- isTestMarksheet: boolean;
38
- startedAt: Date | string;
39
- endedAt: Date | string;
40
- }
41
-
42
- export type IDashboardPastQuizzesInfoData = IDashboardPastQuizzesInfoRes[];
43
-
44
- export type ILatestPastMarksheetIdVar = null;
45
-
46
- export type ILatestPastMarksheetIdData = number;
47
-
48
- export type IFlaggedQuestionsVar = null;
49
-
50
- export type IFlaggedQuestionsData = IUserFlaggedQuestions[];
51
-
52
- export interface IMarksheetFeedbackVar {
53
- id: Id;
54
- }
55
-
56
- export interface IMarksheetTopicFeedback {
57
- topicId: Id;
58
- name: string;
59
- score: number;
60
- avgScore: number;
61
- }
62
-
63
- export interface IMarksheetFeedbackData {
64
- marksheetId: Id;
65
- correct: number;
66
- incorrect: number;
67
- total: number;
68
- timeTaken: number;
69
- passingMark: number;
70
- topics: IMarksheetTopicFeedback[];
71
- }
@@ -1,13 +0,0 @@
1
- import { Id, IUserMockTest } from '../../../models';
2
-
3
- export interface IMockTestVar {
4
- id: Id;
5
- }
6
-
7
- export type IMockTestData = IUserMockTest;
8
-
9
- export interface IMockTestsVar {
10
- clinical: boolean;
11
- }
12
-
13
- export type IMockTestsData = IUserMockTest[];
@@ -1,52 +0,0 @@
1
- import {
2
- Id,
3
- IDashboardOsce,
4
- IOsceMarksheet,
5
- IOsceStation,
6
- IOsceStationItem,
7
- } from '../../../models';
8
-
9
- export interface IDashboardOsceVar {
10
- solo: boolean;
11
- }
12
-
13
- export interface IDashboardOsceData extends IDashboardOsce {}
14
-
15
- export interface IOsceMarksheetVar {
16
- id: number;
17
- }
18
-
19
- export interface IOsceMarksheetData extends IOsceMarksheet {}
20
-
21
- export interface IOsceStationVar {
22
- id: Id;
23
- }
24
-
25
- export interface IOsceStationData extends IOsceStation {}
26
-
27
- export interface IOsceMarksheetsVar {
28
- solo: boolean;
29
- }
30
-
31
- export type IOsceMarksheetsData = IOsceMarksheet[];
32
-
33
- export interface IOsceStationsVar {
34
- osceTypeId?: Id;
35
- solo: boolean;
36
- attempted: boolean;
37
- difficulty: number[];
38
- }
39
-
40
- export type IOsceStationsData = IOsceStationItem[];
41
-
42
- export interface ISearchOsceStationsVar {
43
- search: string;
44
- }
45
-
46
- export type ISearchOsceStationsData = IOsceStationItem[];
47
-
48
- export interface IHeartbeatVar {
49
- agoraId: string;
50
- }
51
-
52
- export type IHeartBeatData = boolean;
@@ -1,4 +0,0 @@
1
- import { ITopic } from '../../../models';
2
-
3
- export type IQuesBookVar = null;
4
- export type IQuesBookData = ITopic[];
@@ -1,35 +0,0 @@
1
- import { Id, IPreBuildTodo, ITodo } from '../../../models';
2
-
3
- export interface IPreBuildTodoVar {
4
- topics: number[];
5
- conceptIds: number[];
6
- search: string;
7
- source: string;
8
- filterOlderCard: boolean;
9
- }
10
-
11
- export type IPreBuildTodoData = IPreBuildTodo;
12
-
13
- export interface IGetTodoInfoVar {
14
- todoId: Id;
15
- }
16
-
17
- export type IGetTodoInfoData = ITodo;
18
-
19
- export type IDailyFeedVar = null;
20
-
21
- interface IDailyFeedTopicInfo {
22
- name: string;
23
- topicQuestionCount: number;
24
- }
25
-
26
- export interface IDailyFeed {
27
- topic: IDailyFeedTopicInfo[];
28
- totalCard: number;
29
- todoId: number;
30
- learnCard: number;
31
- confidentCard: number;
32
- reviewCard: number;
33
- }
34
-
35
- export type IDailyFeedData = IDailyFeed;
@@ -1,25 +0,0 @@
1
- import { Id, ITopic } from '../../../models';
2
-
3
- export interface ITopicVar {
4
- id: Id;
5
- }
6
-
7
- export type ITopicData = ITopic;
8
-
9
- export interface ITopicsVar {
10
- filter: 'clinical' | 'pre-clinical' | 'interpretation';
11
- }
12
-
13
- export interface ITopicInfo {
14
- id: number;
15
- name: string;
16
- totalQuestions: number;
17
- correctQuestions: number;
18
- incorrectQuestions: number;
19
- totalCards: number;
20
- ConfidentCards: number;
21
- ReviewCards: number;
22
- LearnCards: number;
23
- }
24
-
25
- export type ITopicsData = ITopicInfo[];
@@ -1,16 +0,0 @@
1
- export interface IUniversityLeaderboardVar {
2
- limit: number;
3
- }
4
-
5
- export interface IUniversitiesRankSpeciality {
6
- name: string;
7
- speciality: string;
8
- rank: number;
9
- }
10
- export interface IUniversityLeaderboard {
11
- updatedAt: Date | string | null;
12
- month: IUniversitiesRankSpeciality[];
13
- quarter: IUniversitiesRankSpeciality[];
14
- }
15
-
16
- export interface IUniversityLeaderboardData extends IUniversityLeaderboard {}
@@ -1,31 +0,0 @@
1
- import { ISubscription, IUser } from '../../../models';
2
-
3
- export type IDashboardUserVar = null;
4
-
5
- export interface IDashboardUserData {
6
- examDate: Date | string;
7
- totalQuestions: number;
8
- completedQuestionsCount: number;
9
- completedCorrectQuestionsCount: number;
10
- completedIncorrectQuestionsCount: number;
11
- totalCards: number;
12
- completedCardsCount: number;
13
- completedCardsConfidentCount: number;
14
- completedCardsReviewCount: number;
15
- completedCardsLearnCount: number;
16
- subscription: ISubscription;
17
- }
18
-
19
- export type IUserVar = null;
20
-
21
- export interface IUserData extends IUser {}
22
-
23
- export type IDailyProgressVar = null;
24
-
25
- export interface IDailyProgressInfo {
26
- totalCount: number;
27
- totalTrue: number;
28
- dateString: string;
29
- }
30
-
31
- export type IDailyProgressData = IDailyProgressInfo[];
@@ -1,13 +0,0 @@
1
- import { Id, IVideo } from '../../../models';
2
-
3
- export interface IVideoVar {
4
- id: Id;
5
- }
6
-
7
- export type IVideoData = IVideo;
8
-
9
- export interface IVideosVar {
10
- filter: 'new' | 'popular' | 'personal' | 'live';
11
- limit: number;
12
- }
13
- export type IVideosData = IVideo[];
@@ -1,7 +0,0 @@
1
- import { ITodo } from '../../models';
2
-
3
- export interface ISampleCardsVar {
4
- filter: 'sample-clinical-quescards' | 'sample-pre-clinical-quescards';
5
- }
6
-
7
- export interface ISampleCardsData extends ITodo {}
@@ -1,7 +0,0 @@
1
- import { IMarksheet } from '../../models';
2
-
3
- export interface ISampleQuestionsVar {
4
- filter: 'sample-clinical-questions' | 'sample-pre-clinical-questions';
5
- }
6
-
7
- export interface ISampleQuestionsData extends IMarksheet {}
@@ -1,17 +0,0 @@
1
- export interface IUsernameAvailableVar {
2
- username: string;
3
- }
4
-
5
- export type IUsernameAvailableData = boolean;
6
-
7
- export interface IUsernameProvisionedVar {
8
- username: string;
9
- }
10
-
11
- export type IUsernameProvisionedData = boolean;
12
-
13
- export interface IValidateResetPasswordTokenVar {
14
- token: string;
15
- }
16
-
17
- export type IValidateResetPasswordTokenData = string;
@@ -1,20 +0,0 @@
1
- import { Id, IVideo } from '../../models';
2
-
3
- export interface IVideosVar {
4
- filter: 'new' | 'popular' | 'personal' | 'live';
5
- limit: number;
6
- }
7
-
8
- export type IVideosData = IVideo[];
9
-
10
- export interface IVideoVar {
11
- id: Id;
12
- }
13
-
14
- export type IVideoData = IVideo;
15
-
16
- export interface IZoomSignatureVar {
17
- meetingNumber: string;
18
- }
19
-
20
- export type IZoomSignatureData = string;
@@ -1,68 +0,0 @@
1
- import { EOsceMarksheetAction, EOsceRoles, Id, IUser } from '../../models';
2
-
3
- export const ROLE_CHANGED = 'ROLE_CHANGED';
4
- export const OSCE_MARKSHEET_ACTION = 'OSCE_MARKSHEET_ACTION';
5
-
6
- export interface IOsceGroupMember {
7
- role: EOsceRoles;
8
- user: IUser | null;
9
- }
10
-
11
- export interface IOsceGroup {
12
- agoraId: string;
13
- members: [
14
- {
15
- role: EOsceRoles.CANDIDATE;
16
- user: IUser | null;
17
- },
18
- {
19
- role: EOsceRoles.EXAMINER;
20
- user: IUser | null;
21
- },
22
- {
23
- role: EOsceRoles.ACTOR;
24
- user: IUser | null;
25
- },
26
- {
27
- role: EOsceRoles.OBSERVER;
28
- user: IUser | null;
29
- }
30
- ];
31
- }
32
-
33
- export const OsceGroupInit: IOsceGroup['members'] = [
34
- {
35
- role: EOsceRoles.CANDIDATE,
36
- user: null,
37
- },
38
- {
39
- role: EOsceRoles.EXAMINER,
40
- user: null,
41
- },
42
- {
43
- role: EOsceRoles.ACTOR,
44
- user: null,
45
- },
46
- {
47
- role: EOsceRoles.OBSERVER,
48
- user: null,
49
- },
50
- ];
51
-
52
- export interface IRoleChangedVar {
53
- agoraId: string;
54
- }
55
-
56
- export interface IRoleChangedData extends IOsceGroup {}
57
-
58
- export interface IOsceMarksheetActionsVar {
59
- agoraId: string;
60
- }
61
-
62
- export interface IOsceMarksheetAction {
63
- agoraId: string;
64
- userId: Id;
65
- action: EOsceMarksheetAction;
66
- }
67
-
68
- export interface IOsceMarksheetActionsData extends IOsceMarksheetAction {}
package/utils/uuid4.ts DELETED
@@ -1,286 +0,0 @@
1
- class Uuid4 {
2
- /**
3
- * Generate a custom base 64 encoded UUID v4 (random).
4
- *
5
- * @param {Uint8Array} [data] Should normally be `undefined` to create a
6
- * truly random v4 UUID.
7
- * @returns {string} Returns a custom base 64 encoded UUID v4.
8
- */
9
- public static asBase64(data?: Uint8Array): string {
10
- // Add an initial 4 bit zero pad so result is always 22 chars long.
11
- const binString = '0000' + Uuid4._asBinString(data);
12
- let result = '';
13
- let pieces = [
14
- 0, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96, 102,
15
- 108, 114, 120, 126,
16
- ];
17
- for (const piece of pieces) {
18
- result += Uuid4._base64[binString.substr(piece, 6)];
19
- }
20
- return result;
21
- }
22
- /**
23
- * Generate a hexadecimal encoded UUID v4 (random).
24
- *
25
- * @param {Uint8Array} [data] Should normally be `undefined` to create a
26
- * truly random v4 UUID.
27
- * @returns {string} Returns a hexadecimal encoded UUID v4.
28
- */
29
- public static asHexString(data?: Uint8Array): string {
30
- const binString = Uuid4._asBinString(data);
31
- let hexString = '';
32
- const pieces = [0, 16, 32, 48, 64, 80, 96, 112];
33
- for (const piece of pieces) {
34
- hexString += parseInt(binString.substr(piece, 16), 2)
35
- .toString(16)
36
- .padStart(4, '0');
37
- }
38
- return hexString;
39
- }
40
- /**
41
- * Generate a standard UUID v4 (random).
42
- *
43
- * @param {Uint8Array} [data] Should normally be `undefined` to create a
44
- * truly random v4 UUID.
45
- * @returns {string} Returns a standard UUID v4.
46
- */
47
- public static asUuid(data?: Uint8Array): string {
48
- const hex = Uuid4.asHexString(data);
49
- return Uuid4.fromHexStringToUuid(hex);
50
- }
51
- /**
52
- * Convert from a base 64 encoded to a hexadecimal encoded UUID.
53
- *
54
- * NOTE: This method does not verify input is valid UUID.
55
- *
56
- * @param {string} data A base 64 encoded UUID.
57
- * @returns {string} Returns a hexadecimal encoded UUID.
58
- */
59
- public static fromBase64ToHexString(data: string): string {
60
- if (22 !== data.length) {
61
- const mess = `Expected base 64 number length of 22 characters but was given length: ${data.length}`;
62
- throw new RangeError(mess);
63
- }
64
- // Need switched keys and values so reverse lookups can be done.
65
- let flipped: { [key: string]: string } = {};
66
- for (const [key, value] of Object.entries(Uuid4._base64)) {
67
- flipped[value] = key;
68
- }
69
- let binString = '';
70
- for (let i = 0, len = data.length; i < len; ++i) {
71
- binString += flipped[data[i]];
72
- }
73
- // Cut off 4 bit zero padding.
74
- binString = binString.substr(-128);
75
- let hexString = '';
76
- const pieces = [0, 32, 64, 96];
77
- for (const piece of pieces) {
78
- hexString += parseInt(binString.substr(piece, 32), 2)
79
- .toString(16)
80
- .padStart(8, '0');
81
- }
82
- return hexString;
83
- }
84
- /**
85
- * Convert from a base 64 encoded to a standard UUID.
86
- *
87
- * NOTE: This method does not verify input is valid UUID.
88
- *
89
- * @param {string} data The base 64 encoded UUID.
90
- * @returns {string} Returns a standard UUID.
91
- */
92
- public static fromBase64ToUuid(data: string): string {
93
- const hexString = Uuid4.fromBase64ToHexString(data);
94
- return Uuid4.fromHexStringToUuid(hexString);
95
- }
96
- /**
97
- * Convert from a hexadecimal encoded to a base 64 encoded UUID.
98
- *
99
- * NOTE: This method does not verify input is valid UUID.
100
- *
101
- * @param {string} data The hexadecimal encoded UUID.
102
- * @returns {string} Returns base 64 encoded UUID.
103
- */
104
- public static fromHexStringToBase64(data: string): string {
105
- if (32 !== data.length) {
106
- const mess = `Expected hex string length of 32 characters but was given length: ${data.length}`;
107
- throw new RangeError(mess);
108
- }
109
- let pieces = [0, 4, 8, 12, 16, 20, 24, 28];
110
- let binString = '0000';
111
- for (const piece of pieces) {
112
- binString += parseInt(data.substr(piece, 4), 16)
113
- .toString(2)
114
- .padStart(16, '0');
115
- }
116
- let result = '';
117
- pieces = [
118
- 0, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96, 102,
119
- 108, 114, 120, 126,
120
- ];
121
- for (const piece of pieces) {
122
- result += Uuid4._base64[binString.substr(piece, 6)];
123
- }
124
- return result;
125
- }
126
- /**
127
- * Convert from a hexadecimal encoded to a standard UUID.
128
- *
129
- * NOTE: This method does not verify input is valid UUID.
130
- *
131
- * @param {string} data The hexadecimal encoded UUID.
132
- * @returns {string} Returns a standard UUID.
133
- */
134
- public static fromHexStringToUuid(data: string): string {
135
- if (32 !== data.length) {
136
- const mess = `Expected hex string length of 32 characters but was given length: ${data.length}`;
137
- throw new RangeError(mess);
138
- }
139
- const pieces = [8, 4, 4, 4, 12];
140
- let start = 0;
141
- let hexArray: string[] = [];
142
- for (const piece of pieces) {
143
- hexArray.push(data.substr(start, piece));
144
- start += piece;
145
- }
146
- return hexArray.join('-');
147
- }
148
- /**
149
- * Convert from a standard UUID to a base 64 encoded UUID.
150
- *
151
- * NOTE: This method does not verify input is valid UUID.
152
- *
153
- * @param {string} data The standard UUID.
154
- * @returns {string} Returns base 64 encoded UUID.
155
- */
156
- public static fromUuidToBase64(data: string): string {
157
- const hexString = data.replace(/-/g, '');
158
- return Uuid4.fromHexStringToBase64(hexString);
159
- }
160
- /**
161
- * Convert from a standard UUID to a hexadecimal encoded UUID.
162
- *
163
- * NOTE: This method does not verify input is valid UUID.
164
- *
165
- * @param {string} data The standard UUID.
166
- * @returns {string} Returns a hexadecimal encoded UUID.
167
- */
168
- public static fromUuidToHexString(data: string): string {
169
- return data.replace(/-/g, '');
170
- }
171
- public get [Symbol.toStringTag]() {
172
- return 'Uuid4';
173
- }
174
- /**
175
- * Helper method for the common parts of creating new UUID encoded as a binary string.
176
- *
177
- * @param {Uint8Array} [data] Should normally be `undefined` to create a
178
- * truly random v4 UUID.
179
- * @returns {string} Returns an UUID encoded as a binary string.
180
- * @private
181
- */
182
- protected static _asBinString(data?: Uint8Array): string {
183
- let binArray = data ?? Uuid4._getRandomArray();
184
- if (16 !== binArray.length) {
185
- const mess = `Expected data array length of 16 but was given length: ${binArray.length}`;
186
- throw new RangeError(mess);
187
- }
188
- binArray[6] = (binArray[6] & 0x0f) | 0x40;
189
- binArray[8] = (binArray[8] & 0x3f) | 0x80;
190
- let binary = '';
191
- for (const piece of binArray) {
192
- binary += piece.toString(2).padStart(8, '0');
193
- }
194
- return binary;
195
- }
196
- /**
197
- * Used to paste over differences in browser vs node secure random number generation.
198
- *
199
- * @returns {Uint8Array} Returns a new random number filled Uint8Array.
200
- * @private
201
- */
202
- protected static _getRandomArray(): Uint8Array {
203
- if (typeof window === 'undefined') {
204
- let crypto = require('crypto');
205
- return Uint8Array.from(crypto.randomBytes(16));
206
- }
207
- // `result` is modified in place.
208
- let result = new Uint8Array(16);
209
- window.crypto.getRandomValues(result);
210
- return result;
211
- }
212
- /**
213
- * Used in mapping from binary to base 64 during encoding.
214
- *
215
- * @type {object}
216
- * @private
217
- */
218
- protected static _base64: { [key: string]: string } = {
219
- '000000': 'A',
220
- '000001': 'B',
221
- '000010': 'C',
222
- '000011': 'D',
223
- '000100': 'E',
224
- '000101': 'F',
225
- '000110': 'G',
226
- '000111': 'H',
227
- '001000': 'I',
228
- '001001': 'J',
229
- '001010': 'K',
230
- '001011': 'L',
231
- '001100': 'M',
232
- '001101': 'N',
233
- '001110': 'O',
234
- '001111': 'P',
235
- '010000': 'Q',
236
- '010001': 'R',
237
- '010010': 'S',
238
- '010011': 'T',
239
- '010100': 'U',
240
- '010101': 'V',
241
- '010110': 'W',
242
- '010111': 'X',
243
- '011000': 'Y',
244
- '011001': 'Z',
245
- '011010': 'a',
246
- '011011': 'b',
247
- '011100': 'c',
248
- '011101': 'd',
249
- '011110': 'e',
250
- '011111': 'f',
251
- '100000': 'g',
252
- '100001': 'h',
253
- '100010': 'i',
254
- '100011': 'j',
255
- '100100': 'k',
256
- '100101': 'l',
257
- '100110': 'm',
258
- '100111': 'n',
259
- '101000': 'o',
260
- '101001': 'p',
261
- '101010': 'q',
262
- '101011': 'r',
263
- '101100': 's',
264
- '101101': 't',
265
- '101110': 'u',
266
- '101111': 'v',
267
- '110000': 'w',
268
- '110001': 'x',
269
- '110010': 'y',
270
- '110011': 'z',
271
- '110100': '0',
272
- '110101': '1',
273
- '110110': '2',
274
- '110111': '3',
275
- '111000': '4',
276
- '111001': '5',
277
- '111010': '6',
278
- '111011': '7',
279
- '111100': '8',
280
- '111101': '9',
281
- '111110': '-',
282
- '111111': '_',
283
- };
284
- }
285
-
286
- export default Uuid4;