@quatrain/core 0.4.0 → 0.4.3
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/lib/Core.d.ts +3 -0
- package/lib/Core.js +2 -1
- package/lib/backends/AbstractAdapter.js +2 -2
- package/lib/components/AbstractObject.d.ts +1 -1
- package/lib/components/AbstractObject.js +3 -6
- package/lib/components/BaseObject.js +4 -5
- package/lib/components/DataObject.js +3 -0
- package/lib/components/Entity.d.ts +1 -0
- package/lib/components/Entity.js +45 -3
- package/lib/components/User.d.ts +0 -1
- package/lib/components/User.js +0 -1
- package/lib/properties/CollectionProperty.js +7 -1
- package/lib/utils/DataGenerator.js +3 -1
- package/package.json +2 -2
- package/lib/components/EntityProperties.d.ts +0 -1
- package/lib/components/EntityProperties.js +0 -47
package/lib/Core.d.ts
CHANGED
|
@@ -7,6 +7,9 @@ export declare type BackendRegistry<T extends AbstractAdapter> = {
|
|
|
7
7
|
export declare class Core {
|
|
8
8
|
static defaultBackend: string;
|
|
9
9
|
static currentUser: UserClass;
|
|
10
|
+
static classRegistry: {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
};
|
|
10
13
|
static logger: {
|
|
11
14
|
(...data: any[]): void;
|
|
12
15
|
(message?: any, ...optionalParams: any[]): void;
|
package/lib/Core.js
CHANGED
|
@@ -40,10 +40,11 @@ class Core {
|
|
|
40
40
|
* @param level string
|
|
41
41
|
*/
|
|
42
42
|
static log(message, src = 'Core', level = 'NOTICE') {
|
|
43
|
-
Core.logger(
|
|
43
|
+
Core.logger(`${Date.now()} - [${src}] ${message}`);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
exports.Core = Core;
|
|
47
47
|
Core.defaultBackend = '@default';
|
|
48
|
+
Core.classRegistry = {};
|
|
48
49
|
Core.logger = console.log;
|
|
49
50
|
Core._backends = {};
|
|
@@ -31,7 +31,7 @@ class AbstractAdapter {
|
|
|
31
31
|
return this._alias;
|
|
32
32
|
}
|
|
33
33
|
getCollection(dao) {
|
|
34
|
-
return dao.uri.class.name.toLowerCase();
|
|
34
|
+
return dao.uri.class.COLLECTION || dao.uri.class.name.toLowerCase();
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
* Process Query instance and return result
|
|
@@ -40,7 +40,7 @@ class AbstractAdapter {
|
|
|
40
40
|
*/
|
|
41
41
|
query(query) {
|
|
42
42
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
-
return this.find(yield query.obj.daoFactory(), query.filters, query.sortAndLimit);
|
|
43
|
+
return yield this.find(yield query.obj.daoFactory(), query.filters, query.sortAndLimit);
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
46
|
log(message) {
|
|
@@ -3,7 +3,7 @@ import { DataObjectProperties } from '../properties/';
|
|
|
3
3
|
import { Query } from '../backends/Query';
|
|
4
4
|
export declare abstract class AbstractObject {
|
|
5
5
|
static PROPS_DEFINITION: DataObjectProperties;
|
|
6
|
-
static COLLECTION: string;
|
|
6
|
+
static COLLECTION: string | undefined;
|
|
7
7
|
static LABEL_KEY: string;
|
|
8
8
|
protected _dataObject: DataObjectClass<any>;
|
|
9
9
|
constructor(dao: DataObjectClass<any>);
|
|
@@ -8,13 +8,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var _a;
|
|
12
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
12
|
exports.AbstractObject = void 0;
|
|
14
13
|
const Query_1 = require("../backends/Query");
|
|
15
14
|
class AbstractObject {
|
|
16
15
|
constructor(dao) {
|
|
17
16
|
this._dataObject = dao;
|
|
17
|
+
AbstractObject.COLLECTION = this.constructor.name.toLowerCase();
|
|
18
18
|
}
|
|
19
19
|
get(key) {
|
|
20
20
|
return this._dataObject.get(key);
|
|
@@ -47,8 +47,8 @@ class AbstractObject {
|
|
|
47
47
|
return this._dataObject.uri;
|
|
48
48
|
}
|
|
49
49
|
toJSON() {
|
|
50
|
-
var
|
|
51
|
-
return typeof this.uri === 'string' ? this.uri : (
|
|
50
|
+
var _a;
|
|
51
|
+
return typeof this.uri === 'string' ? this.uri : (_a = this.uri) === null || _a === void 0 ? void 0 : _a.toJSON();
|
|
52
52
|
}
|
|
53
53
|
save() {
|
|
54
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -65,9 +65,6 @@ class AbstractObject {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
exports.AbstractObject = AbstractObject;
|
|
68
|
-
_a = AbstractObject;
|
|
69
68
|
AbstractObject.PROPS_DEFINITION = [];
|
|
70
|
-
// Which name to use in backend as table/collection identifer
|
|
71
|
-
AbstractObject.COLLECTION = _a.constructor.name.toLowerCase();
|
|
72
69
|
// Which property's value to use in backend as label for object reference
|
|
73
70
|
AbstractObject.LABEL_KEY = 'name';
|
|
@@ -28,13 +28,13 @@ class BaseObject extends AbstractObject_1.AbstractObject {
|
|
|
28
28
|
static daoFactory(src = undefined, child = this) {
|
|
29
29
|
return __awaiter(this, void 0, void 0, function* () {
|
|
30
30
|
// merge base properties with additional or redefined ones
|
|
31
|
-
const base =
|
|
31
|
+
const base = [...BaseObject.PROPS_DEFINITION];
|
|
32
32
|
// this.PROPS_DEFINITION &&
|
|
33
|
-
|
|
33
|
+
child.PROPS_DEFINITION.forEach((property) => {
|
|
34
34
|
// manage parent properties potential redeclaration
|
|
35
35
|
const found = base.findIndex((el) => el.name === property.name);
|
|
36
36
|
if (found !== -1) {
|
|
37
|
-
base[found] =
|
|
37
|
+
base[found] = property;
|
|
38
38
|
}
|
|
39
39
|
else {
|
|
40
40
|
base.push(property);
|
|
@@ -66,8 +66,7 @@ class BaseObject extends AbstractObject_1.AbstractObject {
|
|
|
66
66
|
return Reflect.construct(this, [dao]);
|
|
67
67
|
}
|
|
68
68
|
catch (err) {
|
|
69
|
-
|
|
70
|
-
throw new Error(`Unable to build instance for '${this.constructor.name}': ${err.message}`);
|
|
69
|
+
throw new Error(`Unable to build instance for '${this.name}': ${err.message}`);
|
|
71
70
|
}
|
|
72
71
|
});
|
|
73
72
|
}
|
|
@@ -171,6 +171,9 @@ class DataObject {
|
|
|
171
171
|
const prop = Reflect.get(this._properties, key);
|
|
172
172
|
const value = prop.val();
|
|
173
173
|
switch (prop.constructor.name) {
|
|
174
|
+
case 'CollectionProperty':
|
|
175
|
+
// ignore
|
|
176
|
+
break;
|
|
174
177
|
case 'ObjectProperty':
|
|
175
178
|
Reflect.set(data, key, value ? value.toJSON() : null);
|
|
176
179
|
break;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BaseObject } from './BaseObject';
|
|
2
2
|
import { EntityClass } from './types/EntityClass';
|
|
3
|
+
export declare const EntityProperties: any;
|
|
3
4
|
export declare class Entity extends BaseObject implements EntityClass {
|
|
4
5
|
static PROPS_DEFINITION: any;
|
|
5
6
|
static factory(src?: any): Promise<Entity>;
|
package/lib/components/Entity.js
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
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
|
+
};
|
|
2
25
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
26
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
27
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -9,9 +32,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
32
|
});
|
|
10
33
|
};
|
|
11
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.Entity = void 0;
|
|
35
|
+
exports.Entity = exports.EntityProperties = void 0;
|
|
13
36
|
const BaseObject_1 = require("./BaseObject");
|
|
14
|
-
const
|
|
37
|
+
const CollectionProperty_1 = require("../properties/CollectionProperty");
|
|
38
|
+
const StringProperty_1 = require("../properties/StringProperty");
|
|
39
|
+
const htmlType = __importStar(require("../properties/types/PropertyHTMLType"));
|
|
40
|
+
exports.EntityProperties = [
|
|
41
|
+
{
|
|
42
|
+
// surcharge property minLength and htmlType
|
|
43
|
+
name: 'name',
|
|
44
|
+
type: StringProperty_1.StringProperty.TYPE,
|
|
45
|
+
mandatory: true,
|
|
46
|
+
minLength: 1,
|
|
47
|
+
htmlType: htmlType.ORG,
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: 'users',
|
|
51
|
+
mandatory: true,
|
|
52
|
+
type: CollectionProperty_1.CollectionProperty.TYPE,
|
|
53
|
+
instanceOf: 'User',
|
|
54
|
+
parentKey: 'entity',
|
|
55
|
+
},
|
|
56
|
+
];
|
|
15
57
|
class Entity extends BaseObject_1.BaseObject {
|
|
16
58
|
static factory(src = undefined) {
|
|
17
59
|
const _super = Object.create(null, {
|
|
@@ -23,4 +65,4 @@ class Entity extends BaseObject_1.BaseObject {
|
|
|
23
65
|
}
|
|
24
66
|
}
|
|
25
67
|
exports.Entity = Entity;
|
|
26
|
-
Entity.PROPS_DEFINITION =
|
|
68
|
+
Entity.PROPS_DEFINITION = exports.EntityProperties;
|
package/lib/components/User.d.ts
CHANGED
package/lib/components/User.js
CHANGED
|
@@ -19,7 +19,13 @@ class CollectionProperty extends BaseProperty_1.BaseProperty {
|
|
|
19
19
|
super(config);
|
|
20
20
|
this._value = undefined;
|
|
21
21
|
this._filters = undefined;
|
|
22
|
-
|
|
22
|
+
if (!config.instanceOf) {
|
|
23
|
+
throw new Error('Parameter instanceOf is mandatory');
|
|
24
|
+
}
|
|
25
|
+
this._instanceOf =
|
|
26
|
+
typeof config.instanceOf === 'string'
|
|
27
|
+
? Core_1.Core.classRegistry[config.instanceOf]
|
|
28
|
+
: config.instanceOf;
|
|
23
29
|
this._backend = config.backend
|
|
24
30
|
? Core_1.Core.getBackend(config.backend)
|
|
25
31
|
: undefined;
|
|
@@ -33,6 +33,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
35
|
exports.DataGenerator = void 0;
|
|
36
|
+
const Core_1 = require("../Core");
|
|
36
37
|
const htmlType = __importStar(require("../properties/types/PropertyHTMLType"));
|
|
37
38
|
const faker_1 = require("@faker-js/faker");
|
|
38
39
|
/**
|
|
@@ -44,8 +45,9 @@ const faker_1 = require("@faker-js/faker");
|
|
|
44
45
|
*/
|
|
45
46
|
const DataGenerator = (model, qty = 5, forcedValues = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
47
|
const promises = [];
|
|
48
|
+
Core_1.Core.log(`Starting to create ${qty} ${model.constructor.name} records`);
|
|
47
49
|
for (let i = 0; i < qty; i++) {
|
|
48
|
-
const dao = yield model.dataObject.clone(model.dataObject.toJSON())
|
|
50
|
+
const dao = yield model.dataObject.clone(); //model.dataObject.toJSON())
|
|
49
51
|
Object.keys(dao.properties).forEach((key) => {
|
|
50
52
|
const property = dao.get(key);
|
|
51
53
|
if (forcedValues[key]) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quatrain/core",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "Core objects for business apps",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -27,4 +27,4 @@
|
|
|
27
27
|
"push": "yarn version --patch --no-git-tag-version ; yarn publish --access public",
|
|
28
28
|
"prepublish": "tsc"
|
|
29
29
|
}
|
|
30
|
-
}
|
|
30
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const EntityProperties: any;
|
|
@@ -1,47 +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.EntityProperties = void 0;
|
|
27
|
-
const properties_1 = require("../properties");
|
|
28
|
-
const StringProperty_1 = require("../properties/StringProperty");
|
|
29
|
-
const htmlType = __importStar(require("../properties/types/PropertyHTMLType"));
|
|
30
|
-
const User_1 = require("./User");
|
|
31
|
-
exports.EntityProperties = [
|
|
32
|
-
{
|
|
33
|
-
// surcharge property minLength and htmlType
|
|
34
|
-
name: 'name',
|
|
35
|
-
type: StringProperty_1.StringProperty.TYPE,
|
|
36
|
-
mandatory: true,
|
|
37
|
-
minLength: 1,
|
|
38
|
-
htmlType: htmlType.ORG,
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
name: 'users',
|
|
42
|
-
mandatory: true,
|
|
43
|
-
type: properties_1.CollectionProperty.TYPE,
|
|
44
|
-
instanceOf: User_1.User,
|
|
45
|
-
parentKey: 'entity',
|
|
46
|
-
},
|
|
47
|
-
];
|