@quatrain/core 1.0.0-beta22 → 1.0.0-beta24
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/Backend copy.d.ts +39 -0
- package/lib/Backend copy.js +11 -0
- package/lib/Core.d.ts +0 -4
- package/lib/Core.js +6 -18
- package/lib/Storage.d.ts +13 -0
- package/lib/Storage.js +2 -0
- package/lib/backends/Query.d.ts +3 -1
- package/lib/backends/Query.js +1 -3
- package/lib/backends/types/BackendInterface.d.ts +1 -1
- package/lib/components/BaseRepository.d.ts +1 -1
- package/lib/components/BaseRepository.js +11 -5
- package/lib/components/DataObject.d.ts +1 -0
- package/lib/components/DataObject.js +3 -0
- package/lib/components/ObjectUri.js +2 -2
- package/lib/index.d.ts +1 -8
- package/lib/index.js +1 -3
- package/lib/properties/ArrayProperty.js +3 -0
- package/lib/properties/FileProperty.d.ts +10 -0
- package/lib/properties/FileProperty.js +12 -0
- package/lib/properties/ObjectProperty copy.d.ts +16 -0
- package/lib/properties/ObjectProperty copy.js +85 -0
- package/lib/properties/ObjectProperty.d.ts +1 -0
- package/lib/properties/ObjectProperty.js +3 -2
- 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/lib/storages/AbstractStorageAdapter.d.ts +7 -1
- package/lib/storages/AbstractStorageAdapter.js +6 -0
- package/lib/storages/StorageAdapterInterface.d.ts +4 -3
- package/lib/storages/index.d.ts +2 -1
- package/lib/storages/index.js +13 -1
- package/lib/storages/types/DownloadFileMetaType.d.ts +4 -0
- package/lib/storages/types/DownloadFileMetaType.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import Middleware from './backends/middlewares/Middleware';
|
|
2
|
+
export declare enum BackendAction {
|
|
3
|
+
CREATE = "create",
|
|
4
|
+
READ = "read",
|
|
5
|
+
UPDATE = "update",
|
|
6
|
+
DELETE = "delete",
|
|
7
|
+
WRITE = "write"
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Default interface for a backend record
|
|
11
|
+
*/
|
|
12
|
+
export interface BackendRecordType {
|
|
13
|
+
uid: string | undefined;
|
|
14
|
+
path: string | undefined;
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Backend Parameters acceptable keys
|
|
19
|
+
*/
|
|
20
|
+
export type BackendParametersKeys = 'host' | 'alias' | 'mapping' | 'middlewares' | 'config' | 'fixtures' | 'softDelete' | 'debug';
|
|
21
|
+
/**
|
|
22
|
+
* Backend parameters interface
|
|
23
|
+
*/
|
|
24
|
+
export interface BackendParameters {
|
|
25
|
+
host?: string;
|
|
26
|
+
alias?: string;
|
|
27
|
+
hierarchy?: {
|
|
28
|
+
[collection: string]: any;
|
|
29
|
+
};
|
|
30
|
+
mapping?: {
|
|
31
|
+
[x: string]: any;
|
|
32
|
+
};
|
|
33
|
+
middlewares?: Middleware[];
|
|
34
|
+
config?: any;
|
|
35
|
+
fixtures?: any;
|
|
36
|
+
softDelete?: boolean;
|
|
37
|
+
useNativeForeignKeys?: boolean;
|
|
38
|
+
debug?: boolean;
|
|
39
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BackendAction = void 0;
|
|
4
|
+
var BackendAction;
|
|
5
|
+
(function (BackendAction) {
|
|
6
|
+
BackendAction["CREATE"] = "create";
|
|
7
|
+
BackendAction["READ"] = "read";
|
|
8
|
+
BackendAction["UPDATE"] = "update";
|
|
9
|
+
BackendAction["DELETE"] = "delete";
|
|
10
|
+
BackendAction["WRITE"] = "write";
|
|
11
|
+
})(BackendAction || (exports.BackendAction = BackendAction = {}));
|
package/lib/Core.d.ts
CHANGED
|
@@ -11,7 +11,6 @@ export declare class Core {
|
|
|
11
11
|
static storage: any;
|
|
12
12
|
static storagePrefix: string;
|
|
13
13
|
static defaultBackend: string;
|
|
14
|
-
static defaultStorage: string;
|
|
15
14
|
static userClass: typeof User;
|
|
16
15
|
static classRegistry: {
|
|
17
16
|
[key: string]: any;
|
|
@@ -20,7 +19,6 @@ export declare class Core {
|
|
|
20
19
|
static auth: AuthAdapter | AbstractAuthAdapter;
|
|
21
20
|
static timestamp: () => string;
|
|
22
21
|
protected static _backends: BackendRegistry<any>;
|
|
23
|
-
protected static _storages: BackendRegistry<any>;
|
|
24
22
|
static definition(key: string): {
|
|
25
23
|
manifest: {
|
|
26
24
|
type: StringConstructor;
|
|
@@ -31,8 +29,6 @@ export declare class Core {
|
|
|
31
29
|
static getConfig(key: string): Promise<any>;
|
|
32
30
|
static addBackend(backend: AbstractAdapter, alias: string, setDefault?: boolean): void;
|
|
33
31
|
static getBackend<T extends AbstractAdapter>(alias?: string): T;
|
|
34
|
-
static addStorage(backend: AbstractAdapter, alias: string, setDefault?: boolean): void;
|
|
35
|
-
static getStorage<T extends AbstractAdapter>(alias?: string): T;
|
|
36
32
|
static addClass(name: string, obj: any): void;
|
|
37
33
|
static getClass(name: string): any;
|
|
38
34
|
/**
|
package/lib/Core.js
CHANGED
|
@@ -23,13 +23,17 @@ class Core {
|
|
|
23
23
|
}
|
|
24
24
|
static addConfig(key, value) {
|
|
25
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
|
|
26
|
+
if (!this.storage.set) {
|
|
27
|
+
yield this.storage.init();
|
|
28
|
+
}
|
|
27
29
|
yield this.storage.set(`${this.storagePrefix}_${key}`, value);
|
|
28
30
|
});
|
|
29
31
|
}
|
|
30
32
|
static getConfig(key) {
|
|
31
33
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
|
|
34
|
+
if (!this.storage.get) {
|
|
35
|
+
yield this.storage.init();
|
|
36
|
+
}
|
|
33
37
|
return yield this.storage.get(`${this.storagePrefix}_${key}`);
|
|
34
38
|
});
|
|
35
39
|
}
|
|
@@ -47,20 +51,6 @@ class Core {
|
|
|
47
51
|
throw new Error(`Unknown backend alias: '${alias}'`);
|
|
48
52
|
}
|
|
49
53
|
}
|
|
50
|
-
static addStorage(backend, alias, setDefault = false) {
|
|
51
|
-
Core._storages[alias] = backend;
|
|
52
|
-
if (setDefault) {
|
|
53
|
-
Core.defaultStorage = alias;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
static getStorage(alias = this.defaultStorage) {
|
|
57
|
-
if (this._storages[alias]) {
|
|
58
|
-
return this._storages[alias];
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
throw new Error(`Unknown storage alias: '${alias}'`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
54
|
static addClass(name, obj) {
|
|
65
55
|
Core.classRegistry[name] = obj;
|
|
66
56
|
}
|
|
@@ -89,11 +79,9 @@ exports.Core = Core;
|
|
|
89
79
|
Core.storage = require('node-persist');
|
|
90
80
|
Core.storagePrefix = 'core';
|
|
91
81
|
Core.defaultBackend = '@default';
|
|
92
|
-
Core.defaultStorage = '@default';
|
|
93
82
|
Core.userClass = User_1.User;
|
|
94
83
|
Core.classRegistry = {};
|
|
95
84
|
Core.logger = console;
|
|
96
85
|
// How timestamp are formatted
|
|
97
86
|
Core.timestamp = () => new Date().toISOString();
|
|
98
87
|
Core._backends = {};
|
|
99
|
-
Core._storages = {};
|
package/lib/Storage.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Backend Parameters acceptable keys
|
|
3
|
+
*/
|
|
4
|
+
export type StorageParametersKeys = 'region' | 'alias' | 'config' | 'debug';
|
|
5
|
+
/**
|
|
6
|
+
* Backend parameters interface
|
|
7
|
+
*/
|
|
8
|
+
export interface StorageParameters {
|
|
9
|
+
region?: string;
|
|
10
|
+
alias?: string;
|
|
11
|
+
config?: any;
|
|
12
|
+
debug?: boolean;
|
|
13
|
+
}
|
package/lib/Storage.js
ADDED
package/lib/backends/Query.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { BaseObjectCore } from '../components/BaseObjectCore';
|
|
|
8
8
|
export declare const AS_OBJECTURIS = "objectUris";
|
|
9
9
|
export declare const AS_DATAOBJECTS = "dataObjects";
|
|
10
10
|
export declare const AS_INSTANCES = "classInstances";
|
|
11
|
+
export type OperatorKeys = 'equals' | 'notEquals' | 'greater' | 'greaterOrEquals' | 'lower' | 'lowerOrEquals' | 'contains' | 'notContains' | 'containsAll' | 'containsAny';
|
|
11
12
|
export type QueryMetaType = {
|
|
12
13
|
count: number;
|
|
13
14
|
offset: number;
|
|
@@ -15,6 +16,7 @@ export type QueryMetaType = {
|
|
|
15
16
|
executionTime: string | number;
|
|
16
17
|
sortField?: string;
|
|
17
18
|
sortOrder?: 'asc' | 'desc';
|
|
19
|
+
debug?: any;
|
|
18
20
|
};
|
|
19
21
|
export type QueryResultType<T> = {
|
|
20
22
|
items: Array<T>;
|
|
@@ -41,7 +43,7 @@ export declare class Query<T extends typeof BaseObjectCore> {
|
|
|
41
43
|
* This may be need in some NoSQL backend to query subcollections
|
|
42
44
|
*/
|
|
43
45
|
set parent(parent: T | undefined);
|
|
44
|
-
where(param: Filter | string | any, value?: any, operator?:
|
|
46
|
+
where(param: Filter | string | any, value?: any, operator?: OperatorKeys): this;
|
|
45
47
|
sortBy(param: Sorting | string, order?: any): this;
|
|
46
48
|
setLimits(limits: Limits): this;
|
|
47
49
|
offset(offset?: number): this;
|
package/lib/backends/Query.js
CHANGED
|
@@ -54,7 +54,7 @@ class Query {
|
|
|
54
54
|
else {
|
|
55
55
|
if (operator === 'equals' && Array.isArray(value)) {
|
|
56
56
|
// auto-convert operator if value is an array
|
|
57
|
-
operator = 'contains';
|
|
57
|
+
operator = 'contains';
|
|
58
58
|
}
|
|
59
59
|
this.filters.push(new Filter_1.Filter(param, value, operator));
|
|
60
60
|
}
|
|
@@ -107,8 +107,6 @@ class Query {
|
|
|
107
107
|
}
|
|
108
108
|
execute(as = returnAs.AS_DATAOBJECTS, backend = Core_1.Core.getBackend(this._obj.DEFAULT_BACKEND)) {
|
|
109
109
|
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
-
//<DataObjectClass<any>[] | ObjectUri[] | Persisted<BaseObject>[]> {
|
|
111
|
-
//</any><Array<T2> | Array<DataObject> | Array<ObjectUri>> {
|
|
112
110
|
try {
|
|
113
111
|
switch (as) {
|
|
114
112
|
case exports.AS_DATAOBJECTS:
|
|
@@ -7,7 +7,7 @@ export interface BackendInterface {
|
|
|
7
7
|
create(dataObject: DataObjectClass<any>, desiredUid: string | undefined): Promise<DataObjectClass<any>>;
|
|
8
8
|
read(param: string | DataObjectClass<any>): Promise<DataObjectClass<any>>;
|
|
9
9
|
update(dataObject: DataObjectClass<any>): Promise<DataObjectClass<any>>;
|
|
10
|
-
delete(dataObject: DataObjectClass<any
|
|
10
|
+
delete(dataObject: DataObjectClass<any>, hardDelete?: boolean): Promise<DataObjectClass<any>>;
|
|
11
11
|
query(query: Query<any>): Promise<QueryResultType<DataObjectClass<any>>>;
|
|
12
12
|
find(dataObject: DataObjectClass<any>, filters: Filters | Filter[] | undefined, pagination: SortAndLimit | undefined, parent: any): Promise<QueryResultType<DataObjectClass<any>>>;
|
|
13
13
|
}
|
|
@@ -20,6 +20,6 @@ export default class BaseRepository<T extends BaseObject> {
|
|
|
20
20
|
* delete object in its backend
|
|
21
21
|
* @param uid string
|
|
22
22
|
*/
|
|
23
|
-
delete(uid: string): Promise<DataObjectClass<any>>;
|
|
23
|
+
delete(uid: string, hardDelete?: boolean): Promise<DataObjectClass<any>>;
|
|
24
24
|
query(query: Query<any>): Promise<QueryResultType<T>>;
|
|
25
25
|
}
|
|
@@ -49,7 +49,10 @@ class BaseRepository {
|
|
|
49
49
|
getDataObjectFromUid(uid) {
|
|
50
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
51
|
const collection = this._model.COLLECTION || this._model.name.toLowerCase();
|
|
52
|
-
|
|
52
|
+
let path = `${collection}/${uid}`;
|
|
53
|
+
if (uid.split('/').length > 2) {
|
|
54
|
+
path = uid;
|
|
55
|
+
}
|
|
53
56
|
const dataObject = DataObject_1.DataObject.factory({
|
|
54
57
|
properties: this._model.PROPS_DEFINITION,
|
|
55
58
|
uri: path,
|
|
@@ -76,6 +79,9 @@ class BaseRepository {
|
|
|
76
79
|
}
|
|
77
80
|
read(key) {
|
|
78
81
|
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
if (!key) {
|
|
83
|
+
throw new Error(`Missing key value in ${this.constructor.name}`);
|
|
84
|
+
}
|
|
79
85
|
try {
|
|
80
86
|
let dataObject;
|
|
81
87
|
if (key.split('/').length <= 2) {
|
|
@@ -100,7 +106,7 @@ class BaseRepository {
|
|
|
100
106
|
throw e;
|
|
101
107
|
}
|
|
102
108
|
if (e instanceof ResourcesErrors_1.NotFoundError) {
|
|
103
|
-
|
|
109
|
+
return null;
|
|
104
110
|
}
|
|
105
111
|
throw e;
|
|
106
112
|
}
|
|
@@ -108,7 +114,7 @@ class BaseRepository {
|
|
|
108
114
|
}
|
|
109
115
|
update(obj) {
|
|
110
116
|
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
-
const dataObject = obj.dataObject;
|
|
117
|
+
const dataObject = obj.dataObject || obj;
|
|
112
118
|
const savedObj = yield this.backendAdapter.update(dataObject);
|
|
113
119
|
return this._model.fromDataObject(savedObj);
|
|
114
120
|
});
|
|
@@ -117,10 +123,10 @@ class BaseRepository {
|
|
|
117
123
|
* delete object in its backend
|
|
118
124
|
* @param uid string
|
|
119
125
|
*/
|
|
120
|
-
delete(uid) {
|
|
126
|
+
delete(uid, hardDelete = false) {
|
|
121
127
|
return __awaiter(this, void 0, void 0, function* () {
|
|
122
128
|
const dataObject = yield this.getDataObjectFromUid(uid);
|
|
123
|
-
return yield this.backendAdapter.delete(dataObject);
|
|
129
|
+
return yield this.backendAdapter.delete(dataObject, hardDelete);
|
|
124
130
|
});
|
|
125
131
|
}
|
|
126
132
|
query(query) {
|
|
@@ -85,6 +85,7 @@ export declare class DataObject implements DataObjectClass<any> {
|
|
|
85
85
|
get uri(): ObjectUri;
|
|
86
86
|
get class(): any;
|
|
87
87
|
get parentProp(): string | undefined;
|
|
88
|
+
set parentProp(str: string | undefined);
|
|
88
89
|
has(key: string): boolean;
|
|
89
90
|
/**
|
|
90
91
|
* Returns property matching key or throw
|
|
@@ -139,7 +139,7 @@ class ObjectUri {
|
|
|
139
139
|
*/
|
|
140
140
|
toReference() {
|
|
141
141
|
return {
|
|
142
|
-
ref: this.
|
|
142
|
+
ref: this.path,
|
|
143
143
|
uri: this._literal,
|
|
144
144
|
label: this._label,
|
|
145
145
|
};
|
|
@@ -147,7 +147,7 @@ class ObjectUri {
|
|
|
147
147
|
toJSON() {
|
|
148
148
|
return {
|
|
149
149
|
backend: this._backend,
|
|
150
|
-
ref: this.
|
|
150
|
+
ref: this.path,
|
|
151
151
|
label: this._label || '',
|
|
152
152
|
};
|
|
153
153
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -30,13 +30,6 @@ import { AuthAction, AuthParameters, AuthParametersKeys } from './Auth';
|
|
|
30
30
|
import { AuthInterface, AbstractAuthAdapter, AuthenticationError } from './authentication';
|
|
31
31
|
import { AbstractAdapter, MockAdapter, BackendError, Query, QueryMetaType, QueryResultType, Filter, Filters, Limits, Sorting, SortAndLimit } from './backends';
|
|
32
32
|
import { BadRequestError, UnauthorizedError, ForbiddenError, NotFoundError, GoneError } from './common/ResourcesErrors';
|
|
33
|
-
import { AbstractStorageAdapter } from './storages/AbstractStorageAdapter';
|
|
34
|
-
import { FileType } from './storages/types/FileType';
|
|
35
|
-
import { BlobType } from './storages/types/BlobType';
|
|
36
|
-
import { BlobMediaType } from './storages/types/BlobMediaType';
|
|
37
|
-
import { StorageAdapterInterface } from './storages/StorageAdapterInterface';
|
|
38
|
-
import { FileResponseLink } from './storages/types/FileResponseLink';
|
|
39
|
-
import { FileResponseUrl } from './storages/types/FileResponseUrl';
|
|
40
33
|
import { DatabaseTriggerType } from './wrappers/cloud/types/DatabaseTriggerType';
|
|
41
34
|
import { AbstractCloudWrapper } from './wrappers/cloud/AbstractCloudWrapper';
|
|
42
|
-
export { statuses, utils, Core, Property, BaseProperty, BasePropertyType, BooleanProperty, BooleanPropertyType, DateTimeProperty, DateTimePropertyType, EnumProperty, EnumPropertyType, HashProperty, HashPropertyType, ObjectProperty, ObjectPropertyType, StringProperty, StringPropertyType, AbstractAdapter, RepositoryClass, MockAdapter, ObjectUri, DataObjectClass, DataObject, AbstractObject, BaseObject, BaseObjectCore, BaseObjectProperties, AuthAction, AuthParameters, AuthParametersKeys, AuthInterface, AbstractAuthAdapter, AuthenticationError, BackendParameters, BackendParametersKeys, BackendRecordType, BackendAction, BaseRepository, BackendError, Query, QueryMetaType, QueryResultType, Filter, Filters, Limits, Sorting, SortAndLimit, Middleware, InjectMetaMiddleware, InjectKeywordsMiddleware, User, UserType, Proxy, UserRepository, Entity, EntityType, EntityRepository, BadRequestError, UnauthorizedError, ForbiddenError, NotFoundError, GoneError,
|
|
35
|
+
export { statuses, utils, Core, Property, BaseProperty, BasePropertyType, BooleanProperty, BooleanPropertyType, DateTimeProperty, DateTimePropertyType, EnumProperty, EnumPropertyType, HashProperty, HashPropertyType, ObjectProperty, ObjectPropertyType, StringProperty, StringPropertyType, AbstractAdapter, RepositoryClass, MockAdapter, ObjectUri, DataObjectClass, DataObject, AbstractObject, BaseObject, BaseObjectCore, BaseObjectProperties, AuthAction, AuthParameters, AuthParametersKeys, AuthInterface, AbstractAuthAdapter, AuthenticationError, BackendParameters, BackendParametersKeys, BackendRecordType, BackendAction, BaseRepository, BackendError, Query, QueryMetaType, QueryResultType, Filter, Filters, Limits, Sorting, SortAndLimit, Middleware, InjectMetaMiddleware, InjectKeywordsMiddleware, User, UserType, Proxy, UserRepository, Entity, EntityType, EntityRepository, BadRequestError, UnauthorizedError, ForbiddenError, NotFoundError, GoneError, DatabaseTriggerType, AbstractCloudWrapper, };
|
package/lib/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.AbstractCloudWrapper = exports.
|
|
29
|
+
exports.AbstractCloudWrapper = exports.GoneError = exports.NotFoundError = exports.ForbiddenError = exports.UnauthorizedError = exports.BadRequestError = exports.EntityRepository = exports.Entity = exports.UserRepository = exports.User = exports.InjectKeywordsMiddleware = exports.InjectMetaMiddleware = exports.SortAndLimit = exports.Sorting = exports.Limits = exports.Filters = exports.Filter = exports.Query = exports.BackendError = exports.BaseRepository = exports.BackendAction = exports.AuthenticationError = exports.AbstractAuthAdapter = exports.AuthAction = exports.BaseObjectProperties = exports.BaseObjectCore = exports.AbstractObject = exports.DataObject = exports.ObjectUri = exports.MockAdapter = exports.AbstractAdapter = exports.StringProperty = exports.ObjectProperty = exports.HashProperty = exports.EnumProperty = exports.DateTimeProperty = exports.BooleanProperty = exports.BaseProperty = exports.Property = exports.Core = exports.utils = exports.statuses = void 0;
|
|
30
30
|
const Core_1 = require("./Core");
|
|
31
31
|
Object.defineProperty(exports, "Core", { enumerable: true, get: function () { return Core_1.Core; } });
|
|
32
32
|
const statuses = __importStar(require("./common/statuses"));
|
|
@@ -96,7 +96,5 @@ Object.defineProperty(exports, "UnauthorizedError", { enumerable: true, get: fun
|
|
|
96
96
|
Object.defineProperty(exports, "ForbiddenError", { enumerable: true, get: function () { return ResourcesErrors_1.ForbiddenError; } });
|
|
97
97
|
Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return ResourcesErrors_1.NotFoundError; } });
|
|
98
98
|
Object.defineProperty(exports, "GoneError", { enumerable: true, get: function () { return ResourcesErrors_1.GoneError; } });
|
|
99
|
-
const AbstractStorageAdapter_1 = require("./storages/AbstractStorageAdapter");
|
|
100
|
-
Object.defineProperty(exports, "AbstractStorageAdapter", { enumerable: true, get: function () { return AbstractStorageAdapter_1.AbstractStorageAdapter; } });
|
|
101
99
|
const AbstractCloudWrapper_1 = require("./wrappers/cloud/AbstractCloudWrapper");
|
|
102
100
|
Object.defineProperty(exports, "AbstractCloudWrapper", { enumerable: true, get: function () { return AbstractCloudWrapper_1.AbstractCloudWrapper; } });
|
|
@@ -31,6 +31,9 @@ class ArrayProperty extends BaseProperty_1.BaseProperty {
|
|
|
31
31
|
return this._maxLength;
|
|
32
32
|
}
|
|
33
33
|
set(value, setChanged = true) {
|
|
34
|
+
if (value === null) {
|
|
35
|
+
value = [];
|
|
36
|
+
}
|
|
34
37
|
if (!Array.isArray(value)) {
|
|
35
38
|
throw new Error(`value ${JSON.stringify(value)} is not an array`);
|
|
36
39
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ObjectUri } from '../components/ObjectUri';
|
|
2
|
+
import { BaseProperty, BasePropertyType } from './BaseProperty';
|
|
3
|
+
import { BaseObjectClass } from '../components/types/BaseObjectClass';
|
|
4
|
+
export interface FilePropertyType extends BasePropertyType {
|
|
5
|
+
}
|
|
6
|
+
export declare class FileProperty extends BaseProperty {
|
|
7
|
+
static TYPE: string;
|
|
8
|
+
_value: BaseObjectClass | ObjectUri | undefined;
|
|
9
|
+
constructor(config: FilePropertyType);
|
|
10
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FileProperty = void 0;
|
|
4
|
+
const BaseProperty_1 = require("./BaseProperty");
|
|
5
|
+
class FileProperty extends BaseProperty_1.BaseProperty {
|
|
6
|
+
constructor(config) {
|
|
7
|
+
super(config);
|
|
8
|
+
this._value = undefined;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.FileProperty = FileProperty;
|
|
12
|
+
FileProperty.TYPE = 'file';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ObjectUri } from '../components/ObjectUri';
|
|
2
|
+
import { BaseProperty, BasePropertyType } from './BaseProperty';
|
|
3
|
+
import { BaseObjectClass } from '../components/types/BaseObjectClass';
|
|
4
|
+
export interface ObjectPropertyType extends BasePropertyType {
|
|
5
|
+
instanceOf: any;
|
|
6
|
+
}
|
|
7
|
+
export declare class ObjectProperty extends BaseProperty {
|
|
8
|
+
static TYPE: string;
|
|
9
|
+
_value: BaseObjectClass | ObjectUri | undefined;
|
|
10
|
+
_instanceOf: any;
|
|
11
|
+
constructor(config: ObjectPropertyType);
|
|
12
|
+
get instanceOf(): any;
|
|
13
|
+
val(transform?: string | undefined): any;
|
|
14
|
+
set(value: object, setChanged?: boolean): this;
|
|
15
|
+
toJSON(): any;
|
|
16
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ObjectProperty = void 0;
|
|
4
|
+
const DataObject_1 = require("../components/DataObject");
|
|
5
|
+
const ObjectUri_1 = require("../components/ObjectUri");
|
|
6
|
+
const BaseProperty_1 = require("./BaseProperty");
|
|
7
|
+
const Query_1 = require("../backends/Query");
|
|
8
|
+
const Core_1 = require("../Core");
|
|
9
|
+
class ObjectProperty extends BaseProperty_1.BaseProperty {
|
|
10
|
+
constructor(config) {
|
|
11
|
+
super(config);
|
|
12
|
+
this._value = undefined;
|
|
13
|
+
this._instanceOf = config.instanceOf;
|
|
14
|
+
}
|
|
15
|
+
get instanceOf() {
|
|
16
|
+
return this._instanceOf;
|
|
17
|
+
}
|
|
18
|
+
val(transform = undefined) {
|
|
19
|
+
if (typeof this._instanceOf === 'string') {
|
|
20
|
+
this._instanceOf = Core_1.Core.getClass(this._instanceOf);
|
|
21
|
+
}
|
|
22
|
+
if (!this._value) {
|
|
23
|
+
return this._defaultValue;
|
|
24
|
+
}
|
|
25
|
+
switch (transform) {
|
|
26
|
+
case Query_1.returnAs.AS_DATAOBJECTS:
|
|
27
|
+
if (this._value instanceof DataObject_1.DataObject) {
|
|
28
|
+
console.log(`Returning already existing dataObject`);
|
|
29
|
+
return this._value;
|
|
30
|
+
}
|
|
31
|
+
else if (this._value instanceof ObjectUri_1.ObjectUri) {
|
|
32
|
+
console.log(`Converting objectUri -> dataObject`);
|
|
33
|
+
return DataObject_1.DataObject.factory({
|
|
34
|
+
properties: Reflect.get(this._instanceOf, 'PROPS_DEFINITION'),
|
|
35
|
+
uri: this._value,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
console.log(`Converting instance -> dataObject`);
|
|
40
|
+
return this._value.dataObject;
|
|
41
|
+
}
|
|
42
|
+
case Query_1.returnAs.AS_INSTANCES:
|
|
43
|
+
if (this._value instanceof DataObject_1.DataObject) {
|
|
44
|
+
console.log(`Converting dataObject -> instance`);
|
|
45
|
+
return Reflect.construct(this._instanceOf, [this._value]);
|
|
46
|
+
}
|
|
47
|
+
else if (this._value instanceof ObjectUri_1.ObjectUri) {
|
|
48
|
+
// console.log('ObjectProperty', this)
|
|
49
|
+
console.log(`Converting objectUri -> dataObject -> instance`);
|
|
50
|
+
// console.log(this._instanceOf)
|
|
51
|
+
const dao = DataObject_1.DataObject.factory({
|
|
52
|
+
properties: Reflect.get(this._instanceOf, 'PROPS_DEFINITION'),
|
|
53
|
+
uri: this._value,
|
|
54
|
+
});
|
|
55
|
+
return Reflect.construct(this._instanceOf, [dao]);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
console.log(`Returning already existing instance`);
|
|
59
|
+
return this._value;
|
|
60
|
+
}
|
|
61
|
+
case Query_1.returnAs.AS_OBJECTURIS:
|
|
62
|
+
default:
|
|
63
|
+
return this._value;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
set(value, setChanged = true) {
|
|
67
|
+
if (value instanceof ObjectUri_1.ObjectUri &&
|
|
68
|
+
value instanceof DataObject_1.DataObject &&
|
|
69
|
+
value.constructor.name !== this._instanceOf.constructor.name) {
|
|
70
|
+
throw new Error(`value ${JSON.stringify(value)} is not an instance of ${this._instanceOf.constructor.name}`);
|
|
71
|
+
}
|
|
72
|
+
return super.set(value, setChanged);
|
|
73
|
+
}
|
|
74
|
+
toJSON() {
|
|
75
|
+
if (this._value instanceof ObjectUri_1.ObjectUri) {
|
|
76
|
+
return this._value.toJSON();
|
|
77
|
+
}
|
|
78
|
+
return this._value &&
|
|
79
|
+
(this._value.dataObject || this._value instanceof DataObject_1.DataObject)
|
|
80
|
+
? this._value.dataObject.toReference()
|
|
81
|
+
: null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.ObjectProperty = ObjectProperty;
|
|
85
|
+
ObjectProperty.TYPE = 'object';
|
|
@@ -9,6 +9,7 @@ export declare class ObjectProperty extends BaseProperty {
|
|
|
9
9
|
_value: BaseObjectClass | ObjectUri | undefined;
|
|
10
10
|
_instanceOf: any;
|
|
11
11
|
constructor(config: ObjectPropertyType);
|
|
12
|
+
get instanceOf(): any;
|
|
12
13
|
val(transform?: string | undefined): any;
|
|
13
14
|
set(value: object, setChanged?: boolean): this;
|
|
14
15
|
toJSON(): any;
|
|
@@ -12,11 +12,12 @@ class ObjectProperty extends BaseProperty_1.BaseProperty {
|
|
|
12
12
|
this._value = undefined;
|
|
13
13
|
this._instanceOf = config.instanceOf;
|
|
14
14
|
}
|
|
15
|
+
get instanceOf() {
|
|
16
|
+
return this._instanceOf;
|
|
17
|
+
}
|
|
15
18
|
val(transform = undefined) {
|
|
16
19
|
if (typeof this._instanceOf === 'string') {
|
|
17
|
-
//console.log(`Getting instance from string ${this._instanceOf}`)
|
|
18
20
|
this._instanceOf = Core_1.Core.getClass(this._instanceOf);
|
|
19
|
-
//throw new Error(`Parameter 'instanceOf' was not properly setted`)
|
|
20
21
|
}
|
|
21
22
|
if (!this._value) {
|
|
22
23
|
return this._defaultValue;
|
|
@@ -7,6 +7,7 @@ import { HashPropertyType } from './HashProperty';
|
|
|
7
7
|
import { StringPropertyType } from './StringProperty';
|
|
8
8
|
import { NumberPropertyType } from './NumberProperty';
|
|
9
9
|
import { ObjectPropertyType } from './ObjectProperty';
|
|
10
|
+
import { FilePropertyType } from './FileProperty';
|
|
10
11
|
export declare class Property {
|
|
11
12
|
static TYPE_ANY: string;
|
|
12
13
|
static TYPE_NUMBER: string;
|
|
@@ -18,5 +19,6 @@ export declare class Property {
|
|
|
18
19
|
static TYPE_DATETIME: string;
|
|
19
20
|
static TYPE_ARRAY: string;
|
|
20
21
|
static TYPE_MAP: string;
|
|
21
|
-
static
|
|
22
|
+
static TYPE_FILE: string;
|
|
23
|
+
static factory(params: ObjectPropertyType & StringPropertyType & NumberPropertyType & EnumPropertyType & BooleanPropertyType & HashPropertyType & DateTimePropertyType & FilePropertyType, parent: DataObjectClass<any>): BaseProperty;
|
|
22
24
|
}
|
|
@@ -12,6 +12,7 @@ const ObjectProperty_1 = require("./ObjectProperty");
|
|
|
12
12
|
const CollectionProperty_1 = require("./CollectionProperty");
|
|
13
13
|
const ArrayProperty_1 = require("./ArrayProperty");
|
|
14
14
|
const MapProperty_1 = require("./MapProperty");
|
|
15
|
+
const FileProperty_1 = require("./FileProperty");
|
|
15
16
|
class Property {
|
|
16
17
|
static factory(params, parent) {
|
|
17
18
|
params.parent = parent;
|
|
@@ -41,6 +42,8 @@ class Property {
|
|
|
41
42
|
return new ArrayProperty_1.ArrayProperty(params);
|
|
42
43
|
case MapProperty_1.MapProperty.TYPE:
|
|
43
44
|
return new MapProperty_1.MapProperty(params);
|
|
45
|
+
case FileProperty_1.FileProperty.TYPE:
|
|
46
|
+
return new FileProperty_1.FileProperty(params);
|
|
44
47
|
default:
|
|
45
48
|
throw new Error(`Unknown property type ${params.type}`);
|
|
46
49
|
}
|
|
@@ -57,3 +60,4 @@ Property.TYPE_HASH = 'hash';
|
|
|
57
60
|
Property.TYPE_DATETIME = 'datetime';
|
|
58
61
|
Property.TYPE_ARRAY = 'array';
|
|
59
62
|
Property.TYPE_MAP = 'map';
|
|
63
|
+
Property.TYPE_FILE = 'file';
|
|
@@ -9,9 +9,10 @@ import { BooleanProperty, BooleanPropertyType } from './BooleanProperty';
|
|
|
9
9
|
import { DateTimeProperty, DateTimePropertyType } from './DateTimeProperty';
|
|
10
10
|
import { ObjectProperty, ObjectPropertyType } from './ObjectProperty';
|
|
11
11
|
import { MapProperty, MapPropertyType } from './MapProperty';
|
|
12
|
+
import { FileProperty, FilePropertyType } from './FileProperty';
|
|
12
13
|
import { CollectionProperty, CollectionPropertyType } from './CollectionProperty';
|
|
13
14
|
import { PropertyTypes } from './types/PropertyTypes';
|
|
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
|
+
export { Property, BaseProperty, BasePropertyType, ArrayProperty, ArrayPropertyType, NumberProperty, NumberPropertyType, BooleanProperty, BooleanPropertyType, DateTimeProperty, DateTimePropertyType, EnumProperty, EnumPropertyType, ObjectProperty, ObjectPropertyType, StringProperty, StringPropertyType, HashProperty, HashPropertyType, MapProperty, MapPropertyType, FileProperty, FilePropertyType, CollectionProperty, CollectionPropertyType, };
|
|
15
16
|
type BaseType = {
|
|
16
17
|
type: PropertyTypes;
|
|
17
18
|
};
|
package/lib/properties/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CollectionProperty = exports.MapProperty = exports.HashProperty = exports.StringProperty = exports.ObjectProperty = exports.EnumProperty = exports.DateTimeProperty = exports.BooleanProperty = exports.NumberProperty = exports.ArrayProperty = exports.BaseProperty = exports.Property = void 0;
|
|
3
|
+
exports.CollectionProperty = exports.FileProperty = exports.MapProperty = exports.HashProperty = exports.StringProperty = exports.ObjectProperty = exports.EnumProperty = exports.DateTimeProperty = exports.BooleanProperty = exports.NumberProperty = exports.ArrayProperty = exports.BaseProperty = exports.Property = void 0;
|
|
4
4
|
const Property_1 = require("./Property");
|
|
5
5
|
Object.defineProperty(exports, "Property", { enumerable: true, get: function () { return Property_1.Property; } });
|
|
6
6
|
const BaseProperty_1 = require("./BaseProperty");
|
|
@@ -23,5 +23,7 @@ const ObjectProperty_1 = require("./ObjectProperty");
|
|
|
23
23
|
Object.defineProperty(exports, "ObjectProperty", { enumerable: true, get: function () { return ObjectProperty_1.ObjectProperty; } });
|
|
24
24
|
const MapProperty_1 = require("./MapProperty");
|
|
25
25
|
Object.defineProperty(exports, "MapProperty", { enumerable: true, get: function () { return MapProperty_1.MapProperty; } });
|
|
26
|
+
const FileProperty_1 = require("./FileProperty");
|
|
27
|
+
Object.defineProperty(exports, "FileProperty", { enumerable: true, get: function () { return FileProperty_1.FileProperty; } });
|
|
26
28
|
const CollectionProperty_1 = require("./CollectionProperty");
|
|
27
29
|
Object.defineProperty(exports, "CollectionProperty", { enumerable: true, get: function () { return CollectionProperty_1.CollectionProperty; } });
|
|
@@ -2,10 +2,16 @@
|
|
|
2
2
|
import { Readable } from 'stream';
|
|
3
3
|
import { FileType } from './types/FileType';
|
|
4
4
|
import { StorageAdapterInterface } from './StorageAdapterInterface';
|
|
5
|
+
import { DownloadFileMeta } from './types/DownloadFileMetaType';
|
|
6
|
+
import { StorageParameters } from '../Storage';
|
|
5
7
|
export declare abstract class AbstractStorageAdapter implements StorageAdapterInterface {
|
|
8
|
+
protected _alias: string;
|
|
9
|
+
protected _params: StorageParameters;
|
|
10
|
+
constructor(params?: StorageParameters);
|
|
6
11
|
abstract getDriver(): any;
|
|
7
12
|
abstract create(file: FileType, stream: Readable): Promise<FileType>;
|
|
8
|
-
abstract download(file: FileType, path:
|
|
13
|
+
abstract download(file: FileType, path: DownloadFileMeta): Promise<any>;
|
|
14
|
+
abstract copy(file: FileType, destFile: FileType): Promise<any>;
|
|
9
15
|
abstract getUrl(file: FileType, expiresIn?: number, action?: string, extra?: any): Promise<any>;
|
|
10
16
|
abstract delete(file: FileType): Promise<Boolean>;
|
|
11
17
|
abstract stream(file: FileType, res: any): Promise<any>;
|
|
@@ -3,5 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AbstractStorageAdapter = void 0;
|
|
4
4
|
//import { APIResponseLink, ResponsePublicUrl } from './types'
|
|
5
5
|
class AbstractStorageAdapter {
|
|
6
|
+
constructor(params = {}) {
|
|
7
|
+
this._alias = '';
|
|
8
|
+
this._params = {};
|
|
9
|
+
this._alias = params.alias || '';
|
|
10
|
+
this._params = params;
|
|
11
|
+
}
|
|
6
12
|
}
|
|
7
13
|
exports.AbstractStorageAdapter = AbstractStorageAdapter;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Readable } from
|
|
3
|
-
import { FileType } from
|
|
2
|
+
import { Readable } from 'stream';
|
|
3
|
+
import { FileType } from './types/FileType';
|
|
4
|
+
import { DownloadFileMeta } from './types/DownloadFileMetaType';
|
|
4
5
|
/**
|
|
5
6
|
* These are the public functions that any storage interface must expose
|
|
6
7
|
*/
|
|
@@ -9,7 +10,7 @@ export interface StorageAdapterInterface {
|
|
|
9
10
|
create(file: FileType, stream: Readable): Promise<FileType>;
|
|
10
11
|
delete(file: FileType): Promise<Boolean>;
|
|
11
12
|
stream(file: FileType, res: any): Promise<any>;
|
|
12
|
-
download(file: FileType, path:
|
|
13
|
+
download(file: FileType, path: DownloadFileMeta): Promise<string>;
|
|
13
14
|
getUrl(file: FileType, expiresIn?: number, action?: string, extra?: any): Promise<any>;
|
|
14
15
|
getUploadUrl(filePath: FileType, expiresIn?: number): Promise<any>;
|
|
15
16
|
getReadable(filePath: FileType): Promise<Readable>;
|
package/lib/storages/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { BlobType } from './types/BlobType';
|
|
|
3
3
|
import { BlobMediaType } from './types/BlobMediaType';
|
|
4
4
|
import { FileResponseLink } from './types/FileResponseLink';
|
|
5
5
|
import { FileResponseUrl } from './types/FileResponseUrl';
|
|
6
|
+
import { DownloadFileMeta } from './types/DownloadFileMetaType';
|
|
6
7
|
import { StorageAdapterInterface } from './StorageAdapterInterface';
|
|
7
8
|
import { AbstractStorageAdapter } from './AbstractStorageAdapter';
|
|
8
|
-
export { FileType, BlobType, BlobMediaType, FileResponseLink, FileResponseUrl, StorageAdapterInterface, AbstractStorageAdapter, };
|
|
9
|
+
export { FileType, BlobType, BlobMediaType, FileResponseLink, FileResponseUrl, DownloadFileMeta, StorageAdapterInterface, AbstractStorageAdapter, };
|
package/lib/storages/index.js
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AbstractStorageAdapter = void 0;
|
|
3
|
+
exports.AbstractStorageAdapter = exports.DownloadFileMeta = exports.FileResponseUrl = exports.FileResponseLink = exports.BlobMediaType = exports.BlobType = exports.FileType = void 0;
|
|
4
|
+
const FileType_1 = require("./types/FileType");
|
|
5
|
+
Object.defineProperty(exports, "FileType", { enumerable: true, get: function () { return FileType_1.FileType; } });
|
|
6
|
+
const BlobType_1 = require("./types/BlobType");
|
|
7
|
+
Object.defineProperty(exports, "BlobType", { enumerable: true, get: function () { return BlobType_1.BlobType; } });
|
|
8
|
+
const BlobMediaType_1 = require("./types/BlobMediaType");
|
|
9
|
+
Object.defineProperty(exports, "BlobMediaType", { enumerable: true, get: function () { return BlobMediaType_1.BlobMediaType; } });
|
|
10
|
+
const FileResponseLink_1 = require("./types/FileResponseLink");
|
|
11
|
+
Object.defineProperty(exports, "FileResponseLink", { enumerable: true, get: function () { return FileResponseLink_1.FileResponseLink; } });
|
|
12
|
+
const FileResponseUrl_1 = require("./types/FileResponseUrl");
|
|
13
|
+
Object.defineProperty(exports, "FileResponseUrl", { enumerable: true, get: function () { return FileResponseUrl_1.FileResponseUrl; } });
|
|
14
|
+
const DownloadFileMetaType_1 = require("./types/DownloadFileMetaType");
|
|
15
|
+
Object.defineProperty(exports, "DownloadFileMeta", { enumerable: true, get: function () { return DownloadFileMetaType_1.DownloadFileMeta; } });
|
|
4
16
|
const AbstractStorageAdapter_1 = require("./AbstractStorageAdapter");
|
|
5
17
|
Object.defineProperty(exports, "AbstractStorageAdapter", { enumerable: true, get: function () { return AbstractStorageAdapter_1.AbstractStorageAdapter; } });
|