diff --git a/generated/api_pb.d.ts b/generated/api_pb.d.ts index b2a24ac..6e2daec 100644 --- a/generated/api_pb.d.ts +++ b/generated/api_pb.d.ts @@ -48,6 +48,28 @@ export namespace Request { } } +export class Uids extends jspb.Message { + clearUidsList(): void; + getUidsList(): Array; + setUidsList(value: Array): void; + addUids(value: string, index?: number): string; + + serializeBinary(): Uint8Array; + toObject(includeInstance?: boolean): Uids.AsObject; + static toObject(includeInstance: boolean, msg: Uids): Uids.AsObject; + static extensions: {[key: number]: jspb.ExtensionFieldInfo}; + static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; + static serializeBinaryToWriter(message: Uids, writer: jspb.BinaryWriter): void; + static deserializeBinary(bytes: Uint8Array): Uids; + static deserializeBinaryFromReader(message: Uids, reader: jspb.BinaryReader): Uids; +} + +export namespace Uids { + export type AsObject = { + uidsList: Array, + } +} + export class Response extends jspb.Message { getJson(): Uint8Array | string; getJson_asU8(): Uint8Array; @@ -64,6 +86,11 @@ export class Response extends jspb.Message { getLatency(): Latency | undefined; setLatency(value?: Latency): void; + hasMetrics(): boolean; + clearMetrics(): void; + getMetrics(): Metrics | undefined; + setMetrics(value?: Metrics): void; + getUidsMap(): jspb.Map; clearUidsMap(): void; serializeBinary(): Uint8Array; @@ -81,6 +108,7 @@ export namespace Response { json: Uint8Array | string, txn?: TxnContext.AsObject, latency?: Latency.AsObject, + metrics?: Metrics.AsObject, uidsMap: Array<[string, string]>, } } @@ -302,6 +330,9 @@ export class Latency extends jspb.Message { getAssignTimestampNs(): number; setAssignTimestampNs(value: number): void; + getTotalNs(): number; + setTotalNs(value: number): void; + serializeBinary(): Uint8Array; toObject(includeInstance?: boolean): Latency.AsObject; static toObject(includeInstance: boolean, msg: Latency): Latency.AsObject; @@ -318,6 +349,26 @@ export namespace Latency { processingNs: number, encodingNs: number, assignTimestampNs: number, + totalNs: number, + } +} + +export class Metrics extends jspb.Message { + getNumUidsMap(): jspb.Map; + clearNumUidsMap(): void; + serializeBinary(): Uint8Array; + toObject(includeInstance?: boolean): Metrics.AsObject; + static toObject(includeInstance: boolean, msg: Metrics): Metrics.AsObject; + static extensions: {[key: number]: jspb.ExtensionFieldInfo}; + static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; + static serializeBinaryToWriter(message: Metrics, writer: jspb.BinaryWriter): void; + static deserializeBinary(bytes: Uint8Array): Metrics; + static deserializeBinaryFromReader(message: Metrics, reader: jspb.BinaryReader): Metrics; +} + +export namespace Metrics { + export type AsObject = { + numUidsMap: Array<[string, number]>, } } diff --git a/generated/api_pb.js b/generated/api_pb.js index 7e52741..069252f 100644 --- a/generated/api_pb.js +++ b/generated/api_pb.js @@ -18,6 +18,7 @@ goog.exportSymbol('proto.api.Facet.ValType', null, global); goog.exportSymbol('proto.api.Jwt', null, global); goog.exportSymbol('proto.api.Latency', null, global); goog.exportSymbol('proto.api.LoginRequest', null, global); +goog.exportSymbol('proto.api.Metrics', null, global); goog.exportSymbol('proto.api.Mutation', null, global); goog.exportSymbol('proto.api.NQuad', null, global); goog.exportSymbol('proto.api.Operation', null, global); @@ -26,6 +27,7 @@ goog.exportSymbol('proto.api.Payload', null, global); goog.exportSymbol('proto.api.Request', null, global); goog.exportSymbol('proto.api.Response', null, global); goog.exportSymbol('proto.api.TxnContext', null, global); +goog.exportSymbol('proto.api.Uids', null, global); goog.exportSymbol('proto.api.Value', null, global); goog.exportSymbol('proto.api.Value.ValCase', null, global); goog.exportSymbol('proto.api.Version', null, global); @@ -50,6 +52,27 @@ if (goog.DEBUG && !COMPILED) { */ proto.api.Request.displayName = 'proto.api.Request'; } +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.api.Uids = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, proto.api.Uids.repeatedFields_, null); +}; +goog.inherits(proto.api.Uids, jspb.Message); +if (goog.DEBUG && !COMPILED) { + /** + * @public + * @override + */ + proto.api.Uids.displayName = 'proto.api.Uids'; +} /** * Generated by JsPbCodeGenerator. * @param {Array=} opt_data Optional initial data array, typically from a @@ -218,6 +241,27 @@ if (goog.DEBUG && !COMPILED) { */ proto.api.Latency.displayName = 'proto.api.Latency'; } +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.api.Metrics = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, null); +}; +goog.inherits(proto.api.Metrics, jspb.Message); +if (goog.DEBUG && !COMPILED) { + /** + * @public + * @override + */ + proto.api.Metrics.displayName = 'proto.api.Metrics'; +} /** * Generated by JsPbCodeGenerator. * @param {Array=} opt_data Optional initial data array, typically from a @@ -667,6 +711,162 @@ proto.api.Request.prototype.setCommitNow = function(value) { +/** + * List of repeated fields within this message type. + * @private {!Array} + * @const + */ +proto.api.Uids.repeatedFields_ = [1]; + + + +if (jspb.Message.GENERATE_TO_OBJECT) { +/** + * Creates an object representation of this proto. + * Field names that are reserved in JavaScript and will be renamed to pb_name. + * Optional fields that are not set will be set to undefined. + * To access a reserved field use, foo.pb_, eg, foo.pb_default. + * For the list of reserved names please see: + * net/proto2/compiler/js/internal/generator.cc#kKeyword. + * @param {boolean=} opt_includeInstance Deprecated. whether to include the + * JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @return {!Object} + */ +proto.api.Uids.prototype.toObject = function(opt_includeInstance) { + return proto.api.Uids.toObject(opt_includeInstance, this); +}; + + +/** + * Static version of the {@see toObject} method. + * @param {boolean|undefined} includeInstance Deprecated. Whether to include + * the JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @param {!proto.api.Uids} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.api.Uids.toObject = function(includeInstance, msg) { + var f, obj = { + uidsList: (f = jspb.Message.getRepeatedField(msg, 1)) == null ? undefined : f + }; + + if (includeInstance) { + obj.$jspbMessageInstance = msg; + } + return obj; +}; +} + + +/** + * Deserializes binary data (in protobuf wire format). + * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @return {!proto.api.Uids} + */ +proto.api.Uids.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.api.Uids; + return proto.api.Uids.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.api.Uids} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.api.Uids} + */ +proto.api.Uids.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + case 1: + var value = /** @type {string} */ (reader.readString()); + msg.addUids(value); + break; + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.api.Uids.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.api.Uids.serializeBinaryToWriter(this, writer); + return writer.getResultBuffer(); +}; + + +/** + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.api.Uids} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.api.Uids.serializeBinaryToWriter = function(message, writer) { + var f = undefined; + f = message.getUidsList(); + if (f.length > 0) { + writer.writeRepeatedString( + 1, + f + ); + } +}; + + +/** + * repeated string uids = 1; + * @return {!Array} + */ +proto.api.Uids.prototype.getUidsList = function() { + return /** @type {!Array} */ (jspb.Message.getRepeatedField(this, 1)); +}; + + +/** + * @param {!Array} value + * @return {!proto.api.Uids} returns this + */ +proto.api.Uids.prototype.setUidsList = function(value) { + return jspb.Message.setField(this, 1, value || []); +}; + + +/** + * @param {string} value + * @param {number=} opt_index + * @return {!proto.api.Uids} returns this + */ +proto.api.Uids.prototype.addUids = function(value, opt_index) { + return jspb.Message.addToRepeatedField(this, 1, value, opt_index); +}; + + +/** + * Clears the list making it empty but non-null. + * @return {!proto.api.Uids} returns this + */ +proto.api.Uids.prototype.clearUidsList = function() { + return this.setUidsList([]); +}; + + + if (jspb.Message.GENERATE_TO_OBJECT) { @@ -701,6 +901,7 @@ proto.api.Response.toObject = function(includeInstance, msg) { json: msg.getJson_asB64(), txn: (f = msg.getTxn()) && proto.api.TxnContext.toObject(includeInstance, f), latency: (f = msg.getLatency()) && proto.api.Latency.toObject(includeInstance, f), + metrics: (f = msg.getMetrics()) && proto.api.Metrics.toObject(includeInstance, f), uidsMap: (f = msg.getUidsMap()) ? f.toObject(includeInstance, undefined) : [] }; @@ -752,6 +953,11 @@ proto.api.Response.deserializeBinaryFromReader = function(msg, reader) { reader.readMessage(value,proto.api.Latency.deserializeBinaryFromReader); msg.setLatency(value); break; + case 4: + var value = new proto.api.Metrics; + reader.readMessage(value,proto.api.Metrics.deserializeBinaryFromReader); + msg.setMetrics(value); + break; case 12: var value = msg.getUidsMap(); reader.readMessage(value, function(message, reader) { @@ -810,6 +1016,14 @@ proto.api.Response.serializeBinaryToWriter = function(message, writer) { proto.api.Latency.serializeBinaryToWriter ); } + f = message.getMetrics(); + if (f != null) { + writer.writeMessage( + 4, + f, + proto.api.Metrics.serializeBinaryToWriter + ); + } f = message.getUidsMap(true); if (f && f.getLength() > 0) { f.serializeBinary(12, writer, jspb.BinaryWriter.prototype.writeString, jspb.BinaryWriter.prototype.writeString); @@ -933,6 +1147,43 @@ proto.api.Response.prototype.hasLatency = function() { }; +/** + * optional Metrics metrics = 4; + * @return {?proto.api.Metrics} + */ +proto.api.Response.prototype.getMetrics = function() { + return /** @type{?proto.api.Metrics} */ ( + jspb.Message.getWrapperField(this, proto.api.Metrics, 4)); +}; + + +/** + * @param {?proto.api.Metrics|undefined} value + * @return {!proto.api.Response} returns this +*/ +proto.api.Response.prototype.setMetrics = function(value) { + return jspb.Message.setWrapperField(this, 4, value); +}; + + +/** + * Clears the message field making it undefined. + * @return {!proto.api.Response} returns this + */ +proto.api.Response.prototype.clearMetrics = function() { + return this.setMetrics(undefined); +}; + + +/** + * Returns whether this field is set. + * @return {boolean} + */ +proto.api.Response.prototype.hasMetrics = function() { + return jspb.Message.getField(this, 4) != null; +}; + + /** * map uids = 12; * @param {boolean=} opt_noLazyCreate Do not create the map if @@ -2420,7 +2671,8 @@ proto.api.Latency.toObject = function(includeInstance, msg) { parsingNs: jspb.Message.getFieldWithDefault(msg, 1, 0), processingNs: jspb.Message.getFieldWithDefault(msg, 2, 0), encodingNs: jspb.Message.getFieldWithDefault(msg, 3, 0), - assignTimestampNs: jspb.Message.getFieldWithDefault(msg, 4, 0) + assignTimestampNs: jspb.Message.getFieldWithDefault(msg, 4, 0), + totalNs: jspb.Message.getFieldWithDefault(msg, 5, 0) }; if (includeInstance) { @@ -2473,6 +2725,10 @@ proto.api.Latency.deserializeBinaryFromReader = function(msg, reader) { var value = /** @type {number} */ (reader.readUint64()); msg.setAssignTimestampNs(value); break; + case 5: + var value = /** @type {number} */ (reader.readUint64()); + msg.setTotalNs(value); + break; default: reader.skipField(); break; @@ -2530,6 +2786,13 @@ proto.api.Latency.serializeBinaryToWriter = function(message, writer) { f ); } + f = message.getTotalNs(); + if (f !== 0) { + writer.writeUint64( + 5, + f + ); + } }; @@ -2605,6 +2868,157 @@ proto.api.Latency.prototype.setAssignTimestampNs = function(value) { }; +/** + * optional uint64 total_ns = 5; + * @return {number} + */ +proto.api.Latency.prototype.getTotalNs = function() { + return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 5, 0)); +}; + + +/** + * @param {number} value + * @return {!proto.api.Latency} returns this + */ +proto.api.Latency.prototype.setTotalNs = function(value) { + return jspb.Message.setProto3IntField(this, 5, value); +}; + + + + + +if (jspb.Message.GENERATE_TO_OBJECT) { +/** + * Creates an object representation of this proto. + * Field names that are reserved in JavaScript and will be renamed to pb_name. + * Optional fields that are not set will be set to undefined. + * To access a reserved field use, foo.pb_, eg, foo.pb_default. + * For the list of reserved names please see: + * net/proto2/compiler/js/internal/generator.cc#kKeyword. + * @param {boolean=} opt_includeInstance Deprecated. whether to include the + * JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @return {!Object} + */ +proto.api.Metrics.prototype.toObject = function(opt_includeInstance) { + return proto.api.Metrics.toObject(opt_includeInstance, this); +}; + + +/** + * Static version of the {@see toObject} method. + * @param {boolean|undefined} includeInstance Deprecated. Whether to include + * the JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @param {!proto.api.Metrics} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.api.Metrics.toObject = function(includeInstance, msg) { + var f, obj = { + numUidsMap: (f = msg.getNumUidsMap()) ? f.toObject(includeInstance, undefined) : [] + }; + + if (includeInstance) { + obj.$jspbMessageInstance = msg; + } + return obj; +}; +} + + +/** + * Deserializes binary data (in protobuf wire format). + * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @return {!proto.api.Metrics} + */ +proto.api.Metrics.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.api.Metrics; + return proto.api.Metrics.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.api.Metrics} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.api.Metrics} + */ +proto.api.Metrics.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + case 1: + var value = msg.getNumUidsMap(); + reader.readMessage(value, function(message, reader) { + jspb.Map.deserializeBinary(message, reader, jspb.BinaryReader.prototype.readString, jspb.BinaryReader.prototype.readUint64, null, "", 0); + }); + break; + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.api.Metrics.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.api.Metrics.serializeBinaryToWriter(this, writer); + return writer.getResultBuffer(); +}; + + +/** + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.api.Metrics} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.api.Metrics.serializeBinaryToWriter = function(message, writer) { + var f = undefined; + f = message.getNumUidsMap(true); + if (f && f.getLength() > 0) { + f.serializeBinary(1, writer, jspb.BinaryWriter.prototype.writeString, jspb.BinaryWriter.prototype.writeUint64); + } +}; + + +/** + * map num_uids = 1; + * @param {boolean=} opt_noLazyCreate Do not create the map if + * empty, instead returning `undefined` + * @return {!jspb.Map} + */ +proto.api.Metrics.prototype.getNumUidsMap = function(opt_noLazyCreate) { + return /** @type {!jspb.Map} */ ( + jspb.Message.getMapField(this, 1, opt_noLazyCreate, + null)); +}; + + +/** + * Clears values from the map. The map will be non-null. + * @return {!proto.api.Metrics} returns this + */ +proto.api.Metrics.prototype.clearNumUidsMap = function() { + this.getNumUidsMap().clear(); + return this;}; + + /** * List of repeated fields within this message type. diff --git a/protos/api.proto b/protos/api.proto index 03f33ab..c04125b 100644 --- a/protos/api.proto +++ b/protos/api.proto @@ -23,6 +23,13 @@ syntax = "proto3"; package api; +/* import "gogoproto/gogo.proto"; */ + +/* option (gogoproto.marshaler_all) = true; */ +/* option (gogoproto.sizer_all) = true; */ +/* option (gogoproto.unmarshaler_all) = true; */ +/* option (gogoproto.goproto_getters_all) = true; */ + option java_package = "io.dgraph"; option java_outer_classname = "DgraphProto"; @@ -47,10 +54,18 @@ message Request { bool commit_now = 13; } +message Uids { + repeated string uids = 1; +} + message Response { bytes json = 1; TxnContext txn = 2; Latency latency = 3; + // Metrics contains all metrics related to the query. + Metrics metrics = 4; + // uids contains a mapping of blank_node => uid for the node. It only returns uids + // that were created as part of a mutation. map uids = 12; } @@ -112,6 +127,12 @@ message Latency { uint64 processing_ns = 2; uint64 encoding_ns = 3; uint64 assign_timestamp_ns = 4; + uint64 total_ns = 5; +} + +message Metrics { + // num_uids is the map of number of uids processed by each attribute. + map num_uids = 1; } message NQuad { diff --git a/tests/integration/doRequest.spec.ts b/tests/integration/doRequest.spec.ts index cff99e9..13c9746 100644 --- a/tests/integration/doRequest.spec.ts +++ b/tests/integration/doRequest.spec.ts @@ -46,7 +46,7 @@ describe("doRequest", () => { expect(res.getJson()).toEqual({ me: [{ name: "ok 200" }, { name: "ok 300" }, { name: "ok 400" }] }); }); - it("fails with two mutations since multiple mutations are supported yet", async () => { + it("performs two mutations and then query finishes successfully", async () => { const client = await setup(); await setSchema(client, ` name: string @index(fulltext) . @@ -60,10 +60,12 @@ describe("doRequest", () => { const req = new dgraph.Request(); req.setMutationsList([mu1, mu2]); req.setCommitNow(true); + const resp = client.newTxn().doRequest(req); + await expect(resp).resolves.toBeDefined(); - const res = client.newTxn().doRequest(req); - const ONLY_ONE_MUTATION_SUPPORTED = new Error(`${UNKNOWN_CODE}: Only 1 mutation per request is supported`); - await expect(res).rejects.toEqual(ONLY_ONE_MUTATION_SUPPORTED); + const query = `{ me(func: has(name), orderasc: name) { name }}`; + const res = await client.newTxn().query(query); + expect(res.getJson()).toEqual({ me: [{ name: "ok 200" }, { name: "ok 300" }] }); }); it("fails with zero mutations since either a mutation or a query is required", async () => {