velocious 1.0.5 → 1.0.7
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.mjs → velocious.js} +1 -1
- package/package.json +7 -5
- package/peak_flow.yml +1 -1
- package/spec/cli/commands/db/{create-spec.mjs → create-spec.js} +3 -3
- package/spec/cli/commands/db/{migrate-spec.mjs → migrate-spec.js} +4 -2
- package/spec/cli/commands/destroy/{migration-spec.mjs → migration-spec.js} +2 -2
- package/spec/cli/commands/generate/{migration-spec.mjs → migration-spec.js} +3 -3
- package/spec/cli/commands/{init-spec.mjs → init-spec.js} +6 -6
- package/spec/cli/commands/test/{test-files-finder-spec.mjs → test-files-finder-spec.js} +2 -2
- package/spec/database/connection/drivers/mysql/{query-parser-spec.mjs → query-parser-spec.js} +6 -6
- package/spec/database/drivers/mysql/{connection-spec.mjs → connection-spec.js} +2 -2
- package/spec/database/record/create-spec.js +23 -0
- package/spec/database/record/{destroy-spec.mjs → destroy-spec.js} +2 -2
- package/spec/database/record/{find-spec.mjs → find-spec.js} +2 -3
- package/spec/database/record/query-spec.js +37 -0
- package/spec/database/record/{update-spec.mjs → update-spec.js} +2 -2
- package/spec/dummy/{index.mjs → index.js} +16 -4
- package/spec/dummy/src/config/configuration.example.js +36 -0
- package/spec/dummy/src/config/configuration.peakflow.js +37 -0
- package/spec/dummy/src/config/{routes.mjs → routes.js} +1 -1
- package/spec/dummy/src/database/migrations/{20230728075328-create-projects.mjs → 20230728075328-create-projects.js} +1 -2
- package/spec/dummy/src/database/migrations/{20230728075329-create-tasks.mjs → 20230728075329-create-tasks.js} +1 -2
- package/spec/dummy/src/database/migrations/20250605133926-create-project-translations.js +16 -0
- package/spec/dummy/src/models/project.js +9 -0
- package/spec/dummy/src/models/task.js +8 -0
- package/spec/dummy/src/routes/tasks/{controller.mjs → controller.js} +2 -2
- package/spec/http-server/{client-spec.mjs → client-spec.js} +3 -3
- package/spec/http-server/{get-spec.mjs → get-spec.js} +1 -1
- package/spec/http-server/{post-spec.mjs → post-spec.js} +2 -2
- package/spec/support/jasmine.json +2 -2
- package/src/{application.mjs → application.js} +3 -3
- package/src/big-brother.js +37 -0
- package/src/cli/commands/db/{create.mjs → create.js} +9 -7
- package/src/cli/commands/db/{migrate.mjs → migrate.js} +4 -5
- package/src/cli/commands/destroy/{migration.mjs → migration.js} +2 -2
- package/src/cli/commands/generate/{migration.mjs → migration.js} +5 -5
- package/src/cli/commands/generate/{model.mjs → model.js} +5 -5
- package/src/cli/commands/{init.mjs → init.js} +6 -6
- package/src/cli/commands/{server.mjs → server.js} +1 -1
- package/src/cli/commands/test/{index.mjs → index.js} +3 -3
- package/src/cli/commands/test/{test-files-finder.mjs → test-files-finder.js} +1 -1
- package/src/cli/{index.mjs → index.js} +4 -4
- package/src/{configuration-resolver.mjs → configuration-resolver.js} +2 -2
- package/src/{configuration.mjs → configuration.js} +39 -3
- package/src/database/drivers/{base.mjs → base.js} +23 -4
- package/src/database/drivers/mysql/column.js +8 -0
- package/src/database/drivers/mysql/{index.mjs → index.js} +44 -12
- package/src/database/drivers/{sqlite/options.mjs → mysql/options.js} +2 -1
- package/src/database/drivers/mysql/query-parser.js +4 -0
- package/src/database/drivers/mysql/sql/{create-database.mjs → create-database.js} +1 -1
- package/src/database/drivers/{sqlite/sql/create-table.mjs → mysql/sql/create-table.js} +1 -1
- package/src/database/drivers/mysql/sql/{delete.mjs → delete.js} +1 -1
- package/src/database/drivers/{sqlite/sql/insert.mjs → mysql/sql/insert.js} +1 -1
- package/src/database/drivers/mysql/sql/{update.mjs → update.js} +1 -1
- package/src/database/drivers/mysql/table.js +25 -0
- package/src/database/drivers/sqlite/base.js +108 -0
- package/src/database/drivers/sqlite/column.js +10 -0
- package/src/database/drivers/sqlite/{index.native.mjs → index.native.js} +19 -22
- package/src/database/drivers/sqlite/index.web.js +55 -0
- package/src/database/drivers/{mysql/options.mjs → sqlite/options.js} +3 -2
- package/src/database/drivers/sqlite/query-parser.js +4 -0
- package/src/database/drivers/sqlite/query.native.js +24 -0
- package/src/database/drivers/sqlite/query.web.js +34 -0
- package/src/database/drivers/sqlite/sql/create-index.js +4 -0
- package/src/database/drivers/{mysql/sql/create-table.mjs → sqlite/sql/create-table.js} +1 -1
- package/src/database/drivers/sqlite/sql/{delete.mjs → delete.js} +1 -1
- package/src/database/drivers/{mysql/sql/insert.mjs → sqlite/sql/insert.js} +1 -1
- package/src/database/drivers/sqlite/sql/{update.mjs → update.js} +1 -1
- package/src/database/drivers/sqlite/table.js +24 -0
- package/src/database/initializer-from-require-context.js +21 -0
- package/src/database/{migrate-from-require-context.mjs → migrate-from-require-context.js} +2 -2
- package/src/database/migration/index.js +50 -0
- package/src/database/{migrator.mjs → migrator.js} +4 -2
- package/src/database/pool/{async-tracked-multi-connection.mjs → async-tracked-multi-connection.js} +1 -1
- package/src/database/pool/{base.mjs → base.js} +6 -1
- package/src/database/pool/{single-multi-use.mjs → single-multi-use.js} +1 -1
- package/src/database/query/{base.mjs → base.js} +2 -1
- package/src/database/query/{create-database-base.mjs → create-database-base.js} +1 -1
- package/src/database/query/create-index-base.js +50 -0
- package/src/database/query/create-table-base.js +92 -0
- package/src/database/query/{delete-base.mjs → delete-base.js} +1 -1
- package/src/database/query/{from-plain.mjs → from-plain.js} +1 -1
- package/src/database/query/{from-table.mjs → from-table.js} +1 -1
- package/src/database/query/index.js +206 -0
- package/src/database/query/{join-plain.mjs → join-plain.js} +1 -1
- package/src/database/query/{order-plain.mjs → order-plain.js} +1 -1
- package/src/database/query/preloader/belongs-to.js +52 -0
- package/src/database/query/preloader/has-many.js +55 -0
- package/src/database/query/preloader.js +41 -0
- package/src/database/query/{select-plain.mjs → select-plain.js} +1 -1
- package/src/database/query/{select-table-and-column.mjs → select-table-and-column.js} +1 -1
- package/src/database/query/where-base.js +9 -0
- package/src/database/query/where-hash.js +35 -0
- package/src/database/query/where-plain.js +13 -0
- package/src/database/query-parser/base-query-parser.js +33 -0
- package/src/database/query-parser/group-parser.js +40 -0
- package/src/database/query-parser/joins-parser.js +71 -0
- package/src/database/query-parser/limit-parser.js +40 -0
- package/src/database/query-parser/{options.mjs → options.js} +2 -1
- package/src/database/query-parser/order-parser.js +39 -0
- package/src/database/query-parser/{select-parser.mjs → select-parser.js} +5 -1
- package/src/database/query-parser/where-parser.js +39 -0
- package/src/database/record/index.js +622 -0
- package/src/database/record/instance-relationships/base.js +28 -0
- package/src/database/record/instance-relationships/belongs-to.js +20 -0
- package/src/database/record/instance-relationships/has-many.js +47 -0
- package/src/database/record/relationships/base.js +32 -0
- package/src/database/record/relationships/belongs-to.js +12 -0
- package/src/database/record/relationships/has-many.js +12 -0
- package/src/database/table-data/{index.mjs → index.js} +15 -25
- package/src/http-server/client/{index.mjs → index.js} +3 -3
- package/src/http-server/client/request-buffer/{index.mjs → index.js} +4 -4
- package/src/http-server/client/{request-parser.mjs → request-parser.js} +2 -2
- package/src/http-server/client/{request-runner.mjs → request-runner.js} +3 -3
- package/src/http-server/client/{request.mjs → request.js} +1 -1
- package/src/http-server/{index.mjs → index.js} +3 -3
- package/src/http-server/{server-client.mjs → server-client.js} +1 -1
- package/src/http-server/worker-handler/{index.mjs → index.js} +2 -2
- package/src/http-server/worker-handler/{worker-script.mjs → worker-script.js} +1 -1
- package/src/http-server/worker-handler/{worker-thread.mjs → worker-thread.js} +12 -9
- package/src/routes/{app-routes.mjs → app-routes.js} +1 -1
- package/src/routes/{base-route.mjs → base-route.js} +2 -2
- package/src/routes/{get-route.mjs → get-route.js} +1 -1
- package/src/routes/{index.mjs → index.js} +1 -1
- package/src/routes/{resolver.mjs → resolver.js} +1 -1
- package/src/routes/{resource-route.mjs → resource-route.js} +1 -1
- package/src/routes/{root-route.mjs → root-route.js} +1 -1
- package/src/templates/{configuration.mjs → configuration.js} +3 -3
- package/src/templates/{generate-migration.mjs → generate-migration.js} +1 -1
- package/src/templates/generate-model.js +6 -0
- package/src/templates/{routes.mjs → routes.js} +1 -1
- package/src/utils/rest-args-error.js +9 -0
- package/spec/database/record/create-spec.mjs +0 -14
- package/spec/dummy/src/config/configuration.example.mjs +0 -21
- package/spec/dummy/src/config/configuration.peakflow.mjs +0 -22
- package/spec/dummy/src/models/task.mjs +0 -4
- package/src/database/drivers/mysql/query-parser.mjs +0 -25
- package/src/database/drivers/sqlite/base.mjs +0 -36
- package/src/database/drivers/sqlite/index.web.mjs +0 -45
- package/src/database/drivers/sqlite/query-parser.mjs +0 -25
- package/src/database/drivers/sqlite/query.native.mjs +0 -9
- package/src/database/drivers/sqlite/query.web.mjs +0 -9
- package/src/database/drivers/sqlite/table.mjs +0 -9
- package/src/database/migration/index.mjs +0 -18
- package/src/database/query/create-table-base.mjs +0 -69
- package/src/database/query/index.mjs +0 -144
- package/src/database/query-parser/joins-parser.mjs +0 -30
- package/src/database/record/index.mjs +0 -187
- package/src/templates/generate-model.mjs +0 -4
- /package/{index.mjs → index.js} +0 -0
- /package/spec/dummy/{dummy-directory.mjs → dummy-directory.js} +0 -0
- /package/src/cli/{base-command.mjs → base-command.js} +0 -0
- /package/src/cli/commands/test/{test-runner.mjs → test-runner.js} +0 -0
- /package/src/{controller.mjs → controller.js} +0 -0
- /package/src/database/drivers/mysql/{connect-connection.mjs → connect-connection.js} +0 -0
- /package/src/database/drivers/mysql/{query.mjs → query.js} +0 -0
- /package/src/database/{handler.mjs → handler.js} +0 -0
- /package/src/database/query/{from-base.mjs → from-base.js} +0 -0
- /package/src/database/query/{insert-base.mjs → insert-base.js} +0 -0
- /package/src/database/query/{join-base.mjs → join-base.js} +0 -0
- /package/src/database/query/{order-base.mjs → order-base.js} +0 -0
- /package/src/database/query/{select-base.mjs → select-base.js} +0 -0
- /package/src/database/query/{update-base.mjs → update-base.js} +0 -0
- /package/src/database/query-parser/{from-parser.mjs → from-parser.js} +0 -0
- /package/src/database/record/{record-not-found-error.mjs → record-not-found-error.js} +0 -0
- /package/src/{error-logger.mjs → error-logger.js} +0 -0
- /package/src/http-server/client/{params-to-object.mjs → params-to-object.js} +0 -0
- /package/src/http-server/client/request-buffer/{form-data-part.mjs → form-data-part.js} +0 -0
- /package/src/http-server/client/request-buffer/{header.mjs → header.js} +0 -0
- /package/src/http-server/client/{response.mjs → response.js} +0 -0
- /package/src/{logger.mjs → logger.js} +0 -0
- /package/src/spec/{index.mjs → index.js} +0 -0
- /package/src/utils/{file-exists.mjs → file-exists.js} +0 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import BaseInstanceRelationship from "./base.js"
|
|
2
|
+
|
|
3
|
+
export default class VelociousDatabaseRecordBelongsToInstanceRelationship extends BaseInstanceRelationship {
|
|
4
|
+
constructor(args) {
|
|
5
|
+
super(args)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
build(data) {
|
|
9
|
+
const targetModelClass = this.getTargetModelClass()
|
|
10
|
+
const newInstance = new targetModelClass(data)
|
|
11
|
+
|
|
12
|
+
this._loaded = newInstance
|
|
13
|
+
|
|
14
|
+
return newInstance
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
setLoaded(models) {
|
|
18
|
+
this._loaded = models
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import BaseInstanceRelationship from "./base.js"
|
|
2
|
+
|
|
3
|
+
export default class VelociousDatabaseRecordHasManyInstanceRelationship extends BaseInstanceRelationship {
|
|
4
|
+
constructor(args) {
|
|
5
|
+
super(args)
|
|
6
|
+
this._loaded = []
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
build(data) {
|
|
10
|
+
const targetModelClass = this.getTargetModelClass()
|
|
11
|
+
const newInstance = new targetModelClass(data)
|
|
12
|
+
|
|
13
|
+
this._loaded.push(newInstance)
|
|
14
|
+
|
|
15
|
+
return newInstance
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
loaded() {
|
|
19
|
+
if (!this._preloaded && this.model.isPersisted()) {
|
|
20
|
+
throw new Error(`${this.model.constructor.name}#${this.relationship.getRelationshipName()} hasn't been preloaded`)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return this._loaded
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
addToLoaded(models) {
|
|
27
|
+
if (Array.isArray(models)) {
|
|
28
|
+
for (const model of models) {
|
|
29
|
+
this._loaded.push(model)
|
|
30
|
+
}
|
|
31
|
+
} else {
|
|
32
|
+
this._loaded.push(models)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
setLoaded(models) {
|
|
37
|
+
if (!Array.isArray(models)) throw new Error(`Argument given to setLoaded wasn't an array: ${typeof models}`)
|
|
38
|
+
|
|
39
|
+
this._loaded = models
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
setPreloaded(preloadedValue) {
|
|
43
|
+
this._preloaded = preloadedValue
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
getTargetModelClass = () => this.relationship.getTargetModelClass()
|
|
47
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export default class VelociousDatabaseRecordBaseRelationship {
|
|
2
|
+
constructor({className, configuration, foreignKey, klass, modelClass, relationshipName, through, type, ...restArgs}) {
|
|
3
|
+
const restArgsKeys = Object.keys(restArgs)
|
|
4
|
+
|
|
5
|
+
if (restArgsKeys.length > 0) throw new Error(`Unknown args given: ${restArgsKeys.join(", ")}`)
|
|
6
|
+
if (!modelClass) throw new Error(`'modelClass' wasn't given for ${relationshipName}`)
|
|
7
|
+
if (!className && !klass) throw new Error(`Neither 'className' or 'klass' was given for ${modelClass.name}#${relationshipName}`)
|
|
8
|
+
|
|
9
|
+
this.className = className
|
|
10
|
+
this.configuration = configuration
|
|
11
|
+
this.foreignKey = foreignKey
|
|
12
|
+
this.klass = klass
|
|
13
|
+
this.modelClass = modelClass
|
|
14
|
+
this.relationshipName = relationshipName
|
|
15
|
+
this.through = through
|
|
16
|
+
this.type = type
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
getRelationshipName = () => this.relationshipName
|
|
20
|
+
getPrimaryKey = () => "id" // TODO: Support custom given primary key
|
|
21
|
+
getType = () => this.type
|
|
22
|
+
|
|
23
|
+
getTargetModelClass() {
|
|
24
|
+
if (this.className) {
|
|
25
|
+
return this.modelClass._getConfiguration().getModelClass(this.className)
|
|
26
|
+
} else if (this.klass) {
|
|
27
|
+
return this.klass
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
throw new Error("Couldn't figure out the target model class")
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import BaseRelationship from "./base.js"
|
|
2
|
+
import * as inflection from "inflection"
|
|
3
|
+
|
|
4
|
+
export default class VelociousDatabaseRecordBelongsToRelationship extends BaseRelationship {
|
|
5
|
+
getForeignKey() {
|
|
6
|
+
if (!this.foreignKey) {
|
|
7
|
+
this.foreignKey = `${inflection.underscore(this.getTargetModelClass().name)}_id`
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return this.foreignKey
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import BaseRelationship from "./base.js"
|
|
2
|
+
import * as inflection from "inflection"
|
|
3
|
+
|
|
4
|
+
export default class VelociousDatabaseRecordHasManyRelationship extends BaseRelationship {
|
|
5
|
+
getForeignKey() {
|
|
6
|
+
if (!this.foreignKey) {
|
|
7
|
+
this.foreignKey = `${inflection.underscore(this.modelClass.name)}_id`
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return this.foreignKey
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -33,18 +33,22 @@ export default class TableData {
|
|
|
33
33
|
this._name = name
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
_defineColumn(name, args = {}) {
|
|
37
|
+
const column = new TableColumn(name, args)
|
|
38
|
+
|
|
39
|
+
this._columns.push(column)
|
|
40
|
+
}
|
|
41
|
+
|
|
36
42
|
getColumns = () => this._columns
|
|
37
43
|
getName = () => this._name
|
|
38
44
|
getIfNotExists = () => this.args.ifNotExists
|
|
39
45
|
getIndexes = () => this._indexes
|
|
40
46
|
getReferences = () => this._references
|
|
41
47
|
|
|
42
|
-
bigint(name, args = {}) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
this._columns.push(column)
|
|
47
|
-
}
|
|
48
|
+
bigint = (name, args = {}) => this._defineColumn(name, Object.assign({type: "bigint"}, args))
|
|
49
|
+
boolean = (name, args) => this._defineColumn(name, Object.assign({type: "boolean"}, args))
|
|
50
|
+
datetime = (name, args) => this._defineColumn(name, Object.assign({type: "datetime"}, args))
|
|
51
|
+
integer = (name, args = {}) => this._defineColumn(name, Object.assign({type: "integer"}, args))
|
|
48
52
|
|
|
49
53
|
references(name, args = {}) {
|
|
50
54
|
const columnName = `${name}_id`
|
|
@@ -59,25 +63,11 @@ export default class TableData {
|
|
|
59
63
|
this._references.push(reference)
|
|
60
64
|
}
|
|
61
65
|
|
|
62
|
-
string(name, args) {
|
|
63
|
-
|
|
64
|
-
const column = new TableColumn(name, columnArgs)
|
|
65
|
-
|
|
66
|
-
this._columns.push(column)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
text(name, args) {
|
|
70
|
-
const columnArgs = Object.assign({type: "text"}, args)
|
|
71
|
-
const column = new TableColumn(name, columnArgs)
|
|
72
|
-
|
|
73
|
-
this._columns.push(column)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
timestamps() {
|
|
77
|
-
const createdAtColumn = new TableColumn("created_at", {type: "datetime"})
|
|
78
|
-
const updatedAtColumn = new TableColumn("updated_at", {type: "datetime"})
|
|
66
|
+
string = (name, args) => this._defineColumn(name, Object.assign({type: "string"}, args))
|
|
67
|
+
text = (name, args) => this._defineColumn(name, Object.assign({type: "text"}, args))
|
|
79
68
|
|
|
80
|
-
|
|
81
|
-
this.
|
|
69
|
+
timestamps(args = {}) {
|
|
70
|
+
this.datetime("created_at", args)
|
|
71
|
+
this.datetime("updated_at", args)
|
|
82
72
|
}
|
|
83
73
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {digg} from "diggerize"
|
|
2
2
|
import {EventEmitter} from "events"
|
|
3
|
-
import logger from "../../logger.
|
|
4
|
-
import Request from "./request.
|
|
5
|
-
import RequestRunner from "./request-runner.
|
|
3
|
+
import logger from "../../logger.js"
|
|
4
|
+
import Request from "./request.js"
|
|
5
|
+
import RequestRunner from "./request-runner.js"
|
|
6
6
|
|
|
7
7
|
export default class VeoliciousHttpServerClient {
|
|
8
8
|
events = new EventEmitter()
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {EventEmitter} from "events"
|
|
2
|
-
import FormDataPart from "./form-data-part.
|
|
3
|
-
import Header from "./header.
|
|
2
|
+
import FormDataPart from "./form-data-part.js"
|
|
3
|
+
import Header from "./header.js"
|
|
4
4
|
import Incorporator from "incorporator"
|
|
5
|
-
import logger from "../../../logger.
|
|
6
|
-
import ParamsToObject from "../params-to-object.
|
|
5
|
+
import logger from "../../../logger.js"
|
|
6
|
+
import ParamsToObject from "../params-to-object.js"
|
|
7
7
|
import querystring from "querystring"
|
|
8
8
|
|
|
9
9
|
export default class RequestBuffer {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {digg} from "diggerize"
|
|
2
2
|
import {EventEmitter} from "events"
|
|
3
3
|
import Incorporator from "incorporator"
|
|
4
|
-
import ParamsToObject from "./params-to-object.
|
|
5
|
-
import RequestBuffer from "./request-buffer/index.
|
|
4
|
+
import ParamsToObject from "./params-to-object.js"
|
|
5
|
+
import RequestBuffer from "./request-buffer/index.js"
|
|
6
6
|
|
|
7
7
|
export default class VelociousHttpServerClientRequestParser {
|
|
8
8
|
constructor({configuration}) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import EventEmitter from "events"
|
|
2
|
-
import logger from "../../logger.
|
|
3
|
-
import Response from "./response.
|
|
4
|
-
import RoutesResolver from "../../routes/resolver.
|
|
2
|
+
import logger from "../../logger.js"
|
|
3
|
+
import Response from "./response.js"
|
|
4
|
+
import RoutesResolver from "../../routes/resolver.js"
|
|
5
5
|
|
|
6
6
|
export default class VelociousHttpServerClientRequestRunner {
|
|
7
7
|
events = new EventEmitter()
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {digg} from "diggerize"
|
|
2
|
-
import logger from "../logger.
|
|
2
|
+
import logger from "../logger.js"
|
|
3
3
|
import Net from "net"
|
|
4
|
-
import ServerClient from "./server-client.
|
|
5
|
-
import WorkerHandler from "./worker-handler/index.
|
|
4
|
+
import ServerClient from "./server-client.js"
|
|
5
|
+
import WorkerHandler from "./worker-handler/index.js"
|
|
6
6
|
|
|
7
7
|
export default class VelociousHttpServer {
|
|
8
8
|
clientCount = 0
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {digg, digs} from "diggerize"
|
|
2
2
|
import {dirname} from "path"
|
|
3
3
|
import {fileURLToPath} from "url"
|
|
4
|
-
import logger from "../../logger.
|
|
4
|
+
import logger from "../../logger.js"
|
|
5
5
|
import {Worker} from "worker_threads"
|
|
6
6
|
|
|
7
7
|
export default class VelociousHttpServerWorker {
|
|
@@ -19,7 +19,7 @@ export default class VelociousHttpServerWorker {
|
|
|
19
19
|
const __dirname = dirname(__filename)
|
|
20
20
|
|
|
21
21
|
this.onStartCallback = resolve
|
|
22
|
-
this.worker = new Worker(`${__dirname}/worker-script.
|
|
22
|
+
this.worker = new Worker(`${__dirname}/worker-script.js`, {
|
|
23
23
|
workerData: {
|
|
24
24
|
debug,
|
|
25
25
|
directory,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import Application from "../../application.
|
|
2
|
-
import Client from "../client/index.
|
|
1
|
+
import Application from "../../application.js"
|
|
2
|
+
import Client from "../client/index.js"
|
|
3
3
|
import {digg, digs} from "diggerize"
|
|
4
|
-
import errorLogger from "../../error-logger.
|
|
5
|
-
import logger from "../../logger.
|
|
4
|
+
import errorLogger from "../../error-logger.js"
|
|
5
|
+
import logger from "../../logger.js"
|
|
6
6
|
|
|
7
7
|
export default class VelociousHttpServerWorkerHandlerWorkerThread {
|
|
8
8
|
constructor({parentPort, workerData}) {
|
|
@@ -25,14 +25,17 @@ export default class VelociousHttpServerWorkerHandlerWorkerThread {
|
|
|
25
25
|
|
|
26
26
|
async initialize() {
|
|
27
27
|
const {debug, directory} = digs(this.workerData, "debug", "directory")
|
|
28
|
-
const configurationPath = `${this.workerData.directory}/src/config/configuration.
|
|
28
|
+
const configurationPath = `${this.workerData.directory}/src/config/configuration.js`
|
|
29
29
|
const configurationImport = await import(configurationPath)
|
|
30
|
-
const configuration = configurationImport.default
|
|
31
30
|
|
|
32
|
-
this.
|
|
33
|
-
|
|
34
|
-
this.configuration = configuration
|
|
31
|
+
this.configuration = configurationImport.default
|
|
35
32
|
this.configuration.setCurrent()
|
|
33
|
+
|
|
34
|
+
this.application = new Application({configuration: this.configuration, debug, directory})
|
|
35
|
+
|
|
36
|
+
if (this.configuration.isInitialized()) {
|
|
37
|
+
await this.configuration.initialize()
|
|
38
|
+
}
|
|
36
39
|
}
|
|
37
40
|
|
|
38
41
|
onCommand = (data) => {
|
|
@@ -3,7 +3,7 @@ import {digg} from "diggerize"
|
|
|
3
3
|
export default class VelociousRoutesAppRoutes {
|
|
4
4
|
static async getRoutes(configuration) {
|
|
5
5
|
// Every client need to make their own routes because they probably can't be shared across different worker threads
|
|
6
|
-
const routesImport = await import(`${configuration.getDirectory()}/src/config/routes.
|
|
6
|
+
const routesImport = await import(`${configuration.getDirectory()}/src/config/routes.js`)
|
|
7
7
|
|
|
8
8
|
return digg(routesImport, "default", "routes")
|
|
9
9
|
}
|
|
@@ -21,7 +21,7 @@ export default class VelociousRoutesResolver {
|
|
|
21
21
|
if (!matchResult) throw new Error(`Couldn't match a route with the given path: ${currentPath}`)
|
|
22
22
|
|
|
23
23
|
if (this.params.action && this.params.controller) {
|
|
24
|
-
const controllerPath = `${this.configuration.getDirectory()}/src/routes/${digg(this, "params", "controller")}/controller.
|
|
24
|
+
const controllerPath = `${this.configuration.getDirectory()}/src/routes/${digg(this, "params", "controller")}/controller.js`
|
|
25
25
|
const controllerClassImport = await import(controllerPath)
|
|
26
26
|
const controllerClass = controllerClassImport.default
|
|
27
27
|
const controllerInstance = new controllerClass({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import AsyncTrackedMultiConnection from "velocious/src/database/pool/async-tracked-multi-connection.
|
|
2
|
-
import Configuration from "velocious/src/configuration.
|
|
3
|
-
import MysqlDriver from "velocious/src/database/drivers/mysql/index.
|
|
1
|
+
import AsyncTrackedMultiConnection from "velocious/src/database/pool/async-tracked-multi-connection.js"
|
|
2
|
+
import Configuration from "velocious/src/configuration.js"
|
|
3
|
+
import MysqlDriver from "velocious/src/database/drivers/mysql/index.js"
|
|
4
4
|
|
|
5
5
|
export default new Configuration({
|
|
6
6
|
database: {
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import Dummy from "../../dummy/index.mjs"
|
|
2
|
-
import Task from "../../dummy/src/models/task.mjs"
|
|
3
|
-
|
|
4
|
-
describe("Record - create", () => {
|
|
5
|
-
it("creates a new simple record", async () => {
|
|
6
|
-
await Dummy.run(async () => {
|
|
7
|
-
const task = new Task({name: "Test task"})
|
|
8
|
-
|
|
9
|
-
await task.save()
|
|
10
|
-
|
|
11
|
-
expect(task.id()).not.toBeUndefined()
|
|
12
|
-
})
|
|
13
|
-
})
|
|
14
|
-
})
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import AsyncTrackedMultiConnection from "../../../../src/database/pool/async-tracked-multi-connection.mjs"
|
|
2
|
-
import Configuration from "../../../../src/configuration.mjs"
|
|
3
|
-
import dummyDirectory from "../../dummy-directory.mjs"
|
|
4
|
-
import MysqlDriver from "../../../../src/database/drivers/mysql/index.mjs"
|
|
5
|
-
|
|
6
|
-
export default new Configuration({
|
|
7
|
-
database: {
|
|
8
|
-
default: {
|
|
9
|
-
master: {
|
|
10
|
-
driver: MysqlDriver,
|
|
11
|
-
poolType: AsyncTrackedMultiConnection,
|
|
12
|
-
type: "mysql",
|
|
13
|
-
host: "mariadb",
|
|
14
|
-
username: "username",
|
|
15
|
-
password: "password",
|
|
16
|
-
database: "velocious_test"
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
directory: dummyDirectory()
|
|
21
|
-
})
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import AsyncTrackedMultiConnection from "../../../../src/database/pool/async-tracked-multi-connection.mjs"
|
|
2
|
-
import Configuration from "../../../../src/configuration.mjs"
|
|
3
|
-
import dummyDirectory from "../../dummy-directory.mjs"
|
|
4
|
-
import MysqlDriver from "../../../../src/database/drivers/mysql/index.mjs"
|
|
5
|
-
|
|
6
|
-
export default new Configuration({
|
|
7
|
-
database: {
|
|
8
|
-
default: {
|
|
9
|
-
master: {
|
|
10
|
-
driver: MysqlDriver,
|
|
11
|
-
poolType: AsyncTrackedMultiConnection,
|
|
12
|
-
type: "mysql",
|
|
13
|
-
host: "mariadb",
|
|
14
|
-
username: "peakflow",
|
|
15
|
-
password: "password",
|
|
16
|
-
database: "velocious_test",
|
|
17
|
-
useDatabase: "velocious_test"
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
directory: dummyDirectory()
|
|
22
|
-
})
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import {digs} from "diggerize"
|
|
2
|
-
import FromParser from "../../query-parser/from-parser.mjs"
|
|
3
|
-
import JoinsParser from "../../query-parser/joins-parser.mjs"
|
|
4
|
-
import SelectParser from "../../query-parser/select-parser.mjs"
|
|
5
|
-
|
|
6
|
-
export default class VelociousDatabaseConnectionDriversMysqlQueryParser {
|
|
7
|
-
constructor({pretty, query}) {
|
|
8
|
-
if (!query) throw new Error("No query given")
|
|
9
|
-
|
|
10
|
-
this.pretty = pretty
|
|
11
|
-
this.query = query
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
toSql() {
|
|
15
|
-
const {pretty, query} = digs(this, "pretty", "query")
|
|
16
|
-
|
|
17
|
-
let sql = ""
|
|
18
|
-
|
|
19
|
-
sql += new SelectParser({pretty, query}).toSql()
|
|
20
|
-
sql += new FromParser({pretty, query}).toSql()
|
|
21
|
-
sql += new JoinsParser({pretty, query}).toSql()
|
|
22
|
-
|
|
23
|
-
return sql
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import Base from "../base.mjs"
|
|
2
|
-
import CreateTable from "../sqlite/sql/create-table.mjs"
|
|
3
|
-
import Delete from "../sqlite/sql/delete.mjs"
|
|
4
|
-
import Insert from "../sqlite/sql/insert.mjs"
|
|
5
|
-
import QueryParser from "../sqlite/query-parser.mjs"
|
|
6
|
-
import Table from "./table"
|
|
7
|
-
import Update from "../sqlite/sql/update.mjs"
|
|
8
|
-
|
|
9
|
-
export default class VelociousDatabaseDriversSqliteBase extends Base {
|
|
10
|
-
createTableSql(tableData) {
|
|
11
|
-
const createArgs = Object.assign({tableData, driver: this})
|
|
12
|
-
const createTable = new CreateTable(createArgs)
|
|
13
|
-
|
|
14
|
-
return createTable.toSql()
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
deleteSql = ({tableName, conditions}) => new Delete({conditions, driver: this, tableName}).toSql()
|
|
18
|
-
insertSql = ({tableName, data}) => new Insert({driver: this, tableName, data}).toSql()
|
|
19
|
-
|
|
20
|
-
async getTables() {
|
|
21
|
-
const result = await this.query("SELECT name FROM sqlite_master WHERE type = 'table'")
|
|
22
|
-
const tables = []
|
|
23
|
-
|
|
24
|
-
for (const row of result) {
|
|
25
|
-
const table = new Table(row)
|
|
26
|
-
|
|
27
|
-
tables.push(table)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return tables
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
queryToSql = (query) => new QueryParser({query}).toSql()
|
|
34
|
-
quoteColumn = (string) => `\`${string}\``
|
|
35
|
-
updateSql = ({conditions, data, tableName}) => new Update({conditions, data, driver: this, tableName}).toSql()
|
|
36
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import Base from "./base.mjs"
|
|
2
|
-
import {digg} from "diggerize"
|
|
3
|
-
import Options from "../sqlite/options.mjs"
|
|
4
|
-
import query from "./query"
|
|
5
|
-
|
|
6
|
-
import initSqlJs from "sql.js"
|
|
7
|
-
|
|
8
|
-
export default class VelociousDatabaseDriversSqliteWeb extends Base {
|
|
9
|
-
async connect() {
|
|
10
|
-
const SQL = await initSqlJs({
|
|
11
|
-
// Required to load the wasm binary asynchronously. Of course, you can host it wherever you want you can omit locateFile completely when running in Node.
|
|
12
|
-
locateFile: (file) => `https://sql.js.org/dist/${file}`
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
const databaseContent = localStorage.getItem(this.localStorageName())
|
|
16
|
-
|
|
17
|
-
this.connection = new SQL.Database(databaseContent)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
localStorageName = () => `VelociousDatabaseDriversSqliteWeb---${digg(this.getArgs(), "name")}`
|
|
21
|
-
disconnect = () => this.saveDatabase()
|
|
22
|
-
saveDatabase = () => localStorage.setItem(this.localStorageName(), this.connection.export())
|
|
23
|
-
|
|
24
|
-
async close() {
|
|
25
|
-
this.saveDatabase()
|
|
26
|
-
await this.connection.end()
|
|
27
|
-
this.connection = undefined
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
query = async (sql) => await query(this.connection, sql)
|
|
31
|
-
|
|
32
|
-
quote(string) {
|
|
33
|
-
if (!this.connection) throw new Error("Can't escape before connected")
|
|
34
|
-
|
|
35
|
-
return this.connection.escape(string)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
options() {
|
|
39
|
-
if (!this._options) {
|
|
40
|
-
this._options = new Options({driver: this})
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return this._options
|
|
44
|
-
}
|
|
45
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import {digs} from "diggerize"
|
|
2
|
-
import FromParser from "../../query-parser/from-parser.mjs"
|
|
3
|
-
import JoinsParser from "../../query-parser/joins-parser.mjs"
|
|
4
|
-
import SelectParser from "../../query-parser/select-parser.mjs"
|
|
5
|
-
|
|
6
|
-
export default class VelociousDatabaseConnectionDriversMysqlQueryParser {
|
|
7
|
-
constructor({pretty, query}) {
|
|
8
|
-
if (!query) throw new Error("No query given")
|
|
9
|
-
|
|
10
|
-
this.pretty = pretty
|
|
11
|
-
this.query = query
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
toSql() {
|
|
15
|
-
const {pretty, query} = digs(this, "pretty", "query")
|
|
16
|
-
|
|
17
|
-
let sql = ""
|
|
18
|
-
|
|
19
|
-
sql += new SelectParser({pretty, query}).toSql()
|
|
20
|
-
sql += new FromParser({pretty, query}).toSql()
|
|
21
|
-
sql += new JoinsParser({pretty, query}).toSql()
|
|
22
|
-
|
|
23
|
-
return sql
|
|
24
|
-
}
|
|
25
|
-
}
|