@shakerquiz/utilities 0.2.14 → 0.2.15

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.14",
3
+ "version": "0.2.15",
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
- // export let Features: {
7
- // Checkin: 'Checkin'
7
+ export let Features: {
8
+ Checkin: 'Checkin'
8
9
 
9
- // User: 'User'
10
- // Users: 'Users'
10
+ User: 'User'
11
+ Users: 'Users'
11
12
 
12
- // Theme: 'Theme'
13
- // Themes: 'Themes'
13
+ Theme: 'Theme'
14
+ Themes: 'Themes'
14
15
 
15
- // Game: 'Game'
16
- // Games: 'Games'
16
+ Game: 'Game'
17
+ Games: 'Games'
17
18
 
18
- // Registration: 'Registration'
19
- // Registrations: 'Registrations'
19
+ Registration: 'Registration'
20
+ Registrations: 'Registrations'
20
21
 
21
- // City: 'City'
22
- // Cities: 'Cities'
22
+ City: 'City'
23
+ Cities: 'Cities'
23
24
 
24
- // CityPublic: 'CityPublic'
25
- // CitiesPublic: 'CitiesPublic'
25
+ Location: 'Location'
26
+ Locations: 'Locations'
27
+ }
26
28
 
27
- // Location: 'Location'
28
- // Locations: 'Locations'
29
- // }
29
+ export let FeatureKinds: {
30
+ [Features.Checkin]: Kinds.Item
30
31
 
31
- // export let FeatureKinds: {
32
- // [Features.Checkin]: Kinds.Item
32
+ [Features.User]: Kinds.Item
33
+ [Features.Users]: Kinds.List
33
34
 
34
- // [Features.User]: Kinds.Item
35
- // [Features.Users]: Kinds.List
35
+ [Features.Theme]: Kinds.Item
36
+ [Features.Themes]: Kinds.List
36
37
 
37
- // [Features.Theme]: Kinds.Item
38
- // [Features.Themes]: Kinds.List
38
+ [Features.Game]: Kinds.Item
39
+ [Features.Games]: Kinds.List
39
40
 
40
- // [Features.Game]: Kinds.Item
41
- // [Features.Games]: Kinds.List
41
+ [Features.Registration]: Kinds.Item
42
+ [Features.Registrations]: Kinds.List
42
43
 
43
- // [Features.Registration]: Kinds.Item
44
- // [Features.Registrations]: Kinds.List
44
+ [Features.City]: Kinds.Item
45
+ [Features.Cities]: Kinds.List
45
46
 
46
- // [Features.City]: Kinds.Item
47
- // [Features.Cities]: Kinds.List
47
+ [Features.Location]: Kinds.Item
48
+ [Features.Locations]: Kinds.List
49
+ }
48
50
 
49
- // [Features.CityPublic]: Kinds.Item
50
- // [Features.CitiesPublic]: Kinds.List
51
+ export let FeatureServices: {
52
+ [Features.Checkin]: Services.Users
51
53
 
52
- // [Features.Location]: Kinds.Item
53
- // [Features.Locations]: Kinds.List
54
- // }
54
+ [Features.User]: Services.Users
55
+ [Features.Users]: Services.Users
55
56
 
56
- export let FeatureUrls: Map<
57
- keyof typeof Features,
58
- Map<keyof typeof Networks, (options: URLOptions) => URL>
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,3 +1,4 @@
1
+ import { Services } from 'source/enumerations/services.js'
1
2
  import { Kinds } from './kinds.js'
2
3
 
3
4
  export let Features = /** @type {const} */ ({
@@ -44,4 +45,26 @@ export let FeatureKinds = {
44
45
  [Features.Locations]: Kinds.List,
45
46
  }
46
47
 
47
- export let FeatureUrls = new Map()
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()
@@ -1,6 +1,6 @@
1
1
  import { Features } from './features.d.ts'
2
2
 
3
- export let Patterns: {
3
+ export let FeaturePatterns: {
4
4
  /**
5
5
  * Users
6
6
  */
@@ -1,6 +1,6 @@
1
1
  import { Features } from './features.js'
2
2
 
3
- export let Patterns = {
3
+ export let FeaturePatterns = {
4
4
  /**
5
5
  * Users
6
6
  */
@@ -0,0 +1,5 @@
1
+ export let Services: {
2
+ Games: 'Games'
3
+ Locations: 'Locations'
4
+ Users: 'Users'
5
+ }
@@ -0,0 +1,5 @@
1
+ export let Services = /** @type {const} */ ({
2
+ Games: 'Games',
3
+ Locations: 'Locations',
4
+ Users: 'Users',
5
+ })
@@ -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 { FeatureKinds, FeatureUrls } from '../enumerations/features.js'
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 = FeatureUrls
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(options), init)
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('shaker-quiz-token', init.cookie),
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
- !FeatureUrls
97
- .has(feature)
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
- !FeatureUrls
103
- .get(feature)
104
- .has(network)
105
- )
106
- throw TypeError(`Network '${network}' must be listed in 'FeatureUrls'.`)
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
@@ -9,4 +9,5 @@ export * from './enumerations/patterns.js'
9
9
  export * from './enumerations/phases.js'
10
10
  export * from './enumerations/regexps.js'
11
11
  export * from './enumerations/roles.js'
12
+ export * from './enumerations/services.js'
12
13
  export * from './functions/request.js'