@webiny/api-headless-cms-ddb-es 5.40.0-beta.1 → 5.40.0-beta.3

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 (106) hide show
  1. package/configurations.js +1 -2
  2. package/configurations.js.map +1 -1
  3. package/definitions/entry.js +30 -0
  4. package/definitions/entry.js.map +1 -1
  5. package/definitions/entryElasticsearch.js.map +1 -1
  6. package/definitions/group.js.map +1 -1
  7. package/definitions/model.js.map +1 -1
  8. package/definitions/system.js.map +1 -1
  9. package/definitions/table.d.ts +2 -2
  10. package/definitions/table.js.map +1 -1
  11. package/definitions/tableElasticsearch.d.ts +2 -2
  12. package/definitions/tableElasticsearch.js.map +1 -1
  13. package/dynamoDb/index.js.map +1 -1
  14. package/dynamoDb/storage/date.js.map +1 -1
  15. package/dynamoDb/storage/longText.js.map +1 -1
  16. package/dynamoDb/storage/richText.js +2 -1
  17. package/dynamoDb/storage/richText.js.map +1 -1
  18. package/elasticsearch/createElasticsearchIndex.js.map +1 -1
  19. package/elasticsearch/deleteElasticsearchIndex.js.map +1 -1
  20. package/elasticsearch/index.js.map +1 -1
  21. package/elasticsearch/indexing/dateTimeIndexing.js.map +1 -1
  22. package/elasticsearch/indexing/defaultFieldIndexing.js.map +1 -1
  23. package/elasticsearch/indexing/index.js.map +1 -1
  24. package/elasticsearch/indexing/jsonIndexing.js.map +1 -1
  25. package/elasticsearch/indexing/longTextIndexing.js.map +1 -1
  26. package/elasticsearch/indexing/numberIndexing.js.map +1 -1
  27. package/elasticsearch/indexing/objectIndexing.js.map +1 -1
  28. package/elasticsearch/indexing/richTextIndexing.js.map +1 -1
  29. package/elasticsearch/indices/base.js +1 -2
  30. package/elasticsearch/indices/base.js.map +1 -1
  31. package/elasticsearch/indices/index.js.map +1 -1
  32. package/elasticsearch/indices/japanese.js +1 -2
  33. package/elasticsearch/indices/japanese.js.map +1 -1
  34. package/elasticsearch/search/index.js.map +1 -1
  35. package/elasticsearch/search/refSearch.js.map +1 -1
  36. package/elasticsearch/search/timeSearch.js.map +1 -1
  37. package/helpers/entryIndexHelpers.js.map +1 -1
  38. package/helpers/fieldIdentifier.js.map +1 -1
  39. package/helpers/index.js.map +1 -1
  40. package/index.js.map +1 -1
  41. package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -1
  42. package/operations/entry/dataLoader/constants.js +1 -2
  43. package/operations/entry/dataLoader/constants.js.map +1 -1
  44. package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -1
  45. package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -1
  46. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -1
  47. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -1
  48. package/operations/entry/dataLoader/getRevisionById.js.map +1 -1
  49. package/operations/entry/dataLoader/index.js.map +1 -1
  50. package/operations/entry/dataLoader/types.js.map +1 -1
  51. package/operations/entry/dataLoaders.js.map +1 -1
  52. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js.map +1 -1
  53. package/operations/entry/elasticsearch/body.js.map +1 -1
  54. package/operations/entry/elasticsearch/fields.js +28 -0
  55. package/operations/entry/elasticsearch/fields.js.map +1 -1
  56. package/operations/entry/elasticsearch/filtering/applyFiltering.js.map +1 -1
  57. package/operations/entry/elasticsearch/filtering/exec.js.map +1 -1
  58. package/operations/entry/elasticsearch/filtering/index.js.map +1 -1
  59. package/operations/entry/elasticsearch/filtering/path.js.map +1 -1
  60. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js.map +1 -1
  61. package/operations/entry/elasticsearch/filtering/plugins/index.js.map +1 -1
  62. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js.map +1 -1
  63. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js.map +1 -1
  64. package/operations/entry/elasticsearch/filtering/populated.js.map +1 -1
  65. package/operations/entry/elasticsearch/filtering/values.js.map +1 -1
  66. package/operations/entry/elasticsearch/fullTextSearch.js.map +1 -1
  67. package/operations/entry/elasticsearch/fullTextSearchFields.js.map +1 -1
  68. package/operations/entry/elasticsearch/initialQuery.js.map +1 -1
  69. package/operations/entry/elasticsearch/keyword.js.map +1 -1
  70. package/operations/entry/elasticsearch/plugins/bodyModifier.js.map +1 -1
  71. package/operations/entry/elasticsearch/plugins/operator.js.map +1 -1
  72. package/operations/entry/elasticsearch/plugins/queryModifier.js.map +1 -1
  73. package/operations/entry/elasticsearch/plugins/search.js.map +1 -1
  74. package/operations/entry/elasticsearch/plugins/sortModifier.js.map +1 -1
  75. package/operations/entry/elasticsearch/sort.js.map +1 -1
  76. package/operations/entry/elasticsearch/transformValueForSearch.js.map +1 -1
  77. package/operations/entry/elasticsearch/types.js.map +1 -1
  78. package/operations/entry/index.js +308 -2
  79. package/operations/entry/index.js.map +1 -1
  80. package/operations/entry/keys.js.map +1 -1
  81. package/operations/entry/recordType.js.map +1 -1
  82. package/operations/entry/transformations/convertEntryKeys.js.map +1 -1
  83. package/operations/entry/transformations/index.js.map +1 -1
  84. package/operations/entry/transformations/modifyEntryValues.d.ts +10 -0
  85. package/operations/entry/transformations/modifyEntryValues.js.map +1 -1
  86. package/operations/entry/transformations/transformEntryKeys.js.map +1 -1
  87. package/operations/entry/transformations/transformEntryToIndex.js.map +1 -1
  88. package/operations/group/index.js.map +1 -1
  89. package/operations/model/index.js.map +1 -1
  90. package/operations/system/index.js.map +1 -1
  91. package/operations/system/indexes.js.map +1 -1
  92. package/package.json +29 -29
  93. package/plugins/CmsElasticsearchModelFieldPlugin.js.map +1 -1
  94. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js.map +1 -1
  95. package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.js.map +1 -1
  96. package/plugins/CmsEntryElasticsearchIndexPlugin.js.map +1 -1
  97. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js.map +1 -1
  98. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js.map +1 -1
  99. package/plugins/CmsEntryElasticsearchSortModifierPlugin.js.map +1 -1
  100. package/plugins/CmsEntryElasticsearchValuesModifier.js.map +1 -1
  101. package/plugins/CmsEntryFilterPlugin.js.map +1 -1
  102. package/plugins/index.js.map +1 -1
  103. package/tasks/createIndexTaskPlugin.js.map +1 -1
  104. package/types.d.ts +2 -2
  105. package/types.js +1 -2
  106. package/types.js.map +1 -1
@@ -557,6 +557,310 @@ const createEntriesStorageOperations = params => {
557
557
  });
558
558
  }
559
559
  };
560
+ const moveToBin = async (initialModel, params) => {
561
+ const {
562
+ entry: initialEntry,
563
+ storageEntry: initialStorageEntry
564
+ } = params;
565
+ const model = getStorageOperationsModel(initialModel);
566
+ const transformer = (0, _transformations.createTransformer)({
567
+ plugins,
568
+ model,
569
+ entry: initialEntry,
570
+ storageEntry: initialStorageEntry
571
+ });
572
+ const {
573
+ entry,
574
+ storageEntry
575
+ } = transformer.transformEntryKeys();
576
+ const partitionKey = (0, _keys.createPartitionKey)({
577
+ id: entry.id,
578
+ locale: model.locale,
579
+ tenant: model.tenant
580
+ });
581
+
582
+ /**
583
+ * First we need to fetch all the records in the regular DynamoDB table.
584
+ */
585
+ const queryAllParams = {
586
+ entity,
587
+ partitionKey,
588
+ options: {
589
+ gte: " "
590
+ }
591
+ };
592
+ const latestSortKey = (0, _keys.createLatestSortKey)();
593
+ const publishedSortKey = (0, _keys.createPublishedSortKey)();
594
+ const records = await (0, _query.queryAll)(queryAllParams);
595
+
596
+ /**
597
+ * Let's pick the `deleted` meta fields from the entry.
598
+ */
599
+ const updatedEntryMetaFields = (0, _constants.pickEntryMetaFields)(entry, _constants.isDeletedEntryMetaField);
600
+
601
+ /**
602
+ * Then update all the records with data received.
603
+ */
604
+ let latestRecord = undefined;
605
+ let publishedRecord = undefined;
606
+ const items = [];
607
+ for (const record of records) {
608
+ items.push(entity.putBatch({
609
+ ...record,
610
+ ...updatedEntryMetaFields,
611
+ wbyDeleted: storageEntry.wbyDeleted,
612
+ location: storageEntry.location,
613
+ binOriginalFolderId: storageEntry.binOriginalFolderId
614
+ }));
615
+ /**
616
+ * We need to get the published and latest records, so we can update the Elasticsearch.
617
+ */
618
+ if (record.SK === publishedSortKey) {
619
+ publishedRecord = record;
620
+ } else if (record.SK === latestSortKey) {
621
+ latestRecord = record;
622
+ }
623
+ }
624
+
625
+ /**
626
+ * We write the records back to the primary DynamoDB table.
627
+ */
628
+ try {
629
+ await (0, _batchWrite.batchWriteAll)({
630
+ table: entity.table,
631
+ items
632
+ });
633
+ dataLoaders.clearAll({
634
+ model
635
+ });
636
+ } catch (ex) {
637
+ throw new _error.default(ex.message || "Could mark as deleted all entry records from in the DynamoDB table.", ex.code || "MOVE_ENTRY_TO_BIN_ERROR", {
638
+ error: ex,
639
+ entry,
640
+ storageEntry
641
+ });
642
+ }
643
+
644
+ /**
645
+ * We need to get the published and latest records from Elasticsearch.
646
+ */
647
+ const esGetItems = [];
648
+ if (publishedRecord) {
649
+ esGetItems.push(esEntity.getBatch({
650
+ PK: partitionKey,
651
+ SK: publishedSortKey
652
+ }));
653
+ }
654
+ if (latestRecord) {
655
+ esGetItems.push(esEntity.getBatch({
656
+ PK: partitionKey,
657
+ SK: latestSortKey
658
+ }));
659
+ }
660
+ if (esGetItems.length === 0) {
661
+ return;
662
+ }
663
+ const esRecords = await (0, _dbDynamodb.batchReadAll)({
664
+ table: esEntity.table,
665
+ items: esGetItems
666
+ });
667
+ const esItems = (await Promise.all(esRecords.map(async record => {
668
+ if (!record) {
669
+ return null;
670
+ }
671
+ return {
672
+ ...record,
673
+ data: await (0, _apiElasticsearch.decompress)(plugins, record.data)
674
+ };
675
+ }))).filter(Boolean);
676
+ if (esItems.length === 0) {
677
+ return;
678
+ }
679
+
680
+ /**
681
+ * We update all ES records with data received.
682
+ */
683
+ const esUpdateItems = [];
684
+ for (const item of esItems) {
685
+ esUpdateItems.push(esEntity.putBatch({
686
+ ...item,
687
+ data: await (0, _apiElasticsearch.compress)(plugins, {
688
+ ...item.data,
689
+ ...updatedEntryMetaFields,
690
+ wbyDeleted: entry.wbyDeleted,
691
+ location: entry.location,
692
+ binOriginalFolderId: entry.binOriginalFolderId
693
+ })
694
+ }));
695
+ }
696
+
697
+ /**
698
+ * We write the records back to the primary DynamoDB Elasticsearch table.
699
+ */
700
+ try {
701
+ await (0, _batchWrite.batchWriteAll)({
702
+ table: esEntity.table,
703
+ items: esUpdateItems
704
+ });
705
+ } catch (ex) {
706
+ throw new _error.default(ex.message || "Could not mark as deleted entry records from DynamoDB Elasticsearch table.", ex.code || "MOVE_ENTRY_TO_BIN_ERROR", {
707
+ error: ex,
708
+ entry,
709
+ storageEntry
710
+ });
711
+ }
712
+ };
713
+ const restoreFromBin = async (initialModel, params) => {
714
+ const {
715
+ entry: initialEntry,
716
+ storageEntry: initialStorageEntry
717
+ } = params;
718
+ const model = getStorageOperationsModel(initialModel);
719
+ const transformer = (0, _transformations.createTransformer)({
720
+ plugins,
721
+ model,
722
+ entry: initialEntry,
723
+ storageEntry: initialStorageEntry
724
+ });
725
+ const {
726
+ entry,
727
+ storageEntry
728
+ } = transformer.transformEntryKeys();
729
+
730
+ /**
731
+ * Let's pick the `restored` meta fields from the storage entry.
732
+ */
733
+ const updatedEntryMetaFields = (0, _constants.pickEntryMetaFields)(entry, _constants.isRestoredEntryMetaField);
734
+ const partitionKey = (0, _keys.createPartitionKey)({
735
+ id: entry.id,
736
+ locale: model.locale,
737
+ tenant: model.tenant
738
+ });
739
+
740
+ /**
741
+ * First we need to fetch all the records in the regular DynamoDB table.
742
+ */
743
+ const queryAllParams = {
744
+ entity,
745
+ partitionKey,
746
+ options: {
747
+ gte: " "
748
+ }
749
+ };
750
+ const latestSortKey = (0, _keys.createLatestSortKey)();
751
+ const publishedSortKey = (0, _keys.createPublishedSortKey)();
752
+ const records = await (0, _query.queryAll)(queryAllParams);
753
+
754
+ /**
755
+ * Then update all the records with data received.
756
+ */
757
+ let latestRecord = undefined;
758
+ let publishedRecord = undefined;
759
+ const items = [];
760
+ for (const record of records) {
761
+ items.push(entity.putBatch({
762
+ ...record,
763
+ ...updatedEntryMetaFields,
764
+ wbyDeleted: storageEntry.wbyDeleted,
765
+ location: storageEntry.location,
766
+ binOriginalFolderId: storageEntry.binOriginalFolderId
767
+ }));
768
+ /**
769
+ * We need to get the published and latest records, so we can update the Elasticsearch.
770
+ */
771
+ if (record.SK === publishedSortKey) {
772
+ publishedRecord = record;
773
+ } else if (record.SK === latestSortKey) {
774
+ latestRecord = record;
775
+ }
776
+ }
777
+
778
+ /**
779
+ * We write the records back to the primary DynamoDB table.
780
+ */
781
+ try {
782
+ await (0, _batchWrite.batchWriteAll)({
783
+ table: entity.table,
784
+ items
785
+ });
786
+ dataLoaders.clearAll({
787
+ model
788
+ });
789
+ } catch (ex) {
790
+ throw new _error.default(ex.message || "Could not restore all entry records from in the DynamoDB table.", ex.code || "RESTORE_ENTRY_ERROR", {
791
+ error: ex,
792
+ entry,
793
+ storageEntry
794
+ });
795
+ }
796
+
797
+ /**
798
+ * We need to get the published and latest records from Elasticsearch.
799
+ */
800
+ const esGetItems = [];
801
+ if (publishedRecord) {
802
+ esGetItems.push(esEntity.getBatch({
803
+ PK: partitionKey,
804
+ SK: publishedSortKey
805
+ }));
806
+ }
807
+ if (latestRecord) {
808
+ esGetItems.push(esEntity.getBatch({
809
+ PK: partitionKey,
810
+ SK: latestSortKey
811
+ }));
812
+ }
813
+ const esRecords = await (0, _dbDynamodb.batchReadAll)({
814
+ table: esEntity.table,
815
+ items: esGetItems
816
+ });
817
+ const esItems = (await Promise.all(esRecords.map(async record => {
818
+ if (!record) {
819
+ return null;
820
+ }
821
+ return {
822
+ ...record,
823
+ data: await (0, _apiElasticsearch.decompress)(plugins, record.data)
824
+ };
825
+ }))).filter(Boolean);
826
+ if (esItems.length === 0) {
827
+ return initialStorageEntry;
828
+ }
829
+
830
+ /**
831
+ * We update all ES records with data received.
832
+ */
833
+ const esUpdateItems = [];
834
+ for (const item of esItems) {
835
+ esUpdateItems.push(esEntity.putBatch({
836
+ ...item,
837
+ data: await (0, _apiElasticsearch.compress)(plugins, {
838
+ ...item.data,
839
+ ...updatedEntryMetaFields,
840
+ wbyDeleted: entry.wbyDeleted,
841
+ location: entry.location,
842
+ binOriginalFolderId: entry.binOriginalFolderId
843
+ })
844
+ }));
845
+ }
846
+
847
+ /**
848
+ * We write the records back to the primary DynamoDB Elasticsearch table.
849
+ */
850
+ try {
851
+ await (0, _batchWrite.batchWriteAll)({
852
+ table: esEntity.table,
853
+ items: esUpdateItems
854
+ });
855
+ } catch (ex) {
856
+ throw new _error.default(ex.message || "Could not restore entry records from DynamoDB Elasticsearch table.", ex.code || "RESTORE_ENTRY_ERROR", {
857
+ error: ex,
858
+ entry,
859
+ storageEntry
860
+ });
861
+ }
862
+ return initialStorageEntry;
863
+ };
560
864
  const deleteEntry = async (initialModel, params) => {
561
865
  const {
562
866
  entry
@@ -603,7 +907,7 @@ const createEntriesStorageOperations = params => {
603
907
  model
604
908
  });
605
909
  } catch (ex) {
606
- throw new _error.default(ex.message || "Could not delete entry records from DynamoDB table.", ex.code || "DELETE_ENTRY_ERROR", {
910
+ throw new _error.default(ex.message || "Could not destroy entry records from DynamoDB table.", ex.code || "DELETE_ENTRY_ERROR", {
607
911
  error: ex,
608
912
  id
609
913
  });
@@ -614,7 +918,7 @@ const createEntriesStorageOperations = params => {
614
918
  items: deleteEsItems
615
919
  });
616
920
  } catch (ex) {
617
- throw new _error.default(ex.message || "Could not delete entry records from DynamoDB Elasticsearch table.", ex.code || "DELETE_ENTRY_ERROR", {
921
+ throw new _error.default(ex.message || "Could not destroy entry records from DynamoDB Elasticsearch table.", ex.code || "DELETE_ENTRY_ERROR", {
618
922
  error: ex,
619
923
  id
620
924
  });
@@ -1461,6 +1765,8 @@ const createEntriesStorageOperations = params => {
1461
1765
  update,
1462
1766
  move,
1463
1767
  delete: deleteEntry,
1768
+ moveToBin,
1769
+ restoreFromBin,
1464
1770
  deleteRevision,
1465
1771
  deleteMultipleEntries,
1466
1772
  get,