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


TypeScript joi.boolean函數代碼示例

本文整理匯總了TypeScript中joi.boolean函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript boolean函數的具體用法?TypeScript boolean怎麽用?TypeScript boolean使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了boolean函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: registerDeprecationLoggingRoutes

export function registerDeprecationLoggingRoutes(server: Legacy.Server) {
  const { callWithRequest } = server.plugins.elasticsearch.getCluster('admin');

  server.route({
    path: '/api/upgrade_assistant/deprecation_logging',
    method: 'GET',
    async handler(request) {
      try {
        return await getDeprecationLoggingStatus(callWithRequest, request);
      } catch (e) {
        return Boom.boomify(e, { statusCode: 500 });
      }
    },
  });

  server.route({
    path: '/api/upgrade_assistant/deprecation_logging',
    method: 'PUT',
    options: {
      validate: {
        payload: Joi.object({
          isEnabled: Joi.boolean(),
        }),
      },
    },
    async handler(request) {
      try {
        const { isEnabled } = request.payload as { isEnabled: boolean };
        return await setDeprecationLogging(callWithRequest, request, isEnabled);
      } catch (e) {
        return Boom.boomify(e, { statusCode: 500 });
      }
    },
  });
}
開發者ID:gingerwizard,項目名稱:kibana,代碼行數:35,代碼來源:deprecation_logging.ts

示例2: upgradeAssistant

export function upgradeAssistant(kibana: any) {
  return new kibana.Plugin({
    id: 'upgrade_assistant',
    configPrefix: 'xpack.upgrade_assistant',
    require: ['elasticsearch'],
    uiExports: {
      managementSections: ['plugins/upgrade_assistant'],
      savedObjectSchemas: {
        'upgrade-assistant-reindex-operation': {
          isNamespaceAgnostic: true,
        },
        'upgrade-assistant-telemetry': {
          isNamespaceAgnostic: true,
        },
      },
      styleSheetPaths: resolve(__dirname, 'public/index.scss'),
      mappings,
    },
    publicDir: resolve(__dirname, 'public'),

    config() {
      return Joi.object({
        enabled: Joi.boolean().default(true),
      }).default();
    },

    init(server: Legacy.Server) {
      // Add server routes and initialize the plugin here
      initServer(server);
    },
  });
}
開發者ID:njd5475,項目名稱:kibana,代碼行數:32,代碼來源:index.ts

示例3: createUser

export function createUser(req: Request, res: Response, next: NextFunction) {
  const schema = Joi.object().keys({
    name: Joi.string().min(3).required(),
    email: Joi.string().email().required(),
    password: Joi.string().required().regex(passwordRegex),
    agreeTos: Joi.boolean().only(true).required(),
    referral: Joi.string().email().options({
      language: {
        key: '{{!label}}',
        string: {
          email: 'Not valid referral code'
        }
      }
    }).label(' ') // Joi does not allow empty label but space is working
  });

  if (req.body.referral) {
    req.body.referral = base64decode(req.body.referral);
  }

  const result = Joi.validate(req.body, schema, options);

  if (result.error) {
    return res.status(422).json(result);
  } else {
    return next();
  }
}
開發者ID:Norestlabs-Mariya,項目名稱:backend-ico-dashboard,代碼行數:28,代碼來源:request.validation.ts

示例4: it

 it("should annotate the class property", function () {
     const metadata = Reflect.getMetadata(WORKING_SCHEMA_KEY, MyClass.prototype);
     const expected = {
         myProperty: Joi.boolean()
     };
     assert.deepEqual(metadata, expected);
 });
開發者ID:laurence-myers,項目名稱:tsdv-joi,代碼行數:7,代碼來源:boolean.ts

示例5: handler

export const createResolveImportErrorsRoute = (
  prereqs: Prerequisites,
  server: Hapi.Server,
  supportedTypes: string[]
) => ({
  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(),
        retries: Joi.array()
          .items(
            Joi.object({
              type: Joi.string().required(),
              id: Joi.string().required(),
              overwrite: Joi.boolean().default(false),
              replaceReferences: Joi.array()
                .items(
                  Joi.object({
                    type: Joi.string().required(),
                    from: Joi.string().required(),
                    to: Joi.string().required(),
                  })
                )
                .default([]),
            })
          )
          .required(),
      }).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({
      supportedTypes,
      savedObjectsClient,
      readStream: request.payload.file,
      retries: request.payload.retries,
      objectLimit: request.server.config().get('savedObjects.maxImportExportSize'),
    });
  },
});
開發者ID:elastic,項目名稱:kibana,代碼行數:56,代碼來源:resolve_import_errors.ts

示例6: handler

export const createExportRoute = (
  prereqs: Prerequisites,
  server: Hapi.Server,
  supportedTypes: string[]
) => ({
  path: '/api/saved_objects/_export',
  method: 'POST',
  config: {
    pre: [prereqs.getSavedObjectsClient],
    validate: {
      payload: Joi.object()
        .keys({
          type: Joi.array()
            .items(Joi.string().valid(supportedTypes))
            .single()
            .optional(),
          objects: Joi.array()
            .items({
              type: Joi.string()
                .valid(supportedTypes)
                .required(),
              id: Joi.string().required(),
            })
            .max(server.config().get('savedObjects.maxImportExportSize'))
            .optional(),
          includeReferencesDeep: Joi.boolean().default(false),
        })
        .xor('type', 'objects')
        .default(),
    },
    async handler(request: ExportRequest, h: Hapi.ResponseToolkit) {
      const { savedObjectsClient } = request.pre;
      const docsToExport = await getSortedObjectsForExport({
        savedObjectsClient,
        types: request.payload.type,
        objects: request.payload.objects,
        exportSizeLimit: server.config().get('savedObjects.maxImportExportSize'),
        includeReferencesDeep: request.payload.includeReferencesDeep,
      });
      return h
        .response(docsToExport.map(doc => stringify(doc)).join('\n'))
        .header('Content-Disposition', `attachment; filename="export.ndjson"`)
        .header('Content-Type', 'application/ndjson');
    },
  },
});
開發者ID:elastic,項目名稱:kibana,代碼行數:46,代碼來源:export.ts

示例7: handler

export const createCreateRoute = (prereqs: Prerequisites) => {
  return {
    path: '/api/saved_objects/{type}/{id?}',
    method: 'POST',
    options: {
      pre: [prereqs.getSavedObjectsClient],
      validate: {
        query: Joi.object()
          .keys({
            overwrite: Joi.boolean().default(false),
          })
          .default(),
        params: Joi.object()
          .keys({
            type: Joi.string().required(),
            id: Joi.string(),
          })
          .required(),
        payload: Joi.object({
          attributes: Joi.object().required(),
          migrationVersion: Joi.object().optional(),
          references: Joi.array()
            .items(
              Joi.object().keys({
                name: Joi.string().required(),
                type: Joi.string().required(),
                id: Joi.string().required(),
              })
            )
            .default([]),
        }).required(),
      },
      handler(request: CreateRequest) {
        const { savedObjectsClient } = request.pre;
        const { type, id } = request.params;
        const { overwrite } = request.query;
        const { migrationVersion, references } = request.payload;
        const options = { id, overwrite, migrationVersion, references };

        return savedObjectsClient.create(type, request.payload.attributes, options);
      },
    },
  };
};
開發者ID:elastic,項目名稱:kibana,代碼行數:44,代碼來源:create.ts

示例8: registerTelemetryRoutes

export function registerTelemetryRoutes(server: UpgradeAssistantTelemetryServer) {
  server.route({
    path: '/api/upgrade_assistant/telemetry/ui_open',
    method: 'PUT',
    options: {
      validate: {
        payload: Joi.object({
          overview: Joi.boolean().default(false),
          cluster: Joi.boolean().default(false),
          indices: Joi.boolean().default(false),
        }),
      },
    },
    async handler(request) {
      try {
        return await upsertUIOpenOption(server, request);
      } catch (e) {
        return Boom.boomify(e, { statusCode: 500 });
      }
    },
  });

  server.route({
    path: '/api/upgrade_assistant/telemetry/ui_reindex',
    method: 'PUT',
    options: {
      validate: {
        payload: Joi.object({
          close: Joi.boolean().default(false),
          open: Joi.boolean().default(false),
          start: Joi.boolean().default(false),
          stop: Joi.boolean().default(false),
        }),
      },
    },
    async handler(request) {
      try {
        return await upsertUIReindexOption(server, request);
      } catch (e) {
        return Boom.boomify(e, { statusCode: 500 });
      }
    },
  });
}
開發者ID:njd5475,項目名稱:kibana,代碼行數:44,代碼來源:telemetry.ts

示例9: handler

export const createImportRoute = (
  prereqs: Prerequisites,
  server: Hapi.Server,
  supportedTypes: string[]
) => ({
  path: '/api/saved_objects/_import',
  method: 'POST',
  config: {
    pre: [prereqs.getSavedObjectsClient],
    payload: {
      maxBytes: server.config().get('savedObjects.maxImportPayloadBytes'),
      output: 'stream',
      allow: 'multipart/form-data',
    },
    validate: {
      query: Joi.object()
        .keys({
          overwrite: Joi.boolean().default(false),
        })
        .default(),
      payload: Joi.object({
        file: Joi.object().required(),
      }).default(),
    },
  },
  async handler(request: ImportRequest, h: Hapi.ResponseToolkit) {
    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 importSavedObjects({
      supportedTypes,
      savedObjectsClient,
      readStream: request.payload.file,
      objectLimit: request.server.config().get('savedObjects.maxImportExportSize'),
      overwrite: request.query.overwrite,
    });
  },
});
開發者ID:elastic,項目名稱:kibana,代碼行數:41,代碼來源:import.ts

示例10: upgradeAssistant

export function upgradeAssistant(kibana: any) {
  return new kibana.Plugin({
    id: 'upgrade_assistant',
    require: ['elasticsearch'],
    uiExports: {
      managementSections: ['plugins/upgrade_assistant'],
      styleSheetPaths: resolve(__dirname, 'public/index.scss'),
    },
    publicDir: resolve(__dirname, 'public'),

    config() {
      return Joi.object({
        enabled: Joi.boolean().default(true),
      }).default();
    },

    init(server: Server) {
      // Add server routes and initialize the plugin here
      initServer(server);
    },
  });
}
開發者ID:gingerwizard,項目名稱:kibana,代碼行數:22,代碼來源:index.ts


注:本文中的joi.boolean函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。