@abapify/adt-plugin 0.4.15 → 0.4.18
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/dist/index.d.mts +0 -10
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +3 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { AdkObject } from "@abapify/adk";
|
|
2
|
-
//#region src/types.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* ABAP object type code (e.g., 'CLAS', 'INTF', 'DOMA')
|
|
5
4
|
*/
|
|
@@ -201,8 +200,6 @@ interface AdtPlugin {
|
|
|
201
200
|
* Same as AdtPlugin but allows partial hooks
|
|
202
201
|
*/
|
|
203
202
|
type AdtPluginDefinition = AdtPlugin;
|
|
204
|
-
//#endregion
|
|
205
|
-
//#region src/cli-types.d.ts
|
|
206
203
|
/**
|
|
207
204
|
* CLI Command Plugin Types
|
|
208
205
|
*
|
|
@@ -381,8 +378,6 @@ interface AdtCliConfig {
|
|
|
381
378
|
*/
|
|
382
379
|
[key: string]: unknown;
|
|
383
380
|
}
|
|
384
|
-
//#endregion
|
|
385
|
-
//#region src/factory.d.ts
|
|
386
381
|
/**
|
|
387
382
|
* Create an ADT plugin with validation
|
|
388
383
|
*
|
|
@@ -413,8 +408,6 @@ interface AdtCliConfig {
|
|
|
413
408
|
* ```
|
|
414
409
|
*/
|
|
415
410
|
declare function createPlugin(definition: AdtPluginDefinition): AdtPlugin;
|
|
416
|
-
//#endregion
|
|
417
|
-
//#region src/lib/format/format-plugin.d.ts
|
|
418
411
|
/**
|
|
419
412
|
* FormatPlugin — interface for serialization-format plugins (abapGit, gCTS, AFF, …).
|
|
420
413
|
*
|
|
@@ -572,8 +565,6 @@ interface FormatPlugin {
|
|
|
572
565
|
/** Parse a format-specific filename, if the format defines one. */
|
|
573
566
|
parseFilename?(filename: string): ParsedFormatFilename | undefined;
|
|
574
567
|
}
|
|
575
|
-
//#endregion
|
|
576
|
-
//#region src/lib/format/format-registry.d.ts
|
|
577
568
|
/**
|
|
578
569
|
* Register a format plugin.
|
|
579
570
|
*
|
|
@@ -609,6 +600,5 @@ declare function unregisterFormatPlugin(id: string): boolean;
|
|
|
609
600
|
* Intended for tests only.
|
|
610
601
|
*/
|
|
611
602
|
declare function clearFormatRegistry(): void;
|
|
612
|
-
//#endregion
|
|
613
603
|
export { type AbapGitOutputFormat, type AbapObjectType, type AdtCliConfig, type AdtPlugin, type AdtPluginDefinition, type CliArgument, type CliCommandModule, type CliCommandPlugin, type CliContext, type CliLogger, type CliOption, type DeleteResult, type ExportContext, type ExportOptions, type ExportResult, type FileTree, type FormatHandler, type FormatHandlerSchema, FormatMaterializationError, type FormatMaterializationErrorCode, type FormatMaterializationInput, type FormatMaterializationResult, type FormatOptionValue, type FormatPlugin, type FormatSerializeOptions, type ImportContext, type ImportResult, type MaterializedFormatFile, type ParsedFormatFilename, type SerializedFile, clearFormatRegistry, createPlugin, getFormatPlugin, listFormatPlugins, registerFormatPlugin, requireFormatPlugin, unregisterFormatPlugin };
|
|
614
604
|
//# 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;;;;;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;;;;;;;;;;;;;;;;;;;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
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/factory.ts
|
|
2
2
|
/**
|
|
3
3
|
* Create an ADT plugin with validation
|
|
4
4
|
*
|
|
@@ -37,8 +37,7 @@ function createPlugin(definition) {
|
|
|
37
37
|
return definition;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
//#region src/lib/format/format-plugin.ts
|
|
40
|
+
// src/lib/format/format-plugin.ts
|
|
42
41
|
var FormatMaterializationError = class extends Error {
|
|
43
42
|
code;
|
|
44
43
|
name = "FormatMaterializationError";
|
|
@@ -48,8 +47,7 @@ var FormatMaterializationError = class extends Error {
|
|
|
48
47
|
}
|
|
49
48
|
};
|
|
50
49
|
|
|
51
|
-
|
|
52
|
-
//#region src/lib/format/format-registry.ts
|
|
50
|
+
// src/lib/format/format-registry.ts
|
|
53
51
|
const REGISTRY_KEY = Symbol.for("@abapify/adt-plugin/format-registry");
|
|
54
52
|
function getStore() {
|
|
55
53
|
const g = globalThis;
|
|
@@ -119,6 +117,5 @@ function clearFormatRegistry() {
|
|
|
119
117
|
getStore().plugins.clear();
|
|
120
118
|
}
|
|
121
119
|
|
|
122
|
-
//#endregion
|
|
123
120
|
export { FormatMaterializationError, clearFormatRegistry, createPlugin, getFormatPlugin, listFormatPlugins, registerFormatPlugin, requireFormatPlugin, unregisterFormatPlugin };
|
|
124
121
|
//# 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-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":";;;;;;;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,IAAI;EACZ,MAAM,IAAI,MACR,kBAAkB,GAAG,0BAClB,YACG,sBAAsB,UAAU,KAChC,8CACR;CACF;CACA,OAAO;AACT;;;;AAKA,SAAgB,oBAAoC;CAClD,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC,QAAQ,OAAO,CAAC;AACxC;;;;;;AAOA,SAAgB,uBAAuB,IAAqB;CAC1D,OAAO,SAAS,CAAC,CAAC,QAAQ,OAAO,EAAE;AACrC;;;;;;AAOA,SAAgB,sBAA4B;CAC1C,SAAS,CAAC,CAAC,QAAQ,MAAM;AAC3B"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/factory.ts","../src/lib/format/format-plugin.ts","../src/lib/format/format-registry.ts"],"sourcesContent":["/**\n * ADT Plugin Factory\n *\n * Factory function for creating ADT plugins with validation.\n */\n\nimport type { AdtPlugin, AdtPluginDefinition } from './types';\n\n/**\n * Create an ADT plugin with validation\n *\n * @param definition - Plugin definition\n * @returns Validated plugin instance\n *\n * @example\n * ```typescript\n * import { createPlugin } from '@abapify/adt-plugin';\n *\n * export const myPlugin = createPlugin({\n * name: 'myFormat',\n * version: '1.0.0',\n * description: 'My custom format plugin',\n *\n * registry: {\n * isSupported: (type) => supportedTypes.includes(type),\n * getSupportedTypes: () => supportedTypes,\n * },\n *\n * format: {\n * import: async (object, targetPath, context) => {\n * // Implementation\n * return { success: true, filesCreated: [] };\n * },\n * },\n * });\n * ```\n */\nexport function createPlugin(definition: AdtPluginDefinition): AdtPlugin {\n // Validate required fields\n if (!definition.name) {\n throw new Error('Plugin name is required');\n }\n if (!definition.version) {\n throw new Error('Plugin version is required');\n }\n if (!definition.registry) {\n throw new Error('Plugin registry is required');\n }\n if (!definition.format) {\n throw new Error('Plugin format is required');\n }\n if (typeof definition.format.import !== 'function') {\n throw new 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;C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B;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.18",
|
|
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.18"
|
|
23
23
|
},
|
|
24
24
|
"repository": {
|
|
25
25
|
"type": "git",
|