houdini-react 1.2.0-react.1 → 1.2.7
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/README.md +1 -1
- package/build/plugin/codegen/entries.d.ts +6 -0
- package/build/plugin/codegen/index.d.ts +14 -0
- package/build/plugin/codegen/manifest.d.ts +42 -0
- package/build/plugin/codegen/render.d.ts +2 -0
- package/build/plugin/codegen/router.d.ts +8 -0
- package/build/plugin/codegen/typeRoot.d.ts +6 -0
- package/build/plugin/config.d.ts +2 -1
- package/build/plugin/conventions.d.ts +24 -0
- package/build/plugin/dedent.d.ts +1 -0
- package/build/plugin/extract.d.ts +1 -1
- package/build/plugin/index.d.ts +16 -3
- package/build/plugin/vite.d.ts +19 -0
- package/build/plugin-cjs/index.js +132171 -43771
- package/build/plugin-esm/index.js +132162 -43765
- package/build/runtime/client.d.ts +3 -0
- package/build/runtime/clientPlugin.d.ts +3 -0
- package/build/runtime/hooks/useDocumentHandle.d.ts +4 -4
- package/build/runtime/hooks/useDocumentStore.d.ts +6 -5
- package/build/runtime/hooks/useDocumentSubscription.d.ts +4 -3
- package/build/runtime/hooks/useFragment.d.ts +3 -2
- package/build/runtime/hooks/useFragmentHandle.d.ts +2 -3
- package/build/runtime/hooks/useMutation.d.ts +2 -2
- package/build/runtime/hooks/useQuery.d.ts +3 -3
- package/build/runtime/hooks/useQueryHandle.d.ts +3 -3
- package/build/runtime/hooks/useSubscription.d.ts +2 -2
- package/build/runtime/hooks/useSubscriptionHandle.d.ts +3 -3
- package/build/runtime/index.d.ts +30 -1
- package/build/runtime/manifest.d.ts +3 -0
- package/build/runtime/routing/components/Link.d.ts +5 -0
- package/build/runtime/routing/components/Router.d.ts +56 -0
- package/build/runtime/routing/components/index.d.ts +2 -0
- package/build/runtime/routing/index.d.ts +3 -0
- package/build/runtime/routing/lib/cache.d.ts +7 -0
- package/build/runtime/routing/lib/match.d.ts +38 -0
- package/build/runtime/routing/lib/types.d.ts +23 -0
- package/build/runtime-cjs/client.d.ts +3 -0
- package/build/runtime-cjs/client.js +26 -0
- package/build/runtime-cjs/clientPlugin.d.ts +3 -0
- package/build/{next-cjs/index.js → runtime-cjs/clientPlugin.js} +15 -26
- package/build/runtime-cjs/hooks/useDocumentHandle.d.ts +4 -4
- package/build/runtime-cjs/hooks/useDocumentHandle.js +11 -7
- package/build/runtime-cjs/hooks/useDocumentStore.d.ts +6 -5
- package/build/runtime-cjs/hooks/useDocumentStore.js +9 -4
- package/build/runtime-cjs/hooks/useDocumentSubscription.d.ts +4 -3
- package/build/runtime-cjs/hooks/useDocumentSubscription.js +15 -8
- package/build/runtime-cjs/hooks/useFragment.d.ts +3 -2
- package/build/runtime-cjs/hooks/useFragment.js +9 -7
- package/build/runtime-cjs/hooks/useFragmentHandle.d.ts +2 -3
- package/build/runtime-cjs/hooks/useMutation.d.ts +2 -2
- package/build/runtime-cjs/hooks/useMutation.js +3 -1
- package/build/runtime-cjs/hooks/useQuery.d.ts +3 -3
- package/build/runtime-cjs/hooks/useQueryHandle.d.ts +3 -3
- package/build/runtime-cjs/hooks/useQueryHandle.js +4 -4
- package/build/runtime-cjs/hooks/useSubscription.d.ts +2 -2
- package/build/runtime-cjs/hooks/useSubscriptionHandle.d.ts +3 -3
- package/build/runtime-cjs/index.d.ts +30 -1
- package/build/runtime-cjs/index.js +89 -3
- package/build/runtime-cjs/manifest.d.ts +3 -0
- package/build/runtime-cjs/manifest.js +27 -0
- package/build/runtime-cjs/routing/components/Link.d.ts +5 -0
- package/build/runtime-cjs/{hooks/useHoudiniClient.js → routing/components/Link.js} +22 -13
- package/build/runtime-cjs/routing/components/Router.d.ts +56 -0
- package/build/runtime-cjs/routing/components/Router.js +296 -0
- package/build/runtime-cjs/routing/components/index.d.ts +2 -0
- package/build/runtime-cjs/{context.js → routing/components/index.js} +15 -19
- package/build/runtime-cjs/routing/index.d.ts +3 -0
- package/build/runtime-cjs/routing/index.js +30 -0
- package/build/runtime-cjs/routing/lib/cache.d.ts +7 -0
- package/build/runtime-cjs/{lib → routing/lib}/cache.js +23 -40
- package/build/runtime-cjs/routing/lib/match.d.ts +38 -0
- package/build/runtime-cjs/routing/lib/match.js +149 -0
- package/build/runtime-cjs/routing/lib/types.d.ts +23 -0
- package/build/runtime-cjs/routing/lib/types.js +16 -0
- package/build/runtime-esm/client.d.ts +3 -0
- package/build/runtime-esm/client.js +4 -0
- package/build/runtime-esm/clientPlugin.d.ts +3 -0
- package/build/runtime-esm/clientPlugin.js +17 -0
- package/build/runtime-esm/hooks/useDocumentHandle.d.ts +4 -4
- package/build/runtime-esm/hooks/useDocumentHandle.js +12 -10
- package/build/runtime-esm/hooks/useDocumentStore.d.ts +6 -5
- package/build/runtime-esm/hooks/useDocumentStore.js +9 -4
- package/build/runtime-esm/hooks/useDocumentSubscription.d.ts +4 -3
- package/build/runtime-esm/hooks/useDocumentSubscription.js +15 -8
- package/build/runtime-esm/hooks/useFragment.d.ts +3 -2
- package/build/runtime-esm/hooks/useFragment.js +9 -7
- package/build/runtime-esm/hooks/useFragmentHandle.d.ts +2 -3
- package/build/runtime-esm/hooks/useMutation.d.ts +2 -2
- package/build/runtime-esm/hooks/useMutation.js +3 -1
- package/build/runtime-esm/hooks/useQuery.d.ts +3 -3
- package/build/runtime-esm/hooks/useQueryHandle.d.ts +3 -3
- package/build/runtime-esm/hooks/useQueryHandle.js +4 -4
- package/build/runtime-esm/hooks/useSubscription.d.ts +2 -2
- package/build/runtime-esm/hooks/useSubscriptionHandle.d.ts +3 -3
- package/build/runtime-esm/index.d.ts +30 -1
- package/build/runtime-esm/index.js +81 -2
- package/build/runtime-esm/manifest.d.ts +3 -0
- package/build/runtime-esm/manifest.js +5 -0
- package/build/runtime-esm/routing/components/Link.d.ts +5 -0
- package/build/runtime-esm/routing/components/Link.js +21 -0
- package/build/runtime-esm/routing/components/Router.d.ts +56 -0
- package/build/runtime-esm/routing/components/Router.js +257 -0
- package/build/runtime-esm/routing/components/index.d.ts +2 -0
- package/build/runtime-esm/routing/components/index.js +9 -0
- package/build/runtime-esm/routing/index.d.ts +3 -0
- package/build/runtime-esm/routing/index.js +5 -0
- package/build/runtime-esm/routing/lib/cache.d.ts +7 -0
- package/build/runtime-esm/routing/lib/cache.js +29 -0
- package/build/runtime-esm/routing/lib/match.d.ts +38 -0
- package/build/runtime-esm/routing/lib/match.js +122 -0
- package/build/runtime-esm/routing/lib/types.d.ts +23 -0
- package/build/runtime-esm/routing/lib/types.js +0 -0
- package/build/server/compat.d.ts +7 -0
- package/build/server/index.d.ts +17 -0
- package/build/server/session.d.ts +3 -0
- package/build/server-cjs/index.js +166712 -0
- package/build/server-esm/index.js +166703 -0
- package/package.json +21 -10
- package/build/next/index.d.ts +0 -2
- package/build/next-esm/index.js +0 -26
- package/build/runtime/context.d.ts +0 -7
- package/build/runtime/hooks/useHoudiniClient.d.ts +0 -2
- package/build/runtime/lib/cache.d.ts +0 -62
- package/build/runtime-cjs/context.d.ts +0 -7
- package/build/runtime-cjs/hooks/useHoudiniClient.d.ts +0 -2
- package/build/runtime-cjs/lib/cache.d.ts +0 -62
- package/build/runtime-esm/context.d.ts +0 -7
- package/build/runtime-esm/context.js +0 -10
- package/build/runtime-esm/hooks/useHoudiniClient.d.ts +0 -2
- package/build/runtime-esm/hooks/useHoudiniClient.js +0 -12
- package/build/runtime-esm/lib/cache.d.ts +0 -62
- package/build/runtime-esm/lib/cache.js +0 -47
- /package/build/{next-cjs → server-cjs}/package.json +0 -0
- /package/build/{next-esm → server-esm}/package.json +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "houdini-react",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.7",
|
|
4
4
|
"description": "The React plugin for houdini",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -16,41 +16,52 @@
|
|
|
16
16
|
},
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"devDependencies": {
|
|
19
|
+
"@types/cookie-parser": "^1.4.3",
|
|
20
|
+
"@types/cookie-session": "^2.0.44",
|
|
21
|
+
"@types/cookies": "^0.7.7",
|
|
19
22
|
"@types/estraverse": "^5.1.2",
|
|
20
|
-
"@types/
|
|
23
|
+
"@types/express": "^4.17.17",
|
|
24
|
+
"@types/react-dom": "^18.0.10",
|
|
21
25
|
"next": "^13.0.1",
|
|
22
26
|
"scripts": "^1.0.0"
|
|
23
27
|
},
|
|
24
28
|
"dependencies": {
|
|
25
29
|
"@babel/parser": "^7.19.3",
|
|
30
|
+
"@babel/types": "^7.21.4",
|
|
26
31
|
"@types/react": "^18.0.28",
|
|
27
|
-
"
|
|
32
|
+
"cookie-parser": "^1.4.6",
|
|
33
|
+
"cookie-session": "^2.0.0",
|
|
34
|
+
"cookies": "^0.8.0",
|
|
28
35
|
"estraverse": "^5.3.0",
|
|
36
|
+
"express": "^4.18.2",
|
|
29
37
|
"graphql": "^15.8.0",
|
|
30
38
|
"react": "^18.2.0",
|
|
39
|
+
"react-streaming": "^0.3.9",
|
|
31
40
|
"recast": "^0.23.1",
|
|
32
41
|
"rollup": "^3.7.4",
|
|
33
42
|
"use-deep-compare-effect": "^1.8.1",
|
|
34
|
-
"houdini": "^1.2.
|
|
43
|
+
"houdini": "^1.2.7"
|
|
35
44
|
},
|
|
36
45
|
"files": [
|
|
37
46
|
"build"
|
|
38
47
|
],
|
|
39
48
|
"exports": {
|
|
40
49
|
"./package.json": "./package.json",
|
|
41
|
-
"./next": {
|
|
42
|
-
"import": "./build/next-esm/index.js",
|
|
43
|
-
"require": "./build/next-cjs/index.js"
|
|
44
|
-
},
|
|
45
50
|
".": {
|
|
51
|
+
"types": "./build/plugin/index.d.ts",
|
|
46
52
|
"import": "./build/plugin-esm/index.js",
|
|
47
53
|
"require": "./build/plugin-cjs/index.js"
|
|
54
|
+
},
|
|
55
|
+
"./server": {
|
|
56
|
+
"types": "./build/server/index.d.ts",
|
|
57
|
+
"import": "./build/server-esm/index.js",
|
|
58
|
+
"require": "./build/server-cjs/index.js"
|
|
48
59
|
}
|
|
49
60
|
},
|
|
50
61
|
"typesVersions": {
|
|
51
62
|
"*": {
|
|
52
|
-
"
|
|
53
|
-
"build/
|
|
63
|
+
"server": [
|
|
64
|
+
"build/server/index.d.ts"
|
|
54
65
|
]
|
|
55
66
|
}
|
|
56
67
|
},
|
package/build/next/index.d.ts
DELETED
package/build/next-esm/index.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
const require = conflict_free(import.meta.url);
|
|
2
|
-
|
|
3
|
-
// src/next/index.ts
|
|
4
|
-
function withHoudini(nextConfig) {
|
|
5
|
-
return {
|
|
6
|
-
...nextConfig,
|
|
7
|
-
webpack(config, options) {
|
|
8
|
-
config.module.rules.push({
|
|
9
|
-
test: /\.(jsx|tsx)$/,
|
|
10
|
-
use: [
|
|
11
|
-
options.defaultLoaders.babel,
|
|
12
|
-
{
|
|
13
|
-
loader: "houdini/webpack"
|
|
14
|
-
}
|
|
15
|
-
]
|
|
16
|
-
});
|
|
17
|
-
if (nextConfig && typeof nextConfig.webpack === "function") {
|
|
18
|
-
return nextConfig.webpack(config, options);
|
|
19
|
-
}
|
|
20
|
-
return config;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
export {
|
|
25
|
-
withHoudini
|
|
26
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
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;
|
|
@@ -1,62 +0,0 @@
|
|
|
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
|
-
*/
|
|
@@ -1,7 +0,0 @@
|
|
|
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;
|
|
@@ -1,62 +0,0 @@
|
|
|
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
|
-
*/
|
|
@@ -1,7 +0,0 @@
|
|
|
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;
|
|
@@ -1,10 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { HoudiniContext } from "../context";
|
|
3
|
-
function useHoudiniClient() {
|
|
4
|
-
const client = React.useContext(HoudiniContext);
|
|
5
|
-
if (!client) {
|
|
6
|
-
throw new Error("Could not find client");
|
|
7
|
-
}
|
|
8
|
-
return client;
|
|
9
|
-
}
|
|
10
|
-
export {
|
|
11
|
-
useHoudiniClient
|
|
12
|
-
};
|
|
@@ -1,62 +0,0 @@
|
|
|
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
|
-
*/
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
class LRUCache {
|
|
2
|
-
_capacity;
|
|
3
|
-
_map;
|
|
4
|
-
constructor(capacity = 1e3) {
|
|
5
|
-
this._capacity = capacity;
|
|
6
|
-
this._map = /* @__PURE__ */ new Map();
|
|
7
|
-
}
|
|
8
|
-
set(key, value) {
|
|
9
|
-
this._map.delete(key);
|
|
10
|
-
this._map.set(key, value);
|
|
11
|
-
if (this._map.size > this._capacity) {
|
|
12
|
-
const firstKey = this._map.keys().next();
|
|
13
|
-
if (!firstKey.done) {
|
|
14
|
-
this._map.delete(firstKey.value);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
get(key) {
|
|
19
|
-
const value = this._map.get(key);
|
|
20
|
-
if (value != null) {
|
|
21
|
-
this._map.delete(key);
|
|
22
|
-
this._map.set(key, value);
|
|
23
|
-
}
|
|
24
|
-
return value ?? null;
|
|
25
|
-
}
|
|
26
|
-
has(key) {
|
|
27
|
-
return this._map.has(key);
|
|
28
|
-
}
|
|
29
|
-
delete(key) {
|
|
30
|
-
this._map.delete(key);
|
|
31
|
-
}
|
|
32
|
-
size() {
|
|
33
|
-
return this._map.size;
|
|
34
|
-
}
|
|
35
|
-
capacity() {
|
|
36
|
-
return this._capacity - this._map.size;
|
|
37
|
-
}
|
|
38
|
-
clear() {
|
|
39
|
-
this._map.clear();
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
function createCache(capacity = 1e3) {
|
|
43
|
-
return new LRUCache(capacity);
|
|
44
|
-
}
|
|
45
|
-
export {
|
|
46
|
-
createCache
|
|
47
|
-
};
|
|
File without changes
|
|
File without changes
|