@impz/client 3.0.2 → 4.1.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";
@@ -553,6 +553,7 @@ declare const ProcedureAccessSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
553
553
  read: "read";
554
554
  }>;
555
555
  on: z.ZodLiteral<"image">;
556
+ held: z.ZodOptional<z.ZodLiteral<true>>;
556
557
  audit: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<false>, z.ZodLiteral<"refusals">]>>;
557
558
  }, z.core.$strip>, z.ZodObject<{
558
559
  scope: z.ZodEnum<{
@@ -9529,12 +9530,15 @@ declare const impContract: {
9529
9530
  }, import("zod/v4/core").$strip>;
9530
9531
  };
9531
9532
  }>, ProcedureMeta & Record<never, never>>;
9532
- buildStream: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<import("zod").ZodObject<{
9533
+ buildStream: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<import("zod").ZodUnion<readonly [import("zod").ZodObject<{
9533
9534
  contextDir: import("zod").ZodString;
9534
9535
  name: import("zod").ZodString;
9535
9536
  dockerfile: import("zod").ZodOptional<import("zod").ZodString>;
9536
9537
  logs: import("zod").ZodOptional<import("zod").ZodBoolean>;
9537
- }, import("zod/v4/core").$strip>, import("@orpc/contract").Schema<AsyncIteratorObject<{
9538
+ }, import("zod/v4/core").$strip>, import("zod").ZodObject<{
9539
+ upload: import("zod").ZodString;
9540
+ logs: import("zod").ZodOptional<import("zod").ZodBoolean>;
9541
+ }, import("zod/v4/core").$strip>]>, import("@orpc/contract").Schema<AsyncIteratorObject<{
9538
9542
  type: "progress";
9539
9543
  phase: "build" | "copy" | "pack" | "pull" | "unpack" | "upload";
9540
9544
  elapsedMs: number;
@@ -17026,7 +17030,6 @@ declare const impContract: {
17026
17030
  tokenUpdate: import("zod").ZodOptional<import("zod").ZodBoolean>;
17027
17031
  tokenImageAdd: import("zod").ZodOptional<import("zod").ZodBoolean>;
17028
17032
  databaseCopy: import("zod").ZodOptional<import("zod").ZodBoolean>;
17029
- imageBuildStream: import("zod").ZodOptional<import("zod").ZodBoolean>;
17030
17033
  imageOpStream: import("zod").ZodOptional<import("zod").ZodBoolean>;
17031
17034
  imageBuilds: import("zod").ZodOptional<import("zod").ZodBoolean>;
17032
17035
  execRequire: import("zod").ZodOptional<import("zod").ZodBoolean>;
@@ -17043,6 +17046,7 @@ declare const impContract: {
17043
17046
  execDropSysAdmin: import("zod").ZodOptional<import("zod").ZodBoolean>;
17044
17047
  guestScratch: import("zod").ZodOptional<import("zod").ZodBoolean>;
17045
17048
  imagePins: import("zod").ZodOptional<import("zod").ZodBoolean>;
17049
+ buildContextUpload: import("zod").ZodOptional<import("zod").ZodBoolean>;
17046
17050
  }, import("zod/v4/core").$strip>>;
17047
17051
  }, import("zod/v4/core").$strip>, import("@orpc/contract").MergedErrorMap<Record<never, never>, {
17048
17052
  NOT_FOUND: {
@@ -17228,7 +17232,6 @@ declare const impContract: {
17228
17232
  tokenUpdate: import("zod").ZodOptional<import("zod").ZodBoolean>;
17229
17233
  tokenImageAdd: import("zod").ZodOptional<import("zod").ZodBoolean>;
17230
17234
  databaseCopy: import("zod").ZodOptional<import("zod").ZodBoolean>;
17231
- imageBuildStream: import("zod").ZodOptional<import("zod").ZodBoolean>;
17232
17235
  imageOpStream: import("zod").ZodOptional<import("zod").ZodBoolean>;
17233
17236
  imageBuilds: import("zod").ZodOptional<import("zod").ZodBoolean>;
17234
17237
  execRequire: import("zod").ZodOptional<import("zod").ZodBoolean>;
@@ -17245,6 +17248,7 @@ declare const impContract: {
17245
17248
  execDropSysAdmin: import("zod").ZodOptional<import("zod").ZodBoolean>;
17246
17249
  guestScratch: import("zod").ZodOptional<import("zod").ZodBoolean>;
17247
17250
  imagePins: import("zod").ZodOptional<import("zod").ZodBoolean>;
17251
+ buildContextUpload: import("zod").ZodOptional<import("zod").ZodBoolean>;
17248
17252
  }, import("zod/v4/core").$strip>;
17249
17253
  }, import("zod/v4/core").$strip>, import("@orpc/contract").MergedErrorMap<Record<never, never>, {
17250
17254
  NOT_FOUND: {
@@ -21529,7 +21533,6 @@ declare const SystemInfoSchema: z.ZodObject<{
21529
21533
  tokenUpdate: z.ZodOptional<z.ZodBoolean>;
21530
21534
  tokenImageAdd: z.ZodOptional<z.ZodBoolean>;
21531
21535
  databaseCopy: z.ZodOptional<z.ZodBoolean>;
21532
- imageBuildStream: z.ZodOptional<z.ZodBoolean>;
21533
21536
  imageOpStream: z.ZodOptional<z.ZodBoolean>;
21534
21537
  imageBuilds: z.ZodOptional<z.ZodBoolean>;
21535
21538
  execRequire: z.ZodOptional<z.ZodBoolean>;
@@ -21546,6 +21549,7 @@ declare const SystemInfoSchema: z.ZodObject<{
21546
21549
  execDropSysAdmin: z.ZodOptional<z.ZodBoolean>;
21547
21550
  guestScratch: z.ZodOptional<z.ZodBoolean>;
21548
21551
  imagePins: z.ZodOptional<z.ZodBoolean>;
21552
+ buildContextUpload: z.ZodOptional<z.ZodBoolean>;
21549
21553
  }, z.core.$strip>>;
21550
21554
  }, z.core.$strip>;
21551
21555
  type SystemInfo = z.infer<typeof SystemInfoSchema>;
@@ -21559,7 +21563,6 @@ declare const SystemFeaturesInfoSchema: z.ZodObject<{
21559
21563
  tokenUpdate: z.ZodOptional<z.ZodBoolean>;
21560
21564
  tokenImageAdd: z.ZodOptional<z.ZodBoolean>;
21561
21565
  databaseCopy: z.ZodOptional<z.ZodBoolean>;
21562
- imageBuildStream: z.ZodOptional<z.ZodBoolean>;
21563
21566
  imageOpStream: z.ZodOptional<z.ZodBoolean>;
21564
21567
  imageBuilds: z.ZodOptional<z.ZodBoolean>;
21565
21568
  execRequire: z.ZodOptional<z.ZodBoolean>;
@@ -21576,6 +21579,7 @@ declare const SystemFeaturesInfoSchema: z.ZodObject<{
21576
21579
  execDropSysAdmin: z.ZodOptional<z.ZodBoolean>;
21577
21580
  guestScratch: z.ZodOptional<z.ZodBoolean>;
21578
21581
  imagePins: z.ZodOptional<z.ZodBoolean>;
21582
+ buildContextUpload: z.ZodOptional<z.ZodBoolean>;
21579
21583
  }, z.core.$strip>;
21580
21584
  }, z.core.$strip>;
21581
21585
  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.1.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.1.0",
4
4
  "description": "Typed client for impd, the imp host daemon: imps, checkpoints, images and exec",
5
5
  "license": "MIT",
6
6
  "repository": {