Skip to content

Commit

Permalink
Fix TS compilation issues related to ProxyHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Mar 23, 2021
1 parent 5aa21a4 commit 757436e
Show file tree
Hide file tree
Showing 5 changed files with 1,318 additions and 1,225 deletions.
4 changes: 2 additions & 2 deletions lib/RdfObjectLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ export class RdfObjectLoader {
stream.on('end', () => {
if (this.normalizeLists) {
for (const listRoot of listMaterializer.getRoots()) {
const listTerms = <RDF.Term[]> listMaterializer.getList(listRoot);
this.resources[termToString(listRoot)].list = listTerms.map(term => this.resources[termToString(term)]);
const listTerms = listMaterializer.getList(listRoot);
this.resources[termToString(listRoot)].list = listTerms!.map(term => this.resources[termToString(term)]);
}
}
resolve();
Expand Down
7 changes: 4 additions & 3 deletions lib/Resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ export class Resource {
if (type.equals(this.term)) {
return true;
}
return (this.propertiesUri['http://www.w3.org/1999/02/22-rdf-syntax-ns#type'] || [])
.concat(this.propertiesUri['http://www.w3.org/2000/01/rdf-schema#subClassOf'] || [])
.reduce((acc: boolean, superType: Resource) => acc || superType.isA(type), false);
return [
...this.propertiesUri['http://www.w3.org/1999/02/22-rdf-syntax-ns#type'] || [],
...this.propertiesUri['http://www.w3.org/2000/01/rdf-schema#subClassOf'] || [],
].reduce((acc: boolean, superType: Resource) => acc || superType.isA(type), false);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions lib/ShortcutPropertyHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ export class ShortcutPropertyHandler<T> implements ProxyHandler<Record<string, T
this.context = context;
}

public has(target: Record<string, T[]>, propertyKey: PropertyKey): boolean {
public has(target: Record<string, T[]>, propertyKey: string | symbol): boolean {
return this.get(target, propertyKey).length > 0;
}

public get(target: Record<string, T[]>, propertyKey: PropertyKey): T[] {
public get(target: Record<string, T[]>, propertyKey: string | symbol): T[] {
const iri = this.context.expandTerm(this.toTermString(propertyKey), true);
if (!iri) {
throw new Error(`Illegal property getting for disabled context key '${this.toTermString(propertyKey)}'`);
Expand All @@ -26,7 +26,7 @@ export class ShortcutPropertyHandler<T> implements ProxyHandler<Record<string, T
return target[iri];
}

public set(target: Record<string, T[]>, propertyKey: PropertyKey, value: any): boolean {
public set(target: Record<string, T[]>, propertyKey: string | symbol, value: any): boolean {
const iri = this.context.expandTerm(this.toTermString(propertyKey), true);
if (!iri) {
throw new Error(`Illegal property setting for disabled context key '${this.toTermString(propertyKey)}'`);
Expand All @@ -35,13 +35,13 @@ export class ShortcutPropertyHandler<T> implements ProxyHandler<Record<string, T
return true;
}

public ownKeys(target: Record<string, T[]>): PropertyKey[] {
public ownKeys(target: Record<string, T[]>): (string | symbol)[] {
return <string[]> Object.keys(target)
.map((key: string) => this.context.expandTerm(key, true))
.filter(key => key && this.has(target, key));
}

private toTermString(propertyKey: PropertyKey): string {
private toTermString(propertyKey: string | symbol): string {
return typeof propertyKey === 'string' ? propertyKey : String(propertyKey);
}
}
10 changes: 5 additions & 5 deletions lib/SingularPropertyHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@
* This proxy will always take the first element of array values.
*/
export class SingularPropertyHandler<T> implements ProxyHandler<Record<string, T[]>> {
public has(target: Record<string, T[]>, propertyKey: PropertyKey): boolean {
public has(target: Record<string, T[]>, propertyKey: string | symbol): boolean {
return !!this.get(target, propertyKey);
}

public get(target: Record<string, T[]>, propertyKey: PropertyKey): T | undefined {
public get(target: Record<string, T[]>, propertyKey: string | symbol): T | undefined {
const value = target[<string> propertyKey];
return value && value.length > 0 ? value[0] : undefined;
}

public set(target: Record<string, T[]>, propertyKey: PropertyKey, value: any): boolean {
public set(target: Record<string, T[]>, propertyKey: string | symbol, value: any): boolean {
target[<string> propertyKey] = [ value ];
return true;
}

public ownKeys(target: Record<string, T[]>): PropertyKey[] {
public ownKeys(target: Record<string, T[]>): (string | symbol)[] {
return Object.keys(target).filter(key => this.has(target, key));
}

public deleteProperty(target: Record<string, T[]>, propertyKey: PropertyKey): boolean {
public deleteProperty(target: Record<string, T[]>, propertyKey: string | symbol): boolean {
target[<string> propertyKey] = [];
return true;
}
Expand Down
Loading

0 comments on commit 757436e

Please sign in to comment.