Skip to content

Commit

Permalink
feat!: Add support for cheqd/proto v2 [DEV-2154] (#69)
Browse files Browse the repository at this point in the history
* v2 proto

* Update package-lock.json
  • Loading branch information
ankurdotb authored Jan 25, 2023
1 parent e6fcc65 commit e3d7b37
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 78 deletions.
43 changes: 37 additions & 6 deletions cheqd/resource/v2/query.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable */
import Long from "long";
import _m0 from "protobufjs/minimal";
import { PageRequest, PageResponse } from "../../../cosmos/base/query/v1beta1/pagination";
import { Metadata, ResourceWithMetadata } from "./resource";

/** QueryResourceRequest is the request type for the Query/Resource RPC method */
Expand Down Expand Up @@ -66,12 +67,16 @@ export interface QueryCollectionResourcesRequest {
* - wGHEXrZvJxR8vw5P3UWH1j
*/
collectionId: string;
/** pagination defines an optional pagination for the request. */
pagination: PageRequest | undefined;
}

/** QueryCollectionResourcesResponse is the response type for the Query/CollectionResources RPC method */
export interface QueryCollectionResourcesResponse {
/** resources is the requested collection of resource metadata */
resources: Metadata[];
/** pagination defines the pagination in the response. */
pagination: PageResponse | undefined;
}

function createBaseQueryResourceRequest(): QueryResourceRequest {
Expand Down Expand Up @@ -308,14 +313,17 @@ export const QueryResourceMetadataResponse = {
};

function createBaseQueryCollectionResourcesRequest(): QueryCollectionResourcesRequest {
return { collectionId: "" };
return { collectionId: "", pagination: undefined };
}

export const QueryCollectionResourcesRequest = {
encode(message: QueryCollectionResourcesRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.collectionId !== "") {
writer.uint32(10).string(message.collectionId);
}
if (message.pagination !== undefined) {
PageRequest.encode(message.pagination, writer.uint32(18).fork()).ldelim();
}
return writer;
},

Expand All @@ -329,6 +337,9 @@ export const QueryCollectionResourcesRequest = {
case 1:
message.collectionId = reader.string();
break;
case 2:
message.pagination = PageRequest.decode(reader, reader.uint32());
break;
default:
reader.skipType(tag & 7);
break;
Expand All @@ -338,12 +349,17 @@ export const QueryCollectionResourcesRequest = {
},

fromJSON(object: any): QueryCollectionResourcesRequest {
return { collectionId: isSet(object.collectionId) ? String(object.collectionId) : "" };
return {
collectionId: isSet(object.collectionId) ? String(object.collectionId) : "",
pagination: isSet(object.pagination) ? PageRequest.fromJSON(object.pagination) : undefined,
};
},

toJSON(message: QueryCollectionResourcesRequest): unknown {
const obj: any = {};
message.collectionId !== undefined && (obj.collectionId = message.collectionId);
message.pagination !== undefined &&
(obj.pagination = message.pagination ? PageRequest.toJSON(message.pagination) : undefined);
return obj;
},

Expand All @@ -356,19 +372,25 @@ export const QueryCollectionResourcesRequest = {
): QueryCollectionResourcesRequest {
const message = createBaseQueryCollectionResourcesRequest();
message.collectionId = object.collectionId ?? "";
message.pagination = (object.pagination !== undefined && object.pagination !== null)
? PageRequest.fromPartial(object.pagination)
: undefined;
return message;
},
};

function createBaseQueryCollectionResourcesResponse(): QueryCollectionResourcesResponse {
return { resources: [] };
return { resources: [], pagination: undefined };
}

export const QueryCollectionResourcesResponse = {
encode(message: QueryCollectionResourcesResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
for (const v of message.resources) {
Metadata.encode(v!, writer.uint32(10).fork()).ldelim();
}
if (message.pagination !== undefined) {
PageResponse.encode(message.pagination, writer.uint32(18).fork()).ldelim();
}
return writer;
},

Expand All @@ -382,6 +404,9 @@ export const QueryCollectionResourcesResponse = {
case 1:
message.resources.push(Metadata.decode(reader, reader.uint32()));
break;
case 2:
message.pagination = PageResponse.decode(reader, reader.uint32());
break;
default:
reader.skipType(tag & 7);
break;
Expand All @@ -393,6 +418,7 @@ export const QueryCollectionResourcesResponse = {
fromJSON(object: any): QueryCollectionResourcesResponse {
return {
resources: Array.isArray(object?.resources) ? object.resources.map((e: any) => Metadata.fromJSON(e)) : [],
pagination: isSet(object.pagination) ? PageResponse.fromJSON(object.pagination) : undefined,
};
},

Expand All @@ -403,6 +429,8 @@ export const QueryCollectionResourcesResponse = {
} else {
obj.resources = [];
}
message.pagination !== undefined &&
(obj.pagination = message.pagination ? PageResponse.toJSON(message.pagination) : undefined);
return obj;
},

Expand All @@ -417,17 +445,20 @@ export const QueryCollectionResourcesResponse = {
): QueryCollectionResourcesResponse {
const message = createBaseQueryCollectionResourcesResponse();
message.resources = object.resources?.map((e) => Metadata.fromPartial(e)) || [];
message.pagination = (object.pagination !== undefined && object.pagination !== null)
? PageResponse.fromPartial(object.pagination)
: undefined;
return message;
},
};

/** Query defines the gRPC querier service for the resource module */
export interface Query {
/** Fetch a resource from a collection with a given collection_id and id */
/** Fetch data/payload for a specific resource (without metadata) */
Resource(request: QueryResourceRequest): Promise<QueryResourceResponse>;
/** Fetch a resource's metadata from a collection with a given collection_id and id */
/** Fetch only metadata for a specific resource */
ResourceMetadata(request: QueryResourceMetadataRequest): Promise<QueryResourceMetadataResponse>;
/** Fetch all resource metadata from a collection with a given collection_id */
/** Fetch metadata for all resources in a collection */
CollectionResources(request: QueryCollectionResourcesRequest): Promise<QueryCollectionResourcesResponse>;
}

Expand Down
145 changes: 75 additions & 70 deletions cheqd/resource/v2/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ import Long from "long";
import _m0 from "protobufjs/minimal";
import { Timestamp } from "../../../google/protobuf/timestamp";

/** ResourceWithMetadata describes the overall structure of a DID-Linked Resource */
export interface ResourceWithMetadata {
resource: Resource | undefined;
metadata: Metadata | undefined;
}

/** Resource stores the contents of a DID-Linked Resource */
export interface Resource {
/** bytes is the raw data of the Resource */
Expand All @@ -20,6 +14,11 @@ export interface Metadata {
/**
* collection_id is the ID of the collection that the Resource belongs to. Defined client-side.
* This field is the unique identifier of the DID linked to this Resource
* Format: <unique-identifier>
*
* Examples:
* - c82f2b02-bdab-4dd7-b833-3e143745d612
* - wGHEXrZvJxR8vw5P3UWH1j
*/
collectionId: string;
/**
Expand Down Expand Up @@ -105,72 +104,12 @@ export interface AlternativeUri {
description: string;
}

function createBaseResourceWithMetadata(): ResourceWithMetadata {
return { resource: undefined, metadata: undefined };
/** ResourceWithMetadata describes the overall structure of a DID-Linked Resource */
export interface ResourceWithMetadata {
resource: Resource | undefined;
metadata: Metadata | undefined;
}

export const ResourceWithMetadata = {
encode(message: ResourceWithMetadata, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.resource !== undefined) {
Resource.encode(message.resource, writer.uint32(10).fork()).ldelim();
}
if (message.metadata !== undefined) {
Metadata.encode(message.metadata, writer.uint32(18).fork()).ldelim();
}
return writer;
},

decode(input: _m0.Reader | Uint8Array, length?: number): ResourceWithMetadata {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseResourceWithMetadata();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.resource = Resource.decode(reader, reader.uint32());
break;
case 2:
message.metadata = Metadata.decode(reader, reader.uint32());
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},

fromJSON(object: any): ResourceWithMetadata {
return {
resource: isSet(object.resource) ? Resource.fromJSON(object.resource) : undefined,
metadata: isSet(object.metadata) ? Metadata.fromJSON(object.metadata) : undefined,
};
},

toJSON(message: ResourceWithMetadata): unknown {
const obj: any = {};
message.resource !== undefined && (obj.resource = message.resource ? Resource.toJSON(message.resource) : undefined);
message.metadata !== undefined && (obj.metadata = message.metadata ? Metadata.toJSON(message.metadata) : undefined);
return obj;
},

create<I extends Exact<DeepPartial<ResourceWithMetadata>, I>>(base?: I): ResourceWithMetadata {
return ResourceWithMetadata.fromPartial(base ?? {});
},

fromPartial<I extends Exact<DeepPartial<ResourceWithMetadata>, I>>(object: I): ResourceWithMetadata {
const message = createBaseResourceWithMetadata();
message.resource = (object.resource !== undefined && object.resource !== null)
? Resource.fromPartial(object.resource)
: undefined;
message.metadata = (object.metadata !== undefined && object.metadata !== null)
? Metadata.fromPartial(object.metadata)
: undefined;
return message;
},
};

function createBaseResource(): Resource {
return { data: new Uint8Array() };
}
Expand Down Expand Up @@ -446,6 +385,72 @@ export const AlternativeUri = {
},
};

function createBaseResourceWithMetadata(): ResourceWithMetadata {
return { resource: undefined, metadata: undefined };
}

export const ResourceWithMetadata = {
encode(message: ResourceWithMetadata, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.resource !== undefined) {
Resource.encode(message.resource, writer.uint32(10).fork()).ldelim();
}
if (message.metadata !== undefined) {
Metadata.encode(message.metadata, writer.uint32(18).fork()).ldelim();
}
return writer;
},

decode(input: _m0.Reader | Uint8Array, length?: number): ResourceWithMetadata {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseResourceWithMetadata();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.resource = Resource.decode(reader, reader.uint32());
break;
case 2:
message.metadata = Metadata.decode(reader, reader.uint32());
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},

fromJSON(object: any): ResourceWithMetadata {
return {
resource: isSet(object.resource) ? Resource.fromJSON(object.resource) : undefined,
metadata: isSet(object.metadata) ? Metadata.fromJSON(object.metadata) : undefined,
};
},

toJSON(message: ResourceWithMetadata): unknown {
const obj: any = {};
message.resource !== undefined && (obj.resource = message.resource ? Resource.toJSON(message.resource) : undefined);
message.metadata !== undefined && (obj.metadata = message.metadata ? Metadata.toJSON(message.metadata) : undefined);
return obj;
},

create<I extends Exact<DeepPartial<ResourceWithMetadata>, I>>(base?: I): ResourceWithMetadata {
return ResourceWithMetadata.fromPartial(base ?? {});
},

fromPartial<I extends Exact<DeepPartial<ResourceWithMetadata>, I>>(object: I): ResourceWithMetadata {
const message = createBaseResourceWithMetadata();
message.resource = (object.resource !== undefined && object.resource !== null)
? Resource.fromPartial(object.resource)
: undefined;
message.metadata = (object.metadata !== undefined && object.metadata !== null)
? Metadata.fromPartial(object.metadata)
: undefined;
return message;
},
};

declare var self: any | undefined;
declare var window: any | undefined;
declare var global: any | undefined;
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e3d7b37

Please sign in to comment.