plugistry 0.0.1
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 +21 -0
- package/README.md +77 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +58 -0
- package/package.json +35 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 plugistry contributors
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# plugistry
|
|
2
|
+
|
|
3
|
+
Type-safe plugin composition primitives for TypeScript.
|
|
4
|
+
|
|
5
|
+
This is intentionally small: it provides the base pieces for building a typed plugin/composition layer without tying the package to any application domain.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install plugistry
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Example
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import {
|
|
17
|
+
createPlatform,
|
|
18
|
+
definePlugin,
|
|
19
|
+
definePort,
|
|
20
|
+
} from 'plugistry';
|
|
21
|
+
|
|
22
|
+
interface DocumentRepository {
|
|
23
|
+
get(id: string): Promise<{ id: string; title: string } | null>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const DocumentRepositoryPort =
|
|
27
|
+
definePort<DocumentRepository>('example/DocumentRepository');
|
|
28
|
+
|
|
29
|
+
const documentMemoryPlugin = definePlugin({
|
|
30
|
+
name: 'document-memory',
|
|
31
|
+
|
|
32
|
+
register(ctx) {
|
|
33
|
+
ctx.provide(DocumentRepositoryPort, {
|
|
34
|
+
async get(id) {
|
|
35
|
+
return { id, title: 'Example' };
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const platform = createPlatform()
|
|
42
|
+
.use(documentMemoryPlugin)
|
|
43
|
+
.build();
|
|
44
|
+
|
|
45
|
+
const documents = platform.resolve(DocumentRepositoryPort);
|
|
46
|
+
const document = await documents.get('doc-1');
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Included primitives
|
|
50
|
+
|
|
51
|
+
- `createPlatform()`
|
|
52
|
+
- `definePlugin()`
|
|
53
|
+
- `definePort<T>()`
|
|
54
|
+
- `defineConcept<T>()`
|
|
55
|
+
- type-level plugin contribution accumulation
|
|
56
|
+
- runtime provider registration and resolution
|
|
57
|
+
- duplicate/missing provider validation
|
|
58
|
+
|
|
59
|
+
## Publish
|
|
60
|
+
|
|
61
|
+
Before publishing, verify the package name is still available:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
npm view plugistry
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Then:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
npm login
|
|
71
|
+
npm pack --dry-run
|
|
72
|
+
npm publish
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Status
|
|
76
|
+
|
|
77
|
+
`0.0.1` is a minimal bootstrap release. The intended next step is a typed concept registry with plugin-driven registry transformations, scoped providers, decorators, contributors, and validation.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export interface Port<T> {
|
|
2
|
+
readonly key: symbol;
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly __type?: T;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export declare function definePort<T>(name: string): Port<T>;
|
|
8
|
+
|
|
9
|
+
export interface Concept<T> {
|
|
10
|
+
readonly __type?: T;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export declare function defineConcept<T>(): Concept<T>;
|
|
14
|
+
|
|
15
|
+
export interface Plugin<Contribution extends object = {}> {
|
|
16
|
+
readonly name: string;
|
|
17
|
+
readonly contribution?: Contribution;
|
|
18
|
+
register?(context: PluginContext): void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface PluginContext {
|
|
22
|
+
provide<T>(port: Port<T>, value: T): void;
|
|
23
|
+
resolve<T>(port: Port<T>): T;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export declare function definePlugin<const C extends object>(
|
|
27
|
+
plugin: Plugin<C>,
|
|
28
|
+
): Plugin<C>;
|
|
29
|
+
|
|
30
|
+
type ContributionOf<P> =
|
|
31
|
+
P extends Plugin<infer C> ? C : {};
|
|
32
|
+
|
|
33
|
+
export type Merge<A, B> = A & B;
|
|
34
|
+
|
|
35
|
+
export interface Platform<C extends object> {
|
|
36
|
+
readonly capabilities: C;
|
|
37
|
+
resolve<T>(port: Port<T>): T;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface PlatformBuilder<C extends object = {}> {
|
|
41
|
+
use<P extends Plugin<any>>(
|
|
42
|
+
plugin: P,
|
|
43
|
+
): PlatformBuilder<Merge<C, ContributionOf<P>>>;
|
|
44
|
+
|
|
45
|
+
build(): Platform<C>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export declare function createPlatform(): PlatformBuilder<{}>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export function definePort(name) {
|
|
2
|
+
return {
|
|
3
|
+
key: Symbol.for(name),
|
|
4
|
+
name,
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function defineConcept() {
|
|
9
|
+
return {};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function definePlugin(plugin) {
|
|
13
|
+
return plugin;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function createPlatform() {
|
|
17
|
+
const plugins = [];
|
|
18
|
+
|
|
19
|
+
const builder = {
|
|
20
|
+
use(plugin) {
|
|
21
|
+
plugins.push(plugin);
|
|
22
|
+
return builder;
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
build() {
|
|
26
|
+
const providers = new Map();
|
|
27
|
+
|
|
28
|
+
const context = {
|
|
29
|
+
provide(port, value) {
|
|
30
|
+
if (providers.has(port.key)) {
|
|
31
|
+
throw new Error(`Provider already registered: ${port.name}`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
providers.set(port.key, value);
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
resolve(port) {
|
|
38
|
+
if (!providers.has(port.key)) {
|
|
39
|
+
throw new Error(`Missing provider: ${port.name}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return providers.get(port.key);
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
for (const plugin of plugins) {
|
|
47
|
+
plugin.register?.(context);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
capabilities: {},
|
|
52
|
+
resolve: context.resolve,
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
return builder;
|
|
58
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "plugistry",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Type-safe plugin composition primitives for TypeScript.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"test": "node ./test.mjs",
|
|
22
|
+
"pack:dry": "npm pack --dry-run"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"typescript",
|
|
26
|
+
"plugin",
|
|
27
|
+
"composition",
|
|
28
|
+
"dependency-injection",
|
|
29
|
+
"architecture"
|
|
30
|
+
],
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=20"
|
|
34
|
+
}
|
|
35
|
+
}
|