@dotinc/ogre 0.5.0 → 0.6.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.
- package/.tap/processinfo/{6d907291-2f1e-4670-b04c-3a667271c352.json → 31ca0767-30d5-4c1b-aab3-1a456fd51558.json} +6 -6
- package/.tap/processinfo/{4cdc23d3-f7ce-4075-922f-722bf0d687fc.json → 52683acc-91e1-4d54-9715-1cbaf91964a7.json} +6 -6
- package/.tap/processinfo/{8c48e5e9-6eca-4afe-a7b5-04e26b765d29.json → 65d66b6b-127f-4a35-b64a-5b0ac1df524c.json} +22 -22
- package/.tap/processinfo/{7dc6b1af-ac78-47bc-9b62-630e387e8755.json → 77376985-2ddf-4b47-9631-c637b0ecbcdd.json} +6 -6
- package/.tap/processinfo/{0799a6bd-022f-41d1-8be9-6338667041c0.json → 86009ac9-5819-45bf-b53f-0448d4b7ef56.json} +6 -6
- package/.tap/processinfo/{8ca695ae-d038-441a-b4ab-2a242d22d416.json → 9e67801c-9248-4793-994c-a9b4f59ebc4f.json} +6 -6
- package/.tap/processinfo/{98475c49-5ee5-4c2c-b8e2-85bd2af528c9.json → f9080426-4139-4a9a-a59f-ccbfa4cadf7d.json} +13 -13
- package/.tap/test-results/src/branch.test.ts.tap +6 -6
- package/.tap/test-results/src/checkout.test.ts.tap +9 -9
- package/.tap/test-results/src/commit.test.ts.tap +24 -16
- package/.tap/test-results/src/merge.test.ts.tap +2 -2
- package/.tap/test-results/src/repository.test.ts.tap +86 -12
- package/.tap/test-results/src/tag.test.ts.tap +3 -3
- package/.tap/test-results/src/utils.test.ts.tap +7 -7
- package/CHANGELOG.md +13 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +5 -0
- package/lib/repository.d.ts +13 -1
- package/lib/repository.js +34 -20
- package/lib/test.utils.d.ts +1 -4
- package/lib/test.utils.js +2 -1
- package/package.json +2 -2
- package/src/commit.test.ts +18 -0
- package/src/index.ts +2 -0
- package/src/repository.test.ts +146 -1
- package/src/repository.ts +51 -21
- package/src/test.utils.ts +4 -3
package/src/repository.ts
CHANGED
|
@@ -7,6 +7,9 @@ import {
|
|
|
7
7
|
generate,
|
|
8
8
|
Observer,
|
|
9
9
|
Operation,
|
|
10
|
+
validate,
|
|
11
|
+
applyPatch,
|
|
12
|
+
JsonPatchError,
|
|
10
13
|
} from "fast-json-patch";
|
|
11
14
|
import { calculateCommitHash, Commit } from "./commit";
|
|
12
15
|
import { History, Reference } from "./interfaces";
|
|
@@ -37,6 +40,17 @@ export interface RepositoryObject<T extends { [k: string]: any }> {
|
|
|
37
40
|
*/
|
|
38
41
|
diff(shaishFrom: string, shaishTo?: string): Operation[];
|
|
39
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Returns pending changes.
|
|
45
|
+
*/
|
|
46
|
+
status(): Operation[];
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Applies a patch to the repository's HEAD
|
|
50
|
+
* @param patch
|
|
51
|
+
*/
|
|
52
|
+
apply(patch: Operation[]): void;
|
|
53
|
+
|
|
40
54
|
// It returns the reference where we are currently at
|
|
41
55
|
head(): string;
|
|
42
56
|
|
|
@@ -116,11 +130,20 @@ export class Repository<T extends { [k: PropertyKey]: any }>
|
|
|
116
130
|
if (!patchToTarget || patchToTarget.length < 1) {
|
|
117
131
|
return;
|
|
118
132
|
}
|
|
119
|
-
|
|
133
|
+
this.observer.unobserve();
|
|
120
134
|
patchToTarget.reduce(applyReducer, this.data);
|
|
121
135
|
this.observer = observe(this.data);
|
|
122
136
|
}
|
|
123
137
|
|
|
138
|
+
apply(patch: Operation[]): JsonPatchError | undefined {
|
|
139
|
+
const err = validate(patch, this.data);
|
|
140
|
+
if (err) {
|
|
141
|
+
return err;
|
|
142
|
+
}
|
|
143
|
+
applyPatch(this.data, patch);
|
|
144
|
+
// const changed = patch.reduce(applyReducer, this.data);
|
|
145
|
+
}
|
|
146
|
+
|
|
124
147
|
reset(
|
|
125
148
|
mode: "soft" | "hard" | undefined = "hard",
|
|
126
149
|
shaish: string | undefined = REFS_HEAD_KEY,
|
|
@@ -161,6 +184,15 @@ export class Repository<T extends { [k: PropertyKey]: any }>
|
|
|
161
184
|
return REFS_HEAD_KEY; // detached state
|
|
162
185
|
}
|
|
163
186
|
|
|
187
|
+
status() {
|
|
188
|
+
const commit = this.commitAtHead();
|
|
189
|
+
if (!commit) {
|
|
190
|
+
// on root repo return the pending changes
|
|
191
|
+
return compare(this.original, this.data); // this.observer.patches is empty?? :(
|
|
192
|
+
}
|
|
193
|
+
return this.diff(commit.hash);
|
|
194
|
+
}
|
|
195
|
+
|
|
164
196
|
diff(shaishFrom: string, shaishTo?: string): Operation[] {
|
|
165
197
|
const [cFrom] = shaishToCommit(shaishFrom, this.refs, this.commits);
|
|
166
198
|
let target: T;
|
|
@@ -455,21 +487,6 @@ const treeToObject = <T = any>(tree: string): T => {
|
|
|
455
487
|
const getLastItem = (thePath: string) =>
|
|
456
488
|
thePath.substring(thePath.lastIndexOf("/") + 1);
|
|
457
489
|
|
|
458
|
-
/**
|
|
459
|
-
* Traverses the commit tree backwards and reassembles the changelog
|
|
460
|
-
* @param commit
|
|
461
|
-
* @param commitsList
|
|
462
|
-
*/
|
|
463
|
-
const traverseAndCollectChangelog = (commit: Commit, commitsList: Commit[]) => {
|
|
464
|
-
let c: Commit | undefined = commit;
|
|
465
|
-
let clog: Operation[] = [];
|
|
466
|
-
while (c !== undefined) {
|
|
467
|
-
clog = [...commit.changes, ...clog];
|
|
468
|
-
c = commitsList.find((parent) => parent.hash === c?.parent);
|
|
469
|
-
}
|
|
470
|
-
return clog;
|
|
471
|
-
};
|
|
472
|
-
|
|
473
490
|
const mapPath = (
|
|
474
491
|
from: Commit,
|
|
475
492
|
to: Commit,
|
|
@@ -613,16 +630,29 @@ export const printChangeLog = <T extends { [k: string]: any }>(
|
|
|
613
630
|
repository: RepositoryObject<T>,
|
|
614
631
|
) => {
|
|
615
632
|
console.log("----------------------------------------------------------");
|
|
616
|
-
console.log(
|
|
633
|
+
console.log("Changelog");
|
|
634
|
+
console.log("----------------------------------------------------------");
|
|
617
635
|
const history = repository.getHistory();
|
|
618
636
|
const head = commitAtRefIn(repository.head(), history.refs, history.commits);
|
|
619
637
|
if (!head) {
|
|
620
638
|
throw new Error(`fatal: HEAD is not defined`);
|
|
621
639
|
}
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
console.log(
|
|
640
|
+
let c: Commit | undefined = head;
|
|
641
|
+
while (c) {
|
|
642
|
+
console.log(
|
|
643
|
+
`${c.hash} ${refsAtCommit(history.refs, c)
|
|
644
|
+
.map((r) => r.name)
|
|
645
|
+
.join(" ")}`,
|
|
646
|
+
);
|
|
647
|
+
for (const chg of c.changes) {
|
|
648
|
+
printChange(chg);
|
|
649
|
+
}
|
|
650
|
+
c = history.commits.find((parent) => parent.hash === c?.parent);
|
|
625
651
|
}
|
|
626
|
-
|
|
652
|
+
console.log("End of changelog");
|
|
627
653
|
console.log("----------------------------------------------------------");
|
|
628
654
|
};
|
|
655
|
+
|
|
656
|
+
export const printChange = (chg: Operation) => {
|
|
657
|
+
console.log(` ${JSON.stringify(chg)}`);
|
|
658
|
+
};
|
package/src/test.utils.ts
CHANGED
|
@@ -16,14 +16,15 @@ export type ComplexObject = {
|
|
|
16
16
|
|
|
17
17
|
export const testAuthor = "User name <name@domain.com>";
|
|
18
18
|
|
|
19
|
-
export async function getBaseline(
|
|
20
|
-
|
|
21
|
-
> {
|
|
19
|
+
export async function getBaseline(
|
|
20
|
+
obj?: Partial<ComplexObject>,
|
|
21
|
+
): Promise<[RepositoryObject<ComplexObject>, ComplexObject]> {
|
|
22
22
|
const co: ComplexObject = {
|
|
23
23
|
uuid: undefined,
|
|
24
24
|
name: undefined,
|
|
25
25
|
description: undefined,
|
|
26
26
|
nested: [],
|
|
27
|
+
...obj,
|
|
27
28
|
};
|
|
28
29
|
const repo = new Repository(co, {});
|
|
29
30
|
return [repo, co];
|