@payloadcms/db-postgres 0.1.0-beta.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. package/dist/connect.js +82 -0
  2. package/dist/create.js +32 -0
  3. package/dist/createGlobal.js +32 -0
  4. package/dist/createGlobalVersion.js +48 -0
  5. package/dist/createMigration.js +85 -0
  6. package/dist/createVersion.js +54 -0
  7. package/dist/deleteMany.js +44 -0
  8. package/dist/deleteOne.js +47 -0
  9. package/dist/deleteVersions.js +46 -0
  10. package/dist/destroy.js +16 -0
  11. package/dist/find/buildFindManyArgs.js +61 -0
  12. package/dist/find/chainMethods.js +21 -0
  13. package/dist/find/findMany.js +197 -0
  14. package/dist/find/traverseFields.js +118 -0
  15. package/dist/find.js +35 -0
  16. package/dist/findGlobal.js +38 -0
  17. package/dist/findGlobalVersions.js +39 -0
  18. package/dist/findOne.js +49 -0
  19. package/dist/findVersions.js +39 -0
  20. package/dist/index.js +95 -0
  21. package/dist/init.js +74 -0
  22. package/dist/migrate.js +81 -0
  23. package/dist/migrateStatus.js +54 -0
  24. package/dist/mock.js +13 -0
  25. package/dist/queries/buildAndOrConditions.js +39 -0
  26. package/dist/queries/buildQuery.js +80 -0
  27. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.js +24 -0
  28. package/dist/queries/createJSONQuery/formatJSONPathSegment.js +15 -0
  29. package/dist/queries/createJSONQuery/index.js +64 -0
  30. package/dist/queries/getTableColumnFromPath.js +333 -0
  31. package/dist/queries/operatorMap.js +34 -0
  32. package/dist/queries/parseParams.js +146 -0
  33. package/dist/queries/sanitizeQueryValue.js +79 -0
  34. package/dist/queryDrafts.js +56 -0
  35. package/dist/reference.js +76 -0
  36. package/dist/schema/build.js +245 -0
  37. package/dist/schema/createIndex.js +19 -0
  38. package/dist/schema/parentIDColumnMap.js +18 -0
  39. package/dist/schema/traverseFields.js +430 -0
  40. package/dist/schema/validateExistingBlockIsIdentical.js +34 -0
  41. package/dist/transactions/beginTransaction.js +51 -0
  42. package/dist/transactions/commitTransaction.js +24 -0
  43. package/dist/transactions/rollbackTransaction.js +20 -0
  44. package/dist/transform/read/hasManyNumber.js +20 -0
  45. package/dist/transform/read/index.js +42 -0
  46. package/dist/transform/read/relationship.js +74 -0
  47. package/dist/transform/read/traverseFields.js +325 -0
  48. package/dist/transform/write/array.js +55 -0
  49. package/dist/transform/write/blocks.js +56 -0
  50. package/dist/transform/write/index.js +46 -0
  51. package/dist/transform/write/numbers.js +21 -0
  52. package/dist/transform/write/relationships.js +33 -0
  53. package/dist/transform/write/selects.js +29 -0
  54. package/dist/transform/write/traverseFields.js +379 -0
  55. package/dist/transform/write/types.js +6 -0
  56. package/dist/types.js +6 -0
  57. package/dist/update.js +48 -0
  58. package/dist/updateGlobal.js +39 -0
  59. package/dist/updateGlobalVersion.js +50 -0
  60. package/dist/updateVersion.js +50 -0
  61. package/dist/upsertRow/deleteExistingArrayRows.js +20 -0
  62. package/dist/upsertRow/deleteExistingRowsByPath.js +43 -0
  63. package/dist/upsertRow/index.js +243 -0
  64. package/dist/upsertRow/insertArrays.js +64 -0
  65. package/dist/upsertRow/types.js +6 -0
  66. package/dist/utilities/appendPrefixToKeys.js +16 -0
  67. package/dist/utilities/createBlocksMap.js +39 -0
  68. package/dist/utilities/createMigrationTable.js +23 -0
  69. package/dist/utilities/createRelationshipMap.js +29 -0
  70. package/dist/utilities/hasLocalesTable.js +21 -0
  71. package/dist/utilities/isArrayOfRows.js +15 -0
  72. package/dist/utilities/migrationTableExists.js +19 -0
  73. package/dist/webpack.js +30 -0
  74. package/package.json +47 -0
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "rollbackTransaction", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return rollbackTransaction;
9
+ }
10
+ });
11
+ const rollbackTransaction = async function rollbackTransaction(id = '') {
12
+ if (!this.sessions[id]) {
13
+ this.payload.logger.warn('rollbackTransaction called when no transaction exists');
14
+ return;
15
+ }
16
+ await this.sessions[id].reject();
17
+ delete this.sessions[id];
18
+ };
19
+
20
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90cmFuc2FjdGlvbnMvcm9sbGJhY2tUcmFuc2FjdGlvbi50cyJdLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgdHlwZSB7IFJvbGxiYWNrVHJhbnNhY3Rpb24gfSBmcm9tICdwYXlsb2FkL2RhdGFiYXNlJ1xuXG5leHBvcnQgY29uc3Qgcm9sbGJhY2tUcmFuc2FjdGlvbjogUm9sbGJhY2tUcmFuc2FjdGlvbiA9IGFzeW5jIGZ1bmN0aW9uIHJvbGxiYWNrVHJhbnNhY3Rpb24oXG4gIGlkID0gJycsXG4pIHtcbiAgaWYgKCF0aGlzLnNlc3Npb25zW2lkXSkge1xuICAgIHRoaXMucGF5bG9hZC5sb2dnZXIud2Fybigncm9sbGJhY2tUcmFuc2FjdGlvbiBjYWxsZWQgd2hlbiBubyB0cmFuc2FjdGlvbiBleGlzdHMnKVxuICAgIHJldHVyblxuICB9XG5cbiAgYXdhaXQgdGhpcy5zZXNzaW9uc1tpZF0ucmVqZWN0KClcblxuICBkZWxldGUgdGhpcy5zZXNzaW9uc1tpZF1cbn1cbiJdLCJuYW1lcyI6WyJyb2xsYmFja1RyYW5zYWN0aW9uIiwiaWQiLCJzZXNzaW9ucyIsInBheWxvYWQiLCJsb2dnZXIiLCJ3YXJuIiwicmVqZWN0Il0sIm1hcHBpbmdzIjoiOzs7OytCQUVhQTs7O2VBQUFBOzs7QUFBTixNQUFNQSxzQkFBMkMsZUFBZUEsb0JBQ3JFQyxLQUFLLEVBQUU7SUFFUCxJQUFJLENBQUMsSUFBSSxDQUFDQyxRQUFRLENBQUNELEdBQUcsRUFBRTtRQUN0QixJQUFJLENBQUNFLE9BQU8sQ0FBQ0MsTUFBTSxDQUFDQyxJQUFJLENBQUM7UUFDekI7SUFDRjtJQUVBLE1BQU0sSUFBSSxDQUFDSCxRQUFRLENBQUNELEdBQUcsQ0FBQ0ssTUFBTTtJQUU5QixPQUFPLElBQUksQ0FBQ0osUUFBUSxDQUFDRCxHQUFHO0FBQzFCIn0=
@@ -0,0 +1,20 @@
1
+ /* eslint-disable no-param-reassign */ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "transformHasManyNumber", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return transformHasManyNumber;
9
+ }
10
+ });
11
+ const transformHasManyNumber = ({ field, locale, numberRows, ref })=>{
12
+ const result = numberRows.map(({ number })=>number);
13
+ if (locale) {
14
+ ref[field.name][locale] = result;
15
+ } else {
16
+ ref[field.name] = result;
17
+ }
18
+ };
19
+
20
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy90cmFuc2Zvcm0vcmVhZC9oYXNNYW55TnVtYmVyLnRzIl0sInNvdXJjZXNDb250ZW50IjpbIi8qIGVzbGludC1kaXNhYmxlIG5vLXBhcmFtLXJlYXNzaWduICovXG5pbXBvcnQgdHlwZSB7IE51bWJlckZpZWxkIH0gZnJvbSAncGF5bG9hZC90eXBlcydcblxudHlwZSBBcmdzID0ge1xuICBmaWVsZDogTnVtYmVyRmllbGRcbiAgbG9jYWxlPzogc3RyaW5nXG4gIG51bWJlclJvd3M6IFJlY29yZDxzdHJpbmcsIHVua25vd24+W11cbiAgcmVmOiBSZWNvcmQ8c3RyaW5nLCB1bmtub3duPlxufVxuXG5leHBvcnQgY29uc3QgdHJhbnNmb3JtSGFzTWFueU51bWJlciA9ICh7IGZpZWxkLCBsb2NhbGUsIG51bWJlclJvd3MsIHJlZiB9OiBBcmdzKSA9PiB7XG4gIGNvbnN0IHJlc3VsdCA9IG51bWJlclJvd3MubWFwKCh7IG51bWJlciB9KSA9PiBudW1iZXIpXG5cbiAgaWYgKGxvY2FsZSkge1xuICAgIHJlZltmaWVsZC5uYW1lXVtsb2NhbGVdID0gcmVzdWx0XG4gIH0gZWxzZSB7XG4gICAgcmVmW2ZpZWxkLm5hbWVdID0gcmVzdWx0XG4gIH1cbn1cbiJdLCJuYW1lcyI6WyJ0cmFuc2Zvcm1IYXNNYW55TnVtYmVyIiwiZmllbGQiLCJsb2NhbGUiLCJudW1iZXJSb3dzIiwicmVmIiwicmVzdWx0IiwibWFwIiwibnVtYmVyIiwibmFtZSJdLCJtYXBwaW5ncyI6IkFBQUEsb0NBQW9DOzs7OytCQVV2QkE7OztlQUFBQTs7O0FBQU4sTUFBTUEseUJBQXlCLENBQUMsRUFBRUMsS0FBSyxFQUFFQyxNQUFNLEVBQUVDLFVBQVUsRUFBRUMsR0FBRyxFQUFRO0lBQzdFLE1BQU1DLFNBQVNGLFdBQVdHLEdBQUcsQ0FBQyxDQUFDLEVBQUVDLE1BQU0sRUFBRSxHQUFLQTtJQUU5QyxJQUFJTCxRQUFRO1FBQ1ZFLEdBQUcsQ0FBQ0gsTUFBTU8sSUFBSSxDQUFDLENBQUNOLE9BQU8sR0FBR0c7SUFDNUIsT0FBTztRQUNMRCxHQUFHLENBQUNILE1BQU1PLElBQUksQ0FBQyxHQUFHSDtJQUNwQjtBQUNGIn0=
@@ -0,0 +1,42 @@
1
+ /* eslint-disable no-param-reassign */ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "transform", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return transform;
9
+ }
10
+ });
11
+ const _createBlocksMap = require("../../utilities/createBlocksMap");
12
+ const _createRelationshipMap = require("../../utilities/createRelationshipMap");
13
+ const _traverseFields = require("./traverseFields");
14
+ const transform = ({ config, data, fields })=>{
15
+ let relationships = {};
16
+ let numbers = {};
17
+ if ('_relationships' in data) {
18
+ relationships = (0, _createRelationshipMap.createPathMap)(data._relationships);
19
+ delete data._relationships;
20
+ }
21
+ if ('_numbers' in data) {
22
+ numbers = (0, _createRelationshipMap.createPathMap)(data._numbers);
23
+ delete data._numbers;
24
+ }
25
+ const blocks = (0, _createBlocksMap.createBlocksMap)(data);
26
+ const result = (0, _traverseFields.traverseFields)({
27
+ blocks,
28
+ config,
29
+ dataRef: {
30
+ id: data.id
31
+ },
32
+ fieldPrefix: '',
33
+ fields,
34
+ numbers,
35
+ path: '',
36
+ relationships,
37
+ table: data
38
+ });
39
+ return result;
40
+ };
41
+
42
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy90cmFuc2Zvcm0vcmVhZC9pbmRleC50cyJdLCJzb3VyY2VzQ29udGVudCI6WyIvKiBlc2xpbnQtZGlzYWJsZSBuby1wYXJhbS1yZWFzc2lnbiAqL1xuaW1wb3J0IHR5cGUgeyBTYW5pdGl6ZWRDb25maWcgfSBmcm9tICdwYXlsb2FkL2NvbmZpZydcbmltcG9ydCB0eXBlIHsgRmllbGQsIFR5cGVXaXRoSUQgfSBmcm9tICdwYXlsb2FkL3R5cGVzJ1xuXG5pbXBvcnQgeyBjcmVhdGVCbG9ja3NNYXAgfSBmcm9tICcuLi8uLi91dGlsaXRpZXMvY3JlYXRlQmxvY2tzTWFwJ1xuaW1wb3J0IHsgY3JlYXRlUGF0aE1hcCB9IGZyb20gJy4uLy4uL3V0aWxpdGllcy9jcmVhdGVSZWxhdGlvbnNoaXBNYXAnXG5pbXBvcnQgeyB0cmF2ZXJzZUZpZWxkcyB9IGZyb20gJy4vdHJhdmVyc2VGaWVsZHMnXG5cbnR5cGUgVHJhbnNmb3JtQXJncyA9IHtcbiAgY29uZmlnOiBTYW5pdGl6ZWRDb25maWdcbiAgZGF0YTogUmVjb3JkPHN0cmluZywgdW5rbm93bj5cbiAgZmFsbGJhY2tMb2NhbGU/OiBmYWxzZSB8IHN0cmluZ1xuICBmaWVsZHM6IEZpZWxkW11cbiAgbG9jYWxlPzogc3RyaW5nXG59XG5cbi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QUFNO1FBQ05aO1FBQ0FhLE9BQU9mO0lBQ1Q7SUFFQSxPQUFPUztBQUNUIn0=
@@ -0,0 +1,74 @@
1
+ /* eslint-disable no-param-reassign */ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "transformRelationship", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return transformRelationship;
9
+ }
10
+ });
11
+ const transformRelationship = ({ field, locale, ref, relations })=>{
12
+ let result;
13
+ if (!('hasMany' in field) || field.hasMany === false) {
14
+ const relation = relations[0];
15
+ if (relation) {
16
+ // Handle hasOne Poly
17
+ if (Array.isArray(field.relationTo)) {
18
+ const matchedRelation = Object.entries(relation).find(([key, val])=>val !== null && ![
19
+ 'id',
20
+ 'locale',
21
+ 'order',
22
+ 'parent',
23
+ 'path'
24
+ ].includes(key));
25
+ if (matchedRelation) {
26
+ const relationTo = matchedRelation[0].replace('ID', '');
27
+ result = {
28
+ relationTo,
29
+ value: matchedRelation[1]
30
+ };
31
+ }
32
+ } else {
33
+ // Handle hasOne
34
+ const relatedData = relation[`${field.relationTo}ID`];
35
+ result = relatedData;
36
+ }
37
+ }
38
+ } else {
39
+ const transformedRelations = [];
40
+ relations.forEach((relation)=>{
41
+ // Handle hasMany
42
+ if (!Array.isArray(field.relationTo)) {
43
+ const relatedData = relation[`${field.relationTo}ID`];
44
+ if (relatedData) {
45
+ transformedRelations.push(relatedData);
46
+ }
47
+ } else {
48
+ // Handle hasMany Poly
49
+ const matchedRelation = Object.entries(relation).find(([key, val])=>val !== null && ![
50
+ 'id',
51
+ 'locale',
52
+ 'order',
53
+ 'parent',
54
+ 'path'
55
+ ].includes(key));
56
+ if (matchedRelation) {
57
+ const relationTo = matchedRelation[0].replace('ID', '');
58
+ transformedRelations.push({
59
+ relationTo,
60
+ value: matchedRelation[1]
61
+ });
62
+ }
63
+ }
64
+ });
65
+ result = transformedRelations;
66
+ }
67
+ if (locale) {
68
+ ref[field.name][locale] = result;
69
+ } else {
70
+ ref[field.name] = result;
71
+ }
72
+ };
73
+
74
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy90cmFuc2Zvcm0vcmVhZC9yZWxhdGlvbnNoaXAudHMiXSwic291cmNlc0NvbnRlbnQiOlsiLyogZXNsaW50LWRpc2FibGUgbm8tcGFyYW0tcmVhc3NpZ24gKi9cbmltcG9ydCB0eXBlIHsgUmVsYXRpb25zaGlwRmllbGQsIFVwbG9hZEZpZWxkIH0gZnJvbSAncGF5bG9hZC90eXBlcydcblxudHlwZSBBcmdzID0ge1xuICBmaWVsZDogUmVsYXRpb25zaGlwRmllbGQgfCBVcGxvYWRGaWVsZFxuICBsb2NhbGU/OiBzdHJpbmdcbiAgcmVmOiBSZWNvcmQ8c3RyaW5nLCB1bmtub3duPlxuICByZWxhdGlvbnM6IFJlY29yZDxzdHJpbmcsIHVua25vd24+W11cbn1cblxuZXhwb3J0IGNvbnN0IHRyYW5zZm9ybVJlbGF0aW9uc2hpcCA9ICh7IGZpZWxkLCBsb2NhbGUsIHJlZiwgcmVsYXRpb25zIH06IEFyZ3MpID0+IHtcbiAgbGV0IHJlc3VsdDogdW5rbm93blxuXG4gIGlmICghKCdoYXNNYW55JyBpbiBmaWVsZCkgfHwgZmllbGQuaGFzTWFueSA9PT0gZmFsc2UpIHtcbiAgICBjb25zdCByZWxhdGlvbiA9IHJlbGF0aW9uc1swXVxuXG4gICAgaWYgKHJlbGF0aW9uKSB7XG4gICAgICAvLyBIYW5kbGUgaGFzT25lIFBvbHlcbiAgICAgIGlmIChBcnJheS5pc0FycmF5KGZpZWxkLnJlbGF0aW9uVG8pKSB7XG4gICAgICAgIGNvbnN0IG1hdGNoZWRSZWxhdGlvbiA9IE9iamVjdC5lbnRyaWVzKHJlbGF0aW9uKS5maW5kKFxuICAgICAgICAgIChba2V5LCB2YWxdKSA9PlxuICAgICAgICAgICAgdmFsICE9PSBudWxsICYmICFbJ2lkJywgJ2xvY2FsZScsICdvcmRlcicsICdwYXJlbnQnLCAncGF0aCddLmluY2x1ZGVzKGtleSksXG4gICAgICAgIClcblxuICAgICAgICBpZiAobWF0Y2hlZFJlbGF0aW9uKSB7XG4gICAgICAgICAgY29uc3QgcmVsYXRpb25UbyA9IG1hdGNoZWRSZWxhdGlvblswXS5yZXBsYWNlKCdJRCcsICcnKVxuXG4gICAgICAgICAgcmVzdWx0ID0ge1xuICAgICAgICAgICAgcmVsYXRpb25UbyxcbiAgICAgICAgICAgIHZhbHVlOiBtYXRjaGVkUmVsYXRpb25bMV0sXG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9IGVsc2Uge1xuICAgICAgICAvLyBIYW5kbGUgaGFzT25lXG4gICAgICAgIGNvbnN0IHJlbGF0ZWREYXRhID0gcmVsYXRpb25bYCR7ZmllbGQucmVsYXRpb25Ub31JRGBdXG4gICAgICAgIHJlc3VsdCA9IHJlbGF0ZWREYXRhXG4gICAgICB9XG4gICAgfVxuICB9IGVsc2Uge1xuICAgIGNvbnN0IHRyYW5zZm9ybWVkUmVsYXRpb25zID0gW11cblxuICAgIHJlbGF0aW9ucy5mb3JFYWNoKChyZWxhdGlvbikgPT4ge1xuICAgICAgLy8gSGFuZGxlIGhhc01hbnlcbiAgICAgIGlmICghQXJyYXkuaXNBcnJheShmaWVsZC5yZWxhdGlvblRvKSkge1xuICAgICAgICBjb25zdCByZWxhdGVkRGF0YSA9IHJlbGF0aW9uW2Ake2ZpZWxkLnJlbGF0aW9uVG99SURgXVxuXG4gICAgICAgIGlmIChyZWxhdGVkRGF0YSkge1xuICAgICAgICAgIHRyYW5zZm9ybWVkUmVsYXRpb25zLnB1c2gocmVsYXRlZERhdGEpXG4gICAgICAgIH1cbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIC8vIEhhbmRsZSBoYXNNYW55IFBvbHlcbiAgICAgICAgY29uc3QgbWF0Y2hlZFJlbGF0aW9uID0gT2JqZWN0L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UFDakIsaUJBQWlCO1lBQ2pCLElBQUksQ0FBQ0MsTUFBTUMsT0FBTyxDQUFDUixNQUFNUyxVQUFVLEdBQUc7Z0JBQ3BDLE1BQU1VLGNBQWNiLFFBQVEsQ0FBQyxDQUFDLEVBQUVOLE1BQU1TLFVBQVUsQ0FBQyxFQUFFLENBQUMsQ0FBQztnQkFFckQsSUFBSVUsYUFBYTtvQkFDZkMscUJBQXFCRSxJQUFJLENBQUNIO2dCQUM1QjtZQUNGLE9BQU87Z0JBQ0wsc0JBQXNCO2dCQUN0QixNQUFNVCxrQkFBa0JDLE9BQU9DLE9BQU8sQ0FBQ04sVUFBVU8sSUFBSSxDQUNuRCxDQUFDLENBQUNDLEtBQUtDLElBQUksR0FDVEEsUUFBUSxRQUFRLENBQUM7d0JBQUM7d0JBQU07d0JBQVU7d0JBQVM7d0JBQVU7cUJBQU8sQ0FBQ0MsUUFBUSxDQUFDRjtnQkFHMUUsSUFBSUosaUJBQWlCO29CQUNuQixNQUFNRCxhQUFhQyxlQUFlLENBQUMsRUFBRSxDQUFDTyxPQUFPLENBQUMsTUFBTTtvQkFFcERHLHFCQUFxQkUsSUFBSSxDQUFDO3dCQUN4QmI7d0JBQ0FTLE9BQU9SLGVBQWUsQ0FBQyxFQUFFO29CQUMzQjtnQkFDRjtZQUNGO1FBQ0Y7UUFFQU4sU0FBU2dCO0lBQ1g7SUFFQSxJQUFJbkIsUUFBUTtRQUNWQyxHQUFHLENBQUNGLE1BQU11QixJQUFJLENBQUMsQ0FBQ3RCLE9BQU8sR0FBR0c7SUFDNUIsT0FBTztRQUNMRixHQUFHLENBQUNGLE1BQU11QixJQUFJLENBQUMsR0FBR25CO0lBQ3BCO0FBQ0YifQ==
@@ -0,0 +1,325 @@
1
+ /* eslint-disable no-param-reassign */ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "traverseFields", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return traverseFields;
9
+ }
10
+ });
11
+ const _types = require("payload/types");
12
+ const _hasManyNumber = require("./hasManyNumber");
13
+ const _relationship = require("./relationship");
14
+ const traverseFields = ({ blocks, config, dataRef, fieldPrefix, fields, numbers, path, relationships, table })=>{
15
+ const sanitizedPath = path ? `${path}.` : path;
16
+ const formatted = fields.reduce((result, field)=>{
17
+ if (field.type === 'tabs') {
18
+ traverseFields({
19
+ blocks,
20
+ config,
21
+ dataRef,
22
+ fieldPrefix,
23
+ fields: field.tabs.map((tab)=>({
24
+ ...tab,
25
+ type: 'tab'
26
+ })),
27
+ numbers,
28
+ path,
29
+ relationships,
30
+ table
31
+ });
32
+ }
33
+ if (field.type === 'collapsible' || field.type === 'row' || field.type === 'tab' && !('name' in field)) {
34
+ traverseFields({
35
+ blocks,
36
+ config,
37
+ dataRef,
38
+ fieldPrefix,
39
+ fields: field.fields,
40
+ numbers,
41
+ path,
42
+ relationships,
43
+ table
44
+ });
45
+ }
46
+ if ((0, _types.fieldAffectsData)(field)) {
47
+ const fieldName = `${fieldPrefix || ''}${field.name}`;
48
+ const fieldData = table[fieldName];
49
+ if (field.type === 'array') {
50
+ if (Array.isArray(fieldData)) {
51
+ if (field.localized) {
52
+ result[field.name] = fieldData.reduce((arrayResult, row)=>{
53
+ if (typeof row._locale === 'string') {
54
+ if (!arrayResult[row._locale]) arrayResult[row._locale] = [];
55
+ const locale = row._locale;
56
+ const data = {};
57
+ delete row._locale;
58
+ const rowResult = traverseFields({
59
+ blocks,
60
+ config,
61
+ dataRef: data,
62
+ fieldPrefix: '',
63
+ fields: field.fields,
64
+ numbers,
65
+ path: `${sanitizedPath}${field.name}.${row._order - 1}`,
66
+ relationships,
67
+ table: row
68
+ });
69
+ arrayResult[locale].push(rowResult);
70
+ }
71
+ return arrayResult;
72
+ }, {});
73
+ } else {
74
+ result[field.name] = fieldData.map((row, i)=>{
75
+ return traverseFields({
76
+ blocks,
77
+ config,
78
+ dataRef: row,
79
+ fieldPrefix: '',
80
+ fields: field.fields,
81
+ numbers,
82
+ path: `${sanitizedPath}${field.name}.${i}`,
83
+ relationships,
84
+ table: row
85
+ });
86
+ });
87
+ }
88
+ }
89
+ return result;
90
+ }
91
+ if (field.type === 'blocks') {
92
+ const blockFieldPath = `${sanitizedPath}${field.name}`;
93
+ if (Array.isArray(blocks[blockFieldPath])) {
94
+ if (field.localized) {
95
+ result[field.name] = {};
96
+ blocks[blockFieldPath].forEach((row)=>{
97
+ if (typeof row._locale === 'string') {
98
+ if (!result[field.name][row._locale]) result[field.name][row._locale] = [];
99
+ result[field.name][row._locale].push(row);
100
+ delete row._locale;
101
+ }
102
+ });
103
+ Object.entries(result[field.name]).forEach(([locale, localizedBlocks])=>{
104
+ result[field.name][locale] = localizedBlocks.map((row)=>{
105
+ const block = field.blocks.find(({ slug })=>slug === row.blockType);
106
+ if (block) {
107
+ const blockResult = traverseFields({
108
+ blocks,
109
+ config,
110
+ dataRef: row,
111
+ fieldPrefix: '',
112
+ fields: block.fields,
113
+ numbers,
114
+ path: `${blockFieldPath}.${row._order - 1}`,
115
+ relationships,
116
+ table: row
117
+ });
118
+ delete blockResult._order;
119
+ return blockResult;
120
+ }
121
+ return {};
122
+ });
123
+ });
124
+ } else {
125
+ result[field.name] = blocks[blockFieldPath].map((row, i)=>{
126
+ delete row._order;
127
+ const block = field.blocks.find(({ slug })=>slug === row.blockType);
128
+ if (block) {
129
+ return traverseFields({
130
+ blocks,
131
+ config,
132
+ dataRef: row,
133
+ fieldPrefix: '',
134
+ fields: block.fields,
135
+ numbers,
136
+ path: `${blockFieldPath}.${i}`,
137
+ relationships,
138
+ table: row
139
+ });
140
+ }
141
+ return {};
142
+ });
143
+ }
144
+ }
145
+ return result;
146
+ }
147
+ if (field.type === 'relationship' || field.type === 'upload') {
148
+ const relationPathMatch = relationships[`${sanitizedPath}${field.name}`];
149
+ if (!relationPathMatch) return result;
150
+ if (field.localized) {
151
+ result[field.name] = {};
152
+ const relationsByLocale = {};
153
+ relationPathMatch.forEach((row)=>{
154
+ if (typeof row.locale === 'string') {
155
+ if (!relationsByLocale[row.locale]) relationsByLocale[row.locale] = [];
156
+ relationsByLocale[row.locale].push(row);
157
+ }
158
+ });
159
+ Object.entries(relationsByLocale).forEach(([locale, relations])=>{
160
+ (0, _relationship.transformRelationship)({
161
+ field,
162
+ locale,
163
+ ref: result,
164
+ relations
165
+ });
166
+ });
167
+ } else {
168
+ (0, _relationship.transformRelationship)({
169
+ field,
170
+ ref: result,
171
+ relations: relationPathMatch
172
+ });
173
+ }
174
+ return result;
175
+ }
176
+ if (field.type === 'number' && field.hasMany) {
177
+ const numberPathMatch = numbers[`${sanitizedPath}${field.name}`];
178
+ if (!numberPathMatch) return result;
179
+ if (field.localized) {
180
+ result[field.name] = {};
181
+ const numbersByLocale = {};
182
+ numberPathMatch.forEach((row)=>{
183
+ if (typeof row.locale === 'string') {
184
+ if (!numbersByLocale[row.locale]) numbersByLocale[row.locale] = [];
185
+ numbersByLocale[row.locale].push(row);
186
+ }
187
+ });
188
+ Object.entries(numbersByLocale).forEach(([locale, numbers])=>{
189
+ (0, _hasManyNumber.transformHasManyNumber)({
190
+ field,
191
+ locale,
192
+ numberRows: numbers,
193
+ ref: result
194
+ });
195
+ });
196
+ } else {
197
+ (0, _hasManyNumber.transformHasManyNumber)({
198
+ field,
199
+ numberRows: numberPathMatch,
200
+ ref: result
201
+ });
202
+ }
203
+ return result;
204
+ }
205
+ if (field.type === 'select' && field.hasMany) {
206
+ if (Array.isArray(fieldData)) {
207
+ if (field.localized) {
208
+ result[field.name] = fieldData.reduce((selectResult, row)=>{
209
+ if (typeof row.locale === 'string') {
210
+ if (!selectResult[row.locale]) selectResult[row.locale] = [];
211
+ selectResult[row.locale].push(row.value);
212
+ }
213
+ return selectResult;
214
+ }, {});
215
+ } else {
216
+ result[field.name] = fieldData.map(({ value })=>value);
217
+ }
218
+ }
219
+ return result;
220
+ }
221
+ const localizedFieldData = {};
222
+ const valuesToTransform = [];
223
+ if (field.localized && Array.isArray(table._locales)) {
224
+ table._locales.forEach((localeRow)=>{
225
+ valuesToTransform.push({
226
+ ref: localizedFieldData,
227
+ table: localeRow
228
+ });
229
+ });
230
+ } else {
231
+ valuesToTransform.push({
232
+ ref: result,
233
+ table
234
+ });
235
+ }
236
+ valuesToTransform.forEach(({ ref, table })=>{
237
+ const fieldData = table[`${fieldPrefix || ''}${field.name}`];
238
+ const locale = table?._locale;
239
+ switch(field.type){
240
+ case 'tab':
241
+ case 'group':
242
+ {
243
+ const groupFieldPrefix = `${fieldPrefix || ''}${field.name}_`;
244
+ if (field.localized) {
245
+ if (typeof locale === 'string' && !ref[locale]) {
246
+ ref[locale] = {};
247
+ delete table._locale;
248
+ }
249
+ Object.entries(ref).forEach(([groupLocale, groupLocaleData])=>{
250
+ ref[groupLocale] = traverseFields({
251
+ blocks,
252
+ config,
253
+ dataRef: groupLocaleData,
254
+ fieldPrefix: groupFieldPrefix,
255
+ fields: field.fields,
256
+ numbers,
257
+ path: `${sanitizedPath}${field.name}`,
258
+ relationships,
259
+ table
260
+ });
261
+ });
262
+ } else {
263
+ const groupData = {};
264
+ ref[field.name] = traverseFields({
265
+ blocks,
266
+ config,
267
+ dataRef: groupData,
268
+ fieldPrefix: groupFieldPrefix,
269
+ fields: field.fields,
270
+ numbers,
271
+ path: `${sanitizedPath}${field.name}`,
272
+ relationships,
273
+ table
274
+ });
275
+ }
276
+ break;
277
+ }
278
+ case 'number':
279
+ {
280
+ let val = fieldData;
281
+ if (typeof fieldData === 'string') {
282
+ val = Number.parseFloat(fieldData);
283
+ }
284
+ if (typeof locale === 'string') {
285
+ ref[locale] = val;
286
+ } else {
287
+ result[field.name] = val;
288
+ }
289
+ break;
290
+ }
291
+ case 'date':
292
+ {
293
+ let val = fieldData;
294
+ if (typeof fieldData === 'string') {
295
+ val = new Date(fieldData).toISOString();
296
+ }
297
+ if (typeof locale === 'string') {
298
+ ref[locale] = val;
299
+ } else {
300
+ result[field.name] = val;
301
+ }
302
+ break;
303
+ }
304
+ default:
305
+ {
306
+ if (typeof locale === 'string') {
307
+ ref[locale] = fieldData;
308
+ } else {
309
+ result[field.name] = fieldData;
310
+ }
311
+ break;
312
+ }
313
+ }
314
+ });
315
+ if (Object.keys(localizedFieldData).length > 0) {
316
+ result[field.name] = localizedFieldData;
317
+ }
318
+ return result;
319
+ }
320
+ return result;
321
+ }, dataRef);
322
+ return formatted;
323
+ };
324
+
325
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy90cmFuc2Zvcm0vcmVhZC90cmF2ZXJzZUZpZWxkcy50cyJdLCJzb3VyY2VzQ29udGVudCI6WyIvKiBlc2xpbnQtZGlzYWJsZSBuby1wYXJhbS1yZWFzc2lnbiAqL1xuaW1wb3J0IHR5cGUgeyBTYW5pdGl6ZWRDb25maWcgfSBmcm9tICdwYXlsb2FkL2NvbmZpZydcbmltcG9ydCB0eXBlIHsgRmllbGQsIFRhYkFzRmllbGQgfSBmcm9tICdwYXlsb2FkL3R5cGVzJ1xuXG5pbXBvcnQgeyBmaWVsZEFmZmVjdHNEYXRhIH0gZnJvbSAncGF5bG9hZC90eXBlcydcblxuaW1wb3J0IHR5cGUgeyBCbG9ja3NNYXAgfSBmcm9tICcuLi8uLi91dGlsaXRpZXMvY3JlYXRlQmxvY2tzTWFwJ1xuXG5pbXBvcnQgeyB0cmFuc2Zvcm1IYXNNYW55TnVtYmVyIH0gZnJvbSAnLi9oYXNNYW55TnVtYmVyJ1xuaW1wb3J0IHsgdHJhbnNmb3JtUmVsYXRpb25zaGlwIH0gZnJvbSAnLi9yZWxhdGlvbnNoaXAnXG5cbnR5cGUgVHJhdmVyc2VGaWVsZHNBcmdzID0ge1xuICAvKipcbiAgICogUHJlLWZvcm1hdHRlZCBibG9ja3MgbWFwXG4gICAqL1xuICBibG9ja3M6IEJsb2Nrc01hcFxuICAvKipcbiAgICogVGhlIGZ1bGwgUGF5bG9hZCBjb25maWdcbiAgICovXG4gI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AgICAgICAgICAgICAgIGRlbGV0ZSByb3cuX2xvY2FsZVxuXG4gICAgICAgICAgICAgICAgY29uc3Qgcm93UmVzdWx0ID0gdHJhdmVyc2VGaWVsZHM8VD4oe1xuICAgICAgICAgICAgICAgICAgYmxvY2tzLFxuICAgICAgICAgICAgICAgICAgY29uZmlnLFxuICAgICAgICAgICAgICAgICAgZGF0YVJlZjogZGF0YSxcbiAgICAgICAgICAgICAgICAgIGZpZWxkUHJlZml4OiAnJyxcbiAgICAgICAgICAgICAgICAgIGZpZWxkczogZmllbGQuZmllbGRzLFxuICAgICAgICAgICAgICAgICAgbnVtYmVycyxcbiAgICAgICAgICAgICAgICAgIHBhdGg6IGAke3Nhbml0aXplZFBhdGh9JHtmaWVsZC5uYW1lfS4ke3Jvdy5fb3JkZXIgLSAxfWAsXG4gICAgICAgICAgICAgICAgICByZWxhdGlvbnNoaXBzLFxuICAgICAgICAgICAgICAgICAgdGFibGU6IHJvdyxcbiAgICAgICAgICAgICAgICB9KVxuXG4gICAgICAgICAgICAgICAgYXJyYXlSZXN1bHRbbG9jYWxlXS5wdXNoKHJvd1Jlc3VsdClcbiAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgIHJldHVybiBhcnJheVJlc3VsdFxuICAgICAgICAgICAgfSwge30pXG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHJlc3VsdFtmaWVsZC5uYW1lXSA9IGZpZWxkRGF0YS5tYXAoKHJvdywgaSkgPT4ge1xuICAgICAgICAgICAgICByZXR1cm4gdHJhdmVyc2VGaWVsZHM8VD4oe1xuICAgICAgICAgICAgICAgIGJsb2NrcyxcbiAgICAgICAgICAgICAgICBjb25maWcsXG4gICAgICAgICAgICAgICAgZGF0YVJlZjogcm93LFxuICAgICAgICAgICAgICAgIGZpZWxkUHJlZml4OiAnJyxcbiAgICAgICAgICAgICAgICBmaWVsZHM6IGZpZWxkLmZpZWxkcyxcbiAgICAgICAgICAgICAgICBudW1iZXJzLFxuICA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YWxpemVkQmxvY2tzXSkgPT4ge1xuICAgICAgICAgICAgICByZXN1bHRbZmllbGQubmFtZV1bbG9jYWxlXSA9IGxvY2FsaXplZEJsb2Nrcy5tYXAoKHJvdykgPT4ge1xuICAgICAgICAgICAgICAgIGNvbnN0IGJsb2NrID0gZmllbGQuYmxvY2tzLmZpbmQoKHsgc2x1ZyB9KSA9PiBzbHVnID09PSByb3cuYmxvY2tUeXBlKVxuXG4gICAgICAgICAgICAgICAgaWYgKGJsb2NrKSB7XG4gICAgICAgICAgICAgICAgICBjb25zdCBibG9ja1Jlc3VsdCA9IHRyYXZlcnNlRmllbGRzPFQ+KHtcbiAgICAgICAgICAgICAgICAgICAgYmxvY2tzLFxuICAgICAgICAgICAgICAgICAgICBjb25maWcsXG4gICAgICAgICAgICAgICAgICAgIGRhdGFSZWY6IHJvdyxcbiAgICAgICAgICAgICAgICAgICAgZmllbGRQcmVmaXg6ICcnLFxuICAgICAgICAgICAgICAgICAgICBmaWVsZHM6IGJsb2NrLmZpZWxkcyxcbiAgICAgICAgICAgICAgICAgICAgbnVtYmVycyxcbiAgICAgICAgICAgICAgICAgICAgcGF0aDogYCR7YmxvY2tGaWVsZFBhdGh9LiR7cm93Ll9vcmRlciAtIDF9YCxcbiAgICAgICAgICAgICAgICAgICAgcmVsYXRpb25zaGlwcyxcbiAgICAgICAgICAgICAgICAgICAgdGFibGU6IHJvdyxcbiAgICAgICAgICAgICAgICAgIH0pXG5cbiAgICAgICAgICAgICAgICAgIGRlbGV0ZSBibG9ja1Jlc3VsdC5fb3JkZXJcbiAgICAgICAgICAgICAgICAgIHJldHVybiBibG9ja1Jlc3VsdFxuICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgIHJldHVybiB7fVxuICAgICAgICAgICAgICB9KVxuICAgICAgICAgICAgfSlcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgcmVzdWx0W2ZpZWxkLm5hbWVdID0gYmxvY2tzW2Jsb2NrRmllbGRQYXRoXS5tYXAoKHJvdywgaSkgPT4ge1xuICAgICAgICAgICAgICBkZWxldGUgcm93Ll9vcmRlclxuICAgICAgICAgICAgICBjb25zdCBibG9jayA9IGZpZWxkLmJsb2Nrcy5maW5kKCh7IHNsdWcgfSkgPT4gc2x1ZyA9PT0gcm93LmJsb2NrVHlwZSlcblxuICAgICAgICAgICAgICBpZiAoYmxvY2spIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gdHJhdmVyc2VGaWVsZHM8VD4oe1xuICAgICAgICAgICAgICAgICAgYmxvY2tzLFxuICAgICAgICAgICAgICAgICAgY29uZmlnLFxuICAgICAgICAgICAgICAgICAgZGF0YVJlZjogcm93LFxuICAgICAgICAgICAgICAgICAgZmllbGRQcmVmaXg6ICcnLFxuICAgICAgICAgICAgICAgICAgZmllbGRzOiBibG9jay5maWVsZHMsXG4gICAgICAgICAgICAgICAgICBudW1iZXJzLFxuICAgICAgICAgICAgICAgICAgcGF0aDogYCR7YmxvY2tGaWVsZFBhdGh9LiR7aX1gLFxuICAgICAgICAgICAgICAgICAgcmVsYXRpb25zaGlwcyxcbiAgICAgICAgICAgICAgICAgIHRhYmxlOiByb3csXG4gICAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgIHJldHVybiB7fVxuICAgICAgICAgICAgfSlcbiAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICByZXR1cm4gcmVzdWx0XG4gICAgICB9XG5cbiAgICAgIGlmIChmaWVsZC50eXBlID09PSAncmVsYXRpb25zaGlwJyB8fCBmaWVsZC50eXBlID09PSAndXBsb2FkJykge1xuICAgICAgICBjb25zdCByZWxhdGlvblBhdGhNYXRjaCA9IHJlbGF0aW9uc2hpcHNbYCR7c2FuaXRpemVkUGF0aH0ke2ZpZWxkLm5hbWV9YF1cbiAgICAgICAgaWYgKCFyZWxhdGlvblBhdGhNYXRjaCkgcmV0dXJuIHJlc3VsdFxuXG4gICAgICAgIGlmIChmaWVsZC5sb2NhbGl6ZWQpIHtcbiAgICAgICAgICByZXN1bHRbZmllbGQubmFtZV0gPSB7fVxuICAgICAgICAgIGNvbnN0IHJlbGF0aW9uc0J5TG9jYWxlOiBSZWNvcmQ8c3RyaW5nLCBSZWNvcmQ8c3RyaW5nLCB1bmtub3duPltdPiA9IHt9XG5cbiAgICAgICAgICByZWxhdGlvblBhdGhNYXRjaC5mb3JFYWNoKChyb3cpID0+IHtcbiAgICAgICAgICAgIGlmICh0eXBlb2Ygcm93LmxvY2FsZSA9PT0gJ3N0cmluZycpIHtcbiAgICAgICAgICAgICAgaWYgKCFyZWxhdGlvbnNCeUxvY2FsZVtyb3cubG9jYWxlXSkgcmVsYXRpb25zQnlMb2NhbGVbcm93LmxvY2FsZV0gPSBbXVxuICAgICAgICAgICAgICByZWxhdGlvbnNCeUxvY2FsZVtyb3cubG9jYWxlXS5wdXNoKHJvdylcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9KVxuXG4gICAgICAgICAgT2JqZWN0LmVudHJpZXMocmVsYXRpb25zQnlMb2NhbGUpLmZvckVhY2goKFtsb2NhbGUsIHJlbGF0aW9uc10pID0+IHtcbiAgICAgICAgICAgIHRyYW5zZm9ybVJlbGF0aW9uc2hpcCh7XG4gICAgICAgICAgICAgIGZpZWxkLFxuICAgICAgICAgICAgICBsb2NhbGUsXG4gICAgICAgICAgICAgIHJlZjogcmVzdWx0LFxuICAgICAgICAgICAgICByZWxhdGlvbnMsXG4gICAgICAgICAgICB9KVxuICAgICAgICAgIH0pXG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgdHJhbnNmb3JtUmVsYXRpb25zaGlwKHtcbiAgICAgICAgICAgIGZpZWxkLFxuICAgICAgICAgICAgcmVmOiByZXN1bHQsXG4gICAgICAgICAgICByZWxhdGlvbnM6IHJlbGF0aW9uUGF0aE1hdGNoLFxuICAgICAgICAgIH0pXG4gICAgICAgIH1cblxuICAgICAgICByZXR1cm4gcmVzdWx0XG4gICAgICB9XG5cbiAgICAgIGlmIChmaWVsZC50eXBlID09PSAnbnVtYmVyJyAmJiBmaWVsZC5oYXNNYW55KSB7XG4gICAgICAgIGNvbnN0IG51bWJlclBhdGhNYXRjaCA9IG51bWJlcnNbYCR7c2FuaXRpemVkUGF0aH0ke2ZpZWxkLm5hbWV9YF1cbiAgICAgICAgaWYgKCFudW1iZXJQYXRoTWF0Y2gpIHJldHVybiByZXN1bHRcblxuICAgICAgICBpZiAoZmllbGQubG9jYWxpemVkKSB7XG4gICAgICAgICAgcmVzdWx0W2ZpZWxkLm5hbWVdID0ge31cbiAgICAgICAgICBjb25zdCBudW1iZXJzQnlMb2NhbGU6IFJlY29yZDxzdHJpbmcsIFJlY29yZDxzdHJpbmcsIHVua25vd24+W10+ID0ge31cblxuICAgICAgICAgIG51bWJlclBhdGhNYXRjaC5mb3JFYWNoKChyb3cpID0+IHtcbiAgICAgICAgICAgIGlmICh0eXBlb2Ygcm93LmxvY2FsZSA9PT0gJ3N0cmluZycpIHtcbiAgICAgICAgICAgICAgaWYgKCFudW1iZXJzQnlMb2NhbGVbcm93LmxvY2FsZV0pIG51bWJlcnNCeUxvY2FsZVtyb3cubG9jYWxlXSA9IFtdXG4gICAgICAgICAgICAgIG51bWJlcnNCeUxvY2FsZVtyb3cubG9jYWxlXS5wdXNoKHJvdylcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9KVxuXG4gICAgICAgICAgT2JqZWN0LmVudHJpZXMobnVtYmVyc0J5TG9jYWxlKS5mb3JFYWNoKChbbG9jYWxlLCBudW1iZXJzXSkgPT4ge1xuICAgICAgICAgICAgdHJhbnNmb3JtSGFzTWFueU51bWJlcih7XG4gICAgICAgICAgICAgIGZpZWxkLFxuICAgICAgICAgICAgICBsb2NhbGUsXG4gICAgICAgICAgICAgIG51bWJlclJvd3M6IG51bWJlcnMsXG4gICAgICAgICAgICAgIHJlZjogcmVzdWx0LFxuICAgICAgICAgICAgfSlcbiAgICAgICAgICB9KVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHRyYW5zZm9ybUhhc01hbnlOdW1iZXIoe1xuICAgICAgICAgICAgZmllbGQsXG4gICAgICAgICAgICBudW1iZXJSb3dzOiBudW1iZXJQYXRoTWF0Y2gsXG4gICAgICAgICAgICByZWY6IHJlc3VsdCxcbiAgICAgICAgICB9KVxuICAgICAgICB9XG5cbiAgICAgICAgcmV0dXJuIHJlc3VsdFxuICAgICAgfVxuXG4gICAgICBpZiAoZmllbGQudHlwZSA9PT0gJ3NlbGVjdCcgJiYgZmllbGQuaGFzTWFueSkge1xuICAgICAgICBpZiAoQXJyYXkuaXNBcnJheShmaWVsZERhdGEpKSB7XG4gICAgICAgICAgaWYgKGZpZWxkLmxvY2FsaXplZCkge1xuICAgICAgICAgICAgcmVzdWx0W2ZpZWxkLm5hbWVdID0gZmllbGREYXRhLnJlZHVjZSgoc2VsZWN0UmVzdWx0LCByb3cpID0+IHtcbiAgICAgICAgICAgICAgaWYgKHR5cGVvZiByb3cubG9jYWxlID09PSAnc3RyaW5nJykge1xuICAgICAgICAgICAgICAgIGlmICghc2VsZWN0UmVzdWx0W3Jvdy5sb2NhbGVdKSBzZWxlY3RSZXN1bHRbcm93LmxvY2FsZV0gPSBbXVxuICAgICAgICAgICAgICAgIHNlbGVjdFJlc3VsdFtyb3cubG9jYWxlXS5wdXNoKHJvdy52YWx1ZSlcbiAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgIHJldHVybiBzZWxlY3RSZXN1bHRcbiAgICAgICAgICAgIH0sIHt9KVxuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICByZXN1bHRbZmllbGQubmFtZV0gPSBmaWVsZERhdGEubWFwKCh7IHZhbHVlIH0pID0+IHZhbHVlKVxuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gcmVzdWx0XG4gICAgICB9XG5cbiAgICAgIGNvbnN0IGxvY2FsaXplZEZpZWxkRGF0YSA9IHt9XG4gICAgICBjb25zd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ICAgICAgICAgICAgICAgcmVmW2xvY2FsZV0gPSB7fVxuICAgICAgICAgICAgICAgIGRlbGV0ZSB0YWJsZS5fbG9jYWxlXG4gICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICBPYmplY3QuZW50cmllcyhyZWYpLmZvckVhY2goKFtncm91cExvY2FsZSwgZ3JvdXBMb2NhbGVEYXRhXSkgPT4ge1xuICAgICAgICAgICAgICAgIHJlZltncm91cExvY2FsZV0gPSB0cmF2ZXJzZUZpZWxkczxSZWNvcmQ8c3RyaW5nLCB1bmtub3duPj4oe1xuICAgICAgICAgICAgICAgICAgYmxvY2tzLFxuICAgICAgICAgICAgICAgICAgY29uZmlnLFxuICAgICAgICAgICAgICAgICAgZGF0YVJlZjogZ3JvdXBMb2NhbGVEYXRhIGFzIFJlY29yZDxzdHJpbmcsIHVua25vd24+LFxuICAgICAgICAgICAgICAgICAgZmllbGRQcmVmaXg6IGdyb3VwRmllbGRQcmVmaXgsXG4gICAgICAgICAgICAgICAgICBmaWVsZHM6IGZpZWxkLmZpZWxkcyxcbiAgICAgICAgICAgICAgICAgIG51bWJlcnMsXG4gICAgICAgICAgICAgICAgICBwYXRoOiBgJHtzYW5pdGl6ZWRQYXRofSR7ZmllbGQubmFtZX1gLFxuICAgICAgICAgICAgICAgICAgcmVsYXRpb25zaGlwcyxcbiAgICAgICAgICAgICAgICAgIHRhYmxlLFxuICAgICAgICAgICAgICAgIH0pXG4gICAgICAgICAgICAgIH0pXG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICBjb25zdCBncm91cERhdGEgPSB7fVxuXG4gICAgICAgICAgICAgIHJlZltmaWVsZC5uYW1lXSA9IHRyYXZlcnNlRmllbGRzPFJlY29yZDxzdHJpbmcsIHVua25vd24+Pih7XG4gICAgICAgICAgICAgICAgYmxvY2tzLFxuICAgICAgICAgICAgICAgIGNvbmZpZyxcbiAgICAgICAgICAgICAgICBkYXRhUmVmOiBncm91cERhdGEgYXMgUmVjb3JkPHN0cmluZywgdW5rbm93bj4sXG4gICAgICAgICAgICAgICAgZmllbGRQcmVmaXg6IGdyb3VwRmllbGRQcmVmaXgsXG4gICAgICAgICAgICAgICAgZmllbGRzOiBmaWVsZC5maWVsZHMsXG4gICAgICAgICAgICAgICAgbnVtYmVycyxcbiAgICAgICAgICAgICAgICBwYXRoOiBgJHtzYW5pdGl6ZWRQYXRofSR7ZmllbGQubmFtZX1gLFxuICAgICAgICAgICAgICAgIHJlbGF0aW9uc2hpcHMsXG4gICAgICAgICAgICAgICAgdGFibGUsXG4gICAgICAgICAgICAgIH0pXG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGJyZWFrXG4gICAgICAgICAgfVxuXG4gICAgICAgICAgY2FzZSAnbnVtYmVyJzoge1xuICAgICAgICAgICAgbGV0IHZhbCA9IGZpZWxkRGF0YVxuICAgICAgICAgICAgaWYgKHR5cGVvZiBmaWVsZERhdGEgPT09ICdzdHJpbmcnKSB7XG4gICAgICAgICAgICAgIHZhbCA9IE51bWJlci5wYXJzZUZsb2F0KGZpZWxkRGF0YSlcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKHR5cGVvZiBsb2NhbGUgPT09ICdzdHJpbmcnKSB7XG4gICAgICAgICAgICAgIHJlZltsb2NhbGVdID0gdmFsXG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICByZXN1bHRbZmllbGQubmFtZV0gPSB2YWxcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgYnJlYWtcbiAgICAgICAgICB9XG5cbiAgICAgICAgICBjYXNlICdkYXRlJzoge1xuICAgICAgICAgICAgbGV0IHZhbCA9IGZpZWxkRGF0YVxuXG4gICAgICAgICAgICBpZiAodHlwZW9mIGZpZWxkRGF0YSA9PT0gJ3N0cmluZycpIHtcbiAgICAgICAgICAgICAgdmFsID0gbmV3IERhdGUoZmllbGREYXRhKS50b0lTT1N0cmluZygpXG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmICh0eXBlb2YgbG9jYWxlID09PSAnc3RyaW5nJykge1xuICAgICAgICAgICAgICByZWZbbG9jYWxlXSA9IHZhbFxuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgcmVzdWx0W2ZpZWxkLm5hbWVdID0gdmFsXG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGJyZWFrXG4gICAgICAgICAgfVxuXG4gICAgICAgICAgZGVmYXVsdDoge1xuICAgICAgICAgICAgaWYgKHR5cGVvZiBsb2NhbGUgPT09ICdzdHJpbmcnKSB7XG4gICAgICAgICAgICAgIHJlZltsb2NhbGVdID0gZmllbGREYXRhXG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICByZXN1bHRbZmllbGQubmFtZV0gPSBmaWVsZERhdGFcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgYnJlYWtcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH0pXG5cbiAgICAgIGlmIChPYmplY3Qua2V5cyhsb2NhbGl6ZWRGaWVsZERhdGEpLmxlbmd0aCA+IDApIHtcbiAgICAgICAgcmVzdWx0W2ZpZWxkLm5hbWVdID0gbG9jYWxpemVkRmllbGREYXRhXG4gICAgICB9XG5cbiAgICAgIHJldHVybiByZXN1bHRcbiAgICB9XG5cbiAgICByZXR1cm4gcmVzdWx0XG4gIH0sIGRhdGFSZWYpXG5cbiAgcmV0dXJuIGZvcm1hdHRlZCBhcyBUXG59XG4iXSwibmFtZXMiOlsidHJhdmVyc2VGaWVsZHMiLCJibG9ja3MiLCJjb25maWciLCJkYXRhUmVmIiwiZmllbGRQcmVmaXgiLCJmaWVsZHMiLCJudW1iZXJzIiwicGF0aCIsInJlbGF0aW9uc2hpcHMiLCJ0YWJsZSIsInNhbml0aXplZFBhdGgiLCJmb3JtYXR0ZWQiLCJyZWR1Y2UiLCJyZXN1bHQiLCJmaWVsZCIsInR5cGUiLCJ0YWJzIiwibWFwIiwidGFiIiwiZ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87Z0NBQ0xwRCxNQUFNLENBQUNDLE1BQU1PLElBQUksQ0FBQyxHQUFHNEM7NEJBQ3ZCOzRCQUVBO3dCQUNGO29CQUVBO3dCQUFTOzRCQUNQLElBQUksT0FBT3BDLFdBQVcsVUFBVTtnQ0FDOUJvQixHQUFHLENBQUNwQixPQUFPLEdBQUdQOzRCQUNoQixPQUFPO2dDQUNMVCxNQUFNLENBQUNDLE1BQU1PLElBQUksQ0FBQyxHQUFHQzs0QkFDdkI7NEJBRUE7d0JBQ0Y7Z0JBQ0Y7WUFDRjtZQUVBLElBQUllLE9BQU9pQyxJQUFJLENBQUNiLG9CQUFvQmMsTUFBTSxHQUFHLEdBQUc7Z0JBQzlDMUQsTUFBTSxDQUFDQyxNQUFNTyxJQUFJLENBQUMsR0FBR29DO1lBQ3ZCO1lBRUEsT0FBTzVDO1FBQ1Q7UUFFQSxPQUFPQTtJQUNULEdBQUdWO0lBRUgsT0FBT1E7QUFDVCJ9
@@ -0,0 +1,55 @@
1
+ /* eslint-disable no-param-reassign */ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "transformArray", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return transformArray;
9
+ }
10
+ });
11
+ const _isArrayOfRows = require("../../utilities/isArrayOfRows");
12
+ const _traverseFields = require("./traverseFields");
13
+ const transformArray = ({ arrayTableName, baseTableName, blocks, data, field, locale, numbers, path, relationships, relationshipsToDelete, selects })=>{
14
+ const newRows = [];
15
+ if ((0, _isArrayOfRows.isArrayOfRows)(data)) {
16
+ data.forEach((arrayRow, i)=>{
17
+ const newRow = {
18
+ arrays: {},
19
+ locales: {},
20
+ row: {
21
+ _order: i + 1
22
+ }
23
+ };
24
+ if (locale) {
25
+ newRow.locales[locale] = {
26
+ _locale: locale
27
+ };
28
+ }
29
+ if (field.localized) {
30
+ newRow.row._locale = locale;
31
+ }
32
+ (0, _traverseFields.traverseFields)({
33
+ arrays: newRow.arrays,
34
+ baseTableName,
35
+ blocks,
36
+ columnPrefix: '',
37
+ data: arrayRow,
38
+ fieldPrefix: '',
39
+ fields: field.fields,
40
+ locales: newRow.locales,
41
+ numbers,
42
+ parentTableName: arrayTableName,
43
+ path: `${path || ''}${field.name}.${i}.`,
44
+ relationships,
45
+ relationshipsToDelete,
46
+ row: newRow.row,
47
+ selects
48
+ });
49
+ newRows.push(newRow);
50
+ });
51
+ }
52
+ return newRows;
53
+ };
54
+
55
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy90cmFuc2Zvcm0vd3JpdGUvYXJyYXkudHMiXSwic291cmNlc0NvbnRlbnQiOlsiLyogZXNsaW50LWRpc2FibGUgbm8tcGFyYW0tcmVhc3NpZ24gKi9cbmltcG9ydCB0eXBlIHsgQXJyYXlGaWVsZCB9IGZyb20gJ3BheWxvYWQvdHlwZXMnXG5cbmltcG9ydCB0eXBlIHsgQXJyYXlSb3dUb0luc2VydCwgQmxvY2tSb3dUb0luc2VydCwgUmVsYXRpb25zaGlwVG9EZWxldGUgfSBmcm9tICcuL3R5cGVzJ1xuXG5pbXBvcnQgeyBpc0FycmF5T2ZSb3dzIH0gZnJvbSAnLi4vLi4vdXRpbGl0aWVzL2lzQXJyYXlPZlJvd3MnXG5pbXBvcnQgeyB0cmF2ZXJzZUZpZWxkcyB9IGZyb20gJy4vdHJhdmVyc2VGaWVsZHMnXG5cbnR5cGUgQXJncyA9IHtcbiAgYXJyYXlUYWJsZU5hbWU6IHN0cmluZ1xuICBiYXNlVGFibGVOYW1lOiBzdHJpbmdcbiAgYmxvY2tzOiB7XG4gICAgW2Jsb2NrVHlwZTogc3RyaW5nXTogQmxvY2tSb3dUb0luc2VydFtdXG4gIH1cbiAgZGF0YTogdW5rbm93blxuICBmaWVsZDogQXJyYXlGaWVsZFxuICBsb2NhbGU/OiBzdHJpbmdcbiAgbnVtYmVyczogUmVjb3JkPHN0cmluZywg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