rdflib 2.2.10 → 2.2.12-5f141ca2

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.
Files changed (190) hide show
  1. package/.babelrc +0 -0
  2. package/README.md +1 -0
  3. package/changes.txt +0 -0
  4. package/dist/rdflib.min.js +62 -0
  5. package/dist/rdflib.min.js.map +1 -0
  6. package/esm/blank-node.js +137 -0
  7. package/esm/class-order.js +12 -0
  8. package/esm/collection.js +173 -0
  9. package/esm/convert.js +61 -0
  10. package/esm/default-graph.js +57 -0
  11. package/esm/empty.js +46 -0
  12. package/esm/factories/canonical-data-factory.js +204 -0
  13. package/esm/factories/extended-term-factory.js +55 -0
  14. package/esm/factories/factory-types.js +18 -0
  15. package/esm/factories/rdflib-data-factory.js +55 -0
  16. package/esm/fetcher.js +2180 -0
  17. package/esm/formula.js +987 -0
  18. package/esm/index.js +64 -0
  19. package/esm/jsonldparser.js +122 -0
  20. package/esm/jsonparser.js +60 -0
  21. package/esm/literal.js +236 -0
  22. package/esm/log.js +13 -0
  23. package/esm/n3parser.js +1854 -0
  24. package/esm/named-node.js +154 -0
  25. package/esm/namespace.js +17 -0
  26. package/esm/node-internal.js +151 -0
  27. package/esm/node.js +46 -0
  28. package/esm/parse.js +138 -0
  29. package/esm/patch-parser.js +110 -0
  30. package/esm/query-to-sparql.js +83 -0
  31. package/esm/query.js +620 -0
  32. package/esm/rdfaparser.js +1197 -0
  33. package/esm/rdfxmlparser.js +588 -0
  34. package/esm/serialize.js +95 -0
  35. package/esm/serializer.js +1162 -0
  36. package/esm/sparql-to-query.js +566 -0
  37. package/esm/statement.js +128 -0
  38. package/esm/store.js +1306 -0
  39. package/esm/tf-types.js +1 -0
  40. package/esm/types.js +25 -0
  41. package/esm/update-manager.js +1252 -0
  42. package/esm/updates-via.js +197 -0
  43. package/esm/uri.js +245 -0
  44. package/esm/utils/default-graph-uri.js +4 -0
  45. package/esm/utils/termValue.js +8 -0
  46. package/esm/utils/terms.js +72 -0
  47. package/esm/utils-js.js +348 -0
  48. package/esm/utils.js +103 -0
  49. package/esm/variable.js +101 -0
  50. package/esm/xsd-internal.js +10 -0
  51. package/esm/xsd.js +15 -0
  52. package/lib/blank-node.d.ts +44 -0
  53. package/lib/blank-node.js +0 -0
  54. package/lib/class-order.d.ts +7 -0
  55. package/lib/class-order.js +0 -0
  56. package/lib/collection.d.ts +65 -0
  57. package/lib/collection.js +0 -0
  58. package/lib/convert.d.ts +2 -0
  59. package/lib/convert.js +0 -0
  60. package/lib/default-graph.d.ts +13 -0
  61. package/lib/default-graph.js +0 -0
  62. package/lib/empty.d.ts +11 -0
  63. package/lib/empty.js +0 -0
  64. package/lib/factories/canonical-data-factory.d.ts +6 -0
  65. package/lib/factories/canonical-data-factory.js +0 -0
  66. package/lib/factories/extended-term-factory.d.ts +13 -0
  67. package/lib/factories/extended-term-factory.js +0 -0
  68. package/lib/factories/factory-types.d.ts +67 -0
  69. package/lib/factories/factory-types.js +0 -0
  70. package/lib/factories/rdflib-data-factory.d.ts +4 -0
  71. package/lib/factories/rdflib-data-factory.js +0 -0
  72. package/lib/fetcher.d.ts +443 -0
  73. package/lib/fetcher.js +3 -2
  74. package/lib/formula.d.ts +327 -0
  75. package/lib/formula.js +0 -0
  76. package/lib/index.d.ts +40 -0
  77. package/lib/index.js +0 -0
  78. package/lib/jsonldparser.d.ts +13 -0
  79. package/lib/jsonldparser.js +0 -0
  80. package/lib/jsonparser.d.ts +4 -0
  81. package/lib/jsonparser.js +0 -0
  82. package/lib/literal.d.ts +67 -0
  83. package/lib/literal.js +0 -0
  84. package/lib/log.d.ts +15 -0
  85. package/lib/log.js +0 -0
  86. package/lib/n3parser.d.ts +62 -0
  87. package/lib/n3parser.js +1334 -1289
  88. package/lib/named-node.d.ts +44 -0
  89. package/lib/named-node.js +0 -0
  90. package/lib/namespace.d.ts +7 -0
  91. package/lib/namespace.js +0 -0
  92. package/lib/node-internal.d.ts +63 -0
  93. package/lib/node-internal.js +0 -0
  94. package/lib/node.d.ts +2 -0
  95. package/lib/node.js +0 -0
  96. package/lib/parse.d.ts +16 -0
  97. package/lib/parse.js +0 -0
  98. package/lib/patch-parser.d.ts +3 -0
  99. package/lib/patch-parser.js +0 -0
  100. package/lib/query-to-sparql.d.ts +1 -0
  101. package/lib/query-to-sparql.js +0 -0
  102. package/lib/query.d.ts +27 -0
  103. package/lib/query.js +0 -0
  104. package/lib/rdfaparser.d.ts +78 -0
  105. package/lib/rdfaparser.js +0 -0
  106. package/lib/rdfxmlparser.d.ts +60 -0
  107. package/lib/rdfxmlparser.js +430 -413
  108. package/lib/serialize.d.ts +23 -0
  109. package/lib/serialize.js +1 -1
  110. package/lib/serializer.d.ts +54 -0
  111. package/lib/serializer.js +851 -824
  112. package/lib/sparql-to-query.d.ts +6 -0
  113. package/lib/sparql-to-query.js +0 -0
  114. package/lib/statement.d.ts +55 -0
  115. package/lib/statement.js +0 -0
  116. package/lib/store.d.ts +302 -0
  117. package/lib/store.js +0 -0
  118. package/lib/tf-types.d.ts +151 -0
  119. package/lib/tf-types.js +0 -0
  120. package/lib/types.d.ts +68 -0
  121. package/lib/types.js +0 -0
  122. package/lib/update-manager.d.ts +198 -0
  123. package/lib/update-manager.js +0 -0
  124. package/lib/updates-via.d.ts +26 -0
  125. package/lib/updates-via.js +0 -0
  126. package/lib/uri.d.ts +33 -0
  127. package/lib/uri.js +0 -0
  128. package/lib/utils/default-graph-uri.d.ts +3 -0
  129. package/lib/utils/default-graph-uri.js +0 -0
  130. package/lib/utils/termValue.d.ts +3 -0
  131. package/lib/utils/termValue.js +0 -0
  132. package/lib/utils/terms.d.ts +33 -0
  133. package/lib/utils/terms.js +0 -0
  134. package/lib/utils-js.d.ts +50 -0
  135. package/lib/utils-js.js +0 -0
  136. package/lib/utils.d.ts +20 -0
  137. package/lib/utils.js +0 -0
  138. package/lib/variable.d.ts +29 -0
  139. package/lib/variable.js +0 -0
  140. package/lib/xsd-internal.d.ts +11 -0
  141. package/lib/xsd-internal.js +0 -0
  142. package/lib/xsd.d.ts +19 -0
  143. package/lib/xsd.js +8 -14
  144. package/package.json +3 -3
  145. package/src/blank-node.ts +0 -0
  146. package/src/class-order.ts +0 -0
  147. package/src/collection.ts +0 -0
  148. package/src/convert.js +0 -0
  149. package/src/default-graph.ts +0 -0
  150. package/src/empty.ts +0 -0
  151. package/src/factories/canonical-data-factory.ts +0 -0
  152. package/src/factories/extended-term-factory.ts +0 -0
  153. package/src/factories/factory-types.ts +0 -0
  154. package/src/factories/rdflib-data-factory.ts +0 -0
  155. package/src/fetcher.ts +6 -3
  156. package/src/formula.ts +0 -0
  157. package/src/index.ts +0 -0
  158. package/src/jsonldparser.js +0 -0
  159. package/src/jsonparser.js +0 -0
  160. package/src/literal.ts +0 -0
  161. package/src/log.js +0 -0
  162. package/src/n3parser.js +1114 -1110
  163. package/src/named-node.ts +0 -0
  164. package/src/namespace.ts +0 -0
  165. package/src/node-internal.ts +0 -0
  166. package/src/node.ts +0 -0
  167. package/src/parse.ts +0 -0
  168. package/src/patch-parser.js +0 -0
  169. package/src/query-to-sparql.js +0 -0
  170. package/src/query.js +0 -0
  171. package/src/rdfaparser.js +0 -0
  172. package/src/rdfxmlparser.js +22 -21
  173. package/src/serialize.ts +3 -3
  174. package/src/serializer.js +74 -62
  175. package/src/sparql-to-query.js +0 -0
  176. package/src/statement.ts +0 -0
  177. package/src/store.ts +0 -0
  178. package/src/tf-types.ts +0 -0
  179. package/src/types.ts +0 -0
  180. package/src/update-manager.ts +0 -0
  181. package/src/updates-via.js +0 -0
  182. package/src/uri.ts +0 -0
  183. package/src/utils/default-graph-uri.ts +0 -0
  184. package/src/utils/termValue.ts +0 -0
  185. package/src/utils/terms.ts +0 -0
  186. package/src/utils-js.js +0 -0
  187. package/src/utils.ts +0 -0
  188. package/src/variable.ts +0 -0
  189. package/src/xsd-internal.js +0 -0
  190. package/src/xsd.js +16 -14
@@ -0,0 +1,65 @@
1
+ import RdflibBlankNode from './blank-node';
2
+ import Literal from './literal';
3
+ import Node from './node-internal';
4
+ import { Bindings, CollectionTermType, FromValueReturns, ValueType } from './types';
5
+ import Variable from './variable';
6
+ import { Term } from './tf-types';
7
+ /**
8
+ * Creates an RDF Node from a native javascript value.
9
+ * RDF Nodes are returned unchanged, undefined returned as itself.
10
+ * Arrays return Collections.
11
+ * Strings, numbers and booleans return Literals.
12
+ * @param value {Node|Date|String|Number|Boolean|Undefined}
13
+ * @return {Node|Collection}
14
+ */
15
+ export declare function fromValue<T extends FromValueReturns<C> = any, C extends Node = any>(value: ValueType): T;
16
+ /**
17
+ * A collection of other RDF nodes
18
+ *
19
+ * Use generic T to control the contents of the array.
20
+ */
21
+ export default class Collection<T extends Node = Node | RdflibBlankNode | Collection<any> | Literal | Variable> extends Node implements Term {
22
+ static termType: typeof CollectionTermType;
23
+ termType: typeof CollectionTermType;
24
+ classOrder: number;
25
+ closed: boolean;
26
+ compareTerm: (other: RdflibBlankNode) => number;
27
+ /**
28
+ * The nodes in this collection
29
+ */
30
+ elements: T[];
31
+ isVar: number;
32
+ constructor(initial?: ReadonlyArray<ValueType>);
33
+ get id(): string;
34
+ set id(value: string);
35
+ /**
36
+ * Appends an element to this collection
37
+ * @param element - The new element
38
+ */
39
+ append(element: T): number;
40
+ /**
41
+ * Closes this collection
42
+ */
43
+ close(): boolean;
44
+ /**
45
+ * Removes the first element from the collection (and return it)
46
+ */
47
+ shift(): T | undefined;
48
+ /**
49
+ * Creates a new Collection with the substituting bindings applied
50
+ * @param bindings - The bindings to substitute
51
+ */
52
+ substitute(bindings: Bindings): any;
53
+ toNT(): string;
54
+ static toNT(collection: any): string;
55
+ /**
56
+ * Serializes the collection to a string.
57
+ * Surrounded by (parentheses) and separated by spaces.
58
+ */
59
+ toString(): string;
60
+ /**
61
+ * Prepends the specified element to the collection's front
62
+ * @param element - The element to prepend
63
+ */
64
+ unshift(element: T): number;
65
+ }
package/lib/collection.js CHANGED
File without changes
@@ -0,0 +1,2 @@
1
+ export function convertToJson(n3String: any, jsonCallback: any): void;
2
+ export function convertToNQuads(n3String: any, nquadCallback: any): void;
package/lib/convert.js CHANGED
File without changes
@@ -0,0 +1,13 @@
1
+ import Node from './node-internal';
2
+ import { DefaultGraphTermType } from './types';
3
+ import { DefaultGraph as TFDefaultGraph } from './tf-types';
4
+ /** The RDF default graph */
5
+ export default class DefaultGraph extends Node implements TFDefaultGraph {
6
+ value: '';
7
+ termType: typeof DefaultGraphTermType;
8
+ uri: string;
9
+ constructor();
10
+ toCanonical(): "";
11
+ toString(): string;
12
+ }
13
+ export declare function isDefaultGraph(object: any): object is DefaultGraph;
File without changes
package/lib/empty.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import Node from './node-internal';
2
+ import { EmptyTermType } from './types';
3
+ import { Term } from './tf-types';
4
+ /**
5
+ * An empty node
6
+ */
7
+ export default class Empty extends Node implements Term {
8
+ termType: typeof EmptyTermType;
9
+ constructor();
10
+ toString(): string;
11
+ }
package/lib/empty.js CHANGED
File without changes
@@ -0,0 +1,6 @@
1
+ import { DataFactory } from './factory-types';
2
+ export { defaultGraphURI } from '../utils/default-graph-uri';
3
+ /** A basic internal RDFlib datafactory, which does not support Collections */
4
+ declare const CanonicalDataFactory: DataFactory;
5
+ /** Contains the factory methods as defined in the spec, plus id */
6
+ export default CanonicalDataFactory;
File without changes
@@ -0,0 +1,13 @@
1
+ import Collection from '../collection';
2
+ import { ValueType } from '../types';
3
+ import { DataFactory } from './factory-types';
4
+ interface CollectionFactory extends DataFactory {
5
+ collection(elements: ReadonlyArray<ValueType>): Collection;
6
+ }
7
+ /**
8
+ * Data factory which also supports Collections
9
+ *
10
+ * Necessary for preventing circular dependencies.
11
+ */
12
+ declare const ExtendedTermFactory: CollectionFactory;
13
+ export default ExtendedTermFactory;
File without changes
@@ -0,0 +1,67 @@
1
+ import Literal from '../literal';
2
+ import Statement from '../statement';
3
+ import NamedNode from '../named-node';
4
+ import BlankNode from '../blank-node';
5
+ import Variable from '../variable';
6
+ import DefaultGraph from '../default-graph';
7
+ import { BlankNode as TFBlankNode, RdfJsDataFactory, Literal as TFLiteral, NamedNode as TFNamedNode, Quad, Term, Variable as TFVariable } from '../tf-types';
8
+ export declare type Comparable = Term | TFNamedNode | TFBlankNode | TFLiteral | Quad | undefined | null;
9
+ export declare type DefaultFactoryTypes = NamedNode | BlankNode | Literal | Variable | Statement;
10
+ export declare type Indexable = number | string;
11
+ export declare type Namespace = (term: string) => TFNamedNode;
12
+ /** A set of features that may be supported by a Data Factory */
13
+ export declare type SupportTable = Record<Feature, boolean>;
14
+ export declare type TFIDFactoryTypes = TFNamedNode | TFBlankNode | TFLiteral | Quad | TFVariable | Term;
15
+ export declare enum Feature {
16
+ /** Whether the factory supports termType:Collection terms */
17
+ collections = "COLLECTIONS",
18
+ /** Whether the factory supports termType:DefaultGraph terms */
19
+ defaultGraphType = "DEFAULT_GRAPH_TYPE",
20
+ /** Whether the factory supports equals on produced instances */
21
+ equalsMethod = "EQUALS_METHOD",
22
+ /** Whether the factory can create a unique idempotent identifier for the given term. */
23
+ id = "ID",
24
+ /**
25
+ * Whether the factory will return the same instance for subsequent calls.
26
+ * This implies `===`, which means methods like `indexOf` can be used.
27
+ */
28
+ identity = "IDENTITY",
29
+ /** Whether the factory supports mapping ids back to instances (should adhere to the identity setting) */
30
+ reversibleId = "REVERSIBLE_ID",
31
+ /** Whether the factory supports termType:Variable terms */
32
+ variableType = "VARIABLE_TYPE"
33
+ }
34
+ /**
35
+ * Defines a DataFactory as used in rdflib, based on the RDF/JS: Data model specification,
36
+ * but with additional extensions
37
+ *
38
+ * bnIndex is optional but useful.
39
+ */
40
+ export interface DataFactory<FactoryTypes = DefaultFactoryTypes, IndexType = Indexable> extends RdfJsDataFactory {
41
+ /**
42
+ * BlankNode index
43
+ * @private
44
+ */
45
+ bnIndex?: number;
46
+ supports: SupportTable;
47
+ namedNode(value: string): NamedNode;
48
+ blankNode(value?: string): BlankNode;
49
+ literal(value: string, languageOrDatatype?: string | TFNamedNode): Literal;
50
+ variable(value: string): Variable;
51
+ defaultGraph(): DefaultGraph;
52
+ isQuad(obj: any): obj is Statement;
53
+ equals(a: Comparable, b: Comparable): boolean;
54
+ toNQ(term: Term | FactoryTypes): string;
55
+ quad(subject: Term, predicate: Term, object: Term, graph?: Term): Statement;
56
+ quadToNQ(term: Statement | Quad): string;
57
+ termToNQ(term: Term): string;
58
+ /**
59
+ * Generates a unique session-idempotent identifier for the given object.
60
+ *
61
+ * @example NQ serialization (reversible from value)
62
+ * @example MD5 hash of termType + value (irreversible from value, map needed)
63
+ *
64
+ * @return {Indexable} A unique value which must also be a valid JS object key type.
65
+ */
66
+ id(obj: Term | FactoryTypes): IndexType;
67
+ }
File without changes
@@ -0,0 +1,4 @@
1
+ import { IRDFlibDataFactory } from '../types';
2
+ /** Full RDFLib.js Data Factory */
3
+ declare const RDFlibDataFactory: IRDFlibDataFactory;
4
+ export default RDFlibDataFactory;
File without changes
@@ -0,0 +1,443 @@
1
+ /**
2
+ *
3
+ * Project: rdflib.js
4
+ *
5
+ * @file: fetcher.js
6
+ *
7
+ * Description: contains functions for requesting/fetching/retracting
8
+ * This implements quite a lot of the web architecture.
9
+ * A fetcher is bound to a specific quad store, into which
10
+ * it loads stuff and into which it writes its metadata
11
+ * @@ The metadata could be optionally a separate graph
12
+ *
13
+ * - implements semantics of HTTP headers, Internet Content Types
14
+ * - selects parsers for rdf/xml, n3, rdfa, grddl
15
+ *
16
+ * TO do:
17
+ * - Implement a runtime registry for parsers and serializers
18
+ * -
19
+ */
20
+ /**
21
+ * Things to test: callbacks on request, refresh, retract
22
+ * loading from HTTP, HTTPS, FTP, FILE, others?
23
+ * To do:
24
+ * Firing up a mail client for mid: (message:) URLs
25
+ */
26
+ import IndexedFormula from './store';
27
+ import RDFlibNamedNode from './named-node';
28
+ import { ContentType } from './types';
29
+ import { BlankNode, Quad_Graph, NamedNode, Quad_Predicate, Quad_Subject } from './tf-types';
30
+ export interface FetchError extends Error {
31
+ statusText?: string;
32
+ status?: StatusValues;
33
+ response?: ExtendedResponse;
34
+ }
35
+ /** An extended interface of Response, since RDFlib.js adds some properties. */
36
+ export interface ExtendedResponse extends Response {
37
+ /** String representation of the Body */
38
+ responseText?: string;
39
+ /** Identifier of the reqest */
40
+ req?: Quad_Subject;
41
+ size?: number;
42
+ timeout?: number;
43
+ /** Used in UpdateManager.updateDav */
44
+ error?: string;
45
+ }
46
+ /** tell typescript that a 'panes' child may exist on Window */
47
+ declare global {
48
+ interface Window {
49
+ panes?: any;
50
+ solidFetcher?: any;
51
+ solidFetch?: any;
52
+ }
53
+ var solidFetcher: Function;
54
+ var solidFetch: Function;
55
+ }
56
+ declare type UserCallback = (ok: boolean, message: string, response?: any) => void;
57
+ declare type HTTPMethods = 'GET' | 'PUT' | 'POST' | 'PATCH' | 'HEAD' | 'DELETE' | 'CONNECT' | 'TRACE' | 'OPTIONS';
58
+ /** All valid inputs for initFetchOptions */
59
+ declare type Options = Partial<AutoInitOptions>;
60
+ /** Initiated by initFetchOptions, which runs on load */
61
+ export interface AutoInitOptions extends RequestInit {
62
+ /** The used Fetch function */
63
+ fetch?: Fetch;
64
+ /**
65
+ * Referring term, the resource which
66
+ * referred to this (for tracking bad links).
67
+ * The document in which this link was found.
68
+ */
69
+ referringTerm?: NamedNode;
70
+ /** Provided content type (for writes) */
71
+ contentType?: string;
72
+ /**
73
+ * Override the incoming header to
74
+ * force the data to be treated as this content-type (for reads)
75
+ */
76
+ forceContentType?: ContentType;
77
+ /**
78
+ * Load the data even if loaded before.
79
+ * Also sets the `Cache-Control:` header to `no-cache`
80
+ */
81
+ force?: boolean;
82
+ /**
83
+ * Original uri to preserve
84
+ * through proxying etc (`xhr.original`).
85
+ */
86
+ baseURI: string;
87
+ /**
88
+ * Whether this request is a retry via
89
+ * a proxy (generally done from an error handler)
90
+ */
91
+ proxyUsed?: boolean;
92
+ actualProxyURI?: string;
93
+ /** flag for XHR/CORS etc */
94
+ withCredentials?: boolean;
95
+ /** Before we parse new data, clear old, but only on status 200 responses */
96
+ clearPreviousData?: boolean;
97
+ /** Prevents the addition of various metadata triples (about the fetch request) to the store*/
98
+ noMeta?: boolean;
99
+ noRDFa?: boolean;
100
+ handlers?: Handler[];
101
+ timeout?: number;
102
+ method?: HTTPMethods;
103
+ retriedWithNoCredentials?: boolean;
104
+ requestedURI?: string;
105
+ resource: Quad_Subject;
106
+ /** The serialized resource in the body*/
107
+ original: NamedNode;
108
+ data?: string;
109
+ req: BlankNode;
110
+ body?: string;
111
+ headers: HeadersInit;
112
+ credentials?: 'include' | 'omit';
113
+ }
114
+ declare class Handler {
115
+ response: ExtendedResponse;
116
+ dom: Document;
117
+ static pattern: RegExp;
118
+ constructor(response: ExtendedResponse, dom?: Document);
119
+ }
120
+ declare type StatusValues =
121
+ /** No record of web access or record reset */
122
+ undefined |
123
+ /** Has been requested, fetch in progress */
124
+ true |
125
+ /** Received, OK */
126
+ 'done' |
127
+ /** Not logged in */
128
+ 401 |
129
+ /** HTTP status unauthorized */
130
+ 403 |
131
+ /** Not found, resource does not exist */
132
+ 404 |
133
+ /** In attempt to counter CORS problems retried */
134
+ 'redirected' |
135
+ /** If it did fail */
136
+ 'failed' | 'parse_error' |
137
+ /**
138
+ * URI is not a protocol Fetcher can deal with
139
+ * other strings mean various other errors.
140
+ */
141
+ 'unsupported_protocol' | 'timeout' |
142
+ /** Any other HTTP status code */
143
+ number;
144
+ interface MediatypesMap {
145
+ [id: string]: {
146
+ 'q'?: number | string;
147
+ };
148
+ }
149
+ interface RequestedMap {
150
+ [uri: string]: StatusValues;
151
+ }
152
+ interface TimeOutsMap {
153
+ [uri: string]: number[];
154
+ }
155
+ interface FetchQueue {
156
+ [uri: string]: Promise<ExtendedResponse>;
157
+ }
158
+ interface FetchCallbacks {
159
+ [uri: string]: UserCallback[];
160
+ }
161
+ interface BooleanMap {
162
+ [uri: string]: boolean;
163
+ }
164
+ declare type Result = Response;
165
+ /** Differs from normal Fetch, has an extended Response type */
166
+ declare type Fetch = (input: RequestInfo, init?: RequestInit) => Promise<ExtendedResponse>;
167
+ interface CallbackifyInterface {
168
+ fireCallbacks: Function;
169
+ }
170
+ /** Fetcher
171
+ *
172
+ * The Fetcher object is a helper object for a quadstore
173
+ * which turns it from an offline store to an online store.
174
+ * The fetcher deals with loading data files rom the web,
175
+ * figuring how to parse them. It will also refresh, remove, the data
176
+ * and put back the data to the web.
177
+ */
178
+ export default class Fetcher implements CallbackifyInterface {
179
+ store: IndexedFormula;
180
+ timeout: number;
181
+ _fetch: Fetch;
182
+ mediatypes: MediatypesMap;
183
+ /** Denoting this session */
184
+ appNode: BlankNode;
185
+ /**
186
+ * this.requested[uri] states:
187
+ * undefined no record of web access or records reset
188
+ * true has been requested, fetch in progress
189
+ * 'done' received, Ok
190
+ * 401 Not logged in
191
+ * 403 HTTP status unauthorized
192
+ * 404 Resource does not exist. Can be created etc.
193
+ * 'redirected' In attempt to counter CORS problems retried.
194
+ * 'parse_error' Parse error
195
+ * 'unsupported_protocol' URI is not a protocol Fetcher can deal with
196
+ * other strings mean various other errors.
197
+ */
198
+ requested: RequestedMap;
199
+ /** List of timeouts associated with a requested URL */
200
+ timeouts: TimeOutsMap;
201
+ /** Redirected from *key uri* to *value uri* */
202
+ redirectedTo: Record<string, string>;
203
+ fetchQueue: FetchQueue;
204
+ /** fetchCallbacks[uri].push(callback) */
205
+ fetchCallbacks: FetchCallbacks;
206
+ /** Keep track of explicit 404s -> we can overwrite etc */
207
+ nonexistent: BooleanMap;
208
+ lookedUp: BooleanMap;
209
+ handlers: Array<typeof Handler>;
210
+ ns: {
211
+ [k: string]: (ln: string) => Quad_Predicate;
212
+ };
213
+ static HANDLERS: {
214
+ [handlerName: number]: Handler;
215
+ };
216
+ static CONTENT_TYPE_BY_EXT: Record<string, string>;
217
+ static crossSiteProxyTemplate: any;
218
+ /** Methods added by calling Util.callbackify in the constructor*/
219
+ fireCallbacks: Function;
220
+ constructor(store: IndexedFormula, options?: Options);
221
+ static crossSiteProxy(uri: string): undefined | any;
222
+ static offlineOverride(uri: string): string;
223
+ static proxyIfNecessary(uri: string): any;
224
+ /**
225
+ * Tests whether the uri's protocol is supported by the Fetcher.
226
+ * @param uri
227
+ */
228
+ static unsupportedProtocol(uri: string): boolean;
229
+ /** Decide on credentials using old XXHR api or new fetch() one
230
+ * @param requestedURI
231
+ * @param options
232
+ */
233
+ static setCredentials(requestedURI: string, options?: Options): void;
234
+ /**
235
+ * Promise-based load function
236
+ *
237
+ * Loads a web resource or resources into the store.
238
+ *
239
+ * A resource may be given as NamedNode object, or as a plain URI.
240
+ * an array of resources will be given, in which they will be fetched in parallel.
241
+ * By default, the HTTP headers are recorded also, in the same store, in a separate graph.
242
+ * This allows code like editable() for example to test things about the resource.
243
+ *
244
+ * @param uri {Array<RDFlibNamedNode>|Array<string>|RDFlibNamedNode|string}
245
+ *
246
+ * @param [options={}] {Object}
247
+ *
248
+ * @param [options.fetch] {Function}
249
+ *
250
+ * @param [options.referringTerm] {RDFlibNamedNode} Referring term, the resource which
251
+ * referred to this (for tracking bad links)
252
+ *
253
+ * @param [options.contentType] {string} Provided content type (for writes)
254
+ *
255
+ * @param [options.forceContentType] {string} Override the incoming header to
256
+ * force the data to be treated as this content-type (for reads)
257
+ *
258
+ * @param [options.force] {boolean} Load the data even if loaded before.
259
+ * Also sets the `Cache-Control:` header to `no-cache`
260
+ *
261
+ * @param [options.baseURI=docuri] {Node|string} Original uri to preserve
262
+ * through proxying etc (`xhr.original`).
263
+ *
264
+ * @param [options.proxyUsed] {boolean} Whether this request is a retry via
265
+ * a proxy (generally done from an error handler)
266
+ *
267
+ * @param [options.withCredentials] {boolean} flag for XHR/CORS etc
268
+ *
269
+ * @param [options.clearPreviousData] {boolean} Before we parse new data,
270
+ * clear old, but only on status 200 responses
271
+ *
272
+ * @param [options.noMeta] {boolean} Prevents the addition of various metadata
273
+ * triples (about the fetch request) to the store
274
+ *
275
+ * @param [options.noRDFa] {boolean}
276
+ *
277
+ * @returns {Promise<Result>}
278
+ */
279
+ load<T extends NamedNode | string | Array<string | NamedNode>>(uri: T, options?: Options): T extends Array<string | NamedNode> ? Promise<Result[]> : Promise<Result>;
280
+ pendingFetchPromise(uri: string, originalUri: string, options: AutoInitOptions): Promise<Result>;
281
+ /**
282
+ * @param _options - DEPRECATED
283
+ */
284
+ cleanupFetchRequest(originalUri: string, _options: any, timeout: number): void;
285
+ initFetchOptions(uri: string, options: Options): AutoInitOptions;
286
+ /**
287
+ * (The promise chain ends in either a `failFetch()` or a `doneFetch()`)
288
+ *
289
+ * @param docuri {string}
290
+ * @param options {Object}
291
+ *
292
+ * @returns {Promise<Object>} fetch() result or an { error, status } object
293
+ */
294
+ fetchUri(docuri: string, options: AutoInitOptions): Promise<ExtendedResponse | FetchError>;
295
+ /**
296
+ * Asks for a doc to be loaded if necessary then calls back
297
+ *
298
+ * Calling methods:
299
+ * nowOrWhenFetched (uri, userCallback)
300
+ * nowOrWhenFetched (uri, options, userCallback)
301
+ * nowOrWhenFetched (uri, referringTerm, userCallback, options) <-- old
302
+ * nowOrWhenFetched (uri, referringTerm, userCallback) <-- old
303
+ *
304
+ * Options include:
305
+ * referringTerm The document in which this link was found.
306
+ * this is valuable when finding the source of bad URIs
307
+ * force boolean. Never mind whether you have tried before,
308
+ * load this from scratch.
309
+ * forceContentType Override the incoming header to force the data to be
310
+ * treated as this content-type.
311
+ *
312
+ * Callback function takes:
313
+ *
314
+ * ok True if the fetch worked, and got a 200 response.
315
+ * False if any error happened
316
+ *
317
+ * errmessage Text error message if not OK.
318
+ *
319
+ * response The fetch Response object (was: XHR) if there was was one
320
+ * includes response.status as the HTTP status if any.
321
+ */
322
+ nowOrWhenFetched(uriIn: string | NamedNode, p2?: UserCallback | Options, userCallback?: UserCallback, options?: Options): void;
323
+ /**
324
+ * Records a status message (as a literal node) by appending it to the
325
+ * request's metadata status collection.
326
+ *
327
+ */
328
+ addStatus(req: BlankNode, statusMessage: string): void;
329
+ /**
330
+ * Records errors in the system on failure:
331
+ *
332
+ * - Adds an entry to the request status collection
333
+ * - Adds an error triple with the fail message to the metadata
334
+ * - Fires the 'fail' callback
335
+ * - Rejects with an error result object, which has a response object if any
336
+ */
337
+ failFetch(options: {
338
+ req: BlankNode;
339
+ original: Quad_Subject;
340
+ } & Options, errorMessage: string, statusCode: StatusValues, response?: ExtendedResponse): Promise<FetchError>;
341
+ linkData(originalUri: NamedNode, rel: string, uri: string, why: Quad_Graph, reverse?: boolean): void;
342
+ parseLinkHeader(linkHeader: string, originalUri: NamedNode, reqNode: Quad_Graph): void;
343
+ doneFetch(options: {
344
+ req: Quad_Subject;
345
+ original: Quad_Subject;
346
+ } & Options, response: ExtendedResponse): Response;
347
+ /**
348
+ * Note two nodes are now smushed
349
+ * If only one was flagged as looked up, then the new node is looked up again,
350
+ * which will make sure all the URIs are dereferenced
351
+ */
352
+ nowKnownAs(was: Quad_Subject, now: Quad_Subject): void;
353
+ /**
354
+ * Writes back to the web what we have in the store for this uri
355
+ */
356
+ putBack(uri: NamedNode | string, options?: Options): Promise<Response>;
357
+ webCopy(here: string, there: string, contentType: any): Promise<ExtendedResponse>;
358
+ delete(uri: string, options?: Options): Promise<ExtendedResponse>;
359
+ /** Create an empty resource if it really does not exist
360
+ * Be absolutely sure something does not exist before creating a new empty file
361
+ * as otherwise existing could be deleted.
362
+ * @param doc - The resource
363
+ */
364
+ createIfNotExists(doc: RDFlibNamedNode, contentType?: "text/turtle", data?: string): Promise<ExtendedResponse>;
365
+ /**
366
+ * @param parentURI URI of parent container
367
+ * @param folderName - Optional folder name (slug)
368
+ * @param data - Optional folder metadata
369
+ */
370
+ createContainer(parentURI: string, folderName: string, data: string): Promise<Response>;
371
+ invalidateCache(iri: string | NamedNode): void;
372
+ /**
373
+ * A generic web opeation, at the fetch() level.
374
+ * does not invole the quadstore.
375
+ *
376
+ * Returns promise of Response
377
+ * If data is returned, copies it to response.responseText before returning
378
+ */
379
+ webOperation(method: HTTPMethods, uriIn: string | NamedNode, options?: Options): Promise<ExtendedResponse>;
380
+ /**
381
+ * Looks up something.
382
+ * Looks up all the URIs a things has.
383
+ *
384
+ * @param term - canonical term for the thing whose URI is
385
+ * to be dereferenced
386
+ * @param rterm - the resource which referred to this
387
+ * (for tracking bad links)
388
+ */
389
+ lookUpThing(term: Quad_Subject, rterm: Quad_Subject): Promise<Response> | Promise<Response>[];
390
+ /**
391
+ * Looks up response header.
392
+ *
393
+ * @returns {Array|undefined} a list of header values found in a stored HTTP
394
+ * response, or [] if response was found but no header found,
395
+ * or undefined if no response is available.
396
+ * Looks for { [] link:requestedURI ?uri; link:response [ httph:header-name ?value ] }
397
+ */
398
+ getHeader(doc: NamedNode, header: string): undefined | string[];
399
+ saveRequestMetadata(docuri: string, options: AutoInitOptions): void;
400
+ saveResponseMetadata(response: Response, options: {
401
+ req: BlankNode;
402
+ resource: Quad_Subject;
403
+ } & Options): BlankNode;
404
+ objectRefresh(term: NamedNode): void;
405
+ refresh(term: NamedNode, userCallback?: UserCallback): void;
406
+ refreshIfExpired(term: NamedNode, userCallback: UserCallback): void;
407
+ retract(term: Quad_Graph): void;
408
+ getState(docuri: string): any;
409
+ isPending(docuri: string): boolean;
410
+ unload(term: NamedNode): void;
411
+ addHandler(handler: typeof Handler): void;
412
+ retryNoCredentials(docuri: string, options: any): Promise<Result>;
413
+ /**
414
+ * Tests whether a request is being made to a cross-site URI (for purposes
415
+ * of retrying with a proxy)
416
+ */
417
+ isCrossSite(uri: string): boolean;
418
+ /**
419
+ * Called when there's a network error in fetch(), or a response
420
+ * with status of 0.
421
+ */
422
+ handleError(response: ExtendedResponse | Error, docuri: string, options: AutoInitOptions): Promise<ExtendedResponse | FetchError>;
423
+ addType(rdfType: NamedNode, req: Quad_Subject, kb: IndexedFormula, locURI: string): void;
424
+ /**
425
+ * Handle fetch() response
426
+ */
427
+ handleResponse(response: ExtendedResponse, docuri: string, options: AutoInitOptions): Promise<FetchError | ExtendedResponse> | ExtendedResponse;
428
+ saveErrorResponse(response: ExtendedResponse, responseNode: Quad_Subject): Promise<void>;
429
+ handlerForContentType(contentType: string, response: ExtendedResponse): Handler | null;
430
+ guessContentType(uri: string): ContentType | undefined;
431
+ normalizedContentType(options: AutoInitOptions, headers: Headers): ContentType | string | null;
432
+ /**
433
+ * Sends a new request to the specified uri. (Extracted from `onerrorFactory()`)
434
+ */
435
+ redirectToProxy(newURI: string, options: AutoInitOptions): Promise<ExtendedResponse | FetchError>;
436
+ setRequestTimeout(uri: string, options: {
437
+ req: Quad_Subject;
438
+ original: Quad_Subject;
439
+ } & Options): Promise<number | FetchError>;
440
+ addFetchCallback(uri: string, callback: UserCallback): void;
441
+ acceptString(): string;
442
+ }
443
+ export {};
package/lib/fetcher.js CHANGED
@@ -668,8 +668,9 @@ var Fetcher = /*#__PURE__*/function () {
668
668
  (0, _defineProperty2.default)(this, "fireCallbacks", void 0);
669
669
  this.store = store || new _store.default();
670
670
  this.ns = getNS(this.store.rdfFactory);
671
- this.timeout = options.timeout || 30000;
672
- this._fetch = options.fetch || typeof global !== 'undefined' && global.solidFetcher || typeof window !== 'undefined' && window.solidFetcher || _crossFetch.default;
671
+ this.timeout = options.timeout || 30000; // solidFetcher is deprecated
672
+
673
+ this._fetch = options.fetch || typeof global !== 'undefined' && (global.solidFetcher || global.solidFetch) || typeof window !== 'undefined' && (window.solidFetcher || window.solidFetch) || _crossFetch.default;
673
674
 
674
675
  if (!this._fetch) {
675
676
  throw new Error('No _fetch function available for Fetcher');