solid-logic 1.3.17-9d25ceb7 → 1.3.17-a849582e
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/lib/acl/aclLogic.d.ts +12 -30
- package/lib/acl/aclLogic.d.ts.map +1 -1
- package/lib/acl/aclLogic.js +151 -116
- package/lib/acl/aclLogic.js.map +1 -1
- package/lib/authn/SolidAuthnLogic.d.ts.map +1 -1
- package/lib/authn/SolidAuthnLogic.js +2 -2
- package/lib/authn/SolidAuthnLogic.js.map +1 -1
- package/lib/chat/chatLogic.d.ts +16 -0
- package/lib/chat/chatLogic.d.ts.map +1 -0
- package/lib/chat/{ChatLogic.js → chatLogic.js} +82 -87
- package/lib/chat/chatLogic.js.map +1 -0
- package/lib/discovery/discoveryLogic.d.ts +8 -8
- package/lib/discovery/discoveryLogic.d.ts.map +1 -1
- package/lib/discovery/discoveryLogic.js +65 -72
- package/lib/discovery/discoveryLogic.js.map +1 -1
- package/lib/inbox/inboxLogic.d.ts +7 -0
- package/lib/inbox/inboxLogic.d.ts.map +1 -0
- package/lib/inbox/{InboxLogic.js → inboxLogic.js} +58 -64
- package/lib/inbox/inboxLogic.js.map +1 -0
- package/lib/index.d.ts +10 -13
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +76 -32
- package/lib/index.js.map +1 -1
- package/lib/logic/CustomError.d.ts +4 -0
- package/lib/logic/CustomError.d.ts.map +1 -1
- package/lib/logic/CustomError.js +17 -1
- package/lib/logic/CustomError.js.map +1 -1
- package/lib/logic/solidLogicSingleton.d.ts +35 -3
- package/lib/logic/solidLogicSingleton.d.ts.map +1 -1
- package/lib/logic/solidLogicSingleton.js +87 -8
- package/lib/logic/solidLogicSingleton.js.map +1 -1
- package/lib/profile/profileLogic.d.ts +13 -0
- package/lib/profile/profileLogic.d.ts.map +1 -0
- package/lib/profile/profileLogic.js +268 -0
- package/lib/profile/profileLogic.js.map +1 -0
- package/lib/typeIndex/typeIndexLogic.d.ts +31 -21
- package/lib/typeIndex/typeIndexLogic.d.ts.map +1 -1
- package/lib/typeIndex/typeIndexLogic.js +650 -295
- package/lib/typeIndex/typeIndexLogic.js.map +1 -1
- package/lib/types.d.ts +17 -0
- package/lib/types.d.ts.map +1 -1
- package/lib/util/containerLogic.d.ts +11 -0
- package/lib/util/containerLogic.d.ts.map +1 -0
- package/lib/{profile/ProfileLogic.js → util/containerLogic.js} +53 -44
- package/lib/util/containerLogic.js.map +1 -0
- package/lib/util/utilityLogic.d.ts +15 -0
- package/lib/util/utilityLogic.d.ts.map +1 -0
- package/lib/util/utilityLogic.js +272 -0
- package/lib/util/utilityLogic.js.map +1 -0
- package/lib/util/utils.d.ts +8 -0
- package/lib/util/utils.d.ts.map +1 -0
- package/lib/util/utils.js +48 -0
- package/lib/util/utils.js.map +1 -0
- package/package.json +3 -1
- package/src/acl/aclLogic.ts +135 -119
- package/src/authn/SolidAuthnLogic.ts +3 -2
- package/src/chat/chatLogic.ts +225 -0
- package/src/discovery/discoveryLogic.ts +66 -87
- package/src/inbox/inboxLogic.ts +57 -0
- package/src/index.ts +74 -21
- package/src/logic/CustomError.ts +5 -1
- package/src/logic/solidLogicSingleton.ts +160 -7
- package/src/profile/profileLogic.ts +134 -0
- package/src/typeIndex/typeIndexLogic.ts +417 -153
- package/src/types.ts +7 -3
- package/src/util/containerLogic.ts +54 -0
- package/src/util/ns.js +5 -0
- package/src/util/utilityLogic.ts +155 -0
- package/src/util/utils.ts +52 -0
- package/test/aclLogic.test.ts +13 -4
- package/test/chatLogic.test.ts +70 -71
- package/test/container.test.ts +56 -0
- package/test/discoveryLogic.test.ts +14 -14
- package/test/helpers/dataSetup.ts +134 -0
- package/test/helpers/setup.ts +4 -0
- package/test/inboxLogic.test.ts +39 -38
- package/test/logic.test.ts +11 -9
- package/test/profileLogic.test.ts +246 -0
- package/test/typeIndexLogic.test.ts +49 -22
- package/test/typeIndexLogicPart2.test.ts +485 -0
- package/test/utilityLogic.test.ts +172 -126
- package/test/utils.test.ts +32 -0
- package/lib/chat/ChatLogic.d.ts +0 -26
- package/lib/chat/ChatLogic.d.ts.map +0 -1
- package/lib/chat/ChatLogic.js.map +0 -1
- package/lib/chat/determineChatContainer.d.ts +0 -3
- package/lib/chat/determineChatContainer.d.ts.map +0 -1
- package/lib/chat/determineChatContainer.js +0 -12
- package/lib/chat/determineChatContainer.js.map +0 -1
- package/lib/inbox/InboxLogic.d.ts +0 -18
- package/lib/inbox/InboxLogic.d.ts.map +0 -1
- package/lib/inbox/InboxLogic.js.map +0 -1
- package/lib/logic/SolidLogic.d.ts +0 -48
- package/lib/logic/SolidLogic.d.ts.map +0 -1
- package/lib/logic/SolidLogic.js +0 -321
- package/lib/logic/SolidLogic.js.map +0 -1
- package/lib/profile/ProfileLogic.d.ts +0 -13
- package/lib/profile/ProfileLogic.d.ts.map +0 -1
- package/lib/profile/ProfileLogic.js.map +0 -1
- package/lib/util/UtilityLogic.d.ts +0 -33
- package/lib/util/UtilityLogic.d.ts.map +0 -1
- package/lib/util/UtilityLogic.js +0 -240
- package/lib/util/UtilityLogic.js.map +0 -1
- package/lib/util/uri.d.ts +0 -3
- package/lib/util/uri.d.ts.map +0 -1
- package/lib/util/uri.js +0 -9
- package/lib/util/uri.js.map +0 -1
- package/src/chat/ChatLogic.ts +0 -244
- package/src/chat/determineChatContainer.ts +0 -14
- package/src/inbox/InboxLogic.ts +0 -66
- package/src/logic/SolidLogic.ts +0 -262
- package/src/profile/ProfileLogic.ts +0 -44
- package/src/util/UtilityLogic.ts +0 -161
- package/src/util/uri.ts +0 -5
|
@@ -58,311 +58,666 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
58
58
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
62
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
63
|
-
};
|
|
64
61
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
-
exports.
|
|
62
|
+
exports.createTypeIndexLogic = void 0;
|
|
63
|
+
var rdf = __importStar(require("rdflib"));
|
|
66
64
|
var rdflib_1 = require("rdflib");
|
|
67
65
|
var debug = __importStar(require("../util/debug"));
|
|
68
|
-
var
|
|
69
|
-
var
|
|
70
|
-
|
|
71
|
-
var
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
66
|
+
var ns_1 = require("../util/ns");
|
|
67
|
+
var utils_1 = require("../util/utils");
|
|
68
|
+
function createTypeIndexLogic(store, authn, profileLogic, utilityLogic) {
|
|
69
|
+
var ns = ns_1.ns;
|
|
70
|
+
function updatePromise(del, ins) {
|
|
71
|
+
if (ins === void 0) { ins = []; }
|
|
72
|
+
return new Promise(function (resolve, reject) {
|
|
73
|
+
store.updater.update(del, ins, function (_uri, ok, errorBody) {
|
|
74
|
+
if (!ok) {
|
|
75
|
+
reject(new Error(errorBody));
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
resolve();
|
|
79
|
+
}
|
|
80
|
+
}); // callback
|
|
81
|
+
}); // promise
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Resolves with the same context, outputting
|
|
85
|
+
* @see https://github.com/solidos/solid/blob/main/proposals/data-discovery.md#discoverability
|
|
86
|
+
*/
|
|
87
|
+
function ensureTypeIndexes(context, agent) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
89
|
+
return __generator(this, function (_a) {
|
|
90
|
+
switch (_a.label) {
|
|
91
|
+
case 0:
|
|
92
|
+
if (!context.me) {
|
|
93
|
+
throw new Error("ensureTypeIndexes: @@ no user");
|
|
94
|
+
}
|
|
95
|
+
return [4 /*yield*/, ensureOneTypeIndex(context, true, agent)];
|
|
96
|
+
case 1:
|
|
97
|
+
_a.sent();
|
|
98
|
+
return [4 /*yield*/, ensureOneTypeIndex(context, false, agent)];
|
|
99
|
+
case 2:
|
|
100
|
+
_a.sent();
|
|
101
|
+
return [2 /*return*/, context];
|
|
102
|
+
}
|
|
103
|
+
});
|
|
94
104
|
});
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
105
|
+
}
|
|
106
|
+
function loadTypeIndexes(context) {
|
|
107
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
108
|
+
var error_1, indexes, error_2;
|
|
109
|
+
var _this = this;
|
|
110
|
+
return __generator(this, function (_a) {
|
|
111
|
+
switch (_a.label) {
|
|
112
|
+
case 0:
|
|
113
|
+
_a.trys.push([0, 2, , 3]);
|
|
114
|
+
return [4 /*yield*/, profileLogic.silencedLoadPreferences(context.me)];
|
|
115
|
+
case 1:
|
|
116
|
+
_a.sent();
|
|
117
|
+
return [3 /*break*/, 3];
|
|
118
|
+
case 2:
|
|
119
|
+
error_1 = _a.sent();
|
|
120
|
+
debug.warn(error_1.message);
|
|
121
|
+
return [3 /*break*/, 3];
|
|
122
|
+
case 3:
|
|
123
|
+
_a.trys.push([3, 5, , 6]);
|
|
124
|
+
return [4 /*yield*/, loadIndexes(context.me, context.publicProfile || null, context.preferencesFile || null)];
|
|
125
|
+
case 4:
|
|
126
|
+
indexes = _a.sent();
|
|
127
|
+
context.index = context.index || {};
|
|
128
|
+
context.index.private = indexes.private || context.index.private;
|
|
129
|
+
context.index.public = indexes.public || context.index.public;
|
|
130
|
+
return [2 /*return*/, context];
|
|
131
|
+
case 5:
|
|
132
|
+
error_2 = _a.sent();
|
|
133
|
+
(function (error) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
134
|
+
return [2 /*return*/, debug.warn(error.message)];
|
|
135
|
+
}); }); });
|
|
136
|
+
return [3 /*break*/, 6];
|
|
137
|
+
case 6: return [2 /*return*/];
|
|
138
|
+
}
|
|
139
|
+
});
|
|
121
140
|
});
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Register a new app in a type index
|
|
144
|
+
* used in chat in bookmark.js (solid-ui)
|
|
145
|
+
*/
|
|
146
|
+
function registerInTypeIndex(context, instance, theClass, isPublic, agent // Defaults to current user
|
|
147
|
+
) {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
149
|
+
var indexes, index, registration, ins, e_1;
|
|
150
|
+
return __generator(this, function (_a) {
|
|
151
|
+
switch (_a.label) {
|
|
152
|
+
case 0: return [4 /*yield*/, ensureOneTypeIndex(context, isPublic, agent)];
|
|
153
|
+
case 1:
|
|
154
|
+
_a.sent();
|
|
155
|
+
if (!context.index) {
|
|
156
|
+
throw new Error('registerInTypeIndex: No type index found');
|
|
157
|
+
}
|
|
158
|
+
indexes = isPublic ? context.index.public : context.index.private;
|
|
159
|
+
if (!indexes.length) {
|
|
160
|
+
throw new Error('registerInTypeIndex: What no type index?');
|
|
161
|
+
}
|
|
162
|
+
index = indexes[0];
|
|
163
|
+
registration = (0, utils_1.newThing)(index);
|
|
164
|
+
ins = [
|
|
165
|
+
// See https://github.com/solidos/solid/blob/main/proposals/data-discovery.md
|
|
166
|
+
(0, rdflib_1.st)(registration, ns.rdf('type'), ns.solid('TypeRegistration'), index),
|
|
167
|
+
(0, rdflib_1.st)(registration, ns.solid('forClass'), theClass, index),
|
|
168
|
+
(0, rdflib_1.st)(registration, ns.solid('instance'), instance, index)
|
|
169
|
+
];
|
|
170
|
+
_a.label = 2;
|
|
171
|
+
case 2:
|
|
172
|
+
_a.trys.push([2, 4, , 5]);
|
|
173
|
+
return [4 /*yield*/, updatePromise([], ins)];
|
|
174
|
+
case 3:
|
|
175
|
+
_a.sent();
|
|
176
|
+
return [3 /*break*/, 5];
|
|
177
|
+
case 4:
|
|
178
|
+
e_1 = _a.sent();
|
|
179
|
+
debug.log(e_1);
|
|
180
|
+
alert(e_1);
|
|
181
|
+
return [3 /*break*/, 5];
|
|
182
|
+
case 5: return [2 /*return*/, context];
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Resolves with the same context, outputting
|
|
189
|
+
* output: index.public, index.private
|
|
190
|
+
* @@ This is a very bizare function
|
|
191
|
+
* @see https://github.com/solidos/solid/blob/main/proposals/data-discovery.md#discoverability
|
|
192
|
+
*/
|
|
193
|
+
function loadIndex(context, isPublic) {
|
|
194
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
195
|
+
var indexes;
|
|
196
|
+
var _this = this;
|
|
197
|
+
return __generator(this, function (_a) {
|
|
198
|
+
switch (_a.label) {
|
|
199
|
+
case 0: return [4 /*yield*/, loadIndexes(context.me, (isPublic ? context.publicProfile || null : null), (isPublic ? null : context.preferencesFile || null),
|
|
200
|
+
// async (err: Error) => widgets.complain(context, err.message)
|
|
201
|
+
function (err) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
202
|
+
return [2 /*return*/, debug.error(err.message)];
|
|
203
|
+
}); }); })];
|
|
204
|
+
case 1:
|
|
205
|
+
indexes = _a.sent();
|
|
206
|
+
context.index = context.index || {};
|
|
207
|
+
context.index.private = indexes.private.concat(context.index.private || []); // otherwise concat will wrongly add 'undefined' as a private index
|
|
208
|
+
context.index.public = indexes.public.concat(context.index.public || []); // otherwise concat will wrongly add 'undefined' as a public index
|
|
209
|
+
return [2 /*return*/, context];
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Load or create ONE type index
|
|
216
|
+
* Find one or make one or fail
|
|
217
|
+
* Many reasons for failing including script not having permission etc
|
|
218
|
+
*
|
|
219
|
+
* Adds its output to the context
|
|
220
|
+
* @see https://github.com/solidos/solid/blob/main/proposals/data-discovery.md#discoverability
|
|
221
|
+
*/
|
|
222
|
+
function ensureOneTypeIndex(context, isPublic, agent) {
|
|
223
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
224
|
+
var context2, relevant, pp, error_3;
|
|
225
|
+
return __generator(this, function (_a) {
|
|
226
|
+
switch (_a.label) {
|
|
227
|
+
case 0: return [4 /*yield*/, profileLogic.ensureLoadedPreferences(context)];
|
|
228
|
+
case 1:
|
|
229
|
+
context2 = _a.sent();
|
|
230
|
+
if (!context2.publicProfile)
|
|
231
|
+
throw new Error("@@ type index: no publicProfile");
|
|
232
|
+
if (!context2.preferencesFile)
|
|
233
|
+
throw new Error("@@ type index: no preferencesFile for profile ".concat(context2.publicProfile));
|
|
234
|
+
relevant = isPublic ? context2.publicProfile : context2.preferencesFile;
|
|
235
|
+
_a.label = 2;
|
|
236
|
+
case 2:
|
|
237
|
+
_a.trys.push([2, 5, , 7]);
|
|
238
|
+
return [4 /*yield*/, loadIndex(context2, isPublic)];
|
|
239
|
+
case 3:
|
|
240
|
+
_a.sent();
|
|
241
|
+
pp = isPublic ? 'public' : 'private';
|
|
242
|
+
if (context2.index && context2.index[pp] && context2.index[pp].length > 0) {
|
|
243
|
+
debug.log("ensureOneTypeIndex: Type index exists already ".concat(context2.index[pp]));
|
|
244
|
+
return [2 /*return*/, context2];
|
|
245
|
+
}
|
|
246
|
+
return [4 /*yield*/, makeIndexIfNecessary(context2, isPublic, store, ns)];
|
|
247
|
+
case 4:
|
|
248
|
+
_a.sent();
|
|
249
|
+
return [3 /*break*/, 7];
|
|
250
|
+
case 5:
|
|
251
|
+
error_3 = _a.sent();
|
|
252
|
+
return [4 /*yield*/, makeIndexIfNecessary(context2, isPublic, store, ns)
|
|
253
|
+
// widgets.complain(context2, 'calling loadIndex:' + error)
|
|
254
|
+
];
|
|
255
|
+
case 6:
|
|
256
|
+
_a.sent();
|
|
257
|
+
return [3 /*break*/, 7];
|
|
258
|
+
case 7: return [2 /*return*/];
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
function putIndex(newIndex, context) {
|
|
264
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
265
|
+
var e_2, msg;
|
|
266
|
+
return __generator(this, function (_a) {
|
|
267
|
+
switch (_a.label) {
|
|
268
|
+
case 0:
|
|
269
|
+
_a.trys.push([0, 2, , 3]);
|
|
270
|
+
return [4 /*yield*/, utilityLogic.createEmptyRdfDoc(newIndex, 'Blank initial Type index')];
|
|
271
|
+
case 1:
|
|
272
|
+
_a.sent();
|
|
273
|
+
return [2 /*return*/, context];
|
|
274
|
+
case 2:
|
|
275
|
+
e_2 = _a.sent();
|
|
276
|
+
msg = "Error creating new index ".concat(e_2);
|
|
277
|
+
// widgets.complain(context, msg)
|
|
278
|
+
debug.warn(msg);
|
|
279
|
+
return [3 /*break*/, 3];
|
|
280
|
+
case 3: return [2 /*return*/];
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
} // putIndex
|
|
285
|
+
function makeIndexIfNecessary(context, isPublic, store, ns) {
|
|
286
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
287
|
+
var relevant, visibility, newIndex, addMe, err_1, msg, ixs, err_2, msg;
|
|
288
|
+
return __generator(this, function (_a) {
|
|
289
|
+
switch (_a.label) {
|
|
290
|
+
case 0:
|
|
291
|
+
relevant = isPublic ? context.publicProfile : context.preferencesFile;
|
|
292
|
+
if (!relevant)
|
|
293
|
+
alert('@@@@ relevent null');
|
|
294
|
+
visibility = isPublic ? 'public' : 'private';
|
|
295
|
+
context.index = context.index || {};
|
|
296
|
+
context.index[visibility] = context.index[visibility] || [];
|
|
297
|
+
if (!(context.index[visibility].length === 0)) return [3 /*break*/, 6];
|
|
298
|
+
if (!store.updater.editable(relevant)) {
|
|
299
|
+
debug.log("Not adding new type index as ".concat(relevant, " is not editable"));
|
|
300
|
+
return [2 /*return*/];
|
|
301
|
+
}
|
|
302
|
+
newIndex = rdf.sym("".concat(relevant.dir().uri + visibility, "TypeIndex.ttl"));
|
|
303
|
+
debug.log("Linking to new fresh type index ".concat(newIndex));
|
|
304
|
+
if (!confirm("OK to create a new empty index file at ".concat(newIndex, ", overwriting anything that is now there?"))) {
|
|
305
|
+
throw new Error('cancelled by user');
|
|
306
|
+
}
|
|
307
|
+
debug.log("Linking to new fresh type index ".concat(newIndex));
|
|
308
|
+
addMe = [
|
|
309
|
+
(0, rdflib_1.st)(context.me, ns.solid("".concat(visibility, "TypeIndex")), newIndex, relevant)
|
|
310
|
+
];
|
|
311
|
+
_a.label = 1;
|
|
312
|
+
case 1:
|
|
313
|
+
_a.trys.push([1, 3, , 4]);
|
|
314
|
+
return [4 /*yield*/, updatePromise([], addMe)];
|
|
315
|
+
case 2:
|
|
316
|
+
_a.sent();
|
|
317
|
+
return [3 /*break*/, 4];
|
|
318
|
+
case 3:
|
|
319
|
+
err_1 = _a.sent();
|
|
320
|
+
msg = "Error saving type index link saving back ".concat(newIndex, ": ").concat(err_1);
|
|
321
|
+
//widgets.complain(context, msg)
|
|
322
|
+
debug.warn(msg);
|
|
323
|
+
return [2 /*return*/, context];
|
|
324
|
+
case 4:
|
|
325
|
+
debug.log("Creating new fresh type index file".concat(newIndex));
|
|
326
|
+
return [4 /*yield*/, putIndex(newIndex, context)];
|
|
327
|
+
case 5:
|
|
328
|
+
_a.sent();
|
|
329
|
+
context.index[visibility].push(newIndex); // @@ wait
|
|
330
|
+
return [3 /*break*/, 10];
|
|
331
|
+
case 6:
|
|
332
|
+
ixs = context.index[visibility];
|
|
333
|
+
_a.label = 7;
|
|
334
|
+
case 7:
|
|
335
|
+
_a.trys.push([7, 9, , 10]);
|
|
336
|
+
return [4 /*yield*/, store.fetcher.load(ixs)];
|
|
337
|
+
case 8:
|
|
338
|
+
_a.sent();
|
|
339
|
+
return [3 /*break*/, 10];
|
|
340
|
+
case 9:
|
|
341
|
+
err_2 = _a.sent();
|
|
342
|
+
msg = "ensureOneTypeIndex: loading indexes ".concat(err_2);
|
|
343
|
+
debug.warn(msg);
|
|
344
|
+
return [3 /*break*/, 10];
|
|
345
|
+
case 10: return [2 /*return*/];
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
} // makeIndexIfNecessary
|
|
350
|
+
function loadIndexes(me, publicProfile, preferencesFile, onWarning) {
|
|
128
351
|
var _this = this;
|
|
129
|
-
return
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
return [
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
352
|
+
if (onWarning === void 0) { onWarning = function (_err) { return __awaiter(_this, void 0, void 0, function () {
|
|
353
|
+
return __generator(this, function (_a) {
|
|
354
|
+
return [2 /*return*/, undefined];
|
|
355
|
+
});
|
|
356
|
+
}); }; }
|
|
357
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
358
|
+
var privateIndexes, publicIndexes, err_3, err_4;
|
|
359
|
+
return __generator(this, function (_a) {
|
|
360
|
+
switch (_a.label) {
|
|
361
|
+
case 0:
|
|
362
|
+
privateIndexes = [];
|
|
363
|
+
publicIndexes = [];
|
|
364
|
+
if (!publicProfile) return [3 /*break*/, 4];
|
|
365
|
+
publicIndexes = getTypeIndex(me, publicProfile, true);
|
|
366
|
+
_a.label = 1;
|
|
367
|
+
case 1:
|
|
368
|
+
_a.trys.push([1, 3, , 4]);
|
|
369
|
+
return [4 /*yield*/, store.fetcher.load(publicIndexes)];
|
|
370
|
+
case 2:
|
|
371
|
+
_a.sent();
|
|
372
|
+
return [3 /*break*/, 4];
|
|
373
|
+
case 3:
|
|
374
|
+
err_3 = _a.sent();
|
|
375
|
+
onWarning(new Error("loadIndex: loading public type index(es) ".concat(err_3)));
|
|
376
|
+
return [3 /*break*/, 4];
|
|
377
|
+
case 4:
|
|
378
|
+
if (!preferencesFile) return [3 /*break*/, 9];
|
|
379
|
+
privateIndexes = getTypeIndex(me, preferencesFile, false);
|
|
380
|
+
if (!(privateIndexes.length === 0)) return [3 /*break*/, 6];
|
|
381
|
+
return [4 /*yield*/, onWarning(new Error("Your preference file ".concat(preferencesFile, " does not point to a private type index.")))];
|
|
382
|
+
case 5:
|
|
383
|
+
_a.sent();
|
|
384
|
+
return [3 /*break*/, 9];
|
|
385
|
+
case 6:
|
|
386
|
+
_a.trys.push([6, 8, , 9]);
|
|
387
|
+
return [4 /*yield*/, store.fetcher.load(privateIndexes)];
|
|
388
|
+
case 7:
|
|
389
|
+
_a.sent();
|
|
390
|
+
return [3 /*break*/, 9];
|
|
391
|
+
case 8:
|
|
392
|
+
err_4 = _a.sent();
|
|
393
|
+
onWarning(new Error("loadIndex: loading private type index(es) ".concat(err_4)));
|
|
394
|
+
return [3 /*break*/, 9];
|
|
395
|
+
case 9: return [2 /*return*/, {
|
|
396
|
+
private: privateIndexes,
|
|
397
|
+
public: publicIndexes,
|
|
398
|
+
}];
|
|
399
|
+
}
|
|
400
|
+
});
|
|
158
401
|
});
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
switch (_a.label) {
|
|
170
|
-
case 0:
|
|
171
|
-
if (!context.me) {
|
|
172
|
-
throw new Error("ensureTypeIndexes: @@ no user");
|
|
173
|
-
}
|
|
174
|
-
return [4 /*yield*/, ensureOneTypeIndex(context, true, agent)];
|
|
175
|
-
case 1:
|
|
176
|
-
_a.sent();
|
|
177
|
-
return [4 /*yield*/, ensureOneTypeIndex(context, false, agent)];
|
|
178
|
-
case 2:
|
|
179
|
-
_a.sent();
|
|
180
|
-
return [2 /*return*/, context];
|
|
181
|
-
}
|
|
402
|
+
}
|
|
403
|
+
function getTypeIndex(me, preferencesFile, isPublic) {
|
|
404
|
+
// console.log('getTypeIndex', store.each(me, undefined, undefined, preferencesFile), isPublic, preferencesFile)
|
|
405
|
+
return store.each(me, isPublic ? ns.solid("publicTypeIndex") : ns.solid("privateTypeIndex"), undefined, preferencesFile);
|
|
406
|
+
}
|
|
407
|
+
function getRegistrations(instance, theClass) {
|
|
408
|
+
return store
|
|
409
|
+
.each(undefined, ns.solid("instance"), instance)
|
|
410
|
+
.filter(function (r) {
|
|
411
|
+
return store.holds(r, ns.solid("forClass"), theClass);
|
|
182
412
|
});
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
_a.label = 7;
|
|
267
|
-
case 7:
|
|
268
|
-
_a.trys.push([7, 9, , 10]);
|
|
269
|
-
return [4 /*yield*/, solidLogicSingleton_1.solidLogicSingleton.load(ixs)];
|
|
270
|
-
case 8:
|
|
271
|
-
_a.sent();
|
|
272
|
-
return [3 /*break*/, 10];
|
|
273
|
-
case 9:
|
|
274
|
-
err_2 = _a.sent();
|
|
275
|
-
msg = "ensureOneTypeIndex: loading indexes ".concat(err_2);
|
|
276
|
-
debug.warn(msg);
|
|
277
|
-
return [3 /*break*/, 10];
|
|
278
|
-
case 10: return [2 /*return*/];
|
|
279
|
-
}
|
|
280
|
-
});
|
|
413
|
+
}
|
|
414
|
+
function loadTypeIndexesFor(user) {
|
|
415
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
416
|
+
var profile, suggestion, publicTypeIndex, err_5, message, publicScopes, preferencesFile, err_6, privateScopes, suggestedPrivateTypeIndex, privateTypeIndex, _a, err_7, message, scopes, files, err_8;
|
|
417
|
+
return __generator(this, function (_b) {
|
|
418
|
+
switch (_b.label) {
|
|
419
|
+
case 0:
|
|
420
|
+
if (!user)
|
|
421
|
+
throw new Error("loadTypeIndexesFor: No user given");
|
|
422
|
+
return [4 /*yield*/, profileLogic.loadProfile(user)];
|
|
423
|
+
case 1:
|
|
424
|
+
profile = _b.sent();
|
|
425
|
+
suggestion = suggestPublicTypeIndex(user);
|
|
426
|
+
_b.label = 2;
|
|
427
|
+
case 2:
|
|
428
|
+
_b.trys.push([2, 4, , 5]);
|
|
429
|
+
return [4 /*yield*/, utilityLogic.followOrCreateLink(user, ns.solid('publicTypeIndex'), suggestion, profile)];
|
|
430
|
+
case 3:
|
|
431
|
+
publicTypeIndex = _b.sent();
|
|
432
|
+
return [3 /*break*/, 5];
|
|
433
|
+
case 4:
|
|
434
|
+
err_5 = _b.sent();
|
|
435
|
+
message = "User ".concat(user, " has no pointer in profile to publicTypeIndex file.");
|
|
436
|
+
debug.warn(message);
|
|
437
|
+
return [3 /*break*/, 5];
|
|
438
|
+
case 5:
|
|
439
|
+
publicScopes = publicTypeIndex ? [{ label: 'public', index: publicTypeIndex, agent: user }] : [];
|
|
440
|
+
_b.label = 6;
|
|
441
|
+
case 6:
|
|
442
|
+
_b.trys.push([6, 8, , 9]);
|
|
443
|
+
return [4 /*yield*/, profileLogic.silencedLoadPreferences(user)];
|
|
444
|
+
case 7:
|
|
445
|
+
preferencesFile = _b.sent();
|
|
446
|
+
return [3 /*break*/, 9];
|
|
447
|
+
case 8:
|
|
448
|
+
err_6 = _b.sent();
|
|
449
|
+
preferencesFile = null;
|
|
450
|
+
return [3 /*break*/, 9];
|
|
451
|
+
case 9:
|
|
452
|
+
if (!preferencesFile) return [3 /*break*/, 15];
|
|
453
|
+
suggestedPrivateTypeIndex = suggestPrivateTypeIndex(preferencesFile);
|
|
454
|
+
privateTypeIndex = void 0;
|
|
455
|
+
_b.label = 10;
|
|
456
|
+
case 10:
|
|
457
|
+
_b.trys.push([10, 13, , 14]);
|
|
458
|
+
_a = store.any(user, ns.solid('privateTypeIndex'), undefined, profile);
|
|
459
|
+
if (_a) return [3 /*break*/, 12];
|
|
460
|
+
return [4 /*yield*/, utilityLogic.followOrCreateLink(user, ns.solid('privateTypeIndex'), suggestedPrivateTypeIndex, preferencesFile)];
|
|
461
|
+
case 11:
|
|
462
|
+
_a = (_b.sent());
|
|
463
|
+
_b.label = 12;
|
|
464
|
+
case 12:
|
|
465
|
+
privateTypeIndex = _a;
|
|
466
|
+
return [3 /*break*/, 14];
|
|
467
|
+
case 13:
|
|
468
|
+
err_7 = _b.sent();
|
|
469
|
+
message = "User ".concat(user, " has no pointer in preference file to privateTypeIndex file.");
|
|
470
|
+
debug.warn(message);
|
|
471
|
+
return [3 /*break*/, 14];
|
|
472
|
+
case 14:
|
|
473
|
+
privateScopes = privateTypeIndex ? [{ label: 'private', index: privateTypeIndex, agent: user }] : [];
|
|
474
|
+
return [3 /*break*/, 16];
|
|
475
|
+
case 15:
|
|
476
|
+
privateScopes = [];
|
|
477
|
+
_b.label = 16;
|
|
478
|
+
case 16:
|
|
479
|
+
scopes = publicScopes.concat(privateScopes);
|
|
480
|
+
if (scopes.length === 0)
|
|
481
|
+
return [2 /*return*/, scopes];
|
|
482
|
+
files = scopes.map(function (scope) { return scope.index; });
|
|
483
|
+
_b.label = 17;
|
|
484
|
+
case 17:
|
|
485
|
+
_b.trys.push([17, 19, , 20]);
|
|
486
|
+
return [4 /*yield*/, store.fetcher.load(files)];
|
|
487
|
+
case 18:
|
|
488
|
+
_b.sent();
|
|
489
|
+
return [3 /*break*/, 20];
|
|
490
|
+
case 19:
|
|
491
|
+
err_8 = _b.sent();
|
|
492
|
+
debug.warn('Problems loading type index: ', err_8);
|
|
493
|
+
return [3 /*break*/, 20];
|
|
494
|
+
case 20: return [2 /*return*/, scopes];
|
|
495
|
+
}
|
|
281
496
|
});
|
|
282
|
-
} // makeIndexIfNecessary
|
|
283
|
-
var context2, relevant, pp, error_3;
|
|
284
|
-
return __generator(this, function (_a) {
|
|
285
|
-
switch (_a.label) {
|
|
286
|
-
case 0: return [4 /*yield*/, ensureLoadedPreferences(context)];
|
|
287
|
-
case 1:
|
|
288
|
-
context2 = _a.sent();
|
|
289
|
-
if (!context2.publicProfile)
|
|
290
|
-
throw new Error("@@ type index: no publicProfile");
|
|
291
|
-
if (!context2.preferencesFile)
|
|
292
|
-
throw new Error("@@ type index: no preferencesFile for profile ".concat(context2.publicProfile));
|
|
293
|
-
relevant = isPublic ? context2.publicProfile : context2.preferencesFile;
|
|
294
|
-
_a.label = 2;
|
|
295
|
-
case 2:
|
|
296
|
-
_a.trys.push([2, 5, , 7]);
|
|
297
|
-
return [4 /*yield*/, loadIndex(context2, isPublic)];
|
|
298
|
-
case 3:
|
|
299
|
-
_a.sent();
|
|
300
|
-
pp = isPublic ? 'public' : 'private';
|
|
301
|
-
if (context2.index && context2.index[pp] && context2.index[pp].length > 0) {
|
|
302
|
-
debug.log("ensureOneTypeIndex: Type index exists already ".concat(context2.index[pp]));
|
|
303
|
-
return [2 /*return*/, context2];
|
|
304
|
-
}
|
|
305
|
-
return [4 /*yield*/, makeIndexIfNecessary(context2, isPublic)];
|
|
306
|
-
case 4:
|
|
307
|
-
_a.sent();
|
|
308
|
-
return [3 /*break*/, 7];
|
|
309
|
-
case 5:
|
|
310
|
-
error_3 = _a.sent();
|
|
311
|
-
return [4 /*yield*/, makeIndexIfNecessary(context2, isPublic)
|
|
312
|
-
// widgets.complain(context2, 'calling loadIndex:' + error)
|
|
313
|
-
];
|
|
314
|
-
case 6:
|
|
315
|
-
_a.sent();
|
|
316
|
-
return [3 /*break*/, 7];
|
|
317
|
-
case 7: return [2 /*return*/];
|
|
318
|
-
}
|
|
319
497
|
});
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
)
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
e_2 = _a.sent();
|
|
359
|
-
debug.log(e_2);
|
|
360
|
-
alert(e_2);
|
|
361
|
-
return [3 /*break*/, 5];
|
|
362
|
-
case 5: return [2 /*return*/, context];
|
|
363
|
-
}
|
|
498
|
+
}
|
|
499
|
+
function loadCommunityTypeIndexes(user) {
|
|
500
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
501
|
+
var preferencesFile, err_9, message, communities, result, _i, communities_1, org, _a, _b;
|
|
502
|
+
return __generator(this, function (_c) {
|
|
503
|
+
switch (_c.label) {
|
|
504
|
+
case 0:
|
|
505
|
+
_c.trys.push([0, 2, , 3]);
|
|
506
|
+
return [4 /*yield*/, profileLogic.silencedLoadPreferences(user)];
|
|
507
|
+
case 1:
|
|
508
|
+
preferencesFile = _c.sent();
|
|
509
|
+
return [3 /*break*/, 3];
|
|
510
|
+
case 2:
|
|
511
|
+
err_9 = _c.sent();
|
|
512
|
+
message = "User ".concat(user, " has no pointer in profile to preferences file.");
|
|
513
|
+
debug.warn(message);
|
|
514
|
+
return [3 /*break*/, 3];
|
|
515
|
+
case 3:
|
|
516
|
+
if (!preferencesFile) return [3 /*break*/, 8];
|
|
517
|
+
communities = store.each(user, ns.solid('community'), undefined, preferencesFile).concat(store.each(user, ns.solid('community'), undefined, user.doc()));
|
|
518
|
+
result = [];
|
|
519
|
+
_i = 0, communities_1 = communities;
|
|
520
|
+
_c.label = 4;
|
|
521
|
+
case 4:
|
|
522
|
+
if (!(_i < communities_1.length)) return [3 /*break*/, 7];
|
|
523
|
+
org = communities_1[_i];
|
|
524
|
+
_b = (_a = result).concat;
|
|
525
|
+
return [4 /*yield*/, loadTypeIndexesFor(org)];
|
|
526
|
+
case 5:
|
|
527
|
+
result = _b.apply(_a, [_c.sent()]);
|
|
528
|
+
_c.label = 6;
|
|
529
|
+
case 6:
|
|
530
|
+
_i++;
|
|
531
|
+
return [3 /*break*/, 4];
|
|
532
|
+
case 7: return [2 /*return*/, result];
|
|
533
|
+
case 8: return [2 /*return*/, []]; // No communities
|
|
534
|
+
}
|
|
535
|
+
});
|
|
364
536
|
});
|
|
365
|
-
}
|
|
537
|
+
}
|
|
538
|
+
function loadAllTypeIndexes(user) {
|
|
539
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
540
|
+
var _a, _b;
|
|
541
|
+
return __generator(this, function (_c) {
|
|
542
|
+
switch (_c.label) {
|
|
543
|
+
case 0: return [4 /*yield*/, loadTypeIndexesFor(user)];
|
|
544
|
+
case 1:
|
|
545
|
+
_b = (_a = (_c.sent())).concat;
|
|
546
|
+
return [4 /*yield*/, loadCommunityTypeIndexes(user)];
|
|
547
|
+
case 2: return [2 /*return*/, _b.apply(_a, [(_c.sent()).flat()])];
|
|
548
|
+
}
|
|
549
|
+
});
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
function getScopedAppInstances(klass, user) {
|
|
553
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
554
|
+
var scopes, scopedApps, _i, scopes_1, scope, scopedApps0;
|
|
555
|
+
return __generator(this, function (_a) {
|
|
556
|
+
switch (_a.label) {
|
|
557
|
+
case 0: return [4 /*yield*/, loadAllTypeIndexes(user)];
|
|
558
|
+
case 1:
|
|
559
|
+
scopes = _a.sent();
|
|
560
|
+
scopedApps = [];
|
|
561
|
+
_i = 0, scopes_1 = scopes;
|
|
562
|
+
_a.label = 2;
|
|
563
|
+
case 2:
|
|
564
|
+
if (!(_i < scopes_1.length)) return [3 /*break*/, 5];
|
|
565
|
+
scope = scopes_1[_i];
|
|
566
|
+
return [4 /*yield*/, getScopedAppsFromIndex(scope, klass)];
|
|
567
|
+
case 3:
|
|
568
|
+
scopedApps0 = _a.sent();
|
|
569
|
+
scopedApps = scopedApps.concat(scopedApps0);
|
|
570
|
+
_a.label = 4;
|
|
571
|
+
case 4:
|
|
572
|
+
_i++;
|
|
573
|
+
return [3 /*break*/, 2];
|
|
574
|
+
case 5: return [2 /*return*/, scopedApps];
|
|
575
|
+
}
|
|
576
|
+
});
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
// This is the function signature which used to be in solid-ui/logic
|
|
580
|
+
// Recommended to use getScopedAppInstances instead as it provides more information.
|
|
581
|
+
//
|
|
582
|
+
function getAppInstances(klass) {
|
|
583
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
584
|
+
var user, scopedAppInstances;
|
|
585
|
+
return __generator(this, function (_a) {
|
|
586
|
+
switch (_a.label) {
|
|
587
|
+
case 0:
|
|
588
|
+
user = authn.currentUser();
|
|
589
|
+
if (!user)
|
|
590
|
+
throw new Error('getAppInstances: Must be logged in to find apps.');
|
|
591
|
+
return [4 /*yield*/, getScopedAppInstances(klass, user)];
|
|
592
|
+
case 1:
|
|
593
|
+
scopedAppInstances = _a.sent();
|
|
594
|
+
return [2 /*return*/, scopedAppInstances.map(function (scoped) { return scoped.instance; })];
|
|
595
|
+
}
|
|
596
|
+
});
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
function suggestPublicTypeIndex(me) {
|
|
600
|
+
var _a;
|
|
601
|
+
return (0, rdflib_1.sym)(((_a = me.doc().dir()) === null || _a === void 0 ? void 0 : _a.uri) + 'publicTypeIndex.ttl');
|
|
602
|
+
}
|
|
603
|
+
// Note this one is based off the pref file not the profile
|
|
604
|
+
function suggestPrivateTypeIndex(preferencesFile) {
|
|
605
|
+
var _a;
|
|
606
|
+
return (0, rdflib_1.sym)(((_a = preferencesFile.doc().dir()) === null || _a === void 0 ? void 0 : _a.uri) + 'privateTypeIndex.ttl');
|
|
607
|
+
}
|
|
608
|
+
/*
|
|
609
|
+
* Register a new app in a type index
|
|
610
|
+
* used in chat in bookmark.js (solid-ui)
|
|
611
|
+
* Returns the registration object if successful else null
|
|
612
|
+
*/
|
|
613
|
+
function registerInstanceInTypeIndex(instance, index, theClass) {
|
|
614
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
615
|
+
var registration, ins, err_10, msg;
|
|
616
|
+
return __generator(this, function (_a) {
|
|
617
|
+
switch (_a.label) {
|
|
618
|
+
case 0:
|
|
619
|
+
registration = (0, utils_1.newThing)(index);
|
|
620
|
+
ins = [
|
|
621
|
+
// See https://github.com/solid/solid/blob/main/proposals/data-discovery.md
|
|
622
|
+
(0, rdflib_1.st)(registration, ns.rdf('type'), ns.solid('TypeRegistration'), index),
|
|
623
|
+
(0, rdflib_1.st)(registration, ns.solid('forClass'), theClass, index),
|
|
624
|
+
(0, rdflib_1.st)(registration, ns.solid('instance'), instance, index)
|
|
625
|
+
];
|
|
626
|
+
_a.label = 1;
|
|
627
|
+
case 1:
|
|
628
|
+
_a.trys.push([1, 3, , 4]);
|
|
629
|
+
return [4 /*yield*/, store.updater.update([], ins)];
|
|
630
|
+
case 2:
|
|
631
|
+
_a.sent();
|
|
632
|
+
return [3 /*break*/, 4];
|
|
633
|
+
case 3:
|
|
634
|
+
err_10 = _a.sent();
|
|
635
|
+
msg = "Unable to register ".concat(instance, " in index ").concat(index, ": ").concat(err_10);
|
|
636
|
+
console.warn(msg);
|
|
637
|
+
return [2 /*return*/, null];
|
|
638
|
+
case 4: return [2 /*return*/, registration];
|
|
639
|
+
}
|
|
640
|
+
});
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
function deleteTypeIndexRegistration(item) {
|
|
644
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
645
|
+
var reg, statements;
|
|
646
|
+
return __generator(this, function (_a) {
|
|
647
|
+
switch (_a.label) {
|
|
648
|
+
case 0:
|
|
649
|
+
reg = store.the(null, ns.solid('instance'), item.instance, item.scope.index);
|
|
650
|
+
if (!reg)
|
|
651
|
+
throw new Error("deleteTypeIndexRegistration: No registration found for ".concat(item.instance));
|
|
652
|
+
statements = store.statementsMatching(reg, null, null, item.scope.index);
|
|
653
|
+
return [4 /*yield*/, store.updater.update(statements, [])];
|
|
654
|
+
case 1:
|
|
655
|
+
_a.sent();
|
|
656
|
+
return [2 /*return*/];
|
|
657
|
+
}
|
|
658
|
+
});
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
function getScopedAppsFromIndex(scope, theClass) {
|
|
662
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
663
|
+
var index, registrations, relevant, directInstances, instances, instanceContainers, containers, i, cont, contents;
|
|
664
|
+
return __generator(this, function (_a) {
|
|
665
|
+
switch (_a.label) {
|
|
666
|
+
case 0:
|
|
667
|
+
index = scope.index;
|
|
668
|
+
registrations = store.statementsMatching(null, ns.solid('instance'), null, index)
|
|
669
|
+
.concat(store.statementsMatching(null, ns.solid('instanceContainer'), null, index))
|
|
670
|
+
.map(function (st) { return st.subject; });
|
|
671
|
+
relevant = theClass ? registrations.filter(function (reg) { var _a; return (_a = store.any(reg, ns.solid('forClass'), null, index)) === null || _a === void 0 ? void 0 : _a.sameTerm(theClass); })
|
|
672
|
+
: registrations;
|
|
673
|
+
directInstances = relevant.map(function (reg) { return store.each(reg, ns.solid('instance'), null, index).map(function (one) { return (0, rdflib_1.sym)(one.value); }); }).flat();
|
|
674
|
+
instances = (0, utils_1.uniqueNodes)(directInstances);
|
|
675
|
+
instanceContainers = relevant.map(function (reg) { return store.each(reg, ns.solid('instanceContainer'), null, index).map(function (one) { return (0, rdflib_1.sym)(one.value); }); }).flat();
|
|
676
|
+
containers = (0, utils_1.uniqueNodes)(instanceContainers);
|
|
677
|
+
if (containers.length > 0) {
|
|
678
|
+
console.log('@@ getScopedAppsFromIndex containers ', containers);
|
|
679
|
+
}
|
|
680
|
+
i = 0;
|
|
681
|
+
_a.label = 1;
|
|
682
|
+
case 1:
|
|
683
|
+
if (!(i < containers.length)) return [3 /*break*/, 4];
|
|
684
|
+
cont = containers[i];
|
|
685
|
+
return [4 /*yield*/, store.fetcher.load(cont)];
|
|
686
|
+
case 2:
|
|
687
|
+
_a.sent();
|
|
688
|
+
contents = store.each(cont, ns.ldp('contains'), null, cont).map(function (one) { return (0, rdflib_1.sym)(one.value); });
|
|
689
|
+
instances = instances.concat(contents);
|
|
690
|
+
_a.label = 3;
|
|
691
|
+
case 3:
|
|
692
|
+
i++;
|
|
693
|
+
return [3 /*break*/, 1];
|
|
694
|
+
case 4: return [2 /*return*/, instances.map(function (instance) { return { instance: instance, scope: scope }; })];
|
|
695
|
+
}
|
|
696
|
+
});
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
return {
|
|
700
|
+
ensureTypeIndexes: ensureTypeIndexes,
|
|
701
|
+
loadTypeIndexes: loadTypeIndexes,
|
|
702
|
+
registerInTypeIndex: registerInTypeIndex,
|
|
703
|
+
loadIndex: loadIndex,
|
|
704
|
+
ensureOneTypeIndex: ensureOneTypeIndex,
|
|
705
|
+
putIndex: putIndex,
|
|
706
|
+
makeIndexIfNecessary: makeIndexIfNecessary,
|
|
707
|
+
loadIndexes: loadIndexes,
|
|
708
|
+
getTypeIndex: getTypeIndex,
|
|
709
|
+
getRegistrations: getRegistrations,
|
|
710
|
+
loadTypeIndexesFor: loadTypeIndexesFor,
|
|
711
|
+
loadCommunityTypeIndexes: loadCommunityTypeIndexes,
|
|
712
|
+
loadAllTypeIndexes: loadAllTypeIndexes,
|
|
713
|
+
getScopedAppInstances: getScopedAppInstances,
|
|
714
|
+
getAppInstances: getAppInstances,
|
|
715
|
+
suggestPublicTypeIndex: suggestPublicTypeIndex,
|
|
716
|
+
suggestPrivateTypeIndex: suggestPrivateTypeIndex,
|
|
717
|
+
registerInstanceInTypeIndex: registerInstanceInTypeIndex,
|
|
718
|
+
deleteTypeIndexRegistration: deleteTypeIndexRegistration,
|
|
719
|
+
getScopedAppsFromIndex: getScopedAppsFromIndex
|
|
720
|
+
};
|
|
366
721
|
}
|
|
367
|
-
exports.
|
|
722
|
+
exports.createTypeIndexLogic = createTypeIndexLogic;
|
|
368
723
|
//# sourceMappingURL=typeIndexLogic.js.map
|