body method

  1. @override
String body(
  1. String path,
  2. String baseName,
  3. String className
)
override

Defines the actual body code. path is passed relative to lib, baseName is the filename, and className is the filename converted to Pascal case.

実際の本体コードを定義します。pathにlibからの相対パス、baseNameにファイル名が渡され、classNameにファイル名をパスカルケースに変換した値が渡されます。

Implementation

@override
String body(String path, String baseName, String className) {
  final comment = entry == "region"
      ? """
// Register functions for fixed-region backends such as TiDB.
// This Worker runs in the placement region set in `wrangler.region.jsonc`.
//
// TiDBなどの固定リージョンのバックエンド向け機能を登録してください。
// このWorkerは`wrangler.region.jsonc`で指定したplacementのリージョンで動作します。"""
      : """
// Define [m.Functions.xxxx] for the functions to be added to Workers.
//
// Workersに追加する機能を[m.Functions.xxxx]を定義してください。""";
  return """
$comment
${firebaseProjectId != null ? """
class EnvironmentFirebaseAuthAdapter extends m.WorkersAuthAdapterBase {
  build(): MiddlewareHandler {
      return async (context, next) => {
          const projectId = context.env?.FIREBASE_PROJECT_ID;
          if (typeof projectId !== "string" || !projectId) {
              return context.text("Firebase project is not configured.", 503);
          }
          return await new m.FirebaseAuthAdapter({ projectId }).build()(context, next);
      };
  }
}
""" : """"""}
export default m.deploy([
${firebaseProjectId != null ? """
], {
  type: "$entry",
  rules: rules as m.RulesConfig,
  auth: new EnvironmentFirebaseAuthAdapter(),
});
""" : """
], {
  type: "$entry",
  rules: rules as m.RulesConfig,
});
"""}
""";
}