@ldsg/cli 0.3.31 → 0.3.33
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/.rush/temp/package-deps_build.json +27 -27
- package/.rush/temp/shrinkwrap-deps.json +58 -3
- package/.tsbuildinfo +1 -1
- package/CHANGELOG.json +52 -0
- package/CHANGELOG.md +15 -1
- package/README.md +5 -2
- package/dist/__tests__/commands.test.js +104 -104
- package/dist/__tests__/formatter.test.js +66 -63
- package/dist/__tests__/formatter.test.js.map +1 -1
- package/dist/__tests__/json-file-mutator.test.js +48 -45
- package/dist/__tests__/json-file-mutator.test.js.map +1 -1
- package/dist/__tests__/source-resolver.test.js +39 -39
- package/dist/cli.js +89 -89
- package/dist/cli.js.map +1 -1
- package/dist/commands/resource/convert.d.ts +1 -1
- package/dist/commands/resource/convert.js +9 -7
- package/dist/commands/resource/convert.js.map +1 -1
- package/dist/commands/resource/create.d.ts +2 -2
- package/dist/commands/resource/create.js +5 -5
- package/dist/commands/resource/delete.d.ts +2 -2
- package/dist/commands/resource/delete.js.map +1 -1
- package/dist/commands/resource/diff.d.ts +2 -2
- package/dist/commands/resource/diff.js +8 -8
- package/dist/commands/resource/get.d.ts +1 -1
- package/dist/commands/resource/list.d.ts +2 -2
- package/dist/commands/resource/list.js +11 -11
- package/dist/commands/resource/list.js.map +1 -1
- package/dist/commands/resource/tree.d.ts +1 -1
- package/dist/commands/resource/update.d.ts +2 -2
- package/dist/commands/resource/update.js +1 -1
- package/dist/constants.js +2 -2
- package/dist/types/get-extend-app-data-params.d.ts +2 -2
- package/dist/types/resource-record.d.ts +2 -2
- package/dist/utils/formatter.d.ts +1 -1
- package/dist/utils/formatter.js +25 -25
- package/dist/utils/get-extend-app-data-params-using-npm-ldsg-module.d.ts +1 -1
- package/dist/utils/get-extend-app-data-params-using-npm-ldsg-module.js +12 -12
- package/dist/utils/get-extend-app-data-params-using-npm-ldsg-module.js.map +1 -1
- package/dist/utils/get-extend-app-data-params-using-workspace-ldsg-module/index.d.ts +1 -1
- package/dist/utils/get-extend-app-data-params-using-workspace-ldsg-module/index.js +20 -20
- package/dist/utils/get-extend-app-data-params-using-workspace-ldsg-module/index.js.map +1 -1
- package/dist/utils/json-file-mutator.d.ts +2 -2
- package/dist/utils/json-file-mutator.js +4 -4
- package/dist/utils/json-file-mutator.js.map +1 -1
- package/dist/utils/source-resolver.d.ts +1 -1
- package/dist/utils/source-resolver.js +15 -15
- package/dist/utils/source-resolver.js.map +1 -1
- package/jest.config.js +8 -8
- package/package.json +13 -10
- package/src/__tests__/commands.test.ts +116 -116
- package/src/__tests__/formatter.test.ts +68 -65
- package/src/__tests__/json-file-mutator.test.ts +57 -52
- package/src/__tests__/source-resolver.test.ts +43 -43
- package/src/cli.ts +132 -114
- package/src/commands/resource/convert.ts +13 -11
- package/src/commands/resource/create.ts +8 -8
- package/src/commands/resource/delete.ts +6 -4
- package/src/commands/resource/diff.ts +10 -10
- package/src/commands/resource/get.ts +2 -2
- package/src/commands/resource/list.ts +20 -18
- package/src/commands/resource/tree.ts +2 -2
- package/src/commands/resource/update.ts +4 -4
- package/src/constants.ts +2 -2
- package/src/types/get-extend-app-data-params.ts +5 -3
- package/src/types/resource-record.ts +2 -2
- package/src/utils/formatter.ts +27 -27
- package/src/utils/get-extend-app-data-params-using-npm-ldsg-module.ts +20 -16
- package/src/utils/get-extend-app-data-params-using-workspace-ldsg-module/index.ts +28 -26
- package/src/utils/json-file-mutator.ts +18 -12
- package/src/utils/source-resolver.ts +26 -21
package/CHANGELOG.json
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ldsg/cli",
|
|
3
3
|
"entries": [
|
|
4
|
+
{
|
|
5
|
+
"version": "0.3.33",
|
|
6
|
+
"tag": "@ldsg/cli_v0.3.33",
|
|
7
|
+
"date": "Sat, 08 Aug 2026 04:31:45 GMT",
|
|
8
|
+
"comments": {
|
|
9
|
+
"patch": [
|
|
10
|
+
{
|
|
11
|
+
"comment": "发布更新"
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"dependency": [
|
|
15
|
+
{
|
|
16
|
+
"comment": "Updating dependency \"@ldsg/apaas-to-runtime\" to `0.3.33`"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"comment": "Updating dependency \"@ldsg/constants\" to `0.3.33`"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"comment": "Updating dependency \"@ldsg/utils\" to `0.3.33`"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"comment": "Updating dependency \"@ldsg/types\" to `0.3.33`"
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"version": "0.3.32",
|
|
32
|
+
"tag": "@ldsg/cli_v0.3.32",
|
|
33
|
+
"date": "Fri, 07 Aug 2026 01:06:09 GMT",
|
|
34
|
+
"comments": {
|
|
35
|
+
"patch": [
|
|
36
|
+
{
|
|
37
|
+
"comment": "发布更新"
|
|
38
|
+
}
|
|
39
|
+
],
|
|
40
|
+
"dependency": [
|
|
41
|
+
{
|
|
42
|
+
"comment": "Updating dependency \"@ldsg/apaas-to-runtime\" to `0.3.32`"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"comment": "Updating dependency \"@ldsg/constants\" to `0.3.32`"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"comment": "Updating dependency \"@ldsg/utils\" to `0.3.32`"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"comment": "Updating dependency \"@ldsg/types\" to `0.3.32`"
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
},
|
|
4
56
|
{
|
|
5
57
|
"version": "0.3.31",
|
|
6
58
|
"tag": "@ldsg/cli_v0.3.31",
|
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
# Change Log - @ldsg/cli
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Sat, 08 Aug 2026 04:31:45 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 0.3.33
|
|
6
|
+
Sat, 08 Aug 2026 04:31:45 GMT
|
|
7
|
+
|
|
8
|
+
### Patches
|
|
9
|
+
|
|
10
|
+
- 发布更新
|
|
11
|
+
|
|
12
|
+
## 0.3.32
|
|
13
|
+
Fri, 07 Aug 2026 01:06:09 GMT
|
|
14
|
+
|
|
15
|
+
### Patches
|
|
16
|
+
|
|
17
|
+
- 发布更新
|
|
4
18
|
|
|
5
19
|
## 0.3.31
|
|
6
20
|
Mon, 03 Aug 2026 13:30:44 GMT
|
package/README.md
CHANGED
|
@@ -19,12 +19,12 @@ pnpm build
|
|
|
19
19
|
# 实例
|
|
20
20
|
# 单命令
|
|
21
21
|
pnpm fetch-app-data \
|
|
22
|
-
--app-data-uri https://api
|
|
22
|
+
--app-data-uri https://api.ldsgy.com/projects/691e7be28bcc5027fa90caa8/app_data?secret_key=Je2hmI8tATgC3clBuBo2q0GIPgNO3vyytfK5seiLtWbZRwv4xGyYt1N \
|
|
23
23
|
&& pnpm prepare-app-code && pnpm build
|
|
24
24
|
|
|
25
25
|
# 多命令
|
|
26
26
|
pnpm fetch-app-data \
|
|
27
|
-
--app-data-uri https://api
|
|
27
|
+
--app-data-uri https://api.ldsgy.com/projects/691e7be28bcc5027fa90caa8/app_data?secret_key=Je2hmI8tATgC3clBuBo2q0GIPgNO3vyytfK5seiLtWbZRwv4xGyYt1N
|
|
28
28
|
pnpm prepare-app-code
|
|
29
29
|
pnpm build
|
|
30
30
|
```
|
|
@@ -59,4 +59,7 @@ pnpm start
|
|
|
59
59
|
# 用本地数据库测试启动,需要移除资源中的数据库配置
|
|
60
60
|
pnpm start:test
|
|
61
61
|
```
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
|
|
62
65
|
```
|
|
@@ -9,206 +9,206 @@ const update_1 = require("../commands/resource/update");
|
|
|
9
9
|
const delete_1 = require("../commands/resource/delete");
|
|
10
10
|
const diff_1 = require("../commands/resource/diff");
|
|
11
11
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
12
|
-
jest.mock(
|
|
12
|
+
jest.mock("fs-extra");
|
|
13
13
|
const mockedFs = fs_extra_1.default;
|
|
14
14
|
const sampleRecords = [
|
|
15
|
-
{ id:
|
|
16
|
-
{ id:
|
|
17
|
-
{ id:
|
|
18
|
-
{ id:
|
|
19
|
-
{ id:
|
|
20
|
-
{ id:
|
|
15
|
+
{ id: "app1", kind: "application", parentId: null, settings: { title: "My App" } },
|
|
16
|
+
{ id: "form1", kind: "form", parentId: "app1", settings: { title: "Login Form" } },
|
|
17
|
+
{ id: "form2", kind: "form", parentId: "app1", settings: { title: "Register Form" } },
|
|
18
|
+
{ id: "table1", kind: "table", parentId: "app1", settings: { title: "Users" } },
|
|
19
|
+
{ id: "field1", kind: "field", parentId: "table1", settings: { title: "Name" } },
|
|
20
|
+
{ id: "field2", kind: "field", parentId: "table1", settings: { title: "Email" } },
|
|
21
21
|
];
|
|
22
22
|
const sourceData = {
|
|
23
23
|
resourceRecords: sampleRecords,
|
|
24
|
-
format:
|
|
25
|
-
filePath:
|
|
24
|
+
format: "array",
|
|
25
|
+
filePath: "/test/data.json",
|
|
26
26
|
};
|
|
27
|
-
describe(
|
|
27
|
+
describe("commands", () => {
|
|
28
28
|
beforeEach(() => {
|
|
29
29
|
jest.resetAllMocks();
|
|
30
30
|
mockedFs.readJson.mockResolvedValue([...sampleRecords]);
|
|
31
31
|
});
|
|
32
|
-
describe(
|
|
33
|
-
it(
|
|
32
|
+
describe("listResources", () => {
|
|
33
|
+
it("should return all records without filter", async () => {
|
|
34
34
|
const result = await (0, list_1.listResources)(sampleRecords, {});
|
|
35
35
|
expect(result.total).toBe(6);
|
|
36
36
|
expect(result.resources).toHaveLength(6);
|
|
37
37
|
});
|
|
38
|
-
it(
|
|
39
|
-
const result = await (0, list_1.listResources)(sampleRecords, { kind:
|
|
38
|
+
it("should filter by kind", async () => {
|
|
39
|
+
const result = await (0, list_1.listResources)(sampleRecords, { kind: "form" });
|
|
40
40
|
expect(result.total).toBe(2);
|
|
41
|
-
expect(result.resources.every((r) => r.kind ===
|
|
41
|
+
expect(result.resources.every((r) => r.kind === "form")).toBe(true);
|
|
42
42
|
});
|
|
43
|
-
it(
|
|
44
|
-
const result = await (0, list_1.listResources)(sampleRecords, { parentId:
|
|
43
|
+
it("should filter by parentId", async () => {
|
|
44
|
+
const result = await (0, list_1.listResources)(sampleRecords, { parentId: "table1" });
|
|
45
45
|
expect(result.total).toBe(2);
|
|
46
|
-
expect(result.resources.every((r) => r.parentId ===
|
|
46
|
+
expect(result.resources.every((r) => r.parentId === "table1")).toBe(true);
|
|
47
47
|
});
|
|
48
|
-
it(
|
|
49
|
-
const result = await (0, list_1.listResources)(sampleRecords, { rootId:
|
|
48
|
+
it("should filter by rootId", async () => {
|
|
49
|
+
const result = await (0, list_1.listResources)(sampleRecords, { rootId: "table1" });
|
|
50
50
|
expect(result.total).toBe(3);
|
|
51
|
-
expect(result.resources.map((r) => r.id)).toEqual([
|
|
51
|
+
expect(result.resources.map((r) => r.id)).toEqual(["table1", "field1", "field2"]);
|
|
52
52
|
});
|
|
53
|
-
it(
|
|
54
|
-
const result = await (0, list_1.listResources)(sampleRecords, { kind:
|
|
53
|
+
it("should combine filters", async () => {
|
|
54
|
+
const result = await (0, list_1.listResources)(sampleRecords, { kind: "field", rootId: "table1" });
|
|
55
55
|
expect(result.total).toBe(2);
|
|
56
56
|
});
|
|
57
57
|
});
|
|
58
|
-
describe(
|
|
59
|
-
it(
|
|
60
|
-
const result = await (0, list_1.getResource)(sampleRecords,
|
|
58
|
+
describe("getResource", () => {
|
|
59
|
+
it("should get a single resource by id", async () => {
|
|
60
|
+
const result = await (0, list_1.getResource)(sampleRecords, "app1", {});
|
|
61
61
|
expect(result).not.toBeNull();
|
|
62
|
-
expect(result.id).toBe(
|
|
62
|
+
expect(result.id).toBe("app1");
|
|
63
63
|
});
|
|
64
|
-
it(
|
|
65
|
-
const result = await (0, list_1.getResource)(sampleRecords,
|
|
64
|
+
it("should return null for non-existent id", async () => {
|
|
65
|
+
const result = await (0, list_1.getResource)(sampleRecords, "nonexistent", {});
|
|
66
66
|
expect(result).toBeNull();
|
|
67
67
|
});
|
|
68
|
-
it(
|
|
69
|
-
const result = (await (0, list_1.getResource)(sampleRecords,
|
|
68
|
+
it("should include children when requested", async () => {
|
|
69
|
+
const result = (await (0, list_1.getResource)(sampleRecords, "app1", { children: true }));
|
|
70
70
|
expect(result.children).toHaveLength(3);
|
|
71
|
-
expect(result.children.map((c) => c.id)).toEqual([
|
|
71
|
+
expect(result.children.map((c) => c.id)).toEqual(["form1", "form2", "table1"]);
|
|
72
72
|
});
|
|
73
|
-
it(
|
|
74
|
-
const result = await (0, list_1.getResource)(sampleRecords,
|
|
73
|
+
it("should return null for non-existent id with tree option", async () => {
|
|
74
|
+
const result = await (0, list_1.getResource)(sampleRecords, "nonexistent", { tree: true });
|
|
75
75
|
expect(result).toBeNull();
|
|
76
76
|
});
|
|
77
77
|
});
|
|
78
|
-
describe(
|
|
79
|
-
it(
|
|
80
|
-
const result = await (0, list_1.getTree)(sampleRecords,
|
|
81
|
-
expect(result.rootId).toBe(
|
|
82
|
-
expect(result.tree.resource.id).toBe(
|
|
78
|
+
describe("getTree", () => {
|
|
79
|
+
it("should build tree for specified root", async () => {
|
|
80
|
+
const result = await (0, list_1.getTree)(sampleRecords, "table1");
|
|
81
|
+
expect(result.rootId).toBe("table1");
|
|
82
|
+
expect(result.tree.resource.id).toBe("table1");
|
|
83
83
|
expect(result.tree.children).toHaveLength(2);
|
|
84
84
|
});
|
|
85
|
-
it(
|
|
85
|
+
it("should auto-detect root when only one", async () => {
|
|
86
86
|
const singleRoot = [
|
|
87
|
-
{ id:
|
|
88
|
-
{ id:
|
|
87
|
+
{ id: "app1", kind: "application", parentId: null, settings: {} },
|
|
88
|
+
{ id: "form1", kind: "form", parentId: "app1", settings: {} },
|
|
89
89
|
];
|
|
90
90
|
const result = await (0, list_1.getTree)(singleRoot, undefined);
|
|
91
|
-
expect(result.rootId).toBe(
|
|
91
|
+
expect(result.rootId).toBe("app1");
|
|
92
92
|
});
|
|
93
|
-
it(
|
|
94
|
-
await expect((0, list_1.getTree)(sampleRecords,
|
|
93
|
+
it("should throw for non-existent root", async () => {
|
|
94
|
+
await expect((0, list_1.getTree)(sampleRecords, "nonexistent")).rejects.toThrow("not found");
|
|
95
95
|
});
|
|
96
96
|
});
|
|
97
|
-
describe(
|
|
98
|
-
it(
|
|
97
|
+
describe("createResource", () => {
|
|
98
|
+
it("should create with explicit fields", async () => {
|
|
99
99
|
mockedFs.readJson.mockResolvedValue([...sampleRecords]);
|
|
100
100
|
const result = await (0, create_1.createResource)({
|
|
101
101
|
sourceData,
|
|
102
|
-
kind:
|
|
103
|
-
parentId:
|
|
104
|
-
settings: { title:
|
|
102
|
+
kind: "form",
|
|
103
|
+
parentId: "app1",
|
|
104
|
+
settings: { title: "New Form" },
|
|
105
105
|
});
|
|
106
|
-
expect(result.record.kind).toBe(
|
|
107
|
-
expect(result.record.parentId).toBe(
|
|
108
|
-
expect(result.record.settings).toEqual({ title:
|
|
106
|
+
expect(result.record.kind).toBe("form");
|
|
107
|
+
expect(result.record.parentId).toBe("app1");
|
|
108
|
+
expect(result.record.settings).toEqual({ title: "New Form" });
|
|
109
109
|
expect(mockedFs.writeJson).toHaveBeenCalled();
|
|
110
110
|
});
|
|
111
|
-
it(
|
|
111
|
+
it("should throw without kind", async () => {
|
|
112
112
|
await expect((0, create_1.createResource)({
|
|
113
113
|
sourceData,
|
|
114
|
-
parentId:
|
|
115
|
-
})).rejects.toThrow(
|
|
114
|
+
parentId: "app1",
|
|
115
|
+
})).rejects.toThrow("--kind");
|
|
116
116
|
});
|
|
117
|
-
it(
|
|
117
|
+
it("should throw without parent-id", async () => {
|
|
118
118
|
await expect((0, create_1.createResource)({
|
|
119
119
|
sourceData,
|
|
120
|
-
kind:
|
|
121
|
-
})).rejects.toThrow(
|
|
120
|
+
kind: "form",
|
|
121
|
+
})).rejects.toThrow("--parent-id");
|
|
122
122
|
});
|
|
123
123
|
});
|
|
124
|
-
describe(
|
|
125
|
-
it(
|
|
124
|
+
describe("updateResource", () => {
|
|
125
|
+
it("should update existing resource", async () => {
|
|
126
126
|
mockedFs.readJson.mockResolvedValue([...sampleRecords]);
|
|
127
127
|
const result = await (0, update_1.updateResource)({
|
|
128
128
|
sourceData,
|
|
129
|
-
id:
|
|
130
|
-
settings: { title:
|
|
129
|
+
id: "form1",
|
|
130
|
+
settings: { title: "Updated Form" },
|
|
131
131
|
});
|
|
132
|
-
expect(result.record.id).toBe(
|
|
133
|
-
expect(result.record.settings).toEqual({ title:
|
|
132
|
+
expect(result.record.id).toBe("form1");
|
|
133
|
+
expect(result.record.settings).toEqual({ title: "Updated Form" });
|
|
134
134
|
expect(mockedFs.writeJson).toHaveBeenCalled();
|
|
135
135
|
});
|
|
136
|
-
it(
|
|
136
|
+
it("should throw on non-existent id", async () => {
|
|
137
137
|
await expect((0, update_1.updateResource)({
|
|
138
138
|
sourceData,
|
|
139
|
-
id:
|
|
140
|
-
settings: { title:
|
|
141
|
-
})).rejects.toThrow(
|
|
139
|
+
id: "nonexistent",
|
|
140
|
+
settings: { title: "x" },
|
|
141
|
+
})).rejects.toThrow("not found");
|
|
142
142
|
});
|
|
143
143
|
});
|
|
144
|
-
describe(
|
|
145
|
-
it(
|
|
144
|
+
describe("deleteResource", () => {
|
|
145
|
+
it("should delete resource and children", async () => {
|
|
146
146
|
mockedFs.readJson.mockResolvedValue([...sampleRecords]);
|
|
147
147
|
const result = await (0, delete_1.deleteResource)({
|
|
148
148
|
sourceData,
|
|
149
|
-
id:
|
|
149
|
+
id: "table1",
|
|
150
150
|
});
|
|
151
151
|
expect(result.removed).toHaveLength(3);
|
|
152
|
-
expect(result.removed.map((r) => r.id)).toEqual([
|
|
152
|
+
expect(result.removed.map((r) => r.id)).toEqual(["table1", "field1", "field2"]);
|
|
153
153
|
});
|
|
154
|
-
it(
|
|
154
|
+
it("should throw on non-existent id", async () => {
|
|
155
155
|
await expect((0, delete_1.deleteResource)({
|
|
156
156
|
sourceData,
|
|
157
|
-
id:
|
|
158
|
-
})).rejects.toThrow(
|
|
157
|
+
id: "nonexistent",
|
|
158
|
+
})).rejects.toThrow("not found");
|
|
159
159
|
});
|
|
160
160
|
});
|
|
161
|
-
describe(
|
|
161
|
+
describe("diffResource", () => {
|
|
162
162
|
const recordsA = [
|
|
163
|
-
{ id:
|
|
163
|
+
{ id: "1", kind: "application", parentId: null, settings: { title: "App A", version: 1 } },
|
|
164
164
|
];
|
|
165
165
|
const recordsB = [
|
|
166
166
|
{
|
|
167
|
-
id:
|
|
168
|
-
kind:
|
|
167
|
+
id: "1",
|
|
168
|
+
kind: "application",
|
|
169
169
|
parentId: null,
|
|
170
|
-
settings: { title:
|
|
171
|
-
}
|
|
170
|
+
settings: { title: "App B", version: 1, newField: "new" },
|
|
171
|
+
},
|
|
172
172
|
];
|
|
173
|
-
it(
|
|
173
|
+
it("should detect changed fields", async () => {
|
|
174
174
|
const result = await (0, diff_1.diffResource)({
|
|
175
|
-
sourceA:
|
|
176
|
-
sourceB:
|
|
177
|
-
id:
|
|
175
|
+
sourceA: "a.json",
|
|
176
|
+
sourceB: "b.json",
|
|
177
|
+
id: "1",
|
|
178
178
|
recordsA,
|
|
179
|
-
recordsB
|
|
179
|
+
recordsB,
|
|
180
180
|
});
|
|
181
181
|
expect(result.changed.length).toBeGreaterThan(0);
|
|
182
|
-
expect(result.changed.some((c) => c.path ===
|
|
182
|
+
expect(result.changed.some((c) => c.path === "title")).toBe(true);
|
|
183
183
|
});
|
|
184
|
-
it(
|
|
184
|
+
it("should detect added fields", async () => {
|
|
185
185
|
const result = await (0, diff_1.diffResource)({
|
|
186
|
-
sourceA:
|
|
187
|
-
sourceB:
|
|
188
|
-
id:
|
|
186
|
+
sourceA: "a.json",
|
|
187
|
+
sourceB: "b.json",
|
|
188
|
+
id: "1",
|
|
189
189
|
recordsA,
|
|
190
|
-
recordsB
|
|
190
|
+
recordsB,
|
|
191
191
|
});
|
|
192
|
-
expect(result.added.some((a) => a.path ===
|
|
192
|
+
expect(result.added.some((a) => a.path === "newField")).toBe(true);
|
|
193
193
|
});
|
|
194
|
-
it(
|
|
194
|
+
it("should handle resource only in one side", async () => {
|
|
195
195
|
const result = await (0, diff_1.diffResource)({
|
|
196
|
-
sourceA:
|
|
197
|
-
sourceB:
|
|
198
|
-
id:
|
|
196
|
+
sourceA: "a.json",
|
|
197
|
+
sourceB: "b.json",
|
|
198
|
+
id: "2",
|
|
199
199
|
recordsA: [],
|
|
200
|
-
recordsB: [{ id:
|
|
200
|
+
recordsB: [{ id: "2", kind: "application", parentId: null, settings: {} }],
|
|
201
201
|
});
|
|
202
202
|
expect(result.sideA).toBeNull();
|
|
203
203
|
expect(result.sideB).not.toBeNull();
|
|
204
204
|
});
|
|
205
|
-
it(
|
|
205
|
+
it("should report no differences for identical resources", async () => {
|
|
206
206
|
const result = await (0, diff_1.diffResource)({
|
|
207
|
-
sourceA:
|
|
208
|
-
sourceB:
|
|
209
|
-
id:
|
|
207
|
+
sourceA: "a.json",
|
|
208
|
+
sourceB: "b.json",
|
|
209
|
+
id: "1",
|
|
210
210
|
recordsA,
|
|
211
|
-
recordsB: recordsA
|
|
211
|
+
recordsB: recordsA,
|
|
212
212
|
});
|
|
213
213
|
expect(result.changed).toHaveLength(0);
|
|
214
214
|
expect(result.added).toHaveLength(0);
|
|
@@ -1,113 +1,116 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const formatter_1 = require("../utils/formatter");
|
|
4
|
-
describe(
|
|
5
|
-
describe(
|
|
6
|
-
it(
|
|
7
|
-
const result = (0, formatter_1.formatSuccess)({ id:
|
|
8
|
-
expect(result).toEqual({ success: true, data: { id:
|
|
4
|
+
describe("formatter", () => {
|
|
5
|
+
describe("formatSuccess", () => {
|
|
6
|
+
it("should format success response", () => {
|
|
7
|
+
const result = (0, formatter_1.formatSuccess)({ id: "1" });
|
|
8
|
+
expect(result).toEqual({ success: true, data: { id: "1" } });
|
|
9
9
|
});
|
|
10
10
|
});
|
|
11
|
-
describe(
|
|
12
|
-
it(
|
|
13
|
-
const result = (0, formatter_1.formatError)(
|
|
14
|
-
expect(result).toEqual({
|
|
11
|
+
describe("formatError", () => {
|
|
12
|
+
it("should format error response", () => {
|
|
13
|
+
const result = (0, formatter_1.formatError)("NOT_FOUND", "Resource not found");
|
|
14
|
+
expect(result).toEqual({
|
|
15
|
+
success: false,
|
|
16
|
+
error: { code: "NOT_FOUND", message: "Resource not found" },
|
|
17
|
+
});
|
|
15
18
|
});
|
|
16
19
|
});
|
|
17
|
-
describe(
|
|
18
|
-
it(
|
|
19
|
-
const result = (0, formatter_1.formatJson)({ a: 1, b:
|
|
20
|
+
describe("formatJson", () => {
|
|
21
|
+
it("should format JSON with 2-space indent", () => {
|
|
22
|
+
const result = (0, formatter_1.formatJson)({ a: 1, b: "test" });
|
|
20
23
|
expect(result).toBe('{\n "a": 1,\n "b": "test"\n}');
|
|
21
24
|
});
|
|
22
25
|
});
|
|
23
|
-
describe(
|
|
24
|
-
it(
|
|
25
|
-
expect((0, formatter_1.formatPrettyList)([])).toBe(
|
|
26
|
+
describe("formatPrettyList", () => {
|
|
27
|
+
it("should return message for empty list", () => {
|
|
28
|
+
expect((0, formatter_1.formatPrettyList)([])).toBe("No resources found.");
|
|
26
29
|
});
|
|
27
|
-
it(
|
|
30
|
+
it("should format list with header and rows", () => {
|
|
28
31
|
const resources = [
|
|
29
|
-
{ id:
|
|
30
|
-
{ id:
|
|
32
|
+
{ id: "1", kind: "application", parentId: null, title: "App1" },
|
|
33
|
+
{ id: "2", kind: "form", parentId: "1", title: "Form1" },
|
|
31
34
|
];
|
|
32
35
|
const result = (0, formatter_1.formatPrettyList)(resources);
|
|
33
|
-
expect(result).toContain(
|
|
34
|
-
expect(result).toContain(
|
|
35
|
-
expect(result).toContain(
|
|
36
|
-
expect(result).toContain(
|
|
36
|
+
expect(result).toContain("ID");
|
|
37
|
+
expect(result).toContain("KIND");
|
|
38
|
+
expect(result).toContain("PARENT ID");
|
|
39
|
+
expect(result).toContain("Total: 2 resource(s)");
|
|
37
40
|
});
|
|
38
41
|
});
|
|
39
|
-
describe(
|
|
40
|
-
it(
|
|
42
|
+
describe("formatPrettyTree", () => {
|
|
43
|
+
it("should format a tree with root and children", () => {
|
|
41
44
|
const tree = {
|
|
42
|
-
resource: { id:
|
|
45
|
+
resource: { id: "1", kind: "application", parentId: null, settings: {} },
|
|
43
46
|
children: [
|
|
44
47
|
{
|
|
45
|
-
resource: { id:
|
|
46
|
-
children: []
|
|
47
|
-
}
|
|
48
|
-
]
|
|
48
|
+
resource: { id: "2", kind: "form", parentId: "1", settings: {} },
|
|
49
|
+
children: [],
|
|
50
|
+
},
|
|
51
|
+
],
|
|
49
52
|
};
|
|
50
53
|
const result = (0, formatter_1.formatPrettyTree)(tree, false);
|
|
51
|
-
expect(result).toContain(
|
|
52
|
-
expect(result).toContain(
|
|
53
|
-
expect(result).toContain(
|
|
54
|
+
expect(result).toContain("1");
|
|
55
|
+
expect(result).toContain("2");
|
|
56
|
+
expect(result).toContain("└──");
|
|
54
57
|
});
|
|
55
|
-
it(
|
|
58
|
+
it("should show kind prefix with showKind option", () => {
|
|
56
59
|
const tree = {
|
|
57
|
-
resource: { id:
|
|
58
|
-
children: []
|
|
60
|
+
resource: { id: "1", kind: "application", parentId: null, settings: {} },
|
|
61
|
+
children: [],
|
|
59
62
|
};
|
|
60
63
|
const result = (0, formatter_1.formatPrettyTree)(tree, true);
|
|
61
|
-
expect(result).toContain(
|
|
64
|
+
expect(result).toContain("[application]");
|
|
62
65
|
});
|
|
63
66
|
});
|
|
64
|
-
describe(
|
|
65
|
-
it(
|
|
67
|
+
describe("formatPrettyDiff", () => {
|
|
68
|
+
it("should show no differences message", () => {
|
|
66
69
|
const diff = {
|
|
67
|
-
id:
|
|
68
|
-
kind:
|
|
69
|
-
sourceA:
|
|
70
|
-
sourceB:
|
|
70
|
+
id: "1",
|
|
71
|
+
kind: "application",
|
|
72
|
+
sourceA: "a.json",
|
|
73
|
+
sourceB: "b.json",
|
|
71
74
|
changed: [],
|
|
72
75
|
added: [],
|
|
73
76
|
removed: [],
|
|
74
|
-
sideA: { id:
|
|
75
|
-
sideB: { id:
|
|
77
|
+
sideA: { id: "1", kind: "application", parentId: null, settings: {} },
|
|
78
|
+
sideB: { id: "1", kind: "application", parentId: null, settings: {} },
|
|
76
79
|
};
|
|
77
80
|
const result = (0, formatter_1.formatPrettyDiff)(diff);
|
|
78
|
-
expect(result).toContain(
|
|
81
|
+
expect(result).toContain("No differences found.");
|
|
79
82
|
});
|
|
80
|
-
it(
|
|
83
|
+
it("should show changed fields", () => {
|
|
81
84
|
const diff = {
|
|
82
|
-
id:
|
|
83
|
-
kind:
|
|
84
|
-
sourceA:
|
|
85
|
-
sourceB:
|
|
86
|
-
changed: [{ path:
|
|
85
|
+
id: "1",
|
|
86
|
+
kind: "application",
|
|
87
|
+
sourceA: "a.json",
|
|
88
|
+
sourceB: "b.json",
|
|
89
|
+
changed: [{ path: "settings.title", from: "Old", to: "New" }],
|
|
87
90
|
added: [],
|
|
88
91
|
removed: [],
|
|
89
|
-
sideA: { id:
|
|
90
|
-
sideB: { id:
|
|
92
|
+
sideA: { id: "1", kind: "application", parentId: null, settings: {} },
|
|
93
|
+
sideB: { id: "1", kind: "application", parentId: null, settings: {} },
|
|
91
94
|
};
|
|
92
95
|
const result = (0, formatter_1.formatPrettyDiff)(diff);
|
|
93
|
-
expect(result).toContain(
|
|
94
|
-
expect(result).toContain(
|
|
95
|
-
expect(result).toContain(
|
|
96
|
+
expect(result).toContain("settings.title");
|
|
97
|
+
expect(result).toContain("Old");
|
|
98
|
+
expect(result).toContain("New");
|
|
96
99
|
});
|
|
97
|
-
it(
|
|
100
|
+
it("should show side-only existence", () => {
|
|
98
101
|
const diffA = {
|
|
99
|
-
id:
|
|
100
|
-
kind:
|
|
101
|
-
sourceA:
|
|
102
|
-
sourceB:
|
|
102
|
+
id: "1",
|
|
103
|
+
kind: "application",
|
|
104
|
+
sourceA: "a.json",
|
|
105
|
+
sourceB: "b.json",
|
|
103
106
|
changed: [],
|
|
104
107
|
added: [],
|
|
105
108
|
removed: [],
|
|
106
109
|
sideA: null,
|
|
107
|
-
sideB: { id:
|
|
110
|
+
sideB: { id: "1", kind: "application", parentId: null, settings: {} },
|
|
108
111
|
};
|
|
109
112
|
const result = (0, formatter_1.formatPrettyDiff)(diffA);
|
|
110
|
-
expect(result).toContain(
|
|
113
|
+
expect(result).toContain("only exists in source B");
|
|
111
114
|
});
|
|
112
115
|
});
|
|
113
116
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.test.js","sourceRoot":"","sources":["../../src/__tests__/formatter.test.ts"],"names":[],"mappings":";;AAAA,kDAO4B;AAE5B,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;QAC7B,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE;YACxC,MAAM,MAAM,GAAG,IAAA,yBAAa,EAAC,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;YAC1C,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;QAC/D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;QAC3B,EAAE,CAAC,8BAA8B,EAAE,GAAG,EAAE;YACtC,MAAM,MAAM,GAAG,IAAA,uBAAW,EAAC,WAAW,EAAE,oBAAoB,CAAC,CAAC;YAC9D,MAA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