@payloadcms/db-mongodb 3.0.0-canary.c13f9ba → 3.0.0-canary.c696728

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. package/README.md +1 -1
  2. package/dist/connect.d.ts +1 -1
  3. package/dist/connect.d.ts.map +1 -1
  4. package/dist/connect.js +13 -4
  5. package/dist/connect.js.map +1 -1
  6. package/dist/count.d.ts +1 -1
  7. package/dist/count.d.ts.map +1 -1
  8. package/dist/count.js +2 -2
  9. package/dist/count.js.map +1 -1
  10. package/dist/create.d.ts +1 -1
  11. package/dist/create.d.ts.map +1 -1
  12. package/dist/create.js +14 -4
  13. package/dist/create.js.map +1 -1
  14. package/dist/createGlobal.d.ts +1 -1
  15. package/dist/createGlobal.d.ts.map +1 -1
  16. package/dist/createGlobal.js +11 -6
  17. package/dist/createGlobal.js.map +1 -1
  18. package/dist/createGlobalVersion.d.ts +1 -1
  19. package/dist/createGlobalVersion.d.ts.map +1 -1
  20. package/dist/createGlobalVersion.js +14 -5
  21. package/dist/createGlobalVersion.js.map +1 -1
  22. package/dist/createMigration.d.ts +1 -1
  23. package/dist/createMigration.d.ts.map +1 -1
  24. package/dist/createMigration.js +2 -2
  25. package/dist/createMigration.js.map +1 -1
  26. package/dist/createVersion.d.ts +1 -1
  27. package/dist/createVersion.d.ts.map +1 -1
  28. package/dist/createVersion.js +15 -6
  29. package/dist/createVersion.js.map +1 -1
  30. package/dist/deleteMany.d.ts +1 -1
  31. package/dist/deleteMany.d.ts.map +1 -1
  32. package/dist/deleteMany.js +1 -1
  33. package/dist/deleteMany.js.map +1 -1
  34. package/dist/deleteOne.d.ts +1 -1
  35. package/dist/deleteOne.d.ts.map +1 -1
  36. package/dist/deleteOne.js +2 -2
  37. package/dist/deleteOne.js.map +1 -1
  38. package/dist/deleteVersions.d.ts +1 -1
  39. package/dist/deleteVersions.d.ts.map +1 -1
  40. package/dist/deleteVersions.js +1 -1
  41. package/dist/deleteVersions.js.map +1 -1
  42. package/dist/destroy.d.ts +1 -1
  43. package/dist/destroy.d.ts.map +1 -1
  44. package/dist/destroy.js.map +1 -1
  45. package/dist/find.d.ts +1 -1
  46. package/dist/find.d.ts.map +1 -1
  47. package/dist/find.js +29 -6
  48. package/dist/find.js.map +1 -1
  49. package/dist/findGlobal.d.ts +1 -1
  50. package/dist/findGlobal.d.ts.map +1 -1
  51. package/dist/findGlobal.js +3 -3
  52. package/dist/findGlobal.js.map +1 -1
  53. package/dist/findGlobalVersions.d.ts +1 -1
  54. package/dist/findGlobalVersions.d.ts.map +1 -1
  55. package/dist/findGlobalVersions.js +12 -7
  56. package/dist/findGlobalVersions.js.map +1 -1
  57. package/dist/findOne.d.ts +1 -1
  58. package/dist/findOne.d.ts.map +1 -1
  59. package/dist/findOne.js +20 -4
  60. package/dist/findOne.js.map +1 -1
  61. package/dist/findVersions.d.ts +1 -1
  62. package/dist/findVersions.d.ts.map +1 -1
  63. package/dist/findVersions.js +10 -4
  64. package/dist/findVersions.js.map +1 -1
  65. package/dist/index.d.ts +49 -35
  66. package/dist/index.d.ts.map +1 -1
  67. package/dist/index.js +8 -4
  68. package/dist/index.js.map +1 -1
  69. package/dist/init.d.ts +1 -1
  70. package/dist/init.d.ts.map +1 -1
  71. package/dist/init.js +11 -8
  72. package/dist/init.js.map +1 -1
  73. package/dist/migrateFresh.d.ts.map +1 -1
  74. package/dist/migrateFresh.js +1 -1
  75. package/dist/migrateFresh.js.map +1 -1
  76. package/dist/models/buildCollectionSchema.d.ts +2 -29
  77. package/dist/models/buildCollectionSchema.d.ts.map +1 -1
  78. package/dist/models/buildCollectionSchema.js +16 -4
  79. package/dist/models/buildCollectionSchema.js.map +1 -1
  80. package/dist/models/buildGlobalModel.d.ts +1 -1
  81. package/dist/models/buildGlobalModel.d.ts.map +1 -1
  82. package/dist/models/buildGlobalModel.js +2 -2
  83. package/dist/models/buildGlobalModel.js.map +1 -1
  84. package/dist/models/buildSchema.d.ts +2 -29
  85. package/dist/models/buildSchema.d.ts.map +1 -1
  86. package/dist/models/buildSchema.js +100 -22
  87. package/dist/models/buildSchema.js.map +1 -1
  88. package/dist/predefinedMigrations/versions-v1-v2.js.map +1 -1
  89. package/dist/queries/buildAndOrConditions.d.ts +1 -2
  90. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  91. package/dist/queries/buildAndOrConditions.js +0 -2
  92. package/dist/queries/buildAndOrConditions.js.map +1 -1
  93. package/dist/queries/buildQuery.d.ts +3 -4
  94. package/dist/queries/buildQuery.d.ts.map +1 -1
  95. package/dist/queries/buildQuery.js +2 -3
  96. package/dist/queries/buildQuery.js.map +1 -1
  97. package/dist/queries/buildSearchParams.d.ts +1 -2
  98. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  99. package/dist/queries/buildSearchParams.js +21 -13
  100. package/dist/queries/buildSearchParams.js.map +1 -1
  101. package/dist/queries/buildSortParam.d.ts +2 -28
  102. package/dist/queries/buildSortParam.d.ts.map +1 -1
  103. package/dist/queries/buildSortParam.js.map +1 -1
  104. package/dist/queries/getLocalizedSortProperty.d.ts +1 -2
  105. package/dist/queries/getLocalizedSortProperty.d.ts.map +1 -1
  106. package/dist/queries/getLocalizedSortProperty.js +2 -2
  107. package/dist/queries/getLocalizedSortProperty.js.map +1 -1
  108. package/dist/queries/getLocalizedSortProperty.spec.js +44 -44
  109. package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
  110. package/dist/queries/mock.js.map +1 -1
  111. package/dist/queries/operatorMap.js.map +1 -1
  112. package/dist/queries/parseParams.d.ts +1 -3
  113. package/dist/queries/parseParams.d.ts.map +1 -1
  114. package/dist/queries/parseParams.js +6 -7
  115. package/dist/queries/parseParams.js.map +1 -1
  116. package/dist/queries/sanitizeQueryValue.d.ts +1 -1
  117. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  118. package/dist/queries/sanitizeQueryValue.js +132 -25
  119. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  120. package/dist/queryDrafts.d.ts +1 -1
  121. package/dist/queryDrafts.d.ts.map +1 -1
  122. package/dist/queryDrafts.js +10 -4
  123. package/dist/queryDrafts.js.map +1 -1
  124. package/dist/testCredentials.js.map +1 -1
  125. package/dist/transactions/beginTransaction.d.ts +1 -1
  126. package/dist/transactions/beginTransaction.d.ts.map +1 -1
  127. package/dist/transactions/beginTransaction.js +3 -1
  128. package/dist/transactions/beginTransaction.js.map +1 -1
  129. package/dist/transactions/commitTransaction.d.ts +1 -1
  130. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  131. package/dist/transactions/commitTransaction.js +3 -0
  132. package/dist/transactions/commitTransaction.js.map +1 -1
  133. package/dist/transactions/rollbackTransaction.d.ts +1 -1
  134. package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
  135. package/dist/transactions/rollbackTransaction.js +13 -7
  136. package/dist/transactions/rollbackTransaction.js.map +1 -1
  137. package/dist/types.d.ts +5 -31
  138. package/dist/types.d.ts.map +1 -1
  139. package/dist/types.js.map +1 -1
  140. package/dist/updateGlobal.d.ts +1 -1
  141. package/dist/updateGlobal.d.ts.map +1 -1
  142. package/dist/updateGlobal.js +9 -3
  143. package/dist/updateGlobal.js.map +1 -1
  144. package/dist/updateGlobalVersion.d.ts +2 -3
  145. package/dist/updateGlobalVersion.d.ts.map +1 -1
  146. package/dist/updateGlobalVersion.js +11 -4
  147. package/dist/updateGlobalVersion.js.map +1 -1
  148. package/dist/updateOne.d.ts +1 -1
  149. package/dist/updateOne.d.ts.map +1 -1
  150. package/dist/updateOne.js +15 -5
  151. package/dist/updateOne.js.map +1 -1
  152. package/dist/updateVersion.d.ts +1 -1
  153. package/dist/updateVersion.d.ts.map +1 -1
  154. package/dist/updateVersion.js +9 -2
  155. package/dist/updateVersion.js.map +1 -1
  156. package/dist/utilities/buildJoinAggregation.d.ts +15 -0
  157. package/dist/utilities/buildJoinAggregation.d.ts.map +1 -0
  158. package/dist/utilities/buildJoinAggregation.js +148 -0
  159. package/dist/utilities/buildJoinAggregation.js.map +1 -0
  160. package/dist/utilities/getDBName.d.ts +1 -1
  161. package/dist/utilities/getDBName.d.ts.map +1 -1
  162. package/dist/utilities/getDBName.js +3 -1
  163. package/dist/utilities/getDBName.js.map +1 -1
  164. package/dist/utilities/handleError.d.ts +6 -2
  165. package/dist/utilities/handleError.d.ts.map +1 -1
  166. package/dist/utilities/handleError.js +12 -9
  167. package/dist/utilities/handleError.js.map +1 -1
  168. package/dist/utilities/sanitizeInternalFields.d.ts +1 -2
  169. package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -1
  170. package/dist/utilities/sanitizeInternalFields.js +1 -2
  171. package/dist/utilities/sanitizeInternalFields.js.map +1 -1
  172. package/dist/utilities/sanitizeRelationshipIDs.d.ts +9 -0
  173. package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -0
  174. package/dist/utilities/sanitizeRelationshipIDs.js +111 -0
  175. package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -0
  176. package/dist/withSession.d.ts +3 -27
  177. package/dist/withSession.d.ts.map +1 -1
  178. package/dist/withSession.js +10 -4
  179. package/dist/withSession.js.map +1 -1
  180. package/package.json +14 -13
@@ -1,24 +1,21 @@
1
- import { sanitizeConfig } from 'payload/config';
1
+ import { sanitizeConfig } from 'payload';
2
2
  import { getLocalizedSortProperty } from './getLocalizedSortProperty.js';
3
3
  let config;
4
4
  describe('get localized sort property', ()=>{
5
5
  beforeAll(async ()=>{
6
6
  config = await sanitizeConfig({
7
7
  localization: {
8
+ defaultLocale: 'en',
9
+ fallback: true,
8
10
  locales: [
9
11
  'en',
10
12
  'es'
11
- ],
12
- defaultLocale: 'en',
13
- fallback: true
13
+ ]
14
14
  }
15
15
  });
16
16
  });
17
- it('passes through a non-localized sort property', async ()=>{
17
+ it('passes through a non-localized sort property', ()=>{
18
18
  const result = getLocalizedSortProperty({
19
- segments: [
20
- 'title'
21
- ],
22
19
  config,
23
20
  fields: [
24
21
  {
@@ -26,15 +23,15 @@ describe('get localized sort property', ()=>{
26
23
  type: 'text'
27
24
  }
28
25
  ],
29
- locale: 'en'
26
+ locale: 'en',
27
+ segments: [
28
+ 'title'
29
+ ]
30
30
  });
31
31
  expect(result).toStrictEqual('title');
32
32
  });
33
33
  it('properly localizes an un-localized sort property', ()=>{
34
34
  const result = getLocalizedSortProperty({
35
- segments: [
36
- 'title'
37
- ],
38
35
  config,
39
36
  fields: [
40
37
  {
@@ -43,16 +40,15 @@ describe('get localized sort property', ()=>{
43
40
  localized: true
44
41
  }
45
42
  ],
46
- locale: 'en'
43
+ locale: 'en',
44
+ segments: [
45
+ 'title'
46
+ ]
47
47
  });
48
48
  expect(result).toStrictEqual('title.en');
49
49
  });
50
50
  it('keeps specifically asked-for localized sort properties', ()=>{
51
51
  const result = getLocalizedSortProperty({
52
- segments: [
53
- 'title',
54
- 'es'
55
- ],
56
52
  config,
57
53
  fields: [
58
54
  {
@@ -61,16 +57,16 @@ describe('get localized sort property', ()=>{
61
57
  localized: true
62
58
  }
63
59
  ],
64
- locale: 'en'
60
+ locale: 'en',
61
+ segments: [
62
+ 'title',
63
+ 'es'
64
+ ]
65
65
  });
66
66
  expect(result).toStrictEqual('title.es');
67
67
  });
68
68
  it('properly localizes nested sort properties', ()=>{
69
69
  const result = getLocalizedSortProperty({
70
- segments: [
71
- 'group',
72
- 'title'
73
- ],
74
70
  config,
75
71
  fields: [
76
72
  {
@@ -85,17 +81,16 @@ describe('get localized sort property', ()=>{
85
81
  ]
86
82
  }
87
83
  ],
88
- locale: 'en'
84
+ locale: 'en',
85
+ segments: [
86
+ 'group',
87
+ 'title'
88
+ ]
89
89
  });
90
90
  expect(result).toStrictEqual('group.title.en');
91
91
  });
92
92
  it('keeps requested locale with nested sort properties', ()=>{
93
93
  const result = getLocalizedSortProperty({
94
- segments: [
95
- 'group',
96
- 'title',
97
- 'es'
98
- ],
99
94
  config,
100
95
  fields: [
101
96
  {
@@ -110,15 +105,17 @@ describe('get localized sort property', ()=>{
110
105
  ]
111
106
  }
112
107
  ],
113
- locale: 'en'
108
+ locale: 'en',
109
+ segments: [
110
+ 'group',
111
+ 'title',
112
+ 'es'
113
+ ]
114
114
  });
115
115
  expect(result).toStrictEqual('group.title.es');
116
116
  });
117
117
  it('properly localizes field within row', ()=>{
118
118
  const result = getLocalizedSortProperty({
119
- segments: [
120
- 'title'
121
- ],
122
119
  config,
123
120
  fields: [
124
121
  {
@@ -132,16 +129,15 @@ describe('get localized sort property', ()=>{
132
129
  ]
133
130
  }
134
131
  ],
135
- locale: 'en'
132
+ locale: 'en',
133
+ segments: [
134
+ 'title'
135
+ ]
136
136
  });
137
137
  expect(result).toStrictEqual('title.en');
138
138
  });
139
139
  it('properly localizes field within named tab', ()=>{
140
140
  const result = getLocalizedSortProperty({
141
- segments: [
142
- 'tab',
143
- 'title'
144
- ],
145
141
  config,
146
142
  fields: [
147
143
  {
@@ -160,34 +156,38 @@ describe('get localized sort property', ()=>{
160
156
  ]
161
157
  }
162
158
  ],
163
- locale: 'en'
159
+ locale: 'en',
160
+ segments: [
161
+ 'tab',
162
+ 'title'
163
+ ]
164
164
  });
165
165
  expect(result).toStrictEqual('tab.title.en');
166
166
  });
167
167
  it('properly localizes field within unnamed tab', ()=>{
168
168
  const result = getLocalizedSortProperty({
169
- segments: [
170
- 'title'
171
- ],
172
169
  config,
173
170
  fields: [
174
171
  {
175
172
  type: 'tabs',
176
173
  tabs: [
177
174
  {
178
- label: 'Tab',
179
175
  fields: [
180
176
  {
181
177
  name: 'title',
182
178
  type: 'text',
183
179
  localized: true
184
180
  }
185
- ]
181
+ ],
182
+ label: 'Tab'
186
183
  }
187
184
  ]
188
185
  }
189
186
  ],
190
- locale: 'en'
187
+ locale: 'en',
188
+ segments: [
189
+ 'title'
190
+ ]
191
191
  });
192
192
  expect(result).toStrictEqual('title.en');
193
193
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/getLocalizedSortProperty.spec.ts"],"sourcesContent":["import { SanitizedConfig, sanitizeConfig } from 'payload/config'\nimport { Config } from 'payload/config'\nimport { getLocalizedSortProperty } from './getLocalizedSortProperty.js'\n\nlet config: SanitizedConfig\n\ndescribe('get localized sort property', () => {\n beforeAll(async () => {\n config = (await sanitizeConfig({\n localization: {\n locales: ['en', 'es'],\n defaultLocale: 'en',\n fallback: true,\n },\n } as Config)) as SanitizedConfig\n })\n it('passes through a non-localized sort property', async () => {\n const result = getLocalizedSortProperty({\n segments: ['title'],\n config,\n fields: [\n {\n name: 'title',\n type: 'text',\n },\n ],\n locale: 'en',\n })\n\n expect(result).toStrictEqual('title')\n })\n\n it('properly localizes an un-localized sort property', () => {\n const result = getLocalizedSortProperty({\n segments: ['title'],\n config,\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n locale: 'en',\n })\n\n expect(result).toStrictEqual('title.en')\n })\n\n it('keeps specifically asked-for localized sort properties', () => {\n const result = getLocalizedSortProperty({\n segments: ['title', 'es'],\n config,\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n locale: 'en',\n })\n\n expect(result).toStrictEqual('title.es')\n })\n\n it('properly localizes nested sort properties', () => {\n const result = getLocalizedSortProperty({\n segments: ['group', 'title'],\n config,\n fields: [\n {\n name: 'group',\n type: 'group',\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n },\n ],\n locale: 'en',\n })\n\n expect(result).toStrictEqual('group.title.en')\n })\n\n it('keeps requested locale with nested sort properties', () => {\n const result = getLocalizedSortProperty({\n segments: ['group', 'title', 'es'],\n config,\n fields: [\n {\n name: 'group',\n type: 'group',\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n },\n ],\n locale: 'en',\n })\n\n expect(result).toStrictEqual('group.title.es')\n })\n\n it('properly localizes field within row', () => {\n const result = getLocalizedSortProperty({\n segments: ['title'],\n config,\n fields: [\n {\n type: 'row',\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n },\n ],\n locale: 'en',\n })\n\n expect(result).toStrictEqual('title.en')\n })\n\n it('properly localizes field within named tab', () => {\n const result = getLocalizedSortProperty({\n segments: ['tab', 'title'],\n config,\n fields: [\n {\n type: 'tabs',\n tabs: [\n {\n name: 'tab',\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n },\n ],\n },\n ],\n locale: 'en',\n })\n\n expect(result).toStrictEqual('tab.title.en')\n })\n\n it('properly localizes field within unnamed tab', () => {\n const result = getLocalizedSortProperty({\n segments: ['title'],\n config,\n fields: [\n {\n type: 'tabs',\n tabs: [\n {\n label: 'Tab',\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n },\n ],\n },\n ],\n locale: 'en',\n })\n\n expect(result).toStrictEqual('title.en')\n })\n})\n"],"names":["sanitizeConfig","getLocalizedSortProperty","config","describe","beforeAll","localization","locales","defaultLocale","fallback","it","result","segments","fields","name","type","locale","expect","toStrictEqual","localized","tabs","label"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAA0BA,cAAc,QAAQ,iBAAgB;AAEhE,SAASC,wBAAwB,QAAQ,gCAA+B;AAExE,IAAIC;AAEJC,SAAS,+BAA+B;IACtCC,UAAU;QACRF,SAAU,MAAMF,eAAe;YAC7BK,cAAc;gBACZC,SAAS;oBAAC;oBAAM;iBAAK;gBACrBC,eAAe;gBACfC,UAAU;YACZ;QACF;IACF;IACAC,GAAG,gDAAgD;QACjD,MAAMC,SAAST,yBAAyB;YACtCU,UAAU;gBAAC;aAAQ;YACnBT;YACAU,QAAQ;gBACN;oBACEC,MAAM;oBACNC,MAAM;gBACR;aACD;YACDC,QAAQ;QACV;QAEAC,OAAON,QAAQO,aAAa,CAAC;IAC/B;IAEAR,GAAG,oDAAoD;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AEAR,GAAG,6CAA6C;QAC9C,MAAMC,SAAST,yBAAyB;YACtCU,UAAU;gBAAC;gBAAO;aAAQ;YAC1BT;YACAU,QAAQ;gBACN;oBACEE,MAAM;oBACNK,MAAM;wBACJ;4BACEN,MAAM;4BACND,QAAQ;gCACN;oCACEC,MAAM;oCACNC,MAAM;oCACNI,WAAW;gCACb;6BACD;wBACH;qBACD;gBACH;aACD;YACDH,QAAQ;QACV;QAEAC,OAAON,QAAQO,aAAa,CAAC;IAC/B;IAEAR,GAAG,+CAA+C;QAChD,MAAMC,SAAST,yBAAyB;YACtCU,UAAU;gBAAC;aAAQ;YACnBT;YACAU,QAAQ;gBACN;oBACEE,MAAM;oBACNK,MAAM;wBACJ;4BACEC,OAAO;4BACPR,QAAQ;gCACN;oCACEC,MAAM;oCACNC,MAAM;oCACNI,WAAW;gCACb;6BACD;wBACH;qBACD;gBACH;aACD;YACDH,QAAQ;QACV;QAEAC,OAAON,QAAQO,aAAa,CAAC;IAC/B;AACF"}
1
+ {"version":3,"sources":["../../src/queries/getLocalizedSortProperty.spec.ts"],"sourcesContent":["import type { Config, SanitizedConfig } from 'payload'\n\nimport { sanitizeConfig } from 'payload'\n\nimport { getLocalizedSortProperty } from './getLocalizedSortProperty.js'\n\nlet config: SanitizedConfig\n\ndescribe('get localized sort property', () => {\n beforeAll(async () => {\n config = await sanitizeConfig({\n localization: {\n defaultLocale: 'en',\n fallback: true,\n locales: ['en', 'es'],\n },\n } as Config)\n })\n it('passes through a non-localized sort property', () => {\n const result = getLocalizedSortProperty({\n config,\n fields: [\n {\n name: 'title',\n type: 'text',\n },\n ],\n locale: 'en',\n segments: ['title'],\n })\n\n expect(result).toStrictEqual('title')\n })\n\n it('properly localizes an un-localized sort property', () => {\n const result = getLocalizedSortProperty({\n config,\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n locale: 'en',\n segments: ['title'],\n })\n\n expect(result).toStrictEqual('title.en')\n })\n\n it('keeps specifically asked-for localized sort properties', () => {\n const result = getLocalizedSortProperty({\n config,\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n locale: 'en',\n segments: ['title', 'es'],\n })\n\n expect(result).toStrictEqual('title.es')\n })\n\n it('properly localizes nested sort properties', () => {\n const result = getLocalizedSortProperty({\n config,\n fields: [\n {\n name: 'group',\n type: 'group',\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n },\n ],\n locale: 'en',\n segments: ['group', 'title'],\n })\n\n expect(result).toStrictEqual('group.title.en')\n })\n\n it('keeps requested locale with nested sort properties', () => {\n const result = getLocalizedSortProperty({\n config,\n fields: [\n {\n name: 'group',\n type: 'group',\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n },\n ],\n locale: 'en',\n segments: ['group', 'title', 'es'],\n })\n\n expect(result).toStrictEqual('group.title.es')\n })\n\n it('properly localizes field within row', () => {\n const result = getLocalizedSortProperty({\n config,\n fields: [\n {\n type: 'row',\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n },\n ],\n locale: 'en',\n segments: ['title'],\n })\n\n expect(result).toStrictEqual('title.en')\n })\n\n it('properly localizes field within named tab', () => {\n const result = getLocalizedSortProperty({\n config,\n fields: [\n {\n type: 'tabs',\n tabs: [\n {\n name: 'tab',\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n },\n ],\n },\n ],\n locale: 'en',\n segments: ['tab', 'title'],\n })\n\n expect(result).toStrictEqual('tab.title.en')\n })\n\n it('properly localizes field within unnamed tab', () => {\n const result = getLocalizedSortProperty({\n config,\n fields: [\n {\n type: 'tabs',\n tabs: [\n {\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n label: 'Tab',\n },\n ],\n },\n ],\n locale: 'en',\n segments: ['title'],\n })\n\n expect(result).toStrictEqual('title.en')\n })\n})\n"],"names":["sanitizeConfig","getLocalizedSortProperty","config","describe","beforeAll","localization","defaultLocale","fallback","locales","it","result","fields","name","type","locale","segments","expect","toStrictEqual","localized","tabs","label"],"mappings":"AAEA,SAASA,cAAc,QAAQ,UAAS;AAExC,SAASC,wBAAwB,QAAQ,gCAA+B;AAExE,IAAIC;AAEJC,SAAS,+BAA+B;IACtCC,UAAU;QACRF,SAAS,MAAMF,eAAe;YAC5BK,cAAc;gBACZC,eAAe;gBACfC,UAAU;gBACVC,SAAS;oBAAC;oBAAM;iBAAK;YACvB;QACF;IACF;IACAC,GAAG,gDAAgD;QACjD,MAAMC,SAAST,yBAAyB;YACtCC;YACAS,QAAQ;gBACN;oBACEC,MAAM;oBACNC,MAAM;gBACR;aACD;YACDC,QAAQ;YACRC,UAAU;gBAAC;aAAQ;QACrB;QAEAC,OAAON,QAAQO,aAAa,CAAC;IAC/B;IAEAR,GAAG,oDAAoD;QACrD,MAAMC,SAAST,yBAAyB;YACtCC;YACAS,QAAQ;gBACN;oBACEC,MAAM;oBACNC,MAAM;oBACNK,WAAW;gBACb;aACD;YACDJ,QAAQ;YACRC,UAAU;gBAAC;aAAQ;QACrB;QAEAC,OAAON,QAAQO,aAAa,CAAC;IAC/B;IAEAR,GAAG,0DAA0D;QAC3D,MAAMC,SAAST,yBAAyB;YACtCC;YACAS,QAAQ;gBACN;oBACEC,MAAM;oBACNC,MAAM;oBACNK,WAAW;gBACb;aACD;YACDJ,QAAQ;YACRC,UAAU;gBAAC;gBAAS;aAAK;QAC3B;QAEAC,OAAON,QAAQO,aAAa,CAAC;IAC/B;IAEAR,GAAG,6CAA6C;QAC9C,MAAMC,SAAST,yBAAyB;YACtCC;YACAS,QAAQ;gBACN;oBACEC,MAAM;oBACNC,MAAM;oBACNF,QAAQ;wBACN;4BACEC,MAAM;4BACNC,MAAM;4BACNK,WAAW;wBACb;qBACD;gBACH;aACD;YACDJ,QAAQ;YACRC,UAAU;gBAAC;gBAAS;aAAQ;QAC9B;QAEAC,OAAON,QAAQO,aAAa,CAAC;IAC/B;IAEAR,GAAG,sDAAsD;QACvD,MAAMC,SAAST,yBAAyB;YACtCC;YACAS,QAAQ;gBACN;oBACEC,MAAM;oBACNC,MAAM;oBACNF,QAAQ;wBACN;4BACEC,MAAM;4BACNC,MAAM;4BACNK,WAAW;wBACb;qBACD;gBACH;aACD;YACDJ,QAAQ;YACRC,UAAU;gBAAC;gBAAS;gBAAS;aAAK;QACpC;QAEAC,OAAON,QAAQO,aAAa,CAAC;IAC/B;IAEAR,GAAG,uCAAuC;QACxC,MAAMC,SAAST,yBAAyB;YACtCC;YACAS,QAAQ;gBACN;oBACEE,MAAM;oBACNF,QAAQ;wBACN;4BACEC,MAAM;4BACNC,MAAM;4BACNK,WAAW;wBACb;qBACD;gBACH;aACD;YACDJ,QAAQ;YACRC,UAAU;gBAAC;aAAQ;QACrB;QAEAC,OAAON,QAAQO,aAAa,CAAC;IAC/B;IAEAR,GAAG,6CAA6C;QAC9C,MAAMC,SAAST,yBAAyB;YACtCC;YACAS,QAAQ;gBACN;oBACEE,MAAM;oBACNM,MAAM;wBACJ;4BACEP,MAAM;4BACND,QAAQ;gCACN;oCACEC,MAAM;oCACNC,MAAM;oCACNK,WAAW;gCACb;6BACD;wBACH;qBACD;gBACH;aACD;YACDJ,QAAQ;YACRC,UAAU;gBAAC;gBAAO;aAAQ;QAC5B;QAEAC,OAAON,QAAQO,aAAa,CAAC;IAC/B;IAEAR,GAAG,+CAA+C;QAChD,MAAMC,SAAST,yBAAyB;YACtCC;YACAS,QAAQ;gBACN;oBACEE,MAAM;oBACNM,MAAM;wBACJ;4BACER,QAAQ;gCACN;oCACEC,MAAM;oCACNC,MAAM;oCACNK,WAAW;gCACb;6BACD;4BACDE,OAAO;wBACT;qBACD;gBACH;aACD;YACDN,QAAQ;YACRC,UAAU;gBAAC;aAAQ;QACrB;QAEAC,OAAON,QAAQO,aAAa,CAAC;IAC/B;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/mock.js"],"names":[],"rangeMappings":"","mappings":""}
1
+ {"version":3,"sources":["../../src/queries/mock.js"],"names":[],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/operatorMap.ts"],"sourcesContent":["export const operatorMap = {\n all: '$all',\n equals: '$eq',\n exists: '$exists',\n greater_than: '$gt',\n greater_than_equal: '$gte',\n in: '$in',\n intersects: '$geoIntersects',\n less_than: '$lt',\n less_than_equal: '$lte',\n near: '$near',\n not_equals: '$ne',\n not_in: '$nin',\n within: '$geoWithin',\n}\n"],"names":["operatorMap","all","equals","exists","greater_than","greater_than_equal","in","intersects","less_than","less_than_equal","near","not_equals","not_in","within"],"rangeMappings":";;;;;;;;;;;;;;","mappings":"AAAA,OAAO,MAAMA,cAAc;IACzBC,KAAK;IACLC,QAAQ;IACRC,QAAQ;IACRC,cAAc;IACdC,oBAAoB;IACpBC,IAAI;IACJC,YAAY;IACZC,WAAW;IACXC,iBAAiB;IACjBC,MAAM;IACNC,YAAY;IACZC,QAAQ;IACRC,QAAQ;AACV,EAAC"}
1
+ {"version":3,"sources":["../../src/queries/operatorMap.ts"],"sourcesContent":["export const operatorMap = {\n all: '$all',\n equals: '$eq',\n exists: '$exists',\n greater_than: '$gt',\n greater_than_equal: '$gte',\n in: '$in',\n intersects: '$geoIntersects',\n less_than: '$lt',\n less_than_equal: '$lte',\n near: '$near',\n not_equals: '$ne',\n not_in: '$nin',\n within: '$geoWithin',\n}\n"],"names":["operatorMap","all","equals","exists","greater_than","greater_than_equal","in","intersects","less_than","less_than_equal","near","not_equals","not_in","within"],"mappings":"AAAA,OAAO,MAAMA,cAAc;IACzBC,KAAK;IACLC,QAAQ;IACRC,QAAQ;IACRC,cAAc;IACdC,oBAAoB;IACpBC,IAAI;IACJC,YAAY;IACZC,WAAW;IACXC,iBAAiB;IACjBC,MAAM;IACNC,YAAY;IACZC,QAAQ;IACRC,QAAQ;AACV,EAAC"}
@@ -1,6 +1,4 @@
1
- import type { Payload } from 'payload';
2
- import type { Where } from 'payload/types';
3
- import type { Field } from 'payload/types';
1
+ import type { Field, Payload, Where } from 'payload';
4
2
  export declare function parseParams({ collectionSlug, fields, globalSlug, locale, payload, where, }: {
5
3
  collectionSlug?: string;
6
4
  fields: Field[];
@@ -1 +1 @@
1
- {"version":3,"file":"parseParams.d.ts","sourceRoot":"","sources":["../../src/queries/parseParams.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,KAAK,EAAY,KAAK,EAAE,MAAM,eAAe,CAAA;AACpD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAS1C,wBAAsB,WAAW,CAAC,EAChC,cAAc,EACd,MAAM,EACN,UAAU,EACV,MAAM,EACN,OAAO,EACP,KAAK,GACN,EAAE;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,KAAK,CAAA;CACb,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CA0DnC"}
1
+ {"version":3,"file":"parseParams.d.ts","sourceRoot":"","sources":["../../src/queries/parseParams.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAY,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAQ9D,wBAAsB,WAAW,CAAC,EAChC,cAAc,EACd,MAAM,EACN,UAAU,EACV,MAAM,EACN,OAAO,EACP,KAAK,GACN,EAAE;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,KAAK,CAAA;CACb,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CA4DnC"}
@@ -1,6 +1,5 @@
1
- /* eslint-disable no-restricted-syntax */ /* eslint-disable no-await-in-loop */ import deepmerge from 'deepmerge';
2
- import { validOperators } from 'payload/types';
3
- import { combineMerge } from 'payload/utilities';
1
+ import { deepMergeWithCombinedArrays } from 'payload';
2
+ import { validOperators } from 'payload/shared';
4
3
  import { buildAndOrConditions } from './buildAndOrConditions.js';
5
4
  import { buildSearchParam } from './buildSearchParams.js';
6
5
  export async function parseParams({ collectionSlug, fields, globalSlug, locale, payload, where }) {
@@ -24,7 +23,9 @@ export async function parseParams({ collectionSlug, fields, globalSlug, locale,
24
23
  payload,
25
24
  where: condition
26
25
  });
27
- if (builtConditions.length > 0) result[conditionOperator] = builtConditions;
26
+ if (builtConditions.length > 0) {
27
+ result[conditionOperator] = builtConditions;
28
+ }
28
29
  } else {
29
30
  // It's a path - and there can be multiple comparisons on a single path.
30
31
  // For example - title like 'test' and title not equal to 'tester'
@@ -49,9 +50,7 @@ export async function parseParams({ collectionSlug, fields, globalSlug, locale,
49
50
  [searchParam.path]: searchParam.value
50
51
  };
51
52
  } else if (typeof searchParam?.value === 'object') {
52
- result = deepmerge(result, searchParam.value, {
53
- arrayMerge: combineMerge
54
- });
53
+ result = deepMergeWithCombinedArrays(result, searchParam.value);
55
54
  }
56
55
  }
57
56
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/parseParams.ts"],"sourcesContent":["/* eslint-disable no-restricted-syntax */\n/* eslint-disable no-await-in-loop */\nimport type { FilterQuery } from 'mongoose'\nimport type { Payload } from 'payload'\nimport type { Operator, Where } from 'payload/types'\nimport type { Field } from 'payload/types'\n\nimport deepmerge from 'deepmerge'\nimport { validOperators } from 'payload/types'\nimport { combineMerge } from 'payload/utilities'\n\nimport { buildAndOrConditions } from './buildAndOrConditions.js'\nimport { buildSearchParam } from './buildSearchParams.js'\n\nexport async function parseParams({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n where,\n}: {\n collectionSlug?: string\n fields: Field[]\n globalSlug?: string\n locale: string\n payload: Payload\n where: Where\n}): Promise<Record<string, unknown>> {\n let result = {} as FilterQuery<any>\n\n if (typeof where === 'object') {\n // We need to determine if the whereKey is an AND, OR, or a schema path\n for (const relationOrPath of Object.keys(where)) {\n const condition = where[relationOrPath]\n let conditionOperator: '$and' | '$or'\n if (relationOrPath.toLowerCase() === 'and') {\n conditionOperator = '$and'\n } else if (relationOrPath.toLowerCase() === 'or') {\n conditionOperator = '$or'\n }\n if (Array.isArray(condition)) {\n const builtConditions = await buildAndOrConditions({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n where: condition,\n })\n if (builtConditions.length > 0) result[conditionOperator] = builtConditions\n } else {\n // It's a path - and there can be multiple comparisons on a single path.\n // For example - title like 'test' and title not equal to 'tester'\n // So we need to loop on keys again here to handle each operator independently\n const pathOperators = where[relationOrPath]\n if (typeof pathOperators === 'object') {\n for (const operator of Object.keys(pathOperators)) {\n if (validOperators.includes(operator as Operator)) {\n const searchParam = await buildSearchParam({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath: relationOrPath,\n locale,\n operator,\n payload,\n val: pathOperators[operator],\n })\n\n if (searchParam?.value && searchParam?.path) {\n result = {\n ...result,\n [searchParam.path]: searchParam.value,\n }\n } else if (typeof searchParam?.value === 'object') {\n result = deepmerge(result, searchParam.value, { arrayMerge: combineMerge })\n }\n }\n }\n }\n }\n }\n }\n\n return result\n}\n"],"names":["deepmerge","validOperators","combineMerge","buildAndOrConditions","buildSearchParam","parseParams","collectionSlug","fields","globalSlug","locale","payload","where","result","relationOrPath","Object","keys","condition","conditionOperator","toLowerCase","Array","isArray","builtConditions","length","pathOperators","operator","includes","searchParam","incomingPath","val","value","path","arrayMerge"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,uCAAuC,GACvC,mCAAmC,GAMnC,OAAOA,eA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YAAYI,IAAI,CAAC,EAAEJ,YAAYG,KAAK;gCACvC;4BACF,OAAO,IAAI,OAAOH,aAAaG,UAAU,UAAU;gCACjDjB,SAASZ,UAAUY,QAAQc,YAAYG,KAAK,EAAE;oCAAEE,YAAY7B;gCAAa;4BAC3E;wBACF;oBACF;gBACF;YACF;QACF;IACF;IAEA,OAAOU;AACT"}
1
+ {"version":3,"sources":["../../src/queries/parseParams.ts"],"sourcesContent":["import type { FilterQuery } from 'mongoose'\nimport type { Field, Operator, Payload, Where } from 'payload'\n\nimport { deepMergeWithCombinedArrays } from 'payload'\nimport { validOperators } from 'payload/shared'\n\nimport { buildAndOrConditions } from './buildAndOrConditions.js'\nimport { buildSearchParam } from './buildSearchParams.js'\n\nexport async function parseParams({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n where,\n}: {\n collectionSlug?: string\n fields: Field[]\n globalSlug?: string\n locale: string\n payload: Payload\n where: Where\n}): Promise<Record<string, unknown>> {\n let result = {} as FilterQuery<any>\n\n if (typeof where === 'object') {\n // We need to determine if the whereKey is an AND, OR, or a schema path\n for (const relationOrPath of Object.keys(where)) {\n const condition = where[relationOrPath]\n let conditionOperator: '$and' | '$or'\n if (relationOrPath.toLowerCase() === 'and') {\n conditionOperator = '$and'\n } else if (relationOrPath.toLowerCase() === 'or') {\n conditionOperator = '$or'\n }\n if (Array.isArray(condition)) {\n const builtConditions = await buildAndOrConditions({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n where: condition,\n })\n if (builtConditions.length > 0) {\n result[conditionOperator] = builtConditions\n }\n } else {\n // It's a path - and there can be multiple comparisons on a single path.\n // For example - title like 'test' and title not equal to 'tester'\n // So we need to loop on keys again here to handle each operator independently\n const pathOperators = where[relationOrPath]\n if (typeof pathOperators === 'object') {\n for (const operator of Object.keys(pathOperators)) {\n if (validOperators.includes(operator as Operator)) {\n const searchParam = await buildSearchParam({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath: relationOrPath,\n locale,\n operator,\n payload,\n val: pathOperators[operator],\n })\n\n if (searchParam?.value && searchParam?.path) {\n result = {\n ...result,\n [searchParam.path]: searchParam.value,\n }\n } else if (typeof searchParam?.value === 'object') {\n result = deepMergeWithCombinedArrays(result, searchParam.value)\n }\n }\n }\n }\n }\n }\n }\n\n return result\n}\n"],"names":["deepMergeWithCombinedArrays","validOperators","buildAndOrConditions","buildSearchParam","parseParams","collectionSlug","fields","globalSlug","locale","payload","where","result","relationOrPath","Object","keys","condition","conditionOperator","toLowerCase","Array","isArray","builtConditions","length","pathOperators","operator","includes","searchParam","incomingPath","val","value","path"],"mappings":"AAGA,SAASA,2BAA2B,QAAQ,UAAS;AACrD,SAASC,cAAc,QAAQ,iBAAgB;AAE/C,SAASC,oBAAoB,QAAQ,4BAA2B;AAChE,SAASC,gBAAgB,QAAQ,yBAAwB;AAEzD,OAAO,eAAeC,YAAY,EAChCC,cAAc,EACdC,MAAM,EACNC,UAAU,EACVC,MAAM,EACNC,OAAO,EACPC,KAAK,EAQN;IACC,IAAIC,SAAS,CAAC;IAEd,IAAI,OAAOD,UAAU,UAAU;QAC7B,uEAAuE;QACvE,KAAK,MAAME,kBAAkBC,OAAOC,IAAI,CAACJ,OAAQ;YAC/C,MAAMK,YAAYL,KAAK,CAACE,eAAe;YACvC,IAAII;YACJ,IAAIJ,eAAeK,WAAW,OAAO,OAAO;gBAC1CD,oBAAoB;YACtB,OAAO,IAAIJ,eAAeK,WAAW,OAAO,MAAM;gBAChDD,oBAAoB;YACtB;YACA,IAAIE,MAAMC,OAAO,CAACJ,YAAY;gBAC5B,MAAMK,kBAAkB,MAAMlB,qBAAqB;oBACjDG;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC,OAAOK;gBACT;gBACA,IAAIK,gBAAgBC,MAAM,GAAG,GAAG;oBAC9BV,MAAM,CAACK,kBAAkB,GAAGI;gBAC9B;YACF,OAAO;gBACL,wEAAwE;gBACxE,kEAAkE;gBAClE,8EAA8E;gBAC9E,MAAME,gBAAgBZ,KAAK,CAACE,eAAe;gBAC3C,IAAI,OAAOU,kBAAkB,UAAU;oBACrC,KAAK,MAAMC,YAAYV,OAAOC,IAAI,CAACQ,eAAgB;wBACjD,IAAIrB,eAAeuB,QAAQ,CAACD,WAAuB;4BACjD,MAAME,cAAc,MAAMtB,iBAAiB;gCACzCE;gCACAC;gCACAC;gCACAmB,cAAcd;gCACdJ;gCACAe;gCACAd;gCACAkB,KAAKL,aAAa,CAACC,SAAS;4BAC9B;4BAEA,IAAIE,aAAaG,SAASH,aAAaI,MAAM;gCAC3ClB,SAAS;oCACP,GAAGA,MAAM;oCACT,CAACc,YAAYI,IAAI,CAAC,EAAEJ,YAAYG,KAAK;gCACvC;4BACF,OAAO,IAAI,OAAOH,aAAaG,UAAU,UAAU;gCACjDjB,SAASX,4BAA4BW,QAAQc,YAAYG,KAAK;4BAChE;wBACF;oBACF;gBACF;YACF;QACF;IACF;IAEA,OAAOjB;AACT"}
@@ -1,4 +1,4 @@
1
- import type { Field, TabAsField } from 'payload/types';
1
+ import type { Field, TabAsField } from 'payload';
2
2
  type SanitizeQueryValueArgs = {
3
3
  field: Field | TabAsField;
4
4
  hasCustomID: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"sanitizeQueryValue.d.ts","sourceRoot":"","sources":["../../src/queries/sanitizeQueryValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAKtD,KAAK,sBAAsB,GAAG;IAC5B,KAAK,EAAE,KAAK,GAAG,UAAU,CAAA;IACzB,WAAW,EAAE,OAAO,CAAA;IACpB,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,GAAG,CAAA;CACT,CAAA;AAED,eAAO,MAAM,kBAAkB,iDAM5B,sBAAsB,KAAG;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,GAAG,CAAC,EAAE,OAAO,CAAA;CAgKd,CAAA"}
1
+ {"version":3,"file":"sanitizeQueryValue.d.ts","sourceRoot":"","sources":["../../src/queries/sanitizeQueryValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAMhD,KAAK,sBAAsB,GAAG;IAC5B,KAAK,EAAE,KAAK,GAAG,UAAU,CAAA;IACzB,WAAW,EAAE,OAAO,CAAA;IACpB,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,GAAG,CAAA;CACT,CAAA;AAID,eAAO,MAAM,kBAAkB,iDAM5B,sBAAsB,KAAG;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,GAAG,CAAC,EAAE,OAAO,CAAA;CA8Od,CAAA"}
@@ -1,33 +1,71 @@
1
+ import ObjectIdImport from 'bson-objectid';
1
2
  import mongoose from 'mongoose';
2
- import { createArrayFromCommaDelineated } from 'payload/utilities';
3
+ import { createArrayFromCommaDelineated } from 'payload';
4
+ const ObjectId = ObjectIdImport.default || ObjectIdImport;
3
5
  export const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })=>{
4
6
  let formattedValue = val;
5
7
  let formattedOperator = operator;
6
8
  // Disregard invalid _ids
7
- if (path === '_id' && typeof val === 'string' && val.split(',').length === 1) {
8
- if (!hasCustomID) {
9
- const isValid = mongoose.Types.ObjectId.isValid(val);
10
- if (!isValid) {
11
- return {
12
- operator: formattedOperator,
13
- val: undefined
14
- };
9
+ if (path === '_id') {
10
+ if (typeof val === 'string' && val.split(',').length === 1) {
11
+ if (!hasCustomID) {
12
+ const isValid = mongoose.Types.ObjectId.isValid(val);
13
+ if (!isValid) {
14
+ return {
15
+ operator: formattedOperator,
16
+ val: undefined
17
+ };
18
+ } else {
19
+ if ([
20
+ 'in',
21
+ 'not_in'
22
+ ].includes(operator)) {
23
+ formattedValue = createArrayFromCommaDelineated(formattedValue).map((id)=>ObjectId(id));
24
+ } else {
25
+ formattedValue = ObjectId(val);
26
+ }
27
+ }
15
28
  }
16
- }
17
- if (field.type === 'number') {
18
- const parsedNumber = parseFloat(val);
19
- if (Number.isNaN(parsedNumber)) {
20
- return {
21
- operator: formattedOperator,
22
- val: undefined
23
- };
29
+ if (field.type === 'number') {
30
+ const parsedNumber = parseFloat(val);
31
+ if (Number.isNaN(parsedNumber)) {
32
+ return {
33
+ operator: formattedOperator,
34
+ val: undefined
35
+ };
36
+ }
24
37
  }
38
+ } else if (Array.isArray(val)) {
39
+ formattedValue = formattedValue.reduce((formattedValues, inVal)=>{
40
+ const newValues = [
41
+ inVal
42
+ ];
43
+ if (!hasCustomID) {
44
+ if (mongoose.Types.ObjectId.isValid(inVal)) {
45
+ newValues.push(ObjectId(inVal));
46
+ }
47
+ }
48
+ if (field.type === 'number') {
49
+ const parsedNumber = parseFloat(inVal);
50
+ if (!Number.isNaN(parsedNumber)) {
51
+ newValues.push(parsedNumber);
52
+ }
53
+ }
54
+ return [
55
+ ...formattedValues,
56
+ ...newValues
57
+ ];
58
+ }, []);
25
59
  }
26
60
  }
27
61
  // Cast incoming values as proper searchable types
28
62
  if (field.type === 'checkbox' && typeof val === 'string') {
29
- if (val.toLowerCase() === 'true') formattedValue = true;
30
- if (val.toLowerCase() === 'false') formattedValue = false;
63
+ if (val.toLowerCase() === 'true') {
64
+ formattedValue = true;
65
+ }
66
+ if (val.toLowerCase() === 'false') {
67
+ formattedValue = false;
68
+ }
31
69
  }
32
70
  if ([
33
71
  'all',
@@ -57,6 +95,11 @@ export const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })=
57
95
  }
58
96
  // Object equality requires the value to be the first key in the object that is being queried.
59
97
  if (operator === 'equals' && formattedValue && typeof formattedValue === 'object' && formattedValue.value && formattedValue.relationTo) {
98
+ const { value } = formattedValue;
99
+ const isValid = mongoose.Types.ObjectId.isValid(value);
100
+ if (isValid) {
101
+ formattedValue.value = ObjectId(value);
102
+ }
60
103
  return {
61
104
  rawQuery: {
62
105
  $and: [
@@ -74,20 +117,32 @@ export const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })=
74
117
  }
75
118
  };
76
119
  }
77
- if (operator === 'in' && Array.isArray(formattedValue)) {
120
+ if ([
121
+ 'in',
122
+ 'not_in'
123
+ ].includes(operator) && Array.isArray(formattedValue)) {
78
124
  formattedValue = formattedValue.reduce((formattedValues, inVal)=>{
79
125
  const newValues = [
80
126
  inVal
81
127
  ];
82
- if (mongoose.Types.ObjectId.isValid(inVal)) newValues.push(new mongoose.Types.ObjectId(inVal));
128
+ if (mongoose.Types.ObjectId.isValid(inVal)) {
129
+ newValues.push(ObjectId(inVal));
130
+ }
83
131
  const parsedNumber = parseFloat(inVal);
84
- if (!Number.isNaN(parsedNumber)) newValues.push(parsedNumber);
132
+ if (!Number.isNaN(parsedNumber)) {
133
+ newValues.push(parsedNumber);
134
+ }
85
135
  return [
86
136
  ...formattedValues,
87
137
  ...newValues
88
138
  ];
89
139
  }, []);
90
140
  }
141
+ if (operator === 'contains' && typeof formattedValue === 'string') {
142
+ if (mongoose.Types.ObjectId.isValid(formattedValue)) {
143
+ formattedValue = ObjectId(formattedValue);
144
+ }
145
+ }
91
146
  }
92
147
  // Set up specific formatting necessary by operators
93
148
  if (operator === 'near') {
@@ -113,8 +168,12 @@ export const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })=
113
168
  ]
114
169
  }
115
170
  };
116
- if (maxDistance) formattedValue.$maxDistance = parseFloat(maxDistance);
117
- if (minDistance) formattedValue.$minDistance = parseFloat(minDistance);
171
+ if (maxDistance) {
172
+ formattedValue.$maxDistance = parseFloat(maxDistance);
173
+ }
174
+ if (minDistance) {
175
+ formattedValue.$minDistance = parseFloat(minDistance);
176
+ }
118
177
  }
119
178
  }
120
179
  if (operator === 'within' || operator === 'intersects') {
@@ -123,12 +182,60 @@ export const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })=
123
182
  };
124
183
  }
125
184
  if (path !== '_id' || path === '_id' && hasCustomID && field.type === 'text') {
126
- if (operator === 'contains') {
185
+ if (operator === 'contains' && !mongoose.Types.ObjectId.isValid(formattedValue)) {
127
186
  formattedValue = {
128
187
  $options: 'i',
129
188
  $regex: formattedValue.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&')
130
189
  };
131
190
  }
191
+ if (operator === 'exists') {
192
+ formattedValue = formattedValue === 'true' || formattedValue === true;
193
+ if (formattedValue) {
194
+ return {
195
+ rawQuery: {
196
+ $and: [
197
+ {
198
+ [path]: {
199
+ $exists: true
200
+ }
201
+ },
202
+ {
203
+ [path]: {
204
+ $ne: null
205
+ }
206
+ },
207
+ {
208
+ [path]: {
209
+ $ne: ''
210
+ }
211
+ }
212
+ ]
213
+ }
214
+ };
215
+ } else {
216
+ return {
217
+ rawQuery: {
218
+ $or: [
219
+ {
220
+ [path]: {
221
+ $exists: false
222
+ }
223
+ },
224
+ {
225
+ [path]: {
226
+ $eq: null
227
+ }
228
+ },
229
+ {
230
+ [path]: {
231
+ $eq: ''
232
+ }
233
+ }
234
+ ]
235
+ }
236
+ };
237
+ }
238
+ }
132
239
  }
133
240
  if ((path === '_id' || path === 'parent') && operator === 'like' && formattedValue.length === 24 && !hasCustomID) {
134
241
  formattedOperator = 'equals';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/sanitizeQueryValue.ts"],"sourcesContent":["import type { Field, TabAsField } from 'payload/types'\n\nimport mongoose from 'mongoose'\nimport { createArrayFromCommaDelineated } from 'payload/utilities'\n\ntype SanitizeQueryValueArgs = {\n field: Field | TabAsField\n hasCustomID: boolean\n operator: string\n path: string\n val: any\n}\n\nexport const sanitizeQueryValue = ({\n field,\n hasCustomID,\n operator,\n path,\n val,\n}: SanitizeQueryValueArgs): {\n operator?: string\n rawQuery?: unknown\n val?: unknown\n} => {\n let formattedValue = val\n let formattedOperator = operator\n\n // Disregard invalid _ids\n if (path === '_id' && typeof val === 'string' && val.split(',').length === 1) {\n if (!hasCustomID) {\n const isValid = mongoose.Types.ObjectId.isValid(val)\n\n if (!isValid) {\n return { operator: formattedOperator, val: undefined }\n }\n }\n\n if (field.type === 'number') {\n const parsedNumber = parseFloat(val)\n\n if (Number.isNaN(parsedNumber)) {\n return { operator: formattedOperator, val: undefined }\n }\n }\n }\n\n // Cast incoming values as proper searchable types\n if (field.type === 'checkbox' && typeof val === 'string') {\n if (val.toLowerCase() === 'true') formattedValue = true\n if (val.toLowerCase() === 'false') formattedValue = false\n }\n\n if (['all', 'in', 'not_in'].includes(operator) && typeof formattedValue === 'string') {\n formattedValue = createArrayFromCommaDelineated(formattedValue)\n\n if (field.type === 'number') {\n formattedValue = formattedValue.map((arrayVal) => parseFloat(arrayVal))\n }\n }\n\n if (field.type === 'number' && typeof formattedValue === 'string') {\n formattedValue = Number(val)\n }\n\n if (field.type === 'date' && typeof val === 'string' && operator !== 'exists') {\n formattedValue = new Date(val)\n if (Number.isNaN(Date.parse(formattedValue))) {\n return undefined\n }\n }\n\n if (['relationship', 'upload'].includes(field.type)) {\n if (val === 'null') {\n formattedValue = null\n }\n\n // Object equality requires the value to be the first key in the object that is being queried.\n if (\n operator === 'equals' &&\n formattedValue &&\n typeof formattedValue === 'object' &&\n formattedValue.value &&\n formattedValue.relationTo\n ) {\n return {\n rawQuery: {\n $and: [\n { [`${path}.value`]: { $eq: formattedValue.value } },\n { [`${path}.relationTo`]: { $eq: formattedValue.relationTo } },\n ],\n },\n }\n }\n\n if (operator === 'in' && Array.isArray(formattedValue)) {\n formattedValue = formattedValue.reduce((formattedValues, inVal) => {\n const newValues = [inVal]\n if (mongoose.Types.ObjectId.isValid(inVal))\n newValues.push(new mongoose.Types.ObjectId(inVal))\n\n const parsedNumber = parseFloat(inVal)\n if (!Number.isNaN(parsedNumber)) newValues.push(parsedNumber)\n\n return [...formattedValues, ...newValues]\n }, [])\n }\n }\n\n // Set up specific formatting necessary by operators\n\n if (operator === 'near') {\n let lng\n let lat\n let maxDistance\n let minDistance\n\n if (Array.isArray(formattedValue)) {\n ;[lng, lat, maxDistance, minDistance] = formattedValue\n }\n\n if (typeof formattedValue === 'string') {\n ;[lng, lat, maxDistance, minDistance] = createArrayFromCommaDelineated(formattedValue)\n }\n\n if (lng == null || lat == null || (maxDistance == null && minDistance == null)) {\n formattedValue = undefined\n } else {\n formattedValue = {\n $geometry: { type: 'Point', coordinates: [parseFloat(lng), parseFloat(lat)] },\n }\n\n if (maxDistance) formattedValue.$maxDistance = parseFloat(maxDistance)\n if (minDistance) formattedValue.$minDistance = parseFloat(minDistance)\n }\n }\n\n if (operator === 'within' || operator === 'intersects') {\n formattedValue = {\n $geometry: formattedValue,\n }\n }\n\n if (path !== '_id' || (path === '_id' && hasCustomID && field.type === 'text')) {\n if (operator === 'contains') {\n formattedValue = {\n $options: 'i',\n $regex: formattedValue.replace(/[\\\\^$*+?.()|[\\]{}]/g, '\\\\$&'),\n }\n }\n }\n\n if (\n (path === '_id' || path === 'parent') &&\n operator === 'like' &&\n formattedValue.length === 24 &&\n !hasCustomID\n ) {\n formattedOperator = 'equals'\n }\n\n if (operator === 'exists') {\n formattedValue = formattedValue === 'true' || formattedValue === true\n\n // Clearable fields\n if (['relationship', 'select', 'upload'].includes(field.type)) {\n if (formattedValue) {\n return {\n rawQuery: {\n $and: [{ [path]: { $exists: true } }, { [path]: { $ne: null } }],\n },\n }\n } else {\n return {\n rawQuery: {\n $or: [{ [path]: { $exists: false } }, { [path]: { $eq: null } }],\n },\n }\n }\n }\n }\n\n return { operator: formattedOperator, val: formattedValue }\n}\n"],"names":["mongoose","createArrayFromCommaDelineated","sanitizeQueryValue","field","hasCustomID","operator","path","val","formattedValue","formattedOperator","split","length","isValid","Types","ObjectId","undefined","type","parsedNumber","parseFloat","Number","isNaN","toLowerCase","includes","map","arrayVal","Date","parse","value","relationTo","rawQuery","$and","$eq","Array","isArray","reduce","formattedValues","inVal","newValues","push","lng","lat","maxDistance","minDistance","$geometry","coordinates","$maxDistance","$minDistance","$options","$regex","replace","$exists","$ne","$or"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,OAAOA,cAAc,WAAU;AAC/B,SAASC,8BAA8B,QAAQ,oBAAmB;AAUlE,OAAO,MAAMC,qBAAqB,CAAC,EACjCC,KAAK,EACLC,WAAW,EACXC,QAAQ,EACRC,IAAI,EACJC,GAAG,EACoB;IAKvB,IAAIC,iBAAiBD;IACrB,IAAIE,oBAAoBJ;IAExB,yBAAyB;IACzB,IAAIC,SAAS,SAAS,OAAOC,QAAQ,YAAYA,IAAIG,KAAK,CAAC,KAAKC,MAAM,KAAK,GAAG;QAC5E,IAAI,CAACP,aAAa;YAChB,MAAMQ,UAAUZ,SAASa,KAAK,CAACC,QAAQ,CAACF,OAAO,CAACL;YAEhD,IAAI,CAACK,SAAS;gBACZ,OAAO;oBAAEP,UAAUI;oBAAmBF,KAAKQ;gBAAU;YACvD;QACF;QAEA,IAAIZ,MAAMa,IAAI,KAAK,UAAU;YAC3B,MAAMC,eAAeC,WAAWX;YAEhC,IAAIY,OAAOC,KAAK,CAACH,eAAe;gBAC9B,OAAO;oBAAEZ,UAAUI;oBAAmBF,KAAKQ;gBAAU;YACvD;QACF;IACF;IAEA,kDAAkD;IAClD,IAAIZ,MAAMa,IAAI,KAAK,cAAc,OAAOT,QAAQ,UAAU;QACxD,IAAIA,IAAIc,WAAW,OAAO,QAAQb,iBAAiB;QACnD,IAAID,IAAIc,WAAW,OAAO,SAASb,iBAAiB;IACtD;IAEA,IAAI;QAAC;QAAO;QAAM;KAAS,CAACc,QAAQ,CAACjB,aAAa,OAAOG,m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AAmB,UAAUA,mBAAmB;QAEjE,mBAAmB;QACnB,IAAI;YAAC;YAAgB;YAAU;SAAS,CAACc,QAAQ,CAACnB,MAAMa,IAAI,GAAG;YAC7D,IAAIR,gBAAgB;gBAClB,OAAO;oBACLqB,UAAU;wBACRC,MAAM;4BAAC;gCAAE,CAACxB,KAAK,EAAE;oCAAE4C,SAAS;gCAAK;4BAAE;4BAAG;gCAAE,CAAC5C,KAAK,EAAE;oCAAE6C,KAAK;gCAAK;4BAAE;yBAAE;oBAClE;gBACF;YACF,OAAO;gBACL,OAAO;oBACLtB,UAAU;wBACRuB,KAAK;4BAAC;gCAAE,CAAC9C,KAAK,EAAE;oCAAE4C,SAAS;gCAAM;4BAAE;4BAAG;gCAAE,CAAC5C,KAAK,EAAE;oCAAEyB,KAAK;gCAAK;4BAAE;yBAAE;oBAClE;gBACF;YACF;QACF;IACF;IAEA,OAAO;QAAE1B,UAAUI;QAAmBF,KAAKC;IAAe;AAC5D,EAAC"}
1
+ {"version":3,"sources":["../../src/queries/sanitizeQueryValue.ts"],"sourcesContent":["import type { Field, TabAsField } from 'payload'\n\nimport ObjectIdImport from 'bson-objectid'\nimport mongoose from 'mongoose'\nimport { createArrayFromCommaDelineated } from 'payload'\n\ntype SanitizeQueryValueArgs = {\n field: Field | TabAsField\n hasCustomID: boolean\n operator: string\n path: string\n val: any\n}\n\nconst ObjectId = (ObjectIdImport.default ||\n ObjectIdImport) as unknown as typeof ObjectIdImport.default\nexport const sanitizeQueryValue = ({\n field,\n hasCustomID,\n operator,\n path,\n val,\n}: SanitizeQueryValueArgs): {\n operator?: string\n rawQuery?: unknown\n val?: unknown\n} => {\n let formattedValue = val\n let formattedOperator = operator\n\n // Disregard invalid _ids\n if (path === '_id') {\n if (typeof val === 'string' && val.split(',').length === 1) {\n if (!hasCustomID) {\n const isValid = mongoose.Types.ObjectId.isValid(val)\n\n if (!isValid) {\n return { operator: formattedOperator, val: undefined }\n } else {\n if (['in', 'not_in'].includes(operator)) {\n formattedValue = createArrayFromCommaDelineated(formattedValue).map((id) =>\n ObjectId(id),\n )\n } else {\n formattedValue = ObjectId(val)\n }\n }\n }\n\n if (field.type === 'number') {\n const parsedNumber = parseFloat(val)\n\n if (Number.isNaN(parsedNumber)) {\n return { operator: formattedOperator, val: undefined }\n }\n }\n } else if (Array.isArray(val)) {\n formattedValue = formattedValue.reduce((formattedValues, inVal) => {\n const newValues = [inVal]\n if (!hasCustomID) {\n if (mongoose.Types.ObjectId.isValid(inVal)) {\n newValues.push(ObjectId(inVal))\n }\n }\n\n if (field.type === 'number') {\n const parsedNumber = parseFloat(inVal)\n if (!Number.isNaN(parsedNumber)) {\n newValues.push(parsedNumber)\n }\n }\n\n return [...formattedValues, ...newValues]\n }, [])\n }\n }\n\n // Cast incoming values as proper searchable types\n if (field.type === 'checkbox' && typeof val === 'string') {\n if (val.toLowerCase() === 'true') {\n formattedValue = true\n }\n if (val.toLowerCase() === 'false') {\n formattedValue = false\n }\n }\n\n if (['all', 'in', 'not_in'].includes(operator) && typeof formattedValue === 'string') {\n formattedValue = createArrayFromCommaDelineated(formattedValue)\n\n if (field.type === 'number') {\n formattedValue = formattedValue.map((arrayVal) => parseFloat(arrayVal))\n }\n }\n\n if (field.type === 'number' && typeof formattedValue === 'string') {\n formattedValue = Number(val)\n }\n\n if (field.type === 'date' && typeof val === 'string' && operator !== 'exists') {\n formattedValue = new Date(val)\n if (Number.isNaN(Date.parse(formattedValue))) {\n return undefined\n }\n }\n\n if (['relationship', 'upload'].includes(field.type)) {\n if (val === 'null') {\n formattedValue = null\n }\n\n // Object equality requires the value to be the first key in the object that is being queried.\n if (\n operator === 'equals' &&\n formattedValue &&\n typeof formattedValue === 'object' &&\n formattedValue.value &&\n formattedValue.relationTo\n ) {\n const { value } = formattedValue\n const isValid = mongoose.Types.ObjectId.isValid(value)\n\n if (isValid) {\n formattedValue.value = ObjectId(value)\n }\n\n return {\n rawQuery: {\n $and: [\n { [`${path}.value`]: { $eq: formattedValue.value } },\n { [`${path}.relationTo`]: { $eq: formattedValue.relationTo } },\n ],\n },\n }\n }\n\n if (['in', 'not_in'].includes(operator) && Array.isArray(formattedValue)) {\n formattedValue = formattedValue.reduce((formattedValues, inVal) => {\n const newValues = [inVal]\n if (mongoose.Types.ObjectId.isValid(inVal)) {\n newValues.push(ObjectId(inVal))\n }\n\n const parsedNumber = parseFloat(inVal)\n if (!Number.isNaN(parsedNumber)) {\n newValues.push(parsedNumber)\n }\n\n return [...formattedValues, ...newValues]\n }, [])\n }\n\n if (operator === 'contains' && typeof formattedValue === 'string') {\n if (mongoose.Types.ObjectId.isValid(formattedValue)) {\n formattedValue = ObjectId(formattedValue)\n }\n }\n }\n\n // Set up specific formatting necessary by operators\n\n if (operator === 'near') {\n let lng\n let lat\n let maxDistance\n let minDistance\n\n if (Array.isArray(formattedValue)) {\n ;[lng, lat, maxDistance, minDistance] = formattedValue\n }\n\n if (typeof formattedValue === 'string') {\n ;[lng, lat, maxDistance, minDistance] = createArrayFromCommaDelineated(formattedValue)\n }\n\n if (lng == null || lat == null || (maxDistance == null && minDistance == null)) {\n formattedValue = undefined\n } else {\n formattedValue = {\n $geometry: { type: 'Point', coordinates: [parseFloat(lng), parseFloat(lat)] },\n }\n\n if (maxDistance) {\n formattedValue.$maxDistance = parseFloat(maxDistance)\n }\n if (minDistance) {\n formattedValue.$minDistance = parseFloat(minDistance)\n }\n }\n }\n\n if (operator === 'within' || operator === 'intersects') {\n formattedValue = {\n $geometry: formattedValue,\n }\n }\n\n if (path !== '_id' || (path === '_id' && hasCustomID && field.type === 'text')) {\n if (operator === 'contains' && !mongoose.Types.ObjectId.isValid(formattedValue)) {\n formattedValue = {\n $options: 'i',\n $regex: formattedValue.replace(/[\\\\^$*+?.()|[\\]{}]/g, '\\\\$&'),\n }\n }\n\n if (operator === 'exists') {\n formattedValue = formattedValue === 'true' || formattedValue === true\n\n if (formattedValue) {\n return {\n rawQuery: {\n $and: [\n { [path]: { $exists: true } },\n { [path]: { $ne: null } },\n { [path]: { $ne: '' } },\n ],\n },\n }\n } else {\n return {\n rawQuery: {\n $or: [\n { [path]: { $exists: false } },\n { [path]: { $eq: null } },\n { [path]: { $eq: '' } }, // Treat empty string as null / undefined\n ],\n },\n }\n }\n }\n }\n\n if (\n (path === '_id' || path === 'parent') &&\n operator === 'like' &&\n formattedValue.length === 24 &&\n !hasCustomID\n ) {\n formattedOperator = 'equals'\n }\n\n if (operator === 'exists') {\n formattedValue = formattedValue === 'true' || formattedValue === true\n\n // Clearable fields\n if (['relationship', 'select', 'upload'].includes(field.type)) {\n if (formattedValue) {\n return {\n rawQuery: {\n $and: [{ [path]: { $exists: true } }, { [path]: { $ne: null } }],\n },\n }\n } else {\n return {\n rawQuery: {\n $or: [{ [path]: { $exists: false } }, { [path]: { $eq: null } }],\n },\n }\n }\n }\n }\n\n return { operator: formattedOperator, val: formattedValue }\n}\n"],"names":["ObjectIdImport","mongoose","createArrayFromCommaDelineated","ObjectId","default","sanitizeQueryValue","field","hasCustomID","operator","path","val","formattedValue","formattedOperator","split","length","isValid","Types","undefined","includes","map","id","type","parsedNumber","parseFloat","Number","isNaN","Array","isArray","reduce","formattedValues","inVal","newValues","push","toLowerCase","arrayVal","Date","parse","value","relationTo","rawQuery","$and","$eq","lng","lat","maxDistance","minDistance","$geometry","coordinates","$maxDistance","$minDistance","$options","$regex","replace","$exists","$ne","$or"],"mappings":"AAEA,OAAOA,oBAAoB,gBAAe;AAC1C,OAAOC,cAAc,WAAU;AAC/B,SAASC,8BAA8B,QAAQ,UAAS;AAUxD,MAAMC,WAAYH,eAAeI,OAAO,IACtCJ;AACF,OAAO,MAAMK,qBAAqB,CAAC,EACjCC,KAAK,EACLC,WAAW,EACXC,QAAQ,EACRC,IAAI,EACJC,GAAG,EACoB;IAKvB,IAAIC,iBAAiBD;IACrB,IAAIE,oBAAoBJ;IAExB,yBAAyB;IACzB,IAAIC,SAAS,OAAO;QAClB,IAAI,OAAOC,QAAQ,YAAYA,IAAIG,KAAK,CAAC,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SAAS,CAACO,QAAQ,CAACZ,MAAMe,IAAI,GAAG;YAC7D,IAAIV,gBAAgB;gBAClB,OAAO;oBACL4B,UAAU;wBACRC,MAAM;4BAAC;gCAAE,CAAC/B,KAAK,EAAE;oCAAE4C,SAAS;gCAAK;4BAAE;4BAAG;gCAAE,CAAC5C,KAAK,EAAE;oCAAE6C,KAAK;gCAAK;4BAAE;yBAAE;oBAClE;gBACF;YACF,OAAO;gBACL,OAAO;oBACLf,UAAU;wBACRgB,KAAK;4BAAC;gCAAE,CAAC9C,KAAK,EAAE;oCAAE4C,SAAS;gCAAM;4BAAE;4BAAG;gCAAE,CAAC5C,KAAK,EAAE;oCAAEgC,KAAK;gCAAK;4BAAE;yBAAE;oBAClE;gBACF;YACF;QACF;IACF;IAEA,OAAO;QAAEjC,UAAUI;QAAmBF,KAAKC;IAAe;AAC5D,EAAC"}
@@ -1,3 +1,3 @@
1
- import type { QueryDrafts } from 'payload/database';
1
+ import type { QueryDrafts } from 'payload';
2
2
  export declare const queryDrafts: QueryDrafts;
3
3
  //# sourceMappingURL=queryDrafts.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"queryDrafts.d.ts","sourceRoot":"","sources":["../src/queryDrafts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAWnD,eAAO,MAAM,WAAW,EAAE,WAmGzB,CAAA"}
1
+ {"version":3,"file":"queryDrafts.d.ts","sourceRoot":"","sources":["../src/queryDrafts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAkB,WAAW,EAAE,MAAM,SAAS,CAAA;AAU1D,eAAO,MAAM,WAAW,EAAE,WAiGzB,CAAA"}