@bison-lab/payload-core 4.40.0 → 5.1.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 (36) hide show
  1. package/README.md +47 -4
  2. package/dist/admin.d.mts +21 -1
  3. package/dist/admin.d.mts.map +1 -1
  4. package/dist/admin.mjs +270 -5
  5. package/dist/admin.mjs.map +1 -1
  6. package/dist/{capability-DdnN7AHB.mjs → capability-Cb62lWQo.mjs} +1392 -32
  7. package/dist/capability-Cb62lWQo.mjs.map +1 -0
  8. package/dist/{capability-BVDhJV8A.d.mts → capability-Dotbq58Q.d.mts} +85 -9
  9. package/dist/capability-Dotbq58Q.d.mts.map +1 -0
  10. package/dist/index.d.mts +3 -3
  11. package/dist/index.mjs +3 -3
  12. package/dist/locale-B6rUVwpg.mjs.map +1 -1
  13. package/dist/{locale-5z7KTvRJ.d.mts → locale-CTT3nn6T.d.mts} +5 -4
  14. package/dist/locale-CTT3nn6T.d.mts.map +1 -0
  15. package/dist/{messages-Bk1uYO3o.mjs → messages-dZV_aAnR.mjs} +2 -2
  16. package/dist/{messages-Bk1uYO3o.mjs.map → messages-dZV_aAnR.mjs.map} +1 -1
  17. package/dist/navigation.d.mts +2 -2
  18. package/dist/og.d.mts +1 -1
  19. package/dist/{published-CY5PIy5W.d.mts → published-B3etM6X5.d.mts} +2 -2
  20. package/dist/{published-CY5PIy5W.d.mts.map → published-B3etM6X5.d.mts.map} +1 -1
  21. package/dist/{published-BC8kg47c.d.mts → published-QDNmDi02.d.mts} +2 -2
  22. package/dist/{published-BC8kg47c.d.mts.map → published-QDNmDi02.d.mts.map} +1 -1
  23. package/dist/{strings-Bafwdg67.mjs → strings-Fd7kUCT7.mjs} +4 -4
  24. package/dist/strings-Fd7kUCT7.mjs.map +1 -0
  25. package/dist/theme.d.mts +2 -2
  26. package/dist/translate-messages-cli.mjs +3 -3
  27. package/dist/translate-messages-cli.mjs.map +1 -1
  28. package/dist/translate.d.mts +366 -6
  29. package/dist/translate.d.mts.map +1 -1
  30. package/dist/translate.mjs +238 -5
  31. package/dist/translate.mjs.map +1 -1
  32. package/package.json +8 -10
  33. package/dist/capability-BVDhJV8A.d.mts.map +0 -1
  34. package/dist/capability-DdnN7AHB.mjs.map +0 -1
  35. package/dist/locale-5z7KTvRJ.d.mts.map +0 -1
  36. package/dist/strings-Bafwdg67.mjs.map +0 -1
@@ -1,6 +1,6 @@
1
- import { A as sameRow, C as readTranslationSettings, D as encryptApiKey, E as decryptApiKey, O as resolveApiKey, S as invalidateTranslationSettings, T as siteFromInstructions, _ as withTranslator, a as isAutosave, b as TRANSLATION_SETTINGS_SLUG, c as shouldSkipDraftedTranslation, d as runAfterCommit, f as TRANSLATE_NOW, g as readTranslateState, h as localeCodes, i as translationSettingsEndpoints, j as translationJob, k as collectLocalizedStrings, l as shouldSkipUndraftedTranslation, m as BISON_TRANSLATION_CONTEXT, n as hasLocalizedFields, o as draftedTranslationDecision, p as translateDocument, r as translation, s as localizedCopyUnchanged, t as applyTranslation, u as TRANSACTION_TIMEOUT_MS, v as TRANSLATION_GRANT, w as resolveModel, x as TRANSLATION_STATE_SLUG, y as TRANSLATION_KEY_PANEL } from "./capability-DdnN7AHB.mjs";
2
- import { a as TRANSLATE_MODEL_PRICES, c as estimateCost, d as translationSystemPrompt, f as verifyAnthropicKey, i as ECONOMY_TRANSLATE_MODEL, l as modelPrice, n as translateStrings, o as anthropicTranslator, p as classifyAnthropicError, r as DEFAULT_TRANSLATE_MODEL, s as containsWord, t as isTranslatorConfigured, u as parseJsonArray } from "./strings-Bafwdg67.mjs";
3
- import { t as fillMessages } from "./messages-Bk1uYO3o.mjs";
1
+ import { $ as decryptApiKey, A as TRANSLATION_SETTINGS_SLUG, B as monthKey, C as translateDocument, D as TRANSLATION_ACTIVITY_PANEL, E as withTranslator, F as resolveModel, G as LIBRARY_DEFAULT_LOCALE, H as usageHistory, I as siteFromInstructions, J as activeAlternates, K as LIBRARY_LOCALES, L as FAILURE_ADVICE, M as TRANSLATION_STATUS_BAR, N as invalidateTranslationSettings, O as TRANSLATION_GRANT, P as readTranslationSettings, Q as withLibraryLocales, R as RATE_LIMIT_STREAK, S as TRANSLATE_NOW, T as readTranslateState, U as usageThisMonth, V as recordUsage, W as ACTIVE_LOCALES_CACHE_MS, X as inactiveLocaleRedirect, Y as activeLocales, Z as invalidateActiveLocales, _ as localizedCopyUnchanged, a as LEASE_MS, b as TRANSACTION_TIMEOUT_MS, c as estimateJob, d as resumeStaleJobs, et as encryptApiKey, f as runJobSlice, g as draftedTranslationDecision, h as isAutosave, i as translationSettingsEndpoints, it as translationJob, j as TRANSLATION_STATE_SLUG, k as TRANSLATION_KEY_PANEL, l as frozenWordForce, m as startJob, n as hasLocalizedFields, nt as collectLocalizedStrings, o as TRANSLATION_JOBS_SLUG, p as startBackfill, q as LIBRARY_LOCALE_CODES, r as translation, rt as sameRow, s as claimJob, t as applyTranslation, tt as resolveApiKey, u as jobView, v as shouldSkipDraftedTranslation, w as BISON_TRANSLATION_CONTEXT, x as runAfterCommit, y as shouldSkipUndraftedTranslation, z as TRANSLATION_USAGE_SLUG } from "./capability-Cb62lWQo.mjs";
2
+ import { a as TRANSLATE_MODEL_PRICES, c as estimateCost, d as translationSystemPrompt, f as verifyAnthropicKey, i as ECONOMY_TRANSLATE_MODEL, l as modelPrice, n as translateStrings, o as anthropicTranslator, p as classifyAnthropicError, r as DEFAULT_TRANSLATE_MODEL, s as containsWord, t as isTranslatorConfigured, u as parseJsonArray } from "./strings-Fd7kUCT7.mjs";
3
+ import { t as fillMessages } from "./messages-dZV_aAnR.mjs";
4
4
  //#region src/translate/plugin.ts
5
5
  function hints(list) {
6
6
  return (list ?? []).map((entry) => typeof entry === "string" ? [entry, {}] : [entry.slug, entry.context ? { context: entry.context } : {}]);
@@ -19,7 +19,6 @@ function hints(list) {
19
19
  function autoTranslate(options) {
20
20
  return (config) => {
21
21
  if (!options.enabled) return config;
22
- if (localeCodes(config.localization).length < 2) console.warn("[@bison-lab/payload-core] autoTranslate is enabled but the config has no localization with two or more locales; nothing is translated.");
23
22
  for (const [slug] of hints(options.collections)) if (!config.collections?.some((collection) => collection.slug === slug)) throw new Error(`autoTranslate: no collection "${slug}" in the config`);
24
23
  for (const [slug] of hints(options.globals)) if (!config.globals?.some((global) => global.slug === slug)) throw new Error(`autoTranslate: no global "${slug}" in the config`);
25
24
  return applyTranslation(config, {
@@ -31,6 +30,240 @@ function autoTranslate(options) {
31
30
  };
32
31
  }
33
32
  //#endregion
34
- export { BISON_TRANSLATION_CONTEXT, DEFAULT_TRANSLATE_MODEL, ECONOMY_TRANSLATE_MODEL, TRANSACTION_TIMEOUT_MS, TRANSLATE_MODEL_PRICES, TRANSLATE_NOW, TRANSLATION_GRANT, TRANSLATION_KEY_PANEL, TRANSLATION_SETTINGS_SLUG, TRANSLATION_STATE_SLUG, anthropicTranslator, applyTranslation, autoTranslate, classifyAnthropicError, collectLocalizedStrings, containsWord, decryptApiKey, draftedTranslationDecision, encryptApiKey, estimateCost, fillMessages, hasLocalizedFields, invalidateTranslationSettings, isAutosave, isTranslatorConfigured, localizedCopyUnchanged, modelPrice, parseJsonArray, readTranslateState, readTranslationSettings, resolveApiKey, resolveModel, runAfterCommit, sameRow, shouldSkipDraftedTranslation, shouldSkipUndraftedTranslation, siteFromInstructions, translateDocument, translateStrings, translation, translationJob, translationSettingsEndpoints, translationSystemPrompt, verifyAnthropicKey, withTranslator };
33
+ //#region src/translate/migrate-locales.ts
34
+ /**
35
+ * Splits generated SQL into statements at a `;` that ends a line, keeping a
36
+ * `DO $$ ... $$;` block whole.
37
+ */
38
+ function splitStatements(text) {
39
+ const out = [];
40
+ let current = [];
41
+ let inDollar = false;
42
+ for (const line of text.split("\n")) {
43
+ if (line.trim() === "" && current.length === 0) continue;
44
+ current.push(line);
45
+ if ((line.match(/\$\$/g)?.length ?? 0) % 2 === 1) inDollar = !inDollar;
46
+ if (!inDollar && /;\s*$/.test(line)) {
47
+ out.push(current.join("\n").trim());
48
+ current = [];
49
+ }
50
+ }
51
+ const rest = current.join("\n").trim();
52
+ if (rest) out.push(rest);
53
+ return out;
54
+ }
55
+ const DROP_COLUMN = /^ALTER TABLE\s+(?:"[^"]+"\.)?"([^"]+)"\s+DROP COLUMN\s+(?:IF EXISTS\s+)?"([^"]+)"/i;
56
+ const DROP_TYPE = /^DROP TYPE\b/i;
57
+ /** The bare name of a type in `DROP TYPE` / `CREATE TYPE` (`"public"."enum_x"` → `enum_x`). */
58
+ const TYPE_NAME = /^(?:DROP|CREATE) TYPE\s+(?:IF EXISTS\s+)?(?:"[^"]+"\.)?"?([^"\s(]+)"?/i;
59
+ const ADD_LOCALE = /^ALTER TABLE\s+(?:"[^"]+"\.)?"([^"]+)"\s+ADD COLUMN\s+"locale"\s/i;
60
+ /**
61
+ * A NOT NULL locale column added to a table that already has rows: `_locale`
62
+ * on a localized array or blocks table, or `locale` on a localized hasMany
63
+ * select's own table. Either would fail on the first existing row.
64
+ */
65
+ const ADD_LOCALE_NOT_NULL = /^(ALTER TABLE\s+((?:"[^"]+"\.)?"[^"]+")\s+ADD COLUMN\s+"(_?locale)"\s+(\S+)\s+NOT NULL)(\s*;)$/i;
66
+ /**
67
+ * Sorts statements into what runs before the copy and the drops that run
68
+ * after it. A `_locale NOT NULL` column added to an existing table (a
69
+ * localized array or blocks field) gets the default locale as a default
70
+ * while it is added, so existing rows are kept as that locale's.
71
+ */
72
+ function partitionStatements(statements, locale = "en") {
73
+ const first = [];
74
+ const last = [];
75
+ const localeColumns = [];
76
+ const drops = /* @__PURE__ */ new Map();
77
+ const recreated = new Set(statements.filter((statement) => /^CREATE TYPE\b/i.test(statement)).map((statement) => statement.match(TYPE_NAME)?.[1]).filter((name) => Boolean(name)));
78
+ for (const statement of statements) {
79
+ const addLocaleColumn = statement.match(ADD_LOCALE);
80
+ if (addLocaleColumn) localeColumns.push(addLocaleColumn[1]);
81
+ const drop = statement.match(DROP_COLUMN);
82
+ if (drop) {
83
+ const [, table, column] = drop;
84
+ drops.set(table, [...drops.get(table) ?? [], column]);
85
+ last.push(statement);
86
+ continue;
87
+ }
88
+ if (DROP_TYPE.test(statement)) {
89
+ const name = statement.match(TYPE_NAME)?.[1];
90
+ if (name && recreated.has(name)) first.push(statement);
91
+ else last.push(statement);
92
+ continue;
93
+ }
94
+ const addLocale = statement.match(ADD_LOCALE_NOT_NULL);
95
+ if (addLocale && !/DEFAULT/i.test(statement)) {
96
+ const [, head, table, columnName, type] = addLocale;
97
+ first.push(`${head} DEFAULT '${locale}'::text::${type};`);
98
+ first.push(`ALTER TABLE ${table} ALTER COLUMN "${columnName}" DROP DEFAULT;`);
99
+ continue;
100
+ }
101
+ first.push(statement);
102
+ }
103
+ return {
104
+ first,
105
+ localeColumns,
106
+ drops,
107
+ last
108
+ };
109
+ }
110
+ /** Payload's default table name for a slug (`toSnakeCase`). */
111
+ function snake(value) {
112
+ return value.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/[-\s]+/g, "_").toLowerCase();
113
+ }
114
+ /** Named fields at this level, looking through rows, collapsibles, unnamed groups and unnamed tabs. */
115
+ function named(fields) {
116
+ return fields.flatMap((field) => {
117
+ if (field.type === "tabs") return (field.tabs ?? []).flatMap((tab) => tab.name ? [{
118
+ type: "group",
119
+ name: tab.name,
120
+ localized: tab.localized,
121
+ fields: tab.fields
122
+ }] : named(tab.fields));
123
+ if (!field.name && field.fields) return named(field.fields);
124
+ return field.name ? [field] : [];
125
+ });
126
+ }
127
+ /**
128
+ * Whether the stored `path` of a relationship / hasMany row (`related`,
129
+ * `layout.1.items.0.ref`) is a localized field, or sits inside one.
130
+ * `undefined` when the path is not in the config. Throws when blocks
131
+ * disagree (two block types with the same sub-path, one localized).
132
+ */
133
+ function isLocalizedPath(fields, segments, inherited = false, configBlocks = []) {
134
+ const [head, ...rest] = segments;
135
+ const field = named(fields).find((candidate) => candidate.name === head);
136
+ if (!field) return void 0;
137
+ const localized = inherited || field.localized === true;
138
+ if (rest.length === 0) return localized;
139
+ if (field.type === "array") return isLocalizedPath(field.fields ?? [], rest.slice(1), localized, configBlocks);
140
+ if (field.type === "blocks") {
141
+ const referenced = (field.blockReferences ?? []).flatMap((ref) => typeof ref === "string" ? configBlocks.filter((block) => block.slug === ref) : [ref]);
142
+ const answers = [...field.blocks ?? [], ...referenced].map((block) => isLocalizedPath(block.fields, rest.slice(1), localized, configBlocks)).filter((answer) => answer !== void 0);
143
+ if (answers.length === 0) return void 0;
144
+ if (answers.some((answer) => answer !== answers[0])) throw new Error(`localizeExistingContent: "${segments.join(".")}" is localized in one block type and not another`);
145
+ return answers[0];
146
+ }
147
+ return isLocalizedPath(field.fields ?? [], rest, localized, configBlocks);
148
+ }
149
+ /** The adapter's table suffixes: Payload's defaults unless the site set its own. */
150
+ function suffixes(payload) {
151
+ return {
152
+ locales: payload?.db?.localesSuffix ?? "_locales",
153
+ rels: payload?.db?.relationshipsSuffix ?? "_rels",
154
+ versions: payload?.db?.versionsSuffix ?? "_v"
155
+ };
156
+ }
157
+ const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
158
+ /** A shared relationship / hasMany table: `<base><relationshipsSuffix>`, `<base>_texts`, `<base>_numbers`. */
159
+ function sharedSuffix(payload) {
160
+ return new RegExp(`(${escapeRegExp(suffixes(payload).rels)}|_texts|_numbers)$`);
161
+ }
162
+ function entityFor(payload, table) {
163
+ const { versions } = suffixes(payload);
164
+ const base = table.replace(sharedSuffix(payload), "");
165
+ const version = base.startsWith("_") && base.endsWith(versions);
166
+ const name = version ? base.slice(1, -versions.length) : base;
167
+ const entity = [...payload.config.collections ?? [], ...payload.config.globals ?? []].find((candidate) => (typeof candidate.dbName === "string" ? candidate.dbName : snake(candidate.slug)) === name);
168
+ return entity ? {
169
+ fields: entity.fields,
170
+ version
171
+ } : null;
172
+ }
173
+ const quote = (name) => `"${name.replace(/"/g, "\"\"")}"`;
174
+ const literal = (value) => `'${value.replace(/'/g, "''")}'`;
175
+ function rowsOf(result) {
176
+ if (Array.isArray(result)) return result;
177
+ const rows = result?.rows;
178
+ return Array.isArray(rows) ? rows : [];
179
+ }
180
+ /**
181
+ * Runs a localization migration without losing content: see the module
182
+ * comment. Returns what it copied. Throws (and Payload rolls the migration
183
+ * back) on any SQL error.
184
+ */
185
+ async function localizeExistingContent(options) {
186
+ const { db, sql } = options;
187
+ const locale = options.locale ?? "en";
188
+ const schema = options.schema ?? "public";
189
+ const log = options.log ?? ((line) => console.log(line));
190
+ const run = (text) => db.execute(sql.raw(text));
191
+ const { first, localeColumns, drops, last } = partitionStatements(splitStatements(options.statements), locale);
192
+ for (const statement of first) await run(statement);
193
+ for (const table of localeColumns) {
194
+ const qualifiedTable = `${quote(schema)}.${quote(table)}`;
195
+ const tableColumns = rowsOf(await run(`SELECT column_name, udt_schema, udt_name FROM information_schema.columns WHERE table_schema = ${literal(schema)} AND table_name = ${literal(table)} AND column_name IN ('locale', 'path')`));
196
+ const localeInfo = tableColumns.find((info) => info.column_name === "locale");
197
+ const value = localeInfo ? `${literal(locale)}::text::${quote(localeInfo.udt_schema)}.${quote(localeInfo.udt_name)}` : literal(locale);
198
+ if (!tableColumns.some((info) => info.column_name === "path")) {
199
+ log(`[localize] ${table}: locale set on ${(await run(`UPDATE ${qualifiedTable} SET "locale" = ${value} WHERE "locale" IS NULL`))?.rowCount ?? "?"} rows`);
200
+ continue;
201
+ }
202
+ const paths = rowsOf(await run(`SELECT DISTINCT "path" FROM ${qualifiedTable} WHERE "locale" IS NULL`)).map((row) => String(row.path));
203
+ if (paths.length === 0) continue;
204
+ if (!options.payload) throw new Error(`localizeExistingContent: ${table} holds relationship or hasMany rows that may belong to localized fields. Pass the migration's payload ({ db, payload, sql, statements }) so they keep their content.`);
205
+ const entity = entityFor(options.payload, table);
206
+ if (!entity) throw new Error(`localizeExistingContent: no collection or global stores its relationships in ${table}. If one does under a custom table name, give that collection or global a dbName matching ${table.replace(sharedSuffix(options.payload), "")}.`);
207
+ const localized = paths.filter((path) => {
208
+ const segments = path.split(".");
209
+ const own = entity.version && segments[0] === "version" ? segments.slice(1) : segments;
210
+ const answer = isLocalizedPath(entity.fields, own, false, options.payload.config.blocks ?? []);
211
+ if (answer === void 0) throw new Error(`localizeExistingContent: ${table} has rows at "${path}", which is not a field in the config passed`);
212
+ return answer;
213
+ });
214
+ if (localized.length === 0) continue;
215
+ log(`[localize] ${table}: locale set on ${(await run(`UPDATE ${qualifiedTable} SET "locale" = ${value} WHERE "locale" IS NULL AND "path" IN (${localized.map(literal).join(", ")})`))?.rowCount ?? "?"} rows (${localized.join(", ")})`);
216
+ }
217
+ const columnsOf = async (table) => rowsOf(await run(`SELECT column_name, data_type, udt_schema, udt_name FROM information_schema.columns WHERE table_schema = ${literal(schema)} AND table_name = ${literal(table)}`));
218
+ const copies = [];
219
+ for (const [table, dropped] of drops) {
220
+ const into = `${table}${suffixes(options.payload).locales}`;
221
+ const target = await columnsOf(into);
222
+ if (target.length === 0) {
223
+ log(`[localize] ${table}: ${dropped.join(", ")} dropped with no locale table to keep them; not copied`);
224
+ continue;
225
+ }
226
+ const byName = new Map(target.map((column) => [column.column_name, column]));
227
+ const moving = dropped.filter((column) => byName.has(column));
228
+ const lost = dropped.filter((column) => !byName.has(column));
229
+ if (lost.length) log(`[localize] ${table}: ${lost.join(", ")} dropped, not localized; not copied`);
230
+ if (moving.length === 0) continue;
231
+ const cast = (column) => {
232
+ const info = byName.get(column);
233
+ return info.data_type === "USER-DEFINED" ? `${quote(column)}::text::${quote(info.udt_schema)}.${quote(info.udt_name)}` : quote(column);
234
+ };
235
+ const localeColumn = byName.get("_locale");
236
+ if (!localeColumn || !byName.has("_parent_id")) throw new Error(`localizeExistingContent: ${into} has no _locale / _parent_id column`);
237
+ const localeValue = `${literal(locale)}::text::${quote(localeColumn.udt_schema)}.${quote(localeColumn.udt_name)}`;
238
+ const qualified = (name) => `${quote(schema)}.${quote(name)}`;
239
+ const statement = `INSERT INTO ${qualified(into)} (${[
240
+ ...moving.map(quote),
241
+ "\"_locale\"",
242
+ "\"_parent_id\""
243
+ ].join(", ")})
244
+ SELECT ${[
245
+ ...moving.map((column) => `p.${cast(column)}`),
246
+ localeValue,
247
+ "p.\"id\""
248
+ ].join(", ")}
249
+ FROM ${qualified(table)} p
250
+ WHERE NOT EXISTS (SELECT 1 FROM ${qualified(into)} l WHERE l."_parent_id" = p."id" AND l."_locale"::text = ${literal(locale)})`;
251
+ const updated = await run(`UPDATE ${qualified(into)} l SET ${moving.map((column) => `${quote(column)} = p.${cast(column)}`).join(", ")}
252
+ FROM ${qualified(table)} p
253
+ WHERE l."_parent_id" = p."id" AND l."_locale"::text = ${literal(locale)}`);
254
+ const rows = ((await run(statement))?.rowCount ?? 0) + (updated?.rowCount ?? 0);
255
+ copies.push({
256
+ table,
257
+ into,
258
+ columns: moving,
259
+ rows
260
+ });
261
+ log(`[localize] ${table} -> ${into}: ${moving.join(", ")} (${rows} rows)`);
262
+ }
263
+ for (const statement of last) await run(statement);
264
+ return copies;
265
+ }
266
+ //#endregion
267
+ export { ACTIVE_LOCALES_CACHE_MS, BISON_TRANSLATION_CONTEXT, DEFAULT_TRANSLATE_MODEL, ECONOMY_TRANSLATE_MODEL, FAILURE_ADVICE, LEASE_MS, LIBRARY_DEFAULT_LOCALE, LIBRARY_LOCALES, LIBRARY_LOCALE_CODES, RATE_LIMIT_STREAK, TRANSACTION_TIMEOUT_MS, TRANSLATE_MODEL_PRICES, TRANSLATE_NOW, TRANSLATION_ACTIVITY_PANEL, TRANSLATION_GRANT, TRANSLATION_JOBS_SLUG, TRANSLATION_KEY_PANEL, TRANSLATION_SETTINGS_SLUG, TRANSLATION_STATE_SLUG, TRANSLATION_STATUS_BAR, TRANSLATION_USAGE_SLUG, activeAlternates, activeLocales, anthropicTranslator, applyTranslation, autoTranslate, claimJob, classifyAnthropicError, collectLocalizedStrings, containsWord, decryptApiKey, draftedTranslationDecision, encryptApiKey, estimateCost, estimateJob, fillMessages, frozenWordForce, hasLocalizedFields, inactiveLocaleRedirect, invalidateActiveLocales, invalidateTranslationSettings, isAutosave, isLocalizedPath, isTranslatorConfigured, jobView, localizeExistingContent, localizedCopyUnchanged, modelPrice, monthKey, parseJsonArray, partitionStatements, readTranslateState, readTranslationSettings, recordUsage, resolveApiKey, resolveModel, resumeStaleJobs, runAfterCommit, runJobSlice, sameRow, shouldSkipDraftedTranslation, shouldSkipUndraftedTranslation, siteFromInstructions, splitStatements, startBackfill, startJob, translateDocument, translateStrings, translation, translationJob, translationSettingsEndpoints, translationSystemPrompt, usageHistory, usageThisMonth, verifyAnthropicKey, withLibraryLocales, withTranslator };
35
268
 
36
269
  //# sourceMappingURL=translate.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"translate.mjs","names":[],"sources":["../src/translate/plugin.ts"],"sourcesContent":["import type { Config, Plugin } from \"payload\";\n\nimport { applyTranslation, type TranslationEntityHint } from \"./capability\";\nimport { localeCodes } from \"./state\";\nimport type { AutoTranslateOptions, TranslatedEntity } from \"./types\";\n\nfunction hints(list: TranslatedEntity[] | undefined): Array<[string, TranslationEntityHint]> {\n return (list ?? []).map((entry) =>\n typeof entry === \"string\" ? [entry, {}] : [entry.slug, entry.context ? { context: entry.context } : {}],\n );\n}\n\n/**\n * @deprecated Every site now has translation through `adminNav()` (or\n * `translation()`), switched on by an Admin in Settings → Translation, and\n * it covers every collection and global with localized fields. This keeps\n * an existing `autoTranslate({ ... })` line working: `enabled: false`\n * returns the config untouched; `enabled: true` applies the capability with\n * its `site` (the instructions' first values), `waitUntil`, the listed\n * entities' `context` hints, and `translator`, which then replaces the\n * screen's key and model (tests). The listed slugs must exist. The screen's\n * switch governs it either way.\n */\nexport function autoTranslate(options: AutoTranslateOptions): Plugin {\n return (config: Config): Config => {\n if (!options.enabled) return config;\n if (localeCodes(config.localization).length < 2) {\n console.warn(\n \"[@bison-lab/payload-core] autoTranslate is enabled but the config has no localization with two or more locales; nothing is translated.\",\n );\n }\n for (const [slug] of hints(options.collections)) {\n if (!config.collections?.some((collection) => collection.slug === slug)) {\n throw new Error(`autoTranslate: no collection \"${slug}\" in the config`);\n }\n }\n for (const [slug] of hints(options.globals)) {\n if (!config.globals?.some((global) => global.slug === slug)) {\n throw new Error(`autoTranslate: no global \"${slug}\" in the config`);\n }\n }\n return applyTranslation(config, {\n translator: options.translator,\n ...(options.site ? { site: options.site } : {}),\n ...(options.waitUntil ? { waitUntil: options.waitUntil } : {}),\n hints: Object.fromEntries([...hints(options.collections), ...hints(options.globals)]),\n });\n };\n}\n"],"mappings":";;;;AAMA,SAAS,MAAM,MAA8E;AAC3F,SAAQ,QAAQ,EAAE,EAAE,KAAK,UACvB,OAAO,UAAU,WAAW,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,MAAM,MAAM,MAAM,UAAU,EAAE,SAAS,MAAM,SAAS,GAAG,EAAE,CAAC,CACxG;;;;;;;;;;;;;AAcH,SAAgB,cAAc,SAAuC;AACnE,SAAQ,WAA2B;AACjC,MAAI,CAAC,QAAQ,QAAS,QAAO;AAC7B,MAAI,YAAY,OAAO,aAAa,CAAC,SAAS,EAC5C,SAAQ,KACN,yIACD;AAEH,OAAK,MAAM,CAAC,SAAS,MAAM,QAAQ,YAAY,CAC7C,KAAI,CAAC,OAAO,aAAa,MAAM,eAAe,WAAW,SAAS,KAAK,CACrE,OAAM,IAAI,MAAM,iCAAiC,KAAK,iBAAiB;AAG3E,OAAK,MAAM,CAAC,SAAS,MAAM,QAAQ,QAAQ,CACzC,KAAI,CAAC,OAAO,SAAS,MAAM,WAAW,OAAO,SAAS,KAAK,CACzD,OAAM,IAAI,MAAM,6BAA6B,KAAK,iBAAiB;AAGvE,SAAO,iBAAiB,QAAQ;GAC9B,YAAY,QAAQ;GACpB,GAAI,QAAQ,OAAO,EAAE,MAAM,QAAQ,MAAM,GAAG,EAAE;GAC9C,GAAI,QAAQ,YAAY,EAAE,WAAW,QAAQ,WAAW,GAAG,EAAE;GAC7D,OAAO,OAAO,YAAY,CAAC,GAAG,MAAM,QAAQ,YAAY,EAAE,GAAG,MAAM,QAAQ,QAAQ,CAAC,CAAC;GACtF,CAAC"}
1
+ {"version":3,"file":"translate.mjs","names":[],"sources":["../src/translate/plugin.ts","../src/translate/migrate-locales.ts"],"sourcesContent":["import type { Config, Plugin } from \"payload\";\n\nimport { applyTranslation, type TranslationEntityHint } from \"./capability\";\nimport type { AutoTranslateOptions, TranslatedEntity } from \"./types\";\n\nfunction hints(list: TranslatedEntity[] | undefined): Array<[string, TranslationEntityHint]> {\n return (list ?? []).map((entry) =>\n typeof entry === \"string\" ? [entry, {}] : [entry.slug, entry.context ? { context: entry.context } : {}],\n );\n}\n\n/**\n * @deprecated Every site now has translation through `adminNav()` (or\n * `translation()`), switched on by an Admin in Settings → Translation, and\n * it covers every collection and global with localized fields. This keeps\n * an existing `autoTranslate({ ... })` line working: `enabled: false`\n * returns the config untouched; `enabled: true` applies the capability with\n * its `site` (the instructions' first values), `waitUntil`, the listed\n * entities' `context` hints, and `translator`, which then replaces the\n * screen's key and model (tests). The listed slugs must exist. The screen's\n * switch governs it either way.\n */\nexport function autoTranslate(options: AutoTranslateOptions): Plugin {\n return (config: Config): Config => {\n if (!options.enabled) return config;\n for (const [slug] of hints(options.collections)) {\n if (!config.collections?.some((collection) => collection.slug === slug)) {\n throw new Error(`autoTranslate: no collection \"${slug}\" in the config`);\n }\n }\n for (const [slug] of hints(options.globals)) {\n if (!config.globals?.some((global) => global.slug === slug)) {\n throw new Error(`autoTranslate: no global \"${slug}\" in the config`);\n }\n }\n return applyTranslation(config, {\n translator: options.translator,\n ...(options.site ? { site: options.site } : {}),\n ...(options.waitUntil ? { waitUntil: options.waitUntil } : {}),\n hints: Object.fromEntries([...hints(options.collections), ...hints(options.globals)]),\n });\n };\n}\n","/**\n * The data migration for a Postgres site going from one locale to several.\n *\n * Turning localization on moves every localized column out of its table\n * into a `<table>_locales` table (one row per locale). `payload\n * migrate:create` writes that as SQL that creates the new tables and then\n * drops the old columns, which throws the copy away. This runs the same\n * SQL with one step in between: after everything else and before any column\n * or type is dropped, each column that moves is copied into its locale\n * table as the default locale's row. Nothing else changes, so the result is\n * exactly the schema Payload generated, holding the content it held before.\n *\n * In the generated migration, replace the body of `up`:\n *\n * ```ts\n * import { localizeExistingContent } from \"@bison-lab/payload-core/translate\";\n *\n * export async function up({ db, payload }: MigrateUpArgs): Promise<void> {\n * await localizeExistingContent({ db, payload, sql, statements: `\n * ...the SQL migrate:create wrote inside sql`...`, unchanged...\n * ` });\n * }\n * ```\n *\n * Postgres only. The migration has no `down`: going back to one locale\n * would drop every other locale's copy.\n */\n\n/** The slice of Payload's `db` (Drizzle) this uses. */\nexport interface MigrationDb {\n // Method syntax on purpose: its parameter is checked bivariantly, so\n // Payload's `PostgresDB` (whose `execute` takes `SQLWrapper | string`)\n // is accepted as it is, with no cast in the site's migration.\n execute(query: never): Promise<unknown>;\n}\n\n/** `sql` from `@payloadcms/db-postgres`, for `sql.raw`. */\nexport interface MigrationSql {\n raw: (text: string) => unknown;\n}\n\n/** The slice of the site's Payload config the relationship step reads (`payload` from the migration's `up`). */\nexport interface MigrationPayload {\n /** The adapter's table-name suffixes, when a site changed them (`postgresAdapter({ localesSuffix })`). */\n db?: { localesSuffix?: string; relationshipsSuffix?: string; versionsSuffix?: string };\n config: {\n collections?: ReadonlyArray<{ slug: string; dbName?: unknown; fields: readonly unknown[] }>;\n globals?: ReadonlyArray<{ slug: string; dbName?: unknown; fields: readonly unknown[] }>;\n /** Config-level blocks, for blocks fields that use `blockReferences`. */\n blocks?: ReadonlyArray<{ slug: string; fields: readonly unknown[] }>;\n };\n}\n\nexport interface LocalizeExistingContentOptions {\n db: MigrationDb;\n sql: MigrationSql;\n /**\n * The migration's `payload`. Needed when a localized relationship, upload\n * or hasMany text/number field already holds rows: Payload keeps those in\n * shared `_rels` / `_texts` / `_numbers` tables with a `locale` column it\n * adds now, and only the config says which rows belong to a localized\n * field. Without it, such rows make the migration stop with an error\n * rather than lose them.\n */\n payload?: MigrationPayload;\n /** The SQL `migrate:create` generated for this change, as text. */\n statements: string;\n /** The locale existing content is in. Defaults to `en`. */\n locale?: string;\n /** The Postgres schema Payload's tables are in. Defaults to `public`. */\n schema?: string;\n /** Progress lines; defaults to `console.log`. */\n log?: (line: string) => void;\n}\n\nexport interface LocalizedTableCopy {\n table: string;\n into: string;\n columns: string[];\n rows: number;\n}\n\n/**\n * Splits generated SQL into statements at a `;` that ends a line, keeping a\n * `DO $$ ... $$;` block whole.\n */\nexport function splitStatements(text: string): string[] {\n const out: string[] = [];\n let current: string[] = [];\n let inDollar = false;\n for (const line of text.split(\"\\n\")) {\n if (line.trim() === \"\" && current.length === 0) continue;\n current.push(line);\n const dollars = line.match(/\\$\\$/g)?.length ?? 0;\n if (dollars % 2 === 1) inDollar = !inDollar;\n if (!inDollar && /;\\s*$/.test(line)) {\n out.push(current.join(\"\\n\").trim());\n current = [];\n }\n }\n const rest = current.join(\"\\n\").trim();\n if (rest) out.push(rest);\n return out;\n}\n\nconst DROP_COLUMN = /^ALTER TABLE\\s+(?:\"[^\"]+\"\\.)?\"([^\"]+)\"\\s+DROP COLUMN\\s+(?:IF EXISTS\\s+)?\"([^\"]+)\"/i;\nconst DROP_TYPE = /^DROP TYPE\\b/i;\n/** The bare name of a type in `DROP TYPE` / `CREATE TYPE` (`\"public\".\"enum_x\"` → `enum_x`). */\nconst TYPE_NAME = /^(?:DROP|CREATE) TYPE\\s+(?:IF EXISTS\\s+)?(?:\"[^\"]+\"\\.)?\"?([^\"\\s(]+)\"?/i;\nconst ADD_LOCALE = /^ALTER TABLE\\s+(?:\"[^\"]+\"\\.)?\"([^\"]+)\"\\s+ADD COLUMN\\s+\"locale\"\\s/i;\n/**\n * A NOT NULL locale column added to a table that already has rows: `_locale`\n * on a localized array or blocks table, or `locale` on a localized hasMany\n * select's own table. Either would fail on the first existing row.\n */\nconst ADD_LOCALE_NOT_NULL =\n /^(ALTER TABLE\\s+((?:\"[^\"]+\"\\.)?\"[^\"]+\")\\s+ADD COLUMN\\s+\"(_?locale)\"\\s+(\\S+)\\s+NOT NULL)(\\s*;)$/i;\n\nexport interface PartitionedStatements {\n /** Everything that does not drop: creates, adds, indexes, constraints. */\n first: string[];\n /** Tables that gain a nullable `locale` column (shared relationship / hasMany tables). */\n localeColumns: string[];\n /** The columns dropped, by table. */\n drops: Map<string, string[]>;\n /** The drops themselves, run last. */\n last: string[];\n}\n\n/**\n * Sorts statements into what runs before the copy and the drops that run\n * after it. A `_locale NOT NULL` column added to an existing table (a\n * localized array or blocks field) gets the default locale as a default\n * while it is added, so existing rows are kept as that locale's.\n */\nexport function partitionStatements(statements: readonly string[], locale = \"en\"): PartitionedStatements {\n const first: string[] = [];\n const last: string[] = [];\n const localeColumns: string[] = [];\n const drops = new Map<string, string[]>();\n // drizzle-kit drops and re-creates a type under the same name when an\n // enum loses a value; that drop must stay where it is, before its CREATE.\n const recreated = new Set(\n statements\n .filter((statement) => /^CREATE TYPE\\b/i.test(statement))\n .map((statement) => statement.match(TYPE_NAME)?.[1])\n .filter((name): name is string => Boolean(name)),\n );\n for (const statement of statements) {\n const addLocaleColumn = statement.match(ADD_LOCALE);\n if (addLocaleColumn) localeColumns.push(addLocaleColumn[1]!);\n const drop = statement.match(DROP_COLUMN);\n if (drop) {\n const [, table, column] = drop as unknown as [string, string, string];\n drops.set(table, [...(drops.get(table) ?? []), column]);\n last.push(statement);\n continue;\n }\n if (DROP_TYPE.test(statement)) {\n const name = statement.match(TYPE_NAME)?.[1];\n if (name && recreated.has(name)) first.push(statement);\n else last.push(statement);\n continue;\n }\n const addLocale = statement.match(ADD_LOCALE_NOT_NULL);\n if (addLocale && !/DEFAULT/i.test(statement)) {\n const [, head, table, columnName, type] = addLocale as unknown as [string, string, string, string, string];\n first.push(`${head} DEFAULT '${locale}'::text::${type};`);\n first.push(`ALTER TABLE ${table} ALTER COLUMN \"${columnName}\" DROP DEFAULT;`);\n continue;\n }\n first.push(statement);\n }\n return { first, localeColumns, drops, last };\n}\n\n// ---------------------------------------------------------------------------\n// Rows of localized relationships, uploads and hasMany fields\n\ninterface ConfigField {\n type?: string;\n name?: string;\n localized?: boolean;\n fields?: ConfigField[];\n tabs?: Array<{ name?: string; localized?: boolean; fields: ConfigField[] }>;\n blocks?: Array<{ slug: string; fields: ConfigField[] }>;\n blockReferences?: Array<string | { slug: string; fields: ConfigField[] }>;\n}\n\n/** Payload's default table name for a slug (`toSnakeCase`). */\nfunction snake(value: string): string {\n return value\n .replace(/([a-z0-9])([A-Z])/g, \"$1_$2\")\n .replace(/[-\\s]+/g, \"_\")\n .toLowerCase();\n}\n\n/** Named fields at this level, looking through rows, collapsibles, unnamed groups and unnamed tabs. */\nfunction named(fields: readonly ConfigField[]): ConfigField[] {\n return fields.flatMap((field) => {\n if (field.type === \"tabs\") {\n return (field.tabs ?? []).flatMap((tab) =>\n tab.name ? [{ type: \"group\", name: tab.name, localized: tab.localized, fields: tab.fields }] : named(tab.fields),\n );\n }\n if (!field.name && field.fields) return named(field.fields);\n return field.name ? [field] : [];\n });\n}\n\n/**\n * Whether the stored `path` of a relationship / hasMany row (`related`,\n * `layout.1.items.0.ref`) is a localized field, or sits inside one.\n * `undefined` when the path is not in the config. Throws when blocks\n * disagree (two block types with the same sub-path, one localized).\n */\nexport function isLocalizedPath(\n fields: readonly ConfigField[],\n segments: readonly string[],\n inherited = false,\n configBlocks: ReadonlyArray<{ slug: string; fields: readonly unknown[] }> = [],\n): boolean | undefined {\n const [head, ...rest] = segments;\n const field = named(fields).find((candidate) => candidate.name === head);\n if (!field) return undefined;\n const localized = inherited || field.localized === true;\n if (rest.length === 0) return localized;\n if (field.type === \"array\") return isLocalizedPath(field.fields ?? [], rest.slice(1), localized, configBlocks);\n if (field.type === \"blocks\") {\n // Inline blocks, plus blocks named by slug in `blockReferences` and declared once in `config.blocks`.\n const referenced = (field.blockReferences ?? []).flatMap((ref) =>\n typeof ref === \"string\" ? configBlocks.filter((block) => block.slug === ref) : [ref],\n ) as Array<{ slug: string; fields: ConfigField[] }>;\n const answers = [...(field.blocks ?? []), ...referenced]\n .map((block) => isLocalizedPath(block.fields, rest.slice(1), localized, configBlocks))\n .filter((answer): answer is boolean => answer !== undefined);\n if (answers.length === 0) return undefined;\n if (answers.some((answer) => answer !== answers[0])) {\n throw new Error(`localizeExistingContent: \"${segments.join(\".\")}\" is localized in one block type and not another`);\n }\n return answers[0];\n }\n return isLocalizedPath(field.fields ?? [], rest, localized, configBlocks);\n}\n\n/** The adapter's table suffixes: Payload's defaults unless the site set its own. */\nfunction suffixes(payload: MigrationPayload | undefined) {\n return {\n locales: payload?.db?.localesSuffix ?? \"_locales\",\n rels: payload?.db?.relationshipsSuffix ?? \"_rels\",\n versions: payload?.db?.versionsSuffix ?? \"_v\",\n };\n}\n\nconst escapeRegExp = (value: string) => value.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n\n/** A shared relationship / hasMany table: `<base><relationshipsSuffix>`, `<base>_texts`, `<base>_numbers`. */\nfunction sharedSuffix(payload: MigrationPayload | undefined): RegExp {\n return new RegExp(`(${escapeRegExp(suffixes(payload).rels)}|_texts|_numbers)$`);\n}\n\nfunction entityFor(payload: MigrationPayload, table: string): { fields: readonly ConfigField[]; version: boolean } | null {\n const { versions } = suffixes(payload);\n const base = table.replace(sharedSuffix(payload), \"\");\n const version = base.startsWith(\"_\") && base.endsWith(versions);\n const name = version ? base.slice(1, -versions.length) : base;\n const entities = [...(payload.config.collections ?? []), ...(payload.config.globals ?? [])];\n const entity = entities.find((candidate) =>\n (typeof candidate.dbName === \"string\" ? candidate.dbName : snake(candidate.slug)) === name,\n );\n return entity ? { fields: entity.fields as readonly ConfigField[], version } : null;\n}\n\nconst quote = (name: string) => `\"${name.replace(/\"/g, '\"\"')}\"`;\nconst literal = (value: string) => `'${value.replace(/'/g, \"''\")}'`;\n\nfunction rowsOf(result: unknown): Array<Record<string, unknown>> {\n if (Array.isArray(result)) return result as Array<Record<string, unknown>>;\n const rows = (result as { rows?: unknown } | null)?.rows;\n return Array.isArray(rows) ? (rows as Array<Record<string, unknown>>) : [];\n}\n\ninterface ColumnInfo {\n column_name: string;\n data_type: string;\n udt_schema: string;\n udt_name: string;\n}\n\n/**\n * Runs a localization migration without losing content: see the module\n * comment. Returns what it copied. Throws (and Payload rolls the migration\n * back) on any SQL error.\n */\nexport async function localizeExistingContent(options: LocalizeExistingContentOptions): Promise<LocalizedTableCopy[]> {\n const { db, sql } = options;\n const locale = options.locale ?? \"en\";\n const schema = options.schema ?? \"public\";\n const log = options.log ?? ((line: string) => console.log(line));\n const run = (text: string) => db.execute(sql.raw(text) as never);\n\n const { first, localeColumns, drops, last } = partitionStatements(splitStatements(options.statements), locale);\n for (const statement of first) await run(statement);\n\n // Relationship, upload and hasMany rows: the new `locale` column is the\n // default locale on rows of a localized field, and stays empty on the\n // rest (Payload reads a non-localized row only when it has no locale).\n for (const table of localeColumns) {\n const qualifiedTable = `${quote(schema)}.${quote(table)}`;\n const tableColumns = rowsOf(\n await run(\n `SELECT column_name, udt_schema, udt_name FROM information_schema.columns WHERE table_schema = ${literal(schema)} AND table_name = ${literal(table)} AND column_name IN ('locale', 'path')`,\n ),\n ) as unknown as ColumnInfo[];\n const localeInfo = tableColumns.find((info) => info.column_name === \"locale\");\n const value = localeInfo\n ? `${literal(locale)}::text::${quote(localeInfo.udt_schema)}.${quote(localeInfo.udt_name)}`\n : literal(locale);\n // Shared by structure, not by name: a relationship / hasMany table keeps\n // each row's field `path`; a hasMany select's own table (which may well be\n // called `pages_phone_numbers`) has none.\n const shared = tableColumns.some((info) => info.column_name === \"path\");\n if (!shared) {\n // A hasMany select keeps its own table, which gains `locale` only when the field is localized.\n const result = await run(`UPDATE ${qualifiedTable} SET \"locale\" = ${value} WHERE \"locale\" IS NULL`);\n log(`[localize] ${table}: locale set on ${(result as { rowCount?: number } | null)?.rowCount ?? \"?\"} rows`);\n continue;\n }\n const paths = rowsOf(await run(`SELECT DISTINCT \"path\" FROM ${qualifiedTable} WHERE \"locale\" IS NULL`)).map((row) =>\n String(row.path),\n );\n if (paths.length === 0) continue;\n if (!options.payload) {\n throw new Error(\n `localizeExistingContent: ${table} holds relationship or hasMany rows that may belong to localized fields. Pass the migration's payload ({ db, payload, sql, statements }) so they keep their content.`,\n );\n }\n const entity = entityFor(options.payload, table);\n if (!entity) {\n throw new Error(\n `localizeExistingContent: no collection or global stores its relationships in ${table}. If one does under a custom table name, give that collection or global a dbName matching ${table.replace(sharedSuffix(options.payload), \"\")}.`,\n );\n }\n const localized = paths.filter((path) => {\n const segments = path.split(\".\");\n const own = entity.version && segments[0] === \"version\" ? segments.slice(1) : segments;\n const answer = isLocalizedPath(entity.fields, own, false, options.payload!.config.blocks ?? []);\n // A row the config cannot place may be exactly the content this exists\n // to keep: stop rather than guess.\n if (answer === undefined) {\n throw new Error(`localizeExistingContent: ${table} has rows at \"${path}\", which is not a field in the config passed`);\n }\n return answer;\n });\n if (localized.length === 0) continue;\n const result = await run(\n `UPDATE ${qualifiedTable} SET \"locale\" = ${value} WHERE \"locale\" IS NULL AND \"path\" IN (${localized.map(literal).join(\", \")})`,\n );\n log(`[localize] ${table}: locale set on ${(result as { rowCount?: number } | null)?.rowCount ?? \"?\"} rows (${localized.join(\", \")})`);\n }\n\n const columnsOf = async (table: string): Promise<ColumnInfo[]> =>\n rowsOf(\n await run(\n `SELECT column_name, data_type, udt_schema, udt_name FROM information_schema.columns WHERE table_schema = ${literal(\n schema,\n )} AND table_name = ${literal(table)}`,\n ),\n ) as unknown as ColumnInfo[];\n\n const copies: LocalizedTableCopy[] = [];\n for (const [table, dropped] of drops) {\n const into = `${table}${suffixes(options.payload).locales}`;\n const target = await columnsOf(into);\n if (target.length === 0) {\n log(`[localize] ${table}: ${dropped.join(\", \")} dropped with no locale table to keep them; not copied`);\n continue;\n }\n const byName = new Map(target.map((column) => [column.column_name, column]));\n const moving = dropped.filter((column) => byName.has(column));\n const lost = dropped.filter((column) => !byName.has(column));\n if (lost.length) log(`[localize] ${table}: ${lost.join(\", \")} dropped, not localized; not copied`);\n if (moving.length === 0) continue;\n const cast = (column: string) => {\n const info = byName.get(column)!;\n return info.data_type === \"USER-DEFINED\"\n ? `${quote(column)}::text::${quote(info.udt_schema)}.${quote(info.udt_name)}`\n : quote(column);\n };\n const localeColumn = byName.get(\"_locale\");\n if (!localeColumn || !byName.has(\"_parent_id\")) {\n throw new Error(`localizeExistingContent: ${into} has no _locale / _parent_id column`);\n }\n const localeValue = `${literal(locale)}::text::${quote(localeColumn.udt_schema)}.${quote(localeColumn.udt_name)}`;\n const qualified = (name: string) => `${quote(schema)}.${quote(name)}`;\n const statement = `INSERT INTO ${qualified(into)} (${[...moving.map(quote), '\"_locale\"', '\"_parent_id\"'].join(\", \")})\nSELECT ${[...moving.map((column) => `p.${cast(column)}`), localeValue, 'p.\"id\"'].join(\", \")}\nFROM ${qualified(table)} p\nWHERE NOT EXISTS (SELECT 1 FROM ${qualified(into)} l WHERE l.\"_parent_id\" = p.\"id\" AND l.\"_locale\"::text = ${literal(\n locale,\n )})`;\n // A locale row that already exists (a site that had localization makes\n // another field localized) gets the moved values; any other parent gets\n // a new English row.\n const updated = await run(`UPDATE ${qualified(into)} l SET ${moving\n .map((column) => `${quote(column)} = p.${cast(column)}`)\n .join(\", \")}\nFROM ${qualified(table)} p\nWHERE l.\"_parent_id\" = p.\"id\" AND l.\"_locale\"::text = ${literal(locale)}`);\n const result = await run(statement);\n const rows =\n ((result as { rowCount?: number } | null)?.rowCount ?? 0) + ((updated as { rowCount?: number } | null)?.rowCount ?? 0);\n copies.push({ table, into, columns: moving, rows });\n log(`[localize] ${table} -> ${into}: ${moving.join(\", \")} (${rows} rows)`);\n }\n\n for (const statement of last) await run(statement);\n return copies;\n}\n"],"mappings":";;;;AAKA,SAAS,MAAM,MAA8E;AAC3F,SAAQ,QAAQ,EAAE,EAAE,KAAK,UACvB,OAAO,UAAU,WAAW,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,MAAM,MAAM,MAAM,UAAU,EAAE,SAAS,MAAM,SAAS,GAAG,EA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E,MAAM,SADS,MAAM,IAAI,UAAU,GAEU,YAAY,MAAO,SAA0C,YAAY;AACtH,SAAO,KAAK;GAAE;GAAO;GAAM,SAAS;GAAQ;GAAM,CAAC;AACnD,MAAI,cAAc,MAAM,MAAM,KAAK,IAAI,OAAO,KAAK,KAAK,CAAC,IAAI,KAAK,QAAQ;;AAG5E,MAAK,MAAM,aAAa,KAAM,OAAM,IAAI,UAAU;AAClD,QAAO"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bison-lab/payload-core",
3
- "version": "4.40.0",
3
+ "version": "5.1.0",
4
4
  "description": "Site-agnostic Payload CMS configuration for Bison Lab sites: the SEO tab, the Theme global, the Roles Global, the brand-assets cupboard, and the metadata and theme readers for the pages they describe",
5
5
  "keywords": [
6
6
  "bison-lab",
@@ -93,9 +93,9 @@
93
93
  },
94
94
  "peerDependencies": {
95
95
  "@anthropic-ai/sdk": ">=0.110.0",
96
- "@bison-lab/fonts": "^3.0.0 || ^4.0.0",
97
- "@bison-lab/tokens": "^3.0.0 || ^4.0.0",
98
- "@bison-lab/ui": "^4.0.0",
96
+ "@bison-lab/fonts": "^3.0.0 || ^4.0.0 || ^5.0.0",
97
+ "@bison-lab/tokens": "^3.0.0 || ^4.0.0 || ^5.0.0",
98
+ "@bison-lab/ui": "^4.0.0 || ^5.0.0",
99
99
  "@payloadcms/live-preview-react": "^3.0.0",
100
100
  "@payloadcms/plugin-redirects": "^3.0.0",
101
101
  "@payloadcms/plugin-seo": "^3.0.0",
@@ -108,9 +108,6 @@
108
108
  "satori": ">=0.10.0"
109
109
  },
110
110
  "peerDependenciesMeta": {
111
- "@anthropic-ai/sdk": {
112
- "optional": true
113
- },
114
111
  "@bison-lab/fonts": {
115
112
  "optional": false
116
113
  },
@@ -163,9 +160,9 @@
163
160
  "tsdown": "^0.21.0",
164
161
  "typescript": "^5.9.3",
165
162
  "vitest": "^4.1.2",
166
- "@bison-lab/tokens": "4.38.0",
167
163
  "@bison-lab/fonts": "4.38.0",
168
- "@bison-lab/ui": "4.39.0"
164
+ "@bison-lab/ui": "4.39.0",
165
+ "@bison-lab/tokens": "4.38.0"
169
166
  },
170
167
  "publishConfig": {
171
168
  "access": "public"
@@ -176,6 +173,7 @@
176
173
  "clean": "rm -rf dist",
177
174
  "typecheck": "tsc --noEmit",
178
175
  "test": "vitest run",
179
- "test:watch": "vitest"
176
+ "test:watch": "vitest",
177
+ "test:postgres": "BISON_PG_TEST=1 vitest run src/__tests__/translate-localize-postgres.test.ts"
180
178
  }
181
179
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"capability-BVDhJV8A.d.mts","names":[],"sources":["../src/translate/errors.ts","../src/translate/types.ts","../src/translate/anthropic.ts","../src/translate/key.ts","../src/translate/settings.ts","../src/translate/settings-endpoints.ts","../src/translate/capability.ts"],"mappings":";;;;;;AAWA;;;;;AAWA;;;KAXY,sBAAA;;iBAWI,sBAAA,CAAuB,KAAA,YAAiB,sBAAA;;;;KCrB5C,GAAA,GAAM,MAAA;;KAGN,oBAAA;;;;;ADkBZ;;;;;;;;ACrBA;UAkBiB,sBAAA;EACf,MAAA;EACA,IAAA,EAAM,oBAAA;AAAA;AAjBR;AAAA,cAqBa,yBAAA;;;;AANb;;UAaiB,aAAA;EAXW;EAa1B,IAAA;EAbA;EAeA,KAAA;EAf0B;EAiB1B,KAAA;EAbW;EAeX,YAAA;;;;AARF;;EAcE,SAAA,GAAY,MAAA;AAAA;;UAIG,gBAAA;EACf,IAAA;EACA,EAAA;EANA;EAQA,OAAA;EARkB;EAUlB,IAAA,GAAO,aAAA;AAAA;;;;;;;;;;KAYG,UAAA,KAAe,OAAA,YAAmB,OAAA,EAAS,gBAAA,KAAqB,OAAA;EAC1E,UAAA;AAAA;;KAIU,gBAAA;EAGN,IAAA,UARiD;EAUjD,OAAA,IAAW,GAAA,EAAK,GAAA;AAAA;AAAA,UAGL,oBAAA;EAZL;;AAIZ;;;EAcE,OAAA;EAXI;EAaJ,WAAA,GA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