# loads

id: test
script:
  'use strict';

  var worker_threads = require('worker_threads');

  function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }const send = (data) => {
      const cleaned = JSON.parse(JSON.stringify(data));
      _optionalChain([worker_threads.parentPort, 'optionalAccess', _ => _.postMessage, 'call', _2 => _2(cleaned)]);
  };

  const sendLog = (event) => {
      send({
          type: 'log',
          payload: event,
      });
  };
  const info = (message, data) => {
      sendLog({
          severity: 'info',
          message,
          data,
      });
  };
  const warn = (message, data) => {
      sendLog({
          severity: 'warning',
          message,
          data,
      });
  };
  const error = (message, data) => {
      sendLog({
          severity: 'error',
          message,
          data,
      });
  };
  const logger = {
      info,
      warn,
      error,
  };

  const create = (name, data) => {
      send({
          type: 'artifact:create',
          payload: {
              name,
              data: data.toString('base64'),
          },
      });
  };
  const artifacts = {
      create,
  };

  logger.info('Hello world');

  artifacts.create('foo', 'bar');


