From b9601bcc7df13f59d7b8089aad037b70b88d6f80 Mon Sep 17 00:00:00 2001 From: Philippe Ozil Date: Mon, 13 Nov 2023 17:41:50 +0100 Subject: [PATCH] build: release v3.2.1 --- dist/client.cjs | 34 ++++++++++++++++++++++++++++++++-- dist/client.d.ts | 19 ------------------- dist/client.d.ts.map | 2 +- dist/client.js | 34 ++++++++++++++++++++++++++++++++-- package.json | 2 +- 5 files changed, 66 insertions(+), 25 deletions(-) diff --git a/dist/client.cjs b/dist/client.cjs index 9536a6f..066f53a 100644 --- a/dist/client.cjs +++ b/dist/client.cjs @@ -477,6 +477,33 @@ function base64url(input) { } // src/client.js +var CUSTOM_LONG_AVRO_TYPE = import_avro_js2.default.types.LongType.using({ + fromBuffer: (buf) => { + const big = buf.readBigInt64LE(); + if (big > Number.MAX_SAFE_INTEGER) { + return big; + } + return Number(BigInt.asIntN(64, big)); + }, + toBuffer: (n) => { + const buf = Buffer.alloc(8); + if (n instanceof BigInt) { + buf.writeBigInt64LE(n); + } else { + buf.writeBigInt64LE(BigInt(n)); + } + return buf; + }, + fromJSON: BigInt, + toJSON: Number, + isValid: (n) => { + const type = typeof n; + return type === "bigint" || type === "number"; + }, + compare: (n1, n2) => { + return n1 === n2 ? 0 : n1 < n2 ? -1 : 1; + } +}); var PubSubApiClient = class { /** * gRPC client @@ -688,7 +715,7 @@ var PubSubApiClient = class { replayId = decodeReplayId(event.replayId); } catch (error2) { } - const message = replayId ? `Failed to parse event with replay ID ${this.replayId}` : `Failed to parse event with unknown replay ID (latest replay ID was ${latestReplayId})`; + const message = replayId ? `Failed to parse event with replay ID ${replayId}` : `Failed to parse event with unknown replay ID (latest replay ID was ${latestReplayId})`; const parseError = new EventParseError( message, error, @@ -697,6 +724,7 @@ var PubSubApiClient = class { latestReplayId ); eventEmitter.emit("error", parseError); + this.#logger.error(parseError); } if (eventEmitter.getReceivedEventCount() === eventEmitter.getRequestedEventCount()) { eventEmitter.emit("lastevent"); @@ -825,7 +853,9 @@ var PubSubApiClient = class { if (schemaError) { reject(schemaError); } else { - const schemaType = import_avro_js2.default.parse(res.schemaJson); + const schemaType = import_avro_js2.default.parse(res.schemaJson, { + registry: { long: CUSTOM_LONG_AVRO_TYPE } + }); this.#logger.info( `Topic schema loaded: ${topicName}` ); diff --git a/dist/client.d.ts b/dist/client.d.ts index 8ef201c..8c9f53d 100644 --- a/dist/client.d.ts +++ b/dist/client.d.ts @@ -1,22 +1,3 @@ -/** - * @typedef {Object} PublishResult - * @property {number} replayId - * @property {string} correlationKey - * @global - */ -/** - * @typedef {Object} Schema - * @property {string} id - * @property {Object} type - * @protected - */ -/** - * @typedef {Object} Logger - * @property {Function} debug - * @property {Function} info - * @property {Function} error - * @protected - */ /** * Client for the Salesforce Pub/Sub API * @alias PubSubApiClient diff --git a/dist/client.d.ts.map b/dist/client.d.ts.map index 25f9306..1e1846e 100644 --- a/dist/client.d.ts.map +++ b/dist/client.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.js"],"names":[],"mappings":"AAmBA;;;;;GAKG;AAEH;;;;;GAKG;AAEH;;;;;;GAMG;AAEH;;;;GAIG;AACH;IAeI;;;OAGG;IACH,qBAFW,MAAM,EAchB;IAED;;;;OAIG;IACH,WAHa,QAAQ,IAAI,CAAC,CAuBzB;IAED;;;;;;;OAOG;IACH,6BANW,MAAM,eACN,MAAM,mBACN,MAAM,GACJ,QAAQ,IAAI,CAAC,CAmCzB;IAmDD;;;;;;OAMG;IACH,sCALW,MAAM,gBACN,MAAM,GACJ,qBAAqB,CASjC;IAED;;;;;;;OAOG;IACH,iCANW,MAAM,gBACN,MAAM,YACN,MAAM,GACJ,qBAAqB,CAUjC;IAED;;;;;;OAMG;IACH,qBALW,MAAM,gBACN,MAAM,GACJ,qBAAqB,CAQjC;IAoGD;;;;;;;OAOG;IACH,mBANW,MAAM,iCAEN,MAAM,GACJ,QAAQ,aAAa,CAAC,CAwClC;IAED;;;OAGG;IACH,cAGC;;CAuDJ;;cA7aa,MAAM;oBACN,MAAM;;;QAMN,MAAM"} \ No newline at end of file +{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.js"],"names":[],"mappings":"AA0EA;;;;GAIG;AACH;IAeI;;;OAGG;IACH,qBAFW,MAAM,EAchB;IAED;;;;OAIG;IACH,WAHa,QAAQ,IAAI,CAAC,CAuBzB;IAED;;;;;;;OAOG;IACH,6BANW,MAAM,eACN,MAAM,mBACN,MAAM,GACJ,QAAQ,IAAI,CAAC,CAmCzB;IAmDD;;;;;;OAMG;IACH,sCALW,MAAM,gBACN,MAAM,GACJ,qBAAqB,CASjC;IAED;;;;;;;OAOG;IACH,iCANW,MAAM,gBACN,MAAM,YACN,MAAM,GACJ,qBAAqB,CAUjC;IAED;;;;;;OAMG;IACH,qBALW,MAAM,gBACN,MAAM,GACJ,qBAAqB,CAQjC;IAqGD;;;;;;;OAOG;IACH,mBANW,MAAM,iCAEN,MAAM,GACJ,QAAQ,aAAa,CAAC,CAwClC;IAED;;;OAGG;IACH,cAGC;;CAyDJ;;cAjda,MAAM;oBACN,MAAM;;;QAMN,MAAM"} \ No newline at end of file diff --git a/dist/client.js b/dist/client.js index 40d0637..8aebeb6 100644 --- a/dist/client.js +++ b/dist/client.js @@ -444,6 +444,33 @@ function base64url(input) { } // src/client.js +var CUSTOM_LONG_AVRO_TYPE = avro2.types.LongType.using({ + fromBuffer: (buf) => { + const big = buf.readBigInt64LE(); + if (big > Number.MAX_SAFE_INTEGER) { + return big; + } + return Number(BigInt.asIntN(64, big)); + }, + toBuffer: (n) => { + const buf = Buffer.alloc(8); + if (n instanceof BigInt) { + buf.writeBigInt64LE(n); + } else { + buf.writeBigInt64LE(BigInt(n)); + } + return buf; + }, + fromJSON: BigInt, + toJSON: Number, + isValid: (n) => { + const type = typeof n; + return type === "bigint" || type === "number"; + }, + compare: (n1, n2) => { + return n1 === n2 ? 0 : n1 < n2 ? -1 : 1; + } +}); var PubSubApiClient = class { /** * gRPC client @@ -655,7 +682,7 @@ var PubSubApiClient = class { replayId = decodeReplayId(event.replayId); } catch (error2) { } - const message = replayId ? `Failed to parse event with replay ID ${this.replayId}` : `Failed to parse event with unknown replay ID (latest replay ID was ${latestReplayId})`; + const message = replayId ? `Failed to parse event with replay ID ${replayId}` : `Failed to parse event with unknown replay ID (latest replay ID was ${latestReplayId})`; const parseError = new EventParseError( message, error, @@ -664,6 +691,7 @@ var PubSubApiClient = class { latestReplayId ); eventEmitter.emit("error", parseError); + this.#logger.error(parseError); } if (eventEmitter.getReceivedEventCount() === eventEmitter.getRequestedEventCount()) { eventEmitter.emit("lastevent"); @@ -792,7 +820,9 @@ var PubSubApiClient = class { if (schemaError) { reject(schemaError); } else { - const schemaType = avro2.parse(res.schemaJson); + const schemaType = avro2.parse(res.schemaJson, { + registry: { long: CUSTOM_LONG_AVRO_TYPE } + }); this.#logger.info( `Topic schema loaded: ${topicName}` ); diff --git a/package.json b/package.json index 719087a..c4cbf26 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salesforce-pubsub-api-client", - "version": "3.2.0", + "version": "3.2.1", "type": "module", "description": "A node client for the Salesforce Pub/Sub API", "author": "pozil",