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.
@@ -118,7 +118,6 @@ const client = new Command("client")
118
118
  success()
119
119
  }));
120
120
 
121
-
122
121
  module.exports = {
123
122
  login,
124
123
  logout,
@@ -9,62 +9,102 @@ 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 graphql = new Command("graphql").description(commandDescriptions['graphql']).configureHelp({
14
39
  helpWidth: process.stdout.columns || 80
15
- })
40
+ })
16
41
 
17
- const graphqlQuery = async ({ query, parseOutput = true, sdk = undefined}) => {
18
- /* @param {object} query */
42
+ /**
43
+ * @typedef {Object} GraphqlQueryRequestParams
44
+ * @property {object} query The query or queries to execute.
45
+ * @property {boolean} parseOutput
46
+ * @property {libClient | undefined} sdk
47
+ */
19
48
 
49
+ /**
50
+ * @param {GraphqlQueryRequestParams} params
51
+ */
52
+ const graphqlQuery = async ({ query, parseOutput = true, sdk = undefined}) => {
20
53
  let client = !sdk ? await sdkForProject() : sdk;
21
54
  let apiPath = '/graphql';
22
55
  let payload = {};
23
-
24
- /** Body Params */
25
56
  if (typeof query !== 'undefined') {
26
57
  payload['query'] = JSON.parse(query);
27
58
  }
28
59
 
29
60
  let response = undefined;
61
+
30
62
  response = await client.call('post', apiPath, {
31
63
  'x-sdk-graphql': 'true',
32
64
  'content-type': 'application/json',
33
65
  }, payload);
34
-
66
+
35
67
  if (parseOutput) {
36
68
  parse(response)
37
69
  success()
38
70
  }
71
+
39
72
  return response;
40
73
  }
41
74
 
42
- const graphqlMutation = async ({ query, parseOutput = true, sdk = undefined}) => {
43
- /* @param {object} query */
75
+ /**
76
+ * @typedef {Object} GraphqlMutationRequestParams
77
+ * @property {object} query The query or queries to execute.
78
+ * @property {boolean} parseOutput
79
+ * @property {libClient | undefined} sdk
80
+ */
44
81
 
82
+ /**
83
+ * @param {GraphqlMutationRequestParams} params
84
+ */
85
+ const graphqlMutation = async ({ query, parseOutput = true, sdk = undefined}) => {
45
86
  let client = !sdk ? await sdkForProject() : sdk;
46
87
  let apiPath = '/graphql/mutation';
47
88
  let payload = {};
48
-
49
- /** Body Params */
50
89
  if (typeof query !== 'undefined') {
51
90
  payload['query'] = JSON.parse(query);
52
91
  }
53
92
 
54
93
  let response = undefined;
94
+
55
95
  response = await client.call('post', apiPath, {
56
96
  'x-sdk-graphql': 'true',
57
97
  'content-type': 'application/json',
58
98
  }, payload);
59
-
99
+
60
100
  if (parseOutput) {
61
101
  parse(response)
62
102
  success()
63
103
  }
104
+
64
105
  return response;
65
106
  }
66
107
 
67
-
68
108
  graphql
69
109
  .command(`query`)
70
110
  .description(`Execute a GraphQL mutation.`)
@@ -77,9 +117,8 @@ graphql
77
117
  .requiredOption(`--query <query>`, `The query or queries to execute.`)
78
118
  .action(actionRunner(graphqlMutation))
79
119
 
80
-
81
120
  module.exports = {
82
121
  graphql,
83
122
  graphqlQuery,
84
123
  graphqlMutation
85
- };
124
+ };