@directus/api 32.0.0 → 32.0.1

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.
@@ -192,6 +192,7 @@ export class ImportService {
192
192
  const extractJSON = StreamArray.withParser();
193
193
  const nestedActionEvents = [];
194
194
  const errorTracker = createErrorTracker();
195
+ const isSingleton = this.schema.collections[collection]?.singleton ?? false;
195
196
  return transaction(this.knex, async (trx) => {
196
197
  const service = getService(collection, {
197
198
  knex: trx,
@@ -205,10 +206,16 @@ export class ImportService {
205
206
  if (errorTracker.shouldStop())
206
207
  return;
207
208
  try {
208
- const result = await service.upsertOne(task.data, {
209
- bypassEmitAction: (params) => nestedActionEvents.push(params),
210
- });
211
- return result;
209
+ if (isSingleton) {
210
+ return await service.upsertSingleton(task.data, {
211
+ bypassEmitAction: (params) => nestedActionEvents.push(params),
212
+ });
213
+ }
214
+ else {
215
+ return await service.upsertOne(task.data, {
216
+ bypassEmitAction: (params) => nestedActionEvents.push(params),
217
+ });
218
+ }
212
219
  }
213
220
  catch (error) {
214
221
  for (const err of toArray(error)) {
@@ -228,6 +235,15 @@ export class ImportService {
228
235
  });
229
236
  stream.pipe(extractJSON);
230
237
  extractJSON.on('data', ({ value }) => {
238
+ if (isSingleton && rowNumber > 1) {
239
+ saveQueue.kill();
240
+ destroyStream(stream);
241
+ destroyStream(extractJSON);
242
+ reject(new InvalidPayloadError({
243
+ reason: `Cannot import multiple records into singleton collection ${collection}`,
244
+ }));
245
+ return;
246
+ }
231
247
  saveQueue.push({ data: value, rowNumber: rowNumber++ });
232
248
  });
233
249
  extractJSON.on('error', (err) => {
@@ -265,6 +281,7 @@ export class ImportService {
265
281
  throw new Error('Failed to create temporary file for import');
266
282
  const nestedActionEvents = [];
267
283
  const errorTracker = createErrorTracker();
284
+ const isSingleton = this.schema.collections[collection]?.singleton ?? false;
268
285
  return transaction(this.knex, async (trx) => {
269
286
  const service = getService(collection, {
270
287
  knex: trx,
@@ -289,10 +306,16 @@ export class ImportService {
289
306
  if (errorTracker.shouldStop())
290
307
  return;
291
308
  try {
292
- const result = await service.upsertOne(task.data, {
293
- bypassEmitAction: (action) => nestedActionEvents.push(action),
294
- });
295
- return result;
309
+ if (isSingleton) {
310
+ return await service.upsertSingleton(task.data, {
311
+ bypassEmitAction: (action) => nestedActionEvents.push(action),
312
+ });
313
+ }
314
+ else {
315
+ return await service.upsertOne(task.data, {
316
+ bypassEmitAction: (action) => nestedActionEvents.push(action),
317
+ });
318
+ }
296
319
  }
297
320
  catch (error) {
298
321
  for (const err of toArray(error)) {
@@ -341,6 +364,14 @@ export class ImportService {
341
364
  }))
342
365
  .on('data', (obj) => {
343
366
  rowNumber++;
367
+ if (isSingleton && rowNumber > 1) {
368
+ saveQueue.kill();
369
+ cleanup(true);
370
+ reject(new InvalidPayloadError({
371
+ reason: `Cannot import multiple records into singleton collection ${collection}`,
372
+ }));
373
+ return;
374
+ }
344
375
  const result = {};
345
376
  for (const field in obj) {
346
377
  if (obj[field] !== undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@directus/api",
3
- "version": "32.0.0",
3
+ "version": "32.0.1",
4
4
  "description": "Directus is a real-time API and App dashboard for managing SQL database content",
5
5
  "keywords": [
6
6
  "directus",
@@ -153,30 +153,30 @@
153
153
  "ws": "8.18.3",
154
154
  "zod": "4.1.12",
155
155
  "zod-validation-error": "4.0.2",
156
- "@directus/app": "14.1.0",
157
156
  "@directus/constants": "14.0.0",
157
+ "@directus/app": "14.1.1",
158
158
  "@directus/errors": "2.0.5",
159
- "@directus/extensions": "3.0.12",
160
- "@directus/env": "5.3.0",
161
- "@directus/extensions-sdk": "17.0.0",
162
- "@directus/extensions-registry": "3.0.12",
159
+ "@directus/env": "5.3.1",
160
+ "@directus/extensions": "3.0.13",
161
+ "@directus/extensions-registry": "3.0.13",
162
+ "@directus/extensions-sdk": "17.0.1",
163
163
  "@directus/format-title": "12.1.1",
164
- "@directus/memory": "3.0.10",
165
- "@directus/pressure": "3.0.10",
166
- "@directus/schema-builder": "0.0.7",
164
+ "@directus/memory": "3.0.11",
165
+ "@directus/pressure": "3.0.11",
166
+ "@directus/schema-builder": "0.0.8",
167
167
  "@directus/schema": "13.0.4",
168
- "@directus/storage": "12.0.3",
169
168
  "@directus/specs": "11.1.1",
170
- "@directus/storage-driver-azure": "12.0.10",
171
- "@directus/storage-driver-cloudinary": "12.0.10",
172
- "@directus/storage-driver-gcs": "12.0.10",
173
- "@directus/storage-driver-s3": "12.0.10",
174
- "@directus/system-data": "3.4.0",
169
+ "@directus/storage": "12.0.3",
170
+ "@directus/storage-driver-azure": "12.0.11",
171
+ "@directus/storage-driver-cloudinary": "12.0.11",
172
+ "@directus/storage-driver-gcs": "12.0.11",
175
173
  "@directus/storage-driver-local": "12.0.3",
176
- "@directus/utils": "13.0.11",
177
- "@directus/storage-driver-supabase": "3.0.10",
178
- "@directus/validation": "2.0.10",
179
- "directus": "11.13.0"
174
+ "@directus/storage-driver-s3": "12.0.11",
175
+ "@directus/storage-driver-supabase": "3.0.11",
176
+ "@directus/system-data": "3.4.1",
177
+ "@directus/utils": "13.0.12",
178
+ "@directus/validation": "2.0.11",
179
+ "directus": "11.13.1"
180
180
  },
181
181
  "devDependencies": {
182
182
  "@directus/tsconfig": "3.0.0",
@@ -219,8 +219,8 @@
219
219
  "knex-mock-client": "3.0.2",
220
220
  "typescript": "5.9.3",
221
221
  "vitest": "3.2.4",
222
- "@directus/types": "13.3.0",
223
- "@directus/schema-builder": "0.0.7"
222
+ "@directus/schema-builder": "0.0.8",
223
+ "@directus/types": "13.3.1"
224
224
  },
225
225
  "optionalDependencies": {
226
226
  "@keyv/redis": "3.0.1",