Skip to content

Commit

Permalink
workload delegation
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyson Midboe authored and Tyson Midboe committed Jun 29, 2023
1 parent 75bacdc commit f554a2e
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 13 deletions.
Empty file added api/litehouse.js
Empty file.
3 changes: 2 additions & 1 deletion api/litehouse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface IModel {
addAdapter (name: string, cb: cb): void
addService (name: string, cb: cb): void
addRelation (name: string, model: string, foreignKey: string, desc: string, localOnly: boolean): Model
addDataSource (name: string, adapter: string)
}

declare class Litehouse implements IAegis {
Expand All @@ -28,5 +29,5 @@ declare class Model implements IModel {
addMethod (name: string, cb: cb): void
addAdapter (name: string, cb: cb): void
addService (name: string, cb: cb): void
addRelation(name: string, model: string, foreignKey: string, desc: string, localOnly: boolean): Model;
addRelation (name: string, model: string, foreignKey: string, desc: string, localOnly: boolean): Model
}
9 changes: 9 additions & 0 deletions api/test/adapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
test('import remote adapter', async () => {
const litehouse = new Litehouse()
const fs = require('fs')
const adapter = litehouse.import('adapters/fedex')
const model.addAdapter('shipping',adapter)
await model.importDb()
const result = model.classify(fs.createReadStream('bird.jpg'))
assert.equal(result.name, 'bald eagle')
})
10 changes: 0 additions & 10 deletions api/test/method-override.js

This file was deleted.

13 changes: 12 additions & 1 deletion api/test/method.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const litehouse = new Litehouse()
const MODEL = 'math'
const METHOD = 'fibonacci'

test(async () => {
test('method', async () => {
const model = litehouse.addModel(MODEL, msg => ({
name: 'math',
desc: 'various mathematical functions'
Expand Down Expand Up @@ -39,3 +39,14 @@ test(async () => {
.then(msg => Promise.resolve(assert.equal(msg.answer, 1000000)))
.catch(err => Promise.reject(err))
})

test('override', () => {
const decorate = require('./models/dependencies/classifier/decorate')
const litehouse = new Litehouse()
const model = Litehouse.importRemote('models/classifier')

// overrides generated method, see model.js
model.addMethod('classify', (msg, model) =>
decorate(model.classify(msg.readable))
)
})
13 changes: 12 additions & 1 deletion api/test/model.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const Litehouse = require('..')
const litehouse = new Litehouse()
const test = require('node:test')
const assert = require('node:assert')
Expand All @@ -18,7 +19,7 @@ const Classifier = (msg, deps) => ({
}
})

test(() => {
test('model', () => {
litehouse.addModel(MODEL, Classifier, {
export: [METHOD_IMPORTDB, METHOD_CLASSIFY]
})
Expand Down Expand Up @@ -57,3 +58,13 @@ test(() => {
.catch(err => Promise.reject(err))
])
})

test('remote import', async () => {
const litehouse = new Litehouse()
const fs = require('fs')
const factory = litehouse.import('models/classifier')
const model = factory({ classdb: 'birds' })
await model.importDb()
const result = model.classify(fs.createReadStream('bird.jpg'))
assert.equal(result.name, 'bald eagle')
})

0 comments on commit f554a2e

Please # to comment.