@productminds/article-events 0.0.8 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeHelpers = void 0;
4
+ const schema_1 = require("@effect/schema");
5
+ const makeHelpers = (schema) => {
6
+ const decode = schema_1.Schema.decodeUnknownEither(schema);
7
+ const decodeExn = (u) => {
8
+ const decoded = decode(u);
9
+ if (decoded._tag === 'Left') {
10
+ throw new Error('Failed to decode ArticleEvent');
11
+ }
12
+ return decoded.right;
13
+ };
14
+ const encode = schema_1.Schema.encodeEither(schema);
15
+ const encodeExn = (event) => {
16
+ const encoded = encode(event);
17
+ if (encoded._tag === 'Left') {
18
+ throw new Error('Failed to encode ArticleEvent');
19
+ }
20
+ return encoded.right;
21
+ };
22
+ const fromString = (msg) => decode(JSON.parse(msg));
23
+ const fromBuffer = (msg) => decode(JSON.parse(msg.toString()));
24
+ const fromStringExn = (msg) => decodeExn(JSON.parse(msg));
25
+ const fromBufferExn = (msg) => fromStringExn(msg.toString());
26
+ const toString = (event) => JSON.stringify(encode(event));
27
+ const toBuffer = (event) => Buffer.from(toString(event));
28
+ const toStringExn = (event) => JSON.stringify(encodeExn(event));
29
+ const toBufferExn = (event) => Buffer.from(toStringExn(event));
30
+ return {
31
+ decode,
32
+ decodeExn,
33
+ encode,
34
+ encodeExn,
35
+ fromString,
36
+ fromBuffer,
37
+ fromStringExn,
38
+ fromBufferExn,
39
+ toString,
40
+ toBuffer,
41
+ toStringExn,
42
+ toBufferExn
43
+ };
44
+ };
45
+ exports.makeHelpers = makeHelpers;
package/index.ts CHANGED
@@ -1,3 +1,5 @@
1
- export * as ArticleEvent from './src/events/ArticleEvent';
2
- export * as ExternalArticleEvent from './src/events/ExternalArticleEvent';
3
- export * as InternalArticleEvent from './src/events/InternalArticleEvent';
1
+ import ArticleEvent from './src/events/ArticleEvent';
2
+ import ExternalArticleEvent from './src/events/ExternalArticleEvent';
3
+ import InternalArticleEvent from './src/events/InternalArticleEvent';
4
+
5
+ export { ArticleEvent, ExternalArticleEvent, InternalArticleEvent };
package/package.json CHANGED
@@ -1,25 +1,9 @@
1
1
  {
2
2
  "name": "@productminds/article-events",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "",
5
- "exports": {
6
- ".": {
7
- "types": "./dist/index.d.ts",
8
- "default": "./dist/index.js"
9
- },
10
- "./ArticleEvent": {
11
- "types": "./dist/ArticleEvent.d.ts",
12
- "default": "./dist/ArticleEvent.js"
13
- },
14
- "./InternalArticleEvent": {
15
- "types": "./dist/InternalArticleEvent.d.ts",
16
- "default": "./dist/InternalArticleEvent.js"
17
- },
18
- "./ExternalArticleEvent": {
19
- "types": "./dist/ExternalArticleEvent.d.ts",
20
- "default": "./dist/ExternalArticleEvent.js"
21
- }
22
- },
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
23
7
  "scripts": {
24
8
  "build": "tsc",
25
9
  "build:watch": "tsc --watch",