Repository navigation
Expand file tree
/
Copy pathhook.form.ts
More file actions
104 lines (102 loc) · 4.98 KB
/
Copy pathhook.form.ts
File metadata and controls
104 lines (102 loc) · 4.98 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { defineForm } from '../ui/view.zod';
/**
* Form Layout for Hook Metadata Type
*
* Hooks intercept the data lifecycle. The body field is a composite
* (`{ language, source, capabilities?, timeoutMs?, memoryMb? }`) whose
* `source` renders in a Monaco code editor with language-appropriate
* syntax highlighting. The body's refusal catalogue (`refusals`) sits beside it.
*/
export const hookForm = defineForm({
schemaId: 'hook',
type: 'simple',
sections: [
{
label: 'Identity',
description: 'What this hook is and when it fires.',
columns: 2,
fields: [
{ field: 'name', type: 'text', required: true, immutable: true, colSpan: 1, helpText: 'snake_case identifier (immutable after creation)' },
{ field: 'label', type: 'text', colSpan: 1 },
{ field: 'description', type: 'textarea', colSpan: 2 },
{ field: 'object', type: 'text', required: true, colSpan: 1, helpText: 'Target object name (or "*" for global)' },
{ field: 'events', type: 'tags', required: true, colSpan: 1, helpText: 'Lifecycle events (e.g. beforeInsert, afterUpdate)' },
{ field: 'priority', type: 'number', colSpan: 1, helpText: 'Lower numbers run first' },
],
},
{
label: 'Body',
description: 'Inline expression or sandboxed JavaScript executed when the hook fires.',
fields: [
{
field: 'body',
type: 'composite',
helpText: 'Either an L1 expression or an L2 sandboxed JS body',
fields: [
{ field: 'language', type: 'select', required: true, helpText: 'expression = pure formula; js = sandboxed JavaScript', options: [
{ label: 'Expression (L1)', value: 'expression' },
{ label: 'JavaScript (L2 sandboxed)', value: 'js' },
] },
{ field: 'source', type: 'code', language: 'javascript', required: true, helpText: 'Function body source — no top-level imports' },
{ field: 'capabilities', type: 'tags', helpText: 'Allowed ctx APIs (api.read, api.write, crypto.uuid, log, …)' },
{ field: 'timeoutMs', type: 'number', helpText: 'Per-invocation timeout (ms)' },
{ field: 'memoryMb', type: 'number', helpText: 'Per-invocation memory cap (MB, max 256)' },
],
},
// The catalogue is a record keyed by the code, and an entry has no
// member that echoes its key — so the row takes the key-only record
// control, which never writes the key into the entry (#26835).
{
field: 'refusals',
type: 'record',
widget: 'key-only-record',
helpText: 'Refusal catalogue, keyed by the SCREAMING_SNAKE code the body throws (e.g. CLEAN_VERSION_REQUIRED). The caller reads the declared message, translated into their language, with the declared status. JavaScript (L2) bodies only',
fields: [
{ field: 'message', type: 'textarea', required: true, helpText: 'The sentence the user reads when the body throws this code — plain text, with no placeholders' },
{ field: 'status', type: 'number', helpText: 'HTTP status of the refusal (400–499). Absent: 400' },
],
},
],
},
{
label: 'Legacy handler',
description: 'Function name reference — deprecated in favour of body.',
collapsible: true,
collapsed: true,
fields: [
{ field: 'handler', type: 'text', helpText: 'Handler function name (deprecated — prefer `body`)' },
],
},
{
label: 'Execution',
collapsible: true,
collapsed: true,
columns: 2,
fields: [
{ field: 'async', type: 'boolean', colSpan: 1, helpText: 'Run in background, do not block the transaction' },
{ field: 'onError', type: 'select', colSpan: 1, options: [
{ label: 'Abort', value: 'abort' },
{ label: 'Log', value: 'log' },
] },
{ field: 'timeoutMs', type: 'number', colSpan: 1, helpText: 'Abort the hook after N milliseconds' },
{ field: 'runAs', type: 'select', colSpan: 1, helpText: 'Identity for ctx.api data operations: inherit the triggering write (default), system (elevated), or user (the triggering user)', options: [
{ label: 'Inherit (triggering write)', value: 'inherit' },
{ label: 'System (elevated)', value: 'system' },
{ label: 'User (triggering user)', value: 'user' },
] },
{ field: 'condition', type: 'code', language: 'expression', colSpan: 2, helpText: 'CEL predicate — the hook runs only when TRUE' },
{
field: 'retryPolicy',
type: 'composite',
colSpan: 2,
helpText: 'Retry on failure — most useful for async hooks',
fields: [
{ field: 'maxRetries', type: 'number', helpText: 'Maximum retry attempts' },
{ field: 'backoffMs', type: 'number', helpText: 'Delay between retries (ms)' },
],
},
],
},
],
});