notationBuiltManifest function

Json? notationBuiltManifest({
  1. required Json? source,
  2. required List<String> pages,
  3. required Map<String, Json> appVariables,
})

The manifest expand writes for a site whose shared state is in app.txt, which a render reads its variables from: source (the site's own manifest; null: none, and the manifest lists pages, the page ids in order) with appVariables (app.txt's, as NotationSiteFiles.appVariables) among its variables, marked as written (notationBuiltKey). Null when there is nothing to write: a manifest of the site's own and no state in app.txt.

Implementation

Json? notationBuiltManifest({required Json? source, required List<String> pages, required Map<String, Json> appVariables}) {
  Json record(Json v) => {
        for (final k in const ['type', 'value', 'formula', 'parameters', 'options', 'persist'])
          if (v.containsKey(k)) k: v[k],
        if (!v.containsKey('value') && !v.containsKey('formula')) 'value': null,
      };
  final declared = {
    for (final e in appVariables.entries)
      if (!e.value.containsKey(notationInlineFormulaKey)) e.key: record(e.value),
  };
  if (source == null) {
    return {
      'schema': 3,
      'pages': [for (final p in pages) '$p.json'],
      if (declared.isNotEmpty) 'variables': declared,
      notationBuiltKey: {'all': true},
    };
  }
  if (declared.isEmpty) return null;
  final own = source['variables'];
  return {
    ...source,
    'variables': own is List
        ? [
            ...own,
            for (final e in declared.entries) {'name': e.key, ...e.value},
          ]
        : {...?readMap(own), ...declared},
    notationBuiltKey: {'variables': declared.keys.toList()},
  };
}