Skip to content

Commit

Permalink
feat: allowing typescript inheritance for deepstream.io
Browse files Browse the repository at this point in the history
  • Loading branch information
yasserf committed Jan 28, 2018
1 parent 2293bbd commit 50776d5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
16 changes: 14 additions & 2 deletions src/config/config-initialiser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict'

import * as fs from 'fs'
import FileAuthenticationHandler from '../authentication/file-based-authentication-handler'
import OpenAuthenticationHandler from '../authentication/open-authentication-handler'
Expand All @@ -17,6 +15,16 @@ import * as fileUtils from './file-utils'

let commandLineArguments

const customPlugins = new Map()

/**
* Registers plugins by name. Useful when wanting to include
* custom plugins in a binary
*/
export const registerPlugin = function (name: string, construct: Function) {
customPlugins.set(name, construct)
}

/**
* Takes a configuration object and instantiates functional properties.
* CLI arguments will be considered.
Expand Down Expand Up @@ -196,6 +204,10 @@ function handleConnectionEndpoints (config: DeepstreamConfig, services: any): Ar
* CLI arguments will be considered.
*/
function resolvePluginClass (plugin: PluginConfig, type: string): any {
if (customPlugins.has(plugin.name)) {
return customPlugins.get(plugin.name)
}

// nexe needs *global.require* for __dynamic__ modules
// but browserify and proxyquire can't handle *global.require*
const req = global && global.require ? global.require : require
Expand Down
8 changes: 4 additions & 4 deletions src/deepstream.io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ process.title = 'deepstream server'
export class Deepstream extends EventEmitter {
public constants: any

private config: DeepstreamConfig
private services: DeepstreamServices
protected config: DeepstreamConfig
protected services: DeepstreamServices

private messageProcessor: any
private messageDistributor: any
Expand Down Expand Up @@ -193,7 +193,7 @@ export class Deepstream extends EventEmitter {
/**
* Invoked once the logger is initialised. Initialises any built-in or custom Deepstream plugins.
*/
private pluginInit (): void {
protected pluginInit (): void {
this.services.message = new MessageConnector(this.config, this.services, 'deepstream')

const infoLogger = message => this.services.logger.info(EVENT.INFO, message)
Expand Down Expand Up @@ -239,7 +239,7 @@ export class Deepstream extends EventEmitter {
* Invoked once all plugins are initialised. Instantiates the messaging pipeline and
* the various handlers.
*/
private serviceInit (): void {
protected serviceInit (): void {
this.messageProcessor = new MessageProcessor(this.config, this.services)
this.messageDistributor = new MessageDistributor(this.config, this.services)

Expand Down
2 changes: 0 additions & 2 deletions test-e2e/tools/cluster.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict'

const { Deepstream } = require('../../dist/src/deepstream.io')
const LocalCache = require('../../dist/src/default-plugins/local-cache').default
const localCache = new LocalCache()
Expand Down

0 comments on commit 50776d5

Please sign in to comment.