@wbce-d9/api 12.7.0 → 12.7.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.
@@ -1,2 +1,2 @@
1
1
  import type { InternalAxiosRequestConfig } from 'axios';
2
- export declare const requestInterceptor: (config: InternalAxiosRequestConfig) => Promise<InternalAxiosRequestConfig<any>>;
2
+ export declare const requestInterceptor: (config: InternalAxiosRequestConfig) => Promise<InternalAxiosRequestConfig<any, any>>;
@@ -1,2 +1,2 @@
1
1
  import type { AxiosResponse } from 'axios';
2
- export declare const responseInterceptor: (config: AxiosResponse<any, any>) => Promise<AxiosResponse<any, any, {}>>;
2
+ export declare const responseInterceptor: (config: AxiosResponse<any, any>) => Promise<AxiosResponse<any, any, {}, any>>;
@@ -478,6 +478,23 @@ export class PayloadService {
478
478
  knex: this.knex,
479
479
  schema: this.schema,
480
480
  });
481
+ const adminItemService = new ItemsService(relation.collection, {
482
+ knex: this.knex,
483
+ schema: this.schema,
484
+ });
485
+ const parentKey = parent || payload[currentPrimaryKeyField];
486
+ // Add the back-reference to the item, unless it is already linked to this parent.
487
+ const attachToParent = async (item) => {
488
+ const key = item[relatedPrimaryKeyField];
489
+ if (key) {
490
+ // readMany rather than readOne: not found is not an error.
491
+ const currentItems = await adminItemService.readMany([key], { fields: [relation.field] });
492
+ if (currentItems.length > 0 && currentItems[0][relation.field] == parentKey) {
493
+ return omit(item, relation.field);
494
+ }
495
+ }
496
+ return { ...item, [relation.field]: parentKey };
497
+ };
481
498
  const recordsToUpsert = [];
482
499
  const savedPrimaryKeys = [];
483
500
  // Nested array of individual items
@@ -512,10 +529,8 @@ export class PayloadService {
512
529
  [relatedPrimaryKeyField]: relatedRecord,
513
530
  };
514
531
  }
515
- recordsToUpsert.push({
516
- ...record,
517
- [relation.field]: parent || payload[currentPrimaryKeyField],
518
- });
532
+ const attachedRecord = await attachToParent(record);
533
+ recordsToUpsert.push(attachedRecord);
519
534
  }
520
535
  savedPrimaryKeys.push(...(await itemsService.upsertMany(recordsToUpsert, {
521
536
  onRevisionCreate: (pk) => revisions.push(pk),
@@ -581,14 +596,14 @@ export class PayloadService {
581
596
  }
582
597
  return {
583
598
  ...record,
584
- [relation.field]: parent || payload[currentPrimaryKeyField],
599
+ [relation.field]: parentKey,
585
600
  };
586
601
  });
587
602
  }
588
603
  else {
589
604
  createPayload = alterations.create.map((item) => ({
590
605
  ...item,
591
- [relation.field]: parent || payload[currentPrimaryKeyField],
606
+ [relation.field]: parentKey,
592
607
  }));
593
608
  }
594
609
  await itemsService.createMany(createPayload, {
@@ -601,10 +616,8 @@ export class PayloadService {
601
616
  if (alterations.update) {
602
617
  const primaryKeyField = this.schema.collections[relation.collection].primary;
603
618
  for (const item of alterations.update) {
604
- await itemsService.updateOne(item[primaryKeyField], {
605
- ...item,
606
- [relation.field]: parent || payload[currentPrimaryKeyField],
607
- }, {
619
+ const attachedItem = await attachToParent(item);
620
+ await itemsService.updateOne(attachedItem[primaryKeyField], attachedItem, {
608
621
  onRevisionCreate: (pk) => revisions.push(pk),
609
622
  bypassEmitAction: (params) => opts?.bypassEmitAction ? opts.bypassEmitAction(params) : nestedActionEvents.push(params),
610
623
  emitEvents: opts?.emitEvents,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wbce-d9/api",
3
- "version": "12.7.0",
3
+ "version": "12.7.1",
4
4
  "description": "Directus is a real-time API and App dashboard for managing SQL database content",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -66,7 +66,7 @@
66
66
  "@rollup/plugin-node-resolve": "15.0.2",
67
67
  "@rollup/plugin-virtual": "3.0.1",
68
68
  "@wbce-d9/format-title": "10.0.0",
69
- "axios": "^1.18.0",
69
+ "axios": "^1.20.0",
70
70
  "chalk": "5.2.0",
71
71
  "commander": "10.0.1",
72
72
  "date-fns": "2.29.3",
@@ -144,20 +144,20 @@
144
144
  "tmp-promise": "3.0.3",
145
145
  "tsx": "3.12.6",
146
146
  "uuid-validate": "0.0.3",
147
- "@wbce-d9/app": "11.2.0",
148
- "@wbce-d9/extensions-sdk": "10.0.5",
147
+ "@wbce-d9/app": "11.3.0",
148
+ "@wbce-d9/constants": "10.0.0",
149
+ "@wbce-d9/extensions-sdk": "10.1.0",
150
+ "@wbce-d9/exceptions": "10.0.1",
149
151
  "@wbce-d9/schema": "10.0.0",
152
+ "@wbce-d9/storage": "10.0.0",
150
153
  "@wbce-d9/specs": "9.26.5",
151
- "@wbce-d9/storage-driver-azure": "10.0.4",
152
- "@wbce-d9/storage-driver-cloudinary": "10.0.5",
153
- "@wbce-d9/storage-driver-local": "10.0.4",
154
- "@wbce-d9/storage-driver-gcs": "10.0.4",
155
- "@wbce-d9/storage-driver-s3": "10.0.4",
154
+ "@wbce-d9/storage-driver-cloudinary": "10.0.6",
155
+ "@wbce-d9/storage-driver-azure": "10.0.5",
156
+ "@wbce-d9/storage-driver-local": "10.0.5",
157
+ "@wbce-d9/utils": "10.0.5",
158
+ "@wbce-d9/storage-driver-s3": "10.0.5",
156
159
  "@wbce-d9/update-check": "10.0.4",
157
- "@wbce-d9/storage": "10.0.0",
158
- "@wbce-d9/utils": "10.0.4",
159
- "@wbce-d9/constants": "10.0.0",
160
- "@wbce-d9/exceptions": "10.0.1"
160
+ "@wbce-d9/storage-driver-gcs": "10.0.5"
161
161
  },
162
162
  "devDependencies": {
163
163
  "@ngneat/falso": "6.4.0",