@ovotech/avro-ts
Advanced tools
Comparing version 6.0.5 to 6.0.7
@@ -89,6 +89,6 @@ "use strict"; | ||
if (context.external[module][type]) { | ||
const externalNamespace = helpers_1.convertNamespace(namespace); | ||
const externalNamespace = helpers_1.convertName(namespace); | ||
const alias = `${externalNamespace}${helpers_1.firstUpperCase(name)}`; | ||
const externalContext = document_1.withImports(context, { | ||
named: [{ name: helpers_1.convertNamespace(namespace), as: alias }], | ||
named: [{ name: helpers_1.convertName(namespace), as: alias }], | ||
module, | ||
@@ -102,3 +102,3 @@ }); | ||
const ref = namespace | ||
? ts_compose_1.Type.Referance([helpers_1.convertNamespace(namespace), helpers_1.firstUpperCase(name)]) | ||
? ts_compose_1.Type.Referance([helpers_1.convertName(namespace), helpers_1.firstUpperCase(name)]) | ||
: ts_compose_1.Type.Referance(helpers_1.firstUpperCase(name)); | ||
@@ -105,0 +105,0 @@ return ts_compose_1.document(context, ref); |
@@ -7,4 +7,4 @@ import { Context } from './types'; | ||
export declare const firstUpperCase: (name: string) => string; | ||
export declare const convertNamespace: (namespace: string) => string; | ||
export declare const convertName: (namespace: string) => string; | ||
export declare const nameParts: (fullName: string) => [string] | [string, string]; | ||
export declare const namedType: (type: ts.InterfaceDeclaration | ts.TypeAliasDeclaration, context: Context, schema: avroSchema.RecordType | avroSchema.EnumType, namespace?: string | undefined) => Document<ts.TypeNode, Context>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.namedType = exports.nameParts = exports.convertNamespace = exports.firstUpperCase = exports.fullName = void 0; | ||
exports.namedType = exports.nameParts = exports.convertName = exports.firstUpperCase = exports.fullName = void 0; | ||
const ts_compose_1 = require("@ovotech/ts-compose"); | ||
@@ -9,4 +9,7 @@ const fullName = (context, schema) => { var _a; return `${(_a = schema.namespace) !== null && _a !== void 0 ? _a : context.namespace}.${schema.name}`; }; | ||
exports.firstUpperCase = firstUpperCase; | ||
const convertNamespace = (namespace) => namespace.split('.').map(exports.firstUpperCase).join(''); | ||
exports.convertNamespace = convertNamespace; | ||
const convertName = (namespace) => namespace | ||
.split(/[^a-zA-Z0-9\_]+/) | ||
.map(exports.firstUpperCase) | ||
.join(''); | ||
exports.convertName = convertName; | ||
const nameParts = (fullName) => { | ||
@@ -20,4 +23,4 @@ const parts = fullName.split('.'); | ||
const namedType = (type, context, schema, namespace) => { | ||
const name = exports.firstUpperCase(schema.name); | ||
const namespaceName = namespace ? exports.convertNamespace(namespace) : undefined; | ||
const name = exports.convertName(exports.firstUpperCase(schema.name)); | ||
const namespaceName = namespace ? exports.convertName(namespace) : undefined; | ||
const fullName = namespaceName ? [namespaceName, name] : name; | ||
@@ -24,0 +27,0 @@ const contextWithRef = namespace |
@@ -30,3 +30,3 @@ "use strict"; | ||
const record = ts_compose_1.Type.Interface({ | ||
name: helpers_1.firstUpperCase(schema.name), | ||
name: helpers_1.convertName(helpers_1.firstUpperCase(schema.name)), | ||
props: fields.items, | ||
@@ -33,0 +33,0 @@ isExport: true, |
import { schema, Schema } from 'avsc'; | ||
import { Convert } from '../types'; | ||
export declare const isUnion: (type: Schema) => type is schema.NamedType[]; | ||
export declare const isUnion: (type: Schema) => type is ("string" | "boolean" | "null" | "int" | "long" | "float" | "double" | "bytes" | schema.NamedType)[]; | ||
export declare const convertUnionType: Convert<schema.DefinedType[]>; |
import { schema, Schema } from 'avsc'; | ||
import { Convert, Context } from '../types'; | ||
export declare const isWrappedUnion: (type: Schema, context: Context) => type is schema.RecordType[]; | ||
export declare const convertWrappedUnionType: Convert<schema.RecordType[]>; | ||
declare type WrappedUnionItem = schema.RecordType | 'null'; | ||
export declare const isWrappedUnion: (type: Schema, context: Context) => type is WrappedUnionItem[]; | ||
export declare const convertWrappedUnionType: Convert<WrappedUnionItem[]>; | ||
export {}; |
@@ -11,4 +11,4 @@ "use strict"; | ||
const isWrappedUnion = (type, context) => union_1.isUnion(type) && | ||
type.length > 1 && | ||
type.every((item) => record_1.isRecordType(resolveItem(context, item))); | ||
type.filter((item) => item !== 'null').length > 1 && | ||
type.filter((item) => item !== 'null').every((item) => record_1.isRecordType(resolveItem(context, item))); | ||
exports.isWrappedUnion = isWrappedUnion; | ||
@@ -21,11 +21,13 @@ const convertWrappedUnionType = (context, schema) => { | ||
context: { ...converted.context, namespace: context.namespace }, | ||
type: ts_compose_1.Type.TypeLiteral({ | ||
props: resolved.map((schemaItem) => { | ||
return ts_compose_1.Type.Prop({ | ||
name: helpers_1.fullName(context, schemaItem), | ||
isOptional: schemaItem.name === item.name ? false : true, | ||
type: schemaItem.name === item.name ? converted.type : ts_compose_1.Type.Never, | ||
}); | ||
}), | ||
}), | ||
type: record_1.isRecordType(item) | ||
? ts_compose_1.Type.TypeLiteral({ | ||
props: resolved.filter(record_1.isRecordType).map((schemaItem) => { | ||
return ts_compose_1.Type.Prop({ | ||
name: helpers_1.fullName(context, schemaItem), | ||
isOptional: schemaItem.name === item.name ? false : true, | ||
type: schemaItem.name === item.name ? converted.type : ts_compose_1.Type.Never, | ||
}); | ||
}), | ||
}) | ||
: ts_compose_1.Type.Null, | ||
}; | ||
@@ -32,0 +34,0 @@ }); |
{ | ||
"name": "@ovotech/avro-ts", | ||
"description": "Convert avro schemas into typescript interfaces", | ||
"version": "6.0.5", | ||
"version": "6.0.7", | ||
"main": "dist/index.js", | ||
@@ -40,3 +40,3 @@ "source": "src/index.ts", | ||
}, | ||
"gitHead": "932a027265d6986d733642c64467cff22e8771fe" | ||
"gitHead": "47626be2d648bec6ba92dbbfd5bfc41f94e12153" | ||
} |
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
32113
466