@quatrain/core 1.1.51 → 1.2.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.
Files changed (49) hide show
  1. package/LICENSE.md +654 -9
  2. package/NOTICE.md +15 -0
  3. package/dist/Core.d.ts.map +1 -1
  4. package/dist/components/BaseObject.d.ts.map +1 -1
  5. package/dist/components/BaseObject.js +9 -0
  6. package/dist/components/BaseObject.js.map +1 -1
  7. package/dist/components/BaseObjectProperties.js +17 -7
  8. package/dist/components/BaseObjectProperties.js.map +1 -1
  9. package/dist/components/DataObject.js +1 -1
  10. package/dist/components/DataObject.js.map +1 -1
  11. package/dist/components/Entity.js +17 -7
  12. package/dist/components/Entity.js.map +1 -1
  13. package/dist/components/User.js +17 -7
  14. package/dist/components/User.js.map +1 -1
  15. package/dist/components/test_script.d.ts +2 -0
  16. package/dist/components/test_script.d.ts.map +1 -0
  17. package/dist/components/test_script.js +18 -0
  18. package/dist/components/test_script.js.map +1 -0
  19. package/dist/components/test_script3.d.ts +2 -0
  20. package/dist/components/test_script3.d.ts.map +1 -0
  21. package/dist/components/test_script3.js +8 -0
  22. package/dist/components/test_script3.js.map +1 -0
  23. package/dist/components/types/ProxyConstructor.d.ts.map +1 -1
  24. package/dist/index.d.ts +5 -2
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +24 -8
  27. package/dist/index.js.map +1 -1
  28. package/dist/properties/BaseProperty.d.ts +1 -1
  29. package/dist/properties/StringProperty.js +1 -1
  30. package/dist/properties/StringProperty.js.map +1 -1
  31. package/dist/properties/types/PropertyHTMLType.d.ts +8 -1
  32. package/dist/properties/types/PropertyHTMLType.d.ts.map +1 -1
  33. package/dist/properties/types/PropertyHTMLType.js +8 -1
  34. package/dist/properties/types/PropertyHTMLType.js.map +1 -1
  35. package/package.json +7 -8
  36. package/src/components/BaseObject.test.ts +33 -0
  37. package/src/components/BaseObject.ts +10 -0
  38. package/src/components/DataObject.ts +1 -1
  39. package/src/components/test_script.ts +17 -0
  40. package/src/components/test_script3.ts +5 -0
  41. package/src/index.ts +8 -0
  42. package/src/properties/CollectionProperty.test.ts +1 -1
  43. package/src/properties/StringProperty.ts +1 -1
  44. package/src/properties/types/PropertyHTMLType.ts +14 -0
  45. package/dist/common/DataGenerator.d.ts +0 -3
  46. package/dist/common/DataGenerator.d.ts.map +0 -1
  47. package/dist/common/DataGenerator.js +0 -86
  48. package/dist/common/DataGenerator.js.map +0 -1
  49. package/src/common/DataGenerator.ts +0 -81
@@ -43,6 +43,12 @@ export class BaseObject extends AbstractObject {
43
43
  ): Promise<DataObjectType> {
44
44
  const dao = this.fillProperties(child)
45
45
 
46
+ if (src instanceof ObjectUri) {
47
+ dao.uri = src
48
+ } else if (typeof src === 'string') {
49
+ dao.uri.path = src
50
+ }
51
+
46
52
  return dao
47
53
  }
48
54
 
@@ -78,6 +84,10 @@ export class BaseObject extends AbstractObject {
78
84
  return this.fromObject(src)
79
85
  }
80
86
 
87
+ if (typeof src === 'string' && !src.includes('/')) {
88
+ src = `${this.COLLECTION}/${src}`
89
+ }
90
+
81
91
  const dao = await this.daoFactory(src, child)
82
92
 
83
93
  const constructedObject = Reflect.construct(this, [dao])
@@ -401,7 +401,7 @@ export class DataObject implements DataObjectType {
401
401
  }
402
402
 
403
403
  async clone(data: any = {}): Promise<DataObject> {
404
- const cloned = await DataObject.factory()
404
+ const cloned = await (this.constructor as any).factory()
405
405
  cloned.uri.class = this.uri.class
406
406
  cloned._populated = false
407
407
 
@@ -0,0 +1,17 @@
1
+ import { BaseObject } from './BaseObject'
2
+ import { StringProperty } from '../properties/StringProperty'
3
+
4
+ class TestModel extends BaseObject {
5
+ static COLLECTION = 'test_collection'
6
+ static PROPS_DEFINITION = [
7
+ {
8
+ name: 'testProp',
9
+ type: StringProperty.TYPE,
10
+ },
11
+ ]
12
+ }
13
+
14
+ TestModel.factory('12345').then(obj => {
15
+ console.log('--- PATH ---', obj.uri.path)
16
+ console.log('--- URI ---', obj.uri)
17
+ }).catch(console.error)
@@ -0,0 +1,5 @@
1
+ import { ObjectUri } from './ObjectUri'
2
+ const uri = new ObjectUri()
3
+ uri.path = 'test_collection/12345'
4
+ console.log('--- PATH ---', uri.path)
5
+ console.log('--- URI ---', uri)
package/src/index.ts CHANGED
@@ -24,6 +24,8 @@ import {
24
24
  CollectionPropertyType,
25
25
  } from './properties/CollectionProperty'
26
26
  import { ArrayProperty, ArrayPropertyType } from './properties/ArrayProperty'
27
+ import { MapProperty, MapPropertyType } from './properties/MapProperty'
28
+ import { FileProperty, FilePropertyType } from './properties/FileProperty'
27
29
  import { AbstractObject } from './components/AbstractObject'
28
30
  import { ObjectUri } from './components/ObjectUri'
29
31
  import { DataObjectClass } from './components/types/DataObjectClass'
@@ -44,9 +46,11 @@ import {
44
46
  NotFoundError,
45
47
  GoneError,
46
48
  } from './common/ResourcesErrors'
49
+ import * as htmlType from './properties/types/PropertyHTMLType'
47
50
  import { DataObjectParams } from './components/types/DataObjectParams'
48
51
 
49
52
  export {
53
+ htmlType,
50
54
  statuses,
51
55
  Core,
52
56
  Property,
@@ -61,6 +65,8 @@ export {
61
65
  NumberProperty,
62
66
  returnAs,
63
67
  StringProperty,
68
+ MapProperty,
69
+ FileProperty,
64
70
  ObjectUri,
65
71
  DataObject,
66
72
  AbstractObject,
@@ -88,6 +94,8 @@ export type {
88
94
  ObjectPropertyType,
89
95
  NumberPropertyType,
90
96
  StringPropertyType,
97
+ MapPropertyType,
98
+ FilePropertyType,
91
99
  DataObjectClass,
92
100
  DataObjectProperties,
93
101
  BaseObjectType,
@@ -1,6 +1,6 @@
1
1
  import { Entity } from '../components/Entity'
2
2
  import { User } from '../components/User'
3
- import { DataGenerator } from '../common/DataGenerator'
3
+ import { DataGenerator } from '@quatrain/testing'
4
4
  import * as statuses from '../common/statuses'
5
5
 
6
6
  describe('Collection Property', () => {
@@ -74,7 +74,7 @@ export class StringProperty extends BaseProperty {
74
74
  }
75
75
 
76
76
  if (this._minLength > 0 && value.length < this._minLength) {
77
- throw new Error(`Value is too short`)
77
+ throw new Error(`${this._name}: value '${value}' is too short (min ${this._minLength})`)
78
78
  }
79
79
 
80
80
  if (this._maxLength > 0 && value.length > this._maxLength) {
@@ -10,6 +10,13 @@ export const PASSWORD = 'password'
10
10
  export const BIRTHDAY = 'bday'
11
11
  export const GENDER = 'sex'
12
12
  export const ORG = 'organization'
13
+ export const TEXT = 'text'
14
+ export const TEXTAREA = 'textarea'
15
+ export const HIDDEN = 'hidden'
16
+ export const SELECT = 'select'
17
+ export const CHECKBOX = 'checkbox'
18
+ export const NUMBER = 'number'
19
+ export const FILE = 'file'
13
20
 
14
21
  export type PropertyHTMLType =
15
22
  | typeof OFF
@@ -21,3 +28,10 @@ export type PropertyHTMLType =
21
28
  | typeof BIRTHDAY
22
29
  | typeof GENDER
23
30
  | typeof ORG
31
+ | typeof TEXT
32
+ | typeof TEXTAREA
33
+ | typeof HIDDEN
34
+ | typeof SELECT
35
+ | typeof CHECKBOX
36
+ | typeof NUMBER
37
+ | typeof FILE
@@ -1,3 +0,0 @@
1
- import { AbstractObject } from '../components/AbstractObject';
2
- export declare const DataGenerator: <T extends AbstractObject>(model: T, qty?: number, forcedValues?: any) => Promise<any>;
3
- //# sourceMappingURL=DataGenerator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DataGenerator.d.ts","sourceRoot":"","sources":["../../src/common/DataGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAY7D,eAAO,MAAM,aAAa,6CAElB,MAAM,iBACG,GAAG,KACjB,QAAQ,GAAG,CAgEb,CAAA"}
@@ -1,86 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.DataGenerator = void 0;
27
- const htmlType = __importStar(require("../properties/types/PropertyHTMLType"));
28
- const faker_1 = require("@faker-js/faker");
29
- const __1 = require("..");
30
- const DataGenerator = async (model, qty = 5, forcedValues = {}) => {
31
- const promises = [];
32
- __1.Core.info(`Starting to create ${qty} ${model.constructor.name} records`);
33
- for (let i = 0; i < qty; i++) {
34
- const dao = await model.dataObject.clone();
35
- Object.keys(dao.properties).forEach((key) => {
36
- __1.Core.debug(`Getting property for '${key}'`);
37
- const property = dao.get(key);
38
- if (forcedValues[key]) {
39
- property.set(forcedValues[key]);
40
- return;
41
- }
42
- switch (property.constructor.name) {
43
- case 'StringProperty':
44
- switch (property.htmlType) {
45
- case htmlType.GIVEN_NAME:
46
- property.set(faker_1.faker.name.firstName());
47
- break;
48
- case htmlType.FAMILY_NAME:
49
- property.set(faker_1.faker.name.lastName());
50
- break;
51
- case htmlType.EMAIL:
52
- property.set(faker_1.faker.helpers.unique(faker_1.faker.internet.email));
53
- break;
54
- case htmlType.ORG:
55
- property.set(faker_1.faker.company.name());
56
- break;
57
- default:
58
- property.set(faker_1.faker.word.noun());
59
- break;
60
- }
61
- break;
62
- case 'EnumProperty':
63
- property.set(faker_1.faker.helpers.arrayElement(property.values));
64
- break;
65
- case 'HashProperty':
66
- property.set(faker_1.faker.random.alphaNumeric(16));
67
- break;
68
- case 'DateTimeProperty':
69
- switch (property.htmlType) {
70
- case htmlType.BIRTHDAY:
71
- property.set(faker_1.faker.date.birthdate());
72
- break;
73
- default:
74
- break;
75
- }
76
- break;
77
- default:
78
- break;
79
- }
80
- });
81
- promises.push(dao);
82
- }
83
- return promises;
84
- };
85
- exports.DataGenerator = DataGenerator;
86
- //# sourceMappingURL=DataGenerator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DataGenerator.js","sourceRoot":"","sources":["../../src/common/DataGenerator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,+EAAgE;AAChE,2CAAuC;AACvC,0BAAyB;AASlB,MAAM,aAAa,GAAG,KAAK,EAC/B,KAAQ,EACR,MAAc,CAAC,EACf,eAAoB,EAAE,EACT,EAAE;IACf,MAAM,QAAQ,GAAQ,EAAE,CAAA;IACxB,QAAI,CAAC,IAAI,CAAC,sBAAsB,GAAG,IAAI,KAAK,CAAC,WAAW,CAAC,IAAI,UAAU,CAAC,CAAA;IACxE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5B,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,UAAU,CAAC,KAAK,EAAE,CAAA;QAE1C,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YACzC,QAAI,CAAC,KAAK,CAAC,yBAAyB,GAAG,GAAG,CAAC,CAAA;YAC3C,MAAM,QAAQ,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YAE7B,IAAI,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC;gBACrB,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAA;gBAC/B,OAAM;YACT,CAAC;YA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pC,MAAK;wBACR;4BAEG,MAAK;oBACX,CAAC;oBACD,MAAK;gBAER;oBACG,MAAK;YACX,CAAC;QACJ,CAAC,CAAC,CAAA;QAEF,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACrB,CAAC;IAED,OAAO,QAAQ,CAAA;AAClB,CAAC,CAAA;AApEY,QAAA,aAAa,iBAoEzB"}
@@ -1,81 +0,0 @@
1
- import { AbstractObject } from '../components/AbstractObject'
2
- import * as htmlType from '../properties/types/PropertyHTMLType'
3
- import { faker } from '@faker-js/faker'
4
- import { Core } from '..'
5
-
6
- /**
7
- * Generate data from model of object and save it in default backend
8
- * @param model
9
- * @param qty
10
- * @param forcedValues
11
- * @returns
12
- */
13
- export const DataGenerator = async <T extends AbstractObject>(
14
- model: T,
15
- qty: number = 5,
16
- forcedValues: any = {}
17
- ): Promise<any> => {
18
- const promises: any = []
19
- Core.info(`Starting to create ${qty} ${model.constructor.name} records`)
20
- for (let i = 0; i < qty; i++) {
21
- const dao = await model.dataObject.clone()
22
-
23
- Object.keys(dao.properties).forEach((key) => {
24
- Core.debug(`Getting property for '${key}'`)
25
- const property = dao.get(key)
26
-
27
- if (forcedValues[key]) {
28
- property.set(forcedValues[key])
29
- return
30
- }
31
-
32
- switch (property.constructor.name) {
33
- case 'StringProperty':
34
- switch (property.htmlType) {
35
- case htmlType.GIVEN_NAME:
36
- property.set(faker.name.firstName())
37
- break
38
- case htmlType.FAMILY_NAME:
39
- property.set(faker.name.lastName())
40
- break
41
- case htmlType.EMAIL:
42
- property.set(faker.helpers.unique(faker.internet.email))
43
- break
44
- case htmlType.ORG:
45
- property.set(faker.company.name())
46
- break
47
- default:
48
- property.set(faker.word.noun())
49
- break
50
- }
51
- break
52
-
53
- case 'EnumProperty':
54
- property.set(faker.helpers.arrayElement(property.values))
55
- break
56
-
57
- case 'HashProperty':
58
- property.set(faker.random.alphaNumeric(16))
59
- break
60
-
61
- case 'DateTimeProperty':
62
- switch (property.htmlType) {
63
- case htmlType.BIRTHDAY:
64
- property.set(faker.date.birthdate())
65
- break
66
- default:
67
- //property.set(faker.date.future())
68
- break
69
- }
70
- break
71
-
72
- default:
73
- break
74
- }
75
- })
76
-
77
- promises.push(dao)
78
- }
79
-
80
- return promises
81
- }