Fix incorrect constructor options in sparqljs (#44106)

* Fix incorrect constructor options in sparqljs

* Include old version of sparqljs typings
This commit is contained in:
Ruben Taelman 2020-04-26 19:08:26 +02:00 committed by GitHub
parent e3a57f1567
commit 402f540b7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 588 additions and 114 deletions

View File

@ -1,14 +1,15 @@
// Type definitions for sparqljs 2.1
// Type definitions for sparqljs 3.0
// Project: https://github.com/RubenVerborgh/SPARQL.js
// Definitions by: Alexey Morozov <https://github.com/AlexeyMz>
// Ruben Taelman <https://github.com/rubensworks>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
export const Parser: {
new (
new (options?: {
prefixes?: { [prefix: string]: string },
baseIRI?: string,
): SparqlParser;
}): SparqlParser;
};
export const Generator: {

View File

@ -24,10 +24,10 @@ function officialExamples() {
}
function advancedOptions() {
const parser = new SparqlJs.Parser(
{rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'},
'http://example.com'
);
const parser = new SparqlJs.Parser({
prefixes: {rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'},
baseIRI: 'http://example.com'
});
const generator = new SparqlJs.Generator({allPrefixes: false});
}

272
types/sparqljs/v2/index.d.ts vendored Normal file
View File

@ -0,0 +1,272 @@
// Type definitions for sparqljs 2.1
// Project: https://github.com/RubenVerborgh/SPARQL.js
// Definitions by: Alexey Morozov <https://github.com/AlexeyMz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
export const Parser: {
new (
prefixes?: { [prefix: string]: string },
baseIRI?: string,
): SparqlParser;
};
export const Generator: {
new (options?: GeneratorOptions): SparqlGenerator;
};
export interface GeneratorOptions {
allPrefixes?: boolean;
}
export interface SparqlParser {
parse(query: string): SparqlQuery;
}
export interface SparqlGenerator {
stringify(query: SparqlQuery): string;
}
export type SparqlQuery = Query | Update;
export type Query = SelectQuery | ConstructQuery | AskQuery | DescribeQuery;
export interface BaseQuery {
type: 'query';
base?: string;
prefixes: { [prefix: string]: string; };
where?: Pattern[];
values?: ValuePatternRow[];
}
export interface SelectQuery extends BaseQuery {
queryType: 'SELECT';
variables: Variable[] | ['*'];
distinct?: boolean;
from?: {
default: string[];
named: string[];
};
reduced?: boolean;
group?: Grouping[];
having?: Expression[];
order?: Ordering[];
limit?: number;
offset?: number;
}
export interface Grouping {
expression: Expression;
}
export interface Ordering {
expression: Expression;
descending?: boolean;
}
export interface ConstructQuery extends BaseQuery {
queryType: 'CONSTRUCT';
template?: Triple[];
}
export interface AskQuery extends BaseQuery {
queryType: 'ASK';
}
export interface DescribeQuery extends BaseQuery {
queryType: 'DESCRIBE';
variables: Variable[] | ['*'];
}
export interface Update {
type: 'update';
prefixes: { [prefix: string]: string; };
updates: UpdateOperation[];
}
export type UpdateOperation = InsertDeleteOperation | ManagementOperation;
export interface InsertDeleteOperation {
updateType: 'insert' | 'delete' | 'deletewhere' | 'insertdelete';
graph?: string;
insert?: Quads[];
delete?: Quads[];
where?: Pattern[];
}
export type Quads = BgpPattern | GraphQuads;
export type ManagementOperation =
| CopyMoveAddOperation
| LoadOperation
| CreateOperation
| ClearDropOperation;
export interface CopyMoveAddOperation {
type: 'copy' | 'move' | 'add';
silent: boolean;
source: GraphOrDefault;
destination: GraphOrDefault;
}
export interface LoadOperation {
type: 'load';
silent: boolean;
source: string;
destination: string | false;
}
export interface CreateOperation {
type: 'create';
silent: boolean;
graph: string;
}
export interface ClearDropOperation {
type: 'clear' | 'drop';
silent: boolean;
graph: GraphReference;
}
export interface GraphOrDefault {
type: 'graph';
name?: string;
default?: boolean;
}
export interface GraphReference extends GraphOrDefault {
named?: boolean;
all?: boolean;
}
/**
* Examples: '?var', '*',
* SELECT (?a as ?b) ... ==> { expression: '?a', variable: '?b' }
*/
export type Variable = VariableExpression | Term;
export interface VariableExpression {
expression: Expression;
variable: Term;
}
export type Pattern =
| BgpPattern
| BlockPattern
| GraphPattern
| ServicePattern
| FilterPattern
| BindPattern
| ValuesPattern
| SelectQuery;
/**
* Basic Graph Pattern
*/
export interface BgpPattern {
type: 'bgp';
triples: Triple[];
}
export interface GraphQuads {
type: 'graph';
name: Term;
triples: Triple[];
}
export interface BlockPattern {
type: 'optional' | 'union' | 'group' | 'minus' | 'graph' | 'service';
patterns: Pattern[];
}
export interface GroupPattern extends BlockPattern {
type: 'group';
}
export interface GraphPattern extends BlockPattern {
type: 'graph';
name: Term;
}
export interface ServicePattern extends BlockPattern {
type: 'service';
name: Term;
silent: boolean;
}
export interface FilterPattern {
type: 'filter';
expression: Expression;
}
export interface BindPattern {
type: 'bind';
expression: Expression;
variable: Term;
}
export interface ValuesPattern {
type: 'values';
values: ValuePatternRow[];
}
export interface ValuePatternRow {
[variable: string]: Term;
}
/**
* Either '?var', 'schema:iri', '_:blankNode',
* '"literal"^^<schema:datatype>' or '{undefined}'.
*
* Term is a nominal type based on string.
*/
export type Term = string & { __termBrand: string; };
export interface Triple {
subject: Term;
predicate: PropertyPath | Term;
object: Term;
}
export interface PropertyPath {
type: 'path';
pathType: '|' | '/' | '^' | '+' | '*' | '!';
items: Array<PropertyPath | Term>;
}
export type Expression =
| OperationExpression
| FunctionCallExpression
| AggregateExpression
| BgpPattern
| GroupPattern
| Tuple
| Term;
// allow Expression circularly reference itself
// tslint:disable-next-line no-empty-interface
export interface Tuple extends Array<Expression> {}
export interface BaseExpression {
type: string;
distinct?: boolean;
}
export interface OperationExpression extends BaseExpression {
type: 'operation';
operator: string;
args: Expression[];
}
export interface FunctionCallExpression extends BaseExpression {
type: 'functionCall';
function: string;
args: Expression[];
}
export interface AggregateExpression extends BaseExpression {
type: 'aggregate';
expression: Expression;
aggregation: string;
separator?: string;
}

View File

@ -0,0 +1,169 @@
import * as SparqlJs from 'sparqljs';
/**
* Examples from the project's README
*/
function officialExamples() {
// Parse a SPARQL query to a JSON object
const SparqlParser = SparqlJs.Parser;
const parser = new SparqlParser();
const parsedQuery = parser.parse(
'PREFIX foaf: <http://xmlns.com/foaf/0.1/> ' +
'SELECT * { ?mickey foaf:name "Mickey Mouse"@en; foaf:knows ?other. }',
);
// Regenerate a SPARQL query from a JSON object
const SparqlGenerator = SparqlJs.Generator;
const generator = new SparqlGenerator();
if (parsedQuery.type === 'query' && parsedQuery.queryType === 'SELECT') {
parsedQuery.variables = ['?mickey' as SparqlJs.Term];
}
// $ExpectType string
generator.stringify(parsedQuery);
}
function advancedOptions() {
const parser = new SparqlJs.Parser(
{rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'},
'http://example.com'
);
const generator = new SparqlJs.Generator({allPrefixes: false});
}
/**
* Basic query structure
*/
function basicQueries() {
const foo = 'example:foo' as SparqlJs.Term;
const bar = 'example:bar' as SparqlJs.Term;
const qux = 'example:qux' as SparqlJs.Term;
const prefixes = {rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'};
const bgpPattern: SparqlJs.BgpPattern = {
type: 'bgp',
triples: [
{subject: foo, predicate: qux, object: bar},
{
subject: foo,
predicate: {
type: 'path',
pathType: '|',
items: [qux, bar],
},
object: bar,
}
],
};
const select: SparqlJs.SelectQuery = {
type: 'query',
queryType: 'SELECT',
prefixes,
variables: ['*'],
distinct: true,
from: {
default: ['http://example.com/'],
named: ['http://example.com/foo', 'http://example.com/bar'],
},
reduced: false,
group: [
{expression: foo},
{expression: bar},
],
having: [{
type: 'functionCall',
function: 'isIRI',
args: [foo],
}],
order: [{
expression: bar,
descending: true,
}],
limit: 100,
offset: 10,
where: [bgpPattern],
values: [
{x: foo, y: bar},
{x: foo},
]
};
const construct: SparqlJs.ConstructQuery = {
type: 'query',
queryType: 'CONSTRUCT',
base: 'http://example.com',
prefixes,
template: bgpPattern.triples,
};
const ask: SparqlJs.AskQuery = {
type: 'query',
queryType: 'ASK',
prefixes,
};
const describe: SparqlJs.DescribeQuery = {
type: 'query',
queryType: 'DESCRIBE',
prefixes,
variables: [
foo,
{
variable: bar,
expression: {
type: 'operation',
operator: '+',
args: [foo, bar],
}
}
],
};
}
/**
* Update query structure
*/
function updateQueries() {
const bgp: SparqlJs.BgpPattern = {
type: 'bgp',
triples: [],
};
const update: SparqlJs.Update = {
type: 'update',
prefixes: {
rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
},
updates: [
{
updateType: 'insertdelete',
graph: 'http://example.com/foo',
insert: [bgp],
delete: [bgp],
where: [],
},
{
type: 'copy',
silent: true,
source: {
type: 'graph',
name: 'http://example.com/foo',
},
destination: {
type: 'graph',
default: true,
},
},
{
type: 'clear',
silent: false,
graph: {
type: 'graph',
all: true,
},
},
],
};
}

View File

@ -0,0 +1,31 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../../",
"typeRoots": [
"../../"
],
"types": [],
"paths": {
"sparqljs": [
"sparqljs/v2"
],
"sparqljs/*": [
"sparqljs/v2/*"
]
},
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"sparqljs-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }

View File

@ -1,7 +1,7 @@
// Type definitions for yog-ral 0.20
// Project: https://gitlab.baidu.com/fex/node-ral
// Definitions by: ssddi456 <https://github.com/ssddi456>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
export * from 'node-ral';
// Type definitions for yog-ral 0.20
// Project: https://gitlab.baidu.com/fex/node-ral
// Definitions by: ssddi456 <https://github.com/ssddi456>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
export * from 'node-ral';

View File

@ -1,24 +1,24 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"yog-ral-tests.ts"
]
}
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"yog-ral-tests.ts"
]
}

View File

@ -1,3 +1,3 @@
{
"extends": "dtslint/dt.json"
}
{
"extends": "dtslint/dt.json"
}

View File

@ -1,73 +1,73 @@
import * as yogRal from "yog-ral";
class FormConverter extends yogRal.Converter {
pack(config: yogRal.Service, data: {}) {
return new Buffer('123');
}
unpack(config: yogRal.Service, data: {}) {
return {};
}
getName() {
return 'form';
}
}
class HashringBalance extends yogRal.Balance {
getName() {
return 'hashring';
}
fetchServer(balanceContext: yogRal.Balance.BalanceContextClass, conf: {}, prevBackend: yogRal.Server): yogRal.Server {
return {
host: '127.0.0.1',
port: 8888,
};
}
}
class HttpProtocol extends yogRal.Protocol {
getName() {
return 'http';
}
_request(config: any, callback: (err: any, data: any) => any) {
callback(new Error(), '123');
}
}
class DefaultConfigNormalizer extends yogRal.ConfigNormalizer {
getName() {
return 'default';
}
needUpdate() {
return false;
}
normalizeConfig(config: any) {
return config;
}
}
const runner = yogRal.RAL('test', {});
runner.on('data', () => {
// yeap
});
runner.doRequest();
yogRal.RAL.init();
yogRal.RALPromise('test', {}).then;
yogRal.Config.loadRawConf;
yogRal.Config.load;
yogRal.Config.normalizerManager;
yogRal.Config.normalize;
yogRal.Config.getContext;
yogRal.Config.getConf;
yogRal.Config.clearConf;
yogRal.Config.getConfNames;
yogRal.Config.getRawConf;
yogRal.Config.getUpdateNeededRawConf;
yogRal.Config.enableUpdate;
yogRal.Config.disableUpdate;
yogRal.Config.isAutoUpdateEnabled;
const logger = yogRal.Logger('some');
logger.debug('test');
import * as yogRal from "yog-ral";
class FormConverter extends yogRal.Converter {
pack(config: yogRal.Service, data: {}) {
return new Buffer('123');
}
unpack(config: yogRal.Service, data: {}) {
return {};
}
getName() {
return 'form';
}
}
class HashringBalance extends yogRal.Balance {
getName() {
return 'hashring';
}
fetchServer(balanceContext: yogRal.Balance.BalanceContextClass, conf: {}, prevBackend: yogRal.Server): yogRal.Server {
return {
host: '127.0.0.1',
port: 8888,
};
}
}
class HttpProtocol extends yogRal.Protocol {
getName() {
return 'http';
}
_request(config: any, callback: (err: any, data: any) => any) {
callback(new Error(), '123');
}
}
class DefaultConfigNormalizer extends yogRal.ConfigNormalizer {
getName() {
return 'default';
}
needUpdate() {
return false;
}
normalizeConfig(config: any) {
return config;
}
}
const runner = yogRal.RAL('test', {});
runner.on('data', () => {
// yeap
});
runner.doRequest();
yogRal.RAL.init();
yogRal.RALPromise('test', {}).then;
yogRal.Config.loadRawConf;
yogRal.Config.load;
yogRal.Config.normalizerManager;
yogRal.Config.normalize;
yogRal.Config.getContext;
yogRal.Config.getConf;
yogRal.Config.clearConf;
yogRal.Config.getConfNames;
yogRal.Config.getRawConf;
yogRal.Config.getUpdateNeededRawConf;
yogRal.Config.enableUpdate;
yogRal.Config.disableUpdate;
yogRal.Config.isAutoUpdateEnabled;
const logger = yogRal.Logger('some');
logger.debug('test');