Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion docs/examples/databases/list-documents.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const result = await databases.listDocuments({
collectionId: '<COLLECTION_ID>',
queries: [], // optional
transactionId: '<TRANSACTION_ID>', // optional
total: false // optional
total: false, // optional
ttl: 0 // optional
});

console.log(result);
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/migrations/create-appwrite-migration.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```javascript
import { Client, Migrations, Resources } from "@appwrite.io/console";
import { Client, Migrations, AppwriteMigrationResource } from "@appwrite.io/console";

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
Expand All @@ -8,7 +8,7 @@ const client = new Client()
const migrations = new Migrations(client);

const result = await migrations.createAppwriteMigration({
resources: [Resources.User],
resources: [AppwriteMigrationResource.User],
endpoint: 'https://example.com',
projectId: '<PROJECT_ID>',
apiKey: '<API_KEY>'
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/migrations/create-firebase-migration.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```javascript
import { Client, Migrations, Resources } from "@appwrite.io/console";
import { Client, Migrations, FirebaseMigrationResource } from "@appwrite.io/console";

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
Expand All @@ -8,7 +8,7 @@ const client = new Client()
const migrations = new Migrations(client);

const result = await migrations.createFirebaseMigration({
resources: [Resources.User],
resources: [FirebaseMigrationResource.User],
serviceAccount: '<SERVICE_ACCOUNT>'
});

Expand Down
4 changes: 2 additions & 2 deletions docs/examples/migrations/create-n-host-migration.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```javascript
import { Client, Migrations, Resources } from "@appwrite.io/console";
import { Client, Migrations, NHostMigrationResource } from "@appwrite.io/console";

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
Expand All @@ -8,7 +8,7 @@ const client = new Client()
const migrations = new Migrations(client);

const result = await migrations.createNHostMigration({
resources: [Resources.User],
resources: [NHostMigrationResource.User],
subdomain: '<SUBDOMAIN>',
region: '<REGION>',
adminSecret: '<ADMIN_SECRET>',
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/migrations/create-supabase-migration.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```javascript
import { Client, Migrations, Resources } from "@appwrite.io/console";
import { Client, Migrations, SupabaseMigrationResource } from "@appwrite.io/console";

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
Expand All @@ -8,7 +8,7 @@ const client = new Client()
const migrations = new Migrations(client);

const result = await migrations.createSupabaseMigration({
resources: [Resources.User],
resources: [SupabaseMigrationResource.User],
endpoint: 'https://example.com',
apiKey: '<API_KEY>',
databaseHost: '<DATABASE_HOST>',
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/migrations/get-appwrite-report.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```javascript
import { Client, Migrations, Resources } from "@appwrite.io/console";
import { Client, Migrations, AppwriteMigrationResource } from "@appwrite.io/console";

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
Expand All @@ -8,7 +8,7 @@ const client = new Client()
const migrations = new Migrations(client);

const result = await migrations.getAppwriteReport({
resources: [Resources.User],
resources: [AppwriteMigrationResource.User],
endpoint: 'https://example.com',
projectID: '<PROJECT_ID>',
key: '<KEY>'
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/migrations/get-firebase-report.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```javascript
import { Client, Migrations, Resources } from "@appwrite.io/console";
import { Client, Migrations, FirebaseMigrationResource } from "@appwrite.io/console";

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
Expand All @@ -8,7 +8,7 @@ const client = new Client()
const migrations = new Migrations(client);

const result = await migrations.getFirebaseReport({
resources: [Resources.User],
resources: [FirebaseMigrationResource.User],
serviceAccount: '<SERVICE_ACCOUNT>'
});

Expand Down
4 changes: 2 additions & 2 deletions docs/examples/migrations/get-n-host-report.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```javascript
import { Client, Migrations, Resources } from "@appwrite.io/console";
import { Client, Migrations, NHostMigrationResource } from "@appwrite.io/console";

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
Expand All @@ -8,7 +8,7 @@ const client = new Client()
const migrations = new Migrations(client);

const result = await migrations.getNHostReport({
resources: [Resources.User],
resources: [NHostMigrationResource.User],
subdomain: '<SUBDOMAIN>',
region: '<REGION>',
adminSecret: '<ADMIN_SECRET>',
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/migrations/get-supabase-report.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```javascript
import { Client, Migrations, Resources } from "@appwrite.io/console";
import { Client, Migrations, SupabaseMigrationResource } from "@appwrite.io/console";

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
Expand All @@ -8,7 +8,7 @@ const client = new Client()
const migrations = new Migrations(client);

const result = await migrations.getSupabaseReport({
resources: [Resources.User],
resources: [SupabaseMigrationResource.User],
endpoint: 'https://example.com',
apiKey: '<API_KEY>',
databaseHost: '<DATABASE_HOST>',
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/sites/create-deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ const sites = new Sites(client);
const result = await sites.createDeployment({
siteId: '<SITE_ID>',
code: document.getElementById('uploader').files[0],
activate: false,
installCommand: '<INSTALL_COMMAND>', // optional
buildCommand: '<BUILD_COMMAND>', // optional
outputDirectory: '<OUTPUT_DIRECTORY>' // optional
outputDirectory: '<OUTPUT_DIRECTORY>', // optional
activate: false // optional
});

console.log(result);
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/tablesdb/list-rows.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const result = await tablesDB.listRows({
tableId: '<TABLE_ID>',
queries: [], // optional
transactionId: '<TRANSACTION_ID>', // optional
total: false // optional
total: false, // optional
ttl: 0 // optional
});

console.log(result);
Expand Down
34 changes: 19 additions & 15 deletions src/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ interface Resolved { _res: any }
type Actionable = Document | Row | File | Team | Membership;

function normalize(id: string): string {
const trimmed = id.trim();
return trimmed === "" ? "*" : trimmed;
if (id === undefined || id === null) {
throw new Error("Channel ID is required");
}
const trimmed = String(id).trim();
if (trimmed === "") {
throw new Error("Channel ID is required");
}
return trimmed;
}

export class Channel<T> {
Expand All @@ -44,9 +50,8 @@ export class Channel<T> {

// --- DATABASE ROUTE ---
// Only available on Channel<Database>
collection(this: Channel<Database>, id?: string): Channel<Collection> {
// Default: wildcard collection ID
return this.next<Collection>("collections", id ?? "*");
collection(this: Channel<Database>, id: string): Channel<Collection> {
return this.next<Collection>("collections", id);
}

// Only available on Channel<Collection>
Expand All @@ -56,9 +61,8 @@ export class Channel<T> {
}

// --- TABLESDB ROUTE ---
table(this: Channel<TablesDB>, id?: string): Channel<Table> {
// Default: wildcard table ID
return this.next<Table>("tables", id ?? "*");
table(this: Channel<TablesDB>, id: string): Channel<Table> {
return this.next<Table>("tables", id);
}

row(this: Channel<Table>, id?: string): Channel<Row> {
Expand Down Expand Up @@ -91,31 +95,31 @@ export class Channel<T> {
}

// --- ROOT FACTORIES ---
static database(id: string = "*") {
static database(id: string) {
return new Channel<Database>(["databases", normalize(id)]);
}

static execution(id: string = "*") {
static execution(id: string) {
return new Channel<Execution>(["executions", normalize(id)]);
}

static tablesdb(id: string = "*") {
static tablesdb(id: string) {
return new Channel<TablesDB>(["tablesdb", normalize(id)]);
}

static bucket(id: string = "*") {
static bucket(id: string) {
return new Channel<Bucket>(["buckets", normalize(id)]);
}

static function(id: string = "*") {
static function(id: string) {
return new Channel<Func>(["functions", normalize(id)]);
}

static team(id: string = "*") {
static team(id: string) {
return new Channel<Team>(["teams", normalize(id)]);
}

static membership(id: string = "*") {
static membership(id: string) {
return new Channel<Membership>(["memberships", normalize(id)]);
}

Expand Down
21 changes: 21 additions & 0 deletions src/enums/appwrite-migration-resource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export enum AppwriteMigrationResource {
User = 'user',
Team = 'team',
Membership = 'membership',
Database = 'database',
Table = 'table',
Column = 'column',
Index = 'index',
Row = 'row',
Document = 'document',
Attribute = 'attribute',
Collection = 'collection',
Bucket = 'bucket',
File = 'file',
Function = 'function',
Deployment = 'deployment',
Environmentvariable = 'environment-variable',
Site = 'site',
Sitedeployment = 'site-deployment',
Sitevariable = 'site-variable',
}
3 changes: 3 additions & 0 deletions src/enums/build-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export enum BuildRuntime {
Pythonml311 = 'python-ml-3.11',
Pythonml312 = 'python-ml-3.12',
Pythonml313 = 'python-ml-3.13',
Deno121 = 'deno-1.21',
Deno124 = 'deno-1.24',
Deno135 = 'deno-1.35',
Deno140 = 'deno-1.40',
Deno146 = 'deno-1.46',
Deno20 = 'deno-2.0',
Expand Down
12 changes: 12 additions & 0 deletions src/enums/firebase-migration-resource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export enum FirebaseMigrationResource {
User = 'user',
Database = 'database',
Table = 'table',
Column = 'column',
Row = 'row',
Document = 'document',
Attribute = 'attribute',
Collection = 'collection',
Bucket = 'bucket',
File = 'file',
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export enum Resources {
export enum NHostMigrationResource {
User = 'user',
Database = 'database',
Table = 'table',
Expand Down
3 changes: 3 additions & 0 deletions src/enums/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export enum Runtime {
Pythonml311 = 'python-ml-3.11',
Pythonml312 = 'python-ml-3.12',
Pythonml313 = 'python-ml-3.13',
Deno121 = 'deno-1.21',
Deno124 = 'deno-1.24',
Deno135 = 'deno-1.35',
Deno140 = 'deno-1.40',
Deno146 = 'deno-1.46',
Deno20 = 'deno-2.0',
Expand Down
3 changes: 3 additions & 0 deletions src/enums/runtimes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export enum Runtimes {
Pythonml311 = 'python-ml-3.11',
Pythonml312 = 'python-ml-3.12',
Pythonml313 = 'python-ml-3.13',
Deno121 = 'deno-1.21',
Deno124 = 'deno-1.24',
Deno135 = 'deno-1.35',
Deno140 = 'deno-1.40',
Deno146 = 'deno-1.46',
Deno20 = 'deno-2.0',
Expand Down
13 changes: 13 additions & 0 deletions src/enums/supabase-migration-resource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export enum SupabaseMigrationResource {
User = 'user',
Database = 'database',
Table = 'table',
Column = 'column',
Index = 'index',
Row = 'row',
Document = 'document',
Attribute = 'attribute',
Collection = 'collection',
Bucket = 'bucket',
File = 'file',
}
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ export { ExecutionMethod } from './enums/execution-method';
export { Name } from './enums/name';
export { MessagePriority } from './enums/message-priority';
export { SmtpEncryption } from './enums/smtp-encryption';
export { Resources } from './enums/resources';
export { AppwriteMigrationResource } from './enums/appwrite-migration-resource';
export { FirebaseMigrationResource } from './enums/firebase-migration-resource';
export { NHostMigrationResource } from './enums/n-host-migration-resource';
export { SupabaseMigrationResource } from './enums/supabase-migration-resource';
export { ProjectUsageRange } from './enums/project-usage-range';
export { Region } from './enums/region';
export { Api } from './enums/api';
Expand Down
Loading