@quatrain/core 0.4.4 → 0.5.0

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 (73) hide show
  1. package/lib/Backend.d.ts +6 -5
  2. package/lib/Backend.js +17 -5
  3. package/lib/Core.d.ts +3 -3
  4. package/lib/backends/AbstractAdapter.d.ts +11 -6
  5. package/lib/backends/AbstractAdapter.js +13 -3
  6. package/lib/backends/Filter.d.ts +2 -2
  7. package/lib/backends/FilterOperators.d.ts +1 -1
  8. package/lib/backends/FilterOperators.js +1 -1
  9. package/lib/backends/MockAdapter.js +13 -5
  10. package/lib/backends/Query.d.ts +9 -3
  11. package/lib/backends/Query.js +26 -6
  12. package/lib/backends/middlewares/InjectMetaMiddleware.d.ts +7 -6
  13. package/lib/backends/middlewares/InjectMetaMiddleware.js +8 -28
  14. package/lib/backends/middlewares/Middleware.d.ts +5 -0
  15. package/lib/common/ResourcesErrors.d.ts +13 -0
  16. package/lib/common/ResourcesErrors.js +25 -0
  17. package/lib/components/AbstractObject.d.ts +0 -2
  18. package/lib/components/AbstractObject.js +0 -4
  19. package/lib/components/BaseObject.d.ts +11 -13
  20. package/lib/components/BaseObject.js +84 -78
  21. package/lib/components/BaseObjectCore.d.ts +60 -0
  22. package/lib/components/BaseObjectCore.js +153 -0
  23. package/lib/components/BaseRepository.d.ts +24 -0
  24. package/lib/components/BaseRepository.js +116 -0
  25. package/lib/components/DataObject.d.ts +19 -4
  26. package/lib/components/DataObject.js +51 -18
  27. package/lib/components/Entity.d.ts +22 -3
  28. package/lib/components/Entity.js +23 -22
  29. package/lib/components/EntityRepository.d.ts +6 -0
  30. package/lib/components/EntityRepository.js +14 -0
  31. package/lib/components/ObjectUri.js +3 -3
  32. package/lib/components/User.d.ts +14 -3
  33. package/lib/components/User.js +10 -8
  34. package/lib/components/UserRepository.d.ts +7 -0
  35. package/lib/components/UserRepository.js +36 -0
  36. package/lib/components/index.d.ts +4 -5
  37. package/lib/components/index.js +6 -9
  38. package/lib/components/types/AbstractObjectClass.d.ts +1 -1
  39. package/lib/components/types/BaseObjectClass.d.ts +3 -2
  40. package/lib/components/types/DataObjectClass.d.ts +3 -0
  41. package/lib/components/types/Payload.d.ts +10 -0
  42. package/lib/components/types/Payload.js +2 -0
  43. package/lib/components/types/Persisted.d.ts +6 -0
  44. package/lib/components/types/Persisted.js +2 -0
  45. package/lib/components/types/Properties.d.ts +3 -0
  46. package/lib/components/types/Properties.js +1 -0
  47. package/lib/components/types/ProxyConstructor.d.ts +10 -0
  48. package/lib/components/types/ProxyConstructor.js +4 -0
  49. package/lib/components/types/RepositoryClass.d.ts +40 -0
  50. package/lib/components/types/RepositoryClass.js +2 -0
  51. package/lib/index.d.ts +11 -3
  52. package/lib/index.js +21 -8
  53. package/lib/properties/BaseProperty.d.ts +2 -1
  54. package/lib/properties/BaseProperty.js +5 -1
  55. package/lib/properties/CollectionProperty.d.ts +4 -3
  56. package/lib/properties/HashProperty.d.ts +1 -1
  57. package/lib/properties/NumberProperty.d.ts +2 -2
  58. package/lib/properties/ObjectProperty.d.ts +5 -3
  59. package/lib/properties/ObjectProperty.js +5 -2
  60. package/lib/properties/Property.js +6 -0
  61. package/lib/properties/index.d.ts +2 -2
  62. package/lib/properties/types/PropertyClassType.d.ts +2 -1
  63. package/lib/properties/types/PropertyHTMLType.d.ts +1 -1
  64. package/lib/properties/types/PropertyTypes.d.ts +2 -2
  65. package/lib/utils/DataGenerator.d.ts +3 -2
  66. package/lib/utils/DataGenerator.js +1 -1
  67. package/package.json +31 -29
  68. package/lib/components/BaseObjectProperties.d.ts +0 -13
  69. package/lib/components/BaseObjectProperties.js +0 -87
  70. package/lib/components/UserProperties.d.ts +0 -1
  71. package/lib/components/UserProperties.js +0 -103
  72. package/lib/components/types/UserClass.d.ts +0 -3
  73. /package/lib/{components/types/UserClass.js → backends/middlewares/Middleware.js} +0 -0
@@ -12,7 +12,7 @@ import { MapProperty, MapPropertyType } from './MapProperty';
12
12
  import { CollectionProperty, CollectionPropertyType } from './CollectionProperty';
13
13
  import { PropertyTypes } from './types/PropertyTypes';
14
14
  export { Property, BaseProperty, BasePropertyType, ArrayProperty, ArrayPropertyType, NumberProperty, NumberPropertyType, BooleanProperty, BooleanPropertyType, DateTimeProperty, DateTimePropertyType, EnumProperty, EnumPropertyType, ObjectProperty, ObjectPropertyType, StringProperty, StringPropertyType, HashProperty, HashPropertyType, MapProperty, MapPropertyType, CollectionProperty, CollectionPropertyType, };
15
- declare type BaseType = {
15
+ type BaseType = {
16
16
  type: PropertyTypes;
17
17
  };
18
- export declare type DataObjectProperties = ((NumberPropertyType & BaseType) | (BooleanPropertyType & BaseType) | (EnumPropertyType & BaseType) | (ObjectPropertyType & BaseType) | (StringPropertyType & BaseType) | (HashPropertyType & BaseType) | (DateTimeProperty & BaseType) | (ArrayPropertyType & BaseType) | (MapPropertyType & BaseType) | (CollectionPropertyType & BaseType))[];
18
+ export type DataObjectProperties = ((NumberPropertyType & BaseType) | (BooleanPropertyType & BaseType) | (EnumPropertyType & BaseType) | (ObjectPropertyType & BaseType) | (StringPropertyType & BaseType) | (HashPropertyType & BaseType) | (DateTimeProperty & BaseType) | (ArrayPropertyType & BaseType) | (MapPropertyType & BaseType) | (CollectionPropertyType & BaseType))[];
@@ -1,6 +1,7 @@
1
- import { AbstractPropertyType } from "./AbstractPropertyType";
1
+ import { AbstractPropertyType } from './AbstractPropertyType';
2
2
  export interface PropertyClassType {
3
3
  set(value: any): AbstractPropertyType;
4
4
  val(transform?: any): any;
5
5
  toJSON(): any;
6
+ clone(): PropertyClassType;
6
7
  }
@@ -7,4 +7,4 @@ export declare const PASSWORD = "password";
7
7
  export declare const BIRTHDAY = "bday";
8
8
  export declare const GENDER = "sex";
9
9
  export declare const ORG = "organization";
10
- export declare type PropertyHTMLType = typeof OFF | typeof NAME | typeof GIVEN_NAME | typeof FAMILY_NAME | typeof EMAIL | typeof PASSWORD | typeof BIRTHDAY | typeof GENDER | typeof ORG;
10
+ export type PropertyHTMLType = typeof OFF | typeof NAME | typeof GIVEN_NAME | typeof FAMILY_NAME | typeof EMAIL | typeof PASSWORD | typeof BIRTHDAY | typeof GENDER | typeof ORG;
@@ -1,5 +1,5 @@
1
1
  import { Property } from '..';
2
- export declare type PropertyTypes = typeof Property.TYPE_STRING | typeof Property.TYPE_NUMBER | typeof Property.TYPE_ENUM | typeof Property.TYPE_BOOLEAN | typeof Property.TYPE_OBJECT | typeof Property.TYPE_DATETIME | typeof Property.TYPE_HASH | typeof Property.TYPE_ARRAY;
3
- export declare type BaseType = {
2
+ export type PropertyTypes = typeof Property.TYPE_STRING | typeof Property.TYPE_NUMBER | typeof Property.TYPE_ENUM | typeof Property.TYPE_BOOLEAN | typeof Property.TYPE_OBJECT | typeof Property.TYPE_DATETIME | typeof Property.TYPE_HASH | typeof Property.TYPE_ARRAY;
3
+ export type BaseType = {
4
4
  type: PropertyTypes;
5
5
  };
@@ -1,4 +1,5 @@
1
- import { BaseObject } from '../components';
1
+ import { BaseObject } from '../components/BaseObject';
2
+ import { Proxy } from '../components/types/ProxyConstructor';
2
3
  /**
3
4
  * Generate data from model of object and save it in default backend
4
5
  * @param model
@@ -6,4 +7,4 @@ import { BaseObject } from '../components';
6
7
  * @param forcedValues
7
8
  * @returns
8
9
  */
9
- export declare const DataGenerator: <T extends BaseObject>(model: T, qty?: number, forcedValues?: any) => Promise<any>;
10
+ export declare const DataGenerator: <T extends BaseObject>(model: Proxy<T>, qty?: number, forcedValues?: any) => Promise<any>;
@@ -47,7 +47,7 @@ const DataGenerator = (model, qty = 5, forcedValues = {}) => __awaiter(void 0, v
47
47
  const promises = [];
48
48
  Core_1.Core.log(`Starting to create ${qty} ${model.constructor.name} records`);
49
49
  for (let i = 0; i < qty; i++) {
50
- const dao = yield model.dataObject.clone(); //model.dataObject.toJSON())
50
+ const dao = yield model.core.dataObject.clone(); //model.dataObject.toJSON())
51
51
  Object.keys(dao.properties).forEach((key) => {
52
52
  const property = dao.get(key);
53
53
  if (forcedValues[key]) {
package/package.json CHANGED
@@ -1,30 +1,32 @@
1
1
  {
2
- "name": "@quatrain/core",
3
- "version": "0.4.4",
4
- "description": "Core objects for business apps",
5
- "main": "lib/index.js",
6
- "types": "lib/index.d.ts",
7
- "files": [
8
- "lib/",
9
- "README.md"
10
- ],
11
- "author": "Quatrain Développement SAS <developers@quatrain.com>",
12
- "license": "MIT",
13
- "devDependencies": {
14
- "@faker-js/faker": "^7.6.0",
15
- "@tsconfig/recommended": "^1.0.1",
16
- "@types/jest": "^27.0.3",
17
- "jest": "^27.4.7",
18
- "jest-node-exports-resolver": "^1.1.6",
19
- "trace-unhandled": "^2.0.1",
20
- "ts-jest": "^27.1.2",
21
- "ts-node": "^10.4.0",
22
- "typescript": "^4.7.4"
23
- },
24
- "scripts": {
25
- "test": "tsc && jest --verbose",
26
- "build": "tsc --watch",
27
- "push": "yarn version --patch --no-git-tag-version ; yarn publish --access public",
28
- "prepublish": "tsc"
29
- }
30
- }
2
+ "name": "@quatrain/core",
3
+ "version": "0.5.0",
4
+ "description": "Core objects for business apps",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "files": [
8
+ "lib/",
9
+ "README.md"
10
+ ],
11
+ "author": "Quatrain Développement SAS <developers@quatrain.com>",
12
+ "license": "MIT",
13
+ "devDependencies": {
14
+ "@tsconfig/recommended": "^1.0.1",
15
+ "@types/jest": "^27.0.3",
16
+ "jest": "^27.4.7",
17
+ "jest-node-exports-resolver": "^1.1.6",
18
+ "trace-unhandled": "^2.0.1",
19
+ "ts-jest": "^27.1.2",
20
+ "ts-node": "^10.4.0",
21
+ "typescript": "^5.1.5"
22
+ },
23
+ "dependencies": {
24
+ "@faker-js/faker": "^7.6.0"
25
+ },
26
+ "scripts": {
27
+ "test": "tsc && jest --verbose",
28
+ "build": "tsc --watch",
29
+ "push": "yarn version --patch --no-git-tag-version ; yarn publish --access public",
30
+ "prepublish": "tsc"
31
+ }
32
+ }
@@ -1,13 +0,0 @@
1
- import { UserClass } from './types/UserClass';
2
- import { ObjectUri } from './ObjectUri';
3
- export interface BaseObjectType {
4
- name: string;
5
- status: string;
6
- createdBy?: UserClass | ObjectUri;
7
- createdAt?: number;
8
- updatedBy?: UserClass | ObjectUri;
9
- updatedAt?: number;
10
- deletedBy?: UserClass | ObjectUri;
11
- deletedAt?: number;
12
- }
13
- export declare const BaseObjectProperties: any;
@@ -1,87 +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.BaseObjectProperties = void 0;
27
- const statuses = __importStar(require("../statuses"));
28
- const StringProperty_1 = require("../properties/StringProperty");
29
- const ObjectProperty_1 = require("../properties/ObjectProperty");
30
- const EnumProperty_1 = require("../properties/EnumProperty");
31
- const DateTimeProperty_1 = require("../properties/DateTimeProperty");
32
- const htmlType = __importStar(require("../properties/types/PropertyHTMLType"));
33
- exports.BaseObjectProperties = [
34
- {
35
- name: 'name',
36
- mandatory: true,
37
- type: StringProperty_1.StringProperty.TYPE,
38
- minLength: 1,
39
- maxLength: 100,
40
- htmlType: htmlType.NAME,
41
- },
42
- {
43
- name: 'status',
44
- mandatory: true,
45
- type: EnumProperty_1.EnumProperty.TYPE,
46
- values: [
47
- statuses.CREATED,
48
- statuses.PENDING,
49
- statuses.ACTIVE,
50
- statuses.DELETED,
51
- ],
52
- defaultValue: statuses.CREATED,
53
- },
54
- {
55
- name: 'createdBy',
56
- type: ObjectProperty_1.ObjectProperty.TYPE,
57
- instanceOf: 'User',
58
- mandatory: true,
59
- protected: true,
60
- },
61
- {
62
- name: 'createdAt',
63
- type: DateTimeProperty_1.DateTimeProperty.TYPE,
64
- mandatory: true,
65
- protected: true,
66
- },
67
- {
68
- name: 'updatedBy',
69
- type: ObjectProperty_1.ObjectProperty.TYPE,
70
- instanceOf: 'User',
71
- },
72
- {
73
- name: 'updatedAt',
74
- type: DateTimeProperty_1.DateTimeProperty.TYPE,
75
- },
76
- {
77
- name: 'deletedBy',
78
- type: ObjectProperty_1.ObjectProperty.TYPE,
79
- instanceOf: 'User',
80
- protected: true,
81
- },
82
- {
83
- name: 'deletedAt',
84
- type: DateTimeProperty_1.DateTimeProperty.TYPE,
85
- protected: true,
86
- },
87
- ];
@@ -1 +0,0 @@
1
- export declare const UserProperties: any;
@@ -1,103 +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.UserProperties = void 0;
27
- const properties_1 = require("../properties");
28
- const HashProperty_1 = require("../properties/HashProperty");
29
- const StringProperty_1 = require("../properties/StringProperty");
30
- const Entity_1 = require("./Entity");
31
- const htmlType = __importStar(require("../properties/types/PropertyHTMLType"));
32
- /**
33
- * Callback function to populate the 'name' property
34
- * @param dao DataObject
35
- * @returns
36
- */
37
- const onChange = (dao) => dao.set('name', `${dao.val('firstname')} ${dao.val('lastname')}`);
38
- exports.UserProperties = [
39
- {
40
- // change name property minLength
41
- name: 'name',
42
- type: StringProperty_1.StringProperty.TYPE,
43
- minLength: 0,
44
- fullSearch: true,
45
- htmlType: htmlType.NAME,
46
- },
47
- {
48
- name: 'firstname',
49
- mandatory: true,
50
- type: StringProperty_1.StringProperty.TYPE,
51
- minLength: 1,
52
- maxLength: 100,
53
- htmlType: htmlType.GIVEN_NAME,
54
- onChange,
55
- },
56
- {
57
- name: 'lastname',
58
- mandatory: true,
59
- type: StringProperty_1.StringProperty.TYPE,
60
- minLength: 1,
61
- maxLength: 100,
62
- htmlType: htmlType.FAMILY_NAME,
63
- onChange,
64
- },
65
- {
66
- name: 'gender',
67
- mandatory: false,
68
- type: properties_1.EnumProperty.TYPE,
69
- values: ['male', 'female', 'nonbinary'],
70
- htmlType: htmlType.GENDER,
71
- },
72
- {
73
- name: 'birthday',
74
- mandatory: false,
75
- type: properties_1.DateTimeProperty.TYPE,
76
- htmlType: htmlType.BIRTHDAY,
77
- },
78
- {
79
- name: 'email',
80
- mandatory: true,
81
- type: StringProperty_1.StringProperty.TYPE,
82
- minLength: 1,
83
- maxLength: 100,
84
- fullSearch: true,
85
- htmlType: htmlType.EMAIL,
86
- },
87
- {
88
- name: 'password',
89
- mandatory: true,
90
- type: HashProperty_1.HashProperty.TYPE,
91
- algorithm: HashProperty_1.HashProperty.ALGORITHM_SHA256,
92
- salt: '',
93
- minLength: 5,
94
- maxLength: 20,
95
- htmlType: htmlType.PASSWORD,
96
- },
97
- {
98
- name: 'entity',
99
- mandatory: false,
100
- type: properties_1.ObjectProperty.TYPE,
101
- instanceof: Entity_1.Entity,
102
- },
103
- ];
@@ -1,3 +0,0 @@
1
- import { BaseObjectClass } from './BaseObjectClass';
2
- export interface UserClass extends BaseObjectClass {
3
- }