@flightdev/data 0.0.6

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.
@@ -0,0 +1,83 @@
1
+ import { j as FetchState, U as UseFetchOptions, l as UseAsyncDataOptions } from './cache-DU1v4CKe.js';
2
+ export { q as clearCache, o as configureCache, g as getCachedData, i as invalidate, r as invalidateCache, p as prefetch, s as setCachedData } from './cache-DU1v4CKe.js';
3
+
4
+ /**
5
+ * @flightdev/data - Solid Adapter
6
+ *
7
+ * Solid.js primitives for data fetching using Flight's core.
8
+ * Uses Solid signals: createSignal, createEffect, onMount, onCleanup.
9
+ *
10
+ * @module @flightdev/data/solid
11
+ */
12
+
13
+ type Accessor<T> = () => T;
14
+ interface UseFetchReturn<T> {
15
+ data: Accessor<T | undefined>;
16
+ pending: Accessor<boolean>;
17
+ error: Accessor<Error | undefined>;
18
+ status: Accessor<FetchState<T>['status']>;
19
+ isStale: Accessor<boolean>;
20
+ refresh: () => Promise<void>;
21
+ execute: () => Promise<void>;
22
+ }
23
+ interface UseAsyncDataReturn<T> {
24
+ data: Accessor<T | undefined>;
25
+ pending: Accessor<boolean>;
26
+ error: Accessor<Error | undefined>;
27
+ status: Accessor<FetchState<T>['status']>;
28
+ execute: () => Promise<void>;
29
+ refresh: () => Promise<void>;
30
+ }
31
+ /**
32
+ * Solid primitive for data fetching with caching and deduplication
33
+ *
34
+ * @example
35
+ * ```tsx
36
+ * import { useFetch } from '@flightdev/data/solid';
37
+ *
38
+ * function Users() {
39
+ * const { data, pending, error, refresh } = useFetch('/api/users');
40
+ *
41
+ * return (
42
+ * <Show when={!pending()} fallback={<p>Loading...</p>}>
43
+ * <ul>
44
+ * <For each={data()}>{user => <li>{user.name}</li>}</For>
45
+ * </ul>
46
+ * </Show>
47
+ * );
48
+ * }
49
+ * ```
50
+ */
51
+ declare function useFetch<T = unknown>(url: string | Accessor<string | null>, options?: UseFetchOptions<T>): UseFetchReturn<T>;
52
+ /**
53
+ * Solid primitive for custom async data fetching
54
+ *
55
+ * @example
56
+ * ```tsx
57
+ * import { useAsyncData } from '@flightdev/data/solid';
58
+ *
59
+ * function Analytics() {
60
+ * const { data, pending, execute } = useAsyncData(
61
+ * 'analytics',
62
+ * () => analyticsAPI.getReport()
63
+ * );
64
+ *
65
+ * return (
66
+ * <div>
67
+ * <button onClick={execute}>Refresh</button>
68
+ * <Show when={!pending()} fallback={<Spinner />}>
69
+ * <Chart data={data()} />
70
+ * </Show>
71
+ * </div>
72
+ * );
73
+ * }
74
+ * ```
75
+ */
76
+ declare function useAsyncData<T = unknown>(key: string, fetcher: () => Promise<T>, options?: UseAsyncDataOptions<T>): UseAsyncDataReturn<T>;
77
+
78
+ /**
79
+ * Hydrate data on client startup
80
+ */
81
+ declare function hydrateFlightData(): void;
82
+
83
+ export { type UseAsyncDataReturn, type UseFetchReturn, hydrateFlightData, useAsyncData, useFetch };
package/dist/solid.js ADDED
@@ -0,0 +1,142 @@
1
+ import {
2
+ asyncData,
3
+ clearCache,
4
+ configureCache,
5
+ fetchData,
6
+ getCachedData,
7
+ hydrateFetchData,
8
+ invalidate,
9
+ invalidateCache,
10
+ prefetch,
11
+ setCachedData
12
+ } from "./chunk-NOWQL3EM.js";
13
+
14
+ // src/solid.ts
15
+ var Solid = null;
16
+ function getSolid() {
17
+ if (Solid) return Solid;
18
+ const isBrowser = typeof window !== "undefined";
19
+ if (typeof globalThis !== "undefined") {
20
+ const g = globalThis;
21
+ if (g.Solid) {
22
+ Solid = g.Solid;
23
+ } else if (g.solidJs) {
24
+ Solid = g.solidJs;
25
+ }
26
+ }
27
+ if (!Solid && isBrowser) {
28
+ const w = window;
29
+ if (w.Solid) {
30
+ Solid = w.Solid;
31
+ }
32
+ }
33
+ if (!Solid) {
34
+ throw new Error(
35
+ "[@flightdev/data] Solid not found. Make sure Solid is available or import correctly."
36
+ );
37
+ }
38
+ return Solid;
39
+ }
40
+ function useFetch(url, options = {}) {
41
+ const { createSignal, createEffect, onMount, onCleanup } = getSolid();
42
+ const { immediate = true } = options;
43
+ const [data, setData] = createSignal(options.default);
44
+ const [pending, setPending] = createSignal(false);
45
+ const [error, setError] = createSignal(void 0);
46
+ const [status, setStatus] = createSignal("idle");
47
+ const [isStale, setIsStale] = createSignal(false);
48
+ const getUrl = () => {
49
+ return typeof url === "function" ? url() : url;
50
+ };
51
+ const execute = async () => {
52
+ const currentUrl = getUrl();
53
+ if (!currentUrl) return;
54
+ setPending(true);
55
+ const result = await fetchData(currentUrl, options);
56
+ setData(() => result.data);
57
+ setError(() => result.error);
58
+ setStatus(() => result.status);
59
+ setIsStale(() => result.isStale);
60
+ setPending(false);
61
+ };
62
+ const refresh = async () => {
63
+ const currentUrl = getUrl();
64
+ if (!currentUrl) return;
65
+ const key = options.key ?? currentUrl;
66
+ invalidate(key);
67
+ await execute();
68
+ };
69
+ if (typeof url === "function") {
70
+ createEffect(() => {
71
+ url();
72
+ if (immediate) execute();
73
+ });
74
+ }
75
+ onMount(() => {
76
+ if (immediate && getUrl()) {
77
+ execute();
78
+ }
79
+ });
80
+ if (options.revalidateOnFocus) {
81
+ const onFocus = () => execute();
82
+ onMount(() => window.addEventListener("focus", onFocus));
83
+ onCleanup(() => window.removeEventListener("focus", onFocus));
84
+ }
85
+ return {
86
+ data,
87
+ pending,
88
+ error,
89
+ status,
90
+ isStale,
91
+ refresh,
92
+ execute
93
+ };
94
+ }
95
+ function useAsyncData(key, fetcher, options = {}) {
96
+ const { createSignal, onMount } = getSolid();
97
+ const { immediate = true } = options;
98
+ const [data, setData] = createSignal(options.default);
99
+ const [pending, setPending] = createSignal(false);
100
+ const [error, setError] = createSignal(void 0);
101
+ const [status, setStatus] = createSignal("idle");
102
+ const execute = async () => {
103
+ setPending(true);
104
+ const result = await asyncData(key, fetcher, options);
105
+ setData(() => result.data);
106
+ setError(() => result.error);
107
+ setStatus(() => result.status);
108
+ setPending(false);
109
+ };
110
+ const refresh = async () => {
111
+ invalidate(key);
112
+ await execute();
113
+ };
114
+ onMount(() => {
115
+ if (immediate) {
116
+ execute();
117
+ }
118
+ });
119
+ return {
120
+ data,
121
+ pending,
122
+ error,
123
+ status,
124
+ execute,
125
+ refresh
126
+ };
127
+ }
128
+ function hydrateFlightData() {
129
+ hydrateFetchData();
130
+ }
131
+ export {
132
+ clearCache,
133
+ configureCache,
134
+ getCachedData,
135
+ hydrateFlightData,
136
+ invalidate,
137
+ invalidateCache,
138
+ prefetch,
139
+ setCachedData,
140
+ useAsyncData,
141
+ useFetch
142
+ };
@@ -0,0 +1,80 @@
1
+ import { j as FetchState, U as UseFetchOptions, l as UseAsyncDataOptions } from './cache-DU1v4CKe.js';
2
+ export { q as clearCache, o as configureCache, g as getCachedData, i as invalidate, r as invalidateCache, p as prefetch, s as setCachedData } from './cache-DU1v4CKe.js';
3
+
4
+ /**
5
+ * @flightdev/data - Svelte Adapter
6
+ *
7
+ * Svelte stores for data fetching using Flight's core.
8
+ * Uses Svelte stores: writable, derived.
9
+ *
10
+ * @module @flightdev/data/svelte
11
+ */
12
+
13
+ interface Readable<T> {
14
+ subscribe: (run: (value: T) => void) => () => void;
15
+ }
16
+ interface UseFetchReturn<T> {
17
+ data: Readable<T | undefined>;
18
+ pending: Readable<boolean>;
19
+ error: Readable<Error | undefined>;
20
+ status: Readable<FetchState<T>['status']>;
21
+ isStale: Readable<boolean>;
22
+ refresh: () => Promise<void>;
23
+ execute: () => Promise<void>;
24
+ }
25
+ interface UseAsyncDataReturn<T> {
26
+ data: Readable<T | undefined>;
27
+ pending: Readable<boolean>;
28
+ error: Readable<Error | undefined>;
29
+ status: Readable<FetchState<T>['status']>;
30
+ execute: () => Promise<void>;
31
+ refresh: () => Promise<void>;
32
+ }
33
+ /**
34
+ * Svelte store for data fetching with caching and deduplication
35
+ *
36
+ * @example
37
+ * ```svelte
38
+ * <script>
39
+ * import { useFetch } from '@flightdev/data/svelte';
40
+ *
41
+ * const { data, pending, error, refresh } = useFetch('/api/users');
42
+ * </script>
43
+ *
44
+ * {#if $pending}
45
+ * <p>Loading...</p>
46
+ * {:else if $error}
47
+ * <p>Error: {$error.message}</p>
48
+ * {:else}
49
+ * <ul>
50
+ * {#each $data as user}
51
+ * <li>{user.name}</li>
52
+ * {/each}
53
+ * </ul>
54
+ * {/if}
55
+ * ```
56
+ */
57
+ declare function useFetch<T = unknown>(url: string | null, options?: UseFetchOptions<T>): UseFetchReturn<T>;
58
+ /**
59
+ * Svelte store for custom async data fetching
60
+ *
61
+ * @example
62
+ * ```svelte
63
+ * <script>
64
+ * import { useAsyncData } from '@flightdev/data/svelte';
65
+ *
66
+ * const { data, pending, execute } = useAsyncData(
67
+ * 'analytics',
68
+ * () => analyticsAPI.getReport()
69
+ * );
70
+ * </script>
71
+ * ```
72
+ */
73
+ declare function useAsyncData<T = unknown>(key: string, fetcher: () => Promise<T>, options?: UseAsyncDataOptions<T>): UseAsyncDataReturn<T>;
74
+
75
+ /**
76
+ * Hydrate data on client startup
77
+ */
78
+ declare function hydrateFlightData(): void;
79
+
80
+ export { type UseAsyncDataReturn, type UseFetchReturn, hydrateFlightData, useAsyncData, useFetch };
package/dist/svelte.js ADDED
@@ -0,0 +1,114 @@
1
+ import {
2
+ asyncData,
3
+ clearCache,
4
+ configureCache,
5
+ fetchData,
6
+ getCachedData,
7
+ hydrateFetchData,
8
+ invalidate,
9
+ invalidateCache,
10
+ prefetch,
11
+ setCachedData
12
+ } from "./chunk-NOWQL3EM.js";
13
+
14
+ // src/svelte.ts
15
+ function createWritable(initial) {
16
+ let value = initial;
17
+ const subscribers = /* @__PURE__ */ new Set();
18
+ return {
19
+ subscribe(run) {
20
+ subscribers.add(run);
21
+ run(value);
22
+ return () => subscribers.delete(run);
23
+ },
24
+ set(newValue) {
25
+ value = newValue;
26
+ subscribers.forEach((fn) => fn(value));
27
+ },
28
+ update(fn) {
29
+ value = fn(value);
30
+ subscribers.forEach((fn2) => fn2(value));
31
+ }
32
+ };
33
+ }
34
+ function useFetch(url, options = {}) {
35
+ const { immediate = true } = options;
36
+ const data = createWritable(options.default);
37
+ const pending = createWritable(false);
38
+ const error = createWritable(void 0);
39
+ const status = createWritable("idle");
40
+ const isStale = createWritable(false);
41
+ const execute = async () => {
42
+ if (!url) return;
43
+ pending.set(true);
44
+ const result = await fetchData(url, options);
45
+ data.set(result.data);
46
+ error.set(result.error);
47
+ status.set(result.status);
48
+ isStale.set(result.isStale);
49
+ pending.set(false);
50
+ };
51
+ const refresh = async () => {
52
+ if (!url) return;
53
+ const key = options.key ?? url;
54
+ invalidate(key);
55
+ await execute();
56
+ };
57
+ if (immediate && url) {
58
+ execute();
59
+ }
60
+ return {
61
+ data,
62
+ pending,
63
+ error,
64
+ status,
65
+ isStale,
66
+ refresh,
67
+ execute
68
+ };
69
+ }
70
+ function useAsyncData(key, fetcher, options = {}) {
71
+ const { immediate = true } = options;
72
+ const data = createWritable(options.default);
73
+ const pending = createWritable(false);
74
+ const error = createWritable(void 0);
75
+ const status = createWritable("idle");
76
+ const execute = async () => {
77
+ pending.set(true);
78
+ const result = await asyncData(key, fetcher, options);
79
+ data.set(result.data);
80
+ error.set(result.error);
81
+ status.set(result.status);
82
+ pending.set(false);
83
+ };
84
+ const refresh = async () => {
85
+ invalidate(key);
86
+ await execute();
87
+ };
88
+ if (immediate) {
89
+ execute();
90
+ }
91
+ return {
92
+ data,
93
+ pending,
94
+ error,
95
+ status,
96
+ execute,
97
+ refresh
98
+ };
99
+ }
100
+ function hydrateFlightData() {
101
+ hydrateFetchData();
102
+ }
103
+ export {
104
+ clearCache,
105
+ configureCache,
106
+ getCachedData,
107
+ hydrateFlightData,
108
+ invalidate,
109
+ invalidateCache,
110
+ prefetch,
111
+ setCachedData,
112
+ useAsyncData,
113
+ useFetch
114
+ };
package/dist/vue.d.ts ADDED
@@ -0,0 +1,76 @@
1
+ import { j as FetchState, U as UseFetchOptions, l as UseAsyncDataOptions } from './cache-DU1v4CKe.js';
2
+ export { q as clearCache, o as configureCache, g as getCachedData, i as invalidate, r as invalidateCache, p as prefetch, s as setCachedData } from './cache-DU1v4CKe.js';
3
+
4
+ /**
5
+ * @flightdev/data - Vue Adapter
6
+ *
7
+ * Vue composables for data fetching using Flight's core.
8
+ * Uses Vue 3 Composition API: ref, watch, onMounted, onUnmounted.
9
+ *
10
+ * @module @flightdev/data/vue
11
+ */
12
+
13
+ interface Ref<T> {
14
+ value: T;
15
+ }
16
+ interface UseFetchReturn<T> {
17
+ data: Ref<T | undefined>;
18
+ pending: Ref<boolean>;
19
+ error: Ref<Error | undefined>;
20
+ status: Ref<FetchState<T>['status']>;
21
+ isStale: Ref<boolean>;
22
+ refresh: () => Promise<void>;
23
+ execute: () => Promise<void>;
24
+ }
25
+ interface UseAsyncDataReturn<T> {
26
+ data: Ref<T | undefined>;
27
+ pending: Ref<boolean>;
28
+ error: Ref<Error | undefined>;
29
+ status: Ref<FetchState<T>['status']>;
30
+ execute: () => Promise<void>;
31
+ refresh: () => Promise<void>;
32
+ }
33
+ /**
34
+ * Vue composable for data fetching with caching and deduplication
35
+ *
36
+ * @example
37
+ * ```vue
38
+ * <script setup>
39
+ * import { useFetch } from '@flightdev/data/vue';
40
+ *
41
+ * const { data, pending, error, refresh } = useFetch('/api/users');
42
+ * </script>
43
+ *
44
+ * <template>
45
+ * <p v-if="pending">Loading...</p>
46
+ * <p v-else-if="error">Error: {{ error.message }}</p>
47
+ * <ul v-else>
48
+ * <li v-for="user in data" :key="user.id">{{ user.name }}</li>
49
+ * </ul>
50
+ * </template>
51
+ * ```
52
+ */
53
+ declare function useFetch<T = unknown>(url: string | (() => string | null), options?: UseFetchOptions<T>): UseFetchReturn<T>;
54
+ /**
55
+ * Vue composable for custom async data fetching
56
+ *
57
+ * @example
58
+ * ```vue
59
+ * <script setup>
60
+ * import { useAsyncData } from '@flightdev/data/vue';
61
+ *
62
+ * const { data, pending, execute } = useAsyncData(
63
+ * 'analytics',
64
+ * () => analyticsAPI.getReport()
65
+ * );
66
+ * </script>
67
+ * ```
68
+ */
69
+ declare function useAsyncData<T = unknown>(key: string, fetcher: () => Promise<T>, options?: UseAsyncDataOptions<T>): UseAsyncDataReturn<T>;
70
+
71
+ /**
72
+ * Hydrate data on client startup
73
+ */
74
+ declare function hydrateFlightData(): void;
75
+
76
+ export { type UseAsyncDataReturn, type UseFetchReturn, hydrateFlightData, useAsyncData, useFetch };
package/dist/vue.js ADDED
@@ -0,0 +1,136 @@
1
+ import {
2
+ asyncData,
3
+ clearCache,
4
+ configureCache,
5
+ fetchData,
6
+ getCachedData,
7
+ hydrateFetchData,
8
+ invalidate,
9
+ invalidateCache,
10
+ prefetch,
11
+ setCachedData
12
+ } from "./chunk-NOWQL3EM.js";
13
+
14
+ // src/vue.ts
15
+ var Vue = null;
16
+ function getVue() {
17
+ if (Vue) return Vue;
18
+ const isBrowser = typeof window !== "undefined";
19
+ if (typeof globalThis !== "undefined" && globalThis.Vue) {
20
+ Vue = globalThis.Vue;
21
+ }
22
+ if (!Vue && isBrowser) {
23
+ const w = window;
24
+ if (w.Vue) {
25
+ Vue = w.Vue;
26
+ }
27
+ }
28
+ if (!Vue) {
29
+ throw new Error(
30
+ "[@flightdev/data] Vue not found. Make sure Vue is available globally or import Vue composables correctly."
31
+ );
32
+ }
33
+ return Vue;
34
+ }
35
+ function useFetch(url, options = {}) {
36
+ const { ref, watch, onMounted, onUnmounted } = getVue();
37
+ const { immediate = true } = options;
38
+ const data = ref(options.default);
39
+ const pending = ref(false);
40
+ const error = ref(void 0);
41
+ const status = ref("idle");
42
+ const isStale = ref(false);
43
+ const getUrl = () => {
44
+ return typeof url === "function" ? url() : url;
45
+ };
46
+ const execute = async () => {
47
+ const currentUrl = getUrl();
48
+ if (!currentUrl) return;
49
+ pending.value = true;
50
+ const result = await fetchData(currentUrl, options);
51
+ data.value = result.data;
52
+ error.value = result.error;
53
+ status.value = result.status;
54
+ isStale.value = result.isStale;
55
+ pending.value = false;
56
+ };
57
+ const refresh = async () => {
58
+ const currentUrl = getUrl();
59
+ if (!currentUrl) return;
60
+ const key = options.key ?? currentUrl;
61
+ invalidate(key);
62
+ await execute();
63
+ };
64
+ if (typeof url === "function") {
65
+ watch(url, () => {
66
+ if (immediate) execute();
67
+ });
68
+ }
69
+ onMounted(() => {
70
+ if (immediate && getUrl()) {
71
+ execute();
72
+ }
73
+ });
74
+ if (options.revalidateOnFocus) {
75
+ const onFocus = () => execute();
76
+ onMounted(() => window.addEventListener("focus", onFocus));
77
+ onUnmounted(() => window.removeEventListener("focus", onFocus));
78
+ }
79
+ return {
80
+ data,
81
+ pending,
82
+ error,
83
+ status,
84
+ isStale,
85
+ refresh,
86
+ execute
87
+ };
88
+ }
89
+ function useAsyncData(key, fetcher, options = {}) {
90
+ const { ref, onMounted } = getVue();
91
+ const { immediate = true } = options;
92
+ const data = ref(options.default);
93
+ const pending = ref(false);
94
+ const error = ref(void 0);
95
+ const status = ref("idle");
96
+ const execute = async () => {
97
+ pending.value = true;
98
+ const result = await asyncData(key, fetcher, options);
99
+ data.value = result.data;
100
+ error.value = result.error;
101
+ status.value = result.status;
102
+ pending.value = false;
103
+ };
104
+ const refresh = async () => {
105
+ invalidate(key);
106
+ await execute();
107
+ };
108
+ onMounted(() => {
109
+ if (immediate) {
110
+ execute();
111
+ }
112
+ });
113
+ return {
114
+ data,
115
+ pending,
116
+ error,
117
+ status,
118
+ execute,
119
+ refresh
120
+ };
121
+ }
122
+ function hydrateFlightData() {
123
+ hydrateFetchData();
124
+ }
125
+ export {
126
+ clearCache,
127
+ configureCache,
128
+ getCachedData,
129
+ hydrateFlightData,
130
+ invalidate,
131
+ invalidateCache,
132
+ prefetch,
133
+ setCachedData,
134
+ useAsyncData,
135
+ useFetch
136
+ };
package/package.json ADDED
@@ -0,0 +1,84 @@
1
+ {
2
+ "name": "@flightdev/data",
3
+ "version": "0.0.6",
4
+ "description": "Data fetching primitives for Flight Framework - loaders, actions, forms, useFetch, and useAsyncData",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ },
14
+ "./react": {
15
+ "types": "./dist/react.d.ts",
16
+ "import": "./dist/react.js"
17
+ },
18
+ "./vue": {
19
+ "types": "./dist/vue.d.ts",
20
+ "import": "./dist/vue.js"
21
+ },
22
+ "./svelte": {
23
+ "types": "./dist/svelte.d.ts",
24
+ "import": "./dist/svelte.js"
25
+ },
26
+ "./solid": {
27
+ "types": "./dist/solid.d.ts",
28
+ "import": "./dist/solid.js"
29
+ }
30
+ },
31
+ "files": [
32
+ "dist"
33
+ ],
34
+ "keywords": [
35
+ "flight",
36
+ "data",
37
+ "loader",
38
+ "action",
39
+ "forms",
40
+ "ssr",
41
+ "useFetch",
42
+ "useAsyncData",
43
+ "cache",
44
+ "react",
45
+ "vue",
46
+ "svelte",
47
+ "solid"
48
+ ],
49
+ "author": "Flight Framework",
50
+ "license": "MIT",
51
+ "repository": {
52
+ "type": "git",
53
+ "url": "https://github.com/EliosLT/Flight-framework",
54
+ "directory": "packages/data"
55
+ },
56
+ "devDependencies": {
57
+ "tsup": "^8.0.0",
58
+ "typescript": "^5.3.0"
59
+ },
60
+ "peerDependencies": {
61
+ "react": ">=18.0.0",
62
+ "vue": ">=3.0.0",
63
+ "svelte": ">=4.0.0",
64
+ "solid-js": ">=1.0.0"
65
+ },
66
+ "peerDependenciesMeta": {
67
+ "react": {
68
+ "optional": true
69
+ },
70
+ "vue": {
71
+ "optional": true
72
+ },
73
+ "svelte": {
74
+ "optional": true
75
+ },
76
+ "solid-js": {
77
+ "optional": true
78
+ }
79
+ },
80
+ "scripts": {
81
+ "build": "tsup src/index.ts src/react.ts src/vue.ts src/svelte.ts src/solid.ts --format esm --dts --clean",
82
+ "dev": "tsup src/index.ts src/react.ts src/vue.ts src/svelte.ts src/solid.ts --format esm --dts --watch"
83
+ }
84
+ }