@fragmentsx/client-core 0.2.4 → 0.3.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/dist/index.cjs.js
CHANGED
|
@@ -1713,7 +1713,13 @@ const createFetcher = (baseUrl, defaultHeaders = {}) => {
|
|
|
1713
1713
|
...options.headers
|
|
1714
1714
|
}
|
|
1715
1715
|
}).then(async (res) => {
|
|
1716
|
-
if (!res.ok)
|
|
1716
|
+
if (!res.ok) {
|
|
1717
|
+
if (process.env.NODE_ENV === "production") {
|
|
1718
|
+
console.error(`Fetch error: ${res.status}`);
|
|
1719
|
+
return null;
|
|
1720
|
+
}
|
|
1721
|
+
throw new Error(`Fetch error: ${res.status}`);
|
|
1722
|
+
}
|
|
1717
1723
|
const data = await res.json();
|
|
1718
1724
|
if (!query2.includes("mutation")) {
|
|
1719
1725
|
cache.set(cacheKey, data);
|
|
@@ -2582,34 +2588,8 @@ const loadPlugin = (state) => {
|
|
|
2582
2588
|
console.error("LoadFragmentPlugin depends from Fetch and Fragments plugin");
|
|
2583
2589
|
return state;
|
|
2584
2590
|
}
|
|
2585
|
-
const
|
|
2586
|
-
const createSuspenseResource = (key, fetcher) => {
|
|
2587
|
-
if (resourceCache.has(key)) return resourceCache.get(key);
|
|
2588
|
-
let status = "pending";
|
|
2589
|
-
let result;
|
|
2590
|
-
const suspender = fetcher().then(
|
|
2591
|
-
(r2) => {
|
|
2592
|
-
status = "success";
|
|
2593
|
-
result = r2;
|
|
2594
|
-
},
|
|
2595
|
-
(e) => {
|
|
2596
|
-
status = "error";
|
|
2597
|
-
result = e;
|
|
2598
|
-
}
|
|
2599
|
-
);
|
|
2600
|
-
const resource = {
|
|
2601
|
-
read() {
|
|
2602
|
-
if (status === "pending") throw suspender;
|
|
2603
|
-
if (status === "error") throw result;
|
|
2604
|
-
return result;
|
|
2605
|
-
}
|
|
2606
|
-
};
|
|
2607
|
-
resourceCache.set(key, resource);
|
|
2608
|
-
return resource;
|
|
2609
|
-
};
|
|
2610
|
-
const loadFragment = (fragmentId, options) => {
|
|
2591
|
+
const loadFragment = (fragmentId) => {
|
|
2611
2592
|
var _a, _b;
|
|
2612
|
-
const suspense = options == null ? void 0 : options.suspense;
|
|
2613
2593
|
const readFragment = (_a = state == null ? void 0 : state.$fetch) == null ? void 0 : _a.readFragment(fragmentId);
|
|
2614
2594
|
const fragmentManager = (_b = state == null ? void 0 : state.$fragments) == null ? void 0 : _b.getManager(fragmentId);
|
|
2615
2595
|
if (readFragment && !fragmentManager) {
|
|
@@ -2620,38 +2600,18 @@ const loadPlugin = (state) => {
|
|
|
2620
2600
|
return fragmentManager2;
|
|
2621
2601
|
}
|
|
2622
2602
|
if (readFragment && fragmentManager) return fragmentManager;
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
return state.$fragments.createFragmentManager(
|
|
2627
|
-
fragmentId,
|
|
2628
|
-
fragmentDocument
|
|
2629
|
-
);
|
|
2630
|
-
};
|
|
2631
|
-
if (suspense) {
|
|
2632
|
-
const resource = createSuspenseResource(fragmentId, loader);
|
|
2633
|
-
return resource.read();
|
|
2634
|
-
}
|
|
2635
|
-
return loader();
|
|
2603
|
+
return state.$fetch.queryFragment(fragmentId).then(
|
|
2604
|
+
(fragmentDocument) => state.$fragments.createFragmentManager(fragmentId, fragmentDocument)
|
|
2605
|
+
);
|
|
2636
2606
|
};
|
|
2637
|
-
const loadArea = (areaCode
|
|
2607
|
+
const loadArea = (areaCode) => {
|
|
2638
2608
|
var _a;
|
|
2639
|
-
const suspense = options == null ? void 0 : options.suspense;
|
|
2640
2609
|
const readArea2 = (_a = state == null ? void 0 : state.$fetch) == null ? void 0 : _a.readArea(areaCode);
|
|
2641
2610
|
if (readArea2) return readArea2;
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
const areaEntity = await ((_a2 = state == null ? void 0 : state.$fetch) == null ? void 0 : _a2.queryArea(areaCode));
|
|
2645
|
-
await loadFragment(areaEntity == null ? void 0 : areaEntity.fragmentId, {
|
|
2646
|
-
suspense: false
|
|
2647
|
-
});
|
|
2611
|
+
return state.$fetch.queryArea(areaCode).then(async (areaEntity) => {
|
|
2612
|
+
await loadFragment(areaEntity == null ? void 0 : areaEntity.fragmentId);
|
|
2648
2613
|
return areaEntity;
|
|
2649
|
-
};
|
|
2650
|
-
if (suspense) {
|
|
2651
|
-
const resource = createSuspenseResource(areaCode, loader);
|
|
2652
|
-
return resource.read();
|
|
2653
|
-
}
|
|
2654
|
-
return loader();
|
|
2614
|
+
});
|
|
2655
2615
|
};
|
|
2656
2616
|
const readArea = () => {
|
|
2657
2617
|
return state;
|
package/dist/index.es.js
CHANGED
|
@@ -1711,7 +1711,13 @@ const createFetcher = (baseUrl, defaultHeaders = {}) => {
|
|
|
1711
1711
|
...options.headers
|
|
1712
1712
|
}
|
|
1713
1713
|
}).then(async (res) => {
|
|
1714
|
-
if (!res.ok)
|
|
1714
|
+
if (!res.ok) {
|
|
1715
|
+
if (process.env.NODE_ENV === "production") {
|
|
1716
|
+
console.error(`Fetch error: ${res.status}`);
|
|
1717
|
+
return null;
|
|
1718
|
+
}
|
|
1719
|
+
throw new Error(`Fetch error: ${res.status}`);
|
|
1720
|
+
}
|
|
1715
1721
|
const data = await res.json();
|
|
1716
1722
|
if (!query2.includes("mutation")) {
|
|
1717
1723
|
cache.set(cacheKey, data);
|
|
@@ -2580,34 +2586,8 @@ const loadPlugin = (state) => {
|
|
|
2580
2586
|
console.error("LoadFragmentPlugin depends from Fetch and Fragments plugin");
|
|
2581
2587
|
return state;
|
|
2582
2588
|
}
|
|
2583
|
-
const
|
|
2584
|
-
const createSuspenseResource = (key, fetcher) => {
|
|
2585
|
-
if (resourceCache.has(key)) return resourceCache.get(key);
|
|
2586
|
-
let status = "pending";
|
|
2587
|
-
let result;
|
|
2588
|
-
const suspender = fetcher().then(
|
|
2589
|
-
(r2) => {
|
|
2590
|
-
status = "success";
|
|
2591
|
-
result = r2;
|
|
2592
|
-
},
|
|
2593
|
-
(e) => {
|
|
2594
|
-
status = "error";
|
|
2595
|
-
result = e;
|
|
2596
|
-
}
|
|
2597
|
-
);
|
|
2598
|
-
const resource = {
|
|
2599
|
-
read() {
|
|
2600
|
-
if (status === "pending") throw suspender;
|
|
2601
|
-
if (status === "error") throw result;
|
|
2602
|
-
return result;
|
|
2603
|
-
}
|
|
2604
|
-
};
|
|
2605
|
-
resourceCache.set(key, resource);
|
|
2606
|
-
return resource;
|
|
2607
|
-
};
|
|
2608
|
-
const loadFragment = (fragmentId, options) => {
|
|
2589
|
+
const loadFragment = (fragmentId) => {
|
|
2609
2590
|
var _a, _b;
|
|
2610
|
-
const suspense = options == null ? void 0 : options.suspense;
|
|
2611
2591
|
const readFragment = (_a = state == null ? void 0 : state.$fetch) == null ? void 0 : _a.readFragment(fragmentId);
|
|
2612
2592
|
const fragmentManager = (_b = state == null ? void 0 : state.$fragments) == null ? void 0 : _b.getManager(fragmentId);
|
|
2613
2593
|
if (readFragment && !fragmentManager) {
|
|
@@ -2618,38 +2598,18 @@ const loadPlugin = (state) => {
|
|
|
2618
2598
|
return fragmentManager2;
|
|
2619
2599
|
}
|
|
2620
2600
|
if (readFragment && fragmentManager) return fragmentManager;
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
return state.$fragments.createFragmentManager(
|
|
2625
|
-
fragmentId,
|
|
2626
|
-
fragmentDocument
|
|
2627
|
-
);
|
|
2628
|
-
};
|
|
2629
|
-
if (suspense) {
|
|
2630
|
-
const resource = createSuspenseResource(fragmentId, loader);
|
|
2631
|
-
return resource.read();
|
|
2632
|
-
}
|
|
2633
|
-
return loader();
|
|
2601
|
+
return state.$fetch.queryFragment(fragmentId).then(
|
|
2602
|
+
(fragmentDocument) => state.$fragments.createFragmentManager(fragmentId, fragmentDocument)
|
|
2603
|
+
);
|
|
2634
2604
|
};
|
|
2635
|
-
const loadArea = (areaCode
|
|
2605
|
+
const loadArea = (areaCode) => {
|
|
2636
2606
|
var _a;
|
|
2637
|
-
const suspense = options == null ? void 0 : options.suspense;
|
|
2638
2607
|
const readArea2 = (_a = state == null ? void 0 : state.$fetch) == null ? void 0 : _a.readArea(areaCode);
|
|
2639
2608
|
if (readArea2) return readArea2;
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
const areaEntity = await ((_a2 = state == null ? void 0 : state.$fetch) == null ? void 0 : _a2.queryArea(areaCode));
|
|
2643
|
-
await loadFragment(areaEntity == null ? void 0 : areaEntity.fragmentId, {
|
|
2644
|
-
suspense: false
|
|
2645
|
-
});
|
|
2609
|
+
return state.$fetch.queryArea(areaCode).then(async (areaEntity) => {
|
|
2610
|
+
await loadFragment(areaEntity == null ? void 0 : areaEntity.fragmentId);
|
|
2646
2611
|
return areaEntity;
|
|
2647
|
-
};
|
|
2648
|
-
if (suspense) {
|
|
2649
|
-
const resource = createSuspenseResource(areaCode, loader);
|
|
2650
|
-
return resource.read();
|
|
2651
|
-
}
|
|
2652
|
-
return loader();
|
|
2612
|
+
});
|
|
2653
2613
|
};
|
|
2654
2614
|
const readArea = () => {
|
|
2655
2615
|
return state;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../../../src/plugins/fetch/fetcher.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,aAAa,YACf,MAAM,mBACC,WAAW;YAWN,CAAC,SACb,MAAM,cACF,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YACzB,WAAW,KACnB,OAAO,CAAC;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../../../src/plugins/fetch/fetcher.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,aAAa,YACf,MAAM,mBACC,WAAW;YAWN,CAAC,SACb,MAAM,cACF,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YACzB,WAAW,KACnB,OAAO,CAAC;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC;2BA8CO,MAAM,YAAY,WAAW;;CAO5D,CAAC"}
|
|
@@ -2,17 +2,16 @@ import { Plugin } from '@graph-state/core';
|
|
|
2
2
|
declare module "@graph-state/core" {
|
|
3
3
|
interface GraphState {
|
|
4
4
|
$load: {
|
|
5
|
-
loadFragment: (fragmentID: number
|
|
6
|
-
loadArea: (areaCode: string
|
|
5
|
+
loadFragment: (fragmentID: number) => GraphState | Promise<GraphState>;
|
|
6
|
+
loadArea: (areaCode: string) => {
|
|
7
7
|
fragmentId: number;
|
|
8
8
|
props: unknown;
|
|
9
|
-
}
|
|
9
|
+
} | Promise<{
|
|
10
|
+
fragmentId: number;
|
|
11
|
+
props: unknown;
|
|
12
|
+
}>;
|
|
10
13
|
};
|
|
11
14
|
}
|
|
12
15
|
}
|
|
13
|
-
interface LoadPluginOptions {
|
|
14
|
-
suspense?: boolean;
|
|
15
|
-
}
|
|
16
16
|
export declare const loadPlugin: Plugin;
|
|
17
|
-
export {};
|
|
18
17
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/load/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,QAAQ,mBAAmB,CAAC;IACjC,UAAU,UAAU;QAClB,KAAK,EAAE;YACL,YAAY,EAAE,CACZ,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/load/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,QAAQ,mBAAmB,CAAC;IACjC,UAAU,UAAU;QAClB,KAAK,EAAE;YACL,YAAY,EAAE,CACZ,UAAU,EAAE,MAAM,KACf,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;YACtC,QAAQ,EAAE,CACR,QAAQ,EAAE,MAAM,KACb;gBAAE,UAAU,EAAE,MAAM,CAAC;gBAAC,KAAK,EAAE,OAAO,CAAA;aAAE,GAAG,OAAO,CAAC;gBAAE,UAAU,EAAE,MAAM,CAAC;gBAAC,KAAK,EAAE,OAAO,CAAA;aAAE,CAAC,CAAC;SAC/F,CAAC;KACH;CACF;AAED,eAAO,MAAM,UAAU,EAAE,MA6CxB,CAAC"}
|