Compare commits

...
Author SHA1 Message Date
Josh Gross f166bbadbb Remove unused cache API 2024-12-17 11:03:13 -05:00
Bassem Dghaidi b7a00a3203 Merge pull request #1886 from actions/Link-/cache-4.0.0
Prepare `@actions/cache` `4.0.0` release
2024-12-04 20:09:19 +01:00
Bassem Dghaidi 0827eef58f Rerun CI 2024-12-04 10:53:00 -08:00
Bassem Dghaidi cd9197e9bd Add announcement link 2024-12-04 08:23:10 -08:00
Bassem Dghaidi 72447df44c Update deprecation notice 2024-12-04 05:33:47 -08:00
Bassem Dghaidi 59845ec372 Update deprecation notice 2024-12-04 05:30:50 -08:00
Bassem Dghaidi cb001af8a3 Update README to include deprecation notice 2024-12-03 02:52:39 -08:00
Bassem Dghaidi 4498687c5e Prepare @actions/cache 4.0.0 release 2024-12-03 02:40:00 -08:00
Bassem Dghaidi a10e209c8d Merge pull request #1882 from actions/enhance-blob-client
Enhance blob client resilience & performance
2024-12-02 20:48:46 +01:00
6 changed files with 41 additions and 364 deletions
+14 -2
View File
@@ -6,6 +6,20 @@ See ["Caching dependencies to speed up workflows"](https://docs.github.com/en/ac
Note that GitHub will remove any cache entries that have not been accessed in over 7 days. There is no limit on the number of caches you can store, but the total size of all caches in a repository is limited to 10 GB. If you exceed this limit, GitHub will save your cache but will begin evicting caches until the total size is less than 10 GB. Note that GitHub will remove any cache entries that have not been accessed in over 7 days. There is no limit on the number of caches you can store, but the total size of all caches in a repository is limited to 10 GB. If you exceed this limit, GitHub will save your cache but will begin evicting caches until the total size is less than 10 GB.
## ⚠️ Important changes
The cache backend service has been rewritten from the ground up for improved performance and reliability. The [@actions/cache](https://github.com/actions/toolkit/tree/main/packages/cache) package now integrates with the new cache service (v2) APIs.
The new service will gradually roll out as of **February 1st, 2025**. The legacy service will also be sunset on the same date. Changes in this release are **fully backward compatible**.
**All previous versions of this package will be deprecated**. We recommend upgrading to version `4.0.0` as soon as possible before **February 1st, 2025.**
If you do not upgrade, all workflow runs using any of the deprecated [@actions/cache](https://github.com/actions/toolkit/tree/main/packages/cache) packages will fail.
Upgrading to the recommended version should not break or require any changes to your workflows beyond updating your `package.json` to version `4.0.0`.
Read more about the change & access the migration guide: [reference to the announcement](https://github.com/actions/toolkit/discussions/1890).
## Usage ## Usage
This package is used by the v2+ versions of our first party cache action. You can find an example implementation in the cache repo [here](https://github.com/actions/cache). This package is used by the v2+ versions of our first party cache action. You can find an example implementation in the cache repo [here](https://github.com/actions/cache).
@@ -47,5 +61,3 @@ const cacheKey = await cache.restoreCache(paths, key, restoreKeys)
A cache gets downloaded in multiple segments of fixed sizes (now `128MB` to fail-fast, previously `1GB` for a `32-bit` runner and `2GB` for a `64-bit` runner were used). Sometimes, a segment download gets stuck which causes the workflow job to be stuck forever and fail. Version `v3.0.4` of cache package introduces a segment download timeout. The segment download timeout will allow the segment download to get aborted and hence allow the job to proceed with a cache miss. A cache gets downloaded in multiple segments of fixed sizes (now `128MB` to fail-fast, previously `1GB` for a `32-bit` runner and `2GB` for a `64-bit` runner were used). Sometimes, a segment download gets stuck which causes the workflow job to be stuck forever and fail. Version `v3.0.4` of cache package introduces a segment download timeout. The segment download timeout will allow the segment download to get aborted and hence allow the job to proceed with a cache miss.
Default value of this timeout is 10 minutes (starting `v3.2.1` and higher, previously 60 minutes in versions between `v.3.0.4` and `v3.2.0`, both included) and can be customized by specifying an [environment variable](https://docs.github.com/en/actions/learn-github-actions/environment-variables) named `SEGMENT_DOWNLOAD_TIMEOUT_MINS` with timeout value in minutes. Default value of this timeout is 10 minutes (starting `v3.2.1` and higher, previously 60 minutes in versions between `v.3.0.4` and `v3.2.0`, both included) and can be customized by specifying an [environment variable](https://docs.github.com/en/actions/learn-github-actions/environment-variables) named `SEGMENT_DOWNLOAD_TIMEOUT_MINS` with timeout value in minutes.
+23
View File
@@ -1,6 +1,29 @@
# @actions/cache Releases # @actions/cache Releases
### 4.0.0
#### Important changes
The cache backend service has been rewritten from the ground up for improved performance and reliability. The [@actions/cache](https://github.com/actions/toolkit/tree/main/packages/cache) package now integrates with the new cache service (v2) APIs.
The new service will gradually roll out as of **February 1st, 2025**. The legacy service will also be sunset on the same date. Changes in this release are **fully backward compatible**.
**All previous versions of this package will be deprecated**. We recommend upgrading to version `4.0.0` as soon as possible before **February 1st, 2025.**
If you do not upgrade, all workflow runs using any of the deprecated [@actions/cache](https://github.com/actions/toolkit/tree/main/packages/cache) packages will fail.
Upgrading to the recommended version should not break or require any changes to your workflows beyond updating your `package.json` to version `4.0.0`.
Read more about the change & access the migration guide: [reference to the announcement](https://github.com/actions/toolkit/discussions/1890).
#### Minor changes
- Update `@actions/core` to `1.11.0`
- Update `semver` `6.3.1`
- Add `twirp-ts` `2.5.0` to dependencies
### 3.3.0 ### 3.3.0
- Update `@actions/core` to `1.11.1` - Update `@actions/core` to `1.11.1`
- Remove dependency on `uuid` package [#1824](https://github.com/actions/toolkit/pull/1824), [#1842](https://github.com/actions/toolkit/pull/1842) - Remove dependency on `uuid` package [#1824](https://github.com/actions/toolkit/pull/1824), [#1842](https://github.com/actions/toolkit/pull/1842)
+2 -2
View File
@@ -1,12 +1,12 @@
{ {
"name": "@actions/cache", "name": "@actions/cache",
"version": "3.3.0", "version": "4.0.0",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@actions/cache", "name": "@actions/cache",
"version": "3.3.0", "version": "4.0.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/core": "^1.11.1", "@actions/core": "^1.11.1",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@actions/cache", "name": "@actions/cache",
"version": "3.3.0", "version": "4.0.0",
"preview": true, "preview": true,
"description": "Actions cache lib", "description": "Actions cache lib",
"keywords": [ "keywords": [
+1 -170
View File
@@ -212,52 +212,6 @@ export interface ListCacheEntriesResponse {
*/ */
entries: CacheEntry[]; entries: CacheEntry[];
} }
/**
* @generated from protobuf message github.actions.results.api.v1.LookupCacheEntryRequest
*/
export interface LookupCacheEntryRequest {
/**
* Scope and other metadata for the cache entry
*
* @generated from protobuf field: github.actions.results.entities.v1.CacheMetadata metadata = 1;
*/
metadata?: CacheMetadata;
/**
* An explicit key for a cache entry
*
* @generated from protobuf field: string key = 2;
*/
key: string;
/**
* Restore keys used for prefix searching
*
* @generated from protobuf field: repeated string restore_keys = 3;
*/
restoreKeys: string[];
/**
* Hash of the compression tool, runner OS and paths cached
*
* @generated from protobuf field: string version = 4;
*/
version: string;
}
/**
* @generated from protobuf message github.actions.results.api.v1.LookupCacheEntryResponse
*/
export interface LookupCacheEntryResponse {
/**
* Indicates whether the cache entry exists or not
*
* @generated from protobuf field: bool exists = 1;
*/
exists: boolean;
/**
* Matched cache entry metadata
*
* @generated from protobuf field: github.actions.results.entities.v1.CacheEntry entry = 2;
*/
entry?: CacheEntry;
}
// @generated message type with reflection information, may provide speed optimized methods // @generated message type with reflection information, may provide speed optimized methods
class CreateCacheEntryRequest$Type extends MessageType<CreateCacheEntryRequest> { class CreateCacheEntryRequest$Type extends MessageType<CreateCacheEntryRequest> {
constructor() { constructor() {
@@ -840,128 +794,6 @@ class ListCacheEntriesResponse$Type extends MessageType<ListCacheEntriesResponse
* @generated MessageType for protobuf message github.actions.results.api.v1.ListCacheEntriesResponse * @generated MessageType for protobuf message github.actions.results.api.v1.ListCacheEntriesResponse
*/ */
export const ListCacheEntriesResponse = new ListCacheEntriesResponse$Type(); export const ListCacheEntriesResponse = new ListCacheEntriesResponse$Type();
// @generated message type with reflection information, may provide speed optimized methods
class LookupCacheEntryRequest$Type extends MessageType<LookupCacheEntryRequest> {
constructor() {
super("github.actions.results.api.v1.LookupCacheEntryRequest", [
{ no: 1, name: "metadata", kind: "message", T: () => CacheMetadata },
{ no: 2, name: "key", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
{ no: 3, name: "restore_keys", kind: "scalar", repeat: 2 /*RepeatType.UNPACKED*/, T: 9 /*ScalarType.STRING*/ },
{ no: 4, name: "version", kind: "scalar", T: 9 /*ScalarType.STRING*/ }
]);
}
create(value?: PartialMessage<LookupCacheEntryRequest>): LookupCacheEntryRequest {
const message = { key: "", restoreKeys: [], version: "" };
globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
if (value !== undefined)
reflectionMergePartial<LookupCacheEntryRequest>(this, message, value);
return message;
}
internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: LookupCacheEntryRequest): LookupCacheEntryRequest {
let message = target ?? this.create(), end = reader.pos + length;
while (reader.pos < end) {
let [fieldNo, wireType] = reader.tag();
switch (fieldNo) {
case /* github.actions.results.entities.v1.CacheMetadata metadata */ 1:
message.metadata = CacheMetadata.internalBinaryRead(reader, reader.uint32(), options, message.metadata);
break;
case /* string key */ 2:
message.key = reader.string();
break;
case /* repeated string restore_keys */ 3:
message.restoreKeys.push(reader.string());
break;
case /* string version */ 4:
message.version = reader.string();
break;
default:
let u = options.readUnknownField;
if (u === "throw")
throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
let d = reader.skip(wireType);
if (u !== false)
(u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
}
}
return message;
}
internalBinaryWrite(message: LookupCacheEntryRequest, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter {
/* github.actions.results.entities.v1.CacheMetadata metadata = 1; */
if (message.metadata)
CacheMetadata.internalBinaryWrite(message.metadata, writer.tag(1, WireType.LengthDelimited).fork(), options).join();
/* string key = 2; */
if (message.key !== "")
writer.tag(2, WireType.LengthDelimited).string(message.key);
/* repeated string restore_keys = 3; */
for (let i = 0; i < message.restoreKeys.length; i++)
writer.tag(3, WireType.LengthDelimited).string(message.restoreKeys[i]);
/* string version = 4; */
if (message.version !== "")
writer.tag(4, WireType.LengthDelimited).string(message.version);
let u = options.writeUnknownFields;
if (u !== false)
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
return writer;
}
}
/**
* @generated MessageType for protobuf message github.actions.results.api.v1.LookupCacheEntryRequest
*/
export const LookupCacheEntryRequest = new LookupCacheEntryRequest$Type();
// @generated message type with reflection information, may provide speed optimized methods
class LookupCacheEntryResponse$Type extends MessageType<LookupCacheEntryResponse> {
constructor() {
super("github.actions.results.api.v1.LookupCacheEntryResponse", [
{ no: 1, name: "exists", kind: "scalar", T: 8 /*ScalarType.BOOL*/ },
{ no: 2, name: "entry", kind: "message", T: () => CacheEntry }
]);
}
create(value?: PartialMessage<LookupCacheEntryResponse>): LookupCacheEntryResponse {
const message = { exists: false };
globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
if (value !== undefined)
reflectionMergePartial<LookupCacheEntryResponse>(this, message, value);
return message;
}
internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: LookupCacheEntryResponse): LookupCacheEntryResponse {
let message = target ?? this.create(), end = reader.pos + length;
while (reader.pos < end) {
let [fieldNo, wireType] = reader.tag();
switch (fieldNo) {
case /* bool exists */ 1:
message.exists = reader.bool();
break;
case /* github.actions.results.entities.v1.CacheEntry entry */ 2:
message.entry = CacheEntry.internalBinaryRead(reader, reader.uint32(), options, message.entry);
break;
default:
let u = options.readUnknownField;
if (u === "throw")
throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
let d = reader.skip(wireType);
if (u !== false)
(u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
}
}
return message;
}
internalBinaryWrite(message: LookupCacheEntryResponse, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter {
/* bool exists = 1; */
if (message.exists !== false)
writer.tag(1, WireType.Varint).bool(message.exists);
/* github.actions.results.entities.v1.CacheEntry entry = 2; */
if (message.entry)
CacheEntry.internalBinaryWrite(message.entry, writer.tag(2, WireType.LengthDelimited).fork(), options).join();
let u = options.writeUnknownFields;
if (u !== false)
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
return writer;
}
}
/**
* @generated MessageType for protobuf message github.actions.results.api.v1.LookupCacheEntryResponse
*/
export const LookupCacheEntryResponse = new LookupCacheEntryResponse$Type();
/** /**
* @generated ServiceType for protobuf service github.actions.results.api.v1.CacheService * @generated ServiceType for protobuf service github.actions.results.api.v1.CacheService
*/ */
@@ -970,6 +802,5 @@ export const CacheService = new ServiceType("github.actions.results.api.v1.Cache
{ name: "FinalizeCacheEntryUpload", options: {}, I: FinalizeCacheEntryUploadRequest, O: FinalizeCacheEntryUploadResponse }, { name: "FinalizeCacheEntryUpload", options: {}, I: FinalizeCacheEntryUploadRequest, O: FinalizeCacheEntryUploadResponse },
{ name: "GetCacheEntryDownloadURL", options: {}, I: GetCacheEntryDownloadURLRequest, O: GetCacheEntryDownloadURLResponse }, { name: "GetCacheEntryDownloadURL", options: {}, I: GetCacheEntryDownloadURLRequest, O: GetCacheEntryDownloadURLResponse },
{ name: "DeleteCacheEntry", options: {}, I: DeleteCacheEntryRequest, O: DeleteCacheEntryResponse }, { name: "DeleteCacheEntry", options: {}, I: DeleteCacheEntryRequest, O: DeleteCacheEntryResponse },
{ name: "ListCacheEntries", options: {}, I: ListCacheEntriesRequest, O: ListCacheEntriesResponse }, { name: "ListCacheEntries", options: {}, I: ListCacheEntriesRequest, O: ListCacheEntriesResponse }
{ name: "LookupCacheEntry", options: {}, I: LookupCacheEntryRequest, O: LookupCacheEntryResponse }
]); ]);
@@ -19,8 +19,6 @@ import {
DeleteCacheEntryResponse, DeleteCacheEntryResponse,
ListCacheEntriesRequest, ListCacheEntriesRequest,
ListCacheEntriesResponse, ListCacheEntriesResponse,
LookupCacheEntryRequest,
LookupCacheEntryResponse,
} from "./cache"; } from "./cache";
//==================================// //==================================//
@@ -52,9 +50,6 @@ export interface CacheServiceClient {
ListCacheEntries( ListCacheEntries(
request: ListCacheEntriesRequest request: ListCacheEntriesRequest
): Promise<ListCacheEntriesResponse>; ): Promise<ListCacheEntriesResponse>;
LookupCacheEntry(
request: LookupCacheEntryRequest
): Promise<LookupCacheEntryResponse>;
} }
export class CacheServiceClientJSON implements CacheServiceClient { export class CacheServiceClientJSON implements CacheServiceClient {
@@ -66,7 +61,6 @@ export class CacheServiceClientJSON implements CacheServiceClient {
this.GetCacheEntryDownloadURL.bind(this); this.GetCacheEntryDownloadURL.bind(this);
this.DeleteCacheEntry.bind(this); this.DeleteCacheEntry.bind(this);
this.ListCacheEntries.bind(this); this.ListCacheEntries.bind(this);
this.LookupCacheEntry.bind(this);
} }
CreateCacheEntry( CreateCacheEntry(
request: CreateCacheEntryRequest request: CreateCacheEntryRequest
@@ -167,26 +161,6 @@ export class CacheServiceClientJSON implements CacheServiceClient {
}) })
); );
} }
LookupCacheEntry(
request: LookupCacheEntryRequest
): Promise<LookupCacheEntryResponse> {
const data = LookupCacheEntryRequest.toJson(request, {
useProtoFieldName: true,
emitDefaultValues: false,
});
const promise = this.rpc.request(
"github.actions.results.api.v1.CacheService",
"LookupCacheEntry",
"application/json",
data as object
);
return promise.then((data) =>
LookupCacheEntryResponse.fromJson(data as any, {
ignoreUnknownFields: true,
})
);
}
} }
export class CacheServiceClientProtobuf implements CacheServiceClient { export class CacheServiceClientProtobuf implements CacheServiceClient {
@@ -198,7 +172,6 @@ export class CacheServiceClientProtobuf implements CacheServiceClient {
this.GetCacheEntryDownloadURL.bind(this); this.GetCacheEntryDownloadURL.bind(this);
this.DeleteCacheEntry.bind(this); this.DeleteCacheEntry.bind(this);
this.ListCacheEntries.bind(this); this.ListCacheEntries.bind(this);
this.LookupCacheEntry.bind(this);
} }
CreateCacheEntry( CreateCacheEntry(
request: CreateCacheEntryRequest request: CreateCacheEntryRequest
@@ -274,21 +247,6 @@ export class CacheServiceClientProtobuf implements CacheServiceClient {
ListCacheEntriesResponse.fromBinary(data as Uint8Array) ListCacheEntriesResponse.fromBinary(data as Uint8Array)
); );
} }
LookupCacheEntry(
request: LookupCacheEntryRequest
): Promise<LookupCacheEntryResponse> {
const data = LookupCacheEntryRequest.toBinary(request);
const promise = this.rpc.request(
"github.actions.results.api.v1.CacheService",
"LookupCacheEntry",
"application/protobuf",
data
);
return promise.then((data) =>
LookupCacheEntryResponse.fromBinary(data as Uint8Array)
);
}
} }
//==================================// //==================================//
@@ -316,10 +274,6 @@ export interface CacheServiceTwirp<T extends TwirpContext = TwirpContext> {
ctx: T, ctx: T,
request: ListCacheEntriesRequest request: ListCacheEntriesRequest
): Promise<ListCacheEntriesResponse>; ): Promise<ListCacheEntriesResponse>;
LookupCacheEntry(
ctx: T,
request: LookupCacheEntryRequest
): Promise<LookupCacheEntryResponse>;
} }
export enum CacheServiceMethod { export enum CacheServiceMethod {
@@ -328,7 +282,6 @@ export enum CacheServiceMethod {
GetCacheEntryDownloadURL = "GetCacheEntryDownloadURL", GetCacheEntryDownloadURL = "GetCacheEntryDownloadURL",
DeleteCacheEntry = "DeleteCacheEntry", DeleteCacheEntry = "DeleteCacheEntry",
ListCacheEntries = "ListCacheEntries", ListCacheEntries = "ListCacheEntries",
LookupCacheEntry = "LookupCacheEntry",
} }
export const CacheServiceMethodList = [ export const CacheServiceMethodList = [
@@ -337,7 +290,6 @@ export const CacheServiceMethodList = [
CacheServiceMethod.GetCacheEntryDownloadURL, CacheServiceMethod.GetCacheEntryDownloadURL,
CacheServiceMethod.DeleteCacheEntry, CacheServiceMethod.DeleteCacheEntry,
CacheServiceMethod.ListCacheEntries, CacheServiceMethod.ListCacheEntries,
CacheServiceMethod.LookupCacheEntry,
]; ];
export function createCacheServiceServer<T extends TwirpContext = TwirpContext>( export function createCacheServiceServer<T extends TwirpContext = TwirpContext>(
@@ -457,26 +409,6 @@ function matchCacheServiceRoute<T extends TwirpContext = TwirpContext>(
interceptors interceptors
); );
}; };
case "LookupCacheEntry":
return async (
ctx: T,
service: CacheServiceTwirp,
data: Buffer,
interceptors?: Interceptor<
T,
LookupCacheEntryRequest,
LookupCacheEntryResponse
>[]
) => {
ctx = { ...ctx, methodName: "LookupCacheEntry" };
await events.onMatch(ctx);
return handleCacheServiceLookupCacheEntryRequest(
ctx,
service,
data,
interceptors
);
};
default: default:
events.onNotFound(); events.onNotFound();
const msg = `no handler found`; const msg = `no handler found`;
@@ -648,39 +580,6 @@ function handleCacheServiceListCacheEntriesRequest<
throw new TwirpError(TwirpErrorCode.BadRoute, msg); throw new TwirpError(TwirpErrorCode.BadRoute, msg);
} }
} }
function handleCacheServiceLookupCacheEntryRequest<
T extends TwirpContext = TwirpContext
>(
ctx: T,
service: CacheServiceTwirp,
data: Buffer,
interceptors?: Interceptor<
T,
LookupCacheEntryRequest,
LookupCacheEntryResponse
>[]
): Promise<string | Uint8Array> {
switch (ctx.contentType) {
case TwirpContentType.JSON:
return handleCacheServiceLookupCacheEntryJSON<T>(
ctx,
service,
data,
interceptors
);
case TwirpContentType.Protobuf:
return handleCacheServiceLookupCacheEntryProtobuf<T>(
ctx,
service,
data,
interceptors
);
default:
const msg = "unexpected Content-Type";
throw new TwirpError(TwirpErrorCode.BadRoute, msg);
}
}
async function handleCacheServiceCreateCacheEntryJSON< async function handleCacheServiceCreateCacheEntryJSON<
T extends TwirpContext = TwirpContext T extends TwirpContext = TwirpContext
>( >(
@@ -920,54 +819,6 @@ async function handleCacheServiceListCacheEntriesJSON<
}) as string }) as string
); );
} }
async function handleCacheServiceLookupCacheEntryJSON<
T extends TwirpContext = TwirpContext
>(
ctx: T,
service: CacheServiceTwirp,
data: Buffer,
interceptors?: Interceptor<
T,
LookupCacheEntryRequest,
LookupCacheEntryResponse
>[]
) {
let request: LookupCacheEntryRequest;
let response: LookupCacheEntryResponse;
try {
const body = JSON.parse(data.toString() || "{}");
request = LookupCacheEntryRequest.fromJson(body, {
ignoreUnknownFields: true,
});
} catch (e) {
if (e instanceof Error) {
const msg = "the json request could not be decoded";
throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
}
}
if (interceptors && interceptors.length > 0) {
const interceptor = chainInterceptors(...interceptors) as Interceptor<
T,
LookupCacheEntryRequest,
LookupCacheEntryResponse
>;
response = await interceptor(ctx, request!, (ctx, inputReq) => {
return service.LookupCacheEntry(ctx, inputReq);
});
} else {
response = await service.LookupCacheEntry(ctx, request!);
}
return JSON.stringify(
LookupCacheEntryResponse.toJson(response, {
useProtoFieldName: true,
emitDefaultValues: false,
}) as string
);
}
async function handleCacheServiceCreateCacheEntryProtobuf< async function handleCacheServiceCreateCacheEntryProtobuf<
T extends TwirpContext = TwirpContext T extends TwirpContext = TwirpContext
>( >(
@@ -1167,43 +1018,3 @@ async function handleCacheServiceListCacheEntriesProtobuf<
return Buffer.from(ListCacheEntriesResponse.toBinary(response)); return Buffer.from(ListCacheEntriesResponse.toBinary(response));
} }
async function handleCacheServiceLookupCacheEntryProtobuf<
T extends TwirpContext = TwirpContext
>(
ctx: T,
service: CacheServiceTwirp,
data: Buffer,
interceptors?: Interceptor<
T,
LookupCacheEntryRequest,
LookupCacheEntryResponse
>[]
) {
let request: LookupCacheEntryRequest;
let response: LookupCacheEntryResponse;
try {
request = LookupCacheEntryRequest.fromBinary(data);
} catch (e) {
if (e instanceof Error) {
const msg = "the protobuf request could not be decoded";
throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
}
}
if (interceptors && interceptors.length > 0) {
const interceptor = chainInterceptors(...interceptors) as Interceptor<
T,
LookupCacheEntryRequest,
LookupCacheEntryResponse
>;
response = await interceptor(ctx, request!, (ctx, inputReq) => {
return service.LookupCacheEntry(ctx, inputReq);
});
} else {
response = await service.LookupCacheEntry(ctx, request!);
}
return Buffer.from(LookupCacheEntryResponse.toBinary(response));
}