@dotinc/ogre 0.10.0 → 0.10.1

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.
Files changed (54) hide show
  1. package/.tap/processinfo/0741404d-d06b-4ac8-a639-dfe1be9ccf07.json +866 -0
  2. package/.tap/processinfo/1691fd47-213e-46a9-ba45-a2f508a155f1.json +866 -0
  3. package/.tap/processinfo/6dcd3368-1cc7-4f75-809d-20b0b3340e04.json +866 -0
  4. package/.tap/processinfo/78acaa93-00af-492d-8195-06f5256ef8cf.json +866 -0
  5. package/.tap/processinfo/9b28b42b-9293-4cdc-be9a-e2748575485f.json +866 -0
  6. package/.tap/processinfo/ad880a78-892c-46c9-bf08-1c89b8427ce2.json +866 -0
  7. package/.tap/processinfo/eb1b6e66-8dfe-4ab9-bdd4-297f7c89c5f9.json +866 -0
  8. package/.tap/test-results/src/branch.test.ts.tap +6 -6
  9. package/.tap/test-results/src/checkout.test.ts.tap +9 -9
  10. package/.tap/test-results/src/commit.test.ts.tap +18 -18
  11. package/.tap/test-results/src/merge.test.ts.tap +2 -2
  12. package/.tap/test-results/src/repository.test.ts.tap +35 -35
  13. package/.tap/test-results/src/tag.test.ts.tap +3 -3
  14. package/.tap/test-results/src/utils.test.ts.tap +12 -12
  15. package/CHANGELOG.md +18 -0
  16. package/lib/commit.js +3 -7
  17. package/lib/git2json.d.ts +1 -1
  18. package/lib/git2json.js +6 -10
  19. package/lib/hash.js +2 -6
  20. package/lib/index.d.ts +7 -7
  21. package/lib/index.js +7 -14
  22. package/lib/interfaces.d.ts +1 -1
  23. package/lib/interfaces.js +1 -2
  24. package/lib/ref.js +2 -7
  25. package/lib/repository.d.ts +2 -2
  26. package/lib/repository.js +63 -67
  27. package/lib/size.js +7 -14
  28. package/lib/test.utils.d.ts +2 -2
  29. package/lib/test.utils.js +10 -17
  30. package/lib/utils.d.ts +3 -3
  31. package/lib/utils.js +47 -73
  32. package/package.json +3 -3
  33. package/src/branch.test.ts +1 -1
  34. package/src/checkout.test.ts +2 -2
  35. package/src/commit.test.ts +2 -3
  36. package/src/commit.ts +7 -7
  37. package/src/git2json.ts +3 -3
  38. package/src/hash.ts +3 -3
  39. package/src/index.ts +7 -7
  40. package/src/interfaces.ts +1 -1
  41. package/src/merge.test.ts +1 -1
  42. package/src/repository.test.ts +3 -3
  43. package/src/repository.ts +3 -3
  44. package/src/tag.test.ts +1 -1
  45. package/src/test.utils.ts +2 -2
  46. package/src/utils.test.ts +3 -3
  47. package/src/utils.ts +4 -4
  48. package/.tap/processinfo/47e5601b-c2e5-4064-88bd-15f1484dec76.json +0 -246
  49. package/.tap/processinfo/5654cfb5-e31e-4776-99bb-86f233fa2881.json +0 -246
  50. package/.tap/processinfo/b57115cf-ee9b-4b93-8261-0fc4783a00ac.json +0 -246
  51. package/.tap/processinfo/ba4f26b9-c10e-4e97-bc44-f8db195e0047.json +0 -246
  52. package/.tap/processinfo/c5025b3f-8bba-4ab4-8cb6-b70dc75e9747.json +0 -246
  53. package/.tap/processinfo/ea6f6096-cc7a-431d-8f2a-c65249be747c.json +0 -246
  54. package/.tap/processinfo/fe306306-8121-4647-b0fc-3c2819db59a1.json +0 -246
package/lib/git2json.js CHANGED
@@ -1,20 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatGit2Json = void 0;
4
- const utils_1 = require("./utils");
1
+ import { cleanAuthor, createHeadRefValue, isTagRef, REFS_HEAD_KEY, } from "./utils.js";
5
2
  const findRefs = (commit, refs) => {
6
3
  const list = [];
7
- const headRef = refs.get(utils_1.REFS_HEAD_KEY);
4
+ const headRef = refs.get(REFS_HEAD_KEY);
8
5
  for (const [key, ref] of refs.entries()) {
9
6
  if (ref.value === commit.hash) {
10
- if ((0, utils_1.isTagRef)(key)) {
7
+ if (isTagRef(key)) {
11
8
  list.push(`tag: ${ref.name}`);
12
9
  }
13
10
  else {
14
11
  list.push(ref.name);
15
12
  }
16
13
  // also check if HEAD is pointing to this ref
17
- if (headRef && headRef.value === (0, utils_1.createHeadRefValue)(key)) {
14
+ if (headRef && headRef.value === createHeadRefValue(key)) {
18
15
  list.push(headRef.name);
19
16
  }
20
17
  }
@@ -30,10 +27,10 @@ const findRefs = (commit, refs) => {
30
27
  * in the Repository history. The json representation is returned in `git2json` format based on:
31
28
  * https://github.com/fabien0102/git2json/blob/e067166d2468018b6f3982a8fb44a2e54110ce02/src/git2json.js#L5-L22
32
29
  */
33
- const formatGit2Json = (history) => {
30
+ export const formatGit2Json = (history) => {
34
31
  const { commits, refs } = history;
35
32
  return commits.reverse().map((c) => {
36
- const [name, email] = (0, utils_1.cleanAuthor)(c.author);
33
+ const [name, email] = cleanAuthor(c.author);
37
34
  return {
38
35
  refs: findRefs(c, refs),
39
36
  hash: c.hash,
@@ -61,4 +58,3 @@ const formatGit2Json = (history) => {
61
58
  };
62
59
  });
63
60
  };
64
- exports.formatGit2Json = formatGit2Json;
package/lib/hash.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * Credit goes to https://github.com/juanelas/object-sha
4
3
  *
@@ -7,8 +6,6 @@
7
6
  *
8
7
  * @packageDocumentation
9
8
  */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.digest = void 0;
12
9
  /**
13
10
  * Returns a string with a hexadecimal representation of the digest of the input object using a given hash algorithm.
14
11
  * It first creates an array of the object values ordered by the object keys (using hashable(obj));
@@ -23,7 +20,7 @@ exports.digest = void 0;
23
20
  *
24
21
  * @returns a promise that resolves to a string with hexadecimal content.
25
22
  */
26
- function digest(obj, algorithm = "SHA-256", isBrowser = false) {
23
+ export function digest(obj, algorithm = "SHA-256", isBrowser = false) {
27
24
  // eslint-disable-line
28
25
  const algorithms = ["SHA-1", "SHA-256", "SHA-384", "SHA-512"];
29
26
  if (!algorithms.includes(algorithm)) {
@@ -42,7 +39,7 @@ function digest(obj, algorithm = "SHA-256", isBrowser = false) {
42
39
  }
43
40
  else {
44
41
  const nodeAlg = algorithm.toLowerCase().replace("-", "");
45
- digest = require("crypto")
42
+ digest = (await import("crypto"))
46
43
  .createHash(nodeAlg)
47
44
  .update(Buffer.from(hashInput))
48
45
  .digest("hex"); // eslint-disable-line
@@ -51,7 +48,6 @@ function digest(obj, algorithm = "SHA-256", isBrowser = false) {
51
48
  return digest;
52
49
  })(obj, algorithm);
53
50
  }
54
- exports.digest = digest;
55
51
  function isObject(val) {
56
52
  return val != null && typeof val === "object" && !Array.isArray(val);
57
53
  }
package/lib/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- export * from "./interfaces";
2
- export * from "./repository";
3
- export { Commit } from "./commit";
4
- export * from "./ref";
5
- export * from "./size";
6
- export * from "./utils";
7
- export * from "./git2json";
1
+ export * from "./interfaces.js";
2
+ export * from "./repository.js";
3
+ export { Commit } from "./commit.js";
4
+ export * from "./ref.js";
5
+ export * from "./size.js";
6
+ export * from "./utils.js";
7
+ export * from "./git2json.js";
8
8
  export { compare, deepClone, Operation, JsonPatchError } from "fast-json-patch";
package/lib/index.js CHANGED
@@ -1,14 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.JsonPatchError = exports.deepClone = exports.compare = void 0;
4
- const tslib_1 = require("tslib");
5
- tslib_1.__exportStar(require("./interfaces"), exports);
6
- tslib_1.__exportStar(require("./repository"), exports);
7
- tslib_1.__exportStar(require("./ref"), exports);
8
- tslib_1.__exportStar(require("./size"), exports);
9
- tslib_1.__exportStar(require("./utils"), exports);
10
- tslib_1.__exportStar(require("./git2json"), exports);
11
- var fast_json_patch_1 = require("fast-json-patch");
12
- Object.defineProperty(exports, "compare", { enumerable: true, get: function () { return fast_json_patch_1.compare; } });
13
- Object.defineProperty(exports, "deepClone", { enumerable: true, get: function () { return fast_json_patch_1.deepClone; } });
14
- Object.defineProperty(exports, "JsonPatchError", { enumerable: true, get: function () { return fast_json_patch_1.JsonPatchError; } });
1
+ export * from "./interfaces.js";
2
+ export * from "./repository.js";
3
+ export * from "./ref.js";
4
+ export * from "./size.js";
5
+ export * from "./utils.js";
6
+ export * from "./git2json.js";
7
+ export { compare, deepClone, JsonPatchError } from "fast-json-patch";
@@ -1,4 +1,4 @@
1
- import { Commit } from "./commit";
1
+ import { Commit } from "./commit.js";
2
2
  export interface Reference {
3
3
  name: string;
4
4
  value: string;
package/lib/interfaces.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
package/lib/ref.js CHANGED
@@ -1,13 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validBranch = exports.validRef = void 0;
4
1
  const bad = /(^|[/.])([/.]|$)|^@$|@{|[\x00-\x20\x7f~^:?*[\\]|\.lock(\/|$)/;
5
2
  const badBranch = /^(-|HEAD$)/;
6
- function validRef(name, onelevel) {
3
+ export function validRef(name, onelevel) {
7
4
  return !bad.test(name) && (onelevel || name.includes("/"));
8
5
  }
9
- exports.validRef = validRef;
10
- function validBranch(name) {
6
+ export function validBranch(name) {
11
7
  return validRef(name, true) && !badBranch.test(name);
12
8
  }
13
- exports.validBranch = validBranch;
@@ -1,6 +1,6 @@
1
1
  import { JsonPatchError, Operation } from "fast-json-patch";
2
- import { Commit } from "./commit";
3
- import { History, Reference } from "./interfaces";
2
+ import { Commit } from "./commit.js";
3
+ import { History, Reference } from "./interfaces.js";
4
4
  export interface RepositoryOptions<T extends {
5
5
  [k: string]: any;
6
6
  }> {
package/lib/repository.js CHANGED
@@ -1,31 +1,28 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Repository = void 0;
4
- const fast_json_patch_1 = require("fast-json-patch");
5
- const commit_1 = require("./commit");
6
- const fflate_1 = require("fflate");
7
- const utils_1 = require("./utils");
1
+ import { applyPatch, applyReducer, compare, deepClone, generate, observe, unobserve, validate, } from "fast-json-patch";
2
+ import { calculateCommitHash } from "./commit.js";
3
+ import { compressSync, strToU8 } from "fflate";
4
+ import { brancheNameToRef, cleanRefValue, commitAtRefIn, createHeadRefValue, getLastRefPathElement, headValueRefPrefix, immutableArrayCopy, immutableMapCopy, localHeadPathPrefix, mapPath, mutableMapCopy, REFS_HEAD_KEY, REFS_MAIN_KEY, refsAtCommit, shaishToCommit, tagToRef, treeToObject, validateBranchName, validateRef, } from "./utils.js";
8
5
  /**
9
6
  * A repository recording and managing the state transitions of an object
10
7
  */
11
- class Repository {
8
+ export class Repository {
12
9
  constructor(obj, options) {
13
10
  var _a, _b, _c, _d, _e, _f;
14
11
  // FIXME: move this to refs/remote as git would do?
15
- this.remoteRefs = (0, utils_1.immutableMapCopy)((_a = options.history) === null || _a === void 0 ? void 0 : _a.refs);
16
- this.remoteCommits = (0, utils_1.immutableArrayCopy)((_b = options.history) === null || _b === void 0 ? void 0 : _b.commits, (c) => c.hash);
17
- this.original = (0, fast_json_patch_1.deepClone)(obj);
12
+ this.remoteRefs = immutableMapCopy((_a = options.history) === null || _a === void 0 ? void 0 : _a.refs);
13
+ this.remoteCommits = immutableArrayCopy((_b = options.history) === null || _b === void 0 ? void 0 : _b.commits, (c) => c.hash);
14
+ this.original = deepClone(obj);
18
15
  // store js ref, so obj can still be modified without going through repo.data
19
16
  this.data = obj;
20
- this.observer = (0, fast_json_patch_1.observe)(obj);
17
+ this.observer = observe(obj);
21
18
  this.refs = ((_c = options.history) === null || _c === void 0 ? void 0 : _c.refs)
22
- ? (0, utils_1.mutableMapCopy)((_d = options.history) === null || _d === void 0 ? void 0 : _d.refs)
19
+ ? mutableMapCopy((_d = options.history) === null || _d === void 0 ? void 0 : _d.refs)
23
20
  : new Map([
24
21
  [
25
- utils_1.REFS_HEAD_KEY,
22
+ REFS_HEAD_KEY,
26
23
  {
27
- name: utils_1.REFS_HEAD_KEY,
28
- value: `ref: ${utils_1.REFS_MAIN_KEY}`,
24
+ name: REFS_HEAD_KEY,
25
+ value: `ref: ${REFS_MAIN_KEY}`,
29
26
  },
30
27
  ],
31
28
  ]);
@@ -55,7 +52,7 @@ class Repository {
55
52
  };
56
53
  // collect ref updates and commits that are not present on the remote
57
54
  for (const [key, ref] of this.refs) {
58
- if (key === utils_1.REFS_HEAD_KEY) {
55
+ if (key === REFS_HEAD_KEY) {
59
56
  continue;
60
57
  }
61
58
  const remote = (_a = this.remoteRefs) === null || _a === void 0 ? void 0 : _a.get(key);
@@ -68,7 +65,7 @@ class Repository {
68
65
  continue;
69
66
  }
70
67
  // map all commits to root
71
- const [isAncestor, path] = (0, utils_1.mapPath)(this.commits, localCommit, undefined);
68
+ const [isAncestor, path] = mapPath(this.commits, localCommit, undefined);
72
69
  if (isAncestor) {
73
70
  for (let i = 0; i < path.length; i++) {
74
71
  const commit = path[i];
@@ -98,7 +95,7 @@ class Repository {
98
95
  }
99
96
  // FIXME: do we have to have the remote ref as a commit locally?
100
97
  const remoteCommit = this.commits.find((c) => c.hash === remote.value);
101
- const [isAncestor, path] = (0, utils_1.mapPath)(this.commits, localCommit, remoteCommit);
98
+ const [isAncestor, path] = mapPath(this.commits, localCommit, remoteCommit);
102
99
  if (isAncestor) {
103
100
  for (let i = 0; i < path.length; i++) {
104
101
  const commit = path[i];
@@ -120,18 +117,18 @@ class Repository {
120
117
  return this.remoteRefs;
121
118
  }
122
119
  moveTo(commit) {
123
- const targetTree = (0, utils_1.treeToObject)(commit.tree);
124
- const patchToTarget = (0, fast_json_patch_1.compare)(this.data, targetTree);
120
+ const targetTree = treeToObject(commit.tree);
121
+ const patchToTarget = compare(this.data, targetTree);
125
122
  if (!patchToTarget || patchToTarget.length < 1) {
126
123
  return;
127
124
  }
128
125
  this.observer.unobserve();
129
- patchToTarget.reduce(fast_json_patch_1.applyReducer, this.data);
130
- this.observer = (0, fast_json_patch_1.observe)(this.data);
126
+ patchToTarget.reduce(applyReducer, this.data);
127
+ this.observer = observe(this.data);
131
128
  }
132
129
  apply(patch) {
133
- const p = (0, fast_json_patch_1.deepClone)(patch);
134
- const err = (0, fast_json_patch_1.validate)(p, this.data);
130
+ const p = deepClone(patch);
131
+ const err = validate(p, this.data);
135
132
  if (err) {
136
133
  // credit goes to @NicBright
137
134
  // https://github.com/Starcounter-Jack/JSON-Patch/issues/280#issuecomment-1980435509
@@ -158,72 +155,72 @@ class Repository {
158
155
  return err;
159
156
  }
160
157
  }
161
- (0, fast_json_patch_1.applyPatch)(this.data, patch);
158
+ applyPatch(this.data, patch);
162
159
  // const changed = patch.reduce(applyReducer, this.data);
163
160
  }
164
- reset(mode = "hard", shaish = utils_1.REFS_HEAD_KEY) {
161
+ reset(mode = "hard", shaish = REFS_HEAD_KEY) {
165
162
  if (mode === "hard") {
166
- (0, fast_json_patch_1.unobserve)(this.data, this.observer);
163
+ unobserve(this.data, this.observer);
167
164
  }
168
- const [commit] = (0, utils_1.shaishToCommit)(shaish, this.refs, this.commits);
165
+ const [commit] = shaishToCommit(shaish, this.refs, this.commits);
169
166
  this.moveTo(commit);
170
- const refs = (0, utils_1.refsAtCommit)(this.refs, commit);
167
+ const refs = refsAtCommit(this.refs, commit);
171
168
  // reset only moves heads and not tags
172
- const moveableRefs = refs.filter((r) => r.name.startsWith((0, utils_1.localHeadPathPrefix)()));
169
+ const moveableRefs = refs.filter((r) => r.name.startsWith(localHeadPathPrefix()));
173
170
  for (const ref of moveableRefs) {
174
171
  this.moveRef(ref.name, commit);
175
172
  }
176
173
  if (mode === "hard") {
177
- this.observer = (0, fast_json_patch_1.observe)(this.data);
174
+ this.observer = observe(this.data);
178
175
  }
179
176
  }
180
177
  branch() {
181
- const currentHeadRef = this.refs.get(utils_1.REFS_HEAD_KEY);
178
+ const currentHeadRef = this.refs.get(REFS_HEAD_KEY);
182
179
  if (!currentHeadRef) {
183
180
  throw new Error("unreachable: ref HEAD not available");
184
181
  }
185
- if (currentHeadRef.value.includes(utils_1.headValueRefPrefix)) {
186
- const refName = (0, utils_1.cleanRefValue)(currentHeadRef.value);
182
+ if (currentHeadRef.value.includes(headValueRefPrefix)) {
183
+ const refName = cleanRefValue(currentHeadRef.value);
187
184
  if (this.refs.has(refName))
188
- return (0, utils_1.getLastRefPathElement)(refName);
185
+ return getLastRefPathElement(refName);
189
186
  }
190
- return utils_1.REFS_HEAD_KEY; // detached state
187
+ return REFS_HEAD_KEY; // detached state
191
188
  }
192
189
  status() {
193
190
  const commit = this.commitAtHead();
194
191
  if (!commit) {
195
192
  // on root repo return the pending changes
196
- return (0, fast_json_patch_1.compare)(this.original, this.data); // this.observer.patches is empty?? :(
193
+ return compare(this.original, this.data); // this.observer.patches is empty?? :(
197
194
  }
198
195
  return this.diff(commit.hash);
199
196
  }
200
197
  diff(shaishFrom, shaishTo) {
201
- const [cFrom] = (0, utils_1.shaishToCommit)(shaishFrom, this.refs, this.commits);
198
+ const [cFrom] = shaishToCommit(shaishFrom, this.refs, this.commits);
202
199
  let target;
203
200
  if (shaishTo) {
204
- const [cTo] = (0, utils_1.shaishToCommit)(shaishTo, this.refs, this.commits);
205
- target = (0, utils_1.treeToObject)(cTo.tree);
201
+ const [cTo] = shaishToCommit(shaishTo, this.refs, this.commits);
202
+ target = treeToObject(cTo.tree);
206
203
  }
207
204
  else {
208
205
  target = this.data;
209
206
  }
210
- const targetTree = (0, utils_1.treeToObject)(cFrom.tree);
211
- return (0, fast_json_patch_1.compare)(targetTree, target);
207
+ const targetTree = treeToObject(cFrom.tree);
208
+ return compare(targetTree, target);
212
209
  }
213
210
  checkout(shaish, createBranch) {
214
211
  if (createBranch) {
215
- (0, utils_1.validateBranchName)(shaish);
216
- let branchRef = (0, utils_1.brancheNameToRef)(shaish);
212
+ validateBranchName(shaish);
213
+ let branchRef = brancheNameToRef(shaish);
217
214
  const commit = this.commitAtHead();
218
215
  if (commit) {
219
216
  this.moveRef(branchRef, commit);
220
217
  }
221
- this.moveRef(utils_1.REFS_HEAD_KEY, branchRef);
218
+ this.moveRef(REFS_HEAD_KEY, branchRef);
222
219
  }
223
220
  else {
224
- const [commit, isRef, refKey] = (0, utils_1.shaishToCommit)(shaish, this.refs, this.commits);
221
+ const [commit, isRef, refKey] = shaishToCommit(shaish, this.refs, this.commits);
225
222
  this.moveTo(commit);
226
- this.moveRef(utils_1.REFS_HEAD_KEY, isRef && refKey !== undefined ? refKey : commit);
223
+ this.moveRef(REFS_HEAD_KEY, isRef && refKey !== undefined ? refKey : commit);
227
224
  }
228
225
  }
229
226
  async commit(message, author, amend) {
@@ -235,11 +232,11 @@ class Repository {
235
232
  if (parent) {
236
233
  if (amend) {
237
234
  [parent] = parent.parent
238
- ? (0, utils_1.shaishToCommit)(parent.parent, this.refs, this.commits)
235
+ ? shaishToCommit(parent.parent, this.refs, this.commits)
239
236
  : [parent]; // we are the very first commit in the repository
240
237
  }
241
238
  }
242
- const patch = (0, fast_json_patch_1.generate)(this.observer);
239
+ const patch = generate(this.observer);
243
240
  if ((patch.length === 0 && !amend) ||
244
241
  (amend && message === (parent === null || parent === void 0 ? void 0 : parent.message))) {
245
242
  throw new Error(`no changes to commit`);
@@ -249,14 +246,14 @@ class Repository {
249
246
  ? parent.changes
250
247
  : [];
251
248
  const changes = [...parentChanges, ...patch];
252
- const sha = await (0, commit_1.calculateCommitHash)({
249
+ const sha = await calculateCommitHash({
253
250
  message,
254
251
  author,
255
252
  changes,
256
253
  parentRef: parent === null || parent === void 0 ? void 0 : parent.hash,
257
254
  timestamp,
258
255
  });
259
- const treeHash = Buffer.from((0, fflate_1.compressSync)((0, fflate_1.strToU8)(JSON.stringify(this.data)), { level: 6, mem: 8 })).toString("base64");
256
+ const treeHash = Buffer.from(compressSync(strToU8(JSON.stringify(this.data)), { level: 6, mem: 8 })).toString("base64");
260
257
  const commit = {
261
258
  hash: sha,
262
259
  message,
@@ -278,13 +275,13 @@ class Repository {
278
275
  }
279
276
  else {
280
277
  // move detached HEAD to new commit
281
- this.moveRef(utils_1.REFS_HEAD_KEY, commit);
278
+ this.moveRef(REFS_HEAD_KEY, commit);
282
279
  }
283
280
  return sha;
284
281
  }
285
282
  // region Commit lookups
286
283
  commitAtHead() {
287
- return (0, utils_1.commitAtRefIn)(utils_1.REFS_HEAD_KEY, this.refs, this.commits);
284
+ return commitAtRefIn(REFS_HEAD_KEY, this.refs, this.commits);
288
285
  }
289
286
  mustCommitAtHead() {
290
287
  const commitHead = this.commitAtHead();
@@ -295,17 +292,17 @@ class Repository {
295
292
  }
296
293
  // endregion
297
294
  createBranch(name) {
298
- (0, utils_1.validateBranchName)(name);
299
- const branchRef = (0, utils_1.brancheNameToRef)(name);
295
+ validateBranchName(name);
296
+ const branchRef = brancheNameToRef(name);
300
297
  this.saveNewRef(branchRef, name);
301
298
  return branchRef;
302
299
  }
303
300
  head() {
304
- const ref = this.refs.get(utils_1.REFS_HEAD_KEY);
301
+ const ref = this.refs.get(REFS_HEAD_KEY);
305
302
  if (!ref) {
306
303
  throw new Error(`unreachable: HEAD is not present`);
307
304
  }
308
- return (0, utils_1.cleanRefValue)(ref.value);
305
+ return cleanRefValue(ref.value);
309
306
  }
310
307
  // region History functions
311
308
  collectCommits() {
@@ -351,7 +348,7 @@ class Repository {
351
348
  // const srcHead = commitAtRefIn(REFS_HEAD, src.refs, src.commits)
352
349
  throw new Error(`fatal: source type (${source instanceof Repository ? "Repository" : "History"}) not implemented`);
353
350
  }
354
- const [srcCommit] = (0, utils_1.shaishToCommit)(source, this.refs, this.commits);
351
+ const [srcCommit] = shaishToCommit(source, this.refs, this.commits);
355
352
  const headCommit = this.mustCommitAtHead();
356
353
  // no change
357
354
  // *---* (master)
@@ -368,7 +365,7 @@ class Repository {
368
365
  // *---*
369
366
  // \
370
367
  // *---*---* (master, foo)
371
- const [isAncestor] = (0, utils_1.mapPath)(this.commits, srcCommit, headCommit);
368
+ const [isAncestor] = mapPath(this.commits, srcCommit, headCommit);
372
369
  if (isAncestor) {
373
370
  this.moveRef(this.head(), srcCommit);
374
371
  this.moveTo(srcCommit);
@@ -391,9 +388,9 @@ class Repository {
391
388
  // region Ref methods
392
389
  moveRef(refName, value) {
393
390
  let ref = this.refs.get(refName);
394
- const val = typeof value === "string" ? (0, utils_1.createHeadRefValue)(value) : value.hash;
391
+ const val = typeof value === "string" ? createHeadRefValue(value) : value.hash;
395
392
  if (!ref) {
396
- ref = { name: (0, utils_1.getLastRefPathElement)(refName), value: val };
393
+ ref = { name: getLastRefPathElement(refName), value: val };
397
394
  }
398
395
  else {
399
396
  ref.value = val;
@@ -407,24 +404,24 @@ class Repository {
407
404
  if (!headRef) {
408
405
  throw new Error(`unreachable: HEAD not present`);
409
406
  }
410
- throw new Error(`fatal: not a valid object name: '${(0, utils_1.getLastRefPathElement)(headRef)}'`);
407
+ throw new Error(`fatal: not a valid object name: '${getLastRefPathElement(headRef)}'`);
411
408
  }
412
409
  this.refs.set(refKey, { name: name, value: headCommit.hash });
413
410
  }
414
411
  ref(reference) {
415
412
  var _a;
416
413
  const ref = (_a = this.refs.get(reference)) === null || _a === void 0 ? void 0 : _a.value;
417
- return ref ? (0, utils_1.cleanRefValue)(ref) : undefined;
414
+ return ref ? cleanRefValue(ref) : undefined;
418
415
  }
419
416
  // endregion
420
417
  tag(tag) {
421
418
  try {
422
- (0, utils_1.validateRef)(tag);
419
+ validateRef(tag);
423
420
  }
424
421
  catch (e) {
425
422
  throw new Error(`fatal: '${tag}' is not a valid tag name`);
426
423
  }
427
- const tagRef = (0, utils_1.tagToRef)(tag);
424
+ const tagRef = tagToRef(tag);
428
425
  try {
429
426
  this.saveNewRef(tagRef, tag);
430
427
  }
@@ -436,4 +433,3 @@ class Repository {
436
433
  return tagRef;
437
434
  }
438
435
  }
439
- exports.Repository = Repository;
package/lib/size.js CHANGED
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sizeInMegabytes = exports.sizeInKilobytes = exports.sizeInBytes = exports.getSizeInBytes = void 0;
4
- const getSizeInBytes = (obj) => {
1
+ export const getSizeInBytes = (obj) => {
5
2
  let str;
6
3
  if (typeof obj === "string") {
7
4
  // If obj is a string, then use it
@@ -14,18 +11,14 @@ const getSizeInBytes = (obj) => {
14
11
  // Get the length of the Uint8Array
15
12
  return new TextEncoder().encode(str).length; // in bytes
16
13
  };
17
- exports.getSizeInBytes = getSizeInBytes;
18
- const sizeInBytes = (obj) => {
19
- return (0, exports.getSizeInBytes)(obj); // B
14
+ export const sizeInBytes = (obj) => {
15
+ return getSizeInBytes(obj); // B
20
16
  };
21
- exports.sizeInBytes = sizeInBytes;
22
- const sizeInKilobytes = (obj) => {
23
- const bytes = (0, exports.getSizeInBytes)(obj);
17
+ export const sizeInKilobytes = (obj) => {
18
+ const bytes = getSizeInBytes(obj);
24
19
  return bytes / 1000; // kB
25
20
  };
26
- exports.sizeInKilobytes = sizeInKilobytes;
27
- const sizeInMegabytes = (obj) => {
28
- const bytes = (0, exports.getSizeInBytes)(obj);
21
+ export const sizeInMegabytes = (obj) => {
22
+ const bytes = getSizeInBytes(obj);
29
23
  return bytes / 1000 / 1000; // mB
30
24
  };
31
- exports.sizeInMegabytes = sizeInMegabytes;
@@ -1,5 +1,5 @@
1
- import { RepositoryObject } from "./repository";
2
- import { Commit } from "./commit";
1
+ import { RepositoryObject } from "./repository.js";
2
+ import { Commit } from "./commit.js";
3
3
  export type NestedObject = {
4
4
  name?: string;
5
5
  uuid?: string;
package/lib/test.utils.js CHANGED
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sumChanges = exports.addOneStep = exports.updateHeaderData = exports.getBaseline = exports.testAuthor = void 0;
4
- const uuid_1 = require("uuid");
5
- const repository_1 = require("./repository");
6
- exports.testAuthor = "User name <name@domain.com>";
7
- async function getBaseline(obj) {
1
+ import { v4 as uuid4 } from "uuid";
2
+ import { Repository } from "./repository.js";
3
+ export const testAuthor = "User name <name@domain.com>";
4
+ export async function getBaseline(obj) {
8
5
  const co = {
9
6
  uuid: undefined,
10
7
  name: undefined,
@@ -12,27 +9,23 @@ async function getBaseline(obj) {
12
9
  nested: [],
13
10
  ...obj,
14
11
  };
15
- const repo = new repository_1.Repository(co, {});
12
+ const repo = new Repository(co, {});
16
13
  return [repo, co];
17
14
  }
18
- exports.getBaseline = getBaseline;
19
- function updateHeaderData(wrapped) {
20
- wrapped.uuid = (0, uuid_1.v4)();
15
+ export function updateHeaderData(wrapped) {
16
+ wrapped.uuid = uuid4();
21
17
  wrapped.name = "my first process template";
22
18
  wrapped.description = "now we have a description";
23
19
  return 3; // change entries
24
20
  }
25
- exports.updateHeaderData = updateHeaderData;
26
- function addOneStep(wrapped) {
21
+ export function addOneStep(wrapped) {
27
22
  const pe = {};
28
- pe.uuid = (0, uuid_1.v4)();
23
+ pe.uuid = uuid4();
29
24
  pe.name = "first name";
30
25
  wrapped.nested.push(pe);
31
26
  wrapped.nested[0].name = "new name";
32
27
  return 1; // change entries
33
28
  }
34
- exports.addOneStep = addOneStep;
35
- function sumChanges(commits) {
29
+ export function sumChanges(commits) {
36
30
  return commits === null || commits === void 0 ? void 0 : commits.map((c) => c.changes.length).reduce((p, c) => p + c, 0);
37
31
  }
38
- exports.sumChanges = sumChanges;
package/lib/utils.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { Commit } from "./commit";
2
- import { Reference } from "./interfaces";
1
+ import { Commit } from "./commit.js";
2
+ import { Reference } from "./interfaces.js";
3
3
  import { Operation } from "fast-json-patch";
4
- import { RepositoryObject } from "./repository";
4
+ import { RepositoryObject } from "./repository.js";
5
5
  export declare const cleanAuthor: (author: string) => [name: string, email: string];
6
6
  export declare const localRefPrefix = "refs/";
7
7
  export declare const remoteRefPrefix = "refs/remotes/origin/";