@objectql/types 1.4.0 → 1.6.0

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/dist/page.d.ts ADDED
@@ -0,0 +1,272 @@
1
+ /**
2
+ * Page Metadata Definition
3
+ *
4
+ * Defines the structure for pages in ObjectQL applications.
5
+ * Inspired by low-code platforms like Airtable, Retool, Appsmith, and Salesforce Lightning.
6
+ *
7
+ * Pages are composable UI containers that can render data from objects,
8
+ * display custom components, and orchestrate user interactions.
9
+ */
10
+ /**
11
+ * Layout types for page arrangement
12
+ */
13
+ export type PageLayoutType = 'single_column' | 'two_column' | 'three_column' | 'dashboard' | 'canvas' | 'tabs' | 'wizard' | 'custom';
14
+ /**
15
+ * Component types that can be placed on a page
16
+ */
17
+ export type PageComponentType = 'data_grid' | 'form' | 'detail_view' | 'chart' | 'metric' | 'list' | 'calendar' | 'kanban' | 'timeline' | 'text' | 'html' | 'iframe' | 'button' | 'tabs' | 'container' | 'divider' | 'image' | 'custom';
18
+ /**
19
+ * Responsive breakpoint configuration
20
+ */
21
+ export interface ResponsiveConfig {
22
+ /** Mobile viewport (< 640px) */
23
+ mobile?: {
24
+ columns?: number;
25
+ visible?: boolean;
26
+ order?: number;
27
+ };
28
+ /** Tablet viewport (640px - 1024px) */
29
+ tablet?: {
30
+ columns?: number;
31
+ visible?: boolean;
32
+ order?: number;
33
+ };
34
+ /** Desktop viewport (> 1024px) */
35
+ desktop?: {
36
+ columns?: number;
37
+ visible?: boolean;
38
+ order?: number;
39
+ };
40
+ }
41
+ /**
42
+ * Data source configuration for components
43
+ */
44
+ export interface ComponentDataSource {
45
+ /** Object name to query */
46
+ object?: string;
47
+ /** Filter conditions */
48
+ filters?: any[];
49
+ /** Fields to display */
50
+ fields?: string[];
51
+ /** Sort configuration */
52
+ sort?: Array<[string, 'asc' | 'desc']>;
53
+ /** Maximum records to fetch */
54
+ limit?: number;
55
+ /** Enable pagination */
56
+ paginate?: boolean;
57
+ /** Related objects to expand */
58
+ expand?: Record<string, any>;
59
+ /** Custom query override */
60
+ query?: any;
61
+ }
62
+ /**
63
+ * Action triggered by component interaction
64
+ */
65
+ export interface ComponentAction {
66
+ /** Action type */
67
+ type: 'navigate' | 'open_modal' | 'run_action' | 'submit_form' | 'refresh' | 'custom';
68
+ /** Navigation path (for type: navigate) */
69
+ path?: string;
70
+ /** Modal component to open (for type: open_modal) */
71
+ modal?: string;
72
+ /** Action name to execute (for type: run_action) */
73
+ action?: string;
74
+ /** Target object for action */
75
+ object?: string;
76
+ /** Custom handler function */
77
+ handler?: string;
78
+ /** Confirmation message before executing */
79
+ confirm?: string;
80
+ /** Success message after execution */
81
+ success_message?: string;
82
+ /** Error handling */
83
+ on_error?: 'show_toast' | 'show_modal' | 'ignore';
84
+ }
85
+ /**
86
+ * Styling configuration for components
87
+ */
88
+ export interface ComponentStyle {
89
+ /** Width (e.g., '100%', '300px', 'auto') */
90
+ width?: string;
91
+ /** Height */
92
+ height?: string;
93
+ /** Minimum width */
94
+ min_width?: string;
95
+ /** Minimum height */
96
+ min_height?: string;
97
+ /** Background color */
98
+ background?: string;
99
+ /** Text color */
100
+ color?: string;
101
+ /** Border */
102
+ border?: string;
103
+ /** Border radius */
104
+ border_radius?: string;
105
+ /** Padding */
106
+ padding?: string;
107
+ /** Margin */
108
+ margin?: string;
109
+ /** Custom CSS classes */
110
+ class_name?: string;
111
+ /** Inline styles */
112
+ custom_css?: Record<string, any>;
113
+ }
114
+ /**
115
+ * Base component configuration
116
+ */
117
+ export interface PageComponent {
118
+ /** Unique component identifier within the page */
119
+ id: string;
120
+ /** Component type */
121
+ type: PageComponentType;
122
+ /** Display label */
123
+ label?: string;
124
+ /** Component description */
125
+ description?: string;
126
+ /** Data source configuration */
127
+ data_source?: ComponentDataSource;
128
+ /** Component-specific configuration */
129
+ config?: Record<string, any>;
130
+ /** Actions triggered by this component */
131
+ actions?: {
132
+ on_click?: ComponentAction;
133
+ on_submit?: ComponentAction;
134
+ on_load?: ComponentAction;
135
+ on_change?: ComponentAction;
136
+ [key: string]: ComponentAction | undefined;
137
+ };
138
+ /** Visual styling */
139
+ style?: ComponentStyle;
140
+ /** Responsive behavior */
141
+ responsive?: ResponsiveConfig;
142
+ /** Visibility conditions */
143
+ visible_when?: Record<string, any>;
144
+ /** Access control */
145
+ permissions?: string[];
146
+ /** Nested components (for containers, tabs, etc.) */
147
+ components?: PageComponent[];
148
+ /** Grid position (for dashboard layout) */
149
+ grid?: {
150
+ x: number;
151
+ y: number;
152
+ w: number;
153
+ h: number;
154
+ };
155
+ /** Custom component reference */
156
+ component?: string;
157
+ }
158
+ /**
159
+ * Page section/region configuration
160
+ */
161
+ export interface PageSection {
162
+ /** Section identifier */
163
+ id: string;
164
+ /** Section label */
165
+ label?: string;
166
+ /** Section type */
167
+ type?: 'header' | 'sidebar' | 'content' | 'footer' | 'custom';
168
+ /** Components in this section */
169
+ components: PageComponent[];
170
+ /** Section styling */
171
+ style?: ComponentStyle;
172
+ /** Collapsible section */
173
+ collapsible?: boolean;
174
+ /** Default collapsed state */
175
+ collapsed?: boolean;
176
+ /** Visibility conditions */
177
+ visible_when?: Record<string, any>;
178
+ }
179
+ /**
180
+ * Page metadata configuration
181
+ */
182
+ export interface PageConfig {
183
+ /** Unique page identifier */
184
+ name: string;
185
+ /** Display label */
186
+ label: string;
187
+ /** Page description */
188
+ description?: string;
189
+ /** Icon for navigation */
190
+ icon?: string;
191
+ /** Layout type */
192
+ layout: PageLayoutType;
193
+ /** Page sections */
194
+ sections?: PageSection[];
195
+ /** Components (alternative to sections for simple layouts) */
196
+ components?: PageComponent[];
197
+ /** Page-level data sources */
198
+ data_sources?: Record<string, ComponentDataSource>;
199
+ /** Page-level actions */
200
+ actions?: Record<string, ComponentAction>;
201
+ /** Page styling */
202
+ style?: ComponentStyle;
203
+ /** Access control */
204
+ permissions?: {
205
+ /** Roles allowed to view this page */
206
+ view?: string[];
207
+ /** Roles allowed to edit this page */
208
+ edit?: string[];
209
+ };
210
+ /** SEO and metadata */
211
+ meta?: {
212
+ title?: string;
213
+ description?: string;
214
+ keywords?: string[];
215
+ };
216
+ /** Page state management */
217
+ state?: {
218
+ /** Initial state values */
219
+ initial?: Record<string, any>;
220
+ /** State persistence */
221
+ persist?: boolean;
222
+ /** Storage key for persistence */
223
+ storage_key?: string;
224
+ };
225
+ /** Responsive configuration */
226
+ responsive?: ResponsiveConfig;
227
+ /** Custom page handler/controller */
228
+ handler?: string;
229
+ /** Enable real-time updates */
230
+ realtime?: boolean;
231
+ /** Refresh interval in seconds */
232
+ refresh_interval?: number;
233
+ /** AI context for page generation and understanding */
234
+ ai_context?: {
235
+ /** Purpose of the page */
236
+ intent?: string;
237
+ /** Target user persona */
238
+ persona?: string;
239
+ /** Key user tasks */
240
+ tasks?: string[];
241
+ };
242
+ }
243
+ /**
244
+ * Lightweight page reference (for menus, navigation, etc.)
245
+ *
246
+ * Used in application navigation menus and links to reference pages
247
+ * without loading the full page configuration. This is useful for:
248
+ * - Building navigation menus
249
+ * - Creating page links
250
+ * - Page selection dropdowns
251
+ *
252
+ * @example
253
+ * ```typescript
254
+ * // In navigation menu
255
+ * const menuItem: PageReference = {
256
+ * name: 'dashboard',
257
+ * label: 'Dashboard',
258
+ * icon: 'dashboard',
259
+ * path: '/dashboard'
260
+ * };
261
+ * ```
262
+ */
263
+ export interface PageReference {
264
+ /** Page name/identifier */
265
+ name: string;
266
+ /** Display label */
267
+ label?: string;
268
+ /** Icon */
269
+ icon?: string;
270
+ /** Path/route */
271
+ path?: string;
272
+ }
package/dist/page.js ADDED
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ /**
3
+ * Page Metadata Definition
4
+ *
5
+ * Defines the structure for pages in ObjectQL applications.
6
+ * Inspired by low-code platforms like Airtable, Retool, Appsmith, and Salesforce Lightning.
7
+ *
8
+ * Pages are composable UI containers that can render data from objects,
9
+ * display custom components, and orchestrate user interactions.
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ //# sourceMappingURL=page.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page.js","sourceRoot":"","sources":["../src/page.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG"}
@@ -0,0 +1,391 @@
1
+ /**
2
+ * Permission and Security Metadata Types
3
+ *
4
+ * This module defines the TypeScript interfaces for ObjectQL's permission system,
5
+ * implementing role-based access control (RBAC), field-level security, and
6
+ * record-level rules.
7
+ *
8
+ * Based on specification: docs/spec/permission.md
9
+ */
10
+ /**
11
+ * Basic CRUD operations for object-level permissions
12
+ */
13
+ export type ObjectOperation = 'create' | 'read' | 'update' | 'delete' | 'view_all' | 'modify_all';
14
+ /**
15
+ * Field-level operations
16
+ */
17
+ export type FieldOperation = 'read' | 'update';
18
+ /**
19
+ * Comparison operators for permission conditions
20
+ */
21
+ export type PermissionOperator = '=' | '!=' | '>' | '>=' | '<' | '<=' | 'in' | 'not_in' | 'contains' | 'not_contains' | 'starts_with' | 'ends_with';
22
+ /**
23
+ * Object-level permissions controlling CRUD operations
24
+ */
25
+ export interface ObjectPermissions {
26
+ /** Roles that can create new records */
27
+ create?: string[];
28
+ /** Roles that can view records */
29
+ read?: string[];
30
+ /** Roles that can update records */
31
+ update?: string[];
32
+ /** Roles that can delete records */
33
+ delete?: string[];
34
+ /** Roles that can view all records (bypass ownership rules) */
35
+ view_all?: string[];
36
+ /** Roles that can modify all records (bypass ownership rules) */
37
+ modify_all?: string[];
38
+ }
39
+ /**
40
+ * Field-level permissions for a specific field
41
+ */
42
+ export interface FieldPermission {
43
+ /** Roles that can read this field */
44
+ read?: string[];
45
+ /** Roles that can update this field */
46
+ update?: string[];
47
+ }
48
+ /**
49
+ * Map of field names to their permissions
50
+ */
51
+ export type FieldPermissions = Record<string, FieldPermission>;
52
+ /**
53
+ * Condition type for record-level rules
54
+ */
55
+ export type ConditionType = 'simple' | 'complex' | 'formula' | 'lookup';
56
+ /**
57
+ * Simple condition for a single field comparison
58
+ */
59
+ export interface SimpleCondition {
60
+ type?: 'simple';
61
+ /** Field to check */
62
+ field: string;
63
+ /** Comparison operator */
64
+ operator: PermissionOperator;
65
+ /** Value to compare against (can include variables like $current_user.id) */
66
+ value: any;
67
+ }
68
+ /**
69
+ * Simple condition element (inline form for complex expressions)
70
+ */
71
+ export interface ConditionElement {
72
+ field: string;
73
+ operator: PermissionOperator;
74
+ value: any;
75
+ }
76
+ /**
77
+ * Expression element in complex conditions
78
+ */
79
+ export type ConditionExpression = SimpleCondition | ConditionElement | 'and' | 'or';
80
+ /**
81
+ * Complex condition with multiple clauses
82
+ */
83
+ export interface ComplexCondition {
84
+ type: 'complex';
85
+ /** Array of conditions and logical operators */
86
+ expression: ConditionExpression[];
87
+ }
88
+ /**
89
+ * Formula-based condition using custom logic
90
+ */
91
+ export interface FormulaCondition {
92
+ type: 'formula';
93
+ /** JavaScript expression or formula */
94
+ formula: string;
95
+ }
96
+ /**
97
+ * Lookup condition checking related record data
98
+ */
99
+ export interface LookupCondition {
100
+ type: 'lookup';
101
+ /** Related object to check */
102
+ object: string;
103
+ /** Field linking to related object */
104
+ via: string;
105
+ /** Condition to check on related object */
106
+ condition: RecordRuleCondition;
107
+ }
108
+ /**
109
+ * Union type for all condition types
110
+ */
111
+ export type RecordRuleCondition = SimpleCondition | ComplexCondition | FormulaCondition | LookupCondition;
112
+ /**
113
+ * Permissions granted by a record rule
114
+ */
115
+ export interface RecordRulePermissions {
116
+ /** Grant read permission */
117
+ read?: boolean;
118
+ /** Grant update permission */
119
+ update?: boolean;
120
+ /** Grant delete permission */
121
+ delete?: boolean;
122
+ }
123
+ /**
124
+ * Record-level rule for dynamic access control
125
+ */
126
+ export interface RecordRule {
127
+ /** Unique name of the rule */
128
+ name: string;
129
+ /** Priority (higher priority rules take precedence, default: 0) */
130
+ priority?: number;
131
+ /** Human-readable description */
132
+ description?: string;
133
+ /** Condition for applying this rule */
134
+ condition: RecordRuleCondition;
135
+ /** Permissions granted when condition matches */
136
+ permissions: RecordRulePermissions;
137
+ }
138
+ /**
139
+ * Sharing rule type
140
+ */
141
+ export type SharingRuleType = 'manual' | 'criteria' | 'team';
142
+ /**
143
+ * Who to share with
144
+ */
145
+ export interface SharedWith {
146
+ type: 'role' | 'team' | 'user' | 'group';
147
+ roles?: string[];
148
+ teams?: string[];
149
+ users?: string[];
150
+ groups?: string[];
151
+ }
152
+ /**
153
+ * Base sharing rule
154
+ */
155
+ export interface BaseSharingRule {
156
+ /** Unique name of the rule */
157
+ name: string;
158
+ /** Type of sharing rule */
159
+ type: SharingRuleType;
160
+ /** Description */
161
+ description?: string;
162
+ /** Whether this rule is enabled */
163
+ enabled?: boolean;
164
+ /** Permissions granted through sharing */
165
+ permissions: RecordRulePermissions;
166
+ }
167
+ /**
168
+ * Manual sharing rule - users can manually share records
169
+ */
170
+ export interface ManualSharingRule extends BaseSharingRule {
171
+ type: 'manual';
172
+ }
173
+ /**
174
+ * Criteria-based sharing rule - automatic sharing
175
+ */
176
+ export interface CriteriaSharingRule extends BaseSharingRule {
177
+ type: 'criteria';
178
+ /** Condition for automatic sharing */
179
+ condition: RecordRuleCondition;
180
+ /** Who to share with */
181
+ shared_with: SharedWith;
182
+ }
183
+ /**
184
+ * Team-based sharing rule
185
+ */
186
+ export interface TeamSharingRule extends BaseSharingRule {
187
+ type: 'team';
188
+ /** Field containing team ID */
189
+ team_field: string;
190
+ }
191
+ /**
192
+ * Union type for all sharing rules
193
+ */
194
+ export type SharingRule = ManualSharingRule | CriteriaSharingRule | TeamSharingRule;
195
+ /**
196
+ * Condition for action execution
197
+ */
198
+ export interface ActionCondition {
199
+ /** Field to check */
200
+ field: string;
201
+ /** Comparison operator */
202
+ operator: PermissionOperator;
203
+ /** Value to compare */
204
+ value: any;
205
+ }
206
+ /**
207
+ * Rate limiting configuration for actions
208
+ */
209
+ export interface ActionRateLimit {
210
+ /** Maximum requests per hour */
211
+ requests_per_hour?: number;
212
+ /** Maximum requests per day */
213
+ requests_per_day?: number;
214
+ }
215
+ /**
216
+ * Permission configuration for a specific action
217
+ */
218
+ export interface ActionPermission {
219
+ /** Roles that can execute this action */
220
+ execute: string[];
221
+ /** Conditions that must be met for execution */
222
+ conditions?: ActionCondition[];
223
+ /** Rate limiting */
224
+ rate_limit?: ActionRateLimit;
225
+ }
226
+ /**
227
+ * Map of action names to their permissions
228
+ */
229
+ export type ActionPermissions = Record<string, ActionPermission>;
230
+ /**
231
+ * Field restrictions for a view
232
+ */
233
+ export interface ViewFieldRestriction {
234
+ /** Field name */
235
+ [fieldName: string]: {
236
+ /** Roles that can see this field in the view */
237
+ visible_to: string[];
238
+ };
239
+ }
240
+ /**
241
+ * Permission configuration for a specific view
242
+ */
243
+ export interface ViewPermission {
244
+ /** Roles that can access this view */
245
+ access: string[];
246
+ /** Field-level restrictions within the view */
247
+ field_restrictions?: ViewFieldRestriction;
248
+ }
249
+ /**
250
+ * Map of view names to their permissions
251
+ */
252
+ export type ViewPermissions = Record<string, ViewPermission>;
253
+ /**
254
+ * Row-level security configuration
255
+ */
256
+ export interface RowLevelSecurity {
257
+ /** Whether RLS is enabled */
258
+ enabled: boolean;
259
+ /** Default rule applied to all users */
260
+ default_rule?: SimpleCondition;
261
+ /** Exceptions to the default rule */
262
+ exceptions?: Array<{
263
+ /** Role to apply exception to */
264
+ role: string;
265
+ /** Whether to bypass RLS entirely */
266
+ bypass?: boolean;
267
+ /** Custom condition for this role */
268
+ condition?: RecordRuleCondition;
269
+ }>;
270
+ }
271
+ /**
272
+ * Field masking configuration for a specific field
273
+ */
274
+ export interface FieldMaskConfig {
275
+ /** Mask format (e.g., "****-****-****-{last4}") */
276
+ mask_format: string;
277
+ /** Roles that can see the unmasked value */
278
+ visible_to: string[];
279
+ }
280
+ /**
281
+ * Map of field names to their masking configuration
282
+ */
283
+ export type FieldMasking = Record<string, FieldMaskConfig>;
284
+ /**
285
+ * Audit event type
286
+ */
287
+ export type AuditEventType = 'permission_grant' | 'permission_revoke' | 'access_denied' | 'sensitive_field_access';
288
+ /**
289
+ * Alert configuration for suspicious activity
290
+ */
291
+ export interface AuditAlert {
292
+ /** Event type to alert on */
293
+ event: AuditEventType;
294
+ /** Number of events to trigger alert */
295
+ threshold: number;
296
+ /** Time window in minutes */
297
+ window_minutes: number;
298
+ /** Who to notify (roles or user IDs) */
299
+ notify: string[];
300
+ }
301
+ /**
302
+ * Audit trail configuration
303
+ */
304
+ export interface AuditConfig {
305
+ /** Whether auditing is enabled */
306
+ enabled: boolean;
307
+ /** Events to log */
308
+ events?: AuditEventType[];
309
+ /** Retention period in days */
310
+ retention_days?: number;
311
+ /** Alert configurations */
312
+ alerts?: AuditAlert[];
313
+ }
314
+ /**
315
+ * Complete permission configuration for an object
316
+ */
317
+ export interface PermissionConfig {
318
+ /** Unique name of the permission configuration */
319
+ name: string;
320
+ /** Object this permission applies to */
321
+ object: string;
322
+ /** Description */
323
+ description?: string;
324
+ /**
325
+ * Roles referenced in this permission configuration.
326
+ *
327
+ * Best Practice: Define roles centrally in ApplicationConfig and reference them here.
328
+ * This field serves to:
329
+ * 1. Document which roles apply to this object
330
+ * 2. Validate that only defined roles are used
331
+ * 3. Support standalone usage without application context
332
+ *
333
+ * Example:
334
+ * - Define in app: permissions.roles: [admin, manager, user]
335
+ * - Reference here: roles: [admin, manager, user]
336
+ */
337
+ roles?: string[];
338
+ /** Object-level permissions */
339
+ object_permissions?: ObjectPermissions;
340
+ /** Field-level security */
341
+ field_permissions?: FieldPermissions;
342
+ /** Record-level access rules */
343
+ record_rules?: RecordRule[];
344
+ /** Sharing rules */
345
+ sharing_rules?: SharingRule[];
346
+ /** Action permissions */
347
+ action_permissions?: ActionPermissions;
348
+ /** View permissions */
349
+ view_permissions?: ViewPermissions;
350
+ /** Row-level security */
351
+ row_level_security?: RowLevelSecurity;
352
+ /** Field masking */
353
+ field_masking?: FieldMasking;
354
+ /** Audit configuration */
355
+ audit?: AuditConfig;
356
+ }
357
+ /**
358
+ * Context for permission checks
359
+ */
360
+ export interface PermissionCheckContext {
361
+ /** Current user */
362
+ user: {
363
+ id: string;
364
+ /** User roles (array for consistency, single role represented as one-element array) */
365
+ roles?: string[];
366
+ department_id?: string;
367
+ team_id?: string;
368
+ [key: string]: any;
369
+ };
370
+ /** Object name */
371
+ object: string;
372
+ /** Operation to check */
373
+ operation: ObjectOperation | FieldOperation;
374
+ /** Record ID (for record-level checks) */
375
+ recordId?: string;
376
+ /** Field name (for field-level checks) */
377
+ field?: string;
378
+ /** Record data (for condition evaluation) */
379
+ record?: any;
380
+ }
381
+ /**
382
+ * Result of a permission check
383
+ */
384
+ export interface PermissionCheckResult {
385
+ /** Whether permission is granted */
386
+ granted: boolean;
387
+ /** Reason if denied */
388
+ reason?: string;
389
+ /** Rule that granted/denied access */
390
+ rule?: string;
391
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ /**
3
+ * Permission and Security Metadata Types
4
+ *
5
+ * This module defines the TypeScript interfaces for ObjectQL's permission system,
6
+ * implementing role-based access control (RBAC), field-level security, and
7
+ * record-level rules.
8
+ *
9
+ * Based on specification: docs/spec/permission.md
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ //# sourceMappingURL=permission.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permission.js","sourceRoot":"","sources":["../src/permission.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG"}