@stonecrop/stonecrop 0.11.4 → 0.11.5
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/registry.js +64 -12
- package/dist/src/registry.d.ts +9 -2
- package/dist/src/registry.d.ts.map +1 -1
- package/dist/stonecrop.d.ts +9 -2
- package/dist/stonecrop.js +225 -176
- package/dist/stonecrop.js.map +1 -1
- package/package.json +4 -4
- package/src/registry.ts +83 -14
package/dist/registry.js
CHANGED
|
@@ -96,7 +96,7 @@ export default class Registry {
|
|
|
96
96
|
* For each link field:
|
|
97
97
|
* - Looks up the corresponding link declaration in `links` by fieldname
|
|
98
98
|
* - `cardinality: 'noneOrMany'` or `'atLeastOne'`: auto-derives `columns` from the target's schema,
|
|
99
|
-
* sets `component` to `link.component ?? 'ATable'`, `config: { view: 'list' }
|
|
99
|
+
* sets `component` to `link.component ?? 'ATable'`, `config: { view: 'list' }`.
|
|
100
100
|
* - `cardinality: 'one'` or `'atMostOne'`: embeds the target schema as the entry's
|
|
101
101
|
* `schema` property, sets `component` to `link.component ?? 'AForm'`.
|
|
102
102
|
*
|
|
@@ -150,20 +150,30 @@ export default class Registry {
|
|
|
150
150
|
continue;
|
|
151
151
|
}
|
|
152
152
|
const childSchema = this.resolveSchema(targetDoctype, seen);
|
|
153
|
+
// Extract properties consumed by resolution; preserve everything else
|
|
154
|
+
// TODO: options and cardinality are untyped runtime properties on link fields; add them to
|
|
155
|
+
// FormSchema (or a dedicated link field type) to remove this cast
|
|
156
|
+
const { fieldtype: _ft, options: _opt, cardinality: _card, ...fieldRest } = field;
|
|
153
157
|
if (link.cardinality === 'noneOrMany' || link.cardinality === 'atLeastOne') {
|
|
154
158
|
// Many relationship — build table config
|
|
155
|
-
resolvedFields.push(this.buildTableConfig({
|
|
159
|
+
resolvedFields.push(this.buildTableConfig({ ...fieldRest, label: fieldRest.label || field.fieldname }, childSchema, link.component));
|
|
156
160
|
}
|
|
157
161
|
else {
|
|
158
162
|
// One relationship — embed form schema
|
|
163
|
+
// TODO: remove assertion once resolved link output has a dedicated type separate from input schema
|
|
159
164
|
resolvedFields.push({
|
|
160
|
-
|
|
161
|
-
label:
|
|
162
|
-
component: link.component || 'AForm',
|
|
165
|
+
...fieldRest,
|
|
166
|
+
label: fieldRest.label || field.fieldname,
|
|
167
|
+
component: link.component || fieldRest.component || 'AForm',
|
|
163
168
|
schema: childSchema,
|
|
164
169
|
});
|
|
165
170
|
}
|
|
166
171
|
}
|
|
172
|
+
else if ('schema' in field && Array.isArray(field.schema)) {
|
|
173
|
+
// Fieldset — recursively resolve nested fields
|
|
174
|
+
const resolvedChildren = this.resolveFields(field.schema, linksByFieldname, seen);
|
|
175
|
+
resolvedFields.push({ ...field, schema: resolvedChildren });
|
|
176
|
+
}
|
|
167
177
|
else {
|
|
168
178
|
// Scalar field — copy as-is
|
|
169
179
|
resolvedFields.push({ ...field });
|
|
@@ -173,16 +183,60 @@ export default class Registry {
|
|
|
173
183
|
return resolvedFields;
|
|
174
184
|
}
|
|
175
185
|
/**
|
|
176
|
-
*
|
|
186
|
+
* Recursively resolve a flat fields array using the provided link context.
|
|
187
|
+
* Used by resolveSchema to handle fieldset children.
|
|
188
|
+
* @internal
|
|
189
|
+
*/
|
|
190
|
+
resolveFields(fields, links, visited) {
|
|
191
|
+
const resolved = [];
|
|
192
|
+
for (const field of fields) {
|
|
193
|
+
if ('fieldtype' in field && field.fieldtype === 'Link') {
|
|
194
|
+
const link = links.get(field.fieldname);
|
|
195
|
+
if (!link) {
|
|
196
|
+
resolved.push({ ...field });
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
const targetDoctype = this.registry[link.target];
|
|
200
|
+
if (!targetDoctype) {
|
|
201
|
+
resolved.push({ ...field });
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
const childSchema = this.resolveSchema(targetDoctype, new Set(visited));
|
|
205
|
+
const { fieldtype: _ft, options: _opt, cardinality: _card, ...fieldRest } = field;
|
|
206
|
+
if (link.cardinality === 'noneOrMany' || link.cardinality === 'atLeastOne') {
|
|
207
|
+
resolved.push(this.buildTableConfig({ ...fieldRest, label: fieldRest.label || field.fieldname }, childSchema, link.component));
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
// TODO: remove assertion once resolved link output has a dedicated type separate from input schema
|
|
211
|
+
resolved.push({
|
|
212
|
+
...fieldRest,
|
|
213
|
+
label: fieldRest.label || field.fieldname,
|
|
214
|
+
component: link.component || fieldRest.component || 'AForm',
|
|
215
|
+
schema: childSchema,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
else if ('schema' in field && Array.isArray(field.schema)) {
|
|
220
|
+
resolved.push({ ...field, schema: this.resolveFields(field.schema, links, visited) });
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
resolved.push({ ...field });
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return resolved;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Build an ATable configuration from a field and child schema.
|
|
230
|
+
* Data-model properties from the source field are preserved via the spread `field` argument.
|
|
177
231
|
* @internal
|
|
178
232
|
*/
|
|
179
233
|
buildTableConfig(field, childSchema, component) {
|
|
180
234
|
const resolved = {
|
|
235
|
+
...field,
|
|
181
236
|
fieldname: field.fieldname,
|
|
182
237
|
component: component || field.component || 'ATable',
|
|
183
238
|
columns: field.columns,
|
|
184
239
|
config: field.config,
|
|
185
|
-
rows: field.rows,
|
|
186
240
|
};
|
|
187
241
|
if (!resolved.columns) {
|
|
188
242
|
resolved.columns = childSchema
|
|
@@ -199,9 +253,6 @@ export default class Registry {
|
|
|
199
253
|
if (!resolved.config) {
|
|
200
254
|
resolved.config = { view: 'list' };
|
|
201
255
|
}
|
|
202
|
-
if (!resolved.rows) {
|
|
203
|
-
resolved.rows = [];
|
|
204
|
-
}
|
|
205
256
|
return resolved;
|
|
206
257
|
}
|
|
207
258
|
/**
|
|
@@ -242,8 +293,9 @@ export default class Registry {
|
|
|
242
293
|
record[field.fieldname] = [];
|
|
243
294
|
return;
|
|
244
295
|
}
|
|
245
|
-
// Resolved 1:many table entry —
|
|
246
|
-
|
|
296
|
+
// Resolved 1:many table entry — structural detection via columns
|
|
297
|
+
// TODO: replace 'columns' presence check with a type discriminant on SchemaTypes once one exists
|
|
298
|
+
if ('columns' in field) {
|
|
247
299
|
record[field.fieldname] = [];
|
|
248
300
|
return;
|
|
249
301
|
}
|
package/dist/src/registry.d.ts
CHANGED
|
@@ -74,7 +74,7 @@ export default class Registry {
|
|
|
74
74
|
* For each link field:
|
|
75
75
|
* - Looks up the corresponding link declaration in `links` by fieldname
|
|
76
76
|
* - `cardinality: 'noneOrMany'` or `'atLeastOne'`: auto-derives `columns` from the target's schema,
|
|
77
|
-
* sets `component` to `link.component ?? 'ATable'`, `config: { view: 'list' }
|
|
77
|
+
* sets `component` to `link.component ?? 'ATable'`, `config: { view: 'list' }`.
|
|
78
78
|
* - `cardinality: 'one'` or `'atMostOne'`: embeds the target schema as the entry's
|
|
79
79
|
* `schema` property, sets `component` to `link.component ?? 'AForm'`.
|
|
80
80
|
*
|
|
@@ -89,7 +89,14 @@ export default class Registry {
|
|
|
89
89
|
*/
|
|
90
90
|
resolveSchema(doctype: Doctype, visited?: Set<string>): SchemaTypes[];
|
|
91
91
|
/**
|
|
92
|
-
*
|
|
92
|
+
* Recursively resolve a flat fields array using the provided link context.
|
|
93
|
+
* Used by resolveSchema to handle fieldset children.
|
|
94
|
+
* @internal
|
|
95
|
+
*/
|
|
96
|
+
private resolveFields;
|
|
97
|
+
/**
|
|
98
|
+
* Build an ATable configuration from a field and child schema.
|
|
99
|
+
* Data-model properties from the source field are preserved via the spread `field` argument.
|
|
93
100
|
* @internal
|
|
94
101
|
*/
|
|
95
102
|
private buildTableConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/registry.ts"],"names":[],"mappings":"AAA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AW,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAqD5D;;;;;OAKG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS;IAI7C;;;;;;;;;;;;;OAaG;IACH,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,KAAK,CAAC,eAAe,GAAG;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAUvF;;;;;;;;;;;;;OAaG;IACH,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,KAAK,CAAC,eAAe,GAAG;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAwBtG;;;OAGG;IACH,OAAO,CAAC,oBAAoB;CAgC5B"}
|
package/dist/stonecrop.d.ts
CHANGED
|
@@ -1240,7 +1240,7 @@ export declare class Registry {
|
|
|
1240
1240
|
* For each link field:
|
|
1241
1241
|
* - Looks up the corresponding link declaration in `links` by fieldname
|
|
1242
1242
|
* - `cardinality: 'noneOrMany'` or `'atLeastOne'`: auto-derives `columns` from the target's schema,
|
|
1243
|
-
* sets `component` to `link.component ?? 'ATable'`, `config: { view: 'list' }
|
|
1243
|
+
* sets `component` to `link.component ?? 'ATable'`, `config: { view: 'list' }`.
|
|
1244
1244
|
* - `cardinality: 'one'` or `'atMostOne'`: embeds the target schema as the entry's
|
|
1245
1245
|
* `schema` property, sets `component` to `link.component ?? 'AForm'`.
|
|
1246
1246
|
*
|
|
@@ -1255,7 +1255,14 @@ export declare class Registry {
|
|
|
1255
1255
|
*/
|
|
1256
1256
|
resolveSchema(doctype: Doctype, visited?: Set<string>): SchemaTypes[];
|
|
1257
1257
|
/**
|
|
1258
|
-
*
|
|
1258
|
+
* Recursively resolve a flat fields array using the provided link context.
|
|
1259
|
+
* Used by resolveSchema to handle fieldset children.
|
|
1260
|
+
* @internal
|
|
1261
|
+
*/
|
|
1262
|
+
private resolveFields;
|
|
1263
|
+
/**
|
|
1264
|
+
* Build an ATable configuration from a field and child schema.
|
|
1265
|
+
* Data-model properties from the source field are preserved via the spread `field` argument.
|
|
1259
1266
|
* @internal
|
|
1260
1267
|
*/
|
|
1261
1268
|
private buildTableConfig;
|