ldkit 1.1.0 → 2.1.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 -5
- package/esm/library/decoder.js +20 -30
- package/esm/library/encoder.js +33 -17
- package/esm/library/engine/mod.js +2 -2
- package/esm/library/engine/query_engine.js +40 -0
- package/esm/library/engine/query_engine_proxy.js +8 -8
- package/esm/library/engine/types.js +1 -0
- package/esm/library/lens/lens.js +416 -27
- package/esm/library/lens/mod.js +1 -1
- package/esm/library/lens/query_builder.js +86 -52
- package/esm/library/lens/search_helper.js +142 -0
- package/esm/library/lens/update_helper.js +157 -0
- package/esm/library/namespace.js +36 -0
- package/esm/library/options.js +50 -0
- package/esm/library/schema/data_types.js +3 -38
- package/esm/library/schema/search.js +1 -0
- package/esm/library/schema/utils.js +31 -6
- package/esm/library/sparql/mod.js +2 -1
- package/esm/library/sparql/sparql_expression_builders.js +18 -0
- package/esm/library/sparql/sparql_query_builders.js +65 -0
- package/esm/library/sparql/sparql_shared_builders.js +1 -0
- package/esm/library/sparql/sparql_tag.js +27 -1
- package/esm/library/sparql/sparql_update_builders.js +70 -0
- package/esm/library/sparql/stringify.js +3 -4
- package/esm/mod.js +4 -4
- package/esm/{library/namespaces → namespaces}/dbo.js +7 -2
- package/esm/{library/namespaces → namespaces}/dc.js +7 -2
- package/esm/{library/namespaces → namespaces}/dcterms.js +7 -2
- package/esm/{library/namespaces → namespaces}/foaf.js +7 -2
- package/esm/{library/namespaces → namespaces}/gr.js +7 -2
- package/esm/namespaces/ldkit.js +11 -0
- package/esm/namespaces/owl.js +91 -0
- package/{script/library → esm}/namespaces/rdf.js +7 -4
- package/{script/library → esm}/namespaces/rdfs.js +7 -4
- package/esm/{library/namespaces → namespaces}/schema.js +7 -2
- package/esm/{library/namespaces → namespaces}/sioc.js +7 -2
- package/{script/library → esm}/namespaces/skos.js +7 -4
- package/{script/library → esm}/namespaces/xsd.js +7 -4
- package/esm/namespaces.js +30 -1
- package/esm/rdf.js +14 -1
- package/esm/sparql.js +13 -0
- package/package.json +8 -8
- package/script/library/decoder.js +25 -38
- package/script/library/encoder.js +38 -24
- package/script/library/engine/mod.js +16 -5
- package/script/library/engine/query_engine.js +40 -0
- package/script/library/engine/query_engine_proxy.js +7 -7
- package/script/library/engine/types.js +2 -0
- package/script/library/lens/lens.js +417 -29
- package/script/library/lens/mod.js +15 -4
- package/script/library/lens/query_builder.js +87 -56
- package/script/library/lens/search_helper.js +146 -0
- package/script/library/lens/update_helper.js +161 -0
- package/script/library/namespace.js +40 -0
- package/script/library/options.js +56 -0
- package/script/library/schema/data_types.js +3 -41
- package/script/library/schema/search.js +2 -0
- package/script/library/schema/utils.js +33 -11
- package/script/library/sparql/mod.js +17 -3
- package/script/library/sparql/sparql_expression_builders.js +22 -0
- package/script/library/sparql/sparql_query_builders.js +65 -0
- package/script/library/sparql/sparql_shared_builders.js +3 -1
- package/script/library/sparql/sparql_tag.js +30 -7
- package/script/library/sparql/sparql_update_builders.js +70 -0
- package/script/library/sparql/stringify.js +4 -8
- package/script/mod.js +20 -11
- package/script/{library/namespaces → namespaces}/dbo.js +8 -2
- package/script/{library/namespaces → namespaces}/dc.js +8 -2
- package/script/{library/namespaces → namespaces}/dcterms.js +8 -2
- package/script/{library/namespaces → namespaces}/foaf.js +8 -2
- package/script/{library/namespaces → namespaces}/gr.js +8 -2
- package/script/namespaces/ldkit.js +14 -0
- package/script/namespaces/owl.js +94 -0
- package/{esm/library → script}/namespaces/rdf.js +10 -2
- package/{esm/library → script}/namespaces/rdfs.js +10 -2
- package/script/{library/namespaces → namespaces}/schema.js +8 -2
- package/script/{library/namespaces → namespaces}/sioc.js +8 -2
- package/{esm/library → script}/namespaces/skos.js +10 -2
- package/{esm/library → script}/namespaces/xsd.js +10 -2
- package/script/namespaces.js +44 -1
- package/script/rdf.js +20 -15
- package/script/sparql.js +13 -0
- package/types/library/decoder.d.ts +4 -3
- package/types/library/encoder.d.ts +5 -3
- package/types/library/engine/mod.d.ts +2 -2
- package/types/library/engine/query_engine.d.ts +50 -9
- package/types/library/engine/query_engine_proxy.d.ts +4 -3
- package/types/library/engine/types.d.ts +23 -0
- package/types/library/lens/lens.d.ts +401 -24
- package/types/library/lens/mod.d.ts +1 -1
- package/types/library/lens/query_builder.d.ts +11 -11
- package/types/library/lens/search_helper.d.ts +21 -0
- package/types/library/lens/types.d.ts +5 -2
- package/types/library/lens/update_helper.d.ts +23 -0
- package/types/library/namespace.d.ts +41 -0
- package/types/library/options.d.ts +70 -0
- package/types/library/rdf.d.ts +8 -15
- package/types/library/schema/data_types.d.ts +44 -37
- package/types/library/schema/interface.d.ts +75 -20
- package/types/library/schema/mod.d.ts +4 -2
- package/types/library/schema/schema.d.ts +23 -16
- package/types/library/schema/search.d.ts +20 -0
- package/types/library/schema/utils.d.ts +3 -3
- package/types/library/sparql/mod.d.ts +2 -1
- package/types/library/sparql/sparql_expression_builders.d.ts +19 -0
- package/types/library/sparql/sparql_query_builders.d.ts +68 -3
- package/types/library/sparql/sparql_shared_builders.d.ts +1 -0
- package/types/library/sparql/sparql_tag.d.ts +29 -1
- package/types/library/sparql/sparql_update_builders.d.ts +68 -0
- package/types/mod.d.ts +5 -6
- package/types/namespaces/dbo.d.ts +10 -0
- package/types/namespaces/dc.d.ts +10 -0
- package/types/namespaces/dcterms.d.ts +10 -0
- package/types/namespaces/foaf.d.ts +10 -0
- package/types/namespaces/gr.d.ts +10 -0
- package/types/namespaces/ldkit.d.ts +10 -0
- package/types/namespaces/owl.d.ts +10 -0
- package/types/namespaces/rdf.d.ts +10 -0
- package/types/namespaces/rdfs.d.ts +10 -0
- package/types/namespaces/schema.d.ts +10 -0
- package/types/namespaces/sioc.d.ts +10 -0
- package/types/namespaces/skos.d.ts +10 -0
- package/types/namespaces/xsd.d.ts +10 -0
- package/types/namespaces.d.ts +30 -1
- package/types/rdf.d.ts +14 -1
- package/types/sparql.d.ts +13 -0
- package/esm/library/global.js +0 -25
- package/esm/library/lens/query_helper.js +0 -102
- package/esm/library/namespaces/ldkit.js +0 -6
- package/esm/library/namespaces/mod.js +0 -13
- package/esm/library/namespaces/namespace.js +0 -11
- package/script/library/global.js +0 -32
- package/script/library/lens/query_helper.js +0 -106
- package/script/library/namespaces/ldkit.js +0 -8
- package/script/library/namespaces/mod.js +0 -32
- package/script/library/namespaces/namespace.js +0 -15
- package/types/library/global.d.ts +0 -5
- package/types/library/lens/query_helper.d.ts +0 -19
- package/types/library/namespaces/dbo.d.ts +0 -3649
- package/types/library/namespaces/dc.d.ts +0 -21
- package/types/library/namespaces/dcterms.d.ts +0 -104
- package/types/library/namespaces/foaf.d.ts +0 -69
- package/types/library/namespaces/gr.d.ts +0 -175
- package/types/library/namespaces/ldkit.d.ts +0 -7
- package/types/library/namespaces/mod.d.ts +0 -13
- package/types/library/namespaces/namespace.d.ts +0 -15
- package/types/library/namespaces/rdf.d.ts +0 -28
- package/types/library/namespaces/rdfs.d.ts +0 -21
- package/types/library/namespaces/schema.d.ts +0 -2697
- package/types/library/namespaces/sioc.d.ts +0 -105
- package/types/library/namespaces/skos.d.ts +0 -38
- package/types/library/namespaces/xsd.d.ts +0 -56
package/types/library/rdf.d.ts
CHANGED
|
@@ -1,20 +1,13 @@
|
|
|
1
|
-
import type * as RDF from "
|
|
1
|
+
import type * as RDF from "@rdfjs/types";
|
|
2
2
|
export type { RDF };
|
|
3
3
|
export { fromRdf, toRdf } from "rdf-literal";
|
|
4
4
|
import { DataFactory, DefaultGraph } from "rdf-data-factory";
|
|
5
5
|
export { DataFactory, DefaultGraph };
|
|
6
6
|
export * as N3 from "n3";
|
|
7
|
-
|
|
8
|
-
export type
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
12
|
-
export type Context = LDkitContext & RDF.QueryStringContext & RDF.QuerySourceContext<IDataSource> & IQueryContextCommon;
|
|
13
|
-
export type IQueryEngine = RDF.StringSparqlQueryable<RDF.SparqlResultSupport, Context>;
|
|
14
|
-
export type Iri = string;
|
|
15
|
-
export type Node = Map<Iri, RDF.Term[]>;
|
|
16
|
-
export type Graph = Map<Iri, Node>;
|
|
17
|
-
export declare const quadsToGraph: (quads: RDF.Quad[]) => Graph;
|
|
7
|
+
export type IRI = string;
|
|
8
|
+
export type Node = Map<IRI, RDF.Term[]>;
|
|
9
|
+
export type Graph = Map<IRI, Node>;
|
|
10
|
+
export declare const quadsToGraph: (quads: Iterable<RDF.Quad>) => Graph;
|
|
18
11
|
export declare namespace RDFJSON {
|
|
19
12
|
type Term = {
|
|
20
13
|
type: "uri" | "literal" | "bnode";
|
|
@@ -23,7 +16,7 @@ export declare namespace RDFJSON {
|
|
|
23
16
|
datatype?: string;
|
|
24
17
|
};
|
|
25
18
|
type Bindings = Record<string, Term>;
|
|
26
|
-
type Triple = [
|
|
19
|
+
type Triple = [IRI, IRI, Term];
|
|
27
20
|
type SparqlResultsJsonFormat = {
|
|
28
21
|
head: {
|
|
29
22
|
vars?: string[];
|
|
@@ -33,7 +26,7 @@ export declare namespace RDFJSON {
|
|
|
33
26
|
};
|
|
34
27
|
boolean?: boolean;
|
|
35
28
|
};
|
|
36
|
-
type RdfJsonFormat = Record<
|
|
29
|
+
type RdfJsonFormat = Record<IRI, Record<IRI, Term[]>>;
|
|
37
30
|
interface TermFactory {
|
|
38
31
|
fromJson(jsonTerm: Term): RDF.Term;
|
|
39
32
|
}
|
|
@@ -80,5 +73,5 @@ export declare class QuadFactory implements RDFJSON.QuadFactory {
|
|
|
80
73
|
protected readonly dataFactory: RDF.DataFactory;
|
|
81
74
|
protected readonly termFactory: RDFJSON.TermFactory;
|
|
82
75
|
constructor(dataFactory?: RDF.DataFactory, termFactory?: RDFJSON.TermFactory);
|
|
83
|
-
fromJson(jsonRdf: [
|
|
76
|
+
fromJson(jsonRdf: [IRI, IRI, RDFJSON.Term]): RDF.Quad;
|
|
84
77
|
}
|
|
@@ -1,39 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
1
|
+
import { xsd } from "../../namespaces/xsd.js";
|
|
2
|
+
import { rdf } from "../../namespaces/rdf.js";
|
|
3
|
+
import { ldkit } from "../../namespaces/ldkit.js";
|
|
4
|
+
import { type IRI } from "../rdf.js";
|
|
5
|
+
/** Map of supported RDF data types and their JavaScript native counterparts */
|
|
6
|
+
export type SupportedDataTypes = {
|
|
7
|
+
[xsd.dateTime]: Date;
|
|
8
|
+
[xsd.date]: Date;
|
|
9
|
+
[xsd.gDay]: Date;
|
|
10
|
+
[xsd.gMonthDay]: Date;
|
|
11
|
+
[xsd.gYear]: Date;
|
|
12
|
+
[xsd.gYearMonth]: Date;
|
|
13
|
+
[xsd.boolean]: boolean;
|
|
14
|
+
[xsd.double]: number;
|
|
15
|
+
[xsd.decimal]: number;
|
|
16
|
+
[xsd.float]: number;
|
|
17
|
+
[xsd.integer]: number;
|
|
18
|
+
[xsd.long]: number;
|
|
19
|
+
[xsd.int]: number;
|
|
20
|
+
[xsd.byte]: number;
|
|
21
|
+
[xsd.short]: number;
|
|
22
|
+
[xsd.negativeInteger]: number;
|
|
23
|
+
[xsd.nonNegativeInteger]: number;
|
|
24
|
+
[xsd.nonPositiveInteger]: number;
|
|
25
|
+
[xsd.positiveInteger]: number;
|
|
26
|
+
[xsd.unsignedByte]: number;
|
|
27
|
+
[xsd.unsignedInt]: number;
|
|
28
|
+
[xsd.unsignedLong]: number;
|
|
29
|
+
[xsd.unsignedShort]: number;
|
|
30
|
+
[xsd.string]: string;
|
|
31
|
+
[xsd.normalizedString]: string;
|
|
32
|
+
[xsd.anyURI]: string;
|
|
33
|
+
[xsd.base64Binary]: string;
|
|
34
|
+
[xsd.language]: string;
|
|
35
|
+
[xsd.Name]: string;
|
|
36
|
+
[xsd.NCName]: string;
|
|
37
|
+
[xsd.NMTOKEN]: string;
|
|
38
|
+
[xsd.token]: string;
|
|
39
|
+
[xsd.hexBinary]: string;
|
|
40
|
+
[rdf.langString]: string;
|
|
41
|
+
[xsd.time]: string;
|
|
42
|
+
[xsd.duration]: string;
|
|
43
|
+
[ldkit.IRI]: IRI;
|
|
36
44
|
};
|
|
37
|
-
|
|
45
|
+
/** List of supported native JavaScript types */
|
|
38
46
|
export type SupportedNativeTypes = SupportedDataTypes[keyof SupportedDataTypes];
|
|
39
|
-
export {};
|
|
@@ -1,32 +1,87 @@
|
|
|
1
|
+
import { IRI } from "../rdf.js";
|
|
1
2
|
import type { SupportedDataTypes } from "./data_types.js";
|
|
2
|
-
import type {
|
|
3
|
-
type
|
|
3
|
+
import type { Property, Schema } from "./schema.js";
|
|
4
|
+
import type { SearchFilters } from "./search.js";
|
|
5
|
+
type Unite<T> = T extends Record<string, unknown> ? {
|
|
6
|
+
[Key in keyof T]: T[Key];
|
|
7
|
+
} : T;
|
|
8
|
+
type IsOptional<T extends Property> = T extends {
|
|
4
9
|
"@optional": true;
|
|
5
10
|
} ? true : false;
|
|
6
|
-
type IsArray<
|
|
11
|
+
type IsArray<T extends Property> = T extends {
|
|
7
12
|
"@array": true;
|
|
8
13
|
} ? true : false;
|
|
9
|
-
type IsMultilang<
|
|
14
|
+
type IsMultilang<T extends Property> = T extends {
|
|
10
15
|
"@multilang": true;
|
|
11
16
|
} ? true : false;
|
|
12
|
-
type
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
type IsInverse<T extends Property> = T extends {
|
|
18
|
+
"@inverse": true;
|
|
19
|
+
} ? true : false;
|
|
20
|
+
type ValidPropertyDefinition = Property | string;
|
|
21
|
+
type ConvertPropertyType<T extends Property> = T extends {
|
|
16
22
|
"@type": unknown;
|
|
17
23
|
} ? T["@type"] extends keyof SupportedDataTypes ? SupportedDataTypes[T["@type"]] : never : string;
|
|
18
|
-
type
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
type
|
|
22
|
-
type
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
type ConvertPropertySchema<T extends Property> = T extends {
|
|
25
|
+
"@schema": Schema;
|
|
26
|
+
} ? Unite<SchemaInterface<T["@schema"]>> : ConvertPropertyType<T>;
|
|
27
|
+
type ConvertPropertyOptional<T extends Property> = IsOptional<T> extends true ? ConvertPropertySchema<T> | null : ConvertPropertySchema<T>;
|
|
28
|
+
type ConvertPropertyArray<T extends Property> = IsArray<T> extends true ? ConvertPropertySchema<T>[] : ConvertPropertyOptional<T>;
|
|
29
|
+
type ConvertPropertyMultilang<T extends Property> = IsMultilang<T> extends true ? IsArray<T> extends true ? Record<string, ConvertPropertyType<T>[]> : Record<string, ConvertPropertyType<T>> : ConvertPropertyArray<T>;
|
|
30
|
+
type ConvertPropertyObject<T extends Property> = ConvertPropertyMultilang<T>;
|
|
31
|
+
type ConvertProperty<T extends ValidPropertyDefinition> = T extends Property ? ConvertPropertyObject<T> : string;
|
|
32
|
+
/** Object that contains IRI of an entity */
|
|
33
|
+
export type Identity = {
|
|
34
|
+
$id: IRI;
|
|
28
35
|
};
|
|
29
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Describes a data model of a data entity according to its schema,. as resolved
|
|
38
|
+
* by LDkit, i.e. the shape of data that LDkit returns when querying for entities.
|
|
39
|
+
*
|
|
40
|
+
* See {@link Lens.prototype.find} for usage example.
|
|
41
|
+
*/
|
|
42
|
+
export type SchemaInterface<T extends Schema> = Identity & {
|
|
30
43
|
[X in Exclude<keyof T, "@type">]: T[X] extends ValidPropertyDefinition ? ConvertProperty<T[X]> : never;
|
|
31
|
-
}
|
|
44
|
+
};
|
|
45
|
+
type ConvertUpdatePropertySchema<T extends Property> = T extends {
|
|
46
|
+
"@schema": Schema;
|
|
47
|
+
} ? Unite<SchemaUpdateInterface<T["@schema"]>> : ConvertPropertyType<T>;
|
|
48
|
+
type ConvertUpdatePropertyOptional<T extends Property> = IsOptional<T> extends true ? ConvertPropertySchema<T> | null : ConvertUpdatePropertySchema<T>;
|
|
49
|
+
type CreateArrayUpdateInterface<T extends Property> = {
|
|
50
|
+
$set?: ConvertPropertyType<T>[];
|
|
51
|
+
$add?: ConvertPropertyType<T>[];
|
|
52
|
+
$remove?: ConvertPropertyType<T>[];
|
|
53
|
+
} | ConvertPropertyType<T>[];
|
|
54
|
+
type ConvertUpdatePropertyArray<T extends Property> = IsArray<T> extends true ? CreateArrayUpdateInterface<T> : ConvertUpdatePropertyOptional<T>;
|
|
55
|
+
type ConvertUpdatePropertyMultilang<T extends Property> = IsMultilang<T> extends true ? IsArray<T> extends true ? Record<string, CreateArrayUpdateInterface<T>> : Record<string, ConvertPropertyType<T>> : ConvertUpdatePropertyArray<T>;
|
|
56
|
+
type ConvertUpdatePropertyObject<T extends Property> = ConvertUpdatePropertyMultilang<T>;
|
|
57
|
+
type ConvertUpdateProperty<T extends ValidPropertyDefinition> = T extends Property ? ConvertUpdatePropertyObject<T> : string;
|
|
58
|
+
/**
|
|
59
|
+
* Describes a shape of data for updating an entity, according to its data schema.
|
|
60
|
+
*
|
|
61
|
+
* See {@link Lens.prototype.update} for usage example.
|
|
62
|
+
*/
|
|
63
|
+
export type SchemaUpdateInterface<T extends Schema> = Identity & {
|
|
64
|
+
[X in Exclude<keyof T, "@type">]?: T[X] extends ValidPropertyDefinition ? ConvertUpdateProperty<T[X]> : never;
|
|
65
|
+
};
|
|
66
|
+
type ConvertSearchPropertySchema<T extends Property> = T extends {
|
|
67
|
+
"@schema": Schema;
|
|
68
|
+
} ? Unite<SchemaSearchInterfaceProperties<T["@schema"]>> : IsInverse<T> extends true ? never : SearchFilters<ConvertPropertyType<T>>;
|
|
69
|
+
type ConvertSearchProperty<T extends ValidPropertyDefinition> = T extends Property ? ConvertSearchPropertySchema<T> : SearchFilters<string>;
|
|
70
|
+
type InversePropertiesMap<T extends Schema> = {
|
|
71
|
+
[X in keyof T]: T[X] extends {
|
|
72
|
+
"@inverse": true;
|
|
73
|
+
} ? X : never;
|
|
74
|
+
};
|
|
75
|
+
type InverseProperties<T extends Schema> = InversePropertiesMap<T>[keyof InversePropertiesMap<T>];
|
|
76
|
+
type SchemaSearchInterfaceProperties<T extends Schema> = {
|
|
77
|
+
[X in Exclude<keyof T, "@type" | InverseProperties<T>>]?: T[X] extends ValidPropertyDefinition ? ConvertSearchProperty<T[X]> : never;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Describes a shape of data for updating an entity, according to its data schema.
|
|
81
|
+
*
|
|
82
|
+
* See {@link Lens.prototype.find} for usage example.
|
|
83
|
+
*/
|
|
84
|
+
export type SchemaSearchInterface<T extends Schema> = {
|
|
85
|
+
$id?: IRI | IRI[];
|
|
86
|
+
} & SchemaSearchInterfaceProperties<T>;
|
|
32
87
|
export {};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export type {
|
|
2
|
-
export type {
|
|
1
|
+
export type { SupportedDataTypes, SupportedNativeTypes } from "./data_types.js";
|
|
2
|
+
export type { Identity, SchemaInterface, SchemaSearchInterface, SchemaUpdateInterface, } from "./interface.js";
|
|
3
|
+
export type { ExpandedProperty, ExpandedSchema, Property, Schema, } from "./schema.js";
|
|
4
|
+
export type { SearchFilters, SearchSchema } from "./search.js";
|
|
3
5
|
export { expandSchema, getSchemaProperties } from "./utils.js";
|
|
@@ -1,30 +1,37 @@
|
|
|
1
1
|
import type { SupportedDataTypes } from "./data_types.js";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Data property prototype that describes RDF predicate of a data entity.
|
|
4
|
+
* Includes specification of other metadata, such as whether the property
|
|
5
|
+
* is optional, array, inverse, or whether it is a nested data entity, etc.
|
|
6
|
+
*/
|
|
7
|
+
export type Property = {
|
|
4
8
|
"@id": string;
|
|
5
|
-
"@type"?:
|
|
6
|
-
"@
|
|
9
|
+
"@type"?: keyof SupportedDataTypes;
|
|
10
|
+
"@schema"?: Schema;
|
|
7
11
|
"@optional"?: true;
|
|
8
12
|
"@array"?: true;
|
|
9
13
|
"@multilang"?: true;
|
|
14
|
+
"@inverse"?: true;
|
|
10
15
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Data schema prototype that describes a data entity. Includes an optional
|
|
18
|
+
* specification of RDF type and a map of RDF properties.
|
|
19
|
+
*/
|
|
20
|
+
export type Schema = {
|
|
21
|
+
"@type"?: string | readonly string[];
|
|
22
|
+
} & {
|
|
23
|
+
[key: string]: Property | string | readonly string[];
|
|
16
24
|
};
|
|
17
|
-
export type
|
|
18
|
-
export type Property = {
|
|
25
|
+
export type ExpandedProperty = {
|
|
19
26
|
"@id": string;
|
|
20
|
-
"@type"?:
|
|
21
|
-
"@
|
|
27
|
+
"@type"?: keyof SupportedDataTypes;
|
|
28
|
+
"@schema"?: ExpandedSchema;
|
|
22
29
|
"@optional"?: true;
|
|
23
30
|
"@array"?: true;
|
|
24
31
|
"@multilang"?: true;
|
|
32
|
+
"@inverse"?: true;
|
|
25
33
|
};
|
|
26
|
-
export type
|
|
27
|
-
[key: string]:
|
|
34
|
+
export type ExpandedSchema = {
|
|
35
|
+
[key: string]: ExpandedProperty | string[];
|
|
28
36
|
"@type": string[];
|
|
29
37
|
};
|
|
30
|
-
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { SparqlValue } from "../sparql/mod.js";
|
|
2
|
+
export type SearchFilters<T> = T | {
|
|
3
|
+
$equals?: T;
|
|
4
|
+
$not?: T;
|
|
5
|
+
$contains?: T;
|
|
6
|
+
$strStarts?: T;
|
|
7
|
+
$strEnds?: T;
|
|
8
|
+
$gt?: T;
|
|
9
|
+
$gte?: T;
|
|
10
|
+
$lt?: T;
|
|
11
|
+
$lte?: T;
|
|
12
|
+
$regex?: string;
|
|
13
|
+
$langMatches?: string;
|
|
14
|
+
$in?: T[];
|
|
15
|
+
$notIn?: T[];
|
|
16
|
+
$filter?: SparqlValue;
|
|
17
|
+
};
|
|
18
|
+
export type SearchSchema = {
|
|
19
|
+
[key: string]: SearchFilters<unknown> | SearchSchema;
|
|
20
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const expandSchema: (schemaPrototype:
|
|
3
|
-
export declare const getSchemaProperties: (schema:
|
|
1
|
+
import type { ExpandedProperty, ExpandedSchema, Schema } from "./schema.js";
|
|
2
|
+
export declare const expandSchema: (schemaPrototype: Schema) => ExpandedSchema;
|
|
3
|
+
export declare const getSchemaProperties: (schema: ExpandedSchema) => Record<string, ExpandedProperty>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from "./sparql_tag.js";
|
|
2
2
|
export { ASK, CONSTRUCT, DESCRIBE, SELECT } from "./sparql_query_builders.js";
|
|
3
3
|
export { DELETE, INSERT, WITH } from "./sparql_update_builders.js";
|
|
4
|
+
export * from "./sparql_expression_builders.js";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SparqlBuilder } from "./sparql_shared_builders.js";
|
|
2
|
+
import { type SparqlValue } from "./sparql_tag.js";
|
|
3
|
+
type Builders<T extends keyof SparqlExpressionBuilder> = Pick<SparqlExpressionBuilder, T>;
|
|
4
|
+
declare class SparqlExpressionBuilder extends SparqlBuilder {
|
|
5
|
+
OPTIONAL(strings: TemplateStringsArray, ...values: SparqlValue[]): Builders<"build">;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* SPARQL OPTIONAL expression fluent interface
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { OPTIONAL } from "ldkit/sparql";
|
|
13
|
+
*
|
|
14
|
+
* const query = OPTIONAL`?s ?p ?o`.build();
|
|
15
|
+
* console.log(query); // OPTIONAL { ?s ?p ?o }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare const OPTIONAL: (strings: TemplateStringsArray, ...values: SparqlValue[]) => Builders<"build">;
|
|
19
|
+
export {};
|
|
@@ -22,18 +22,83 @@ declare class SparqlQueryBuilder extends SparqlBuilder {
|
|
|
22
22
|
ASK_WHERE(strings: TemplateStringsArray, ...values: SparqlValue[]): Builders<"build" | "GROUP_BY" | "ORDER_BY" | "LIMIT">;
|
|
23
23
|
DESCRIBE(strings: TemplateStringsArray, ...values: SparqlValue[]): Builders<"build" | "FROM" | "FROM_NAMED" | "WHERE">;
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* SPARQL SELECT query fluent interface
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* import { SELECT } from "ldkit/sparql";
|
|
31
|
+
*
|
|
32
|
+
* const query = SELECT`?s`.WHERE`?s ?p ?o`.ORDER_BY`?s`.LIMIT(100).build();
|
|
33
|
+
* console.log(query);
|
|
34
|
+
* // SELECT ?s WHERE { ?s ?p ?o } ORDER BY ?s LIMIT 100
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* import { SELECT } from "ldkit/sparql";
|
|
40
|
+
*
|
|
41
|
+
* const query = SELECT.DISTINCT`?s`.WHERE`?s ?p ?o`.build();
|
|
42
|
+
* console.log(query);
|
|
43
|
+
* // SELECT DISTINCT ?s WHERE { ?s ?p ?o }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
25
46
|
export declare const SELECT: ((strings: TemplateStringsArray, ...values: SparqlValue[]) => Builders<"WHERE" | "FROM_NAMED" | "FROM">) & {
|
|
26
47
|
DISTINCT: (strings: TemplateStringsArray, ...values: SparqlValue[]) => Builders<"WHERE" | "FROM_NAMED" | "FROM">;
|
|
27
48
|
REDUCED: (strings: TemplateStringsArray, ...values: SparqlValue[]) => Builders<"WHERE" | "FROM_NAMED" | "FROM">;
|
|
28
49
|
readonly ALL: Builders<"WHERE" | "FROM_NAMED" | "FROM">;
|
|
29
50
|
};
|
|
51
|
+
/**
|
|
52
|
+
* SPARQL CONSTRUCT query fluent interface
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* import { CONSTRUCT } from "ldkit/sparql";
|
|
57
|
+
* import { DataFactory } from "ldkit/rdf";
|
|
58
|
+
*
|
|
59
|
+
* const df = new DataFactory();
|
|
60
|
+
* const sNode = df.namedNode("http://example.org/datasource");
|
|
61
|
+
* const pNode = df.namedNode("http://example.org/hasSubject");
|
|
62
|
+
*
|
|
63
|
+
* const query = CONSTRUCT`${sNode} ${pNode} ?s`.WHERE`?s ?p ?o`.build();
|
|
64
|
+
* console.log(query);
|
|
65
|
+
* // CONSTRUCT { <http://example.org/datasource> <http://example.org/hasSubject> ?s }
|
|
66
|
+
* // WHERE { ?s ?p ?o }
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
30
69
|
export declare const CONSTRUCT: ((strings: TemplateStringsArray, ...values: SparqlValue[]) => Builders<"WHERE">) & {
|
|
31
|
-
WHERE: (strings: TemplateStringsArray, ...values: SparqlValue[]) => Builders<"
|
|
70
|
+
WHERE: (strings: TemplateStringsArray, ...values: SparqlValue[]) => Builders<"build" | "LIMIT" | "ORDER_BY" | "GROUP_BY">;
|
|
32
71
|
};
|
|
72
|
+
/**
|
|
73
|
+
* SPARQL ASK query fluent interface
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* import { ASK } from "ldkit/sparql";
|
|
78
|
+
*
|
|
79
|
+
* const query = ASK`?s ?p ?o`.build();
|
|
80
|
+
* console.log(query); // ASK { ?s ?p ?o }
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
33
83
|
export declare const ASK: ((strings: TemplateStringsArray, ...values: SparqlValue[]) => Builders<"build">) & {
|
|
34
84
|
FROM: (stringOrNamedNode: string | RDF.NamedNode<string>) => Builders<"WHERE" | "FROM_NAMED" | "FROM">;
|
|
35
85
|
FROM_NAMED: (stringOrNamedNode: string | RDF.NamedNode<string>) => Builders<"WHERE" | "FROM_NAMED">;
|
|
36
|
-
WHERE: (strings: TemplateStringsArray, ...values: SparqlValue[]) => Builders<"
|
|
86
|
+
WHERE: (strings: TemplateStringsArray, ...values: SparqlValue[]) => Builders<"build" | "LIMIT" | "ORDER_BY" | "GROUP_BY">;
|
|
37
87
|
};
|
|
38
|
-
|
|
88
|
+
/**
|
|
89
|
+
* SPARQL DESCRIBE query fluent interface
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* import { DESCRIBE } from "ldkit/sparql";
|
|
94
|
+
* import { DataFactory } from "ldkit/rdf";
|
|
95
|
+
*
|
|
96
|
+
* const df = new DataFactory();
|
|
97
|
+
* const node = df.namedNode("http://example.org/resource");
|
|
98
|
+
*
|
|
99
|
+
* const query = DESCRIBE`${node}`.build();
|
|
100
|
+
* console.log(query); // DESCRIBE <http://example.org/resource>
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export declare const DESCRIBE: (strings: TemplateStringsArray, ...values: SparqlValue[]) => Builders<"build" | "WHERE" | "FROM_NAMED" | "FROM">;
|
|
39
104
|
export {};
|
|
@@ -2,6 +2,7 @@ import { DataFactory, RDF } from "../rdf.js";
|
|
|
2
2
|
import { type SparqlValue } from "./sparql_tag.js";
|
|
3
3
|
type Wrap = (keyword: string, value: string) => string;
|
|
4
4
|
export declare const braces: Wrap;
|
|
5
|
+
export declare const bracesInline: Wrap;
|
|
5
6
|
export declare const parentheses: Wrap;
|
|
6
7
|
export declare abstract class SparqlBuilder {
|
|
7
8
|
protected value: string;
|
|
@@ -1,3 +1,31 @@
|
|
|
1
1
|
import { type RDF } from "../rdf.js";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Any value that can be used in LDkit SPARQL builders
|
|
4
|
+
*/
|
|
5
|
+
export type SparqlValue = RDF.Term | string | number | boolean | Date | Iterable<SparqlValue> | {
|
|
6
|
+
build: () => string;
|
|
7
|
+
} | null | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* A template tag for SPARQL queries or its parts. Automatically converts
|
|
10
|
+
* values to SPARQL literals and escapes strings as needed.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { sparql } from "ldkit/sparql";
|
|
15
|
+
* import { DataFactory } from "ldkit/rdf";
|
|
16
|
+
*
|
|
17
|
+
* const df = new DataFactory();
|
|
18
|
+
* const quad = df.quad(
|
|
19
|
+
* df.namedNode("http://example.org/s"),
|
|
20
|
+
* df.namedNode("http://example.org/p"),
|
|
21
|
+
* df.literal("o"),
|
|
22
|
+
* );
|
|
23
|
+
* const query = sparql`SELECT * WHERE { ${quad} }`;
|
|
24
|
+
* console.log(query); // SELECT * WHERE { <http://example.org/s> <http://example.org/p> "o" . }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @param strings {TemplateStringsArray} template strings
|
|
28
|
+
* @param values {SparqlValue[]}
|
|
29
|
+
* @returns {string} SPARQL query or its part
|
|
30
|
+
*/
|
|
3
31
|
export declare const sparql: (strings: TemplateStringsArray, ...values: SparqlValue[]) => string;
|
|
@@ -10,13 +10,81 @@ declare class SparqlUpdateBuilder extends SparqlBuilder {
|
|
|
10
10
|
INSERT_DATA(strings: TemplateStringsArray, ...values: SparqlValue[]): Builders<"build">;
|
|
11
11
|
DELETE(strings: TemplateStringsArray, ...values: SparqlValue[]): Builders<"INSERT" | "USING" | "USING_NAMED" | "WHERE">;
|
|
12
12
|
DELETE_DATA(strings: TemplateStringsArray, ...values: SparqlValue[]): Builders<"build">;
|
|
13
|
+
DELETE_WHERE(strings: TemplateStringsArray, ...values: SparqlValue[]): Builders<"build">;
|
|
13
14
|
WITH(stringOrNamedNode: string | RDF.NamedNode<string>): Builders<"INSERT" | "DELETE">;
|
|
14
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* SPARQL INSERT query fluent interface
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { INSERT } from "ldkit/sparql";
|
|
22
|
+
* import { foaf } from "ldkit/namespaces";
|
|
23
|
+
* import { DataFactory } from "ldkit/rdf";
|
|
24
|
+
*
|
|
25
|
+
* const df = new DataFactory();
|
|
26
|
+
* const firstName = df.namedNode(foaf.firstName);
|
|
27
|
+
*
|
|
28
|
+
* const query = INSERT`?person ${firstName} "Paul"`
|
|
29
|
+
* .WHERE`?person ${firstName} "Jean"`
|
|
30
|
+
* .build();
|
|
31
|
+
* console.log(query);
|
|
32
|
+
* // INSERT { ?person <http://xmlns.com/foaf/0.1/firstName> "Paul" }
|
|
33
|
+
* // WHERE { ?person <http://xmlns.com/foaf/0.1/firstName> "Jean" }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
15
36
|
export declare const INSERT: ((strings: TemplateStringsArray, ...values: SparqlValue[]) => Builders<"WHERE" | "USING_NAMED" | "USING">) & {
|
|
16
37
|
DATA: (strings: TemplateStringsArray, ...values: SparqlValue[]) => Builders<"build">;
|
|
17
38
|
};
|
|
39
|
+
/**
|
|
40
|
+
* SPARQL DELETE query fluent interface
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* import { DELETE } from "ldkit/sparql";
|
|
45
|
+
* import { foaf } from "ldkit/namespaces";
|
|
46
|
+
* import { DataFactory } from "ldkit/rdf";
|
|
47
|
+
*
|
|
48
|
+
* const df = new DataFactory();
|
|
49
|
+
* const firstName = df.namedNode(foaf.firstName);
|
|
50
|
+
*
|
|
51
|
+
* const query = DELETE`?person ${firstName} "Jean"`
|
|
52
|
+
* .INSERT`?person ${firstName} "Paul"`
|
|
53
|
+
* .WHERE`?person ${firstName} "Jean"`
|
|
54
|
+
* .build();
|
|
55
|
+
* console.log(query);
|
|
56
|
+
* // DELETE { ?person <http://xmlns.com/foaf/0.1/firstName> "Jean" }
|
|
57
|
+
* // INSERT { ?person <http://xmlns.com/foaf/0.1/firstName> "Paul" }
|
|
58
|
+
* // WHERE { ?person <http://xmlns.com/foaf/0.1/firstName> "Jean" }
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
18
61
|
export declare const DELETE: ((strings: TemplateStringsArray, ...values: SparqlValue[]) => Builders<"WHERE" | "USING_NAMED" | "USING" | "INSERT">) & {
|
|
19
62
|
DATA: (strings: TemplateStringsArray, ...values: SparqlValue[]) => Builders<"build">;
|
|
63
|
+
WHERE: (strings: TemplateStringsArray, ...values: SparqlValue[]) => Builders<"build">;
|
|
20
64
|
};
|
|
65
|
+
/**
|
|
66
|
+
* SPARQL WITH query fluent interface
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* import { DELETE } from "ldkit/sparql";
|
|
71
|
+
* import { foaf } from "ldkit/namespaces";
|
|
72
|
+
* import { DataFactory } from "ldkit/rdf";
|
|
73
|
+
*
|
|
74
|
+
* const df = new DataFactory();
|
|
75
|
+
* const firstName = df.namedNode(foaf.firstName);
|
|
76
|
+
* const graph = df.namedNode("http://example.org/graph");
|
|
77
|
+
*
|
|
78
|
+
* const query = WITH(graph).DELETE`?person ${firstName} "Jean"`
|
|
79
|
+
* .INSERT`?person ${firstName} "Paul"`
|
|
80
|
+
* .WHERE`?person ${firstName} "Jean"`
|
|
81
|
+
* .build();
|
|
82
|
+
* console.log(query);
|
|
83
|
+
* // WITH <http://example.org/graph>
|
|
84
|
+
* // DELETE { ?person <http://xmlns.com/foaf/0.1/firstName> "Jean" }
|
|
85
|
+
* // INSERT { ?person <http://xmlns.com/foaf/0.1/firstName> "Paul" }
|
|
86
|
+
* // WHERE { ?person <http://xmlns.com/foaf/0.1/firstName> "Jean" }
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
21
89
|
export declare const WITH: (stringOrNamedNode: string | RDF.NamedNode<string>) => Builders<"INSERT" | "DELETE">;
|
|
22
90
|
export {};
|
package/types/mod.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export { type
|
|
2
|
-
export {
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export { QueryEngine } from "./library/engine/mod.js";
|
|
1
|
+
export { type Options, setGlobalOptions } from "./library/options.js";
|
|
2
|
+
export type { Identity, Property, Schema, SchemaInterface, SchemaSearchInterface, SchemaUpdateInterface, SupportedDataTypes, } from "./library/schema/mod.js";
|
|
3
|
+
export * from "./library/lens/mod.js";
|
|
4
|
+
export * from "./library/namespace.js";
|
|
5
|
+
export * from "./library/engine/mod.js";
|