@vzn/vx-reapi 0.0.596 → 0.0.597

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vzn/vx-reapi",
3
- "version": "0.0.596",
3
+ "version": "0.0.597",
4
4
  "license": "MIT",
5
5
  "description": "Bazel Remote Execution API plugin for vx — remote cache (ActionCache + CAS) against NativeLink, BuildBuddy, Buildbarn or bazel-remote.",
6
6
  "keywords": [
@@ -39,7 +39,7 @@
39
39
  "access": "public"
40
40
  },
41
41
  "peerDependencies": {
42
- "@vzn/vx": "^0.0.596"
42
+ "@vzn/vx": "^0.0.597"
43
43
  },
44
44
  "repository": {
45
45
  "type": "git",
package/src/merkle.ts CHANGED
@@ -389,7 +389,7 @@ function tag(field: number, wire: number): Uint8Array {
389
389
  return varint((field << 3) | wire)
390
390
  }
391
391
 
392
- function lenField(field: number, payload: Uint8Array): Uint8Array {
392
+ export function lenField(field: number, payload: Uint8Array): Uint8Array {
393
393
  return concat([tag(field, 2), varint(payload.length), payload])
394
394
  }
395
395
 
@@ -398,7 +398,7 @@ function lenField(field: number, payload: Uint8Array): Uint8Array {
398
398
  // zero would change the serialised bytes and therefore the DIGEST — most
399
399
  // visibly for the empty blob, whose `size_bytes` is 0, so any tree containing
400
400
  // an empty file would address differently from the server's view of it.
401
- function strField(field: number, value: string): Uint8Array {
401
+ export function strField(field: number, value: string): Uint8Array {
402
402
  return value === '' ? EMPTY : lenField(field, new TextEncoder().encode(value))
403
403
  }
404
404
 
package/src/wire.ts CHANGED
@@ -6,19 +6,15 @@
6
6
  import * as grpc from '@grpc/grpc-js'
7
7
  import * as protoLoader from '@grpc/proto-loader'
8
8
  import path from 'node:path'
9
- import { canDigest, concat, digestWith, hasherFor, type DigestFunctionName } from './merkle.js'
10
-
11
- /** Bare varint bytes, for the hand-encoded RequestMetadata header. */
12
- function varintBytes(n: number): Uint8Array {
13
- const out: number[] = []
14
- let v = n
15
- while (v >= 0x80) {
16
- out.push((v & 0x7f) | 0x80)
17
- v >>>= 7
18
- }
19
- out.push(v)
20
- return new Uint8Array(out)
21
- }
9
+ import {
10
+ canDigest,
11
+ concat,
12
+ digestWith,
13
+ hasherFor,
14
+ lenField,
15
+ strField,
16
+ type DigestFunctionName,
17
+ } from './merkle.js'
22
18
 
23
19
  /**
24
20
  * Default bytes per ByteStream message.
@@ -599,21 +595,12 @@ export class ReapiClient {
599
595
  * with `ToolDetails { tool_name = 1, tool_version = 2 }`.
600
596
  */
601
597
  private requestMetadata(): Uint8Array {
602
- const str = (field: number, v: string): Uint8Array => {
603
- if (v === '') return new Uint8Array()
604
- const bytes = new TextEncoder().encode(v)
605
- return concat([varintBytes((field << 3) | 2), varintBytes(bytes.length), bytes])
606
- }
607
- const tool = concat([str(1, this.toolName), str(2, this.toolVersion)])
608
- const toolField =
609
- tool.length === 0
610
- ? new Uint8Array()
611
- : concat([varintBytes((1 << 3) | 2), varintBytes(tool.length), tool])
598
+ const tool = concat([strField(1, this.toolName), strField(2, this.toolVersion)])
612
599
  return concat([
613
- toolField,
614
- str(2, this.actionId),
615
- str(3, this.toolInvocationId),
616
- str(4, this.correlatedInvocationsId),
600
+ tool.length === 0 ? tool : lenField(1, tool),
601
+ strField(2, this.actionId),
602
+ strField(3, this.toolInvocationId),
603
+ strField(4, this.correlatedInvocationsId),
617
604
  ])
618
605
  }
619
606