@strapi/core 0.0.0-experimental.90ca9123352ed07e0a9cedaf4bcad1475e74137f → 0.0.0-experimental.a407f3bc8fb79a53cf7975140864526b6ddbac4b

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 (120) hide show
  1. package/dist/core-api/controller/collection-type.js.map +1 -1
  2. package/dist/core-api/controller/collection-type.mjs.map +1 -1
  3. package/dist/core-api/controller/single-type.js.map +1 -1
  4. package/dist/core-api/controller/single-type.mjs.map +1 -1
  5. package/dist/core-api/controller/transform.js +2 -2
  6. package/dist/core-api/controller/transform.js.map +1 -1
  7. package/dist/core-api/controller/transform.mjs +2 -2
  8. package/dist/core-api/controller/transform.mjs.map +1 -1
  9. package/dist/core-api/service/collection-type.d.ts.map +1 -1
  10. package/dist/core-api/service/collection-type.js.map +1 -1
  11. package/dist/core-api/service/collection-type.mjs.map +1 -1
  12. package/dist/core-api/service/single-type.d.ts +3 -2
  13. package/dist/core-api/service/single-type.d.ts.map +1 -1
  14. package/dist/core-api/service/single-type.js +15 -3
  15. package/dist/core-api/service/single-type.js.map +1 -1
  16. package/dist/core-api/service/single-type.mjs +15 -3
  17. package/dist/core-api/service/single-type.mjs.map +1 -1
  18. package/dist/services/document-service/common.d.ts +2 -2
  19. package/dist/services/document-service/common.d.ts.map +1 -1
  20. package/dist/services/document-service/common.js.map +1 -1
  21. package/dist/services/document-service/common.mjs.map +1 -1
  22. package/dist/services/document-service/document-engine.d.ts.map +1 -1
  23. package/dist/services/document-service/document-engine.js +12 -20
  24. package/dist/services/document-service/document-engine.js.map +1 -1
  25. package/dist/services/document-service/document-engine.mjs +13 -21
  26. package/dist/services/document-service/document-engine.mjs.map +1 -1
  27. package/dist/services/document-service/index.d.ts.map +1 -1
  28. package/dist/services/document-service/index.js +4 -4
  29. package/dist/services/document-service/index.js.map +1 -1
  30. package/dist/services/document-service/index.mjs +2 -2
  31. package/dist/services/document-service/index.mjs.map +1 -1
  32. package/dist/services/document-service/internationalization.d.ts +2 -1
  33. package/dist/services/document-service/internationalization.d.ts.map +1 -1
  34. package/dist/services/document-service/internationalization.js +14 -0
  35. package/dist/services/document-service/internationalization.js.map +1 -1
  36. package/dist/services/document-service/internationalization.mjs +15 -1
  37. package/dist/services/document-service/internationalization.mjs.map +1 -1
  38. package/dist/services/document-service/repositories/content-type.d.ts +3 -0
  39. package/dist/services/document-service/repositories/content-type.d.ts.map +1 -0
  40. package/dist/services/document-service/{collection-type.js → repositories/content-type.js} +27 -33
  41. package/dist/services/document-service/repositories/content-type.js.map +1 -0
  42. package/dist/services/document-service/{collection-type.mjs → repositories/content-type.mjs} +27 -33
  43. package/dist/services/document-service/repositories/content-type.mjs.map +1 -0
  44. package/dist/services/document-service/transform/fields.d.ts.map +1 -1
  45. package/dist/services/document-service/transform/fields.js +11 -10
  46. package/dist/services/document-service/transform/fields.js.map +1 -1
  47. package/dist/services/document-service/transform/fields.mjs +11 -10
  48. package/dist/services/document-service/transform/fields.mjs.map +1 -1
  49. package/dist/services/document-service/transform/id-transform.d.ts +2 -9
  50. package/dist/services/document-service/transform/id-transform.d.ts.map +1 -1
  51. package/dist/services/document-service/transform/id-transform.js +2 -32
  52. package/dist/services/document-service/transform/id-transform.js.map +1 -1
  53. package/dist/services/document-service/transform/id-transform.mjs +2 -32
  54. package/dist/services/document-service/transform/id-transform.mjs.map +1 -1
  55. package/dist/services/document-service/transform/populate.d.ts.map +1 -1
  56. package/dist/services/document-service/transform/populate.js +0 -10
  57. package/dist/services/document-service/transform/populate.js.map +1 -1
  58. package/dist/services/document-service/transform/populate.mjs +0 -10
  59. package/dist/services/document-service/transform/populate.mjs.map +1 -1
  60. package/dist/services/document-service/transform/relations/extract/data-ids.d.ts.map +1 -1
  61. package/dist/services/document-service/transform/relations/extract/data-ids.js +7 -4
  62. package/dist/services/document-service/transform/relations/extract/data-ids.js.map +1 -1
  63. package/dist/services/document-service/transform/relations/extract/data-ids.mjs +7 -4
  64. package/dist/services/document-service/transform/relations/extract/data-ids.mjs.map +1 -1
  65. package/dist/services/document-service/transform/relations/transform/data-ids.d.ts.map +1 -1
  66. package/dist/services/document-service/transform/relations/transform/data-ids.js +11 -9
  67. package/dist/services/document-service/transform/relations/transform/data-ids.js.map +1 -1
  68. package/dist/services/document-service/transform/relations/transform/data-ids.mjs +11 -9
  69. package/dist/services/document-service/transform/relations/transform/data-ids.mjs.map +1 -1
  70. package/dist/services/document-service/transform/relations/utils/data.d.ts +2 -4
  71. package/dist/services/document-service/transform/relations/utils/data.d.ts.map +1 -1
  72. package/dist/services/document-service/transform/relations/utils/data.js +1 -1
  73. package/dist/services/document-service/transform/relations/utils/data.js.map +1 -1
  74. package/dist/services/document-service/transform/relations/utils/data.mjs +1 -1
  75. package/dist/services/document-service/transform/relations/utils/data.mjs.map +1 -1
  76. package/dist/services/document-service/transform/relations/utils/i18n.d.ts +2 -2
  77. package/dist/services/document-service/transform/relations/utils/i18n.d.ts.map +1 -1
  78. package/dist/services/document-service/transform/relations/utils/i18n.js.map +1 -1
  79. package/dist/services/document-service/transform/relations/utils/i18n.mjs.map +1 -1
  80. package/dist/services/document-service/transform/relations/utils/types.d.ts +5 -1
  81. package/dist/services/document-service/transform/relations/utils/types.d.ts.map +1 -1
  82. package/dist/utils/transform-content-types-to-models.d.ts +174 -3
  83. package/dist/utils/transform-content-types-to-models.d.ts.map +1 -1
  84. package/dist/utils/transform-content-types-to-models.js +80 -41
  85. package/dist/utils/transform-content-types-to-models.js.map +1 -1
  86. package/dist/utils/transform-content-types-to-models.mjs +79 -41
  87. package/dist/utils/transform-content-types-to-models.mjs.map +1 -1
  88. package/package.json +14 -14
  89. package/dist/services/document-service/collection-type.d.ts +0 -4
  90. package/dist/services/document-service/collection-type.d.ts.map +0 -1
  91. package/dist/services/document-service/collection-type.js.map +0 -1
  92. package/dist/services/document-service/collection-type.mjs.map +0 -1
  93. package/dist/services/document-service/repository-factory.d.ts +0 -3
  94. package/dist/services/document-service/repository-factory.d.ts.map +0 -1
  95. package/dist/services/document-service/repository-factory.js +0 -12
  96. package/dist/services/document-service/repository-factory.js.map +0 -1
  97. package/dist/services/document-service/repository-factory.mjs +0 -12
  98. package/dist/services/document-service/repository-factory.mjs.map +0 -1
  99. package/dist/services/document-service/single-type.d.ts +0 -4
  100. package/dist/services/document-service/single-type.d.ts.map +0 -1
  101. package/dist/services/document-service/single-type.js +0 -92
  102. package/dist/services/document-service/single-type.js.map +0 -1
  103. package/dist/services/document-service/single-type.mjs +0 -92
  104. package/dist/services/document-service/single-type.mjs.map +0 -1
  105. package/dist/services/document-service/transform/filters.js +0 -49
  106. package/dist/services/document-service/transform/filters.js.map +0 -1
  107. package/dist/services/document-service/transform/filters.mjs +0 -49
  108. package/dist/services/document-service/transform/filters.mjs.map +0 -1
  109. package/dist/services/document-service/transform/relations/transform/output-ids.js +0 -26
  110. package/dist/services/document-service/transform/relations/transform/output-ids.js.map +0 -1
  111. package/dist/services/document-service/transform/relations/transform/output-ids.mjs +0 -26
  112. package/dist/services/document-service/transform/relations/transform/output-ids.mjs.map +0 -1
  113. package/dist/services/document-service/transform/sort.js +0 -44
  114. package/dist/services/document-service/transform/sort.js.map +0 -1
  115. package/dist/services/document-service/transform/sort.mjs +0 -44
  116. package/dist/services/document-service/transform/sort.mjs.map +0 -1
  117. package/dist/services/document-service/transform/utils.js +0 -23
  118. package/dist/services/document-service/transform/utils.js.map +0 -1
  119. package/dist/services/document-service/transform/utils.mjs +0 -23
  120. package/dist/services/document-service/transform/utils.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"data-ids.d.ts","sourceRoot":"","sources":["../../../../../../src/services/document-service/transform/relations/transform/data-ids.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,MAAM,EAAE,MAAM,eAAe,CAAC;AAKjE,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AA4GrC,QAAA,MAAM,uBAAuB,UACpB,KAAK,QACN,OAAO,MAAM,EAAE,GAAG,CAAC,QACnB;IACJ,GAAG,EAAE,OAAO,GAAG,CAAC,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,qDAwCF,CAAC;AAEF,OAAO,EAAE,uBAAuB,EAAE,CAAC"}
1
+ {"version":3,"file":"data-ids.d.ts","sourceRoot":"","sources":["../../../../../../src/services/document-service/transform/relations/transform/data-ids.ts"],"names":[],"mappings":"AAEA,OAAO,EAA4B,MAAM,EAAE,MAAM,eAAe,CAAC;AAKjE,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AA8GrC,QAAA,MAAM,uBAAuB,UACpB,KAAK,QACN,OAAO,MAAM,EAAE,GAAG,CAAC,QACnB;IACJ,GAAG,EAAE,OAAO,GAAG,CAAC,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,qDAwCF,CAAC;AAEF,OAAO,EAAE,uBAAuB,EAAE,CAAC"}
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const strapiUtils = require("@strapi/utils");
4
3
  const _ = require("lodash/fp");
4
+ const strapiUtils = require("@strapi/utils");
5
5
  const data = require("../utils/data.js");
6
6
  const i18n = require("../utils/i18n.js");
7
7
  const isNumeric = (value) => {
8
+ if (Array.isArray(value))
9
+ return false;
8
10
  const parsed = parseInt(value, 10);
9
11
  return !Number.isNaN(parsed);
10
12
  };
@@ -19,12 +21,12 @@ const transformPrimitive = (relation, getId) => {
19
21
  return getId(relation);
20
22
  }
21
23
  if (data.isLongHand(relation)) {
22
- if (isNumeric(relation.id))
24
+ if (!("documentId" in relation))
23
25
  return relation;
24
- const id = getId(relation.id, relation.locale);
25
- if (!id)
26
+ const entryId = getId(relation.documentId, relation.locale);
27
+ if (!entryId)
26
28
  return void 0;
27
- return { ...relation, id };
29
+ return { ...relation, id: entryId };
28
30
  }
29
31
  if (Array.isArray(relation)) {
30
32
  return relation.map((item) => transformPrimitive(item, getId)).filter(Boolean);
@@ -50,11 +52,11 @@ const transformRelationIdsVisitor = (relation, getId) => {
50
52
  return relation2;
51
53
  const { position } = relation2;
52
54
  if (position?.before) {
53
- const { id } = transformPrimitive({ ...position, id: position.before }, getId);
55
+ const { id } = transformPrimitive({ ...position, documentId: position.before }, getId);
54
56
  position.before = id;
55
57
  }
56
58
  if (position?.after) {
57
- const { id } = transformPrimitive({ ...position, id: position.after }, getId);
59
+ const { id } = transformPrimitive({ ...position, documentId: position.after }, getId);
58
60
  position.after = id;
59
61
  }
60
62
  return relation2;
@@ -88,7 +90,7 @@ const transformDataIdsVisitor = (idMap, data2, opts) => {
88
90
  uid: target,
89
91
  documentId,
90
92
  locale: i18n.getRelationTargetLocale(
91
- { id: documentId, locale },
93
+ { documentId, locale },
92
94
  {
93
95
  targetUid: target,
94
96
  sourceUid: opts.uid,
@@ -101,7 +103,7 @@ const transformDataIdsVisitor = (idMap, data2, opts) => {
101
103
  return entryId;
102
104
  if (opts.allowMissingId)
103
105
  return null;
104
- throw new Error(`Document with id "${documentId}" not found`);
106
+ throw new strapiUtils.errors.ValidationError(`Document with id "${documentId}" not found`);
105
107
  };
106
108
  const newRelation = transformRelationIdsVisitor(value, getId);
107
109
  set(key, newRelation);
@@ -1 +1 @@
1
- {"version":3,"file":"data-ids.js","sources":["../../../../../../src/services/document-service/transform/relations/transform/data-ids.ts"],"sourcesContent":["import { EntityService, Attribute, Common } from '@strapi/types';\nimport { traverseEntity } from '@strapi/utils';\nimport { isObject, isNil } from 'lodash/fp';\nimport { ShortHand, LongHand, ID, GetId } from '../utils/types';\nimport { isShortHand, isLongHand } from '../utils/data';\nimport { IdMap } from '../../id-map';\nimport { getRelationTargetLocale } from '../utils/i18n';\n\nconst isNumeric = (value: any): value is number => {\n const parsed = parseInt(value, 10);\n return !Number.isNaN(parsed);\n};\n\nconst transformPrimitive = <T extends ShortHand | LongHand>(\n relation: T | T[] | null | undefined,\n getId: GetId\n): T | T[] | undefined => {\n // If id value is a number, return it as is, it's already an entry id\n if (isNumeric(relation)) {\n return relation;\n }\n\n // null\n if (isNil(relation)) {\n return relation as T | undefined;\n }\n\n // id\n if (isShortHand(relation)) {\n return getId(relation) as T;\n }\n\n // { id }\n if (isLongHand(relation)) {\n // It's already an entry id\n if (isNumeric(relation.id)) return relation;\n\n // @ts-expect-error - TODO: Add relation type\n const id = getId(relation.id, relation.locale) as T;\n\n // If the id is not found, return undefined\n if (!id) return undefined;\n\n return { ...(relation as object), id } as T;\n }\n\n // id[]\n if (Array.isArray(relation)) {\n return relation.map((item) => transformPrimitive(item, getId)).filter(Boolean) as T[];\n }\n return undefined;\n};\n\nconst transformRelationIdsVisitor = <T extends Attribute.RelationKind.Any>(\n relation: EntityService.Params.Attribute.RelationInputValue<T>,\n getId: GetId\n): EntityService.Params.Attribute.RelationInputValue<T> => {\n const map = transformPrimitive(relation as any, getId);\n if (map) return map;\n\n if (!isObject(relation)) return relation;\n\n // set: id[]\n // what if result of mapPrimitive is undefined?\n if ('set' in relation) {\n relation.set = transformPrimitive(relation.set as any, getId);\n }\n if ('disconnect' in relation) {\n relation.disconnect = transformPrimitive(relation.disconnect as any, getId);\n }\n\n if ('connect' in relation) {\n // connect: id[] | { id } | ...\n relation.connect = transformPrimitive(relation.connect as any, getId);\n\n const mapPosition = (relation: any) => {\n if (isShortHand(relation) || !('position' in relation)) return relation;\n\n const { position } = relation;\n\n // { connect: { id: id, position: { before: id } } }\n if (position?.before) {\n const { id } = transformPrimitive({ ...position, id: position.before }, getId);\n position.before = id;\n }\n\n // { connect: { id: id, position: { after: id } } }\n if (position?.after) {\n const { id } = transformPrimitive({ ...position, id: position.after }, getId);\n position.after = id;\n }\n\n return relation;\n };\n\n if (Array.isArray(relation.connect)) {\n relation.connect = relation.connect.map(mapPosition);\n } else {\n relation.connect = mapPosition(relation.connect);\n }\n }\n\n return relation;\n};\n\nconst EXCLUDED_FIELDS = [\n 'createdBy',\n 'updatedBy',\n 'localizations',\n 'strapi_stage',\n 'strapi_assignee',\n];\n\nconst transformDataIdsVisitor = (\n idMap: IdMap,\n data: Record<string, any>,\n opts: {\n uid: Common.UID.Schema;\n locale?: string | null;\n isDraft?: boolean;\n allowMissingId?: boolean; // Whether to ignore missing ids and not throw any error\n }\n) => {\n return traverseEntity(\n ({ key, value, attribute }, { set }) => {\n // Find relational attributes, and return the document ids\n if (attribute.type === 'relation') {\n const target = attribute.target;\n // TODO: Handle polymorphic relations\n if (!target) return;\n // TODO: Handle this differently\n if (EXCLUDED_FIELDS.includes(key)) return;\n\n const getId = (documentId: ID, locale?: string): ID | null => {\n const entryId = idMap.get({\n uid: target,\n documentId: documentId as string,\n locale: getRelationTargetLocale(\n { id: documentId, locale },\n {\n targetUid: target as Common.UID.Schema,\n sourceUid: opts.uid,\n sourceLocale: opts.locale,\n }\n ),\n isDraft: opts.isDraft,\n });\n\n if (entryId) return entryId;\n if (opts.allowMissingId) return null;\n\n throw new Error(`Document with id \"${documentId}\" not found`);\n };\n\n const newRelation = transformRelationIdsVisitor(value as any, getId);\n set(key, newRelation as any);\n }\n },\n { schema: strapi.getModel(opts.uid) },\n data\n );\n};\n\nexport { transformDataIdsVisitor };\n"],"names":["isNil","isShortHand","isLongHand","isObject","relation","data","traverseEntity","getRelationTargetLocale"],"mappings":";;;;;;AAQA,MAAM,YAAY,CAAC,UAAgC;AAC3C,QAAA,SAAS,SAAS,OAAO,EAAE;AAC1B,SAAA,CAAC,OAAO,MAAM,MAAM;AAC7B;AAEA,MAAM,qBAAqB,CACzB,UACA,UACwB;AAEpB,MAAA,UAAU,QAAQ,GAAG;AAChB,WAAA;AAAA,EACT;AAGI,MAAAA,EAAAA,MAAM,QAAQ,GAAG;AACZ,WAAA;AAAA,EACT;AAGI,M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AA,IAAA;AAGT,QAAI,MAAM,QAAQ,SAAS,OAAO,GAAG;AACnC,eAAS,UAAU,SAAS,QAAQ,IAAI,WAAW;AAAA,IAAA,OAC9C;AACI,eAAA,UAAU,YAAY,SAAS,OAAO;AAAA,IACjD;AAAA,EACF;AAEO,SAAA;AACT;AAEA,MAAM,kBAAkB;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,0BAA0B,CAC9B,OACAC,OACA,SAMG;AACI,SAAAC,YAAA;AAAA,IACL,CAAC,EAAE,KAAK,OAAO,aAAa,EAAE,UAAU;AAElC,UAAA,UAAU,SAAS,YAAY;AACjC,cAAM,SAAS,UAAU;AAEzB,YAAI,CAAC;AAAQ;AAET,YAAA,gBAAgB,SAAS,GAAG;AAAG;AAE7B,cAAA,QAAQ,CAAC,YAAgB,WAA+B;AACtD,gBAAA,UAAU,MAAM,IAAI;AAAA,YACxB,KAAK;AAAA,YACL;AAAA,YACA,QAAQC,KAAA;AAAA,cACN,EAAE,IAAI,YAAY,OAAO;AAAA,cACzB;AAAA,gBACE,WAAW;AAAA,gBACX,WAAW,KAAK;AAAA,gBAChB,cAAc,KAAK;AAAA,cACrB;AAAA,YACF;AAAA,YACA,SAAS,KAAK;AAAA,UAAA,CACf;AAEG,cAAA;AAAgB,mBAAA;AACpB,cAAI,KAAK;AAAuB,mBAAA;AAEhC,gBAAM,IAAI,MAAM,qBAAqB,UAAU,aAAa;AAAA,QAAA;AAGxD,cAAA,cAAc,4BAA4B,OAAc,KAAK;AACnE,YAAI,KAAK,WAAkB;AAAA,MAC7B;AAAA,IACF;AAAA,IACA,EAAE,QAAQ,OAAO,SAAS,KAAK,GAAG,EAAE;AAAA,IACpCF;AAAA,EAAA;AAEJ;;"}
1
+ {"version":3,"file":"data-ids.js","sources":["../../../../../../src/services/document-service/transform/relations/transform/data-ids.ts"],"sourcesContent":["import { isObject, isNil } from 'lodash/fp';\n\nimport { EntityService, Attribute, Common } from '@strapi/types';\nimport { traverseEntity, errors } from '@strapi/utils';\n\nimport { ShortHand, LongHand, ID, GetId } from '../utils/types';\nimport { isShortHand, isLongHand } from '../utils/data';\nimport { IdMap } from '../../id-map';\nimport { getRelationTargetLocale } from '../utils/i18n';\n\nconst isNumeric = (value: any): value is number => {\n if (Array.isArray(value)) return false; // Handle [1, 'docId'] case\n const parsed = parseInt(value, 10);\n return !Number.isNaN(parsed);\n};\n\nconst transformPrimitive = <T extends ShortHand | LongHand>(\n relation: T | T[] | null | undefined,\n getId: GetId\n): T | T[] | undefined => {\n // TODO: Remove this, we should use the long hand version with 'id' for this case\n // If id value is a number, return it as is, it's already an entry id\n if (isNumeric(relation)) {\n return relation;\n }\n\n // null\n if (isNil(relation)) {\n return relation as T | undefined;\n }\n\n // id\n if (isShortHand(relation)) {\n return getId(relation) as T;\n }\n\n // { id }\n if (isLongHand(relation)) {\n // If the id is already an entry id, return it as is\n if (!('documentId' in relation)) return relation;\n\n // @ts-expect-error - TODO: Add relation type\n const entryId = getId(relation.documentId, relation.locale) as T;\n\n // If the id is not found, return undefined\n if (!entryId) return undefined;\n\n return { ...(relation as object), id: entryId } as T;\n }\n\n // id[]\n if (Array.isArray(relation)) {\n return relation.map((item) => transformPrimitive(item, getId)).filter(Boolean) as T[];\n }\n return undefined;\n};\n\nconst transformRelationIdsVisitor = <T extends Attribute.RelationKind.Any>(\n relation: EntityService.Params.Attribute.RelationInputValue<T>,\n getId: GetId\n): EntityService.Params.Attribute.RelationInputValue<T> => {\n const map = transformPrimitive(relation as any, getId);\n if (map) return map;\n\n if (!isObject(relation)) return relation;\n\n // set: id[]\n // what if result of mapPrimitive is undefined?\n if ('set' in relation) {\n relation.set = transformPrimitive(relation.set as any, getId);\n }\n if ('disconnect' in relation) {\n relation.disconnect = transformPrimitive(relation.disconnect as any, getId);\n }\n\n if ('connect' in relation) {\n // connect: id[] | { id } | ...\n relation.connect = transformPrimitive(relation.connect as any, getId);\n\n const mapPosition = (relation: any) => {\n if (isShortHand(relation) || !('position' in relation)) return relation;\n\n const { position } = relation;\n\n // { connect: { id: id, position: { before: id } } }\n if (position?.before) {\n const { id } = transformPrimitive({ ...position, documentId: position.before }, getId);\n position.before = id;\n }\n\n // { connect: { id: id, position: { after: id } } }\n if (position?.after) {\n const { id } = transformPrimitive({ ...position, documentId: position.after }, getId);\n position.after = id;\n }\n\n return relation;\n };\n\n if (Array.isArray(relation.connect)) {\n relation.connect = relation.connect.map(mapPosition);\n } else {\n relation.connect = mapPosition(relation.connect);\n }\n }\n\n return relation;\n};\n\nconst EXCLUDED_FIELDS = [\n 'createdBy',\n 'updatedBy',\n 'localizations',\n 'strapi_stage',\n 'strapi_assignee',\n];\n\nconst transformDataIdsVisitor = (\n idMap: IdMap,\n data: Record<string, any>,\n opts: {\n uid: Common.UID.Schema;\n locale?: string | null;\n isDraft?: boolean;\n allowMissingId?: boolean; // Whether to ignore missing ids and not throw any error\n }\n) => {\n return traverseEntity(\n ({ key, value, attribute }, { set }) => {\n // Find relational attributes, and return the document ids\n if (attribute.type === 'relation') {\n const target = attribute.target;\n // TODO: Handle polymorphic relations\n if (!target) return;\n // TODO: Handle this differently\n if (EXCLUDED_FIELDS.includes(key)) return;\n\n const getId = (documentId: ID, locale?: string): ID | null => {\n const entryId = idMap.get({\n uid: target,\n documentId,\n locale: getRelationTargetLocale(\n { documentId, locale },\n {\n targetUid: target as Common.UID.Schema,\n sourceUid: opts.uid,\n sourceLocale: opts.locale,\n }\n ),\n isDraft: opts.isDraft,\n });\n\n if (entryId) return entryId;\n if (opts.allowMissingId) return null;\n\n throw new errors.ValidationError(`Document with id \"${documentId}\" not found`);\n };\n\n const newRelation = transformRelationIdsVisitor(value as any, getId);\n set(key, newRelation as any);\n }\n },\n { schema: strapi.getModel(opts.uid) },\n data\n );\n};\n\nexport { transformDataIdsVisitor };\n"],"names":["isNil","isShortHand","isLongHand","isObject","relation","data","traverseEntity","getRelationTargetLocale","errors"],"mappings":";;;;;;AAUA,MAAM,Y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UAAU,aAAa;AAAA,QAAA;AAGzE,cAAA,cAAc,4BAA4B,OAAc,KAAK;AACnE,YAAI,KAAK,WAAkB;AAAA,MAC7B;AAAA,IACF;AAAA,IACA,EAAE,QAAQ,OAAO,SAAS,KAAK,GAAG,EAAE;AAAA,IACpCH;AAAA,EAAA;AAEJ;;"}
@@ -1,8 +1,10 @@
1
- import { traverseEntity } from "@strapi/utils";
2
1
  import { isObject, isNil } from "lodash/fp";
2
+ import { traverseEntity, errors } from "@strapi/utils";
3
3
  import { isShortHand, isLongHand } from "../utils/data.mjs";
4
4
  import { getRelationTargetLocale } from "../utils/i18n.mjs";
5
5
  const isNumeric = (value) => {
6
+ if (Array.isArray(value))
7
+ return false;
6
8
  const parsed = parseInt(value, 10);
7
9
  return !Number.isNaN(parsed);
8
10
  };
@@ -17,12 +19,12 @@ const transformPrimitive = (relation, getId) => {
17
19
  return getId(relation);
18
20
  }
19
21
  if (isLongHand(relation)) {
20
- if (isNumeric(relation.id))
22
+ if (!("documentId" in relation))
21
23
  return relation;
22
- const id = getId(relation.id, relation.locale);
23
- if (!id)
24
+ const entryId = getId(relation.documentId, relation.locale);
25
+ if (!entryId)
24
26
  return void 0;
25
- return { ...relation, id };
27
+ return { ...relation, id: entryId };
26
28
  }
27
29
  if (Array.isArray(relation)) {
28
30
  return relation.map((item) => transformPrimitive(item, getId)).filter(Boolean);
@@ -48,11 +50,11 @@ const transformRelationIdsVisitor = (relation, getId) => {
48
50
  return relation2;
49
51
  const { position } = relation2;
50
52
  if (position?.before) {
51
- const { id } = transformPrimitive({ ...position, id: position.before }, getId);
53
+ const { id } = transformPrimitive({ ...position, documentId: position.before }, getId);
52
54
  position.before = id;
53
55
  }
54
56
  if (position?.after) {
55
- const { id } = transformPrimitive({ ...position, id: position.after }, getId);
57
+ const { id } = transformPrimitive({ ...position, documentId: position.after }, getId);
56
58
  position.after = id;
57
59
  }
58
60
  return relation2;
@@ -86,7 +88,7 @@ const transformDataIdsVisitor = (idMap, data, opts) => {
86
88
  uid: target,
87
89
  documentId,
88
90
  locale: getRelationTargetLocale(
89
- { id: documentId, locale },
91
+ { documentId, locale },
90
92
  {
91
93
  targetUid: target,
92
94
  sourceUid: opts.uid,
@@ -99,7 +101,7 @@ const transformDataIdsVisitor = (idMap, data, opts) => {
99
101
  return entryId;
100
102
  if (opts.allowMissingId)
101
103
  return null;
102
- throw new Error(`Document with id "${documentId}" not found`);
104
+ throw new errors.ValidationError(`Document with id "${documentId}" not found`);
103
105
  };
104
106
  const newRelation = transformRelationIdsVisitor(value, getId);
105
107
  set(key, newRelation);
@@ -1 +1 @@
1
- {"version":3,"file":"data-ids.mjs","sources":["../../../../../../src/services/document-service/transform/relations/transform/data-ids.ts"],"sourcesContent":["import { EntityService, Attribute, Common } from '@strapi/types';\nimport { traverseEntity } from '@strapi/utils';\nimport { isObject, isNil } from 'lodash/fp';\nimport { ShortHand, LongHand, ID, GetId } from '../utils/types';\nimport { isShortHand, isLongHand } from '../utils/data';\nimport { IdMap } from '../../id-map';\nimport { getRelationTargetLocale } from '../utils/i18n';\n\nconst isNumeric = (value: any): value is number => {\n const parsed = parseInt(value, 10);\n return !Number.isNaN(parsed);\n};\n\nconst transformPrimitive = <T extends ShortHand | LongHand>(\n relation: T | T[] | null | undefined,\n getId: GetId\n): T | T[] | undefined => {\n // If id value is a number, return it as is, it's already an entry id\n if (isNumeric(relation)) {\n return relation;\n }\n\n // null\n if (isNil(relation)) {\n return relation as T | undefined;\n }\n\n // id\n if (isShortHand(relation)) {\n return getId(relation) as T;\n }\n\n // { id }\n if (isLongHand(relation)) {\n // It's already an entry id\n if (isNumeric(relation.id)) return relation;\n\n // @ts-expect-error - TODO: Add relation type\n const id = getId(relation.id, relation.locale) as T;\n\n // If the id is not found, return undefined\n if (!id) return undefined;\n\n return { ...(relation as object), id } as T;\n }\n\n // id[]\n if (Array.isArray(relation)) {\n return relation.map((item) => transformPrimitive(item, getId)).filter(Boolean) as T[];\n }\n return undefined;\n};\n\nconst transformRelationIdsVisitor = <T extends Attribute.RelationKind.Any>(\n relation: EntityService.Params.Attribute.RelationInputValue<T>,\n getId: GetId\n): EntityService.Params.Attribute.RelationInputValue<T> => {\n const map = transformPrimitive(relation as any, getId);\n if (map) return map;\n\n if (!isObject(relation)) return relation;\n\n // set: id[]\n // what if result of mapPrimitive is undefined?\n if ('set' in relation) {\n relation.set = transformPrimitive(relation.set as any, getId);\n }\n if ('disconnect' in relation) {\n relation.disconnect = transformPrimitive(relation.disconnect as any, getId);\n }\n\n if ('connect' in relation) {\n // connect: id[] | { id } | ...\n relation.connect = transformPrimitive(relation.connect as any, getId);\n\n const mapPosition = (relation: any) => {\n if (isShortHand(relation) || !('position' in relation)) return relation;\n\n const { position } = relation;\n\n // { connect: { id: id, position: { before: id } } }\n if (position?.before) {\n const { id } = transformPrimitive({ ...position, id: position.before }, getId);\n position.before = id;\n }\n\n // { connect: { id: id, position: { after: id } } }\n if (position?.after) {\n const { id } = transformPrimitive({ ...position, id: position.after }, getId);\n position.after = id;\n }\n\n return relation;\n };\n\n if (Array.isArray(relation.connect)) {\n relation.connect = relation.connect.map(mapPosition);\n } else {\n relation.connect = mapPosition(relation.connect);\n }\n }\n\n return relation;\n};\n\nconst EXCLUDED_FIELDS = [\n 'createdBy',\n 'updatedBy',\n 'localizations',\n 'strapi_stage',\n 'strapi_assignee',\n];\n\nconst transformDataIdsVisitor = (\n idMap: IdMap,\n data: Record<string, any>,\n opts: {\n uid: Common.UID.Schema;\n locale?: string | null;\n isDraft?: boolean;\n allowMissingId?: boolean; // Whether to ignore missing ids and not throw any error\n }\n) => {\n return traverseEntity(\n ({ key, value, attribute }, { set }) => {\n // Find relational attributes, and return the document ids\n if (attribute.type === 'relation') {\n const target = attribute.target;\n // TODO: Handle polymorphic relations\n if (!target) return;\n // TODO: Handle this differently\n if (EXCLUDED_FIELDS.includes(key)) return;\n\n const getId = (documentId: ID, locale?: string): ID | null => {\n const entryId = idMap.get({\n uid: target,\n documentId: documentId as string,\n locale: getRelationTargetLocale(\n { id: documentId, locale },\n {\n targetUid: target as Common.UID.Schema,\n sourceUid: opts.uid,\n sourceLocale: opts.locale,\n }\n ),\n isDraft: opts.isDraft,\n });\n\n if (entryId) return entryId;\n if (opts.allowMissingId) return null;\n\n throw new Error(`Document with id \"${documentId}\" not found`);\n };\n\n const newRelation = transformRelationIdsVisitor(value as any, getId);\n set(key, newRelation as any);\n }\n },\n { schema: strapi.getModel(opts.uid) },\n data\n );\n};\n\nexport { transformDataIdsVisitor };\n"],"names":["relation"],"mappings":";;;;AAQA,MAAM,YAAY,CAAC,UAAgC;AAC3C,QAAA,SAAS,SAAS,OAAO,EAAE;AAC1B,SAAA,CAAC,OAAO,MAAM,MAAM;AAC7B;AAEA,MAAM,qBAAqB,CACzB,UACA,UACwB;AAEpB,MAAA,UAAU,QAAQ,GAAG;AAChB,WAAA;AAAA,EACT;AAGI,MAAA,MAAM,QAAQ,GAAG;AACZ,WAAA;AAAA,EACT;AAGI,MAAA,YAAY,QAAQ,GAAG;AACzB,WAAO,MAAM,QAAQ;AAAA,EACvB;AAGI,MAAA,WAAW,QAAQ,GAAG;AAEpB,QAAA,UAAU,SAAS,EAAE;AAAU,aAAA;AAGnC,UAAM,KAAK,MAAM,SAAS,IAAI,SAAS,MAAM;AAG7C,QAAI,CAAC;AAAW,aAAA;AAET,WAAA,EAAE,GAAI,UAAqB;EACpC;AAGI,MAAA,MAAM,QAAQ,QAAQ,GAAG;AACpB,WAAA,SAAS,IAAI,CAAC,SAAS,mBAAmB,MAAM,KAAK,CAAC,EAAE,OAAO,OAAO;AAAA,EAC/E;AACO,SAAA;AACT;AAEA,MAAM,8BAA8B,CAClC,UACA,UACyD;AACnD,QAAA,MAAM,mBAAmB,UAAiB,KAAK;AACjD,MAAA;AAAY,WAAA;AAEZ,MAAA,CAAC,SAAS,QAAQ;AAAU,WAAA;AAIhC,MAAI,SAAS,UAAU;AACrB,aAAS,MAAM,mBAAmB,SAAS,KAAY,KAAK;AAAA,EAC9D;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,cACzB;AAAA,gBACE,WAAW;AAAA,gBACX,WAAW,KAAK;AAAA,gBAChB,cAAc,KAAK;AAAA,cACrB;AAAA,YACF;AAAA,YACA,SAAS,KAAK;AAAA,UAAA,CACf;AAEG,cAAA;AAAgB,mBAAA;AACpB,cAAI,KAAK;AAAuB,mBAAA;AAEhC,gBAAM,IAAI,MAAM,qBAAqB,UAAU,aAAa;AAAA,QAAA;AAGxD,cAAA,cAAc,4BAA4B,OAAc,KAAK;AACnE,YAAI,KAAK,WAAkB;AAAA,MAC7B;AAAA,IACF;AAAA,IACA,EAAE,QAAQ,OAAO,SAAS,KAAK,GAAG,EAAE;AAAA,IACpC;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"data-ids.mjs","sources":["../../../../../../src/services/document-service/transform/relations/transform/data-ids.ts"],"sourcesContent":["import { isObject, isNil } from 'lodash/fp';\n\nimport { EntityService, Attribute, Common } from '@strapi/types';\nimport { traverseEntity, errors } from '@strapi/utils';\n\nimport { ShortHand, LongHand, ID, GetId } from '../utils/types';\nimport { isShortHand, isLongHand } from '../utils/data';\nimport { IdMap } from '../../id-map';\nimport { getRelationTargetLocale } from '../utils/i18n';\n\nconst isNumeric = (value: any): value is number => {\n if (Array.isArray(value)) return false; // Handle [1, 'docId'] case\n const parsed = parseInt(value, 10);\n return !Number.isNaN(parsed);\n};\n\nconst transformPrimitive = <T extends ShortHand | LongHand>(\n relation: T | T[] | null | undefined,\n getId: GetId\n): T | T[] | undefined => {\n // TODO: Remove this, we should use the long hand version with 'id' for this case\n // If id value is a number, return it as is, it's already an entry id\n if (isNumeric(relation)) {\n return relation;\n }\n\n // null\n if (isNil(relation)) {\n return relation as T | undefined;\n }\n\n // id\n if (isShortHand(relation)) {\n return getId(relation) as T;\n }\n\n // { id }\n if (isLongHand(relation)) {\n // If the id is already an entry id, return it as is\n if (!('documentId' in relation)) return relation;\n\n // @ts-expect-error - TODO: Add relation type\n const entryId = getId(relation.documentId, relation.locale) as T;\n\n // If the id is not found, return undefined\n if (!entryId) return undefined;\n\n return { ...(relation as object), id: entryId } as T;\n }\n\n // id[]\n if (Array.isArray(relation)) {\n return relation.map((item) => transformPrimitive(item, getId)).filter(Boolean) as T[];\n }\n return undefined;\n};\n\nconst transformRelationIdsVisitor = <T extends Attribute.RelationKind.Any>(\n relation: EntityService.Params.Attribute.RelationInputValue<T>,\n getId: GetId\n): EntityService.Params.Attribute.RelationInputValue<T> => {\n const map = transformPrimitive(relation as any, getId);\n if (map) return map;\n\n if (!isObject(relation)) return relation;\n\n // set: id[]\n // what if result of mapPrimitive is undefined?\n if ('set' in relation) {\n relation.set = transformPrimitive(relation.set as any, getId);\n }\n if ('disconnect' in relation) {\n relation.disconnect = transformPrimitive(relation.disconnect as any, getId);\n }\n\n if ('connect' in relation) {\n // connect: id[] | { id } | ...\n relation.connect = transformPrimitive(relation.connect as any, getId);\n\n const mapPosition = (relation: any) => {\n if (isShortHand(relation) || !('position' in relation)) return relation;\n\n const { position } = relation;\n\n // { connect: { id: id, position: { before: id } } }\n if (position?.before) {\n const { id } = transformPrimitive({ ...position, documentId: position.before }, getId);\n position.before = id;\n }\n\n // { connect: { id: id, position: { after: id } } }\n if (position?.after) {\n const { id } = transformPrimitive({ ...position, documentId: position.after }, getId);\n position.after = id;\n }\n\n return relation;\n };\n\n if (Array.isArray(relation.connect)) {\n relation.connect = relation.connect.map(mapPosition);\n } else {\n relation.connect = mapPosition(relation.connect);\n }\n }\n\n return relation;\n};\n\nconst EXCLUDED_FIELDS = [\n 'createdBy',\n 'updatedBy',\n 'localizations',\n 'strapi_stage',\n 'strapi_assignee',\n];\n\nconst transformDataIdsVisitor = (\n idMap: IdMap,\n data: Record<string, any>,\n opts: {\n uid: Common.UID.Schema;\n locale?: string | null;\n isDraft?: boolean;\n allowMissingId?: boolean; // Whether to ignore missing ids and not throw any error\n }\n) => {\n return traverseEntity(\n ({ key, value, attribute }, { set }) => {\n // Find relational attributes, and return the document ids\n if (attribute.type === 'relation') {\n const target = attribute.target;\n // TODO: Handle polymorphic relations\n if (!target) return;\n // TODO: Handle this differently\n if (EXCLUDED_FIELDS.includes(key)) return;\n\n const getId = (documentId: ID, locale?: string): ID | null => {\n const entryId = idMap.get({\n uid: target,\n documentId,\n locale: getRelationTargetLocale(\n { documentId, locale },\n {\n targetUid: target as Common.UID.Schema,\n sourceUid: opts.uid,\n sourceLocale: opts.locale,\n }\n ),\n isDraft: opts.isDraft,\n });\n\n if (entryId) return entryId;\n if (opts.allowMissingId) return null;\n\n throw new errors.ValidationError(`Document with id \"${documentId}\" not found`);\n };\n\n const newRelation = transformRelationIdsVisitor(value as any, getId);\n set(key, newRelation as any);\n }\n },\n { schema: strapi.getModel(opts.uid) },\n data\n );\n};\n\nexport { transformDataIdsVisitor };\n"],"names":["relation"],"mappings":";;;;AAUA,MAAM,YAAY,CAAC,UAAgC;AAC7C,MAAA,MAAM,QAAQ,KAAK;AAAU,WAAA;AAC3B,QAAA,SAAS,SAAS,OAAO,EAAE;AAC1B,SAAA,CAAC,OAAO,MAAM,MAAM;AAC7B;AAEA,MAAM,qBAAqB,CACzB,UACA,UACwB;AAGpB,MAAA,UAAU,QAAQ,GAAG;AAChB,WAAA;AAAA,EACT;AAGI,MAAA,MAAM,QAAQ,GAAG;AACZ,WAAA;AAAA,EACT;AAGI,MAAA,YAAY,QAAQ,GAAG;AACzB,WAAO,MAAM,QAAQ;AAAA,EACvB;AAGI,MAAA,WAAW,QAAQ,GAAG;AAExB,QAAI,EAAE,gBAAgB;AAAkB,aAAA;AAGxC,UAAM,UAAU,MAAM,SAAS,YAAY,SAAS,MAAM;AAG1D,QAAI,CAAC;AAAgB,aAAA;AAErB,WAAO,EAAE,GAAI,UAAqB,IAAI,QAAQ;AAAA,EAChD;AAGI,MAAA,MAAM,QAAQ,QAAQ,GAAG;AACpB,WAAA,SAAS,IAAI,CAAC,SAAS,mBAAmB,MAAM,KAAK,CAAC,EAAE,OAAO,OAAO;AAAA,EAC/E;AACO,SAAA;AACT;AAEA,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EzB,YAAI,CAAC;AAAQ;AAET,YAAA,gBAAgB,SAAS,GAAG;AAAG;AAE7B,cAAA,QAAQ,CAAC,YAAgB,WAA+B;AACtD,gBAAA,UAAU,MAAM,IAAI;AAAA,YACxB,KAAK;AAAA,YACL;AAAA,YACA,QAAQ;AAAA,cACN,EAAE,YAAY,OAAO;AAAA,cACrB;AAAA,gBACE,WAAW;AAAA,gBACX,WAAW,KAAK;AAAA,gBAChB,cAAc,KAAK;AAAA,cACrB;AAAA,YACF;AAAA,YACA,SAAS,KAAK;AAAA,UAAA,CACf;AAEG,cAAA;AAAgB,mBAAA;AACpB,cAAI,KAAK;AAAuB,mBAAA;AAEhC,gBAAM,IAAI,OAAO,gBAAgB,qBAAqB,UAAU,aAAa;AAAA,QAAA;AAGzE,cAAA,cAAc,4BAA4B,OAAc,KAAK;AACnE,YAAI,KAAK,WAAkB;AAAA,MAC7B;AAAA,IACF;AAAA,IACA,EAAE,QAAQ,OAAO,SAAS,KAAK,GAAG,EAAE;AAAA,IACpC;AAAA,EAAA;AAEJ;"}
@@ -1,6 +1,4 @@
1
- import { ID } from './types';
1
+ import { ID, LongHand } from './types';
2
2
  export declare const isShortHand: (relation: any) => relation is ID;
3
- export declare const isLongHand: (relation: any) => relation is {
4
- id: ID;
5
- };
3
+ export declare const isLongHand: (relation: any) => relation is LongHand;
6
4
  //# sourceMappingURL=data.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../../../../../src/services/document-service/transform/relations/utils/data.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAE7B,eAAO,MAAM,WAAW,aAAc,GAAG,mBAExC,CAAC;AAEF,eAAO,MAAM,UAAU,aAAc,GAAG;QAAqB,EAAE;CAE9D,CAAC"}
1
+ {"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../../../../../src/services/document-service/transform/relations/utils/data.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEvC,eAAO,MAAM,WAAW,aAAc,GAAG,mBAExC,CAAC;AAEF,eAAO,MAAM,UAAU,aAAc,GAAG,yBAEvC,CAAC"}
@@ -5,7 +5,7 @@ const isShortHand = (relation) => {
5
5
  return typeof relation === "string" || typeof relation === "number";
6
6
  };
7
7
  const isLongHand = (relation) => {
8
- return _.isObject(relation) && "id" in relation;
8
+ return _.isObject(relation) && ("id" in relation || "documentId" in relation);
9
9
  };
10
10
  exports.isLongHand = isLongHand;
11
11
  exports.isShortHand = isShortHand;
@@ -1 +1 @@
1
- {"version":3,"file":"data.js","sources":["../../../../../../src/services/document-service/transform/relations/utils/data.ts"],"sourcesContent":["import { isObject } from 'lodash/fp';\nimport { ID } from './types';\n\nexport const isShortHand = (relation: any): relation is ID => {\n return typeof relation === 'string' || typeof relation === 'number';\n};\n\nexport const isLongHand = (relation: any): relation is { id: ID } => {\n return isObject(relation) && 'id' in relation;\n};\n"],"names":["isObject"],"mappings":";;;AAGa,MAAA,cAAc,CAAC,aAAkC;AAC5D,SAAO,OAAO,aAAa,YAAY,OAAO,aAAa;AAC7D;AAEa,MAAA,aAAa,CAAC,aAA0C;AAC5D,SAAAA,WAAS,QAAQ,KAAK,QAAQ;AACvC;;;"}
1
+ {"version":3,"file":"data.js","sources":["../../../../../../src/services/document-service/transform/relations/utils/data.ts"],"sourcesContent":["import { isObject } from 'lodash/fp';\nimport { ID, LongHand } from './types';\n\nexport const isShortHand = (relation: any): relation is ID => {\n return typeof relation === 'string' || typeof relation === 'number';\n};\n\nexport const isLongHand = (relation: any): relation is LongHand => {\n return isObject(relation) && ('id' in relation || 'documentId' in relation);\n};\n"],"names":["isObject"],"mappings":";;;AAGa,MAAA,cAAc,CAAC,aAAkC;AAC5D,SAAO,OAAO,aAAa,YAAY,OAAO,aAAa;AAC7D;AAEa,MAAA,aAAa,CAAC,aAAwC;AACjE,SAAOA,EAAAA,SAAS,QAAQ,MAAM,QAAQ,YAAY,gBAAgB;AACpE;;;"}
@@ -3,7 +3,7 @@ const isShortHand = (relation) => {
3
3
  return typeof relation === "string" || typeof relation === "number";
4
4
  };
5
5
  const isLongHand = (relation) => {
6
- return isObject(relation) && "id" in relation;
6
+ return isObject(relation) && ("id" in relation || "documentId" in relation);
7
7
  };
8
8
  export {
9
9
  isLongHand,
@@ -1 +1 @@
1
- {"version":3,"file":"data.mjs","sources":["../../../../../../src/services/document-service/transform/relations/utils/data.ts"],"sourcesContent":["import { isObject } from 'lodash/fp';\nimport { ID } from './types';\n\nexport const isShortHand = (relation: any): relation is ID => {\n return typeof relation === 'string' || typeof relation === 'number';\n};\n\nexport const isLongHand = (relation: any): relation is { id: ID } => {\n return isObject(relation) && 'id' in relation;\n};\n"],"names":[],"mappings":";AAGa,MAAA,cAAc,CAAC,aAAkC;AAC5D,SAAO,OAAO,aAAa,YAAY,OAAO,aAAa;AAC7D;AAEa,MAAA,aAAa,CAAC,aAA0C;AAC5D,SAAA,SAAS,QAAQ,KAAK,QAAQ;AACvC;"}
1
+ {"version":3,"file":"data.mjs","sources":["../../../../../../src/services/document-service/transform/relations/utils/data.ts"],"sourcesContent":["import { isObject } from 'lodash/fp';\nimport { ID, LongHand } from './types';\n\nexport const isShortHand = (relation: any): relation is ID => {\n return typeof relation === 'string' || typeof relation === 'number';\n};\n\nexport const isLongHand = (relation: any): relation is LongHand => {\n return isObject(relation) && ('id' in relation || 'documentId' in relation);\n};\n"],"names":[],"mappings":";AAGa,MAAA,cAAc,CAAC,aAAkC;AAC5D,SAAO,OAAO,aAAa,YAAY,OAAO,aAAa;AAC7D;AAEa,MAAA,aAAa,CAAC,aAAwC;AACjE,SAAO,SAAS,QAAQ,MAAM,QAAQ,YAAY,gBAAgB;AACpE;"}
@@ -1,8 +1,8 @@
1
1
  import { Common } from '@strapi/types';
2
- import { LongHand } from './types';
2
+ import { LongHandDocument } from './types';
3
3
  export declare const isLocalizedContentType: (uid: Common.UID.Schema) => any;
4
4
  export declare const getDefaultLocale: () => string;
5
- export declare const getRelationTargetLocale: (relation: LongHand, opts: {
5
+ export declare const getRelationTargetLocale: (relation: LongHandDocument, opts: {
6
6
  targetUid: Common.UID.Schema;
7
7
  sourceUid: Common.UID.Schema;
8
8
  sourceLocale?: string | null;
@@ -1 +1 @@
1
- {"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../../../../../../src/services/document-service/transform/relations/utils/i18n.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,eAAO,MAAM,sBAAsB,QAAS,OAAO,GAAG,CAAC,MAAM,QAG5D,CAAC;AAEF,eAAO,MAAM,gBAAgB,cAI5B,CAAC;AAEF,eAAO,MAAM,uBAAuB,aACxB,QAAQ,QACZ;IACJ,SAAS,EAAE,OAAO,GAAG,CAAC,MAAM,CAAC;IAC7B,SAAS,EAAE,OAAO,GAAG,CAAC,MAAM,CAAC;IAC7B,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B,kBAuBF,CAAC"}
1
+ {"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../../../../../../src/services/document-service/transform/relations/utils/i18n.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C,eAAO,MAAM,sBAAsB,QAAS,OAAO,GAAG,CAAC,MAAM,QAG5D,CAAC;AAEF,eAAO,MAAM,gBAAgB,cAI5B,CAAC;AAEF,eAAO,MAAM,uBAAuB,aACxB,gBAAgB,QACpB;IACJ,SAAS,EAAE,OAAO,GAAG,CAAC,MAAM,CAAC;IAC7B,SAAS,EAAE,OAAO,GAAG,CAAC,MAAM,CAAC;IAC7B,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B,kBAuBF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"i18n.js","sources":["../../../../../../src/services/document-service/transform/relations/utils/i18n.ts"],"sourcesContent":["import { Common } from '@strapi/types';\nimport { errors } from '@strapi/utils';\nimport { LongHand } from './types';\n\nexport const isLocalizedContentType = (uid: Common.UID.Schema) => {\n const model = strapi.getModel(uid);\n return strapi.plugin('i18n').service('content-types').isLocalizedContentType(model);\n};\n\nexport const getDefaultLocale = () => {\n // TODO: Fix this\n // return strapi.plugin('i18n').service('locales').getDefaultLocale();\n return 'en';\n};\n\nexport const getRelationTargetLocale = (\n relation: LongHand,\n opts: {\n targetUid: Common.UID.Schema;\n sourceUid: Common.UID.Schema;\n sourceLocale?: string | null;\n }\n) => {\n const defaultLocale = getDefaultLocale();\n const targetLocale = relation.locale || opts.sourceLocale || defaultLocale;\n\n const isTargetLocalized = isLocalizedContentType(opts.targetUid);\n const isSourceLocalized = isLocalizedContentType(opts.sourceUid);\n\n // Locale validations\n if (isSourceLocalized && isTargetLocalized) {\n // Check the targetLocale matches\n if (targetLocale !== opts.sourceLocale) {\n throw new errors.ValidationError(\n `Relation locale does not match the source locale ${JSON.stringify(relation)}`\n );\n }\n }\n\n if (isTargetLocalized) {\n return targetLocale;\n }\n\n return null;\n};\n"],"names":["errors"],"mappings":";;;AAIa,MAAA,yBAAyB,CAAC,QAA2B;AAC1D,QAAA,QAAQ,OAAO,SAAS,GAAG;AAC1B,SAAA,OAAO,OAAO,MAAM,EAAE,QAAQ,eAAe,EAAE,uBAAuB,KAAK;AACpF;AAEO,MAAM,mBAAmB,MAAM;AAG7B,SAAA;AACT;AAEa,MAAA,0BAA0B,CACrC,UACA,SAKG;AACH,QAAM,gBAAgB;AACtB,QAAM,eAAe,SAAS,UAAU,KAAK,gBAAgB;AAEvD,QAAA,oBAAoB,uBAAuB,KAAK,SAAS;AACzD,QAAA,oBAAoB,uBAAuB,KAAK,SAAS;AAG/D,MAAI,qBAAqB,mBAAmB;AAEtC,QAAA,iBAAiB,KAAK,cAAc;AACtC,YAAM,IAAIA,YAAO,OAAA;AAAA,QACf,oDAAoD,KAAK,UAAU,QAAQ,CAAC;AAAA,MAAA;AAAA,IAEhF;AAAA,EACF;AAEA,MAAI,mBAAmB;AACd,WAAA;AAAA,EACT;AAEO,SAAA;AACT;;;;"}
1
+ {"version":3,"file":"i18n.js","sources":["../../../../../../src/services/document-service/transform/relations/utils/i18n.ts"],"sourcesContent":["import { Common } from '@strapi/types';\nimport { errors } from '@strapi/utils';\nimport { LongHandDocument } from './types';\n\nexport const isLocalizedContentType = (uid: Common.UID.Schema) => {\n const model = strapi.getModel(uid);\n return strapi.plugin('i18n').service('content-types').isLocalizedContentType(model);\n};\n\nexport const getDefaultLocale = () => {\n // TODO: Fix this\n // return strapi.plugin('i18n').service('locales').getDefaultLocale();\n return 'en';\n};\n\nexport const getRelationTargetLocale = (\n relation: LongHandDocument,\n opts: {\n targetUid: Common.UID.Schema;\n sourceUid: Common.UID.Schema;\n sourceLocale?: string | null;\n }\n) => {\n const defaultLocale = getDefaultLocale();\n const targetLocale = relation.locale || opts.sourceLocale || defaultLocale;\n\n const isTargetLocalized = isLocalizedContentType(opts.targetUid);\n const isSourceLocalized = isLocalizedContentType(opts.sourceUid);\n\n // Locale validations\n if (isSourceLocalized && isTargetLocalized) {\n // Check the targetLocale matches\n if (targetLocale !== opts.sourceLocale) {\n throw new errors.ValidationError(\n `Relation locale does not match the source locale ${JSON.stringify(relation)}`\n );\n }\n }\n\n if (isTargetLocalized) {\n return targetLocale;\n }\n\n return null;\n};\n"],"names":["errors"],"mappings":";;;AAIa,MAAA,yBAAyB,CAAC,QAA2B;AAC1D,QAAA,QAAQ,OAAO,SAAS,GAAG;AAC1B,SAAA,OAAO,OAAO,MAAM,EAAE,QAAQ,eAAe,EAAE,uBAAuB,KAAK;AACpF;AAEO,MAAM,mBAAmB,MAAM;AAG7B,SAAA;AACT;AAEa,MAAA,0BAA0B,CACrC,UACA,SAKG;AACH,QAAM,gBAAgB;AACtB,QAAM,eAAe,SAAS,UAAU,KAAK,gBAAgB;AAEvD,QAAA,oBAAoB,uBAAuB,KAAK,SAAS;AACzD,QAAA,oBAAoB,uBAAuB,KAAK,SAAS;AAG/D,MAAI,qBAAqB,mBAAmB;AAEtC,QAAA,iBAAiB,KAAK,cAAc;AACtC,YAAM,IAAIA,YAAO,OAAA;AAAA,QACf,oDAAoD,KAAK,UAAU,QAAQ,CAAC;AAAA,MAAA;AAAA,IAEhF;AAAA,EACF;AAEA,MAAI,mBAAmB;AACd,WAAA;AAAA,EACT;AAEO,SAAA;AACT;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"i18n.mjs","sources":["../../../../../../src/services/document-service/transform/relations/utils/i18n.ts"],"sourcesContent":["import { Common } from '@strapi/types';\nimport { errors } from '@strapi/utils';\nimport { LongHand } from './types';\n\nexport const isLocalizedContentType = (uid: Common.UID.Schema) => {\n const model = strapi.getModel(uid);\n return strapi.plugin('i18n').service('content-types').isLocalizedContentType(model);\n};\n\nexport const getDefaultLocale = () => {\n // TODO: Fix this\n // return strapi.plugin('i18n').service('locales').getDefaultLocale();\n return 'en';\n};\n\nexport const getRelationTargetLocale = (\n relation: LongHand,\n opts: {\n targetUid: Common.UID.Schema;\n sourceUid: Common.UID.Schema;\n sourceLocale?: string | null;\n }\n) => {\n const defaultLocale = getDefaultLocale();\n const targetLocale = relation.locale || opts.sourceLocale || defaultLocale;\n\n const isTargetLocalized = isLocalizedContentType(opts.targetUid);\n const isSourceLocalized = isLocalizedContentType(opts.sourceUid);\n\n // Locale validations\n if (isSourceLocalized && isTargetLocalized) {\n // Check the targetLocale matches\n if (targetLocale !== opts.sourceLocale) {\n throw new errors.ValidationError(\n `Relation locale does not match the source locale ${JSON.stringify(relation)}`\n );\n }\n }\n\n if (isTargetLocalized) {\n return targetLocale;\n }\n\n return null;\n};\n"],"names":[],"mappings":";AAIa,MAAA,yBAAyB,CAAC,QAA2B;AAC1D,QAAA,QAAQ,OAAO,SAAS,GAAG;AAC1B,SAAA,OAAO,OAAO,MAAM,EAAE,QAAQ,eAAe,EAAE,uBAAuB,KAAK;AACpF;AAEO,MAAM,mBAAmB,MAAM;AAG7B,SAAA;AACT;AAEa,MAAA,0BAA0B,CACrC,UACA,SAKG;AACH,QAAM,gBAAgB;AACtB,QAAM,eAAe,SAAS,UAAU,KAAK,gBAAgB;AAEvD,QAAA,oBAAoB,uBAAuB,KAAK,SAAS;AACzD,QAAA,oBAAoB,uBAAuB,KAAK,SAAS;AAG/D,MAAI,qBAAqB,mBAAmB;AAEtC,QAAA,iBAAiB,KAAK,cAAc;AACtC,YAAM,IAAI,OAAO;AAAA,QACf,oDAAoD,KAAK,UAAU,QAAQ,CAAC;AAAA,MAAA;AAAA,IAEhF;AAAA,EACF;AAEA,MAAI,mBAAmB;AACd,WAAA;AAAA,EACT;AAEO,SAAA;AACT;"}
1
+ {"version":3,"file":"i18n.mjs","sources":["../../../../../../src/services/document-service/transform/relations/utils/i18n.ts"],"sourcesContent":["import { Common } from '@strapi/types';\nimport { errors } from '@strapi/utils';\nimport { LongHandDocument } from './types';\n\nexport const isLocalizedContentType = (uid: Common.UID.Schema) => {\n const model = strapi.getModel(uid);\n return strapi.plugin('i18n').service('content-types').isLocalizedContentType(model);\n};\n\nexport const getDefaultLocale = () => {\n // TODO: Fix this\n // return strapi.plugin('i18n').service('locales').getDefaultLocale();\n return 'en';\n};\n\nexport const getRelationTargetLocale = (\n relation: LongHandDocument,\n opts: {\n targetUid: Common.UID.Schema;\n sourceUid: Common.UID.Schema;\n sourceLocale?: string | null;\n }\n) => {\n const defaultLocale = getDefaultLocale();\n const targetLocale = relation.locale || opts.sourceLocale || defaultLocale;\n\n const isTargetLocalized = isLocalizedContentType(opts.targetUid);\n const isSourceLocalized = isLocalizedContentType(opts.sourceUid);\n\n // Locale validations\n if (isSourceLocalized && isTargetLocalized) {\n // Check the targetLocale matches\n if (targetLocale !== opts.sourceLocale) {\n throw new errors.ValidationError(\n `Relation locale does not match the source locale ${JSON.stringify(relation)}`\n );\n }\n }\n\n if (isTargetLocalized) {\n return targetLocale;\n }\n\n return null;\n};\n"],"names":[],"mappings":";AAIa,MAAA,yBAAyB,CAAC,QAA2B;AAC1D,QAAA,QAAQ,OAAO,SAAS,GAAG;AAC1B,SAAA,OAAO,OAAO,MAAM,EAAE,QAAQ,eAAe,EAAE,uBAAuB,KAAK;AACpF;AAEO,MAAM,mBAAmB,MAAM;AAG7B,SAAA;AACT;AAEa,MAAA,0BAA0B,CACrC,UACA,SAKG;AACH,QAAM,gBAAgB;AACtB,QAAM,eAAe,SAAS,UAAU,KAAK,gBAAgB;AAEvD,QAAA,oBAAoB,uBAAuB,KAAK,SAAS;AACzD,QAAA,oBAAoB,uBAAuB,KAAK,SAAS;AAG/D,MAAI,qBAAqB,mBAAmB;AAEtC,QAAA,iBAAiB,KAAK,cAAc;AACtC,YAAM,IAAI,OAAO;AAAA,QACf,oDAAoD,KAAK,UAAU,QAAQ,CAAC;AAAA,MAAA;AAAA,IAEhF;AAAA,EACF;AAEA,MAAI,mBAAmB;AACd,WAAA;AAAA,EACT;AAEO,SAAA;AACT;"}
@@ -1,8 +1,12 @@
1
1
  export type ID = string | number;
2
2
  export type ShortHand = ID;
3
- export type LongHand = {
3
+ export type LongHandEntity = {
4
4
  id: ID;
5
+ };
6
+ export type LongHandDocument = {
7
+ documentId: ID;
5
8
  locale?: string;
6
9
  };
10
+ export type LongHand = LongHandEntity | LongHandDocument;
7
11
  export type GetId = (relation: ID) => ID | null;
8
12
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../src/services/document-service/transform/relations/utils/types.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,EAAE,GAAG,MAAM,GAAG,MAAM,CAAC;AACjC,MAAM,MAAM,SAAS,GAAG,EAAE,CAAC;AAC3B,MAAM,MAAM,QAAQ,GAAG;IAAE,EAAE,EAAE,EAAE,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnD,MAAM,MAAM,KAAK,GAAG,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../src/services/document-service/transform/relations/utils/types.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,EAAE,GAAG,MAAM,GAAG,MAAM,CAAC;AACjC,MAAM,MAAM,SAAS,GAAG,EAAE,CAAC;AAE3B,MAAM,MAAM,cAAc,GAAG;IAAE,EAAE,EAAE,EAAE,CAAA;CAAE,CAAC;AACxC,MAAM,MAAM,gBAAgB,GAAG;IAAE,UAAU,EAAE,EAAE,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AACnE,MAAM,MAAM,QAAQ,GAAG,cAAc,GAAG,gBAAgB,CAAC;AAEzD,MAAM,MAAM,KAAK,GAAG,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC"}
@@ -1,6 +1,177 @@
1
- import { Model } from '@strapi/database';
2
- import { Schema } from '@strapi/types';
1
+ import { type Model } from '@strapi/database';
2
+ import { Schema, Attribute } from '@strapi/types';
3
3
  import { createId } from '@paralleldrive/cuid2';
4
+ /**
5
+ * Because strapi/database models don't know about things like components or dynamic zones, we use this file to convert them
6
+ * to a relations format that it recognizes
7
+ *
8
+ * Therefore we have to keep an additional set of helpers/extensions to the database naming methods
9
+ */
10
+ export declare const COMPONENT_JOIN_TABLE_SUFFIX = "components";
11
+ export declare const DZ_JOIN_TABLE_SUFFIX = "components";
12
+ export declare const COMPONENT_INVERSE_COLUMN_NAME = "component";
13
+ export declare const COMPONENT_TYPE_COLUMN = "component_type";
14
+ export declare const ENTITY = "entity";
15
+ export declare const getComponentJoinTableName: (collectionName: string) => string;
16
+ export declare const getDzJoinTableName: (collectionName: string) => string;
17
+ export type LoadedContentTypeModel = Schema.ContentType & Required<Pick<Schema.ContentType, 'collectionName' | 'uid' | 'modelName'>>;
18
+ export declare const transformAttribute: (name: string, attribute: Attribute.Any, contentType: LoadedContentTypeModel) => Attribute.BigInteger | (Attribute.OfType<"boolean"> & Attribute.ConfigurableOption & Attribute.DefaultOption<boolean> & Attribute.PrivateOption & Attribute.RequiredOption & Attribute.WritableOption & Attribute.VisibleOption) | Attribute.Blocks | Attribute.DateTime | Attribute.Date | Attribute.Decimal | Attribute.Email | Attribute.Enumeration<string[]> | Attribute.Float | Attribute.Integer | Attribute.JSON | Attribute.Password | (Attribute.OfType<"relation"> & {
19
+ relation: "morphToOne";
20
+ } & Attribute.ConfigurableOption & Attribute.PrivateOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.RequiredOption) | (Attribute.OfType<"relation"> & {
21
+ relation: "morphToMany";
22
+ } & Attribute.ConfigurableOption & Attribute.PrivateOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.RequiredOption) | (Attribute.OfType<"relation"> & {
23
+ relation: "oneToOne";
24
+ target: import("@strapi/types/dist/types/core/common/uid").ContentType;
25
+ } & import("@strapi/types/dist/types/utils").Without<{
26
+ inversedBy?: string | undefined;
27
+ }, {
28
+ mappedBy?: string | undefined;
29
+ }> & {
30
+ mappedBy?: string | undefined;
31
+ } & Attribute.ConfigurableOption & Attribute.PrivateOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.RequiredOption) | (Attribute.OfType<"relation"> & {
32
+ relation: "oneToOne";
33
+ target: import("@strapi/types/dist/types/core/common/uid").ContentType;
34
+ } & import("@strapi/types/dist/types/utils").Without<{
35
+ mappedBy?: string | undefined;
36
+ }, {
37
+ inversedBy?: string | undefined;
38
+ }> & {
39
+ inversedBy?: string | undefined;
40
+ } & Attribute.ConfigurableOption & Attribute.PrivateOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.RequiredOption) | (Attribute.OfType<"relation"> & {
41
+ relation: "oneToMany";
42
+ target: import("@strapi/types/dist/types/core/common/uid").ContentType;
43
+ } & import("@strapi/types/dist/types/utils").Without<{
44
+ inversedBy?: string | undefined;
45
+ }, {
46
+ mappedBy?: string | undefined;
47
+ }> & {
48
+ mappedBy?: string | undefined;
49
+ } & Attribute.ConfigurableOption & Attribute.PrivateOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.RequiredOption) | (Attribute.OfType<"relation"> & {
50
+ relation: "oneToMany";
51
+ target: import("@strapi/types/dist/types/core/common/uid").ContentType;
52
+ } & import("@strapi/types/dist/types/utils").Without<{
53
+ mappedBy?: string | undefined;
54
+ }, {
55
+ inversedBy?: string | undefined;
56
+ }> & {
57
+ inversedBy?: string | undefined;
58
+ } & Attribute.ConfigurableOption & Attribute.PrivateOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.RequiredOption) | (Attribute.OfType<"relation"> & {
59
+ relation: "manyToOne";
60
+ target: import("@strapi/types/dist/types/core/common/uid").ContentType;
61
+ } & import("@strapi/types/dist/types/utils").Without<{
62
+ inversedBy?: string | undefined;
63
+ }, {
64
+ mappedBy?: string | undefined;
65
+ }> & {
66
+ mappedBy?: string | undefined;
67
+ } & Attribute.ConfigurableOption & Attribute.PrivateOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.RequiredOption) | (Attribute.OfType<"relation"> & {
68
+ relation: "manyToOne";
69
+ target: import("@strapi/types/dist/types/core/common/uid").ContentType;
70
+ } & import("@strapi/types/dist/types/utils").Without<{
71
+ mappedBy?: string | undefined;
72
+ }, {
73
+ inversedBy?: string | undefined;
74
+ }> & {
75
+ inversedBy?: string | undefined;
76
+ } & Attribute.ConfigurableOption & Attribute.PrivateOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.RequiredOption) | (Attribute.OfType<"relation"> & {
77
+ relation: "manyToMany";
78
+ target: import("@strapi/types/dist/types/core/common/uid").ContentType;
79
+ } & import("@strapi/types/dist/types/utils").Without<{
80
+ inversedBy?: string | undefined;
81
+ }, {
82
+ mappedBy?: string | undefined;
83
+ }> & {
84
+ mappedBy?: string | undefined;
85
+ } & Attribute.ConfigurableOption & Attribute.PrivateOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.RequiredOption) | (Attribute.OfType<"relation"> & {
86
+ relation: "manyToMany";
87
+ target: import("@strapi/types/dist/types/core/common/uid").ContentType;
88
+ } & import("@strapi/types/dist/types/utils").Without<{
89
+ mappedBy?: string | undefined;
90
+ }, {
91
+ inversedBy?: string | undefined;
92
+ }> & {
93
+ inversedBy?: string | undefined;
94
+ } & Attribute.ConfigurableOption & Attribute.PrivateOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.RequiredOption) | (Attribute.OfType<"relation"> & {
95
+ relation: "oneWay";
96
+ target: import("@strapi/types/dist/types/core/common/uid").ContentType;
97
+ } & Attribute.ConfigurableOption & Attribute.PrivateOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.RequiredOption) | (Attribute.OfType<"relation"> & {
98
+ relation: "manyWay";
99
+ target: import("@strapi/types/dist/types/core/common/uid").ContentType;
100
+ } & Attribute.ConfigurableOption & Attribute.PrivateOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.RequiredOption) | (Attribute.OfType<"relation"> & {
101
+ relation: "morphOne";
102
+ target: import("@strapi/types/dist/types/core/common/uid").ContentType;
103
+ morphBy?: string | undefined;
104
+ } & Attribute.ConfigurableOption & Attribute.PrivateOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.RequiredOption) | (Attribute.OfType<"relation"> & {
105
+ relation: "morphMany";
106
+ target: import("@strapi/types/dist/types/core/common/uid").ContentType;
107
+ morphBy?: string | undefined;
108
+ } & Attribute.ConfigurableOption & Attribute.PrivateOption & Attribute.WritableOption & Attribute.VisibleOption & Attribute.RequiredOption) | Attribute.RichText | (Attribute.OfType<"string"> & Attribute.StringProperties & Attribute.ConfigurableOption & Attribute.DefaultOption<string> & Attribute.MinMaxLengthOption & Attribute.PrivateOption & Attribute.UniqueOption & Attribute.RequiredOption & Attribute.WritableOption & Attribute.VisibleOption) | Attribute.Text | Attribute.Time | Attribute.Timestamp | Attribute.UID<string, Attribute.UIDOptions> | {
109
+ type: string;
110
+ relation: string;
111
+ target: string;
112
+ morphBy: string;
113
+ joinTable?: undefined;
114
+ } | {
115
+ type: string;
116
+ relation: string;
117
+ target: `${string}.${string}`;
118
+ joinTable: {
119
+ name: string;
120
+ joinColumn: {
121
+ name: string;
122
+ referencedColumn: string;
123
+ };
124
+ inverseJoinColumn: {
125
+ name: string;
126
+ referencedColumn: string;
127
+ };
128
+ on: {
129
+ field: string;
130
+ };
131
+ orderColumnName: string;
132
+ orderBy: {
133
+ order: string;
134
+ };
135
+ pivotColumns: string[];
136
+ morphColumn?: undefined;
137
+ };
138
+ morphBy?: undefined;
139
+ } | {
140
+ type: string;
141
+ relation: string;
142
+ joinTable: {
143
+ name: string;
144
+ joinColumn: {
145
+ name: string;
146
+ referencedColumn: string;
147
+ };
148
+ morphColumn: {
149
+ idColumn: {
150
+ name: string;
151
+ referencedColumn: string;
152
+ };
153
+ typeColumn: {
154
+ name: string;
155
+ };
156
+ typeField: string;
157
+ };
158
+ on: {
159
+ field: string;
160
+ };
161
+ orderBy: {
162
+ order: string;
163
+ };
164
+ pivotColumns: string[];
165
+ inverseJoinColumn?: undefined;
166
+ orderColumnName?: undefined;
167
+ };
168
+ target?: undefined;
169
+ morphBy?: undefined;
170
+ };
171
+ export declare const transformAttributes: (contentType: LoadedContentTypeModel) => {};
172
+ export declare const hasComponentsOrDz: (contentType: LoadedContentTypeModel) => contentType is Schema.ContentType & Required<Pick<Schema.ContentType, "uid" | "collectionName" | "modelName">> & {
173
+ type: 'dynamiczone' | 'component';
174
+ };
4
175
  export declare const createDocumentId: typeof createId;
5
- export declare const transformContentTypesToModels: (contentTypes: Schema.ContentType[]) => Model[];
176
+ export declare const transformContentTypesToModels: (contentTypes: LoadedContentTypeModel[]) => Model[];
6
177
  //# sourceMappingURL=transform-content-types-to-models.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"transform-content-types-to-models.d.ts","sourceRoot":"","sources":["../../src/utils/transform-content-types-to-models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,MAAM,EAAa,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAmGhD,eAAO,MAAM,gBAAgB,iBAAW,CAAC;AAuEzC,eAAO,MAAM,6BAA6B,iBAAkB,OAAO,WAAW,EAAE,KAAG,KAAK,EA8CvF,CAAC"}
1
+ {"version":3,"file":"transform-content-types-to-models.d.ts","sourceRoot":"","sources":["../../src/utils/transform-content-types-to-models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAS,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAMhD;;;;;GAKG;AAEH,eAAO,MAAM,2BAA2B,eAAe,CAAC;AACxD,eAAO,MAAM,oBAAoB,eAAe,CAAC;AACjD,eAAO,MAAM,6BAA6B,cAAc,CAAC;AACzD,eAAO,MAAM,qBAAqB,mBAAmB,CAAC;AACtD,eAAO,MAAM,MAAM,WAAW,CAAC;AAE/B,eAAO,MAAM,yBAAyB,mBAAoB,MAAM,WACmB,CAAC;AAEpF,eAAO,MAAM,kBAAkB,mBAAoB,MAAM,WACmB,CAAC;AAI7E,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC,WAAW,GACrD,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,gBAAgB,GAAG,KAAK,GAAG,WAAW,CAAC,CAAC,CAAC;AAG7E,eAAO,MAAM,kBAAkB,SACvB,MAAM,aACD,UAAU,GAAG,eACX,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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