verteilen-core 1.3.14 → 1.3.16

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/server/io.js CHANGED
@@ -105,9 +105,9 @@ const _CreateRecordIOLoader = (loader, memory, type, folder, ext = ".json") => {
105
105
  const arr = get_array(type);
106
106
  const b = arr.findIndex(x => x.uuid == uuid);
107
107
  if (b != -1)
108
- arr.push(JSON.parse(data));
109
- else
110
108
  arr[b] = JSON.parse(data);
109
+ else
110
+ arr.push(JSON.parse(data));
111
111
  },
112
112
  load: async (uuid, cache) => {
113
113
  const arr = get_array(type);
@@ -120,6 +120,12 @@ const _CreateRecordIOLoader = (loader, memory, type, folder, ext = ".json") => {
120
120
  if (!loader.exists(root))
121
121
  await loader.mkdir(root);
122
122
  const file = loader.join(root, uuid + ext);
123
+ if (!loader.exists(file)) {
124
+ const b = arr.findIndex(x => x.uuid == uuid);
125
+ if (b != -1)
126
+ arr.splice(b, 1);
127
+ return "";
128
+ }
123
129
  const a = await loader.read_string(file);
124
130
  if (cache)
125
131
  arr.push(JSON.parse(a));
@@ -143,7 +149,9 @@ const _CreateRecordIOLoader = (loader, memory, type, folder, ext = ".json") => {
143
149
  if (!loader.exists(root))
144
150
  await loader.mkdir(root);
145
151
  const file = loader.join(root, uuid + ext);
146
- await loader.rm(file);
152
+ if (loader.exists(file)) {
153
+ await loader.rm(file);
154
+ }
147
155
  const arr = get_array(type);
148
156
  const b = arr.findIndex(x => x.uuid == uuid);
149
157
  if (b != -1)
@@ -16,5 +16,6 @@ export declare class Project_Module {
16
16
  CloneJobs(uuids: Array<string>): Promise<Array<string>>;
17
17
  CascadeDeleteProject(uuid: string, bind: boolean): Promise<void>;
18
18
  CascadeDeleteTask(uuid: string): Promise<void>;
19
+ CascadeDeleteJob(uuid: string): Promise<void>;
19
20
  Delete_Database_Idle(uuid: string): Promise<void>;
20
21
  }
@@ -124,6 +124,21 @@ class Project_Module {
124
124
  const ps = p.jobs_uuid.map(j_uuid => this.loader.job.delete(j_uuid));
125
125
  await Promise.all(ps);
126
126
  await this.loader.task.delete(uuid);
127
+ const ps2 = this.memory.projects.filter(x => x.tasks_uuid.includes(uuid)).map(x => x.uuid);
128
+ for (let u of ps2) {
129
+ const index = this.memory.projects.findIndex(x => x.uuid == u);
130
+ if (index != -1)
131
+ this.memory.projects.splice(index, 1);
132
+ }
133
+ }
134
+ async CascadeDeleteJob(uuid) {
135
+ await this.loader.job.delete(uuid);
136
+ const ps2 = this.memory.tasks.filter(x => x.jobs_uuid.includes(uuid)).map(x => x.uuid);
137
+ for (let u of ps2) {
138
+ const index = this.memory.tasks.findIndex(x => x.uuid == u);
139
+ if (index != -1)
140
+ this.memory.tasks.splice(index, 1);
141
+ }
127
142
  }
128
143
  async Delete_Database_Idle(uuid) {
129
144
  return this.loader.project.load_all().then(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "verteilen-core",
3
- "version": "1.3.14",
3
+ "version": "1.3.16",
4
4
  "license": "MIT",
5
5
  "homepage": "https://verteilen.github.io/wiki/",
6
6
  "author": "Elly",
package/src/server/io.ts CHANGED
@@ -188,8 +188,8 @@ export const _CreateRecordIOLoader = (loader:RecordIOBase, memory:MemoryData, ty
188
188
  await loader.write_string(file, data)
189
189
  const arr = get_array(type)
190
190
  const b = arr.findIndex(x => x.uuid == uuid)
191
- if(b != -1) arr.push(JSON.parse(data))
192
- else arr[b] = JSON.parse(data)
191
+ if(b != -1) arr[b] = JSON.parse(data)
192
+ else arr.push(JSON.parse(data))
193
193
  },
194
194
  load: async (uuid:string, cache: boolean):Promise<string> => {
195
195
  const arr:Array<any> = get_array(type)
@@ -200,6 +200,11 @@ export const _CreateRecordIOLoader = (loader:RecordIOBase, memory:MemoryData, ty
200
200
  const root = loader.join(loader.root, folder)
201
201
  if(!loader.exists(root)) await loader.mkdir(root)
202
202
  const file = loader.join(root, uuid + ext)
203
+ if(!loader.exists(file)){
204
+ const b = arr.findIndex(x => x.uuid == uuid)
205
+ if(b != -1) arr.splice(b, 1)
206
+ return ""
207
+ }
203
208
  const a = await loader.read_string(file)
204
209
  if(cache) arr.push(JSON.parse(a))
205
210
  return a
@@ -219,7 +224,9 @@ export const _CreateRecordIOLoader = (loader:RecordIOBase, memory:MemoryData, ty
219
224
  const root = loader.join(loader.root, folder)
220
225
  if(!loader.exists(root)) await loader.mkdir(root)
221
226
  const file = loader.join(root, uuid + ext)
222
- await loader.rm(file)
227
+ if(loader.exists(file)){
228
+ await loader.rm(file)
229
+ }
223
230
  const arr = get_array(type)
224
231
  const b = arr.findIndex(x => x.uuid == uuid)
225
232
  if(b != -1) arr.splice(b, 1)
@@ -158,13 +158,30 @@ export class Project_Module {
158
158
  * Delete Task related data and project itself
159
159
  * @param uuid Task UUID
160
160
  */
161
- async CascadeDeleteTask(uuid:string):Promise<void>{
161
+ async CascadeDeleteTask(uuid:string):Promise<void>{
162
162
  await this.loader.task.load(uuid, true)
163
163
  const p:Task = this.memory.tasks.find(p=> p.uuid == uuid)!
164
164
  if(!p) return
165
165
  const ps = p.jobs_uuid.map(j_uuid => this.loader.job.delete(j_uuid))
166
166
  await Promise.all(ps)
167
167
  await this.loader.task.delete(uuid)
168
+ const ps2 = this.memory.projects.filter(x => x.tasks_uuid.includes(uuid)).map(x => x.uuid)
169
+ for(let u of ps2){
170
+ const index = this.memory.projects.findIndex(x => x.uuid == u)
171
+ if(index != -1) this.memory.projects.splice(index, 1)
172
+ }
173
+ }
174
+ /**
175
+ * Delete Task related data and project itself
176
+ * @param uuid Task UUID
177
+ */
178
+ async CascadeDeleteJob(uuid:string):Promise<void>{
179
+ await this.loader.job.delete(uuid)
180
+ const ps2 = this.memory.tasks.filter(x => x.jobs_uuid.includes(uuid)).map(x => x.uuid)
181
+ for(let u of ps2){
182
+ const index = this.memory.tasks.findIndex(x => x.uuid == u)
183
+ if(index != -1) this.memory.tasks.splice(index, 1)
184
+ }
168
185
  }
169
186
  /**
170
187
  * Delete idle database
@@ -0,0 +1,32 @@
1
+ import { CreateRecordIOLoader, DATA_FOLDER, RecordIOBase, Server } from '../../src/index'
2
+ import * as path from 'path'
3
+ import * as os from 'os'
4
+ import * as fs from "fs";
5
+ import * as fsp from "fs/promises";
6
+
7
+ const CreateIO = ():RecordIOBase => {
8
+ return {
9
+ root: path.join(os.homedir(), DATA_FOLDER),
10
+ join: path.join,
11
+ read_dir: (path:string) => fsp.readdir(path, { withFileTypes: false }),
12
+ read_dir_dir: (path:string) => fsp.readdir(path, { withFileTypes: true }).then(x => x.filter(y => !y.isFile()).map(y => y.name)),
13
+ read_dir_file: (path:string) => fsp.readdir(path, { withFileTypes: true }).then(x => x.filter(y => y.isFile()).map(y => y.name)),
14
+ read_string: (path:string, options?:any) => fsp.readFile(path, options).then(x => x.toString('utf-8')),
15
+ write_string: (path:string, content:string) => fsp.writeFile(path, content),
16
+ exists: (path:string) => fs.existsSync(path),
17
+ mkdir: async (path:string) => { await fsp.mkdir(path, {recursive: true}) },
18
+ rm: (path:string) => fsp.rm(path, {recursive: true}),
19
+ cp: (path:string, newpath:string) => fsp.cp(path, newpath)
20
+ }
21
+ }
22
+
23
+ async function main(){
24
+ const server:Server = new Server()
25
+ server.io = CreateIO()
26
+ server.loader = CreateRecordIOLoader(server.io, server.memory)
27
+
28
+ const p = await server.loader.task.load_all()
29
+ console.log(p.map(x => JSON.parse(x)))
30
+ }
31
+
32
+ main()