Skip to content

Commit 71eb9a5

Browse files
authored
Merge pull request #276 from module-federation/release-0-1-0
fix threadpool, datasource and cache loading
2 parents d4c34e9 + 2a195b4 commit 71eb9a5

File tree

18 files changed

+339
-283
lines changed

18 files changed

+339
-283
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"license": "Apache-2.0",
99
"scripts": {
1010
"start": "./start.sh",
11-
"build": "npm run build:esm && npm run build:cjs",
11+
"build": "npm run build:esm && npm run build:cjs && cd ../aegis/wasm && yarn build && yarn deploy",
1212
"watch": "node watch.mjs",
1313
"webswitch": "cd ../aegis-host ; export SWITCH=true ; export PORT=8888 ; yarn start",
1414
"build:esm": "babel --delete-dir-on-start -d esm/ src/ && cp src/index.js esm",
@@ -32,6 +32,7 @@
3232
"assemblyscript": "0.25.2",
3333
"cors": "^2.8.5",
3434
"dotenv": "16.0.1",
35+
"express": "^4.18.2",
3536
"express-fileupload": "^1.4.0",
3637
"express-jwt": "7.7.5",
3738
"import-fresh": "3.3.0",
@@ -70,8 +71,8 @@
7071
"jsdoc-to-markdown": "7.1.1",
7172
"mocha": "10.0.0",
7273
"mocha-esm": "1.1.1",
73-
"pretty-cli": "^0.0.14",
7474
"prettier": "^2.8.1",
75+
"pretty-cli": "^0.0.14",
7576
"split": "1.0.1",
7677
"standard": "^17.0.0",
7778
"yarn": "1.22.19"

src/adapters/controllers/get-content.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import ModelFactory from '../../domain'
44

5-
function prettifyJson(json) {
5+
function prettifyJson (json) {
66
if (typeof json !== 'string') {
77
json = JSON.stringify(json, null, 2)
88
}
@@ -27,7 +27,7 @@ function prettifyJson(json) {
2727
)
2828
}
2929

30-
function getResourceName(httpRequest, defaultTitle = '') {
30+
function getResourceName (httpRequest, defaultTitle = '') {
3131
if (/events/i.test(httpRequest.query.details)) return 'Domain Events'
3232
if (/threads/i.test(httpRequest.query.details)) return 'Thread Pools'
3333
if (/data/i.test(httpRequest.query.details)) return 'Data Sources'
@@ -37,7 +37,7 @@ function getResourceName(httpRequest, defaultTitle = '') {
3737
return defaultTitle
3838
}
3939

40-
function findLocalRelatedModels(modelName) {
40+
function findLocalRelatedModels (modelName) {
4141
const localModels = ModelFactory.getModelSpecs().map(s =>
4242
s.modelName.toUpperCase()
4343
)
@@ -60,7 +60,7 @@ function findLocalRelatedModels(modelName) {
6060
* @returns
6161
*/
6262

63-
export default function getContent(httpRequest, content, defaultTitle) {
63+
export default function getContent (httpRequest, content, defaultTitle) {
6464
const contents = content instanceof Array ? content : [content]
6565
try {
6666
if (!httpRequest.query.html)
@@ -169,14 +169,14 @@ export default function getContent(httpRequest, content, defaultTitle) {
169169

170170
html += '<div class="mb3">'
171171
ModelFactory.getModelSpecs().forEach(s => {
172-
html += `<a href="${httpRequest.path}?${queryText}modelName=${s.modelName}">View thread info for ${s.modelName}</a><br>`
172+
html += `<a href="${httpRequest.path}?${queryText}modelName=${s.modelName}">View data in ${s.modelName} thread</a><br>`
173173
try {
174174
console.debug(httpRequest.query.details === 'data')
175175
if (httpRequest.query.details === 'data') {
176176
const related = findLocalRelatedModels(s.modelName)
177177
related.forEach(
178-
rel =>
179-
(html += `<a href="${httpRequest.path}?${queryText}modelName=${s.modelName}&poolName=${rel}">View ${s.modelName} thread info for ${rel}</a><br>`)
178+
relModel =>
179+
(html += `<a href="${httpRequest.path}?${queryText}modelName=${s.modelName}&poolName=${relModel}">View ${relModel} data from ${s.modelName} thread</a><br>`)
180180
)
181181
}
182182
} catch (error) {

src/adapters/controllers/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ import anyInvokePortFactory from './post-invoke-port'
2626
import makeLiveUpdate from './live-update'
2727
import makeLiveRollout from './live-rollout'
2828

29-
function make(useCases, controllerFactory) {
29+
function make (useCases, controllerFactory) {
3030
return useCases().map(uc => ({
3131
endpoint: uc.endpoint,
3232
path: uc.path,
3333
ports: uc.ports,
34-
fn: controllerFactory(uc.fn),
34+
fn: controllerFactory(uc.fn)
3535
}))
3636
}
3737

3838
export const postModels = () => make(createModels, postModelFactory)
3939
export const patchModels = () => make(editModels, patchModelFactory)
4040
export const getModels = () => make(listModels, getModelsFactory)
41-
export const getModelsById = () => make(findModels, getModelByIdFactory)
41+
export const getModelById = () => make(findModels, getModelByIdFactory)
4242
export const deleteModels = () => make(removeModels, deleteModelFactory)
4343
export const anyInvokePorts = () => make(invokePorts, anyInvokePortFactory)
4444
export const liveUpdate = () => make(hotReload, makeLiveUpdate)
@@ -51,14 +51,14 @@ export const initCache = () => {
5151
const specs = loadModels()
5252
registerEvents()
5353

54-
async function loadModelInstances() {
54+
async function loadModelInstances () {
5555
console.time(label)
5656
await Promise.allSettled(specs.map(async m => (m && m.fn ? m.fn() : false)))
5757
console.timeEnd(label)
5858
}
5959

6060
return {
61-
load: () => loadModelInstances(),
61+
load: () => loadModelInstances()
6262
}
6363
}
6464

src/adapters/datasources/datasource-mongodb.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ export class DataSourceMongoDb extends DataSource {
309309
async streamList (options) {
310310
const pipeArgs = []
311311

312+
console.log('streamList')
312313
try {
313314
const paginate = new Transform({
314315
writableObjectMode: true,
@@ -391,7 +392,7 @@ export class DataSourceMongoDb extends DataSource {
391392
}
392393
console.log({ options })
393394

394-
if (options.streamResult) return this.streamList(options)
395+
if (param.streamResult) return this.streamList(param)
395396

396397
const data = (await this.mongoFind(options)).toArray()
397398
const count = data?.length

src/aegis.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ const { EventBrokerFactory, DomainEvents, importRemotes, requestContext } =
77
const { badUserRoute, reload } = DomainEvents
88
const { pathToRegexp, match } = require('path-to-regexp')
99
const { nanoid } = require('nanoid')
10-
const { EventEmitter } = require('stream')
10+
const { EventEmitter } = require('node:stream')
1111
const broker = EventBrokerFactory.getInstance()
1212

1313
const {
1414
deleteModels,
1515
getConfig,
1616
getRoutes,
1717
getModels,
18-
getModelsById,
18+
getModelById,
1919
http,
2020
initCache,
2121
patchModels,
@@ -35,7 +35,7 @@ const endpointPortId = e => `${modelPath}/${e}/:id/service/ports/:port`
3535

3636
/**
3737
* Store routes and their controllers for direct invocation
38-
* as serverless functions
38+
*
3939
* @extends {Map}
4040
*/
4141
class RouteMap extends Map {
@@ -138,7 +138,7 @@ function makeRoutes () {
138138
router.autoRoutes(endpoint, 'get', liveUpdate, http)
139139
router.autoRoutes(endpoint, 'get', getModels, http)
140140
router.autoRoutes(endpoint, 'post', postModels, http)
141-
router.autoRoutes(endpointId, 'get', getModelsById, http)
141+
router.autoRoutes(endpointId, 'get', getModelById, http)
142142
router.autoRoutes(endpointId, 'patch', patchModels, http)
143143
router.autoRoutes(endpointId, 'delete', deleteModels, http)
144144
router.autoRoutes(endpointCmd, 'patch', patchModels, http)
@@ -162,8 +162,8 @@ function makeRoutes () {
162162
*
163163
* @param {string} path
164164
* @param {'get'|'patch'|'post'|'delete'} method
165-
* @param {Request} req
166-
* @param {Response} res
165+
* @param {ClientRequest} req
166+
* @param {ServerResponse} res
167167
* @returns
168168
*/
169169
async function handle (path, method, req, res) {
@@ -266,4 +266,3 @@ process.on('uncaughtException', error => {
266266
console.error('uncaughtException', error)
267267
broker.notify('uncaughtException', error)
268268
})
269-

0 commit comments

Comments
 (0)