Skip to content

Commit

Permalink
Renamed SchemaInterfaceIdentity to Identity
Browse files Browse the repository at this point in the history
  • Loading branch information
karelklima committed Jan 4, 2024
1 parent f1985f7 commit c262105
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 26 deletions.
16 changes: 8 additions & 8 deletions library/lens/lens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
import {
type ExpandedSchema,
expandSchema,
type Identity,
type Schema,
type SchemaInterface,
type SchemaInterfaceIdentity,
type SchemaSearchInterface,
type SchemaUpdateInterface,
} from "../schema/mod.ts";
Expand All @@ -34,17 +34,17 @@ export const createLens = <T extends Schema>(
) => new Lens(schema, options);

export class Lens<
S extends Schema,
I = SchemaInterface<S>,
U = SchemaUpdateInterface<S>,
X = SchemaSearchInterface<S>,
T extends Schema,
I = SchemaInterface<T>,
U = SchemaUpdateInterface<T>,
S = SchemaSearchInterface<T>,
> {
private readonly schema: ExpandedSchema;
private readonly options: Options;
private readonly engine: QueryEngineProxy;
private readonly queryBuilder: QueryBuilder;

constructor(schema: S, options?: Options) {
constructor(schema: T, options?: Options) {
this.schema = expandSchema(schema);
this.options = resolveOptions(options);
const context = resolveQueryContext(this.options);
Expand Down Expand Up @@ -74,7 +74,7 @@ export class Lens<
}

async find(
options: { where?: X | string | RDF.Quad[]; take?: number; skip?: number } =
options: { where?: S | string | RDF.Quad[]; take?: number; skip?: number } =
{},
) {
const { where, take, skip } = {
Expand Down Expand Up @@ -125,7 +125,7 @@ export class Lens<
return this.updateQuery(q);
}

delete(...identities: SchemaInterfaceIdentity[] | Iri[]) {
delete(...identities: Identity[] | Iri[]) {
const iris = identities.map((identity) => {
return typeof identity === "string" ? identity : identity.$id;
});
Expand Down
4 changes: 2 additions & 2 deletions library/lens/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { SchemaInterfaceIdentity } from "../schema/mod.ts";
import type { Identity } from "../schema/mod.ts";

export type Entity<T extends unknown = Record<string, unknown>> =
& DeepPartial<T>
& SchemaInterfaceIdentity;
& Identity;

export type DeepPartial<T> = T extends Record<string, unknown>
? { [P in keyof T]?: DeepPartial<T[P]> }
Expand Down
10 changes: 3 additions & 7 deletions library/schema/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,12 @@ type ConvertProperty<T extends ValidPropertyDefinition> = T extends Property
? ConvertPropertyObject<T>
: string;

export type SchemaInterfaceIdentity = {
export type Identity = {
$id: string;
};

export type SchemaInterfaceType = {
$type: string[];
};

export type SchemaInterface<T extends Schema> =
& SchemaInterfaceIdentity
& Identity
& {
[X in Exclude<keyof T, "@type">]: T[X] extends ValidPropertyDefinition
? ConvertProperty<T[X]>
Expand Down Expand Up @@ -105,7 +101,7 @@ type ConvertUpdateProperty<T extends ValidPropertyDefinition> = T extends
Property ? ConvertUpdatePropertyObject<T> : string;

export type SchemaUpdateInterface<T extends Schema> =
& SchemaInterfaceIdentity
& Identity
& {
[X in Exclude<keyof T, "@type">]?: T[X] extends ValidPropertyDefinition
? ConvertUpdateProperty<T[X]>
Expand Down
3 changes: 1 addition & 2 deletions library/schema/mod.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
export type { SupportedDataTypes, SupportedNativeTypes } from "./data_types.ts";

export type {
Identity,
SchemaInterface,
SchemaInterfaceIdentity,
SchemaInterfaceType,
SchemaSearchInterface,
SchemaUpdateInterface,
} from "./interface.ts";
Expand Down
10 changes: 3 additions & 7 deletions library/schema/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@ export type Property = {
"@inverse"?: true;
};

export type SchemaPrototypeProperties = {
[key: string]: Property | string | readonly string[];
};

export type SchemaPrototypeType = {
export type Schema = {
"@type"?: string | readonly string[];
} & {
[key: string]: Property | string | readonly string[];
};

export type Schema = SchemaPrototypeProperties & SchemaPrototypeType;

export type ExpandedProperty = {
"@id": string;
"@type"?: PropertyType;
Expand Down

0 comments on commit c262105

Please sign in to comment.