@sanity/document-internationalization 0.3.3 → 0.3.6

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.
@@ -1831,12 +1831,16 @@ function createSanityReference(id) {
1831
1831
  var weak = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1832
1832
  return _objectSpread$2({
1833
1833
  _type: 'reference',
1834
- _ref: id
1834
+ _ref: id.replace("drafts.", "")
1835
1835
  }, weak === true ? {
1836
1836
  _weak: true
1837
1837
  } : {});
1838
1838
  }
1839
1839
 
1840
+ function getLanguageFromDocument(doc, config) {
1841
+ return (doc === null || doc === void 0 ? void 0 : doc[config.fieldNames.lang]) || config.base || null;
1842
+ }
1843
+
1840
1844
  var BATCH_SIZE = 50;
1841
1845
  function batch(_x, _x2) {
1842
1846
  return _batch.apply(this, arguments);
@@ -2169,7 +2173,7 @@ var fixIdStructureMismatchDocuments = /*#__PURE__*/function () {
2169
2173
  transaction = sanityClient.transaction();
2170
2174
  documentsChunk.forEach(function (d) {
2171
2175
  var baseId = getBaseIdFromId(d._id);
2172
- var lang = getLanguageFromId(d._id);
2176
+ var lang = getLanguageFromDocument(d, config);
2173
2177
 
2174
2178
  if (lang) {
2175
2179
  var newId = buildDocId(baseId, lang);
@@ -2252,6 +2256,8 @@ var fixLanguageFields = /*#__PURE__*/function () {
2252
2256
  break;
2253
2257
  }
2254
2258
 
2259
+ // @README keep the language from ID behavior
2260
+ // because in this case we expect the language field not to be available
2255
2261
  language = getLanguageFromId(d._id) || base;
2256
2262
  _context.next = 6;
2257
2263
  return sanityClient.patch(d._id, {
@@ -2320,7 +2326,7 @@ var fixTranslationRefs = /*#__PURE__*/function () {
2320
2326
 
2321
2327
  if (config.referenceBehavior !== ReferenceBehavior.DISABLED) {
2322
2328
  translatedRefs = ___default["default"].compact(relevantTranslations.map(function (doc) {
2323
- var lang = getLanguageFromId(doc._id);
2329
+ var lang = getLanguageFromDocument(doc, config);
2324
2330
  if (!lang) return null;
2325
2331
  return _objectSpread({
2326
2332
  _key: lang