パッケージの詳細

@avro/types

mtth8kMIT1.0.25

Avro serialization

avro, avsc, binary, buffer

readme

Avro types NPM version

Pure JavaScript implementation of the Avro specification.

Features

Installation

$ npm install @avro/types

@avro/types is compatible with all versions of node.js since 0.11.

Examples

Inside a node.js module, or using browserify:

const {Type} = require('@avro/types');
  • Encode and decode values from a known schema:

    const type = Type.forSchema({
      type: 'record',
      fields: [
        {name: 'kind', type: {type: 'enum', symbols: ['CAT', 'DOG']}},
        {name: 'name', type: 'string'}
      ]
    });
    
    const buf = type.toBuffer({kind: 'CAT', name: 'Albert'}); // Encoded buffer.
    const val = type.fromBuffer(buf); // = {kind: 'CAT', name: 'Albert'}
  • Infer a value's schema and encode similar values:

    const type = Type.forValue({
      city: 'Cambridge',
      zipCodes: ['02138', '02139'],
      visits: 2
    });
    
    // We can use `type` to encode any values with the same structure:
    const bufs = [
      type.toBuffer({city: 'Seattle', zipCodes: ['98101'], visits: 3}),
      type.toBuffer({city: 'NYC', zipCodes: [], visits: 0})
    ];

更新履歴

6.0

General

  • Removed TypeScript typings (please help bring them back!).
  • Removed Browserify-specific shims. Serialization functionality is natively compatible with @avro/types.
  • Removed IDL support from parse.

Types (@avro/types)

  • Renamed a few methods (the previous names are still available and will be deprecated in 6.1):
    • decode to binaryDecodeAt
    • encode to binaryEncodeAt
    • fromBuffer to binaryDecode
    • toBuffer to binaryEncode
    • compareBuffers to binaryCompare
  • Added a checkValid method to check whether a value matches the type, producing actionable error messages.
  • Replaced name() method with name and branchName properties.
  • Removed fingerprint, inspect, and random methods.
  • Removed deprecated getters (getValuesType, getSchema, ...).
  • Replaced fromString (resp. toString) with fromJSON (resp. toJSON).
  • Removed clone options.
  • Updated isValid to reject unknown fields by default and renamed the noUndeclaredFields option to allowUndeclaredFields.

Containers & streams (@avro/streams)

No changes.

RPC services (@avro/services)

Overhauled the API: services are now more composable, RPCs are easier to instrument, natively support promises, and much more. This functionality requires node>=7.

IDL parsing (@avro/idl)

  • Added a synchronous version of assembleProtocol: assembleProtocolSync.
  • Removed readSchema, and readProtocol.