aboutsummaryrefslogtreecommitdiff
path: root/src/fields/Schema.ts
diff options
context:
space:
mode:
authorJoanne <zehan_ding@brown.edu>2025-05-12 20:58:01 -0400
committerJoanne <zehan_ding@brown.edu>2025-05-12 20:58:01 -0400
commitcd93c88b8fee83a99342eac4dc60f7b4373fa843 (patch)
treeb00d1f46c802752c90e54bb21be785a05e05195e /src/fields/Schema.ts
parent4997c3de20a381eac30224a7a550afa66174f07d (diff)
parent3a733aa0fd24517e83649824dec0fc8bcc0bde43 (diff)
added tutorial tool, still need to integrate with metadatatool
Diffstat (limited to 'src/fields/Schema.ts')
-rw-r--r--src/fields/Schema.ts21
1 files changed, 9 insertions, 12 deletions
diff --git a/src/fields/Schema.ts b/src/fields/Schema.ts
index 89e5cda8d..cdd278d67 100644
--- a/src/fields/Schema.ts
+++ b/src/fields/Schema.ts
@@ -1,6 +1,3 @@
-/* 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, FieldType } from './Doc';
@@ -16,7 +13,6 @@ 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 +32,10 @@ export function makeInterface<T extends Interface[]>(...schemas: T): InterfaceFu
const proto = new Proxy(
{},
{
- get(target: any, prop, receiver) {
+ get(target: unknown, prop, receiver) {
const field = receiver.doc?.[prop];
if (prop in schema) {
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
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
@@ -59,7 +56,7 @@ export function makeInterface<T extends Interface[]>(...schemas: T): InterfaceFu
}
return field;
},
- set(target: any, prop, value, receiver) {
+ set(target: unknown, prop, value, receiver) {
receiver.doc && (receiver.doc[prop] = value); // receiver.doc may be undefined as the result of a change in acls
return true;
},
@@ -77,10 +74,10 @@ export function makeStrictInterface<T extends Interface>(schema: T): (doc: Doc)
const type = schema[key];
Object.defineProperty(proto, key, {
get() {
- return Cast(this.__doc[key], type as any);
+ return Cast(this.__doc[key], type as never);
},
set(setValue) {
- const value = Cast(setValue, type as any);
+ const value = Cast(setValue, type as never);
if (value !== undefined) {
this.__doc[key] = value;
return;
@@ -89,7 +86,7 @@ export function makeStrictInterface<T extends Interface>(schema: T): (doc: Doc)
},
});
}
- return function (doc: any) {
+ return function (doc: unknown) {
if (!(doc instanceof Doc)) {
throw new Error("Currently wrapping a schema in another schema isn't supported");
}
@@ -101,18 +98,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;
+ return undefined as never;
// (schema as any).proto = Doc;
// return schema as any;
}
export function listSpec<U extends ToConstructor<FieldType>>(type: U): ListSpec<ToType<U>> {
- return { List: type as any }; // TODO Types
+ return { List: type as never }; // TODO Types
}
export function defaultSpec<T extends ToConstructor<FieldType>>(type: T, defaultVal: ToType<T>): DefaultFieldConstructor<ToType<T>> {
return {
- type: type as any,
+ type: type as never,
defaultVal,
};
}