velocious 1.0.111 → 1.0.113
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/bin/velocious.js +0 -0
- package/dist/src/database/query/index.d.ts +41 -115
- package/dist/src/database/query/index.d.ts.map +1 -1
- package/dist/src/database/query/index.js +26 -205
- package/dist/src/database/query/join-object.d.ts.map +1 -1
- package/dist/src/database/query/join-object.js +7 -2
- package/dist/src/database/query/model-class-query.d.ts +98 -0
- package/dist/src/database/query/model-class-query.d.ts.map +1 -0
- package/dist/src/database/query/model-class-query.js +249 -0
- package/dist/src/database/query-parser/select-parser.d.ts.map +1 -1
- package/dist/src/database/query-parser/select-parser.js +3 -1
- package/dist/src/database/record/index.d.ts +33 -46
- package/dist/src/database/record/index.d.ts.map +1 -1
- package/dist/src/database/record/index.js +25 -38
- package/dist/src/environment-handlers/node/cli/commands/generate/base-models.d.ts.map +1 -1
- package/dist/src/environment-handlers/node/cli/commands/generate/base-models.js +11 -4
- package/package.json +2 -2
|
@@ -12,7 +12,7 @@ import HasManyRelationship from "./relationships/has-many.js";
|
|
|
12
12
|
import HasOneInstanceRelationship from "./instance-relationships/has-one.js";
|
|
13
13
|
import HasOneRelationship from "./relationships/has-one.js";
|
|
14
14
|
import * as inflection from "inflection";
|
|
15
|
-
import
|
|
15
|
+
import ModelClassQuery from "../query/model-class-query.js";
|
|
16
16
|
import restArgsError from "../../utils/rest-args-error.js";
|
|
17
17
|
import ValidatorsPresence from "./validators/presence.js";
|
|
18
18
|
import ValidatorsUniqueness from "./validators/uniqueness.js";
|
|
@@ -27,21 +27,18 @@ class ValidationError extends Error {
|
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* @param {VelociousDatabaseRecord} model
|
|
30
|
+
* @returns {void}
|
|
30
31
|
*/
|
|
31
32
|
setModel(model) {
|
|
32
33
|
this._model = model;
|
|
33
34
|
}
|
|
34
|
-
/**
|
|
35
|
-
* @returns {Record<string, ValidationErrorObjectType[]>}
|
|
36
|
-
*/
|
|
35
|
+
/** @returns {Record<string, ValidationErrorObjectType[]>} */
|
|
37
36
|
getValidationErrors() {
|
|
38
37
|
if (!this._validationErrors)
|
|
39
38
|
throw new Error("Validation errors hasn't been set");
|
|
40
39
|
return this._validationErrors;
|
|
41
40
|
}
|
|
42
|
-
/**
|
|
43
|
-
* @param {Record<string, ValidationErrorObjectType[]>} validationErrors
|
|
44
|
-
*/
|
|
41
|
+
/** @param {Record<string, ValidationErrorObjectType[]>} validationErrors */
|
|
45
42
|
setValidationErrors(validationErrors) {
|
|
46
43
|
this._validationErrors = validationErrors;
|
|
47
44
|
}
|
|
@@ -903,11 +900,11 @@ class VelociousDatabaseRecord {
|
|
|
903
900
|
translation.assign(assignments);
|
|
904
901
|
}
|
|
905
902
|
/**
|
|
906
|
-
* @returns {
|
|
903
|
+
* @returns {ModelClassQuery<typeof this>}
|
|
907
904
|
*/
|
|
908
905
|
static _newQuery() {
|
|
909
906
|
const handler = new Handler();
|
|
910
|
-
const query = new
|
|
907
|
+
const query = new ModelClassQuery({
|
|
911
908
|
driver: this.connection(),
|
|
912
909
|
handler,
|
|
913
910
|
modelClass: this
|
|
@@ -922,7 +919,7 @@ class VelociousDatabaseRecord {
|
|
|
922
919
|
return this.primaryKey();
|
|
923
920
|
}
|
|
924
921
|
/**
|
|
925
|
-
* @returns {
|
|
922
|
+
* @returns {ModelClassQuery<typeof this>}
|
|
926
923
|
*/
|
|
927
924
|
static all() {
|
|
928
925
|
return this._newQuery();
|
|
@@ -959,7 +956,7 @@ class VelociousDatabaseRecord {
|
|
|
959
956
|
}
|
|
960
957
|
/**
|
|
961
958
|
* @param {{[key: string]: any}} conditions
|
|
962
|
-
* @param {function() : void} callback
|
|
959
|
+
* @param {function() : void} [callback]
|
|
963
960
|
* @returns {Promise<InstanceType<typeof this>>}
|
|
964
961
|
*/
|
|
965
962
|
static async findOrCreateBy(conditions, callback) {
|
|
@@ -967,7 +964,7 @@ class VelociousDatabaseRecord {
|
|
|
967
964
|
}
|
|
968
965
|
/**
|
|
969
966
|
* @param {object} conditions
|
|
970
|
-
* @param {function(import("../record/index.js").default) : void} callback
|
|
967
|
+
* @param {function(import("../record/index.js").default) : void} [callback]
|
|
971
968
|
* @returns {Promise<InstanceType<typeof this>>}
|
|
972
969
|
*/
|
|
973
970
|
static async findOrInitializeBy(conditions, callback) {
|
|
@@ -981,7 +978,7 @@ class VelociousDatabaseRecord {
|
|
|
981
978
|
}
|
|
982
979
|
/**
|
|
983
980
|
* @param {string|{[key: string]: any}} join
|
|
984
|
-
* @returns {
|
|
981
|
+
* @returns {ModelClassQuery<typeof this>}
|
|
985
982
|
*/
|
|
986
983
|
static joins(join) {
|
|
987
984
|
return this._newQuery().joins(join);
|
|
@@ -994,28 +991,28 @@ class VelociousDatabaseRecord {
|
|
|
994
991
|
}
|
|
995
992
|
/**
|
|
996
993
|
* @param {number} value
|
|
997
|
-
* @returns {
|
|
994
|
+
* @returns {ModelClassQuery<typeof this>}
|
|
998
995
|
*/
|
|
999
996
|
static limit(value) {
|
|
1000
997
|
return this._newQuery().limit(value);
|
|
1001
998
|
}
|
|
1002
999
|
/**
|
|
1003
1000
|
* @param {string | number} order
|
|
1004
|
-
* @returns {
|
|
1001
|
+
* @returns {ModelClassQuery<typeof this>}
|
|
1005
1002
|
*/
|
|
1006
1003
|
static order(order) {
|
|
1007
1004
|
return this._newQuery().order(order);
|
|
1008
1005
|
}
|
|
1009
1006
|
/**
|
|
1010
1007
|
* @param {import("../query/index.js").NestedPreloadRecord} preload
|
|
1011
|
-
* @returns {
|
|
1008
|
+
* @returns {ModelClassQuery<typeof this>}
|
|
1012
1009
|
*/
|
|
1013
1010
|
static preload(preload) {
|
|
1014
1011
|
return this._newQuery().preload(preload);
|
|
1015
1012
|
}
|
|
1016
1013
|
/**
|
|
1017
1014
|
* @param {import("../query/index.js").SelectArgumentType} select
|
|
1018
|
-
* @returns {
|
|
1015
|
+
* @returns {ModelClassQuery<typeof this>}
|
|
1019
1016
|
*/
|
|
1020
1017
|
static select(select) {
|
|
1021
1018
|
return this._newQuery().select(select);
|
|
@@ -1028,7 +1025,7 @@ class VelociousDatabaseRecord {
|
|
|
1028
1025
|
}
|
|
1029
1026
|
/**
|
|
1030
1027
|
* @param {import("../query/index.js").WhereArgumentType} where
|
|
1031
|
-
* @returns {
|
|
1028
|
+
* @returns {ModelClassQuery<typeof this>}
|
|
1032
1029
|
*/
|
|
1033
1030
|
static where(where) {
|
|
1034
1031
|
return this._newQuery().where(where);
|
|
@@ -1235,9 +1232,7 @@ class VelociousDatabaseRecord {
|
|
|
1235
1232
|
}
|
|
1236
1233
|
return belongsToChanges;
|
|
1237
1234
|
}
|
|
1238
|
-
/**
|
|
1239
|
-
* @returns {Promise<void>}
|
|
1240
|
-
*/
|
|
1235
|
+
/** @returns {Promise<void>} */
|
|
1241
1236
|
async _createNewRecord() {
|
|
1242
1237
|
if (!this.getModelClass().connection()["insertSql"]) {
|
|
1243
1238
|
throw new Error(`No insertSql on ${this.getModelClass().connection().constructor.name}`);
|
|
@@ -1276,9 +1271,7 @@ class VelociousDatabaseRecord {
|
|
|
1276
1271
|
instanceRelationship.setPreloaded(true);
|
|
1277
1272
|
}
|
|
1278
1273
|
}
|
|
1279
|
-
/**
|
|
1280
|
-
* @returns {Promise<void>}
|
|
1281
|
-
*/
|
|
1274
|
+
/** @returns {Promise<void>} */
|
|
1282
1275
|
async _updateRecordWithChanges() {
|
|
1283
1276
|
/** @type {Record<string, any>} */
|
|
1284
1277
|
const conditions = {};
|
|
@@ -1298,9 +1291,7 @@ class VelociousDatabaseRecord {
|
|
|
1298
1291
|
await this._reloadWithId(this.id());
|
|
1299
1292
|
}
|
|
1300
1293
|
}
|
|
1301
|
-
/**
|
|
1302
|
-
* @returns {number|string}
|
|
1303
|
-
*/
|
|
1294
|
+
/** @returns {number|string} */
|
|
1304
1295
|
id() {
|
|
1305
1296
|
if (!this.getModelClass()._columnNameToAttributeName) {
|
|
1306
1297
|
throw new Error(`Column names mapping hasn't been set on ${this.constructor.name}. Has the model been initialized?`);
|
|
@@ -1312,13 +1303,9 @@ class VelociousDatabaseRecord {
|
|
|
1312
1303
|
}
|
|
1313
1304
|
return this.readAttribute(attributeName);
|
|
1314
1305
|
}
|
|
1315
|
-
/**
|
|
1316
|
-
* @returns {boolean}
|
|
1317
|
-
*/
|
|
1306
|
+
/** @returns {boolean} */
|
|
1318
1307
|
isPersisted() { return !this._isNewRecord; }
|
|
1319
|
-
/**
|
|
1320
|
-
* @returns {boolean}
|
|
1321
|
-
*/
|
|
1308
|
+
/** @returns {boolean} */
|
|
1322
1309
|
isNewRecord() { return this._isNewRecord; }
|
|
1323
1310
|
/**
|
|
1324
1311
|
* @param {boolean} newIsNewRecord
|
|
@@ -1328,14 +1315,16 @@ class VelociousDatabaseRecord {
|
|
|
1328
1315
|
this._isNewRecord = newIsNewRecord;
|
|
1329
1316
|
}
|
|
1330
1317
|
/**
|
|
1318
|
+
* @template {typeof VelociousDatabaseRecord} MC
|
|
1331
1319
|
* @param {string | number} id
|
|
1320
|
+
* @returns {Promise<void>}
|
|
1332
1321
|
*/
|
|
1333
1322
|
async _reloadWithId(id) {
|
|
1334
1323
|
const primaryKey = this.getModelClass().primaryKey();
|
|
1335
1324
|
/** @type {Record<string, any>} */
|
|
1336
1325
|
const whereObject = {};
|
|
1337
1326
|
whereObject[primaryKey] = id;
|
|
1338
|
-
const query = this.getModelClass().where(whereObject);
|
|
1327
|
+
const query = /** @type {import("../query/model-class-query.js").default<MC>} */ (this.getModelClass().where(whereObject));
|
|
1339
1328
|
const reloadedModel = await query.first();
|
|
1340
1329
|
if (!reloadedModel)
|
|
1341
1330
|
throw new Error(`${this.constructor.name}#${id} couldn't be reloaded - record didn't exist`);
|
|
@@ -1346,7 +1335,7 @@ class VelociousDatabaseRecord {
|
|
|
1346
1335
|
* @returns {Promise<void>}
|
|
1347
1336
|
*/
|
|
1348
1337
|
async reload() {
|
|
1349
|
-
this._reloadWithId(this.readAttribute("id"));
|
|
1338
|
+
await this._reloadWithId(this.readAttribute("id"));
|
|
1350
1339
|
}
|
|
1351
1340
|
async _runValidations() {
|
|
1352
1341
|
/** @type {Record<string, {type: string, message: string}>} */
|
|
@@ -1367,9 +1356,7 @@ class VelociousDatabaseRecord {
|
|
|
1367
1356
|
throw validationError;
|
|
1368
1357
|
}
|
|
1369
1358
|
}
|
|
1370
|
-
/**
|
|
1371
|
-
* @returns {string[]}
|
|
1372
|
-
*/
|
|
1359
|
+
/** @returns {string[]} */
|
|
1373
1360
|
fullErrorMessages() {
|
|
1374
1361
|
/** @type {string[]} */
|
|
1375
1362
|
const validationErrorMessages = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-models.d.ts","sourceRoot":"","sources":["../../../../../../../src/environment-handlers/node/cli/commands/generate/base-models.js"],"names":[],"mappings":"AAKA;IACE,yBA4OC;IAED;;;OAGG;IACH,4BAHW,OAAO,gDAAgD,EAAE,OAAO,GAC9D,MAAM,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"base-models.d.ts","sourceRoot":"","sources":["../../../../../../../src/environment-handlers/node/cli/commands/generate/base-models.js"],"names":[],"mappings":"AAKA;IACE,yBA4OC;IAED;;;OAGG;IACH,4BAHW,OAAO,gDAAgD,EAAE,OAAO,GAC9D,MAAM,GAAG,SAAS,CAkB9B;CACF;wBAzQuB,oCAAoC"}
|
|
@@ -205,17 +205,24 @@ export default class DbGenerateModel extends BaseCommand {
|
|
|
205
205
|
* @returns {string | undefined}
|
|
206
206
|
*/
|
|
207
207
|
jsDocTypeFromColumn(column) {
|
|
208
|
-
|
|
208
|
+
const type = column.getType();
|
|
209
|
+
if (type == "boolean") {
|
|
210
|
+
return "boolean";
|
|
211
|
+
}
|
|
212
|
+
else if (type == "json") {
|
|
213
|
+
return "Record<string, any>";
|
|
214
|
+
}
|
|
215
|
+
else if (type == "blob" || type == "varchar" || type == "text" || type == "uuid") {
|
|
209
216
|
return "string";
|
|
210
217
|
}
|
|
211
|
-
else if (["bigint", "int", "integer", "smallint"].includes(
|
|
218
|
+
else if (["bigint", "int", "integer", "smallint"].includes(type)) {
|
|
212
219
|
return "number";
|
|
213
220
|
}
|
|
214
|
-
else if (["date", "datetime"].includes(
|
|
221
|
+
else if (["date", "datetime"].includes(type)) {
|
|
215
222
|
return "Date";
|
|
216
223
|
}
|
|
217
224
|
else {
|
|
218
|
-
console.error(`Unknown column type: ${
|
|
225
|
+
console.error(`Unknown column type: ${type}`);
|
|
219
226
|
}
|
|
220
227
|
}
|
|
221
228
|
}
|
package/package.json
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
"velocious": "dist/bin/velocious.js"
|
|
4
4
|
},
|
|
5
5
|
"name": "velocious",
|
|
6
|
-
"version": "1.0.
|
|
6
|
+
"version": "1.0.113",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
9
9
|
"files": ["dist/**"],
|
|
10
10
|
"scripts": {
|
|
11
|
-
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
11
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json && chmod +x dist/bin/velocious.js",
|
|
12
12
|
"lint": "eslint",
|
|
13
13
|
"test": "VELOCIOUS_TEST_DIR=../ cd spec/dummy && npx velocious test",
|
|
14
14
|
"prepublishOnly": "npm run build",
|