@hapiboo/flux 1.0.3 → 1.1.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/dist/application.d.ts +8 -8
- package/dist/application.js +31 -3
- package/dist/decorators.d.ts +12 -7
- package/dist/decorators.js +22 -8
- package/dist/index.d.ts +4 -4
- package/dist/index.js +6 -4
- package/dist/interfaces.d.ts +3 -3
- package/dist/types.d.ts +11 -5
- package/dist/types.js +8 -3
- 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) => {
|
|
@@ -97,8 +109,16 @@ var fluxApplication;
|
|
|
97
109
|
if (!kCol) {
|
|
98
110
|
throw new Error(`Index key column '${index.key}' not found in model '${source.name}'.`);
|
|
99
111
|
}
|
|
100
|
-
if (
|
|
101
|
-
throw new Error(`Index
|
|
112
|
+
if (kCol.info.type !== 'S' && kCol.info.type !== 'N') {
|
|
113
|
+
throw new Error(`Index key column '${index.key}' in model '${source.name}' has invalid type '${kCol.info.type}'. Only 'String' and 'Number' are allowed.`);
|
|
114
|
+
}
|
|
115
|
+
if (index.sort) {
|
|
116
|
+
if (!sCOl) {
|
|
117
|
+
throw new Error(`Index sort column '${index.sort}' not found in model '${source.name}'.`);
|
|
118
|
+
}
|
|
119
|
+
if (sCOl.info.type !== 'S' && sCOl.info.type !== 'N') {
|
|
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.`);
|
|
121
|
+
}
|
|
102
122
|
}
|
|
103
123
|
return {
|
|
104
124
|
name: index.name,
|
|
@@ -108,6 +128,7 @@ var fluxApplication;
|
|
|
108
128
|
});
|
|
109
129
|
modelCache.set(source, { table: tableName, id: '' });
|
|
110
130
|
columnCache.set(source, columnsInfo);
|
|
131
|
+
calculatedColumnCache.set(source, calculatedColumnsInfo);
|
|
111
132
|
idCache.set(source, identifierKey);
|
|
112
133
|
indexesCache.set(source, indexes);
|
|
113
134
|
}
|
|
@@ -124,6 +145,7 @@ var fluxApplication;
|
|
|
124
145
|
function getModelWriter(source, item) {
|
|
125
146
|
const model = getModel(source);
|
|
126
147
|
const columns = columnCache.get(source) || [];
|
|
148
|
+
const calculatedColumns = calculatedColumnCache.get(source) || [];
|
|
127
149
|
const identifierKey = idCache.get(source) || 'id';
|
|
128
150
|
const values = new core_1.Dictionary();
|
|
129
151
|
columns.forEach((col) => {
|
|
@@ -132,10 +154,16 @@ var fluxApplication;
|
|
|
132
154
|
values.push(col.info.name, value);
|
|
133
155
|
}
|
|
134
156
|
});
|
|
157
|
+
calculatedColumns.forEach((col) => {
|
|
158
|
+
const value = callValueFunction(item, col.methodKey);
|
|
159
|
+
if (value !== undefined) {
|
|
160
|
+
values.push(col.info.name, value);
|
|
161
|
+
}
|
|
162
|
+
});
|
|
135
163
|
return {
|
|
136
164
|
table: model.table,
|
|
137
165
|
id: getValue(item, identifierKey),
|
|
138
|
-
columns: columns.map(col => col.info),
|
|
166
|
+
columns: [...columns.map(col => col.info), ...calculatedColumns.map(col => col.info)],
|
|
139
167
|
values: values
|
|
140
168
|
};
|
|
141
169
|
}
|
package/dist/decorators.d.ts
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
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?: FluxColumnPrimary): PropertyDecorator;
|
|
7
5
|
export declare function FluxIndex(name: string, key: string, sort: string | undefined): ClassDecorator;
|
|
6
|
+
export declare function FluxIdentifier(): PropertyDecorator;
|
|
7
|
+
export declare function FluxColumn(name: string, type?: FluxDBColumnExposed): PropertyDecorator;
|
|
8
|
+
export declare function FluxColumnCalculated(name: string, type?: FluxDBColumnExposed): MethodDecorator;
|
|
8
9
|
export declare namespace hapibooDecorators {
|
|
9
|
-
function getTableName(target:
|
|
10
|
-
function getIdentifierProperty(target:
|
|
11
|
-
function getIndexesInfo(target:
|
|
10
|
+
function getTableName(target: FluxDBObjectCreator): string;
|
|
11
|
+
function getIdentifierProperty(target: FluxDBObjectCreator): string;
|
|
12
|
+
function getIndexesInfo(target: FluxDBObjectCreator): {
|
|
12
13
|
name: string;
|
|
13
14
|
key: string;
|
|
14
15
|
sort: string | undefined;
|
|
15
16
|
}[];
|
|
16
|
-
function getColumnsInfo(target:
|
|
17
|
+
function getColumnsInfo(target: FluxDBObjectCreator): {
|
|
17
18
|
info: IFluxColumnInfo;
|
|
18
19
|
propertyKey: string | symbol;
|
|
19
20
|
}[];
|
|
21
|
+
function getCalculatedColumnsInfo(target: FluxDBObjectCreator): {
|
|
22
|
+
info: IFluxColumnInfo;
|
|
23
|
+
methodKey: string | symbol;
|
|
24
|
+
}[];
|
|
20
25
|
}
|
package/dist/decorators.js
CHANGED
|
@@ -2,37 +2,46 @@
|
|
|
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.FluxIdentifier = FluxIdentifier;
|
|
7
|
+
exports.FluxColumn = FluxColumn;
|
|
8
|
+
exports.FluxColumnCalculated = FluxColumnCalculated;
|
|
8
9
|
require("reflect-metadata");
|
|
9
10
|
const types_1 = require("./types");
|
|
10
11
|
const META_TABLE = Symbol('meta:class:table');
|
|
11
12
|
const META_INDEX = Symbol('meta:class:index');
|
|
12
13
|
const META_IDENTIFIER = Symbol('meta:field:id');
|
|
13
14
|
const META_COLUMN = Symbol('meta:field:column');
|
|
15
|
+
const META_COLUMN_FUNCTION = Symbol('meta:field:column_function');
|
|
14
16
|
function FluxTable(name) {
|
|
15
17
|
return target => {
|
|
16
18
|
Reflect.defineMetadata(META_TABLE, { name }, target);
|
|
17
19
|
};
|
|
18
20
|
}
|
|
21
|
+
function FluxIndex(name, key, sort) {
|
|
22
|
+
return target => {
|
|
23
|
+
const indexes = Reflect.getMetadata(META_INDEX, target) || [];
|
|
24
|
+
indexes.push({ name, key, sort });
|
|
25
|
+
Reflect.defineMetadata(META_INDEX, indexes, target);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
19
28
|
function FluxIdentifier() {
|
|
20
29
|
return (target, key) => {
|
|
21
30
|
Reflect.defineMetadata(META_IDENTIFIER, { propertyKey: key }, target.constructor);
|
|
22
31
|
};
|
|
23
32
|
}
|
|
24
|
-
function
|
|
33
|
+
function FluxColumn(name, type = types_1.FluxDBColumnExposed.String) {
|
|
25
34
|
return (target, key) => {
|
|
26
35
|
const fields = Reflect.getMetadata(META_COLUMN, target.constructor) || [];
|
|
27
36
|
fields.push({ propertyKey: key, info: { name, type } });
|
|
28
37
|
Reflect.defineMetadata(META_COLUMN, fields, target.constructor);
|
|
29
38
|
};
|
|
30
39
|
}
|
|
31
|
-
function
|
|
32
|
-
return target => {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
Reflect.defineMetadata(
|
|
40
|
+
function FluxColumnCalculated(name, type = types_1.FluxDBColumnExposed.String) {
|
|
41
|
+
return (target, key, _descriptor) => {
|
|
42
|
+
const methods = Reflect.getMetadata(META_COLUMN_FUNCTION, target.constructor) || [];
|
|
43
|
+
methods.push({ methodKey: key, info: { name, type } });
|
|
44
|
+
Reflect.defineMetadata(META_COLUMN_FUNCTION, methods, target.constructor);
|
|
36
45
|
};
|
|
37
46
|
}
|
|
38
47
|
var hapibooDecorators;
|
|
@@ -57,4 +66,9 @@ var hapibooDecorators;
|
|
|
57
66
|
return metadata ? metadata : [];
|
|
58
67
|
}
|
|
59
68
|
hapibooDecorators.getColumnsInfo = getColumnsInfo;
|
|
69
|
+
function getCalculatedColumnsInfo(target) {
|
|
70
|
+
const metadata = Reflect.getMetadata(META_COLUMN_FUNCTION, target);
|
|
71
|
+
return metadata ? metadata : [];
|
|
72
|
+
}
|
|
73
|
+
hapibooDecorators.getCalculatedColumnsInfo = getCalculatedColumnsInfo;
|
|
60
74
|
})(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,14 +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, "
|
|
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; } });
|
|
7
8
|
const decorators_1 = require("./decorators");
|
|
8
9
|
Object.defineProperty(exports, "FluxTable", { enumerable: true, get: function () { return decorators_1.FluxTable; } });
|
|
9
10
|
Object.defineProperty(exports, "FluxIndex", { enumerable: true, get: function () { return decorators_1.FluxIndex; } });
|
|
10
|
-
Object.defineProperty(exports, "FluxExposedColumn", { enumerable: true, get: function () { return decorators_1.FluxExposedColumn; } });
|
|
11
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; } });
|
|
12
14
|
const application_1 = require("./application");
|
|
13
15
|
Object.defineProperty(exports, "fluxApplication", { enumerable: true, get: function () { return application_1.fluxApplication; } });
|
|
14
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,9 +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
|
+
readonly String: "S";
|
|
8
|
+
readonly Number: "N";
|
|
9
|
+
readonly Boolean: "BOOL";
|
|
10
|
+
};
|
|
11
|
+
export declare const FluxDBColumn: {
|
|
7
12
|
readonly String: "S";
|
|
8
13
|
readonly Number: "N";
|
|
9
14
|
readonly Boolean: "BOOL";
|
|
@@ -11,10 +16,11 @@ export declare const FluxColumn: {
|
|
|
11
16
|
readonly List: "L";
|
|
12
17
|
readonly Object: "M";
|
|
13
18
|
};
|
|
14
|
-
export type
|
|
15
|
-
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];
|
|
16
22
|
export type FluxDBFilterOperator = '=' | '<>' | 'EXISTS' | 'NOT EXISTS';
|
|
17
23
|
export type FluxDBFilterOperatorValues = '<' | '<=' | '>' | '>=';
|
|
18
24
|
export type FluxDBFilterOperatorCollection = 'IN';
|
|
19
25
|
export type FluxDBFilterLogic = 'AND' | 'OR';
|
|
20
|
-
export type
|
|
26
|
+
export type FluxDBObjectCreator<T extends IFluxObject = IFluxObject> = new () => T;
|
package/dist/types.js
CHANGED
|
@@ -1,11 +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
|
+
String: 'S',
|
|
10
|
+
Number: 'N',
|
|
11
|
+
Boolean: 'BOOL',
|
|
12
|
+
};
|
|
13
|
+
exports.FluxDBColumn = {
|
|
9
14
|
String: 'S',
|
|
10
15
|
Number: 'N',
|
|
11
16
|
Boolean: 'BOOL',
|