@backstage/plugin-events-backend-test-utils 0.0.0-nightly-20221115024001
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/CHANGELOG.md +19 -0
- package/README.md +4 -0
- package/dist/index.cjs.js +69 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/package.json +34 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @backstage/plugin-events-backend-test-utils
|
|
2
|
+
|
|
3
|
+
## 0.0.0-nightly-20221115024001
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 7bbd2403a1: Adds a new backend plugin plugin-events-backend for managing events.
|
|
8
|
+
|
|
9
|
+
plugin-events-node exposes interfaces which can be used by modules.
|
|
10
|
+
|
|
11
|
+
plugin-events-backend-test-utils provides utilities which can be used while writing tests e.g. for modules.
|
|
12
|
+
|
|
13
|
+
Please find more information at
|
|
14
|
+
https://github.com/backstage/backstage/tree/master/plugins/events-backend/README.md.
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies
|
|
19
|
+
- @backstage/plugin-events-node@0.0.0-nightly-20221115024001
|
package/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
class TestEventBroker {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.published = [];
|
|
8
|
+
this.subscribed = [];
|
|
9
|
+
}
|
|
10
|
+
async publish(params) {
|
|
11
|
+
this.published.push(params);
|
|
12
|
+
}
|
|
13
|
+
subscribe(...subscribers) {
|
|
14
|
+
this.subscribed.push(...subscribers.flat());
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
var __accessCheck = (obj, member, msg) => {
|
|
19
|
+
if (!member.has(obj))
|
|
20
|
+
throw TypeError("Cannot " + msg);
|
|
21
|
+
};
|
|
22
|
+
var __privateGet = (obj, member, getter) => {
|
|
23
|
+
__accessCheck(obj, member, "read from private field");
|
|
24
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
25
|
+
};
|
|
26
|
+
var __privateAdd = (obj, member, value) => {
|
|
27
|
+
if (member.has(obj))
|
|
28
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
29
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
30
|
+
};
|
|
31
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
32
|
+
__accessCheck(obj, member, "write to private field");
|
|
33
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
34
|
+
return value;
|
|
35
|
+
};
|
|
36
|
+
var _eventBroker;
|
|
37
|
+
class TestEventPublisher {
|
|
38
|
+
constructor() {
|
|
39
|
+
__privateAdd(this, _eventBroker, void 0);
|
|
40
|
+
}
|
|
41
|
+
async setEventBroker(eventBroker) {
|
|
42
|
+
__privateSet(this, _eventBroker, eventBroker);
|
|
43
|
+
}
|
|
44
|
+
get eventBroker() {
|
|
45
|
+
return __privateGet(this, _eventBroker);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
_eventBroker = new WeakMap();
|
|
49
|
+
|
|
50
|
+
class TestEventSubscriber {
|
|
51
|
+
constructor(name, topics) {
|
|
52
|
+
this.receivedEvents = {};
|
|
53
|
+
this.name = name;
|
|
54
|
+
this.topics = topics;
|
|
55
|
+
}
|
|
56
|
+
supportsEventTopics() {
|
|
57
|
+
return this.topics;
|
|
58
|
+
}
|
|
59
|
+
async onEvent(params) {
|
|
60
|
+
var _a;
|
|
61
|
+
this.receivedEvents[params.topic] = (_a = this.receivedEvents[params.topic]) != null ? _a : [];
|
|
62
|
+
this.receivedEvents[params.topic].push(params);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
exports.TestEventBroker = TestEventBroker;
|
|
67
|
+
exports.TestEventPublisher = TestEventPublisher;
|
|
68
|
+
exports.TestEventSubscriber = TestEventSubscriber;
|
|
69
|
+
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/testUtils/TestEventBroker.ts","../src/testUtils/TestEventPublisher.ts","../src/testUtils/TestEventSubscriber.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n EventBroker,\n EventParams,\n EventSubscriber,\n} from '@backstage/plugin-events-node';\n\n/** @public */\nexport class TestEventBroker implements EventBroker {\n readonly published: EventParams[] = [];\n readonly subscribed: EventSubscriber[] = [];\n\n async publish(params: EventParams): Promise<void> {\n this.published.push(params);\n }\n\n subscribe(\n ...subscribers: Array<EventSubscriber | Array<EventSubscriber>>\n ): void {\n this.subscribed.push(...subscribers.flat());\n }\n}\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { EventBroker, EventPublisher } from '@backstage/plugin-events-node';\n\n/** @public */\nexport class TestEventPublisher implements EventPublisher {\n #eventBroker?: EventBroker;\n\n async setEventBroker(eventBroker: EventBroker): Promise<void> {\n this.#eventBroker = eventBroker;\n }\n\n get eventBroker() {\n return this.#eventBroker;\n }\n}\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { EventParams, EventSubscriber } from '@backstage/plugin-events-node';\n\n/** @public */\nexport class TestEventSubscriber implements EventSubscriber {\n readonly name: string;\n readonly topics: string[];\n\n readonly receivedEvents: Record<string, EventParams[]> = {};\n\n constructor(name: string, topics: string[]) {\n this.name = name;\n this.topics = topics;\n }\n\n supportsEventTopics(): string[] {\n return this.topics;\n }\n\n async onEvent(params: EventParams): Promise<void> {\n this.receivedEvents[params.topic] = this.receivedEvents[params.topic] ?? [];\n this.receivedEvents[params.topic].push(params);\n }\n}\n"],"names":[],"mappings":";;;;AAuBO,MAAM,eAAuC,CAAA;AAAA,EAA7C,WAAA,GAAA;AACL,IAAA,IAAA,CAAS,YAA2B,EAAC,CAAA;AACrC,IAAA,IAAA,CAAS,aAAgC,EAAC,CAAA;AAAA,GAAA;AAAA,EAE1C,MAAM,QAAQ,MAAoC,EAAA;AAChD,IAAK,IAAA,CAAA,SAAA,CAAU,KAAK,MAAM,CAAA,CAAA;AAAA,GAC5B;AAAA,EAEA,aACK,WACG,EAAA;AACN,IAAA,IAAA,CAAK,UAAW,CAAA,IAAA,CAAK,GAAG,WAAA,CAAY,MAAM,CAAA,CAAA;AAAA,GAC5C;AACF;;;;;;;;;;;;;;;;;;;;ACpCA,IAAA,YAAA,CAAA;AAmBO,MAAM,kBAA6C,CAAA;AAAA,EAAnD,WAAA,GAAA;AACL,IAAA,YAAA,CAAA,IAAA,EAAA,YAAA,EAAA,KAAA,CAAA,CAAA,CAAA;AAAA,GAAA;AAAA,EAEA,MAAM,eAAe,WAAyC,EAAA;AAC5D,IAAA,YAAA,CAAA,IAAA,EAAK,YAAe,EAAA,WAAA,CAAA,CAAA;AAAA,GACtB;AAAA,EAEA,IAAI,WAAc,GAAA;AAChB,IAAA,OAAO,YAAK,CAAA,IAAA,EAAA,YAAA,CAAA,CAAA;AAAA,GACd;AACF,CAAA;AATE,YAAA,GAAA,IAAA,OAAA,EAAA;;ACDK,MAAM,mBAA+C,CAAA;AAAA,EAM1D,WAAA,CAAY,MAAc,MAAkB,EAAA;AAF5C,IAAA,IAAA,CAAS,iBAAgD,EAAC,CAAA;AAGxD,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA,CAAA;AACZ,IAAA,IAAA,CAAK,MAAS,GAAA,MAAA,CAAA;AAAA,GAChB;AAAA,EAEA,mBAAgC,GAAA;AAC9B,IAAA,OAAO,IAAK,CAAA,MAAA,CAAA;AAAA,GACd;AAAA,EAEA,MAAM,QAAQ,MAAoC,EAAA;AAlCpD,IAAA,IAAA,EAAA,CAAA;AAmCI,IAAK,IAAA,CAAA,cAAA,CAAe,OAAO,KAAS,CAAA,GAAA,CAAA,EAAA,GAAA,IAAA,CAAK,eAAe,MAAO,CAAA,KAAA,CAAA,KAA3B,YAAqC,EAAC,CAAA;AAC1E,IAAA,IAAA,CAAK,cAAe,CAAA,MAAA,CAAO,KAAO,CAAA,CAAA,IAAA,CAAK,MAAM,CAAA,CAAA;AAAA,GAC/C;AACF;;;;;;"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { EventBroker, EventParams, EventSubscriber, EventPublisher } from '@backstage/plugin-events-node';
|
|
2
|
+
|
|
3
|
+
/** @public */
|
|
4
|
+
declare class TestEventBroker implements EventBroker {
|
|
5
|
+
readonly published: EventParams[];
|
|
6
|
+
readonly subscribed: EventSubscriber[];
|
|
7
|
+
publish(params: EventParams): Promise<void>;
|
|
8
|
+
subscribe(...subscribers: Array<EventSubscriber | Array<EventSubscriber>>): void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** @public */
|
|
12
|
+
declare class TestEventPublisher implements EventPublisher {
|
|
13
|
+
#private;
|
|
14
|
+
setEventBroker(eventBroker: EventBroker): Promise<void>;
|
|
15
|
+
get eventBroker(): EventBroker | undefined;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** @public */
|
|
19
|
+
declare class TestEventSubscriber implements EventSubscriber {
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly topics: string[];
|
|
22
|
+
readonly receivedEvents: Record<string, EventParams[]>;
|
|
23
|
+
constructor(name: string, topics: string[]);
|
|
24
|
+
supportsEventTopics(): string[];
|
|
25
|
+
onEvent(params: EventParams): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { TestEventBroker, TestEventPublisher, TestEventSubscriber };
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@backstage/plugin-events-backend-test-utils",
|
|
3
|
+
"description": "The plugin-events-backend-test-utils for @backstage/plugin-events-node",
|
|
4
|
+
"version": "0.0.0-nightly-20221115024001",
|
|
5
|
+
"main": "dist/index.cjs.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public",
|
|
10
|
+
"main": "dist/index.cjs.js",
|
|
11
|
+
"types": "dist/index.d.ts"
|
|
12
|
+
},
|
|
13
|
+
"backstage": {
|
|
14
|
+
"role": "node-library"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"start": "backstage-cli package start",
|
|
18
|
+
"build": "backstage-cli package build",
|
|
19
|
+
"lint": "backstage-cli package lint",
|
|
20
|
+
"test": "backstage-cli package test",
|
|
21
|
+
"clean": "backstage-cli package clean",
|
|
22
|
+
"prepack": "backstage-cli package prepack",
|
|
23
|
+
"postpack": "backstage-cli package postpack"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@backstage/plugin-events-node": "^0.0.0-nightly-20221115024001"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@backstage/cli": "^0.0.0-nightly-20221115024001"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist"
|
|
33
|
+
]
|
|
34
|
+
}
|