@shakerquiz/utilities 0.3.34 → 0.3.36

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.3.34",
3
+ "version": "0.3.36",
4
4
  "author": "yurkimus <yurkimus@gmail.com>",
5
5
  "license": "ISC",
6
6
  "scripts": {
@@ -0,0 +1,8 @@
1
+ export namespace Schemas {
2
+ export { CitySchema as City };
3
+ export { GameSchema as Game };
4
+ export { RegistrationSchema as Registration };
5
+ export { ThemeSchema as Theme };
6
+ export { UserSchema as User };
7
+ export { VenueSchema as Venue };
8
+ }
@@ -0,0 +1,17 @@
1
+ import { Domains } from '../enumerations/domains.js'
2
+
3
+ import { CitySchema } from '../schemas/city.js'
4
+ import { GameSchema } from '../schemas/game.js'
5
+ import { RegistrationSchema } from '../schemas/registration.js'
6
+ import { ThemeSchema } from '../schemas/theme.js'
7
+ import { UserSchema } from '../schemas/user.js'
8
+ import { VenueSchema } from '../schemas/venue.js'
9
+
10
+ export var Schemas = /** @type {const} */ ({
11
+ [Domains.City]: CitySchema,
12
+ [Domains.Game]: GameSchema,
13
+ [Domains.Registration]: RegistrationSchema,
14
+ [Domains.Theme]: ThemeSchema,
15
+ [Domains.User]: UserSchema,
16
+ [Domains.Venue]: VenueSchema,
17
+ })
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @param {Feature} feature
3
+ * @param {*} object
4
+ */
5
+ export function validateSchema(feature: Feature, object: any): void;
@@ -0,0 +1,70 @@
1
+ import { Schemas } from '../enumerations/schemas.js'
2
+
3
+ /**
4
+ * @param {Feature} feature
5
+ * @param {*} object
6
+ */
7
+ export function validateSchema(feature, object) {
8
+ if (!(feature in Schemas))
9
+ throw TypeError(
10
+ `Parameter 'feature' '${feature}' must be a member of 'Schemas'.`,
11
+ )
12
+
13
+ let schema = Schemas[feature]
14
+
15
+ for (let property in object)
16
+ if (!(property in schema)) {
17
+ let message = `Property '${property}' must be a member of '${columns}'.`
18
+
19
+ throw TypeError(message)
20
+ }
21
+
22
+ for (let property in object) {
23
+ let descriptor = schema[property]
24
+ let value = value[property]
25
+
26
+ if (!is(descriptor.type, value)) {
27
+ let message =
28
+ `Property '${property}' must be of type '${descriptor.type}'.`
29
+
30
+ throw TypeError(message)
31
+ }
32
+
33
+ switch (descriptor.type) {
34
+ case 'String':
35
+ if ('minLength' in descriptor) {
36
+ if (!is('Number', descriptor.minLength)) {
37
+ let message =
38
+ `Descriptor 'minLength' must be a 'Number' when presented.`
39
+
40
+ throw TypeError(message)
41
+ }
42
+
43
+ if (value.length < descriptor.minLength) {
44
+ let message =
45
+ `String '${value}' length should not be less than '${descriptor.minLength}'.`
46
+
47
+ throw TypeError(message)
48
+ }
49
+ }
50
+
51
+ if ('maxLength' in descriptor) {
52
+ if (!is('Number', descriptor.maxLength)) {
53
+ let message =
54
+ `Descriptor 'maxLength' must be a 'Number' when presented.`
55
+
56
+ throw TypeError(message)
57
+ }
58
+
59
+ if (value.length > descriptor.maxLength) {
60
+ let message =
61
+ `String '${value}' length should not be more than '${descriptor.maxLength}'.`
62
+
63
+ throw TypeError(message)
64
+ }
65
+ }
66
+
67
+ break
68
+ }
69
+ }
70
+ }
package/source/index.d.ts CHANGED
@@ -30,11 +30,13 @@ export * from './enumerations/regexps.js'
30
30
  export * from './enumerations/registration-statuses.js'
31
31
  export * from './enumerations/requirements.js'
32
32
  export * from './enumerations/roles.js'
33
+ export * from './enumerations/schemas.js'
33
34
  export * from './enumerations/services.js'
34
35
 
35
36
  export * from './functions/fetch.js'
36
37
  export * from './functions/origin.js'
37
38
  export * from './functions/pathname.js'
39
+ export * from './functions/schema.js'
38
40
  export * from './functions/url.js'
39
41
 
40
42
  export * from './schemas/city.js'
package/source/index.js CHANGED
@@ -30,11 +30,13 @@ export * from './enumerations/regexps.js'
30
30
  export * from './enumerations/registration-statuses.js'
31
31
  export * from './enumerations/requirements.js'
32
32
  export * from './enumerations/roles.js'
33
+ export * from './enumerations/schemas.js'
33
34
  export * from './enumerations/services.js'
34
35
 
35
36
  export * from './functions/fetch.js'
36
37
  export * from './functions/origin.js'
37
38
  export * from './functions/pathname.js'
39
+ export * from './functions/schema.js'
38
40
  export * from './functions/url.js'
39
41
 
40
42
  export * from './schemas/city.js'
@@ -1,56 +1,10 @@
1
- export namespace CityColumns {
2
- let address: "address";
3
- let alias: "alias";
4
- let chatapp_category: "chatapp_category";
5
- let chatapp_legacy: "chatapp_legacy";
6
- let chatapp_line: "chatapp_line";
7
- let chatapp_tag: "chatapp_tag";
8
- let chatapp_user: "chatapp_user";
9
- let country: "country";
10
- let currency: "currency";
11
- let custom_html: "custom_html";
12
- let custom_script: "custom_script";
13
- let description: "description";
14
- let email: "email";
15
- let game_time: "game_time";
16
- let id: "id";
17
- let inst_comment: "inst_comment";
18
- let inst_link: "inst_link";
19
- let inst_login: "inst_login";
20
- let inst_password: "inst_password";
21
- let is_default: "is_default";
22
- let is_franchise: "is_franchise";
23
- let max_members_count: "max_members_count";
24
- let meta_description: "meta_description";
25
- let meta_title: "meta_title";
26
- let min_members_count: "min_members_count";
27
- let name: "name";
28
- let phone: "phone";
29
- let price: "price";
30
- let region: "region";
31
- let telegram_chat_id: "telegram_chat_id";
32
- let tg_comment: "tg_comment";
33
- let tg_link: "tg_link";
34
- let tg_login: "tg_login";
35
- let tg_password: "tg_password";
36
- let time_created: "time_created";
37
- let time_updated: "time_updated";
38
- let timezone: "timezone";
39
- let title: "title";
40
- let vk_comment: "vk_comment";
41
- let vk_group_id: "vk_group_id";
42
- let vk_link: "vk_link";
43
- let yandex_metrica: "yandex_metrica";
44
- }
45
- export namespace CityColumnDescriptors {
46
- export namespace address_1 {
1
+ export namespace CitySchema {
2
+ namespace address {
47
3
  let type: "String";
48
- let nullable: true;
49
4
  let minLength: 1;
50
5
  let maxLength: 255;
51
6
  }
52
- export { address_1 as address };
53
- export namespace alias_1 {
7
+ namespace alias {
54
8
  let type_1: "String";
55
9
  export { type_1 as type };
56
10
  let minLength_1: 1;
@@ -58,66 +12,47 @@ export namespace CityColumnDescriptors {
58
12
  let maxLength_1: 255;
59
13
  export { maxLength_1 as maxLength };
60
14
  }
61
- export { alias_1 as alias };
62
- export namespace chatapp_category_1 {
15
+ namespace chatapp_category {
63
16
  let type_2: "String";
64
17
  export { type_2 as type };
65
- let nullable_1: true;
66
- export { nullable_1 as nullable };
67
18
  }
68
- export { chatapp_category_1 as chatapp_category };
69
- export namespace chatapp_legacy_1 {
19
+ namespace chatapp_legacy {
70
20
  let type_3: "Boolean";
71
21
  export { type_3 as type };
72
- let nullable_2: true;
73
- export { nullable_2 as nullable };
74
22
  }
75
- export { chatapp_legacy_1 as chatapp_legacy };
76
- export namespace chatapp_line_1 {
23
+ namespace chatapp_line {
77
24
  let type_4: "String";
78
25
  export { type_4 as type };
79
- let nullable_3: true;
80
- export { nullable_3 as nullable };
81
26
  let minLength_2: 1;
82
27
  export { minLength_2 as minLength };
83
28
  let maxLength_2: 255;
84
29
  export { maxLength_2 as maxLength };
85
30
  }
86
- export { chatapp_line_1 as chatapp_line };
87
- export namespace chatapp_tag_1 {
31
+ namespace chatapp_tag {
88
32
  let type_5: "String";
89
33
  export { type_5 as type };
90
- let nullable_4: true;
91
- export { nullable_4 as nullable };
92
34
  let minLength_3: 1;
93
35
  export { minLength_3 as minLength };
94
36
  let maxLength_3: 255;
95
37
  export { maxLength_3 as maxLength };
96
38
  }
97
- export { chatapp_tag_1 as chatapp_tag };
98
- export namespace chatapp_user_1 {
39
+ namespace chatapp_user {
99
40
  let type_6: "String";
100
41
  export { type_6 as type };
101
- let nullable_5: true;
102
- export { nullable_5 as nullable };
103
42
  let minLength_4: 1;
104
43
  export { minLength_4 as minLength };
105
44
  let maxLength_4: 255;
106
45
  export { maxLength_4 as maxLength };
107
46
  }
108
- export { chatapp_user_1 as chatapp_user };
109
- export namespace country_1 {
47
+ namespace country {
110
48
  let type_7: "String";
111
49
  export { type_7 as type };
112
- let nullable_6: true;
113
- export { nullable_6 as nullable };
114
50
  let minLength_5: 2;
115
51
  export { minLength_5 as minLength };
116
52
  let maxLength_5: 2;
117
53
  export { maxLength_5 as maxLength };
118
54
  }
119
- export { country_1 as country };
120
- export namespace currency_1 {
55
+ namespace currency {
121
56
  let type_8: "String";
122
57
  export { type_8 as type };
123
58
  let minLength_6: 3;
@@ -125,148 +60,103 @@ export namespace CityColumnDescriptors {
125
60
  let maxLength_6: 3;
126
61
  export { maxLength_6 as maxLength };
127
62
  }
128
- export { currency_1 as currency };
129
- export namespace custom_html_1 {
63
+ namespace custom_html {
130
64
  let type_9: "String";
131
65
  export { type_9 as type };
132
- let nullable_7: true;
133
- export { nullable_7 as nullable };
134
66
  }
135
- export { custom_html_1 as custom_html };
136
- export namespace custom_script_1 {
67
+ namespace custom_script {
137
68
  let type_10: "String";
138
69
  export { type_10 as type };
139
- let nullable_8: true;
140
- export { nullable_8 as nullable };
141
70
  }
142
- export { custom_script_1 as custom_script };
143
- export namespace description_1 {
71
+ namespace description {
144
72
  let type_11: "String";
145
73
  export { type_11 as type };
146
- let nullable_9: true;
147
- export { nullable_9 as nullable };
148
74
  let minLength_7: 1;
149
75
  export { minLength_7 as minLength };
150
76
  let maxLength_7: 255;
151
77
  export { maxLength_7 as maxLength };
152
78
  }
153
- export { description_1 as description };
154
- export namespace email_1 {
79
+ namespace email {
155
80
  let type_12: "String";
156
81
  export { type_12 as type };
157
- let nullable_10: true;
158
- export { nullable_10 as nullable };
159
82
  let minLength_8: 1;
160
83
  export { minLength_8 as minLength };
161
84
  let maxLength_8: 255;
162
85
  export { maxLength_8 as maxLength };
163
86
  export let format: "email";
164
87
  }
165
- export { email_1 as email };
166
- export namespace game_time_1 {
88
+ namespace game_time {
167
89
  let type_13: "String";
168
90
  export { type_13 as type };
169
91
  let format_1: "time";
170
92
  export { format_1 as format };
171
93
  }
172
- export { game_time_1 as game_time };
173
- export namespace id_1 {
94
+ namespace id {
174
95
  let type_14: "String";
175
96
  export { type_14 as type };
176
- let nullable_11: true;
177
- export { nullable_11 as nullable };
178
97
  let format_2: "uuid";
179
98
  export { format_2 as format };
180
99
  }
181
- export { id_1 as id };
182
- export namespace inst_comment_1 {
100
+ namespace inst_comment {
183
101
  let type_15: "String";
184
102
  export { type_15 as type };
185
- let nullable_12: true;
186
- export { nullable_12 as nullable };
187
103
  export let deprecated: true;
188
104
  }
189
- export { inst_comment_1 as inst_comment };
190
- export namespace inst_link_1 {
105
+ namespace inst_link {
191
106
  let type_16: "String";
192
107
  export { type_16 as type };
193
- let nullable_13: true;
194
- export { nullable_13 as nullable };
195
108
  let deprecated_1: true;
196
109
  export { deprecated_1 as deprecated };
197
110
  }
198
- export { inst_link_1 as inst_link };
199
- export namespace inst_login_1 {
111
+ namespace inst_login {
200
112
  let type_17: "String";
201
113
  export { type_17 as type };
202
- let nullable_14: true;
203
- export { nullable_14 as nullable };
204
114
  let deprecated_2: true;
205
115
  export { deprecated_2 as deprecated };
206
116
  }
207
- export { inst_login_1 as inst_login };
208
- export namespace inst_password_1 {
117
+ namespace inst_password {
209
118
  let type_18: "String";
210
119
  export { type_18 as type };
211
- let nullable_15: true;
212
- export { nullable_15 as nullable };
213
120
  let deprecated_3: true;
214
121
  export { deprecated_3 as deprecated };
215
122
  }
216
- export { inst_password_1 as inst_password };
217
- export namespace is_default_1 {
123
+ namespace is_default {
218
124
  let type_19: "Boolean";
219
125
  export { type_19 as type };
220
- let nullable_16: true;
221
- export { nullable_16 as nullable };
222
126
  }
223
- export { is_default_1 as is_default };
224
- export namespace is_franchise_1 {
127
+ namespace is_franchise {
225
128
  let type_20: "Boolean";
226
129
  export { type_20 as type };
227
130
  }
228
- export { is_franchise_1 as is_franchise };
229
- export namespace max_members_count_1 {
131
+ namespace max_members_count {
230
132
  let type_21: "Number";
231
133
  export { type_21 as type };
232
- let nullable_17: true;
233
- export { nullable_17 as nullable };
234
134
  let format_3: "integer";
235
135
  export { format_3 as format };
236
136
  }
237
- export { max_members_count_1 as max_members_count };
238
- export namespace meta_description_1 {
137
+ namespace meta_description {
239
138
  let type_22: "String";
240
139
  export { type_22 as type };
241
- let nullable_18: true;
242
- export { nullable_18 as nullable };
243
140
  let minLength_9: 1;
244
141
  export { minLength_9 as minLength };
245
142
  let maxLength_9: 255;
246
143
  export { maxLength_9 as maxLength };
247
144
  }
248
- export { meta_description_1 as meta_description };
249
- export namespace meta_title_1 {
145
+ namespace meta_title {
250
146
  let type_23: "String";
251
147
  export { type_23 as type };
252
- let nullable_19: true;
253
- export { nullable_19 as nullable };
254
148
  let minLength_10: 1;
255
149
  export { minLength_10 as minLength };
256
150
  let maxLength_10: 255;
257
151
  export { maxLength_10 as maxLength };
258
152
  }
259
- export { meta_title_1 as meta_title };
260
- export namespace min_members_count_1 {
153
+ namespace min_members_count {
261
154
  let type_24: "Number";
262
155
  export { type_24 as type };
263
- let nullable_20: true;
264
- export { nullable_20 as nullable };
265
156
  let format_4: "integer";
266
157
  export { format_4 as format };
267
158
  }
268
- export { min_members_count_1 as min_members_count };
269
- export namespace name_1 {
159
+ namespace name {
270
160
  let type_25: "String";
271
161
  export { type_25 as type };
272
162
  let minLength_11: 1;
@@ -274,76 +164,55 @@ export namespace CityColumnDescriptors {
274
164
  let maxLength_11: 255;
275
165
  export { maxLength_11 as maxLength };
276
166
  }
277
- export { name_1 as name };
278
- export namespace phone_1 {
167
+ namespace phone {
279
168
  let type_26: "String";
280
169
  export { type_26 as type };
281
- let nullable_21: true;
282
- export { nullable_21 as nullable };
283
170
  let minLength_12: 1;
284
171
  export { minLength_12 as minLength };
285
172
  let maxLength_12: 255;
286
173
  export { maxLength_12 as maxLength };
287
174
  }
288
- export { phone_1 as phone };
289
- export namespace price_1 {
290
- let type_27: "String";
175
+ namespace price {
176
+ let type_27: "Number";
291
177
  export { type_27 as type };
292
- let nullable_22: true;
293
- export { nullable_22 as nullable };
294
178
  let format_5: "float";
295
179
  export { format_5 as format };
296
180
  }
297
- export { price_1 as price };
298
- export namespace region_1 {
181
+ namespace region {
299
182
  let type_28: "String";
300
183
  export { type_28 as type };
301
- let nullable_23: true;
302
- export { nullable_23 as nullable };
303
184
  let minLength_13: 1;
304
185
  export { minLength_13 as minLength };
305
186
  let maxLength_13: 255;
306
187
  export { maxLength_13 as maxLength };
307
188
  }
308
- export { region_1 as region };
309
- export namespace telegram_chat_id_1 {
189
+ namespace telegram_chat_id {
310
190
  let type_29: "String";
311
191
  export { type_29 as type };
312
- let nullable_24: true;
313
- export { nullable_24 as nullable };
314
192
  let minLength_14: 1;
315
193
  export { minLength_14 as minLength };
316
194
  let maxLength_14: 255;
317
195
  export { maxLength_14 as maxLength };
318
196
  }
319
- export { telegram_chat_id_1 as telegram_chat_id };
320
- export namespace tg_comment_1 {
197
+ namespace tg_comment {
321
198
  let type_30: "String";
322
199
  export { type_30 as type };
323
- let nullable_25: true;
324
- export { nullable_25 as nullable };
325
200
  let minLength_15: 1;
326
201
  export { minLength_15 as minLength };
327
202
  let maxLength_15: 255;
328
203
  export { maxLength_15 as maxLength };
329
204
  }
330
- export { tg_comment_1 as tg_comment };
331
- export namespace tg_link_1 {
205
+ namespace tg_link {
332
206
  let type_31: "String";
333
207
  export { type_31 as type };
334
- let nullable_26: true;
335
- export { nullable_26 as nullable };
336
208
  let minLength_16: 1;
337
209
  export { minLength_16 as minLength };
338
210
  let maxLength_16: 255;
339
211
  export { maxLength_16 as maxLength };
340
212
  }
341
- export { tg_link_1 as tg_link };
342
- export namespace tg_login_1 {
213
+ namespace tg_login {
343
214
  let type_32: "String";
344
215
  export { type_32 as type };
345
- let nullable_27: true;
346
- export { nullable_27 as nullable };
347
216
  let deprecated_4: true;
348
217
  export { deprecated_4 as deprecated };
349
218
  let minLength_17: 1;
@@ -351,12 +220,9 @@ export namespace CityColumnDescriptors {
351
220
  let maxLength_17: 255;
352
221
  export { maxLength_17 as maxLength };
353
222
  }
354
- export { tg_login_1 as tg_login };
355
- export namespace tg_password_1 {
223
+ namespace tg_password {
356
224
  let type_33: "String";
357
225
  export { type_33 as type };
358
- let nullable_28: true;
359
- export { nullable_28 as nullable };
360
226
  let deprecated_5: true;
361
227
  export { deprecated_5 as deprecated };
362
228
  let minLength_18: 1;
@@ -364,71 +230,46 @@ export namespace CityColumnDescriptors {
364
230
  let maxLength_18: 255;
365
231
  export { maxLength_18 as maxLength };
366
232
  }
367
- export { tg_password_1 as tg_password };
368
- export namespace time_created_1 {
233
+ namespace time_created {
369
234
  let type_34: "String";
370
235
  export { type_34 as type };
371
- let nullable_29: true;
372
- export { nullable_29 as nullable };
373
236
  let format_6: "Date";
374
237
  export { format_6 as format };
375
238
  }
376
- export { time_created_1 as time_created };
377
- export namespace time_updated_1 {
239
+ namespace time_updated {
378
240
  let type_35: "String";
379
241
  export { type_35 as type };
380
- let nullable_30: true;
381
- export { nullable_30 as nullable };
382
242
  let format_7: "Date";
383
243
  export { format_7 as format };
384
244
  }
385
- export { time_updated_1 as time_updated };
386
- export namespace timezone_1 {
245
+ namespace timezone {
387
246
  let type_36: "String";
388
247
  export { type_36 as type };
389
- let nullable_31: true;
390
- export { nullable_31 as nullable };
391
248
  let format_8: "integer";
392
249
  export { format_8 as format };
393
250
  }
394
- export { timezone_1 as timezone };
395
- export namespace title_1 {
251
+ namespace title {
396
252
  let type_37: "String";
397
253
  export { type_37 as type };
398
- let nullable_32: true;
399
- export { nullable_32 as nullable };
400
254
  let minLength_19: 1;
401
255
  export { minLength_19 as minLength };
402
256
  let maxLength_19: 255;
403
257
  export { maxLength_19 as maxLength };
404
258
  }
405
- export { title_1 as title };
406
- export namespace vk_comment_1 {
259
+ namespace vk_comment {
407
260
  let type_38: "String";
408
261
  export { type_38 as type };
409
- let nullable_33: true;
410
- export { nullable_33 as nullable };
411
262
  }
412
- export { vk_comment_1 as vk_comment };
413
- export namespace vk_group_id_1 {
263
+ namespace vk_group_id {
414
264
  let type_39: "String";
415
265
  export { type_39 as type };
416
- let nullable_34: true;
417
- export { nullable_34 as nullable };
418
266
  }
419
- export { vk_group_id_1 as vk_group_id };
420
- export namespace vk_link_1 {
267
+ namespace vk_link {
421
268
  let type_40: "String";
422
269
  export { type_40 as type };
423
- let nullable_35: true;
424
- export { nullable_35 as nullable };
425
270
  }
426
- export { vk_link_1 as vk_link };
427
- export namespace yandex_metrica_1 {
271
+ namespace yandex_metrica {
428
272
  let type_41: "String";
429
273
  export { type_41 as type };
430
- let nullable_36: true;
431
- export { nullable_36 as nullable };
432
274
  }
433
- export { yandex_metrica_1 as yandex_metrica };
434
275
  }