Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@hamok-dev/common

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hamok-dev/common

Library for hamok describe communication schema for typescript implementation

  • 1.0.0-rc.0
  • unpublished
  • develop-100-dev-rc
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Hamok Messages Library for Javascript

This library is written for the hamok schema. It provides API for hamok-ts-core based on a unified communication schema.

Exported Components

The library exports the following components.

Logger

import { createLogger, setLogLevel } from "@hamok-dev/hamok-ts-messages";

// create a logger with a name
const logger = createLogger("myComponent");

// globally set the minimum loglevel written out to the console
setLogLevel('warn');

Messages

import { Message, MessageType } from "@hamok-dev/hamok-ts-messages";
const message = new Message({
    type: MessageType.HELLO_NOTIFICATION,
    sourceId: "sourceId",
})

Codec, FacadedCodec

import { Codec, FacadedCodec } from "@hamok-dev/hamok-ts-messages";

const strToNumCodec: Codec<string, number> = {
    encode: (input: string) => Number.parseInt(input),
    decode: (input: number) => `${input}`,
};
const strToBoolCodec: Codec<string, boolean> = FacadedCodec
    .wrap<string, number>(strToNumCodec)
    .then<boolean>({
        encode: (input: number) => 0 !== input,
        decode: (input: boolean) => input ? 1 : 0,
    })
strToBoolCodec.encode("5"); // true
strToBoolCodec.decode(true) // "1"

GridCodec

Encode and decode messages for Grid operations.

import { GridCodec, HelloNotification, Message } from "@hamok-dev/hamok-ts-messages";
const codec = new GridCodec();
const outbNotification: HelloNotification = {
    sourceEndpointId: "sourceEndpointId",
};
const message = codec.encodeHelloNotification(outbNotification);
const inbNotification = codec.decodeHelloNotification(message)

StorageCodec

Encode and decode messages for Distributed Storage operations.

import { 
    StorageCodec, 
    UpdateEntriesRequest,
    UpdateEntriesResponse,
    Message
} from "@hamok-dev/hamok-ts-messages";
const codec = new StorageCodec();

const requestMessage = codec.encodeUpdateEntriesRequest(new UpdateEntriesRequest<number, string>(
    new Map<number, string>([[1, "oneV2"]])
));
const request = codec.decodeUpdateEntriesRequest(requestMessage);

const responseMessage = codec.encodeUpdateResponse(request.createResponse(
    new Map<number, string>([[1, "oneV1"]])
));

const response = codec.decodeUpdateResponse(responseMessage);

Keywords

FAQs

Package last updated on 13 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc