appwrite-cli 4.2.0 → 4.2.1

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,58 +9,105 @@ 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;
54
+
21
55
  let apiPath = '/graphql';
22
56
  let payload = {};
23
-
24
- /** Body Params */
25
57
  if (typeof query !== 'undefined') {
26
58
  payload['query'] = JSON.parse(query);
27
59
  }
28
60
 
61
+
29
62
  let response = undefined;
63
+
30
64
  response = await client.call('post', apiPath, {
31
65
  'x-sdk-graphql': 'true',
32
66
  'content-type': 'application/json',
33
67
  }, payload);
68
+
34
69
 
35
70
  if (parseOutput) {
36
71
  parse(response)
37
72
  success()
38
73
  }
74
+
39
75
  return response;
40
76
  }
41
77
 
42
- const graphqlMutation = async ({ query, parseOutput = true, sdk = undefined}) => {
43
- /* @param {object} query */
78
+ /**
79
+ * @typedef {Object} GraphqlMutationRequestParams
80
+ * @property {object} query The query or queries to execute.
81
+ * @property {boolean} parseOutput
82
+ * @property {libClient | undefined} sdk
83
+ */
44
84
 
85
+ /**
86
+ * @param {GraphqlMutationRequestParams} params
87
+ */
88
+ const graphqlMutation = async ({ query, parseOutput = true, sdk = undefined}) => {
45
89
  let client = !sdk ? await sdkForProject() : sdk;
90
+
46
91
  let apiPath = '/graphql/mutation';
47
92
  let payload = {};
48
-
49
- /** Body Params */
50
93
  if (typeof query !== 'undefined') {
51
94
  payload['query'] = JSON.parse(query);
52
95
  }
53
96
 
97
+
54
98
  let response = undefined;
99
+
55
100
  response = await client.call('post', apiPath, {
56
101
  'x-sdk-graphql': 'true',
57
102
  'content-type': 'application/json',
58
103
  }, payload);
104
+
59
105
 
60
106
  if (parseOutput) {
61
107
  parse(response)
62
108
  success()
63
109
  }
110
+
64
111
  return response;
65
112
  }
66
113
 
@@ -80,6 +127,6 @@ graphql
80
127
 
81
128
  module.exports = {
82
129
  graphql,
83
- graphqlQuery,
84
- graphqlMutation
85
- };
130
+ graphqlQuery,
131
+ graphqlMutation
132
+ };