@@ -139,6 +139,7 @@ export function registerRPC (app: Express, sessions: SessionManager, ctx: Measur
139
139
async function withSession (
140
140
req : Request ,
141
141
res : ExpressResponse ,
142
+ method : string ,
142
143
operation : (
143
144
ctx : ClientSessionCtx ,
144
145
session : Session ,
@@ -183,9 +184,15 @@ export function registerRPC (app: Express, sessions: SessionManager, ctx: Measur
183
184
}
184
185
185
186
const rpc = transactorRpc
186
- const rateLimit = await sessions . handleRPC ( rpc . context , rpc . session , rpc . client , async ( ctx , rateLimit ) => {
187
- await operation ( ctx , rpc . session , rateLimit , token )
188
- } )
187
+ const rateLimit = await sessions . handleRPC (
188
+ rpc . context ,
189
+ rpc . session ,
190
+ method ,
191
+ rpc . client ,
192
+ async ( ctx , rateLimit ) => {
193
+ await operation ( ctx , rpc . session , rateLimit , token )
194
+ }
195
+ )
189
196
if ( rateLimit !== undefined ) {
190
197
const { remaining, limit, reset, retryAfter } = rateLimit
191
198
const retryHeaders : OutgoingHttpHeaders = {
@@ -212,7 +219,7 @@ export function registerRPC (app: Express, sessions: SessionManager, ctx: Measur
212
219
}
213
220
214
221
app . get ( '/api/v1/ping/:workspaceId' , ( req , res ) => {
215
- void withSession ( req , res , async ( ctx , session , rateLimit ) => {
222
+ void withSession ( req , res , 'ping' , async ( ctx , session , rateLimit ) => {
216
223
await session . ping ( ctx )
217
224
await sendJson (
218
225
req ,
@@ -228,7 +235,7 @@ export function registerRPC (app: Express, sessions: SessionManager, ctx: Measur
228
235
} )
229
236
230
237
app . get ( '/api/v1/find-all/:workspaceId' , ( req , res ) => {
231
- void withSession ( req , res , async ( ctx , session , rateLimit ) => {
238
+ void withSession ( req , res , 'findAll' , async ( ctx , session , rateLimit ) => {
232
239
const _class = req . query . class as Ref < Class < Doc > >
233
240
const query = req . query . query !== undefined ? JSON . parse ( req . query . query as string ) : { }
234
241
const options = req . query . options !== undefined ? JSON . parse ( req . query . options as string ) : { }
@@ -242,7 +249,7 @@ export function registerRPC (app: Express, sessions: SessionManager, ctx: Measur
242
249
} )
243
250
244
251
app . post ( '/api/v1/find-all/:workspaceId' , ( req , res ) => {
245
- void withSession ( req , res , async ( ctx , session , rateLimit ) => {
252
+ void withSession ( req , res , 'findAll' , async ( ctx , session , rateLimit ) => {
246
253
const { _class, query, options } : any = ( await retrieveJson ( req ) ) ?? { }
247
254
248
255
const result = await session . findAllRaw ( ctx , _class , query , options )
@@ -251,7 +258,7 @@ export function registerRPC (app: Express, sessions: SessionManager, ctx: Measur
251
258
} )
252
259
253
260
app . post ( '/api/v1/tx/:workspaceId' , ( req , res ) => {
254
- void withSession ( req , res , async ( ctx , session , rateLimit ) => {
261
+ void withSession ( req , res , 'tx' , async ( ctx , session , rateLimit ) => {
255
262
const tx : any = ( await retrieveJson ( req ) ) ?? { }
256
263
257
264
if ( tx . _class === core . class . TxDomainEvent ) {
@@ -271,7 +278,7 @@ export function registerRPC (app: Express, sessions: SessionManager, ctx: Measur
271
278
* @deprecated Use /api/v1/tx/:workspaceIdd instead
272
279
*/
273
280
app . post ( '/api/v1/event/:workspaceId' , ( req , res ) => {
274
- void withSession ( req , res , async ( ctx , session ) => {
281
+ void withSession ( req , res , 'domainRequest' , async ( ctx , session ) => {
275
282
const event : any = ( await retrieveJson ( req ) ) ?? { }
276
283
277
284
const { result } = await session . domainRequestRaw ( ctx , COMMUNICATION_DOMAIN , {
@@ -282,14 +289,14 @@ export function registerRPC (app: Express, sessions: SessionManager, ctx: Measur
282
289
} )
283
290
284
291
app . get ( '/api/v1/account/:workspaceId' , ( req , res ) => {
285
- void withSession ( req , res , async ( ctx , session , rateLimit ) => {
292
+ void withSession ( req , res , 'account' , async ( ctx , session , rateLimit ) => {
286
293
const result = session . getRawAccount ( )
287
294
await sendJson ( req , res , result , rateLimitToHeaders ( rateLimit ) )
288
295
} )
289
296
} )
290
297
291
298
app . get ( '/api/v1/load-model/:workspaceId' , ( req , res ) => {
292
- void withSession ( req , res , async ( ctx , session , rateLimit ) => {
299
+ void withSession ( req , res , 'loadModel' , async ( ctx , session , rateLimit ) => {
293
300
const lastModelTx = parseInt ( ( req . query . lastModelTx as string ) ?? '0' )
294
301
const lastHash = req . query . lastHash as string
295
302
const result = await session . loadModelRaw ( ctx , lastModelTx , lastHash )
@@ -322,7 +329,7 @@ export function registerRPC (app: Express, sessions: SessionManager, ctx: Measur
322
329
} )
323
330
324
331
app . get ( '/api/v1/search-fulltext/:workspaceId' , ( req , res ) => {
325
- void withSession ( req , res , async ( ctx , session , rateLimit ) => {
332
+ void withSession ( req , res , 'searchFulltext' , async ( ctx , session , rateLimit ) => {
326
333
const query : SearchQuery = {
327
334
query : req . query . query as string ,
328
335
classes : req . query . classes !== undefined ? JSON . parse ( req . query . classes as string ) : undefined ,
@@ -337,7 +344,7 @@ export function registerRPC (app: Express, sessions: SessionManager, ctx: Measur
337
344
} )
338
345
339
346
app . get ( '/api/v1/request/:domain/:operation/:workspaceId' , ( req , res ) => {
340
- void withSession ( req , res , async ( ctx , session ) => {
347
+ void withSession ( req , res , 'domainRequest' , async ( ctx , session ) => {
341
348
const domain = req . params . domain as OperationDomain
342
349
const operation = req . params . operation
343
350
@@ -351,7 +358,7 @@ export function registerRPC (app: Express, sessions: SessionManager, ctx: Measur
351
358
} )
352
359
353
360
app . post ( '/api/v1/request/:domain/:workspaceId' , ( req , res ) => {
354
- void withSession ( req , res , async ( ctx , session ) => {
361
+ void withSession ( req , res , 'domainRequest' , async ( ctx , session ) => {
355
362
const domain = req . params . domain as OperationDomain
356
363
const params = retrieveJson ( req )
357
364
const { result } = await session . domainRequestRaw ( ctx , domain , params )
@@ -360,7 +367,7 @@ export function registerRPC (app: Express, sessions: SessionManager, ctx: Measur
360
367
} )
361
368
362
369
app . post ( '/api/v1/ensure-person/:workspaceId' , ( req , res ) => {
363
- void withSession ( req , res , async ( ctx , session , rateLimit , token ) => {
370
+ void withSession ( req , res , 'ensurePerson' , async ( ctx , session , rateLimit , token ) => {
364
371
const { socialType, socialValue, firstName, lastName } = ( await retrieveJson ( req ) ) ?? { }
365
372
const accountClient = getAccountClient ( token )
366
373
@@ -438,7 +445,7 @@ export function registerRPC (app: Express, sessions: SessionManager, ctx: Measur
438
445
439
446
// To use in non-js (rust) clients that can't link to @hcengineering/core
440
447
app . get ( '/api/v1/generate-id/:workspaceId' , ( req , res ) => {
441
- void withSession ( req , res , async ( ctx , session , rateLimit ) => {
448
+ void withSession ( req , res , 'generateId' , async ( ctx , session , rateLimit ) => {
442
449
const result = { id : generateId ( ) }
443
450
await sendJson ( req , res , result , rateLimitToHeaders ( rateLimit ) )
444
451
} )
0 commit comments