UNPKG

4.77 kBTypeScriptView Raw
1/**
2 * Copyright 2020 Inrupt Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal in
6 * the Software without restriction, including without limitation the rights to use,
7 * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
8 * Software, and to permit persons to whom the Software is furnished to do so,
9 * subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 */
21import { LitDataset, UrlString, Thing, Url, ThingLocal, LocalNode, ThingPersisted, ChangeLog } from "./interfaces";
22/**
23 * @hidden Scopes are not yet consistently used in Solid and hence not properly implemented in this library yet (the add*() and set*() functions do not respect it yet), so we're not exposing these to developers at this point in time.
24 */
25export interface GetThingOptions {
26 /**
27 * Which Named Graph to extract the Thing from.
28 *
29 * If not specified, the Thing will include Quads from all Named Graphs in the given
30 * [[LitDataset]].
31 **/
32 scope?: Url | UrlString;
33}
34/**
35 * Extract Quads with a given Subject from a [[LitDataset]] into a [[Thing]].
36 *
37 * @param litDataset The [[LitDataset]] to extract the [[Thing]] from.
38 * @param thingUrl The URL of the desired [[Thing]].
39 * @param options Not yet implemented.
40 */
41export declare function getThingOne(litDataset: LitDataset, thingUrl: UrlString | Url | LocalNode, options?: GetThingOptions): Thing;
42/**
43 * Get all [[Thing]]s about which a [[LitDataset]] contains Quads.
44 *
45 * @param litDataset The [[LitDataset]] to extract the [[Thing]]s from.
46 * @param options Not yet implemented.
47 */
48export declare function getThingAll(litDataset: LitDataset, options?: GetThingOptions): Thing[];
49/**
50 * Insert a [[Thing]] into a [[LitDataset]], replacing previous instances of that Thing.
51 *
52 * @param litDataset The LitDataset to insert a Thing into.
53 * @param thing The Thing to insert into the given LitDataset.
54 * @returns A new LitDataset equal to the given LitDataset, but with the given Thing.
55 */
56export declare function setThing<Dataset extends LitDataset>(litDataset: Dataset, thing: Thing): Dataset & ChangeLog;
57/**
58 * Remove a Thing from a LitDataset.
59 *
60 * @param litDataset The LitDataset to remove a Thing from.
61 * @param thing The Thing to remove from `litDataset`.
62 * @returns A new [[LitDataset]] equal to the input LitDataset, excluding the given Thing.
63 */
64export declare function removeThing<Dataset extends LitDataset>(litDataset: Dataset, thing: UrlString | Url | LocalNode | Thing): Dataset & ChangeLog;
65interface CreateThingLocalOptions {
66 /**
67 * The name that should be used for this [[Thing]] when constructing its URL.
68 *
69 * If not provided, a random one will be generated.
70 */
71 name?: string;
72}
73interface CreateThingPersistedOptions {
74 /**
75 * The URL of the newly created [[Thing]].
76 */
77 url: UrlString;
78}
79export declare type CreateThingOptions = CreateThingLocalOptions | CreateThingPersistedOptions;
80/**
81 * Initialise a new [[Thing]] in memory.
82 *
83 * @param options See [[CreateThingOptions]].
84 */
85export declare function createThing(options: CreateThingPersistedOptions): ThingPersisted;
86export declare function createThing(options?: CreateThingLocalOptions): ThingLocal;
87/**
88 * Get the URL to a given [[Thing]].
89 *
90 * @param thing The [[Thing]] you want to obtain the URL from.
91 * @param baseUrl If `thing` is not persisted yet, the base URL that should be used to construct this [[Thing]]'s URL.
92 */
93export declare function asUrl(thing: ThingLocal, baseUrl: UrlString): UrlString;
94export declare function asUrl(thing: ThingPersisted): UrlString;
95/** @hidden Alias of [[asUrl]] for those who prefer IRI terminology. */
96export declare const asIri: typeof asUrl;
97/**
98 * @param thing The [[Thing]] of which a URL might or might not be known.
99 * @return Whether `thing` has no known URL yet.
100 */
101export declare function isThingLocal(thing: ThingPersisted | ThingLocal): thing is ThingLocal;
102export {};