velocious 1.0.30 → 1.0.31

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
@@ -3,7 +3,7 @@
3
3
  "velocious": "bin/velocious.js"
4
4
  },
5
5
  "name": "velocious",
6
- "version": "1.0.30",
6
+ "version": "1.0.31",
7
7
  "main": "index.js",
8
8
  "scripts": {
9
9
  "test": "jasmine",
@@ -33,7 +33,7 @@ export default class DbMigrate extends BaseCommand {
33
33
 
34
34
  await this.configuration.withConnections(async () => {
35
35
  await this.migrator.prepare()
36
- await this.migrator.migrateFiles(files)
36
+ await this.migrator.migrateFiles(files, async (importPath) => await import(importPath))
37
37
  })
38
38
  }
39
39
  }
@@ -34,7 +34,7 @@ export default class DbReset extends BaseCommand {
34
34
  await this.configuration.withConnections(async () => {
35
35
  await this.migrator.reset()
36
36
  await this.migrator.prepare()
37
- await this.migrator.migrateFiles(files)
37
+ await this.migrator.migrateFiles(files, async (importPath) => await import(importPath))
38
38
  })
39
39
  }
40
40
  }
@@ -36,20 +36,20 @@ export default class VelociousDatabaseMigrator {
36
36
  if (!this.migrationsVersions) throw new Error("Migrations versions hasn't been loaded yet")
37
37
  if (!this.migrationsVersions[dbIdentifier]) throw new Error(`Migrations versions hasn't been loaded yet for db: ${dbIdentifier}`)
38
38
 
39
- if (version in this.migrationsVersions) {
39
+ if (version in this.migrationsVersions[dbIdentifier]) {
40
40
  return true
41
41
  }
42
42
 
43
43
  return false
44
44
  }
45
45
 
46
- async migrateFiles(files) {
46
+ async migrateFiles(files, importCallback) {
47
47
  await this.configuration.withConnections(async () => {
48
48
  for (const migration of files) {
49
49
  await this.runMigrationFile({
50
50
  migration,
51
51
  requireMigration: async () => {
52
- const migrationImport = await import(migration.fullPath)
52
+ const migrationImport = await importCallback(migration.fullPath)
53
53
 
54
54
  return migrationImport.default
55
55
  }
@@ -1,8 +1,8 @@
1
- import DatabaseMigrateFromRequireContext from "./migrate-from-require-context.js"
2
1
  import React from "react"
3
2
  import useEnvSense from "env-sense/src/use-env-sense.js"
4
3
 
5
4
  import Configuration from "../configuration.js"
5
+ import Migrator from "./migrator.js"
6
6
  import restArgsError from "../utils/rest-args-error.js"
7
7
 
8
8
  const loadMigrations = function loadMigrations({migrationsRequireContext, ...restArgs}) {
@@ -15,9 +15,10 @@ const loadMigrations = function loadMigrations({migrationsRequireContext, ...res
15
15
 
16
16
  try {
17
17
  await Configuration.current().withConnections(async () => {
18
- const databaseMigrateFromRequireContext = new DatabaseMigrateFromRequireContext()
18
+ const migrator = new Migrator({configuration: Configuration.current()})
19
19
 
20
- await databaseMigrateFromRequireContext.execute(migrationsRequireContext)
20
+ await migrator.prepare()
21
+ await migrator.migrateFilesFromRequireContext(migrationsRequireContext)
21
22
  })
22
23
 
23
24
  await Configuration.current().initialize()
@@ -1,4 +1,5 @@
1
1
  import GetRoute from "./get-route.js"
2
+ import PostRoute from "./post-route.js"
2
3
  import ResourceRoute from "./resource-route.js"
3
4
 
4
5
  var VelociousBaseRoute
@@ -19,6 +20,12 @@ export function initBaseRoute() {
19
20
  throw new Error(`No 'matchWithPath' implemented on ${this.constructor.name}`)
20
21
  }
21
22
 
23
+ post(name, args) {
24
+ const route = new PostRoute({name, args})
25
+
26
+ this.routes.push(route)
27
+ }
28
+
22
29
  resources(name, callback) {
23
30
  const route = new ResourceRoute({name})
24
31
 
@@ -0,0 +1,24 @@
1
+ import BaseRoute, {initBaseRoute} from "./base-route.js"
2
+ import escapeStringRegexp from "escape-string-regexp"
3
+
4
+ initBaseRoute()
5
+
6
+ export default class VelociousRoutePostRoute extends BaseRoute {
7
+ constructor({name}) {
8
+ super()
9
+ this.name = name
10
+ this.regExp = new RegExp(`^(${escapeStringRegexp(name)})(.*)$`)
11
+ }
12
+
13
+ matchWithPath({params, path}) {
14
+ const match = path.match(this.regExp)
15
+
16
+ if (match) {
17
+ const [_beginnigSlash, _matchedName, restPath] = match
18
+
19
+ params.action = this.name
20
+
21
+ return {restPath}
22
+ }
23
+ }
24
+ }