verteilen-core 1.3.7 → 1.3.9

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.
@@ -85,3 +85,6 @@ export interface Node extends DataHeader {
85
85
  permission?: LocalPermission;
86
86
  acl?: ACLType;
87
87
  }
88
+ export declare const CreateDefaultProject: () => Project;
89
+ export declare const CreateDefaultTask: () => Task;
90
+ export declare const CreateDefaultJob: () => Job;
@@ -1,2 +1,45 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CreateDefaultJob = exports.CreateDefaultTask = exports.CreateDefaultProject = void 0;
4
+ const enum_1 = require("./enum");
5
+ const uuid_1 = require("uuid");
6
+ const CreateDefaultProject = () => {
7
+ return {
8
+ uuid: (0, uuid_1.v6)(),
9
+ title: "",
10
+ description: "",
11
+ tasks: [],
12
+ tasks_uuid: [],
13
+ database_uuid: ""
14
+ };
15
+ };
16
+ exports.CreateDefaultProject = CreateDefaultProject;
17
+ const CreateDefaultTask = () => {
18
+ return {
19
+ uuid: (0, uuid_1.v6)(),
20
+ title: "Default",
21
+ description: "",
22
+ setupjob: false,
23
+ cronjob: false,
24
+ cronjobKey: "",
25
+ multi: false,
26
+ multiKey: "",
27
+ properties: [],
28
+ jobs: [],
29
+ jobs_uuid: [],
30
+ };
31
+ };
32
+ exports.CreateDefaultTask = CreateDefaultTask;
33
+ const CreateDefaultJob = () => {
34
+ return {
35
+ uuid: (0, uuid_1.v6)(),
36
+ category: enum_1.JobCategory.Execution,
37
+ type: enum_1.JobType.JAVASCRIPT,
38
+ script: "",
39
+ string_args: [],
40
+ number_args: [],
41
+ boolean_args: [],
42
+ id_args: [],
43
+ };
44
+ };
45
+ exports.CreateDefaultJob = CreateDefaultJob;
@@ -11,6 +11,9 @@ export declare class Project_Module {
11
11
  PopulateTask(uuid: string): Task | undefined;
12
12
  GetProjectRelatedTask(uuid: string): Array<Task>;
13
13
  GetTaskRelatedJob(uuid: string): Array<Job>;
14
+ CloneProjects(uuids: Array<string>): Promise<Array<string>>;
15
+ CloneTasks(uuids: Array<string>): Promise<Array<string>>;
16
+ CloneJobs(uuids: Array<string>): Promise<Array<string>>;
14
17
  CascadeDeleteProject(uuid: string, bind: boolean): void;
15
18
  CascadeDeleteTask(uuid: string): void;
16
19
  Delete_Database_Idle(uuid: string): Promise<void>;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Project_Module = void 0;
4
+ const uuid_1 = require("uuid");
4
5
  class Project_Module {
5
6
  server;
6
7
  constructor(memory) {
@@ -60,6 +61,43 @@ class Project_Module {
60
61
  }).filter(x => x != undefined);
61
62
  return r;
62
63
  }
64
+ async CloneProjects(uuids) {
65
+ const p = uuids.map(x => this.loader.project.load(x, true));
66
+ const ps = await Promise.all(p);
67
+ const projects = ps.map(x => JSON.parse(x));
68
+ projects.forEach(x => x.uuid = (0, uuid_1.v6)());
69
+ const jus = projects.map(x => this.CloneTasks(x.tasks_uuid));
70
+ const ju = await Promise.all(jus);
71
+ projects.forEach((t, index) => {
72
+ t.tasks_uuid = ju[index];
73
+ });
74
+ const js = projects.map(x => this.loader.project.save(x.uuid, JSON.stringify(x)));
75
+ await Promise.all(js);
76
+ return projects.map(x => x.uuid);
77
+ }
78
+ async CloneTasks(uuids) {
79
+ const p = uuids.map(x => this.loader.task.load(x, true));
80
+ const ps = await Promise.all(p);
81
+ const tasks = ps.map(x => JSON.parse(x));
82
+ tasks.forEach(x => x.uuid = (0, uuid_1.v6)());
83
+ const jus = tasks.map(x => this.CloneJobs(x.jobs_uuid));
84
+ const ju = await Promise.all(jus);
85
+ tasks.forEach((t, index) => {
86
+ t.jobs_uuid = ju[index];
87
+ });
88
+ const js = tasks.map(x => this.loader.task.save(x.uuid, JSON.stringify(x)));
89
+ await Promise.all(js);
90
+ return tasks.map(x => x.uuid);
91
+ }
92
+ async CloneJobs(uuids) {
93
+ const p = uuids.map(x => this.loader.job.load(x, true));
94
+ const ps = await Promise.all(p);
95
+ const jobs = ps.map(x => JSON.parse(x));
96
+ jobs.forEach(x => x.uuid = (0, uuid_1.v6)());
97
+ const js = jobs.map(x => this.loader.job.save(x.uuid, JSON.stringify(x)));
98
+ await Promise.all(js);
99
+ return jobs.map(x => x.uuid);
100
+ }
63
101
  CascadeDeleteProject(uuid, bind) {
64
102
  const p = this.memory.projects.find(p => p.uuid == uuid);
65
103
  if (!p)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "verteilen-core",
3
- "version": "1.3.7",
3
+ "version": "1.3.9",
4
4
  "license": "MIT",
5
5
  "homepage": "https://verteilen.github.io/wiki/",
6
6
  "author": "Elly",
@@ -6,9 +6,10 @@
6
6
  /**
7
7
  * Defined the basic compute use data structure
8
8
  */
9
- import { DataType, DataTypeBase, JobType, JobType2, ServiceMode } from "./enum"
9
+ import { DataType, DataTypeBase, JobCategory, JobType, JobType2, ServiceMode } from "./enum"
10
10
  import { ACLType, LocalPermission as LocalPermission } from "./server"
11
11
  import { TaskLogic } from "./struct"
12
+ import { v6 as uuidv6 } from 'uuid'
12
13
 
13
14
  export interface DatabaseConfigTrigger {
14
15
  types: Array<DataTypeBase>
@@ -389,4 +390,45 @@ export interface Node extends DataHeader {
389
390
  * Could be public, protected, private
390
391
  */
391
392
  acl?: ACLType
393
+ }
394
+
395
+
396
+ export const CreateDefaultProject = () : Project => {
397
+ return {
398
+ uuid: uuidv6(),
399
+ title: "",
400
+ description: "",
401
+ tasks: [],
402
+ tasks_uuid: [],
403
+ database_uuid: ""
404
+ }
405
+ }
406
+
407
+ export const CreateDefaultTask = () : Task => {
408
+ return {
409
+ uuid: uuidv6(),
410
+ title: "Default",
411
+ description: "",
412
+ setupjob: false,
413
+ cronjob: false,
414
+ cronjobKey: "",
415
+ multi: false,
416
+ multiKey: "",
417
+ properties: [],
418
+ jobs: [],
419
+ jobs_uuid: [],
420
+ }
421
+ }
422
+
423
+ export const CreateDefaultJob = () : Job => {
424
+ return {
425
+ uuid: uuidv6(),
426
+ category: JobCategory.Execution,
427
+ type: JobType.JAVASCRIPT,
428
+ script: "",
429
+ string_args: [],
430
+ number_args: [],
431
+ boolean_args: [],
432
+ id_args: [],
433
+ }
392
434
  }
@@ -6,6 +6,7 @@
6
6
  import { Job, Project, Task } from "../../interface"
7
7
  import { MemoryData, RecordLoader } from "../io"
8
8
  import { Server } from "../server"
9
+ import { v6 as uuidv6 } from 'uuid'
9
10
 
10
11
  export class Project_Module {
11
12
  server:Server
@@ -81,6 +82,58 @@ export class Project_Module {
81
82
  }).filter(x => x != undefined)
82
83
  return r
83
84
  }
85
+ /**
86
+ * Clone Project Container
87
+ * @param uuids project uuids
88
+ * @returns The new uuids list
89
+ */
90
+ async CloneProjects(uuids:Array<string>):Promise<Array<string>>{
91
+ const p = uuids.map(x => this.loader.project.load(x, true))
92
+ const ps = await Promise.all(p)
93
+ const projects:Array<Project> = ps.map(x => JSON.parse(x))
94
+ projects.forEach(x => x.uuid = uuidv6())
95
+ const jus = projects.map(x => this.CloneTasks(x.tasks_uuid))
96
+ const ju = await Promise.all(jus)
97
+ projects.forEach((t, index) => {
98
+ t.tasks_uuid = ju[index]
99
+ })
100
+ const js = projects.map(x => this.loader.project.save(x.uuid, JSON.stringify(x)))
101
+ await Promise.all(js)
102
+ return projects.map(x => x.uuid)
103
+ }
104
+ /**
105
+ * Clone Task Container
106
+ * @param uuids task uuids
107
+ * @returns The new uuids list
108
+ */
109
+ async CloneTasks(uuids:Array<string>):Promise<Array<string>>{
110
+ const p = uuids.map(x => this.loader.task.load(x, true))
111
+ const ps = await Promise.all(p)
112
+ const tasks:Array<Task> = ps.map(x => JSON.parse(x))
113
+ tasks.forEach(x => x.uuid = uuidv6())
114
+ const jus = tasks.map(x => this.CloneJobs(x.jobs_uuid))
115
+ const ju = await Promise.all(jus)
116
+ tasks.forEach((t, index) => {
117
+ t.jobs_uuid = ju[index]
118
+ })
119
+ const js = tasks.map(x => this.loader.task.save(x.uuid, JSON.stringify(x)))
120
+ await Promise.all(js)
121
+ return tasks.map(x => x.uuid)
122
+ }
123
+ /**
124
+ * Clone Job Container
125
+ * @param uuids job uuids
126
+ * @returns The new uuids list
127
+ */
128
+ async CloneJobs(uuids:Array<string>):Promise<Array<string>>{
129
+ const p = uuids.map(x => this.loader.job.load(x, true))
130
+ const ps = await Promise.all(p)
131
+ const jobs:Array<Job> = ps.map(x => JSON.parse(x))
132
+ jobs.forEach(x => x.uuid = uuidv6())
133
+ const js = jobs.map(x => this.loader.job.save(x.uuid, JSON.stringify(x)))
134
+ await Promise.all(js)
135
+ return jobs.map(x => x.uuid)
136
+ }
84
137
  /**
85
138
  * Delete project related data and project itself
86
139
  * @param uuid Project UUID