|
@@ -31,8 +31,8 @@ import * as fmdModels from '../models/field.model';
|
|
// AutoMeta: Generate Automatic Metadata from a model
|
|
// AutoMeta: Generate Automatic Metadata from a model
|
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
-const isScalar = val => typeof val === 'boolean' || typeof val === 'number' || typeof val === 'string';
|
|
|
|
-const isArray = val => Array.isArray(val);
|
|
|
|
|
|
+const isScalar = (val: any) => typeof val === 'boolean' || typeof val === 'number' || typeof val === 'string';
|
|
|
|
+const isArray = (val: any) => Array.isArray(val);
|
|
|
|
|
|
const keyValPairToMeta = (val: any, key: string) => ({ name: key, [isScalar(val) ? 'value' : 'meta']: val });
|
|
const keyValPairToMeta = (val: any, key: string) => ({ name: key, [isScalar(val) ? 'value' : 'meta']: val });
|
|
const keyValPairToMetaRecursive = ( [key, val] ) => {
|
|
const keyValPairToMetaRecursive = ( [key, val] ) => {
|
|
@@ -72,11 +72,10 @@ const combineExtraMeta = (metaG, extraMeta, createFromExtra = false, containerSe
|
|
Object.entries(extraMeta).forEach(([key, val]: [string, StringMap<any>]) => {
|
|
Object.entries(extraMeta).forEach(([key, val]: [string, StringMap<any>]) => {
|
|
if (typeof metaG[key] === 'object' || createFromExtra) { // If the key exists (in the model) OR we're creating from metadata
|
|
if (typeof metaG[key] === 'object' || createFromExtra) { // If the key exists (in the model) OR we're creating from metadata
|
|
const isCon = isContainer(val);
|
|
const isCon = isContainer(val);
|
|
- const isRepeating = isRepeatingContainer(val);
|
|
|
|
const metaFoG = metaG[key] || {};
|
|
const metaFoG = metaG[key] || {};
|
|
const seed = isCon ? {} : containerSeed; // Container's don't seed themselves, only their children
|
|
const seed = isCon ? {} : containerSeed; // Container's don't seed themselves, only their children
|
|
|
|
|
|
- if (isRepeating)
|
|
|
|
|
|
+ if (isRepeatingContainer(val))
|
|
{
|
|
{
|
|
// We've got a Repeating Container
|
|
// We've got a Repeating Container
|
|
const baseObjWithAllKeys = getRCBaseObjectWithAllKeys(metaFoG, val, createFromExtra);
|
|
const baseObjWithAllKeys = getRCBaseObjectWithAllKeys(metaFoG, val, createFromExtra);
|
|
@@ -102,9 +101,10 @@ const combineExtraMeta = (metaG, extraMeta, createFromExtra = false, containerSe
|
|
val['seed'] || containerSeed
|
|
val['seed'] || containerSeed
|
|
);
|
|
);
|
|
}
|
|
}
|
|
- else
|
|
|
|
|
|
+ else // ----------------------------------------------
|
|
{
|
|
{
|
|
// We've got a Container or a Field
|
|
// We've got a Container or a Field
|
|
|
|
+ /*
|
|
const extra = isCon ?
|
|
const extra = isCon ?
|
|
{
|
|
{
|
|
...val,
|
|
...val,
|
|
@@ -116,7 +116,31 @@ const combineExtraMeta = (metaG, extraMeta, createFromExtra = false, containerSe
|
|
)
|
|
)
|
|
}
|
|
}
|
|
:
|
|
:
|
|
- val;
|
|
|
|
|
|
+ isRepeatingField(val) ? [ val, val, val ] : val; // <----------! HERE WE BE WORKING!
|
|
|
|
+ */
|
|
|
|
+ let extra: StringMap<any>;
|
|
|
|
+ if (isCon) {
|
|
|
|
+ extra = {
|
|
|
|
+ ...val,
|
|
|
|
+ meta: combineExtraMeta( // RECURSION
|
|
|
|
+ metaFoG.meta || {},
|
|
|
|
+ val['meta'],
|
|
|
|
+ createFromExtra,
|
|
|
|
+ val['seed'] || containerSeed // Inherit seeded data if this group's seed isn't set
|
|
|
|
+ )
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else // ----------------------------------------------
|
|
|
|
+ {
|
|
|
|
+ if (isRepeatingField(val)) {
|
|
|
|
+ extra = {
|
|
|
|
+ ...val,
|
|
|
|
+ meta: [ val, val, val ] // <----------! HERE WE BE WORKING!
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ extra = val;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
combinedMeta[key] = combineMetaForField(metaFoG, seed, extra);
|
|
combinedMeta[key] = combineMetaForField(metaFoG, seed, extra);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -664,6 +688,10 @@ const undefinedNullOrScalar = val => {
|
|
// Add Property to object, returning updated object
|
|
// Add Property to object, returning updated object
|
|
const addProp = (obj, key, val) => { obj[key] = val; return obj; };
|
|
const addProp = (obj, key, val) => { obj[key] = val; return obj; };
|
|
|
|
|
|
|
|
+// Is Repeating Field
|
|
|
|
+// Helper function to distinguish a repeating field (a field that can be repeated 1...N times)
|
|
|
|
+const isRepeatingField = (metaF): boolean => metaF.minRepeat || metaF.maxRepeat || metaF.initialRepeat;
|
|
|
|
+
|
|
// Is Group
|
|
// Is Group
|
|
// Helper function to distinguish group from field
|
|
// Helper function to distinguish group from field
|
|
const isGroup = (metaFoG): boolean => !!metaFoG.meta;
|
|
const isGroup = (metaFoG): boolean => !!metaFoG.meta;
|