@focus-reactive/payload-plugin-translator 0.2.0 → 0.3.0

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 (28) hide show
  1. package/dist/client/entities/translation/api/queries/useCollectionTranslationStatus.d.ts +77 -13
  2. package/dist/client/entities/translation/api/queries/useDocumentTranslation.d.ts +77 -13
  3. package/dist/client/features/collection-translation-form/model/schema.d.ts +2 -2
  4. package/dist/client/features/translate-document-form/model/schema.d.ts +3 -3
  5. package/dist/server/features/enqueue-translation/model.d.ts +4 -4
  6. package/dist/server/features/get-document-status/model.d.ts +1 -1
  7. package/dist/server/features/translate-document/handler.d.ts +4 -4
  8. package/dist/server/features/translate-document/handler.js +4 -4
  9. package/dist/server/features/translate-document/index.d.ts +2 -3
  10. package/dist/server/features/translate-document/index.js +1 -2
  11. package/dist/server/features/translate-document/model.d.ts +4 -31
  12. package/dist/server/features/translate-document/model.js +3 -27
  13. package/dist/server/modules/task-runner/TaskRunnerProvider.interface.d.ts +5 -4
  14. package/dist/server/modules/task-runner/payload-jobs-runner/PayloadJobsRunnerProvider.d.ts +4 -4
  15. package/dist/server/modules/task-runner/payload-jobs-runner/PayloadJobsRunnerProvider.js +46 -20
  16. package/dist/server/modules/task-runner/payload-jobs-runner/PayloadJobsTaskRunner.d.ts +22 -56
  17. package/dist/server/modules/task-runner/payload-jobs-runner/PayloadJobsTaskRunner.js +45 -85
  18. package/dist/server/modules/task-runner/payload-jobs-runner/normalizeJob.d.ts +2 -2
  19. package/dist/server/modules/task-runner/payload-jobs-runner/normalizeJob.js +14 -12
  20. package/dist/server/modules/task-runner/payload-jobs-runner/readCollectionRef.d.ts +22 -0
  21. package/dist/server/modules/task-runner/payload-jobs-runner/readCollectionRef.js +22 -0
  22. package/dist/server/modules/task-runner/payload-jobs-runner/types.d.ts +13 -5
  23. package/dist/server/modules/task-runner/sync-runner/SyncTaskRunner.d.ts +5 -5
  24. package/dist/server/modules/task-runner/sync-runner/SyncTaskRunner.js +7 -6
  25. package/dist/server/modules/task-runner/types.d.ts +15 -5
  26. package/package.json +1 -1
  27. package/dist/server/features/translate-document/task.d.ts +0 -40
  28. package/dist/server/features/translate-document/task.js +0 -44
@@ -1,17 +1,27 @@
1
- import type { CollectionSlug } from 'payload';
1
+ import type { CollectionSlug } from "payload";
2
+ /**
3
+ * Document identifier.
4
+ *
5
+ * The plugin is ID-agnostic: it treats every document ID as a string
6
+ * internally, converting once at ingress (the enqueue boundary / write side).
7
+ * Payload coerces the string back to the collection's native PK type on
8
+ * `findByID` / `update`, so number-id (autoincrement) and string-id (uuid/text)
9
+ * collections both work without the plugin ever branching on ID type.
10
+ */
11
+ export type ID = string;
2
12
  /**
3
13
  * Status of a translation task
4
14
  */
5
- export type TaskStatus = 'pending' | 'running' | 'completed' | 'failed';
15
+ export type TaskStatus = "pending" | "running" | "completed" | "failed";
6
16
  /**
7
17
  * Input for creating a new translation task
8
18
  */
9
19
  export type TaskInput = {
10
20
  collectionSlug: CollectionSlug;
11
- collectionId: string | number;
21
+ collectionId: ID;
12
22
  sourceLng: string;
13
23
  targetLng: string;
14
- strategy: 'overwrite' | 'skip_existing';
24
+ strategy: "overwrite" | "skip_existing";
15
25
  publishOnTranslation: boolean;
16
26
  };
17
27
  /**
@@ -36,5 +46,5 @@ export type RunResult = {
36
46
  success: true;
37
47
  } | {
38
48
  success: false;
39
- error: 'not_found' | 'already_running' | 'already_completed';
49
+ error: "not_found" | "already_running" | "already_completed";
40
50
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@focus-reactive/payload-plugin-translator",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Translation plugin for Payload CMS 3.x. Automatically translate your localized content using any translation provider.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,40 +0,0 @@
1
- import type { CollectionSlug, Field, PayloadRequest } from 'payload';
2
- import type { TranslationStrategyName } from '../../modules/translation-pipeline/strategies';
3
- import type { TranslateDocumentHandler } from './handler';
4
- import type { TaskConfig, AutoRunConfig } from './model';
5
- import { TASK_NAME, QUEUE_NAME } from './model';
6
- type TaskInput = {
7
- collection: {
8
- relationTo: CollectionSlug;
9
- value: string | number | Record<string, unknown>;
10
- };
11
- source_lng: string;
12
- target_lng: string;
13
- strategy: TranslationStrategyName;
14
- publish_on_translation?: boolean;
15
- };
16
- export type PayloadTaskConfig = {
17
- slug: string;
18
- inputSchema: Field[];
19
- retries?: TaskConfig['retries'];
20
- handler: (args: {
21
- req: PayloadRequest;
22
- input: TaskInput;
23
- }) => Promise<{
24
- output: Record<string, never>;
25
- }>;
26
- };
27
- type CreateTaskOptions = {
28
- collections: CollectionSlug[];
29
- handler: TranslateDocumentHandler;
30
- retries?: TaskConfig['retries'];
31
- };
32
- /**
33
- * Creates a Payload task definition for document translation
34
- */
35
- export declare function createTranslateDocumentTask(options: CreateTaskOptions): PayloadTaskConfig;
36
- /**
37
- * Creates auto-run configuration for the job queue
38
- */
39
- export declare function createAutoRunConfig(options?: Partial<AutoRunConfig>): AutoRunConfig;
40
- export { TASK_NAME, QUEUE_NAME };
@@ -1,44 +0,0 @@
1
- import { TASK_NAME, QUEUE_NAME, DEFAULT_AUTO_RUN, taskInputSchema } from './model';
2
- /**
3
- * Creates a Payload task definition for document translation
4
- */ export function createTranslateDocumentTask(options) {
5
- const { collections, handler, retries } = options;
6
- return {
7
- slug: TASK_NAME,
8
- inputSchema: [
9
- {
10
- type: 'relationship',
11
- name: 'collection',
12
- relationTo: collections,
13
- required: true
14
- },
15
- ...taskInputSchema.slice(1)
16
- ],
17
- retries,
18
- handler: async (args)=>{
19
- await handler.handle(args.req.payload, {
20
- collection: args.input.collection.relationTo,
21
- collectionId: args.input.collection.value,
22
- sourceLng: args.input.source_lng,
23
- targetLng: args.input.target_lng,
24
- strategy: args.input.strategy,
25
- publishOnTranslation: args.input.publish_on_translation ?? false
26
- });
27
- return {
28
- output: {}
29
- };
30
- }
31
- };
32
- }
33
- /**
34
- * Creates auto-run configuration for the job queue
35
- */ export function createAutoRunConfig(options) {
36
- return {
37
- queue: QUEUE_NAME,
38
- limit: options?.limit ?? DEFAULT_AUTO_RUN.limit,
39
- cron: options?.cron ?? DEFAULT_AUTO_RUN.cron
40
- };
41
- }
42
- export { TASK_NAME, QUEUE_NAME };
43
-
44
- //# sourceMappingURL=task.js.map