Comparing version 6.0.0-alpha.10 to 6.0.0-alpha.11
@@ -27,2 +27,4 @@ /* jshint node: true */ | ||
var MAP_BYTES_TYPE = types.Type.forSchema({type: 'map', values: 'bytes'}, OPTS); | ||
var HEADER_TYPE = types.Type.forSchema({ | ||
@@ -33,3 +35,3 @@ name: 'Header', | ||
{name: 'magic', type: {type: 'fixed', name: 'Magic', size: 4}}, | ||
{name: 'meta', type: {type: 'map', values: 'bytes'}}, | ||
{name: 'meta', type: MAP_BYTES_TYPE}, | ||
{name: 'sync', type: {type: 'fixed', name: 'Sync', size: 16}} | ||
@@ -366,2 +368,3 @@ ] | ||
* + `codecs` | ||
* + `metadata`` | ||
* + `noCheck` | ||
@@ -408,2 +411,7 @@ * + `omitHeader`, useful to append to an existing block file. | ||
this._metadata = opts.metadata || {}; | ||
if (!MAP_BYTES_TYPE.isValid(this._metadata)) { | ||
throw new Error('invalid metadata'); | ||
} | ||
var codec = this._codec; | ||
@@ -453,9 +461,10 @@ this._compress = (this._codecs || BlockEncoder.getDefaultCodecs())[codec]; | ||
BlockEncoder.prototype._writeHeader = function () { | ||
var schemaStr = JSON.stringify( | ||
var schema = JSON.stringify( | ||
this._schema ? this._schema : this._type.schema({exportAttrs: true}) | ||
); | ||
var meta = { | ||
'avro.schema': new Buffer(schemaStr), | ||
'avro.codec': new Buffer(this._codec) | ||
}; | ||
var meta = utils.copyOwnProperties( | ||
this._metadata, | ||
{'avro.schema': new Buffer(schema), 'avro.codec': new Buffer(this._codec)}, | ||
true // Overwrite. | ||
); | ||
var Header = HEADER_TYPE.recordConstructor; | ||
@@ -462,0 +471,0 @@ var header = new Header(MAGIC_BYTES, meta, this._syncMarker); |
{ | ||
"name": "avsc", | ||
"version": "6.0.0-alpha.10", | ||
"version": "6.0.0-alpha.11", | ||
"description": "Avro for JavaScript", | ||
@@ -54,7 +54,6 @@ "homepage": "https://github.com/mtth/avsc", | ||
"devDependencies": { | ||
"benchmark": "^2.1.3", | ||
"coveralls": "^2.13.3", | ||
"coveralls": "^3.0.1", | ||
"istanbul": "^0.4.5", | ||
"mocha": "^3.5.3", | ||
"tmp": "^0.0.29" | ||
"mocha": "^5.2.0", | ||
"tmp": "^0.0.33" | ||
}, | ||
@@ -61,0 +60,0 @@ "author": { |
@@ -24,4 +24,3 @@ # Avsc [![NPM version](https://img.shields.io/npm/v/avsc.svg)](https://www.npmjs.com/package/avsc) [![Download count](https://img.shields.io/npm/dm/avsc.svg)](https://www.npmjs.com/package/avsc) [![Build status](https://travis-ci.org/mtth/avsc.svg?branch=master)](https://travis-ci.org/mtth/avsc) [![Coverage status](https://coveralls.io/repos/mtth/avsc/badge.svg?branch=master&service=github)](https://coveralls.io/github/mtth/avsc?branch=master) | ||
`avsc` is compatible with all versions of [node.js][] since `0.11` and major | ||
browsers via [browserify][] (see the full compatibility table | ||
[here][browser-support]). For convenience, you can also find compiled | ||
browsers via [browserify][]. For convenience, you can also find compiled | ||
distributions with the [releases][] (but please host your own copy). | ||
@@ -28,0 +27,0 @@ |
@@ -1,34 +0,128 @@ | ||
// Note: this typing file is incomplete (https://github.com/mtth/avsc/pull/134). | ||
// TODO: Wherever the type is just `any`, it was probably generated automatically. | ||
// Either finish documenting the type signature or document why `any` is appropriate. | ||
// TODO: Wherever the argument names are just `args: any`, it was probably generated from the signature of util.deprecate. Fix argument counts and types. | ||
// NOTE: This does not contain entries for functions available in the browser (functions/methods in etc/browser) | ||
// Note: These typings are incomplete (https://github.com/mtth/avsc/pull/134). | ||
// In particular, they do not contain entries for functions available in the | ||
// browser (functions/methods in etc/browser). | ||
import * as stream from 'stream'; | ||
import { EventEmitter } from 'events' | ||
// TODO: Wherever the type is just `any`, it was probably generated | ||
// automatically. Either finish documenting the type signature or document why | ||
// `any` is appropriate. | ||
type Schema = string | object; // TODO object should be further specified | ||
import * as stream from 'stream'; | ||
import { EventEmitter } from 'events'; | ||
export type Callback<V, Err = any> = (err: Err, value: V) => void; | ||
//"virtual" namespace (no JS, just types) for Avro Schema | ||
declare namespace schema { | ||
export type AvroSchema = DefinedType | DefinedType[]; | ||
type DefinedType = PrimitiveType | ComplexType | LogicalType | string; | ||
type PrimitiveType = 'null' | 'boolean' | 'int' | 'long' | 'float' | 'double' | 'bytes' | 'string'; | ||
type ComplexType = NamedType | RecordType | EnumType | MapType | ArrayType | FixedType; | ||
type LogicalType = ComplexType & LogicalTypeExtension; | ||
export type CodecTransformer = (buffer: Buffer, callback: () => void) => Buffer; // TODO | ||
interface NamedType { | ||
type: PrimitiveType | ||
} | ||
export interface CodecOptions { | ||
deflate: CodecTransformer; | ||
snappy: CodecTransformer; | ||
interface RecordType { | ||
type: "record"; | ||
name: string; | ||
namespace?: string; | ||
doc?: string; | ||
aliases?: string[]; | ||
fields: { | ||
name: string; | ||
doc?: string; | ||
type: Schema; | ||
default?: any; | ||
}[]; | ||
order?: "ascending" | "descending" | "ignore"; | ||
} | ||
interface EnumType { | ||
type: "enum"; | ||
name: string; | ||
namespace?: string; | ||
aliases?: string[]; | ||
doc?: string; | ||
symbols: string[]; | ||
} | ||
interface ArrayType { | ||
type: "array"; | ||
items: Schema; | ||
} | ||
interface MapType { | ||
type: "map"; | ||
values: Schema; | ||
} | ||
interface FixedType { | ||
type: "fixed"; | ||
name: string; | ||
aliases?: string[]; | ||
size: number; | ||
} | ||
interface LogicalTypeExtension { | ||
logicalType: string; | ||
[param: string]: any; | ||
} | ||
} | ||
export interface Decoder { | ||
on(type: 'metadata', callback: (type: Type) => void): this; | ||
on(type: 'data', callback: (value: object) => void): this; | ||
//Types of Options/arguments | ||
type Schema = Type | schema.AvroSchema; | ||
type Callback<V, Err = any> = (err: Err, value: V) => void; | ||
type Codec = (buffer: Buffer, callback: Callback<Buffer>) => void; | ||
interface CodecOptions { | ||
[name: string]: Codec; | ||
} | ||
export interface Encoder { | ||
// TODO | ||
interface DecoderOptions { | ||
noDecode: boolean; | ||
readerSchema: string | object | Type; | ||
codecs: CodecOptions; | ||
parseHook: (schema: Schema) => Type | ||
} | ||
export interface ReaderOptions { | ||
// TODO | ||
interface EncoderOptions { | ||
blockSize: number; | ||
codec: string; | ||
codecs: CodecOptions; | ||
writeHeader: boolean | 'always' | 'never' | 'auto'; | ||
syncMarker: Buffer; | ||
} | ||
interface ForSchemaOptions { | ||
assertLogicalTypes: boolean; | ||
logicalTypes: { [type: string]: types.LogicalType }; | ||
namespace: string; | ||
noAnonymousTypes: boolean; | ||
registry: { [name: string]: Type }; | ||
typeHook: (schema: Schema, opts: ForSchemaOptions) => Type; | ||
wrapUnions: boolean | 'auto' | 'always' | 'never'; | ||
} | ||
interface TypeOptions extends ForSchemaOptions { | ||
strictDefaults: boolean; | ||
} | ||
interface ForValueOptions extends TypeOptions { | ||
emptyArrayType: Type; | ||
valueHook: (val: any, opts: ForValueOptions) => Type; | ||
} | ||
interface CloneOptions { | ||
coerceBuffers: boolean; | ||
fieldHook: (field: types.Field, value: any, type: Type) => any; | ||
qualifyNames: boolean; | ||
skipMissingFields: boolean; | ||
wrapUnions: boolean; | ||
} | ||
interface IsValidOptions { | ||
noUndeclaredFields: boolean; | ||
errorHook: (path: string[], val: any, type: Type) => void | ||
} | ||
interface AssembleOptions { | ||
@@ -38,46 +132,56 @@ importHook: (filePath: string, type: 'idl', callback: Callback<object>) => void; | ||
export function assemble(args: any): any; | ||
interface SchemaOptions { | ||
exportAttrs: boolean; | ||
noDeref: boolean; | ||
} | ||
declare class Resolver { | ||
//no public methods | ||
} | ||
//exported functions | ||
export function assembleProtocol(filePath: string, opts: Partial<AssembleOptions>, callback: Callback<object>): void; | ||
export function assembleProtocol(filePath: string, callback: Callback<object>): void; | ||
export function combine(args: any): any; | ||
export function createFileDecoder(fileName: string, codecs?: Partial<CodecOptions>): Decoder; | ||
export function createFileEncoder(filePath: string, schema: Schema, options?: any): Encoder; | ||
export function createFileDecoder(fileName: string, opts?: Partial<DecoderOptions>): streams.BlockDecoder; | ||
export function createFileEncoder(filePath: string, schema: Schema, opts?: Partial<EncoderOptions>): streams.BlockEncoder; | ||
export function createBlobEncoder(schema: Schema, opts?: Partial<EncoderOptions>): stream.Duplex; | ||
export function createBlobDecoder(blob: Blob, opts?: Partial<DecoderOptions>): streams.BlockDecoder; | ||
export function discoverProtocol(transport: Service.Transport, options: any, callback: Callback<any>): void; | ||
export function discoverProtocol(transport: Service.Transport, callback: Callback<any>): void; | ||
export function extractFileHeader(filePath: string, options?: any): void; | ||
export function infer(args: any): any; | ||
export function parse(schemaOrProtocolIdl: string, options?: any): any; // TODO protocol literal or Type | ||
export function readProtocol(protocolIdl: string, options?: Partial<ReaderOptions>): any; | ||
export function readSchema(schemaIdl: string, options?: Partial<ReaderOptions>): Schema; | ||
// TODO streams | ||
export function readProtocol(protocolIdl: string, options?: Partial<DecoderOptions>): any; | ||
export function readSchema(schemaIdl: string, options?: Partial<DecoderOptions>): Schema; | ||
// TODO more specific types than `any` | ||
export class Type { | ||
clone(val: any, opts?: any): any; | ||
clone(val: any, opts?: Partial<CloneOptions>): any; | ||
compare(val1: any, val2: any): number; | ||
compareBuffers(buf1: any, buf2: any): number; | ||
constructor(schema: Schema, opts?: any); | ||
createResolver(type: any, opts?: any): any; // TODO: opts not documented on wiki | ||
decode(buf: any, pos?: any, resolver?: any): any | ||
fingerprint(algorithm?: any): any; | ||
fromBuffer(buffer: Buffer, resolver?: any, noCheck?: boolean): Type; // TODO | ||
fromString(str: any): any; | ||
compareBuffers(buf1: Buffer, buf2: Buffer): number; | ||
createResolver(type: Type): Resolver; | ||
decode(buf: Buffer, pos?: number, resolver?: Resolver): { value: any, offset: number}; | ||
encode(val: any, buf: Buffer, pos?: number): number; | ||
equals(type: Type): boolean; | ||
fingerprint(algorithm?: string): Buffer; | ||
fromBuffer(buffer: Buffer, resolver?: Resolver, noCheck?: boolean): any; | ||
fromString(str: string): any; | ||
inspect(): string; | ||
isValid(val: any, opts?: any): any; | ||
isValid(val: any, opts?: Partial<IsValidOptions>): boolean; | ||
random(): Type; | ||
schema(opts?: any): any; | ||
toBuffer(value: object): Buffer; | ||
toJSON(): string; | ||
toString(val?: any): any; | ||
schema(opts?: Partial<SchemaOptions>): Schema; | ||
toBuffer(value: any): Buffer; | ||
toJSON(): object; | ||
toString(val?: any): string; | ||
wrap(val: any): any; | ||
readonly aliases: string[]|undefined; | ||
readonly doc: string|undefined; | ||
readonly name: string|undefined; | ||
readonly branchName: string|undefined; | ||
readonly aliases: string[] | undefined; | ||
readonly doc: string | undefined; | ||
readonly name: string | undefined; | ||
readonly branchName: string | undefined; | ||
readonly typeName: string; | ||
static forSchema(schema: Schema, opts?: any): Type; | ||
static forTypes(types: any, opts?: any): Type; | ||
static forValue(value: object, opts?: any): Type; | ||
static forSchema(schema: Schema, opts?: Partial<ForSchemaOptions>): Type; | ||
static forTypes(types: Type[], opts?: Partial<TypeOptions>): Type; | ||
static forValue(value: object, opts?: Partial<ForValueOptions>): Type; | ||
static isType(arg: any, ...prefix: string[]): boolean; | ||
static __reset(size: number): void; | ||
} | ||
@@ -89,8 +193,8 @@ | ||
createServer(options?: Partial<Service.ServerOptions>): Service.Server; | ||
equals(args: any): any; // deprecated | ||
equals(args: any): boolean; // deprecated | ||
inspect(): string; | ||
message(name: string): any; | ||
type(name: string): Type|undefined; | ||
type(name: string): Type | undefined; | ||
readonly doc: string|undefined; | ||
readonly doc: string | undefined; | ||
readonly hash: Buffer; | ||
@@ -118,3 +222,3 @@ readonly messages: any[]; | ||
interface ServerChannel extends EventEmitter { | ||
interface ServerChannel extends EventEmitter { | ||
readonly destroyed: boolean; | ||
@@ -176,18 +280,23 @@ readonly draining: boolean; | ||
export namespace streams { | ||
class BlockDecoder { | ||
constructor(opts?: any); | ||
static defaultCodecs(): any; | ||
class BlockDecoder extends stream.Duplex { | ||
constructor(opts?: Partial<DecoderOptions>); | ||
static defaultCodecs(): CodecOptions; | ||
//should add meta-data listener, but regrettably that requires all other events to be repeated | ||
//here, or else they won't show up in code-completion. To avoid clutter, the meta-data event | ||
//is therefore omitted from this stream. | ||
} | ||
class BlockEncoder { | ||
constructor(schema: Schema, opts: any); | ||
static defaultCodecs(): any; | ||
class BlockEncoder extends stream.Duplex { | ||
constructor(schema: Schema, opts?: Partial<EncoderOptions>); | ||
static defaultCodecs(): CodecOptions; | ||
} | ||
class RawDecoder { | ||
constructor(schema: Schema, opts: any); | ||
class RawDecoder extends stream.Duplex { | ||
constructor(schema: Schema, opts?: { decode?: boolean }); | ||
} | ||
class RawEncoder { | ||
constructor(schema: Schema, opts: any); | ||
class RawEncoder extends stream.Duplex { | ||
constructor(schema: Schema, opts?: { batchSize?: number }); | ||
} | ||
@@ -243,6 +352,6 @@ } | ||
readonly underlyingType: Type; | ||
_export(schema: Schema): void; | ||
_fromValue(val: any): any; | ||
_resolve(type: Type): any; | ||
_toValue(any: any): any; | ||
protected _export(schema: Schema): void; | ||
protected _fromValue(val: any): any; | ||
protected _resolve(type: Type): any; | ||
protected _toValue(any: any): any; | ||
random(): LogicalType; | ||
@@ -254,3 +363,3 @@ } | ||
random(): LongType; | ||
static __with(methods: object, noUnpack?: boolean) : void; | ||
static __with(methods: object, noUnpack?: boolean): void; | ||
} | ||
@@ -293,2 +402,3 @@ | ||
random(): UnwrappedUnionType; | ||
readonly types: Type[]; | ||
} | ||
@@ -299,3 +409,4 @@ | ||
random(): WrappedUnionType; | ||
readonly types: Type[]; | ||
} | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
251959
4
7896
132