Skip to content

Commit 72d0dbb

Browse files
authored
Merge pull request #135 from objectstack-ai/copilot/refactor-objectql-adherence
2 parents 698d1f7 + 9f1b180 commit 72d0dbb

File tree

13 files changed

+292
-110
lines changed

13 files changed

+292
-110
lines changed

packages/foundation/core/src/util.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ export function convertIntrospectedSchemaToObjects(
110110

111111
if (foreignKey) {
112112
// This is a lookup field
113+
// Note: name must be set explicitly here since we're creating the config programmatically.
114+
// When defined in YAML (ObjectConfig.fields Record), the name is auto-populated from the key.
113115
fieldConfig = {
116+
name: column.name,
114117
type: 'lookup',
115118
reference_to: foreignKey.referencedTable,
116119
label: toTitleCase(column.name),
@@ -120,7 +123,10 @@ export function convertIntrospectedSchemaToObjects(
120123
// Regular field
121124
const fieldType = mapDatabaseTypeToFieldType(column.type);
122125

126+
// Note: name must be set explicitly here since we're creating the config programmatically.
127+
// When defined in YAML (ObjectConfig.fields Record), the name is auto-populated from the key.
123128
fieldConfig = {
129+
name: column.name,
124130
type: fieldType,
125131
label: toTitleCase(column.name),
126132
required: !column.nullable
@@ -133,7 +139,7 @@ export function convertIntrospectedSchemaToObjects(
133139

134140
// Add max length for text fields
135141
if (column.maxLength && (fieldType === 'text' || fieldType === 'textarea')) {
136-
fieldConfig.max_length = column.maxLength;
142+
fieldConfig.maxLength = column.maxLength;
137143
}
138144

139145
// Add default value

packages/foundation/core/src/validator.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,10 @@ export class Validator {
190190
}
191191
}
192192

193-
// Pattern validation (supports both pattern and deprecated regex)
194-
const patternValue = validation.pattern ?? validation.regex;
195-
if (patternValue) {
193+
// Pattern validation
194+
if (validation.pattern) {
196195
try {
197-
const pattern = new RegExp(patternValue);
196+
const pattern = new RegExp(validation.pattern);
198197
if (!pattern.test(String(value))) {
199198
results.push({
200199
rule: `${fieldName}_pattern`,
@@ -208,7 +207,7 @@ export class Validator {
208207
results.push({
209208
rule: `${fieldName}_pattern`,
210209
valid: false,
211-
message: `Invalid regex pattern: ${patternValue}`,
210+
message: `Invalid regex pattern: ${validation.pattern}`,
212211
severity: 'error',
213212
fields: [fieldName],
214213
});

packages/foundation/core/test/util.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ describe('Utility Functions', () => {
327327
const objects = convertIntrospectedSchemaToObjects(schema);
328328
const fields = objects[0].fields!;
329329

330-
expect(fields.short_text.max_length).toBe(100);
330+
expect(fields.short_text.maxLength).toBe(100);
331331
});
332332

333333
it('should add default value when present', () => {

packages/foundation/types/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@
2222
"schemas"
2323
],
2424
"scripts": {
25-
"build": "tsc && npm run generate:schemas",
25+
"build": "tsc",
2626
"generate:schemas": "node scripts/generate-schemas.js",
2727
"test": "jest --passWithNoTests"
2828
},
29+
"dependencies": {
30+
"@objectstack/spec": "^0.1.1"
31+
},
2932
"devDependencies": {
3033
"ts-json-schema-generator": "^2.4.0"
3134
}

packages/foundation/types/src/action.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,21 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9+
// Import and re-export types from the Protocol Constitution (@objectstack/spec)
10+
import type { Action } from '@objectstack/spec';
911
import { FieldConfig } from "./field";
1012
import { HookAPI } from "./hook"; // Reuse the restricted API interface
1113

14+
/**
15+
* Re-export Protocol Types from the Constitution
16+
*/
17+
export type { Action as SpecAction };
18+
19+
/**
20+
* RUNTIME-SPECIFIC TYPES
21+
* The following types extend the Protocol Action definition with runtime execution capabilities
22+
*/
23+
1224
/**
1325
* Defines the scope of the action.
1426
* - `record`: Acts on a specific record instance (e.g. "Approve Order").
@@ -24,6 +36,8 @@ export type ActionInputDefinition = Record<string, FieldConfig>;
2436

2537
/**
2638
* Context passed to the action handler execution.
39+
*
40+
* RUNTIME TYPE: Used during action execution.
2741
*/
2842
export interface ActionContext<BaseT = any, InputT = any> {
2943
/** The object this action belongs to. */
@@ -58,11 +72,19 @@ export interface ActionContext<BaseT = any, InputT = any> {
5872
}
5973

6074
/**
75+
* Runtime Action Configuration
76+
*
6177
* The configuration of an Action visible to the Metadata engine (YAML/JSON side).
78+
* Compatible with Protocol Action but adds runtime-specific options.
6279
*/
6380
export interface ActionConfig {
81+
/** Display label */
6482
label?: string;
83+
84+
/** Description */
6585
description?: string;
86+
87+
/** Icon name */
6688
icon?: string;
6789

6890
/**
@@ -93,6 +115,8 @@ export interface ActionConfig {
93115

94116
/**
95117
* The full implementation definition (Code side).
118+
*
119+
* RUNTIME TYPE: Includes the handler function for execution.
96120
*/
97121
export interface ActionDefinition<BaseT = any, InputT = any, ReturnT = any> extends ActionConfig {
98122
/**

0 commit comments

Comments
 (0)