@abapify/adt-plugin 0.3.6 → 0.4.1

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