ldkit 0.6.5 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -15
- package/esm/library/global.js +2 -2
- package/esm/library/{resource/resource.js → lens/lens.js} +17 -2
- package/esm/library/lens/mod.js +1 -0
- package/esm/library/rdf.js +1 -1
- package/esm/library/sparql/sparql_query_builders.js +70 -32
- package/esm/library/sparql/sparql_shared_builders.js +42 -36
- package/esm/library/sparql/sparql_update_builders.js +32 -13
- package/esm/mod.js +1 -1
- package/package.json +36 -16
- package/script/library/global.js +2 -2
- package/script/library/{resource/resource.js → lens/lens.js} +20 -4
- package/script/library/lens/mod.js +6 -0
- package/script/library/sparql/sparql_query_builders.js +70 -31
- package/script/library/sparql/sparql_shared_builders.js +46 -41
- package/script/library/sparql/sparql_update_builders.js +32 -12
- package/script/mod.js +3 -2
- package/types/library/asynciterator.d.ts +3 -3
- package/types/library/decoder.d.ts +1 -1
- package/types/library/encoder.d.ts +1 -1
- package/types/library/engine/query_engine.d.ts +1 -1
- package/types/library/{resource/resource.d.ts → lens/lens.d.ts} +17 -2
- package/types/library/lens/mod.d.ts +1 -0
- package/types/library/lens/types.d.ts +5 -0
- package/types/library/namespaces/namespace.d.ts +4 -4
- package/types/library/rdf.d.ts +6 -6
- package/types/library/schema/data_types.d.ts +2 -2
- package/types/library/schema/interface.d.ts +13 -13
- package/types/library/schema/schema.d.ts +7 -7
- package/types/library/sparql/sparql_query_builders.d.ts +36 -1175
- package/types/library/sparql/sparql_shared_builders.d.ts +13 -11
- package/types/library/sparql/sparql_tag.d.ts +1 -1
- package/types/library/sparql/sparql_update_builders.d.ts +20 -129
- package/types/mod.d.ts +1 -1
- package/esm/library/resource/mod.js +0 -1
- package/script/library/resource/mod.js +0 -6
- package/types/library/resource/mod.d.ts +0 -1
- package/types/library/resource/types.d.ts +0 -5
- /package/esm/library/{resource → lens}/query_builder.js +0 -0
- /package/esm/library/{resource → lens}/query_helper.js +0 -0
- /package/esm/library/{resource → lens}/types.js +0 -0
- /package/script/library/{resource → lens}/query_builder.js +0 -0
- /package/script/library/{resource → lens}/query_helper.js +0 -0
- /package/script/library/{resource → lens}/types.js +0 -0
- /package/types/library/{resource → lens}/query_builder.d.ts +0 -0
- /package/types/library/{resource → lens}/query_helper.d.ts +0 -0
|
@@ -1,47 +1,52 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.SparqlBuilder = exports.parentheses = exports.braces = void 0;
|
|
4
4
|
const rdf_js_1 = require("../rdf.js");
|
|
5
5
|
const sparql_tag_js_1 = require("./sparql_tag.js");
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
6
|
+
const braces = (keyword, value) => `${keyword} {\n${value}\n}\n`;
|
|
7
|
+
exports.braces = braces;
|
|
8
|
+
const parentheses = (keyword, value) => `${keyword} (${value})\n`;
|
|
9
|
+
exports.parentheses = parentheses;
|
|
10
|
+
const none = (keyword, value) => `${keyword} ${value}\n`;
|
|
11
|
+
class SparqlBuilder {
|
|
12
|
+
constructor() {
|
|
13
|
+
Object.defineProperty(this, "value", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
configurable: true,
|
|
16
|
+
writable: true,
|
|
17
|
+
value: ""
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(this, "dataFactory", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true,
|
|
23
|
+
value: new rdf_js_1.DataFactory()
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
build() {
|
|
27
|
+
return this.value;
|
|
28
|
+
}
|
|
29
|
+
sparql(strings, ...values) {
|
|
30
|
+
return !values || values.length < 1
|
|
31
|
+
? (0, sparql_tag_js_1.sparql)(strings)
|
|
32
|
+
: (0, sparql_tag_js_1.sparql)(strings, ...values);
|
|
33
|
+
}
|
|
34
|
+
template(strings, values, keyword, wrap = none) {
|
|
35
|
+
const inputSparql = this.sparql(strings, ...values);
|
|
36
|
+
this.value += wrap(keyword, inputSparql);
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
namedNode(stringOrNamedNode, keyword, wrap = none) {
|
|
35
40
|
const namedNode = typeof stringOrNamedNode === "string"
|
|
36
|
-
?
|
|
41
|
+
? this.dataFactory.namedNode(stringOrNamedNode)
|
|
37
42
|
: stringOrNamedNode;
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
return
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
exports.
|
|
43
|
+
const inputSparql = this.sparql `${namedNode}`;
|
|
44
|
+
this.value += wrap(keyword, inputSparql);
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
number(number, keyword, wrap = none) {
|
|
48
|
+
this.value += wrap(keyword, number.toString());
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.SparqlBuilder = SparqlBuilder;
|
|
@@ -2,17 +2,37 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.WITH = exports.DELETE = exports.INSERT = void 0;
|
|
4
4
|
const sparql_shared_builders_js_1 = require("./sparql_shared_builders.js");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
class SparqlUpdateBuilder extends sparql_shared_builders_js_1.SparqlBuilder {
|
|
6
|
+
WHERE(strings, ...values) {
|
|
7
|
+
return this.template(strings, values, "WHERE", sparql_shared_builders_js_1.braces);
|
|
8
|
+
}
|
|
9
|
+
USING_NAMED(stringOrNamedNode) {
|
|
10
|
+
return this.namedNode(stringOrNamedNode, "USING NAMED");
|
|
11
|
+
}
|
|
12
|
+
USING(stringOrNamedNode) {
|
|
13
|
+
return this.namedNode(stringOrNamedNode, "USING");
|
|
14
|
+
}
|
|
15
|
+
INSERT(strings, ...values) {
|
|
16
|
+
return this.template(strings, values, "INSERT", sparql_shared_builders_js_1.braces);
|
|
17
|
+
}
|
|
18
|
+
INSERT_DATA(strings, ...values) {
|
|
19
|
+
return this.template(strings, values, "INSERT DATA", sparql_shared_builders_js_1.braces);
|
|
20
|
+
}
|
|
21
|
+
DELETE(strings, ...values) {
|
|
22
|
+
return this.template(strings, values, "DELETE", sparql_shared_builders_js_1.braces);
|
|
23
|
+
}
|
|
24
|
+
DELETE_DATA(strings, ...values) {
|
|
25
|
+
return this.template(strings, values, "DELETE DATA", sparql_shared_builders_js_1.braces);
|
|
26
|
+
}
|
|
27
|
+
WITH(stringOrNamedNode) {
|
|
28
|
+
return this.namedNode(stringOrNamedNode, "WITH");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.INSERT = Object.assign((strings, ...values) => new SparqlUpdateBuilder().INSERT(strings, ...values), {
|
|
32
|
+
DATA: (strings, ...values) => new SparqlUpdateBuilder().INSERT_DATA(strings, ...values),
|
|
12
33
|
});
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
exports.DELETE = Object.assign(_DELETE, {
|
|
16
|
-
DATA: _DELETE_DATA,
|
|
34
|
+
exports.DELETE = Object.assign((strings, ...values) => new SparqlUpdateBuilder().DELETE(strings, ...values), {
|
|
35
|
+
DATA: (strings, ...values) => new SparqlUpdateBuilder().DELETE_DATA(strings, ...values),
|
|
17
36
|
});
|
|
18
|
-
|
|
37
|
+
const WITH = (stringOrNamedNode) => new SparqlUpdateBuilder().WITH(stringOrNamedNode);
|
|
38
|
+
exports.WITH = WITH;
|
package/script/mod.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createNamespace = exports.createResource = exports.setDefaultEngine = exports.setDefaultContext = void 0;
|
|
3
|
+
exports.createNamespace = exports.createResource = exports.createLens = exports.setDefaultEngine = exports.setDefaultContext = void 0;
|
|
4
4
|
var global_js_1 = require("./library/global.js");
|
|
5
5
|
Object.defineProperty(exports, "setDefaultContext", { enumerable: true, get: function () { return global_js_1.setDefaultContext; } });
|
|
6
6
|
Object.defineProperty(exports, "setDefaultEngine", { enumerable: true, get: function () { return global_js_1.setDefaultEngine; } });
|
|
7
|
-
var mod_js_1 = require("./library/
|
|
7
|
+
var mod_js_1 = require("./library/lens/mod.js");
|
|
8
|
+
Object.defineProperty(exports, "createLens", { enumerable: true, get: function () { return mod_js_1.createLens; } });
|
|
8
9
|
Object.defineProperty(exports, "createResource", { enumerable: true, get: function () { return mod_js_1.createResource; } });
|
|
9
10
|
var namespace_js_1 = require("./library/namespaces/namespace.js");
|
|
10
11
|
Object.defineProperty(exports, "createNamespace", { enumerable: true, get: function () { return namespace_js_1.createNamespace; } });
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { AsyncIterator } from "asynciterator";
|
|
2
2
|
export { ArrayIterator, type AsyncIterator, MappingIterator, } from "asynciterator";
|
|
3
|
-
|
|
3
|
+
type TreeNode<T> = {
|
|
4
4
|
[property: string]: T[] | TreeNode<T>;
|
|
5
5
|
};
|
|
6
|
-
export
|
|
7
|
-
|
|
6
|
+
export type Tree<T> = T[] | TreeNode<T>;
|
|
7
|
+
type Subtree<T> = {
|
|
8
8
|
type: "node";
|
|
9
9
|
tree: TreeNode<T>;
|
|
10
10
|
parent?: Subtree<T>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Context, Graph } from "./rdf.js";
|
|
2
2
|
import type { Schema } from "./schema/mod.js";
|
|
3
|
-
|
|
3
|
+
type DecodedNode = Record<string, unknown>;
|
|
4
4
|
export declare const decode: (graph: Graph, schema: Schema, context: Context) => DecodedNode[];
|
|
5
5
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Context, type RDF } from "./rdf.js";
|
|
2
2
|
import type { Schema } from "./schema/mod.js";
|
|
3
|
-
|
|
3
|
+
type DecodedNode = Record<string, unknown>;
|
|
4
4
|
export declare const encode: (node: DecodedNode, schema: Schema, context: Context, variableInitCounter?: number) => RDF.Quad[];
|
|
5
5
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Context, type IQueryEngine, type RDF, RDFJSON } from "../rdf.js";
|
|
2
|
-
|
|
2
|
+
type QueryResponseFormat = {
|
|
3
3
|
"application/sparql-results+json": RDFJSON.SparqlResultsJsonFormat;
|
|
4
4
|
"application/rdf+json": RDFJSON.RdfJsonFormat;
|
|
5
5
|
};
|
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
import type { Context, IQueryEngine, Iri, RDF } from "../rdf.js";
|
|
2
2
|
import { type SchemaInterface, type SchemaInterfaceIdentity, type SchemaPrototype } from "../schema/mod.js";
|
|
3
3
|
import type { Entity } from "./types.js";
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Lens lets you query and update RDF data via data schema using TypeScript native data types.
|
|
6
|
+
*
|
|
7
|
+
* https://ldkit.io/docs/components/lens
|
|
8
|
+
*
|
|
9
|
+
* @param schema data schema which extends `SchemaPrototype`
|
|
10
|
+
* @param context optional `Context` - contains LDkit and query engine configuration
|
|
11
|
+
* @param engine optional Query Engine
|
|
12
|
+
* @returns Lens instance
|
|
13
|
+
*/
|
|
14
|
+
export declare const createLens: <T extends SchemaPrototype>(schema: T, context?: Context, engine?: IQueryEngine) => Lens<T, SchemaInterface<T>>;
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated
|
|
17
|
+
* Use `createLens` instead
|
|
18
|
+
*/
|
|
19
|
+
export declare const createResource: <T extends SchemaPrototype>(schema: T, context?: Context, engine?: IQueryEngine) => Lens<T, SchemaInterface<T>>;
|
|
20
|
+
export declare class Lens<S extends SchemaPrototype, I = SchemaInterface<S>> {
|
|
6
21
|
private readonly schema;
|
|
7
22
|
private readonly context;
|
|
8
23
|
private readonly engine;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createLens, createResource, type Lens } from "./lens.js";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SchemaInterfaceIdentity } from "../schema/mod.js";
|
|
2
|
+
export type Entity<T extends unknown = Record<string, unknown>> = DeepPartial<T> & SchemaInterfaceIdentity;
|
|
3
|
+
export type DeepPartial<T> = T extends Record<string, unknown> ? {
|
|
4
|
+
[P in keyof T]?: DeepPartial<T[P]>;
|
|
5
|
+
} : T;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
type NamespacePrototype = {
|
|
2
2
|
iri: string;
|
|
3
3
|
prefix: string;
|
|
4
4
|
terms: readonly string[];
|
|
5
5
|
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
type NamespacePrefix<Namespace extends NamespacePrototype> = Namespace["prefix"];
|
|
7
|
+
type NamespaceIri<Namespace extends NamespacePrototype> = Namespace["iri"];
|
|
8
|
+
type NamespaceObject<Namespace extends NamespacePrototype> = {
|
|
9
9
|
[Term in Namespace["terms"][number]]: `${NamespacePrefix<Namespace>}${Term}`;
|
|
10
10
|
};
|
|
11
11
|
export declare const createNamespace: <N extends NamespacePrototype, I = NamespaceIri<N>, P = NamespacePrefix<N>, O = NamespaceObject<N>>(namespaceSpec: N) => O & {
|
package/types/library/rdf.d.ts
CHANGED
|
@@ -4,15 +4,15 @@ export { fromRdf, toRdf } from "rdf-literal";
|
|
|
4
4
|
import { DataFactory, DefaultGraph } from "rdf-data-factory";
|
|
5
5
|
export { DataFactory, DefaultGraph };
|
|
6
6
|
import type { IDataSource, IQueryContextCommon } from "@comunica/types";
|
|
7
|
-
export
|
|
7
|
+
export type LDkitContext = {
|
|
8
8
|
graph?: string;
|
|
9
9
|
language?: string;
|
|
10
10
|
};
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export
|
|
15
|
-
export
|
|
11
|
+
export type Context = LDkitContext & RDF.QueryStringContext & RDF.QuerySourceContext<IDataSource> & IQueryContextCommon;
|
|
12
|
+
export type IQueryEngine = RDF.StringSparqlQueryable<RDF.SparqlResultSupport, Context>;
|
|
13
|
+
export type Iri = string;
|
|
14
|
+
export type Node = Map<Iri, RDF.Term[]>;
|
|
15
|
+
export type Graph = Map<Iri, Node>;
|
|
16
16
|
export declare const quadsToGraph: (quads: RDF.Quad[]) => Graph;
|
|
17
17
|
export declare namespace RDFJSON {
|
|
18
18
|
type Term = {
|
|
@@ -34,6 +34,6 @@ declare const SupportedDataTypesPrototype: {
|
|
|
34
34
|
"xsd:hexBinary": string;
|
|
35
35
|
"rdf:langString": string;
|
|
36
36
|
};
|
|
37
|
-
export
|
|
38
|
-
export
|
|
37
|
+
export type SupportedDataTypes = typeof SupportedDataTypesPrototype;
|
|
38
|
+
export type SupportedNativeTypes = SupportedDataTypes[keyof SupportedDataTypes];
|
|
39
39
|
export {};
|
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
import type { SupportedDataTypes } from "./data_types.js";
|
|
2
2
|
import type { PropertyPrototype, SchemaPrototype } from "./schema.js";
|
|
3
|
-
|
|
3
|
+
type IsOptional<Property extends PropertyPrototype> = Property extends {
|
|
4
4
|
"@optional": true;
|
|
5
5
|
} ? true : false;
|
|
6
|
-
|
|
6
|
+
type IsArray<Property extends PropertyPrototype> = Property extends {
|
|
7
7
|
"@array": true;
|
|
8
8
|
} ? true : false;
|
|
9
|
-
|
|
9
|
+
type IsMultilang<Property extends PropertyPrototype> = Property extends {
|
|
10
10
|
"@multilang": true;
|
|
11
11
|
} ? true : false;
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
type ValidPropertyDefinition = PropertyPrototype | string;
|
|
13
|
+
type ConvertPropertyType<T extends PropertyPrototype> = T extends {
|
|
14
14
|
"@context": SchemaPrototype;
|
|
15
15
|
} ? SchemaInterface<T["@context"]> : T extends {
|
|
16
16
|
"@type": unknown;
|
|
17
17
|
} ? T["@type"] extends keyof SupportedDataTypes ? SupportedDataTypes[T["@type"]] : never : string;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
export
|
|
18
|
+
type ConvertPropertyOptional<T extends PropertyPrototype> = IsOptional<T> extends true ? ConvertPropertyType<T> | undefined : ConvertPropertyType<T>;
|
|
19
|
+
type ConvertPropertyArray<T extends PropertyPrototype> = IsArray<T> extends true ? ConvertPropertyType<T>[] : ConvertPropertyOptional<T>;
|
|
20
|
+
type ConvertPropertyMultilang<T extends PropertyPrototype> = IsMultilang<T> extends true ? IsArray<T> extends true ? Record<string, ConvertPropertyType<T>[]> : Record<string, ConvertPropertyType<T>> : ConvertPropertyArray<T>;
|
|
21
|
+
type ConvertPropertyObject<T extends PropertyPrototype> = ConvertPropertyMultilang<T>;
|
|
22
|
+
type ConvertProperty<T extends ValidPropertyDefinition> = T extends PropertyPrototype ? ConvertPropertyObject<T> : string;
|
|
23
|
+
export type SchemaInterfaceIdentity = {
|
|
24
24
|
$id: string;
|
|
25
25
|
};
|
|
26
|
-
export
|
|
26
|
+
export type SchemaInterfaceType = {
|
|
27
27
|
$type: string[];
|
|
28
28
|
};
|
|
29
|
-
export
|
|
29
|
+
export type SchemaInterface<T extends SchemaPrototype> = {
|
|
30
30
|
[X in Exclude<keyof T, "@type">]: T[X] extends ValidPropertyDefinition ? ConvertProperty<T[X]> : never;
|
|
31
31
|
} & SchemaInterfaceIdentity & SchemaInterfaceType;
|
|
32
32
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SupportedDataTypes } from "./data_types.js";
|
|
2
|
-
|
|
3
|
-
export
|
|
2
|
+
type PropertyType = keyof SupportedDataTypes;
|
|
3
|
+
export type PropertyPrototype = {
|
|
4
4
|
"@id": string;
|
|
5
5
|
"@type"?: PropertyType;
|
|
6
6
|
"@context"?: SchemaPrototype;
|
|
@@ -8,14 +8,14 @@ export declare type PropertyPrototype = {
|
|
|
8
8
|
"@array"?: true;
|
|
9
9
|
"@multilang"?: true;
|
|
10
10
|
};
|
|
11
|
-
export
|
|
11
|
+
export type SchemaPrototypeProperties = {
|
|
12
12
|
[key: string]: PropertyPrototype | string | readonly string[];
|
|
13
13
|
};
|
|
14
|
-
export
|
|
14
|
+
export type SchemaPrototypeType = {
|
|
15
15
|
"@type": string | readonly string[];
|
|
16
16
|
};
|
|
17
|
-
export
|
|
18
|
-
export
|
|
17
|
+
export type SchemaPrototype = SchemaPrototypeProperties & SchemaPrototypeType;
|
|
18
|
+
export type Property = {
|
|
19
19
|
"@id": string;
|
|
20
20
|
"@type"?: PropertyType;
|
|
21
21
|
"@context"?: Schema;
|
|
@@ -23,7 +23,7 @@ export declare type Property = {
|
|
|
23
23
|
"@array"?: true;
|
|
24
24
|
"@multilang"?: true;
|
|
25
25
|
};
|
|
26
|
-
export
|
|
26
|
+
export type Schema = {
|
|
27
27
|
[key: string]: Property | string[];
|
|
28
28
|
"@type": string[];
|
|
29
29
|
};
|