aboutsummaryrefslogtreecommitdiff
path: root/src/fields/Schema.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/fields/Schema.ts')
-rw-r--r--src/fields/Schema.ts27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/fields/Schema.ts b/src/fields/Schema.ts
index f5e64ae1f..89e5cda8d 100644
--- a/src/fields/Schema.ts
+++ b/src/fields/Schema.ts
@@ -1,5 +1,9 @@
+/* eslint-disable guard-for-in */
+/* eslint-disable no-restricted-syntax */
+/* eslint-disable no-redeclare */
+/* eslint-disable no-use-before-define */
import { Interface, ToInterface, Cast, ToConstructor, HasTail, Head, Tail, ListSpec, ToType, DefaultFieldConstructor } from './Types';
-import { Doc, Field } from './Doc';
+import { Doc, FieldType } from './Doc';
import { ObjectField } from './ObjectField';
import { RefField } from './RefField';
import { SelfProxy } from './DocSymbols';
@@ -12,6 +16,7 @@ type AllToInterface<T extends Interface[]> = {
export const emptySchema = createSchema({});
export const Document = makeInterface(emptySchema);
+// eslint-disable-next-line no-redeclare
export type Document = makeInterface<[typeof emptySchema]>;
export interface InterfaceFunc<T extends Interface[]> {
@@ -36,9 +41,10 @@ export function makeInterface<T extends Interface[]>(...schemas: T): InterfaceFu
if (prop in schema) {
const desc = prop === 'proto' ? Doc : (schema as any)[prop]; // bcz: proto doesn't appear in schemas ... maybe it should?
if (typeof desc === 'object' && 'defaultVal' in desc && 'type' in desc) {
- //defaultSpec
+ // defaultSpec
return Cast(field, desc.type, desc.defaultVal);
}
+ // eslint-disable-next-line no-prototype-builtins
if (typeof desc === 'function' && !ObjectField.isPrototypeOf(desc) && !RefField.isPrototypeOf(desc)) {
const doc = Cast(field, Doc);
if (doc === undefined) {
@@ -47,7 +53,7 @@ export function makeInterface<T extends Interface[]>(...schemas: T): InterfaceFu
if (doc instanceof Doc) {
return desc(doc);
}
- return doc.then(doc => doc && desc(doc));
+ return doc.then(d => d && desc(d));
}
return Cast(field, desc);
}
@@ -73,8 +79,8 @@ export function makeStrictInterface<T extends Interface>(schema: T): (doc: Doc)
get() {
return Cast(this.__doc[key], type as any);
},
- set(value) {
- value = Cast(value, type as any);
+ set(setValue) {
+ const value = Cast(setValue, type as any);
if (value !== undefined) {
this.__doc[key] = value;
return;
@@ -93,17 +99,18 @@ export function makeStrictInterface<T extends Interface>(schema: T): (doc: Doc)
};
}
+// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function createSchema<T extends Interface>(schema: T): T & { proto: ToConstructor<Doc> } {
return undefined as any;
- (schema as any).proto = Doc;
- return schema as any;
+ // (schema as any).proto = Doc;
+ // return schema as any;
}
-export function listSpec<U extends ToConstructor<Field>>(type: U): ListSpec<ToType<U>> {
- return { List: type as any }; //TODO Types
+export function listSpec<U extends ToConstructor<FieldType>>(type: U): ListSpec<ToType<U>> {
+ return { List: type as any }; // TODO Types
}
-export function defaultSpec<T extends ToConstructor<Field>>(type: T, defaultVal: ToType<T>): DefaultFieldConstructor<ToType<T>> {
+export function defaultSpec<T extends ToConstructor<FieldType>>(type: T, defaultVal: ToType<T>): DefaultFieldConstructor<ToType<T>> {
return {
type: type as any,
defaultVal,