velocious 1.0.63 → 1.0.65

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/bin/velocious.js CHANGED
@@ -22,5 +22,4 @@ for (let i = 0; i < processArgs.length; i++) {
22
22
  const cli = new Cli({parsedProcessArgs, processArgs})
23
23
 
24
24
  await cli.execute()
25
-
26
25
  process.exit(0)
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "velocious": "bin/velocious.js"
4
4
  },
5
5
  "name": "velocious",
6
- "version": "1.0.63",
6
+ "version": "1.0.65",
7
7
  "main": "index.js",
8
8
  "scripts": {
9
9
  "test": "VELOCIOUS_TEST_DIR=../ cd spec/dummy && npx velocious test",
@@ -1,4 +1,6 @@
1
1
  import Configuration from "./configuration.js"
2
+ import envSense from "env-sense/src/use-env-sense.js"
3
+ import fileExists from "./utils/file-exists.js"
2
4
 
3
5
  const configurationResolver = async (args) => {
4
6
  if (Configuration.current(false)) {
@@ -6,8 +8,17 @@ const configurationResolver = async (args) => {
6
8
  }
7
9
 
8
10
  const directory = args.directory || process.cwd()
9
- const configurationPath = `${directory}/src/config/configuration.js`
10
- let configuration
11
+ let configurationPrePath = `${directory}/src/config/configuration`
12
+ const configurationPathForNode = `${configurationPrePath}.node.js`
13
+ const configurationPathDefault = `${configurationPrePath}.js`
14
+ const {isServer} = envSense()
15
+ let configuration, configurationPath
16
+
17
+ if (isServer && await fileExists(configurationPathForNode)) {
18
+ configurationPath = configurationPathForNode
19
+ } else {
20
+ configurationPath = configurationPathDefault
21
+ }
11
22
 
12
23
  try {
13
24
  const configurationImport = await import(configurationPath)
@@ -390,24 +390,26 @@ class VelociousDatabaseRecord {
390
390
  const isNewRecord = this.isNewRecord()
391
391
  let result
392
392
 
393
- await this._runValidations()
393
+ await this.constructor._getConfiguration().ensureConnections(async () => {
394
+ await this._runValidations()
394
395
 
395
- await this.constructor.transaction(async () => {
396
- // If any belongs-to-relationships was saved, then updated-at should still be set on this record.
397
- const {savedCount} = await this._autoSaveBelongsToRelationships()
396
+ await this.constructor.transaction(async () => {
397
+ // If any belongs-to-relationships was saved, then updated-at should still be set on this record.
398
+ const {savedCount} = await this._autoSaveBelongsToRelationships()
398
399
 
399
- if (this.isPersisted()) {
400
- // If any has-many-relationships will be saved, then updated-at should still be set on this record.
401
- const autoSaveHasManyrelationships = this._autoSaveHasManyAndHasOneRelationshipsToSave()
400
+ if (this.isPersisted()) {
401
+ // If any has-many-relationships will be saved, then updated-at should still be set on this record.
402
+ const autoSaveHasManyrelationships = this._autoSaveHasManyAndHasOneRelationshipsToSave()
402
403
 
403
- if (this._hasChanges() || savedCount > 0 || autoSaveHasManyrelationships.length > 0) {
404
- result = await this._updateRecordWithChanges()
404
+ if (this._hasChanges() || savedCount > 0 || autoSaveHasManyrelationships.length > 0) {
405
+ result = await this._updateRecordWithChanges()
406
+ }
407
+ } else {
408
+ result = await this._createNewRecord()
405
409
  }
406
- } else {
407
- result = await this._createNewRecord()
408
- }
409
410
 
410
- await this._autoSaveHasManyAndHasOneRelationships({isNewRecord})
411
+ await this._autoSaveHasManyAndHasOneRelationships({isNewRecord})
412
+ })
411
413
  })
412
414
 
413
415
  return result
@@ -23,7 +23,7 @@ export default class TestFilesFinder {
23
23
  return this.foundFiles
24
24
  }
25
25
 
26
- findingPromisesLength = () => Object.keys(this.findingPromises).length
26
+ findingPromisesLength() { return Object.keys(this.findingPromises).length }
27
27
 
28
28
  async waitForFindingPromises() {
29
29
  while (this.findingPromisesLength() > 0) {
@@ -90,7 +90,7 @@ export default class TestFilesFinder {
90
90
  return true
91
91
  }
92
92
  }
93
- } else if (file.match(/-(spec|test)\.js/)) {
93
+ } else if (file.match(/-(spec|test)\.(m|)js$/)) {
94
94
  return true
95
95
  }
96
96
 
@@ -1,6 +1,6 @@
1
1
  import fs from "node:fs/promises"
2
2
 
3
- const fileExists = async (path) => {
3
+ async function fileExists(path) {
4
4
  try {
5
5
  await fs.access(path)
6
6