velocious 1.0.84 → 1.0.85
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/package.json
CHANGED
|
@@ -20,10 +20,11 @@ export default class VelociousCliCommandsServer extends BaseCommand{
|
|
|
20
20
|
},
|
|
21
21
|
type: "server"
|
|
22
22
|
})
|
|
23
|
+
const environment = this.configuration.getEnvironment()
|
|
23
24
|
|
|
24
25
|
await application.initialize()
|
|
25
26
|
await application.startHttpServer()
|
|
26
|
-
console.log(`Started Velocious HTTP server on ${host}:${port}`)
|
|
27
|
+
console.log(`Started Velocious HTTP server on ${host}:${port} in ${environment} environment`)
|
|
27
28
|
await application.wait()
|
|
28
29
|
}
|
|
29
30
|
}
|
package/src/cli/index.js
CHANGED
|
@@ -11,11 +11,11 @@ export default class VelociousCli {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
async execute() {
|
|
14
|
-
const __filename = fileURLToPath(import.meta.url)
|
|
15
|
-
const basePath = await fs.realpath(`${dirname(__filename)}/../..`)
|
|
16
14
|
const commandParts = this.args.processArgs[0].split(":")
|
|
17
15
|
const filePaths = []
|
|
18
|
-
|
|
16
|
+
const basePath = await this.getBasePath()
|
|
17
|
+
const commandsPath = `${basePath}/src/cli/commands`
|
|
18
|
+
let filePath = commandsPath
|
|
19
19
|
|
|
20
20
|
for (let commandPart of commandParts) {
|
|
21
21
|
if (commandPart == "d") commandPart = "destroy"
|
|
@@ -38,7 +38,23 @@ export default class VelociousCli {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
if (!fileFound)
|
|
41
|
+
if (!fileFound) {
|
|
42
|
+
const possibleCommands = []
|
|
43
|
+
const commandFiles = fs.glob(`${commandsPath}/**/*.js`)
|
|
44
|
+
|
|
45
|
+
for await (const aFilePath of commandFiles) {
|
|
46
|
+
const aFilePathParts = aFilePath.split("/")
|
|
47
|
+
const lastPart = aFilePathParts[aFilePathParts.length - 1]
|
|
48
|
+
|
|
49
|
+
if (lastPart == "index.js") {
|
|
50
|
+
possibleCommands.push(aFilePathParts[aFilePathParts.length - 2])
|
|
51
|
+
} else {
|
|
52
|
+
possibleCommands.push(lastPart.replace(".js", ""))
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
throw new Error(`Unknown command: ${this.args.processArgs[0]} which should have been one of: ${possibleCommands.sort().join(", ")}`)
|
|
57
|
+
}
|
|
42
58
|
|
|
43
59
|
const commandClassImport = await import(fileFound)
|
|
44
60
|
const CommandClass = commandClassImport.default
|
|
@@ -54,6 +70,13 @@ export default class VelociousCli {
|
|
|
54
70
|
return await commandInstance.execute()
|
|
55
71
|
}
|
|
56
72
|
|
|
73
|
+
async getBasePath() {
|
|
74
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
75
|
+
const basePath = await fs.realpath(`${dirname(__filename)}/../..`)
|
|
76
|
+
|
|
77
|
+
return basePath
|
|
78
|
+
}
|
|
79
|
+
|
|
57
80
|
async loadConfiguration() {
|
|
58
81
|
this.configuration = await configurationResolver({directory: this.args.directory})
|
|
59
82
|
this.configuration.setCurrent()
|
|
@@ -299,6 +299,11 @@ export default class VelociousDatabaseQuery {
|
|
|
299
299
|
return await this._executeQuery()
|
|
300
300
|
}
|
|
301
301
|
|
|
302
|
+
/**
|
|
303
|
+
* Converts query results to array of model instances
|
|
304
|
+
*
|
|
305
|
+
* @returns {Promise<Array>} Array of model instances
|
|
306
|
+
*/
|
|
302
307
|
async toArray() {
|
|
303
308
|
const models = []
|
|
304
309
|
const results = await this.results()
|
|
@@ -323,8 +328,17 @@ export default class VelociousDatabaseQuery {
|
|
|
323
328
|
return models
|
|
324
329
|
}
|
|
325
330
|
|
|
331
|
+
/**
|
|
332
|
+
* Generates SQL string representing this query
|
|
333
|
+
*
|
|
334
|
+
* @returns {String} SQL string representing this query
|
|
335
|
+
*/
|
|
326
336
|
toSql() { return this.driver.queryToSql(this) }
|
|
327
337
|
|
|
338
|
+
/**
|
|
339
|
+
* @param {Object|String} where
|
|
340
|
+
* @returns {VelociousDatabaseQuery} This query instance
|
|
341
|
+
*/
|
|
328
342
|
where(where) {
|
|
329
343
|
if (typeof where == "string") {
|
|
330
344
|
where = new WherePlain(this, where)
|
|
@@ -204,6 +204,12 @@ class VelociousDatabaseRecord {
|
|
|
204
204
|
return this._instanceRelationships[relationshipName]
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
+
/**
|
|
208
|
+
* Adds a belongs-to-relationship to the model.
|
|
209
|
+
*
|
|
210
|
+
* @param {string} relationshipName The name of the relationship.
|
|
211
|
+
* @param {object} options The options for the relationship.
|
|
212
|
+
*/
|
|
207
213
|
static belongsTo(relationshipName, options) {
|
|
208
214
|
this._defineRelationship(relationshipName, Object.assign({type: "belongsTo"}, options))
|
|
209
215
|
}
|
|
@@ -241,10 +247,22 @@ class VelociousDatabaseRecord {
|
|
|
241
247
|
return this.constructor._getConfiguration()
|
|
242
248
|
}
|
|
243
249
|
|
|
250
|
+
/**
|
|
251
|
+
* Adds a has-many-relationship to the model class.
|
|
252
|
+
*
|
|
253
|
+
* @param {string} relationshipName The name of the relationship (e.g. "posts")
|
|
254
|
+
* @param {object} options The options for the relationship (e.g. {className: "Post"})
|
|
255
|
+
*/
|
|
244
256
|
static hasMany(relationshipName, options = {}) {
|
|
245
257
|
return this._defineRelationship(relationshipName, Object.assign({type: "hasMany"}, options))
|
|
246
258
|
}
|
|
247
259
|
|
|
260
|
+
/**
|
|
261
|
+
* Adds a has-one-relationship to the model class.
|
|
262
|
+
*
|
|
263
|
+
* @param {string} relationshipName The name of the relationship (e.g. "post")
|
|
264
|
+
* @param {object} options The options for the relationship (e.g. {className: "Post"})
|
|
265
|
+
*/
|
|
248
266
|
static hasOne(relationshipName, options = {}) {
|
|
249
267
|
return this._defineRelationship(relationshipName, Object.assign({type: "hasOne"}, options))
|
|
250
268
|
}
|
|
@@ -650,6 +668,12 @@ class VelociousDatabaseRecord {
|
|
|
650
668
|
}
|
|
651
669
|
}
|
|
652
670
|
|
|
671
|
+
/**
|
|
672
|
+
* Adds a validation to an attribute.
|
|
673
|
+
*
|
|
674
|
+
* @param {string} attributeName The name of the attribute to validate.
|
|
675
|
+
* @param {object} validators The validators to add. Key is the validator name, value is the validator arguments.
|
|
676
|
+
*/
|
|
653
677
|
static async validates(attributeName, validators) {
|
|
654
678
|
for (const validatorName in validators) {
|
|
655
679
|
const validatorArgs = validators[validatorName]
|
|
@@ -805,12 +829,18 @@ class VelociousDatabaseRecord {
|
|
|
805
829
|
this._isNewRecord = false
|
|
806
830
|
}
|
|
807
831
|
|
|
832
|
+
/**
|
|
833
|
+
* Assigns the given attributes to the record.
|
|
834
|
+
*/
|
|
808
835
|
assign(attributesToAssign) {
|
|
809
836
|
for (const attributeToAssign in attributesToAssign) {
|
|
810
837
|
this.setAttribute(attributeToAssign, attributesToAssign[attributeToAssign])
|
|
811
838
|
}
|
|
812
839
|
}
|
|
813
840
|
|
|
841
|
+
/**
|
|
842
|
+
* Returns a the current attributes of the record (original attributes from database plus changes)
|
|
843
|
+
*/
|
|
814
844
|
attributes() {
|
|
815
845
|
return Object.assign({}, this._attributes, this._changes)
|
|
816
846
|
}
|
|
@@ -821,6 +851,9 @@ class VelociousDatabaseRecord {
|
|
|
821
851
|
return this.constructor.connection()
|
|
822
852
|
}
|
|
823
853
|
|
|
854
|
+
/**
|
|
855
|
+
* Destroys the record in the database and all of its dependent records.
|
|
856
|
+
*/
|
|
824
857
|
async destroy() {
|
|
825
858
|
for (const relationship of this.constructor.getRelationships()) {
|
|
826
859
|
if (relationship.getDependent() != "destroy") {
|
|
@@ -867,8 +900,11 @@ class VelociousDatabaseRecord {
|
|
|
867
900
|
await this._connection().query(sql)
|
|
868
901
|
}
|
|
869
902
|
|
|
870
|
-
_hasChanges
|
|
903
|
+
_hasChanges() { return Object.keys(this._changes).length > 0 }
|
|
871
904
|
|
|
905
|
+
/**
|
|
906
|
+
* Returns true if the model has been changed since it was loaded from the database.
|
|
907
|
+
*/
|
|
872
908
|
isChanged() {
|
|
873
909
|
if (this.isNewRecord() || this._hasChanges()){
|
|
874
910
|
return true
|
|
@@ -898,6 +934,9 @@ class VelociousDatabaseRecord {
|
|
|
898
934
|
return false
|
|
899
935
|
}
|
|
900
936
|
|
|
937
|
+
/**
|
|
938
|
+
* Returns the changes that have been made to this record since it was loaded from the database.
|
|
939
|
+
*/
|
|
901
940
|
changes() {
|
|
902
941
|
const changes = {}
|
|
903
942
|
|
|
@@ -916,6 +955,11 @@ class VelociousDatabaseRecord {
|
|
|
916
955
|
return this.constructor.tableName()
|
|
917
956
|
}
|
|
918
957
|
|
|
958
|
+
/**
|
|
959
|
+
* Reads an attribute value from the record.
|
|
960
|
+
*
|
|
961
|
+
* @param {string} attributeName The name of the attribute to read. This is the attribute name, not the column name.
|
|
962
|
+
*/
|
|
919
963
|
readAttribute(attributeName) {
|
|
920
964
|
const columnName = this.constructor._attributeNameToColumnName[attributeName]
|
|
921
965
|
|
|
@@ -924,6 +968,11 @@ class VelociousDatabaseRecord {
|
|
|
924
968
|
return this.readColumn(columnName)
|
|
925
969
|
}
|
|
926
970
|
|
|
971
|
+
/**
|
|
972
|
+
* Reads a column value from the record.
|
|
973
|
+
*
|
|
974
|
+
* @param {string} attributeName The name of the column to read. This is the column name, not the attribute name.
|
|
975
|
+
*/
|
|
927
976
|
readColumn(attributeName) {
|
|
928
977
|
const column = this.constructor.getColumns().find((column) => column.getName() == attributeName)
|
|
929
978
|
let result
|
|
@@ -1110,6 +1159,11 @@ class VelociousDatabaseRecord {
|
|
|
1110
1159
|
return validationErrorMessages
|
|
1111
1160
|
}
|
|
1112
1161
|
|
|
1162
|
+
/**
|
|
1163
|
+
* Assigns the attributes to the record and saves it.
|
|
1164
|
+
*
|
|
1165
|
+
* @param {Object} attributesToAssign - The attributes to assign to the record.
|
|
1166
|
+
*/
|
|
1113
1167
|
async update(attributesToAssign) {
|
|
1114
1168
|
if (attributesToAssign) this.assign(attributesToAssign)
|
|
1115
1169
|
|