@impz/client 2.11.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +34 -6
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import { P, match } from "ts-pattern";
5
5
  import pRetry, { AbortError } from "p-retry";
6
6
  //#endregion
7
7
  //#region src/check-server.ts
8
- const CLIENT_VERSION = "2.11.0";
8
+ const CLIENT_VERSION = "3.0.1";
9
9
  async function checkServer(rpc, options = {}) {
10
10
  const signal = options.signal;
11
11
  const callOptions = signal === void 0 ? {} : { signal };
@@ -1583,6 +1583,37 @@ function splitLines() {
1583
1583
  });
1584
1584
  }
1585
1585
  //#endregion
1586
+ //#region ../shared/src/read-lines.ts
1587
+ async function* readLines(stream) {
1588
+ const reader = stream.pipeThrough(decodeText()).pipeThrough(splitLines()).getReader();
1589
+ const read = { isDone: false };
1590
+ try {
1591
+ for (;;) {
1592
+ const next = await reader.read();
1593
+ if (next.done) {
1594
+ read.isDone = true;
1595
+ return;
1596
+ }
1597
+ yield next.value;
1598
+ }
1599
+ } finally {
1600
+ if (!read.isDone) await reader.cancel();
1601
+ reader.releaseLock();
1602
+ }
1603
+ }
1604
+ function decodeText() {
1605
+ const decoder = new TextDecoder();
1606
+ return new TransformStream({
1607
+ transform: (chunk, controller) => {
1608
+ controller.enqueue(decoder.decode(chunk, { stream: true }));
1609
+ },
1610
+ flush: (controller) => {
1611
+ const rest = decoder.decode();
1612
+ if (rest !== "") controller.enqueue(rest);
1613
+ }
1614
+ });
1615
+ }
1616
+ //#endregion
1586
1617
  //#region src/read-build-answer.ts
1587
1618
  async function readBuildAnswer(response, onProgress, onLog) {
1588
1619
  if (response.ok && isStream(response)) return readBuildEvents(response, onProgress, onLog);
@@ -1603,7 +1634,8 @@ function isStream(response) {
1603
1634
  return response.headers.get("content-type")?.startsWith(IMAGE_BUILD_STREAM_TYPE) === true;
1604
1635
  }
1605
1636
  async function readBuildEvents(response, onProgress, onLog) {
1606
- for await (const line of readLines(response)) {
1637
+ const lines = response.body === null ? [] : readLines(response.body);
1638
+ for await (const line of lines) {
1607
1639
  const parsed = ImageBuildEventSchema.safeParse(parseJson(line));
1608
1640
  if (!parsed.success) continue;
1609
1641
  const event = parsed.data;
@@ -1614,10 +1646,6 @@ async function readBuildEvents(response, onProgress, onLog) {
1614
1646
  }
1615
1647
  throw new ORPCError$1("INTERNAL_SERVER_ERROR", { message: "the image build stream ended before impd answered the image" });
1616
1648
  }
1617
- async function* readLines(response) {
1618
- if (response.body === null) return;
1619
- yield* response.body.pipeThrough(new TextDecoderStream()).pipeThrough(splitLines());
1620
- }
1621
1649
  function parseJson(line) {
1622
1650
  try {
1623
1651
  return JSON.parse(line);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@impz/client",
3
- "version": "2.11.0",
3
+ "version": "3.0.1",
4
4
  "description": "Typed client for impd, the imp host daemon: imps, checkpoints, images and exec",
5
5
  "license": "MIT",
6
6
  "repository": {