@shakerquiz/utilities 0.2.14 → 0.2.16
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 +4 -1
- package/source/enumerations/features.d.ts +59 -39
- package/source/enumerations/features.js +24 -1
- package/source/enumerations/patterns.d.ts +1 -1
- package/source/enumerations/patterns.js +1 -1
- package/source/enumerations/services.d.ts +5 -0
- package/source/enumerations/services.js +5 -0
- package/source/functions/request.js +36 -16
- package/source/index.d.ts +1 -0
- package/source/index.js +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shakerquiz/utilities",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.16",
|
|
4
4
|
"author": "yurkimus <yurkimus@gmail.com>",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"exports": {
|
|
@@ -16,5 +16,8 @@
|
|
|
16
16
|
"@yurkimus/message": "0.0.14",
|
|
17
17
|
"@yurkimus/response-status": "0.1.1",
|
|
18
18
|
"@yurkimus/url": "0.2.8"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"urlpattern-polyfill": "10.0.0"
|
|
19
22
|
}
|
|
20
23
|
}
|
|
@@ -1,61 +1,81 @@
|
|
|
1
1
|
import { URLOptions } from '@yurkimus/url'
|
|
2
2
|
|
|
3
|
-
import { Kinds } from './kinds'
|
|
4
|
-
import { Networks } from './networks'
|
|
3
|
+
import { Kinds } from './kinds.d.ts'
|
|
4
|
+
import { Networks } from './networks.d.ts'
|
|
5
|
+
import { Services } from './services.d.ts'
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
export let Features: {
|
|
8
|
+
Checkin: 'Checkin'
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
User: 'User'
|
|
11
|
+
Users: 'Users'
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
Theme: 'Theme'
|
|
14
|
+
Themes: 'Themes'
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
Game: 'Game'
|
|
17
|
+
Games: 'Games'
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
Registration: 'Registration'
|
|
20
|
+
Registrations: 'Registrations'
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
City: 'City'
|
|
23
|
+
Cities: 'Cities'
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
Location: 'Location'
|
|
26
|
+
Locations: 'Locations'
|
|
27
|
+
}
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// }
|
|
29
|
+
export let FeatureKinds: {
|
|
30
|
+
[Features.Checkin]: Kinds.Item
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
[Features.User]: Kinds.Item
|
|
33
|
+
[Features.Users]: Kinds.List
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
[Features.Theme]: Kinds.Item
|
|
36
|
+
[Features.Themes]: Kinds.List
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
[Features.Game]: Kinds.Item
|
|
39
|
+
[Features.Games]: Kinds.List
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
[Features.Registration]: Kinds.Item
|
|
42
|
+
[Features.Registrations]: Kinds.List
|
|
42
43
|
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
[Features.City]: Kinds.Item
|
|
45
|
+
[Features.Cities]: Kinds.List
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
[Features.Location]: Kinds.Item
|
|
48
|
+
[Features.Locations]: Kinds.List
|
|
49
|
+
}
|
|
48
50
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
export let FeatureServices: {
|
|
52
|
+
[Features.Checkin]: Services.Users
|
|
51
53
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
// }
|
|
54
|
+
[Features.User]: Services.Users
|
|
55
|
+
[Features.Users]: Services.Users
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
[Features.Theme]: Services.Games
|
|
58
|
+
[Features.Themes]: Services.Games
|
|
59
|
+
|
|
60
|
+
[Features.Game]: Services.Games
|
|
61
|
+
[Features.Games]: Services.Games
|
|
62
|
+
|
|
63
|
+
[Features.Registration]: Services.Games
|
|
64
|
+
[Features.Registrations]: Services.Games
|
|
65
|
+
|
|
66
|
+
[Features.City]: Services.Locations
|
|
67
|
+
[Features.Cities]: Services.Locations
|
|
68
|
+
|
|
69
|
+
[Features.Location]: Services.Locations
|
|
70
|
+
[Features.Locations]: Services.Locations
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export let FeatureOrigins: Map<
|
|
74
|
+
keyof typeof Services,
|
|
75
|
+
Map<
|
|
76
|
+
keyof typeof Networks,
|
|
77
|
+
(pathname: string, options: URLOptions) => URL
|
|
78
|
+
>
|
|
59
79
|
>
|
|
60
80
|
|
|
61
81
|
type Features = typeof Features
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Kinds } from './kinds.js'
|
|
2
|
+
import { Services } from './services.js'
|
|
2
3
|
|
|
3
4
|
export let Features = /** @type {const} */ ({
|
|
4
5
|
Checkin: 'Checkin',
|
|
@@ -44,4 +45,26 @@ export let FeatureKinds = {
|
|
|
44
45
|
[Features.Locations]: Kinds.List,
|
|
45
46
|
}
|
|
46
47
|
|
|
47
|
-
export let
|
|
48
|
+
export let FeatureServices = {
|
|
49
|
+
[Features.Checkin]: Services.Users,
|
|
50
|
+
|
|
51
|
+
[Features.User]: Services.Users,
|
|
52
|
+
[Features.Users]: Services.Users,
|
|
53
|
+
|
|
54
|
+
[Features.Theme]: Services.Games,
|
|
55
|
+
[Features.Themes]: Services.Games,
|
|
56
|
+
|
|
57
|
+
[Features.Game]: Services.Games,
|
|
58
|
+
[Features.Games]: Services.Games,
|
|
59
|
+
|
|
60
|
+
[Features.Registration]: Services.Games,
|
|
61
|
+
[Features.Registrations]: Services.Games,
|
|
62
|
+
|
|
63
|
+
[Features.City]: Services.Locations,
|
|
64
|
+
[Features.Cities]: Services.Locations,
|
|
65
|
+
|
|
66
|
+
[Features.Location]: Services.Locations,
|
|
67
|
+
[Features.Locations]: Services.Locations,
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export let FeatureOrigins = new Map()
|
|
@@ -3,8 +3,14 @@ import { MessageError } from '@yurkimus/errors'
|
|
|
3
3
|
import * as message from '@yurkimus/message'
|
|
4
4
|
import { ResponseStatus } from '@yurkimus/response-status'
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { Cookies } from '../enumerations/cookies.js'
|
|
7
|
+
import {
|
|
8
|
+
FeatureKinds,
|
|
9
|
+
FeatureOrigins,
|
|
10
|
+
FeatureServices,
|
|
11
|
+
} from '../enumerations/features.js'
|
|
7
12
|
import { Kinds } from '../enumerations/kinds.js'
|
|
13
|
+
import { FeaturePatterns } from '../enumerations/patterns.js'
|
|
8
14
|
|
|
9
15
|
let handleMessage = (feature, [response, body]) => {
|
|
10
16
|
switch (response.status) {
|
|
@@ -54,11 +60,16 @@ let makeRequest = (feature, method, network, options, init) => {
|
|
|
54
60
|
if (!('method' in init))
|
|
55
61
|
init.method = method
|
|
56
62
|
|
|
57
|
-
let url =
|
|
58
|
-
.get(feature)
|
|
63
|
+
let url = FeatureOrigins
|
|
64
|
+
.get(FeatureServices[feature])
|
|
59
65
|
.get(network)
|
|
66
|
+
.call(
|
|
67
|
+
undefined,
|
|
68
|
+
FeaturePatterns[feature].pathname,
|
|
69
|
+
options,
|
|
70
|
+
)
|
|
60
71
|
|
|
61
|
-
let request = new Request(url
|
|
72
|
+
let request = new Request(url, init)
|
|
62
73
|
|
|
63
74
|
if (!request.headers.has('Content-Type'))
|
|
64
75
|
request.headers.set(
|
|
@@ -69,7 +80,7 @@ let makeRequest = (feature, method, network, options, init) => {
|
|
|
69
80
|
if ('cookie' in init)
|
|
70
81
|
request.headers.set(
|
|
71
82
|
'Authorization',
|
|
72
|
-
cookies.read(
|
|
83
|
+
cookies.read(Cookies.Token, init.cookie),
|
|
73
84
|
)
|
|
74
85
|
|
|
75
86
|
return fetch(request)
|
|
@@ -92,18 +103,27 @@ export let Extensions = new WeakMap()
|
|
|
92
103
|
* @param {Network} network
|
|
93
104
|
*/
|
|
94
105
|
export let useRequest = (feature, method, network) => {
|
|
95
|
-
if (
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
throw TypeError(`Feature '${feature}' must be listed in 'FeatureUrls'.`)
|
|
106
|
+
if (!(feature in FeatureServices))
|
|
107
|
+
throw TypeError(
|
|
108
|
+
`Feature '${feature}' must be listed in 'FeatureServices'.`,
|
|
109
|
+
)
|
|
100
110
|
|
|
101
|
-
if (
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
111
|
+
if (!(feature in FeaturePatterns))
|
|
112
|
+
throw TypeError(
|
|
113
|
+
`Feature '${feature}' must be listed in 'FeaturePatterns'.`,
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
if (!FeatureOrigins.has(FeatureServices[feature]))
|
|
117
|
+
throw TypeError(
|
|
118
|
+
`Service '${
|
|
119
|
+
FeatureServices[feature]
|
|
120
|
+
}' must be listed in 'FeatureOrigins'.`,
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
if (!FeatureOrigins.get(FeatureServices[feature]).has(network))
|
|
124
|
+
throw TypeError(
|
|
125
|
+
`Network '${network}' must be listed in '${FeatureServices[feature]}'.`,
|
|
126
|
+
)
|
|
107
127
|
|
|
108
128
|
/**
|
|
109
129
|
* @param {import('@yurkimus/url').URLOptions} options
|
package/source/index.d.ts
CHANGED
|
@@ -18,5 +18,6 @@ export * from './enumerations/patterns.js'
|
|
|
18
18
|
export * from './enumerations/phases.js'
|
|
19
19
|
export * from './enumerations/regexps.js'
|
|
20
20
|
export * from './enumerations/roles.js'
|
|
21
|
+
export * from './enumerations/services.js'
|
|
21
22
|
|
|
22
23
|
export * from './functions/request.js'
|
package/source/index.js
CHANGED