@shakerquiz/utilities 0.4.1 → 0.4.2

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,10 +1,10 @@
1
1
  {
2
2
  "name": "@shakerquiz/utilities",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "author": "yurkimus <yurkimus@gmail.com>",
5
5
  "license": "ISC",
6
6
  "scripts": {
7
- "type": "tsc --emitdeclarationonly --declaration --allowjs"
7
+ "type": "tsc --emitdeclarationonly --declaration --allowjs ./source/**/*"
8
8
  },
9
9
  "exports": {
10
10
  ".": {
@@ -1,3 +1,21 @@
1
+ export const Domains: readonly ["Asset", "User", "Role", "City", "Venue", "Theme", "ThemeAsset", "Game", "GameAsset", "Registration", "Mailing"];
2
+ /**
3
+ * @type {Record<Domain, Icon>}
4
+ */
5
+ export const DomainIcon: Record<Domain, Icon>;
6
+ /**
7
+ * @type {Record<Domain, Record<Kind, string>>}
8
+ */
9
+ export const DomainKindPathname: Record<Domain, Record<Kind, string>>;
10
+ export const Procedures: readonly ["Checkin", "Redirect"];
11
+ /**
12
+ * @type {Record<Procedure, Icon>}
13
+ */
14
+ export const ProcedureIcon: Record<Procedure, Icon>;
15
+ /**
16
+ * @type {Record<Procedure, Record<Kind, string>>}
17
+ */
18
+ export const ProcedureKindPathname: Record<Procedure, Record<Kind, string>>;
1
19
  export const Features: ("Asset" | "User" | "Role" | "City" | "Venue" | "Theme" | "ThemeAsset" | "Game" | "GameAsset" | "Registration" | "Mailing")[];
2
20
  /**
3
21
  * @type {Record<Feature, Icon>}
@@ -7,7 +25,3 @@ export const FeatureIcon: Record<Feature, Icon>;
7
25
  * @type {Record<Feature, Record<Kind, string>>}
8
26
  */
9
27
  export const FeatureKindPathname: Record<Feature, Record<Kind, string>>;
10
- /**
11
- * @type {Record<Feature, Record<Method, Requirement>>}
12
- */
13
- export const FeatureMethodRequirements: Record<Feature, Record<Method, Requirement>>;
@@ -1,6 +1,103 @@
1
- import { DomainIcon, DomainKindPathname, DomainMethodRequirements, Domains } from './domains.js'
1
+ export var Domains = /** @type {const} */ ([
2
+ 'Asset',
3
+ 'User',
4
+ 'Role',
5
+ 'City',
6
+ 'Venue',
7
+ 'Theme',
8
+ 'ThemeAsset',
9
+ 'Game',
10
+ 'GameAsset',
11
+ 'Registration',
12
+ 'Mailing',
13
+ ])
2
14
 
3
- import { ProcedureIcon, ProcedureKindPathname, ProcedureMethodRequirements, Procedures } from './procedures.js'
15
+ /**
16
+ * @type {Record<Domain, Icon>}
17
+ */
18
+ export var DomainIcon = {
19
+ 'User': 'users',
20
+ 'Role': 'identification',
21
+ 'City': 'building-office',
22
+ 'Venue': 'map-pin',
23
+ 'Theme': 'document-text',
24
+ 'Game': 'newspaper',
25
+ 'Registration': 'user-group',
26
+ 'Mailing': 'envelope',
27
+ }
28
+
29
+ /**
30
+ * @type {Record<Domain, Record<Kind, string>>}
31
+ */
32
+ export var DomainKindPathname = {
33
+ 'User': {
34
+ 'Unit': '/user/:user?',
35
+ 'Set': '/users',
36
+ },
37
+
38
+ 'Role': {
39
+ 'Unit': '/role/:role?',
40
+ 'Set': '/roles',
41
+ },
42
+
43
+ 'City': {
44
+ 'Unit': '/city/:city?',
45
+ 'Set': '/cities',
46
+ },
47
+
48
+ 'Venue': {
49
+ 'Unit': '/venue/:venue?',
50
+ 'Set': '/venues',
51
+ },
52
+
53
+ 'Theme': {
54
+ 'Unit': '/theme/:theme?',
55
+ 'Set': '/themes',
56
+ },
57
+
58
+ 'Game': {
59
+ 'Unit': '/game/:game?',
60
+ 'Set': '/games',
61
+ },
62
+
63
+ 'Registration': {
64
+ 'Unit': '/registration/:registration?',
65
+ 'Set': '/registrations',
66
+ },
67
+
68
+ 'Mailing': {
69
+ 'Unit': '/mailing/:mailing?',
70
+ 'Set': '/mailings',
71
+ },
72
+ }
73
+
74
+ export var Procedures = /** @type {const} */ ([
75
+ 'Checkin',
76
+ 'Redirect',
77
+ ])
78
+
79
+ /**
80
+ * @type {Record<Procedure, Icon>}
81
+ */
82
+ export var ProcedureIcon = {
83
+ 'Checkin': 'arrow-right-end-on-rectangle',
84
+ 'Redirect': 'no-symbol',
85
+ }
86
+
87
+ /**
88
+ * @type {Record<Procedure, Record<Kind, string>>}
89
+ */
90
+ export var ProcedureKindPathname = {
91
+ 'Checkin': {
92
+ 'Unit': '/checkin',
93
+ 'Set': '/checkins',
94
+ },
95
+
96
+ 'Redirect': {
97
+ 'Unit': '/redirect',
98
+ 'Set': '/redirects',
99
+ },
100
+ }
4
101
 
5
102
  export var Features = Domains.concat(Procedures)
6
103
 
@@ -19,11 +116,3 @@ export var FeatureKindPathname = {
19
116
  ...DomainKindPathname,
20
117
  ...ProcedureKindPathname,
21
118
  }
22
-
23
- /**
24
- * @type {Record<Feature, Record<Method, Requirement>>}
25
- */
26
- export var FeatureMethodRequirements = {
27
- ...DomainMethodRequirements,
28
- ...ProcedureMethodRequirements,
29
- }
package/source/index.d.ts CHANGED
@@ -9,11 +9,9 @@
9
9
  /// <reference path='./user.d.ts' />
10
10
  /// <reference path='./venue.d.ts' />
11
11
 
12
- export * from './enumerations/core/domains.js'
13
12
  export * from './enumerations/core/features.js'
14
13
  export * from './enumerations/core/kinds.js'
15
14
  export * from './enumerations/core/methods.js'
16
- export * from './enumerations/core/procedures.js'
17
15
  export * from './enumerations/core/scopes.js'
18
16
 
19
17
  export * from './enumerations/misc/constants.js'
package/source/index.js CHANGED
@@ -9,11 +9,9 @@
9
9
  /// <reference path='./user.d.ts' />
10
10
  /// <reference path='./venue.d.ts' />
11
11
 
12
- export * from './enumerations/core/domains.js'
13
12
  export * from './enumerations/core/features.js'
14
13
  export * from './enumerations/core/kinds.js'
15
14
  export * from './enumerations/core/methods.js'
16
- export * from './enumerations/core/procedures.js'
17
15
  export * from './enumerations/core/scopes.js'
18
16
 
19
17
  export * from './enumerations/misc/constants.js'
@@ -1,13 +0,0 @@
1
- export const Domains: readonly ["Asset", "User", "Role", "City", "Venue", "Theme", "ThemeAsset", "Game", "GameAsset", "Registration", "Mailing"];
2
- /**
3
- * @type {Record<Domain, Icon>}
4
- */
5
- export const DomainIcon: Record<Domain, Icon>;
6
- /**
7
- * @type {Record<Domain, Record<Kind, string>>}
8
- */
9
- export const DomainKindPathname: Record<Domain, Record<Kind, string>>;
10
- /**
11
- * @type {Record<Domain, Record<Method, Set<Requirement>>>}
12
- */
13
- export const DomainMethodRequirements: Record<Domain, Record<Method, Set<Requirement>>>;
@@ -1,149 +0,0 @@
1
- export var Domains = /** @type {const} */ ([
2
- 'Asset',
3
- 'User',
4
- 'Role',
5
- 'City',
6
- 'Venue',
7
- 'Theme',
8
- 'ThemeAsset',
9
- 'Game',
10
- 'GameAsset',
11
- 'Registration',
12
- 'Mailing',
13
- ])
14
-
15
- /**
16
- * @type {Record<Domain, Icon>}
17
- */
18
- export var DomainIcon = {
19
- 'User': 'users',
20
- 'Role': 'identification',
21
- 'City': 'building-office',
22
- 'Venue': 'map-pin',
23
- 'Theme': 'document-text',
24
- 'Game': 'newspaper',
25
- 'Registration': 'user-group',
26
- 'Mailing': 'envelope',
27
- }
28
-
29
- /**
30
- * @type {Record<Domain, Record<Kind, string>>}
31
- */
32
- export var DomainKindPathname = {
33
- 'User': {
34
- 'Unit': '/user/:user?',
35
- 'Set': '/users',
36
- },
37
-
38
- 'Role': {
39
- 'Unit': '/role/:role?',
40
- 'Set': '/roles',
41
- },
42
-
43
- 'City': {
44
- 'Unit': '/city/:city?',
45
- 'Set': '/cities',
46
- },
47
-
48
- 'Venue': {
49
- 'Unit': '/venue/:venue?',
50
- 'Set': '/venues',
51
- },
52
-
53
- 'Theme': {
54
- 'Unit': '/theme/:theme?',
55
- 'Set': '/themes',
56
- },
57
-
58
- 'Game': {
59
- 'Unit': '/game/:game?',
60
- 'Set': '/games',
61
- },
62
-
63
- 'Registration': {
64
- 'Unit': '/registration/:registration?',
65
- 'Set': '/registrations',
66
- },
67
-
68
- 'Mailing': {
69
- 'Unit': '/mailing/:mailing?',
70
- 'Set': '/mailings',
71
- },
72
- }
73
-
74
- /**
75
- * @type {Record<Domain, Record<Method, Set<Requirement>>>}
76
- */
77
- export var DomainMethodRequirements = {
78
- 'User': {
79
- 'DELETE': new Set(['Checkin']),
80
- 'GET': new Set(['Checkin']),
81
- 'OPTIONS': new Set([]),
82
- 'PATCH': new Set(['Checkin', 'Body']),
83
- 'POST': new Set(['Checkin', 'Body']),
84
- 'PUT': new Set(['Checkin', 'Body']),
85
- },
86
-
87
- 'Role': {
88
- 'DELETE': new Set(['Checkin']),
89
- 'GET': new Set(['Checkin']),
90
- 'OPTIONS': new Set([]),
91
- 'PATCH': new Set(['Checkin', 'Body']),
92
- 'POST': new Set(['Checkin', 'Body']),
93
- 'PUT': new Set(['Checkin', 'Body']),
94
- },
95
-
96
- 'City': {
97
- 'DELETE': new Set(['Checkin']),
98
- 'GET': new Set(['Checkin']),
99
- 'OPTIONS': new Set([]),
100
- 'PATCH': new Set(['Checkin', 'Body']),
101
- 'POST': new Set(['Checkin', 'Body']),
102
- 'PUT': new Set(['Checkin', 'Body']),
103
- },
104
-
105
- 'Venue': {
106
- 'DELETE': new Set(['Checkin']),
107
- 'GET': new Set(['Checkin']),
108
- 'OPTIONS': new Set([]),
109
- 'PATCH': new Set(['Checkin', 'Body']),
110
- 'POST': new Set(['Checkin', 'Body']),
111
- 'PUT': new Set(['Checkin', 'Body']),
112
- },
113
-
114
- 'Theme': {
115
- 'DELETE': new Set(['Checkin']),
116
- 'GET': new Set(['Checkin']),
117
- 'OPTIONS': new Set([]),
118
- 'PATCH': new Set(['Checkin', 'Body']),
119
- 'POST': new Set(['Checkin', 'Body']),
120
- 'PUT': new Set(['Checkin', 'Body']),
121
- },
122
-
123
- 'Game': {
124
- 'DELETE': new Set(['Checkin']),
125
- 'GET': new Set(['Checkin']),
126
- 'OPTIONS': new Set([]),
127
- 'PATCH': new Set(['Checkin', 'Body']),
128
- 'POST': new Set(['Checkin', 'Body']),
129
- 'PUT': new Set(['Checkin', 'Body']),
130
- },
131
-
132
- 'Registration': {
133
- 'DELETE': new Set(['Checkin']),
134
- 'GET': new Set(['Checkin']),
135
- 'OPTIONS': new Set([]),
136
- 'PATCH': new Set(['Checkin', 'Body']),
137
- 'POST': new Set(['Checkin', 'Body']),
138
- 'PUT': new Set(['Checkin', 'Body']),
139
- },
140
-
141
- 'Mailing': {
142
- 'DELETE': new Set(['Checkin']),
143
- 'GET': new Set(['Checkin']),
144
- 'OPTIONS': new Set([]),
145
- 'PATCH': new Set(['Checkin', 'Body']),
146
- 'POST': new Set(['Checkin', 'Body']),
147
- 'PUT': new Set(['Checkin', 'Body']),
148
- },
149
- }
@@ -1,13 +0,0 @@
1
- export const Procedures: readonly ["Checkin", "Redirect"];
2
- /**
3
- * @type {Record<Procedure, Icon>}
4
- */
5
- export const ProcedureIcon: Record<Procedure, Icon>;
6
- /**
7
- * @type {Record<Procedure, Record<Kind, string>>}
8
- */
9
- export const ProcedureKindPathname: Record<Procedure, Record<Kind, string>>;
10
- /**
11
- * @type {Record<Procedure, Record<Method, Set<Requirement>>>}
12
- */
13
- export const ProcedureMethodRequirements: Record<Procedure, Record<Method, Set<Requirement>>>;
@@ -1,45 +0,0 @@
1
- export var Procedures = /** @type {const} */ ([
2
- 'Checkin',
3
- 'Redirect',
4
- ])
5
-
6
- /**
7
- * @type {Record<Procedure, Icon>}
8
- */
9
- export var ProcedureIcon = {
10
- 'Checkin': 'arrow-right-end-on-rectangle',
11
- 'Redirect': 'no-symbol',
12
- }
13
-
14
- /**
15
- * @type {Record<Procedure, Record<Kind, string>>}
16
- */
17
- export var ProcedureKindPathname = {
18
- 'Checkin': {
19
- 'Unit': '/checkin',
20
- 'Set': '/checkins',
21
- },
22
-
23
- 'Redirect': {
24
- 'Unit': '/redirect',
25
- 'Set': '/redirects',
26
- },
27
- }
28
-
29
- /**
30
- * @type {Record<Procedure, Record<Method, Set<Requirement>>>}
31
- */
32
- export var ProcedureMethodRequirements = {
33
- 'Checkin': {
34
- 'DELETE': new Set([]),
35
- 'GET': new Set([]),
36
- 'OPTIONS': new Set([]),
37
- 'PATCH': new Set([]),
38
- 'POST': new Set(['Body']),
39
- 'PUT': new Set([]),
40
- },
41
-
42
- 'Redirect': {
43
- 'GET': new Set([]),
44
- },
45
- }
@@ -1,3 +0,0 @@
1
- export function parseResponse(response: Response): any;
2
- export function resolveResponse(scope: Scope, [response, value]: [Response, any]): any;
3
- export function scopeRequest<R>(scope: Scope, input: RequestInfo, init: RequestInit): Promise<R>;
@@ -1,81 +0,0 @@
1
- import { Methods } from '../enumerations/core/methods.js'
2
- import { Scopes } from '../enumerations/core/scopes.js'
3
-
4
- /**
5
- * @param {Response} response
6
- */
7
- export var parseResponse = response => {
8
- let mime = response.headers.get('Content-Type') ?? ''
9
-
10
- if (mime.includes('application/json'))
11
- return Promise.all([
12
- response,
13
- response.json(),
14
- ])
15
- else if (mime.includes('multipart/form-data'))
16
- return Promise.all([
17
- response,
18
- response.formData(),
19
- ])
20
- else
21
- return Promise.all([
22
- response,
23
- response.text(),
24
- ])
25
- }
26
-
27
- /**
28
- * @param {Scope} scope
29
- * @param {[Response, any]} param1
30
- */
31
- export var resolveResponse = (scope, [response, value]) => {
32
- let [method, feature, kind] = scope.split('/')
33
-
34
- if (response.ok) {
35
- switch (response.status) {
36
- case 204:
37
- switch (kind) {
38
- case 'Unit':
39
- return null
40
-
41
- case 'Set':
42
- return []
43
- }
44
-
45
- default:
46
- return value
47
- }
48
- } else
49
- throw value
50
- }
51
-
52
- /**
53
- * @template R
54
- *
55
- * @param {Scope} scope
56
- * @param {RequestInfo} input
57
- * @param {RequestInit} init
58
- *
59
- * @returns {Promise<R>}
60
- */
61
- export var scopeRequest = (scope, input, init) => {
62
- if (!Scopes.includes(scope))
63
- throw TypeError(
64
- `Parameter 'scope' must be listed in 'Scopes'.`,
65
- )
66
-
67
- let [method, feature, kind] = scope.split('/')
68
-
69
- if (!('method' in init))
70
- init.method = method
71
-
72
- if (!Methods.includes(init.method))
73
- throw TypeError(
74
- `[featureFetch] Method '${init.method}' is not listed in 'Methods'.`,
75
- )
76
-
77
- return globalThis
78
- .fetch(input, init)
79
- .then(parseResponse)
80
- .then(resolveResponse.bind(null, scope))
81
- }