sanity-plugin-internationalized-array 5.0.0-canary.1 → 5.0.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/README.md +76 -3
- package/dist/index.d.ts +14 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +435 -359
- package/dist/index.js.map +1 -1
- package/dist/migrations/index.d.ts +8 -8
- package/package.json +15 -9
package/README.md
CHANGED
|
@@ -368,6 +368,30 @@ Use a backwards compatible query until your migration is ready and has been exec
|
|
|
368
368
|
}
|
|
369
369
|
```
|
|
370
370
|
|
|
371
|
+
If you use AI agents in your code, you can copy [this skill](../../.claude/skills/i18n-array-groq-query-migration/SKILL.md) to your project to guide your agents and help you with the migration.
|
|
372
|
+
|
|
373
|
+
Use this pre migration prompt
|
|
374
|
+
|
|
375
|
+
```text
|
|
376
|
+
Use the project skill `i18n-array-groq-query-migration` to update this repo's GROQ queries for `sanity-plugin-internationalized-array` v5.
|
|
377
|
+
|
|
378
|
+
Goal:
|
|
379
|
+
- Detect all query patterns where language is read from `_key` (for example `_key == "en"` or `_key == $language`).
|
|
380
|
+
- Keep the same language expression used in each query.
|
|
381
|
+
|
|
382
|
+
Mode: PRE-MIGRATION (backwards-compatible)
|
|
383
|
+
- Replace `_key == <languageExpr>` with `language == <languageExpr> || _key == <languageExpr>`.
|
|
384
|
+
|
|
385
|
+
What to do:
|
|
386
|
+
1) Scan the codebase for all relevant GROQ queries.
|
|
387
|
+
2) Update the files in place.
|
|
388
|
+
3) Exclude unrelated `_key` uses that are not language matching.
|
|
389
|
+
4) Return a concise report with:
|
|
390
|
+
- files changed
|
|
391
|
+
- before/after snippets
|
|
392
|
+
- any ambiguous matches needing manual review.
|
|
393
|
+
```
|
|
394
|
+
|
|
371
395
|
### 3. Data migration
|
|
372
396
|
|
|
373
397
|
The package exports a migration helper that you can run with the [migration CLI](https://www.sanity.io/docs/cli-reference/cli-migration).
|
|
@@ -404,13 +428,62 @@ And update `@sanity/document-internationalization` to `v6`
|
|
|
404
428
|
|
|
405
429
|
Previously we updated the GROQ queries to support both locations for the language field. Once migration is complete, update the GROQ queries again to only use `language` and remove the dependency on `_key`.
|
|
406
430
|
|
|
407
|
-
```
|
|
431
|
+
```groq
|
|
408
432
|
*[_type == "person"] {
|
|
409
|
-
|
|
410
|
-
+ "greeting": greeting[language == "en"][0].value
|
|
433
|
+
"greeting": greeting[language == "en"][0].value
|
|
411
434
|
}
|
|
412
435
|
```
|
|
413
436
|
|
|
437
|
+
If you use AI agents in your code, you can automate this with the project skill at `.cursor/skills/i18n-array-groq-query-migration/SKILL.md`.
|
|
438
|
+
|
|
439
|
+
### Ask your AI agent to help you
|
|
440
|
+
|
|
441
|
+
```text
|
|
442
|
+
# Migrate internationalized-array to v5 and document-internationalization to v6
|
|
443
|
+
Create and present a plan first, then wait for user confirmation before making changes.
|
|
444
|
+
|
|
445
|
+
Before running any migration steps, ask the user to create a backup and confirm it is complete. Do not proceed until backup confirmation is received.
|
|
446
|
+
|
|
447
|
+
Use this context:
|
|
448
|
+
- Document internationalization (v5 -> v6): https://github.com/sanity-io/plugins/blob/main/plugins/%40sanity/document-internationalization/README.md#migrating-to-v6
|
|
449
|
+
- Internationalized array README: https://github.com/sanity-io/plugins/blob/main/plugins/sanity-plugin-internationalized-array/README.md
|
|
450
|
+
- Skill source to copy from: https://github.com/sanity-io/plugins/blob/main/.claude/skills/i18n-array-groq-query-migration/SKILL.md
|
|
451
|
+
|
|
452
|
+
Then execute this workflow:
|
|
453
|
+
## Pre migration:
|
|
454
|
+
1) Copy the `i18n-array-groq-query-migration` skill file from the provided source URL into the relevant local project skill location.
|
|
455
|
+
2) Use the project skill `i18n-array-groq-query-migration` in PRE-MIGRATION mode and update all legacy GROQ filters from:
|
|
456
|
+
`_key == <languageExpr>`
|
|
457
|
+
to:
|
|
458
|
+
`language == <languageExpr> || _key == <languageExpr>`
|
|
459
|
+
3) Keep the same `<languageExpr>` in each query, edit files in place, and report changed files plus any ambiguous cases.
|
|
460
|
+
4) Add a pause here, the user should deploy this changes with the queries updated before continuing with the migration, request confirmation on this step.
|
|
461
|
+
|
|
462
|
+
## Migration:
|
|
463
|
+
5) Update the packages to the new versions.
|
|
464
|
+
6) Identify schema types that need updates by scanning schemas where internationalization is used, specifically document types that contain fields with `type` matching `internationalizedArray*`.
|
|
465
|
+
7) Create the migration file following the internationalized array migration guidance, using the discovered document types in the previous step.
|
|
466
|
+
8) If `@sanity/document-internationalization` is used, include `translation.metadata` in the migration document types and plan for upgrading `@sanity/document-internationalization` to `v6`.
|
|
467
|
+
9) Ask the user to run the migration as dry run first, then non-dry-run only after confirmation.
|
|
468
|
+
10) Stop and ask the user to confirm the migration completed successfully before proceeding to post-migration query cleanup.
|
|
469
|
+
11) Ask the user to deploy the changes.
|
|
470
|
+
|
|
471
|
+
## Post migration.
|
|
472
|
+
11) After migration is confirmed complete, use the project skill in POST-MIGRATION mode.
|
|
473
|
+
12) Update all GROQ queries from:
|
|
474
|
+
`language == <languageExpr> || _key == <languageExpr>`
|
|
475
|
+
to:
|
|
476
|
+
`language == <languageExpr>`
|
|
477
|
+
13) Keep the same `<languageExpr>` in each query, edit files in place, and report changed files plus any ambiguous cases.
|
|
478
|
+
|
|
479
|
+
Report:
|
|
480
|
+
- The approved plan
|
|
481
|
+
- Backup confirmation status
|
|
482
|
+
- Changed query files
|
|
483
|
+
- Discovered schema types for migration
|
|
484
|
+
- The created migration file path and summary of what it migrates
|
|
485
|
+
```
|
|
486
|
+
|
|
414
487
|
## Usage with language filter
|
|
415
488
|
|
|
416
489
|
The plugin now includes built-in integration with `@sanity/language-filter`.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import { FieldDefinition, Rule, RuleTypeConstraint, SanityClient } from "sanity";
|
|
3
|
-
import { FilterFieldFunction } from "@sanity/language-filter";
|
|
1
|
+
import * as sanity from "sanity";
|
|
2
|
+
import { FieldDefinition, FieldMember, FieldsetState, ObjectSchemaType, Rule, RuleTypeConstraint, SanityClient } from "sanity";
|
|
4
3
|
type Language = {
|
|
5
4
|
id: Intl.UnicodeBCP47LocaleIdentifier;
|
|
6
5
|
title: string;
|
|
@@ -137,6 +136,16 @@ type PluginConfig = {
|
|
|
137
136
|
* @defaultValue 'code'
|
|
138
137
|
* */
|
|
139
138
|
languageDisplay?: LanguageDisplay;
|
|
139
|
+
/**
|
|
140
|
+
* @internal
|
|
141
|
+
* Function to determine if the plugin layout and root input should be included for a given document type.
|
|
142
|
+
* @defaultValue (documentType) => documentType !== 'translation.metadata'
|
|
143
|
+
* @example
|
|
144
|
+
* {
|
|
145
|
+
* includeForDocumentType: (documentType) => documentType === 'translation.metadata'
|
|
146
|
+
* }
|
|
147
|
+
*/
|
|
148
|
+
includeForDocumentType?: (documentType: string) => boolean;
|
|
140
149
|
/**
|
|
141
150
|
* Configure the language filter for the plugin by providing the document types that should show the filter.
|
|
142
151
|
* ```tsx
|
|
@@ -176,11 +185,11 @@ declare const clear: () => void;
|
|
|
176
185
|
* ```
|
|
177
186
|
*/
|
|
178
187
|
declare const LANGUAGE_FIELD_NAME: "language";
|
|
179
|
-
declare const internationalizedArray:
|
|
188
|
+
declare const internationalizedArray: sanity.Plugin<PluginConfig>;
|
|
180
189
|
/**
|
|
181
190
|
* Default filter function for the internationalized array field.
|
|
182
191
|
* It filter the field base on the `language` value of the object.
|
|
183
192
|
*/
|
|
184
|
-
declare const internationalizedArrayLanguageFilter:
|
|
193
|
+
declare const internationalizedArrayLanguageFilter: (enclosingType: ObjectSchemaType, _member: FieldMember | FieldsetState, selectedLanguageIds: string[], parentValue: Record<string, unknown> | undefined, languages: Language[]) => boolean;
|
|
185
194
|
export { AllowedType, ArrayConfig, InternationalizedArrayItem, LANGUAGE_FIELD_NAME, Language, LanguageCallback, LanguageDisplay, PluginConfig, Value, clear, internationalizedArray, internationalizedArrayLanguageFilter, isInternationalizedArrayItemType };
|
|
186
195
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/cache.ts","../src/constants.ts","../src/plugin.tsx","../src/utils/internationalizedArrayLanguageFilter.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/cache.ts","../src/constants.ts","../src/plugin.tsx","../src/utils/internationalizedArrayLanguageFilter.ts"],"mappings":";;KAEY,QAAA;EACV,EAAA,EAAI,IAAA,CAAK,4BAAA;EACT,KAAA;AAAA;AAAA,KAGU,WAAA;AAAA,KAEA,WAAA;EACV,IAAA;EACA,IAAA,EAAM,WAAA;EACN,SAAA,EAAW,QAAA;EACX,KAAA;EACA,KAAA;EACA,MAAA;EACA,QAAA;EACA,UAAA,GAAa,IAAA,GAAO,IAAA;EACpB,KAAA;IAAA,CAAU,GAAA;IAAuB,OAAA;MAAA,CAAW,GAAA;IAAA;EAAA;AAAA;;;;KAMlC,KAAA;EACV,IAAA,UAfA;EAiBA,QAAA;EACA,KAAA;AAAA;AAAA,iBAGc,gCAAA,CACd,IAAA,WACC,IAAA,IAAQ,0BAAA;AAAA,KAIC,0BAAA;EACV,IAAA;EACA,KAAA,GAAQ,CAAA,EAvBR;EAyBA,QAAA;EAxBa;;;EA4Bb,KAAA;AAAA;AAAA,KAGU,gBAAA,IACV,MAAA,EAAQ,YAAA,EACR,aAAA,EAAe,MAAA,sBACZ,OAAA,CAAQ,QAAA;AAAA,KAED,eAAA;AAAA,KAEA,YAAA;EA/BA;;;;EAoCV,UAAA;EAjCA;;;;AAIF;;;;;;;;EA0CE,MAAA,GAAS,MAAA;EApCC;;;;;;;;;;;;AAWZ;;;;;;;;;;;;;;;EAqDE,SAAA,EAAW,QAAA,KAAa,gBAAA;EAlDL;AAErB;;;;;AAEA;;EAuDE,gBAAA;EArCS;;;;;;;;;;;;;;;;;;;;;;;EA8DT,UAAA,YAAsB,kBAAA,GAAqB,eAAA;EAoC3C;;;;EA/BA,eAAA;EC/GW;;;;EDoHX,YAAA;;AExHF;;;EF6HE,eAAA,GAAkB,eAAA;EE7HkC;;ACZtD;;;;;;ACJA;EJuJE,sBAAA,IAA0B,YAAA;;;;;;;;;;;EAW1B,cAAA;IACE,aAAA;EAAA;AAAA;AAAA,cC/IS,KAAA;;;AD3Bb;;;;;;;;;;AAKA;;;;;AAEA;;;;;;cEgBa,mBAAA;AAAA,cCZA,sBAAA,EAAsB,MAAA,CAAA,MAAA,CAAA,YAAA;;AHXnC;;;cIOa,oCAAA,GACX,aAAA,EAAe,gBAAA,EACf,OAAA,EAAS,WAAA,GAAc,aAAA,EACvB,mBAAA,YACA,WAAA,EAAa,MAAA,+BACb,SAAA,EAAW,QAAA"}
|