@justanarthur/payload-plugin-translator 1.3.21 → 3.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/jobs.d.ts CHANGED
@@ -1,186 +1,41 @@
1
1
  import { CollectionAfterChangeHook } from "payload";
2
2
  type CreateAutoTranslateCollectionHookOptions = {
3
- /**
4
- * The collection's slug. Used to populate the workflow's
5
- * `collection` input so the queued task targets the right entity.
6
- */
7
3
  collectionSlug: string;
8
- /**
9
- * Source-of-truth locale. The hook only fires when the request
10
- * is operating **in** this locale — edits to a non-default locale
11
- * don't fan out (those edits would be translations of translations).
12
- *
13
- * Falls back to `req.payload.config.localization.defaultLocale`
14
- * at request time when omitted.
15
- */
16
4
  defaultLocale?: string;
17
- /**
18
- * Target locales the workflow fans out to. Defaults to every
19
- * locale declared on `req.payload.config.localization.locales`
20
- * **except** the default locale.
21
- */
22
5
  targetLocales?: string[];
23
- /**
24
- * Only fan out when the doc is published. Default: `true`.
25
- * Keeps draft autosaves from triggering per-locale jobs.
26
- * Set `false` if your host treats drafts as valid translation
27
- * sources.
28
- */
29
6
  onlyOnPublished?: boolean;
30
- /**
31
- * Workflow slug the hook queues. Must match the slug of the
32
- * workflow registered in
33
- * `payload.config.ts → jobs: { workflows: [...] }`.
34
- * Default: `'translateEntityToLocales'`.
35
- */
36
7
  workflowSlug?: string;
37
- /**
38
- * Resolver key the queued task should call. Must match a `key`
39
- * declared in `translator({ resolvers: [...] })`. Default: the
40
- * first registered resolver's key (resolved at request time),
41
- * which the workflow forwards to the per-locale task as the
42
- * `resolver` input.
43
- */
44
8
  resolverKey?: string;
45
9
  };
46
- /**
47
- * Build a `CollectionAfterChangeHook` that schedules the
48
- * auto-translation workflow for every non-default locale.
49
- *
50
- * Skip rules (any one is sufficient):
51
- *
52
- * - `context.disableAutoTranslate` is set (lets seed scripts and
53
- * tests opt out).
54
- * - `req.locale` is missing or doesn't match `defaultLocale`.
55
- * - `req.user` is missing (system-initiated changes shouldn't
56
- * kick off LLM-billed jobs).
57
- * - `onlyOnPublished` (default `true`) is enabled and the doc's
58
- * `_status` is not `'published'`.
59
- * - The resolved target locale list is empty (e.g. single-locale
60
- * site).
61
- */
62
10
  declare function createAutoTranslateCollectionHook(options: CreateAutoTranslateCollectionHookOptions): {
63
11
  afterChange: CollectionAfterChangeHook;
64
12
  };
65
13
  import { GlobalAfterChangeHook } from "payload";
66
14
  type CreateAutoTranslateGlobalHookOptions = {
67
- /**
68
- * The global's slug. Used to populate the workflow's `global`
69
- * input so the queued task targets the right entity.
70
- */
71
15
  globalSlug: string;
72
- /**
73
- * Source-of-truth locale. The hook only fires when the request
74
- * is operating **in** this locale — edits to a non-default locale
75
- * don't fan out (those edits would be translations of translations).
76
- *
77
- * Falls back to `req.payload.config.localization.defaultLocale`
78
- * at request time when omitted.
79
- */
80
16
  defaultLocale?: string;
81
- /**
82
- * Target locales the workflow fans out to. Defaults to every
83
- * locale declared on `req.payload.config.localization.locales`
84
- * **except** the default locale.
85
- */
86
17
  targetLocales?: string[];
87
- /**
88
- * Workflow slug the hook queues. Must match the slug of the
89
- * workflow registered in
90
- * `payload.config.ts → jobs: { workflows: [...] }`.
91
- * Default: `'translateEntityToLocales'`.
92
- */
93
18
  workflowSlug?: string;
94
- /**
95
- * Resolver key the queued task should call. Must match a `key`
96
- * declared in `translator({ resolvers: [...] })`. Default: the
97
- * first registered resolver's key (resolved at request time),
98
- * which the workflow forwards to the per-locale task as the
99
- * `resolver` input.
100
- */
101
19
  resolverKey?: string;
102
20
  };
103
- /**
104
- * Build a `GlobalAfterChangeHook` that schedules the
105
- * auto-translation workflow for every non-default locale.
106
- *
107
- * Same skip rules as the collection hook factory **minus** the
108
- * `_status === 'published'` check (globals have no versioning —
109
- * every save is the canonical state). See
110
- * `createAutoTranslateCollectionHook` for the full rule list.
111
- */
112
21
  declare function createAutoTranslateGlobalHook(options: CreateAutoTranslateGlobalHookOptions): GlobalAfterChangeHook;
113
22
  import { TaskConfig, TaskHandler } from "payload";
114
23
  type TranslateTaskConfig = Omit<TaskConfig, "handler"> & {
115
24
  handler: TaskHandler<string, string>;
116
25
  };
117
26
  type CreateTranslateTaskOptions = {
118
- /**
119
- * Resolver key the upstream `translateOperation` should call.
120
- * Must match a `key` declared in the host's
121
- * `translator({ resolvers: [{ key: '<X>', resolve: ... }] })`.
122
- * Falls back to the first registered resolver's key when omitted.
123
- */
124
27
  resolverKey?: string;
125
- /**
126
- * Override the task slug. Default:
127
- * `'translateEntityToLocale'`.
128
- */
129
28
  slug?: string;
130
29
  };
131
- /**
132
- * Build the per-locale translation task.
133
- *
134
- * Behaviour:
135
- *
136
- * 1. Call `translateOperation` with
137
- * `emptyOnly: false, overrideAccess: true, update: false` so we
138
- * get a translated payload without the plugin writing back.
139
- * 2. Strip the synthetic `_locale` / `_parent_id` keys the plugin
140
- * attaches to the result.
141
- * 3. Persist via `req.payload.update` (collection) or
142
- * `req.payload.updateGlobal` (global) at `toLocale`, again with
143
- * `overrideAccess: true` so jobs run cleanly outside user
144
- * sessions.
145
- * 4. Fail loudly on any error — Payload retries the task up to
146
- * `retries` times before giving up.
147
- *
148
- * Hosts wire the returned task into
149
- * `payload.config.ts → jobs: { tasks: [<task>] }`.
150
- */
151
30
  declare function createTranslateTask(options?: CreateTranslateTaskOptions): TranslateTaskConfig;
152
31
  import { WorkflowConfig, WorkflowHandler } from "payload";
153
32
  type TranslateWorkflowConfig = Omit<WorkflowConfig, "handler"> & {
154
33
  handler: WorkflowHandler;
155
34
  };
156
35
  type CreateTranslateWorkflowOptions = {
157
- /**
158
- * Override the workflow slug. Default:
159
- * `'translateEntityToLocales'`.
160
- */
161
36
  slug?: string;
162
- /**
163
- * Override the per-locale task slug the workflow schedules.
164
- * Must match the slug passed to `createTranslateTask` on the
165
- * host's side. Default: `'translateEntityToLocale'`.
166
- */
167
37
  taskSlug?: string;
168
38
  };
169
- /**
170
- * Build the per-save translation workflow.
171
- *
172
- * The workflow receives one `entity + (fromLocale, toLocale, updatedAt)`
173
- * tuple per call and schedules **one** `translateEntityToLocale` task.
174
- * The `afterChange` hook factories fan out one call per non-default
175
- * locale so each task runs independently — one failing locale does
176
- * not block the others.
177
- *
178
- * The dedupe key (entity + locales + `updatedAt`) lets Payload collapse
179
- * duplicate jobs queued by rapid autosave bursts.
180
- *
181
- * Hosts wire the returned workflow into
182
- * `payload.config.ts → jobs: { workflows: [<workflow>] }`.
183
- */
184
39
  declare function createTranslateWorkflow(options?: CreateTranslateWorkflowOptions): TranslateWorkflowConfig;
185
40
  declare const TRANSLATE_TASK_SLUG = "translateEntityToLocale";
186
41
  declare const TRANSLATE_WORKFLOW_SLUG = "translateEntityToLocales";