@defjs/vue 0.0.2 → 0.0.3

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.
Files changed (4) hide show
  1. package/README.md +5 -5
  2. package/index.d.ts +14 -14
  3. package/index.js +10 -10
  4. package/package.json +2 -2
package/README.md CHANGED
@@ -10,7 +10,7 @@ Keeping SDK definitions in their own package means the SDK needs no Vue dependen
10
10
  bun add @defjs/core @defjs/vue vue
11
11
  ```
12
12
 
13
- The package is ESM and requires `@defjs/core` as a peer in the `^0.5.0` range.
13
+ The package is ESM and requires `@defjs/core` as a peer in the `^0.6.0` range.
14
14
 
15
15
  ## Quick start
16
16
 
@@ -46,7 +46,7 @@ watch(
46
46
  const abort = new AbortController();
47
47
  onCleanup(() => abort.abort());
48
48
 
49
- void getUser(client({ abort: abort.signal }), { id }).then(
49
+ void getUser(client({ signal: abort.signal }), { id }).then(
50
50
  ([error, user]) => {
51
51
  if (abort.signal.aborted) return;
52
52
  if (error) {
@@ -72,13 +72,13 @@ watch(
72
72
 
73
73
  Creates a Vue plugin that provides the supplied client as `HTTP_CLIENT`.
74
74
 
75
- ### `injectClient(key?): Client`
75
+ ### `injectClient(key?): DerivableClient`
76
76
 
77
77
  Returns the nearest client for `key`, defaulting to `HTTP_CLIENT`. Call it in a valid injection context: synchronous `setup()` or `app.runWithContext()` (Vue 3.3+). Throws without an active context or a client for the key; a missing custom key never falls back to `HTTP_CLIENT`.
78
78
 
79
79
  ### `HTTP_CLIENT`
80
80
 
81
- Public `InjectionKey<Client>` for native subtree overrides:
81
+ Public `InjectionKey<DerivableClient>` for native subtree overrides:
82
82
 
83
83
  ```ts
84
84
  provide(HTTP_CLIENT, createClient(withEndpoint("https://preview.example.com")));
@@ -98,7 +98,7 @@ app.use(createClientPlugin(client));
98
98
 
99
99
  ## Notes
100
100
 
101
- - `Client` is a function. `injectClient()` returns that same function. Pass it straight to `createClientPlugin` or `provide`. Do not pass it to `watch` or `computed` as the source: Vue calls a function source. Do not wrap it in `ref` or `reactive`; the plugin stores the function as-is.
101
+ - `injectClient()` returns the `DerivableClient` that was provided, a function. Call it with request options where the operation runs to derive a `Client` value. Pass it straight to `createClientPlugin` or `provide`. Do not pass it to `watch` or `computed` as the source: Vue calls a function source. Do not wrap it in `ref` or `reactive`; the plugin stores it as-is. A derived `Client` value is not accepted.
102
102
  - Create request-specific clients (SSR data with credentials, cookies, or tenant state) at the application boundary.
103
103
  - The owner that creates a client also owns its requests, SSE streams, and WebSocket sessions. App unmount does not clean them up.
104
104
  - Import `createClient`, `withEndpoint`, `withInterceptors`, and other client options from `@defjs/core`.
package/index.d.ts CHANGED
@@ -1,42 +1,42 @@
1
1
  import { InjectionKey, Plugin } from "vue";
2
- import { Client } from "@defjs/core";
2
+ import { DerivableClient } from "@defjs/core";
3
3
  /**
4
- * Vue injection key for the Defjs {@link Client} provided by {@link createClientPlugin}.
4
+ * Vue injection key for the Defjs {@link DerivableClient} provided by {@link createClientPlugin}.
5
5
  *
6
6
  * Prefer {@link injectClient} over calling `inject(HTTP_CLIENT)` directly. `inject(HTTP_CLIENT)` returns `undefined` when nothing was provided. Override a subtree with `provide(HTTP_CLIENT, childClient)`.
7
7
  *
8
8
  * @group vue
9
- * @see {@link Client}
9
+ * @see {@link DerivableClient}
10
10
  * @see {@link injectClient}
11
11
  */
12
- export declare const HTTP_CLIENT: InjectionKey<Client>;
12
+ export declare const HTTP_CLIENT: InjectionKey<DerivableClient>;
13
13
  /**
14
14
  * Create a Vue plugin that provides an existing Defjs client via {@link HTTP_CLIENT}.
15
15
  *
16
- * Does not create, cache, or dispose the client — pass the function from `createClient`. Installing it calls `app.provide(HTTP_CLIENT, client)`, so components read the client with `injectClient()`. The client is stored as that function: it is not wrapped in `ref`, `reactive`, or `markRaw`.
16
+ * Does not create, cache, or dispose the client — pass the client returned by `createClient`. Installing it calls `app.provide(HTTP_CLIENT, client)`, so components read the client with `injectClient()`. The client is stored as given: it is not wrapped in `ref`, `reactive`, or `markRaw`.
17
17
  *
18
- * @param client - The client function to provide to the app.
18
+ * @param client - The client returned by `createClient` to provide to the app.
19
19
  * @returns A Vue `Plugin` for `app.use(...)`.
20
20
  *
21
21
  * @group vue
22
- * @see {@link Client}
22
+ * @see {@link DerivableClient}
23
23
  * @exampleFile examples/api/create-client-plugin.ts#example
24
24
  */
25
- export declare function createClientPlugin(client: Client): Plugin;
25
+ export declare function createClientPlugin(client: DerivableClient): Plugin;
26
26
  /**
27
27
  * Vue composable that injects the Defjs client for a key, defaulting to {@link HTTP_CLIENT}.
28
28
  *
29
29
  * `injectClient(key)` reads the nearest provider for that key; omitted or `undefined` uses `HTTP_CLIENT`. Call in a valid Vue injection context: synchronous `setup()`, compiler-restored `<script setup>` after top-level `await`, or a synchronous `app.runWithContext()` callback (Vue 3.3+). `app.runWithContext()` supplies only synchronous app-level context, not subtree overrides or context across ordinary `await`.
30
30
  *
31
- * For a custom `InjectionKey<Client>`, use `app.provide(key, client)` or an ancestor’s `provide(key, client)`. Share the same `Symbol` object; matching descriptions do not make keys equal. `createClientPlugin(client)` still takes only the client and provides `HTTP_CLIENT`.
31
+ * For a custom `InjectionKey<DerivableClient>`, use `app.provide(key, client)` or an ancestor’s `provide(key, client)`. Share the same `Symbol` object; matching descriptions do not make keys equal. `createClientPlugin(client)` still takes only the client and provides `HTTP_CLIENT`.
32
32
  *
33
- * It returns the exact client function provided for the selected key, and throws an `Error` without an active injection context or a client for the selected key. Installing the plugin alone does not establish an injection context.
33
+ * It returns the exact client value provided for the selected key, and throws an `Error` without an active injection context or a client for the selected key. Installing the plugin alone does not establish an injection context.
34
34
  *
35
- * `Client` is callable. Pass it to `provide` as-is. Do not pass it to `watch` or `computed` as the source: Vue calls a function source. Do not wrap it in `ref` or `reactive`.
35
+ * The injected `DerivableClient` is a function. Call it with request options at the call site to derive a `Client` value for one call: `getUser(client({ signal }), input)`. Do not pass it to `watch` or `computed` as the source: Vue calls a function source. Do not wrap it in `ref` or `reactive`. The provider holds only a root client; a derived `Client` value is not accepted, so create it where the operation is called.
36
36
  *
37
37
  * @param key - Injection key; use the same object with `app.provide` or `provide`.
38
38
  * Defaults to `HTTP_CLIENT`, as provided by {@link createClientPlugin}.
39
- * @returns The injected client function.
39
+ * @returns The injected derivable client.
40
40
  * @throws If called outside a Vue injection context or no client was provided for
41
41
  * the requested key. A missing custom key does not fall back to `HTTP_CLIENT`.
42
42
  *
@@ -45,6 +45,6 @@ export declare function createClientPlugin(client: Client): Plugin;
45
45
  * const client = injectClient()
46
46
  * ```
47
47
  * @group vue
48
- * @see {@link Client}
48
+ * @see {@link DerivableClient}
49
49
  */
50
- export declare function injectClient(key?: InjectionKey<Client>): Client;
50
+ export declare function injectClient(key?: InjectionKey<DerivableClient>): DerivableClient;
package/index.js CHANGED
@@ -1,25 +1,25 @@
1
1
  import { inject } from "vue";
2
2
  // src/core.ts
3
3
  /**
4
- * Vue injection key for the Defjs {@link Client} provided by {@link createClientPlugin}.
4
+ * Vue injection key for the Defjs {@link DerivableClient} provided by {@link createClientPlugin}.
5
5
  *
6
6
  * Prefer {@link injectClient} over calling `inject(HTTP_CLIENT)` directly. `inject(HTTP_CLIENT)` returns `undefined` when nothing was provided. Override a subtree with `provide(HTTP_CLIENT, childClient)`.
7
7
  *
8
8
  * @group vue
9
- * @see {@link Client}
9
+ * @see {@link DerivableClient}
10
10
  * @see {@link injectClient}
11
11
  */
12
12
  const HTTP_CLIENT = Symbol("HTTP_CLIENT");
13
13
  /**
14
14
  * Create a Vue plugin that provides an existing Defjs client via {@link HTTP_CLIENT}.
15
15
  *
16
- * Does not create, cache, or dispose the client — pass the function from `createClient`. Installing it calls `app.provide(HTTP_CLIENT, client)`, so components read the client with `injectClient()`. The client is stored as that function: it is not wrapped in `ref`, `reactive`, or `markRaw`.
16
+ * Does not create, cache, or dispose the client — pass the client returned by `createClient`. Installing it calls `app.provide(HTTP_CLIENT, client)`, so components read the client with `injectClient()`. The client is stored as given: it is not wrapped in `ref`, `reactive`, or `markRaw`.
17
17
  *
18
- * @param client - The client function to provide to the app.
18
+ * @param client - The client returned by `createClient` to provide to the app.
19
19
  * @returns A Vue `Plugin` for `app.use(...)`.
20
20
  *
21
21
  * @group vue
22
- * @see {@link Client}
22
+ * @see {@link DerivableClient}
23
23
  * @exampleFile examples/api/create-client-plugin.ts#example
24
24
  */
25
25
  function createClientPlugin(client) {
@@ -32,15 +32,15 @@ function createClientPlugin(client) {
32
32
  *
33
33
  * `injectClient(key)` reads the nearest provider for that key; omitted or `undefined` uses `HTTP_CLIENT`. Call in a valid Vue injection context: synchronous `setup()`, compiler-restored `<script setup>` after top-level `await`, or a synchronous `app.runWithContext()` callback (Vue 3.3+). `app.runWithContext()` supplies only synchronous app-level context, not subtree overrides or context across ordinary `await`.
34
34
  *
35
- * For a custom `InjectionKey<Client>`, use `app.provide(key, client)` or an ancestor’s `provide(key, client)`. Share the same `Symbol` object; matching descriptions do not make keys equal. `createClientPlugin(client)` still takes only the client and provides `HTTP_CLIENT`.
35
+ * For a custom `InjectionKey<DerivableClient>`, use `app.provide(key, client)` or an ancestor’s `provide(key, client)`. Share the same `Symbol` object; matching descriptions do not make keys equal. `createClientPlugin(client)` still takes only the client and provides `HTTP_CLIENT`.
36
36
  *
37
- * It returns the exact client function provided for the selected key, and throws an `Error` without an active injection context or a client for the selected key. Installing the plugin alone does not establish an injection context.
37
+ * It returns the exact client value provided for the selected key, and throws an `Error` without an active injection context or a client for the selected key. Installing the plugin alone does not establish an injection context.
38
38
  *
39
- * `Client` is callable. Pass it to `provide` as-is. Do not pass it to `watch` or `computed` as the source: Vue calls a function source. Do not wrap it in `ref` or `reactive`.
39
+ * The injected `DerivableClient` is a function. Call it with request options at the call site to derive a `Client` value for one call: `getUser(client({ signal }), input)`. Do not pass it to `watch` or `computed` as the source: Vue calls a function source. Do not wrap it in `ref` or `reactive`. The provider holds only a root client; a derived `Client` value is not accepted, so create it where the operation is called.
40
40
  *
41
41
  * @param key - Injection key; use the same object with `app.provide` or `provide`.
42
42
  * Defaults to `HTTP_CLIENT`, as provided by {@link createClientPlugin}.
43
- * @returns The injected client function.
43
+ * @returns The injected derivable client.
44
44
  * @throws If called outside a Vue injection context or no client was provided for
45
45
  * the requested key. A missing custom key does not fall back to `HTTP_CLIENT`.
46
46
  *
@@ -49,7 +49,7 @@ function createClientPlugin(client) {
49
49
  * const client = injectClient()
50
50
  * ```
51
51
  * @group vue
52
- * @see {@link Client}
52
+ * @see {@link DerivableClient}
53
53
  */
54
54
  function injectClient(key = HTTP_CLIENT) {
55
55
  const client = inject(key);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defjs/vue",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Provide an existing Defjs client to a Vue application.",
5
5
  "bugs": {
6
6
  "url": "https://github.com/defjs/defjs/issues"
@@ -14,7 +14,7 @@
14
14
  "main": "./index.js",
15
15
  "types": "./index.d.ts",
16
16
  "peerDependencies": {
17
- "@defjs/core": "^0.5.0",
17
+ "@defjs/core": "^0.6.0",
18
18
  "vue": ">=3.0.0"
19
19
  },
20
20
  "module": "./index.js",