@focus-reactive/payload-plugin-translator 0.2.1 → 0.4.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.
- package/dist/client/features/collection-translation-form/model/schema.d.ts +2 -2
- package/dist/client/features/translate-document-form/model/schema.d.ts +3 -3
- package/dist/server/features/cancel/handler.d.ts +2 -2
- package/dist/server/features/cancel/handler.js +3 -3
- package/dist/server/features/cancel-by-collection/handler.d.ts +3 -3
- package/dist/server/features/cancel-by-collection/handler.js +5 -5
- package/dist/server/features/enqueue-translation/handler.d.ts +3 -3
- package/dist/server/features/enqueue-translation/handler.js +4 -4
- package/dist/server/features/enqueue-translation/model.d.ts +4 -4
- package/dist/server/features/get-collection-status/handler.d.ts +3 -3
- package/dist/server/features/get-collection-status/handler.js +4 -4
- package/dist/server/features/get-document-status/handler.d.ts +3 -3
- package/dist/server/features/get-document-status/handler.js +4 -4
- package/dist/server/features/get-document-status/model.d.ts +1 -1
- package/dist/server/features/run-translation/handler.d.ts +2 -2
- package/dist/server/features/run-translation/handler.js +7 -7
- package/dist/server/features/translate-document/handler.d.ts +4 -4
- package/dist/server/features/translate-document/handler.js +4 -4
- package/dist/server/features/translate-document/index.d.ts +2 -3
- package/dist/server/features/translate-document/index.js +1 -2
- package/dist/server/features/translate-document/model.d.ts +4 -31
- package/dist/server/features/translate-document/model.js +3 -27
- package/dist/server/modules/task-runner/TaskRunnerProvider.interface.d.ts +6 -4
- package/dist/server/modules/task-runner/payload-jobs-runner/PayloadJobsRunnerProvider.d.ts +4 -4
- package/dist/server/modules/task-runner/payload-jobs-runner/PayloadJobsRunnerProvider.js +72 -20
- package/dist/server/modules/task-runner/payload-jobs-runner/PayloadJobsTaskRunner.d.ts +51 -56
- package/dist/server/modules/task-runner/payload-jobs-runner/PayloadJobsTaskRunner.js +146 -91
- package/dist/server/modules/task-runner/payload-jobs-runner/normalizeJob.d.ts +2 -2
- package/dist/server/modules/task-runner/payload-jobs-runner/normalizeJob.js +14 -12
- package/dist/server/modules/task-runner/payload-jobs-runner/readCollectionRef.d.ts +22 -0
- package/dist/server/modules/task-runner/payload-jobs-runner/readCollectionRef.js +22 -0
- package/dist/server/modules/task-runner/payload-jobs-runner/types.d.ts +30 -5
- package/dist/server/modules/task-runner/sync-runner/SyncTaskRunner.d.ts +5 -5
- package/dist/server/modules/task-runner/sync-runner/SyncTaskRunner.js +7 -6
- package/dist/server/modules/task-runner/types.d.ts +15 -5
- package/package.json +1 -1
- package/dist/server/features/translate-document/task.d.ts +0 -40
- package/dist/server/features/translate-document/task.js +0 -44
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
const now = new Date().toISOString();
|
|
19
19
|
const task = {
|
|
20
20
|
id: crypto.randomUUID(),
|
|
21
|
-
status:
|
|
21
|
+
status: "running",
|
|
22
22
|
input,
|
|
23
23
|
createdAt: now,
|
|
24
24
|
updatedAt: now,
|
|
@@ -34,12 +34,12 @@
|
|
|
34
34
|
strategy: input.strategy,
|
|
35
35
|
publishOnTranslation: input.publishOnTranslation
|
|
36
36
|
});
|
|
37
|
-
task.status =
|
|
37
|
+
task.status = "completed";
|
|
38
38
|
task.completedAt = new Date().toISOString();
|
|
39
39
|
} catch (error) {
|
|
40
|
-
task.status =
|
|
40
|
+
task.status = "failed";
|
|
41
41
|
task.error = {
|
|
42
|
-
message: error instanceof Error ? error.message :
|
|
42
|
+
message: error instanceof Error ? error.message : "Unknown error"
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
task.updatedAt = new Date().toISOString();
|
|
@@ -52,14 +52,15 @@
|
|
|
52
52
|
// Sync runner executes tasks immediately, no pending tasks to run
|
|
53
53
|
return {
|
|
54
54
|
success: false,
|
|
55
|
-
error:
|
|
55
|
+
error: "not_found"
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
async findByCollection(collectionSlug, documentIds) {
|
|
59
59
|
const results = [];
|
|
60
|
+
const wanted = documentIds ? new Set(documentIds.map(String)) : undefined;
|
|
60
61
|
for (const [, task] of this.tasks){
|
|
61
62
|
if (task.input.collectionSlug !== collectionSlug) continue;
|
|
62
|
-
if (
|
|
63
|
+
if (wanted && !wanted.has(task.input.collectionId)) continue;
|
|
63
64
|
results.push(task);
|
|
64
65
|
}
|
|
65
66
|
return results;
|
|
@@ -1,17 +1,27 @@
|
|
|
1
|
-
import type { CollectionSlug } from
|
|
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 =
|
|
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:
|
|
21
|
+
collectionId: ID;
|
|
12
22
|
sourceLng: string;
|
|
13
23
|
targetLng: string;
|
|
14
|
-
strategy:
|
|
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:
|
|
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.
|
|
3
|
+
"version": "0.4.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
|