@ovotech/avro-ts
Advanced tools
Comparing version 4.2.4 to 5.0.0
import { schema, Schema } from 'avsc'; | ||
import { Convert } from '../types'; | ||
export declare const isRecordType: (type: Schema) => type is schema.RecordType; | ||
export declare const withDefault: (def: any, doc: string | undefined) => string | undefined; | ||
export declare const convertRecordType: Convert<schema.RecordType>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.convertRecordType = exports.isRecordType = void 0; | ||
exports.convertRecordType = exports.withDefault = exports.isRecordType = void 0; | ||
const ts_compose_1 = require("@ovotech/ts-compose"); | ||
const convert_1 = require("../convert"); | ||
exports.isRecordType = (type) => typeof type === 'object' && 'type' in type && type.type === 'record'; | ||
exports.withDefault = (def, doc) => { | ||
if (def === undefined) { | ||
return doc; | ||
} | ||
const defDoc = `Default: ${JSON.stringify(def)}`; | ||
return doc === undefined ? defDoc : `${doc}\n\n${defDoc}`; | ||
}; | ||
exports.convertRecordType = (context, schema) => { | ||
var _a; | ||
const namespace = (_a = schema.namespace) !== null && _a !== void 0 ? _a : context.namespace; | ||
const fields = ts_compose_1.mapWithContext(context, schema.fields, (fieldContext, { name, type, doc }) => { | ||
const fields = ts_compose_1.mapWithContext(context, schema.fields, (fieldContext, { name, type, doc, default: def }) => { | ||
const converted = convert_1.convertType({ ...fieldContext, namespace }, type); | ||
return ts_compose_1.document(converted.context, ts_compose_1.Type.Prop({ name, type: converted.type, jsDoc: doc })); | ||
return ts_compose_1.document(converted.context, ts_compose_1.Type.Prop({ | ||
name, | ||
type: converted.type, | ||
jsDoc: exports.withDefault(def, doc), | ||
isOptional: def !== undefined, | ||
})); | ||
}); | ||
@@ -14,0 +26,0 @@ const name = convert_1.firstUpperCase(schema.name); |
{ | ||
"name": "@ovotech/avro-ts", | ||
"description": "Convert avro schemas into typescript interfaces", | ||
"version": "4.2.4", | ||
"version": "5.0.0", | ||
"main": "dist/index.js", | ||
@@ -38,3 +38,3 @@ "source": "src/index.ts", | ||
}, | ||
"gitHead": "e85f4cdfc56c0c8514326bebb40aaf0dfd30339d" | ||
"gitHead": "fe95a576eb2366110b3bf478cbe587aff3fc63fa" | ||
} |
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
24922
361
34548