@studiocms/cfetch 0.1.4 → 0.1.5

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 CHANGED
@@ -3,6 +3,7 @@
3
3
  ![Readme's Banner](https://github.com/withstudiocms/cfetch/blob/main/assets/cfetch-banner.png)
4
4
 
5
5
  [![NPM Version](https://img.shields.io/npm/v/@studiocms/cfetch?logo=npm)](https://npm.im/@studiocms/cfetch)
6
+ [![JSR](https://jsr.io/badges/@studiocms/cfetch)](https://jsr.io/@studiocms/cfetch)
6
7
  [![Formatted with Biome](https://img.shields.io/badge/Formatted_with-Biome-60a5fa?style=flat&logo=biome)](https://biomejs.dev/)
7
8
  [![Built with Astro](https://astro.badg.es/v2/built-with-astro/tiny.svg)](https://astro.build)
8
9
 
package/dist/consts.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * This module contains constants for cFetch
3
+ * @module
4
+ */
1
5
  import type { CacheConfig } from './types.js';
2
6
  /**
3
7
  * Default cache configuration object.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,7 @@
1
- /// <reference types="./cache.d.ts" preserve="true" />
1
+ /**
2
+ * This module contains the AstroIntegration for cFetch
3
+ * @module
4
+ */
2
5
  import type { AstroIntegration } from 'astro';
3
6
  import type { CacheConfig } from './types.js';
4
7
  /**
@@ -32,5 +35,5 @@ import type { CacheConfig } from './types.js';
32
35
  * // Use the data in your component
33
36
  * ```
34
37
  */
35
- export declare function astroCache(opts?: CacheConfig): AstroIntegration;
36
- export default astroCache;
38
+ export declare function cFetch(opts?: CacheConfig): AstroIntegration;
39
+ export default cFetch;
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { defaultConfig } from "./consts.js";
2
+ import stub from "./stub.js";
2
3
  import { addVirtualImports, createResolver } from "./utils/integration.js";
3
- function astroCache(opts) {
4
+ function cFetch(opts) {
4
5
  const name = "@studiocms/cfetch";
5
6
  const { resolve } = createResolver(import.meta.url);
6
7
  const options = {
@@ -18,12 +19,18 @@ function astroCache(opts) {
18
19
  "c:fetch": `export * from '${resolve("./wrappers.js")}';`
19
20
  }
20
21
  });
22
+ },
23
+ "astro:config:done": ({ injectTypes }) => {
24
+ injectTypes({
25
+ filename: "cfetch.d.ts",
26
+ content: stub
27
+ });
21
28
  }
22
29
  }
23
30
  };
24
31
  }
25
- var index_default = astroCache;
32
+ var index_default = cFetch;
26
33
  export {
27
- astroCache,
34
+ cFetch,
28
35
  index_default as default
29
36
  };
package/dist/stub.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * This module contains a stub file for type generation
3
+ * @module
4
+ */
5
+ declare const stub: string;
6
+ export default stub;
@@ -1,32 +1,35 @@
1
+ import { createResolver } from "./utils/integration.js";
2
+ const { resolve } = createResolver(import.meta.url);
3
+ const stub = `
1
4
  declare module 'virtual:cfetch/config' {
2
5
  /**
3
6
  * Default configuration for the cache passed from the user.
4
7
  *
5
8
  * @property lifetime - Specifies the duration for which the cache is valid.
6
9
  * The format should be a template literal string representing
7
- * either minutes (`<number>m`) or hours (`<number>h`).
10
+ * either minutes (\`<number>m\`) or hours (\`<number>h\`).
8
11
  * For example: "5m" for 5 minutes or "2h" for 2 hours.
9
12
  */
10
- const defaultConfig: import('./types').CacheConfig;
13
+ const defaultConfig: import(${resolve("./types")}).CacheConfig;
11
14
  export default defaultConfig;
12
15
  }
13
16
 
14
17
  declare module 'c:fetch' {
15
18
  /**
16
- * Represents the type of the global `fetch` function.
19
+ * Represents the type of the global \`fetch\` function.
17
20
  *
18
- * This type is derived from the built-in `fetch` function, allowing you to
19
- * use it as a reference for type-safe operations involving `fetch`.
21
+ * This type is derived from the built-in \`fetch\` function, allowing you to
22
+ * use it as a reference for type-safe operations involving \`fetch\`.
20
23
  */
21
24
  type FetchType = typeof fetch;
22
25
  /**
23
- * Represents the input parameter type for the `FetchType` function.
24
- * This type is derived from the first parameter of the `FetchType` function.
26
+ * Represents the input parameter type for the \`FetchType\` function.
27
+ * This type is derived from the first parameter of the \`FetchType\` function.
25
28
  */
26
29
  type Input = Parameters<FetchType>[0];
27
30
  /**
28
- * Represents the `init` parameter of the `fetch` function, which is the second parameter
29
- * in the `FetchType` function signature. This type is used to configure the request,
31
+ * Represents the \`init\` parameter of the\`fetch\` function, which is the second parameter
32
+ * in the \`FetchType\` function signature. This type is used to configure the request,
30
33
  * including options such as method, headers, body, and other settings.
31
34
  */
32
35
  type Init = Parameters<FetchType>[1];
@@ -42,17 +45,17 @@ declare module 'c:fetch' {
42
45
  *
43
46
  * @property lifetime - Specifies the duration for which the cache is valid.
44
47
  * The format should be a template literal string representing
45
- * either minutes (`<number>m`) or hours (`<number>h`).
48
+ * either minutes (\`<number>m\`) or hours (\`<number>h\`).
46
49
  * For example: "5m" for 5 minutes or "2h" for 2 hours.
47
50
  */
48
51
  export interface CacheConfig {
49
52
  /**
50
53
  * Specifies the duration for which the cache is valid.
51
54
  * The format should be a template literal string representing
52
- * either minutes (`<number>m`) or hours (`<number>h`).
55
+ * either minutes (\`<number>m\`) or hours (\`<number>h\`).
53
56
  * For example: "5m" for 5 minutes or "2h" for 2 hours.
54
57
  */
55
- lifetime: `${number}m` | `${number}h`;
58
+ lifetime: \`<number>m\` | \`<number>h\`;
56
59
  }
57
60
  /**
58
61
  * Fetches data with caching capabilities. If the data is not present in the cache
@@ -61,13 +64,13 @@ declare module 'c:fetch' {
61
64
  *
62
65
  * @param input - The input to the fetch function, typically a URL or Request object.
63
66
  * @param init - An optional configuration object for the fetch request.
64
- * @param cacheConfig - Partial configuration for the cache behavior. Defaults to `defaultConfig`.
67
+ * @param cacheConfig - Partial configuration for the cache behavior. Defaults to \`defaultConfig\`.
65
68
  * @param type - Optional parameter specifying the expected response body format.
66
69
  * Can be either 'json' or 'text'. Determines how the response body is processed.
67
70
  * @param metadata - A boolean indicating whether to return the full cached object (including metadata)
68
- * or just the data. Defaults to `false`.
69
- * @returns The fetched or cached data. If `full` is `true`, returns an object containing
70
- * both the data and metadata (e.g., `lastCheck`).
71
+ * or just the data. Defaults to \`false\`.
72
+ * @returns The fetched or cached data. If \`full\` is \`true\`, returns an object containing
73
+ * both the data and metadata (e.g., \`lastCheck\`).
71
74
  * @throws An error if fetching new data fails and no cached data is available.
72
75
  */
73
76
  export function cFetch(
@@ -84,3 +87,9 @@ declare module 'c:fetch' {
84
87
  metadata?: boolean
85
88
  ): Promise<CacheDataValue>;
86
89
  }
90
+
91
+ `;
92
+ var stub_default = stub;
93
+ export {
94
+ stub_default as default
95
+ };
package/dist/types.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * This module contains types for the cfetch package
3
+ * @module
4
+ */
1
5
  /**
2
6
  * Represents the type of the global `fetch` function.
3
7
  *
@@ -1,3 +1,7 @@
1
+ /**
2
+ * This module contains Astro Integration Utilities
3
+ * @module
4
+ */
1
5
  import type path from 'node:path';
2
6
  import type { HookParameters } from 'astro';
3
7
  import type { PluginOption } from 'vite';
@@ -1,3 +1,7 @@
1
+ /**
2
+ * This module contains helper functions for cFetch
3
+ * @module
4
+ */
1
5
  /**
2
6
  * Determines whether a given date is older than a specified lifetime.
3
7
  *
@@ -1,3 +1,7 @@
1
+ /**
2
+ * This module contains functions that wrap and cache the native fetch function
3
+ * @module
4
+ */
1
5
  import type { CacheConfig, CacheDataValue, Init, Input } from './types.js';
2
6
  export type { CacheConfig };
3
7
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@studiocms/cfetch",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Astro integration that allows you to have a cached fetch function in your Astro SSR project.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://studiocms.dev",
@@ -47,13 +47,13 @@
47
47
  "./types": {
48
48
  "types": "./dist/types.d.ts",
49
49
  "default": "./dist/types.js"
50
- },
51
- "./v/types": "./dist/cache.d.ts"
50
+ }
52
51
  },
53
52
  "devDependencies": {
54
53
  "@inox-tools/astro-tests": "^0.5.1",
55
54
  "@types/node": "^22.0.0",
56
- "jest-extended": "^4.0.2"
55
+ "jest-extended": "^4.0.2",
56
+ "astro": "^5.5"
57
57
  },
58
58
  "peerDependencies": {
59
59
  "astro": "^5.5",