velocious 1.0.727 → 1.0.728

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 (95) 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/drivers/base.js +34 -12
  10. package/build/database/drivers/mssql/index.js +17 -18
  11. package/build/database/drivers/mssql/table.js +28 -25
  12. package/build/database/drivers/mysql/index.js +15 -18
  13. package/build/database/drivers/mysql/table.js +31 -23
  14. package/build/database/drivers/pgsql/index.js +15 -18
  15. package/build/database/drivers/pgsql/table.js +28 -26
  16. package/build/database/drivers/sqlite/base.js +7 -9
  17. package/build/database/drivers/sqlite/table.js +32 -26
  18. package/build/database/pool/async-tracked-multi-connection.js +1 -0
  19. package/build/database/pool/base.js +14 -4
  20. package/build/database/pool/single-multi-use.js +1 -0
  21. package/build/environment-handlers/node/cli/commands/server.js +1 -0
  22. package/build/http-server/server-lock.js +28 -4
  23. package/build/src/application.d.ts +7 -4
  24. package/build/src/application.d.ts.map +1 -1
  25. package/build/src/application.js +27 -4
  26. package/build/src/background-jobs/main.d.ts +2 -1
  27. package/build/src/background-jobs/main.d.ts.map +1 -1
  28. package/build/src/background-jobs/main.js +10 -2
  29. package/build/src/background-jobs/worker.d.ts +42 -0
  30. package/build/src/background-jobs/worker.d.ts.map +1 -1
  31. package/build/src/background-jobs/worker.js +61 -5
  32. package/build/src/cli/process-args.d.ts +11 -0
  33. package/build/src/cli/process-args.d.ts.map +1 -0
  34. package/build/src/cli/process-args.js +34 -0
  35. package/build/src/configuration.d.ts +13 -0
  36. package/build/src/configuration.d.ts.map +1 -1
  37. package/build/src/configuration.js +22 -1
  38. package/build/src/database/drivers/base.d.ts +15 -2
  39. package/build/src/database/drivers/base.d.ts.map +1 -1
  40. package/build/src/database/drivers/base.js +33 -13
  41. package/build/src/database/drivers/mssql/index.d.ts +2 -2
  42. package/build/src/database/drivers/mssql/index.d.ts.map +1 -1
  43. package/build/src/database/drivers/mssql/index.js +17 -18
  44. package/build/src/database/drivers/mssql/table.d.ts.map +1 -1
  45. package/build/src/database/drivers/mssql/table.js +25 -23
  46. package/build/src/database/drivers/mysql/index.d.ts +2 -2
  47. package/build/src/database/drivers/mysql/index.d.ts.map +1 -1
  48. package/build/src/database/drivers/mysql/index.js +16 -19
  49. package/build/src/database/drivers/mysql/table.d.ts.map +1 -1
  50. package/build/src/database/drivers/mysql/table.js +27 -22
  51. package/build/src/database/drivers/pgsql/index.d.ts +2 -2
  52. package/build/src/database/drivers/pgsql/index.d.ts.map +1 -1
  53. package/build/src/database/drivers/pgsql/index.js +16 -19
  54. package/build/src/database/drivers/pgsql/table.d.ts.map +1 -1
  55. package/build/src/database/drivers/pgsql/table.js +25 -23
  56. package/build/src/database/drivers/sqlite/base.d.ts.map +1 -1
  57. package/build/src/database/drivers/sqlite/base.js +8 -10
  58. package/build/src/database/drivers/sqlite/table.d.ts.map +1 -1
  59. package/build/src/database/drivers/sqlite/table.js +29 -25
  60. package/build/src/database/pool/async-tracked-multi-connection.d.ts.map +1 -1
  61. package/build/src/database/pool/async-tracked-multi-connection.js +2 -1
  62. package/build/src/database/pool/base.d.ts +6 -0
  63. package/build/src/database/pool/base.d.ts.map +1 -1
  64. package/build/src/database/pool/base.js +14 -5
  65. package/build/src/database/pool/single-multi-use.d.ts.map +1 -1
  66. package/build/src/database/pool/single-multi-use.js +2 -1
  67. package/build/src/environment-handlers/node/cli/commands/server.d.ts.map +1 -1
  68. package/build/src/environment-handlers/node/cli/commands/server.js +2 -1
  69. package/build/src/http-server/server-lock.d.ts +23 -5
  70. package/build/src/http-server/server-lock.d.ts.map +1 -1
  71. package/build/src/http-server/server-lock.js +27 -5
  72. package/build/src/tenants/default-tenant-database-provisioning.d.ts.map +1 -1
  73. package/build/src/tenants/default-tenant-database-provisioning.js +7 -1
  74. package/build/tenants/default-tenant-database-provisioning.js +8 -0
  75. package/package.json +2 -2
  76. package/src/application.js +32 -3
  77. package/src/background-jobs/main.js +9 -1
  78. package/src/background-jobs/worker.js +69 -6
  79. package/src/cli/process-args.js +34 -0
  80. package/src/configuration.js +26 -0
  81. package/src/database/drivers/base.js +34 -12
  82. package/src/database/drivers/mssql/index.js +17 -18
  83. package/src/database/drivers/mssql/table.js +28 -25
  84. package/src/database/drivers/mysql/index.js +15 -18
  85. package/src/database/drivers/mysql/table.js +31 -23
  86. package/src/database/drivers/pgsql/index.js +15 -18
  87. package/src/database/drivers/pgsql/table.js +28 -26
  88. package/src/database/drivers/sqlite/base.js +7 -9
  89. package/src/database/drivers/sqlite/table.js +32 -26
  90. package/src/database/pool/async-tracked-multi-connection.js +1 -0
  91. package/src/database/pool/base.js +14 -4
  92. package/src/database/pool/single-multi-use.js +1 -0
  93. package/src/environment-handlers/node/cli/commands/server.js +1 -0
  94. package/src/http-server/server-lock.js +28 -4
  95. package/src/tenants/default-tenant-database-provisioning.js +8 -0
@@ -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,6 +14,8 @@
14
14
  * driver's own `createDatabaseSql`/`dropDatabaseSql`.
15
15
  */
16
16
 
17
+ import PoolBase from "../database/pool/base.js"
18
+
17
19
  const SAFE_TENANT_DATABASE_NAME = /^[a-z0-9_]+$/
18
20
 
19
21
  /**
@@ -121,4 +123,10 @@ export async function dropTenantDatabase({configuration, databaseConfiguration})
121
123
  } finally {
122
124
  await connection.close()
123
125
  }
126
+
127
+ // The DROP DATABASE ran on the maintenance connection, so the dropped tenant's
128
+ // own shared schema-metadata cache was never invalidated by the DDL path. Clear
129
+ // it explicitly: recreating the tenant database later must re-introspect, not
130
+ // serve the dropped schema from the shared cache.
131
+ configuration.clearSchemaCachesForReuseKey(PoolBase.configurationReuseKey(databaseConfiguration))
124
132
  }