@payloadcms/drizzle 3.1.1-canary.c40ff01 → 3.1.2-canary.eb1a61e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/count.js +1 -1
- package/dist/count.js.map +1 -1
- package/dist/countGlobalVersions.js +1 -1
- package/dist/countGlobalVersions.js.map +1 -1
- package/dist/countVersions.js +1 -1
- package/dist/countVersions.js.map +1 -1
- package/dist/create.js +1 -1
- package/dist/create.js.map +1 -1
- package/dist/createGlobal.js +1 -1
- package/dist/createGlobal.js.map +1 -1
- package/dist/createGlobalVersion.js +1 -1
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createVersion.js +1 -1
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteMany.js +1 -1
- package/dist/deleteMany.js.map +1 -1
- package/dist/deleteOne.js +3 -3
- package/dist/deleteOne.js.map +1 -1
- package/dist/deleteVersions.js +1 -1
- package/dist/deleteVersions.js.map +1 -1
- package/dist/find/buildFindManyArgs.d.ts +2 -2
- package/dist/find/buildFindManyArgs.d.ts.map +1 -1
- package/dist/find/buildFindManyArgs.js.map +1 -1
- package/dist/find/findMany.d.ts +2 -2
- package/dist/find/findMany.d.ts.map +1 -1
- package/dist/find/findMany.js.map +1 -1
- package/dist/find/traverseFields.d.ts +2 -2
- package/dist/find/traverseFields.d.ts.map +1 -1
- package/dist/find/traverseFields.js +312 -359
- package/dist/find/traverseFields.js.map +1 -1
- package/dist/find.js +1 -1
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.js +1 -1
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.js +1 -1
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.js +1 -1
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.js +1 -1
- package/dist/findVersions.js.map +1 -1
- package/dist/postgres/init.js +4 -4
- package/dist/postgres/init.js.map +1 -1
- package/dist/postgres/schema/build.d.ts +2 -2
- package/dist/postgres/schema/build.d.ts.map +1 -1
- package/dist/postgres/schema/build.js.map +1 -1
- package/dist/postgres/schema/idToUUID.d.ts +2 -2
- package/dist/postgres/schema/idToUUID.d.ts.map +1 -1
- package/dist/postgres/schema/idToUUID.js.map +1 -1
- package/dist/postgres/schema/setColumnID.d.ts +2 -2
- package/dist/postgres/schema/setColumnID.d.ts.map +1 -1
- package/dist/postgres/schema/setColumnID.js +1 -3
- package/dist/postgres/schema/setColumnID.js.map +1 -1
- package/dist/postgres/schema/traverseFields.d.ts +2 -2
- package/dist/postgres/schema/traverseFields.d.ts.map +1 -1
- package/dist/postgres/schema/traverseFields.js +38 -182
- package/dist/postgres/schema/traverseFields.js.map +1 -1
- package/dist/queries/buildAndOrConditions.d.ts +2 -2
- package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
- package/dist/queries/buildAndOrConditions.js.map +1 -1
- package/dist/queries/buildOrderBy.d.ts +2 -2
- package/dist/queries/buildOrderBy.d.ts.map +1 -1
- package/dist/queries/buildOrderBy.js.map +1 -1
- package/dist/queries/buildQuery.d.ts +2 -2
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/buildQuery.js.map +1 -1
- package/dist/queries/getTableColumnFromPath.d.ts +3 -3
- package/dist/queries/getTableColumnFromPath.d.ts.map +1 -1
- package/dist/queries/getTableColumnFromPath.js +34 -59
- package/dist/queries/getTableColumnFromPath.js.map +1 -1
- package/dist/queries/parseParams.d.ts +2 -2
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queryDrafts.js +1 -1
- package/dist/queryDrafts.js.map +1 -1
- package/dist/transform/read/index.d.ts +2 -2
- package/dist/transform/read/index.d.ts.map +1 -1
- package/dist/transform/read/index.js.map +1 -1
- package/dist/transform/read/traverseFields.d.ts +2 -2
- package/dist/transform/read/traverseFields.d.ts.map +1 -1
- package/dist/transform/read/traverseFields.js +380 -421
- package/dist/transform/read/traverseFields.js.map +1 -1
- package/dist/transform/write/array.d.ts +2 -2
- package/dist/transform/write/array.d.ts.map +1 -1
- package/dist/transform/write/array.js +1 -1
- package/dist/transform/write/array.js.map +1 -1
- package/dist/transform/write/blocks.d.ts +2 -2
- package/dist/transform/write/blocks.d.ts.map +1 -1
- package/dist/transform/write/blocks.js +1 -1
- package/dist/transform/write/blocks.js.map +1 -1
- package/dist/transform/write/index.d.ts +2 -2
- package/dist/transform/write/index.d.ts.map +1 -1
- package/dist/transform/write/index.js.map +1 -1
- package/dist/transform/write/traverseFields.d.ts +2 -2
- package/dist/transform/write/traverseFields.d.ts.map +1 -1
- package/dist/transform/write/traverseFields.js +53 -171
- package/dist/transform/write/traverseFields.js.map +1 -1
- package/dist/update.js +2 -2
- package/dist/update.js.map +1 -1
- package/dist/updateGlobal.js +1 -1
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.js +1 -1
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateVersion.js +1 -1
- package/dist/updateVersion.js.map +1 -1
- package/dist/upsertRow/index.d.ts.map +1 -1
- package/dist/upsertRow/index.js +8 -8
- package/dist/upsertRow/index.js.map +1 -1
- package/dist/upsertRow/types.d.ts +2 -2
- package/dist/upsertRow/types.d.ts.map +1 -1
- package/dist/upsertRow/types.js.map +1 -1
- package/package.json +4 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { fieldIsVirtual } from 'payload/shared';
|
|
2
2
|
import { transformHasManyNumber } from './hasManyNumber.js';
|
|
3
3
|
import { transformHasManyText } from './hasManyText.js';
|
|
4
4
|
import { transformRelationship } from './relationship.js';
|
|
@@ -7,106 +7,163 @@ import { transformRelationship } from './relationship.js';
|
|
|
7
7
|
export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fieldPrefix, fields, joinQuery, numbers, path, relationships, table, texts, withinArrayOrBlockLocale })=>{
|
|
8
8
|
const sanitizedPath = path ? `${path}.` : path;
|
|
9
9
|
const formatted = fields.reduce((result, field)=>{
|
|
10
|
-
if (field
|
|
11
|
-
|
|
12
|
-
adapter,
|
|
13
|
-
blocks,
|
|
14
|
-
config,
|
|
15
|
-
dataRef,
|
|
16
|
-
deletions,
|
|
17
|
-
fieldPrefix,
|
|
18
|
-
fields: field.tabs.map((tab)=>({
|
|
19
|
-
...tab,
|
|
20
|
-
type: 'tab'
|
|
21
|
-
})),
|
|
22
|
-
joinQuery,
|
|
23
|
-
numbers,
|
|
24
|
-
path,
|
|
25
|
-
relationships,
|
|
26
|
-
table,
|
|
27
|
-
texts,
|
|
28
|
-
withinArrayOrBlockLocale
|
|
29
|
-
});
|
|
10
|
+
if (fieldIsVirtual(field)) {
|
|
11
|
+
return result;
|
|
30
12
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
deletions,
|
|
38
|
-
fieldPrefix,
|
|
39
|
-
fields: field.fields,
|
|
40
|
-
joinQuery,
|
|
41
|
-
numbers,
|
|
42
|
-
path,
|
|
43
|
-
relationships,
|
|
44
|
-
table,
|
|
45
|
-
texts,
|
|
46
|
-
withinArrayOrBlockLocale
|
|
47
|
-
});
|
|
13
|
+
const fieldName = `${fieldPrefix || ''}${field.name}`;
|
|
14
|
+
let fieldData = table[fieldName];
|
|
15
|
+
const localizedFieldData = {};
|
|
16
|
+
const valuesToTransform = [];
|
|
17
|
+
if (fieldPrefix) {
|
|
18
|
+
deletions.push(()=>delete table[fieldName]);
|
|
48
19
|
}
|
|
49
|
-
if (
|
|
50
|
-
if (
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
20
|
+
if (field.type === 'array') {
|
|
21
|
+
if (Array.isArray(fieldData)) {
|
|
22
|
+
if (field.localized) {
|
|
23
|
+
result[field.name] = fieldData.reduce((arrayResult, row)=>{
|
|
24
|
+
if (typeof row._locale === 'string') {
|
|
25
|
+
if (!arrayResult[row._locale]) {
|
|
26
|
+
arrayResult[row._locale] = [];
|
|
27
|
+
}
|
|
28
|
+
const locale = row._locale;
|
|
29
|
+
const data = {};
|
|
30
|
+
delete row._locale;
|
|
31
|
+
if (row._uuid) {
|
|
32
|
+
row.id = row._uuid;
|
|
33
|
+
delete row._uuid;
|
|
34
|
+
}
|
|
35
|
+
const rowResult = traverseFields({
|
|
36
|
+
adapter,
|
|
37
|
+
blocks,
|
|
38
|
+
config,
|
|
39
|
+
dataRef: data,
|
|
40
|
+
deletions,
|
|
41
|
+
fieldPrefix: '',
|
|
42
|
+
fields: field.flattenedFields,
|
|
43
|
+
numbers,
|
|
44
|
+
path: `${sanitizedPath}${field.name}.${row._order - 1}`,
|
|
45
|
+
relationships,
|
|
46
|
+
table: row,
|
|
47
|
+
texts,
|
|
48
|
+
withinArrayOrBlockLocale: locale
|
|
49
|
+
});
|
|
50
|
+
if ('_order' in rowResult) {
|
|
51
|
+
delete rowResult._order;
|
|
52
|
+
}
|
|
53
|
+
arrayResult[locale].push(rowResult);
|
|
54
|
+
}
|
|
55
|
+
return arrayResult;
|
|
56
|
+
}, {});
|
|
57
|
+
} else {
|
|
58
|
+
result[field.name] = fieldData.reduce((acc, row, i)=>{
|
|
59
|
+
if (row._uuid) {
|
|
60
|
+
row.id = row._uuid;
|
|
61
|
+
delete row._uuid;
|
|
62
|
+
}
|
|
63
|
+
if ('_order' in row) {
|
|
64
|
+
delete row._order;
|
|
65
|
+
}
|
|
66
|
+
if (!withinArrayOrBlockLocale || withinArrayOrBlockLocale && withinArrayOrBlockLocale === row._locale) {
|
|
67
|
+
if (row._locale) {
|
|
70
68
|
delete row._locale;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
69
|
+
}
|
|
70
|
+
acc.push(traverseFields({
|
|
71
|
+
adapter,
|
|
72
|
+
blocks,
|
|
73
|
+
config,
|
|
74
|
+
dataRef: row,
|
|
75
|
+
deletions,
|
|
76
|
+
fieldPrefix: '',
|
|
77
|
+
fields: field.flattenedFields,
|
|
78
|
+
numbers,
|
|
79
|
+
path: `${sanitizedPath}${field.name}.${i}`,
|
|
80
|
+
relationships,
|
|
81
|
+
table: row,
|
|
82
|
+
texts,
|
|
83
|
+
withinArrayOrBlockLocale
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
return acc;
|
|
87
|
+
}, []);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
if (field.type === 'blocks') {
|
|
93
|
+
const blockFieldPath = `${sanitizedPath}${field.name}`;
|
|
94
|
+
const blocksByPath = blocks[blockFieldPath];
|
|
95
|
+
if (Array.isArray(blocksByPath)) {
|
|
96
|
+
if (field.localized) {
|
|
97
|
+
result[field.name] = {};
|
|
98
|
+
blocksByPath.forEach((row)=>{
|
|
99
|
+
if (row._uuid) {
|
|
100
|
+
row.id = row._uuid;
|
|
101
|
+
delete row._uuid;
|
|
102
|
+
}
|
|
103
|
+
if (typeof row._locale === 'string') {
|
|
104
|
+
if (!result[field.name][row._locale]) {
|
|
105
|
+
result[field.name][row._locale] = [];
|
|
106
|
+
}
|
|
107
|
+
result[field.name][row._locale].push(row);
|
|
108
|
+
delete row._locale;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
Object.entries(result[field.name]).forEach(([locale, localizedBlocks])=>{
|
|
112
|
+
result[field.name][locale] = localizedBlocks.map((row)=>{
|
|
113
|
+
const block = field.blocks.find(({ slug })=>slug === row.blockType);
|
|
114
|
+
if (block) {
|
|
115
|
+
const blockResult = traverseFields({
|
|
76
116
|
adapter,
|
|
77
117
|
blocks,
|
|
78
118
|
config,
|
|
79
|
-
dataRef:
|
|
119
|
+
dataRef: row,
|
|
80
120
|
deletions,
|
|
81
121
|
fieldPrefix: '',
|
|
82
|
-
fields:
|
|
122
|
+
fields: block.flattenedFields,
|
|
83
123
|
numbers,
|
|
84
|
-
path: `${
|
|
124
|
+
path: `${blockFieldPath}.${row._order - 1}`,
|
|
85
125
|
relationships,
|
|
86
126
|
table: row,
|
|
87
127
|
texts,
|
|
88
128
|
withinArrayOrBlockLocale: locale
|
|
89
129
|
});
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
arrayResult[locale].push(rowResult);
|
|
94
|
-
}
|
|
95
|
-
return arrayResult;
|
|
96
|
-
}, {});
|
|
97
|
-
} else {
|
|
98
|
-
result[field.name] = fieldData.reduce((acc, row, i)=>{
|
|
99
|
-
if (row._uuid) {
|
|
100
|
-
row.id = row._uuid;
|
|
101
|
-
delete row._uuid;
|
|
130
|
+
delete blockResult._order;
|
|
131
|
+
return blockResult;
|
|
102
132
|
}
|
|
103
|
-
|
|
104
|
-
|
|
133
|
+
return {};
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
} else {
|
|
137
|
+
// Add locale-specific index to have a proper blockFieldPath for current locale
|
|
138
|
+
// because blocks can be in the same array for different locales!
|
|
139
|
+
if (withinArrayOrBlockLocale && config.localization) {
|
|
140
|
+
for (const locale of config.localization.localeCodes){
|
|
141
|
+
let localeIndex = 0;
|
|
142
|
+
for(let i = 0; i < blocksByPath.length; i++){
|
|
143
|
+
const row = blocksByPath[i];
|
|
144
|
+
if (row._locale === locale) {
|
|
145
|
+
row._index = localeIndex;
|
|
146
|
+
localeIndex++;
|
|
147
|
+
}
|
|
105
148
|
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
result[field.name] = blocksByPath.reduce((acc, row, i)=>{
|
|
152
|
+
delete row._order;
|
|
153
|
+
if (row._uuid) {
|
|
154
|
+
row.id = row._uuid;
|
|
155
|
+
delete row._uuid;
|
|
156
|
+
}
|
|
157
|
+
const block = field.blocks.find(({ slug })=>slug === row.blockType);
|
|
158
|
+
if (block) {
|
|
106
159
|
if (!withinArrayOrBlockLocale || withinArrayOrBlockLocale && withinArrayOrBlockLocale === row._locale) {
|
|
107
160
|
if (row._locale) {
|
|
108
161
|
delete row._locale;
|
|
109
162
|
}
|
|
163
|
+
if (typeof row._index === 'number') {
|
|
164
|
+
i = row._index;
|
|
165
|
+
delete row._index;
|
|
166
|
+
}
|
|
110
167
|
acc.push(traverseFields({
|
|
111
168
|
adapter,
|
|
112
169
|
blocks,
|
|
@@ -114,410 +171,312 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
|
|
|
114
171
|
dataRef: row,
|
|
115
172
|
deletions,
|
|
116
173
|
fieldPrefix: '',
|
|
117
|
-
fields:
|
|
174
|
+
fields: block.flattenedFields,
|
|
118
175
|
numbers,
|
|
119
|
-
path: `${
|
|
176
|
+
path: `${blockFieldPath}.${i}`,
|
|
120
177
|
relationships,
|
|
121
178
|
table: row,
|
|
122
179
|
texts,
|
|
123
180
|
withinArrayOrBlockLocale
|
|
124
181
|
}));
|
|
182
|
+
return acc;
|
|
125
183
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return result;
|
|
131
|
-
}
|
|
132
|
-
if (field.type === 'blocks') {
|
|
133
|
-
const blockFieldPath = `${sanitizedPath}${field.name}`;
|
|
134
|
-
const blocksByPath = blocks[blockFieldPath];
|
|
135
|
-
if (Array.isArray(blocksByPath)) {
|
|
136
|
-
if (field.localized) {
|
|
137
|
-
result[field.name] = {};
|
|
138
|
-
blocksByPath.forEach((row)=>{
|
|
139
|
-
if (row._uuid) {
|
|
140
|
-
row.id = row._uuid;
|
|
141
|
-
delete row._uuid;
|
|
142
|
-
}
|
|
143
|
-
if (typeof row._locale === 'string') {
|
|
144
|
-
if (!result[field.name][row._locale]) {
|
|
145
|
-
result[field.name][row._locale] = [];
|
|
146
|
-
}
|
|
147
|
-
result[field.name][row._locale].push(row);
|
|
148
|
-
delete row._locale;
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
Object.entries(result[field.name]).forEach(([locale, localizedBlocks])=>{
|
|
152
|
-
result[field.name][locale] = localizedBlocks.map((row)=>{
|
|
153
|
-
const block = field.blocks.find(({ slug })=>slug === row.blockType);
|
|
154
|
-
if (block) {
|
|
155
|
-
const blockResult = traverseFields({
|
|
156
|
-
adapter,
|
|
157
|
-
blocks,
|
|
158
|
-
config,
|
|
159
|
-
dataRef: row,
|
|
160
|
-
deletions,
|
|
161
|
-
fieldPrefix: '',
|
|
162
|
-
fields: block.fields,
|
|
163
|
-
numbers,
|
|
164
|
-
path: `${blockFieldPath}.${row._order - 1}`,
|
|
165
|
-
relationships,
|
|
166
|
-
table: row,
|
|
167
|
-
texts,
|
|
168
|
-
withinArrayOrBlockLocale: locale
|
|
169
|
-
});
|
|
170
|
-
delete blockResult._order;
|
|
171
|
-
return blockResult;
|
|
172
|
-
}
|
|
173
|
-
return {};
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
} else {
|
|
177
|
-
// Add locale-specific index to have a proper blockFieldPath for current locale
|
|
178
|
-
// because blocks can be in the same array for different locales!
|
|
179
|
-
if (withinArrayOrBlockLocale && config.localization) {
|
|
180
|
-
for (const locale of config.localization.localeCodes){
|
|
181
|
-
let localeIndex = 0;
|
|
182
|
-
for(let i = 0; i < blocksByPath.length; i++){
|
|
183
|
-
const row = blocksByPath[i];
|
|
184
|
-
if (row._locale === locale) {
|
|
185
|
-
row._index = localeIndex;
|
|
186
|
-
localeIndex++;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
184
|
+
} else {
|
|
185
|
+
acc.push({});
|
|
190
186
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
if (row._uuid) {
|
|
194
|
-
row.id = row._uuid;
|
|
195
|
-
delete row._uuid;
|
|
196
|
-
}
|
|
197
|
-
const block = field.blocks.find(({ slug })=>slug === row.blockType);
|
|
198
|
-
if (block) {
|
|
199
|
-
if (!withinArrayOrBlockLocale || withinArrayOrBlockLocale && withinArrayOrBlockLocale === row._locale) {
|
|
200
|
-
if (row._locale) {
|
|
201
|
-
delete row._locale;
|
|
202
|
-
}
|
|
203
|
-
if (typeof row._index === 'number') {
|
|
204
|
-
i = row._index;
|
|
205
|
-
delete row._index;
|
|
206
|
-
}
|
|
207
|
-
acc.push(traverseFields({
|
|
208
|
-
adapter,
|
|
209
|
-
blocks,
|
|
210
|
-
config,
|
|
211
|
-
dataRef: row,
|
|
212
|
-
deletions,
|
|
213
|
-
fieldPrefix: '',
|
|
214
|
-
fields: block.fields,
|
|
215
|
-
numbers,
|
|
216
|
-
path: `${blockFieldPath}.${i}`,
|
|
217
|
-
relationships,
|
|
218
|
-
table: row,
|
|
219
|
-
texts,
|
|
220
|
-
withinArrayOrBlockLocale
|
|
221
|
-
}));
|
|
222
|
-
return acc;
|
|
223
|
-
}
|
|
224
|
-
} else {
|
|
225
|
-
acc.push({});
|
|
226
|
-
}
|
|
227
|
-
return acc;
|
|
228
|
-
}, []);
|
|
229
|
-
}
|
|
187
|
+
return acc;
|
|
188
|
+
}, []);
|
|
230
189
|
}
|
|
231
|
-
return result;
|
|
232
190
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
191
|
+
return result;
|
|
192
|
+
}
|
|
193
|
+
if (field.type === 'relationship' || field.type === 'upload') {
|
|
194
|
+
if (typeof field.relationTo === 'string' && !('hasMany' in field && field.hasMany)) {
|
|
195
|
+
if (field.localized && config.localization && config.localization.locales && Array.isArray(table?._locales)) {
|
|
196
|
+
table._locales.forEach((localeRow)=>{
|
|
197
|
+
result[field.name] = {
|
|
198
|
+
[localeRow._locale]: localeRow[fieldName]
|
|
199
|
+
};
|
|
200
|
+
});
|
|
201
|
+
} else {
|
|
202
|
+
valuesToTransform.push({
|
|
203
|
+
ref: result,
|
|
204
|
+
table
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
} else {
|
|
208
|
+
const relationPathMatch = relationships[`${sanitizedPath}${field.name}`];
|
|
209
|
+
if (!relationPathMatch) {
|
|
210
|
+
if ('hasMany' in field && field.hasMany) {
|
|
211
|
+
if (field.localized && config.localization && config.localization.locales) {
|
|
237
212
|
result[field.name] = {
|
|
238
|
-
[
|
|
213
|
+
[config.localization.defaultLocale]: []
|
|
239
214
|
};
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
valuesToTransform.push({
|
|
243
|
-
ref: result,
|
|
244
|
-
table
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
} else {
|
|
248
|
-
const relationPathMatch = relationships[`${sanitizedPath}${field.name}`];
|
|
249
|
-
if (!relationPathMatch) {
|
|
250
|
-
if ('hasMany' in field && field.hasMany) {
|
|
251
|
-
if (field.localized && config.localization && config.localization.locales) {
|
|
252
|
-
result[field.name] = {
|
|
253
|
-
[config.localization.defaultLocale]: []
|
|
254
|
-
};
|
|
255
|
-
} else {
|
|
256
|
-
result[field.name] = [];
|
|
257
|
-
}
|
|
215
|
+
} else {
|
|
216
|
+
result[field.name] = [];
|
|
258
217
|
}
|
|
259
|
-
return result;
|
|
260
218
|
}
|
|
261
|
-
if (field.localized) {
|
|
262
|
-
result[field.name] = {};
|
|
263
|
-
const relationsByLocale = {};
|
|
264
|
-
relationPathMatch.forEach((row)=>{
|
|
265
|
-
if (typeof row.locale === 'string') {
|
|
266
|
-
if (!relationsByLocale[row.locale]) {
|
|
267
|
-
relationsByLocale[row.locale] = [];
|
|
268
|
-
}
|
|
269
|
-
relationsByLocale[row.locale].push(row);
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
Object.entries(relationsByLocale).forEach(([locale, relations])=>{
|
|
273
|
-
transformRelationship({
|
|
274
|
-
field,
|
|
275
|
-
locale,
|
|
276
|
-
ref: result,
|
|
277
|
-
relations
|
|
278
|
-
});
|
|
279
|
-
});
|
|
280
|
-
} else {
|
|
281
|
-
transformRelationship({
|
|
282
|
-
field,
|
|
283
|
-
ref: result,
|
|
284
|
-
relations: relationPathMatch,
|
|
285
|
-
withinArrayOrBlockLocale
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
return result;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
if (field.type === 'join') {
|
|
292
|
-
const { limit = field.defaultLimit ?? 10 } = joinQuery?.[`${fieldPrefix.replaceAll('_', '.')}${field.name}`] || {};
|
|
293
|
-
// raw hasMany results from SQLite
|
|
294
|
-
if (typeof fieldData === 'string') {
|
|
295
|
-
fieldData = JSON.parse(fieldData);
|
|
296
|
-
}
|
|
297
|
-
let fieldResult;
|
|
298
|
-
if (Array.isArray(fieldData)) {
|
|
299
|
-
if (field.localized) {
|
|
300
|
-
fieldResult = fieldData.reduce((joinResult, row)=>{
|
|
301
|
-
if (typeof row._locale === 'string') {
|
|
302
|
-
if (!joinResult[row._locale]) {
|
|
303
|
-
joinResult[row._locale] = {
|
|
304
|
-
docs: [],
|
|
305
|
-
hasNextPage: false
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
joinResult[row._locale].docs.push(row._parentID);
|
|
309
|
-
}
|
|
310
|
-
return joinResult;
|
|
311
|
-
}, {});
|
|
312
|
-
Object.keys(fieldResult).forEach((locale)=>{
|
|
313
|
-
fieldResult[locale].hasNextPage = fieldResult[locale].docs.length > limit;
|
|
314
|
-
fieldResult[locale].docs = fieldResult[locale].docs.slice(0, limit);
|
|
315
|
-
});
|
|
316
|
-
} else {
|
|
317
|
-
const hasNextPage = limit !== 0 && fieldData.length > limit;
|
|
318
|
-
fieldResult = {
|
|
319
|
-
docs: (hasNextPage ? fieldData.slice(0, limit) : fieldData).map(({ id })=>({
|
|
320
|
-
id
|
|
321
|
-
})),
|
|
322
|
-
hasNextPage
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
result[field.name] = fieldResult;
|
|
327
|
-
return result;
|
|
328
|
-
}
|
|
329
|
-
if (field.type === 'text' && field?.hasMany) {
|
|
330
|
-
const textPathMatch = texts[`${sanitizedPath}${field.name}`];
|
|
331
|
-
if (!textPathMatch) {
|
|
332
219
|
return result;
|
|
333
220
|
}
|
|
334
221
|
if (field.localized) {
|
|
335
222
|
result[field.name] = {};
|
|
336
|
-
const
|
|
337
|
-
|
|
223
|
+
const relationsByLocale = {};
|
|
224
|
+
relationPathMatch.forEach((row)=>{
|
|
338
225
|
if (typeof row.locale === 'string') {
|
|
339
|
-
if (!
|
|
340
|
-
|
|
226
|
+
if (!relationsByLocale[row.locale]) {
|
|
227
|
+
relationsByLocale[row.locale] = [];
|
|
341
228
|
}
|
|
342
|
-
|
|
229
|
+
relationsByLocale[row.locale].push(row);
|
|
343
230
|
}
|
|
344
231
|
});
|
|
345
|
-
Object.entries(
|
|
346
|
-
|
|
232
|
+
Object.entries(relationsByLocale).forEach(([locale, relations])=>{
|
|
233
|
+
transformRelationship({
|
|
347
234
|
field,
|
|
348
235
|
locale,
|
|
349
236
|
ref: result,
|
|
350
|
-
|
|
237
|
+
relations
|
|
351
238
|
});
|
|
352
239
|
});
|
|
353
240
|
} else {
|
|
354
|
-
|
|
241
|
+
transformRelationship({
|
|
355
242
|
field,
|
|
356
243
|
ref: result,
|
|
357
|
-
|
|
244
|
+
relations: relationPathMatch,
|
|
358
245
|
withinArrayOrBlockLocale
|
|
359
246
|
});
|
|
360
247
|
}
|
|
361
248
|
return result;
|
|
362
249
|
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
250
|
+
}
|
|
251
|
+
if (field.type === 'join') {
|
|
252
|
+
const { limit = field.defaultLimit ?? 10 } = joinQuery?.[`${fieldPrefix.replaceAll('_', '.')}${field.name}`] || {};
|
|
253
|
+
// raw hasMany results from SQLite
|
|
254
|
+
if (typeof fieldData === 'string') {
|
|
255
|
+
fieldData = JSON.parse(fieldData);
|
|
256
|
+
}
|
|
257
|
+
let fieldResult;
|
|
258
|
+
if (Array.isArray(fieldData)) {
|
|
368
259
|
if (field.localized) {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
260
|
+
fieldResult = fieldData.reduce((joinResult, row)=>{
|
|
261
|
+
if (typeof row._locale === 'string') {
|
|
262
|
+
if (!joinResult[row._locale]) {
|
|
263
|
+
joinResult[row._locale] = {
|
|
264
|
+
docs: [],
|
|
265
|
+
hasNextPage: false
|
|
266
|
+
};
|
|
375
267
|
}
|
|
376
|
-
|
|
268
|
+
joinResult[row._locale].docs.push(row._parentID);
|
|
377
269
|
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
numberRows: numbers,
|
|
384
|
-
ref: result
|
|
385
|
-
});
|
|
270
|
+
return joinResult;
|
|
271
|
+
}, {});
|
|
272
|
+
Object.keys(fieldResult).forEach((locale)=>{
|
|
273
|
+
fieldResult[locale].hasNextPage = fieldResult[locale].docs.length > limit;
|
|
274
|
+
fieldResult[locale].docs = fieldResult[locale].docs.slice(0, limit);
|
|
386
275
|
});
|
|
387
276
|
} else {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
277
|
+
const hasNextPage = limit !== 0 && fieldData.length > limit;
|
|
278
|
+
fieldResult = {
|
|
279
|
+
docs: (hasNextPage ? fieldData.slice(0, limit) : fieldData).map(({ id })=>({
|
|
280
|
+
id
|
|
281
|
+
})),
|
|
282
|
+
hasNextPage
|
|
283
|
+
};
|
|
394
284
|
}
|
|
285
|
+
}
|
|
286
|
+
result[field.name] = fieldResult;
|
|
287
|
+
return result;
|
|
288
|
+
}
|
|
289
|
+
if (field.type === 'text' && field?.hasMany) {
|
|
290
|
+
const textPathMatch = texts[`${sanitizedPath}${field.name}`];
|
|
291
|
+
if (!textPathMatch) {
|
|
395
292
|
return result;
|
|
396
293
|
}
|
|
397
|
-
if (field.
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
}
|
|
405
|
-
selectResult[row.locale].push(row.value);
|
|
406
|
-
}
|
|
407
|
-
return selectResult;
|
|
408
|
-
}, {});
|
|
409
|
-
} else {
|
|
410
|
-
let selectData = fieldData;
|
|
411
|
-
if (withinArrayOrBlockLocale) {
|
|
412
|
-
selectData = selectData.filter(({ locale })=>locale === withinArrayOrBlockLocale);
|
|
294
|
+
if (field.localized) {
|
|
295
|
+
result[field.name] = {};
|
|
296
|
+
const textsByLocale = {};
|
|
297
|
+
textPathMatch.forEach((row)=>{
|
|
298
|
+
if (typeof row.locale === 'string') {
|
|
299
|
+
if (!textsByLocale[row.locale]) {
|
|
300
|
+
textsByLocale[row.locale] = [];
|
|
413
301
|
}
|
|
414
|
-
|
|
302
|
+
textsByLocale[row.locale].push(row);
|
|
415
303
|
}
|
|
416
|
-
}
|
|
304
|
+
});
|
|
305
|
+
Object.entries(textsByLocale).forEach(([locale, texts])=>{
|
|
306
|
+
transformHasManyText({
|
|
307
|
+
field,
|
|
308
|
+
locale,
|
|
309
|
+
ref: result,
|
|
310
|
+
textRows: texts
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
} else {
|
|
314
|
+
transformHasManyText({
|
|
315
|
+
field,
|
|
316
|
+
ref: result,
|
|
317
|
+
textRows: textPathMatch,
|
|
318
|
+
withinArrayOrBlockLocale
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
return result;
|
|
322
|
+
}
|
|
323
|
+
if (field.type === 'number' && field.hasMany) {
|
|
324
|
+
const numberPathMatch = numbers[`${sanitizedPath}${field.name}`];
|
|
325
|
+
if (!numberPathMatch) {
|
|
417
326
|
return result;
|
|
418
327
|
}
|
|
419
|
-
if (field.localized
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
valuesToTransform.push({
|
|
427
|
-
ref: localizedFieldData,
|
|
428
|
-
table: {
|
|
429
|
-
...table,
|
|
430
|
-
...localeRow
|
|
328
|
+
if (field.localized) {
|
|
329
|
+
result[field.name] = {};
|
|
330
|
+
const numbersByLocale = {};
|
|
331
|
+
numberPathMatch.forEach((row)=>{
|
|
332
|
+
if (typeof row.locale === 'string') {
|
|
333
|
+
if (!numbersByLocale[row.locale]) {
|
|
334
|
+
numbersByLocale[row.locale] = [];
|
|
431
335
|
}
|
|
336
|
+
numbersByLocale[row.locale].push(row);
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
Object.entries(numbersByLocale).forEach(([locale, numbers])=>{
|
|
340
|
+
transformHasManyNumber({
|
|
341
|
+
field,
|
|
342
|
+
locale,
|
|
343
|
+
numberRows: numbers,
|
|
344
|
+
ref: result
|
|
432
345
|
});
|
|
433
346
|
});
|
|
434
347
|
} else {
|
|
435
|
-
|
|
348
|
+
transformHasManyNumber({
|
|
349
|
+
field,
|
|
350
|
+
numberRows: numberPathMatch,
|
|
436
351
|
ref: result,
|
|
437
|
-
|
|
352
|
+
withinArrayOrBlockLocale
|
|
438
353
|
});
|
|
439
354
|
}
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
{
|
|
447
|
-
if (
|
|
448
|
-
|
|
355
|
+
return result;
|
|
356
|
+
}
|
|
357
|
+
if (field.type === 'select' && field.hasMany) {
|
|
358
|
+
if (Array.isArray(fieldData)) {
|
|
359
|
+
if (field.localized) {
|
|
360
|
+
result[field.name] = fieldData.reduce((selectResult, row)=>{
|
|
361
|
+
if (typeof row.locale === 'string') {
|
|
362
|
+
if (!selectResult[row.locale]) {
|
|
363
|
+
selectResult[row.locale] = [];
|
|
449
364
|
}
|
|
450
|
-
|
|
365
|
+
selectResult[row.locale].push(row.value);
|
|
451
366
|
}
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
367
|
+
return selectResult;
|
|
368
|
+
}, {});
|
|
369
|
+
} else {
|
|
370
|
+
let selectData = fieldData;
|
|
371
|
+
if (withinArrayOrBlockLocale) {
|
|
372
|
+
selectData = selectData.filter(({ locale })=>locale === withinArrayOrBlockLocale);
|
|
373
|
+
}
|
|
374
|
+
result[field.name] = selectData.map(({ value })=>value);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
return result;
|
|
378
|
+
}
|
|
379
|
+
if (field.localized && Array.isArray(table._locales)) {
|
|
380
|
+
if (!table._locales.length && adapter.payload.config.localization) {
|
|
381
|
+
adapter.payload.config.localization.localeCodes.forEach((_locale)=>table._locales.push({
|
|
382
|
+
_locale
|
|
383
|
+
}));
|
|
384
|
+
}
|
|
385
|
+
table._locales.forEach((localeRow)=>{
|
|
386
|
+
valuesToTransform.push({
|
|
387
|
+
ref: localizedFieldData,
|
|
388
|
+
table: {
|
|
389
|
+
...table,
|
|
390
|
+
...localeRow
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
} else {
|
|
395
|
+
valuesToTransform.push({
|
|
396
|
+
ref: result,
|
|
397
|
+
table
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
valuesToTransform.forEach(({ ref, table })=>{
|
|
401
|
+
const fieldData = table[`${fieldPrefix || ''}${field.name}`];
|
|
402
|
+
const locale = table?._locale;
|
|
403
|
+
let val = fieldData;
|
|
404
|
+
switch(field.type){
|
|
405
|
+
case 'date':
|
|
406
|
+
{
|
|
407
|
+
if (typeof fieldData === 'string') {
|
|
408
|
+
val = new Date(fieldData).toISOString();
|
|
481
409
|
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
410
|
+
break;
|
|
411
|
+
}
|
|
412
|
+
case 'group':
|
|
413
|
+
case 'tab':
|
|
414
|
+
{
|
|
415
|
+
const groupFieldPrefix = `${fieldPrefix || ''}${field.name}_`;
|
|
416
|
+
const groupData = {};
|
|
417
|
+
const locale = table._locale;
|
|
418
|
+
const refKey = field.localized && locale ? locale : field.name;
|
|
419
|
+
if (field.localized && locale) {
|
|
420
|
+
delete table._locale;
|
|
488
421
|
}
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
422
|
+
ref[refKey] = traverseFields({
|
|
423
|
+
adapter,
|
|
424
|
+
blocks,
|
|
425
|
+
config,
|
|
426
|
+
dataRef: groupData,
|
|
427
|
+
deletions,
|
|
428
|
+
fieldPrefix: groupFieldPrefix,
|
|
429
|
+
fields: field.flattenedFields,
|
|
430
|
+
numbers,
|
|
431
|
+
path: `${sanitizedPath}${field.name}`,
|
|
432
|
+
relationships,
|
|
433
|
+
table,
|
|
434
|
+
texts,
|
|
435
|
+
withinArrayOrBlockLocale: locale || withinArrayOrBlockLocale
|
|
436
|
+
});
|
|
437
|
+
if ('_order' in ref) {
|
|
438
|
+
delete ref._order;
|
|
496
439
|
}
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
case 'number':
|
|
443
|
+
{
|
|
444
|
+
if (typeof fieldData === 'string') {
|
|
445
|
+
val = Number.parseFloat(fieldData);
|
|
503
446
|
}
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
447
|
+
break;
|
|
448
|
+
}
|
|
449
|
+
case 'relationship':
|
|
450
|
+
case 'upload':
|
|
451
|
+
{
|
|
452
|
+
if (val && typeof field.relationTo === 'string' && adapter.payload.collections[field.relationTo].customIDType === 'number') {
|
|
453
|
+
val = Number(val);
|
|
507
454
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
455
|
+
break;
|
|
456
|
+
}
|
|
457
|
+
case 'text':
|
|
458
|
+
{
|
|
459
|
+
if (typeof fieldData === 'string') {
|
|
460
|
+
val = String(fieldData);
|
|
461
|
+
}
|
|
462
|
+
break;
|
|
463
|
+
}
|
|
464
|
+
default:
|
|
465
|
+
{
|
|
466
|
+
break;
|
|
467
|
+
}
|
|
517
468
|
}
|
|
518
|
-
|
|
469
|
+
if (typeof locale === 'string') {
|
|
470
|
+
ref[locale] = val;
|
|
471
|
+
} else {
|
|
472
|
+
result[field.name] = val;
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
if (Object.keys(localizedFieldData).length > 0) {
|
|
476
|
+
result[field.name] = localizedFieldData;
|
|
519
477
|
}
|
|
520
478
|
return result;
|
|
479
|
+
return result;
|
|
521
480
|
}, dataRef);
|
|
522
481
|
if (Array.isArray(table._locales)) {
|
|
523
482
|
deletions.push(()=>delete table._locales);
|