Get rid of ts flatbuffer namespaces.

They aren't really required and complicate imports.

Change-Id: I4fa401bb58a84563553236b18042dade9b16ad8d
diff --git a/aos/BUILD b/aos/BUILD
index 47de872..4936da4 100644
--- a/aos/BUILD
+++ b/aos/BUILD
@@ -1,5 +1,5 @@
 load("//tools:environments.bzl", "mcu_cpus")
-load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_cc_library", "flatbuffer_py_library")
+load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_cc_library", "flatbuffer_py_library", "flatbuffer_ts_library")
 
 filegroup(
     name = "prime_binaries",
@@ -287,6 +287,12 @@
     visibility = ["//visibility:public"],
 )
 
+flatbuffer_ts_library(
+    name = "configuration_ts_fbs",
+    srcs = ["configuration.fbs"],
+    visibility = ["//visibility:public"],
+)
+
 flatbuffer_py_library(
     name = "configuration_fbs_python",
     srcs = ["configuration.fbs"],
diff --git a/aos/network/BUILD b/aos/network/BUILD
index 96d561f..89853f0 100644
--- a/aos/network/BUILD
+++ b/aos/network/BUILD
@@ -13,6 +13,14 @@
     ],
 )
 
+flatbuffer_ts_library(
+    name = "connect_ts_fbs",
+    srcs = ["connect.fbs"],
+    includes = [
+        "//aos:configuration_fbs_includes",
+    ],
+)
+
 flatbuffer_cc_library(
     name = "timestamp_fbs",
     srcs = ["timestamp.fbs"],
diff --git a/aos/network/www/BUILD b/aos/network/www/BUILD
index 76e8ef4..bab5198 100644
--- a/aos/network/www/BUILD
+++ b/aos/network/www/BUILD
@@ -18,6 +18,8 @@
     ],
     deps = [
         "//aos/network:web_proxy_ts_fbs",
+        "//aos/network:connect_ts_fbs",
+        "//aos:configuration_ts_fbs",
     ],
     visibility=["//visibility:public"],
 )
diff --git a/aos/network/www/config_handler.ts b/aos/network/www/config_handler.ts
index 0af78b6..aed3315 100644
--- a/aos/network/www/config_handler.ts
+++ b/aos/network/www/config_handler.ts
@@ -1,10 +1,11 @@
-import {aos} from 'aos/network/web_proxy_generated';
+import {Configuration, Channel} from 'aos/configuration_generated';
+import {Connect} from 'aos/network/connect_generated';
 
 export class ConfigHandler {
   private readonly root_div = document.getElementById('config');
 
   constructor(
-      private readonly config: aos.Configuration,
+      private readonly config: Configuration,
       private readonly dataChannel: RTCDataChannel) {}
 
   printConfig() {
@@ -46,19 +47,19 @@
       const channel = this.config.channels(index);
       const namefb = builder.createString(channel.name());
       const typefb = builder.createString(channel.type());
-      aos.Channel.startChannel(builder);
-      aos.Channel.addName(builder, namefb);
-      aos.Channel.addType(builder, typefb);
-      const channelfb = aos.Channel.endChannel(builder);
+      Channel.startChannel(builder);
+      Channel.addName(builder, namefb);
+      Channel.addType(builder, typefb);
+      const channelfb = Channel.endChannel(builder);
       channels.push(channelfb);
     }
 
     const channelsfb =
-        aos.message_bridge.Connect.createChannelsToTransferVector(
+        Connect.createChannelsToTransferVector(
             builder, channels);
-    aos.message_bridge.Connect.startConnect(builder);
-    aos.message_bridge.Connect.addChannelsToTransfer(builder, channelsfb);
-    const connect = aos.message_bridge.Connect.endConnect(builder);
+    Connect.startConnect(builder);
+    Connect.addChannelsToTransfer(builder, channelsfb);
+    const connect = Connect.endConnect(builder);
     builder.finish(connect);
     const array = builder.asUint8Array();
     console.log('connect', array);
diff --git a/aos/network/www/ping_handler.ts b/aos/network/www/ping_handler.ts
index 9b37d70..df7635d 100644
--- a/aos/network/www/ping_handler.ts
+++ b/aos/network/www/ping_handler.ts
@@ -1,8 +1,8 @@
-import {aos} from 'aos/events/ping_generated';
+import {Ping} from 'aos/events/ping_generated';
 
 export function HandlePing(data: Uint8Array) {
   const fbBuffer = new flatbuffers.ByteBuffer(data);
-  const ping = aos.examples.Ping.getRootAsPing(fbBuffer);
+  const ping = Ping.getRootAsPing(fbBuffer);
 
   document.getElementById('val').innerHTML = ping.value();
   document.getElementById('time').innerHTML = ping.sendTime().low;
diff --git a/aos/network/www/proxy.ts b/aos/network/www/proxy.ts
index 27ffbfe..80c71b2 100644
--- a/aos/network/www/proxy.ts
+++ b/aos/network/www/proxy.ts
@@ -1,5 +1,5 @@
-import {aos} from 'aos/network/web_proxy_generated';
 import {ConfigHandler} from './config_handler';
+import {Configuration} from 'aos/configuration_generated';
 
 // There is one handler for each DataChannel, it maintains the state of
 // multi-part messages and delegates to a callback when the message is fully
@@ -16,7 +16,7 @@
   handleMessage(e: MessageEvent): void {
     const fbBuffer = new flatbuffers.ByteBuffer(new Uint8Array(e.data));
     const messageHeader =
-        aos.web_proxy.MessageHeader.getRootAsMessageHeader(fbBuffer);
+        WebProxy.MessageHeader.getRootAsMessageHeader(fbBuffer);
     // Short circuit if only one packet
     if (messageHeader.packetCount === 1) {
       this.handlerFunc(messageHeader.dataArray());
@@ -44,8 +44,8 @@
   private rtcPeerConnection: RTCPeerConnection|null = null;
   private dataChannel: DataChannel|null = null;
   private webSocketUrl: string;
-  private configHandler: ConfigHandler|null =
-      null private config: aos.Configuration|null = null;
+  private configHandler: ConfigHandler|null = null;
+  private config: Configuration|null = null;
   private readonly handlerFuncs = new Map<string, (data: Uint8Array) => void>();
   private readonly handlers = new Set<Handler>();
 
@@ -98,10 +98,10 @@
     const candidateString = builder.createString(candidate.candidate);
     const sdpMidString = builder.createString(candidate.sdpMid);
 
-    const iceFb = aos.web_proxy.WebSocketIce.createWebSocketIce(
+    const iceFb = WebProxy.WebSocketIce.createWebSocketIce(
         builder, candidateString, sdpMidString, candidate.sdpMLineIndex);
-    const messageFb = aos.web_proxy.WebSocketMessage.createWebSocketMessage(
-        builder, aos.web_proxy.Payload.WebSocketIce, iceFb);
+    const messageFb = WebProxy.WebSocketMessage.createWebSocketMessage(
+        builder, WebProxy.Payload.WebSocketIce, iceFb);
     builder.finish(messageFb);
     const array = builder.asUint8Array();
     this.webSocketConnection.send(array.buffer.slice(array.byteOffset));
@@ -113,10 +113,10 @@
     const builder = new flatbuffers.Builder(512);
     const offerString = builder.createString(description.sdp);
 
-    const webSocketSdp = aos.web_proxy.WebSocketSdp.createWebSocketSdp(
-        builder, aos.web_proxy.SdpType.OFFER, offerString);
-    const message = aos.web_proxy.WebSocketMessage.createWebSocketMessage(
-        builder, aos.web_proxy.Payload.WebSocketSdp, webSocketSdp);
+    const webSocketSdp = WebProxy.WebSocketSdp.createWebSocketSdp(
+        builder, WebProxy.SdpType.OFFER, offerString);
+    const message = WebProxy.WebSocketMessage.createWebSocketMessage(
+        builder, WebProxy.Payload.WebSocketSdp, webSocketSdp);
     builder.finish(message);
     const array = builder.asUint8Array();
     this.webSocketConnection.send(array.buffer.slice(array.byteOffset));
@@ -145,19 +145,19 @@
     const buffer = new Uint8Array(e.data)
     const fbBuffer = new flatbuffers.ByteBuffer(buffer);
     const message =
-        aos.web_proxy.WebSocketMessage.getRootAsWebSocketMessage(fbBuffer);
+        WebProxy.WebSocketMessage.getRootAsWebSocketMessage(fbBuffer);
     switch (message.payloadType()) {
-      case aos.web_proxy.Payload.WebSocketSdp:
-        const sdpFb = message.payload(new aos.web_proxy.WebSocketSdp());
-        if (sdpFb.type() !== aos.web_proxy.SdpType.ANSWER) {
+      case WebProxy.Payload.WebSocketSdp:
+        const sdpFb = message.payload(new WebProxy.WebSocketSdp());
+        if (sdpFb.type() !== WebProxy.SdpType.ANSWER) {
           console.log('got something other than an answer back');
           break;
         }
         this.rtcPeerConnection.setRemoteDescription(new RTCSessionDescription(
             {'type': 'answer', 'sdp': sdpFb.payload()}));
         break;
-      case aos.web_proxy.Payload.WebSocketIce:
-        const iceFb = message.payload(new aos.web_proxy.WebSocketIce());
+      case WebProxy.Payload.WebSocketIce:
+        const iceFb = message.payload(new WebProxy.WebSocketIce());
         const candidate = {} as RTCIceCandidateInit;
         candidate.candidate = iceFb.candidate();
         candidate.sdpMid = iceFb.sdpMid();
diff --git a/third_party/flatbuffers/src/idl_gen_js_ts.cpp b/third_party/flatbuffers/src/idl_gen_js_ts.cpp
index be0a205..cfb0cb6 100644
--- a/third_party/flatbuffers/src/idl_gen_js_ts.cpp
+++ b/third_party/flatbuffers/src/idl_gen_js_ts.cpp
@@ -153,10 +153,9 @@
           imported_files.emplace(file.first);
         }
 
-        code += "export namespace " + file.second.target_namespace + " { \n";
+        //code += "export namespace " + file.second.target_namespace + " { \n";
         code += "export import " + file.second.symbol + " = ";
-        code += GenFileNamespacePrefix(file.first) + "." +
-                file.second.source_namespace + "." + file.second.symbol +
+        code += file.second.symbol +
                 "; }\n";
       }
     }
@@ -334,7 +333,7 @@
     std::string ns = GetNameSpace(enum_def);
     std::string enum_def_name = enum_def.name + (reverse ? "Name" : "");
     if (lang_.language == IDLOptions::kTs) {
-      if (!ns.empty()) { code += "export namespace " + ns + "{\n"; }
+      //if (!ns.empty()) { code += "export namespace " + ns + "{\n"; }
       code += "export enum " + enum_def.name + "{\n";
     } else {
       if (enum_def.defined_namespace->components.empty()) {
@@ -348,7 +347,7 @@
           exports += "this." + enum_def_name + " = " + enum_def_name + ";\n";
         }
       }
-      code += WrapInNameSpace(enum_def) + (reverse ? "Name" : "") + " = {\n";
+      code += enum_def.name + (reverse ? "Name" : "") + " = {\n";
     }
     for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end(); ++it) {
       auto &ev = **it;
@@ -416,7 +415,7 @@
         if (type.base_type == BASE_TYPE_BOOL) { getter = "!!" + getter; }
         if (type.enum_def) {
           getter = "/** " +
-                   GenTypeAnnotation(kType, WrapInNameSpace(*type.enum_def), "",
+                   GenTypeAnnotation(kType, type.enum_def->name, "",
                                      false) +
                    " */ (" + getter + ")";
         }
@@ -433,15 +432,15 @@
     if (value.type.enum_def) {
       if (auto val = value.type.enum_def->FindByValue(value.constant)) {
         if (lang_.language == IDLOptions::kTs) {
-          return GenPrefixedTypeName(WrapInNameSpace(*value.type.enum_def),
+          return GenPrefixedTypeName(value.type.enum_def->name,
                                      value.type.enum_def->file) +
                  "." + val->name;
         } else {
-          return WrapInNameSpace(*value.type.enum_def) + "." + val->name;
+          return value.type.enum_def->name + "." + val->name;
         }
       } else {
         return "/** " +
-               GenTypeAnnotation(kType, WrapInNameSpace(*value.type.enum_def),
+               GenTypeAnnotation(kType, value.type.enum_def->name,
                                  "", false) +
                "} */ (" + value.constant + ")";
       }
@@ -473,7 +472,7 @@
         if (type.base_type == BASE_TYPE_STRING) {
           name = "string|Uint8Array";
         } else {
-          name = WrapInNameSpace(*type.struct_def);
+          name = type.struct_def->name;
         }
         return (allowNull) ? (name + "|null") : (name);
       }
@@ -485,7 +484,7 @@
       case BASE_TYPE_ULONG: return "flatbuffers.Long";
       default:
         if (IsScalar(type.base_type)) {
-          if (type.enum_def) { return WrapInNameSpace(*type.enum_def); }
+          if (type.enum_def) { return type.enum_def->name; }
           return "number";
         }
         return "flatbuffers.Offset";
@@ -675,9 +674,9 @@
     if (lang_.language == IDLOptions::kTs) {
       object_name = struct_def.name;
       GenDocComment(struct_def.doc_comment, code_ptr, "@constructor");
-      if (!object_namespace.empty()) {
-        code += "export namespace " + object_namespace + "{\n";
-      }
+      //if (!object_namespace.empty()) {
+      //  code += "export namespace " + object_namespace + "{\n";
+      //}
       code += "export class " + struct_def.name;
       code += " {\n";
       if (lang_.language != IDLOptions::kTs) {
@@ -695,7 +694,7 @@
       code += "  bb_pos:number = 0;\n";
     } else {
       bool isStatement = struct_def.defined_namespace->components.empty();
-      object_name = WrapInNameSpace(struct_def);
+      object_name = struct_def.name;
       GenDocComment(struct_def.doc_comment, code_ptr, "@constructor");
       if (isStatement) {
         if (parser_.opts.use_goog_js_export_format) {
@@ -851,7 +850,7 @@
       else {
         switch (field.value.type.base_type) {
           case BASE_TYPE_STRUCT: {
-            auto type = WrapInNameSpace(*field.value.type.struct_def);
+            auto type = field.value.type.struct_def->name;
             GenDocComment(
                 field.doc_comment, code_ptr,
                 GenTypeAnnotation(kParam, type + "=", "obj") +
@@ -978,7 +977,7 @@
               if (field.value.type.enum_def) {
                 code += "/** " +
                         GenTypeAnnotation(
-                            kType, WrapInNameSpace(*field.value.type.enum_def),
+                            kType, field.value.type.enum_def->name,
                             "", false) +
                         " */ (" + field.value.constant + ")";
               } else {
@@ -1359,9 +1358,9 @@
     }
 
     if (lang_.language == IDLOptions::kTs) {
-      if (!object_namespace.empty()) {
-        code += "}\n";
-      }
+      //if (!object_namespace.empty()) {
+      //  code += "}\n";
+      //}
       code += "}\n";
     }
   }
diff --git a/y2020/vision/sift/BUILD b/y2020/vision/sift/BUILD
index 5cfb6aa..8b71119 100644
--- a/y2020/vision/sift/BUILD
+++ b/y2020/vision/sift/BUILD
@@ -1,5 +1,5 @@
 load(":fast_gaussian.bzl", "fast_gaussian")
-load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_cc_library", "flatbuffer_py_library")
+load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_cc_library", "flatbuffer_py_library", "flatbuffer_ts_library")
 
 cc_binary(
     name = "fast_gaussian_generator",
@@ -213,6 +213,12 @@
     visibility = ["//visibility:public"],
 )
 
+flatbuffer_ts_library(
+    name = "sift_ts_fbs",
+    srcs = ["sift.fbs"],
+    visibility = ["//y2020:__subpackages__"],
+)
+
 flatbuffer_cc_library(
     name = "sift_training_fbs",
     srcs = ["sift_training.fbs"],
diff --git a/y2020/www/BUILD b/y2020/www/BUILD
index 146456f..c0daa07 100644
--- a/y2020/www/BUILD
+++ b/y2020/www/BUILD
@@ -10,6 +10,7 @@
     deps = [
         "//aos/network/www:proxy",
         "//y2020/vision:vision_ts_fbs",
+        "//y2020/vision/sift:sift_ts_fbs",
     ],
     visibility = ["//y2020:__subpackages__"],
 )
diff --git a/y2020/www/image_handler.ts b/y2020/www/image_handler.ts
index abaf831..7bb2cfb 100644
--- a/y2020/www/image_handler.ts
+++ b/y2020/www/image_handler.ts
@@ -1,4 +1,4 @@
-import {frc971} from 'y2020/vision/vision_generated';
+import {CameraImage} from 'y2020/vision/vision_generated';
 
 export class ImageHandler {
   private canvas = document.createElement('canvas');
@@ -9,7 +9,7 @@
 
   handleImage(data: Uint8Array) {
     const fbBuffer = new flatbuffers.ByteBuffer(data);
-    const image = frc971.vision.CameraImage.getRootAsCameraImage(fbBuffer);
+    const image = CameraImage.getRootAsCameraImage(fbBuffer);
 
     const width = image.cols();
     const height = image.rows();
@@ -56,6 +56,6 @@
   }
 
   getId() {
-    return frc971.vision.CameraImage.getFullyQualifiedName();
+    return CameraImage.getFullyQualifiedName();
   }
 }