@actyx/sdk
Version:
Actyx SDK
58 lines • 1.99 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SubscriptionSet = exports.SubscriptionSetIO = exports.TagSubscription = exports.Subscription = exports.SubscriptionIO = void 0;
/*
* Actyx SDK: Functions for writing distributed apps
* deployed on peer-to-peer networks, without any servers.
*
* Copyright (C) 2021 Actyx AG
*/
/*
* Actyx Pond: A TypeScript framework for writing distributed apps
* deployed on peer-to-peer networks, without any servers.
*
* Copyright (C) 2020 Actyx AG
*/
/* eslint-disable @typescript-eslint/no-explicit-any */
const t = require("io-ts");
const subscriptionToString = (subscription) => {
if (subscription.name === '' && subscription.sourceId !== '') {
throw new Error();
}
// TODO: escaping / and ,
const parts = [subscription.semantics, subscription.name, subscription.sourceId].filter((x) => x !== '');
return parts.join('/');
};
exports.SubscriptionIO = t.readonly(t.type({
semantics: t.string,
// Wildcard is ""
name: t.string,
// Wildcard is ""
sourceId: t.string,
}));
exports.Subscription = {
toString: subscriptionToString,
};
exports.TagSubscription = t.readonly(t.type({
tags: t.readonlyArray(t.string),
local: t.boolean,
}));
/**
* A set of subscriptions
*/
exports.SubscriptionSetIO = t.taggedUnion(
// FIXME: why doesn't this work with t.readonly??
'type', [
t.type({ type: t.literal('empty') }),
t.type({ type: t.literal('all') }),
t.type({ type: t.literal('or'), subscriptions: t.readonlyArray(exports.SubscriptionIO) }),
t.type({ type: t.literal('tags'), subscriptions: t.readonlyArray(exports.TagSubscription) }),
// To be added in the future:
// t.type({ type: t.literal('tag_expr'), subscriptions: t.string }),
]);
exports.SubscriptionSet = {
empty: { type: 'empty' },
all: { type: 'all' },
or: (subscriptions) => ({ type: 'or', subscriptions }),
};
//# sourceMappingURL=subscription.js.map