Skip to content

Commit 9fc5b59

Browse files
committed
Merge remote-tracking branch 'origin/master' into fix-flutter-realtime-multisub
2 parents c0cb91b + 9e23c22 commit 9fc5b59

File tree

9 files changed

+180
-141
lines changed

9 files changed

+180
-141
lines changed

composer.lock

Lines changed: 78 additions & 77 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/cli/lib/commands/command.js.twig

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,6 @@ const {{ service.name | caseLower }}{{ method.name | caseUcfirst }} = async ({ {
136136

137137
} else {
138138
const streamFilePath = payload['{{ parameter.name }}'];
139-
let id = undefined;
140-
141-
let counter = 0;
142-
const totalCounters = Math.ceil(size / libClient.CHUNK_SIZE);
143139

144140
const apiHeaders = {
145141
{% for parameter in method.parameters.header %}
@@ -150,49 +146,44 @@ const {{ service.name | caseLower }}{{ method.name | caseUcfirst }} = async ({ {
150146
{% endfor %}
151147
};
152148

149+
let offset = 0;
153150
{% for parameter in method.parameters.all %}
154151
{% if parameter.isUploadID %}
155152
if({{ parameter.name | caseCamel | escapeKeyword }} != 'unique()') {
156153
try {
157154
response = await client.call('get', apiPath + '/' + {{ parameter.name }}, apiHeaders);
158-
counter = response.chunksUploaded;
155+
offset = response.chunksUploaded * libClient.CHUNK_SIZE;
159156
} catch(e) {
160157
}
161158
}
162159
{% endif %}
163160
{% endfor %}
164161

165-
for (counter; counter < totalCounters; counter++) {
166-
const start = (counter * libClient.CHUNK_SIZE);
167-
const end = Math.min((((counter * libClient.CHUNK_SIZE) + libClient.CHUNK_SIZE) - 1), size - 1);
168-
169-
apiHeaders['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
162+
while (offset < size) {
163+
let end = Math.min(offset + libClient.CHUNK_SIZE - 1, size - 1);
170164

171-
if (id) {
172-
apiHeaders['x-appwrite-id'] = id;
165+
apiHeaders['content-range'] = 'bytes ' + offset + '-' + end + '/' + size;
166+
if (response && response.$id) {
167+
apiHeaders['x-{{spec.title | caseLower }}-id'] = response.$id;
173168
}
174169

175170
const stream = fs.createReadStream(streamFilePath, {
176-
start,
171+
start: offset,
177172
end
178173
});
179174
payload['{{ parameter.name }}'] = stream;
180-
181175
response = await client.call('{{ method.method | caseLower }}', apiPath, apiHeaders, payload{% if method.type == 'location' %}, 'arraybuffer'{% endif %});
182176

183-
if (!id) {
184-
id = response['$id'];
185-
}
186-
187-
if (onProgress !== null) {
177+
if (onProgress) {
188178
onProgress({
189-
$id: response['$id'],
190-
progress: Math.min((counter+1) * libClient.CHUNK_SIZE, size) / size * 100,
191-
sizeUploaded: end+1,
192-
chunksTotal: response['chunksTotal'],
193-
chunksUploaded: response['chunksUploaded']
179+
$id: response.$id,
180+
progress: ( offset / size ) * 100,
181+
sizeUploaded: offset,
182+
chunksTotal: response.chunksTotal,
183+
chunksUploaded: response.chunksUploaded
194184
});
195185
}
186+
offset += libClient.CHUNK_SIZE;
196187
}
197188
}
198189
{% endif %}

templates/cli/lib/commands/deploy.js.twig

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,14 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
206206
functionId: func['$id'],
207207
name: func.name,
208208
execute: func.execute,
209-
vars: JSON.stringify(response.vars),
210209
events: func.events,
211210
schedule: func.schedule,
212211
timeout: func.timeout,
212+
enabled: func.enabled,
213+
logging: func.logging,
214+
entrypoint: func.entrypoint,
215+
commands: func.commands,
216+
vars: JSON.stringify(response.vars),
213217
parseOutput: false
214218
});
215219
} catch (e) {
@@ -220,10 +224,14 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
220224
name: func.name,
221225
runtime: func.runtime,
222226
execute: func.execute,
223-
vars: JSON.stringify(func.vars),
224227
events: func.events,
225228
schedule: func.schedule,
226229
timeout: func.timeout,
230+
enabled: func.enabled,
231+
logging: func.logging,
232+
entrypoint: func.entrypoint,
233+
commands: func.commands,
234+
vars: JSON.stringify(func.vars),
227235
parseOutput: false
228236
});
229237

@@ -292,6 +300,7 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
292300
response = await functionsCreateDeployment({
293301
functionId: func['$id'],
294302
entrypoint: func.entrypoint,
303+
commands: func.commands,
295304
code: func.path,
296305
activate: true,
297306
parseOutput: false

templates/cli/lib/commands/init.js.twig

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,16 @@ const initFunction = async () => {
7272
log(`Entrypoint for this runtime not found. You will be asked to configure entrypoint when you first deploy the function.`);
7373
}
7474

75+
if (!answers.runtime.commands) {
76+
log(`Installation command for this runtime not found. You will be asked to configure the install command when you first deploy the function.`);
77+
}
78+
7579
let response = await functionsCreate({
7680
functionId: answers.id,
7781
name: answers.name,
7882
runtime: answers.runtime.id,
83+
entrypoint: answers.runtime.entrypoint || '',
84+
commands: answers.runtime.commands || '',
7985
parseOutput: false
8086
})
8187

@@ -138,13 +144,16 @@ const initFunction = async () => {
138144
$id: response['$id'],
139145
name: response.name,
140146
runtime: response.runtime,
141-
path: `functions/${answers.name}`,
142-
entrypoint: answers.runtime.entrypoint || '',
143-
ignore: answers.runtime.ignore || null,
144147
execute: response.execute,
145148
events: response.events,
146149
schedule: response.schedule,
147150
timeout: response.timeout,
151+
enabled: response.enabled,
152+
logging: response.logging,
153+
entrypoint: response.entrypoint,
154+
commands: response.commands,
155+
ignore: answers.runtime.ignore || null,
156+
path: `functions/${answers.name}`,
148157
};
149158

150159
localConfig.addFunction(data);

templates/cli/lib/questions.js.twig

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,57 @@ const getEntrypoint = (runtime) => {
4343
case 'dart':
4444
return 'lib/main.dart';
4545
case 'deno':
46-
return 'src/mod.ts';
46+
return 'src/main.ts';
4747
case 'node':
48-
return 'src/index.js';
48+
return 'src/main.js';
4949
case 'php':
5050
return 'src/index.php';
5151
case 'python':
52-
return 'src/index.py';
52+
return 'src/main.py';
5353
case 'ruby':
54-
return 'src/index.rb';
54+
return 'lib/main.rb';
5555
case 'rust':
5656
return 'main.rs';
5757
case 'swift':
58-
return 'Sources/swift-5.5/main.swift';
58+
return 'Sources/index.swift';
5959
case 'cpp':
60-
return 'src/index.cc';
60+
return 'src/main.cc';
6161
case 'dotnet':
6262
return 'src/Index.cs';
6363
case 'java':
64-
return 'src/Index.java';
64+
return 'src/Main.java';
6565
case 'kotlin':
66-
return 'src/Index.kt';
66+
return 'src/Main.kt';
67+
}
68+
69+
return undefined;
70+
};
71+
72+
const getInstallCommand = (runtime) => {
73+
const languge = runtime.split('-')[0];
74+
75+
switch (languge) {
76+
case 'dart':
77+
return 'dart pub get';
78+
case 'deno':
79+
return "deno install";
80+
case 'node':
81+
return 'npm install';
82+
case 'php':
83+
return 'composer install';
84+
case 'python':
85+
return 'pip install -r requirements.txt';
86+
case 'ruby':
87+
return 'bundle install';
88+
case 'rust':
89+
return 'cargo install';
90+
case 'dotnet':
91+
return 'dotnet restore';
92+
case 'swift':
93+
case 'java':
94+
case 'kotlin':
95+
case 'cpp':
96+
return '';
6797
}
6898

6999
return undefined;
@@ -171,10 +201,15 @@ const questionsInitFunction = [
171201
parseOutput: false
172202
})
173203
let runtimes = response["runtimes"]
174-
let choices = runtimes.map((runtime, idx) => {
204+
let choices = runtimes.map((runtime, idx) => {
175205
return {
176206
name: `${runtime.name} (${runtime['$id']})`,
177-
value: { id: runtime['$id'], entrypoint: getEntrypoint(runtime['$id']), ignore: getIgnores(runtime['$id']) },
207+
value: {
208+
id: runtime['$id'],
209+
entrypoint: getEntrypoint(runtime['$id']),
210+
ignore: getIgnores(runtime['$id']),
211+
commands : getInstallCommand(runtime['$id'])
212+
},
178213
}
179214
})
180215
return choices;

templates/cli/package.json.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"windows-arm64": "pkg -t node16-win-arm64 -o build/appwrite-cli-win-arm64.exe package.json"
2323
},
2424
"dependencies": {
25-
"axios": "^0.27.2",
25+
"axios": "1.5.0",
2626
"chalk": "4.1.2",
2727
"cli-table3": "^0.6.2",
2828
"commander": "^9.2.0",

templates/web/src/services/template.ts.twig

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ export class {{ service.name | caseUcfirst }} extends Service {
8585

8686
if (size <= Service.CHUNK_SIZE) {
8787
return await this.client.call('{{ method.method | caseLower }}', uri, {
88-
8988
{% for parameter in method.parameters.header %}
9089
'{{ parameter.name | caseCamel | escapeKeyword }}': this.client.${{ parameter.name | caseCamel | escapeKeyword }},
9190
{% endfor %}
@@ -94,8 +93,6 @@ export class {{ service.name | caseUcfirst }} extends Service {
9493
{% endfor %}
9594
}, payload);
9695
}
97-
let id = undefined;
98-
let response = undefined;
9996

10097
const apiHeaders: { [header: string]: string } = {
10198
{% for parameter in method.parameters.header %}
@@ -106,50 +103,43 @@ export class {{ service.name | caseUcfirst }} extends Service {
106103
{% endfor %}
107104
}
108105

109-
let counter = 0;
110-
const totalCounters = Math.ceil(size / Service.CHUNK_SIZE);
106+
let offset = 0;
107+
let response = undefined;
111108
{% for parameter in method.parameters.all %}
112109
{% if parameter.isUploadID %}
113110
if({{ parameter.name | caseCamel | escapeKeyword }} != 'unique()') {
114111
try {
115112
response = await this.client.call('GET', new URL(this.client.config.endpoint + apiPath + '/' + {{ parameter.name }}), apiHeaders);
116-
counter = response.chunksUploaded;
113+
offset = response.chunksUploaded * Service.CHUNK_SIZE;
117114
} catch(e) {
118115
}
119116
}
120117
{% endif %}
121118
{% endfor %}
122119

123-
for (counter; counter < totalCounters; counter++) {
124-
const start = (counter * Service.CHUNK_SIZE);
125-
const end = Math.min((((counter * Service.CHUNK_SIZE) + Service.CHUNK_SIZE) - 1), size);
126-
127-
apiHeaders['content-range'] = 'bytes ' + start + '-' + end + '/' + size
120+
while (offset < size) {
121+
let end = Math.min(offset + Service.CHUNK_SIZE - 1, size - 1);
128122

129-
if (id) {
130-
apiHeaders['x-{{spec.title | caseLower }}-id'] = id;
123+
apiHeaders['content-range'] = 'bytes ' + offset + '-' + end + '/' + size;
124+
if (response && response.$id) {
125+
apiHeaders['x-{{spec.title | caseLower }}-id'] = response.$id;
131126
}
132127

133-
const stream = {{ parameter.name | caseCamel | escapeKeyword }}.slice(start, end + 1);
134-
payload['{{ parameter.name }}'] = new File([stream], {{ parameter.name | caseCamel | escapeKeyword }}.name);
135-
128+
const chunk = {{ parameter.name | caseCamel | escapeKeyword }}.slice(offset, end + 1);
129+
payload['{{ parameter.name }}'] = new File([chunk], {{ parameter.name | caseCamel | escapeKeyword }}.name);
136130
response = await this.client.call('{{ method.method | caseLower }}', uri, apiHeaders, payload);
137131

138-
if (!id) {
139-
id = response['$id'];
140-
}
141-
142132
if (onProgress) {
143133
onProgress({
144134
$id: response.$id,
145-
progress: Math.min((counter + 1) * Service.CHUNK_SIZE, size) / size * 100,
146-
sizeUploaded: end,
135+
progress: (offset / size) * 100,
136+
sizeUploaded: offset,
147137
chunksTotal: response.chunksTotal,
148138
chunksUploaded: response.chunksUploaded
149139
});
150140
}
141+
offset += Service.CHUNK_SIZE;
151142
}
152-
153143
return response;
154144
{% endif %}
155145
{% endfor %}

tests/Base.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ abstract class Base extends TestCase
106106
protected array $build = [];
107107
protected string $command = '';
108108
protected array $expectedOutput = [];
109+
protected string $sdkName;
110+
protected string $sdkPlatform;
111+
protected string $sdkLanguage;
112+
protected string $version;
109113

110114
public function setUp(): void
111115
{

tests/languages/cli/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { exec, execSync } = require('child_process');
22

3-
execSync("node index client --endpoint 'https://stage.cloud.appwrite.io/v1' --projectId console --key=35y3h5h345 --selfSigned true", { stdio: 'inherit' });
3+
execSync("node index client --endpoint 'https://qa.appwrite.org/v1' --projectId console --key=35y3h5h345 --selfSigned true", { stdio: 'inherit' });
44

55
var output;
66
console.log('\nTest Started');

0 commit comments

Comments
 (0)