Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f166bbadbb | |||
| b7a00a3203 | |||
| 0827eef58f | |||
| cd9197e9bd | |||
| 72447df44c | |||
| 59845ec372 | |||
| cb001af8a3 | |||
| 4498687c5e | |||
| a10e209c8d |
Vendored
+14
-2
@@ -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.
|
||||
|
||||
## ⚠️ 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
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
|
||||
|
||||
Vendored
+23
@@ -1,6 +1,29 @@
|
||||
# @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
|
||||
|
||||
- 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)
|
||||
|
||||
|
||||
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@actions/cache",
|
||||
"version": "3.3.0",
|
||||
"version": "4.0.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@actions/cache",
|
||||
"version": "3.3.0",
|
||||
"version": "4.0.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.11.1",
|
||||
|
||||
Vendored
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@actions/cache",
|
||||
"version": "3.3.0",
|
||||
"version": "4.0.0",
|
||||
"preview": true,
|
||||
"description": "Actions cache lib",
|
||||
"keywords": [
|
||||
|
||||
+1
-170
@@ -212,52 +212,6 @@ export interface ListCacheEntriesResponse {
|
||||
*/
|
||||
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
|
||||
class CreateCacheEntryRequest$Type extends MessageType<CreateCacheEntryRequest> {
|
||||
constructor() {
|
||||
@@ -840,128 +794,6 @@ class ListCacheEntriesResponse$Type extends MessageType<ListCacheEntriesResponse
|
||||
* @generated MessageType for protobuf message github.actions.results.api.v1.ListCacheEntriesResponse
|
||||
*/
|
||||
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
|
||||
*/
|
||||
@@ -970,6 +802,5 @@ export const CacheService = new ServiceType("github.actions.results.api.v1.Cache
|
||||
{ name: "FinalizeCacheEntryUpload", options: {}, I: FinalizeCacheEntryUploadRequest, O: FinalizeCacheEntryUploadResponse },
|
||||
{ name: "GetCacheEntryDownloadURL", options: {}, I: GetCacheEntryDownloadURLRequest, O: GetCacheEntryDownloadURLResponse },
|
||||
{ name: "DeleteCacheEntry", options: {}, I: DeleteCacheEntryRequest, O: DeleteCacheEntryResponse },
|
||||
{ name: "ListCacheEntries", options: {}, I: ListCacheEntriesRequest, O: ListCacheEntriesResponse },
|
||||
{ name: "LookupCacheEntry", options: {}, I: LookupCacheEntryRequest, O: LookupCacheEntryResponse }
|
||||
{ name: "ListCacheEntries", options: {}, I: ListCacheEntriesRequest, O: ListCacheEntriesResponse }
|
||||
]);
|
||||
|
||||
@@ -19,8 +19,6 @@ import {
|
||||
DeleteCacheEntryResponse,
|
||||
ListCacheEntriesRequest,
|
||||
ListCacheEntriesResponse,
|
||||
LookupCacheEntryRequest,
|
||||
LookupCacheEntryResponse,
|
||||
} from "./cache";
|
||||
|
||||
//==================================//
|
||||
@@ -52,9 +50,6 @@ export interface CacheServiceClient {
|
||||
ListCacheEntries(
|
||||
request: ListCacheEntriesRequest
|
||||
): Promise<ListCacheEntriesResponse>;
|
||||
LookupCacheEntry(
|
||||
request: LookupCacheEntryRequest
|
||||
): Promise<LookupCacheEntryResponse>;
|
||||
}
|
||||
|
||||
export class CacheServiceClientJSON implements CacheServiceClient {
|
||||
@@ -66,7 +61,6 @@ export class CacheServiceClientJSON implements CacheServiceClient {
|
||||
this.GetCacheEntryDownloadURL.bind(this);
|
||||
this.DeleteCacheEntry.bind(this);
|
||||
this.ListCacheEntries.bind(this);
|
||||
this.LookupCacheEntry.bind(this);
|
||||
}
|
||||
CreateCacheEntry(
|
||||
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 {
|
||||
@@ -198,7 +172,6 @@ export class CacheServiceClientProtobuf implements CacheServiceClient {
|
||||
this.GetCacheEntryDownloadURL.bind(this);
|
||||
this.DeleteCacheEntry.bind(this);
|
||||
this.ListCacheEntries.bind(this);
|
||||
this.LookupCacheEntry.bind(this);
|
||||
}
|
||||
CreateCacheEntry(
|
||||
request: CreateCacheEntryRequest
|
||||
@@ -274,21 +247,6 @@ export class CacheServiceClientProtobuf implements CacheServiceClient {
|
||||
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,
|
||||
request: ListCacheEntriesRequest
|
||||
): Promise<ListCacheEntriesResponse>;
|
||||
LookupCacheEntry(
|
||||
ctx: T,
|
||||
request: LookupCacheEntryRequest
|
||||
): Promise<LookupCacheEntryResponse>;
|
||||
}
|
||||
|
||||
export enum CacheServiceMethod {
|
||||
@@ -328,7 +282,6 @@ export enum CacheServiceMethod {
|
||||
GetCacheEntryDownloadURL = "GetCacheEntryDownloadURL",
|
||||
DeleteCacheEntry = "DeleteCacheEntry",
|
||||
ListCacheEntries = "ListCacheEntries",
|
||||
LookupCacheEntry = "LookupCacheEntry",
|
||||
}
|
||||
|
||||
export const CacheServiceMethodList = [
|
||||
@@ -337,7 +290,6 @@ export const CacheServiceMethodList = [
|
||||
CacheServiceMethod.GetCacheEntryDownloadURL,
|
||||
CacheServiceMethod.DeleteCacheEntry,
|
||||
CacheServiceMethod.ListCacheEntries,
|
||||
CacheServiceMethod.LookupCacheEntry,
|
||||
];
|
||||
|
||||
export function createCacheServiceServer<T extends TwirpContext = TwirpContext>(
|
||||
@@ -457,26 +409,6 @@ function matchCacheServiceRoute<T extends TwirpContext = TwirpContext>(
|
||||
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:
|
||||
events.onNotFound();
|
||||
const msg = `no handler found`;
|
||||
@@ -648,39 +580,6 @@ function handleCacheServiceListCacheEntriesRequest<
|
||||
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<
|
||||
T extends TwirpContext = TwirpContext
|
||||
>(
|
||||
@@ -920,54 +819,6 @@ async function handleCacheServiceListCacheEntriesJSON<
|
||||
}) 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<
|
||||
T extends TwirpContext = TwirpContext
|
||||
>(
|
||||
@@ -1167,43 +1018,3 @@ async function handleCacheServiceListCacheEntriesProtobuf<
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user