Skip to content

Commit

Permalink
fix: remove search and update types
Browse files Browse the repository at this point in the history
  • Loading branch information
adlerfaulkner committed Oct 20, 2023
1 parent 5240c8d commit b83ebd5
Show file tree
Hide file tree
Showing 17 changed files with 234 additions and 121 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@comake/skl-js-engine",
"version": "0.15.3",
"version": "0.15.4",
"description": "Standard Knowledge Language Javascript Engine",
"keywords": [
"skl",
Expand Down
4 changes: 2 additions & 2 deletions src/SklEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ import type {
MappingWithParameterReference,
RdfList,
VerbConfig,
JSONObject,
} from './util/Types';
import {
convertJsonLdToQuads,
toJSON,
getValueIfDefined,
ensureArray,
} from './util/Util';
import type { JSONObject } from './util/Util';
import { SKL, SHACL, RDFS, SKL_ENGINE, XSD, RDF } from './util/Vocabularies';

export type VerbHandler = <T extends OrArray<NodeObject> = OrArray<NodeObject>>(
Expand Down Expand Up @@ -290,7 +290,7 @@ export class SKLEngine {
verbConfig?: VerbConfig,
): Promise<OrArray<NodeObject>> {
const nextVerbMapping = list[0];
const returnValue = await this.executeVerbFromVerbMapping(nextVerbMapping, args as JSONObject, verbConfig);
const returnValue = await this.executeVerbFromVerbMapping(nextVerbMapping, args, verbConfig);
if (list.length > 1) {
return await this.executeSeriesFromList(
list.slice(1),
Expand Down
3 changes: 1 addition & 2 deletions src/mapping/Mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import * as RmlParser from '@comake/rmlmapper-js';
import type { NodeObject } from 'jsonld';
import jsonld from 'jsonld';
import type { OrArray } from '../util/Types';
import type { JSONObject } from '../util/Util';
import type { OrArray, JSONObject } from '../util/Types';

export interface MapperArgs {
functions?: Record<string, (args: any | any[]) => any>;
Expand Down
29 changes: 12 additions & 17 deletions src/storage/FindOptionsTypes.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
/* eslint-disable @typescript-eslint/naming-convention */
import type { OrArray } from '../util/Types';
import type { JSONArray, JSONObject } from '../util/Util';
import type { OrArray, JSONArray, JSONObject } from '../util/Types';
import type { FindOperator } from './FindOperator';
import type { InverseRelationOperatorValue } from './operator/InverseRelation';
import type { InverseRelationOrderValue } from './operator/InverseRelationOrder';

export type FindOptionsSelectByString = string[];

export type FindOptionsRelationsByString = string[];

export type FindOptionsSelect = FindOptionsSelectByString | {[key: string]: boolean | FindOptionsSelect };
export type FindOptionsSelect = string[] | {[key: string]: boolean | FindOptionsSelect };

export interface FindOneOptions {
search?: string;
select?: FindOptionsSelect;
where?: FindOptionsWhere;
relations?: FindOptionsRelations;
order?: FindOptionsOrder;
searchRelations?: boolean;
skipFraming?: boolean;
}

export type FindOptionsRelationsValue = |
boolean |
FindOptionsRelations |
FindOperator<InverseRelationOperatorValue, 'inverseRelation'>;

// eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style
export type FindOptionsRelations = {
[k: string]: boolean | FindOptionsRelations | FindOperator<InverseRelationOperatorValue, 'inverseRelation'>;
[k: string]: FindOptionsRelationsValue;
};

export type FindOptionsOrderValue = 'ASC' | 'DESC' | 'asc' | 'desc' | 1 | -1;
Expand All @@ -48,15 +47,15 @@ export type NonJsonValueObject = {
'@type': string;
};

export type ValueObject =
export type ValueWhereFieldObject =
| JsonValueObject
| LanguageValueObject
| NonJsonValueObject;

export type FindOptionsWhereField =
| OrArray<FieldPrimitiveValue>
| ValueObject
| Exclude<FindOptionsWhere, 'search'>
| ValueWhereFieldObject
| FindOptionsWhere
| OrArray<FindOperator<any, any>>;

export type IdFindOptionsWhereField =
Expand All @@ -79,17 +78,13 @@ export interface FindAllOptions extends FindOneOptions {
}

export interface FindExistsOptions {
search?: string;
where?: FindOptionsWhere;
relations?: FindOptionsRelations;
searchRelations?: boolean;
}

export interface FindCountOptions {
search?: string;
where?: FindOptionsWhere;
relations?: FindOptionsRelations;
order?: FindOptionsOrder;
offset?: number;
searchRelations?: boolean;
}
8 changes: 4 additions & 4 deletions src/storage/QueryAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ export interface QueryAdapter {
*/
executeRawEntityQuery(query: string, frame?: Frame): Promise<GraphObject>;
/**
* Finds first entity by a given find options.
* If entity was not found in the database - returns null.
* Finds the first entity by a given find options.
* If entity was not found in the database it returns null.
*/
find(options?: FindOneOptions): Promise<Entity | null>;
/**
* Finds first entity that matches given where condition.
* If entity was not found in the database - returns null.
* Finds the first entity that matches given where condition.
* If entity was not found in the database it returns null.
*/
findBy(where: FindOptionsWhere): Promise<Entity | null>;
/**
Expand Down
10 changes: 3 additions & 7 deletions src/storage/memory/MemoryQueryAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import type { ReferenceNodeObject } from '@comake/rmlmapper-js';
import type { GraphObject } from 'jsonld';
import type { Frame } from 'jsonld/jsonld-spec';
import { toJSValueFromDataType } from '../../util/TripleUtil';
import type { Entity, EntityFieldValue, PossibleArrayFieldValues } from '../../util/Types';
import type { JSONObject, JSONArray } from '../../util/Util';
import type { Entity, EntityFieldValue, PossibleArrayFieldValues, JSONObject, JSONArray } from '../../util/Types';
import { ensureArray } from '../../util/Util';
import { RDFS } from '../../util/Vocabularies';
import type { FindOperatorType } from '../FindOperator';
Expand All @@ -16,7 +15,7 @@ import type {
FindOptionsWhere,
FindOptionsWhereField,
FieldPrimitiveValue,
ValueObject,
ValueWhereFieldObject,
FindCountOptions,
FindExistsOptions,
} from '../FindOptionsTypes';
Expand Down Expand Up @@ -71,9 +70,6 @@ export class MemoryQueryAdapter implements QueryAdapter {
}

public async findAll(options?: FindAllOptions): Promise<Entity[]> {
if (options?.search) {
return [];
}
let results: Entity[] = [];
if (options?.where?.id && Object.keys(options.where).length === 1 && typeof options.where.id === 'string') {
const schema = this.schemas[options.where.id];
Expand Down Expand Up @@ -214,7 +210,7 @@ export class MemoryQueryAdapter implements QueryAdapter {
if ((field as ReferenceNodeObject)['@id']) {
return (field as ReferenceNodeObject)['@id'] === value;
}
if ((field as ValueObject)['@value']) {
if ((field as ValueWhereFieldObject)['@value']) {
const jsValue = toJSValueFromDataType(
(field as any)['@value'],
(field as any)['@type'],
Expand Down
3 changes: 0 additions & 3 deletions src/storage/sparql/SparqlQueryAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ export class SparqlQueryAdapter implements QueryAdapter {
}

private async findAllAsJsonLd(options?: FindAllOptions): Promise<OrArray<NodeObject>> {
if (options?.search) {
return [];
}
const queryBuilder = new SparqlQueryBuilder();
const { where, selectionTriples, entityOrder } = await this.buildFindAllQueryData(queryBuilder, options);
if (entityOrder && entityOrder.length === 0) {
Expand Down
12 changes: 6 additions & 6 deletions src/storage/sparql/SparqlQueryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import type {
FindOptionsWhereField,
IdFindOptionsWhereField,
TypeFindOptionsWhereField,
ValueObject,
ValueWhereFieldObject,
} from '../FindOptionsTypes';
import type { InverseRelationOperatorValue } from '../operator/InverseRelation';
import type { InverseRelationOrderValue } from '../operator/InverseRelationOrder';
Expand Down Expand Up @@ -341,7 +341,7 @@ export class SparqlQueryBuilder {
}
if (typeof value === 'object') {
if ('@value' in value) {
return this.createWhereQueryDataForValueObject(subject, predicate, value as ValueObject);
return this.createWhereQueryDataForValueObject(subject, predicate, value as ValueWhereFieldObject);
}
return this.createWhereQueryDataForNestedWhere(subject, predicate, value as FindOptionsWhere);
}
Expand Down Expand Up @@ -499,7 +499,7 @@ export class SparqlQueryBuilder {
private createWhereQueryDataForValueObject(
subject: Variable,
predicate: IriTerm | PropertyPath,
valueObject: ValueObject,
valueObject: ValueWhereFieldObject,
): WhereQueryData {
const term = this.valueObjectToTerm(valueObject);
return {
Expand All @@ -512,7 +512,7 @@ export class SparqlQueryBuilder {
};
}

private valueObjectToTerm(valueObject: ValueObject): Literal {
private valueObjectToTerm(valueObject: ValueWhereFieldObject): Literal {
let typeOrLanguage: string;
let value: string;
if ('@type' in valueObject && valueObject['@type'] === '@json') {
Expand Down Expand Up @@ -673,10 +673,10 @@ export class SparqlQueryBuilder {
return createSparqlNotEqualOperation(leftSide, rightSide as Expression);
}

private resolveValueToTerm(value: FieldPrimitiveValue | ValueObject): NamedNode | Literal {
private resolveValueToTerm(value: FieldPrimitiveValue | ValueWhereFieldObject): NamedNode | Literal {
if (typeof value === 'object' && '@value' in value) {
return valueToLiteral(
(value as ValueObject)['@value'],
(value as ValueWhereFieldObject)['@value'],
'@type' in value ? value['@type'] : undefined,
);
}
Expand Down
3 changes: 1 addition & 2 deletions src/util/SparqlUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import type {
import type { RawQueryResult } from '../storage/QueryAdapter';
import type { SelectVariableQueryResult } from '../storage/sparql/SparqlQueryExecutor';
import { toJSValueFromDataType } from './TripleUtil';
import { BDS, DCTERMS, RDF, RDFS } from './Vocabularies';
import { DCTERMS, RDF, RDFS } from './Vocabularies';

export const rdfTypeNamedNode = DataFactory.namedNode(RDF.type);
export const rdfsSubClassOfNamedNode = DataFactory.namedNode(RDFS.subClassOf);
Expand All @@ -44,7 +44,6 @@ export const countVariable = DataFactory.variable('count');
export const now = DataFactory.variable('now');
export const created = DataFactory.namedNode(DCTERMS.created);
export const modified = DataFactory.namedNode(DCTERMS.modified);
export const searchPredicate = DataFactory.namedNode(BDS.search);
export const firstPredicate = DataFactory.namedNode(RDF.first);
export const restPredicate = DataFactory.namedNode(RDF.rest);
export const nilPredicate = DataFactory.namedNode(RDF.nil);
Expand Down
3 changes: 1 addition & 2 deletions src/util/TripleUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import type { Frame } from 'jsonld/jsonld-spec';
import { FindOperator } from '../storage/FindOperator';
import type { FindOptionsRelations, FindOptionsWhere } from '../storage/FindOptionsTypes';
import type { InverseRelationOperatorValue } from '../storage/operator/InverseRelation';
import type { OrArray } from './Types';
import type { JSONArray, JSONObject } from './Util';
import type { OrArray, JSONArray, JSONObject } from './Types';
import { ensureArray } from './Util';
import { RDF, XSD } from './Vocabularies';

Expand Down
Loading

0 comments on commit b83ebd5

Please sign in to comment.