Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ShishKabab committed Apr 12, 2020
2 parents 472a29e + f2a85d2 commit 449f4ad
Show file tree
Hide file tree
Showing 27 changed files with 5,808 additions and 519 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ yarn-error.log*
*.swp

private
lib
3 changes: 3 additions & 0 deletions demos/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Demos

- https://github.com/WorldBrain/storex-hub-demo-memex-gist-sharer
238 changes: 0 additions & 238 deletions demos/memex-gist-sharer/main.ts

This file was deleted.

31 changes: 17 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
{
"name": "@worldbrain/storex-hub",
"version": "0.3.0",
"version": "0.4.0",
"description": "A single data store for your local Storex apps",
"main": "lib/main.js",
"scripts": {
"start": "ts-node ts/main.ts",
"storex-hub": "ts-node/main.ts",
"memex-gist-sharer": "ts-node demos/memex-gist-sharer/main.ts",
"prepare": "tsc",
"prepare:watch": "npm run prepare -- -w",
"test": "mocha --require ts-node/register \"ts/**/*.test.ts\"",
Expand All @@ -25,48 +23,53 @@
"@worldbrain/storex-pattern-modules": "^0.4.0",
"bcrypt": "^4.0.1",
"crypto-random-string": "^3.2.0",
"fast-glob": "^3.2.2",
"gist-client": "^1.1.1",
"fake-indexeddb": "^2.0.4",
"koa": "^2.11.0",
"koa-bodyparser": "^4.2.1",
"koa-router": "^8.0.6",
"koa-session": "^5.12.3",
"koa-socket-2": "^1.2.0",
"lodash": "^4.17.10",
"source-map-support": "^0.4.18",
"prompt-sync": "^4.2.0",
"sqlite3": "^4.1.1",
"socket.io-client": "^2.3.0",
"typed-emitter": "^0.2.0",
"uuid": "^3.4.0"
"supertest": "^4.0.2",
"tempy": "^0.5.0",
"uuid": "^3.4.0",
"yargs": "^15.3.1"
},
"devDependencies": {
"@types/bcrypt": "^3.0.0",
"@types/chai": "^4.0.6",
"@types/events": "^1.2.0",
"@types/expect": "^1.20.4",
"@types/koa": "^2.11.0",
"@types/koa-bodyparser": "^4.3.0",
"@types/koa-router": "^7.4.0",
"@types/lodash": "^4.14.149",
"@types/minimist": "1.2.0",
"@types/mocha": "^2.2.44",
"@types/node": "^10.12.11",
"@types/socket.io": "^2.1.4",
"@types/socket.io-client": "^1.4.32",
"@types/supertest": "^2.0.8",
"@types/uuid": "^3.4.7",
"@types/yargs": "^11.0.0",
"chai": "^4.1.2",
"del": "^5.1.0",
"expect": "^23.5.0",
"expect": "^25.3.0",
"fake-fs": "^0.5.0",
"fake-indexeddb": "^2.0.4",
"mocha": "^4.0.1",
"nw": "^0.44.5",
"nw-builder": "^3.5.7",
"nyc": "^13.3.0",
"sinon": "^4.1.2",
"socket.io-client": "^2.3.0",
"supertest": "^4.0.2",
"tempy": "^0.5.0",
"source-map-support": "0.5.16",
"storex-hub-plugin-internal-selftest": "^0.0.2",
"ts-node": "^7.0.1",
"typescript": "^3.7.5"
"typescript": "^3.7.5",
"@types/prompt-sync": "^4.1.0",
"@worldbrain/storex-hub-interfaces": "^0.1.1"
},
"resolutions": {
"**/graphql": "^14.0.0"
Expand Down
23 changes: 15 additions & 8 deletions ts/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export interface ApplicationApiOptions {
callbacks?: AllStorexHubCallbacks_v0
}
export class Application {
private storage: Promise<Storage>
public storage: Promise<Storage>

private remoteSessions: { [identifier: string]: AllStorexHubCallbacks_v0 } = {}
private appEvents: { [identifier: string]: EventEmitter } = {}
private events = new EventEmitter() as TypedEmitter<{
Expand Down Expand Up @@ -81,7 +82,7 @@ export class Application {

if (request.type === 'app-availability-changed') {
const handler = (event: { app: string, availability: boolean }) => {
options?.callbacks?.handleEvent?.({
return options?.callbacks?.handleEvent?.({
event: {
type: 'app-availability-changed',
...event,
Expand All @@ -107,7 +108,7 @@ export class Application {
await subscription.unsubscribe()
delete subscriptions[subscriptionId]
},
emitEvent: async ({ event }) => {
emitEvent: async ({ event, synchronous }) => {
if (!session.identifiedApp) {
throw new Error('Cannot emit event if not identified')
}
Expand All @@ -117,10 +118,16 @@ export class Application {
throw new Error(`App ${session.identifiedApp.identifier} is not a remote app`)
}

appEvents.emit(event.type, {
...event,
app: session.identifiedApp.identifier
})
if (synchronous) {
await Promise.all(appEvents.listeners(event.type).map(handler => {
return handler({ ...event, app: session.identifiedApp!.identifier })
}))
} else {
appEvents.emit(event.type, {
...event,
app: session.identifiedApp.identifier
})
}
},
destroySession: async () => {
if (session.identifiedApp) {
Expand Down Expand Up @@ -168,7 +175,7 @@ export async function subsribeToRemoteEvent(request: RemoteSubscriptionRequest_v
}

const handler = (event: ClientEvent) => {
options.handleEvent?.({ event })
return options.handleEvent?.({ event })
}
appEvents.addListener(request.type, handler)

Expand Down
Empty file added ts/constants.ts
Empty file.
Loading

0 comments on commit 449f4ad

Please sign in to comment.