Skip to content

Commit

Permalink
Merge pull request #6 from schicks/master
Browse files Browse the repository at this point in the history
Handle logicalType
  • Loading branch information
joewood authored Mar 29, 2020
2 parents 5a54d26 + 5c1e804 commit 6dffae1
Show file tree
Hide file tree
Showing 12 changed files with 4,568 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RecordType } from "./model";
export { RecordType } from "./model";
export { RecordType, Field } from "./model";
/** Converts an Avro record type to a TypeScript file */
export declare function avroToTypeScript(recordType: RecordType): string;
3 changes: 3 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ function convertType(type, buffer) {
// array, call recursively for the array element type
return convertEnum(type, buffer);
}
else if (model_1.isLogicalType(type)) {
return convertType(type.type, buffer);
}
else {
console.error("Cannot work out type", type);
return "UNKNOWN";
Expand Down
6 changes: 5 additions & 1 deletion lib/model.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
export interface Schema {
}
export declare type Type = NameOrType | NameOrType[];
export declare type NameOrType = TypeNames | RecordType | ArrayType | NamedType;
export declare type NameOrType = TypeNames | RecordType | ArrayType | NamedType | LogicalType;
export declare type TypeNames = "record" | "array" | "null" | "map" | string;
export interface Field {
name: string;
Expand Down Expand Up @@ -33,9 +33,13 @@ export interface EnumType extends BaseType {
export interface NamedType extends BaseType {
type: string;
}
export interface LogicalType extends BaseType {
logicalType: string;
}
export declare function isRecordType(type: BaseType): type is RecordType;
export declare function isArrayType(type: BaseType): type is ArrayType;
export declare function isMapType(type: BaseType): type is MapType;
export declare function isEnumType(type: BaseType): type is EnumType;
export declare function isUnion(type: Type): type is NamedType[];
export declare function isOptional(type: Type): boolean;
export declare function isLogicalType(type: Type): type is LogicalType;
6 changes: 5 additions & 1 deletion lib/model.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**** Contains the Interfaces and Type Guards for Avro schema */
"use strict";
/**** Contains the Interfaces and Type Guards for Avro schema */
Object.defineProperty(exports, "__esModule", { value: true });
function isRecordType(type) {
return type.type === "record";
Expand Down Expand Up @@ -30,3 +30,7 @@ function isOptional(type) {
}
}
exports.isOptional = isOptional;
function isLogicalType(type) {
return typeof type !== 'string' && 'logicalType' in type;
}
exports.isLogicalType = isLogicalType;
Loading

0 comments on commit 6dffae1

Please sign in to comment.