@elek-io/core 0.5.3 → 0.6.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/dist/browser/index.browser.js +3 -4
- package/dist/browser/index.browser.js.map +1 -1
- package/dist/node/index.node.js +990 -950
- package/dist/node/index.node.js.map +1 -1
- package/package.json +11 -10
- package/dist/browser/index.browser.cjs +0 -1082
- package/dist/browser/index.browser.cjs.map +0 -1
- package/dist/browser/index.browser.d.cts +0 -12551
- package/dist/node/index.node.cjs +0 -3409
- package/dist/node/index.node.cjs.map +0 -1
- package/dist/node/index.node.d.cts +0 -13384
package/dist/node/index.node.cjs
DELETED
|
@@ -1,3409 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.node.ts
|
|
31
|
-
var index_node_exports = {};
|
|
32
|
-
__export(index_node_exports, {
|
|
33
|
-
BooleanValueDefinitionBaseSchema: () => BooleanValueDefinitionBaseSchema,
|
|
34
|
-
NumberValueDefinitionBaseSchema: () => NumberValueDefinitionBaseSchema,
|
|
35
|
-
ReferenceValueDefinitionBaseSchema: () => ReferenceValueDefinitionBaseSchema,
|
|
36
|
-
StringValueDefinitionBaseSchema: () => StringValueDefinitionBaseSchema,
|
|
37
|
-
UserTypeSchema: () => UserTypeSchema,
|
|
38
|
-
ValueDefinitionBaseSchema: () => ValueDefinitionBaseSchema,
|
|
39
|
-
ValueInputTypeSchema: () => ValueInputTypeSchema,
|
|
40
|
-
ValueInputWidthSchema: () => ValueInputWidthSchema,
|
|
41
|
-
ValueTypeSchema: () => ValueTypeSchema,
|
|
42
|
-
assetExportSchema: () => assetExportSchema,
|
|
43
|
-
assetFileSchema: () => assetFileSchema,
|
|
44
|
-
assetSchema: () => assetSchema,
|
|
45
|
-
assetValueDefinitionSchema: () => assetValueDefinitionSchema,
|
|
46
|
-
baseFileSchema: () => baseFileSchema,
|
|
47
|
-
baseFileWithLanguageSchema: () => baseFileWithLanguageSchema,
|
|
48
|
-
baseUserSchema: () => baseUserSchema,
|
|
49
|
-
cloneProjectSchema: () => cloneProjectSchema,
|
|
50
|
-
cloudUserSchema: () => cloudUserSchema,
|
|
51
|
-
collectionExportSchema: () => collectionExportSchema,
|
|
52
|
-
collectionFileSchema: () => collectionFileSchema,
|
|
53
|
-
collectionSchema: () => collectionSchema,
|
|
54
|
-
constructorElekIoCoreSchema: () => constructorElekIoCoreSchema,
|
|
55
|
-
countAssetsSchema: () => countAssetsSchema,
|
|
56
|
-
countCollectionsSchema: () => countCollectionsSchema,
|
|
57
|
-
countEntriesSchema: () => countEntriesSchema,
|
|
58
|
-
countGitTagsSchema: () => countGitTagsSchema,
|
|
59
|
-
createAssetSchema: () => createAssetSchema,
|
|
60
|
-
createCollectionSchema: () => createCollectionSchema,
|
|
61
|
-
createEntrySchema: () => createEntrySchema,
|
|
62
|
-
createGitTagSchema: () => createGitTagSchema,
|
|
63
|
-
createProjectSchema: () => createProjectSchema,
|
|
64
|
-
currentBranchProjectSchema: () => currentBranchProjectSchema,
|
|
65
|
-
currentTimestamp: () => currentTimestamp,
|
|
66
|
-
dateValueDefinitionSchema: () => dateValueDefinitionSchema,
|
|
67
|
-
datetimeValueDefinitionSchema: () => datetimeValueDefinitionSchema,
|
|
68
|
-
default: () => ElekIoCore,
|
|
69
|
-
deleteAssetSchema: () => deleteAssetSchema,
|
|
70
|
-
deleteCollectionSchema: () => deleteCollectionSchema,
|
|
71
|
-
deleteEntrySchema: () => deleteEntrySchema,
|
|
72
|
-
deleteGitTagSchema: () => deleteGitTagSchema,
|
|
73
|
-
deleteProjectSchema: () => deleteProjectSchema,
|
|
74
|
-
directBooleanValueSchema: () => directBooleanValueSchema,
|
|
75
|
-
directNumberValueSchema: () => directNumberValueSchema,
|
|
76
|
-
directStringValueSchema: () => directStringValueSchema,
|
|
77
|
-
directValueBaseSchema: () => directValueBaseSchema,
|
|
78
|
-
directValueSchema: () => directValueSchema,
|
|
79
|
-
elekIoCoreOptionsSchema: () => elekIoCoreOptionsSchema,
|
|
80
|
-
emailValueDefinitionSchema: () => emailValueDefinitionSchema,
|
|
81
|
-
entryExportSchema: () => entryExportSchema,
|
|
82
|
-
entryFileSchema: () => entryFileSchema,
|
|
83
|
-
entrySchema: () => entrySchema,
|
|
84
|
-
entryValueDefinitionSchema: () => entryValueDefinitionSchema,
|
|
85
|
-
environmentSchema: () => environmentSchema,
|
|
86
|
-
fileReferenceSchema: () => fileReferenceSchema,
|
|
87
|
-
getChangesProjectSchema: () => getChangesProjectSchema,
|
|
88
|
-
getRemoteOriginUrlProjectSchema: () => getRemoteOriginUrlProjectSchema,
|
|
89
|
-
getValueContentSchemaFromDefinition: () => getValueContentSchemaFromDefinition,
|
|
90
|
-
gitCloneOptionsSchema: () => gitCloneOptionsSchema,
|
|
91
|
-
gitCommitIconSchema: () => gitCommitIconSchema,
|
|
92
|
-
gitCommitSchema: () => gitCommitSchema,
|
|
93
|
-
gitInitOptionsSchema: () => gitInitOptionsSchema,
|
|
94
|
-
gitLogOptionsSchema: () => gitLogOptionsSchema,
|
|
95
|
-
gitRepositoryPathSchema: () => gitRepositoryPathSchema,
|
|
96
|
-
gitSignatureSchema: () => gitSignatureSchema,
|
|
97
|
-
gitSwitchOptionsSchema: () => gitSwitchOptionsSchema,
|
|
98
|
-
gitTagSchema: () => gitTagSchema,
|
|
99
|
-
ipValueDefinitionSchema: () => ipValueDefinitionSchema,
|
|
100
|
-
listAssetsSchema: () => listAssetsSchema,
|
|
101
|
-
listBranchesProjectSchema: () => listBranchesProjectSchema,
|
|
102
|
-
listCollectionsSchema: () => listCollectionsSchema,
|
|
103
|
-
listEntriesSchema: () => listEntriesSchema,
|
|
104
|
-
listGitTagsSchema: () => listGitTagsSchema,
|
|
105
|
-
listProjectsSchema: () => listProjectsSchema,
|
|
106
|
-
localUserSchema: () => localUserSchema,
|
|
107
|
-
numberValueDefinitionSchema: () => numberValueDefinitionSchema,
|
|
108
|
-
objectTypeSchema: () => objectTypeSchema,
|
|
109
|
-
projectExportSchema: () => projectExportSchema,
|
|
110
|
-
projectFileSchema: () => projectFileSchema,
|
|
111
|
-
projectFolderSchema: () => projectFolderSchema,
|
|
112
|
-
projectSchema: () => projectSchema,
|
|
113
|
-
projectSettingsSchema: () => projectSettingsSchema,
|
|
114
|
-
projectStatusSchema: () => projectStatusSchema,
|
|
115
|
-
projectUpgradeSchema: () => projectUpgradeSchema,
|
|
116
|
-
rangeValueDefinitionSchema: () => rangeValueDefinitionSchema,
|
|
117
|
-
readAssetSchema: () => readAssetSchema,
|
|
118
|
-
readCollectionSchema: () => readCollectionSchema,
|
|
119
|
-
readEntrySchema: () => readEntrySchema,
|
|
120
|
-
readGitTagSchema: () => readGitTagSchema,
|
|
121
|
-
readProjectSchema: () => readProjectSchema,
|
|
122
|
-
referencedValueSchema: () => referencedValueSchema,
|
|
123
|
-
resolvedReferencedValueSchema: () => resolvedReferencedValueSchema,
|
|
124
|
-
resolvedValueContentReferenceSchema: () => resolvedValueContentReferenceSchema,
|
|
125
|
-
resolvedValueSchema: () => resolvedValueSchema,
|
|
126
|
-
searchProjectSchema: () => searchProjectSchema,
|
|
127
|
-
serviceTypeSchema: () => serviceTypeSchema,
|
|
128
|
-
setRemoteOriginUrlProjectSchema: () => setRemoteOriginUrlProjectSchema,
|
|
129
|
-
setUserSchema: () => setUserSchema,
|
|
130
|
-
slug: () => slug,
|
|
131
|
-
stringValueDefinitionSchema: () => stringValueDefinitionSchema,
|
|
132
|
-
supportedAssetExtensionSchema: () => supportedAssetExtensionSchema,
|
|
133
|
-
supportedAssetMimeTypeSchema: () => supportedAssetMimeTypeSchema,
|
|
134
|
-
supportedAssetTypeSchema: () => supportedAssetTypeSchema,
|
|
135
|
-
supportedIconSchema: () => supportedIconSchema,
|
|
136
|
-
supportedLanguageSchema: () => supportedLanguageSchema,
|
|
137
|
-
switchBranchProjectSchema: () => switchBranchProjectSchema,
|
|
138
|
-
synchronizeProjectSchema: () => synchronizeProjectSchema,
|
|
139
|
-
telephoneValueDefinitionSchema: () => telephoneValueDefinitionSchema,
|
|
140
|
-
textValueDefinitionSchema: () => textValueDefinitionSchema,
|
|
141
|
-
textareaValueDefinitionSchema: () => textareaValueDefinitionSchema,
|
|
142
|
-
timeValueDefinitionSchema: () => timeValueDefinitionSchema,
|
|
143
|
-
toggleValueDefinitionSchema: () => toggleValueDefinitionSchema,
|
|
144
|
-
translatableArrayOf: () => translatableArrayOf,
|
|
145
|
-
translatableBooleanSchema: () => translatableBooleanSchema,
|
|
146
|
-
translatableNumberSchema: () => translatableNumberSchema,
|
|
147
|
-
translatableStringSchema: () => translatableStringSchema,
|
|
148
|
-
updateAssetSchema: () => updateAssetSchema,
|
|
149
|
-
updateCollectionSchema: () => updateCollectionSchema,
|
|
150
|
-
updateEntrySchema: () => updateEntrySchema,
|
|
151
|
-
updateProjectSchema: () => updateProjectSchema,
|
|
152
|
-
upgradeProjectSchema: () => upgradeProjectSchema,
|
|
153
|
-
urlValueDefinitionSchema: () => urlValueDefinitionSchema,
|
|
154
|
-
userFileSchema: () => userFileSchema,
|
|
155
|
-
userSchema: () => userSchema,
|
|
156
|
-
uuid: () => uuid,
|
|
157
|
-
uuidSchema: () => uuidSchema,
|
|
158
|
-
valueContentReferenceBase: () => valueContentReferenceBase,
|
|
159
|
-
valueContentReferenceSchema: () => valueContentReferenceSchema,
|
|
160
|
-
valueContentReferenceToAssetSchema: () => valueContentReferenceToAssetSchema,
|
|
161
|
-
valueContentReferenceToCollectionSchema: () => valueContentReferenceToCollectionSchema,
|
|
162
|
-
valueContentReferenceToEntrySchema: () => valueContentReferenceToEntrySchema,
|
|
163
|
-
valueContentReferenceWithLanguageBase: () => valueContentReferenceWithLanguageBase,
|
|
164
|
-
valueDefinitionSchema: () => valueDefinitionSchema,
|
|
165
|
-
valueSchema: () => valueSchema,
|
|
166
|
-
versionSchema: () => versionSchema
|
|
167
|
-
});
|
|
168
|
-
module.exports = __toCommonJS(index_node_exports);
|
|
169
|
-
var import_fs_extra7 = __toESM(require("fs-extra"), 1);
|
|
170
|
-
|
|
171
|
-
// src/schema/assetSchema.ts
|
|
172
|
-
var import_zod3 = __toESM(require("zod"), 1);
|
|
173
|
-
|
|
174
|
-
// src/schema/baseSchema.ts
|
|
175
|
-
var import_zod = __toESM(require("zod"), 1);
|
|
176
|
-
var environmentSchema = import_zod.default.enum(["production", "development", "test"]);
|
|
177
|
-
var supportedLanguageSchema = import_zod.default.enum([
|
|
178
|
-
/**
|
|
179
|
-
* Bulgarian
|
|
180
|
-
*/
|
|
181
|
-
"bg",
|
|
182
|
-
//
|
|
183
|
-
"cs",
|
|
184
|
-
// Czech
|
|
185
|
-
"da",
|
|
186
|
-
// Danish
|
|
187
|
-
"de",
|
|
188
|
-
// German
|
|
189
|
-
"el",
|
|
190
|
-
// Greek
|
|
191
|
-
"en",
|
|
192
|
-
// (US) English
|
|
193
|
-
"es",
|
|
194
|
-
// Spanish
|
|
195
|
-
"et",
|
|
196
|
-
// Estonian
|
|
197
|
-
"fi",
|
|
198
|
-
// Finnish
|
|
199
|
-
"fr",
|
|
200
|
-
// French
|
|
201
|
-
"hu",
|
|
202
|
-
// Hungarian
|
|
203
|
-
"it",
|
|
204
|
-
// Italian
|
|
205
|
-
"ja",
|
|
206
|
-
// Japanese
|
|
207
|
-
"lt",
|
|
208
|
-
// Lithuanian
|
|
209
|
-
"lv",
|
|
210
|
-
// Latvian
|
|
211
|
-
"nl",
|
|
212
|
-
// Dutch
|
|
213
|
-
"pl",
|
|
214
|
-
// Polish
|
|
215
|
-
"pt",
|
|
216
|
-
// Portuguese
|
|
217
|
-
"ro",
|
|
218
|
-
// Romanian
|
|
219
|
-
"ru",
|
|
220
|
-
// Russian
|
|
221
|
-
"sk",
|
|
222
|
-
// Slovak
|
|
223
|
-
"sl",
|
|
224
|
-
// Slovenian
|
|
225
|
-
"sv",
|
|
226
|
-
// Swedish
|
|
227
|
-
"zh"
|
|
228
|
-
// (Simplified) Chinese
|
|
229
|
-
]);
|
|
230
|
-
var supportedIconSchema = import_zod.default.enum(["home", "plus", "foobar"]);
|
|
231
|
-
var supportedAssetMimeTypeSchema = import_zod.default.enum([
|
|
232
|
-
"image/avif",
|
|
233
|
-
"image/gif",
|
|
234
|
-
"image/jpeg",
|
|
235
|
-
"image/png",
|
|
236
|
-
"image/svg+xml",
|
|
237
|
-
"image/webp",
|
|
238
|
-
"application/pdf",
|
|
239
|
-
"application/zip",
|
|
240
|
-
"video/mp4",
|
|
241
|
-
"video/webm",
|
|
242
|
-
"audio/webm",
|
|
243
|
-
"audio/flac"
|
|
244
|
-
]);
|
|
245
|
-
var supportedAssetExtensionSchema = import_zod.default.enum([
|
|
246
|
-
"avif",
|
|
247
|
-
"gif",
|
|
248
|
-
"jpg",
|
|
249
|
-
"jpeg",
|
|
250
|
-
"png",
|
|
251
|
-
"svg",
|
|
252
|
-
"webp",
|
|
253
|
-
"pdf",
|
|
254
|
-
"zip",
|
|
255
|
-
"mp4",
|
|
256
|
-
"webm",
|
|
257
|
-
"flac",
|
|
258
|
-
"json"
|
|
259
|
-
]);
|
|
260
|
-
var supportedAssetTypeSchema = import_zod.default.object({
|
|
261
|
-
extension: supportedAssetExtensionSchema,
|
|
262
|
-
mimeType: supportedAssetMimeTypeSchema
|
|
263
|
-
});
|
|
264
|
-
var objectTypeSchema = import_zod.default.enum([
|
|
265
|
-
"project",
|
|
266
|
-
"asset",
|
|
267
|
-
"collection",
|
|
268
|
-
"entry",
|
|
269
|
-
"value",
|
|
270
|
-
"sharedValue"
|
|
271
|
-
]);
|
|
272
|
-
var versionSchema = import_zod.default.string();
|
|
273
|
-
var uuidSchema = import_zod.default.string().uuid("shared.invalidUuid");
|
|
274
|
-
var translatableStringSchema = import_zod.default.record(
|
|
275
|
-
supportedLanguageSchema,
|
|
276
|
-
import_zod.default.string().trim().min(1, "shared.translatableStringRequired")
|
|
277
|
-
);
|
|
278
|
-
var translatableNumberSchema = import_zod.default.record(
|
|
279
|
-
supportedLanguageSchema,
|
|
280
|
-
import_zod.default.number({ required_error: "shared.translatableNumberRequired" })
|
|
281
|
-
);
|
|
282
|
-
var translatableBooleanSchema = import_zod.default.record(
|
|
283
|
-
supportedLanguageSchema,
|
|
284
|
-
import_zod.default.boolean({ required_error: "shared.translatableBooleanRequired" })
|
|
285
|
-
);
|
|
286
|
-
function translatableArrayOf(schema) {
|
|
287
|
-
return import_zod.default.record(supportedLanguageSchema, import_zod.default.array(schema));
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
// src/schema/fileSchema.ts
|
|
291
|
-
var import_zod2 = __toESM(require("zod"), 1);
|
|
292
|
-
var baseFileSchema = import_zod2.default.object({
|
|
293
|
-
/**
|
|
294
|
-
* The ID of the file
|
|
295
|
-
*
|
|
296
|
-
* The ID is part of the files name.
|
|
297
|
-
*/
|
|
298
|
-
id: uuidSchema.readonly(),
|
|
299
|
-
/**
|
|
300
|
-
* The timestamp of the file being created is set by the service of "objectType" while creating it
|
|
301
|
-
*/
|
|
302
|
-
created: import_zod2.default.number().readonly(),
|
|
303
|
-
/**
|
|
304
|
-
* The timestamp of the file being updated is set by the service of "objectType" while updating it
|
|
305
|
-
*/
|
|
306
|
-
updated: import_zod2.default.number().nullable()
|
|
307
|
-
});
|
|
308
|
-
var baseFileWithLanguageSchema = baseFileSchema.extend({
|
|
309
|
-
/**
|
|
310
|
-
* The language of the file
|
|
311
|
-
*
|
|
312
|
-
* The language is part of the files name and together with it's ID the only unique identifier.
|
|
313
|
-
* That's why the language cannot be changed after creating the file.
|
|
314
|
-
*
|
|
315
|
-
* @todo Maybe remove the above restriction by implementing logic to handle changing the files language inside all services
|
|
316
|
-
*/
|
|
317
|
-
language: supportedLanguageSchema.readonly()
|
|
318
|
-
});
|
|
319
|
-
var fileReferenceSchema = import_zod2.default.object({
|
|
320
|
-
id: uuidSchema,
|
|
321
|
-
language: supportedLanguageSchema.optional(),
|
|
322
|
-
extension: supportedAssetExtensionSchema.optional()
|
|
323
|
-
});
|
|
324
|
-
|
|
325
|
-
// src/schema/assetSchema.ts
|
|
326
|
-
var assetFileSchema = baseFileWithLanguageSchema.extend({
|
|
327
|
-
objectType: import_zod3.default.literal(objectTypeSchema.Enum.asset).readonly(),
|
|
328
|
-
name: import_zod3.default.string(),
|
|
329
|
-
description: import_zod3.default.string(),
|
|
330
|
-
extension: supportedAssetExtensionSchema.readonly(),
|
|
331
|
-
mimeType: supportedAssetMimeTypeSchema.readonly(),
|
|
332
|
-
/**
|
|
333
|
-
* Total size in bytes
|
|
334
|
-
*/
|
|
335
|
-
size: import_zod3.default.number().readonly()
|
|
336
|
-
});
|
|
337
|
-
var assetSchema = assetFileSchema.extend({
|
|
338
|
-
/**
|
|
339
|
-
* Absolute path on this filesystem
|
|
340
|
-
*/
|
|
341
|
-
absolutePath: import_zod3.default.string().readonly()
|
|
342
|
-
});
|
|
343
|
-
var assetExportSchema = assetSchema.extend({});
|
|
344
|
-
var createAssetSchema = assetFileSchema.pick({
|
|
345
|
-
name: true,
|
|
346
|
-
description: true,
|
|
347
|
-
language: true
|
|
348
|
-
}).extend({
|
|
349
|
-
projectId: uuidSchema.readonly(),
|
|
350
|
-
/**
|
|
351
|
-
* Path of the file to add as a new Asset
|
|
352
|
-
*/
|
|
353
|
-
filePath: import_zod3.default.string().readonly()
|
|
354
|
-
});
|
|
355
|
-
var readAssetSchema = assetFileSchema.pick({
|
|
356
|
-
id: true,
|
|
357
|
-
language: true
|
|
358
|
-
}).extend({
|
|
359
|
-
projectId: uuidSchema.readonly()
|
|
360
|
-
});
|
|
361
|
-
var updateAssetSchema = assetFileSchema.pick({
|
|
362
|
-
id: true,
|
|
363
|
-
name: true,
|
|
364
|
-
description: true,
|
|
365
|
-
language: true
|
|
366
|
-
}).extend({
|
|
367
|
-
projectId: uuidSchema.readonly(),
|
|
368
|
-
/**
|
|
369
|
-
* Path of the new file to update the Asset with
|
|
370
|
-
*/
|
|
371
|
-
newFilePath: import_zod3.default.string().readonly().optional()
|
|
372
|
-
});
|
|
373
|
-
var deleteAssetSchema = assetFileSchema.pick({
|
|
374
|
-
id: true,
|
|
375
|
-
language: true,
|
|
376
|
-
extension: true
|
|
377
|
-
}).extend({
|
|
378
|
-
projectId: uuidSchema.readonly()
|
|
379
|
-
});
|
|
380
|
-
var countAssetsSchema = import_zod3.default.object({ projectId: uuidSchema.readonly() });
|
|
381
|
-
|
|
382
|
-
// src/schema/collectionSchema.ts
|
|
383
|
-
var import_zod6 = __toESM(require("zod"), 1);
|
|
384
|
-
|
|
385
|
-
// src/schema/entrySchema.ts
|
|
386
|
-
var import_zod5 = __toESM(require("zod"), 1);
|
|
387
|
-
|
|
388
|
-
// src/schema/valueSchema.ts
|
|
389
|
-
var import_zod4 = __toESM(require("zod"), 1);
|
|
390
|
-
var ValueTypeSchema = import_zod4.default.enum([
|
|
391
|
-
"string",
|
|
392
|
-
"number",
|
|
393
|
-
"boolean",
|
|
394
|
-
"reference"
|
|
395
|
-
]);
|
|
396
|
-
var ValueInputTypeSchema = import_zod4.default.enum([
|
|
397
|
-
// String
|
|
398
|
-
"text",
|
|
399
|
-
"textarea",
|
|
400
|
-
"email",
|
|
401
|
-
// 'password', @todo maybe if there is a usecase
|
|
402
|
-
"url",
|
|
403
|
-
"ip",
|
|
404
|
-
"date",
|
|
405
|
-
"time",
|
|
406
|
-
"datetime",
|
|
407
|
-
"telephone",
|
|
408
|
-
// Number
|
|
409
|
-
"number",
|
|
410
|
-
"range",
|
|
411
|
-
// Boolean
|
|
412
|
-
"toggle",
|
|
413
|
-
// Reference
|
|
414
|
-
"asset",
|
|
415
|
-
"entry"
|
|
416
|
-
// 'sharedValue', // @todo
|
|
417
|
-
]);
|
|
418
|
-
var ValueInputWidthSchema = import_zod4.default.enum(["12", "6", "4", "3"]);
|
|
419
|
-
var ValueDefinitionBaseSchema = import_zod4.default.object({
|
|
420
|
-
id: uuidSchema.readonly(),
|
|
421
|
-
label: translatableStringSchema,
|
|
422
|
-
description: translatableStringSchema,
|
|
423
|
-
isRequired: import_zod4.default.boolean(),
|
|
424
|
-
isDisabled: import_zod4.default.boolean(),
|
|
425
|
-
isUnique: import_zod4.default.boolean(),
|
|
426
|
-
inputWidth: ValueInputWidthSchema
|
|
427
|
-
});
|
|
428
|
-
var StringValueDefinitionBaseSchema = ValueDefinitionBaseSchema.extend(
|
|
429
|
-
{
|
|
430
|
-
valueType: import_zod4.default.literal(ValueTypeSchema.Enum.string),
|
|
431
|
-
defaultValue: import_zod4.default.string().nullable()
|
|
432
|
-
}
|
|
433
|
-
);
|
|
434
|
-
var textValueDefinitionSchema = StringValueDefinitionBaseSchema.extend(
|
|
435
|
-
{
|
|
436
|
-
inputType: import_zod4.default.literal(ValueInputTypeSchema.Enum.text),
|
|
437
|
-
min: import_zod4.default.number().nullable(),
|
|
438
|
-
max: import_zod4.default.number().nullable()
|
|
439
|
-
}
|
|
440
|
-
);
|
|
441
|
-
var textareaValueDefinitionSchema = StringValueDefinitionBaseSchema.extend({
|
|
442
|
-
inputType: import_zod4.default.literal(ValueInputTypeSchema.Enum.textarea),
|
|
443
|
-
min: import_zod4.default.number().nullable(),
|
|
444
|
-
max: import_zod4.default.number().nullable()
|
|
445
|
-
});
|
|
446
|
-
var emailValueDefinitionSchema = StringValueDefinitionBaseSchema.extend({
|
|
447
|
-
inputType: import_zod4.default.literal(ValueInputTypeSchema.Enum.email),
|
|
448
|
-
defaultValue: import_zod4.default.string().email().nullable()
|
|
449
|
-
});
|
|
450
|
-
var urlValueDefinitionSchema = StringValueDefinitionBaseSchema.extend({
|
|
451
|
-
inputType: import_zod4.default.literal(ValueInputTypeSchema.Enum.url),
|
|
452
|
-
defaultValue: import_zod4.default.string().url().nullable()
|
|
453
|
-
});
|
|
454
|
-
var ipValueDefinitionSchema = StringValueDefinitionBaseSchema.extend({
|
|
455
|
-
inputType: import_zod4.default.literal(ValueInputTypeSchema.Enum.ip),
|
|
456
|
-
defaultValue: import_zod4.default.string().ip().nullable()
|
|
457
|
-
});
|
|
458
|
-
var dateValueDefinitionSchema = StringValueDefinitionBaseSchema.extend(
|
|
459
|
-
{
|
|
460
|
-
inputType: import_zod4.default.literal(ValueInputTypeSchema.Enum.date),
|
|
461
|
-
defaultValue: import_zod4.default.string().date().nullable()
|
|
462
|
-
}
|
|
463
|
-
);
|
|
464
|
-
var timeValueDefinitionSchema = StringValueDefinitionBaseSchema.extend(
|
|
465
|
-
{
|
|
466
|
-
inputType: import_zod4.default.literal(ValueInputTypeSchema.Enum.time),
|
|
467
|
-
defaultValue: import_zod4.default.string().time().nullable()
|
|
468
|
-
}
|
|
469
|
-
);
|
|
470
|
-
var datetimeValueDefinitionSchema = StringValueDefinitionBaseSchema.extend({
|
|
471
|
-
inputType: import_zod4.default.literal(ValueInputTypeSchema.Enum.datetime),
|
|
472
|
-
defaultValue: import_zod4.default.string().datetime().nullable()
|
|
473
|
-
});
|
|
474
|
-
var telephoneValueDefinitionSchema = StringValueDefinitionBaseSchema.extend({
|
|
475
|
-
inputType: import_zod4.default.literal(ValueInputTypeSchema.Enum.telephone)
|
|
476
|
-
// defaultValue: z.string().e164(), @todo when zod v4 releases @see https://github.com/colinhacks/zod/pull/3476
|
|
477
|
-
});
|
|
478
|
-
var stringValueDefinitionSchema = import_zod4.default.union([
|
|
479
|
-
textValueDefinitionSchema,
|
|
480
|
-
textareaValueDefinitionSchema,
|
|
481
|
-
emailValueDefinitionSchema,
|
|
482
|
-
urlValueDefinitionSchema,
|
|
483
|
-
ipValueDefinitionSchema,
|
|
484
|
-
dateValueDefinitionSchema,
|
|
485
|
-
timeValueDefinitionSchema,
|
|
486
|
-
datetimeValueDefinitionSchema,
|
|
487
|
-
telephoneValueDefinitionSchema
|
|
488
|
-
]);
|
|
489
|
-
var NumberValueDefinitionBaseSchema = ValueDefinitionBaseSchema.extend(
|
|
490
|
-
{
|
|
491
|
-
valueType: import_zod4.default.literal(ValueTypeSchema.Enum.number),
|
|
492
|
-
min: import_zod4.default.number().nullable(),
|
|
493
|
-
max: import_zod4.default.number().nullable(),
|
|
494
|
-
isUnique: import_zod4.default.literal(false),
|
|
495
|
-
defaultValue: import_zod4.default.number().nullable()
|
|
496
|
-
}
|
|
497
|
-
);
|
|
498
|
-
var numberValueDefinitionSchema = NumberValueDefinitionBaseSchema.extend({
|
|
499
|
-
inputType: import_zod4.default.literal(ValueInputTypeSchema.Enum.number)
|
|
500
|
-
});
|
|
501
|
-
var rangeValueDefinitionSchema = NumberValueDefinitionBaseSchema.extend({
|
|
502
|
-
inputType: import_zod4.default.literal(ValueInputTypeSchema.Enum.range),
|
|
503
|
-
// Overwrite from nullable to required because a range needs min, max and default to work and is required, since it always returns a number
|
|
504
|
-
isRequired: import_zod4.default.literal(true),
|
|
505
|
-
min: import_zod4.default.number(),
|
|
506
|
-
max: import_zod4.default.number(),
|
|
507
|
-
defaultValue: import_zod4.default.number()
|
|
508
|
-
});
|
|
509
|
-
var BooleanValueDefinitionBaseSchema = ValueDefinitionBaseSchema.extend({
|
|
510
|
-
valueType: import_zod4.default.literal(ValueTypeSchema.Enum.boolean),
|
|
511
|
-
// Overwrite from nullable to required because a boolean needs a default to work and is required, since it always is either true or false
|
|
512
|
-
isRequired: import_zod4.default.literal(true),
|
|
513
|
-
defaultValue: import_zod4.default.boolean(),
|
|
514
|
-
isUnique: import_zod4.default.literal(false)
|
|
515
|
-
});
|
|
516
|
-
var toggleValueDefinitionSchema = BooleanValueDefinitionBaseSchema.extend({
|
|
517
|
-
inputType: import_zod4.default.literal(ValueInputTypeSchema.Enum.toggle)
|
|
518
|
-
});
|
|
519
|
-
var ReferenceValueDefinitionBaseSchema = ValueDefinitionBaseSchema.extend({
|
|
520
|
-
valueType: import_zod4.default.literal(ValueTypeSchema.Enum.reference)
|
|
521
|
-
});
|
|
522
|
-
var assetValueDefinitionSchema = ReferenceValueDefinitionBaseSchema.extend({
|
|
523
|
-
inputType: import_zod4.default.literal(ValueInputTypeSchema.Enum.asset),
|
|
524
|
-
allowedMimeTypes: import_zod4.default.array(supportedAssetMimeTypeSchema).min(1),
|
|
525
|
-
min: import_zod4.default.number().nullable(),
|
|
526
|
-
max: import_zod4.default.number().nullable()
|
|
527
|
-
});
|
|
528
|
-
var entryValueDefinitionSchema = ReferenceValueDefinitionBaseSchema.extend({
|
|
529
|
-
inputType: import_zod4.default.literal(ValueInputTypeSchema.Enum.entry),
|
|
530
|
-
ofCollections: import_zod4.default.array(uuidSchema),
|
|
531
|
-
min: import_zod4.default.number().nullable(),
|
|
532
|
-
max: import_zod4.default.number().nullable()
|
|
533
|
-
});
|
|
534
|
-
var valueDefinitionSchema = import_zod4.default.union([
|
|
535
|
-
stringValueDefinitionSchema,
|
|
536
|
-
numberValueDefinitionSchema,
|
|
537
|
-
rangeValueDefinitionSchema,
|
|
538
|
-
toggleValueDefinitionSchema,
|
|
539
|
-
assetValueDefinitionSchema,
|
|
540
|
-
entryValueDefinitionSchema
|
|
541
|
-
// sharedValueDefinitionSchema,
|
|
542
|
-
]);
|
|
543
|
-
var valueContentReferenceBase = import_zod4.default.object({
|
|
544
|
-
id: uuidSchema
|
|
545
|
-
});
|
|
546
|
-
var valueContentReferenceWithLanguageBase = valueContentReferenceBase.extend({
|
|
547
|
-
language: supportedLanguageSchema
|
|
548
|
-
});
|
|
549
|
-
var valueContentReferenceToAssetSchema = valueContentReferenceWithLanguageBase.extend({
|
|
550
|
-
objectType: import_zod4.default.literal(objectTypeSchema.Enum.asset)
|
|
551
|
-
});
|
|
552
|
-
var valueContentReferenceToCollectionSchema = valueContentReferenceBase.extend({
|
|
553
|
-
objectType: import_zod4.default.literal(objectTypeSchema.Enum.collection)
|
|
554
|
-
});
|
|
555
|
-
var valueContentReferenceToEntrySchema = valueContentReferenceBase.extend({
|
|
556
|
-
objectType: import_zod4.default.literal(objectTypeSchema.Enum.entry)
|
|
557
|
-
});
|
|
558
|
-
var valueContentReferenceSchema = import_zod4.default.union([
|
|
559
|
-
valueContentReferenceToAssetSchema,
|
|
560
|
-
valueContentReferenceToCollectionSchema,
|
|
561
|
-
valueContentReferenceToEntrySchema
|
|
562
|
-
// valueContentReferenceToSharedValueSchema,
|
|
563
|
-
]);
|
|
564
|
-
var resolvedValueContentReferenceSchema = import_zod4.default.union([
|
|
565
|
-
assetSchema,
|
|
566
|
-
import_zod4.default.lazy(() => entrySchema)
|
|
567
|
-
// Circular dependency / recursive type @see https://github.com/colinhacks/zod?tab=readme-ov-file#recursive-types
|
|
568
|
-
// resolvedValueContentReferenceToSharedValueSchema,
|
|
569
|
-
]);
|
|
570
|
-
var directValueBaseSchema = import_zod4.default.object({
|
|
571
|
-
objectType: import_zod4.default.literal(objectTypeSchema.Enum.value).readonly(),
|
|
572
|
-
definitionId: uuidSchema.readonly()
|
|
573
|
-
});
|
|
574
|
-
var directStringValueSchema = directValueBaseSchema.extend({
|
|
575
|
-
valueType: import_zod4.default.literal(ValueTypeSchema.Enum.string).readonly(),
|
|
576
|
-
content: translatableStringSchema
|
|
577
|
-
});
|
|
578
|
-
var directNumberValueSchema = directValueBaseSchema.extend({
|
|
579
|
-
valueType: import_zod4.default.literal(ValueTypeSchema.Enum.number).readonly(),
|
|
580
|
-
content: translatableNumberSchema
|
|
581
|
-
});
|
|
582
|
-
var directBooleanValueSchema = directValueBaseSchema.extend({
|
|
583
|
-
valueType: import_zod4.default.literal(ValueTypeSchema.Enum.boolean).readonly(),
|
|
584
|
-
content: translatableBooleanSchema
|
|
585
|
-
});
|
|
586
|
-
var directValueSchema = import_zod4.default.union([
|
|
587
|
-
directStringValueSchema,
|
|
588
|
-
directNumberValueSchema,
|
|
589
|
-
directBooleanValueSchema
|
|
590
|
-
]);
|
|
591
|
-
var referencedValueSchema = import_zod4.default.object({
|
|
592
|
-
objectType: import_zod4.default.literal(objectTypeSchema.Enum.value).readonly(),
|
|
593
|
-
definitionId: uuidSchema.readonly(),
|
|
594
|
-
valueType: import_zod4.default.literal(ValueTypeSchema.Enum.reference).readonly(),
|
|
595
|
-
content: translatableArrayOf(valueContentReferenceSchema)
|
|
596
|
-
});
|
|
597
|
-
var valueSchema = import_zod4.default.union([directValueSchema, referencedValueSchema]);
|
|
598
|
-
var resolvedReferencedValueSchema = referencedValueSchema.extend({
|
|
599
|
-
content: translatableArrayOf(resolvedValueContentReferenceSchema)
|
|
600
|
-
});
|
|
601
|
-
var resolvedValueSchema = import_zod4.default.union([
|
|
602
|
-
directValueSchema,
|
|
603
|
-
resolvedReferencedValueSchema
|
|
604
|
-
]);
|
|
605
|
-
function getValueContentSchemaFromDefinition(definition) {
|
|
606
|
-
switch (definition.valueType) {
|
|
607
|
-
case ValueTypeSchema.Enum.boolean:
|
|
608
|
-
return getBooleanValueContentSchema(definition);
|
|
609
|
-
case ValueTypeSchema.Enum.number:
|
|
610
|
-
return getNumberValueContentSchema(definition);
|
|
611
|
-
case ValueTypeSchema.Enum.string:
|
|
612
|
-
return getStringValueContentSchema(definition);
|
|
613
|
-
case ValueTypeSchema.Enum.reference:
|
|
614
|
-
return getReferenceValueContentSchema(definition);
|
|
615
|
-
default:
|
|
616
|
-
throw new Error(
|
|
617
|
-
// @ts-expect-error
|
|
618
|
-
`Error generating schema for unsupported ValueType "${definition.valueType}"`
|
|
619
|
-
);
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
function getBooleanValueContentSchema(definition) {
|
|
623
|
-
return import_zod4.default.boolean();
|
|
624
|
-
}
|
|
625
|
-
function getNumberValueContentSchema(definition) {
|
|
626
|
-
let schema = import_zod4.default.number();
|
|
627
|
-
if (definition.min) {
|
|
628
|
-
schema = schema.min(definition.min);
|
|
629
|
-
}
|
|
630
|
-
if (definition.max) {
|
|
631
|
-
schema = schema.max(definition.max);
|
|
632
|
-
}
|
|
633
|
-
if (definition.isRequired === false) {
|
|
634
|
-
return schema.nullable();
|
|
635
|
-
}
|
|
636
|
-
return schema;
|
|
637
|
-
}
|
|
638
|
-
function getStringValueContentSchema(definition) {
|
|
639
|
-
let schema = import_zod4.default.string().trim();
|
|
640
|
-
if ("min" in definition && definition.min) {
|
|
641
|
-
schema = schema.min(definition.min);
|
|
642
|
-
}
|
|
643
|
-
if ("max" in definition && definition.max) {
|
|
644
|
-
schema = schema.max(definition.max);
|
|
645
|
-
}
|
|
646
|
-
switch (definition.inputType) {
|
|
647
|
-
case ValueInputTypeSchema.Enum.email:
|
|
648
|
-
schema = schema.email();
|
|
649
|
-
break;
|
|
650
|
-
case ValueInputTypeSchema.Enum.url:
|
|
651
|
-
schema = schema.url();
|
|
652
|
-
break;
|
|
653
|
-
case ValueInputTypeSchema.Enum.ip:
|
|
654
|
-
schema = schema.ip();
|
|
655
|
-
break;
|
|
656
|
-
case ValueInputTypeSchema.Enum.date:
|
|
657
|
-
schema = schema.date();
|
|
658
|
-
break;
|
|
659
|
-
case ValueInputTypeSchema.Enum.time:
|
|
660
|
-
schema = schema.time();
|
|
661
|
-
break;
|
|
662
|
-
case ValueInputTypeSchema.Enum.datetime:
|
|
663
|
-
schema = schema.datetime();
|
|
664
|
-
break;
|
|
665
|
-
case ValueInputTypeSchema.Enum.telephone:
|
|
666
|
-
break;
|
|
667
|
-
}
|
|
668
|
-
if (definition.isRequired === false) {
|
|
669
|
-
return schema.nullable();
|
|
670
|
-
}
|
|
671
|
-
return schema.min(1, "shared.stringValueRequired");
|
|
672
|
-
}
|
|
673
|
-
function getReferenceValueContentSchema(definition) {
|
|
674
|
-
let schema;
|
|
675
|
-
switch (definition.inputType) {
|
|
676
|
-
case ValueInputTypeSchema.Enum.asset:
|
|
677
|
-
{
|
|
678
|
-
schema = import_zod4.default.array(valueContentReferenceToAssetSchema);
|
|
679
|
-
}
|
|
680
|
-
break;
|
|
681
|
-
case ValueInputTypeSchema.Enum.entry:
|
|
682
|
-
{
|
|
683
|
-
schema = import_zod4.default.array(valueContentReferenceToEntrySchema);
|
|
684
|
-
}
|
|
685
|
-
break;
|
|
686
|
-
}
|
|
687
|
-
if (definition.isRequired) {
|
|
688
|
-
schema = schema.min(1, "shared.referenceRequired");
|
|
689
|
-
}
|
|
690
|
-
if (definition.min) {
|
|
691
|
-
schema = schema.min(definition.min);
|
|
692
|
-
}
|
|
693
|
-
if (definition.max) {
|
|
694
|
-
schema = schema.max(definition.max);
|
|
695
|
-
}
|
|
696
|
-
return schema;
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
// src/schema/entrySchema.ts
|
|
700
|
-
var entryFileSchema = baseFileSchema.extend({
|
|
701
|
-
objectType: import_zod5.default.literal(objectTypeSchema.Enum.entry).readonly(),
|
|
702
|
-
values: import_zod5.default.array(valueSchema)
|
|
703
|
-
});
|
|
704
|
-
var entrySchema = entryFileSchema.extend({
|
|
705
|
-
values: import_zod5.default.array(import_zod5.default.lazy(() => resolvedValueSchema))
|
|
706
|
-
});
|
|
707
|
-
var entryExportSchema = entrySchema.extend({});
|
|
708
|
-
var createEntrySchema = entryFileSchema.omit({
|
|
709
|
-
id: true,
|
|
710
|
-
objectType: true,
|
|
711
|
-
created: true,
|
|
712
|
-
updated: true
|
|
713
|
-
}).extend({
|
|
714
|
-
projectId: uuidSchema.readonly(),
|
|
715
|
-
collectionId: uuidSchema.readonly(),
|
|
716
|
-
values: import_zod5.default.array(valueSchema)
|
|
717
|
-
});
|
|
718
|
-
var readEntrySchema = import_zod5.default.object({
|
|
719
|
-
id: uuidSchema.readonly(),
|
|
720
|
-
projectId: uuidSchema.readonly(),
|
|
721
|
-
collectionId: uuidSchema.readonly()
|
|
722
|
-
});
|
|
723
|
-
var updateEntrySchema = entrySchema.omit({
|
|
724
|
-
objectType: true,
|
|
725
|
-
created: true,
|
|
726
|
-
updated: true
|
|
727
|
-
}).extend({
|
|
728
|
-
projectId: uuidSchema.readonly(),
|
|
729
|
-
collectionId: uuidSchema.readonly()
|
|
730
|
-
});
|
|
731
|
-
var deleteEntrySchema = readEntrySchema.extend({});
|
|
732
|
-
var countEntriesSchema = import_zod5.default.object({
|
|
733
|
-
projectId: uuidSchema.readonly(),
|
|
734
|
-
collectionId: uuidSchema.readonly()
|
|
735
|
-
});
|
|
736
|
-
|
|
737
|
-
// src/schema/collectionSchema.ts
|
|
738
|
-
var collectionFileSchema = baseFileSchema.extend({
|
|
739
|
-
objectType: import_zod6.default.literal(objectTypeSchema.Enum.collection).readonly(),
|
|
740
|
-
name: import_zod6.default.object({
|
|
741
|
-
singular: translatableStringSchema,
|
|
742
|
-
plural: translatableStringSchema
|
|
743
|
-
}),
|
|
744
|
-
slug: import_zod6.default.object({
|
|
745
|
-
singular: import_zod6.default.string(),
|
|
746
|
-
plural: import_zod6.default.string()
|
|
747
|
-
}),
|
|
748
|
-
description: translatableStringSchema,
|
|
749
|
-
icon: supportedIconSchema,
|
|
750
|
-
valueDefinitions: import_zod6.default.array(valueDefinitionSchema)
|
|
751
|
-
});
|
|
752
|
-
var collectionSchema = collectionFileSchema.extend({});
|
|
753
|
-
var collectionExportSchema = collectionSchema.extend({
|
|
754
|
-
entries: import_zod6.default.array(entryExportSchema)
|
|
755
|
-
});
|
|
756
|
-
var createCollectionSchema = collectionSchema.omit({
|
|
757
|
-
id: true,
|
|
758
|
-
objectType: true,
|
|
759
|
-
created: true,
|
|
760
|
-
updated: true
|
|
761
|
-
}).extend({
|
|
762
|
-
projectId: uuidSchema.readonly()
|
|
763
|
-
});
|
|
764
|
-
var readCollectionSchema = import_zod6.default.object({
|
|
765
|
-
id: uuidSchema.readonly(),
|
|
766
|
-
projectId: uuidSchema.readonly()
|
|
767
|
-
});
|
|
768
|
-
var updateCollectionSchema = collectionFileSchema.pick({
|
|
769
|
-
id: true,
|
|
770
|
-
name: true,
|
|
771
|
-
slug: true,
|
|
772
|
-
description: true,
|
|
773
|
-
icon: true,
|
|
774
|
-
valueDefinitions: true
|
|
775
|
-
}).extend({
|
|
776
|
-
projectId: uuidSchema.readonly()
|
|
777
|
-
});
|
|
778
|
-
var deleteCollectionSchema = readCollectionSchema.extend({});
|
|
779
|
-
var countCollectionsSchema = import_zod6.default.object({
|
|
780
|
-
projectId: uuidSchema.readonly()
|
|
781
|
-
});
|
|
782
|
-
|
|
783
|
-
// src/schema/coreSchema.ts
|
|
784
|
-
var import_zod7 = require("zod");
|
|
785
|
-
var elekIoCoreOptionsSchema = import_zod7.z.object({
|
|
786
|
-
/**
|
|
787
|
-
* The environment elek.io Core is currently running in
|
|
788
|
-
*/
|
|
789
|
-
environment: environmentSchema,
|
|
790
|
-
/**
|
|
791
|
-
* The current version of elek.io Core
|
|
792
|
-
*/
|
|
793
|
-
version: versionSchema,
|
|
794
|
-
file: import_zod7.z.object({
|
|
795
|
-
json: import_zod7.z.object({
|
|
796
|
-
/**
|
|
797
|
-
* If set, adds indentation with spaces (number) or escape character (string)
|
|
798
|
-
* and line break characters to saved JSON files on disk, to make them easier to read.
|
|
799
|
-
* Defaults to 2 spaces of indentation.
|
|
800
|
-
*/
|
|
801
|
-
indentation: import_zod7.z.union([import_zod7.z.number(), import_zod7.z.string()])
|
|
802
|
-
})
|
|
803
|
-
})
|
|
804
|
-
});
|
|
805
|
-
var constructorElekIoCoreSchema = elekIoCoreOptionsSchema.omit({
|
|
806
|
-
version: true
|
|
807
|
-
}).partial({
|
|
808
|
-
environment: true,
|
|
809
|
-
file: true
|
|
810
|
-
}).optional();
|
|
811
|
-
|
|
812
|
-
// src/schema/gitSchema.ts
|
|
813
|
-
var import_zod8 = require("zod");
|
|
814
|
-
var gitRepositoryPathSchema = import_zod8.z.string();
|
|
815
|
-
var gitSignatureSchema = import_zod8.z.object({
|
|
816
|
-
name: import_zod8.z.string(),
|
|
817
|
-
email: import_zod8.z.string()
|
|
818
|
-
});
|
|
819
|
-
var gitCommitSchema = import_zod8.z.object({
|
|
820
|
-
/**
|
|
821
|
-
* SHA-1 hash of the commit
|
|
822
|
-
*/
|
|
823
|
-
hash: import_zod8.z.string(),
|
|
824
|
-
message: import_zod8.z.string(),
|
|
825
|
-
author: gitSignatureSchema,
|
|
826
|
-
timestamp: import_zod8.z.number(),
|
|
827
|
-
tag: import_zod8.z.string().nullable()
|
|
828
|
-
});
|
|
829
|
-
var GitCommitIconNative = /* @__PURE__ */ ((GitCommitIconNative2) => {
|
|
830
|
-
GitCommitIconNative2["INIT"] = ":tada:";
|
|
831
|
-
GitCommitIconNative2["CREATE"] = ":heavy_plus_sign:";
|
|
832
|
-
GitCommitIconNative2["UPDATE"] = ":wrench:";
|
|
833
|
-
GitCommitIconNative2["DELETE"] = ":fire:";
|
|
834
|
-
return GitCommitIconNative2;
|
|
835
|
-
})(GitCommitIconNative || {});
|
|
836
|
-
var gitCommitIconSchema = import_zod8.z.nativeEnum(GitCommitIconNative);
|
|
837
|
-
var gitInitOptionsSchema = import_zod8.z.object({
|
|
838
|
-
/**
|
|
839
|
-
* 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).
|
|
840
|
-
*/
|
|
841
|
-
initialBranch: import_zod8.z.string()
|
|
842
|
-
});
|
|
843
|
-
var gitCloneOptionsSchema = import_zod8.z.object({
|
|
844
|
-
/**
|
|
845
|
-
* Create a shallow clone with a history truncated to the specified number of commits. Implies --single-branch unless --no-single-branch is given to fetch the histories near the tips of all branches. If you want to clone submodules shallowly, also pass --shallow-submodules.
|
|
846
|
-
*/
|
|
847
|
-
depth: import_zod8.z.number(),
|
|
848
|
-
/**
|
|
849
|
-
* Clone only the history leading to the tip of a single branch, either specified by the --branch option or the primary branch remote’s HEAD points at. Further fetches into the resulting repository will only update the remote-tracking branch for the branch this option was used for the initial cloning. If the HEAD at the remote did not point at any branch when --single-branch clone was made, no remote-tracking branch is created.
|
|
850
|
-
*/
|
|
851
|
-
singleBranch: import_zod8.z.boolean(),
|
|
852
|
-
/**
|
|
853
|
-
* 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.
|
|
854
|
-
*/
|
|
855
|
-
branch: import_zod8.z.string()
|
|
856
|
-
});
|
|
857
|
-
var gitSwitchOptionsSchema = import_zod8.z.object({
|
|
858
|
-
/**
|
|
859
|
-
* If true, creates a new local branch and then switches to it
|
|
860
|
-
*
|
|
861
|
-
* @see https://git-scm.com/docs/git-switch#Documentation/git-switch.txt---createltnew-branchgt
|
|
862
|
-
*/
|
|
863
|
-
isNew: import_zod8.z.boolean().optional()
|
|
864
|
-
});
|
|
865
|
-
var gitLogOptionsSchema = import_zod8.z.object({
|
|
866
|
-
/**
|
|
867
|
-
* Limit the result to given number of commits
|
|
868
|
-
*/
|
|
869
|
-
limit: import_zod8.z.number().optional(),
|
|
870
|
-
/**
|
|
871
|
-
* Only list commits that are between given SHAs or tag names
|
|
872
|
-
*
|
|
873
|
-
* Note that the commits of from and to are not included in the result
|
|
874
|
-
*/
|
|
875
|
-
between: import_zod8.z.object({
|
|
876
|
-
/**
|
|
877
|
-
* From the oldest commit
|
|
878
|
-
*/
|
|
879
|
-
from: import_zod8.z.string(),
|
|
880
|
-
/**
|
|
881
|
-
* To the newest commit
|
|
882
|
-
*
|
|
883
|
-
* Defaults to the current HEAD
|
|
884
|
-
*/
|
|
885
|
-
to: import_zod8.z.string().optional()
|
|
886
|
-
})
|
|
887
|
-
});
|
|
888
|
-
|
|
889
|
-
// src/schema/gitTagSchema.ts
|
|
890
|
-
var import_zod9 = require("zod");
|
|
891
|
-
var gitTagSchema = import_zod9.z.object({
|
|
892
|
-
id: uuidSchema,
|
|
893
|
-
message: import_zod9.z.string(),
|
|
894
|
-
author: gitSignatureSchema,
|
|
895
|
-
timestamp: import_zod9.z.number()
|
|
896
|
-
});
|
|
897
|
-
var createGitTagSchema = gitTagSchema.pick({
|
|
898
|
-
message: true
|
|
899
|
-
}).extend({
|
|
900
|
-
path: gitRepositoryPathSchema,
|
|
901
|
-
hash: gitCommitSchema.shape.hash.optional()
|
|
902
|
-
});
|
|
903
|
-
var readGitTagSchema = import_zod9.z.object({
|
|
904
|
-
path: gitRepositoryPathSchema,
|
|
905
|
-
id: uuidSchema.readonly()
|
|
906
|
-
});
|
|
907
|
-
var deleteGitTagSchema = readGitTagSchema.extend({});
|
|
908
|
-
var countGitTagsSchema = import_zod9.z.object({
|
|
909
|
-
path: gitRepositoryPathSchema
|
|
910
|
-
});
|
|
911
|
-
|
|
912
|
-
// src/schema/projectSchema.ts
|
|
913
|
-
var import_zod10 = require("zod");
|
|
914
|
-
var projectStatusSchema = import_zod10.z.enum(["foo", "bar", "todo"]);
|
|
915
|
-
var projectSettingsSchema = import_zod10.z.object({
|
|
916
|
-
language: import_zod10.z.object({
|
|
917
|
-
default: supportedLanguageSchema,
|
|
918
|
-
supported: import_zod10.z.array(supportedLanguageSchema)
|
|
919
|
-
})
|
|
920
|
-
});
|
|
921
|
-
var projectFolderSchema = import_zod10.z.enum([
|
|
922
|
-
"assets",
|
|
923
|
-
"collections",
|
|
924
|
-
"shared-values",
|
|
925
|
-
"lfs"
|
|
926
|
-
// 'logs',
|
|
927
|
-
// 'public',
|
|
928
|
-
// 'theme',
|
|
929
|
-
]);
|
|
930
|
-
var projectFileSchema = baseFileSchema.extend({
|
|
931
|
-
objectType: import_zod10.z.literal(objectTypeSchema.Enum.project).readonly(),
|
|
932
|
-
coreVersion: versionSchema,
|
|
933
|
-
name: import_zod10.z.string().trim().min(1, "shared.projectNameRequired"),
|
|
934
|
-
description: import_zod10.z.string().trim().min(1, "shared.projectDescriptionRequired"),
|
|
935
|
-
version: versionSchema,
|
|
936
|
-
status: projectStatusSchema,
|
|
937
|
-
settings: projectSettingsSchema
|
|
938
|
-
});
|
|
939
|
-
var projectSchema = projectFileSchema.extend({});
|
|
940
|
-
var projectExportSchema = projectSchema.extend({
|
|
941
|
-
assets: import_zod10.z.array(assetExportSchema),
|
|
942
|
-
collections: import_zod10.z.array(collectionExportSchema)
|
|
943
|
-
});
|
|
944
|
-
var createProjectSchema = projectSchema.pick({
|
|
945
|
-
name: true,
|
|
946
|
-
description: true,
|
|
947
|
-
settings: true
|
|
948
|
-
}).partial({
|
|
949
|
-
description: true,
|
|
950
|
-
settings: true
|
|
951
|
-
});
|
|
952
|
-
var readProjectSchema = import_zod10.z.object({
|
|
953
|
-
id: uuidSchema.readonly()
|
|
954
|
-
});
|
|
955
|
-
var updateProjectSchema = projectSchema.pick({
|
|
956
|
-
id: true,
|
|
957
|
-
name: true,
|
|
958
|
-
description: true,
|
|
959
|
-
settings: true
|
|
960
|
-
}).partial({
|
|
961
|
-
name: true,
|
|
962
|
-
description: true,
|
|
963
|
-
settings: true
|
|
964
|
-
});
|
|
965
|
-
var upgradeProjectSchema = import_zod10.z.object({
|
|
966
|
-
id: uuidSchema.readonly()
|
|
967
|
-
});
|
|
968
|
-
var deleteProjectSchema = readProjectSchema.extend({});
|
|
969
|
-
var projectUpgradeSchema = import_zod10.z.object({
|
|
970
|
-
/**
|
|
971
|
-
* The Core version the Project will be upgraded to
|
|
972
|
-
*/
|
|
973
|
-
to: versionSchema.readonly(),
|
|
974
|
-
/**
|
|
975
|
-
* Function that will be executed in the process of upgrading a Project
|
|
976
|
-
*/
|
|
977
|
-
run: import_zod10.z.function().args(projectFileSchema).returns(import_zod10.z.promise(import_zod10.z.void()))
|
|
978
|
-
});
|
|
979
|
-
var cloneProjectSchema = import_zod10.z.object({
|
|
980
|
-
url: import_zod10.z.string()
|
|
981
|
-
});
|
|
982
|
-
var listBranchesProjectSchema = import_zod10.z.object({
|
|
983
|
-
id: uuidSchema.readonly()
|
|
984
|
-
});
|
|
985
|
-
var currentBranchProjectSchema = import_zod10.z.object({
|
|
986
|
-
id: uuidSchema.readonly()
|
|
987
|
-
});
|
|
988
|
-
var switchBranchProjectSchema = import_zod10.z.object({
|
|
989
|
-
id: uuidSchema.readonly(),
|
|
990
|
-
branch: import_zod10.z.string(),
|
|
991
|
-
options: gitSwitchOptionsSchema.optional()
|
|
992
|
-
});
|
|
993
|
-
var getRemoteOriginUrlProjectSchema = import_zod10.z.object({
|
|
994
|
-
id: uuidSchema.readonly()
|
|
995
|
-
});
|
|
996
|
-
var setRemoteOriginUrlProjectSchema = import_zod10.z.object({
|
|
997
|
-
id: uuidSchema.readonly(),
|
|
998
|
-
url: import_zod10.z.string()
|
|
999
|
-
});
|
|
1000
|
-
var getChangesProjectSchema = import_zod10.z.object({
|
|
1001
|
-
id: uuidSchema.readonly()
|
|
1002
|
-
});
|
|
1003
|
-
var synchronizeProjectSchema = import_zod10.z.object({
|
|
1004
|
-
id: uuidSchema.readonly()
|
|
1005
|
-
});
|
|
1006
|
-
var searchProjectSchema = import_zod10.z.object({
|
|
1007
|
-
id: uuidSchema.readonly(),
|
|
1008
|
-
query: import_zod10.z.string(),
|
|
1009
|
-
language: supportedLanguageSchema,
|
|
1010
|
-
type: import_zod10.z.array(objectTypeSchema).optional()
|
|
1011
|
-
});
|
|
1012
|
-
|
|
1013
|
-
// src/schema/serviceSchema.ts
|
|
1014
|
-
var import_zod11 = require("zod");
|
|
1015
|
-
var serviceTypeSchema = import_zod11.z.enum([
|
|
1016
|
-
"Git",
|
|
1017
|
-
"GitTag",
|
|
1018
|
-
"User",
|
|
1019
|
-
"Project",
|
|
1020
|
-
"Asset",
|
|
1021
|
-
"JsonFile",
|
|
1022
|
-
"Search",
|
|
1023
|
-
"Collection",
|
|
1024
|
-
"Entry",
|
|
1025
|
-
"Value"
|
|
1026
|
-
]);
|
|
1027
|
-
var listSchema = import_zod11.z.object({
|
|
1028
|
-
projectId: uuidSchema,
|
|
1029
|
-
limit: import_zod11.z.number().optional(),
|
|
1030
|
-
offset: import_zod11.z.number().optional()
|
|
1031
|
-
});
|
|
1032
|
-
var listCollectionsSchema = listSchema;
|
|
1033
|
-
var listEntriesSchema = listSchema.extend({
|
|
1034
|
-
collectionId: uuidSchema
|
|
1035
|
-
});
|
|
1036
|
-
var listAssetsSchema = listSchema;
|
|
1037
|
-
var listProjectsSchema = listSchema.omit({
|
|
1038
|
-
projectId: true
|
|
1039
|
-
});
|
|
1040
|
-
var listGitTagsSchema = import_zod11.z.object({
|
|
1041
|
-
path: gitRepositoryPathSchema
|
|
1042
|
-
});
|
|
1043
|
-
|
|
1044
|
-
// src/schema/userSchema.ts
|
|
1045
|
-
var import_zod12 = __toESM(require("zod"), 1);
|
|
1046
|
-
var UserTypeSchema = import_zod12.default.enum(["local", "cloud"]);
|
|
1047
|
-
var baseUserSchema = gitSignatureSchema.extend({
|
|
1048
|
-
userType: UserTypeSchema,
|
|
1049
|
-
language: supportedLanguageSchema
|
|
1050
|
-
});
|
|
1051
|
-
var localUserSchema = baseUserSchema.extend({
|
|
1052
|
-
userType: import_zod12.default.literal(UserTypeSchema.Enum.local)
|
|
1053
|
-
});
|
|
1054
|
-
var cloudUserSchema = baseUserSchema.extend({
|
|
1055
|
-
userType: import_zod12.default.literal(UserTypeSchema.Enum.cloud),
|
|
1056
|
-
id: uuidSchema
|
|
1057
|
-
});
|
|
1058
|
-
var userFileSchema = import_zod12.default.union([localUserSchema, cloudUserSchema]);
|
|
1059
|
-
var userSchema = userFileSchema;
|
|
1060
|
-
var setUserSchema = userSchema;
|
|
1061
|
-
|
|
1062
|
-
// src/error/GitError.ts
|
|
1063
|
-
var GitError = class extends Error {
|
|
1064
|
-
constructor(message) {
|
|
1065
|
-
super(message);
|
|
1066
|
-
this.name = "GitError";
|
|
1067
|
-
}
|
|
1068
|
-
};
|
|
1069
|
-
|
|
1070
|
-
// src/error/NoCurrentUserError.ts
|
|
1071
|
-
var NoCurrentUserError = class extends Error {
|
|
1072
|
-
constructor() {
|
|
1073
|
-
super("Make sure to set a User via Core before using other methods");
|
|
1074
|
-
this.name = "NoCurrentUserError";
|
|
1075
|
-
}
|
|
1076
|
-
};
|
|
1077
|
-
|
|
1078
|
-
// src/error/ProjectUpgradeError.ts
|
|
1079
|
-
var ProjectUpgradeError = class extends Error {
|
|
1080
|
-
constructor(message) {
|
|
1081
|
-
super(message);
|
|
1082
|
-
this.name = "ProjectUpgradeError";
|
|
1083
|
-
}
|
|
1084
|
-
};
|
|
1085
|
-
|
|
1086
|
-
// src/error/RequiredParameterMissingError.ts
|
|
1087
|
-
var RequiredParameterMissingError = class extends Error {
|
|
1088
|
-
constructor(parameter) {
|
|
1089
|
-
super(`Missing required parameter "${parameter}"`);
|
|
1090
|
-
this.name = "RequiredParameterMissingError";
|
|
1091
|
-
}
|
|
1092
|
-
};
|
|
1093
|
-
|
|
1094
|
-
// src/util/node.ts
|
|
1095
|
-
var node_exports = {};
|
|
1096
|
-
__export(node_exports, {
|
|
1097
|
-
assignDefaultIfMissing: () => assignDefaultIfMissing,
|
|
1098
|
-
files: () => files,
|
|
1099
|
-
folders: () => folders,
|
|
1100
|
-
isNoError: () => isNoError,
|
|
1101
|
-
notEmpty: () => notEmpty,
|
|
1102
|
-
pathTo: () => pathTo,
|
|
1103
|
-
returnResolved: () => returnResolved,
|
|
1104
|
-
spawnChildProcess: () => spawnChildProcess,
|
|
1105
|
-
workingDirectory: () => workingDirectory
|
|
1106
|
-
});
|
|
1107
|
-
var import_child_process = require("child_process");
|
|
1108
|
-
var import_fs_extra = __toESM(require("fs-extra"), 1);
|
|
1109
|
-
var import_os = __toESM(require("os"), 1);
|
|
1110
|
-
var import_path = __toESM(require("path"), 1);
|
|
1111
|
-
var workingDirectory = import_path.default.join(import_os.default.homedir(), "elek.io");
|
|
1112
|
-
var pathTo = {
|
|
1113
|
-
tmp: import_path.default.join(workingDirectory, "tmp"),
|
|
1114
|
-
userFile: import_path.default.join(workingDirectory, "user.json"),
|
|
1115
|
-
// logs: Path.join(workingDirectory, 'logs'),
|
|
1116
|
-
projects: import_path.default.join(workingDirectory, "projects"),
|
|
1117
|
-
project: (projectId) => {
|
|
1118
|
-
return import_path.default.join(pathTo.projects, projectId);
|
|
1119
|
-
},
|
|
1120
|
-
projectFile: (projectId) => {
|
|
1121
|
-
return import_path.default.join(pathTo.project(projectId), "project.json");
|
|
1122
|
-
},
|
|
1123
|
-
// projectLogs: (projectId: string): string => {
|
|
1124
|
-
// return Path.join(pathTo.project(projectId), projectFolderSchema.Enum.logs);
|
|
1125
|
-
// },
|
|
1126
|
-
// public: (projectId: string): string => {
|
|
1127
|
-
// return Path.join(pathTo.project(projectId), 'public');
|
|
1128
|
-
// },
|
|
1129
|
-
lfs: (projectId) => {
|
|
1130
|
-
return import_path.default.join(pathTo.project(projectId), projectFolderSchema.Enum.lfs);
|
|
1131
|
-
},
|
|
1132
|
-
collections: (projectId) => {
|
|
1133
|
-
return import_path.default.join(
|
|
1134
|
-
pathTo.project(projectId),
|
|
1135
|
-
projectFolderSchema.Enum.collections
|
|
1136
|
-
);
|
|
1137
|
-
},
|
|
1138
|
-
collection: (projectId, id) => {
|
|
1139
|
-
return import_path.default.join(pathTo.collections(projectId), id);
|
|
1140
|
-
},
|
|
1141
|
-
collectionFile: (projectId, id) => {
|
|
1142
|
-
return import_path.default.join(pathTo.collection(projectId, id), "collection.json");
|
|
1143
|
-
},
|
|
1144
|
-
entries: (projectId, collectionId) => {
|
|
1145
|
-
return import_path.default.join(pathTo.collection(projectId, collectionId));
|
|
1146
|
-
},
|
|
1147
|
-
entryFile: (projectId, collectionId, id) => {
|
|
1148
|
-
return import_path.default.join(pathTo.entries(projectId, collectionId), `${id}.json`);
|
|
1149
|
-
},
|
|
1150
|
-
sharedValues: (projectId) => {
|
|
1151
|
-
return import_path.default.join(pathTo.project(projectId), "shared-values");
|
|
1152
|
-
},
|
|
1153
|
-
sharedValueFile: (projectId, id, language) => {
|
|
1154
|
-
return import_path.default.join(pathTo.sharedValues(projectId), `${id}.${language}.json`);
|
|
1155
|
-
},
|
|
1156
|
-
assets: (projectId) => {
|
|
1157
|
-
return import_path.default.join(
|
|
1158
|
-
pathTo.project(projectId),
|
|
1159
|
-
projectFolderSchema.Enum.assets
|
|
1160
|
-
);
|
|
1161
|
-
},
|
|
1162
|
-
assetFile: (projectId, id, language) => {
|
|
1163
|
-
return import_path.default.join(pathTo.assets(projectId), `${id}.${language}.json`);
|
|
1164
|
-
},
|
|
1165
|
-
asset: (projectId, id, language, extension) => {
|
|
1166
|
-
return import_path.default.join(pathTo.lfs(projectId), `${id}.${language}.${extension}`);
|
|
1167
|
-
}
|
|
1168
|
-
};
|
|
1169
|
-
function assignDefaultIfMissing(value, defaultsTo) {
|
|
1170
|
-
return Object.assign(defaultsTo, value);
|
|
1171
|
-
}
|
|
1172
|
-
function notEmpty(value) {
|
|
1173
|
-
if (value === null || value === void 0) {
|
|
1174
|
-
return false;
|
|
1175
|
-
}
|
|
1176
|
-
if (typeof value === "string") {
|
|
1177
|
-
if (value.trim() === "") {
|
|
1178
|
-
return false;
|
|
1179
|
-
}
|
|
1180
|
-
}
|
|
1181
|
-
return true;
|
|
1182
|
-
}
|
|
1183
|
-
function isNoError(item) {
|
|
1184
|
-
return item instanceof Error !== true;
|
|
1185
|
-
}
|
|
1186
|
-
async function returnResolved(promises) {
|
|
1187
|
-
const toCheck = [];
|
|
1188
|
-
for (let index = 0; index < promises.length; index++) {
|
|
1189
|
-
const promise = promises[index];
|
|
1190
|
-
if (!promise) {
|
|
1191
|
-
throw new Error(`No promise found at index "${index}"`);
|
|
1192
|
-
}
|
|
1193
|
-
toCheck.push(
|
|
1194
|
-
promise.then((result) => {
|
|
1195
|
-
return result;
|
|
1196
|
-
}).catch((error) => {
|
|
1197
|
-
return new Error(error);
|
|
1198
|
-
})
|
|
1199
|
-
);
|
|
1200
|
-
}
|
|
1201
|
-
const checked = await Promise.all(toCheck);
|
|
1202
|
-
return checked.filter(isNoError);
|
|
1203
|
-
}
|
|
1204
|
-
function spawnChildProcess(command, args, options) {
|
|
1205
|
-
return new Promise((resolve, reject) => {
|
|
1206
|
-
const childProcess = (0, import_child_process.spawn)(command, args, options);
|
|
1207
|
-
let log = "";
|
|
1208
|
-
childProcess.stdout.on("data", (data) => {
|
|
1209
|
-
log += data;
|
|
1210
|
-
});
|
|
1211
|
-
childProcess.stderr.on("data", (data) => {
|
|
1212
|
-
log += data;
|
|
1213
|
-
});
|
|
1214
|
-
childProcess.on("error", (error) => {
|
|
1215
|
-
throw error;
|
|
1216
|
-
});
|
|
1217
|
-
childProcess.on("exit", (code) => {
|
|
1218
|
-
if (code === 0) {
|
|
1219
|
-
return resolve(log);
|
|
1220
|
-
}
|
|
1221
|
-
return reject(log);
|
|
1222
|
-
});
|
|
1223
|
-
});
|
|
1224
|
-
}
|
|
1225
|
-
async function folders(path) {
|
|
1226
|
-
const dirent = await import_fs_extra.default.readdir(path, { withFileTypes: true });
|
|
1227
|
-
return dirent.filter((dirent2) => {
|
|
1228
|
-
return dirent2.isDirectory();
|
|
1229
|
-
});
|
|
1230
|
-
}
|
|
1231
|
-
async function files(path, extension) {
|
|
1232
|
-
const dirent = await import_fs_extra.default.readdir(path, { withFileTypes: true });
|
|
1233
|
-
return dirent.filter((dirent2) => {
|
|
1234
|
-
if (extension && dirent2.isFile() === true) {
|
|
1235
|
-
if (dirent2.name.endsWith(extension)) {
|
|
1236
|
-
return true;
|
|
1237
|
-
}
|
|
1238
|
-
return false;
|
|
1239
|
-
}
|
|
1240
|
-
return dirent2.isFile();
|
|
1241
|
-
});
|
|
1242
|
-
}
|
|
1243
|
-
|
|
1244
|
-
// src/service/AbstractCrudService.ts
|
|
1245
|
-
var AbstractCrudService = class {
|
|
1246
|
-
/**
|
|
1247
|
-
* Do not instantiate directly as this is an abstract class
|
|
1248
|
-
*/
|
|
1249
|
-
constructor(type, options) {
|
|
1250
|
-
this.type = type;
|
|
1251
|
-
this.options = options;
|
|
1252
|
-
this.gitMessage = {
|
|
1253
|
-
create: `${gitCommitIconSchema.enum.CREATE} Created ${this.type}`,
|
|
1254
|
-
update: `${gitCommitIconSchema.enum.UPDATE} Updated ${this.type}`,
|
|
1255
|
-
delete: `${gitCommitIconSchema.enum.DELETE} Deleted ${this.type}`
|
|
1256
|
-
};
|
|
1257
|
-
}
|
|
1258
|
-
/**
|
|
1259
|
-
* Returns a list of all file references of given project and type
|
|
1260
|
-
*
|
|
1261
|
-
* @param type File type of the references wanted
|
|
1262
|
-
* @param projectId Project to get all asset references from
|
|
1263
|
-
* @param collectionId Only needed when requesting files of type "Entry"
|
|
1264
|
-
*/
|
|
1265
|
-
async listReferences(type, projectId, collectionId) {
|
|
1266
|
-
switch (type) {
|
|
1267
|
-
case objectTypeSchema.Enum.asset:
|
|
1268
|
-
if (!projectId) {
|
|
1269
|
-
throw new RequiredParameterMissingError("projectId");
|
|
1270
|
-
}
|
|
1271
|
-
return this.getFileReferences(pathTo.lfs(projectId));
|
|
1272
|
-
case objectTypeSchema.Enum.project:
|
|
1273
|
-
return this.getFolderReferences(pathTo.projects);
|
|
1274
|
-
case objectTypeSchema.Enum.collection:
|
|
1275
|
-
if (!projectId) {
|
|
1276
|
-
throw new RequiredParameterMissingError("projectId");
|
|
1277
|
-
}
|
|
1278
|
-
return this.getFolderReferences(pathTo.collections(projectId));
|
|
1279
|
-
case objectTypeSchema.Enum.entry:
|
|
1280
|
-
if (!projectId) {
|
|
1281
|
-
throw new RequiredParameterMissingError("projectId");
|
|
1282
|
-
}
|
|
1283
|
-
if (!collectionId) {
|
|
1284
|
-
throw new RequiredParameterMissingError("collectionId");
|
|
1285
|
-
}
|
|
1286
|
-
return this.getFileReferences(
|
|
1287
|
-
pathTo.collection(projectId, collectionId)
|
|
1288
|
-
);
|
|
1289
|
-
case objectTypeSchema.Enum.sharedValue:
|
|
1290
|
-
if (!projectId) {
|
|
1291
|
-
throw new RequiredParameterMissingError("projectId");
|
|
1292
|
-
}
|
|
1293
|
-
return this.getFileReferences(pathTo.sharedValues(projectId));
|
|
1294
|
-
default:
|
|
1295
|
-
throw new Error(`Trying to list files of unsupported type "${type}"`);
|
|
1296
|
-
}
|
|
1297
|
-
}
|
|
1298
|
-
async getFolderReferences(path) {
|
|
1299
|
-
const possibleFolders = await folders(path);
|
|
1300
|
-
const results = possibleFolders.map((possibleFolder) => {
|
|
1301
|
-
const folderReference = {
|
|
1302
|
-
id: possibleFolder.name
|
|
1303
|
-
};
|
|
1304
|
-
try {
|
|
1305
|
-
return fileReferenceSchema.parse(folderReference);
|
|
1306
|
-
} catch (error) {
|
|
1307
|
-
return null;
|
|
1308
|
-
}
|
|
1309
|
-
});
|
|
1310
|
-
return results.filter(notEmpty);
|
|
1311
|
-
}
|
|
1312
|
-
/**
|
|
1313
|
-
* Searches for all files inside given folder,
|
|
1314
|
-
* parses their names and returns them as FileReference
|
|
1315
|
-
*
|
|
1316
|
-
* Ignores files not matching the [id].[language].[extension]
|
|
1317
|
-
* or [id].[extension] format for their names
|
|
1318
|
-
*/
|
|
1319
|
-
async getFileReferences(path) {
|
|
1320
|
-
const possibleFiles = await files(path);
|
|
1321
|
-
const results = await Promise.all(
|
|
1322
|
-
possibleFiles.map(async (possibleFile) => {
|
|
1323
|
-
const fileNameArray = possibleFile.name.split(".");
|
|
1324
|
-
const fileReference = {
|
|
1325
|
-
id: fileNameArray[0],
|
|
1326
|
-
language: fileNameArray.length === 3 ? fileNameArray[1] : void 0,
|
|
1327
|
-
extension: fileNameArray.length === 2 ? fileNameArray[1] : fileNameArray[2]
|
|
1328
|
-
};
|
|
1329
|
-
try {
|
|
1330
|
-
return fileReferenceSchema.parse(fileReference);
|
|
1331
|
-
} catch (error) {
|
|
1332
|
-
return null;
|
|
1333
|
-
}
|
|
1334
|
-
})
|
|
1335
|
-
);
|
|
1336
|
-
return results.filter(notEmpty);
|
|
1337
|
-
}
|
|
1338
|
-
};
|
|
1339
|
-
|
|
1340
|
-
// src/service/AssetService.ts
|
|
1341
|
-
var import_fs_extra3 = __toESM(require("fs-extra"), 1);
|
|
1342
|
-
var import_is_svg = __toESM(require("is-svg"), 1);
|
|
1343
|
-
|
|
1344
|
-
// src/util/shared.ts
|
|
1345
|
-
var import_slugify = __toESM(require("slugify"), 1);
|
|
1346
|
-
var import_uuid = require("uuid");
|
|
1347
|
-
var Slugify = import_slugify.default.default || import_slugify.default;
|
|
1348
|
-
function uuid() {
|
|
1349
|
-
return (0, import_uuid.v4)();
|
|
1350
|
-
}
|
|
1351
|
-
function currentTimestamp() {
|
|
1352
|
-
return Math.floor(Date.now() / 1e3);
|
|
1353
|
-
}
|
|
1354
|
-
function slug(string) {
|
|
1355
|
-
return Slugify(string, {
|
|
1356
|
-
replacement: "-",
|
|
1357
|
-
// replace spaces with replacement character, defaults to `-`
|
|
1358
|
-
remove: void 0,
|
|
1359
|
-
// remove characters that match regex, defaults to `undefined`
|
|
1360
|
-
lower: true,
|
|
1361
|
-
// convert to lower case, defaults to `false`
|
|
1362
|
-
strict: true
|
|
1363
|
-
// strip special characters except replacement, defaults to `false`
|
|
1364
|
-
});
|
|
1365
|
-
}
|
|
1366
|
-
|
|
1367
|
-
// src/service/JsonFileService.ts
|
|
1368
|
-
var import_fs_extra2 = __toESM(require("fs-extra"), 1);
|
|
1369
|
-
var JsonFileService = class extends AbstractCrudService {
|
|
1370
|
-
constructor(options) {
|
|
1371
|
-
super(serviceTypeSchema.Enum.JsonFile, options);
|
|
1372
|
-
this.cache = /* @__PURE__ */ new Map();
|
|
1373
|
-
}
|
|
1374
|
-
/**
|
|
1375
|
-
* Creates a new file on disk. Fails if path already exists
|
|
1376
|
-
*
|
|
1377
|
-
* @param data Data to write into the file
|
|
1378
|
-
* @param path Path to write the file to
|
|
1379
|
-
* @param schema Schema of the file to validate against
|
|
1380
|
-
* @returns Validated content of the file from disk
|
|
1381
|
-
*/
|
|
1382
|
-
async create(data, path, schema) {
|
|
1383
|
-
const parsedData = schema.parse(data);
|
|
1384
|
-
const string = this.serialize(parsedData);
|
|
1385
|
-
await import_fs_extra2.default.writeFile(path, string, {
|
|
1386
|
-
flag: "wx",
|
|
1387
|
-
encoding: "utf8"
|
|
1388
|
-
});
|
|
1389
|
-
this.cache.set(path, parsedData);
|
|
1390
|
-
return parsedData;
|
|
1391
|
-
}
|
|
1392
|
-
/**
|
|
1393
|
-
* Reads the content of a file on disk. Fails if path does not exist
|
|
1394
|
-
*
|
|
1395
|
-
* @param path Path to read the file from
|
|
1396
|
-
* @param schema Schema of the file to validate against
|
|
1397
|
-
* @returns Validated content of the file from disk
|
|
1398
|
-
*/
|
|
1399
|
-
async read(path, schema) {
|
|
1400
|
-
if (this.cache.has(path)) {
|
|
1401
|
-
return this.cache.get(path);
|
|
1402
|
-
}
|
|
1403
|
-
const data = await import_fs_extra2.default.readFile(path, {
|
|
1404
|
-
flag: "r",
|
|
1405
|
-
encoding: "utf8"
|
|
1406
|
-
});
|
|
1407
|
-
const json = this.deserialize(data);
|
|
1408
|
-
const parsedData = schema.parse(json);
|
|
1409
|
-
this.cache.set(path, parsedData);
|
|
1410
|
-
return parsedData;
|
|
1411
|
-
}
|
|
1412
|
-
/**
|
|
1413
|
-
* Overwrites an existing file on disk
|
|
1414
|
-
*
|
|
1415
|
-
* @todo Check how to error out if the file does not exist already
|
|
1416
|
-
*
|
|
1417
|
-
* @param data Data to write into the file
|
|
1418
|
-
* @param path Path to the file to overwrite
|
|
1419
|
-
* @param schema Schema of the file to validate against
|
|
1420
|
-
* @returns Validated content of the file from disk
|
|
1421
|
-
*/
|
|
1422
|
-
async update(data, path, schema) {
|
|
1423
|
-
const parsedData = schema.parse(data);
|
|
1424
|
-
const string = this.serialize(parsedData);
|
|
1425
|
-
await import_fs_extra2.default.writeFile(path, string, {
|
|
1426
|
-
flag: "w",
|
|
1427
|
-
encoding: "utf8"
|
|
1428
|
-
});
|
|
1429
|
-
this.cache.set(path, parsedData);
|
|
1430
|
-
return parsedData;
|
|
1431
|
-
}
|
|
1432
|
-
serialize(data) {
|
|
1433
|
-
return JSON.stringify(data, null, this.options.file.json.indentation);
|
|
1434
|
-
}
|
|
1435
|
-
deserialize(data) {
|
|
1436
|
-
return JSON.parse(data);
|
|
1437
|
-
}
|
|
1438
|
-
};
|
|
1439
|
-
|
|
1440
|
-
// src/service/AssetService.ts
|
|
1441
|
-
var AssetService = class extends AbstractCrudService {
|
|
1442
|
-
constructor(options, jsonFileService, gitService) {
|
|
1443
|
-
super(serviceTypeSchema.Enum.Asset, options);
|
|
1444
|
-
this.jsonFileService = jsonFileService;
|
|
1445
|
-
this.gitService = gitService;
|
|
1446
|
-
}
|
|
1447
|
-
/**
|
|
1448
|
-
* Creates a new Asset
|
|
1449
|
-
*/
|
|
1450
|
-
async create(props) {
|
|
1451
|
-
createAssetSchema.parse(props);
|
|
1452
|
-
const id = uuid();
|
|
1453
|
-
const projectPath = pathTo.project(props.projectId);
|
|
1454
|
-
const fileType = await this.getSupportedFileTypeOrThrow(props.filePath);
|
|
1455
|
-
const size = await this.getAssetSize(props.filePath);
|
|
1456
|
-
const assetPath = pathTo.asset(
|
|
1457
|
-
props.projectId,
|
|
1458
|
-
id,
|
|
1459
|
-
props.language,
|
|
1460
|
-
fileType.extension
|
|
1461
|
-
);
|
|
1462
|
-
const assetFilePath = pathTo.assetFile(props.projectId, id, props.language);
|
|
1463
|
-
const assetFile = {
|
|
1464
|
-
...props,
|
|
1465
|
-
objectType: "asset",
|
|
1466
|
-
id,
|
|
1467
|
-
created: currentTimestamp(),
|
|
1468
|
-
updated: null,
|
|
1469
|
-
extension: fileType.extension,
|
|
1470
|
-
mimeType: fileType.mimeType,
|
|
1471
|
-
size
|
|
1472
|
-
};
|
|
1473
|
-
try {
|
|
1474
|
-
await import_fs_extra3.default.copyFile(props.filePath, assetPath);
|
|
1475
|
-
await this.jsonFileService.create(
|
|
1476
|
-
assetFile,
|
|
1477
|
-
assetFilePath,
|
|
1478
|
-
assetFileSchema
|
|
1479
|
-
);
|
|
1480
|
-
} catch (error) {
|
|
1481
|
-
await this.delete({ ...assetFile, projectId: props.projectId });
|
|
1482
|
-
throw error;
|
|
1483
|
-
}
|
|
1484
|
-
await this.gitService.add(projectPath, [assetFilePath, assetPath]);
|
|
1485
|
-
await this.gitService.commit(projectPath, this.gitMessage.create);
|
|
1486
|
-
return this.toAsset(props.projectId, assetFile);
|
|
1487
|
-
}
|
|
1488
|
-
/**
|
|
1489
|
-
* Returns an Asset by ID and language
|
|
1490
|
-
*/
|
|
1491
|
-
async read(props) {
|
|
1492
|
-
readAssetSchema.parse(props);
|
|
1493
|
-
const assetFile = await this.jsonFileService.read(
|
|
1494
|
-
pathTo.assetFile(props.projectId, props.id, props.language),
|
|
1495
|
-
assetFileSchema
|
|
1496
|
-
);
|
|
1497
|
-
return this.toAsset(props.projectId, assetFile);
|
|
1498
|
-
}
|
|
1499
|
-
/**
|
|
1500
|
-
* Updates given Asset
|
|
1501
|
-
*
|
|
1502
|
-
* Use the optional "newFilePath" prop to update the Asset itself
|
|
1503
|
-
*/
|
|
1504
|
-
async update(props) {
|
|
1505
|
-
updateAssetSchema.parse(props);
|
|
1506
|
-
const projectPath = pathTo.project(props.projectId);
|
|
1507
|
-
const assetFilePath = pathTo.assetFile(
|
|
1508
|
-
props.projectId,
|
|
1509
|
-
props.id,
|
|
1510
|
-
props.language
|
|
1511
|
-
);
|
|
1512
|
-
const prevAssetFile = await this.read(props);
|
|
1513
|
-
const assetFile = {
|
|
1514
|
-
...prevAssetFile,
|
|
1515
|
-
...props,
|
|
1516
|
-
updated: currentTimestamp()
|
|
1517
|
-
};
|
|
1518
|
-
if (props.newFilePath) {
|
|
1519
|
-
const fileType = await this.getSupportedFileTypeOrThrow(
|
|
1520
|
-
props.newFilePath
|
|
1521
|
-
);
|
|
1522
|
-
const size = await this.getAssetSize(props.newFilePath);
|
|
1523
|
-
const prevAssetPath = pathTo.asset(
|
|
1524
|
-
props.projectId,
|
|
1525
|
-
props.id,
|
|
1526
|
-
props.language,
|
|
1527
|
-
prevAssetFile.extension
|
|
1528
|
-
);
|
|
1529
|
-
const assetPath = pathTo.asset(
|
|
1530
|
-
props.projectId,
|
|
1531
|
-
props.id,
|
|
1532
|
-
props.language,
|
|
1533
|
-
fileType.extension
|
|
1534
|
-
);
|
|
1535
|
-
await import_fs_extra3.default.remove(prevAssetPath);
|
|
1536
|
-
await import_fs_extra3.default.copyFile(props.newFilePath, assetPath);
|
|
1537
|
-
assetFile.extension = fileType.extension;
|
|
1538
|
-
assetFile.mimeType = fileType.mimeType;
|
|
1539
|
-
assetFile.size = size;
|
|
1540
|
-
}
|
|
1541
|
-
await this.jsonFileService.update(
|
|
1542
|
-
assetFile,
|
|
1543
|
-
assetFilePath,
|
|
1544
|
-
assetFileSchema
|
|
1545
|
-
);
|
|
1546
|
-
await this.gitService.add(projectPath, [assetFilePath]);
|
|
1547
|
-
await this.gitService.commit(projectPath, this.gitMessage.update);
|
|
1548
|
-
return this.toAsset(props.projectId, assetFile);
|
|
1549
|
-
}
|
|
1550
|
-
/**
|
|
1551
|
-
* Deletes given Asset
|
|
1552
|
-
*/
|
|
1553
|
-
async delete(props) {
|
|
1554
|
-
deleteAssetSchema.parse(props);
|
|
1555
|
-
const projectPath = pathTo.project(props.projectId);
|
|
1556
|
-
const assetFilePath = pathTo.assetFile(
|
|
1557
|
-
props.projectId,
|
|
1558
|
-
props.id,
|
|
1559
|
-
props.language
|
|
1560
|
-
);
|
|
1561
|
-
const assetPath = pathTo.asset(
|
|
1562
|
-
props.projectId,
|
|
1563
|
-
props.id,
|
|
1564
|
-
props.language,
|
|
1565
|
-
props.extension
|
|
1566
|
-
);
|
|
1567
|
-
await import_fs_extra3.default.remove(assetPath);
|
|
1568
|
-
await import_fs_extra3.default.remove(assetFilePath);
|
|
1569
|
-
await this.gitService.add(projectPath, [assetFilePath, assetPath]);
|
|
1570
|
-
await this.gitService.commit(projectPath, this.gitMessage.delete);
|
|
1571
|
-
}
|
|
1572
|
-
async list(props) {
|
|
1573
|
-
listAssetsSchema.parse(props);
|
|
1574
|
-
const offset = props.offset || 0;
|
|
1575
|
-
const limit = props.limit || 15;
|
|
1576
|
-
const assetReferences = await this.listReferences(
|
|
1577
|
-
objectTypeSchema.Enum.asset,
|
|
1578
|
-
props.projectId
|
|
1579
|
-
);
|
|
1580
|
-
const partialAssetReferences = assetReferences.slice(offset, limit);
|
|
1581
|
-
const assets = await returnResolved(
|
|
1582
|
-
partialAssetReferences.map((assetReference) => {
|
|
1583
|
-
if (!assetReference.language) {
|
|
1584
|
-
throw new RequiredParameterMissingError("language");
|
|
1585
|
-
}
|
|
1586
|
-
return this.read({
|
|
1587
|
-
projectId: props.projectId,
|
|
1588
|
-
id: assetReference.id,
|
|
1589
|
-
language: assetReference.language
|
|
1590
|
-
});
|
|
1591
|
-
})
|
|
1592
|
-
);
|
|
1593
|
-
return {
|
|
1594
|
-
total: assetReferences.length,
|
|
1595
|
-
limit,
|
|
1596
|
-
offset,
|
|
1597
|
-
list: assets
|
|
1598
|
-
};
|
|
1599
|
-
}
|
|
1600
|
-
async count(props) {
|
|
1601
|
-
countAssetsSchema.parse(props);
|
|
1602
|
-
const count = (await this.listReferences(objectTypeSchema.Enum.asset, props.projectId)).length;
|
|
1603
|
-
return count;
|
|
1604
|
-
}
|
|
1605
|
-
/**
|
|
1606
|
-
* Checks if given object is of type Asset
|
|
1607
|
-
*/
|
|
1608
|
-
isAsset(obj) {
|
|
1609
|
-
return assetSchema.safeParse(obj).success;
|
|
1610
|
-
}
|
|
1611
|
-
/**
|
|
1612
|
-
* Returns the size of an Asset in bytes
|
|
1613
|
-
*
|
|
1614
|
-
* @param path Path of the Asset to get the size from
|
|
1615
|
-
*/
|
|
1616
|
-
async getAssetSize(path) {
|
|
1617
|
-
return (await import_fs_extra3.default.stat(path)).size;
|
|
1618
|
-
}
|
|
1619
|
-
/**
|
|
1620
|
-
* Creates an Asset from given AssetFile
|
|
1621
|
-
*
|
|
1622
|
-
* @param projectId The project's ID
|
|
1623
|
-
* @param assetFile The AssetFile to convert
|
|
1624
|
-
*/
|
|
1625
|
-
async toAsset(projectId, assetFile) {
|
|
1626
|
-
const assetPath = pathTo.asset(
|
|
1627
|
-
projectId,
|
|
1628
|
-
assetFile.id,
|
|
1629
|
-
assetFile.language,
|
|
1630
|
-
assetFile.extension
|
|
1631
|
-
);
|
|
1632
|
-
const asset = {
|
|
1633
|
-
...assetFile,
|
|
1634
|
-
absolutePath: assetPath
|
|
1635
|
-
};
|
|
1636
|
-
return asset;
|
|
1637
|
-
}
|
|
1638
|
-
/**
|
|
1639
|
-
* Returns the found and supported extension as well as mime type,
|
|
1640
|
-
* otherwise throws an error
|
|
1641
|
-
*
|
|
1642
|
-
* @param filePath Path to the file to check
|
|
1643
|
-
*/
|
|
1644
|
-
async getSupportedFileTypeOrThrow(filePath) {
|
|
1645
|
-
const fileSize = (await import_fs_extra3.default.stat(filePath)).size;
|
|
1646
|
-
if (fileSize / 1e3 <= 500) {
|
|
1647
|
-
const fileBuffer = await import_fs_extra3.default.readFile(filePath);
|
|
1648
|
-
if ((0, import_is_svg.default)(fileBuffer.toString()) === true) {
|
|
1649
|
-
return {
|
|
1650
|
-
extension: supportedAssetExtensionSchema.Enum.svg,
|
|
1651
|
-
mimeType: supportedAssetMimeTypeSchema.Enum["image/svg+xml"]
|
|
1652
|
-
};
|
|
1653
|
-
}
|
|
1654
|
-
}
|
|
1655
|
-
const { fileTypeFromFile } = await import("file-type");
|
|
1656
|
-
const fileType = await fileTypeFromFile(filePath);
|
|
1657
|
-
const result = supportedAssetTypeSchema.parse({
|
|
1658
|
-
extension: fileType?.ext,
|
|
1659
|
-
mimeType: fileType?.mime
|
|
1660
|
-
});
|
|
1661
|
-
return result;
|
|
1662
|
-
}
|
|
1663
|
-
};
|
|
1664
|
-
|
|
1665
|
-
// src/service/CollectionService.ts
|
|
1666
|
-
var import_fs_extra4 = __toESM(require("fs-extra"), 1);
|
|
1667
|
-
|
|
1668
|
-
// src/service/GitService.ts
|
|
1669
|
-
var import_dugite = require("dugite");
|
|
1670
|
-
var import_os3 = require("os");
|
|
1671
|
-
var import_p_queue = __toESM(require("p-queue"), 1);
|
|
1672
|
-
|
|
1673
|
-
// src/service/GitTagService.ts
|
|
1674
|
-
var import_os2 = require("os");
|
|
1675
|
-
var GitTagService = class extends AbstractCrudService {
|
|
1676
|
-
constructor(options, git) {
|
|
1677
|
-
super(serviceTypeSchema.Enum.GitTag, options);
|
|
1678
|
-
this.git = git;
|
|
1679
|
-
}
|
|
1680
|
-
/**
|
|
1681
|
-
* Creates a new tag
|
|
1682
|
-
*
|
|
1683
|
-
* @see https://git-scm.com/docs/git-tag#Documentation/git-tag.txt---annotate
|
|
1684
|
-
*/
|
|
1685
|
-
async create(props) {
|
|
1686
|
-
createGitTagSchema.parse(props);
|
|
1687
|
-
const id = uuid();
|
|
1688
|
-
let args = ["tag", "--annotate", id];
|
|
1689
|
-
if (props.hash) {
|
|
1690
|
-
args = [...args, props.hash];
|
|
1691
|
-
}
|
|
1692
|
-
args = [...args, "-m", props.message];
|
|
1693
|
-
await this.git(props.path, args);
|
|
1694
|
-
const tag = await this.read({ path: props.path, id });
|
|
1695
|
-
return tag;
|
|
1696
|
-
}
|
|
1697
|
-
/**
|
|
1698
|
-
* Returns a tag by ID
|
|
1699
|
-
*
|
|
1700
|
-
* Internally uses list() but only returns the tag with matching ID.
|
|
1701
|
-
*/
|
|
1702
|
-
async read(props) {
|
|
1703
|
-
readGitTagSchema.parse(props);
|
|
1704
|
-
const tags = await this.list({ path: props.path });
|
|
1705
|
-
const tag = tags.list.find((tag2) => {
|
|
1706
|
-
return tag2.id === props.id;
|
|
1707
|
-
});
|
|
1708
|
-
if (!tag) {
|
|
1709
|
-
throw new GitError(
|
|
1710
|
-
`Provided tag with UUID "${props.id}" did not match any known tags`
|
|
1711
|
-
);
|
|
1712
|
-
}
|
|
1713
|
-
return tag;
|
|
1714
|
-
}
|
|
1715
|
-
/**
|
|
1716
|
-
* Updating a git tag is not supported.
|
|
1717
|
-
* Please delete the old and create a new one
|
|
1718
|
-
*
|
|
1719
|
-
* @see https://git-scm.com/docs/git-tag#_on_re_tagging
|
|
1720
|
-
*/
|
|
1721
|
-
async update() {
|
|
1722
|
-
throw new Error(
|
|
1723
|
-
"Updating a git tag is not supported. Please delete the old and create a new one"
|
|
1724
|
-
);
|
|
1725
|
-
}
|
|
1726
|
-
/**
|
|
1727
|
-
* Deletes a tag
|
|
1728
|
-
*
|
|
1729
|
-
* @see https://git-scm.com/docs/git-tag#Documentation/git-tag.txt---delete
|
|
1730
|
-
*
|
|
1731
|
-
* @param path Path to the repository
|
|
1732
|
-
* @param id UUID of the tag to delete
|
|
1733
|
-
*/
|
|
1734
|
-
async delete(props) {
|
|
1735
|
-
deleteGitTagSchema.parse(props);
|
|
1736
|
-
const args = ["tag", "--delete", props.id];
|
|
1737
|
-
await this.git(props.path, args);
|
|
1738
|
-
}
|
|
1739
|
-
/**
|
|
1740
|
-
* Gets all local tags or filter them by pattern
|
|
1741
|
-
*
|
|
1742
|
-
* They are sorted by authordate of the commit, not the timestamp the tag is created.
|
|
1743
|
-
* This ensures tags are sorted correctly in the timeline of their commits.
|
|
1744
|
-
*
|
|
1745
|
-
* @see https://git-scm.com/docs/git-tag#Documentation/git-tag.txt---list
|
|
1746
|
-
*/
|
|
1747
|
-
async list(props) {
|
|
1748
|
-
listGitTagsSchema.parse(props);
|
|
1749
|
-
let args = ["tag", "--list"];
|
|
1750
|
-
args = [
|
|
1751
|
-
...args,
|
|
1752
|
-
"--sort=-*authordate",
|
|
1753
|
-
"--format=%(refname:short)|%(subject)|%(*authorname)|%(*authoremail)|%(*authordate:unix)"
|
|
1754
|
-
];
|
|
1755
|
-
const result = await this.git(props.path, args);
|
|
1756
|
-
const noEmptyLinesArr = result.stdout.split(import_os2.EOL).filter((line) => {
|
|
1757
|
-
return line.trim() !== "";
|
|
1758
|
-
});
|
|
1759
|
-
const lineObjArr = noEmptyLinesArr.map((line) => {
|
|
1760
|
-
const lineArray = line.split("|");
|
|
1761
|
-
return {
|
|
1762
|
-
id: lineArray[0],
|
|
1763
|
-
message: lineArray[1],
|
|
1764
|
-
author: {
|
|
1765
|
-
name: lineArray[2],
|
|
1766
|
-
email: lineArray[3]
|
|
1767
|
-
},
|
|
1768
|
-
timestamp: parseInt(lineArray[4])
|
|
1769
|
-
};
|
|
1770
|
-
});
|
|
1771
|
-
const gitTags = lineObjArr.filter(this.isGitTag.bind(this));
|
|
1772
|
-
return {
|
|
1773
|
-
total: gitTags.length,
|
|
1774
|
-
limit: 0,
|
|
1775
|
-
offset: 0,
|
|
1776
|
-
list: gitTags
|
|
1777
|
-
};
|
|
1778
|
-
}
|
|
1779
|
-
/**
|
|
1780
|
-
* Returns the total number of tags inside given repository
|
|
1781
|
-
*
|
|
1782
|
-
* Internally uses list(), so do not use count()
|
|
1783
|
-
* in conjuncion with it to avoid multiple git calls.
|
|
1784
|
-
*
|
|
1785
|
-
* @param path Path to the repository
|
|
1786
|
-
*/
|
|
1787
|
-
async count(props) {
|
|
1788
|
-
countGitTagsSchema.parse(props);
|
|
1789
|
-
const gitTags = await this.list({ path: props.path });
|
|
1790
|
-
return gitTags.total;
|
|
1791
|
-
}
|
|
1792
|
-
/**
|
|
1793
|
-
* Type guard for GitTag
|
|
1794
|
-
*
|
|
1795
|
-
* @param obj The object to check
|
|
1796
|
-
*/
|
|
1797
|
-
isGitTag(obj) {
|
|
1798
|
-
return gitTagSchema.safeParse(obj).success;
|
|
1799
|
-
}
|
|
1800
|
-
};
|
|
1801
|
-
|
|
1802
|
-
// src/service/UserService.ts
|
|
1803
|
-
var UserService = class {
|
|
1804
|
-
constructor(jsonFileService) {
|
|
1805
|
-
this.jsonFileService = jsonFileService;
|
|
1806
|
-
}
|
|
1807
|
-
/**
|
|
1808
|
-
* Returns the User currently working with Core
|
|
1809
|
-
*/
|
|
1810
|
-
async get() {
|
|
1811
|
-
try {
|
|
1812
|
-
return await this.jsonFileService.read(pathTo.userFile, userFileSchema);
|
|
1813
|
-
} catch (error) {
|
|
1814
|
-
return void 0;
|
|
1815
|
-
}
|
|
1816
|
-
}
|
|
1817
|
-
/**
|
|
1818
|
-
* Sets the User currently working with Core
|
|
1819
|
-
*
|
|
1820
|
-
* By doing so all git operations are done with the signature of this User
|
|
1821
|
-
*/
|
|
1822
|
-
async set(props) {
|
|
1823
|
-
setUserSchema.parse(props);
|
|
1824
|
-
const userFilePath = pathTo.userFile;
|
|
1825
|
-
const userFile = {
|
|
1826
|
-
...props
|
|
1827
|
-
};
|
|
1828
|
-
if (userFile.userType === UserTypeSchema.Enum.cloud) {
|
|
1829
|
-
}
|
|
1830
|
-
await this.jsonFileService.update(userFile, userFilePath, userFileSchema);
|
|
1831
|
-
return userFile;
|
|
1832
|
-
}
|
|
1833
|
-
};
|
|
1834
|
-
|
|
1835
|
-
// src/service/GitService.ts
|
|
1836
|
-
var GitService2 = class {
|
|
1837
|
-
constructor(options, userService) {
|
|
1838
|
-
this.branches = {
|
|
1839
|
-
/**
|
|
1840
|
-
* List branches
|
|
1841
|
-
*
|
|
1842
|
-
* @see https://www.git-scm.com/docs/git-branch
|
|
1843
|
-
*
|
|
1844
|
-
* @param path Path to the repository
|
|
1845
|
-
*/
|
|
1846
|
-
list: async (path) => {
|
|
1847
|
-
const args = ["branch", "--list", "--all"];
|
|
1848
|
-
const result = await this.git(path, args);
|
|
1849
|
-
const normalizedLinesArr = result.stdout.split(import_os3.EOL).filter((line) => {
|
|
1850
|
-
return line.trim() !== "";
|
|
1851
|
-
}).map((line) => {
|
|
1852
|
-
return line.trim().replace("* ", "");
|
|
1853
|
-
});
|
|
1854
|
-
const local = [];
|
|
1855
|
-
const remote = [];
|
|
1856
|
-
normalizedLinesArr.forEach((line) => {
|
|
1857
|
-
if (line.startsWith("remotes/")) {
|
|
1858
|
-
remote.push(line.replace("remotes/", ""));
|
|
1859
|
-
} else {
|
|
1860
|
-
local.push(line);
|
|
1861
|
-
}
|
|
1862
|
-
});
|
|
1863
|
-
return {
|
|
1864
|
-
local,
|
|
1865
|
-
remote
|
|
1866
|
-
};
|
|
1867
|
-
},
|
|
1868
|
-
/**
|
|
1869
|
-
* Returns the name of the current branch. In detached HEAD state, an empty string is returned.
|
|
1870
|
-
*
|
|
1871
|
-
* @see https://www.git-scm.com/docs/git-branch#Documentation/git-branch.txt---show-current
|
|
1872
|
-
*
|
|
1873
|
-
* @param path Path to the repository
|
|
1874
|
-
*/
|
|
1875
|
-
current: async (path) => {
|
|
1876
|
-
const args = ["branch", "--show-current"];
|
|
1877
|
-
const result = await this.git(path, args);
|
|
1878
|
-
return result.stdout.trim();
|
|
1879
|
-
},
|
|
1880
|
-
/**
|
|
1881
|
-
* Switch branches
|
|
1882
|
-
*
|
|
1883
|
-
* @see https://git-scm.com/docs/git-switch/
|
|
1884
|
-
*
|
|
1885
|
-
* @param path Path to the repository
|
|
1886
|
-
* @param branch Name of the branch to switch to
|
|
1887
|
-
* @param options Options specific to the switch operation
|
|
1888
|
-
*/
|
|
1889
|
-
switch: async (path, branch, options) => {
|
|
1890
|
-
await this.checkBranchOrTagName(path, branch);
|
|
1891
|
-
let args = ["switch"];
|
|
1892
|
-
if (options?.isNew === true) {
|
|
1893
|
-
args = [...args, "--create", branch];
|
|
1894
|
-
} else {
|
|
1895
|
-
args = [...args, branch];
|
|
1896
|
-
}
|
|
1897
|
-
await this.git(path, args);
|
|
1898
|
-
}
|
|
1899
|
-
};
|
|
1900
|
-
this.remotes = {
|
|
1901
|
-
/**
|
|
1902
|
-
* Returns a list of currently tracked remotes
|
|
1903
|
-
*
|
|
1904
|
-
* @see https://git-scm.com/docs/git-remote
|
|
1905
|
-
*
|
|
1906
|
-
* @param path Path to the repository
|
|
1907
|
-
*/
|
|
1908
|
-
list: async (path) => {
|
|
1909
|
-
const args = ["remote"];
|
|
1910
|
-
const result = await this.git(path, args);
|
|
1911
|
-
const normalizedLinesArr = result.stdout.split(import_os3.EOL).filter((line) => {
|
|
1912
|
-
return line.trim() !== "";
|
|
1913
|
-
});
|
|
1914
|
-
return normalizedLinesArr;
|
|
1915
|
-
},
|
|
1916
|
-
/**
|
|
1917
|
-
* Returns true if the `origin` remote exists, otherwise false
|
|
1918
|
-
*
|
|
1919
|
-
* @param path Path to the repository
|
|
1920
|
-
*/
|
|
1921
|
-
hasOrigin: async (path) => {
|
|
1922
|
-
const remotes = await this.remotes.list(path);
|
|
1923
|
-
if (remotes.includes("origin")) {
|
|
1924
|
-
return true;
|
|
1925
|
-
}
|
|
1926
|
-
return false;
|
|
1927
|
-
},
|
|
1928
|
-
/**
|
|
1929
|
-
* Adds the `origin` remote with given URL
|
|
1930
|
-
*
|
|
1931
|
-
* Throws if `origin` remote is added already.
|
|
1932
|
-
*
|
|
1933
|
-
* @see https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-emaddem
|
|
1934
|
-
*
|
|
1935
|
-
* @param path Path to the repository
|
|
1936
|
-
*/
|
|
1937
|
-
addOrigin: async (path, url) => {
|
|
1938
|
-
const args = ["remote", "add", "origin", url];
|
|
1939
|
-
await this.git(path, args);
|
|
1940
|
-
},
|
|
1941
|
-
/**
|
|
1942
|
-
* Returns the current `origin` remote URL
|
|
1943
|
-
*
|
|
1944
|
-
* Throws if no `origin` remote is added yet.
|
|
1945
|
-
*
|
|
1946
|
-
* @see https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-emget-urlem
|
|
1947
|
-
*
|
|
1948
|
-
* @param path Path to the repository
|
|
1949
|
-
*/
|
|
1950
|
-
getOriginUrl: async (path) => {
|
|
1951
|
-
const args = ["remote", "get-url", "origin"];
|
|
1952
|
-
const result = (await this.git(path, args)).stdout.trim();
|
|
1953
|
-
return result.length === 0 ? null : result;
|
|
1954
|
-
},
|
|
1955
|
-
/**
|
|
1956
|
-
* Sets the current `origin` remote URL
|
|
1957
|
-
*
|
|
1958
|
-
* Throws if no `origin` remote is added yet.
|
|
1959
|
-
*
|
|
1960
|
-
* @see https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-emset-urlem
|
|
1961
|
-
*
|
|
1962
|
-
* @param path Path to the repository
|
|
1963
|
-
*/
|
|
1964
|
-
setOriginUrl: async (path, url) => {
|
|
1965
|
-
const args = ["remote", "set-url", "origin", url];
|
|
1966
|
-
await this.git(path, args);
|
|
1967
|
-
}
|
|
1968
|
-
};
|
|
1969
|
-
this.version = null;
|
|
1970
|
-
this.gitPath = null;
|
|
1971
|
-
this.queue = new import_p_queue.default({
|
|
1972
|
-
concurrency: 1
|
|
1973
|
-
// No concurrency because git operations are sequencial
|
|
1974
|
-
});
|
|
1975
|
-
this.gitTagService = new GitTagService(options, this.git);
|
|
1976
|
-
this.userService = userService;
|
|
1977
|
-
this.updateVersion();
|
|
1978
|
-
this.updateGitPath();
|
|
1979
|
-
}
|
|
1980
|
-
/**
|
|
1981
|
-
* CRUD methods to work with git tags
|
|
1982
|
-
*/
|
|
1983
|
-
get tags() {
|
|
1984
|
-
return this.gitTagService;
|
|
1985
|
-
}
|
|
1986
|
-
/**
|
|
1987
|
-
* Create an empty Git repository or reinitialize an existing one
|
|
1988
|
-
*
|
|
1989
|
-
* @see https://git-scm.com/docs/git-init
|
|
1990
|
-
*
|
|
1991
|
-
* @param path Path to initialize in. Fails if path does not exist
|
|
1992
|
-
* @param options Options specific to the init operation
|
|
1993
|
-
*/
|
|
1994
|
-
async init(path, options) {
|
|
1995
|
-
let args = ["init"];
|
|
1996
|
-
if (options?.initialBranch) {
|
|
1997
|
-
args = [...args, `--initial-branch=${options.initialBranch}`];
|
|
1998
|
-
}
|
|
1999
|
-
await this.git(path, args);
|
|
2000
|
-
await this.setLocalConfig(path);
|
|
2001
|
-
await this.installLfs(path);
|
|
2002
|
-
}
|
|
2003
|
-
/**
|
|
2004
|
-
* Clone a repository into a directory
|
|
2005
|
-
*
|
|
2006
|
-
* @see https://git-scm.com/docs/git-clone
|
|
2007
|
-
*
|
|
2008
|
-
* @todo Implement progress callback / events
|
|
2009
|
-
*
|
|
2010
|
-
* @param url The remote repository URL to clone from
|
|
2011
|
-
* @param path The destination path for the cloned repository.
|
|
2012
|
-
* Which is only working if the directory is existing and empty.
|
|
2013
|
-
* @param options Options specific to the clone operation
|
|
2014
|
-
*/
|
|
2015
|
-
async clone(url, path, options) {
|
|
2016
|
-
let args = ["clone", "--progress"];
|
|
2017
|
-
if (options?.branch) {
|
|
2018
|
-
args = [...args, "--branch", options.branch];
|
|
2019
|
-
}
|
|
2020
|
-
if (options?.depth) {
|
|
2021
|
-
args = [...args, "--depth", options.depth.toString()];
|
|
2022
|
-
}
|
|
2023
|
-
if (options?.singleBranch === true) {
|
|
2024
|
-
args = [...args, "--single-branch"];
|
|
2025
|
-
}
|
|
2026
|
-
await this.git("", [...args, url, path]);
|
|
2027
|
-
await this.setLocalConfig(path);
|
|
2028
|
-
}
|
|
2029
|
-
/**
|
|
2030
|
-
* Add file contents to the index
|
|
2031
|
-
*
|
|
2032
|
-
* @see https://git-scm.com/docs/git-add
|
|
2033
|
-
*
|
|
2034
|
-
* @param path Path to the repository
|
|
2035
|
-
* @param files Files to add
|
|
2036
|
-
*/
|
|
2037
|
-
async add(path, files2) {
|
|
2038
|
-
const args = ["add", "--", ...files2];
|
|
2039
|
-
await this.git(path, args);
|
|
2040
|
-
}
|
|
2041
|
-
/**
|
|
2042
|
-
* Reset current HEAD to the specified state
|
|
2043
|
-
*
|
|
2044
|
-
* @todo maybe add more options
|
|
2045
|
-
* @see https://git-scm.com/docs/git-reset
|
|
2046
|
-
*
|
|
2047
|
-
* @param path Path to the repository
|
|
2048
|
-
* @param mode Modifies the working tree depending on given mode
|
|
2049
|
-
* @param commit Resets the current branch head to this commit / tag
|
|
2050
|
-
*/
|
|
2051
|
-
async reset(path, mode, commit) {
|
|
2052
|
-
const args = ["reset", `--${mode}`, commit];
|
|
2053
|
-
await this.git(path, args);
|
|
2054
|
-
}
|
|
2055
|
-
/**
|
|
2056
|
-
* Restore working tree files
|
|
2057
|
-
*
|
|
2058
|
-
* @see https://git-scm.com/docs/git-restore/
|
|
2059
|
-
*
|
|
2060
|
-
* @todo It's probably a good idea to not use restore
|
|
2061
|
-
* for a use case where someone just wants to have a look
|
|
2062
|
-
* and maybe copy something from a deleted file.
|
|
2063
|
-
* We should use `checkout` without `add .` and `commit` for that
|
|
2064
|
-
*
|
|
2065
|
-
* @param path Path to the repository
|
|
2066
|
-
* @param source Git commit SHA or tag name to restore to
|
|
2067
|
-
* @param files Files to restore
|
|
2068
|
-
*/
|
|
2069
|
-
// public async restore(
|
|
2070
|
-
// path: string,
|
|
2071
|
-
// source: string,
|
|
2072
|
-
// files: string[]
|
|
2073
|
-
// ): Promise<void> {
|
|
2074
|
-
// const args = ['restore', `--source=${source}`, ...files];
|
|
2075
|
-
// await this.git(path, args);
|
|
2076
|
-
// }
|
|
2077
|
-
/**
|
|
2078
|
-
* Download objects and refs from remote `origin`
|
|
2079
|
-
*
|
|
2080
|
-
* @see https://www.git-scm.com/docs/git-fetch
|
|
2081
|
-
*
|
|
2082
|
-
* @param path Path to the repository
|
|
2083
|
-
*/
|
|
2084
|
-
async fetch(path) {
|
|
2085
|
-
const args = ["fetch"];
|
|
2086
|
-
await this.git(path, args);
|
|
2087
|
-
}
|
|
2088
|
-
/**
|
|
2089
|
-
* Fetch from and integrate (rebase or merge) with a local branch
|
|
2090
|
-
*
|
|
2091
|
-
* @see https://git-scm.com/docs/git-pull
|
|
2092
|
-
*
|
|
2093
|
-
* @param path Path to the repository
|
|
2094
|
-
*/
|
|
2095
|
-
async pull(path) {
|
|
2096
|
-
const args = ["pull"];
|
|
2097
|
-
await this.git(path, args);
|
|
2098
|
-
}
|
|
2099
|
-
/**
|
|
2100
|
-
* Update remote refs along with associated objects to remote `origin`
|
|
2101
|
-
*
|
|
2102
|
-
* @see https://git-scm.com/docs/git-push
|
|
2103
|
-
*
|
|
2104
|
-
* @param path Path to the repository
|
|
2105
|
-
*/
|
|
2106
|
-
async push(path, options) {
|
|
2107
|
-
let args = ["push", "origin"];
|
|
2108
|
-
if (options?.all === true) {
|
|
2109
|
-
args = [...args, "--all"];
|
|
2110
|
-
}
|
|
2111
|
-
if (options?.force === true) {
|
|
2112
|
-
args = [...args, "--force"];
|
|
2113
|
-
}
|
|
2114
|
-
await this.git(path, args);
|
|
2115
|
-
}
|
|
2116
|
-
/**
|
|
2117
|
-
* Record changes to the repository
|
|
2118
|
-
*
|
|
2119
|
-
* @see https://git-scm.com/docs/git-commit
|
|
2120
|
-
*
|
|
2121
|
-
* @param path Path to the repository
|
|
2122
|
-
* @param message A message that describes the changes
|
|
2123
|
-
*/
|
|
2124
|
-
async commit(path, message) {
|
|
2125
|
-
const user = await this.userService.get();
|
|
2126
|
-
if (!user) {
|
|
2127
|
-
throw new NoCurrentUserError();
|
|
2128
|
-
}
|
|
2129
|
-
const args = [
|
|
2130
|
-
"commit",
|
|
2131
|
-
`--message=${message}`,
|
|
2132
|
-
`--author=${user.name} <${user.email}>`
|
|
2133
|
-
];
|
|
2134
|
-
await this.git(path, args);
|
|
2135
|
-
}
|
|
2136
|
-
/**
|
|
2137
|
-
* Gets local commit history
|
|
2138
|
-
*
|
|
2139
|
-
* @see https://git-scm.com/docs/git-log
|
|
2140
|
-
*
|
|
2141
|
-
* @todo Check if there is a need to trim the git commit message of chars
|
|
2142
|
-
* @todo Use this method in a service. Decide if we need a HistoryService for example
|
|
2143
|
-
*
|
|
2144
|
-
* @param path Path to the repository
|
|
2145
|
-
* @param options Options specific to the log operation
|
|
2146
|
-
*/
|
|
2147
|
-
async log(path, options) {
|
|
2148
|
-
let args = ["log"];
|
|
2149
|
-
if (options?.between?.from) {
|
|
2150
|
-
args = [
|
|
2151
|
-
...args,
|
|
2152
|
-
`${options.between.from}..${options.between.to || "HEAD"}`
|
|
2153
|
-
];
|
|
2154
|
-
}
|
|
2155
|
-
if (options?.limit) {
|
|
2156
|
-
args = [...args, `--max-count=${options.limit}`];
|
|
2157
|
-
}
|
|
2158
|
-
const result = await this.git(path, [
|
|
2159
|
-
...args,
|
|
2160
|
-
"--format=%H|%s|%an|%ae|%at|%D"
|
|
2161
|
-
]);
|
|
2162
|
-
const noEmptyLinesArr = result.stdout.split(import_os3.EOL).filter((line) => {
|
|
2163
|
-
return line.trim() !== "";
|
|
2164
|
-
});
|
|
2165
|
-
const lineObjArr = noEmptyLinesArr.map((line) => {
|
|
2166
|
-
const lineArray = line.split("|");
|
|
2167
|
-
return {
|
|
2168
|
-
hash: lineArray[0],
|
|
2169
|
-
message: lineArray[1],
|
|
2170
|
-
author: {
|
|
2171
|
-
name: lineArray[2],
|
|
2172
|
-
email: lineArray[3]
|
|
2173
|
-
},
|
|
2174
|
-
timestamp: parseInt(lineArray[4]),
|
|
2175
|
-
tag: this.refNameToTagName(lineArray[5])
|
|
2176
|
-
};
|
|
2177
|
-
});
|
|
2178
|
-
return lineObjArr.filter(this.isGitCommit.bind(this));
|
|
2179
|
-
}
|
|
2180
|
-
refNameToTagName(refName) {
|
|
2181
|
-
const tagName = refName.replace("tag: ", "").trim();
|
|
2182
|
-
if (tagName === "" || uuidSchema.safeParse(tagName).success === false) {
|
|
2183
|
-
return null;
|
|
2184
|
-
}
|
|
2185
|
-
return tagName;
|
|
2186
|
-
}
|
|
2187
|
-
/**
|
|
2188
|
-
* Returns a timestamp of given files creation
|
|
2189
|
-
*
|
|
2190
|
-
* Git only returns the timestamp the file was added,
|
|
2191
|
-
* which could be different from the file being created.
|
|
2192
|
-
* But since file operations will always be committed
|
|
2193
|
-
* immediately, this is practically the same.
|
|
2194
|
-
*
|
|
2195
|
-
* @param path Path to the repository
|
|
2196
|
-
* @param file File to get timestamp from
|
|
2197
|
-
*/
|
|
2198
|
-
async getFileCreatedTimestamp(path, file) {
|
|
2199
|
-
const result = await this.git(path, [
|
|
2200
|
-
"log",
|
|
2201
|
-
"--diff-filter=A",
|
|
2202
|
-
"--follow",
|
|
2203
|
-
"--format=%at",
|
|
2204
|
-
"--max-count=1",
|
|
2205
|
-
"--",
|
|
2206
|
-
file
|
|
2207
|
-
]);
|
|
2208
|
-
return parseInt(result.stdout);
|
|
2209
|
-
}
|
|
2210
|
-
/**
|
|
2211
|
-
* Returns a timestamp of the files last modification
|
|
2212
|
-
*
|
|
2213
|
-
* @param path Path to the repository
|
|
2214
|
-
* @param file File to get timestamp from
|
|
2215
|
-
*/
|
|
2216
|
-
async getFileLastUpdatedTimestamp(path, file) {
|
|
2217
|
-
const result = await this.git(path, [
|
|
2218
|
-
"log",
|
|
2219
|
-
"--follow",
|
|
2220
|
-
"--format=%at",
|
|
2221
|
-
"--max-count=1",
|
|
2222
|
-
"--",
|
|
2223
|
-
file
|
|
2224
|
-
]);
|
|
2225
|
-
return parseInt(result.stdout);
|
|
2226
|
-
}
|
|
2227
|
-
/**
|
|
2228
|
-
* Returns created and updated timestamps from given file
|
|
2229
|
-
*
|
|
2230
|
-
* @param path Path to the project
|
|
2231
|
-
* @param file Path to the file
|
|
2232
|
-
*/
|
|
2233
|
-
async getFileCreatedUpdatedMeta(path, file) {
|
|
2234
|
-
const meta = await Promise.all([
|
|
2235
|
-
this.getFileCreatedTimestamp(path, file),
|
|
2236
|
-
this.getFileLastUpdatedTimestamp(path, file)
|
|
2237
|
-
]);
|
|
2238
|
-
return {
|
|
2239
|
-
created: meta[0],
|
|
2240
|
-
updated: meta[1]
|
|
2241
|
-
};
|
|
2242
|
-
}
|
|
2243
|
-
/**
|
|
2244
|
-
* Reads the currently used version of Git
|
|
2245
|
-
*
|
|
2246
|
-
* This can help debugging
|
|
2247
|
-
*/
|
|
2248
|
-
async updateVersion() {
|
|
2249
|
-
const result = await this.git("", ["--version"]);
|
|
2250
|
-
this.version = result.stdout.replace("git version", "").trim();
|
|
2251
|
-
}
|
|
2252
|
-
/**
|
|
2253
|
-
* Reads the path to the executable of Git that is used
|
|
2254
|
-
*
|
|
2255
|
-
* This can help debugging, since dugite is shipping their own executable
|
|
2256
|
-
* but in some cases resolves another executable
|
|
2257
|
-
* @see https://github.com/desktop/dugite/blob/main/lib/git-environment.ts
|
|
2258
|
-
*/
|
|
2259
|
-
async updateGitPath() {
|
|
2260
|
-
const result = await this.git("", ["--exec-path"]);
|
|
2261
|
-
this.gitPath = result.stdout.trim();
|
|
2262
|
-
}
|
|
2263
|
-
/**
|
|
2264
|
-
* A reference is used in Git to specify branches and tags.
|
|
2265
|
-
* This method checks if given name matches the required format
|
|
2266
|
-
*
|
|
2267
|
-
* @see https://git-scm.com/docs/git-check-ref-format
|
|
2268
|
-
*
|
|
2269
|
-
* @param path Path to the repository
|
|
2270
|
-
* @param name Name to check
|
|
2271
|
-
*/
|
|
2272
|
-
async checkBranchOrTagName(path, name) {
|
|
2273
|
-
await this.git(path, ["check-ref-format", "--allow-onelevel", name]);
|
|
2274
|
-
}
|
|
2275
|
-
/**
|
|
2276
|
-
* Installs LFS support and starts tracking
|
|
2277
|
-
* all files inside the lfs folder
|
|
2278
|
-
*
|
|
2279
|
-
* @param path Path to the repository
|
|
2280
|
-
*/
|
|
2281
|
-
async installLfs(path) {
|
|
2282
|
-
await this.git(path, ["lfs", "install"]);
|
|
2283
|
-
await this.git(path, ["lfs", "track", "lfs/*"]);
|
|
2284
|
-
}
|
|
2285
|
-
/**
|
|
2286
|
-
* Sets the git config of given local repository from ElekIoCoreOptions
|
|
2287
|
-
*
|
|
2288
|
-
* @param path Path to the repository
|
|
2289
|
-
*/
|
|
2290
|
-
async setLocalConfig(path) {
|
|
2291
|
-
const user = await this.userService.get();
|
|
2292
|
-
if (!user) {
|
|
2293
|
-
throw new NoCurrentUserError();
|
|
2294
|
-
}
|
|
2295
|
-
const userNameArgs = ["config", "--local", "user.name", user.name];
|
|
2296
|
-
const userEmailArgs = ["config", "--local", "user.email", user.email];
|
|
2297
|
-
const autoSetupRemoteArgs = [
|
|
2298
|
-
"config",
|
|
2299
|
-
"--local",
|
|
2300
|
-
"push.autoSetupRemote",
|
|
2301
|
-
"true"
|
|
2302
|
-
];
|
|
2303
|
-
await this.git(path, userNameArgs);
|
|
2304
|
-
await this.git(path, userEmailArgs);
|
|
2305
|
-
await this.git(path, autoSetupRemoteArgs);
|
|
2306
|
-
}
|
|
2307
|
-
/**
|
|
2308
|
-
* Type guard for GitCommit
|
|
2309
|
-
*
|
|
2310
|
-
* @param obj The object to check
|
|
2311
|
-
*/
|
|
2312
|
-
isGitCommit(obj) {
|
|
2313
|
-
return gitCommitSchema.safeParse(obj).success;
|
|
2314
|
-
}
|
|
2315
|
-
/**
|
|
2316
|
-
* Wraps the execution of any git command
|
|
2317
|
-
* to use a FIFO queue for sequential processing
|
|
2318
|
-
*
|
|
2319
|
-
* @param path Path to the repository
|
|
2320
|
-
* @param args Arguments to append after the `git` command
|
|
2321
|
-
*/
|
|
2322
|
-
async git(path, args) {
|
|
2323
|
-
const result = await this.queue.add(
|
|
2324
|
-
() => import_dugite.GitProcess.exec(args, path, {
|
|
2325
|
-
env: {
|
|
2326
|
-
// @todo Nasty stuff - remove after update to dugite with git > v2.45.2 once available
|
|
2327
|
-
// @see https://github.com/git-lfs/git-lfs/issues/5749
|
|
2328
|
-
GIT_CLONE_PROTECTION_ACTIVE: "false"
|
|
2329
|
-
}
|
|
2330
|
-
})
|
|
2331
|
-
);
|
|
2332
|
-
if (!result) {
|
|
2333
|
-
throw new GitError(
|
|
2334
|
-
`Git ${this.version} (${this.gitPath}) command "git ${args.join(
|
|
2335
|
-
" "
|
|
2336
|
-
)}" failed to return a result`
|
|
2337
|
-
);
|
|
2338
|
-
}
|
|
2339
|
-
if (result.exitCode !== 0) {
|
|
2340
|
-
throw new GitError(
|
|
2341
|
-
`Git ${this.version} (${this.gitPath}) command "git ${args.join(
|
|
2342
|
-
" "
|
|
2343
|
-
)}" failed with exit code "${result.exitCode}" and message "${result.stderr}"`
|
|
2344
|
-
);
|
|
2345
|
-
}
|
|
2346
|
-
return result;
|
|
2347
|
-
}
|
|
2348
|
-
};
|
|
2349
|
-
|
|
2350
|
-
// src/service/CollectionService.ts
|
|
2351
|
-
var CollectionService = class extends AbstractCrudService {
|
|
2352
|
-
constructor(options, jsonFileService, gitService) {
|
|
2353
|
-
super(serviceTypeSchema.Enum.Collection, options);
|
|
2354
|
-
this.jsonFileService = jsonFileService;
|
|
2355
|
-
this.gitService = gitService;
|
|
2356
|
-
}
|
|
2357
|
-
/**
|
|
2358
|
-
* Creates a new Collection
|
|
2359
|
-
*/
|
|
2360
|
-
async create(props) {
|
|
2361
|
-
createCollectionSchema.parse(props);
|
|
2362
|
-
const id = uuid();
|
|
2363
|
-
const projectPath = pathTo.project(props.projectId);
|
|
2364
|
-
const collectionPath = pathTo.collection(props.projectId, id);
|
|
2365
|
-
const collectionFilePath = pathTo.collectionFile(props.projectId, id);
|
|
2366
|
-
const collectionFile = {
|
|
2367
|
-
...props,
|
|
2368
|
-
objectType: "collection",
|
|
2369
|
-
id,
|
|
2370
|
-
slug: {
|
|
2371
|
-
singular: slug(props.slug.singular),
|
|
2372
|
-
plural: slug(props.slug.plural)
|
|
2373
|
-
},
|
|
2374
|
-
created: currentTimestamp(),
|
|
2375
|
-
updated: null
|
|
2376
|
-
};
|
|
2377
|
-
await import_fs_extra4.default.ensureDir(collectionPath);
|
|
2378
|
-
await this.jsonFileService.create(
|
|
2379
|
-
collectionFile,
|
|
2380
|
-
collectionFilePath,
|
|
2381
|
-
collectionFileSchema
|
|
2382
|
-
);
|
|
2383
|
-
await this.gitService.add(projectPath, [collectionFilePath]);
|
|
2384
|
-
await this.gitService.commit(projectPath, this.gitMessage.create);
|
|
2385
|
-
return collectionFile;
|
|
2386
|
-
}
|
|
2387
|
-
/**
|
|
2388
|
-
* Returns a Collection by ID
|
|
2389
|
-
*/
|
|
2390
|
-
async read(props) {
|
|
2391
|
-
readCollectionSchema.parse(props);
|
|
2392
|
-
const collection = await this.jsonFileService.read(
|
|
2393
|
-
pathTo.collectionFile(props.projectId, props.id),
|
|
2394
|
-
collectionFileSchema
|
|
2395
|
-
);
|
|
2396
|
-
return collection;
|
|
2397
|
-
}
|
|
2398
|
-
/**
|
|
2399
|
-
* Updates given Collection
|
|
2400
|
-
*
|
|
2401
|
-
* @todo finish implementing checks for FieldDefinitions and extract methods
|
|
2402
|
-
*
|
|
2403
|
-
* @param projectId Project ID of the collection to update
|
|
2404
|
-
* @param collection Collection to write to disk
|
|
2405
|
-
* @returns An object containing information about the actions needed to be taken,
|
|
2406
|
-
* before given update can be executed or void if the update was executed successfully
|
|
2407
|
-
*/
|
|
2408
|
-
async update(props) {
|
|
2409
|
-
updateCollectionSchema.parse(props);
|
|
2410
|
-
const projectPath = pathTo.project(props.projectId);
|
|
2411
|
-
const collectionFilePath = pathTo.collectionFile(props.projectId, props.id);
|
|
2412
|
-
const prevCollectionFile = await this.read(props);
|
|
2413
|
-
const collectionFile = {
|
|
2414
|
-
...prevCollectionFile,
|
|
2415
|
-
...props,
|
|
2416
|
-
updated: currentTimestamp()
|
|
2417
|
-
};
|
|
2418
|
-
await this.jsonFileService.update(
|
|
2419
|
-
collectionFile,
|
|
2420
|
-
collectionFilePath,
|
|
2421
|
-
collectionFileSchema
|
|
2422
|
-
);
|
|
2423
|
-
await this.gitService.add(projectPath, [collectionFilePath]);
|
|
2424
|
-
await this.gitService.commit(projectPath, this.gitMessage.update);
|
|
2425
|
-
return collectionFile;
|
|
2426
|
-
}
|
|
2427
|
-
/**
|
|
2428
|
-
* Deletes given Collection (folder), including it's items
|
|
2429
|
-
*
|
|
2430
|
-
* The Fields that Collection used are not deleted.
|
|
2431
|
-
*/
|
|
2432
|
-
async delete(props) {
|
|
2433
|
-
deleteCollectionSchema.parse(props);
|
|
2434
|
-
const projectPath = pathTo.project(props.projectId);
|
|
2435
|
-
const collectionPath = pathTo.collection(props.projectId, props.id);
|
|
2436
|
-
await import_fs_extra4.default.remove(collectionPath);
|
|
2437
|
-
await this.gitService.add(projectPath, [collectionPath]);
|
|
2438
|
-
await this.gitService.commit(projectPath, this.gitMessage.delete);
|
|
2439
|
-
}
|
|
2440
|
-
async list(props) {
|
|
2441
|
-
listCollectionsSchema.parse(props);
|
|
2442
|
-
const offset = props.offset || 0;
|
|
2443
|
-
const limit = props.limit || 15;
|
|
2444
|
-
const collectionReferences = await this.listReferences(
|
|
2445
|
-
objectTypeSchema.Enum.collection,
|
|
2446
|
-
props.projectId
|
|
2447
|
-
);
|
|
2448
|
-
const partialCollectionReferences = collectionReferences.slice(
|
|
2449
|
-
offset,
|
|
2450
|
-
limit
|
|
2451
|
-
);
|
|
2452
|
-
const collections = await returnResolved(
|
|
2453
|
-
partialCollectionReferences.map((reference) => {
|
|
2454
|
-
return this.read({
|
|
2455
|
-
projectId: props.projectId,
|
|
2456
|
-
id: reference.id
|
|
2457
|
-
});
|
|
2458
|
-
})
|
|
2459
|
-
);
|
|
2460
|
-
return {
|
|
2461
|
-
total: collectionReferences.length,
|
|
2462
|
-
limit,
|
|
2463
|
-
offset,
|
|
2464
|
-
list: collections
|
|
2465
|
-
};
|
|
2466
|
-
}
|
|
2467
|
-
async count(props) {
|
|
2468
|
-
countCollectionsSchema.parse(props);
|
|
2469
|
-
const count = (await this.listReferences(
|
|
2470
|
-
objectTypeSchema.Enum.collection,
|
|
2471
|
-
props.projectId
|
|
2472
|
-
)).length;
|
|
2473
|
-
return count;
|
|
2474
|
-
}
|
|
2475
|
-
/**
|
|
2476
|
-
* Checks if given object is of type Collection
|
|
2477
|
-
*/
|
|
2478
|
-
isCollection(obj) {
|
|
2479
|
-
return collectionFileSchema.safeParse(obj).success;
|
|
2480
|
-
}
|
|
2481
|
-
};
|
|
2482
|
-
|
|
2483
|
-
// src/service/EntryService.ts
|
|
2484
|
-
var import_fs_extra5 = __toESM(require("fs-extra"), 1);
|
|
2485
|
-
var EntryService = class extends AbstractCrudService {
|
|
2486
|
-
// private sharedValueService: SharedValueService;
|
|
2487
|
-
constructor(options, jsonFileService, gitService, collectionService, assetService) {
|
|
2488
|
-
super(serviceTypeSchema.Enum.Entry, options);
|
|
2489
|
-
this.jsonFileService = jsonFileService;
|
|
2490
|
-
this.gitService = gitService;
|
|
2491
|
-
this.collectionService = collectionService;
|
|
2492
|
-
this.assetService = assetService;
|
|
2493
|
-
}
|
|
2494
|
-
/**
|
|
2495
|
-
* Creates a new Entry for given Collection
|
|
2496
|
-
*/
|
|
2497
|
-
async create(props) {
|
|
2498
|
-
createEntrySchema.parse(props);
|
|
2499
|
-
const id = uuid();
|
|
2500
|
-
const projectPath = pathTo.project(props.projectId);
|
|
2501
|
-
const entryFilePath = pathTo.entryFile(
|
|
2502
|
-
props.projectId,
|
|
2503
|
-
props.collectionId,
|
|
2504
|
-
id
|
|
2505
|
-
);
|
|
2506
|
-
const collection = await this.collectionService.read({
|
|
2507
|
-
projectId: props.projectId,
|
|
2508
|
-
id: props.collectionId
|
|
2509
|
-
});
|
|
2510
|
-
const entryFile = {
|
|
2511
|
-
objectType: "entry",
|
|
2512
|
-
id,
|
|
2513
|
-
values: props.values,
|
|
2514
|
-
created: currentTimestamp(),
|
|
2515
|
-
updated: null
|
|
2516
|
-
};
|
|
2517
|
-
const entry = await this.toEntry({
|
|
2518
|
-
projectId: props.projectId,
|
|
2519
|
-
collectionId: props.collectionId,
|
|
2520
|
-
entryFile
|
|
2521
|
-
});
|
|
2522
|
-
this.validateValues({
|
|
2523
|
-
collectionId: props.collectionId,
|
|
2524
|
-
valueDefinitions: collection.valueDefinitions,
|
|
2525
|
-
values: entry.values
|
|
2526
|
-
});
|
|
2527
|
-
await this.jsonFileService.create(
|
|
2528
|
-
entryFile,
|
|
2529
|
-
entryFilePath,
|
|
2530
|
-
entryFileSchema
|
|
2531
|
-
);
|
|
2532
|
-
await this.gitService.add(projectPath, [entryFilePath]);
|
|
2533
|
-
await this.gitService.commit(projectPath, this.gitMessage.create);
|
|
2534
|
-
return entry;
|
|
2535
|
-
}
|
|
2536
|
-
/**
|
|
2537
|
-
* Returns an Entry from given Collection by ID and language
|
|
2538
|
-
*/
|
|
2539
|
-
async read(props) {
|
|
2540
|
-
readEntrySchema.parse(props);
|
|
2541
|
-
const entryFile = await this.jsonFileService.read(
|
|
2542
|
-
pathTo.entryFile(props.projectId, props.collectionId, props.id),
|
|
2543
|
-
entryFileSchema
|
|
2544
|
-
);
|
|
2545
|
-
return await this.toEntry({
|
|
2546
|
-
projectId: props.projectId,
|
|
2547
|
-
collectionId: props.collectionId,
|
|
2548
|
-
entryFile
|
|
2549
|
-
});
|
|
2550
|
-
}
|
|
2551
|
-
/**
|
|
2552
|
-
* Updates an Entry of given Collection with new Values and shared Values
|
|
2553
|
-
*/
|
|
2554
|
-
async update(props) {
|
|
2555
|
-
updateEntrySchema.parse(props);
|
|
2556
|
-
const projectPath = pathTo.project(props.projectId);
|
|
2557
|
-
const entryFilePath = pathTo.entryFile(
|
|
2558
|
-
props.projectId,
|
|
2559
|
-
props.collectionId,
|
|
2560
|
-
props.id
|
|
2561
|
-
);
|
|
2562
|
-
const collection = await this.collectionService.read({
|
|
2563
|
-
projectId: props.projectId,
|
|
2564
|
-
id: props.collectionId
|
|
2565
|
-
});
|
|
2566
|
-
const prevEntryFile = await this.read({
|
|
2567
|
-
projectId: props.projectId,
|
|
2568
|
-
collectionId: props.collectionId,
|
|
2569
|
-
id: props.id
|
|
2570
|
-
});
|
|
2571
|
-
const entryFile = {
|
|
2572
|
-
...prevEntryFile,
|
|
2573
|
-
values: props.values,
|
|
2574
|
-
updated: currentTimestamp()
|
|
2575
|
-
};
|
|
2576
|
-
const entry = await this.toEntry({
|
|
2577
|
-
projectId: props.projectId,
|
|
2578
|
-
collectionId: props.collectionId,
|
|
2579
|
-
entryFile
|
|
2580
|
-
});
|
|
2581
|
-
this.validateValues({
|
|
2582
|
-
collectionId: props.collectionId,
|
|
2583
|
-
valueDefinitions: collection.valueDefinitions,
|
|
2584
|
-
values: entry.values
|
|
2585
|
-
});
|
|
2586
|
-
await this.jsonFileService.update(
|
|
2587
|
-
entryFile,
|
|
2588
|
-
entryFilePath,
|
|
2589
|
-
entryFileSchema
|
|
2590
|
-
);
|
|
2591
|
-
await this.gitService.add(projectPath, [entryFilePath]);
|
|
2592
|
-
await this.gitService.commit(projectPath, this.gitMessage.update);
|
|
2593
|
-
return entry;
|
|
2594
|
-
}
|
|
2595
|
-
/**
|
|
2596
|
-
* Deletes given Entry from it's Collection
|
|
2597
|
-
*/
|
|
2598
|
-
async delete(props) {
|
|
2599
|
-
deleteEntrySchema.parse(props);
|
|
2600
|
-
const projectPath = pathTo.project(props.projectId);
|
|
2601
|
-
const entryFilePath = pathTo.entryFile(
|
|
2602
|
-
props.projectId,
|
|
2603
|
-
props.collectionId,
|
|
2604
|
-
props.id
|
|
2605
|
-
);
|
|
2606
|
-
await import_fs_extra5.default.remove(entryFilePath);
|
|
2607
|
-
await this.gitService.add(projectPath, [entryFilePath]);
|
|
2608
|
-
await this.gitService.commit(projectPath, this.gitMessage.delete);
|
|
2609
|
-
}
|
|
2610
|
-
async list(props) {
|
|
2611
|
-
listEntriesSchema.parse(props);
|
|
2612
|
-
const offset = props.offset || 0;
|
|
2613
|
-
const limit = props.limit || 15;
|
|
2614
|
-
const entryReferences = await this.listReferences(
|
|
2615
|
-
objectTypeSchema.Enum.entry,
|
|
2616
|
-
props.projectId,
|
|
2617
|
-
props.collectionId
|
|
2618
|
-
);
|
|
2619
|
-
const partialEntryReferences = entryReferences.slice(offset, limit);
|
|
2620
|
-
const entries = await returnResolved(
|
|
2621
|
-
partialEntryReferences.map((reference) => {
|
|
2622
|
-
return this.read({
|
|
2623
|
-
projectId: props.projectId,
|
|
2624
|
-
collectionId: props.collectionId,
|
|
2625
|
-
id: reference.id
|
|
2626
|
-
});
|
|
2627
|
-
})
|
|
2628
|
-
);
|
|
2629
|
-
return {
|
|
2630
|
-
total: entryReferences.length,
|
|
2631
|
-
limit,
|
|
2632
|
-
offset,
|
|
2633
|
-
list: entries
|
|
2634
|
-
};
|
|
2635
|
-
}
|
|
2636
|
-
async count(props) {
|
|
2637
|
-
countEntriesSchema.parse(props);
|
|
2638
|
-
return (await this.listReferences(
|
|
2639
|
-
objectTypeSchema.Enum.entry,
|
|
2640
|
-
props.projectId,
|
|
2641
|
-
props.collectionId
|
|
2642
|
-
)).length;
|
|
2643
|
-
}
|
|
2644
|
-
/**
|
|
2645
|
-
* Checks if given object is of type Entry
|
|
2646
|
-
*/
|
|
2647
|
-
isEntry(obj) {
|
|
2648
|
-
return entrySchema.safeParse(obj).success;
|
|
2649
|
-
}
|
|
2650
|
-
/**
|
|
2651
|
-
* Returns a Value definition by ID
|
|
2652
|
-
*/
|
|
2653
|
-
getValueDefinitionById(props) {
|
|
2654
|
-
const definition = props.valueDefinitions.find((def) => {
|
|
2655
|
-
if (def.id === props.id) {
|
|
2656
|
-
return true;
|
|
2657
|
-
}
|
|
2658
|
-
return false;
|
|
2659
|
-
});
|
|
2660
|
-
if (!definition) {
|
|
2661
|
-
throw new Error(
|
|
2662
|
-
`No definition with ID "${props.id}" found in Collection "${props.collectionId}" for given Value reference`
|
|
2663
|
-
);
|
|
2664
|
-
}
|
|
2665
|
-
return definition;
|
|
2666
|
-
}
|
|
2667
|
-
/**
|
|
2668
|
-
* Validates given Values against it's Collections definitions
|
|
2669
|
-
*/
|
|
2670
|
-
validateValues(props) {
|
|
2671
|
-
props.values.map((value) => {
|
|
2672
|
-
const definition = this.getValueDefinitionById({
|
|
2673
|
-
collectionId: props.collectionId,
|
|
2674
|
-
valueDefinitions: props.valueDefinitions,
|
|
2675
|
-
id: value.definitionId
|
|
2676
|
-
});
|
|
2677
|
-
const schema = getValueContentSchemaFromDefinition(definition);
|
|
2678
|
-
try {
|
|
2679
|
-
for (const [language, content] of Object.entries(value.content)) {
|
|
2680
|
-
schema.parse(content);
|
|
2681
|
-
}
|
|
2682
|
-
} catch (error) {
|
|
2683
|
-
console.log("Definition:", definition);
|
|
2684
|
-
console.log("Value:", value);
|
|
2685
|
-
throw error;
|
|
2686
|
-
}
|
|
2687
|
-
});
|
|
2688
|
-
}
|
|
2689
|
-
/**
|
|
2690
|
-
* Validates given shared Value references against it's Collections definitions
|
|
2691
|
-
*/
|
|
2692
|
-
// private validateResolvedSharedValues(props: {
|
|
2693
|
-
// collectionId: string;
|
|
2694
|
-
// valueDefinitions: ValueDefinition[];
|
|
2695
|
-
// resolvedSharedValues: ResolvedSharedValueReference[];
|
|
2696
|
-
// }) {
|
|
2697
|
-
// props.resolvedSharedValues.map((value) => {
|
|
2698
|
-
// const definition = this.getValueDefinitionById({
|
|
2699
|
-
// collectionId: props.collectionId,
|
|
2700
|
-
// valueDefinitions: props.valueDefinitions,
|
|
2701
|
-
// id: value.definitionId,
|
|
2702
|
-
// });
|
|
2703
|
-
// const schema = getValueSchemaFromDefinition(definition);
|
|
2704
|
-
// schema.parse(value.resolved.content);
|
|
2705
|
-
// });
|
|
2706
|
-
// }
|
|
2707
|
-
async resolveValueContentReference(props) {
|
|
2708
|
-
switch (props.valueContentReference.objectType) {
|
|
2709
|
-
case objectTypeSchema.Enum.asset:
|
|
2710
|
-
return await this.assetService.read({
|
|
2711
|
-
projectId: props.projectId,
|
|
2712
|
-
id: props.valueContentReference.id,
|
|
2713
|
-
language: props.valueContentReference.language
|
|
2714
|
-
});
|
|
2715
|
-
case objectTypeSchema.Enum.entry:
|
|
2716
|
-
return await this.read({
|
|
2717
|
-
projectId: props.projectId,
|
|
2718
|
-
collectionId: props.collectionId,
|
|
2719
|
-
id: props.valueContentReference.id
|
|
2720
|
-
});
|
|
2721
|
-
default:
|
|
2722
|
-
throw new Error(
|
|
2723
|
-
// @ts-ignore
|
|
2724
|
-
`Tried to resolve unsupported Value reference "${props.valueContentReference.referenceObjectType}"`
|
|
2725
|
-
);
|
|
2726
|
-
}
|
|
2727
|
-
}
|
|
2728
|
-
async resolveValueContentReferences(props) {
|
|
2729
|
-
let resolvedContent = {};
|
|
2730
|
-
for (const language in props.valueReference.content) {
|
|
2731
|
-
const referencesOfLanguage = props.valueReference.content[language];
|
|
2732
|
-
if (!referencesOfLanguage) {
|
|
2733
|
-
throw new Error(
|
|
2734
|
-
`Trying to access content references by language "${language}" failed`
|
|
2735
|
-
);
|
|
2736
|
-
}
|
|
2737
|
-
const resolvedReferencesOfLanguage = await Promise.all(
|
|
2738
|
-
referencesOfLanguage.map(async (reference) => {
|
|
2739
|
-
return await this.resolveValueContentReference({
|
|
2740
|
-
projectId: props.projectId,
|
|
2741
|
-
collectionId: props.collectionId,
|
|
2742
|
-
valueContentReference: reference
|
|
2743
|
-
});
|
|
2744
|
-
})
|
|
2745
|
-
);
|
|
2746
|
-
resolvedContent = {
|
|
2747
|
-
...resolvedContent,
|
|
2748
|
-
[language]: resolvedReferencesOfLanguage
|
|
2749
|
-
};
|
|
2750
|
-
}
|
|
2751
|
-
return resolvedContent;
|
|
2752
|
-
}
|
|
2753
|
-
/**
|
|
2754
|
-
* Creates an Entry from given EntryFile by resolving it's Values
|
|
2755
|
-
*/
|
|
2756
|
-
async toEntry(props) {
|
|
2757
|
-
return {
|
|
2758
|
-
...props.entryFile,
|
|
2759
|
-
// @ts-ignore @todo fixme - I have no idea why this happens. The types seem to be compatible to me and they work
|
|
2760
|
-
values: await Promise.all(
|
|
2761
|
-
props.entryFile.values.map(async (value) => {
|
|
2762
|
-
if (value.valueType === ValueTypeSchema.Enum.reference) {
|
|
2763
|
-
const resolvedContentReferences = await this.resolveValueContentReferences({
|
|
2764
|
-
projectId: props.projectId,
|
|
2765
|
-
collectionId: props.collectionId,
|
|
2766
|
-
valueReference: value
|
|
2767
|
-
});
|
|
2768
|
-
return {
|
|
2769
|
-
...value,
|
|
2770
|
-
content: resolvedContentReferences
|
|
2771
|
-
};
|
|
2772
|
-
}
|
|
2773
|
-
return value;
|
|
2774
|
-
})
|
|
2775
|
-
)
|
|
2776
|
-
};
|
|
2777
|
-
}
|
|
2778
|
-
};
|
|
2779
|
-
|
|
2780
|
-
// src/service/ProjectService.ts
|
|
2781
|
-
var import_fs_extra6 = __toESM(require("fs-extra"), 1);
|
|
2782
|
-
var import_os4 = __toESM(require("os"), 1);
|
|
2783
|
-
var import_path2 = __toESM(require("path"), 1);
|
|
2784
|
-
var import_semver = __toESM(require("semver"), 1);
|
|
2785
|
-
var ProjectService = class extends AbstractCrudService {
|
|
2786
|
-
constructor(options, jsonFileService, userService, gitService, assetService, collectionService, entryService) {
|
|
2787
|
-
super(serviceTypeSchema.Enum.Project, options);
|
|
2788
|
-
this.branches = {
|
|
2789
|
-
list: async (props) => {
|
|
2790
|
-
listBranchesProjectSchema.parse(props);
|
|
2791
|
-
const projectPath = pathTo.project(props.id);
|
|
2792
|
-
await this.gitService.fetch(projectPath);
|
|
2793
|
-
return await this.gitService.branches.list(projectPath);
|
|
2794
|
-
},
|
|
2795
|
-
current: async (props) => {
|
|
2796
|
-
currentBranchProjectSchema.parse(props);
|
|
2797
|
-
const projectPath = pathTo.project(props.id);
|
|
2798
|
-
return await this.gitService.branches.current(projectPath);
|
|
2799
|
-
},
|
|
2800
|
-
switch: async (props) => {
|
|
2801
|
-
switchBranchProjectSchema.parse(props);
|
|
2802
|
-
const projectPath = pathTo.project(props.id);
|
|
2803
|
-
return await this.gitService.branches.switch(
|
|
2804
|
-
projectPath,
|
|
2805
|
-
props.branch,
|
|
2806
|
-
props.options
|
|
2807
|
-
);
|
|
2808
|
-
}
|
|
2809
|
-
};
|
|
2810
|
-
this.remotes = {
|
|
2811
|
-
getOriginUrl: async (props) => {
|
|
2812
|
-
getRemoteOriginUrlProjectSchema.parse(props);
|
|
2813
|
-
const projectPath = pathTo.project(props.id);
|
|
2814
|
-
return await this.gitService.remotes.getOriginUrl(projectPath);
|
|
2815
|
-
},
|
|
2816
|
-
setOriginUrl: async (props) => {
|
|
2817
|
-
setRemoteOriginUrlProjectSchema.parse(props);
|
|
2818
|
-
const projectPath = pathTo.project(props.id);
|
|
2819
|
-
const hasOrigin = await this.gitService.remotes.hasOrigin(projectPath);
|
|
2820
|
-
if (!hasOrigin) {
|
|
2821
|
-
await this.gitService.remotes.addOrigin(projectPath, props.url);
|
|
2822
|
-
} else {
|
|
2823
|
-
await this.gitService.remotes.setOriginUrl(projectPath, props.url);
|
|
2824
|
-
}
|
|
2825
|
-
}
|
|
2826
|
-
};
|
|
2827
|
-
this.jsonFileService = jsonFileService;
|
|
2828
|
-
this.userService = userService;
|
|
2829
|
-
this.gitService = gitService;
|
|
2830
|
-
this.assetService = assetService;
|
|
2831
|
-
this.collectionService = collectionService;
|
|
2832
|
-
this.entryService = entryService;
|
|
2833
|
-
}
|
|
2834
|
-
/**
|
|
2835
|
-
* Creates a new Project
|
|
2836
|
-
*/
|
|
2837
|
-
async create(props) {
|
|
2838
|
-
createProjectSchema.parse(props);
|
|
2839
|
-
const user = await this.userService.get();
|
|
2840
|
-
if (!user) {
|
|
2841
|
-
throw new NoCurrentUserError();
|
|
2842
|
-
}
|
|
2843
|
-
const id = uuid();
|
|
2844
|
-
const defaultSettings = {
|
|
2845
|
-
language: {
|
|
2846
|
-
default: user.language,
|
|
2847
|
-
supported: [user.language]
|
|
2848
|
-
}
|
|
2849
|
-
};
|
|
2850
|
-
const projectFile = {
|
|
2851
|
-
...props,
|
|
2852
|
-
objectType: "project",
|
|
2853
|
-
id,
|
|
2854
|
-
description: props.description || "",
|
|
2855
|
-
settings: Object.assign({}, defaultSettings, props.settings),
|
|
2856
|
-
created: currentTimestamp(),
|
|
2857
|
-
updated: null,
|
|
2858
|
-
coreVersion: this.options.version,
|
|
2859
|
-
// @todo should be read from package.json to avoid duplicates
|
|
2860
|
-
status: "todo",
|
|
2861
|
-
version: "0.0.1"
|
|
2862
|
-
};
|
|
2863
|
-
const projectPath = pathTo.project(id);
|
|
2864
|
-
await import_fs_extra6.default.ensureDir(projectPath);
|
|
2865
|
-
try {
|
|
2866
|
-
await this.createFolderStructure(projectPath);
|
|
2867
|
-
await this.createGitignore(projectPath);
|
|
2868
|
-
await this.gitService.init(projectPath, { initialBranch: "main" });
|
|
2869
|
-
await this.jsonFileService.create(
|
|
2870
|
-
projectFile,
|
|
2871
|
-
pathTo.projectFile(id),
|
|
2872
|
-
projectFileSchema
|
|
2873
|
-
);
|
|
2874
|
-
await this.gitService.add(projectPath, ["."]);
|
|
2875
|
-
await this.gitService.commit(
|
|
2876
|
-
projectPath,
|
|
2877
|
-
`${gitCommitIconSchema.enum.INIT} Created this new elek.io project`
|
|
2878
|
-
);
|
|
2879
|
-
await this.gitService.branches.switch(projectPath, "stage", {
|
|
2880
|
-
isNew: true
|
|
2881
|
-
});
|
|
2882
|
-
} catch (error) {
|
|
2883
|
-
await this.delete({
|
|
2884
|
-
id
|
|
2885
|
-
});
|
|
2886
|
-
throw error;
|
|
2887
|
-
}
|
|
2888
|
-
return await this.toProject({
|
|
2889
|
-
projectFile
|
|
2890
|
-
});
|
|
2891
|
-
}
|
|
2892
|
-
/**
|
|
2893
|
-
* Clones a Project by URL
|
|
2894
|
-
*/
|
|
2895
|
-
async clone(props) {
|
|
2896
|
-
cloneProjectSchema.parse(props);
|
|
2897
|
-
const tmpId = uuid();
|
|
2898
|
-
const tmpProjectPath = import_path2.default.join(pathTo.tmp, tmpId);
|
|
2899
|
-
await this.gitService.clone(props.url, tmpProjectPath);
|
|
2900
|
-
const projectFile = await this.jsonFileService.read(
|
|
2901
|
-
import_path2.default.join(tmpProjectPath, "project.json"),
|
|
2902
|
-
projectFileSchema
|
|
2903
|
-
);
|
|
2904
|
-
const projectPath = pathTo.project(projectFile.id);
|
|
2905
|
-
const alreadyExists = await import_fs_extra6.default.pathExists(projectPath);
|
|
2906
|
-
if (alreadyExists) {
|
|
2907
|
-
throw new Error(
|
|
2908
|
-
`Tried to clone Project "${projectFile.id}" from "${props.url}" - but the Project already exists locally`
|
|
2909
|
-
);
|
|
2910
|
-
}
|
|
2911
|
-
await import_fs_extra6.default.copy(tmpProjectPath, projectPath);
|
|
2912
|
-
await import_fs_extra6.default.remove(tmpProjectPath);
|
|
2913
|
-
return await this.toProject({
|
|
2914
|
-
projectFile
|
|
2915
|
-
});
|
|
2916
|
-
}
|
|
2917
|
-
/**
|
|
2918
|
-
* Returns a Project by ID
|
|
2919
|
-
*/
|
|
2920
|
-
async read(props) {
|
|
2921
|
-
readProjectSchema.parse(props);
|
|
2922
|
-
const projectFile = await this.jsonFileService.read(
|
|
2923
|
-
pathTo.projectFile(props.id),
|
|
2924
|
-
projectFileSchema
|
|
2925
|
-
);
|
|
2926
|
-
return await this.toProject({
|
|
2927
|
-
projectFile
|
|
2928
|
-
});
|
|
2929
|
-
}
|
|
2930
|
-
/**
|
|
2931
|
-
* Updates given Project
|
|
2932
|
-
*/
|
|
2933
|
-
async update(props) {
|
|
2934
|
-
updateProjectSchema.parse(props);
|
|
2935
|
-
const projectPath = pathTo.project(props.id);
|
|
2936
|
-
const filePath = pathTo.projectFile(props.id);
|
|
2937
|
-
const prevProjectFile = await this.read(props);
|
|
2938
|
-
const projectFile = {
|
|
2939
|
-
...prevProjectFile,
|
|
2940
|
-
...props,
|
|
2941
|
-
updated: currentTimestamp()
|
|
2942
|
-
};
|
|
2943
|
-
await this.jsonFileService.update(projectFile, filePath, projectFileSchema);
|
|
2944
|
-
await this.gitService.add(projectPath, [filePath]);
|
|
2945
|
-
await this.gitService.commit(projectPath, this.gitMessage.update);
|
|
2946
|
-
return await this.toProject({
|
|
2947
|
-
projectFile
|
|
2948
|
-
});
|
|
2949
|
-
}
|
|
2950
|
-
/**
|
|
2951
|
-
* Upgrades given Project to the latest version of this client
|
|
2952
|
-
*
|
|
2953
|
-
* Needed when a new core version is requiring changes to existing files or structure.
|
|
2954
|
-
*
|
|
2955
|
-
* @todo Find out why using this.snapshotService is throwing isObjWithKeyAndValueOfString of undefined error in gitService (maybe binding issue)
|
|
2956
|
-
*/
|
|
2957
|
-
async upgrade(props) {
|
|
2958
|
-
upgradeProjectSchema.parse(props);
|
|
2959
|
-
const project = await this.read(props);
|
|
2960
|
-
const projectPath = pathTo.project(project.id);
|
|
2961
|
-
if (import_semver.default.gt(project.coreVersion, this.options.version)) {
|
|
2962
|
-
throw new Error(
|
|
2963
|
-
`Failed upgrading project. The projects core version "${project.coreVersion}" is higher than the current core version "${this.options.version}" of this client. A client upgrade is needed beforehand.`
|
|
2964
|
-
);
|
|
2965
|
-
}
|
|
2966
|
-
if (import_semver.default.eq(project.coreVersion, this.options.version)) {
|
|
2967
|
-
return;
|
|
2968
|
-
}
|
|
2969
|
-
const upgradeFiles = await files(
|
|
2970
|
-
import_path2.default.resolve(__dirname, "../upgrade"),
|
|
2971
|
-
"ts"
|
|
2972
|
-
);
|
|
2973
|
-
const upgrades = (await Promise.all(
|
|
2974
|
-
upgradeFiles.map((file) => {
|
|
2975
|
-
return import(import_path2.default.join("../upgrade", file.name));
|
|
2976
|
-
})
|
|
2977
|
-
)).map((upgradeImport) => {
|
|
2978
|
-
return upgradeImport.default;
|
|
2979
|
-
});
|
|
2980
|
-
const sortedUpgrades = upgrades.sort((a, b) => {
|
|
2981
|
-
return import_semver.default.compare(a.to, b.to);
|
|
2982
|
-
}).filter((upgrade) => {
|
|
2983
|
-
if (upgrade.to !== "0.0.0") {
|
|
2984
|
-
return upgrade;
|
|
2985
|
-
}
|
|
2986
|
-
});
|
|
2987
|
-
for (let index = 0; index < sortedUpgrades.length; index++) {
|
|
2988
|
-
const upgrade = sortedUpgrades[index];
|
|
2989
|
-
if (!upgrade) {
|
|
2990
|
-
throw new Error("Expected ProjectUpgrade but got undefined");
|
|
2991
|
-
}
|
|
2992
|
-
const failsafeTag = await this.gitService.tags.create({
|
|
2993
|
-
path: projectPath,
|
|
2994
|
-
message: `Attempting to upgrade Project to Core version "${upgrade.to}"`
|
|
2995
|
-
});
|
|
2996
|
-
try {
|
|
2997
|
-
await upgrade.run(project);
|
|
2998
|
-
project.coreVersion = upgrade.to;
|
|
2999
|
-
await this.update(project);
|
|
3000
|
-
await this.gitService.tags.create({
|
|
3001
|
-
path: projectPath,
|
|
3002
|
-
message: `Upgraded Project to Core version "${upgrade.to}"`
|
|
3003
|
-
});
|
|
3004
|
-
await this.gitService.tags.delete({
|
|
3005
|
-
path: projectPath,
|
|
3006
|
-
id: failsafeTag.id
|
|
3007
|
-
});
|
|
3008
|
-
} catch (error) {
|
|
3009
|
-
await this.gitService.reset(projectPath, "hard", failsafeTag.id);
|
|
3010
|
-
throw new ProjectUpgradeError(
|
|
3011
|
-
`Failed to upgrade Project to Core version "${upgrade.to}"`
|
|
3012
|
-
);
|
|
3013
|
-
}
|
|
3014
|
-
}
|
|
3015
|
-
}
|
|
3016
|
-
/**
|
|
3017
|
-
* Returns the differences of the given Projects current branch
|
|
3018
|
-
* between the local and remote `origin` (commits ahead & behind)
|
|
3019
|
-
*
|
|
3020
|
-
* - `behind` contains a list of commits on the current branch that are available on the remote `origin` but not yet locally
|
|
3021
|
-
* - `ahead` contains a list of commits on the current branch that are available locally but not yet on the remote `origin`
|
|
3022
|
-
*/
|
|
3023
|
-
async getChanges(props) {
|
|
3024
|
-
getChangesProjectSchema.parse(props);
|
|
3025
|
-
const projectPath = pathTo.project(props.id);
|
|
3026
|
-
const currentBranch = await this.gitService.branches.current(projectPath);
|
|
3027
|
-
await this.gitService.fetch(projectPath);
|
|
3028
|
-
const behind = await this.gitService.log(projectPath, {
|
|
3029
|
-
between: { from: currentBranch, to: `origin/${currentBranch}` }
|
|
3030
|
-
});
|
|
3031
|
-
const ahead = await this.gitService.log(projectPath, {
|
|
3032
|
-
between: { from: `origin/${currentBranch}`, to: currentBranch }
|
|
3033
|
-
});
|
|
3034
|
-
return {
|
|
3035
|
-
behind,
|
|
3036
|
-
ahead
|
|
3037
|
-
};
|
|
3038
|
-
}
|
|
3039
|
-
/**
|
|
3040
|
-
* Pulls remote changes of `origin` down to the local repository
|
|
3041
|
-
* and then pushes local commits to the upstream branch
|
|
3042
|
-
*/
|
|
3043
|
-
async synchronize(props) {
|
|
3044
|
-
synchronizeProjectSchema.parse(props);
|
|
3045
|
-
const projectPath = pathTo.project(props.id);
|
|
3046
|
-
await this.gitService.pull(projectPath);
|
|
3047
|
-
await this.gitService.push(projectPath);
|
|
3048
|
-
}
|
|
3049
|
-
/**
|
|
3050
|
-
* Deletes given Project
|
|
3051
|
-
*
|
|
3052
|
-
* Deletes the whole Project folder including the history, not only the config file.
|
|
3053
|
-
* Use with caution, since a Project that is only available locally could be lost forever.
|
|
3054
|
-
* Or changes that are not pushed to a remote yet, will be lost too.
|
|
3055
|
-
*/
|
|
3056
|
-
async delete(props) {
|
|
3057
|
-
deleteProjectSchema.parse(props);
|
|
3058
|
-
await import_fs_extra6.default.remove(pathTo.project(props.id));
|
|
3059
|
-
}
|
|
3060
|
-
async list(props) {
|
|
3061
|
-
if (props) {
|
|
3062
|
-
listProjectsSchema.parse(props);
|
|
3063
|
-
}
|
|
3064
|
-
const offset = props?.offset || 0;
|
|
3065
|
-
const limit = props?.limit || 15;
|
|
3066
|
-
const projectReferences = await this.listReferences(
|
|
3067
|
-
objectTypeSchema.Enum.project
|
|
3068
|
-
);
|
|
3069
|
-
const partialProjectReferences = projectReferences.slice(offset, limit);
|
|
3070
|
-
const projects = await returnResolved(
|
|
3071
|
-
partialProjectReferences.map((reference) => {
|
|
3072
|
-
return this.read({ id: reference.id });
|
|
3073
|
-
})
|
|
3074
|
-
);
|
|
3075
|
-
return {
|
|
3076
|
-
total: projectReferences.length,
|
|
3077
|
-
limit,
|
|
3078
|
-
offset,
|
|
3079
|
-
list: projects
|
|
3080
|
-
};
|
|
3081
|
-
}
|
|
3082
|
-
async count() {
|
|
3083
|
-
return (await this.listReferences(objectTypeSchema.Enum.project)).length;
|
|
3084
|
-
}
|
|
3085
|
-
/**
|
|
3086
|
-
* Checks if given object is of type Project
|
|
3087
|
-
*/
|
|
3088
|
-
isProject(obj) {
|
|
3089
|
-
return projectFileSchema.safeParse(obj).success;
|
|
3090
|
-
}
|
|
3091
|
-
/**
|
|
3092
|
-
* Exports given Project to JSON
|
|
3093
|
-
*
|
|
3094
|
-
* @todo do not read everything before writing to disk -> stream into file given via props
|
|
3095
|
-
* @todo performance tests
|
|
3096
|
-
* @todo add progress callback
|
|
3097
|
-
*/
|
|
3098
|
-
async exportToJson(projectId) {
|
|
3099
|
-
const project = await this.read({ id: projectId });
|
|
3100
|
-
const assets = (await this.assetService.list({ projectId, limit: 0 })).list;
|
|
3101
|
-
const collections = (await this.collectionService.list({ projectId, limit: 0 })).list;
|
|
3102
|
-
const collectionExport = await Promise.all(
|
|
3103
|
-
collections.map(async (collection) => {
|
|
3104
|
-
const entries = (await this.entryService.list({
|
|
3105
|
-
projectId,
|
|
3106
|
-
collectionId: collection.id,
|
|
3107
|
-
limit: 0
|
|
3108
|
-
})).list;
|
|
3109
|
-
return {
|
|
3110
|
-
...collection,
|
|
3111
|
-
entries
|
|
3112
|
-
};
|
|
3113
|
-
})
|
|
3114
|
-
);
|
|
3115
|
-
return {
|
|
3116
|
-
...project,
|
|
3117
|
-
assets,
|
|
3118
|
-
collections: collectionExport
|
|
3119
|
-
};
|
|
3120
|
-
}
|
|
3121
|
-
/**
|
|
3122
|
-
* Creates a Project from given ProjectFile by adding git information
|
|
3123
|
-
*/
|
|
3124
|
-
async toProject(props) {
|
|
3125
|
-
return {
|
|
3126
|
-
...props.projectFile
|
|
3127
|
-
};
|
|
3128
|
-
}
|
|
3129
|
-
/**
|
|
3130
|
-
* Creates the projects folder structure and makes sure to
|
|
3131
|
-
* write empty .gitkeep files inside them to ensure they are
|
|
3132
|
-
* committed
|
|
3133
|
-
*/
|
|
3134
|
-
async createFolderStructure(path) {
|
|
3135
|
-
const folders2 = Object.values(projectFolderSchema.Values);
|
|
3136
|
-
await Promise.all(
|
|
3137
|
-
folders2.map(async (folder) => {
|
|
3138
|
-
await import_fs_extra6.default.mkdirp(import_path2.default.join(path, folder));
|
|
3139
|
-
await import_fs_extra6.default.writeFile(import_path2.default.join(path, folder, ".gitkeep"), "");
|
|
3140
|
-
})
|
|
3141
|
-
);
|
|
3142
|
-
}
|
|
3143
|
-
/**
|
|
3144
|
-
* Writes the Projects main .gitignore file to disk
|
|
3145
|
-
*
|
|
3146
|
-
* @todo Add general things to ignore
|
|
3147
|
-
* @see https://github.com/github/gitignore/tree/master/Global
|
|
3148
|
-
*/
|
|
3149
|
-
async createGitignore(path) {
|
|
3150
|
-
const lines = [
|
|
3151
|
-
"# Ignore all hidden files and folders...",
|
|
3152
|
-
".*",
|
|
3153
|
-
"# ...but these",
|
|
3154
|
-
"!/.gitignore",
|
|
3155
|
-
"!/.gitattributes",
|
|
3156
|
-
"!/**/.gitkeep",
|
|
3157
|
-
"",
|
|
3158
|
-
"# elek.io related ignores"
|
|
3159
|
-
// projectFolderSchema.Enum.theme + '/',
|
|
3160
|
-
// projectFolderSchema.Enum.public + '/',
|
|
3161
|
-
// projectFolderSchema.Enum.logs + '/',
|
|
3162
|
-
];
|
|
3163
|
-
await import_fs_extra6.default.writeFile(import_path2.default.join(path, ".gitignore"), lines.join(import_os4.default.EOL));
|
|
3164
|
-
}
|
|
3165
|
-
};
|
|
3166
|
-
|
|
3167
|
-
// src/index.node.ts
|
|
3168
|
-
var ElekIoCore = class {
|
|
3169
|
-
// private readonly sharedValueService: SharedValueService;
|
|
3170
|
-
constructor(props) {
|
|
3171
|
-
const parsedProps = constructorElekIoCoreSchema.parse(props);
|
|
3172
|
-
const defaults = {
|
|
3173
|
-
environment: "production",
|
|
3174
|
-
version: "0.0.0",
|
|
3175
|
-
file: {
|
|
3176
|
-
json: {
|
|
3177
|
-
indentation: 2
|
|
3178
|
-
}
|
|
3179
|
-
}
|
|
3180
|
-
};
|
|
3181
|
-
this.options = Object.assign({}, defaults, parsedProps);
|
|
3182
|
-
this.jsonFileService = new JsonFileService(this.options);
|
|
3183
|
-
this.userService = new UserService(this.jsonFileService);
|
|
3184
|
-
this.gitService = new GitService2(this.options, this.userService);
|
|
3185
|
-
this.assetService = new AssetService(
|
|
3186
|
-
this.options,
|
|
3187
|
-
this.jsonFileService,
|
|
3188
|
-
this.gitService
|
|
3189
|
-
);
|
|
3190
|
-
this.collectionService = new CollectionService(
|
|
3191
|
-
this.options,
|
|
3192
|
-
this.jsonFileService,
|
|
3193
|
-
this.gitService
|
|
3194
|
-
);
|
|
3195
|
-
this.entryService = new EntryService(
|
|
3196
|
-
this.options,
|
|
3197
|
-
this.jsonFileService,
|
|
3198
|
-
this.gitService,
|
|
3199
|
-
this.collectionService,
|
|
3200
|
-
this.assetService
|
|
3201
|
-
// this.sharedValueService
|
|
3202
|
-
);
|
|
3203
|
-
this.projectService = new ProjectService(
|
|
3204
|
-
this.options,
|
|
3205
|
-
this.jsonFileService,
|
|
3206
|
-
this.userService,
|
|
3207
|
-
this.gitService,
|
|
3208
|
-
this.assetService,
|
|
3209
|
-
this.collectionService,
|
|
3210
|
-
this.entryService
|
|
3211
|
-
);
|
|
3212
|
-
if (this.options.environment !== "production") {
|
|
3213
|
-
console.info(
|
|
3214
|
-
`Initializing inside an "${this.options.environment}" environment`,
|
|
3215
|
-
{
|
|
3216
|
-
...this.options
|
|
3217
|
-
}
|
|
3218
|
-
);
|
|
3219
|
-
}
|
|
3220
|
-
import_fs_extra7.default.mkdirpSync(pathTo.projects);
|
|
3221
|
-
import_fs_extra7.default.mkdirpSync(pathTo.tmp);
|
|
3222
|
-
import_fs_extra7.default.emptyDirSync(pathTo.tmp);
|
|
3223
|
-
}
|
|
3224
|
-
/**
|
|
3225
|
-
* Utility / helper functions
|
|
3226
|
-
*/
|
|
3227
|
-
get util() {
|
|
3228
|
-
return node_exports;
|
|
3229
|
-
}
|
|
3230
|
-
/**
|
|
3231
|
-
* Exposes git functions
|
|
3232
|
-
*/
|
|
3233
|
-
get git() {
|
|
3234
|
-
return this.gitService;
|
|
3235
|
-
}
|
|
3236
|
-
/**
|
|
3237
|
-
* Getter and setter methods for the User currently working with Core
|
|
3238
|
-
*/
|
|
3239
|
-
get user() {
|
|
3240
|
-
return this.userService;
|
|
3241
|
-
}
|
|
3242
|
-
/**
|
|
3243
|
-
* CRUD methods to work with Projects
|
|
3244
|
-
*/
|
|
3245
|
-
get projects() {
|
|
3246
|
-
return this.projectService;
|
|
3247
|
-
}
|
|
3248
|
-
/**
|
|
3249
|
-
* CRUD methods to work with Assets
|
|
3250
|
-
*/
|
|
3251
|
-
get assets() {
|
|
3252
|
-
return this.assetService;
|
|
3253
|
-
}
|
|
3254
|
-
/**
|
|
3255
|
-
* CRUD methods to work with Collections
|
|
3256
|
-
*/
|
|
3257
|
-
get collections() {
|
|
3258
|
-
return this.collectionService;
|
|
3259
|
-
}
|
|
3260
|
-
/**
|
|
3261
|
-
* CRUD methods to work with Entries
|
|
3262
|
-
*/
|
|
3263
|
-
get entries() {
|
|
3264
|
-
return this.entryService;
|
|
3265
|
-
}
|
|
3266
|
-
/**
|
|
3267
|
-
* CRUD methods to work with Values
|
|
3268
|
-
*/
|
|
3269
|
-
// public get sharedValues(): SharedValueService {
|
|
3270
|
-
// return this.sharedValueService;
|
|
3271
|
-
// }
|
|
3272
|
-
};
|
|
3273
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
3274
|
-
0 && (module.exports = {
|
|
3275
|
-
BooleanValueDefinitionBaseSchema,
|
|
3276
|
-
NumberValueDefinitionBaseSchema,
|
|
3277
|
-
ReferenceValueDefinitionBaseSchema,
|
|
3278
|
-
StringValueDefinitionBaseSchema,
|
|
3279
|
-
UserTypeSchema,
|
|
3280
|
-
ValueDefinitionBaseSchema,
|
|
3281
|
-
ValueInputTypeSchema,
|
|
3282
|
-
ValueInputWidthSchema,
|
|
3283
|
-
ValueTypeSchema,
|
|
3284
|
-
assetExportSchema,
|
|
3285
|
-
assetFileSchema,
|
|
3286
|
-
assetSchema,
|
|
3287
|
-
assetValueDefinitionSchema,
|
|
3288
|
-
baseFileSchema,
|
|
3289
|
-
baseFileWithLanguageSchema,
|
|
3290
|
-
baseUserSchema,
|
|
3291
|
-
cloneProjectSchema,
|
|
3292
|
-
cloudUserSchema,
|
|
3293
|
-
collectionExportSchema,
|
|
3294
|
-
collectionFileSchema,
|
|
3295
|
-
collectionSchema,
|
|
3296
|
-
constructorElekIoCoreSchema,
|
|
3297
|
-
countAssetsSchema,
|
|
3298
|
-
countCollectionsSchema,
|
|
3299
|
-
countEntriesSchema,
|
|
3300
|
-
countGitTagsSchema,
|
|
3301
|
-
createAssetSchema,
|
|
3302
|
-
createCollectionSchema,
|
|
3303
|
-
createEntrySchema,
|
|
3304
|
-
createGitTagSchema,
|
|
3305
|
-
createProjectSchema,
|
|
3306
|
-
currentBranchProjectSchema,
|
|
3307
|
-
currentTimestamp,
|
|
3308
|
-
dateValueDefinitionSchema,
|
|
3309
|
-
datetimeValueDefinitionSchema,
|
|
3310
|
-
deleteAssetSchema,
|
|
3311
|
-
deleteCollectionSchema,
|
|
3312
|
-
deleteEntrySchema,
|
|
3313
|
-
deleteGitTagSchema,
|
|
3314
|
-
deleteProjectSchema,
|
|
3315
|
-
directBooleanValueSchema,
|
|
3316
|
-
directNumberValueSchema,
|
|
3317
|
-
directStringValueSchema,
|
|
3318
|
-
directValueBaseSchema,
|
|
3319
|
-
directValueSchema,
|
|
3320
|
-
elekIoCoreOptionsSchema,
|
|
3321
|
-
emailValueDefinitionSchema,
|
|
3322
|
-
entryExportSchema,
|
|
3323
|
-
entryFileSchema,
|
|
3324
|
-
entrySchema,
|
|
3325
|
-
entryValueDefinitionSchema,
|
|
3326
|
-
environmentSchema,
|
|
3327
|
-
fileReferenceSchema,
|
|
3328
|
-
getChangesProjectSchema,
|
|
3329
|
-
getRemoteOriginUrlProjectSchema,
|
|
3330
|
-
getValueContentSchemaFromDefinition,
|
|
3331
|
-
gitCloneOptionsSchema,
|
|
3332
|
-
gitCommitIconSchema,
|
|
3333
|
-
gitCommitSchema,
|
|
3334
|
-
gitInitOptionsSchema,
|
|
3335
|
-
gitLogOptionsSchema,
|
|
3336
|
-
gitRepositoryPathSchema,
|
|
3337
|
-
gitSignatureSchema,
|
|
3338
|
-
gitSwitchOptionsSchema,
|
|
3339
|
-
gitTagSchema,
|
|
3340
|
-
ipValueDefinitionSchema,
|
|
3341
|
-
listAssetsSchema,
|
|
3342
|
-
listBranchesProjectSchema,
|
|
3343
|
-
listCollectionsSchema,
|
|
3344
|
-
listEntriesSchema,
|
|
3345
|
-
listGitTagsSchema,
|
|
3346
|
-
listProjectsSchema,
|
|
3347
|
-
localUserSchema,
|
|
3348
|
-
numberValueDefinitionSchema,
|
|
3349
|
-
objectTypeSchema,
|
|
3350
|
-
projectExportSchema,
|
|
3351
|
-
projectFileSchema,
|
|
3352
|
-
projectFolderSchema,
|
|
3353
|
-
projectSchema,
|
|
3354
|
-
projectSettingsSchema,
|
|
3355
|
-
projectStatusSchema,
|
|
3356
|
-
projectUpgradeSchema,
|
|
3357
|
-
rangeValueDefinitionSchema,
|
|
3358
|
-
readAssetSchema,
|
|
3359
|
-
readCollectionSchema,
|
|
3360
|
-
readEntrySchema,
|
|
3361
|
-
readGitTagSchema,
|
|
3362
|
-
readProjectSchema,
|
|
3363
|
-
referencedValueSchema,
|
|
3364
|
-
resolvedReferencedValueSchema,
|
|
3365
|
-
resolvedValueContentReferenceSchema,
|
|
3366
|
-
resolvedValueSchema,
|
|
3367
|
-
searchProjectSchema,
|
|
3368
|
-
serviceTypeSchema,
|
|
3369
|
-
setRemoteOriginUrlProjectSchema,
|
|
3370
|
-
setUserSchema,
|
|
3371
|
-
slug,
|
|
3372
|
-
stringValueDefinitionSchema,
|
|
3373
|
-
supportedAssetExtensionSchema,
|
|
3374
|
-
supportedAssetMimeTypeSchema,
|
|
3375
|
-
supportedAssetTypeSchema,
|
|
3376
|
-
supportedIconSchema,
|
|
3377
|
-
supportedLanguageSchema,
|
|
3378
|
-
switchBranchProjectSchema,
|
|
3379
|
-
synchronizeProjectSchema,
|
|
3380
|
-
telephoneValueDefinitionSchema,
|
|
3381
|
-
textValueDefinitionSchema,
|
|
3382
|
-
textareaValueDefinitionSchema,
|
|
3383
|
-
timeValueDefinitionSchema,
|
|
3384
|
-
toggleValueDefinitionSchema,
|
|
3385
|
-
translatableArrayOf,
|
|
3386
|
-
translatableBooleanSchema,
|
|
3387
|
-
translatableNumberSchema,
|
|
3388
|
-
translatableStringSchema,
|
|
3389
|
-
updateAssetSchema,
|
|
3390
|
-
updateCollectionSchema,
|
|
3391
|
-
updateEntrySchema,
|
|
3392
|
-
updateProjectSchema,
|
|
3393
|
-
upgradeProjectSchema,
|
|
3394
|
-
urlValueDefinitionSchema,
|
|
3395
|
-
userFileSchema,
|
|
3396
|
-
userSchema,
|
|
3397
|
-
uuid,
|
|
3398
|
-
uuidSchema,
|
|
3399
|
-
valueContentReferenceBase,
|
|
3400
|
-
valueContentReferenceSchema,
|
|
3401
|
-
valueContentReferenceToAssetSchema,
|
|
3402
|
-
valueContentReferenceToCollectionSchema,
|
|
3403
|
-
valueContentReferenceToEntrySchema,
|
|
3404
|
-
valueContentReferenceWithLanguageBase,
|
|
3405
|
-
valueDefinitionSchema,
|
|
3406
|
-
valueSchema,
|
|
3407
|
-
versionSchema
|
|
3408
|
-
});
|
|
3409
|
-
//# sourceMappingURL=index.node.cjs.map
|