message: progress on refactor
diff: @@ -69,53 +69,74 @@ export class Compiler<Identity extends Saved | Unsaved = Saved> {
  async compile(): Promise<CompiledCard<Identity, ModuleRef>> {
  let { cardSource } = this;
  -
  let originalModules = this.analyzeFiles();
  let parentCard = await this.getParentCard(originalModules);
  let fields = await this.lookupFieldsForCard(originalModules, parentCard);
  + this.assertData(fields);
  + this.outputModules = await this.transformFiles(originalModules, fields, parentCard);
  + return {
  + realm: cardSource.realm,
  + url: (cardSource.id ? `${cardSource.realm}${cardSource.id}` : undefined) as Identity,
  + schemaModule: this.getSchemaModuleRef(parentCard, cardSource.schema),
  + serializerModule: this.getSerializerModuleRef(parentCard, cardSource.serializer),
  + fields,
  + adoptsFrom: parentCard,
  + componentInfos: await this.prepareComponents(originalModules, fields, parentCard),
  + modules: this.outputModules,
  + deps: [...this.dependencies],
  + };
  + }
  - if (cardSource.data) {
  - let unexpectedFields = difference(Object.keys(cardSource.data), Object.keys(fields));
  + private assertData(fields: CompiledCard['fields']) {
  + if (this.cardSource.data) {
  + let unexpectedFields = difference(Object.keys(this.cardSource.data), Object.keys(fields));
  if (unexpectedFields.length) {
  throw new BadRequest(`Field(s) "${unexpectedFields.join(',')}" does not exist on this card`);
  }
  }
  + }
  + private async transformFiles(
  + originalModules: OriginalModules,
  + fields: CompiledCard['fields'],
  + parentCard: CompiledCard | undefined
  + ) {
  + let outputModules: CompiledCard<Unsaved, LocalRef>['modules'] = {};
  for (let [localPath, mod] of Object.entries(originalModules)) {
  + outputModules[localPath] = await this.transformFile(localPath, mod, fields, parentCard, originalModules);
  + }
  + return outputModules;
  + }
  +
  + private async transformFile(
  + localPath: string,
  + mod: JSSourceModule | AssetModule,
  + fields: CompiledCard['fields'],
  + parentCard: CompiledCard | undefined,
  + originalModules: OriginalModules
  + ) {
  + let { cardSource } = this;
  if (mod.type === 'asset') {
  - this.outputModules[localPath] = {
  + return {
  type: mod.mimeType,
  source: mod.source,
  };
  - continue;
  }
  -
  switch (localPath) {
  case cardSource.schema:
  - this.outputModules[localPath] = await this.prepareSchema(mod, fields, parentCard);
  - break;
  + return await this.prepareSchema(mod, fields, parentCard);
  case cardSource.serializer:
  - this.outputModules[localPath] = await this.prepareSerializer(localPath, originalModules, parentCard);
  - break;
  -
  + return await this.prepareSerializer(localPath, originalModules, parentCard);
  + case cardSource.isolated:
  + case cardSource.embedded:
  + case cardSource.edit:
  default:
  - break;
  - }
  - }
  -
  - let compiledCard = {
  - realm: cardSource.realm,
  - url: (cardSource.id ? `${cardSource.realm}${cardSource.id}` : undefined) as Identity,
  - schemaModule: this.getSchemaModuleRef(parentCard, cardSource.schema),
  - serializerModule: this.getSerializerModuleRef(parentCard, cardSource.serializer),
  - fields,
  - adoptsFrom: parentCard,
  - componentInfos: await this.prepareComponents(originalModules, fields, parentCard),
  - modules: this.outputModules,
  - deps: [...this.dependencies],
  + return {
  + type: JS_TYPE,
  + source: mod.source,
  + ast: mod.ast,
  };
  -
  - return compiledCard;
  + }
  }
  private analyzeFiles() {
  