solid-logic 1.3.17-8a332867 → 1.3.17-a2363122

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 (121) hide show
  1. package/jest.config.js +1 -1
  2. package/lib/acl/aclLogic.d.ts +12 -30
  3. package/lib/acl/aclLogic.d.ts.map +1 -1
  4. package/lib/acl/aclLogic.js +152 -119
  5. package/lib/acl/aclLogic.js.map +1 -1
  6. package/lib/authn/SolidAuthnLogic.d.ts.map +1 -1
  7. package/lib/authn/SolidAuthnLogic.js +2 -2
  8. package/lib/authn/SolidAuthnLogic.js.map +1 -1
  9. package/lib/chat/chatLogic.d.ts +16 -0
  10. package/lib/chat/chatLogic.d.ts.map +1 -0
  11. package/lib/chat/{ChatLogic.js → chatLogic.js} +82 -87
  12. package/lib/chat/chatLogic.js.map +1 -0
  13. package/lib/inbox/inboxLogic.d.ts +7 -0
  14. package/lib/inbox/inboxLogic.d.ts.map +1 -0
  15. package/lib/inbox/{InboxLogic.js → inboxLogic.js} +58 -64
  16. package/lib/inbox/inboxLogic.js.map +1 -0
  17. package/lib/index.d.ts +18 -9
  18. package/lib/index.d.ts.map +1 -1
  19. package/lib/index.js +77 -34
  20. package/lib/index.js.map +1 -1
  21. package/lib/logic/CustomError.d.ts +4 -0
  22. package/lib/logic/CustomError.d.ts.map +1 -1
  23. package/lib/logic/CustomError.js +17 -1
  24. package/lib/logic/CustomError.js.map +1 -1
  25. package/lib/logic/SolidLogic.d.ts +8 -34
  26. package/lib/logic/SolidLogic.d.ts.map +1 -1
  27. package/lib/logic/SolidLogic.js +16 -250
  28. package/lib/logic/SolidLogic.js.map +1 -1
  29. package/lib/logic/solidLogicSingleton.js +1 -1
  30. package/lib/logic/solidLogicSingleton.js.map +1 -1
  31. package/lib/logic/solidLogicSingletonNew.d.ts +68 -0
  32. package/lib/logic/solidLogicSingletonNew.d.ts.map +1 -0
  33. package/lib/logic/solidLogicSingletonNew.js +221 -0
  34. package/lib/logic/solidLogicSingletonNew.js.map +1 -0
  35. package/lib/profile/profileLogic.d.ts +13 -0
  36. package/lib/profile/profileLogic.d.ts.map +1 -0
  37. package/lib/profile/profileLogic.js +268 -0
  38. package/lib/profile/profileLogic.js.map +1 -0
  39. package/lib/typeIndex/typeIndexLogic.d.ts +18 -21
  40. package/lib/typeIndex/typeIndexLogic.d.ts.map +1 -1
  41. package/lib/typeIndex/typeIndexLogic.js +304 -296
  42. package/lib/typeIndex/typeIndexLogic.js.map +1 -1
  43. package/lib/types.d.ts +17 -0
  44. package/lib/types.d.ts.map +1 -1
  45. package/lib/util/containerLogic.d.ts +11 -0
  46. package/lib/util/containerLogic.d.ts.map +1 -0
  47. package/lib/{profile/ProfileLogic.js → util/containerLogic.js} +53 -44
  48. package/lib/util/containerLogic.js.map +1 -0
  49. package/lib/util/ns.d.ts +2 -0
  50. package/lib/util/ns.d.ts.map +1 -0
  51. package/lib/util/ns.js +34 -0
  52. package/lib/util/ns.js.map +1 -0
  53. package/lib/util/utilityLogic.d.ts +15 -0
  54. package/lib/util/utilityLogic.d.ts.map +1 -0
  55. package/lib/util/utilityLogic.js +272 -0
  56. package/lib/util/utilityLogic.js.map +1 -0
  57. package/lib/util/utils.d.ts +8 -0
  58. package/lib/util/utils.d.ts.map +1 -0
  59. package/lib/util/utils.js +48 -0
  60. package/lib/util/utils.js.map +1 -0
  61. package/package.json +3 -1
  62. package/src/acl/aclLogic.ts +136 -118
  63. package/src/authn/SolidAuthnLogic.ts +3 -2
  64. package/src/chat/chatLogic.ts +225 -0
  65. package/src/inbox/inboxLogic.ts +57 -0
  66. package/src/index.ts +123 -29
  67. package/src/logic/CustomError.ts +5 -1
  68. package/src/logic/SolidLogic.ts +30 -211
  69. package/src/logic/solidLogicSingleton.ts +1 -1
  70. package/src/logic/solidLogicSingletonNew.ts +213 -0
  71. package/src/profile/profileLogic.ts +134 -0
  72. package/src/typeIndex/typeIndexLogic.ts +175 -182
  73. package/src/types.ts +7 -3
  74. package/src/util/containerLogic.ts +54 -0
  75. package/src/util/ns.ts +5 -0
  76. package/src/util/utilityLogic.ts +155 -0
  77. package/src/util/utils.ts +52 -0
  78. package/test/aclLogic.test.ts +13 -4
  79. package/test/chatLogic.test.ts +70 -71
  80. package/test/container.test.ts +56 -0
  81. package/test/helpers/dataSetup.ts +134 -0
  82. package/test/helpers/setup.ts +1 -0
  83. package/test/inboxLogic.test.ts +39 -38
  84. package/test/logic.test.ts +10 -9
  85. package/test/profileLogic.test.ts +246 -0
  86. package/test/typeIndexLogic.test.ts +487 -30
  87. package/test/utilityLogic.test.ts +172 -126
  88. package/test/utils.test.ts +32 -0
  89. package/lib/chat/ChatLogic.d.ts +0 -26
  90. package/lib/chat/ChatLogic.d.ts.map +0 -1
  91. package/lib/chat/ChatLogic.js.map +0 -1
  92. package/lib/chat/determineChatContainer.d.ts +0 -3
  93. package/lib/chat/determineChatContainer.d.ts.map +0 -1
  94. package/lib/chat/determineChatContainer.js +0 -12
  95. package/lib/chat/determineChatContainer.js.map +0 -1
  96. package/lib/discovery/discoveryLogic.d.ts +0 -40
  97. package/lib/discovery/discoveryLogic.d.ts.map +0 -1
  98. package/lib/discovery/discoveryLogic.js +0 -494
  99. package/lib/discovery/discoveryLogic.js.map +0 -1
  100. package/lib/inbox/InboxLogic.d.ts +0 -18
  101. package/lib/inbox/InboxLogic.d.ts.map +0 -1
  102. package/lib/inbox/InboxLogic.js.map +0 -1
  103. package/lib/profile/ProfileLogic.d.ts +0 -13
  104. package/lib/profile/ProfileLogic.d.ts.map +0 -1
  105. package/lib/profile/ProfileLogic.js.map +0 -1
  106. package/lib/util/UtilityLogic.d.ts +0 -33
  107. package/lib/util/UtilityLogic.d.ts.map +0 -1
  108. package/lib/util/UtilityLogic.js +0 -240
  109. package/lib/util/UtilityLogic.js.map +0 -1
  110. package/lib/util/uri.d.ts +0 -3
  111. package/lib/util/uri.d.ts.map +0 -1
  112. package/lib/util/uri.js +0 -9
  113. package/lib/util/uri.js.map +0 -1
  114. package/src/chat/ChatLogic.ts +0 -244
  115. package/src/chat/determineChatContainer.ts +0 -14
  116. package/src/discovery/discoveryLogic.ts +0 -310
  117. package/src/inbox/InboxLogic.ts +0 -66
  118. package/src/profile/ProfileLogic.ts +0 -44
  119. package/src/util/UtilityLogic.ts +0 -161
  120. package/src/util/uri.ts +0 -5
  121. package/test/discoveryLogic.test.ts +0 -740
@@ -1 +1 @@
1
- {"version":3,"file":"typeIndexLogic.d.ts","sourceRoot":"","sources":["../../src/typeIndex/typeIndexLogic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAW,MAAM,QAAQ,CAAA;AAK3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAA;AAIhD,eAAO,MAAM,EAAE,KAAuB,CAAA;AAWtC;;;;;GAKG;AACH,wBAAsB,SAAS,CAC/B,OAAO,EAAE,qBAAqB,EAC9B,QAAQ,EAAE,OAAO,GACd,OAAO,CAAC,qBAAqB,CAAC,CAYhC;AAED,wBAAsB,eAAe,CAAE,OAAO,EAAE,qBAAqB,8CAqBpE;AAED;;;GAGG;AACH,wBAAsB,iBAAiB,CAAE,OAAO,EAAE,qBAAqB,EAAE,KAAK,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAO1H;AAyFD;;;GAGG;AACH,wBAAsB,mBAAmB,CACzC,OAAO,EAAE,qBAAqB,EAC9B,QAAQ,EAAE,SAAS,EACnB,QAAQ,EAAE,SAAS,EACnB,QAAQ,EAAE,OAAO,EACjB,KAAK,CAAC,EAAE,SAAS,GACd,OAAO,CAAC,qBAAqB,CAAC,CAwBhC"}
1
+ {"version":3,"file":"typeIndexLogic.d.ts","sourceRoot":"","sources":["../../src/typeIndex/typeIndexLogic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAW,MAAM,QAAQ,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAKpD,wBAAgB,oBAAoB,CAAC,KAAK,KAAA,EAAE,KAAK,KAAA,EAAE,YAAY,KAAA,EAAE,YAAY,KAAA;oCAwH3D,SAAS,SACZ,SAAS,YACN,SAAS,KAEpB,QAAQ,SAAS,GAAG,IAAI,CAAC;;+BAjHY,SAAS,KAAG,QAAQ,MAAM,cAAc,CAAC,CAAC;qCAiDpC,SAAS,KAAG,QAAQ,cAAc,EAAE,EAAE,CAAC;+BAqB7C,SAAS;mCAIL,SAAS,QAAQ,SAAS,KAAG,QAAQ,SAAS,EAAE,CAAC;6BAavD,SAAS,KAAG,QAAQ,SAAS,EAAE,CAAC;iCAOlC,SAAS;+CAKK,SAAS;;mDAuCJ,SAAS,GAAG,IAAI;;;;EAsC1E"}
@@ -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.registerInTypeIndex = exports.ensureTypeIndexes = exports.loadTypeIndexes = exports.loadIndex = exports.ns = void 0;
62
+ exports.createTypeIndexLogic = void 0;
66
63
  var rdflib_1 = require("rdflib");
67
64
  var debug = __importStar(require("../util/debug"));
68
- var solid_namespace_1 = __importDefault(require("solid-namespace"));
69
- var $rdf = __importStar(require("rdflib"));
70
- var uri_1 = require("../util/uri");
71
- var solidLogicSingleton_1 = require("../logic/solidLogicSingleton");
72
- // import { ensureLoadedPreferences } from '../logic/logic'
73
- var discoveryLogic_1 = require("../discovery/discoveryLogic");
74
- exports.ns = (0, solid_namespace_1.default)($rdf);
75
- var store = solidLogicSingleton_1.solidLogicSingleton.store;
76
- function ensureLoadedPreferences(context) {
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
- * Resolves with the same context, outputting
99
- * output: index.public, index.private
100
- * @@ This is a very bizare function
101
- * @see https://github.com/solidos/solid/blob/main/proposals/data-discovery.md#discoverability
102
- */
103
- function loadIndex(context, isPublic) {
104
- return __awaiter(this, void 0, void 0, function () {
105
- var indexes;
106
- var _this = this;
107
- return __generator(this, function (_a) {
108
- switch (_a.label) {
109
- case 0: return [4 /*yield*/, solidLogicSingleton_1.solidLogicSingleton.loadIndexes(context.me, (isPublic ? context.publicProfile || null : null), (isPublic ? null : context.preferencesFile || null),
110
- // async (err: Error) => widgets.complain(context, err.message)
111
- function (err) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
112
- return [2 /*return*/, debug.error(err.message)];
113
- }); }); })];
114
- case 1:
115
- indexes = _a.sent();
116
- context.index = context.index || {};
117
- context.index.private = indexes.private.concat(context.index.private || []); // otherwise concat will wrongly add 'undefined' as a private index
118
- context.index.public = indexes.public.concat(context.index.public || []); // otherwise concat will wrongly add 'undefined' as a public index
119
- return [2 /*return*/, context];
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
- exports.loadIndex = loadIndex;
125
- function loadTypeIndexes(context) {
126
- return __awaiter(this, void 0, void 0, function () {
127
- var error_1, indexes, error_2;
128
- var _this = this;
129
- return __generator(this, function (_a) {
130
- switch (_a.label) {
131
- case 0:
132
- _a.trys.push([0, 2, , 3]);
133
- return [4 /*yield*/, (0, discoveryLogic_1.loadPreferences)(solidLogicSingleton_1.solidLogicSingleton.store, context.me)];
134
- case 1:
135
- _a.sent();
136
- return [3 /*break*/, 3];
137
- case 2:
138
- error_1 = _a.sent();
139
- debug.warn(error_1.message);
140
- return [3 /*break*/, 3];
141
- case 3:
142
- _a.trys.push([3, 5, , 6]);
143
- return [4 /*yield*/, solidLogicSingleton_1.solidLogicSingleton.loadIndexes(context.me, context.publicProfile || null, context.preferencesFile || null)];
144
- case 4:
145
- indexes = _a.sent();
146
- context.index = context.index || {};
147
- context.index.private = indexes.private || context.index.private;
148
- context.index.public = indexes.public || context.index.public;
149
- return [2 /*return*/, context];
150
- case 5:
151
- error_2 = _a.sent();
152
- (function (error) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
153
- return [2 /*return*/, debug.warn(error.message)];
154
- }); }); });
155
- return [3 /*break*/, 6];
156
- case 6: return [2 /*return*/];
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
- exports.loadTypeIndexes = loadTypeIndexes;
162
- /**
163
- * Resolves with the same context, outputting
164
- * @see https://github.com/solidos/solid/blob/main/proposals/data-discovery.md#discoverability
165
- */
166
- function ensureTypeIndexes(context, agent) {
167
- return __awaiter(this, void 0, void 0, function () {
168
- return __generator(this, function (_a) {
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
- }
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
- exports.ensureTypeIndexes = ensureTypeIndexes;
186
- /**
187
- * Load or create ONE type index
188
- * Find one or make one or fail
189
- * Many reasons for failing including script not having permission etc
190
- *
191
- * Adds its output to the context
192
- * @see https://github.com/solidos/solid/blob/main/proposals/data-discovery.md#discoverability
193
- */
194
- function ensureOneTypeIndex(context, isPublic, agent) {
195
- return __awaiter(this, void 0, void 0, function () {
196
- function makeIndexIfNecessary(context, isPublic) {
197
- return __awaiter(this, void 0, void 0, function () {
198
- function putIndex(newIndex) {
199
- return __awaiter(this, void 0, void 0, function () {
200
- var e_1, msg;
201
- return __generator(this, function (_a) {
202
- switch (_a.label) {
203
- case 0:
204
- _a.trys.push([0, 2, , 3]);
205
- return [4 /*yield*/, solidLogicSingleton_1.solidLogicSingleton.createEmptyRdfDoc(newIndex, 'Blank initial Type index')];
206
- case 1:
207
- _a.sent();
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
- * Register a new app in a type index
324
- * used in chat in bookmark.js (solid-ui)
325
- */
326
- function registerInTypeIndex(context, instance, theClass, isPublic, agent // Defaults to current user
327
- ) {
328
- return __awaiter(this, void 0, void 0, function () {
329
- var indexes, index, registration, ins, e_2;
330
- return __generator(this, function (_a) {
331
- switch (_a.label) {
332
- case 0: return [4 /*yield*/, ensureOneTypeIndex(context, isPublic, agent)];
333
- case 1:
334
- _a.sent();
335
- if (!context.index) {
336
- throw new Error('registerInTypeIndex: No type index found');
337
- }
338
- indexes = isPublic ? context.index.public : context.index.private;
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.registerInTypeIndex = registerInTypeIndex;
375
+ exports.createTypeIndexLogic = createTypeIndexLogic;
368
376
  //# sourceMappingURL=typeIndexLogic.js.map