@impz/client 3.0.2 → 4.0.0

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.
package/dist/index.d.ts CHANGED
@@ -30,7 +30,7 @@ declare const CheckpointSchema: z.ZodObject<{
30
30
  }, z.core.$strip>;
31
31
  type Checkpoint = z.infer<typeof CheckpointSchema>;
32
32
  //#endregion
33
- //#region ../api/src/protocols/image-build-protocol.d.ts
33
+ //#region ../api/src/schemas/image-op-event-schema.d.ts
34
34
  declare const ImageBuildPhaseSchema: z.ZodEnum<{
35
35
  build: "build";
36
36
  copy: "copy";
@@ -9529,12 +9529,15 @@ declare const impContract: {
9529
9529
  }, import("zod/v4/core").$strip>;
9530
9530
  };
9531
9531
  }>, ProcedureMeta & Record<never, never>>;
9532
- buildStream: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<import("zod").ZodObject<{
9532
+ buildStream: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<import("zod").ZodUnion<readonly [import("zod").ZodObject<{
9533
9533
  contextDir: import("zod").ZodString;
9534
9534
  name: import("zod").ZodString;
9535
9535
  dockerfile: import("zod").ZodOptional<import("zod").ZodString>;
9536
9536
  logs: import("zod").ZodOptional<import("zod").ZodBoolean>;
9537
- }, import("zod/v4/core").$strip>, import("@orpc/contract").Schema<AsyncIteratorObject<{
9537
+ }, import("zod/v4/core").$strip>, import("zod").ZodObject<{
9538
+ upload: import("zod").ZodString;
9539
+ logs: import("zod").ZodOptional<import("zod").ZodBoolean>;
9540
+ }, import("zod/v4/core").$strip>]>, import("@orpc/contract").Schema<AsyncIteratorObject<{
9538
9541
  type: "progress";
9539
9542
  phase: "build" | "copy" | "pack" | "pull" | "unpack" | "upload";
9540
9543
  elapsedMs: number;
@@ -17026,7 +17029,6 @@ declare const impContract: {
17026
17029
  tokenUpdate: import("zod").ZodOptional<import("zod").ZodBoolean>;
17027
17030
  tokenImageAdd: import("zod").ZodOptional<import("zod").ZodBoolean>;
17028
17031
  databaseCopy: import("zod").ZodOptional<import("zod").ZodBoolean>;
17029
- imageBuildStream: import("zod").ZodOptional<import("zod").ZodBoolean>;
17030
17032
  imageOpStream: import("zod").ZodOptional<import("zod").ZodBoolean>;
17031
17033
  imageBuilds: import("zod").ZodOptional<import("zod").ZodBoolean>;
17032
17034
  execRequire: import("zod").ZodOptional<import("zod").ZodBoolean>;
@@ -17043,6 +17045,7 @@ declare const impContract: {
17043
17045
  execDropSysAdmin: import("zod").ZodOptional<import("zod").ZodBoolean>;
17044
17046
  guestScratch: import("zod").ZodOptional<import("zod").ZodBoolean>;
17045
17047
  imagePins: import("zod").ZodOptional<import("zod").ZodBoolean>;
17048
+ buildContextUpload: import("zod").ZodOptional<import("zod").ZodBoolean>;
17046
17049
  }, import("zod/v4/core").$strip>>;
17047
17050
  }, import("zod/v4/core").$strip>, import("@orpc/contract").MergedErrorMap<Record<never, never>, {
17048
17051
  NOT_FOUND: {
@@ -17228,7 +17231,6 @@ declare const impContract: {
17228
17231
  tokenUpdate: import("zod").ZodOptional<import("zod").ZodBoolean>;
17229
17232
  tokenImageAdd: import("zod").ZodOptional<import("zod").ZodBoolean>;
17230
17233
  databaseCopy: import("zod").ZodOptional<import("zod").ZodBoolean>;
17231
- imageBuildStream: import("zod").ZodOptional<import("zod").ZodBoolean>;
17232
17234
  imageOpStream: import("zod").ZodOptional<import("zod").ZodBoolean>;
17233
17235
  imageBuilds: import("zod").ZodOptional<import("zod").ZodBoolean>;
17234
17236
  execRequire: import("zod").ZodOptional<import("zod").ZodBoolean>;
@@ -17245,6 +17247,7 @@ declare const impContract: {
17245
17247
  execDropSysAdmin: import("zod").ZodOptional<import("zod").ZodBoolean>;
17246
17248
  guestScratch: import("zod").ZodOptional<import("zod").ZodBoolean>;
17247
17249
  imagePins: import("zod").ZodOptional<import("zod").ZodBoolean>;
17250
+ buildContextUpload: import("zod").ZodOptional<import("zod").ZodBoolean>;
17248
17251
  }, import("zod/v4/core").$strip>;
17249
17252
  }, import("zod/v4/core").$strip>, import("@orpc/contract").MergedErrorMap<Record<never, never>, {
17250
17253
  NOT_FOUND: {
@@ -21529,7 +21532,6 @@ declare const SystemInfoSchema: z.ZodObject<{
21529
21532
  tokenUpdate: z.ZodOptional<z.ZodBoolean>;
21530
21533
  tokenImageAdd: z.ZodOptional<z.ZodBoolean>;
21531
21534
  databaseCopy: z.ZodOptional<z.ZodBoolean>;
21532
- imageBuildStream: z.ZodOptional<z.ZodBoolean>;
21533
21535
  imageOpStream: z.ZodOptional<z.ZodBoolean>;
21534
21536
  imageBuilds: z.ZodOptional<z.ZodBoolean>;
21535
21537
  execRequire: z.ZodOptional<z.ZodBoolean>;
@@ -21546,6 +21548,7 @@ declare const SystemInfoSchema: z.ZodObject<{
21546
21548
  execDropSysAdmin: z.ZodOptional<z.ZodBoolean>;
21547
21549
  guestScratch: z.ZodOptional<z.ZodBoolean>;
21548
21550
  imagePins: z.ZodOptional<z.ZodBoolean>;
21551
+ buildContextUpload: z.ZodOptional<z.ZodBoolean>;
21549
21552
  }, z.core.$strip>>;
21550
21553
  }, z.core.$strip>;
21551
21554
  type SystemInfo = z.infer<typeof SystemInfoSchema>;
@@ -21559,7 +21562,6 @@ declare const SystemFeaturesInfoSchema: z.ZodObject<{
21559
21562
  tokenUpdate: z.ZodOptional<z.ZodBoolean>;
21560
21563
  tokenImageAdd: z.ZodOptional<z.ZodBoolean>;
21561
21564
  databaseCopy: z.ZodOptional<z.ZodBoolean>;
21562
- imageBuildStream: z.ZodOptional<z.ZodBoolean>;
21563
21565
  imageOpStream: z.ZodOptional<z.ZodBoolean>;
21564
21566
  imageBuilds: z.ZodOptional<z.ZodBoolean>;
21565
21567
  execRequire: z.ZodOptional<z.ZodBoolean>;
@@ -21576,6 +21578,7 @@ declare const SystemFeaturesInfoSchema: z.ZodObject<{
21576
21578
  execDropSysAdmin: z.ZodOptional<z.ZodBoolean>;
21577
21579
  guestScratch: z.ZodOptional<z.ZodBoolean>;
21578
21580
  imagePins: z.ZodOptional<z.ZodBoolean>;
21581
+ buildContextUpload: z.ZodOptional<z.ZodBoolean>;
21579
21582
  }, z.core.$strip>;
21580
21583
  }, z.core.$strip>;
21581
21584
  type SystemFeaturesInfo = z.infer<typeof SystemFeaturesInfoSchema>;
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 = "3.0.2";
8
+ const CLIENT_VERSION = "4.0.0";
9
9
  async function checkServer(rpc, options = {}) {
10
10
  const signal = options.signal;
11
11
  const callOptions = signal === void 0 ? {} : { signal };
@@ -50,68 +50,21 @@ const LeaseSummarySchema = z.object({
50
50
  otherCount: z.int().nonnegative()
51
51
  });
52
52
  //#endregion
53
- //#region ../api/src/schemas/image-schema.ts
54
- const ImageSourceSchema = z.enum(["oci", "imp"]);
55
- const ImageSchema = z.object({
56
- id: z.string(),
57
- name: NameSchema,
58
- ref: z.string(),
59
- digest: z.string(),
60
- source: ImageSourceSchema,
61
- createdAt: z.date(),
62
- sizeBytes: z.int().nonnegative(),
63
- pinned: z.boolean().default(false)
64
- });
65
- //#endregion
66
- //#region ../api/src/protocols/image-build-protocol.ts
67
- const IMAGE_BUILD_PATH = "/images/build";
68
- const IMAGE_BUILD_STREAM_TYPE = "application/x-ndjson";
53
+ //#region ../api/src/protocols/build-context-protocol.ts
54
+ const BUILD_CONTEXT_PATH = "/images/build-context";
69
55
  const DockerfilePathSchema = z.string().min(1).refine((path) => !path.startsWith("/") && !path.split(/[/\\]/u).includes(".."), { message: "the Dockerfile path must be relative and stay inside the build context" });
70
56
  z.object({
71
57
  name: NameSchema,
72
58
  dockerfile: DockerfilePathSchema.optional()
73
59
  });
74
- const ImageBuildResultSchema = ImageSchema.extend({ createdAt: z.coerce.date() });
75
- const ImageBuildErrorSchema = z.object({
60
+ const BuildContextUploadSchema = z.object({
61
+ id: z.string().min(1),
62
+ expiresAt: z.coerce.date()
63
+ });
64
+ const BuildContextErrorSchema = z.object({
76
65
  code: z.string(),
77
66
  message: z.string()
78
67
  });
79
- const ImageBuildPhaseSchema = z.enum([
80
- "upload",
81
- "pack",
82
- "build",
83
- "pull",
84
- "unpack",
85
- "copy"
86
- ]);
87
- const IMAGE_BUILD_LOG_MAX_CHARS = 8192;
88
- const ImageBuildProgressSchema = z.object({
89
- type: z.literal("progress"),
90
- phase: ImageBuildPhaseSchema,
91
- elapsedMs: z.number().nonnegative(),
92
- step: z.string().optional()
93
- });
94
- const ImageBuildLogSchema = z.object({
95
- type: z.literal("log"),
96
- text: z.string().max(IMAGE_BUILD_LOG_MAX_CHARS)
97
- });
98
- const ImageBuildEventSchema = z.discriminatedUnion("type", [
99
- ImageBuildProgressSchema,
100
- ImageBuildLogSchema,
101
- z.object({
102
- type: z.literal("image"),
103
- image: ImageBuildResultSchema
104
- }),
105
- ImageBuildErrorSchema.extend({ type: z.literal("error") })
106
- ]);
107
- z.discriminatedUnion("type", [
108
- ImageBuildProgressSchema,
109
- ImageBuildLogSchema,
110
- z.object({
111
- type: z.literal("image"),
112
- image: ImageSchema
113
- })
114
- ]);
115
68
  //#endregion
116
69
  //#region ../api/src/schemas/offset-schema.ts
117
70
  const OffsetSchema = z.int().nonnegative();
@@ -895,7 +848,6 @@ const FEATURE_GAPS = {
895
848
  tokenUpdate: "is older than 0.34.0",
896
849
  tokenImageAdd: "has no token image adds",
897
850
  databaseCopy: "is older than 0.30.0",
898
- imageBuildStream: "has no build stream",
899
851
  imageOpStream: "has no image add or build streams",
900
852
  imageBuilds: "has no list of running image builds",
901
853
  execRequire: "is older than 0.30.0",
@@ -911,7 +863,8 @@ const FEATURE_GAPS = {
911
863
  readOnlyFiles: "has no read-only files",
912
864
  execDropSysAdmin: "cannot drop CAP_SYS_ADMIN from a command",
913
865
  guestScratch: "does not name the guest scratch folder",
914
- imagePins: "has no image pins"
866
+ imagePins: "has no image pins",
867
+ buildContextUpload: "has no build context upload"
915
868
  };
916
869
  var MissingFeatureError = class extends Error {
917
870
  name = "MissingFeatureError";
@@ -1568,101 +1521,27 @@ function isUnavailable(error) {
1568
1521
  return error instanceof TypeError;
1569
1522
  }
1570
1523
  //#endregion
1571
- //#region ../shared/src/split-lines.ts
1572
- function splitLines() {
1573
- const state = { pending: "" };
1574
- return new TransformStream({
1575
- transform: (chunk, controller) => {
1576
- const lines = `${state.pending}${chunk}`.split("\n");
1577
- state.pending = lines.pop() ?? "";
1578
- for (const line of lines) controller.enqueue(line);
1579
- },
1580
- flush: (controller) => {
1581
- if (state.pending !== "") controller.enqueue(state.pending);
1582
- }
1583
- });
1584
- }
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
1617
- //#region src/read-build-answer.ts
1618
- async function readBuildAnswer(response, onProgress, onLog) {
1619
- if (response.ok && isStream(response)) return readBuildEvents(response, onProgress, onLog);
1620
- const body = await response.json().catch(() => null);
1621
- if (response.ok) return ImageBuildResultSchema.parse(body);
1622
- const failure = ImageBuildErrorSchema.safeParse(body);
1623
- if (failure.success) throw new ORPCError$1(failure.data.code, {
1624
- status: response.status,
1625
- message: failure.data.message
1626
- });
1627
- const code = response.status === 401 ? "UNAUTHORIZED" : "INTERNAL_SERVER_ERROR";
1628
- throw new ORPCError$1(code, {
1629
- status: response.status,
1630
- message: `impd answered ${String(response.status)} to the image build`
1631
- });
1632
- }
1633
- function isStream(response) {
1634
- return response.headers.get("content-type")?.startsWith(IMAGE_BUILD_STREAM_TYPE) === true;
1635
- }
1636
- async function readBuildEvents(response, onProgress, onLog) {
1637
- const lines = response.body === null ? [] : readLines(response.body);
1638
- for await (const line of lines) {
1639
- const parsed = ImageBuildEventSchema.safeParse(parseJson(line));
1640
- if (!parsed.success) continue;
1641
- const event = parsed.data;
1524
+ //#region src/run-image-build.ts
1525
+ async function runImageBuild(deps, name, context, options = {}) {
1526
+ const call = { ...options.signal !== void 0 && { signal: options.signal } };
1527
+ await requireFeatures(deps.rpc, { buildContextUpload: "answer the upload with not found" }, call);
1528
+ const upload = await writeBuildContext(deps, name, context, options);
1529
+ const events = await deps.rpc.images.buildStream({
1530
+ upload: upload.id,
1531
+ logs: options.onLog !== void 0
1532
+ }, call);
1533
+ for await (const event of events) {
1642
1534
  if (event.type === "image") return event.image;
1643
- if (event.type === "error") throw new ORPCError$1(event.code, { message: event.message });
1644
- if (event.type === "log") onLog?.(event.text);
1645
- else onProgress?.(event);
1535
+ if (event.type === "log") options.onLog?.(event.text);
1536
+ else options.onProgress?.(event);
1646
1537
  }
1647
1538
  throw new ORPCError$1("INTERNAL_SERVER_ERROR", { message: "the image build stream ended before impd answered the image" });
1648
1539
  }
1649
- function parseJson(line) {
1650
- try {
1651
- return JSON.parse(line);
1652
- } catch {
1653
- return null;
1654
- }
1655
- }
1656
- //#endregion
1657
- //#region src/run-image-build.ts
1658
- async function runImageBuild(deps, name, context, options = {}) {
1659
- const url = resolveImpdUrl(deps.baseUrl, IMAGE_BUILD_PATH);
1540
+ async function writeBuildContext(deps, name, context, options) {
1541
+ const url = resolveImpdUrl(deps.baseUrl, BUILD_CONTEXT_PATH);
1660
1542
  url.searchParams.set("name", name);
1661
1543
  if (options.dockerfile !== void 0) url.searchParams.set("dockerfile", options.dockerfile);
1662
- const headers = {
1663
- "content-type": "application/x-tar",
1664
- accept: `${IMAGE_BUILD_STREAM_TYPE}, application/json`
1665
- };
1544
+ const headers = { "content-type": "application/x-tar" };
1666
1545
  if (deps.token !== null) headers["authorization"] = `Bearer ${deps.token}`;
1667
1546
  if (options.size !== void 0) headers["content-length"] = String(options.size);
1668
1547
  const init = {
@@ -1672,8 +1551,19 @@ async function runImageBuild(deps, name, context, options = {}) {
1672
1551
  duplex: "half",
1673
1552
  ...options.signal !== void 0 && { signal: options.signal }
1674
1553
  };
1675
- const request = new Request(url.href, init);
1676
- return readBuildAnswer(await (deps.fetch ?? fetch)(request), options.onProgress, options.onLog);
1554
+ const response = await (deps.fetch ?? fetch)(new Request(url.href, init));
1555
+ const body = await response.json().catch(() => null);
1556
+ if (response.ok) return BuildContextUploadSchema.parse(body);
1557
+ const failure = BuildContextErrorSchema.safeParse(body);
1558
+ if (failure.success) throw new ORPCError$1(failure.data.code, {
1559
+ status: response.status,
1560
+ message: failure.data.message
1561
+ });
1562
+ const code = response.status === 401 ? "UNAUTHORIZED" : "INTERNAL_SERVER_ERROR";
1563
+ throw new ORPCError$1(code, {
1564
+ status: response.status,
1565
+ message: `impd answered ${String(response.status)} to the build context upload`
1566
+ });
1677
1567
  }
1678
1568
  //#endregion
1679
1569
  //#region src/send-long-call.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@impz/client",
3
- "version": "3.0.2",
3
+ "version": "4.0.0",
4
4
  "description": "Typed client for impd, the imp host daemon: imps, checkpoints, images and exec",
5
5
  "license": "MIT",
6
6
  "repository": {