solid-logic 1.3.17-f5eebe26 → 1.3.17-fca5749b
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 +152 -119
- 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/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 +18 -9
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +76 -22
- 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/SolidLogic.d.ts +8 -34
- package/lib/logic/SolidLogic.d.ts.map +1 -1
- package/lib/logic/SolidLogic.js +16 -250
- package/lib/logic/SolidLogic.js.map +1 -1
- package/lib/logic/solidLogicSingleton.js +1 -1
- package/lib/logic/solidLogicSingleton.js.map +1 -1
- package/lib/logic/solidLogicSingletonNew.d.ts +67 -0
- package/lib/logic/solidLogicSingletonNew.d.ts.map +1 -0
- package/lib/logic/solidLogicSingletonNew.js +219 -0
- package/lib/logic/solidLogicSingletonNew.js.map +1 -0
- package/lib/profile/profileLogic.d.ts +11 -0
- package/lib/profile/profileLogic.d.ts.map +1 -0
- package/lib/profile/profileLogic.js +246 -0
- package/lib/profile/profileLogic.js.map +1 -0
- package/lib/typeIndex/typeIndexLogic.d.ts +18 -21
- package/lib/typeIndex/typeIndexLogic.d.ts.map +1 -1
- package/lib/typeIndex/typeIndexLogic.js +304 -296
- 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/ns.d.ts +2 -0
- package/lib/util/ns.d.ts.map +1 -0
- package/lib/util/ns.js +34 -0
- package/lib/util/ns.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 +136 -118
- package/src/authn/SolidAuthnLogic.ts +3 -2
- package/src/chat/chatLogic.ts +225 -0
- package/src/inbox/inboxLogic.ts +57 -0
- package/src/index.ts +124 -20
- package/src/logic/CustomError.ts +5 -1
- package/src/logic/SolidLogic.ts +30 -211
- package/src/logic/solidLogicSingleton.ts +1 -1
- package/src/logic/solidLogicSingletonNew.ts +210 -0
- package/src/profile/profileLogic.ts +125 -0
- package/src/typeIndex/typeIndexLogic.ts +175 -182
- package/src/types.ts +7 -3
- package/src/util/containerLogic.ts +54 -0
- package/src/util/ns.ts +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/helpers/dataSetup.ts +134 -0
- package/test/helpers/setup.ts +4 -0
- package/test/inboxLogic.test.ts +39 -38
- package/test/logic.test.ts +10 -9
- package/test/profileLogic.test.ts +246 -0
- package/test/typeIndexLogic.test.ts +487 -30
- 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/discovery/discoveryLogic.d.ts +0 -37
- package/lib/discovery/discoveryLogic.d.ts.map +0 -1
- package/lib/discovery/discoveryLogic.js +0 -507
- package/lib/discovery/discoveryLogic.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/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/discovery/discoveryLogic.ts +0 -288
- package/src/inbox/InboxLogic.ts +0 -66
- package/src/profile/ProfileLogic.ts +0 -44
- package/src/util/UtilityLogic.ts +0 -161
- package/src/util/uri.ts +0 -5
- package/test/discoveryLogic.test.ts +0 -712
|
@@ -58,311 +58,319 @@ 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;
|
|
66
63
|
var rdflib_1 = require("rdflib");
|
|
67
64
|
var debug = __importStar(require("../util/debug"));
|
|
68
|
-
var
|
|
69
|
-
var
|
|
70
|
-
|
|
71
|
-
var
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
78
|
-
var _a, _b;
|
|
79
|
-
return __generator(this, function (_c) {
|
|
80
|
-
switch (_c.label) {
|
|
81
|
-
case 0:
|
|
82
|
-
if (!context.me)
|
|
83
|
-
throw new Error('@@ ensureLoadedPreferences: no user specified');
|
|
84
|
-
_a = context;
|
|
85
|
-
return [4 /*yield*/, (0, discoveryLogic_1.loadProfile)(store, context.me)];
|
|
86
|
-
case 1:
|
|
87
|
-
_a.publicProfile = _c.sent();
|
|
88
|
-
_b = context;
|
|
89
|
-
return [4 /*yield*/, (0, discoveryLogic_1.loadPreferences)(store, context.me)];
|
|
90
|
-
case 2:
|
|
91
|
-
_b.preferencesFile = _c.sent();
|
|
92
|
-
return [2 /*return*/, context];
|
|
93
|
-
}
|
|
65
|
+
var ns_1 = require("../util/ns");
|
|
66
|
+
var utils_1 = require("../util/utils");
|
|
67
|
+
function createTypeIndexLogic(store, authn, profileLogic, utilityLogic) {
|
|
68
|
+
var ns = ns_1.ns;
|
|
69
|
+
function getRegistrations(instance, theClass) {
|
|
70
|
+
return store
|
|
71
|
+
.each(undefined, ns.solid("instance"), instance)
|
|
72
|
+
.filter(function (r) {
|
|
73
|
+
return store.holds(r, ns.solid("forClass"), theClass);
|
|
94
74
|
});
|
|
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
|
-
|
|
75
|
+
}
|
|
76
|
+
function loadTypeIndexesFor(user) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
78
|
+
var profile, suggestion, publicTypeIndex, err_1, message, publicScopes, preferencesFile, err_2, privateScopes, suggestedPrivateTypeIndex, privateTypeIndex, _a, err_3, message, scopes, files, err_4;
|
|
79
|
+
return __generator(this, function (_b) {
|
|
80
|
+
switch (_b.label) {
|
|
81
|
+
case 0:
|
|
82
|
+
if (!user)
|
|
83
|
+
throw new Error("loadTypeIndexesFor: No user given");
|
|
84
|
+
return [4 /*yield*/, profileLogic.loadProfile(user)];
|
|
85
|
+
case 1:
|
|
86
|
+
profile = _b.sent();
|
|
87
|
+
suggestion = suggestPublicTypeIndex(user);
|
|
88
|
+
_b.label = 2;
|
|
89
|
+
case 2:
|
|
90
|
+
_b.trys.push([2, 4, , 5]);
|
|
91
|
+
return [4 /*yield*/, utilityLogic.followOrCreateLink(user, ns.solid('publicTypeIndex'), suggestion, profile)];
|
|
92
|
+
case 3:
|
|
93
|
+
publicTypeIndex = _b.sent();
|
|
94
|
+
return [3 /*break*/, 5];
|
|
95
|
+
case 4:
|
|
96
|
+
err_1 = _b.sent();
|
|
97
|
+
message = "User ".concat(user, " has no pointer in profile to publicTypeIndex file.");
|
|
98
|
+
debug.warn(message);
|
|
99
|
+
return [3 /*break*/, 5];
|
|
100
|
+
case 5:
|
|
101
|
+
publicScopes = publicTypeIndex ? [{ label: 'public', index: publicTypeIndex, agent: user }] : [];
|
|
102
|
+
_b.label = 6;
|
|
103
|
+
case 6:
|
|
104
|
+
_b.trys.push([6, 8, , 9]);
|
|
105
|
+
return [4 /*yield*/, profileLogic.silencedLoadPreferences(user)];
|
|
106
|
+
case 7:
|
|
107
|
+
preferencesFile = _b.sent();
|
|
108
|
+
return [3 /*break*/, 9];
|
|
109
|
+
case 8:
|
|
110
|
+
err_2 = _b.sent();
|
|
111
|
+
preferencesFile = null;
|
|
112
|
+
return [3 /*break*/, 9];
|
|
113
|
+
case 9:
|
|
114
|
+
if (!preferencesFile) return [3 /*break*/, 15];
|
|
115
|
+
suggestedPrivateTypeIndex = suggestPrivateTypeIndex(preferencesFile);
|
|
116
|
+
privateTypeIndex = void 0;
|
|
117
|
+
_b.label = 10;
|
|
118
|
+
case 10:
|
|
119
|
+
_b.trys.push([10, 13, , 14]);
|
|
120
|
+
_a = store.any(user, ns.solid('privateTypeIndex'), undefined, profile);
|
|
121
|
+
if (_a) return [3 /*break*/, 12];
|
|
122
|
+
return [4 /*yield*/, utilityLogic.followOrCreateLink(user, ns.solid('privateTypeIndex'), suggestedPrivateTypeIndex, preferencesFile)];
|
|
123
|
+
case 11:
|
|
124
|
+
_a = (_b.sent());
|
|
125
|
+
_b.label = 12;
|
|
126
|
+
case 12:
|
|
127
|
+
privateTypeIndex = _a;
|
|
128
|
+
return [3 /*break*/, 14];
|
|
129
|
+
case 13:
|
|
130
|
+
err_3 = _b.sent();
|
|
131
|
+
message = "User ".concat(user, " has no pointer in preference file to privateTypeIndex file.");
|
|
132
|
+
debug.warn(message);
|
|
133
|
+
return [3 /*break*/, 14];
|
|
134
|
+
case 14:
|
|
135
|
+
privateScopes = privateTypeIndex ? [{ label: 'private', index: privateTypeIndex, agent: user }] : [];
|
|
136
|
+
return [3 /*break*/, 16];
|
|
137
|
+
case 15:
|
|
138
|
+
privateScopes = [];
|
|
139
|
+
_b.label = 16;
|
|
140
|
+
case 16:
|
|
141
|
+
scopes = publicScopes.concat(privateScopes);
|
|
142
|
+
if (scopes.length === 0)
|
|
143
|
+
return [2 /*return*/, scopes];
|
|
144
|
+
files = scopes.map(function (scope) { return scope.index; });
|
|
145
|
+
_b.label = 17;
|
|
146
|
+
case 17:
|
|
147
|
+
_b.trys.push([17, 19, , 20]);
|
|
148
|
+
return [4 /*yield*/, store.fetcher.load(files)];
|
|
149
|
+
case 18:
|
|
150
|
+
_b.sent();
|
|
151
|
+
return [3 /*break*/, 20];
|
|
152
|
+
case 19:
|
|
153
|
+
err_4 = _b.sent();
|
|
154
|
+
debug.warn('Problems loading type index: ', err_4);
|
|
155
|
+
return [3 /*break*/, 20];
|
|
156
|
+
case 20: return [2 /*return*/, scopes];
|
|
157
|
+
}
|
|
158
|
+
});
|
|
121
159
|
});
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
160
|
+
}
|
|
161
|
+
function loadCommunityTypeIndexes(user) {
|
|
162
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
163
|
+
var preferencesFile, err_5, message, communities, result, _i, communities_1, org, _a, _b;
|
|
164
|
+
return __generator(this, function (_c) {
|
|
165
|
+
switch (_c.label) {
|
|
166
|
+
case 0:
|
|
167
|
+
_c.trys.push([0, 2, , 3]);
|
|
168
|
+
return [4 /*yield*/, profileLogic.silencedLoadPreferences(user)];
|
|
169
|
+
case 1:
|
|
170
|
+
preferencesFile = _c.sent();
|
|
171
|
+
return [3 /*break*/, 3];
|
|
172
|
+
case 2:
|
|
173
|
+
err_5 = _c.sent();
|
|
174
|
+
message = "User ".concat(user, " has no pointer in profile to preferences file.");
|
|
175
|
+
debug.warn(message);
|
|
176
|
+
return [3 /*break*/, 3];
|
|
177
|
+
case 3:
|
|
178
|
+
if (!preferencesFile) return [3 /*break*/, 8];
|
|
179
|
+
communities = store.each(user, ns.solid('community'), undefined, preferencesFile).concat(store.each(user, ns.solid('community'), undefined, user.doc()));
|
|
180
|
+
result = [];
|
|
181
|
+
_i = 0, communities_1 = communities;
|
|
182
|
+
_c.label = 4;
|
|
183
|
+
case 4:
|
|
184
|
+
if (!(_i < communities_1.length)) return [3 /*break*/, 7];
|
|
185
|
+
org = communities_1[_i];
|
|
186
|
+
_b = (_a = result).concat;
|
|
187
|
+
return [4 /*yield*/, loadTypeIndexesFor(org)];
|
|
188
|
+
case 5:
|
|
189
|
+
result = _b.apply(_a, [_c.sent()]);
|
|
190
|
+
_c.label = 6;
|
|
191
|
+
case 6:
|
|
192
|
+
_i++;
|
|
193
|
+
return [3 /*break*/, 4];
|
|
194
|
+
case 7: return [2 /*return*/, result];
|
|
195
|
+
case 8: return [2 /*return*/, []]; // No communities
|
|
196
|
+
}
|
|
197
|
+
});
|
|
158
198
|
});
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
-
}
|
|
199
|
+
}
|
|
200
|
+
function loadAllTypeIndexes(user) {
|
|
201
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
202
|
+
var _a, _b;
|
|
203
|
+
return __generator(this, function (_c) {
|
|
204
|
+
switch (_c.label) {
|
|
205
|
+
case 0: return [4 /*yield*/, loadTypeIndexesFor(user)];
|
|
206
|
+
case 1:
|
|
207
|
+
_b = (_a = (_c.sent())).concat;
|
|
208
|
+
return [4 /*yield*/, loadCommunityTypeIndexes(user)];
|
|
209
|
+
case 2: return [2 /*return*/, _b.apply(_a, [(_c.sent()).flat()])];
|
|
210
|
+
}
|
|
211
|
+
});
|
|
182
212
|
});
|
|
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
|
-
return [2 /*return*/, context];
|
|
209
|
-
case 2:
|
|
210
|
-
e_1 = _a.sent();
|
|
211
|
-
msg = "Error creating new index ".concat(e_1);
|
|
212
|
-
// widgets.complain(context, msg)
|
|
213
|
-
debug.warn(msg);
|
|
214
|
-
return [3 /*break*/, 3];
|
|
215
|
-
case 3: return [2 /*return*/];
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
} // putIndex
|
|
220
|
-
var relevant, visibility, newIndex, addMe, err_1, msg, ixs, err_2, msg;
|
|
221
|
-
return __generator(this, function (_a) {
|
|
222
|
-
switch (_a.label) {
|
|
223
|
-
case 0:
|
|
224
|
-
relevant = isPublic ? context.publicProfile : context.preferencesFile;
|
|
225
|
-
if (!relevant)
|
|
226
|
-
alert('@@@@ relevent null');
|
|
227
|
-
visibility = isPublic ? 'public' : 'private';
|
|
228
|
-
context.index = context.index || {};
|
|
229
|
-
context.index[visibility] = context.index[visibility] || [];
|
|
230
|
-
if (!(context.index[visibility].length === 0)) return [3 /*break*/, 6];
|
|
231
|
-
if (!store.updater.editable(relevant)) {
|
|
232
|
-
debug.log("Not adding new type index as ".concat(relevant, " is not editable"));
|
|
233
|
-
return [2 /*return*/];
|
|
234
|
-
}
|
|
235
|
-
newIndex = (0, rdflib_1.sym)("".concat(relevant.dir().uri + visibility, "TypeIndex.ttl"));
|
|
236
|
-
debug.log("Linking to new fresh type index ".concat(newIndex));
|
|
237
|
-
if (!confirm("OK to create a new empty index file at ".concat(newIndex, ", overwriting anything that is now there?"))) {
|
|
238
|
-
throw new Error('cancelled by user');
|
|
239
|
-
}
|
|
240
|
-
debug.log("Linking to new fresh type index ".concat(newIndex));
|
|
241
|
-
addMe = [
|
|
242
|
-
(0, rdflib_1.st)(context.me, exports.ns.solid("".concat(visibility, "TypeIndex")), newIndex, relevant)
|
|
243
|
-
];
|
|
244
|
-
_a.label = 1;
|
|
245
|
-
case 1:
|
|
246
|
-
_a.trys.push([1, 3, , 4]);
|
|
247
|
-
return [4 /*yield*/, solidLogicSingleton_1.solidLogicSingleton.updatePromise([], addMe)];
|
|
248
|
-
case 2:
|
|
249
|
-
_a.sent();
|
|
250
|
-
return [3 /*break*/, 4];
|
|
251
|
-
case 3:
|
|
252
|
-
err_1 = _a.sent();
|
|
253
|
-
msg = "Error saving type index link saving back ".concat(newIndex, ": ").concat(err_1);
|
|
254
|
-
//widgets.complain(context, msg)
|
|
255
|
-
debug.warn(msg);
|
|
256
|
-
return [2 /*return*/, context];
|
|
257
|
-
case 4:
|
|
258
|
-
debug.log("Creating new fresh type index file".concat(newIndex));
|
|
259
|
-
return [4 /*yield*/, putIndex(newIndex)];
|
|
260
|
-
case 5:
|
|
261
|
-
_a.sent();
|
|
262
|
-
context.index[visibility].push(newIndex); // @@ wait
|
|
263
|
-
return [3 /*break*/, 10];
|
|
264
|
-
case 6:
|
|
265
|
-
ixs = context.index[visibility];
|
|
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
|
-
});
|
|
213
|
+
}
|
|
214
|
+
function getScopedAppInstances(klass, user) {
|
|
215
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
216
|
+
var scopes, scopedApps, _i, scopes_1, scope, scopedApps0;
|
|
217
|
+
return __generator(this, function (_a) {
|
|
218
|
+
switch (_a.label) {
|
|
219
|
+
case 0: return [4 /*yield*/, loadAllTypeIndexes(user)];
|
|
220
|
+
case 1:
|
|
221
|
+
scopes = _a.sent();
|
|
222
|
+
scopedApps = [];
|
|
223
|
+
_i = 0, scopes_1 = scopes;
|
|
224
|
+
_a.label = 2;
|
|
225
|
+
case 2:
|
|
226
|
+
if (!(_i < scopes_1.length)) return [3 /*break*/, 5];
|
|
227
|
+
scope = scopes_1[_i];
|
|
228
|
+
return [4 /*yield*/, getScopedAppsFromIndex(scope, klass)];
|
|
229
|
+
case 3:
|
|
230
|
+
scopedApps0 = _a.sent();
|
|
231
|
+
scopedApps = scopedApps.concat(scopedApps0);
|
|
232
|
+
_a.label = 4;
|
|
233
|
+
case 4:
|
|
234
|
+
_i++;
|
|
235
|
+
return [3 /*break*/, 2];
|
|
236
|
+
case 5: return [2 /*return*/, scopedApps];
|
|
237
|
+
}
|
|
281
238
|
});
|
|
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
239
|
});
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
) {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
if (!indexes.length) {
|
|
340
|
-
throw new Error('registerInTypeIndex: What no type index?');
|
|
341
|
-
}
|
|
342
|
-
index = indexes[0];
|
|
343
|
-
registration = (0, uri_1.newThing)(index);
|
|
344
|
-
ins = [
|
|
345
|
-
// See https://github.com/solidos/solid/blob/main/proposals/data-discovery.md
|
|
346
|
-
(0, rdflib_1.st)(registration, exports.ns.rdf('type'), exports.ns.solid('TypeRegistration'), index),
|
|
347
|
-
(0, rdflib_1.st)(registration, exports.ns.solid('forClass'), theClass, index),
|
|
348
|
-
(0, rdflib_1.st)(registration, exports.ns.solid('instance'), instance, index)
|
|
349
|
-
];
|
|
350
|
-
_a.label = 2;
|
|
351
|
-
case 2:
|
|
352
|
-
_a.trys.push([2, 4, , 5]);
|
|
353
|
-
return [4 /*yield*/, solidLogicSingleton_1.solidLogicSingleton.updatePromise([], ins)];
|
|
354
|
-
case 3:
|
|
355
|
-
_a.sent();
|
|
356
|
-
return [3 /*break*/, 5];
|
|
357
|
-
case 4:
|
|
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
|
-
}
|
|
240
|
+
}
|
|
241
|
+
// This is the function signature which used to be in solid-ui/logic
|
|
242
|
+
// Recommended to use getScopedAppInstances instead as it provides more information.
|
|
243
|
+
//
|
|
244
|
+
function getAppInstances(klass) {
|
|
245
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
246
|
+
var user, scopedAppInstances;
|
|
247
|
+
return __generator(this, function (_a) {
|
|
248
|
+
switch (_a.label) {
|
|
249
|
+
case 0:
|
|
250
|
+
user = authn.currentUser();
|
|
251
|
+
if (!user)
|
|
252
|
+
throw new Error('getAppInstances: Must be logged in to find apps.');
|
|
253
|
+
return [4 /*yield*/, getScopedAppInstances(klass, user)];
|
|
254
|
+
case 1:
|
|
255
|
+
scopedAppInstances = _a.sent();
|
|
256
|
+
return [2 /*return*/, scopedAppInstances.map(function (scoped) { return scoped.instance; })];
|
|
257
|
+
}
|
|
258
|
+
});
|
|
364
259
|
});
|
|
365
|
-
}
|
|
260
|
+
}
|
|
261
|
+
function suggestPublicTypeIndex(me) {
|
|
262
|
+
var _a;
|
|
263
|
+
return (0, rdflib_1.sym)(((_a = me.doc().dir()) === null || _a === void 0 ? void 0 : _a.uri) + 'publicTypeIndex.ttl');
|
|
264
|
+
}
|
|
265
|
+
// Note this one is based off the pref file not the profile
|
|
266
|
+
function suggestPrivateTypeIndex(preferencesFile) {
|
|
267
|
+
var _a;
|
|
268
|
+
return (0, rdflib_1.sym)(((_a = preferencesFile.doc().dir()) === null || _a === void 0 ? void 0 : _a.uri) + 'privateTypeIndex.ttl');
|
|
269
|
+
}
|
|
270
|
+
/*
|
|
271
|
+
* Register a new app in a type index
|
|
272
|
+
* used in chat in bookmark.js (solid-ui)
|
|
273
|
+
* Returns the registration object if successful else null
|
|
274
|
+
*/
|
|
275
|
+
function registerInTypeIndex(instance, index, theClass) {
|
|
276
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
277
|
+
var registration, ins, err_6, msg;
|
|
278
|
+
return __generator(this, function (_a) {
|
|
279
|
+
switch (_a.label) {
|
|
280
|
+
case 0:
|
|
281
|
+
registration = (0, utils_1.newThing)(index);
|
|
282
|
+
ins = [
|
|
283
|
+
// See https://github.com/solid/solid/blob/main/proposals/data-discovery.md
|
|
284
|
+
(0, rdflib_1.st)(registration, ns.rdf('type'), ns.solid('TypeRegistration'), index),
|
|
285
|
+
(0, rdflib_1.st)(registration, ns.solid('forClass'), theClass, index),
|
|
286
|
+
(0, rdflib_1.st)(registration, ns.solid('instance'), instance, index)
|
|
287
|
+
];
|
|
288
|
+
_a.label = 1;
|
|
289
|
+
case 1:
|
|
290
|
+
_a.trys.push([1, 3, , 4]);
|
|
291
|
+
return [4 /*yield*/, store.updater.update([], ins)];
|
|
292
|
+
case 2:
|
|
293
|
+
_a.sent();
|
|
294
|
+
return [3 /*break*/, 4];
|
|
295
|
+
case 3:
|
|
296
|
+
err_6 = _a.sent();
|
|
297
|
+
msg = "Unable to register ".concat(instance, " in index ").concat(index, ": ").concat(err_6);
|
|
298
|
+
console.warn(msg);
|
|
299
|
+
return [2 /*return*/, null];
|
|
300
|
+
case 4: return [2 /*return*/, registration];
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
function deleteTypeIndexRegistration(item) {
|
|
306
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
307
|
+
var reg, statements;
|
|
308
|
+
return __generator(this, function (_a) {
|
|
309
|
+
switch (_a.label) {
|
|
310
|
+
case 0:
|
|
311
|
+
reg = store.the(null, ns.solid('instance'), item.instance, item.scope.index);
|
|
312
|
+
if (!reg)
|
|
313
|
+
throw new Error("deleteTypeIndexRegistration: No registration found for ".concat(item.instance));
|
|
314
|
+
statements = store.statementsMatching(reg, null, null, item.scope.index);
|
|
315
|
+
return [4 /*yield*/, store.updater.update(statements, [])];
|
|
316
|
+
case 1:
|
|
317
|
+
_a.sent();
|
|
318
|
+
return [2 /*return*/];
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
function getScopedAppsFromIndex(scope, theClass) {
|
|
324
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
325
|
+
var index, registrations, relevant, directInstances, instances, instanceContainers, containers, i, cont, contents;
|
|
326
|
+
return __generator(this, function (_a) {
|
|
327
|
+
switch (_a.label) {
|
|
328
|
+
case 0:
|
|
329
|
+
index = scope.index;
|
|
330
|
+
registrations = store.statementsMatching(null, ns.solid('instance'), null, index)
|
|
331
|
+
.concat(store.statementsMatching(null, ns.solid('instanceContainer'), null, index))
|
|
332
|
+
.map(function (st) { return st.subject; });
|
|
333
|
+
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); })
|
|
334
|
+
: registrations;
|
|
335
|
+
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();
|
|
336
|
+
instances = (0, utils_1.uniqueNodes)(directInstances);
|
|
337
|
+
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();
|
|
338
|
+
containers = (0, utils_1.uniqueNodes)(instanceContainers);
|
|
339
|
+
if (containers.length > 0) {
|
|
340
|
+
console.log('@@ getScopedAppsFromIndex containers ', containers);
|
|
341
|
+
}
|
|
342
|
+
i = 0;
|
|
343
|
+
_a.label = 1;
|
|
344
|
+
case 1:
|
|
345
|
+
if (!(i < containers.length)) return [3 /*break*/, 4];
|
|
346
|
+
cont = containers[i];
|
|
347
|
+
return [4 /*yield*/, store.fetcher.load(cont)];
|
|
348
|
+
case 2:
|
|
349
|
+
_a.sent();
|
|
350
|
+
contents = store.each(cont, ns.ldp('contains'), null, cont).map(function (one) { return (0, rdflib_1.sym)(one.value); });
|
|
351
|
+
instances = instances.concat(contents);
|
|
352
|
+
_a.label = 3;
|
|
353
|
+
case 3:
|
|
354
|
+
i++;
|
|
355
|
+
return [3 /*break*/, 1];
|
|
356
|
+
case 4: return [2 /*return*/, instances.map(function (instance) { return { instance: instance, scope: scope }; })];
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
return {
|
|
362
|
+
registerInTypeIndex: registerInTypeIndex,
|
|
363
|
+
getRegistrations: getRegistrations,
|
|
364
|
+
loadTypeIndexesFor: loadTypeIndexesFor,
|
|
365
|
+
loadCommunityTypeIndexes: loadCommunityTypeIndexes,
|
|
366
|
+
loadAllTypeIndexes: loadAllTypeIndexes,
|
|
367
|
+
getScopedAppInstances: getScopedAppInstances,
|
|
368
|
+
getAppInstances: getAppInstances,
|
|
369
|
+
suggestPublicTypeIndex: suggestPublicTypeIndex,
|
|
370
|
+
suggestPrivateTypeIndex: suggestPrivateTypeIndex,
|
|
371
|
+
deleteTypeIndexRegistration: deleteTypeIndexRegistration,
|
|
372
|
+
getScopedAppsFromIndex: getScopedAppsFromIndex
|
|
373
|
+
};
|
|
366
374
|
}
|
|
367
|
-
exports.
|
|
375
|
+
exports.createTypeIndexLogic = createTypeIndexLogic;
|
|
368
376
|
//# sourceMappingURL=typeIndexLogic.js.map
|