@shakerquiz/utilities 4.0.1 → 4.0.3
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/.github/workflows/publish.yml +1 -1
- package/dprint.json +0 -3
- package/jsconfig.json +5 -8
- package/package.json +6 -2
- package/scripts/codegen.js +104 -0
- package/scripts/template.js +55 -0
- package/source/codegen/autogenerated.js +782 -0
- package/source/entities/key.js +6 -4
- package/source/entities/pattern.js +3 -3
- package/source/entities/{route.js → routes.js} +0 -7
- package/source/entities/runtimes.js +14 -0
- package/source/entities/segment.js +36 -4
- package/source/entities/service-runtime.js +2 -2
- package/source/entities/services.js +28 -0
- package/source/helpers/access.js +11 -13
- package/source/helpers/route-pathname.js +26 -0
- package/source/helpers/tag.js +32 -29
- package/source/index.js +5 -9
- package/scripts/route-cardinality.js +0 -23
- package/scripts/route-parameter.js +0 -29
- package/scripts/route-pathname.js +0 -37
- package/scripts/route-relation.js +0 -26
- package/scripts/route-service.js +0 -25
- package/scripts/templates/route-cardinality.js +0 -5
- package/scripts/templates/route-parameter.js +0 -5
- package/scripts/templates/route-pathname.js +0 -7
- package/scripts/templates/route-relation.js +0 -5
- package/scripts/templates/route-service.js +0 -7
- package/source/entities/route-cardinality.js +0 -151
- package/source/entities/route-parameter.js +0 -151
- package/source/entities/route-pathname.js +0 -226
- package/source/entities/route-relation.js +0 -151
- package/source/entities/route-service.js +0 -181
- package/source/entities/runtime.js +0 -6
- package/source/entities/service.js +0 -22
- package/source/helpers/hydrate-route-pathname.js +0 -29
package/source/entities/key.js
CHANGED
|
@@ -34,8 +34,10 @@ export const Keys = Object.freeze(
|
|
|
34
34
|
)
|
|
35
35
|
|
|
36
36
|
export const Key = Object.freeze(
|
|
37
|
-
/** @type {{ [x in typeof Keys[number]]: x }} */ (
|
|
38
|
-
(
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
/** @type {{ [x in typeof Keys[number]]: x }} */ (
|
|
38
|
+
Keys.reduce(
|
|
39
|
+
(o, x) => (o[x] = x, o),
|
|
40
|
+
{},
|
|
41
|
+
)
|
|
42
|
+
),
|
|
41
43
|
)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export const Pattern = Object.freeze({
|
|
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
|
JWT: /^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$/,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
COUNTRY_CODE: /[A-Z]{2}/,
|
|
5
|
+
CURRENCY_CODE: /[A-Z]{3}/,
|
|
6
|
+
TIMEZONE_NAME: /[A-Za-z]+\/(?:[A-Za-z]+(?:_[A-Za-z]+)?)+/,
|
|
7
7
|
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const Runtimes = Object.freeze(
|
|
2
|
+
/** @type {const} */ ([
|
|
3
|
+
'Bun',
|
|
4
|
+
'Deno',
|
|
5
|
+
'Node',
|
|
6
|
+
'Vite',
|
|
7
|
+
]),
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
export const Runtime = Object.freeze(
|
|
11
|
+
/** @type {{ [x in typeof Runtimes[number]]: x }} */ (
|
|
12
|
+
Runtimes.reduce((o, x) => (o[x] = x, o), {})
|
|
13
|
+
),
|
|
14
|
+
)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Key } from './key.js'
|
|
2
|
-
import {
|
|
2
|
+
import { Pattern } from './pattern.js'
|
|
3
|
+
import { Service } from './services.js'
|
|
3
4
|
|
|
4
5
|
export const Segments = Object.freeze(
|
|
5
6
|
/** @type {const} */ ([
|
|
@@ -9,6 +10,7 @@ export const Segments = Object.freeze(
|
|
|
9
10
|
cardinality: '1',
|
|
10
11
|
relation: undefined,
|
|
11
12
|
service: Service['Checkin'],
|
|
13
|
+
pattern: undefined,
|
|
12
14
|
}),
|
|
13
15
|
),
|
|
14
16
|
Object.freeze(
|
|
@@ -17,6 +19,7 @@ export const Segments = Object.freeze(
|
|
|
17
19
|
cardinality: '1',
|
|
18
20
|
relation: Key['users'],
|
|
19
21
|
service: Service['Users'],
|
|
22
|
+
pattern: Pattern.UUID.source,
|
|
20
23
|
}),
|
|
21
24
|
),
|
|
22
25
|
Object.freeze(
|
|
@@ -25,6 +28,7 @@ export const Segments = Object.freeze(
|
|
|
25
28
|
cardinality: 'n',
|
|
26
29
|
relation: Key['user'],
|
|
27
30
|
service: Service['Users'],
|
|
31
|
+
pattern: undefined,
|
|
28
32
|
}),
|
|
29
33
|
),
|
|
30
34
|
Object.freeze(
|
|
@@ -33,6 +37,7 @@ export const Segments = Object.freeze(
|
|
|
33
37
|
cardinality: '1',
|
|
34
38
|
relation: Key['roles'],
|
|
35
39
|
service: Service['Roles'],
|
|
40
|
+
pattern: Pattern.UUID.source,
|
|
36
41
|
}),
|
|
37
42
|
),
|
|
38
43
|
Object.freeze(
|
|
@@ -41,6 +46,7 @@ export const Segments = Object.freeze(
|
|
|
41
46
|
cardinality: 'n',
|
|
42
47
|
relation: Key['role'],
|
|
43
48
|
service: Service['Roles'],
|
|
49
|
+
pattern: undefined,
|
|
44
50
|
}),
|
|
45
51
|
),
|
|
46
52
|
Object.freeze(
|
|
@@ -49,6 +55,7 @@ export const Segments = Object.freeze(
|
|
|
49
55
|
cardinality: '1',
|
|
50
56
|
relation: Key['countries'],
|
|
51
57
|
service: Service['Locations'],
|
|
58
|
+
pattern: Pattern.COUNTRY_CODE.source,
|
|
52
59
|
}),
|
|
53
60
|
),
|
|
54
61
|
Object.freeze(
|
|
@@ -57,6 +64,7 @@ export const Segments = Object.freeze(
|
|
|
57
64
|
cardinality: 'n',
|
|
58
65
|
relation: Key['country'],
|
|
59
66
|
service: Service['Locations'],
|
|
67
|
+
pattern: undefined,
|
|
60
68
|
}),
|
|
61
69
|
),
|
|
62
70
|
Object.freeze(
|
|
@@ -65,6 +73,7 @@ export const Segments = Object.freeze(
|
|
|
65
73
|
cardinality: '1',
|
|
66
74
|
relation: Key['currencies'],
|
|
67
75
|
service: Service['Locations'],
|
|
76
|
+
pattern: Pattern.CURRENCY_CODE.source,
|
|
68
77
|
}),
|
|
69
78
|
),
|
|
70
79
|
Object.freeze(
|
|
@@ -73,6 +82,7 @@ export const Segments = Object.freeze(
|
|
|
73
82
|
cardinality: 'n',
|
|
74
83
|
relation: Key['currency'],
|
|
75
84
|
service: Service['Locations'],
|
|
85
|
+
pattern: undefined,
|
|
76
86
|
}),
|
|
77
87
|
),
|
|
78
88
|
Object.freeze(
|
|
@@ -81,6 +91,7 @@ export const Segments = Object.freeze(
|
|
|
81
91
|
cardinality: '1',
|
|
82
92
|
relation: Key['timezones'],
|
|
83
93
|
service: Service['Locations'],
|
|
94
|
+
pattern: Pattern.TIMEZONE_NAME.source,
|
|
84
95
|
}),
|
|
85
96
|
),
|
|
86
97
|
Object.freeze(
|
|
@@ -89,6 +100,7 @@ export const Segments = Object.freeze(
|
|
|
89
100
|
cardinality: 'n',
|
|
90
101
|
relation: Key['timezone'],
|
|
91
102
|
service: Service['Locations'],
|
|
103
|
+
pattern: undefined,
|
|
92
104
|
}),
|
|
93
105
|
),
|
|
94
106
|
Object.freeze(
|
|
@@ -97,6 +109,7 @@ export const Segments = Object.freeze(
|
|
|
97
109
|
cardinality: '1',
|
|
98
110
|
relation: Key['cities'],
|
|
99
111
|
service: Service['Cities'],
|
|
112
|
+
pattern: Pattern.UUID.source,
|
|
100
113
|
}),
|
|
101
114
|
),
|
|
102
115
|
Object.freeze(
|
|
@@ -105,6 +118,7 @@ export const Segments = Object.freeze(
|
|
|
105
118
|
cardinality: 'n',
|
|
106
119
|
relation: Key['city'],
|
|
107
120
|
service: Service['Cities'],
|
|
121
|
+
pattern: undefined,
|
|
108
122
|
}),
|
|
109
123
|
),
|
|
110
124
|
Object.freeze(
|
|
@@ -113,6 +127,7 @@ export const Segments = Object.freeze(
|
|
|
113
127
|
cardinality: '1',
|
|
114
128
|
relation: Key['venues'],
|
|
115
129
|
service: Service['Venues'],
|
|
130
|
+
pattern: Pattern.UUID.source,
|
|
116
131
|
}),
|
|
117
132
|
),
|
|
118
133
|
Object.freeze(
|
|
@@ -121,6 +136,7 @@ export const Segments = Object.freeze(
|
|
|
121
136
|
cardinality: 'n',
|
|
122
137
|
relation: Key['venue'],
|
|
123
138
|
service: Service['Venues'],
|
|
139
|
+
pattern: undefined,
|
|
124
140
|
}),
|
|
125
141
|
),
|
|
126
142
|
Object.freeze(
|
|
@@ -129,6 +145,7 @@ export const Segments = Object.freeze(
|
|
|
129
145
|
cardinality: '1',
|
|
130
146
|
relation: Key['themes'],
|
|
131
147
|
service: Service['Themes'],
|
|
148
|
+
pattern: Pattern.UUID.source,
|
|
132
149
|
}),
|
|
133
150
|
),
|
|
134
151
|
Object.freeze(
|
|
@@ -137,6 +154,7 @@ export const Segments = Object.freeze(
|
|
|
137
154
|
cardinality: 'n',
|
|
138
155
|
relation: Key['theme'],
|
|
139
156
|
service: Service['Themes'],
|
|
157
|
+
pattern: undefined,
|
|
140
158
|
}),
|
|
141
159
|
),
|
|
142
160
|
Object.freeze(
|
|
@@ -145,6 +163,7 @@ export const Segments = Object.freeze(
|
|
|
145
163
|
cardinality: '1',
|
|
146
164
|
relation: undefined,
|
|
147
165
|
service: undefined,
|
|
166
|
+
pattern: Pattern.UUID.source,
|
|
148
167
|
}),
|
|
149
168
|
),
|
|
150
169
|
Object.freeze(
|
|
@@ -153,6 +172,7 @@ export const Segments = Object.freeze(
|
|
|
153
172
|
cardinality: '1',
|
|
154
173
|
relation: Key['games'],
|
|
155
174
|
service: Service['Games'],
|
|
175
|
+
pattern: Pattern.UUID.source,
|
|
156
176
|
}),
|
|
157
177
|
),
|
|
158
178
|
Object.freeze(
|
|
@@ -161,6 +181,7 @@ export const Segments = Object.freeze(
|
|
|
161
181
|
cardinality: 'n',
|
|
162
182
|
relation: Key['game'],
|
|
163
183
|
service: Service['Games'],
|
|
184
|
+
pattern: undefined,
|
|
164
185
|
}),
|
|
165
186
|
),
|
|
166
187
|
Object.freeze(
|
|
@@ -169,6 +190,7 @@ export const Segments = Object.freeze(
|
|
|
169
190
|
cardinality: '1',
|
|
170
191
|
relation: Key['registrations'],
|
|
171
192
|
service: Service['Registrations'],
|
|
193
|
+
pattern: Pattern.UUID.source,
|
|
172
194
|
}),
|
|
173
195
|
),
|
|
174
196
|
Object.freeze(
|
|
@@ -177,6 +199,7 @@ export const Segments = Object.freeze(
|
|
|
177
199
|
cardinality: 'n',
|
|
178
200
|
relation: Key['registration'],
|
|
179
201
|
service: Service['Registrations'],
|
|
202
|
+
pattern: undefined,
|
|
180
203
|
}),
|
|
181
204
|
),
|
|
182
205
|
Object.freeze(
|
|
@@ -185,6 +208,7 @@ export const Segments = Object.freeze(
|
|
|
185
208
|
cardinality: '1',
|
|
186
209
|
relation: undefined,
|
|
187
210
|
service: undefined,
|
|
211
|
+
pattern: undefined,
|
|
188
212
|
}),
|
|
189
213
|
),
|
|
190
214
|
Object.freeze(
|
|
@@ -193,6 +217,7 @@ export const Segments = Object.freeze(
|
|
|
193
217
|
cardinality: '1',
|
|
194
218
|
relation: undefined,
|
|
195
219
|
service: undefined,
|
|
220
|
+
pattern: undefined,
|
|
196
221
|
}),
|
|
197
222
|
),
|
|
198
223
|
Object.freeze(
|
|
@@ -201,6 +226,7 @@ export const Segments = Object.freeze(
|
|
|
201
226
|
cardinality: '1',
|
|
202
227
|
relation: undefined,
|
|
203
228
|
service: undefined,
|
|
229
|
+
pattern: undefined,
|
|
204
230
|
}),
|
|
205
231
|
),
|
|
206
232
|
Object.freeze(
|
|
@@ -209,6 +235,7 @@ export const Segments = Object.freeze(
|
|
|
209
235
|
cardinality: '1',
|
|
210
236
|
relation: undefined,
|
|
211
237
|
service: undefined,
|
|
238
|
+
pattern: undefined,
|
|
212
239
|
}),
|
|
213
240
|
),
|
|
214
241
|
Object.freeze(
|
|
@@ -217,6 +244,7 @@ export const Segments = Object.freeze(
|
|
|
217
244
|
cardinality: '1',
|
|
218
245
|
relation: undefined,
|
|
219
246
|
service: undefined,
|
|
247
|
+
pattern: undefined,
|
|
220
248
|
}),
|
|
221
249
|
),
|
|
222
250
|
Object.freeze(
|
|
@@ -225,6 +253,7 @@ export const Segments = Object.freeze(
|
|
|
225
253
|
cardinality: '1',
|
|
226
254
|
relation: undefined,
|
|
227
255
|
service: undefined,
|
|
256
|
+
pattern: undefined,
|
|
228
257
|
}),
|
|
229
258
|
),
|
|
230
259
|
Object.freeze(
|
|
@@ -233,6 +262,7 @@ export const Segments = Object.freeze(
|
|
|
233
262
|
cardinality: '1',
|
|
234
263
|
relation: undefined,
|
|
235
264
|
service: undefined,
|
|
265
|
+
pattern: undefined,
|
|
236
266
|
}),
|
|
237
267
|
),
|
|
238
268
|
Object.freeze(
|
|
@@ -241,15 +271,17 @@ export const Segments = Object.freeze(
|
|
|
241
271
|
cardinality: '1',
|
|
242
272
|
relation: undefined,
|
|
243
273
|
service: undefined,
|
|
274
|
+
pattern: undefined,
|
|
244
275
|
}),
|
|
245
276
|
),
|
|
246
277
|
]),
|
|
247
278
|
)
|
|
248
279
|
|
|
249
280
|
export const Segment = Object.freeze(
|
|
250
|
-
/** @type {{ [x in typeof Segments[number]['key']]: Extract<typeof Segments[number], { key: x }> }} */ (
|
|
251
|
-
.reduce(
|
|
281
|
+
/** @type {{ [x in typeof Segments[number]['key']]: Extract<typeof Segments[number], { key: x }> }} */ (
|
|
282
|
+
Segments.reduce(
|
|
252
283
|
(o, x) => (o[x.key] = x, o),
|
|
253
284
|
{},
|
|
254
|
-
)
|
|
285
|
+
)
|
|
286
|
+
),
|
|
255
287
|
)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export const Services = Object.freeze(
|
|
2
|
+
/** @type {const} */ ([
|
|
3
|
+
'Users',
|
|
4
|
+
'Roles',
|
|
5
|
+
'Checkin',
|
|
6
|
+
'Locations',
|
|
7
|
+
'Cities',
|
|
8
|
+
'Venues',
|
|
9
|
+
'Themes',
|
|
10
|
+
'Games',
|
|
11
|
+
'Registrations',
|
|
12
|
+
'Files',
|
|
13
|
+
'Procedures',
|
|
14
|
+
'Integrations',
|
|
15
|
+
'Updates',
|
|
16
|
+
'Hub',
|
|
17
|
+
'Landing',
|
|
18
|
+
'Telegram',
|
|
19
|
+
'Vkma',
|
|
20
|
+
'Minio',
|
|
21
|
+
]),
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
export const Service = Object.freeze(
|
|
25
|
+
/** @type {{ [x in typeof Services[number]]: x }} */ (
|
|
26
|
+
Services.reduce((o, x) => (o[x] = x, o), {})
|
|
27
|
+
),
|
|
28
|
+
)
|
package/source/helpers/access.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ParameterPattern, PathnameParameters, Route, RouteCardinality, RoutePathname, RouteService, ServiceRoutes } from '../codegen/autogenerated.js'
|
|
1
2
|
import { Blend } from '../entities/blend.js'
|
|
2
3
|
import { Cardinality } from '../entities/cardinality.js'
|
|
3
4
|
import { Category } from '../entities/category.js'
|
|
@@ -20,14 +21,9 @@ import { RegistrationLineup } from '../entities/registration-lineup.js'
|
|
|
20
21
|
import { RegistrationMailing } from '../entities/registration-mailing.js'
|
|
21
22
|
import { RegistrationStatus } from '../entities/registration-status.js'
|
|
22
23
|
import { Role } from '../entities/role.js'
|
|
23
|
-
import {
|
|
24
|
-
import { RouteParameter } from '../entities/route-parameter.js'
|
|
25
|
-
import { RoutePathname } from '../entities/route-pathname.js'
|
|
26
|
-
import { RouteService, ServiceRoutes } from '../entities/route-service.js'
|
|
27
|
-
import { Route } from '../entities/route.js'
|
|
28
|
-
import { Runtime } from '../entities/runtime.js'
|
|
24
|
+
import { Runtime } from '../entities/runtimes.js'
|
|
29
25
|
import { ServiceRuntime } from '../entities/service-runtime.js'
|
|
30
|
-
import { Service } from '../entities/
|
|
26
|
+
import { Service } from '../entities/services.js'
|
|
31
27
|
import { ThemeStatus } from '../entities/theme-status.js'
|
|
32
28
|
import { VenueAudience } from '../entities/venue-audience.js'
|
|
33
29
|
import { VenueStatus } from '../entities/venue-status.js'
|
|
@@ -61,6 +57,8 @@ const Prop = new Map([
|
|
|
61
57
|
[Mode, 'mode'],
|
|
62
58
|
[Network, 'network'],
|
|
63
59
|
[Numerosity, 'numerosity'],
|
|
60
|
+
[ParameterPattern, 'pattern'],
|
|
61
|
+
[PathnameParameters, 'parameters'],
|
|
64
62
|
[Pattern, 'pattern'],
|
|
65
63
|
[Phase, 'phase'],
|
|
66
64
|
[Quantifier, 'quantifier'],
|
|
@@ -69,15 +67,14 @@ const Prop = new Map([
|
|
|
69
67
|
[RegistrationMailing, 'mailing'],
|
|
70
68
|
[RegistrationStatus, 'status'],
|
|
71
69
|
[Role, 'name'],
|
|
70
|
+
[Route, 'route'],
|
|
72
71
|
[RouteCardinality, 'cardinality'],
|
|
73
|
-
[RouteParameter, 'parameter'],
|
|
74
72
|
[RoutePathname, 'pathname'],
|
|
75
73
|
[RouteService, 'service'],
|
|
76
|
-
[Route, 'route'],
|
|
77
74
|
[Runtime, 'runtime'],
|
|
75
|
+
[Service, 'service'],
|
|
78
76
|
[ServiceRoutes, 'routes'],
|
|
79
77
|
[ServiceRuntime, 'runtime'],
|
|
80
|
-
[Service, 'service'],
|
|
81
78
|
[ThemeStatus, 'status'],
|
|
82
79
|
[VenueAudience, 'audience'],
|
|
83
80
|
[VenueStatus, 'status'],
|
|
@@ -98,6 +95,8 @@ const Tag = new Map([
|
|
|
98
95
|
[Mode, 'Mode'],
|
|
99
96
|
[Network, 'Network'],
|
|
100
97
|
[Numerosity, 'Numerosity'],
|
|
98
|
+
[ParameterPattern, 'ParameterPattern'],
|
|
99
|
+
[PathnameParameters, 'PathnameParameters'],
|
|
101
100
|
[Pattern, 'Pattern'],
|
|
102
101
|
[Phase, 'Phase'],
|
|
103
102
|
[Quantifier, 'Quantifier'],
|
|
@@ -106,14 +105,13 @@ const Tag = new Map([
|
|
|
106
105
|
[RegistrationMailing, 'RegistrationMailing'],
|
|
107
106
|
[RegistrationStatus, 'RegistrationStatus'],
|
|
108
107
|
[Role, 'Role'],
|
|
108
|
+
[Route, 'Route'],
|
|
109
109
|
[RouteCardinality, 'RouteCardinality'],
|
|
110
|
-
[RouteParameter, 'RouteParameter'],
|
|
111
110
|
[RoutePathname, 'RoutePathname'],
|
|
112
111
|
[RouteService, 'RouteService'],
|
|
113
|
-
[Route, 'Route'],
|
|
114
112
|
[Runtime, 'Runtime'],
|
|
115
|
-
[ServiceRuntime, 'ServiceRuntime'],
|
|
116
113
|
[Service, 'Service'],
|
|
114
|
+
[ServiceRuntime, 'ServiceRuntime'],
|
|
117
115
|
[ThemeStatus, 'ThemeStatus'],
|
|
118
116
|
[VenueAudience, 'VenueAudience'],
|
|
119
117
|
[VenueStatus, 'VenueStatus'],
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { PathnameParameters, Route, RoutePathname } from '../codegen/autogenerated.js'
|
|
2
|
+
import { access } from './access.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @template {keyof typeof import('@shakerquiz/utilities').Route} R
|
|
6
|
+
*
|
|
7
|
+
* @param {R} maybeRoute
|
|
8
|
+
* @param {any[]} maybeParams
|
|
9
|
+
*
|
|
10
|
+
* @returns {typeof import('@shakerquiz/utilities').RoutePathname[R]}
|
|
11
|
+
*/
|
|
12
|
+
export const hydrateRoutePathname = (maybeRoute, maybeParams) => {
|
|
13
|
+
if (!Array.isArray(maybeParams))
|
|
14
|
+
throw TypeError(`Parameter 'params' must be 'Array'.`)
|
|
15
|
+
|
|
16
|
+
var route = access(Route, maybeRoute)
|
|
17
|
+
|
|
18
|
+
var pathname = access(RoutePathname, route)
|
|
19
|
+
|
|
20
|
+
var pathnameParameters = access(PathnameParameters, pathname)
|
|
21
|
+
|
|
22
|
+
return pathnameParameters.reduce((pathname, parameter, index) =>
|
|
23
|
+
Object.hasOwn(maybeParams, index)
|
|
24
|
+
? pathname.replace(parameter, maybeParams[index])
|
|
25
|
+
: pathname, pathname)
|
|
26
|
+
}
|
package/source/helpers/tag.js
CHANGED
|
@@ -1,35 +1,38 @@
|
|
|
1
1
|
import { Method } from '../entities/method.js'
|
|
2
2
|
|
|
3
3
|
import { access } from './access.js'
|
|
4
|
-
import { hydrateRoutePathname } from './
|
|
4
|
+
import { hydrateRoutePathname } from './route-pathname.js'
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
6
|
+
/**
|
|
7
|
+
* @template {keyof typeof import('@shakerquiz/utilities').Method} M
|
|
8
|
+
* @template {keyof typeof import('@shakerquiz/utilities').Route} R
|
|
9
|
+
*
|
|
10
|
+
* @param {M} maybeMethod
|
|
11
|
+
* @param {R} maybeRoute
|
|
12
|
+
* @param {any[]} maybeParams
|
|
13
|
+
*
|
|
14
|
+
* @returns {`${M}/${ReturnType<typeof hydrateRoutePathname<R>>}`}
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* tag('GET', 'cities', []) // => 'GET/cities'
|
|
18
|
+
*
|
|
19
|
+
* tag('GET', 'game/theme/cover', ['<g>']) // => 'GET/game/<g>/theme/:theme/:cover'
|
|
20
|
+
*
|
|
21
|
+
* tag('POST', 'city', []) // => 'POST/city/:city'
|
|
22
|
+
*/
|
|
23
|
+
export const tag = (maybeMethod, maybeRoute, maybeParams) => {
|
|
24
|
+
var method = access(Method, maybeMethod)
|
|
20
25
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
)
|
|
26
|
+
return method + '/' + hydrateRoutePathname(maybeRoute, maybeParams)
|
|
27
|
+
}
|
|
24
28
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
)
|
|
29
|
+
/**
|
|
30
|
+
* @template {keyof typeof import('@shakerquiz/utilities').Method} M
|
|
31
|
+
* @template {keyof typeof import('@shakerquiz/utilities').Route} R
|
|
32
|
+
*
|
|
33
|
+
* @param {M} maybeMethod
|
|
34
|
+
* @param {R} maybeRoute
|
|
35
|
+
* @param {any[]} maybeParams
|
|
36
|
+
*/
|
|
37
|
+
export const tagexp = (maybeMethod, maybeRoute, maybeParams) =>
|
|
38
|
+
new RegExp(`^${tag(maybeMethod, maybeRoute, maybeParams)}$`)
|
package/source/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from './codegen/autogenerated.js'
|
|
1
2
|
export * from './entities/blend.js'
|
|
2
3
|
export * from './entities/cardinality.js'
|
|
3
4
|
export * from './entities/category.js'
|
|
@@ -22,19 +23,14 @@ export * from './entities/registration-lineup.js'
|
|
|
22
23
|
export * from './entities/registration-mailing.js'
|
|
23
24
|
export * from './entities/registration-status.js'
|
|
24
25
|
export * from './entities/role.js'
|
|
25
|
-
export * from './entities/
|
|
26
|
-
export * from './entities/
|
|
27
|
-
export * from './entities/route-pathname.js'
|
|
28
|
-
export * from './entities/route-relation.js'
|
|
29
|
-
export * from './entities/route-service.js'
|
|
30
|
-
export * from './entities/route.js'
|
|
31
|
-
export * from './entities/runtime.js'
|
|
26
|
+
export * from './entities/routes.js'
|
|
27
|
+
export * from './entities/runtimes.js'
|
|
32
28
|
export * from './entities/segment.js'
|
|
33
29
|
export * from './entities/service-runtime.js'
|
|
34
|
-
export * from './entities/
|
|
30
|
+
export * from './entities/services.js'
|
|
35
31
|
export * from './entities/theme-status.js'
|
|
36
32
|
export * from './entities/venue-audience.js'
|
|
37
33
|
export * from './entities/venue-status.js'
|
|
38
34
|
export * from './helpers/access.js'
|
|
39
|
-
export * from './helpers/
|
|
35
|
+
export * from './helpers/route-pathname.js'
|
|
40
36
|
export * from './helpers/tag.js'
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import template from './templates/route-cardinality.js' with { type: 'text' }
|
|
2
|
-
|
|
3
|
-
import { Routes } from '../source/entities/route.js'
|
|
4
|
-
import { Segment } from '../source/entities/segment.js'
|
|
5
|
-
|
|
6
|
-
let cardinalities = Routes.map(route => {
|
|
7
|
-
const cardinalities = route.split('/').map(key => Segment[key].cardinality)
|
|
8
|
-
|
|
9
|
-
return cardinalities.length > 1
|
|
10
|
-
? cardinalities.at(0) + '/' + cardinalities.at(-1)
|
|
11
|
-
: cardinalities.at(0)
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
let RouteCardinalities = JSON.stringify(cardinalities, undefined, 2)
|
|
15
|
-
|
|
16
|
-
let RouteCardinality = JSON.stringify(Routes.reduce((o, x, i) => (o[x] = cardinalities[i], o), {}), null, 2)
|
|
17
|
-
|
|
18
|
-
Bun.write(
|
|
19
|
-
'./source/entities/route-cardinality.js',
|
|
20
|
-
template
|
|
21
|
-
.replace('/* RouteCardinalities */', RouteCardinalities)
|
|
22
|
-
.replace('/* RouteCardinality */', RouteCardinality),
|
|
23
|
-
)
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import template from './templates/route-parameter.js' with { type: 'text' }
|
|
2
|
-
|
|
3
|
-
import { Routes } from '../source/entities/route.js'
|
|
4
|
-
import { Segment } from '../source/entities/segment.js'
|
|
5
|
-
|
|
6
|
-
let pathnames = Routes.map(route =>
|
|
7
|
-
route
|
|
8
|
-
.split('/')
|
|
9
|
-
.map(key => Segment[key].cardinality === '1' ? key + '/:' + key : key)
|
|
10
|
-
.join('/')
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
let parameters = pathnames.map(pathname =>
|
|
14
|
-
pathname
|
|
15
|
-
.split('/')
|
|
16
|
-
.filter(key => key.includes(':'))
|
|
17
|
-
.join('/')
|
|
18
|
-
)
|
|
19
|
-
|
|
20
|
-
let RouteParameters = JSON.stringify(parameters, undefined, 2)
|
|
21
|
-
|
|
22
|
-
let RouteParameter = JSON.stringify(Routes.reduce((o, x, i) => (o[x] = parameters[i], o), {}), null, 2)
|
|
23
|
-
|
|
24
|
-
Bun.write(
|
|
25
|
-
'./source/entities/route-parameter.js',
|
|
26
|
-
template
|
|
27
|
-
.replace('/* RouteParameters */', RouteParameters)
|
|
28
|
-
.replace('/* RouteParameter */', RouteParameter),
|
|
29
|
-
)
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import template from './templates/route-pathname.js' with { type: 'text' }
|
|
2
|
-
|
|
3
|
-
import { Routes } from '../source/entities/route.js'
|
|
4
|
-
import { Segment } from '../source/entities/segment.js'
|
|
5
|
-
|
|
6
|
-
let pathnames = Routes.map(route =>
|
|
7
|
-
route
|
|
8
|
-
.split('/')
|
|
9
|
-
.map(key => Segment[key].cardinality === '1' ? key + '/:' + key : key)
|
|
10
|
-
.join('/')
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
let RoutePathnames = JSON.stringify(
|
|
14
|
-
pathnames,
|
|
15
|
-
undefined,
|
|
16
|
-
2,
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
let RoutePathname = JSON.stringify(
|
|
20
|
-
Routes.reduce((o, x, i) => (o[x] = pathnames[i], o), {}),
|
|
21
|
-
null,
|
|
22
|
-
2,
|
|
23
|
-
)
|
|
24
|
-
|
|
25
|
-
let PathnameRoute = JSON.stringify(
|
|
26
|
-
pathnames.reduce((o, x, i) => (o[x] = Routes[i], o), {}),
|
|
27
|
-
null,
|
|
28
|
-
2,
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
Bun.write(
|
|
32
|
-
'./source/entities/route-pathname.js',
|
|
33
|
-
template
|
|
34
|
-
.replace('/* RoutePathnames */', RoutePathnames)
|
|
35
|
-
.replace('/* RoutePathname */', RoutePathname)
|
|
36
|
-
.replace('/* PathnameRoute */', PathnameRoute),
|
|
37
|
-
)
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import template from './templates/route-relation.js' with { type: 'text' }
|
|
2
|
-
|
|
3
|
-
import { Routes } from '../source/entities/route.js'
|
|
4
|
-
import { Segment } from '../source/entities/segment.js'
|
|
5
|
-
|
|
6
|
-
let relations = Routes.map(route =>
|
|
7
|
-
route
|
|
8
|
-
.split('/')
|
|
9
|
-
.map((key, index) =>
|
|
10
|
-
Segment[key].cardinality === '1' || index > 0
|
|
11
|
-
? key
|
|
12
|
-
: Segment[key].relation ?? key
|
|
13
|
-
)
|
|
14
|
-
.join('/')
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
let RouteRelations = JSON.stringify(relations, undefined, 2)
|
|
18
|
-
|
|
19
|
-
let RouteRelation = JSON.stringify(Routes.reduce((o, x, i) => (o[x] = relations[i], o), {}), null, 2)
|
|
20
|
-
|
|
21
|
-
Bun.write(
|
|
22
|
-
'./source/entities/route-relation.js',
|
|
23
|
-
template
|
|
24
|
-
.replace('/* RouteRelations */', RouteRelations)
|
|
25
|
-
.replace('/* RouteRelation */', RouteRelation),
|
|
26
|
-
)
|