@abapify/adt-plugin 0.4.34 → 0.4.36

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 CHANGED
@@ -1,151 +1,42 @@
1
1
  # @abapify/adt-plugin
2
2
 
3
- [![version](https://img.shields.io/github/package-json/v/abapify/adt-cli?filename=packages/adt-plugin/package.json)](https://github.com/abapify/adt-cli/pkgs/npm/%40abapify%2Fadt-plugin)
3
+ [![npm](https://img.shields.io/npm/v/%40abapify%2Fadt-plugin)](https://www.npmjs.com/package/@abapify/adt-plugin)
4
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/abapify/adt-cli/blob/main/LICENSE)
4
5
 
5
- Core plugin interface for ADT format serialization.
6
+ ADT Plugin interface and factory for abapify.
6
7
 
7
- ## Overview
8
-
9
- This package defines the **plugin contract** for serializing ADK objects to various formats (abapGit, etc.). Plugins implement this interface to provide format-specific serialization.
10
-
11
- **Key principle:** Plugins only handle serialization format. They receive ADK objects and produce files - no ADT client logic.
12
-
13
- ## Installation
8
+ ## Install
14
9
 
15
10
  ```bash
16
- bun add @abapify/adt-plugin
11
+ npm install @abapify/adt-plugin
17
12
  ```
18
13
 
19
14
  ## Usage
20
15
 
21
- ### Creating a Plugin
22
-
23
- ```typescript
24
- import { createPlugin, type AdtPlugin } from '@abapify/adt-plugin';
16
+ ```ts
17
+ import { createPlugin } from '@abapify/adt-plugin';
25
18
 
26
19
  export const myPlugin = createPlugin({
27
20
  name: 'myFormat',
28
21
  version: '1.0.0',
29
- description: 'My custom format plugin',
30
-
31
- // Registry service - what object types are supported
32
22
  registry: {
33
23
  isSupported: (type) => ['CLAS', 'INTF'].includes(type),
34
24
  getSupportedTypes: () => ['CLAS', 'INTF'],
35
25
  },
36
-
37
- // Format service - import/export operations
38
- format: {
39
- // Import: ADK object → file system
40
- import: async (object, targetPath, context) => {
41
- // Serialize object to files
42
- return {
43
- success: true,
44
- filesCreated: ['myclass.clas.xml'],
45
- };
46
- },
47
-
48
- // Export: file system → ADK object (optional)
49
- export: async (sourcePath, type, name) => {
50
- // Deserialize files to ADK object
51
- return {
52
- success: true,
53
- object: myAdkObject,
54
- };
55
- },
56
- },
57
-
58
- // Lifecycle hooks (optional)
59
- hooks: {
60
- afterImport: async (targetPath) => {
61
- // Generate metadata files, etc.
62
- },
63
- },
26
+ // ... serialization services
64
27
  });
65
28
  ```
66
29
 
67
- ### Using a Plugin
68
-
69
- ```typescript
70
- import { abapGitPlugin } from '@abapify/adt-plugin-abapgit';
71
-
72
- // Check if type is supported
73
- if (abapGitPlugin.registry.isSupported('CLAS')) {
74
- // Import object to file system
75
- const result = await abapGitPlugin.format.import(myClassObject, './output', {
76
- packagePath: ['ZROOT', 'ZSUB'],
77
- });
78
-
79
- if (result.success) {
80
- console.log('Files created:', result.filesCreated);
81
- }
82
- }
83
-
84
- // Get all supported types
85
- const types = abapGitPlugin.registry.getSupportedTypes();
86
- // → ['CLAS', 'INTF', 'DOMA', 'DEVC', 'DTEL']
87
- ```
30
+ ## Features
88
31
 
89
- ## API
32
+ - Interface and factory for abapify format plugins
33
+ - Registry of supported object types
34
+ - Shared contract for abapGit, gCTS, and custom formats
90
35
 
91
- ### Pure tree materialization
36
+ ## Documentation
92
37
 
93
- Flow-style consumers need to calculate repository changes before touching the
94
- filesystem. A `FormatPlugin` exposes the optional pure materialization
95
- capability. Obtain one through `requireFormatPlugin` (not `createPlugin`, which
96
- returns an `AdtPlugin`):
97
-
98
- ```typescript
99
- import { requireFormatPlugin } from '@abapify/adt-plugin';
100
-
101
- const formatPlugin = requireFormatPlugin('abapGit');
102
- const result = await formatPlugin.materialize?.({
103
- object: adkObject,
104
- objectType: 'CLAS',
105
- packagePath: ['ZROOT', 'ZROOT_FEATURE'],
106
- sources: {
107
- main: historicalMainSource,
108
- definitions: historicalLocalDefinitions,
109
- },
110
- formatOptions: { folderLogic: 'prefix' },
111
- });
112
- ```
113
-
114
- When `sources` is present it is authoritative. A handler emits only those
115
- components and must not read mutable source through the ADK object. The result
116
- contains deterministic repository-relative files with `source` or `metadata`
117
- roles; the caller owns validation and filesystem reconciliation.
118
-
119
- ### `createPlugin(definition)`
120
-
121
- Factory function to create a validated plugin instance.
122
-
123
- ### `AdtPlugin` Interface
124
-
125
- ```typescript
126
- interface AdtPlugin {
127
- readonly name: string;
128
- readonly version: string;
129
- readonly description: string;
130
-
131
- readonly registry: {
132
- isSupported(type: AbapObjectType): boolean;
133
- getSupportedTypes(): AbapObjectType[];
134
- };
135
-
136
- readonly format: {
137
- import(object, targetPath, context): Promise<ImportResult>;
138
- export?(sourcePath, type, name): Promise<ExportResult>;
139
- };
140
-
141
- readonly hooks?: {
142
- afterImport?(targetPath: string): Promise<void>;
143
- beforeExport?(sourcePath: string): Promise<void>;
144
- };
145
- }
146
- ```
38
+ **[adt-cli.netlify.app/sdk/packages/adt-plugin](https://adt-cli.netlify.app/sdk/packages/adt-plugin)**
147
39
 
148
- ## Terminology
40
+ ---
149
41
 
150
- - **Import** (to Git): ADK object → serialized files (SAP → file system)
151
- - **Export** (from Git): serialized files → ADK object (file system → SAP)
42
+ Part of [**abapify**](https://github.com/abapify/adt-cli) — open, typed tooling for SAP ABAP Development Tools (ADT): CLI, MCP server, and SDK.
package/dist/index.d.mts CHANGED
@@ -1,8 +1,4 @@
1
1
  import { AdkObject } from "@abapify/adk";
2
- /**
3
- * ABAP object type code (e.g., 'CLAS', 'INTF', 'DOMA')
4
- */
5
- type AbapObjectType = string;
6
2
  /**
7
3
  * Primitive value accepted for format/plugin options.
8
4
  */
@@ -137,11 +133,11 @@ interface AdtPlugin {
137
133
  /**
138
134
  * Check if object type is supported by this plugin
139
135
  */
140
- isSupported(type: AbapObjectType): boolean;
136
+ isSupported(type: string): boolean;
141
137
  /**
142
138
  * Get all supported object types
143
139
  */
144
- getSupportedTypes(): AbapObjectType[];
140
+ getSupportedTypes(): string[];
145
141
  };
146
142
  /** Format service - import/export operations */
147
143
  readonly format: {
@@ -600,5 +596,5 @@ declare function unregisterFormatPlugin(id: string): boolean;
600
596
  * Intended for tests only.
601
597
  */
602
598
  declare function clearFormatRegistry(): void;
603
- export { type AbapGitOutputFormat, type AbapObjectType, type AdtCliConfig, type AdtPlugin, type AdtPluginDefinition, type CliArgument, type CliCommandModule, type CliCommandPlugin, type CliContext, type CliLogger, type CliOption, type DeleteResult, type ExportContext, type ExportOptions, type ExportResult, type FileTree, type FormatHandler, type FormatHandlerSchema, FormatMaterializationError, type FormatMaterializationErrorCode, type FormatMaterializationInput, type FormatMaterializationResult, type FormatOptionValue, type FormatPlugin, type FormatSerializeOptions, type ImportContext, type ImportResult, type MaterializedFormatFile, type ParsedFormatFilename, type SerializedFile, clearFormatRegistry, createPlugin, getFormatPlugin, listFormatPlugins, registerFormatPlugin, requireFormatPlugin, unregisterFormatPlugin };
599
+ export { type AbapGitOutputFormat, type AdtCliConfig, type AdtPlugin, type AdtPluginDefinition, type CliArgument, type CliCommandModule, type CliCommandPlugin, type CliContext, type CliLogger, type CliOption, type DeleteResult, type ExportContext, type ExportOptions, type ExportResult, type FileTree, type FormatHandler, type FormatHandlerSchema, FormatMaterializationError, type FormatMaterializationErrorCode, type FormatMaterializationInput, type FormatMaterializationResult, type FormatOptionValue, type FormatPlugin, type FormatSerializeOptions, type ImportContext, type ImportResult, type MaterializedFormatFile, type ParsedFormatFilename, type SerializedFile, clearFormatRegistry, createPlugin, getFormatPlugin, listFormatPlugins, registerFormatPlugin, requireFormatPlugin, unregisterFormatPlugin };
604
600
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/cli-types.ts","../src/factory.ts","../src/lib/format/format-plugin.ts","../src/lib/format/format-registry.ts"],"mappings":";;;;KAeY;;;;KAIA;;;;;;;UAYK;;;;;;;;EAQf,mBAAmB,sBAAsB;;;;;EAMzC,gBAAgB,SAAS,eAAe;;;;;EAMxC,sBAAsB,SAAS,eAAe;;;;;UA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;;;;;;;;;;;;;;iBClKa,aAAa,YAAY,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;UCT9C;;EAEf;;EAEA;;EAEA,WAAW;;;KAID;;UAGK;;;;;;;EAOf,UAAU,SAAS;;;;;;EAMnB,SAAS;;UAGD,qCAAqC;EAC7C;;EAEA;;UAGQ,uCAAuC;EAC/C;;;KAIU,yBACV,+BAA+B;UAEhB;EACf;EACA;EACA;EACA,UAAU,SAAS;EACnB,gBAAgB,SAAS,eAAe;;UAGzB;EACf,OAAO;;KAGG;cAKC,mCAAmC;WAInC,MAAM;WAHC;EAGP,YAAA,MAAM,gCACf;;;;;;;;;UAaa;;EAEf;;EAEA;;EAEA;;EAEA;;;;;;;;;UAUe;EACf,MAAM;EACN,MAAM,eAAe;IAAY;;;;;;;;;;UAUlB;;WAEN;;WAEA;;WAEA,QAAQ;;WAER,oBAAoB;;WAEpB;;EAET,UACE,iBACA,UAAU,yBACT,QAAQ;;;;;EAKX,aAAa;IAAoB;MAAiB;;EAElD,YAAY,iBAAiB,SAAS;;;;;UAMvB;;WAEN;;WAEA;;WAEA,gBAAgB;;EAEzB,WAAW,eAAe;;;;;EAK1B,aACE,OAAO,6BACN,QAAQ;;EAEX,eAAe,mBAAmB;;;;;;;;;;iBC9IpB,qBAAqB,QAAQ;;;;iBAe7B,gBAAgB,aAAa;;;;;;iBAS7B,oBAAoB,aAAa;;;;iBAmBjC,qBAAqB;;;;;;iBASrB,uBAAuB;;;;;;iBASvB"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/cli-types.ts","../src/factory.ts","../src/lib/format/format-plugin.ts","../src/lib/format/format-registry.ts"],"mappings":";;;;KAeY;;;;;;;UAYK;;;;;;;;EAQf,mBAAmB,sBAAsB;;;;;EAMzC,gBAAgB,SAAS,eAAe;;;;;EAMxC,sBAAsB,SAAS,eAAe;;;;;UAM/B;EACf;EACA;EACA;;;;;UAMe;EACf;;EAEA;EACA;;;;;;;;UAae;;WAE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9C;;EAEf;;EAEA;;EAEA,WAAW;;;KAID;;UAGK;;;;;;;EAOf,UAAU,SAAS;;;;;;EAMnB,SAAS;;UAGD,qCAAqC;EAC7C;;EAEA;;UAGQ,uCAAuC;EAC/C;;;KAIU,yBACV,+BAA+B;UAEhB;EACf;EACA;EACA;EACA,UAAU,SAAS;EACnB,gBAAgB,SAAS,eAAe;;UAGzB;EACf,OAAO;;KAGG;cAKC,mCAAmC;WAInC,MAAM;WAHC;EAGP,YAAA,MAAM,gCACf;;;;;;;;;UAaa;;EAEf;;EAEA;;EAEA;;EAEA;;;;;;;;;UAUe;EACf,MAAM;EACN,MAAM,eAAe;IAAY;;;;;;;;;;UAUlB;;WAEN;;WAEA;;WAEA,QAAQ;;WAER,oBAAoB;;WAEpB;;EAET,UACE,iBACA,UAAU,yBACT,QAAQ;;;;;EAKX,aAAa;IAAoB;MAAiB;;EAElD,YAAY,iBAAiB,SAAS;;;;;UAMvB;;WAEN;;WAEA;;WAEA,gBAAgB;;EAEzB,WAAW,eAAe;;;;;EAK1B,aACE,OAAO,6BACN,QAAQ;;EAEX,eAAe,mBAAmB;;;;;;;;;;iBC9IpB,qBAAqB,QAAQ;;;;iBAe7B,gBAAgB,aAAa;;;;;;iBAS7B,oBAAoB,aAAa;;;;iBAmBjC,qBAAqB;;;;;;iBASrB,uBAAuB;;;;;;iBASvB"}
package/dist/index.mjs CHANGED
@@ -33,7 +33,7 @@ function createPlugin(definition) {
33
33
  if (!definition.version) throw new Error("Plugin version is required");
34
34
  if (!definition.registry) throw new Error("Plugin registry is required");
35
35
  if (!definition.format) throw new Error("Plugin format is required");
36
- if (typeof definition.format.import !== "function") throw new Error("Plugin format.import must be a function");
36
+ if (typeof definition.format.import !== "function") throw new TypeError("Plugin format.import must be a function");
37
37
  return definition;
38
38
  }
39
39
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/factory.ts","../src/lib/format/format-plugin.ts","../src/lib/format/format-registry.ts"],"sourcesContent":["/**\n * ADT Plugin Factory\n *\n * Factory function for creating ADT plugins with validation.\n */\n\nimport type { AdtPlugin, AdtPluginDefinition } from './types';\n\n/**\n * Create an ADT plugin with validation\n *\n * @param definition - Plugin definition\n * @returns Validated plugin instance\n *\n * @example\n * ```typescript\n * import { createPlugin } from '@abapify/adt-plugin';\n *\n * export const myPlugin = createPlugin({\n * name: 'myFormat',\n * version: '1.0.0',\n * description: 'My custom format plugin',\n *\n * registry: {\n * isSupported: (type) => supportedTypes.includes(type),\n * getSupportedTypes: () => supportedTypes,\n * },\n *\n * format: {\n * import: async (object, targetPath, context) => {\n * // Implementation\n * return { success: true, filesCreated: [] };\n * },\n * },\n * });\n * ```\n */\nexport function createPlugin(definition: AdtPluginDefinition): AdtPlugin {\n // Validate required fields\n if (!definition.name) {\n throw new Error('Plugin name is required');\n }\n if (!definition.version) {\n throw new Error('Plugin version is required');\n }\n if (!definition.registry) {\n throw new Error('Plugin registry is required');\n }\n if (!definition.format) {\n throw new Error('Plugin format is required');\n }\n if (typeof definition.format.import !== 'function') {\n throw new Error('Plugin format.import must be a function');\n }\n\n // Return validated plugin\n return definition;\n}\n","import type { FormatOptionValue } from '../../types';\n\n/**\n * FormatPlugin — interface for serialization-format plugins (abapGit, gCTS, AFF, …).\n *\n * A format plugin owns:\n * - a stable CLI id (used with `--format <id>`)\n * - the set of ABAP object types it can serialize\n * - a `getHandler(type)` accessor returning a `FormatHandler` for a specific\n * ABAP object type (the handler knows how to turn an ADK object into files\n * and vice versa)\n * - an optional `parseFilename(name)` helper (format-specific naming\n * convention — e.g. `zcl_foo.clas.xml` for abapGit)\n *\n * Format plugins are registered through the `format-registry` module. Packages\n * that implement a format (such as `@abapify/adt-plugin-abapgit`) call\n * `registerFormatPlugin(...)` as a side-effect of being imported, so pulling in\n * the package is enough to make `--format <id>` work. Consumers (export, diff,\n * import, checkout) MUST look plugins up through `getFormatPlugin(id)` — they\n * must NOT import format packages directly.\n */\n\n/**\n * Serialized output file produced by a handler.\n *\n * Identical shape to the pre-existing `SerializedFile` in\n * `@abapify/adt-plugin-abapgit` so migration is a pure rename.\n */\nexport interface SerializedFile {\n /** Relative path from the object directory (e.g. `zcl_foo.clas.xml`). */\n path: string;\n /** File contents. */\n content: string;\n /** Optional encoding (default: utf-8). */\n encoding?: BufferEncoding;\n}\n\n/** Output format for object types that support both legacy abapGit XML and AFF JSON. */\nexport type AbapGitOutputFormat = 'aff' | 'legacy';\n\n/** Source contents selected independently from mutable object getters. */\nexport interface FormatSerializeOptions {\n /**\n * Source component id to content.\n *\n * When present, this record is authoritative: handlers MUST NOT read source\n * through the object model and MUST emit only the supplied components.\n */\n sources?: Readonly<Record<string, string>>;\n /**\n * Output format for object types that support both legacy abapGit XML and\n * ABAP File Format (AFF) JSON. When omitted, the handler's default format\n * is used (AFF for CDS/RAP types, legacy XML for DDIC/code types).\n */\n format?: AbapGitOutputFormat;\n}\n\ninterface MaterializedFormatSourceFile extends SerializedFile {\n role: 'source';\n /** Source-history component id for source files. */\n sourceComponent: string;\n}\n\ninterface MaterializedFormatMetadataFile extends SerializedFile {\n role: 'metadata';\n}\n\n/** A repository-relative file produced without filesystem mutation. */\nexport type MaterializedFormatFile =\n MaterializedFormatSourceFile | MaterializedFormatMetadataFile;\n\nexport interface FormatMaterializationInput {\n object: unknown;\n objectType: string;\n packagePath: readonly string[];\n sources?: Readonly<Record<string, string>>;\n formatOptions?: Readonly<Record<string, FormatOptionValue>>;\n}\n\nexport interface FormatMaterializationResult {\n files: MaterializedFormatFile[];\n}\n\nexport type FormatMaterializationErrorCode =\n | 'FORMAT_MATERIALIZATION_UNSUPPORTED'\n | 'FORMAT_OBJECT_TYPE_UNSUPPORTED'\n | 'FORMAT_SOURCE_COMPONENT_UNSUPPORTED';\n\nexport class FormatMaterializationError extends Error {\n override readonly name = 'FormatMaterializationError';\n\n constructor(\n readonly code: FormatMaterializationErrorCode,\n message: string,\n ) {\n super(message);\n }\n}\n\n/**\n * Result of parsing a format-specific filename.\n *\n * Different formats use different naming conventions; this is the minimum\n * info any consumer needs (the object name, the SAP object type and the file\n * extension).\n */\nexport interface ParsedFormatFilename {\n /** SAP object name (e.g. `ZCL_FOO`). */\n name: string;\n /** SAP object type code (e.g. `CLAS`, `INTF`). */\n type: string;\n /** Optional per-file suffix (e.g. `testclasses` for a CLAS sub-include). */\n suffix?: string;\n /** File extension without the dot (e.g. `xml`, `abap`). */\n extension: string;\n}\n\n/**\n * Minimal schema surface used by format consumers.\n *\n * Both `parse` and `build` intentionally use `unknown` to avoid coupling\n * `@abapify/adt-plugin` to any particular XML schema library (ts-xsd, speci,\n * …). Concrete handlers may narrow this with a typed schema internally.\n */\nexport interface FormatHandlerSchema {\n parse(xml: string): unknown;\n build(data: unknown, options?: { pretty?: boolean }): string;\n}\n\n/**\n * Handler for a single ABAP object type within a format.\n *\n * Kept intentionally abstract — the concrete handler implementation in e.g.\n * `adt-plugin-abapgit` is a structural superset of this interface, so there\n * is no need to convert between them.\n */\nexport interface FormatHandler {\n /** ABAP object type code (e.g. `CLAS`). */\n readonly type: string;\n /** File extension associated with the object type (e.g. `clas`). */\n readonly fileExtension: string;\n /** Schema for parsing/building the handler's XML representation. */\n readonly schema: FormatHandlerSchema;\n /** Optional map from abapGit file suffix to source key. */\n readonly suffixToSourceKey?: Record<string, string>;\n /** Whether this handler treats an explicit `sources` map as authoritative. */\n readonly supportsExplicitSources?: boolean;\n /** Serialize an ADK object to one or more files. */\n serialize(\n object: unknown,\n options?: FormatSerializeOptions,\n ): Promise<SerializedFile[]>;\n /**\n * Map format-specific XML values back to ADK data. Present only on\n * handlers that support bidirectional (git → SAP) workflows.\n */\n fromAbapGit?(values: unknown): { name: string } & Record<string, unknown>;\n /** Set resolved source files on an ADK object during deserialization. */\n setSources?(object: unknown, sources: Record<string, string>): void;\n}\n\n/**\n * A serialization-format plugin.\n */\nexport interface FormatPlugin {\n /** Stable id used on the CLI (`--format <id>`). */\n readonly id: string;\n /** Human-readable description shown in help output. */\n readonly description: string;\n /** SAP object types this plugin can serialize (snapshot — may be computed). */\n readonly supportedTypes: ReadonlyArray<string>;\n /** Look up the handler for a given ABAP object type. */\n getHandler(type: string): FormatHandler | undefined;\n /**\n * Produce the desired repository files for one object without ADT,\n * filesystem, or Git side effects.\n */\n materialize?(\n input: FormatMaterializationInput,\n ): Promise<FormatMaterializationResult>;\n /** Parse a format-specific filename, if the format defines one. */\n parseFilename?(filename: string): ParsedFormatFilename | undefined;\n}\n","/**\n * Global format-plugin registry.\n *\n * Format plugins self-register at module-load time via\n * `registerFormatPlugin(plugin)`. Consumers look them up via\n * `getFormatPlugin(id)` — they must NOT import format-implementation packages\n * directly. See `docs/architecture/format-plugins.md`.\n *\n * The registry lives on `globalThis` so that a single registration survives\n * across duplicate ESM graph evaluations (e.g. when both the CLI and a\n * plugin's own tests import `@abapify/adt-plugin` along different paths).\n */\n\nimport type { FormatPlugin } from './format-plugin';\n\nconst REGISTRY_KEY = Symbol.for('@abapify/adt-plugin/format-registry');\n\ninterface RegistryStore {\n plugins: Map<string, FormatPlugin>;\n}\n\nfunction getStore(): RegistryStore {\n const g = globalThis as unknown as Record<symbol, RegistryStore | undefined>;\n let store = g[REGISTRY_KEY];\n if (!store) {\n store = { plugins: new Map() };\n g[REGISTRY_KEY] = store;\n }\n return store;\n}\n\n/**\n * Register a format plugin.\n *\n * Idempotent for the same plugin instance: registering the same object twice\n * is a no-op (guards against dual-module-graph evaluation during tests /\n * bundler output). Registering a **different** plugin under an id that is\n * already taken throws.\n */\nexport function registerFormatPlugin(plugin: FormatPlugin): void {\n const store = getStore();\n const existing = store.plugins.get(plugin.id);\n if (existing) {\n if (existing === plugin) return;\n throw new Error(\n `Format plugin with id \"${plugin.id}\" is already registered (different instance).`,\n );\n }\n store.plugins.set(plugin.id, plugin);\n}\n\n/**\n * Look up a registered format plugin by id.\n */\nexport function getFormatPlugin(id: string): FormatPlugin | undefined {\n return getStore().plugins.get(id);\n}\n\n/**\n * Look up a format plugin by id, or throw a consistent error if it is not\n * registered. Use this from CLI commands where a missing plugin is always\n * user-visible.\n */\nexport function requireFormatPlugin(id: string): FormatPlugin {\n const plugin = getFormatPlugin(id);\n if (!plugin) {\n const available = listFormatPlugins()\n .map((p) => p.id)\n .join(', ');\n throw new Error(\n `Format plugin \"${id}\" is not registered. ` +\n (available\n ? `Available formats: ${available}.`\n : 'No format plugins are currently registered.'),\n );\n }\n return plugin;\n}\n\n/**\n * List all registered format plugins.\n */\nexport function listFormatPlugins(): FormatPlugin[] {\n return [...getStore().plugins.values()];\n}\n\n/**\n * Remove a plugin from the registry.\n *\n * Intended for tests only. Returns true if an entry was removed.\n */\nexport function unregisterFormatPlugin(id: string): boolean {\n return getStore().plugins.delete(id);\n}\n\n/**\n * Clear the registry completely.\n *\n * Intended for tests only.\n */\nexport function clearFormatRegistry(): void {\n getStore().plugins.clear();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,SAAgB,aAAa,YAA4C;CAEvE,IAAI,CAAC,WAAW,MACd,MAAM,IAAI,MAAM,yBAAyB;CAE3C,IAAI,CAAC,WAAW,SACd,MAAM,IAAI,MAAM,4BAA4B;CAE9C,IAAI,CAAC,WAAW,UACd,MAAM,IAAI,MAAM,6BAA6B;CAE/C,IAAI,CAAC,WAAW,QACd,MAAM,IAAI,MAAM,2BAA2B;CAE7C,IAAI,OAAO,WAAW,OAAO,WAAW,YACtC,MAAM,IAAI,MAAM,yCAAyC;CAI3D,OAAO;AACT;;;AC+BA,IAAa,6BAAb,cAAgD,MAAM;CAIzC;CAHX,AAAkB,OAAO;CAEzB,YACE,AAAS,MACT,SACA;EACA,MAAM,OAAO;EAHJ;CAIX;AACF;;;AClFA,MAAM,eAAe,OAAO,IAAI,qCAAqC;AAMrE,SAAS,WAA0B;CACjC,MAAM,IAAI;CACV,IAAI,QAAQ,EAAE;CACd,IAAI,CAAC,OAAO;EACV,QAAQ,EAAE,yBAAS,IAAI,IAAI,EAAE;EAC7B,EAAE,gBAAgB;CACpB;CACA,OAAO;AACT;;;;;;;;;AAUA,SAAgB,qBAAqB,QAA4B;CAC/D,MAAM,QAAQ,SAAS;CACvB,MAAM,WAAW,MAAM,QAAQ,IAAI,OAAO,EAAE;CAC5C,IAAI,UAAU;EACZ,IAAI,aAAa,QAAQ;EACzB,MAAM,IAAI,MACR,0BAA0B,OAAO,GAAG,8CACtC;CACF;CACA,MAAM,QAAQ,IAAI,OAAO,IAAI,MAAM;AACrC;;;;AAKA,SAAgB,gBAAgB,IAAsC;CACpE,OAAO,SAAS,CAAC,CAAC,QAAQ,IAAI,EAAE;AAClC;;;;;;AAOA,SAAgB,oBAAoB,IAA0B;CAC5D,MAAM,SAAS,gBAAgB,EAAE;CACjC,IAAI,CAAC,QAAQ;EACX,MAAM,YAAY,kBAAkB,CAAC,CAClC,KAAK,MAAM,EAAE,EAAE,CAAC,CAChB,KAAK,IAAI;EACZ,MAAM,IAAI,MACR,kBAAkB,GAAG,0BAClB,YACG,sBAAsB,UAAU,KAChC,8CACR;CACF;CACA,OAAO;AACT;;;;AAKA,SAAgB,oBAAoC;CAClD,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC,QAAQ,OAAO,CAAC;AACxC;;;;;;AAOA,SAAgB,uBAAuB,IAAqB;CAC1D,OAAO,SAAS,CAAC,CAAC,QAAQ,OAAO,EAAE;AACrC;;;;;;AAOA,SAAgB,sBAA4B;CAC1C,SAAS,CAAC,CAAC,QAAQ,MAAM;AAC3B"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/factory.ts","../src/lib/format/format-plugin.ts","../src/lib/format/format-registry.ts"],"sourcesContent":["/**\n * ADT Plugin Factory\n *\n * Factory function for creating ADT plugins with validation.\n */\n\nimport type { AdtPlugin, AdtPluginDefinition } from './types';\n\n/**\n * Create an ADT plugin with validation\n *\n * @param definition - Plugin definition\n * @returns Validated plugin instance\n *\n * @example\n * ```typescript\n * import { createPlugin } from '@abapify/adt-plugin';\n *\n * export const myPlugin = createPlugin({\n * name: 'myFormat',\n * version: '1.0.0',\n * description: 'My custom format plugin',\n *\n * registry: {\n * isSupported: (type) => supportedTypes.includes(type),\n * getSupportedTypes: () => supportedTypes,\n * },\n *\n * format: {\n * import: async (object, targetPath, context) => {\n * // Implementation\n * return { success: true, filesCreated: [] };\n * },\n * },\n * });\n * ```\n */\nexport function createPlugin(definition: AdtPluginDefinition): AdtPlugin {\n // Validate required fields\n if (!definition.name) {\n throw new Error('Plugin name is required');\n }\n if (!definition.version) {\n throw new Error('Plugin version is required');\n }\n if (!definition.registry) {\n throw new Error('Plugin registry is required');\n }\n if (!definition.format) {\n throw new Error('Plugin format is required');\n }\n if (typeof definition.format.import !== 'function') {\n throw new TypeError('Plugin format.import must be a function');\n }\n\n // Return validated plugin\n return definition;\n}\n","import type { FormatOptionValue } from '../../types';\n\n/**\n * FormatPlugin — interface for serialization-format plugins (abapGit, gCTS, AFF, …).\n *\n * A format plugin owns:\n * - a stable CLI id (used with `--format <id>`)\n * - the set of ABAP object types it can serialize\n * - a `getHandler(type)` accessor returning a `FormatHandler` for a specific\n * ABAP object type (the handler knows how to turn an ADK object into files\n * and vice versa)\n * - an optional `parseFilename(name)` helper (format-specific naming\n * convention — e.g. `zcl_foo.clas.xml` for abapGit)\n *\n * Format plugins are registered through the `format-registry` module. Packages\n * that implement a format (such as `@abapify/adt-plugin-abapgit`) call\n * `registerFormatPlugin(...)` as a side-effect of being imported, so pulling in\n * the package is enough to make `--format <id>` work. Consumers (export, diff,\n * import, checkout) MUST look plugins up through `getFormatPlugin(id)` — they\n * must NOT import format packages directly.\n */\n\n/**\n * Serialized output file produced by a handler.\n *\n * Identical shape to the pre-existing `SerializedFile` in\n * `@abapify/adt-plugin-abapgit` so migration is a pure rename.\n */\nexport interface SerializedFile {\n /** Relative path from the object directory (e.g. `zcl_foo.clas.xml`). */\n path: string;\n /** File contents. */\n content: string;\n /** Optional encoding (default: utf-8). */\n encoding?: BufferEncoding;\n}\n\n/** Output format for object types that support both legacy abapGit XML and AFF JSON. */\nexport type AbapGitOutputFormat = 'aff' | 'legacy';\n\n/** Source contents selected independently from mutable object getters. */\nexport interface FormatSerializeOptions {\n /**\n * Source component id to content.\n *\n * When present, this record is authoritative: handlers MUST NOT read source\n * through the object model and MUST emit only the supplied components.\n */\n sources?: Readonly<Record<string, string>>;\n /**\n * Output format for object types that support both legacy abapGit XML and\n * ABAP File Format (AFF) JSON. When omitted, the handler's default format\n * is used (AFF for CDS/RAP types, legacy XML for DDIC/code types).\n */\n format?: AbapGitOutputFormat;\n}\n\ninterface MaterializedFormatSourceFile extends SerializedFile {\n role: 'source';\n /** Source-history component id for source files. */\n sourceComponent: string;\n}\n\ninterface MaterializedFormatMetadataFile extends SerializedFile {\n role: 'metadata';\n}\n\n/** A repository-relative file produced without filesystem mutation. */\nexport type MaterializedFormatFile =\n MaterializedFormatSourceFile | MaterializedFormatMetadataFile;\n\nexport interface FormatMaterializationInput {\n object: unknown;\n objectType: string;\n packagePath: readonly string[];\n sources?: Readonly<Record<string, string>>;\n formatOptions?: Readonly<Record<string, FormatOptionValue>>;\n}\n\nexport interface FormatMaterializationResult {\n files: MaterializedFormatFile[];\n}\n\nexport type FormatMaterializationErrorCode =\n | 'FORMAT_MATERIALIZATION_UNSUPPORTED'\n | 'FORMAT_OBJECT_TYPE_UNSUPPORTED'\n | 'FORMAT_SOURCE_COMPONENT_UNSUPPORTED';\n\nexport class FormatMaterializationError extends Error {\n override readonly name = 'FormatMaterializationError';\n\n constructor(\n readonly code: FormatMaterializationErrorCode,\n message: string,\n ) {\n super(message);\n }\n}\n\n/**\n * Result of parsing a format-specific filename.\n *\n * Different formats use different naming conventions; this is the minimum\n * info any consumer needs (the object name, the SAP object type and the file\n * extension).\n */\nexport interface ParsedFormatFilename {\n /** SAP object name (e.g. `ZCL_FOO`). */\n name: string;\n /** SAP object type code (e.g. `CLAS`, `INTF`). */\n type: string;\n /** Optional per-file suffix (e.g. `testclasses` for a CLAS sub-include). */\n suffix?: string;\n /** File extension without the dot (e.g. `xml`, `abap`). */\n extension: string;\n}\n\n/**\n * Minimal schema surface used by format consumers.\n *\n * Both `parse` and `build` intentionally use `unknown` to avoid coupling\n * `@abapify/adt-plugin` to any particular XML schema library (ts-xsd, speci,\n * …). Concrete handlers may narrow this with a typed schema internally.\n */\nexport interface FormatHandlerSchema {\n parse(xml: string): unknown;\n build(data: unknown, options?: { pretty?: boolean }): string;\n}\n\n/**\n * Handler for a single ABAP object type within a format.\n *\n * Kept intentionally abstract — the concrete handler implementation in e.g.\n * `adt-plugin-abapgit` is a structural superset of this interface, so there\n * is no need to convert between them.\n */\nexport interface FormatHandler {\n /** ABAP object type code (e.g. `CLAS`). */\n readonly type: string;\n /** File extension associated with the object type (e.g. `clas`). */\n readonly fileExtension: string;\n /** Schema for parsing/building the handler's XML representation. */\n readonly schema: FormatHandlerSchema;\n /** Optional map from abapGit file suffix to source key. */\n readonly suffixToSourceKey?: Record<string, string>;\n /** Whether this handler treats an explicit `sources` map as authoritative. */\n readonly supportsExplicitSources?: boolean;\n /** Serialize an ADK object to one or more files. */\n serialize(\n object: unknown,\n options?: FormatSerializeOptions,\n ): Promise<SerializedFile[]>;\n /**\n * Map format-specific XML values back to ADK data. Present only on\n * handlers that support bidirectional (git → SAP) workflows.\n */\n fromAbapGit?(values: unknown): { name: string } & Record<string, unknown>;\n /** Set resolved source files on an ADK object during deserialization. */\n setSources?(object: unknown, sources: Record<string, string>): void;\n}\n\n/**\n * A serialization-format plugin.\n */\nexport interface FormatPlugin {\n /** Stable id used on the CLI (`--format <id>`). */\n readonly id: string;\n /** Human-readable description shown in help output. */\n readonly description: string;\n /** SAP object types this plugin can serialize (snapshot — may be computed). */\n readonly supportedTypes: ReadonlyArray<string>;\n /** Look up the handler for a given ABAP object type. */\n getHandler(type: string): FormatHandler | undefined;\n /**\n * Produce the desired repository files for one object without ADT,\n * filesystem, or Git side effects.\n */\n materialize?(\n input: FormatMaterializationInput,\n ): Promise<FormatMaterializationResult>;\n /** Parse a format-specific filename, if the format defines one. */\n parseFilename?(filename: string): ParsedFormatFilename | undefined;\n}\n","/**\n * Global format-plugin registry.\n *\n * Format plugins self-register at module-load time via\n * `registerFormatPlugin(plugin)`. Consumers look them up via\n * `getFormatPlugin(id)` — they must NOT import format-implementation packages\n * directly. See `docs/architecture/format-plugins.md`.\n *\n * The registry lives on `globalThis` so that a single registration survives\n * across duplicate ESM graph evaluations (e.g. when both the CLI and a\n * plugin's own tests import `@abapify/adt-plugin` along different paths).\n */\n\nimport type { FormatPlugin } from './format-plugin';\n\nconst REGISTRY_KEY = Symbol.for('@abapify/adt-plugin/format-registry');\n\ninterface RegistryStore {\n plugins: Map<string, FormatPlugin>;\n}\n\nfunction getStore(): RegistryStore {\n const g = globalThis as unknown as Record<symbol, RegistryStore | undefined>;\n let store = g[REGISTRY_KEY];\n if (!store) {\n store = { plugins: new Map() };\n g[REGISTRY_KEY] = store;\n }\n return store;\n}\n\n/**\n * Register a format plugin.\n *\n * Idempotent for the same plugin instance: registering the same object twice\n * is a no-op (guards against dual-module-graph evaluation during tests /\n * bundler output). Registering a **different** plugin under an id that is\n * already taken throws.\n */\nexport function registerFormatPlugin(plugin: FormatPlugin): void {\n const store = getStore();\n const existing = store.plugins.get(plugin.id);\n if (existing) {\n if (existing === plugin) return;\n throw new Error(\n `Format plugin with id \"${plugin.id}\" is already registered (different instance).`,\n );\n }\n store.plugins.set(plugin.id, plugin);\n}\n\n/**\n * Look up a registered format plugin by id.\n */\nexport function getFormatPlugin(id: string): FormatPlugin | undefined {\n return getStore().plugins.get(id);\n}\n\n/**\n * Look up a format plugin by id, or throw a consistent error if it is not\n * registered. Use this from CLI commands where a missing plugin is always\n * user-visible.\n */\nexport function requireFormatPlugin(id: string): FormatPlugin {\n const plugin = getFormatPlugin(id);\n if (!plugin) {\n const available = listFormatPlugins()\n .map((p) => p.id)\n .join(', ');\n throw new Error(\n `Format plugin \"${id}\" is not registered. ` +\n (available\n ? `Available formats: ${available}.`\n : 'No format plugins are currently registered.'),\n );\n }\n return plugin;\n}\n\n/**\n * List all registered format plugins.\n */\nexport function listFormatPlugins(): FormatPlugin[] {\n return [...getStore().plugins.values()];\n}\n\n/**\n * Remove a plugin from the registry.\n *\n * Intended for tests only. Returns true if an entry was removed.\n */\nexport function unregisterFormatPlugin(id: string): boolean {\n return getStore().plugins.delete(id);\n}\n\n/**\n * Clear the registry completely.\n *\n * Intended for tests only.\n */\nexport function clearFormatRegistry(): void {\n getStore().plugins.clear();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,SAAgB,aAAa,YAA4C;CAEvE,IAAI,CAAC,WAAW,MACd,MAAM,IAAI,MAAM,yBAAyB;CAE3C,IAAI,CAAC,WAAW,SACd,MAAM,IAAI,MAAM,4BAA4B;CAE9C,IAAI,CAAC,WAAW,UACd,MAAM,IAAI,MAAM,6BAA6B;CAE/C,IAAI,CAAC,WAAW,QACd,MAAM,IAAI,MAAM,2BAA2B;CAE7C,IAAI,OAAO,WAAW,OAAO,WAAW,YACtC,MAAM,IAAI,UAAU,yCAAyC;CAI/D,OAAO;AACT;;;AC+BA,IAAa,6BAAb,cAAgD,MAAM;CAIzC;CAHX,AAAkB,OAAO;CAEzB,YACE,AAAS,MACT,SACA;EACA,MAAM,OAAO;EAHJ;CAIX;AACF;;;AClFA,MAAM,eAAe,OAAO,IAAI,qCAAqC;AAMrE,SAAS,WAA0B;CACjC,MAAM,IAAI;CACV,IAAI,QAAQ,EAAE;CACd,IAAI,CAAC,OAAO;EACV,QAAQ,EAAE,yBAAS,IAAI,IAAI,EAAE;EAC7B,EAAE,gBAAgB;CACpB;CACA,OAAO;AACT;;;;;;;;;AAUA,SAAgB,qBAAqB,QAA4B;CAC/D,MAAM,QAAQ,SAAS;CACvB,MAAM,WAAW,MAAM,QAAQ,IAAI,OAAO,EAAE;CAC5C,IAAI,UAAU;EACZ,IAAI,aAAa,QAAQ;EACzB,MAAM,IAAI,MACR,0BAA0B,OAAO,GAAG,8CACtC;CACF;CACA,MAAM,QAAQ,IAAI,OAAO,IAAI,MAAM;AACrC;;;;AAKA,SAAgB,gBAAgB,IAAsC;CACpE,OAAO,SAAS,CAAC,CAAC,QAAQ,IAAI,EAAE;AAClC;;;;;;AAOA,SAAgB,oBAAoB,IAA0B;CAC5D,MAAM,SAAS,gBAAgB,EAAE;CACjC,IAAI,CAAC,QAAQ;EACX,MAAM,YAAY,kBAAkB,CAAC,CAClC,KAAK,MAAM,EAAE,EAAE,CAAC,CAChB,KAAK,IAAI;EACZ,MAAM,IAAI,MACR,kBAAkB,GAAG,0BAClB,YACG,sBAAsB,UAAU,KAChC,8CACR;CACF;CACA,OAAO;AACT;;;;AAKA,SAAgB,oBAAoC;CAClD,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC,QAAQ,OAAO,CAAC;AACxC;;;;;;AAOA,SAAgB,uBAAuB,IAAqB;CAC1D,OAAO,SAAS,CAAC,CAAC,QAAQ,OAAO,EAAE;AACrC;;;;;;AAOA,SAAgB,sBAA4B;CAC1C,SAAS,CAAC,CAAC,QAAQ,MAAM;AAC3B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abapify/adt-plugin",
3
- "version": "0.4.34",
3
+ "version": "0.4.36",
4
4
  "description": "ADT Plugin interface and factory for abapify",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -19,7 +19,7 @@
19
19
  "dist"
20
20
  ],
21
21
  "dependencies": {
22
- "@abapify/adk": "0.4.34"
22
+ "@abapify/adk": "0.4.36"
23
23
  },
24
24
  "repository": {
25
25
  "type": "git",