@fjell/lib-sequelize 4.3.4 → 4.4.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/Coordinate.js +13 -0
- package/dist/Definition.js +23 -0
- package/dist/EventCoordinator.js +30 -0
- package/dist/Instance.js +16 -0
- package/dist/KeyMaster.js +84 -0
- package/dist/{src/Operations.d.ts → Operations.d.ts} +3 -3
- package/dist/Operations.js +25 -0
- package/dist/Options.js +19 -0
- package/dist/{src/QueryBuilder.js → QueryBuilder.js} +67 -46
- package/dist/{src/RowProcessor.d.ts → RowProcessor.d.ts} +2 -2
- package/dist/RowProcessor.js +18 -0
- package/dist/contained/Instance.js +16 -0
- package/dist/contained/index.js +2 -0
- package/dist/index.js +10 -0
- package/dist/logger.d.ts +2 -0
- package/dist/logger.js +6 -0
- package/dist/{src/ops → ops}/all.d.ts +3 -3
- package/dist/{src/ops → ops}/all.js +21 -13
- package/dist/{src/ops → ops}/create.d.ts +3 -3
- package/dist/ops/create.js +18 -0
- package/dist/{src/ops → ops}/find.d.ts +3 -3
- package/dist/{src/ops → ops}/find.js +14 -9
- package/dist/ops/get.js +45 -0
- package/dist/{src/ops → ops}/one.d.ts +3 -3
- package/dist/ops/one.js +22 -0
- package/dist/{src/ops → ops}/remove.d.ts +3 -4
- package/dist/ops/remove.js +67 -0
- package/dist/{src/ops → ops}/update.d.ts +3 -3
- package/dist/ops/update.js +57 -0
- package/dist/primary/Instance.js +26 -0
- package/dist/primary/index.js +2 -0
- package/package.json +26 -21
- package/src/Instance.ts +1 -2
- package/src/Operations.ts +1 -1
- package/src/contained/Instance.ts +1 -2
- package/src/ops/all.ts +1 -1
- package/src/ops/find.ts +1 -1
- package/src/primary/Instance.ts +1 -2
- 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.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.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.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.js +0 -17
- package/dist/src/ops/one.js.map +0 -1
- package/dist/src/ops/remove.js +0 -56
- package/dist/src/ops/remove.js.map +0 -1
- 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/dist/{src/Coordinate.d.ts → Coordinate.d.ts} +0 -0
- package/dist/{src/Definition.d.ts → Definition.d.ts} +1 -1
- package/dist/{src/EventCoordinator.d.ts → EventCoordinator.d.ts} +0 -0
- package/dist/{src/Instance.d.ts → Instance.d.ts} +1 -1
- package/dist/{src/KeyMaster.d.ts → KeyMaster.d.ts} +0 -0
- package/dist/{src/Options.d.ts → Options.d.ts} +1 -1
- /package/dist/{src/QueryBuilder.d.ts → QueryBuilder.d.ts} +0 -0
- /package/dist/{src/contained → contained}/Instance.d.ts +0 -0
- /package/dist/{src/contained → contained}/index.d.ts +0 -0
- /package/dist/{src/index.d.ts → index.d.ts} +0 -0
- /package/dist/{src/ops → ops}/get.d.ts +0 -0
- /package/dist/{src/primary → primary}/Instance.d.ts +0 -0
- /package/dist/{src/primary → primary}/index.d.ts +0 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as Library from '@fjell/lib';
|
|
2
|
+
|
|
3
|
+
const SCOPE_SEQUELIZE = 'sequelize';
|
|
4
|
+
const createCoordinate = (kta, scopes)=>{
|
|
5
|
+
const coordinate = Library.createCoordinate(kta, [
|
|
6
|
+
SCOPE_SEQUELIZE,
|
|
7
|
+
...scopes || []
|
|
8
|
+
]);
|
|
9
|
+
return coordinate;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export { SCOPE_SEQUELIZE, createCoordinate };
|
|
13
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ29vcmRpbmF0ZS5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7In0=
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as Library from '@fjell/lib';
|
|
2
|
+
import { createCoordinate } from './Coordinate.js';
|
|
3
|
+
import { createOptions } from './Options.js';
|
|
4
|
+
import LibLogger from './logger.js';
|
|
5
|
+
|
|
6
|
+
const logger = LibLogger.get('lib-sequelize', 'Definition');
|
|
7
|
+
function createDefinition(kta, scopes, libOptions) {
|
|
8
|
+
logger.debug('createDefinition', {
|
|
9
|
+
kta,
|
|
10
|
+
scopes,
|
|
11
|
+
libOptions
|
|
12
|
+
});
|
|
13
|
+
const coordinate = createCoordinate(kta, scopes);
|
|
14
|
+
const options = createOptions(libOptions);
|
|
15
|
+
const definition = Library.createDefinition(coordinate, options);
|
|
16
|
+
return {
|
|
17
|
+
...definition,
|
|
18
|
+
options
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { createDefinition };
|
|
23
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRGVmaW5pdGlvbi5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import 'deepmerge';
|
|
2
|
+
import LibLogger from './logger.js';
|
|
3
|
+
|
|
4
|
+
const logger = LibLogger.get("sequelize", "EventCoordinator");
|
|
5
|
+
//#endregion
|
|
6
|
+
const populateEvents = (item)=>{
|
|
7
|
+
const events = {
|
|
8
|
+
created: {
|
|
9
|
+
at: item.createdAt
|
|
10
|
+
},
|
|
11
|
+
updated: {
|
|
12
|
+
at: item.updatedAt
|
|
13
|
+
},
|
|
14
|
+
deleted: {
|
|
15
|
+
at: null
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
item.events = events;
|
|
19
|
+
return item;
|
|
20
|
+
};
|
|
21
|
+
const removeEvents = (item)=>{
|
|
22
|
+
logger.default('Removing Events', {
|
|
23
|
+
item
|
|
24
|
+
});
|
|
25
|
+
delete item.events;
|
|
26
|
+
return item;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { populateEvents, removeEvents };
|
|
30
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRXZlbnRDb29yZGluYXRvci5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
|
package/dist/Instance.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as Library from '@fjell/lib';
|
|
2
|
+
import { createDefinition } from './Definition.js';
|
|
3
|
+
import { createOperations } from './Operations.js';
|
|
4
|
+
|
|
5
|
+
function createInstance(keyTypes, models, libOptions = {}, scopes = []) {
|
|
6
|
+
const definition = createDefinition(keyTypes, scopes, libOptions);
|
|
7
|
+
const operations = createOperations(models, definition);
|
|
8
|
+
return {
|
|
9
|
+
definition,
|
|
10
|
+
operations: Library.wrapOperations(operations, definition),
|
|
11
|
+
models
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { createInstance };
|
|
16
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSW5zdGFuY2UuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7OyJ9
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import LibLogger from './logger.js';
|
|
2
|
+
|
|
3
|
+
const logger = LibLogger.get('sequelize', 'KeyMaster');
|
|
4
|
+
const removeKey = (item)=>{
|
|
5
|
+
logger.default('Removing Key', {
|
|
6
|
+
item
|
|
7
|
+
});
|
|
8
|
+
delete item.key;
|
|
9
|
+
return item;
|
|
10
|
+
};
|
|
11
|
+
const populateKey = (item, keyTypes)=>{
|
|
12
|
+
if (keyTypes.length === 1) {
|
|
13
|
+
item.key = {
|
|
14
|
+
kt: keyTypes[0],
|
|
15
|
+
pk: item.id
|
|
16
|
+
};
|
|
17
|
+
delete item.id;
|
|
18
|
+
} else if (keyTypes.length === 2) {
|
|
19
|
+
item.key = {
|
|
20
|
+
kt: keyTypes[0],
|
|
21
|
+
pk: item.id,
|
|
22
|
+
// TODO: Shouldn't this be inspecting the model to get the primary key type?
|
|
23
|
+
loc: [
|
|
24
|
+
{
|
|
25
|
+
kt: keyTypes[1],
|
|
26
|
+
lk: item[keyTypes[1] + 'Id']
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
};
|
|
30
|
+
delete item.id;
|
|
31
|
+
delete item[keyTypes[1] + 'Id'];
|
|
32
|
+
} else {
|
|
33
|
+
throw new Error('Not implemented');
|
|
34
|
+
}
|
|
35
|
+
return item;
|
|
36
|
+
};
|
|
37
|
+
const addKey = (item, keyTypes)=>{
|
|
38
|
+
logger.default('Adding Key', {
|
|
39
|
+
item
|
|
40
|
+
});
|
|
41
|
+
const key = {};
|
|
42
|
+
if (Array.isArray(keyTypes) && keyTypes.length > 1) {
|
|
43
|
+
const type = [
|
|
44
|
+
...keyTypes
|
|
45
|
+
];
|
|
46
|
+
const pkType = type.shift();
|
|
47
|
+
Object.assign(key, {
|
|
48
|
+
kt: pkType,
|
|
49
|
+
pk: item.id
|
|
50
|
+
});
|
|
51
|
+
// TODO: This is really just for primary items
|
|
52
|
+
if (type.length === 1) {
|
|
53
|
+
// TODO: This should be looking at the model to get the primary key of the reference item or association
|
|
54
|
+
const locKeyTypeId = type[0] + 'Id';
|
|
55
|
+
Object.assign(key, {
|
|
56
|
+
loc: [
|
|
57
|
+
{
|
|
58
|
+
kt: type[0],
|
|
59
|
+
lk: item[locKeyTypeId]
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
});
|
|
63
|
+
} else if (type.length === 2) {
|
|
64
|
+
throw new Error('Not implemented');
|
|
65
|
+
} else if (type.length === 3) {
|
|
66
|
+
throw new Error('Not implemented');
|
|
67
|
+
} else if (type.length === 4) {
|
|
68
|
+
throw new Error('Not implemented');
|
|
69
|
+
} else if (type.length === 5) {
|
|
70
|
+
throw new Error('Not implemented');
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
Object.assign(key, {
|
|
74
|
+
kt: keyTypes[0],
|
|
75
|
+
pk: item.id
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
Object.assign(item, {
|
|
79
|
+
key
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export { addKey, populateKey, removeKey };
|
|
84
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiS2V5TWFzdGVyLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Item } from
|
|
1
|
+
import { Item } from '@fjell/core';
|
|
2
|
+
import { ModelStatic } from 'sequelize';
|
|
3
|
+
import { Definition } from '@fjell/lib';
|
|
2
4
|
import * as Library from "@fjell/lib";
|
|
3
|
-
import { ModelStatic } from "sequelize";
|
|
4
|
-
import { Definition } from "@fjell/lib";
|
|
5
5
|
export declare const createOperations: <V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(models: Array<ModelStatic<any>>, definition: Definition<V, S, L1, L2, L3, L4, L5>) => Library.Operations<V, S, L1, L2, L3, L4, L5>;
|
|
@@ -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)=>{
|
|
10
|
+
const operations = {};
|
|
11
|
+
operations.all = getAllOperation(models, definition);
|
|
12
|
+
operations.one = getOneOperation(models, definition);
|
|
13
|
+
operations.create = getCreateOperation();
|
|
14
|
+
operations.update = getUpdateOperation(models, definition);
|
|
15
|
+
operations.get = getGetOperation(models, definition);
|
|
16
|
+
operations.remove = getRemoveOperation(models, definition);
|
|
17
|
+
operations.find = getFindOperation(models, definition);
|
|
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=
|
package/dist/Options.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as Library from '@fjell/lib';
|
|
2
|
+
import deepmerge from 'deepmerge';
|
|
3
|
+
|
|
4
|
+
const defaultOptions = {
|
|
5
|
+
deleteOnRemove: false
|
|
6
|
+
};
|
|
7
|
+
const createOptions = (libOptions)=>{
|
|
8
|
+
const defaultOptions = {
|
|
9
|
+
deleteOnRemove: false
|
|
10
|
+
};
|
|
11
|
+
const options = Library.createOptions(libOptions);
|
|
12
|
+
const mergedOptions = deepmerge(defaultOptions, options);
|
|
13
|
+
return {
|
|
14
|
+
...mergedOptions
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { createOptions, defaultOptions };
|
|
19
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiT3B0aW9ucy5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
|
|
@@ -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=
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { AllItemTypeArrays, Item } from
|
|
2
|
-
import { Model } from
|
|
1
|
+
import { AllItemTypeArrays, Item } from '@fjell/core';
|
|
2
|
+
import { Model } from 'sequelize';
|
|
3
3
|
export declare const processRow: <S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(row: Model<any, any>, keyTypes: AllItemTypeArrays<S, L1, L2, L3, L4, L5>) => Item<S, L1, L2, L3, L4, L5>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import LibLogger from './logger.js';
|
|
2
|
+
import { addKey } from './KeyMaster.js';
|
|
3
|
+
|
|
4
|
+
const logger = LibLogger.get('sequelize', 'RowProcessor');
|
|
5
|
+
const processRow = (row, keyTypes)=>{
|
|
6
|
+
logger.default('Processing Row', {
|
|
7
|
+
row
|
|
8
|
+
});
|
|
9
|
+
const item = row.get({
|
|
10
|
+
plain: true
|
|
11
|
+
});
|
|
12
|
+
addKey(item, keyTypes);
|
|
13
|
+
logger.default('Processed Row: ' + JSON.stringify(item));
|
|
14
|
+
return item;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { processRow };
|
|
18
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUm93UHJvY2Vzc29yLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
|
|
@@ -0,0 +1,16 @@
|
|
|
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 = []) {
|
|
6
|
+
const definition = createDefinition(keyTypes, scopes, libOptions);
|
|
7
|
+
const operations = createOperations(models, definition);
|
|
8
|
+
return {
|
|
9
|
+
definition,
|
|
10
|
+
operations: Contained.wrapOperations(operations, definition),
|
|
11
|
+
models
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { createInstance };
|
|
16
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSW5zdGFuY2UuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7OyJ9
|
package/dist/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, defaultOptions } 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==
|
package/dist/logger.d.ts
ADDED
package/dist/logger.js
ADDED
|
@@ -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,4 +1,4 @@
|
|
|
1
|
-
import { Definition } from
|
|
2
|
-
import { Item, ItemQuery, LocKeyArray } from
|
|
3
|
-
import { ModelStatic } from
|
|
1
|
+
import { Definition } from '../Definition';
|
|
2
|
+
import { Item, ItemQuery, LocKeyArray } from '@fjell/core';
|
|
3
|
+
import { ModelStatic } from 'sequelize';
|
|
4
4
|
export declare const getAllOperation: <V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(models: ModelStatic<any>[], definition: Definition<V, S, L1, L2, L3, L4, L5>) => (itemQuery: ItemQuery, locations?: LocKeyArray<L1, L2, L3, L4, L5> | [] | undefined) => Promise<V[]>;
|
|
@@ -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 getAllOperation = (models, definition)=>{
|
|
8
9
|
const { coordinate } = 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,22 @@ 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 matchingItems.map((row)=>validateKeys(processRow(row, coordinate.kta), coordinate.kta));
|
|
44
50
|
};
|
|
45
51
|
return all;
|
|
46
52
|
};
|
|
47
|
-
|
|
53
|
+
|
|
54
|
+
export { getAllOperation };
|
|
55
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWxsLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ComKey, Item, LocKeyArray, PriKey, TypesProperties } from
|
|
2
|
-
import { ModelStatic } from
|
|
3
|
-
import { Definition } from
|
|
1
|
+
import { ComKey, Item, LocKeyArray, PriKey, TypesProperties } from '@fjell/core';
|
|
2
|
+
import { ModelStatic } from 'sequelize';
|
|
3
|
+
import { Definition } from '../Definition';
|
|
4
4
|
export declare const getCreateOperation: <V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(models: ModelStatic<any>[], definition: Definition<V, S, L1, L2, L3, L4, L5>) => (item: TypesProperties<V, S, L1, L2, L3, L4, L5>, options?: {
|
|
5
5
|
key: PriKey<S> | ComKey<S, L1, L2, L3, L4, L5>;
|
|
6
6
|
locations?: never;
|
|
@@ -0,0 +1,18 @@
|
|
|
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)=>{
|
|
7
|
+
const create = async (item, options)=>{
|
|
8
|
+
logger.default('Create', {
|
|
9
|
+
item,
|
|
10
|
+
options
|
|
11
|
+
});
|
|
12
|
+
throw new Error('Not implemented');
|
|
13
|
+
};
|
|
14
|
+
return create;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { getCreateOperation };
|
|
18
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY3JlYXRlLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Item, LocKeyArray } from
|
|
2
|
-
import { Definition } from
|
|
3
|
-
import { ModelStatic } from
|
|
1
|
+
import { Item, LocKeyArray } from '@fjell/core';
|
|
2
|
+
import { Definition } from '../Definition';
|
|
3
|
+
import { ModelStatic } from 'sequelize';
|
|
4
4
|
export declare const getFindOperation: <V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(models: ModelStatic<any>[], definition: Definition<V, S, L1, L2, L3, L4, L5>) => (finder: string, finderParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>, locations?: LocKeyArray<L1, L2, L3, L4, L5> | []) => Promise<V[]>;
|