@shakerquiz/utilities 0.2.26 → 0.2.28
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.
- package/package.json +2 -2
- package/source/enumerations/cookies.js +2 -2
- package/source/enumerations/features.js +129 -60
- package/source/enumerations/networks.js +2 -1
- package/source/enumerations/phases.js +2 -2
- package/source/enumerations/regexps.js +1 -1
- package/source/enumerations/services.js +29 -0
- package/source/functions/fetch.js +9 -6
- package/source/functions/origins.js +39 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shakerquiz/utilities",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.28",
|
|
4
4
|
"author": "yurkimus <yurkimus@gmail.com>",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"exports": {
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@yurkimus/cookies": "0.0.8",
|
|
15
|
-
"@yurkimus/errors": "0.1.
|
|
15
|
+
"@yurkimus/errors": "0.1.4",
|
|
16
16
|
"@yurkimus/message": "0.0.14",
|
|
17
17
|
"@yurkimus/response-status": "0.1.1",
|
|
18
18
|
"@yurkimus/url": "0.2.8",
|
|
@@ -2,6 +2,7 @@ import { Kinds } from './kinds.js'
|
|
|
2
2
|
import { Methods } from './methods.js'
|
|
3
3
|
import { Networks } from './networks.js'
|
|
4
4
|
import { Requirements } from './requirements.js'
|
|
5
|
+
import { Services } from './services.js'
|
|
5
6
|
|
|
6
7
|
export var Features = /** @type {const} */ ({
|
|
7
8
|
Checkin: 'Checkin',
|
|
@@ -19,6 +20,22 @@ export var Features = /** @type {const} */ ({
|
|
|
19
20
|
Users: 'Users',
|
|
20
21
|
})
|
|
21
22
|
|
|
23
|
+
export var FeatureServices = {
|
|
24
|
+
[Features.Game]: Services.Games,
|
|
25
|
+
[Features.Games]: Services.Games,
|
|
26
|
+
[Features.Theme]: Services.Games,
|
|
27
|
+
[Features.Themes]: Services.Games,
|
|
28
|
+
[Features.Registration]: Services.Games,
|
|
29
|
+
[Features.Registrations]: Services.Games,
|
|
30
|
+
[Features.Cities]: Services.Locations,
|
|
31
|
+
[Features.City]: Services.Locations,
|
|
32
|
+
[Features.Location]: Services.Locations,
|
|
33
|
+
[Features.Locations]: Services.Locations,
|
|
34
|
+
[Features.Checkin]: Services.Users,
|
|
35
|
+
[Features.User]: Services.Users,
|
|
36
|
+
[Features.Users]: Services.Users,
|
|
37
|
+
}
|
|
38
|
+
|
|
22
39
|
export var FeatureKinds = {
|
|
23
40
|
[Features.Checkin]: Kinds.Item,
|
|
24
41
|
[Features.Cities]: Kinds.List,
|
|
@@ -93,69 +110,14 @@ export var FeaturePatterns = {
|
|
|
93
110
|
}),
|
|
94
111
|
}
|
|
95
112
|
|
|
96
|
-
export var
|
|
113
|
+
export var FeatureMethodRequirements = {
|
|
97
114
|
[Features.Checkin]: {
|
|
98
|
-
[
|
|
99
|
-
[Networks.Public]: 'https://users.backend.shakerquiz.ru/',
|
|
100
|
-
},
|
|
101
|
-
[Features.Cities]: {
|
|
102
|
-
[Networks.Private]: 'http://locations:8000/',
|
|
103
|
-
[Networks.Public]: 'https://locations.backend.shakerquiz.ru/',
|
|
104
|
-
},
|
|
105
|
-
[Features.City]: {
|
|
106
|
-
[Networks.Private]: 'http://locations:8000/',
|
|
107
|
-
[Networks.Public]: 'https://locations.backend.shakerquiz.ru/',
|
|
108
|
-
},
|
|
109
|
-
[Features.Game]: {
|
|
110
|
-
[Networks.Private]: 'http://games:8000/',
|
|
111
|
-
[Networks.Public]: 'https://games.backend.shakerquiz.ru/',
|
|
112
|
-
},
|
|
113
|
-
[Features.Games]: {
|
|
114
|
-
[Networks.Private]: 'http://games:8000/',
|
|
115
|
-
[Networks.Public]: 'https://games.backend.shakerquiz.ru/',
|
|
116
|
-
},
|
|
117
|
-
[Features.Location]: {
|
|
118
|
-
[Networks.Private]: 'http://locations:8000/',
|
|
119
|
-
[Networks.Public]: 'https://locations.backend.shakerquiz.ru/',
|
|
120
|
-
},
|
|
121
|
-
[Features.Locations]: {
|
|
122
|
-
[Networks.Private]: 'http://locations:8000/',
|
|
123
|
-
[Networks.Public]: 'https://locations.backend.shakerquiz.ru/',
|
|
124
|
-
},
|
|
125
|
-
[Features.Registration]: {
|
|
126
|
-
[Networks.Private]: 'http://games:8000/',
|
|
127
|
-
[Networks.Public]: 'https://games.backend.shakerquiz.ru/',
|
|
128
|
-
},
|
|
129
|
-
[Features.Registrations]: {
|
|
130
|
-
[Networks.Private]: 'http://games:8000/',
|
|
131
|
-
[Networks.Public]: 'https://games.backend.shakerquiz.ru/',
|
|
132
|
-
},
|
|
133
|
-
[Features.Theme]: {
|
|
134
|
-
[Networks.Private]: 'http://games:8000/',
|
|
135
|
-
[Networks.Public]: 'https://games.backend.shakerquiz.ru/',
|
|
136
|
-
},
|
|
137
|
-
[Features.Themes]: {
|
|
138
|
-
[Networks.Private]: 'http://games:8000/',
|
|
139
|
-
[Networks.Public]: 'https://games.backend.shakerquiz.ru/',
|
|
140
|
-
},
|
|
141
|
-
[Features.User]: {
|
|
142
|
-
[Networks.Private]: 'http://users:8000/',
|
|
143
|
-
[Networks.Public]: 'https://users.backend.shakerquiz.ru/',
|
|
144
|
-
},
|
|
145
|
-
[Features.Users]: {
|
|
146
|
-
[Networks.Private]: 'http://users:8000/',
|
|
147
|
-
[Networks.Public]: 'https://users.backend.shakerquiz.ru/',
|
|
148
|
-
},
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
export var FeatureRequirements = {
|
|
152
|
-
[Features.Checkin]: {
|
|
153
|
-
[Methods.DELETE]: new Set([Requirements.Checkin]),
|
|
115
|
+
[Methods.DELETE]: new Set([]),
|
|
154
116
|
[Methods.GET]: new Set([]),
|
|
155
117
|
[Methods.OPTIONS]: new Set([]),
|
|
156
|
-
[Methods.PATCH]: new Set([
|
|
157
|
-
[Methods.POST]: new Set([Requirements.
|
|
158
|
-
[Methods.PUT]: new Set([
|
|
118
|
+
[Methods.PATCH]: new Set([]),
|
|
119
|
+
[Methods.POST]: new Set([Requirements.Body]),
|
|
120
|
+
[Methods.PUT]: new Set([]),
|
|
159
121
|
},
|
|
160
122
|
[Features.Cities]: {
|
|
161
123
|
[Methods.DELETE]: new Set([Requirements.Checkin]),
|
|
@@ -254,3 +216,110 @@ export var FeatureRequirements = {
|
|
|
254
216
|
[Methods.PUT]: new Set([Requirements.Checkin, Requirements.Body]),
|
|
255
217
|
},
|
|
256
218
|
}
|
|
219
|
+
|
|
220
|
+
export var FeatureNetworkOrigins = new Map([
|
|
221
|
+
[
|
|
222
|
+
Features.Checkin,
|
|
223
|
+
new Map([
|
|
224
|
+
[Networks.Docker, ''],
|
|
225
|
+
[Networks.Local, ''],
|
|
226
|
+
[Networks.Public, ''],
|
|
227
|
+
]),
|
|
228
|
+
],
|
|
229
|
+
[
|
|
230
|
+
Features.Cities,
|
|
231
|
+
new Map([
|
|
232
|
+
[Networks.Docker, ''],
|
|
233
|
+
[Networks.Local, ''],
|
|
234
|
+
[Networks.Public, ''],
|
|
235
|
+
]),
|
|
236
|
+
],
|
|
237
|
+
[
|
|
238
|
+
Features.City,
|
|
239
|
+
new Map([
|
|
240
|
+
[Networks.Docker, ''],
|
|
241
|
+
[Networks.Local, ''],
|
|
242
|
+
[Networks.Public, ''],
|
|
243
|
+
]),
|
|
244
|
+
],
|
|
245
|
+
[
|
|
246
|
+
Features.Game,
|
|
247
|
+
new Map([
|
|
248
|
+
[Networks.Docker, ''],
|
|
249
|
+
[Networks.Local, ''],
|
|
250
|
+
[Networks.Public, ''],
|
|
251
|
+
]),
|
|
252
|
+
],
|
|
253
|
+
[
|
|
254
|
+
Features.Games,
|
|
255
|
+
new Map([
|
|
256
|
+
[Networks.Docker, ''],
|
|
257
|
+
[Networks.Local, ''],
|
|
258
|
+
[Networks.Public, ''],
|
|
259
|
+
]),
|
|
260
|
+
],
|
|
261
|
+
[
|
|
262
|
+
Features.Location,
|
|
263
|
+
new Map([
|
|
264
|
+
[Networks.Docker, ''],
|
|
265
|
+
[Networks.Local, ''],
|
|
266
|
+
[Networks.Public, ''],
|
|
267
|
+
]),
|
|
268
|
+
],
|
|
269
|
+
[
|
|
270
|
+
Features.Locations,
|
|
271
|
+
new Map([
|
|
272
|
+
[Networks.Docker, ''],
|
|
273
|
+
[Networks.Local, ''],
|
|
274
|
+
[Networks.Public, ''],
|
|
275
|
+
]),
|
|
276
|
+
],
|
|
277
|
+
[
|
|
278
|
+
Features.Registration,
|
|
279
|
+
new Map([
|
|
280
|
+
[Networks.Docker, ''],
|
|
281
|
+
[Networks.Local, ''],
|
|
282
|
+
[Networks.Public, ''],
|
|
283
|
+
]),
|
|
284
|
+
],
|
|
285
|
+
[
|
|
286
|
+
Features.Registrations,
|
|
287
|
+
new Map([
|
|
288
|
+
[Networks.Docker, ''],
|
|
289
|
+
[Networks.Local, ''],
|
|
290
|
+
[Networks.Public, ''],
|
|
291
|
+
]),
|
|
292
|
+
],
|
|
293
|
+
[
|
|
294
|
+
Features.Theme,
|
|
295
|
+
new Map([
|
|
296
|
+
[Networks.Docker, ''],
|
|
297
|
+
[Networks.Local, ''],
|
|
298
|
+
[Networks.Public, ''],
|
|
299
|
+
]),
|
|
300
|
+
],
|
|
301
|
+
[
|
|
302
|
+
Features.Themes,
|
|
303
|
+
new Map([
|
|
304
|
+
[Networks.Docker, ''],
|
|
305
|
+
[Networks.Local, ''],
|
|
306
|
+
[Networks.Public, ''],
|
|
307
|
+
]),
|
|
308
|
+
],
|
|
309
|
+
[
|
|
310
|
+
Features.User,
|
|
311
|
+
new Map([
|
|
312
|
+
[Networks.Docker, ''],
|
|
313
|
+
[Networks.Local, ''],
|
|
314
|
+
[Networks.Public, ''],
|
|
315
|
+
]),
|
|
316
|
+
],
|
|
317
|
+
[
|
|
318
|
+
Features.Users,
|
|
319
|
+
new Map([
|
|
320
|
+
[Networks.Docker, ''],
|
|
321
|
+
[Networks.Local, ''],
|
|
322
|
+
[Networks.Public, ''],
|
|
323
|
+
]),
|
|
324
|
+
],
|
|
325
|
+
])
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Features } from './features.js'
|
|
2
|
+
|
|
3
|
+
export var Services = /** @type {const} */ ({
|
|
4
|
+
Games: 'Games',
|
|
5
|
+
Locations: 'Locations',
|
|
6
|
+
Users: 'Users',
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
export var ServiceFeatures = {
|
|
10
|
+
[Services.Games]: [
|
|
11
|
+
Features.Game,
|
|
12
|
+
Features.Games,
|
|
13
|
+
Features.Theme,
|
|
14
|
+
Features.Themes,
|
|
15
|
+
Features.Registration,
|
|
16
|
+
Features.Registrations,
|
|
17
|
+
],
|
|
18
|
+
[Services.Locations]: [
|
|
19
|
+
Features.Cities,
|
|
20
|
+
Features.City,
|
|
21
|
+
Features.Location,
|
|
22
|
+
Features.Locations,
|
|
23
|
+
],
|
|
24
|
+
[Services.Users]: [
|
|
25
|
+
Features.Checkin,
|
|
26
|
+
Features.User,
|
|
27
|
+
Features.Users,
|
|
28
|
+
],
|
|
29
|
+
}
|
|
@@ -56,7 +56,7 @@ let request = (feature, method, network, options, init) => {
|
|
|
56
56
|
|
|
57
57
|
let instance = new Request(
|
|
58
58
|
url(
|
|
59
|
-
FeatureNetworkOrigins
|
|
59
|
+
FeatureNetworkOrigins.get(feature).get(network),
|
|
60
60
|
FeaturePathnames[feature],
|
|
61
61
|
options,
|
|
62
62
|
),
|
|
@@ -113,16 +113,19 @@ export let useFetch = (feature, method, network) => {
|
|
|
113
113
|
`Feature '${feature}' must be listed in 'FeaturePathnames'.`,
|
|
114
114
|
)
|
|
115
115
|
|
|
116
|
-
if (!(feature
|
|
116
|
+
if (!FeatureNetworkOrigins.has(feature))
|
|
117
117
|
throw TypeError(
|
|
118
118
|
`Feature '${feature}' must be listed in 'FeatureNetworkOrigins'.`,
|
|
119
119
|
)
|
|
120
120
|
|
|
121
|
-
if (!(
|
|
121
|
+
if (!FeatureNetworkOrigins.get(feature).has(network))
|
|
122
122
|
throw TypeError(
|
|
123
|
-
`Network '${
|
|
124
|
-
|
|
125
|
-
|
|
123
|
+
`Feature Network '${feature}' '${network}' must be listed in 'FeatureNetworkOrigins'.`,
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
if (!URL.canParse(FeatureNetworkOrigins.get(feature).get(network)))
|
|
127
|
+
throw TypeError(
|
|
128
|
+
`Value of 'FeatureNetworkOrigins' '${feature}' '${network}' cannot be parsed as URL.`,
|
|
126
129
|
)
|
|
127
130
|
|
|
128
131
|
/**
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { FeatureNetworkOrigins, Features } from '../enumerations/features.js'
|
|
2
|
+
import { Networks } from '../enumerations/networks.js'
|
|
3
|
+
import { ServiceFeatures, Services } from '../enumerations/services.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {Record<
|
|
7
|
+
* keyof typeof Services,
|
|
8
|
+
* Record<keyof typeof Networks, URL['origin']>
|
|
9
|
+
* >} origins
|
|
10
|
+
*
|
|
11
|
+
* @returns {void}
|
|
12
|
+
*/
|
|
13
|
+
export var setFeatureNetworkOrigins = origins => {
|
|
14
|
+
for (let service in origins) {
|
|
15
|
+
if (!(service in Services))
|
|
16
|
+
throw TypeError(
|
|
17
|
+
`Service '${service}' must be listed in 'Services'.`,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
for (let feature of ServiceFeatures[service]) {
|
|
21
|
+
if (!(feature in Features))
|
|
22
|
+
throw TypeError(
|
|
23
|
+
`Feature '${feature}' must be listed in 'Features'.`,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
for (let network in origins[service]) {
|
|
27
|
+
if (!(network in Networks))
|
|
28
|
+
throw TypeError(
|
|
29
|
+
`Network '${network}' must be listed in 'Networks'.`,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
return void FeatureNetworkOrigins
|
|
33
|
+
.get(feature)
|
|
34
|
+
.get(network)
|
|
35
|
+
.set(origins[service][network])
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|