@openfn/project 0.10.1 → 0.11.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 CHANGED
@@ -15,6 +15,8 @@ declare class Workflow {
15
15
  options: any;
16
16
  constructor(workflow: l.Workflow);
17
17
  get steps(): WithMeta<l.Job & l.Trigger>[];
18
+ get start(): string | undefined;
19
+ set start(s: string);
18
20
  _buildIndex(): void;
19
21
  set(id: string, props: Partial<l.Job | l.StepEdge>): this;
20
22
  get(id: string): WithMeta<l.Step | l.Trigger | l.StepEdge>;
@@ -43,6 +45,7 @@ type FromPathConfig = l.WorkspaceConfig & {
43
45
 
44
46
  type FromFsConfig = {
45
47
  root: string;
48
+ config?: Partial<l.WorkspaceConfig>;
46
49
  logger?: Logger;
47
50
  };
48
51
 
@@ -66,6 +69,7 @@ type MergeProjectOptions = {
66
69
  declare class Workspace {
67
70
  config: l.WorkspaceConfig;
68
71
  activeProject?: l.ProjectMeta;
72
+ root: string;
69
73
  private projects;
70
74
  private projectPaths;
71
75
  private isValid;
@@ -77,6 +81,8 @@ declare class Workspace {
77
81
  get(nameyThing: string): Project | null;
78
82
  getProjectPath(id: string): string | undefined;
79
83
  getActiveProject(): Project | undefined;
84
+ getCheckedOutProject(): Promise<Project>;
85
+ getCredentialMap(): string | undefined;
80
86
  getConfig(): Partial<l.WorkspaceConfig>;
81
87
  get activeProjectId(): unknown;
82
88
  get valid(): boolean;
package/dist/index.js CHANGED
@@ -105,7 +105,16 @@ var Workflow = class {
105
105
  };
106
106
  this.workflow = clone(workflow);
107
107
  this.workflow.history = workflow.history?.length ? workflow.history : [];
108
- const { id, name, openfn, steps, history, ...options } = workflow;
108
+ const {
109
+ id,
110
+ name,
111
+ openfn,
112
+ steps,
113
+ history,
114
+ start: _start,
115
+ options,
116
+ ...rest
117
+ } = workflow;
109
118
  if (!(id || name)) {
110
119
  throw new Error("A Workflow MUST have a name or id");
111
120
  }
@@ -116,12 +125,18 @@ var Workflow = class {
116
125
  this.workflow.name = this.name;
117
126
  }
118
127
  this.openfn = openfn;
119
- this.options = options;
128
+ this.options = Object.assign({}, options, rest);
120
129
  this._buildIndex();
121
130
  }
122
131
  get steps() {
123
132
  return this.workflow.steps;
124
133
  }
134
+ get start() {
135
+ return this.workflow.start;
136
+ }
137
+ set start(s) {
138
+ this.workflow.start = s;
139
+ }
125
140
  _buildIndex() {
126
141
  for (const step of this.workflow.steps) {
127
142
  const s = step;
@@ -389,6 +404,7 @@ import { readFileSync } from "node:fs";
389
404
  import path from "node:path";
390
405
  import { pickBy, isNil as isNil2 } from "lodash-es";
391
406
  var buildConfig = (config = {}) => ({
407
+ credentials: "credentials.yaml",
392
408
  ...config,
393
409
  dirs: {
394
410
  projects: config.dirs?.projects ?? ".projects",
@@ -505,6 +521,7 @@ var extractWorkflow = (project, workflowId) => {
505
521
  const wf = {
506
522
  id: workflow.id,
507
523
  name: workflow.name,
524
+ start: workflow.start,
508
525
  // Note: if no options are defined, options will serialize to an empty object
509
526
  // Not crazy about this - maybe we should do something better? Or do we like the consistency?
510
527
  options: workflow.options,
@@ -690,6 +707,9 @@ var mapWorkflow2 = (workflow) => {
690
707
  }
691
708
  workflow.triggers.forEach((trigger) => {
692
709
  const { type, ...otherProps } = trigger;
710
+ if (!mapped.start) {
711
+ mapped.start = `trigger-${type}`;
712
+ }
693
713
  const connectedEdges = edges.filter(
694
714
  (e) => e.source_trigger_id === trigger.id
695
715
  );
@@ -748,16 +768,13 @@ import path2 from "node:path";
748
768
  // src/parse/from-project.ts
749
769
  var from_project_default = (data, config) => {
750
770
  let rawJson = ensure_json_default(data);
751
- let json;
752
771
  if (rawJson.cli?.version ?? rawJson.version) {
753
- json = from_v2(rawJson);
754
- } else {
755
- json = from_v1(rawJson);
772
+ return new Project_default(from_v2(rawJson), config);
756
773
  }
757
- return new Project_default(json, config);
774
+ return from_v1(rawJson, config);
758
775
  };
759
- var from_v1 = (data) => {
760
- return from_app_state_default(data);
776
+ var from_v1 = (data, config = {}) => {
777
+ return from_app_state_default(data, {}, config);
761
778
  };
762
779
  var from_v2 = (data) => {
763
780
  return {
@@ -789,7 +806,7 @@ var parseProject = async (options) => {
789
806
  const { root, logger } = options;
790
807
  const { type, content } = findWorkspaceFile(root);
791
808
  const context = loadWorkspaceFile(content, type);
792
- const config = buildConfig(context.workspace);
809
+ const config = buildConfig(options.config ?? context.workspace);
793
810
  const proj = {
794
811
  id: context.project?.id,
795
812
  name: context.project?.name,
@@ -799,14 +816,26 @@ var parseProject = async (options) => {
799
816
  };
800
817
  const workflowDir = config.workflowRoot ?? config.dirs?.workflows ?? "workflows";
801
818
  const fileType = config.formats?.workflow ?? "yaml";
802
- const pattern = `${root}/${workflowDir}/*/*.${fileType}`;
819
+ const pattern = path3.resolve(root, workflowDir) + `/**/*.${fileType}`;
803
820
  const candidateWfs = await glob(pattern, {
804
821
  ignore: ["**node_modules/**", "**tmp**"]
805
822
  });
806
823
  for (const filePath of candidateWfs) {
807
824
  const candidate = await fs.readFile(filePath, "utf-8");
808
825
  try {
809
- const wf = fileType === "yaml" ? yamlToJson(candidate) : JSON.parse(candidate);
826
+ let wf = fileType === "yaml" ? yamlToJson(candidate) : JSON.parse(candidate);
827
+ if (wf.workflow) {
828
+ if (wf.options) {
829
+ const { start, ...rest } = wf.options;
830
+ if (start) {
831
+ wf.workflow.start = start;
832
+ }
833
+ if (rest) {
834
+ wf.workflow.options = Object.assign({}, wf.workflow.options, rest);
835
+ }
836
+ }
837
+ wf = wf.workflow;
838
+ }
810
839
  if (wf.id && Array.isArray(wf.steps)) {
811
840
  for (const step of wf.steps) {
812
841
  if (step.expression && step.expression.endsWith(".js")) {
@@ -1454,6 +1483,7 @@ var Workspace = class {
1454
1483
  config;
1455
1484
  // TODO activeProject should be the actual project
1456
1485
  activeProject;
1486
+ root;
1457
1487
  projects = [];
1458
1488
  projectPaths = /* @__PURE__ */ new Map();
1459
1489
  isValid = false;
@@ -1461,6 +1491,7 @@ var Workspace = class {
1461
1491
  // Set validate to false to suppress warnings if a Workspace doesn't exist
1462
1492
  // This is appropriate if, say, fetching a project for the first time
1463
1493
  constructor(workspacePath, logger, validate = true) {
1494
+ this.root = workspacePath;
1464
1495
  this.logger = logger ?? createLogger("Workspace", { level: "info" });
1465
1496
  let context = { workspace: void 0, project: void 0 };
1466
1497
  try {
@@ -1526,6 +1557,12 @@ var Workspace = class {
1526
1557
  getActiveProject() {
1527
1558
  return this.projects.find((p) => p.openfn?.uuid === this.activeProject?.uuid) ?? this.projects.find((p) => p.id === this.activeProject?.id);
1528
1559
  }
1560
+ getCheckedOutProject() {
1561
+ return Project.from("fs", { root: this.root, config: this.config });
1562
+ }
1563
+ getCredentialMap() {
1564
+ return this.config.credentials;
1565
+ }
1529
1566
  // TODO this needs to return default values
1530
1567
  // We should always rely on the workspace to load these values
1531
1568
  getConfig() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfn/project",
3
- "version": "0.10.1",
3
+ "version": "0.11.0",
4
4
  "description": "Read, serialize, replicate and sync OpenFn projects",
5
5
  "type": "module",
6
6
  "exports": {