houdini-react 1.2.0-react.1
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/LICENSE +21 -0
- package/README.md +36 -0
- package/build/next/index.d.ts +2 -0
- package/build/next-cjs/index.js +50 -0
- package/build/next-cjs/package.json +1 -0
- package/build/next-esm/index.js +26 -0
- package/build/next-esm/package.json +1 -0
- package/build/plugin/config.d.ts +3 -0
- package/build/plugin/extract.d.ts +6 -0
- package/build/plugin/index.d.ts +3 -0
- package/build/plugin/transform.d.ts +6 -0
- package/build/plugin-cjs/index.js +78313 -0
- package/build/plugin-cjs/package.json +1 -0
- package/build/plugin-esm/index.js +78307 -0
- package/build/plugin-esm/package.json +1 -0
- package/build/runtime/context.d.ts +7 -0
- package/build/runtime/hooks/index.d.ts +8 -0
- package/build/runtime/hooks/useDeepCompareEffect.d.ts +35 -0
- package/build/runtime/hooks/useDocumentHandle.d.ts +34 -0
- package/build/runtime/hooks/useDocumentStore.d.ts +11 -0
- package/build/runtime/hooks/useDocumentSubscription.d.ts +14 -0
- package/build/runtime/hooks/useFragment.d.ts +15 -0
- package/build/runtime/hooks/useFragmentHandle.d.ts +9 -0
- package/build/runtime/hooks/useHoudiniClient.d.ts +2 -0
- package/build/runtime/hooks/useIsMounted.d.ts +3 -0
- package/build/runtime/hooks/useMutation.d.ts +10 -0
- package/build/runtime/hooks/useQuery.d.ts +5 -0
- package/build/runtime/hooks/useQueryHandle.d.ts +10 -0
- package/build/runtime/hooks/useSubscription.d.ts +4 -0
- package/build/runtime/hooks/useSubscriptionHandle.d.ts +25 -0
- package/build/runtime/index.d.ts +2 -0
- package/build/runtime/lib/cache.d.ts +62 -0
- package/build/runtime-cjs/context.d.ts +7 -0
- package/build/runtime-cjs/context.js +41 -0
- package/build/runtime-cjs/hooks/index.d.ts +8 -0
- package/build/runtime-cjs/hooks/index.js +45 -0
- package/build/runtime-cjs/hooks/useDeepCompareEffect.d.ts +35 -0
- package/build/runtime-cjs/hooks/useDeepCompareEffect.js +72 -0
- package/build/runtime-cjs/hooks/useDocumentHandle.d.ts +34 -0
- package/build/runtime-cjs/hooks/useDocumentHandle.js +127 -0
- package/build/runtime-cjs/hooks/useDocumentStore.d.ts +11 -0
- package/build/runtime-cjs/hooks/useDocumentStore.js +63 -0
- package/build/runtime-cjs/hooks/useDocumentSubscription.d.ts +14 -0
- package/build/runtime-cjs/hooks/useDocumentSubscription.js +65 -0
- package/build/runtime-cjs/hooks/useFragment.d.ts +15 -0
- package/build/runtime-cjs/hooks/useFragment.js +93 -0
- package/build/runtime-cjs/hooks/useFragmentHandle.d.ts +9 -0
- package/build/runtime-cjs/hooks/useFragmentHandle.js +47 -0
- package/build/runtime-cjs/hooks/useHoudiniClient.d.ts +2 -0
- package/build/runtime-cjs/hooks/useHoudiniClient.js +42 -0
- package/build/runtime-cjs/hooks/useIsMounted.d.ts +3 -0
- package/build/runtime-cjs/hooks/useIsMounted.js +38 -0
- package/build/runtime-cjs/hooks/useMutation.d.ts +10 -0
- package/build/runtime-cjs/hooks/useMutation.js +48 -0
- package/build/runtime-cjs/hooks/useQuery.d.ts +5 -0
- package/build/runtime-cjs/hooks/useQuery.js +32 -0
- package/build/runtime-cjs/hooks/useQueryHandle.d.ts +10 -0
- package/build/runtime-cjs/hooks/useQueryHandle.js +125 -0
- package/build/runtime-cjs/hooks/useSubscription.d.ts +4 -0
- package/build/runtime-cjs/hooks/useSubscription.js +32 -0
- package/build/runtime-cjs/hooks/useSubscriptionHandle.d.ts +25 -0
- package/build/runtime-cjs/hooks/useSubscriptionHandle.js +42 -0
- package/build/runtime-cjs/index.d.ts +2 -0
- package/build/runtime-cjs/index.js +30 -0
- package/build/runtime-cjs/lib/cache.d.ts +62 -0
- package/build/runtime-cjs/lib/cache.js +71 -0
- package/build/runtime-cjs/package.json +1 -0
- package/build/runtime-esm/context.d.ts +7 -0
- package/build/runtime-esm/context.js +10 -0
- package/build/runtime-esm/hooks/index.d.ts +8 -0
- package/build/runtime-esm/hooks/index.js +16 -0
- package/build/runtime-esm/hooks/useDeepCompareEffect.d.ts +35 -0
- package/build/runtime-esm/hooks/useDeepCompareEffect.js +41 -0
- package/build/runtime-esm/hooks/useDocumentHandle.d.ts +34 -0
- package/build/runtime-esm/hooks/useDocumentHandle.js +99 -0
- package/build/runtime-esm/hooks/useDocumentStore.d.ts +11 -0
- package/build/runtime-esm/hooks/useDocumentStore.js +33 -0
- package/build/runtime-esm/hooks/useDocumentSubscription.d.ts +14 -0
- package/build/runtime-esm/hooks/useDocumentSubscription.js +35 -0
- package/build/runtime-esm/hooks/useFragment.d.ts +15 -0
- package/build/runtime-esm/hooks/useFragment.js +62 -0
- package/build/runtime-esm/hooks/useFragmentHandle.d.ts +9 -0
- package/build/runtime-esm/hooks/useFragmentHandle.js +23 -0
- package/build/runtime-esm/hooks/useHoudiniClient.d.ts +2 -0
- package/build/runtime-esm/hooks/useHoudiniClient.js +12 -0
- package/build/runtime-esm/hooks/useIsMounted.d.ts +3 -0
- package/build/runtime-esm/hooks/useIsMounted.js +14 -0
- package/build/runtime-esm/hooks/useMutation.d.ts +10 -0
- package/build/runtime-esm/hooks/useMutation.js +24 -0
- package/build/runtime-esm/hooks/useQuery.d.ts +5 -0
- package/build/runtime-esm/hooks/useQuery.js +8 -0
- package/build/runtime-esm/hooks/useQueryHandle.d.ts +10 -0
- package/build/runtime-esm/hooks/useQueryHandle.js +95 -0
- package/build/runtime-esm/hooks/useSubscription.d.ts +4 -0
- package/build/runtime-esm/hooks/useSubscription.js +8 -0
- package/build/runtime-esm/hooks/useSubscriptionHandle.d.ts +25 -0
- package/build/runtime-esm/hooks/useSubscriptionHandle.js +18 -0
- package/build/runtime-esm/index.d.ts +2 -0
- package/build/runtime-esm/index.js +5 -0
- package/build/runtime-esm/lib/cache.d.ts +62 -0
- package/build/runtime-esm/lib/cache.js +47 -0
- package/build/runtime-esm/package.json +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var useQueryHandle_exports = {};
|
|
26
|
+
__export(useQueryHandle_exports, {
|
|
27
|
+
useQueryHandle: () => useQueryHandle
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(useQueryHandle_exports);
|
|
30
|
+
var import_react = __toESM(require("react"));
|
|
31
|
+
var import_cache = require("../lib/cache");
|
|
32
|
+
var import_useDocumentHandle = require("./useDocumentHandle");
|
|
33
|
+
var import_useHoudiniClient = require("./useHoudiniClient");
|
|
34
|
+
var import_useIsMounted = require("./useIsMounted");
|
|
35
|
+
const promiseCache = (0, import_cache.createCache)();
|
|
36
|
+
function useQueryHandle({ artifact }, variables = null, config = {}) {
|
|
37
|
+
const identifier = queryIdentifier({ artifact, variables, config });
|
|
38
|
+
const suspenseValue = promiseCache.get(identifier);
|
|
39
|
+
const client = (0, import_useHoudiniClient.useHoudiniClient)();
|
|
40
|
+
const isMountedRef = (0, import_useIsMounted.useIsMountedRef)();
|
|
41
|
+
let [observer] = import_react.default.useState(
|
|
42
|
+
client.observe({
|
|
43
|
+
artifact,
|
|
44
|
+
initialValue: suspenseValue?.resolved?.data ?? {}
|
|
45
|
+
})
|
|
46
|
+
);
|
|
47
|
+
const suspenseTracker = import_react.default.useRef(false);
|
|
48
|
+
const box = import_react.default.useRef(observer.state);
|
|
49
|
+
const subscribe = import_react.default.useCallback(
|
|
50
|
+
(fn) => {
|
|
51
|
+
return observer.subscribe((val) => {
|
|
52
|
+
box.current = val;
|
|
53
|
+
if (isMountedRef.current && !suspenseTracker.current) {
|
|
54
|
+
fn();
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
[observer]
|
|
59
|
+
);
|
|
60
|
+
const storeValue = import_react.default.useSyncExternalStore(subscribe, () => box.current);
|
|
61
|
+
const handle = (0, import_useDocumentHandle.useDocumentHandle)({
|
|
62
|
+
artifact,
|
|
63
|
+
observer,
|
|
64
|
+
storeValue
|
|
65
|
+
});
|
|
66
|
+
import_react.default.useEffect(() => {
|
|
67
|
+
return () => {
|
|
68
|
+
promiseCache.delete(identifier);
|
|
69
|
+
};
|
|
70
|
+
}, [identifier]);
|
|
71
|
+
import_react.default.useEffect(() => {
|
|
72
|
+
return () => {
|
|
73
|
+
observer.cleanup();
|
|
74
|
+
};
|
|
75
|
+
}, [observer]);
|
|
76
|
+
let result = storeValue.data;
|
|
77
|
+
if (!suspenseValue) {
|
|
78
|
+
let resolve = () => {
|
|
79
|
+
};
|
|
80
|
+
const loadPromise = new Promise((r) => resolve = r);
|
|
81
|
+
const suspenseUnit = {
|
|
82
|
+
then: loadPromise.then.bind(loadPromise),
|
|
83
|
+
resolve,
|
|
84
|
+
variables
|
|
85
|
+
};
|
|
86
|
+
promiseCache.set(identifier, suspenseUnit);
|
|
87
|
+
handle.fetch({
|
|
88
|
+
variables,
|
|
89
|
+
stuff: {
|
|
90
|
+
silenceLoading: true
|
|
91
|
+
}
|
|
92
|
+
}).then((value) => {
|
|
93
|
+
suspenseUnit.resolved = {
|
|
94
|
+
...handle,
|
|
95
|
+
data: value.data,
|
|
96
|
+
partia: value.partial,
|
|
97
|
+
artifact
|
|
98
|
+
};
|
|
99
|
+
suspenseUnit.resolve();
|
|
100
|
+
});
|
|
101
|
+
suspenseTracker.current = true;
|
|
102
|
+
throw suspenseUnit;
|
|
103
|
+
}
|
|
104
|
+
if (!result && suspenseValue && !suspenseValue.resolved) {
|
|
105
|
+
suspenseTracker.current = true;
|
|
106
|
+
throw suspenseValue;
|
|
107
|
+
}
|
|
108
|
+
if (!result && suspenseValue?.resolved) {
|
|
109
|
+
return suspenseValue.resolved;
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
...handle,
|
|
113
|
+
variables: storeValue.variables,
|
|
114
|
+
data: result
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function queryIdentifier(args) {
|
|
118
|
+
args.fetchKey ??= 0;
|
|
119
|
+
const { artifact, variables, fetchKey } = args;
|
|
120
|
+
return [artifact.name, JSON.stringify(variables), fetchKey].join("@@");
|
|
121
|
+
}
|
|
122
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
123
|
+
0 && (module.exports = {
|
|
124
|
+
useQueryHandle
|
|
125
|
+
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { SubscriptionArtifact, GraphQLObject } from '$houdini/runtime/lib/types';
|
|
2
|
+
export declare function useSubscription<_Result extends GraphQLObject, _Input extends {}>(document: {
|
|
3
|
+
artifact: SubscriptionArtifact;
|
|
4
|
+
}, variables: _Input): import("houdini").GraphQLObject | null;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var useSubscription_exports = {};
|
|
20
|
+
__export(useSubscription_exports, {
|
|
21
|
+
useSubscription: () => useSubscription
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(useSubscription_exports);
|
|
24
|
+
var import_useSubscriptionHandle = require("./useSubscriptionHandle");
|
|
25
|
+
function useSubscription(document, variables) {
|
|
26
|
+
const { data } = (0, import_useSubscriptionHandle.useSubscriptionHandle)(document, variables);
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
useSubscription
|
|
32
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SubscriptionArtifact, GraphQLObject } from '$houdini/runtime/lib/types';
|
|
2
|
+
export type SubscriptionHandle<_Result extends GraphQLObject, _Input extends {} | null> = {
|
|
3
|
+
data: _Result | null;
|
|
4
|
+
errors: {
|
|
5
|
+
message: string;
|
|
6
|
+
}[] | null;
|
|
7
|
+
variables: _Input;
|
|
8
|
+
listen: (args: {
|
|
9
|
+
variables?: _Input;
|
|
10
|
+
}) => void;
|
|
11
|
+
unlisten: () => void;
|
|
12
|
+
fetching: boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare function useSubscriptionHandle<_Result extends GraphQLObject, _Input extends {}>({ artifact }: {
|
|
15
|
+
artifact: SubscriptionArtifact;
|
|
16
|
+
}, variables: _Input): {
|
|
17
|
+
data: import("houdini").GraphQLObject | null;
|
|
18
|
+
errors: {
|
|
19
|
+
message: string;
|
|
20
|
+
}[] | null;
|
|
21
|
+
fetching: boolean;
|
|
22
|
+
variables: _Input;
|
|
23
|
+
unlisten: () => Promise<void>;
|
|
24
|
+
listen: ({ metadata, session, fetch, variables, policy, stuff, cacheParams, setup, silenceEcho, }?: import("$houdini/lib").SendParams) => Promise<import("$houdini/runtime/lib/types").QueryResult<import("houdini").GraphQLObject, _Input>>;
|
|
25
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var useSubscriptionHandle_exports = {};
|
|
20
|
+
__export(useSubscriptionHandle_exports, {
|
|
21
|
+
useSubscriptionHandle: () => useSubscriptionHandle
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(useSubscriptionHandle_exports);
|
|
24
|
+
var import_useDocumentSubscription = require("./useDocumentSubscription");
|
|
25
|
+
function useSubscriptionHandle({ artifact }, variables) {
|
|
26
|
+
const [storeValue, observer] = (0, import_useDocumentSubscription.useDocumentSubscription)({
|
|
27
|
+
artifact,
|
|
28
|
+
variables
|
|
29
|
+
});
|
|
30
|
+
return {
|
|
31
|
+
data: storeValue.data,
|
|
32
|
+
errors: storeValue.errors,
|
|
33
|
+
fetching: storeValue.fetching,
|
|
34
|
+
variables,
|
|
35
|
+
unlisten: observer.cleanup,
|
|
36
|
+
listen: observer.send
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
useSubscriptionHandle
|
|
42
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var runtime_exports = {};
|
|
21
|
+
__export(runtime_exports, {
|
|
22
|
+
HoudiniProvider: () => import_context.HoudiniProvider
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(runtime_exports);
|
|
25
|
+
__reExport(runtime_exports, require("./hooks"), module.exports);
|
|
26
|
+
var import_context = require("./context");
|
|
27
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
+
0 && (module.exports = {
|
|
29
|
+
HoudiniProvider
|
|
30
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is a copy and paste of a very simple and effective LRU cache
|
|
3
|
+
* using javascript maps. It was copied under the MIT license found at the
|
|
4
|
+
* bottom of the page.
|
|
5
|
+
*/
|
|
6
|
+
export interface Cache<T> {
|
|
7
|
+
get(key: string): T | null;
|
|
8
|
+
set(key: string, value: T): void;
|
|
9
|
+
has(key: string): boolean;
|
|
10
|
+
delete(key: string): void;
|
|
11
|
+
size(): number;
|
|
12
|
+
capacity(): number;
|
|
13
|
+
clear(): void;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* JS maps (both plain objects and Map) maintain key insertion
|
|
17
|
+
* order, which means there is an easy way to simulate LRU behavior
|
|
18
|
+
* that should also perform quite well:
|
|
19
|
+
*
|
|
20
|
+
* To insert a new value, first delete the key from the inner _map,
|
|
21
|
+
* then _map.set(k, v). By deleting and reinserting, you ensure that the
|
|
22
|
+
* map sees the key as the last inserted key.
|
|
23
|
+
*
|
|
24
|
+
* Get does the same: if the key is present, delete and reinsert it.
|
|
25
|
+
*/
|
|
26
|
+
declare class LRUCache<T> implements Cache<T> {
|
|
27
|
+
_capacity: number;
|
|
28
|
+
_map: Map<string, T>;
|
|
29
|
+
constructor(capacity?: number);
|
|
30
|
+
set(key: string, value: T): void;
|
|
31
|
+
get(key: string): T | null;
|
|
32
|
+
has(key: string): boolean;
|
|
33
|
+
delete(key: string): void;
|
|
34
|
+
size(): number;
|
|
35
|
+
capacity(): number;
|
|
36
|
+
clear(): void;
|
|
37
|
+
}
|
|
38
|
+
export declare function createCache<T>(capacity?: number): LRUCache<T>;
|
|
39
|
+
export {};
|
|
40
|
+
/**
|
|
41
|
+
MIT License
|
|
42
|
+
|
|
43
|
+
Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
44
|
+
|
|
45
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
46
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
47
|
+
in the Software without restriction, including without limitation the rights
|
|
48
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
49
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
50
|
+
furnished to do so, subject to the following conditions:
|
|
51
|
+
|
|
52
|
+
The above copyright notice and this permission notice shall be included in all
|
|
53
|
+
copies or substantial portions of the Software.
|
|
54
|
+
|
|
55
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
56
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
57
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
58
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
59
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
60
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
61
|
+
SOFTWARE.
|
|
62
|
+
*/
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var cache_exports = {};
|
|
20
|
+
__export(cache_exports, {
|
|
21
|
+
createCache: () => createCache
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(cache_exports);
|
|
24
|
+
class LRUCache {
|
|
25
|
+
_capacity;
|
|
26
|
+
_map;
|
|
27
|
+
constructor(capacity = 1e3) {
|
|
28
|
+
this._capacity = capacity;
|
|
29
|
+
this._map = /* @__PURE__ */ new Map();
|
|
30
|
+
}
|
|
31
|
+
set(key, value) {
|
|
32
|
+
this._map.delete(key);
|
|
33
|
+
this._map.set(key, value);
|
|
34
|
+
if (this._map.size > this._capacity) {
|
|
35
|
+
const firstKey = this._map.keys().next();
|
|
36
|
+
if (!firstKey.done) {
|
|
37
|
+
this._map.delete(firstKey.value);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
get(key) {
|
|
42
|
+
const value = this._map.get(key);
|
|
43
|
+
if (value != null) {
|
|
44
|
+
this._map.delete(key);
|
|
45
|
+
this._map.set(key, value);
|
|
46
|
+
}
|
|
47
|
+
return value ?? null;
|
|
48
|
+
}
|
|
49
|
+
has(key) {
|
|
50
|
+
return this._map.has(key);
|
|
51
|
+
}
|
|
52
|
+
delete(key) {
|
|
53
|
+
this._map.delete(key);
|
|
54
|
+
}
|
|
55
|
+
size() {
|
|
56
|
+
return this._map.size;
|
|
57
|
+
}
|
|
58
|
+
capacity() {
|
|
59
|
+
return this._capacity - this._map.size;
|
|
60
|
+
}
|
|
61
|
+
clear() {
|
|
62
|
+
this._map.clear();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function createCache(capacity = 1e3) {
|
|
66
|
+
return new LRUCache(capacity);
|
|
67
|
+
}
|
|
68
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
+
0 && (module.exports = {
|
|
70
|
+
createCache
|
|
71
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { HoudiniClient } from '$houdini/runtime';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
export declare const HoudiniContext: React.Context<HoudiniClient | null>;
|
|
4
|
+
export declare const HoudiniProvider: ({ client, children, }: {
|
|
5
|
+
client: HoudiniClient;
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
}) => JSX.Element;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
const HoudiniContext = React.createContext(null);
|
|
3
|
+
const HoudiniProvider = ({
|
|
4
|
+
client,
|
|
5
|
+
children
|
|
6
|
+
}) => /* @__PURE__ */ React.createElement(HoudiniContext.Provider, { value: client }, children);
|
|
7
|
+
export {
|
|
8
|
+
HoudiniContext,
|
|
9
|
+
HoudiniProvider
|
|
10
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { useQuery } from './useQuery';
|
|
2
|
+
export { useQueryHandle } from './useQueryHandle';
|
|
3
|
+
export { useFragment } from './useFragment';
|
|
4
|
+
export { useFragmentHandle } from './useFragmentHandle';
|
|
5
|
+
export { useMutation } from './useMutation';
|
|
6
|
+
export { useSubscription } from './useSubscription';
|
|
7
|
+
export { type DocumentHandle } from './useDocumentHandle';
|
|
8
|
+
export { type UseQueryConfig } from './useQueryHandle';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useQuery } from "./useQuery";
|
|
2
|
+
import { useQueryHandle } from "./useQueryHandle";
|
|
3
|
+
import { useFragment } from "./useFragment";
|
|
4
|
+
import { useFragmentHandle } from "./useFragmentHandle";
|
|
5
|
+
import { useMutation } from "./useMutation";
|
|
6
|
+
import { useSubscription } from "./useSubscription";
|
|
7
|
+
import {} from "./useDocumentHandle";
|
|
8
|
+
import {} from "./useQueryHandle";
|
|
9
|
+
export {
|
|
10
|
+
useFragment,
|
|
11
|
+
useFragmentHandle,
|
|
12
|
+
useMutation,
|
|
13
|
+
useQuery,
|
|
14
|
+
useQueryHandle,
|
|
15
|
+
useSubscription
|
|
16
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
type UseEffectParams = Parameters<typeof React.useEffect>;
|
|
3
|
+
type EffectCallback = UseEffectParams[0];
|
|
4
|
+
type DependencyList = UseEffectParams[1];
|
|
5
|
+
type UseEffectReturn = ReturnType<typeof React.useEffect>;
|
|
6
|
+
/**
|
|
7
|
+
* @param value the value to be memoized (usually a dependency list)
|
|
8
|
+
* @returns a memoized version of the value as long as it remains deeply equal
|
|
9
|
+
*/
|
|
10
|
+
export declare function useDeepCompareMemoize<T>(value: T): T;
|
|
11
|
+
declare function useDeepCompareEffect(callback: EffectCallback, dependencies: DependencyList): UseEffectReturn;
|
|
12
|
+
export declare function useDeepCompareEffectNoCheck(callback: EffectCallback, dependencies: DependencyList): UseEffectReturn;
|
|
13
|
+
export default useDeepCompareEffect;
|
|
14
|
+
/**
|
|
15
|
+
The MIT License (MIT)
|
|
16
|
+
Copyright (c) 2020 Kent C. Dodds
|
|
17
|
+
|
|
18
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
19
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
20
|
+
in the Software without restriction, including without limitation the rights
|
|
21
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
22
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
23
|
+
furnished to do so, subject to the following conditions:
|
|
24
|
+
|
|
25
|
+
The above copyright notice and this permission notice shall be included in all
|
|
26
|
+
copies or substantial portions of the Software.
|
|
27
|
+
|
|
28
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
29
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
30
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
31
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
32
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
33
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
34
|
+
SOFTWARE.
|
|
35
|
+
*/
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { deepEquals } from "$houdini/runtime/lib/deepEquals";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
function checkDeps(deps) {
|
|
4
|
+
if (!deps || !deps.length) {
|
|
5
|
+
throw new Error(
|
|
6
|
+
"useDeepCompareEffect should not be used with no dependencies. Use React.useEffect instead."
|
|
7
|
+
);
|
|
8
|
+
}
|
|
9
|
+
if (deps.every(isPrimitive)) {
|
|
10
|
+
throw new Error(
|
|
11
|
+
"useDeepCompareEffect should not be used with dependencies that are all primitive values. Use React.useEffect instead."
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function isPrimitive(val) {
|
|
16
|
+
return val == null || /^[sbn]/.test(typeof val);
|
|
17
|
+
}
|
|
18
|
+
function useDeepCompareMemoize(value) {
|
|
19
|
+
const ref = React.useRef(value);
|
|
20
|
+
const signalRef = React.useRef(0);
|
|
21
|
+
if (!deepEquals(value, ref.current)) {
|
|
22
|
+
ref.current = value;
|
|
23
|
+
signalRef.current += 1;
|
|
24
|
+
}
|
|
25
|
+
return React.useMemo(() => ref.current, [signalRef.current]);
|
|
26
|
+
}
|
|
27
|
+
function useDeepCompareEffect(callback, dependencies) {
|
|
28
|
+
if (process.env.NODE_ENV !== "production") {
|
|
29
|
+
checkDeps(dependencies);
|
|
30
|
+
}
|
|
31
|
+
return React.useEffect(callback, useDeepCompareMemoize(dependencies));
|
|
32
|
+
}
|
|
33
|
+
function useDeepCompareEffectNoCheck(callback, dependencies) {
|
|
34
|
+
return React.useEffect(callback, useDeepCompareMemoize(dependencies));
|
|
35
|
+
}
|
|
36
|
+
var useDeepCompareEffect_default = useDeepCompareEffect;
|
|
37
|
+
export {
|
|
38
|
+
useDeepCompareEffect_default as default,
|
|
39
|
+
useDeepCompareEffectNoCheck,
|
|
40
|
+
useDeepCompareMemoize
|
|
41
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { DocumentStore } from '$houdini/runtime/client';
|
|
2
|
+
import { type QueryArtifact, GraphQLObject, CursorHandlers, OffsetHandlers, PageInfo, FetchFn, QueryResult, DocumentArtifact } from '$houdini/runtime/lib/types';
|
|
3
|
+
export declare function useDocumentHandle<_Artifact extends QueryArtifact, _Data extends GraphQLObject, _Input extends Record<string, any>>({ artifact, observer, storeValue, }: {
|
|
4
|
+
artifact: DocumentArtifact;
|
|
5
|
+
observer: DocumentStore<_Data, _Input>;
|
|
6
|
+
storeValue: QueryResult<_Data, _Input>;
|
|
7
|
+
}): DocumentHandle<_Artifact, _Data, _Input> & {
|
|
8
|
+
fetch: FetchFn<_Data, _Input>;
|
|
9
|
+
};
|
|
10
|
+
export type DocumentHandle<_Artifact extends QueryArtifact, _Data extends GraphQLObject = GraphQLObject, _Input extends {} = []> = {
|
|
11
|
+
data: _Data;
|
|
12
|
+
partial: boolean;
|
|
13
|
+
} & RefetchHandlers<_Artifact, _Data, _Input>;
|
|
14
|
+
type RefetchHandlers<_Artifact extends QueryArtifact, _Data extends GraphQLObject, _Input> = _Artifact extends {
|
|
15
|
+
refetch: {
|
|
16
|
+
paginated: true;
|
|
17
|
+
method: 'cursor';
|
|
18
|
+
};
|
|
19
|
+
} ? {
|
|
20
|
+
loadNext: CursorHandlers<_Data, _Input>['loadNextPage'];
|
|
21
|
+
loadNextPending: boolean;
|
|
22
|
+
loadPrevious: CursorHandlers<_Data, _Input>['loadPreviousPage'];
|
|
23
|
+
loadPreviousPending: boolean;
|
|
24
|
+
pageInfo: PageInfo;
|
|
25
|
+
} : _Artifact extends {
|
|
26
|
+
refetch: {
|
|
27
|
+
paginated: true;
|
|
28
|
+
method: 'offset';
|
|
29
|
+
};
|
|
30
|
+
} ? {
|
|
31
|
+
loadNext: OffsetHandlers<_Data, _Input>['loadNextPage'];
|
|
32
|
+
loadNextPending: boolean;
|
|
33
|
+
} : {};
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { extractPageInfo } from "$houdini/runtime/lib/pageInfo";
|
|
2
|
+
import { cursorHandlers, offsetHandlers } from "$houdini/runtime/lib/pagination";
|
|
3
|
+
import {
|
|
4
|
+
ArtifactKind
|
|
5
|
+
} from "$houdini/runtime/lib/types";
|
|
6
|
+
import React from "react";
|
|
7
|
+
function useDocumentHandle({
|
|
8
|
+
artifact,
|
|
9
|
+
observer,
|
|
10
|
+
storeValue
|
|
11
|
+
}) {
|
|
12
|
+
const [forwardPending, setForwardPending] = React.useState(false);
|
|
13
|
+
const [backwardPending, setBackwardPending] = React.useState(false);
|
|
14
|
+
return React.useMemo(() => {
|
|
15
|
+
const wrapLoad = (setLoading, fn) => {
|
|
16
|
+
return async (value) => {
|
|
17
|
+
setLoading(true);
|
|
18
|
+
const result = await fn(value);
|
|
19
|
+
setLoading(false);
|
|
20
|
+
return result;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
const fetchQuery = (args) => observer.send(args);
|
|
24
|
+
if (artifact.kind !== ArtifactKind.Query || !artifact.refetch?.paginated) {
|
|
25
|
+
return {
|
|
26
|
+
data: storeValue.data,
|
|
27
|
+
fetch: fetchQuery,
|
|
28
|
+
partial: storeValue.partial
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const getSession = async () => ({});
|
|
32
|
+
if (artifact.refetch.method === "cursor") {
|
|
33
|
+
const handlers = cursorHandlers({
|
|
34
|
+
artifact,
|
|
35
|
+
getState: () => storeValue.data,
|
|
36
|
+
getVariables: () => storeValue.variables,
|
|
37
|
+
storeName: artifact.name,
|
|
38
|
+
fetch: fetchQuery,
|
|
39
|
+
fetchUpdate: (args, updates) => {
|
|
40
|
+
return observer.send({
|
|
41
|
+
...args,
|
|
42
|
+
cacheParams: {
|
|
43
|
+
disableSubscriptions: true,
|
|
44
|
+
applyUpdates: updates,
|
|
45
|
+
...args?.cacheParams
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
getSession
|
|
50
|
+
});
|
|
51
|
+
return {
|
|
52
|
+
data: storeValue.data,
|
|
53
|
+
fetch: handlers.fetch,
|
|
54
|
+
partial: storeValue.partial,
|
|
55
|
+
loadNext: wrapLoad(setForwardPending, handlers.loadNextPage),
|
|
56
|
+
loadNextPending: forwardPending,
|
|
57
|
+
loadPrevious: wrapLoad(setBackwardPending, handlers.loadPreviousPage),
|
|
58
|
+
loadPreviousPending: backwardPending,
|
|
59
|
+
pageInfo: extractPageInfo(storeValue.data, artifact.refetch.path)
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
if (artifact.refetch.method === "offset") {
|
|
63
|
+
const handlers = offsetHandlers({
|
|
64
|
+
artifact,
|
|
65
|
+
getState: () => storeValue.data,
|
|
66
|
+
getVariables: () => storeValue.variables,
|
|
67
|
+
storeName: artifact.name,
|
|
68
|
+
fetch: fetchQuery,
|
|
69
|
+
fetchUpdate: async (args, updates = ["append"]) => {
|
|
70
|
+
return observer.send({
|
|
71
|
+
...args,
|
|
72
|
+
cacheParams: {
|
|
73
|
+
disableSubscriptions: true,
|
|
74
|
+
applyUpdates: updates,
|
|
75
|
+
...args?.cacheParams
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
getSession: async () => ({})
|
|
80
|
+
});
|
|
81
|
+
return {
|
|
82
|
+
data: storeValue.data,
|
|
83
|
+
fetch: handlers.fetch,
|
|
84
|
+
partial: storeValue.partial,
|
|
85
|
+
loadNext: wrapLoad(setForwardPending, handlers.loadNextPage),
|
|
86
|
+
loadNextPending: forwardPending
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
data: storeValue.data,
|
|
91
|
+
fetch: fetchQuery,
|
|
92
|
+
refetch: fetchQuery,
|
|
93
|
+
partial: storeValue.partial
|
|
94
|
+
};
|
|
95
|
+
}, [artifact, observer, storeValue, true, true]);
|
|
96
|
+
}
|
|
97
|
+
export {
|
|
98
|
+
useDocumentHandle
|
|
99
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { DocumentArtifact, QueryResult } from '$houdini/lib/types';
|
|
2
|
+
import type { DocumentStore, ObserveParams } from '$houdini/runtime/client';
|
|
3
|
+
import { GraphQLObject } from 'houdini';
|
|
4
|
+
export type UseDocumentStoreParams<_Artifact extends DocumentArtifact, _Data extends GraphQLObject> = {
|
|
5
|
+
artifact: _Artifact;
|
|
6
|
+
} & Partial<ObserveParams<_Data>>;
|
|
7
|
+
export declare function useDocumentStore<_Data extends GraphQLObject = GraphQLObject, _Input extends {} = {}, _Artifact extends DocumentArtifact = DocumentArtifact>({ artifact, ...observeParams }: UseDocumentStoreParams<_Artifact, _Data>): [
|
|
8
|
+
QueryResult<_Data, _Input>,
|
|
9
|
+
DocumentStore<_Data, _Input>,
|
|
10
|
+
(store: DocumentStore<_Data, _Input>) => void
|
|
11
|
+
];
|