velocious 1.0.727 → 1.0.729

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.
Files changed (112) hide show
  1. package/README.md +2 -2
  2. package/bin/velocious.js +2 -19
  3. package/build/application.js +32 -3
  4. package/build/background-jobs/main.js +9 -1
  5. package/build/background-jobs/worker.js +69 -6
  6. package/build/bin/velocious.js +2 -19
  7. package/build/cli/process-args.js +34 -0
  8. package/build/configuration.js +26 -0
  9. package/build/database/database-name.js +25 -0
  10. package/build/database/drivers/base.js +60 -12
  11. package/build/database/drivers/mssql/index.js +27 -18
  12. package/build/database/drivers/mssql/table.js +28 -25
  13. package/build/database/drivers/mysql/index.js +25 -18
  14. package/build/database/drivers/mysql/table.js +31 -23
  15. package/build/database/drivers/pgsql/index.js +25 -18
  16. package/build/database/drivers/pgsql/table.js +28 -26
  17. package/build/database/drivers/sqlite/base.js +20 -9
  18. package/build/database/drivers/sqlite/table.js +32 -26
  19. package/build/database/pool/async-tracked-multi-connection.js +1 -0
  20. package/build/database/pool/base.js +14 -4
  21. package/build/database/pool/single-multi-use.js +1 -0
  22. package/build/database/query/model-class-query.js +85 -0
  23. package/build/database/record/index.js +33 -0
  24. package/build/environment-handlers/node/cli/commands/server.js +1 -0
  25. package/build/http-server/server-lock.js +28 -4
  26. package/build/src/application.d.ts +7 -4
  27. package/build/src/application.d.ts.map +1 -1
  28. package/build/src/application.js +27 -4
  29. package/build/src/background-jobs/main.d.ts +2 -1
  30. package/build/src/background-jobs/main.d.ts.map +1 -1
  31. package/build/src/background-jobs/main.js +10 -2
  32. package/build/src/background-jobs/worker.d.ts +42 -0
  33. package/build/src/background-jobs/worker.d.ts.map +1 -1
  34. package/build/src/background-jobs/worker.js +61 -5
  35. package/build/src/cli/process-args.d.ts +11 -0
  36. package/build/src/cli/process-args.d.ts.map +1 -0
  37. package/build/src/cli/process-args.js +34 -0
  38. package/build/src/configuration.d.ts +13 -0
  39. package/build/src/configuration.d.ts.map +1 -1
  40. package/build/src/configuration.js +22 -1
  41. package/build/src/database/database-name.d.ts +9 -0
  42. package/build/src/database/database-name.d.ts.map +1 -0
  43. package/build/src/database/database-name.js +23 -0
  44. package/build/src/database/drivers/base.d.ts +31 -2
  45. package/build/src/database/drivers/base.d.ts.map +1 -1
  46. package/build/src/database/drivers/base.js +56 -13
  47. package/build/src/database/drivers/mssql/index.d.ts +7 -2
  48. package/build/src/database/drivers/mssql/index.d.ts.map +1 -1
  49. package/build/src/database/drivers/mssql/index.js +25 -18
  50. package/build/src/database/drivers/mssql/table.d.ts.map +1 -1
  51. package/build/src/database/drivers/mssql/table.js +25 -23
  52. package/build/src/database/drivers/mysql/index.d.ts +7 -2
  53. package/build/src/database/drivers/mysql/index.d.ts.map +1 -1
  54. package/build/src/database/drivers/mysql/index.js +24 -19
  55. package/build/src/database/drivers/mysql/table.d.ts.map +1 -1
  56. package/build/src/database/drivers/mysql/table.js +27 -22
  57. package/build/src/database/drivers/pgsql/index.d.ts +7 -2
  58. package/build/src/database/drivers/pgsql/index.d.ts.map +1 -1
  59. package/build/src/database/drivers/pgsql/index.js +24 -19
  60. package/build/src/database/drivers/pgsql/table.d.ts.map +1 -1
  61. package/build/src/database/drivers/pgsql/table.js +25 -23
  62. package/build/src/database/drivers/sqlite/base.d.ts +8 -0
  63. package/build/src/database/drivers/sqlite/base.d.ts.map +1 -1
  64. package/build/src/database/drivers/sqlite/base.js +19 -10
  65. package/build/src/database/drivers/sqlite/table.d.ts.map +1 -1
  66. package/build/src/database/drivers/sqlite/table.js +29 -25
  67. package/build/src/database/pool/async-tracked-multi-connection.d.ts.map +1 -1
  68. package/build/src/database/pool/async-tracked-multi-connection.js +2 -1
  69. package/build/src/database/pool/base.d.ts +6 -0
  70. package/build/src/database/pool/base.d.ts.map +1 -1
  71. package/build/src/database/pool/base.js +14 -5
  72. package/build/src/database/pool/single-multi-use.d.ts.map +1 -1
  73. package/build/src/database/pool/single-multi-use.js +2 -1
  74. package/build/src/database/query/model-class-query.d.ts +20 -0
  75. package/build/src/database/query/model-class-query.d.ts.map +1 -1
  76. package/build/src/database/query/model-class-query.js +75 -1
  77. package/build/src/database/record/index.d.ts +46 -0
  78. package/build/src/database/record/index.d.ts.map +1 -1
  79. package/build/src/database/record/index.js +30 -1
  80. package/build/src/environment-handlers/node/cli/commands/server.d.ts.map +1 -1
  81. package/build/src/environment-handlers/node/cli/commands/server.js +2 -1
  82. package/build/src/http-server/server-lock.d.ts +23 -5
  83. package/build/src/http-server/server-lock.d.ts.map +1 -1
  84. package/build/src/http-server/server-lock.js +27 -5
  85. package/build/src/tenants/default-tenant-database-provisioning.d.ts +14 -0
  86. package/build/src/tenants/default-tenant-database-provisioning.d.ts.map +1 -1
  87. package/build/src/tenants/default-tenant-database-provisioning.js +31 -17
  88. package/build/tenants/default-tenant-database-provisioning.js +33 -19
  89. package/package.json +2 -2
  90. package/src/application.js +32 -3
  91. package/src/background-jobs/main.js +9 -1
  92. package/src/background-jobs/worker.js +69 -6
  93. package/src/cli/process-args.js +34 -0
  94. package/src/configuration.js +26 -0
  95. package/src/database/database-name.js +25 -0
  96. package/src/database/drivers/base.js +60 -12
  97. package/src/database/drivers/mssql/index.js +27 -18
  98. package/src/database/drivers/mssql/table.js +28 -25
  99. package/src/database/drivers/mysql/index.js +25 -18
  100. package/src/database/drivers/mysql/table.js +31 -23
  101. package/src/database/drivers/pgsql/index.js +25 -18
  102. package/src/database/drivers/pgsql/table.js +28 -26
  103. package/src/database/drivers/sqlite/base.js +20 -9
  104. package/src/database/drivers/sqlite/table.js +32 -26
  105. package/src/database/pool/async-tracked-multi-connection.js +1 -0
  106. package/src/database/pool/base.js +14 -4
  107. package/src/database/pool/single-multi-use.js +1 -0
  108. package/src/database/query/model-class-query.js +85 -0
  109. package/src/database/record/index.js +33 -0
  110. package/src/environment-handlers/node/cli/commands/server.js +1 -0
  111. package/src/http-server/server-lock.js +28 -4
  112. package/src/tenants/default-tenant-database-provisioning.js +33 -19
@@ -17,6 +17,11 @@ import path from "node:path"
17
17
  * server and a test-spawned backend in the same app directory coexist, while
18
18
  * the single-server-per-(directory, environment) invariant still fails loudly
19
19
  * for a duplicate within one environment (STC-697).
20
+ *
21
+ * A caller that knowingly wants a second server in the same
22
+ * (directory, environment) pair can opt out of this lock (STC-698). The lock
23
+ * itself is unchanged for every other caller: an opted-out lock never acquires
24
+ * and therefore never releases, so it can never remove a live owner's lock.
20
25
  */
21
26
  export default class VelociousHttpServerLock {
22
27
  /**
@@ -26,11 +31,13 @@ export default class VelociousHttpServerLock {
26
31
  * @param {import("../configuration.js").default} args.configuration - Configuration that owns the application directory.
27
32
  * @param {string} args.host - Configured HTTP host.
28
33
  * @param {number} args.port - Configured HTTP port.
34
+ * @param {boolean} [args.optOut] - Skip acquisition for this caller instead of contending for the lock.
29
35
  */
30
- constructor({configuration, host, port}) {
36
+ constructor({configuration, host, port, optOut = false}) {
31
37
  this.configuration = configuration
32
38
  this.host = host
33
39
  this.port = port
40
+ this.optOut = optOut
34
41
  this.environment = String(configuration.getEnvironment())
35
42
  // Scope the lock name by environment and keep the segment filesystem-safe,
36
43
  // so odd environment names can never escape tmp/ or collide with each other.
@@ -46,21 +53,28 @@ export default class VelociousHttpServerLock {
46
53
 
47
54
  /**
48
55
  * Acquires the app-directory + environment HTTP server lock before startup
49
- * side effects run. A stale lock (dead local owner or expired lease) is
56
+ * side effects run. An opted-out caller never touches the lock, so the live
57
+ * owner keeps it. A stale lock (dead local owner or expired lease) is
50
58
  * reclaimed by the backend; a live foreign owner in the same environment
51
59
  * fails loudly with the owner details.
52
- * @returns {Promise<void>} - Resolves after the lock has been acquired.
60
+ * @returns {Promise<boolean>} - Whether this caller holds the lock.
53
61
  */
54
62
  async acquire() {
63
+ if (this.optOut) return false
64
+
55
65
  const acquired = await this.backend.acquire(this.lockName, {timeoutMs: 0})
56
66
 
57
67
  if (!acquired) throw new Error(await this.lockHeldMessage())
58
68
 
59
69
  this.acquired = true
70
+
71
+ return true
60
72
  }
61
73
 
62
74
  /**
63
- * Releases the held environment-scoped HTTP server lock directory.
75
+ * Releases the held environment-scoped HTTP server lock directory. A lock
76
+ * that was never acquired (an opted-out caller) is a no-op, so it can never
77
+ * remove the live owner's lock on shutdown.
64
78
  * @returns {Promise<void>} - Resolves after best-effort lock release.
65
79
  */
66
80
  async release() {
@@ -90,4 +104,14 @@ export default class VelociousHttpServerLock {
90
104
 
91
105
  return `A Velocious HTTP server is already running for this application in the ${this.environment} environment (${details}). Remove ${this.lockPath} if the server is no longer running.`
92
106
  }
107
+
108
+ /**
109
+ * Builds the warning emitted when a caller knowingly starts a server without
110
+ * the lock, so an unprotected production process is visible in the log rather
111
+ * than silently running without duplicate-server protection.
112
+ * @returns {string} - Warning message naming the application directory and port.
113
+ */
114
+ lockSkippedMessage() {
115
+ return `Skipping the HTTP server lock for ${this.configuration.getDirectory()} on ${this.host}:${String(this.port)} because the caller opted out. This server runs without duplicate-server protection for the ${this.environment} environment.`
116
+ }
93
117
  }
@@ -14,7 +14,8 @@
14
14
  * driver's own `createDatabaseSql`/`dropDatabaseSql`.
15
15
  */
16
16
 
17
- const SAFE_TENANT_DATABASE_NAME = /^[a-z0-9_]+$/
17
+ import {safeDatabaseName} from "../database/database-name.js"
18
+ import PoolBase from "../database/pool/base.js"
18
19
 
19
20
  /**
20
21
  * Whether the driver stores each database as a local file instead of on a server.
@@ -32,13 +33,7 @@ function fileBackedDriver(databaseConfiguration) {
32
33
  * @returns {string} - The validated tenant database name.
33
34
  */
34
35
  function guardedDatabaseName(databaseConfiguration) {
35
- const databaseName = databaseConfiguration.database
36
-
37
- if (!databaseName || !SAFE_TENANT_DATABASE_NAME.test(databaseName)) {
38
- throw new Error(`Unsafe tenant database name: ${databaseName}`)
39
- }
40
-
41
- return databaseName
36
+ return safeDatabaseName(databaseConfiguration.database, "tenant database provisioning")
42
37
  }
43
38
 
44
39
  /**
@@ -97,23 +92,22 @@ export async function createTenantDatabase({configuration, databaseConfiguration
97
92
  }
98
93
 
99
94
  /**
100
- * Drops the tenant database for one tenant. Uses `DROP DATABASE IF EXISTS`, so it
101
- * is a safe no-op for a tenant that was never fully provisioned.
102
- * @param {{configuration: import("../configuration.js").default, databaseConfiguration: import("../configuration-types.js").DatabaseConfigurationType}} args - Provisioning arguments.
103
- * @returns {Promise<void>} - Resolves once the tenant database is gone.
95
+ * Drops one exact database through the maintenance connection (`useDatabase`) and the
96
+ * driver's own `dropDatabaseSql`. The name is validated against the strict allowlist
97
+ * first, so the helper can only ever drop a single explicitly named database — never a
98
+ * name-pattern sweep. Uses `DROP DATABASE IF EXISTS`, so it is a safe no-op for a
99
+ * database that never existed.
100
+ * @param {{configuration: import("../configuration.js").default, databaseConfiguration: import("../configuration-types.js").DatabaseConfigurationType, databaseName: string | undefined}} args - Database configuration and the exact database name to drop.
101
+ * @returns {Promise<void>} - Resolves once the database is gone.
104
102
  */
105
- export async function dropTenantDatabase({configuration, databaseConfiguration}) {
106
- if (fileBackedDriver(databaseConfiguration)) {
107
- return
108
- }
109
-
110
- const databaseName = guardedDatabaseName(databaseConfiguration)
103
+ export async function dropDatabaseByName({configuration, databaseConfiguration, databaseName}) {
104
+ const guardedName = safeDatabaseName(databaseName, "dropDatabase")
111
105
  const connection = maintenanceConnection(databaseConfiguration, configuration)
112
106
 
113
107
  await connection.connect()
114
108
 
115
109
  try {
116
- const sqls = connection.dropDatabaseSql(databaseName, {ifExists: true})
110
+ const sqls = connection.dropDatabaseSql(guardedName, {ifExists: true})
117
111
 
118
112
  for (const sql of sqls) {
119
113
  await connection.query(sql)
@@ -122,3 +116,23 @@ export async function dropTenantDatabase({configuration, databaseConfiguration})
122
116
  await connection.close()
123
117
  }
124
118
  }
119
+
120
+ /**
121
+ * Drops the tenant database for one tenant. Uses `DROP DATABASE IF EXISTS`, so it
122
+ * is a safe no-op for a tenant that was never fully provisioned.
123
+ * @param {{configuration: import("../configuration.js").default, databaseConfiguration: import("../configuration-types.js").DatabaseConfigurationType}} args - Provisioning arguments.
124
+ * @returns {Promise<void>} - Resolves once the tenant database is gone.
125
+ */
126
+ export async function dropTenantDatabase({configuration, databaseConfiguration}) {
127
+ if (fileBackedDriver(databaseConfiguration)) {
128
+ return
129
+ }
130
+
131
+ await dropDatabaseByName({configuration, databaseConfiguration, databaseName: databaseConfiguration.database})
132
+
133
+ // The DROP DATABASE ran on the maintenance connection, so the dropped tenant's
134
+ // own shared schema-metadata cache was never invalidated by the DDL path. Clear
135
+ // it explicitly: recreating the tenant database later must re-introspect, not
136
+ // serve the dropped schema from the shared cache.
137
+ configuration.clearSchemaCachesForReuseKey(PoolBase.configurationReuseKey(databaseConfiguration))
138
+ }