@shakerquiz/utilities 0.2.27 → 0.2.29

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shakerquiz/utilities",
3
- "version": "0.2.27",
3
+ "version": "0.2.29",
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.3",
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",
@@ -1,5 +1,5 @@
1
- export var Cookies = {
1
+ export var Cookies = /** @type {const} */ ({
2
2
  Token: 'shaker-quiz-token',
3
3
  Refresh: 'shaker-quiz-refresh-token',
4
4
  Role: 'shaker-quiz-user-role',
5
- }
5
+ })
@@ -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,44 @@ 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
+
39
+ export var ServiceFeatures = {
40
+ [Services.Games]: [
41
+ Features.Game,
42
+ Features.Games,
43
+ Features.Theme,
44
+ Features.Themes,
45
+ Features.Registration,
46
+ Features.Registrations,
47
+ ],
48
+ [Services.Locations]: [
49
+ Features.Cities,
50
+ Features.City,
51
+ Features.Location,
52
+ Features.Locations,
53
+ ],
54
+ [Services.Users]: [
55
+ Features.Checkin,
56
+ Features.User,
57
+ Features.Users,
58
+ ],
59
+ }
60
+
22
61
  export var FeatureKinds = {
23
62
  [Features.Checkin]: Kinds.Item,
24
63
  [Features.Cities]: Kinds.List,
@@ -93,62 +132,7 @@ export var FeaturePatterns = {
93
132
  }),
94
133
  }
95
134
 
96
- export var FeatureNetworkOrigins = /** @type {const} */ ({
97
- [Features.Checkin]: {
98
- [Networks.Private]: 'http://users:8000/',
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 = {
135
+ export var FeatureMethodRequirements = {
152
136
  [Features.Checkin]: {
153
137
  [Methods.DELETE]: new Set([]),
154
138
  [Methods.GET]: new Set([]),
@@ -254,3 +238,110 @@ export var FeatureRequirements = {
254
238
  [Methods.PUT]: new Set([Requirements.Checkin, Requirements.Body]),
255
239
  },
256
240
  }
241
+
242
+ export var FeatureNetworkOrigins = new Map([
243
+ [
244
+ Features.Checkin,
245
+ new Map([
246
+ [Networks.Docker, ''],
247
+ [Networks.Local, ''],
248
+ [Networks.Public, ''],
249
+ ]),
250
+ ],
251
+ [
252
+ Features.Cities,
253
+ new Map([
254
+ [Networks.Docker, ''],
255
+ [Networks.Local, ''],
256
+ [Networks.Public, ''],
257
+ ]),
258
+ ],
259
+ [
260
+ Features.City,
261
+ new Map([
262
+ [Networks.Docker, ''],
263
+ [Networks.Local, ''],
264
+ [Networks.Public, ''],
265
+ ]),
266
+ ],
267
+ [
268
+ Features.Game,
269
+ new Map([
270
+ [Networks.Docker, ''],
271
+ [Networks.Local, ''],
272
+ [Networks.Public, ''],
273
+ ]),
274
+ ],
275
+ [
276
+ Features.Games,
277
+ new Map([
278
+ [Networks.Docker, ''],
279
+ [Networks.Local, ''],
280
+ [Networks.Public, ''],
281
+ ]),
282
+ ],
283
+ [
284
+ Features.Location,
285
+ new Map([
286
+ [Networks.Docker, ''],
287
+ [Networks.Local, ''],
288
+ [Networks.Public, ''],
289
+ ]),
290
+ ],
291
+ [
292
+ Features.Locations,
293
+ new Map([
294
+ [Networks.Docker, ''],
295
+ [Networks.Local, ''],
296
+ [Networks.Public, ''],
297
+ ]),
298
+ ],
299
+ [
300
+ Features.Registration,
301
+ new Map([
302
+ [Networks.Docker, ''],
303
+ [Networks.Local, ''],
304
+ [Networks.Public, ''],
305
+ ]),
306
+ ],
307
+ [
308
+ Features.Registrations,
309
+ new Map([
310
+ [Networks.Docker, ''],
311
+ [Networks.Local, ''],
312
+ [Networks.Public, ''],
313
+ ]),
314
+ ],
315
+ [
316
+ Features.Theme,
317
+ new Map([
318
+ [Networks.Docker, ''],
319
+ [Networks.Local, ''],
320
+ [Networks.Public, ''],
321
+ ]),
322
+ ],
323
+ [
324
+ Features.Themes,
325
+ new Map([
326
+ [Networks.Docker, ''],
327
+ [Networks.Local, ''],
328
+ [Networks.Public, ''],
329
+ ]),
330
+ ],
331
+ [
332
+ Features.User,
333
+ new Map([
334
+ [Networks.Docker, ''],
335
+ [Networks.Local, ''],
336
+ [Networks.Public, ''],
337
+ ]),
338
+ ],
339
+ [
340
+ Features.Users,
341
+ new Map([
342
+ [Networks.Docker, ''],
343
+ [Networks.Local, ''],
344
+ [Networks.Public, ''],
345
+ ]),
346
+ ],
347
+ ])
@@ -1,4 +1,5 @@
1
1
  export var Networks = /** @type {const} */ ({
2
- Private: 'Private',
2
+ Docker: 'Private',
3
+ Local: 'Local',
3
4
  Public: 'Public',
4
5
  })
@@ -1,7 +1,7 @@
1
- export let Phases = {
1
+ export var Phases = /** @type {const} */ ({
2
2
  Aborted: 'Aborted',
3
3
  Failed: 'Failed',
4
4
  Idle: 'Idle',
5
5
  Loaded: 'Loaded',
6
6
  Loading: 'Loading',
7
- }
7
+ })
@@ -1,4 +1,4 @@
1
- export let RegExps = {
1
+ export var RegExps = {
2
2
  Uuid: /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/,
3
3
  ElementId:
4
4
  /\d+:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}:\d+/,
@@ -0,0 +1,5 @@
1
+ export var Services = /** @type {const} */ ({
2
+ Games: 'Games',
3
+ Locations: 'Locations',
4
+ Users: 'Users',
5
+ })
@@ -56,7 +56,7 @@ let request = (feature, method, network, options, init) => {
56
56
 
57
57
  let instance = new Request(
58
58
  url(
59
- FeatureNetworkOrigins[feature][network],
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 in FeatureNetworkOrigins))
116
+ if (!FeatureNetworkOrigins.has(feature))
117
117
  throw TypeError(
118
118
  `Feature '${feature}' must be listed in 'FeatureNetworkOrigins'.`,
119
119
  )
120
120
 
121
- if (!(network in FeatureNetworkOrigins[feature]))
121
+ if (!FeatureNetworkOrigins.get(feature).has(network))
122
122
  throw TypeError(
123
- `Network '${
124
- FeatureNetworkOrigins[feature]
125
- }' must be listed in 'FeatureNetworkOrigins[feature]'.`,
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
+ }
package/source/index.js CHANGED
@@ -9,5 +9,7 @@ export * from './enumerations/phases.js'
9
9
  export * from './enumerations/regexps.js'
10
10
  export * from './enumerations/requirements.js'
11
11
  export * from './enumerations/roles.js'
12
+ export * from './enumerations/services.js'
12
13
 
13
14
  export * from './functions/fetch.js'
15
+ export * from './functions/origins.js'