UNPKG

@solid/community-server

Version:

Community Solid Server: an open and modular implementation of the Solid specifications

45 lines 2.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NotificationDescriber = void 0; const n3_1 = require("n3"); const BasicRepresentation_1 = require("../../http/representation/BasicRepresentation"); const ContentTypes_1 = require("../../util/ContentTypes"); const StreamUtil_1 = require("../../util/StreamUtil"); const Vocabularies_1 = require("../../util/Vocabularies"); const StorageDescriber_1 = require("../description/StorageDescriber"); /** * Outputs quads describing all the subscription services of the server, * as described in https://solidproject.org/TR/2022/notifications-protocol-20221231#discovery and * https://solidproject.org/TR/2022/notifications-protocol-20221231#description-resource-data-model. * * In the future, if there is ever a need to add notification channels to the description resource as described above, * this functionality should probably be added here as well. */ class NotificationDescriber extends StorageDescriber_1.StorageDescriber { converter; subscriptions; constructor(converter, subscriptions) { super(); this.converter = converter; this.subscriptions = subscriptions; } async handle(identifier) { const subject = n3_1.DataFactory.namedNode(identifier.path); const subscriptionLinks = []; const preferences = { type: { [ContentTypes_1.INTERNAL_QUADS]: 1 } }; const subscriptionQuads = await Promise.all(this.subscriptions.map(async (sub) => { const jsonld = sub.getDescription(); const representation = new BasicRepresentation_1.BasicRepresentation(JSON.stringify(jsonld), { path: jsonld.id }, ContentTypes_1.APPLICATION_LD_JSON); const converted = await this.converter.handleSafe({ identifier, representation, preferences }); const arr = await (0, StreamUtil_1.arrayifyStream)(converted.data); subscriptionLinks.push(n3_1.DataFactory.quad(subject, Vocabularies_1.NOTIFY.terms.subscription, n3_1.DataFactory.namedNode(jsonld.id))); return arr; })); return [ ...subscriptionLinks, ...subscriptionQuads.flat(), ]; } } exports.NotificationDescriber = NotificationDescriber; //# sourceMappingURL=NotificationDescriber.js.map