當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。