@igorchugurov/public-api-sdk 1.2.0 → 1.3.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.
- package/LICENSE +1 -0
- package/README.md +24 -3
- package/dist/{client-DS5xnLAo.d.mts → client-D3jtlTId.d.mts} +9 -0
- package/dist/{client-DS5xnLAo.d.ts → client-D3jtlTId.d.ts} +9 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +70 -53
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +70 -53
- package/dist/index.mjs.map +1 -1
- package/dist/server.d.mts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +70 -53
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +70 -53
- package/dist/server.mjs.map +1 -1
- package/package.json +3 -3
package/dist/server.mjs
CHANGED
|
@@ -592,6 +592,22 @@ function flattenInstance(instance, fields, relationsAsIds = false) {
|
|
|
592
592
|
}
|
|
593
593
|
return result;
|
|
594
594
|
}
|
|
595
|
+
function transformEntityFile(row) {
|
|
596
|
+
return {
|
|
597
|
+
id: row.id,
|
|
598
|
+
entityInstanceId: row.entity_instance_id,
|
|
599
|
+
fieldId: row.field_id,
|
|
600
|
+
fileUrl: row.file_url,
|
|
601
|
+
filePath: row.file_path,
|
|
602
|
+
fileName: row.file_name,
|
|
603
|
+
fileSize: row.file_size,
|
|
604
|
+
fileType: row.file_type,
|
|
605
|
+
storageBucket: row.storage_bucket,
|
|
606
|
+
uploadedBy: row.uploaded_by,
|
|
607
|
+
createdAt: row.created_at,
|
|
608
|
+
updatedAt: row.updated_at
|
|
609
|
+
};
|
|
610
|
+
}
|
|
595
611
|
|
|
596
612
|
// src/client.ts
|
|
597
613
|
init_slug();
|
|
@@ -697,6 +713,42 @@ var _PublicAPIClient = class _PublicAPIClient extends BasePublicAPIClient {
|
|
|
697
713
|
getMode() {
|
|
698
714
|
return this.mode;
|
|
699
715
|
}
|
|
716
|
+
/**
|
|
717
|
+
* Загружает файлы для экземпляра и возвращает их как полные объекты EntityFile,
|
|
718
|
+
* сгруппированные по именам полей
|
|
719
|
+
*/
|
|
720
|
+
async loadFilesForInstance(instanceId, fileFields) {
|
|
721
|
+
if (fileFields.length === 0) {
|
|
722
|
+
return /* @__PURE__ */ new Map();
|
|
723
|
+
}
|
|
724
|
+
const { data: allFiles, error: filesError } = await this.supabase.from("entity_file").select("*").eq("entity_instance_id", instanceId);
|
|
725
|
+
if (filesError) {
|
|
726
|
+
throw new SDKError(
|
|
727
|
+
"FILES_LOAD_ERROR",
|
|
728
|
+
`Failed to load files for instance ${instanceId}: ${filesError.message}`,
|
|
729
|
+
500,
|
|
730
|
+
filesError
|
|
731
|
+
);
|
|
732
|
+
}
|
|
733
|
+
if (!allFiles || allFiles.length === 0) {
|
|
734
|
+
return /* @__PURE__ */ new Map();
|
|
735
|
+
}
|
|
736
|
+
const filesMap = /* @__PURE__ */ new Map();
|
|
737
|
+
const fieldIdToName = new Map(
|
|
738
|
+
fileFields.map((f) => [f.id, f.name])
|
|
739
|
+
);
|
|
740
|
+
allFiles.forEach((fileRow) => {
|
|
741
|
+
if (!fileRow.field_id) return;
|
|
742
|
+
const fieldName = fieldIdToName.get(fileRow.field_id);
|
|
743
|
+
if (!fieldName) return;
|
|
744
|
+
const entityFile = transformEntityFile(fileRow);
|
|
745
|
+
if (!filesMap.has(fieldName)) {
|
|
746
|
+
filesMap.set(fieldName, []);
|
|
747
|
+
}
|
|
748
|
+
filesMap.get(fieldName).push(entityFile);
|
|
749
|
+
});
|
|
750
|
+
return filesMap;
|
|
751
|
+
}
|
|
700
752
|
/**
|
|
701
753
|
* Получить один экземпляр
|
|
702
754
|
*/
|
|
@@ -773,34 +825,15 @@ var _PublicAPIClient = class _PublicAPIClient extends BasePublicAPIClient {
|
|
|
773
825
|
}
|
|
774
826
|
}
|
|
775
827
|
}
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
throw new SDKError(
|
|
783
|
-
"FILES_LOAD_ERROR",
|
|
784
|
-
`Failed to load files for instance ${id}: ${filesError.message}`,
|
|
785
|
-
500,
|
|
786
|
-
filesError
|
|
787
|
-
);
|
|
788
|
-
}
|
|
789
|
-
if (allFiles) {
|
|
790
|
-
const filesByFieldId = /* @__PURE__ */ new Map();
|
|
791
|
-
allFiles.forEach((file) => {
|
|
792
|
-
if (file.field_id) {
|
|
793
|
-
if (!filesByFieldId.has(file.field_id)) {
|
|
794
|
-
filesByFieldId.set(file.field_id, []);
|
|
795
|
-
}
|
|
796
|
-
filesByFieldId.get(file.field_id).push(file.id);
|
|
797
|
-
}
|
|
798
|
-
});
|
|
828
|
+
if ((params == null ? void 0 : params.loadFiles) === true) {
|
|
829
|
+
const fileFields = fields.filter(
|
|
830
|
+
(f) => f.type === "files" || f.type === "images"
|
|
831
|
+
);
|
|
832
|
+
if (fileFields.length > 0) {
|
|
833
|
+
const filesMap = await this.loadFilesForInstance(id, fileFields);
|
|
799
834
|
fileFields.forEach((field) => {
|
|
800
|
-
const
|
|
801
|
-
|
|
802
|
-
transformedInstance.data[field.name] = fileIds;
|
|
803
|
-
}
|
|
835
|
+
const files = filesMap.get(field.name) || [];
|
|
836
|
+
transformedInstance.data[field.name] = files;
|
|
804
837
|
});
|
|
805
838
|
}
|
|
806
839
|
}
|
|
@@ -901,34 +934,18 @@ var _PublicAPIClient = class _PublicAPIClient extends BasePublicAPIClient {
|
|
|
901
934
|
}
|
|
902
935
|
}
|
|
903
936
|
}
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
`Failed to load files for instance with slug ${slug}: ${filesError.message}`,
|
|
913
|
-
500,
|
|
914
|
-
filesError
|
|
937
|
+
if ((params == null ? void 0 : params.loadFiles) === true) {
|
|
938
|
+
const fileFields = fields.filter(
|
|
939
|
+
(f) => f.type === "files" || f.type === "images"
|
|
940
|
+
);
|
|
941
|
+
if (fileFields.length > 0) {
|
|
942
|
+
const filesMap = await this.loadFilesForInstance(
|
|
943
|
+
transformedInstance.id,
|
|
944
|
+
fileFields
|
|
915
945
|
);
|
|
916
|
-
}
|
|
917
|
-
if (allFiles) {
|
|
918
|
-
const filesByFieldId = /* @__PURE__ */ new Map();
|
|
919
|
-
allFiles.forEach((file) => {
|
|
920
|
-
if (file.field_id) {
|
|
921
|
-
if (!filesByFieldId.has(file.field_id)) {
|
|
922
|
-
filesByFieldId.set(file.field_id, []);
|
|
923
|
-
}
|
|
924
|
-
filesByFieldId.get(file.field_id).push(file.id);
|
|
925
|
-
}
|
|
926
|
-
});
|
|
927
946
|
fileFields.forEach((field) => {
|
|
928
|
-
const
|
|
929
|
-
|
|
930
|
-
transformedInstance.data[field.name] = fileIds;
|
|
931
|
-
}
|
|
947
|
+
const files = filesMap.get(field.name) || [];
|
|
948
|
+
transformedInstance.data[field.name] = files;
|
|
932
949
|
});
|
|
933
950
|
}
|
|
934
951
|
}
|