mythix-orm 1.5.6 → 1.6.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/lib/connection/connection-base.d.ts +180 -0
- package/lib/connection/connection-base.js +242 -16
- package/lib/connection/index.d.ts +5 -0
- package/lib/connection/literals/average-literal.d.ts +5 -0
- package/lib/connection/literals/count-literal.d.ts +5 -0
- package/lib/connection/literals/distinct-literal.d.ts +5 -0
- package/lib/connection/literals/field-literal.d.ts +5 -0
- package/lib/connection/literals/index.d.ts +10 -0
- package/lib/connection/literals/literal-base.d.ts +22 -0
- package/lib/connection/literals/literal-base.js +2 -2
- package/lib/connection/literals/literal-field-base.d.ts +17 -0
- package/lib/connection/literals/literal-field-base.js +4 -4
- package/lib/connection/literals/literal.d.ts +5 -0
- package/lib/connection/literals/max-literal.d.ts +5 -0
- package/lib/connection/literals/min-literal.d.ts +5 -0
- package/lib/connection/literals/sum-literal.d.ts +5 -0
- package/lib/connection/query-generator-base.d.ts +121 -0
- package/lib/connection/query-generator-base.js +5 -6
- package/lib/field.d.ts +61 -0
- package/lib/field.js +9 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.js +7 -1
- package/lib/interfaces/common.ts +3 -0
- package/lib/model.d.ts +205 -0
- package/lib/model.js +136 -32
- package/lib/proxy-class/proxy-class.js +6 -6
- package/lib/query-engine/index.d.ts +1 -0
- package/lib/query-engine/model-scope.js +2 -2
- package/lib/query-engine/query-engine-base.js +2 -2
- package/lib/query-engine/query-engine.d.ts +144 -0
- package/lib/query-engine/query-engine.js +4 -0
- package/lib/types/concrete/bigint-type.d.ts +16 -0
- package/lib/types/concrete/bigint-type.js +8 -5
- package/lib/types/concrete/blob-type.d.ts +11 -0
- package/lib/types/concrete/blob-type.js +5 -4
- package/lib/types/concrete/boolean-type.d.ts +11 -0
- package/lib/types/concrete/boolean-type.js +4 -4
- package/lib/types/concrete/char-type.d.ts +11 -0
- package/lib/types/concrete/char-type.js +4 -4
- package/lib/types/concrete/date-type.d.ts +16 -0
- package/lib/types/concrete/date-type.js +9 -4
- package/lib/types/concrete/datetime-type.d.ts +16 -0
- package/lib/types/concrete/datetime-type.js +9 -4
- package/lib/types/concrete/foreign-key-type.d.ts +32 -0
- package/lib/types/concrete/foreign-key-type.js +274 -10
- package/lib/types/concrete/index.d.ts +19 -0
- package/lib/types/concrete/index.js +2 -0
- package/lib/types/concrete/integer-type.d.ts +16 -0
- package/lib/types/concrete/integer-type.js +6 -4
- package/lib/types/concrete/numeric-type.d.ts +11 -0
- package/lib/types/concrete/numeric-type.js +6 -4
- package/lib/types/concrete/real-type.d.ts +11 -0
- package/lib/types/concrete/real-type.js +111 -4
- package/lib/types/concrete/serialized-type.d.ts +25 -0
- package/lib/types/concrete/serialized-type.js +287 -5
- package/lib/types/concrete/string-type.d.ts +11 -0
- package/lib/types/concrete/string-type.js +0 -4
- package/lib/types/concrete/text-type.d.ts +11 -0
- package/lib/types/concrete/text-type.js +0 -4
- package/lib/types/concrete/uuid-base.d.ts +13 -0
- package/lib/types/concrete/uuid-base.js +4 -1
- package/lib/types/concrete/uuid-v1-type.d.ts +31 -0
- package/lib/types/concrete/uuid-v1-type.js +0 -4
- package/lib/types/concrete/uuid-v3-type.d.ts +27 -0
- package/lib/types/concrete/uuid-v3-type.js +0 -4
- package/lib/types/concrete/uuid-v4-type.d.ts +27 -0
- package/lib/types/concrete/uuid-v4-type.js +0 -4
- package/lib/types/concrete/uuid-v5-type.d.ts +27 -0
- package/lib/types/concrete/uuid-v5-type.js +0 -4
- package/lib/types/concrete/xid-type.d.ts +17 -0
- package/lib/types/concrete/xid-type.js +0 -4
- package/lib/types/helpers/default-helpers.d.ts +61 -0
- package/lib/types/helpers/index.d.ts +1 -0
- package/lib/types/index.d.ts +6 -0
- package/lib/types/index.js +2 -0
- package/lib/types/type.d.ts +89 -0
- package/lib/types/type.js +57 -25
- package/lib/types/virtual/index.d.ts +4 -0
- package/lib/types/virtual/model-type.d.ts +15 -0
- package/lib/types/virtual/model-type.js +2 -2
- package/lib/types/virtual/models-type.d.ts +15 -0
- package/lib/types/virtual/models-type.js +5 -5
- package/lib/types/virtual/relational-type-base.d.ts +46 -0
- package/lib/types/virtual/relational-type-base.js +12 -20
- package/lib/utils/index.d.ts +6 -0
- package/lib/utils/index.js +1 -4
- package/lib/utils/misc-utils.d.ts +4 -0
- package/lib/utils/misc-utils.js +0 -35
- package/lib/utils/model-utils.d.ts +90 -0
- package/lib/utils/model-utils.js +4 -4
- package/lib/utils/query-utils.d.ts +11 -0
- package/package.json +3 -2
- package/.biblorc.js +0 -29
- package/docs/Associations.md +0 -539
- package/docs/Certifications.md +0 -22
- package/docs/Home.md +0 -54
- package/docs/Query Engine.md +0 -428
|
@@ -42,19 +42,19 @@ class RelationalTypeBase extends Type {
|
|
|
42
42
|
Object.defineProperties(this, {
|
|
43
43
|
'targetModelName': {
|
|
44
44
|
writable: true,
|
|
45
|
-
|
|
45
|
+
enumerable: false,
|
|
46
46
|
configurable: true,
|
|
47
47
|
value: targetModelName,
|
|
48
48
|
},
|
|
49
49
|
'queryFactory': {
|
|
50
50
|
writable: true,
|
|
51
|
-
|
|
51
|
+
enumerable: false,
|
|
52
52
|
configurable: true,
|
|
53
53
|
value: queryFactory,
|
|
54
54
|
},
|
|
55
55
|
'options': {
|
|
56
56
|
writable: true,
|
|
57
|
-
|
|
57
|
+
enumerable: false,
|
|
58
58
|
configurable: true,
|
|
59
59
|
value: options,
|
|
60
60
|
},
|
|
@@ -274,32 +274,24 @@ class RelationalTypeBase extends Type {
|
|
|
274
274
|
}
|
|
275
275
|
|
|
276
276
|
getTargetModel(_connection) {
|
|
277
|
-
let connection
|
|
277
|
+
let connection = _connection || this.getModel().getConnection();
|
|
278
278
|
return connection.getModel(this.targetModelName);
|
|
279
279
|
}
|
|
280
280
|
|
|
281
|
-
async prepareQuery({ connection: _connection, self, field, options: _options
|
|
281
|
+
async prepareQuery({ connection: _connection, self, field, options: _options }, args) {
|
|
282
282
|
let options = _options || {};
|
|
283
283
|
let queryFactory = this.queryFactory;
|
|
284
284
|
let connection = _connection || self.getConnection(options.connection);
|
|
285
|
-
let userQuery = _userQuery;
|
|
286
285
|
let TargetModel = this.getTargetModel(connection);
|
|
287
|
-
|
|
288
|
-
if (!QueryEngine.isQuery(userQuery) && Nife.instanceOf(userQuery, 'array', 'object', 'map', 'set'))
|
|
289
|
-
userQuery = Utils.generateQueryFromFilter(connection, TargetModel, userQuery);
|
|
290
|
-
|
|
291
286
|
let rootQuery = await queryFactory.call(
|
|
292
287
|
self,
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
},
|
|
301
|
-
connection.getModels() || {},
|
|
302
|
-
),
|
|
288
|
+
{
|
|
289
|
+
type: this,
|
|
290
|
+
self,
|
|
291
|
+
connection,
|
|
292
|
+
field,
|
|
293
|
+
},
|
|
294
|
+
connection.getModels() || {},
|
|
303
295
|
...(args || []),
|
|
304
296
|
);
|
|
305
297
|
|
package/lib/utils/index.js
CHANGED
|
@@ -6,9 +6,7 @@ const QueryUtils = require('./query-utils');
|
|
|
6
6
|
|
|
7
7
|
const {
|
|
8
8
|
collect,
|
|
9
|
-
copyStaticProps,
|
|
10
9
|
objectAssignSpecial,
|
|
11
|
-
iterateStaticProps,
|
|
12
10
|
} = MiscUtils;
|
|
13
11
|
|
|
14
12
|
const {
|
|
@@ -36,12 +34,11 @@ const {
|
|
|
36
34
|
module.exports = {
|
|
37
35
|
MiscUtils,
|
|
38
36
|
ModelUtils,
|
|
37
|
+
QueryUtils,
|
|
39
38
|
|
|
40
39
|
// MiscUtils
|
|
41
40
|
collect,
|
|
42
|
-
copyStaticProps,
|
|
43
41
|
objectAssignSpecial,
|
|
44
|
-
iterateStaticProps,
|
|
45
42
|
|
|
46
43
|
// ModelUtils
|
|
47
44
|
assignRelatedModels,
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { GenericObject } from '../interfaces/common';
|
|
2
|
+
|
|
3
|
+
declare function collect(iterator: AsyncIterator<any>): Promise<Array<any>>;
|
|
4
|
+
declare function objectAssignSpecial(obj: GenericObject, proto?: GenericObject | null, skipKeys?: Array<string> | GenericObject): GenericObject;
|
package/lib/utils/misc-utils.js
CHANGED
|
@@ -1,38 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
function iterateStaticProps(Klass, callback) {
|
|
4
|
-
if (typeof Klass !== 'function')
|
|
5
|
-
throw new TypeError('Utils::iterateStaticProps: "Klass" argument must be a function.');
|
|
6
|
-
|
|
7
|
-
let prototype = Klass.prototype;
|
|
8
|
-
let keys = Object.getOwnPropertyNames(Klass);
|
|
9
|
-
|
|
10
|
-
for (let i = 0, il = keys.length; i < il; i++) {
|
|
11
|
-
let key = keys[i];
|
|
12
|
-
if (key === 'length' || key === 'name' || key === 'prototype')
|
|
13
|
-
continue;
|
|
14
|
-
|
|
15
|
-
let value = Klass[key];
|
|
16
|
-
callback({ value, key, Klass, prototype });
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function copyStaticProps(Klass, destination) {
|
|
21
|
-
if (typeof Klass !== 'function')
|
|
22
|
-
throw new TypeError('Utils::copyStaticProps: "Klass" argument must be a function.');
|
|
23
|
-
|
|
24
|
-
iterateStaticProps(Klass, ({ value, key }) => {
|
|
25
|
-
Object.defineProperties(destination, {
|
|
26
|
-
[key]: {
|
|
27
|
-
writable: true,
|
|
28
|
-
enumberable: false,
|
|
29
|
-
configurable: true,
|
|
30
|
-
value: value,
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
3
|
async function collect(iterator) {
|
|
37
4
|
let items = [];
|
|
38
5
|
|
|
@@ -67,7 +34,5 @@ function objectAssignSpecial(obj, proto, skipKeys) {
|
|
|
67
34
|
|
|
68
35
|
module.exports = {
|
|
69
36
|
collect,
|
|
70
|
-
copyStaticProps,
|
|
71
37
|
objectAssignSpecial,
|
|
72
|
-
iterateStaticProps,
|
|
73
38
|
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import ConnectionBase from '../connection/connection-base';
|
|
2
|
+
import Field from '../field';
|
|
3
|
+
import { GenericObject } from '../interfaces/common';
|
|
4
|
+
import { Model, ModelClass } from '../model';
|
|
5
|
+
import { QueryEngine } from '../query-engine';
|
|
6
|
+
|
|
7
|
+
export declare interface FullyQualifiedFieldDefinition {
|
|
8
|
+
modelName: string;
|
|
9
|
+
fieldNames: Array<string>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export declare interface RelationStatus {
|
|
13
|
+
create?: boolean;
|
|
14
|
+
instance?: Model | GenericObject;
|
|
15
|
+
modelName: string;
|
|
16
|
+
Model: ModelClass;
|
|
17
|
+
fields: Map<string, string>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export declare interface ModelsRelationStatuses {
|
|
21
|
+
[ key: string ]: RelationStatus
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export declare function isUUID(value: any): boolean;
|
|
25
|
+
export declare function sanitizeFieldString(value: string): string;
|
|
26
|
+
export declare function parseQualifiedName(value: string): FullyQualifiedFieldDefinition;
|
|
27
|
+
export declare function injectModelMethod(self: any, method: Function, methodName: string, fullMethodName: string): void;
|
|
28
|
+
export declare function fieldToFullyQualifiedName(field: Field | string, Model: ModelClass): string;
|
|
29
|
+
|
|
30
|
+
export declare function sortModelNamesByDependencyOrder(
|
|
31
|
+
connection: ConnectionBase,
|
|
32
|
+
modelNames: Array<string>,
|
|
33
|
+
dependencyHelper: (Model: ModelClass, modelName: string) => Array<string>,
|
|
34
|
+
): Array<string>;
|
|
35
|
+
|
|
36
|
+
export declare function sortModelNamesByCreationOrder(connection: ConnectionBase, modelNames: Array<string>): Array<string>;
|
|
37
|
+
|
|
38
|
+
export declare function getRelationalModelStatusForField(
|
|
39
|
+
connection: ConnectionBase,
|
|
40
|
+
self: Model,
|
|
41
|
+
field: Field,
|
|
42
|
+
...args: Array<any>,
|
|
43
|
+
): Promise<{
|
|
44
|
+
relationalMap: ModelsRelationStatuses,
|
|
45
|
+
TargetModel?: ModelClass,
|
|
46
|
+
TargetField?: Field,
|
|
47
|
+
}>;
|
|
48
|
+
|
|
49
|
+
export declare function constructModelsForCreationFromOriginField(
|
|
50
|
+
connection: ConnectionBase,
|
|
51
|
+
self: Model,
|
|
52
|
+
field: Field,
|
|
53
|
+
attributes: Model | GenericObject,
|
|
54
|
+
): Promise<{
|
|
55
|
+
relationalMap: ModelsRelationStatuses,
|
|
56
|
+
sortedModelNames: Array<string>
|
|
57
|
+
} | undefined>;
|
|
58
|
+
|
|
59
|
+
export declare function createAndSaveAllRelatedModels(
|
|
60
|
+
connection: ConnectionBase,
|
|
61
|
+
self: Model,
|
|
62
|
+
field: Field,
|
|
63
|
+
allModelAttributes: Array<Model | GenericObject>,
|
|
64
|
+
options?: GenericObject,
|
|
65
|
+
): Promise<Array<Model> | undefined>;
|
|
66
|
+
|
|
67
|
+
export declare function setRelationalValues<T = Model>(
|
|
68
|
+
connection: ConnectionBase,
|
|
69
|
+
TargetModel: ModelClass,
|
|
70
|
+
targetModelInstance: T,
|
|
71
|
+
SourceModel: ModelClass,
|
|
72
|
+
sourceModelInstance: Model,
|
|
73
|
+
): T;
|
|
74
|
+
|
|
75
|
+
export declare function assignRelatedModels(model: Model, relatedModels: Model | Array<Model>): void;
|
|
76
|
+
export declare function getPrimaryKeysForModels(
|
|
77
|
+
connection: ConnectionBase,
|
|
78
|
+
Model: ModelClass,
|
|
79
|
+
models: Model | Array<Model>,
|
|
80
|
+
options?: {
|
|
81
|
+
includeRelations?: boolean | Array<string>,
|
|
82
|
+
skipRelations?: Array<string>,
|
|
83
|
+
},
|
|
84
|
+
): Array<any> | { [ key: string ]: Array<any> };
|
|
85
|
+
|
|
86
|
+
export declare function buildQueryFromModelsAttributes(
|
|
87
|
+
connection: ConnectionBase,
|
|
88
|
+
Model: ModelClass,
|
|
89
|
+
models: Model | GenericObject | Array<Model | GenericObject>
|
|
90
|
+
): QueryEngine;
|
package/lib/utils/model-utils.js
CHANGED
|
@@ -41,7 +41,7 @@ function injectModelMethod(self, method, methodName, fullMethodName) {
|
|
|
41
41
|
Object.defineProperties(self, {
|
|
42
42
|
[fullMethodName]: {
|
|
43
43
|
writable: true,
|
|
44
|
-
|
|
44
|
+
enumerable: false,
|
|
45
45
|
configurable: true,
|
|
46
46
|
value: method,
|
|
47
47
|
},
|
|
@@ -51,7 +51,7 @@ function injectModelMethod(self, method, methodName, fullMethodName) {
|
|
|
51
51
|
Object.defineProperties(self, {
|
|
52
52
|
[methodName]: {
|
|
53
53
|
writable: true,
|
|
54
|
-
|
|
54
|
+
enumerable: false,
|
|
55
55
|
configurable: true,
|
|
56
56
|
value: function(...args) {
|
|
57
57
|
return method.apply(this, args);
|
|
@@ -574,7 +574,7 @@ function assignRelatedModels(model, _relatedModels) {
|
|
|
574
574
|
|
|
575
575
|
Object.defineProperty(relatedScope, 'Model', {
|
|
576
576
|
writable: true,
|
|
577
|
-
|
|
577
|
+
enumerable: false,
|
|
578
578
|
configurable: true,
|
|
579
579
|
value: RelatedModel,
|
|
580
580
|
});
|
|
@@ -589,7 +589,7 @@ function assignRelatedModels(model, _relatedModels) {
|
|
|
589
589
|
if (Nife.isNotEmpty(pkValue)) {
|
|
590
590
|
Object.defineProperty(relatedScope, pkValue, {
|
|
591
591
|
writable: true,
|
|
592
|
-
|
|
592
|
+
enumerable: false,
|
|
593
593
|
configurable: true,
|
|
594
594
|
value: relatedModel,
|
|
595
595
|
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import ConnectionBase from '../connection/connection-base';
|
|
2
|
+
import { GenericObject } from '../interfaces/common';
|
|
3
|
+
import { Model, ModelClass } from '../model';
|
|
4
|
+
import { QueryEngine } from '../query-engine';
|
|
5
|
+
|
|
6
|
+
export declare function parseFilterFieldAndOperator(fieldName: string): { field: string, operator: string };
|
|
7
|
+
export declare function generateQueryFromFilter(
|
|
8
|
+
connection: ConnectionBase,
|
|
9
|
+
Model: ModelClass,
|
|
10
|
+
filter: Array<GenericObject | Model> | GenericObject | Model,
|
|
11
|
+
): QueryEngine;
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mythix-orm",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "ORM for Mythix framework",
|
|
5
|
-
"main": "lib/index
|
|
5
|
+
"main": "lib/index",
|
|
6
6
|
"type": "commonjs",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"coverage": "clear ; node ./node_modules/.bin/nyc ./node_modules/.bin/jasmine",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"homepage": "https://github.com/th317erd/mythix-orm#readme",
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@spothero/eslint-plugin-spothero": "github:spothero/eslint-plugin-spothero",
|
|
37
|
+
"@types/node": "^18.7.16",
|
|
37
38
|
"better-sqlite3": "^7.6.2",
|
|
38
39
|
"colors": "^1.4.0",
|
|
39
40
|
"diff": "^5.1.0",
|
package/.biblorc.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/* global __dirname */
|
|
4
|
-
|
|
5
|
-
const Path = require('path');
|
|
6
|
-
|
|
7
|
-
module.exports = {
|
|
8
|
-
rootDir: __dirname,
|
|
9
|
-
inputDir: Path.resolve(__dirname),
|
|
10
|
-
outputDir: Path.resolve(__dirname, '..', 'mythix-orm.wiki'),
|
|
11
|
-
files: [
|
|
12
|
-
{
|
|
13
|
-
include: /\/lib\/.*\.js$/,
|
|
14
|
-
parser: 'typescript',
|
|
15
|
-
compiler: 'typescript',
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
include: /\/docs\/.*\.md$/,
|
|
19
|
-
parser: 'markdown',
|
|
20
|
-
compiler: 'markdown',
|
|
21
|
-
},
|
|
22
|
-
],
|
|
23
|
-
exclude: [
|
|
24
|
-
/node_modules|\/spec\//
|
|
25
|
-
],
|
|
26
|
-
generatorOptions: {
|
|
27
|
-
baseURL: './',
|
|
28
|
-
},
|
|
29
|
-
};
|