How to use the @xviz/schema.protoEnumsToInts function in @xviz/schema

To help you get started, we’ve selected a few @xviz/schema examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github uber / xviz / test / modules / schema / proto-validation.spec.js View on Github external
function validateAgainstExample(t, validator, protoType, protoEnumTypes, examplePath, jsonExample) {
  const originalJsonExample = clone(jsonExample);

  protoEnumsToInts(protoType, jsonExample, protoEnumTypes);

  // Sanity check out input data
  const schemaName = protoType.options[EXTENSION_PROPERTY];
  validateXVIZJSON(t, validator, schemaName, originalJsonExample, 'Example JSON');

  // Verify content "works" as protobuf
  verifyProto(t, protoType, jsonExample, `Protobuf verified`);

  // Populate proto object with content, we do "fromObject" first
  // so that the well known types will be handled
  const protoObject = protoType.fromObject(jsonExample);
  const serializedProtoData = protoType.encode(protoObject).finish();
  const protoData = protoType.decode(serializedProtoData);

  // Dump to Object
  const options = {
github uber / xviz / test / modules / schema / proto-utils.spec.js View on Github external
test('protoEnumsToInts#Simple', t => {
  const goodObj = {
    foo: 'zip',
    other: 42
  };

  const expObj = {
    foo: 0,
    other: 42
  };

  protoEnumsToInts(TEST_PROTO_TYPE, goodObj, ENUM_TYPES);
  t.ok(JSON.stringify(goodObj) === JSON.stringify(expObj), 'Converted enum');

  t.end();
});
github uber / xviz / test / modules / schema / proto-utils.spec.js View on Github external
test('protoEnumsToInts#PackageScopeEnum', t => {
  const goodObj = {
    foo: 'cpp',
    other: 42
  };

  const expObj = {
    foo: 1,
    other: 42
  };

  const testPackageType = TEST_PROTO_ROOT.lookupType('TestPackage');

  protoEnumsToInts(testPackageType, goodObj, ENUM_TYPES);
  t.ok(JSON.stringify(goodObj) === JSON.stringify(expObj), 'Converted enum');

  t.end();
});
github uber / xviz / test / modules / schema / proto-utils.spec.js View on Github external
mapped: {
      foo: {
        foo: 1,
        other: 42
      }
    },
    list: [
      {
        foo: 0
      }
    ],
    primMap: {a: 4, b: 2},
    primList: ['a', 'b']
  };

  protoEnumsToInts(nestedType, nestedObj, ENUM_TYPES);
  t.deepEqual(nestedObj, expectedObj, 'Converted nested and mapped enums');

  t.end();
});
github uber / xviz / test / modules / schema / proto-utils.spec.js View on Github external
    () => protoEnumsToInts(TEST_PROTO_TYPE, badObj, ENUM_TYPES),
    /Error/,