@teambit/objects 0.0.19
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/artifacts/__bit_junit.xml +68 -0
- package/artifacts/preview/teambit_scope_objects-preview.js +1 -0
- package/dist/fixtures/version-model-extended.json +48 -0
- package/dist/fixtures/version-model-object.json +87 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +371 -0
- package/dist/index.js.map +1 -0
- package/dist/models/dependencies-graph.d.ts +45 -0
- package/dist/models/dependencies-graph.js +106 -0
- package/dist/models/dependencies-graph.js.map +1 -0
- package/dist/models/detach-heads.d.ts +25 -0
- package/dist/models/detach-heads.js +84 -0
- package/dist/models/detach-heads.js.map +1 -0
- package/dist/models/export-metadata.d.ts +24 -0
- package/dist/models/export-metadata.js +76 -0
- package/dist/models/export-metadata.js.map +1 -0
- package/dist/models/index.d.ts +10 -0
- package/dist/models/index.js +125 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models/lane-history.d.ts +40 -0
- package/dist/models/lane-history.js +117 -0
- package/dist/models/lane-history.js.map +1 -0
- package/dist/models/lane.d.ts +124 -0
- package/dist/models/lane.js +463 -0
- package/dist/models/lane.js.map +1 -0
- package/dist/models/model-component.d.ts +317 -0
- package/dist/models/model-component.js +1365 -0
- package/dist/models/model-component.js.map +1 -0
- package/dist/models/model-component.spec.d.ts +1 -0
- package/dist/models/model-component.spec.js +71 -0
- package/dist/models/model-component.spec.js.map +1 -0
- package/dist/models/scopeMeta.d.ts +20 -0
- package/dist/models/scopeMeta.js +71 -0
- package/dist/models/scopeMeta.js.map +1 -0
- package/dist/models/source.d.ts +10 -0
- package/dist/models/source.js +43 -0
- package/dist/models/source.js.map +1 -0
- package/dist/models/symlink.d.ts +30 -0
- package/dist/models/symlink.js +91 -0
- package/dist/models/symlink.js.map +1 -0
- package/dist/models/version-history.d.ts +59 -0
- package/dist/models/version-history.js +285 -0
- package/dist/models/version-history.js.map +1 -0
- package/dist/models/version.d.ts +279 -0
- package/dist/models/version.js +777 -0
- package/dist/models/version.js.map +1 -0
- package/dist/models/version.spec.d.ts +1 -0
- package/dist/models/version.spec.js +340 -0
- package/dist/models/version.spec.js.map +1 -0
- package/dist/objects/bit-object-list.d.ts +24 -0
- package/dist/objects/bit-object-list.js +65 -0
- package/dist/objects/bit-object-list.js.map +1 -0
- package/dist/objects/index.d.ts +5 -0
- package/dist/objects/index.js +60 -0
- package/dist/objects/index.js.map +1 -0
- package/dist/objects/object-list-to-graph.d.ts +13 -0
- package/dist/objects/object-list-to-graph.js +93 -0
- package/dist/objects/object-list-to-graph.js.map +1 -0
- package/dist/objects/object-list.d.ts +52 -0
- package/dist/objects/object-list.js +369 -0
- package/dist/objects/object-list.js.map +1 -0
- package/dist/objects/object.d.ts +35 -0
- package/dist/objects/object.js +190 -0
- package/dist/objects/object.js.map +1 -0
- package/dist/objects/objects-readable-generator.d.ts +31 -0
- package/dist/objects/objects-readable-generator.js +192 -0
- package/dist/objects/objects-readable-generator.js.map +1 -0
- package/dist/objects/raw-object.d.ts +23 -0
- package/dist/objects/raw-object.js +155 -0
- package/dist/objects/raw-object.js.map +1 -0
- package/dist/objects/ref.d.ts +14 -0
- package/dist/objects/ref.js +45 -0
- package/dist/objects/ref.js.map +1 -0
- package/dist/objects/repository-hooks.d.ts +4 -0
- package/dist/objects/repository-hooks.js +56 -0
- package/dist/objects/repository-hooks.js.map +1 -0
- package/dist/objects/repository.d.ts +148 -0
- package/dist/objects/repository.js +842 -0
- package/dist/objects/repository.js.map +1 -0
- package/dist/objects/scope-index.d.ts +73 -0
- package/dist/objects/scope-index.js +251 -0
- package/dist/objects/scope-index.js.map +1 -0
- package/dist/objects/scope-index.spec.d.ts +1 -0
- package/dist/objects/scope-index.spec.js +152 -0
- package/dist/objects/scope-index.spec.js.map +1 -0
- package/dist/objects.aspect.d.ts +2 -0
- package/dist/objects.aspect.js +18 -0
- package/dist/objects.aspect.js.map +1 -0
- package/dist/objects.main.runtime.d.ts +7 -0
- package/dist/objects.main.runtime.js +36 -0
- package/dist/objects.main.runtime.js.map +1 -0
- package/dist/preview-1736824735631.js +7 -0
- package/fixtures/version-model-extended.json +48 -0
- package/fixtures/version-model-object.json +87 -0
- package/models/dependencies-graph.ts +119 -0
- package/models/detach-heads.ts +79 -0
- package/models/export-metadata.ts +57 -0
- package/models/index.ts +11 -0
- package/models/lane-history.ts +106 -0
- package/models/lane.ts +367 -0
- package/models/model-component.spec.ts +55 -0
- package/models/model-component.ts +1367 -0
- package/models/scopeMeta.ts +60 -0
- package/models/source.ts +32 -0
- package/models/symlink.ts +66 -0
- package/models/version-history.ts +266 -0
- package/models/version.spec.ts +288 -0
- package/models/version.ts +818 -0
- package/objects/bit-object-list.ts +59 -0
- package/objects/index.ts +6 -0
- package/objects/object-list-to-graph.ts +69 -0
- package/objects/object-list.ts +313 -0
- package/objects/object.ts +153 -0
- package/objects/objects-readable-generator.ts +167 -0
- package/objects/raw-object.ts +142 -0
- package/objects/ref.ts +45 -0
- package/objects/repository-hooks.ts +42 -0
- package/objects/repository.ts +753 -0
- package/objects/scope-index.spec.ts +95 -0
- package/objects/scope-index.ts +192 -0
- package/package.json +98 -0
- package/types/asset.d.ts +41 -0
- package/types/style.d.ts +42 -0
@@ -0,0 +1,842 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
function _fsExtra() {
|
8
|
+
const data = _interopRequireDefault(require("fs-extra"));
|
9
|
+
_fsExtra = function () {
|
10
|
+
return data;
|
11
|
+
};
|
12
|
+
return data;
|
13
|
+
}
|
14
|
+
function _uidNumber() {
|
15
|
+
const data = _interopRequireDefault(require("uid-number"));
|
16
|
+
_uidNumber = function () {
|
17
|
+
return data;
|
18
|
+
};
|
19
|
+
return data;
|
20
|
+
}
|
21
|
+
function _asyncMutex() {
|
22
|
+
const data = require("async-mutex");
|
23
|
+
_asyncMutex = function () {
|
24
|
+
return data;
|
25
|
+
};
|
26
|
+
return data;
|
27
|
+
}
|
28
|
+
function _lodash() {
|
29
|
+
const data = require("lodash");
|
30
|
+
_lodash = function () {
|
31
|
+
return data;
|
32
|
+
};
|
33
|
+
return data;
|
34
|
+
}
|
35
|
+
function _bitError() {
|
36
|
+
const data = require("@teambit/bit-error");
|
37
|
+
_bitError = function () {
|
38
|
+
return data;
|
39
|
+
};
|
40
|
+
return data;
|
41
|
+
}
|
42
|
+
function _componentVersion() {
|
43
|
+
const data = require("@teambit/component-version");
|
44
|
+
_componentVersion = function () {
|
45
|
+
return data;
|
46
|
+
};
|
47
|
+
return data;
|
48
|
+
}
|
49
|
+
function path() {
|
50
|
+
const data = _interopRequireWildcard(require("path"));
|
51
|
+
path = function () {
|
52
|
+
return data;
|
53
|
+
};
|
54
|
+
return data;
|
55
|
+
}
|
56
|
+
function _toolboxPromise() {
|
57
|
+
const data = require("@teambit/toolbox.promise.map-pool");
|
58
|
+
_toolboxPromise = function () {
|
59
|
+
return data;
|
60
|
+
};
|
61
|
+
return data;
|
62
|
+
}
|
63
|
+
function _legacy() {
|
64
|
+
const data = require("@teambit/legacy.constants");
|
65
|
+
_legacy = function () {
|
66
|
+
return data;
|
67
|
+
};
|
68
|
+
return data;
|
69
|
+
}
|
70
|
+
function _legacy2() {
|
71
|
+
const data = require("@teambit/legacy.logger");
|
72
|
+
_legacy2 = function () {
|
73
|
+
return data;
|
74
|
+
};
|
75
|
+
return data;
|
76
|
+
}
|
77
|
+
function _legacy3() {
|
78
|
+
const data = require("@teambit/legacy.utils");
|
79
|
+
_legacy3 = function () {
|
80
|
+
return data;
|
81
|
+
};
|
82
|
+
return data;
|
83
|
+
}
|
84
|
+
function _toolboxFs() {
|
85
|
+
const data = require("@teambit/toolbox.fs.remove-empty-dir");
|
86
|
+
_toolboxFs = function () {
|
87
|
+
return data;
|
88
|
+
};
|
89
|
+
return data;
|
90
|
+
}
|
91
|
+
function _harmonyModules() {
|
92
|
+
const data = require("@teambit/harmony.modules.concurrency");
|
93
|
+
_harmonyModules = function () {
|
94
|
+
return data;
|
95
|
+
};
|
96
|
+
return data;
|
97
|
+
}
|
98
|
+
function _legacy4() {
|
99
|
+
const data = require("@teambit/legacy.scope");
|
100
|
+
_legacy4 = function () {
|
101
|
+
return data;
|
102
|
+
};
|
103
|
+
return data;
|
104
|
+
}
|
105
|
+
function _scopeIndex() {
|
106
|
+
const data = require("./scope-index");
|
107
|
+
_scopeIndex = function () {
|
108
|
+
return data;
|
109
|
+
};
|
110
|
+
return data;
|
111
|
+
}
|
112
|
+
function _object() {
|
113
|
+
const data = _interopRequireDefault(require("./object"));
|
114
|
+
_object = function () {
|
115
|
+
return data;
|
116
|
+
};
|
117
|
+
return data;
|
118
|
+
}
|
119
|
+
function _objectList() {
|
120
|
+
const data = require("./object-list");
|
121
|
+
_objectList = function () {
|
122
|
+
return data;
|
123
|
+
};
|
124
|
+
return data;
|
125
|
+
}
|
126
|
+
function _rawObject() {
|
127
|
+
const data = _interopRequireDefault(require("./raw-object"));
|
128
|
+
_rawObject = function () {
|
129
|
+
return data;
|
130
|
+
};
|
131
|
+
return data;
|
132
|
+
}
|
133
|
+
function _ref() {
|
134
|
+
const data = _interopRequireDefault(require("./ref"));
|
135
|
+
_ref = function () {
|
136
|
+
return data;
|
137
|
+
};
|
138
|
+
return data;
|
139
|
+
}
|
140
|
+
function _repositoryHooks() {
|
141
|
+
const data = require("./repository-hooks");
|
142
|
+
_repositoryHooks = function () {
|
143
|
+
return data;
|
144
|
+
};
|
145
|
+
return data;
|
146
|
+
}
|
147
|
+
function _harmonyModules2() {
|
148
|
+
const data = require("@teambit/harmony.modules.in-memory-cache");
|
149
|
+
_harmonyModules2 = function () {
|
150
|
+
return data;
|
151
|
+
};
|
152
|
+
return data;
|
153
|
+
}
|
154
|
+
function _models() {
|
155
|
+
const data = require("../models");
|
156
|
+
_models = function () {
|
157
|
+
return data;
|
158
|
+
};
|
159
|
+
return data;
|
160
|
+
}
|
161
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
162
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
163
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
164
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
165
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
166
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
167
|
+
const OBJECTS_BACKUP_DIR = `${_legacy().OBJECTS_DIR}.bak`;
|
168
|
+
const TRASH_DIR = 'trash';
|
169
|
+
class Repository {
|
170
|
+
constructor(scopePath, scopeJson) {
|
171
|
+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
172
|
+
_defineProperty(this, "objects", {});
|
173
|
+
_defineProperty(this, "objectsToRemove", []);
|
174
|
+
_defineProperty(this, "scopeJson", void 0);
|
175
|
+
_defineProperty(this, "onRead", void 0);
|
176
|
+
_defineProperty(this, "onPersist", void 0);
|
177
|
+
_defineProperty(this, "scopePath", void 0);
|
178
|
+
_defineProperty(this, "scopeIndex", void 0);
|
179
|
+
_defineProperty(this, "cache", void 0);
|
180
|
+
_defineProperty(this, "remoteLanes", void 0);
|
181
|
+
_defineProperty(this, "unmergedComponents", void 0);
|
182
|
+
_defineProperty(this, "persistMutex", new (_asyncMutex().Mutex)());
|
183
|
+
this.scopePath = scopePath;
|
184
|
+
this.scopeJson = scopeJson;
|
185
|
+
this.onRead = (0, _repositoryHooks().onRead)(scopePath, scopeJson);
|
186
|
+
this.onPersist = (0, _repositoryHooks().onPersist)(scopePath, scopeJson);
|
187
|
+
this.cache = (0, _harmonyModules2().createInMemoryCache)({
|
188
|
+
maxSize: (0, _harmonyModules2().getMaxSizeForObjects)()
|
189
|
+
});
|
190
|
+
}
|
191
|
+
static async load({
|
192
|
+
scopePath,
|
193
|
+
scopeJson
|
194
|
+
}) {
|
195
|
+
const repository = new Repository(scopePath, scopeJson);
|
196
|
+
await repository.init();
|
197
|
+
return repository;
|
198
|
+
}
|
199
|
+
async init() {
|
200
|
+
const scopeIndex = await this.loadOptionallyCreateScopeIndex();
|
201
|
+
this.scopeIndex = scopeIndex;
|
202
|
+
this.remoteLanes = new (_legacy4().RemoteLanes)(this.scopePath);
|
203
|
+
this.unmergedComponents = await _legacy4().UnmergedComponents.load(this.scopePath);
|
204
|
+
}
|
205
|
+
static async create({
|
206
|
+
scopePath,
|
207
|
+
scopeJson
|
208
|
+
}) {
|
209
|
+
const repository = new Repository(scopePath, scopeJson);
|
210
|
+
const scopeIndex = _scopeIndex().ScopeIndex.create(scopePath);
|
211
|
+
repository.scopeIndex = scopeIndex;
|
212
|
+
repository.unmergedComponents = await _legacy4().UnmergedComponents.load(scopePath);
|
213
|
+
repository.remoteLanes = new (_legacy4().RemoteLanes)(scopePath);
|
214
|
+
return repository;
|
215
|
+
}
|
216
|
+
static reset(scopePath) {
|
217
|
+
return _scopeIndex().ScopeIndex.reset(scopePath);
|
218
|
+
}
|
219
|
+
static getPathByScopePath(scopePath) {
|
220
|
+
return path().join(scopePath, _legacy().OBJECTS_DIR);
|
221
|
+
}
|
222
|
+
async reLoadScopeIndex() {
|
223
|
+
this.scopeIndex = await this.loadOptionallyCreateScopeIndex();
|
224
|
+
}
|
225
|
+
|
226
|
+
/**
|
227
|
+
* current scope index difference with <scope_folder>/index.json content, reload it
|
228
|
+
* @deprecated use Scope aspect `watchSystemFiles` instead, it's way more efficient.
|
229
|
+
*/
|
230
|
+
async reloadScopeIndexIfNeed(force = false) {
|
231
|
+
const latestScopeIndex = await this.loadOptionallyCreateScopeIndex();
|
232
|
+
if (force) {
|
233
|
+
this.scopeIndex = latestScopeIndex;
|
234
|
+
return;
|
235
|
+
}
|
236
|
+
const currentAllScopeIndexItems = this.scopeIndex.getAll();
|
237
|
+
const latestAllScopeIndexItems = latestScopeIndex.getAll();
|
238
|
+
if (currentAllScopeIndexItems.length !== latestAllScopeIndexItems.length) {
|
239
|
+
this.scopeIndex = latestScopeIndex;
|
240
|
+
return;
|
241
|
+
}
|
242
|
+
if ((0, _lodash().differenceWith)(currentAllScopeIndexItems, latestAllScopeIndexItems, _lodash().isEqual).length) {
|
243
|
+
this.scopeIndex = latestScopeIndex;
|
244
|
+
}
|
245
|
+
}
|
246
|
+
ensureDir() {
|
247
|
+
return _fsExtra().default.ensureDir(this.getPath());
|
248
|
+
}
|
249
|
+
getPath() {
|
250
|
+
return Repository.getPathByScopePath(this.scopePath);
|
251
|
+
}
|
252
|
+
getBackupPath(dirName) {
|
253
|
+
const backupPath = path().join(this.scopePath, OBJECTS_BACKUP_DIR);
|
254
|
+
return dirName ? path().join(backupPath, dirName) : backupPath;
|
255
|
+
}
|
256
|
+
getTrashDir() {
|
257
|
+
return path().join(this.scopePath, TRASH_DIR);
|
258
|
+
}
|
259
|
+
getLicense() {
|
260
|
+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
261
|
+
return this.scopeJson.getPopulatedLicense();
|
262
|
+
}
|
263
|
+
async getScopeMetaObject() {
|
264
|
+
const license = await this.getLicense();
|
265
|
+
const object = _models().ScopeMeta.fromObject({
|
266
|
+
license,
|
267
|
+
name: this.scopeJson.name
|
268
|
+
});
|
269
|
+
return {
|
270
|
+
ref: object.hash(),
|
271
|
+
buffer: await object.compress()
|
272
|
+
};
|
273
|
+
}
|
274
|
+
objectPath(ref) {
|
275
|
+
return path().join(this.getPath(), this.hashPath(ref));
|
276
|
+
}
|
277
|
+
async has(ref) {
|
278
|
+
const objectPath = this.objectPath(ref);
|
279
|
+
return _fsExtra().default.pathExists(objectPath);
|
280
|
+
}
|
281
|
+
async hasMultiple(refs) {
|
282
|
+
const concurrency = (0, _harmonyModules().concurrentIOLimit)();
|
283
|
+
const existingRefs = await (0, _toolboxPromise().pMapPool)(refs, async ref => {
|
284
|
+
const pathExists = await this.has(ref);
|
285
|
+
return pathExists ? ref : null;
|
286
|
+
}, {
|
287
|
+
concurrency
|
288
|
+
});
|
289
|
+
return (0, _lodash().compact)(existingRefs);
|
290
|
+
}
|
291
|
+
async load(ref, throws = false) {
|
292
|
+
// during tag, the updated objects are in `this.objects`.
|
293
|
+
// `this.cache` is less reliable, because if it reaches its max, then it loads from the filesystem, which may not
|
294
|
+
// be there yet (in case of "version" object), or may be out-of-date (in case of "component" object).
|
295
|
+
const inMemoryObjects = this.objects[ref.hash.toString()];
|
296
|
+
if (inMemoryObjects) return inMemoryObjects;
|
297
|
+
if (ref.hash.length < _componentVersion().HASH_SIZE) {
|
298
|
+
ref = await this.getFullRefFromShortHash(ref);
|
299
|
+
}
|
300
|
+
const cached = this.getCache(ref);
|
301
|
+
if (cached) {
|
302
|
+
return cached;
|
303
|
+
}
|
304
|
+
let fileContentsRaw;
|
305
|
+
const objectPath = this.objectPath(ref);
|
306
|
+
try {
|
307
|
+
fileContentsRaw = await _fsExtra().default.readFile(objectPath);
|
308
|
+
} catch (err) {
|
309
|
+
if (err.code !== 'ENOENT') {
|
310
|
+
_legacy2().logger.error(`Failed reading a ref file ${objectPath}. Error: ${err.message}`);
|
311
|
+
throw err;
|
312
|
+
}
|
313
|
+
_legacy2().logger.trace(`Failed finding a ref file ${objectPath}.`);
|
314
|
+
if (throws) {
|
315
|
+
// if we just `throw err` we loose the stack trace.
|
316
|
+
// see https://stackoverflow.com/questions/68022123/no-stack-in-fs-promises-readfile-enoent-error
|
317
|
+
const msg = `fatal: failed finding an object file ${objectPath} in the filesystem at ${err.path}`;
|
318
|
+
throw Object.assign(err, {
|
319
|
+
stack: new Error(msg).stack
|
320
|
+
});
|
321
|
+
}
|
322
|
+
// @ts-ignore @todo: fix! it should return BitObject | null.
|
323
|
+
return null;
|
324
|
+
}
|
325
|
+
const size = fileContentsRaw.byteLength;
|
326
|
+
const fileContents = this.onRead(fileContentsRaw);
|
327
|
+
// uncomment to debug the transformed objects by onRead
|
328
|
+
// console.log('transformedContent load', ref.toString(), BitObject.parseSync(fileContents).getType());
|
329
|
+
const parsedObject = await _object().default.parseObject(fileContents, objectPath);
|
330
|
+
const maxSizeToCache = 100 * 1024; // 100KB
|
331
|
+
if (size < maxSizeToCache) {
|
332
|
+
// don't cache big files (mainly artifacts) to prevent out-of-memory
|
333
|
+
this.setCache(parsedObject);
|
334
|
+
}
|
335
|
+
return parsedObject;
|
336
|
+
}
|
337
|
+
|
338
|
+
/**
|
339
|
+
* this is restricted to provide objects according to the given types. Otherwise, big scopes (>1GB) could crush.
|
340
|
+
* example usage: `this.list([ModelComponent, Symlink, Lane])`
|
341
|
+
*/
|
342
|
+
async list(types) {
|
343
|
+
const refs = await this.listRefs();
|
344
|
+
const concurrency = (0, _harmonyModules().concurrentIOLimit)();
|
345
|
+
_legacy2().logger.debug(`Repository.list, ${refs.length} refs are going to be loaded, searching for types: ${types.map(t => t.name).join(', ')}`);
|
346
|
+
const objects = [];
|
347
|
+
const loadGracefully = process.argv.includes('--never-exported');
|
348
|
+
const isTypeIncluded = obj => types.some(type => type.name === obj.constructor.name); // avoid using "obj instanceof type" for Harmony to call this function successfully
|
349
|
+
await (0, _toolboxPromise().pMapPool)(refs, async ref => {
|
350
|
+
const object = loadGracefully ? await this.loadRefDeleteIfInvalid(ref) : await this.loadRefOnlyIfType(ref, types);
|
351
|
+
if (!object) return;
|
352
|
+
if (loadGracefully && !isTypeIncluded(object)) return;
|
353
|
+
objects.push(object);
|
354
|
+
}, {
|
355
|
+
concurrency,
|
356
|
+
onCompletedChunk: completed => {
|
357
|
+
if (completed % 1000 === 0) _legacy2().logger.debug(`Repository.list, completed ${completed} out of ${refs.length}`);
|
358
|
+
}
|
359
|
+
});
|
360
|
+
return objects;
|
361
|
+
}
|
362
|
+
async loadRefDeleteIfInvalid(ref) {
|
363
|
+
try {
|
364
|
+
return await this.load(ref, true);
|
365
|
+
} catch (err) {
|
366
|
+
// this is needed temporarily to allow `bit reset --never-exported` to fix the bit-id-comp-id error.
|
367
|
+
// in a few months, we can remove this condition (around min 2024)
|
368
|
+
if (err.constructor.name === 'BitIdCompIdError' || err.constructor.name === 'MissingScope') {
|
369
|
+
_legacy2().logger.debug(`bit-id-comp-id error, moving an object to trash ${ref.toString()}`);
|
370
|
+
await this.moveOneObjectToTrash(ref);
|
371
|
+
return undefined;
|
372
|
+
}
|
373
|
+
throw err;
|
374
|
+
}
|
375
|
+
}
|
376
|
+
async loadRefOnlyIfType(ref, types) {
|
377
|
+
const objectPath = this.objectPath(ref);
|
378
|
+
const fileContentsRaw = await _fsExtra().default.readFile(objectPath);
|
379
|
+
const fileContents = this.onRead(fileContentsRaw);
|
380
|
+
const typeNames = types.map(type => type.name);
|
381
|
+
const parsedObject = await _object().default.parseObjectOnlyIfType(fileContents, typeNames, objectPath);
|
382
|
+
return parsedObject;
|
383
|
+
}
|
384
|
+
async listRefs(cwd = this.getPath()) {
|
385
|
+
const matches = await (0, _legacy3().glob)(path().join('*', '*'), {
|
386
|
+
cwd
|
387
|
+
});
|
388
|
+
const refs = matches.map(str => {
|
389
|
+
const hash = str.replace(path().sep, '');
|
390
|
+
if (!(0, _componentVersion().isSnap)(hash)) {
|
391
|
+
_legacy2().logger.error(`fatal: the file "${str}" is not a valid bit object path`);
|
392
|
+
return null;
|
393
|
+
}
|
394
|
+
return new (_ref().default)(hash);
|
395
|
+
});
|
396
|
+
return (0, _lodash().compact)(refs);
|
397
|
+
}
|
398
|
+
async listRefsStartWith(shortHash) {
|
399
|
+
const pathPrefix = this.hashPath(shortHash);
|
400
|
+
const matches = await (0, _legacy3().glob)(`${pathPrefix}*`, {
|
401
|
+
cwd: this.getPath()
|
402
|
+
});
|
403
|
+
const refs = matches.map(str => {
|
404
|
+
const hash = str.replace(path().sep, '');
|
405
|
+
if (!(0, _componentVersion().isSnap)(hash)) {
|
406
|
+
_legacy2().logger.error(`fatal: the file "${str}" is not a valid bit object path`);
|
407
|
+
return null;
|
408
|
+
}
|
409
|
+
return new (_ref().default)(hash);
|
410
|
+
});
|
411
|
+
return (0, _lodash().compact)(refs);
|
412
|
+
}
|
413
|
+
async listRawObjects() {
|
414
|
+
const refs = await this.listRefs();
|
415
|
+
const concurrency = (0, _harmonyModules().concurrentIOLimit)();
|
416
|
+
return (0, _toolboxPromise().pMapPool)(refs, async ref => {
|
417
|
+
try {
|
418
|
+
const buffer = await this.loadRaw(ref);
|
419
|
+
const bitRawObject = await _rawObject().default.fromDeflatedBuffer(buffer, ref.hash);
|
420
|
+
return bitRawObject;
|
421
|
+
} catch {
|
422
|
+
_legacy2().logger.error(`Couldn't load the ref ${ref} this object is probably corrupted and should be delete`);
|
423
|
+
return null;
|
424
|
+
}
|
425
|
+
}, {
|
426
|
+
concurrency
|
427
|
+
});
|
428
|
+
}
|
429
|
+
async listObjectsFromIndex(indexType, filter) {
|
430
|
+
const hashes = filter ? this.scopeIndex.getHashesByQuery(indexType, filter) : this.scopeIndex.getHashes(indexType);
|
431
|
+
return this._getBitObjectsByHashes(hashes);
|
432
|
+
}
|
433
|
+
getHashFromIndex(indexType, filter) {
|
434
|
+
const hashes = this.scopeIndex.getHashesByQuery(indexType, filter);
|
435
|
+
if (hashes.length > 2) throw new Error('getHashFromIndex expect to get zero or one result');
|
436
|
+
return hashes.length ? hashes[0] : null;
|
437
|
+
}
|
438
|
+
async _getBitObjectsByHashes(hashes) {
|
439
|
+
const missingIndexItems = [];
|
440
|
+
const bitObjects = await Promise.all(hashes.map(async hash => {
|
441
|
+
const bitObject = await this.load(new (_ref().default)(hash));
|
442
|
+
if (!bitObject) {
|
443
|
+
const indexItem = this.scopeIndex.find(hash);
|
444
|
+
if (!indexItem) throw new Error(`_getBitObjectsByHashes failed finding ${hash}`);
|
445
|
+
missingIndexItems.push(indexItem);
|
446
|
+
return;
|
447
|
+
}
|
448
|
+
return bitObject;
|
449
|
+
}));
|
450
|
+
if (missingIndexItems.length) {
|
451
|
+
this.scopeIndex.removeMany(missingIndexItems.map(item => new (_ref().default)(item.hash)));
|
452
|
+
await this.scopeIndex.write();
|
453
|
+
const missingStringified = missingIndexItems.map(item => item.toIdentifierString());
|
454
|
+
throw new (_legacy4().OutdatedIndexJson)(missingStringified);
|
455
|
+
}
|
456
|
+
return (0, _lodash().compact)(bitObjects);
|
457
|
+
}
|
458
|
+
async loadOptionallyCreateScopeIndex() {
|
459
|
+
try {
|
460
|
+
const scopeIndex = await _scopeIndex().ScopeIndex.load(this.scopePath);
|
461
|
+
return scopeIndex;
|
462
|
+
} catch (err) {
|
463
|
+
if (err.code === 'ENOENT') {
|
464
|
+
const bitObjects = await this.list([_models().ModelComponent, _models().Lane]);
|
465
|
+
const scopeIndex = _scopeIndex().ScopeIndex.create(this.scopePath);
|
466
|
+
const added = scopeIndex.addMany(bitObjects);
|
467
|
+
if (added) await scopeIndex.write();
|
468
|
+
return scopeIndex;
|
469
|
+
}
|
470
|
+
throw err;
|
471
|
+
}
|
472
|
+
}
|
473
|
+
async loadRaw(ref) {
|
474
|
+
if (ref.hash.length < _componentVersion().HASH_SIZE) {
|
475
|
+
ref = await this.getFullRefFromShortHash(ref);
|
476
|
+
}
|
477
|
+
const raw = await _fsExtra().default.readFile(this.objectPath(ref));
|
478
|
+
// Run hook to transform content pre reading
|
479
|
+
const transformedContent = this.onRead(raw);
|
480
|
+
// uncomment to debug the transformed objects by onRead
|
481
|
+
// console.log('transformedContent loadRaw', ref.toString(), BitObject.parseSync(transformedContent).getType());
|
482
|
+
return transformedContent;
|
483
|
+
}
|
484
|
+
async getFullRefFromShortHash(ref) {
|
485
|
+
const refs = await this.listRefsStartWith(ref);
|
486
|
+
if (refs.length > 1) {
|
487
|
+
throw new Error(`found ${refs.length} objects with the same short hash ${ref.toString()}, please use longer hash`);
|
488
|
+
}
|
489
|
+
if (refs.length === 0) {
|
490
|
+
throw new Error(`failed finding an object with the short hash ${ref.toString()}`);
|
491
|
+
}
|
492
|
+
return refs[0];
|
493
|
+
}
|
494
|
+
async loadManyRaw(refs) {
|
495
|
+
const concurrency = (0, _harmonyModules().concurrentIOLimit)();
|
496
|
+
const uniqRefs = (0, _lodash().uniqBy)(refs, 'hash');
|
497
|
+
return (0, _toolboxPromise().pMapPool)(uniqRefs, async ref => ({
|
498
|
+
ref,
|
499
|
+
buffer: await this.loadRaw(ref)
|
500
|
+
}), {
|
501
|
+
concurrency
|
502
|
+
});
|
503
|
+
}
|
504
|
+
async loadManyRawIgnoreMissing(refs) {
|
505
|
+
const concurrency = (0, _harmonyModules().concurrentIOLimit)();
|
506
|
+
const results = await (0, _toolboxPromise().pMapPool)(refs, async ref => {
|
507
|
+
try {
|
508
|
+
const buffer = await this.loadRaw(ref);
|
509
|
+
return {
|
510
|
+
ref,
|
511
|
+
buffer
|
512
|
+
};
|
513
|
+
} catch (err) {
|
514
|
+
if (err.code === 'ENOENT') return null;
|
515
|
+
throw err;
|
516
|
+
}
|
517
|
+
}, {
|
518
|
+
concurrency
|
519
|
+
});
|
520
|
+
return (0, _lodash().compact)(results);
|
521
|
+
}
|
522
|
+
async loadRawObject(ref) {
|
523
|
+
const buffer = await this.loadRaw(ref);
|
524
|
+
const bitRawObject = await _rawObject().default.fromDeflatedBuffer(buffer, ref.hash);
|
525
|
+
return bitRawObject;
|
526
|
+
}
|
527
|
+
|
528
|
+
/**
|
529
|
+
* prefer using `this.load()` for an async version, which also writes to the cache
|
530
|
+
*/
|
531
|
+
loadSync(ref, throws = true) {
|
532
|
+
try {
|
533
|
+
const objectFile = _fsExtra().default.readFileSync(this.objectPath(ref));
|
534
|
+
// Run hook to transform content pre reading
|
535
|
+
const transformedContent = this.onRead(objectFile);
|
536
|
+
return _object().default.parseSync(transformedContent);
|
537
|
+
} catch {
|
538
|
+
if (throws) {
|
539
|
+
throw new (_legacy4().HashNotFound)(ref.toString());
|
540
|
+
}
|
541
|
+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
542
|
+
return null;
|
543
|
+
}
|
544
|
+
}
|
545
|
+
setCache(object) {
|
546
|
+
this.cache.set(object.hash().toString(), object);
|
547
|
+
return this;
|
548
|
+
}
|
549
|
+
getCache(ref) {
|
550
|
+
return this.cache.get(ref.toString());
|
551
|
+
}
|
552
|
+
removeFromCache(ref) {
|
553
|
+
this.cache.delete(ref.toString());
|
554
|
+
}
|
555
|
+
async clearCache() {
|
556
|
+
_legacy2().logger.debug('repository.clearCache');
|
557
|
+
this.cache.deleteAll();
|
558
|
+
await this.init();
|
559
|
+
}
|
560
|
+
clearObjectsFromCache() {
|
561
|
+
_legacy2().logger.debug('repository.clearObjectsFromCache');
|
562
|
+
this.cache.deleteAll();
|
563
|
+
}
|
564
|
+
backup(dirName) {
|
565
|
+
const backupDir = this.getBackupPath(dirName);
|
566
|
+
const objectsDir = this.getPath();
|
567
|
+
_legacy2().logger.debug(`making a backup of all objects from ${objectsDir} to ${backupDir}`);
|
568
|
+
_fsExtra().default.emptyDirSync(backupDir);
|
569
|
+
_fsExtra().default.copySync(objectsDir, backupDir);
|
570
|
+
}
|
571
|
+
add(object) {
|
572
|
+
// console.trace(`repository: adding object ${object?.hash().toString()}`);
|
573
|
+
if (!object) return this;
|
574
|
+
// leave the following commented log message, it is very useful for debugging but too verbose when not needed.
|
575
|
+
// logger.debug(`repository: adding object ${object.hash().toString()} which consist of the following id: ${object.id()}`);
|
576
|
+
this.objects[object.hash().toString()] = object;
|
577
|
+
this.setCache(object);
|
578
|
+
return this;
|
579
|
+
}
|
580
|
+
addMany(objects) {
|
581
|
+
if (!objects || !objects.length) return this;
|
582
|
+
objects.forEach(obj => this.add(obj));
|
583
|
+
return this;
|
584
|
+
}
|
585
|
+
removeObject(ref) {
|
586
|
+
this.objectsToRemove.push(ref);
|
587
|
+
}
|
588
|
+
removeManyObjects(refs) {
|
589
|
+
if (!refs || !refs.length) return;
|
590
|
+
refs.forEach(ref => this.removeObject(ref));
|
591
|
+
}
|
592
|
+
findMany(refs) {
|
593
|
+
return Promise.all(refs.map(ref => this.load(ref)));
|
594
|
+
}
|
595
|
+
|
596
|
+
/**
|
597
|
+
* important! use this method only for commands that are non running on an http server.
|
598
|
+
*
|
599
|
+
* it's better to remove/delete objects directly and not using the `objects` member.
|
600
|
+
* it helps to avoid multiple processes running concurrently on an http server.
|
601
|
+
*
|
602
|
+
* persist objects changes (added and removed) into the filesystem
|
603
|
+
* do not call this function multiple times in parallel, otherwise, it'll damage the index.json file.
|
604
|
+
* call this function only once after you added and removed all applicable objects.
|
605
|
+
*/
|
606
|
+
async persist(validate = true) {
|
607
|
+
// do not let two requests enter this critical area, otherwise, refs/index.json/objects could
|
608
|
+
// be corrupted
|
609
|
+
_legacy2().logger.debug(`Repository.persist, going to acquire a lock`);
|
610
|
+
await this.persistMutex.runExclusive(async () => {
|
611
|
+
_legacy2().logger.debug(`Repository.persist, validate = ${validate.toString()}, a lock has been acquired`);
|
612
|
+
await this.deleteObjectsFromFS(this.objectsToRemove);
|
613
|
+
this.validateObjects(validate, Object.values(this.objects));
|
614
|
+
await this.writeObjectsToTheFS(Object.values(this.objects));
|
615
|
+
await this.writeRemoteLanes();
|
616
|
+
await this.unmergedComponents.write();
|
617
|
+
});
|
618
|
+
_legacy2().logger.debug(`Repository.persist, completed. the lock has been released`);
|
619
|
+
this.clearObjects();
|
620
|
+
if (Repository.onPostObjectsPersist) {
|
621
|
+
Repository.onPostObjectsPersist().catch(err => {
|
622
|
+
_legacy2().logger.error('fatal: onPostObjectsPersist encountered an error (this error does not stop the process)', err);
|
623
|
+
});
|
624
|
+
}
|
625
|
+
}
|
626
|
+
async writeRemoteLanes() {
|
627
|
+
await this.remoteLanes.write();
|
628
|
+
}
|
629
|
+
|
630
|
+
/**
|
631
|
+
* this is especially critical for http server, where one process lives long and serves multiple
|
632
|
+
* exports. without this, the objects get accumulated over time and being rewritten over and over
|
633
|
+
* again.
|
634
|
+
*/
|
635
|
+
clearObjects() {
|
636
|
+
this.objects = {};
|
637
|
+
this.objectsToRemove = [];
|
638
|
+
}
|
639
|
+
|
640
|
+
/**
|
641
|
+
* normally, the validation step takes place just before the acutal writing of the file.
|
642
|
+
* however, this can be an issue where a component has an invalid version. the component could
|
643
|
+
* be saved before validating the version (see #1727). that's why we validate here before writing
|
644
|
+
* anything to the filesystem.
|
645
|
+
* the open question here is whether should we validate again before the actual writing or it
|
646
|
+
* should be enough to validate here?
|
647
|
+
* for now, it does validate again before saving, only to be 100% sure nothing happens in a few
|
648
|
+
* lines of code until the actual writing. however, if the performance penalty is noticeable, we
|
649
|
+
* can easily revert it by changing `bitObject.validateBeforePersist = false` line run regardless
|
650
|
+
* the `validate` argument.
|
651
|
+
*/
|
652
|
+
validateObjects(validate, objects) {
|
653
|
+
objects.forEach(bitObject => {
|
654
|
+
// @ts-ignore some BitObject classes have validate() method
|
655
|
+
if (validate && bitObject.validate) {
|
656
|
+
// @ts-ignore
|
657
|
+
bitObject.validate();
|
658
|
+
}
|
659
|
+
if (!validate) {
|
660
|
+
bitObject.validateBeforePersist = false;
|
661
|
+
}
|
662
|
+
});
|
663
|
+
}
|
664
|
+
async deleteObjectsFromFS(refs) {
|
665
|
+
if (!refs.length) return;
|
666
|
+
const uniqRefs = (0, _lodash().uniqBy)(refs, 'hash');
|
667
|
+
_legacy2().logger.debug(`Repository._deleteMany: deleting ${uniqRefs.length} objects`);
|
668
|
+
const concurrency = (0, _harmonyModules().concurrentIOLimit)();
|
669
|
+
await (0, _toolboxPromise().pMapPool)(uniqRefs, ref => this._deleteOne(ref), {
|
670
|
+
concurrency
|
671
|
+
});
|
672
|
+
const removed = this.scopeIndex.removeMany(uniqRefs);
|
673
|
+
if (removed) await this.scopeIndex.write();
|
674
|
+
}
|
675
|
+
async moveObjectsToDir(refs, dir) {
|
676
|
+
if (!refs.length) return;
|
677
|
+
const uniqRefs = (0, _lodash().uniqBy)(refs, 'hash');
|
678
|
+
_legacy2().logger.debug(`Repository.moveObjectsToDir: ${uniqRefs.length} objects`);
|
679
|
+
const concurrency = (0, _harmonyModules().concurrentIOLimit)();
|
680
|
+
await (0, _toolboxPromise().pMapPool)(uniqRefs, ref => this.moveOneObjectToDir(ref, dir), {
|
681
|
+
concurrency
|
682
|
+
});
|
683
|
+
const removed = this.scopeIndex.removeMany(uniqRefs);
|
684
|
+
if (removed) await this.scopeIndex.write();
|
685
|
+
}
|
686
|
+
async moveObjectsToTrash(refs) {
|
687
|
+
await this.moveObjectsToDir(refs, TRASH_DIR);
|
688
|
+
}
|
689
|
+
async listTrash() {
|
690
|
+
return this.listRefs(this.getTrashDir());
|
691
|
+
}
|
692
|
+
async getFromTrash(refs) {
|
693
|
+
const objectsFromTrash = await Promise.all(refs.map(async ref => {
|
694
|
+
const trashObjPath = path().join(this.getTrashDir(), this.hashPath(ref));
|
695
|
+
let buffer;
|
696
|
+
try {
|
697
|
+
buffer = await _fsExtra().default.readFile(trashObjPath);
|
698
|
+
} catch (err) {
|
699
|
+
if (err.code === 'ENOENT') {
|
700
|
+
throw new (_bitError().BitError)(`unable to find the object ${ref.toString()} in the trash`);
|
701
|
+
}
|
702
|
+
throw err;
|
703
|
+
}
|
704
|
+
return _object().default.parseObject(buffer, trashObjPath);
|
705
|
+
}));
|
706
|
+
return objectsFromTrash;
|
707
|
+
}
|
708
|
+
async restoreFromTrash(refs) {
|
709
|
+
_legacy2().logger.debug(`Repository.restoreFromTrash: ${refs.length} objects`);
|
710
|
+
const objectsFromTrash = await this.getFromTrash(refs);
|
711
|
+
await this.writeObjectsToTheFS(objectsFromTrash);
|
712
|
+
}
|
713
|
+
async restoreFromDir(dir, overwrite = false) {
|
714
|
+
await _fsExtra().default.copy(path().join(this.scopePath, dir), this.getPath(), {
|
715
|
+
overwrite
|
716
|
+
});
|
717
|
+
}
|
718
|
+
async moveOneObjectToDir(ref, dir) {
|
719
|
+
const currentPath = this.objectPath(ref);
|
720
|
+
const absDir = path().join(this.scopePath, dir);
|
721
|
+
const fullPath = path().join(absDir, this.hashPath(ref));
|
722
|
+
await _fsExtra().default.move(currentPath, fullPath, {
|
723
|
+
overwrite: true
|
724
|
+
});
|
725
|
+
this.removeFromCache(ref);
|
726
|
+
}
|
727
|
+
async moveOneObjectToTrash(ref) {
|
728
|
+
await this.moveOneObjectToDir(ref, TRASH_DIR);
|
729
|
+
}
|
730
|
+
async deleteRecordsFromUnmergedComponents(compIds) {
|
731
|
+
this.unmergedComponents.removeMultipleComponents(compIds);
|
732
|
+
await this.unmergedComponents.write();
|
733
|
+
}
|
734
|
+
|
735
|
+
/**
|
736
|
+
* write all objects to the FS and index the components/lanes/symlink objects
|
737
|
+
*/
|
738
|
+
async writeObjectsToTheFS(objects) {
|
739
|
+
const count = objects.length;
|
740
|
+
if (!count) return;
|
741
|
+
_legacy2().logger.trace(`Repository.writeObjectsToTheFS: started writing ${count} objects`);
|
742
|
+
const concurrency = (0, _harmonyModules().concurrentIOLimit)();
|
743
|
+
await (0, _toolboxPromise().pMapPool)(objects, obj => this._writeOne(obj), {
|
744
|
+
concurrency
|
745
|
+
});
|
746
|
+
_legacy2().logger.trace(`Repository.writeObjectsToTheFS: completed writing ${count} objects`);
|
747
|
+
const added = this.scopeIndex.addMany(objects);
|
748
|
+
if (added) await this.scopeIndex.write();
|
749
|
+
}
|
750
|
+
|
751
|
+
/**
|
752
|
+
* do not call this method directly. always call this.removeObject() and once done with all objects,
|
753
|
+
* call this.persist()
|
754
|
+
*/
|
755
|
+
_deleteOne(ref) {
|
756
|
+
this.removeFromCache(ref);
|
757
|
+
const pathToDelete = this.objectPath(ref);
|
758
|
+
_legacy2().logger.trace(`repository._deleteOne: deleting ${pathToDelete}`);
|
759
|
+
return removeFile(pathToDelete, true);
|
760
|
+
}
|
761
|
+
|
762
|
+
/**
|
763
|
+
* always prefer this.persist() or this.writeObjectsToTheFS()
|
764
|
+
* this method doesn't write to scopeIndex. so using this method for ModelComponent or
|
765
|
+
* Symlink makes the index outdated.
|
766
|
+
*/
|
767
|
+
async _writeOne(object) {
|
768
|
+
const contents = await object.compress();
|
769
|
+
const options = {};
|
770
|
+
if (this.scopeJson.groupName) options.gid = await resolveGroupId(this.scopeJson.groupName);
|
771
|
+
const hash = object.hash();
|
772
|
+
if (this.cache.has(hash.toString())) this.cache.set(hash.toString(), object); // update the cache
|
773
|
+
const objectPath = this.objectPath(hash);
|
774
|
+
_legacy2().logger.trace(`repository._writeOne: ${objectPath}`);
|
775
|
+
// Run hook to transform content pre persisting
|
776
|
+
const transformedContent = this.onPersist(contents);
|
777
|
+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
778
|
+
return (0, _legacy3().writeFile)(objectPath, transformedContent, options);
|
779
|
+
}
|
780
|
+
async writeObjectsToPendingDir(objectList, pendingDir) {
|
781
|
+
const options = {};
|
782
|
+
if (this.scopeJson.groupName) options.gid = await resolveGroupId(this.scopeJson.groupName);
|
783
|
+
await Promise.all(objectList.objects.map(async object => {
|
784
|
+
const objPath = path().join(pendingDir, this.hashPath(object.ref));
|
785
|
+
await (0, _legacy3().writeFile)(objPath, object.buffer, options);
|
786
|
+
}));
|
787
|
+
}
|
788
|
+
async readObjectsFromPendingDir(pendingDir) {
|
789
|
+
const refs = await this.listRefs(pendingDir);
|
790
|
+
const objects = await Promise.all(refs.map(async ref => {
|
791
|
+
const buffer = await _fsExtra().default.readFile(path().join(pendingDir, this.hashPath(ref)));
|
792
|
+
return {
|
793
|
+
ref,
|
794
|
+
buffer
|
795
|
+
};
|
796
|
+
}));
|
797
|
+
return new (_objectList().ObjectList)(objects);
|
798
|
+
}
|
799
|
+
hashPath(ref) {
|
800
|
+
const hash = ref.toString();
|
801
|
+
return path().join(hash.slice(0, 2), hash.slice(2));
|
802
|
+
}
|
803
|
+
}
|
804
|
+
exports.default = Repository;
|
805
|
+
_defineProperty(Repository, "onPostObjectsPersist", void 0);
|
806
|
+
async function removeFile(filePath, propagateDirs = false) {
|
807
|
+
try {
|
808
|
+
await _fsExtra().default.unlink(filePath);
|
809
|
+
} catch (err) {
|
810
|
+
if (err.code === 'ENOENT') {
|
811
|
+
// the file doesn't exist, that's fine, no need to do anything
|
812
|
+
return false;
|
813
|
+
}
|
814
|
+
throw err;
|
815
|
+
}
|
816
|
+
if (!propagateDirs) return true;
|
817
|
+
const {
|
818
|
+
dir
|
819
|
+
} = path().parse(filePath);
|
820
|
+
await (0, _toolboxFs().removeEmptyDir)(dir);
|
821
|
+
return true;
|
822
|
+
}
|
823
|
+
function resolveGroupId(groupName) {
|
824
|
+
return new Promise((resolve, reject) => {
|
825
|
+
(0, _uidNumber().default)(null, groupName, (err, uid, gid) => {
|
826
|
+
if (err) {
|
827
|
+
_legacy2().logger.error('resolveGroupId', err);
|
828
|
+
if (err.message.includes('EPERM')) {
|
829
|
+
return reject(new (_bitError().BitError)(`unable to resolve group id of "${groupName}", current user does not have sufficient permissions`));
|
830
|
+
}
|
831
|
+
if (err.message.includes('group id does not exist')) {
|
832
|
+
return reject(new (_bitError().BitError)(`unable to resolve group id of "${groupName}", the group does not exist`));
|
833
|
+
}
|
834
|
+
return reject(new (_bitError().BitError)(`unable to resolve group id of "${groupName}", got an error ${err.message}`));
|
835
|
+
}
|
836
|
+
// on Windows it'll always be null
|
837
|
+
return resolve(gid);
|
838
|
+
});
|
839
|
+
});
|
840
|
+
}
|
841
|
+
|
842
|
+
//# sourceMappingURL=repository.js.map
|