process method

MetaFormResult process(
  1. IMSchemaDefinition definition, {
  2. JsonPath? basePath,
  3. Iterable<IMetaPropertyHandler>? adhocHandlers,
})

Examines a schema definition, and locates the appropriate handlers for each logical property. The basePath is used in the case where a subform is "flattened" into it's parent, and helps the system recognize and read/store data to the subtree, even though the visual representation is flattened.

Implementation

MetaFormResult process(
  IMSchemaDefinition definition, {
  JsonPath? basePath,
  Iterable<IMetaPropertyHandler>? adhocHandlers,
}) {
  basePath ??= JsonPath.root();
  final result = MetaFormResult(definition: definition, basePath: basePath);
  [...?adhocHandlers, ...handlers].forEach((handler) {
    final accepted = [
      ...(handler as MetaPropertyHandler)
          .acceptProperties(basePath, definition, result.pending)
    ];
    for (final handled in accepted) {
      // Verify that these fields aren't already handled
      final alreadyMapped = handled.paths.keys
          .where((path) => result.mappedFields.containsKey(path));
      if (alreadyMapped.isNotEmpty) {
        log.info(
            "Skipping paths ${handled.paths} because the following were already mapped: $alreadyMapped");
        continue;
      }

      handled.paths.keys.forEach((path) {
        result.mappedFields[path] = handled;
        result.pending.remove(path);
      });

      result.handled[handled.path] = handled;
    }
  });

  return result;
}