@payloadcms/drizzle 3.91.0-internal.6e3dc85 → 4.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/exports/postgres.d.ts +4 -0
  3. package/dist/exports/postgres.d.ts.map +1 -1
  4. package/dist/exports/postgres.js +4 -0
  5. package/dist/exports/postgres.js.map +1 -1
  6. package/dist/exports/sqlite.d.ts +2 -0
  7. package/dist/exports/sqlite.d.ts.map +1 -1
  8. package/dist/exports/sqlite.js +2 -0
  9. package/dist/exports/sqlite.js.map +1 -1
  10. package/dist/find/buildPolymorphicJoinQuery.d.ts +2 -1
  11. package/dist/find/buildPolymorphicJoinQuery.d.ts.map +1 -1
  12. package/dist/find/buildPolymorphicJoinQuery.js +2 -1
  13. package/dist/find/buildPolymorphicJoinQuery.js.map +1 -1
  14. package/dist/find/buildPolymorphicJoinWhere.d.ts +2 -1
  15. package/dist/find/buildPolymorphicJoinWhere.d.ts.map +1 -1
  16. package/dist/find/buildPolymorphicJoinWhere.js +43 -10
  17. package/dist/find/buildPolymorphicJoinWhere.js.map +1 -1
  18. package/dist/find/createPolymorphicJoinWherePlan.js +3 -2
  19. package/dist/find/createPolymorphicJoinWherePlan.js.map +1 -1
  20. package/dist/find/traverseFields.d.ts.map +1 -1
  21. package/dist/find/traverseFields.js +2 -2
  22. package/dist/find/traverseFields.js.map +1 -1
  23. package/dist/index.d.ts +4 -11
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +2 -9
  26. package/dist/index.js.map +1 -1
  27. package/dist/migrate.d.ts.map +1 -1
  28. package/dist/migrate.js +41 -15
  29. package/dist/migrate.js.map +1 -1
  30. package/dist/migrateDown.d.ts +2 -1
  31. package/dist/migrateDown.d.ts.map +1 -1
  32. package/dist/migrateDown.js +17 -4
  33. package/dist/migrateDown.js.map +1 -1
  34. package/dist/migrateFresh.d.ts +4 -2
  35. package/dist/migrateFresh.d.ts.map +1 -1
  36. package/dist/migrateFresh.js +26 -9
  37. package/dist/migrateFresh.js.map +1 -1
  38. package/dist/migrateRefresh.d.ts +2 -1
  39. package/dist/migrateRefresh.d.ts.map +1 -1
  40. package/dist/migrateRefresh.js +20 -5
  41. package/dist/migrateRefresh.js.map +1 -1
  42. package/dist/migrateReset.d.ts +2 -1
  43. package/dist/migrateReset.d.ts.map +1 -1
  44. package/dist/migrateReset.js +18 -4
  45. package/dist/migrateReset.js.map +1 -1
  46. package/dist/migrateStatus.d.ts +2 -1
  47. package/dist/migrateStatus.d.ts.map +1 -1
  48. package/dist/migrateStatus.js +11 -6
  49. package/dist/migrateStatus.js.map +1 -1
  50. package/dist/postgres/predefinedMigrations/localize-status/index.d.ts +11 -0
  51. package/dist/postgres/predefinedMigrations/localize-status/index.d.ts.map +1 -0
  52. package/dist/postgres/predefinedMigrations/localize-status/index.js +296 -0
  53. package/dist/postgres/predefinedMigrations/localize-status/index.js.map +1 -0
  54. package/dist/postgres/predefinedMigrations/localize-status/migrateMainCollection.d.ts +13 -0
  55. package/dist/postgres/predefinedMigrations/localize-status/migrateMainCollection.d.ts.map +1 -0
  56. package/dist/postgres/predefinedMigrations/localize-status/migrateMainCollection.js +51 -0
  57. package/dist/postgres/predefinedMigrations/localize-status/migrateMainCollection.js.map +1 -0
  58. package/dist/postgres/predefinedMigrations/localize-status/migrateMainGlobal.d.ts +13 -0
  59. package/dist/postgres/predefinedMigrations/localize-status/migrateMainGlobal.d.ts.map +1 -0
  60. package/dist/postgres/predefinedMigrations/localize-status/migrateMainGlobal.js +54 -0
  61. package/dist/postgres/predefinedMigrations/localize-status/migrateMainGlobal.js.map +1 -0
  62. package/dist/postgres/predefinedMigrations/sizes-to-variants/index.d.ts +35 -0
  63. package/dist/postgres/predefinedMigrations/sizes-to-variants/index.d.ts.map +1 -0
  64. package/dist/postgres/predefinedMigrations/sizes-to-variants/index.js +185 -0
  65. package/dist/postgres/predefinedMigrations/sizes-to-variants/index.js.map +1 -0
  66. package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts.map +1 -1
  67. package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/index.js +8 -4
  68. package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/index.js.map +1 -1
  69. package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts.map +1 -1
  70. package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js.map +1 -1
  71. package/dist/postgres/predefinedMigrations/v2-v3/index.js +1 -1
  72. package/dist/postgres/predefinedMigrations/v2-v3/index.js.map +1 -1
  73. package/dist/postgres/query/assertOperatorHandlerExtensionsInstalled.d.ts +15 -0
  74. package/dist/postgres/query/assertOperatorHandlerExtensionsInstalled.d.ts.map +1 -0
  75. package/dist/postgres/query/assertOperatorHandlerExtensionsInstalled.js +25 -0
  76. package/dist/postgres/query/assertOperatorHandlerExtensionsInstalled.js.map +1 -0
  77. package/dist/postgres/query/postgresUnaccent.d.ts +13 -0
  78. package/dist/postgres/query/postgresUnaccent.d.ts.map +1 -0
  79. package/dist/postgres/query/postgresUnaccent.js +40 -0
  80. package/dist/postgres/query/postgresUnaccent.js.map +1 -0
  81. package/dist/postgres/schema/geometryColumn.d.ts +2 -2
  82. package/dist/postgres/types.d.ts +13 -2
  83. package/dist/postgres/types.d.ts.map +1 -1
  84. package/dist/postgres/types.js.map +1 -1
  85. package/dist/queries/addJoinTable.d.ts +1 -1
  86. package/dist/queries/buildOperatorConstraint.d.ts +22 -0
  87. package/dist/queries/buildOperatorConstraint.d.ts.map +1 -0
  88. package/dist/queries/buildOperatorConstraint.js +63 -0
  89. package/dist/queries/buildOperatorConstraint.js.map +1 -0
  90. package/dist/queries/buildOrderBy.d.ts +1 -1
  91. package/dist/queries/buildOrderBy.d.ts.map +1 -1
  92. package/dist/queries/buildOrderBy.js +6 -1
  93. package/dist/queries/buildOrderBy.js.map +1 -1
  94. package/dist/queries/getTableColumnFromPath.d.ts +12 -3
  95. package/dist/queries/getTableColumnFromPath.d.ts.map +1 -1
  96. package/dist/queries/getTableColumnFromPath.js +52 -29
  97. package/dist/queries/getTableColumnFromPath.js.map +1 -1
  98. package/dist/queries/operatorMap.d.ts +7 -3
  99. package/dist/queries/operatorMap.d.ts.map +1 -1
  100. package/dist/queries/operatorMap.js.map +1 -1
  101. package/dist/queries/parseParams.d.ts.map +1 -1
  102. package/dist/queries/parseParams.js +226 -36
  103. package/dist/queries/parseParams.js.map +1 -1
  104. package/dist/queries/resolveRelationshipPath.d.ts +36 -0
  105. package/dist/queries/resolveRelationshipPath.d.ts.map +1 -0
  106. package/dist/queries/resolveRelationshipPath.js +66 -0
  107. package/dist/queries/resolveRelationshipPath.js.map +1 -0
  108. package/dist/queries/validateOperatorHandlers.d.ts +8 -0
  109. package/dist/queries/validateOperatorHandlers.d.ts.map +1 -0
  110. package/dist/queries/validateOperatorHandlers.js +30 -0
  111. package/dist/queries/validateOperatorHandlers.js.map +1 -0
  112. package/dist/schema/traverseFields.d.ts.map +1 -1
  113. package/dist/schema/traverseFields.js +2 -1
  114. package/dist/schema/traverseFields.js.map +1 -1
  115. package/dist/sqlite/insert.d.ts.map +1 -1
  116. package/dist/sqlite/insert.js +4 -1
  117. package/dist/sqlite/insert.js.map +1 -1
  118. package/dist/sqlite/predefinedMigrations/localize-status/index.d.ts +28 -0
  119. package/dist/sqlite/predefinedMigrations/localize-status/index.d.ts.map +1 -0
  120. package/dist/sqlite/predefinedMigrations/localize-status/index.js +198 -0
  121. package/dist/sqlite/predefinedMigrations/localize-status/index.js.map +1 -0
  122. package/dist/sqlite/predefinedMigrations/localize-status/migrateMainCollection.d.ts +12 -0
  123. package/dist/sqlite/predefinedMigrations/localize-status/migrateMainCollection.d.ts.map +1 -0
  124. package/dist/sqlite/predefinedMigrations/localize-status/migrateMainCollection.js +24 -0
  125. package/dist/sqlite/predefinedMigrations/localize-status/migrateMainCollection.js.map +1 -0
  126. package/dist/sqlite/predefinedMigrations/localize-status/migrateMainGlobal.d.ts +12 -0
  127. package/dist/sqlite/predefinedMigrations/localize-status/migrateMainGlobal.d.ts.map +1 -0
  128. package/dist/sqlite/predefinedMigrations/localize-status/migrateMainGlobal.js +28 -0
  129. package/dist/sqlite/predefinedMigrations/localize-status/migrateMainGlobal.js.map +1 -0
  130. package/dist/sqlite/predefinedMigrations/sizes-to-variants/index.d.ts +15 -0
  131. package/dist/sqlite/predefinedMigrations/sizes-to-variants/index.d.ts.map +1 -0
  132. package/dist/sqlite/predefinedMigrations/sizes-to-variants/index.js +114 -0
  133. package/dist/sqlite/predefinedMigrations/sizes-to-variants/index.js.map +1 -0
  134. package/dist/transform/read/traverseFields.js +2 -2
  135. package/dist/transform/read/traverseFields.js.map +1 -1
  136. package/dist/transform/write/blocks.js +1 -1
  137. package/dist/transform/write/blocks.js.map +1 -1
  138. package/dist/transform/write/traverseFields.js +1 -2
  139. package/dist/transform/write/traverseFields.js.map +1 -1
  140. package/dist/types.d.ts +50 -6
  141. package/dist/types.d.ts.map +1 -1
  142. package/dist/types.js +1 -3
  143. package/dist/types.js.map +1 -1
  144. package/dist/updateJobs.d.ts.map +1 -1
  145. package/dist/updateJobs.js +37 -0
  146. package/dist/updateJobs.js.map +1 -1
  147. package/dist/upsertRow/index.d.ts.map +1 -1
  148. package/dist/upsertRow/index.js +5 -2
  149. package/dist/upsertRow/index.js.map +1 -1
  150. package/dist/upsertRow/insertArrays.d.ts.map +1 -1
  151. package/dist/upsertRow/insertArrays.js +2 -1
  152. package/dist/upsertRow/insertArrays.js.map +1 -1
  153. package/dist/utilities/buildCreateMigration.d.ts.map +1 -1
  154. package/dist/utilities/buildCreateMigration.js +12 -8
  155. package/dist/utilities/buildCreateMigration.js.map +1 -1
  156. package/dist/utilities/buildDynamicPredefinedSizesToVariantsMigration.d.ts +15 -0
  157. package/dist/utilities/buildDynamicPredefinedSizesToVariantsMigration.d.ts.map +1 -0
  158. package/dist/utilities/buildDynamicPredefinedSizesToVariantsMigration.js +110 -0
  159. package/dist/utilities/buildDynamicPredefinedSizesToVariantsMigration.js.map +1 -0
  160. package/dist/utilities/checkTruncatedIdentifiers.d.ts +1 -1
  161. package/dist/utilities/createSchemaGenerator.d.ts.map +1 -1
  162. package/dist/utilities/createSchemaGenerator.js +3 -0
  163. package/dist/utilities/createSchemaGenerator.js.map +1 -1
  164. package/dist/utilities/getPrimaryDb.d.ts +1 -1
  165. package/dist/utilities/getSizesToVariantsRenames.d.ts +54 -0
  166. package/dist/utilities/getSizesToVariantsRenames.d.ts.map +1 -0
  167. package/dist/utilities/getSizesToVariantsRenames.js +251 -0
  168. package/dist/utilities/getSizesToVariantsRenames.js.map +1 -0
  169. package/dist/utilities/getTransaction.d.ts +1 -1
  170. package/dist/utilities/getTransaction.d.ts.map +1 -1
  171. package/dist/utilities/validateExistingBlockIsIdentical.d.ts +1 -4
  172. package/dist/utilities/validateExistingBlockIsIdentical.d.ts.map +1 -1
  173. package/dist/utilities/validateExistingBlockIsIdentical.js.map +1 -1
  174. package/package.json +6 -11
  175. package/dist/exports/types-deprecated.d.ts +0 -150
  176. package/dist/exports/types-deprecated.d.ts.map +0 -1
  177. package/dist/exports/types-deprecated.js +0 -5
  178. package/dist/exports/types-deprecated.js.map +0 -1
  179. package/dist/find/buildPolymorphicJoinQuery.spec.js +0 -384
  180. package/dist/find/buildPolymorphicJoinQuery.spec.js.map +0 -1
  181. package/dist/find/buildPolymorphicJoinWhere.spec.js +0 -762
  182. package/dist/find/buildPolymorphicJoinWhere.spec.js.map +0 -1
  183. package/dist/find/chainMethods.d.ts +0 -20
  184. package/dist/find/chainMethods.d.ts.map +0 -1
  185. package/dist/find/chainMethods.js +0 -16
  186. package/dist/find/chainMethods.js.map +0 -1
  187. package/dist/find/createPolymorphicJoinWherePlan.spec.js +0 -897
  188. package/dist/find/createPolymorphicJoinWherePlan.spec.js.map +0 -1
  189. package/dist/schema/buildRawSchema.spec.js +0 -231
  190. package/dist/schema/buildRawSchema.spec.js.map +0 -1
  191. package/dist/sqlite/createJSONQuery/index.spec.js +0 -28
  192. package/dist/sqlite/createJSONQuery/index.spec.js.map +0 -1
  193. package/dist/updateOne.spec.js +0 -84
  194. package/dist/updateOne.spec.js.map +0 -1
  195. package/dist/upsertRow/conditionalUpdate.spec.js +0 -61
  196. package/dist/upsertRow/conditionalUpdate.spec.js.map +0 -1
  197. package/dist/upsertRow/handleUpsertError.spec.js +0 -42
  198. package/dist/upsertRow/handleUpsertError.spec.js.map +0 -1
  199. package/dist/utilities/checkTruncatedIdentifiers.spec.js +0 -301
  200. package/dist/utilities/checkTruncatedIdentifiers.spec.js.map +0 -1
  201. package/dist/utilities/isValidStringID.spec.js +0 -15
  202. package/dist/utilities/isValidStringID.spec.js.map +0 -1
  203. package/dist/utilities/validateIdentifierLength.spec.js +0 -19
  204. package/dist/utilities/validateIdentifierLength.spec.js.map +0 -1
@@ -1,897 +0,0 @@
1
- import { getTableName } from 'drizzle-orm';
2
- import { pgEnum, pgTable, serial } from 'drizzle-orm/pg-core';
3
- import { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core';
4
- import { flattenAllFields } from 'payload';
5
- import toSnakeCase from 'to-snake-case';
6
- import { describe, expect, it } from 'vitest';
7
- import { createPolymorphicJoinWherePlan } from './createPolymorphicJoinWherePlan.js';
8
- const articlesTable = sqliteTable('join_articles', {
9
- id: integer('id').primaryKey(),
10
- details_status: text('details_status_flat'),
11
- score: integer('score'),
12
- status: text('status'),
13
- variantKind: text('variant_kind'),
14
- variantRadio: text('variant_radio'),
15
- variantRadioMismatch: text('variant_radio_mismatch'),
16
- title: text('title'),
17
- variantSelect: text('variant_select'),
18
- variantSelectMismatch: text('variant_select_mismatch'),
19
- variantValue: text('variant_value')
20
- });
21
- const notesTable = sqliteTable('join_notes', {
22
- id: integer('id').primaryKey(),
23
- details_status: text('details_status_flat'),
24
- status: text('status'),
25
- variantKind: text('variant_kind'),
26
- variantRadio: integer('variant_radio'),
27
- variantRadioMismatch: integer('variant_radio_mismatch'),
28
- title: text('title'),
29
- variantSelect: integer('variant_select'),
30
- variantSelectMismatch: integer('variant_select_mismatch'),
31
- variantTags: text('variant_tags'),
32
- variantValue: integer('variant_value')
33
- });
34
- const articleSelectEnum = pgEnum('join_plan_article_select', [
35
- 'available',
36
- 'reviewed'
37
- ]);
38
- const articleRadioEnum = pgEnum('join_plan_article_radio', [
39
- 'draft',
40
- 'published'
41
- ]);
42
- const noteSelectEnum = pgEnum('join_plan_note_select', [
43
- 'available',
44
- 'reviewed'
45
- ]);
46
- const noteRadioEnum = pgEnum('join_plan_note_radio', [
47
- 'draft',
48
- 'published'
49
- ]);
50
- const postgresArticlesTable = pgTable('join_plan_articles', {
51
- id: serial('id').primaryKey(),
52
- variantRadio: articleRadioEnum('variant_radio'),
53
- variantSelect: articleSelectEnum('variant_select')
54
- });
55
- const postgresNotesTable = pgTable('join_plan_notes', {
56
- id: serial('id').primaryKey(),
57
- variantRadio: noteRadioEnum('variant_radio'),
58
- variantSelect: noteSelectEnum('variant_select')
59
- });
60
- const articleFields = [
61
- {
62
- name: 'title',
63
- type: 'text'
64
- },
65
- {
66
- name: 'score',
67
- type: 'number'
68
- },
69
- {
70
- name: 'details',
71
- type: 'group',
72
- fields: [
73
- {
74
- name: 'status',
75
- type: 'text'
76
- },
77
- {
78
- hasMany: true,
79
- name: 'tags',
80
- options: [
81
- 'available'
82
- ],
83
- type: 'select'
84
- }
85
- ]
86
- },
87
- {
88
- name: 'details_status',
89
- type: 'text'
90
- },
91
- {
92
- name: 'status',
93
- type: 'text'
94
- },
95
- {
96
- hasMany: true,
97
- name: 'variantTags',
98
- options: [
99
- 'available'
100
- ],
101
- type: 'select'
102
- },
103
- {
104
- name: 'variantKind',
105
- options: [
106
- 'available'
107
- ],
108
- type: 'select'
109
- },
110
- {
111
- name: 'variantRadio',
112
- options: [
113
- {
114
- label: 'Available',
115
- value: 'available'
116
- },
117
- 'reviewed'
118
- ],
119
- type: 'radio'
120
- },
121
- {
122
- name: 'variantRadioMismatch',
123
- options: [
124
- 'available',
125
- 'reviewed'
126
- ],
127
- type: 'radio'
128
- },
129
- {
130
- name: 'variantSelect',
131
- options: [
132
- 'available',
133
- 'reviewed'
134
- ],
135
- type: 'select'
136
- },
137
- {
138
- name: 'variantSelectMismatch',
139
- options: [
140
- 'available',
141
- 'reviewed'
142
- ],
143
- type: 'select'
144
- },
145
- {
146
- name: 'variantValue',
147
- type: 'text'
148
- },
149
- {
150
- localized: true,
151
- name: 'localizedTitle',
152
- type: 'text'
153
- },
154
- {
155
- name: 'entries',
156
- type: 'array',
157
- fields: [
158
- {
159
- hasMany: true,
160
- name: 'tags',
161
- options: [
162
- 'available'
163
- ],
164
- type: 'select'
165
- }
166
- ]
167
- },
168
- {
169
- name: 'content',
170
- type: 'blocks',
171
- blocks: [
172
- {
173
- slug: 'hero',
174
- fields: [
175
- {
176
- hasMany: true,
177
- name: 'tags',
178
- options: [
179
- 'available'
180
- ],
181
- type: 'select'
182
- }
183
- ]
184
- }
185
- ]
186
- }
187
- ];
188
- const noteFields = [
189
- {
190
- name: 'title',
191
- type: 'text'
192
- },
193
- {
194
- name: 'details',
195
- type: 'group',
196
- fields: [
197
- {
198
- name: 'status',
199
- type: 'text'
200
- },
201
- {
202
- hasMany: true,
203
- name: 'tags',
204
- options: [
205
- 'available'
206
- ],
207
- type: 'select'
208
- }
209
- ]
210
- },
211
- {
212
- name: 'details_status',
213
- type: 'text'
214
- },
215
- {
216
- name: 'status',
217
- type: 'text'
218
- },
219
- {
220
- name: 'variantTags',
221
- options: [
222
- 'available'
223
- ],
224
- type: 'select'
225
- },
226
- {
227
- name: 'variantKind',
228
- options: [
229
- 'available'
230
- ],
231
- type: 'radio'
232
- },
233
- {
234
- name: 'variantRadio',
235
- options: [
236
- {
237
- label: 'Different label',
238
- value: 'available'
239
- },
240
- 'reviewed'
241
- ],
242
- type: 'radio'
243
- },
244
- {
245
- name: 'variantRadioMismatch',
246
- options: [
247
- 'reviewed',
248
- 'available'
249
- ],
250
- type: 'radio'
251
- },
252
- {
253
- name: 'variantSelect',
254
- options: [
255
- 'available',
256
- 'reviewed'
257
- ],
258
- type: 'select'
259
- },
260
- {
261
- name: 'variantSelectMismatch',
262
- options: [
263
- 'reviewed',
264
- 'available'
265
- ],
266
- type: 'select'
267
- },
268
- {
269
- name: 'variantValue',
270
- type: 'number'
271
- }
272
- ];
273
- const articleEnumFields = [
274
- {
275
- name: 'variantSelect',
276
- options: [
277
- 'available',
278
- {
279
- label: 'Reviewed',
280
- value: 'reviewed'
281
- }
282
- ],
283
- type: 'select'
284
- },
285
- {
286
- name: 'variantRadio',
287
- options: [
288
- 'draft',
289
- 'published'
290
- ],
291
- type: 'radio'
292
- }
293
- ];
294
- const noteEnumFields = [
295
- {
296
- name: 'variantSelect',
297
- options: [
298
- {
299
- label: 'Available',
300
- value: 'available'
301
- },
302
- 'reviewed'
303
- ],
304
- type: 'select'
305
- },
306
- {
307
- name: 'variantRadio',
308
- options: [
309
- {
310
- label: 'Draft',
311
- value: 'draft'
312
- },
313
- {
314
- label: 'Published',
315
- value: 'published'
316
- }
317
- ],
318
- type: 'radio'
319
- }
320
- ];
321
- const createAdapter = (fixtures)=>{
322
- const collections = {};
323
- const tableNameMap = new Map();
324
- const tables = {};
325
- for (const [slug, fixture] of Object.entries(fixtures)){
326
- const tableName = getTableName(fixture.table);
327
- collections[slug] = {
328
- config: {
329
- fields: fixture.fields,
330
- flattenedFields: flattenAllFields({
331
- fields: fixture.fields
332
- })
333
- }
334
- };
335
- tableNameMap.set(toSnakeCase(slug), tableName);
336
- tables[tableName] = fixture.table;
337
- }
338
- return {
339
- idType: 'serial',
340
- payload: {
341
- collections
342
- },
343
- tableNameMap,
344
- tables
345
- };
346
- };
347
- const adapter = createAdapter({
348
- articles: {
349
- fields: articleFields,
350
- table: articlesTable
351
- },
352
- notes: {
353
- fields: noteFields,
354
- table: notesTable
355
- }
356
- });
357
- const createPlan = (where, collections = [
358
- 'articles',
359
- 'notes'
360
- ])=>createPolymorphicJoinWherePlan({
361
- adapter,
362
- collections,
363
- where
364
- });
365
- describe('createPolymorphicJoinWherePlan', ()=>{
366
- it('creates one scalar plan per unique field in nested boolean clauses', ()=>{
367
- const plan = createPlan({
368
- AND: [
369
- {
370
- title: {
371
- equals: 'available'
372
- }
373
- },
374
- {
375
- 'details.status': {
376
- equals: 'reviewed'
377
- }
378
- },
379
- {
380
- OR: [
381
- {
382
- score: {
383
- greater_than: 1
384
- }
385
- },
386
- {
387
- title: {
388
- not_equals: 'restricted'
389
- }
390
- }
391
- ]
392
- }
393
- ]
394
- });
395
- expect([
396
- ...plan.keys()
397
- ]).toEqual([
398
- 'title',
399
- 'details.status',
400
- 'score'
401
- ]);
402
- expect(plan.get('title')).toMatchObject({
403
- columnPath: 'title',
404
- schemaPath: 'title',
405
- type: 'scalar'
406
- });
407
- expect([
408
- ...plan.get('title').fieldsByCollection.keys()
409
- ]).toEqual([
410
- 'articles',
411
- 'notes'
412
- ]);
413
- expect(plan.get('details.status')).toMatchObject({
414
- columnPath: 'details_status',
415
- type: 'scalar'
416
- });
417
- expect([
418
- ...plan.get('score').fieldsByCollection.keys()
419
- ]).toEqual([
420
- 'articles'
421
- ]);
422
- });
423
- it('creates scalar plans for id and relationTo without configured fields', ()=>{
424
- const plan = createPlan({
425
- id: {
426
- in: [
427
- 1,
428
- 2
429
- ]
430
- },
431
- relationTo: {
432
- equals: 'articles'
433
- }
434
- });
435
- expect(plan.get('id')).toMatchObject({
436
- columnPath: 'id',
437
- type: 'scalar'
438
- });
439
- expect([
440
- ...plan.get('id').fieldsByCollection.keys()
441
- ]).toEqual([
442
- 'articles',
443
- 'notes'
444
- ]);
445
- expect(plan.get('relationTo')).toMatchObject({
446
- columnPath: 'relationTo',
447
- type: 'scalar'
448
- });
449
- expect(plan.get('relationTo').fieldsByCollection.size).toBe(0);
450
- });
451
- it('uses a synthetic UUID field context for an id path without a configured id field', ()=>{
452
- const uuidTable = sqliteTable('uuid_articles', {
453
- id: text('id').primaryKey()
454
- });
455
- const uuidAdapter = createAdapter({
456
- articles: {
457
- fields: [],
458
- table: uuidTable
459
- }
460
- });
461
- uuidAdapter.idType = 'uuid';
462
- const idPlan = createPolymorphicJoinWherePlan({
463
- adapter: uuidAdapter,
464
- collections: [
465
- 'articles'
466
- ],
467
- where: {
468
- id: {
469
- equals: '01991f04-1780-7000-8000-000000000001'
470
- }
471
- }
472
- }).get('id');
473
- expect(idPlan.fieldsByCollection.get('articles')).toMatchObject({
474
- field: {
475
- name: 'id',
476
- type: 'text'
477
- },
478
- isUUID: true,
479
- type: 'scalar'
480
- });
481
- });
482
- it('keeps a scalar path valid when it is absent from one target collection', ()=>{
483
- const scorePlan = createPlan({
484
- score: {
485
- equals: 5
486
- }
487
- }).get('score');
488
- expect(scorePlan.type).toBe('scalar');
489
- expect([
490
- ...scorePlan.fieldsByCollection.keys()
491
- ]).toEqual([
492
- 'articles'
493
- ]);
494
- });
495
- it('creates a hasManySelect plan when the field uses separate value rows', ()=>{
496
- const tagsPlan = createPlan({
497
- 'details.tags': {
498
- contains: 'available'
499
- }
500
- }).get('details.tags');
501
- expect(tagsPlan).toMatchObject({
502
- columnPath: 'details_tags',
503
- schemaPath: 'details.tags',
504
- type: 'hasManySelect'
505
- });
506
- expect([
507
- ...tagsPlan.fieldsByCollection.values()
508
- ]).toEqual([
509
- expect.objectContaining({
510
- field: expect.objectContaining({
511
- name: 'tags'
512
- }),
513
- type: 'hasManySelect'
514
- }),
515
- expect.objectContaining({
516
- field: expect.objectContaining({
517
- name: 'tags'
518
- }),
519
- type: 'hasManySelect'
520
- })
521
- ]);
522
- });
523
- it('accepts matching select fields even when their database column types differ', ()=>{
524
- const selectPlan = createPlan({
525
- variantSelect: {
526
- equals: 'available'
527
- }
528
- }).get('variantSelect');
529
- expect(selectPlan.type).toBe('scalar');
530
- expect([
531
- ...selectPlan.fieldsByCollection.keys()
532
- ]).toEqual([
533
- 'articles',
534
- 'notes'
535
- ]);
536
- });
537
- it('accepts text and textarea fields that use the same query value coercion', ()=>{
538
- const fieldsWithTextarea = noteFields.map((field)=>field.name === 'title' ? {
539
- ...field,
540
- type: 'textarea'
541
- } : field);
542
- const compatibleAdapter = createAdapter({
543
- articles: {
544
- fields: articleFields,
545
- table: articlesTable
546
- },
547
- notes: {
548
- fields: fieldsWithTextarea,
549
- table: notesTable
550
- }
551
- });
552
- const titlePlan = createPolymorphicJoinWherePlan({
553
- adapter: compatibleAdapter,
554
- collections: [
555
- 'articles',
556
- 'notes'
557
- ],
558
- where: {
559
- title: {
560
- equals: 'available'
561
- }
562
- }
563
- }).get('title');
564
- expect(titlePlan.type).toBe('scalar');
565
- });
566
- it.each([
567
- [
568
- 'select',
569
- 'variantSelect',
570
- 'available'
571
- ],
572
- [
573
- 'radio',
574
- 'variantRadio',
575
- 'draft'
576
- ]
577
- ])('accepts PostgreSQL %s fields with separate enum types and matching option values', (_fieldType, schemaPath, value)=>{
578
- const postgresAdapter = createAdapter({
579
- articles: {
580
- fields: articleEnumFields,
581
- table: postgresArticlesTable
582
- },
583
- notes: {
584
- fields: noteEnumFields,
585
- table: postgresNotesTable
586
- }
587
- });
588
- const fieldPlan = createPolymorphicJoinWherePlan({
589
- adapter: postgresAdapter,
590
- collections: [
591
- 'articles',
592
- 'notes'
593
- ],
594
- where: {
595
- [schemaPath]: {
596
- equals: value
597
- }
598
- }
599
- }).get(schemaPath);
600
- expect(fieldPlan.type).toBe('scalar');
601
- expect([
602
- ...fieldPlan.fieldsByCollection.keys()
603
- ]).toEqual([
604
- 'articles',
605
- 'notes'
606
- ]);
607
- });
608
- it.each([
609
- [
610
- 'select',
611
- 'variantSelect',
612
- [
613
- 'available',
614
- 'restricted'
615
- ]
616
- ],
617
- [
618
- 'select',
619
- 'variantSelect',
620
- [
621
- 'reviewed',
622
- 'available'
623
- ]
624
- ],
625
- [
626
- 'radio',
627
- 'variantRadio',
628
- [
629
- 'draft',
630
- 'restricted'
631
- ]
632
- ],
633
- [
634
- 'radio',
635
- 'variantRadio',
636
- [
637
- 'published',
638
- 'draft'
639
- ]
640
- ]
641
- ])('rejects PostgreSQL %s fields whose option values differ or use a different order', (fieldType, schemaPath, options)=>{
642
- const noteFieldsWithDifferentOptions = noteEnumFields.map((field)=>field.name === schemaPath ? {
643
- ...field,
644
- options: [
645
- ...options
646
- ],
647
- type: fieldType
648
- } : field);
649
- const postgresAdapter = createAdapter({
650
- articles: {
651
- fields: articleEnumFields,
652
- table: postgresArticlesTable
653
- },
654
- notes: {
655
- fields: noteFieldsWithDifferentOptions,
656
- table: postgresNotesTable
657
- }
658
- });
659
- const fieldPlan = createPolymorphicJoinWherePlan({
660
- adapter: postgresAdapter,
661
- collections: [
662
- 'articles',
663
- 'notes'
664
- ],
665
- where: {
666
- [schemaPath]: {
667
- equals: options[0]
668
- }
669
- }
670
- }).get(schemaPath);
671
- expect(fieldPlan.type).toBe('invalid');
672
- });
673
- it('accepts matching radio option values even when labels and database column types differ', ()=>{
674
- const radioPlan = createPlan({
675
- variantRadio: {
676
- equals: 'available'
677
- }
678
- }).get('variantRadio');
679
- expect(radioPlan.type).toBe('scalar');
680
- expect([
681
- ...radioPlan.fieldsByCollection.keys()
682
- ]).toEqual([
683
- 'articles',
684
- 'notes'
685
- ]);
686
- });
687
- it.each([
688
- [
689
- 'a field that is absent from every collection',
690
- {
691
- unknown: {
692
- equals: 'value'
693
- }
694
- },
695
- 'unknown'
696
- ],
697
- [
698
- 'incompatible scalar field types',
699
- {
700
- variantValue: {
701
- equals: 'value'
702
- }
703
- },
704
- 'variantValue'
705
- ],
706
- [
707
- 'select fields with differently ordered option values',
708
- {
709
- variantSelectMismatch: {
710
- equals: 'available'
711
- }
712
- },
713
- 'variantSelectMismatch'
714
- ],
715
- [
716
- 'radio fields with differently ordered option values',
717
- {
718
- variantRadioMismatch: {
719
- equals: 'available'
720
- }
721
- },
722
- 'variantRadioMismatch'
723
- ],
724
- [
725
- 'a select field mixed with a radio field',
726
- {
727
- variantKind: {
728
- equals: 'available'
729
- }
730
- },
731
- 'variantKind'
732
- ],
733
- [
734
- 'a has-many select mixed with a scalar select',
735
- {
736
- variantTags: {
737
- contains: 'available'
738
- }
739
- },
740
- 'variantTags'
741
- ],
742
- [
743
- 'a localized field',
744
- {
745
- localizedTitle: {
746
- equals: 'value'
747
- }
748
- },
749
- 'localizedTitle'
750
- ],
751
- [
752
- 'a field stored in array rows',
753
- {
754
- 'entries.tags': {
755
- equals: 'value'
756
- }
757
- },
758
- 'entries.tags'
759
- ],
760
- [
761
- 'a field stored in block rows',
762
- {
763
- 'content.hero.tags': {
764
- equals: 'value'
765
- }
766
- },
767
- 'content.hero.tags'
768
- ]
769
- ])('marks %s as invalid', (_description, where, schemaPath)=>{
770
- expect(createPlan(where).get(schemaPath)).toMatchObject({
771
- type: 'invalid'
772
- });
773
- });
774
- it('marks both schema paths as invalid when they resolve to the same flattened column path', ()=>{
775
- const plan = createPlan({
776
- 'details.status': {
777
- equals: 'available'
778
- },
779
- details_status: {
780
- equals: 'available'
781
- }
782
- });
783
- expect(plan.get('details.status')).toMatchObject({
784
- columnPath: 'details_status',
785
- type: 'invalid'
786
- });
787
- expect(plan.get('details_status')).toMatchObject({
788
- columnPath: 'details_status',
789
- type: 'invalid'
790
- });
791
- });
792
- it('marks a configured scalar field as invalid when its table column is missing', ()=>{
793
- const tableWithoutTitle = sqliteTable('articles_without_title', {
794
- id: integer('id').primaryKey()
795
- });
796
- const adapterWithoutTitle = createAdapter({
797
- articles: {
798
- fields: [
799
- {
800
- name: 'title',
801
- type: 'text'
802
- }
803
- ],
804
- table: tableWithoutTitle
805
- }
806
- });
807
- const plan = createPolymorphicJoinWherePlan({
808
- adapter: adapterWithoutTitle,
809
- collections: [
810
- 'articles'
811
- ],
812
- where: {
813
- title: {
814
- equals: 'available'
815
- }
816
- }
817
- });
818
- expect(plan.get('title')).toMatchObject({
819
- type: 'invalid'
820
- });
821
- });
822
- it('marks an id path as invalid when a target table has no id column', ()=>{
823
- const tableWithoutID = sqliteTable('articles_without_id', {
824
- title: text('title')
825
- });
826
- const adapterWithoutID = createAdapter({
827
- articles: {
828
- fields: [
829
- {
830
- name: 'title',
831
- type: 'text'
832
- }
833
- ],
834
- table: tableWithoutID
835
- }
836
- });
837
- const plan = createPolymorphicJoinWherePlan({
838
- adapter: adapterWithoutID,
839
- collections: [
840
- 'articles'
841
- ],
842
- where: {
843
- id: {
844
- equals: 1
845
- }
846
- }
847
- });
848
- expect(plan.get('id')).toMatchObject({
849
- type: 'invalid'
850
- });
851
- });
852
- it('marks every requested path as invalid when there are no target collections', ()=>{
853
- expect(createPlan({
854
- title: {
855
- equals: 'available'
856
- }
857
- }, []).get('title')).toMatchObject({
858
- type: 'invalid'
859
- });
860
- });
861
- it('throws a descriptive error when a target collection is not configured', ()=>{
862
- expect(()=>createPlan({
863
- title: {
864
- equals: 'available'
865
- }
866
- }, [
867
- 'missing'
868
- ])).toThrow('Unknown polymorphic join collection "missing"');
869
- });
870
- it('throws a descriptive error when a configured collection has no database table', ()=>{
871
- const adapterWithoutTable = createAdapter({
872
- articles: {
873
- fields: [
874
- {
875
- name: 'title',
876
- type: 'text'
877
- }
878
- ],
879
- table: articlesTable
880
- }
881
- });
882
- adapterWithoutTable.tables = {};
883
- expect(()=>createPolymorphicJoinWherePlan({
884
- adapter: adapterWithoutTable,
885
- collections: [
886
- 'articles'
887
- ],
888
- where: {
889
- title: {
890
- equals: 'available'
891
- }
892
- }
893
- })).toThrow('Polymorphic join collection "articles" has no database table');
894
- });
895
- });
896
-
897
- //# sourceMappingURL=createPolymorphicJoinWherePlan.spec.js.map