@shakerquiz/utilities 4.0.53 → 4.0.54
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/dprint.json +1 -1
- package/package.json +1 -1
- package/scripts/codegen.js +2 -2
- package/source/entities/segment.js +186 -136
- package/source/helpers/route-pathname.js +115 -15
- package/source/helpers/tag.js +9 -10
- package/source/index.js +0 -1
- package/source/helpers/params.js +0 -17
package/dprint.json
CHANGED
package/package.json
CHANGED
package/scripts/codegen.js
CHANGED
|
@@ -30,7 +30,7 @@ let breakdown = route =>
|
|
|
30
30
|
else if (Segment[x].cardinality === '1')
|
|
31
31
|
return x
|
|
32
32
|
else
|
|
33
|
-
return Segment[x].
|
|
33
|
+
return Segment[x].singular
|
|
34
34
|
})
|
|
35
35
|
.join('/')
|
|
36
36
|
|
|
@@ -45,7 +45,7 @@ let relation = route => {
|
|
|
45
45
|
|
|
46
46
|
return segments
|
|
47
47
|
.slice(segments.length >= 3 ? -2 : 0)
|
|
48
|
-
.map(x => Segment[x].cardinality === '1' ? x : Segment[x].
|
|
48
|
+
.map(x => Segment[x].cardinality === '1' ? x : Segment[x].singular)
|
|
49
49
|
.join('/')
|
|
50
50
|
}
|
|
51
51
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Key } from './key.js'
|
|
2
1
|
import { Pattern } from './pattern.js'
|
|
3
2
|
import { Service } from './services.js'
|
|
4
3
|
|
|
@@ -6,371 +5,422 @@ export const Segments = Object.freeze(
|
|
|
6
5
|
/** @type {const} */ ([
|
|
7
6
|
Object.freeze(
|
|
8
7
|
/** @type {const} */ ({
|
|
9
|
-
key:
|
|
8
|
+
key: 'checkin',
|
|
10
9
|
cardinality: '1',
|
|
11
|
-
|
|
10
|
+
singular: 'checkin',
|
|
11
|
+
plural: 'checkins',
|
|
12
12
|
service: Service['Checkin'],
|
|
13
|
-
pattern:
|
|
13
|
+
pattern: null,
|
|
14
14
|
}),
|
|
15
15
|
),
|
|
16
16
|
Object.freeze(
|
|
17
17
|
/** @type {const} */ ({
|
|
18
|
-
key:
|
|
18
|
+
key: 'user',
|
|
19
19
|
cardinality: '1',
|
|
20
|
-
|
|
20
|
+
singular: 'user',
|
|
21
|
+
plural: 'users',
|
|
21
22
|
service: Service['Users'],
|
|
22
23
|
pattern: Pattern.UUID.source,
|
|
23
24
|
}),
|
|
24
25
|
),
|
|
25
26
|
Object.freeze(
|
|
26
27
|
/** @type {const} */ ({
|
|
27
|
-
key:
|
|
28
|
+
key: 'users',
|
|
28
29
|
cardinality: 'n',
|
|
29
|
-
|
|
30
|
+
singular: 'user',
|
|
31
|
+
plural: 'users',
|
|
30
32
|
service: Service['Users'],
|
|
31
|
-
pattern:
|
|
33
|
+
pattern: null,
|
|
32
34
|
}),
|
|
33
35
|
),
|
|
34
36
|
Object.freeze(
|
|
35
37
|
/** @type {const} */ ({
|
|
36
|
-
key:
|
|
38
|
+
key: 'role',
|
|
37
39
|
cardinality: '1',
|
|
38
|
-
|
|
40
|
+
singular: 'role',
|
|
41
|
+
plural: 'roles',
|
|
39
42
|
service: Service['Roles'],
|
|
40
43
|
pattern: Pattern.UUID.source,
|
|
41
44
|
}),
|
|
42
45
|
),
|
|
43
46
|
Object.freeze(
|
|
44
47
|
/** @type {const} */ ({
|
|
45
|
-
key:
|
|
48
|
+
key: 'roles',
|
|
46
49
|
cardinality: 'n',
|
|
47
|
-
|
|
50
|
+
singular: 'role',
|
|
51
|
+
plural: 'roles',
|
|
48
52
|
service: Service['Roles'],
|
|
49
|
-
pattern:
|
|
53
|
+
pattern: null,
|
|
50
54
|
}),
|
|
51
55
|
),
|
|
52
56
|
Object.freeze(
|
|
53
57
|
/** @type {const} */ ({
|
|
54
|
-
key:
|
|
58
|
+
key: 'country',
|
|
55
59
|
cardinality: '1',
|
|
56
|
-
|
|
60
|
+
singular: 'country',
|
|
61
|
+
plural: 'countries',
|
|
57
62
|
service: Service['Locations'],
|
|
58
63
|
pattern: Pattern.COUNTRY_CODE.source,
|
|
59
64
|
}),
|
|
60
65
|
),
|
|
61
66
|
Object.freeze(
|
|
62
67
|
/** @type {const} */ ({
|
|
63
|
-
key:
|
|
68
|
+
key: 'countries',
|
|
64
69
|
cardinality: 'n',
|
|
65
|
-
|
|
70
|
+
singular: 'country',
|
|
71
|
+
plural: 'countries',
|
|
66
72
|
service: Service['Locations'],
|
|
67
|
-
pattern:
|
|
73
|
+
pattern: null,
|
|
68
74
|
}),
|
|
69
75
|
),
|
|
70
76
|
Object.freeze(
|
|
71
77
|
/** @type {const} */ ({
|
|
72
|
-
key:
|
|
78
|
+
key: 'currency',
|
|
73
79
|
cardinality: '1',
|
|
74
|
-
|
|
80
|
+
singular: 'currency',
|
|
81
|
+
plural: 'currencies',
|
|
75
82
|
service: Service['Locations'],
|
|
76
83
|
pattern: Pattern.CURRENCY_CODE.source,
|
|
77
84
|
}),
|
|
78
85
|
),
|
|
79
86
|
Object.freeze(
|
|
80
87
|
/** @type {const} */ ({
|
|
81
|
-
key:
|
|
88
|
+
key: 'currencies',
|
|
82
89
|
cardinality: 'n',
|
|
83
|
-
|
|
90
|
+
singular: 'currency',
|
|
91
|
+
plural: 'currencies',
|
|
84
92
|
service: Service['Locations'],
|
|
85
|
-
pattern:
|
|
93
|
+
pattern: null,
|
|
86
94
|
}),
|
|
87
95
|
),
|
|
88
96
|
Object.freeze(
|
|
89
97
|
/** @type {const} */ ({
|
|
90
|
-
key:
|
|
98
|
+
key: 'timezone',
|
|
91
99
|
cardinality: '1',
|
|
92
|
-
|
|
100
|
+
singular: 'timezone',
|
|
101
|
+
plural: 'timezones',
|
|
93
102
|
service: Service['Locations'],
|
|
94
103
|
pattern: Pattern.TIMEZONE_NAME.source,
|
|
95
104
|
}),
|
|
96
105
|
),
|
|
97
106
|
Object.freeze(
|
|
98
107
|
/** @type {const} */ ({
|
|
99
|
-
key:
|
|
108
|
+
key: 'timezones',
|
|
100
109
|
cardinality: 'n',
|
|
101
|
-
|
|
110
|
+
singular: 'timezone',
|
|
111
|
+
plural: 'timezones',
|
|
102
112
|
service: Service['Locations'],
|
|
103
|
-
pattern:
|
|
113
|
+
pattern: null,
|
|
104
114
|
}),
|
|
105
115
|
),
|
|
106
116
|
Object.freeze(
|
|
107
117
|
/** @type {const} */ ({
|
|
108
|
-
key:
|
|
118
|
+
key: 'city',
|
|
109
119
|
cardinality: '1',
|
|
110
|
-
|
|
120
|
+
singular: 'city',
|
|
121
|
+
plural: 'cities',
|
|
111
122
|
service: Service['Cities'],
|
|
112
123
|
pattern: Pattern.UUID.source,
|
|
113
124
|
}),
|
|
114
125
|
),
|
|
115
126
|
Object.freeze(
|
|
116
127
|
/** @type {const} */ ({
|
|
117
|
-
key:
|
|
128
|
+
key: 'cities',
|
|
118
129
|
cardinality: 'n',
|
|
119
|
-
|
|
130
|
+
singular: 'city',
|
|
131
|
+
plural: 'cities',
|
|
120
132
|
service: Service['Cities'],
|
|
121
|
-
pattern:
|
|
133
|
+
pattern: null,
|
|
122
134
|
}),
|
|
123
135
|
),
|
|
124
136
|
Object.freeze(
|
|
125
137
|
/** @type {const} */ ({
|
|
126
|
-
key:
|
|
138
|
+
key: 'venue',
|
|
127
139
|
cardinality: '1',
|
|
128
|
-
|
|
140
|
+
singular: 'venue',
|
|
141
|
+
plural: 'venues',
|
|
129
142
|
service: Service['Venues'],
|
|
130
143
|
pattern: Pattern.UUID.source,
|
|
131
144
|
}),
|
|
132
145
|
),
|
|
133
146
|
Object.freeze(
|
|
134
147
|
/** @type {const} */ ({
|
|
135
|
-
key:
|
|
148
|
+
key: 'venues',
|
|
136
149
|
cardinality: 'n',
|
|
137
|
-
|
|
150
|
+
singular: 'venue',
|
|
151
|
+
plural: 'venues',
|
|
138
152
|
service: Service['Venues'],
|
|
139
|
-
pattern:
|
|
153
|
+
pattern: null,
|
|
140
154
|
}),
|
|
141
155
|
),
|
|
142
156
|
Object.freeze(
|
|
143
157
|
/** @type {const} */ ({
|
|
144
|
-
key:
|
|
158
|
+
key: 'theme',
|
|
145
159
|
cardinality: '1',
|
|
146
|
-
|
|
160
|
+
singular: 'theme',
|
|
161
|
+
plural: 'themes',
|
|
147
162
|
service: Service['Themes'],
|
|
148
163
|
pattern: Pattern.UUID.source,
|
|
149
164
|
}),
|
|
150
165
|
),
|
|
151
166
|
Object.freeze(
|
|
152
167
|
/** @type {const} */ ({
|
|
153
|
-
key:
|
|
168
|
+
key: 'themes',
|
|
154
169
|
cardinality: 'n',
|
|
155
|
-
|
|
170
|
+
singular: 'theme',
|
|
171
|
+
plural: 'themes',
|
|
156
172
|
service: Service['Themes'],
|
|
157
|
-
pattern:
|
|
173
|
+
pattern: null,
|
|
158
174
|
}),
|
|
159
175
|
),
|
|
160
176
|
Object.freeze(
|
|
161
177
|
/** @type {const} */ ({
|
|
162
|
-
key:
|
|
178
|
+
key: 'cover',
|
|
163
179
|
cardinality: '1',
|
|
164
|
-
|
|
180
|
+
singular: 'cover',
|
|
181
|
+
plural: 'covers',
|
|
165
182
|
service: Service['Minio'],
|
|
166
183
|
pattern: Pattern.UUID.source,
|
|
167
184
|
}),
|
|
168
185
|
),
|
|
169
186
|
Object.freeze(
|
|
170
187
|
/** @type {const} */ ({
|
|
171
|
-
key:
|
|
188
|
+
key: 'covers',
|
|
189
|
+
cardinality: 'n',
|
|
190
|
+
singular: 'cover',
|
|
191
|
+
plural: 'covers',
|
|
192
|
+
service: Service['Minio'],
|
|
193
|
+
pattern: null,
|
|
194
|
+
}),
|
|
195
|
+
),
|
|
196
|
+
Object.freeze(
|
|
197
|
+
/** @type {const} */ ({
|
|
198
|
+
key: 'game',
|
|
172
199
|
cardinality: '1',
|
|
173
|
-
|
|
200
|
+
singular: 'game',
|
|
201
|
+
plural: 'games',
|
|
174
202
|
service: Service['Games'],
|
|
175
203
|
pattern: Pattern.UUID.source,
|
|
176
204
|
}),
|
|
177
205
|
),
|
|
178
206
|
Object.freeze(
|
|
179
207
|
/** @type {const} */ ({
|
|
180
|
-
key:
|
|
208
|
+
key: 'games',
|
|
181
209
|
cardinality: 'n',
|
|
182
|
-
|
|
210
|
+
singular: 'game',
|
|
211
|
+
plural: 'games',
|
|
183
212
|
service: Service['Games'],
|
|
184
|
-
pattern:
|
|
213
|
+
pattern: null,
|
|
185
214
|
}),
|
|
186
215
|
),
|
|
187
216
|
Object.freeze(
|
|
188
217
|
/** @type {const} */ ({
|
|
189
|
-
key:
|
|
218
|
+
key: 'registration',
|
|
190
219
|
cardinality: '1',
|
|
191
|
-
|
|
220
|
+
singular: 'registration',
|
|
221
|
+
plural: 'registrations',
|
|
192
222
|
service: Service['Registrations'],
|
|
193
223
|
pattern: Pattern.UUID.source,
|
|
194
224
|
}),
|
|
195
225
|
),
|
|
196
226
|
Object.freeze(
|
|
197
227
|
/** @type {const} */ ({
|
|
198
|
-
key:
|
|
228
|
+
key: 'registrations',
|
|
199
229
|
cardinality: 'n',
|
|
200
|
-
|
|
230
|
+
singular: 'registration',
|
|
231
|
+
plural: 'registrations',
|
|
201
232
|
service: Service['Registrations'],
|
|
202
|
-
pattern:
|
|
233
|
+
pattern: null,
|
|
203
234
|
}),
|
|
204
235
|
),
|
|
205
236
|
Object.freeze(
|
|
206
237
|
/** @type {const} */ ({
|
|
207
|
-
key:
|
|
238
|
+
key: 'status',
|
|
208
239
|
cardinality: '1',
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
240
|
+
singular: 'status',
|
|
241
|
+
plural: 'statuses',
|
|
242
|
+
service: null,
|
|
243
|
+
pattern: Pattern.STRING.source,
|
|
212
244
|
}),
|
|
213
245
|
),
|
|
214
246
|
Object.freeze(
|
|
215
247
|
/** @type {const} */ ({
|
|
216
|
-
key:
|
|
217
|
-
cardinality: '
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
248
|
+
key: 'statuses',
|
|
249
|
+
cardinality: 'n',
|
|
250
|
+
singular: 'status',
|
|
251
|
+
plural: 'statuses',
|
|
252
|
+
service: null,
|
|
253
|
+
pattern: null,
|
|
221
254
|
}),
|
|
222
255
|
),
|
|
223
256
|
Object.freeze(
|
|
224
257
|
/** @type {const} */ ({
|
|
225
|
-
key:
|
|
258
|
+
key: 'lineup',
|
|
226
259
|
cardinality: '1',
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
260
|
+
singular: 'lineup',
|
|
261
|
+
plural: 'lineups',
|
|
262
|
+
service: null,
|
|
263
|
+
pattern: null,
|
|
230
264
|
}),
|
|
231
265
|
),
|
|
232
266
|
Object.freeze(
|
|
233
267
|
/** @type {const} */ ({
|
|
234
|
-
key:
|
|
235
|
-
cardinality: '
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
268
|
+
key: 'lineups',
|
|
269
|
+
cardinality: 'n',
|
|
270
|
+
singular: 'lineup',
|
|
271
|
+
plural: 'lineups',
|
|
272
|
+
service: null,
|
|
273
|
+
pattern: null,
|
|
239
274
|
}),
|
|
240
275
|
),
|
|
241
276
|
Object.freeze(
|
|
242
277
|
/** @type {const} */ ({
|
|
243
|
-
key:
|
|
278
|
+
key: 'telegram',
|
|
244
279
|
cardinality: '1',
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
280
|
+
singular: 'telegram',
|
|
281
|
+
plural: 'telegrams',
|
|
282
|
+
service: Service['Telegram'],
|
|
283
|
+
pattern: null,
|
|
248
284
|
}),
|
|
249
285
|
),
|
|
250
286
|
Object.freeze(
|
|
251
287
|
/** @type {const} */ ({
|
|
252
|
-
key:
|
|
288
|
+
key: 'chatapp',
|
|
253
289
|
cardinality: '1',
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
290
|
+
singular: 'chatapp',
|
|
291
|
+
plural: 'chatapps',
|
|
292
|
+
service: Service['Chatapp'],
|
|
293
|
+
pattern: null,
|
|
257
294
|
}),
|
|
258
295
|
),
|
|
259
296
|
Object.freeze(
|
|
260
297
|
/** @type {const} */ ({
|
|
261
|
-
key:
|
|
298
|
+
key: 'bitrix',
|
|
262
299
|
cardinality: '1',
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
300
|
+
singular: 'bitrix',
|
|
301
|
+
plural: 'bitrixes',
|
|
302
|
+
service: Service['Bitrix'],
|
|
303
|
+
pattern: null,
|
|
266
304
|
}),
|
|
267
305
|
),
|
|
268
306
|
Object.freeze(
|
|
269
307
|
/** @type {const} */ ({
|
|
270
|
-
key:
|
|
271
|
-
cardinality: '
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
308
|
+
key: 'webhook',
|
|
309
|
+
cardinality: '1',
|
|
310
|
+
singular: 'webhook',
|
|
311
|
+
plural: 'webhooks',
|
|
312
|
+
service: null,
|
|
313
|
+
pattern: null,
|
|
275
314
|
}),
|
|
276
315
|
),
|
|
277
316
|
Object.freeze(
|
|
278
317
|
/** @type {const} */ ({
|
|
279
|
-
key:
|
|
318
|
+
key: 'source',
|
|
280
319
|
cardinality: '1',
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
320
|
+
singular: 'source',
|
|
321
|
+
plural: 'sources',
|
|
322
|
+
service: Service['Updates'],
|
|
323
|
+
pattern: null,
|
|
284
324
|
}),
|
|
285
325
|
),
|
|
286
326
|
Object.freeze(
|
|
287
327
|
/** @type {const} */ ({
|
|
288
|
-
key:
|
|
328
|
+
key: 'search',
|
|
289
329
|
cardinality: '1',
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
330
|
+
singular: 'search',
|
|
331
|
+
plural: 'searches',
|
|
332
|
+
service: null,
|
|
333
|
+
pattern: null,
|
|
293
334
|
}),
|
|
294
335
|
),
|
|
295
336
|
Object.freeze(
|
|
296
337
|
/** @type {const} */ ({
|
|
297
|
-
key:
|
|
338
|
+
key: 'export',
|
|
298
339
|
cardinality: '1',
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
340
|
+
singular: 'export',
|
|
341
|
+
plural: 'exports',
|
|
342
|
+
service: null,
|
|
343
|
+
pattern: null,
|
|
302
344
|
}),
|
|
303
345
|
),
|
|
304
346
|
Object.freeze(
|
|
305
347
|
/** @type {const} */ ({
|
|
306
|
-
key:
|
|
348
|
+
key: 'password',
|
|
307
349
|
cardinality: '1',
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
350
|
+
singular: 'password',
|
|
351
|
+
plural: 'passwords',
|
|
352
|
+
service: null,
|
|
353
|
+
pattern: null,
|
|
311
354
|
}),
|
|
312
355
|
),
|
|
313
356
|
Object.freeze(
|
|
314
357
|
/** @type {const} */ ({
|
|
315
|
-
key:
|
|
316
|
-
cardinality: '
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
358
|
+
key: 'vk_group_token',
|
|
359
|
+
cardinality: '1',
|
|
360
|
+
singular: 'vk_group_token',
|
|
361
|
+
plural: 'vk_group_tokens',
|
|
362
|
+
service: null,
|
|
363
|
+
pattern: null,
|
|
320
364
|
}),
|
|
321
365
|
),
|
|
322
366
|
Object.freeze(
|
|
323
367
|
/** @type {const} */ ({
|
|
324
|
-
key:
|
|
368
|
+
key: 'summary',
|
|
325
369
|
cardinality: '1',
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
370
|
+
singular: 'summary',
|
|
371
|
+
plural: 'summaries',
|
|
372
|
+
service: null,
|
|
373
|
+
pattern: null,
|
|
329
374
|
}),
|
|
330
375
|
),
|
|
331
376
|
Object.freeze(
|
|
332
377
|
/** @type {const} */ ({
|
|
333
|
-
key:
|
|
378
|
+
key: 'mailing',
|
|
334
379
|
cardinality: '1',
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
380
|
+
singular: 'mailing',
|
|
381
|
+
plural: 'mailings',
|
|
382
|
+
service: null,
|
|
383
|
+
pattern: null,
|
|
338
384
|
}),
|
|
339
385
|
),
|
|
340
386
|
Object.freeze(
|
|
341
387
|
/** @type {const} */ ({
|
|
342
|
-
key:
|
|
388
|
+
key: 'channel',
|
|
343
389
|
cardinality: '1',
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
390
|
+
singular: 'channel',
|
|
391
|
+
plural: 'channels',
|
|
392
|
+
service: null,
|
|
393
|
+
pattern: null,
|
|
347
394
|
}),
|
|
348
395
|
),
|
|
349
396
|
Object.freeze(
|
|
350
397
|
/** @type {const} */ ({
|
|
351
|
-
key:
|
|
398
|
+
key: 'creation',
|
|
352
399
|
cardinality: '1',
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
400
|
+
singular: 'creation',
|
|
401
|
+
plural: 'creations',
|
|
402
|
+
service: null,
|
|
403
|
+
pattern: null,
|
|
356
404
|
}),
|
|
357
405
|
),
|
|
358
406
|
Object.freeze(
|
|
359
407
|
/** @type {const} */ ({
|
|
360
|
-
key:
|
|
408
|
+
key: 'confirmation',
|
|
361
409
|
cardinality: '1',
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
410
|
+
singular: 'confirmation',
|
|
411
|
+
plural: 'confirmations',
|
|
412
|
+
service: null,
|
|
413
|
+
pattern: null,
|
|
365
414
|
}),
|
|
366
415
|
),
|
|
367
416
|
Object.freeze(
|
|
368
417
|
/** @type {const} */ ({
|
|
369
|
-
key:
|
|
418
|
+
key: 'cancellation',
|
|
370
419
|
cardinality: '1',
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
420
|
+
singular: 'cancellation',
|
|
421
|
+
plural: 'cancellations',
|
|
422
|
+
service: null,
|
|
423
|
+
pattern: null,
|
|
374
424
|
}),
|
|
375
425
|
),
|
|
376
426
|
]),
|
|
@@ -1,27 +1,127 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Route } from '../entities/routes.js'
|
|
3
|
-
import { access } from './access.js'
|
|
1
|
+
import { Segment } from '../entities/segment.js'
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
|
-
* @
|
|
4
|
+
* @param {string} maybeString
|
|
7
5
|
*
|
|
8
|
-
* @
|
|
6
|
+
* @example
|
|
7
|
+
* route('user/role') // 'user/role'
|
|
8
|
+
* route('game/registrations') // 'game/registrations'
|
|
9
|
+
*/
|
|
10
|
+
export const route = maybeString => {
|
|
11
|
+
if (typeof maybeString !== 'string')
|
|
12
|
+
throw TypeError(`Parameter 'maybeString' must be String.`)
|
|
13
|
+
|
|
14
|
+
const segments = maybeString.split('/')
|
|
15
|
+
|
|
16
|
+
if (segments.length < 1)
|
|
17
|
+
throw TypeError(`Parameter 'maybeString' must contain at least one segment.`)
|
|
18
|
+
|
|
19
|
+
for (const segment of segments)
|
|
20
|
+
if (!Object.hasOwn(Segment, segment))
|
|
21
|
+
throw TypeError(`[route] Could not access segment Segment['${segment}'].`)
|
|
22
|
+
|
|
23
|
+
return segments.join('/')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {string} segment
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* segment('user') // 'user/:user'
|
|
31
|
+
* segment('roles') // 'roles'
|
|
32
|
+
*/
|
|
33
|
+
export const segment = segment => {
|
|
34
|
+
if (Segment[segment].pattern === null)
|
|
35
|
+
return segment
|
|
36
|
+
else if (Segment[segment].cardinality === '1')
|
|
37
|
+
return `${segment}/:${segment}`
|
|
38
|
+
else
|
|
39
|
+
return segment
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @param {string} maybeRoute
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* routePathname('user/role') // 'user/:user/role/:role'
|
|
47
|
+
* routePathname('game/registrations') // 'game/:game/registrations'
|
|
48
|
+
*/
|
|
49
|
+
export const routePathname = maybeRoute =>
|
|
50
|
+
route(maybeRoute)
|
|
51
|
+
.split('/')
|
|
52
|
+
.map(segment)
|
|
53
|
+
.join('/')
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @param {string} maybeRoute
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* routeParameters('user/role') // [':user', ':role']
|
|
60
|
+
* routeParameters('game/registrations') // [':game']
|
|
61
|
+
*/
|
|
62
|
+
export const routeParameters = maybeRoute =>
|
|
63
|
+
routePathname(maybeRoute)
|
|
64
|
+
.split('/')
|
|
65
|
+
.filter(x => x.includes(':'))
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @param {string} maybeRoute
|
|
69
|
+
* @param {object} object
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* routeParametersFromObject('user/role', { ':user': 1, ':role': 2 }) // [1, 2]
|
|
73
|
+
* routeParametersFromObject('game/registrations', { ':game': 1 }) // [1]
|
|
74
|
+
*/
|
|
75
|
+
export const routeParametersFromObject = (maybeRoute, object) =>
|
|
76
|
+
routeParameters(maybeRoute)
|
|
77
|
+
.map(prop => object[prop])
|
|
78
|
+
.filter(Boolean)
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @param {string} maybeRoute
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* routeProperties('user/role') // ['user_id', 'role_id']
|
|
85
|
+
* routeProperties('game/registrations') // ['game_id']
|
|
86
|
+
*/
|
|
87
|
+
export const routeProperties = maybeRoute =>
|
|
88
|
+
routeParameters(maybeRoute)
|
|
89
|
+
.map(parameter => parameter.replace(':', '') + '_id')
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @param {string} maybeRoute
|
|
93
|
+
* @param {object} object
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* routePropertiesFromObject('user/role', { user_id: 1, role_id: 2 }) // [1, 2]
|
|
97
|
+
* routePropertiesFromObject('game/registrations', { game_id: 1 }) // [1]
|
|
98
|
+
*/
|
|
99
|
+
export const routePropertiesFromObject = (maybeRoute, object) =>
|
|
100
|
+
routeProperties(maybeRoute)
|
|
101
|
+
.map(prop => object[prop])
|
|
102
|
+
.filter(Boolean)
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @param {string} maybeRoute
|
|
9
106
|
* @param {any[]} maybeParams
|
|
10
107
|
*
|
|
11
|
-
* @
|
|
108
|
+
* @example
|
|
109
|
+
* hydrateRoutePathname('user/role', [1, 2]) // 'user/1/role/2'
|
|
110
|
+
* hydrateRoutePathname('game/registrations', [1]) // 'game/1/registrations'
|
|
12
111
|
*/
|
|
13
112
|
export const hydrateRoutePathname = (maybeRoute, maybeParams) => {
|
|
14
113
|
if (!Array.isArray(maybeParams))
|
|
15
|
-
throw TypeError(`Parameter 'params' must be
|
|
16
|
-
|
|
17
|
-
var route = access(Route, maybeRoute)
|
|
114
|
+
throw TypeError(`Parameter 'params' must be Array.`)
|
|
18
115
|
|
|
19
|
-
|
|
116
|
+
const pathname = routePathname(maybeRoute)
|
|
20
117
|
|
|
21
|
-
|
|
118
|
+
const parameters = routeParameters(maybeRoute)
|
|
22
119
|
|
|
23
|
-
return
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
120
|
+
return parameters.reduce(
|
|
121
|
+
(accumulator, parameter, index) =>
|
|
122
|
+
Object.hasOwn(maybeParams, index)
|
|
123
|
+
? accumulator.replace(parameter, maybeParams[index])
|
|
124
|
+
: accumulator,
|
|
125
|
+
pathname,
|
|
126
|
+
)
|
|
27
127
|
}
|
package/source/helpers/tag.js
CHANGED
|
@@ -1,37 +1,36 @@
|
|
|
1
1
|
import { Method } from '../entities/method.js'
|
|
2
2
|
|
|
3
|
-
import { access } from './access.js'
|
|
4
3
|
import { hydrateRoutePathname } from './route-pathname.js'
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* @template {keyof typeof import('@shakerquiz/utilities').Method} M
|
|
8
|
-
* @template {keyof typeof import('@shakerquiz/utilities').Route} R
|
|
9
7
|
*
|
|
10
8
|
* @param {M} maybeMethod
|
|
11
|
-
* @param {
|
|
9
|
+
* @param {string} maybeRoute
|
|
12
10
|
* @param {any[]} maybeParams
|
|
13
11
|
*
|
|
14
|
-
* @returns {`${M}/${ReturnType<typeof hydrateRoutePathname<R>>}`}
|
|
15
|
-
*
|
|
16
12
|
* @example
|
|
17
13
|
* tag('GET', 'cities', []) // => 'GET/cities'
|
|
18
14
|
*
|
|
19
|
-
* tag('GET', 'game/theme/cover', ['<
|
|
15
|
+
* tag('GET', 'game/theme/cover', ['<game>']) // => 'GET/game/<game>/theme/:theme/:cover'
|
|
20
16
|
*
|
|
21
17
|
* tag('POST', 'city', []) // => 'POST/city/:city'
|
|
22
18
|
*/
|
|
23
19
|
export const tag = (maybeMethod, maybeRoute, maybeParams) => {
|
|
24
|
-
|
|
20
|
+
if (!Object.hasOwn(Method, maybeMethod))
|
|
21
|
+
throw TypeError(`Could not access Method['${maybeMethod}'].`)
|
|
25
22
|
|
|
26
|
-
return
|
|
23
|
+
return ''
|
|
24
|
+
+ Method[maybeMethod]
|
|
25
|
+
+ '/'
|
|
26
|
+
+ hydrateRoutePathname(maybeRoute, maybeParams)
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* @template {keyof typeof import('@shakerquiz/utilities').Method} M
|
|
31
|
-
* @template {keyof typeof import('@shakerquiz/utilities').Route} R
|
|
32
31
|
*
|
|
33
32
|
* @param {M} maybeMethod
|
|
34
|
-
* @param {
|
|
33
|
+
* @param {string} maybeRoute
|
|
35
34
|
* @param {any[]} maybeParams
|
|
36
35
|
*/
|
|
37
36
|
export const tagexp = (maybeMethod, maybeRoute, maybeParams) =>
|
package/source/index.js
CHANGED
|
@@ -32,6 +32,5 @@ export * from './entities/theme-status.js'
|
|
|
32
32
|
export * from './entities/venue-audience.js'
|
|
33
33
|
export * from './entities/venue-status.js'
|
|
34
34
|
export * from './helpers/access.js'
|
|
35
|
-
export * from './helpers/params.js'
|
|
36
35
|
export * from './helpers/route-pathname.js'
|
|
37
36
|
export * from './helpers/tag.js'
|
package/source/helpers/params.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { RouteParameters } from '../codegen/autogenerated.js'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @param {keyof typeof import('@shakerquiz/utilities').Route} route
|
|
5
|
-
*/
|
|
6
|
-
export const props = route =>
|
|
7
|
-
RouteParameters[route]
|
|
8
|
-
.map(param => param.replace(':', '') + '_id')
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @param {keyof typeof import('@shakerquiz/utilities').Route} route
|
|
12
|
-
* @param {object} value
|
|
13
|
-
*/
|
|
14
|
-
export const params = (route, value) =>
|
|
15
|
-
props(route)
|
|
16
|
-
.map(prop => value[prop])
|
|
17
|
-
.filter(Boolean)
|