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

TypeScript joi.string函数代码示例

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

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



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

示例1: 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>> => {
    const 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:elastic,项目名称:kibana,代码行数:24,代码来源:list.ts


示例2: updateDoor

  public updateDoor(): Hapi.IRouteAdditionalConfigurationOptions {
    return {
      handler: (request: Hapi.Request, reply: Hapi.IReply) => {
        const id = request.params["id"]

        this.doorRepository.findById(id).then((door: IDoor) => {
          if (door) {
            var updateDoor: IDoor = request.payload;

            door.completed = updateDoor.completed;
            door.description = updateDoor.description;
            door.name = updateDoor.name;

            this.doorRepository.findByIdAndUpdate(id, door).then((updatedDoor: IDoor) => {
              reply(updatedDoor);
            }).catch((error) => {
              reply(Boom.badImplementation(error));
            });
          } else {
            reply(Boom.notFound());
          }
        }).catch((error) => {
          reply(Boom.badImplementation(error));
        });
      },
      tags: ['api', 'doors'],
      description: 'Update door by id.',
      validate: {
        params: {
          id: Joi.string().required()
        },
        payload: DoorModel.updateDoorModel
      },
      plugins: {
        'hapi-swagger': {
          responses: {
            '200': {
              'description': 'Deleted Door.',
              'schema': DoorModel.doorModel
            },
            '404': {
              'description': 'Door does not exists.'
            }
          }
        }
      }
    };
  }
开发者ID:Happy-Ferret,项目名称:wachschutz,代码行数:48,代码来源:doorController.ts


示例3: updateTask

  public updateTask(): Hapi.IRouteAdditionalConfigurationOptions {
    return {
      handler: (request: Hapi.Request, reply: Hapi.IReply) => {
        const id = request.params["id"]

        this.taskRepository.findById(id).then((task: ITask) => {
          if (task) {
            var updateTask: ITask = request.payload;

            task.completed = updateTask.completed;
            task.description = updateTask.description;
            task.name = updateTask.name;

            this.taskRepository.findByIdAndUpdate(id, task).then((updatedTask: ITask) => {
              reply(updatedTask);
            }).catch((error) => {
              reply(Boom.badImplementation(error));
            });
          } else {
            reply(Boom.notFound());
          }
        }).catch((error) => {
          reply(Boom.badImplementation(error));
        });
      },
      tags: ['api', 'tasks'],
      description: 'Update task by id.',
      validate: {
        params: {
          id: Joi.string().required()
        },
        payload: TaskModel.updateTaskModel
      },
      plugins: {
        'hapi-swagger': {
          responses: {
            '200': {
              'description': 'Deleted Task.',
              'schema': TaskModel.taskModel
            },
            '404': {
              'description': 'Task does not exists.'
            }
          }
        }
      }
    };
  }
开发者ID:divramod,项目名称:hapi-seed-advanced,代码行数:48,代码来源:taskController.ts


示例4: RecordsController

exports.register = (server: Server, options: any, next: Function) => {

    const controller = new RecordsController();

    server.dependency("hapi-mongodb", (server: Server, next: Function) => {

        controller.useDb(server.plugins["hapi-mongodb"].db);

        return next();
    });

    server.route({
        path: "/docs/{slug}/subdocs/{subdocId}/records/{recordId}",
        method: "GET",
        config: {
            description: "Get a record",
            notes: "Returns a record by the slug and subdocument id passed in the path",
            tags: ["api"],
            plugins: {
                "hapi-swagger": {
                    order: 3
                }
            },
            validate: {
                params: {
                    slug: Joi.string()
                        .required()
                        .description("the slug for the document"),
                    subdocId: Joi.number()
                        .required()
                        .description("the id for the subdocument"),
                    recordId: Joi.number()
                        .required()
                        .description("the id for the record"),
                }
            },
            pre: [
                { method: controller.getRecord, assign: "record" },
                { method: controller.getSerializedRecord, assign: "serialisedRecord" }
            ],
            handler: controller.sendRecord
        }
    });

    return next();
};
开发者ID:vandemataramlib,项目名称:vml,代码行数:46,代码来源:records.ts


示例5: deleteUser

  public deleteUser(): Hapi.IRouteAdditionalConfigurationOptions {
    return {
      handler: (request: Hapi.Request, reply: Hapi.IReply) => {
        const id = request.params["id"]

        this.userRepository.findById(id).then((user: IUser) => {
          if (user) {
            this.userRepository.findByIdAndDelete(id).then(() => {
              reply(user);
            }).catch((error) => {
              reply(Boom.badImplementation(error));
            });
          } else {
            reply(Boom.notFound());
          }
        }).catch((error) => {
          reply(Boom.badImplementation(error));
        });
      },
      tags: ['api', 'users'],
      description: 'Delete user by id.',
      validate: {
        params: {
          id: Joi.string().required()
        }
      },
      response: {
        schema: UserModel.userModel
      },
      plugins: {
        'hapi-swagger': {
          responses: {
            '200': {
              'description': 'Deleted User.',
              'schema': UserModel.userModel
            },
            '404': {
              'description': 'User does not exists.'
            }
          }
        }
      }
    };
  }
开发者ID:divramod,项目名称:hapi-seed-advanced,代码行数:44,代码来源:userController.ts


示例6:

const urlPartsSchema = () =>
  Joi.object()
    .keys({
      protocol: Joi.string()
        .valid('http', 'https')
        .default('http'),
      hostname: Joi.string()
        .hostname()
        .default('localhost'),
      port: Joi.number(),
      auth: Joi.string().regex(/^[^:]+:.+$/, 'username and password separated by a colon'),
      username: Joi.string(),
      password: Joi.string(),
      pathname: Joi.string().regex(/^\//, 'start with a /'),
      hash: Joi.string().regex(/^\//, 'start with a /'),
    })
    .default();
开发者ID:elastic,项目名称:kibana,代码行数:17,代码来源:schema.ts


示例7: registerRoutes

export default function registerRoutes(server: Server)
{
    server.route({
        path: "/users",
        method: "POST",
        config: {
            auth: strategies.masterAuth,
            validate:{ 
                payload: joi.object().keys({
                    name: joi.string().label("Name"),
                    username: joi.string().email().label("Username"),
                    password: joi.string().min(6).label("Password"),
                    accountId: joi.string().label("Account Id"),
                })
            },
        },
        handler: {
            async: (request, reply) => createUser(server, request, reply)
        }
    })

    server.route({
        path: "/users/{id}",
        method: "GET",
        config: {
            auth: strategies.accountAuth,
            validate: {
                params: joi.string().required().label("User Id")
            }
        },
        handler: {
            async: (request, reply) => getUser(server, request, reply)
        }
    })

    server.route({
        path: "/users/{id}",
        method: "PUT",
        config: {
            auth: strategies.accountAuth,
            validate: {
                params: joi.string().required().label("User Id")
            }
        },
        handler: {
            async: (request, reply) => updateUser(server, request, reply),
        }
    })
}
开发者ID:nozzlegear,项目名称:stages-api,代码行数:49,代码来源:users-routes.ts


示例8: expect

        server.inject(request, (res) => {

            const result = res.result as ResponsePayload.RegisterUserSuccess;
            const schema = Joi.object().keys({
                data: Joi.object().keys({
                    kind: Joi.allow("User_OwnerView"),
                    uuid: Joi.string().length(36),
                    created_at: Joi.date(),
                    modified_at: Joi.date(),
                    deleted_at: Joi.allow(null),
                    email: Joi.allow("[email protected]"),
                    is_admin: Joi.allow(false),
                }),
            });
            let valid = Joi.validate(result, schema, {presence: "required"});

            expect(res.statusCode).toEqual(200);
            expect(valid.error).toEqual(null);

            done();
        });
开发者ID:AJamesPhillips,项目名称:napthr,代码行数:21,代码来源:routes.test.ts


示例9: it

  it('formats value validation errors correctly', () => {
    expect.assertions(1);
    const schema = Joi.array().items(
      Joi.object({
        type: Joi.string().required(),
      }).required()
    );

    const error = schema.validate([{}], { abortEarly: false }).error as HapiValidationError;

    // Emulate what Hapi v17 does by default
    error.output = { ...emptyOutput };
    error.output.payload.validation.keys = ['0.type', ''];

    try {
      defaultValidationErrorHandler({} as Request, {} as ResponseToolkit, error);
    } catch (err) {
      // Verify the empty string gets corrected to 'value'
      expect(err.output.payload.validation.keys).toEqual(['0.type', 'value']);
    }
  });
开发者ID:austec-automation,项目名称:kibana,代码行数:21,代码来源:http_tools.test.ts


示例10: DocumentsController

exports.register = (server: Server, options: any, next: Function) => {

    const controller = new DocumentsController();

    server.dependency("hapi-mongodb", (server: Server, next: Function) => {

        controller.useDb(server.plugins["hapi-mongodb"].db);

        return next();
    });

    server.route({
        method: "GET",
        path: "/docs/{slug}",
        config: {
            description: "Get a document",
            notes: "Returns a document by the slug passed in the path",
            tags: ["api"],
            plugins: {
                "hapi-swagger": {
                    order: 1
                }
            },
            validate: {
                params: {
                    slug: Joi.string()
                        .required()
                        .description("the slug for the document"),
                }
            },
            pre: [
                { method: controller.getDocument, assign: "document" },
                { method: controller.getSerializedDocument, assign: "serializedDocument" }
            ],
            handler: controller.sendDocument
        }
    });

    return next();
};
开发者ID:vandemataramlib,项目名称:vml,代码行数:40,代码来源:documents.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript joi.validate函数代码示例发布时间:2022-05-25
下一篇:
TypeScript joi.only函数代码示例发布时间: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