houdini-react 2.0.0-go.1 → 2.0.0-go.10
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/bin/houdini-react +84 -0
- package/package.json +90 -87
- package/postInstall.js +351 -0
- package/runtime/client.ts +5 -0
- package/runtime/clientPlugin.ts +17 -0
- package/runtime/componentFields.ts +79 -0
- package/runtime/hooks/index.ts +9 -0
- package/runtime/hooks/useDeepCompareEffect.ts +89 -0
- package/runtime/hooks/useDocumentHandle.ts +224 -0
- package/runtime/hooks/useDocumentStore.ts +76 -0
- package/runtime/hooks/useDocumentSubscription.ts +62 -0
- package/runtime/hooks/useFragment.ts +102 -0
- package/runtime/hooks/useFragmentHandle.ts +47 -0
- package/runtime/hooks/useIsMounted.ts +14 -0
- package/runtime/hooks/useMutation.ts +54 -0
- package/runtime/hooks/useQuery.ts +17 -0
- package/runtime/hooks/useQueryHandle.ts +184 -0
- package/runtime/hooks/useSubscription.ts +12 -0
- package/runtime/hooks/useSubscriptionHandle.ts +33 -0
- package/runtime/index.tsx +49 -0
- package/runtime/manifest.ts +6 -0
- package/runtime/package.json +1 -0
- package/runtime/routing/Router.tsx +887 -0
- package/runtime/routing/cache.ts +52 -0
- package/runtime/routing/index.ts +2 -0
- package/server/index.d.ts +1 -0
- package/server/index.js +4 -0
- package/server/package.json +1 -0
- package/vite/index.d.ts +3 -0
- package/vite/index.js +11 -0
- package/vite/package.json +1 -0
- package/shim.cjs +0 -64
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// a suspense cache is an object that maintains a key-value store of
|
|
2
|
+
// objects. If a value is missing when get() is called, a promise
|
|
3
|
+
// is thrown that resolves when a value is passed to set()
|
|
4
|
+
import { LRUCache } from 'houdini/runtime'
|
|
5
|
+
|
|
6
|
+
export function suspense_cache<T>(initialData?: Record<string, T>): SuspenseCache<T> {
|
|
7
|
+
const cache = new SuspenseCache<T>()
|
|
8
|
+
|
|
9
|
+
for (const [key, value] of Object.entries(initialData ?? {})) {
|
|
10
|
+
cache.set(key, value)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return cache
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class SuspenseCache<_Data> extends LRUCache<_Data> {
|
|
17
|
+
// if get is called before set, we need to invoke a callback.
|
|
18
|
+
// that means we need a place to put our callbacks
|
|
19
|
+
#callbacks: Map<string, { resolve: () => void; reject: () => void }[]> = new Map()
|
|
20
|
+
|
|
21
|
+
get(key: string): _Data {
|
|
22
|
+
// if there is a value, use that
|
|
23
|
+
if (super.has(key)) {
|
|
24
|
+
return super.get(key)!
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// we don't have a value, so we need to throw a promise
|
|
28
|
+
// that resolves when a value is passed to set()
|
|
29
|
+
throw new Promise<void>((resolve, reject) => {
|
|
30
|
+
this.#subscribe(key, resolve, reject)
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// TODO: reject?
|
|
35
|
+
|
|
36
|
+
set(key: string, value: _Data) {
|
|
37
|
+
// perform the set like normal
|
|
38
|
+
super.set(key, value)
|
|
39
|
+
|
|
40
|
+
// if there are subscribers, resolve them
|
|
41
|
+
if (this.#callbacks.has(key)) {
|
|
42
|
+
// resolve all of the callbacks
|
|
43
|
+
this.#callbacks.get(key)?.forEach(({ resolve }) => resolve())
|
|
44
|
+
// delete the key
|
|
45
|
+
this.#callbacks.delete(key)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
#subscribe(key: string, resolve: () => void, reject: () => void) {
|
|
50
|
+
this.#callbacks.set(key, [...(this.#callbacks.get(key) || []), { resolve, reject }])
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { renderToStream } from 'react-streaming-compat/server';
|
package/server/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
package/vite/index.d.ts
ADDED
package/vite/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
package/shim.cjs
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
function getBinaryPath() {
|
|
4
|
-
// lookup table for all platforms and binary distribution packages
|
|
5
|
-
const BINARY_DISTRIBUTION_PACKAGES = {
|
|
6
|
-
'linux-x64': 'houdini-react-linux-x64',
|
|
7
|
-
'linux-arm64': 'houdini-react-linux-arm64',
|
|
8
|
-
'win32-x64': 'houdini-react-windows-x64',
|
|
9
|
-
'win32-arm64': 'houdini-react-windows-arm64',
|
|
10
|
-
'darwin-x64': 'houdini-react-darwin-x64',
|
|
11
|
-
'darwin-arm64': 'houdini-react-darwin-arm64',
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// windows binaries end with .exe so we need to special case them
|
|
15
|
-
const binaryName = process.platform === 'win32' ? 'houdini-react.exe' : 'houdini-react'
|
|
16
|
-
|
|
17
|
-
// determine package name for this platform
|
|
18
|
-
const platformSpecificPackageName =
|
|
19
|
-
BINARY_DISTRIBUTION_PACKAGES[`${process.platform}-${process.arch}`]
|
|
20
|
-
|
|
21
|
-
try {
|
|
22
|
-
// resolving will fail if the optionalDependency was not installed
|
|
23
|
-
return require.resolve(`../${platformSpecificPackageName}/bin/${binaryName}`)
|
|
24
|
-
} catch (e) {
|
|
25
|
-
return require('path').join(__dirname, binaryName)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
// instead of execFileSync, use spawn to handle the process more gracefully
|
|
29
|
-
const childProcess = require('child_process').spawn(getBinaryPath(), process.argv.slice(2), {
|
|
30
|
-
stdio: 'inherit',
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
// array of signals we want to handle
|
|
34
|
-
const signals = ['SIGTERM', 'SIGINT', 'SIGQUIT', 'SIGHUP']
|
|
35
|
-
|
|
36
|
-
// handle each signal
|
|
37
|
-
signals.forEach((signal) => {
|
|
38
|
-
process.on(signal, () => {
|
|
39
|
-
if (childProcess) {
|
|
40
|
-
// on windows, we need to use taskkill for proper tree killing
|
|
41
|
-
if (process.platform === 'win32') {
|
|
42
|
-
require('child_process').spawn('taskkill', ['/pid', childProcess.pid, '/f', '/t'])
|
|
43
|
-
} else {
|
|
44
|
-
try {
|
|
45
|
-
childProcess.kill(signal)
|
|
46
|
-
} catch (err) {
|
|
47
|
-
// if the process is already gone, that's fine
|
|
48
|
-
if (err.code !== 'ESRCH') throw err
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
process.exit(0)
|
|
53
|
-
})
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
// handle child process exit
|
|
57
|
-
childProcess.on('exit', (code, signal) => {
|
|
58
|
-
// if the child was terminated due to a signal, exit with the same signal
|
|
59
|
-
if (signal) {
|
|
60
|
-
process.exit(0)
|
|
61
|
-
} else {
|
|
62
|
-
process.exit(code)
|
|
63
|
-
}
|
|
64
|
-
})
|