Skip to content

Commit 9ac5165

Browse files
Copilothotlong
andcommitted
Fix code review feedback: improve type safety in handlers and registration
- Replace `as string ?? value` with `? String(x) : default` pattern - Replace `Function` type with `(...args: unknown[]) => unknown` - Remove `as any` casts in config lifecycle hooks Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent b8659bc commit 9ac5165

7 files changed

Lines changed: 14 additions & 14 deletions

File tree

examples/app-crm/objectstack.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ import { registerCrmActionHandlers } from './src/actions/register-handlers';
3636
* Plugin lifecycle hook — called by AppPlugin when the engine is ready.
3737
* This is where action handlers are registered on the ObjectQL engine.
3838
*/
39-
export const onEnable = async (ctx: { ql: { registerAction: Function } }) => {
40-
registerCrmActionHandlers(ctx.ql as any);
39+
export const onEnable = async (ctx: { ql: { registerAction: (...args: unknown[]) => void } }) => {
40+
registerCrmActionHandlers(ctx.ql);
4141
};
4242

4343
export default defineStack({

examples/app-crm/src/actions/handlers/contact.handlers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ export async function sendEmail(ctx: ActionContext): Promise<{ activityId: strin
4343
const { record, engine, user, params } = ctx;
4444
const activity = await engine.insert('activity', {
4545
type: 'email',
46-
subject: params?.subject as string ?? `Email to ${record.email}`,
47-
body: params?.body as string ?? '',
46+
subject: params?.subject ? String(params.subject) : `Email to ${record.email}`,
47+
body: params?.body ? String(params.body) : '',
4848
contact_id: record._id as string,
4949
account_id: record.account_id as string,
5050
direction: 'outbound',

examples/app-crm/src/actions/handlers/global.handlers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ export async function logCall(ctx: ActionContext): Promise<{ activityId: string
4040
const { record, engine, user, params } = ctx;
4141
const activity = await engine.insert('activity', {
4242
type: 'call',
43-
subject: params?.subject as string,
44-
duration_minutes: params?.duration as number,
45-
notes: params?.notes as string ?? '',
43+
subject: params?.subject ? String(params.subject) : 'Untitled Call',
44+
duration_minutes: params?.duration ? Number(params.duration) : 0,
45+
notes: params?.notes ? String(params.notes) : '',
4646
related_to_id: record._id as string,
4747
direction: 'outbound',
4848
status: 'completed',

examples/app-crm/src/actions/register-handlers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ import {
7272
* ```
7373
*/
7474
export function registerCrmActionHandlers(engine: {
75-
registerAction(objectName: string, actionName: string, handler: Function): void;
75+
registerAction(objectName: string, actionName: string, handler: (...args: unknown[]) => unknown): void;
7676
}): void {
7777
// ─── Lead Domain ───────────────────────────────────────────────────
7878
// ConvertLeadAction (type: flow) — also has server-side handler for

examples/app-todo/objectstack.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import { registerTaskActionHandlers } from './src/actions/register-handlers';
2121
* Plugin lifecycle hook — called by AppPlugin when the engine is ready.
2222
* This is where action handlers are registered on the ObjectQL engine.
2323
*/
24-
export const onEnable = async (ctx: { ql: { registerAction: Function } }) => {
25-
registerTaskActionHandlers(ctx.ql as any);
24+
export const onEnable = async (ctx: { ql: { registerAction: (...args: unknown[]) => void } }) => {
25+
registerTaskActionHandlers(ctx.ql);
2626
};
2727

2828
export default defineStack({

examples/app-todo/src/actions/register-handlers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ import {
7676
* ```
7777
*/
7878
export function registerTaskActionHandlers(engine: {
79-
registerAction(objectName: string, actionName: string, handler: Function): void;
79+
registerAction(objectName: string, actionName: string, handler: (...args: unknown[]) => unknown): void;
8080
}): void {
8181
// ─── Script-type actions (server-side handlers) ────────────────────
8282
engine.registerAction('task', 'completeTask', completeTask);

examples/app-todo/src/actions/task.handlers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ export async function deleteCompletedTasks(ctx: ActionContext): Promise<void> {
8989
export async function deferTask(ctx: ActionContext): Promise<void> {
9090
const { record, engine, params } = ctx;
9191
await engine.update('task', record._id as string, {
92-
due_date: params?.new_due_date as string,
93-
defer_reason: params?.reason as string ?? null,
92+
due_date: params?.new_due_date ? String(params.new_due_date) : null,
93+
defer_reason: params?.reason ? String(params.reason) : null,
9494
status: 'waiting',
9595
});
9696
}
@@ -99,7 +99,7 @@ export async function deferTask(ctx: ActionContext): Promise<void> {
9999
export async function setReminder(ctx: ActionContext): Promise<void> {
100100
const { record, engine, params } = ctx;
101101
await engine.update('task', record._id as string, {
102-
reminder_date: params?.reminder_date as string,
102+
reminder_date: params?.reminder_date ? String(params.reminder_date) : null,
103103
has_reminder: true,
104104
});
105105
}

0 commit comments

Comments
 (0)