How to use the typedi.Token function in typedi

To help you get started, we’ve selected a few typedi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github umijs / vscode-extension-umi-pro / src / services / parser / modelEffectsParser.ts View on Github external
import { Service, Token, Inject } from 'typedi';
import { IVscodeService, VscodeServiceToken } from './../vscodeService';
import { isNotNull, sourceLocationToRange } from '../../common/utils';
import generate from '@babel/generator';
import { isEqual } from 'lodash';

interface ModelEffectsCode {
  range: Range;
  code: string;
}

export interface IModelEffectsParser {
  parseFile(path: string): Promise;
}

export const ModelEffectsParserToken = new Token();

const reduxSagaEffectsCommands = ['put', 'call', 'select', 'cancel', 'take', 'all'];

@Service(ModelEffectsParserToken)
// eslint-disable-next-line @typescript-eslint/class-name-casing
class _ModelEffectParser implements IModelEffectsParser {
  public readonly vscodeService: IVscodeService;

  constructor(
    @Inject(VscodeServiceToken)
    vscodeService: IVscodeService
  ) {
    this.vscodeService = vscodeService;
  }

  public async parseFile(filePath: string) {
github webclipper / web-clipper / src / service / common / powerpack.ts View on Github external
avatar_url: string;
  expire_date: string;
}

export interface IPowerpackService {
  userInfo: PowerpackUserInfo | null;
  accessToken?: string;
  bought: boolean;
  expired: boolean;

  startup(): Promise;
  logout(): Promise;
  refresh(): Promise;
}

export const IPowerpackService = new Token();
github youzan / zan-proxy / packages / libproxy / src / service / Host.ts View on Github external
export interface HostService extends HasAsyncInit {
  resolveHost(hostname: string): Promise;
  createHostRecord(
    name: string,
    description: string,
    content?,
  ): Promise;
  deleteHostRecord(name: string): Promise;
  setUseHost(name: string): Promise;
  getHostRecord(name: string): HostRecord | undefined;
  saveHostRecord(name: string, content: object): Promise;
  getHostRecordList(): Promise;
}

export const HostServiceToken = new Token('service.host');
export const HostStorageToken = new Token('storage.host');
github patrickmichalina / fusing-angular-v1-archived / src / server / rest-api / index.ts View on Github external
import { auth0ServerValidationNoAngularFactory, azNoAngular } from './helpers'
import * as express from 'express'
import * as bodyParser from 'body-parser'
import { map } from 'rxjs/operators'
import { AuthOptions } from 'auth0-js'

const swaggerJSDoc = require('swagger-jsdoc')
const swaggerUi = require('swagger-ui-express')

useContainer(Container)

export type Auth0Config = AuthOptions
export type SendGridAPIKey = string
export type Auth0Cert = string
export const AUTH0_MANAGEMENT_CLIENT_CONFIG = new Token()
export const SENDGRID_API_KEY = new Token()
export const AUTH0_CERT = new Token()

Container.set(
  AUTH0_CERT,
  process.env.AUTH0_CERT && process.env.AUTH0_CERT.replace(/\\n/g, '\n')
)
Container.set(SENDGRID_API_KEY, process.env.SENDGRID_API_KEY)
Container.set(AUTH0_MANAGEMENT_CLIENT_CONFIG, {
  domain: process.env.AUTH0_DOMAIN || '',
  clientID: process.env.AUTH0_CLIENT_ID || ''
} as AuthOptions)

export const useApi = (app: express.Application) => {
  const swaggerSpec = swaggerJSDoc({
    swaggerDefinition: {
      info: {
github youzan / zan-proxy / packages / libproxy / src / service / Host.ts View on Github external
export interface HostService extends HasAsyncInit {
  resolveHost(hostname: string): Promise;
  createHostRecord(
    name: string,
    description: string,
    content?,
  ): Promise;
  deleteHostRecord(name: string): Promise;
  setUseHost(name: string): Promise;
  getHostRecord(name: string): HostRecord | undefined;
  saveHostRecord(name: string, content: object): Promise;
  getHostRecordList(): Promise;
}

export const HostServiceToken = new Token('service.host');
export const HostStorageToken = new Token('storage.host');
github umijs / vscode-extension-umi-pro / src / services / modelReferenceService.ts View on Github external
namespace: string;
  action: string;
}
interface FileInfoCache {
  [filePath: string]: Action[];
}

interface ReferenceCache {
  [model: string]: {
    [action: string]: {
      [filePath: string]: Location[];
    };
  };
}

export const ModelReferenceServiceToken = new Token();

@Service(ModelReferenceServiceToken)
export default class ModelReferenceService implements IModelReferenceService {
  private modelReferenceParser: IModelReferenceParser;
  private modelReferenceMap: Map;
  private projectFileModelsMap: Map;
  private modelInfoService: IModelInfoService;
  private logger: ILogger;
  private vscodeService: IVscodeService;

  constructor(
    @Inject(LoggerService)
    logger: ILogger,
    @Inject(VscodeServiceToken)
    vscodeService: IVscodeService,
    @Inject(ModelInfoServiceToken)
github wemaintain / auto-relay / packages / core / src / services / auto-relay-config.service.ts View on Github external
import { SharedObjectFactory } from '../graphql/shared-object.factory'
import { Container, Service, Token } from 'typedi'
import { AutoRelayConfigArgs, AutoRelayConfigArgsExistingModel, AutoRelayConfigArgsNoModel, AutoRelayOrmConnect } from '../interfaces/auto-relay-config.interface'
import { ClassValueThunk } from '..'
import * as Relay from 'graphql-relay'

export const PREFIX = new Token('PREFIX')
export const CONNECTION_BASE_OBJECT = new Token>('CONNECTION_BASE_OBJECT')
export const PAGINATION_OBJECT = new Token>('PAGINATION_OBJECT')
export const CONNECTIONARGS_OBJECT = new Token>('CONNECTIONARGS_OBJECT')
export const ORM_CONNECTION = new Token('ORM_CONNECTION')

@Service()
export class AutoRelayConfig {

  protected static _sharedObjectFactory: SharedObjectFactory = Container.get(SharedObjectFactory)
  protected static _config: AutoRelayConfigArgs = {  } as any

  constructor(
    config: AutoRelayConfigArgs
  ) {
    if (!config) throw new Error(`No config supplied to AutoRelay`)
    Container.remove(PAGINATION_OBJECT, CONNECTIONARGS_OBJECT)

    this._registerOrm(config)
github patrickmichalina / fusing-angular-v1-archived / src / server / rest-api / index.ts View on Github external
} from '../../client/app/app.module'
import { auth0ServerValidationNoAngularFactory, azNoAngular } from './helpers'
import * as express from 'express'
import * as bodyParser from 'body-parser'
import { map } from 'rxjs/operators'
import { AuthOptions } from 'auth0-js'

const swaggerJSDoc = require('swagger-jsdoc')
const swaggerUi = require('swagger-ui-express')

useContainer(Container)

export type Auth0Config = AuthOptions
export type SendGridAPIKey = string
export type Auth0Cert = string
export const AUTH0_MANAGEMENT_CLIENT_CONFIG = new Token()
export const SENDGRID_API_KEY = new Token()
export const AUTH0_CERT = new Token()

Container.set(
  AUTH0_CERT,
  process.env.AUTH0_CERT && process.env.AUTH0_CERT.replace(/\\n/g, '\n')
)
Container.set(SENDGRID_API_KEY, process.env.SENDGRID_API_KEY)
Container.set(AUTH0_MANAGEMENT_CLIENT_CONFIG, {
  domain: process.env.AUTH0_DOMAIN || '',
  clientID: process.env.AUTH0_CLIENT_ID || ''
} as AuthOptions)

export const useApi = (app: express.Application) => {
  const swaggerSpec = swaggerJSDoc({
    swaggerDefinition: {
github umijs / vscode-extension-umi-pro / src / services / vscodeService.ts View on Github external
workspaceFolders: null,
      workspaceConfigurations: null,
    };
  }
  const workspaceConfigurations = workspaceFolders.map(f =>
    vscode.workspace.getConfiguration(CONFIG_NAMESPACE, f.uri)
  );
  return { workspaceFolders, workspaceConfigurations };
}

export async function loadVscodeService(service: IVscodeService) {
  const { workspaceFolders, workspaceConfigurations } = await getVscodeServiceArgs();
  service.load(workspaceFolders, workspaceConfigurations);
}

export const VscodeServiceToken = new Token();

@Service(VscodeServiceToken)
export class VscodeService implements IVscodeService {
  private workspaceFolders: vscode.WorkspaceFolder[];
  private workspaceConfigurations: vscode.WorkspaceConfiguration[];

  constructor() {
    this.workspaceFolders = [];
    this.workspaceConfigurations = [];
  }

  load(
    workspaceFolders: vscode.WorkspaceFolder[] | null,
    workspaceConfigurations: vscode.WorkspaceConfiguration[] | null
  ) {
    if (!workspaceConfigurations || !workspaceFolders) {
github patrickmichalina / fusing-angular-v1-archived / src / server / rest-api / index.ts View on Github external
import * as express from 'express'
import * as bodyParser from 'body-parser'
import { map } from 'rxjs/operators'
import { AuthOptions } from 'auth0-js'

const swaggerJSDoc = require('swagger-jsdoc')
const swaggerUi = require('swagger-ui-express')

useContainer(Container)

export type Auth0Config = AuthOptions
export type SendGridAPIKey = string
export type Auth0Cert = string
export const AUTH0_MANAGEMENT_CLIENT_CONFIG = new Token()
export const SENDGRID_API_KEY = new Token()
export const AUTH0_CERT = new Token()

Container.set(
  AUTH0_CERT,
  process.env.AUTH0_CERT && process.env.AUTH0_CERT.replace(/\\n/g, '\n')
)
Container.set(SENDGRID_API_KEY, process.env.SENDGRID_API_KEY)
Container.set(AUTH0_MANAGEMENT_CLIENT_CONFIG, {
  domain: process.env.AUTH0_DOMAIN || '',
  clientID: process.env.AUTH0_CLIENT_ID || ''
} as AuthOptions)

export const useApi = (app: express.Application) => {
  const swaggerSpec = swaggerJSDoc({
    swaggerDefinition: {
      info: {
        title: 'fusing-angular',