• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript joi.object函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中joi.object函数的典型用法代码示例。如果您正苦于以下问题:TypeScript object函数的具体用法?TypeScript object怎么用?TypeScript object使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了object函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: initStatusApi

export function initStatusApi(server: Server) {
  server.route({
    method: 'GET',
    path: `${ROOT}/server`,
    options: {
      validate: {
        query: Joi.object().keys({
          _debug: Joi.bool()
        })
      }
    },
    handler: req => {
      const setup = setupRequest(req);
      return getServerStatus({ setup }).catch(defaultErrorHandler);
    }
  });

  server.route({
    method: 'GET',
    path: `${ROOT}/agent`,
    options: {
      validate: {
        query: Joi.object().keys({
          _debug: Joi.bool()
        })
      }
    },
    handler: req => {
      const setup = setupRequest(req);
      return getAgentStatus({ setup }).catch(defaultErrorHandler);
    }
  });
}
开发者ID:njd5475,项目名称:kibana,代码行数:33,代码来源:status_check.ts


示例2: reply

export const createBeatUpdateRoute = (libs: CMServerLibs) => ({
  method: 'PUT',
  path: '/api/beats/agent/{beatId}',
  licenseRequired: true,
  config: {
    auth: {
      mode: 'optional',
    },
    validate: {
      headers: Joi.object({
        'kbn-beats-access-token': Joi.string(),
      }).options({
        allowUnknown: true,
      }),
      params: Joi.object({
        beatId: Joi.string(),
      }),
      payload: Joi.object({
        active: Joi.bool(),
        ephemeral_id: Joi.string(),
        host_name: Joi.string(),
        local_configuration_yml: Joi.string(),
        metadata: Joi.object(),
        name: Joi.string(),
        type: Joi.string(),
        version: Joi.string(),
      }),
    },
  },
  handler: async (request: FrameworkRequest, reply: any) => {
    const { beatId } = request.params;
    const accessToken = request.headers['kbn-beats-access-token'];
    const remoteAddress = request.info.remoteAddress;
    const userOrToken = accessToken || request.user;

    if (request.user.kind === 'unauthenticated' && request.payload.active !== undefined) {
      return reply({ message: 'access-token is not a valid auth type to change beat status' }).code(
        401
      );
    }

    try {
      const status = await libs.beats.update(userOrToken, beatId, {
        ...request.payload,
        host_ip: remoteAddress,
      });

      switch (status) {
        case 'beat-not-found':
          return reply({ message: 'Beat not found', success: false }).code(404);
        case 'invalid-access-token':
          return reply({ message: 'Invalid access token', success: false }).code(401);
      }

      reply({ success: true }).code(204);
    } catch (err) {
      return reply(wrapEsError(err));
    }
  },
});
开发者ID:salihkardan,项目名称:kibana,代码行数:60,代码来源:update.ts


示例3: reply

export const createTagRemovalsRoute = (libs: CMServerLibs) => ({
  method: 'POST',
  path: '/api/beats/agents_tags/removals',
  licenseRequired: true,
  config: {
    validate: {
      payload: Joi.object({
        removals: Joi.array().items(
          Joi.object({
            beatId: Joi.string().required(),
            tag: Joi.string().required(),
          })
        ),
      }).required(),
    },
  },
  handler: async (request: FrameworkRequest, reply: any) => {
    const { removals } = request.payload;

    try {
      const response = await libs.beats.removeTagsFromBeats(request.user, removals);
      reply(response);
    } catch (err) {
      // TODO move this to kibana route thing in adapter
      return reply(wrapEsError(err));
    }
  },
});
开发者ID:salihkardan,项目名称:kibana,代码行数:28,代码来源:tag_removal.ts


示例4: wrapEsError

export const createSetTagRoute = (libs: CMServerLibs) => ({
  method: 'PUT',
  path: '/api/beats/tag/{tagId}',
  licenseRequired: REQUIRED_LICENSES,
  requiredRoles: ['beats_admin'],
  config: {
    validate: {
      params: Joi.object({
        tagId: Joi.string(),
      }),
      payload: Joi.object({
        color: Joi.string(),
        name: Joi.string(),
      }),
    },
  },
  handler: async (request: FrameworkRequest) => {
    const defaultConfig = {
      id: request.params.tagId,
      name: request.params.tagId,
      color: '#DD0A73',
      hasConfigurationBlocksTypes: [],
    };
    const config = { ...defaultConfig, ...get(request, 'payload', {}) };

    try {
      const id = await libs.tags.upsertTag(request.user, config);

      return { success: true, id };
    } catch (err) {
      // TODO move this to kibana route thing in adapter
      return wrapEsError(err);
    }
  },
});
开发者ID:lucabelluccini,项目名称:kibana,代码行数:35,代码来源:set.ts


示例5: handler

export const registerCapabilitiesRoute = (
  server: Server,
  defaultCapabilities: Capabilities,
  modifiers: CapabilitiesModifier[]
) => {
  server.route({
    path: '/api/capabilities',
    method: 'POST',
    options: {
      validate: {
        payload: Joi.object({
          capabilities: Joi.object().required(),
        }).required(),
      },
    },
    async handler(request) {
      const { capabilities } = request.payload as { capabilities: Capabilities };
      return {
        capabilities: await resolveCapabilities(
          request,
          modifiers,
          defaultCapabilities,
          capabilities
        ),
      };
    },
  });
};
开发者ID:elastic,项目名称:kibana,代码行数:28,代码来源:capabilities_route.ts


示例6: reply

export const createListTagsRoute = (libs: CMServerLibs) => ({
  method: 'GET',
  path: '/api/beats/tags',
  validate: {
    headers: Joi.object({
      'kbn-beats-enrollment-token': Joi.string().required(),
    }).options({
      allowUnknown: true,
    }),
    query: Joi.object({
      ESQuery: Joi.string(),
    }),
  },
  licenseRequired: true,
  handler: async (request: any, reply: any) => {
    let tags: BeatTag[];
    try {
      tags = await libs.tags.getAll(
        request.user
        // request.query ? JSON.parse(request.query.ESQuery) : undefined
      );
    } catch (err) {
      return reply(wrapEsError(err));
    }

    reply(tags);
  },
});
开发者ID:salihkardan,项目名称:kibana,代码行数:28,代码来源:list.ts


示例7: async

export const createSetTagRoute = (libs: CMServerLibs) => ({
  method: 'PUT',
  path: '/api/beats/tag/{tagId}',
  licenseRequired: REQUIRED_LICENSES,
  requiredRoles: ['beats_admin'],
  config: {
    validate: {
      params: Joi.object({
        tagId: Joi.string(),
      }),
      payload: Joi.object({
        color: Joi.string(),
        name: Joi.string(),
      }),
    },
  },
  handler: async (request: FrameworkRequest): Promise<ReturnTypeUpsert<BeatTag>> => {
    const defaultConfig = {
      id: request.params.tagId,
      name: request.params.tagId,
      color: '#DD0A73',
      hasConfigurationBlocksTypes: [],
    };
    const config = { ...defaultConfig, ...get(request, 'payload', {}) };

    const id = await libs.tags.upsertTag(request.user, config);
    const tag = await libs.tags.getWithIds(request.user, [id]);

    // TODO the action needs to be surfaced
    return { success: true, item: tag[0], action: 'created' };
  },
});
开发者ID:njd5475,项目名称:kibana,代码行数:32,代码来源:set.ts


示例8: async

export const createListTagsRoute = (libs: CMServerLibs) => ({
  method: 'GET',
  path: '/api/beats/tags',
  requiredRoles: ['beats_admin'],
  licenseRequired: REQUIRED_LICENSES,
  validate: {
    headers: Joi.object({
      'kbn-beats-enrollment-token': Joi.string().required(),
    }).options({
      allowUnknown: true,
    }),
    query: Joi.object({
      ESQuery: Joi.string(),
    }),
  },
  handler: async (request: FrameworkRequest): Promise<ReturnTypeList<BeatTag>> => {
    let tags: BeatTag[];
    tags = await libs.tags.getAll(
      request.user,
      request.query && request.query.ESQuery ? JSON.parse(request.query.ESQuery) : undefined
    );

    return { list: tags, success: true, page: -1, total: -1 };
  },
});
开发者ID:njd5475,项目名称:kibana,代码行数:25,代码来源:list.ts


示例9: wrapEsError

export const createTagAssignmentsRoute = (libs: CMServerLibs) => ({
  method: 'POST',
  path: '/api/beats/agents_tags/assignments',
  licenseRequired: REQUIRED_LICENSES,
  requiredRoles: ['beats_admin'],
  config: {
    validate: {
      payload: Joi.object({
        assignments: Joi.array().items(
          Joi.object({
            beatId: Joi.string().required(),
            tag: Joi.string().required(),
          })
        ),
      }).required(),
    },
  },
  handler: async (request: FrameworkRequest) => {
    const { assignments }: { assignments: BeatsTagAssignment[] } = request.payload;

    try {
      const response = await libs.beats.assignTagsToBeats(request.user, assignments);
      return response;
    } catch (err) {
      // TODO move this to kibana route thing in adapter
      return wrapEsError(err);
    }
  },
});
开发者ID:lucabelluccini,项目名称:kibana,代码行数:29,代码来源:tag_assignment.ts


示例10: handler

export const createResolveImportErrorsRoute = (prereqs: Prerequisites, server: Hapi.Server) => ({
  path: '/api/saved_objects/_resolve_import_errors',
  method: 'POST',
  config: {
    pre: [prereqs.getSavedObjectsClient],
    payload: {
      maxBytes: server.config().get('savedObjects.maxImportPayloadBytes'),
      output: 'stream',
      allow: 'multipart/form-data',
    },
    validate: {
      payload: Joi.object({
        file: Joi.object().required(),
        overwrites: Joi.array()
          .items(
            Joi.object({
              type: Joi.string().required(),
              id: Joi.string().required(),
            })
          )
          .default([]),
        replaceReferences: Joi.array()
          .items(
            Joi.object({
              type: Joi.string().required(),
              from: Joi.string().required(),
              to: Joi.string().required(),
            })
          )
          .default([]),
        skips: Joi.array()
          .items(
            Joi.object({
              type: Joi.string().required(),
              id: Joi.string().required(),
            })
          )
          .default([]),
      }).default(),
    },
  },
  async handler(request: ImportRequest) {
    const { savedObjectsClient } = request.pre;
    const { filename } = request.payload.file.hapi;
    const fileExtension = extname(filename).toLowerCase();
    if (fileExtension !== '.ndjson') {
      return Boom.badRequest(`Invalid file extension ${fileExtension}`);
    }
    return await resolveImportErrors({
      savedObjectsClient,
      readStream: request.payload.file,
      objectLimit: request.server.config().get('savedObjects.maxImportExportSize'),
      skips: request.payload.skips,
      overwrites: request.payload.overwrites,
      replaceReferences: request.payload.replaceReferences,
    });
  },
});
开发者ID:njd5475,项目名称:kibana,代码行数:58,代码来源:resolve_import_errors.ts



注:本文中的joi.object函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript joi.only函数代码示例发布时间:2022-05-25
下一篇:
TypeScript joi.number函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap