react-native-appwrite 0.19.0 → 0.21.0
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.
- package/.github/workflows/publish.yml +9 -8
- package/CHANGELOG.md +12 -0
- package/LICENSE +1 -1
- package/README.md +3 -3
- package/dist/cjs/sdk.js +254 -64
- package/dist/cjs/sdk.js.map +1 -1
- package/dist/esm/sdk.js +250 -65
- package/dist/esm/sdk.js.map +1 -1
- package/docs/examples/account/create-anonymous-session.md +2 -0
- package/docs/examples/account/create-email-password-session.md +2 -0
- package/docs/examples/account/create-email-token.md +2 -0
- package/docs/examples/account/create-email-verification.md +2 -0
- package/docs/examples/account/create-jwt.md +5 -1
- package/docs/examples/account/create-magic-url-token.md +2 -0
- package/docs/examples/account/create-mfa-authenticator.md +2 -0
- package/docs/examples/account/create-mfa-challenge.md +2 -0
- package/docs/examples/account/create-mfa-recovery-codes.md +2 -0
- package/docs/examples/account/create-o-auth-2-session.md +2 -0
- package/docs/examples/account/create-o-auth-2-token.md +2 -0
- package/docs/examples/account/create-phone-token.md +2 -0
- package/docs/examples/account/create-phone-verification.md +2 -0
- package/docs/examples/account/create-push-target.md +2 -0
- package/docs/examples/account/create-recovery.md +2 -0
- package/docs/examples/account/create-session.md +2 -0
- package/docs/examples/account/create-verification.md +2 -0
- package/docs/examples/account/create.md +2 -0
- package/docs/examples/account/delete-identity.md +2 -0
- package/docs/examples/account/delete-mfa-authenticator.md +2 -0
- package/docs/examples/account/delete-push-target.md +2 -0
- package/docs/examples/account/delete-session.md +2 -0
- package/docs/examples/account/delete-sessions.md +2 -0
- package/docs/examples/account/get-mfa-recovery-codes.md +2 -0
- package/docs/examples/account/get-prefs.md +2 -0
- package/docs/examples/account/get-session.md +2 -0
- package/docs/examples/account/get.md +2 -0
- package/docs/examples/account/list-identities.md +2 -0
- package/docs/examples/account/list-logs.md +2 -0
- package/docs/examples/account/list-mfa-factors.md +2 -0
- package/docs/examples/account/list-sessions.md +2 -0
- package/docs/examples/account/update-email-verification.md +2 -0
- package/docs/examples/account/update-email.md +2 -0
- package/docs/examples/account/update-magic-url-session.md +2 -0
- package/docs/examples/account/update-mfa-authenticator.md +2 -0
- package/docs/examples/account/update-mfa-challenge.md +2 -0
- package/docs/examples/account/update-mfa-recovery-codes.md +2 -0
- package/docs/examples/account/update-mfa.md +2 -0
- package/docs/examples/account/update-name.md +2 -0
- package/docs/examples/account/update-password.md +2 -0
- package/docs/examples/account/update-phone-session.md +2 -0
- package/docs/examples/account/update-phone-verification.md +2 -0
- package/docs/examples/account/update-phone.md +2 -0
- package/docs/examples/account/update-prefs.md +2 -0
- package/docs/examples/account/update-push-target.md +2 -0
- package/docs/examples/account/update-recovery.md +2 -0
- package/docs/examples/account/update-session.md +2 -0
- package/docs/examples/account/update-status.md +2 -0
- package/docs/examples/account/update-verification.md +2 -0
- package/docs/examples/avatars/get-browser.md +2 -0
- package/docs/examples/avatars/get-credit-card.md +2 -0
- package/docs/examples/avatars/get-favicon.md +2 -0
- package/docs/examples/avatars/get-flag.md +2 -0
- package/docs/examples/avatars/get-image.md +2 -0
- package/docs/examples/avatars/get-initials.md +2 -0
- package/docs/examples/avatars/get-qr.md +2 -0
- package/docs/examples/avatars/get-screenshot.md +7 -5
- package/docs/examples/databases/create-document.md +2 -0
- package/docs/examples/databases/create-operations.md +2 -0
- package/docs/examples/databases/create-transaction.md +2 -0
- package/docs/examples/databases/decrement-document-attribute.md +2 -0
- package/docs/examples/databases/delete-document.md +2 -0
- package/docs/examples/databases/delete-transaction.md +2 -0
- package/docs/examples/databases/get-document.md +2 -0
- package/docs/examples/databases/get-transaction.md +2 -0
- package/docs/examples/databases/increment-document-attribute.md +2 -0
- package/docs/examples/databases/list-documents.md +2 -0
- package/docs/examples/databases/list-transactions.md +2 -0
- package/docs/examples/databases/update-document.md +9 -1
- package/docs/examples/databases/update-transaction.md +2 -0
- package/docs/examples/databases/upsert-document.md +9 -1
- package/docs/examples/functions/create-execution.md +2 -0
- package/docs/examples/functions/get-execution.md +2 -0
- package/docs/examples/functions/list-executions.md +2 -0
- package/docs/examples/graphql/mutation.md +2 -0
- package/docs/examples/graphql/query.md +2 -0
- package/docs/examples/locale/get.md +2 -0
- package/docs/examples/locale/list-codes.md +2 -0
- package/docs/examples/locale/list-continents.md +2 -0
- package/docs/examples/locale/list-countries-eu.md +2 -0
- package/docs/examples/locale/list-countries-phones.md +2 -0
- package/docs/examples/locale/list-countries.md +2 -0
- package/docs/examples/locale/list-currencies.md +2 -0
- package/docs/examples/locale/list-languages.md +2 -0
- package/docs/examples/messaging/create-subscriber.md +2 -0
- package/docs/examples/messaging/delete-subscriber.md +2 -0
- package/docs/examples/storage/create-file.md +2 -0
- package/docs/examples/storage/delete-file.md +2 -0
- package/docs/examples/storage/get-file-download.md +2 -0
- package/docs/examples/storage/get-file-preview.md +2 -0
- package/docs/examples/storage/get-file-view.md +2 -0
- package/docs/examples/storage/get-file.md +2 -0
- package/docs/examples/storage/list-files.md +2 -0
- package/docs/examples/storage/update-file.md +2 -0
- package/docs/examples/tablesdb/create-operations.md +2 -0
- package/docs/examples/tablesdb/create-row.md +2 -0
- package/docs/examples/tablesdb/create-transaction.md +2 -0
- package/docs/examples/tablesdb/decrement-row-column.md +2 -0
- package/docs/examples/tablesdb/delete-row.md +2 -0
- package/docs/examples/tablesdb/delete-transaction.md +2 -0
- package/docs/examples/tablesdb/get-row.md +2 -0
- package/docs/examples/tablesdb/get-transaction.md +2 -0
- package/docs/examples/tablesdb/increment-row-column.md +2 -0
- package/docs/examples/tablesdb/list-rows.md +2 -0
- package/docs/examples/tablesdb/list-transactions.md +2 -0
- package/docs/examples/tablesdb/update-row.md +9 -1
- package/docs/examples/tablesdb/update-transaction.md +2 -0
- package/docs/examples/tablesdb/upsert-row.md +9 -1
- package/docs/examples/teams/create-membership.md +2 -0
- package/docs/examples/teams/create.md +2 -0
- package/docs/examples/teams/delete-membership.md +2 -0
- package/docs/examples/teams/delete.md +2 -0
- package/docs/examples/teams/get-membership.md +2 -0
- package/docs/examples/teams/get-prefs.md +2 -0
- package/docs/examples/teams/get.md +2 -0
- package/docs/examples/teams/list-memberships.md +2 -0
- package/docs/examples/teams/list.md +2 -0
- package/docs/examples/teams/update-membership-status.md +2 -0
- package/docs/examples/teams/update-membership.md +2 -0
- package/docs/examples/teams/update-name.md +2 -0
- package/docs/examples/teams/update-prefs.md +2 -0
- package/package.json +6 -3
- package/rollup.config.js +3 -1
- package/src/channel.ts +132 -0
- package/src/client.ts +72 -10
- package/src/enums/browser-permission.ts +22 -0
- package/src/enums/o-auth-provider.ts +2 -1
- package/src/index.ts +3 -2
- package/src/models.ts +8 -0
- package/src/query.ts +54 -9
- package/src/services/account.ts +45 -16
- package/src/services/avatars.ts +20 -19
- package/src/services/databases.ts +5 -9
- package/src/services/graphql.ts +2 -2
- package/src/services/storage.ts +8 -8
- package/types/channel.d.ts +71 -0
- package/types/client.d.ts +2 -1
- package/types/enums/browser-permission.d.ts +22 -0
- package/types/enums/o-auth-provider.d.ts +2 -1
- package/types/index.d.ts +3 -2
- package/types/models.d.ts +8 -0
- package/types/query.d.ts +36 -6
- package/types/services/account.d.ts +17 -5
- package/types/services/avatars.d.ts +12 -11
- package/types/services/databases.d.ts +2 -2
- package/types/services/storage.d.ts +8 -8
- package/src/enums/output.ts +0 -9
- package/types/enums/output.d.ts +0 -9
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-appwrite",
|
|
3
3
|
"homepage": "https://appwrite.io/support",
|
|
4
|
-
"description": "Appwrite is an open-source self-hosted backend server that
|
|
5
|
-
"version": "0.
|
|
4
|
+
"description": "Appwrite is an open-source self-hosted backend server that abstracts and simplifies complex and repetitive development tasks behind a very simple REST API",
|
|
5
|
+
"version": "0.21.0",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
7
7
|
"main": "dist/cjs/sdk.js",
|
|
8
8
|
"exports": {
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@rollup/plugin-typescript": "8.3.2",
|
|
29
|
+
"@types/json-bigint": "1.0.4",
|
|
29
30
|
"playwright": "1.56.1",
|
|
30
31
|
"rollup": "2.75.4",
|
|
31
32
|
"serve-handler": "6.1.0",
|
|
@@ -34,7 +35,9 @@
|
|
|
34
35
|
},
|
|
35
36
|
"dependencies": {
|
|
36
37
|
"expo-file-system": "18.*.*",
|
|
37
|
-
"
|
|
38
|
+
"json-bigint": "1.0.0",
|
|
39
|
+
"react-native": ">=0.76.7 <1.0.0",
|
|
40
|
+
"bignumber.js": "^9.0.0"
|
|
38
41
|
},
|
|
39
42
|
"peerDependencies": {
|
|
40
43
|
"expo": "*"
|
package/rollup.config.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import pkg from "./package.json";
|
|
2
2
|
import typescript from "@rollup/plugin-typescript";
|
|
3
3
|
|
|
4
|
+
const external = Object.keys(pkg.dependencies ?? {});
|
|
5
|
+
|
|
4
6
|
export default {
|
|
5
|
-
external: Object.keys(pkg.dependencies),
|
|
6
7
|
input: "src/index.ts",
|
|
8
|
+
external,
|
|
7
9
|
plugins: [typescript()],
|
|
8
10
|
output: [
|
|
9
11
|
{
|
package/src/channel.ts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
interface Root {}
|
|
2
|
+
interface Database { _db: any }
|
|
3
|
+
interface Collection { _coll: any }
|
|
4
|
+
interface Document { _doc: any }
|
|
5
|
+
interface TablesDB { _tdb: any }
|
|
6
|
+
interface Table { _tbl: any }
|
|
7
|
+
interface Row { _row: any }
|
|
8
|
+
interface Bucket { _bkt: any }
|
|
9
|
+
interface File { _file: any }
|
|
10
|
+
interface Func { _fn: any }
|
|
11
|
+
interface Execution { _exec: any }
|
|
12
|
+
interface Team { _team: any }
|
|
13
|
+
interface Membership { _mem: any }
|
|
14
|
+
interface Resolved { _res: any }
|
|
15
|
+
|
|
16
|
+
type Actionable = Document | Row | File | Team | Membership;
|
|
17
|
+
|
|
18
|
+
function normalize(id: string): string {
|
|
19
|
+
const trimmed = id.trim();
|
|
20
|
+
return trimmed === "" ? "*" : trimmed;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class Channel<T> {
|
|
24
|
+
declare _type: T;
|
|
25
|
+
|
|
26
|
+
private constructor(private readonly segments: string[]) {}
|
|
27
|
+
|
|
28
|
+
private next<N>(segment: string, id: string = "*"): Channel<N> {
|
|
29
|
+
return new Channel<N>([...this.segments, segment, normalize(id)]) as any;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private resolve(action: string): Channel<Resolved> {
|
|
33
|
+
return new Channel<Resolved>([...this.segments, action]) as any;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
toString(): string {
|
|
37
|
+
return this.segments.join(".");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// --- DATABASE ROUTE ---
|
|
41
|
+
// Only available on Channel<Database>
|
|
42
|
+
collection(this: Channel<Database>, id: string = "*"): Channel<Collection> {
|
|
43
|
+
return this.next<Collection>("collections", id);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Only available on Channel<Collection>
|
|
47
|
+
document(this: Channel<Collection>, id: string = "*"): Channel<Document> {
|
|
48
|
+
return this.next<Document>("documents", id);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// --- TABLESDB ROUTE ---
|
|
52
|
+
table(this: Channel<TablesDB>, id: string = "*"): Channel<Table> {
|
|
53
|
+
return this.next<Table>("tables", id);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
row(this: Channel<Table>, id: string = "*"): Channel<Row> {
|
|
57
|
+
return this.next<Row>("rows", id);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// --- BUCKET ROUTE ---
|
|
61
|
+
file(this: Channel<Bucket>, id: string = "*"): Channel<File> {
|
|
62
|
+
return this.next<File>("files", id);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// --- TERMINAL ACTIONS ---
|
|
66
|
+
// Restricted to the Actionable union
|
|
67
|
+
create(this: Channel<Actionable>): Channel<Resolved> {
|
|
68
|
+
return this.resolve("create");
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
update(this: Channel<Actionable>): Channel<Resolved> {
|
|
72
|
+
return this.resolve("update");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
delete(this: Channel<Actionable>): Channel<Resolved> {
|
|
76
|
+
return this.resolve("delete");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// --- ROOT FACTORIES ---
|
|
80
|
+
static database(id: string = "*") {
|
|
81
|
+
return new Channel<Database>(["databases", normalize(id)]);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
static tablesdb(id: string = "*") {
|
|
85
|
+
return new Channel<TablesDB>(["tablesdb", normalize(id)]);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
static bucket(id: string = "*") {
|
|
89
|
+
return new Channel<Bucket>(["buckets", normalize(id)]);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
static function(id: string = "*") {
|
|
93
|
+
return new Channel<Func>(["functions", normalize(id)]);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
static execution(id: string = "*") {
|
|
97
|
+
return new Channel<Execution>(["executions", normalize(id)]);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
static team(id: string = "*") {
|
|
101
|
+
return new Channel<Team>(["teams", normalize(id)]);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
static membership(id: string = "*") {
|
|
105
|
+
return new Channel<Membership>(["memberships", normalize(id)]);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
static account(): string {
|
|
109
|
+
return "account";
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Global events
|
|
113
|
+
static get documents(): string {
|
|
114
|
+
return "documents";
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
static get rows(): string {
|
|
118
|
+
return "rows";
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
static get files(): string {
|
|
122
|
+
return "files";
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
static get executions(): string {
|
|
126
|
+
return "executions";
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Export types for backward compatibility with realtime
|
|
131
|
+
export type ActionableChannel = Channel<Document> | Channel<Row> | Channel<File> | Channel<Execution> | Channel<Team> | Channel<Membership>;
|
|
132
|
+
export type ResolvedChannel = Channel<Resolved>;
|
package/src/client.ts
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
import { Models } from './models';
|
|
2
2
|
import { Service } from './service';
|
|
3
3
|
import { Platform } from 'react-native';
|
|
4
|
+
import { Query } from './query';
|
|
5
|
+
import JSONbigModule from 'json-bigint';
|
|
6
|
+
import BigNumber from 'bignumber.js';
|
|
7
|
+
const JSONbigParser = JSONbigModule({ storeAsString: false });
|
|
8
|
+
const JSONbigSerializer = JSONbigModule({ useNativeBigInt: true });
|
|
9
|
+
|
|
10
|
+
const MAX_SAFE = BigInt(Number.MAX_SAFE_INTEGER);
|
|
11
|
+
const MIN_SAFE = BigInt(Number.MIN_SAFE_INTEGER);
|
|
12
|
+
|
|
13
|
+
function reviver(_key: string, value: any): any {
|
|
14
|
+
if (BigNumber.isBigNumber(value)) {
|
|
15
|
+
if (value.isInteger()) {
|
|
16
|
+
const str = value.toFixed();
|
|
17
|
+
const bi = BigInt(str);
|
|
18
|
+
if (bi >= MIN_SAFE && bi <= MAX_SAFE) {
|
|
19
|
+
return Number(str);
|
|
20
|
+
}
|
|
21
|
+
return bi;
|
|
22
|
+
}
|
|
23
|
+
return value.toNumber();
|
|
24
|
+
}
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const JSONbig = {
|
|
29
|
+
parse: (text: string) => JSONbigParser.parse(text, reviver),
|
|
30
|
+
stringify: JSONbigSerializer.stringify
|
|
31
|
+
};
|
|
4
32
|
|
|
5
33
|
type Payload = {
|
|
6
34
|
[key: string]: any;
|
|
@@ -63,8 +91,10 @@ type Realtime = {
|
|
|
63
91
|
url?: string;
|
|
64
92
|
lastMessage?: RealtimeResponse;
|
|
65
93
|
channels: Set<string>;
|
|
94
|
+
queries: Set<string>;
|
|
66
95
|
subscriptions: Map<number, {
|
|
67
96
|
channels: string[];
|
|
97
|
+
queries: string[];
|
|
68
98
|
callback: (payload: RealtimeResponseEvent<any>) => void
|
|
69
99
|
}>;
|
|
70
100
|
subscriptionsCounter: number;
|
|
@@ -74,7 +104,7 @@ type Realtime = {
|
|
|
74
104
|
connect: () => void;
|
|
75
105
|
createSocket: () => void;
|
|
76
106
|
createHeartbeat: () => void;
|
|
77
|
-
cleanUp: (channels: string[]) => void;
|
|
107
|
+
cleanUp: (channels: string[], queries: string[]) => void;
|
|
78
108
|
onMessage: (event: MessageEvent) => void;
|
|
79
109
|
}
|
|
80
110
|
|
|
@@ -115,7 +145,7 @@ class Client {
|
|
|
115
145
|
'x-sdk-name': 'React Native',
|
|
116
146
|
'x-sdk-platform': 'client',
|
|
117
147
|
'x-sdk-language': 'reactnative',
|
|
118
|
-
'x-sdk-version': '0.
|
|
148
|
+
'x-sdk-version': '0.21.0',
|
|
119
149
|
'X-Appwrite-Response-Format': '1.8.0',
|
|
120
150
|
};
|
|
121
151
|
|
|
@@ -129,6 +159,10 @@ class Client {
|
|
|
129
159
|
* @returns {this}
|
|
130
160
|
*/
|
|
131
161
|
setEndpoint(endpoint: string): this {
|
|
162
|
+
if (!endpoint || typeof endpoint !== 'string') {
|
|
163
|
+
throw new AppwriteException('Endpoint must be a valid string');
|
|
164
|
+
}
|
|
165
|
+
|
|
132
166
|
if (!endpoint.startsWith('http://') && !endpoint.startsWith('https://')) {
|
|
133
167
|
throw new AppwriteException('Invalid endpoint URL: ' + endpoint);
|
|
134
168
|
}
|
|
@@ -147,6 +181,10 @@ class Client {
|
|
|
147
181
|
* @returns {this}
|
|
148
182
|
*/
|
|
149
183
|
setEndpointRealtime(endpointRealtime: string): this {
|
|
184
|
+
if (!endpointRealtime || typeof endpointRealtime !== 'string') {
|
|
185
|
+
throw new AppwriteException('Endpoint must be a valid string');
|
|
186
|
+
}
|
|
187
|
+
|
|
150
188
|
if (!endpointRealtime.startsWith('ws://') && !endpointRealtime.startsWith('wss://')) {
|
|
151
189
|
throw new AppwriteException('Invalid realtime endpoint URL: ' + endpointRealtime);
|
|
152
190
|
}
|
|
@@ -249,6 +287,7 @@ class Client {
|
|
|
249
287
|
heartbeat: undefined,
|
|
250
288
|
url: '',
|
|
251
289
|
channels: new Set(),
|
|
290
|
+
queries: new Set(),
|
|
252
291
|
subscriptions: new Map(),
|
|
253
292
|
subscriptionsCounter: 0,
|
|
254
293
|
reconnect: true,
|
|
@@ -278,7 +317,7 @@ class Client {
|
|
|
278
317
|
}
|
|
279
318
|
|
|
280
319
|
this.realtime.heartbeat = window?.setInterval(() => {
|
|
281
|
-
this.realtime.socket?.send(
|
|
320
|
+
this.realtime.socket?.send(JSONbig.stringify({
|
|
282
321
|
type: 'ping'
|
|
283
322
|
}));
|
|
284
323
|
}, 20_000);
|
|
@@ -295,6 +334,9 @@ class Client {
|
|
|
295
334
|
this.realtime.channels.forEach(channel => {
|
|
296
335
|
channels.append('channels[]', channel);
|
|
297
336
|
});
|
|
337
|
+
this.realtime.queries.forEach(query => {
|
|
338
|
+
channels.append('queries[]', query);
|
|
339
|
+
});
|
|
298
340
|
|
|
299
341
|
const url = this.config.endpointRealtime + '/realtime?' + channels.toString();
|
|
300
342
|
|
|
@@ -347,7 +389,7 @@ class Client {
|
|
|
347
389
|
},
|
|
348
390
|
onMessage: (event) => {
|
|
349
391
|
try {
|
|
350
|
-
const message: RealtimeResponse =
|
|
392
|
+
const message: RealtimeResponse = JSONbig.parse(event.data);
|
|
351
393
|
this.realtime.lastMessage = message;
|
|
352
394
|
switch (message.type) {
|
|
353
395
|
case 'event':
|
|
@@ -373,7 +415,7 @@ class Client {
|
|
|
373
415
|
console.error(e);
|
|
374
416
|
}
|
|
375
417
|
},
|
|
376
|
-
cleanUp: channels => {
|
|
418
|
+
cleanUp: (channels, queries) => {
|
|
377
419
|
this.realtime.channels.forEach(channel => {
|
|
378
420
|
if (channels.includes(channel)) {
|
|
379
421
|
let found = Array.from(this.realtime.subscriptions).some(([_key, subscription] )=> {
|
|
@@ -385,6 +427,18 @@ class Client {
|
|
|
385
427
|
}
|
|
386
428
|
}
|
|
387
429
|
})
|
|
430
|
+
|
|
431
|
+
this.realtime.queries.forEach(query => {
|
|
432
|
+
if (queries.includes(query)) {
|
|
433
|
+
let found = Array.from(this.realtime.subscriptions).some(([_key, subscription]) => {
|
|
434
|
+
return subscription.queries?.includes(query);
|
|
435
|
+
})
|
|
436
|
+
|
|
437
|
+
if (!found) {
|
|
438
|
+
this.realtime.queries.delete(query);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
})
|
|
388
442
|
}
|
|
389
443
|
}
|
|
390
444
|
|
|
@@ -413,13 +467,21 @@ class Client {
|
|
|
413
467
|
* @param {(payload: RealtimeMessage) => void} callback Is called on every realtime update.
|
|
414
468
|
* @returns {() => void} Unsubscribes from events.
|
|
415
469
|
*/
|
|
416
|
-
subscribe<T extends unknown>(
|
|
470
|
+
subscribe<T extends unknown>(
|
|
471
|
+
channels: string | string[],
|
|
472
|
+
callback: (payload: RealtimeResponseEvent<T>) => void,
|
|
473
|
+
queries: (string | Query)[] = []
|
|
474
|
+
): () => void {
|
|
417
475
|
let channelArray = typeof channels === 'string' ? [channels] : channels;
|
|
418
476
|
channelArray.forEach(channel => this.realtime.channels.add(channel));
|
|
419
477
|
|
|
478
|
+
const queryStrings = (queries ?? []).map(q => typeof q === 'string' ? q : q.toString());
|
|
479
|
+
queryStrings.forEach(query => this.realtime.queries.add(query));
|
|
480
|
+
|
|
420
481
|
const counter = this.realtime.subscriptionsCounter++;
|
|
421
482
|
this.realtime.subscriptions.set(counter, {
|
|
422
483
|
channels: channelArray,
|
|
484
|
+
queries: queryStrings,
|
|
423
485
|
callback
|
|
424
486
|
});
|
|
425
487
|
|
|
@@ -427,7 +489,7 @@ class Client {
|
|
|
427
489
|
|
|
428
490
|
return () => {
|
|
429
491
|
this.realtime.subscriptions.delete(counter);
|
|
430
|
-
this.realtime.cleanUp(channelArray);
|
|
492
|
+
this.realtime.cleanUp(channelArray, queryStrings);
|
|
431
493
|
this.realtime.connect();
|
|
432
494
|
}
|
|
433
495
|
}
|
|
@@ -454,7 +516,7 @@ class Client {
|
|
|
454
516
|
} else {
|
|
455
517
|
switch (headers['content-type']) {
|
|
456
518
|
case 'application/json':
|
|
457
|
-
options.body =
|
|
519
|
+
options.body = JSONbig.stringify(params);
|
|
458
520
|
break;
|
|
459
521
|
|
|
460
522
|
case 'multipart/form-data':
|
|
@@ -487,7 +549,7 @@ class Client {
|
|
|
487
549
|
}
|
|
488
550
|
|
|
489
551
|
if (response.headers.get('content-type')?.includes('application/json')) {
|
|
490
|
-
data = await response.
|
|
552
|
+
data = JSONbig.parse(await response.text());
|
|
491
553
|
} else if (responseType === 'arrayBuffer') {
|
|
492
554
|
data = await response.arrayBuffer();
|
|
493
555
|
} else {
|
|
@@ -499,7 +561,7 @@ class Client {
|
|
|
499
561
|
if (400 <= response.status) {
|
|
500
562
|
let responseText = '';
|
|
501
563
|
if (response.headers.get('content-type')?.includes('application/json')) {
|
|
502
|
-
responseText =
|
|
564
|
+
responseText = JSONbig.stringify(data);
|
|
503
565
|
} else {
|
|
504
566
|
responseText = data?.message;
|
|
505
567
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export enum BrowserPermission {
|
|
2
|
+
Geolocation = 'geolocation',
|
|
3
|
+
Camera = 'camera',
|
|
4
|
+
Microphone = 'microphone',
|
|
5
|
+
Notifications = 'notifications',
|
|
6
|
+
Midi = 'midi',
|
|
7
|
+
Push = 'push',
|
|
8
|
+
ClipboardRead = 'clipboard-read',
|
|
9
|
+
ClipboardWrite = 'clipboard-write',
|
|
10
|
+
PaymentHandler = 'payment-handler',
|
|
11
|
+
Usb = 'usb',
|
|
12
|
+
Bluetooth = 'bluetooth',
|
|
13
|
+
Accelerometer = 'accelerometer',
|
|
14
|
+
Gyroscope = 'gyroscope',
|
|
15
|
+
Magnetometer = 'magnetometer',
|
|
16
|
+
AmbientLightSensor = 'ambient-light-sensor',
|
|
17
|
+
BackgroundSync = 'background-sync',
|
|
18
|
+
PersistentStorage = 'persistent-storage',
|
|
19
|
+
ScreenWakeLock = 'screen-wake-lock',
|
|
20
|
+
WebShare = 'web-share',
|
|
21
|
+
XrSpatialTracking = 'xr-spatial-tracking',
|
|
22
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -15,6 +15,7 @@ export { Query } from './query';
|
|
|
15
15
|
export { Permission } from './permission';
|
|
16
16
|
export { Role } from './role';
|
|
17
17
|
export { ID } from './id';
|
|
18
|
+
export { Channel } from './channel';
|
|
18
19
|
export { Operator, Condition } from './operator';
|
|
19
20
|
export { AuthenticatorType } from './enums/authenticator-type';
|
|
20
21
|
export { AuthenticationFactor } from './enums/authentication-factor';
|
|
@@ -24,9 +25,9 @@ export { CreditCard } from './enums/credit-card';
|
|
|
24
25
|
export { Flag } from './enums/flag';
|
|
25
26
|
export { Theme } from './enums/theme';
|
|
26
27
|
export { Timezone } from './enums/timezone';
|
|
27
|
-
export {
|
|
28
|
+
export { BrowserPermission } from './enums/browser-permission';
|
|
29
|
+
export { ImageFormat } from './enums/image-format';
|
|
28
30
|
export { ExecutionMethod } from './enums/execution-method';
|
|
29
31
|
export { ImageGravity } from './enums/image-gravity';
|
|
30
|
-
export { ImageFormat } from './enums/image-format';
|
|
31
32
|
export { ExecutionTrigger } from './enums/execution-trigger';
|
|
32
33
|
export { ExecutionStatus } from './enums/execution-status';
|
package/src/models.ts
CHANGED
|
@@ -904,6 +904,14 @@ export namespace Models {
|
|
|
904
904
|
* Total number of chunks uploaded
|
|
905
905
|
*/
|
|
906
906
|
chunksUploaded: number;
|
|
907
|
+
/**
|
|
908
|
+
* Whether file contents are encrypted at rest.
|
|
909
|
+
*/
|
|
910
|
+
encryption: boolean;
|
|
911
|
+
/**
|
|
912
|
+
* Compression algorithm used for the file. Will be one of none, [gzip](https://en.wikipedia.org/wiki/Gzip), or [zstd](https://en.wikipedia.org/wiki/Zstd).
|
|
913
|
+
*/
|
|
914
|
+
compression: string;
|
|
907
915
|
}
|
|
908
916
|
|
|
909
917
|
/**
|
package/src/query.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import JSONbigModule from 'json-bigint';
|
|
2
|
+
const JSONbig = JSONbigModule({ useNativeBigInt: true });
|
|
3
|
+
|
|
4
|
+
type QueryTypesSingle = string | number | bigint | boolean;
|
|
5
|
+
export type QueryTypesList = string[] | number[] | bigint[] | boolean[] | Query[] | any[];
|
|
3
6
|
export type QueryTypes = QueryTypesSingle | QueryTypesList;
|
|
4
7
|
type AttributesTypes = string | string[];
|
|
5
8
|
|
|
@@ -26,7 +29,7 @@ export class Query {
|
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
toString(): string {
|
|
29
|
-
return
|
|
32
|
+
return JSONbig.stringify({
|
|
30
33
|
method: this.method,
|
|
31
34
|
attribute: this.attribute,
|
|
32
35
|
values: this.values,
|
|
@@ -39,6 +42,16 @@ export class Query {
|
|
|
39
42
|
static notEqual = (attribute: string, value: QueryTypes): string =>
|
|
40
43
|
new Query("notEqual", attribute, value).toString();
|
|
41
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Filter resources where attribute matches a regular expression pattern.
|
|
47
|
+
*
|
|
48
|
+
* @param {string} attribute The attribute to filter on.
|
|
49
|
+
* @param {string} pattern The regular expression pattern to match.
|
|
50
|
+
* @returns {string}
|
|
51
|
+
*/
|
|
52
|
+
static regex = (attribute: string, pattern: string): string =>
|
|
53
|
+
new Query("regex", attribute, pattern).toString();
|
|
54
|
+
|
|
42
55
|
static lessThan = (attribute: string, value: QueryTypes): string =>
|
|
43
56
|
new Query("lessThan", attribute, value).toString();
|
|
44
57
|
|
|
@@ -57,7 +70,25 @@ export class Query {
|
|
|
57
70
|
static isNotNull = (attribute: string): string =>
|
|
58
71
|
new Query("isNotNull", attribute).toString();
|
|
59
72
|
|
|
60
|
-
|
|
73
|
+
/**
|
|
74
|
+
* Filter resources where the specified attributes exist.
|
|
75
|
+
*
|
|
76
|
+
* @param {string[]} attributes The list of attributes that must exist.
|
|
77
|
+
* @returns {string}
|
|
78
|
+
*/
|
|
79
|
+
static exists = (attributes: string[]): string =>
|
|
80
|
+
new Query("exists", undefined, attributes).toString();
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Filter resources where the specified attributes do not exist.
|
|
84
|
+
*
|
|
85
|
+
* @param {string[]} attributes The list of attributes that must not exist.
|
|
86
|
+
* @returns {string}
|
|
87
|
+
*/
|
|
88
|
+
static notExists = (attributes: string[]): string =>
|
|
89
|
+
new Query("notExists", undefined, attributes).toString();
|
|
90
|
+
|
|
91
|
+
static between = (attribute: string, start: string | number | bigint, end: string | number | bigint) =>
|
|
61
92
|
new Query("between", attribute, [start, end] as QueryTypesList).toString();
|
|
62
93
|
|
|
63
94
|
static startsWith = (attribute: string, value: string): string =>
|
|
@@ -128,11 +159,11 @@ export class Query {
|
|
|
128
159
|
* Filter resources where attribute is not between start and end (exclusive).
|
|
129
160
|
*
|
|
130
161
|
* @param {string} attribute
|
|
131
|
-
* @param {string | number} start
|
|
132
|
-
* @param {string | number} end
|
|
162
|
+
* @param {string | number | bigint} start
|
|
163
|
+
* @param {string | number | bigint} end
|
|
133
164
|
* @returns {string}
|
|
134
165
|
*/
|
|
135
|
-
static notBetween = (attribute: string, start: string | number, end: string | number): string =>
|
|
166
|
+
static notBetween = (attribute: string, start: string | number | bigint, end: string | number | bigint): string =>
|
|
136
167
|
new Query("notBetween", attribute, [start, end] as QueryTypesList).toString();
|
|
137
168
|
|
|
138
169
|
/**
|
|
@@ -212,10 +243,24 @@ export class Query {
|
|
|
212
243
|
Query.between("$updatedAt", start, end);
|
|
213
244
|
|
|
214
245
|
static or = (queries: string[]) =>
|
|
215
|
-
new Query("or", undefined, queries.map((query) =>
|
|
246
|
+
new Query("or", undefined, queries.map((query) => JSONbig.parse(query))).toString();
|
|
216
247
|
|
|
217
248
|
static and = (queries: string[]) =>
|
|
218
|
-
new Query("and", undefined, queries.map((query) =>
|
|
249
|
+
new Query("and", undefined, queries.map((query) => JSONbig.parse(query))).toString();
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Filter array elements where at least one element matches all the specified queries.
|
|
253
|
+
*
|
|
254
|
+
* @param {string} attribute The attribute containing the array to filter on.
|
|
255
|
+
* @param {string[]} queries The list of query strings to match against array elements.
|
|
256
|
+
* @returns {string}
|
|
257
|
+
*/
|
|
258
|
+
static elemMatch = (attribute: string, queries: string[]): string =>
|
|
259
|
+
new Query(
|
|
260
|
+
"elemMatch",
|
|
261
|
+
attribute,
|
|
262
|
+
queries.map((query) => JSONbig.parse(query))
|
|
263
|
+
).toString();
|
|
219
264
|
|
|
220
265
|
/**
|
|
221
266
|
* Filter resources where attribute is at a specific distance from the given coordinates.
|