@enbox/api
Version:
SDK for accessing the features and capabilities of Web5
35 lines • 1.79 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { getRecordAuthor } from '@enbox/agent';
import { Record } from './record.js';
/**
* Utility class for dealing with subscriptions.
*/
export class SubscriptionUtil {
/**
* Creates a record subscription handler that can be used to process incoming {Record} messages.
*/
static recordSubscriptionHandler({ agent, connectedDid, request, delegateDid, protocolRole, permissionsApi }) {
const { subscriptionHandler, from: remoteOrigin } = request;
return (event) => __awaiter(this, void 0, void 0, function* () {
const { message, initialWrite } = event;
const author = getRecordAuthor(message);
const recordOptions = {
author,
connectedDid,
remoteOrigin,
initialWrite
};
const record = new Record(agent, Object.assign(Object.assign(Object.assign({}, message), recordOptions), { protocolRole, delegateDid: delegateDid }), permissionsApi);
subscriptionHandler(record);
});
}
}
//# sourceMappingURL=subscription-util.js.map