Skip to content
Back to skills

Linkly

ASecurity

Chapter 5 pushed a live trickle of events to observers. This chapter **moves a large amount of data at once**: a CSV of links, sent to one function as a **stream**. A stream is a value in a call's payload. The call carries a small reference, and the SDK sends the bytes over a separate pipe while the function reads them, so the file never has to fit in one JSON message. You'll give this its own `bulk-importer` worker so the `link` worker stays focused on single links.

  • 18,978 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 3, 2026
developmentjavascripttypescriptjavabashnodenodejsdatabasefrontend

Works with

  • cli

Security analysis

A96/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro scans all 17 files and shows the line behind each finding

Scanned December 1, 2026

npx -y skills add iii-hq/iii --skill linkly --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Linkly?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Linkly
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/iii-hq-linkly-05551cdd/badge)](https://www.skillsdirectory.com/skills/iii-hq-linkly-05551cdd)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
<!-- generated by iii-skill-render. DO NOT EDIT (changes here are overwritten on the next render). Edit docs/next/tutorials/linkly/channels.mdx. -->

# Ch. 6: Move bulk data with a stream


Chapter 5 pushed a live trickle of events to observers. This chapter **moves a large amount of data
at once**: a CSV of links, sent to one function as a **stream**. A stream is a value in a call's
payload. The call carries a small reference, and the SDK sends the bytes over a separate pipe while
the function reads them, so the file never has to fit in one JSON message. You'll give this its own
`bulk-importer` worker so the `link` worker stays focused on single links.

## Add the worker

Uncomment the Ch. 6 block in `worker-compose.yaml`:

```yaml worker-compose.yaml
bulk-importer:
  worker: path://./bulk-importer
  start_after: [link, sandbox-libkrun]
  scripts:
    build: iii call sandbox::build worker=bulk-importer
    run: iii call sandbox::start worker=bulk-importer
```

## Import a CSV from a stream

The `bulk-importer` worker exposes one function that receives the CSV as an `InputStream`, reads it
line by line, and calls `link::create` from the `link` worker for each row. Create
`bulk-importer/src/index.ts`:

```typescript bulk-importer/src/index.ts
import { registerWorker, type InputStream } from "iii-sdk";
import { Logger } from "@iii-dev/helpers/observability";

const worker = registerWorker(process.env.III_URL ?? "ws://localhost:49134", {
  workerName: "bulk-importer",
});
const logger = new Logger();

worker.registerFunction("bulk-importer::import_csv", async (input: { csv: InputStream }) => {
  let imported = 0;
  let skipped = 0;
  let header = true;
  // Read the stream one line at a time, as the uploader sends it.
  for await (const row of input.csv.lines()) {
    if (header) {
      header = false; // skip the header row
      continue;
    }
    // Split on the first comma only, so commas inside the URL survive.
    const comma = row.indexOf(",");
    if (comma === -1) continue;
    const code = row.slice(0, comma).trim();
    const url = row.slice(comma + 1).trim();
    if (!url) continue;
    try {
      await worker.call({
        function_id: "link::create",
        payload: { code, url },
      });
      imported += 1;
    } catch (err) {
      // link::create refuses a taken code with its own error, "code `<code>`
      // is already taken". Skip that row. Re-throw anything else (a timeout, a
      // worker that is down) so a broken import fails loudly instead of
      // counting rows it never created as "skipped".
      if (!(err instanceof Error && err.message.endsWith("is already taken"))) throw err;
      skipped += 1;
      logger.warn("bulk import row skipped", { code, error: String(err) });
    }
  }
  logger.info("bulk import complete", { imported, skipped });
  return { imported, skipped };
});

logger.info("bulk-importer ready");
```

Restart Compose so it picks up the change:

```bash
iii call compose::restart
```

## See it work

With the engine running, let's bulk-load some links.

<Note>
  Unlike previous chapters this section and Chapter 7 require that you have [node and npm
  installed](https://nodejs.org/en/download/current) locally. This is because we're now creating
  client side code that runs outside of workers.
</Note>

### Upload a CSV

The uploader is a small standalone script that calls `bulk-importer::import_csv` with the CSV in its
payload. `InputStream.from(csv)` marks the CSV as a stream: the SDK creates a pipe for it, puts a
reference in the payload, and sends the bytes while the importer reads them. The call resolves with
the importer's answer. The script is not a worker, so `channel-client/` holds it, outside
`worker-compose.yaml`:

```bash
cd channel-client && npm install
```

Write this into `channel-client/import-links.js`:

```javascript import-links.js
import { InputStream, registerWorker } from "iii-sdk";

const worker = registerWorker(process.env.III_URL ?? "ws://127.0.0.1:49134", {
  workerName: "uploader",
  // The project's namespace, where bulk-importer::import_csv lives.
  namespace: process.env.III_NAMESPACE || "default",
});

const csv = ["code,url", "mylink,https://iii.dev", "mydocslink,https://iii.dev/docs"].join("\n");

const result = await worker.call({
  function_id: "bulk-importer::import_csv",
  payload: { csv: InputStream.from(csv) },
});
console.log(result);

await worker.shutdown();
```

```bash
node import-links.js
```

```text
{ imported: 2, skipped: 0 }
```

The SDK prints a few `[iii]` / `[OTel]` connection lines around that object; the
`{ imported, skipped }` line is the importer's answer.

Run it again and it reports `{ imported: 0, skipped: 2 }`: the codes are already taken, so
`link::create` throws its `is already taken` error for each row and the importer skips those rows
instead of aborting the batch. The check reads `link::create`'s own message, which the chapter
controls, not the database's wording.

To upload a file from disk instead, pass `createReadStream("links.csv")` from `node:fs` as `csv`: a
Node `Readable` in a payload is a stream too. See [Streaming](../../creating-workers/streaming) for
the other ways to send, return, and forward streams.

Both new links resolve immediately:

```bash
iii call link::resolve code=mylink
iii call link::resolve code=mydocslink
```

```json
{
  "url": "https://iii.dev"
}
{
  "url": "https://iii.dev/docs"
}
```

## Conclusion

Linkly can now ingest a file's worth of links in a single streamed upload through a dedicated
`bulk-importer` worker. Next, in [Ch. 7: Bring in the browser](./frontend), you turn a browser tab
into a worker that creates links and subscribes to the live click stream.

Files in this skill

  • channels.mdx4.6 KB
  • channels.mdx.skill.md4.6 KB
  • durable-execution.mdx11.7 KB
  • durable-execution.mdx.skill.md11.7 KB
  • foundations.mdx13.5 KB
  • foundations.mdx.skill.md13.5 KB
  • frontend.mdx11.6 KB
  • frontend.mdx.skill.md11.5 KB
  • observability.mdx6.4 KB
  • observability.mdx.skill.md6.4 KB
  • overview.mdx2.1 KB
  • overview.mdx.skill.md2.1 KB
  • persistence.mdx8.4 KB
  • persistence.mdx.skill.md8.4 KB
  • streaming.mdx4.7 KB
  • streaming.mdx.skill.md4.7 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.