@adobe/aio-cli-plugin-app-storage 1.0.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/LICENSE +201 -0
- package/README.md +55 -0
- package/bin/run.js +16 -0
- package/oclif.manifest.json +316 -0
- package/package.json +63 -0
- package/src/BaseCommand.js +96 -0
- package/src/commands/app/state/delete.js +122 -0
- package/src/commands/app/state/get.js +55 -0
- package/src/commands/app/state/list.js +74 -0
- package/src/commands/app/state/put.js +68 -0
- package/src/commands/app/state/stats.js +36 -0
- package/src/constants.js +16 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright {yyyy} {name of copyright owner}
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# aio-cli-plugin-app-storage
|
|
2
|
+
|
|
3
|
+
The CLI Plugin to manage your App Builder State storage.
|
|
4
|
+
|
|
5
|
+
If you need to access State programmatically, check the
|
|
6
|
+
[@adobe/aio-lib-state](https://github.com/adobe/aio-lib-state) library.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
<!-- toc -->
|
|
10
|
+
* [aio-cli-plugin-app-storage](#aio-cli-plugin-app-storage)
|
|
11
|
+
* [Usage](#usage)
|
|
12
|
+
* [Commands](#commands)
|
|
13
|
+
<!-- tocstop -->
|
|
14
|
+
|
|
15
|
+
# Usage
|
|
16
|
+
|
|
17
|
+
```sh-session
|
|
18
|
+
$ aio plugins:install @adobe/aio-cli-plugin-app-storage
|
|
19
|
+
$ # OR
|
|
20
|
+
$ aio discover -i
|
|
21
|
+
$ aio app state --help
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
# Commands
|
|
25
|
+
<!-- commands -->
|
|
26
|
+
* [`aio help [COMMAND]`](#aio-help-command)
|
|
27
|
+
|
|
28
|
+
## `aio help [COMMAND]`
|
|
29
|
+
|
|
30
|
+
Display help for aio.
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
USAGE
|
|
34
|
+
$ aio help [COMMAND...] [-n]
|
|
35
|
+
|
|
36
|
+
ARGUMENTS
|
|
37
|
+
COMMAND... Command to show help for.
|
|
38
|
+
|
|
39
|
+
FLAGS
|
|
40
|
+
-n, --nested-commands Include all nested commands in the output.
|
|
41
|
+
|
|
42
|
+
DESCRIPTION
|
|
43
|
+
Display help for aio.
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v6.2.8/src/commands/help.ts)_
|
|
47
|
+
<!-- commandsstop -->
|
|
48
|
+
|
|
49
|
+
## Contributing
|
|
50
|
+
|
|
51
|
+
Contributions are welcomed! Read the [Contributing Guide](CONTRIBUTING.md) for more information.
|
|
52
|
+
|
|
53
|
+
## Licensing
|
|
54
|
+
|
|
55
|
+
This project is licensed under the Apache V2 License. See [LICENSE](LICENSE) for more information.
|
package/bin/run.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/* eslint-disable node/shebang */
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
Copyright 2024 Adobe. All rights reserved.
|
|
6
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
8
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
10
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
11
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
|
+
governing permissions and limitations under the License.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import {execute} from '@oclif/core'
|
|
16
|
+
await execute({dir: import.meta.url})
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
{
|
|
2
|
+
"commands": {
|
|
3
|
+
"app:state:delete": {
|
|
4
|
+
"aliases": [
|
|
5
|
+
"app:state:delete"
|
|
6
|
+
],
|
|
7
|
+
"args": {
|
|
8
|
+
"keys": {
|
|
9
|
+
"description": "keys to delete. Above 5 keys, you will be prompted for confirmation",
|
|
10
|
+
"name": "keys",
|
|
11
|
+
"required": false
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"description": "Delete key-values",
|
|
15
|
+
"examples": [
|
|
16
|
+
"$ aio app state delete key",
|
|
17
|
+
"$ aio app state delete key1 key2 key3",
|
|
18
|
+
"$ aio app state delete --match 'gl*b'",
|
|
19
|
+
"$ aio app state delete --match 'gl*b' --json",
|
|
20
|
+
"$ aio app state delete --match 'be-carreful*' --force"
|
|
21
|
+
],
|
|
22
|
+
"flags": {
|
|
23
|
+
"json": {
|
|
24
|
+
"description": "Format output as json.",
|
|
25
|
+
"helpGroup": "GLOBAL",
|
|
26
|
+
"name": "json",
|
|
27
|
+
"allowNo": false,
|
|
28
|
+
"type": "boolean"
|
|
29
|
+
},
|
|
30
|
+
"region": {
|
|
31
|
+
"description": "State region. Defaults to 'AIO_STATE_REGION' env or 'amer' if neither is set.",
|
|
32
|
+
"name": "region",
|
|
33
|
+
"required": false,
|
|
34
|
+
"hasDynamicHelp": false,
|
|
35
|
+
"multiple": false,
|
|
36
|
+
"options": [
|
|
37
|
+
"amer",
|
|
38
|
+
"emea"
|
|
39
|
+
],
|
|
40
|
+
"type": "option"
|
|
41
|
+
},
|
|
42
|
+
"match": {
|
|
43
|
+
"description": "[use with caution!] deletes ALL key-values matching the provided glob-like pattern",
|
|
44
|
+
"name": "match",
|
|
45
|
+
"required": false,
|
|
46
|
+
"hasDynamicHelp": false,
|
|
47
|
+
"multiple": false,
|
|
48
|
+
"type": "option"
|
|
49
|
+
},
|
|
50
|
+
"force": {
|
|
51
|
+
"description": "[use with caution!] force delete, no safety prompt",
|
|
52
|
+
"name": "force",
|
|
53
|
+
"allowNo": false,
|
|
54
|
+
"type": "boolean"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"hasDynamicHelp": false,
|
|
58
|
+
"hiddenAliases": [
|
|
59
|
+
"app:state:del",
|
|
60
|
+
"app:state:remove",
|
|
61
|
+
"app:state:rm"
|
|
62
|
+
],
|
|
63
|
+
"id": "app:state:delete",
|
|
64
|
+
"pluginAlias": "@adobe/aio-cli-plugin-app-storage",
|
|
65
|
+
"pluginName": "@adobe/aio-cli-plugin-app-storage",
|
|
66
|
+
"pluginType": "core",
|
|
67
|
+
"strict": false,
|
|
68
|
+
"enableJsonFlag": true,
|
|
69
|
+
"isESM": true,
|
|
70
|
+
"relativePath": [
|
|
71
|
+
"src",
|
|
72
|
+
"commands",
|
|
73
|
+
"app",
|
|
74
|
+
"state",
|
|
75
|
+
"delete.js"
|
|
76
|
+
]
|
|
77
|
+
},
|
|
78
|
+
"app:state:get": {
|
|
79
|
+
"aliases": [
|
|
80
|
+
"app:state:get"
|
|
81
|
+
],
|
|
82
|
+
"args": {
|
|
83
|
+
"key": {
|
|
84
|
+
"description": "State key",
|
|
85
|
+
"name": "key",
|
|
86
|
+
"required": true
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
"description": "Get a key-value",
|
|
90
|
+
"examples": [
|
|
91
|
+
"$ aio app state get key",
|
|
92
|
+
"$ aio app state get key --json",
|
|
93
|
+
"$ aio app state get key | wc -c"
|
|
94
|
+
],
|
|
95
|
+
"flags": {
|
|
96
|
+
"json": {
|
|
97
|
+
"description": "Format output as json.",
|
|
98
|
+
"helpGroup": "GLOBAL",
|
|
99
|
+
"name": "json",
|
|
100
|
+
"allowNo": false,
|
|
101
|
+
"type": "boolean"
|
|
102
|
+
},
|
|
103
|
+
"region": {
|
|
104
|
+
"description": "State region. Defaults to 'AIO_STATE_REGION' env or 'amer' if neither is set.",
|
|
105
|
+
"name": "region",
|
|
106
|
+
"required": false,
|
|
107
|
+
"hasDynamicHelp": false,
|
|
108
|
+
"multiple": false,
|
|
109
|
+
"options": [
|
|
110
|
+
"amer",
|
|
111
|
+
"emea"
|
|
112
|
+
],
|
|
113
|
+
"type": "option"
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
"hasDynamicHelp": false,
|
|
117
|
+
"hiddenAliases": [],
|
|
118
|
+
"id": "app:state:get",
|
|
119
|
+
"pluginAlias": "@adobe/aio-cli-plugin-app-storage",
|
|
120
|
+
"pluginName": "@adobe/aio-cli-plugin-app-storage",
|
|
121
|
+
"pluginType": "core",
|
|
122
|
+
"strict": true,
|
|
123
|
+
"enableJsonFlag": true,
|
|
124
|
+
"isESM": true,
|
|
125
|
+
"relativePath": [
|
|
126
|
+
"src",
|
|
127
|
+
"commands",
|
|
128
|
+
"app",
|
|
129
|
+
"state",
|
|
130
|
+
"get.js"
|
|
131
|
+
]
|
|
132
|
+
},
|
|
133
|
+
"app:state:list": {
|
|
134
|
+
"aliases": [
|
|
135
|
+
"app:state:list"
|
|
136
|
+
],
|
|
137
|
+
"args": {},
|
|
138
|
+
"description": "List key-values",
|
|
139
|
+
"examples": [
|
|
140
|
+
"$ aio app state list",
|
|
141
|
+
"$ aio app state list --match 'gl*b'",
|
|
142
|
+
"$ aio app state list --json",
|
|
143
|
+
"$ aio app state list | less",
|
|
144
|
+
"$ aio app state list | wc -l"
|
|
145
|
+
],
|
|
146
|
+
"flags": {
|
|
147
|
+
"json": {
|
|
148
|
+
"description": "Format output as json.",
|
|
149
|
+
"helpGroup": "GLOBAL",
|
|
150
|
+
"name": "json",
|
|
151
|
+
"allowNo": false,
|
|
152
|
+
"type": "boolean"
|
|
153
|
+
},
|
|
154
|
+
"region": {
|
|
155
|
+
"description": "State region. Defaults to 'AIO_STATE_REGION' env or 'amer' if neither is set.",
|
|
156
|
+
"name": "region",
|
|
157
|
+
"required": false,
|
|
158
|
+
"hasDynamicHelp": false,
|
|
159
|
+
"multiple": false,
|
|
160
|
+
"options": [
|
|
161
|
+
"amer",
|
|
162
|
+
"emea"
|
|
163
|
+
],
|
|
164
|
+
"type": "option"
|
|
165
|
+
},
|
|
166
|
+
"match": {
|
|
167
|
+
"char": "m",
|
|
168
|
+
"description": "Glob-like pattern to filter keys",
|
|
169
|
+
"name": "match",
|
|
170
|
+
"required": false,
|
|
171
|
+
"default": "*",
|
|
172
|
+
"hasDynamicHelp": false,
|
|
173
|
+
"multiple": false,
|
|
174
|
+
"type": "option"
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
"hasDynamicHelp": false,
|
|
178
|
+
"hiddenAliases": [
|
|
179
|
+
"app:state:ls"
|
|
180
|
+
],
|
|
181
|
+
"id": "app:state:list",
|
|
182
|
+
"pluginAlias": "@adobe/aio-cli-plugin-app-storage",
|
|
183
|
+
"pluginName": "@adobe/aio-cli-plugin-app-storage",
|
|
184
|
+
"pluginType": "core",
|
|
185
|
+
"strict": true,
|
|
186
|
+
"enableJsonFlag": true,
|
|
187
|
+
"isESM": true,
|
|
188
|
+
"relativePath": [
|
|
189
|
+
"src",
|
|
190
|
+
"commands",
|
|
191
|
+
"app",
|
|
192
|
+
"state",
|
|
193
|
+
"list.js"
|
|
194
|
+
]
|
|
195
|
+
},
|
|
196
|
+
"app:state:put": {
|
|
197
|
+
"aliases": [
|
|
198
|
+
"app:state:put"
|
|
199
|
+
],
|
|
200
|
+
"args": {
|
|
201
|
+
"key": {
|
|
202
|
+
"description": "State key",
|
|
203
|
+
"name": "key",
|
|
204
|
+
"required": true
|
|
205
|
+
},
|
|
206
|
+
"value": {
|
|
207
|
+
"description": "State value",
|
|
208
|
+
"name": "value",
|
|
209
|
+
"required": true
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
"description": "Put a key-value",
|
|
213
|
+
"examples": [
|
|
214
|
+
"$ aio app state put key value",
|
|
215
|
+
"$ aio app state put key value --ttl 3600",
|
|
216
|
+
"$ aio app state put key value --json",
|
|
217
|
+
"$ cat value/from/file | xargs -0 ./bin/run.js app state put key"
|
|
218
|
+
],
|
|
219
|
+
"flags": {
|
|
220
|
+
"json": {
|
|
221
|
+
"description": "Format output as json.",
|
|
222
|
+
"helpGroup": "GLOBAL",
|
|
223
|
+
"name": "json",
|
|
224
|
+
"allowNo": false,
|
|
225
|
+
"type": "boolean"
|
|
226
|
+
},
|
|
227
|
+
"region": {
|
|
228
|
+
"description": "State region. Defaults to 'AIO_STATE_REGION' env or 'amer' if neither is set.",
|
|
229
|
+
"name": "region",
|
|
230
|
+
"required": false,
|
|
231
|
+
"hasDynamicHelp": false,
|
|
232
|
+
"multiple": false,
|
|
233
|
+
"options": [
|
|
234
|
+
"amer",
|
|
235
|
+
"emea"
|
|
236
|
+
],
|
|
237
|
+
"type": "option"
|
|
238
|
+
},
|
|
239
|
+
"ttl": {
|
|
240
|
+
"char": "t",
|
|
241
|
+
"description": "Time to live in seconds. Default is 86400 (24 hours), max is 31536000 (1 year).",
|
|
242
|
+
"name": "ttl",
|
|
243
|
+
"required": false,
|
|
244
|
+
"hasDynamicHelp": false,
|
|
245
|
+
"multiple": false,
|
|
246
|
+
"type": "option"
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
"hasDynamicHelp": false,
|
|
250
|
+
"hiddenAliases": [],
|
|
251
|
+
"id": "app:state:put",
|
|
252
|
+
"pluginAlias": "@adobe/aio-cli-plugin-app-storage",
|
|
253
|
+
"pluginName": "@adobe/aio-cli-plugin-app-storage",
|
|
254
|
+
"pluginType": "core",
|
|
255
|
+
"strict": true,
|
|
256
|
+
"enableJsonFlag": true,
|
|
257
|
+
"isESM": true,
|
|
258
|
+
"relativePath": [
|
|
259
|
+
"src",
|
|
260
|
+
"commands",
|
|
261
|
+
"app",
|
|
262
|
+
"state",
|
|
263
|
+
"put.js"
|
|
264
|
+
]
|
|
265
|
+
},
|
|
266
|
+
"app:state:stats": {
|
|
267
|
+
"aliases": [
|
|
268
|
+
"app:state:stats"
|
|
269
|
+
],
|
|
270
|
+
"args": {},
|
|
271
|
+
"description": "Display stats",
|
|
272
|
+
"examples": [
|
|
273
|
+
"$ aio app state stats",
|
|
274
|
+
"$ aio app state stats --json"
|
|
275
|
+
],
|
|
276
|
+
"flags": {
|
|
277
|
+
"json": {
|
|
278
|
+
"description": "Format output as json.",
|
|
279
|
+
"helpGroup": "GLOBAL",
|
|
280
|
+
"name": "json",
|
|
281
|
+
"allowNo": false,
|
|
282
|
+
"type": "boolean"
|
|
283
|
+
},
|
|
284
|
+
"region": {
|
|
285
|
+
"description": "State region. Defaults to 'AIO_STATE_REGION' env or 'amer' if neither is set.",
|
|
286
|
+
"name": "region",
|
|
287
|
+
"required": false,
|
|
288
|
+
"hasDynamicHelp": false,
|
|
289
|
+
"multiple": false,
|
|
290
|
+
"options": [
|
|
291
|
+
"amer",
|
|
292
|
+
"emea"
|
|
293
|
+
],
|
|
294
|
+
"type": "option"
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
"hasDynamicHelp": false,
|
|
298
|
+
"hiddenAliases": [],
|
|
299
|
+
"id": "app:state:stats",
|
|
300
|
+
"pluginAlias": "@adobe/aio-cli-plugin-app-storage",
|
|
301
|
+
"pluginName": "@adobe/aio-cli-plugin-app-storage",
|
|
302
|
+
"pluginType": "core",
|
|
303
|
+
"strict": true,
|
|
304
|
+
"enableJsonFlag": true,
|
|
305
|
+
"isESM": true,
|
|
306
|
+
"relativePath": [
|
|
307
|
+
"src",
|
|
308
|
+
"commands",
|
|
309
|
+
"app",
|
|
310
|
+
"state",
|
|
311
|
+
"stats.js"
|
|
312
|
+
]
|
|
313
|
+
}
|
|
314
|
+
},
|
|
315
|
+
"version": "1.0.0"
|
|
316
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@adobe/aio-cli-plugin-app-storage",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"dependencies": {
|
|
5
|
+
"@adobe/aio-lib-core-config": "^5",
|
|
6
|
+
"@adobe/aio-lib-core-logging": "^3",
|
|
7
|
+
"@adobe/aio-lib-state": "^5",
|
|
8
|
+
"@inquirer/prompts": "^5",
|
|
9
|
+
"@oclif/core": "^4",
|
|
10
|
+
"@oclif/plugin-help": "^6",
|
|
11
|
+
"chalk": "^5"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@adobe/eslint-config-aio-lib-config": "^4",
|
|
15
|
+
"@jest/globals": "^29",
|
|
16
|
+
"eslint": "^8",
|
|
17
|
+
"execa": "^8",
|
|
18
|
+
"jest": "^29",
|
|
19
|
+
"oclif": "^4",
|
|
20
|
+
"stdout-stderr": "^0.1.9"
|
|
21
|
+
},
|
|
22
|
+
"type": "module",
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=18.0.0"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"bin/run.js",
|
|
28
|
+
"oclif.manifest.json",
|
|
29
|
+
"src"
|
|
30
|
+
],
|
|
31
|
+
"keywords": [
|
|
32
|
+
"oclif-plugin"
|
|
33
|
+
],
|
|
34
|
+
"license": "Apache-2.0",
|
|
35
|
+
"oclif": {
|
|
36
|
+
"commands": "./src/commands",
|
|
37
|
+
"topics": {
|
|
38
|
+
"app:state": {
|
|
39
|
+
"description": "Manage your App Builder State storage"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"bin": "aio",
|
|
43
|
+
"topicSeparator": " ",
|
|
44
|
+
"repositoryPrefix": "<%- repo %>/blob/<%- version %>/<%- commandPath %>",
|
|
45
|
+
"plugins": [
|
|
46
|
+
"@oclif/plugin-help"
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
"main": "src/commands/BaseCommand.js",
|
|
50
|
+
"scripts": {
|
|
51
|
+
"lint": "eslint src test e2e",
|
|
52
|
+
"unit-test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --setupFilesAfterEnv=./test/jest.setup.js --testMatch='**/*.test.js' --ci",
|
|
53
|
+
"test": "npm run unit-test && npm run lint",
|
|
54
|
+
"prepack": "oclif manifest && oclif readme --no-aliases",
|
|
55
|
+
"postpack": "rm -f oclif.manifest.json",
|
|
56
|
+
"version": "oclif readme && git add README.md",
|
|
57
|
+
"e2e": "node --experimental-vm-modules node_modules/jest/bin/jest.js --collectCoverage=false --testRegex 'e2e/e2e.js'"
|
|
58
|
+
},
|
|
59
|
+
"jest": {
|
|
60
|
+
"collectCoverage": true,
|
|
61
|
+
"testEnvironment": "node"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2024 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { Command, Flags } from '@oclif/core'
|
|
14
|
+
import config from '@adobe/aio-lib-core-config'
|
|
15
|
+
import AioLogger from '@adobe/aio-lib-core-logging'
|
|
16
|
+
|
|
17
|
+
import { CONFIG_STATE_REGION } from './constants.js'
|
|
18
|
+
import chalk from 'chalk'
|
|
19
|
+
|
|
20
|
+
export class BaseCommand extends Command {
|
|
21
|
+
async init () {
|
|
22
|
+
await super.init()
|
|
23
|
+
|
|
24
|
+
// setup debug logger
|
|
25
|
+
const command = this.constructor.name.toLowerCase() // hacky but convenient
|
|
26
|
+
this.debugLogger = AioLogger(
|
|
27
|
+
`aio:app:state:${command}`,
|
|
28
|
+
{ provider: 'debug' }
|
|
29
|
+
)
|
|
30
|
+
// override warn to stderr
|
|
31
|
+
this.warn = (msg) => process.stderr.write(chalk.yellow(`> Warning: ${msg.split('\n').join('\n> ')}\n`))
|
|
32
|
+
|
|
33
|
+
// parse flags and args
|
|
34
|
+
const { flags, args } = await this.parse(this.prototype)
|
|
35
|
+
this.flags = flags
|
|
36
|
+
this.args = args
|
|
37
|
+
this.debugLogger.debug(`${command} args=${JSON.stringify(this.args)} flags=${JSON.stringify(this.flags)}`)
|
|
38
|
+
|
|
39
|
+
// init state client
|
|
40
|
+
const owOptions = {
|
|
41
|
+
namespace: config.get('runtime.namespace'),
|
|
42
|
+
auth: config.get('runtime.auth')
|
|
43
|
+
}
|
|
44
|
+
if (!(owOptions.namespace && owOptions.auth)) {
|
|
45
|
+
this.error(
|
|
46
|
+
`This command is expected to be run in the root of a App Builder app project.
|
|
47
|
+
Please make sure the 'AIO_RUNTIME_NAMESPACE' and 'AIO_RUNTIME_AUTH' environment variables are configured.`
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
const region = flags.region || config.get(CONFIG_STATE_REGION) || 'amer'
|
|
51
|
+
this.debugLogger.info('using state region: %s', region)
|
|
52
|
+
|
|
53
|
+
if (config.get('state.endpoint')) {
|
|
54
|
+
process.env.AIO_STATE_ENDPOINT = config.get('state.endpoint')
|
|
55
|
+
this.debugLogger.info('using custom endpoint: %s', process.env.AIO_STATE_ENDPOINT)
|
|
56
|
+
}
|
|
57
|
+
// dynamic import to be able to reload the AIO_STATE_ENDPOINT var
|
|
58
|
+
// eslint-disable-next-line node/no-unsupported-features/es-syntax
|
|
59
|
+
const State = await import('@adobe/aio-lib-state')
|
|
60
|
+
|
|
61
|
+
/** @type {import('@adobe/aio-lib-state').AdobeState} */
|
|
62
|
+
this.state = await State.init({ region, ow: owOptions })
|
|
63
|
+
|
|
64
|
+
this.rtNamespace = owOptions.namespace
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async catch (error) {
|
|
68
|
+
this.debugLogger.error(error) // debug log with stack trace
|
|
69
|
+
|
|
70
|
+
if (error.message.includes('User force closed the prompt')) {
|
|
71
|
+
// CTRL +C on a prompt, do not log an error message
|
|
72
|
+
this.exit(2)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (this.flags?.json) {
|
|
76
|
+
process.stderr.write(JSON.stringify(this.toErrorJson(error.message)) + '\n')
|
|
77
|
+
this.exit(2)
|
|
78
|
+
}
|
|
79
|
+
this.error(error.message)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Set to true if you want to add the --json flag to your command.
|
|
84
|
+
// oclif will automatically suppress logs (if you use this.log, this.warn, or this.error) and
|
|
85
|
+
// display the JSON returned by the command's run method.
|
|
86
|
+
BaseCommand.enableJsonFlag = true
|
|
87
|
+
|
|
88
|
+
BaseCommand.flags = {
|
|
89
|
+
region: Flags.string({
|
|
90
|
+
description: 'State region. Defaults to \'AIO_STATE_REGION\' env or \'amer\' if neither is set.',
|
|
91
|
+
required: false,
|
|
92
|
+
options: ['amer', 'emea']
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
BaseCommand.args = {}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2024 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import chalk from 'chalk'
|
|
13
|
+
import { BaseCommand } from '../../../BaseCommand.js'
|
|
14
|
+
import { Args, Flags } from '@oclif/core'
|
|
15
|
+
|
|
16
|
+
const MAX_ARGV_NO_CONFIRM = 5
|
|
17
|
+
|
|
18
|
+
export class Delete extends BaseCommand {
|
|
19
|
+
async run () {
|
|
20
|
+
const { match, force } = this.flags
|
|
21
|
+
const { argv: keysToDelete } = await this.parse(Delete)
|
|
22
|
+
|
|
23
|
+
// eslint-disable-next-line node/no-unsupported-features/es-syntax
|
|
24
|
+
const { input } = await import('@inquirer/prompts')
|
|
25
|
+
|
|
26
|
+
if (match && keysToDelete.length) {
|
|
27
|
+
return this.error('cannot use --match with args')
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!(match || keysToDelete.length)) {
|
|
31
|
+
return this.error('please provide either keys args or --match')
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const containerExists = await this.state.any()
|
|
35
|
+
if (!containerExists) {
|
|
36
|
+
this.error(`there are no keys stored in '${this.rtNamespace}'!`)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (!force) {
|
|
40
|
+
// safeguards
|
|
41
|
+
let warning = null
|
|
42
|
+
|
|
43
|
+
if (keysToDelete.length > MAX_ARGV_NO_CONFIRM) {
|
|
44
|
+
warning = `❌ CAUTION, you specified ${keysToDelete.length} key-values to delete`
|
|
45
|
+
} else if (match) {
|
|
46
|
+
warning = ([...match].every(c => c === '*'))
|
|
47
|
+
? '❌ CAUTION, this will delete ALL key-values!'
|
|
48
|
+
: `❌ CAUTION, this will delete key-values matching the pattern '${match}'`
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (warning) {
|
|
52
|
+
process.stderr.write(chalk.red(warning) + '\n') // console.error doesn't behave nicely with jest
|
|
53
|
+
|
|
54
|
+
const res = await input(
|
|
55
|
+
{ message: `confirm deletion by typing: '${this.rtNamespace}'` },
|
|
56
|
+
// write prompt to stderr for clean --json output
|
|
57
|
+
{ output: process.stderr }
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
if (res !== this.rtNamespace) {
|
|
61
|
+
return this.error('confirmation did not match, aborted')
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let deletedKeys
|
|
67
|
+
if (keysToDelete.length) {
|
|
68
|
+
const ret = await Promise.all(keysToDelete.map(async key => {
|
|
69
|
+
const res = await this.state.delete(key)
|
|
70
|
+
return res ? 1 : 0
|
|
71
|
+
}))
|
|
72
|
+
deletedKeys = ret.reduce((sum, val) => sum + val, 0)
|
|
73
|
+
} else {
|
|
74
|
+
// ! here we go, deleting all the user's keys
|
|
75
|
+
const ret = await this.state.deleteAll({ match })
|
|
76
|
+
deletedKeys = ret.keys
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
this.log(`keys deleted: ${deletedKeys}`)
|
|
80
|
+
return { keys: deletedKeys } // --json
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
Delete.description = 'Delete key-values'
|
|
85
|
+
Delete.examples = [
|
|
86
|
+
'$ aio app state delete key',
|
|
87
|
+
'$ aio app state delete key1 key2 key3',
|
|
88
|
+
'$ aio app state delete --match \'gl*b\'',
|
|
89
|
+
'$ aio app state delete --match \'gl*b\' --json',
|
|
90
|
+
'$ aio app state delete --match \'be-carreful*\' --force'
|
|
91
|
+
]
|
|
92
|
+
|
|
93
|
+
Delete.strict = false // allow for multiple args
|
|
94
|
+
Delete.args = {
|
|
95
|
+
keys: Args.string({
|
|
96
|
+
name: 'keys',
|
|
97
|
+
description: `keys to delete. Above ${MAX_ARGV_NO_CONFIRM} keys, you will be prompted for confirmation`,
|
|
98
|
+
required: false
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
Delete.flags = {
|
|
103
|
+
...BaseCommand.flags,
|
|
104
|
+
match: Flags.string({
|
|
105
|
+
description: '[use with caution!] deletes ALL key-values matching the provided glob-like pattern',
|
|
106
|
+
required: false
|
|
107
|
+
}),
|
|
108
|
+
force: Flags.boolean({
|
|
109
|
+
description: '[use with caution!] force delete, no safety prompt',
|
|
110
|
+
default: false
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
Delete.aliases = [
|
|
115
|
+
'app:state:delete'
|
|
116
|
+
]
|
|
117
|
+
|
|
118
|
+
Delete.hiddenAliases = [
|
|
119
|
+
'app:state:del',
|
|
120
|
+
'app:state:remove',
|
|
121
|
+
'app:state:rm'
|
|
122
|
+
]
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2024 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import chalk from 'chalk'
|
|
13
|
+
import { BaseCommand } from '../../../BaseCommand.js'
|
|
14
|
+
import { Args } from '@oclif/core'
|
|
15
|
+
|
|
16
|
+
export class Get extends BaseCommand {
|
|
17
|
+
async run () {
|
|
18
|
+
const ret = await this.state.get(this.args.key)
|
|
19
|
+
|
|
20
|
+
if (!ret) {
|
|
21
|
+
// and not value = key does not exist
|
|
22
|
+
this.error('key does not exist')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const { value, expiration } = ret
|
|
26
|
+
|
|
27
|
+
if (!this.flags.json) {
|
|
28
|
+
// we write ONLY the value to stdout for pipe-ability (no new line)
|
|
29
|
+
process.stdout.write(value)
|
|
30
|
+
// the rest goes to stderr
|
|
31
|
+
process.stderr.write(chalk.dim(`\n> expiration: ${(new Date(expiration)).toLocaleString()} (local time)\n`))
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return { value, expiration } // --json { value, expiration UTC }
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
Get.description = 'Get a key-value'
|
|
39
|
+
Get.examples = [
|
|
40
|
+
'$ aio app state get key',
|
|
41
|
+
'$ aio app state get key --json',
|
|
42
|
+
'$ aio app state get key | wc -c'
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
Get.args = {
|
|
46
|
+
key: Args.string({
|
|
47
|
+
name: 'key',
|
|
48
|
+
description: 'State key',
|
|
49
|
+
required: true
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
Get.aliases = [
|
|
54
|
+
'app:state:get'
|
|
55
|
+
]
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2024 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { BaseCommand } from '../../../BaseCommand.js'
|
|
13
|
+
import { Flags } from '@oclif/core'
|
|
14
|
+
import chalk from 'chalk'
|
|
15
|
+
|
|
16
|
+
const MAX_KEYS = 5000
|
|
17
|
+
const COUNT_HINT = 500 // per iteration
|
|
18
|
+
|
|
19
|
+
export class List extends BaseCommand {
|
|
20
|
+
async run () {
|
|
21
|
+
const allKeys = []
|
|
22
|
+
|
|
23
|
+
const { match } = this.flags
|
|
24
|
+
|
|
25
|
+
let truncatedKeys = null
|
|
26
|
+
for await (const { keys } of this.state.list({ match, countHint: COUNT_HINT })) {
|
|
27
|
+
if (keys.length + allKeys.length > MAX_KEYS) {
|
|
28
|
+
truncatedKeys = keys.slice(0, MAX_KEYS - allKeys.length)
|
|
29
|
+
break
|
|
30
|
+
}
|
|
31
|
+
allKeys.push(...keys)
|
|
32
|
+
this.logKeys(keys)
|
|
33
|
+
}
|
|
34
|
+
if (truncatedKeys) {
|
|
35
|
+
allKeys.push(...truncatedKeys)
|
|
36
|
+
this.logKeys(truncatedKeys)
|
|
37
|
+
this.warn(chalk.yellow(`Too many keys found, only the first ${MAX_KEYS} keys are displayed\nUse --match to filter keys`))
|
|
38
|
+
}
|
|
39
|
+
return allKeys // --json
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
logKeys (keys) {
|
|
43
|
+
// do not log unnecessary new lines
|
|
44
|
+
keys.length && this.log(keys.join('\n'))
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
List.description = 'List key-values'
|
|
49
|
+
List.examples = [
|
|
50
|
+
'$ aio app state list',
|
|
51
|
+
'$ aio app state list --match \'gl*b\'',
|
|
52
|
+
'$ aio app state list --json',
|
|
53
|
+
'$ aio app state list | less',
|
|
54
|
+
'$ aio app state list | wc -l'
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
List.flags = {
|
|
58
|
+
...BaseCommand.flags,
|
|
59
|
+
match: Flags.string({
|
|
60
|
+
name: 'match',
|
|
61
|
+
char: 'm',
|
|
62
|
+
description: 'Glob-like pattern to filter keys',
|
|
63
|
+
required: false,
|
|
64
|
+
default: '*'
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
List.aliases = [
|
|
69
|
+
'app:state:list'
|
|
70
|
+
]
|
|
71
|
+
// do not show in help
|
|
72
|
+
List.hiddenAliases = [
|
|
73
|
+
'app:state:ls'
|
|
74
|
+
]
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2024 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { BaseCommand } from '../../../BaseCommand.js'
|
|
13
|
+
import { Args, Flags } from '@oclif/core'
|
|
14
|
+
import { DEFAULT_TTL_SECONDS } from '../../../constants.js'
|
|
15
|
+
import chalk from 'chalk'
|
|
16
|
+
|
|
17
|
+
export class Put extends BaseCommand {
|
|
18
|
+
async run () {
|
|
19
|
+
const { key, value } = this.args
|
|
20
|
+
const { json, ttl } = this.flags
|
|
21
|
+
await this.state.put(key, value, { ttl })
|
|
22
|
+
|
|
23
|
+
const bytesValue = Buffer.from(value).length
|
|
24
|
+
const expirationDate = new Date(Date.now() + (ttl || DEFAULT_TTL_SECONDS) * 1000)
|
|
25
|
+
if (!json) {
|
|
26
|
+
process.stdout.write(key)
|
|
27
|
+
// stderr, be consistent with GET
|
|
28
|
+
process.stderr.write(chalk.dim(`\n> expiration: ${new Date(expirationDate).toLocaleString()} (local time)\n`))
|
|
29
|
+
process.stderr.write(chalk.dim(`> bytes value: ${bytesValue}\n`))
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return { key, bytesValue, expiration: expirationDate.toISOString() } // --json
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
Put.description = 'Put a key-value'
|
|
37
|
+
Put.examples = [
|
|
38
|
+
'$ aio app state put key value',
|
|
39
|
+
'$ aio app state put key value --ttl 3600',
|
|
40
|
+
'$ aio app state put key value --json',
|
|
41
|
+
'$ cat value/from/file | xargs -0 ./bin/run.js app state put key'
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
Put.args = {
|
|
45
|
+
key: Args.string({
|
|
46
|
+
name: 'key',
|
|
47
|
+
description: 'State key',
|
|
48
|
+
required: true
|
|
49
|
+
}),
|
|
50
|
+
value: Args.string({
|
|
51
|
+
name: 'value',
|
|
52
|
+
description: 'State value',
|
|
53
|
+
required: true
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
Put.flags = {
|
|
58
|
+
...BaseCommand.flags,
|
|
59
|
+
ttl: Flags.integer({
|
|
60
|
+
char: 't',
|
|
61
|
+
description: 'Time to live in seconds. Default is 86400 (24 hours), max is 31536000 (1 year).',
|
|
62
|
+
required: false
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
Put.aliases = [
|
|
67
|
+
'app:state:put'
|
|
68
|
+
]
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2024 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { BaseCommand } from '../../../BaseCommand.js'
|
|
13
|
+
|
|
14
|
+
export class Stats extends BaseCommand {
|
|
15
|
+
async run () {
|
|
16
|
+
const ret = await this.state.stats()
|
|
17
|
+
this.log(
|
|
18
|
+
`stored in '${this.rtNamespace}'
|
|
19
|
+
keys: ${ret.keys}
|
|
20
|
+
bytes keys: ${ret.bytesKeys}
|
|
21
|
+
bytes values: ${ret.bytesValues}`
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
return ret // --json
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
Stats.description = 'Display stats'
|
|
29
|
+
Stats.examples = [
|
|
30
|
+
'$ aio app state stats',
|
|
31
|
+
'$ aio app state stats --json'
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
Stats.aliases = [
|
|
35
|
+
'app:state:stats'
|
|
36
|
+
]
|
package/src/constants.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2024 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// state.region is a new configuration (env=AIO_STATE_REGION)
|
|
14
|
+
export const CONFIG_STATE_REGION = 'state.region'
|
|
15
|
+
|
|
16
|
+
export const DEFAULT_TTL_SECONDS = 60 * 60 * 24 // 24 hours
|