-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheventing-function.js
More file actions
34 lines (28 loc) · 1 KB
/
eventing-function.js
File metadata and controls
34 lines (28 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Eventing Function skeleton
// Bindings required (configure in Eventing UI or REST API):
// src — source collection (read-only or read+write)
// dst — destination collection (read+write)
//
// Deploy settings:
// Feed boundary: "From now" (new mutations only) or "Everything" (backfill + new)
// Workers: 1–64 (scale with mutation rate)
function OnUpdate(doc, meta) {
// Guard: only process relevant document types
if (doc.type !== "REPLACE_TYPE") return;
// Guard: skip already-processed documents to prevent double mutations
if (doc.processed) return;
// --- Your logic here ---
// Write to destination collection
dst[meta.id] = Object.assign({}, doc, {
processed: true,
processedAt: new Date().toISOString()
});
}
function OnDelete(meta, options) {
// options.is_expiry — true if deleted by TTL expiry
if (options.is_expiry) {
log("Document expired:", meta.id);
}
// Cascade delete to destination
delete dst[meta.id];
}