Skip to content

Commit b1e6772

Browse files
committed
feat: realtime heartbeat
1 parent 7e79cae commit b1e6772

18 files changed

+939
-1276
lines changed

docs/examples/functions/create-execution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const functions = new Functions(client);
88

99
const result = await functions.createExecution(
1010
'<FUNCTION_ID>', // functionId
11-
await pickSingle(), // body (optional)
11+
'<BODY>', // body (optional)
1212
false, // async (optional)
1313
'<PATH>', // path (optional)
1414
ExecutionMethod.GET, // method (optional)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626
},
2727
"devDependencies": {
2828
"@rollup/plugin-typescript": "8.3.2",
29+
"playwright": "1.15.0",
2930
"rollup": "2.75.4",
3031
"serve-handler": "6.1.0",
3132
"tslib": "2.4.0",
3233
"typescript": "4.7.2"
3334
},
3435
"dependencies": {
3536
"expo-file-system": "16.0.8",
36-
"parse-multipart-data": "^1.5.0",
3737
"react-native": "^0.73.6"
3838
},
3939
"peerDependencies": {

src/client.ts

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import { Platform } from 'react-native';
2-
import { getBoundary, parse as parseMultipart} from './multipart';
3-
import { Service } from './service';
4-
import { Payload } from './payload';
51
import { Models } from './models';
2+
import { Service } from './service';
3+
import { Platform } from 'react-native';
64

7-
8-
type Params = {
5+
type Payload = {
96
[key: string]: any;
107
}
118

@@ -386,7 +383,7 @@ class Client {
386383
}
387384
}
388385

389-
async call(method: string, url: URL, headers: Headers = {}, params: Params = {}): Promise<any> {
386+
async call(method: string, url: URL, headers: Headers = {}, params: Payload = {}): Promise<any> {
390387
method = method.toUpperCase();
391388

392389
headers = Object.assign({}, this.headers, headers);
@@ -438,36 +435,6 @@ class Client {
438435

439436
if (response.headers.get('content-type')?.includes('application/json')) {
440437
data = await response.json();
441-
} else if (response.headers.get('content-type')?.includes('multipart/form-data')) {
442-
const boundary = getBoundary(
443-
response.headers.get("content-type") || ""
444-
);
445-
446-
const body = new Uint8Array(await response.arrayBuffer());
447-
const parts = parseMultipart(body, boundary);
448-
const partsObject: { [key: string]: any } = {};
449-
450-
for (const part of parts) {
451-
if (!part.name) {
452-
continue;
453-
}
454-
if (part.name === "responseBody") {
455-
partsObject[part.name] = Payload.fromBinary(part.data, part.filename);
456-
} else if (part.name === "responseStatusCode") {
457-
partsObject[part.name] = parseInt(part.data.toString());
458-
} else if (part.name === "duration") {
459-
partsObject[part.name] = parseFloat(part.data.toString());
460-
} else if (part.type === 'application/json') {
461-
try {
462-
partsObject[part.name] = JSON.parse(part.data.toString());
463-
} catch (e) {
464-
throw new Error(`Error parsing JSON for part ${part.name}: ${e instanceof Error ? e.message : 'Unknown error'}`);
465-
}
466-
} else {
467-
partsObject[part.name] = part.data.toString();
468-
}
469-
}
470-
data = partsObject;
471438
} else {
472439
data = {
473440
message: await response.text()
@@ -496,4 +463,4 @@ class Client {
496463
}
497464

498465
export { Client, AppwriteException };
499-
export type { Models, Params };
466+
export type { Models, Payload };

src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ export { Locale } from './services/locale';
88
export { Messaging } from './services/messaging';
99
export { Storage } from './services/storage';
1010
export { Teams } from './services/teams';
11-
export type { Models, Params, RealtimeResponseEvent, UploadProgress } from './client';
11+
export type { Models, Payload, RealtimeResponseEvent, UploadProgress } from './client';
1212
export type { QueryTypes, QueryTypesList } from './query';
1313
export { Query } from './query';
1414
export { Permission } from './permission';
1515
export { Role } from './role';
1616
export { ID } from './id';
17-
export { Payload } from './payload';
1817
export { AuthenticatorType } from './enums/authenticator-type';
1918
export { AuthenticationFactor } from './enums/authentication-factor';
2019
export { OAuthProvider } from './enums/o-auth-provider';

src/models.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { Payload } from './payload';
2-
31
export namespace Models {
42
/**
53
* Documents List
@@ -928,7 +926,7 @@ export namespace Models {
928926
/**
929927
* HTTP response body. This will return empty unless execution is created as synchronous.
930928
*/
931-
responseBody: Payload;
929+
responseBody: string;
932930
/**
933931
* HTTP response headers as a key-value object. This will return only whitelisted headers. All headers are returned if execution is created as synchronous.
934932
*/

src/multipart.ts

Lines changed: 0 additions & 214 deletions
This file was deleted.

0 commit comments

Comments
 (0)