@hapiboo/flux 1.0.4 → 1.1.1
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/dist/application.d.ts +8 -8
- package/dist/application.js +33 -6
- package/dist/decorators.d.ts +13 -7
- package/dist/decorators.js +30 -8
- package/dist/index.d.ts +4 -4
- package/dist/index.js +6 -5
- package/dist/interfaces.d.ts +3 -3
- package/dist/types.d.ts +7 -7
- package/dist/types.js +4 -4
- package/package.json +1 -1
package/dist/application.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { IResponsePromiseVoid, IResponsePromise } from '@hapiboo/core';
|
|
2
2
|
import { IDBProviderFlux, IFluxModule, IFluxObject, IFluxDBFilter, IFluxIndexData } from './interfaces';
|
|
3
|
-
import {
|
|
3
|
+
import { FluxDBObjectCreator } from './types';
|
|
4
4
|
export declare namespace fluxApplication {
|
|
5
5
|
function registerModule(module: IFluxModule): void;
|
|
6
6
|
function initialize(dbProvider: IDBProviderFlux): void;
|
|
7
7
|
function start(): void;
|
|
8
8
|
namespace repository {
|
|
9
9
|
function initializeModels(): IResponsePromiseVoid;
|
|
10
|
-
function countModel(source:
|
|
11
|
-
function deleteModel(source:
|
|
12
|
-
function createModel<T extends IFluxObject>(source:
|
|
13
|
-
function updateModel<T extends IFluxObject>(source:
|
|
14
|
-
function readModel<T extends IFluxObject>(source:
|
|
15
|
-
function readArray<T extends IFluxObject>(source:
|
|
16
|
-
function queryArray<T extends IFluxObject>(source:
|
|
10
|
+
function countModel(source: FluxDBObjectCreator): IResponsePromise<number>;
|
|
11
|
+
function deleteModel(source: FluxDBObjectCreator, identifier: string): IResponsePromiseVoid;
|
|
12
|
+
function createModel<T extends IFluxObject>(source: FluxDBObjectCreator, item: T): IResponsePromise<T>;
|
|
13
|
+
function updateModel<T extends IFluxObject>(source: FluxDBObjectCreator, item: T): IResponsePromise<T>;
|
|
14
|
+
function readModel<T extends IFluxObject>(source: FluxDBObjectCreator, identifier: string): IResponsePromise<T>;
|
|
15
|
+
function readArray<T extends IFluxObject>(source: FluxDBObjectCreator, filter: IFluxDBFilter | undefined, queryLimit: number | undefined): IResponsePromise<T[]>;
|
|
16
|
+
function queryArray<T extends IFluxObject>(source: FluxDBObjectCreator, index: string, data: IFluxIndexData, filter: IFluxDBFilter | undefined, queryLimit: number | undefined): IResponsePromise<T[]>;
|
|
17
17
|
}
|
|
18
18
|
}
|
package/dist/application.js
CHANGED
|
@@ -65,12 +65,23 @@ var fluxApplication;
|
|
|
65
65
|
(function (objects) {
|
|
66
66
|
const modelCache = new Map();
|
|
67
67
|
const columnCache = new Map();
|
|
68
|
+
const calculatedColumnCache = new Map();
|
|
68
69
|
const idCache = new Map();
|
|
69
70
|
const indexesCache = new Map();
|
|
70
71
|
function getValue(source, propertyKey) {
|
|
71
72
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
72
73
|
return source[propertyKey];
|
|
73
74
|
}
|
|
75
|
+
function callValueFunction(source, methodKey) {
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
77
|
+
const method = source[methodKey];
|
|
78
|
+
if (typeof method === 'function') {
|
|
79
|
+
return method.call(source);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
74
85
|
function getModel(source) {
|
|
75
86
|
const model = modelCache.get(source);
|
|
76
87
|
if (!model) {
|
|
@@ -89,6 +100,7 @@ var fluxApplication;
|
|
|
89
100
|
return;
|
|
90
101
|
const tableName = decorators_1.hapibooDecorators.getTableName(source);
|
|
91
102
|
const columnsInfo = decorators_1.hapibooDecorators.getColumnsInfo(source);
|
|
103
|
+
const calculatedColumnsInfo = decorators_1.hapibooDecorators.getCalculatedColumnsInfo(source);
|
|
92
104
|
const identifierKey = decorators_1.hapibooDecorators.getIdentifierProperty(source);
|
|
93
105
|
const indexesInfo = decorators_1.hapibooDecorators.getIndexesInfo(source);
|
|
94
106
|
const indexes = indexesInfo.map((index) => {
|
|
@@ -107,15 +119,23 @@ var fluxApplication;
|
|
|
107
119
|
if (sCOl.info.type !== 'S' && sCOl.info.type !== 'N') {
|
|
108
120
|
throw new Error(`Index sort column '${index.sort}' in model '${source.name}' has invalid type '${sCOl.info.type}'. Only 'String' and 'Number' are allowed.`);
|
|
109
121
|
}
|
|
122
|
+
return {
|
|
123
|
+
name: index.name,
|
|
124
|
+
key: kCol.info,
|
|
125
|
+
sort: sCOl?.info
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
return {
|
|
130
|
+
name: index.name,
|
|
131
|
+
key: kCol.info,
|
|
132
|
+
sort: { name: 'id', type: 'S' }
|
|
133
|
+
};
|
|
110
134
|
}
|
|
111
|
-
return {
|
|
112
|
-
name: index.name,
|
|
113
|
-
key: kCol.info,
|
|
114
|
-
sort: sCOl?.info
|
|
115
|
-
};
|
|
116
135
|
});
|
|
117
136
|
modelCache.set(source, { table: tableName, id: '' });
|
|
118
137
|
columnCache.set(source, columnsInfo);
|
|
138
|
+
calculatedColumnCache.set(source, calculatedColumnsInfo);
|
|
119
139
|
idCache.set(source, identifierKey);
|
|
120
140
|
indexesCache.set(source, indexes);
|
|
121
141
|
}
|
|
@@ -132,6 +152,7 @@ var fluxApplication;
|
|
|
132
152
|
function getModelWriter(source, item) {
|
|
133
153
|
const model = getModel(source);
|
|
134
154
|
const columns = columnCache.get(source) || [];
|
|
155
|
+
const calculatedColumns = calculatedColumnCache.get(source) || [];
|
|
135
156
|
const identifierKey = idCache.get(source) || 'id';
|
|
136
157
|
const values = new core_1.Dictionary();
|
|
137
158
|
columns.forEach((col) => {
|
|
@@ -140,10 +161,16 @@ var fluxApplication;
|
|
|
140
161
|
values.push(col.info.name, value);
|
|
141
162
|
}
|
|
142
163
|
});
|
|
164
|
+
calculatedColumns.forEach((col) => {
|
|
165
|
+
const value = callValueFunction(item, col.methodKey);
|
|
166
|
+
if (value !== undefined) {
|
|
167
|
+
values.push(col.info.name, value);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
143
170
|
return {
|
|
144
171
|
table: model.table,
|
|
145
172
|
id: getValue(item, identifierKey),
|
|
146
|
-
columns: columns.map(col => col.info),
|
|
173
|
+
columns: [...columns.map(col => col.info), ...calculatedColumns.map(col => col.info)],
|
|
147
174
|
values: values
|
|
148
175
|
};
|
|
149
176
|
}
|
package/dist/decorators.d.ts
CHANGED
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
import {
|
|
2
|
+
import { FluxDBColumnExposed, FluxDBObjectCreator } from './types';
|
|
3
3
|
import { IFluxColumnInfo } from './interfaces';
|
|
4
4
|
export declare function FluxTable(name: string): ClassDecorator;
|
|
5
|
-
export declare function FluxIdentifier(): PropertyDecorator;
|
|
6
|
-
export declare function FluxExposedColumn(name: string, type?: FluxColumnExposed): PropertyDecorator;
|
|
7
5
|
export declare function FluxIndex(name: string, key: string, sort: string | undefined): ClassDecorator;
|
|
6
|
+
export declare function FluxIndexSimple(name: string, key: string): ClassDecorator;
|
|
7
|
+
export declare function FluxIdentifier(): PropertyDecorator;
|
|
8
|
+
export declare function FluxColumn(name: string, type?: FluxDBColumnExposed): PropertyDecorator;
|
|
9
|
+
export declare function FluxColumnCalculated(name: string, type?: FluxDBColumnExposed): MethodDecorator;
|
|
8
10
|
export declare namespace hapibooDecorators {
|
|
9
|
-
function getTableName(target:
|
|
10
|
-
function getIdentifierProperty(target:
|
|
11
|
-
function getIndexesInfo(target:
|
|
11
|
+
function getTableName(target: FluxDBObjectCreator): string;
|
|
12
|
+
function getIdentifierProperty(target: FluxDBObjectCreator): string;
|
|
13
|
+
function getIndexesInfo(target: FluxDBObjectCreator): {
|
|
12
14
|
name: string;
|
|
13
15
|
key: string;
|
|
14
16
|
sort: string | undefined;
|
|
15
17
|
}[];
|
|
16
|
-
function getColumnsInfo(target:
|
|
18
|
+
function getColumnsInfo(target: FluxDBObjectCreator): {
|
|
17
19
|
info: IFluxColumnInfo;
|
|
18
20
|
propertyKey: string | symbol;
|
|
19
21
|
}[];
|
|
22
|
+
function getCalculatedColumnsInfo(target: FluxDBObjectCreator): {
|
|
23
|
+
info: IFluxColumnInfo;
|
|
24
|
+
methodKey: string | symbol;
|
|
25
|
+
}[];
|
|
20
26
|
}
|
package/dist/decorators.js
CHANGED
|
@@ -2,37 +2,54 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.hapibooDecorators = void 0;
|
|
4
4
|
exports.FluxTable = FluxTable;
|
|
5
|
-
exports.FluxIdentifier = FluxIdentifier;
|
|
6
|
-
exports.FluxExposedColumn = FluxExposedColumn;
|
|
7
5
|
exports.FluxIndex = FluxIndex;
|
|
6
|
+
exports.FluxIndexSimple = FluxIndexSimple;
|
|
7
|
+
exports.FluxIdentifier = FluxIdentifier;
|
|
8
|
+
exports.FluxColumn = FluxColumn;
|
|
9
|
+
exports.FluxColumnCalculated = FluxColumnCalculated;
|
|
8
10
|
require("reflect-metadata");
|
|
9
11
|
const types_1 = require("./types");
|
|
10
12
|
const META_TABLE = Symbol('meta:class:table');
|
|
11
13
|
const META_INDEX = Symbol('meta:class:index');
|
|
12
14
|
const META_IDENTIFIER = Symbol('meta:field:id');
|
|
13
15
|
const META_COLUMN = Symbol('meta:field:column');
|
|
16
|
+
const META_COLUMN_FUNCTION = Symbol('meta:field:column_function');
|
|
14
17
|
function FluxTable(name) {
|
|
15
18
|
return target => {
|
|
16
19
|
Reflect.defineMetadata(META_TABLE, { name }, target);
|
|
17
20
|
};
|
|
18
21
|
}
|
|
22
|
+
function FluxIndex(name, key, sort) {
|
|
23
|
+
return target => {
|
|
24
|
+
const indexes = Reflect.getMetadata(META_INDEX, target) || [];
|
|
25
|
+
indexes.push({ name, key, sort });
|
|
26
|
+
Reflect.defineMetadata(META_INDEX, indexes, target);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function FluxIndexSimple(name, key) {
|
|
30
|
+
return target => {
|
|
31
|
+
const indexes = Reflect.getMetadata(META_INDEX, target) || [];
|
|
32
|
+
indexes.push({ name, key, sort: undefined });
|
|
33
|
+
Reflect.defineMetadata(META_INDEX, indexes, target);
|
|
34
|
+
};
|
|
35
|
+
}
|
|
19
36
|
function FluxIdentifier() {
|
|
20
37
|
return (target, key) => {
|
|
21
38
|
Reflect.defineMetadata(META_IDENTIFIER, { propertyKey: key }, target.constructor);
|
|
22
39
|
};
|
|
23
40
|
}
|
|
24
|
-
function
|
|
41
|
+
function FluxColumn(name, type = types_1.FluxDBColumnExposed.String) {
|
|
25
42
|
return (target, key) => {
|
|
26
43
|
const fields = Reflect.getMetadata(META_COLUMN, target.constructor) || [];
|
|
27
44
|
fields.push({ propertyKey: key, info: { name, type } });
|
|
28
45
|
Reflect.defineMetadata(META_COLUMN, fields, target.constructor);
|
|
29
46
|
};
|
|
30
47
|
}
|
|
31
|
-
function
|
|
32
|
-
return target => {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
Reflect.defineMetadata(
|
|
48
|
+
function FluxColumnCalculated(name, type = types_1.FluxDBColumnExposed.String) {
|
|
49
|
+
return (target, key, _descriptor) => {
|
|
50
|
+
const methods = Reflect.getMetadata(META_COLUMN_FUNCTION, target.constructor) || [];
|
|
51
|
+
methods.push({ methodKey: key, info: { name, type } });
|
|
52
|
+
Reflect.defineMetadata(META_COLUMN_FUNCTION, methods, target.constructor);
|
|
36
53
|
};
|
|
37
54
|
}
|
|
38
55
|
var hapibooDecorators;
|
|
@@ -57,4 +74,9 @@ var hapibooDecorators;
|
|
|
57
74
|
return metadata ? metadata : [];
|
|
58
75
|
}
|
|
59
76
|
hapibooDecorators.getColumnsInfo = getColumnsInfo;
|
|
77
|
+
function getCalculatedColumnsInfo(target) {
|
|
78
|
+
const metadata = Reflect.getMetadata(META_COLUMN_FUNCTION, target);
|
|
79
|
+
return metadata ? metadata : [];
|
|
80
|
+
}
|
|
81
|
+
hapibooDecorators.getCalculatedColumnsInfo = getCalculatedColumnsInfo;
|
|
60
82
|
})(hapibooDecorators || (exports.hapibooDecorators = hapibooDecorators = {}));
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { IFluxIndexInfo, IFluxColumnInfo, IFluxIndexData, IFluxDataModel, IFluxDataModelDefinition, IFluxDataModelWriter, IFluxDataModelReader, IFluxDBFilter, IFluxDBCondition, IFluxDBSubCondition, IFluxObject, IFluxModule, IDBProviderFlux } from './interfaces';
|
|
2
|
-
import {
|
|
3
|
-
import { FluxTable, FluxIndex,
|
|
2
|
+
import { FluxDBColumn, FluxDBColumnIndex, FluxDBColumnExposed, FluxDBFilterLogic, FluxDBFilterOperator, FluxDBFilterOperatorValues, FluxDBFilterOperatorCollection } from './types';
|
|
3
|
+
import { FluxTable, FluxIndex, FluxIdentifier, FluxColumn, FluxColumnCalculated } from './decorators';
|
|
4
4
|
import { fluxApplication } from './application';
|
|
5
5
|
import { conditionBuilder } from './conditions';
|
|
6
|
-
export {
|
|
6
|
+
export { FluxDBColumn, FluxDBColumnIndex, FluxDBColumnExposed };
|
|
7
7
|
export { IFluxIndexInfo, IFluxColumnInfo, IFluxIndexData };
|
|
8
8
|
export { IFluxDataModel, IFluxDataModelDefinition, IFluxDataModelWriter, IFluxDataModelReader };
|
|
9
9
|
export { IFluxDBFilter, IFluxDBCondition, IFluxDBSubCondition };
|
|
@@ -12,4 +12,4 @@ export { IFluxObject, IFluxModule };
|
|
|
12
12
|
export { IDBProviderFlux };
|
|
13
13
|
export { conditionBuilder };
|
|
14
14
|
export { fluxApplication };
|
|
15
|
-
export { FluxTable, FluxIndex,
|
|
15
|
+
export { FluxTable, FluxIndex, FluxIdentifier, FluxColumn, FluxColumnCalculated };
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.FluxColumnCalculated = exports.FluxColumn = exports.FluxIdentifier = exports.FluxIndex = exports.FluxTable = exports.fluxApplication = exports.conditionBuilder = exports.FluxDBColumnExposed = exports.FluxDBColumnIndex = exports.FluxDBColumn = void 0;
|
|
4
4
|
const types_1 = require("./types");
|
|
5
|
-
Object.defineProperty(exports, "
|
|
6
|
-
Object.defineProperty(exports, "
|
|
7
|
-
Object.defineProperty(exports, "
|
|
5
|
+
Object.defineProperty(exports, "FluxDBColumn", { enumerable: true, get: function () { return types_1.FluxDBColumn; } });
|
|
6
|
+
Object.defineProperty(exports, "FluxDBColumnIndex", { enumerable: true, get: function () { return types_1.FluxDBColumnIndex; } });
|
|
7
|
+
Object.defineProperty(exports, "FluxDBColumnExposed", { enumerable: true, get: function () { return types_1.FluxDBColumnExposed; } });
|
|
8
8
|
const decorators_1 = require("./decorators");
|
|
9
9
|
Object.defineProperty(exports, "FluxTable", { enumerable: true, get: function () { return decorators_1.FluxTable; } });
|
|
10
10
|
Object.defineProperty(exports, "FluxIndex", { enumerable: true, get: function () { return decorators_1.FluxIndex; } });
|
|
11
|
-
Object.defineProperty(exports, "FluxExposedColumn", { enumerable: true, get: function () { return decorators_1.FluxExposedColumn; } });
|
|
12
11
|
Object.defineProperty(exports, "FluxIdentifier", { enumerable: true, get: function () { return decorators_1.FluxIdentifier; } });
|
|
12
|
+
Object.defineProperty(exports, "FluxColumn", { enumerable: true, get: function () { return decorators_1.FluxColumn; } });
|
|
13
|
+
Object.defineProperty(exports, "FluxColumnCalculated", { enumerable: true, get: function () { return decorators_1.FluxColumnCalculated; } });
|
|
13
14
|
const application_1 = require("./application");
|
|
14
15
|
Object.defineProperty(exports, "fluxApplication", { enumerable: true, get: function () { return application_1.fluxApplication; } });
|
|
15
16
|
const conditions_1 = require("./conditions");
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Dictionary, IResponsePromise, IResponsePromiseVoid } from '@hapiboo/core';
|
|
2
|
-
import {
|
|
2
|
+
import { FluxDBColumnExposed, FluxDBFilterLogic, FluxDBFilterOperator, FluxDBFilterOperatorCollection, FluxDBFilterOperatorValues, FluxDBObjectCreator } from './types';
|
|
3
3
|
export interface IFluxColumnInfo {
|
|
4
4
|
name: string;
|
|
5
|
-
type:
|
|
5
|
+
type: FluxDBColumnExposed;
|
|
6
6
|
}
|
|
7
7
|
export interface IFluxIndexInfo {
|
|
8
8
|
name: string;
|
|
@@ -54,7 +54,7 @@ export interface IFluxObject {
|
|
|
54
54
|
}
|
|
55
55
|
export interface IFluxModule {
|
|
56
56
|
name: string;
|
|
57
|
-
models:
|
|
57
|
+
models: FluxDBObjectCreator[];
|
|
58
58
|
initialize?: () => void;
|
|
59
59
|
start?: () => IResponsePromiseVoid;
|
|
60
60
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { IFluxObject } from './interfaces';
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const FluxDBColumnIndex: {
|
|
3
3
|
readonly String: "S";
|
|
4
4
|
readonly Number: "N";
|
|
5
5
|
};
|
|
6
|
-
export declare const
|
|
6
|
+
export declare const FluxDBColumnExposed: {
|
|
7
7
|
readonly String: "S";
|
|
8
8
|
readonly Number: "N";
|
|
9
9
|
readonly Boolean: "BOOL";
|
|
10
10
|
};
|
|
11
|
-
export declare const
|
|
11
|
+
export declare const FluxDBColumn: {
|
|
12
12
|
readonly String: "S";
|
|
13
13
|
readonly Number: "N";
|
|
14
14
|
readonly Boolean: "BOOL";
|
|
@@ -16,11 +16,11 @@ export declare const FluxColumn: {
|
|
|
16
16
|
readonly List: "L";
|
|
17
17
|
readonly Object: "M";
|
|
18
18
|
};
|
|
19
|
-
export type
|
|
20
|
-
export type
|
|
21
|
-
export type
|
|
19
|
+
export type FluxDBColumnIndex = typeof FluxDBColumnIndex[keyof typeof FluxDBColumnIndex];
|
|
20
|
+
export type FluxDBColumnExposed = typeof FluxDBColumnExposed[keyof typeof FluxDBColumnExposed];
|
|
21
|
+
export type FluxDBColumn = typeof FluxDBColumn[keyof typeof FluxDBColumn];
|
|
22
22
|
export type FluxDBFilterOperator = '=' | '<>' | 'EXISTS' | 'NOT EXISTS';
|
|
23
23
|
export type FluxDBFilterOperatorValues = '<' | '<=' | '>' | '>=';
|
|
24
24
|
export type FluxDBFilterOperatorCollection = 'IN';
|
|
25
25
|
export type FluxDBFilterLogic = 'AND' | 'OR';
|
|
26
|
-
export type
|
|
26
|
+
export type FluxDBObjectCreator<T extends IFluxObject = IFluxObject> = new () => T;
|
package/dist/types.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
3
|
+
exports.FluxDBColumn = exports.FluxDBColumnExposed = exports.FluxDBColumnIndex = void 0;
|
|
4
|
+
exports.FluxDBColumnIndex = {
|
|
5
5
|
String: 'S',
|
|
6
6
|
Number: 'N',
|
|
7
7
|
};
|
|
8
|
-
exports.
|
|
8
|
+
exports.FluxDBColumnExposed = {
|
|
9
9
|
String: 'S',
|
|
10
10
|
Number: 'N',
|
|
11
11
|
Boolean: 'BOOL',
|
|
12
12
|
};
|
|
13
|
-
exports.
|
|
13
|
+
exports.FluxDBColumn = {
|
|
14
14
|
String: 'S',
|
|
15
15
|
Number: 'N',
|
|
16
16
|
Boolean: 'BOOL',
|