@payloadcms/db-mongodb 3.0.0-canary.a0b06af → 3.0.0-canary.a14e066

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. package/dist/connect.d.ts.map +1 -1
  2. package/dist/connect.js +13 -4
  3. package/dist/connect.js.map +1 -1
  4. package/dist/create.d.ts.map +1 -1
  5. package/dist/create.js +7 -1
  6. package/dist/create.js.map +1 -1
  7. package/dist/createGlobal.d.ts.map +1 -1
  8. package/dist/createGlobal.js +10 -5
  9. package/dist/createGlobal.js.map +1 -1
  10. package/dist/createGlobalVersion.d.ts +1 -1
  11. package/dist/createGlobalVersion.d.ts.map +1 -1
  12. package/dist/createGlobalVersion.js +13 -4
  13. package/dist/createGlobalVersion.js.map +1 -1
  14. package/dist/createMigration.d.ts.map +1 -1
  15. package/dist/createMigration.js +3 -3
  16. package/dist/createMigration.js.map +1 -1
  17. package/dist/createVersion.d.ts +1 -1
  18. package/dist/createVersion.d.ts.map +1 -1
  19. package/dist/createVersion.js +31 -9
  20. package/dist/createVersion.js.map +1 -1
  21. package/dist/deleteOne.js +1 -1
  22. package/dist/deleteOne.js.map +1 -1
  23. package/dist/find.d.ts.map +1 -1
  24. package/dist/find.js +27 -4
  25. package/dist/find.js.map +1 -1
  26. package/dist/findGlobal.js +1 -1
  27. package/dist/findGlobal.js.map +1 -1
  28. package/dist/findGlobalVersions.d.ts.map +1 -1
  29. package/dist/findGlobalVersions.js +10 -4
  30. package/dist/findGlobalVersions.js.map +1 -1
  31. package/dist/findOne.d.ts.map +1 -1
  32. package/dist/findOne.js +19 -3
  33. package/dist/findOne.js.map +1 -1
  34. package/dist/findVersions.d.ts.map +1 -1
  35. package/dist/findVersions.js +8 -2
  36. package/dist/findVersions.js.map +1 -1
  37. package/dist/index.d.ts +52 -10
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +12 -6
  40. package/dist/index.js.map +1 -1
  41. package/dist/init.d.ts.map +1 -1
  42. package/dist/init.js +10 -7
  43. package/dist/init.js.map +1 -1
  44. package/dist/models/buildCollectionSchema.d.ts +1 -2
  45. package/dist/models/buildCollectionSchema.d.ts.map +1 -1
  46. package/dist/models/buildCollectionSchema.js +16 -4
  47. package/dist/models/buildCollectionSchema.js.map +1 -1
  48. package/dist/models/buildGlobalModel.js +2 -2
  49. package/dist/models/buildGlobalModel.js.map +1 -1
  50. package/dist/models/buildSchema.d.ts +1 -2
  51. package/dist/models/buildSchema.d.ts.map +1 -1
  52. package/dist/models/buildSchema.js +100 -22
  53. package/dist/models/buildSchema.js.map +1 -1
  54. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  55. package/dist/queries/buildAndOrConditions.js +0 -2
  56. package/dist/queries/buildAndOrConditions.js.map +1 -1
  57. package/dist/queries/buildQuery.d.ts +2 -2
  58. package/dist/queries/buildQuery.d.ts.map +1 -1
  59. package/dist/queries/buildQuery.js +1 -2
  60. package/dist/queries/buildQuery.js.map +1 -1
  61. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  62. package/dist/queries/buildSearchParams.js +19 -11
  63. package/dist/queries/buildSearchParams.js.map +1 -1
  64. package/dist/queries/getLocalizedSortProperty.spec.js +43 -43
  65. package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
  66. package/dist/queries/parseParams.d.ts.map +1 -1
  67. package/dist/queries/parseParams.js +5 -6
  68. package/dist/queries/parseParams.js.map +1 -1
  69. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  70. package/dist/queries/sanitizeQueryValue.js +142 -26
  71. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  72. package/dist/queryDrafts.d.ts.map +1 -1
  73. package/dist/queryDrafts.js +9 -5
  74. package/dist/queryDrafts.js.map +1 -1
  75. package/dist/transactions/beginTransaction.d.ts.map +1 -1
  76. package/dist/transactions/beginTransaction.js +2 -0
  77. package/dist/transactions/beginTransaction.js.map +1 -1
  78. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  79. package/dist/transactions/commitTransaction.js +3 -1
  80. package/dist/transactions/commitTransaction.js.map +1 -1
  81. package/dist/types.d.ts +7 -4
  82. package/dist/types.d.ts.map +1 -1
  83. package/dist/types.js.map +1 -1
  84. package/dist/updateGlobal.d.ts.map +1 -1
  85. package/dist/updateGlobal.js +8 -2
  86. package/dist/updateGlobal.js.map +1 -1
  87. package/dist/updateGlobalVersion.d.ts +2 -2
  88. package/dist/updateGlobalVersion.d.ts.map +1 -1
  89. package/dist/updateGlobalVersion.js +10 -3
  90. package/dist/updateGlobalVersion.js.map +1 -1
  91. package/dist/updateOne.d.ts.map +1 -1
  92. package/dist/updateOne.js +10 -3
  93. package/dist/updateOne.js.map +1 -1
  94. package/dist/updateVersion.d.ts +1 -1
  95. package/dist/updateVersion.d.ts.map +1 -1
  96. package/dist/updateVersion.js +8 -1
  97. package/dist/updateVersion.js.map +1 -1
  98. package/dist/upsert.d.ts +3 -0
  99. package/dist/upsert.d.ts.map +1 -0
  100. package/dist/upsert.js +14 -0
  101. package/dist/upsert.js.map +1 -0
  102. package/dist/utilities/buildJoinAggregation.d.ts +15 -0
  103. package/dist/utilities/buildJoinAggregation.d.ts.map +1 -0
  104. package/dist/utilities/buildJoinAggregation.js +148 -0
  105. package/dist/utilities/buildJoinAggregation.js.map +1 -0
  106. package/dist/utilities/getDBName.d.ts.map +1 -1
  107. package/dist/utilities/getDBName.js +3 -1
  108. package/dist/utilities/getDBName.js.map +1 -1
  109. package/dist/utilities/sanitizeInternalFields.d.ts +1 -2
  110. package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -1
  111. package/dist/utilities/sanitizeInternalFields.js +1 -2
  112. package/dist/utilities/sanitizeInternalFields.js.map +1 -1
  113. package/dist/utilities/sanitizeRelationshipIDs.d.ts +9 -0
  114. package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -0
  115. package/dist/utilities/sanitizeRelationshipIDs.js +115 -0
  116. package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -0
  117. package/dist/withSession.d.ts +1 -1
  118. package/dist/withSession.d.ts.map +1 -1
  119. package/dist/withSession.js +5 -3
  120. package/dist/withSession.js.map +1 -1
  121. package/package.json +9 -7
@@ -5,20 +5,17 @@ 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'\nimport { Config } from 'payload'\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"],"mappings":"AAAA,SAA0BA,cAAc,QAAQ,UAAS;AAEzD,SAASC,wBAAwB,QAAQ,gCAA+B;AAExE,IAAIC;AAEJC,SAAS,+BAA+B;IACtCC,UAAU;QACRF,SAAU,MAAMF,eAAe;YAC7BK,cAAc;gBACZC,SAAS;oBAAC;oBAA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CAAC;IAC/B;IAEAR,GAAG,uCAAuC;QACxC,MAAMC,SAAST,yBAAyB;YACtCU,UAAU;gBAAC;aAAQ;YACnBT;YACAU,QAAQ;gBACN;oBACEE,MAAM;oBACNF,QAAQ;wBACN;4BACEC,MAAM;4BACNC,MAAM;4BACNI,WAAW;wBACb;qBACD;gBACH;aACD;YACDH,QAAQ;QACV;QAEAC,OAAON,QAAQO,aAAa,CAAC;IAC/B;IAEAR,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,S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ACEC,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,"file":"parseParams.d.ts","sourceRoot":"","sources":["../../src/queries/parseParams.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAY,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAS9D,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,5 +1,4 @@
1
- /* eslint-disable no-restricted-syntax */ /* eslint-disable no-await-in-loop */ import deepmerge from 'deepmerge';
2
- import { combineMerge } from 'payload';
1
+ import { deepMergeWithCombinedArrays } from 'payload';
3
2
  import { validOperators } from 'payload/shared';
4
3
  import { buildAndOrConditions } from './buildAndOrConditions.js';
5
4
  import { buildSearchParam } from './buildSearchParams.js';
@@ -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 { Field, Operator, Payload, Where } from 'payload'\n\nimport deepmerge from 'deepmerge'\nimport { combineMerge } 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) 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","combineMerge","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","arrayMerge"],"mappings":"AAAA,uCAAuC,GACvC,mCAAmC,GAInC,OAAOA,eAAe,YAAW;AACjC,SAASC,YAAY,QAAQ,UAAS;AACtC,SAASC,cAAc,QAAQ,iBAAgB;AAE/C,SAASC,oBAAoB,QAAQ,4BAA2B;AAChE,SAASC,gBAAgB,QAAQ,yBAAwB;AAEzD,OAAO,eAAeC,YAAY,EAChCC,cAAc,EACdC,MAAM,EACNC,UA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IAEA,OAAOW;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 +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,SAAS,CAAA;AAKhD,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;AA4BD,eAAO,MAAM,kBAAkB,iDAM5B,sBAAsB,KAAG;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,GAAG,CAAC,EAAE,OAAO,CAAA;CAkOd,CAAA"}
@@ -1,33 +1,118 @@
1
+ import ObjectIdImport from 'bson-objectid';
1
2
  import mongoose from 'mongoose';
2
3
  import { createArrayFromCommaDelineated } from 'payload';
4
+ const buildExistsQuery = (formattedValue, path)=>{
5
+ if (formattedValue) {
6
+ return {
7
+ rawQuery: {
8
+ $and: [
9
+ {
10
+ [path]: {
11
+ $exists: true
12
+ }
13
+ },
14
+ {
15
+ [path]: {
16
+ $ne: null
17
+ }
18
+ },
19
+ {
20
+ [path]: {
21
+ $ne: ''
22
+ }
23
+ }
24
+ ]
25
+ }
26
+ };
27
+ } else {
28
+ return {
29
+ rawQuery: {
30
+ $or: [
31
+ {
32
+ [path]: {
33
+ $exists: false
34
+ }
35
+ },
36
+ {
37
+ [path]: {
38
+ $eq: null
39
+ }
40
+ },
41
+ {
42
+ [path]: {
43
+ $eq: ''
44
+ }
45
+ }
46
+ ]
47
+ }
48
+ };
49
+ }
50
+ };
51
+ const ObjectId = ObjectIdImport.default || ObjectIdImport;
3
52
  export const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })=>{
4
53
  let formattedValue = val;
5
54
  let formattedOperator = operator;
6
55
  // 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
- };
56
+ if (path === '_id') {
57
+ if (typeof val === 'string' && val.split(',').length === 1) {
58
+ if (!hasCustomID) {
59
+ const isValid = mongoose.Types.ObjectId.isValid(val);
60
+ if (!isValid) {
61
+ return {
62
+ operator: formattedOperator,
63
+ val: undefined
64
+ };
65
+ } else {
66
+ if ([
67
+ 'in',
68
+ 'not_in'
69
+ ].includes(operator)) {
70
+ formattedValue = createArrayFromCommaDelineated(formattedValue).map((id)=>ObjectId(id));
71
+ } else {
72
+ formattedValue = ObjectId(val);
73
+ }
74
+ }
15
75
  }
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
- };
76
+ if (field.type === 'number') {
77
+ const parsedNumber = parseFloat(val);
78
+ if (Number.isNaN(parsedNumber)) {
79
+ return {
80
+ operator: formattedOperator,
81
+ val: undefined
82
+ };
83
+ }
24
84
  }
85
+ } else if (Array.isArray(val)) {
86
+ formattedValue = formattedValue.reduce((formattedValues, inVal)=>{
87
+ const newValues = [
88
+ inVal
89
+ ];
90
+ if (!hasCustomID) {
91
+ if (mongoose.Types.ObjectId.isValid(inVal)) {
92
+ newValues.push(ObjectId(inVal));
93
+ }
94
+ }
95
+ if (field.type === 'number') {
96
+ const parsedNumber = parseFloat(inVal);
97
+ if (!Number.isNaN(parsedNumber)) {
98
+ newValues.push(parsedNumber);
99
+ }
100
+ }
101
+ return [
102
+ ...formattedValues,
103
+ ...newValues
104
+ ];
105
+ }, []);
25
106
  }
26
107
  }
27
108
  // Cast incoming values as proper searchable types
28
109
  if (field.type === 'checkbox' && typeof val === 'string') {
29
- if (val.toLowerCase() === 'true') formattedValue = true;
30
- if (val.toLowerCase() === 'false') formattedValue = false;
110
+ if (val.toLowerCase() === 'true') {
111
+ formattedValue = true;
112
+ }
113
+ if (val.toLowerCase() === 'false') {
114
+ formattedValue = false;
115
+ }
31
116
  }
32
117
  if ([
33
118
  'all',
@@ -39,8 +124,14 @@ export const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })=
39
124
  formattedValue = formattedValue.map((arrayVal)=>parseFloat(arrayVal));
40
125
  }
41
126
  }
42
- if (field.type === 'number' && typeof formattedValue === 'string') {
43
- formattedValue = Number(val);
127
+ if (field.type === 'number') {
128
+ if (typeof formattedValue === 'string' && operator !== 'exists') {
129
+ formattedValue = Number(val);
130
+ }
131
+ if (operator === 'exists') {
132
+ formattedValue = val === 'true' ? true : val === 'false' ? false : Boolean(val);
133
+ return buildExistsQuery(formattedValue, path);
134
+ }
44
135
  }
45
136
  if (field.type === 'date' && typeof val === 'string' && operator !== 'exists') {
46
137
  formattedValue = new Date(val);
@@ -57,6 +148,11 @@ export const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })=
57
148
  }
58
149
  // Object equality requires the value to be the first key in the object that is being queried.
59
150
  if (operator === 'equals' && formattedValue && typeof formattedValue === 'object' && formattedValue.value && formattedValue.relationTo) {
151
+ const { value } = formattedValue;
152
+ const isValid = mongoose.Types.ObjectId.isValid(value);
153
+ if (isValid) {
154
+ formattedValue.value = ObjectId(value);
155
+ }
60
156
  return {
61
157
  rawQuery: {
62
158
  $and: [
@@ -74,20 +170,32 @@ export const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })=
74
170
  }
75
171
  };
76
172
  }
77
- if (operator === 'in' && Array.isArray(formattedValue)) {
173
+ if ([
174
+ 'in',
175
+ 'not_in'
176
+ ].includes(operator) && Array.isArray(formattedValue)) {
78
177
  formattedValue = formattedValue.reduce((formattedValues, inVal)=>{
79
178
  const newValues = [
80
179
  inVal
81
180
  ];
82
- if (mongoose.Types.ObjectId.isValid(inVal)) newValues.push(new mongoose.Types.ObjectId(inVal));
181
+ if (mongoose.Types.ObjectId.isValid(inVal)) {
182
+ newValues.push(ObjectId(inVal));
183
+ }
83
184
  const parsedNumber = parseFloat(inVal);
84
- if (!Number.isNaN(parsedNumber)) newValues.push(parsedNumber);
185
+ if (!Number.isNaN(parsedNumber)) {
186
+ newValues.push(parsedNumber);
187
+ }
85
188
  return [
86
189
  ...formattedValues,
87
190
  ...newValues
88
191
  ];
89
192
  }, []);
90
193
  }
194
+ if (operator === 'contains' && typeof formattedValue === 'string') {
195
+ if (mongoose.Types.ObjectId.isValid(formattedValue)) {
196
+ formattedValue = ObjectId(formattedValue);
197
+ }
198
+ }
91
199
  }
92
200
  // Set up specific formatting necessary by operators
93
201
  if (operator === 'near') {
@@ -113,8 +221,12 @@ export const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })=
113
221
  ]
114
222
  }
115
223
  };
116
- if (maxDistance) formattedValue.$maxDistance = parseFloat(maxDistance);
117
- if (minDistance) formattedValue.$minDistance = parseFloat(minDistance);
224
+ if (maxDistance) {
225
+ formattedValue.$maxDistance = parseFloat(maxDistance);
226
+ }
227
+ if (minDistance) {
228
+ formattedValue.$minDistance = parseFloat(minDistance);
229
+ }
118
230
  }
119
231
  }
120
232
  if (operator === 'within' || operator === 'intersects') {
@@ -123,12 +235,16 @@ export const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })=
123
235
  };
124
236
  }
125
237
  if (path !== '_id' || path === '_id' && hasCustomID && field.type === 'text') {
126
- if (operator === 'contains') {
238
+ if (operator === 'contains' && !mongoose.Types.ObjectId.isValid(formattedValue)) {
127
239
  formattedValue = {
128
240
  $options: 'i',
129
241
  $regex: formattedValue.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&')
130
242
  };
131
243
  }
244
+ if (operator === 'exists') {
245
+ formattedValue = formattedValue === 'true' || formattedValue === true;
246
+ return buildExistsQuery(formattedValue, path);
247
+ }
132
248
  }
133
249
  if ((path === '_id' || path === 'parent') && operator === 'like' && formattedValue.length === 24 && !hasCustomID) {
134
250
  formattedOperator = 'equals';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/sanitizeQueryValue.ts"],"sourcesContent":["import type { Field, TabAsField } from 'payload'\n\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\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"],"mappings":"AAEA,OAAOA,cAAc,WAAU;AAC/B,SAASC,8BAA8B,QAAQ,UAAS;AAUxD,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,mBAAmB,UAAU;QACpFA,iBAAiBP,+BAA+BO;QAEhD,IAAIL,MAAMa,IAAI,KAAK,UAAU;YAC3BR,iBAAiBA,eAAee,GAAG,CAAC,CAACC,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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 buildExistsQuery = (formattedValue, path) => {\n if (formattedValue) {\n return {\n rawQuery: {\n $and: [\n { [path]: { $exists: true } },\n { [path]: { $ne: null } },\n { [path]: { $ne: '' } }, // Exclude null and empty string\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\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') {\n if (typeof formattedValue === 'string' && operator !== 'exists') {\n formattedValue = Number(val)\n }\n\n if (operator === 'exists') {\n formattedValue = val === 'true' ? true : val === 'false' ? false : Boolean(val)\n\n return buildExistsQuery(formattedValue, path)\n }\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 return buildExistsQuery(formattedValue, path)\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","buildExistsQuery","formattedValue","path","rawQuery","$and","$exists","$ne","$or","$eq","ObjectId","default","sanitizeQueryValue","field","hasCustomID","operator","val","formattedOperator","split","length","isValid","Types","undefined","includes","map","id","type","parsedNumber","parseFloat","Number","isNaN","Array","isArray","reduce","formattedValues","inVal","newValues","push","toLowerCase","arrayVal","Boolean","Date","parse","value","relationTo","lng","lat","maxDistance","minDistance","$geometry","coordinates","$maxDistance","$minDistance","$options","$regex","replace"],"mappings":"AAEA,OAAOA,oBAAoB,gBAAe;AAC1C,OAAOC,cAAc,WAAU;AAC/B,SAASC,8BAA8B,QAAQ,UAAS;AAUxD,MAAMC,mBAAmB,CAACC,gBAAgBC;IACxC,IAAID,gBAAgB;QAClB,OAAO;YACLE,UAAU;gBACRC,MAAM;oBACJ;wBAAE,CAACF,KAAK,EAAE;4BAAEG,SAAS;wBAAK;oBAAE;oBAC5B;wBAAE,CAACH,KAAK,EAAE;4BAAEI,KAAK;w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,UAAUA,mBAAmB;YAEjE,OAAOD,iBAAiBC,gBAAgBC;QAC1C;IACF;IAEA,IACE,AAACA,CAAAA,SAAS,SAASA,SAAS,QAAO,KACnCY,aAAa,UACbb,eAAeiB,MAAM,KAAK,MAC1B,CAACL,aACD;QACAG,oBAAoB;IACtB;IAEA,IAAIF,aAAa,UAAU;QACzBb,iBAAiBA,mBAAmB,UAAUA,mBAAmB;QAEjE,mBAAmB;QACnB,IAAI;YAAC;YAAgB;YAAU;SAAS,CAACqB,QAAQ,CAACV,MAAMa,IAAI,GAAG;YAC7D,IAAIxB,gBAAgB;gBAClB,OAAO;oBACLE,UAAU;wBACRC,MAAM;4BAAC;gCAAE,CAACF,KAAK,EAAE;oCAAEG,SAAS;gCAAK;4BAAE;4BAAG;gCAAE,CAACH,KAAK,EAAE;oCAAEI,KAAK;gCAAK;4BAAE;yBAAE;oBAClE;gBACF;YACF,OAAO;gBACL,OAAO;oBACLH,UAAU;wBACRI,KAAK;4BAAC;gCAAE,CAACL,KAAK,EAAE;oCAAEG,SAAS;gCAAM;4BAAE;4BAAG;gCAAE,CAACH,KAAK,EAAE;oCAAEM,KAAK;gCAAK;4BAAE;yBAAE;oBAClE;gBACF;YACF;QACF;IACF;IAEA,OAAO;QAAEM,UAAUE;QAAmBD,KAAKd;IAAe;AAC5D,EAAC"}
@@ -1 +1 @@
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,WA0FzB,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,WA+FzB,CAAA"}
@@ -1,6 +1,6 @@
1
1
  import { combineQueries, flattenWhereToOperators } from 'payload';
2
2
  import { buildSortParam } from './queries/buildSortParam.js';
3
- import sanitizeInternalFields from './utilities/sanitizeInternalFields.js';
3
+ import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
4
4
  import { withSession } from './withSession.js';
5
5
  export const queryDrafts = async function queryDrafts({ collection, limit, locale, page, pagination, req = {}, sort: sortArg, where }) {
6
6
  const VersionModel = this.versions[collection];
@@ -43,6 +43,13 @@ export const queryDrafts = async function queryDrafts({ collection, limit, local
43
43
  sort,
44
44
  useEstimatedCount
45
45
  };
46
+ if (this.collation) {
47
+ const defaultLocale = 'en';
48
+ paginationOptions.collation = {
49
+ locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,
50
+ ...this.collation
51
+ };
52
+ }
46
53
  if (!useEstimatedCount && Object.keys(versionQuery).length === 0 && this.disableIndexHints !== true) {
47
54
  // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
48
55
  // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
@@ -66,13 +73,10 @@ export const queryDrafts = async function queryDrafts({ collection, limit, local
66
73
  return {
67
74
  ...result,
68
75
  docs: docs.map((doc)=>{
69
- // eslint-disable-next-line no-param-reassign
70
76
  doc = {
71
77
  _id: doc.parent,
72
78
  id: doc.parent,
73
- ...doc.version,
74
- createdAt: doc.createdAt,
75
- updatedAt: doc.updatedAt
79
+ ...doc.version
76
80
  };
77
81
  return sanitizeInternalFields(doc);
78
82
  })