| 44 | }; |
| 45 | |
| 46 | class SupabaseDatabase<Database = any> { |
| 47 | constructor( |
| 48 | private integration: SupabaseManagement, |
| 49 | private projectRef: string |
| 50 | ) {} |
| 51 | |
| 52 | /** |
| 53 | * The function `on` creates a trigger for when a record is inserted, updated, or deleted on a |
| 54 | * specific table in a database schema. |
| 55 | * @param params - The `params` parameter is an object that contains the following properties: |
| 56 | * @param params.table - The `table` property is a string that specifies the name of the table |
| 57 | * that the trigger will be created for. |
| 58 | * @param params.events - The `events` property is an array of events that specifies the events |
| 59 | * that the trigger will be called for. The events that can be specified are `INSERT`, `UPDATE`, or `DELETE`. |
| 60 | * By default, the trigger will be called for all events. |
| 61 | * @param params.schema - The `schema` property is a string that specifies the name of the schema |
| 62 | * that the trigger will be created for. If the schema is not specified, the default schema will |
| 63 | * be used. (public) |
| 64 | * @param params.filter - The `filter` property is an object that specifies the filter that will |
| 65 | * be used to determine if the trigger should be called. If the filter is not specified, the |
| 66 | * trigger will be called for all records. |
| 67 | * |
| 68 | * @example |
| 69 | * |
| 70 | * ```ts |
| 71 | * const supabase = new SupabaseManagement({ id: "supabase" }); |
| 72 | * const database = supabase.database<Database>("https://<project-id>.supabase.co"); |
| 73 | * |
| 74 | * client.defineJob({ |
| 75 | * trigger: database.on({ |
| 76 | * table: "todos", |
| 77 | * events: ["INSERTED", "UPDATED"], |
| 78 | * schema: "public", |
| 79 | * filter: { |
| 80 | * record: { is_completed: [false] }, |
| 81 | * }, |
| 82 | * }), |
| 83 | * }) |
| 84 | * ``` |
| 85 | */ |
| 86 | on< |
| 87 | SchemaName extends string & keyof Database = "public" extends keyof Database |
| 88 | ? "public" |
| 89 | : string & keyof Database, |
| 90 | Schema extends GenericSchema = Database[SchemaName] extends GenericSchema |
| 91 | ? Database[SchemaName] |
| 92 | : any, |
| 93 | TTableName extends string & keyof Schema["Tables"] = string & keyof Schema["Tables"], |
| 94 | TTable extends Schema["Tables"][TTableName] = Schema["Tables"][TTableName], |
| 95 | TEvents extends WebhookEvents[] = ["INSERT", "UPDATE", "DELETE"], |
| 96 | >(params: { table: TTableName; events?: TEvents; schema?: SchemaName; filter?: EventFilter }) { |
| 97 | return createTrigger<Prettify<UnionPayloads<TEvents, TTableName, SchemaName, TTable["Row"]>>>( |
| 98 | this.integration.source, |
| 99 | { |
| 100 | event: params.events ?? ["INSERT", "UPDATE", "DELETE"], |
| 101 | projectRef: this.projectRef, |
| 102 | ...params, |
| 103 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…