@mawaru/sdk 0.25.0 → 0.27.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.
@@ -93,6 +93,14 @@ describe("duplicateSelection(選択ノードの複製)", () => {
93
93
  expect(new Set(newPortIds).size).toBe(newPortIds.length)
94
94
  })
95
95
 
96
+ it("node_key は引き継がない(同じ版に同じ node_key が2つあると保存 API が 422 になる)", () => {
97
+ const { nodes, connections, b } = chain()
98
+ const saved = nodes.map((n) => ({ ...n, node_key: uuid() }))
99
+ const result = dup(saved, connections, [b.id])
100
+ expect(result.nodes).toHaveLength(1)
101
+ expect(result.nodes[0]?.node_key).toBeUndefined()
102
+ })
103
+
96
104
  it("元のノード・接続を変更しない", () => {
97
105
  const { b, c, nodes, connections } = chain()
98
106
  const snapshot = structuredClone({ nodes, connections })
@@ -20,11 +20,13 @@ export const duplicateSelection = (params: {
20
20
  const selected = new Set(selectedIds)
21
21
 
22
22
  // start / end は回路の構造ノードなので複製しない(選択に混ざっていても落とす)。
23
- // 並び順は元グラフのまま(選択の指定順に依存させない)
23
+ // 並び順は元グラフのまま(選択の指定順に依存させない)。
24
+ // node_key は既存行との突き合わせ用なので複製には引き継がない(同じ版に同じ key が
25
+ // 2つあると保存 API が 422 にする)
24
26
  const portIdMap = new Map<string, string>()
25
27
  const copied = nodes
26
28
  .filter((n) => selected.has(n.id) && n.kind !== "start" && n.kind !== "end")
27
- .map((n) => ({
29
+ .map(({ node_key: _node_key, ...n }) => ({
28
30
  ...n,
29
31
  id: newId(),
30
32
  ports: n.ports.map((p) => {
@@ -216,6 +216,28 @@ describe("buildExtractPlan(子グラフと親置換の生成)", () => {
216
216
  expect(internal).toBeDefined()
217
217
  })
218
218
 
219
+ it("子:node_key は持ち込まない(子 loop の draft に無い key で保存 API が 422 になる)", () => {
220
+ const { nodes, connections, b, c } = chain()
221
+ // 保存済みの親を読んだ状態(各ノードが node_key を持つ)から抽出する
222
+ const saved = nodes.map((n) => ({ ...n, node_key: uuid() }))
223
+ const plan = buildExtractPlan({
224
+ nodes: saved,
225
+ connections,
226
+ selectedIds: [b.id, c.id],
227
+ name: "PRレビュー",
228
+ componentLoopId: uuid(),
229
+ childStartOutPortId: uuid(),
230
+ childEnd: childEndNode(),
231
+ newId: uuid,
232
+ })
233
+ if (!plan.ok) throw new Error(plan.reason)
234
+ for (const n of plan.childNodes) expect(n.node_key).toBeUndefined()
235
+ expect(plan.groupNode.node_key).toBeUndefined()
236
+ // 親に残るノードの node_key はそのまま(既存行との突き合わせに使う)
237
+ const remaining = plan.parentNodes.filter((n) => n.kind !== "component")
238
+ for (const n of remaining) expect(n.node_key).toBeDefined()
239
+ })
240
+
219
241
  it("子:start.main → 入口、出口ポート → end.in が配線される(出口1つは seed の in を使う)", () => {
220
242
  const { plan, childStartOutPortId, childEnd } = build()
221
243
  const [nb, nc] = plan.childNodes
@@ -134,12 +134,14 @@ export const buildExtractPlan = (params: {
134
134
 
135
135
  const selected = new Set(selectedIds)
136
136
  // ノード・ポートとも新 id を採番してコピー(kind 別設定・hooks は共有参照で問題ない
137
- // =この後 JSON 化して保存 API に渡すだけで、エディタ状態には子側を持たない)
137
+ // =この後 JSON 化して保存 API に渡すだけで、エディタ状態には子側を持たない)。
138
+ // node_key は親の版の行との突き合わせ用なので子へは持ち込まない(子 loop の draft に
139
+ // 無い key を送ると保存 API が「この版に存在しないノード」で 422 にする)
138
140
  const nodeIdMap = new Map<string, string>()
139
141
  const portIdMap = new Map<string, string>()
140
142
  const childNodes = nodes
141
143
  .filter((n) => selected.has(n.id))
142
- .map((n) => {
144
+ .map(({ node_key: _node_key, ...n }) => {
143
145
  const id = newId()
144
146
  nodeIdMap.set(n.id, id)
145
147
  return {
@@ -8,11 +8,13 @@ export const duplicateSelection = (params) => {
8
8
  const { nodes, connections, selectedIds, dx, dy, newId } = params;
9
9
  const selected = new Set(selectedIds);
10
10
  // start / end は回路の構造ノードなので複製しない(選択に混ざっていても落とす)。
11
- // 並び順は元グラフのまま(選択の指定順に依存させない)
11
+ // 並び順は元グラフのまま(選択の指定順に依存させない)。
12
+ // node_key は既存行との突き合わせ用なので複製には引き継がない(同じ版に同じ key が
13
+ // 2つあると保存 API が 422 にする)
12
14
  const portIdMap = new Map();
13
15
  const copied = nodes
14
16
  .filter((n) => selected.has(n.id) && n.kind !== "start" && n.kind !== "end")
15
- .map((n) => ({
17
+ .map(({ node_key: _node_key, ...n }) => ({
16
18
  ...n,
17
19
  id: newId(),
18
20
  ports: n.ports.map((p) => {
@@ -61,12 +61,14 @@ export const buildExtractPlan = (params) => {
61
61
  return analysis;
62
62
  const selected = new Set(selectedIds);
63
63
  // ノード・ポートとも新 id を採番してコピー(kind 別設定・hooks は共有参照で問題ない
64
- // =この後 JSON 化して保存 API に渡すだけで、エディタ状態には子側を持たない)
64
+ // =この後 JSON 化して保存 API に渡すだけで、エディタ状態には子側を持たない)。
65
+ // node_key は親の版の行との突き合わせ用なので子へは持ち込まない(子 loop の draft に
66
+ // 無い key を送ると保存 API が「この版に存在しないノード」で 422 にする)
65
67
  const nodeIdMap = new Map();
66
68
  const portIdMap = new Map();
67
69
  const childNodes = nodes
68
70
  .filter((n) => selected.has(n.id))
69
- .map((n) => {
71
+ .map(({ node_key: _node_key, ...n }) => {
70
72
  const id = newId();
71
73
  nodeIdMap.set(n.id, id);
72
74
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mawaru/sdk",
3
- "version": "0.25.0",
3
+ "version": "0.27.0",
4
4
  "description": "mawaru 実行 repo の開発 SDK。契約スキーマ(config.json 規約・ループ graph API)の正 + typegen / validate CLI",
5
5
  "type": "module",
6
6
  "bin": {
@@ -59,7 +59,7 @@ secret)でも、**足りない値を推測・生成・空文字で代用しな
59
59
 
60
60
  疎通確認のあと `GET {MAWARU_API_URL}/tenants/{MAWARU_TENANT_ID}/openapi.json`
61
61
  (ヘッダ `x-api-key: $MAWARU_API_KEY`)を取得すると、機械 API 面
62
- (loops の一覧・作成・詳細・graph PUT、runs/start、members、api-keys、steps の end / decision)の
62
+ (loops の一覧・作成・詳細・graph PUT、runs/start、runs/{runId}/cancel、members、api-keys、steps の end / decision)の
63
63
  パス・メソッド・リクエストボディ(Zod 由来の JSON Schema)が載っている。ここが常に正。
64
64
  段階導入中で未掲載のエンドポイントもある(その場合だけ `api/index.ts` 相当を辿る)。
65
65