@metaobjectsdev/runtime-ts 0.14.1 → 0.15.0-rc.1
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/extract-object.js +25 -19
- package/dist/extract-object.js.map +1 -1
- package/dist/identity-strategy.d.ts.map +1 -1
- package/dist/identity-strategy.js +4 -2
- package/dist/identity-strategy.js.map +1 -1
- package/dist/n2m-resolver.d.ts.map +1 -1
- package/dist/n2m-resolver.js +11 -7
- package/dist/n2m-resolver.js.map +1 -1
- package/dist/object-manager.d.ts.map +1 -1
- package/dist/object-manager.js +4 -2
- package/dist/object-manager.js.map +1 -1
- package/dist/relation-resolver.d.ts.map +1 -1
- package/dist/relation-resolver.js +21 -12
- package/dist/relation-resolver.js.map +1 -1
- package/dist/tph.d.ts.map +1 -1
- package/dist/tph.js +4 -1
- package/dist/tph.js.map +1 -1
- package/dist/type-coercer.js +9 -4
- package/dist/type-coercer.js.map +1 -1
- package/dist/validator-runner.d.ts.map +1 -1
- package/dist/validator-runner.js +17 -10
- package/dist/validator-runner.js.map +1 -1
- package/dist/view.d.ts.map +1 -1
- package/dist/view.js +14 -9
- package/dist/view.js.map +1 -1
- package/package.json +3 -3
- package/src/extract-object.ts +25 -19
- package/src/identity-strategy.ts +4 -2
- package/src/n2m-resolver.ts +11 -7
- package/src/object-manager.ts +4 -2
- package/src/relation-resolver.ts +21 -12
- package/src/tph.ts +4 -1
- package/src/type-coercer.ts +9 -4
- package/src/validator-runner.ts +17 -10
- package/src/view.ts +14 -9
package/src/validator-runner.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
157
|
-
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
44
|
-
|
|
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
|
-
|
|
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
|
-
|
|
78
|
-
|
|
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;
|