@metaobjectsdev/runtime-ts 0.14.2 → 0.15.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.
@@ -60,7 +60,8 @@ export function runValidators(
60
60
  // DB will fill them in (e.g. timestamps with `@default: CURRENT_TIMESTAMP`,
61
61
  // booleans with `@default: false`).
62
62
  const required = isRequired(field);
63
- const hasDefault = field.ownAttr(FIELD_ATTR_DEFAULT) !== undefined;
63
+ // ADR-0039: effective attr @default may be inherited via extends.
64
+ const hasDefault = field.attr(FIELD_ATTR_DEFAULT) !== undefined;
64
65
  if (required && (value === undefined || value === null)) {
65
66
  if (opts.partial && !present) continue;
66
67
  if (hasDefault) continue;
@@ -80,6 +81,7 @@ export function runValidators(
80
81
  // string type-check + length checks must NOT fire — they would reject the
81
82
  // very value the column is declared to hold. Required-ness (above) still
82
83
  // applies; everything else is unconstrained for the open bag.
84
+ // ADR-0039: @dbColumnType is the ONE deliberately own-only attr (physical, never inherited).
83
85
  if (field.subType === FIELD_SUBTYPE_STRING && field.ownAttr(FIELD_ATTR_DB_COLUMN_TYPE) === DB_COLUMN_TYPE_JSONB) {
84
86
  continue;
85
87
  }
@@ -119,10 +121,12 @@ export function runValidators(
119
121
  }
120
122
  }
121
123
 
122
- for (const child of field.ownChildren()) {
124
+ // ADR-0039: effective children — a validator may be inherited via extends.
125
+ for (const child of field.children()) {
123
126
  if (child.type !== TYPE_VALIDATOR) continue;
124
127
  if (child.subType !== VALIDATOR_SUBTYPE_REGEX) continue;
125
- const pattern = child.ownAttr(VALIDATOR_ATTR_PATTERN);
128
+ // ADR-0039: effective attr — @pattern may be inherited.
129
+ const pattern = child.attr(VALIDATOR_ATTR_PATTERN);
126
130
  if (typeof pattern !== "string") continue;
127
131
  if (typeof value !== "string") continue;
128
132
  let regex: RegExp;
@@ -153,30 +157,33 @@ export function runValidators(
153
157
  }
154
158
 
155
159
  function isRequired(field: MetaData): boolean {
156
- if (field.ownAttr(FIELD_ATTR_REQUIRED) === true) return true;
157
- for (const child of field.ownChildren()) {
160
+ // ADR-0039: effective @required and a required-validator may be inherited via extends.
161
+ if (field.attr(FIELD_ATTR_REQUIRED) === true) return true;
162
+ for (const child of field.children()) {
158
163
  if (child.type === TYPE_VALIDATOR && child.subType === VALIDATOR_SUBTYPE_REQUIRED) return true;
159
164
  }
160
165
  return false;
161
166
  }
162
167
 
163
168
  function resolveMaxLength(field: MetaData): number | undefined {
164
- const attr = field.ownAttr(FIELD_ATTR_MAX_LENGTH);
169
+ // ADR-0039: effective — @maxLength and a length-validator may be inherited via extends.
170
+ const attr = field.attr(FIELD_ATTR_MAX_LENGTH);
165
171
  if (typeof attr === "number") return attr;
166
- for (const child of field.ownChildren()) {
172
+ for (const child of field.children()) {
167
173
  if (child.type !== TYPE_VALIDATOR) continue;
168
174
  if (child.subType !== VALIDATOR_SUBTYPE_LENGTH) continue;
169
- const max = child.ownAttr(VALIDATOR_ATTR_MAX);
175
+ const max = child.attr(VALIDATOR_ATTR_MAX);
170
176
  if (typeof max === "number") return max;
171
177
  }
172
178
  return undefined;
173
179
  }
174
180
 
175
181
  function resolveMinLength(field: MetaData): number | undefined {
176
- for (const child of field.ownChildren()) {
182
+ // ADR-0039: effective a length-validator may be inherited via extends.
183
+ for (const child of field.children()) {
177
184
  if (child.type !== TYPE_VALIDATOR) continue;
178
185
  if (child.subType !== VALIDATOR_SUBTYPE_LENGTH) continue;
179
- const min = child.ownAttr(VALIDATOR_ATTR_MIN);
186
+ const min = child.attr(VALIDATOR_ATTR_MIN);
180
187
  if (typeof min === "number") return min;
181
188
  }
182
189
  return undefined;
package/src/view.ts CHANGED
@@ -24,9 +24,10 @@ export interface EntityViewSpec {
24
24
 
25
25
  export function viewFieldNames(entity: MetaData, viewName: string): string[] {
26
26
  const names: string[] = [];
27
- for (const field of entity.ownChildren()) {
27
+ // ADR-0039: effective children — fields and their views may be inherited via extends.
28
+ for (const field of entity.children()) {
28
29
  if (field.type !== TYPE_FIELD) continue;
29
- if (field.ownChildren().some((c) => c.type === TYPE_VIEW && c.name === viewName)) {
30
+ if (field.children().some((c) => c.type === TYPE_VIEW && c.name === viewName)) {
30
31
  names.push(field.name);
31
32
  }
32
33
  }
@@ -34,14 +35,16 @@ export function viewFieldNames(entity: MetaData, viewName: string): string[] {
34
35
  }
35
36
 
36
37
  export function fieldViewSpec(entity: MetaData, fieldName: string, viewName: string): FieldViewSpec | null {
37
- const field = entity.ownChildren().find((c) => c.type === TYPE_FIELD && c.name === fieldName);
38
+ // ADR-0039: effective children — a field and its view may be inherited via extends.
39
+ const field = entity.children().find((c) => c.type === TYPE_FIELD && c.name === fieldName);
38
40
  if (!field) return null;
39
- const view = field.ownChildren().find((c) => c.type === TYPE_VIEW && c.name === viewName);
41
+ const view = field.children().find((c) => c.type === TYPE_VIEW && c.name === viewName);
40
42
  if (!view) return null;
41
43
 
42
44
  const attrs: Record<string, unknown> = {};
43
- for (const key of view.ownAttrs().keys()) {
44
- attrs[key] = view.ownAttr(key);
45
+ // ADR-0039: effective attrs — a view's attrs may be inherited via its extends.
46
+ for (const key of view.attrs().keys()) {
47
+ attrs[key] = view.attr(key);
45
48
  }
46
49
 
47
50
  const required = isFieldRequired(field);
@@ -59,7 +62,8 @@ export function fieldViewSpec(entity: MetaData, fieldName: string, viewName: str
59
62
 
60
63
  export function entityViewSpec(entity: MetaData, viewName: string): EntityViewSpec {
61
64
  const fields: FieldViewSpec[] = [];
62
- for (const field of entity.ownChildren()) {
65
+ // ADR-0039: effective children — fields may be inherited via extends.
66
+ for (const field of entity.children()) {
63
67
  if (field.type !== TYPE_FIELD) continue;
64
68
  const spec = fieldViewSpec(entity, field.name, viewName);
65
69
  if (spec !== null) fields.push(spec);
@@ -74,8 +78,9 @@ export function entityViewSpec(entity: MetaData, viewName: string): EntityViewSp
74
78
  }
75
79
 
76
80
  function isFieldRequired(field: MetaData): boolean {
77
- if (field.ownAttr(FIELD_ATTR_REQUIRED) === true) return true;
78
- for (const child of field.ownChildren()) {
81
+ // ADR-0039: effective @required and a required-validator may be inherited via extends.
82
+ if (field.attr(FIELD_ATTR_REQUIRED) === true) return true;
83
+ for (const child of field.children()) {
79
84
  if (child.type === TYPE_VALIDATOR && child.subType === VALIDATOR_SUBTYPE_REQUIRED) return true;
80
85
  }
81
86
  return false;