From e3ad2c2c8f920a5538541b8e495af52815e36dc6 Mon Sep 17 00:00:00 2001 From: Tyler Schicke Date: Fri, 19 Apr 2019 23:52:34 -0400 Subject: Started fixing stuff --- src/new_fields/Doc.ts | 8 ++++++++ src/new_fields/Schema.ts | 7 ++++--- src/new_fields/Types.ts | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) (limited to 'src/new_fields') diff --git a/src/new_fields/Doc.ts b/src/new_fields/Doc.ts index c67170573..23a8c05cc 100644 --- a/src/new_fields/Doc.ts +++ b/src/new_fields/Doc.ts @@ -84,6 +84,14 @@ export namespace Doc { export function GetT(doc: Doc, key: string, ctor: FieldCtor, ignoreProto: boolean = false): Field | null | undefined { return Cast(Get(doc, key, ignoreProto), ctor); } + export function MakeDelegate(doc: Opt): Opt { + if (!doc) { + return undefined; + } + const delegate = new Doc(); + delegate.prototype = doc; + return delegate; + } export const Prototype = Symbol("Prototype"); } diff --git a/src/new_fields/Schema.ts b/src/new_fields/Schema.ts index c7d2f0801..27b9635af 100644 --- a/src/new_fields/Schema.ts +++ b/src/new_fields/Schema.ts @@ -1,4 +1,4 @@ -import { Interface, ToInterface, Cast } from "./Types"; +import { Interface, ToInterface, Cast, FieldCtor, ToConstructor } from "./Types"; import { Doc } from "./Doc"; export type makeInterface = Partial> & Doc; @@ -42,6 +42,7 @@ export function makeStrictInterface(schema: T): (doc: Doc) }; } -export function createSchema(schema: T): T { - return schema; +export function createSchema(schema: T): T & { prototype: ToConstructor } { + schema.prototype = Doc; + return schema as any; } diff --git a/src/new_fields/Types.ts b/src/new_fields/Types.ts index 416298a64..cafb208ce 100644 --- a/src/new_fields/Types.ts +++ b/src/new_fields/Types.ts @@ -53,6 +53,6 @@ export function Cast>(field: Field | null | undefined return undefined; } -export function FieldValue(field: Opt | Promise>): Opt { +export function FieldValue(field: Opt | Promise>): Opt { return field instanceof Promise ? undefined : field; } -- cgit v1.2.3-70-g09d2