Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Engine updates #57

Merged
merged 8 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
863 changes: 727 additions & 136 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@comake/skl-js-engine",
"version": "0.26.0",
"version": "0.32.0",
"description": "Standard Knowledge Language Javascript Engine",
"keywords": [
"skl",
Expand Down Expand Up @@ -29,7 +29,8 @@
"test:integration": "jest --coverageReporters text-summary -- test/integration",
"test:unit": "jest --config=./jest.coverage.config.js test/unit",
"test:package": "chmod +x test/deploy/validate-package.sh && test/deploy/validate-package.sh",
"prepare": "husky && npm run build"
"prepare": "husky && npm run build",
"postinstall": "patch-package"
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand All @@ -52,6 +53,7 @@
"memory-level": "^1.0.0",
"mime-types": "^2.1.35",
"n3": "^1.17.2",
"patch-package": "^8.0.0",
"quadstore": "13.1.1",
"quadstore-comunica": "^4.3.0",
"rdf-data-factory": "^1.1.2",
Expand Down
13 changes: 13 additions & 0 deletions patches/sparqljs+3.7.1.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/node_modules/sparqljs/lib/SparqlGenerator.js b/node_modules/sparqljs/lib/SparqlGenerator.js
index 527f0e9..43121b9 100644
--- a/node_modules/sparqljs/lib/SparqlGenerator.js
+++ b/node_modules/sparqljs/lib/SparqlGenerator.js
@@ -220,7 +220,7 @@ Generator.prototype.toExpression = function (expr) {
'(' + (expr.distinct ? 'DISTINCT ' : '') + this.toExpression(expr.expression) +
(typeof expr.separator === 'string' ? '; SEPARATOR = ' + '"' + expr.separator.replace(escape, escapeReplacer) + '"' : '') + ')';
case 'functioncall':
- return this.toEntity(expr.function) + '(' + mapJoin(expr.args, ', ', this.toExpression, this) + ')';
+ return expr.function + '(' + mapJoin(expr.args, ', ', this.toExpression, this) + ')';
case 'operation':
var operator = expr.operator.toUpperCase(), args = expr.args || [];
switch (expr.operator.toLowerCase()) {
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export * from './storage/operator/LessThan';
export * from './storage/operator/LessThanOrEqual';
export * from './storage/operator/Not';
export * from './storage/operator/OneOrMorePath';
export * from './storage/operator/Sequence';
export * from './storage/operator/SequencePath';
export * from './storage/operator/ZeroOrMorePath';

Expand Down
12 changes: 10 additions & 2 deletions src/storage/FindOperator.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Variable } from "rdf-data-factory";

export type FindOperatorType =
| 'in'
| 'not'
Expand All @@ -14,21 +16,27 @@ export type FindOperatorType =
| 'zeroOrMorePath'
| 'inversePath'
| 'oneOrMorePath'
| 'contains';
| 'contains'
| 'sequence';

export interface FindOperatorArgs<T, TType> {
operator: TType;
value?: T | FindOperator<T, any>;
subject?: Variable;
isOptional?: boolean;
}

export class FindOperator<T, TType extends FindOperatorType> {
public readonly type = 'operator';
public readonly operator: TType;
public readonly subject?: Variable;
public readonly value?: T | FindOperator<T, any>;

public readonly isOptional?: boolean;
public constructor(args: FindOperatorArgs<T, TType>) {
this.operator = args.operator;
this.value = args.value;
this.subject = args.subject;
this.isOptional = args.isOptional;
}

public static isFindOperator(value: any): boolean {
Expand Down
13 changes: 10 additions & 3 deletions src/storage/FindOptionsTypes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/naming-convention */
import type { Variable } from 'sparqljs';
import type { Expression, Variable } from 'sparqljs';
import type { OrArray, JSONArray, JSONObject } from '../util/Types';
import type { FindOperator } from './FindOperator';
import type { InverseRelationOperatorValue } from './operator/InverseRelation';
Expand Down Expand Up @@ -59,7 +59,8 @@ export type FindOptionsWhereField =
| OrArray<FieldPrimitiveValue>
| ValueWhereFieldObject
| FindOptionsWhere
| OrArray<FindOperator<any, any>>;
| OrArray<FindOperator<any, any>>
| BindPattern[];

export type IdFindOptionsWhereField =
| string
Expand All @@ -69,10 +70,16 @@ export type TypeFindOptionsWhereField =
| string
| FindOperator<string | string[] | FindOptionsWhere, 'in' | 'not' | 'equal' | 'inverse' | 'contains'>;

export interface BindPattern {
expression: Expression;
variable: Variable;
}

export interface FindOptionsWhere {
type?: TypeFindOptionsWhereField;
id?: IdFindOptionsWhereField;
[k: string]: FindOptionsWhereField | undefined;
binds?: BindPattern[];
[k: string]: FindOptionsWhereField | BindPattern[] | undefined;
}

// Add these new types
Expand Down
1 change: 1 addition & 0 deletions src/storage/operator/InverseRelation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { FindOptionsRelations } from '../FindOptionsTypes';
export interface InverseRelationOperatorValue {
resolvedName: string;
relations?: FindOptionsRelations;
[key: string]: any;
}

// eslint-disable-next-line @typescript-eslint/naming-convention
Expand Down
11 changes: 11 additions & 0 deletions src/storage/operator/Sequence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { FindOperator } from '../FindOperator';

// eslint-disable-next-line @typescript-eslint/naming-convention
export function Sequence<T>(
value: T | FindOperator<T, any>,
): FindOperator<T, 'sequence'> {
return new FindOperator({
operator: 'sequence',
value,
});
}
11 changes: 9 additions & 2 deletions src/storage/query-adapter/sparql/SparqlQueryAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,12 @@ export class SparqlQueryAdapter implements QueryAdapter {
if (entityOrder && entityOrder.length === 0) {
return [];
}
const queryData = queryBuilder.buildEntitySelectPatternsFromOptions(entityVariable, options);
const query = queryBuilder.buildConstructFromEntitySelectQuery(
where,
selectionTriples,
options?.select,
queryData.selectVariables,
);
return await this.executeEntitySelectQuery(query, options, entityOrder);
}
Expand All @@ -129,10 +131,15 @@ export class SparqlQueryAdapter implements QueryAdapter {
const queryData = queryBuilder.buildEntitySelectPatternsFromOptions(entityVariable, options);
const entitySelectQuery = queryData.where.length > 0
? createSparqlSelectQuery(
options?.entitySelectVariable ?? entityVariable,
[
options?.entitySelectVariable ?? entityVariable,
...(queryData.selectVariables?.map(({ variable, expression }) => ({
variable,
expression,
})) ?? []),
],
queryData.where,
queryData.orders,
// FIXME: This will not work if queryData.group is defined, figure out what can make it defined.
queryData.group ?? options?.group,
options?.limit,
options?.offset,
Expand Down
Loading
Loading