@shakerquiz/utilities 0.2.48 → 0.3.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.
- package/package.json +1 -1
- package/source/enumerations/features.js +384 -228
- package/source/enumerations/networks.js +0 -1
- package/source/enumerations/services.js +6 -6
- package/source/functions/fetch.js +38 -18
- package/source/functions/origin.js +26 -26
- package/source/globals.d.ts +641 -565
- package/source/enumerations/constants.d.ts +0 -3
- package/source/enumerations/cookies.d.ts +0 -5
- package/source/enumerations/features.d.ts +0 -382
- package/source/enumerations/game-statuses.d.ts +0 -17
- package/source/enumerations/kinds.d.ts +0 -4
- package/source/enumerations/networks.d.ts +0 -5
- package/source/enumerations/phases.d.ts +0 -7
- package/source/enumerations/regexps.d.ts +0 -5
- package/source/enumerations/request-methods.d.ts +0 -18
- package/source/enumerations/requirements.d.ts +0 -4
- package/source/enumerations/roles.d.ts +0 -6
- package/source/enumerations/services.d.ts +0 -8
- package/source/functions/fetch.d.ts +0 -16
- package/source/functions/origin.d.ts +0 -1
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
export var Services = /** @type {const} */ ({
|
|
2
|
+
/**
|
|
3
|
+
* @description Frontend-service representing tools for managing and creating content.
|
|
4
|
+
*/
|
|
5
|
+
Admin: 'Admin',
|
|
2
6
|
/**
|
|
3
7
|
* @description Backend-service manipulating Theme, Game and Registration.
|
|
4
8
|
*/
|
|
@@ -12,15 +16,11 @@ export var Services = /** @type {const} */ ({
|
|
|
12
16
|
*/
|
|
13
17
|
Locations: 'Locations',
|
|
14
18
|
/**
|
|
15
|
-
* @description Frontend-service representing
|
|
19
|
+
* @description Frontend-service representing integration with vk.com.
|
|
16
20
|
*/
|
|
17
|
-
|
|
21
|
+
MiniApp: 'MiniApp',
|
|
18
22
|
/**
|
|
19
23
|
* @description Backend-service manipulating Checkin and User.
|
|
20
24
|
*/
|
|
21
25
|
Users: 'Users',
|
|
22
|
-
/**
|
|
23
|
-
* @description Frontend-service representing integration with vk.com.
|
|
24
|
-
*/
|
|
25
|
-
MiniApp: 'MiniApp',
|
|
26
26
|
})
|
|
@@ -6,14 +6,15 @@ import { ResponseStatus } from '@yurkimus/response-status'
|
|
|
6
6
|
import { Cookies } from '../enumerations/cookies.js'
|
|
7
7
|
import {
|
|
8
8
|
FeatureKinds,
|
|
9
|
-
FeatureNetworkUrls,
|
|
10
9
|
FeaturePathnames,
|
|
11
10
|
Features,
|
|
11
|
+
ServiceFeatureNetworkURLs,
|
|
12
|
+
ServiceFeatures,
|
|
12
13
|
} from '../enumerations/features.js'
|
|
13
14
|
import { Kinds } from '../enumerations/kinds.js'
|
|
14
15
|
import { Networks } from '../enumerations/networks.js'
|
|
15
16
|
import { RequestMethods } from '../enumerations/request-methods.js'
|
|
16
|
-
import {
|
|
17
|
+
import { Services } from '../enumerations/services.js'
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* @typedef {'onbefore' | 'onfulfilled' | 'onrejected'} ExtensionHooks
|
|
@@ -52,27 +53,45 @@ var handleMessage = (feature, [response, body]) => {
|
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
/**
|
|
55
|
-
* @template {
|
|
56
|
-
* @template {
|
|
56
|
+
* @template {Service} S
|
|
57
|
+
* @template {typeof import('../enumerations/features.js').ServiceFeatures[S][number]} F
|
|
58
|
+
* @template {Network} N
|
|
57
59
|
*
|
|
58
|
-
* @param {
|
|
59
|
-
* @param {
|
|
60
|
+
* @param {S} service
|
|
61
|
+
* @param {F} feature
|
|
62
|
+
* @param {N} network
|
|
60
63
|
*/
|
|
61
|
-
export var useFetch = (feature, network) =>
|
|
64
|
+
export var useFetch = (service, feature, network) =>
|
|
62
65
|
/**
|
|
63
|
-
* @template {
|
|
66
|
+
* @template {RequestMethod} [M='GET']
|
|
67
|
+
* @template {Role} [R='default']
|
|
64
68
|
*
|
|
65
69
|
* @param {import('@yurkimus/url').URLOptions | undefined} options
|
|
66
70
|
* @param {RequestInit} init
|
|
67
71
|
*
|
|
68
|
-
* @returns {Promise<FetchResults[
|
|
72
|
+
* @returns {Promise<FetchResults[S][F][M][R]>}
|
|
69
73
|
*/
|
|
70
74
|
function fetcher(options, init) {
|
|
75
|
+
if (!(service in Services))
|
|
76
|
+
throw TypeError(
|
|
77
|
+
`Feature '${service}' must be listed in 'Features'.`,
|
|
78
|
+
)
|
|
79
|
+
|
|
71
80
|
if (!(feature in Features))
|
|
72
81
|
throw TypeError(
|
|
73
82
|
`Feature '${feature}' must be listed in 'Features'.`,
|
|
74
83
|
)
|
|
75
84
|
|
|
85
|
+
if (!(feature in FeaturePathnames))
|
|
86
|
+
throw TypeError(
|
|
87
|
+
`Feature '${feature}' must be listed in 'FeaturePathnames'.`,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
if (!(feature in ServiceFeatures[service]))
|
|
91
|
+
throw TypeError(
|
|
92
|
+
`Feature '${feature}' must be listed in 'ServiceFeatures'.`,
|
|
93
|
+
)
|
|
94
|
+
|
|
76
95
|
if (!(init.method in RequestMethods))
|
|
77
96
|
throw TypeError(
|
|
78
97
|
`Method '${init.method}' must be listed in 'RequestMethods'.`,
|
|
@@ -83,24 +102,24 @@ export var useFetch = (feature, network) =>
|
|
|
83
102
|
`Network '${network}' must be listed in 'Networks'.`,
|
|
84
103
|
)
|
|
85
104
|
|
|
86
|
-
if (!(
|
|
105
|
+
if (!ServiceFeatureNetworkURLs.has(service))
|
|
87
106
|
throw TypeError(
|
|
88
|
-
`
|
|
107
|
+
`Service '${service}' must be listed in 'ServiceFeatureNetworkURLs'.`,
|
|
89
108
|
)
|
|
90
109
|
|
|
91
|
-
if (!
|
|
110
|
+
if (!ServiceFeatureNetworkURLs.get(service).has(feature))
|
|
92
111
|
throw TypeError(
|
|
93
|
-
`Feature '${feature}' must be listed in '
|
|
112
|
+
`Feature '${feature}' must be listed in 'ServiceFeatureNetworkURLs[service]'.`,
|
|
94
113
|
)
|
|
95
114
|
|
|
96
|
-
if (!
|
|
115
|
+
if (!ServiceFeatureNetworkURLs.get(service).get(feature).has(network))
|
|
97
116
|
throw TypeError(
|
|
98
|
-
`
|
|
117
|
+
`Network '${network}' must be listed in 'ServiceFeatureNetworkURLs[service][feature]'.`,
|
|
99
118
|
)
|
|
100
119
|
|
|
101
|
-
if (!
|
|
120
|
+
if (!ServiceFeatureNetworkURLs.get(service).get(feature).get(network))
|
|
102
121
|
throw TypeError(
|
|
103
|
-
`
|
|
122
|
+
`Network '${network}' of 'ServiceFeatureNetworkURLs[service][feature]' must have a value.`,
|
|
104
123
|
)
|
|
105
124
|
|
|
106
125
|
extensions.set(
|
|
@@ -112,7 +131,8 @@ export var useFetch = (feature, network) =>
|
|
|
112
131
|
]),
|
|
113
132
|
)
|
|
114
133
|
|
|
115
|
-
var url =
|
|
134
|
+
var url = ServiceFeatureNetworkURLs
|
|
135
|
+
.get(service)
|
|
116
136
|
.get(feature)
|
|
117
137
|
.get(network)
|
|
118
138
|
.call(undefined, options)
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { url } from '@yurkimus/url'
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
FeatureNetworkOrigins,
|
|
5
|
-
FeatureNetworkUrls,
|
|
6
4
|
FeaturePathnames,
|
|
7
5
|
Features,
|
|
6
|
+
ServiceFeatureNetworkURLs,
|
|
8
7
|
ServiceFeatures,
|
|
8
|
+
ServiceNetworkOrigins,
|
|
9
9
|
} from '../enumerations/features.js'
|
|
10
10
|
import { Networks } from '../enumerations/networks.js'
|
|
11
11
|
import { Services } from '../enumerations/services.js'
|
|
@@ -15,40 +15,40 @@ import { Services } from '../enumerations/services.js'
|
|
|
15
15
|
*
|
|
16
16
|
* @returns {void}
|
|
17
17
|
*/
|
|
18
|
-
export var
|
|
19
|
-
for (
|
|
18
|
+
export var setServiceNetworkOrigins = origins => {
|
|
19
|
+
for (var service in origins) {
|
|
20
20
|
if (!(service in Services))
|
|
21
21
|
throw TypeError(
|
|
22
22
|
`Service '${service}' must be listed in 'Services'.`,
|
|
23
23
|
)
|
|
24
24
|
|
|
25
|
-
for (
|
|
26
|
-
if (!(
|
|
25
|
+
for (var network in origins[service]) {
|
|
26
|
+
if (!(network in Networks))
|
|
27
27
|
throw TypeError(
|
|
28
|
-
`
|
|
28
|
+
`Network '${network}' must be listed in 'Networks'.`,
|
|
29
29
|
)
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
for (let network in origins[service]) {
|
|
37
|
-
if (!(network in Networks))
|
|
38
|
-
throw TypeError(
|
|
39
|
-
`Network '${network}' must be listed in 'Networks'.`,
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
var origin = origins[service][network]
|
|
43
|
-
var pathname = FeaturePathnames[feature]
|
|
44
|
-
|
|
45
|
-
FeatureNetworkOrigins
|
|
46
|
-
.get(feature)
|
|
31
|
+
for (var origin in origins[service][network]) {
|
|
32
|
+
ServiceNetworkOrigins
|
|
33
|
+
.get(service)
|
|
47
34
|
.set(network, origin)
|
|
48
35
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
36
|
+
for (var feature in ServiceFeatures[service]) {
|
|
37
|
+
if (!(feature in Features))
|
|
38
|
+
throw TypeError(
|
|
39
|
+
`Feature '${feature}' must be listed in 'Features'.`,
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
if (!(feature in FeaturePathnames))
|
|
43
|
+
throw TypeError(
|
|
44
|
+
`Feature '${feature}' must be listed in 'FeaturePathnames'.`,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
ServiceFeatureNetworkURLs
|
|
48
|
+
.get(service)
|
|
49
|
+
.get(feature)
|
|
50
|
+
.set(network, url.bind(undefined, origin, pathname))
|
|
51
|
+
}
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
}
|