Skip to content

Commit a832a40

Browse files
authored
Merge pull request #23 from roboflow/security/merge-upstream-and-deploy-new-npm-package
Security/merge upstream and deploy new npm package
2 parents 0040d08 + 75fb587 commit a832a40

15 files changed

+8300
-4160
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
node_modules
22
/lib
3+
src/*.js
4+
src/*.d.ts
5+
src/*.js.map
6+
!src/tensorFlowRecordsProtoBuf_pb.js

.npmignore

Whitespace-only changes.

package-lock.json

Lines changed: 8228 additions & 4089 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
{
22
"name": "@roboflow/tfrecords",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "TensorFlow record (.tfrecord) API for Node.JS and Browsers",
55
"main": "src/tensorFlowBuilder.js",
66
"dependencies": {
77
"buffer-reverse": "^1.0.1",
8-
"crypto-js": "^3.1.9-1",
9-
"google-protobuf": "^3.6.1",
8+
"google-protobuf": "3.21.2",
109
"node-int64": "^0.4.0",
1110
"shortid": "^2.2.14"
1211
},
1312
"types": "src/index.d.ts",
1413
"scripts": {
1514
"test": "jest --config jestconfig.json",
16-
"build": "tsc",
15+
"build": "tsc --project tsconfig.build.json",
1716
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
1817
"lint": "tslint -p tsconfig.json",
1918
"prepare": "npm run build",
@@ -37,14 +36,14 @@
3736
},
3837
"homepage": "https://github.com/JacopoMangiavacchi/TFRecords#readme",
3938
"devDependencies": {
40-
"@types/node": "^10.12.7",
41-
"@types/jest": "^24.0.23",
42-
"jest": "^24.9.0",
39+
"@types/jest": "^29.5.12",
40+
"@types/node": "^20.12.7",
41+
"jest": "^29.7.0",
4342
"prettier": "^1.16.4",
44-
"ts-jest": "^24.2.0",
43+
"ts-jest": "29.1.2",
4544
"tslint": "^5.12.1",
4645
"tslint-config-prettier": "^1.18.0",
47-
"typescript": "^3.3.3"
46+
"typescript": "^5.4.5"
4847
},
4948
"publishConfig": {
5049
"registry": "https://registry.npmjs.org"

src/guard.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ class Guard {
77
* @param paramName - The name of the parameter to validate
88
* @param message - The error message to return on invalid value
99
*/
10-
static emtpy(value, paramName, message) {
11-
if ((!!value === false || value.trim().length === 0)) {
10+
static empty(value, paramName, message) {
11+
if (value === null || !value || value.trim().length === 0) {
1212
message = message || (`'${paramName || "value"}' cannot be null or empty`);
1313
throw new Error(message);
1414
}
@@ -20,7 +20,7 @@ class Guard {
2020
* @param message - The error message to return on invalid value
2121
*/
2222
static null(value, paramName, message) {
23-
if ((!!value === false)) {
23+
if (!value) {
2424
message = message || (`'${paramName || "value"}' cannot be null or undefined`);
2525
throw new Error(message);
2626
}
@@ -33,7 +33,7 @@ class Guard {
3333
* @param message - The error message to return on invalid value
3434
*/
3535
static expression(value, predicate, paramName, message) {
36-
if (!!value === false || !predicate(value)) {
36+
if (!value || !predicate(value)) {
3737
message = message || (`'${paramName || "value"}' is not a valid value`);
3838
throw new Error(message);
3939
}

src/guard.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
66
const guard_1 = __importDefault(require("./guard"));
77
describe("Guard", () => {
88
function methodWithRequiredName(name) {
9-
guard_1.default.emtpy(name);
9+
guard_1.default.empty(name);
1010
}
1111
function methodWithRequiredNameWithParam(name) {
12-
guard_1.default.emtpy(name, "name", "Name is required");
12+
guard_1.default.empty(name, "name", "Name is required");
1313
}
1414
function methodWithRequiredObject(options) {
1515
guard_1.default.null(options);

src/guard.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import Guard from "./guard";
22

33
describe("Guard", () => {
4-
function methodWithRequiredName(name: string) {
5-
Guard.emtpy(name);
4+
function methodWithRequiredName(name: string | null) {
5+
Guard.empty(name);
66
}
77

8-
function methodWithRequiredNameWithParam(name: string) {
9-
Guard.emtpy(name, "name", "Name is required");
8+
function methodWithRequiredNameWithParam(name: string | null) {
9+
Guard.empty(name, "name", "Name is required");
1010
}
1111

1212
function methodWithRequiredObject(options: any) {

src/guard.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ export default class Guard {
55
* @param paramName - The name of the parameter to validate
66
* @param message - The error message to return on invalid value
77
*/
8-
public static emtpy(value: string, paramName?: string, message?: string) {
9-
if ((!!value === false || value.trim().length === 0)) {
8+
public static empty(value: string | null, paramName?: string, message?: string) {
9+
if (value === null || !value || value.trim().length === 0) {
1010
message = message || (`'${paramName || "value"}' cannot be null or empty`);
1111
throw new Error(message);
1212
}
@@ -19,7 +19,7 @@ export default class Guard {
1919
* @param message - The error message to return on invalid value
2020
*/
2121
public static null(value: any, paramName?: string, message?: string) {
22-
if ((!!value === false)) {
22+
if (!value) {
2323
message = message || (`'${paramName || "value"}' cannot be null or undefined`);
2424
throw new Error(message);
2525
}
@@ -33,7 +33,7 @@ export default class Guard {
3333
* @param message - The error message to return on invalid value
3434
*/
3535
public static expression<T>(value: T, predicate: (value: T) => boolean, paramName?: string, message?: string) {
36-
if (!!value === false || !predicate(value)) {
36+
if (!value || !predicate(value)) {
3737
message = message || (`'${paramName || "value"}' is not a valid value`);
3838
throw new Error(message);
3939
}

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { FeatureType, TFRecordsBuilder } from "./tensorFlowBuilder";
2+
export { TFRecordsReader } from "./tensorFlowReader";

src/tensorFlowBuilder.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.TFRecordsBuilder = exports.FeatureType = void 0;
34
const tensorFlowRecordsProtoBuf_pb_1 = require("./tensorFlowRecordsProtoBuf_pb");
45
const tensorFlowHelpers_1 = require("./tensorFlowHelpers");
56
const stream_1 = require("stream");
@@ -17,15 +18,12 @@ var FeatureType;
1718
FeatureType[FeatureType["Binary"] = 1] = "Binary";
1819
FeatureType[FeatureType["Int64"] = 2] = "Int64";
1920
FeatureType[FeatureType["Float"] = 3] = "Float";
20-
})(FeatureType = exports.FeatureType || (exports.FeatureType = {}));
21+
})(FeatureType || (exports.FeatureType = FeatureType = {}));
2122
/**
2223
* @name - TFRecords Builder Class
2324
* @description - Create a TFRecords object
2425
*/
2526
class TFRecordsBuilder {
26-
constructor() {
27-
this.features = new tensorFlowRecordsProtoBuf_pb_1.Features();
28-
}
2927
/**
3028
* @records - An Array of TFRecord Buffer created with releaseTFRecord()
3129
* @description - Return a Buffer representation of a TFRecords object
@@ -34,9 +32,9 @@ class TFRecordsBuilder {
3432
return Buffer.concat(records.map((record) => {
3533
const length = record.length;
3634
// Get TFRecords CRCs for TFRecords Header and Footer
37-
const bufferLength = tensorFlowHelpers_1.getInt64Buffer(length);
38-
const bufferLengthMaskedCRC = tensorFlowHelpers_1.getInt32Buffer(tensorFlowHelpers_1.maskCrc(tensorFlowHelpers_1.crc32c(bufferLength)));
39-
const bufferDataMaskedCRC = tensorFlowHelpers_1.getInt32Buffer(tensorFlowHelpers_1.maskCrc(tensorFlowHelpers_1.crc32c(record)));
35+
const bufferLength = (0, tensorFlowHelpers_1.getInt64Buffer)(length);
36+
const bufferLengthMaskedCRC = (0, tensorFlowHelpers_1.getInt32Buffer)((0, tensorFlowHelpers_1.maskCrc)((0, tensorFlowHelpers_1.crc32c)(bufferLength)));
37+
const bufferDataMaskedCRC = (0, tensorFlowHelpers_1.getInt32Buffer)((0, tensorFlowHelpers_1.maskCrc)((0, tensorFlowHelpers_1.crc32c)(record)));
4038
// Concatenate all TFRecords Header, Data and Footer buffer
4139
return Buffer.concat([bufferLength,
4240
bufferLengthMaskedCRC,
@@ -58,14 +56,17 @@ class TFRecordsBuilder {
5856
transform: (record, encoding, callback) => {
5957
const length = record.length;
6058
// Get TFRecords CRCs for TFRecords Header and Footer
61-
const bufferLength = tensorFlowHelpers_1.getInt64Buffer(length);
62-
const bufferLengthMaskedCRC = tensorFlowHelpers_1.getInt32Buffer(tensorFlowHelpers_1.maskCrc(tensorFlowHelpers_1.crc32c(bufferLength)));
63-
const bufferDataMaskedCRC = tensorFlowHelpers_1.getInt32Buffer(tensorFlowHelpers_1.maskCrc(tensorFlowHelpers_1.crc32c(record)));
59+
const bufferLength = (0, tensorFlowHelpers_1.getInt64Buffer)(length);
60+
const bufferLengthMaskedCRC = (0, tensorFlowHelpers_1.getInt32Buffer)((0, tensorFlowHelpers_1.maskCrc)((0, tensorFlowHelpers_1.crc32c)(bufferLength)));
61+
const bufferDataMaskedCRC = (0, tensorFlowHelpers_1.getInt32Buffer)((0, tensorFlowHelpers_1.maskCrc)((0, tensorFlowHelpers_1.crc32c)(record)));
6462
callback(undefined, Buffer.concat([bufferLength, bufferLengthMaskedCRC, record, bufferDataMaskedCRC]));
6563
},
6664
highWaterMark,
6765
});
6866
}
67+
constructor() {
68+
this.features = new tensorFlowRecordsProtoBuf_pb_1.Features();
69+
}
6970
/**
7071
* @key - Feature Key
7172
* @type - Feature Type
@@ -87,7 +88,7 @@ class TFRecordsBuilder {
8788
case FeatureType.String:
8889
const stringList = new tensorFlowRecordsProtoBuf_pb_1.BytesList();
8990
values.forEach((value) => {
90-
stringList.addValue(tensorFlowHelpers_1.textEncode(value));
91+
stringList.addValue((0, tensorFlowHelpers_1.textEncode)(value));
9192
});
9293
feature.setBytesList(stringList);
9394
break;

0 commit comments

Comments
 (0)