velocious 1.0.549 → 1.0.552

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 (56) hide show
  1. package/README.md +13 -0
  2. package/build/background-jobs/json-socket.js +25 -0
  3. package/build/background-jobs/socket-request.js +48 -6
  4. package/build/background-jobs/status-reporter.js +14 -2
  5. package/build/configuration-types.js +1 -0
  6. package/build/database/advisory-lock-runner.js +17 -8
  7. package/build/database/drivers/base.js +12 -0
  8. package/build/database/drivers/mssql/index.js +52 -3
  9. package/build/database/drivers/mysql/index.js +34 -0
  10. package/build/database/structure-sql-loader.js +12 -6
  11. package/build/src/background-jobs/json-socket.d.ts +20 -0
  12. package/build/src/background-jobs/json-socket.d.ts.map +1 -1
  13. package/build/src/background-jobs/json-socket.js +25 -1
  14. package/build/src/background-jobs/socket-request.d.ts +13 -1
  15. package/build/src/background-jobs/socket-request.d.ts.map +1 -1
  16. package/build/src/background-jobs/socket-request.js +44 -7
  17. package/build/src/background-jobs/status-reporter.d.ts +12 -1
  18. package/build/src/background-jobs/status-reporter.d.ts.map +1 -1
  19. package/build/src/background-jobs/status-reporter.js +14 -3
  20. package/build/src/configuration-types.d.ts +5 -0
  21. package/build/src/configuration-types.d.ts.map +1 -1
  22. package/build/src/configuration-types.js +2 -1
  23. package/build/src/database/advisory-lock-runner.d.ts +25 -8
  24. package/build/src/database/advisory-lock-runner.d.ts.map +1 -1
  25. package/build/src/database/advisory-lock-runner.js +18 -9
  26. package/build/src/database/drivers/base.d.ts +9 -0
  27. package/build/src/database/drivers/base.d.ts.map +1 -1
  28. package/build/src/database/drivers/base.js +12 -1
  29. package/build/src/database/drivers/mssql/index.d.ts +9 -0
  30. package/build/src/database/drivers/mssql/index.d.ts.map +1 -1
  31. package/build/src/database/drivers/mssql/index.js +45 -2
  32. package/build/src/database/drivers/mysql/index.d.ts.map +1 -1
  33. package/build/src/database/drivers/mysql/index.js +35 -1
  34. package/build/src/database/structure-sql-loader.d.ts.map +1 -1
  35. package/build/src/database/structure-sql-loader.js +14 -8
  36. package/build/src/testing/test.d.ts +2 -1
  37. package/build/src/testing/test.d.ts.map +1 -1
  38. package/build/src/testing/test.js +3 -2
  39. package/build/src/testing/wait-for-event.d.ts +46 -0
  40. package/build/src/testing/wait-for-event.d.ts.map +1 -0
  41. package/build/src/testing/wait-for-event.js +64 -0
  42. package/build/testing/test.js +2 -1
  43. package/build/testing/wait-for-event.js +72 -0
  44. package/build/tsconfig.tsbuildinfo +1 -1
  45. package/package.json +2 -2
  46. package/src/background-jobs/json-socket.js +25 -0
  47. package/src/background-jobs/socket-request.js +48 -6
  48. package/src/background-jobs/status-reporter.js +14 -2
  49. package/src/configuration-types.js +1 -0
  50. package/src/database/advisory-lock-runner.js +17 -8
  51. package/src/database/drivers/base.js +12 -0
  52. package/src/database/drivers/mssql/index.js +52 -3
  53. package/src/database/drivers/mysql/index.js +34 -0
  54. package/src/database/structure-sql-loader.js +12 -6
  55. package/src/testing/test.js +2 -1
  56. package/src/testing/wait-for-event.js +72 -0
@@ -4,6 +4,7 @@ import path from "path"
4
4
  import {fileURLToPath} from "url"
5
5
  import EventEmitter from "../utils/event-emitter.js"
6
6
  import Expect from "./expect.js"
7
+ import waitForEvent from "./wait-for-event.js"
7
8
  import {arrayContaining, objectContaining} from "./expect-utils.js"
8
9
 
9
10
  /**
@@ -351,7 +352,7 @@ globalThis.fit = fit
351
352
  globalThis.testEvents = testEvents
352
353
  globalThis.configureTests = configureTests
353
354
 
354
- export {afterAll, afterEach, beforeAll, beforeEach, configureTests, describe, expect, fit, it, arrayContaining, objectContaining, testConfig, testEvents, tests}
355
+ export {afterAll, afterEach, beforeAll, beforeEach, configureTests, describe, expect, fit, it, arrayContaining, objectContaining, testConfig, testEvents, tests, waitForEvent}
355
356
  /**
356
357
  * VelociousTestConfig type.
357
358
  * @typedef {object} VelociousTestConfig
@@ -0,0 +1,72 @@
1
+ // @ts-check
2
+
3
+ /**
4
+ * @typedef {object} WaitForEventOptions
5
+ * @property {number} [timeoutMs] Timeout in milliseconds (default: 5000).
6
+ * @property {(...args: Array<?>) => boolean} [filter] Only resolve when this predicate returns true for the emitted arguments.
7
+ */
8
+
9
+ /**
10
+ * @typedef {object} EventEmitterLike
11
+ * @property {(event: string, listener: (...args: Array<?>) => void) => void} on Registers a listener.
12
+ * @property {(event: string, listener: (...args: Array<?>) => void) => void} off Removes a listener.
13
+ */
14
+
15
+ /**
16
+ * Resolves the moment `eventName` fires on `emitter` — optionally only when `filter`
17
+ * matches the emitted arguments — instead of sleeping a fixed duration. Rejects with a
18
+ * timeout error if the event does not fire within `timeoutMs`. The listener is always
19
+ * removed (on resolve and on timeout).
20
+ *
21
+ * Use this to await a real signal (a background job finishing, a model update, a
22
+ * websocket message) rather than guessing a delay. To poll an arbitrary condition
23
+ * instead of a discrete event, use awaitery's `waitFor`.
24
+ * @param {EventEmitterLike} emitter - Event emitter exposing `on`/`off` (Node EventEmitter, eventemitter3, velocious `testEvents`, ...).
25
+ * @param {string} eventName - The event to wait for.
26
+ * @param {WaitForEventOptions} [options] - Options.
27
+ * @returns {Promise<?>} - Resolves with the single emitted argument, an array when the event emits multiple, or undefined when it emits none.
28
+ */
29
+ export default function waitForEvent(emitter, eventName, options = {}) {
30
+ const {timeoutMs = 5000, filter} = options
31
+
32
+ return new Promise((resolve, reject) => {
33
+ /** @type {ReturnType<typeof setTimeout>} */
34
+ let timer
35
+
36
+ /**
37
+ * Resolves the wait when a matching event fires, removing itself first. A filter
38
+ * that throws (e.g. it assumes an event shape an intermediate emission doesn't
39
+ * have) rejects immediately rather than leaving the waiter pending until timeout.
40
+ * @param {...?} args - Emitted arguments.
41
+ * @returns {void}
42
+ */
43
+ const listener = (...args) => {
44
+ if (filter) {
45
+ let matched
46
+
47
+ try {
48
+ matched = filter(...args)
49
+ } catch (error) {
50
+ clearTimeout(timer)
51
+ emitter.off(eventName, listener)
52
+ reject(error)
53
+
54
+ return
55
+ }
56
+
57
+ if (!matched) return
58
+ }
59
+
60
+ clearTimeout(timer)
61
+ emitter.off(eventName, listener)
62
+ resolve(args.length > 1 ? args : args[0])
63
+ }
64
+
65
+ timer = setTimeout(() => {
66
+ emitter.off(eventName, listener)
67
+ reject(new Error(`Timed out after ${timeoutMs}ms waiting for event ${JSON.stringify(eventName)}`))
68
+ }, timeoutMs)
69
+
70
+ emitter.on(eventName, listener)
71
+ })
72
+ }
@@ -1 +1 @@
1
- {"root":["../index.js","../bin/velocious.js","../src/application.js","../src/configuration-resolver.js","../src/configuration-types.js","../src/configuration.js","../src/controller.js","../src/current-configuration.js","../src/current.js","../src/error-logger.js","../src/frontend-model-controller.js","../src/initializer.js","../src/logger.js","../src/mailer.js","../src/record-payload-values.js","../src/time-zone.js","../src/velocious-error.js","../src/authorization/ability.js","../src/authorization/base-resource.js","../src/background-jobs/client.js","../src/background-jobs/cron-expression.js","../src/background-jobs/forked-runner-child.js","../src/background-jobs/job-record.js","../src/background-jobs/job-registry.js","../src/background-jobs/job-runner.js","../src/background-jobs/job.js","../src/background-jobs/json-socket.js","../src/background-jobs/main.js","../src/background-jobs/normalize-error.js","../src/background-jobs/pooled-runner-child.js","../src/background-jobs/runner-process-title.js","../src/background-jobs/scheduler.js","../src/background-jobs/socket-request.js","../src/background-jobs/status-reporter.js","../src/background-jobs/store.js","../src/background-jobs/types.js","../src/background-jobs/worker.js","../src/background-jobs/web/authorization.js","../src/background-jobs/web/controller.js","../src/background-jobs/web/index.js","../src/background-jobs/web/path-matcher.js","../src/background-jobs/web/registry.js","../src/beacon/client.js","../src/beacon/in-process-broker.js","../src/beacon/in-process-client.js","../src/beacon/server.js","../src/beacon/types.js","../src/cli/base-command.js","../src/cli/browser-cli.js","../src/cli/index.js","../src/cli/tenant-database-command-helper.js","../src/cli/use-browser-cli.js","../src/cli/commands/background-jobs-main.js","../src/cli/commands/background-jobs-runner.js","../src/cli/commands/background-jobs-worker.js","../src/cli/commands/beacon.js","../src/cli/commands/console.js","../src/cli/commands/init.js","../src/cli/commands/routes.js","../src/cli/commands/run-script.js","../src/cli/commands/runner.js","../src/cli/commands/server.js","../src/cli/commands/test.js","../src/cli/commands/db/base-command.js","../src/cli/commands/db/create.js","../src/cli/commands/db/drop.js","../src/cli/commands/db/migrate.js","../src/cli/commands/db/reset.js","../src/cli/commands/db/rollback.js","../src/cli/commands/db/seed.js","../src/cli/commands/db/schema/dump.js","../src/cli/commands/db/schema/load.js","../src/cli/commands/db/tenants/check.js","../src/cli/commands/db/tenants/create.js","../src/cli/commands/db/tenants/drop.js","../src/cli/commands/db/tenants/migrate.js","../src/cli/commands/destroy/migration.js","../src/cli/commands/generate/base-models.js","../src/cli/commands/generate/frontend-models.js","../src/cli/commands/generate/migration.js","../src/cli/commands/generate/model.js","../src/cli/commands/lint/relationships.js","../src/database/advisory-lock-runner.js","../src/database/annotations-async-hooks.js","../src/database/annotations.js","../src/database/column-types.js","../src/database/datetime-storage.js","../src/database/handler.js","../src/database/initializer-from-require-context.js","../src/database/live-query.js","../src/database/migrations-ledger.js","../src/database/migrator.js","../src/database/record-changes.js","../src/database/structure-sql-loader.js","../src/database/use-database.js","../src/database/use-live-query.js","../src/database/drivers/base-column.js","../src/database/drivers/base-columns-index.js","../src/database/drivers/base-foreign-key.js","../src/database/drivers/base-table.js","../src/database/drivers/base.js","../src/database/drivers/mssql/column.js","../src/database/drivers/mssql/columns-index.js","../src/database/drivers/mssql/connect-connection.js","../src/database/drivers/mssql/foreign-key.js","../src/database/drivers/mssql/index.js","../src/database/drivers/mssql/options.js","../src/database/drivers/mssql/query-parser.js","../src/database/drivers/mssql/structure-sql.js","../src/database/drivers/mssql/table.js","../src/database/drivers/mssql/sql/alter-table.js","../src/database/drivers/mssql/sql/create-database.js","../src/database/drivers/mssql/sql/create-index.js","../src/database/drivers/mssql/sql/create-table.js","../src/database/drivers/mssql/sql/delete.js","../src/database/drivers/mssql/sql/drop-database.js","../src/database/drivers/mssql/sql/drop-table.js","../src/database/drivers/mssql/sql/insert.js","../src/database/drivers/mssql/sql/remove-index.js","../src/database/drivers/mssql/sql/update.js","../src/database/drivers/mssql/sql/upsert.js","../src/database/drivers/mysql/column.js","../src/database/drivers/mysql/columns-index.js","../src/database/drivers/mysql/foreign-key.js","../src/database/drivers/mysql/index.js","../src/database/drivers/mysql/options.js","../src/database/drivers/mysql/query-parser.js","../src/database/drivers/mysql/query-stream.js","../src/database/drivers/mysql/query.js","../src/database/drivers/mysql/structure-sql.js","../src/database/drivers/mysql/table.js","../src/database/drivers/mysql/sql/alter-table.js","../src/database/drivers/mysql/sql/create-database.js","../src/database/drivers/mysql/sql/create-index.js","../src/database/drivers/mysql/sql/create-table.js","../src/database/drivers/mysql/sql/delete.js","../src/database/drivers/mysql/sql/drop-database.js","../src/database/drivers/mysql/sql/drop-table.js","../src/database/drivers/mysql/sql/insert.js","../src/database/drivers/mysql/sql/remove-index.js","../src/database/drivers/mysql/sql/update.js","../src/database/drivers/mysql/sql/upsert.js","../src/database/drivers/pgsql/column.js","../src/database/drivers/pgsql/columns-index.js","../src/database/drivers/pgsql/foreign-key.js","../src/database/drivers/pgsql/index.js","../src/database/drivers/pgsql/options.js","../src/database/drivers/pgsql/query-parser.js","../src/database/drivers/pgsql/structure-sql.js","../src/database/drivers/pgsql/table.js","../src/database/drivers/pgsql/sql/alter-table.js","../src/database/drivers/pgsql/sql/create-database.js","../src/database/drivers/pgsql/sql/create-index.js","../src/database/drivers/pgsql/sql/create-table.js","../src/database/drivers/pgsql/sql/delete.js","../src/database/drivers/pgsql/sql/drop-database.js","../src/database/drivers/pgsql/sql/drop-table.js","../src/database/drivers/pgsql/sql/insert.js","../src/database/drivers/pgsql/sql/remove-index.js","../src/database/drivers/pgsql/sql/update.js","../src/database/drivers/pgsql/sql/upsert.js","../src/database/drivers/sqlite/base.js","../src/database/drivers/sqlite/column.js","../src/database/drivers/sqlite/columns-index.js","../src/database/drivers/sqlite/connection-sql-js.js","../src/database/drivers/sqlite/foreign-key.js","../src/database/drivers/sqlite/index.js","../src/database/drivers/sqlite/index.native.js","../src/database/drivers/sqlite/index.web.js","../src/database/drivers/sqlite/options.js","../src/database/drivers/sqlite/query-parser.js","../src/database/drivers/sqlite/query.js","../src/database/drivers/sqlite/query.native.js","../src/database/drivers/sqlite/query.web.js","../src/database/drivers/sqlite/structure-sql.js","../src/database/drivers/sqlite/table-rebuilder.js","../src/database/drivers/sqlite/table.js","../src/database/drivers/sqlite/web-persistence.js","../src/database/drivers/sqlite/sql/alter-table.js","../src/database/drivers/sqlite/sql/create-index.js","../src/database/drivers/sqlite/sql/create-table.js","../src/database/drivers/sqlite/sql/delete.js","../src/database/drivers/sqlite/sql/drop-table.js","../src/database/drivers/sqlite/sql/insert.js","../src/database/drivers/sqlite/sql/remove-index.js","../src/database/drivers/sqlite/sql/update.js","../src/database/drivers/sqlite/sql/upsert.js","../src/database/drivers/structure-sql/utils.js","../src/database/migration/index.js","../src/database/migrator/files-finder.js","../src/database/migrator/types.js","../src/database/pool/async-tracked-multi-connection.js","../src/database/pool/base-methods-forward.js","../src/database/pool/base.js","../src/database/pool/single-multi-use.js","../src/database/query/alter-table-base.js","../src/database/query/base.js","../src/database/query/create-database-base.js","../src/database/query/create-index-base.js","../src/database/query/create-table-base.js","../src/database/query/delete-base.js","../src/database/query/drop-database-base.js","../src/database/query/drop-table-base.js","../src/database/query/from-base.js","../src/database/query/from-plain.js","../src/database/query/from-table.js","../src/database/query/index.js","../src/database/query/insert-base.js","../src/database/query/join-base.js","../src/database/query/join-object.js","../src/database/query/join-plain.js","../src/database/query/join-tracker.js","../src/database/query/model-class-query.js","../src/database/query/order-base.js","../src/database/query/order-column.js","../src/database/query/order-plain.js","../src/database/query/preloader.js","../src/database/query/query-data.js","../src/database/query/remove-index-base.js","../src/database/query/select-base.js","../src/database/query/select-plain.js","../src/database/query/select-table-and-column.js","../src/database/query/update-base.js","../src/database/query/upsert-base.js","../src/database/query/where-base.js","../src/database/query/where-combinator.js","../src/database/query/where-hash.js","../src/database/query/where-model-class-hash.js","../src/database/query/where-not.js","../src/database/query/where-plain.js","../src/database/query/with-count.js","../src/database/query/preloader/belongs-to.js","../src/database/query/preloader/ensure-model-class-initialized.js","../src/database/query/preloader/has-many.js","../src/database/query/preloader/has-one.js","../src/database/query/preloader/selection.js","../src/database/query-parser/base-query-parser.js","../src/database/query-parser/from-parser.js","../src/database/query-parser/group-parser.js","../src/database/query-parser/joins-parser.js","../src/database/query-parser/limit-parser.js","../src/database/query-parser/options.js","../src/database/query-parser/order-parser.js","../src/database/query-parser/select-parser.js","../src/database/query-parser/where-parser.js","../src/database/record/acts-as-list.js","../src/database/record/auditing.js","../src/database/record/counter-cache-magnitude.js","../src/database/record/index.js","../src/database/record/record-not-found-error.js","../src/database/record/state-machine.js","../src/database/record/user-module.js","../src/database/record/validation-messages.js","../src/database/record/attachments/attachment-record.js","../src/database/record/attachments/download.js","../src/database/record/attachments/handle.js","../src/database/record/attachments/normalize-input.js","../src/database/record/attachments/store.js","../src/database/record/attachments/storage-drivers/filesystem.js","../src/database/record/attachments/storage-drivers/native.js","../src/database/record/attachments/storage-drivers/s3.js","../src/database/record/instance-relationships/base.js","../src/database/record/instance-relationships/belongs-to.js","../src/database/record/instance-relationships/has-many.js","../src/database/record/instance-relationships/has-one.js","../src/database/record/relationships/base.js","../src/database/record/relationships/belongs-to.js","../src/database/record/relationships/has-many.js","../src/database/record/relationships/has-one.js","../src/database/record/validators/base.js","../src/database/record/validators/format.js","../src/database/record/validators/length.js","../src/database/record/validators/presence.js","../src/database/record/validators/uniqueness.js","../src/database/table-data/index.js","../src/database/table-data/table-column.js","../src/database/table-data/table-foreign-key.js","../src/database/table-data/table-index.js","../src/database/table-data/table-reference.js","../src/database/tenants/data-copier.js","../src/database/tenants/schema-cloner.js","../src/database/tenants/tenant-table-plan.js","../src/environment-handlers/base.js","../src/environment-handlers/browser.js","../src/environment-handlers/node.js","../src/environment-handlers/node/cli/commands/background-jobs-main.js","../src/environment-handlers/node/cli/commands/background-jobs-runner.js","../src/environment-handlers/node/cli/commands/background-jobs-worker.js","../src/environment-handlers/node/cli/commands/beacon.js","../src/environment-handlers/node/cli/commands/cli-command-context.js","../src/environment-handlers/node/cli/commands/console.js","../src/environment-handlers/node/cli/commands/init.js","../src/environment-handlers/node/cli/commands/routes.js","../src/environment-handlers/node/cli/commands/run-script.js","../src/environment-handlers/node/cli/commands/runner.js","../src/environment-handlers/node/cli/commands/server.js","../src/environment-handlers/node/cli/commands/test.js","../src/environment-handlers/node/cli/commands/db/seed.js","../src/environment-handlers/node/cli/commands/db/schema/dump.js","../src/environment-handlers/node/cli/commands/db/schema/load.js","../src/environment-handlers/node/cli/commands/destroy/migration.js","../src/environment-handlers/node/cli/commands/generate/base-models.js","../src/environment-handlers/node/cli/commands/generate/frontend-models.js","../src/environment-handlers/node/cli/commands/generate/generated-file-banner.js","../src/environment-handlers/node/cli/commands/generate/migration.js","../src/environment-handlers/node/cli/commands/generate/model.js","../src/environment-handlers/node/cli/commands/lint/relationships.js","../src/error-reporting/request-details.js","../src/frontend-model-resource/base-resource.js","../src/frontend-model-resource/velocious-attachment-resource.js","../src/frontend-models/base.js","../src/frontend-models/built-in-resources.js","../src/frontend-models/clear-pending-debounced-callback.js","../src/frontend-models/event-hook-models.js","../src/frontend-models/model-registry.js","../src/frontend-models/outgoing-event-buffer.js","../src/frontend-models/preloader.js","../src/frontend-models/query.js","../src/frontend-models/resource-config-validation.js","../src/frontend-models/resource-definition.js","../src/frontend-models/transport-serialization.js","../src/frontend-models/use-created-event.js","../src/frontend-models/use-destroyed-event.js","../src/frontend-models/use-model-class-event.js","../src/frontend-models/use-updated-event.js","../src/frontend-models/websocket-channel.js","../src/frontend-models/websocket-publishers.js","../src/http-client/header.js","../src/http-client/index.js","../src/http-client/request.js","../src/http-client/response.js","../src/http-client/websocket-client.js","../src/http-server/cookie.js","../src/http-server/development-reloader.js","../src/http-server/index.js","../src/http-server/remote-address.js","../src/http-server/server-client.js","../src/http-server/server-lock.js","../src/http-server/websocket-channel-subscribers.js","../src/http-server/websocket-channel.js","../src/http-server/websocket-connection.js","../src/http-server/websocket-event-log-store.js","../src/http-server/websocket-events-host.js","../src/http-server/websocket-events.js","../src/http-server/client/index.js","../src/http-server/client/params-to-object.js","../src/http-server/client/request-parser.js","../src/http-server/client/request-runner.js","../src/http-server/client/request-timing.js","../src/http-server/client/request.js","../src/http-server/client/response.js","../src/http-server/client/websocket-request.js","../src/http-server/client/websocket-session.js","../src/http-server/client/request-buffer/form-data-part.js","../src/http-server/client/request-buffer/header.js","../src/http-server/client/request-buffer/index.js","../src/http-server/client/uploaded-file/memory-uploaded-file.js","../src/http-server/client/uploaded-file/temporary-uploaded-file.js","../src/http-server/client/uploaded-file/uploaded-file.js","../src/http-server/worker-handler/channel-subscriber-dispatch.js","../src/http-server/worker-handler/in-process.js","../src/http-server/worker-handler/index.js","../src/http-server/worker-handler/worker-script.js","../src/http-server/worker-handler/worker-thread.js","../src/jobs/mail-delivery.js","../src/jobs/prune-terminal-background-jobs.js","../src/logger/base-logger.js","../src/logger/console-logger.js","../src/logger/file-logger.js","../src/logger/outputs/array-output.js","../src/logger/outputs/console-output.js","../src/logger/outputs/file-output.js","../src/logger/outputs/stdout-output.js","../src/mailer/base.js","../src/mailer/delivery.js","../src/mailer/index.js","../src/mailer/backends/smtp.js","../src/packages/velocious-package.js","../src/plugins/sqljs-wasm-route-controller.js","../src/plugins/sqljs-wasm-route.js","../src/routes/app-routes.js","../src/routes/base-route.js","../src/routes/basic-route.js","../src/routes/get-route.js","../src/routes/index.js","../src/routes/namespace-route.js","../src/routes/plugin-routes.js","../src/routes/post-route.js","../src/routes/resolver.js","../src/routes/resource-route.js","../src/routes/root-route.js","../src/routes/built-in/api-manifest/controller.js","../src/routes/built-in/debug/controller.js","../src/routes/built-in/errors/controller.js","../src/routes/hooks/frontend-model-command-route-hook.js","../src/sync/conflict-strategy.js","../src/sync/device-identity.js","../src/sync/local-mutation-log.js","../src/sync/offline-grant.js","../src/sync/peer-mutation-bundle.js","../src/sync/query-scope.js","../src/sync/server-change-feed.js","../src/sync/server-sequence-allocator.js","../src/sync/stable-json.js","../src/sync/sync-api-client-types.js","../src/sync/sync-api-client.js","../src/sync/sync-api-controller.js","../src/sync/sync-change-fanout.js","../src/sync/sync-channel-name.js","../src/sync/sync-client-registry.js","../src/sync/sync-client-types.js","../src/sync/sync-client.js","../src/sync/sync-envelope-replay-service.js","../src/sync/sync-model-change-feed-service.js","../src/sync/sync-publish-suppression.js","../src/sync/sync-publisher-types.js","../src/sync/sync-publisher.js","../src/sync/sync-realtime-bridge.js","../src/sync/sync-replay-upsert-applier.js","../src/sync/sync-resource-base.js","../src/sync/sync-scope-attributes.js","../src/sync/sync-scope-store.js","../src/sync/sync-websocket-channel.js","../src/tenants/default-tenant-database-provisioning.js","../src/tenants/tenant-aggregator.js","../src/tenants/tenant-iterator.js","../src/tenants/tenant.js","../src/testing/base-expect.js","../src/testing/browser-frontend-model-event-hook-scenarios.js","../src/testing/browser-test-app.js","../src/testing/expect-to-change.js","../src/testing/expect-utils.js","../src/testing/expect.js","../src/testing/request-client.js","../src/testing/test-files-finder.js","../src/testing/test-filter-parser.js","../src/testing/test-runner.js","../src/testing/test-suite-splitter.js","../src/testing/test.js","../src/types/external-modules.d.ts","../src/utils/backtrace-cleaner-node.js","../src/utils/backtrace-cleaner.js","../src/utils/deburr-column-name.js","../src/utils/event-emitter.js","../src/utils/file-exists.js","../src/utils/format-value.js","../src/utils/is-date.js","../src/utils/model-scope.js","../src/utils/nest-callbacks.js","../src/utils/plain-object.js","../src/utils/ransack.js","../src/utils/rest-args-error.js","../src/utils/singularize-model-name.js","../src/utils/split-sql-statements.js","../src/utils/to-import-specifier.js","../src/utils/with-tracked-stack-async-hooks.js","../src/utils/with-tracked-stack.js"],"version":"6.0.3"}
1
+ {"root":["../index.js","../bin/velocious.js","../src/application.js","../src/configuration-resolver.js","../src/configuration-types.js","../src/configuration.js","../src/controller.js","../src/current-configuration.js","../src/current.js","../src/error-logger.js","../src/frontend-model-controller.js","../src/initializer.js","../src/logger.js","../src/mailer.js","../src/record-payload-values.js","../src/time-zone.js","../src/velocious-error.js","../src/authorization/ability.js","../src/authorization/base-resource.js","../src/background-jobs/client.js","../src/background-jobs/cron-expression.js","../src/background-jobs/forked-runner-child.js","../src/background-jobs/job-record.js","../src/background-jobs/job-registry.js","../src/background-jobs/job-runner.js","../src/background-jobs/job.js","../src/background-jobs/json-socket.js","../src/background-jobs/main.js","../src/background-jobs/normalize-error.js","../src/background-jobs/pooled-runner-child.js","../src/background-jobs/runner-process-title.js","../src/background-jobs/scheduler.js","../src/background-jobs/socket-request.js","../src/background-jobs/status-reporter.js","../src/background-jobs/store.js","../src/background-jobs/types.js","../src/background-jobs/worker.js","../src/background-jobs/web/authorization.js","../src/background-jobs/web/controller.js","../src/background-jobs/web/index.js","../src/background-jobs/web/path-matcher.js","../src/background-jobs/web/registry.js","../src/beacon/client.js","../src/beacon/in-process-broker.js","../src/beacon/in-process-client.js","../src/beacon/server.js","../src/beacon/types.js","../src/cli/base-command.js","../src/cli/browser-cli.js","../src/cli/index.js","../src/cli/tenant-database-command-helper.js","../src/cli/use-browser-cli.js","../src/cli/commands/background-jobs-main.js","../src/cli/commands/background-jobs-runner.js","../src/cli/commands/background-jobs-worker.js","../src/cli/commands/beacon.js","../src/cli/commands/console.js","../src/cli/commands/init.js","../src/cli/commands/routes.js","../src/cli/commands/run-script.js","../src/cli/commands/runner.js","../src/cli/commands/server.js","../src/cli/commands/test.js","../src/cli/commands/db/base-command.js","../src/cli/commands/db/create.js","../src/cli/commands/db/drop.js","../src/cli/commands/db/migrate.js","../src/cli/commands/db/reset.js","../src/cli/commands/db/rollback.js","../src/cli/commands/db/seed.js","../src/cli/commands/db/schema/dump.js","../src/cli/commands/db/schema/load.js","../src/cli/commands/db/tenants/check.js","../src/cli/commands/db/tenants/create.js","../src/cli/commands/db/tenants/drop.js","../src/cli/commands/db/tenants/migrate.js","../src/cli/commands/destroy/migration.js","../src/cli/commands/generate/base-models.js","../src/cli/commands/generate/frontend-models.js","../src/cli/commands/generate/migration.js","../src/cli/commands/generate/model.js","../src/cli/commands/lint/relationships.js","../src/database/advisory-lock-runner.js","../src/database/annotations-async-hooks.js","../src/database/annotations.js","../src/database/column-types.js","../src/database/datetime-storage.js","../src/database/handler.js","../src/database/initializer-from-require-context.js","../src/database/live-query.js","../src/database/migrations-ledger.js","../src/database/migrator.js","../src/database/record-changes.js","../src/database/structure-sql-loader.js","../src/database/use-database.js","../src/database/use-live-query.js","../src/database/drivers/base-column.js","../src/database/drivers/base-columns-index.js","../src/database/drivers/base-foreign-key.js","../src/database/drivers/base-table.js","../src/database/drivers/base.js","../src/database/drivers/mssql/column.js","../src/database/drivers/mssql/columns-index.js","../src/database/drivers/mssql/connect-connection.js","../src/database/drivers/mssql/foreign-key.js","../src/database/drivers/mssql/index.js","../src/database/drivers/mssql/options.js","../src/database/drivers/mssql/query-parser.js","../src/database/drivers/mssql/structure-sql.js","../src/database/drivers/mssql/table.js","../src/database/drivers/mssql/sql/alter-table.js","../src/database/drivers/mssql/sql/create-database.js","../src/database/drivers/mssql/sql/create-index.js","../src/database/drivers/mssql/sql/create-table.js","../src/database/drivers/mssql/sql/delete.js","../src/database/drivers/mssql/sql/drop-database.js","../src/database/drivers/mssql/sql/drop-table.js","../src/database/drivers/mssql/sql/insert.js","../src/database/drivers/mssql/sql/remove-index.js","../src/database/drivers/mssql/sql/update.js","../src/database/drivers/mssql/sql/upsert.js","../src/database/drivers/mysql/column.js","../src/database/drivers/mysql/columns-index.js","../src/database/drivers/mysql/foreign-key.js","../src/database/drivers/mysql/index.js","../src/database/drivers/mysql/options.js","../src/database/drivers/mysql/query-parser.js","../src/database/drivers/mysql/query-stream.js","../src/database/drivers/mysql/query.js","../src/database/drivers/mysql/structure-sql.js","../src/database/drivers/mysql/table.js","../src/database/drivers/mysql/sql/alter-table.js","../src/database/drivers/mysql/sql/create-database.js","../src/database/drivers/mysql/sql/create-index.js","../src/database/drivers/mysql/sql/create-table.js","../src/database/drivers/mysql/sql/delete.js","../src/database/drivers/mysql/sql/drop-database.js","../src/database/drivers/mysql/sql/drop-table.js","../src/database/drivers/mysql/sql/insert.js","../src/database/drivers/mysql/sql/remove-index.js","../src/database/drivers/mysql/sql/update.js","../src/database/drivers/mysql/sql/upsert.js","../src/database/drivers/pgsql/column.js","../src/database/drivers/pgsql/columns-index.js","../src/database/drivers/pgsql/foreign-key.js","../src/database/drivers/pgsql/index.js","../src/database/drivers/pgsql/options.js","../src/database/drivers/pgsql/query-parser.js","../src/database/drivers/pgsql/structure-sql.js","../src/database/drivers/pgsql/table.js","../src/database/drivers/pgsql/sql/alter-table.js","../src/database/drivers/pgsql/sql/create-database.js","../src/database/drivers/pgsql/sql/create-index.js","../src/database/drivers/pgsql/sql/create-table.js","../src/database/drivers/pgsql/sql/delete.js","../src/database/drivers/pgsql/sql/drop-database.js","../src/database/drivers/pgsql/sql/drop-table.js","../src/database/drivers/pgsql/sql/insert.js","../src/database/drivers/pgsql/sql/remove-index.js","../src/database/drivers/pgsql/sql/update.js","../src/database/drivers/pgsql/sql/upsert.js","../src/database/drivers/sqlite/base.js","../src/database/drivers/sqlite/column.js","../src/database/drivers/sqlite/columns-index.js","../src/database/drivers/sqlite/connection-sql-js.js","../src/database/drivers/sqlite/foreign-key.js","../src/database/drivers/sqlite/index.js","../src/database/drivers/sqlite/index.native.js","../src/database/drivers/sqlite/index.web.js","../src/database/drivers/sqlite/options.js","../src/database/drivers/sqlite/query-parser.js","../src/database/drivers/sqlite/query.js","../src/database/drivers/sqlite/query.native.js","../src/database/drivers/sqlite/query.web.js","../src/database/drivers/sqlite/structure-sql.js","../src/database/drivers/sqlite/table-rebuilder.js","../src/database/drivers/sqlite/table.js","../src/database/drivers/sqlite/web-persistence.js","../src/database/drivers/sqlite/sql/alter-table.js","../src/database/drivers/sqlite/sql/create-index.js","../src/database/drivers/sqlite/sql/create-table.js","../src/database/drivers/sqlite/sql/delete.js","../src/database/drivers/sqlite/sql/drop-table.js","../src/database/drivers/sqlite/sql/insert.js","../src/database/drivers/sqlite/sql/remove-index.js","../src/database/drivers/sqlite/sql/update.js","../src/database/drivers/sqlite/sql/upsert.js","../src/database/drivers/structure-sql/utils.js","../src/database/migration/index.js","../src/database/migrator/files-finder.js","../src/database/migrator/types.js","../src/database/pool/async-tracked-multi-connection.js","../src/database/pool/base-methods-forward.js","../src/database/pool/base.js","../src/database/pool/single-multi-use.js","../src/database/query/alter-table-base.js","../src/database/query/base.js","../src/database/query/create-database-base.js","../src/database/query/create-index-base.js","../src/database/query/create-table-base.js","../src/database/query/delete-base.js","../src/database/query/drop-database-base.js","../src/database/query/drop-table-base.js","../src/database/query/from-base.js","../src/database/query/from-plain.js","../src/database/query/from-table.js","../src/database/query/index.js","../src/database/query/insert-base.js","../src/database/query/join-base.js","../src/database/query/join-object.js","../src/database/query/join-plain.js","../src/database/query/join-tracker.js","../src/database/query/model-class-query.js","../src/database/query/order-base.js","../src/database/query/order-column.js","../src/database/query/order-plain.js","../src/database/query/preloader.js","../src/database/query/query-data.js","../src/database/query/remove-index-base.js","../src/database/query/select-base.js","../src/database/query/select-plain.js","../src/database/query/select-table-and-column.js","../src/database/query/update-base.js","../src/database/query/upsert-base.js","../src/database/query/where-base.js","../src/database/query/where-combinator.js","../src/database/query/where-hash.js","../src/database/query/where-model-class-hash.js","../src/database/query/where-not.js","../src/database/query/where-plain.js","../src/database/query/with-count.js","../src/database/query/preloader/belongs-to.js","../src/database/query/preloader/ensure-model-class-initialized.js","../src/database/query/preloader/has-many.js","../src/database/query/preloader/has-one.js","../src/database/query/preloader/selection.js","../src/database/query-parser/base-query-parser.js","../src/database/query-parser/from-parser.js","../src/database/query-parser/group-parser.js","../src/database/query-parser/joins-parser.js","../src/database/query-parser/limit-parser.js","../src/database/query-parser/options.js","../src/database/query-parser/order-parser.js","../src/database/query-parser/select-parser.js","../src/database/query-parser/where-parser.js","../src/database/record/acts-as-list.js","../src/database/record/auditing.js","../src/database/record/counter-cache-magnitude.js","../src/database/record/index.js","../src/database/record/record-not-found-error.js","../src/database/record/state-machine.js","../src/database/record/user-module.js","../src/database/record/validation-messages.js","../src/database/record/attachments/attachment-record.js","../src/database/record/attachments/download.js","../src/database/record/attachments/handle.js","../src/database/record/attachments/normalize-input.js","../src/database/record/attachments/store.js","../src/database/record/attachments/storage-drivers/filesystem.js","../src/database/record/attachments/storage-drivers/native.js","../src/database/record/attachments/storage-drivers/s3.js","../src/database/record/instance-relationships/base.js","../src/database/record/instance-relationships/belongs-to.js","../src/database/record/instance-relationships/has-many.js","../src/database/record/instance-relationships/has-one.js","../src/database/record/relationships/base.js","../src/database/record/relationships/belongs-to.js","../src/database/record/relationships/has-many.js","../src/database/record/relationships/has-one.js","../src/database/record/validators/base.js","../src/database/record/validators/format.js","../src/database/record/validators/length.js","../src/database/record/validators/presence.js","../src/database/record/validators/uniqueness.js","../src/database/table-data/index.js","../src/database/table-data/table-column.js","../src/database/table-data/table-foreign-key.js","../src/database/table-data/table-index.js","../src/database/table-data/table-reference.js","../src/database/tenants/data-copier.js","../src/database/tenants/schema-cloner.js","../src/database/tenants/tenant-table-plan.js","../src/environment-handlers/base.js","../src/environment-handlers/browser.js","../src/environment-handlers/node.js","../src/environment-handlers/node/cli/commands/background-jobs-main.js","../src/environment-handlers/node/cli/commands/background-jobs-runner.js","../src/environment-handlers/node/cli/commands/background-jobs-worker.js","../src/environment-handlers/node/cli/commands/beacon.js","../src/environment-handlers/node/cli/commands/cli-command-context.js","../src/environment-handlers/node/cli/commands/console.js","../src/environment-handlers/node/cli/commands/init.js","../src/environment-handlers/node/cli/commands/routes.js","../src/environment-handlers/node/cli/commands/run-script.js","../src/environment-handlers/node/cli/commands/runner.js","../src/environment-handlers/node/cli/commands/server.js","../src/environment-handlers/node/cli/commands/test.js","../src/environment-handlers/node/cli/commands/db/seed.js","../src/environment-handlers/node/cli/commands/db/schema/dump.js","../src/environment-handlers/node/cli/commands/db/schema/load.js","../src/environment-handlers/node/cli/commands/destroy/migration.js","../src/environment-handlers/node/cli/commands/generate/base-models.js","../src/environment-handlers/node/cli/commands/generate/frontend-models.js","../src/environment-handlers/node/cli/commands/generate/generated-file-banner.js","../src/environment-handlers/node/cli/commands/generate/migration.js","../src/environment-handlers/node/cli/commands/generate/model.js","../src/environment-handlers/node/cli/commands/lint/relationships.js","../src/error-reporting/request-details.js","../src/frontend-model-resource/base-resource.js","../src/frontend-model-resource/velocious-attachment-resource.js","../src/frontend-models/base.js","../src/frontend-models/built-in-resources.js","../src/frontend-models/clear-pending-debounced-callback.js","../src/frontend-models/event-hook-models.js","../src/frontend-models/model-registry.js","../src/frontend-models/outgoing-event-buffer.js","../src/frontend-models/preloader.js","../src/frontend-models/query.js","../src/frontend-models/resource-config-validation.js","../src/frontend-models/resource-definition.js","../src/frontend-models/transport-serialization.js","../src/frontend-models/use-created-event.js","../src/frontend-models/use-destroyed-event.js","../src/frontend-models/use-model-class-event.js","../src/frontend-models/use-updated-event.js","../src/frontend-models/websocket-channel.js","../src/frontend-models/websocket-publishers.js","../src/http-client/header.js","../src/http-client/index.js","../src/http-client/request.js","../src/http-client/response.js","../src/http-client/websocket-client.js","../src/http-server/cookie.js","../src/http-server/development-reloader.js","../src/http-server/index.js","../src/http-server/remote-address.js","../src/http-server/server-client.js","../src/http-server/server-lock.js","../src/http-server/websocket-channel-subscribers.js","../src/http-server/websocket-channel.js","../src/http-server/websocket-connection.js","../src/http-server/websocket-event-log-store.js","../src/http-server/websocket-events-host.js","../src/http-server/websocket-events.js","../src/http-server/client/index.js","../src/http-server/client/params-to-object.js","../src/http-server/client/request-parser.js","../src/http-server/client/request-runner.js","../src/http-server/client/request-timing.js","../src/http-server/client/request.js","../src/http-server/client/response.js","../src/http-server/client/websocket-request.js","../src/http-server/client/websocket-session.js","../src/http-server/client/request-buffer/form-data-part.js","../src/http-server/client/request-buffer/header.js","../src/http-server/client/request-buffer/index.js","../src/http-server/client/uploaded-file/memory-uploaded-file.js","../src/http-server/client/uploaded-file/temporary-uploaded-file.js","../src/http-server/client/uploaded-file/uploaded-file.js","../src/http-server/worker-handler/channel-subscriber-dispatch.js","../src/http-server/worker-handler/in-process.js","../src/http-server/worker-handler/index.js","../src/http-server/worker-handler/worker-script.js","../src/http-server/worker-handler/worker-thread.js","../src/jobs/mail-delivery.js","../src/jobs/prune-terminal-background-jobs.js","../src/logger/base-logger.js","../src/logger/console-logger.js","../src/logger/file-logger.js","../src/logger/outputs/array-output.js","../src/logger/outputs/console-output.js","../src/logger/outputs/file-output.js","../src/logger/outputs/stdout-output.js","../src/mailer/base.js","../src/mailer/delivery.js","../src/mailer/index.js","../src/mailer/backends/smtp.js","../src/packages/velocious-package.js","../src/plugins/sqljs-wasm-route-controller.js","../src/plugins/sqljs-wasm-route.js","../src/routes/app-routes.js","../src/routes/base-route.js","../src/routes/basic-route.js","../src/routes/get-route.js","../src/routes/index.js","../src/routes/namespace-route.js","../src/routes/plugin-routes.js","../src/routes/post-route.js","../src/routes/resolver.js","../src/routes/resource-route.js","../src/routes/root-route.js","../src/routes/built-in/api-manifest/controller.js","../src/routes/built-in/debug/controller.js","../src/routes/built-in/errors/controller.js","../src/routes/hooks/frontend-model-command-route-hook.js","../src/sync/conflict-strategy.js","../src/sync/device-identity.js","../src/sync/local-mutation-log.js","../src/sync/offline-grant.js","../src/sync/peer-mutation-bundle.js","../src/sync/query-scope.js","../src/sync/server-change-feed.js","../src/sync/server-sequence-allocator.js","../src/sync/stable-json.js","../src/sync/sync-api-client-types.js","../src/sync/sync-api-client.js","../src/sync/sync-api-controller.js","../src/sync/sync-change-fanout.js","../src/sync/sync-channel-name.js","../src/sync/sync-client-registry.js","../src/sync/sync-client-types.js","../src/sync/sync-client.js","../src/sync/sync-envelope-replay-service.js","../src/sync/sync-model-change-feed-service.js","../src/sync/sync-publish-suppression.js","../src/sync/sync-publisher-types.js","../src/sync/sync-publisher.js","../src/sync/sync-realtime-bridge.js","../src/sync/sync-replay-upsert-applier.js","../src/sync/sync-resource-base.js","../src/sync/sync-scope-attributes.js","../src/sync/sync-scope-store.js","../src/sync/sync-websocket-channel.js","../src/tenants/default-tenant-database-provisioning.js","../src/tenants/tenant-aggregator.js","../src/tenants/tenant-iterator.js","../src/tenants/tenant.js","../src/testing/base-expect.js","../src/testing/browser-frontend-model-event-hook-scenarios.js","../src/testing/browser-test-app.js","../src/testing/expect-to-change.js","../src/testing/expect-utils.js","../src/testing/expect.js","../src/testing/request-client.js","../src/testing/test-files-finder.js","../src/testing/test-filter-parser.js","../src/testing/test-runner.js","../src/testing/test-suite-splitter.js","../src/testing/test.js","../src/testing/wait-for-event.js","../src/types/external-modules.d.ts","../src/utils/backtrace-cleaner-node.js","../src/utils/backtrace-cleaner.js","../src/utils/deburr-column-name.js","../src/utils/event-emitter.js","../src/utils/file-exists.js","../src/utils/format-value.js","../src/utils/is-date.js","../src/utils/model-scope.js","../src/utils/nest-callbacks.js","../src/utils/plain-object.js","../src/utils/ransack.js","../src/utils/rest-args-error.js","../src/utils/singularize-model-name.js","../src/utils/split-sql-statements.js","../src/utils/to-import-specifier.js","../src/utils/with-tracked-stack-async-hooks.js","../src/utils/with-tracked-stack.js"],"version":"6.0.3"}
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "velocious": "build/bin/velocious.js"
4
4
  },
5
5
  "name": "velocious",
6
- "version": "1.0.549",
6
+ "version": "1.0.552",
7
7
  "main": "build/index.js",
8
8
  "types": "build/index.d.ts",
9
9
  "files": [
@@ -52,7 +52,7 @@
52
52
  "description": "",
53
53
  "dependencies": {
54
54
  "@js-temporal/polyfill": "^0.5.1",
55
- "awaitery": "^1.0.6",
55
+ "awaitery": "^1.0.17",
56
56
  "bcryptjs": "^3.0.2",
57
57
  "better-localstorage": "^1.0.7",
58
58
  "debounce": "^3.0.0",
@@ -44,6 +44,19 @@ export default class JsonSocket extends EventEmitter {
44
44
  * the main's liveness sweep to drop a wedged/silent worker.
45
45
  * @type {number | undefined} */
46
46
  this.lastSeenAt = undefined
47
+ /**
48
+ * Internal test-only observability counter — NOT public API. Number of times
49
+ * `destroy()` has run, incremented immediately before the raw socket
50
+ * `destroy()` call so specs can assert the actual teardown method that ran
51
+ * rather than a self-reported flag. Do not read or depend on this outside tests.
52
+ * @type {number} */
53
+ this._destroyCallCount = 0
54
+ /**
55
+ * Internal test-only observability counter — NOT public API. Number of times
56
+ * `close()` has run, incremented immediately before the raw socket `end()`
57
+ * call. Do not read or depend on this outside tests.
58
+ * @type {number} */
59
+ this._closeCallCount = 0
47
60
  this.buffer = ""
48
61
  this.socket.setEncoding("utf8")
49
62
  this.socket.on("data", (chunk) => this._onData(String(chunk)))
@@ -91,6 +104,18 @@ export default class JsonSocket extends EventEmitter {
91
104
  * @returns {void}
92
105
  */
93
106
  close() {
107
+ this._closeCallCount++
94
108
  this.socket.end()
95
109
  }
110
+
111
+ /**
112
+ * Forcibly destroys the underlying socket. Unlike {@link close}, which
113
+ * half-closes gracefully via `end()`, this tears the connection down
114
+ * immediately so a stalled/aborted request does not leave the socket alive.
115
+ * @returns {void}
116
+ */
117
+ destroy() {
118
+ this._destroyCallCount++
119
+ this.socket.destroy()
120
+ }
96
121
  }
@@ -15,6 +15,16 @@ export default class BackgroundJobsSocketRequest {
15
15
  this.host = host
16
16
  this.port = port
17
17
  this.role = role
18
+ /**
19
+ * Internal test-only observability reference — NOT public API. Holds the
20
+ * JsonSocket wrapper this request created so the timeout spec can inspect the
21
+ * wrapper's own `destroy()`/`close()` call counters — direct evidence of which
22
+ * teardown method actually ran, not a self-reported flag. Retains the single
23
+ * (already torn-down) wrapper for the request's lifetime. Do not expose or
24
+ * depend on this outside tests.
25
+ * @type {JsonSocket | undefined}
26
+ */
27
+ this._jsonSocket = undefined
18
28
  }
19
29
 
20
30
  /**
@@ -23,28 +33,60 @@ export default class BackgroundJobsSocketRequest {
23
33
  * @param {object} args - Options.
24
34
  * @param {(jsonSocket: JsonSocket) => void} args.onConnect - Called after the socket connects.
25
35
  * @param {(args: {message: import("./types.js").BackgroundJobSocketMessage, resolve: (value: T) => void, reject: (error: Error) => void}) => void} args.onMessage - Message handler.
36
+ * @param {AbortSignal} [args.signal] - Aborts the request; on abort the pending socket is destroyed and the promise rejects with the signal reason when it is an Error, otherwise with a generic abort Error.
26
37
  * @returns {Promise<T>} - Resolved request value.
27
38
  */
28
- async run({onConnect, onMessage}) {
39
+ async run({onConnect, onMessage, signal}) {
29
40
  const socket = net.createConnection({host: this.host, port: this.port})
30
41
  const jsonSocket = new JsonSocket(socket)
31
42
 
43
+ this._jsonSocket = jsonSocket
44
+
32
45
  return await new Promise((resolve, reject) => {
33
46
  let finished = false
34
47
  /**
35
48
  * Finish.
49
+ * @param {object} options - Options.
50
+ * @param {boolean} [options.destroy] - Destroy the socket instead of gracefully closing it.
36
51
  * @param {() => void} callback - Finish callback.
37
52
  */
38
- const finish = (callback) => {
53
+ const finish = ({destroy = false} = {}, callback) => {
39
54
  if (finished) return
40
55
  finished = true
56
+ if (signal) signal.removeEventListener("abort", onAbort)
41
57
  jsonSocket.removeAllListeners()
42
- jsonSocket.close()
58
+
59
+ if (destroy) {
60
+ jsonSocket.destroy()
61
+ } else {
62
+ jsonSocket.close()
63
+ }
64
+
43
65
  callback()
44
66
  }
45
67
 
68
+ /**
69
+ * Handles a cooperative abort: tears down the pending socket and rejects
70
+ * with the signal reason when it is an Error.
71
+ * @returns {void}
72
+ */
73
+ const onAbort = () => {
74
+ const reason = signal?.reason
75
+
76
+ finish({destroy: true}, () => reject(reason instanceof Error ? reason : new Error("Background job socket request aborted")))
77
+ }
78
+
79
+ if (signal) {
80
+ if (signal.aborted) {
81
+ onAbort()
82
+ return
83
+ }
84
+
85
+ signal.addEventListener("abort", onAbort)
86
+ }
87
+
46
88
  jsonSocket.on("error", (error) => {
47
- finish(() => reject(error))
89
+ finish({}, () => reject(error))
48
90
  })
49
91
 
50
92
  /**
@@ -54,8 +96,8 @@ export default class BackgroundJobsSocketRequest {
54
96
  jsonSocket.on("message", (message) => {
55
97
  onMessage({
56
98
  message,
57
- resolve: (value) => finish(() => resolve(value)),
58
- reject: (error) => finish(() => reject(error))
99
+ resolve: (value) => finish({}, () => resolve(value)),
100
+ reject: (error) => finish({}, () => reject(error))
59
101
  })
60
102
  })
61
103
 
@@ -15,11 +15,20 @@ export default class BackgroundJobsStatusReporter {
15
15
  * @param {import("../configuration.js").default} args.configuration - Configuration.
16
16
  * @param {string} [args.host] - Host.
17
17
  * @param {number} [args.port] - Port.
18
+ * @param {number} [args.attemptTimeoutMs] - Per-attempt socket-request timeout in milliseconds (default: 5000).
18
19
  */
19
- constructor({configuration, host, port}) {
20
+ constructor({configuration, host, port, attemptTimeoutMs = 5000}) {
20
21
  this.configuration = configuration
21
22
  this.host = host
22
23
  this.port = port
24
+ this.attemptTimeoutMs = attemptTimeoutMs
25
+ /**
26
+ * Internal test-only observability state — NOT public API. References the most
27
+ * recent socket request so the timeout spec can inspect how its socket was torn
28
+ * down. Do not expose or depend on this outside tests.
29
+ * @type {BackgroundJobsSocketRequest | undefined}
30
+ */
31
+ this._lastRequest = undefined
23
32
  this.logger = new Logger(this)
24
33
  }
25
34
 
@@ -39,10 +48,13 @@ export default class BackgroundJobsStatusReporter {
39
48
  const host = this.host || config.host
40
49
  const port = typeof this.port === "number" ? this.port : config.port
41
50
 
42
- await timeout({timeout: 5000}, async () => {
51
+ await timeout({timeout: this.attemptTimeoutMs}, async ({control}) => {
43
52
  const request = new BackgroundJobsSocketRequest({host, port, role: "reporter"})
44
53
 
54
+ this._lastRequest = request
55
+
45
56
  await request.run({
57
+ signal: control.signal,
46
58
  onConnect: (jsonSocket) => {
47
59
  jsonSocket.send({
48
60
  type: status === "completed" ? "job-complete" : "job-failed",
@@ -72,6 +72,7 @@
72
72
  * @property {function() : ?} [getConnection] - Custom connection factory override.
73
73
  * @property {string} [host] - Database host.
74
74
  * @property {boolean} [migrations] - Whether migrations are enabled for this database.
75
+ * @property {boolean} [multipleStatements] - (MySQL) Opt in to multi-statement queries so a whole structure SQL dump loads in one round-trip via `StructureSqlLoader`. Off by default; ordinary queries otherwise reject stacked statements.
75
76
  * @property {string} [password] - Password for the database user.
76
77
  * @property {number} [port] - Database port.
77
78
  * @property {string} [primaryKeyType] - Default type for implicit migration primary keys and references. Defaults to `uuid`.
@@ -1,6 +1,6 @@
1
1
  // @ts-check
2
2
 
3
- import timeout from "awaitery/build/timeout.js"
3
+ import timeout, {TimeoutError} from "awaitery/build/timeout.js"
4
4
 
5
5
  /**
6
6
  * Thrown when an advisory lock could not be acquired before `timeoutMs` elapsed.
@@ -67,9 +67,12 @@ export default class AdvisoryLockRunner {
67
67
 
68
68
  /**
69
69
  * Runs a callback after acquiring the advisory lock, waiting up to `timeoutMs`.
70
+ * When a `holdTimeoutMs` is set the callback receives a `TimeoutControl` from
71
+ * awaitery for cooperative cancellation (`control.check()`, `control.signal`,
72
+ * `control.timedOut`, `control.remaining()`).
70
73
  * @template T
71
74
  * @param {string} name - Lock name.
72
- * @param {() => Promise<T>} callback - Callback to invoke while the lock is held.
75
+ * @param {(args?: {control: import("awaitery/build/timeout.js").TimeoutControl}) => Promise<T>} callback - Callback to invoke while the lock is held.
73
76
  * @param {{timeoutMs?: number | null, holdTimeoutMs?: number | null}} [args] - Lock and hold timeout options.
74
77
  * @returns {Promise<T>} - Resolves with the callback result.
75
78
  */
@@ -87,9 +90,11 @@ export default class AdvisoryLockRunner {
87
90
 
88
91
  /**
89
92
  * Runs a callback only if the advisory lock can be acquired immediately.
93
+ * When a `holdTimeoutMs` is set the callback receives a `TimeoutControl` from
94
+ * awaitery for cooperative cancellation.
90
95
  * @template T
91
96
  * @param {string} name - Lock name.
92
- * @param {() => Promise<T>} callback - Callback to invoke while the lock is held.
97
+ * @param {(args?: {control: import("awaitery/build/timeout.js").TimeoutControl}) => Promise<T>} callback - Callback to invoke while the lock is held.
93
98
  * @param {{holdTimeoutMs?: number | null}} [args] - Hold timeout options.
94
99
  * @returns {Promise<T>} - Resolves with the callback result.
95
100
  */
@@ -108,7 +113,7 @@ export default class AdvisoryLockRunner {
108
113
  /**
109
114
  * Runs the lock holder callback and releases the lock from its owning connection.
110
115
  * @template T
111
- * @param {{callback: () => Promise<T>, connection: import("./drivers/base.js").default, holdTimeoutMs?: number | null, name: string}} args - Locked callback args.
116
+ * @param {{callback: (args?: {control: import("awaitery/build/timeout.js").TimeoutControl}) => Promise<T>, connection: import("./drivers/base.js").default, holdTimeoutMs?: number | null, name: string}} args - Locked callback args.
112
117
  * @returns {Promise<T>} - Resolves with the callback result.
113
118
  */
114
119
  async runLockedCallback({callback, connection, holdTimeoutMs, name}) {
@@ -160,9 +165,13 @@ export default class AdvisoryLockRunner {
160
165
  * Runs `callback`, rejecting with `AdvisoryLockHoldTimeoutError` if it has
161
166
  * not settled within `holdTimeoutMs`. The callback is not cancelled; callers
162
167
  * use a dedicated advisory-lock connection so the lock can still be released.
168
+ *
169
+ * The callback receives a `TimeoutControl` from awaitery, enabling cooperative
170
+ * cancellation via `control.check()`, `control.signal`, `control.timedOut`,
171
+ * and `control.remaining()`.
163
172
  * @template T
164
173
  * @param {string} name - Lock name (for the error message).
165
- * @param {() => Promise<T>} callback - Callback holding the lock.
174
+ * @param {(args?: {control: import("awaitery/build/timeout.js").TimeoutControl}) => Promise<T>} callback - Callback holding the lock.
166
175
  * @param {number | null} [holdTimeoutMs] - Max hold time; falsy disables the timeout.
167
176
  * @returns {Promise<T>} - Resolves with the callback result.
168
177
  */
@@ -174,15 +183,15 @@ export default class AdvisoryLockRunner {
174
183
  let callbackSettled = false
175
184
 
176
185
  try {
177
- return await timeout({timeout: holdTimeoutMs}, async () => {
186
+ return await timeout({timeout: holdTimeoutMs}, async ({control}) => {
178
187
  try {
179
- return await callback()
188
+ return await callback({control})
180
189
  } finally {
181
190
  callbackSettled = true
182
191
  }
183
192
  })
184
193
  } catch (error) {
185
- if (!callbackSettled) {
194
+ if (!callbackSettled || error instanceof TimeoutError) {
186
195
  throw new AdvisoryLockHoldTimeoutError(`Advisory lock ${JSON.stringify(name)} held longer than ${holdTimeoutMs}ms`, {name})
187
196
  }
188
197
 
@@ -583,6 +583,18 @@ export default class VelociousDatabaseDriversBase {
583
583
  return null
584
584
  }
585
585
 
586
+ /**
587
+ * Executes a whole multi-statement structure SQL script in a single round-trip when
588
+ * the driver supports it, running on this connection (so the caller's foreign-key
589
+ * handling applies). Returns true if it ran the whole script; false when the caller
590
+ * should run the statements individually. The base driver has no batch path.
591
+ * @param {string} _structureSql - Full multi-statement structure SQL.
592
+ * @returns {Promise<boolean>} - Whether the script was executed as one batch.
593
+ */
594
+ async execStructureScript(_structureSql) {
595
+ return false
596
+ }
597
+
586
598
  /**
587
599
  * Runs get table by name.
588
600
  * @param {string} name - Name.
@@ -23,6 +23,17 @@ import Upsert from "./sql/upsert.js"
23
23
  import Update from "./sql/update.js"
24
24
  import UUID from "pure-uuid"
25
25
 
26
+ /**
27
+ * SQL Server error number raised by `sp_releaseapplock` when the current
28
+ * session does not hold the requested application lock. Releasing a lock the
29
+ * session no longer holds is a normal race (a shared connection's final
30
+ * check-in may already have auto-released it), which the cross-driver
31
+ * `releaseAdvisoryLock` contract models by resolving to `false`. We translate
32
+ * this specific error into that result rather than letting it escape.
33
+ * @type {number}
34
+ */
35
+ const APPLOCK_NOT_HELD_ERROR_NUMBER = 1223
36
+
26
37
  export default class VelociousDatabaseDriversMssql extends Base{
27
38
  async connect() {
28
39
  const args = this.getArgs()
@@ -640,18 +651,56 @@ export default class VelociousDatabaseDriversMssql extends Base{
640
651
 
641
652
  /**
642
653
  * Runs release advisory lock.
654
+ *
655
+ * `sp_releaseapplock` returns 0 when the lock was released, but SQL Server
656
+ * raises error {@link APPLOCK_NOT_HELD_ERROR_NUMBER} instead of returning a
657
+ * failure code when the session does not currently hold the lock. That
658
+ * error aborts the batch before the trailing `SELECT` can run, so we catch
659
+ * it and resolve to `false` to honor the cross-driver contract for an
660
+ * already-unheld lock.
643
661
  * @param {string} name - Lock name.
644
662
  * @returns {Promise<boolean>} - True if the lock was held by this session and has now been released.
645
663
  */
646
664
  async _releaseAdvisoryLock(name) {
647
- const rows = await this.query(
648
- `DECLARE @velocious_advisory_lock_result INT; EXEC @velocious_advisory_lock_result = sp_releaseapplock @Resource = ${this.quote(name)}, @LockOwner = 'Session'; SELECT @velocious_advisory_lock_result AS velocious_advisory_lock_result`
649
- )
665
+ let rows
666
+
667
+ try {
668
+ rows = await this.query(
669
+ `DECLARE @velocious_advisory_lock_result INT; EXEC @velocious_advisory_lock_result = sp_releaseapplock @Resource = ${this.quote(name)}, @LockOwner = 'Session'; SELECT @velocious_advisory_lock_result AS velocious_advisory_lock_result`
670
+ )
671
+ } catch (error) {
672
+ if (this._isApplockNotHeldError(error)) return false
673
+
674
+ throw error
675
+ }
676
+
650
677
  const result = Number(rows?.[0]?.velocious_advisory_lock_result)
651
678
 
652
679
  return result === 0
653
680
  }
654
681
 
682
+ /**
683
+ * Detects the SQL Server "application lock is not currently held" error
684
+ * raised by `sp_releaseapplock`. It walks the wrapped-error cause chain
685
+ * because `query` re-wraps the driver's `RequestError` in a plain `Error`,
686
+ * and matches on the stable numeric error number rather than the message.
687
+ * @param {unknown} error - Error thrown while releasing the lock.
688
+ * @returns {boolean} - True if the error means the lock was not held by this session.
689
+ */
690
+ _isApplockNotHeldError(error) {
691
+ let current = error
692
+
693
+ while (current instanceof Error) {
694
+ const errorNumber = /** @type {{number?: unknown}} */ (current).number
695
+
696
+ if (typeof errorNumber === "number" && errorNumber === APPLOCK_NOT_HELD_ERROR_NUMBER) return true
697
+
698
+ current = current.cause
699
+ }
700
+
701
+ return false
702
+ }
703
+
655
704
  /**
656
705
  * Returns true if any session currently holds the application lock.
657
706
  *