UNPKG

7.1 kBPlain TextView 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 */
21
22import { DatasetCore, Quad, NamedNode, BlankNode } from "rdf-js";
23
24/**
25 * Alias to indicate where we expect to be given a URL represented as an RDF/JS NamedNode.
26 */
27export type Url = NamedNode;
28/** @hidden Alias of Url for those who prefer to use IRI terminology. */
29export type Iri = Url;
30/**
31 * Alias to indicate where we expect to be given a URL.
32 */
33export type UrlString = string;
34/** @hidden Alias of UrlString for those who prefer to use IRI terminology. */
35export type IriString = UrlString;
36/**
37 * Alias to indicate where we expect to be given a WebId.
38 */
39export type WebId = UrlString;
40
41/**
42 * A LitDataset represents all Quads from a single Resource.
43 */
44export type LitDataset = DatasetCore;
45/**
46 * A Thing represents all Quads with a given Subject URL and a given Named
47 * Graph, from a single Resource.
48 */
49export type Thing = DatasetCore & ({ url: UrlString } | { name: string });
50/**
51 * A [[Thing]] for which we know what the full Subject URL is.
52 */
53export type ThingPersisted = Thing & { url: UrlString };
54/**
55 * A [[Thing]] whose full Subject URL will be determined when it is persisted.
56 */
57export type ThingLocal = Thing & { name: string };
58/**
59 * Represents the BlankNode that will be initialised to a NamedNode when persisted.
60 *
61 * This is a Blank Node with a `name` property attached, which will be used to construct this
62 * Node's full URL once it is persisted, where it will transform into a Named Node.
63 *
64 * @internal Utility method; library users should not need to interact with LocalNodes directly.
65 */
66export type LocalNode = BlankNode & { name: string };
67
68/**
69 * A [[LitDataset]] containing Access Control rules for another LitDataset.
70 *
71 * Please note that the Web Access Control specification is not yet finalised, and hence, this
72 * function is still experimental and can change in a non-major release.
73 */
74export type unstable_AclDataset = LitDataset &
75 DatasetInfo & { accessTo: UrlString };
76
77/**
78 * @hidden Developers shouldn't need to directly access ACL rules. Instead, we provide our own functions that verify what access someone has.
79 */
80export type unstable_AclRule = Thing;
81
82/**
83 * An object with the boolean properties `read`, `append`, `write` and `control`, representing the
84 * respective Access Modes defined by the Web Access Control specification.
85 *
86 * Since that specification is not finalised yet, this interface is still experimental.
87 */
88export type unstable_AccessModes =
89 // If someone has write permissions, they also have append permissions:
90 | {
91 read: boolean;
92 append: true;
93 write: true;
94 control: boolean;
95 }
96 | {
97 read: boolean;
98 append: boolean;
99 write: false;
100 control: boolean;
101 };
102
103type unstable_WacAllow = {
104 user: unstable_AccessModes;
105 public: unstable_AccessModes;
106};
107/**
108 * [[LitDataset]]s fetched by lit-pod include this metadata describing its relation to a Pod Resource.
109 */
110export type DatasetInfo = {
111 datasetInfo: {
112 fetchedFrom: UrlString;
113 /**
114 * The URL reported by the server as possibly containing an ACL file. Note that this file might
115 * not necessarily exist, in which case the ACL of the nearest Container with an ACL applies.
116 *
117 * @ignore We anticipate the Solid spec to change how the ACL gets accessed, which would result
118 * in this API changing as well.
119 */
120 unstable_aclUrl?: UrlString;
121 /**
122 * Access permissions for the current user and the general public for this resource.
123 *
124 * @ignore There is no consensus yet about how this functionality will be incorporated in the
125 * final spec, so the final implementation might influence this API in the future.
126 * @see https://github.com/solid/solid-spec/blob/cb1373a369398d561b909009bd0e5a8c3fec953b/api-rest.md#wac-allow-headers
127 * @see https://github.com/solid/specification/issues/171
128 */
129 unstable_permissions?: unstable_WacAllow;
130 };
131};
132
133/**
134 * @internal Data structure to keep track of operations done by us; should not be read or manipulated by the developer.
135 */
136export type ChangeLog = {
137 changeLog: {
138 additions: Quad[];
139 deletions: Quad[];
140 };
141};
142
143/**
144 * @hidden Developers should use [[unstable_getResourceAcl]] and [[unstable_getFallbackAcl]] to access these.
145 */
146export type unstable_Acl = {
147 acl: {
148 resourceAcl?: unstable_AclDataset;
149 fallbackAcl: unstable_AclDataset | null;
150 };
151};
152
153/**
154 * Verify whether a given LitDataset includes metadata about where it was retrieved from.
155 *
156 * @param dataset A [[LitDataset]] that may have metadata attached about the Resource it was retrieved from.
157 * @returns True if `dataset` includes metadata about the Resource it was retrieved from, false if not.
158 */
159export function hasDatasetInfo<T extends LitDataset>(
160 dataset: T
161): dataset is T & DatasetInfo {
162 const potentialDatasetInfo = dataset as T & DatasetInfo;
163 return typeof potentialDatasetInfo.datasetInfo === "object";
164}
165
166/** @internal */
167export function hasChangelog<T extends LitDataset>(
168 dataset: T
169): dataset is T & ChangeLog {
170 const potentialChangeLog = dataset as T & ChangeLog;
171 return (
172 typeof potentialChangeLog.changeLog === "object" &&
173 Array.isArray(potentialChangeLog.changeLog.additions) &&
174 Array.isArray(potentialChangeLog.changeLog.deletions)
175 );
176}
177
178/**
179 * Given a [[LitDataset]], verify whether it has ACL data attached to it.
180 *
181 * This should generally only be true for LitDatasets fetched by
182 * [[unstable_fetchLitDatasetWithAcl]].
183 *
184 * @param dataset A [[LitDataset]].
185 * @returns Whether the given `dataset` has ACL data attached to it.
186 * @internal
187 */
188export function unstable_hasAccessibleAcl<Dataset extends DatasetInfo>(
189 dataset: Dataset
190): dataset is Dataset & {
191 datasetInfo: { unstable_aclUrl: UrlString };
192} {
193 return typeof dataset.datasetInfo.unstable_aclUrl === "string";
194}
195
196/**
197 * A RequestInit restriction where the method is set by the library
198 */
199export type unstable_UploadRequestInit = Omit<RequestInit, "method">;