verteilen-core 1.3.6 → 1.3.8

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.
@@ -1,4 +1,4 @@
1
- import { Project, Task } from "../../interface";
1
+ import { Job, Project, Task } from "../../interface";
2
2
  import { MemoryData, RecordLoader } from "../io";
3
3
  import { Server } from "../server";
4
4
  export declare class Project_Module {
@@ -9,6 +9,11 @@ export declare class Project_Module {
9
9
  ProjectJobCount(uuid: string): number;
10
10
  PopulateProject(uuid: string): Project | undefined;
11
11
  PopulateTask(uuid: string): Task | undefined;
12
+ GetProjectRelatedTask(uuid: string): Array<Task>;
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>>;
12
17
  CascadeDeleteProject(uuid: string, bind: boolean): void;
13
18
  CascadeDeleteTask(uuid: string): void;
14
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) {
@@ -42,6 +43,61 @@ class Project_Module {
42
43
  }
43
44
  return buffer;
44
45
  }
46
+ GetProjectRelatedTask(uuid) {
47
+ const p = this.memory.projects.find(x => x.uuid == uuid);
48
+ if (!p)
49
+ return [];
50
+ const r = p.tasks_uuid.map(x => {
51
+ return this.memory.tasks.find(y => y.uuid == x);
52
+ }).filter(x => x != undefined);
53
+ return r;
54
+ }
55
+ GetTaskRelatedJob(uuid) {
56
+ const p = this.memory.tasks.find(x => x.uuid == uuid);
57
+ if (!p)
58
+ return [];
59
+ const r = p.jobs_uuid.map(x => {
60
+ return this.memory.jobs.find(y => y.uuid == x);
61
+ }).filter(x => x != undefined);
62
+ return r;
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
+ }
45
101
  CascadeDeleteProject(uuid, bind) {
46
102
  const p = this.memory.projects.find(p => p.uuid == uuid);
47
103
  if (!p)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "verteilen-core",
3
- "version": "1.3.6",
3
+ "version": "1.3.8",
4
4
  "license": "MIT",
5
5
  "homepage": "https://verteilen.github.io/wiki/",
6
6
  "author": "Elly",
@@ -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
@@ -55,6 +56,84 @@ export class Project_Module {
55
56
  }
56
57
  return buffer
57
58
  }
59
+ /**
60
+ * Get tasks from project related
61
+ * @param uuid Project UUID
62
+ * @returns Related Tasks
63
+ */
64
+ GetProjectRelatedTask(uuid:string):Array<Task> {
65
+ const p = this.memory.projects.find(x => x.uuid == uuid)
66
+ if(!p) return []
67
+ const r = p.tasks_uuid.map(x => {
68
+ return this.memory.tasks.find(y => y.uuid == x)
69
+ }).filter(x => x != undefined)
70
+ return r
71
+ }
72
+ /**
73
+ * Get jobs from task related
74
+ * @param uuid Task UUID
75
+ * @returns Related Jobs
76
+ */
77
+ GetTaskRelatedJob(uuid:string):Array<Job> {
78
+ const p = this.memory.tasks.find(x => x.uuid == uuid)
79
+ if(!p) return []
80
+ const r = p.jobs_uuid.map(x => {
81
+ return this.memory.jobs.find(y => y.uuid == x)
82
+ }).filter(x => x != undefined)
83
+ return r
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
+ }
58
137
  /**
59
138
  * Delete project related data and project itself
60
139
  * @param uuid Project UUID