Skip to content

Commit 2d31dde

Browse files
realtime updates in skills
1 parent d0c835d commit 2d31dde

File tree

4 files changed

+42
-23
lines changed

4 files changed

+42
-23
lines changed

templates/agent-skills/dart.md.twig

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,16 +260,19 @@ await teams.delete(teamId: '[TEAM_ID]');
260260
```dart
261261
final realtime = Realtime(client);
262262

263-
final subscription = realtime.subscribe(['tablesdb.[DATABASE_ID].tables.[TABLE_ID].rows']);
263+
// Subscribe to row changes
264+
final subscription = realtime.subscribe([
265+
Channel.tablesdb('[DATABASE_ID]').table('[TABLE_ID]').row(),
266+
]);
264267
subscription.stream.listen((response) {
265268
print(response.events); // e.g. ['tablesdb.*.tables.*.rows.*.create']
266269
print(response.payload); // the affected resource
267270
});
268271

269272
// Subscribe to multiple channels
270273
final multi = realtime.subscribe([
271-
'tablesdb.[DATABASE_ID].tables.[TABLE_ID].rows',
272-
'buckets.[BUCKET_ID].files',
274+
Channel.tablesdb('[DATABASE_ID]').table('[TABLE_ID]').row(),
275+
Channel.bucket('[BUCKET_ID]').file(),
273276
]);
274277

275278
// Cleanup

templates/agent-skills/kotlin.md.twig

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,17 +284,22 @@ teams.delete(teamId = "[TEAM_ID]")
284284
### Real-time Subscriptions (client-side)
285285

286286
```kotlin
287+
import io.{{ spec.title | caseLower }}.Channel
288+
287289
val realtime = Realtime(client)
288290

289-
val subscription = realtime.subscribe("tablesdb.[DATABASE_ID].tables.[TABLE_ID].rows") { response ->
291+
// Subscribe to row changes
292+
val subscription = realtime.subscribe(
293+
Channel.tablesdb("[DATABASE_ID]").table("[TABLE_ID]").row()
294+
) { response ->
290295
println(response.events) // e.g. ["tablesdb.*.tables.*.rows.*.create"]
291296
println(response.payload) // the affected resource
292297
}
293298

294299
// Subscribe to multiple channels
295300
val multi = realtime.subscribe(
296-
"tablesdb.[DATABASE_ID].tables.[TABLE_ID].rows",
297-
"buckets.[BUCKET_ID].files"
301+
Channel.tablesdb("[DATABASE_ID]").table("[TABLE_ID]").row(),
302+
Channel.bucket("[BUCKET_ID]").file()
298303
) { response -> /* ... */ }
299304

300305
// Cleanup

templates/agent-skills/swift.md.twig

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,19 +230,22 @@ try await teams.delete(teamId: "[TEAM_ID]")
230230
```swift
231231
let realtime = Realtime(client)
232232

233-
let subscription = realtime.subscribe(channels: ["tablesdb.[DATABASE_ID].tables.[TABLE_ID].rows"]) { response in
233+
// Subscribe to row changes
234+
let subscription = try await realtime.subscribe(channels: [
235+
Channel.tablesdb("[DATABASE_ID]").table("[TABLE_ID]").row()
236+
]) { response in
234237
print(response.events) // e.g. ["tablesdb.*.tables.*.rows.*.create"]
235238
print(response.payload) // the affected resource
236239
}
237240

238241
// Subscribe to multiple channels
239-
let multi = realtime.subscribe(channels: [
240-
"tablesdb.[DATABASE_ID].tables.[TABLE_ID].rows",
241-
"buckets.[BUCKET_ID].files",
242+
let multi = try await realtime.subscribe(channels: [
243+
Channel.tablesdb("[DATABASE_ID]").table("[TABLE_ID]").row(),
244+
Channel.files(),
242245
]) { response in /* ... */ }
243246

244247
// Cleanup
245-
subscription.close()
248+
try await subscription.close()
246249
```
247250

248251
**Available channels:**

templates/agent-skills/typescript.md.twig

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -422,25 +422,33 @@ await teams.delete({ teamId: '[TEAM_ID]' });
422422
### Real-time Subscriptions (client-side)
423423

424424
```typescript
425+
import { Realtime, Channel } from '{{ spec.title | caseLower }}';
426+
427+
const realtime = new Realtime(client);
428+
425429
// Subscribe to row changes
426-
const unsubscribe = client.subscribe('tablesdb.[DATABASE_ID].tables.[TABLE_ID].rows', (response) => {
427-
console.log(response.events); // e.g. ['tablesdb.*.tables.*.rows.*.create']
428-
console.log(response.payload); // the affected resource
429-
});
430+
const subscription = await realtime.subscribe(
431+
Channel.tablesdb('[DATABASE_ID]').table('[TABLE_ID]').row(),
432+
(response) => {
433+
console.log(response.events); // e.g. ['tablesdb.*.tables.*.rows.*.create']
434+
console.log(response.payload); // the affected resource
435+
}
436+
);
430437

431-
// Subscribe to file changes
432-
client.subscribe('buckets.[BUCKET_ID].files', (response) => {
433-
console.log(response.payload);
434-
});
438+
// Subscribe to a specific row
439+
await realtime.subscribe(
440+
Channel.tablesdb('[DATABASE_ID]').table('[TABLE_ID]').row('[ROW_ID]'),
441+
(response) => { /* ... */ }
442+
);
435443

436444
// Subscribe to multiple channels
437-
client.subscribe([
438-
'tablesdb.[DATABASE_ID].tables.[TABLE_ID].rows',
439-
'buckets.[BUCKET_ID].files',
445+
await realtime.subscribe([
446+
Channel.tablesdb('[DATABASE_ID]').table('[TABLE_ID]').row(),
447+
Channel.bucket('[BUCKET_ID]').file(),
440448
], (response) => { /* ... */ });
441449

442450
// Unsubscribe
443-
unsubscribe();
451+
await subscription.close();
444452
```
445453

446454
**Available channels:**

0 commit comments

Comments
 (0)