@productminds/article-events 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +3 -316
- package/dist/index.js +16 -72
- package/dist/src/events/ArticleEvent.d.ts +70 -0
- package/dist/src/events/ArticleEvent.js +16 -0
- package/dist/src/events/ExternalArticleEvent.d.ts +70 -0
- package/dist/src/events/ExternalArticleEvent.js +16 -0
- package/dist/src/events/InternalArticleEvent.d.ts +70 -0
- package/dist/src/events/InternalArticleEvent.js +16 -0
- package/dist/src/types/Article.d.ts +55 -0
- package/dist/src/types/Article.js +38 -0
- package/dist/src/utils/makeHelpers.d.ts +15 -0
- package/dist/src/utils/makeHelpers.js +45 -0
- package/index.ts +3 -84
- package/package.json +1 -1
- package/src/events/ArticleEvent.ts +19 -0
- package/src/events/ExternalArticleEvent.ts +19 -0
- package/src/events/InternalArticleEvent.ts +19 -0
- package/src/types/Article.ts +46 -0
- package/src/utils/makeHelpers.ts +55 -0
package/dist/index.d.ts
CHANGED
@@ -1,316 +1,3 @@
|
|
1
|
-
|
2
|
-
export
|
3
|
-
|
4
|
-
title: typeof Schema.NonEmpty;
|
5
|
-
teaser: typeof Schema.NonEmpty;
|
6
|
-
content: typeof Schema.NonEmpty;
|
7
|
-
publishedAt: typeof Schema.Date;
|
8
|
-
updatedAt: typeof Schema.Date;
|
9
|
-
retrievedAt: typeof Schema.Date;
|
10
|
-
url: typeof Schema.NonEmpty;
|
11
|
-
site: typeof Schema.NonEmpty;
|
12
|
-
tags: Schema.Array$<Schema.Union<[Schema.Struct<{
|
13
|
-
type: Schema.Literal<["category"]>;
|
14
|
-
value: typeof Schema.NonEmpty;
|
15
|
-
}>, Schema.Struct<{
|
16
|
-
type: Schema.Literal<["articleReference"]>;
|
17
|
-
id: typeof Schema.UUID;
|
18
|
-
}>]>>;
|
19
|
-
authors: Schema.Array$<Schema.Struct<{
|
20
|
-
name: typeof Schema.NonEmpty;
|
21
|
-
}>>;
|
22
|
-
meta: Schema.optional<typeof Schema.Unknown>;
|
23
|
-
}>;
|
24
|
-
export declare const ArticleEventSchema: Schema.Struct<{
|
25
|
-
kind: Schema.Literal<["ARTICLE_EVENT"]>;
|
26
|
-
payload: Schema.Struct<{
|
27
|
-
article: Schema.Struct<{
|
28
|
-
id: typeof Schema.UUID;
|
29
|
-
title: typeof Schema.NonEmpty;
|
30
|
-
teaser: typeof Schema.NonEmpty;
|
31
|
-
content: typeof Schema.NonEmpty;
|
32
|
-
publishedAt: typeof Schema.Date;
|
33
|
-
updatedAt: typeof Schema.Date;
|
34
|
-
retrievedAt: typeof Schema.Date;
|
35
|
-
url: typeof Schema.NonEmpty;
|
36
|
-
site: typeof Schema.NonEmpty;
|
37
|
-
tags: Schema.Array$<Schema.Union<[Schema.Struct<{
|
38
|
-
type: Schema.Literal<["category"]>;
|
39
|
-
value: typeof Schema.NonEmpty;
|
40
|
-
}>, Schema.Struct<{
|
41
|
-
type: Schema.Literal<["articleReference"]>;
|
42
|
-
id: typeof Schema.UUID;
|
43
|
-
}>]>>;
|
44
|
-
authors: Schema.Array$<Schema.Struct<{
|
45
|
-
name: typeof Schema.NonEmpty;
|
46
|
-
}>>;
|
47
|
-
meta: Schema.optional<typeof Schema.Unknown>;
|
48
|
-
}>;
|
49
|
-
status: Schema.Literal<["NEW", "UPDATED"]>;
|
50
|
-
source: Schema.Literal<["INTERNAL", "EXTERNAL"]>;
|
51
|
-
}>;
|
52
|
-
}>;
|
53
|
-
export declare const decode: (u: unknown, overrideOptions?: import("@effect/schema/AST").ParseOptions) => import("effect/Either").Either<{
|
54
|
-
readonly kind: "ARTICLE_EVENT";
|
55
|
-
readonly payload: {
|
56
|
-
readonly article: {
|
57
|
-
readonly id: string;
|
58
|
-
readonly title: string;
|
59
|
-
readonly teaser: string;
|
60
|
-
readonly content: string;
|
61
|
-
readonly publishedAt: Date;
|
62
|
-
readonly updatedAt: Date;
|
63
|
-
readonly retrievedAt: Date;
|
64
|
-
readonly url: string;
|
65
|
-
readonly site: string;
|
66
|
-
readonly tags: readonly ({
|
67
|
-
readonly type: "category";
|
68
|
-
readonly value: string;
|
69
|
-
} | {
|
70
|
-
readonly type: "articleReference";
|
71
|
-
readonly id: string;
|
72
|
-
})[];
|
73
|
-
readonly authors: readonly {
|
74
|
-
readonly name: string;
|
75
|
-
}[];
|
76
|
-
readonly meta?: unknown;
|
77
|
-
};
|
78
|
-
readonly status: "NEW" | "UPDATED";
|
79
|
-
readonly source: "INTERNAL" | "EXTERNAL";
|
80
|
-
};
|
81
|
-
}, import("@effect/schema/ParseResult").ParseError>;
|
82
|
-
export declare const decodeExn: (u: unknown) => {
|
83
|
-
readonly kind: "ARTICLE_EVENT";
|
84
|
-
readonly payload: {
|
85
|
-
readonly article: {
|
86
|
-
readonly id: string;
|
87
|
-
readonly title: string;
|
88
|
-
readonly teaser: string;
|
89
|
-
readonly content: string;
|
90
|
-
readonly publishedAt: Date;
|
91
|
-
readonly updatedAt: Date;
|
92
|
-
readonly retrievedAt: Date;
|
93
|
-
readonly url: string;
|
94
|
-
readonly site: string;
|
95
|
-
readonly tags: readonly ({
|
96
|
-
readonly type: "category";
|
97
|
-
readonly value: string;
|
98
|
-
} | {
|
99
|
-
readonly type: "articleReference";
|
100
|
-
readonly id: string;
|
101
|
-
})[];
|
102
|
-
readonly authors: readonly {
|
103
|
-
readonly name: string;
|
104
|
-
}[];
|
105
|
-
readonly meta?: unknown;
|
106
|
-
};
|
107
|
-
readonly status: "NEW" | "UPDATED";
|
108
|
-
readonly source: "INTERNAL" | "EXTERNAL";
|
109
|
-
};
|
110
|
-
};
|
111
|
-
export declare const encode: (a: {
|
112
|
-
readonly kind: "ARTICLE_EVENT";
|
113
|
-
readonly payload: {
|
114
|
-
readonly article: {
|
115
|
-
readonly id: string;
|
116
|
-
readonly title: string;
|
117
|
-
readonly teaser: string;
|
118
|
-
readonly content: string;
|
119
|
-
readonly publishedAt: Date;
|
120
|
-
readonly updatedAt: Date;
|
121
|
-
readonly retrievedAt: Date;
|
122
|
-
readonly url: string;
|
123
|
-
readonly site: string;
|
124
|
-
readonly tags: readonly ({
|
125
|
-
readonly type: "category";
|
126
|
-
readonly value: string;
|
127
|
-
} | {
|
128
|
-
readonly type: "articleReference";
|
129
|
-
readonly id: string;
|
130
|
-
})[];
|
131
|
-
readonly authors: readonly {
|
132
|
-
readonly name: string;
|
133
|
-
}[];
|
134
|
-
readonly meta?: unknown;
|
135
|
-
};
|
136
|
-
readonly status: "NEW" | "UPDATED";
|
137
|
-
readonly source: "INTERNAL" | "EXTERNAL";
|
138
|
-
};
|
139
|
-
}, overrideOptions?: import("@effect/schema/AST").ParseOptions) => import("effect/Either").Either<{
|
140
|
-
readonly kind: "ARTICLE_EVENT";
|
141
|
-
readonly payload: {
|
142
|
-
readonly article: {
|
143
|
-
readonly id: string;
|
144
|
-
readonly title: string;
|
145
|
-
readonly teaser: string;
|
146
|
-
readonly content: string;
|
147
|
-
readonly publishedAt: string;
|
148
|
-
readonly updatedAt: string;
|
149
|
-
readonly retrievedAt: string;
|
150
|
-
readonly url: string;
|
151
|
-
readonly site: string;
|
152
|
-
readonly tags: readonly ({
|
153
|
-
readonly type: "category";
|
154
|
-
readonly value: string;
|
155
|
-
} | {
|
156
|
-
readonly type: "articleReference";
|
157
|
-
readonly id: string;
|
158
|
-
})[];
|
159
|
-
readonly authors: readonly {
|
160
|
-
readonly name: string;
|
161
|
-
}[];
|
162
|
-
readonly meta?: unknown;
|
163
|
-
};
|
164
|
-
readonly status: "NEW" | "UPDATED";
|
165
|
-
readonly source: "INTERNAL" | "EXTERNAL";
|
166
|
-
};
|
167
|
-
}, import("@effect/schema/ParseResult").ParseError>;
|
168
|
-
export declare const encodeExn: (event: typeof ArticleEventSchema.Type) => {
|
169
|
-
readonly kind: "ARTICLE_EVENT";
|
170
|
-
readonly payload: {
|
171
|
-
readonly article: {
|
172
|
-
readonly id: string;
|
173
|
-
readonly title: string;
|
174
|
-
readonly teaser: string;
|
175
|
-
readonly content: string;
|
176
|
-
readonly publishedAt: string;
|
177
|
-
readonly updatedAt: string;
|
178
|
-
readonly retrievedAt: string;
|
179
|
-
readonly url: string;
|
180
|
-
readonly site: string;
|
181
|
-
readonly tags: readonly ({
|
182
|
-
readonly type: "category";
|
183
|
-
readonly value: string;
|
184
|
-
} | {
|
185
|
-
readonly type: "articleReference";
|
186
|
-
readonly id: string;
|
187
|
-
})[];
|
188
|
-
readonly authors: readonly {
|
189
|
-
readonly name: string;
|
190
|
-
}[];
|
191
|
-
readonly meta?: unknown;
|
192
|
-
};
|
193
|
-
readonly status: "NEW" | "UPDATED";
|
194
|
-
readonly source: "INTERNAL" | "EXTERNAL";
|
195
|
-
};
|
196
|
-
};
|
197
|
-
export declare const fromString: (msg: string) => import("effect/Either").Either<{
|
198
|
-
readonly kind: "ARTICLE_EVENT";
|
199
|
-
readonly payload: {
|
200
|
-
readonly article: {
|
201
|
-
readonly id: string;
|
202
|
-
readonly title: string;
|
203
|
-
readonly teaser: string;
|
204
|
-
readonly content: string;
|
205
|
-
readonly publishedAt: Date;
|
206
|
-
readonly updatedAt: Date;
|
207
|
-
readonly retrievedAt: Date;
|
208
|
-
readonly url: string;
|
209
|
-
readonly site: string;
|
210
|
-
readonly tags: readonly ({
|
211
|
-
readonly type: "category";
|
212
|
-
readonly value: string;
|
213
|
-
} | {
|
214
|
-
readonly type: "articleReference";
|
215
|
-
readonly id: string;
|
216
|
-
})[];
|
217
|
-
readonly authors: readonly {
|
218
|
-
readonly name: string;
|
219
|
-
}[];
|
220
|
-
readonly meta?: unknown;
|
221
|
-
};
|
222
|
-
readonly status: "NEW" | "UPDATED";
|
223
|
-
readonly source: "INTERNAL" | "EXTERNAL";
|
224
|
-
};
|
225
|
-
}, import("@effect/schema/ParseResult").ParseError>;
|
226
|
-
export declare const fromBuffer: (msg: Buffer) => import("effect/Either").Either<{
|
227
|
-
readonly kind: "ARTICLE_EVENT";
|
228
|
-
readonly payload: {
|
229
|
-
readonly article: {
|
230
|
-
readonly id: string;
|
231
|
-
readonly title: string;
|
232
|
-
readonly teaser: string;
|
233
|
-
readonly content: string;
|
234
|
-
readonly publishedAt: Date;
|
235
|
-
readonly updatedAt: Date;
|
236
|
-
readonly retrievedAt: Date;
|
237
|
-
readonly url: string;
|
238
|
-
readonly site: string;
|
239
|
-
readonly tags: readonly ({
|
240
|
-
readonly type: "category";
|
241
|
-
readonly value: string;
|
242
|
-
} | {
|
243
|
-
readonly type: "articleReference";
|
244
|
-
readonly id: string;
|
245
|
-
})[];
|
246
|
-
readonly authors: readonly {
|
247
|
-
readonly name: string;
|
248
|
-
}[];
|
249
|
-
readonly meta?: unknown;
|
250
|
-
};
|
251
|
-
readonly status: "NEW" | "UPDATED";
|
252
|
-
readonly source: "INTERNAL" | "EXTERNAL";
|
253
|
-
};
|
254
|
-
}, import("@effect/schema/ParseResult").ParseError>;
|
255
|
-
export declare const fromStringExn: (msg: string) => {
|
256
|
-
readonly kind: "ARTICLE_EVENT";
|
257
|
-
readonly payload: {
|
258
|
-
readonly article: {
|
259
|
-
readonly id: string;
|
260
|
-
readonly title: string;
|
261
|
-
readonly teaser: string;
|
262
|
-
readonly content: string;
|
263
|
-
readonly publishedAt: Date;
|
264
|
-
readonly updatedAt: Date;
|
265
|
-
readonly retrievedAt: Date;
|
266
|
-
readonly url: string;
|
267
|
-
readonly site: string;
|
268
|
-
readonly tags: readonly ({
|
269
|
-
readonly type: "category";
|
270
|
-
readonly value: string;
|
271
|
-
} | {
|
272
|
-
readonly type: "articleReference";
|
273
|
-
readonly id: string;
|
274
|
-
})[];
|
275
|
-
readonly authors: readonly {
|
276
|
-
readonly name: string;
|
277
|
-
}[];
|
278
|
-
readonly meta?: unknown;
|
279
|
-
};
|
280
|
-
readonly status: "NEW" | "UPDATED";
|
281
|
-
readonly source: "INTERNAL" | "EXTERNAL";
|
282
|
-
};
|
283
|
-
};
|
284
|
-
export declare const fromBufferExn: (msg: Buffer) => {
|
285
|
-
readonly kind: "ARTICLE_EVENT";
|
286
|
-
readonly payload: {
|
287
|
-
readonly article: {
|
288
|
-
readonly id: string;
|
289
|
-
readonly title: string;
|
290
|
-
readonly teaser: string;
|
291
|
-
readonly content: string;
|
292
|
-
readonly publishedAt: Date;
|
293
|
-
readonly updatedAt: Date;
|
294
|
-
readonly retrievedAt: Date;
|
295
|
-
readonly url: string;
|
296
|
-
readonly site: string;
|
297
|
-
readonly tags: readonly ({
|
298
|
-
readonly type: "category";
|
299
|
-
readonly value: string;
|
300
|
-
} | {
|
301
|
-
readonly type: "articleReference";
|
302
|
-
readonly id: string;
|
303
|
-
})[];
|
304
|
-
readonly authors: readonly {
|
305
|
-
readonly name: string;
|
306
|
-
}[];
|
307
|
-
readonly meta?: unknown;
|
308
|
-
};
|
309
|
-
readonly status: "NEW" | "UPDATED";
|
310
|
-
readonly source: "INTERNAL" | "EXTERNAL";
|
311
|
-
};
|
312
|
-
};
|
313
|
-
export declare const toString: (event: typeof ArticleEventSchema.Type) => string;
|
314
|
-
export declare const toBuffer: (event: typeof ArticleEventSchema.Type) => Buffer;
|
315
|
-
export declare const toStringExn: (event: typeof ArticleEventSchema.Type) => string;
|
316
|
-
export declare const toBufferExn: (event: typeof ArticleEventSchema.Type) => Buffer;
|
1
|
+
export * from './src/events/ArticleEvent';
|
2
|
+
export * from './src/events/ExternalArticleEvent';
|
3
|
+
export * from './src/events/InternalArticleEvent';
|
package/dist/index.js
CHANGED
@@ -1,75 +1,19 @@
|
|
1
1
|
"use strict";
|
2
|
-
Object.
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
});
|
8
|
-
const CategoryTagSchema = schema_1.Schema.Struct({
|
9
|
-
type: schema_1.Schema.Literal('category'),
|
10
|
-
value: schema_1.Schema.NonEmpty
|
11
|
-
});
|
12
|
-
const ArticleReferenceSchema = schema_1.Schema.Struct({
|
13
|
-
type: schema_1.Schema.Literal('articleReference'),
|
14
|
-
id: schema_1.Schema.UUID
|
15
|
-
});
|
16
|
-
const TagSchema = schema_1.Schema.Union(CategoryTagSchema, ArticleReferenceSchema);
|
17
|
-
const AuthorSchema = schema_1.Schema.Struct({
|
18
|
-
name: schema_1.Schema.NonEmpty
|
19
|
-
});
|
20
|
-
exports.ArticleSchema = schema_1.Schema.Struct({
|
21
|
-
id: schema_1.Schema.UUID,
|
22
|
-
title: schema_1.Schema.NonEmpty,
|
23
|
-
teaser: schema_1.Schema.NonEmpty,
|
24
|
-
content: schema_1.Schema.NonEmpty,
|
25
|
-
publishedAt: DateTimeSchema,
|
26
|
-
updatedAt: DateTimeSchema,
|
27
|
-
retrievedAt: DateTimeSchema,
|
28
|
-
url: schema_1.Schema.NonEmpty,
|
29
|
-
site: schema_1.Schema.NonEmpty,
|
30
|
-
tags: schema_1.Schema.Array(TagSchema),
|
31
|
-
authors: schema_1.Schema.Array(AuthorSchema),
|
32
|
-
meta: schema_1.Schema.optional(schema_1.Schema.Unknown)
|
33
|
-
});
|
34
|
-
exports.ArticleEventSchema = schema_1.Schema.Struct({
|
35
|
-
kind: schema_1.Schema.Literal('ARTICLE_EVENT'),
|
36
|
-
payload: schema_1.Schema.Struct({
|
37
|
-
article: exports.ArticleSchema,
|
38
|
-
status: schema_1.Schema.Literal('NEW', 'UPDATED'),
|
39
|
-
source: schema_1.Schema.Literal('INTERNAL', 'EXTERNAL')
|
40
|
-
})
|
41
|
-
});
|
42
|
-
exports.decode = schema_1.Schema.decodeUnknownEither(exports.ArticleEventSchema);
|
43
|
-
const decodeExn = (u) => {
|
44
|
-
const decoded = (0, exports.decode)(u);
|
45
|
-
if (decoded._tag === 'Left') {
|
46
|
-
throw new Error('Failed to decode ArticleEvent');
|
47
|
-
}
|
48
|
-
return decoded.right;
|
49
|
-
};
|
50
|
-
exports.decodeExn = decodeExn;
|
51
|
-
exports.encode = schema_1.Schema.encodeEither(exports.ArticleEventSchema);
|
52
|
-
const encodeExn = (event) => {
|
53
|
-
const encoded = (0, exports.encode)(event);
|
54
|
-
if (encoded._tag === 'Left') {
|
55
|
-
throw new Error('Failed to encode ArticleEvent');
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
56
7
|
}
|
57
|
-
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
58
15
|
};
|
59
|
-
exports
|
60
|
-
|
61
|
-
exports
|
62
|
-
|
63
|
-
exports.fromBuffer = fromBuffer;
|
64
|
-
const fromStringExn = (msg) => (0, exports.decodeExn)(JSON.parse(msg));
|
65
|
-
exports.fromStringExn = fromStringExn;
|
66
|
-
const fromBufferExn = (msg) => (0, exports.fromStringExn)(msg.toString());
|
67
|
-
exports.fromBufferExn = fromBufferExn;
|
68
|
-
const toString = (event) => JSON.stringify((0, exports.encode)(event));
|
69
|
-
exports.toString = toString;
|
70
|
-
const toBuffer = (event) => Buffer.from((0, exports.toString)(event));
|
71
|
-
exports.toBuffer = toBuffer;
|
72
|
-
const toStringExn = (event) => JSON.stringify((0, exports.encodeExn)(event));
|
73
|
-
exports.toStringExn = toStringExn;
|
74
|
-
const toBufferExn = (event) => Buffer.from((0, exports.toStringExn)(event));
|
75
|
-
exports.toBufferExn = toBufferExn;
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./src/events/ArticleEvent"), exports);
|
18
|
+
__exportStar(require("./src/events/ExternalArticleEvent"), exports);
|
19
|
+
__exportStar(require("./src/events/InternalArticleEvent"), exports);
|
@@ -0,0 +1,70 @@
|
|
1
|
+
import { Schema } from '@effect/schema';
|
2
|
+
export declare const ArticleEventSchema: Schema.Struct<{
|
3
|
+
kind: Schema.Literal<["ARTICLE_EVENT"]>;
|
4
|
+
payload: Schema.Struct<{
|
5
|
+
article: Schema.Struct<{
|
6
|
+
id: typeof Schema.UUID;
|
7
|
+
title: typeof Schema.NonEmpty;
|
8
|
+
teaser: typeof Schema.NonEmpty;
|
9
|
+
content: typeof Schema.NonEmpty;
|
10
|
+
publishedAt: typeof Schema.Date;
|
11
|
+
updatedAt: typeof Schema.Date;
|
12
|
+
retrievedAt: typeof Schema.Date;
|
13
|
+
url: typeof Schema.NonEmpty;
|
14
|
+
site: typeof Schema.NonEmpty;
|
15
|
+
tags: Schema.Array$<Schema.Union<[Schema.Struct<{
|
16
|
+
type: Schema.Literal<["CATEGORY"]>;
|
17
|
+
value: typeof Schema.NonEmpty;
|
18
|
+
}>, Schema.Struct<{
|
19
|
+
type: Schema.Literal<["EXTERNAL_ARTICLE_REFERENCE"]>;
|
20
|
+
id: typeof Schema.UUID;
|
21
|
+
}>, Schema.Struct<{
|
22
|
+
type: Schema.Literal<["ENTITY"]>;
|
23
|
+
entityType: Schema.Literal<["PERSON"]>;
|
24
|
+
value: typeof Schema.NonEmpty;
|
25
|
+
}>]>>;
|
26
|
+
authors: Schema.Array$<Schema.Struct<{
|
27
|
+
name: typeof Schema.NonEmpty;
|
28
|
+
}>>;
|
29
|
+
meta: Schema.optional<typeof Schema.Unknown>;
|
30
|
+
}>;
|
31
|
+
status: Schema.Literal<["NEW", "UPDATED"]>;
|
32
|
+
source: Schema.Literal<["INTERNAL", "EXTERNAL"]>;
|
33
|
+
}>;
|
34
|
+
}>;
|
35
|
+
declare const _default: {
|
36
|
+
Schema: Schema.Struct<{
|
37
|
+
kind: Schema.Literal<["ARTICLE_EVENT"]>;
|
38
|
+
payload: Schema.Struct<{
|
39
|
+
article: Schema.Struct<{
|
40
|
+
id: typeof Schema.UUID;
|
41
|
+
title: typeof Schema.NonEmpty;
|
42
|
+
teaser: typeof Schema.NonEmpty;
|
43
|
+
content: typeof Schema.NonEmpty;
|
44
|
+
publishedAt: typeof Schema.Date;
|
45
|
+
updatedAt: typeof Schema.Date;
|
46
|
+
retrievedAt: typeof Schema.Date;
|
47
|
+
url: typeof Schema.NonEmpty;
|
48
|
+
site: typeof Schema.NonEmpty;
|
49
|
+
tags: Schema.Array$<Schema.Union<[Schema.Struct<{
|
50
|
+
type: Schema.Literal<["CATEGORY"]>;
|
51
|
+
value: typeof Schema.NonEmpty;
|
52
|
+
}>, Schema.Struct<{
|
53
|
+
type: Schema.Literal<["EXTERNAL_ARTICLE_REFERENCE"]>;
|
54
|
+
id: typeof Schema.UUID;
|
55
|
+
}>, Schema.Struct<{
|
56
|
+
type: Schema.Literal<["ENTITY"]>;
|
57
|
+
entityType: Schema.Literal<["PERSON"]>;
|
58
|
+
value: typeof Schema.NonEmpty;
|
59
|
+
}>]>>;
|
60
|
+
authors: Schema.Array$<Schema.Struct<{
|
61
|
+
name: typeof Schema.NonEmpty;
|
62
|
+
}>>;
|
63
|
+
meta: Schema.optional<typeof Schema.Unknown>;
|
64
|
+
}>;
|
65
|
+
status: Schema.Literal<["NEW", "UPDATED"]>;
|
66
|
+
source: Schema.Literal<["INTERNAL", "EXTERNAL"]>;
|
67
|
+
}>;
|
68
|
+
}>;
|
69
|
+
};
|
70
|
+
export default _default;
|
@@ -0,0 +1,16 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.ArticleEventSchema = void 0;
|
4
|
+
const schema_1 = require("@effect/schema");
|
5
|
+
const Article_1 = require("../types/Article");
|
6
|
+
exports.ArticleEventSchema = schema_1.Schema.Struct({
|
7
|
+
kind: schema_1.Schema.Literal('ARTICLE_EVENT'),
|
8
|
+
payload: schema_1.Schema.Struct({
|
9
|
+
article: Article_1.ArticleSchema,
|
10
|
+
status: schema_1.Schema.Literal('NEW', 'UPDATED'),
|
11
|
+
source: schema_1.Schema.Literal('INTERNAL', 'EXTERNAL')
|
12
|
+
})
|
13
|
+
});
|
14
|
+
const makeHelpers_1 = require("../utils/makeHelpers");
|
15
|
+
const helpers = (0, makeHelpers_1.makeHelpers)(exports.ArticleEventSchema);
|
16
|
+
exports.default = Object.assign({ Schema: exports.ArticleEventSchema }, makeHelpers_1.makeHelpers);
|
@@ -0,0 +1,70 @@
|
|
1
|
+
import { Schema } from '@effect/schema';
|
2
|
+
export declare const ExternalArticleEventSchema: Schema.Struct<{
|
3
|
+
kind: Schema.Literal<["EXTERNAL_ARTICLE_EVENT"]>;
|
4
|
+
payload: Schema.Struct<{
|
5
|
+
article: Schema.Struct<{
|
6
|
+
id: typeof Schema.UUID;
|
7
|
+
title: typeof Schema.NonEmpty;
|
8
|
+
teaser: typeof Schema.NonEmpty;
|
9
|
+
content: typeof Schema.NonEmpty;
|
10
|
+
publishedAt: typeof Schema.Date;
|
11
|
+
updatedAt: typeof Schema.Date;
|
12
|
+
retrievedAt: typeof Schema.Date;
|
13
|
+
url: typeof Schema.NonEmpty;
|
14
|
+
site: typeof Schema.NonEmpty;
|
15
|
+
tags: Schema.Array$<Schema.Union<[Schema.Struct<{
|
16
|
+
type: Schema.Literal<["CATEGORY"]>;
|
17
|
+
value: typeof Schema.NonEmpty;
|
18
|
+
}>, Schema.Struct<{
|
19
|
+
type: Schema.Literal<["EXTERNAL_ARTICLE_REFERENCE"]>;
|
20
|
+
id: typeof Schema.UUID;
|
21
|
+
}>, Schema.Struct<{
|
22
|
+
type: Schema.Literal<["ENTITY"]>;
|
23
|
+
entityType: Schema.Literal<["PERSON"]>;
|
24
|
+
value: typeof Schema.NonEmpty;
|
25
|
+
}>]>>;
|
26
|
+
authors: Schema.Array$<Schema.Struct<{
|
27
|
+
name: typeof Schema.NonEmpty;
|
28
|
+
}>>;
|
29
|
+
meta: Schema.optional<typeof Schema.Unknown>;
|
30
|
+
}>;
|
31
|
+
status: Schema.Literal<["NEW", "UPDATED"]>;
|
32
|
+
source: Schema.Literal<["EXTERNAL"]>;
|
33
|
+
}>;
|
34
|
+
}>;
|
35
|
+
declare const _default: {
|
36
|
+
Schema: Schema.Struct<{
|
37
|
+
kind: Schema.Literal<["EXTERNAL_ARTICLE_EVENT"]>;
|
38
|
+
payload: Schema.Struct<{
|
39
|
+
article: Schema.Struct<{
|
40
|
+
id: typeof Schema.UUID;
|
41
|
+
title: typeof Schema.NonEmpty;
|
42
|
+
teaser: typeof Schema.NonEmpty;
|
43
|
+
content: typeof Schema.NonEmpty;
|
44
|
+
publishedAt: typeof Schema.Date;
|
45
|
+
updatedAt: typeof Schema.Date;
|
46
|
+
retrievedAt: typeof Schema.Date;
|
47
|
+
url: typeof Schema.NonEmpty;
|
48
|
+
site: typeof Schema.NonEmpty;
|
49
|
+
tags: Schema.Array$<Schema.Union<[Schema.Struct<{
|
50
|
+
type: Schema.Literal<["CATEGORY"]>;
|
51
|
+
value: typeof Schema.NonEmpty;
|
52
|
+
}>, Schema.Struct<{
|
53
|
+
type: Schema.Literal<["EXTERNAL_ARTICLE_REFERENCE"]>;
|
54
|
+
id: typeof Schema.UUID;
|
55
|
+
}>, Schema.Struct<{
|
56
|
+
type: Schema.Literal<["ENTITY"]>;
|
57
|
+
entityType: Schema.Literal<["PERSON"]>;
|
58
|
+
value: typeof Schema.NonEmpty;
|
59
|
+
}>]>>;
|
60
|
+
authors: Schema.Array$<Schema.Struct<{
|
61
|
+
name: typeof Schema.NonEmpty;
|
62
|
+
}>>;
|
63
|
+
meta: Schema.optional<typeof Schema.Unknown>;
|
64
|
+
}>;
|
65
|
+
status: Schema.Literal<["NEW", "UPDATED"]>;
|
66
|
+
source: Schema.Literal<["EXTERNAL"]>;
|
67
|
+
}>;
|
68
|
+
}>;
|
69
|
+
};
|
70
|
+
export default _default;
|
@@ -0,0 +1,16 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.ExternalArticleEventSchema = void 0;
|
4
|
+
const schema_1 = require("@effect/schema");
|
5
|
+
const Article_1 = require("../types/Article");
|
6
|
+
exports.ExternalArticleEventSchema = schema_1.Schema.Struct({
|
7
|
+
kind: schema_1.Schema.Literal('EXTERNAL_ARTICLE_EVENT'),
|
8
|
+
payload: schema_1.Schema.Struct({
|
9
|
+
article: Article_1.ArticleSchema,
|
10
|
+
status: schema_1.Schema.Literal('NEW', 'UPDATED'),
|
11
|
+
source: schema_1.Schema.Literal('EXTERNAL')
|
12
|
+
})
|
13
|
+
});
|
14
|
+
const makeHelpers_1 = require("../utils/makeHelpers");
|
15
|
+
const helpers = (0, makeHelpers_1.makeHelpers)(exports.ExternalArticleEventSchema);
|
16
|
+
exports.default = Object.assign({ Schema: exports.ExternalArticleEventSchema }, makeHelpers_1.makeHelpers);
|
@@ -0,0 +1,70 @@
|
|
1
|
+
import { Schema } from '@effect/schema';
|
2
|
+
export declare const InternalArticleEvent: Schema.Struct<{
|
3
|
+
kind: Schema.Literal<["INTERNAL_ARTICLE_EVENT"]>;
|
4
|
+
payload: Schema.Struct<{
|
5
|
+
article: Schema.Struct<{
|
6
|
+
id: typeof Schema.UUID;
|
7
|
+
title: typeof Schema.NonEmpty;
|
8
|
+
teaser: typeof Schema.NonEmpty;
|
9
|
+
content: typeof Schema.NonEmpty;
|
10
|
+
publishedAt: typeof Schema.Date;
|
11
|
+
updatedAt: typeof Schema.Date;
|
12
|
+
retrievedAt: typeof Schema.Date;
|
13
|
+
url: typeof Schema.NonEmpty;
|
14
|
+
site: typeof Schema.NonEmpty;
|
15
|
+
tags: Schema.Array$<Schema.Union<[Schema.Struct<{
|
16
|
+
type: Schema.Literal<["CATEGORY"]>;
|
17
|
+
value: typeof Schema.NonEmpty;
|
18
|
+
}>, Schema.Struct<{
|
19
|
+
type: Schema.Literal<["EXTERNAL_ARTICLE_REFERENCE"]>;
|
20
|
+
id: typeof Schema.UUID;
|
21
|
+
}>, Schema.Struct<{
|
22
|
+
type: Schema.Literal<["ENTITY"]>;
|
23
|
+
entityType: Schema.Literal<["PERSON"]>;
|
24
|
+
value: typeof Schema.NonEmpty;
|
25
|
+
}>]>>;
|
26
|
+
authors: Schema.Array$<Schema.Struct<{
|
27
|
+
name: typeof Schema.NonEmpty;
|
28
|
+
}>>;
|
29
|
+
meta: Schema.optional<typeof Schema.Unknown>;
|
30
|
+
}>;
|
31
|
+
status: Schema.Literal<["NEW", "UPDATED"]>;
|
32
|
+
source: Schema.Literal<["INTERNAL"]>;
|
33
|
+
}>;
|
34
|
+
}>;
|
35
|
+
declare const _default: {
|
36
|
+
Schema: Schema.Struct<{
|
37
|
+
kind: Schema.Literal<["INTERNAL_ARTICLE_EVENT"]>;
|
38
|
+
payload: Schema.Struct<{
|
39
|
+
article: Schema.Struct<{
|
40
|
+
id: typeof Schema.UUID;
|
41
|
+
title: typeof Schema.NonEmpty;
|
42
|
+
teaser: typeof Schema.NonEmpty;
|
43
|
+
content: typeof Schema.NonEmpty;
|
44
|
+
publishedAt: typeof Schema.Date;
|
45
|
+
updatedAt: typeof Schema.Date;
|
46
|
+
retrievedAt: typeof Schema.Date;
|
47
|
+
url: typeof Schema.NonEmpty;
|
48
|
+
site: typeof Schema.NonEmpty;
|
49
|
+
tags: Schema.Array$<Schema.Union<[Schema.Struct<{
|
50
|
+
type: Schema.Literal<["CATEGORY"]>;
|
51
|
+
value: typeof Schema.NonEmpty;
|
52
|
+
}>, Schema.Struct<{
|
53
|
+
type: Schema.Literal<["EXTERNAL_ARTICLE_REFERENCE"]>;
|
54
|
+
id: typeof Schema.UUID;
|
55
|
+
}>, Schema.Struct<{
|
56
|
+
type: Schema.Literal<["ENTITY"]>;
|
57
|
+
entityType: Schema.Literal<["PERSON"]>;
|
58
|
+
value: typeof Schema.NonEmpty;
|
59
|
+
}>]>>;
|
60
|
+
authors: Schema.Array$<Schema.Struct<{
|
61
|
+
name: typeof Schema.NonEmpty;
|
62
|
+
}>>;
|
63
|
+
meta: Schema.optional<typeof Schema.Unknown>;
|
64
|
+
}>;
|
65
|
+
status: Schema.Literal<["NEW", "UPDATED"]>;
|
66
|
+
source: Schema.Literal<["INTERNAL"]>;
|
67
|
+
}>;
|
68
|
+
}>;
|
69
|
+
};
|
70
|
+
export default _default;
|
@@ -0,0 +1,16 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.InternalArticleEvent = void 0;
|
4
|
+
const schema_1 = require("@effect/schema");
|
5
|
+
const Article_1 = require("../types/Article");
|
6
|
+
exports.InternalArticleEvent = schema_1.Schema.Struct({
|
7
|
+
kind: schema_1.Schema.Literal('INTERNAL_ARTICLE_EVENT'),
|
8
|
+
payload: schema_1.Schema.Struct({
|
9
|
+
article: Article_1.ArticleSchema,
|
10
|
+
status: schema_1.Schema.Literal('NEW', 'UPDATED'),
|
11
|
+
source: schema_1.Schema.Literal('INTERNAL')
|
12
|
+
})
|
13
|
+
});
|
14
|
+
const makeHelpers_1 = require("../utils/makeHelpers");
|
15
|
+
const helpers = (0, makeHelpers_1.makeHelpers)(exports.InternalArticleEvent);
|
16
|
+
exports.default = Object.assign({ Schema: exports.InternalArticleEvent }, makeHelpers_1.makeHelpers);
|
@@ -0,0 +1,55 @@
|
|
1
|
+
import { Schema } from '@effect/schema';
|
2
|
+
export declare const DateTimeSchema: typeof Schema.Date;
|
3
|
+
export declare const CategoryTagSchema: Schema.Struct<{
|
4
|
+
type: Schema.Literal<["CATEGORY"]>;
|
5
|
+
value: typeof Schema.NonEmpty;
|
6
|
+
}>;
|
7
|
+
export declare const ArticleReferenceSchema: Schema.Struct<{
|
8
|
+
type: Schema.Literal<["EXTERNAL_ARTICLE_REFERENCE"]>;
|
9
|
+
id: typeof Schema.UUID;
|
10
|
+
}>;
|
11
|
+
export declare const EntityTag: Schema.Struct<{
|
12
|
+
type: Schema.Literal<["ENTITY"]>;
|
13
|
+
entityType: Schema.Literal<["PERSON"]>;
|
14
|
+
value: typeof Schema.NonEmpty;
|
15
|
+
}>;
|
16
|
+
export declare const TagSchema: Schema.Union<[Schema.Struct<{
|
17
|
+
type: Schema.Literal<["CATEGORY"]>;
|
18
|
+
value: typeof Schema.NonEmpty;
|
19
|
+
}>, Schema.Struct<{
|
20
|
+
type: Schema.Literal<["EXTERNAL_ARTICLE_REFERENCE"]>;
|
21
|
+
id: typeof Schema.UUID;
|
22
|
+
}>, Schema.Struct<{
|
23
|
+
type: Schema.Literal<["ENTITY"]>;
|
24
|
+
entityType: Schema.Literal<["PERSON"]>;
|
25
|
+
value: typeof Schema.NonEmpty;
|
26
|
+
}>]>;
|
27
|
+
export declare const AuthorSchema: Schema.Struct<{
|
28
|
+
name: typeof Schema.NonEmpty;
|
29
|
+
}>;
|
30
|
+
export declare const ArticleSchema: Schema.Struct<{
|
31
|
+
id: typeof Schema.UUID;
|
32
|
+
title: typeof Schema.NonEmpty;
|
33
|
+
teaser: typeof Schema.NonEmpty;
|
34
|
+
content: typeof Schema.NonEmpty;
|
35
|
+
publishedAt: typeof Schema.Date;
|
36
|
+
updatedAt: typeof Schema.Date;
|
37
|
+
retrievedAt: typeof Schema.Date;
|
38
|
+
url: typeof Schema.NonEmpty;
|
39
|
+
site: typeof Schema.NonEmpty;
|
40
|
+
tags: Schema.Array$<Schema.Union<[Schema.Struct<{
|
41
|
+
type: Schema.Literal<["CATEGORY"]>;
|
42
|
+
value: typeof Schema.NonEmpty;
|
43
|
+
}>, Schema.Struct<{
|
44
|
+
type: Schema.Literal<["EXTERNAL_ARTICLE_REFERENCE"]>;
|
45
|
+
id: typeof Schema.UUID;
|
46
|
+
}>, Schema.Struct<{
|
47
|
+
type: Schema.Literal<["ENTITY"]>;
|
48
|
+
entityType: Schema.Literal<["PERSON"]>;
|
49
|
+
value: typeof Schema.NonEmpty;
|
50
|
+
}>]>>;
|
51
|
+
authors: Schema.Array$<Schema.Struct<{
|
52
|
+
name: typeof Schema.NonEmpty;
|
53
|
+
}>>;
|
54
|
+
meta: Schema.optional<typeof Schema.Unknown>;
|
55
|
+
}>;
|
@@ -0,0 +1,38 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.ArticleSchema = exports.AuthorSchema = exports.TagSchema = exports.EntityTag = exports.ArticleReferenceSchema = exports.CategoryTagSchema = exports.DateTimeSchema = void 0;
|
4
|
+
const schema_1 = require("@effect/schema");
|
5
|
+
exports.DateTimeSchema = schema_1.Schema.Date.annotations({
|
6
|
+
jsonSchema: { format: 'date-time' }
|
7
|
+
});
|
8
|
+
exports.CategoryTagSchema = schema_1.Schema.Struct({
|
9
|
+
type: schema_1.Schema.Literal('CATEGORY'),
|
10
|
+
value: schema_1.Schema.NonEmpty
|
11
|
+
});
|
12
|
+
exports.ArticleReferenceSchema = schema_1.Schema.Struct({
|
13
|
+
type: schema_1.Schema.Literal('EXTERNAL_ARTICLE_REFERENCE'),
|
14
|
+
id: schema_1.Schema.UUID
|
15
|
+
});
|
16
|
+
exports.EntityTag = schema_1.Schema.Struct({
|
17
|
+
type: schema_1.Schema.Literal('ENTITY'),
|
18
|
+
entityType: schema_1.Schema.Literal('PERSON'),
|
19
|
+
value: schema_1.Schema.NonEmpty
|
20
|
+
});
|
21
|
+
exports.TagSchema = schema_1.Schema.Union(exports.CategoryTagSchema, exports.ArticleReferenceSchema, exports.EntityTag);
|
22
|
+
exports.AuthorSchema = schema_1.Schema.Struct({
|
23
|
+
name: schema_1.Schema.NonEmpty
|
24
|
+
});
|
25
|
+
exports.ArticleSchema = schema_1.Schema.Struct({
|
26
|
+
id: schema_1.Schema.UUID,
|
27
|
+
title: schema_1.Schema.NonEmpty,
|
28
|
+
teaser: schema_1.Schema.NonEmpty,
|
29
|
+
content: schema_1.Schema.NonEmpty,
|
30
|
+
publishedAt: exports.DateTimeSchema,
|
31
|
+
updatedAt: exports.DateTimeSchema,
|
32
|
+
retrievedAt: exports.DateTimeSchema,
|
33
|
+
url: schema_1.Schema.NonEmpty,
|
34
|
+
site: schema_1.Schema.NonEmpty,
|
35
|
+
tags: schema_1.Schema.Array(exports.TagSchema),
|
36
|
+
authors: schema_1.Schema.Array(exports.AuthorSchema),
|
37
|
+
meta: schema_1.Schema.optional(schema_1.Schema.Unknown)
|
38
|
+
});
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { Schema } from '@effect/schema';
|
2
|
+
export declare const makeHelpers: <A, I>(schema: Schema.Schema<A, I, never>) => {
|
3
|
+
decode: (u: unknown, overrideOptions?: import("@effect/schema/AST").ParseOptions) => import("effect/Either").Either<A, import("@effect/schema/ParseResult").ParseError>;
|
4
|
+
decodeExn: (u: unknown) => A;
|
5
|
+
encode: (a: A, overrideOptions?: import("@effect/schema/AST").ParseOptions) => import("effect/Either").Either<I, import("@effect/schema/ParseResult").ParseError>;
|
6
|
+
encodeExn: (event: typeof schema.Type) => I;
|
7
|
+
fromString: (msg: string) => import("effect/Either").Either<A, import("@effect/schema/ParseResult").ParseError>;
|
8
|
+
fromBuffer: (msg: Buffer) => import("effect/Either").Either<A, import("@effect/schema/ParseResult").ParseError>;
|
9
|
+
fromStringExn: (msg: string) => A;
|
10
|
+
fromBufferExn: (msg: Buffer) => A;
|
11
|
+
toString: (event: typeof schema.Type) => string;
|
12
|
+
toBuffer: (event: typeof schema.Type) => Buffer;
|
13
|
+
toStringExn: (event: typeof schema.Type) => string;
|
14
|
+
toBufferExn: (event: typeof schema.Type) => Buffer;
|
15
|
+
};
|
@@ -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,84 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
jsonSchema: { format: 'date-time' }
|
5
|
-
});
|
6
|
-
|
7
|
-
const CategoryTagSchema = Schema.Struct({
|
8
|
-
type: Schema.Literal('category'),
|
9
|
-
value: Schema.NonEmpty
|
10
|
-
});
|
11
|
-
|
12
|
-
const ArticleReferenceSchema = Schema.Struct({
|
13
|
-
type: Schema.Literal('articleReference'),
|
14
|
-
id: Schema.UUID
|
15
|
-
});
|
16
|
-
|
17
|
-
const TagSchema = Schema.Union(CategoryTagSchema, ArticleReferenceSchema);
|
18
|
-
|
19
|
-
const AuthorSchema = Schema.Struct({
|
20
|
-
name: Schema.NonEmpty
|
21
|
-
});
|
22
|
-
|
23
|
-
export const ArticleSchema = Schema.Struct({
|
24
|
-
id: Schema.UUID,
|
25
|
-
title: Schema.NonEmpty,
|
26
|
-
teaser: Schema.NonEmpty,
|
27
|
-
content: Schema.NonEmpty,
|
28
|
-
publishedAt: DateTimeSchema,
|
29
|
-
updatedAt: DateTimeSchema,
|
30
|
-
retrievedAt: DateTimeSchema,
|
31
|
-
url: Schema.NonEmpty,
|
32
|
-
site: Schema.NonEmpty,
|
33
|
-
tags: Schema.Array(TagSchema),
|
34
|
-
authors: Schema.Array(AuthorSchema),
|
35
|
-
meta: Schema.optional(Schema.Unknown)
|
36
|
-
});
|
37
|
-
|
38
|
-
export const ArticleEventSchema = Schema.Struct({
|
39
|
-
kind: Schema.Literal('ARTICLE_EVENT'),
|
40
|
-
payload: Schema.Struct({
|
41
|
-
article: ArticleSchema,
|
42
|
-
status: Schema.Literal('NEW', 'UPDATED'),
|
43
|
-
source: Schema.Literal('INTERNAL', 'EXTERNAL')
|
44
|
-
})
|
45
|
-
});
|
46
|
-
|
47
|
-
export const decode = Schema.decodeUnknownEither(ArticleEventSchema);
|
48
|
-
export const decodeExn = (u: unknown) => {
|
49
|
-
const decoded = decode(u);
|
50
|
-
|
51
|
-
if (decoded._tag === 'Left') {
|
52
|
-
throw new Error('Failed to decode ArticleEvent');
|
53
|
-
}
|
54
|
-
|
55
|
-
return decoded.right;
|
56
|
-
};
|
57
|
-
|
58
|
-
export const encode = Schema.encodeEither(ArticleEventSchema);
|
59
|
-
export const encodeExn = (event: typeof ArticleEventSchema.Type) => {
|
60
|
-
const encoded = encode(event);
|
61
|
-
|
62
|
-
if (encoded._tag === 'Left') {
|
63
|
-
throw new Error('Failed to encode ArticleEvent');
|
64
|
-
}
|
65
|
-
|
66
|
-
return encoded.right;
|
67
|
-
};
|
68
|
-
|
69
|
-
export const fromString = (msg: string) => decode(JSON.parse(msg));
|
70
|
-
export const fromBuffer = (msg: Buffer) => decode(JSON.parse(msg.toString()));
|
71
|
-
|
72
|
-
export const fromStringExn = (msg: string) => decodeExn(JSON.parse(msg));
|
73
|
-
export const fromBufferExn = (msg: Buffer) => fromStringExn(msg.toString());
|
74
|
-
|
75
|
-
export const toString = (event: typeof ArticleEventSchema.Type) =>
|
76
|
-
JSON.stringify(encode(event));
|
77
|
-
|
78
|
-
export const toBuffer = (event: typeof ArticleEventSchema.Type) =>
|
79
|
-
Buffer.from(toString(event));
|
80
|
-
|
81
|
-
export const toStringExn = (event: typeof ArticleEventSchema.Type) =>
|
82
|
-
JSON.stringify(encodeExn(event));
|
83
|
-
export const toBufferExn = (event: typeof ArticleEventSchema.Type) =>
|
84
|
-
Buffer.from(toStringExn(event));
|
1
|
+
export * from './src/events/ArticleEvent';
|
2
|
+
export * from './src/events/ExternalArticleEvent';
|
3
|
+
export * from './src/events/InternalArticleEvent';
|
package/package.json
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
import { Schema } from '@effect/schema';
|
2
|
+
import { ArticleSchema } from '../types/Article';
|
3
|
+
|
4
|
+
export const ArticleEventSchema = Schema.Struct({
|
5
|
+
kind: Schema.Literal('ARTICLE_EVENT'),
|
6
|
+
payload: Schema.Struct({
|
7
|
+
article: ArticleSchema,
|
8
|
+
status: Schema.Literal('NEW', 'UPDATED'),
|
9
|
+
source: Schema.Literal('INTERNAL', 'EXTERNAL')
|
10
|
+
})
|
11
|
+
});
|
12
|
+
|
13
|
+
import { makeHelpers } from '../utils/makeHelpers';
|
14
|
+
const helpers = makeHelpers(ArticleEventSchema);
|
15
|
+
|
16
|
+
export default {
|
17
|
+
Schema: ArticleEventSchema,
|
18
|
+
...makeHelpers
|
19
|
+
};
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { Schema } from '@effect/schema';
|
2
|
+
import { ArticleSchema } from '../types/Article';
|
3
|
+
|
4
|
+
export const ExternalArticleEventSchema = Schema.Struct({
|
5
|
+
kind: Schema.Literal('EXTERNAL_ARTICLE_EVENT'),
|
6
|
+
payload: Schema.Struct({
|
7
|
+
article: ArticleSchema,
|
8
|
+
status: Schema.Literal('NEW', 'UPDATED'),
|
9
|
+
source: Schema.Literal('EXTERNAL')
|
10
|
+
})
|
11
|
+
});
|
12
|
+
|
13
|
+
import { makeHelpers } from '../utils/makeHelpers';
|
14
|
+
const helpers = makeHelpers(ExternalArticleEventSchema);
|
15
|
+
|
16
|
+
export default {
|
17
|
+
Schema: ExternalArticleEventSchema,
|
18
|
+
...makeHelpers
|
19
|
+
};
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { Schema } from '@effect/schema';
|
2
|
+
import { ArticleSchema } from '../types/Article';
|
3
|
+
|
4
|
+
export const InternalArticleEvent = Schema.Struct({
|
5
|
+
kind: Schema.Literal('INTERNAL_ARTICLE_EVENT'),
|
6
|
+
payload: Schema.Struct({
|
7
|
+
article: ArticleSchema,
|
8
|
+
status: Schema.Literal('NEW', 'UPDATED'),
|
9
|
+
source: Schema.Literal('INTERNAL')
|
10
|
+
})
|
11
|
+
});
|
12
|
+
|
13
|
+
import { makeHelpers } from '../utils/makeHelpers';
|
14
|
+
const helpers = makeHelpers(InternalArticleEvent);
|
15
|
+
|
16
|
+
export default {
|
17
|
+
Schema: InternalArticleEvent,
|
18
|
+
...makeHelpers
|
19
|
+
};
|
@@ -0,0 +1,46 @@
|
|
1
|
+
import { Schema } from '@effect/schema';
|
2
|
+
|
3
|
+
export const DateTimeSchema = Schema.Date.annotations({
|
4
|
+
jsonSchema: { format: 'date-time' }
|
5
|
+
});
|
6
|
+
|
7
|
+
export const CategoryTagSchema = Schema.Struct({
|
8
|
+
type: Schema.Literal('CATEGORY'),
|
9
|
+
value: Schema.NonEmpty
|
10
|
+
});
|
11
|
+
|
12
|
+
export const ArticleReferenceSchema = Schema.Struct({
|
13
|
+
type: Schema.Literal('EXTERNAL_ARTICLE_REFERENCE'),
|
14
|
+
id: Schema.UUID
|
15
|
+
});
|
16
|
+
|
17
|
+
export const EntityTag = Schema.Struct({
|
18
|
+
type: Schema.Literal('ENTITY'),
|
19
|
+
entityType: Schema.Literal('PERSON'),
|
20
|
+
value: Schema.NonEmpty
|
21
|
+
});
|
22
|
+
|
23
|
+
export const TagSchema = Schema.Union(
|
24
|
+
CategoryTagSchema,
|
25
|
+
ArticleReferenceSchema,
|
26
|
+
EntityTag
|
27
|
+
);
|
28
|
+
|
29
|
+
export const AuthorSchema = Schema.Struct({
|
30
|
+
name: Schema.NonEmpty
|
31
|
+
});
|
32
|
+
|
33
|
+
export const ArticleSchema = Schema.Struct({
|
34
|
+
id: Schema.UUID,
|
35
|
+
title: Schema.NonEmpty,
|
36
|
+
teaser: Schema.NonEmpty,
|
37
|
+
content: Schema.NonEmpty,
|
38
|
+
publishedAt: DateTimeSchema,
|
39
|
+
updatedAt: DateTimeSchema,
|
40
|
+
retrievedAt: DateTimeSchema,
|
41
|
+
url: Schema.NonEmpty,
|
42
|
+
site: Schema.NonEmpty,
|
43
|
+
tags: Schema.Array(TagSchema),
|
44
|
+
authors: Schema.Array(AuthorSchema),
|
45
|
+
meta: Schema.optional(Schema.Unknown)
|
46
|
+
});
|
@@ -0,0 +1,55 @@
|
|
1
|
+
import { Schema } from '@effect/schema';
|
2
|
+
|
3
|
+
export const makeHelpers = <A, I>(schema: Schema.Schema<A, I, never>) => {
|
4
|
+
const decode = Schema.decodeUnknownEither(schema);
|
5
|
+
const decodeExn = (u: unknown) => {
|
6
|
+
const decoded = decode(u);
|
7
|
+
|
8
|
+
if (decoded._tag === 'Left') {
|
9
|
+
throw new Error('Failed to decode ArticleEvent');
|
10
|
+
}
|
11
|
+
|
12
|
+
return decoded.right;
|
13
|
+
};
|
14
|
+
|
15
|
+
const encode = Schema.encodeEither(schema);
|
16
|
+
const encodeExn = (event: typeof schema.Type) => {
|
17
|
+
const encoded = encode(event);
|
18
|
+
|
19
|
+
if (encoded._tag === 'Left') {
|
20
|
+
throw new Error('Failed to encode ArticleEvent');
|
21
|
+
}
|
22
|
+
|
23
|
+
return encoded.right;
|
24
|
+
};
|
25
|
+
|
26
|
+
const fromString = (msg: string) => decode(JSON.parse(msg));
|
27
|
+
const fromBuffer = (msg: Buffer) => decode(JSON.parse(msg.toString()));
|
28
|
+
|
29
|
+
const fromStringExn = (msg: string) => decodeExn(JSON.parse(msg));
|
30
|
+
const fromBufferExn = (msg: Buffer) => fromStringExn(msg.toString());
|
31
|
+
|
32
|
+
const toString = (event: typeof schema.Type) => JSON.stringify(encode(event));
|
33
|
+
|
34
|
+
const toBuffer = (event: typeof schema.Type) => Buffer.from(toString(event));
|
35
|
+
|
36
|
+
const toStringExn = (event: typeof schema.Type) =>
|
37
|
+
JSON.stringify(encodeExn(event));
|
38
|
+
const toBufferExn = (event: typeof schema.Type) =>
|
39
|
+
Buffer.from(toStringExn(event));
|
40
|
+
|
41
|
+
return {
|
42
|
+
decode,
|
43
|
+
decodeExn,
|
44
|
+
encode,
|
45
|
+
encodeExn,
|
46
|
+
fromString,
|
47
|
+
fromBuffer,
|
48
|
+
fromStringExn,
|
49
|
+
fromBufferExn,
|
50
|
+
toString,
|
51
|
+
toBuffer,
|
52
|
+
toStringExn,
|
53
|
+
toBufferExn
|
54
|
+
};
|
55
|
+
};
|