solid-logic 1.3.12 → 1.3.13-33f4d6e3

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 (143) hide show
  1. package/.babelrc +0 -0
  2. package/.eslintrc.js +0 -0
  3. package/.github/workflows/ci.yml +40 -5
  4. package/.github/workflows/release.yml +0 -0
  5. package/LICENSE +0 -0
  6. package/README.md +0 -0
  7. package/jest.config.js +4 -1
  8. package/lib/acl/aclLogic.d.ts +32 -0
  9. package/lib/acl/aclLogic.d.ts.map +1 -0
  10. package/lib/acl/aclLogic.js +132 -0
  11. package/lib/acl/aclLogic.js.map +1 -0
  12. package/lib/authSession/authSession.d.ts +3 -0
  13. package/lib/authSession/authSession.d.ts.map +1 -0
  14. package/lib/authSession/authSession.js +8 -0
  15. package/lib/authSession/authSession.js.map +1 -0
  16. package/lib/authn/SolidAuthnLogic.d.ts +26 -6
  17. package/lib/authn/SolidAuthnLogic.d.ts.map +1 -1
  18. package/lib/authn/SolidAuthnLogic.js +161 -5
  19. package/lib/authn/SolidAuthnLogic.js.map +1 -1
  20. package/lib/authn/authUtil.d.ts +17 -0
  21. package/lib/authn/authUtil.d.ts.map +1 -0
  22. package/lib/authn/authUtil.js +88 -0
  23. package/lib/authn/authUtil.js.map +1 -0
  24. package/lib/chat/ChatLogic.d.ts +2 -2
  25. package/lib/chat/ChatLogic.d.ts.map +1 -1
  26. package/lib/chat/ChatLogic.js +38 -33
  27. package/lib/chat/ChatLogic.js.map +1 -1
  28. package/lib/chat/determineChatContainer.d.ts +0 -0
  29. package/lib/chat/determineChatContainer.d.ts.map +0 -0
  30. package/lib/chat/determineChatContainer.js +0 -0
  31. package/lib/chat/determineChatContainer.js.map +0 -0
  32. package/lib/inbox/InboxLogic.d.ts +2 -2
  33. package/lib/inbox/InboxLogic.d.ts.map +1 -1
  34. package/lib/inbox/InboxLogic.js +14 -13
  35. package/lib/inbox/InboxLogic.js.map +1 -1
  36. package/lib/index.d.ts +9 -72
  37. package/lib/index.d.ts.map +1 -1
  38. package/lib/index.js +31 -387
  39. package/lib/index.js.map +1 -1
  40. package/lib/issuer/issuerLogic.d.ts +8 -0
  41. package/lib/issuer/issuerLogic.d.ts.map +1 -0
  42. package/lib/issuer/issuerLogic.js +53 -0
  43. package/lib/issuer/issuerLogic.js.map +1 -0
  44. package/lib/logic/CustomError.d.ts +17 -0
  45. package/lib/logic/CustomError.d.ts.map +1 -0
  46. package/lib/logic/CustomError.js +73 -0
  47. package/lib/logic/CustomError.js.map +1 -0
  48. package/lib/{index-alain.d.ts → logic/SolidLogic.d.ts} +7 -33
  49. package/lib/logic/SolidLogic.d.ts.map +1 -0
  50. package/lib/{index-alain.js → logic/SolidLogic.js} +17 -99
  51. package/lib/logic/SolidLogic.js.map +1 -0
  52. package/lib/logic/solidLogicSingleton.d.ts +8 -0
  53. package/lib/logic/solidLogicSingleton.d.ts.map +1 -0
  54. package/lib/logic/solidLogicSingleton.js +85 -0
  55. package/lib/logic/solidLogicSingleton.js.map +1 -0
  56. package/lib/profile/ProfileLogic.d.ts +2 -3
  57. package/lib/profile/ProfileLogic.d.ts.map +1 -1
  58. package/lib/profile/ProfileLogic.js +10 -8
  59. package/lib/profile/ProfileLogic.js.map +1 -1
  60. package/lib/typeIndex/typeIndexLogic.d.ts +22 -0
  61. package/lib/typeIndex/typeIndexLogic.d.ts.map +1 -0
  62. package/lib/typeIndex/typeIndexLogic.js +302 -0
  63. package/lib/typeIndex/typeIndexLogic.js.map +1 -0
  64. package/lib/types.d.ts +29 -0
  65. package/lib/types.d.ts.map +1 -0
  66. package/lib/{authn/index.js → types.js} +1 -1
  67. package/lib/types.js.map +1 -0
  68. package/lib/util/UtilityLogic.d.ts +2 -2
  69. package/lib/util/UtilityLogic.d.ts.map +1 -1
  70. package/lib/util/UtilityLogic.js +10 -8
  71. package/lib/util/UtilityLogic.js.map +1 -1
  72. package/lib/{debug.d.ts → util/debug.d.ts} +0 -0
  73. package/lib/util/debug.d.ts.map +1 -0
  74. package/lib/{debug.js → util/debug.js} +0 -0
  75. package/lib/util/debug.js.map +1 -0
  76. package/lib/{uri.d.ts → util/uri.d.ts} +0 -0
  77. package/lib/util/uri.d.ts.map +1 -0
  78. package/lib/{uri.js → util/uri.js} +0 -0
  79. package/lib/util/uri.js.map +1 -0
  80. package/package.json +7 -5
  81. package/renovate.json +0 -0
  82. package/src/acl/aclLogic.ts +137 -0
  83. package/src/authSession/authSession.ts +12 -0
  84. package/src/authn/SolidAuthnLogic.ts +112 -10
  85. package/src/authn/authUtil.ts +67 -0
  86. package/src/chat/ChatLogic.ts +13 -13
  87. package/src/chat/determineChatContainer.ts +0 -0
  88. package/src/inbox/InboxLogic.ts +3 -15
  89. package/src/index.ts +18 -307
  90. package/src/issuer/issuerLogic.ts +40 -0
  91. package/src/logic/CustomError.ts +25 -0
  92. package/src/logic/SolidLogic.ts +264 -0
  93. package/src/logic/solidLogicSingleton.ts +24 -0
  94. package/src/profile/ProfileLogic.ts +4 -5
  95. package/src/typeIndex/typeIndexLogic.ts +170 -0
  96. package/src/types.ts +41 -0
  97. package/src/util/UtilityLogic.ts +4 -16
  98. package/src/{debug.ts → util/debug.ts} +0 -0
  99. package/src/{uri.ts → util/uri.ts} +0 -0
  100. package/test/aclLogic.test.ts +15 -0
  101. package/test/authUtil.test.ts +23 -0
  102. package/{src/chat/integration.test.ts → test/chatLogic.test.ts} +4 -5
  103. package/test/helpers/setup.ts +13 -0
  104. package/{src/inbox/unit.test.ts → test/inboxLogic.test.ts} +5 -6
  105. package/test/logic.test.ts +28 -0
  106. package/test/solidAuthLogic.test.ts +49 -0
  107. package/test/typeIndexLogic.test.ts +26 -0
  108. package/{src/util/unit.test.ts → test/utilityLogic.test.ts} +3 -4
  109. package/tsconfig.json +0 -0
  110. package/jest.setup.ts +0 -2
  111. package/lib/authn/NoAuthnLogic.d.ts +0 -9
  112. package/lib/authn/NoAuthnLogic.d.ts.map +0 -1
  113. package/lib/authn/NoAuthnLogic.js +0 -17
  114. package/lib/authn/NoAuthnLogic.js.map +0 -1
  115. package/lib/authn/index.d.ts +0 -5
  116. package/lib/authn/index.d.ts.map +0 -1
  117. package/lib/authn/index.js.map +0 -1
  118. package/lib/chat/integration.test.d.ts +0 -2
  119. package/lib/chat/integration.test.d.ts.map +0 -1
  120. package/lib/chat/integration.test.js +0 -318
  121. package/lib/chat/integration.test.js.map +0 -1
  122. package/lib/debug.d.ts.map +0 -1
  123. package/lib/debug.js.map +0 -1
  124. package/lib/inbox/unit.test.d.ts +0 -2
  125. package/lib/inbox/unit.test.d.ts.map +0 -1
  126. package/lib/inbox/unit.test.js +0 -264
  127. package/lib/inbox/unit.test.js.map +0 -1
  128. package/lib/index-alain.d.ts.map +0 -1
  129. package/lib/index-alain.js.map +0 -1
  130. package/lib/uri.d.ts.map +0 -1
  131. package/lib/uri.js.map +0 -1
  132. package/lib/util/UtilityLogic-alain.d.ts +0 -32
  133. package/lib/util/UtilityLogic-alain.d.ts.map +0 -1
  134. package/lib/util/UtilityLogic-alain.js +0 -248
  135. package/lib/util/UtilityLogic-alain.js.map +0 -1
  136. package/lib/util/unit.test.d.ts +0 -2
  137. package/lib/util/unit.test.d.ts.map +0 -1
  138. package/lib/util/unit.test.js +0 -200
  139. package/lib/util/unit.test.js.map +0 -1
  140. package/src/authn/NoAuthnLogic.ts +0 -16
  141. package/src/authn/index.ts +0 -5
  142. package/src/index-alain.txt +0 -316
  143. package/src/util/UtilityLogic-alain.txt +0 -181
@@ -1,200 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
- return new (P || (P = Promise))(function (resolve, reject) {
24
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
- step((generator = generator.apply(thisArg, _arguments || [])).next());
28
- });
29
- };
30
- var __generator = (this && this.__generator) || function (thisArg, body) {
31
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
32
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
33
- function verb(n) { return function (v) { return step([n, v]); }; }
34
- function step(op) {
35
- if (f) throw new TypeError("Generator is already executing.");
36
- while (_) try {
37
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
38
- if (y = 0, t) op = [op[0] & 2, t.value];
39
- switch (op[0]) {
40
- case 0: case 1: t = op; break;
41
- case 4: _.label++; return { value: op[1], done: false };
42
- case 5: _.label++; y = op[1]; op = [0]; continue;
43
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
44
- default:
45
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
46
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
47
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
48
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
49
- if (t[2]) _.ops.pop();
50
- _.trys.pop(); continue;
51
- }
52
- op = body.call(thisArg, _);
53
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
54
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
55
- }
56
- };
57
- var __importDefault = (this && this.__importDefault) || function (mod) {
58
- return (mod && mod.__esModule) ? mod : { "default": mod };
59
- };
60
- Object.defineProperty(exports, "__esModule", { value: true });
61
- /* eslint-disable @typescript-eslint/no-non-null-assertion */
62
- var UtilityLogic_1 = require("./UtilityLogic");
63
- var solid_namespace_1 = __importDefault(require("solid-namespace"));
64
- var rdf = __importStar(require("rdflib"));
65
- var jest_fetch_mock_1 = __importDefault(require("jest-fetch-mock"));
66
- var rdflib_1 = require("rdflib");
67
- var ns = (0, solid_namespace_1.default)(rdf);
68
- var alice = rdf.sym("https://alice.example/profile/card#me");
69
- var bob = rdf.sym("https://bob.example/profile/card#me");
70
- describe("Utility logic", function () {
71
- var util;
72
- var store;
73
- var fetcher;
74
- beforeEach(function () {
75
- jest_fetch_mock_1.default.resetMocks();
76
- jest_fetch_mock_1.default.mockResponse("Not Found", {
77
- status: 404,
78
- });
79
- fetcher = { fetch: jest_fetch_mock_1.default };
80
- store = rdf.graph();
81
- store.fetcher = rdf.fetcher(store, fetcher);
82
- store.updater = new rdflib_1.UpdateManager(store);
83
- util = new UtilityLogic_1.UtilityLogic(store, ns, fetcher);
84
- });
85
- describe("getArchiveUrl", function () {
86
- it("produces the right URL in February", function () {
87
- var url = util.getArchiveUrl('https://example.com/inbox/asdf-qwer-asdf-qwer', new Date('7 Feb 2062 UTC'));
88
- expect(url).toEqual('https://example.com/inbox/archive/2062/02/07/asdf-qwer-asdf-qwer');
89
- });
90
- it("produces the right URL in November", function () {
91
- var url = util.getArchiveUrl('https://example.com/inbox/asdf-qwer-asdf-qwer', new Date('12 Nov 2012 UTC'));
92
- expect(url).toEqual('https://example.com/inbox/archive/2012/11/12/asdf-qwer-asdf-qwer');
93
- });
94
- });
95
- describe("getContainerMembers", function () {
96
- describe("When container is empty", function () {
97
- var result;
98
- beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
99
- return __generator(this, function (_a) {
100
- switch (_a.label) {
101
- case 0:
102
- containerIsEmpty();
103
- return [4 /*yield*/, util.getContainerMembers('https://container.com/')];
104
- case 1:
105
- result = _a.sent();
106
- return [2 /*return*/];
107
- }
108
- });
109
- }); });
110
- it("Resolves to an empty array", function () {
111
- expect(result).toEqual([]);
112
- });
113
- });
114
- describe("When container has some containment triples", function () {
115
- var result;
116
- beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
117
- return __generator(this, function (_a) {
118
- switch (_a.label) {
119
- case 0:
120
- containerHasSomeContainmentTriples();
121
- return [4 /*yield*/, util.getContainerMembers('https://container.com/')];
122
- case 1:
123
- result = _a.sent();
124
- return [2 /*return*/];
125
- }
126
- });
127
- }); });
128
- it("Resolves to an array with some URLs", function () {
129
- expect(result.sort()).toEqual([
130
- 'https://container.com/foo.txt',
131
- 'https://container.com/bar/'
132
- ].sort());
133
- });
134
- });
135
- });
136
- describe("setSinglePeerAccess", function () {
137
- beforeEach(function () {
138
- jest_fetch_mock_1.default.mockOnceIf("https://owner.com/some/resource", "hello", {
139
- headers: {
140
- Link: '<https://owner.com/some/acl>; rel="acl"'
141
- }
142
- });
143
- jest_fetch_mock_1.default.mockOnceIf("https://owner.com/some/acl", "Created", {
144
- status: 201
145
- });
146
- });
147
- it("Creates the right ACL doc", function () { return __awaiter(void 0, void 0, void 0, function () {
148
- return __generator(this, function (_a) {
149
- switch (_a.label) {
150
- case 0: return [4 /*yield*/, util.setSinglePeerAccess({
151
- ownerWebId: "https://owner.com/#me",
152
- peerWebId: "https://peer.com/#me",
153
- accessToModes: "acl:Read, acl:Control",
154
- defaultModes: "acl:Write",
155
- target: "https://owner.com/some/resource"
156
- })];
157
- case 1:
158
- _a.sent();
159
- expect(jest_fetch_mock_1.default.mock.calls).toEqual([
160
- ["https://owner.com/some/resource", jest_fetch_mock_1.default.mock.calls[0][1]],
161
- ["https://owner.com/some/acl", {
162
- body: '@prefix acl: <http://www.w3.org/ns/auth/acl#>.\n' +
163
- '\n' +
164
- '<#alice> a acl:Authorization;\n' +
165
- ' acl:agent <https://owner.com/#me>;\n' +
166
- ' acl:accessTo <https://owner.com/some/resource>;\n' +
167
- ' acl:default <https://owner.com/some/resource>;\n' +
168
- ' acl:mode acl:Read, acl:Write, acl:Control.\n' +
169
- '<#bobAccessTo> a acl:Authorization;\n' +
170
- ' acl:agent <https://peer.com/#me>;\n' +
171
- ' acl:accessTo <https://owner.com/some/resource>;\n' +
172
- ' acl:mode acl:Read, acl:Control.\n' +
173
- '<#bobDefault> a acl:Authorization;\n' +
174
- ' acl:agent <https://peer.com/#me>;\n' +
175
- ' acl:default <https://owner.com/some/resource>;\n' +
176
- ' acl:mode acl:Write.\n',
177
- headers: [
178
- ["Content-Type", "text/turtle"]
179
- ],
180
- method: "PUT"
181
- }]
182
- ]);
183
- return [2 /*return*/];
184
- }
185
- });
186
- }); });
187
- });
188
- function containerIsEmpty() {
189
- jest_fetch_mock_1.default.mockOnceIf("https://container.com/", " ", // FIXME: https://github.com/jefflau/jest-fetch-mock/issues/189
190
- {
191
- headers: { "Content-Type": "text/turtle" },
192
- });
193
- }
194
- function containerHasSomeContainmentTriples() {
195
- jest_fetch_mock_1.default.mockOnceIf("https://container.com/", "<.> <http://www.w3.org/ns/ldp#contains> <./foo.txt>, <./bar/> .", {
196
- headers: { "Content-Type": "text/turtle" },
197
- });
198
- }
199
- });
200
- //# sourceMappingURL=unit.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"unit.test.js","sourceRoot":"","sources":["../../src/util/unit.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;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,yBAAS,CAAC,UAAU,CAClB,wBAAwB,EACxB,iEAAiE,EACjE;YACE,OAAO,EAAE,EAAE,cAAc,EAAE,aAAa,EAAE;SAC3C,CACF,CAAC;IACJ,CAAC;AACH,CAAC,CAAC,CAAC"}
@@ -1,16 +0,0 @@
1
- import { AuthnLogic } from "./index";
2
-
3
- /**
4
- * Fallback, if no auth client has been provided to solid-logic
5
- */
6
- export class NoAuthnLogic implements AuthnLogic {
7
- constructor() {
8
- console.warn(
9
- "no auth client passed to solid-logic, logic that relies on auth is not available"
10
- );
11
- }
12
-
13
- currentUser(): null {
14
- return null;
15
- }
16
- }
@@ -1,5 +0,0 @@
1
- import { NamedNode } from "rdflib";
2
-
3
- export interface AuthnLogic {
4
- currentUser: () => NamedNode | null;
5
- }
@@ -1,316 +0,0 @@
1
- import { Session } from "@inrupt/solid-client-authn-browser";
2
- import * as rdf from "rdflib";
3
- import { Fetcher, NamedNode, Statement, Store, UpdateManager } from "rdflib";
4
- import solidNamespace from "solid-namespace";
5
- import { AuthnLogic } from "./authn";
6
- import { NoAuthnLogic } from "./authn/NoAuthnLogic";
7
- import { SolidAuthnLogic } from "./authn/SolidAuthnLogic";
8
- import crossFetch from 'cross-fetch';
9
-
10
- import { ChatLogic } from "./chat/ChatLogic";
11
- import * as debug from "./debug";
12
- import { ProfileLogic } from "./profile/ProfileLogic";
13
- import { UtilityLogic } from "./util/UtilityLogic";
14
-
15
- export { ACL_LINK } from './util/UtilityLogic';
16
-
17
- const ns: SolidNamespace = solidNamespace(rdf);
18
-
19
- interface ConnectedStore extends Store {
20
- fetcher: Fetcher;
21
- }
22
-
23
- export interface LiveStore extends ConnectedStore {
24
- updater: UpdateManager;
25
- }
26
-
27
- export interface SolidNamespace {
28
- [key: string]: (term: string) => NamedNode;
29
- }
30
-
31
- export class SolidLogic {
32
- cache: {
33
- profileDocument: {
34
- [WebID: string]: NamedNode;
35
- };
36
- preferencesFile: {
37
- [WebID: string]: NamedNode;
38
- };
39
- };
40
-
41
- store: LiveStore;
42
- me: string | undefined;
43
- fetcher: { fetch: (url: string, options?: any) => any };
44
- _fetch: Function;
45
-
46
- chat: ChatLogic;
47
- profile: ProfileLogic;
48
- authn: AuthnLogic;
49
- util: UtilityLogic;
50
-
51
- constructor(fetcher: { fetch: (url: any, requestInit: any) => any }, solidAuthSession: Session) {
52
- this.store = rdf.graph() as LiveStore; // Make a Quad store
53
- rdf.fetcher(this.store, fetcher); // Attach a web I/O module, store.fetcher
54
- this.store.updater = new rdf.UpdateManager(this.store); // Add real-time live updates store.updater
55
- this.cache = {
56
- profileDocument: {},
57
- preferencesFile: {},
58
- };
59
- this.fetcher = fetcher
60
- /*this._fetch = this.fetcher.fetch
61
- || typeof global !== 'undefined' && global.solidFetch
62
- || typeof window !== 'undefined' && window.solidFetch
63
- || crossFetch
64
- if (!this._fetch) {
65
- throw new Error('No _fetch function available for Fetcher')
66
- } */
67
- if (solidAuthSession) {
68
- this.authn = new SolidAuthnLogic(solidAuthSession);
69
- } else {
70
- this.authn = new NoAuthnLogic();
71
- }
72
- this.profile = new ProfileLogic(this.store, ns, this.authn);
73
- this.chat = new ChatLogic(this.store, ns, this.profile);
74
- this.util = new UtilityLogic(this.store, ns, this.fetcher);
75
- }
76
-
77
- findAclDocUrl(url: string) {
78
- return this.util.findAclDocUrl(url);
79
- }
80
-
81
- loadDoc(doc: NamedNode): Promise<void> {
82
- return this.util.loadDoc(doc);
83
- }
84
-
85
- async loadProfile(me: NamedNode): Promise<NamedNode> {
86
- // console.log('loadProfile', me)
87
- if (this.cache.profileDocument[me.value]) {
88
- return this.cache.profileDocument[me.value];
89
- }
90
- let profileDocument;
91
- try {
92
- profileDocument = me.doc();
93
- await this.loadDoc(profileDocument);
94
- return profileDocument;
95
- } catch (err) {
96
- const message = `Logged in but cannot load profile ${profileDocument} : ${err}`;
97
- throw new Error(message);
98
- }
99
- }
100
-
101
- async loadPreferences(me: NamedNode): Promise<NamedNode> {
102
- // console.log('loadPreferences', me)
103
- if (this.cache.preferencesFile[me.value]) {
104
- return this.cache.preferencesFile[me.value];
105
- }
106
- const preferencesFile = this.store.any(me, ns.space("preferencesFile"));
107
-
108
- // console.log('this.store.any()', this.store.any())
109
- /**
110
- * Are we working cross-origin?
111
- * Returns True if we are in a webapp at an origin, and the file origin is different
112
- */
113
- function differentOrigin(): boolean {
114
- if (!preferencesFile) {
115
- return true;
116
- }
117
- return (
118
- `${window.location.origin}/` !== new URL(preferencesFile.value).origin
119
- );
120
- }
121
-
122
- if (!preferencesFile) {
123
- throw new Error(
124
- `Can't find a preference file pointer in profile ${me.doc()}`
125
- );
126
- }
127
-
128
- if (!this.store.fetcher) {
129
- throw new Error("Cannot load doc, have no fetcher");
130
- }
131
- // //// Load preference file
132
- try {
133
- await this.store.fetcher.load(preferencesFile as NamedNode, {
134
- withCredentials: true,
135
- });
136
- } catch (err) {
137
- // Really important to look at why
138
- const status = err.status;
139
- debug.log(`HTTP status ${status} for preference file ${preferencesFile}`);
140
- if (status === 401) {
141
- throw new UnauthorizedError();
142
- }
143
- if (status === 403) {
144
- if (differentOrigin()) {
145
- throw new CrossOriginForbiddenError();
146
- }
147
- throw new SameOriginForbiddenError();
148
- }
149
- if (status === 404) {
150
- throw new NotFoundError(preferencesFile.value);
151
- }
152
- throw new FetchError(err.status, err.message);
153
- }
154
- return preferencesFile as NamedNode;
155
- }
156
-
157
- getTypeIndex(
158
- me: NamedNode | string,
159
- preferencesFile: NamedNode | string,
160
- isPublic: boolean
161
- ): NamedNode[] {
162
- // console.log('getTypeIndex', this.store.each(me, undefined, undefined, preferencesFile), isPublic, preferencesFile)
163
- return this.store.each(
164
- me as NamedNode,
165
- isPublic ? ns.solid("publicTypeIndex") : ns.solid("privateTypeIndex"),
166
- undefined,
167
- preferencesFile as NamedNode
168
- ) as NamedNode[];
169
- }
170
-
171
- getRegistrations(instance, theClass) {
172
- return this.store
173
- .each(undefined, ns.solid("instance"), instance)
174
- .filter((r) => {
175
- return this.store.holds(r, ns.solid("forClass"), theClass);
176
- });
177
- }
178
-
179
- load(doc: NamedNode | NamedNode[] | string) {
180
- if (!this.store.fetcher) {
181
- throw new Error("Cannot load doc(s), have no fetcher");
182
- }
183
- return this.store.fetcher.load(doc);
184
- }
185
-
186
- async loadIndexes(
187
- me: NamedNode | string,
188
- publicProfile: NamedNode | string | null,
189
- preferencesFile: NamedNode | string | null,
190
- onWarning = async (_err: Error) => {
191
- return undefined;
192
- }
193
- ): Promise<{
194
- private: any;
195
- public: any;
196
- }> {
197
- let privateIndexes: any[] = [];
198
- let publicIndexes: any[] = [];
199
- if (publicProfile) {
200
- publicIndexes = this.getTypeIndex(me, publicProfile, true);
201
- try {
202
- await this.load(publicIndexes as NamedNode[]);
203
- } catch (err) {
204
- onWarning(new Error(`loadIndex: loading public type index(es) ${err}`));
205
- }
206
- }
207
- if (preferencesFile) {
208
- privateIndexes = this.getTypeIndex(me, preferencesFile, false);
209
- // console.log({ privateIndexes })
210
- if (privateIndexes.length === 0) {
211
- await onWarning(
212
- new Error(
213
- `Your preference file ${preferencesFile} does not point to a private type index.`
214
- )
215
- );
216
- } else {
217
- try {
218
- await this.load(privateIndexes);
219
- } catch (err) {
220
- onWarning(
221
- new Error(`loadIndex: loading private type index(es) ${err}`)
222
- );
223
- }
224
- }
225
- // } else {
226
- // debug.log(
227
- // 'We know your preference file is not available, so we are not bothering with private type indexes.'
228
- // )
229
- }
230
-
231
- return {
232
- private: privateIndexes,
233
- public: publicIndexes,
234
- };
235
- }
236
-
237
- async createEmptyRdfDoc(doc: NamedNode, comment: string) {
238
- if (!this.store.fetcher) {
239
- throw new Error("Cannot create empty rdf doc, have no fetcher");
240
- }
241
- await this.store.fetcher.webOperation("PUT", doc.uri, {
242
- data: `# ${new Date()} ${comment}
243
- `,
244
- contentType: "text/turtle",
245
- });
246
- }
247
-
248
- // @@@@ use the one in rdflib.js when it is available and delete this
249
- updatePromise(
250
- del: Array<Statement>,
251
- ins: Array<Statement> = []
252
- ): Promise<void> {
253
- return new Promise((resolve, reject) => {
254
- if (!this.store.updater) {
255
- throw new Error("Cannot updatePromise, have no updater");
256
- }
257
- this.store.updater.update(del, ins, function (_uri, ok, errorBody) {
258
- if (!ok) {
259
- reject(new Error(errorBody));
260
- } else {
261
- resolve();
262
- }
263
- }); // callback
264
- }); // promise
265
- }
266
-
267
- isContainer(url: string) {
268
- return this.util.isContainer(url);
269
- }
270
-
271
- getContainerElements(containerNode: NamedNode): NamedNode[] {
272
- return this.util.getContainerElements(containerNode);
273
- }
274
-
275
- getContainerMembers(containerUrl: string): Promise<string[]> {
276
- return this.util.getContainerMembers(containerUrl);
277
- }
278
-
279
- async recursiveDelete(url: string) {
280
- return this.util.recursiveDelete(url);
281
- }
282
-
283
- clearStore() {
284
- return this.util.clearStore();
285
- }
286
-
287
- async fetch(url: string, options?: any) {
288
- return this.fetcher.fetch(url, options);
289
- }
290
- }
291
-
292
- class CustomError extends Error {
293
- constructor(message?: string) {
294
- super(message);
295
- // see: typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html
296
- Object.setPrototypeOf(this, new.target.prototype); // restore prototype chain
297
- this.name = new.target.name; // stack traces display correctly now
298
- }
299
- }
300
-
301
- export class UnauthorizedError extends CustomError {}
302
-
303
- export class CrossOriginForbiddenError extends CustomError {}
304
-
305
- export class SameOriginForbiddenError extends CustomError {}
306
-
307
- export class NotFoundError extends CustomError {}
308
-
309
- export class FetchError extends CustomError {
310
- status: number;
311
-
312
- constructor(status: number, message?: string) {
313
- super(message);
314
- this.status = status;
315
- }
316
- }