本文整理匯總了TypeScript中typestore.Coordinator.init方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Coordinator.init方法的具體用法?TypeScript Coordinator.init怎麽用?TypeScript Coordinator.init使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類typestore.Coordinator
的用法示例。
在下文中一共展示了Coordinator.init方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: reset
/**
* Reset TypeStore and start all over
*
* @param syncStrategy
* @param endpoint
* @returns {Bluebird<Coordinator>}
*/
async function reset(syncStrategy:SyncStrategy,endpoint:string) {
// Init dynamo type
// using local
const opts:IDynamoDBStorePluginOptions = {
endpoint: endpoint,
prefix: `test_${process.env.USER}_`
}
store = new DynamoDBStorePlugin(opts,Fixtures.Test1)
if (!endpoint)
delete opts['endpoint']
if (coordinator)
await coordinator.stop()
coordinator = new Coordinator()
await coordinator.init({syncStrategy},store)
return coordinator
}
示例6: runCars
export async function runCars() {
let dynamoEndpoint = DynamoDBLocalEndpoint
let dynamoLocal = null, dynamoPort = 8787
if (process.env.CIRCLE) {
dynamoLocal = require('dynamodb-local')
await dynamoLocal.launch(dynamoPort, null, ['-sharedDb'])
dynamoEndpoint = `http://localhost:${dynamoPort}`
}
// Pass in options and the indexer/search
// will service as a rest array
const cloudSearchProvider = new CloudSearchProviderPlugin({
endpoint: CloudSearchLocalEndpoint,
awsOptions: {
region: 'us-east-1',
credentials:awsCredentialChain
}
},Car)
// Pass in options and the models that the store
// will service as a rest array
const dynamoStore = new DynamoDBStorePlugin({
endpoint: dynamoEndpoint,
prefix: `examples_cars_${process.env.USER}_`
},Car)
// Create a coordinator
const coordinator = new Coordinator()
// Initialize it with all plugins
await coordinator.init({
syncStrategy: SyncStrategy.Overwrite
},dynamoStore,cloudSearchProvider)
// 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)
let carCount = await repo1.count()
assert.ok(carCount === 1, 'only 1 car in there today!')
const car1Key = repo1.key(car1.manufacturer,car1.year)
const car1FromRepo = await repo1.get(car1Key)
assert.ok(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)}`)
await repo1.remove(car1Key)
carCount = await repo1.count()
assert.ok(carCount === 0, 'only 1 car in there today!')
if (dynamoLocal)
await dynamoLocal.stop(dynamoPort)
return true
}