How to use @faasjs/deep_merge - 10 common examples

To help you get started, we’ve selected a few @faasjs/deep_merge 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 faasjs / faasjs / packages / tencentcloud / src / http / deploy.ts View on Github external
export default async function (this: Tencentcloud, data: DeployData, origin: any) {
  this.logger.info('开始发布网关');

  if (!this.config || !this.config.secretId || !this.config.secretKey) throw Error('Missing secretId or secretKey!');

  const config = deepMerge(origin);

  // 参数名适配
  config.config['requestConfig.path'] = config.config.path;
  delete config.config.path;

  if (config.config.method) {
    config.config['requestConfig.method'] = config.config.method;
    delete config.config.method;
  }
  if (config.config.timeout) {
    config.config.serviceTimeout = config.config.timeout;
    delete config.config.timeout;
  }
  if (config.config.functionName) {
    config.config.serviceScfFunctionName = config.config.functionName;
    delete config.config.functionName;
github faasjs / faasjs / packages / http / src / index.ts View on Github external
public async onDeploy (data: DeployData, next: Next) {
    this.logger.debug('[Http] 组装网关配置');
    this.logger.debug('%o', data);

    const config = deepMerge(data.config!.plugins![this.name || this.type], { config: this.config });

    // 根据文件及文件夹名生成路径
    config.config.path = '=/' + data.name!.replace(/_/g, '/').replace(/\/index$/, '');

    this.logger.debug('[Http] 组装完成 %o', config);

    // 引用服务商部署插件
    // eslint-disable-next-line security/detect-non-literal-require, @typescript-eslint/no-var-requires
    const Provider = require(config.provider.type);
    const provider = new Provider(config.provider.config);

    // 部署网关
    await provider.deploy(this.type, data, config);

    await next();
  }
github faasjs / faasjs / packages / deployer / src / index.ts View on Github external
public async deploy () {
    const data = this.deployData;
    const loadResult = await loadTs(data.filename, { tmp: true });

    const func = loadResult.module;
    if (!func) {
      throw Error(`Func load failed: ${data.filename}`);
    }

    if (func.config) {
      data.config = deepMerge(data.config, func.config);
    }

    data.dependencies = deepMerge(loadResult.dependencies, func.dependencies);

    // 按类型分类插件
    const includedCloudFunction = [];
    for (let i = 0; i < func.plugins.length; i++) {
      const plugin = func.plugins[i as number];
      if (!plugin.type) {
        data.logger!.error('Unknow plugin type: %o', plugin);
        throw Error('[Deployer] Unknow plugin type');
      }

      if (plugin.type === 'cloud_function') {
        includedCloudFunction.push({
          index: i,
github faasjs / faasjs / packages / cloud_function / src / index.ts View on Github external
public async onDeploy (data: DeployData, next: Next) {
    data.logger!.debug('[CloudFunction] 组装云函数配置');
    data.logger!.debug('%o', data);

    const config = deepMerge(data.config!.plugins![this.name || this.type], { config: this.config });

    data.logger!.debug('[CloudFunction] 组装完成 %o', config);

    // 引用服务商部署插件
    // eslint-disable-next-line security/detect-non-literal-require, @typescript-eslint/no-var-requires
    const Provider = require(config.provider.type);
    const provider = new Provider(config.provider.config);

    data.dependencies![config.provider.type as string] = loadNpmVersion(config.provider.type);

    // 部署云函数
    await provider.deploy(this.type, data, config);

    await next();
  }
github faasjs / faasjs / packages / load / src / load_config.ts View on Github external
const configs: { [key: string]: FuncConfig }[] = [];

    const paths = [this.root, '.'].concat(dirname(filename.replace(root, '')).split(sep));

    paths.reduce(function (base, path) {
      const root = join(base, path);
      const faas = join(root, 'faas.yaml');

      if (existsSync(faas)) {
        configs.push(safeLoad(readFileSync(faas).toString()));
      }

      return root;
    });

    this.origin = deepMerge(...configs);

    if (!this.origin.defaults) {
      throw Error('[faas.yaml] need defaults env.');
    }

    this.defaults = deepMerge(this.origin.defaults);

    for (const key in this.origin) {
      if (key !== 'defaults') {
        this[key as string] = deepMerge(this.origin.defaults, this.origin[key as string]);
      }

      const data = this[key as string];

      if (!data.providers) {
        throw Error(`[faas.yaml] missing key: ${key}/providers`);
github faasjs / faasjs / packages / load / src / load_config.ts View on Github external
}

      return root;
    });

    this.origin = deepMerge(...configs);

    if (!this.origin.defaults) {
      throw Error('[faas.yaml] need defaults env.');
    }

    this.defaults = deepMerge(this.origin.defaults);

    for (const key in this.origin) {
      if (key !== 'defaults') {
        this[key as string] = deepMerge(this.origin.defaults, this.origin[key as string]);
      }

      const data = this[key as string];

      if (!data.providers) {
        throw Error(`[faas.yaml] missing key: ${key}/providers`);
      }

      if (!data.plugins) {
        throw Error(`[faas.yaml] missing key: ${key}/plugins`);
      }

      for (const pluginKey in data.plugins) {
        const plugin = data.plugins[pluginKey as string];
        plugin.name = pluginKey;
        if (plugin.provider) {
github faasjs / faasjs / packages / sql / src / index.ts View on Github external
public async onMount (data: MountData, next: Next) {
    this.logger.debug('[Mount] begin');
    this.logger.time('sql');
    if (data.config.plugins[this.name]) {
      this.config = deepMerge(data.config.plugins[this.name || this.type].config, this.config);
    }

    this.logger.debug('conncet: %o', this.config);

    if (!this.adapterType) {
      this.adapterType = data.config.plugins[this.name || this.type].adapter;
    }

    switch (this.adapterType) {
      case 'sqlite':
        this.adapter = new Sqlite(this.config!);
        break;
      case 'postgresql':
        this.adapter = new Postgresql(this.config);
        break;
      case 'mysql':
github faasjs / faasjs / packages / http / src / index.ts View on Github external
public async onMount (data: MountData, next: Next) {
    this.logger.debug('[onMount] merge config');
    if (data.config.plugins[this.name || this.type]) {
      this.config = deepMerge(this.config, data.config.plugins[this.name || this.type].config);
    }

    this.logger.debug('[onMount] prepare cookie & session');
    this.cookie = new Cookie(this.config.cookie || {});
    this.session = this.cookie.session;

    if (this.validatorOptions) {
      this.logger.debug('[onMount] prepare validator');
      this.validator = new Validator(this.validatorOptions);
    }

    await next();
  }
github faasjs / faasjs / packages / load / src / load_config.ts View on Github external
if (!data.plugins) {
        throw Error(`[faas.yaml] missing key: ${key}/plugins`);
      }

      for (const pluginKey in data.plugins) {
        const plugin = data.plugins[pluginKey as string];
        plugin.name = pluginKey;
        if (plugin.provider) {
          if (typeof plugin.provider === 'string') {
            if (!data.providers[plugin.provider]) {
              throw Error(`[faas.yaml] missing provider: ${plugin.provider} <${key}/plugins/${pluginKey}>`);
            }
            plugin.provider = data.providers[plugin.provider];
          } else {
            plugin.provider = deepMerge(data.providers[plugin.provider], plugin.provider);
          }
        }
      }
    }
  }
}
github faasjs / faasjs / packages / redis / src / index.ts View on Github external
public async onMount (data: MountData, next: Next) {
    this.logger.debug('[Mount] begin');
    this.logger.time('redis');

    if (data.config.plugins[this.name || this.type]) {
      this.config = deepMerge(data.config.plugins[this.name || this.type].config, this.config);
    }

    this.logger.debug('conncet: %o', this.config);
    this.adapter = createClient(this.config);

    this.logger.timeEnd('redis', '[Mount] end');

    await next();
  }

@faasjs/deep_merge

A helper function to deep merge objects and array.

MIT
Latest version published 11 hours ago

Package Health Score

78 / 100
Full package analysis

Popular @faasjs/deep_merge functions

Similar packages