Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(compogen): replace array[*] to array[any] #919

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pkg/component/generic/collection/v0/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Concatenate multiple arrays or merge multiple objects into a single collection.
| Input | ID | Type | Description |
| :--- | :--- | :--- | :--- |
| Task ID (required) | `task` | string | `TASK_CONCAT` |
| Data (required) | `data` | array[*] | An array of arrays or objects to be concatenated/merged. For arrays: [[1, 2], [3, 4]] becomes [1, 2, 3, 4]. For objects: [\{'a': 1\}, \{'b': 2\}] becomes \{'a': 1, 'b': 2\}. Later values override earlier ones for objects. |
| Data (required) | `data` | array[any] | An array of arrays or objects to be concatenated/merged. For arrays: [[1, 2], [3, 4]] becomes [1, 2, 3, 4]. For objects: [\{'a': 1\}, \{'b': 2\}] becomes \{'a': 1, 'b': 2\}. Later values override earlier ones for objects. |
</div>


Expand All @@ -123,7 +123,7 @@ Find elements that exist in the first array or object but not in any of the othe
| Input | ID | Type | Description |
| :--- | :--- | :--- | :--- |
| Task ID (required) | `task` | string | `TASK_DIFFERENCE` |
| Data (required) | `data` | array[*] | An array of arrays or objects to find the difference. The first element is compared against all subsequent elements. For example, given arrays [[1, 2, 3], [2, 3, 4], [3, 4, 5]], the result will be [1]. For objects, given [\{'a': 1, 'b': 2\}, \{'b': 2, 'c': 3\}], the result will be \{'a': 1\}. |
| Data (required) | `data` | array[any] | An array of arrays or objects to find the difference. The first element is compared against all subsequent elements. For example, given arrays [[1, 2, 3], [2, 3, 4], [3, 4, 5]], the result will be [1]. For objects, given [\{'a': 1, 'b': 2\}, \{'b': 2, 'c': 3\}], the result will be \{'a': 1\}. |
</div>


Expand All @@ -148,7 +148,7 @@ Find common elements that exist in all input arrays or objects.
| Input | ID | Type | Description |
| :--- | :--- | :--- | :--- |
| Task ID (required) | `task` | string | `TASK_INTERSECTION` |
| Data (required) | `data` | array[*] | An array of arrays or objects to find common elements. For arrays: given [[1, 2, 3], [2, 3, 4]], the result will be [2, 3]. For objects: given [\{'a': 1, 'b': 2\}, \{'b': 2, 'c': 3\}], the result will be \{'b': 2\}. |
| Data (required) | `data` | array[any] | An array of arrays or objects to find common elements. For arrays: given [[1, 2, 3], [2, 3, 4]], the result will be [2, 3]. For objects: given [\{'a': 1, 'b': 2\}, \{'b': 2, 'c': 3\}], the result will be \{'b': 2\}. |
</div>


Expand Down Expand Up @@ -186,7 +186,7 @@ Split arrays or objects into smaller chunks.

| Output | ID | Type | Description |
| :--- | :--- | :--- | :--- |
| Data | `data` | array[*] | The resulting array after splitting. For arrays: array of subarrays. For objects: array of smaller objects with alphabetically ordered keys |
| Data | `data` | array[any] | The resulting array after splitting. For arrays: array of subarrays. For objects: array of smaller objects with alphabetically ordered keys |
</div>


Expand All @@ -199,7 +199,7 @@ Find elements that exist in exactly one of the input arrays or objects, but not
| Input | ID | Type | Description |
| :--- | :--- | :--- | :--- |
| Task ID (required) | `task` | string | `TASK_SYMMETRIC_DIFFERENCE` |
| Data (required) | `data` | array[*] | An array of arrays or objects to find symmetric difference. For arrays: given [[1, 2], [2, 3]], the result will be [1, 3]. For objects: given [\{'a': 1, 'b': 2\}, \{'b': 2, 'c': 3\}], the result will be \{'a': 1, 'c': 3\}. |
| Data (required) | `data` | array[any] | An array of arrays or objects to find symmetric difference. For arrays: given [[1, 2], [2, 3]], the result will be [1, 3]. For objects: given [\{'a': 1, 'b': 2\}, \{'b': 2, 'c': 3\}], the result will be \{'a': 1, 'c': 3\}. |
</div>


Expand All @@ -224,7 +224,7 @@ Find unique elements that exist in any of the input arrays or objects.
| Input | ID | Type | Description |
| :--- | :--- | :--- | :--- |
| Task ID (required) | `task` | string | `TASK_UNION` |
| Data (required) | `data` | array[*] | An array of arrays or objects to find unique elements. For arrays: given [[1, 2], [2, 3]], the result will be [1, 2, 3]. For objects: given [\{'a': 1, 'b': 2\}, \{'b': 2, 'c': 3\}], the result will be \{'a': 1, 'b': 2, 'c': 3\}. |
| Data (required) | `data` | array[any] | An array of arrays or objects to find unique elements. For arrays: given [[1, 2], [2, 3]], the result will be [1, 2, 3]. For objects: given [\{'a': 1, 'b': 2\}, \{'b': 2, 'c': 3\}], the result will be \{'a': 1, 'b': 2, 'c': 3\}. |
</div>


Expand Down
10 changes: 10 additions & 0 deletions pkg/component/tools/compogen/cmd/testdata/readme-component1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,15 @@ cmp pkg/dummy/README.mdx want-readme.mdx
"instillUIOrder": 0,
"title": "Dummy File",
"type": "*"
},
"dummy-array": {
"description": "this is an array",
"instillUIOrder": 0,
"title": "Dummy Array",
"type": "array",
"items": {
"type": "*"
}
}
},
"required": [
Expand Down Expand Up @@ -377,6 +386,7 @@ Perform a dummy task.
| Input | ID | Type | Description |
| :--- | :--- | :--- | :--- |
| Task ID (required) | `task` | string | `TASK_DUMMY` |
| Dummy Array | `dummy-array` | array[any] | this is an array |
| Dummy File | `dummy-file` | any | this is a file |
| Dummy String | `dummy-string` | string | `{{dummy_string}}` |
| Durna (required) | `durna` | string | Lorem ipsum dolor sit amet, consectetur adipiscing elit |
Expand Down
11 changes: 9 additions & 2 deletions pkg/component/tools/compogen/pkg/gen/readme.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,18 +321,22 @@ func parseResourceProperties(o *objectSchema) []resourceProperty {
}

prop.Title = titleCase(prop.Title)
prop.replaceType()

// If type is map, extend the type with the element type.
switch prop.Type {
case "array":
if prop.Items.Type != "" {
prop.Type += fmt.Sprintf("[%s]", prop.Items.Type)
if prop.Items.Type == "*" {
prop.Type = "array[any]"
} else {
prop.Type += fmt.Sprintf("[%s]", prop.Items.Type)
}
}
case "":
prop.Type = "any"
}
prop.replaceDescription()
prop.replaceType()

propMap[k] = prop
}
Expand Down Expand Up @@ -680,4 +684,7 @@ func (prop *property) replaceType() {
if prop.Type == "*" {
prop.Type = "any"
}
if prop.Type == "array" && prop.Items.Type == "*" {
prop.Type = "array[any]"
}
}
Loading