@teambit/objects 0.0.711 → 0.0.713
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/models/source.js +3 -0
- package/dist/models/source.js.map +1 -1
- package/dist/models/source.spec.d.ts +1 -0
- package/dist/models/source.spec.js +41 -0
- package/dist/models/source.spec.js.map +1 -0
- package/models/source.spec.ts +13 -0
- package/models/source.ts +3 -0
- package/package.json +12 -12
- /package/dist/{preview-1791474723254.js → preview-1791590494285.js} +0 -0
package/dist/models/source.js
CHANGED
|
@@ -31,6 +31,9 @@ class Source extends _objects().BitObject {
|
|
|
31
31
|
return this.contents.toString();
|
|
32
32
|
}
|
|
33
33
|
static parse(contents) {
|
|
34
|
+
// zlib returns small results as a slice of a bigger (16KB) buffer. unlike other objects, which are parsed and dropped,
|
|
35
|
+
// a Source keeps these bytes, often for long (e.g. as a component file), so it copies them instead of pinning 16KB.
|
|
36
|
+
if (contents.byteLength < contents.buffer.byteLength / 2) contents = Buffer.from(contents);
|
|
34
37
|
return new Source(contents);
|
|
35
38
|
}
|
|
36
39
|
static from(buffer) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_objects","data","require","_defineProperty","e","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","Source","BitObject","constructor","contents","id","toBuffer","toString","parse","
|
|
1
|
+
{"version":3,"names":["_objects","data","require","_defineProperty","e","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","Source","BitObject","constructor","contents","id","toBuffer","toString","parse","byteLength","buffer","Buffer","from","exports","default"],"sources":["source.ts"],"sourcesContent":["import { BitObject } from '../objects';\n\n// TODO: fix .parse\nexport default class Source extends BitObject {\n contents: Buffer;\n\n constructor(contents: Buffer) {\n super();\n this.contents = contents;\n }\n\n id() {\n return this.contents;\n }\n\n toBuffer() {\n return this.contents;\n }\n\n toString() {\n return this.contents.toString();\n }\n\n static parse(contents: Buffer): Source {\n // zlib returns small results as a slice of a bigger (16KB) buffer. unlike other objects, which are parsed and dropped,\n // a Source keeps these bytes, often for long (e.g. as a component file), so it copies them instead of pinning 16KB.\n if (contents.byteLength < contents.buffer.byteLength / 2) contents = Buffer.from(contents);\n return new Source(contents);\n }\n\n static from(buffer: Buffer): Source {\n return new Source(buffer);\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,QAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAAuC,SAAAE,gBAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,YAAAD,CAAA,GAAAE,cAAA,CAAAF,CAAA,MAAAD,CAAA,GAAAI,MAAA,CAAAC,cAAA,CAAAL,CAAA,EAAAC,CAAA,IAAAK,KAAA,EAAAJ,CAAA,EAAAK,UAAA,MAAAC,YAAA,MAAAC,QAAA,UAAAT,CAAA,CAAAC,CAAA,IAAAC,CAAA,EAAAF,CAAA;AAAA,SAAAG,eAAAD,CAAA,QAAAQ,CAAA,GAAAC,YAAA,CAAAT,CAAA,uCAAAQ,CAAA,GAAAA,CAAA,GAAAA,CAAA;AAAA,SAAAC,aAAAT,CAAA,EAAAD,CAAA,2BAAAC,CAAA,KAAAA,CAAA,SAAAA,CAAA,MAAAF,CAAA,GAAAE,CAAA,CAAAU,MAAA,CAAAC,WAAA,kBAAAb,CAAA,QAAAU,CAAA,GAAAV,CAAA,CAAAc,IAAA,CAAAZ,CAAA,EAAAD,CAAA,uCAAAS,CAAA,SAAAA,CAAA,YAAAK,SAAA,yEAAAd,CAAA,GAAAe,MAAA,GAAAC,MAAA,EAAAf,CAAA;AAEvC;AACe,MAAMgB,MAAM,SAASC,oBAAS,CAAC;EAG5CC,WAAWA,CAACC,QAAgB,EAAE;IAC5B,KAAK,CAAC,CAAC;IAACtB,eAAA;IACR,IAAI,CAACsB,QAAQ,GAAGA,QAAQ;EAC1B;EAEAC,EAAEA,CAAA,EAAG;IACH,OAAO,IAAI,CAACD,QAAQ;EACtB;EAEAE,QAAQA,CAAA,EAAG;IACT,OAAO,IAAI,CAACF,QAAQ;EACtB;EAEAG,QAAQA,CAAA,EAAG;IACT,OAAO,IAAI,CAACH,QAAQ,CAACG,QAAQ,CAAC,CAAC;EACjC;EAEA,OAAOC,KAAKA,CAACJ,QAAgB,EAAU;IACrC;IACA;IACA,IAAIA,QAAQ,CAACK,UAAU,GAAGL,QAAQ,CAACM,MAAM,CAACD,UAAU,GAAG,CAAC,EAAEL,QAAQ,GAAGO,MAAM,CAACC,IAAI,CAACR,QAAQ,CAAC;IAC1F,OAAO,IAAIH,MAAM,CAACG,QAAQ,CAAC;EAC7B;EAEA,OAAOQ,IAAIA,CAACF,MAAc,EAAU;IAClC,OAAO,IAAIT,MAAM,CAACS,MAAM,CAAC;EAC3B;AACF;AAACG,OAAA,CAAAC,OAAA,GAAAb,MAAA","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _chai() {
|
|
4
|
+
const data = require("chai");
|
|
5
|
+
_chai = function () {
|
|
6
|
+
return data;
|
|
7
|
+
};
|
|
8
|
+
return data;
|
|
9
|
+
}
|
|
10
|
+
function _zlib() {
|
|
11
|
+
const data = require("zlib");
|
|
12
|
+
_zlib = function () {
|
|
13
|
+
return data;
|
|
14
|
+
};
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
function _objects() {
|
|
18
|
+
const data = require("../objects");
|
|
19
|
+
_objects = function () {
|
|
20
|
+
return data;
|
|
21
|
+
};
|
|
22
|
+
return data;
|
|
23
|
+
}
|
|
24
|
+
function _source() {
|
|
25
|
+
const data = _interopRequireDefault(require("./source"));
|
|
26
|
+
_source = function () {
|
|
27
|
+
return data;
|
|
28
|
+
};
|
|
29
|
+
return data;
|
|
30
|
+
}
|
|
31
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
32
|
+
describe('Source', () => {
|
|
33
|
+
it('should not keep the whole inflated buffer when the file is small', async () => {
|
|
34
|
+
const file = _source().default.from(Buffer.from('const a = 1;'));
|
|
35
|
+
const parsed = await _objects().BitObject.parseObject((0, _zlib().deflateSync)(file.serialize()));
|
|
36
|
+
(0, _chai().expect)(parsed.contents.toString()).to.equal('const a = 1;');
|
|
37
|
+
(0, _chai().expect)(parsed.contents.buffer.byteLength).to.be.below(16 * 1024);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=source.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_chai","data","require","_zlib","_objects","_source","_interopRequireDefault","e","__esModule","default","describe","it","file","Source","from","Buffer","parsed","BitObject","parseObject","deflateSync","serialize","expect","contents","toString","to","equal","buffer","byteLength","be","below"],"sources":["source.spec.ts"],"sourcesContent":["import { expect } from 'chai';\nimport { deflateSync } from 'zlib';\nimport { BitObject } from '../objects';\nimport Source from './source';\n\ndescribe('Source', () => {\n it('should not keep the whole inflated buffer when the file is small', async () => {\n const file = Source.from(Buffer.from('const a = 1;'));\n const parsed = (await BitObject.parseObject(deflateSync(file.serialize()))) as Source;\n expect(parsed.contents.toString()).to.equal('const a = 1;');\n expect(parsed.contents.buffer.byteLength).to.be.below(16 * 1024);\n });\n});\n"],"mappings":";;AAAA,SAAAA,MAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,KAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,MAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,KAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,SAAA;EAAA,MAAAH,IAAA,GAAAC,OAAA;EAAAE,QAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,QAAA;EAAA,MAAAJ,IAAA,GAAAK,sBAAA,CAAAJ,OAAA;EAAAG,OAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA8B,SAAAK,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAE9BG,QAAQ,CAAC,QAAQ,EAAE,MAAM;EACvBC,EAAE,CAAC,kEAAkE,EAAE,YAAY;IACjF,MAAMC,IAAI,GAAGC,iBAAM,CAACC,IAAI,CAACC,MAAM,CAACD,IAAI,CAAC,cAAc,CAAC,CAAC;IACrD,MAAME,MAAM,GAAI,MAAMC,oBAAS,CAACC,WAAW,CAAC,IAAAC,mBAAW,EAACP,IAAI,CAACQ,SAAS,CAAC,CAAC,CAAC,CAAY;IACrF,IAAAC,cAAM,EAACL,MAAM,CAACM,QAAQ,CAACC,QAAQ,CAAC,CAAC,CAAC,CAACC,EAAE,CAACC,KAAK,CAAC,cAAc,CAAC;IAC3D,IAAAJ,cAAM,EAACL,MAAM,CAACM,QAAQ,CAACI,MAAM,CAACC,UAAU,CAAC,CAACH,EAAE,CAACI,EAAE,CAACC,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC;EAClE,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
import { deflateSync } from 'zlib';
|
|
3
|
+
import { BitObject } from '../objects';
|
|
4
|
+
import Source from './source';
|
|
5
|
+
|
|
6
|
+
describe('Source', () => {
|
|
7
|
+
it('should not keep the whole inflated buffer when the file is small', async () => {
|
|
8
|
+
const file = Source.from(Buffer.from('const a = 1;'));
|
|
9
|
+
const parsed = (await BitObject.parseObject(deflateSync(file.serialize()))) as Source;
|
|
10
|
+
expect(parsed.contents.toString()).to.equal('const a = 1;');
|
|
11
|
+
expect(parsed.contents.buffer.byteLength).to.be.below(16 * 1024);
|
|
12
|
+
});
|
|
13
|
+
});
|
package/models/source.ts
CHANGED
|
@@ -22,6 +22,9 @@ export default class Source extends BitObject {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
static parse(contents: Buffer): Source {
|
|
25
|
+
// zlib returns small results as a slice of a bigger (16KB) buffer. unlike other objects, which are parsed and dropped,
|
|
26
|
+
// a Source keeps these bytes, often for long (e.g. as a component file), so it copies them instead of pinning 16KB.
|
|
27
|
+
if (contents.byteLength < contents.buffer.byteLength / 2) contents = Buffer.from(contents);
|
|
25
28
|
return new Source(contents);
|
|
26
29
|
}
|
|
27
30
|
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/objects",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.713",
|
|
4
4
|
"homepage": "https://bit.cloud/teambit/scope/objects",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.scope",
|
|
8
8
|
"name": "objects",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.713"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@pnpm/lockfile.types": "1100.0.19",
|
|
@@ -22,32 +22,32 @@
|
|
|
22
22
|
"@teambit/harmony.modules.runtimes": "0.0.4",
|
|
23
23
|
"@teambit/component-id": "1.2.5",
|
|
24
24
|
"@teambit/legacy.utils": "0.0.56",
|
|
25
|
+
"@teambit/harmony.modules.get-basic-log": "0.0.182",
|
|
25
26
|
"@teambit/bit-error": "0.0.404",
|
|
26
27
|
"@teambit/component-version": "1.0.4",
|
|
28
|
+
"@teambit/component.snap-distance": "0.0.182",
|
|
29
|
+
"@teambit/config-store": "0.0.293",
|
|
27
30
|
"@teambit/lane-id": "0.0.312",
|
|
28
31
|
"@teambit/legacy.cli.error": "0.0.67",
|
|
29
32
|
"@teambit/legacy.constants": "0.0.49",
|
|
30
33
|
"@teambit/legacy.logger": "0.0.67",
|
|
34
|
+
"@teambit/legacy.scope": "0.0.181",
|
|
31
35
|
"@teambit/toolbox.crypto.sha1": "0.0.24",
|
|
36
|
+
"@teambit/component.sources": "0.0.233",
|
|
32
37
|
"@teambit/harmony.modules.concurrency": "0.0.50",
|
|
33
38
|
"@teambit/legacy-bit-id": "1.1.4",
|
|
34
39
|
"@teambit/legacy-component-log": "0.0.434",
|
|
40
|
+
"@teambit/legacy.consumer-component": "0.0.182",
|
|
41
|
+
"@teambit/legacy.consumer-config": "0.0.181",
|
|
42
|
+
"@teambit/legacy.extension-data": "0.0.183",
|
|
35
43
|
"@teambit/pkg.modules.semver-helper": "0.0.38",
|
|
36
44
|
"@teambit/toolbox.array.duplications-finder": "0.0.19",
|
|
37
45
|
"@teambit/toolbox.promise.map-pool": "0.0.24",
|
|
38
46
|
"@teambit/graph.cleargraph": "0.0.11",
|
|
39
47
|
"@teambit/bit.get-bit-version": "0.0.31",
|
|
48
|
+
"@teambit/semantics.doc-parser": "0.0.189",
|
|
40
49
|
"@teambit/harmony.modules.in-memory-cache": "0.0.54",
|
|
41
|
-
"@teambit/toolbox.fs.remove-empty-dir": "0.0.22"
|
|
42
|
-
"@teambit/harmony.modules.get-basic-log": "0.0.181",
|
|
43
|
-
"@teambit/component.snap-distance": "0.0.181",
|
|
44
|
-
"@teambit/config-store": "0.0.292",
|
|
45
|
-
"@teambit/legacy.scope": "0.0.180",
|
|
46
|
-
"@teambit/component.sources": "0.0.232",
|
|
47
|
-
"@teambit/legacy.consumer-component": "0.0.181",
|
|
48
|
-
"@teambit/legacy.consumer-config": "0.0.180",
|
|
49
|
-
"@teambit/legacy.extension-data": "0.0.182",
|
|
50
|
-
"@teambit/semantics.doc-parser": "0.0.188"
|
|
50
|
+
"@teambit/toolbox.fs.remove-empty-dir": "0.0.22"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/semver": "7.5.8",
|
|
File without changes
|