@nordcraft/runtime 1.0.8 → 1.0.9
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/api/createAPIv2.js +49 -49
- package/dist/api/createAPIv2.js.map +1 -1
- package/dist/custom-element.main.esm.js +14 -14
- package/dist/custom-element.main.esm.js.map +3 -3
- package/dist/page.main.esm.js +3 -3
- package/dist/page.main.esm.js.map +3 -3
- package/package.json +3 -3
- package/src/api/createAPIv2.ts +63 -61
package/package.json
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
"type": "module",
|
|
5
5
|
"homepage": "https://github.com/nordcraftengine/nordcraft",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@nordcraft/core": "1.0.
|
|
8
|
-
"@nordcraft/std-lib": "1.0.
|
|
7
|
+
"@nordcraft/core": "1.0.9",
|
|
8
|
+
"@nordcraft/std-lib": "1.0.9",
|
|
9
9
|
"fast-deep-equal": "3.1.3",
|
|
10
10
|
"path-to-regexp": "6.3.0"
|
|
11
11
|
},
|
|
@@ -21,5 +21,5 @@
|
|
|
21
21
|
"files": ["dist", "src"],
|
|
22
22
|
"main": "dist/page.main.js",
|
|
23
23
|
"types": "dist/page.main.d.ts",
|
|
24
|
-
"version": "1.0.
|
|
24
|
+
"version": "1.0.9"
|
|
25
25
|
}
|
package/src/api/createAPIv2.ts
CHANGED
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
sortObjectEntries,
|
|
32
32
|
} from '@nordcraft/core/dist/utils/collections'
|
|
33
33
|
import { PROXY_URL_HEADER, validateUrl } from '@nordcraft/core/dist/utils/url'
|
|
34
|
+
import { isDefined } from '@nordcraft/core/dist/utils/util'
|
|
34
35
|
import { handleAction } from '../events/handleAction'
|
|
35
36
|
import type { Signal } from '../signal/signal'
|
|
36
37
|
import type { ComponentContext, ContextApi } from '../types'
|
|
@@ -748,71 +749,72 @@ export function createAPI(
|
|
|
748
749
|
}
|
|
749
750
|
})
|
|
750
751
|
payloadSignal.subscribe(async (_) => {
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
headers: cacheMatch.response?.headers ?? undefined,
|
|
782
|
-
},
|
|
783
|
-
{
|
|
784
|
-
requestStart:
|
|
785
|
-
cacheMatch.response?.performance?.requestStart ?? null,
|
|
786
|
-
responseStart:
|
|
787
|
-
cacheMatch.response?.performance?.responseStart ?? null,
|
|
788
|
-
responseEnd:
|
|
789
|
-
cacheMatch.response?.performance?.responseEnd ?? null,
|
|
790
|
-
},
|
|
791
|
-
)
|
|
792
|
-
}
|
|
793
|
-
} else {
|
|
794
|
-
// Execute will set the initial status of the api in the dataSignal
|
|
795
|
-
await execute(api, url, requestSettings)
|
|
796
|
-
}
|
|
752
|
+
const { url, requestSettings } = constructRequest(api)
|
|
753
|
+
// Ensure we only use caching if the page is currently loading
|
|
754
|
+
const cacheMatch =
|
|
755
|
+
// We lookup the API from cache as long as autofetch is defined (and not statically falsy)
|
|
756
|
+
// since the autofetch formula could've evaluated to true during SSR
|
|
757
|
+
isDefined(api.autoFetch) &&
|
|
758
|
+
(api.autoFetch.type !== 'value' || api.autoFetch.value === true) &&
|
|
759
|
+
(window?.__toddle?.isPageLoaded ?? false) === false
|
|
760
|
+
? (ctx.toddle.pageState.Apis?.[
|
|
761
|
+
requestHash(url, requestSettings)
|
|
762
|
+
] as ApiStatus)
|
|
763
|
+
: undefined
|
|
764
|
+
|
|
765
|
+
if (cacheMatch) {
|
|
766
|
+
if (cacheMatch.error) {
|
|
767
|
+
apiError(
|
|
768
|
+
api,
|
|
769
|
+
{
|
|
770
|
+
body: cacheMatch.error,
|
|
771
|
+
status: cacheMatch.response?.status,
|
|
772
|
+
headers: cacheMatch.response?.headers ?? undefined,
|
|
773
|
+
},
|
|
774
|
+
{
|
|
775
|
+
requestStart:
|
|
776
|
+
cacheMatch.response?.performance?.requestStart ?? null,
|
|
777
|
+
responseStart:
|
|
778
|
+
cacheMatch.response?.performance?.responseStart ?? null,
|
|
779
|
+
responseEnd: cacheMatch.response?.performance?.responseEnd ?? null,
|
|
780
|
+
},
|
|
781
|
+
)
|
|
797
782
|
} else {
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
783
|
+
apiSuccess(
|
|
784
|
+
api,
|
|
785
|
+
{
|
|
786
|
+
body: cacheMatch.data,
|
|
787
|
+
status: cacheMatch.response?.status,
|
|
788
|
+
headers: cacheMatch.response?.headers ?? undefined,
|
|
789
|
+
},
|
|
790
|
+
{
|
|
791
|
+
requestStart:
|
|
792
|
+
cacheMatch.response?.performance?.requestStart ?? null,
|
|
793
|
+
responseStart:
|
|
794
|
+
cacheMatch.response?.performance?.responseStart ?? null,
|
|
795
|
+
responseEnd: cacheMatch.response?.performance?.responseEnd ?? null,
|
|
796
|
+
},
|
|
797
|
+
)
|
|
801
798
|
}
|
|
802
799
|
} else {
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
800
|
+
if (applyFormula(api.autoFetch, getFormulaContext(api))) {
|
|
801
|
+
// Execute will set the initial status of the api in the dataSignal
|
|
802
|
+
await execute(api, url, requestSettings)
|
|
803
|
+
} else {
|
|
804
|
+
ctx.dataSignal.update((data) => {
|
|
805
|
+
return {
|
|
806
|
+
...data,
|
|
807
|
+
Apis: {
|
|
808
|
+
...(data.Apis ?? {}),
|
|
809
|
+
[api.name]: {
|
|
810
|
+
isLoading: false,
|
|
811
|
+
data: null,
|
|
812
|
+
error: null,
|
|
813
|
+
},
|
|
812
814
|
},
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
}
|
|
815
|
+
}
|
|
816
|
+
})
|
|
817
|
+
}
|
|
816
818
|
}
|
|
817
819
|
})
|
|
818
820
|
|