@dotinc/ogre 0.10.2 → 0.10.3

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/src/repository.ts CHANGED
@@ -13,7 +13,6 @@ import {
13
13
  } from "fast-json-patch";
14
14
  import { calculateCommitHash, Commit } from "./commit.js";
15
15
  import { History, Reference } from "./interfaces.js";
16
- import { compressSync, strToU8 } from "fflate";
17
16
  import {
18
17
  brancheNameToRef,
19
18
  cleanRefValue,
@@ -26,6 +25,7 @@ import {
26
25
  localHeadPathPrefix,
27
26
  mapPath,
28
27
  mutableMapCopy,
28
+ objectToTree,
29
29
  REFS_HEAD_KEY,
30
30
  REFS_MAIN_KEY,
31
31
  refsAtCommit,
@@ -429,9 +429,7 @@ export class Repository<T extends { [k: PropertyKey]: any }>
429
429
  timestamp,
430
430
  });
431
431
 
432
- const treeHash = Buffer.from(
433
- compressSync(strToU8(JSON.stringify(this.data)), { level: 6, mem: 8 }),
434
- ).toString("base64");
432
+ const treeHash = objectToTree(this.data);
435
433
  const commit = {
436
434
  hash: sha,
437
435
  message,
package/src/utils.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  // [RFC5322](https://www.ietf.org/rfc/rfc5322.txt)
2
2
  import { Commit } from "./commit.js";
3
3
  import { Reference } from "./interfaces.js";
4
- import { decompressSync, strFromU8 } from "fflate";
4
+ import { compressSync, decompressSync, strFromU8, strToU8 } from "fflate";
5
5
  import { validBranch, validRef } from "./ref.js";
6
6
  import { deepClone, Operation } from "fast-json-patch";
7
7
  import { RepositoryObject } from "./repository.js";
@@ -51,10 +51,16 @@ export const REFS_HEAD_KEY = "HEAD";
51
51
  * Should only be used in local context
52
52
  */
53
53
  export const REFS_MAIN_KEY = `${localHeadPathPrefix()}main`;
54
+
55
+ export function objectToTree(obj: any) {
56
+ return Buffer.from(
57
+ compressSync(strToU8(JSON.stringify(obj)), { level: 6, mem: 8 }),
58
+ ).toString("base64");
59
+ }
60
+
54
61
  export const treeToObject = <T = any>(tree: string): T => {
55
62
  return JSON.parse(strFromU8(decompressSync(Buffer.from(tree, "base64"))));
56
63
  };
57
-
58
64
  /**
59
65
  * Maps the path from a commit to another commit.
60
66
  * It travels backwards through parent relationships until the root state.
@@ -235,6 +241,7 @@ export const printChangeLog = <T extends { [k: string]: any }>(
235
241
  export const printChange = (chg: Operation) => {
236
242
  console.log(` ${JSON.stringify(chg)}`);
237
243
  };
244
+
238
245
  /**
239
246
  * Should be called with a `/` delimited ref path. E.g. refs/heads/main
240
247
  * @param thePath