@quatrain/core 1.0.0-beta8 → 1.0.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.
- package/lib/Core.d.ts +4 -10
- package/lib/Core.js +25 -14
- package/lib/components/AbstractObject.d.ts +1 -1
- package/lib/components/BaseObjectCore.d.ts +5 -45
- package/lib/components/BaseObjectCore.js +45 -63
- package/lib/components/DataObject.d.ts +3 -7
- package/lib/components/DataObject.js +14 -43
- package/lib/components/ObjectUri.d.ts +23 -4
- package/lib/components/ObjectUri.js +47 -18
- package/lib/components/index.d.ts +1 -3
- package/lib/components/index.js +1 -8
- package/lib/index.d.ts +5 -15
- package/lib/index.js +7 -33
- package/lib/properties/ArrayProperty.js +3 -0
- package/lib/properties/BaseProperty.js +2 -2
- package/lib/properties/CollectionProperty.d.ts +1 -16
- package/lib/properties/CollectionProperty.js +0 -41
- package/lib/properties/FileProperty.d.ts +10 -0
- package/lib/properties/FileProperty.js +12 -0
- package/lib/properties/ObjectProperty.d.ts +7 -0
- package/lib/properties/ObjectProperty.js +17 -10
- package/lib/properties/Property.d.ts +3 -1
- package/lib/properties/Property.js +4 -0
- package/lib/properties/index.d.ts +2 -1
- package/lib/properties/index.js +3 -1
- package/package.json +4 -2
- package/lib/Auth.d.ts +0 -25
- package/lib/Auth.js +0 -9
- package/lib/Backend.d.ts +0 -38
- package/lib/Backend.js +0 -10
- package/lib/authentication/AbstractAuthAdapter.d.ts +0 -21
- package/lib/authentication/AbstractAuthAdapter.js +0 -28
- package/lib/authentication/AuthenticationError.d.ts +0 -2
- package/lib/authentication/AuthenticationError.js +0 -6
- package/lib/authentication/index.d.ts +0 -4
- package/lib/authentication/index.js +0 -7
- package/lib/authentication/middlewares/AbstractAuthMiddleware.d.ts +0 -0
- package/lib/authentication/middlewares/AbstractAuthMiddleware.js +0 -1
- package/lib/authentication/middlewares/Middleware.d.ts +0 -5
- package/lib/authentication/middlewares/Middleware.js +0 -2
- package/lib/authentication/types/AuthInterface.d.ts +0 -9
- package/lib/authentication/types/AuthInterface.js +0 -2
- package/lib/backends/AbstractAdapter.d.ts +0 -42
- package/lib/backends/AbstractAdapter.js +0 -86
- package/lib/backends/BackendError.d.ts +0 -2
- package/lib/backends/BackendError.js +0 -6
- package/lib/backends/Filter.d.ts +0 -17
- package/lib/backends/Filter.js +0 -14
- package/lib/backends/FilterOperators.d.ts +0 -13
- package/lib/backends/FilterOperators.js +0 -16
- package/lib/backends/Filters.d.ts +0 -11
- package/lib/backends/Filters.js +0 -14
- package/lib/backends/Limits.d.ts +0 -9
- package/lib/backends/Limits.js +0 -10
- package/lib/backends/MockAdapter.d.ts +0 -25
- package/lib/backends/MockAdapter.js +0 -189
- package/lib/backends/NotFoundError.d.ts +0 -2
- package/lib/backends/NotFoundError.js +0 -6
- package/lib/backends/Query.d.ts +0 -54
- package/lib/backends/Query.js +0 -131
- package/lib/backends/SortAndLimit.d.ts +0 -11
- package/lib/backends/SortAndLimit.js +0 -11
- package/lib/backends/Sorting.d.ts +0 -9
- package/lib/backends/Sorting.js +0 -10
- package/lib/backends/index.d.ts +0 -12
- package/lib/backends/index.js +0 -46
- package/lib/backends/middlewares/AbstractMiddleware.d.ts +0 -0
- package/lib/backends/middlewares/AbstractMiddleware.js +0 -1
- package/lib/backends/middlewares/InjectKeywordsMiddleware.d.ts +0 -9
- package/lib/backends/middlewares/InjectKeywordsMiddleware.js +0 -47
- package/lib/backends/middlewares/InjectMetaMiddleware.d.ts +0 -13
- package/lib/backends/middlewares/InjectMetaMiddleware.js +0 -33
- package/lib/backends/middlewares/Middleware.d.ts +0 -5
- package/lib/backends/middlewares/Middleware.js +0 -2
- package/lib/backends/middlewares/types/MiddlewareParams.d.ts +0 -3
- package/lib/backends/middlewares/types/MiddlewareParams.js +0 -2
- package/lib/backends/types/BackendInterface.d.ts +0 -13
- package/lib/backends/types/BackendInterface.js +0 -2
- package/lib/backends/types/CollectionHierarchy.d.ts +0 -3
- package/lib/backends/types/CollectionHierarchy.js +0 -6
- package/lib/components/BaseRepository.d.ts +0 -25
- package/lib/components/BaseRepository.js +0 -132
- package/lib/components/EntityRepository.d.ts +0 -6
- package/lib/components/EntityRepository.js +0 -14
- package/lib/components/UserRepository.d.ts +0 -7
- package/lib/components/UserRepository.js +0 -36
- package/lib/components/types/RepositoryClass.d.ts +0 -40
- package/lib/components/types/RepositoryClass.js +0 -2
- package/lib/utils/DataGenerator.d.ts +0 -9
- package/lib/utils/DataGenerator.js +0 -102
- package/lib/utils/index.d.ts +0 -2
- package/lib/utils/index.js +0 -5
package/lib/Core.d.ts
CHANGED
|
@@ -1,28 +1,22 @@
|
|
|
1
|
-
import { AbstractAuthAdapter } from './authentication';
|
|
2
|
-
import { AbstractAdapter } from './backends/AbstractAdapter';
|
|
3
1
|
import { User } from './components/User';
|
|
4
2
|
import { DataObjectClass } from './components/types/DataObjectClass';
|
|
5
|
-
export type BackendRegistry<T extends AbstractAdapter> = {
|
|
6
|
-
[x: string]: T;
|
|
7
|
-
};
|
|
8
3
|
export declare class Core {
|
|
9
|
-
static
|
|
4
|
+
static storage: any;
|
|
5
|
+
static storagePrefix: string;
|
|
10
6
|
static userClass: typeof User;
|
|
11
7
|
static classRegistry: {
|
|
12
8
|
[key: string]: any;
|
|
13
9
|
};
|
|
14
10
|
static logger: Console;
|
|
15
|
-
static auth: AbstractAuthAdapter;
|
|
16
11
|
static timestamp: () => string;
|
|
17
|
-
protected static _backends: BackendRegistry<any>;
|
|
18
12
|
static definition(key: string): {
|
|
19
13
|
manifest: {
|
|
20
14
|
type: StringConstructor;
|
|
21
15
|
mandatory: boolean;
|
|
22
16
|
};
|
|
23
17
|
};
|
|
24
|
-
static
|
|
25
|
-
static
|
|
18
|
+
static addConfig(key: string, value: any): Promise<void>;
|
|
19
|
+
static getConfig(key: string): Promise<any>;
|
|
26
20
|
static addClass(name: string, obj: any): void;
|
|
27
21
|
static getClass(name: string): any;
|
|
28
22
|
/**
|
package/lib/Core.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.Core = void 0;
|
|
4
13
|
const DataObject_1 = require("./components/DataObject");
|
|
@@ -12,19 +21,21 @@ class Core {
|
|
|
12
21
|
},
|
|
13
22
|
};
|
|
14
23
|
}
|
|
15
|
-
static
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
24
|
+
static addConfig(key, value) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
if (!this.storage.set) {
|
|
27
|
+
yield this.storage.init();
|
|
28
|
+
}
|
|
29
|
+
yield this.storage.set(`${this.storagePrefix}_${key}`, value);
|
|
30
|
+
});
|
|
20
31
|
}
|
|
21
|
-
static
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
32
|
+
static getConfig(key) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
if (!this.storage.get) {
|
|
35
|
+
yield this.storage.init();
|
|
36
|
+
}
|
|
37
|
+
return yield this.storage.get(`${this.storagePrefix}_${key}`);
|
|
38
|
+
});
|
|
28
39
|
}
|
|
29
40
|
static addClass(name, obj) {
|
|
30
41
|
Core.classRegistry[name] = obj;
|
|
@@ -51,10 +62,10 @@ class Core {
|
|
|
51
62
|
}
|
|
52
63
|
}
|
|
53
64
|
exports.Core = Core;
|
|
54
|
-
Core.
|
|
65
|
+
Core.storage = require('node-persist');
|
|
66
|
+
Core.storagePrefix = 'core';
|
|
55
67
|
Core.userClass = User_1.User;
|
|
56
68
|
Core.classRegistry = {};
|
|
57
69
|
Core.logger = console;
|
|
58
70
|
// How timestamp are formatted
|
|
59
71
|
Core.timestamp = () => new Date().toISOString();
|
|
60
|
-
Core._backends = {};
|
|
@@ -1,36 +1,8 @@
|
|
|
1
|
-
import { ObjectUri } from '
|
|
2
|
-
import { DataObjectClass } from './types/DataObjectClass';
|
|
3
|
-
import { BaseObjectClass } from './types/BaseObjectClass';
|
|
1
|
+
import { ObjectUri, DataObjectClass, DataObject, BaseObject } from '../';
|
|
4
2
|
import { AbstractObject } from './AbstractObject';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import { Persisted } from './types/Persisted';
|
|
9
|
-
import { Proxy } from './types/ProxyConstructor';
|
|
10
|
-
import { DataObjectProperties } from '../properties';
|
|
11
|
-
export declare class BaseObjectCore extends AbstractObject implements BaseObjectClass {
|
|
12
|
-
static PROPS_DEFINITION: DataObjectProperties;
|
|
13
|
-
static getProperty(key: string): (import("../properties").NumberPropertyType & {
|
|
14
|
-
type: string;
|
|
15
|
-
}) | (import("../properties").BooleanPropertyType & {
|
|
16
|
-
type: string;
|
|
17
|
-
}) | (import("../properties").EnumPropertyType & {
|
|
18
|
-
type: string;
|
|
19
|
-
}) | (import("../properties").ObjectPropertyType & {
|
|
20
|
-
type: string;
|
|
21
|
-
}) | (import("../properties").StringPropertyType & {
|
|
22
|
-
type: string;
|
|
23
|
-
}) | (import("../properties").HashPropertyType & {
|
|
24
|
-
type: string;
|
|
25
|
-
}) | (import("../properties").DateTimeProperty & {
|
|
26
|
-
type: string;
|
|
27
|
-
}) | (import("../properties").ArrayPropertyType & {
|
|
28
|
-
type: string;
|
|
29
|
-
}) | (import("../properties").MapPropertyType & {
|
|
30
|
-
type: string;
|
|
31
|
-
}) | (import("../properties").CollectionPropertyType & {
|
|
32
|
-
type: string;
|
|
33
|
-
}) | undefined;
|
|
3
|
+
export declare class BaseObjectCore extends AbstractObject {
|
|
4
|
+
static PROPS_DEFINITION: any;
|
|
5
|
+
static getProperty(key: string): any;
|
|
34
6
|
static fillProperties(child?: any): DataObject;
|
|
35
7
|
static daoFactory(src?: string | ObjectUri | DataObjectClass<any> | undefined, child?: any): Promise<DataObjectClass<any>>;
|
|
36
8
|
/**
|
|
@@ -46,7 +18,7 @@ export declare class BaseObjectCore extends AbstractObject implements BaseObject
|
|
|
46
18
|
* @param path
|
|
47
19
|
* @returns
|
|
48
20
|
*/
|
|
49
|
-
static fromBackend<T>(path: string): Promise<
|
|
21
|
+
static fromBackend<T>(path: string): Promise<T>;
|
|
50
22
|
/**
|
|
51
23
|
* Instantiates from a DataObject
|
|
52
24
|
* @param dao
|
|
@@ -57,17 +29,5 @@ export declare class BaseObjectCore extends AbstractObject implements BaseObject
|
|
|
57
29
|
* Wrap instance into proxy to get access to properties
|
|
58
30
|
* @returns Proxy
|
|
59
31
|
*/
|
|
60
|
-
protected toProxy<T extends BaseObject>(): Proxy<Proxy<T>>;
|
|
61
32
|
asReference(): any;
|
|
62
|
-
/**
|
|
63
|
-
* Create a query based on given class where parent is current instance
|
|
64
|
-
* @param obj
|
|
65
|
-
* @returns Query
|
|
66
|
-
*/
|
|
67
|
-
query(obj: any): Query<any>;
|
|
68
|
-
/**
|
|
69
|
-
* Create a query based on current class
|
|
70
|
-
* @returns Query
|
|
71
|
-
*/
|
|
72
|
-
static query(): Query<typeof BaseObjectCore>;
|
|
73
33
|
}
|
|
@@ -10,12 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.BaseObjectCore = void 0;
|
|
13
|
-
const
|
|
13
|
+
const __1 = require("../");
|
|
14
14
|
const AbstractObject_1 = require("./AbstractObject");
|
|
15
|
-
const BaseObject_1 = require("./BaseObject");
|
|
16
|
-
const Query_1 = require("../backends/Query");
|
|
17
|
-
const DataObject_1 = require("./DataObject");
|
|
18
|
-
const ProxyConstructor_1 = require("./types/ProxyConstructor");
|
|
19
15
|
class BaseObjectCore extends AbstractObject_1.AbstractObject {
|
|
20
16
|
static getProperty(key) {
|
|
21
17
|
return BaseObjectCore.PROPS_DEFINITION.find((prop) => prop.name === key);
|
|
@@ -33,7 +29,7 @@ class BaseObjectCore extends AbstractObject_1.AbstractObject {
|
|
|
33
29
|
base.push(property);
|
|
34
30
|
}
|
|
35
31
|
});
|
|
36
|
-
const dao =
|
|
32
|
+
const dao = __1.DataObject.factory({
|
|
37
33
|
properties: base,
|
|
38
34
|
parentProp: this.PARENT_PROP,
|
|
39
35
|
});
|
|
@@ -43,7 +39,7 @@ class BaseObjectCore extends AbstractObject_1.AbstractObject {
|
|
|
43
39
|
static daoFactory(src = undefined, child = this) {
|
|
44
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45
41
|
const dao = this.fillProperties(child);
|
|
46
|
-
if (src instanceof
|
|
42
|
+
if (src instanceof __1.ObjectUri) {
|
|
47
43
|
dao.uri = src;
|
|
48
44
|
yield dao.read();
|
|
49
45
|
}
|
|
@@ -62,7 +58,7 @@ class BaseObjectCore extends AbstractObject_1.AbstractObject {
|
|
|
62
58
|
*/
|
|
63
59
|
static fromObject(src, child = this) {
|
|
64
60
|
const dao = this.fillProperties(child);
|
|
65
|
-
dao.uri = new
|
|
61
|
+
dao.uri = new __1.ObjectUri(`${this.COLLECTION}${__1.ObjectUri.DEFAULT}`, Reflect.get(src, 'name'));
|
|
66
62
|
dao.uri.class = child;
|
|
67
63
|
dao.populateFromData(src);
|
|
68
64
|
const obj = new this(dao);
|
|
@@ -71,12 +67,12 @@ class BaseObjectCore extends AbstractObject_1.AbstractObject {
|
|
|
71
67
|
static factory(src = undefined, child = this) {
|
|
72
68
|
return __awaiter(this, void 0, void 0, function* () {
|
|
73
69
|
try {
|
|
74
|
-
if (typeof src == 'object' && !(src instanceof
|
|
70
|
+
if (typeof src == 'object' && !(src instanceof __1.ObjectUri)) {
|
|
75
71
|
return this.fromObject(src);
|
|
76
72
|
}
|
|
77
73
|
const dao = yield this.daoFactory(src, child);
|
|
78
74
|
const constructedObject = Reflect.construct(this, [dao]);
|
|
79
|
-
return constructedObject
|
|
75
|
+
return constructedObject;
|
|
80
76
|
}
|
|
81
77
|
catch (err) {
|
|
82
78
|
throw new Error(`Unable to build instance for '${this.name}': ${err.message}`);
|
|
@@ -109,61 +105,47 @@ class BaseObjectCore extends AbstractObject_1.AbstractObject {
|
|
|
109
105
|
* Wrap instance into proxy to get access to properties
|
|
110
106
|
* @returns Proxy
|
|
111
107
|
*/
|
|
112
|
-
toProxy() {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
108
|
+
// protected toProxy<T extends BaseObject>() {
|
|
109
|
+
// return new ProxyConstructor<this, Proxy<T>>(this, {
|
|
110
|
+
// get: (target, prop) => {
|
|
111
|
+
// if (prop === 'uid') {
|
|
112
|
+
// return target.uid
|
|
113
|
+
// }
|
|
114
|
+
// if (prop === 'uri') {
|
|
115
|
+
// return target.uri
|
|
116
|
+
// }
|
|
117
|
+
// if (prop == 'toJSON') {
|
|
118
|
+
// return target.toJSON
|
|
119
|
+
// }
|
|
120
|
+
// if (prop == 'save') {
|
|
121
|
+
// return target.save
|
|
122
|
+
// }
|
|
123
|
+
// if (prop == 'constructor') {
|
|
124
|
+
// return target.constructor
|
|
125
|
+
// }
|
|
126
|
+
// if (prop === 'core') {
|
|
127
|
+
// return target
|
|
128
|
+
// }
|
|
129
|
+
// // i don't know why and i shouldn't have to wonder why
|
|
130
|
+
// // but everything crashes unless we do this terribleness
|
|
131
|
+
// if (prop == 'then') {
|
|
132
|
+
// return
|
|
133
|
+
// }
|
|
134
|
+
// return target.val(prop as string)
|
|
135
|
+
// },
|
|
136
|
+
// set(target, prop, newValue) {
|
|
137
|
+
// if (prop === 'uid' || prop === 'core') {
|
|
138
|
+
// throw new Error(`Property '${prop}' is readonly`)
|
|
139
|
+
// }
|
|
140
|
+
// target.set(prop as string, newValue)
|
|
141
|
+
// return true
|
|
142
|
+
// },
|
|
143
|
+
// })
|
|
144
|
+
// }
|
|
149
145
|
asReference() {
|
|
150
146
|
return this._dataObject.toReference();
|
|
151
147
|
}
|
|
152
|
-
/**
|
|
153
|
-
* Create a query based on given class where parent is current instance
|
|
154
|
-
* @param obj
|
|
155
|
-
* @returns Query
|
|
156
|
-
*/
|
|
157
|
-
query(obj) {
|
|
158
|
-
return new Query_1.Query(obj, this);
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Create a query based on current class
|
|
162
|
-
* @returns Query
|
|
163
|
-
*/
|
|
164
|
-
static query() {
|
|
165
|
-
return new Query_1.Query(this);
|
|
166
|
-
}
|
|
167
148
|
}
|
|
168
149
|
exports.BaseObjectCore = BaseObjectCore;
|
|
169
|
-
|
|
150
|
+
// implements BaseObjectClass {
|
|
151
|
+
BaseObjectCore.PROPS_DEFINITION = __1.BaseObjectProperties;
|
|
@@ -26,8 +26,8 @@ export declare class DataObject implements DataObjectClass<any> {
|
|
|
26
26
|
protected _objectUri: ObjectUri;
|
|
27
27
|
protected _uid: string | undefined;
|
|
28
28
|
protected _properties: Properties;
|
|
29
|
-
protected _persisted: boolean;
|
|
30
29
|
protected _populated: boolean;
|
|
30
|
+
protected _persisted: boolean;
|
|
31
31
|
protected _parentProp: string | undefined;
|
|
32
32
|
protected _proxied: any;
|
|
33
33
|
/**
|
|
@@ -40,6 +40,7 @@ export declare class DataObject implements DataObjectClass<any> {
|
|
|
40
40
|
*/
|
|
41
41
|
protected constructor(params: DataObjectParams | undefined);
|
|
42
42
|
protected _init(properties: any[]): void;
|
|
43
|
+
isPersisted(): boolean;
|
|
43
44
|
/**
|
|
44
45
|
* Wrap instance into proxy to get access to properties
|
|
45
46
|
* @returns Proxy
|
|
@@ -68,13 +69,7 @@ export declare class DataObject implements DataObjectClass<any> {
|
|
|
68
69
|
populateFromData(data: {
|
|
69
70
|
[x: string]: unknown;
|
|
70
71
|
}): this;
|
|
71
|
-
/**
|
|
72
|
-
* Populate data object from backend query
|
|
73
|
-
* @param data
|
|
74
|
-
*/
|
|
75
|
-
populateFromBackend(): Promise<DataObject>;
|
|
76
72
|
isPopulated(): boolean;
|
|
77
|
-
isPersisted(): boolean;
|
|
78
73
|
get properties(): Properties;
|
|
79
74
|
get backend(): string | undefined;
|
|
80
75
|
get path(): string;
|
|
@@ -85,6 +80,7 @@ export declare class DataObject implements DataObjectClass<any> {
|
|
|
85
80
|
get uri(): ObjectUri;
|
|
86
81
|
get class(): any;
|
|
87
82
|
get parentProp(): string | undefined;
|
|
83
|
+
set parentProp(str: string | undefined);
|
|
88
84
|
has(key: string): boolean;
|
|
89
85
|
/**
|
|
90
86
|
* Returns property matching key or throw
|
|
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.DataObject = void 0;
|
|
13
|
-
const Core_1 = require("../Core");
|
|
14
13
|
const Property_1 = require("../properties/Property");
|
|
15
14
|
const ObjectUri_1 = require("./ObjectUri");
|
|
16
15
|
const ResourcesErrors_1 = require("../common/ResourcesErrors");
|
|
@@ -27,8 +26,8 @@ class DataObject {
|
|
|
27
26
|
constructor(params) {
|
|
28
27
|
this._uid = undefined;
|
|
29
28
|
this._properties = {};
|
|
30
|
-
this._persisted = false;
|
|
31
29
|
this._populated = false;
|
|
30
|
+
this._persisted = false;
|
|
32
31
|
/**
|
|
33
32
|
* Has data been modified since last backend operation?
|
|
34
33
|
*/
|
|
@@ -54,6 +53,9 @@ class DataObject {
|
|
|
54
53
|
this._properties[prop.name] = Property_1.Property.factory(prop, this);
|
|
55
54
|
});
|
|
56
55
|
}
|
|
56
|
+
isPersisted() {
|
|
57
|
+
return this._persisted;
|
|
58
|
+
}
|
|
57
59
|
/**
|
|
58
60
|
* Wrap instance into proxy to get access to properties
|
|
59
61
|
* @returns Proxy
|
|
@@ -108,9 +110,8 @@ class DataObject {
|
|
|
108
110
|
if (this._populated === false) {
|
|
109
111
|
if (data) {
|
|
110
112
|
this.populateFromData(data);
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
yield this.populateFromBackend();
|
|
113
|
+
// } else if (this.path !== '/' && this.path !== '') {
|
|
114
|
+
// await this.populateFromBackend()
|
|
114
115
|
}
|
|
115
116
|
this._populated = true;
|
|
116
117
|
if (Reflect.get(this._properties, 'name')) {
|
|
@@ -150,30 +151,9 @@ class DataObject {
|
|
|
150
151
|
}
|
|
151
152
|
return this;
|
|
152
153
|
}
|
|
153
|
-
/**
|
|
154
|
-
* Populate data object from backend query
|
|
155
|
-
* @param data
|
|
156
|
-
*/
|
|
157
|
-
populateFromBackend() {
|
|
158
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
159
|
-
if (this._populated === false) {
|
|
160
|
-
if (this.path !== '/' && this.path !== '') {
|
|
161
|
-
yield Core_1.Core.getBackend(this._objectUri.backend).read(this);
|
|
162
|
-
}
|
|
163
|
-
this._populated = true;
|
|
164
|
-
if (Reflect.get(this._properties, 'name')) {
|
|
165
|
-
this.uri.label = this.val('name');
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
return this;
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
154
|
isPopulated() {
|
|
172
155
|
return this._populated;
|
|
173
156
|
}
|
|
174
|
-
isPersisted() {
|
|
175
|
-
return this._persisted;
|
|
176
|
-
}
|
|
177
157
|
get properties() {
|
|
178
158
|
return this._properties;
|
|
179
159
|
}
|
|
@@ -198,7 +178,7 @@ class DataObject {
|
|
|
198
178
|
set uri(uri) {
|
|
199
179
|
this._objectUri = uri;
|
|
200
180
|
if (this._objectUri.collection !== ObjectUri_1.ObjectUri.MISSING_COLLECTION) {
|
|
201
|
-
this._persisted = true
|
|
181
|
+
// this._persisted = true
|
|
202
182
|
}
|
|
203
183
|
}
|
|
204
184
|
get uri() {
|
|
@@ -211,6 +191,9 @@ class DataObject {
|
|
|
211
191
|
get parentProp() {
|
|
212
192
|
return this._parentProp;
|
|
213
193
|
}
|
|
194
|
+
set parentProp(str) {
|
|
195
|
+
this._parentProp = str;
|
|
196
|
+
}
|
|
214
197
|
has(key) {
|
|
215
198
|
return Reflect.has(this._properties, key);
|
|
216
199
|
}
|
|
@@ -268,7 +251,7 @@ class DataObject {
|
|
|
268
251
|
const prop = Reflect.get(this._properties, key);
|
|
269
252
|
if (ignoreUnchanged && prop.hasChanged === false)
|
|
270
253
|
return;
|
|
271
|
-
console.log(prop.constructor.name);
|
|
254
|
+
// console.log(prop.constructor.name);
|
|
272
255
|
switch (prop.constructor.name) {
|
|
273
256
|
case 'CollectionProperty':
|
|
274
257
|
// ignore
|
|
@@ -301,27 +284,15 @@ class DataObject {
|
|
|
301
284
|
}
|
|
302
285
|
read() {
|
|
303
286
|
return __awaiter(this, void 0, void 0, function* () {
|
|
304
|
-
|
|
305
|
-
return yield Core_1.Core.getBackend().read(this); //this.populate()
|
|
306
|
-
}
|
|
307
|
-
catch (err) {
|
|
308
|
-
console.log(err.message);
|
|
309
|
-
throw new Error(err.message);
|
|
310
|
-
}
|
|
287
|
+
throw new Error(`This is just a stub, please use DataObject from @quatrain/backend to persist`);
|
|
311
288
|
});
|
|
312
289
|
}
|
|
313
290
|
save() {
|
|
314
|
-
|
|
315
|
-
this._persisted = true;
|
|
316
|
-
this._modified = false;
|
|
317
|
-
return this.uid ? backend.update(this) : backend.create(this);
|
|
291
|
+
throw new Error(`This is just a stub, please use DataObject from @quatrain/backend to persist`);
|
|
318
292
|
}
|
|
319
293
|
delete() {
|
|
320
294
|
return __awaiter(this, void 0, void 0, function* () {
|
|
321
|
-
|
|
322
|
-
this._persisted = false;
|
|
323
|
-
this._modified = false;
|
|
324
|
-
return yield backend.delete(this);
|
|
295
|
+
throw new Error(`This is just a stub, please use DataObject from @quatrain/backend to persist`);
|
|
325
296
|
});
|
|
326
297
|
}
|
|
327
298
|
/**
|
|
@@ -4,25 +4,44 @@ export declare class ObjectUri {
|
|
|
4
4
|
protected _str: string;
|
|
5
5
|
protected _pairs: Array<string>;
|
|
6
6
|
protected _literal: string;
|
|
7
|
-
protected _backend: string;
|
|
7
|
+
protected _backend: string | undefined;
|
|
8
8
|
protected _path: string;
|
|
9
9
|
protected _uid: string | undefined;
|
|
10
10
|
protected _collection: string | undefined;
|
|
11
11
|
protected _label: string | undefined;
|
|
12
12
|
protected _objClass: any;
|
|
13
|
+
protected _parent: ObjectUri | undefined;
|
|
13
14
|
/**
|
|
14
15
|
* create object uri from string:
|
|
15
16
|
* ex: 'xyz', '@backend:xyz', 'collection/xyz', '@backend:collection/xyz'
|
|
16
17
|
* some backends will need a collection or table name, some may deduct it from object
|
|
17
|
-
* @param str
|
|
18
|
+
* @param str partial or full resource path
|
|
19
|
+
* @param label optional label to describe path
|
|
18
20
|
*/
|
|
19
21
|
constructor(str?: string, label?: string | undefined);
|
|
20
22
|
set class(objClass: any);
|
|
21
23
|
get class(): any;
|
|
22
|
-
get backend(): string;
|
|
24
|
+
get backend(): string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Returns the full path of the resource
|
|
27
|
+
* including optional parents' path
|
|
28
|
+
* @returns string
|
|
29
|
+
*/
|
|
23
30
|
get path(): string;
|
|
31
|
+
/**
|
|
32
|
+
* Returns the own path of the resource
|
|
33
|
+
* without the optional parents' paths
|
|
34
|
+
* @returns string
|
|
35
|
+
*/
|
|
36
|
+
get ownPath(): string;
|
|
37
|
+
get parent(): ObjectUri | undefined;
|
|
24
38
|
set label(label: string | undefined);
|
|
25
39
|
get label(): string | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Return the full path litteral
|
|
42
|
+
* including the backend alias
|
|
43
|
+
* @returns string
|
|
44
|
+
*/
|
|
26
45
|
get literal(): string;
|
|
27
46
|
set path(path: string);
|
|
28
47
|
get uid(): string | undefined;
|
|
@@ -38,7 +57,7 @@ export declare class ObjectUri {
|
|
|
38
57
|
label: string | undefined;
|
|
39
58
|
};
|
|
40
59
|
toJSON(): {
|
|
41
|
-
backend: string;
|
|
60
|
+
backend: string | undefined;
|
|
42
61
|
ref: string;
|
|
43
62
|
label: string;
|
|
44
63
|
};
|