@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 CHANGED
@@ -18,4 +18,4 @@
18
18
  "https://plugins.dprint.dev/typescript-0.93.0.wasm",
19
19
  "https://plugins.dprint.dev/json-0.19.3.wasm"
20
20
  ]
21
- }
21
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@shakerquiz/utilities",
4
- "version": "4.0.53",
4
+ "version": "4.0.54",
5
5
  "author": "yurkimus <yurkimus@gmail.com>",
6
6
  "license": "ISC",
7
7
  "repository": {
@@ -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].relation
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].relation)
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: Key['checkin'],
8
+ key: 'checkin',
10
9
  cardinality: '1',
11
- relation: undefined,
10
+ singular: 'checkin',
11
+ plural: 'checkins',
12
12
  service: Service['Checkin'],
13
- pattern: undefined,
13
+ pattern: null,
14
14
  }),
15
15
  ),
16
16
  Object.freeze(
17
17
  /** @type {const} */ ({
18
- key: Key['user'],
18
+ key: 'user',
19
19
  cardinality: '1',
20
- relation: Key['users'],
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: Key['users'],
28
+ key: 'users',
28
29
  cardinality: 'n',
29
- relation: Key['user'],
30
+ singular: 'user',
31
+ plural: 'users',
30
32
  service: Service['Users'],
31
- pattern: undefined,
33
+ pattern: null,
32
34
  }),
33
35
  ),
34
36
  Object.freeze(
35
37
  /** @type {const} */ ({
36
- key: Key['role'],
38
+ key: 'role',
37
39
  cardinality: '1',
38
- relation: Key['roles'],
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: Key['roles'],
48
+ key: 'roles',
46
49
  cardinality: 'n',
47
- relation: Key['role'],
50
+ singular: 'role',
51
+ plural: 'roles',
48
52
  service: Service['Roles'],
49
- pattern: undefined,
53
+ pattern: null,
50
54
  }),
51
55
  ),
52
56
  Object.freeze(
53
57
  /** @type {const} */ ({
54
- key: Key['country'],
58
+ key: 'country',
55
59
  cardinality: '1',
56
- relation: Key['countries'],
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: Key['countries'],
68
+ key: 'countries',
64
69
  cardinality: 'n',
65
- relation: Key['country'],
70
+ singular: 'country',
71
+ plural: 'countries',
66
72
  service: Service['Locations'],
67
- pattern: undefined,
73
+ pattern: null,
68
74
  }),
69
75
  ),
70
76
  Object.freeze(
71
77
  /** @type {const} */ ({
72
- key: Key['currency'],
78
+ key: 'currency',
73
79
  cardinality: '1',
74
- relation: Key['currencies'],
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: Key['currencies'],
88
+ key: 'currencies',
82
89
  cardinality: 'n',
83
- relation: Key['currency'],
90
+ singular: 'currency',
91
+ plural: 'currencies',
84
92
  service: Service['Locations'],
85
- pattern: undefined,
93
+ pattern: null,
86
94
  }),
87
95
  ),
88
96
  Object.freeze(
89
97
  /** @type {const} */ ({
90
- key: Key['timezone'],
98
+ key: 'timezone',
91
99
  cardinality: '1',
92
- relation: Key['timezones'],
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: Key['timezones'],
108
+ key: 'timezones',
100
109
  cardinality: 'n',
101
- relation: Key['timezone'],
110
+ singular: 'timezone',
111
+ plural: 'timezones',
102
112
  service: Service['Locations'],
103
- pattern: undefined,
113
+ pattern: null,
104
114
  }),
105
115
  ),
106
116
  Object.freeze(
107
117
  /** @type {const} */ ({
108
- key: Key['city'],
118
+ key: 'city',
109
119
  cardinality: '1',
110
- relation: Key['cities'],
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: Key['cities'],
128
+ key: 'cities',
118
129
  cardinality: 'n',
119
- relation: Key['city'],
130
+ singular: 'city',
131
+ plural: 'cities',
120
132
  service: Service['Cities'],
121
- pattern: undefined,
133
+ pattern: null,
122
134
  }),
123
135
  ),
124
136
  Object.freeze(
125
137
  /** @type {const} */ ({
126
- key: Key['venue'],
138
+ key: 'venue',
127
139
  cardinality: '1',
128
- relation: Key['venues'],
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: Key['venues'],
148
+ key: 'venues',
136
149
  cardinality: 'n',
137
- relation: Key['venue'],
150
+ singular: 'venue',
151
+ plural: 'venues',
138
152
  service: Service['Venues'],
139
- pattern: undefined,
153
+ pattern: null,
140
154
  }),
141
155
  ),
142
156
  Object.freeze(
143
157
  /** @type {const} */ ({
144
- key: Key['theme'],
158
+ key: 'theme',
145
159
  cardinality: '1',
146
- relation: Key['themes'],
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: Key['themes'],
168
+ key: 'themes',
154
169
  cardinality: 'n',
155
- relation: Key['theme'],
170
+ singular: 'theme',
171
+ plural: 'themes',
156
172
  service: Service['Themes'],
157
- pattern: undefined,
173
+ pattern: null,
158
174
  }),
159
175
  ),
160
176
  Object.freeze(
161
177
  /** @type {const} */ ({
162
- key: Key['cover'],
178
+ key: 'cover',
163
179
  cardinality: '1',
164
- relation: undefined,
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: Key['game'],
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
- relation: Key['games'],
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: Key['games'],
208
+ key: 'games',
181
209
  cardinality: 'n',
182
- relation: Key['game'],
210
+ singular: 'game',
211
+ plural: 'games',
183
212
  service: Service['Games'],
184
- pattern: undefined,
213
+ pattern: null,
185
214
  }),
186
215
  ),
187
216
  Object.freeze(
188
217
  /** @type {const} */ ({
189
- key: Key['registration'],
218
+ key: 'registration',
190
219
  cardinality: '1',
191
- relation: Key['registrations'],
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: Key['registrations'],
228
+ key: 'registrations',
199
229
  cardinality: 'n',
200
- relation: Key['registration'],
230
+ singular: 'registration',
231
+ plural: 'registrations',
201
232
  service: Service['Registrations'],
202
- pattern: undefined,
233
+ pattern: null,
203
234
  }),
204
235
  ),
205
236
  Object.freeze(
206
237
  /** @type {const} */ ({
207
- key: Key['export'],
238
+ key: 'status',
208
239
  cardinality: '1',
209
- relation: undefined,
210
- service: undefined,
211
- pattern: undefined,
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: Key['password'],
217
- cardinality: '1',
218
- relation: undefined,
219
- service: undefined,
220
- pattern: undefined,
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: Key['vk_group_token'],
258
+ key: 'lineup',
226
259
  cardinality: '1',
227
- relation: undefined,
228
- service: undefined,
229
- pattern: undefined,
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: Key['summary'],
235
- cardinality: '1',
236
- relation: undefined,
237
- service: undefined,
238
- pattern: undefined,
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: Key['mailing'],
278
+ key: 'telegram',
244
279
  cardinality: '1',
245
- relation: undefined,
246
- service: undefined,
247
- pattern: undefined,
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: Key['channel'],
288
+ key: 'chatapp',
253
289
  cardinality: '1',
254
- relation: undefined,
255
- service: undefined,
256
- pattern: undefined,
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: Key['status'],
298
+ key: 'bitrix',
262
299
  cardinality: '1',
263
- relation: Key['statuses'],
264
- service: undefined,
265
- pattern: Pattern.STRING.source,
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: Key['statuses'],
271
- cardinality: 'n',
272
- relation: Key['status'],
273
- service: undefined,
274
- pattern: undefined,
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: Key['creation'],
318
+ key: 'source',
280
319
  cardinality: '1',
281
- relation: undefined,
282
- service: undefined,
283
- pattern: undefined,
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: Key['confirmation'],
328
+ key: 'search',
289
329
  cardinality: '1',
290
- relation: undefined,
291
- service: undefined,
292
- pattern: undefined,
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: Key['cancellation'],
338
+ key: 'export',
298
339
  cardinality: '1',
299
- relation: undefined,
300
- service: undefined,
301
- pattern: undefined,
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: Key['lineup'],
348
+ key: 'password',
307
349
  cardinality: '1',
308
- relation: Key['lineups'],
309
- service: undefined,
310
- pattern: undefined,
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: Key['lineups'],
316
- cardinality: 'n',
317
- relation: Key['lineup'],
318
- service: undefined,
319
- pattern: undefined,
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: Key['telegram'],
368
+ key: 'summary',
325
369
  cardinality: '1',
326
- relation: undefined,
327
- service: Service['Telegram'],
328
- pattern: undefined,
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: Key['chatapp'],
378
+ key: 'mailing',
334
379
  cardinality: '1',
335
- relation: undefined,
336
- service: Service['Chatapp'],
337
- pattern: undefined,
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: Key['bitrix'],
388
+ key: 'channel',
343
389
  cardinality: '1',
344
- relation: undefined,
345
- service: Service['Bitrix'],
346
- pattern: undefined,
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: Key['webhook'],
398
+ key: 'creation',
352
399
  cardinality: '1',
353
- relation: undefined,
354
- service: undefined,
355
- pattern: undefined,
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: Key['source'],
408
+ key: 'confirmation',
361
409
  cardinality: '1',
362
- relation: undefined,
363
- service: Service['Updates'],
364
- pattern: undefined,
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: Key['search'],
418
+ key: 'cancellation',
370
419
  cardinality: '1',
371
- relation: undefined,
372
- service: undefined,
373
- pattern: undefined,
420
+ singular: 'cancellation',
421
+ plural: 'cancellations',
422
+ service: null,
423
+ pattern: null,
374
424
  }),
375
425
  ),
376
426
  ]),
@@ -1,27 +1,127 @@
1
- import { PathnameParameters, RoutePathname } from '../codegen/autogenerated.js'
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
- * @template {keyof typeof import('@shakerquiz/utilities').Route} R
4
+ * @param {string} maybeString
7
5
  *
8
- * @param {R} maybeRoute
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
- * @returns {typeof import('@shakerquiz/utilities').RoutePathname[R]}
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 'Array'.`)
16
-
17
- var route = access(Route, maybeRoute)
114
+ throw TypeError(`Parameter 'params' must be Array.`)
18
115
 
19
- var pathname = access(RoutePathname, route)
116
+ const pathname = routePathname(maybeRoute)
20
117
 
21
- var pathnameParameters = access(PathnameParameters, pathname)
118
+ const parameters = routeParameters(maybeRoute)
22
119
 
23
- return pathnameParameters.reduce((pathname, parameter, index) =>
24
- Object.hasOwn(maybeParams, index)
25
- ? pathname.replace(parameter, maybeParams[index])
26
- : pathname, pathname)
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
  }
@@ -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 {R} maybeRoute
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', ['<g>']) // => 'GET/game/<g>/theme/: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
- var method = access(Method, maybeMethod)
20
+ if (!Object.hasOwn(Method, maybeMethod))
21
+ throw TypeError(`Could not access Method['${maybeMethod}'].`)
25
22
 
26
- return method + '/' + hydrateRoutePathname(maybeRoute, maybeParams)
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 {R} maybeRoute
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'
@@ -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)