| 57 | } |
| 58 | |
| 59 | type Object interface { |
| 60 | // Build will be responsible for reading the metadata object from metadata files in project directory |
| 61 | // It should return nil if it was not able to find the matching metadata file |
| 62 | // Build returns a map of the objects, and it's corresponding unmarshalled content |
| 63 | // For example: |
| 64 | // an implementation for handling the "remote_schemas" object might return a map like |
| 65 | // "remote_schemas": []yaml.Node |
| 66 | // since there is a chance that this function can return a yaml.Node. The return value is not expected to |
| 67 | // directly be unmarshalled to JSON using json.Marshal |
| 68 | Build() (map[string]interface{}, error) |
| 69 | // Export is responsible for writing the yaml Node(s) for the metadata object |
| 70 | // to project directory |
| 71 | // Export expects a map[string]yaml.Node specifically rather than a builtin data structure like |
| 72 | // map[string]interface{} because it does not guarantee the order in which contents will be unmarshalled. |
| 73 | // eg: say we received the following JSON metadata from the server |
| 74 | // { |
| 75 | // "foo": [ |
| 76 | // "x": 1, |
| 77 | // "a": 2, |
| 78 | // ], |
| 79 | // } |
| 80 | // we are interested in preserving the order of keys when transforming this to YAML. Something like the following |
| 81 | // foo: |
| 82 | // x: 1 |
| 83 | // a: 2 |
| 84 | // This ordering is not guaranteed if we are using map[string]interface{} to unmarshal the JSON. This might look |
| 85 | // something like the following |
| 86 | // foo: |
| 87 | // a: 2 |
| 88 | // x: 1 |
| 89 | // This not bug, since JSON spec doesn't guarantee the ordering anyway. |
| 90 | // We are interested in writing or transforming the JSON object received from the server in |
| 91 | // the same order to YAML files. This coupled with our requirement of NOT strongly typing metadata on CLI requires |
| 92 | // using yaml.Node to preserve the ordering. |
| 93 | Export(metadata map[string]yaml.Node) (map[string][]byte, error) |
| 94 | CreateFiles() error |
| 95 | // GetFiles will return an array of file paths which make up the metadata object. |
| 96 | // For example the "sources" metadata key is made up of files like |
| 97 | // databases.yaml. which then will have !include tags which will branch to include |
| 98 | // files like databases/<source-name>/tables/tables.yaml |
| 99 | // this function is expected to return the list of all these files which make up the metadata object |
| 100 | GetFiles() ([]string, error) |
| 101 | // WriteDiff should be implemented such that it should write the difference |
| 102 | // between the current object and passed in object on the provided writer |
| 103 | WriteDiff(WriteDiffOpts) error |
| 104 | Key() string |
| 105 | Filename() string |
| 106 | // BaseDirectory will return the parent directory of `Filename()` |
| 107 | BaseDirectory() string |
| 108 | } |
| 109 | |
| 110 | var ErrMetadataFileNotFound = fmt.Errorf("metadata file not found") |
| 111 |
no outgoing calls
no test coverage detected