How to use the avsc.Type function in avsc

To help you get started, we’ve selected a few avsc 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 kafkajs / confluent-schema-registry / src / utils / avdlToAVSC.spec.ts View on Github external
const compareWithJavaImplementation = (avdlPath: string, name: string) => async () => {
  const absolutePathToAvdlToAVSC = absolutePath('./bin/avdlToAVSC.sh')
  const execaArgs = [`./fixtures/avdl/${avdlPath}`, name]

  let expectedAVSC
  try {
    const { stdout: result } = await execa(absolutePathToAvdlToAVSC, execaArgs)
    expectedAVSC = JSON.parse(result)
  } catch (error) {
    console.error(`Error when running ${absolutePathToAvdlToAVSC}`, error) // eslint-disable-line no-console
    throw error
  }

  const avsc = avdlToAVSC(absolutePath('./fixtures/avdl', avdlPath))
  expect(avsc).toEqual(expectedAVSC)
  expect(avro.Type.forSchema(avsc)).toBeTruthy()
  expect(await registry.register(avsc)).toBeTruthy()
}
github mtth / avsc / js / index.js View on Github external
function instrument(schema) {
      if (schema instanceof avsc.Type) {
        schema = schema.getSchema();
      }
      var refs = [];
      return avsc.parse(schema, {typeHook: hook,
                                 wrapUnions: true});

      function hook(schema, opts) {
        if (~refs.indexOf(schema)) {
          return;
        }
        refs.push(schema);

        if (schema.type === 'record') {
          schema.fields.forEach(function (f) {
            f['default'] = undefined;
          });
github eHealthAfrica / aether / aether-ui / aether / ui / assets / apps / utils / avro-utils.jsx View on Github external
export const generateSchema = (obj, defaultName = 'Auto') => {
  const schema = avro.Type.forValue(obj).schema()
  const nameGen = generateSchemaName(defaultName)
  traverseObject(nameGen, schema)
  return schema
}
github moleculerjs / moleculer / src / serializers / avro.js View on Github external
function createSchemas() {
	const avro = require("avsc");
	const schemas = {};

	schemas[P.PACKET_EVENT] = avro.Type.forSchema({
		name: P.PACKET_EVENT,
		type: "record",
		fields: [
			{ name: "ver", type: "string" },
			{ name: "sender", type: "string" },
			{ name: "event", type: "string" },
			{ name: "data", type: [ "null", "string"], default: null },
			{ name: "groups", type: [ "null", {
				type: "array",
				items: "string"
			}], default: null },
			{ name: "broadcast", type: "boolean" }
		]
	});

	schemas[P.PACKET_REQUEST] = avro.Type.forSchema({
github kafkajs / confluent-schema-registry / src / cache.ts View on Github external
setSchema = (registryId: number, schema: Schema): Schema => {
    this.schemasByRegistryId[registryId] = avro.Type.forSchema(schema)

    return this.schemasByRegistryId[registryId]
  }
github moleculerjs / moleculer / src / serializers / avro.js View on Github external
{ name: "ver", type: "string" },
			{ name: "sender", type: "string" }
		]
	});

	schemas[P.PACKET_HEARTBEAT] = avro.Type.forSchema({
		name: P.PACKET_HEARTBEAT,
		type: "record",
		fields: [
			{ name: "ver", type: "string" },
			{ name: "sender", type: "string" },
			{ name: "cpu", type: "double" }
		]
	});

	schemas[P.PACKET_PING] = avro.Type.forSchema({
		name: P.PACKET_PING,
		type: "record",
		fields: [
			{ name: "ver", type: "string" },
			{ name: "sender", type: "string" },
			{ name: "time", type: "long" }
		]
	});

	schemas[P.PACKET_PONG] = avro.Type.forSchema({
		name: P.PACKET_PONG,
		type: "record",
		fields: [
			{ name: "ver", type: "string" },
			{ name: "sender", type: "string" },
			{ name: "time", type: "long" },
github nodefluent / schema-registry / lib / schemas / Avro.js View on Github external
static parseSchema(schema){
        return avro.Type.forSchema(schema);
    }
}
github Optum / knack / packages / knack-avro / src / encodeDecode.js View on Github external
return options.resolveType(schema);
	}

	let avroSchema = schema;
	if (typeof schema === 'string') {
		avroSchema = JSON.parse(schema);
	}

	let storeKey = schema;
	if (typeof schema === 'object') {
		storeKey = JSON.stringify(schema);
	}

	let type = typeStore[storeKey];
	if (!type) {
		type = avro.Type.forSchema(avroSchema);
		typeStore[storeKey] = type;
	}

	return type;
};
github Optum / knack / packages / knack-avro / src / avscToAst.js View on Github external
static fromAvroSchema(avroSchema) {
		const avscType = avro.Type.forSchema(avroSchema);
		const ast = new Ast(avscType);
		ast.build();
		return ast;
	}

avsc

Avro for JavaScript

MIT
Latest version published 2 years ago

Package Health Score

76 / 100
Full package analysis