@shakerquiz/utilities 0.3.35 → 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.35",
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,55 +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
4
  let minLength: 1;
49
5
  let maxLength: 255;
50
6
  }
51
- export { address_1 as address };
52
- export namespace alias_1 {
7
+ namespace alias {
53
8
  let type_1: "String";
54
9
  export { type_1 as type };
55
10
  let minLength_1: 1;
@@ -57,18 +12,15 @@ export namespace CityColumnDescriptors {
57
12
  let maxLength_1: 255;
58
13
  export { maxLength_1 as maxLength };
59
14
  }
60
- export { alias_1 as alias };
61
- export namespace chatapp_category_1 {
15
+ namespace chatapp_category {
62
16
  let type_2: "String";
63
17
  export { type_2 as type };
64
18
  }
65
- export { chatapp_category_1 as chatapp_category };
66
- export namespace chatapp_legacy_1 {
19
+ namespace chatapp_legacy {
67
20
  let type_3: "Boolean";
68
21
  export { type_3 as type };
69
22
  }
70
- export { chatapp_legacy_1 as chatapp_legacy };
71
- export namespace chatapp_line_1 {
23
+ namespace chatapp_line {
72
24
  let type_4: "String";
73
25
  export { type_4 as type };
74
26
  let minLength_2: 1;
@@ -76,8 +28,7 @@ export namespace CityColumnDescriptors {
76
28
  let maxLength_2: 255;
77
29
  export { maxLength_2 as maxLength };
78
30
  }
79
- export { chatapp_line_1 as chatapp_line };
80
- export namespace chatapp_tag_1 {
31
+ namespace chatapp_tag {
81
32
  let type_5: "String";
82
33
  export { type_5 as type };
83
34
  let minLength_3: 1;
@@ -85,8 +36,7 @@ export namespace CityColumnDescriptors {
85
36
  let maxLength_3: 255;
86
37
  export { maxLength_3 as maxLength };
87
38
  }
88
- export { chatapp_tag_1 as chatapp_tag };
89
- export namespace chatapp_user_1 {
39
+ namespace chatapp_user {
90
40
  let type_6: "String";
91
41
  export { type_6 as type };
92
42
  let minLength_4: 1;
@@ -94,8 +44,7 @@ export namespace CityColumnDescriptors {
94
44
  let maxLength_4: 255;
95
45
  export { maxLength_4 as maxLength };
96
46
  }
97
- export { chatapp_user_1 as chatapp_user };
98
- export namespace country_1 {
47
+ namespace country {
99
48
  let type_7: "String";
100
49
  export { type_7 as type };
101
50
  let minLength_5: 2;
@@ -103,8 +52,7 @@ export namespace CityColumnDescriptors {
103
52
  let maxLength_5: 2;
104
53
  export { maxLength_5 as maxLength };
105
54
  }
106
- export { country_1 as country };
107
- export namespace currency_1 {
55
+ namespace currency {
108
56
  let type_8: "String";
109
57
  export { type_8 as type };
110
58
  let minLength_6: 3;
@@ -112,18 +60,15 @@ export namespace CityColumnDescriptors {
112
60
  let maxLength_6: 3;
113
61
  export { maxLength_6 as maxLength };
114
62
  }
115
- export { currency_1 as currency };
116
- export namespace custom_html_1 {
63
+ namespace custom_html {
117
64
  let type_9: "String";
118
65
  export { type_9 as type };
119
66
  }
120
- export { custom_html_1 as custom_html };
121
- export namespace custom_script_1 {
67
+ namespace custom_script {
122
68
  let type_10: "String";
123
69
  export { type_10 as type };
124
70
  }
125
- export { custom_script_1 as custom_script };
126
- export namespace description_1 {
71
+ namespace description {
127
72
  let type_11: "String";
128
73
  export { type_11 as type };
129
74
  let minLength_7: 1;
@@ -131,8 +76,7 @@ export namespace CityColumnDescriptors {
131
76
  let maxLength_7: 255;
132
77
  export { maxLength_7 as maxLength };
133
78
  }
134
- export { description_1 as description };
135
- export namespace email_1 {
79
+ namespace email {
136
80
  let type_12: "String";
137
81
  export { type_12 as type };
138
82
  let minLength_8: 1;
@@ -141,66 +85,56 @@ export namespace CityColumnDescriptors {
141
85
  export { maxLength_8 as maxLength };
142
86
  export let format: "email";
143
87
  }
144
- export { email_1 as email };
145
- export namespace game_time_1 {
88
+ namespace game_time {
146
89
  let type_13: "String";
147
90
  export { type_13 as type };
148
91
  let format_1: "time";
149
92
  export { format_1 as format };
150
93
  }
151
- export { game_time_1 as game_time };
152
- export namespace id_1 {
94
+ namespace id {
153
95
  let type_14: "String";
154
96
  export { type_14 as type };
155
97
  let format_2: "uuid";
156
98
  export { format_2 as format };
157
99
  }
158
- export { id_1 as id };
159
- export namespace inst_comment_1 {
100
+ namespace inst_comment {
160
101
  let type_15: "String";
161
102
  export { type_15 as type };
162
103
  export let deprecated: true;
163
104
  }
164
- export { inst_comment_1 as inst_comment };
165
- export namespace inst_link_1 {
105
+ namespace inst_link {
166
106
  let type_16: "String";
167
107
  export { type_16 as type };
168
108
  let deprecated_1: true;
169
109
  export { deprecated_1 as deprecated };
170
110
  }
171
- export { inst_link_1 as inst_link };
172
- export namespace inst_login_1 {
111
+ namespace inst_login {
173
112
  let type_17: "String";
174
113
  export { type_17 as type };
175
114
  let deprecated_2: true;
176
115
  export { deprecated_2 as deprecated };
177
116
  }
178
- export { inst_login_1 as inst_login };
179
- export namespace inst_password_1 {
117
+ namespace inst_password {
180
118
  let type_18: "String";
181
119
  export { type_18 as type };
182
120
  let deprecated_3: true;
183
121
  export { deprecated_3 as deprecated };
184
122
  }
185
- export { inst_password_1 as inst_password };
186
- export namespace is_default_1 {
123
+ namespace is_default {
187
124
  let type_19: "Boolean";
188
125
  export { type_19 as type };
189
126
  }
190
- export { is_default_1 as is_default };
191
- export namespace is_franchise_1 {
127
+ namespace is_franchise {
192
128
  let type_20: "Boolean";
193
129
  export { type_20 as type };
194
130
  }
195
- export { is_franchise_1 as is_franchise };
196
- export namespace max_members_count_1 {
131
+ namespace max_members_count {
197
132
  let type_21: "Number";
198
133
  export { type_21 as type };
199
134
  let format_3: "integer";
200
135
  export { format_3 as format };
201
136
  }
202
- export { max_members_count_1 as max_members_count };
203
- export namespace meta_description_1 {
137
+ namespace meta_description {
204
138
  let type_22: "String";
205
139
  export { type_22 as type };
206
140
  let minLength_9: 1;
@@ -208,8 +142,7 @@ export namespace CityColumnDescriptors {
208
142
  let maxLength_9: 255;
209
143
  export { maxLength_9 as maxLength };
210
144
  }
211
- export { meta_description_1 as meta_description };
212
- export namespace meta_title_1 {
145
+ namespace meta_title {
213
146
  let type_23: "String";
214
147
  export { type_23 as type };
215
148
  let minLength_10: 1;
@@ -217,15 +150,13 @@ export namespace CityColumnDescriptors {
217
150
  let maxLength_10: 255;
218
151
  export { maxLength_10 as maxLength };
219
152
  }
220
- export { meta_title_1 as meta_title };
221
- export namespace min_members_count_1 {
153
+ namespace min_members_count {
222
154
  let type_24: "Number";
223
155
  export { type_24 as type };
224
156
  let format_4: "integer";
225
157
  export { format_4 as format };
226
158
  }
227
- export { min_members_count_1 as min_members_count };
228
- export namespace name_1 {
159
+ namespace name {
229
160
  let type_25: "String";
230
161
  export { type_25 as type };
231
162
  let minLength_11: 1;
@@ -233,8 +164,7 @@ export namespace CityColumnDescriptors {
233
164
  let maxLength_11: 255;
234
165
  export { maxLength_11 as maxLength };
235
166
  }
236
- export { name_1 as name };
237
- export namespace phone_1 {
167
+ namespace phone {
238
168
  let type_26: "String";
239
169
  export { type_26 as type };
240
170
  let minLength_12: 1;
@@ -242,15 +172,13 @@ export namespace CityColumnDescriptors {
242
172
  let maxLength_12: 255;
243
173
  export { maxLength_12 as maxLength };
244
174
  }
245
- export { phone_1 as phone };
246
- export namespace price_1 {
175
+ namespace price {
247
176
  let type_27: "Number";
248
177
  export { type_27 as type };
249
178
  let format_5: "float";
250
179
  export { format_5 as format };
251
180
  }
252
- export { price_1 as price };
253
- export namespace region_1 {
181
+ namespace region {
254
182
  let type_28: "String";
255
183
  export { type_28 as type };
256
184
  let minLength_13: 1;
@@ -258,8 +186,7 @@ export namespace CityColumnDescriptors {
258
186
  let maxLength_13: 255;
259
187
  export { maxLength_13 as maxLength };
260
188
  }
261
- export { region_1 as region };
262
- export namespace telegram_chat_id_1 {
189
+ namespace telegram_chat_id {
263
190
  let type_29: "String";
264
191
  export { type_29 as type };
265
192
  let minLength_14: 1;
@@ -267,8 +194,7 @@ export namespace CityColumnDescriptors {
267
194
  let maxLength_14: 255;
268
195
  export { maxLength_14 as maxLength };
269
196
  }
270
- export { telegram_chat_id_1 as telegram_chat_id };
271
- export namespace tg_comment_1 {
197
+ namespace tg_comment {
272
198
  let type_30: "String";
273
199
  export { type_30 as type };
274
200
  let minLength_15: 1;
@@ -276,8 +202,7 @@ export namespace CityColumnDescriptors {
276
202
  let maxLength_15: 255;
277
203
  export { maxLength_15 as maxLength };
278
204
  }
279
- export { tg_comment_1 as tg_comment };
280
- export namespace tg_link_1 {
205
+ namespace tg_link {
281
206
  let type_31: "String";
282
207
  export { type_31 as type };
283
208
  let minLength_16: 1;
@@ -285,8 +210,7 @@ export namespace CityColumnDescriptors {
285
210
  let maxLength_16: 255;
286
211
  export { maxLength_16 as maxLength };
287
212
  }
288
- export { tg_link_1 as tg_link };
289
- export namespace tg_login_1 {
213
+ namespace tg_login {
290
214
  let type_32: "String";
291
215
  export { type_32 as type };
292
216
  let deprecated_4: true;
@@ -296,8 +220,7 @@ export namespace CityColumnDescriptors {
296
220
  let maxLength_17: 255;
297
221
  export { maxLength_17 as maxLength };
298
222
  }
299
- export { tg_login_1 as tg_login };
300
- export namespace tg_password_1 {
223
+ namespace tg_password {
301
224
  let type_33: "String";
302
225
  export { type_33 as type };
303
226
  let deprecated_5: true;
@@ -307,29 +230,25 @@ export namespace CityColumnDescriptors {
307
230
  let maxLength_18: 255;
308
231
  export { maxLength_18 as maxLength };
309
232
  }
310
- export { tg_password_1 as tg_password };
311
- export namespace time_created_1 {
233
+ namespace time_created {
312
234
  let type_34: "String";
313
235
  export { type_34 as type };
314
236
  let format_6: "Date";
315
237
  export { format_6 as format };
316
238
  }
317
- export { time_created_1 as time_created };
318
- export namespace time_updated_1 {
239
+ namespace time_updated {
319
240
  let type_35: "String";
320
241
  export { type_35 as type };
321
242
  let format_7: "Date";
322
243
  export { format_7 as format };
323
244
  }
324
- export { time_updated_1 as time_updated };
325
- export namespace timezone_1 {
245
+ namespace timezone {
326
246
  let type_36: "String";
327
247
  export { type_36 as type };
328
248
  let format_8: "integer";
329
249
  export { format_8 as format };
330
250
  }
331
- export { timezone_1 as timezone };
332
- export namespace title_1 {
251
+ namespace title {
333
252
  let type_37: "String";
334
253
  export { type_37 as type };
335
254
  let minLength_19: 1;
@@ -337,25 +256,20 @@ export namespace CityColumnDescriptors {
337
256
  let maxLength_19: 255;
338
257
  export { maxLength_19 as maxLength };
339
258
  }
340
- export { title_1 as title };
341
- export namespace vk_comment_1 {
259
+ namespace vk_comment {
342
260
  let type_38: "String";
343
261
  export { type_38 as type };
344
262
  }
345
- export { vk_comment_1 as vk_comment };
346
- export namespace vk_group_id_1 {
263
+ namespace vk_group_id {
347
264
  let type_39: "String";
348
265
  export { type_39 as type };
349
266
  }
350
- export { vk_group_id_1 as vk_group_id };
351
- export namespace vk_link_1 {
267
+ namespace vk_link {
352
268
  let type_40: "String";
353
269
  export { type_40 as type };
354
270
  }
355
- export { vk_link_1 as vk_link };
356
- export namespace yandex_metrica_1 {
271
+ namespace yandex_metrica {
357
272
  let type_41: "String";
358
273
  export { type_41 as type };
359
274
  }
360
- export { yandex_metrica_1 as yandex_metrica };
361
275
  }