@actyx/sdk
Version:
Actyx SDK
43 lines • 2.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.OffsetMapIO = exports.EventKeyIO = exports.Codecs = void 0;
/*
* Actyx SDK: Functions for writing distributed apps
* deployed on peer-to-peer networks, without any servers.
*
* Copyright (C) 2021 Actyx AG
*/
const t = require("io-ts");
const functions_1 = require("./functions");
const various_1 = require("./various");
const Either_1 = require("fp-ts/lib/Either");
/**
*
* Wire format types.
* Not open to the public, just for validation during testing.
*/
// Hide the io-ts stuff from the outside world
/** @internal */
exports.Codecs = {
NodeId: new t.Type('NodeIdFromString', (x) => (0, functions_1.isString)(x), (x, c) => (0, Either_1.map)((s) => s)(t.string.validate(x, c)), (x) => x),
StreamId: new t.Type('StreamIdFromString', (x) => (0, functions_1.isString)(x), (x, c) => (0, Either_1.map)((s) => s)(t.string.validate(x, c)), (x) => x),
AppId: new t.Type('AppIdFromString', (x) => (0, functions_1.isString)(x), (x, c) => (0, Either_1.map)((s) => s)(t.string.validate(x, c)), (x) => x),
Lamport: new t.Type('LamportFromNumber', (x) => (0, functions_1.isNumber)(x), (x, c) => (0, Either_1.map)((s) => various_1.Lamport.of(s))(t.number.validate(x, c)), (x) => x),
Offset: new t.Type('OffsetFromNumber', (x) => (0, functions_1.isNumber)(x), (x, c) => (0, Either_1.map)((s) => s)(t.number.validate(x, c)), (x) => x),
Timestamp: new t.Type('TimestampFromNumber', (x) => (0, functions_1.isNumber)(x), (x, c) => (0, Either_1.map)((s) => s)(t.number.validate(x, c)), (x) => x),
Milliseconds: new t.Type('MilisecondsFromString', (x) => (0, functions_1.isNumber)(x), (x, c) => (0, Either_1.map)((m) => various_1.Milliseconds.of(m))(t.number.validate(x, c)), (x) => x),
};
/**
* Triple that Actyx events are sorted and identified by.
* Wire format.
*
* @internal
*/
exports.EventKeyIO = t.readonly(t.type({
lamport: exports.Codecs.Lamport,
offset: exports.Codecs.Offset,
stream: exports.Codecs.StreamId,
}));
/** OffsetMap serialization format. @internal */
exports.OffsetMapIO = t.readonly(t.record(t.string, exports.Codecs.Offset));
//# sourceMappingURL=wire.js.map