UNPKG

@hello.nrfcloud.com/proto

Version:

Documents the communication protocol between the hello.nrfcloud.com backend and the web application

215 lines (214 loc) 7.59 kB
function _assert_this_initialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _call_super(_this, derived, args) { derived = _get_prototype_of(derived); return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args)); } function _class_call_check(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _construct(Parent, args, Class) { if (_is_native_reflect_construct()) { _construct = Reflect.construct; } else { _construct = function construct(Parent, args, Class) { var a = [ null ]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _set_prototype_of(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); } function _define_property(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _get_prototype_of(o) { _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _get_prototype_of(o); } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _set_prototype_of(subClass, superClass); } function _is_native_function(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; } function _object_spread(target) { for(var i = 1; i < arguments.length; i++){ var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === "function") { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function(key) { _define_property(target, key, source[key]); }); } return target; } function _possible_constructor_return(self, call) { if (call && (_type_of(call) === "object" || typeof call === "function")) { return call; } return _assert_this_initialized(self); } function _set_prototype_of(o, p) { _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _set_prototype_of(o, p); } function _type_of(obj) { "@swc/helpers - typeof"; return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; } function _wrap_native_super(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrap_native_super = function wrapNativeSuper(Class) { if (Class === null || !_is_native_function(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _get_prototype_of(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _set_prototype_of(Wrapper, Class); }; return _wrap_native_super(Class); } function _is_native_reflect_construct() { try { var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {})); } catch (_) {} return (_is_native_reflect_construct = function() { return !!result; })(); } import { Type } from '@sinclair/typebox'; import { Context } from '../Context.js'; import { HttpStatusCode, StatusCode } from './StatusCode.js'; /** * Can be used to throw an error with a Problem Detail object. */ export var ProblemDetailError = /*#__PURE__*/ function(Error1) { "use strict"; _inherits(ProblemDetailError, Error1); function ProblemDetailError(problem) { _class_call_check(this, ProblemDetailError); var _this; _this = _call_super(this, ProblemDetailError, [ problem.title ]), _define_property(_this, "problem", void 0); _this.problem = _object_spread({ '@context': Context.problemDetail.toString() }, problem); _this.name = 'ProblemDetailError'; return _this; } return ProblemDetailError; }(_wrap_native_super(Error)); /** * Problem Details Object * * @see https://datatracker.ietf.org/doc/draft-ietf-httpapi-rfc7807bis/ */ export var ProblemDetail = Type.Object({ '@context': Type.Literal(Context.problemDetail.toString()), '@id': Type.Optional(Type.String()), type: Type.Optional(Type.String()), status: Type.Optional(StatusCode), title: Type.String(), detail: Type.Optional(Type.String()) }, { title: 'Problem Detail', description: 'See see https://datatracker.ietf.org/doc/draft-ietf-httpapi-rfc7807bis/' }); export var BadRequestError = function(param) { var id = param.id, title = param.title, detail = param.detail; return { '@context': Context.problemDetail.toString(), '@id': id, type: Context.error('BadRequest').toString(), status: HttpStatusCode.BAD_REQUEST, title: title, detail: detail }; }; export var ConflictError = function(param) { var id = param.id, title = param.title, detail = param.detail; return { '@context': Context.problemDetail.toString(), '@id': id, type: Context.error('Conflict').toString(), status: HttpStatusCode.CONFLICT, title: title, detail: detail }; }; export var InternalError = function(param) { var id = param.id, title = param.title, detail = param.detail; return { '@context': Context.problemDetail.toString(), '@id': id, type: Context.error('InternalError').toString(), status: HttpStatusCode.INTERNAL_SERVER_ERROR, title: title !== null && title !== void 0 ? title : 'An internal error occurred.', detail: detail }; }; export var NotFoundError = function(param) { var id = param.id, title = param.title, detail = param.detail; return { '@context': Context.problemDetail.toString(), '@id': id, type: Context.error('NotFound').toString(), status: HttpStatusCode.NOT_FOUND, title: title, detail: detail }; };