Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/sdk-build-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ jobs:
;;
cli)
npm install
npm run linux-x64 || echo "Build completed with TypeScript warnings/errors, but binaries were generated"
npm run linux-x64
;;
react-native)
npm install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
sdk: [
Android5Java17,
Android14Java17,
CLINode16,
CLINode18,
CLINode20,
DartBeta,
DartStable,
DotNet60,
Expand Down
7 changes: 6 additions & 1 deletion src/SDK/Language/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ public function getFiles(): array
'destination' => 'lib/types.ts',
'template' => 'cli/lib/types.ts.twig',
],
[
'scope' => 'enum',
'destination' => 'lib/enums/{{ enum.name | caseKebab }}.ts',
'template' => 'cli/lib/enums/enum.ts.twig',
],
[
'scope' => 'default',
'destination' => 'lib/commands/init.ts',
Expand Down Expand Up @@ -384,7 +389,7 @@ public function getTypeName(array $parameter, array $spec = []): string
self::TYPE_STRING => 'string',
self::TYPE_FILE => 'string',
self::TYPE_BOOLEAN => 'boolean',
self::TYPE_OBJECT => 'object',
self::TYPE_OBJECT => 'string',
self::TYPE_ARRAY => (!empty(($parameter['array'] ?? [])['type']) && !\is_array($parameter['array']['type']))
? $this->getTypeName($parameter['array']) . '[]'
: 'any[]',
Expand Down
13 changes: 8 additions & 5 deletions templates/cli/base/params.twig
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@
const nodeStream = fs.createReadStream(filePath);
const stream = convertReadStreamToReadableStream(nodeStream);

if (typeof filePath !== 'undefined') {
{{ parameter.name | caseCamel | escapeKeyword }} = { type: 'file', stream, filename: pathLib.basename(filePath), size: fs.statSync(filePath).size };
payload['{{ parameter.name }}'] = {{ parameter.name | caseCamel | escapeKeyword }}
}
const {{ parameter.name | caseCamel | escapeKeyword }}Upload: FileInput = {
type: 'file',
stream,
filename: pathLib.basename(filePath),
size: fs.statSync(filePath).size
};
payload['{{ parameter.name }}'] = {{ parameter.name | caseCamel | escapeKeyword }}Upload;
{% elseif parameter.type == 'boolean' %}
if (typeof {{ parameter.name | caseCamel | escapeKeyword }} !== 'undefined') {
payload['{{ parameter.name }}'] = {{ parameter.name | caseCamel | escapeKeyword }};
Expand All @@ -74,7 +77,7 @@
payload['{{ parameter.name }}'] = JSON.parse({{ parameter.name | caseCamel | escapeKeyword}});
}
{% elseif parameter.type == 'array' %}
{{ parameter.name | caseCamel | escapeKeyword}} = {{ parameter.name | caseCamel | escapeKeyword}} === true ? [] : {{ parameter.name | caseCamel | escapeKeyword}};
{{ parameter.name | caseCamel | escapeKeyword}} = ({{ parameter.name | caseCamel | escapeKeyword}} as unknown) === true ? [] : {{ parameter.name | caseCamel | escapeKeyword}};
if (typeof {{ parameter.name | caseCamel | escapeKeyword }} !== 'undefined') {
payload['{{ parameter.name }}'] = {{ parameter.name | caseCamel | escapeKeyword}};
}
Expand Down
6 changes: 3 additions & 3 deletions templates/cli/base/requests/file.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% for parameter in method.parameters.all %}
{% if parameter.type == 'file' %}
const size = {{ parameter.name | caseCamel | escapeKeyword }}.size;
const size = {{ parameter.name | caseCamel | escapeKeyword }}Upload.size;

const apiHeaders = {
{% for parameter in method.parameters.header %}
Expand Down Expand Up @@ -59,7 +59,7 @@
apiHeaders['x-{{spec.title | caseLower }}-id'] = id;
}

payload['{{ parameter.name }}'] = { type: 'file', file: new File([uploadableChunkTrimmed], {{ parameter.name | caseCamel | escapeKeyword }}.filename), filename: {{ parameter.name | caseCamel | escapeKeyword }}.filename };
payload['{{ parameter.name }}'] = { type: 'file', file: new File([uploadableChunkTrimmed], {{ parameter.name | caseCamel | escapeKeyword }}Upload.filename), filename: {{ parameter.name | caseCamel | escapeKeyword }}Upload.filename };

response = await client.call('{{ method.method | caseLower }}', apiPath, apiHeaders, payload{% if method.type == 'location' %}, 'arraybuffer'{% endif %});

Expand All @@ -82,7 +82,7 @@
currentPosition = 0;
}

for await (const chunk of {{ parameter.name | caseCamel | escapeKeyword }}.stream) {
for await (const chunk of {{ parameter.name | caseCamel | escapeKeyword }}Upload.stream) {
for(const b of chunk) {
uploadableChunk[currentPosition] = b;

Expand Down
2 changes: 1 addition & 1 deletion templates/cli/index.ts.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const oldWidth = process.stdout.columns;
process.stdout.columns = 100;
/** ---------------------------------------------- */

import program = require('commander');
import { program } from 'commander';
import chalk = require('chalk');
const { version } = require('../package.json');
import { commandDescriptions, cliConfig } from './lib/parser';
Expand Down
6 changes: 3 additions & 3 deletions templates/cli/lib/client.ts.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os = require('os');
import { fetch, FormData, Agent } from 'undici';
import { fetch, FormData, Agent, File } from 'undici';
import JSONbig = require('json-bigint');
import {{ spec.title | caseUcfirst }}Exception = require('./exception');
import { globalConfig } from './config';
Expand All @@ -9,7 +9,7 @@ import type { Headers, RequestParams, ResponseType, FileUpload } from './types';
const JSONBigInt = JSONbig({ storeAsString: false });

class Client {
private readonly CHUNK_SIZE = 5 * 1024 * 1024; // 5MB
readonly CHUNK_SIZE = 5 * 1024 * 1024; // 5MB
private endpoint: string;
private headers: Headers;
private selfSigned: boolean;
Expand Down Expand Up @@ -122,7 +122,7 @@ class Client {
for (const [key, value] of Object.entries(flatParams)) {
if (value && typeof value === 'object' && 'type' in value && value.type === 'file') {
const fileUpload = value as FileUpload;
formData.append(key, fileUpload.file as any, fileUpload.filename);
formData.append(key, fileUpload.file, fileUpload.filename);
} else {
formData.append(key, value as string);
}
Expand Down
18 changes: 15 additions & 3 deletions templates/cli/lib/commands/command.ts.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs = require('fs');
import pathLib = require('path');
import tar = require('tar');
import ignore = require('ignore');
import ignore from 'ignore';
import { promisify } from 'util';
import Client from '../client';
import { getAllFiles, showConsoleLink } from '../utils';
Expand All @@ -11,6 +11,18 @@ import { parse, actionRunner, parseInteger, parseBool, commandDescriptions, succ
import { localConfig, globalConfig } from '../config';
import { File } from 'undici';
import { ReadableStream } from 'stream/web';
import type { UploadProgress, FileInput } from '../types';
{% set addedEnums = [] %}
{% for method in service.methods %}
{% for parameter in method.parameters.all %}
{% if parameter.enumValues is not empty %}
{% if parameter.enumName not in addedEnums %}
import { {{ parameter.enumName | caseUcfirst }} } from '../enums/{{ parameter.enumName | caseKebab }}';
{% set addedEnums = addedEnums|merge([parameter.enumName]) %}
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}

function convertReadStreamToReadableStream(readStream: fs.ReadStream): ReadableStream {
return new ReadableStream({
Expand Down Expand Up @@ -55,7 +67,7 @@ interface {{ service.name | caseUcfirst }}{{ method.name | caseUcfirst }}Request
parseOutput?: boolean;
sdk?: Client;
{% if 'multipart/form-data' in method.consumes %}
onProgress?: (progress: number) => void;
onProgress?: (progress: UploadProgress) => void;
{% endif %}
{% if method.type == 'location' %}
destination?: string;
Expand All @@ -73,7 +85,7 @@ export const {{ service.name }}{{ method.name | caseUcfirst }} = async ({

{%- block baseParams -%}parseOutput = true, overrideForCli = false, sdk = undefined {%- endblock -%}

{%- if 'multipart/form-data' in method.consumes -%},onProgress = () => {}{%- endif -%}
{%- if 'multipart/form-data' in method.consumes -%},onProgress = (progress: any) => {}{%- endif -%}

{%- if method.type == 'location' -%}, destination{%- endif -%}
{% if hasConsolePreview(method.name,service.name) %}, console: showConsole{%- endif -%}
Expand Down
10 changes: 5 additions & 5 deletions templates/cli/lib/commands/generic.ts.twig
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const loginCommand = async ({ email, password, endpoint, mfa, code }: Log

const id = ID.unique();

globalConfig.addSession(id, {});
globalConfig.addSession(id, { endpoint: configEndpoint });
globalConfig.setCurrentSession(id);
globalConfig.setEndpoint(configEndpoint);
globalConfig.setEmail(answers.email);
Expand Down Expand Up @@ -281,12 +281,12 @@ export const client = new Command("client")
if (selfSigned || globalConfig.getSelfSigned()) {
clientInstance.setSelfSigned(true);
}
let response = await clientInstance.call('GET', '/health/version');
let response = await clientInstance.call<{ version?: string }>('GET', '/health/version');
if (!response.version) {
throw new Error();
}
globalConfig.setCurrentSession(id);
globalConfig.addSession(id, {});
globalConfig.addSession(id, { endpoint });
globalConfig.setEndpoint(endpoint);
} catch (_) {
throw new Error("Invalid endpoint or your Appwrite server is not running as expected.");
Expand Down Expand Up @@ -322,8 +322,8 @@ export const migrate = async (): Promise<void> => {
return;
}

const endpoint = globalConfig.get('endpoint');
const cookie = globalConfig.get('cookie');
const endpoint = globalConfig.get('endpoint') as string;
const cookie = globalConfig.get('cookie') as string;

const id = ID.unique();
const data = {
Expand Down
8 changes: 4 additions & 4 deletions templates/cli/lib/commands/init.ts.twig
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const initResources = async (): Promise<void> => {
collection: initCollection
}

const answers = await inquirer.prompt(questionsInitResources[0]);
const answers = await inquirer.prompt([questionsInitResources[0]]);

const action = actions[answers.resource];
if (action !== undefined) {
Expand Down Expand Up @@ -85,9 +85,9 @@ const initProject = async ({ organizationId, projectId, projectName }: InitProje
answers.project = {};
answers.organization = {};

answers.organization = organizationId ?? (await inquirer.prompt(questionsInitProject[2])).organization;
answers.project.name = projectName ?? (await inquirer.prompt(questionsInitProject[3])).project;
answers.project = projectId ?? (await inquirer.prompt(questionsInitProject[4])).id;
answers.organization = organizationId ?? (await inquirer.prompt([questionsInitProject[2]])).organization;
answers.project.name = projectName ?? (await inquirer.prompt([questionsInitProject[3]])).project;
answers.project = projectId ?? (await inquirer.prompt([questionsInitProject[4]])).id;

try {
await projectsGet({ projectId, parseOutput: false });
Expand Down
2 changes: 1 addition & 1 deletion templates/cli/lib/commands/pull.ts.twig
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const pullResources = async ({
await action({ returnOnZero: true });
}
} else {
const answers = await inquirer.prompt(questionsPullResources[0]);
const answers = await inquirer.prompt([questionsPullResources[0]]);

const action = actions[answers.resource];
if (action !== undefined) {
Expand Down
Loading
Loading