@arronqzy/react-blueprint 1.0.23 → 1.0.24

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/index.ts CHANGED
@@ -56,6 +56,7 @@ export {
56
56
  getApiCollectionById,
57
57
  getApiCollectionListItems,
58
58
  upsertApiCollectionFromJson,
59
+ putApiCollection,
59
60
  removeApiCollection,
60
61
  deleteApiCollection,
61
62
  clearApiCollections,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arronqzy/react-blueprint",
3
- "version": "1.0.23",
3
+ "version": "1.0.24",
4
4
  "description": "",
5
5
  "files": [
6
6
  "index.ts",
@@ -18,10 +18,10 @@
18
18
  "dayjs": "^1.11.13",
19
19
  "react-dom": "^19",
20
20
  "@xyflow/react": "^12.9.3",
21
- "@arronqzy/blueprint-dsl": "1.0.17",
22
- "@arronqzy/i18n": "0.1.17",
23
21
  "@arronqzy/react-rx-store": "1.1.8",
24
- "@arronqzy/ui": "1.0.10"
22
+ "@arronqzy/ui": "1.0.10",
23
+ "@arronqzy/blueprint-dsl": "1.0.17",
24
+ "@arronqzy/i18n": "0.1.17"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/react": "^19.0.1",
@@ -34,8 +34,8 @@
34
34
  "eslint": "^8.57.0",
35
35
  "typescript": "^5.5.4",
36
36
  "vite": "^5.1.4",
37
- "@arronqzy/tailwind": "1.0.2",
38
37
  "@arronqzy/eslint-config": "0.0.0",
38
+ "@arronqzy/tailwind": "1.0.2",
39
39
  "@arronqzy/typescript-config": "1.0.0"
40
40
  },
41
41
  "keywords": [],
@@ -70,18 +70,48 @@ export type UpsertApiCollectionInput = {
70
70
  persistLocal: boolean;
71
71
  /** 未写 document.name 时用文件名 */
72
72
  fallbackName?: string;
73
+ /** 省略时写入当前已 hydrate 的 nameSpace */
74
+ nameSpace?: string | null;
73
75
  };
74
76
 
75
77
  export type UpsertApiCollectionResult =
76
78
  | { ok: true; record: ApiCollectionRecord }
77
79
  | { ok: false; error: string };
78
80
 
81
+ function isCurrentNameSpace(nameSpace?: string | null): boolean {
82
+ return normalizeAppNameSpace(nameSpace) === normalizeAppNameSpace(nameSpaceRef);
83
+ }
84
+
85
+ /** 写入接口集合;persistLocal 时落 IndexedDB,同一 nameSpace 下刷新内存列表 */
86
+ export async function putApiCollection(
87
+ record: ApiCollectionRecord,
88
+ nameSpace?: string | null
89
+ ): Promise<ApiCollectionRecord> {
90
+ if (record.persistLocal) {
91
+ await putApiCollectionRecord(record, nameSpace);
92
+ } else if (isCurrentNameSpace(nameSpace)) {
93
+ const existing = records.find((item) => item.id === record.id);
94
+ if (existing?.persistLocal) {
95
+ await deleteApiCollectionRecord(record.id, nameSpace);
96
+ }
97
+ }
98
+ if (isCurrentNameSpace(nameSpace)) {
99
+ const next = records.filter((item) => item.id !== record.id);
100
+ next.push(record);
101
+ records = sortRecords(next);
102
+ emit();
103
+ }
104
+ return record;
105
+ }
106
+
79
107
  export async function upsertApiCollectionFromJson(
80
108
  input: UpsertApiCollectionInput
81
109
  ): Promise<UpsertApiCollectionResult> {
82
110
  const parsed = parseApiCollectionJson(input.rawJson);
83
111
  if (!parsed.ok) return parsed;
84
112
 
113
+ const targetNameSpace =
114
+ input.nameSpace !== undefined ? input.nameSpace : nameSpaceRef;
85
115
  const document: ApiCollectionDocument = {
86
116
  ...parsed.document,
87
117
  name:
@@ -90,11 +120,18 @@ export async function upsertApiCollectionFromJson(
90
120
  parsed.document.name,
91
121
  };
92
122
  const now = Date.now();
93
- const existing = input.id
123
+ const existingInMemory = input.id
94
124
  ? records.find((item) => item.id === input.id) ?? null
95
125
  : null;
126
+ const existingPersisted =
127
+ input.id && !isCurrentNameSpace(targetNameSpace)
128
+ ? await listApiCollectionRecords(targetNameSpace).then(
129
+ (list) => list.find((item) => item.id === input.id) ?? null
130
+ )
131
+ : null;
132
+ const existing = existingInMemory ?? existingPersisted;
96
133
  const record: ApiCollectionRecord = {
97
- id: existing?.id ?? createApiCollectionId(),
134
+ id: existing?.id ?? input.id ?? createApiCollectionId(),
98
135
  name: document.name,
99
136
  persistLocal: input.persistLocal,
100
137
  document,
@@ -103,16 +140,7 @@ export async function upsertApiCollectionFromJson(
103
140
  updatedAt: now,
104
141
  };
105
142
 
106
- if (record.persistLocal) {
107
- await putApiCollectionRecord(record, nameSpaceRef);
108
- } else if (existing?.persistLocal) {
109
- await deleteApiCollectionRecord(record.id, nameSpaceRef);
110
- }
111
-
112
- const next = records.filter((item) => item.id !== record.id);
113
- next.push(record);
114
- records = sortRecords(next);
115
- emit();
143
+ await putApiCollection(record, targetNameSpace);
116
144
  return { ok: true, record };
117
145
  }
118
146
 
@@ -129,10 +157,6 @@ export async function removeApiCollection(id: string): Promise<void> {
129
157
  emit();
130
158
  }
131
159
 
132
- function isCurrentNameSpace(nameSpace?: string | null): boolean {
133
- return normalizeAppNameSpace(nameSpace) === normalizeAppNameSpace(nameSpaceRef);
134
- }
135
-
136
160
  /** 按 nameSpace 删除接口集合;若该 nameSpace 正在被编辑器使用,内存列表同步移除 */
137
161
  export async function deleteApiCollection(
138
162
  id: string,