Skip to content

Commit 7ae299e

Browse files
committed
Version: feat(core): improve inof/outof and add path method
- deep.ts: Changed inof/outof to return links instead of from/to objects - deep.ts: Added path() method to get path through contains relationships - tests/core.ts: Added tests for path() method - CONTRIBUTING.md: Added commit message template Breaking Changes: - inof() now returns links instead of from objects - outof() now returns links instead of to objects
1 parent bc7b356 commit 7ae299e

File tree

4 files changed

+70
-6
lines changed

4 files changed

+70
-6
lines changed

CONTRIBUTING.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,17 @@ yarn build
7878
2. Follow Deep relationship naming conventions:
7979
- Use PascalCase (capital first letter) for Type relationships (e.g., `Type`, `Contains`, `Value`)
8080
- Use camelCase (lowercase first letter) for instance relationships (e.g., `type`, `from`, `to`, `value`)
81+
82+
## Commits and Releases
83+
For publishing, it is necessary to:
84+
1. Increase the version level, usually patch
85+
2. Extract changes description from `git status` and `git diff` for all modified files
86+
3. Format the message according to the following template:
87+
```
88+
Version: type(scope): summary
89+
90+
body
91+
92+
Breaking Changes:
93+
- list of breaking changes (if any)
94+
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"title": "deep",
44
"appId": "com.deep_foundation.deep.app",
55
"macCategory": "public.app-category.developer-tools",
6-
"version": "7.0.0-alpha.5",
6+
"version": "7.0.0-alpha.6",
77
"description": "Universal solution for working with any meaning",
88
"license": "Unlicense",
99
"main": "dist/cli.js",

src/deep.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,7 +1629,7 @@ export class Deep {
16291629
const result = new Set<Deep>();
16301630
for (const link of this.in.call) {
16311631
if (link.type === type) {
1632-
result.add(link.from);
1632+
result.add(link);
16331633
}
16341634
}
16351635
return this.wrap(result);
@@ -1644,7 +1644,7 @@ export class Deep {
16441644
const result = new Set<Deep>();
16451645
for (const link of this.out.call) {
16461646
if (link.type === type) {
1647-
result.add(link.to);
1647+
result.add(link);
16481648
}
16491649
}
16501650
return this.wrap(result);
@@ -1937,6 +1937,35 @@ export class Deep {
19371937
}
19381938
return current;
19391939
}
1940+
1941+
/**
1942+
* Возвращает путь к текущему deep через входящие Contain связи
1943+
* @returns массив строк - путь через contains
1944+
*/
1945+
path(): string[] {
1946+
const result: string[] = [];
1947+
const exists = new Set<any>();
1948+
let current: Deep | undefined = this;
1949+
1950+
while (current) {
1951+
const contains = current.inof(this.deep.Contain);
1952+
if (!contains.size) break;
1953+
1954+
const contain = contains.first;
1955+
if (!contain) break;
1956+
1957+
// Находим ключ в contains, по которому хранится текущий deep
1958+
const from = contain.from;
1959+
if (!from) break;
1960+
1961+
if (exists.has(from)) break;
1962+
result.unshift(contain?.call);
1963+
exists.add(from);
1964+
current = from;
1965+
}
1966+
1967+
return result;
1968+
}
19401969
}
19411970

19421971
/**

src/tests/core.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -863,21 +863,42 @@ test('collection getters (types, froms, tos, typeds, outs, ins)', () => {
863863
test('go method', () => {
864864
const deep = new Deep();
865865

866-
// Создаем тестовую структуру
867866
const a = deep.new();
868867
deep.contains.a = a;
869868
const b = deep.new();
870869
a.contains.b = b;
871870
const c = deep.new();
872871
b.contains.c = c;
873872

874-
// Проверяем успешный поиск
875873
assert.equal(deep.go('a', 'b', 'c'), c);
876874
assert.equal(deep.go('a', 'b'), b);
877875
assert.equal(deep.go('a'), a);
878876

879-
// Проверяем неуспешный поиск
880877
assert.equal(deep.go('x'), undefined);
881878
assert.equal(deep.go('a', 'x'), undefined);
882879
assert.equal(deep.go('a', 'b', 'x'), undefined);
883880
});
881+
882+
test('path method', () => {
883+
const deep = new Deep();
884+
885+
const a = deep.new();
886+
deep.contains.a = a;
887+
const b = deep.new();
888+
a.contains.b = b;
889+
const c = deep.new();
890+
b.contains.c = c;
891+
892+
assert.deepEqual(c.path(), ['a', 'b', 'c']);
893+
assert.deepEqual(b.path(), ['a', 'b']);
894+
assert.deepEqual(a.path(), ['a']);
895+
assert.deepEqual(deep.path(), ['deep']);
896+
897+
const x = deep.new();
898+
deep.contains.x = x;
899+
const y = deep.new();
900+
x.contains.y = y;
901+
y.contains.c = c;
902+
903+
assert.deepEqual(c.path(), ['a', 'b', 'c']);
904+
});

0 commit comments

Comments
 (0)