diff --git a/types/sparqljs/index.d.ts b/types/sparqljs/index.d.ts index 4b63cf8a59..dfc04ccfcd 100644 --- a/types/sparqljs/index.d.ts +++ b/types/sparqljs/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for sparqljs 1.5 +// Type definitions for sparqljs 2.1 // Project: https://github.com/RubenVerborgh/SPARQL.js // Definitions by: Alexey Morozov // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -8,7 +8,6 @@ export const Parser: { new ( prefixes?: { [prefix: string]: string }, baseIRI?: string, - options?: ParserOptions, ): SparqlParser; }; @@ -16,11 +15,6 @@ export const Generator: { new (options?: GeneratorOptions): SparqlGenerator; }; -export interface ParserOptions { - /** @default true */ - collapseGroups?: boolean; -} - export interface GeneratorOptions { allPrefixes?: boolean; } @@ -94,6 +88,7 @@ export type UpdateOperation = InsertDeleteOperation | ManagementOperation; export interface InsertDeleteOperation { updateType: 'insert' | 'delete' | 'deletewhere' | 'insertdelete'; + graph?: string; insert?: Quads[]; delete?: Quads[]; where?: Pattern[]; @@ -101,17 +96,47 @@ export interface InsertDeleteOperation { export type Quads = BgpPattern | GraphQuads; -export interface ManagementOperation { - type: 'load' | 'copy' | 'move' | 'add'; +export type ManagementOperation = + | CopyMoveAddOperation + | LoadOperation + | CreateOperation + | ClearDropOperation; + +export interface CopyMoveAddOperation { + type: 'copy' | 'move' | 'add'; silent: boolean; - source: string | { - type: 'graph'; - default: boolean; - }; - destination?: string | { - type: 'graph'; - name: string; - }; + 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; } /** diff --git a/types/sparqljs/sparqljs-tests.ts b/types/sparqljs/sparqljs-tests.ts index b8c0e36109..2fe29b40c8 100644 --- a/types/sparqljs/sparqljs-tests.ts +++ b/types/sparqljs/sparqljs-tests.ts @@ -26,8 +26,7 @@ function officialExamples() { function advancedOptions() { const parser = new SparqlJs.Parser( {rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'}, - 'http://example.com', - {collapseGroups: true} + 'http://example.com' ); const generator = new SparqlJs.Generator({allPrefixes: false}); } @@ -122,3 +121,49 @@ function basicQueries() { ], }; } + +/** + * 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, + }, + }, + ], + }; +}