Skip to content

Resources and modular source loading

Mechanism

Asana.m loads its configuration with Extension.Contents("Config.json") and Json.Document. It binds the client ID, redirect URI, token URI, authorize URI, and API URL from the parsed record (lines 4–9). The shared Asana.Tables function is declared with DataSource.Kind="Asana" (line 11) and typed on line 12.1

Config.json holds those five values, along with nothing else. They are client identifiers and URLs, not secrets.2 Its api_url line ends with a comma before the closing brace on line 7. Strict JSON parsers reject a trailing comma. Whether Json.Document accepts this one is untested here.3

Asana.Publish takes its button text from Extension.LoadString (line 96). The function's type takes its captions and descriptions from Extension.LoadString as well (lines 14–23). Asana.Icons names PNG files (lines 102–105).45

The Asana folder holds Asana.m, Config.json, and Table.ToNavigationTable.pqm, without the named PNG or string-resource files. The archive extractor removes localization, images, and packaging noise after extraction. A source archive therefore has different dependencies from an installable connector package.

Extension.LoadFunction (lines 243–248) reads a named file with Extension.Contents, decodes it with Text.FromBinary, and evaluates it with Expression.Evaluate(asText, #shared). Line 250 binds Table.ToNavigationTable to the module Table.ToNavigationTable.pqm, which is in the folder.7 Anaplan uses the same loader for TraceContext.pqm and Diagnostics.pqm (lines 802–811), and both files are present in its folder. Anaplan also defines Table.ToNavigationTable inline (line 754).89

Selection and dependencies

Keep configuration in a package file when its values belong to the connector build. A .pqm module can hold helpers used by multiple files in that package. The inputs are packaged files and resource keys; the outputs are values and functions. Match each Extension.Contents filename and Extension.LoadString key to the corresponding packaged resource.17

Anaplan's inline copy of Table.ToNavigationTable shows the other option. It needs no extra file, but the helper is repeated in every connector that needs it. Load a module when the same helper appears in several files, and define it inline when a file must stand alone.9 For OAuth bindings, see OAuth2. For navigation tables, see navigation. For credential handling, see credential access.

Adaptation and failure paths

Match each name to a file or key. Asana's Extension.LoadString keys, such as ButtonTitle (line 96) and AuthenticationLabel (line 87), and its PNG names (lines 102–105) have no matching files in this archive. The archive is therefore not a drop-in package. Those values are unknown here, not empty.45

Use one source for each host. GetTasks calls https://reporting-api.integrations.asana.plus as a literal (line 176). The api_url value in Config.json is the same string, but changing api_url does not change that request.6

Validate JSON with a strict parser before you ship a config file. The trailing comma on Config.json line 6 is the case to test first.3

This config holds a public client ID and URLs. Keep public identifiers separate from secrets when creating a package, and follow the archive's redaction and refresh guidance before contributing extracted source.2

Check module names. The loader calls name Table.ToNavigationTable.pqm, TraceContext.pqm, and Diagnostics.pqm exactly. The file names in each folder must match those strings.78

Validation checklist

  • List each Extension.Contents, Extension.LoadString, and Extension.LoadFunction name, and confirm the file or key exists in the package.
  • Confirm that each .pqm name matches its loader string exactly.
  • Use one source for each host or URL that appears in more than one place.
  • Parse each config file with a strict JSON parser.
  • Review config values for secrets, and keep public identifiers separate from them.

Examples

Config bindings and shared entry point, Asana lines 2–12:

Asana/Asana.m · lines 2–12 Open original source ↗

section Asana;

config = Json.Document ( Extension.Contents( "Config.json") );
client_id=  config[client_id];
redirect_uri = config[redirect_uri];
token_uri = config[token_uri];
authorize_uri = config [authorize_uri];
api_url = config [api_url];

[DataSource.Kind="Asana", Publish="Asana.Publish"]
shared Asana.Tables =  Value.ReplaceType(AsanaNavTable, Asana_Type);

Module loader, Asana lines 243–250:

Asana/Asana.m · lines 243–250 Open original source ↗

Extension.LoadFunction = (name as text) =>
    let
        binary = Extension.Contents(name),
        asText = Text.FromBinary(binary)
    in
        Expression.Evaluate(asText, #shared);

Table.ToNavigationTable = Extension.LoadFunction("Table.ToNavigationTable.pqm");

Loader with two modules, Anaplan lines 802–811:

Anaplan/Anaplan.pq · lines 802–811 Open original source ↗

Extension.LoadFunction = (name as text) =>
    let
        binary = Extension.Contents(name),
        asText = Text.FromBinary(binary)
    in
        Expression.Evaluate(asText, #shared);

TraceContext = Extension.LoadFunction("TraceContext.pqm");
Diagnostics = Extension.LoadFunction("Diagnostics.pqm");
Diagnostics.LogValue = Diagnostics[LogValue];

  1. Asana/Asana.m lines 2–12: section Asana; (line 2), the five Config.json bindings (lines 4–9), DataSource.Kind (line 11), and the shared Asana.Tables (line 12). ↩↩

  2. Asana/Config.json lines 2–6: client_id, redirect_uri, token_uri, authorize_uri, and api_url. The values are client identifiers and URLs. ↩↩

  3. Asana/Config.json line 6: "api_url" ends with a comma, and the closing brace is on line 7. ↩↩

  4. Asana/Asana.m lines 93–100 (Asana.Publish): ButtonText from Extension.LoadString (line 96) and LearnMoreUrl as a literal (line 97). Lines 14–23 take captions from Extension.LoadString (lines 16–22). ↩↩

  5. Asana/Asana.m lines 102–105 (Asana.Icons): PNG names passed to Extension.Contents. ↩↩

  6. Asana/Asana.m lines 173–176 (GetTasks): the literal host in Web.Contents (line 176). api_url is read at line 9. ↩

  7. Asana/Asana.m lines 243–250 (Extension.LoadFunction): Extension.Contents, Text.FromBinary, and Expression.Evaluate (lines 245–248), then the bound Table.ToNavigationTable (line 250). ↩↩↩

  8. Anaplan/Anaplan.pq lines 802–811: the same loader, with TraceContext.pqm (line 809) and Diagnostics.pqm (line 810) loaded, and Diagnostics.LogValue bound (line 811). ↩↩

  9. Anaplan/Anaplan.pq lines 754–775 (Table.ToNavigationTable): the navigation helper defined inline in the connector file. ↩↩