Skip to content

Commit 9f1b180

Browse files
Copilothuangyiirene
andcommitted
refactor: Address PR review feedback - improve documentation and remove ambiguous deprecated properties
Co-authored-by: huangyiirene <7665279+huangyiirene@users.noreply.github.com>
1 parent 0c1156b commit 9f1b180

File tree

4 files changed

+49
-17
lines changed

4 files changed

+49
-17
lines changed

packages/foundation/core/src/util.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ 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 = {
114116
name: column.name,
115117
type: 'lookup',
@@ -121,6 +123,8 @@ export function convertIntrospectedSchemaToObjects(
121123
// Regular field
122124
const fieldType = mapDatabaseTypeToFieldType(column.type);
123125

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.
124128
fieldConfig = {
125129
name: column.name,
126130
type: fieldType,

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/types/src/field.ts

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,16 @@ export interface FieldOption {
114114
* The Protocol Constitution (SpecField) defines the core field schema.
115115
* This adds runtime conveniences and extensions.
116116
*
117-
* We make certain spec fields optional since Zod applies defaults at parse time.
117+
* Properties from the protocol Field interface that are re-declared here:
118+
* - `name`, `label`: Made optional for runtime convenience (auto-populated from Record key)
119+
* - `type`: Extended union type to include runtime-specific types (vector, grid, location, object)
120+
* - `options`: Extended to allow numeric values for backwards compatibility
121+
* - Boolean flags (`required`, `multiple`, `unique`, `hidden`, `readonly`, `encryption`, `index`, `externalId`):
122+
* Made optional since Zod applies defaults at parse time, but runtime usage typically specifies these explicitly
123+
* - `deleteBehavior`: Made optional with protocol-compatible enum values
124+
*
125+
* All other protocol properties (description, defaultValue, maxLength, minLength, precision, scale, min, max,
126+
* reference, referenceFilters, writeRequiresMasterRead, expression, formula, summaryOperations) are inherited as-is.
118127
*/
119128
export interface FieldConfig extends Omit<Field, 'name' | 'label' | 'type' | 'options' | 'required' | 'multiple' | 'unique' | 'deleteBehavior' | 'hidden' | 'readonly' | 'encryption' | 'index' | 'externalId'> {
120129
/** Field name (inferred from Record key when used in ObjectConfig.fields) */
@@ -166,7 +175,32 @@ export interface FieldConfig extends Omit<Field, 'name' | 'label' | 'type' | 'op
166175

167176
/**
168177
* Reference to another object for lookup/master_detail fields.
169-
* @deprecated Use 'reference' from SpecField instead
178+
*
179+
* @deprecated Legacy alias for the protocol-level `reference` field (inherited from {@link Field}).
180+
*
181+
* **Migration Guidance:**
182+
* - **New schemas MUST** use the `reference` field (defined in the protocol Field interface) instead of `reference_to`.
183+
* - **During migration**, engines and tooling SHOULD:
184+
* - Treat `reference_to` as a fallback alias for `reference` (i.e., if `reference` is undefined and `reference_to`
185+
* is defined, behave as though `reference` were set to the same value).
186+
* - Prefer the protocol `reference` value when both are present.
187+
* - This property is retained only for backward compatibility with older *.object.yml definitions and will be
188+
* removed in a future major version once all callers have migrated to `reference`.
189+
*
190+
* @example
191+
* ```yaml
192+
* # Old (deprecated):
193+
* fields:
194+
* owner:
195+
* type: lookup
196+
* reference_to: users
197+
*
198+
* # New (protocol-compliant):
199+
* fields:
200+
* owner:
201+
* type: lookup
202+
* reference: users
203+
* ```
170204
*/
171205
reference_to?: string;
172206

@@ -207,12 +241,6 @@ export interface FieldConfig extends Omit<Field, 'name' | 'label' | 'type' | 'op
207241
*/
208242
min_height?: number;
209243

210-
/**
211-
* Regular expression pattern for validation.
212-
* @deprecated Use validation.pattern instead
213-
*/
214-
regex?: string;
215-
216244
/**
217245
* Field validation configuration.
218246
* Defines validation rules applied at the field level.
@@ -230,10 +258,11 @@ export interface FieldConfig extends Omit<Field, 'name' | 'label' | 'type' | 'op
230258
min_length?: number;
231259
/** Maximum length for strings */
232260
max_length?: number;
233-
/** Regular expression pattern for validation */
261+
/**
262+
* Regular expression pattern for validation.
263+
* Use this for custom pattern matching (e.g., /^[A-Z]{2}\d{4}$/ for codes).
264+
*/
234265
pattern?: string;
235-
/** Regex pattern (alias for pattern) */
236-
regex?: string;
237266
/** Custom validation message */
238267
message?: string;
239268
};

packages/runtime/server/src/metadata.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export function createMetadataHandler(app: IObjectQL, options?: MetadataHandlerO
199199
max: field.max,
200200
minLength: field.minLength,
201201
maxLength: field.maxLength,
202-
regex: field.regex
202+
validation: field.validation
203203
});
204204
}
205205

0 commit comments

Comments
 (0)