@objectstack/spec 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +134 -121
- package/dist/ai/agent.zod.d.ts +164 -0
- package/dist/ai/agent.zod.d.ts.map +1 -0
- package/dist/ai/agent.zod.js +51 -0
- package/dist/api/contract.zod.d.ts +1733 -0
- package/dist/api/contract.zod.d.ts.map +1 -0
- package/dist/api/contract.zod.js +138 -0
- package/dist/data/dataset.zod.d.ts +60 -0
- package/dist/data/dataset.zod.d.ts.map +1 -0
- package/dist/data/dataset.zod.js +54 -0
- package/dist/data/field.zod.d.ts +1808 -0
- package/dist/data/field.zod.d.ts.map +1 -0
- package/dist/data/field.zod.js +222 -0
- package/dist/data/flow.zod.d.ts +242 -0
- package/dist/data/flow.zod.d.ts.map +1 -0
- package/dist/data/flow.zod.js +77 -0
- package/dist/data/mapping.zod.d.ts +470 -0
- package/dist/data/mapping.zod.d.ts.map +1 -0
- package/dist/data/mapping.zod.js +65 -0
- package/dist/data/object.zod.d.ts +844 -0
- package/dist/data/object.zod.d.ts.map +1 -0
- package/dist/data/object.zod.js +81 -0
- package/dist/data/permission.zod.d.ts +163 -0
- package/dist/data/permission.zod.d.ts.map +1 -0
- package/dist/data/permission.zod.js +62 -0
- package/dist/data/query.zod.d.ts +438 -0
- package/dist/data/query.zod.d.ts.map +1 -0
- package/dist/data/query.zod.js +147 -0
- package/dist/data/sharing.zod.d.ts +63 -0
- package/dist/data/sharing.zod.d.ts.map +1 -0
- package/dist/data/sharing.zod.js +57 -0
- package/dist/data/trigger.zod.d.ts +354 -0
- package/dist/data/trigger.zod.d.ts.map +1 -0
- package/dist/data/trigger.zod.js +195 -0
- package/dist/data/validation.zod.d.ts +276 -0
- package/dist/data/validation.zod.d.ts.map +1 -0
- package/dist/data/validation.zod.js +105 -0
- package/dist/data/workflow.zod.d.ts +195 -0
- package/dist/data/workflow.zod.d.ts.map +1 -0
- package/dist/data/workflow.zod.js +64 -0
- package/dist/index.d.ts +41 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +62 -5
- package/dist/system/api.zod.d.ts +294 -0
- package/dist/system/api.zod.d.ts.map +1 -0
- package/dist/system/api.zod.js +56 -0
- package/dist/system/constants/index.d.ts +11 -0
- package/dist/system/constants/index.d.ts.map +1 -0
- package/dist/system/constants/index.js +26 -0
- package/dist/system/constants/paths.d.ts +71 -0
- package/dist/system/constants/paths.d.ts.map +1 -0
- package/dist/system/constants/paths.js +65 -0
- package/dist/system/datasource.zod.d.ts +210 -0
- package/dist/system/datasource.zod.d.ts.map +1 -0
- package/dist/system/datasource.zod.js +90 -0
- package/dist/system/discovery.zod.d.ts +174 -0
- package/dist/system/discovery.zod.d.ts.map +1 -0
- package/dist/system/discovery.zod.js +53 -0
- package/dist/system/driver.zod.d.ts +1525 -0
- package/dist/system/driver.zod.d.ts.map +1 -0
- package/dist/system/driver.zod.js +290 -0
- package/dist/system/identity.zod.d.ts +204 -0
- package/dist/system/identity.zod.d.ts.map +1 -0
- package/dist/system/identity.zod.js +68 -0
- package/dist/system/license.zod.d.ts +110 -0
- package/dist/system/license.zod.d.ts.map +1 -0
- package/dist/system/license.zod.js +63 -0
- package/dist/system/manifest.zod.d.ts +397 -0
- package/dist/system/manifest.zod.d.ts.map +1 -0
- package/dist/system/manifest.zod.js +142 -0
- package/dist/system/plugin.zod.d.ts +3516 -0
- package/dist/system/plugin.zod.d.ts.map +1 -0
- package/dist/system/plugin.zod.js +226 -0
- package/dist/system/policy.zod.d.ts +209 -0
- package/dist/system/policy.zod.d.ts.map +1 -0
- package/dist/system/policy.zod.js +54 -0
- package/dist/system/role.zod.d.ts +34 -0
- package/dist/system/role.zod.d.ts.map +1 -0
- package/dist/system/role.zod.js +25 -0
- package/dist/system/territory.zod.d.ts +91 -0
- package/dist/system/territory.zod.d.ts.map +1 -0
- package/dist/system/territory.zod.js +64 -0
- package/dist/system/translation.zod.d.ts +171 -0
- package/dist/system/translation.zod.d.ts.map +1 -0
- package/dist/system/translation.zod.js +34 -0
- package/dist/system/types/index.d.ts +7 -0
- package/dist/system/types/index.d.ts.map +1 -0
- package/dist/system/types/index.js +22 -0
- package/dist/system/types/plugin.d.ts +113 -0
- package/dist/system/types/plugin.d.ts.map +1 -0
- package/dist/system/types/plugin.js +6 -0
- package/dist/system/webhook.zod.d.ts +106 -0
- package/dist/system/webhook.zod.d.ts.map +1 -0
- package/dist/system/webhook.zod.js +56 -0
- package/dist/ui/action.zod.d.ts +155 -0
- package/dist/ui/action.zod.d.ts.map +1 -0
- package/dist/ui/action.zod.js +54 -0
- package/dist/ui/app.zod.d.ts +405 -0
- package/dist/ui/app.zod.d.ts.map +1 -0
- package/dist/ui/app.zod.js +138 -0
- package/dist/ui/dashboard.zod.d.ts +213 -0
- package/dist/ui/dashboard.zod.d.ts.map +1 -0
- package/dist/ui/dashboard.zod.js +72 -0
- package/dist/ui/page.zod.d.ts +187 -0
- package/dist/ui/page.zod.d.ts.map +1 -0
- package/dist/ui/page.zod.js +48 -0
- package/dist/ui/report.zod.d.ts +233 -0
- package/dist/ui/report.zod.d.ts.map +1 -0
- package/dist/ui/report.zod.js +74 -0
- package/dist/ui/theme.zod.d.ts +1221 -0
- package/dist/ui/theme.zod.d.ts.map +1 -0
- package/dist/ui/theme.zod.js +202 -0
- package/dist/ui/view.zod.d.ts +887 -0
- package/dist/ui/view.zod.d.ts.map +1 -0
- package/dist/ui/view.zod.js +83 -0
- package/dist/ui/widget.zod.d.ts +350 -0
- package/dist/ui/widget.zod.d.ts.map +1 -0
- package/dist/ui/widget.zod.js +66 -0
- package/json-schema/AIKnowledge.json +30 -0
- package/json-schema/AIModelConfig.json +41 -0
- package/json-schema/AITool.json +33 -0
- package/json-schema/Action.json +162 -0
- package/json-schema/ActionParam.json +82 -0
- package/json-schema/Address.json +40 -0
- package/json-schema/Agent.json +140 -0
- package/json-schema/AggregationFunction.json +19 -0
- package/json-schema/AggregationNode.json +42 -0
- package/json-schema/Animation.json +56 -0
- package/json-schema/ApiCapabilities.json +28 -0
- package/json-schema/ApiEndpoint.json +162 -0
- package/json-schema/ApiError.json +27 -0
- package/json-schema/ApiMapping.json +28 -0
- package/json-schema/ApiRoutes.json +41 -0
- package/json-schema/App.json +297 -0
- package/json-schema/AppBranding.json +24 -0
- package/json-schema/AsyncValidation.json +70 -0
- package/json-schema/AuditPolicy.json +31 -0
- package/json-schema/AuthProtocol.json +17 -0
- package/json-schema/AuthProvider.json +171 -0
- package/json-schema/BaseResponse.json +63 -0
- package/json-schema/BorderRadius.json +44 -0
- package/json-schema/Breakpoints.json +36 -0
- package/json-schema/BulkRequest.json +29 -0
- package/json-schema/BulkResponse.json +108 -0
- package/json-schema/CalendarConfig.json +28 -0
- package/json-schema/ChartType.json +19 -0
- package/json-schema/ColorPalette.json +83 -0
- package/json-schema/ConditionalValidation.json +793 -0
- package/json-schema/CreateRequest.json +20 -0
- package/json-schema/CrossFieldValidation.json +56 -0
- package/json-schema/CustomValidator.json +57 -0
- package/json-schema/Dashboard.json +117 -0
- package/json-schema/DashboardNavItem.json +42 -0
- package/json-schema/DashboardWidget.json +89 -0
- package/json-schema/Dataset.json +63 -0
- package/json-schema/DatasetMode.json +16 -0
- package/json-schema/Datasource.json +75 -0
- package/json-schema/DatasourceCapabilities.json +36 -0
- package/json-schema/DeleteResponse.json +68 -0
- package/json-schema/Discovery.json +114 -0
- package/json-schema/DriverCapabilities.json +39 -0
- package/json-schema/DriverDefinition.json +66 -0
- package/json-schema/DriverInterface.json +58 -0
- package/json-schema/DriverOptions.json +23 -0
- package/json-schema/DriverType.json +10 -0
- package/json-schema/EmailAlertAction.json +37 -0
- package/json-schema/ExportRequest.json +786 -0
- package/json-schema/Feature.json +51 -0
- package/json-schema/Field.json +290 -0
- package/json-schema/FieldMapping.json +83 -0
- package/json-schema/FieldNode.json +32 -0
- package/json-schema/FieldPermission.json +22 -0
- package/json-schema/FieldType.json +42 -0
- package/json-schema/FieldUpdateAction.json +32 -0
- package/json-schema/FieldWidgetProps.json +327 -0
- package/json-schema/FilterNode.json +52 -0
- package/json-schema/FilterOperator.json +26 -0
- package/json-schema/Flow.json +186 -0
- package/json-schema/FlowEdge.json +37 -0
- package/json-schema/FlowNode.json +65 -0
- package/json-schema/FlowNodeAction.json +24 -0
- package/json-schema/FlowVariable.json +34 -0
- package/json-schema/FormSection.json +42 -0
- package/json-schema/FormView.json +99 -0
- package/json-schema/FormatValidation.json +59 -0
- package/json-schema/GanttConfig.json +32 -0
- package/json-schema/GroupNavItem.json +42 -0
- package/json-schema/HttpMethod.json +16 -0
- package/json-schema/I18nContext.json +12 -0
- package/json-schema/Index.json +30 -0
- package/json-schema/JoinNode.json +455 -0
- package/json-schema/JoinType.json +15 -0
- package/json-schema/KanbanConfig.json +31 -0
- package/json-schema/LDAPConfig.json +39 -0
- package/json-schema/License.json +57 -0
- package/json-schema/ListRecordResponse.json +103 -0
- package/json-schema/ListView.json +153 -0
- package/json-schema/Locale.json +10 -0
- package/json-schema/LocationCoordinates.json +36 -0
- package/json-schema/Logger.json +25 -0
- package/json-schema/LogicOperator.json +14 -0
- package/json-schema/Manifest.json +315 -0
- package/json-schema/Mapping.json +598 -0
- package/json-schema/MenuItem.json +28 -0
- package/json-schema/MetricType.json +14 -0
- package/json-schema/ModificationResult.json +46 -0
- package/json-schema/NavigationItem.json +214 -0
- package/json-schema/NetworkPolicy.json +31 -0
- package/json-schema/OIDCConfig.json +46 -0
- package/json-schema/OWDModel.json +14 -0
- package/json-schema/Object.json +428 -0
- package/json-schema/ObjectCapabilities.json +62 -0
- package/json-schema/ObjectNavItem.json +46 -0
- package/json-schema/ObjectPermission.json +42 -0
- package/json-schema/ObjectQLClient.json +12 -0
- package/json-schema/Page.json +117 -0
- package/json-schema/PageComponent.json +36 -0
- package/json-schema/PageNavItem.json +47 -0
- package/json-schema/PageRegion.json +63 -0
- package/json-schema/PasswordPolicy.json +41 -0
- package/json-schema/PermissionSet.json +96 -0
- package/json-schema/Plan.json +53 -0
- package/json-schema/Plugin.json +20 -0
- package/json-schema/PluginContext.json +91 -0
- package/json-schema/PluginLifecycle.json +11 -0
- package/json-schema/Policy.json +138 -0
- package/json-schema/Query.json +456 -0
- package/json-schema/RateLimit.json +26 -0
- package/json-schema/RecordData.json +11 -0
- package/json-schema/Report.json +219 -0
- package/json-schema/ReportChart.json +45 -0
- package/json-schema/ReportColumn.json +35 -0
- package/json-schema/ReportGrouping.json +38 -0
- package/json-schema/ReportType.json +15 -0
- package/json-schema/Role.json +32 -0
- package/json-schema/Router.json +12 -0
- package/json-schema/SAMLConfig.json +44 -0
- package/json-schema/Scheduler.json +12 -0
- package/json-schema/ScopedStorage.json +12 -0
- package/json-schema/ScriptValidation.json +48 -0
- package/json-schema/SelectOption.json +32 -0
- package/json-schema/SessionPolicy.json +27 -0
- package/json-schema/Shadow.json +44 -0
- package/json-schema/SharingLevel.json +13 -0
- package/json-schema/SharingRule.json +58 -0
- package/json-schema/SharingRuleType.json +15 -0
- package/json-schema/SingleRecordResponse.json +69 -0
- package/json-schema/SortNode.json +26 -0
- package/json-schema/Spacing.json +64 -0
- package/json-schema/StateMachineValidation.json +59 -0
- package/json-schema/SystemAPI.json +12 -0
- package/json-schema/Territory.json +77 -0
- package/json-schema/TerritoryModel.json +34 -0
- package/json-schema/TerritoryType.json +15 -0
- package/json-schema/Theme.json +543 -0
- package/json-schema/ThemeMode.json +14 -0
- package/json-schema/TransformType.json +18 -0
- package/json-schema/TranslationBundle.json +78 -0
- package/json-schema/TranslationData.json +75 -0
- package/json-schema/Trigger.json +73 -0
- package/json-schema/TriggerAction.json +14 -0
- package/json-schema/TriggerContext.json +61 -0
- package/json-schema/TriggerTiming.json +13 -0
- package/json-schema/Typography.json +142 -0
- package/json-schema/UniquenessValidation.json +59 -0
- package/json-schema/UpdateRequest.json +20 -0
- package/json-schema/UrlNavItem.json +51 -0
- package/json-schema/ValidationRule.json +794 -0
- package/json-schema/View.json +500 -0
- package/json-schema/Webhook.json +88 -0
- package/json-schema/WebhookReceiver.json +66 -0
- package/json-schema/WebhookTriggerType.json +16 -0
- package/json-schema/WindowFunction.json +24 -0
- package/json-schema/WindowFunctionNode.json +104 -0
- package/json-schema/WindowSpec.json +65 -0
- package/json-schema/WorkflowAction.json +84 -0
- package/json-schema/WorkflowRule.json +128 -0
- package/json-schema/WorkflowTriggerType.json +16 -0
- package/json-schema/ZIndex.json +44 -0
- package/package.json +34 -20
- package/dist/examples.d.ts +0 -28
- package/dist/examples.d.ts.map +0 -1
- package/dist/examples.js +0 -250
- package/dist/types/index.d.ts +0 -9
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -8
- package/dist/types/meta/field-type.d.ts +0 -54
- package/dist/types/meta/field-type.d.ts.map +0 -1
- package/dist/types/meta/field-type.js +0 -42
- package/dist/types/meta/index.d.ts +0 -13
- package/dist/types/meta/index.d.ts.map +0 -1
- package/dist/types/meta/index.js +0 -12
- package/dist/types/meta/object-entity.d.ts +0 -246
- package/dist/types/meta/object-entity.d.ts.map +0 -1
- package/dist/types/meta/object-entity.js +0 -9
- package/dist/types/meta/object-field.d.ts +0 -199
- package/dist/types/meta/object-field.d.ts.map +0 -1
- package/dist/types/meta/object-field.js +0 -9
- package/dist/types/meta/object-view.d.ts +0 -430
- package/dist/types/meta/object-view.d.ts.map +0 -1
- package/dist/types/meta/object-view.js +0 -9
- package/src/examples.ts +0 -257
- package/src/index.ts +0 -10
- package/src/types/index.ts +0 -9
- package/src/types/meta/field-type.ts +0 -91
- package/src/types/meta/index.ts +0 -13
- package/src/types/meta/object-entity.ts +0 -265
- package/src/types/meta/object-field.ts +0 -218
- package/src/types/meta/object-view.ts +0 -475
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OWDModel = exports.SharingRuleSchema = exports.SharingLevel = exports.SharingRuleType = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
/**
|
|
6
|
+
* Sharing Rule Type
|
|
7
|
+
* How is the data shared?
|
|
8
|
+
*/
|
|
9
|
+
exports.SharingRuleType = zod_1.z.enum([
|
|
10
|
+
'owner', // Based on record ownership (Role Hierarchy)
|
|
11
|
+
'criteria', // Based on field values (e.g. Status = 'Open')
|
|
12
|
+
'manual', // Ad-hoc sharing (User specific)
|
|
13
|
+
'guest' // Public access
|
|
14
|
+
]);
|
|
15
|
+
/**
|
|
16
|
+
* Sharing Level
|
|
17
|
+
* What access is granted?
|
|
18
|
+
*/
|
|
19
|
+
exports.SharingLevel = zod_1.z.enum([
|
|
20
|
+
'read', // Read Only
|
|
21
|
+
'edit' // Read / Write
|
|
22
|
+
]);
|
|
23
|
+
/**
|
|
24
|
+
* Sharing Rule Schema
|
|
25
|
+
* Defines AUTOMATIC access grants based on logic.
|
|
26
|
+
* The core engine of the governance layer.
|
|
27
|
+
*/
|
|
28
|
+
exports.SharingRuleSchema = zod_1.z.object({
|
|
29
|
+
name: zod_1.z.string().regex(/^[a-z_][a-z0-9_]*$/).describe('Unique rule name'),
|
|
30
|
+
label: zod_1.z.string().optional(),
|
|
31
|
+
active: zod_1.z.boolean().default(true),
|
|
32
|
+
/** Target Object */
|
|
33
|
+
object: zod_1.z.string().describe('Object to share'),
|
|
34
|
+
/** Grant Logic */
|
|
35
|
+
type: exports.SharingRuleType.default('criteria'),
|
|
36
|
+
/**
|
|
37
|
+
* Criteria (for type='criteria')
|
|
38
|
+
* SQL-like condition: "department = 'Sales' AND amount > 10000"
|
|
39
|
+
*/
|
|
40
|
+
criteria: zod_1.z.string().optional(),
|
|
41
|
+
/** Access Level */
|
|
42
|
+
accessLevel: exports.SharingLevel.default('read'),
|
|
43
|
+
/**
|
|
44
|
+
* Target Audience (Whom to share with)
|
|
45
|
+
* ID of a Group, Role, or User.
|
|
46
|
+
*/
|
|
47
|
+
sharedWith: zod_1.z.string().describe('Group/Role ID to share records with'),
|
|
48
|
+
});
|
|
49
|
+
/**
|
|
50
|
+
* Organization-Wide Defaults (OWD)
|
|
51
|
+
* The baseline security posture for an object.
|
|
52
|
+
*/
|
|
53
|
+
exports.OWDModel = zod_1.z.enum([
|
|
54
|
+
'private', // Only owner can see
|
|
55
|
+
'public_read', // Everyone can see, owner can edit
|
|
56
|
+
'public_read_write' // Everyone can see and edit
|
|
57
|
+
]);
|
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Trigger Action Enum
|
|
4
|
+
*
|
|
5
|
+
* Defines the database operation that triggered the execution.
|
|
6
|
+
*/
|
|
7
|
+
export declare const TriggerAction: z.ZodEnum<["insert", "update", "delete"]>;
|
|
8
|
+
/**
|
|
9
|
+
* Trigger Timing Enum
|
|
10
|
+
*
|
|
11
|
+
* Defines when the trigger executes relative to the database operation.
|
|
12
|
+
*/
|
|
13
|
+
export declare const TriggerTiming: z.ZodEnum<["before", "after"]>;
|
|
14
|
+
/**
|
|
15
|
+
* Trigger Context Schema
|
|
16
|
+
*
|
|
17
|
+
* This defines the runtime context available to trigger code during execution.
|
|
18
|
+
* Standardizes how trigger code is written and enables AI code generation.
|
|
19
|
+
*
|
|
20
|
+
* Triggers are business logic hooks that execute before or after database operations.
|
|
21
|
+
* They can validate data, set defaults, update related records, or prevent operations.
|
|
22
|
+
*
|
|
23
|
+
* @example Before Insert Trigger
|
|
24
|
+
* export default {
|
|
25
|
+
* timing: 'before',
|
|
26
|
+
* action: 'insert',
|
|
27
|
+
* execute: async (context: TriggerContext) => {
|
|
28
|
+
* // Set default values
|
|
29
|
+
* if (!context.doc.status) {
|
|
30
|
+
* context.doc.status = 'active';
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* // Validation
|
|
34
|
+
* if (!context.doc.email) {
|
|
35
|
+
* context.addError('Email is required');
|
|
36
|
+
* }
|
|
37
|
+
* }
|
|
38
|
+
* };
|
|
39
|
+
*
|
|
40
|
+
* @example After Update Trigger
|
|
41
|
+
* export default {
|
|
42
|
+
* timing: 'after',
|
|
43
|
+
* action: 'update',
|
|
44
|
+
* execute: async (context: TriggerContext) => {
|
|
45
|
+
* // Update related records
|
|
46
|
+
* if (context.getOldValue('status') !== context.doc.status) {
|
|
47
|
+
* await context.ql.object('activity_log').create({
|
|
48
|
+
* record_id: context.doc.id,
|
|
49
|
+
* message: `Status changed from ${context.getOldValue('status')} to ${context.doc.status}`,
|
|
50
|
+
* user_id: context.userId,
|
|
51
|
+
* });
|
|
52
|
+
* }
|
|
53
|
+
* }
|
|
54
|
+
* };
|
|
55
|
+
*/
|
|
56
|
+
export declare const TriggerContextSchema: z.ZodObject<{
|
|
57
|
+
/**
|
|
58
|
+
* The database operation that triggered execution.
|
|
59
|
+
* One of: 'insert', 'update', 'delete'
|
|
60
|
+
*/
|
|
61
|
+
action: z.ZodEnum<["insert", "update", "delete"]>;
|
|
62
|
+
/**
|
|
63
|
+
* When the trigger executes relative to the operation.
|
|
64
|
+
* - 'before': Execute before database operation (can modify doc, prevent operation)
|
|
65
|
+
* - 'after': Execute after database operation (can trigger side effects)
|
|
66
|
+
*/
|
|
67
|
+
timing: z.ZodEnum<["before", "after"]>;
|
|
68
|
+
/**
|
|
69
|
+
* The current document/record being operated on.
|
|
70
|
+
*
|
|
71
|
+
* For 'before' triggers: Can be modified to change what gets saved.
|
|
72
|
+
* For 'after' triggers: Contains the final saved state (read-only).
|
|
73
|
+
* For 'delete' triggers: Contains the record being deleted.
|
|
74
|
+
*/
|
|
75
|
+
doc: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
76
|
+
/**
|
|
77
|
+
* The document state before the current operation.
|
|
78
|
+
*
|
|
79
|
+
* Only available for 'update' and 'delete' operations.
|
|
80
|
+
* Null for 'insert' operations.
|
|
81
|
+
*
|
|
82
|
+
* Use this to detect what changed in an update trigger.
|
|
83
|
+
*/
|
|
84
|
+
previousDoc: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
85
|
+
/**
|
|
86
|
+
* ID of the user performing the operation.
|
|
87
|
+
*/
|
|
88
|
+
userId: z.ZodString;
|
|
89
|
+
/**
|
|
90
|
+
* Complete user record of the user performing the operation.
|
|
91
|
+
* Contains fields like name, email, roles, etc.
|
|
92
|
+
*/
|
|
93
|
+
user: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
94
|
+
/**
|
|
95
|
+
* ObjectQL data access API.
|
|
96
|
+
* Use this to query or modify other records.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* await context.ql.object('account').findOne(context.doc.account_id);
|
|
100
|
+
* await context.ql.object('activity').create({ ... });
|
|
101
|
+
*/
|
|
102
|
+
ql: z.ZodAny;
|
|
103
|
+
/**
|
|
104
|
+
* Logging interface.
|
|
105
|
+
* Use this for debugging and auditing.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* context.logger.info('Trigger executed', { recordId: context.doc.id });
|
|
109
|
+
* context.logger.error('Validation failed', { error });
|
|
110
|
+
*/
|
|
111
|
+
logger: z.ZodAny;
|
|
112
|
+
/**
|
|
113
|
+
* Add a validation error.
|
|
114
|
+
* For 'before' triggers only - prevents the operation from completing.
|
|
115
|
+
*
|
|
116
|
+
* @param message - Error message to display
|
|
117
|
+
* @param field - Optional field name the error relates to
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* if (context.doc.amount < 0) {
|
|
121
|
+
* context.addError('Amount must be positive', 'amount');
|
|
122
|
+
* }
|
|
123
|
+
*/
|
|
124
|
+
addError: z.ZodFunction<z.ZodTuple<[z.ZodString, z.ZodOptional<z.ZodString>], z.ZodUnknown>, z.ZodVoid>;
|
|
125
|
+
/**
|
|
126
|
+
* Get the old value of a field.
|
|
127
|
+
* Helper function for 'update' triggers to easily compare old vs new values.
|
|
128
|
+
*
|
|
129
|
+
* @param fieldName - Name of the field
|
|
130
|
+
* @returns Previous value of the field, or undefined if not available
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* if (context.getOldValue('status') !== context.doc.status) {
|
|
134
|
+
* // Status changed
|
|
135
|
+
* }
|
|
136
|
+
*/
|
|
137
|
+
getOldValue: z.ZodFunction<z.ZodTuple<[z.ZodString], z.ZodUnknown>, z.ZodAny>;
|
|
138
|
+
}, "strip", z.ZodTypeAny, {
|
|
139
|
+
user: Record<string, any>;
|
|
140
|
+
action: "update" | "delete" | "insert";
|
|
141
|
+
timing: "before" | "after";
|
|
142
|
+
doc: Record<string, any>;
|
|
143
|
+
userId: string;
|
|
144
|
+
addError: (args_0: string, args_1: string | undefined, ...args: unknown[]) => void;
|
|
145
|
+
getOldValue: (args_0: string, ...args: unknown[]) => any;
|
|
146
|
+
previousDoc?: Record<string, any> | undefined;
|
|
147
|
+
ql?: any;
|
|
148
|
+
logger?: any;
|
|
149
|
+
}, {
|
|
150
|
+
user: Record<string, any>;
|
|
151
|
+
action: "update" | "delete" | "insert";
|
|
152
|
+
timing: "before" | "after";
|
|
153
|
+
doc: Record<string, any>;
|
|
154
|
+
userId: string;
|
|
155
|
+
addError: (args_0: string, args_1: string | undefined, ...args: unknown[]) => void;
|
|
156
|
+
getOldValue: (args_0: string, ...args: unknown[]) => any;
|
|
157
|
+
previousDoc?: Record<string, any> | undefined;
|
|
158
|
+
ql?: any;
|
|
159
|
+
logger?: any;
|
|
160
|
+
}>;
|
|
161
|
+
/**
|
|
162
|
+
* Trigger Definition Schema
|
|
163
|
+
*
|
|
164
|
+
* Complete definition of a trigger including metadata and execution function.
|
|
165
|
+
*/
|
|
166
|
+
export declare const TriggerSchema: z.ZodObject<{
|
|
167
|
+
/**
|
|
168
|
+
* Unique trigger name.
|
|
169
|
+
*/
|
|
170
|
+
name: z.ZodString;
|
|
171
|
+
/**
|
|
172
|
+
* Object this trigger is attached to.
|
|
173
|
+
*/
|
|
174
|
+
object: z.ZodString;
|
|
175
|
+
/**
|
|
176
|
+
* Trigger timing.
|
|
177
|
+
*/
|
|
178
|
+
timing: z.ZodEnum<["before", "after"]>;
|
|
179
|
+
/**
|
|
180
|
+
* Trigger action(s).
|
|
181
|
+
* Can be a single action or array of actions.
|
|
182
|
+
*/
|
|
183
|
+
action: z.ZodUnion<[z.ZodEnum<["insert", "update", "delete"]>, z.ZodArray<z.ZodEnum<["insert", "update", "delete"]>, "many">]>;
|
|
184
|
+
/**
|
|
185
|
+
* Trigger execution function.
|
|
186
|
+
* Receives TriggerContext and performs the business logic.
|
|
187
|
+
*/
|
|
188
|
+
execute: z.ZodFunction<z.ZodTuple<[z.ZodObject<{
|
|
189
|
+
/**
|
|
190
|
+
* The database operation that triggered execution.
|
|
191
|
+
* One of: 'insert', 'update', 'delete'
|
|
192
|
+
*/
|
|
193
|
+
action: z.ZodEnum<["insert", "update", "delete"]>;
|
|
194
|
+
/**
|
|
195
|
+
* When the trigger executes relative to the operation.
|
|
196
|
+
* - 'before': Execute before database operation (can modify doc, prevent operation)
|
|
197
|
+
* - 'after': Execute after database operation (can trigger side effects)
|
|
198
|
+
*/
|
|
199
|
+
timing: z.ZodEnum<["before", "after"]>;
|
|
200
|
+
/**
|
|
201
|
+
* The current document/record being operated on.
|
|
202
|
+
*
|
|
203
|
+
* For 'before' triggers: Can be modified to change what gets saved.
|
|
204
|
+
* For 'after' triggers: Contains the final saved state (read-only).
|
|
205
|
+
* For 'delete' triggers: Contains the record being deleted.
|
|
206
|
+
*/
|
|
207
|
+
doc: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
208
|
+
/**
|
|
209
|
+
* The document state before the current operation.
|
|
210
|
+
*
|
|
211
|
+
* Only available for 'update' and 'delete' operations.
|
|
212
|
+
* Null for 'insert' operations.
|
|
213
|
+
*
|
|
214
|
+
* Use this to detect what changed in an update trigger.
|
|
215
|
+
*/
|
|
216
|
+
previousDoc: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
217
|
+
/**
|
|
218
|
+
* ID of the user performing the operation.
|
|
219
|
+
*/
|
|
220
|
+
userId: z.ZodString;
|
|
221
|
+
/**
|
|
222
|
+
* Complete user record of the user performing the operation.
|
|
223
|
+
* Contains fields like name, email, roles, etc.
|
|
224
|
+
*/
|
|
225
|
+
user: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
226
|
+
/**
|
|
227
|
+
* ObjectQL data access API.
|
|
228
|
+
* Use this to query or modify other records.
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* await context.ql.object('account').findOne(context.doc.account_id);
|
|
232
|
+
* await context.ql.object('activity').create({ ... });
|
|
233
|
+
*/
|
|
234
|
+
ql: z.ZodAny;
|
|
235
|
+
/**
|
|
236
|
+
* Logging interface.
|
|
237
|
+
* Use this for debugging and auditing.
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* context.logger.info('Trigger executed', { recordId: context.doc.id });
|
|
241
|
+
* context.logger.error('Validation failed', { error });
|
|
242
|
+
*/
|
|
243
|
+
logger: z.ZodAny;
|
|
244
|
+
/**
|
|
245
|
+
* Add a validation error.
|
|
246
|
+
* For 'before' triggers only - prevents the operation from completing.
|
|
247
|
+
*
|
|
248
|
+
* @param message - Error message to display
|
|
249
|
+
* @param field - Optional field name the error relates to
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* if (context.doc.amount < 0) {
|
|
253
|
+
* context.addError('Amount must be positive', 'amount');
|
|
254
|
+
* }
|
|
255
|
+
*/
|
|
256
|
+
addError: z.ZodFunction<z.ZodTuple<[z.ZodString, z.ZodOptional<z.ZodString>], z.ZodUnknown>, z.ZodVoid>;
|
|
257
|
+
/**
|
|
258
|
+
* Get the old value of a field.
|
|
259
|
+
* Helper function for 'update' triggers to easily compare old vs new values.
|
|
260
|
+
*
|
|
261
|
+
* @param fieldName - Name of the field
|
|
262
|
+
* @returns Previous value of the field, or undefined if not available
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* if (context.getOldValue('status') !== context.doc.status) {
|
|
266
|
+
* // Status changed
|
|
267
|
+
* }
|
|
268
|
+
*/
|
|
269
|
+
getOldValue: z.ZodFunction<z.ZodTuple<[z.ZodString], z.ZodUnknown>, z.ZodAny>;
|
|
270
|
+
}, "strip", z.ZodTypeAny, {
|
|
271
|
+
user: Record<string, any>;
|
|
272
|
+
action: "update" | "delete" | "insert";
|
|
273
|
+
timing: "before" | "after";
|
|
274
|
+
doc: Record<string, any>;
|
|
275
|
+
userId: string;
|
|
276
|
+
addError: (args_0: string, args_1: string | undefined, ...args: unknown[]) => void;
|
|
277
|
+
getOldValue: (args_0: string, ...args: unknown[]) => any;
|
|
278
|
+
previousDoc?: Record<string, any> | undefined;
|
|
279
|
+
ql?: any;
|
|
280
|
+
logger?: any;
|
|
281
|
+
}, {
|
|
282
|
+
user: Record<string, any>;
|
|
283
|
+
action: "update" | "delete" | "insert";
|
|
284
|
+
timing: "before" | "after";
|
|
285
|
+
doc: Record<string, any>;
|
|
286
|
+
userId: string;
|
|
287
|
+
addError: (args_0: string, args_1: string | undefined, ...args: unknown[]) => void;
|
|
288
|
+
getOldValue: (args_0: string, ...args: unknown[]) => any;
|
|
289
|
+
previousDoc?: Record<string, any> | undefined;
|
|
290
|
+
ql?: any;
|
|
291
|
+
logger?: any;
|
|
292
|
+
}>], z.ZodUnknown>, z.ZodPromise<z.ZodVoid>>;
|
|
293
|
+
/**
|
|
294
|
+
* Optional description of what the trigger does.
|
|
295
|
+
*/
|
|
296
|
+
description: z.ZodOptional<z.ZodString>;
|
|
297
|
+
/**
|
|
298
|
+
* Whether the trigger is active.
|
|
299
|
+
*/
|
|
300
|
+
active: z.ZodDefault<z.ZodBoolean>;
|
|
301
|
+
/**
|
|
302
|
+
* Execution order when multiple triggers are defined.
|
|
303
|
+
* Lower numbers execute first.
|
|
304
|
+
*/
|
|
305
|
+
order: z.ZodDefault<z.ZodNumber>;
|
|
306
|
+
}, "strip", z.ZodTypeAny, {
|
|
307
|
+
object: string;
|
|
308
|
+
name: string;
|
|
309
|
+
active: boolean;
|
|
310
|
+
order: number;
|
|
311
|
+
action: "update" | "delete" | "insert" | ("update" | "delete" | "insert")[];
|
|
312
|
+
timing: "before" | "after";
|
|
313
|
+
execute: (args_0: {
|
|
314
|
+
user: Record<string, any>;
|
|
315
|
+
action: "update" | "delete" | "insert";
|
|
316
|
+
timing: "before" | "after";
|
|
317
|
+
doc: Record<string, any>;
|
|
318
|
+
userId: string;
|
|
319
|
+
addError: (args_0: string, args_1: string | undefined, ...args: unknown[]) => void;
|
|
320
|
+
getOldValue: (args_0: string, ...args: unknown[]) => any;
|
|
321
|
+
previousDoc?: Record<string, any> | undefined;
|
|
322
|
+
ql?: any;
|
|
323
|
+
logger?: any;
|
|
324
|
+
}, ...args: unknown[]) => Promise<void>;
|
|
325
|
+
description?: string | undefined;
|
|
326
|
+
}, {
|
|
327
|
+
object: string;
|
|
328
|
+
name: string;
|
|
329
|
+
action: "update" | "delete" | "insert" | ("update" | "delete" | "insert")[];
|
|
330
|
+
timing: "before" | "after";
|
|
331
|
+
execute: (args_0: {
|
|
332
|
+
user: Record<string, any>;
|
|
333
|
+
action: "update" | "delete" | "insert";
|
|
334
|
+
timing: "before" | "after";
|
|
335
|
+
doc: Record<string, any>;
|
|
336
|
+
userId: string;
|
|
337
|
+
addError: (args_0: string, args_1: string | undefined, ...args: unknown[]) => void;
|
|
338
|
+
getOldValue: (args_0: string, ...args: unknown[]) => any;
|
|
339
|
+
previousDoc?: Record<string, any> | undefined;
|
|
340
|
+
ql?: any;
|
|
341
|
+
logger?: any;
|
|
342
|
+
}, ...args: unknown[]) => Promise<void>;
|
|
343
|
+
description?: string | undefined;
|
|
344
|
+
active?: boolean | undefined;
|
|
345
|
+
order?: number | undefined;
|
|
346
|
+
}>;
|
|
347
|
+
/**
|
|
348
|
+
* TypeScript types
|
|
349
|
+
*/
|
|
350
|
+
export type TriggerAction = z.infer<typeof TriggerAction>;
|
|
351
|
+
export type TriggerTiming = z.infer<typeof TriggerTiming>;
|
|
352
|
+
export type TriggerContext = z.infer<typeof TriggerContextSchema>;
|
|
353
|
+
export type Trigger = z.infer<typeof TriggerSchema>;
|
|
354
|
+
//# sourceMappingURL=trigger.zod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trigger.zod.d.ts","sourceRoot":"","sources":["../../src/data/trigger.zod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;GAIG;AACH,eAAO,MAAM,aAAa,2CAAyC,CAAC;AAEpE;;;;GAIG;AACH,eAAO,MAAM,aAAa,gCAA8B,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,eAAO,MAAM,oBAAoB;IAC/B;;;OAGG;;IAGH;;;;OAIG;;IAGH;;;;;;OAMG;;IAGH;;;;;;;OAOG;;IAGH;;OAEG;;IAGH;;;OAGG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;;;;;OAWG;;IAMH;;;;;;;;;;;OAWG;;;;;;;;;;;;;;;;;;;;;;;;EAKH,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,aAAa;IACxB;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;;OAGG;;IAMH;;;OAGG;;QAnIH;;;WAGG;;QAGH;;;;WAIG;;QAGH;;;;;;WAMG;;QAGH;;;;;;;WAOG;;QAGH;;WAEG;;QAGH;;;WAGG;;QAGH;;;;;;;WAOG;;QAGH;;;;;;;WAOG;;QAGH;;;;;;;;;;;WAWG;;QAMH;;;;;;;;;;;WAWG;;;;;;;;;;;;;;;;;;;;;;;;;IA8CH;;OAEG;;IAGH;;OAEG;;IAGH;;;OAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAEH,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAC1D,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAC1D,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAClE,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TriggerSchema = exports.TriggerContextSchema = exports.TriggerTiming = exports.TriggerAction = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
/**
|
|
6
|
+
* Trigger Action Enum
|
|
7
|
+
*
|
|
8
|
+
* Defines the database operation that triggered the execution.
|
|
9
|
+
*/
|
|
10
|
+
exports.TriggerAction = zod_1.z.enum(['insert', 'update', 'delete']);
|
|
11
|
+
/**
|
|
12
|
+
* Trigger Timing Enum
|
|
13
|
+
*
|
|
14
|
+
* Defines when the trigger executes relative to the database operation.
|
|
15
|
+
*/
|
|
16
|
+
exports.TriggerTiming = zod_1.z.enum(['before', 'after']);
|
|
17
|
+
/**
|
|
18
|
+
* Trigger Context Schema
|
|
19
|
+
*
|
|
20
|
+
* This defines the runtime context available to trigger code during execution.
|
|
21
|
+
* Standardizes how trigger code is written and enables AI code generation.
|
|
22
|
+
*
|
|
23
|
+
* Triggers are business logic hooks that execute before or after database operations.
|
|
24
|
+
* They can validate data, set defaults, update related records, or prevent operations.
|
|
25
|
+
*
|
|
26
|
+
* @example Before Insert Trigger
|
|
27
|
+
* export default {
|
|
28
|
+
* timing: 'before',
|
|
29
|
+
* action: 'insert',
|
|
30
|
+
* execute: async (context: TriggerContext) => {
|
|
31
|
+
* // Set default values
|
|
32
|
+
* if (!context.doc.status) {
|
|
33
|
+
* context.doc.status = 'active';
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* // Validation
|
|
37
|
+
* if (!context.doc.email) {
|
|
38
|
+
* context.addError('Email is required');
|
|
39
|
+
* }
|
|
40
|
+
* }
|
|
41
|
+
* };
|
|
42
|
+
*
|
|
43
|
+
* @example After Update Trigger
|
|
44
|
+
* export default {
|
|
45
|
+
* timing: 'after',
|
|
46
|
+
* action: 'update',
|
|
47
|
+
* execute: async (context: TriggerContext) => {
|
|
48
|
+
* // Update related records
|
|
49
|
+
* if (context.getOldValue('status') !== context.doc.status) {
|
|
50
|
+
* await context.ql.object('activity_log').create({
|
|
51
|
+
* record_id: context.doc.id,
|
|
52
|
+
* message: `Status changed from ${context.getOldValue('status')} to ${context.doc.status}`,
|
|
53
|
+
* user_id: context.userId,
|
|
54
|
+
* });
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
* };
|
|
58
|
+
*/
|
|
59
|
+
exports.TriggerContextSchema = zod_1.z.object({
|
|
60
|
+
/**
|
|
61
|
+
* The database operation that triggered execution.
|
|
62
|
+
* One of: 'insert', 'update', 'delete'
|
|
63
|
+
*/
|
|
64
|
+
action: exports.TriggerAction.describe('Database operation type'),
|
|
65
|
+
/**
|
|
66
|
+
* When the trigger executes relative to the operation.
|
|
67
|
+
* - 'before': Execute before database operation (can modify doc, prevent operation)
|
|
68
|
+
* - 'after': Execute after database operation (can trigger side effects)
|
|
69
|
+
*/
|
|
70
|
+
timing: exports.TriggerTiming.describe('Trigger execution timing'),
|
|
71
|
+
/**
|
|
72
|
+
* The current document/record being operated on.
|
|
73
|
+
*
|
|
74
|
+
* For 'before' triggers: Can be modified to change what gets saved.
|
|
75
|
+
* For 'after' triggers: Contains the final saved state (read-only).
|
|
76
|
+
* For 'delete' triggers: Contains the record being deleted.
|
|
77
|
+
*/
|
|
78
|
+
doc: zod_1.z.record(zod_1.z.any()).describe('Current document/record'),
|
|
79
|
+
/**
|
|
80
|
+
* The document state before the current operation.
|
|
81
|
+
*
|
|
82
|
+
* Only available for 'update' and 'delete' operations.
|
|
83
|
+
* Null for 'insert' operations.
|
|
84
|
+
*
|
|
85
|
+
* Use this to detect what changed in an update trigger.
|
|
86
|
+
*/
|
|
87
|
+
previousDoc: zod_1.z.record(zod_1.z.any()).optional().describe('Previous document state'),
|
|
88
|
+
/**
|
|
89
|
+
* ID of the user performing the operation.
|
|
90
|
+
*/
|
|
91
|
+
userId: zod_1.z.string().describe('Current user ID'),
|
|
92
|
+
/**
|
|
93
|
+
* Complete user record of the user performing the operation.
|
|
94
|
+
* Contains fields like name, email, roles, etc.
|
|
95
|
+
*/
|
|
96
|
+
user: zod_1.z.record(zod_1.z.any()).describe('Current user record'),
|
|
97
|
+
/**
|
|
98
|
+
* ObjectQL data access API.
|
|
99
|
+
* Use this to query or modify other records.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* await context.ql.object('account').findOne(context.doc.account_id);
|
|
103
|
+
* await context.ql.object('activity').create({ ... });
|
|
104
|
+
*/
|
|
105
|
+
ql: zod_1.z.any().describe('ObjectQL data access API'),
|
|
106
|
+
/**
|
|
107
|
+
* Logging interface.
|
|
108
|
+
* Use this for debugging and auditing.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* context.logger.info('Trigger executed', { recordId: context.doc.id });
|
|
112
|
+
* context.logger.error('Validation failed', { error });
|
|
113
|
+
*/
|
|
114
|
+
logger: zod_1.z.any().describe('Logging interface'),
|
|
115
|
+
/**
|
|
116
|
+
* Add a validation error.
|
|
117
|
+
* For 'before' triggers only - prevents the operation from completing.
|
|
118
|
+
*
|
|
119
|
+
* @param message - Error message to display
|
|
120
|
+
* @param field - Optional field name the error relates to
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* if (context.doc.amount < 0) {
|
|
124
|
+
* context.addError('Amount must be positive', 'amount');
|
|
125
|
+
* }
|
|
126
|
+
*/
|
|
127
|
+
addError: zod_1.z.function()
|
|
128
|
+
.args(zod_1.z.string(), zod_1.z.string().optional())
|
|
129
|
+
.returns(zod_1.z.void())
|
|
130
|
+
.describe('Add validation error'),
|
|
131
|
+
/**
|
|
132
|
+
* Get the old value of a field.
|
|
133
|
+
* Helper function for 'update' triggers to easily compare old vs new values.
|
|
134
|
+
*
|
|
135
|
+
* @param fieldName - Name of the field
|
|
136
|
+
* @returns Previous value of the field, or undefined if not available
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* if (context.getOldValue('status') !== context.doc.status) {
|
|
140
|
+
* // Status changed
|
|
141
|
+
* }
|
|
142
|
+
*/
|
|
143
|
+
getOldValue: zod_1.z.function()
|
|
144
|
+
.args(zod_1.z.string())
|
|
145
|
+
.returns(zod_1.z.any())
|
|
146
|
+
.describe('Get previous field value'),
|
|
147
|
+
});
|
|
148
|
+
/**
|
|
149
|
+
* Trigger Definition Schema
|
|
150
|
+
*
|
|
151
|
+
* Complete definition of a trigger including metadata and execution function.
|
|
152
|
+
*/
|
|
153
|
+
exports.TriggerSchema = zod_1.z.object({
|
|
154
|
+
/**
|
|
155
|
+
* Unique trigger name.
|
|
156
|
+
*/
|
|
157
|
+
name: zod_1.z.string().regex(/^[a-z_][a-z0-9_]*$/).describe('Trigger name (snake_case)'),
|
|
158
|
+
/**
|
|
159
|
+
* Object this trigger is attached to.
|
|
160
|
+
*/
|
|
161
|
+
object: zod_1.z.string().describe('Target object name'),
|
|
162
|
+
/**
|
|
163
|
+
* Trigger timing.
|
|
164
|
+
*/
|
|
165
|
+
timing: exports.TriggerTiming.describe('Execution timing'),
|
|
166
|
+
/**
|
|
167
|
+
* Trigger action(s).
|
|
168
|
+
* Can be a single action or array of actions.
|
|
169
|
+
*/
|
|
170
|
+
action: zod_1.z.union([
|
|
171
|
+
exports.TriggerAction,
|
|
172
|
+
zod_1.z.array(exports.TriggerAction),
|
|
173
|
+
]).describe('Database operation(s) to trigger on'),
|
|
174
|
+
/**
|
|
175
|
+
* Trigger execution function.
|
|
176
|
+
* Receives TriggerContext and performs the business logic.
|
|
177
|
+
*/
|
|
178
|
+
execute: zod_1.z.function()
|
|
179
|
+
.args(exports.TriggerContextSchema)
|
|
180
|
+
.returns(zod_1.z.promise(zod_1.z.void()))
|
|
181
|
+
.describe('Trigger execution function'),
|
|
182
|
+
/**
|
|
183
|
+
* Optional description of what the trigger does.
|
|
184
|
+
*/
|
|
185
|
+
description: zod_1.z.string().optional().describe('Trigger description'),
|
|
186
|
+
/**
|
|
187
|
+
* Whether the trigger is active.
|
|
188
|
+
*/
|
|
189
|
+
active: zod_1.z.boolean().default(true).describe('Is trigger active'),
|
|
190
|
+
/**
|
|
191
|
+
* Execution order when multiple triggers are defined.
|
|
192
|
+
* Lower numbers execute first.
|
|
193
|
+
*/
|
|
194
|
+
order: zod_1.z.number().default(0).describe('Execution order'),
|
|
195
|
+
});
|