velocious 1.0.472 → 1.0.473

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.
@@ -638,11 +638,15 @@ export default class FrontendModelController extends Controller {
638
638
  */
639
639
  async withFrontendModelRequestContext(params, response, callback) {
640
640
  const configuration = this.getConfiguration()
641
- const tenant = await configuration.resolveTenant({
642
- params,
643
- request: this.request(),
644
- response
645
- })
641
+ const tenant = configuration.getTenantResolver()
642
+ ? await configuration.ensureConnections({name: "Frontend model request tenant resolution"}, async () => {
643
+ return await configuration.resolveTenant({
644
+ params,
645
+ request: this.request(),
646
+ response
647
+ })
648
+ })
649
+ : undefined
646
650
 
647
651
  return await configuration.runWithTenant(tenant, async () => {
648
652
  return await configuration.ensureConnections({name: "Frontend model request"}, async () => {
@@ -106,15 +106,6 @@ export default class FrontendModelWebsocketChannel extends VelociousWebsocketCha
106
106
  * @returns {Promise<void>} Resolves after delivery.
107
107
  */
108
108
  async deliverBroadcast(body, meta) {
109
- const configuration = this.session.configuration
110
-
111
- if (configuration) {
112
- await configuration.ensureConnections({name: "Frontend model websocket broadcast"}, async () => {
113
- await this._deliverBroadcast(body, meta)
114
- })
115
- return
116
- }
117
-
118
109
  await this._deliverBroadcast(body, meta)
119
110
  }
120
111
 
@@ -367,6 +358,29 @@ export default class FrontendModelWebsocketChannel extends VelociousWebsocketCha
367
358
  return controller
368
359
  }
369
360
 
361
+ /**
362
+ * Resolves tenant for event.
363
+ * @param {string | number} id - Event record id.
364
+ * @returns {Promise<?>} - Resolved tenant.
365
+ */
366
+ async _resolveEventTenant(id) {
367
+ const configuration = this.session.configuration
368
+
369
+ return await configuration.ensureConnections({name: "Frontend model websocket event tenant resolution"}, async () => {
370
+ // Mirror the subscribe-time tenant resolution (`WebsocketSession._resolveTenant`):
371
+ // pass `subscription: {channel, params}` so resolvers that derive scope from the
372
+ // subscription behave the same for broadcasts as they did at `channel-subscribe`.
373
+ // The synthetic request forwards the subscriber's params (e.g. authenticationToken),
374
+ // matching this channel's ability resolution above.
375
+ return await configuration.resolveTenant({
376
+ params: {...this.params, id, model: this._modelName()},
377
+ request: /** @type {import("../http-server/client/request.js").default} */ (this._syntheticRequest()),
378
+ response: new Response({configuration}),
379
+ subscription: {channel: FRONTEND_MODELS_CHANNEL_NAME, params: this.params}
380
+ })
381
+ })
382
+ }
383
+
370
384
  /**
371
385
  * Resolves the subscriber's tenant for the broadcast record and runs `callback` inside that tenant
372
386
  * context. Broadcast delivery runs in whatever ambient tenant context the publisher left behind. For
@@ -388,17 +402,7 @@ export default class FrontendModelWebsocketChannel extends VelociousWebsocketCha
388
402
  return await callback()
389
403
  }
390
404
 
391
- // Mirror the subscribe-time tenant resolution (`WebsocketSession._resolveTenant`):
392
- // pass `subscription: {channel, params}` so resolvers that derive scope from the
393
- // subscription behave the same for broadcasts as they did at `channel-subscribe`.
394
- // The synthetic request forwards the subscriber's params (e.g. authenticationToken),
395
- // matching this channel's ability resolution above.
396
- const tenant = await configuration.resolveTenant({
397
- params: {...this.params, id, model: this._modelName()},
398
- request: /** @type {import("../http-server/client/request.js").default} */ (this._syntheticRequest()),
399
- response: new Response({configuration}),
400
- subscription: {channel: FRONTEND_MODELS_CHANNEL_NAME, params: this.params}
401
- })
405
+ const tenant = await this._resolveEventTenant(id)
402
406
 
403
407
  // Always enter `runWithTenant`, even when no tenant resolved. Broadcast fan-out
404
408
  // runs in the publisher's ambient tenant context; falling back to `callback()`
@@ -202,12 +202,14 @@ export default class VelociousRoutesResolver {
202
202
  await this._logActionStart({action, controllerClass, logMethod})
203
203
 
204
204
  try {
205
- const tenant = skipTenantResolution
205
+ const tenant = skipTenantResolution || !this.configuration.getTenantResolver()
206
206
  ? undefined
207
- : await this.configuration.resolveTenant({
208
- params: {...this.queryParameters(), ...this.params},
209
- request: this.request,
210
- response: this.response
207
+ : await this.configuration.ensureConnections({name: `${controllerClass.name}.${action} tenant resolution`}, async () => {
208
+ return await this.configuration.resolveTenant({
209
+ params: {...this.queryParameters(), ...this.params},
210
+ request: this.request,
211
+ response: this.response
212
+ })
211
213
  })
212
214
 
213
215
  const runAction = async () => {