@elek-io/core 0.1.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/README.md +64 -0
- package/dist/index.cjs +2177 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +816 -0
- package/dist/index.d.ts +816 -0
- package/dist/index.js +2250 -0
- package/dist/index.js.map +1 -0
- package/package.json +56 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,816 @@
|
|
|
1
|
+
import * as _elek_io_shared from '@elek-io/shared';
|
|
2
|
+
import { ServiceType, ElekIoCoreOptions, BaseFile, GitTag, Sort, PaginatedList, FileType, FileReference, ExtendedCrudService, CreateGitTagProps, ReadGitTagProps, DeleteGitTagProps, ListGitTagsProps, CountGitTagsProps, UserFile, User, SetUserProps, GitInitOptions, GitCloneOptions, GitSwitchOptions, GitLogOptions, GitCommit, Asset, CreateAssetProps, ReadAssetProps, UpdateAssetProps, DeleteAssetProps, ListAssetsProps, CountAssetsProps, Collection, CreateCollectionProps, ReadCollectionProps, UpdateCollectionProps, DeleteCollectionProps, ListCollectionsProps, CountCollectionsProps, Value, CreateValueProps, ReadValueProps, UpdateValueProps, DeleteValueProps, ListValuesProps, CountValuesProps, ValidateValueProps, Entry, CreateEntryProps, ReadEntryProps, UpdateEntryProps, DeleteEntryProps, ListEntriesProps, CountEntriesProps, Project, CreateProjectProps, ReadProjectProps, UpdateProjectProps, UpgradeProjectProps, DeleteProjectProps, ListProjectsProps, ProjectExport, ConstructorElekIoCoreProps } from '@elek-io/shared';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { SpawnOptionsWithoutStdio } from 'child_process';
|
|
5
|
+
import Fs from 'fs-extra';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A base service that provides properties for most other services
|
|
9
|
+
*/
|
|
10
|
+
declare abstract class AbstractCrudService {
|
|
11
|
+
readonly type: ServiceType;
|
|
12
|
+
readonly options: ElekIoCoreOptions;
|
|
13
|
+
/**
|
|
14
|
+
* Dynamically generated git messages for operations
|
|
15
|
+
*/
|
|
16
|
+
readonly gitMessage: {
|
|
17
|
+
create: string;
|
|
18
|
+
update: string;
|
|
19
|
+
delete: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Do not instantiate directly as this is an abstract class
|
|
23
|
+
*/
|
|
24
|
+
protected constructor(type: ServiceType, options: ElekIoCoreOptions);
|
|
25
|
+
/**
|
|
26
|
+
* Returns the filtered, sorted and paginated version of given list
|
|
27
|
+
*
|
|
28
|
+
* @todo Sorting and filtering requires all models to be loaded
|
|
29
|
+
* from disk. This results in a huge memory spike before the
|
|
30
|
+
* filtering and pagination takes effect - removing most of it again.
|
|
31
|
+
* This approach is still better than returning everything and
|
|
32
|
+
* letting the frontend handle it, since the memory usage would then be constant.
|
|
33
|
+
* But this still could fill the memory limit of node.js (default 1,4 GB).
|
|
34
|
+
*
|
|
35
|
+
* @param list Array to filter, sort and paginate
|
|
36
|
+
* @param sort Array of sort objects containing information about what to sort and how
|
|
37
|
+
* @param filter Filter all object values of `list` by this string
|
|
38
|
+
* @param limit Limit the result to this amount. If 0 is given, no limit is applied
|
|
39
|
+
* @param offset Start at this index instead of 0
|
|
40
|
+
*/
|
|
41
|
+
protected paginate<T extends BaseFile | GitTag>(list: T[], sort?: Sort<T>[], filter?: string, limit?: number, offset?: number): Promise<PaginatedList<T>>;
|
|
42
|
+
/**
|
|
43
|
+
* Returns a list of all file references of given project and type
|
|
44
|
+
*
|
|
45
|
+
* @param type File type of the references wanted
|
|
46
|
+
* @param projectId Project to get all asset references from
|
|
47
|
+
* @param collectionId Only needed when requesting files of type "Entry"
|
|
48
|
+
*/
|
|
49
|
+
protected listReferences(type: FileType, projectId?: string, collectionId?: string): Promise<FileReference[]>;
|
|
50
|
+
private getFolderReferences;
|
|
51
|
+
/**
|
|
52
|
+
* Searches for all files inside given folder,
|
|
53
|
+
* parses their names and returns them as FileReference
|
|
54
|
+
*
|
|
55
|
+
* Ignores files not matching the [id].[language].[extension]
|
|
56
|
+
* or [id].[extension] format for their names
|
|
57
|
+
*/
|
|
58
|
+
private getFileReferences;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Service that manages CRUD functionality for GitTags
|
|
63
|
+
*/
|
|
64
|
+
declare class GitTagService extends AbstractCrudService implements ExtendedCrudService<GitTag> {
|
|
65
|
+
private git;
|
|
66
|
+
constructor(options: ElekIoCoreOptions, git: GitService['git']);
|
|
67
|
+
/**
|
|
68
|
+
* Creates a new tag
|
|
69
|
+
*
|
|
70
|
+
* @see https://git-scm.com/docs/git-tag#Documentation/git-tag.txt---annotate
|
|
71
|
+
*/
|
|
72
|
+
create(props: CreateGitTagProps): Promise<GitTag>;
|
|
73
|
+
/**
|
|
74
|
+
* Returns a tag by ID
|
|
75
|
+
*
|
|
76
|
+
* Internally uses list() with id as pattern.
|
|
77
|
+
*/
|
|
78
|
+
read(props: ReadGitTagProps): Promise<GitTag>;
|
|
79
|
+
/**
|
|
80
|
+
* Updating a git tag is not supported.
|
|
81
|
+
* Please delete the old and create a new one
|
|
82
|
+
*
|
|
83
|
+
* @see https://git-scm.com/docs/git-tag#_on_re_tagging
|
|
84
|
+
*/
|
|
85
|
+
update(): Promise<never>;
|
|
86
|
+
/**
|
|
87
|
+
* Deletes a tag
|
|
88
|
+
*
|
|
89
|
+
* @see https://git-scm.com/docs/git-tag#Documentation/git-tag.txt---delete
|
|
90
|
+
*
|
|
91
|
+
* @param path Path to the repository
|
|
92
|
+
* @param id UUID of the tag to delete
|
|
93
|
+
*/
|
|
94
|
+
delete(props: DeleteGitTagProps): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Gets all local tags or filter them by pattern
|
|
97
|
+
*
|
|
98
|
+
* They are sorted by authordate of the commit, not the timestamp the tag is created.
|
|
99
|
+
* This ensures tags are sorted correctly in the timeline of their commits.
|
|
100
|
+
*
|
|
101
|
+
* @see https://git-scm.com/docs/git-tag#Documentation/git-tag.txt---list
|
|
102
|
+
*/
|
|
103
|
+
list(props: ListGitTagsProps): Promise<PaginatedList<GitTag>>;
|
|
104
|
+
/**
|
|
105
|
+
* Returns the total number of tags inside given repository
|
|
106
|
+
*
|
|
107
|
+
* Internally uses list(), so do not use count()
|
|
108
|
+
* in conjuncion with it to avoid multiple git calls.
|
|
109
|
+
*
|
|
110
|
+
* @param path Path to the repository
|
|
111
|
+
*/
|
|
112
|
+
count(props: CountGitTagsProps): Promise<number>;
|
|
113
|
+
/**
|
|
114
|
+
* Type guard for GitTag
|
|
115
|
+
*
|
|
116
|
+
* @param obj The object to check
|
|
117
|
+
*/
|
|
118
|
+
private isGitTag;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Service that manages CRUD functionality for JSON files on disk
|
|
123
|
+
*/
|
|
124
|
+
declare class JsonFileService extends AbstractCrudService {
|
|
125
|
+
private cache;
|
|
126
|
+
constructor(options: ElekIoCoreOptions);
|
|
127
|
+
/**
|
|
128
|
+
* Creates a new file on disk. Fails if path already exists
|
|
129
|
+
*
|
|
130
|
+
* @param data Data to write into the file
|
|
131
|
+
* @param path Path to write the file to
|
|
132
|
+
* @param schema Schema of the file to validate against
|
|
133
|
+
* @returns Validated content of the file from disk
|
|
134
|
+
*/
|
|
135
|
+
create<T extends z.ZodType<BaseFile>>(data: unknown, path: string, schema: T): Promise<z.output<T>>;
|
|
136
|
+
/**
|
|
137
|
+
* Reads the content of a file on disk. Fails if path does not exist
|
|
138
|
+
*
|
|
139
|
+
* @param path Path to read the file from
|
|
140
|
+
* @param schema Schema of the file to validate against
|
|
141
|
+
* @returns Validated content of the file from disk
|
|
142
|
+
*/
|
|
143
|
+
read<T extends z.ZodType<BaseFile | UserFile>>(path: string, schema: T): Promise<z.output<T>>;
|
|
144
|
+
/**
|
|
145
|
+
* Overwrites an existing file on disk
|
|
146
|
+
*
|
|
147
|
+
* @todo Check how to error out if the file does not exist already
|
|
148
|
+
*
|
|
149
|
+
* @param data Data to write into the file
|
|
150
|
+
* @param path Path to the file to overwrite
|
|
151
|
+
* @param schema Schema of the file to validate against
|
|
152
|
+
* @returns Validated content of the file from disk
|
|
153
|
+
*/
|
|
154
|
+
update<T extends z.ZodType<BaseFile | UserFile>>(data: unknown, path: string, schema: T): Promise<z.output<T>>;
|
|
155
|
+
private serialize;
|
|
156
|
+
private deserialize;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Service that manages CRUD functionality for Asset files on disk
|
|
161
|
+
*/
|
|
162
|
+
declare class UserService {
|
|
163
|
+
private readonly jsonFileService;
|
|
164
|
+
constructor(jsonFileService: JsonFileService);
|
|
165
|
+
/**
|
|
166
|
+
* Returns the User currently working with Core
|
|
167
|
+
*/
|
|
168
|
+
get(): Promise<User | undefined>;
|
|
169
|
+
/**
|
|
170
|
+
* Sets the User currently working with Core
|
|
171
|
+
*
|
|
172
|
+
* By doing so all git operations are done with the signature of this User
|
|
173
|
+
*/
|
|
174
|
+
set(props: SetUserProps): Promise<User>;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Service that manages Git functionality
|
|
179
|
+
*
|
|
180
|
+
* Uses dugite Node.js bindings for Git to be fully compatible
|
|
181
|
+
* and be able to leverage Git LFS functionality
|
|
182
|
+
* @see https://github.com/desktop/dugite
|
|
183
|
+
*
|
|
184
|
+
* Heavily inspired by the GitHub Desktop app
|
|
185
|
+
* @see https://github.com/desktop/desktop
|
|
186
|
+
*
|
|
187
|
+
* Git operations are sequential!
|
|
188
|
+
* We use a FIFO queue to translate async calls
|
|
189
|
+
* into a sequence of git operations
|
|
190
|
+
*/
|
|
191
|
+
declare class GitService {
|
|
192
|
+
private version;
|
|
193
|
+
private queue;
|
|
194
|
+
private gitTagService;
|
|
195
|
+
private userService;
|
|
196
|
+
constructor(options: ElekIoCoreOptions, userService: UserService);
|
|
197
|
+
/**
|
|
198
|
+
* CRUD methods to work with git tags
|
|
199
|
+
*/
|
|
200
|
+
get tags(): GitTagService;
|
|
201
|
+
/**
|
|
202
|
+
* Reads the currently used version of Git
|
|
203
|
+
*/
|
|
204
|
+
getVersion(): Promise<void>;
|
|
205
|
+
/**
|
|
206
|
+
* Create an empty Git repository or reinitialize an existing one
|
|
207
|
+
*
|
|
208
|
+
* @see https://git-scm.com/docs/git-init
|
|
209
|
+
*
|
|
210
|
+
* @param path Path to initialize in. Fails if path does not exist
|
|
211
|
+
* @param options Options specific to the init operation
|
|
212
|
+
*/
|
|
213
|
+
init(path: string, options?: Partial<GitInitOptions>): Promise<void>;
|
|
214
|
+
/**
|
|
215
|
+
* Clone a repository into a directory
|
|
216
|
+
*
|
|
217
|
+
* @see https://git-scm.com/docs/git-clone
|
|
218
|
+
*
|
|
219
|
+
* @todo Implement progress callback / events
|
|
220
|
+
*
|
|
221
|
+
* @param url The remote repository URL to clone from
|
|
222
|
+
* @param path The destination path for the cloned repository.
|
|
223
|
+
* Which is only working if the directory is existing and empty.
|
|
224
|
+
* @param options Options specific to the clone operation
|
|
225
|
+
*/
|
|
226
|
+
clone(url: string, path: string, options?: Partial<GitCloneOptions>): Promise<void>;
|
|
227
|
+
/**
|
|
228
|
+
* Add file contents to the index
|
|
229
|
+
*
|
|
230
|
+
* @see https://git-scm.com/docs/git-add
|
|
231
|
+
*
|
|
232
|
+
* @param path Path to the repository
|
|
233
|
+
* @param files Files to add
|
|
234
|
+
*/
|
|
235
|
+
add(path: string, files: string[]): Promise<void>;
|
|
236
|
+
/**
|
|
237
|
+
* Switch branches
|
|
238
|
+
*
|
|
239
|
+
* @see https://git-scm.com/docs/git-switch/
|
|
240
|
+
*
|
|
241
|
+
* @param path Path to the repository
|
|
242
|
+
* @param name Name of the branch to switch to
|
|
243
|
+
* @param options Options specific to the switch operation
|
|
244
|
+
*/
|
|
245
|
+
switch(path: string, name: string, options?: Partial<GitSwitchOptions>): Promise<void>;
|
|
246
|
+
/**
|
|
247
|
+
* Reset current HEAD to the specified state
|
|
248
|
+
*
|
|
249
|
+
* @todo maybe add more options
|
|
250
|
+
* @see https://git-scm.com/docs/git-reset
|
|
251
|
+
*
|
|
252
|
+
* @param path Path to the repository
|
|
253
|
+
* @param mode Modifies the working tree depending on given mode
|
|
254
|
+
* @param commit Resets the current branch head to this commit / tag
|
|
255
|
+
*/
|
|
256
|
+
reset(path: string, mode: 'soft' | 'hard', commit: string): Promise<void>;
|
|
257
|
+
/**
|
|
258
|
+
* Restore working tree files
|
|
259
|
+
*
|
|
260
|
+
* @see https://git-scm.com/docs/git-restore/
|
|
261
|
+
*
|
|
262
|
+
* @todo It's probably a good idea to not use restore
|
|
263
|
+
* for a use case where someone just wants to have a look
|
|
264
|
+
* and maybe copy something from a deleted file.
|
|
265
|
+
* We should use `checkout` without `add .` and `commit` for that
|
|
266
|
+
*
|
|
267
|
+
* @param path Path to the repository
|
|
268
|
+
* @param source Git commit SHA or tag name to restore to
|
|
269
|
+
* @param files Files to restore
|
|
270
|
+
*/
|
|
271
|
+
/**
|
|
272
|
+
* Fetch from and integrate with another repository or a local branch
|
|
273
|
+
*
|
|
274
|
+
* @see https://git-scm.com/docs/git-pull
|
|
275
|
+
*
|
|
276
|
+
* @param path Path to the repository
|
|
277
|
+
*/
|
|
278
|
+
pull(path: string): Promise<void>;
|
|
279
|
+
/**
|
|
280
|
+
* Record changes to the repository
|
|
281
|
+
*
|
|
282
|
+
* @see https://git-scm.com/docs/git-commit
|
|
283
|
+
*
|
|
284
|
+
* @param path Path to the repository
|
|
285
|
+
* @param message A message that describes the changes
|
|
286
|
+
*/
|
|
287
|
+
commit(path: string, message: string): Promise<void>;
|
|
288
|
+
/**
|
|
289
|
+
* Gets local commit history
|
|
290
|
+
*
|
|
291
|
+
* @see https://git-scm.com/docs/git-log
|
|
292
|
+
*
|
|
293
|
+
* @todo Check if there is a need to trim the git commit message of chars
|
|
294
|
+
* @todo Use this method in a service. Decide if we need a HistoryService for example
|
|
295
|
+
*
|
|
296
|
+
* @param path Path to the repository
|
|
297
|
+
* @param options Options specific to the log operation
|
|
298
|
+
*/
|
|
299
|
+
log(path: string, options?: Partial<GitLogOptions>): Promise<GitCommit[]>;
|
|
300
|
+
refNameToTagName(refName: string): string | undefined;
|
|
301
|
+
/**
|
|
302
|
+
* Returns a timestamp of given files creation
|
|
303
|
+
*
|
|
304
|
+
* Git only returns the timestamp the file was added,
|
|
305
|
+
* which could be different from the file being created.
|
|
306
|
+
* But since file operations will always be committed
|
|
307
|
+
* immediately, this is practically the same.
|
|
308
|
+
*
|
|
309
|
+
* @param path Path to the repository
|
|
310
|
+
* @param file File to get timestamp from
|
|
311
|
+
*/
|
|
312
|
+
getFileCreatedTimestamp(path: string, file: string): Promise<number>;
|
|
313
|
+
/**
|
|
314
|
+
* Returns a timestamp of the files last modification
|
|
315
|
+
*
|
|
316
|
+
* @param path Path to the repository
|
|
317
|
+
* @param file File to get timestamp from
|
|
318
|
+
*/
|
|
319
|
+
getFileLastUpdatedTimestamp(path: string, file: string): Promise<number>;
|
|
320
|
+
/**
|
|
321
|
+
* Returns created and updated timestamps from given file
|
|
322
|
+
*
|
|
323
|
+
* @param path Path to the project
|
|
324
|
+
* @param file Path to the file
|
|
325
|
+
*/
|
|
326
|
+
getFileCreatedUpdatedMeta(path: string, file: string): Promise<{
|
|
327
|
+
created: number;
|
|
328
|
+
updated: number;
|
|
329
|
+
}>;
|
|
330
|
+
/**
|
|
331
|
+
* A reference is used in Git to specify branches and tags.
|
|
332
|
+
* This method checks if given name matches the required format
|
|
333
|
+
*
|
|
334
|
+
* @see https://git-scm.com/docs/git-check-ref-format
|
|
335
|
+
*
|
|
336
|
+
* @param path Path to the repository
|
|
337
|
+
* @param name Name to check
|
|
338
|
+
*/
|
|
339
|
+
private checkBranchOrTagName;
|
|
340
|
+
/**
|
|
341
|
+
* Installs LFS support and starts tracking
|
|
342
|
+
* all files inside the lfs folder
|
|
343
|
+
*
|
|
344
|
+
* @param path Path to the repository
|
|
345
|
+
*/
|
|
346
|
+
private installLfs;
|
|
347
|
+
/**
|
|
348
|
+
* Sets the git config of given local repository from ElekIoCoreOptions
|
|
349
|
+
*
|
|
350
|
+
* @param path Path to the repository
|
|
351
|
+
*/
|
|
352
|
+
private setLocalConfig;
|
|
353
|
+
/**
|
|
354
|
+
* Type guard for GitCommit
|
|
355
|
+
*
|
|
356
|
+
* @param obj The object to check
|
|
357
|
+
*/
|
|
358
|
+
private isGitCommit;
|
|
359
|
+
/**
|
|
360
|
+
* Wraps the execution of any git command
|
|
361
|
+
* to use a FIFO queue for sequential processing
|
|
362
|
+
*
|
|
363
|
+
* @param path Path to the repository
|
|
364
|
+
* @param args Arguments to append after the `git` command
|
|
365
|
+
*/
|
|
366
|
+
private git;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Service that manages CRUD functionality for Asset files on disk
|
|
371
|
+
*/
|
|
372
|
+
declare class AssetService extends AbstractCrudService implements ExtendedCrudService<Asset> {
|
|
373
|
+
private readonly jsonFileService;
|
|
374
|
+
private readonly gitService;
|
|
375
|
+
constructor(options: ElekIoCoreOptions, jsonFileService: JsonFileService, gitService: GitService);
|
|
376
|
+
/**
|
|
377
|
+
* Creates a new Asset
|
|
378
|
+
*/
|
|
379
|
+
create(props: CreateAssetProps): Promise<Asset>;
|
|
380
|
+
/**
|
|
381
|
+
* Returns an Asset by ID and language
|
|
382
|
+
*/
|
|
383
|
+
read(props: ReadAssetProps): Promise<Asset>;
|
|
384
|
+
/**
|
|
385
|
+
* Updates given Asset
|
|
386
|
+
*
|
|
387
|
+
* Use the optional "newFilePath" prop to update the Asset itself
|
|
388
|
+
*/
|
|
389
|
+
update(props: UpdateAssetProps): Promise<Asset>;
|
|
390
|
+
/**
|
|
391
|
+
* Deletes given Asset
|
|
392
|
+
*/
|
|
393
|
+
delete(props: DeleteAssetProps): Promise<void>;
|
|
394
|
+
list(props: ListAssetsProps): Promise<PaginatedList<Asset>>;
|
|
395
|
+
count(props: CountAssetsProps): Promise<number>;
|
|
396
|
+
/**
|
|
397
|
+
* Checks if given object is of type Asset
|
|
398
|
+
*/
|
|
399
|
+
isAsset(obj: BaseFile | unknown): obj is Asset;
|
|
400
|
+
/**
|
|
401
|
+
* Returns the size of an Asset in bytes
|
|
402
|
+
*
|
|
403
|
+
* @param path Path of the Asset to get the size from
|
|
404
|
+
*/
|
|
405
|
+
private getAssetSize;
|
|
406
|
+
/**
|
|
407
|
+
* Creates an Asset from given AssetFile
|
|
408
|
+
*
|
|
409
|
+
* @param projectId The project's ID
|
|
410
|
+
* @param assetFile The AssetFile to convert
|
|
411
|
+
*/
|
|
412
|
+
private toAsset;
|
|
413
|
+
/**
|
|
414
|
+
* Returns the found and supported extension as well as mime type,
|
|
415
|
+
* otherwise throws an error
|
|
416
|
+
*
|
|
417
|
+
* @param filePath Path to the file to check
|
|
418
|
+
*/
|
|
419
|
+
private getSupportedFileTypeOrThrow;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Service that manages CRUD functionality for Collection files on disk
|
|
424
|
+
*/
|
|
425
|
+
declare class CollectionService extends AbstractCrudService implements ExtendedCrudService<Collection> {
|
|
426
|
+
private jsonFileService;
|
|
427
|
+
private gitService;
|
|
428
|
+
constructor(options: ElekIoCoreOptions, jsonFileService: JsonFileService, gitService: GitService);
|
|
429
|
+
/**
|
|
430
|
+
* Creates a new Collection
|
|
431
|
+
*/
|
|
432
|
+
create(props: CreateCollectionProps): Promise<Collection>;
|
|
433
|
+
/**
|
|
434
|
+
* Returns a Collection by ID
|
|
435
|
+
*/
|
|
436
|
+
read(props: ReadCollectionProps): Promise<Collection>;
|
|
437
|
+
/**
|
|
438
|
+
* Updates given Collection
|
|
439
|
+
*
|
|
440
|
+
* @todo finish implementing checks for FieldDefinitions and extract methods
|
|
441
|
+
*
|
|
442
|
+
* @param projectId Project ID of the collection to update
|
|
443
|
+
* @param collection Collection to write to disk
|
|
444
|
+
* @returns An object containing information about the actions needed to be taken,
|
|
445
|
+
* before given update can be executed or void if the update was executed successfully
|
|
446
|
+
*/
|
|
447
|
+
update(props: UpdateCollectionProps): Promise<Collection>;
|
|
448
|
+
/**
|
|
449
|
+
* Deletes given Collection (folder), including it's items
|
|
450
|
+
*
|
|
451
|
+
* The Fields that Collection used are not deleted.
|
|
452
|
+
*/
|
|
453
|
+
delete(props: DeleteCollectionProps): Promise<void>;
|
|
454
|
+
list(props: ListCollectionsProps): Promise<PaginatedList<Collection>>;
|
|
455
|
+
count(props: CountCollectionsProps): Promise<number>;
|
|
456
|
+
/**
|
|
457
|
+
* Checks if given object is of type Collection
|
|
458
|
+
*/
|
|
459
|
+
isCollection(obj: BaseFile | unknown): obj is Collection;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Service that manages CRUD functionality for Value files on disk
|
|
464
|
+
*/
|
|
465
|
+
declare class ValueService extends AbstractCrudService implements ExtendedCrudService<Value> {
|
|
466
|
+
private jsonFileService;
|
|
467
|
+
private gitService;
|
|
468
|
+
constructor(options: ElekIoCoreOptions, jsonFileService: JsonFileService, gitService: GitService, assetService: AssetService);
|
|
469
|
+
/**
|
|
470
|
+
* Creates a new Value
|
|
471
|
+
*/
|
|
472
|
+
create(props: CreateValueProps): Promise<Value>;
|
|
473
|
+
/**
|
|
474
|
+
* Returns a Value by ID and language
|
|
475
|
+
*/
|
|
476
|
+
read(props: ReadValueProps): Promise<Value>;
|
|
477
|
+
/**
|
|
478
|
+
* Updates given Value
|
|
479
|
+
*/
|
|
480
|
+
update(props: UpdateValueProps): Promise<Value>;
|
|
481
|
+
/**
|
|
482
|
+
* Deletes given Value
|
|
483
|
+
*/
|
|
484
|
+
delete(props: DeleteValueProps): Promise<void>;
|
|
485
|
+
list(props: ListValuesProps): Promise<PaginatedList<Value>>;
|
|
486
|
+
count(props: CountValuesProps): Promise<number>;
|
|
487
|
+
/**
|
|
488
|
+
* Checks if given object is of type Value
|
|
489
|
+
*/
|
|
490
|
+
isValue(obj: BaseFile | unknown): obj is Value;
|
|
491
|
+
/**
|
|
492
|
+
* Reads the given Value from disk and validates it against the ValueDefinition
|
|
493
|
+
*/
|
|
494
|
+
validate(props: ValidateValueProps): Promise<_elek_io_shared.SafeParseSuccess<string | undefined> | _elek_io_shared.SafeParseSuccess<number | undefined> | _elek_io_shared.SafeParseError<boolean> | _elek_io_shared.SafeParseSuccess<boolean | undefined>>;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* Service that manages CRUD functionality for Entry files on disk
|
|
499
|
+
*/
|
|
500
|
+
declare class EntryService extends AbstractCrudService implements ExtendedCrudService<Entry> {
|
|
501
|
+
private jsonFileService;
|
|
502
|
+
private gitService;
|
|
503
|
+
private collectionService;
|
|
504
|
+
private valueService;
|
|
505
|
+
constructor(options: ElekIoCoreOptions, jsonFileService: JsonFileService, gitService: GitService, collectionService: CollectionService, valueService: ValueService);
|
|
506
|
+
/**
|
|
507
|
+
* Creates a new Entry
|
|
508
|
+
*/
|
|
509
|
+
create(props: CreateEntryProps): Promise<Entry>;
|
|
510
|
+
/**
|
|
511
|
+
* Returns an Entry by ID and language
|
|
512
|
+
*/
|
|
513
|
+
read(props: ReadEntryProps): Promise<Entry>;
|
|
514
|
+
/**
|
|
515
|
+
* Updates Entry with given ValueReferences
|
|
516
|
+
*/
|
|
517
|
+
update(props: UpdateEntryProps): Promise<Entry>;
|
|
518
|
+
/**
|
|
519
|
+
* Deletes given Entry
|
|
520
|
+
*/
|
|
521
|
+
delete(props: DeleteEntryProps): Promise<void>;
|
|
522
|
+
list(props: ListEntriesProps): Promise<_elek_io_shared.PaginatedList<{
|
|
523
|
+
id: string;
|
|
524
|
+
fileType: "entry";
|
|
525
|
+
created: number;
|
|
526
|
+
language: "bg" | "cs" | "da" | "de" | "el" | "en" | "es" | "et" | "fi" | "fr" | "hu" | "it" | "ja" | "lt" | "lv" | "nl" | "pl" | "pt" | "ro" | "ru" | "sk" | "sl" | "sv" | "zh";
|
|
527
|
+
valueReferences: {
|
|
528
|
+
definitionId: string;
|
|
529
|
+
references: {
|
|
530
|
+
id: string;
|
|
531
|
+
language: "bg" | "cs" | "da" | "de" | "el" | "en" | "es" | "et" | "fi" | "fr" | "hu" | "it" | "ja" | "lt" | "lv" | "nl" | "pl" | "pt" | "ro" | "ru" | "sk" | "sl" | "sv" | "zh";
|
|
532
|
+
};
|
|
533
|
+
}[];
|
|
534
|
+
updated?: number | undefined;
|
|
535
|
+
}>>;
|
|
536
|
+
count(props: CountEntriesProps): Promise<number>;
|
|
537
|
+
/**
|
|
538
|
+
* Checks if given object of Collection, CollectionItem,
|
|
539
|
+
* Field, Project or Asset is of type CollectionItem
|
|
540
|
+
*/
|
|
541
|
+
isEntry(obj: BaseFile | unknown): obj is Entry;
|
|
542
|
+
/**
|
|
543
|
+
* Validates referenced Values against the Collections definition
|
|
544
|
+
*
|
|
545
|
+
* @todo should probably return all errors occurring during parsing instead of throwing
|
|
546
|
+
*/
|
|
547
|
+
private validateValueReferences;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* Service that queries other services for data to search
|
|
552
|
+
*
|
|
553
|
+
* @todo refactor for the new Services
|
|
554
|
+
*/
|
|
555
|
+
declare class SearchService extends AbstractCrudService {
|
|
556
|
+
private assetService;
|
|
557
|
+
private collectionService;
|
|
558
|
+
constructor(options: ElekIoCoreOptions, assetService: AssetService, collectionService: CollectionService);
|
|
559
|
+
/**
|
|
560
|
+
* Search all models inside the project for given query
|
|
561
|
+
*
|
|
562
|
+
* @todo Implement SearchOptions parameter
|
|
563
|
+
*
|
|
564
|
+
* @param project Project to search in
|
|
565
|
+
* @param query Query to search for
|
|
566
|
+
*/
|
|
567
|
+
search(projectId: string, query: string, fileType?: FileType): Promise<{
|
|
568
|
+
type: "value" | "project" | "asset" | "collection" | "entry";
|
|
569
|
+
id: string;
|
|
570
|
+
name: string;
|
|
571
|
+
matches: {
|
|
572
|
+
key: string;
|
|
573
|
+
prefix: string;
|
|
574
|
+
match: string;
|
|
575
|
+
suffix: string;
|
|
576
|
+
}[];
|
|
577
|
+
language?: "bg" | "cs" | "da" | "de" | "el" | "en" | "es" | "et" | "fi" | "fr" | "hu" | "it" | "ja" | "lt" | "lv" | "nl" | "pl" | "pt" | "ro" | "ru" | "sk" | "sl" | "sv" | "zh" | undefined;
|
|
578
|
+
}[]>;
|
|
579
|
+
private truncate;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Service that manages CRUD functionality for Project files on disk
|
|
584
|
+
*/
|
|
585
|
+
declare class ProjectService extends AbstractCrudService implements ExtendedCrudService<Project> {
|
|
586
|
+
private jsonFileService;
|
|
587
|
+
private userService;
|
|
588
|
+
private gitService;
|
|
589
|
+
private searchService;
|
|
590
|
+
private assetService;
|
|
591
|
+
private collectionService;
|
|
592
|
+
private entryService;
|
|
593
|
+
private valueService;
|
|
594
|
+
constructor(options: ElekIoCoreOptions, jsonFileService: JsonFileService, userService: UserService, gitService: GitService, searchService: SearchService, assetService: AssetService, collectionService: CollectionService, entryService: EntryService, valueService: ValueService);
|
|
595
|
+
/**
|
|
596
|
+
* Creates a new Project
|
|
597
|
+
*/
|
|
598
|
+
create(props: CreateProjectProps): Promise<Project>;
|
|
599
|
+
/**
|
|
600
|
+
* Returns a Project by ID
|
|
601
|
+
*/
|
|
602
|
+
read(props: ReadProjectProps): Promise<Project>;
|
|
603
|
+
/**
|
|
604
|
+
* Updates given Project
|
|
605
|
+
*/
|
|
606
|
+
update(props: UpdateProjectProps): Promise<Project>;
|
|
607
|
+
/**
|
|
608
|
+
* Upgrades given Project to the latest version of this client
|
|
609
|
+
*
|
|
610
|
+
* Needed when a new core version is requiring changes to existing files or structure.
|
|
611
|
+
*
|
|
612
|
+
* @todo Find out why using this.snapshotService is throwing isObjWithKeyAndValueOfString of undefined error in gitService (maybe binding issue)
|
|
613
|
+
*/
|
|
614
|
+
upgrade(props: UpgradeProjectProps): Promise<void>;
|
|
615
|
+
/**
|
|
616
|
+
* Deletes given Project
|
|
617
|
+
*
|
|
618
|
+
* Deletes the whole Project folder including the history, not only the config file.
|
|
619
|
+
* Use with caution, since a Project that is only available locally could be lost forever.
|
|
620
|
+
* Or changes that are not pushed to a remote yet, will be lost too.
|
|
621
|
+
*/
|
|
622
|
+
delete(props: DeleteProjectProps): Promise<void>;
|
|
623
|
+
list(props?: ListProjectsProps): Promise<PaginatedList<Project>>;
|
|
624
|
+
count(): Promise<number>;
|
|
625
|
+
/**
|
|
626
|
+
* Search all models inside the project for given query
|
|
627
|
+
*
|
|
628
|
+
* @param projectId Project ID to search in
|
|
629
|
+
* @param query Query to search for
|
|
630
|
+
* @param type (Optional) specify the type to search for
|
|
631
|
+
*/
|
|
632
|
+
search(projectId: string, query: string, type?: FileType): Promise<{
|
|
633
|
+
type: "value" | "project" | "asset" | "collection" | "entry";
|
|
634
|
+
id: string;
|
|
635
|
+
name: string;
|
|
636
|
+
matches: {
|
|
637
|
+
key: string;
|
|
638
|
+
prefix: string;
|
|
639
|
+
match: string;
|
|
640
|
+
suffix: string;
|
|
641
|
+
}[];
|
|
642
|
+
language?: "bg" | "cs" | "da" | "de" | "el" | "en" | "es" | "et" | "fi" | "fr" | "hu" | "it" | "ja" | "lt" | "lv" | "nl" | "pl" | "pt" | "ro" | "ru" | "sk" | "sl" | "sv" | "zh" | undefined;
|
|
643
|
+
}[]>;
|
|
644
|
+
/**
|
|
645
|
+
* Checks if given object is of type Project
|
|
646
|
+
*/
|
|
647
|
+
isProject(obj: BaseFile | unknown): obj is Project;
|
|
648
|
+
/**
|
|
649
|
+
* Exports given Project to JSON
|
|
650
|
+
*
|
|
651
|
+
* @todo performance tests
|
|
652
|
+
* @todo add progress callback
|
|
653
|
+
*/
|
|
654
|
+
exportToJson(projectId: string): Promise<ProjectExport>;
|
|
655
|
+
/**
|
|
656
|
+
* Creates the projects folder structure and makes sure to
|
|
657
|
+
* write empty .gitkeep files inside them to ensure they are
|
|
658
|
+
* committed
|
|
659
|
+
*/
|
|
660
|
+
private createFolderStructure;
|
|
661
|
+
/**
|
|
662
|
+
* Writes the Projects main .gitignore file to disk
|
|
663
|
+
*
|
|
664
|
+
* @todo Add general things to ignore
|
|
665
|
+
* @see https://github.com/github/gitignore/tree/master/Global
|
|
666
|
+
*/
|
|
667
|
+
private createGitignore;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* The directory in which everything is stored and will be worked in
|
|
672
|
+
*
|
|
673
|
+
* @todo make the workingDirectory an elek option to be set via app.getPath('home') (electron instead of node)?
|
|
674
|
+
*/
|
|
675
|
+
declare const workingDirectory: string;
|
|
676
|
+
/**
|
|
677
|
+
* A collection of often used paths
|
|
678
|
+
*/
|
|
679
|
+
declare const pathTo: {
|
|
680
|
+
tmp: string;
|
|
681
|
+
userFile: string;
|
|
682
|
+
projects: string;
|
|
683
|
+
project: (projectId: string) => string;
|
|
684
|
+
projectFile: (projectId: string) => string;
|
|
685
|
+
lfs: (projectId: string) => string;
|
|
686
|
+
collections: (projectId: string) => string;
|
|
687
|
+
collection: (projectId: string, id: string) => string;
|
|
688
|
+
collectionFile: (projectId: string, id: string) => string;
|
|
689
|
+
entries: (projectId: string, collectionId: string) => string;
|
|
690
|
+
entryFile: (projectId: string, collectionId: string, id: string, language: string) => string;
|
|
691
|
+
values: (projectId: string) => string;
|
|
692
|
+
valueFile: (projectId: string, id: string, language: string) => string;
|
|
693
|
+
assets: (projectId: string) => string;
|
|
694
|
+
assetFile: (projectId: string, id: string, language: string) => string;
|
|
695
|
+
asset: (projectId: string, id: string, language: string, extension: string) => string;
|
|
696
|
+
};
|
|
697
|
+
/**
|
|
698
|
+
* Searches for a potential project ID in given path string and returns it
|
|
699
|
+
*
|
|
700
|
+
* Mainly used for logging inside the GitService, where we don't have a project ID,
|
|
701
|
+
* but always have a path which could contain one. The ID is then used,
|
|
702
|
+
* to log to the current project log, instead of logging to the main log file.
|
|
703
|
+
*
|
|
704
|
+
* @todo I really dont like this and I do not know how much performance we loose here
|
|
705
|
+
*/
|
|
706
|
+
declare const fromPath: {
|
|
707
|
+
projectId: (path: string) => string | undefined;
|
|
708
|
+
};
|
|
709
|
+
/**
|
|
710
|
+
* Returns a complete default type, hydrated with the partials of value
|
|
711
|
+
*/
|
|
712
|
+
declare function assignDefaultIfMissing<T extends {}>(value: Partial<T> | undefined | null, defaultsTo: T): T;
|
|
713
|
+
/**
|
|
714
|
+
* Used as parameter for filter() methods to assure,
|
|
715
|
+
* only values not null, undefined or empty strings are returned
|
|
716
|
+
*
|
|
717
|
+
* @param value Value to check
|
|
718
|
+
*/
|
|
719
|
+
declare function notEmpty<T>(value: T | null | undefined): value is T;
|
|
720
|
+
declare function isNoError<T>(item: T | Error): item is T;
|
|
721
|
+
/**
|
|
722
|
+
* Basically a Promise.all() without rejecting if one promise fails to resolve
|
|
723
|
+
*/
|
|
724
|
+
declare function returnResolved<T>(promises: Promise<T>[]): Promise<Awaited<T>[]>;
|
|
725
|
+
/**
|
|
726
|
+
* Custom async typescript ready implementation of Node.js child_process
|
|
727
|
+
*
|
|
728
|
+
* @see https://nodejs.org/api/child_process.html
|
|
729
|
+
* @see https://github.com/ralphtheninja/await-spawn
|
|
730
|
+
*/
|
|
731
|
+
declare function spawnChildProcess(command: string, args: ReadonlyArray<string>, options?: SpawnOptionsWithoutStdio): Promise<string>;
|
|
732
|
+
/**
|
|
733
|
+
* Returns all folders of given path
|
|
734
|
+
*/
|
|
735
|
+
declare function folders(path: string): Promise<Fs.Dirent[]>;
|
|
736
|
+
/**
|
|
737
|
+
* Returns all files of given path which can be filtered by extension
|
|
738
|
+
*/
|
|
739
|
+
declare function files(path: string, extension?: string): Promise<Fs.Dirent[]>;
|
|
740
|
+
/**
|
|
741
|
+
* Returns the relative path for given path
|
|
742
|
+
* by stripping out everything up to the working directory
|
|
743
|
+
*/
|
|
744
|
+
declare function getRelativePath(path: string): string;
|
|
745
|
+
/**
|
|
746
|
+
* Searches given array of objects for duplicates of given key and returns them
|
|
747
|
+
*
|
|
748
|
+
* @param arr Array with possible duplicate values
|
|
749
|
+
* @param key Key of object T to get duplicates of
|
|
750
|
+
*/
|
|
751
|
+
declare function getDuplicates<T>(arr: T[], key: keyof T): T[];
|
|
752
|
+
|
|
753
|
+
declare const CoreUtil_assignDefaultIfMissing: typeof assignDefaultIfMissing;
|
|
754
|
+
declare const CoreUtil_files: typeof files;
|
|
755
|
+
declare const CoreUtil_folders: typeof folders;
|
|
756
|
+
declare const CoreUtil_fromPath: typeof fromPath;
|
|
757
|
+
declare const CoreUtil_getDuplicates: typeof getDuplicates;
|
|
758
|
+
declare const CoreUtil_getRelativePath: typeof getRelativePath;
|
|
759
|
+
declare const CoreUtil_isNoError: typeof isNoError;
|
|
760
|
+
declare const CoreUtil_notEmpty: typeof notEmpty;
|
|
761
|
+
declare const CoreUtil_pathTo: typeof pathTo;
|
|
762
|
+
declare const CoreUtil_returnResolved: typeof returnResolved;
|
|
763
|
+
declare const CoreUtil_spawnChildProcess: typeof spawnChildProcess;
|
|
764
|
+
declare const CoreUtil_workingDirectory: typeof workingDirectory;
|
|
765
|
+
declare namespace CoreUtil {
|
|
766
|
+
export { CoreUtil_assignDefaultIfMissing as assignDefaultIfMissing, CoreUtil_files as files, CoreUtil_folders as folders, CoreUtil_fromPath as fromPath, CoreUtil_getDuplicates as getDuplicates, CoreUtil_getRelativePath as getRelativePath, CoreUtil_isNoError as isNoError, CoreUtil_notEmpty as notEmpty, CoreUtil_pathTo as pathTo, CoreUtil_returnResolved as returnResolved, CoreUtil_spawnChildProcess as spawnChildProcess, CoreUtil_workingDirectory as workingDirectory };
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
/**
|
|
770
|
+
* elek.io Core
|
|
771
|
+
*
|
|
772
|
+
* Provides access to all services Core is offering
|
|
773
|
+
*/
|
|
774
|
+
declare class ElekIoCore {
|
|
775
|
+
private readonly options;
|
|
776
|
+
private readonly userService;
|
|
777
|
+
private readonly gitService;
|
|
778
|
+
private readonly jsonFileService;
|
|
779
|
+
private readonly assetService;
|
|
780
|
+
private readonly searchService;
|
|
781
|
+
private readonly projectService;
|
|
782
|
+
private readonly collectionService;
|
|
783
|
+
private readonly entryService;
|
|
784
|
+
private readonly valueService;
|
|
785
|
+
constructor(props?: ConstructorElekIoCoreProps);
|
|
786
|
+
/**
|
|
787
|
+
* Utility / helper functions
|
|
788
|
+
*/
|
|
789
|
+
get util(): typeof CoreUtil;
|
|
790
|
+
/**
|
|
791
|
+
*
|
|
792
|
+
*/
|
|
793
|
+
get user(): UserService;
|
|
794
|
+
/**
|
|
795
|
+
* CRUD methods to work with Projects
|
|
796
|
+
*/
|
|
797
|
+
get projects(): ProjectService;
|
|
798
|
+
/**
|
|
799
|
+
* CRUD methods to work with Assets
|
|
800
|
+
*/
|
|
801
|
+
get assets(): AssetService;
|
|
802
|
+
/**
|
|
803
|
+
* CRUD methods to work with Collections
|
|
804
|
+
*/
|
|
805
|
+
get collections(): CollectionService;
|
|
806
|
+
/**
|
|
807
|
+
* CRUD methods to work with Entries
|
|
808
|
+
*/
|
|
809
|
+
get entries(): EntryService;
|
|
810
|
+
/**
|
|
811
|
+
* CRUD methods to work with Values
|
|
812
|
+
*/
|
|
813
|
+
get values(): ValueService;
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
export { ElekIoCore as default };
|