@openfn/project 0.2.0 → 0.3.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/index.d.ts +35 -4
- package/dist/index.js +77 -14
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -34,6 +34,10 @@ declare class Workflow {
|
|
|
34
34
|
toJSON(): JSON.Object;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
type FromFsConfig = {
|
|
38
|
+
root: string;
|
|
39
|
+
};
|
|
40
|
+
|
|
37
41
|
type MergeProjectOptions = Partial<{
|
|
38
42
|
workflowMappings: Record<string, string>;
|
|
39
43
|
removeUnmapped: boolean;
|
|
@@ -41,6 +45,22 @@ type MergeProjectOptions = Partial<{
|
|
|
41
45
|
}>;
|
|
42
46
|
|
|
43
47
|
type FileFormats = 'yaml' | 'json';
|
|
48
|
+
interface OpenfnConfig {
|
|
49
|
+
name: string;
|
|
50
|
+
workflowRoot: string;
|
|
51
|
+
formats: {
|
|
52
|
+
openfn: FileFormats;
|
|
53
|
+
project: FileFormats;
|
|
54
|
+
workflow: FileFormats;
|
|
55
|
+
};
|
|
56
|
+
project: {
|
|
57
|
+
projectId: string;
|
|
58
|
+
endpoint: string;
|
|
59
|
+
env: string;
|
|
60
|
+
inserted_at: string;
|
|
61
|
+
updated_at: string;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
44
64
|
type RepoOptions = {
|
|
45
65
|
/**default workflow root when serializing to fs (relative to openfn.yaml) */
|
|
46
66
|
workflowRoot?: string;
|
|
@@ -62,9 +82,7 @@ declare class Project {
|
|
|
62
82
|
repo?: Required<RepoOptions>;
|
|
63
83
|
collections: any;
|
|
64
84
|
static from(type: 'state', data: any, options: Partial<l.ProjectConfig>): Project;
|
|
65
|
-
static from(type: 'fs', options:
|
|
66
|
-
root: string;
|
|
67
|
-
}): Project;
|
|
85
|
+
static from(type: 'fs', options: FromFsConfig): Project;
|
|
68
86
|
static from(type: 'path', data: any): Project;
|
|
69
87
|
static diff(a: Project, b: Project): void;
|
|
70
88
|
static merge(source: Project, target: Project, options: MergeProjectOptions): Project;
|
|
@@ -77,7 +95,20 @@ declare class Project {
|
|
|
77
95
|
getUUID(workflow: string | Workflow, stepId: string, otherStep?: string): any;
|
|
78
96
|
}
|
|
79
97
|
|
|
98
|
+
declare class Workspace {
|
|
99
|
+
private config?;
|
|
100
|
+
private projects;
|
|
101
|
+
private isValid;
|
|
102
|
+
constructor(workspacePath: string);
|
|
103
|
+
list(): Project[];
|
|
104
|
+
get(id: string): Project | undefined;
|
|
105
|
+
getActiveProject(): Project | undefined;
|
|
106
|
+
getConfig(): OpenfnConfig | undefined;
|
|
107
|
+
get activeProjectId(): string | undefined;
|
|
108
|
+
get valid(): boolean;
|
|
109
|
+
}
|
|
110
|
+
|
|
80
111
|
declare function yamlToJson(y: string): any;
|
|
81
112
|
declare function jsonToYaml(json: string | JSONObject): string;
|
|
82
113
|
|
|
83
|
-
export { Project as default, jsonToYaml, yamlToJson };
|
|
114
|
+
export { Workspace, Project as default, jsonToYaml, yamlToJson };
|
package/dist/index.js
CHANGED
|
@@ -263,16 +263,16 @@ import nodepath from "path";
|
|
|
263
263
|
var stringify = (json) => JSON.stringify(json, null, 2);
|
|
264
264
|
function to_fs_default(project) {
|
|
265
265
|
const files = {};
|
|
266
|
-
const { path:
|
|
267
|
-
files[
|
|
266
|
+
const { path: path3, content } = extractRepoConfig(project);
|
|
267
|
+
files[path3] = content;
|
|
268
268
|
for (const wf of project.workflows) {
|
|
269
|
-
const { path:
|
|
270
|
-
files[
|
|
269
|
+
const { path: path4, content: content2 } = extractWorkflow(project, wf.id);
|
|
270
|
+
files[path4] = content2;
|
|
271
271
|
for (const s of wf.steps) {
|
|
272
272
|
const result = extractStep(project, wf.id, s.id);
|
|
273
273
|
if (result) {
|
|
274
|
-
const { path:
|
|
275
|
-
files[
|
|
274
|
+
const { path: path5, content: content3 } = result;
|
|
275
|
+
files[path5] = content3;
|
|
276
276
|
}
|
|
277
277
|
}
|
|
278
278
|
}
|
|
@@ -285,7 +285,7 @@ var extractWorkflow = (project, workflowId2) => {
|
|
|
285
285
|
throw new Error(`workflow not found: ${workflowId2}`);
|
|
286
286
|
}
|
|
287
287
|
const root = project.repo?.workflowRoot ?? "workflows/";
|
|
288
|
-
const
|
|
288
|
+
const path3 = nodepath.join(root, workflow.id, workflow.id);
|
|
289
289
|
const wf = {
|
|
290
290
|
id: workflow.id,
|
|
291
291
|
name: workflow.name,
|
|
@@ -300,7 +300,7 @@ var extractWorkflow = (project, workflowId2) => {
|
|
|
300
300
|
return mapped;
|
|
301
301
|
})
|
|
302
302
|
};
|
|
303
|
-
return handleOutput(wf,
|
|
303
|
+
return handleOutput(wf, path3, format);
|
|
304
304
|
};
|
|
305
305
|
var extractStep = (project, workflowId2, stepId) => {
|
|
306
306
|
const workflow = project.getWorkflow(workflowId2);
|
|
@@ -313,9 +313,9 @@ var extractStep = (project, workflowId2, stepId) => {
|
|
|
313
313
|
}
|
|
314
314
|
if (step.expression) {
|
|
315
315
|
const root = project.config?.workflowRoot ?? "workflows/";
|
|
316
|
-
const
|
|
316
|
+
const path3 = nodepath.join(root, `${workflow.id}/${step.id}.js`);
|
|
317
317
|
const content = step.expression;
|
|
318
|
-
return { path:
|
|
318
|
+
return { path: path3, content };
|
|
319
319
|
}
|
|
320
320
|
};
|
|
321
321
|
var extractRepoConfig = (project) => {
|
|
@@ -328,7 +328,7 @@ var extractRepoConfig = (project) => {
|
|
|
328
328
|
return handleOutput(config, "openfn", format);
|
|
329
329
|
};
|
|
330
330
|
var handleOutput = (data, filePath, format) => {
|
|
331
|
-
const
|
|
331
|
+
const path3 = `${filePath}.${format}`;
|
|
332
332
|
let content;
|
|
333
333
|
if (format === "json") {
|
|
334
334
|
content = stringify(data, null, 2);
|
|
@@ -337,7 +337,7 @@ var handleOutput = (data, filePath, format) => {
|
|
|
337
337
|
} else {
|
|
338
338
|
throw new Error(`Unrecognised format: ${format}`);
|
|
339
339
|
}
|
|
340
|
-
return { path:
|
|
340
|
+
return { path: path3, content };
|
|
341
341
|
};
|
|
342
342
|
|
|
343
343
|
// src/parse/from-app-state.ts
|
|
@@ -984,8 +984,7 @@ var Project = class {
|
|
|
984
984
|
static from(type, data, options) {
|
|
985
985
|
if (type === "state") {
|
|
986
986
|
return from_app_state_default(data, options);
|
|
987
|
-
}
|
|
988
|
-
if (type === "fs") {
|
|
987
|
+
} else if (type === "fs") {
|
|
989
988
|
return parseProject(data, options);
|
|
990
989
|
}
|
|
991
990
|
throw new Error(`Didn't recognize type ${type}`);
|
|
@@ -1050,9 +1049,73 @@ var Project = class {
|
|
|
1050
1049
|
}
|
|
1051
1050
|
};
|
|
1052
1051
|
|
|
1052
|
+
// src/util/path-exists.ts
|
|
1053
|
+
import fs2 from "fs";
|
|
1054
|
+
function pathExists(fpath, type) {
|
|
1055
|
+
try {
|
|
1056
|
+
const stat = fs2.statSync(fpath);
|
|
1057
|
+
if (type === "file" && stat.isFile())
|
|
1058
|
+
return true;
|
|
1059
|
+
else if (type === "directory" && stat.isDirectory())
|
|
1060
|
+
return true;
|
|
1061
|
+
return false;
|
|
1062
|
+
} catch (e) {
|
|
1063
|
+
return false;
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
// src/Workspace.ts
|
|
1068
|
+
import path2 from "path";
|
|
1069
|
+
import fs3 from "fs";
|
|
1070
|
+
var PROJECTS_DIRECTORY = ".projects";
|
|
1071
|
+
var OPENFN_YAML_FILE = "openfn.yaml";
|
|
1072
|
+
var PROJECT_EXTENSIONS = [".yaml", ".yml"];
|
|
1073
|
+
var Workspace = class {
|
|
1074
|
+
config;
|
|
1075
|
+
projects = [];
|
|
1076
|
+
isValid = false;
|
|
1077
|
+
constructor(workspacePath) {
|
|
1078
|
+
const projectsPath = path2.join(workspacePath, PROJECTS_DIRECTORY);
|
|
1079
|
+
const openfnYamlPath = path2.join(workspacePath, OPENFN_YAML_FILE);
|
|
1080
|
+
if (pathExists(openfnYamlPath, "file")) {
|
|
1081
|
+
this.isValid = true;
|
|
1082
|
+
const data = fs3.readFileSync(openfnYamlPath, "utf-8");
|
|
1083
|
+
this.config = yamlToJson(data);
|
|
1084
|
+
}
|
|
1085
|
+
if (this.isValid && pathExists(projectsPath, "directory")) {
|
|
1086
|
+
const stateFiles = fs3.readdirSync(projectsPath).filter(
|
|
1087
|
+
(fileName) => PROJECT_EXTENSIONS.includes(path2.extname(fileName))
|
|
1088
|
+
);
|
|
1089
|
+
this.projects = stateFiles.map((file) => {
|
|
1090
|
+
const data = fs3.readFileSync(path2.join(projectsPath, file), "utf-8");
|
|
1091
|
+
return from_app_state_default(data, { format: "yaml" });
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
list() {
|
|
1096
|
+
return this.projects;
|
|
1097
|
+
}
|
|
1098
|
+
get(id) {
|
|
1099
|
+
return this.projects.find((p) => p.name === id);
|
|
1100
|
+
}
|
|
1101
|
+
getActiveProject() {
|
|
1102
|
+
return this.projects.find((p) => p.name === this.config?.name);
|
|
1103
|
+
}
|
|
1104
|
+
getConfig() {
|
|
1105
|
+
return this.config;
|
|
1106
|
+
}
|
|
1107
|
+
get activeProjectId() {
|
|
1108
|
+
return this.config?.name;
|
|
1109
|
+
}
|
|
1110
|
+
get valid() {
|
|
1111
|
+
return this.isValid;
|
|
1112
|
+
}
|
|
1113
|
+
};
|
|
1114
|
+
|
|
1053
1115
|
// src/index.ts
|
|
1054
1116
|
var src_default = Project;
|
|
1055
1117
|
export {
|
|
1118
|
+
Workspace,
|
|
1056
1119
|
src_default as default,
|
|
1057
1120
|
jsonToYaml,
|
|
1058
1121
|
yamlToJson
|