struct Export {
    uint32 part_id;
    StringPointer name;
}


struct JavascriptBundledPart {
    StringPointer code;

    uint32 dependencies_offset;
    uint32 dependencies_length;

    uint32 exports_offset;
    uint32 exports_length;

    uint32 from_module;

    // The ESM export is this id ("$" + number.toString(16))
    uint32 id;
}

struct JavascriptBundledModule {
  // package-relative path including file extension
  StringPointer path;

  uint32 parts_offset;
  uint32 parts_length;

  uint32 exports_offset;
  uint32 exports_length;

  // index into JavascriptBundle.packages
  uint32 package_id;

  // This lets us efficiently compare strings ignoring the extension
  byte path_extname_length;
}

struct JavascriptBundledPackage {
  StringPointer name;
  StringPointer version;
  uint32 hash;

  uint32 modules_offset;
  uint32 modules_length;
}

struct JavascriptBundle {
  // These are sorted alphabetically so you can do binary search
  JavascriptBundledModule[] modules;
  JavascriptBundledPackage[] packages;
  
  // This is ASCII-encoded so you can send it directly over HTTP
  byte[] etag;

  uint32 generated_at;

  byte[] import_from_name;

  // This is what StringPointer refers to 
  byte[] manifest_string;
}

message JavascriptBundleContainer {
  uint32 bundle_format_version = 1;

  // These go first so if we change JavaScriptBundle we can still read these
  LoadedRouteConfig routes = 3;
  LoadedFramework framework = 2;

  JavascriptBundle bundle = 4;

  // Don't technically need to store this, but it may be helpful as a sanity check
  uint32 code_length = 5;
}
