sanity-plugin-internationalized-array 4.0.2 → 5.0.0-canary.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 +141 -52
- package/dist/index.d.ts +45 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +257 -122
- package/dist/index.js.map +1 -1
- package/dist/migrations/index.d.ts +31 -0
- package/dist/migrations/index.d.ts.map +1 -0
- package/dist/migrations/index.js +26 -0
- package/dist/migrations/index.js.map +1 -0
- package/package.json +7 -5
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as sanity_migrate9 from "sanity/migrate";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a migration that automatically finds all internationalized array
|
|
4
|
+
* item objects and moves language identifiers from `_key` to the dedicated
|
|
5
|
+
* `language` field, generating new random `_key` values.
|
|
6
|
+
*
|
|
7
|
+
* Detection is automatic: the `object` handler is called for every object in
|
|
8
|
+
* every matching document. If the object has a `_type` matching
|
|
9
|
+
* `internationalizedArray*Value` and is missing the `language` field, it is
|
|
10
|
+
* migrated.
|
|
11
|
+
*/
|
|
12
|
+
declare function migrateToLanguageField(documentTypes: string[]): {
|
|
13
|
+
title: string;
|
|
14
|
+
documentTypes: string[];
|
|
15
|
+
migrate: {
|
|
16
|
+
object<Node extends sanity_migrate9.JsonObject>(node: Node): sanity_migrate9.SetOp<Node & {
|
|
17
|
+
readonly _key: undefined;
|
|
18
|
+
readonly language: string | (string & {
|
|
19
|
+
[x: string]: sanity_migrate9.JsonValue;
|
|
20
|
+
} & {
|
|
21
|
+
[x: string]: sanity_migrate9.JsonValue | undefined;
|
|
22
|
+
}) | (string & sanity_migrate9.JsonValue[]) | (string & readonly sanity_migrate9.JsonValue[]) | ({
|
|
23
|
+
[x: string]: sanity_migrate9.JsonValue;
|
|
24
|
+
} & {
|
|
25
|
+
[x: string]: sanity_migrate9.JsonValue | undefined;
|
|
26
|
+
} & string) | (sanity_migrate9.JsonValue[] & string) | (readonly sanity_migrate9.JsonValue[] & string);
|
|
27
|
+
}> | undefined;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export { migrateToLanguageField };
|
|
31
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../migrations/migrateToLanguageField.ts"],"mappings":";;;AA2BA;;;;;;;;iBAAgB,sBAAA,CAAuB,aAAA;;;;wBAAD,eAAA,CAAA,UAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { defineMigration, set } from "sanity/migrate";
|
|
2
|
+
const LANGUAGE_FIELD_NAME = "language", INTERNATIONALIZED_PREFIX = "internationalizedArray", VALUE_SUFFIX = "Value";
|
|
3
|
+
function migrateToLanguageField(documentTypes) {
|
|
4
|
+
return defineMigration({
|
|
5
|
+
title: "Migrate internationalized array from _key to language",
|
|
6
|
+
documentTypes,
|
|
7
|
+
migrate: {
|
|
8
|
+
object(node) {
|
|
9
|
+
const type = node._type, language = node[LANGUAGE_FIELD_NAME];
|
|
10
|
+
if (typeof type != "string" || !type.startsWith(INTERNATIONALIZED_PREFIX) || !type.endsWith(VALUE_SUFFIX) || language && typeof language == "string")
|
|
11
|
+
return;
|
|
12
|
+
const oldKey = node._key;
|
|
13
|
+
if (!(typeof oldKey != "string" || oldKey.length === 0))
|
|
14
|
+
return set({
|
|
15
|
+
...node,
|
|
16
|
+
_key: void 0,
|
|
17
|
+
[LANGUAGE_FIELD_NAME]: oldKey
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
migrateToLanguageField
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../migrations/migrateToLanguageField.ts"],"sourcesContent":["import {defineMigration, set} from 'sanity/migrate'\n\n/**\n * The property which will be used to store the language identifier from v5.\n */\nconst LANGUAGE_FIELD_NAME = 'language'\n/**\n * The prefix of the internationalized array type name.\n * Internationalized arrays contain objects with `_type` starting with this prefix\n * and ending with `Value` (e.g. `internationalizedArrayStringValue`).\n */\nconst INTERNATIONALIZED_PREFIX = 'internationalizedArray'\n/**\n * The suffix of the internationalized array value type name.\n */\nconst VALUE_SUFFIX = 'Value'\n\n/**\n * Creates a migration that automatically finds all internationalized array\n * item objects and moves language identifiers from `_key` to the dedicated\n * `language` field, generating new random `_key` values.\n *\n * Detection is automatic: the `object` handler is called for every object in\n * every matching document. If the object has a `_type` matching\n * `internationalizedArray*Value` and is missing the `language` field, it is\n * migrated.\n */\nexport function migrateToLanguageField(documentTypes: string[]) {\n return defineMigration({\n title: 'Migrate internationalized array from _key to language',\n documentTypes,\n migrate: {\n object(node) {\n const type = node['_type']\n const language = node[LANGUAGE_FIELD_NAME]\n\n if (\n typeof type !== 'string' ||\n !type.startsWith(INTERNATIONALIZED_PREFIX) ||\n !type.endsWith(VALUE_SUFFIX)\n ) {\n return undefined\n }\n\n // Already migrated: has a language field.\n if (language && typeof language === 'string') {\n return undefined\n }\n\n // Needs migration: _key holds the language id.\n const oldKey = node['_key']\n if (typeof oldKey !== 'string' || oldKey.length === 0) {\n return undefined\n }\n\n return set({\n ...node,\n _key: undefined,\n [LANGUAGE_FIELD_NAME]: oldKey,\n })\n },\n },\n })\n}\n"],"names":["LANGUAGE_FIELD_NAME","INTERNATIONALIZED_PREFIX","VALUE_SUFFIX","migrateToLanguageField","documentTypes","defineMigration","title","migrate","object","node","type","language","startsWith","endsWith","oldKey","length","set","_key","undefined"],"mappings":";AAKA,MAAMA,sBAAsB,YAMtBC,2BAA2B,0BAI3BC,eAAe;AAYd,SAASC,uBAAuBC,eAAyB;AAC9D,SAAOC,gBAAgB;AAAA,IACrBC,OAAO;AAAA,IACPF;AAAAA,IACAG,SAAS;AAAA,MACPC,OAAOC,MAAM;AACX,cAAMC,OAAOD,KAAK,OACZE,WAAWF,KAAKT,mBAAmB;AAWzC,YARE,OAAOU,QAAS,YAChB,CAACA,KAAKE,WAAWX,wBAAwB,KACzC,CAACS,KAAKG,SAASX,YAAY,KAMzBS,YAAY,OAAOA,YAAa;AAClC;AAIF,cAAMG,SAASL,KAAK;AACpB,YAAI,EAAA,OAAOK,UAAW,YAAYA,OAAOC,WAAW;AAIpD,iBAAOC,IAAI;AAAA,YACT,GAAGP;AAAAA,YACHQ,MAAMC;AAAAA,YACN,CAAClB,mBAAmB,GAAGc;AAAAA,UAAAA,CACxB;AAAA,MACH;AAAA,IAAA;AAAA,EACF,CACD;AACH;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sanity-plugin-internationalized-array",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0-canary.0",
|
|
4
4
|
"description": "Store localized fields in an array to save on attributes",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -24,12 +24,13 @@
|
|
|
24
24
|
"types": "./dist/index.d.ts",
|
|
25
25
|
"exports": {
|
|
26
26
|
".": "./dist/index.js",
|
|
27
|
+
"./migrations": "./dist/migrations/index.js",
|
|
27
28
|
"./package.json": "./package.json"
|
|
28
29
|
},
|
|
29
30
|
"dependencies": {
|
|
30
31
|
"@sanity/icons": "^3.7.4",
|
|
31
|
-
"@sanity/language-filter": "^4.0.6",
|
|
32
32
|
"@sanity/ui": "^3.1.11",
|
|
33
|
+
"@sanity/util": "^5.10.0",
|
|
33
34
|
"fast-deep-equal": "^3.1.3",
|
|
34
35
|
"lodash-es": "^4.17.23"
|
|
35
36
|
},
|
|
@@ -44,11 +45,12 @@
|
|
|
44
45
|
"jsdom": "^28.0.0",
|
|
45
46
|
"react": "^19.2.4",
|
|
46
47
|
"react-dom": "^19.2.4",
|
|
47
|
-
"sanity": "^5.
|
|
48
|
-
"@repo/
|
|
49
|
-
"@repo/
|
|
48
|
+
"sanity": "^5.10.0",
|
|
49
|
+
"@repo/package.config": "0.0.0",
|
|
50
|
+
"@repo/tsconfig": "0.0.0"
|
|
50
51
|
},
|
|
51
52
|
"peerDependencies": {
|
|
53
|
+
"@sanity/language-filter": "^4.1.0",
|
|
52
54
|
"react": "^19.2",
|
|
53
55
|
"react-dom": "^19.2",
|
|
54
56
|
"sanity": "^5"
|