@focus-reactive/payload-plugin-translator 0.4.0 → 0.5.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.
Files changed (87) hide show
  1. package/README.md +44 -29
  2. package/dist/client/shared/ui/Button/Button.d.ts +4 -4
  3. package/dist/client/shared/ui/Button/Button.js +18 -18
  4. package/dist/client/shared/ui/Button/styles.module.scss +1 -1
  5. package/dist/client/shared/ui/Popup/Popup.d.ts +10 -4
  6. package/dist/client/shared/ui/Popup/Popup.js +4 -3
  7. package/dist/client/shared/ui/Select/Select.d.ts +9 -7
  8. package/dist/client/shared/ui/Select/Select.js +18 -17
  9. package/dist/client/shared/ui/Select/styles.module.scss +5 -0
  10. package/dist/index.d.ts +16 -14
  11. package/dist/index.js +9 -7
  12. package/dist/plugin.d.ts +15 -4
  13. package/dist/plugin.js +34 -57
  14. package/dist/server/features/cancel/handler.d.ts +2 -2
  15. package/dist/server/features/cancel/handler.js +3 -1
  16. package/dist/server/features/cancel/route.d.ts +4 -4
  17. package/dist/server/features/cancel/route.js +4 -4
  18. package/dist/server/features/cancel-by-collection/handler.d.ts +3 -3
  19. package/dist/server/features/cancel-by-collection/handler.js +1 -1
  20. package/dist/server/features/cancel-by-collection/route.d.ts +5 -5
  21. package/dist/server/features/cancel-by-collection/route.js +4 -4
  22. package/dist/server/features/createTranslationRoutes.d.ts +23 -0
  23. package/dist/server/features/createTranslationRoutes.js +27 -0
  24. package/dist/server/features/enqueue-translation/handler.d.ts +3 -3
  25. package/dist/server/features/enqueue-translation/handler.js +1 -1
  26. package/dist/server/features/enqueue-translation/route.d.ts +5 -5
  27. package/dist/server/features/enqueue-translation/route.js +4 -4
  28. package/dist/server/features/get-collection-status/handler.d.ts +3 -3
  29. package/dist/server/features/get-collection-status/handler.js +1 -1
  30. package/dist/server/features/get-collection-status/route.d.ts +5 -5
  31. package/dist/server/features/get-collection-status/route.js +4 -4
  32. package/dist/server/features/get-document-status/handler.d.ts +3 -3
  33. package/dist/server/features/get-document-status/handler.js +1 -1
  34. package/dist/server/features/get-document-status/route.d.ts +5 -5
  35. package/dist/server/features/get-document-status/route.js +4 -4
  36. package/dist/server/features/index.d.ts +7 -6
  37. package/dist/server/features/index.js +7 -6
  38. package/dist/server/features/run-translation/handler.d.ts +2 -2
  39. package/dist/server/features/run-translation/route.d.ts +4 -4
  40. package/dist/server/features/run-translation/route.js +4 -4
  41. package/dist/server/features/translate-document/handler.js +7 -11
  42. package/dist/server/features/translate-field/resolveFieldSubtree.d.ts +31 -0
  43. package/dist/server/features/translate-field/resolveFieldSubtree.js +45 -0
  44. package/dist/server/modules/task-runner/TaskRunnerProvider.interface.d.ts +18 -1
  45. package/dist/server/modules/task-runner/index.d.ts +6 -6
  46. package/dist/server/modules/task-runner/index.js +2 -2
  47. package/dist/server/modules/task-runner/payload-jobs-runner/PayloadJobsRunnerProvider.d.ts +16 -1
  48. package/dist/server/modules/task-runner/payload-jobs-runner/PayloadJobsRunnerProvider.js +16 -1
  49. package/dist/server/modules/task-runner/sync-runner/SyncRunnerProvider.d.ts +18 -10
  50. package/dist/server/modules/task-runner/sync-runner/SyncRunnerProvider.js +24 -14
  51. package/dist/server/modules/translation-levels/PluginConfigBuilder.d.ts +46 -0
  52. package/dist/server/modules/translation-levels/PluginConfigBuilder.js +108 -0
  53. package/dist/server/modules/translation-levels/collectionLevel.d.ts +15 -0
  54. package/dist/server/modules/translation-levels/collectionLevel.js +24 -0
  55. package/dist/server/modules/translation-levels/documentLevel.d.ts +19 -0
  56. package/dist/server/modules/translation-levels/documentLevel.js +28 -0
  57. package/dist/server/modules/translation-levels/index.d.ts +3 -0
  58. package/dist/server/modules/translation-levels/index.js +4 -0
  59. package/dist/server/modules/translation-levels/types.d.ts +42 -0
  60. package/dist/server/modules/translation-levels/types.js +10 -0
  61. package/dist/server/modules/translation-levels/useDocTranslationApi.d.ts +8 -0
  62. package/dist/server/modules/translation-levels/useDocTranslationApi.js +18 -0
  63. package/dist/server/modules/translation-pipeline/index.d.ts +5 -3
  64. package/dist/server/modules/translation-pipeline/index.js +3 -2
  65. package/dist/server/modules/translation-pipeline/stages/data-reconciler/DataReconciler.d.ts +3 -9
  66. package/dist/server/modules/translation-pipeline/stages/data-reconciler/DataReconciler.js +71 -78
  67. package/dist/server/modules/translation-pipeline/stages/field-collector/FieldChunkCollector.d.ts +11 -22
  68. package/dist/server/modules/translation-pipeline/stages/field-collector/FieldChunkCollector.js +85 -106
  69. package/dist/server/modules/translation-pipeline/translateContent.d.ts +35 -0
  70. package/dist/server/modules/translation-pipeline/translateContent.js +30 -0
  71. package/dist/server/modules/translation-providers/OpenAITranslation.provider.d.ts +4 -3
  72. package/dist/server/modules/translation-providers/OpenAITranslation.provider.js +15 -15
  73. package/dist/server/shared/field-traversal/findFieldByPath.d.ts +40 -0
  74. package/dist/server/shared/field-traversal/findFieldByPath.js +88 -0
  75. package/dist/server/shared/field-traversal/index.d.ts +5 -0
  76. package/dist/server/shared/field-traversal/index.js +5 -0
  77. package/dist/server/shared/field-traversal/kernel.d.ts +85 -0
  78. package/dist/server/shared/field-traversal/kernel.js +145 -0
  79. package/dist/server/shared/field-traversal/types.d.ts +191 -0
  80. package/dist/server/shared/field-traversal/types.js +41 -0
  81. package/dist/server/shared/field-traversal/walkFields.d.ts +51 -0
  82. package/dist/server/shared/field-traversal/walkFields.js +164 -0
  83. package/dist/server/shared/utils/filterLocalizedFields.d.ts +3 -3
  84. package/dist/server/shared/utils/filterLocalizedFields.js +52 -63
  85. package/dist/types/AccessGuard.d.ts +24 -1
  86. package/dist/types/AccessGuard.js +12 -1
  87. package/package.json +2 -2
@@ -1,7 +1,7 @@
1
- import type { Config, Payload } from 'payload';
2
- import type { TaskRunner } from '../TaskRunner.interface';
3
- import type { TaskRunnerProvider, TaskRunnerContext } from '../TaskRunnerProvider.interface';
4
- import type { SyncRunnerOptions } from './types';
1
+ import type { Config, Payload } from "payload";
2
+ import type { TaskRunner } from "../TaskRunner.interface";
3
+ import type { TaskRunnerProvider, TaskHandler } from "../TaskRunnerProvider.interface";
4
+ import type { SyncRunnerOptions } from "./types";
5
5
  /**
6
6
  * Synchronous TaskRunnerProvider implementation.
7
7
  *
@@ -9,16 +9,24 @@ import type { SyncRunnerOptions } from './types';
9
9
  * Useful for development, testing, or simple use cases.
10
10
  */
11
11
  export declare class SyncRunnerProvider implements TaskRunnerProvider {
12
- private handler?;
13
12
  private readonly tasks;
14
13
  constructor(options?: SyncRunnerOptions);
15
- create(payload: Payload): TaskRunner;
16
- configure(context: TaskRunnerContext): (config: Config) => Config;
14
+ create(payload: Payload, handler: TaskHandler): TaskRunner;
15
+ configure(): (config: Config) => Config;
17
16
  }
18
17
  /**
19
- * Creates a synchronous TaskRunnerProvider.
18
+ * Creates a synchronous task runner: translations execute inline on enqueue,
19
+ * with no Payload Jobs queue. Status is kept in an in-memory map (bounded by
20
+ * `maxSize`/`ttlMs`) and is **lost on server restart**, so this is best for
21
+ * development, tests, or simple single-process setups — not serverless. Pass the
22
+ * result as `translatorPlugin({ runner })`.
20
23
  *
21
- * Executes translations immediately without queuing.
22
- * Results are stored in memory and lost on server restart.
24
+ * @param options - In-memory store bounds: `maxSize` (default 100) and `ttlMs`
25
+ * (default 1h) for completed/failed task records.
26
+ * @returns A {@link TaskRunnerProvider} for the plugin's `runner` option.
27
+ * @example
28
+ * ```ts
29
+ * translatorPlugin({ collections, translationProvider, runner: createSyncRunner() })
30
+ * ```
23
31
  */
24
32
  export declare function createSyncRunner(options?: SyncRunnerOptions): TaskRunnerProvider;
@@ -1,15 +1,13 @@
1
- import { SyncTaskRunner } from './SyncTaskRunner';
2
- import { LazyMap } from '../../../shared/utils';
1
+ import { SyncTaskRunner } from "./SyncTaskRunner";
2
+ import { LazyMap } from "../../../shared/utils";
3
3
  const DEFAULT_MAX_SIZE = 100;
4
- const DEFAULT_TTL_MS = 60 * 60 * 1000 // 1 hour
5
- ;
4
+ const DEFAULT_TTL_MS = 60 * 60 * 1000; // 1 hour
6
5
  /**
7
6
  * Synchronous TaskRunnerProvider implementation.
8
7
  *
9
8
  * Executes translations immediately without Payload Jobs.
10
9
  * Useful for development, testing, or simple use cases.
11
10
  */ export class SyncRunnerProvider {
12
- handler;
13
11
  tasks;
14
12
  constructor(options){
15
13
  const maxSize = options?.maxSize ?? DEFAULT_MAX_SIZE;
@@ -17,24 +15,36 @@ const DEFAULT_TTL_MS = 60 * 60 * 1000 // 1 hour
17
15
  this.tasks = new LazyMap({
18
16
  maxSize,
19
17
  ttlMs,
20
- isRemovable: (task)=>task.status === 'completed' || task.status === 'failed',
18
+ isRemovable: (task)=>task.status === "completed" || task.status === "failed",
21
19
  getTimestamp: (task)=>new Date(task.updatedAt).getTime()
22
20
  });
23
21
  }
24
- create(payload) {
25
- if (!this.handler) throw new Error('SyncRunnerProvider not configured. Call configure() first.');
26
- return new SyncTaskRunner(payload, this.handler, this.tasks);
22
+ // SyncRunner executes the translation inline on enqueue, so it needs the
23
+ // handler at create time taken from the caller-supplied argument rather than
24
+ // stashed on the instance during configure(). No ambient state, no ordering
25
+ // coupling: create() is a pure function of its arguments.
26
+ create(payload, handler) {
27
+ return new SyncTaskRunner(payload, handler, this.tasks);
27
28
  }
28
- configure(context) {
29
- this.handler = context.handler;
29
+ // No config changes needed — translations run synchronously, no Payload jobs.
30
+ configure() {
30
31
  return (config)=>config;
31
32
  }
32
33
  }
33
34
  /**
34
- * Creates a synchronous TaskRunnerProvider.
35
+ * Creates a synchronous task runner: translations execute inline on enqueue,
36
+ * with no Payload Jobs queue. Status is kept in an in-memory map (bounded by
37
+ * `maxSize`/`ttlMs`) and is **lost on server restart**, so this is best for
38
+ * development, tests, or simple single-process setups — not serverless. Pass the
39
+ * result as `translatorPlugin({ runner })`.
35
40
  *
36
- * Executes translations immediately without queuing.
37
- * Results are stored in memory and lost on server restart.
41
+ * @param options - In-memory store bounds: `maxSize` (default 100) and `ttlMs`
42
+ * (default 1h) for completed/failed task records.
43
+ * @returns A {@link TaskRunnerProvider} for the plugin's `runner` option.
44
+ * @example
45
+ * ```ts
46
+ * translatorPlugin({ collections, translationProvider, runner: createSyncRunner() })
47
+ * ```
38
48
  */ export function createSyncRunner(options) {
39
49
  return new SyncRunnerProvider(options);
40
50
  }
@@ -0,0 +1,46 @@
1
+ import type { CollectionConfig, Config, Endpoint } from "payload";
2
+ import type { AccessGuard } from "../../../types/AccessGuard";
3
+ import type { RawPayloadComponentExport } from "../../../client/shared/types/PayloadComponentExport";
4
+ import type { TaskRunnerFactory } from "../task-runner";
5
+ import type { CollectionAdminSlot, LevelContext } from "./types";
6
+ type ConfigModifier = (config: Config) => Config;
7
+ export type PluginConfigBuilderDeps = {
8
+ collections: CollectionConfig[];
9
+ basePath: string;
10
+ access?: AccessGuard;
11
+ taskRunnerFactory: TaskRunnerFactory;
12
+ };
13
+ /**
14
+ * The single place that mutates the Payload `config`. Levels (through the narrow
15
+ * {@link LevelContext}) and the plugin (through `addAdminProvider` /
16
+ * `addConfigModifier`) only *describe* their contributions; `applyTo(config)` is
17
+ * the one sink that writes them in. This keeps Payload's in-place-mutation style
18
+ * — including the lazy nested-config init — confined here, so `plugin.ts` and the
19
+ * levels stay free of direct config mutation.
20
+ *
21
+ * It implements {@link LevelContext}, so the same instance is what levels receive
22
+ * as their context (they see only `addEndpoints` / `addCollectionComponent`).
23
+ */
24
+ export declare class PluginConfigBuilder implements LevelContext {
25
+ readonly collections: CollectionConfig[];
26
+ readonly basePath: string;
27
+ readonly access?: AccessGuard;
28
+ readonly taskRunnerFactory: TaskRunnerFactory;
29
+ private readonly endpoints;
30
+ private readonly collectionComponents;
31
+ private readonly adminProviders;
32
+ private readonly configModifiers;
33
+ constructor(deps: PluginConfigBuilderDeps);
34
+ addEndpoints(endpoints: Endpoint[]): void;
35
+ addCollectionComponent(slot: CollectionAdminSlot, make: (collection: CollectionConfig) => RawPayloadComponentExport): void;
36
+ /** Register a global admin provider (e.g. the client cache provider). */
37
+ addAdminProvider(provider: RawPayloadComponentExport): void;
38
+ /** Register a config modifier (e.g. the runner's jobs/autorun/onInit setup). */
39
+ addConfigModifier(modifier: ConfigModifier): void;
40
+ /** The one sink that writes every accumulated contribution into `config`. */
41
+ applyTo(config: Config): Config;
42
+ private attachAdminProviders;
43
+ private attachCollectionComponents;
44
+ private registerEndpoints;
45
+ }
46
+ export {};
@@ -0,0 +1,108 @@
1
+ const endpointKey = (endpoint)=>`${endpoint.method} ${endpoint.path}`;
2
+ function attachToSlot(collection, slot, component) {
3
+ if (!collection.admin) collection.admin = {};
4
+ if (!collection.admin.components) collection.admin.components = {};
5
+ const components = collection.admin.components;
6
+ if (slot === "beforeDocumentControls") {
7
+ if (!components.edit) components.edit = {};
8
+ if (!components.edit.beforeDocumentControls) components.edit.beforeDocumentControls = [];
9
+ components.edit.beforeDocumentControls.push(component);
10
+ return;
11
+ }
12
+ if (slot === "beforeListTable") {
13
+ if (!components.beforeListTable) components.beforeListTable = [];
14
+ components.beforeListTable.push(component);
15
+ return;
16
+ }
17
+ // Exhaustiveness: a new CollectionAdminSlot must be handled above, not fall through.
18
+ slot;
19
+ }
20
+ /**
21
+ * The single place that mutates the Payload `config`. Levels (through the narrow
22
+ * {@link LevelContext}) and the plugin (through `addAdminProvider` /
23
+ * `addConfigModifier`) only *describe* their contributions; `applyTo(config)` is
24
+ * the one sink that writes them in. This keeps Payload's in-place-mutation style
25
+ * — including the lazy nested-config init — confined here, so `plugin.ts` and the
26
+ * levels stay free of direct config mutation.
27
+ *
28
+ * It implements {@link LevelContext}, so the same instance is what levels receive
29
+ * as their context (they see only `addEndpoints` / `addCollectionComponent`).
30
+ */ export class PluginConfigBuilder {
31
+ collections;
32
+ basePath;
33
+ access;
34
+ taskRunnerFactory;
35
+ endpoints = [];
36
+ collectionComponents = [];
37
+ adminProviders = [];
38
+ configModifiers = [];
39
+ constructor(deps){
40
+ this.collections = deps.collections;
41
+ this.basePath = deps.basePath;
42
+ this.access = deps.access;
43
+ this.taskRunnerFactory = deps.taskRunnerFactory;
44
+ }
45
+ addEndpoints(endpoints) {
46
+ this.endpoints.push(...endpoints);
47
+ }
48
+ addCollectionComponent(slot, make) {
49
+ this.collectionComponents.push({
50
+ slot,
51
+ make
52
+ });
53
+ }
54
+ /** Register a global admin provider (e.g. the client cache provider). */ addAdminProvider(provider) {
55
+ this.adminProviders.push(provider);
56
+ }
57
+ /** Register a config modifier (e.g. the runner's jobs/autorun/onInit setup). */ addConfigModifier(modifier) {
58
+ this.configModifiers.push(modifier);
59
+ }
60
+ /** The one sink that writes every accumulated contribution into `config`. */ applyTo(config) {
61
+ // Config modifiers first — a runner's modifier may return a fresh config
62
+ // object, so everything else must be applied to its result.
63
+ let result = config;
64
+ for (const modify of this.configModifiers)result = modify(result);
65
+ this.attachAdminProviders(result);
66
+ this.attachCollectionComponents(result);
67
+ this.registerEndpoints(result);
68
+ return result;
69
+ }
70
+ attachAdminProviders(config) {
71
+ if (this.adminProviders.length === 0) return;
72
+ if (!config.admin) config.admin = {};
73
+ if (!config.admin.components) config.admin.components = {};
74
+ if (!config.admin.components.providers) config.admin.components.providers = [];
75
+ // Not deduplicated. Unlike a duplicate endpoint (a route conflict), a
76
+ // duplicate admin provider is harmless, and providers have no reliable
77
+ // identity key across their shapes (`string | { path } | false`, with
78
+ // distinguishing `serverProps`). The single CacheProvider is added once per
79
+ // plugin instance.
80
+ config.admin.components.providers.push(...this.adminProviders);
81
+ }
82
+ attachCollectionComponents(config) {
83
+ if (this.collectionComponents.length === 0) return;
84
+ const managed = new Set(this.collections.map((collection)=>collection.slug));
85
+ config.collections?.forEach((collection)=>{
86
+ if (!managed.has(collection.slug)) return;
87
+ for (const { slot, make } of this.collectionComponents){
88
+ attachToSlot(collection, slot, make(collection));
89
+ }
90
+ });
91
+ }
92
+ registerEndpoints(config) {
93
+ if (this.endpoints.length === 0) return;
94
+ if (!config.endpoints) config.endpoints = [];
95
+ // Seed from endpoints already on the config so each (method, path) registers
96
+ // once — across the levels' contributions AND anything already present (e.g.
97
+ // the plugin registered twice, or a host route at the same path).
98
+ const seen = new Set(config.endpoints.map(endpointKey));
99
+ for (const endpoint of this.endpoints){
100
+ const key = endpointKey(endpoint);
101
+ if (seen.has(key)) continue;
102
+ seen.add(key);
103
+ config.endpoints.push(endpoint);
104
+ }
105
+ }
106
+ }
107
+
108
+ //# sourceMappingURL=PluginConfigBuilder.js.map
@@ -0,0 +1,15 @@
1
+ import type { TranslationLevel } from "./types";
2
+ /**
3
+ * Bulk collection translation: a dashboard on the list view (translate many
4
+ * documents at once), backed by the same shared document-translation API as
5
+ * {@link documentLevel}.
6
+ *
7
+ * @since 0.5.0
8
+ * @returns An opaque {@link TranslationLevel} to list in `translatorPlugin({ levels })`.
9
+ * @example
10
+ * ```ts
11
+ * // Enable only bulk collection translation (no per-document popup):
12
+ * translatorPlugin({ collections: [Posts], translationProvider, runner, levels: [collectionLevel()] })
13
+ * ```
14
+ */
15
+ export declare function collectionLevel(): TranslationLevel;
@@ -0,0 +1,24 @@
1
+ import { BulkDocumentTranslationDashboard } from "../../../client/widgets/bulk-translation-dashboard/ui/BulkTranslationDashboard.export";
2
+ import { useDocTranslationApi } from "./useDocTranslationApi";
3
+ /**
4
+ * Bulk collection translation: a dashboard on the list view (translate many
5
+ * documents at once), backed by the same shared document-translation API as
6
+ * {@link documentLevel}.
7
+ *
8
+ * @since 0.5.0
9
+ * @returns An opaque {@link TranslationLevel} to list in `translatorPlugin({ levels })`.
10
+ * @example
11
+ * ```ts
12
+ * // Enable only bulk collection translation (no per-document popup):
13
+ * translatorPlugin({ collections: [Posts], translationProvider, runner, levels: [collectionLevel()] })
14
+ * ```
15
+ */ export function collectionLevel() {
16
+ return {
17
+ extend (ctx) {
18
+ useDocTranslationApi(ctx);
19
+ ctx.addCollectionComponent("beforeListTable", ()=>new BulkDocumentTranslationDashboard(ctx.access));
20
+ }
21
+ };
22
+ }
23
+
24
+ //# sourceMappingURL=collectionLevel.js.map
@@ -0,0 +1,19 @@
1
+ import type { TranslationLevel } from "./types";
2
+ /**
3
+ * Per-document translation: a popup control on the document edit view, backed by
4
+ * the shared document-translation API (async/job by default; synchronous if the
5
+ * configured `runner` is a sync runner).
6
+ *
7
+ * @since 0.5.0
8
+ * @returns An opaque {@link TranslationLevel} to list in `translatorPlugin({ levels })`.
9
+ * @example
10
+ * ```ts
11
+ * translatorPlugin({
12
+ * collections: [Posts],
13
+ * translationProvider,
14
+ * runner: createPayloadJobsRunner(),
15
+ * levels: [documentLevel(), collectionLevel()], // this is the default — omit for the same result
16
+ * })
17
+ * ```
18
+ */
19
+ export declare function documentLevel(): TranslationLevel;
@@ -0,0 +1,28 @@
1
+ import { TranslateDocumentExport } from "../../../client/widgets/translate-document";
2
+ import { useDocTranslationApi } from "./useDocTranslationApi";
3
+ /**
4
+ * Per-document translation: a popup control on the document edit view, backed by
5
+ * the shared document-translation API (async/job by default; synchronous if the
6
+ * configured `runner` is a sync runner).
7
+ *
8
+ * @since 0.5.0
9
+ * @returns An opaque {@link TranslationLevel} to list in `translatorPlugin({ levels })`.
10
+ * @example
11
+ * ```ts
12
+ * translatorPlugin({
13
+ * collections: [Posts],
14
+ * translationProvider,
15
+ * runner: createPayloadJobsRunner(),
16
+ * levels: [documentLevel(), collectionLevel()], // this is the default — omit for the same result
17
+ * })
18
+ * ```
19
+ */ export function documentLevel() {
20
+ return {
21
+ extend (ctx) {
22
+ useDocTranslationApi(ctx);
23
+ ctx.addCollectionComponent("beforeDocumentControls", (collection)=>new TranslateDocumentExport(collection, ctx.access));
24
+ }
25
+ };
26
+ }
27
+
28
+ //# sourceMappingURL=documentLevel.js.map
@@ -0,0 +1,3 @@
1
+ export type { TranslationLevel } from "./types";
2
+ export { documentLevel } from "./documentLevel";
3
+ export { collectionLevel } from "./collectionLevel";
@@ -0,0 +1,4 @@
1
+ export { documentLevel } from "./documentLevel";
2
+ export { collectionLevel } from "./collectionLevel";
3
+
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,42 @@
1
+ import type { CollectionConfig, Endpoint } from "payload";
2
+ import type { AccessGuard } from "../../../types/AccessGuard";
3
+ import type { RawPayloadComponentExport } from "../../../client/shared/types/PayloadComponentExport";
4
+ import type { TaskRunnerFactory } from "../task-runner";
5
+ export type CollectionAdminSlot = "beforeDocumentControls" | "beforeListTable";
6
+ /**
7
+ * A composable translation surface (document / collection / field).
8
+ *
9
+ * Treat it as an **opaque value**: create one with `documentLevel()` /
10
+ * `collectionLevel()` (and, later, `fieldLevel()`) and list it in
11
+ * `translatorPlugin({ levels })`. It is produced only by those built-in
12
+ * factories — not externally implementable yet, since {@link LevelContext} is
13
+ * intentionally not exported. Opening it later (export `LevelContext`, drop the
14
+ * `@internal` tag) is additive and non-breaking.
15
+ *
16
+ * @since 0.5.0
17
+ */
18
+ export interface TranslationLevel {
19
+ /**
20
+ * Not a stable contract yet — produce via the level factories.
21
+ * @internal
22
+ */
23
+ extend(ctx: LevelContext): void;
24
+ }
25
+ /**
26
+ * Public-ready shape, kept internal until external levels are needed.
27
+ *
28
+ * A level contributes via these generic primitives; it never mutates the raw
29
+ * Payload config. The plugin deduplicates endpoints by method + path on apply.
30
+ * (fieldLevel — Phase 2 — will also read `schemaMap` + `translationProvider`.)
31
+ * @internal
32
+ */
33
+ export interface LevelContext {
34
+ readonly collections: CollectionConfig[];
35
+ readonly basePath: string;
36
+ readonly access?: AccessGuard;
37
+ readonly taskRunnerFactory: TaskRunnerFactory;
38
+ /** Register endpoints. Deduplicated by method + path when applied. */
39
+ addEndpoints(endpoints: Endpoint[]): void;
40
+ /** Attach an admin component to a slot on every managed collection. */
41
+ addCollectionComponent(slot: CollectionAdminSlot, make: (collection: CollectionConfig) => RawPayloadComponentExport): void;
42
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Public-ready shape, kept internal until external levels are needed.
3
+ *
4
+ * A level contributes via these generic primitives; it never mutates the raw
5
+ * Payload config. The plugin deduplicates endpoints by method + path on apply.
6
+ * (fieldLevel — Phase 2 — will also read `schemaMap` + `translationProvider`.)
7
+ * @internal
8
+ */ export { };
9
+
10
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,8 @@
1
+ import type { LevelContext } from "./types";
2
+ /**
3
+ * Contribute the runner-agnostic document-translation API — the shared 6-route
4
+ * bundle, bound to the level context's runner. Both `documentLevel` and
5
+ * `collectionLevel` call this; the plugin deduplicates the endpoints by method +
6
+ * path, so the bundle registers exactly once.
7
+ */
8
+ export declare function useDocTranslationApi(ctx: LevelContext): void;
@@ -0,0 +1,18 @@
1
+ import { createTranslationRoutes } from "../../features/createTranslationRoutes";
2
+ /**
3
+ * Contribute the runner-agnostic document-translation API — the shared 6-route
4
+ * bundle, bound to the level context's runner. Both `documentLevel` and
5
+ * `collectionLevel` call this; the plugin deduplicates the endpoints by method +
6
+ * path, so the bundle registers exactly once.
7
+ */ export function useDocTranslationApi(ctx) {
8
+ ctx.addEndpoints(createTranslationRoutes({
9
+ taskRunnerFactory: ctx.taskRunnerFactory,
10
+ collectionConfig: {
11
+ availableCollections: new Set(ctx.collections.map((collection)=>collection.slug))
12
+ },
13
+ access: ctx.access,
14
+ basePath: ctx.basePath
15
+ }));
16
+ }
17
+
18
+ //# sourceMappingURL=useDocTranslationApi.js.map
@@ -1,3 +1,5 @@
1
- export { TranslationPipeline } from './TranslationPipeline';
2
- export type { TranslationStrategy } from './strategies';
3
- export { OverwriteStrategy, SkipExistingStrategy } from './strategies';
1
+ export { TranslationPipeline } from "./TranslationPipeline";
2
+ export { translateContent } from "./translateContent";
3
+ export type { TranslateContentArgs } from "./translateContent";
4
+ export type { TranslationStrategy } from "./strategies";
5
+ export { OverwriteStrategy, SkipExistingStrategy } from "./strategies";
@@ -1,4 +1,5 @@
1
- export { TranslationPipeline } from './TranslationPipeline';
2
- export { OverwriteStrategy, SkipExistingStrategy } from './strategies';
1
+ export { TranslationPipeline } from "./TranslationPipeline";
2
+ export { translateContent } from "./translateContent";
3
+ export { OverwriteStrategy, SkipExistingStrategy } from "./strategies";
3
4
 
4
5
  //# sourceMappingURL=index.js.map
@@ -1,11 +1,7 @@
1
- import type { Field } from 'payload';
1
+ import type { Field } from "payload";
2
2
  /**
3
- * Deep merges source and target data with target priority.
4
- * Creates full document shape needed for Payload validation.
5
- *
6
- * Logic:
7
- * - If targetValue exists and is not empty → use targetValue
8
- * - Otherwise → use sourceValue
3
+ * Deep-merges source and target data with target priority, producing the full document shape
4
+ * Payload validation needs. Built on the shared {@link walkFields} engine.
9
5
  *
10
6
  * Stage 1 of the translation pipeline.
11
7
  */
@@ -14,12 +10,10 @@ export declare class DataReconciler {
14
10
  constructor(schema: Field[]);
15
11
  /**
16
12
  * Reconciles source and target data into a complete document shape.
17
- * The result contains all fields needed for Payload validation.
18
13
  *
19
14
  * @param sourceData - Source locale document data
20
15
  * @param targetData - Target locale document data (may be empty/partial)
21
16
  * @returns Complete document shape with reconciled field values
22
17
  */
23
18
  reconcile(sourceData: Record<string, unknown>, targetData: Record<string, unknown>): Record<string, unknown>;
24
- private reconcileFields;
25
19
  }