@quatrain/core 0.2.0 → 0.3.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 (66) hide show
  1. package/lib/Core.d.ts +3 -1
  2. package/lib/Core.js +2 -2
  3. package/lib/backends/AbstractAdapter.d.ts +11 -9
  4. package/lib/backends/MockAdapter.d.ts +16 -9
  5. package/lib/backends/MockAdapter.js +87 -22
  6. package/lib/backends/Query.d.ts +11 -3
  7. package/lib/backends/Query.js +30 -4
  8. package/lib/components/AbstractObject.d.ts +9 -9
  9. package/lib/components/AbstractObject.js +2 -2
  10. package/lib/components/BaseObject.d.ts +10 -11
  11. package/lib/components/BaseObject.js +42 -33
  12. package/lib/components/BaseObjectProperties.d.ts +5 -6
  13. package/lib/components/BaseObjectProperties.js +12 -9
  14. package/lib/components/DataObject.d.ts +21 -16
  15. package/lib/components/DataObject.js +35 -18
  16. package/lib/components/Entity.d.ts +6 -0
  17. package/lib/components/Entity.js +26 -0
  18. package/lib/components/EntityProperties.d.ts +1 -0
  19. package/lib/components/EntityProperties.js +12 -0
  20. package/lib/components/ObjectUri.d.ts +4 -1
  21. package/lib/components/ObjectUri.js +7 -4
  22. package/lib/components/User.d.ts +4 -4
  23. package/lib/components/User.js +20 -50
  24. package/lib/components/UserProperties.d.ts +1 -0
  25. package/lib/components/UserProperties.js +59 -0
  26. package/lib/components/index.d.ts +6 -3
  27. package/lib/components/index.js +5 -2
  28. package/lib/components/types/AbstractObjectClass.d.ts +6 -0
  29. package/lib/components/types/AbstractObjectClass.js +2 -0
  30. package/lib/components/types/BaseObjectClass.d.ts +6 -0
  31. package/lib/components/types/BaseObjectClass.js +2 -0
  32. package/lib/components/types/DataObjectClass.d.ts +21 -0
  33. package/lib/components/types/DataObjectClass.js +2 -0
  34. package/lib/components/types/EntityClass.d.ts +3 -0
  35. package/lib/components/types/EntityClass.js +2 -0
  36. package/lib/components/types/UserClass.d.ts +3 -0
  37. package/lib/components/types/UserClass.js +2 -0
  38. package/lib/properties/ArrayProperty.d.ts +1 -0
  39. package/lib/properties/ArrayProperty.js +6 -5
  40. package/lib/properties/BaseProperty.d.ts +5 -4
  41. package/lib/properties/BaseProperty.js +1 -0
  42. package/lib/properties/BooleanProperty.d.ts +2 -1
  43. package/lib/properties/BooleanProperty.js +3 -2
  44. package/lib/properties/CollectionProperty.d.ts +29 -0
  45. package/lib/properties/CollectionProperty.js +62 -0
  46. package/lib/properties/DateTimeProperty.d.ts +1 -0
  47. package/lib/properties/DateTimeProperty.js +1 -0
  48. package/lib/properties/EnumProperty.d.ts +1 -0
  49. package/lib/properties/EnumProperty.js +1 -0
  50. package/lib/properties/HashProperty.d.ts +1 -0
  51. package/lib/properties/HashProperty.js +1 -0
  52. package/lib/properties/MapProperty.d.ts +8 -0
  53. package/lib/properties/MapProperty.js +17 -0
  54. package/lib/properties/NumberProperty.d.ts +1 -0
  55. package/lib/properties/NumberProperty.js +1 -0
  56. package/lib/properties/ObjectProperty.d.ts +4 -7
  57. package/lib/properties/ObjectProperty.js +4 -1
  58. package/lib/properties/Property.d.ts +3 -7
  59. package/lib/properties/Property.js +13 -15
  60. package/lib/properties/StringProperty.d.ts +6 -0
  61. package/lib/properties/StringProperty.js +13 -7
  62. package/lib/properties/index.d.ts +4 -2
  63. package/lib/properties/index.js +5 -1
  64. package/lib/properties/types/PropertyClassType.d.ts +4 -2
  65. package/lib/properties/types/PropertyTypes.d.ts +4 -1
  66. package/package.json +3 -1
package/lib/Core.d.ts CHANGED
@@ -1,9 +1,11 @@
1
- import { AbstractAdapter } from './backends';
1
+ import { AbstractAdapter } from './backends/AbstractAdapter';
2
+ import { UserClass } from './components/types/UserClass';
2
3
  export declare type BackendRegistry<T extends AbstractAdapter> = {
3
4
  [x: string]: T;
4
5
  };
5
6
  export declare class Core {
6
7
  static defaultBackend: string;
8
+ static currentUser: UserClass;
7
9
  protected static _backends: BackendRegistry<any>;
8
10
  static definition(key: string): {
9
11
  manifest: {
package/lib/Core.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Core = void 0;
4
- const backends_1 = require("./backends");
4
+ const MockAdapter_1 = require("./backends/MockAdapter");
5
5
  class Core {
6
6
  static definition(key) {
7
7
  return {
@@ -26,5 +26,5 @@ class Core {
26
26
  exports.Core = Core;
27
27
  Core.defaultBackend = '@default';
28
28
  Core._backends = {
29
- '@mock': new backends_1.MockAdapter({ alias: '@mock' }),
29
+ '@mock': new MockAdapter_1.MockAdapter({ alias: '@mock' }),
30
30
  };
@@ -1,4 +1,5 @@
1
- import { BaseObject, DataObject } from '../components';
1
+ import { DataObjectClass } from '../components';
2
+ import { BaseObjectClass } from '../components/types/BaseObjectClass';
2
3
  import { Filter } from './Filter';
3
4
  import { Filters } from './Filters';
4
5
  import { Query } from './Query';
@@ -8,7 +9,8 @@ import { SortAndLimit } from './SortAndLimit';
8
9
  */
9
10
  export interface BackendRecordType {
10
11
  uid: string | undefined;
11
- [key: string]: string | number | boolean | any[] | Object | undefined;
12
+ path: string | undefined;
13
+ [key: string]: any;
12
14
  }
13
15
  /**
14
16
  * Backend Parameters acceptable keys
@@ -28,13 +30,13 @@ export interface BackendParameters {
28
30
  softDelete?: boolean;
29
31
  debug?: boolean;
30
32
  }
31
- export interface BackendInterface<T extends BaseObject> {
32
- create(dataObject: DataObject, desiredUid: string | undefined): Promise<DataObject>;
33
- read(param: string | DataObject): Promise<DataObject>;
34
- update(dataObject: DataObject): Promise<DataObject>;
35
- delete(dataObject: DataObject): Promise<DataObject>;
36
- query(query: Query<T>): Promise<DataObject[] | T[]>;
37
- find(dataObject: DataObject, filters: Filters | Filter[] | undefined, pagination: SortAndLimit | undefined): Promise<DataObject[] | T[]>;
33
+ export interface BackendInterface<T extends BaseObjectClass> {
34
+ create(dataObject: DataObjectClass, desiredUid: string | undefined): Promise<DataObjectClass>;
35
+ read(param: string | DataObjectClass): Promise<DataObjectClass>;
36
+ update(dataObject: DataObjectClass): Promise<DataObjectClass>;
37
+ delete(dataObject: DataObjectClass): Promise<DataObjectClass>;
38
+ query(query: Query<any>): Promise<DataObjectClass[]>;
39
+ find(dataObject: DataObjectClass, filters: Filters | Filter[] | undefined, pagination: SortAndLimit | undefined): Promise<DataObjectClass[] | T[]>;
38
40
  }
39
41
  export declare abstract class AbstractAdapter {
40
42
  protected _alias: string;
@@ -1,11 +1,12 @@
1
- import { AbstractAdapter, BackendInterface } from './';
2
- import { BaseObject, DataObject } from '../components';
1
+ import { AbstractAdapter, BackendInterface } from './AbstractAdapter';
3
2
  import { BackendRecordType } from './AbstractAdapter';
4
3
  import { Query } from './Query';
5
4
  import { Filter } from './Filter';
6
5
  import { Filters } from './Filters';
7
6
  import { SortAndLimit } from './SortAndLimit';
8
- export declare class MockAdapter<T extends BaseObject> extends AbstractAdapter implements BackendInterface<T> {
7
+ import { DataObjectClass } from '../components/types/DataObjectClass';
8
+ import { BaseObjectClass } from '../components/types/BaseObjectClass';
9
+ export declare class MockAdapter<T extends BaseObjectClass> extends AbstractAdapter implements BackendInterface<T> {
9
10
  protected static _fixtures: any;
10
11
  /**
11
12
  * Inject fixtures data to backend adapter
@@ -13,12 +14,18 @@ export declare class MockAdapter<T extends BaseObject> extends AbstractAdapter i
13
14
  * @param data BackendRecordType
14
15
  */
15
16
  static inject(data: BackendRecordType): void;
17
+ static dao2backend(data: BackendRecordType): Promise<any>;
16
18
  static getFixtures(): any;
17
19
  static getFixture(key: string): any;
18
- create(dataObject: DataObject, desiredUid?: string | undefined): Promise<DataObject>;
19
- read(dataObject: DataObject): Promise<DataObject>;
20
- update(dataObject: DataObject): Promise<DataObject>;
21
- delete(dataObject: DataObject): Promise<DataObject>;
22
- query(query: Query<T>): Promise<DataObject[]>;
23
- find(dataObject: DataObject, filters?: Filters | Filter[] | undefined, pagination?: SortAndLimit | undefined): Promise<DataObject[]>;
20
+ create(dataObject: DataObjectClass): Promise<DataObjectClass>;
21
+ read(dataObject: DataObjectClass): Promise<DataObjectClass>;
22
+ update(dataObject: DataObjectClass): Promise<DataObjectClass>;
23
+ delete(dataObject: DataObjectClass): Promise<DataObjectClass>;
24
+ /**
25
+ * Process Query instance and return result
26
+ * @param query
27
+ * @returns Array
28
+ */
29
+ query(query: Query<any>): Promise<DataObjectClass[]>;
30
+ find(dataObject: DataObjectClass, filters?: Filters | Filter[] | undefined, pagination?: SortAndLimit | undefined): Promise<DataObjectClass[]>;
24
31
  }
@@ -10,35 +10,54 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MockAdapter = void 0;
13
- const _1 = require("./");
13
+ const AbstractAdapter_1 = require("./AbstractAdapter");
14
14
  const statuses_1 = require("../statuses");
15
+ const ObjectUri_1 = require("../components/ObjectUri");
15
16
  const Core_1 = require("../Core");
16
- class MockAdapter extends _1.AbstractAdapter {
17
+ const faker_1 = require("@faker-js/faker");
18
+ class MockAdapter extends AbstractAdapter_1.AbstractAdapter {
17
19
  /**
18
20
  * Inject fixtures data to backend adapter
19
21
  * Force this backend to be default one
20
22
  * @param data BackendRecordType
21
23
  */
22
24
  static inject(data) {
23
- if (data.uid) {
24
- MockAdapter._fixtures[data.uid] = data;
25
+ if (data.path) {
26
+ MockAdapter._fixtures[data.path] = this.dao2backend(data);
25
27
  Core_1.Core.defaultBackend = '@mock';
26
28
  }
27
29
  else {
28
- throw new Error(`Can't inject data without uid`);
30
+ throw new Error(`Can't inject data without a path`);
29
31
  }
30
32
  }
33
+ static dao2backend(data) {
34
+ const processed = {};
35
+ Object.keys(data).forEach((key) => {
36
+ if (data[key] !== null &&
37
+ typeof data[key] === 'object' &&
38
+ data[key].name === 'BaseObject') {
39
+ processed[key] = data[key].dataObject.uri.toReference();
40
+ }
41
+ else {
42
+ processed[key] = data[key];
43
+ }
44
+ });
45
+ return processed;
46
+ }
31
47
  static getFixtures() {
32
48
  return MockAdapter._fixtures;
33
49
  }
34
50
  static getFixture(key) {
35
51
  return MockAdapter._fixtures[key];
36
52
  }
37
- create(dataObject, desiredUid = undefined) {
38
- const uri = desiredUid ||
39
- `${dataObject.class.constructor.name.toLowerCase()}/${Date.now()}`;
40
- MockAdapter.inject(Object.assign(Object.assign({}, dataObject.toJSON()), { uid: uri }));
41
- dataObject.uri = uri;
53
+ create(dataObject) {
54
+ const uri = `${dataObject.uri.class.name.toLowerCase()}/${faker_1.faker.random.alphaNumeric(12)}`;
55
+ MockAdapter.inject(Object.assign(Object.assign({}, dataObject.toJSON()), { uid: uri, path: uri }));
56
+ if (this._params.injectMeta) {
57
+ dataObject.set('createdBy', Core_1.Core.currentUser);
58
+ dataObject.set('createdAt', Date.now());
59
+ }
60
+ dataObject.uri = new ObjectUri_1.ObjectUri(uri);
42
61
  return new Promise(() => dataObject);
43
62
  }
44
63
  read(dataObject) {
@@ -53,27 +72,73 @@ class MockAdapter extends _1.AbstractAdapter {
53
72
  });
54
73
  }
55
74
  update(dataObject) {
56
- return new Promise(() => dataObject);
75
+ return __awaiter(this, void 0, void 0, function* () {
76
+ return new Promise(() => dataObject);
77
+ });
57
78
  }
58
79
  delete(dataObject) {
59
- if (this.getParam('softDelete') === true) {
60
- dataObject.set('status', statuses_1.DELETED);
61
- MockAdapter.inject(Object.assign(Object.assign({}, dataObject.toJSON()), { uid: dataObject.uid }));
62
- }
63
- else if (dataObject.uid !== undefined) {
64
- delete MockAdapter._fixtures[dataObject.uid];
65
- dataObject.uri = undefined;
66
- }
67
- return new Promise(() => dataObject);
80
+ return __awaiter(this, void 0, void 0, function* () {
81
+ if (this.getParam('softDelete') === true) {
82
+ dataObject.set('status', statuses_1.DELETED);
83
+ MockAdapter.inject(Object.assign(Object.assign({}, dataObject.toJSON()), { uid: dataObject.uid }));
84
+ }
85
+ else if (dataObject.uid !== undefined) {
86
+ delete MockAdapter._fixtures[dataObject.uid];
87
+ dataObject.uri = new ObjectUri_1.ObjectUri();
88
+ }
89
+ return new Promise(() => dataObject);
90
+ });
68
91
  }
92
+ /**
93
+ * Process Query instance and return result
94
+ * @param query
95
+ * @returns Array
96
+ */
69
97
  query(query) {
70
98
  return __awaiter(this, void 0, void 0, function* () {
71
- return yield this.find(query.obj.dataObject, query.filters, query.sortAndLimit);
99
+ return this.find(yield query.obj.daoFactory(), query.filters, query.sortAndLimit);
72
100
  });
73
101
  }
74
102
  find(dataObject, filters = undefined, pagination = undefined) {
75
103
  return __awaiter(this, void 0, void 0, function* () {
76
- return [dataObject, dataObject];
104
+ const limit = (pagination === null || pagination === void 0 ? void 0 : pagination.limits.batch) || 1e10;
105
+ let result = [];
106
+ for (let key in MockAdapter.getFixtures()) {
107
+ let keep = true;
108
+ if (result.length <= limit) {
109
+ const dao = yield dataObject.clone(MockAdapter.getFixture(key));
110
+ if (filters) {
111
+ if (Array.isArray(filters)) {
112
+ filters.forEach((filter) => {
113
+ const prop = dao.get(filter.prop);
114
+ if (typeof prop === 'object' &&
115
+ prop.constructor.name === 'ObjectProperty') {
116
+ if (filter.value instanceof ObjectUri_1.ObjectUri &&
117
+ prop.val() !== filter.value.path) {
118
+ keep = false;
119
+ return;
120
+ }
121
+ }
122
+ else {
123
+ if (prop.val() !== filter.value) {
124
+ keep = false;
125
+ return;
126
+ }
127
+ }
128
+ });
129
+ }
130
+ }
131
+ if (keep) {
132
+ dao.uri = new ObjectUri_1.ObjectUri(key);
133
+ result.push(dao);
134
+ }
135
+ }
136
+ }
137
+ if (pagination && pagination.sortings.length > 0) {
138
+ result = result.sort((a, b) => Number(a.val(pagination.sortings[0].prop) >
139
+ b.val(pagination.sortings[0].prop)));
140
+ }
141
+ return result;
77
142
  });
78
143
  }
79
144
  }
@@ -3,8 +3,16 @@ import { Limits } from './Limits';
3
3
  import { Sorting } from './Sorting';
4
4
  import { SortAndLimit } from './SortAndLimit';
5
5
  import { BackendInterface } from './AbstractAdapter';
6
- import { BaseObject } from '../components';
7
- export declare class Query<T extends BaseObject> {
6
+ import { BaseObject } from '../components/BaseObject';
7
+ export declare const AS_OBJECTURIS = "objectUris";
8
+ export declare const AS_DATAOBJECTS = "dataObjects";
9
+ export declare const AS_INSTANCES = "classInstances";
10
+ export declare enum returnAs {
11
+ AS_OBJECTURIS = "objectUris",
12
+ AS_DATAOBJECTS = "dataObjects",
13
+ AS_INSTANCES = "classInstances"
14
+ }
15
+ export declare class Query<T extends typeof BaseObject> {
8
16
  protected _obj: T;
9
17
  protected _params: any;
10
18
  filters: Filter[];
@@ -20,5 +28,5 @@ export declare class Query<T extends BaseObject> {
20
28
  offset(offset?: number): this;
21
29
  batch(batch?: number): this;
22
30
  get sortAndLimit(): SortAndLimit;
23
- execute(backend: BackendInterface<T>): Promise<import("../components").DataObject[] | T[]>;
31
+ execute(as?: returnAs, backend?: BackendInterface<any>): Promise<any>;
24
32
  }
@@ -9,15 +9,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Query = void 0;
12
+ exports.Query = exports.returnAs = exports.AS_INSTANCES = exports.AS_DATAOBJECTS = exports.AS_OBJECTURIS = void 0;
13
13
  const Filter_1 = require("./Filter");
14
14
  const Limits_1 = require("./Limits");
15
15
  const Sorting_1 = require("./Sorting");
16
16
  const SortAndLimit_1 = require("./SortAndLimit");
17
+ const Core_1 = require("../Core");
18
+ exports.AS_OBJECTURIS = 'objectUris';
19
+ exports.AS_DATAOBJECTS = 'dataObjects';
20
+ exports.AS_INSTANCES = 'classInstances';
21
+ var returnAs;
22
+ (function (returnAs) {
23
+ returnAs["AS_OBJECTURIS"] = "objectUris";
24
+ returnAs["AS_DATAOBJECTS"] = "dataObjects";
25
+ returnAs["AS_INSTANCES"] = "classInstances";
26
+ })(returnAs = exports.returnAs || (exports.returnAs = {}));
17
27
  class Query {
18
28
  constructor(obj, params = {}) {
19
29
  this._obj = obj;
20
- //Object.keys(params).forEach((key: string) => (obj[key] = params[key]))
21
30
  this._params = params; // just in case
22
31
  this.filters = [];
23
32
  this.sortings = [];
@@ -63,9 +72,26 @@ class Query {
63
72
  get sortAndLimit() {
64
73
  return new SortAndLimit_1.SortAndLimit(this.sortings, this.limits);
65
74
  }
66
- execute(backend) {
75
+ execute(as = returnAs.AS_DATAOBJECTS, backend = Core_1.Core.getBackend()) {
67
76
  return __awaiter(this, void 0, void 0, function* () {
68
- return yield backend.find(this._obj.dataObject, this.filters, this.sortAndLimit);
77
+ try {
78
+ const result = yield backend.query(this);
79
+ switch (as) {
80
+ case exports.AS_DATAOBJECTS:
81
+ return result;
82
+ case exports.AS_OBJECTURIS:
83
+ return yield Promise.all(result.map((dao) => dao.uri));
84
+ case exports.AS_INSTANCES:
85
+ //console.log(this._obj)
86
+ return yield Promise.all(result.map((dao) => Reflect.construct(this._obj, [dao])));
87
+ default:
88
+ throw new Error(`Unknown output mode`);
89
+ }
90
+ }
91
+ catch (err) {
92
+ console.log(err);
93
+ throw err;
94
+ }
69
95
  });
70
96
  }
71
97
  }
@@ -1,23 +1,23 @@
1
- import { DataObject } from './DataObject';
1
+ import { DataObjectClass } from './types/DataObjectClass';
2
2
  import { DataObjectProperties } from '../properties/';
3
3
  export declare abstract class AbstractObject {
4
4
  static PROPS_DEFINITION: DataObjectProperties;
5
5
  static COLLECTION: string;
6
6
  static LABEL_KEY: string;
7
- protected _dataObject: DataObject;
8
- constructor(dao: DataObject);
7
+ protected _dataObject: DataObjectClass;
8
+ constructor(dao: DataObjectClass);
9
9
  get(key: string): any;
10
- set(key: string, val: any): DataObject;
10
+ set(key: string, val: any): any;
11
11
  val(key: string): any;
12
- get backend(): string | undefined;
12
+ get backend(): any;
13
13
  get path(): string;
14
- get uid(): string | undefined;
15
- get dataObject(): DataObject;
14
+ get uid(): any;
15
+ get dataObject(): DataObjectClass;
16
16
  get uri(): import("./ObjectUri").ObjectUri;
17
17
  toJSON(): {
18
- literal: string;
18
+ backend: string;
19
19
  ref: string;
20
20
  label: string | undefined;
21
21
  };
22
- save(uid?: string | undefined): Promise<DataObject>;
22
+ save(): Promise<DataObjectClass>;
23
23
  }
@@ -49,9 +49,9 @@ class AbstractObject {
49
49
  var _b;
50
50
  return typeof this.uri === 'string' ? this.uri : (_b = this.uri) === null || _b === void 0 ? void 0 : _b.toJSON();
51
51
  }
52
- save(uid = undefined) {
52
+ save() {
53
53
  return __awaiter(this, void 0, void 0, function* () {
54
- return yield this._dataObject.save(uid);
54
+ return yield this._dataObject.save();
55
55
  });
56
56
  }
57
57
  }
@@ -1,16 +1,15 @@
1
1
  import { ObjectUri } from './ObjectUri';
2
+ import { DataObjectClass } from './types/DataObjectClass';
3
+ import { BaseObjectClass } from './types/BaseObjectClass';
2
4
  import { AbstractObject } from './AbstractObject';
3
- import { DataObjectProperties } from '../properties';
4
- import { Query } from '../backends';
5
- export declare class BaseObject extends AbstractObject {
6
- static PROPS_DEFINITION: DataObjectProperties;
5
+ import { Query } from '../backends/Query';
6
+ export declare class BaseObject extends AbstractObject implements BaseObjectClass {
7
+ static PROPS_DEFINITION: any;
8
+ static getProperty(key: string): any;
7
9
  get status(): string;
8
10
  set status(status: string);
9
- static factory<T extends BaseObject>(src?: string | ObjectUri | object | undefined): Promise<T | BaseObject>;
10
- asReference(): {
11
- label: any;
12
- ref: string;
13
- uri: string;
14
- };
15
- query(): Query<this>;
11
+ static daoFactory(src?: string | ObjectUri | DataObjectClass | undefined, child?: any): Promise<DataObjectClass>;
12
+ static factory<T extends BaseObject>(src?: string | ObjectUri | DataObjectClass | undefined, child?: any): Promise<T | BaseObject>;
13
+ asReference(): any;
14
+ query(): Query<any>;
16
15
  }
@@ -10,51 +10,60 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.BaseObject = void 0;
13
- const DataObject_1 = require("./DataObject");
14
13
  const ObjectUri_1 = require("./ObjectUri");
14
+ const DataObject_1 = require("./DataObject");
15
15
  const AbstractObject_1 = require("./AbstractObject");
16
16
  const BaseObjectProperties_1 = require("./BaseObjectProperties");
17
- const backends_1 = require("../backends");
17
+ const Query_1 = require("../backends/Query");
18
18
  class BaseObject extends AbstractObject_1.AbstractObject {
19
+ static getProperty(key) {
20
+ return BaseObject.PROPS_DEFINITION.find((prop) => prop.name === key);
21
+ }
19
22
  get status() {
20
23
  return this._dataObject.val('status');
21
24
  }
22
25
  set status(status) {
23
26
  this._dataObject.set('status', status);
24
27
  }
25
- static factory(src = undefined) {
28
+ static daoFactory(src = undefined, child = this) {
26
29
  return __awaiter(this, void 0, void 0, function* () {
27
- try {
28
- // merge base properties with additional or redefined ones
29
- const base = BaseObjectProperties_1.BaseObjectProperties;
30
- // this.PROPS_DEFINITION &&
31
- this.PROPS_DEFINITION.forEach((property) => {
32
- // manage parent properties potential redeclaration
33
- const found = base.findIndex((el) => el.name === property.name);
34
- if (found !== -1) {
35
- base[found] = Object.assign(base[found], property);
36
- }
37
- else {
38
- base.push(property);
39
- }
40
- });
41
- //console.log('props to add', JSON.stringify(base))
42
- // create data object
43
- const dao = yield DataObject_1.DataObject.factory(this.prototype, base);
44
- if (src instanceof ObjectUri_1.ObjectUri) {
45
- dao.uri = src;
46
- yield dao.populate();
47
- }
48
- else if (typeof src === 'string') {
49
- dao.uri.path = src;
50
- yield dao.populate();
30
+ // merge base properties with additional or redefined ones
31
+ const base = BaseObjectProperties_1.BaseObjectProperties;
32
+ // this.PROPS_DEFINITION &&
33
+ this.PROPS_DEFINITION.forEach((property) => {
34
+ // manage parent properties potential redeclaration
35
+ const found = base.findIndex((el) => el.name === property.name);
36
+ if (found !== -1) {
37
+ base[found] = Object.assign(base[found], property);
51
38
  }
52
- else if (src instanceof Object) {
53
- dao.uri = new ObjectUri_1.ObjectUri(`${this.COLLECTION}${ObjectUri_1.ObjectUri.DEFAULT}`, Reflect.get(src, 'name'));
54
- dao.uri.collection = this.COLLECTION;
55
- yield dao.populate(src);
39
+ else {
40
+ base.push(property);
56
41
  }
57
- return new this(dao);
42
+ });
43
+ // create data object
44
+ const dao = yield DataObject_1.DataObject.factory({ properties: base });
45
+ dao.uri.class = child;
46
+ if (src instanceof ObjectUri_1.ObjectUri) {
47
+ dao.uri = src;
48
+ yield dao.read();
49
+ }
50
+ else if (typeof src === 'string') {
51
+ dao.uri.path = src;
52
+ yield dao.read();
53
+ }
54
+ else if (src instanceof Object) {
55
+ dao.uri = new ObjectUri_1.ObjectUri(`${this.COLLECTION}${ObjectUri_1.ObjectUri.DEFAULT}`, Reflect.get(src, 'name'));
56
+ dao.uri.collection = this.COLLECTION;
57
+ yield dao.populate(src);
58
+ }
59
+ return dao;
60
+ });
61
+ }
62
+ static factory(src = undefined, child = this) {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ try {
65
+ const dao = yield this.daoFactory(src);
66
+ return Reflect.construct(this, [dao]);
58
67
  }
59
68
  catch (err) {
60
69
  console.log(err.message);
@@ -66,7 +75,7 @@ class BaseObject extends AbstractObject_1.AbstractObject {
66
75
  return this._dataObject.toReference();
67
76
  }
68
77
  query() {
69
- return new backends_1.Query(this);
78
+ return new Query_1.Query(this.constructor.prototype);
70
79
  }
71
80
  }
72
81
  exports.BaseObject = BaseObject;
@@ -1,15 +1,14 @@
1
- import { DataObjectProperties } from '../properties';
2
1
  import * as statuses from '../statuses';
3
- import { User } from './User';
2
+ import { UserClass } from './types/UserClass';
4
3
  import { ObjectUri } from './ObjectUri';
5
4
  export interface BaseObjectType {
6
5
  name: string;
7
6
  status: typeof statuses.CREATED | typeof statuses.PENDING | typeof statuses.ACTIVE | typeof statuses.DELETED;
8
- createdBy?: User | ObjectUri;
7
+ createdBy?: UserClass | ObjectUri;
9
8
  createdAt?: number;
10
- updatedBy?: User | ObjectUri;
9
+ updatedBy?: UserClass | ObjectUri;
11
10
  updatedAt?: number;
12
- deletedBy?: User | ObjectUri;
11
+ deletedBy?: UserClass | ObjectUri;
13
12
  deletedAt?: number;
14
13
  }
15
- export declare const BaseObjectProperties: DataObjectProperties;
14
+ export declare const BaseObjectProperties: any;
@@ -24,20 +24,23 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.BaseObjectProperties = void 0;
27
- const Property_1 = require("../properties/Property");
28
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");
29
32
  exports.BaseObjectProperties = [
30
33
  {
31
34
  name: 'name',
32
35
  mandatory: true,
33
- type: Property_1.Property.TYPE_STRING,
36
+ type: StringProperty_1.StringProperty.TYPE,
34
37
  minLength: 1,
35
38
  maxLength: 100,
36
39
  },
37
40
  {
38
41
  name: 'status',
39
42
  mandatory: true,
40
- type: Property_1.Property.TYPE_ENUM,
43
+ type: EnumProperty_1.EnumProperty.TYPE,
41
44
  values: [
42
45
  statuses.CREATED,
43
46
  statuses.PENDING,
@@ -48,35 +51,35 @@ exports.BaseObjectProperties = [
48
51
  },
49
52
  {
50
53
  name: 'createdBy',
51
- type: Property_1.Property.TYPE_OBJECT,
54
+ type: ObjectProperty_1.ObjectProperty.TYPE,
52
55
  instanceOf: 'User',
53
56
  mandatory: true,
54
57
  protected: true,
55
58
  },
56
59
  {
57
60
  name: 'createdAt',
58
- type: Property_1.Property.TYPE_DATETIME,
61
+ type: DateTimeProperty_1.DateTimeProperty.TYPE,
59
62
  mandatory: true,
60
63
  protected: true,
61
64
  },
62
65
  {
63
66
  name: 'updatedBy',
64
- type: Property_1.Property.TYPE_OBJECT,
67
+ type: ObjectProperty_1.ObjectProperty.TYPE,
65
68
  instanceOf: 'User',
66
69
  },
67
70
  {
68
71
  name: 'updatedAt',
69
- type: Property_1.Property.TYPE_DATETIME,
72
+ type: DateTimeProperty_1.DateTimeProperty.TYPE,
70
73
  },
71
74
  {
72
75
  name: 'deletedBy',
73
- type: Property_1.Property.TYPE_OBJECT,
76
+ type: ObjectProperty_1.ObjectProperty.TYPE,
74
77
  instanceOf: 'User',
75
78
  protected: true,
76
79
  },
77
80
  {
78
81
  name: 'deletedAt',
79
- type: Property_1.Property.TYPE_DATETIME,
82
+ type: DateTimeProperty_1.DateTimeProperty.TYPE,
80
83
  protected: true,
81
84
  },
82
85
  ];