npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mares-tcomb-domain-helper

v1.0.10

Published

domain layer에서 tcomb를 이용하여 구현시, private method가 담기는 helper의 최상단 클래스입니다.

Downloads

14

Readme

mares-tcomb-domain-helper

domain layer에서 tcomb를 이용하여 구현시, private method가 담기는 helper의 최상단 클래스입니다.

Installation

npm install --save mares-tcomb-domain-helper

Example

const BaseDomainHelper = require('mares-tcomb-domain-helper')
class ReceiverHelper extends BaseDomainHelper {
    static do() {}
}
module.exports = ReceiverHelper

Detail Example

다음코드는 실제 구현된 코드의 일부이다. 다음과 같이 helper를 생성해서 domain po를 generate하거나, combine함수를 이용해 객체를 변경할 수 있다. 기본적으로 tcomb는 불변이기 때문에 단순 변경은 허용되지 않는다.

const t = require('tcomb-validation')
const BaseDomainHelper = require('mares-tcomb-domain-helper')
const Receiver = require('../values/receiver')
const Template = require('../../template/entities/template')
const {codes, std} = require('../../../../infra/meta')
const {HttpStatus} = require('http-status')

let Message = t.struct({
	_id: t.maybe(t.String),
	key: t.String,
	type: t.enums.of(Object.values(std.enum.messageType)),
	template: Template,
	memo: t.maybe(t.String),
	receivers: t.maybe(t.list(Receiver)),
	crtAt: t.maybe(t.String),
	udtAt: t.maybe(t.String)
}, 'Message')

const helper = new BaseDomainHelper(Message)

/**
 * API 문자를 생성한다.
 * @param {Template} template - template domain
 * @param {string} key - key
 * @param {string} memo - memo
 * @returns {Message}
 */

Message.generateAPIMessage = (template, {key, memo}) => {
	return helper.generate({
		template: template,
		key,
		memo,
		type: std.enum.messageType.multiple
	})
}

/**
 * api 용 문자 발송, 문자를 받아서, 수신자를 생성한다.
 * @param {Message} message - message domain
 * @param {Object[]} receiverInfos - 수신자 정보
 * @param {string} receiverInfos[].phone - 수신자 전화번호
 * @param {Object[]} receiverInfos[].replacementInfos - 문자 내용
 * @param {string} receiverInfos[].replacementInfos[].key - 변환자 키
 * @param {string} receiverInfos[].replacementInfos[].value - 변환자 내용
 */
Message.createMessageAndReceiverForAPIMessage = (message, receiverInfos) => {
	Message.isValidAPIMessage(message.type)
	let receiverDomains = Receiver.createReceiversAsInfo(message, receiverInfos)
	return BaseDomainHelper.combine(message, {
		receivers: receiverDomains
	})
}

/**
 * 일반 문자발송. 일반문자는 템플릿을 이용하여 문자메세지 및 수신자를 생성 후 이벤트를 발생시킨다.
 * @param {Template} template - template domain
 * @param {string} key - key
 * @param {string} memo - memo
 * @param {Object[]} receiverInfos - 수신자 정보
 * @param {string} receiverInfos[].phone - 수신자 전화번호
 * @param {Object[]} receiverInfos[].replacementInfos - 문자 내용
 * @param {string} receiverInfos[].replacementInfos[].key - 변환자 키
 * @param {string} receiverInfos[].replacementInfos[].value - 변환자 내용
 * @returns {Message}
 */
Message.createMessageAndReceiverForNormalMessage = (template, {key, memo}, receiverInfos) => {
	let messageDomain = BaseDomainHelper.create(Message, {
		template: template,
		memo,
		key,
		type: std.enum.messageType.once
	})
	let receiverDomains = Receiver.createReceiversAsInfo(messageDomain, receiverInfos)
	return helper.combine({
		receivers: receiverDomains
	})
}

/**
 * 올바른 API 메세지 타입인지 검사한다.
 */
Message.isValidAPIMessage = (type) => {
	let isValid = type === std.enum.messageType.multiple
	if (!isValid) {
		helper.throwRefineError(HttpStatus.BAD_REQUEST, codes.invalidMessage)
	}
}

/**
 * 올바른 API 메세지 타입인지와 키값을 검사한다.
 */
Message.isValidAPIMessageWithKey = (type, key) => {
	let isValid = type === std.enum.messageType.multiple
	let isValidKey = typeof key === 'string'
	if (!isValid&&!isValidKey) {
		helper.throwRefineErrorObject(HttpStatus.BAD_REQUEST, {
			code: codes.invalidMessage,
			param: 'type',
			value: type,
			domain: 'Message',
		})
	}
}

/**
 * 수신자 상태를 상태코드와 함께 변경한다
 * @param {string} code - 상태코드
 * @param {Object} receiver - 변경전 수신자 도메인 object
 * @param {string} receiver.phone
 * @returns {Receiver} 변경 후 수신자 도메인
 */
Message.updateReceiverToSuccess = (receiver, code) => {
	let receiverDomain = BaseDomainHelper.create(Receiver, receiver)
	return helper.combine({
		code: code,
		status: std.enum.receiverStatus.success
	})
}

/**
 * 수신자 상태를 상태코드와 함께 변경한다
 * @param {string} code - 상태코드
 * @param {Object} receiver - 변경전 수신자 도메인 object
 * @param {string} receiver.phone
 * @returns {Receiver} 변경 후 수신자 도메인
 */
Message.updateReceiverToFail = (receiver, code) => {
	let receiverDomain = BaseDomainHelper.create(Receiver, receiver)
	return helper.combine({
		code: code,
		status: std.enum.receiverStatus.fail
	})
}

module.exports = Message