本文整理匯總了TypeScript中@kbn/config-schema.schema.contextRef方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript schema.contextRef方法的具體用法?TypeScript schema.contextRef怎麽用?TypeScript schema.contextRef使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@kbn/config-schema.schema
的用法示例。
在下文中一共展示了schema.contextRef方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: test
test('correctly passes context', async () => {
mockPackage.raw = {
branch: 'feature-v1',
version: 'v1',
build: {
distributable: true,
number: 100,
sha: 'feature-v1-build-sha',
},
};
const env = new Env('/kibana', getEnvOptions());
const config$ = new BehaviorSubject(new ObjectToConfigAdapter({ foo: {} }));
const schemaDefinition = schema.object({
branchRef: schema.string({
defaultValue: schema.contextRef('branch'),
}),
buildNumRef: schema.number({
defaultValue: schema.contextRef('buildNum'),
}),
buildShaRef: schema.string({
defaultValue: schema.contextRef('buildSha'),
}),
devRef: schema.boolean({ defaultValue: schema.contextRef('dev') }),
prodRef: schema.boolean({ defaultValue: schema.contextRef('prod') }),
versionRef: schema.string({
defaultValue: schema.contextRef('version'),
}),
});
const configService = new ConfigService(config$, env, logger);
await configService.setSchema('foo', schemaDefinition);
const value$ = configService.atPath('foo');
expect(await value$.pipe(first()).toPromise()).toMatchSnapshot();
});
示例2: match
const match = (regex: RegExp, errorMsg: string) => (str: string) =>
regex.test(str) ? undefined : errorMsg;
export const config = {
path: 'server',
schema: schema.object(
{
autoListen: schema.boolean({ defaultValue: true }),
basePath: schema.maybe(
schema.string({
validate: match(validBasePathRegex, "must start with a slash, don't end with one"),
})
),
cors: schema.conditional(
schema.contextRef('dev'),
true,
schema.object(
{
origin: schema.arrayOf(schema.string()),
},
{
defaultValue: {
origin: ['*://localhost:9876'], // karma test server
},
}
),
schema.boolean({ defaultValue: false })
),
host: schema.string({
defaultValue: 'localhost',