1+ import { humanId } from 'human-id' ;
12import Workflow from './Workflow' ;
23import * as serializers from './serialize' ;
34import fromAppState , { FromAppStateConfig } from './parse/from-app-state' ;
@@ -19,47 +20,22 @@ type MergeOptions = {
1920const maybeCreateWorkflow = ( wf : any ) =>
2021 wf instanceof Workflow ? wf : new Workflow ( wf ) ;
2122
22- // TODO --------------
23- // I think this needs renaming to config
24- // and it's part of the workspace technically
25- // I need to support custom props
26- // When serializing, for now, we always write defaults
27- // --------------
28- // repo-wide options
29- type RepoOptions = {
30- /**default workflow root when serializing to fs (relative to openfn.yaml) */
31- // TODO deprecate this
32- workflowRoot ?: string ;
33-
34- formats : {
35- openfn : FileFormats ;
36- workflow : FileFormats ;
37- project : FileFormats ;
38- } ;
39- } ;
40-
41- // A local collection of openfn projects?
42- // class Repo {
43-
44- // projects: {}
45- // }
46-
47- // TODO maybe use an npm for this, or create util
48-
49- // TODO this need to be controlled by the workspace
50-
5123// A single openfn project
5224// could be an app project or a checked out fs
5325export class Project {
5426 // what schema version is this?
5527 // And how are we tracking this?
5628 // version;
5729
58- /** project name */
30+ /** Human readable project name. This corresponds to the label in Lightning */
5931 name ?: string ;
32+
33+ /** Project id. Must be url safe. May be derived from the name. NOT a UUID */
34+ id : string ;
35+
6036 description ?: string ;
6137
62- // array of version shas
38+ // array of version hashes
6339 history : string [ ] = [ ] ;
6440
6541 workflows : Workflow [ ] ;
@@ -79,12 +55,6 @@ export class Project {
7955
8056 config : WorkspaceConfig ;
8157
82- // load a project from a state file (project.json)
83- // or from a path (the file system)
84- // TODO presumably we can detect a state file? Not a big deal?
85-
86- // collections for the project
87- // TODO to be well typed
8858 collections : any ;
8959
9060 static from (
@@ -129,10 +99,16 @@ export class Project {
12999 // stuff that's external to the actual project and managed by the repo
130100
131101 // TODO maybe the constructor is (data, Workspace)
132- constructor ( data : l . Project , repoConfig : RepoOptions = { } ) {
133- this . setConfig ( repoConfig ) ;
102+ constructor ( data : l . Project , config : RepoOptions = { } ) {
103+ this . setConfig ( config ) ;
104+
105+ this . id =
106+ data . id ?? data . name
107+ ? slugify ( data . name )
108+ : humanId ( { separator : '-' , capitalize : false } ) ;
134109
135110 this . name = data . name ;
111+
136112 this . description = data . description ;
137113 this . openfn = data . openfn ;
138114 this . options = data . options ;
@@ -154,19 +130,12 @@ export class Project {
154130 throw new Error ( `Cannot serialize ${ type } ` ) ;
155131 }
156132
157- // would like a better name for this
158- // stamp? id? sha?
159- // this builds a version string for the current state
160- getVersionHash ( ) { }
161-
162- // what else might we need?
163-
164- // get workflow by name or id
165- // this is fuzzy, but is that wrong?
133+ // get workflow by name, id or uuid
166134 getWorkflow ( idOrName : string ) {
167135 return (
168136 this . workflows . find ( ( wf ) => wf . id == idOrName ) ||
169- this . workflows . find ( ( wf ) => wf . name === idOrName )
137+ this . workflows . find ( ( wf ) => wf . name === idOrName ) ||
138+ this . workflows . find ( ( wf ) => wf . openfn ?. uuid === idOrName )
170139 ) ;
171140 }
172141
0 commit comments