Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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()
}
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;
});
export const generateSchema = (obj, defaultName = 'Auto') => {
const schema = avro.Type.forValue(obj).schema()
const nameGen = generateSchemaName(defaultName)
traverseObject(nameGen, schema)
return schema
}
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({
setSchema = (registryId: number, schema: Schema): Schema => {
this.schemasByRegistryId[registryId] = avro.Type.forSchema(schema)
return this.schemasByRegistryId[registryId]
}
{ 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" },
static parseSchema(schema){
return avro.Type.forSchema(schema);
}
}
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;
};
static fromAvroSchema(avroSchema) {
const avscType = avro.Type.forSchema(avroSchema);
const ast = new Ast(avscType);
ast.build();
return ast;
}