|
1 |
| -module Morphir.IR.Source exposing (..) |
| 1 | +{- |
| 2 | + Copyright 2020 Morgan Stanley |
2 | 3 |
|
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
3 | 7 |
|
4 |
| -type Located a |
5 |
| - = At Region a |
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
6 | 9 |
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | +-} |
7 | 16 |
|
8 |
| -type alias Region = |
9 |
| - { start : Location |
10 |
| - , end : Location |
| 17 | + |
| 18 | +module Morphir.IR.Source exposing |
| 19 | + ( Component, ComponentName, DataSourceName, OutputName, OutputSource, DataType(..) |
| 20 | + , component, outputSource |
| 21 | + , ParameterName |
| 22 | + ) |
| 23 | + |
| 24 | +{-| This module defines a JSON Source format for producing a new kind of Morphir IR defined in |
| 25 | +[Distribution](Distribution#Component). This format allows for the definition of entry points and their inputs that |
| 26 | +allows for the production of an encapsulated and tree-shaken component that has no external dependencies. |
| 27 | +
|
| 28 | +
|
| 29 | +# Types |
| 30 | +
|
| 31 | +@docs Component, ComponentName, DataSourceName, OutputName, ArgumentName, OutputSource, DataType |
| 32 | +
|
| 33 | +
|
| 34 | +# Creation |
| 35 | +
|
| 36 | +@docs component, outputSource |
| 37 | +
|
| 38 | +-} |
| 39 | + |
| 40 | +import Dict exposing (Dict) |
| 41 | +import Morphir.IR.FQName exposing (FQName) |
| 42 | +import Morphir.IR.Literal exposing (Literal) |
| 43 | +import Morphir.IR.Name exposing (Name) |
| 44 | +import Morphir.IR.Path exposing (Path) |
| 45 | + |
| 46 | + |
| 47 | +{-| Type that defines the entry points of [Component](Distribution#Component). |
| 48 | +The fields of a component are: |
| 49 | +
|
| 50 | + - name: The name of the component |
| 51 | + - inputs: The inputs of the component as a dictionary of the unique input name and [data type](#DataType). |
| 52 | + - states: The states of the component as a dictionary of the unique state name and [data type](#DataType). |
| 53 | + - outputs: The outputs of the component as a dictionary of unique names and a list of [sources](#OutputSource) that contribute to the output. |
| 54 | +
|
| 55 | +-} |
| 56 | +type alias Component = |
| 57 | + { name : ComponentName |
| 58 | + , inputs : Dict DataSourceName DataType |
| 59 | + , states : Dict DataSourceName DataType |
| 60 | + , outputs : Dict OutputName (List OutputSource) |
| 61 | + } |
| 62 | + |
| 63 | + |
| 64 | +{-| Represents a Component name. |
| 65 | +-} |
| 66 | +type alias ComponentName = |
| 67 | + Path |
| 68 | + |
| 69 | + |
| 70 | +{-| Represents a DataSource name. |
| 71 | +-} |
| 72 | +type alias DataSourceName = |
| 73 | + Name |
| 74 | + |
| 75 | + |
| 76 | +{-| Represents the types of data that can be used as a data source in either the inputs or states field of a [Component](#Component). |
| 77 | +-} |
| 78 | +type DataType |
| 79 | + = RowSet FQName |
| 80 | + | Literal Literal |
| 81 | + |
| 82 | + |
| 83 | +{-| Represents an Output name. |
| 84 | +-} |
| 85 | +type alias OutputName = |
| 86 | + Name |
| 87 | + |
| 88 | + |
| 89 | +{-| Represents the dependencies that contribute to an Output. The fields of an OutputSource are: |
| 90 | +
|
| 91 | + - functionReference: A fully qualified reference to a function that produces a slice of an output. |
| 92 | + - arguments: The arguments that are passed to the function reference. The keys are the parameter names and the values |
| 93 | + are the data source names. The data source names must be declared in inputs or states field of the [Component](#Component). |
| 94 | +
|
| 95 | +-} |
| 96 | +type alias OutputSource = |
| 97 | + { functionReference : FQName |
| 98 | + , arguments : Dict ParameterName DataSourceName |
| 99 | + } |
| 100 | + |
| 101 | + |
| 102 | +{-| Represents an Argument name. |
| 103 | +-} |
| 104 | +type alias ParameterName = |
| 105 | + Name |
| 106 | + |
| 107 | + |
| 108 | +{-| Creates a new component with the given name, inputs, states and outputs. |
| 109 | +-} |
| 110 | +component : ComponentName -> Dict DataSourceName DataType -> Dict DataSourceName DataType -> Dict OutputName (List OutputSource) -> Component |
| 111 | +component name inputs states outputs = |
| 112 | + { name = name |
| 113 | + , inputs = inputs |
| 114 | + , states = states |
| 115 | + , outputs = outputs |
11 | 116 | }
|
12 | 117 |
|
13 | 118 |
|
14 |
| -type alias Location = |
15 |
| - { row : Int |
16 |
| - , column : Int |
| 119 | +{-| Creates a new output source with the given function reference and arguments. |
| 120 | +-} |
| 121 | +outputSource : FQName -> Dict ParameterName DataSourceName -> OutputSource |
| 122 | +outputSource functionName arguments = |
| 123 | + { functionReference = functionName |
| 124 | + , arguments = arguments |
17 | 125 | }
|
0 commit comments