@e22m4u/ts-rest-router 0.2.3 → 0.2.4

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.
@@ -309,6 +309,9 @@ function createRequestDataPropertyDecoratorWithSource(source) {
309
309
  } else if (typeof schemaOrType === "string") {
310
310
  properties[propertyKey] = { type: schemaOrType };
311
311
  rootSchema.properties = properties;
312
+ } else {
313
+ properties[propertyKey] = { type: import_ts_data_schema.DataType.ANY };
314
+ rootSchema.properties = properties;
312
315
  }
313
316
  return requestData({
314
317
  source,
@@ -45,6 +45,10 @@ function createRequestDataPropertyDecoratorWithSource(source) {
45
45
  properties[propertyKey] = { type: schemaOrType };
46
46
  rootSchema.properties = properties;
47
47
  }
48
+ else {
49
+ properties[propertyKey] = { type: DataType.ANY };
50
+ rootSchema.properties = properties;
51
+ }
48
52
  return requestData({
49
53
  source: source,
50
54
  schema: rootSchema,
@@ -186,11 +186,12 @@ describe('requestData', function () {
186
186
  describe('request data piece by a given property key', function () {
187
187
  describe('param', function () {
188
188
  it('sets a given "propertyKey" to the target metadata', function () {
189
+ const propertyKey = 'myPropertyKey';
189
190
  class Target {
190
191
  myMethod(prop) { }
191
192
  }
192
193
  __decorate([
193
- __param(0, requestParam('myPropertyKey')),
194
+ __param(0, requestParam(propertyKey)),
194
195
  __metadata("design:type", Function),
195
196
  __metadata("design:paramtypes", [Object]),
196
197
  __metadata("design:returntype", void 0)
@@ -198,8 +199,15 @@ describe('requestData', function () {
198
199
  const res = RequestDataReflector.getMetadata(Target, 'myMethod');
199
200
  expect(res.get(0)).to.be.eql({
200
201
  source: RequestDataSource.PARAMS,
201
- schema: { type: DataType.OBJECT },
202
- property: 'myPropertyKey',
202
+ schema: {
203
+ type: DataType.OBJECT,
204
+ properties: {
205
+ [propertyKey]: {
206
+ type: DataType.ANY,
207
+ },
208
+ },
209
+ },
210
+ property: propertyKey,
203
211
  });
204
212
  });
205
213
  it('sets a given DataType as property type', function () {
@@ -258,11 +266,12 @@ describe('requestData', function () {
258
266
  });
259
267
  describe('query', function () {
260
268
  it('sets a given "propertyKey" to the target metadata', function () {
269
+ const propertyKey = 'myPropertyKey';
261
270
  class Target {
262
271
  myMethod(prop) { }
263
272
  }
264
273
  __decorate([
265
- __param(0, requestQuery('myPropertyKey')),
274
+ __param(0, requestQuery(propertyKey)),
266
275
  __metadata("design:type", Function),
267
276
  __metadata("design:paramtypes", [Object]),
268
277
  __metadata("design:returntype", void 0)
@@ -270,8 +279,15 @@ describe('requestData', function () {
270
279
  const res = RequestDataReflector.getMetadata(Target, 'myMethod');
271
280
  expect(res.get(0)).to.be.eql({
272
281
  source: RequestDataSource.QUERY,
273
- schema: { type: DataType.OBJECT },
274
- property: 'myPropertyKey',
282
+ schema: {
283
+ type: DataType.OBJECT,
284
+ properties: {
285
+ [propertyKey]: {
286
+ type: DataType.ANY,
287
+ },
288
+ },
289
+ },
290
+ property: propertyKey,
275
291
  });
276
292
  });
277
293
  it('sets a given DataType as property type', function () {
@@ -330,11 +346,12 @@ describe('requestData', function () {
330
346
  });
331
347
  describe('header', function () {
332
348
  it('sets a given "propertyKey" to the target metadata', function () {
349
+ const propertyKey = 'myPropertyKey';
333
350
  class Target {
334
351
  myMethod(prop) { }
335
352
  }
336
353
  __decorate([
337
- __param(0, requestHeader('myPropertyKey')),
354
+ __param(0, requestHeader(propertyKey)),
338
355
  __metadata("design:type", Function),
339
356
  __metadata("design:paramtypes", [Object]),
340
357
  __metadata("design:returntype", void 0)
@@ -342,8 +359,15 @@ describe('requestData', function () {
342
359
  const res = RequestDataReflector.getMetadata(Target, 'myMethod');
343
360
  expect(res.get(0)).to.be.eql({
344
361
  source: RequestDataSource.HEADERS,
345
- schema: { type: DataType.OBJECT },
346
- property: 'myPropertyKey',
362
+ schema: {
363
+ type: DataType.OBJECT,
364
+ properties: {
365
+ [propertyKey]: {
366
+ type: DataType.ANY,
367
+ },
368
+ },
369
+ },
370
+ property: propertyKey,
347
371
  });
348
372
  });
349
373
  it('sets a given DataType as property type', function () {
@@ -402,11 +426,12 @@ describe('requestData', function () {
402
426
  });
403
427
  describe('cookie', function () {
404
428
  it('sets a given "propertyKey" to the target metadata', function () {
429
+ const propertyKey = 'myPropertyKey';
405
430
  class Target {
406
431
  myMethod(prop) { }
407
432
  }
408
433
  __decorate([
409
- __param(0, requestCookie('myPropertyKey')),
434
+ __param(0, requestCookie(propertyKey)),
410
435
  __metadata("design:type", Function),
411
436
  __metadata("design:paramtypes", [Object]),
412
437
  __metadata("design:returntype", void 0)
@@ -414,8 +439,15 @@ describe('requestData', function () {
414
439
  const res = RequestDataReflector.getMetadata(Target, 'myMethod');
415
440
  expect(res.get(0)).to.be.eql({
416
441
  source: RequestDataSource.COOKIE,
417
- schema: { type: DataType.OBJECT },
418
- property: 'myPropertyKey',
442
+ schema: {
443
+ type: DataType.OBJECT,
444
+ properties: {
445
+ [propertyKey]: {
446
+ type: DataType.ANY,
447
+ },
448
+ },
449
+ },
450
+ property: propertyKey,
419
451
  });
420
452
  });
421
453
  it('sets a given DataType as property type', function () {
@@ -474,11 +506,12 @@ describe('requestData', function () {
474
506
  });
475
507
  describe('field', function () {
476
508
  it('sets a given "propertyKey" to the target metadata', function () {
509
+ const propertyKey = 'myPropertyKey';
477
510
  class Target {
478
511
  myMethod(prop) { }
479
512
  }
480
513
  __decorate([
481
- __param(0, requestField('myPropertyKey')),
514
+ __param(0, requestField(propertyKey)),
482
515
  __metadata("design:type", Function),
483
516
  __metadata("design:paramtypes", [Object]),
484
517
  __metadata("design:returntype", void 0)
@@ -486,8 +519,15 @@ describe('requestData', function () {
486
519
  const res = RequestDataReflector.getMetadata(Target, 'myMethod');
487
520
  expect(res.get(0)).to.be.eql({
488
521
  source: RequestDataSource.BODY,
489
- schema: { type: DataType.OBJECT },
490
- property: 'myPropertyKey',
522
+ schema: {
523
+ type: DataType.OBJECT,
524
+ properties: {
525
+ [propertyKey]: {
526
+ type: DataType.ANY,
527
+ },
528
+ },
529
+ },
530
+ property: propertyKey,
491
531
  });
492
532
  });
493
533
  it('sets a given DataType as property type', function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e22m4u/ts-rest-router",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "REST маршрутизатор на основе контроллеров для TypeScript",
5
5
  "author": "e22m4u <e22m4u@yandex.ru>",
6
6
  "license": "MIT",
@@ -160,17 +160,25 @@ describe('requestData', function () {
160
160
  describe('request data piece by a given property key', function () {
161
161
  describe('param', function () {
162
162
  it('sets a given "propertyKey" to the target metadata', function () {
163
+ const propertyKey = 'myPropertyKey';
163
164
  class Target {
164
165
  myMethod(
165
- @requestParam('myPropertyKey')
166
+ @requestParam(propertyKey)
166
167
  prop: unknown,
167
168
  ) {}
168
169
  }
169
170
  const res = RequestDataReflector.getMetadata(Target, 'myMethod');
170
171
  expect(res.get(0)).to.be.eql({
171
172
  source: RequestDataSource.PARAMS,
172
- schema: {type: DataType.OBJECT},
173
- property: 'myPropertyKey',
173
+ schema: {
174
+ type: DataType.OBJECT,
175
+ properties: {
176
+ [propertyKey]: {
177
+ type: DataType.ANY,
178
+ },
179
+ },
180
+ },
181
+ property: propertyKey,
174
182
  });
175
183
  });
176
184
 
@@ -226,17 +234,25 @@ describe('requestData', function () {
226
234
 
227
235
  describe('query', function () {
228
236
  it('sets a given "propertyKey" to the target metadata', function () {
237
+ const propertyKey = 'myPropertyKey';
229
238
  class Target {
230
239
  myMethod(
231
- @requestQuery('myPropertyKey')
240
+ @requestQuery(propertyKey)
232
241
  prop: unknown,
233
242
  ) {}
234
243
  }
235
244
  const res = RequestDataReflector.getMetadata(Target, 'myMethod');
236
245
  expect(res.get(0)).to.be.eql({
237
246
  source: RequestDataSource.QUERY,
238
- schema: {type: DataType.OBJECT},
239
- property: 'myPropertyKey',
247
+ schema: {
248
+ type: DataType.OBJECT,
249
+ properties: {
250
+ [propertyKey]: {
251
+ type: DataType.ANY,
252
+ },
253
+ },
254
+ },
255
+ property: propertyKey,
240
256
  });
241
257
  });
242
258
 
@@ -292,17 +308,25 @@ describe('requestData', function () {
292
308
 
293
309
  describe('header', function () {
294
310
  it('sets a given "propertyKey" to the target metadata', function () {
311
+ const propertyKey = 'myPropertyKey';
295
312
  class Target {
296
313
  myMethod(
297
- @requestHeader('myPropertyKey')
314
+ @requestHeader(propertyKey)
298
315
  prop: unknown,
299
316
  ) {}
300
317
  }
301
318
  const res = RequestDataReflector.getMetadata(Target, 'myMethod');
302
319
  expect(res.get(0)).to.be.eql({
303
320
  source: RequestDataSource.HEADERS,
304
- schema: {type: DataType.OBJECT},
305
- property: 'myPropertyKey',
321
+ schema: {
322
+ type: DataType.OBJECT,
323
+ properties: {
324
+ [propertyKey]: {
325
+ type: DataType.ANY,
326
+ },
327
+ },
328
+ },
329
+ property: propertyKey,
306
330
  });
307
331
  });
308
332
 
@@ -358,17 +382,25 @@ describe('requestData', function () {
358
382
 
359
383
  describe('cookie', function () {
360
384
  it('sets a given "propertyKey" to the target metadata', function () {
385
+ const propertyKey = 'myPropertyKey';
361
386
  class Target {
362
387
  myMethod(
363
- @requestCookie('myPropertyKey')
388
+ @requestCookie(propertyKey)
364
389
  prop: unknown,
365
390
  ) {}
366
391
  }
367
392
  const res = RequestDataReflector.getMetadata(Target, 'myMethod');
368
393
  expect(res.get(0)).to.be.eql({
369
394
  source: RequestDataSource.COOKIE,
370
- schema: {type: DataType.OBJECT},
371
- property: 'myPropertyKey',
395
+ schema: {
396
+ type: DataType.OBJECT,
397
+ properties: {
398
+ [propertyKey]: {
399
+ type: DataType.ANY,
400
+ },
401
+ },
402
+ },
403
+ property: propertyKey,
372
404
  });
373
405
  });
374
406
 
@@ -424,17 +456,25 @@ describe('requestData', function () {
424
456
 
425
457
  describe('field', function () {
426
458
  it('sets a given "propertyKey" to the target metadata', function () {
459
+ const propertyKey = 'myPropertyKey';
427
460
  class Target {
428
461
  myMethod(
429
- @requestField('myPropertyKey')
462
+ @requestField(propertyKey)
430
463
  prop: unknown,
431
464
  ) {}
432
465
  }
433
466
  const res = RequestDataReflector.getMetadata(Target, 'myMethod');
434
467
  expect(res.get(0)).to.be.eql({
435
468
  source: RequestDataSource.BODY,
436
- schema: {type: DataType.OBJECT},
437
- property: 'myPropertyKey',
469
+ schema: {
470
+ type: DataType.OBJECT,
471
+ properties: {
472
+ [propertyKey]: {
473
+ type: DataType.ANY,
474
+ },
475
+ },
476
+ },
477
+ property: propertyKey,
438
478
  });
439
479
  });
440
480
 
@@ -65,6 +65,9 @@ function createRequestDataPropertyDecoratorWithSource(
65
65
  } else if (typeof schemaOrType === 'string') {
66
66
  properties[propertyKey] = {type: schemaOrType};
67
67
  rootSchema.properties = properties;
68
+ } else {
69
+ properties[propertyKey] = {type: DataType.ANY};
70
+ rootSchema.properties = properties;
68
71
  }
69
72
  return requestData({
70
73
  source: source,