@fjell/lib-sequelize 4.3.4 → 4.4.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/cjs/AggregationBuilder.cjs +31 -0
- package/dist/cjs/Coordinate.cjs +37 -0
- package/dist/cjs/Definition.cjs +46 -0
- package/dist/cjs/EventCoordinator.cjs +35 -0
- package/dist/cjs/Instance.cjs +40 -0
- package/dist/cjs/KeyMaster.cjs +91 -0
- package/dist/cjs/Operations.cjs +29 -0
- package/dist/cjs/Options.cjs +39 -0
- package/dist/cjs/QueryBuilder.cjs +188 -0
- package/dist/cjs/ReferenceBuilder.cjs +34 -0
- package/dist/cjs/RowProcessor.cjs +41 -0
- package/dist/cjs/contained/Instance.cjs +21 -0
- package/dist/cjs/contained/index.cjs +10 -0
- package/dist/cjs/index.cjs +23 -0
- package/dist/cjs/logger.cjs +10 -0
- package/dist/cjs/ops/all.cjs +62 -0
- package/dist/cjs/ops/create.cjs +23 -0
- package/dist/cjs/ops/find.cjs +45 -0
- package/dist/cjs/ops/get.cjs +49 -0
- package/dist/cjs/ops/one.cjs +26 -0
- package/dist/cjs/ops/remove.cjs +72 -0
- package/dist/cjs/ops/update.cjs +59 -0
- package/dist/cjs/primary/Instance.cjs +31 -0
- package/dist/cjs/primary/index.cjs +10 -0
- package/dist/cjs/util/general.cjs +52 -0
- package/dist/es/AggregationBuilder.js +27 -0
- package/dist/es/Coordinate.js +13 -0
- package/dist/es/Definition.js +23 -0
- package/dist/es/EventCoordinator.js +30 -0
- package/dist/es/Instance.js +17 -0
- package/dist/es/KeyMaster.js +86 -0
- package/dist/es/Operations.js +25 -0
- package/dist/es/Options.js +16 -0
- package/dist/{src → es}/QueryBuilder.js +67 -46
- package/dist/es/ReferenceBuilder.js +30 -0
- package/dist/es/RowProcessor.js +37 -0
- package/dist/es/contained/Instance.js +17 -0
- package/dist/es/contained/index.js +2 -0
- package/dist/es/index.js +10 -0
- package/dist/es/logger.js +6 -0
- package/dist/{src → es}/ops/all.js +25 -14
- package/dist/es/ops/create.js +19 -0
- package/dist/es/ops/find.js +41 -0
- package/dist/es/ops/get.js +45 -0
- package/dist/es/ops/one.js +22 -0
- package/dist/es/ops/remove.js +68 -0
- package/dist/es/ops/update.js +55 -0
- package/dist/es/primary/Instance.js +27 -0
- package/dist/es/primary/index.js +2 -0
- package/dist/es/util/general.js +47 -0
- package/dist/index.cjs +810 -0
- package/dist/index.cjs.map +1 -0
- package/dist/types/AggregationBuilder.d.ts +4 -0
- package/dist/{src → types}/Definition.d.ts +2 -2
- package/dist/{src → types}/Instance.d.ts +2 -2
- package/dist/{src → types}/KeyMaster.d.ts +1 -2
- package/dist/{src → types}/Operations.d.ts +4 -4
- package/dist/{src → types}/Options.d.ts +15 -4
- package/dist/types/ReferenceBuilder.d.ts +3 -0
- package/dist/types/RowProcessor.d.ts +5 -0
- package/dist/{src → types}/contained/Instance.d.ts +2 -1
- package/dist/types/logger.d.ts +2 -0
- package/dist/types/ops/all.d.ts +5 -0
- package/dist/{src → types}/ops/create.d.ts +5 -4
- package/dist/types/ops/find.d.ts +5 -0
- package/dist/{src → types}/ops/get.d.ts +2 -1
- package/dist/types/ops/one.d.ts +5 -0
- package/dist/types/ops/remove.d.ts +5 -0
- package/dist/types/ops/update.d.ts +5 -0
- package/dist/{src → types}/primary/Instance.d.ts +2 -1
- package/dist/types/util/general.d.ts +4 -0
- package/package.json +45 -35
- package/dist/src/Coordinate.js +0 -7
- package/dist/src/Coordinate.js.map +0 -1
- package/dist/src/Definition.js +0 -16
- package/dist/src/Definition.js.map +0 -1
- package/dist/src/EventCoordinator.js +0 -56
- package/dist/src/EventCoordinator.js.map +0 -1
- package/dist/src/Instance.js +0 -14
- package/dist/src/Instance.js.map +0 -1
- package/dist/src/KeyMaster.js +0 -58
- package/dist/src/KeyMaster.js.map +0 -1
- package/dist/src/Operations.js +0 -22
- package/dist/src/Operations.js.map +0 -1
- package/dist/src/Options.js +0 -16
- package/dist/src/Options.js.map +0 -1
- package/dist/src/QueryBuilder.js.map +0 -1
- package/dist/src/RowProcessor.d.ts +0 -3
- package/dist/src/RowProcessor.js +0 -11
- package/dist/src/RowProcessor.js.map +0 -1
- package/dist/src/contained/Instance.js +0 -14
- package/dist/src/contained/Instance.js.map +0 -1
- package/dist/src/contained/index.js +0 -2
- package/dist/src/contained/index.js.map +0 -1
- package/dist/src/index.js +0 -8
- package/dist/src/index.js.map +0 -1
- package/dist/src/logger.d.ts +0 -2
- package/dist/src/logger.js +0 -4
- package/dist/src/logger.js.map +0 -1
- package/dist/src/ops/all.d.ts +0 -4
- package/dist/src/ops/all.js.map +0 -1
- package/dist/src/ops/create.js +0 -14
- package/dist/src/ops/create.js.map +0 -1
- package/dist/src/ops/find.d.ts +0 -4
- package/dist/src/ops/find.js +0 -26
- package/dist/src/ops/find.js.map +0 -1
- package/dist/src/ops/get.js +0 -36
- package/dist/src/ops/get.js.map +0 -1
- package/dist/src/ops/one.d.ts +0 -4
- package/dist/src/ops/one.js +0 -17
- package/dist/src/ops/one.js.map +0 -1
- package/dist/src/ops/remove.d.ts +0 -5
- package/dist/src/ops/remove.js +0 -56
- package/dist/src/ops/remove.js.map +0 -1
- package/dist/src/ops/update.d.ts +0 -4
- package/dist/src/ops/update.js +0 -49
- package/dist/src/ops/update.js.map +0 -1
- package/dist/src/primary/Instance.js +0 -17
- package/dist/src/primary/Instance.js.map +0 -1
- package/dist/src/primary/index.js +0 -2
- package/dist/src/primary/index.js.map +0 -1
- package/eslint.config.mjs +0 -70
- package/src/Coordinate.ts +0 -16
- package/src/Definition.ts +0 -49
- package/src/EventCoordinator.ts +0 -103
- package/src/Instance.ts +0 -45
- package/src/KeyMaster.ts +0 -90
- package/src/Operations.ts +0 -42
- package/src/Options.ts +0 -41
- package/src/QueryBuilder.ts +0 -208
- package/src/RowProcessor.ts +0 -23
- package/src/contained/Instance.ts +0 -45
- package/src/contained/index.ts +0 -1
- package/src/index.ts +0 -7
- package/src/logger.ts +0 -5
- package/src/ops/all.ts +0 -76
- package/src/ops/create.ts +0 -40
- package/src/ops/find.ts +0 -49
- package/src/ops/get.ts +0 -67
- package/src/ops/one.ts +0 -37
- package/src/ops/remove.ts +0 -81
- package/src/ops/update.ts +0 -78
- package/src/primary/Instance.ts +0 -41
- package/src/primary/index.ts +0 -1
- /package/dist/{src → types}/Coordinate.d.ts +0 -0
- /package/dist/{src → types}/EventCoordinator.d.ts +0 -0
- /package/dist/{src → types}/QueryBuilder.d.ts +0 -0
- /package/dist/{src → types}/contained/index.d.ts +0 -0
- /package/dist/{src → types}/index.d.ts +0 -0
- /package/dist/{src → types}/primary/index.d.ts +0 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { getAllOperation } from './ops/all.js';
|
|
2
|
+
import { getCreateOperation } from './ops/create.js';
|
|
3
|
+
import { getFindOperation } from './ops/find.js';
|
|
4
|
+
import { getGetOperation } from './ops/get.js';
|
|
5
|
+
import { getOneOperation } from './ops/one.js';
|
|
6
|
+
import { getRemoveOperation } from './ops/remove.js';
|
|
7
|
+
import { getUpdateOperation } from './ops/update.js';
|
|
8
|
+
|
|
9
|
+
const createOperations = (models, definition, registry)=>{
|
|
10
|
+
const operations = {};
|
|
11
|
+
operations.all = getAllOperation(models, definition, registry);
|
|
12
|
+
operations.one = getOneOperation(models, definition, registry);
|
|
13
|
+
operations.create = getCreateOperation();
|
|
14
|
+
operations.update = getUpdateOperation(models, definition, registry);
|
|
15
|
+
operations.get = getGetOperation(models, definition, registry);
|
|
16
|
+
operations.remove = getRemoveOperation(models, definition);
|
|
17
|
+
operations.find = getFindOperation(models, definition, registry);
|
|
18
|
+
operations.upsert = ()=>{
|
|
19
|
+
throw new Error('Not implemented');
|
|
20
|
+
};
|
|
21
|
+
return operations;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { createOperations };
|
|
25
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiT3BlcmF0aW9ucy5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as Library from '@fjell/lib';
|
|
2
|
+
import deepmerge from 'deepmerge';
|
|
3
|
+
import { clean } from './util/general.js';
|
|
4
|
+
|
|
5
|
+
const DEFAULT_OPTIONS = {
|
|
6
|
+
deleteOnRemove: false,
|
|
7
|
+
references: [],
|
|
8
|
+
aggregations: []
|
|
9
|
+
};
|
|
10
|
+
const createOptions = (libOptions)=>{
|
|
11
|
+
const options = Library.createOptions(libOptions);
|
|
12
|
+
return deepmerge(DEFAULT_OPTIONS, clean(options));
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { createOptions };
|
|
16
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiT3B0aW9ucy5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
|
|
@@ -1,50 +1,70 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isCondition, isPriKey, isComKey } from '@fjell/core';
|
|
2
2
|
import { Op } from 'sequelize';
|
|
3
|
-
import LibLogger from './logger';
|
|
3
|
+
import LibLogger from './logger.js';
|
|
4
|
+
|
|
4
5
|
const logger = LibLogger.get('sequelize', 'QueryBuilder');
|
|
5
|
-
const addDeleteQuery = (options, model)
|
|
6
|
-
logger.default('Adding Delete Query', {
|
|
6
|
+
const addDeleteQuery = (options, model)=>{
|
|
7
|
+
logger.default('Adding Delete Query', {
|
|
8
|
+
options
|
|
9
|
+
});
|
|
7
10
|
if (model.getAttributes().deletedAt) {
|
|
8
11
|
options.where['deletedAt'] = {
|
|
9
12
|
[Op.eq]: null
|
|
10
13
|
};
|
|
11
|
-
}
|
|
12
|
-
else if (model.getAttributes().isDeleted) {
|
|
14
|
+
} else if (model.getAttributes().isDeleted) {
|
|
13
15
|
options.where['isDeleted'] = {
|
|
14
16
|
[Op.eq]: false
|
|
15
17
|
};
|
|
16
18
|
}
|
|
17
19
|
return options;
|
|
18
20
|
};
|
|
19
|
-
const addEventQueries = (options, events, model)
|
|
20
|
-
logger.default('Adding Event Queries', {
|
|
21
|
-
|
|
21
|
+
const addEventQueries = (options, events, model)=>{
|
|
22
|
+
logger.default('Adding Event Queries', {
|
|
23
|
+
options,
|
|
24
|
+
events
|
|
25
|
+
});
|
|
26
|
+
Object.keys(events).forEach((key)=>{
|
|
22
27
|
if (!model.getAttributes()[`${key}At`]) {
|
|
23
28
|
throw new Error(`Event ${key} is not supported on this model, column ${key}At not found`);
|
|
24
29
|
}
|
|
25
30
|
let whereClauses = {};
|
|
26
31
|
const event = events[key];
|
|
27
32
|
if (event.start) {
|
|
28
|
-
whereClauses = {
|
|
33
|
+
whereClauses = {
|
|
34
|
+
...whereClauses,
|
|
35
|
+
[Op.gte]: new Date(event.start)
|
|
36
|
+
};
|
|
29
37
|
}
|
|
30
38
|
if (event.end) {
|
|
31
|
-
whereClauses = {
|
|
39
|
+
whereClauses = {
|
|
40
|
+
...whereClauses,
|
|
41
|
+
[Op.lt]: new Date(event.end)
|
|
42
|
+
};
|
|
32
43
|
}
|
|
33
44
|
if (event.by) {
|
|
34
45
|
if (!model.getAttributes()[`${key}By`]) {
|
|
35
46
|
throw new Error(`Event ${key} is not supported on this model, column ${key}By not found`);
|
|
36
47
|
}
|
|
37
|
-
whereClauses = {
|
|
48
|
+
whereClauses = {
|
|
49
|
+
...whereClauses,
|
|
50
|
+
[Op.eq]: event.by
|
|
51
|
+
};
|
|
38
52
|
}
|
|
39
53
|
options.where[`${key}At`] = whereClauses;
|
|
40
54
|
});
|
|
41
55
|
return options;
|
|
42
56
|
};
|
|
43
57
|
// Add the references to the query
|
|
44
|
-
const addReferenceQueries = (options, references, model)
|
|
45
|
-
logger.default('Adding Reference Queries', {
|
|
46
|
-
|
|
47
|
-
|
|
58
|
+
const addReferenceQueries = (options, references, model)=>{
|
|
59
|
+
logger.default('Adding Reference Queries', {
|
|
60
|
+
options,
|
|
61
|
+
references
|
|
62
|
+
});
|
|
63
|
+
Object.keys(references).forEach((key)=>{
|
|
64
|
+
logger.default('Adding Reference Query', {
|
|
65
|
+
key,
|
|
66
|
+
references
|
|
67
|
+
});
|
|
48
68
|
if (!model.getAttributes()[`${key}Id`]) {
|
|
49
69
|
throw new Error(`Reference ${key} is not supported on this model, column ${key}Id not found`);
|
|
50
70
|
}
|
|
@@ -53,30 +73,26 @@ const addReferenceQueries = (options, references, model) => {
|
|
|
53
73
|
options.where[`${key}Id`] = {
|
|
54
74
|
[Op.eq]: priKey.pk
|
|
55
75
|
};
|
|
56
|
-
}
|
|
57
|
-
else if (isComKey(references[key])) {
|
|
76
|
+
} else if (isComKey(references[key])) {
|
|
58
77
|
throw new Error('ComKeys are not supported in Sequelize');
|
|
59
78
|
}
|
|
60
79
|
});
|
|
61
80
|
return options;
|
|
62
81
|
};
|
|
63
|
-
|
|
82
|
+
const addCompoundCondition = (options, compoundCondition, model)=>{
|
|
64
83
|
const where = {};
|
|
65
84
|
let compoundOp;
|
|
66
85
|
const compoundType = compoundCondition.compoundType;
|
|
67
86
|
if (compoundType === "AND") {
|
|
68
87
|
compoundOp = Op.and;
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
88
|
+
} else {
|
|
71
89
|
compoundOp = Op.or;
|
|
72
90
|
}
|
|
73
|
-
;
|
|
74
91
|
let conditions = {};
|
|
75
|
-
compoundCondition.conditions.forEach((condition)
|
|
92
|
+
compoundCondition.conditions.forEach((condition)=>{
|
|
76
93
|
if (isCondition(condition)) {
|
|
77
94
|
conditions = addCondition(conditions, condition, model);
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
95
|
+
} else {
|
|
80
96
|
throw new Error('Nest Compound conditions not supported');
|
|
81
97
|
}
|
|
82
98
|
});
|
|
@@ -84,7 +100,7 @@ export const addCompoundCondition = (options, compoundCondition, model) => {
|
|
|
84
100
|
options.where = where;
|
|
85
101
|
return options;
|
|
86
102
|
};
|
|
87
|
-
|
|
103
|
+
const addCondition = (conditions, condition, model)=>{
|
|
88
104
|
let conditionOp;
|
|
89
105
|
const conditionColumn = condition.column;
|
|
90
106
|
if (!model.getAttributes()[conditionColumn]) {
|
|
@@ -92,23 +108,17 @@ export const addCondition = (conditions, condition, model) => {
|
|
|
92
108
|
}
|
|
93
109
|
if (condition.operator === '==') {
|
|
94
110
|
conditionOp = Op.eq;
|
|
95
|
-
}
|
|
96
|
-
else if (condition.operator === '<') {
|
|
111
|
+
} else if (condition.operator === '<') {
|
|
97
112
|
conditionOp = Op.lt;
|
|
98
|
-
}
|
|
99
|
-
else if (condition.operator === '>') {
|
|
113
|
+
} else if (condition.operator === '>') {
|
|
100
114
|
conditionOp = Op.gt;
|
|
101
|
-
}
|
|
102
|
-
else if (condition.operator === '<=') {
|
|
115
|
+
} else if (condition.operator === '<=') {
|
|
103
116
|
conditionOp = Op.lte;
|
|
104
|
-
}
|
|
105
|
-
else if (condition.operator === '>=') {
|
|
117
|
+
} else if (condition.operator === '>=') {
|
|
106
118
|
conditionOp = Op.gte;
|
|
107
|
-
}
|
|
108
|
-
else if (condition.operator === 'in') {
|
|
119
|
+
} else if (condition.operator === 'in') {
|
|
109
120
|
conditionOp = Op.in;
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
121
|
+
} else {
|
|
112
122
|
throw new Error(`Operator ${condition.operator} not supported`);
|
|
113
123
|
}
|
|
114
124
|
conditions[conditionColumn] = {
|
|
@@ -116,13 +126,17 @@ export const addCondition = (conditions, condition, model) => {
|
|
|
116
126
|
};
|
|
117
127
|
return conditions;
|
|
118
128
|
};
|
|
119
|
-
|
|
120
|
-
logger.default('build', {
|
|
129
|
+
const buildQuery = (itemQuery, model)=>{
|
|
130
|
+
logger.default('build', {
|
|
131
|
+
itemQuery
|
|
132
|
+
});
|
|
121
133
|
let options = {
|
|
122
|
-
where: {}
|
|
134
|
+
where: {}
|
|
123
135
|
};
|
|
124
136
|
if (itemQuery.compoundCondition) {
|
|
125
|
-
logger.default('Adding Conditions', {
|
|
137
|
+
logger.default('Adding Conditions', {
|
|
138
|
+
compoundCondition: itemQuery.compoundCondition
|
|
139
|
+
});
|
|
126
140
|
options = addCompoundCondition(options, itemQuery.compoundCondition, model);
|
|
127
141
|
}
|
|
128
142
|
// If the model has a deletedAt column, we need to add a delete query
|
|
@@ -138,7 +152,9 @@ export const buildQuery = (itemQuery, model) => {
|
|
|
138
152
|
// TODO: Once we start to support Aggs on the server-side, we'll need to parse agg queries
|
|
139
153
|
// Apply a limit to the result set
|
|
140
154
|
if (itemQuery.limit) {
|
|
141
|
-
logger.default('Limiting to', {
|
|
155
|
+
logger.default('Limiting to', {
|
|
156
|
+
limit: itemQuery.limit
|
|
157
|
+
});
|
|
142
158
|
options.limit = itemQuery.limit;
|
|
143
159
|
}
|
|
144
160
|
// Apply an offset to the result set
|
|
@@ -147,15 +163,20 @@ export const buildQuery = (itemQuery, model) => {
|
|
|
147
163
|
}
|
|
148
164
|
// Add orderBy to the query
|
|
149
165
|
if (itemQuery.orderBy) {
|
|
150
|
-
itemQuery.orderBy.forEach((orderBy)
|
|
166
|
+
itemQuery.orderBy.forEach((orderBy)=>{
|
|
151
167
|
if (!model.getAttributes()[orderBy.field]) {
|
|
152
168
|
throw new Error(`Order by field ${orderBy.field} not found on model ${model.name}`);
|
|
153
169
|
}
|
|
154
170
|
options.order = [
|
|
155
|
-
[
|
|
171
|
+
[
|
|
172
|
+
orderBy.field,
|
|
173
|
+
orderBy.direction
|
|
174
|
+
]
|
|
156
175
|
];
|
|
157
176
|
});
|
|
158
177
|
}
|
|
159
178
|
return options;
|
|
160
179
|
};
|
|
161
|
-
|
|
180
|
+
|
|
181
|
+
export { addCompoundCondition, addCondition, buildQuery };
|
|
182
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUXVlcnlCdWlsZGVyLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const buildReference = async (item, referenceDefinition, registry)=>{
|
|
2
|
+
// Check if there is more than one key type
|
|
3
|
+
if (referenceDefinition.kta.length > 1) {
|
|
4
|
+
throw new Error("The ReferenceBuilder doesn't work with more than one key type yet");
|
|
5
|
+
}
|
|
6
|
+
// Check if dependencies exist
|
|
7
|
+
if (!registry) {
|
|
8
|
+
throw new Error("This model definition has a reference definition, but the registry is not present");
|
|
9
|
+
}
|
|
10
|
+
// Find the Library.Instance for the key type
|
|
11
|
+
const library = registry.get(referenceDefinition.kta);
|
|
12
|
+
if (!library) {
|
|
13
|
+
throw new Error("This model definition has a reference definition, but the dependency is not present");
|
|
14
|
+
}
|
|
15
|
+
// Create a PriKey using the column value from item
|
|
16
|
+
const priKey = {
|
|
17
|
+
kt: referenceDefinition.kta[0],
|
|
18
|
+
pk: item[referenceDefinition.column]
|
|
19
|
+
};
|
|
20
|
+
// Get the referenced item using the Library.Operations get method
|
|
21
|
+
const referencedItem = await library.operations.get(priKey);
|
|
22
|
+
// TODO: In a Fjell-compliant implementation, this value should be stored in the ref property
|
|
23
|
+
// For now, we'll just populate the property directly
|
|
24
|
+
// Store the result in the property on item
|
|
25
|
+
item[referenceDefinition.property] = referencedItem;
|
|
26
|
+
return item;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { buildReference };
|
|
30
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUmVmZXJlbmNlQnVpbGRlci5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import LibLogger from './logger.js';
|
|
2
|
+
import { addKey } from './KeyMaster.js';
|
|
3
|
+
import { buildReference } from './ReferenceBuilder.js';
|
|
4
|
+
import { buildAggregation } from './AggregationBuilder.js';
|
|
5
|
+
import { stringifyJSON } from './util/general.js';
|
|
6
|
+
import { populateEvents } from './EventCoordinator.js';
|
|
7
|
+
|
|
8
|
+
const logger = LibLogger.get('sequelize', 'RowProcessor');
|
|
9
|
+
const processRow = async (row, keyTypes, referenceDefinitions, aggregationDefinitions, registry)=>{
|
|
10
|
+
logger.default('Processing Row', {
|
|
11
|
+
row
|
|
12
|
+
});
|
|
13
|
+
let item = row.get({
|
|
14
|
+
plain: true
|
|
15
|
+
});
|
|
16
|
+
logger.default('Adding Key to Item with Key Types: %s', stringifyJSON(keyTypes));
|
|
17
|
+
item = addKey(item, keyTypes);
|
|
18
|
+
item = populateEvents(item);
|
|
19
|
+
logger.default('Key Added to Item: %s', stringifyJSON(item.key));
|
|
20
|
+
if (referenceDefinitions && referenceDefinitions.length > 0) {
|
|
21
|
+
for (const referenceDefinition of referenceDefinitions){
|
|
22
|
+
logger.default('Processing Reference for %s to %s', item.key.kt, stringifyJSON(referenceDefinition.kta));
|
|
23
|
+
item = await buildReference(item, referenceDefinition, registry);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (aggregationDefinitions && aggregationDefinitions.length > 0) {
|
|
27
|
+
for (const aggregationDefinition of aggregationDefinitions){
|
|
28
|
+
logger.default('Processing Aggregation for %s from %s', item.key.kt, stringifyJSON(aggregationDefinition.kta));
|
|
29
|
+
item = await buildAggregation(item, aggregationDefinition, registry);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
logger.default('Processed Row: %j', stringifyJSON(item));
|
|
33
|
+
return item;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { processRow };
|
|
37
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUm93UHJvY2Vzc29yLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Contained } from '@fjell/lib';
|
|
2
|
+
import { createDefinition } from '../Definition.js';
|
|
3
|
+
import { createOperations } from '../Operations.js';
|
|
4
|
+
|
|
5
|
+
function createInstance(keyTypes, models, libOptions = {}, scopes = [], registry) {
|
|
6
|
+
const definition = createDefinition(keyTypes, scopes, libOptions);
|
|
7
|
+
const operations = createOperations(models, definition, registry);
|
|
8
|
+
return {
|
|
9
|
+
definition,
|
|
10
|
+
operations: Contained.wrapOperations(operations, definition, registry),
|
|
11
|
+
models,
|
|
12
|
+
registry
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { createInstance };
|
|
17
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSW5zdGFuY2UuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
|
package/dist/es/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { SCOPE_SEQUELIZE, createCoordinate } from './Coordinate.js';
|
|
2
|
+
export { createDefinition } from './Definition.js';
|
|
3
|
+
export { createInstance } from './Instance.js';
|
|
4
|
+
export { createOptions } from './Options.js';
|
|
5
|
+
export { createOperations } from './Operations.js';
|
|
6
|
+
import * as index from './contained/index.js';
|
|
7
|
+
export { index as Contained };
|
|
8
|
+
import * as index$1 from './primary/index.js';
|
|
9
|
+
export { index$1 as Primary };
|
|
10
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7OzsifQ==
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import Logging from '@fjell/logging';
|
|
2
|
+
|
|
3
|
+
const LibLogger = Logging.getLogger('@fjell/lib-sequelize');
|
|
4
|
+
|
|
5
|
+
export { LibLogger as default };
|
|
6
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9nZ2VyLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7OyJ9
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import { validateKeys } from
|
|
2
|
-
import { buildQuery } from
|
|
3
|
-
import LibLogger from '../logger';
|
|
4
|
-
import { processRow } from
|
|
5
|
-
import { Op } from
|
|
1
|
+
import { validateKeys } from '@fjell/core';
|
|
2
|
+
import { buildQuery } from '../QueryBuilder.js';
|
|
3
|
+
import LibLogger from '../logger.js';
|
|
4
|
+
import { processRow } from '../RowProcessor.js';
|
|
5
|
+
import { Op } from 'sequelize';
|
|
6
|
+
|
|
6
7
|
const logger = LibLogger.get('sequelize', 'ops', 'all');
|
|
7
|
-
|
|
8
|
-
const { coordinate } = definition;
|
|
8
|
+
const getAllOperation = (models, definition, registry)=>{
|
|
9
|
+
const { coordinate, options: { references, aggregations } } = definition;
|
|
9
10
|
//#region Query
|
|
10
|
-
const all = async (itemQuery, locations)
|
|
11
|
-
logger.default('All', {
|
|
11
|
+
const all = async (itemQuery, locations)=>{
|
|
12
|
+
logger.default('All', {
|
|
13
|
+
itemQuery,
|
|
14
|
+
locations
|
|
15
|
+
});
|
|
12
16
|
const loc = locations || [];
|
|
13
17
|
// SQ Libs don't support locations
|
|
14
18
|
if (loc.length > 1) {
|
|
@@ -30,18 +34,25 @@ export const getAllOperation = (models, definition) => {
|
|
|
30
34
|
[Op.eq]: loc[0].lk
|
|
31
35
|
}
|
|
32
36
|
};
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
37
|
+
} else {
|
|
35
38
|
logger.error('Location key type not found in sequelize model association for: %s', locKeyType);
|
|
36
39
|
throw new Error('Location key type not found in model');
|
|
37
40
|
}
|
|
38
41
|
}
|
|
39
|
-
logger.default('Configured this Item Query', {
|
|
42
|
+
logger.default('Configured this Item Query', {
|
|
43
|
+
itemQuery,
|
|
44
|
+
options
|
|
45
|
+
});
|
|
40
46
|
const matchingItems = await model.findAll(options);
|
|
41
47
|
// this.logger.default('Matching Items', { matchingItems });
|
|
42
48
|
// TODO: Move this Up!
|
|
43
|
-
return matchingItems.map((row)
|
|
49
|
+
return await Promise.all(matchingItems.map(async (row)=>{
|
|
50
|
+
const processedRow = await processRow(row, coordinate.kta, references, aggregations, registry);
|
|
51
|
+
return validateKeys(processedRow, coordinate.kta);
|
|
52
|
+
}));
|
|
44
53
|
};
|
|
45
54
|
return all;
|
|
46
55
|
};
|
|
47
|
-
|
|
56
|
+
|
|
57
|
+
export { getAllOperation };
|
|
58
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWxsLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import LibLogger from '../logger.js';
|
|
2
|
+
|
|
3
|
+
const logger = LibLogger.get('sequelize', 'ops', 'create');
|
|
4
|
+
const getCreateOperation = (// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
5
|
+
models, // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6
|
+
definition, // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
7
|
+
registry)=>{
|
|
8
|
+
const create = async (item, options)=>{
|
|
9
|
+
logger.default('Create', {
|
|
10
|
+
item,
|
|
11
|
+
options
|
|
12
|
+
});
|
|
13
|
+
throw new Error('Not implemented');
|
|
14
|
+
};
|
|
15
|
+
return create;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { getCreateOperation };
|
|
19
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY3JlYXRlLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { validateKeys } from '@fjell/core';
|
|
2
|
+
import LibLogger from '../logger.js';
|
|
3
|
+
import { processRow } from '../RowProcessor.js';
|
|
4
|
+
|
|
5
|
+
const logger = LibLogger.get('sequelize', 'ops', 'find');
|
|
6
|
+
const getFindOperation = (models, definition, registry)=>{
|
|
7
|
+
const { options: { finders, references, aggregations } } = definition;
|
|
8
|
+
const find = async (finder, finderParams, locations)=>{
|
|
9
|
+
logger.default('Find', {
|
|
10
|
+
finder,
|
|
11
|
+
finderParams,
|
|
12
|
+
locations
|
|
13
|
+
});
|
|
14
|
+
// Note that we execute the createFinders function here because we want to make sure we're always getting the
|
|
15
|
+
// most up to date methods.
|
|
16
|
+
if (finders && finders[finder]) {
|
|
17
|
+
const finderMethod = finders[finder];
|
|
18
|
+
if (finderMethod) {
|
|
19
|
+
const results = await finderMethod(finderParams, locations);
|
|
20
|
+
if (results && results.length > 0) {
|
|
21
|
+
return await Promise.all(results.map(async (row)=>{
|
|
22
|
+
const processedRow = await processRow(row, definition.coordinate.kta, references, aggregations, registry);
|
|
23
|
+
return validateKeys(processedRow, definition.coordinate.kta);
|
|
24
|
+
}));
|
|
25
|
+
} else {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
} else {
|
|
29
|
+
logger.error(`Finder %s not found`, finder);
|
|
30
|
+
throw new Error(`Finder ${finder} not found`);
|
|
31
|
+
}
|
|
32
|
+
} else {
|
|
33
|
+
logger.error(`No finders have been defined for this lib`);
|
|
34
|
+
throw new Error(`No finders found`);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
return find;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { getFindOperation };
|
|
41
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmluZC5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { isValidItemKey, isPriKey, isComKey, validateKeys } from '@fjell/core';
|
|
2
|
+
import LibLogger from '../logger.js';
|
|
3
|
+
import { processRow } from '../RowProcessor.js';
|
|
4
|
+
import { NotFoundError } from '@fjell/lib';
|
|
5
|
+
|
|
6
|
+
const logger = LibLogger.get('sequelize', 'ops', 'get');
|
|
7
|
+
const getGetOperation = (models, definition, registry)=>{
|
|
8
|
+
const { coordinate, options: { references, aggregations } } = definition;
|
|
9
|
+
const { kta } = coordinate;
|
|
10
|
+
const get = async (key)=>{
|
|
11
|
+
logger.default('Get', {
|
|
12
|
+
key
|
|
13
|
+
});
|
|
14
|
+
if (!isValidItemKey(key)) {
|
|
15
|
+
logger.error('Key for Get is not a valid ItemKey: %j', key);
|
|
16
|
+
throw new Error('Key for Get is not a valid ItemKey');
|
|
17
|
+
}
|
|
18
|
+
const itemKey = key;
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
const model = models[0];
|
|
21
|
+
let item;
|
|
22
|
+
if (isPriKey(itemKey)) {
|
|
23
|
+
item = await model.findByPk(itemKey.pk);
|
|
24
|
+
} else if (isComKey(itemKey)) {
|
|
25
|
+
var _comKey_loc_, _comKey_loc_1;
|
|
26
|
+
const comKey = itemKey;
|
|
27
|
+
// TODO: This should probably interrogate the model?
|
|
28
|
+
item = await model.findOne({
|
|
29
|
+
where: {
|
|
30
|
+
id: comKey.pk,
|
|
31
|
+
[(comKey === null || comKey === void 0 ? void 0 : (_comKey_loc_ = comKey.loc[0]) === null || _comKey_loc_ === void 0 ? void 0 : _comKey_loc_.kt) + 'Id']: comKey === null || comKey === void 0 ? void 0 : (_comKey_loc_1 = comKey.loc[0]) === null || _comKey_loc_1 === void 0 ? void 0 : _comKey_loc_1.lk
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
if (!item) {
|
|
36
|
+
throw new NotFoundError('get', coordinate, key);
|
|
37
|
+
} else {
|
|
38
|
+
return validateKeys(await processRow(item, kta, references, aggregations, registry), kta);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
return get;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export { getGetOperation };
|
|
45
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2V0LmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import LibLogger from '../logger.js';
|
|
2
|
+
import { getAllOperation } from './all.js';
|
|
3
|
+
|
|
4
|
+
const logger = LibLogger.get('sequelize', 'ops', 'one');
|
|
5
|
+
const getOneOperation = (models, definition, registry)=>{
|
|
6
|
+
const one = async (itemQuery, locations = [])=>{
|
|
7
|
+
logger.default('One', {
|
|
8
|
+
itemQuery,
|
|
9
|
+
locations
|
|
10
|
+
});
|
|
11
|
+
const items = await getAllOperation(models, definition, registry)(itemQuery, locations);
|
|
12
|
+
if (items.length > 0) {
|
|
13
|
+
return items[0];
|
|
14
|
+
} else {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
return one;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export { getOneOperation };
|
|
22
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib25lLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { isValidItemKey, abbrevIK, isPriKey, isComKey } from '@fjell/core';
|
|
2
|
+
import { populateEvents } from '../EventCoordinator.js';
|
|
3
|
+
import { addKey } from '../KeyMaster.js';
|
|
4
|
+
import LibLogger from '../logger.js';
|
|
5
|
+
|
|
6
|
+
const logger = LibLogger.get('sequelize', 'ops', 'remove');
|
|
7
|
+
const getRemoveOperation = (models, definition, // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
8
|
+
registry)=>{
|
|
9
|
+
const { coordinate, options } = definition;
|
|
10
|
+
const { kta } = coordinate;
|
|
11
|
+
const remove = async (key)=>{
|
|
12
|
+
logger.default('Remove', {
|
|
13
|
+
key
|
|
14
|
+
});
|
|
15
|
+
if (!isValidItemKey(key)) {
|
|
16
|
+
logger.error('Key for Remove is not a valid ItemKey: %j', key);
|
|
17
|
+
throw new Error('Key for Remove is not a valid ItemKey');
|
|
18
|
+
}
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
const model = models[0];
|
|
21
|
+
let item;
|
|
22
|
+
let returnItem;
|
|
23
|
+
logger.debug('remove: %s', abbrevIK(key));
|
|
24
|
+
if (isPriKey(key)) {
|
|
25
|
+
item = await model.findByPk(key.pk);
|
|
26
|
+
} else if (isComKey(key)) {
|
|
27
|
+
var _comKey_loc_, _comKey_loc_1;
|
|
28
|
+
const comKey = key;
|
|
29
|
+
item = await model.findOne({
|
|
30
|
+
where: {
|
|
31
|
+
id: comKey.pk,
|
|
32
|
+
[(comKey === null || comKey === void 0 ? void 0 : (_comKey_loc_ = comKey.loc[0]) === null || _comKey_loc_ === void 0 ? void 0 : _comKey_loc_.kt) + 'Id']: comKey === null || comKey === void 0 ? void 0 : (_comKey_loc_1 = comKey.loc[0]) === null || _comKey_loc_1 === void 0 ? void 0 : _comKey_loc_1.lk
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
const isDeletedAttribute = model.getAttributes().isDeleted;
|
|
37
|
+
const deletedAtAttribute = model.getAttributes().deletedAt;
|
|
38
|
+
if (isDeletedAttribute || deletedAtAttribute) {
|
|
39
|
+
if (model.getAttributes().isDeleted) {
|
|
40
|
+
item.isDeleted = true;
|
|
41
|
+
}
|
|
42
|
+
if (model.getAttributes().deletedAt) {
|
|
43
|
+
item.deletedAt = new Date();
|
|
44
|
+
}
|
|
45
|
+
// Save the object
|
|
46
|
+
await (item === null || item === void 0 ? void 0 : item.save());
|
|
47
|
+
returnItem = item === null || item === void 0 ? void 0 : item.get({
|
|
48
|
+
plain: true
|
|
49
|
+
});
|
|
50
|
+
returnItem = addKey(returnItem, kta);
|
|
51
|
+
returnItem = populateEvents(returnItem);
|
|
52
|
+
} else if (options.deleteOnRemove) {
|
|
53
|
+
await (item === null || item === void 0 ? void 0 : item.destroy());
|
|
54
|
+
returnItem = item === null || item === void 0 ? void 0 : item.get({
|
|
55
|
+
plain: true
|
|
56
|
+
});
|
|
57
|
+
returnItem = addKey(returnItem, kta);
|
|
58
|
+
returnItem = populateEvents(returnItem);
|
|
59
|
+
} else {
|
|
60
|
+
throw new Error('No deletedAt or isDeleted attribute found in model, and deleteOnRemove is not set');
|
|
61
|
+
}
|
|
62
|
+
return returnItem;
|
|
63
|
+
};
|
|
64
|
+
return remove;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export { getRemoveOperation };
|
|
68
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVtb3ZlLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
|