@dotinc/ogre 0.1.0 → 0.2.0-canary.4f08867.0

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 (59) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/LICENSE +21 -0
  3. package/README.md +51 -0
  4. package/lib/commit.d.ts +3 -2
  5. package/lib/commit.js +3 -3
  6. package/lib/hash.d.ts +0 -0
  7. package/lib/hash.js +0 -0
  8. package/lib/index.d.ts +1 -0
  9. package/lib/index.js +1 -0
  10. package/lib/interfaces.d.ts +0 -0
  11. package/lib/interfaces.js +0 -0
  12. package/lib/ref.d.ts +0 -0
  13. package/lib/ref.js +0 -0
  14. package/lib/repository.d.ts +7 -0
  15. package/lib/repository.js +56 -42
  16. package/lib/size.d.ts +0 -0
  17. package/lib/size.js +0 -0
  18. package/lib/test.utils.d.ts +0 -0
  19. package/lib/test.utils.js +0 -0
  20. package/lib/utils.d.ts +1 -0
  21. package/lib/utils.js +27 -0
  22. package/package.json +6 -6
  23. package/src/commit.test.ts +10 -0
  24. package/src/commit.ts +3 -2
  25. package/src/index.ts +1 -0
  26. package/src/repository.test.ts +12 -0
  27. package/src/repository.ts +49 -33
  28. package/src/utils.test.ts +44 -0
  29. package/src/utils.ts +24 -0
  30. package/.nyc_output/34733e82-2b34-4674-aa72-94cab1c84e85.json +0 -1
  31. package/.nyc_output/3fb03278-d8e2-4673-abde-3cce50eb4143.json +0 -1
  32. package/.nyc_output/438de35e-20e6-470d-bfdb-d9b5fbc62f85.json +0 -1
  33. package/.nyc_output/61ba5903-4249-44c6-afe4-60e536bb69e0.json +0 -1
  34. package/.nyc_output/67c0b0a0-d3e0-4e7d-85e9-140cf10bf6e9.json +0 -1
  35. package/.nyc_output/77ec015f-70ab-47be-9757-17b5a39f4100.json +0 -1
  36. package/.nyc_output/processinfo/34733e82-2b34-4674-aa72-94cab1c84e85.json +0 -1
  37. package/.nyc_output/processinfo/3fb03278-d8e2-4673-abde-3cce50eb4143.json +0 -1
  38. package/.nyc_output/processinfo/438de35e-20e6-470d-bfdb-d9b5fbc62f85.json +0 -1
  39. package/.nyc_output/processinfo/61ba5903-4249-44c6-afe4-60e536bb69e0.json +0 -1
  40. package/.nyc_output/processinfo/67c0b0a0-d3e0-4e7d-85e9-140cf10bf6e9.json +0 -1
  41. package/.nyc_output/processinfo/77ec015f-70ab-47be-9757-17b5a39f4100.json +0 -1
  42. package/.nyc_output/processinfo/index.json +0 -1
  43. package/.turbo/turbo-build.log +0 -5
  44. package/coverage/lcov-report/base.css +0 -224
  45. package/coverage/lcov-report/block-navigation.js +0 -87
  46. package/coverage/lcov-report/commit.ts.html +0 -220
  47. package/coverage/lcov-report/favicon.png +0 -0
  48. package/coverage/lcov-report/hash.ts.html +0 -331
  49. package/coverage/lcov-report/index.html +0 -176
  50. package/coverage/lcov-report/prettify.css +0 -1
  51. package/coverage/lcov-report/prettify.js +0 -2
  52. package/coverage/lcov-report/ref.ts.html +0 -115
  53. package/coverage/lcov-report/repository.ts.html +0 -1648
  54. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  55. package/coverage/lcov-report/sorter.js +0 -196
  56. package/coverage/lcov-report/test.utils.ts.html +0 -223
  57. package/coverage/lcov.info +0 -660
  58. package/tsconfig.build.json +0 -6
  59. package/tsconfig.json +0 -16
package/CHANGELOG.md CHANGED
@@ -1,3 +1,33 @@
1
+ # v0.1.2 (Fri Mar 11 2022)
2
+
3
+ #### 🐛 Bug Fix
4
+
5
+ - fix: main package file ([@nadilas](https://github.com/nadilas))
6
+ - fix: move tslib to dependencies ([@nadilas](https://github.com/nadilas))
7
+
8
+ #### ⚠️ Pushed to `main`
9
+
10
+ - chore: clean published packaage ([@nadilas](https://github.com/nadilas))
11
+
12
+ #### Authors: 1
13
+
14
+ - [@nadilas](https://github.com/nadilas)
15
+
16
+ ---
17
+
18
+ # v0.1.1 (Fri Mar 11 2022)
19
+
20
+ #### ⚠️ Pushed to `main`
21
+
22
+ - Merge remote-tracking branch 'origin/main' ([@nadilas](https://github.com/nadilas))
23
+ - doc: add LICENSE and README.md ([@nadilas](https://github.com/nadilas))
24
+
25
+ #### Authors: 1
26
+
27
+ - [@nadilas](https://github.com/nadilas)
28
+
29
+ ---
30
+
1
31
  # v0.1.0 (Fri Mar 11 2022)
2
32
 
3
33
  #### 🚀 Enhancement
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 dot Industries, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # ogre
2
+
3
+ An in-memory git-like repository for objects for when you need to
4
+ keep the history around for a bit longer.
5
+
6
+ ## Features
7
+
8
+ - Commit
9
+ - Branch
10
+ - Checkout
11
+ - Merge
12
+ - fast-forward
13
+
14
+ ## Usage
15
+
16
+ ```typescript
17
+ const repo = new Repository(new ComplexObject())
18
+
19
+ // apply changes
20
+ repo.data.name = 'my name'
21
+ repo.data.description = 'now we have a description'
22
+
23
+ // commit changes
24
+ const init = await repo.commit('initial commit', 'author <author@test.com>')
25
+ // create a branch named savepoint pointing to the last commit
26
+ repo.createBranch('savepoint')
27
+
28
+ // switch to new branch
29
+ repo.checkout('add_details', true)
30
+
31
+ // apply changes
32
+ repo.data.name = 'a fancier name'
33
+
34
+ // a) commit & merge
35
+ await repo.commit('change name', 'author <author@test.com>')
36
+ repo.checkout('main')
37
+ repo.merge('add_details')
38
+
39
+ // or b) discard change and go back
40
+ // by using the branch name
41
+ repo.checkout('main')
42
+ // by using the commit hash in a detached state
43
+ repo.checkout(init)
44
+ ```
45
+
46
+ ## TODO
47
+
48
+ - [ ] Visualization
49
+ - [ ] Merge
50
+ - [ ] recursive
51
+ - [ ] octopus
package/lib/commit.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Change } from './interfaces';
2
2
  export interface Commit {
3
3
  hash: string;
4
+ tree: string;
4
5
  message: string | undefined;
5
6
  author: string;
6
7
  parent: string | undefined;
@@ -8,11 +9,11 @@ export interface Commit {
8
9
  timestamp: Date;
9
10
  to: number;
10
11
  }
11
- export interface HashContent {
12
+ export interface CommitHashContent {
12
13
  message: string;
13
14
  author: string;
14
15
  parentRef: string | undefined;
15
16
  changes: Change[];
16
17
  timestamp: Date;
17
18
  }
18
- export declare function calculateHash(content: HashContent): Promise<string>;
19
+ export declare function calculateCommitHash(content: CommitHashContent): Promise<string>;
package/lib/commit.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calculateHash = void 0;
3
+ exports.calculateCommitHash = void 0;
4
4
  const hash_1 = require("./hash");
5
- function calculateHash(content) {
5
+ function calculateCommitHash(content) {
6
6
  return (0, hash_1.digest)(content);
7
7
  }
8
- exports.calculateHash = calculateHash;
8
+ exports.calculateCommitHash = calculateCommitHash;
package/lib/hash.d.ts CHANGED
File without changes
package/lib/hash.js CHANGED
File without changes
package/lib/index.d.ts CHANGED
@@ -3,3 +3,4 @@ export * from './repository';
3
3
  export { Commit } from './commit';
4
4
  export * from './ref';
5
5
  export * from './size';
6
+ export * from './utils';
package/lib/index.js CHANGED
@@ -5,3 +5,4 @@ tslib_1.__exportStar(require("./interfaces"), exports);
5
5
  tslib_1.__exportStar(require("./repository"), exports);
6
6
  tslib_1.__exportStar(require("./ref"), exports);
7
7
  tslib_1.__exportStar(require("./size"), exports);
8
+ tslib_1.__exportStar(require("./utils"), exports);
File without changes
package/lib/interfaces.js CHANGED
File without changes
package/lib/ref.d.ts CHANGED
File without changes
package/lib/ref.js CHANGED
File without changes
@@ -1,5 +1,7 @@
1
1
  import { History } from './interfaces';
2
2
  import { Commit } from './commit';
3
+ export declare const REFS_HEAD_KEY = "HEAD";
4
+ export declare const REFS_MAIN_KEY: string;
3
5
  export interface RepositoryOptions<T> {
4
6
  history?: History;
5
7
  }
@@ -22,6 +24,11 @@ export interface RespositoryObjectType {
22
24
  * A repository recording and managing the state transitions of an object
23
25
  */
24
26
  export declare const Repository: RespositoryObjectType;
27
+ export declare const createHeadRefValue: (refKey: string) => string;
28
+ export declare const isTagRef: (refKey: string) => boolean;
29
+ export declare const cleanRefValue: (ref: string) => string;
30
+ export declare const brancheNameToRef: (name: string) => string;
31
+ export declare const validateBranchName: (name: string) => void;
25
32
  /**
26
33
  * Prints the underlying changelog of a repository
27
34
  * @param repository
package/lib/repository.js CHANGED
@@ -1,11 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.printChangeLog = exports.Repository = void 0;
3
+ exports.printChangeLog = exports.validateBranchName = exports.brancheNameToRef = exports.cleanRefValue = exports.isTagRef = exports.createHeadRefValue = exports.Repository = exports.REFS_MAIN_KEY = exports.REFS_HEAD_KEY = void 0;
4
4
  const commit_1 = require("./commit");
5
5
  const ref_1 = require("./ref");
6
- const REFS_HEAD = 'HEAD';
7
- const REFS_MAIN = 'refs/heads/main';
8
- const refPrefix = 'ref: ';
6
+ const hash_1 = require("./hash");
7
+ const tagRefPathPrefix = 'refs/tags/';
8
+ const headsRefPathPrefix = 'refs/heads/';
9
+ const headValueRefPrefix = 'ref: ';
10
+ exports.REFS_HEAD_KEY = 'HEAD';
11
+ exports.REFS_MAIN_KEY = `${headsRefPathPrefix}main`;
9
12
  /**
10
13
  * A repository recording and managing the state transitions of an object
11
14
  */
@@ -13,9 +16,9 @@ exports.Repository = function (obj, options) {
13
16
  var _a, _b, _c, _d;
14
17
  let savedLength;
15
18
  let version = 0;
16
- const refs = (_b = (_a = options.history) === null || _a === void 0 ? void 0 : _a.refs) !== null && _b !== void 0 ? _b : new Map([[REFS_HEAD, {
17
- name: REFS_HEAD,
18
- value: `ref: ${REFS_MAIN}`
19
+ const refs = (_b = (_a = options.history) === null || _a === void 0 ? void 0 : _a.refs) !== null && _b !== void 0 ? _b : new Map([[exports.REFS_HEAD_KEY, {
20
+ name: exports.REFS_HEAD_KEY,
21
+ value: `ref: ${exports.REFS_MAIN_KEY}`
19
22
  }]]);
20
23
  const changeLog = [];
21
24
  const targets = [];
@@ -105,28 +108,28 @@ exports.Repository = function (obj, options) {
105
108
  this.data = new Proxy(obj, handler);
106
109
  // region Read state read
107
110
  this.head = () => {
108
- const ref = refs.get(REFS_HEAD);
111
+ const ref = refs.get(exports.REFS_HEAD_KEY);
109
112
  if (!ref) {
110
113
  throw new Error(`unreachable: HEAD is not present`);
111
114
  }
112
- return cleanRefValue(ref.value);
115
+ return (0, exports.cleanRefValue)(ref.value);
113
116
  };
114
117
  this.ref = (reference) => {
115
118
  var _a;
116
119
  const ref = (_a = refs.get(reference)) === null || _a === void 0 ? void 0 : _a.value;
117
- return ref ? cleanRefValue(ref) : undefined;
120
+ return ref ? (0, exports.cleanRefValue)(ref) : undefined;
118
121
  };
119
122
  this.branch = () => {
120
- const currentHeadRef = refs.get(REFS_HEAD);
123
+ const currentHeadRef = refs.get(exports.REFS_HEAD_KEY);
121
124
  if (!currentHeadRef) {
122
125
  throw new Error('unreachable: ref HEAD not available');
123
126
  }
124
- if (currentHeadRef.value.includes(refPrefix)) {
125
- const refName = cleanRefValue(currentHeadRef.value);
127
+ if (currentHeadRef.value.includes(headValueRefPrefix)) {
128
+ const refName = (0, exports.cleanRefValue)(currentHeadRef.value);
126
129
  if (refs.has(refName))
127
130
  return getLastItem(refName);
128
131
  }
129
- return REFS_HEAD; // detached state
132
+ return exports.REFS_HEAD_KEY; // detached state
130
133
  };
131
134
  // endregion
132
135
  // region History functions
@@ -176,7 +179,7 @@ exports.Repository = function (obj, options) {
176
179
  };
177
180
  // region Commit lookups
178
181
  const commitAtHead = () => {
179
- return commitAtHeadIn(REFS_HEAD, refs, commits);
182
+ return commitAtRefIn(exports.REFS_HEAD_KEY, refs, commits);
180
183
  };
181
184
  const mustCommitAtHead = () => {
182
185
  const commitHead = commitAtHead();
@@ -202,13 +205,14 @@ exports.Repository = function (obj, options) {
202
205
  }
203
206
  const timestamp = new Date();
204
207
  const changes = [...changesSinceLastCommit];
205
- const sha = await (0, commit_1.calculateHash)({
208
+ const sha = await (0, commit_1.calculateCommitHash)({
206
209
  message,
207
210
  author,
208
211
  changes,
209
212
  parentRef: parent === null || parent === void 0 ? void 0 : parent.hash,
210
213
  timestamp
211
214
  });
215
+ const treeHash = await (0, hash_1.digest)(obj);
212
216
  const commit = {
213
217
  hash: sha,
214
218
  message,
@@ -216,7 +220,8 @@ exports.Repository = function (obj, options) {
216
220
  changes: changes,
217
221
  parent: parent === null || parent === void 0 ? void 0 : parent.hash,
218
222
  timestamp,
219
- to: version
223
+ to: version,
224
+ tree: treeHash
220
225
  };
221
226
  if (amend) {
222
227
  const idx = commits.findIndex(c => c === parent);
@@ -230,30 +235,30 @@ exports.Repository = function (obj, options) {
230
235
  }
231
236
  else {
232
237
  // move detached HEAD to new commit
233
- moveRef(REFS_HEAD, commit);
238
+ moveRef(exports.REFS_HEAD_KEY, commit);
234
239
  }
235
240
  return sha;
236
241
  };
237
242
  // region Graph manipulation
238
243
  this.checkout = (shaish, createBranch = false) => {
239
244
  if (createBranch) {
240
- validateBranchName(shaish);
241
- let branchRef = brancheNameToRef(shaish);
245
+ (0, exports.validateBranchName)(shaish);
246
+ let branchRef = (0, exports.brancheNameToRef)(shaish);
242
247
  const commit = commitAtHead();
243
248
  if (commit) {
244
249
  moveRef(branchRef, commit);
245
250
  }
246
- moveRef(REFS_HEAD, branchRef);
251
+ moveRef(exports.REFS_HEAD_KEY, branchRef);
247
252
  }
248
253
  else {
249
254
  const [commit, isRef, refKey] = shaishToCommit(shaish, refs, commits);
250
255
  rebuildChangeLog(commit);
251
- moveRef(REFS_HEAD, isRef && refKey !== undefined ? refKey : commit);
256
+ moveRef(exports.REFS_HEAD_KEY, isRef && refKey !== undefined ? refKey : commit);
252
257
  }
253
258
  };
254
259
  this.createBranch = (name) => {
255
- validateBranchName(name);
256
- const refName = brancheNameToRef(name);
260
+ (0, exports.validateBranchName)(name);
261
+ const refName = (0, exports.brancheNameToRef)(name);
257
262
  const headCommit = commitAtHead();
258
263
  if (!headCommit) {
259
264
  const headRef = this.head();
@@ -267,7 +272,7 @@ exports.Repository = function (obj, options) {
267
272
  };
268
273
  const moveRef = (refName, value) => {
269
274
  let ref = refs.get(refName);
270
- const val = typeof value === 'string' ? `${refPrefix}${value}` : value.hash;
275
+ const val = typeof value === 'string' ? (0, exports.createHeadRefValue)(value) : value.hash;
271
276
  if (!ref) {
272
277
  ref = { name: getLastItem(refName), value: val };
273
278
  }
@@ -283,7 +288,7 @@ exports.Repository = function (obj, options) {
283
288
  // for fancier merge tree
284
289
  // https://github.com/isomorphic-git/isomorphic-git/blob/a623133345a5d8b6bb7a8352ea9702ce425d8266/src/utils/mergeTree.js#L33
285
290
  if (typeof source !== 'string') {
286
- // const srcHead = commitAtHeadIn(REFS_HEAD, src.refs, src.commits)
291
+ // const srcHead = commitAtRefIn(REFS_HEAD, src.refs, src.commits)
287
292
  throw new Error(`fatal: source type (${source instanceof exports.Repository ? 'Repository' : 'History'}) not implemented`);
288
293
  }
289
294
  const [srcCommit] = shaishToCommit(source, refs, commits);
@@ -331,15 +336,6 @@ exports.Repository = function (obj, options) {
331
336
  }
332
337
  };
333
338
  const getLastItem = (thePath) => thePath.substring(thePath.lastIndexOf('/') + 1);
334
- const cleanRefValue = (ref) => ref.replace(refPrefix, '');
335
- const brancheNameToRef = (name) => {
336
- return `refs/heads/${name}`;
337
- };
338
- const validateBranchName = (name) => {
339
- if (!(0, ref_1.validBranch)(name)) {
340
- throw new Error(`invalid ref name`);
341
- }
342
- };
343
339
  /**
344
340
  * Traverses the commit tree backwards and reassembles the changelog
345
341
  * @param commit
@@ -370,14 +366,14 @@ const mapPath = (from, to, commits) => {
370
366
  * @param references
371
367
  * @param commitsList
372
368
  */
373
- const commitAtHeadIn = (ref, references, commitsList) => {
369
+ const commitAtRefIn = (ref, references, commitsList) => {
374
370
  const reference = references.get(ref);
375
371
  if (!reference) {
376
372
  throw new Error(`unreachable: '${ref}' is not present`);
377
373
  }
378
374
  let commitHash;
379
- if (reference.value.includes(refPrefix)) {
380
- const refKey = cleanRefValue(reference.value);
375
+ if (reference.value.includes(headValueRefPrefix)) {
376
+ const refKey = (0, exports.cleanRefValue)(reference.value);
381
377
  const targetRef = references.get(refKey);
382
378
  if (!targetRef) {
383
379
  // target branch may not have been saved yet
@@ -412,9 +408,9 @@ const shaishToCommit = (shaish, references, commitsList) => {
412
408
  isRef = true;
413
409
  refKey = name;
414
410
  sha = ref.value;
415
- if (sha.includes(refPrefix)) {
416
- const cleanedRef = cleanRefValue(sha);
417
- const c = commitAtHeadIn(cleanedRef, references, commitsList);
411
+ if (sha.includes(headValueRefPrefix)) {
412
+ const cleanedRef = (0, exports.cleanRefValue)(sha);
413
+ const c = commitAtRefIn(cleanedRef, references, commitsList);
418
414
  if (!c) {
419
415
  throw new Error(`${cleanedRef} points to non-existing commit`);
420
416
  }
@@ -434,6 +430,24 @@ const shaishToCommit = (shaish, references, commitsList) => {
434
430
  }
435
431
  return [found[0], isRef, refKey];
436
432
  };
433
+ const createHeadRefValue = (refKey) => {
434
+ return `${headValueRefPrefix}${refKey}`;
435
+ };
436
+ exports.createHeadRefValue = createHeadRefValue;
437
+ const isTagRef = (refKey) => refKey.indexOf(tagRefPathPrefix) > -1;
438
+ exports.isTagRef = isTagRef;
439
+ const cleanRefValue = (ref) => ref.replace(headValueRefPrefix, '');
440
+ exports.cleanRefValue = cleanRefValue;
441
+ const brancheNameToRef = (name) => {
442
+ return `${headsRefPathPrefix}${name}`;
443
+ };
444
+ exports.brancheNameToRef = brancheNameToRef;
445
+ const validateBranchName = (name) => {
446
+ if (!(0, ref_1.validBranch)(name)) {
447
+ throw new Error(`invalid ref name`);
448
+ }
449
+ };
450
+ exports.validateBranchName = validateBranchName;
437
451
  /**
438
452
  * Prints the underlying changelog of a repository
439
453
  * @param repository
@@ -442,7 +456,7 @@ const printChangeLog = (repository) => {
442
456
  console.log('----------------------------------------------------------');
443
457
  console.log(`Changelog at ${repository.head()}`);
444
458
  const history = repository.getHistory();
445
- const head = commitAtHeadIn(repository.head(), history.refs, history.commits);
459
+ const head = commitAtRefIn(repository.head(), history.refs, history.commits);
446
460
  if (!head) {
447
461
  throw new Error(`fatal: HEAD is not defined`);
448
462
  }
package/lib/size.d.ts CHANGED
File without changes
package/lib/size.js CHANGED
File without changes
File without changes
package/lib/test.utils.js CHANGED
File without changes
package/lib/utils.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const cleanAuthor: (author: string) => [name: string, email: string];
package/lib/utils.js ADDED
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cleanAuthor = void 0;
4
+ // [RFC5322](https://www.ietf.org/rfc/rfc5322.txt)
5
+ const emailRegex = /(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/;
6
+ const cleanAuthor = (author) => {
7
+ if (author === '') {
8
+ throw new Error(`author not provided`);
9
+ }
10
+ // author name <email>
11
+ let strings = author.split(' <');
12
+ if (strings.length > 1) {
13
+ return [strings[0], strings[1].replace('>', '')];
14
+ }
15
+ // author name @handle
16
+ strings = author.split(' @');
17
+ if (strings.length > 1) {
18
+ return [strings[0], `@${strings[1]}`];
19
+ }
20
+ // email@domain.com
21
+ if (emailRegex.test(author)) {
22
+ return ['', author];
23
+ }
24
+ // unrecognized format
25
+ return [author, ''];
26
+ };
27
+ exports.cleanAuthor = cleanAuthor;
package/package.json CHANGED
@@ -4,9 +4,9 @@
4
4
  "type": "git",
5
5
  "url": "https://github.com/dotindustries/ogre.git"
6
6
  },
7
- "version": "0.1.0",
7
+ "version": "0.2.0-canary.4f08867.0",
8
8
  "description": "Git-like repository for in-memory object versioning",
9
- "main": "lib/index.ts",
9
+ "main": "lib/index.js",
10
10
  "types": "lib/index.d.ts",
11
11
  "scripts": {
12
12
  "build": "tsc -p tsconfig.build.json",
@@ -28,16 +28,16 @@
28
28
  },
29
29
  "author": "János Veres @nadilas",
30
30
  "license": "MIT",
31
+ "dependencies": {
32
+ "tslib": "^2.3.1"
33
+ },
31
34
  "devDependencies": {
32
35
  "@ava/typescript": "^3.0.1",
33
36
  "@types/node": "^17.0.21",
34
37
  "@types/uuid": "^8.3.4",
35
38
  "ava": "^4.0.1",
36
- "coveralls": "^3.1.1",
37
39
  "nyc": "^15.1.0",
38
40
  "ts-node": "^10.7.0",
39
- "tslib": "^2.3.1",
40
- "turbo": "^1.1.5",
41
41
  "typescript": "^4.5.5",
42
42
  "uuid": "^8.3.2"
43
43
  },
@@ -45,5 +45,5 @@
45
45
  "registry": "https://registry.npmjs.org/",
46
46
  "access": "public"
47
47
  },
48
- "gitHead": "d1ea04300335cd7618f4cf66251123f489d17b1c"
48
+ "gitHead": "4f08867076b586c0be8dbfe673194ca89c8283d9"
49
49
  }
@@ -32,6 +32,16 @@ test('no commit without changes after recent commit', async t => {
32
32
  return await repo.commit('baseline', testAuthor)
33
33
  }, { message: 'no changes to commit' })
34
34
  })
35
+
36
+ test('treeHash of commit is matching content', async t => {
37
+ const [repo] = await getBaseline()
38
+ repo.data.name = 'new name'
39
+ await repo.commit('baseline', testAuthor)
40
+ const {commits} = repo.getHistory()
41
+ t.is(commits.length, 1)
42
+ t.not(commits[0].tree, '', 'tree hash mismatch')
43
+ })
44
+
35
45
  test('no commit --amend without commit', async t => {
36
46
  const [repo] = await getBaseline()
37
47
  repo.data.name = 'new name'
package/src/commit.ts CHANGED
@@ -10,6 +10,7 @@ export interface Commit {
10
10
  // - author commit timestamp with timezone
11
11
  // - commit message
12
12
  hash: string
13
+ tree: string
13
14
 
14
15
  message: string | undefined
15
16
  author: string
@@ -32,7 +33,7 @@ export interface Commit {
32
33
  to: number;
33
34
  }
34
35
 
35
- export interface HashContent {
36
+ export interface CommitHashContent {
36
37
  message: string
37
38
  author: string
38
39
  parentRef: string | undefined
@@ -40,6 +41,6 @@ export interface HashContent {
40
41
  timestamp: Date
41
42
  }
42
43
 
43
- export function calculateHash(content: HashContent) {
44
+ export function calculateCommitHash(content: CommitHashContent) {
44
45
  return digest(content)
45
46
  }
package/src/index.ts CHANGED
@@ -3,3 +3,4 @@ export * from './repository'
3
3
  export {Commit} from './commit'
4
4
  export * from './ref'
5
5
  export * from './size'
6
+ export * from './utils'
@@ -24,3 +24,15 @@ test('reconstruction', async t => {
24
24
  t.is(history2.commits.length, 2, 'incorrect # of commits')
25
25
  t.is(sumChanges(history2.commits), changeEntries, 'incorrect # of changelog entries')
26
26
  })
27
+
28
+ test('history contains HEAD ref', async t => {
29
+ const [repo] = await getBaseline()
30
+
31
+ t.is(repo.head(), 'refs/heads/main')
32
+
33
+ const history = repo.getHistory()
34
+ let headRef = history.refs.get('HEAD')
35
+ t.not(headRef, undefined)
36
+ t.is(headRef!.name, 'HEAD')
37
+ t.is(headRef!.value, 'ref: refs/heads/main')
38
+ })