Merge pull request #3373 from specklesystems/fabians/core-ioc-105
chore(server): core IoC #105 - remaining js rest to ts
This commit is contained in:
Коммит
bed0fd60c6
|
@ -1,30 +1,28 @@
|
|||
'use strict'
|
||||
const zlib = require('zlib')
|
||||
const { corsMiddleware } = require('@/modules/core/configs/cors')
|
||||
import zlib from 'zlib'
|
||||
import { corsMiddleware } from '@/modules/core/configs/cors'
|
||||
|
||||
const { SpeckleObjectsStream } = require('./speckleObjectsStream')
|
||||
const { pipeline, PassThrough } = require('stream')
|
||||
const { logger } = require('@/logging/logging')
|
||||
const {
|
||||
import { SpeckleObjectsStream } from '@/modules/core/rest/speckleObjectsStream'
|
||||
import { pipeline, PassThrough } from 'stream'
|
||||
import { logger } from '@/logging/logging'
|
||||
import {
|
||||
getFormattedObjectFactory,
|
||||
getObjectChildrenStreamFactory
|
||||
} = require('@/modules/core/repositories/objects')
|
||||
const { db } = require('@/db/knex')
|
||||
const {
|
||||
validatePermissionsReadStreamFactory
|
||||
} = require('@/modules/core/services/streams/auth')
|
||||
const { getStreamFactory } = require('@/modules/core/repositories/streams')
|
||||
const { validateScopes, authorizeResolver } = require('@/modules/shared')
|
||||
} from '@/modules/core/repositories/objects'
|
||||
import { db } from '@/db/knex'
|
||||
import { validatePermissionsReadStreamFactory } from '@/modules/core/services/streams/auth'
|
||||
import { getStreamFactory } from '@/modules/core/repositories/streams'
|
||||
import { validateScopes, authorizeResolver } from '@/modules/shared'
|
||||
import type express from 'express'
|
||||
|
||||
const getObject = getFormattedObjectFactory({ db })
|
||||
const getObjectChildrenStream = getObjectChildrenStreamFactory({ db })
|
||||
const validatePermissionsReadStream = validatePermissionsReadStreamFactory({
|
||||
getStream: getStreamFactory({ db }),
|
||||
validateScopes,
|
||||
authorizeResolver
|
||||
})
|
||||
export default (app: express.Express) => {
|
||||
const getObject = getFormattedObjectFactory({ db })
|
||||
const getObjectChildrenStream = getObjectChildrenStreamFactory({ db })
|
||||
const validatePermissionsReadStream = validatePermissionsReadStreamFactory({
|
||||
getStream: getStreamFactory({ db }),
|
||||
validateScopes,
|
||||
authorizeResolver
|
||||
})
|
||||
|
||||
module.exports = (app) => {
|
||||
app.options('/objects/:streamId/:objectId', corsMiddleware())
|
||||
|
||||
app.get('/objects/:streamId/:objectId', corsMiddleware(), async (req, res) => {
|
|
@ -1,9 +1,14 @@
|
|||
const { Transform } = require('stream')
|
||||
|
||||
// A stream that converts database objects stream to "{id}\t{data_json}\n" stream or a json stream of obj.data fields
|
||||
import { ensureError } from '@speckle/shared'
|
||||
import { Transform, TransformCallback } from 'stream'
|
||||
|
||||
/**
|
||||
* A stream that converts database objects stream to "{id}\t{data_json}\n" stream or a json stream of obj.data fields
|
||||
*/
|
||||
class SpeckleObjectsStream extends Transform {
|
||||
constructor(simpleText) {
|
||||
simpleText: boolean
|
||||
isFirstObject: boolean
|
||||
|
||||
constructor(simpleText: boolean) {
|
||||
super({ writableObjectMode: true })
|
||||
this.simpleText = simpleText
|
||||
|
||||
|
@ -11,7 +16,11 @@ class SpeckleObjectsStream extends Transform {
|
|||
this.isFirstObject = true
|
||||
}
|
||||
|
||||
_transform(dbObj, encoding, callback) {
|
||||
_transform(
|
||||
dbObj: { dataText: string; id: string; data?: Record<string, unknown> },
|
||||
_encoding: BufferEncoding,
|
||||
callback: TransformCallback
|
||||
) {
|
||||
let objData = dbObj.dataText
|
||||
if (objData === undefined) objData = JSON.stringify(dbObj.data)
|
||||
|
||||
|
@ -28,14 +37,14 @@ class SpeckleObjectsStream extends Transform {
|
|||
}
|
||||
callback()
|
||||
} catch (e) {
|
||||
callback(e)
|
||||
callback(ensureError(e))
|
||||
}
|
||||
}
|
||||
|
||||
_flush(callback) {
|
||||
_flush(callback: TransformCallback) {
|
||||
if (!this.simpleText) this.push(']')
|
||||
callback()
|
||||
}
|
||||
}
|
||||
|
||||
exports.SpeckleObjectsStream = SpeckleObjectsStream
|
||||
export { SpeckleObjectsStream }
|
Загрузка…
Ссылка в новой задаче