appwrite-cli 4.2.0 → 4.2.2

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.
@@ -9,130 +9,199 @@ const { Command } = require('commander');
9
9
  const { sdkForProject, sdkForConsole } = require('../sdks')
10
10
  const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser')
11
11
  const { localConfig, globalConfig } = require("../config");
12
+ const { File } = require('undici');
13
+ const { ReadableStream } = require('stream/web');
14
+
15
+ /**
16
+ * @param {fs.ReadStream} readStream
17
+ * @returns {ReadableStream}
18
+ */
19
+ function convertReadStreamToReadableStream(readStream) {
20
+ return new ReadableStream({
21
+ start(controller) {
22
+ readStream.on("data", (chunk) => {
23
+ controller.enqueue(chunk);
24
+ });
25
+ readStream.on("end", () => {
26
+ controller.close();
27
+ });
28
+ readStream.on("error", (err) => {
29
+ controller.error(err);
30
+ });
31
+ },
32
+ cancel() {
33
+ readStream.destroy();
34
+ },
35
+ });
36
+ }
12
37
 
13
38
  const proxy = new Command("proxy").description(commandDescriptions['proxy']).configureHelp({
14
39
  helpWidth: process.stdout.columns || 80
15
- })
16
-
40
+ })
41
+
42
+ /**
43
+ * @typedef {Object} ProxyListRulesRequestParams
44
+ * @property {string[]} queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: domain, resourceType, resourceId, url
45
+ * @property {string} search Search term to filter your list results. Max length: 256 chars.
46
+ * @property {boolean} parseOutput
47
+ * @property {libClient | undefined} sdk
48
+ */
49
+
50
+ /**
51
+ * @param {ProxyListRulesRequestParams} params
52
+ */
17
53
  const proxyListRules = async ({ queries, search, parseOutput = true, sdk = undefined}) => {
18
- /* @param {string[]} queries */
19
- /* @param {string} search */
20
-
21
54
  let client = !sdk ? await sdkForProject() : sdk;
22
55
  let apiPath = '/proxy/rules';
23
56
  let payload = {};
24
-
25
- /** Query Params */
26
57
  if (typeof queries !== 'undefined') {
27
58
  payload['queries'] = queries;
28
59
  }
29
60
  if (typeof search !== 'undefined') {
30
61
  payload['search'] = search;
31
62
  }
63
+
32
64
  let response = undefined;
65
+
33
66
  response = await client.call('get', apiPath, {
34
67
  'content-type': 'application/json',
35
68
  }, payload);
36
-
69
+
37
70
  if (parseOutput) {
38
71
  parse(response)
39
72
  success()
40
73
  }
74
+
41
75
  return response;
42
76
  }
43
77
 
78
+ /**
79
+ * @typedef {Object} ProxyCreateRuleRequestParams
80
+ * @property {string} domain Domain name.
81
+ * @property {string} resourceType Action definition for the rule. Possible values are "api", "function"
82
+ * @property {string} resourceId ID of resource for the action type. If resourceType is "api", leave empty. If resourceType is "function", provide ID of the function.
83
+ * @property {boolean} parseOutput
84
+ * @property {libClient | undefined} sdk
85
+ */
86
+
87
+ /**
88
+ * @param {ProxyCreateRuleRequestParams} params
89
+ */
44
90
  const proxyCreateRule = async ({ domain, resourceType, resourceId, parseOutput = true, sdk = undefined}) => {
45
- /* @param {string} domain */
46
- /* @param {string} resourceType */
47
- /* @param {string} resourceId */
48
-
49
91
  let client = !sdk ? await sdkForProject() : sdk;
50
92
  let apiPath = '/proxy/rules';
51
93
  let payload = {};
52
-
53
- /** Body Params */
54
-
55
94
  if (typeof domain !== 'undefined') {
56
95
  payload['domain'] = domain;
57
96
  }
58
-
59
-
60
97
  if (typeof resourceType !== 'undefined') {
61
98
  payload['resourceType'] = resourceType;
62
99
  }
63
-
64
-
65
100
  if (typeof resourceId !== 'undefined') {
66
101
  payload['resourceId'] = resourceId;
67
102
  }
68
103
 
69
104
  let response = undefined;
105
+
70
106
  response = await client.call('post', apiPath, {
71
107
  'content-type': 'application/json',
72
108
  }, payload);
73
-
109
+
74
110
  if (parseOutput) {
75
111
  parse(response)
76
112
  success()
77
113
  }
114
+
78
115
  return response;
79
116
  }
80
117
 
81
- const proxyGetRule = async ({ ruleId, parseOutput = true, sdk = undefined}) => {
82
- /* @param {string} ruleId */
118
+ /**
119
+ * @typedef {Object} ProxyGetRuleRequestParams
120
+ * @property {string} ruleId Rule ID.
121
+ * @property {boolean} parseOutput
122
+ * @property {libClient | undefined} sdk
123
+ */
83
124
 
125
+ /**
126
+ * @param {ProxyGetRuleRequestParams} params
127
+ */
128
+ const proxyGetRule = async ({ ruleId, parseOutput = true, sdk = undefined}) => {
84
129
  let client = !sdk ? await sdkForProject() : sdk;
85
130
  let apiPath = '/proxy/rules/{ruleId}'.replace('{ruleId}', ruleId);
86
131
  let payload = {};
132
+
87
133
  let response = undefined;
134
+
88
135
  response = await client.call('get', apiPath, {
89
136
  'content-type': 'application/json',
90
137
  }, payload);
91
-
138
+
92
139
  if (parseOutput) {
93
140
  parse(response)
94
141
  success()
95
142
  }
143
+
96
144
  return response;
97
145
  }
98
146
 
99
- const proxyDeleteRule = async ({ ruleId, parseOutput = true, sdk = undefined}) => {
100
- /* @param {string} ruleId */
147
+ /**
148
+ * @typedef {Object} ProxyDeleteRuleRequestParams
149
+ * @property {string} ruleId Rule ID.
150
+ * @property {boolean} parseOutput
151
+ * @property {libClient | undefined} sdk
152
+ */
101
153
 
154
+ /**
155
+ * @param {ProxyDeleteRuleRequestParams} params
156
+ */
157
+ const proxyDeleteRule = async ({ ruleId, parseOutput = true, sdk = undefined}) => {
102
158
  let client = !sdk ? await sdkForProject() : sdk;
103
159
  let apiPath = '/proxy/rules/{ruleId}'.replace('{ruleId}', ruleId);
104
160
  let payload = {};
161
+
105
162
  let response = undefined;
163
+
106
164
  response = await client.call('delete', apiPath, {
107
165
  'content-type': 'application/json',
108
166
  }, payload);
109
-
167
+
110
168
  if (parseOutput) {
111
169
  parse(response)
112
170
  success()
113
171
  }
172
+
114
173
  return response;
115
174
  }
116
175
 
117
- const proxyUpdateRuleVerification = async ({ ruleId, parseOutput = true, sdk = undefined}) => {
118
- /* @param {string} ruleId */
176
+ /**
177
+ * @typedef {Object} ProxyUpdateRuleVerificationRequestParams
178
+ * @property {string} ruleId Rule ID.
179
+ * @property {boolean} parseOutput
180
+ * @property {libClient | undefined} sdk
181
+ */
119
182
 
183
+ /**
184
+ * @param {ProxyUpdateRuleVerificationRequestParams} params
185
+ */
186
+ const proxyUpdateRuleVerification = async ({ ruleId, parseOutput = true, sdk = undefined}) => {
120
187
  let client = !sdk ? await sdkForProject() : sdk;
121
188
  let apiPath = '/proxy/rules/{ruleId}/verification'.replace('{ruleId}', ruleId);
122
189
  let payload = {};
190
+
123
191
  let response = undefined;
192
+
124
193
  response = await client.call('patch', apiPath, {
125
194
  'content-type': 'application/json',
126
195
  }, payload);
127
-
196
+
128
197
  if (parseOutput) {
129
198
  parse(response)
130
199
  success()
131
200
  }
201
+
132
202
  return response;
133
203
  }
134
204
 
135
-
136
205
  proxy
137
206
  .command(`listRules`)
138
207
  .description(`Get a list of all the proxy rules. You can use the query params to filter your results.`)
@@ -166,7 +235,6 @@ proxy
166
235
  .requiredOption(`--ruleId <ruleId>`, `Rule ID.`)
167
236
  .action(actionRunner(proxyUpdateRuleVerification))
168
237
 
169
-
170
238
  module.exports = {
171
239
  proxy,
172
240
  proxyListRules,
@@ -174,4 +242,4 @@ module.exports = {
174
242
  proxyGetRule,
175
243
  proxyDeleteRule,
176
244
  proxyUpdateRuleVerification
177
- };
245
+ };