velocious 1.0.460 → 1.0.462
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/README.md +1 -1
- package/build/application.js +1 -3
- package/build/background-jobs/cron-expression.js +1 -3
- package/build/background-jobs/forked-runner-child.js +1 -3
- package/build/background-jobs/job.js +1 -3
- package/build/background-jobs/scheduler.js +2 -6
- package/build/background-jobs/store.js +2 -6
- package/build/background-jobs/web/controller.js +1 -3
- package/build/background-jobs/worker.js +1 -3
- package/build/beacon/client.js +2 -6
- package/build/cli/tenant-database-command-helper.js +1 -3
- package/build/configuration.js +29 -32
- package/build/controller.js +4 -14
- package/build/current.js +2 -2
- package/build/database/drivers/mssql/index.js +1 -3
- package/build/database/drivers/mysql/index.js +2 -6
- package/build/database/drivers/pgsql/index.js +1 -3
- package/build/database/drivers/sqlite/base.js +3 -9
- package/build/database/drivers/sqlite/index.js +3 -9
- package/build/database/drivers/sqlite/table.js +1 -3
- package/build/database/migrator.js +1 -3
- package/build/database/pool/async-tracked-multi-connection.js +20 -45
- package/build/database/pool/base-methods-forward.js +2 -10
- package/build/database/pool/base.js +5 -15
- package/build/database/query/index.js +4 -12
- package/build/database/query/join-object.js +3 -9
- package/build/database/query/model-class-query.js +21 -63
- package/build/database/query/preloader/belongs-to.js +9 -27
- package/build/database/query/preloader/has-many.js +7 -21
- package/build/database/query/preloader/has-one.js +3 -9
- package/build/database/query/preloader.js +6 -18
- package/build/database/query/query-data.js +5 -15
- package/build/database/query/where-model-class-hash.js +5 -15
- package/build/database/query/with-count.js +5 -15
- package/build/database/record/acts-as-list.js +10 -38
- package/build/database/record/attachments/normalize-input.js +7 -25
- package/build/database/record/attachments/storage-drivers/s3.js +4 -12
- package/build/database/record/attachments/store.js +2 -6
- package/build/database/record/index.js +56 -172
- package/build/database/record/instance-relationships/base.js +6 -20
- package/build/database/record/instance-relationships/belongs-to.js +2 -6
- package/build/database/record/instance-relationships/has-many.js +4 -12
- package/build/database/record/instance-relationships/has-one.js +4 -12
- package/build/database/record/relationships/base.js +1 -5
- package/build/database/record/validators/presence.js +1 -3
- package/build/database/record/validators/uniqueness.js +4 -12
- package/build/environment-handlers/browser.js +1 -3
- package/build/environment-handlers/node/cli/commands/console.js +2 -6
- package/build/environment-handlers/node/cli/commands/db/schema/load.js +1 -3
- package/build/environment-handlers/node/cli/commands/generate/frontend-models.js +67 -11
- package/build/environment-handlers/node.js +15 -6
- package/build/frontend-model-controller.js +34 -110
- package/build/frontend-models/base.js +45 -151
- package/build/frontend-models/clear-pending-debounced-callback.js +1 -3
- package/build/frontend-models/preloader.js +3 -9
- package/build/frontend-models/query.js +11 -33
- package/build/frontend-models/resource-definition.js +2 -6
- package/build/frontend-models/transport-serialization.js +7 -21
- package/build/frontend-models/use-destroyed-event.js +2 -6
- package/build/frontend-models/use-model-class-event.js +2 -6
- package/build/frontend-models/use-updated-event.js +3 -9
- package/build/frontend-models/websocket-channel.js +9 -27
- package/build/frontend-models/websocket-publishers.js +12 -23
- package/build/http-server/client/index.js +6 -18
- package/build/http-server/client/params-to-object.js +6 -18
- package/build/http-server/client/request-buffer/index.js +1 -3
- package/build/http-server/client/request-parser.js +1 -3
- package/build/http-server/client/request-runner.js +4 -12
- package/build/http-server/client/websocket-session.js +6 -18
- package/build/http-server/development-reloader.js +2 -6
- package/build/http-server/remote-address.js +1 -5
- package/build/http-server/server-client.js +3 -9
- package/build/http-server/server-lock.js +2 -6
- package/build/http-server/websocket-channel-subscribers.js +2 -6
- package/build/http-server/websocket-event-log-store.js +5 -15
- package/build/http-server/websocket-events-host.js +1 -3
- package/build/http-server/worker-handler/in-process.js +3 -11
- package/build/http-server/worker-handler/worker-thread.js +1 -3
- package/build/logger.js +2 -6
- package/build/mailer/backends/smtp.js +1 -5
- package/build/mailer/base.js +4 -16
- package/build/plugins/sqljs-wasm-route-controller.js +1 -3
- package/build/routes/basic-route.js +1 -3
- package/build/routes/resolver.js +4 -14
- package/build/src/application.d.ts.map +1 -1
- package/build/src/application.js +2 -4
- package/build/src/background-jobs/cron-expression.d.ts.map +1 -1
- package/build/src/background-jobs/cron-expression.js +2 -4
- package/build/src/background-jobs/forked-runner-child.js +2 -4
- package/build/src/background-jobs/job.d.ts.map +1 -1
- package/build/src/background-jobs/job.js +2 -4
- package/build/src/background-jobs/scheduler.d.ts.map +1 -1
- package/build/src/background-jobs/scheduler.js +3 -7
- package/build/src/background-jobs/store.d.ts.map +1 -1
- package/build/src/background-jobs/store.js +3 -7
- package/build/src/background-jobs/web/controller.d.ts.map +1 -1
- package/build/src/background-jobs/web/controller.js +2 -5
- package/build/src/background-jobs/worker.d.ts.map +1 -1
- package/build/src/background-jobs/worker.js +2 -4
- package/build/src/beacon/client.d.ts.map +1 -1
- package/build/src/beacon/client.js +3 -7
- package/build/src/cli/tenant-database-command-helper.d.ts.map +1 -1
- package/build/src/cli/tenant-database-command-helper.js +2 -4
- package/build/src/configuration.d.ts.map +1 -1
- package/build/src/configuration.js +27 -35
- package/build/src/controller.d.ts.map +1 -1
- package/build/src/controller.js +5 -15
- package/build/src/current.d.ts +4 -4
- package/build/src/current.d.ts.map +1 -1
- package/build/src/current.js +3 -3
- package/build/src/database/drivers/mssql/index.d.ts.map +1 -1
- package/build/src/database/drivers/mssql/index.js +2 -4
- package/build/src/database/drivers/mysql/index.d.ts.map +1 -1
- package/build/src/database/drivers/mysql/index.js +3 -7
- package/build/src/database/drivers/pgsql/index.d.ts.map +1 -1
- package/build/src/database/drivers/pgsql/index.js +2 -4
- package/build/src/database/drivers/sqlite/base.d.ts.map +1 -1
- package/build/src/database/drivers/sqlite/base.js +4 -10
- package/build/src/database/drivers/sqlite/index.d.ts.map +1 -1
- package/build/src/database/drivers/sqlite/index.js +4 -10
- package/build/src/database/drivers/sqlite/table.d.ts.map +1 -1
- package/build/src/database/drivers/sqlite/table.js +2 -4
- package/build/src/database/migrator.d.ts.map +1 -1
- package/build/src/database/migrator.js +2 -4
- package/build/src/database/pool/async-tracked-multi-connection.d.ts.map +1 -1
- package/build/src/database/pool/async-tracked-multi-connection.js +21 -47
- package/build/src/database/pool/base-methods-forward.d.ts.map +1 -1
- package/build/src/database/pool/base-methods-forward.js +3 -11
- package/build/src/database/pool/base.d.ts.map +1 -1
- package/build/src/database/pool/base.js +6 -16
- package/build/src/database/query/index.d.ts.map +1 -1
- package/build/src/database/query/index.js +5 -13
- package/build/src/database/query/join-object.d.ts.map +1 -1
- package/build/src/database/query/join-object.js +4 -10
- package/build/src/database/query/model-class-query.d.ts.map +1 -1
- package/build/src/database/query/model-class-query.js +22 -64
- package/build/src/database/query/preloader/belongs-to.d.ts.map +1 -1
- package/build/src/database/query/preloader/belongs-to.js +10 -28
- package/build/src/database/query/preloader/has-many.d.ts.map +1 -1
- package/build/src/database/query/preloader/has-many.js +8 -22
- package/build/src/database/query/preloader/has-one.d.ts.map +1 -1
- package/build/src/database/query/preloader/has-one.js +4 -10
- package/build/src/database/query/preloader.d.ts.map +1 -1
- package/build/src/database/query/preloader.js +7 -20
- package/build/src/database/query/query-data.d.ts.map +1 -1
- package/build/src/database/query/query-data.js +6 -16
- package/build/src/database/query/where-model-class-hash.d.ts.map +1 -1
- package/build/src/database/query/where-model-class-hash.js +6 -16
- package/build/src/database/query/with-count.d.ts.map +1 -1
- package/build/src/database/query/with-count.js +6 -17
- package/build/src/database/record/acts-as-list.d.ts.map +1 -1
- package/build/src/database/record/acts-as-list.js +11 -47
- package/build/src/database/record/attachments/normalize-input.d.ts.map +1 -1
- package/build/src/database/record/attachments/normalize-input.js +8 -30
- package/build/src/database/record/attachments/storage-drivers/s3.d.ts.map +1 -1
- package/build/src/database/record/attachments/storage-drivers/s3.js +5 -13
- package/build/src/database/record/attachments/store.d.ts.map +1 -1
- package/build/src/database/record/attachments/store.js +3 -7
- package/build/src/database/record/index.d.ts +6 -11
- package/build/src/database/record/index.d.ts.map +1 -1
- package/build/src/database/record/index.js +54 -174
- package/build/src/database/record/instance-relationships/base.d.ts.map +1 -1
- package/build/src/database/record/instance-relationships/base.js +7 -21
- package/build/src/database/record/instance-relationships/belongs-to.d.ts.map +1 -1
- package/build/src/database/record/instance-relationships/belongs-to.js +3 -7
- package/build/src/database/record/instance-relationships/has-many.d.ts.map +1 -1
- package/build/src/database/record/instance-relationships/has-many.js +5 -13
- package/build/src/database/record/instance-relationships/has-one.d.ts.map +1 -1
- package/build/src/database/record/instance-relationships/has-one.js +5 -13
- package/build/src/database/record/relationships/base.d.ts.map +1 -1
- package/build/src/database/record/relationships/base.js +2 -6
- package/build/src/database/record/validators/presence.d.ts.map +1 -1
- package/build/src/database/record/validators/presence.js +2 -4
- package/build/src/database/record/validators/uniqueness.d.ts.map +1 -1
- package/build/src/database/record/validators/uniqueness.js +5 -14
- package/build/src/environment-handlers/browser.d.ts.map +1 -1
- package/build/src/environment-handlers/browser.js +2 -4
- package/build/src/environment-handlers/node/cli/commands/console.d.ts.map +1 -1
- package/build/src/environment-handlers/node/cli/commands/console.js +3 -7
- package/build/src/environment-handlers/node/cli/commands/db/schema/load.d.ts.map +1 -1
- package/build/src/environment-handlers/node/cli/commands/db/schema/load.js +2 -4
- package/build/src/environment-handlers/node/cli/commands/generate/frontend-models.d.ts +38 -0
- package/build/src/environment-handlers/node/cli/commands/generate/frontend-models.d.ts.map +1 -1
- package/build/src/environment-handlers/node/cli/commands/generate/frontend-models.js +58 -12
- package/build/src/environment-handlers/node.d.ts.map +1 -1
- package/build/src/environment-handlers/node.js +16 -7
- package/build/src/frontend-model-controller.d.ts.map +1 -1
- package/build/src/frontend-model-controller.js +35 -114
- package/build/src/frontend-models/base.d.ts.map +1 -1
- package/build/src/frontend-models/base.js +46 -158
- package/build/src/frontend-models/clear-pending-debounced-callback.d.ts.map +1 -1
- package/build/src/frontend-models/clear-pending-debounced-callback.js +2 -4
- package/build/src/frontend-models/preloader.d.ts.map +1 -1
- package/build/src/frontend-models/preloader.js +4 -11
- package/build/src/frontend-models/query.d.ts.map +1 -1
- package/build/src/frontend-models/query.js +12 -34
- package/build/src/frontend-models/resource-definition.d.ts.map +1 -1
- package/build/src/frontend-models/resource-definition.js +3 -7
- package/build/src/frontend-models/transport-serialization.d.ts.map +1 -1
- package/build/src/frontend-models/transport-serialization.js +8 -23
- package/build/src/frontend-models/use-destroyed-event.js +3 -7
- package/build/src/frontend-models/use-model-class-event.d.ts.map +1 -1
- package/build/src/frontend-models/use-model-class-event.js +3 -7
- package/build/src/frontend-models/use-updated-event.d.ts.map +1 -1
- package/build/src/frontend-models/use-updated-event.js +4 -10
- package/build/src/frontend-models/websocket-channel.d.ts.map +1 -1
- package/build/src/frontend-models/websocket-channel.js +10 -32
- package/build/src/frontend-models/websocket-publishers.d.ts.map +1 -1
- package/build/src/frontend-models/websocket-publishers.js +14 -25
- package/build/src/http-server/client/index.d.ts.map +1 -1
- package/build/src/http-server/client/index.js +7 -21
- package/build/src/http-server/client/params-to-object.d.ts.map +1 -1
- package/build/src/http-server/client/params-to-object.js +7 -21
- package/build/src/http-server/client/request-buffer/index.d.ts.map +1 -1
- package/build/src/http-server/client/request-buffer/index.js +2 -4
- package/build/src/http-server/client/request-parser.d.ts.map +1 -1
- package/build/src/http-server/client/request-parser.js +2 -4
- package/build/src/http-server/client/request-runner.d.ts.map +1 -1
- package/build/src/http-server/client/request-runner.js +5 -14
- package/build/src/http-server/client/websocket-session.d.ts.map +1 -1
- package/build/src/http-server/client/websocket-session.js +7 -20
- package/build/src/http-server/development-reloader.d.ts.map +1 -1
- package/build/src/http-server/development-reloader.js +3 -7
- package/build/src/http-server/remote-address.d.ts.map +1 -1
- package/build/src/http-server/remote-address.js +2 -6
- package/build/src/http-server/server-client.d.ts.map +1 -1
- package/build/src/http-server/server-client.js +4 -10
- package/build/src/http-server/server-lock.d.ts.map +1 -1
- package/build/src/http-server/server-lock.js +3 -7
- package/build/src/http-server/websocket-channel-subscribers.d.ts.map +1 -1
- package/build/src/http-server/websocket-channel-subscribers.js +3 -7
- package/build/src/http-server/websocket-event-log-store.d.ts.map +1 -1
- package/build/src/http-server/websocket-event-log-store.js +6 -16
- package/build/src/http-server/websocket-events-host.d.ts.map +1 -1
- package/build/src/http-server/websocket-events-host.js +2 -5
- package/build/src/http-server/worker-handler/in-process.d.ts.map +1 -1
- package/build/src/http-server/worker-handler/in-process.js +4 -12
- package/build/src/http-server/worker-handler/worker-thread.d.ts.map +1 -1
- package/build/src/http-server/worker-handler/worker-thread.js +2 -4
- package/build/src/logger.d.ts.map +1 -1
- package/build/src/logger.js +3 -7
- package/build/src/mailer/backends/smtp.d.ts.map +1 -1
- package/build/src/mailer/backends/smtp.js +2 -6
- package/build/src/mailer/base.d.ts.map +1 -1
- package/build/src/mailer/base.js +5 -17
- package/build/src/plugins/sqljs-wasm-route-controller.d.ts.map +1 -1
- package/build/src/plugins/sqljs-wasm-route-controller.js +2 -4
- package/build/src/routes/basic-route.d.ts.map +1 -1
- package/build/src/routes/basic-route.js +2 -4
- package/build/src/routes/resolver.d.ts.map +1 -1
- package/build/src/routes/resolver.js +5 -15
- package/build/src/testing/expect-utils.d.ts.map +1 -1
- package/build/src/testing/expect-utils.js +9 -27
- package/build/src/testing/expect.d.ts.map +1 -1
- package/build/src/testing/expect.js +5 -15
- package/build/src/testing/test-runner.d.ts.map +1 -1
- package/build/src/testing/test-runner.js +4 -10
- package/build/src/testing/test.d.ts.map +1 -1
- package/build/src/testing/test.js +5 -17
- package/build/src/utils/model-scope.d.ts.map +1 -1
- package/build/src/utils/model-scope.js +2 -5
- package/build/src/utils/ransack.d.ts.map +1 -1
- package/build/src/utils/ransack.js +15 -42
- package/build/src/utils/with-tracked-stack-async-hooks.d.ts.map +1 -1
- package/build/src/utils/with-tracked-stack-async-hooks.js +4 -12
- package/build/src/utils/with-tracked-stack.d.ts.map +1 -1
- package/build/src/utils/with-tracked-stack.js +3 -8
- package/build/testing/expect-utils.js +8 -26
- package/build/testing/expect.js +4 -14
- package/build/testing/test-runner.js +3 -9
- package/build/testing/test.js +4 -12
- package/build/utils/model-scope.js +1 -3
- package/build/utils/ransack.js +15 -41
- package/build/utils/with-tracked-stack-async-hooks.js +3 -9
- package/build/utils/with-tracked-stack.js +2 -6
- package/package.json +3 -2
- package/src/application.js +1 -3
- package/src/background-jobs/cron-expression.js +1 -3
- package/src/background-jobs/forked-runner-child.js +1 -3
- package/src/background-jobs/job.js +1 -3
- package/src/background-jobs/scheduler.js +2 -6
- package/src/background-jobs/store.js +2 -6
- package/src/background-jobs/web/controller.js +1 -3
- package/src/background-jobs/worker.js +1 -3
- package/src/beacon/client.js +2 -6
- package/src/cli/tenant-database-command-helper.js +1 -3
- package/src/configuration.js +29 -32
- package/src/controller.js +4 -14
- package/src/current.js +2 -2
- package/src/database/drivers/mssql/index.js +1 -3
- package/src/database/drivers/mysql/index.js +2 -6
- package/src/database/drivers/pgsql/index.js +1 -3
- package/src/database/drivers/sqlite/base.js +3 -9
- package/src/database/drivers/sqlite/index.js +3 -9
- package/src/database/drivers/sqlite/table.js +1 -3
- package/src/database/migrator.js +1 -3
- package/src/database/pool/async-tracked-multi-connection.js +20 -45
- package/src/database/pool/base-methods-forward.js +2 -10
- package/src/database/pool/base.js +5 -15
- package/src/database/query/index.js +4 -12
- package/src/database/query/join-object.js +3 -9
- package/src/database/query/model-class-query.js +21 -63
- package/src/database/query/preloader/belongs-to.js +9 -27
- package/src/database/query/preloader/has-many.js +7 -21
- package/src/database/query/preloader/has-one.js +3 -9
- package/src/database/query/preloader.js +6 -18
- package/src/database/query/query-data.js +5 -15
- package/src/database/query/where-model-class-hash.js +5 -15
- package/src/database/query/with-count.js +5 -15
- package/src/database/record/acts-as-list.js +10 -38
- package/src/database/record/attachments/normalize-input.js +7 -25
- package/src/database/record/attachments/storage-drivers/s3.js +4 -12
- package/src/database/record/attachments/store.js +2 -6
- package/src/database/record/index.js +56 -172
- package/src/database/record/instance-relationships/base.js +6 -20
- package/src/database/record/instance-relationships/belongs-to.js +2 -6
- package/src/database/record/instance-relationships/has-many.js +4 -12
- package/src/database/record/instance-relationships/has-one.js +4 -12
- package/src/database/record/relationships/base.js +1 -5
- package/src/database/record/validators/presence.js +1 -3
- package/src/database/record/validators/uniqueness.js +4 -12
- package/src/environment-handlers/browser.js +1 -3
- package/src/environment-handlers/node/cli/commands/console.js +2 -6
- package/src/environment-handlers/node/cli/commands/db/schema/load.js +1 -3
- package/src/environment-handlers/node/cli/commands/generate/frontend-models.js +67 -11
- package/src/environment-handlers/node.js +15 -6
- package/src/frontend-model-controller.js +34 -110
- package/src/frontend-models/base.js +45 -151
- package/src/frontend-models/clear-pending-debounced-callback.js +1 -3
- package/src/frontend-models/preloader.js +3 -9
- package/src/frontend-models/query.js +11 -33
- package/src/frontend-models/resource-definition.js +2 -6
- package/src/frontend-models/transport-serialization.js +7 -21
- package/src/frontend-models/use-destroyed-event.js +2 -6
- package/src/frontend-models/use-model-class-event.js +2 -6
- package/src/frontend-models/use-updated-event.js +3 -9
- package/src/frontend-models/websocket-channel.js +9 -27
- package/src/frontend-models/websocket-publishers.js +12 -23
- package/src/http-server/client/index.js +6 -18
- package/src/http-server/client/params-to-object.js +6 -18
- package/src/http-server/client/request-buffer/index.js +1 -3
- package/src/http-server/client/request-parser.js +1 -3
- package/src/http-server/client/request-runner.js +4 -12
- package/src/http-server/client/websocket-session.js +6 -18
- package/src/http-server/development-reloader.js +2 -6
- package/src/http-server/remote-address.js +1 -5
- package/src/http-server/server-client.js +3 -9
- package/src/http-server/server-lock.js +2 -6
- package/src/http-server/websocket-channel-subscribers.js +2 -6
- package/src/http-server/websocket-event-log-store.js +5 -15
- package/src/http-server/websocket-events-host.js +1 -3
- package/src/http-server/worker-handler/in-process.js +3 -11
- package/src/http-server/worker-handler/worker-thread.js +1 -3
- package/src/logger.js +2 -6
- package/src/mailer/backends/smtp.js +1 -5
- package/src/mailer/base.js +4 -16
- package/src/plugins/sqljs-wasm-route-controller.js +1 -3
- package/src/routes/basic-route.js +1 -3
- package/src/routes/resolver.js +4 -14
- package/src/testing/expect-utils.js +8 -26
- package/src/testing/expect.js +4 -14
- package/src/testing/test-runner.js +3 -9
- package/src/testing/test.js +4 -12
- package/src/utils/model-scope.js +1 -3
- package/src/utils/ransack.js +15 -41
- package/src/utils/with-tracked-stack-async-hooks.js +3 -9
- package/src/utils/with-tracked-stack.js +2 -6
|
@@ -216,9 +216,7 @@ export default class VelociousDatabaseQueryModelClassQuery extends DatabaseQuery
|
|
|
216
216
|
* @returns {this} - The clone.
|
|
217
217
|
*/
|
|
218
218
|
clone() {
|
|
219
|
-
const newQuery = /**
|
|
220
|
-
* Narrows the runtime value to the documented type.
|
|
221
|
-
* @type {VelociousDatabaseQueryModelClassQuery<MC>} */ (new VelociousDatabaseQueryModelClassQuery({
|
|
219
|
+
const newQuery = /** @type {VelociousDatabaseQueryModelClassQuery<MC>} */ (new VelociousDatabaseQueryModelClassQuery({
|
|
222
220
|
driver: this._driverFn,
|
|
223
221
|
froms: [...this._froms],
|
|
224
222
|
handler: this.handler.clone(),
|
|
@@ -338,9 +336,7 @@ export default class VelociousDatabaseQueryModelClassQuery extends DatabaseQuery
|
|
|
338
336
|
countQuery._selects = []
|
|
339
337
|
countQuery.select(sql)
|
|
340
338
|
|
|
341
|
-
const results = /**
|
|
342
|
-
* Narrows the runtime value to the documented type.
|
|
343
|
-
* @type {{count: number}[]} */ (await countQuery._executeQuery({
|
|
339
|
+
const results = /** @type {{count: number}[]} */ (await countQuery._executeQuery({
|
|
344
340
|
logName: countQuery.queryLogName("Count")
|
|
345
341
|
}))
|
|
346
342
|
|
|
@@ -374,9 +370,7 @@ export default class VelociousDatabaseQueryModelClassQuery extends DatabaseQuery
|
|
|
374
370
|
`SELECT ${countSql} AS ${this.driver.quoteColumn("count")}`,
|
|
375
371
|
`FROM (${countQuery.toSql()}) AS ${this.driver.quoteTable("paginated_count_rows")}`
|
|
376
372
|
].join(" ")
|
|
377
|
-
const results = /**
|
|
378
|
-
* Narrows the runtime value to the documented type.
|
|
379
|
-
* @type {{count: number}[]} */ (await this.driver.query(
|
|
373
|
+
const results = /** @type {{count: number}[]} */ (await this.driver.query(
|
|
380
374
|
sql,
|
|
381
375
|
{logName: this.queryLogName("Count")}
|
|
382
376
|
))
|
|
@@ -470,18 +464,12 @@ export default class VelociousDatabaseQueryModelClassQuery extends DatabaseQuery
|
|
|
470
464
|
const froms = this.getFroms()
|
|
471
465
|
const lastFrom = froms[froms.length - 1]
|
|
472
466
|
|
|
473
|
-
if (lastFrom && typeof /**
|
|
474
|
-
* Narrows the runtime value to the documented type.
|
|
475
|
-
* @type {?} */ (lastFrom).tableName === "string") {
|
|
467
|
+
if (lastFrom && typeof /** @type {?} */ (lastFrom).tableName === "string") {
|
|
476
468
|
return /** @type {?} */ (lastFrom).tableName
|
|
477
469
|
}
|
|
478
470
|
|
|
479
|
-
if (lastFrom && typeof /**
|
|
480
|
-
|
|
481
|
-
* @type {?} */ (lastFrom).plain === "string") {
|
|
482
|
-
const parsedReference = parseFromPlainTableReference(/**
|
|
483
|
-
* Narrows the runtime value to the documented type.
|
|
484
|
-
* @type {?} */ (lastFrom).plain)
|
|
471
|
+
if (lastFrom && typeof /** @type {?} */ (lastFrom).plain === "string") {
|
|
472
|
+
const parsedReference = parseFromPlainTableReference(/** @type {?} */ (lastFrom).plain)
|
|
485
473
|
|
|
486
474
|
if (parsedReference) return parsedReference
|
|
487
475
|
}
|
|
@@ -539,9 +527,7 @@ export default class VelociousDatabaseQueryModelClassQuery extends DatabaseQuery
|
|
|
539
527
|
* @returns {VelociousDatabaseQueryModelClassQuery<MC>} - The scoped query.
|
|
540
528
|
*/
|
|
541
529
|
withJoinPath(joinBasePath) {
|
|
542
|
-
const scopedQuery = /**
|
|
543
|
-
* Narrows the runtime value to the documented type.
|
|
544
|
-
* @type {VelociousDatabaseQueryModelClassQuery<MC>} */ (this.clone())
|
|
530
|
+
const scopedQuery = /** @type {VelociousDatabaseQueryModelClassQuery<MC>} */ (this.clone())
|
|
545
531
|
|
|
546
532
|
scopedQuery._joinBasePath = joinBasePath
|
|
547
533
|
scopedQuery._joinTracker = this._joinTracker
|
|
@@ -638,9 +624,7 @@ export default class VelociousDatabaseQueryModelClassQuery extends DatabaseQuery
|
|
|
638
624
|
}
|
|
639
625
|
|
|
640
626
|
return this._applyJoinPathScope({
|
|
641
|
-
joinPath: normalizeScopePath(/**
|
|
642
|
-
* Narrows the runtime value to the documented type.
|
|
643
|
-
* @type {string | string[]} */ (pathOrScopeDescriptor)),
|
|
627
|
+
joinPath: normalizeScopePath(/** @type {string | string[]} */ (pathOrScopeDescriptor)),
|
|
644
628
|
scopeDescriptor: maybeScopeDescriptor
|
|
645
629
|
})
|
|
646
630
|
}
|
|
@@ -659,9 +643,7 @@ export default class VelociousDatabaseQueryModelClassQuery extends DatabaseQuery
|
|
|
659
643
|
throw new Error(`Cannot apply ${scopeDescriptor.modelClass.name} scope to ${this.getModelClass().name} query`)
|
|
660
644
|
}
|
|
661
645
|
|
|
662
|
-
const scopedQuery = /**
|
|
663
|
-
* Narrows the runtime value to the documented type.
|
|
664
|
-
* @type {this | void} */ (scopeDescriptor.callback({
|
|
646
|
+
const scopedQuery = /** @type {this | void} */ (scopeDescriptor.callback({
|
|
665
647
|
driver: this.driver,
|
|
666
648
|
modelClass: this.getModelClass(),
|
|
667
649
|
query: this,
|
|
@@ -693,9 +675,7 @@ export default class VelociousDatabaseQueryModelClassQuery extends DatabaseQuery
|
|
|
693
675
|
const scopedQuery = this.buildJoinScopeQuery(targetModelClass, fullJoinPath)
|
|
694
676
|
const originalJoinCount = scopedQuery._joins.length
|
|
695
677
|
const originalWhereCount = scopedQuery._wheres.length
|
|
696
|
-
const appliedQuery = /**
|
|
697
|
-
* Narrows the runtime value to the documented type.
|
|
698
|
-
* @type {typeof scopedQuery | void} */ (scopeDescriptor.callback({
|
|
678
|
+
const appliedQuery = /** @type {typeof scopedQuery | void} */ (scopeDescriptor.callback({
|
|
699
679
|
driver: scopedQuery.driver,
|
|
700
680
|
modelClass: targetModelClass,
|
|
701
681
|
path: [...fullJoinPath],
|
|
@@ -742,9 +722,7 @@ export default class VelociousDatabaseQueryModelClassQuery extends DatabaseQuery
|
|
|
742
722
|
* @returns {VelociousDatabaseQueryModelClassQuery<MC>} - The scoped join query.
|
|
743
723
|
*/
|
|
744
724
|
buildJoinScopeQuery(targetModelClass, joinPath) {
|
|
745
|
-
const scopedQuery = /**
|
|
746
|
-
* Narrows the runtime value to the documented type.
|
|
747
|
-
* @type {VelociousDatabaseQueryModelClassQuery<MC>} */ (targetModelClass._newQuery())
|
|
725
|
+
const scopedQuery = /** @type {VelociousDatabaseQueryModelClassQuery<MC>} */ (targetModelClass._newQuery())
|
|
748
726
|
|
|
749
727
|
scopedQuery._joinTracker = this._joinTracker
|
|
750
728
|
scopedQuery._joinBasePath = joinPath
|
|
@@ -817,9 +795,7 @@ export default class VelociousDatabaseQueryModelClassQuery extends DatabaseQuery
|
|
|
817
795
|
|
|
818
796
|
conditions[this.getModelClass().primaryKey()] = recordId
|
|
819
797
|
|
|
820
|
-
const newQuery = /**
|
|
821
|
-
* Narrows the runtime value to the documented type.
|
|
822
|
-
* @type {VelociousDatabaseQueryModelClassQuery<MC>} */ (this.clone())
|
|
798
|
+
const newQuery = /** @type {VelociousDatabaseQueryModelClassQuery<MC>} */ (this.clone())
|
|
823
799
|
|
|
824
800
|
newQuery.where(conditions)
|
|
825
801
|
|
|
@@ -838,9 +814,7 @@ export default class VelociousDatabaseQueryModelClassQuery extends DatabaseQuery
|
|
|
838
814
|
* @returns {Promise<InstanceType<MC> | null>} - Resolves with the by.
|
|
839
815
|
*/
|
|
840
816
|
async findBy(conditions) {
|
|
841
|
-
const newQuery = /**
|
|
842
|
-
* Narrows the runtime value to the documented type.
|
|
843
|
-
* @type {VelociousDatabaseQueryModelClassQuery<MC>} */ (this.clone())
|
|
817
|
+
const newQuery = /** @type {VelociousDatabaseQueryModelClassQuery<MC>} */ (this.clone())
|
|
844
818
|
|
|
845
819
|
newQuery.where(conditions)
|
|
846
820
|
|
|
@@ -890,9 +864,7 @@ export default class VelociousDatabaseQueryModelClassQuery extends DatabaseQuery
|
|
|
890
864
|
if (record) return record
|
|
891
865
|
|
|
892
866
|
const ModelClass = this.getModelClass()
|
|
893
|
-
const newRecord = /**
|
|
894
|
-
* Narrows the runtime value to the documented type.
|
|
895
|
-
* @type {InstanceType<MC>} */ (new ModelClass(conditions))
|
|
867
|
+
const newRecord = /** @type {InstanceType<MC>} */ (new ModelClass(conditions))
|
|
896
868
|
|
|
897
869
|
if (callback) {
|
|
898
870
|
callback(newRecord)
|
|
@@ -945,9 +917,7 @@ export default class VelociousDatabaseQueryModelClassQuery extends DatabaseQuery
|
|
|
945
917
|
|
|
946
918
|
for (const result of results) {
|
|
947
919
|
const ModelClass = this.getModelClass()
|
|
948
|
-
const model = /**
|
|
949
|
-
* Narrows the runtime value to the documented type.
|
|
950
|
-
* @type {InstanceType<MC>} */ (new ModelClass())
|
|
920
|
+
const model = /** @type {InstanceType<MC>} */ (new ModelClass())
|
|
951
921
|
|
|
952
922
|
model.loadExistingRecord(result)
|
|
953
923
|
models.push(model)
|
|
@@ -1013,9 +983,7 @@ export default class VelociousDatabaseQueryModelClassQuery extends DatabaseQuery
|
|
|
1013
983
|
const attributeMap = modelClass.getAttributeNameToColumnNameMap()
|
|
1014
984
|
const columnNames = flatColumns.map((column) => attributeMap[column] || column)
|
|
1015
985
|
|
|
1016
|
-
const query = /**
|
|
1017
|
-
* Narrows the runtime value to the documented type.
|
|
1018
|
-
* @type {VelociousDatabaseQueryModelClassQuery<MC>} */ (this.clone())
|
|
986
|
+
const query = /** @type {VelociousDatabaseQueryModelClassQuery<MC>} */ (this.clone())
|
|
1019
987
|
|
|
1020
988
|
query._preload = {}
|
|
1021
989
|
query._selects = []
|
|
@@ -1030,15 +998,11 @@ export default class VelociousDatabaseQueryModelClassQuery extends DatabaseQuery
|
|
|
1030
998
|
|
|
1031
999
|
if (columnNames.length === 1) {
|
|
1032
1000
|
const [columnName] = columnNames
|
|
1033
|
-
return rows.map((row) => /**
|
|
1034
|
-
* Narrows the runtime value to the documented type.
|
|
1035
|
-
* @type {Record<string, ?>} */ (row)[columnName])
|
|
1001
|
+
return rows.map((row) => /** @type {Record<string, ?>} */ (row)[columnName])
|
|
1036
1002
|
}
|
|
1037
1003
|
|
|
1038
1004
|
return rows.map((row) => {
|
|
1039
|
-
const rowHash = /**
|
|
1040
|
-
* Narrows the runtime value to the documented type.
|
|
1041
|
-
* @type {Record<string, ?>} */ (row)
|
|
1005
|
+
const rowHash = /** @type {Record<string, ?>} */ (row)
|
|
1042
1006
|
|
|
1043
1007
|
return columnNames.map((columnName) => rowHash[columnName])
|
|
1044
1008
|
})
|
|
@@ -1496,9 +1460,7 @@ function normalizeRelationshipWhereOperator(operator) {
|
|
|
1496
1460
|
}
|
|
1497
1461
|
|
|
1498
1462
|
return /** @type {"eq" | "notEq" | "gt" | "gteq" | "lt" | "lteq" | "like"} */ (
|
|
1499
|
-
operatorAliases[/**
|
|
1500
|
-
* Narrows the runtime value to the documented type.
|
|
1501
|
-
* @type {"<" | "<=" | ">" | ">="} */ (operator)] || operator
|
|
1463
|
+
operatorAliases[/** @type {"<" | "<=" | ">" | ">="} */ (operator)] || operator
|
|
1502
1464
|
)
|
|
1503
1465
|
}
|
|
1504
1466
|
|
|
@@ -1537,9 +1499,7 @@ function normalizeRelationshipWhereOperatorTuples(value) {
|
|
|
1537
1499
|
*/
|
|
1538
1500
|
const addCondition = (conditionValue) => {
|
|
1539
1501
|
if (isRelationshipWhereOperatorTuple(conditionValue)) {
|
|
1540
|
-
const tuple = /**
|
|
1541
|
-
* Narrows the runtime value to the documented type.
|
|
1542
|
-
* @type {[string, "eq" | "notEq" | "gt" | "gteq" | "lt" | "lteq" | "like" | ">" | ">=" | "<" | "<=", unknown, ...Array<unknown>]} */ (conditionValue)
|
|
1502
|
+
const tuple = /** @type {[string, "eq" | "notEq" | "gt" | "gteq" | "lt" | "lteq" | "like" | ">" | ">=" | "<" | "<=", unknown, ...Array<unknown>]} */ (conditionValue)
|
|
1543
1503
|
const normalizedOperator = normalizeRelationshipWhereOperator(tuple[1])
|
|
1544
1504
|
|
|
1545
1505
|
normalized.push([
|
|
@@ -1561,9 +1521,7 @@ function normalizeRelationshipWhereOperatorTuples(value) {
|
|
|
1561
1521
|
throw new Error("Relationship where conditions must be tuples")
|
|
1562
1522
|
}
|
|
1563
1523
|
|
|
1564
|
-
/**
|
|
1565
|
-
* Narrows the runtime value to the documented type.
|
|
1566
|
-
* @type {Array<?>} */ (conditionValue).forEach((nestedConditionValue) => {
|
|
1524
|
+
/** @type {Array<?>} */ (conditionValue).forEach((nestedConditionValue) => {
|
|
1567
1525
|
addCondition(nestedConditionValue)
|
|
1568
1526
|
})
|
|
1569
1527
|
}
|
|
@@ -46,9 +46,7 @@ export default class VelociousDatabaseQueryPreloaderBelongsTo {
|
|
|
46
46
|
const instanceRelationship = model.getRelationshipByName(relationshipName)
|
|
47
47
|
|
|
48
48
|
if (this.selection.isSatisfied({instanceRelationship, targetModelClass, mappingColumns: [primaryKey]})) {
|
|
49
|
-
const loaded = /**
|
|
50
|
-
* Narrows the runtime value to the documented type.
|
|
51
|
-
* @type {import("../../record/index.js").default | undefined} */ (instanceRelationship.getLoadedOrUndefined())
|
|
49
|
+
const loaded = /** @type {import("../../record/index.js").default | undefined} */ (instanceRelationship.getLoadedOrUndefined())
|
|
52
50
|
|
|
53
51
|
if (loaded) satisfiedTargets.push(loaded)
|
|
54
52
|
} else {
|
|
@@ -64,9 +62,7 @@ export default class VelociousDatabaseQueryPreloaderBelongsTo {
|
|
|
64
62
|
const foreignKeyValues = []
|
|
65
63
|
|
|
66
64
|
for (const model of modelsToLoad) {
|
|
67
|
-
const foreignKeyValue = /**
|
|
68
|
-
* Narrows the runtime value to the documented type.
|
|
69
|
-
* @type {string | number | null | undefined} */ (model.readColumn(foreignKey))
|
|
65
|
+
const foreignKeyValue = /** @type {string | number | null | undefined} */ (model.readColumn(foreignKey))
|
|
70
66
|
|
|
71
67
|
// Skip null/undefined foreign keys: a belongsTo with no foreign key has no
|
|
72
68
|
// target, and including them would serialize to e.g. `IN (null)` which
|
|
@@ -106,9 +102,7 @@ export default class VelociousDatabaseQueryPreloaderBelongsTo {
|
|
|
106
102
|
targetModels = await query.toArray()
|
|
107
103
|
|
|
108
104
|
for (const targetModel of targetModels) {
|
|
109
|
-
const primaryKeyValue = /**
|
|
110
|
-
* Narrows the runtime value to the documented type.
|
|
111
|
-
* @type {string | number} */ (targetModel.readColumn(primaryKey))
|
|
105
|
+
const primaryKeyValue = /** @type {string | number} */ (targetModel.readColumn(primaryKey))
|
|
112
106
|
|
|
113
107
|
targetModelsById[primaryKeyValue] = targetModel
|
|
114
108
|
}
|
|
@@ -116,9 +110,7 @@ export default class VelociousDatabaseQueryPreloaderBelongsTo {
|
|
|
116
110
|
|
|
117
111
|
// Set the target preloaded models on the given models
|
|
118
112
|
for (const model of modelsToLoad) {
|
|
119
|
-
const foreignKeyValue = /**
|
|
120
|
-
* Narrows the runtime value to the documented type.
|
|
121
|
-
* @type {string | number} */ (model.readColumn(foreignKey))
|
|
113
|
+
const foreignKeyValue = /** @type {string | number} */ (model.readColumn(foreignKey))
|
|
122
114
|
const targetModel = targetModelsById[foreignKeyValue]
|
|
123
115
|
const modelRelationship = model.getRelationshipByName(relationshipName)
|
|
124
116
|
|
|
@@ -158,23 +150,17 @@ export default class VelociousDatabaseQueryPreloaderBelongsTo {
|
|
|
158
150
|
const targetModelsByClassName = {}
|
|
159
151
|
|
|
160
152
|
for (const model of this.models) {
|
|
161
|
-
const targetType = /**
|
|
162
|
-
* Narrows the runtime value to the documented type.
|
|
163
|
-
* @type {string | undefined} */ (model.readColumn(typeColumn))
|
|
153
|
+
const targetType = /** @type {string | undefined} */ (model.readColumn(typeColumn))
|
|
164
154
|
const instanceRelationship = model.getRelationshipByName(relationshipName)
|
|
165
155
|
const targetModelClass = targetType ? configuration.getModelClass(targetType) : undefined
|
|
166
156
|
|
|
167
157
|
if (targetModelClass && this.selection.isSatisfied({instanceRelationship, targetModelClass, mappingColumns: [primaryKey]})) {
|
|
168
|
-
const loaded = /**
|
|
169
|
-
* Narrows the runtime value to the documented type.
|
|
170
|
-
* @type {import("../../record/index.js").default | undefined} */ (instanceRelationship.getLoadedOrUndefined())
|
|
158
|
+
const loaded = /** @type {import("../../record/index.js").default | undefined} */ (instanceRelationship.getLoadedOrUndefined())
|
|
171
159
|
|
|
172
160
|
if (loaded) {
|
|
173
161
|
satisfiedTargets.push(loaded)
|
|
174
162
|
|
|
175
|
-
const className = /**
|
|
176
|
-
* Narrows the runtime value to the documented type.
|
|
177
|
-
* @type {typeof import("../../record/index.js").default} */ (loaded.constructor).getModelName()
|
|
163
|
+
const className = /** @type {typeof import("../../record/index.js").default} */ (loaded.constructor).getModelName()
|
|
178
164
|
|
|
179
165
|
if (!targetModelsByClassName[className]) targetModelsByClassName[className] = []
|
|
180
166
|
targetModelsByClassName[className].push(loaded)
|
|
@@ -184,9 +170,7 @@ export default class VelociousDatabaseQueryPreloaderBelongsTo {
|
|
|
184
170
|
}
|
|
185
171
|
|
|
186
172
|
modelMeta.push({
|
|
187
|
-
foreignKeyValue: /**
|
|
188
|
-
* Narrows the runtime value to the documented type.
|
|
189
|
-
* @type {string | number | undefined} */ (model.readColumn(foreignKey)),
|
|
173
|
+
foreignKeyValue: /** @type {string | number | undefined} */ (model.readColumn(foreignKey)),
|
|
190
174
|
model,
|
|
191
175
|
targetType
|
|
192
176
|
})
|
|
@@ -244,9 +228,7 @@ export default class VelociousDatabaseQueryPreloaderBelongsTo {
|
|
|
244
228
|
targetModelsByTypeAndId[targetType] = {}
|
|
245
229
|
|
|
246
230
|
for (const targetModel of foundTargetModels) {
|
|
247
|
-
const primaryKeyValue = /**
|
|
248
|
-
* Narrows the runtime value to the documented type.
|
|
249
|
-
* @type {string | number} */ (targetModel.readColumn(primaryKey))
|
|
231
|
+
const primaryKeyValue = /** @type {string | number} */ (targetModel.readColumn(primaryKey))
|
|
250
232
|
|
|
251
233
|
targetModelsByTypeAndId[targetType][primaryKeyValue] = targetModel
|
|
252
234
|
}
|
|
@@ -105,9 +105,7 @@ export default class VelociousDatabaseQueryPreloaderHasMany {
|
|
|
105
105
|
throw new Error(`${this.relationship.getModelClass().name}#${this.relationship.getRelationshipName()} doesn't have a primary key`)
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
const throughRelationshipName = /**
|
|
109
|
-
* Narrows the runtime value to the documented type.
|
|
110
|
-
* @type {string} */ (this.relationship.through)
|
|
108
|
+
const throughRelationshipName = /** @type {string} */ (this.relationship.through)
|
|
111
109
|
const parentModelClass = this.relationship.getModelClass()
|
|
112
110
|
const throughRelationship = parentModelClass.getRelationshipByName(throughRelationshipName)
|
|
113
111
|
const throughModelClass = throughRelationship.getTargetModelClass()
|
|
@@ -146,9 +144,7 @@ export default class VelociousDatabaseQueryPreloaderHasMany {
|
|
|
146
144
|
const preloadCollections = {}
|
|
147
145
|
|
|
148
146
|
for (const model of modelsToLoad) {
|
|
149
|
-
const primaryKeyValue = /**
|
|
150
|
-
* Narrows the runtime value to the documented type.
|
|
151
|
-
* @type {string | number} */ (model.readColumn(primaryKey))
|
|
147
|
+
const primaryKeyValue = /** @type {string | number} */ (model.readColumn(primaryKey))
|
|
152
148
|
|
|
153
149
|
preloadCollections[primaryKeyValue] = []
|
|
154
150
|
|
|
@@ -174,12 +170,8 @@ export default class VelociousDatabaseQueryPreloaderHasMany {
|
|
|
174
170
|
const allTargetIds = new Set()
|
|
175
171
|
|
|
176
172
|
for (const throughModel of throughModels) {
|
|
177
|
-
const parentId = /**
|
|
178
|
-
|
|
179
|
-
* @type {string | number} */ (throughModel.readColumn(throughForeignKey))
|
|
180
|
-
const throughId = /**
|
|
181
|
-
* Narrows the runtime value to the documented type.
|
|
182
|
-
* @type {string | number} */ (throughModel.readColumn(throughModelClass.primaryKey()))
|
|
173
|
+
const parentId = /** @type {string | number} */ (throughModel.readColumn(throughForeignKey))
|
|
174
|
+
const throughId = /** @type {string | number} */ (throughModel.readColumn(throughModelClass.primaryKey()))
|
|
183
175
|
|
|
184
176
|
if (!(parentId in parentToTargetIds)) parentToTargetIds[parentId] = []
|
|
185
177
|
|
|
@@ -208,9 +200,7 @@ export default class VelociousDatabaseQueryPreloaderHasMany {
|
|
|
208
200
|
const targetModelsByForeignKey = {}
|
|
209
201
|
|
|
210
202
|
for (const targetModel of targetModels) {
|
|
211
|
-
const fkValue = /**
|
|
212
|
-
* Narrows the runtime value to the documented type.
|
|
213
|
-
* @type {string | number} */ (targetModel.readColumn(targetForeignKey))
|
|
203
|
+
const fkValue = /** @type {string | number} */ (targetModel.readColumn(targetForeignKey))
|
|
214
204
|
|
|
215
205
|
if (!(fkValue in targetModelsByForeignKey)) targetModelsByForeignKey[fkValue] = []
|
|
216
206
|
|
|
@@ -284,9 +274,7 @@ export default class VelociousDatabaseQueryPreloaderHasMany {
|
|
|
284
274
|
const preloadCollections = {}
|
|
285
275
|
|
|
286
276
|
for (const model of modelsToLoad) {
|
|
287
|
-
const primaryKeyValue = /**
|
|
288
|
-
* Narrows the runtime value to the documented type.
|
|
289
|
-
* @type {string | number} */ (model.readColumn(primaryKey))
|
|
277
|
+
const primaryKeyValue = /** @type {string | number} */ (model.readColumn(primaryKey))
|
|
290
278
|
|
|
291
279
|
preloadCollections[primaryKeyValue] = []
|
|
292
280
|
|
|
@@ -319,9 +307,7 @@ export default class VelociousDatabaseQueryPreloaderHasMany {
|
|
|
319
307
|
const targetModels = await query.toArray()
|
|
320
308
|
|
|
321
309
|
for (const targetModel of targetModels) {
|
|
322
|
-
const foreignKeyValue = /**
|
|
323
|
-
* Narrows the runtime value to the documented type.
|
|
324
|
-
* @type {string | number} */ (targetModel.readColumn(foreignKey))
|
|
310
|
+
const foreignKeyValue = /** @type {string | number} */ (targetModel.readColumn(foreignKey))
|
|
325
311
|
|
|
326
312
|
preloadCollections[foreignKeyValue].push(targetModel)
|
|
327
313
|
}
|
|
@@ -53,17 +53,13 @@ export default class VelociousDatabaseQueryPreloaderHasOne {
|
|
|
53
53
|
const instanceRelationship = model.getRelationshipByName(relationshipName)
|
|
54
54
|
|
|
55
55
|
if (this.selection.isSatisfied({instanceRelationship, targetModelClass, mappingColumns: [foreignKey]})) {
|
|
56
|
-
const loaded = /**
|
|
57
|
-
* Narrows the runtime value to the documented type.
|
|
58
|
-
* @type {import("../../record/index.js").default | undefined} */ (instanceRelationship.getLoadedOrUndefined())
|
|
56
|
+
const loaded = /** @type {import("../../record/index.js").default | undefined} */ (instanceRelationship.getLoadedOrUndefined())
|
|
59
57
|
|
|
60
58
|
if (loaded) satisfiedTargets.push(loaded)
|
|
61
59
|
continue
|
|
62
60
|
}
|
|
63
61
|
|
|
64
|
-
const primaryKeyValue = /**
|
|
65
|
-
* Narrows the runtime value to the documented type.
|
|
66
|
-
* @type {string | number} */ (model.readColumn(primaryKey))
|
|
62
|
+
const primaryKeyValue = /** @type {string | number} */ (model.readColumn(primaryKey))
|
|
67
63
|
|
|
68
64
|
preloadCollections[primaryKeyValue] = undefined
|
|
69
65
|
|
|
@@ -99,9 +95,7 @@ export default class VelociousDatabaseQueryPreloaderHasOne {
|
|
|
99
95
|
const targetModels = await query.toArray()
|
|
100
96
|
|
|
101
97
|
for (const targetModel of targetModels) {
|
|
102
|
-
const foreignKeyValue = /**
|
|
103
|
-
* Narrows the runtime value to the documented type.
|
|
104
|
-
* @type {string | number} */ (targetModel.readColumn(foreignKey))
|
|
98
|
+
const foreignKeyValue = /** @type {string | number} */ (targetModel.readColumn(foreignKey))
|
|
105
99
|
|
|
106
100
|
preloadCollections[foreignKeyValue] = targetModel
|
|
107
101
|
}
|
|
@@ -88,19 +88,13 @@ export default class VelociousDatabaseQueryPreloader {
|
|
|
88
88
|
static async preload(models, queryOrSpec, {force = false} = {}) {
|
|
89
89
|
if (models.length == 0) return
|
|
90
90
|
|
|
91
|
-
const modelClass = /**
|
|
92
|
-
* Narrows the runtime value to the documented type.
|
|
93
|
-
* @type {typeof import("../record/index.js").default} */ (models[0].constructor)
|
|
91
|
+
const modelClass = /** @type {typeof import("../record/index.js").default} */ (models[0].constructor)
|
|
94
92
|
const isQuery = Boolean(queryOrSpec) && typeof queryOrSpec == "object" && "_preload" in queryOrSpec
|
|
95
93
|
// Reuse the query builder's preload/select normalization for raw specs
|
|
96
94
|
// instead of duplicating it here.
|
|
97
95
|
const query = isQuery
|
|
98
|
-
? /**
|
|
99
|
-
|
|
100
|
-
* @type {import("./model-class-query.js").default} */ (queryOrSpec)
|
|
101
|
-
: modelClass.preload(/**
|
|
102
|
-
* Narrows the runtime value to the documented type.
|
|
103
|
-
* @type {?} */ (queryOrSpec))
|
|
96
|
+
? /** @type {import("./model-class-query.js").default} */ (queryOrSpec)
|
|
97
|
+
: modelClass.preload(/** @type {?} */ (queryOrSpec))
|
|
104
98
|
|
|
105
99
|
const preloader = new VelociousDatabaseQueryPreloader({
|
|
106
100
|
modelClass,
|
|
@@ -141,23 +135,17 @@ export default class VelociousDatabaseQueryPreloader {
|
|
|
141
135
|
let preloadResult
|
|
142
136
|
|
|
143
137
|
if (relationship.getType() == "belongsTo") {
|
|
144
|
-
const belongsToRelationship = /**
|
|
145
|
-
* Narrows the runtime value to the documented type.
|
|
146
|
-
* @type {import("../record/relationships/belongs-to.js").default} */ (relationship)
|
|
138
|
+
const belongsToRelationship = /** @type {import("../record/relationships/belongs-to.js").default} */ (relationship)
|
|
147
139
|
const hasManyPreloader = new BelongsToPreloader({models: this.models, relationship: belongsToRelationship, selection: this.selection})
|
|
148
140
|
|
|
149
141
|
preloadResult = await hasManyPreloader.run()
|
|
150
142
|
} else if (relationship.getType() == "hasMany") {
|
|
151
|
-
const hasManyRelationship = /**
|
|
152
|
-
* Narrows the runtime value to the documented type.
|
|
153
|
-
* @type {import("../record/relationships/has-many.js").default} */ (relationship)
|
|
143
|
+
const hasManyRelationship = /** @type {import("../record/relationships/has-many.js").default} */ (relationship)
|
|
154
144
|
const hasManyPreloader = new HasManyPreloader({models: this.models, relationship: hasManyRelationship, selection: this.selection})
|
|
155
145
|
|
|
156
146
|
preloadResult = await hasManyPreloader.run()
|
|
157
147
|
} else if (relationship.getType() == "hasOne") {
|
|
158
|
-
const hasOneRelationship = /**
|
|
159
|
-
* Narrows the runtime value to the documented type.
|
|
160
|
-
* @type {import("../record/relationships/has-one.js").default} */ (relationship)
|
|
148
|
+
const hasOneRelationship = /** @type {import("../record/relationships/has-one.js").default} */ (relationship)
|
|
161
149
|
const hasOnePreloader = new HasOnePreloader({models: this.models, relationship: hasOneRelationship, selection: this.selection})
|
|
162
150
|
|
|
163
151
|
preloadResult = await hasOnePreloader.run()
|
|
@@ -69,9 +69,7 @@ export function normalizeQueryDataSpec(spec, chain = []) {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
if (isPlainObject(item)) {
|
|
72
|
-
for (const nested of normalizeQueryDataSpec(/**
|
|
73
|
-
* Narrows the runtime value to the documented type.
|
|
74
|
-
* @type {?} */ (item), chain)) {
|
|
72
|
+
for (const nested of normalizeQueryDataSpec(/** @type {?} */ (item), chain)) {
|
|
75
73
|
entries.push(nested)
|
|
76
74
|
}
|
|
77
75
|
continue
|
|
@@ -98,9 +96,7 @@ export function normalizeQueryDataSpec(spec, chain = []) {
|
|
|
98
96
|
if (value === false) continue
|
|
99
97
|
|
|
100
98
|
if (typeof value === "string" || Array.isArray(value) || isPlainObject(value)) {
|
|
101
|
-
for (const nested of normalizeQueryDataSpec(/**
|
|
102
|
-
* Narrows the runtime value to the documented type.
|
|
103
|
-
* @type {?} */ (value), [...chain, key])) {
|
|
99
|
+
for (const nested of normalizeQueryDataSpec(/** @type {?} */ (value), [...chain, key])) {
|
|
104
100
|
entries.push(nested)
|
|
105
101
|
}
|
|
106
102
|
continue
|
|
@@ -193,9 +189,7 @@ export async function runQueryData({rootModelClass, rootModels, entries}) {
|
|
|
193
189
|
if (rootModels.length === 0 || entries.length === 0) return
|
|
194
190
|
|
|
195
191
|
const primaryKey = rootModelClass.primaryKey()
|
|
196
|
-
const rootIds = rootModels.map((model) => /**
|
|
197
|
-
* Narrows the runtime value to the documented type.
|
|
198
|
-
* @type {string | number} */ (model.readColumn(primaryKey)))
|
|
192
|
+
const rootIds = rootModels.map((model) => /** @type {string | number} */ (model.readColumn(primaryKey)))
|
|
199
193
|
|
|
200
194
|
for (const entry of entries) {
|
|
201
195
|
await runEntry({entry, primaryKey, rootIds, rootModelClass, rootModels})
|
|
@@ -270,9 +264,7 @@ async function runEntry({entry, primaryKey, rootIds, rootModelClass, rootModels}
|
|
|
270
264
|
tableName: targetTableRef
|
|
271
265
|
})
|
|
272
266
|
|
|
273
|
-
const rows = /**
|
|
274
|
-
* Narrows the runtime value to the documented type.
|
|
275
|
-
* @type {Array<Record<string, ?>>} */ (await query._executeQuery())
|
|
267
|
+
const rows = /** @type {Array<Record<string, ?>>} */ (await query._executeQuery())
|
|
276
268
|
const byParent = new Map()
|
|
277
269
|
|
|
278
270
|
for (const row of rows) {
|
|
@@ -284,9 +276,7 @@ async function runEntry({entry, primaryKey, rootIds, rootModelClass, rootModels}
|
|
|
284
276
|
}
|
|
285
277
|
|
|
286
278
|
for (const model of rootModels) {
|
|
287
|
-
const modelId = /**
|
|
288
|
-
* Narrows the runtime value to the documented type.
|
|
289
|
-
* @type {string | number} */ (model.readColumn(primaryKey))
|
|
279
|
+
const modelId = /** @type {string | number} */ (model.readColumn(primaryKey))
|
|
290
280
|
// Driver-type tolerance: MySQL can return PKs as strings even when
|
|
291
281
|
// the column is numeric. Fall back to a string lookup so results
|
|
292
282
|
// still land on the right model.
|
|
@@ -26,9 +26,7 @@ function normalizeRelationshipWhereOperator(operator) {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
return /** @type {"eq" | "notEq" | "gt" | "gteq" | "lt" | "lteq" | "like"} */ (
|
|
29
|
-
operatorAliases[/**
|
|
30
|
-
* Narrows the runtime value to the documented type.
|
|
31
|
-
* @type {"<" | "<=" | ">" | ">="} */ (operator)] || operator
|
|
29
|
+
operatorAliases[/** @type {"<" | "<=" | ">" | ">="} */ (operator)] || operator
|
|
32
30
|
)
|
|
33
31
|
}
|
|
34
32
|
|
|
@@ -66,9 +64,7 @@ export default class VelociousDatabaseQueryWhereModelClassHash extends WhereBase
|
|
|
66
64
|
toSql() {
|
|
67
65
|
let sql = "("
|
|
68
66
|
|
|
69
|
-
const modelQuery = /**
|
|
70
|
-
* Narrows the runtime value to the documented type.
|
|
71
|
-
* @type {import("./model-class-query.js").default} */ (this.query)
|
|
67
|
+
const modelQuery = /** @type {import("./model-class-query.js").default} */ (this.query)
|
|
72
68
|
const baseTableName = this.qualifyBaseTable
|
|
73
69
|
? modelQuery.getTableReferenceForJoin()
|
|
74
70
|
: undefined
|
|
@@ -144,9 +140,7 @@ export default class VelociousDatabaseQueryWhereModelClassHash extends WhereBase
|
|
|
144
140
|
*/
|
|
145
141
|
const addCondition = (conditionValue) => {
|
|
146
142
|
if (this._isRelationshipWhereOperatorTuple(conditionValue)) {
|
|
147
|
-
const tuple = /**
|
|
148
|
-
* Narrows the runtime value to the documented type.
|
|
149
|
-
* @type {[string, "eq" | "notEq" | "gt" | "gteq" | "lt" | "lteq" | "like" | ">" | ">=" | "<" | "<=", unknown, ...Array<unknown>]} */ (conditionValue)
|
|
143
|
+
const tuple = /** @type {[string, "eq" | "notEq" | "gt" | "gteq" | "lt" | "lteq" | "like" | ">" | ">=" | "<" | "<=", unknown, ...Array<unknown>]} */ (conditionValue)
|
|
150
144
|
const normalizedOperator = normalizeRelationshipWhereOperator(tuple[1])
|
|
151
145
|
|
|
152
146
|
normalized.push([
|
|
@@ -393,9 +387,7 @@ export default class VelociousDatabaseQueryWhereModelClassHash extends WhereBase
|
|
|
393
387
|
*/
|
|
394
388
|
_whereSQLFromHash(hash, modelClass, path, tableName, index = 0) {
|
|
395
389
|
const options = this.getOptions()
|
|
396
|
-
const modelQuery = /**
|
|
397
|
-
* Narrows the runtime value to the documented type.
|
|
398
|
-
* @type {import("./model-class-query.js").default} */ (this.query)
|
|
390
|
+
const modelQuery = /** @type {import("./model-class-query.js").default} */ (this.query)
|
|
399
391
|
let sql = ""
|
|
400
392
|
|
|
401
393
|
for (const whereKey in hash) {
|
|
@@ -441,9 +433,7 @@ export default class VelociousDatabaseQueryWhereModelClassHash extends WhereBase
|
|
|
441
433
|
|
|
442
434
|
if (!targetModelClass) throw new Error(`Relationship "${whereKey}" for ${modelClass.name} has no target model class`)
|
|
443
435
|
|
|
444
|
-
const nestedHash = /**
|
|
445
|
-
* Narrows the runtime value to the documented type.
|
|
446
|
-
* @type {WhereHash} */ (whereValue)
|
|
436
|
+
const nestedHash = /** @type {WhereHash} */ (whereValue)
|
|
447
437
|
const nestedPath = path.concat([whereKey])
|
|
448
438
|
const nestedTableName = modelQuery.getTableReferenceForJoin(...nestedPath)
|
|
449
439
|
|
|
@@ -110,24 +110,18 @@ export async function runWithCount({models, modelClass, entries}) {
|
|
|
110
110
|
if (models.length === 0 || entries.length === 0) return
|
|
111
111
|
|
|
112
112
|
const primaryKey = modelClass.primaryKey()
|
|
113
|
-
const parentIds = models.map((model) => /**
|
|
114
|
-
* Narrows the runtime value to the documented type.
|
|
115
|
-
* @type {string | number} */ (model.readColumn(primaryKey)))
|
|
113
|
+
const parentIds = models.map((model) => /** @type {string | number} */ (model.readColumn(primaryKey)))
|
|
116
114
|
|
|
117
115
|
for (const entry of entries) {
|
|
118
116
|
const counts = await countForEntry({entries, entry, modelClass, parentIds})
|
|
119
117
|
|
|
120
118
|
for (const model of models) {
|
|
121
|
-
const modelPrimaryKeyValue = /**
|
|
122
|
-
* Narrows the runtime value to the documented type.
|
|
123
|
-
* @type {string | number} */ (model.readColumn(primaryKey))
|
|
119
|
+
const modelPrimaryKeyValue = /** @type {string | number} */ (model.readColumn(primaryKey))
|
|
124
120
|
// Tolerate driver differences in numeric return types: SQLite
|
|
125
121
|
// returns integers as JS numbers, but MySQL's raw driver can
|
|
126
122
|
// return count primary keys as strings. Try both.
|
|
127
123
|
const resolvedCount = counts.has(modelPrimaryKeyValue)
|
|
128
|
-
? /**
|
|
129
|
-
* Narrows the runtime value to the documented type.
|
|
130
|
-
* @type {number} */ (counts.get(modelPrimaryKeyValue))
|
|
124
|
+
? /** @type {number} */ (counts.get(modelPrimaryKeyValue))
|
|
131
125
|
: Number(counts.get(String(modelPrimaryKeyValue)) ?? 0)
|
|
132
126
|
|
|
133
127
|
// Counts go on the record's dedicated association-count map,
|
|
@@ -196,9 +190,7 @@ async function countForEntry({entries, entry, modelClass, parentIds}) {
|
|
|
196
190
|
countQuery.select(`${quotedTable}.${quotedFk} AS parent_id`)
|
|
197
191
|
countQuery.select("COUNT(*) AS count_value")
|
|
198
192
|
|
|
199
|
-
const rows = /**
|
|
200
|
-
* Narrows the runtime value to the documented type.
|
|
201
|
-
* @type {Array<{parent_id: string | number, count_value: string | number}>} */ (
|
|
193
|
+
const rows = /** @type {Array<{parent_id: string | number, count_value: string | number}>} */ (
|
|
202
194
|
await countQuery._executeQuery()
|
|
203
195
|
)
|
|
204
196
|
|
|
@@ -208,9 +200,7 @@ async function countForEntry({entries, entry, modelClass, parentIds}) {
|
|
|
208
200
|
const counts = new Map()
|
|
209
201
|
|
|
210
202
|
for (const row of rows) {
|
|
211
|
-
const parentId = /**
|
|
212
|
-
* Narrows the runtime value to the documented type.
|
|
213
|
-
* @type {string | number} */ (row.parent_id)
|
|
203
|
+
const parentId = /** @type {string | number} */ (row.parent_id)
|
|
214
204
|
const countValue = Number(row.count_value) || 0
|
|
215
205
|
counts.set(parentId, countValue)
|
|
216
206
|
}
|