Skip to content

Commit b4fb01a

Browse files
committed
Service-level params for Deno
1 parent 89be5db commit b4fb01a

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

templates/deno/src/services/service.ts.twig

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,27 @@ export type UploadProgress = {
4040
}
4141

4242
export class {{ service.name | caseUcfirst }} extends Service {
43+
{% if service.globalParams | length %}
44+
{% for parameter in service.globalParams %}
45+
protected {{ parameter.name | caseCamel | escapeKeyword }}: {{ parameter.type | typeName }};
46+
public set{{ parameter.name | caseUcfirst | escapeKeyword }}({{ parameter.name | caseCamel | escapeKeyword }}: {{ parameter.type | typeName }}): void
47+
{
48+
this.{{ parameter.name | caseCamel | escapeKeyword }} = {{ parameter.name | caseCamel | escapeKeyword }};
49+
}
50+
public get{{ parameter.name | caseUcfirst | escapeKeyword }}({{ parameter.name | caseCamel | escapeKeyword }}: {{ parameter.type | typeName }}): {{ parameter.type | typeName }}
51+
{
52+
return this.{{ parameter.name | caseCamel | escapeKeyword }};
53+
}
54+
{% endfor %}
55+
constructor(client: Client, {% for parameter in service.globalParams %} {{ parameter.name | caseCamel | escapeKeyword }}:{{ parameter.type | typeName }}{% if not parameter.required %}|null = null{% endif %}{% if not loop.last %}, {% endif %}{% endfor %})
56+
{
57+
super(client);
58+
59+
{% for parameter in service.globalParams %}
60+
this.{{ parameter.name | caseCamel | escapeKeyword }} = {{ parameter.name | caseCamel | escapeKeyword }};
61+
{% endfor %}
62+
}
63+
{% endif %}
4364
{% for method in service.methods %}
4465
{% set generics = _self.get_generics(spec.definitions[method.responseModel], spec, true, true) %}
4566
{% set generics_return = _self.get_generics_return(spec.definitions[method.responseModel], spec) %}
@@ -50,33 +71,33 @@ export class {{ service.name | caseUcfirst }} extends Service {
5071
{{ method.description|comment1 }}
5172
*
5273
{% endif %}
53-
{% for parameter in method.parameters.all %}
74+
{% for parameter in method.parameters.all | filter((param) => not param.isGlobal) %}
5475
* @param {{ '{' }}{{ parameter.type | typeName }}{{ '}' }} {{ parameter.name | caseCamel | escapeKeyword }}
5576
{% endfor %}
5677
* @throws {AppwriteException}
5778
* @returns {Promise}
5879
*/
59-
async {{ method.name | caseCamel }}{% if generics %}<{{generics}}>{% endif %}({% for parameter in method.parameters.all %}{{ parameter.name | caseCamel | escapeKeyword }}{% if not parameter.required %}?{% endif %}: {{ parameter.type | typeName }}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in method.consumes %}, onProgress = (progress: UploadProgress) => {}{% endif %}): Promise<{% if method.type == 'webAuth' %}Response{% elseif method.type == 'location' %}Response{% else %}{% if method.responseModel and method.responseModel != 'any' %}{% if not spec.definitions[method.responseModel].additionalProperties %}Models.{% endif %}{{method.responseModel | caseUcfirst}}{% if generics_return %}<{{generics_return}}>{% endif %}{% else %}Response{% endif %}{% endif %}> {
60-
{% for parameter in method.parameters.all %}
80+
async {{ method.name | caseCamel }}{% if generics %}<{{generics}}>{% endif %}({% for parameter in method.parameters.all | filter((param) => not param.isGlobal) %}{{ parameter.name | caseCamel | escapeKeyword }}{% if not parameter.required %}?{% endif %}: {{ parameter.type | typeName }}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in method.consumes %}, onProgress = (progress: UploadProgress) => {}{% endif %}): Promise<{% if method.type == 'webAuth' %}Response{% elseif method.type == 'location' %}Response{% else %}{% if method.responseModel and method.responseModel != 'any' %}{% if not spec.definitions[method.responseModel].additionalProperties %}Models.{% endif %}{{method.responseModel | caseUcfirst}}{% if generics_return %}<{{generics_return}}>{% endif %}{% else %}Response{% endif %}{% endif %}> {
81+
{% for parameter in method.parameters.all | filter((param) => not param.isGlobal) %}
6182
{% if parameter.required %}
6283
if (typeof {{ parameter.name | caseCamel | escapeKeyword }} === 'undefined') {
6384
throw new {{spec.title | caseUcfirst}}Exception('Missing required parameter: "{{ parameter.name | caseCamel | escapeKeyword }}"');
6485
}
6586

6687
{% endif %}
6788
{% endfor %}
68-
let path = '{{ method.path }}'{% for parameter in method.parameters.path %}.replace('{{ '{' }}{{ parameter.name }}{{ '}' }}', {{ parameter.name | caseCamel | escapeKeyword }}){% endfor %};
89+
let path = '{{ method.path }}'{% for parameter in method.parameters.path %}.replace('{{ '{' }}{{ parameter.name }}{{ '}' }}', {% if parameter.isGlobal %}this.{% endif %}{{ parameter.name | caseCamel | escapeKeyword }}){% endfor %};
6990
let payload: Payload = {};
7091

7192
{% for parameter in method.parameters.query %}
72-
if (typeof {{ parameter.name | caseCamel | escapeKeyword }} !== 'undefined') {
73-
payload['{{ parameter.name }}'] = {{ parameter.name | caseCamel | escapeKeyword }}{% if method.consumes[0] == "multipart/form-data" and ( parameter.type != "string" and parameter.type != "array" ) %}.toString(){% endif %};
93+
if (typeof {% if parameter.isGlobal %}this.{% endif %}{{ parameter.name | caseCamel | escapeKeyword }} !== 'undefined') {
94+
payload['{{ parameter.name }}'] = {% if parameter.isGlobal %}this.{% endif %}{{ parameter.name | caseCamel | escapeKeyword }}{% if method.consumes[0] == "multipart/form-data" and ( parameter.type != "string" and parameter.type != "array" ) %}.toString(){% endif %};
7495
}
7596

7697
{% endfor %}
7798
{% for parameter in method.parameters.body %}
78-
if (typeof {{ parameter.name | caseCamel | escapeKeyword }} !== 'undefined') {
79-
payload['{{ parameter.name }}'] = {{ parameter.name | caseCamel | escapeKeyword }}{% if method.consumes[0] == "multipart/form-data" and ( parameter.type != "string" and parameter.type != "array" ) %}.toString(){% endif %};
99+
if (typeof {% if parameter.isGlobal %}this.{% endif %}{{ parameter.name | caseCamel | escapeKeyword }} !== 'undefined') {
100+
payload['{{ parameter.name }}'] = {% if parameter.isGlobal %}this.{% endif %}{{ parameter.name | caseCamel | escapeKeyword }}{% if method.consumes[0] == "multipart/form-data" and ( parameter.type != "string" and parameter.type != "array" ) %}.toString(){% endif %};
80101
}
81102
{% endfor %}
82103
{% if 'multipart/form-data' in method.consumes %}

tests/languages/deno/tests.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ async function start() {
88
// Init SDK
99
let client = new appwrite.Client()
1010

11-
let foo = new appwrite.Foo(client)
11+
let foo = new appwrite.Foo(client, 'string')
1212
let bar = new appwrite.Bar(client)
1313
let general = new appwrite.General(client)
1414

@@ -18,23 +18,23 @@ async function start() {
1818

1919
// Foo
2020

21-
response = await foo.get('string', 123, ['string in array'])
21+
response = await foo.get(123, ['string in array'])
2222
// @ts-ignore
2323
console.log(response.result)
2424

25-
response = await foo.post('string', 123, ['string in array'])
25+
response = await foo.post(123, ['string in array'])
2626
// @ts-ignore
2727
console.log(response.result)
2828

29-
response = await foo.put('string', 123, ['string in array'])
29+
response = await foo.put(123, ['string in array'])
3030
// @ts-ignore
3131
console.log(response.result)
3232

33-
response = await foo.patch('string', 123, ['string in array'])
33+
response = await foo.patch(123, ['string in array'])
3434
// @ts-ignore
3535
console.log(response.result)
3636

37-
response = await foo.delete('string', 123, ['string in array'])
37+
response = await foo.delete(123, ['string in array'])
3838
// @ts-ignore
3939
console.log(response.result)
4040

0 commit comments

Comments
 (0)