Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions examples/app-crm/src/hooks/opportunity.hook.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.

import type { Hook, HookContext } from '@objectstack/spec/data';
import { defineHook, type HookContext } from '@objectstack/spec/data';

/**
* Pin the probability to 100% when an opportunity is marked Closed Won,
* and 0% when Closed Lost. Demonstrates a basic before-update hook.
*/
export const OpportunityStageHook: Hook = {
export const OpportunityStageHook = defineHook({
name: 'opportunity_stage_probability',
object: 'crm_opportunity',
events: ['beforeInsert', 'beforeUpdate'],
Expand All @@ -16,4 +16,4 @@ export const OpportunityStageHook: Hook = {
if (input.stage === 'closed_won') input.probability = 100;
if (input.stage === 'closed_lost') input.probability = 0;
},
};
});
6 changes: 3 additions & 3 deletions examples/app-todo/src/objects/task.hook.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.

import { HookContext, Hook } from '@objectstack/spec/data';
import { defineHook, type HookContext } from '@objectstack/spec/data';

/**
* Lifecycle logic for `todo_task` — insert defaults and the completion stamp.
Expand Down Expand Up @@ -47,7 +47,7 @@ import { HookContext, Hook } from '@objectstack/spec/data';
* timestamp that every report and list view reads as fact. The same
* `readonly`/strip reasoning applies — only a hook can write the clear.
*/
const taskHook: Hook = {
const taskHook = defineHook({
name: 'task_logic',
object: 'todo_task',
events: ['beforeInsert', 'beforeUpdate', 'afterUpdate'],
Expand Down Expand Up @@ -120,6 +120,6 @@ const taskHook: Hook = {
// runs daily and selects on `due_date` directly.
}
}
};
});

export default taskHook;
Loading