export async function buildMonitorSchema()

in src/push/monitor.ts [128:178]


export async function buildMonitorSchema(monitors: Monitor[], isV2: boolean) {
  /**
   * Set up the bundle artifacts path which can be used to
   * create the bundles required for uploading journeys
   */
  const bundlePath = join(SYNTHETICS_PATH, 'bundles');
  await mkdir(bundlePath, { recursive: true });
  const bundler = new Bundler();
  const schemas: MonitorSchema[] = [];
  const sizes: Map<string, number> = new Map();

  for (const monitor of monitors) {
    const { source, config, filter, type } = monitor;
    const schema: MonitorSchema = {
      ...config,
      locations: translateLocation(config.locations),
    };

    if (type === 'browser') {
      const outPath = join(
        bundlePath,
        normalizeMonitorName(config.name) + '.zip'
      );
      const content = await bundler.build(source.file, outPath);
      monitor.setContent(content);
      Object.assign(schema, { content, filter });
    }
    const size = monitor.size();
    const sizeKB = Math.round(size / 1000);
    if (sizeKB > SIZE_LIMIT_KB) {
      let outer = bold(
        `Aborted: Bundled code ${sizeKB}kB exceeds the recommended ${SIZE_LIMIT_KB}kB limit. Please check the dependencies imported.\n`
      );
      const inner = `* ${config.id} - ${source.file}:${source.line}:${source.column}\n`;
      outer += indent(inner);
      throw red(outer);
    }
    sizes.set(config.id, size);
    /**
     * Generate hash only after the bundled content is created
     * to capture code changes in imported files
     */
    if (isV2) {
      schema.hash = monitor.hash();
    }
    schemas.push(schema);
  }

  await rm(bundlePath, { recursive: true });
  return { schemas, sizes };
}