@contractspec/lib.plugins 0.0.0-canary-20260128200020

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/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # @contractspec/lib.plugins
2
+
3
+ Core plugin API for ContractSpec. Defines plugin interfaces, registry management, and discovery configuration.
4
+
5
+ ## Overview
6
+
7
+ Use this package to build generator, validator, adapter, formatter, and registry resolver plugins. The core types keep plugin behavior consistent while allowing capability-specific logic.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ bun add @contractspec/lib.plugins
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```typescript
18
+ import type { ContractSpecPlugin, PluginContext } from "@contractspec/lib.plugins";
19
+
20
+ export const MarkdownGeneratorPlugin: ContractSpecPlugin = {
21
+ meta: {
22
+ id: "markdown-generator",
23
+ version: "1.0.0",
24
+ type: "generator",
25
+ provides: ["docs"],
26
+ },
27
+ register(context: PluginContext) {
28
+ context.generators.register({
29
+ id: "markdown",
30
+ description: "Generate markdown docs",
31
+ generate: async (specs) => {
32
+ // Implementation
33
+ },
34
+ });
35
+ },
36
+ };
37
+ ```
38
+
39
+ ## Capabilities
40
+
41
+ - **Generators**: Produce code, docs, schemas, or artifacts.
42
+ - **Validators**: Enforce policies and compliance checks.
43
+ - **Adapters**: Integrate frameworks or runtimes.
44
+ - **Formatters**: Post-process generated output.
45
+ - **Registry resolvers**: Resolve plugins from workspace, npm, or remote registries.
46
+
47
+ ## Registry configuration
48
+
49
+ ```json
50
+ {
51
+ "plugins": [
52
+ {
53
+ "id": "markdown-generator",
54
+ "package": "@contractspec/plugin.markdown-generator",
55
+ "capabilities": ["generator"],
56
+ "options": {
57
+ "outputDir": "./docs/generated",
58
+ "format": "table"
59
+ }
60
+ }
61
+ ]
62
+ }
63
+ ```
@@ -0,0 +1,113 @@
1
+ import { AnySchemaModel } from "@contractspec/lib.schema";
2
+
3
+ //#region src/types.d.ts
4
+ type SpecDefinition = unknown;
5
+ type PluginCapabilityType = 'generator' | 'validator' | 'adapter' | 'formatter' | 'registryResolver';
6
+ interface PluginMeta {
7
+ id: string;
8
+ version: string;
9
+ type: PluginCapabilityType;
10
+ provides: string[];
11
+ description?: string;
12
+ compatibility?: string;
13
+ }
14
+ interface PluginContext {
15
+ workspaceRoot: string;
16
+ configPath?: string;
17
+ generators: GeneratorRegistry;
18
+ validators: ValidatorRegistry;
19
+ adapters: AdapterRegistry;
20
+ formatters: FormatterRegistry;
21
+ registryResolvers: RegistryResolverRegistry;
22
+ }
23
+ interface PluginRegistryItem {
24
+ id: string;
25
+ package: string;
26
+ capabilities: PluginCapabilityType[];
27
+ options?: Record<string, unknown>;
28
+ }
29
+ interface PluginRegistryConfig {
30
+ plugins: PluginRegistryItem[];
31
+ registry?: {
32
+ resolutionOrder: ('workspace' | 'npm' | 'remote')[];
33
+ allowPrerelease?: boolean;
34
+ sources?: Record<string, string>;
35
+ };
36
+ }
37
+ interface GeneratorCapability {
38
+ id: string;
39
+ description?: string;
40
+ generate: (specs: SpecDefinition[], context: PluginContext) => Promise<void>;
41
+ }
42
+ interface ValidatorCapability {
43
+ id: string;
44
+ description?: string;
45
+ validate: (specs: SpecDefinition[], context: PluginContext) => Promise<void>;
46
+ }
47
+ interface AdapterCapability {
48
+ id: string;
49
+ description?: string;
50
+ create: (context: PluginContext) => Promise<unknown>;
51
+ }
52
+ interface FormatterCapability {
53
+ id: string;
54
+ description?: string;
55
+ format: (output: string, context: PluginContext) => Promise<string>;
56
+ }
57
+ interface RegistryResolverCapability {
58
+ id: string;
59
+ description?: string;
60
+ resolve: (request: {
61
+ package: string;
62
+ }) => Promise<Record<string, unknown>>;
63
+ }
64
+ interface ContractSpecPlugin {
65
+ meta: PluginMeta;
66
+ register: (context: PluginContext) => void | Promise<void>;
67
+ configure?: (options: Record<string, unknown>, context: PluginContext) => void | Promise<void>;
68
+ validate?: (specs: SpecDefinition[], context: PluginContext) => void | Promise<void>;
69
+ generate?: (specs: SpecDefinition[], context: PluginContext) => void | Promise<void>;
70
+ dispose?: () => void | Promise<void>;
71
+ }
72
+ interface GeneratorRegistry {
73
+ register: (generator: GeneratorCapability) => void;
74
+ list: () => GeneratorCapability[];
75
+ }
76
+ interface ValidatorRegistry {
77
+ register: (validator: ValidatorCapability) => void;
78
+ list: () => ValidatorCapability[];
79
+ }
80
+ interface AdapterRegistry {
81
+ register: (adapter: AdapterCapability) => void;
82
+ list: () => AdapterCapability[];
83
+ }
84
+ interface FormatterRegistry {
85
+ register: (formatter: FormatterCapability) => void;
86
+ list: () => FormatterCapability[];
87
+ }
88
+ interface RegistryResolverRegistry {
89
+ register: (resolver: RegistryResolverCapability) => void;
90
+ list: () => RegistryResolverCapability[];
91
+ }
92
+ interface SpecRegistryEntry {
93
+ id: string;
94
+ spec: SpecDefinition;
95
+ schemas: Record<string, AnySchemaModel>;
96
+ }
97
+ //#endregion
98
+ //#region src/registry.d.ts
99
+ declare class PluginRegistries {
100
+ readonly generators: GeneratorRegistry;
101
+ readonly validators: ValidatorRegistry;
102
+ readonly adapters: AdapterRegistry;
103
+ readonly formatters: FormatterRegistry;
104
+ readonly registryResolvers: RegistryResolverRegistry;
105
+ constructor();
106
+ }
107
+ declare const defaultPluginRegistryConfig: PluginRegistryConfig;
108
+ //#endregion
109
+ //#region src/config.d.ts
110
+ declare function mergePluginConfig(config?: Partial<PluginRegistryConfig>): PluginRegistryConfig;
111
+ //#endregion
112
+ export { type AdapterCapability, type AdapterRegistry, type ContractSpecPlugin, type FormatterCapability, type FormatterRegistry, type GeneratorCapability, type GeneratorRegistry, type PluginCapabilityType, type PluginContext, type PluginMeta, PluginRegistries, type PluginRegistryConfig, type PluginRegistryItem, type RegistryResolverCapability, type RegistryResolverRegistry, type SpecRegistryEntry, type ValidatorCapability, type ValidatorRegistry, defaultPluginRegistryConfig, mergePluginConfig };
113
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],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A;;QAET;WACG,eAAe;;;;cChGb,gBAAA;uBACU;EDzBX,SAAA,UAAc,EC0BH,iBD1BG;EAEd,SAAA,QAAA,ECyBS,eDzBW;EAOf,SAAA,UAAU,ECmBJ,iBDhBf;EAMS,SAAA,iBAAa,ECWA,wBDXA;EAGhB,WAAA,CAAA;;AAEF,cCiBC,2BDjBD,ECiB8B,oBDjB9B;;;iBEtBI,iBAAA,UACL,QAAQ,wBAChB"}
package/dist/index.mjs ADDED
@@ -0,0 +1,66 @@
1
+ //#region src/registry.ts
2
+ var SimpleRegistry = class {
3
+ entries = /* @__PURE__ */ new Map();
4
+ register(entry) {
5
+ this.entries.set(entry.id, entry);
6
+ }
7
+ list() {
8
+ return Array.from(this.entries.values());
9
+ }
10
+ };
11
+ var PluginRegistries = class {
12
+ generators;
13
+ validators;
14
+ adapters;
15
+ formatters;
16
+ registryResolvers;
17
+ constructor() {
18
+ this.generators = new SimpleRegistry();
19
+ this.validators = new SimpleRegistry();
20
+ this.adapters = new SimpleRegistry();
21
+ this.formatters = new SimpleRegistry();
22
+ this.registryResolvers = new SimpleRegistry();
23
+ }
24
+ };
25
+ const defaultPluginRegistryConfig = {
26
+ plugins: [],
27
+ registry: {
28
+ resolutionOrder: [
29
+ "workspace",
30
+ "npm",
31
+ "remote"
32
+ ],
33
+ allowPrerelease: false,
34
+ sources: {}
35
+ }
36
+ };
37
+
38
+ //#endregion
39
+ //#region src/config.ts
40
+ function mergePluginConfig(config) {
41
+ return {
42
+ ...defaultPluginRegistryConfig,
43
+ ...config,
44
+ registry: {
45
+ ...defaultPluginRegistryConfig.registry ?? { resolutionOrder: [
46
+ "workspace",
47
+ "npm",
48
+ "remote"
49
+ ] },
50
+ ...config?.registry,
51
+ resolutionOrder: config?.registry?.resolutionOrder ?? defaultPluginRegistryConfig.registry?.resolutionOrder ?? [
52
+ "workspace",
53
+ "npm",
54
+ "remote"
55
+ ],
56
+ sources: {
57
+ ...defaultPluginRegistryConfig.registry?.sources ?? {},
58
+ ...config?.registry?.sources ?? {}
59
+ }
60
+ }
61
+ };
62
+ }
63
+
64
+ //#endregion
65
+ export { PluginRegistries, defaultPluginRegistryConfig, mergePluginConfig };
66
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/registry.ts","../src/config.ts"],"sourcesContent":["import type {\n AdapterCapability,\n AdapterRegistry,\n FormatterCapability,\n FormatterRegistry,\n GeneratorCapability,\n GeneratorRegistry,\n PluginRegistryConfig,\n RegistryResolverCapability,\n RegistryResolverRegistry,\n ValidatorCapability,\n ValidatorRegistry,\n} from './types.js';\n\nclass SimpleRegistry<T extends { id: string }> {\n private readonly entries = new Map<string, T>();\n\n register(entry: T): void {\n this.entries.set(entry.id, entry);\n }\n\n list(): T[] {\n return Array.from(this.entries.values());\n }\n}\n\nexport class PluginRegistries {\n readonly generators: GeneratorRegistry;\n readonly validators: ValidatorRegistry;\n readonly adapters: AdapterRegistry;\n readonly formatters: FormatterRegistry;\n readonly registryResolvers: RegistryResolverRegistry;\n\n constructor() {\n this.generators = new SimpleRegistry<GeneratorCapability>();\n this.validators = new SimpleRegistry<ValidatorCapability>();\n this.adapters = new SimpleRegistry<AdapterCapability>();\n this.formatters = new SimpleRegistry<FormatterCapability>();\n this.registryResolvers = new SimpleRegistry<RegistryResolverCapability>();\n }\n}\n\nexport const defaultPluginRegistryConfig: PluginRegistryConfig = {\n plugins: [],\n registry: {\n resolutionOrder: ['workspace', 'npm', 'remote'],\n allowPrerelease: false,\n sources: {},\n },\n};\n","import type { PluginRegistryConfig } from './types.js';\nimport { defaultPluginRegistryConfig } from './registry.js';\n\nexport function mergePluginConfig(\n config?: Partial<PluginRegistryConfig>\n): PluginRegistryConfig {\n return {\n ...defaultPluginRegistryConfig,\n ...config,\n registry: {\n ...(defaultPluginRegistryConfig.registry ?? {\n resolutionOrder: ['workspace', 'npm', 'remote'],\n }),\n ...config?.registry,\n resolutionOrder: config?.registry?.resolutionOrder ??\n defaultPluginRegistryConfig.registry?.resolutionOrder ?? [\n 'workspace',\n 'npm',\n 'remote',\n ],\n sources: {\n ...(defaultPluginRegistryConfig.registry?.sources ?? {}),\n ...(config?.registry?.sources ?? {}),\n },\n },\n };\n}\n"],"mappings":";AAcA,IAAM,iBAAN,MAA+C;CAC7C,AAAiB,0BAAU,IAAI,KAAgB;CAE/C,SAAS,OAAgB;AACvB,OAAK,QAAQ,IAAI,MAAM,IAAI,MAAM;;CAGnC,OAAY;AACV,SAAO,MAAM,KAAK,KAAK,QAAQ,QAAQ,CAAC;;;AAI5C,IAAa,mBAAb,MAA8B;CAC5B,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CAET,cAAc;AACZ,OAAK,aAAa,IAAI,gBAAqC;AAC3D,OAAK,aAAa,IAAI,gBAAqC;AAC3D,OAAK,WAAW,IAAI,gBAAmC;AACvD,OAAK,aAAa,IAAI,gBAAqC;AAC3D,OAAK,oBAAoB,IAAI,gBAA4C;;;AAI7E,MAAa,8BAAoD;CAC/D,SAAS,EAAE;CACX,UAAU;EACR,iBAAiB;GAAC;GAAa;GAAO;GAAS;EAC/C,iBAAiB;EACjB,SAAS,EAAE;EACZ;CACF;;;;AC9CD,SAAgB,kBACd,QACsB;AACtB,QAAO;EACL,GAAG;EACH,GAAG;EACH,UAAU;GACR,GAAI,4BAA4B,YAAY,EAC1C,iBAAiB;IAAC;IAAa;IAAO;IAAS,EAChD;GACD,GAAG,QAAQ;GACX,iBAAiB,QAAQ,UAAU,mBACjC,4BAA4B,UAAU,mBAAmB;IACvD;IACA;IACA;IACD;GACH,SAAS;IACP,GAAI,4BAA4B,UAAU,WAAW,EAAE;IACvD,GAAI,QAAQ,UAAU,WAAW,EAAE;IACpC;GACF;EACF"}
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@contractspec/lib.plugins",
3
+ "version": "0.0.0-canary-20260128200020",
4
+ "description": "Plugin API and registry for ContractSpec extensions",
5
+ "keywords": [
6
+ "contractspec",
7
+ "plugins",
8
+ "extensions",
9
+ "generator",
10
+ "validator",
11
+ "adapter",
12
+ "registry",
13
+ "typescript"
14
+ ],
15
+ "type": "module",
16
+ "types": "./dist/index.d.ts",
17
+ "scripts": {
18
+ "publish:pkg": "bun publish --tolerate-republish --ignore-scripts --verbose",
19
+ "publish:pkg:canary": "bun publish:pkg --tag canary",
20
+ "build": "bun build:types && bun build:bundle",
21
+ "build:bundle": "tsdown",
22
+ "build:types": "tsc -p tsconfig.json",
23
+ "dev": "bun build:bundle --watch",
24
+ "clean": "rimraf dist .turbo",
25
+ "lint": "bun lint:fix",
26
+ "lint:fix": "eslint src --fix",
27
+ "lint:check": "eslint src",
28
+ "test": "bun test"
29
+ },
30
+ "dependencies": {
31
+ "@contractspec/lib.contracts": "0.0.0-canary-20260128200020",
32
+ "@contractspec/lib.schema": "1.52.0",
33
+ "zod": "^4.3.5"
34
+ },
35
+ "devDependencies": {
36
+ "@contractspec/tool.tsdown": "1.52.0",
37
+ "@contractspec/tool.typescript": "1.52.0",
38
+ "typescript": "^5.9.3"
39
+ },
40
+ "exports": {
41
+ ".": "./dist/index.mjs",
42
+ "./registry": "./dist/registry.mjs",
43
+ "./types": "./dist/types.mjs",
44
+ "./config": "./dist/config.mjs",
45
+ "./*": "./*"
46
+ },
47
+ "files": [
48
+ "dist",
49
+ "README.md"
50
+ ],
51
+ "publishConfig": {
52
+ "access": "public",
53
+ "registry": "https://registry.npmjs.org/"
54
+ },
55
+ "license": "MIT",
56
+ "repository": {
57
+ "type": "git",
58
+ "url": "https://github.com/lssm-tech/contractspec.git",
59
+ "directory": "packages/libs/plugins"
60
+ },
61
+ "homepage": "https://contractspec.io"
62
+ }