How to use the @fullstack-one/di.Container.get function in @fullstack-one/di

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 / 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 / examples / 1-orm-basic / index.ts View on Github external
require("dotenv").config();

process.on("unhandledRejection", (reason, p) => {
  console.error("Unhandled Rejection:", reason);
});

import { Container } from "@fullstack-one/di";
import { FullstackOneCore } from "fullstack-one";
import { ORM } from "@fullstack-one/db";

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

import Task from "./models/Task";

(async () => {
  await $one.boot();

  const task = new Task();
  task.title = "Catch the flight";
  await task.save();
  console.log("Task has been saved");

  const tasks = await Task.find();
  console.log("Loaded tasks: ", JSON.stringify(tasks, null, 2));
})();
github fullstack-build / fullstack-one / examples / 5-file-storage / index.ts View on Github external
require("dotenv").config();

process.on("unhandledRejection", (reason, p) => {
  console.error("Unhandled Rejection:", reason);
});

import { FullstackOneCore } from "fullstack-one";
import { ORM } from "@fullstack-one/db";
import { Auth, AuthProviderEmail, AuthProviderPassword, IProofMailPayload } from "@fullstack-one/auth";
import { Container } from "@fullstack-one/di";
import { FileStorage } from "@fullstack-one/file-storage";
import { GraphQl } from "@fullstack-one/graphql";
import User from "./models/User";
import { IUserAuthentication } from "@fullstack-one/auth";

const $one: FullstackOneCore = Container.get(FullstackOneCore);
const $orm: ORM = Container.get(ORM);
const $fs: FileStorage = Container.get(FileStorage);
const $auth: Auth = Container.get(Auth);
const $gql: GraphQl = Container.get(GraphQl);
const $authProviderEmail: AuthProviderEmail = Container.get(AuthProviderEmail);
const $authProviderPassword: AuthProviderPassword = Container.get(AuthProviderPassword);

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

$authProviderEmail.registerSendMailCallback((mail: IProofMailPayload) => {
  console.error("authProviderEmail.sendMailCallback", JSON.stringify(mail, null, 2));
});

$orm.addEntity(User);
github fullstack-build / fullstack-one / examples / 5-file-storage / index.ts View on Github external
console.error("Unhandled Rejection:", reason);
});

import { FullstackOneCore } from "fullstack-one";
import { ORM } from "@fullstack-one/db";
import { Auth, AuthProviderEmail, AuthProviderPassword, IProofMailPayload } from "@fullstack-one/auth";
import { Container } from "@fullstack-one/di";
import { FileStorage } from "@fullstack-one/file-storage";
import { GraphQl } from "@fullstack-one/graphql";
import User from "./models/User";
import { IUserAuthentication } from "@fullstack-one/auth";

const $one: FullstackOneCore = Container.get(FullstackOneCore);
const $orm: ORM = Container.get(ORM);
const $fs: FileStorage = Container.get(FileStorage);
const $auth: Auth = Container.get(Auth);
const $gql: GraphQl = Container.get(GraphQl);
const $authProviderEmail: AuthProviderEmail = Container.get(AuthProviderEmail);
const $authProviderPassword: AuthProviderPassword = Container.get(AuthProviderPassword);

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

$authProviderEmail.registerSendMailCallback((mail: IProofMailPayload) => {
  console.error("authProviderEmail.sendMailCallback", JSON.stringify(mail, null, 2));
});

$orm.addEntity(User);

$gql.addResolvers({
  someMutation: () => {
github fullstack-build / fullstack-one / examples / 5-file-storage / index.ts View on Github external
import { FullstackOneCore } from "fullstack-one";
import { Auth, AuthProviderEmail, AuthProviderPassword } from "@fullstack-one/auth";
import { ORM } from "@fullstack-one/db";
import { Container } from "@fullstack-one/di";
import { FileStorage } from "@fullstack-one/file-storage";
import { GraphQl } from "@fullstack-one/graphql";
import User from "./models/User";

const $one: FullstackOneCore = Container.get(FullstackOneCore);
const $fs: FileStorage = Container.get(FileStorage);
const $orm: ORM = Container.get(ORM);
const $auth: Auth = Container.get(Auth);
const $gql: GraphQl = Container.get(GraphQl);
const $authProviderEmail: AuthProviderEmail = Container.get(AuthProviderEmail);
const $authProviderPassword: AuthProviderPassword = Container.get(AuthProviderPassword);

$orm.addEntity(User);

$gql.addResolvers({
  someMutation: () => {
    return "Hello Mutation";
  },
  someQuery: () => {
    return "Hello query";
  }
});

(async () => {
  await $one.boot();
})();
github fullstack-build / fullstack-one / examples / 5-file-storage / index.ts View on Github external
});

import { FullstackOneCore } from "fullstack-one";
import { Auth, AuthProviderEmail, AuthProviderPassword } from "@fullstack-one/auth";
import { ORM } from "@fullstack-one/db";
import { Container } from "@fullstack-one/di";
import { FileStorage } from "@fullstack-one/file-storage";
import { GraphQl } from "@fullstack-one/graphql";
import User from "./models/User";

const $one: FullstackOneCore = Container.get(FullstackOneCore);
const $fs: FileStorage = Container.get(FileStorage);
const $orm: ORM = Container.get(ORM);
const $auth: Auth = Container.get(Auth);
const $gql: GraphQl = Container.get(GraphQl);
const $authProviderEmail: AuthProviderEmail = Container.get(AuthProviderEmail);
const $authProviderPassword: AuthProviderPassword = Container.get(AuthProviderPassword);

$orm.addEntity(User);

$gql.addResolvers({
  someMutation: () => {
    return "Hello Mutation";
  },
  someQuery: () => {
    return "Hello query";
  }
});

(async () => {
  await $one.boot();
})();

@fullstack-one/di

fullstack.one helper package

MIT
Latest version published 3 years ago

Package Health Score

49 / 100
Full package analysis

Similar packages