@shakerquiz/utilities 1.0.0 → 3.0.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 (94) hide show
  1. package/dprint.json +4 -12
  2. package/jsconfig.json +13 -6
  3. package/package.json +9 -12
  4. package/source/enumerations/core/features.js +56 -0
  5. package/source/enumerations/core/methods.js +16 -0
  6. package/source/enumerations/core/networks.js +6 -0
  7. package/source/enumerations/core/runtimes.js +6 -0
  8. package/source/enumerations/entities/affilation.js +91 -0
  9. package/source/enumerations/entities/cities-mode.js +49 -0
  10. package/source/enumerations/entities/city/timezone-mode.js +44 -0
  11. package/source/enumerations/entities/city/venues-mode.js +60 -0
  12. package/source/enumerations/entities/game-status.js +130 -0
  13. package/source/enumerations/entities/password-mode.js +40 -0
  14. package/source/enumerations/entities/registration-attribute.js +83 -0
  15. package/source/enumerations/entities/registration-channel.js +26 -0
  16. package/source/enumerations/entities/registration-lineup.js +75 -0
  17. package/source/enumerations/entities/registration-mailing.js +24 -0
  18. package/source/enumerations/entities/registration-status.js +89 -0
  19. package/source/enumerations/entities/role-mode.js +40 -0
  20. package/source/enumerations/entities/role.js +82 -0
  21. package/source/enumerations/entities/venue/audience.js +100 -0
  22. package/source/enumerations/entities/venue/city-mode.js +44 -0
  23. package/source/enumerations/entities/venue/status.js +53 -0
  24. package/source/enumerations/entities/version.js +76 -0
  25. package/source/enumerations/{constants.js → misc/constants.js} +2 -2
  26. package/source/enumerations/misc/icons.js +655 -0
  27. package/source/enumerations/misc/keys.js +15 -0
  28. package/source/enumerations/misc/phases.js +42 -0
  29. package/source/enumerations/misc/regexps.js +5 -0
  30. package/source/enumerations/misc/routes.js +610 -0
  31. package/source/functions/tag.d.ts +1 -0
  32. package/source/functions/tag.js +5 -0
  33. package/source/index.js +34 -11
  34. package/source/schemas/PATCH/city/admin.json +126 -0
  35. package/source/schemas/PATCH/city/currency/admin.json +173 -0
  36. package/source/schemas/PATCH/city/timezone/admin.json +501 -0
  37. package/source/schemas/PATCH/game/admin.json +30 -0
  38. package/source/schemas/PATCH/game/organizer.json +30 -0
  39. package/source/schemas/PATCH/registration/admin.json +43 -0
  40. package/source/schemas/PATCH/registration/cancellation/default.json +12 -0
  41. package/source/schemas/PATCH/registration/channel/default.json +22 -0
  42. package/source/schemas/PATCH/registration/confirmation/default.json +12 -0
  43. package/source/schemas/PATCH/registration/default.json +10 -0
  44. package/source/schemas/PATCH/registration/organizer.json +43 -0
  45. package/source/schemas/PATCH/theme/admin.json +19 -0
  46. package/source/schemas/PATCH/user/admin.json +30 -0
  47. package/source/schemas/PATCH/user/cities/admin.json +17 -0
  48. package/source/schemas/PATCH/user/password/admin.json +12 -0
  49. package/source/schemas/PATCH/user/role/admin.json +13 -0
  50. package/source/schemas/PATCH/venue/admin.json +44 -0
  51. package/source/schemas/PATCH/venue/organizer.json +44 -0
  52. package/source/schemas/POST/checkin/default.json +16 -0
  53. package/source/schemas/POST/city/admin.json +696 -0
  54. package/source/schemas/POST/game/admin.json +27 -0
  55. package/source/schemas/POST/game/organizer.json +27 -0
  56. package/source/schemas/POST/game/registrations/export/admin.json +17 -0
  57. package/source/schemas/POST/game/registrations/export/organizer.json +17 -0
  58. package/source/schemas/POST/registration/default.json +125 -0
  59. package/source/schemas/POST/registration/mailing/admin.json +16 -0
  60. package/source/schemas/POST/registration/mailing/organizer.json +16 -0
  61. package/source/schemas/POST/registrations/export/admin.json +17 -0
  62. package/source/schemas/POST/registrations/export/organizer.json +17 -0
  63. package/source/schemas/POST/theme/admin.json +24 -0
  64. package/source/schemas/POST/user/admin.json +12 -0
  65. package/source/schemas/POST/user/cities/admin.json +17 -0
  66. package/source/schemas/POST/user/password/admin.json +12 -0
  67. package/source/schemas/POST/user/role/admin.json +13 -0
  68. package/source/schemas/POST/venue/admin.json +38 -0
  69. package/source/schemas/POST/venue/organizer.json +38 -0
  70. package/source/enumerations/constants.d.ts +0 -3
  71. package/source/enumerations/cookies.d.ts +0 -5
  72. package/source/enumerations/cookies.js +0 -5
  73. package/source/enumerations/features.d.ts +0 -58
  74. package/source/enumerations/features.js +0 -49
  75. package/source/enumerations/game-statuses.d.ts +0 -39
  76. package/source/enumerations/game-statuses.js +0 -39
  77. package/source/enumerations/kinds.d.ts +0 -4
  78. package/source/enumerations/kinds.js +0 -4
  79. package/source/enumerations/methods.d.ts +0 -7
  80. package/source/enumerations/methods.js +0 -7
  81. package/source/enumerations/networks.d.ts +0 -4
  82. package/source/enumerations/networks.js +0 -4
  83. package/source/enumerations/phases.d.ts +0 -7
  84. package/source/enumerations/phases.js +0 -7
  85. package/source/enumerations/regexps.d.ts +0 -4
  86. package/source/enumerations/regexps.js +0 -6
  87. package/source/enumerations/roles.d.ts +0 -5
  88. package/source/enumerations/roles.js +0 -5
  89. package/source/functions/request.d.ts +0 -131
  90. package/source/functions/request.js +0 -202
  91. package/source/globals.d.ts +0 -14
  92. package/source/index.d.ts +0 -15
  93. package/source/results.d.ts +0 -137
  94. package/source/rows.d.ts +0 -533
@@ -1,4 +0,0 @@
1
- export let Networks: {
2
- Private: 'Private'
3
- Public: 'Public'
4
- }
@@ -1,4 +0,0 @@
1
- export let Networks = {
2
- Private: 'Private',
3
- Public: 'Public',
4
- }
@@ -1,7 +0,0 @@
1
- export let Phases: {
2
- Aborted: 'Aborted'
3
- Failed: 'Failed'
4
- Idle: 'Idle'
5
- Loaded: 'Loaded'
6
- Loading: 'Loading'
7
- }
@@ -1,7 +0,0 @@
1
- export let Phases = {
2
- Aborted: 'Aborted',
3
- Failed: 'Failed',
4
- Idle: 'Idle',
5
- Loaded: 'Loaded',
6
- Loading: 'Loading',
7
- }
@@ -1,4 +0,0 @@
1
- export let RegExps: {
2
- Uuid: RegExp
3
- ElementId: RegExp
4
- }
@@ -1,6 +0,0 @@
1
- export let RegExps = {
2
- Uuid: /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/,
3
-
4
- ElementId:
5
- /\d+:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}:\d+/,
6
- }
@@ -1,5 +0,0 @@
1
- export let Roles: {
2
- Admin: 'admin'
3
- Organizer: 'organizer'
4
- Default: 'default'
5
- }
@@ -1,5 +0,0 @@
1
- export let Roles = {
2
- Admin: 'admin',
3
- Organizer: 'organizer',
4
- Default: 'default',
5
- }
@@ -1,131 +0,0 @@
1
- import { URLOptions } from '@yurkimus/url'
2
-
3
- import { Features } from '../enumerations/features'
4
- import { Methods } from '../enumerations/methods'
5
- import { Networks } from '../enumerations/networks'
6
-
7
- export let Extensions: WeakMap<
8
- Function,
9
- Map<
10
- | 'onbefore'
11
- | 'onfulfilled'
12
- | 'onrejected',
13
- Set<Function>
14
- >
15
- >
16
-
17
- export let useRequest: <
18
- Feature extends keyof typeof Features,
19
- Method extends keyof typeof Methods,
20
- Network extends keyof typeof Networks,
21
- >(
22
- feature: Feature,
23
- method: Method,
24
- network: Network,
25
- ) => (options: URLOptions, init: RequestInit) => Promise<
26
- {
27
- [Features.Checkin]: {
28
- [Methods.DELETE]: unknown
29
- [Methods.GET]: CheckinResult
30
- [Methods.OPTIONS]: unknown
31
- [Methods.PATCH]: unknown
32
- [Methods.POST]: unknown
33
- }
34
-
35
- [Features.City]: {
36
- [Methods.DELETE]: unknown
37
- [Methods.GET]: CityResult
38
- [Methods.OPTIONS]: unknown
39
- [Methods.PATCH]: unknown
40
- [Methods.POST]: unknown
41
- }
42
-
43
- [Features.Cities]: {
44
- [Methods.DELETE]: unknown
45
- [Methods.GET]: CityResult[]
46
- [Methods.OPTIONS]: unknown
47
- [Methods.PATCH]: unknown
48
- [Methods.POST]: unknown
49
- }
50
-
51
- [Features.CityPublic]: {
52
- [Methods.DELETE]: unknown
53
- [Methods.GET]: CityPublicResult
54
- [Methods.OPTIONS]: unknown
55
- [Methods.PATCH]: unknown
56
- [Methods.POST]: unknown
57
- }
58
-
59
- [Features.CitiesPublic]: {
60
- [Methods.DELETE]: unknown
61
- [Methods.GET]: CityPublicResult[]
62
- [Methods.OPTIONS]: unknown
63
- [Methods.PATCH]: unknown
64
- [Methods.POST]: unknown
65
- }
66
-
67
- [Features.Theme]: {
68
- [Methods.DELETE]: unknown
69
- [Methods.GET]: ThemeResult
70
- [Methods.OPTIONS]: unknown
71
- [Methods.PATCH]: unknown
72
- [Methods.POST]: unknown
73
- }
74
-
75
- [Features.Themes]: {
76
- [Methods.DELETE]: unknown
77
- [Methods.GET]: ThemeResult[]
78
- [Methods.OPTIONS]: unknown
79
- [Methods.PATCH]: unknown
80
- [Methods.POST]: unknown
81
- }
82
-
83
- [Features.Game]: {
84
- [Methods.DELETE]: unknown
85
- [Methods.GET]: unknown
86
- [Methods.OPTIONS]: GameResult
87
- [Methods.PATCH]: unknown
88
- [Methods.POST]: unknown
89
- }
90
-
91
- [Features.Games]: {
92
- [Methods.DELETE]: unknown
93
- [Methods.GET]: GameResult[]
94
- [Methods.OPTIONS]: unknown
95
- [Methods.PATCH]: unknown
96
- [Methods.POST]: unknown
97
- }
98
-
99
- [Features.GamePublic]: {
100
- [Methods.DELETE]: unknown
101
- [Methods.GET]: GamePublicResult
102
- [Methods.OPTIONS]: unknown
103
- [Methods.PATCH]: unknown
104
- [Methods.POST]: unknown
105
- }
106
-
107
- [Features.GamesPublic]: {
108
- [Methods.DELETE]: unknown
109
- [Methods.GET]: GamePublicResult[]
110
- [Methods.OPTIONS]: unknown
111
- [Methods.PATCH]: unknown
112
- [Methods.POST]: unknown
113
- }
114
-
115
- [Features.User]: {
116
- [Methods.DELETE]: unknown
117
- [Methods.GET]: unknown
118
- [Methods.OPTIONS]: unknown
119
- [Methods.PATCH]: unknown
120
- [Methods.POST]: unknown
121
- }
122
-
123
- [Features.Users]: {
124
- [Methods.DELETE]: unknown
125
- [Methods.GET]: unknown
126
- [Methods.OPTIONS]: unknown
127
- [Methods.PATCH]: unknown
128
- [Methods.POST]: unknown
129
- }
130
- }[Feature][Method]
131
- >
@@ -1,202 +0,0 @@
1
- import * as cookies from '@yurkimus/cookies'
2
- import { MessageError } from '@yurkimus/errors'
3
- import * as message from '@yurkimus/message'
4
- import { ResponseStatus } from '@yurkimus/response-status'
5
-
6
- import {
7
- FeatureKinds,
8
- FeatureRequests,
9
- FeatureUrls,
10
- } from '../enumerations/features.js'
11
- import { Kinds } from '../enumerations/kinds.js'
12
-
13
- let handleMessage = (feature, [response, body]) => {
14
- switch (response.status) {
15
- case 200:
16
- case 201:
17
- return body
18
-
19
- case 204:
20
- switch (FeatureKinds[feature]) {
21
- case Kinds.Item:
22
- return null
23
-
24
- case Kinds.List:
25
- return []
26
- }
27
-
28
- case 400:
29
- case 401:
30
- case 403:
31
- case 404:
32
- case 409:
33
- case 415:
34
- case 500:
35
- case 502:
36
- throw MessageError(
37
- body.message,
38
- ResponseStatus(response.status),
39
- )
40
-
41
- default:
42
- throw body
43
- }
44
- }
45
-
46
- /**
47
- * @template {FeaturesUnion} Feature
48
- * @template {MethodsUnion} Method
49
- * @template {NetworksUnion} Network
50
- *
51
- * @param {Feature} feature
52
- * @param {Method} method
53
- * @param {Network} network
54
- * @param {import('@yurkimus/url').URLOptions | undefined} options
55
- * @param {RequestInit} init
56
- */
57
- let makeRequest = (feature, method, network, options, init) => {
58
- if (!('method' in init))
59
- init.method = method
60
-
61
- let url = FeatureUrls
62
- .get(feature)
63
- .get(network)
64
-
65
- let request = new Request(url(options), init)
66
-
67
- if (!request.headers.has('Content-Type'))
68
- request.headers.set(
69
- 'Content-Type',
70
- 'application/json',
71
- )
72
-
73
- if ('cookie' in init)
74
- request.headers.set(
75
- 'Authorization',
76
- cookies.read('shaker-quiz-token', init.cookie),
77
- )
78
-
79
- return fetch(request)
80
- .then(message.read)
81
- .then(handleMessage.bind(undefined, feature))
82
- }
83
-
84
- /**
85
- * @type {WeakMap<Function, Map<'onbefore' | 'onfulfilled' | 'onrejected', Set<Function>>>}
86
- */
87
- export let Extensions = new WeakMap()
88
-
89
- /**
90
- * @template {FeaturesUnion} Feature
91
- * @template {MethodsUnion} Method
92
- * @template {NetworksUnion} Network
93
- *
94
- * @param {Feature} feature
95
- * @param {Method} method
96
- * @param {Network} network
97
- */
98
- export let useRequest = (feature, method, network) => {
99
- if (
100
- !FeatureRequests
101
- .has(feature)
102
- )
103
- throw TypeError(`Feature '${feature}' must be listed in 'FeatureRequests'.`)
104
-
105
- if (
106
- !FeatureRequests
107
- .get(feature)
108
- .has(method)
109
- )
110
- throw TypeError(`Method '${method}' must be listed in 'FeatureRequests'.`)
111
-
112
- if (
113
- !FeatureUrls
114
- .has(feature)
115
- )
116
- throw TypeError(`Feature '${feature}' must be listed in 'FeatureUrls'.`)
117
-
118
- if (
119
- !FeatureUrls
120
- .get(feature)
121
- .has(network)
122
- )
123
- throw TypeError(`Network '${network}' must be listed in 'FeatureUrls'.`)
124
-
125
- /**
126
- * @param {import('@yurkimus/url').URLOptions} options
127
- * @param {RequestInit} init
128
- */
129
- let request = (options, init) => {
130
- let onbefore = parameters => {
131
- let predicates = Extensions
132
- .get(request)
133
- .get('onbefore')
134
-
135
- return (predicates.size > 0)
136
- ? Array
137
- .from(predicates)
138
- .reduce(
139
- (parameters, onbefore) => onbefore(parameters),
140
- parameters,
141
- )
142
- : parameters
143
- }
144
-
145
- let onfulfilled = contract => {
146
- let predicates = Extensions
147
- .get(request)
148
- .get('onfulfilled')
149
-
150
- return (predicates.size > 0)
151
- ? Array
152
- .from(predicates)
153
- .reduce(
154
- (contract, onfulfilled) => onfulfilled(contract),
155
- contract,
156
- )
157
- : contract
158
- }
159
-
160
- let onrejected = reason => {
161
- let predicates = Extensions
162
- .get(request)
163
- .get('onrejected')
164
-
165
- Array
166
- .from(predicates)
167
- .forEach(onrejected => onrejected(reason))
168
-
169
- throw reason
170
- }
171
-
172
- return new Promise((resolve, reject) => {
173
- try {
174
- resolve(onbefore([options, init]))
175
- } catch (reason) {
176
- reject(reason)
177
- }
178
- })
179
- .then(([options, init]) =>
180
- makeRequest(
181
- feature,
182
- method,
183
- network,
184
- options,
185
- init,
186
- )
187
- )
188
- .then(onfulfilled)
189
- .catch(onrejected)
190
- }
191
-
192
- Extensions.set(
193
- request,
194
- new Map([
195
- ['onbefore', new Set([])],
196
- ['onfulfilled', new Set([])],
197
- ['onrejected', new Set([])],
198
- ]),
199
- )
200
-
201
- return request
202
- }
@@ -1,14 +0,0 @@
1
- /**
2
- * General
3
- */
4
-
5
- type Nullable<Type> = Type | null
6
-
7
- /**
8
- * Mixins
9
- */
10
-
11
- interface RequestInit {
12
- /** A string to declaratively set the Authorization header. */
13
- cookie?: string
14
- }
package/source/index.d.ts DELETED
@@ -1,15 +0,0 @@
1
- /// <reference path="globals.d.ts" />
2
- /// <reference path="results.d.ts" />
3
- /// <reference path="rows.d.ts" />
4
-
5
- export * from './enumerations/constants.js'
6
- export * from './enumerations/cookies.js'
7
- export * from './enumerations/features.js'
8
- export * from './enumerations/game-statuses.js'
9
- export * from './enumerations/kinds.js'
10
- export * from './enumerations/methods.js'
11
- export * from './enumerations/networks.js'
12
- export * from './enumerations/phases.js'
13
- export * from './enumerations/regexps.js'
14
- export * from './enumerations/roles.js'
15
- export * from './functions/request.js'
@@ -1,137 +0,0 @@
1
- /**
2
- * Checkin
3
- */
4
-
5
- type CheckinResult =
6
- & {
7
- id: UserRow['id']
8
- first_name: UserRow['first_name']
9
- last_name: UserRow['last_name']
10
- third_name: UserRow['third_name']
11
- phone: UserRow['phone']
12
- email: UserRow['email']
13
- }
14
- & {
15
- image_id: ImageMediaRow['id']
16
- }
17
- & {
18
- role_id: string
19
- role_name: string
20
- }
21
-
22
- /**
23
- * City
24
- */
25
-
26
- type CityResult = CityRow
27
-
28
- type CityPublicResult = {
29
- address: CityRow['address']
30
- alias: CityRow['alias']
31
- country: CityRow['country']
32
- custom_html: CityRow['custom_html']
33
- custom_script: CityRow['custom_script']
34
- email: CityRow['email']
35
- id: CityRow['id']
36
- inst_link: CityRow['inst_link']
37
- max_members_count: CityRow['max_members_count']
38
- meta_description: CityRow['meta_description']
39
- meta_title: CityRow['meta_title']
40
- min_members_count: CityRow['min_members_count']
41
- name: CityRow['name']
42
- phone: CityRow['phone']
43
- tg_link: CityRow['tg_link']
44
- vk_group_id: CityRow['vk_group_id']
45
- vk_link: CityRow['vk_link']
46
- yandex_metrica: CityRow['yandex_metrica']
47
- }
48
-
49
- /**
50
- * Theme
51
- */
52
-
53
- type ThemeResult = {
54
- id: ThemeRow['id']
55
- time_created: ThemeRow['time_created']
56
- name: ThemeRow['name']
57
- description: ThemeRow['description']
58
- short_description: ThemeRow['short_description']
59
- image_id: ImageMediaRow['id']
60
- media_title: MediaRow['title']
61
- media_path: MediaRow['path']
62
- }
63
-
64
- /**
65
- * Game
66
- */
67
-
68
- type GameResult =
69
- & {
70
- event_id: GameRow['id']
71
- event_alias: GameRow['alias']
72
- event_number: GameRow['number']
73
- event_time: GameRow['event_time']
74
- event_status: GameRow['status']
75
- }
76
- & {
77
- location_id: LocationRow['id']
78
- location_name: LocationRow['name']
79
- }
80
- & {
81
- city_id: CityRow['id']
82
- city_alias: CityRow['alias']
83
- city_name: CityRow['name']
84
- city_is_franchise: CityRow['is_franchise']
85
- }
86
- & {
87
- theme_id: ThemeRow['id']
88
- theme_name: ThemeRow['name']
89
- }
90
- & {
91
- media_id: ImageMediaRow['id']
92
- media_title: ImageMediaRow['title']
93
- media_path: ImageMediaRow['path']
94
- }
95
- & {
96
- people_amount: number
97
- people_reserve_amount: number
98
- teams_amount: number
99
- teams_reserve_amount: number
100
- }
101
-
102
- type GamePublicResult =
103
- & {
104
- theme_description: ThemeRow['description']
105
- theme_id: ThemeRow['id']
106
- theme_name: ThemeRow['name']
107
- theme_short_description: ThemeRow['short_description']
108
- }
109
- & {
110
- alias: GameRow['alias']
111
- currency: GameRow['currency']
112
- id: GameRow['id']
113
- max_members_count: GameRow['max_members_count']
114
- min_members_count: GameRow['min_members_count']
115
- number: GameRow['number']
116
- price: GameRow['price']
117
- status: GameRow['status']
118
- event_time: GameRow['event_time']
119
- }
120
- & {
121
- city_alias: CityRow['alias']
122
- city_id: CityRow['id']
123
- }
124
- & {
125
- location_house_number: LocationRow['house_number']
126
- location_id: LocationRow['id']
127
- location_info: LocationRow['location_info']
128
- location_name: LocationRow['name']
129
- location_street: LocationRow['street']
130
- }
131
- & {
132
- media_id: MediaRow['id']
133
- media_path: MediaRow['path']
134
- }
135
- & {
136
- image_id: ImageMediaRow['id']
137
- }