chore(server): core IoC #97 - getObjectsStreamFactory
This commit is contained in:
Родитель
960fe33f69
Коммит
b373e446b3
|
@ -54,6 +54,25 @@ export type GetObjectChildrenStream = (params: {
|
|||
objectId: string
|
||||
}) => Promise<stream.PassThrough & AsyncIterable<{ dataText: string; id: string }>>
|
||||
|
||||
export type GetObjectsStream = (params: {
|
||||
streamId: string
|
||||
objectIds: string[]
|
||||
}) => Promise<
|
||||
stream.PassThrough &
|
||||
AsyncIterable<
|
||||
{
|
||||
dataText: string
|
||||
} & Pick<
|
||||
SpeckleObject,
|
||||
| 'id'
|
||||
| 'speckleType'
|
||||
| 'totalChildrenCount'
|
||||
| 'totalChildrenCountByDepth'
|
||||
| 'createdAt'
|
||||
>
|
||||
>
|
||||
>
|
||||
|
||||
export type GetObjectChildren = (params: {
|
||||
streamId: string
|
||||
objectId: string
|
||||
|
|
|
@ -13,6 +13,7 @@ import {
|
|||
GetObjectChildren,
|
||||
GetObjectChildrenQuery,
|
||||
GetObjectChildrenStream,
|
||||
GetObjectsStream,
|
||||
GetStreamObjects,
|
||||
StoreClosuresIfNotFound,
|
||||
StoreObjects,
|
||||
|
@ -167,6 +168,22 @@ export const getObjectChildrenStreamFactory =
|
|||
return q.stream({ highWaterMark: 500 })
|
||||
}
|
||||
|
||||
export const getObjectsStreamFactory =
|
||||
(deps: { db: Knex }): GetObjectsStream =>
|
||||
async ({ streamId, objectIds }) => {
|
||||
const res = tables
|
||||
.objects(deps.db)
|
||||
.whereIn('id', objectIds)
|
||||
.andWhere('streamId', streamId)
|
||||
.orderBy('id')
|
||||
.select(
|
||||
knex.raw(
|
||||
'"id", "speckleType", "totalChildrenCount", "totalChildrenCountByDepth", "createdAt", data::text as "dataText"'
|
||||
)
|
||||
)
|
||||
return res.stream({ highWaterMark: 500 })
|
||||
}
|
||||
|
||||
export const getObjectChildrenFactory =
|
||||
(deps: { db: Knex }): GetObjectChildren =>
|
||||
async ({ streamId, objectId, limit, depth, select, cursor }) => {
|
||||
|
|
|
@ -3,10 +3,13 @@ import { corsMiddleware } from '@/modules/core/configs/cors'
|
|||
import type { Application } from 'express'
|
||||
import { validatePermissionsReadStream } from '@/modules/core/rest/authUtils'
|
||||
import { SpeckleObjectsStream } from '@/modules/core/rest/speckleObjectsStream'
|
||||
import { getObjectsStream } from '@/modules/core/services/objects'
|
||||
import { pipeline, PassThrough } from 'stream'
|
||||
import { getObjectsStreamFactory } from '@/modules/core/repositories/objects'
|
||||
import { db } from '@/db/knex'
|
||||
|
||||
export default (app: Application) => {
|
||||
const getObjectsStream = getObjectsStreamFactory({ db })
|
||||
|
||||
app.options('/api/getobjects/:streamId', corsMiddleware())
|
||||
|
||||
app.post('/api/getobjects/:streamId', corsMiddleware(), async (req, res) => {
|
||||
|
|
|
@ -3,19 +3,6 @@ const knex = require(`@/db/knex`)
|
|||
const Objects = () => knex('objects')
|
||||
|
||||
module.exports = {
|
||||
async getObjectsStream({ streamId, objectIds }) {
|
||||
const res = Objects()
|
||||
.whereIn('id', objectIds)
|
||||
.andWhere('streamId', streamId)
|
||||
.orderBy('id')
|
||||
.select(
|
||||
knex.raw(
|
||||
'"id", "speckleType", "totalChildrenCount", "totalChildrenCountByDepth", "createdAt", data::text as "dataText"'
|
||||
)
|
||||
)
|
||||
return res.stream({ highWaterMark: 500 })
|
||||
},
|
||||
|
||||
async hasObjects({ streamId, objectIds }) {
|
||||
const dbRes = await Objects()
|
||||
.whereIn('id', objectIds)
|
||||
|
|
Загрузка…
Ссылка в новой задаче