當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript joi.string函數代碼示例

本文整理匯總了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("a@b.c"),
                    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;未經允許,請勿轉載。