当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript PathReporter.PathReporter类代码示例

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


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

示例1: getterFunction

 function dispatchResponse<T, R>(getterFunction: GetterFunction<T, R>, decodedParams: t.Validation<T>): Promise<any> {
   if (decodedParams.isRight()) {
     return getterFunction(db, augur, decodedParams.value);
   } else {
     throw new Error(`Invalid request object: ${PathReporter.report(decodedParams)}`);
   }
 }
开发者ID:AugurProject,项目名称:augur_node,代码行数:7,代码来源:dispatch-json-rpc-request.ts

示例2: ValidationError

export function validate<RequestT, TypeT extends t.Type<RequestT> = t.Type<RequestT>>(iotsType: TypeT, body: any): RequestT {
  const result = iotsType.decode(body)
  if (result.isLeft()) {
    throw new ValidationError(PathReporter.report(result))
  } else if (result.isRight()) {
    return result.value
  }
}
开发者ID:Majavapaja,项目名称:Mursushakki,代码行数:8,代码来源:json.ts

示例3: it

  it('validates the serialized JSON via io-ts', () => {
    const full_test: smoke_test_struct_interface.FullTest = JSON.parse(String(fs.readFileSync(path.resolve(__dirname, './smoke_test_struct_serialized.json'))));
    const success_validation = iots.validate(full_test, smoke_test_struct_interface.FullTest_IO);
    const success_report = PathReporter.report(success_validation);
    assert.deepEqual(success_report, [
      'No errors!',
    ]);
    ThrowReporter.report(success_validation);

    // Pay attention to the Variant types first. -- @sompylasar
    // TODO(@sompylasar): Test more field values.

    assert.isTrue(iots.is(full_test.q, smoke_test_struct_interface.C5TCurrentVariant_T9228482442669086788_IO));

    function handleVariantQCC(variantQCC: smoke_test_struct_interface.MyFreakingVariant) {
      assert.isTrue(iots.is(variantQCC, smoke_test_struct_interface.MyFreakingVariant_IO));

      assert.isTrue(iots.is(variantQCC, smoke_test_struct_interface.MyFreakingVariant_VariantCase_A_IO));
      const variantQCCA = (variantQCC as smoke_test_struct_interface.MyFreakingVariant_VariantCase_A).A;
      if (variantQCCA) {
        assert.strictEqual(variantQCCA.a, (1 << 30), 'full_test.q.c.a is not (1 << 30)');
      }
      else {
        assert.isOk(false, 'full_test.q.c is not Variant<A,B,B2,C,Empty> case A');
      }
    }

    function handleVariantQCD(variantQCD: smoke_test_struct_interface.MyFreakingVariant) {
      assert.isTrue(iots.is(variantQCD, smoke_test_struct_interface.MyFreakingVariant_IO));

      assert.isTrue(iots.is(variantQCD, smoke_test_struct_interface.MyFreakingVariant_VariantCase_Y_IO));
      const variantQCDY = (variantQCD as smoke_test_struct_interface.MyFreakingVariant_VariantCase_Y).Y;
      if (variantQCDY) {
        // The enum E value SOME (0).
        assert.strictEqual(variantQCDY.e, 0, 'full_test.q.d.e is not enum E value SOME (0)');
      }
      else {
        assert.isOk(false, 'full_test.q.d is not Variant<A,X,Y> case Y');
      }
    }

    function handleVariantQ(variantQ: smoke_test_struct_interface.C5TCurrentVariant_T9228482442669086788) {
      assert.isTrue(iots.is(variantQ, smoke_test_struct_interface.C5TCurrentVariant_T9228482442669086788_VariantCase_C_IO));
      const variantQC = (variantQ as smoke_test_struct_interface.C5TCurrentVariant_T9228482442669086788_VariantCase_C).C;
      if (variantQC) {
        handleVariantQCC(variantQC.c);
        handleVariantQCD(variantQC.d);
      }
      else {
        assert.isOk(false, 'full_test.q is not Variant<A,B,B2,C,Empty> case C');
      }
    }

    handleVariantQ(full_test.q);
  });
开发者ID:grixa,项目名称:Current,代码行数:55,代码来源:test.ts

示例4: Error

export const validateConfigurationBlocks = (configurationBlocks: ConfigurationBlock[]) => {
  const validationMap = {
    isHosts: t.array(t.string),
    isString: t.string,
    isPeriod: t.string,
    isPath: t.string,
    isPaths: t.array(t.string),
    isYaml: t.string,
  };

  for (const [index, block] of configurationBlocks.entries()) {
    const blockSchema = configBlockSchemas.find(s => s.id === block.type);
    if (!blockSchema) {
      throw new Error(
        `Invalid config type of ${block.type} used in 'configuration_blocks' at index ${index}`
      );
    }

    const interfaceConfig = blockSchema.configs.reduce(
      (props, config) => {
        if (config.options) {
          props[config.id] = t.union(config.options.map(opt => t.literal(opt.value)));
        } else if (config.validation) {
          props[config.id] = validationMap[config.validation];
        }

        return props;
      },
      {} as t.Props
    );

    const runtimeInterface = createConfigurationBlockInterface(
      t.literal(blockSchema.id),
      t.interface(interfaceConfig)
    );

    const validationResults = runtimeInterface.decode(block);

    if (validationResults.isLeft()) {
      throw new Error(
        `configuration_blocks validation error, configuration_blocks at index ${index} is invalid. ${
          PathReporter.report(validationResults)[0]
        }`
      );
    }
  }
};
开发者ID:elastic,项目名称:kibana,代码行数:47,代码来源:config_block_validation.ts

示例5: createConfigurationBlockInterface

      request.payload.map(async (block: ConfigurationBlock) => {
        const assertData = createConfigurationBlockInterface().decode(block);
        if (assertData.isLeft()) {
          return {
            error: `Error parsing block info, ${PathReporter.report(assertData)[0]}`,
          };
        }

        const { blockID, success, error } = await libs.configurationBlocks.save(
          request.user,
          block
        );
        if (error) {
          return { success, error };
        }

        return { success, blockID };
      })
开发者ID:elastic,项目名称:kibana,代码行数:18,代码来源:upsert.ts


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