Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ovotech/avro-ts

Package Overview
Dependencies
Maintainers
149
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ovotech/avro-ts - npm Package Compare versions

Comparing version 4.2.2 to 4.2.3

1

dist/convert.d.ts

@@ -6,3 +6,4 @@ import { Schema } from 'avsc';

export declare const nameParts: (fullName: string) => [string] | [string, string];
export declare const collectRefs: (type: Schema, context: Context) => Context;
export declare const convertType: Convert;
export declare const toTypeScript: (schema: Schema, initial?: Context) => string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toTypeScript = exports.convertType = exports.nameParts = exports.convertNamespace = exports.firstUpperCase = void 0;
exports.toTypeScript = exports.convertType = exports.collectRefs = exports.nameParts = exports.convertNamespace = exports.firstUpperCase = void 0;
const ts_compose_1 = require("@ovotech/ts-compose");

@@ -16,7 +16,5 @@ const wrapped_union_1 = require("./types/wrapped-union");

const ts = require("typescript");
const helpers_1 = require("./helpers");
exports.firstUpperCase = (name) => name ? name[0].toUpperCase() + name.slice(1) : name;
exports.convertNamespace = (namespace) => namespace
.split('.')
.map(exports.firstUpperCase)
.join('');
exports.convertNamespace = (namespace) => namespace.split('.').map(exports.firstUpperCase).join('');
exports.nameParts = (fullName) => {

@@ -28,4 +26,28 @@ const parts = fullName.split('.');

};
exports.collectRefs = (type, context) => {
if (union_1.isUnion(type)) {
return type.reduce((all, item) => exports.collectRefs(item, all), context);
}
else if (array_1.isArrayType(type)) {
return exports.collectRefs(type.items, context);
}
else if (map_1.isMapType(type)) {
return exports.collectRefs(type.values, context);
}
else if (record_1.isRecordType(type)) {
return type.fields.reduce((all, item) => {
var _a;
return exports.collectRefs(item.type, {
...all,
namespace: (_a = type.namespace) !== null && _a !== void 0 ? _a : all.namespace,
refs: { ...all.refs, [helpers_1.fullName(all, type)]: type },
});
}, context);
}
else {
return context;
}
};
exports.convertType = (context, type) => {
if (wrapped_union_1.isWrappedUnion(type)) {
if (wrapped_union_1.isWrappedUnion(type, context)) {
return wrapped_union_1.convertWrappedUnionType(context, type);

@@ -70,3 +92,4 @@ }

exports.toTypeScript = (schema, initial = {}) => {
const { context, type } = exports.convertType(initial, schema);
const contextWithRefs = exports.collectRefs(schema, initial);
const { context, type } = exports.convertType(contextWithRefs, schema);
const contextWithHeader = context.namespaces

@@ -73,0 +96,0 @@ ? document_1.withHeader(context, '/* eslint-disable @typescript-eslint/no-namespace */')

@@ -19,3 +19,6 @@ import * as ts from 'typescript';

namespace?: string;
refs?: {
[key: string]: Schema;
};
}
export declare type Convert<TSchema = Schema, TType = ts.TypeNode> = (context: Context, type: TSchema) => Document<TType, Context>;

4

dist/types/wrapped-union.d.ts
import { schema, Schema } from 'avsc';
import { Convert } from '../types';
export declare const isWrappedUnion: (type: Schema) => type is schema.RecordType[];
import { Convert, Context } from '../types';
export declare const isWrappedUnion: (type: Schema, context: Context) => type is schema.RecordType[];
export declare const convertWrappedUnionType: Convert<schema.RecordType[]>;

@@ -9,3 +9,10 @@ "use strict";

const helpers_1 = require("../helpers");
exports.isWrappedUnion = (type) => union_1.isUnion(type) && type.every((item) => record_1.isRecordType(item) && type.length > 1);
exports.isWrappedUnion = (type, context) => union_1.isUnion(type) &&
type.length > 1 &&
type.every((item) => {
var _a, _b;
return typeof item === 'string' && ((_a = context.refs) === null || _a === void 0 ? void 0 : _a[item])
? record_1.isRecordType((_b = context.refs) === null || _b === void 0 ? void 0 : _b[item])
: record_1.isRecordType(item);
});
exports.convertWrappedUnionType = (context, schema) => {

@@ -12,0 +19,0 @@ const map = ts_compose_1.mapWithContext(context, schema, (itemContext, item) => {

{
"name": "@ovotech/avro-ts",
"description": "Convert avro schemas into typescript interfaces",
"version": "4.2.2",
"version": "4.2.3",
"main": "dist/index.js",

@@ -38,3 +38,3 @@ "source": "src/index.ts",

},
"gitHead": "b1a6700e81fa6c3359caac24d063d0bbe4685091"
"gitHead": "4162b0b08b32f53e2fd985d5bb78c6d3655a1f8a"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc