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'
|
import zlib from 'zlib'
|
||||||
const zlib = require('zlib')
|
import { corsMiddleware } from '@/modules/core/configs/cors'
|
||||||
const { corsMiddleware } = require('@/modules/core/configs/cors')
|
|
||||||
|
|
||||||
const { SpeckleObjectsStream } = require('./speckleObjectsStream')
|
import { SpeckleObjectsStream } from '@/modules/core/rest/speckleObjectsStream'
|
||||||
const { pipeline, PassThrough } = require('stream')
|
import { pipeline, PassThrough } from 'stream'
|
||||||
const { logger } = require('@/logging/logging')
|
import { logger } from '@/logging/logging'
|
||||||
const {
|
import {
|
||||||
getFormattedObjectFactory,
|
getFormattedObjectFactory,
|
||||||
getObjectChildrenStreamFactory
|
getObjectChildrenStreamFactory
|
||||||
} = require('@/modules/core/repositories/objects')
|
} from '@/modules/core/repositories/objects'
|
||||||
const { db } = require('@/db/knex')
|
import { db } from '@/db/knex'
|
||||||
const {
|
import { validatePermissionsReadStreamFactory } from '@/modules/core/services/streams/auth'
|
||||||
validatePermissionsReadStreamFactory
|
import { getStreamFactory } from '@/modules/core/repositories/streams'
|
||||||
} = require('@/modules/core/services/streams/auth')
|
import { validateScopes, authorizeResolver } from '@/modules/shared'
|
||||||
const { getStreamFactory } = require('@/modules/core/repositories/streams')
|
import type express from 'express'
|
||||||
const { validateScopes, authorizeResolver } = require('@/modules/shared')
|
|
||||||
|
|
||||||
const getObject = getFormattedObjectFactory({ db })
|
export default (app: express.Express) => {
|
||||||
const getObjectChildrenStream = getObjectChildrenStreamFactory({ db })
|
const getObject = getFormattedObjectFactory({ db })
|
||||||
const validatePermissionsReadStream = validatePermissionsReadStreamFactory({
|
const getObjectChildrenStream = getObjectChildrenStreamFactory({ db })
|
||||||
getStream: getStreamFactory({ db }),
|
const validatePermissionsReadStream = validatePermissionsReadStreamFactory({
|
||||||
validateScopes,
|
getStream: getStreamFactory({ db }),
|
||||||
authorizeResolver
|
validateScopes,
|
||||||
})
|
authorizeResolver
|
||||||
|
})
|
||||||
|
|
||||||
module.exports = (app) => {
|
|
||||||
app.options('/objects/:streamId/:objectId', corsMiddleware())
|
app.options('/objects/:streamId/:objectId', corsMiddleware())
|
||||||
|
|
||||||
app.get('/objects/:streamId/:objectId', corsMiddleware(), async (req, res) => {
|
app.get('/objects/:streamId/:objectId', corsMiddleware(), async (req, res) => {
|
|
@ -1,9 +1,14 @@
|
||||||
const { Transform } = require('stream')
|
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
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 {
|
class SpeckleObjectsStream extends Transform {
|
||||||
constructor(simpleText) {
|
simpleText: boolean
|
||||||
|
isFirstObject: boolean
|
||||||
|
|
||||||
|
constructor(simpleText: boolean) {
|
||||||
super({ writableObjectMode: true })
|
super({ writableObjectMode: true })
|
||||||
this.simpleText = simpleText
|
this.simpleText = simpleText
|
||||||
|
|
||||||
|
@ -11,7 +16,11 @@ class SpeckleObjectsStream extends Transform {
|
||||||
this.isFirstObject = true
|
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
|
let objData = dbObj.dataText
|
||||||
if (objData === undefined) objData = JSON.stringify(dbObj.data)
|
if (objData === undefined) objData = JSON.stringify(dbObj.data)
|
||||||
|
|
||||||
|
@ -28,14 +37,14 @@ class SpeckleObjectsStream extends Transform {
|
||||||
}
|
}
|
||||||
callback()
|
callback()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
callback(e)
|
callback(ensureError(e))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_flush(callback) {
|
_flush(callback: TransformCallback) {
|
||||||
if (!this.simpleText) this.push(']')
|
if (!this.simpleText) this.push(']')
|
||||||
callback()
|
callback()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.SpeckleObjectsStream = SpeckleObjectsStream
|
export { SpeckleObjectsStream }
|
Загрузка…
Ссылка в новой задаче