@abapify/adt-plugin 0.4.1 → 0.4.4
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 +57 -5
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +12 -1
- package/dist/index.mjs.map +1 -1
- 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
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { AdkObject } from "@abapify/adk";
|
|
2
|
-
|
|
3
2
|
//#region src/types.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* ABAP object type code (e.g., 'CLAS', 'INTF', 'DOMA')
|
|
@@ -191,7 +190,9 @@ interface AdtPlugin {
|
|
|
191
190
|
};
|
|
192
191
|
/** Lifecycle hooks */
|
|
193
192
|
readonly hooks?: {
|
|
194
|
-
/** Called after all objects have been imported */
|
|
193
|
+
/** Called after all objects have been imported */
|
|
194
|
+
afterImport?(targetPath: string): Promise<void>;
|
|
195
|
+
/** Called before export starts */
|
|
195
196
|
beforeExport?(sourcePath: string): Promise<void>;
|
|
196
197
|
};
|
|
197
198
|
}
|
|
@@ -274,7 +275,7 @@ interface CliContext {
|
|
|
274
275
|
*/
|
|
275
276
|
getAdtClient?: () => Promise<unknown>;
|
|
276
277
|
/**
|
|
277
|
-
* ADT system name for hyperlinks (e.g., "
|
|
278
|
+
* ADT system name for hyperlinks (e.g., "TRL")
|
|
278
279
|
* Used to construct adt:// protocol links.
|
|
279
280
|
* Only available when running within adt-cli context.
|
|
280
281
|
*/
|
|
@@ -447,6 +448,50 @@ interface SerializedFile {
|
|
|
447
448
|
/** Optional encoding (default: utf-8). */
|
|
448
449
|
encoding?: BufferEncoding;
|
|
449
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
|
+
}
|
|
450
495
|
/**
|
|
451
496
|
* Result of parsing a format-specific filename.
|
|
452
497
|
*
|
|
@@ -493,8 +538,10 @@ interface FormatHandler {
|
|
|
493
538
|
readonly schema: FormatHandlerSchema;
|
|
494
539
|
/** Optional map from abapGit file suffix to source key. */
|
|
495
540
|
readonly suffixToSourceKey?: Record<string, string>;
|
|
541
|
+
/** Whether this handler treats an explicit `sources` map as authoritative. */
|
|
542
|
+
readonly supportsExplicitSources?: boolean;
|
|
496
543
|
/** Serialize an ADK object to one or more files. */
|
|
497
|
-
serialize(object: unknown): Promise<SerializedFile[]>;
|
|
544
|
+
serialize(object: unknown, options?: FormatSerializeOptions): Promise<SerializedFile[]>;
|
|
498
545
|
/**
|
|
499
546
|
* Map format-specific XML values back to ADK data. Present only on
|
|
500
547
|
* handlers that support bidirectional (git → SAP) workflows.
|
|
@@ -517,6 +564,11 @@ interface FormatPlugin {
|
|
|
517
564
|
readonly supportedTypes: ReadonlyArray<string>;
|
|
518
565
|
/** Look up the handler for a given ABAP object type. */
|
|
519
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>;
|
|
520
572
|
/** Parse a format-specific filename, if the format defines one. */
|
|
521
573
|
parseFilename?(filename: string): ParsedFormatFilename | undefined;
|
|
522
574
|
}
|
|
@@ -558,5 +610,5 @@ declare function unregisterFormatPlugin(id: string): boolean;
|
|
|
558
610
|
*/
|
|
559
611
|
declare function clearFormatRegistry(): void;
|
|
560
612
|
//#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 };
|
|
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 };
|
|
562
614
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -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":";;;;;
|
|
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;;;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;;;;;;;;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
|
@@ -37,6 +37,17 @@ function createPlugin(definition) {
|
|
|
37
37
|
return definition;
|
|
38
38
|
}
|
|
39
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
|
+
|
|
40
51
|
//#endregion
|
|
41
52
|
//#region src/lib/format/format-registry.ts
|
|
42
53
|
const REGISTRY_KEY = Symbol.for("@abapify/adt-plugin/format-registry");
|
|
@@ -109,5 +120,5 @@ function clearFormatRegistry() {
|
|
|
109
120
|
}
|
|
110
121
|
|
|
111
122
|
//#endregion
|
|
112
|
-
export { clearFormatRegistry, createPlugin, getFormatPlugin, listFormatPlugins, registerFormatPlugin, requireFormatPlugin, unregisterFormatPlugin };
|
|
123
|
+
export { FormatMaterializationError, clearFormatRegistry, createPlugin, getFormatPlugin, listFormatPlugins, registerFormatPlugin, requireFormatPlugin, unregisterFormatPlugin };
|
|
113
124
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +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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AAO,UAAU,CAAC,QAAQ,OAAO,GAAG;;;;;;;AAQtC,SAAgB,sBAA4B;AAC1C,WAAU,CAAC,QAAQ,OAAO"}
|
|
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;CAI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": "0.4.4",
|
|
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.4"
|
|
23
23
|
},
|
|
24
24
|
"repository": {
|
|
25
25
|
"type": "git",
|