@openfn/project 0.3.0 → 0.4.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 +14 -3
- package/dist/index.js +66 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -18,9 +18,8 @@ declare class Workflow {
|
|
|
18
18
|
name: string;
|
|
19
19
|
id: string;
|
|
20
20
|
openfn: OpenfnMeta;
|
|
21
|
-
steps: WithMeta<l.Job | l.Trigger>[];
|
|
22
21
|
constructor(workflow: l.Workflow);
|
|
23
|
-
get steps():
|
|
22
|
+
get steps(): WithMeta<l.Job | l.Trigger>[];
|
|
24
23
|
set(id: string, props: Parital<l.Job, l.Edge>): this;
|
|
25
24
|
get(id: any): WithMeta<l.Step | l.Trigger | l.Edge>;
|
|
26
25
|
meta(id: any): OpenfnMeta;
|
|
@@ -111,4 +110,16 @@ declare class Workspace {
|
|
|
111
110
|
declare function yamlToJson(y: string): any;
|
|
112
111
|
declare function jsonToYaml(json: string | JSONObject): string;
|
|
113
112
|
|
|
114
|
-
|
|
113
|
+
type GenerateWorkflowOptions = {
|
|
114
|
+
name: string;
|
|
115
|
+
uuidSeed: number;
|
|
116
|
+
openfnUuid: boolean;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Generate a Workflow from a simple text based representation
|
|
120
|
+
* The def array contains strings of pairs of nodes
|
|
121
|
+
* eg, ['a-b', 'b-c']
|
|
122
|
+
*/
|
|
123
|
+
declare function generateWorkflow(def: string[], options?: Partial<GenerateWorkflowOptions>): Workflow;
|
|
124
|
+
|
|
125
|
+
export { Workspace, Project as default, generateWorkflow as generate, jsonToYaml, yamlToJson };
|
package/dist/index.js
CHANGED
|
@@ -13,7 +13,6 @@ var Workflow = class {
|
|
|
13
13
|
name;
|
|
14
14
|
id;
|
|
15
15
|
openfn;
|
|
16
|
-
steps;
|
|
17
16
|
constructor(workflow) {
|
|
18
17
|
this.index = {
|
|
19
18
|
steps: {},
|
|
@@ -944,6 +943,7 @@ function merge(source, target, options) {
|
|
|
944
943
|
}
|
|
945
944
|
|
|
946
945
|
// src/Project.ts
|
|
946
|
+
var maybeCreateWorkflow = (wf) => wf instanceof Workflow_default ? wf : new Workflow_default(wf);
|
|
947
947
|
var setConfigDefaults = (config = {}) => ({
|
|
948
948
|
workflowRoot: config.workflowRoot ?? "workflows",
|
|
949
949
|
formats: {
|
|
@@ -1008,7 +1008,7 @@ var Project = class {
|
|
|
1008
1008
|
this.description = data.description;
|
|
1009
1009
|
this.openfn = data.openfn;
|
|
1010
1010
|
this.options = data.options;
|
|
1011
|
-
this.workflows = data.workflows?.map(
|
|
1011
|
+
this.workflows = data.workflows?.map(maybeCreateWorkflow) ?? [];
|
|
1012
1012
|
this.collections = data.collections;
|
|
1013
1013
|
this.credentials = data.credentials;
|
|
1014
1014
|
this.meta = data.meta;
|
|
@@ -1112,11 +1112,75 @@ var Workspace = class {
|
|
|
1112
1112
|
}
|
|
1113
1113
|
};
|
|
1114
1114
|
|
|
1115
|
+
// src/gen/workflow-generator.ts
|
|
1116
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
1117
|
+
|
|
1118
|
+
// src/util/slugify.ts
|
|
1119
|
+
function slugify2(text) {
|
|
1120
|
+
return text.replace(/\W/g, " ").trim().replace(/\s+/g, "-").toLowerCase();
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
// src/gen/workflow-generator.ts
|
|
1124
|
+
function gen(def, name = "workflow", uuidSeed, openfnUuid) {
|
|
1125
|
+
const ids = /* @__PURE__ */ new Map();
|
|
1126
|
+
const nodes = {};
|
|
1127
|
+
for (const conn of def) {
|
|
1128
|
+
const [from, to] = conn.split("-");
|
|
1129
|
+
if (nodes[from]) {
|
|
1130
|
+
if (to) {
|
|
1131
|
+
if (!nodes[from].next?.[to]) {
|
|
1132
|
+
nodes[from].next ??= {};
|
|
1133
|
+
nodes[from].next[to] = edge(`${from}-${to}`);
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
} else {
|
|
1137
|
+
let props;
|
|
1138
|
+
if (to) {
|
|
1139
|
+
props = { next: { [to]: edge(`${from}-${to}`) } };
|
|
1140
|
+
}
|
|
1141
|
+
nodes[from] = node(from, props);
|
|
1142
|
+
}
|
|
1143
|
+
if (to && !nodes[to]) {
|
|
1144
|
+
nodes[to] = node(to);
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
return {
|
|
1148
|
+
name,
|
|
1149
|
+
id: slugify2(name),
|
|
1150
|
+
steps: Object.values(nodes),
|
|
1151
|
+
...openfnUuid ? { openfn: { uuid: randomUUID2() } } : {}
|
|
1152
|
+
};
|
|
1153
|
+
function node(id, props = {}) {
|
|
1154
|
+
return {
|
|
1155
|
+
id,
|
|
1156
|
+
...props,
|
|
1157
|
+
openfn: { uuid: uuid(id) }
|
|
1158
|
+
};
|
|
1159
|
+
}
|
|
1160
|
+
function edge(id, props = {}) {
|
|
1161
|
+
return {
|
|
1162
|
+
...props,
|
|
1163
|
+
openfn: { uuid: uuid(id) }
|
|
1164
|
+
};
|
|
1165
|
+
}
|
|
1166
|
+
function uuid(id) {
|
|
1167
|
+
const muuid = !isNaN(uuidSeed) ? ++uuidSeed : randomUUID2();
|
|
1168
|
+
ids.set(id, muuid);
|
|
1169
|
+
return muuid;
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
function generateWorkflow(def, options = {}) {
|
|
1173
|
+
const { name, uuidSeed, openfnUuid } = options;
|
|
1174
|
+
const wf = gen(def, name, uuidSeed, openfnUuid);
|
|
1175
|
+
return new Workflow_default(wf);
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1115
1178
|
// src/index.ts
|
|
1116
1179
|
var src_default = Project;
|
|
1117
1180
|
export {
|
|
1118
1181
|
Workspace,
|
|
1119
1182
|
src_default as default,
|
|
1183
|
+
generateWorkflow as generate,
|
|
1120
1184
|
jsonToYaml,
|
|
1121
1185
|
yamlToJson
|
|
1122
1186
|
};
|