UNPKG

@lightbend/akkaserverless-javascript-sdk

Version:
124 lines 3.35 kB
"use strict"; /* * Copyright 2021 Lightbend Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Cloudevent = void 0; /** * CloudEvent data. */ class Cloudevent { constructor(metadata) { this.metadata = metadata; } get specversion() { return this.getString('ce-specversion'); } get id() { return this.getString('ce-id'); } set id(id) { if (id === undefined) { this.metadata.delete('ce-id'); } else { this.metadata.asMap['ce-id'] = id; } } get source() { return this.getString('ce-source'); } set source(source) { if (source === undefined) { this.metadata.delete('ce-source'); } else { this.metadata.asMap['ce-source'] = source; } } get type() { return this.getString('ce-type'); } set type(type) { if (type === undefined) { this.metadata.delete('ce-type'); } else { this.metadata.asMap['ce-type'] = type; } } get datacontenttype() { return this.getString('Content-Type'); } set datacontenttype(datacontenttype) { if (datacontenttype === undefined) { this.metadata.delete('Content-Type'); } else { this.metadata.asMap['Content-Type'] = datacontenttype; } } get dataschema() { return this.getString('ce-dataschema'); } set dataschema(dataschema) { if (dataschema === undefined) { this.metadata.delete('ce-dataschema'); } else { this.metadata.asMap['ce-subject'] = dataschema; } } get subject() { return this.getString('ce-subject'); } set subject(subject) { if (subject === undefined) { this.metadata.delete('ce-subject'); } else { this.metadata.asMap['ce-subject'] = subject; } } get time() { const value = this.metadata.asMap['ce-time']; if (typeof value === 'string') { try { return new Date(Date.parse(value)); } catch (e) { return undefined; } } return undefined; } set time(time) { if (time === undefined) { this.metadata.delete('ce-time'); } else { this.metadata.asMap['ce-time'] = time.toISOString(); } } getString(name) { const value = this.metadata.asMap[name]; if (typeof value === 'string') { return value; } return undefined; } } exports.Cloudevent = Cloudevent; //# sourceMappingURL=cloudevent.js.map