@brimdata/zealot
Advanced tools
Comparing version 0.0.13 to 0.0.14
@@ -17,3 +17,3 @@ "use strict"; | ||
this.address = address; | ||
this.baseURL = address; | ||
this.baseURL = `http://${address}`; | ||
} | ||
@@ -20,0 +20,0 @@ async version() { |
@@ -10,6 +10,7 @@ import { Client } from "./client"; | ||
}; | ||
declare function decode(data: zjson.RootRecord, opts: DecodeOpts & { | ||
declare function decode(data: zjson.RootRecord[], opts: DecodeOpts & { | ||
as: "js"; | ||
}): object; | ||
declare function decode(data: zjson.RootRecord, opts?: DecodeOpts): zed.Record; | ||
declare function decode(data: zjson.RootRecord[], opts?: DecodeOpts): zed.Record[]; | ||
declare function decode(data: zjson.EncodedField, opts?: DecodeOpts): zed.Field; | ||
@@ -16,0 +17,0 @@ declare type EncodeOpts = { |
/// <reference types="node" /> | ||
import EventEmitter from "events"; | ||
import { Record } from "./zed"; | ||
import { ZedTypeInterface } from "./zed/types/types"; | ||
import { Type } from "./zed/types/types"; | ||
declare class Channel extends EventEmitter { | ||
rows: Record[]; | ||
types: { | ||
[name: string]: ZedTypeInterface; | ||
[name: string]: Type; | ||
}; | ||
shapes: { | ||
[name: string]: ZedTypeInterface; | ||
[name: string]: Type; | ||
}; | ||
@@ -13,0 +13,0 @@ done: boolean; |
@@ -6,2 +6,2 @@ import { zed } from "../index"; | ||
export declare function createField(name: string, value: unknown): zed.Field; | ||
export declare function createData(value: unknown): zed.AnyValue; | ||
export declare function createData(value: unknown): zed.Value; |
@@ -6,7 +6,7 @@ import { Context } from "."; | ||
import { TypeSet } from "./types/type-set"; | ||
import { ContainerTypeInterface, SerializeTypeDefs, ZedTypeInterface } from "./types/types"; | ||
import { ContainerType, SerializeTypeDefs, Type } from "./types/types"; | ||
import { Field } from "./values/field"; | ||
import { Record } from "./values/record"; | ||
export declare type TypeDefs = { | ||
[key: string]: ZedTypeInterface; | ||
[key: string]: Type; | ||
}; | ||
@@ -20,15 +20,15 @@ export declare class ZedContext { | ||
decodeRecord({ schema, types, values }: zjson.RootRecord, typedefs?: TypeDefs): Record; | ||
decodeType(obj: zjson.Type, typedefs?: TypeDefs): ZedTypeInterface; | ||
decodeType(obj: zjson.Type, typedefs?: TypeDefs): Type; | ||
lookupTypeRecord(fields: TypeField[] | null): TypeRecord; | ||
lookupTypeArray(type: ZedTypeInterface): TypeArray; | ||
lookupTypeSet(type: ZedTypeInterface): TypeSet; | ||
lookupTypeUnion(types: ZedTypeInterface[]): ZedTypeInterface; | ||
lookupTypeMap(keyType: ZedTypeInterface, valType: ZedTypeInterface): ZedTypeInterface; | ||
lookupTypeAlias(name: string, type: ZedTypeInterface): ZedTypeInterface; | ||
alloc<T extends ContainerTypeInterface>(key: string, type: T): T; | ||
lookupTypeArray(type: Type): TypeArray; | ||
lookupTypeSet(type: Type): TypeSet; | ||
lookupTypeUnion(types: Type[]): Type; | ||
lookupTypeMap(keyType: Type, valType: Type): Type; | ||
lookupTypeAlias(name: string, type: Type): Type; | ||
alloc<T extends ContainerType>(key: string, type: T): T; | ||
encode(records: Record[]): zjson.RootRecord[]; | ||
encodeRecord(record: Record, typedefs?: SerializeTypeDefs): zjson.RootRecord; | ||
encodeTypeDef(name: string, typedefs: SerializeTypeDefs, types: zjson.Type[]): void; | ||
walkTypeValues(type: ZedTypeInterface, value: zjson.Value, visit: (name: string) => void): void; | ||
hasTypeType(type: ZedTypeInterface): type is ContainerTypeInterface; | ||
walkTypeValues(type: Type, value: zjson.Value, visit: (name: string) => void): void; | ||
hasTypeType(type: Type): type is ContainerType; | ||
decodeField(obj: zjson.EncodedField): Field; | ||
@@ -35,0 +35,0 @@ encodeField(field: Field): zjson.EncodedField; |
@@ -191,4 +191,3 @@ "use strict"; | ||
return this.typetype[name]; | ||
const bool = "hasTypeType" in type && | ||
type.hasTypeType(this); | ||
const bool = "hasTypeType" in type && type.hasTypeType(this); | ||
this.typetype[name] = bool; | ||
@@ -195,0 +194,0 @@ return bool; |
@@ -57,4 +57,5 @@ export { ZedContext as Context } from "./context"; | ||
export { Union } from "./values/union"; | ||
export { ZedValue as AnyValue } from "./values/types"; | ||
export { Schema } from "./schema"; | ||
export * from "./values/types"; | ||
export * from "./types/types"; | ||
export * from "./utils"; |
@@ -129,2 +129,4 @@ "use strict"; | ||
Object.defineProperty(exports, "Schema", { enumerable: true, get: function () { return schema_1.Schema; } }); | ||
__exportStar(require("./values/types"), exports); | ||
__exportStar(require("./types/types"), exports); | ||
__exportStar(require("./utils"), exports); |
@@ -1,10 +0,10 @@ | ||
import { PrimitiveType, Value } from "../../zjson"; | ||
import { ZedValueInterface } from "../values/types"; | ||
import { ZedTypeInterface } from "./types"; | ||
export declare abstract class BasePrimitive<T> implements ZedTypeInterface { | ||
import * as zjson from "../../zjson"; | ||
import { Value } from "../values/types"; | ||
import { Type } from "./types"; | ||
export declare abstract class BasePrimitive<T> implements Type { | ||
kind: string; | ||
abstract name: string; | ||
abstract create(value: Value, typedefs?: object): ZedValueInterface; | ||
serialize(): PrimitiveType; | ||
abstract create(value: zjson.Value, typedefs?: object): Value; | ||
serialize(): zjson.PrimitiveType; | ||
toString(): string; | ||
} |
import { Field } from "../index"; | ||
import * as zjson from "../../zjson"; | ||
import { TypeDefs, ZedContext } from "../context"; | ||
import { ZedValueInterface } from "../values/types"; | ||
import { ContainerTypeInterface, SerializeTypeDefs, ZedTypeInterface } from "./types"; | ||
export declare class TypeAlias implements ContainerTypeInterface { | ||
import { Value } from "../values/types"; | ||
import { ContainerType, SerializeTypeDefs, Type } from "./types"; | ||
export declare class TypeAlias implements ContainerType { | ||
kind: string; | ||
name: string; | ||
type: ZedTypeInterface; | ||
type: Type; | ||
id?: string | number; | ||
constructor(name: string, type: ZedTypeInterface); | ||
static stringify(name: string, type: ZedTypeInterface): string; | ||
create(value: zjson.Value, typedefs: TypeDefs, parent?: Field): ZedValueInterface; | ||
constructor(name: string, type: Type); | ||
static stringify(name: string, type: Type): string; | ||
create(value: zjson.Value, typedefs: TypeDefs, parent?: Field): Value; | ||
serialize(typedefs: SerializeTypeDefs): zjson.Type; | ||
@@ -15,0 +15,0 @@ hasTypeType(): boolean; |
import * as zjson from "../../zjson"; | ||
import { TypeDefs, ZedContext } from "../context"; | ||
import { Array } from "../values/array"; | ||
import { ContainerTypeInterface, SerializeTypeDefs, ZedTypeInterface } from "./types"; | ||
export declare class TypeArray implements ContainerTypeInterface { | ||
import { ContainerType, SerializeTypeDefs, Type } from "./types"; | ||
export declare class TypeArray implements ContainerType { | ||
id?: number | string; | ||
kind: string; | ||
type: ZedTypeInterface; | ||
constructor(type: ZedTypeInterface); | ||
static stringify(type: ZedTypeInterface): string; | ||
type: Type; | ||
constructor(type: Type); | ||
static stringify(type: Type): string; | ||
create(values: zjson.ArrayValue | null, typedefs: TypeDefs): Array; | ||
@@ -12,0 +12,0 @@ serialize(typedefs: SerializeTypeDefs): zjson.ArrayType; |
import * as zjson from "../../zjson"; | ||
import { TypeDefs, ZedContext } from "../context"; | ||
import { ZedMap } from "../values/map"; | ||
import { ContainerTypeInterface, SerializeTypeDefs, ZedTypeInterface } from "./types"; | ||
export declare class TypeMap implements ContainerTypeInterface { | ||
keyType: ZedTypeInterface; | ||
valType: ZedTypeInterface; | ||
import { ContainerType, SerializeTypeDefs, Type } from "./types"; | ||
export declare class TypeMap implements ContainerType { | ||
keyType: Type; | ||
valType: Type; | ||
kind: string; | ||
id?: string | number; | ||
constructor(keyType: ZedTypeInterface, valType: ZedTypeInterface); | ||
static stringify(keyType: ZedTypeInterface, valType: ZedTypeInterface): string; | ||
constructor(keyType: Type, valType: Type); | ||
static stringify(keyType: Type, valType: Type): string; | ||
create(value: [zjson.Value, zjson.Value][] | null, typedefs: TypeDefs): ZedMap; | ||
@@ -13,0 +13,0 @@ serialize(typedefs: SerializeTypeDefs): zjson.MapType; |
@@ -5,8 +5,8 @@ import * as zjson from "../../zjson"; | ||
import { Record } from "../values/record"; | ||
import { ContainerTypeInterface, SerializeTypeDefs, ZedTypeInterface } from "./types"; | ||
import { ContainerType, SerializeTypeDefs, Type } from "./types"; | ||
export declare type TypeField = { | ||
name: string; | ||
type: ZedTypeInterface; | ||
type: Type; | ||
}; | ||
export declare class TypeRecord implements ContainerTypeInterface { | ||
export declare class TypeRecord implements ContainerType { | ||
kind: string; | ||
@@ -13,0 +13,0 @@ fields: TypeField[] | null; |
@@ -5,9 +5,9 @@ import * as zjson from "../../zjson"; | ||
import { Set } from "../values/set"; | ||
import { ContainerTypeInterface, SerializeTypeDefs, ZedTypeInterface } from "./types"; | ||
export declare class TypeSet implements ContainerTypeInterface { | ||
import { ContainerType, SerializeTypeDefs, Type } from "./types"; | ||
export declare class TypeSet implements ContainerType { | ||
id?: string | number; | ||
kind: string; | ||
type: ZedTypeInterface; | ||
constructor(type: ZedTypeInterface); | ||
static stringify(type: ZedTypeInterface): string; | ||
type: Type; | ||
constructor(type: Type); | ||
static stringify(type: Type): string; | ||
create(values: SetValue, typedefs: TypeDefs): Set; | ||
@@ -14,0 +14,0 @@ serialize(typedefs: SerializeTypeDefs): zjson.SetType; |
import * as zjson from "../../zjson"; | ||
import { TypeDefs, ZedContext } from "../context"; | ||
import { TypeValue } from "../values/type"; | ||
import { ZedValueInterface } from "../values/types"; | ||
import { Value } from "../values/types"; | ||
import { BasePrimitive } from "./base-primitive"; | ||
export declare class TypeOfType extends BasePrimitive<TypeValue> { | ||
name: string; | ||
create(value: string | null, typedefs: TypeDefs): ZedValueInterface; | ||
create(value: string | null, typedefs: TypeDefs): Value; | ||
hasTypeType(): boolean; | ||
@@ -10,0 +10,0 @@ walkTypeValues(ctx: ZedContext, value: zjson.Value, visit: (name: string) => void): void; |
@@ -5,10 +5,10 @@ import { Context } from "../index"; | ||
import { Union } from "../values/union"; | ||
import { ContainerTypeInterface, SerializeTypeDefs, ZedTypeInterface } from "./types"; | ||
import { ContainerType, SerializeTypeDefs, Type } from "./types"; | ||
declare type UnionValue = [string, zjson.Value] | null; | ||
export declare class TypeUnion implements ContainerTypeInterface { | ||
types: ZedTypeInterface[]; | ||
export declare class TypeUnion implements ContainerType { | ||
types: Type[]; | ||
kind: string; | ||
id?: number | string; | ||
constructor(types: ZedTypeInterface[]); | ||
static stringify(types: ZedTypeInterface[]): string; | ||
constructor(types: Type[]); | ||
static stringify(types: Type[]): string; | ||
create(value: zjson.UnionValue, typedefs: TypeDefs): Union; | ||
@@ -15,0 +15,0 @@ serialize(typedefs: SerializeTypeDefs): zjson.UnionType; |
import { Field } from "../index"; | ||
import * as zjson from "../../zjson"; | ||
import { TypeDefs, ZedContext } from "../context"; | ||
import { ZedValueInterface } from "../values/types"; | ||
import { Value } from "../values/types"; | ||
import { TypeAlias } from "./type-alias"; | ||
@@ -16,11 +16,11 @@ import { TypeArray } from "./type-array"; | ||
}; | ||
export interface ZedTypeInterface { | ||
export interface Type { | ||
id?: string | number; | ||
toString(): string; | ||
serialize(typedefs: SerializeTypeDefs): zjson.Type; | ||
create(value: zjson.Value, typedefs: TypeDefs, parent?: Field): ZedValueInterface; | ||
create(value: zjson.Value, typedefs: TypeDefs, parent?: Field): Value; | ||
} | ||
export interface ContainerTypeInterface extends ZedTypeInterface { | ||
export interface ContainerType extends Type { | ||
hasTypeType(ctx: ZedContext): boolean; | ||
walkTypeValues(context: ZedContext, value: zjson.Value, visit: (name: string) => void): void; | ||
} |
import { Array, Primitive, Set, TypeAlias, TypeRecord } from "./index"; | ||
import { PrimitiveName, PrimitiveTypes } from "./types/type-primitives"; | ||
import { ZedTypeInterface } from "./types/types"; | ||
import { Type } from "./types/types"; | ||
import { BString } from "./values/bstring"; | ||
@@ -10,9 +10,9 @@ import { Duration } from "./values/duration"; | ||
import { ZedInt } from "./values/types"; | ||
export declare function typeId(type: ZedTypeInterface): string; | ||
export declare function typeId(type: Type): string; | ||
export declare function isAlias(name: string | number): boolean; | ||
export declare function isInt(value: unknown): value is ZedInt; | ||
export declare function isTime(value: unknown): value is Time; | ||
export declare function isTypeAlias(type: ZedTypeInterface): type is TypeAlias; | ||
export declare function isNamed(type: ZedTypeInterface, name: string): boolean; | ||
export declare function trueType<T extends ZedTypeInterface>(start: ZedTypeInterface): T; | ||
export declare function isTypeAlias(type: Type): type is TypeAlias; | ||
export declare function isNamed(type: Type, name: string): boolean; | ||
export declare function trueType<T extends Type>(start: Type): T; | ||
export declare function isNull(value: unknown): value is null; | ||
@@ -19,0 +19,0 @@ export declare function isStringy(value: unknown): value is String | BString; |
import { TypeArray } from "../types/type-array"; | ||
import { ZedValueInterface } from "./types"; | ||
export declare class Array implements ZedValueInterface { | ||
import { Value } from "./types"; | ||
export declare class Array implements Value { | ||
type: TypeArray; | ||
items: ZedValueInterface[] | null; | ||
constructor(type: TypeArray, items: ZedValueInterface[] | null); | ||
indexOf(value: ZedValueInterface): number; | ||
at(index: number): ZedValueInterface | undefined; | ||
items: Value[] | null; | ||
constructor(type: TypeArray, items: Value[] | null); | ||
indexOf(value: Value): number; | ||
at(index: number): Value | undefined; | ||
toString(): string; | ||
@@ -10,0 +10,0 @@ serialize(): import("../../zjson").Value[] | null; |
import { Record } from "./record"; | ||
import { ZedValueInterface } from "./types"; | ||
import { Value } from "./types"; | ||
export declare class Field { | ||
name: string; | ||
value: ZedValueInterface; | ||
value: Value; | ||
parent: Record | Field | null; | ||
constructor(name: string, value: ZedValueInterface, parent: Record | Field | null); | ||
constructor(name: string, value: Value, parent: Record | Field | null); | ||
/** | ||
* Alias for value | ||
*/ | ||
get data(): ZedValueInterface; | ||
get data(): Value; | ||
get path(): string[]; | ||
get rootRecord(): Record | null; | ||
} |
import { TypeMap } from "../types/type-map"; | ||
import { ZedValueInterface } from "./types"; | ||
export declare class ZedMap implements ZedValueInterface { | ||
import { Value } from "./types"; | ||
export declare class ZedMap implements Value { | ||
type: TypeMap; | ||
value: Map<ZedValueInterface, ZedValueInterface> | null; | ||
constructor(type: TypeMap, value: Map<ZedValueInterface, ZedValueInterface> | null); | ||
value: Map<Value, Value> | null; | ||
constructor(type: TypeMap, value: Map<Value, Value> | null); | ||
toString(): string; | ||
@@ -8,0 +8,0 @@ serialize(): import("../../zjson").Value[][] | null; |
@@ -1,6 +0,6 @@ | ||
import { ZedTypeInterface } from "../types/types"; | ||
import { ZedValueInterface } from "./types"; | ||
export declare abstract class Primitive implements ZedValueInterface { | ||
import { Type } from "../types/types"; | ||
import { Value } from "./types"; | ||
export declare abstract class Primitive implements Value { | ||
value: string | null; | ||
abstract type: ZedTypeInterface; | ||
abstract type: Type; | ||
abstract toJS(): any; | ||
@@ -7,0 +7,0 @@ constructor(value?: string | null); |
@@ -5,5 +5,5 @@ import { TypeAlias } from "../types/type-alias"; | ||
import { Field } from "./field"; | ||
import { ZedValue, ZedValueInterface } from "./types"; | ||
import { ZedValue, Value } from "./types"; | ||
declare type ColumnName = string | string[]; | ||
export declare class Record implements ZedValueInterface { | ||
export declare class Record implements Value { | ||
type: TypeRecord | TypeAlias; | ||
@@ -18,3 +18,3 @@ fields: Field[] | null; | ||
serialize(): import("../../zjson").Value[] | null; | ||
at(index: number): ZedValueInterface | undefined; | ||
at(index: number): Value | undefined; | ||
fieldAt(index: number): Field | null; | ||
@@ -21,0 +21,0 @@ has(name: string | string[], ...types: ZedType[]): boolean; |
import { TypeSet } from "../types/type-set"; | ||
import { ZedValueInterface } from "./types"; | ||
export declare class Set implements ZedValueInterface { | ||
import { Value } from "./types"; | ||
export declare class Set implements Value { | ||
type: TypeSet; | ||
items: ZedValueInterface[] | null; | ||
constructor(type: TypeSet, items: ZedValueInterface[] | null); | ||
indexOf(value: ZedValueInterface): number; | ||
at(index: number): ZedValueInterface | undefined; | ||
items: Value[] | null; | ||
constructor(type: TypeSet, items: Value[] | null); | ||
indexOf(value: Value): number; | ||
at(index: number): Value | undefined; | ||
toString(): string; | ||
@@ -10,0 +10,0 @@ serialize(): import("../../zjson").Value[] | null; |
import { TypeType } from "../types/type-type"; | ||
import { ZedTypeInterface } from "../types/types"; | ||
import { ZedValueInterface } from "./types"; | ||
export declare class TypeValue implements ZedValueInterface { | ||
value: ZedTypeInterface | null; | ||
import { Type } from "../types/types"; | ||
import { Value } from "./types"; | ||
export declare class TypeValue implements Value { | ||
value: Type | null; | ||
type: typeof TypeType; | ||
constructor(value?: ZedTypeInterface | null); | ||
constructor(value?: Type | null); | ||
isUnset(): boolean; | ||
@@ -9,0 +9,0 @@ toString(): string; |
@@ -1,3 +0,3 @@ | ||
import { Value } from "../../zjson"; | ||
import { ZedTypeInterface } from "../types/types"; | ||
import * as zjson from "../../zjson"; | ||
import { Type } from "../types/types"; | ||
import { Array } from "./array"; | ||
@@ -30,8 +30,8 @@ import { Bool } from "./bool"; | ||
export declare type ZedInt = Uint8 | Uint16 | Uint32 | Uint64 | Int8 | Int16 | Int32 | Int64; | ||
export interface ZedValueInterface { | ||
export interface Value { | ||
toJS(): any; | ||
toString(): string; | ||
serialize(): Value; | ||
serialize(): zjson.Value; | ||
isUnset(): boolean; | ||
type: ZedTypeInterface; | ||
type: Type; | ||
} |
import { TypeUnion } from "../types/type-union"; | ||
import { ZedTypeInterface } from "../types/types"; | ||
import { ZedValueInterface } from "./types"; | ||
export declare class Union implements ZedValueInterface { | ||
import { Type } from "../types/types"; | ||
import { Value } from "./types"; | ||
export declare class Union implements Value { | ||
type: TypeUnion; | ||
innerType: ZedTypeInterface; | ||
innerType: Type; | ||
index: number | null; | ||
value: ZedValueInterface | null; | ||
constructor(type: TypeUnion, innerType: ZedTypeInterface, index: number | null, value: ZedValueInterface | null); | ||
value: Value | null; | ||
constructor(type: TypeUnion, innerType: Type, index: number | null, value: Value | null); | ||
toString(): string; | ||
@@ -11,0 +11,0 @@ serialize(): import("../../zjson").Value[] | null; |
{ | ||
"name": "@brimdata/zealot", | ||
"version": "0.0.13", | ||
"version": "0.0.14", | ||
"description": "The Javascript Client for Zed Lakes", | ||
@@ -54,3 +54,3 @@ "keywords": [ | ||
"typescript": "^4.4.4", | ||
"zed": "file:../zed" | ||
"zed": "git+https://github.com/brimdata/zed.git#cd206afb6c2b91a8bffd699f11d426aa51c45986" | ||
}, | ||
@@ -57,0 +57,0 @@ "dependencies": { |
@@ -58,3 +58,3 @@ import fetch from "cross-fetch"; | ||
constructor(public address: string) { | ||
this.baseURL = address; | ||
this.baseURL = `http://${address}`; | ||
} | ||
@@ -61,0 +61,0 @@ |
@@ -13,6 +13,7 @@ import { Client } from "./client"; | ||
function decode( | ||
data: zjson.RootRecord, | ||
data: zjson.RootRecord[], | ||
opts: DecodeOpts & { as: "js" } | ||
): object; | ||
function decode(data: zjson.RootRecord, opts?: DecodeOpts): zed.Record; | ||
function decode(data: zjson.RootRecord[], opts?: DecodeOpts): zed.Record[]; | ||
function decode(data: zjson.EncodedField, opts?: DecodeOpts): zed.Field; | ||
@@ -19,0 +20,0 @@ function decode( |
import EventEmitter from "events"; | ||
import { decode } from "."; | ||
import { Record } from "./zed"; | ||
import { ZedTypeInterface } from "./zed/types/types"; | ||
import { Type } from "./zed/types/types"; | ||
import { RootRecord } from "./zjson"; | ||
@@ -9,4 +9,4 @@ | ||
rows: Record[] = []; | ||
types: { [name: string]: ZedTypeInterface } = {}; | ||
shapes: { [name: string]: ZedTypeInterface } = {}; | ||
types: { [name: string]: Type } = {}; | ||
shapes: { [name: string]: Type } = {}; | ||
done: boolean = false; | ||
@@ -13,0 +13,0 @@ |
@@ -30,5 +30,5 @@ import { isDate, isInteger, isNumber, isObject, isString } from "lodash"; | ||
export function createData(value: unknown): zed.AnyValue { | ||
export function createData(value: unknown): zed.Value { | ||
if (value instanceof zed.Primitive) { | ||
return value as zed.AnyValue; | ||
return value as zed.Value; | ||
} | ||
@@ -35,0 +35,0 @@ |
@@ -10,7 +10,3 @@ import { Context } from "."; | ||
import { TypeUnion } from "./types/type-union"; | ||
import { | ||
ContainerTypeInterface, | ||
SerializeTypeDefs, | ||
ZedTypeInterface, | ||
} from "./types/types"; | ||
import { ContainerType, SerializeTypeDefs, Type } from "./types/types"; | ||
import { isAlias, isNull, typeId } from "./utils"; | ||
@@ -20,3 +16,3 @@ import { Field } from "./values/field"; | ||
export type TypeDefs = { [key: string]: ZedTypeInterface }; | ||
export type TypeDefs = { [key: string]: Type }; | ||
@@ -42,3 +38,3 @@ export class ZedContext { | ||
decodeType(obj: zjson.Type, typedefs: TypeDefs = {}): ZedTypeInterface { | ||
decodeType(obj: zjson.Type, typedefs: TypeDefs = {}): Type { | ||
// All types with the same shape in a zed context must point to the same type instance. When | ||
@@ -121,3 +117,3 @@ // decoding a stream of zjson, use the following logic to get the correct type instance. | ||
lookupTypeArray(type: ZedTypeInterface): TypeArray { | ||
lookupTypeArray(type: Type): TypeArray { | ||
const key = TypeArray.stringify(type); | ||
@@ -131,3 +127,3 @@ if (key in this.typeByShape) { | ||
lookupTypeSet(type: ZedTypeInterface): TypeSet { | ||
lookupTypeSet(type: Type): TypeSet { | ||
const key = TypeSet.stringify(type); | ||
@@ -141,3 +137,3 @@ if (key in this.typeByShape) { | ||
lookupTypeUnion(types: ZedTypeInterface[]) { | ||
lookupTypeUnion(types: Type[]) { | ||
const key = TypeUnion.stringify(types); | ||
@@ -151,3 +147,3 @@ if (key in this.typeByShape) { | ||
lookupTypeMap(keyType: ZedTypeInterface, valType: ZedTypeInterface) { | ||
lookupTypeMap(keyType: Type, valType: Type) { | ||
const key = TypeMap.stringify(keyType, valType); | ||
@@ -161,3 +157,3 @@ if (key in this.typeByShape) { | ||
lookupTypeAlias(name: string, type: ZedTypeInterface) { | ||
lookupTypeAlias(name: string, type: Type) { | ||
const key = TypeAlias.stringify(name, type); | ||
@@ -174,3 +170,3 @@ if (key in this.typeByShape) { | ||
alloc<T extends ContainerTypeInterface>(key: string, type: T): T { | ||
alloc<T extends ContainerType>(key: string, type: T): T { | ||
type.id = this.id++; | ||
@@ -224,3 +220,3 @@ this.typeByShape[key] = type; | ||
walkTypeValues( | ||
type: ZedTypeInterface, | ||
type: Type, | ||
value: zjson.Value, | ||
@@ -234,3 +230,3 @@ visit: (name: string) => void | ||
hasTypeType(type: ZedTypeInterface): type is ContainerTypeInterface { | ||
hasTypeType(type: Type): type is ContainerType { | ||
const name = typeId(type); | ||
@@ -240,4 +236,3 @@ if (name in this.typetype) return this.typetype[name]; | ||
const bool = | ||
"hasTypeType" in type && | ||
(type as ContainerTypeInterface).hasTypeType(this); | ||
"hasTypeType" in type && (type as ContainerType).hasTypeType(this); | ||
this.typetype[name] = bool; | ||
@@ -244,0 +239,0 @@ return bool; |
@@ -57,4 +57,5 @@ export { ZedContext as Context } from "./context"; | ||
export { Union } from "./values/union"; | ||
export { ZedValue as AnyValue } from "./values/types"; | ||
export { Schema } from "./schema"; | ||
export * from "./values/types"; | ||
export * from "./types/types"; | ||
export * from "./utils"; |
@@ -1,11 +0,11 @@ | ||
import { PrimitiveType, Value } from "../../zjson"; | ||
import { ZedValueInterface } from "../values/types"; | ||
import { ZedTypeInterface } from "./types"; | ||
import * as zjson from "../../zjson"; | ||
import { Value } from "../values/types"; | ||
import { Type } from "./types"; | ||
export abstract class BasePrimitive<T> implements ZedTypeInterface { | ||
export abstract class BasePrimitive<T> implements Type { | ||
kind = "primitive"; | ||
abstract name: string; | ||
abstract create(value: Value, typedefs?: object): ZedValueInterface; | ||
abstract create(value: zjson.Value, typedefs?: object): Value; | ||
serialize(): PrimitiveType { | ||
serialize(): zjson.PrimitiveType { | ||
return { kind: "primitive", name: this.name }; | ||
@@ -12,0 +12,0 @@ } |
import { Field, TypeRecord } from "../index"; | ||
import * as zjson from "../../zjson"; | ||
import { TypeDefs, ZedContext } from "../context"; | ||
import { ZedValueInterface } from "../values/types"; | ||
import { | ||
ContainerTypeInterface, | ||
SerializeTypeDefs, | ||
ZedType, | ||
ZedTypeInterface, | ||
} from "./types"; | ||
import { Value } from "../values/types"; | ||
import { ContainerType, SerializeTypeDefs, ZedType, Type } from "./types"; | ||
export class TypeAlias implements ContainerTypeInterface { | ||
export class TypeAlias implements ContainerType { | ||
kind = "alias"; | ||
name: string; | ||
type: ZedTypeInterface; | ||
type: Type; | ||
id?: string | number; | ||
constructor(name: string, type: ZedTypeInterface) { | ||
constructor(name: string, type: Type) { | ||
this.name = name; | ||
@@ -23,3 +18,3 @@ this.type = type; | ||
static stringify(name: string, type: ZedTypeInterface) { | ||
static stringify(name: string, type: Type) { | ||
return name + "=(" + type.toString() + ")"; | ||
@@ -29,3 +24,3 @@ } | ||
create(value: zjson.Value, typedefs: TypeDefs, parent?: Field) { | ||
let v: ZedValueInterface; | ||
let v: Value; | ||
if (this.type instanceof TypeRecord || this.type instanceof TypeAlias) { | ||
@@ -32,0 +27,0 @@ v = this.type.create(value, typedefs, parent); |
@@ -6,18 +6,14 @@ /* eslint-disable @typescript-eslint/no-array-constructor */ | ||
import { Array } from "../values/array"; | ||
import { | ||
ContainerTypeInterface, | ||
SerializeTypeDefs, | ||
ZedTypeInterface, | ||
} from "./types"; | ||
import { ContainerType, SerializeTypeDefs, Type } from "./types"; | ||
export class TypeArray implements ContainerTypeInterface { | ||
export class TypeArray implements ContainerType { | ||
id?: number | string; | ||
kind = "array"; | ||
type: ZedTypeInterface; | ||
type: Type; | ||
constructor(type: ZedTypeInterface) { | ||
constructor(type: Type) { | ||
this.type = type; | ||
} | ||
static stringify(type: ZedTypeInterface) { | ||
static stringify(type: Type) { | ||
return `[${typeId(type)}]`; | ||
@@ -24,0 +20,0 @@ } |
@@ -5,18 +5,11 @@ import * as zjson from "../../zjson"; | ||
import { ZedMap } from "../values/map"; | ||
import { | ||
ContainerTypeInterface, | ||
SerializeTypeDefs, | ||
ZedTypeInterface, | ||
} from "./types"; | ||
import { ContainerType, SerializeTypeDefs, Type } from "./types"; | ||
export class TypeMap implements ContainerTypeInterface { | ||
export class TypeMap implements ContainerType { | ||
kind = "union"; | ||
id?: string | number; | ||
constructor( | ||
public keyType: ZedTypeInterface, | ||
public valType: ZedTypeInterface | ||
) {} | ||
constructor(public keyType: Type, public valType: Type) {} | ||
static stringify(keyType: ZedTypeInterface, valType: ZedTypeInterface) { | ||
static stringify(keyType: Type, valType: Type) { | ||
return `|{` + typeId(keyType) + ":" + typeId(valType) + "}|"; | ||
@@ -23,0 +16,0 @@ } |
@@ -7,10 +7,5 @@ import { isNull } from "../utils"; | ||
import { Record } from "../values/record"; | ||
import { | ||
ContainerTypeInterface, | ||
SerializeTypeDefs, | ||
ZedType, | ||
ZedTypeInterface, | ||
} from "./types"; | ||
import { ContainerType, SerializeTypeDefs, ZedType, Type } from "./types"; | ||
import { Null, trueType } from "../index"; | ||
import { ZedValueInterface } from "../values/types"; | ||
import { Value } from "../values/types"; | ||
import { values } from "lodash"; | ||
@@ -20,6 +15,6 @@ | ||
name: string; | ||
type: ZedTypeInterface; | ||
type: Type; | ||
}; | ||
export class TypeRecord implements ContainerTypeInterface { | ||
export class TypeRecord implements ContainerType { | ||
kind = "record"; | ||
@@ -26,0 +21,0 @@ fields: TypeField[] | null; |
@@ -6,18 +6,14 @@ import * as zjson from "../../zjson"; | ||
import { Set } from "../values/set"; | ||
import { | ||
ContainerTypeInterface, | ||
SerializeTypeDefs, | ||
ZedTypeInterface, | ||
} from "./types"; | ||
import { ContainerType, SerializeTypeDefs, Type } from "./types"; | ||
export class TypeSet implements ContainerTypeInterface { | ||
export class TypeSet implements ContainerType { | ||
id?: string | number; | ||
kind = "set"; | ||
type: ZedTypeInterface; | ||
type: Type; | ||
constructor(type: ZedTypeInterface) { | ||
constructor(type: Type) { | ||
this.type = type; | ||
} | ||
static stringify(type: ZedTypeInterface) { | ||
static stringify(type: Type) { | ||
return `|[${typeId(type)}]|`; | ||
@@ -24,0 +20,0 @@ } |
@@ -5,3 +5,3 @@ import * as zjson from "../../zjson"; | ||
import { TypeValue } from "../values/type"; | ||
import { ZedValueInterface } from "../values/types"; | ||
import { Value } from "../values/types"; | ||
import { BasePrimitive } from "./base-primitive"; | ||
@@ -12,3 +12,3 @@ | ||
create(value: string | null, typedefs: TypeDefs): ZedValueInterface { | ||
create(value: string | null, typedefs: TypeDefs): Value { | ||
if (isNull(value)) { | ||
@@ -15,0 +15,0 @@ return new TypeValue(null); |
@@ -7,16 +7,12 @@ import { Context } from "../index"; | ||
import { TypeNull } from "./type-null"; | ||
import { | ||
ContainerTypeInterface, | ||
SerializeTypeDefs, | ||
ZedTypeInterface, | ||
} from "./types"; | ||
import { ContainerType, SerializeTypeDefs, Type } from "./types"; | ||
type UnionValue = [string, zjson.Value] | null; | ||
export class TypeUnion implements ContainerTypeInterface { | ||
export class TypeUnion implements ContainerType { | ||
kind = "union"; | ||
id?: number | string; | ||
constructor(public types: ZedTypeInterface[]) {} | ||
constructor(public types: Type[]) {} | ||
static stringify(types: ZedTypeInterface[]) { | ||
static stringify(types: Type[]) { | ||
return `(${types.map(typeId).join(",")})`; | ||
@@ -55,3 +51,3 @@ } | ||
const index = parseInt(value[0]); | ||
const innerType = this.types[index] as ZedTypeInterface; | ||
const innerType = this.types[index] as Type; | ||
const innerValue = value[1]; | ||
@@ -58,0 +54,0 @@ |
import { Field } from "../index"; | ||
import * as zjson from "../../zjson"; | ||
import { TypeDefs, ZedContext } from "../context"; | ||
import { ZedValueInterface } from "../values/types"; | ||
import { Value } from "../values/types"; | ||
import { TypeAlias } from "./type-alias"; | ||
@@ -26,14 +26,10 @@ import { TypeArray } from "./type-array"; | ||
export interface ZedTypeInterface { | ||
export interface Type { | ||
id?: string | number; | ||
toString(): string; | ||
serialize(typedefs: SerializeTypeDefs): zjson.Type; | ||
create( | ||
value: zjson.Value, | ||
typedefs: TypeDefs, | ||
parent?: Field | ||
): ZedValueInterface; | ||
create(value: zjson.Value, typedefs: TypeDefs, parent?: Field): Value; | ||
} | ||
export interface ContainerTypeInterface extends ZedTypeInterface { | ||
export interface ContainerType extends Type { | ||
hasTypeType(ctx: ZedContext): boolean; | ||
@@ -40,0 +36,0 @@ walkTypeValues( |
@@ -17,3 +17,3 @@ import { | ||
} from "./types/type-primitives"; | ||
import { ZedTypeInterface } from "./types/types"; | ||
import { Type } from "./types/types"; | ||
import { BString } from "./values/bstring"; | ||
@@ -30,3 +30,3 @@ import { Duration } from "./values/duration"; | ||
export function typeId(type: ZedTypeInterface) { | ||
export function typeId(type: Type) { | ||
if (type instanceof BasePrimitive) { | ||
@@ -66,13 +66,11 @@ return type.name; | ||
export function isTypeAlias(type: ZedTypeInterface): type is TypeAlias { | ||
export function isTypeAlias(type: Type): type is TypeAlias { | ||
return type instanceof TypeAlias; | ||
} | ||
export function isNamed(type: ZedTypeInterface, name: string) { | ||
export function isNamed(type: Type, name: string) { | ||
return isTypeAlias(type) && type.name === name; | ||
} | ||
export function trueType<T extends ZedTypeInterface>( | ||
start: ZedTypeInterface | ||
): T { | ||
export function trueType<T extends Type>(start: Type): T { | ||
let t = start; | ||
@@ -79,0 +77,0 @@ while (isTypeAlias(t)) { |
import { TypeArray } from "../types/type-array"; | ||
import { isNull } from "../utils"; | ||
import { ZedValueInterface } from "./types"; | ||
import { Value } from "./types"; | ||
export class Array implements ZedValueInterface { | ||
constructor( | ||
public type: TypeArray, | ||
public items: ZedValueInterface[] | null | ||
) {} | ||
export class Array implements Value { | ||
constructor(public type: TypeArray, public items: Value[] | null) {} | ||
indexOf(value: ZedValueInterface) { | ||
indexOf(value: Value) { | ||
if (isNull(this.items)) return -1; | ||
@@ -13,0 +10,0 @@ return this.items.indexOf(value); |
import { Record } from "./record"; | ||
import { ZedValue, ZedValueInterface } from "./types"; | ||
import { ZedValue, Value } from "./types"; | ||
@@ -7,3 +7,3 @@ export class Field { | ||
public name: string, | ||
public value: ZedValueInterface, | ||
public value: Value, | ||
public parent: Record | Field | null | ||
@@ -10,0 +10,0 @@ ) {} |
import { TypeIp } from "../types/type-ip"; | ||
import { TypeMap } from "../types/type-map"; | ||
import { isNull } from "../utils"; | ||
import { ZedValue, ZedValueInterface } from "./types"; | ||
import { ZedValue, Value } from "./types"; | ||
export class ZedMap implements ZedValueInterface { | ||
constructor( | ||
public type: TypeMap, | ||
public value: Map<ZedValueInterface, ZedValueInterface> | null | ||
) {} | ||
export class ZedMap implements Value { | ||
constructor(public type: TypeMap, public value: Map<Value, Value> | null) {} | ||
@@ -42,4 +39,4 @@ toString() { | ||
function isIPv6(v: ZedValueInterface): boolean { | ||
function isIPv6(v: Value): boolean { | ||
return v.type === TypeIp && v.toString().includes(":"); | ||
} |
@@ -1,7 +0,7 @@ | ||
import { ZedTypeInterface } from "../types/types"; | ||
import { Type } from "../types/types"; | ||
import { isNull } from "../utils"; | ||
import { ZedValueInterface } from "./types"; | ||
import { Value } from "./types"; | ||
export abstract class Primitive implements ZedValueInterface { | ||
abstract type: ZedTypeInterface; | ||
export abstract class Primitive implements Value { | ||
abstract type: Type; | ||
abstract toJS(): any; | ||
@@ -8,0 +8,0 @@ |
@@ -8,7 +8,7 @@ import { isEmpty, isNull, isString } from "lodash"; | ||
import { Field } from "./field"; | ||
import { ZedValue, ZedValueInterface } from "./types"; | ||
import { ZedValue, Value } from "./types"; | ||
type ColumnName = string | string[]; | ||
export class Record implements ZedValueInterface { | ||
export class Record implements Value { | ||
constructor( | ||
@@ -15,0 +15,0 @@ public type: TypeRecord | TypeAlias, |
import { isNull } from "../utils"; | ||
import { TypeSet } from "../types/type-set"; | ||
import { ZedValue, ZedValueInterface } from "./types"; | ||
import { ZedValue, Value } from "./types"; | ||
export class Set implements ZedValueInterface { | ||
constructor(public type: TypeSet, public items: ZedValueInterface[] | null) {} | ||
export class Set implements Value { | ||
constructor(public type: TypeSet, public items: Value[] | null) {} | ||
indexOf(value: ZedValueInterface) { | ||
indexOf(value: Value) { | ||
if (isNull(this.items)) return -1; | ||
@@ -10,0 +10,0 @@ return this.items.indexOf(value); |
import { TypeType } from "../types/type-type"; | ||
import { ZedTypeInterface } from "../types/types"; | ||
import { Type } from "../types/types"; | ||
import { isNull, typeId } from "../utils"; | ||
import { ZedValueInterface } from "./types"; | ||
import { Value } from "./types"; | ||
export class TypeValue implements ZedValueInterface { | ||
export class TypeValue implements Value { | ||
type: typeof TypeType = TypeType; | ||
constructor(public value: ZedTypeInterface | null = null) {} | ||
constructor(public value: Type | null = null) {} | ||
@@ -11,0 +11,0 @@ isUnset() { |
@@ -1,3 +0,3 @@ | ||
import { Value } from "../../zjson"; | ||
import { ZedTypeInterface } from "../types/types"; | ||
import * as zjson from "../../zjson"; | ||
import { Type } from "../types/types"; | ||
import { Array } from "./array"; | ||
@@ -66,8 +66,8 @@ import { Bool } from "./bool"; | ||
export interface ZedValueInterface { | ||
export interface Value { | ||
toJS(): any; | ||
toString(): string; | ||
serialize(): Value; | ||
serialize(): zjson.Value; | ||
isUnset(): boolean; | ||
type: ZedTypeInterface; | ||
type: Type; | ||
} |
import { TypeUnion } from "../types/type-union"; | ||
import { ZedTypeInterface } from "../types/types"; | ||
import { Type } from "../types/types"; | ||
import { isNull } from "../utils"; | ||
import { ZedValueInterface } from "./types"; | ||
import { Value } from "./types"; | ||
export class Union implements ZedValueInterface { | ||
export class Union implements Value { | ||
constructor( | ||
public type: TypeUnion, | ||
public innerType: ZedTypeInterface, | ||
public innerType: Type, | ||
public index: number | null, | ||
public value: ZedValueInterface | null | ||
public value: Value | null | ||
) {} | ||
@@ -13,0 +13,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1366562
40586
3