@trayio/tray-schema 4.17.1 → 4.18.1

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.
@@ -4,6 +4,7 @@ export interface LegacyTraySchemaConverterInterface {
4
4
  }
5
5
  export declare class LegacyTraySchemaConverter implements LegacyTraySchemaConverterInterface {
6
6
  convertToLegacySchema(schema: DynamicObject): DynamicObject;
7
+ private transformTag;
7
8
  private transformLookup;
8
9
  private transformLookupInput;
9
10
  private transformEnums;
@@ -1 +1 @@
1
- {"version":3,"file":"LegacyTraySchemaConverter.d.ts","sourceRoot":"","sources":["../../src/schema/LegacyTraySchemaConverter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAExE,MAAM,WAAW,kCAAkC;IAClD,qBAAqB,CAAC,MAAM,EAAE,aAAa,GAAG,aAAa,CAAC;CAC5D;AAED,qBAAa,yBACZ,YAAW,kCAAkC;IAE7C,qBAAqB,CAAC,MAAM,EAAE,aAAa,GAAG,aAAa;IAY3D,OAAO,CAAC,eAAe,CAsBrB;IAEF,OAAO,CAAC,oBAAoB,CAc1B;IAEF,OAAO,CAAC,cAAc,CAoBpB;CACF"}
1
+ {"version":3,"file":"LegacyTraySchemaConverter.d.ts","sourceRoot":"","sources":["../../src/schema/LegacyTraySchemaConverter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAExE,MAAM,WAAW,kCAAkC;IAClD,qBAAqB,CAAC,MAAM,EAAE,aAAa,GAAG,aAAa,CAAC;CAC5D;AAED,qBAAa,yBACZ,YAAW,kCAAkC;IAE7C,qBAAqB,CAAC,MAAM,EAAE,aAAa,GAAG,aAAa;IAa3D,OAAO,CAAC,YAAY,CAwBlB;IAEF,OAAO,CAAC,eAAe,CAsBrB;IAEF,OAAO,CAAC,oBAAoB,CAc1B;IAEF,OAAO,CAAC,cAAc,CAoBpB;CACF"}
@@ -7,11 +7,38 @@ class LegacyTraySchemaConverter {
7
7
  if (typeof value === 'object' && value !== null) {
8
8
  this.transformLookup(value);
9
9
  this.transformEnums(value);
10
+ this.transformTag(value);
10
11
  this.convertToLegacySchema(value);
11
12
  }
12
13
  }
13
14
  return schema;
14
15
  }
16
+ transformTag = (object) => {
17
+ if (typeof object !== 'object' || object === null)
18
+ return object;
19
+ if (object.tag && typeof object.tag === 'string') {
20
+ switch (object.tag) {
21
+ case 'code':
22
+ object.format = 'code';
23
+ delete object.tag;
24
+ break;
25
+ case 'text':
26
+ object.format = 'text';
27
+ delete object.tag;
28
+ break;
29
+ case 'datetime':
30
+ object.format = 'datetime';
31
+ delete object.tag;
32
+ break;
33
+ case 'password':
34
+ object.format = 'password';
35
+ delete object.tag;
36
+ break;
37
+ default:
38
+ break;
39
+ }
40
+ }
41
+ };
15
42
  transformLookup = (object) => {
16
43
  if (typeof object !== 'object' || object === null)
17
44
  return object;
@@ -465,5 +465,65 @@ describe('LegacyTraySchemaConverter', () => {
465
465
  const result = converter.convertToLegacySchema(schema);
466
466
  expect(result).toEqual(expected);
467
467
  });
468
+ it('should convert legacy tags to format', () => {
469
+ const schema = {
470
+ type: 'object',
471
+ properties: {
472
+ details: { type: 'string', tag: 'text' },
473
+ password: { type: 'string', tag: 'password' },
474
+ source: { type: 'string', tag: 'code' },
475
+ created: { type: 'string', tag: 'datetime' },
476
+ tag: { type: 'string', tag: 'text' },
477
+ nested: {
478
+ type: 'object',
479
+ properties: {
480
+ details: { type: 'string', tag: 'text' },
481
+ password: { type: 'string', tag: 'password' },
482
+ source: { type: 'string', tag: 'code' },
483
+ created: { type: 'string', tag: 'datetime' },
484
+ tag: { type: 'string', tag: 'text' },
485
+ },
486
+ additionalProperties: false,
487
+ required: [],
488
+ $schema: 'http://json-schema.org/draft-07/schema#',
489
+ advanced: [],
490
+ },
491
+ },
492
+ additionalProperties: false,
493
+ required: [],
494
+ $schema: 'http://json-schema.org/draft-07/schema#',
495
+ advanced: [],
496
+ };
497
+ const expected = {
498
+ type: 'object',
499
+ properties: {
500
+ details: { type: 'string', format: 'text' },
501
+ password: { type: 'string', format: 'password' },
502
+ source: { type: 'string', format: 'code' },
503
+ created: { type: 'string', format: 'datetime' },
504
+ tag: { type: 'string', format: 'text' },
505
+ nested: {
506
+ type: 'object',
507
+ properties: {
508
+ details: { type: 'string', format: 'text' },
509
+ password: { type: 'string', format: 'password' },
510
+ source: { type: 'string', format: 'code' },
511
+ created: { type: 'string', format: 'datetime' },
512
+ tag: { type: 'string', format: 'text' },
513
+ },
514
+ additionalProperties: false,
515
+ required: [],
516
+ $schema: 'http://json-schema.org/draft-07/schema#',
517
+ advanced: [],
518
+ },
519
+ },
520
+ additionalProperties: false,
521
+ required: [],
522
+ $schema: 'http://json-schema.org/draft-07/schema#',
523
+ advanced: [],
524
+ };
525
+ const result = converter.convertToLegacySchema(schema);
526
+ expect(result).toEqual(expected);
527
+ });
468
528
  });
469
529
  });
@@ -1 +1 @@
1
- {"version":3,"file":"TJSTraySchemaGenerator.d.ts","sourceRoot":"","sources":["../../src/schema/TJSTraySchemaGenerator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAe,MAAM,cAAc,CAAC;AAEnD,OAAO,EAEN,aAAa,EAEb,MAAM,yCAAyC,CAAC;AAEjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,qBAAa,sBAAuB,YAAW,mBAAmB;IACjE,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC;IA2C1E,sBAAsB,CAAC,MAAM,EAAE,aAAa,GAAG,aAAa;CAqK5D"}
1
+ {"version":3,"file":"TJSTraySchemaGenerator.d.ts","sourceRoot":"","sources":["../../src/schema/TJSTraySchemaGenerator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAe,MAAM,cAAc,CAAC;AAEnD,OAAO,EAEN,aAAa,EAEb,MAAM,yCAAyC,CAAC;AAEjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,qBAAa,sBAAuB,YAAW,mBAAmB;IACjE,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC;IA2C1E,sBAAsB,CAAC,MAAM,EAAE,aAAa,GAAG,aAAa;CAsL5D"}
@@ -192,6 +192,23 @@ class TJSTraySchemaGenerator {
192
192
  object.properties = {};
193
193
  object.additionalProperties = false;
194
194
  break;
195
+ case 'code':
196
+ object.type = ['string', 'object'];
197
+ object.tag = 'code';
198
+ object.additionalProperties = true;
199
+ break;
200
+ case 'text':
201
+ object.type = 'string';
202
+ object.tag = 'text';
203
+ break;
204
+ case 'datetime':
205
+ object.type = 'string';
206
+ object.tag = 'datetime';
207
+ break;
208
+ case 'password':
209
+ object.type = 'string';
210
+ object.tag = 'password';
211
+ break;
195
212
  default:
196
213
  break;
197
214
  }
@@ -344,31 +344,6 @@ describe('TJSTraySchemaGenerator', () => {
344
344
  };
345
345
  expect(actual).toEqual(expected);
346
346
  });
347
- it('Generates format properties from JSdoc annotations', () => {
348
- const type = 'Input';
349
- const dirPath = __dirname;
350
- const path = (0, path_1.join)(dirPath, 'format.test.data.ts');
351
- const result = new TJSTraySchemaGenerator_1.TJSTraySchemaGenerator().generateFromType(type, path);
352
- const actual = E.getOrElse((error) => {
353
- console.warn(error);
354
- throw new Error(`Failed to generate JSON schema from type`);
355
- })(result);
356
- const expected = {
357
- type: 'object',
358
- properties: {
359
- timestamp: { format: 'datetime', type: 'string' },
360
- html: { format: 'code', type: 'string' },
361
- longNotes: { format: 'text', type: 'string' },
362
- password: { format: 'password', type: 'string' },
363
- file: { format: 'file', type: 'string' },
364
- },
365
- advanced: [],
366
- required: ['file', 'html', 'longNotes', 'password', 'timestamp'],
367
- additionalProperties: false,
368
- $schema: 'http://json-schema.org/draft-07/schema#',
369
- };
370
- expect(actual).toEqual(expected);
371
- });
372
347
  it('Generates default properties from JSdoc annotations', () => {
373
348
  const type = 'Input';
374
349
  const dirPath = __dirname;
@@ -549,9 +524,34 @@ describe('TJSTraySchemaGenerator', () => {
549
524
  enum: ['NestedConstProperty'],
550
525
  enumLabels: ['Nested Const Property'],
551
526
  },
527
+ nestedTimestamp: {
528
+ type: 'string',
529
+ tag: 'datetime',
530
+ },
531
+ nestedHtml: {
532
+ type: ['string', 'object'],
533
+ tag: 'code',
534
+ additionalProperties: true,
535
+ },
536
+ nestedLongNotes: {
537
+ type: 'string',
538
+ tag: 'text',
539
+ },
540
+ nestedPassword: {
541
+ type: 'string',
542
+ tag: 'password',
543
+ },
552
544
  },
553
545
  additionalProperties: false,
554
- required: ['nestedConstProp', 'nestedObj', 'nestedSchema'],
546
+ required: [
547
+ 'nestedConstProp',
548
+ 'nestedHtml',
549
+ 'nestedLongNotes',
550
+ 'nestedObj',
551
+ 'nestedPassword',
552
+ 'nestedSchema',
553
+ 'nestedTimestamp',
554
+ ],
555
555
  advanced: [],
556
556
  },
557
557
  constProp: {
@@ -559,9 +559,35 @@ describe('TJSTraySchemaGenerator', () => {
559
559
  enum: ['ConstProperty'],
560
560
  enumLabels: ['Const Property'],
561
561
  },
562
+ timestamp: {
563
+ type: 'string',
564
+ tag: 'datetime',
565
+ },
566
+ html: {
567
+ type: ['string', 'object'],
568
+ tag: 'code',
569
+ additionalProperties: true,
570
+ },
571
+ longNotes: {
572
+ type: 'string',
573
+ tag: 'text',
574
+ },
575
+ password: {
576
+ type: 'string',
577
+ tag: 'password',
578
+ },
562
579
  },
563
580
  additionalProperties: false,
564
- required: ['constProp', 'nested', 'obj', 'schema'],
581
+ required: [
582
+ 'constProp',
583
+ 'html',
584
+ 'longNotes',
585
+ 'nested',
586
+ 'obj',
587
+ 'password',
588
+ 'schema',
589
+ 'timestamp',
590
+ ],
565
591
  $schema: 'http://json-schema.org/draft-07/schema#',
566
592
  advanced: [],
567
593
  };
@@ -11,6 +11,22 @@ export type Input = {
11
11
  obj: DynamicObject;
12
12
  nested: Nested;
13
13
  constProp: 'ConstProperty';
14
+ /**
15
+ * @TJS-type datetime
16
+ */
17
+ timestamp: string;
18
+ /**
19
+ * @TJS-type code
20
+ */
21
+ html: string | DynamicObject;
22
+ /**
23
+ * @TJS-type text
24
+ */
25
+ longNotes: string;
26
+ /**
27
+ * @TJS-type password
28
+ */
29
+ password: string;
14
30
  };
15
31
  export type Nested = {
16
32
  /**
@@ -23,5 +39,21 @@ export type Nested = {
23
39
  */
24
40
  nestedObj: DynamicObject;
25
41
  nestedConstProp: 'NestedConstProperty';
42
+ /**
43
+ * @TJS-type datetime
44
+ */
45
+ nestedTimestamp: string;
46
+ /**
47
+ * @TJS-type code
48
+ */
49
+ nestedHtml: string | DynamicObject;
50
+ /**
51
+ * @TJS-type text
52
+ */
53
+ nestedLongNotes: string;
54
+ /**
55
+ * @TJS-type password
56
+ */
57
+ nestedPassword: string;
26
58
  };
27
59
  //# sourceMappingURL=tag.test.data.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tag.test.data.d.ts","sourceRoot":"","sources":["../../src/schema/tag.test.data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAExE,MAAM,MAAM,KAAK,GAAG;IACnB;;OAEG;IACH,MAAM,EAAE,aAAa,CAAC;IACtB;;;OAGG;IACH,GAAG,EAAE,aAAa,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,eAAe,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IACpB;;OAEG;IACH,YAAY,EAAE,aAAa,CAAC;IAC5B;;;OAGG;IACH,SAAS,EAAE,aAAa,CAAC;IACzB,eAAe,EAAE,qBAAqB,CAAC;CACvC,CAAC"}
1
+ {"version":3,"file":"tag.test.data.d.ts","sourceRoot":"","sources":["../../src/schema/tag.test.data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAExE,MAAM,MAAM,KAAK,GAAG;IACnB;;OAEG;IACH,MAAM,EAAE,aAAa,CAAC;IACtB;;;OAGG;IACH,GAAG,EAAE,aAAa,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,eAAe,CAAC;IAC3B;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,IAAI,EAAE,MAAM,GAAG,aAAa,CAAC;IAC7B;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IACpB;;OAEG;IACH,YAAY,EAAE,aAAa,CAAC;IAC5B;;;OAGG;IACH,SAAS,EAAE,aAAa,CAAC;IACzB,eAAe,EAAE,qBAAqB,CAAC;IACvC;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;IACxB;;OAEG;IACH,UAAU,EAAE,MAAM,GAAG,aAAa,CAAC;IACnC;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;IACxB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;CACvB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trayio/tray-schema",
3
- "version": "4.17.1",
3
+ "version": "4.18.1",
4
4
  "description": "Schema for Tray connectors and authentications",
5
5
  "exports": {
6
6
  "./*": "./dist/*.js"
@@ -11,7 +11,7 @@
11
11
  "access": "public"
12
12
  },
13
13
  "dependencies": {
14
- "@trayio/commons": "4.17.1",
14
+ "@trayio/commons": "4.18.1",
15
15
  "@types/node": "18.11.9",
16
16
  "lodash": "4.17.21",
17
17
  "typescript-json-schema": "0.62.0"