How to use @fullstack-one/di - 10 common examples

To help you get started, we’ve selected a few @fullstack-one/di 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 fullstack-build / fullstack-one / packages / cli / lib / migrate-db / index.ts View on Github external
const projectMainFile = `${currentWorkDirectory}/index.ts`;
console.log(`Current work directory: ${currentWorkDirectory}`);
console.log(`Assumed ProjectRootMainFile: ${projectMainFile}`);
console.log();

// Manipulate main file name, so @fullstack-one/config gets the config and we can get the env.
require.main.filename = projectMainFile;
const dotEnvPath = `${currentWorkDirectory}/.env`;
dotenv.config({ path: dotEnvPath });

import { Container } from "@fullstack-one/di";
import { BootLoader } from "@fullstack-one/boot-loader";
import { AutoMigrate } from "@fullstack-one/auto-migrate";

const $bootLoader: BootLoader = Container.get(BootLoader);
const $autoMigrate: AutoMigrate = Container.get(AutoMigrate);

console.log();
console.log("Start booting including migration of db by auto-migrate ...");
console.log();
$bootLoader.boot().then(() => {
  console.log();
  console.log("Finished booting and db migration.");
  process.exit();
});
github fullstack-build / fullstack-one / examples / fullstack-one-example / index.ts View on Github external
console.error("Unhandled Rejection:", reason);
  // application specific logging, throwing an error, or other logic here
});

import { Container } from "@fullstack-one/di";
import { FullstackOneCore } from "fullstack-one";
import { GracefulShutdown } from "@fullstack-one/graceful-shutdown";
import { GraphQl } from "@fullstack-one/graphql";
import { AutoMigrate } from "@fullstack-one/auto-migrate";
import { ORM } from "@fullstack-one/db";
import { FileStorage } from "@fullstack-one/file-storage";
import { Auth, AuthProviderPassword, AuthProviderEmail, AuthProviderOAuth, IProofMailPayload, IUserAuthentication } from "@fullstack-one/auth";
import { NotificationsEmail } from "@fullstack-one/notifications";
import { EventEmitter } from "@fullstack-one/events";

const $one: FullstackOneCore = Container.get(FullstackOneCore);
const $gql: GraphQl = Container.get(GraphQl);
const $gs: GracefulShutdown = Container.get(GracefulShutdown);
const $autoMigrate: AutoMigrate = Container.get(AutoMigrate);
const $fs: FileStorage = Container.get(FileStorage);

const $orm: ORM = Container.get(ORM);

const $auth: Auth = Container.get(Auth);

$auth.registerUserRegistrationCallback((userAuthentication: IUserAuthentication) => {
  console.log("USER REGISTERED", JSON.stringify(userAuthentication, null, 2));
});

const $authProviderPassword = Container.get(AuthProviderPassword);
const $authProviderOAuth = Container.get(AuthProviderOAuth);
const $authProviderEmail = Container.get(AuthProviderEmail);
github fullstack-build / fullstack-one / packages / db / lib / DbAppClient.ts View on Github external
const dbName = this.credentials.database;
      const dbNodes = await this.pgClient.query(
        `SELECT * FROM pg_stat_activity WHERE datname = '${dbName}' AND application_name LIKE '${this.applicationNamePrefix}%';`
      );

      // collect all connected node IDs
      const nodeIds: [string] = dbNodes.rows.map((row) => {
        // remove prefix from node name and keep only node ID
        return row.application_name.replace(this.applicationNamePrefix, "");
      }) as [string];

      // check if number of nodes has changed
      let knownNodeIds: string[] = [];
      try {
        // TODO: Evaluate if its a good idea to push it into container or keep it as a public readonly property of DB
        knownNodeIds = Container.get("knownNodeIds");
      } catch {
        // ignore error
      }

      if (knownNodeIds.length !== nodeIds.length) {
        knownNodeIds = nodeIds;
        // update known IDs in DI
        Container.set("knownNodeIds", knownNodeIds);

        this.logger.debug("Postgres number connected clients changed", knownNodeIds);
        this.eventEmitter.emit("connected.nodes.changed");
      }
    } catch (err) {
      this.logger.warn("updateNodeIdsFromDb", err);
    }
  }
github fullstack-build / fullstack-one / packages / events / dist / index.js View on Github external
return __awaiter(this, void 0, void 0, function* () {
            const env = di_1.Container.get("ENVIRONMENT");
            this.nodeId = env.nodeId;
            this.eventEmitter = new eventemitter2_1.EventEmitter2(this.CONFIG.eventEmitter);
            this.dbClient = di_1.Container.get(db_1.DbAppClient);
            yield this.finishInitialisation();
            // set listeners that were cached during booting, clean cache afterwards
            Object.values(this.listenersCache).forEach((eventListeners) => {
                Object.values(eventListeners).forEach((listener) => {
                    this._on(listener.eventName, listener.options, listener.callback);
                });
            });
            this.listenersCache = {};
            // fire events that were cached during booting, clean cache afterwards
            Object.entries(this.emittersCache).forEach((emitterEntry) => {
                const eventName = emitterEntry[0];
                const eventEmitters = emitterEntry[1];
                Object.values(eventEmitters).forEach((emitter) => {
                    this._emit(eventName, emitter.nodeId, ...emitter.args);
                });
            });
github fullstack-build / fullstack-one / packages / db / lib / DbAppClient.ts View on Github external
return row.application_name.replace(this.applicationNamePrefix, "");
      }) as [string];

      // check if number of nodes has changed
      let knownNodeIds: string[] = [];
      try {
        // TODO: Evaluate if its a good idea to push it into container or keep it as a public readonly property of DB
        knownNodeIds = Container.get("knownNodeIds");
      } catch {
        // ignore error
      }

      if (knownNodeIds.length !== nodeIds.length) {
        knownNodeIds = nodeIds;
        // update known IDs in DI
        Container.set("knownNodeIds", knownNodeIds);

        this.logger.debug("Postgres number connected clients changed", knownNodeIds);
        this.eventEmitter.emit("connected.nodes.changed");
      }
    } catch (err) {
      this.logger.warn("updateNodeIdsFromDb", err);
    }
  }
github fullstack-build / fullstack-one / packages / boot-scripts / lib / index.ts View on Github external
constructor(@Inject((type) => LoggerFactory) loggerFactory, @Inject((tpye) => BootLoader) bootLoader) {
    this.logger = loggerFactory.create(this.constructor.name);

    // get settings from DI container
    this.ENVIRONMENT = Container.get("ENVIRONMENT");

    bootLoader.addBootFunction(this.constructor.name, this.boot.bind(this));
  }
github fullstack-build / fullstack-one / packages / schema-builder / lib / db-schema-builder / index.ts View on Github external
import * as _ from "lodash";
import * as fastGlob from "fast-glob";
import * as fs from "fs";
import { diff } from "deep-diff";

import { BootLoader } from "@fullstack-one/boot-loader";
import { Service, Container, Inject } from "@fullstack-one/di";
import { Config, IEnvironment } from "@fullstack-one/config";
import { LoggerFactory, ILogger } from "@fullstack-one/logger";
import { DbAppClient, PgClient } from "@fullstack-one/db";
import { IDbMeta } from "./IDbMeta";
import { MigrationObject } from "./migrationObject";
import { SqlObjFromMigrationObject } from "./toPg/createSqlObjFromMigrationObject";

@Service()
export class DbSchemaBuilder {
  private fromDbMeta: IDbMeta;
  private toDbMeta: IDbMeta;
  private migrationObject: MigrationObject;
  private dbAppClient: DbAppClient;
  private initSqlPaths = [`${__dirname}/../..`];
  private dbConfig;
  private schemaBuilderConfig;
  private permissionSqlStatements: any = [];

  // DI
  private readonly config;
  private readonly logger: ILogger;

  constructor(
    @Inject((type) => BootLoader) bootLoader,
github fullstack-build / fullstack-one / packages / graphql / lib / index.ts View on Github external
import * as KoaRouter from 'koa-router';

import { getResolvers } from './queryBuilder/resolvers';

// fullstack-one core
import { Service, Inject, Container } from '@fullstack-one/di';
// DI imports
import { LoggerFactory, ILogger } from '@fullstack-one/logger';
import { Config, IEnvironment } from '@fullstack-one/config';
import { BootLoader } from '@fullstack-one/boot-loader';
import { GraphQlParser } from '@fullstack-one/graphql-parser';
import { helper } from '@fullstack-one/helper';
import { Server } from '@fullstack-one/server';
import { DbGeneralPool } from '@fullstack-one/db';

@Service()
export class GraphQl {

  private graphQlConfig: any;

  // DI
  private logger: ILogger;
  private ENVIRONMENT: IEnvironment;
  private gqlParser: GraphQlParser;
  private server: Server;
  private dbGeneralPool: DbGeneralPool;
  private resolvers: any = {};
  private customQueries: any = [];
  private customMutations: any = [];
  private customFields: any = {};

  private preQueryHooks = [];
github fullstack-build / fullstack-one / packages / server / lib / index.ts View on Github external
import { Service, Container, Inject } from "@fullstack-one/di";
import { Config, IEnvironment } from "@fullstack-one/config";
import { ILogger, LoggerFactory } from "@fullstack-one/logger";
import { BootLoader } from "@fullstack-one/boot-loader";
import { GracefulShutdown } from "@fullstack-one/graceful-shutdown";

import * as http from "http";
// other npm dependencies
import * as Koa from "koa";
import * as compress from "koa-compress";
import * as bodyParser from "koa-bodyparser";

export { Koa };

@Service()
export class Server {
  private serverConfig;
  private server: http.Server;
  private app: Koa;

  private loggerFactory: LoggerFactory;
  private logger: ILogger;
  private ENVIRONMENT: IEnvironment;
  private readonly bootLoader: BootLoader;
  // private eventEmitter: EventEmitter;

  constructor(
    // @Inject(type => EventEmitter) eventEmitter?,
    @Inject((type) => LoggerFactory) loggerFactory: LoggerFactory,
    @Inject((type) => Config) config: Config,
    @Inject((tpye) => BootLoader) bootLoader: BootLoader,
github fullstack-build / fullstack-one / packages / auth / lib / index.ts View on Github external
import { AuthProvider } from "./AuthProvider";
import { IAuthFactorForProof, IUserAuthentication, ILoginData } from "./interfaces";
import { CryptoFactory } from "./CryptoFactory";
import { SignHelper } from "./SignHelper";
import * as _ from "lodash";

const schema = fs.readFileSync(require.resolve("../schema.gql"), "utf-8");

export * from "./SignHelper";
export * from "./interfaces";
export * from "./AuthProviders/AuthProviderEmail";
export * from "./AuthProviders/AuthProviderOAuth";
export * from "./AuthProviders/AuthProviderPassword";
export { AuthProvider, IAuthFactorForProof };

@Service()
export class Auth {
  private authConfig;
  private cryptoFactory: CryptoFactory;
  private signHelper: SignHelper;
  private authQueryHelper: AuthQueryHelper;
  private csrfProtection: CSRFProtection;
  private accessTokenParser: AccessTokenParser;
  private orm: ORM;

  // DI
  private logger: ILogger;
  private loggerFactory: LoggerFactory;
  private userRegistrationCallback: (userAuthentication: IUserAuthentication) => void;

  public readonly authConnector: AuthConnector;

@fullstack-one/di

fullstack.one helper package

MIT
Latest version published 3 years ago

Package Health Score

49 / 100
Full package analysis

Similar packages