@tsed/adapters 7.18.2 → 7.18.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.
@@ -1,89 +0,0 @@
1
- import {PlatformTest} from "@tsed/common";
2
- import {DiscriminatorKey, DiscriminatorValue, Property, Required} from "@tsed/schema";
3
- import {Adapter, Adapters, FileSyncAdapter} from "../src/index";
4
-
5
- class Event {
6
- @DiscriminatorKey() // declare this property a discriminator key
7
- type: string;
8
-
9
- @Property()
10
- value: string;
11
- }
12
-
13
- class SubEvent extends Event {
14
- @Property()
15
- meta: string;
16
- }
17
-
18
- @DiscriminatorValue("page_view") // or @DiscriminatorValue() value can be inferred by the class name
19
- class PageView extends SubEvent {
20
- @Required()
21
- url: string;
22
- }
23
-
24
- @DiscriminatorValue("action", "click_action")
25
- class Action extends SubEvent {
26
- @Required()
27
- event: string;
28
- }
29
-
30
- @DiscriminatorValue()
31
- class CustomAction extends Event {
32
- @Required()
33
- event: string;
34
-
35
- @Property()
36
- meta: string;
37
- }
38
-
39
- type OneOfEvents = PageView | Action | CustomAction;
40
-
41
- describe("Discriminator", () => {
42
- let adapter: Adapter<OneOfEvents>;
43
- beforeEach(() => PlatformTest.create());
44
- afterEach(() => PlatformTest.reset());
45
- beforeEach(() => {
46
- adapter = PlatformTest.get<Adapters>(Adapters).invokeAdapter<any>({
47
- collectionName: "events",
48
- model: Event,
49
- adapter: FileSyncAdapter
50
- });
51
- });
52
-
53
- it("should store data and return the same type as expected", async () => {
54
- const item1 = new Action();
55
- item1.event = "action_event";
56
- item1.value = "value";
57
- item1.meta = "meta";
58
-
59
- const item2 = new CustomAction();
60
- item2.event = "custom_action";
61
- item2.value = "value";
62
- item2.meta = "meta2";
63
-
64
- await adapter.deleteMany({});
65
-
66
- await adapter.create(item1);
67
- await adapter.create(item2);
68
-
69
- const result = await adapter.findAll();
70
-
71
- expect(result).toEqual([
72
- {
73
- event: "action_event",
74
- meta: "meta",
75
- type: "action",
76
- value: "value"
77
- },
78
- {
79
- event: "custom_action",
80
- meta: "meta2",
81
- type: "custom_action",
82
- value: "value"
83
- }
84
- ]);
85
-
86
- expect(result[0]).toBeInstanceOf(Action);
87
- expect(result[1]).toBeInstanceOf(CustomAction);
88
- });
89
- });
@@ -1,12 +0,0 @@
1
- {
2
- "extends": "./tsconfig.compile.json",
3
- "compilerOptions": {
4
- "baseUrl": ".",
5
- "module": "ES2020",
6
- "rootDir": "src",
7
- "outDir": "./lib/esm",
8
- "declaration": true,
9
- "declarationDir": "./lib/types"
10
- },
11
- "exclude": ["node_modules", "test", "lib", "benchmark", "coverage", "spec", "**/*.benchmark.ts", "**/*.spec.ts", "keys", "jest.config.js"]
12
- }