@abapify/adt-plugin 0.4.0 → 0.4.3
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 +28 -0
- package/dist/index.d.mts +614 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +124 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -88,6 +88,34 @@ const types = abapGitPlugin.registry.getSupportedTypes();
|
|
|
88
88
|
|
|
89
89
|
## API
|
|
90
90
|
|
|
91
|
+
### Pure tree materialization
|
|
92
|
+
|
|
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
|
+
|
|
91
119
|
### `createPlugin(definition)`
|
|
92
120
|
|
|
93
121
|
Factory function to create a validated plugin instance.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,614 @@
|
|
|
1
|
+
import { AdkObject } from "@abapify/adk";
|
|
2
|
+
//#region src/types.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* ABAP object type code (e.g., 'CLAS', 'INTF', 'DOMA')
|
|
5
|
+
*/
|
|
6
|
+
type AbapObjectType = string;
|
|
7
|
+
/**
|
|
8
|
+
* Primitive value accepted for format/plugin options.
|
|
9
|
+
*/
|
|
10
|
+
type FormatOptionValue = string | number | boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Context for import operation
|
|
13
|
+
*
|
|
14
|
+
* The plugin is responsible for determining folder structure based on its format rules.
|
|
15
|
+
* Plugin can use the provided resolver to load package hierarchy from SAP.
|
|
16
|
+
*/
|
|
17
|
+
interface ImportContext {
|
|
18
|
+
/**
|
|
19
|
+
* Resolve full package path from root to the given package.
|
|
20
|
+
* Uses ADK to load package → super package → etc until root.
|
|
21
|
+
*
|
|
22
|
+
* @param packageName - Package name to resolve
|
|
23
|
+
* @returns Array of package names from root to current (e.g., ['ZROOT', 'ZROOT_CHILD', 'ZROOT_CHILD_SUB'])
|
|
24
|
+
*/
|
|
25
|
+
resolvePackagePath(packageName: string): Promise<string[]>;
|
|
26
|
+
/**
|
|
27
|
+
* Format options provided explicitly by CLI invocation.
|
|
28
|
+
* Interpreted by the selected format plugin.
|
|
29
|
+
*/
|
|
30
|
+
formatOptions?: Readonly<Record<string, FormatOptionValue>>;
|
|
31
|
+
/**
|
|
32
|
+
* Format options loaded from configuration (e.g. adt.config.ts).
|
|
33
|
+
* Interpreted by the selected format plugin.
|
|
34
|
+
*/
|
|
35
|
+
configFormatOptions?: Readonly<Record<string, FormatOptionValue>>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Result of import operation
|
|
39
|
+
*/
|
|
40
|
+
interface ImportResult {
|
|
41
|
+
success: boolean;
|
|
42
|
+
filesCreated: string[];
|
|
43
|
+
errors?: string[];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Result of a deletion operation (removing local files for a deleted object)
|
|
47
|
+
*/
|
|
48
|
+
interface DeleteResult {
|
|
49
|
+
success: boolean;
|
|
50
|
+
/** Local file paths that were removed */
|
|
51
|
+
filesRemoved: string[];
|
|
52
|
+
errors?: string[];
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* FileTree - Virtual file system abstraction for export
|
|
56
|
+
*
|
|
57
|
+
* Plugins receive this to iterate and read files without
|
|
58
|
+
* direct dependency on Node.js fs module.
|
|
59
|
+
*/
|
|
60
|
+
interface FileTree {
|
|
61
|
+
/** Root path of the file tree */
|
|
62
|
+
readonly root: string;
|
|
63
|
+
/** Find files matching glob pattern */
|
|
64
|
+
glob(pattern: string): Promise<string[]>;
|
|
65
|
+
/** Read file contents as string */
|
|
66
|
+
read(path: string): Promise<string>;
|
|
67
|
+
/** Read file contents as buffer */
|
|
68
|
+
readBuffer(path: string): Promise<Buffer>;
|
|
69
|
+
/** Check if path exists */
|
|
70
|
+
exists(path: string): Promise<boolean>;
|
|
71
|
+
/** List directory contents */
|
|
72
|
+
readdir(path: string): Promise<string[]>;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Options passed to format plugin's export generator
|
|
76
|
+
*
|
|
77
|
+
* Provides the plugin with deployment context so it can resolve
|
|
78
|
+
* format-specific concerns (e.g., abapGit folder logic → packageRef).
|
|
79
|
+
*/
|
|
80
|
+
interface ExportOptions {
|
|
81
|
+
/** Target root package on SAP (e.g., 'ZABAPGIT_EXAMPLES') */
|
|
82
|
+
rootPackage?: string;
|
|
83
|
+
/** ABAP language version override (e.g., '5' for ABAP Cloud) */
|
|
84
|
+
abapLanguageVersion?: string;
|
|
85
|
+
/** Format options provided explicitly by CLI invocation */
|
|
86
|
+
formatOptions?: Readonly<Record<string, FormatOptionValue>>;
|
|
87
|
+
/** Format options loaded from configuration (e.g. adt.config.ts) */
|
|
88
|
+
configFormatOptions?: Readonly<Record<string, FormatOptionValue>>;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Context for export operation (legacy - kept for compatibility)
|
|
92
|
+
*/
|
|
93
|
+
interface ExportContext {
|
|
94
|
+
/** Base directory containing the serialized files */
|
|
95
|
+
sourceDir: string;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Result of single object export operation (legacy)
|
|
99
|
+
*/
|
|
100
|
+
interface ExportResult {
|
|
101
|
+
success: boolean;
|
|
102
|
+
object?: AdkObject;
|
|
103
|
+
errors?: string[];
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* ADT Plugin interface - service-based structure
|
|
107
|
+
*
|
|
108
|
+
* Plugins provide format-specific serialization/deserialization
|
|
109
|
+
* of ADK objects (e.g., abapGit format).
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* const plugin = createPlugin({
|
|
114
|
+
* name: 'myFormat',
|
|
115
|
+
* version: '1.0.0',
|
|
116
|
+
* description: 'My custom format',
|
|
117
|
+
*
|
|
118
|
+
* registry: {
|
|
119
|
+
* isSupported: (type) => ['CLAS', 'INTF'].includes(type),
|
|
120
|
+
* getSupportedTypes: () => ['CLAS', 'INTF'],
|
|
121
|
+
* },
|
|
122
|
+
*
|
|
123
|
+
* format: {
|
|
124
|
+
* import: async (object, targetPath, context) => {
|
|
125
|
+
* // Serialize object to files
|
|
126
|
+
* return { success: true, filesCreated: ['file.xml'] };
|
|
127
|
+
* },
|
|
128
|
+
* },
|
|
129
|
+
* });
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
interface AdtPlugin {
|
|
133
|
+
readonly name: string;
|
|
134
|
+
readonly version: string;
|
|
135
|
+
readonly description: string;
|
|
136
|
+
/** Registry service - object type support */
|
|
137
|
+
readonly registry: {
|
|
138
|
+
/**
|
|
139
|
+
* Check if object type is supported by this plugin
|
|
140
|
+
*/
|
|
141
|
+
isSupported(type: AbapObjectType): boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Get all supported object types
|
|
144
|
+
*/
|
|
145
|
+
getSupportedTypes(): AbapObjectType[];
|
|
146
|
+
};
|
|
147
|
+
/** Format service - import/export operations */
|
|
148
|
+
readonly format: {
|
|
149
|
+
/**
|
|
150
|
+
* Import ADK object to file system (SAP → Git)
|
|
151
|
+
* Converts ADK object to serialized format files
|
|
152
|
+
*
|
|
153
|
+
* @param object - ADK object to serialize
|
|
154
|
+
* @param targetPath - Base output directory
|
|
155
|
+
* @param context - Import context (package path, etc.)
|
|
156
|
+
*/
|
|
157
|
+
import(object: AdkObject, targetPath: string, context: ImportContext): Promise<ImportResult>;
|
|
158
|
+
/**
|
|
159
|
+
* Delete local files for an object that was marked for deletion in SAP.
|
|
160
|
+
*
|
|
161
|
+
* The plugin uses the same path-resolution rules as `import()` to locate
|
|
162
|
+
* the files, then removes them from the file system.
|
|
163
|
+
*
|
|
164
|
+
* @param objectRef - Lightweight object reference (type, name, pgmid)
|
|
165
|
+
* @param targetPath - Base output directory (same as used for import)
|
|
166
|
+
* @param context - Import context (package path resolver, format options)
|
|
167
|
+
* @returns List of file paths removed, or empty if nothing was found
|
|
168
|
+
*/
|
|
169
|
+
delete?(objectRef: {
|
|
170
|
+
pgmid: string;
|
|
171
|
+
type: string;
|
|
172
|
+
name: string;
|
|
173
|
+
}, targetPath: string, context: ImportContext): Promise<DeleteResult>;
|
|
174
|
+
/**
|
|
175
|
+
* Export from file system to ADK objects (Git → SAP)
|
|
176
|
+
* Generator that yields ADK objects ready to be saved to SAP.
|
|
177
|
+
*
|
|
178
|
+
* Plugin is responsible for:
|
|
179
|
+
* - Iterating files in its format (*.abap, *.xml, etc.)
|
|
180
|
+
* - Parsing each file into ADK object
|
|
181
|
+
* - Resolving format-specific concerns (e.g., packageRef from folder logic)
|
|
182
|
+
* - Yielding ADK objects (does NOT save to SAP)
|
|
183
|
+
*
|
|
184
|
+
* @param fileTree - Virtual file system to read from
|
|
185
|
+
* @param client - ADT client for creating ADK objects
|
|
186
|
+
* @param options - Export options (root package, language version, etc.)
|
|
187
|
+
* @yields ADK objects ready to be saved
|
|
188
|
+
*/
|
|
189
|
+
export?(fileTree: FileTree, client: unknown, options?: ExportOptions): AsyncGenerator<AdkObject>;
|
|
190
|
+
};
|
|
191
|
+
/** Lifecycle hooks */
|
|
192
|
+
readonly hooks?: {
|
|
193
|
+
/** Called after all objects have been imported */
|
|
194
|
+
afterImport?(targetPath: string): Promise<void>;
|
|
195
|
+
/** Called before export starts */
|
|
196
|
+
beforeExport?(sourcePath: string): Promise<void>;
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Plugin definition passed to createPlugin factory
|
|
201
|
+
* Same as AdtPlugin but allows partial hooks
|
|
202
|
+
*/
|
|
203
|
+
type AdtPluginDefinition = AdtPlugin;
|
|
204
|
+
//#endregion
|
|
205
|
+
//#region src/cli-types.d.ts
|
|
206
|
+
/**
|
|
207
|
+
* CLI Command Plugin Types
|
|
208
|
+
*
|
|
209
|
+
* CLI-agnostic interface for command plugins.
|
|
210
|
+
* Plugins implement this interface without depending on any CLI framework (Commander, yargs, etc.)
|
|
211
|
+
* The CLI shell (adt-cli) translates these definitions to the actual CLI framework.
|
|
212
|
+
*/
|
|
213
|
+
/**
|
|
214
|
+
* CLI option definition
|
|
215
|
+
*/
|
|
216
|
+
interface CliOption {
|
|
217
|
+
/**
|
|
218
|
+
* Option flags in Commander format
|
|
219
|
+
* @example '-o, --output <dir>' or '--verbose'
|
|
220
|
+
*/
|
|
221
|
+
flags: string;
|
|
222
|
+
/**
|
|
223
|
+
* Description shown in help
|
|
224
|
+
*/
|
|
225
|
+
description: string;
|
|
226
|
+
/**
|
|
227
|
+
* Default value if not provided
|
|
228
|
+
*/
|
|
229
|
+
default?: string | boolean | number;
|
|
230
|
+
/**
|
|
231
|
+
* Whether this option is required
|
|
232
|
+
*/
|
|
233
|
+
required?: boolean;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* CLI argument definition
|
|
237
|
+
*/
|
|
238
|
+
interface CliArgument {
|
|
239
|
+
/**
|
|
240
|
+
* Argument name
|
|
241
|
+
* Use <name> for required, [name] for optional
|
|
242
|
+
* @example '<path>' or '[config]'
|
|
243
|
+
*/
|
|
244
|
+
name: string;
|
|
245
|
+
/**
|
|
246
|
+
* Description shown in help
|
|
247
|
+
*/
|
|
248
|
+
description: string;
|
|
249
|
+
/**
|
|
250
|
+
* Default value if not provided (only for optional arguments)
|
|
251
|
+
*/
|
|
252
|
+
default?: string;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Context provided to command execution
|
|
256
|
+
*/
|
|
257
|
+
interface CliContext {
|
|
258
|
+
/**
|
|
259
|
+
* Current working directory
|
|
260
|
+
*/
|
|
261
|
+
cwd: string;
|
|
262
|
+
/**
|
|
263
|
+
* Loaded configuration from adt.config.ts (if present)
|
|
264
|
+
*/
|
|
265
|
+
config: Record<string, unknown>;
|
|
266
|
+
/**
|
|
267
|
+
* Logger instance
|
|
268
|
+
*/
|
|
269
|
+
logger: CliLogger;
|
|
270
|
+
/**
|
|
271
|
+
* ADT client factory (provided by adt-cli when authenticated)
|
|
272
|
+
* Returns an authenticated ADT client for making API calls.
|
|
273
|
+
* Only available when running within adt-cli context.
|
|
274
|
+
* Note: This is async - plugins must await the result.
|
|
275
|
+
*/
|
|
276
|
+
getAdtClient?: () => Promise<unknown>;
|
|
277
|
+
/**
|
|
278
|
+
* ADT system name for hyperlinks (e.g., "TRL")
|
|
279
|
+
* Used to construct adt:// protocol links.
|
|
280
|
+
* Only available when running within adt-cli context.
|
|
281
|
+
*/
|
|
282
|
+
adtSystemName?: string;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Simple logger interface (CLI-agnostic)
|
|
286
|
+
*/
|
|
287
|
+
interface CliLogger {
|
|
288
|
+
debug(message: string, ...args: unknown[]): void;
|
|
289
|
+
info(message: string, ...args: unknown[]): void;
|
|
290
|
+
warn(message: string, ...args: unknown[]): void;
|
|
291
|
+
error(message: string, ...args: unknown[]): void;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* CLI Command Plugin interface
|
|
295
|
+
*
|
|
296
|
+
* Implement this interface to create a CLI command plugin.
|
|
297
|
+
* The plugin is CLI-agnostic - it doesn't know about Commander or any other CLI framework.
|
|
298
|
+
*
|
|
299
|
+
* @example
|
|
300
|
+
* ```typescript
|
|
301
|
+
* import type { CliCommandPlugin } from '@abapify/adt-plugin';
|
|
302
|
+
*
|
|
303
|
+
* export const myCommand: CliCommandPlugin = {
|
|
304
|
+
* name: 'my-command',
|
|
305
|
+
* description: 'Does something useful',
|
|
306
|
+
* options: [
|
|
307
|
+
* { flags: '-o, --output <dir>', description: 'Output directory' },
|
|
308
|
+
* ],
|
|
309
|
+
* async execute(args, ctx) {
|
|
310
|
+
* ctx.logger.info('Running my command...');
|
|
311
|
+
* // Do work here
|
|
312
|
+
* },
|
|
313
|
+
* };
|
|
314
|
+
* ```
|
|
315
|
+
*/
|
|
316
|
+
interface CliCommandPlugin {
|
|
317
|
+
/**
|
|
318
|
+
* Command name (used in CLI invocation)
|
|
319
|
+
* @example 'codegen' results in `adt codegen`
|
|
320
|
+
*/
|
|
321
|
+
name: string;
|
|
322
|
+
/**
|
|
323
|
+
* Command alias (alternate name)
|
|
324
|
+
* @example alias: 'deploy' allows `adt deploy` in addition to `adt export`
|
|
325
|
+
*/
|
|
326
|
+
alias?: string;
|
|
327
|
+
/**
|
|
328
|
+
* Command description shown in help
|
|
329
|
+
*/
|
|
330
|
+
description: string;
|
|
331
|
+
/**
|
|
332
|
+
* Command options (flags)
|
|
333
|
+
*/
|
|
334
|
+
options?: CliOption[];
|
|
335
|
+
/**
|
|
336
|
+
* Positional arguments
|
|
337
|
+
*/
|
|
338
|
+
arguments?: CliArgument[];
|
|
339
|
+
/**
|
|
340
|
+
* Nested subcommands
|
|
341
|
+
* @example codegen.subcommands = [contractsCommand] results in `adt codegen contracts`
|
|
342
|
+
*/
|
|
343
|
+
subcommands?: CliCommandPlugin[];
|
|
344
|
+
/**
|
|
345
|
+
* Execute the command
|
|
346
|
+
*
|
|
347
|
+
* @param args - Parsed arguments and options as key-value pairs
|
|
348
|
+
* @param ctx - Execution context (cwd, config, logger)
|
|
349
|
+
*/
|
|
350
|
+
execute?(args: Record<string, unknown>, ctx: CliContext): Promise<void>;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Module that exports a CLI command plugin
|
|
354
|
+
* Used for dynamic import resolution
|
|
355
|
+
*/
|
|
356
|
+
interface CliCommandModule {
|
|
357
|
+
/**
|
|
358
|
+
* Default export should be the command plugin
|
|
359
|
+
*/
|
|
360
|
+
default: CliCommandPlugin;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* ADT CLI configuration for command plugins
|
|
364
|
+
*/
|
|
365
|
+
interface AdtCliConfig {
|
|
366
|
+
/**
|
|
367
|
+
* Command plugins to load
|
|
368
|
+
* Can be package names or relative paths
|
|
369
|
+
*
|
|
370
|
+
* @example
|
|
371
|
+
* ```typescript
|
|
372
|
+
* commands: [
|
|
373
|
+
* '@abapify/adt-codegen/commands/codegen',
|
|
374
|
+
* './my-local-command',
|
|
375
|
+
* ]
|
|
376
|
+
* ```
|
|
377
|
+
*/
|
|
378
|
+
commands?: string[];
|
|
379
|
+
/**
|
|
380
|
+
* Additional configuration passed to commands via context
|
|
381
|
+
*/
|
|
382
|
+
[key: string]: unknown;
|
|
383
|
+
}
|
|
384
|
+
//#endregion
|
|
385
|
+
//#region src/factory.d.ts
|
|
386
|
+
/**
|
|
387
|
+
* Create an ADT plugin with validation
|
|
388
|
+
*
|
|
389
|
+
* @param definition - Plugin definition
|
|
390
|
+
* @returns Validated plugin instance
|
|
391
|
+
*
|
|
392
|
+
* @example
|
|
393
|
+
* ```typescript
|
|
394
|
+
* import { createPlugin } from '@abapify/adt-plugin';
|
|
395
|
+
*
|
|
396
|
+
* export const myPlugin = createPlugin({
|
|
397
|
+
* name: 'myFormat',
|
|
398
|
+
* version: '1.0.0',
|
|
399
|
+
* description: 'My custom format plugin',
|
|
400
|
+
*
|
|
401
|
+
* registry: {
|
|
402
|
+
* isSupported: (type) => supportedTypes.includes(type),
|
|
403
|
+
* getSupportedTypes: () => supportedTypes,
|
|
404
|
+
* },
|
|
405
|
+
*
|
|
406
|
+
* format: {
|
|
407
|
+
* import: async (object, targetPath, context) => {
|
|
408
|
+
* // Implementation
|
|
409
|
+
* return { success: true, filesCreated: [] };
|
|
410
|
+
* },
|
|
411
|
+
* },
|
|
412
|
+
* });
|
|
413
|
+
* ```
|
|
414
|
+
*/
|
|
415
|
+
declare function createPlugin(definition: AdtPluginDefinition): AdtPlugin;
|
|
416
|
+
//#endregion
|
|
417
|
+
//#region src/lib/format/format-plugin.d.ts
|
|
418
|
+
/**
|
|
419
|
+
* FormatPlugin — interface for serialization-format plugins (abapGit, gCTS, AFF, …).
|
|
420
|
+
*
|
|
421
|
+
* A format plugin owns:
|
|
422
|
+
* - a stable CLI id (used with `--format <id>`)
|
|
423
|
+
* - the set of ABAP object types it can serialize
|
|
424
|
+
* - a `getHandler(type)` accessor returning a `FormatHandler` for a specific
|
|
425
|
+
* ABAP object type (the handler knows how to turn an ADK object into files
|
|
426
|
+
* and vice versa)
|
|
427
|
+
* - an optional `parseFilename(name)` helper (format-specific naming
|
|
428
|
+
* convention — e.g. `zcl_foo.clas.xml` for abapGit)
|
|
429
|
+
*
|
|
430
|
+
* Format plugins are registered through the `format-registry` module. Packages
|
|
431
|
+
* that implement a format (such as `@abapify/adt-plugin-abapgit`) call
|
|
432
|
+
* `registerFormatPlugin(...)` as a side-effect of being imported, so pulling in
|
|
433
|
+
* the package is enough to make `--format <id>` work. Consumers (export, diff,
|
|
434
|
+
* import, checkout) MUST look plugins up through `getFormatPlugin(id)` — they
|
|
435
|
+
* must NOT import format packages directly.
|
|
436
|
+
*/
|
|
437
|
+
/**
|
|
438
|
+
* Serialized output file produced by a handler.
|
|
439
|
+
*
|
|
440
|
+
* Identical shape to the pre-existing `SerializedFile` in
|
|
441
|
+
* `@abapify/adt-plugin-abapgit` so migration is a pure rename.
|
|
442
|
+
*/
|
|
443
|
+
interface SerializedFile {
|
|
444
|
+
/** Relative path from the object directory (e.g. `zcl_foo.clas.xml`). */
|
|
445
|
+
path: string;
|
|
446
|
+
/** File contents. */
|
|
447
|
+
content: string;
|
|
448
|
+
/** Optional encoding (default: utf-8). */
|
|
449
|
+
encoding?: BufferEncoding;
|
|
450
|
+
}
|
|
451
|
+
/** Output format for object types that support both legacy abapGit XML and AFF JSON. */
|
|
452
|
+
type AbapGitOutputFormat = 'aff' | 'legacy';
|
|
453
|
+
/** Source contents selected independently from mutable object getters. */
|
|
454
|
+
interface FormatSerializeOptions {
|
|
455
|
+
/**
|
|
456
|
+
* Source component id to content.
|
|
457
|
+
*
|
|
458
|
+
* When present, this record is authoritative: handlers MUST NOT read source
|
|
459
|
+
* through the object model and MUST emit only the supplied components.
|
|
460
|
+
*/
|
|
461
|
+
sources?: Readonly<Record<string, string>>;
|
|
462
|
+
/**
|
|
463
|
+
* Output format for object types that support both legacy abapGit XML and
|
|
464
|
+
* ABAP File Format (AFF) JSON. When omitted, the handler's default format
|
|
465
|
+
* is used (AFF for CDS/RAP types, legacy XML for DDIC/code types).
|
|
466
|
+
*/
|
|
467
|
+
format?: AbapGitOutputFormat;
|
|
468
|
+
}
|
|
469
|
+
interface MaterializedFormatSourceFile extends SerializedFile {
|
|
470
|
+
role: 'source';
|
|
471
|
+
/** Source-history component id for source files. */
|
|
472
|
+
sourceComponent: string;
|
|
473
|
+
}
|
|
474
|
+
interface MaterializedFormatMetadataFile extends SerializedFile {
|
|
475
|
+
role: 'metadata';
|
|
476
|
+
}
|
|
477
|
+
/** A repository-relative file produced without filesystem mutation. */
|
|
478
|
+
type MaterializedFormatFile = MaterializedFormatSourceFile | MaterializedFormatMetadataFile;
|
|
479
|
+
interface FormatMaterializationInput {
|
|
480
|
+
object: unknown;
|
|
481
|
+
objectType: string;
|
|
482
|
+
packagePath: readonly string[];
|
|
483
|
+
sources?: Readonly<Record<string, string>>;
|
|
484
|
+
formatOptions?: Readonly<Record<string, FormatOptionValue>>;
|
|
485
|
+
}
|
|
486
|
+
interface FormatMaterializationResult {
|
|
487
|
+
files: MaterializedFormatFile[];
|
|
488
|
+
}
|
|
489
|
+
type FormatMaterializationErrorCode = 'FORMAT_MATERIALIZATION_UNSUPPORTED' | 'FORMAT_OBJECT_TYPE_UNSUPPORTED' | 'FORMAT_SOURCE_COMPONENT_UNSUPPORTED';
|
|
490
|
+
declare class FormatMaterializationError extends Error {
|
|
491
|
+
readonly code: FormatMaterializationErrorCode;
|
|
492
|
+
readonly name = "FormatMaterializationError";
|
|
493
|
+
constructor(code: FormatMaterializationErrorCode, message: string);
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Result of parsing a format-specific filename.
|
|
497
|
+
*
|
|
498
|
+
* Different formats use different naming conventions; this is the minimum
|
|
499
|
+
* info any consumer needs (the object name, the SAP object type and the file
|
|
500
|
+
* extension).
|
|
501
|
+
*/
|
|
502
|
+
interface ParsedFormatFilename {
|
|
503
|
+
/** SAP object name (e.g. `ZCL_FOO`). */
|
|
504
|
+
name: string;
|
|
505
|
+
/** SAP object type code (e.g. `CLAS`, `INTF`). */
|
|
506
|
+
type: string;
|
|
507
|
+
/** Optional per-file suffix (e.g. `testclasses` for a CLAS sub-include). */
|
|
508
|
+
suffix?: string;
|
|
509
|
+
/** File extension without the dot (e.g. `xml`, `abap`). */
|
|
510
|
+
extension: string;
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Minimal schema surface used by format consumers.
|
|
514
|
+
*
|
|
515
|
+
* Both `parse` and `build` intentionally use `unknown` to avoid coupling
|
|
516
|
+
* `@abapify/adt-plugin` to any particular XML schema library (ts-xsd, speci,
|
|
517
|
+
* …). Concrete handlers may narrow this with a typed schema internally.
|
|
518
|
+
*/
|
|
519
|
+
interface FormatHandlerSchema {
|
|
520
|
+
parse(xml: string): unknown;
|
|
521
|
+
build(data: unknown, options?: {
|
|
522
|
+
pretty?: boolean;
|
|
523
|
+
}): string;
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Handler for a single ABAP object type within a format.
|
|
527
|
+
*
|
|
528
|
+
* Kept intentionally abstract — the concrete handler implementation in e.g.
|
|
529
|
+
* `adt-plugin-abapgit` is a structural superset of this interface, so there
|
|
530
|
+
* is no need to convert between them.
|
|
531
|
+
*/
|
|
532
|
+
interface FormatHandler {
|
|
533
|
+
/** ABAP object type code (e.g. `CLAS`). */
|
|
534
|
+
readonly type: string;
|
|
535
|
+
/** File extension associated with the object type (e.g. `clas`). */
|
|
536
|
+
readonly fileExtension: string;
|
|
537
|
+
/** Schema for parsing/building the handler's XML representation. */
|
|
538
|
+
readonly schema: FormatHandlerSchema;
|
|
539
|
+
/** Optional map from abapGit file suffix to source key. */
|
|
540
|
+
readonly suffixToSourceKey?: Record<string, string>;
|
|
541
|
+
/** Whether this handler treats an explicit `sources` map as authoritative. */
|
|
542
|
+
readonly supportsExplicitSources?: boolean;
|
|
543
|
+
/** Serialize an ADK object to one or more files. */
|
|
544
|
+
serialize(object: unknown, options?: FormatSerializeOptions): Promise<SerializedFile[]>;
|
|
545
|
+
/**
|
|
546
|
+
* Map format-specific XML values back to ADK data. Present only on
|
|
547
|
+
* handlers that support bidirectional (git → SAP) workflows.
|
|
548
|
+
*/
|
|
549
|
+
fromAbapGit?(values: unknown): {
|
|
550
|
+
name: string;
|
|
551
|
+
} & Record<string, unknown>;
|
|
552
|
+
/** Set resolved source files on an ADK object during deserialization. */
|
|
553
|
+
setSources?(object: unknown, sources: Record<string, string>): void;
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* A serialization-format plugin.
|
|
557
|
+
*/
|
|
558
|
+
interface FormatPlugin {
|
|
559
|
+
/** Stable id used on the CLI (`--format <id>`). */
|
|
560
|
+
readonly id: string;
|
|
561
|
+
/** Human-readable description shown in help output. */
|
|
562
|
+
readonly description: string;
|
|
563
|
+
/** SAP object types this plugin can serialize (snapshot — may be computed). */
|
|
564
|
+
readonly supportedTypes: ReadonlyArray<string>;
|
|
565
|
+
/** Look up the handler for a given ABAP object type. */
|
|
566
|
+
getHandler(type: string): FormatHandler | undefined;
|
|
567
|
+
/**
|
|
568
|
+
* Produce the desired repository files for one object without ADT,
|
|
569
|
+
* filesystem, or Git side effects.
|
|
570
|
+
*/
|
|
571
|
+
materialize?(input: FormatMaterializationInput): Promise<FormatMaterializationResult>;
|
|
572
|
+
/** Parse a format-specific filename, if the format defines one. */
|
|
573
|
+
parseFilename?(filename: string): ParsedFormatFilename | undefined;
|
|
574
|
+
}
|
|
575
|
+
//#endregion
|
|
576
|
+
//#region src/lib/format/format-registry.d.ts
|
|
577
|
+
/**
|
|
578
|
+
* Register a format plugin.
|
|
579
|
+
*
|
|
580
|
+
* Idempotent for the same plugin instance: registering the same object twice
|
|
581
|
+
* is a no-op (guards against dual-module-graph evaluation during tests /
|
|
582
|
+
* bundler output). Registering a **different** plugin under an id that is
|
|
583
|
+
* already taken throws.
|
|
584
|
+
*/
|
|
585
|
+
declare function registerFormatPlugin(plugin: FormatPlugin): void;
|
|
586
|
+
/**
|
|
587
|
+
* Look up a registered format plugin by id.
|
|
588
|
+
*/
|
|
589
|
+
declare function getFormatPlugin(id: string): FormatPlugin | undefined;
|
|
590
|
+
/**
|
|
591
|
+
* Look up a format plugin by id, or throw a consistent error if it is not
|
|
592
|
+
* registered. Use this from CLI commands where a missing plugin is always
|
|
593
|
+
* user-visible.
|
|
594
|
+
*/
|
|
595
|
+
declare function requireFormatPlugin(id: string): FormatPlugin;
|
|
596
|
+
/**
|
|
597
|
+
* List all registered format plugins.
|
|
598
|
+
*/
|
|
599
|
+
declare function listFormatPlugins(): FormatPlugin[];
|
|
600
|
+
/**
|
|
601
|
+
* Remove a plugin from the registry.
|
|
602
|
+
*
|
|
603
|
+
* Intended for tests only. Returns true if an entry was removed.
|
|
604
|
+
*/
|
|
605
|
+
declare function unregisterFormatPlugin(id: string): boolean;
|
|
606
|
+
/**
|
|
607
|
+
* Clear the registry completely.
|
|
608
|
+
*
|
|
609
|
+
* Intended for tests only.
|
|
610
|
+
*/
|
|
611
|
+
declare function clearFormatRegistry(): void;
|
|
612
|
+
//#endregion
|
|
613
|
+
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 };
|
|
614
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +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;;;;;UAM/B;EACf;EACA;EACA;;;;;UAMe;EACf;;EAEA;EACA;;;;;;;;UAae;;WAEN;;EAGT,KAAK,kBAAkB;;EAGvB,KAAK,eAAe;;EAGpB,WAAW,eAAe,QAAQ;;EAGlC,OAAO,eAAe;;EAGtB,QAAQ,eAAe;;;;;;;;UASR;;EAEf;;EAGA;;EAGA,gBAAgB,SAAS,eAAe;;EAGxC,sBAAsB,SAAS,eAAe;;;;;UAM/B;;EAEf;;;;;UAMe;EACf;EACA,SAAS;EACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAkCe;WACN;WACA;WACA;;WAGA;;;;IAIP,YAAY,MAAM;;;;IAKlB,qBAAqB;;;WAId;;;;;;;;;IASP,OACE,QAAQ,WACR,oBACA,SAAS,gBACR,QAAQ;;;;;;;;;;;;IAaX,QACE;MAAa;MAAe;MAAc;OAC1C,oBACA,SAAS,gBACR,QAAQ;;;;;;;;;;;;;;;;IAiBX,QACE,UAAU,UACV,iBACA,UAAU,gBACT,eAAe;;;WAIX;;IAEP,aAAa,qBAAqB;;IAGlC,cAAc,qBAAqB;;;;;;;KAY3B,sBAAsB;;;;;;;;;;;;;UC3PjB;;;;;EAKf;;;;EAKA;;;;EAKA;;;;EAKA;;;;;UAMe;;;;;;EAMf;;;;EAKA;;;;EAKA;;;;;UAMe;;;;EAIf;;;;EAKA,QAAQ;;;;EAKR,QAAQ;;;;;;;EAQR,qBAAqB;;;;;;EAOrB;;;;;UAMe;EACf,MAAM,oBAAoB;EAC1B,KAAK,oBAAoB;EACzB,KAAK,oBAAoB;EACzB,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;UA0BX;;;;;EAKf;;;;;EAMA;;;;EAKA;;;;EAKA,UAAU;;;;EAKV,YAAY;;;;;EAMZ,cAAc;;;;;;;EAQd,SAAS,MAAM,yBAAyB,KAAK,aAAa;;;;;;UAO3C;;;;EAIf,SAAS;;;;;UAMM;;;;;;;;;;;;;EAaf;;;;GAKC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
//#region src/factory.ts
|
|
2
|
+
/**
|
|
3
|
+
* Create an ADT plugin with validation
|
|
4
|
+
*
|
|
5
|
+
* @param definition - Plugin definition
|
|
6
|
+
* @returns Validated plugin instance
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { createPlugin } from '@abapify/adt-plugin';
|
|
11
|
+
*
|
|
12
|
+
* export const myPlugin = createPlugin({
|
|
13
|
+
* name: 'myFormat',
|
|
14
|
+
* version: '1.0.0',
|
|
15
|
+
* description: 'My custom format plugin',
|
|
16
|
+
*
|
|
17
|
+
* registry: {
|
|
18
|
+
* isSupported: (type) => supportedTypes.includes(type),
|
|
19
|
+
* getSupportedTypes: () => supportedTypes,
|
|
20
|
+
* },
|
|
21
|
+
*
|
|
22
|
+
* format: {
|
|
23
|
+
* import: async (object, targetPath, context) => {
|
|
24
|
+
* // Implementation
|
|
25
|
+
* return { success: true, filesCreated: [] };
|
|
26
|
+
* },
|
|
27
|
+
* },
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
function createPlugin(definition) {
|
|
32
|
+
if (!definition.name) throw new Error("Plugin name is required");
|
|
33
|
+
if (!definition.version) throw new Error("Plugin version is required");
|
|
34
|
+
if (!definition.registry) throw new Error("Plugin registry is required");
|
|
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");
|
|
37
|
+
return definition;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/lib/format/format-plugin.ts
|
|
42
|
+
var FormatMaterializationError = class extends Error {
|
|
43
|
+
code;
|
|
44
|
+
name = "FormatMaterializationError";
|
|
45
|
+
constructor(code, message) {
|
|
46
|
+
super(message);
|
|
47
|
+
this.code = code;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/lib/format/format-registry.ts
|
|
53
|
+
const REGISTRY_KEY = Symbol.for("@abapify/adt-plugin/format-registry");
|
|
54
|
+
function getStore() {
|
|
55
|
+
const g = globalThis;
|
|
56
|
+
let store = g[REGISTRY_KEY];
|
|
57
|
+
if (!store) {
|
|
58
|
+
store = { plugins: /* @__PURE__ */ new Map() };
|
|
59
|
+
g[REGISTRY_KEY] = store;
|
|
60
|
+
}
|
|
61
|
+
return store;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Register a format plugin.
|
|
65
|
+
*
|
|
66
|
+
* Idempotent for the same plugin instance: registering the same object twice
|
|
67
|
+
* is a no-op (guards against dual-module-graph evaluation during tests /
|
|
68
|
+
* bundler output). Registering a **different** plugin under an id that is
|
|
69
|
+
* already taken throws.
|
|
70
|
+
*/
|
|
71
|
+
function registerFormatPlugin(plugin) {
|
|
72
|
+
const store = getStore();
|
|
73
|
+
const existing = store.plugins.get(plugin.id);
|
|
74
|
+
if (existing) {
|
|
75
|
+
if (existing === plugin) return;
|
|
76
|
+
throw new Error(`Format plugin with id "${plugin.id}" is already registered (different instance).`);
|
|
77
|
+
}
|
|
78
|
+
store.plugins.set(plugin.id, plugin);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Look up a registered format plugin by id.
|
|
82
|
+
*/
|
|
83
|
+
function getFormatPlugin(id) {
|
|
84
|
+
return getStore().plugins.get(id);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Look up a format plugin by id, or throw a consistent error if it is not
|
|
88
|
+
* registered. Use this from CLI commands where a missing plugin is always
|
|
89
|
+
* user-visible.
|
|
90
|
+
*/
|
|
91
|
+
function requireFormatPlugin(id) {
|
|
92
|
+
const plugin = getFormatPlugin(id);
|
|
93
|
+
if (!plugin) {
|
|
94
|
+
const available = listFormatPlugins().map((p) => p.id).join(", ");
|
|
95
|
+
throw new Error(`Format plugin "${id}" is not registered. ` + (available ? `Available formats: ${available}.` : "No format plugins are currently registered."));
|
|
96
|
+
}
|
|
97
|
+
return plugin;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* List all registered format plugins.
|
|
101
|
+
*/
|
|
102
|
+
function listFormatPlugins() {
|
|
103
|
+
return [...getStore().plugins.values()];
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Remove a plugin from the registry.
|
|
107
|
+
*
|
|
108
|
+
* Intended for tests only. Returns true if an entry was removed.
|
|
109
|
+
*/
|
|
110
|
+
function unregisterFormatPlugin(id) {
|
|
111
|
+
return getStore().plugins.delete(id);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Clear the registry completely.
|
|
115
|
+
*
|
|
116
|
+
* Intended for tests only.
|
|
117
|
+
*/
|
|
118
|
+
function clearFormatRegistry() {
|
|
119
|
+
getStore().plugins.clear();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
//#endregion
|
|
123
|
+
export { FormatMaterializationError, clearFormatRegistry, createPlugin, getFormatPlugin, listFormatPlugins, registerFormatPlugin, requireFormatPlugin, unregisterFormatPlugin };
|
|
124
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abapify/adt-plugin",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
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.
|
|
22
|
+
"@abapify/adk": "0.4.3"
|
|
23
23
|
},
|
|
24
24
|
"repository": {
|
|
25
25
|
"type": "git",
|