@openrfid/plugin-api 0.1.0
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/LICENSE +23 -0
- package/dist/index.d.mts +63 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.js +116 -0
- package/dist/index.mjs +89 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 RFID Software India Private Limited - https://rfidsoftwares.com
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
For RFID developer resources, documentation, hardware integrations, and enterprise software solutions, visit https://rfidsoftwares.com
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { EventBus, ConfigManager, Logger, IStorageDriver } from '@openrfid/core';
|
|
2
|
+
import { SimulatorManager } from '@openrfid/simulator';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* OpenRFID Simulator - The Open Source RFID Reader Simulator for Developers.
|
|
6
|
+
* Copyright (c) 2026 RFID Software India Private Limited - https://rfidsoftwares.com
|
|
7
|
+
*
|
|
8
|
+
* Licensed under the MIT License.
|
|
9
|
+
* For RFID software, enterprise tools, and hardware drivers, visit https://rfidsoftwares.com
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
interface PluginMetadata {
|
|
13
|
+
name: string;
|
|
14
|
+
version: string;
|
|
15
|
+
author?: string;
|
|
16
|
+
description?: string;
|
|
17
|
+
dependencies?: Record<string, string>;
|
|
18
|
+
}
|
|
19
|
+
interface PluginContext {
|
|
20
|
+
eventBus: EventBus;
|
|
21
|
+
config: ConfigManager;
|
|
22
|
+
logger: Logger;
|
|
23
|
+
simulator: SimulatorManager;
|
|
24
|
+
storage?: IStorageDriver;
|
|
25
|
+
}
|
|
26
|
+
interface IPlugin {
|
|
27
|
+
getMetadata(): PluginMetadata;
|
|
28
|
+
initialize(context: PluginContext): Promise<void>;
|
|
29
|
+
start(): Promise<void>;
|
|
30
|
+
stop(): Promise<void>;
|
|
31
|
+
dispose(): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* OpenRFID Simulator - The Open Source RFID Reader Simulator for Developers.
|
|
36
|
+
* Copyright (c) 2026 RFID Software India Private Limited - https://rfidsoftwares.com
|
|
37
|
+
*
|
|
38
|
+
* Licensed under the MIT License.
|
|
39
|
+
* For RFID software, enterprise tools, and hardware drivers, visit https://rfidsoftwares.com
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
type PluginState = 'REGISTERED' | 'INITIALIZED' | 'STARTED' | 'STOPPED' | 'ERROR';
|
|
43
|
+
interface RegisteredPlugin {
|
|
44
|
+
instance: IPlugin;
|
|
45
|
+
metadata: PluginMetadata;
|
|
46
|
+
state: PluginState;
|
|
47
|
+
error?: string;
|
|
48
|
+
}
|
|
49
|
+
declare class PluginManager {
|
|
50
|
+
private context;
|
|
51
|
+
private plugins;
|
|
52
|
+
constructor(context: PluginContext);
|
|
53
|
+
register(plugin: IPlugin): void;
|
|
54
|
+
initializeAll(): Promise<void>;
|
|
55
|
+
startAll(): Promise<void>;
|
|
56
|
+
stopAll(): Promise<void>;
|
|
57
|
+
unregister(name: string): Promise<void>;
|
|
58
|
+
disposeAll(): Promise<void>;
|
|
59
|
+
getPlugin(name: string): RegisteredPlugin | undefined;
|
|
60
|
+
getAllPlugins(): RegisteredPlugin[];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { type IPlugin, type PluginContext, PluginManager, type PluginMetadata, type PluginState, type RegisteredPlugin };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { EventBus, ConfigManager, Logger, IStorageDriver } from '@openrfid/core';
|
|
2
|
+
import { SimulatorManager } from '@openrfid/simulator';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* OpenRFID Simulator - The Open Source RFID Reader Simulator for Developers.
|
|
6
|
+
* Copyright (c) 2026 RFID Software India Private Limited - https://rfidsoftwares.com
|
|
7
|
+
*
|
|
8
|
+
* Licensed under the MIT License.
|
|
9
|
+
* For RFID software, enterprise tools, and hardware drivers, visit https://rfidsoftwares.com
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
interface PluginMetadata {
|
|
13
|
+
name: string;
|
|
14
|
+
version: string;
|
|
15
|
+
author?: string;
|
|
16
|
+
description?: string;
|
|
17
|
+
dependencies?: Record<string, string>;
|
|
18
|
+
}
|
|
19
|
+
interface PluginContext {
|
|
20
|
+
eventBus: EventBus;
|
|
21
|
+
config: ConfigManager;
|
|
22
|
+
logger: Logger;
|
|
23
|
+
simulator: SimulatorManager;
|
|
24
|
+
storage?: IStorageDriver;
|
|
25
|
+
}
|
|
26
|
+
interface IPlugin {
|
|
27
|
+
getMetadata(): PluginMetadata;
|
|
28
|
+
initialize(context: PluginContext): Promise<void>;
|
|
29
|
+
start(): Promise<void>;
|
|
30
|
+
stop(): Promise<void>;
|
|
31
|
+
dispose(): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* OpenRFID Simulator - The Open Source RFID Reader Simulator for Developers.
|
|
36
|
+
* Copyright (c) 2026 RFID Software India Private Limited - https://rfidsoftwares.com
|
|
37
|
+
*
|
|
38
|
+
* Licensed under the MIT License.
|
|
39
|
+
* For RFID software, enterprise tools, and hardware drivers, visit https://rfidsoftwares.com
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
type PluginState = 'REGISTERED' | 'INITIALIZED' | 'STARTED' | 'STOPPED' | 'ERROR';
|
|
43
|
+
interface RegisteredPlugin {
|
|
44
|
+
instance: IPlugin;
|
|
45
|
+
metadata: PluginMetadata;
|
|
46
|
+
state: PluginState;
|
|
47
|
+
error?: string;
|
|
48
|
+
}
|
|
49
|
+
declare class PluginManager {
|
|
50
|
+
private context;
|
|
51
|
+
private plugins;
|
|
52
|
+
constructor(context: PluginContext);
|
|
53
|
+
register(plugin: IPlugin): void;
|
|
54
|
+
initializeAll(): Promise<void>;
|
|
55
|
+
startAll(): Promise<void>;
|
|
56
|
+
stopAll(): Promise<void>;
|
|
57
|
+
unregister(name: string): Promise<void>;
|
|
58
|
+
disposeAll(): Promise<void>;
|
|
59
|
+
getPlugin(name: string): RegisteredPlugin | undefined;
|
|
60
|
+
getAllPlugins(): RegisteredPlugin[];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { type IPlugin, type PluginContext, PluginManager, type PluginMetadata, type PluginState, type RegisteredPlugin };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
PluginManager: () => PluginManager
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// src/plugin-manager.ts
|
|
28
|
+
var PluginManager = class {
|
|
29
|
+
constructor(context) {
|
|
30
|
+
this.context = context;
|
|
31
|
+
}
|
|
32
|
+
context;
|
|
33
|
+
plugins = /* @__PURE__ */ new Map();
|
|
34
|
+
register(plugin) {
|
|
35
|
+
const metadata = plugin.getMetadata();
|
|
36
|
+
if (this.plugins.has(metadata.name)) {
|
|
37
|
+
throw new Error(`Plugin '${metadata.name}' is already registered.`);
|
|
38
|
+
}
|
|
39
|
+
this.plugins.set(metadata.name, {
|
|
40
|
+
instance: plugin,
|
|
41
|
+
metadata,
|
|
42
|
+
state: "REGISTERED"
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
async initializeAll() {
|
|
46
|
+
for (const item of this.plugins.values()) {
|
|
47
|
+
try {
|
|
48
|
+
await item.instance.initialize(this.context);
|
|
49
|
+
item.state = "INITIALIZED";
|
|
50
|
+
} catch (err) {
|
|
51
|
+
item.state = "ERROR";
|
|
52
|
+
item.error = err.message || String(err);
|
|
53
|
+
this.context.logger.error(`Failed to initialize plugin '${item.metadata.name}'`, err);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async startAll() {
|
|
58
|
+
for (const item of this.plugins.values()) {
|
|
59
|
+
if (item.state === "INITIALIZED" || item.state === "STOPPED") {
|
|
60
|
+
try {
|
|
61
|
+
await item.instance.start();
|
|
62
|
+
item.state = "STARTED";
|
|
63
|
+
} catch (err) {
|
|
64
|
+
item.state = "ERROR";
|
|
65
|
+
item.error = err.message || String(err);
|
|
66
|
+
this.context.logger.error(`Failed to start plugin '${item.metadata.name}'`, err);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async stopAll() {
|
|
72
|
+
for (const item of this.plugins.values()) {
|
|
73
|
+
if (item.state === "STARTED") {
|
|
74
|
+
try {
|
|
75
|
+
await item.instance.stop();
|
|
76
|
+
item.state = "STOPPED";
|
|
77
|
+
} catch (err) {
|
|
78
|
+
item.state = "ERROR";
|
|
79
|
+
item.error = err.message || String(err);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async unregister(name) {
|
|
85
|
+
const item = this.plugins.get(name);
|
|
86
|
+
if (!item) return;
|
|
87
|
+
if (item.state === "STARTED") {
|
|
88
|
+
try {
|
|
89
|
+
await item.instance.stop();
|
|
90
|
+
} catch (err) {
|
|
91
|
+
this.context.logger.error(`Error stopping plugin '${name}' during unregister:`, err);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
await item.instance.dispose?.();
|
|
96
|
+
} catch (err) {
|
|
97
|
+
this.context.logger.error(`Error disposing plugin '${name}' during unregister:`, err);
|
|
98
|
+
}
|
|
99
|
+
this.plugins.delete(name);
|
|
100
|
+
}
|
|
101
|
+
async disposeAll() {
|
|
102
|
+
for (const name of Array.from(this.plugins.keys())) {
|
|
103
|
+
await this.unregister(name);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
getPlugin(name) {
|
|
107
|
+
return this.plugins.get(name);
|
|
108
|
+
}
|
|
109
|
+
getAllPlugins() {
|
|
110
|
+
return Array.from(this.plugins.values());
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
114
|
+
0 && (module.exports = {
|
|
115
|
+
PluginManager
|
|
116
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// src/plugin-manager.ts
|
|
2
|
+
var PluginManager = class {
|
|
3
|
+
constructor(context) {
|
|
4
|
+
this.context = context;
|
|
5
|
+
}
|
|
6
|
+
context;
|
|
7
|
+
plugins = /* @__PURE__ */ new Map();
|
|
8
|
+
register(plugin) {
|
|
9
|
+
const metadata = plugin.getMetadata();
|
|
10
|
+
if (this.plugins.has(metadata.name)) {
|
|
11
|
+
throw new Error(`Plugin '${metadata.name}' is already registered.`);
|
|
12
|
+
}
|
|
13
|
+
this.plugins.set(metadata.name, {
|
|
14
|
+
instance: plugin,
|
|
15
|
+
metadata,
|
|
16
|
+
state: "REGISTERED"
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
async initializeAll() {
|
|
20
|
+
for (const item of this.plugins.values()) {
|
|
21
|
+
try {
|
|
22
|
+
await item.instance.initialize(this.context);
|
|
23
|
+
item.state = "INITIALIZED";
|
|
24
|
+
} catch (err) {
|
|
25
|
+
item.state = "ERROR";
|
|
26
|
+
item.error = err.message || String(err);
|
|
27
|
+
this.context.logger.error(`Failed to initialize plugin '${item.metadata.name}'`, err);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async startAll() {
|
|
32
|
+
for (const item of this.plugins.values()) {
|
|
33
|
+
if (item.state === "INITIALIZED" || item.state === "STOPPED") {
|
|
34
|
+
try {
|
|
35
|
+
await item.instance.start();
|
|
36
|
+
item.state = "STARTED";
|
|
37
|
+
} catch (err) {
|
|
38
|
+
item.state = "ERROR";
|
|
39
|
+
item.error = err.message || String(err);
|
|
40
|
+
this.context.logger.error(`Failed to start plugin '${item.metadata.name}'`, err);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async stopAll() {
|
|
46
|
+
for (const item of this.plugins.values()) {
|
|
47
|
+
if (item.state === "STARTED") {
|
|
48
|
+
try {
|
|
49
|
+
await item.instance.stop();
|
|
50
|
+
item.state = "STOPPED";
|
|
51
|
+
} catch (err) {
|
|
52
|
+
item.state = "ERROR";
|
|
53
|
+
item.error = err.message || String(err);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async unregister(name) {
|
|
59
|
+
const item = this.plugins.get(name);
|
|
60
|
+
if (!item) return;
|
|
61
|
+
if (item.state === "STARTED") {
|
|
62
|
+
try {
|
|
63
|
+
await item.instance.stop();
|
|
64
|
+
} catch (err) {
|
|
65
|
+
this.context.logger.error(`Error stopping plugin '${name}' during unregister:`, err);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
await item.instance.dispose?.();
|
|
70
|
+
} catch (err) {
|
|
71
|
+
this.context.logger.error(`Error disposing plugin '${name}' during unregister:`, err);
|
|
72
|
+
}
|
|
73
|
+
this.plugins.delete(name);
|
|
74
|
+
}
|
|
75
|
+
async disposeAll() {
|
|
76
|
+
for (const name of Array.from(this.plugins.keys())) {
|
|
77
|
+
await this.unregister(name);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
getPlugin(name) {
|
|
81
|
+
return this.plugins.get(name);
|
|
82
|
+
}
|
|
83
|
+
getAllPlugins() {
|
|
84
|
+
return Array.from(this.plugins.values());
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
export {
|
|
88
|
+
PluginManager
|
|
89
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openrfid/plugin-api",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Extensible plugin interface, manifest validator, context provider, and lifecycle manager for OpenRFID Simulator.",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@openrfid/core": "0.1.0",
|
|
20
|
+
"@openrfid/readers": "0.1.0",
|
|
21
|
+
"@openrfid/simulator": "0.1.0",
|
|
22
|
+
"@openrfid/tags": "0.1.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"tsup": "^8.0.2",
|
|
26
|
+
"typescript": "^5.4.5",
|
|
27
|
+
"vitest": "^1.5.0"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "https://github.com/rfidsoftwares/openrfid-simulator.git"
|
|
36
|
+
},
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://github.com/rfidsoftwares/openrfid-simulator/issues"
|
|
39
|
+
},
|
|
40
|
+
"homepage": "https://rfidsoftwares.com",
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
43
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
44
|
+
"test": "vitest run",
|
|
45
|
+
"typecheck": "tsc --noEmit"
|
|
46
|
+
}
|
|
47
|
+
}
|