本文整理匯總了TypeScript中typestore.Coordinator類的典型用法代碼示例。如果您正苦於以下問題:TypeScript Coordinator類的具體用法?TypeScript Coordinator怎麽用?TypeScript Coordinator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Coordinator類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: reset
/**
* Reset TypeStore and start all over
*/
async function reset(useGlobal = true, extraOpts = null,...models) {
await stop()
const
storeOpts:IPouchDBOptions = Object.assign({
//filename: `test-db.websql.db`,
//sync: true
//filename: `http://127.0.0.1:5984/tstest-${new Date()}`
filename: `/tmp/tstest-${Date.now()}`,
databasePerRepo: !useGlobal
},extraOpts || {})
//if (!useGlobal)
//mkdirp(storeOpts.filename)
log.info(`Create store - global = ${useGlobal}`)
store = new PouchDBPlugin(storeOpts)
coordinator = new Coordinator()
log.info(`Init coordinator`)
await coordinator.init({}, store)
log.info(`Start coordinator`)
await coordinator.start(...models)
return coordinator
}
示例2: before
before(async () => {
if (coordinator)
await coordinator.stop()
coordinator = new Coordinator()
await coordinator.init({},store,cloudSearchProvider)
await coordinator.start(CloudSearchTestModel)
})
示例3: runCars
export async function runCars() {
const idbOpts = {
databaseName: 'cars-db'
}
const dbToDelete = new Dexie(idbOpts.databaseName)
await dbToDelete.delete()
const idbStore = new IndexedDBPlugin(idbOpts, Car)
// Create a coordinator
const coordinator = new Coordinator()
// Initialize it with all plugins
await coordinator.init({
syncStrategy: SyncStrategy.Overwrite
},idbStore)
// Then start it with all models
await coordinator.start(Car)
let car1 = new Car({
manufacturer: 'volvo',
year: 1956,
model: '740gle',
tagLine: 'old school'
})
const repo1 = coordinator.getRepo(CarRepo)
car1 = await repo1.save(car1)
log.info('Car saved')
let carCount = await repo1.count()
assert(carCount === 1, 'only 1 car in there today!')
log.info('Car count = 1')
const car1Key = repo1.key(car1.manufacturer)
const car1FromRepo = await repo1.get(car1Key)
assert(car1FromRepo.manufacturer === car1.manufacturer &&
car1FromRepo.year === car1.year &&
car1FromRepo.model === car1.model
,`These should be identical\n${JSON.stringify(car1,null,4)}
from repo \n${JSON.stringify(car1FromRepo,null,4)}`)
log.info('Car models match')
await repo1.remove(car1Key)
log.info('Car removed')
carCount = await repo1.count()
assert(carCount === 0, 'only 1 car in there today!')
log.info('Car count 0')
log.info('All tests run')
return true
}
示例4: reset
/**
* Reset TypeStore and start all over
*
* @returns {Bluebird<Coordinator>}
*/
async function reset() {
// Init dynamo type
// using local
store = new IndexedDBPlugin(storeOpts)
if (coordinator)
await coordinator.reset()
coordinator = new Coordinator()
await coordinator.init({},store)
return coordinator
}
示例5: uuid
before(async () => {
t1 = new Fixtures.Test1()
t1.id = uuid()
t1.createdAt = new Date().getTime()
t1.randomText = 'asdfasdfadsf'
await coordinator.start(Fixtures.Test1)
test1Repo = coordinator.getRepo(Fixtures.Test1Repo)
})
示例6: async
it('#tableDef', async () => {
await coordinator.start(Fixtures.Test1)
const modelOpts = coordinator.getModel(Fixtures.Test1)
const tableDef = store.tableDefinition(modelOpts.name)
expect(tableDef.KeySchema.length).toBe(2)
expect(tableDef.AttributeDefinitions.length).toBe(3)
expect(tableDef.AttributeDefinitions[0].AttributeName).toBe('id')
expect(tableDef.AttributeDefinitions[0].AttributeType).toBe('S')
})
示例7: async
doTest = async (modelClazz,repoClazz) => {
try {
let
model = new modelClazz(),
repo = coordinator.getRepo(repoClazz)
Object.assign(model, {
id: uuid.v4(),
createdAt: Faker.date.past(),
randomText: Faker.lorem.words(10)
})
model = await repo.save(model)
const
model2 = Object.assign(new modelClazz(),model, {
randomText: Faker.lorem.words(10),
$$doc: Object.assign({},(model as any).$$doc,{
_rev: '1-aa86c0e405a07fb76ef3e523dd1c2ae1'
}),
})
await repo.save(model2)
return null
} catch (anErr) {
return anErr
}
}