@elek-io/core 0.10.0 → 0.11.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.
@@ -8,7 +8,7 @@ var __export = (target, all) => {
8
8
  import Fs7 from "fs-extra";
9
9
 
10
10
  // package.json
11
- var version = "0.10.0";
11
+ var version = "0.11.1";
12
12
 
13
13
  // src/schema/assetSchema.ts
14
14
  import z4 from "zod";
@@ -69,39 +69,6 @@ var supportedLanguageSchema = z.enum([
69
69
  // (Simplified) Chinese
70
70
  ]);
71
71
  var supportedIconSchema = z.enum(["home", "plus", "foobar"]);
72
- var supportedAssetMimeTypeSchema = z.enum([
73
- "image/avif",
74
- "image/gif",
75
- "image/jpeg",
76
- "image/png",
77
- "image/svg+xml",
78
- "image/webp",
79
- "application/pdf",
80
- "application/zip",
81
- "video/mp4",
82
- "video/webm",
83
- "audio/webm",
84
- "audio/flac"
85
- ]);
86
- var supportedAssetExtensionSchema = z.enum([
87
- "avif",
88
- "gif",
89
- "jpg",
90
- "jpeg",
91
- "png",
92
- "svg",
93
- "webp",
94
- "pdf",
95
- "zip",
96
- "mp4",
97
- "webm",
98
- "flac",
99
- "json"
100
- ]);
101
- var supportedAssetTypeSchema = z.object({
102
- extension: supportedAssetExtensionSchema,
103
- mimeType: supportedAssetMimeTypeSchema
104
- });
105
72
  var objectTypeSchema = z.enum([
106
73
  "project",
107
74
  "asset",
@@ -151,48 +118,47 @@ var baseFileSchema = z2.object({
151
118
  */
152
119
  updated: z2.string().datetime().nullable()
153
120
  });
154
- var baseFileWithLanguageSchema = baseFileSchema.extend({
155
- /**
156
- * The language of the file
157
- *
158
- * The language is part of the files name and together with it's ID the only unique identifier.
159
- * That's why the language cannot be changed after creating the file.
160
- *
161
- * @todo Maybe remove the above restriction by implementing logic to handle changing the files language inside all services
162
- */
163
- language: supportedLanguageSchema.readonly()
164
- });
165
121
  var fileReferenceSchema = z2.object({
166
122
  id: uuidSchema,
167
- language: supportedLanguageSchema.optional(),
168
- extension: supportedAssetExtensionSchema.optional()
123
+ extension: z2.string().optional()
169
124
  });
170
125
 
171
126
  // src/schema/gitSchema.ts
172
127
  import { z as z3 } from "zod";
173
- var gitRepositoryPathSchema = z3.string();
174
128
  var gitSignatureSchema = z3.object({
175
129
  name: z3.string(),
176
130
  email: z3.string()
177
131
  });
132
+ var gitMessageSchema = z3.object({
133
+ method: z3.enum(["create", "update", "delete", "upgrade"]),
134
+ reference: z3.object({
135
+ objectType: objectTypeSchema,
136
+ /**
137
+ * ID of the objectType
138
+ */
139
+ id: uuidSchema,
140
+ /**
141
+ * Only present if the objectType is of "entry"
142
+ */
143
+ collectionId: uuidSchema.optional()
144
+ })
145
+ });
146
+ var gitTagSchema = z3.object({
147
+ id: uuidSchema,
148
+ message: z3.string(),
149
+ author: gitSignatureSchema,
150
+ datetime: z3.string().datetime()
151
+ });
178
152
  var gitCommitSchema = z3.object({
179
153
  /**
180
154
  * SHA-1 hash of the commit
181
155
  */
182
156
  hash: z3.string(),
183
- message: z3.string(),
157
+ message: gitMessageSchema,
184
158
  author: gitSignatureSchema,
185
159
  datetime: z3.string().datetime(),
186
- tag: z3.string().nullable()
187
- });
188
- var GitCommitIconNative = /* @__PURE__ */ ((GitCommitIconNative2) => {
189
- GitCommitIconNative2["INIT"] = ":tada:";
190
- GitCommitIconNative2["CREATE"] = ":heavy_plus_sign:";
191
- GitCommitIconNative2["UPDATE"] = ":wrench:";
192
- GitCommitIconNative2["DELETE"] = ":heavy_minus_sign:";
193
- return GitCommitIconNative2;
194
- })(GitCommitIconNative || {});
195
- var gitCommitIconSchema = z3.nativeEnum(GitCommitIconNative);
160
+ tag: gitTagSchema.nullable()
161
+ });
196
162
  var gitInitOptionsSchema = z3.object({
197
163
  /**
198
164
  * Use the specified name for the initial branch in the newly created repository. If not specified, fall back to the default name (currently master, but this is subject to change in the future; the name can be customized via the init.defaultBranch configuration variable).
@@ -211,7 +177,19 @@ var gitCloneOptionsSchema = z3.object({
211
177
  /**
212
178
  * Instead of pointing the newly created HEAD to the branch pointed to by the cloned repository’s HEAD, point to <name> branch instead. In a non-bare repository, this is the branch that will be checked out. --branch can also take tags and detaches the HEAD at that commit in the resulting repository.
213
179
  */
214
- branch: z3.string()
180
+ branch: z3.string(),
181
+ /**
182
+ * Make a bare Git repository. That is, instead of creating <directory> and placing the administrative files in <directory>`/.git`, make the <directory> itself the $GIT_DIR.
183
+ * Used primarily to copy an existing local repository to a server, where you want to set up the repository as a central point to work with others.
184
+ *
185
+ * The destination path for the cloned repository should end with a .git by convention.
186
+ *
187
+ * @see https://git-scm.com/book/en/v2/Git-on-the-Server-Getting-Git-on-a-Server
188
+ */
189
+ bare: z3.boolean()
190
+ });
191
+ var gitMergeOptionsSchema = z3.object({
192
+ squash: z3.boolean()
215
193
  });
216
194
  var gitSwitchOptionsSchema = z3.object({
217
195
  /**
@@ -248,14 +226,28 @@ var gitLogOptionsSchema = z3.object({
248
226
  */
249
227
  filePath: z3.string().optional()
250
228
  });
229
+ var createGitTagSchema = gitTagSchema.pick({
230
+ message: true
231
+ }).extend({
232
+ path: z3.string(),
233
+ hash: z3.string().optional()
234
+ });
235
+ var readGitTagSchema = z3.object({
236
+ path: z3.string(),
237
+ id: uuidSchema.readonly()
238
+ });
239
+ var deleteGitTagSchema = readGitTagSchema.extend({});
240
+ var countGitTagsSchema = z3.object({
241
+ path: z3.string()
242
+ });
251
243
 
252
244
  // src/schema/assetSchema.ts
253
245
  var assetFileSchema = baseFileSchema.extend({
254
246
  objectType: z4.literal(objectTypeSchema.Enum.asset).readonly(),
255
247
  name: z4.string(),
256
248
  description: z4.string(),
257
- extension: supportedAssetExtensionSchema.readonly(),
258
- mimeType: supportedAssetMimeTypeSchema.readonly(),
249
+ extension: z4.string().readonly(),
250
+ mimeType: z4.string().readonly(),
259
251
  /**
260
252
  * Total size in bytes
261
253
  */
@@ -331,9 +323,6 @@ var ValueTypeSchema = z5.enum([
331
323
  var valueContentReferenceBase = z5.object({
332
324
  id: uuidSchema
333
325
  });
334
- var valueContentReferenceWithLanguageBase = valueContentReferenceBase.extend({
335
- language: supportedLanguageSchema
336
- });
337
326
  var valueContentReferenceToAssetSchema = valueContentReferenceBase.extend({
338
327
  objectType: z5.literal(objectTypeSchema.Enum.asset)
339
328
  });
@@ -564,7 +553,6 @@ var ReferenceFieldDefinitionBaseSchema = FieldDefinitionBaseSchema.extend({
564
553
  });
565
554
  var assetFieldDefinitionSchema = ReferenceFieldDefinitionBaseSchema.extend({
566
555
  fieldType: z7.literal(FieldTypeSchema.Enum.asset),
567
- allowedMimeTypes: z7.array(supportedAssetMimeTypeSchema).min(1),
568
556
  min: z7.number().nullable(),
569
557
  max: z7.number().nullable()
570
558
  });
@@ -754,39 +742,16 @@ var constructorElekIoCoreSchema = elekIoCoreOptionsSchema.partial({
754
742
  file: true
755
743
  }).optional();
756
744
 
757
- // src/schema/gitTagSchema.ts
758
- import { z as z10 } from "zod";
759
- var gitTagSchema = z10.object({
760
- id: uuidSchema,
761
- message: z10.string(),
762
- author: gitSignatureSchema,
763
- datetime: z10.string().datetime()
764
- });
765
- var createGitTagSchema = gitTagSchema.pick({
766
- message: true
767
- }).extend({
768
- path: gitRepositoryPathSchema,
769
- hash: gitCommitSchema.shape.hash.optional()
770
- });
771
- var readGitTagSchema = z10.object({
772
- path: gitRepositoryPathSchema,
773
- id: uuidSchema.readonly()
774
- });
775
- var deleteGitTagSchema = readGitTagSchema.extend({});
776
- var countGitTagsSchema = z10.object({
777
- path: gitRepositoryPathSchema
778
- });
779
-
780
745
  // src/schema/projectSchema.ts
781
- import { z as z11 } from "zod";
782
- var projectStatusSchema = z11.enum(["foo", "bar", "todo"]);
783
- var projectSettingsSchema = z11.object({
784
- language: z11.object({
746
+ import { z as z10 } from "zod";
747
+ var projectStatusSchema = z10.enum(["foo", "bar", "todo"]);
748
+ var projectSettingsSchema = z10.object({
749
+ language: z10.object({
785
750
  default: supportedLanguageSchema,
786
- supported: z11.array(supportedLanguageSchema)
751
+ supported: z10.array(supportedLanguageSchema)
787
752
  })
788
753
  });
789
- var projectFolderSchema = z11.enum([
754
+ var projectFolderSchema = z10.enum([
790
755
  "assets",
791
756
  "collections",
792
757
  "shared-values",
@@ -795,25 +760,27 @@ var projectFolderSchema = z11.enum([
795
760
  // 'public',
796
761
  // 'theme',
797
762
  ]);
763
+ var projectBranchSchema = z10.enum(["production", "work"]);
798
764
  var projectFileSchema = baseFileSchema.extend({
799
- objectType: z11.literal(objectTypeSchema.Enum.project).readonly(),
765
+ objectType: z10.literal(objectTypeSchema.Enum.project).readonly(),
800
766
  coreVersion: versionSchema,
801
- name: z11.string().trim().min(1, "shared.projectNameRequired"),
802
- description: z11.string().trim().min(1, "shared.projectDescriptionRequired"),
767
+ name: z10.string().trim().min(1, "shared.projectNameRequired"),
768
+ description: z10.string().trim().min(1, "shared.projectDescriptionRequired"),
803
769
  version: versionSchema,
804
770
  status: projectStatusSchema,
805
771
  settings: projectSettingsSchema
806
772
  });
807
773
  var projectSchema = projectFileSchema.extend({
774
+ remoteOriginUrl: z10.string().nullable(),
808
775
  /**
809
776
  * Commit history of this Project
810
777
  */
811
- history: z11.array(gitCommitSchema),
778
+ history: z10.array(gitCommitSchema),
812
779
  /**
813
780
  * Full commit history of this Project
814
781
  * including all Assets, Collections, Entries and other files
815
782
  */
816
- fullHistory: z11.array(gitCommitSchema)
783
+ fullHistory: z10.array(gitCommitSchema)
817
784
  });
818
785
  var outdatedProjectSchema = projectFileSchema.pick({
819
786
  id: true,
@@ -821,8 +788,8 @@ var outdatedProjectSchema = projectFileSchema.pick({
821
788
  coreVersion: true
822
789
  });
823
790
  var projectExportSchema = projectSchema.extend({
824
- assets: z11.array(assetExportSchema),
825
- collections: z11.array(collectionExportSchema)
791
+ assets: z10.array(assetExportSchema),
792
+ collections: z10.array(collectionExportSchema)
826
793
  });
827
794
  var createProjectSchema = projectSchema.pick({
828
795
  name: true,
@@ -832,9 +799,9 @@ var createProjectSchema = projectSchema.pick({
832
799
  description: true,
833
800
  settings: true
834
801
  });
835
- var readProjectSchema = z11.object({
802
+ var readProjectSchema = z10.object({
836
803
  id: uuidSchema.readonly(),
837
- commitHash: z11.string().optional().readonly()
804
+ commitHash: z10.string().optional().readonly()
838
805
  });
839
806
  var updateProjectSchema = projectSchema.pick({
840
807
  id: true,
@@ -846,15 +813,17 @@ var updateProjectSchema = projectSchema.pick({
846
813
  description: true,
847
814
  settings: true
848
815
  });
849
- var upgradeProjectSchema = z11.object({
816
+ var upgradeProjectSchema = z10.object({
850
817
  id: uuidSchema.readonly(),
851
818
  /**
852
819
  * Force the upgrade even if the Project is up-to-date
853
820
  */
854
- force: z11.boolean().optional()
821
+ force: z10.boolean().optional()
822
+ });
823
+ var deleteProjectSchema = readProjectSchema.extend({
824
+ force: z10.boolean().optional()
855
825
  });
856
- var deleteProjectSchema = readProjectSchema.extend({});
857
- var projectUpgradeSchema = z11.object({
826
+ var projectUpgradeSchema = z10.object({
858
827
  /**
859
828
  * The Core version the Project will be upgraded to
860
829
  */
@@ -862,45 +831,45 @@ var projectUpgradeSchema = z11.object({
862
831
  /**
863
832
  * Function that will be executed in the process of upgrading a Project
864
833
  */
865
- run: z11.function().args(projectFileSchema).returns(z11.promise(z11.void()))
834
+ run: z10.function().args(projectFileSchema).returns(z10.promise(z10.void()))
866
835
  });
867
- var cloneProjectSchema = z11.object({
868
- url: z11.string()
836
+ var cloneProjectSchema = z10.object({
837
+ url: z10.string()
869
838
  });
870
- var listBranchesProjectSchema = z11.object({
839
+ var listBranchesProjectSchema = z10.object({
871
840
  id: uuidSchema.readonly()
872
841
  });
873
- var currentBranchProjectSchema = z11.object({
842
+ var currentBranchProjectSchema = z10.object({
874
843
  id: uuidSchema.readonly()
875
844
  });
876
- var switchBranchProjectSchema = z11.object({
845
+ var switchBranchProjectSchema = z10.object({
877
846
  id: uuidSchema.readonly(),
878
- branch: z11.string(),
847
+ branch: z10.string(),
879
848
  options: gitSwitchOptionsSchema.optional()
880
849
  });
881
- var getRemoteOriginUrlProjectSchema = z11.object({
850
+ var getRemoteOriginUrlProjectSchema = z10.object({
882
851
  id: uuidSchema.readonly()
883
852
  });
884
- var setRemoteOriginUrlProjectSchema = z11.object({
853
+ var setRemoteOriginUrlProjectSchema = z10.object({
885
854
  id: uuidSchema.readonly(),
886
- url: z11.string()
855
+ url: z10.string()
887
856
  });
888
- var getChangesProjectSchema = z11.object({
857
+ var getChangesProjectSchema = z10.object({
889
858
  id: uuidSchema.readonly()
890
859
  });
891
- var synchronizeProjectSchema = z11.object({
860
+ var synchronizeProjectSchema = z10.object({
892
861
  id: uuidSchema.readonly()
893
862
  });
894
- var searchProjectSchema = z11.object({
863
+ var searchProjectSchema = z10.object({
895
864
  id: uuidSchema.readonly(),
896
- query: z11.string(),
865
+ query: z10.string(),
897
866
  language: supportedLanguageSchema,
898
- type: z11.array(objectTypeSchema).optional()
867
+ type: z10.array(objectTypeSchema).optional()
899
868
  });
900
869
 
901
870
  // src/schema/serviceSchema.ts
902
- import { z as z12 } from "zod";
903
- var serviceTypeSchema = z12.enum([
871
+ import { z as z11 } from "zod";
872
+ var serviceTypeSchema = z11.enum([
904
873
  "Git",
905
874
  "GitTag",
906
875
  "User",
@@ -912,10 +881,10 @@ var serviceTypeSchema = z12.enum([
912
881
  "Entry",
913
882
  "Value"
914
883
  ]);
915
- var listSchema = z12.object({
884
+ var listSchema = z11.object({
916
885
  projectId: uuidSchema,
917
- limit: z12.number().optional(),
918
- offset: z12.number().optional()
886
+ limit: z11.number().optional(),
887
+ offset: z11.number().optional()
919
888
  });
920
889
  var listCollectionsSchema = listSchema;
921
890
  var listEntriesSchema = listSchema.extend({
@@ -925,33 +894,33 @@ var listAssetsSchema = listSchema;
925
894
  var listProjectsSchema = listSchema.omit({
926
895
  projectId: true
927
896
  });
928
- var listGitTagsSchema = z12.object({
929
- path: gitRepositoryPathSchema
897
+ var listGitTagsSchema = z11.object({
898
+ path: z11.string()
930
899
  });
931
900
 
932
901
  // src/schema/userSchema.ts
933
- import z13 from "zod";
934
- var UserTypeSchema = z13.enum(["local", "cloud"]);
902
+ import z12 from "zod";
903
+ var UserTypeSchema = z12.enum(["local", "cloud"]);
935
904
  var baseUserSchema = gitSignatureSchema.extend({
936
905
  userType: UserTypeSchema,
937
906
  language: supportedLanguageSchema,
938
- window: z13.object({
939
- width: z13.number(),
940
- height: z13.number(),
941
- position: z13.object({
942
- x: z13.number(),
943
- y: z13.number()
907
+ window: z12.object({
908
+ width: z12.number(),
909
+ height: z12.number(),
910
+ position: z12.object({
911
+ x: z12.number(),
912
+ y: z12.number()
944
913
  })
945
914
  }).nullable()
946
915
  });
947
916
  var localUserSchema = baseUserSchema.extend({
948
- userType: z13.literal(UserTypeSchema.Enum.local)
917
+ userType: z12.literal(UserTypeSchema.Enum.local)
949
918
  });
950
919
  var cloudUserSchema = baseUserSchema.extend({
951
- userType: z13.literal(UserTypeSchema.Enum.cloud),
920
+ userType: z12.literal(UserTypeSchema.Enum.cloud),
952
921
  id: uuidSchema
953
922
  });
954
- var userFileSchema = z13.union([localUserSchema, cloudUserSchema]);
923
+ var userFileSchema = z12.union([localUserSchema, cloudUserSchema]);
955
924
  var userSchema = userFileSchema;
956
925
  var setUserSchema = userSchema;
957
926
 
@@ -990,17 +959,14 @@ var RequiredParameterMissingError = class extends Error {
990
959
  // src/util/node.ts
991
960
  var node_exports = {};
992
961
  __export(node_exports, {
993
- assignDefaultIfMissing: () => assignDefaultIfMissing,
994
962
  files: () => files,
995
963
  folders: () => folders,
996
964
  isNoError: () => isNoError,
997
965
  notEmpty: () => notEmpty,
998
966
  pathTo: () => pathTo,
999
967
  returnResolved: () => returnResolved,
1000
- spawnChildProcess: () => spawnChildProcess,
1001
968
  workingDirectory: () => workingDirectory
1002
969
  });
1003
- import { spawn } from "child_process";
1004
970
  import Fs from "fs-extra";
1005
971
  import Os from "os";
1006
972
  import Path from "path";
@@ -1061,13 +1027,10 @@ var pathTo = {
1061
1027
  asset: (projectId, id, extension) => {
1062
1028
  return Path.join(pathTo.lfs(projectId), `${id}.${extension}`);
1063
1029
  },
1064
- tmpAsset: (id, extension) => {
1065
- return Path.join(pathTo.tmp, `${id}.${extension}`);
1030
+ tmpAsset: (id, commitHash, extension) => {
1031
+ return Path.join(pathTo.tmp, `${id}.${commitHash}.${extension}`);
1066
1032
  }
1067
1033
  };
1068
- function assignDefaultIfMissing(value, defaultsTo) {
1069
- return Object.assign(defaultsTo, value);
1070
- }
1071
1034
  function notEmpty(value) {
1072
1035
  if (value === null || value === void 0) {
1073
1036
  return false;
@@ -1100,27 +1063,6 @@ async function returnResolved(promises) {
1100
1063
  const checked = await Promise.all(toCheck);
1101
1064
  return checked.filter(isNoError);
1102
1065
  }
1103
- function spawnChildProcess(command, args, options) {
1104
- return new Promise((resolve, reject) => {
1105
- const childProcess = spawn(command, args, options);
1106
- let log = "";
1107
- childProcess.stdout.on("data", (data) => {
1108
- log += data;
1109
- });
1110
- childProcess.stderr.on("data", (data) => {
1111
- log += data;
1112
- });
1113
- childProcess.on("error", (error) => {
1114
- throw error;
1115
- });
1116
- childProcess.on("exit", (code) => {
1117
- if (code === 0) {
1118
- return resolve(log);
1119
- }
1120
- return reject(log);
1121
- });
1122
- });
1123
- }
1124
1066
  async function folders(path) {
1125
1067
  const dirent = await Fs.readdir(path, { withFileTypes: true });
1126
1068
  return dirent.filter((dirent2) => {
@@ -1144,21 +1086,12 @@ async function files(path, extension) {
1144
1086
  var AbstractCrudService = class {
1145
1087
  type;
1146
1088
  options;
1147
- /**
1148
- * Dynamically generated git messages for operations
1149
- */
1150
- gitMessage;
1151
1089
  /**
1152
1090
  * Do not instantiate directly as this is an abstract class
1153
1091
  */
1154
1092
  constructor(type, options) {
1155
1093
  this.type = type;
1156
1094
  this.options = options;
1157
- this.gitMessage = {
1158
- create: `${gitCommitIconSchema.enum.CREATE} Created ${this.type}`,
1159
- update: `${gitCommitIconSchema.enum.UPDATE} Updated ${this.type}`,
1160
- delete: `${gitCommitIconSchema.enum.DELETE} Deleted ${this.type}`
1161
- };
1162
1095
  }
1163
1096
  /**
1164
1097
  * Returns a list of all file references of given project and type
@@ -1174,6 +1107,7 @@ var AbstractCrudService = class {
1174
1107
  throw new RequiredParameterMissingError("projectId");
1175
1108
  }
1176
1109
  return this.getFileReferences(pathTo.lfs(projectId));
1110
+ // LFS folder is correct, since we want the extension of the file itself, not the AssetFile (.json)
1177
1111
  case objectTypeSchema.Enum.project:
1178
1112
  return this.getFolderReferences(pathTo.projects);
1179
1113
  case objectTypeSchema.Enum.collection:
@@ -1218,8 +1152,7 @@ var AbstractCrudService = class {
1218
1152
  * Searches for all files inside given folder,
1219
1153
  * parses their names and returns them as FileReference
1220
1154
  *
1221
- * Ignores files not matching the [id].[language].[extension]
1222
- * or [id].[extension] format for their names
1155
+ * Ignores files if the extension is not supported.
1223
1156
  */
1224
1157
  async getFileReferences(path) {
1225
1158
  const possibleFiles = await files(path);
@@ -1227,9 +1160,8 @@ var AbstractCrudService = class {
1227
1160
  possibleFiles.map(async (possibleFile) => {
1228
1161
  const fileNameArray = possibleFile.name.split(".");
1229
1162
  const fileReference = {
1230
- id: fileNameArray[0] || "",
1231
- language: fileNameArray.length === 3 ? fileNameArray[1] : void 0,
1232
- extension: fileNameArray.length === 2 ? fileNameArray[1] : fileNameArray[2]
1163
+ id: fileNameArray[0],
1164
+ extension: fileNameArray[1]
1233
1165
  };
1234
1166
  try {
1235
1167
  return fileReferenceSchema.parse(fileReference);
@@ -1243,9 +1175,8 @@ var AbstractCrudService = class {
1243
1175
  };
1244
1176
 
1245
1177
  // src/service/AssetService.ts
1246
- import { fileTypeFromFile } from "file-type";
1247
1178
  import Fs2 from "fs-extra";
1248
- import isSvg from "is-svg";
1179
+ import mime from "mime";
1249
1180
 
1250
1181
  // src/util/shared.ts
1251
1182
  import slugify from "@sindresorhus/slugify";
@@ -1286,8 +1217,8 @@ var AssetService = class extends AbstractCrudService {
1286
1217
  createAssetSchema.parse(props);
1287
1218
  const id = uuid();
1288
1219
  const projectPath = pathTo.project(props.projectId);
1289
- const fileType = await this.getSupportedFileTypeOrThrow(props.filePath);
1290
- const size = await this.getAssetSize(props.filePath);
1220
+ const fileType = this.getFileType(props.filePath);
1221
+ const size = await this.getFileSize(props.filePath);
1291
1222
  const assetPath = pathTo.asset(props.projectId, id, fileType.extension);
1292
1223
  const assetFilePath = pathTo.assetFile(props.projectId, id);
1293
1224
  const assetFile = {
@@ -1313,7 +1244,10 @@ var AssetService = class extends AbstractCrudService {
1313
1244
  throw error;
1314
1245
  }
1315
1246
  await this.gitService.add(projectPath, [assetFilePath, assetPath]);
1316
- await this.gitService.commit(projectPath, this.gitMessage.create);
1247
+ await this.gitService.commit(projectPath, {
1248
+ method: "create",
1249
+ reference: { objectType: "asset", id }
1250
+ });
1317
1251
  return this.toAsset(props.projectId, assetFile);
1318
1252
  }
1319
1253
  /**
@@ -1346,11 +1280,11 @@ var AssetService = class extends AbstractCrudService {
1346
1280
  "binary"
1347
1281
  );
1348
1282
  await Fs2.writeFile(
1349
- pathTo.tmpAsset(assetFile.id, assetFile.extension),
1283
+ pathTo.tmpAsset(assetFile.id, props.commitHash, assetFile.extension),
1350
1284
  assetBlob,
1351
1285
  "binary"
1352
1286
  );
1353
- return this.toAsset(props.projectId, assetFile, true);
1287
+ return this.toAsset(props.projectId, assetFile, props.commitHash);
1354
1288
  }
1355
1289
  }
1356
1290
  /**
@@ -1378,10 +1312,8 @@ var AssetService = class extends AbstractCrudService {
1378
1312
  updated: datetime()
1379
1313
  };
1380
1314
  if (props.newFilePath) {
1381
- const fileType = await this.getSupportedFileTypeOrThrow(
1382
- props.newFilePath
1383
- );
1384
- const size = await this.getAssetSize(props.newFilePath);
1315
+ const fileType = this.getFileType(props.newFilePath);
1316
+ const size = await this.getFileSize(props.newFilePath);
1385
1317
  const prevAssetPath = pathTo.asset(
1386
1318
  props.projectId,
1387
1319
  props.id,
@@ -1405,7 +1337,10 @@ var AssetService = class extends AbstractCrudService {
1405
1337
  assetFileSchema
1406
1338
  );
1407
1339
  await this.gitService.add(projectPath, [assetFilePath]);
1408
- await this.gitService.commit(projectPath, this.gitMessage.update);
1340
+ await this.gitService.commit(projectPath, {
1341
+ method: "update",
1342
+ reference: { objectType: "asset", id: assetFile.id }
1343
+ });
1409
1344
  return this.toAsset(props.projectId, assetFile);
1410
1345
  }
1411
1346
  /**
@@ -1419,7 +1354,10 @@ var AssetService = class extends AbstractCrudService {
1419
1354
  await Fs2.remove(assetPath);
1420
1355
  await Fs2.remove(assetFilePath);
1421
1356
  await this.gitService.add(projectPath, [assetFilePath, assetPath]);
1422
- await this.gitService.commit(projectPath, this.gitMessage.delete);
1357
+ await this.gitService.commit(projectPath, {
1358
+ method: "delete",
1359
+ reference: { objectType: "asset", id: props.id }
1360
+ });
1423
1361
  }
1424
1362
  async list(props) {
1425
1363
  listAssetsSchema.parse(props);
@@ -1457,11 +1395,11 @@ var AssetService = class extends AbstractCrudService {
1457
1395
  return assetSchema.safeParse(obj).success;
1458
1396
  }
1459
1397
  /**
1460
- * Returns the size of an Asset in bytes
1398
+ * Returns the size of an file in bytes
1461
1399
  *
1462
- * @param path Path of the Asset to get the size from
1400
+ * @param path Path of the file to get the size from
1463
1401
  */
1464
- async getAssetSize(path) {
1402
+ async getFileSize(path) {
1465
1403
  return (await Fs2.stat(path)).size;
1466
1404
  }
1467
1405
  /**
@@ -1470,8 +1408,8 @@ var AssetService = class extends AbstractCrudService {
1470
1408
  * @param projectId The project's ID
1471
1409
  * @param assetFile The AssetFile to convert
1472
1410
  */
1473
- async toAsset(projectId, assetFile, isFromHistory = false) {
1474
- const assetPath = isFromHistory === false ? pathTo.asset(projectId, assetFile.id, assetFile.extension) : pathTo.tmpAsset(assetFile.id, assetFile.extension);
1411
+ async toAsset(projectId, assetFile, commitHash) {
1412
+ const assetPath = commitHash ? pathTo.tmpAsset(assetFile.id, commitHash, assetFile.extension) : pathTo.asset(projectId, assetFile.id, assetFile.extension);
1475
1413
  const history = await this.gitService.log(pathTo.project(projectId), {
1476
1414
  filePath: pathTo.assetFile(projectId, assetFile.id)
1477
1415
  });
@@ -1488,23 +1426,21 @@ var AssetService = class extends AbstractCrudService {
1488
1426
  *
1489
1427
  * @param filePath Path to the file to check
1490
1428
  */
1491
- async getSupportedFileTypeOrThrow(filePath) {
1492
- const fileSize = (await Fs2.stat(filePath)).size;
1493
- if (fileSize / 1e3 <= 500) {
1494
- const fileBuffer = await Fs2.readFile(filePath);
1495
- if (isSvg(fileBuffer.toString()) === true) {
1496
- return {
1497
- extension: supportedAssetExtensionSchema.Enum.svg,
1498
- mimeType: supportedAssetMimeTypeSchema.Enum["image/svg+xml"]
1499
- };
1500
- }
1429
+ getFileType(filePath) {
1430
+ const mimeType = mime.getType(filePath);
1431
+ if (mimeType === null) {
1432
+ throw new Error(`Unsupported MIME type of file "${filePath}"`);
1501
1433
  }
1502
- const fileType = await fileTypeFromFile(filePath);
1503
- const result = supportedAssetTypeSchema.parse({
1504
- extension: fileType?.ext,
1505
- mimeType: fileType?.mime
1506
- });
1507
- return result;
1434
+ const extension = mime.getExtension(mimeType);
1435
+ if (extension === null) {
1436
+ throw new Error(
1437
+ `Unsupported extension for MIME type "${mimeType}" of file "${filePath}"`
1438
+ );
1439
+ }
1440
+ return {
1441
+ extension,
1442
+ mimeType
1443
+ };
1508
1444
  }
1509
1445
  /**
1510
1446
  * Migrates an potentially outdated Asset file to the current schema
@@ -1551,7 +1487,10 @@ var CollectionService = class extends AbstractCrudService {
1551
1487
  collectionFileSchema
1552
1488
  );
1553
1489
  await this.gitService.add(projectPath, [collectionFilePath]);
1554
- await this.gitService.commit(projectPath, this.gitMessage.create);
1490
+ await this.gitService.commit(projectPath, {
1491
+ method: "create",
1492
+ reference: { objectType: "collection", id }
1493
+ });
1555
1494
  return this.toCollection(props.projectId, collectionFile);
1556
1495
  }
1557
1496
  /**
@@ -1606,7 +1545,10 @@ var CollectionService = class extends AbstractCrudService {
1606
1545
  collectionFileSchema
1607
1546
  );
1608
1547
  await this.gitService.add(projectPath, [collectionFilePath]);
1609
- await this.gitService.commit(projectPath, this.gitMessage.update);
1548
+ await this.gitService.commit(projectPath, {
1549
+ method: "update",
1550
+ reference: { objectType: "collection", id: collectionFile.id }
1551
+ });
1610
1552
  return this.toCollection(props.projectId, collectionFile);
1611
1553
  }
1612
1554
  /**
@@ -1620,7 +1562,10 @@ var CollectionService = class extends AbstractCrudService {
1620
1562
  const collectionPath = pathTo.collection(props.projectId, props.id);
1621
1563
  await Fs3.remove(collectionPath);
1622
1564
  await this.gitService.add(projectPath, [collectionPath]);
1623
- await this.gitService.commit(projectPath, this.gitMessage.delete);
1565
+ await this.gitService.commit(projectPath, {
1566
+ method: "delete",
1567
+ reference: { objectType: "collection", id: props.id }
1568
+ });
1624
1569
  }
1625
1570
  async list(props) {
1626
1571
  listCollectionsSchema.parse(props);
@@ -1743,7 +1688,14 @@ var EntryService = class extends AbstractCrudService {
1743
1688
  entryFileSchema
1744
1689
  );
1745
1690
  await this.gitService.add(projectPath, [entryFilePath]);
1746
- await this.gitService.commit(projectPath, this.gitMessage.create);
1691
+ await this.gitService.commit(projectPath, {
1692
+ method: "create",
1693
+ reference: {
1694
+ objectType: "entry",
1695
+ id: entryFile.id,
1696
+ collectionId: props.collectionId
1697
+ }
1698
+ });
1747
1699
  return entry;
1748
1700
  }
1749
1701
  /**
@@ -1813,7 +1765,14 @@ var EntryService = class extends AbstractCrudService {
1813
1765
  entryFileSchema
1814
1766
  );
1815
1767
  await this.gitService.add(projectPath, [entryFilePath]);
1816
- await this.gitService.commit(projectPath, this.gitMessage.update);
1768
+ await this.gitService.commit(projectPath, {
1769
+ method: "update",
1770
+ reference: {
1771
+ objectType: "entry",
1772
+ id: entryFile.id,
1773
+ collectionId: props.collectionId
1774
+ }
1775
+ });
1817
1776
  return entry;
1818
1777
  }
1819
1778
  /**
@@ -1829,7 +1788,14 @@ var EntryService = class extends AbstractCrudService {
1829
1788
  );
1830
1789
  await Fs4.remove(entryFilePath);
1831
1790
  await this.gitService.add(projectPath, [entryFilePath]);
1832
- await this.gitService.commit(projectPath, this.gitMessage.delete);
1791
+ await this.gitService.commit(projectPath, {
1792
+ method: "delete",
1793
+ reference: {
1794
+ objectType: "entry",
1795
+ id: props.id,
1796
+ collectionId: props.collectionId
1797
+ }
1798
+ });
1833
1799
  }
1834
1800
  async list(props) {
1835
1801
  listEntriesSchema.parse(props);
@@ -1949,6 +1915,11 @@ var EntryService = class extends AbstractCrudService {
1949
1915
  collectionId: props.collectionId,
1950
1916
  id: props.valueContentReference.id
1951
1917
  });
1918
+ // case objectTypeSchema.Enum.sharedValue:
1919
+ // return this.resolveValueContentReferenceToSharedValue({
1920
+ // projectId: props.projectId,
1921
+ // valueContentReferenceToSharedValue: props.valueContentReference,
1922
+ // });
1952
1923
  default:
1953
1924
  throw new Error(
1954
1925
  // @ts-ignore
@@ -2203,6 +2174,9 @@ var GitService = class {
2203
2174
  */
2204
2175
  async clone(url, path, options) {
2205
2176
  let args = ["clone", "--progress"];
2177
+ if (options?.bare) {
2178
+ args = [...args, "--bare"];
2179
+ }
2206
2180
  if (options?.branch) {
2207
2181
  args = [...args, "--branch", options.branch];
2208
2182
  }
@@ -2303,6 +2277,21 @@ var GitService = class {
2303
2277
  args = [...args, branch];
2304
2278
  }
2305
2279
  await this.git(path, args);
2280
+ },
2281
+ /**
2282
+ * Delete a branch
2283
+ *
2284
+ * @see https://git-scm.com/docs/git-branch#Documentation/git-branch.txt---delete
2285
+ *
2286
+ * @param path Path to the repository
2287
+ * @param branch Name of the branch to delete
2288
+ */
2289
+ delete: async (path, branch, force) => {
2290
+ let args = ["branch", "--delete"];
2291
+ if (force === true) {
2292
+ args = [...args, "--force"];
2293
+ }
2294
+ await this.git(path, [...args, branch]);
2306
2295
  }
2307
2296
  };
2308
2297
  remotes = {
@@ -2374,6 +2363,19 @@ var GitService = class {
2374
2363
  await this.git(path, args);
2375
2364
  }
2376
2365
  };
2366
+ /**
2367
+ * Join two development histories together
2368
+ *
2369
+ * @see https://git-scm.com/docs/git-merge
2370
+ */
2371
+ async merge(path, branch, options) {
2372
+ let args = ["merge"];
2373
+ if (options?.squash === true) {
2374
+ args = [...args, "--squash"];
2375
+ }
2376
+ args = [...args, branch];
2377
+ await this.git(path, args);
2378
+ }
2377
2379
  /**
2378
2380
  * Reset current HEAD to the specified state
2379
2381
  *
@@ -2455,16 +2457,17 @@ var GitService = class {
2455
2457
  * @see https://git-scm.com/docs/git-commit
2456
2458
  *
2457
2459
  * @param path Path to the repository
2458
- * @param message A message that describes the changes
2460
+ * @param message An object describing the changes
2459
2461
  */
2460
2462
  async commit(path, message) {
2463
+ gitMessageSchema.parse(message);
2461
2464
  const user = await this.userService.get();
2462
2465
  if (!user) {
2463
2466
  throw new NoCurrentUserError();
2464
2467
  }
2465
2468
  const args = [
2466
2469
  "commit",
2467
- `--message=${message}`,
2470
+ `--message=${JSON.stringify(message)}`,
2468
2471
  `--author=${user.name} <${user.email}>`
2469
2472
  ];
2470
2473
  await this.git(path, args);
@@ -2499,19 +2502,23 @@ var GitService = class {
2499
2502
  const noEmptyLinesArr = result.stdout.split("\n").filter((line) => {
2500
2503
  return line.trim() !== "";
2501
2504
  });
2502
- const lineObjArr = noEmptyLinesArr.map((line) => {
2503
- const lineArray = line.split("|");
2504
- return {
2505
- hash: lineArray[0],
2506
- message: lineArray[1],
2507
- author: {
2508
- name: lineArray[2],
2509
- email: lineArray[3]
2510
- },
2511
- datetime: datetime(lineArray[4]),
2512
- tag: this.refNameToTagName(lineArray[5] || "")
2513
- };
2514
- });
2505
+ const lineObjArr = await Promise.all(
2506
+ noEmptyLinesArr.map(async (line) => {
2507
+ const lineArray = line.split("|");
2508
+ const tagId = this.refNameToTagName(lineArray[5] || "");
2509
+ const tag = tagId ? await this.tags.read({ path, id: tagId }) : null;
2510
+ return {
2511
+ hash: lineArray[0],
2512
+ message: JSON.parse(lineArray[1] || ""),
2513
+ author: {
2514
+ name: lineArray[2],
2515
+ email: lineArray[3]
2516
+ },
2517
+ datetime: datetime(lineArray[4]),
2518
+ tag
2519
+ };
2520
+ })
2521
+ );
2515
2522
  return lineObjArr.filter(this.isGitCommit.bind(this));
2516
2523
  }
2517
2524
  /**
@@ -2774,7 +2781,13 @@ var LogService = class {
2774
2781
  new transports.Console({
2775
2782
  handleExceptions: true,
2776
2783
  handleRejections: true,
2777
- format: format.cli()
2784
+ format: format.combine(
2785
+ format.colorize(),
2786
+ format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
2787
+ format.printf((info) => {
2788
+ return `${info.level} [${info["timestamp"]}]: ${info.message}`;
2789
+ })
2790
+ )
2778
2791
  })
2779
2792
  ]
2780
2793
  });
@@ -2785,16 +2798,16 @@ var LogService = class {
2785
2798
  });
2786
2799
  }
2787
2800
  debug(message, ...meta) {
2788
- return this.logger.debug(message, ...meta);
2801
+ this.logger.debug(message, ...meta);
2789
2802
  }
2790
2803
  info(message, ...meta) {
2791
- return this.logger.info(message, ...meta);
2804
+ this.logger.info(message, ...meta);
2792
2805
  }
2793
2806
  warn(message, ...meta) {
2794
- return this.logger.warn(message, ...meta);
2807
+ this.logger.warn(message, ...meta);
2795
2808
  }
2796
2809
  error(message, ...meta) {
2797
- return this.logger.error(message, ...meta);
2810
+ this.logger.error(message, ...meta);
2798
2811
  }
2799
2812
  read(options) {
2800
2813
  return this.logger.query(options);
@@ -2806,6 +2819,28 @@ import Fs6 from "fs-extra";
2806
2819
  import Os2 from "os";
2807
2820
  import Path4 from "path";
2808
2821
  import Semver from "semver";
2822
+
2823
+ // src/error/RemoteOriginMissingError.ts
2824
+ var RemoteOriginMissingError = class extends Error {
2825
+ constructor(projectId) {
2826
+ super(
2827
+ `Tried to delete Project "${projectId}" but it does not have a remote origin. Deleting a Project without a remote origin could lead to data loss. Use the "force" option to delete it anyway.`
2828
+ );
2829
+ this.name = "RemoteOriginMissingError";
2830
+ }
2831
+ };
2832
+
2833
+ // src/error/SynchronizeLocalChangesError.ts
2834
+ var SynchronizeLocalChangesError = class extends Error {
2835
+ constructor(projectId) {
2836
+ super(
2837
+ `Tried to delete Project "${projectId}" but it has local changes that are not yet pushed to the remote origin. Deleting a Project with local changes could lead to data loss. Use the "force" option to delete it anyway.`
2838
+ );
2839
+ this.name = "SynchronizeLocalChangesError";
2840
+ }
2841
+ };
2842
+
2843
+ // src/service/ProjectService.ts
2809
2844
  var ProjectService = class extends AbstractCrudService {
2810
2845
  coreVersion;
2811
2846
  logService;
@@ -2859,23 +2894,30 @@ var ProjectService = class extends AbstractCrudService {
2859
2894
  try {
2860
2895
  await this.createFolderStructure(projectPath);
2861
2896
  await this.createGitignore(projectPath);
2862
- await this.gitService.init(projectPath, { initialBranch: "main" });
2897
+ await this.gitService.init(projectPath, {
2898
+ initialBranch: projectBranchSchema.Enum.production
2899
+ });
2863
2900
  await this.jsonFileService.create(
2864
2901
  projectFile,
2865
2902
  pathTo.projectFile(id),
2866
2903
  projectFileSchema
2867
2904
  );
2868
2905
  await this.gitService.add(projectPath, ["."]);
2869
- await this.gitService.commit(
2906
+ await this.gitService.commit(projectPath, {
2907
+ method: "create",
2908
+ reference: { objectType: "project", id }
2909
+ });
2910
+ await this.gitService.branches.switch(
2870
2911
  projectPath,
2871
- `${gitCommitIconSchema.enum.INIT} Created this new elek.io project`
2912
+ projectBranchSchema.Enum.work,
2913
+ {
2914
+ isNew: true
2915
+ }
2872
2916
  );
2873
- await this.gitService.branches.switch(projectPath, "stage", {
2874
- isNew: true
2875
- });
2876
2917
  } catch (error) {
2877
2918
  await this.delete({
2878
- id
2919
+ id,
2920
+ force: true
2879
2921
  });
2880
2922
  throw error;
2881
2923
  }
@@ -2953,7 +2995,10 @@ var ProjectService = class extends AbstractCrudService {
2953
2995
  };
2954
2996
  await this.jsonFileService.update(projectFile, filePath, projectFileSchema);
2955
2997
  await this.gitService.add(projectPath, [filePath]);
2956
- await this.gitService.commit(projectPath, this.gitMessage.update);
2998
+ await this.gitService.commit(projectPath, {
2999
+ method: "update",
3000
+ reference: { objectType: "project", id: projectFile.id }
3001
+ });
2957
3002
  return await this.toProject(projectFile);
2958
3003
  }
2959
3004
  /**
@@ -2965,15 +3010,22 @@ var ProjectService = class extends AbstractCrudService {
2965
3010
  upgradeProjectSchema.parse(props);
2966
3011
  const projectPath = pathTo.project(props.id);
2967
3012
  const projectFilePath = pathTo.projectFile(props.id);
2968
- const prevProjectFile = outdatedProjectSchema.passthrough().parse(await this.jsonFileService.unsafeRead(projectFilePath));
2969
- if (Semver.gt(prevProjectFile.coreVersion, this.coreVersion)) {
3013
+ const currentBranch = await this.gitService.branches.current(projectPath);
3014
+ if (currentBranch !== projectBranchSchema.Enum.work) {
3015
+ await this.gitService.branches.switch(
3016
+ projectPath,
3017
+ projectBranchSchema.Enum.work
3018
+ );
3019
+ }
3020
+ const currentProjectFile = outdatedProjectSchema.passthrough().parse(await this.jsonFileService.unsafeRead(projectFilePath));
3021
+ if (Semver.gt(currentProjectFile.coreVersion, this.coreVersion)) {
2970
3022
  throw new ProjectUpgradeError(
2971
- `The Projects Core version "${prevProjectFile.coreVersion}" is higher than the current Core version "${this.coreVersion}".`
3023
+ `The Projects Core version "${currentProjectFile.coreVersion}" is higher than the current Core version "${this.coreVersion}".`
2972
3024
  );
2973
3025
  }
2974
- if (Semver.eq(prevProjectFile.coreVersion, this.coreVersion) && props.force !== true) {
3026
+ if (Semver.eq(currentProjectFile.coreVersion, this.coreVersion) && props.force !== true) {
2975
3027
  throw new ProjectUpgradeError(
2976
- `The Projects Core version "${prevProjectFile.coreVersion}" is already up to date.`
3028
+ `The Projects Core version "${currentProjectFile.coreVersion}" is already up to date.`
2977
3029
  );
2978
3030
  }
2979
3031
  const assetReferences = await this.listReferences("asset", props.id);
@@ -2982,11 +3034,11 @@ var ProjectService = class extends AbstractCrudService {
2982
3034
  props.id
2983
3035
  );
2984
3036
  this.logService.info(
2985
- `Attempting to upgrade Project "${props.id}" from Core version ${prevProjectFile.coreVersion} to ${this.coreVersion}`
3037
+ `Attempting to upgrade Project "${props.id}" from Core version ${currentProjectFile.coreVersion} to ${this.coreVersion}`
2986
3038
  );
2987
- const failsafeTag = await this.gitService.tags.create({
2988
- path: projectPath,
2989
- message: `Attempting to upgrade Project from Core version ${prevProjectFile.coreVersion} to ${this.coreVersion}`
3039
+ const upgradeBranchName = `upgrade/core-${currentProjectFile.coreVersion}-to-${this.coreVersion}`;
3040
+ await this.gitService.branches.switch(projectPath, upgradeBranchName, {
3041
+ isNew: true
2990
3042
  });
2991
3043
  try {
2992
3044
  await Promise.all(
@@ -3018,22 +3070,45 @@ var ProjectService = class extends AbstractCrudService {
3018
3070
  );
3019
3071
  })
3020
3072
  );
3021
- const migratedProjectFile = this.migrate(prevProjectFile);
3073
+ const migratedProjectFile = this.migrate(currentProjectFile);
3022
3074
  await this.update(migratedProjectFile);
3023
- this.logService.info(`Upgraded project "${projectFilePath}"`, {
3024
- previous: prevProjectFile,
3025
- migrated: migratedProjectFile
3075
+ await this.gitService.branches.switch(
3076
+ projectPath,
3077
+ projectBranchSchema.Enum.work
3078
+ );
3079
+ await this.gitService.merge(projectPath, upgradeBranchName, {
3080
+ squash: true
3026
3081
  });
3027
- await this.gitService.tags.create({
3028
- path: projectPath,
3029
- message: `Upgraded Project to Core version "${this.coreVersion}"`
3082
+ await this.gitService.commit(projectPath, {
3083
+ method: "upgrade",
3084
+ reference: { objectType: "project", id: migratedProjectFile.id }
3030
3085
  });
3031
- await this.gitService.tags.delete({
3086
+ await this.gitService.tags.create({
3032
3087
  path: projectPath,
3033
- id: failsafeTag.id
3088
+ message: `Upgraded Project to Core version ${migratedProjectFile.coreVersion}`
3034
3089
  });
3090
+ await this.gitService.branches.delete(
3091
+ projectPath,
3092
+ upgradeBranchName,
3093
+ true
3094
+ );
3095
+ this.logService.info(
3096
+ `Upgraded Project "${projectFilePath}" to Core version "${this.coreVersion}"`,
3097
+ {
3098
+ previous: currentProjectFile,
3099
+ migrated: migratedProjectFile
3100
+ }
3101
+ );
3035
3102
  } catch (error) {
3036
- await this.gitService.reset(projectPath, "hard", failsafeTag.id);
3103
+ await this.gitService.branches.switch(
3104
+ projectPath,
3105
+ projectBranchSchema.Enum.work
3106
+ );
3107
+ await this.gitService.branches.delete(
3108
+ projectPath,
3109
+ upgradeBranchName,
3110
+ true
3111
+ );
3037
3112
  throw error;
3038
3113
  }
3039
3114
  }
@@ -3062,38 +3137,37 @@ var ProjectService = class extends AbstractCrudService {
3062
3137
  );
3063
3138
  }
3064
3139
  };
3065
- remotes = {
3066
- getOriginUrl: async (props) => {
3067
- getRemoteOriginUrlProjectSchema.parse(props);
3068
- const projectPath = pathTo.project(props.id);
3069
- const hasOrigin = await this.gitService.remotes.hasOrigin(projectPath);
3070
- if (!hasOrigin) {
3071
- return null;
3072
- } else {
3073
- return await this.gitService.remotes.getOriginUrl(projectPath);
3074
- }
3075
- },
3076
- setOriginUrl: async (props) => {
3077
- setRemoteOriginUrlProjectSchema.parse(props);
3078
- const projectPath = pathTo.project(props.id);
3079
- const hasOrigin = await this.gitService.remotes.hasOrigin(projectPath);
3080
- if (!hasOrigin) {
3081
- await this.gitService.remotes.addOrigin(projectPath, props.url);
3082
- } else {
3083
- await this.gitService.remotes.setOriginUrl(projectPath, props.url);
3084
- }
3140
+ /**
3141
+ * Updates the remote origin URL of given Project
3142
+ */
3143
+ async setRemoteOriginUrl(props) {
3144
+ setRemoteOriginUrlProjectSchema.parse(props);
3145
+ const projectPath = pathTo.project(props.id);
3146
+ const hasOrigin = await this.gitService.remotes.hasOrigin(projectPath);
3147
+ if (!hasOrigin) {
3148
+ await this.gitService.remotes.addOrigin(projectPath, props.url);
3149
+ } else {
3150
+ await this.gitService.remotes.setOriginUrl(projectPath, props.url);
3085
3151
  }
3086
- };
3152
+ }
3087
3153
  /**
3088
3154
  * Returns the differences of the given Projects current branch
3089
3155
  * between the local and remote `origin` (commits ahead & behind)
3090
3156
  *
3157
+ * Throws an error if the Project does not have a remote origin.
3158
+ *
3091
3159
  * - `behind` contains a list of commits on the current branch that are available on the remote `origin` but not yet locally
3092
3160
  * - `ahead` contains a list of commits on the current branch that are available locally but not yet on the remote `origin`
3093
3161
  */
3094
3162
  async getChanges(props) {
3095
3163
  getChangesProjectSchema.parse(props);
3096
3164
  const projectPath = pathTo.project(props.id);
3165
+ const hasRemoteOrigin = await this.gitService.remotes.hasOrigin(
3166
+ projectPath
3167
+ );
3168
+ if (hasRemoteOrigin === false) {
3169
+ throw new Error(`Project "${props.id}" does not have a remote origin`);
3170
+ }
3097
3171
  const currentBranch = await this.gitService.branches.current(projectPath);
3098
3172
  await this.gitService.fetch(projectPath);
3099
3173
  const behind = await this.gitService.log(projectPath, {
@@ -3121,11 +3195,23 @@ var ProjectService = class extends AbstractCrudService {
3121
3195
  * Deletes given Project
3122
3196
  *
3123
3197
  * Deletes the whole Project folder including the history, not only the config file.
3124
- * Use with caution, since a Project that is only available locally could be lost forever.
3125
- * Or changes that are not pushed to a remote yet, will be lost too.
3198
+ * Throws in case a Project is only available locally and could be lost forever,
3199
+ * or changes are not pushed to a remote yet.
3126
3200
  */
3127
3201
  async delete(props) {
3128
3202
  deleteProjectSchema.parse(props);
3203
+ const hasRemoteOrigin = await this.gitService.remotes.hasOrigin(
3204
+ pathTo.project(props.id)
3205
+ );
3206
+ if (hasRemoteOrigin === false && props.force !== true) {
3207
+ throw new RemoteOriginMissingError(props.id);
3208
+ }
3209
+ if (hasRemoteOrigin === true && props.force !== true) {
3210
+ const changes = await this.getChanges({ id: props.id });
3211
+ if (changes.ahead.length > 0) {
3212
+ throw new SynchronizeLocalChangesError(props.id);
3213
+ }
3214
+ }
3129
3215
  await Fs6.remove(pathTo.project(props.id));
3130
3216
  }
3131
3217
  /**
@@ -3220,6 +3306,12 @@ var ProjectService = class extends AbstractCrudService {
3220
3306
  * Creates a Project from given ProjectFile
3221
3307
  */
3222
3308
  async toProject(projectFile) {
3309
+ const projectPath = pathTo.project(projectFile.id);
3310
+ let remoteOriginUrl = null;
3311
+ const hasOrigin = await this.gitService.remotes.hasOrigin(projectPath);
3312
+ if (hasOrigin) {
3313
+ remoteOriginUrl = await this.gitService.remotes.getOriginUrl(projectPath);
3314
+ }
3223
3315
  const fullHistory = await this.gitService.log(
3224
3316
  pathTo.project(projectFile.id)
3225
3317
  );
@@ -3228,6 +3320,7 @@ var ProjectService = class extends AbstractCrudService {
3228
3320
  });
3229
3321
  return {
3230
3322
  ...projectFile,
3323
+ remoteOriginUrl,
3231
3324
  history,
3232
3325
  fullHistory
3233
3326
  };
@@ -3505,7 +3598,6 @@ export {
3505
3598
  assetFileSchema,
3506
3599
  assetSchema,
3507
3600
  baseFileSchema,
3508
- baseFileWithLanguageSchema,
3509
3601
  baseUserSchema,
3510
3602
  cloneProjectSchema,
3511
3603
  cloudUserSchema,
@@ -3549,11 +3641,11 @@ export {
3549
3641
  getRemoteOriginUrlProjectSchema,
3550
3642
  getValueContentSchemaFromFieldDefinition,
3551
3643
  gitCloneOptionsSchema,
3552
- gitCommitIconSchema,
3553
3644
  gitCommitSchema,
3554
3645
  gitInitOptionsSchema,
3555
3646
  gitLogOptionsSchema,
3556
- gitRepositoryPathSchema,
3647
+ gitMergeOptionsSchema,
3648
+ gitMessageSchema,
3557
3649
  gitSignatureSchema,
3558
3650
  gitSwitchOptionsSchema,
3559
3651
  gitTagSchema,
@@ -3569,6 +3661,7 @@ export {
3569
3661
  numberFieldDefinitionSchema,
3570
3662
  objectTypeSchema,
3571
3663
  outdatedProjectSchema,
3664
+ projectBranchSchema,
3572
3665
  projectExportSchema,
3573
3666
  projectFileSchema,
3574
3667
  projectFolderSchema,
@@ -3593,9 +3686,6 @@ export {
3593
3686
  setUserSchema,
3594
3687
  slug,
3595
3688
  stringFieldDefinitionSchema,
3596
- supportedAssetExtensionSchema,
3597
- supportedAssetMimeTypeSchema,
3598
- supportedAssetTypeSchema,
3599
3689
  supportedIconSchema,
3600
3690
  supportedLanguageSchema,
3601
3691
  switchBranchProjectSchema,
@@ -3624,7 +3714,6 @@ export {
3624
3714
  valueContentReferenceToAssetSchema,
3625
3715
  valueContentReferenceToCollectionSchema,
3626
3716
  valueContentReferenceToEntrySchema,
3627
- valueContentReferenceWithLanguageBase,
3628
3717
  valueSchema,
3629
3718
  versionSchema
3630
3719
  };