@yassidev/nuxt-directus 0.0.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/README.md +84 -0
- package/dist/module.d.mts +575 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +290 -0
- package/dist/runtime/composables/graphql.d.ts +4 -0
- package/dist/runtime/composables/graphql.js +5 -0
- package/dist/runtime/composables/rest.d.ts +4 -0
- package/dist/runtime/composables/rest.js +5 -0
- package/dist/runtime/helpers.d.ts +11 -0
- package/dist/runtime/helpers.js +40 -0
- package/dist/runtime/lang/index.d.ts +5 -0
- package/dist/runtime/lang/index.js +5 -0
- package/dist/types.d.mts +7 -0
- package/package.json +62 -0
package/README.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Get your module up and running quickly.
|
|
3
|
+
|
|
4
|
+
Find and replace all on all files (CMD+SHIFT+F):
|
|
5
|
+
- Name: My Module
|
|
6
|
+
- Package name: my-module
|
|
7
|
+
- Description: My new Nuxt module
|
|
8
|
+
-->
|
|
9
|
+
|
|
10
|
+
# My Module
|
|
11
|
+
|
|
12
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
13
|
+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
14
|
+
[![License][license-src]][license-href]
|
|
15
|
+
[![Nuxt][nuxt-src]][nuxt-href]
|
|
16
|
+
|
|
17
|
+
My new Nuxt module for doing amazing things.
|
|
18
|
+
|
|
19
|
+
- [✨ Release Notes](/CHANGELOG.md)
|
|
20
|
+
<!-- - [🏀 Online playground](https://stackblitz.com/github/your-org/my-module?file=playground%2Fapp.vue) -->
|
|
21
|
+
<!-- - [📖 Documentation](https://example.com) -->
|
|
22
|
+
|
|
23
|
+
## Features
|
|
24
|
+
|
|
25
|
+
<!-- Highlight some of the features your module provide here -->
|
|
26
|
+
- ⛰ Foo
|
|
27
|
+
- 🚠 Bar
|
|
28
|
+
- 🌲 Baz
|
|
29
|
+
|
|
30
|
+
## Quick Setup
|
|
31
|
+
|
|
32
|
+
Install the module to your Nuxt application with one command:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npx nuxi module add my-module
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
That's it! You can now use My Module in your Nuxt app ✨
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
## Contribution
|
|
42
|
+
|
|
43
|
+
<details>
|
|
44
|
+
<summary>Local development</summary>
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# Install dependencies
|
|
48
|
+
npm install
|
|
49
|
+
|
|
50
|
+
# Generate type stubs
|
|
51
|
+
npm run dev:prepare
|
|
52
|
+
|
|
53
|
+
# Develop with the playground
|
|
54
|
+
npm run dev
|
|
55
|
+
|
|
56
|
+
# Build the playground
|
|
57
|
+
npm run dev:build
|
|
58
|
+
|
|
59
|
+
# Run ESLint
|
|
60
|
+
npm run lint
|
|
61
|
+
|
|
62
|
+
# Run Vitest
|
|
63
|
+
npm run test
|
|
64
|
+
npm run test:watch
|
|
65
|
+
|
|
66
|
+
# Release new version
|
|
67
|
+
npm run release
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
</details>
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
<!-- Badges -->
|
|
74
|
+
[npm-version-src]: https://img.shields.io/npm/v/my-module/latest.svg?style=flat&colorA=020420&colorB=00DC82
|
|
75
|
+
[npm-version-href]: https://npmjs.com/package/my-module
|
|
76
|
+
|
|
77
|
+
[npm-downloads-src]: https://img.shields.io/npm/dm/my-module.svg?style=flat&colorA=020420&colorB=00DC82
|
|
78
|
+
[npm-downloads-href]: https://npm.chart.dev/my-module
|
|
79
|
+
|
|
80
|
+
[license-src]: https://img.shields.io/npm/l/my-module.svg?style=flat&colorA=020420&colorB=00DC82
|
|
81
|
+
[license-href]: https://npmjs.com/package/my-module
|
|
82
|
+
|
|
83
|
+
[nuxt-src]: https://img.shields.io/badge/Nuxt-020420?logo=nuxt.js
|
|
84
|
+
[nuxt-href]: https://nuxt.com
|
|
@@ -0,0 +1,575 @@
|
|
|
1
|
+
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
+
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
3
|
+
|
|
4
|
+
type QueryValue = string | number | undefined | null | boolean | Array<QueryValue> | Record<string, any>;
|
|
5
|
+
type QueryObject = Record<string, QueryValue | QueryValue[]>;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A CloseEvent is sent to clients using WebSockets when the connection is closed. This is delivered to the listener indicated by the WebSocket object's onclose attribute.
|
|
9
|
+
*
|
|
10
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CloseEvent)
|
|
11
|
+
*/
|
|
12
|
+
interface CloseEvent extends Event {
|
|
13
|
+
/**
|
|
14
|
+
* Returns the WebSocket connection close code provided by the server.
|
|
15
|
+
*
|
|
16
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CloseEvent/code)
|
|
17
|
+
*/
|
|
18
|
+
readonly code: number;
|
|
19
|
+
/**
|
|
20
|
+
* Returns the WebSocket connection close reason provided by the server.
|
|
21
|
+
*
|
|
22
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CloseEvent/reason)
|
|
23
|
+
*/
|
|
24
|
+
readonly reason: string;
|
|
25
|
+
/**
|
|
26
|
+
* Returns true if the connection closed cleanly; false otherwise.
|
|
27
|
+
*
|
|
28
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CloseEvent/wasClean)
|
|
29
|
+
*/
|
|
30
|
+
readonly wasClean: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* An event which takes place in the DOM.
|
|
34
|
+
*
|
|
35
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event)
|
|
36
|
+
*/
|
|
37
|
+
interface Event {
|
|
38
|
+
/**
|
|
39
|
+
* Returns true or false depending on how event was initialized. True if event goes through its target's ancestors in reverse tree order, and false otherwise.
|
|
40
|
+
*
|
|
41
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/bubbles)
|
|
42
|
+
*/
|
|
43
|
+
readonly bubbles: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* @deprecated
|
|
46
|
+
*
|
|
47
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/cancelBubble)
|
|
48
|
+
*/
|
|
49
|
+
cancelBubble: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Returns true or false depending on how event was initialized. Its return value does not always carry meaning, but true can indicate that part of the operation during which event was dispatched, can be canceled by invoking the preventDefault() method.
|
|
52
|
+
*
|
|
53
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/cancelable)
|
|
54
|
+
*/
|
|
55
|
+
readonly cancelable: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Returns true or false depending on how event was initialized. True if event invokes listeners past a ShadowRoot node that is the root of its target, and false otherwise.
|
|
58
|
+
*
|
|
59
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/composed)
|
|
60
|
+
*/
|
|
61
|
+
readonly composed: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Returns the object whose event listener's callback is currently being invoked.
|
|
64
|
+
*
|
|
65
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/currentTarget)
|
|
66
|
+
*/
|
|
67
|
+
readonly currentTarget: EventTarget | null;
|
|
68
|
+
/**
|
|
69
|
+
* Returns true if preventDefault() was invoked successfully to indicate cancelation, and false otherwise.
|
|
70
|
+
*
|
|
71
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/defaultPrevented)
|
|
72
|
+
*/
|
|
73
|
+
readonly defaultPrevented: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Returns the event's phase, which is one of NONE, CAPTURING_PHASE, AT_TARGET, and BUBBLING_PHASE.
|
|
76
|
+
*
|
|
77
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/eventPhase)
|
|
78
|
+
*/
|
|
79
|
+
readonly eventPhase: number;
|
|
80
|
+
/**
|
|
81
|
+
* Returns true if event was dispatched by the user agent, and false otherwise.
|
|
82
|
+
*
|
|
83
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/isTrusted)
|
|
84
|
+
*/
|
|
85
|
+
readonly isTrusted: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* @deprecated
|
|
88
|
+
*
|
|
89
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/returnValue)
|
|
90
|
+
*/
|
|
91
|
+
returnValue: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* @deprecated
|
|
94
|
+
*
|
|
95
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/srcElement)
|
|
96
|
+
*/
|
|
97
|
+
readonly srcElement: EventTarget | null;
|
|
98
|
+
/**
|
|
99
|
+
* Returns the object to which event is dispatched (its target).
|
|
100
|
+
*
|
|
101
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/target)
|
|
102
|
+
*/
|
|
103
|
+
readonly target: EventTarget | null;
|
|
104
|
+
/**
|
|
105
|
+
* Returns the event's timestamp as the number of milliseconds measured relative to the time origin.
|
|
106
|
+
*
|
|
107
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/timeStamp)
|
|
108
|
+
*/
|
|
109
|
+
readonly timeStamp: DOMHighResTimeStamp;
|
|
110
|
+
/**
|
|
111
|
+
* Returns the type of event, e.g. "click", "hashchange", or "submit".
|
|
112
|
+
*
|
|
113
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/type)
|
|
114
|
+
*/
|
|
115
|
+
readonly type: string;
|
|
116
|
+
/**
|
|
117
|
+
* Returns the invocation target objects of event's path (objects on which listeners will be invoked), except for any nodes in shadow trees of which the shadow root's mode is "closed" that are not reachable from event's currentTarget.
|
|
118
|
+
*
|
|
119
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/composedPath)
|
|
120
|
+
*/
|
|
121
|
+
composedPath(): EventTarget[];
|
|
122
|
+
/**
|
|
123
|
+
* @deprecated
|
|
124
|
+
*
|
|
125
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/initEvent)
|
|
126
|
+
*/
|
|
127
|
+
initEvent(type: string, bubbles?: boolean, cancelable?: boolean): void;
|
|
128
|
+
/**
|
|
129
|
+
* If invoked when the cancelable attribute value is true, and while executing a listener for the event with passive set to false, signals to the operation that caused event to be dispatched that it needs to be canceled.
|
|
130
|
+
*
|
|
131
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/preventDefault)
|
|
132
|
+
*/
|
|
133
|
+
preventDefault(): void;
|
|
134
|
+
/**
|
|
135
|
+
* Invoking this method prevents event from reaching any registered event listeners after the current one finishes running and, when dispatched in a tree, also prevents event from reaching any other objects.
|
|
136
|
+
*
|
|
137
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/stopImmediatePropagation)
|
|
138
|
+
*/
|
|
139
|
+
stopImmediatePropagation(): void;
|
|
140
|
+
/**
|
|
141
|
+
* When dispatched in a tree, invoking this method prevents event from reaching any objects other than the current object.
|
|
142
|
+
*
|
|
143
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/stopPropagation)
|
|
144
|
+
*/
|
|
145
|
+
stopPropagation(): void;
|
|
146
|
+
readonly NONE: 0;
|
|
147
|
+
readonly CAPTURING_PHASE: 1;
|
|
148
|
+
readonly AT_TARGET: 2;
|
|
149
|
+
readonly BUBBLING_PHASE: 3;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* EventTarget is a DOM interface implemented by objects that can receive events and may have listeners for them.
|
|
153
|
+
*
|
|
154
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget)
|
|
155
|
+
*/
|
|
156
|
+
interface EventTarget {
|
|
157
|
+
/**
|
|
158
|
+
* Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.
|
|
159
|
+
*
|
|
160
|
+
* The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.
|
|
161
|
+
*
|
|
162
|
+
* When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.
|
|
163
|
+
*
|
|
164
|
+
* When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.
|
|
165
|
+
*
|
|
166
|
+
* When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.
|
|
167
|
+
*
|
|
168
|
+
* If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.
|
|
169
|
+
*
|
|
170
|
+
* The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.
|
|
171
|
+
*
|
|
172
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener)
|
|
173
|
+
*/
|
|
174
|
+
addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: AddEventListenerOptions | boolean): void;
|
|
175
|
+
/**
|
|
176
|
+
* Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.
|
|
177
|
+
*
|
|
178
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/dispatchEvent)
|
|
179
|
+
*/
|
|
180
|
+
dispatchEvent(event: Event): boolean;
|
|
181
|
+
/**
|
|
182
|
+
* Removes the event listener in target's event listener list with the same type, callback, and options.
|
|
183
|
+
*
|
|
184
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/removeEventListener)
|
|
185
|
+
*/
|
|
186
|
+
removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* A message received by a target object.
|
|
190
|
+
*
|
|
191
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent)
|
|
192
|
+
*/
|
|
193
|
+
interface MessageEvent$1<T = any> extends Event {
|
|
194
|
+
/**
|
|
195
|
+
* Returns the data of the message.
|
|
196
|
+
*
|
|
197
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent/data)
|
|
198
|
+
*/
|
|
199
|
+
readonly data: T;
|
|
200
|
+
/**
|
|
201
|
+
* Returns the last event ID string, for server-sent events.
|
|
202
|
+
*
|
|
203
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent/lastEventId)
|
|
204
|
+
*/
|
|
205
|
+
readonly lastEventId: string;
|
|
206
|
+
/**
|
|
207
|
+
* Returns the origin of the message, for server-sent events and cross-document messaging.
|
|
208
|
+
*
|
|
209
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent/origin)
|
|
210
|
+
*/
|
|
211
|
+
readonly origin: string;
|
|
212
|
+
/**
|
|
213
|
+
* Returns the MessagePort array sent with the message, for cross-document messaging and channel messaging.
|
|
214
|
+
*
|
|
215
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent/ports)
|
|
216
|
+
*/
|
|
217
|
+
readonly ports: ReadonlyArray<MessagePort>;
|
|
218
|
+
/**
|
|
219
|
+
* Returns the WindowProxy of the source window, for cross-document messaging, and the MessagePort being attached, in the connect event fired at SharedWorkerGlobalScope objects.
|
|
220
|
+
*
|
|
221
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent/source)
|
|
222
|
+
*/
|
|
223
|
+
readonly source: MessageEventSource | null;
|
|
224
|
+
/** @deprecated */
|
|
225
|
+
initMessageEvent(type: string, bubbles?: boolean, cancelable?: boolean, data?: any, origin?: string, lastEventId?: string, source?: MessageEventSource | null, ports?: MessagePort[]): void;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Provides the API for creating and managing a WebSocket connection to a server, as well as for sending and receiving data on the connection.
|
|
229
|
+
*
|
|
230
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket)
|
|
231
|
+
*/
|
|
232
|
+
interface WebSocket extends EventTarget {
|
|
233
|
+
/**
|
|
234
|
+
* Returns a string that indicates how binary data from the WebSocket object is exposed to scripts:
|
|
235
|
+
*
|
|
236
|
+
* Can be set, to change how binary data is returned. The default is "blob".
|
|
237
|
+
*
|
|
238
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/binaryType)
|
|
239
|
+
*/
|
|
240
|
+
binaryType: BinaryType | (string & {});
|
|
241
|
+
/**
|
|
242
|
+
* Returns the number of bytes of application data (UTF-8 text and binary data) that have been queued using send() but not yet been transmitted to the network.
|
|
243
|
+
*
|
|
244
|
+
* If the WebSocket connection is closed, this attribute's value will only increase with each call to the send() method. (The number does not reset to zero once the connection closes.)
|
|
245
|
+
*
|
|
246
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/bufferedAmount)
|
|
247
|
+
*/
|
|
248
|
+
readonly bufferedAmount: number;
|
|
249
|
+
/**
|
|
250
|
+
* Returns the extensions selected by the server, if any.
|
|
251
|
+
*
|
|
252
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/extensions)
|
|
253
|
+
*/
|
|
254
|
+
readonly extensions: string;
|
|
255
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/close_event) */
|
|
256
|
+
onclose: ((this: WebSocket, ev: CloseEvent) => any) | null;
|
|
257
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/error_event) */
|
|
258
|
+
onerror: ((this: WebSocket, ev: Event) => any) | null;
|
|
259
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/message_event) */
|
|
260
|
+
onmessage: ((this: WebSocket, ev: MessageEvent$1) => any) | null;
|
|
261
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/open_event) */
|
|
262
|
+
onopen: ((this: WebSocket, ev: Event) => any) | null;
|
|
263
|
+
/**
|
|
264
|
+
* Returns the subprotocol selected by the server, if any. It can be used in conjunction with the array form of the constructor's second argument to perform subprotocol negotiation.
|
|
265
|
+
*
|
|
266
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/protocol)
|
|
267
|
+
*/
|
|
268
|
+
readonly protocol: string;
|
|
269
|
+
/**
|
|
270
|
+
* Returns the state of the WebSocket object's connection. It can have the values described below.
|
|
271
|
+
*
|
|
272
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/readyState)
|
|
273
|
+
*/
|
|
274
|
+
readonly readyState: number;
|
|
275
|
+
/**
|
|
276
|
+
* Returns the URL that was used to establish the WebSocket connection.
|
|
277
|
+
*
|
|
278
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/url)
|
|
279
|
+
*/
|
|
280
|
+
readonly url: string;
|
|
281
|
+
/**
|
|
282
|
+
* Closes the WebSocket connection, optionally using code as the the WebSocket connection close code and reason as the the WebSocket connection close reason.
|
|
283
|
+
*
|
|
284
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/close)
|
|
285
|
+
*/
|
|
286
|
+
close(code?: number, reason?: string): void;
|
|
287
|
+
/**
|
|
288
|
+
* Transmits data using the WebSocket connection. data can be a string, a Blob, an ArrayBuffer, or an ArrayBufferView.
|
|
289
|
+
*
|
|
290
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/send)
|
|
291
|
+
*/
|
|
292
|
+
send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void;
|
|
293
|
+
readonly CONNECTING: 0;
|
|
294
|
+
readonly OPEN: 1;
|
|
295
|
+
readonly CLOSING: 2;
|
|
296
|
+
readonly CLOSED: 3;
|
|
297
|
+
addEventListener<K extends keyof WebSocketEventMap>(type: K, listener: (this: WebSocket, ev: WebSocketEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
|
|
298
|
+
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
|
299
|
+
removeEventListener<K extends keyof WebSocketEventMap>(type: K, listener: (this: WebSocket, ev: WebSocketEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
|
|
300
|
+
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
declare const kNodeInspect: unique symbol;
|
|
304
|
+
|
|
305
|
+
interface AdapterInternal {
|
|
306
|
+
ws: unknown;
|
|
307
|
+
request: UpgradeRequest;
|
|
308
|
+
peers?: Set<Peer>;
|
|
309
|
+
context?: Peer["context"];
|
|
310
|
+
}
|
|
311
|
+
declare abstract class Peer<Internal extends AdapterInternal = AdapterInternal> {
|
|
312
|
+
#private;
|
|
313
|
+
protected _internal: Internal;
|
|
314
|
+
protected _topics: Set<string>;
|
|
315
|
+
protected _id?: string;
|
|
316
|
+
constructor(internal: Internal);
|
|
317
|
+
get context(): Record<string, unknown>;
|
|
318
|
+
/**
|
|
319
|
+
* Unique random [uuid v4](https://developer.mozilla.org/en-US/docs/Glossary/UUID) identifier for the peer.
|
|
320
|
+
*/
|
|
321
|
+
get id(): string;
|
|
322
|
+
/** IP address of the peer */
|
|
323
|
+
get remoteAddress(): string | undefined;
|
|
324
|
+
/** upgrade request */
|
|
325
|
+
get request(): UpgradeRequest;
|
|
326
|
+
/**
|
|
327
|
+
* Get the [WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) instance.
|
|
328
|
+
*
|
|
329
|
+
* **Note:** crossws adds polyfill for the following properties if native values are not available:
|
|
330
|
+
* - `protocol`: Extracted from the `sec-websocket-protocol` header.
|
|
331
|
+
* - `extensions`: Extracted from the `sec-websocket-extensions` header.
|
|
332
|
+
* - `url`: Extracted from the request URL (http -> ws).
|
|
333
|
+
* */
|
|
334
|
+
get websocket(): Partial<WebSocket>;
|
|
335
|
+
/** All connected peers to the server */
|
|
336
|
+
get peers(): Set<Peer>;
|
|
337
|
+
/** All topics, this peer has been subscribed to. */
|
|
338
|
+
get topics(): Set<string>;
|
|
339
|
+
abstract close(code?: number, reason?: string): void;
|
|
340
|
+
/** Abruptly close the connection */
|
|
341
|
+
terminate(): void;
|
|
342
|
+
/** Subscribe to a topic */
|
|
343
|
+
subscribe(topic: string): void;
|
|
344
|
+
/** Unsubscribe from a topic */
|
|
345
|
+
unsubscribe(topic: string): void;
|
|
346
|
+
/** Send a message to the peer. */
|
|
347
|
+
abstract send(data: unknown, options?: {
|
|
348
|
+
compress?: boolean;
|
|
349
|
+
}): number | void | undefined;
|
|
350
|
+
/** Send message to subscribes of topic */
|
|
351
|
+
abstract publish(topic: string, data: unknown, options?: {
|
|
352
|
+
compress?: boolean;
|
|
353
|
+
}): void;
|
|
354
|
+
toString(): string;
|
|
355
|
+
[Symbol.toPrimitive](): string;
|
|
356
|
+
[Symbol.toStringTag](): "WebSocket";
|
|
357
|
+
[kNodeInspect](): Record<string, unknown>;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
declare class WSError extends Error {
|
|
361
|
+
constructor(...args: any[]);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
declare class Message implements Partial<MessageEvent> {
|
|
365
|
+
#private;
|
|
366
|
+
/** Access to the original [message event](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/message_event) if available. */
|
|
367
|
+
readonly event?: MessageEvent;
|
|
368
|
+
/** Access to the Peer that emitted the message. */
|
|
369
|
+
readonly peer?: Peer;
|
|
370
|
+
/** Raw message data (can be of any type). */
|
|
371
|
+
readonly rawData: unknown;
|
|
372
|
+
constructor(rawData: unknown, peer: Peer, event?: MessageEvent);
|
|
373
|
+
/**
|
|
374
|
+
* Unique random [uuid v4](https://developer.mozilla.org/en-US/docs/Glossary/UUID) identifier for the message.
|
|
375
|
+
*/
|
|
376
|
+
get id(): string;
|
|
377
|
+
/**
|
|
378
|
+
* Get data as [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) value.
|
|
379
|
+
*
|
|
380
|
+
* If raw data is in any other format or string, it will be automatically converted and encoded.
|
|
381
|
+
*/
|
|
382
|
+
uint8Array(): Uint8Array;
|
|
383
|
+
/**
|
|
384
|
+
* Get data as [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) or [SharedArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) value.
|
|
385
|
+
*
|
|
386
|
+
* If raw data is in any other format or string, it will be automatically converted and encoded.
|
|
387
|
+
*/
|
|
388
|
+
arrayBuffer(): ArrayBuffer | SharedArrayBuffer;
|
|
389
|
+
/**
|
|
390
|
+
* Get data as [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) value.
|
|
391
|
+
*
|
|
392
|
+
* If raw data is in any other format or string, it will be automatically converted and encoded. */
|
|
393
|
+
blob(): Blob;
|
|
394
|
+
/**
|
|
395
|
+
* Get stringified text version of the message.
|
|
396
|
+
*
|
|
397
|
+
* If raw data is in any other format, it will be automatically converted and decoded.
|
|
398
|
+
*/
|
|
399
|
+
text(): string;
|
|
400
|
+
/**
|
|
401
|
+
* Get parsed version of the message text with [`JSON.parse()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse).
|
|
402
|
+
*/
|
|
403
|
+
json<T = unknown>(): T;
|
|
404
|
+
/**
|
|
405
|
+
* Message data (value varies based on `peer.websocket.binaryType`).
|
|
406
|
+
*/
|
|
407
|
+
get data(): unknown;
|
|
408
|
+
toString(): string;
|
|
409
|
+
[Symbol.toPrimitive](): string;
|
|
410
|
+
[kNodeInspect](): {
|
|
411
|
+
data: unknown;
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
type MaybePromise$1<T> = T | Promise<T>;
|
|
415
|
+
type UpgradeRequest = Request | {
|
|
416
|
+
url: string;
|
|
417
|
+
headers: Headers;
|
|
418
|
+
};
|
|
419
|
+
interface Hooks {
|
|
420
|
+
/** Upgrading */
|
|
421
|
+
/**
|
|
422
|
+
*
|
|
423
|
+
* @param request
|
|
424
|
+
* @throws {Response}
|
|
425
|
+
*/
|
|
426
|
+
upgrade: (request: UpgradeRequest & {
|
|
427
|
+
context: Peer["context"];
|
|
428
|
+
}) => MaybePromise$1<Response | ResponseInit | void>;
|
|
429
|
+
/** A message is received */
|
|
430
|
+
message: (peer: Peer, message: Message) => MaybePromise$1<void>;
|
|
431
|
+
/** A socket is opened */
|
|
432
|
+
open: (peer: Peer) => MaybePromise$1<void>;
|
|
433
|
+
/** A socket is closed */
|
|
434
|
+
close: (peer: Peer, details: {
|
|
435
|
+
code?: number;
|
|
436
|
+
reason?: string;
|
|
437
|
+
}) => MaybePromise$1<void>;
|
|
438
|
+
/** An error occurs */
|
|
439
|
+
error: (peer: Peer, error: WSError) => MaybePromise$1<void>;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
interface NodeEventContext {
|
|
443
|
+
req: IncomingMessage & {
|
|
444
|
+
originalUrl?: string;
|
|
445
|
+
};
|
|
446
|
+
res: ServerResponse;
|
|
447
|
+
}
|
|
448
|
+
interface WebEventContext {
|
|
449
|
+
request?: Request;
|
|
450
|
+
url?: URL;
|
|
451
|
+
}
|
|
452
|
+
declare class H3Event<_RequestT extends EventHandlerRequest = EventHandlerRequest> implements Pick<FetchEvent, "respondWith"> {
|
|
453
|
+
"__is_event__": boolean;
|
|
454
|
+
node: NodeEventContext;
|
|
455
|
+
web?: WebEventContext;
|
|
456
|
+
context: H3EventContext;
|
|
457
|
+
_method?: HTTPMethod;
|
|
458
|
+
_path?: string;
|
|
459
|
+
_headers?: Headers;
|
|
460
|
+
_requestBody?: BodyInit;
|
|
461
|
+
_handled: boolean;
|
|
462
|
+
_onBeforeResponseCalled: boolean | undefined;
|
|
463
|
+
_onAfterResponseCalled: boolean | undefined;
|
|
464
|
+
constructor(req: IncomingMessage, res: ServerResponse);
|
|
465
|
+
get method(): HTTPMethod;
|
|
466
|
+
get path(): string;
|
|
467
|
+
get headers(): Headers;
|
|
468
|
+
get handled(): boolean;
|
|
469
|
+
respondWith(response: Response | PromiseLike<Response>): Promise<void>;
|
|
470
|
+
toString(): string;
|
|
471
|
+
toJSON(): string;
|
|
472
|
+
/** @deprecated Please use `event.node.req` instead. */
|
|
473
|
+
get req(): IncomingMessage & {
|
|
474
|
+
originalUrl?: string;
|
|
475
|
+
};
|
|
476
|
+
/** @deprecated Please use `event.node.res` instead. */
|
|
477
|
+
get res(): ServerResponse<IncomingMessage>;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
type SessionDataT = Record<string, any>;
|
|
481
|
+
type SessionData<T extends SessionDataT = SessionDataT> = T;
|
|
482
|
+
declare const getSessionPromise: unique symbol;
|
|
483
|
+
interface Session<T extends SessionDataT = SessionDataT> {
|
|
484
|
+
id: string;
|
|
485
|
+
createdAt: number;
|
|
486
|
+
data: SessionData<T>;
|
|
487
|
+
[getSessionPromise]?: Promise<Session<T>>;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
type RouterMethod = Lowercase<HTTPMethod>;
|
|
491
|
+
interface RouteNode {
|
|
492
|
+
handlers: Partial<Record<RouterMethod | "all", EventHandler>>;
|
|
493
|
+
path: string;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
type RequestHeaders = Partial<Record<HTTPHeaderName, string | undefined>>;
|
|
497
|
+
type _HTTPHeaderName = "WWW-Authenticate" | "Authorization" | "Proxy-Authenticate" | "Proxy-Authorization" | "Age" | "Cache-Control" | "Clear-Site-Data" | "Expires" | "Pragma" | "Accept-CH" | "Critical-CH" | "Sec-CH-UA" | "Sec-CH-UA-Arch" | "Sec-CH-UA-Bitness" | "Sec-CH-UA-Full-Version-List" | "Sec-CH-UA-Mobile" | "Sec-CH-UA-Model" | "Sec-CH-UA-Platform" | "Sec-CH-UA-Platform-Version" | "Sec-CH-UA-Prefers-Color-Scheme" | "Sec-CH-UA-Prefers-Reduced-Motion" | "Downlink" | "ECT" | "RTT" | "Save-Data" | "Last-Modified" | "ETag" | "If-Match" | "If-None-Match" | "If-Modified-Since" | "If-Unmodified-Since" | "Vary" | "Connection" | "Keep-Alive" | "Accept" | "Accept-Encoding" | "Accept-Language" | "Expect" | "Max-Forwards" | "Cookie" | "Set-Cookie" | "Access-Control-Allow-Origin" | "Access-Control-Allow-Credentials" | "Access-Control-Allow-Headers" | "Access-Control-Allow-Methods" | "Access-Control-Expose-Headers" | "Access-Control-Max-Age" | "Access-Control-Request-Headers" | "Access-Control-Request-Method" | "Origin" | "Timing-Allow-Origin" | "Content-Disposition" | "Content-Length" | "Content-Type" | "Content-Encoding" | "Content-Language" | "Content-Location" | "Forwarded" | "X-Forwarded-For" | "X-Forwarded-Host" | "X-Forwarded-Proto" | "Via" | "Location" | "Refresh" | "From" | "Host" | "Referer" | "Referrer-Policy" | "User-Agent" | "Allow" | "Server" | "Accept-Ranges" | "Range" | "If-Range" | "Content-Range" | "Cross-Origin-Embedder-Policy" | "Cross-Origin-Opener-Policy" | "Cross-Origin-Resource-Policy" | "Content-Security-Policy" | "Content-Security-Policy-Report-Only" | "Expect-CT" | "Origin-Isolation" | "Permissions-Policy" | "Strict-Transport-Security" | "Upgrade-Insecure-Requests" | "X-Content-Type-Options" | "X-Frame-Options" | "X-Permitted-Cross-Domain-Policies" | "X-Powered-By" | "X-XSS-Protection" | "Sec-Fetch-Site" | "Sec-Fetch-Mode" | "Sec-Fetch-User" | "Sec-Fetch-Dest" | "Sec-Purpose" | "Service-Worker-Navigation-Preload" | "Last-Event-ID" | "NEL" | "Ping-From" | "Ping-To" | "Report-To" | "Transfer-Encoding" | "TE" | "Trailer" | "Sec-WebSocket-Key" | "Sec-WebSocket-Extensions" | "Sec-WebSocket-Accept" | "Sec-WebSocket-Protocol" | "Sec-WebSocket-Version" | "Accept-Push-Policy" | "Accept-Signature" | "Alt-Svc" | "Alt-Used" | "Date" | "Early-Data" | "Link" | "Push-Policy" | "Retry-After" | "Signature" | "Signed-Headers" | "Server-Timing" | "Service-Worker-Allowed" | "SourceMap" | "Upgrade" | "X-DNS-Prefetch-Control" | "X-Pingback" | "X-Requested-With" | "X-Robots-Tag";
|
|
498
|
+
type HTTPHeaderName = _HTTPHeaderName | Lowercase<_HTTPHeaderName> | (string & {});
|
|
499
|
+
|
|
500
|
+
type HTTPMethod = "GET" | "HEAD" | "PATCH" | "POST" | "PUT" | "DELETE" | "CONNECT" | "OPTIONS" | "TRACE";
|
|
501
|
+
interface H3EventContext extends Record<string, any> {
|
|
502
|
+
params?: Record<string, string>;
|
|
503
|
+
/**
|
|
504
|
+
* Matched router Node
|
|
505
|
+
*
|
|
506
|
+
* @experimental The object structure may change in non-major version.
|
|
507
|
+
*/
|
|
508
|
+
matchedRoute?: RouteNode;
|
|
509
|
+
sessions?: Record<string, Session>;
|
|
510
|
+
clientAddress?: string;
|
|
511
|
+
}
|
|
512
|
+
type EventHandlerResponse<T = any> = T | Promise<T>;
|
|
513
|
+
interface EventHandlerRequest {
|
|
514
|
+
body?: any;
|
|
515
|
+
query?: QueryObject;
|
|
516
|
+
routerParams?: Record<string, string>;
|
|
517
|
+
}
|
|
518
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
519
|
+
type EventHandlerResolver = (path: string) => MaybePromise<undefined | {
|
|
520
|
+
route?: string;
|
|
521
|
+
handler: EventHandler;
|
|
522
|
+
}>;
|
|
523
|
+
interface EventHandler<Request extends EventHandlerRequest = EventHandlerRequest, Response extends EventHandlerResponse = EventHandlerResponse> {
|
|
524
|
+
__is_handler__?: true;
|
|
525
|
+
__resolve__?: EventHandlerResolver;
|
|
526
|
+
__websocket__?: Partial<Hooks>;
|
|
527
|
+
(event: H3Event<Request>): Response;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
type Duplex = "half" | "full";
|
|
531
|
+
interface ProxyOptions {
|
|
532
|
+
headers?: RequestHeaders | HeadersInit;
|
|
533
|
+
fetchOptions?: RequestInit & {
|
|
534
|
+
duplex?: Duplex;
|
|
535
|
+
} & {
|
|
536
|
+
ignoreResponseError?: boolean;
|
|
537
|
+
};
|
|
538
|
+
fetch?: typeof fetch;
|
|
539
|
+
sendStream?: boolean;
|
|
540
|
+
streamRequest?: boolean;
|
|
541
|
+
cookieDomainRewrite?: string | Record<string, string>;
|
|
542
|
+
cookiePathRewrite?: string | Record<string, string>;
|
|
543
|
+
onResponse?: (event: H3Event, response: Response) => void;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
interface ModuleOptions {
|
|
547
|
+
url?: string;
|
|
548
|
+
accessToken?: string;
|
|
549
|
+
composables?: false | {
|
|
550
|
+
enabled?: boolean;
|
|
551
|
+
mode?: 'graphql' | 'rest';
|
|
552
|
+
client?: boolean;
|
|
553
|
+
server?: boolean;
|
|
554
|
+
};
|
|
555
|
+
i18n?: false | {
|
|
556
|
+
enabled?: boolean;
|
|
557
|
+
sync?: boolean;
|
|
558
|
+
prefix?: string;
|
|
559
|
+
};
|
|
560
|
+
types?: false | {
|
|
561
|
+
enabled?: boolean;
|
|
562
|
+
};
|
|
563
|
+
proxy?: false | {
|
|
564
|
+
enabled?: boolean;
|
|
565
|
+
path?: string;
|
|
566
|
+
options?: ProxyOptions;
|
|
567
|
+
};
|
|
568
|
+
image?: false | {
|
|
569
|
+
enabled?: boolean;
|
|
570
|
+
alias?: string;
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
574
|
+
|
|
575
|
+
export { _default as default };
|
package/dist/module.json
ADDED
package/dist/module.mjs
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { defineNuxtModule, useLogger, updateRuntimeConfig, hasNuxtModule, createResolver, addImports, addServerImports, addTemplate, addTypeTemplate } from 'nuxt/kit';
|
|
2
|
+
import { generateDirectusTypes } from 'directus-sdk-typegen';
|
|
3
|
+
import { readTranslations, updateTranslationsBatch, createTranslations, deleteTranslations, createDirectus, rest, staticToken } from '@directus/sdk';
|
|
4
|
+
import { readFileSync } from 'node:fs';
|
|
5
|
+
|
|
6
|
+
const NAME = "directus";
|
|
7
|
+
|
|
8
|
+
const JOIN_LEADING_SLASH_RE = /^\.?\//;
|
|
9
|
+
function hasTrailingSlash(input = "", respectQueryAndFragment) {
|
|
10
|
+
{
|
|
11
|
+
return input.endsWith("/");
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function withoutTrailingSlash(input = "", respectQueryAndFragment) {
|
|
15
|
+
{
|
|
16
|
+
return (hasTrailingSlash(input) ? input.slice(0, -1) : input) || "/";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function withTrailingSlash(input = "", respectQueryAndFragment) {
|
|
20
|
+
{
|
|
21
|
+
return input.endsWith("/") ? input : input + "/";
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function isNonEmptyURL(url) {
|
|
25
|
+
return url && url !== "/";
|
|
26
|
+
}
|
|
27
|
+
function joinURL(base, ...input) {
|
|
28
|
+
let url = base || "";
|
|
29
|
+
for (const segment of input.filter((url2) => isNonEmptyURL(url2))) {
|
|
30
|
+
if (url) {
|
|
31
|
+
const _segment = segment.replace(JOIN_LEADING_SLASH_RE, "");
|
|
32
|
+
url = withTrailingSlash(url) + _segment;
|
|
33
|
+
} else {
|
|
34
|
+
url = segment;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return url;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function isPlainObject(value) {
|
|
41
|
+
if (value === null || typeof value !== "object") {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
const prototype = Object.getPrototypeOf(value);
|
|
45
|
+
if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
if (Symbol.iterator in value) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
if (Symbol.toStringTag in value) {
|
|
52
|
+
return Object.prototype.toString.call(value) === "[object Module]";
|
|
53
|
+
}
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
58
|
+
if (!isPlainObject(defaults)) {
|
|
59
|
+
return _defu(baseObject, {}, namespace, merger);
|
|
60
|
+
}
|
|
61
|
+
const object = Object.assign({}, defaults);
|
|
62
|
+
for (const key in baseObject) {
|
|
63
|
+
if (key === "__proto__" || key === "constructor") {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const value = baseObject[key];
|
|
67
|
+
if (value === null || value === void 0) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (merger && merger(object, key, value, namespace)) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (Array.isArray(value) && Array.isArray(object[key])) {
|
|
74
|
+
object[key] = [...value, ...object[key]];
|
|
75
|
+
} else if (isPlainObject(value) && isPlainObject(object[key])) {
|
|
76
|
+
object[key] = _defu(
|
|
77
|
+
value,
|
|
78
|
+
object[key],
|
|
79
|
+
(namespace ? `${namespace}.` : "") + key.toString(),
|
|
80
|
+
merger
|
|
81
|
+
);
|
|
82
|
+
} else {
|
|
83
|
+
object[key] = value;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return object;
|
|
87
|
+
}
|
|
88
|
+
function createDefu(merger) {
|
|
89
|
+
return (...arguments_) => (
|
|
90
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
91
|
+
arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
const defu = createDefu();
|
|
95
|
+
|
|
96
|
+
function useDirectus(config) {
|
|
97
|
+
return createDirectus(config.url).with(rest()).with(staticToken(config.accessToken || ""));
|
|
98
|
+
}
|
|
99
|
+
async function fetchTranslations(locale, config) {
|
|
100
|
+
const { i18nPrefix } = config;
|
|
101
|
+
const directus = useDirectus(config);
|
|
102
|
+
return await directus.request(readTranslations({
|
|
103
|
+
fields: ["key", "value", "id"],
|
|
104
|
+
limit: -1,
|
|
105
|
+
filter: { language: { _eq: locale }, ...i18nPrefix ? { key: { _startsWith: i18nPrefix } } : {} }
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
async function syncTranslations(locale, translations, config) {
|
|
109
|
+
const directus = useDirectus(config);
|
|
110
|
+
const current = await fetchTranslations(locale, config);
|
|
111
|
+
const payload = {
|
|
112
|
+
create: [],
|
|
113
|
+
update: [],
|
|
114
|
+
remove: []
|
|
115
|
+
};
|
|
116
|
+
for (const [key, value] of Object.entries(translations)) {
|
|
117
|
+
const translation = current.find((t) => t.key === key);
|
|
118
|
+
if (!translation) {
|
|
119
|
+
payload.create.push({ key, value, language: locale });
|
|
120
|
+
} else if (translation.value !== value) {
|
|
121
|
+
payload.update.push({ id: translation.id, value });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
for (const translation of current) {
|
|
125
|
+
if (!translations[translation.key]) {
|
|
126
|
+
payload.remove.push(translation.id);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (!payload.create.length && !payload.update.length && !payload.remove.length) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
return Promise.all([
|
|
133
|
+
payload.update.length > 0 ? directus.request(updateTranslationsBatch(payload.update)) : null,
|
|
134
|
+
payload.create.length > 0 ? directus.request(createTranslations(payload.create)) : null,
|
|
135
|
+
payload.remove.length > 0 ? directus.request(deleteTranslations(payload.remove)) : null
|
|
136
|
+
]);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const module = defineNuxtModule({
|
|
140
|
+
meta: { name: NAME },
|
|
141
|
+
setup(options, nuxt) {
|
|
142
|
+
const logger = useLogger(NAME);
|
|
143
|
+
const config = normalizeConfig(options);
|
|
144
|
+
if (!config.accessToken || !config.url) {
|
|
145
|
+
logger.error(`Please provide both 'url' and 'accessToken' options.`);
|
|
146
|
+
}
|
|
147
|
+
nuxt.options.typescript.hoist ??= [];
|
|
148
|
+
nuxt.options.typescript.hoist.push("@directus/sdk");
|
|
149
|
+
updateRuntimeConfig({
|
|
150
|
+
[NAME]: {
|
|
151
|
+
url: config.url,
|
|
152
|
+
accessToken: config.accessToken,
|
|
153
|
+
i18nPrefix: config.i18n.prefix
|
|
154
|
+
},
|
|
155
|
+
public: {
|
|
156
|
+
[NAME]: {
|
|
157
|
+
url: config.proxy.enabled ? config.proxy.path : config.composables.client ? config.url : void 0,
|
|
158
|
+
i18nPrefix: config.i18n.prefix
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
if (config.types.enabled) {
|
|
163
|
+
setupTypes(config, nuxt, logger);
|
|
164
|
+
}
|
|
165
|
+
if (config.composables.enabled) {
|
|
166
|
+
setupComposables(config, nuxt, logger);
|
|
167
|
+
}
|
|
168
|
+
if (config.i18n.enabled) {
|
|
169
|
+
if (!hasNuxtModule("@nuxtjs/i18n")) return logger.error("@nuxtjs/i18n is not installed! Please install it to use the i18n features of this module.");
|
|
170
|
+
setupI18n(config, nuxt, logger);
|
|
171
|
+
}
|
|
172
|
+
if (config.proxy.enabled) {
|
|
173
|
+
setupProxy(config, nuxt, logger);
|
|
174
|
+
}
|
|
175
|
+
if (config.image.enabled) {
|
|
176
|
+
if (!hasNuxtModule("@nuxt/image")) return logger.error("@nuxt/image is not installed! Please install it to use the image features of this module.");
|
|
177
|
+
setupImage(config, nuxt, logger);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
function normalizeConfig(options) {
|
|
182
|
+
return defu({
|
|
183
|
+
url: options.url,
|
|
184
|
+
accessToken: options.accessToken,
|
|
185
|
+
i18n: options.i18n === false ? { enabled: false } : options.i18n,
|
|
186
|
+
types: options.types === false ? { enabled: false } : options.types,
|
|
187
|
+
proxy: options.proxy === false ? { enabled: false } : options.proxy,
|
|
188
|
+
image: options.image === false ? { enabled: false } : options.image,
|
|
189
|
+
composables: options.composables === false ? { enabled: false } : options.composables
|
|
190
|
+
}, {
|
|
191
|
+
url: process.env.DIRECTUS_URL ?? "http://localhost:8055",
|
|
192
|
+
accessToken: process.env.DIRECTUS_ACCESS_TOKEN ?? "",
|
|
193
|
+
i18n: { enabled: hasNuxtModule("@nuxtjs/i18n"), sync: true, prefix: void 0 },
|
|
194
|
+
types: { enabled: true },
|
|
195
|
+
proxy: { enabled: true, path: "/api", options: {} },
|
|
196
|
+
image: { enabled: hasNuxtModule("@nuxt/image"), alias: "directus" },
|
|
197
|
+
composables: { enabled: true, mode: "rest", client: true, server: true }
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
function setupComposables(config, nuxt, logger) {
|
|
201
|
+
const { resolve } = createResolver(import.meta.url);
|
|
202
|
+
const path = resolve(`./runtime/composables/${config.composables.mode}`);
|
|
203
|
+
nuxt.options.alias = defu(nuxt.options.alias, {
|
|
204
|
+
"#directus": path
|
|
205
|
+
});
|
|
206
|
+
if (config.composables.client) {
|
|
207
|
+
addImports({
|
|
208
|
+
from: path,
|
|
209
|
+
name: "useDirectus"
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
if (config.composables.server) {
|
|
213
|
+
addServerImports({
|
|
214
|
+
from: path,
|
|
215
|
+
name: "useDirectus"
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
logger.info(`Composables have been registered (mode: ${config.composables.mode}).`);
|
|
219
|
+
}
|
|
220
|
+
function setupI18n(config, nuxt, logger) {
|
|
221
|
+
const { resolve } = createResolver(import.meta.url);
|
|
222
|
+
const codes = (nuxt.options.i18n?.locales || []).map((locale) => typeof locale === "string" ? locale : locale.code);
|
|
223
|
+
if (!codes.length) return;
|
|
224
|
+
if (config.i18n.sync) {
|
|
225
|
+
const runtimeConfig = {
|
|
226
|
+
url: config.url,
|
|
227
|
+
accessToken: config.accessToken,
|
|
228
|
+
i18nPrefix: config.i18n.prefix
|
|
229
|
+
};
|
|
230
|
+
codes.map((code) => {
|
|
231
|
+
const { dst } = addTemplate({
|
|
232
|
+
write: true,
|
|
233
|
+
filename: `../.locales/${code}.json`,
|
|
234
|
+
getContents: () => fetchTranslations(code, runtimeConfig).then((translations) => {
|
|
235
|
+
return JSON.stringify(Object.fromEntries(translations.map((translation) => [translation.key, translation.value])), null, 2);
|
|
236
|
+
})
|
|
237
|
+
});
|
|
238
|
+
nuxt.hook("builder:watch", async (event, filePath) => {
|
|
239
|
+
if (filePath === dst) {
|
|
240
|
+
const translations = JSON.parse(readFileSync(filePath, "utf-8"));
|
|
241
|
+
const done = await syncTranslations(code, translations, runtimeConfig);
|
|
242
|
+
if (!done) return;
|
|
243
|
+
logger.info(`Synced translations for locale: ${code}`);
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
nuxt.hook("i18n:registerModule", (register) => {
|
|
249
|
+
const locales = codes.map((code) => ({
|
|
250
|
+
code,
|
|
251
|
+
file: "index.ts"
|
|
252
|
+
}));
|
|
253
|
+
register({ langDir: resolve("./runtime/lang"), locales });
|
|
254
|
+
logger.success("Locales have been registered: " + codes.join(", "));
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
async function setupTypes(config, nuxt, logger) {
|
|
258
|
+
addTypeTemplate({
|
|
259
|
+
filename: "directus/types.d.ts",
|
|
260
|
+
getContents: () => generateDirectusTypes({
|
|
261
|
+
directusUrl: withoutTrailingSlash(config.url),
|
|
262
|
+
outputPath: "",
|
|
263
|
+
directusToken: config.accessToken
|
|
264
|
+
})
|
|
265
|
+
});
|
|
266
|
+
nuxt.options.alias = defu(nuxt.options.alias, {
|
|
267
|
+
"#directus/types": "./directus/types.d.ts"
|
|
268
|
+
});
|
|
269
|
+
logger.info("Directus types have been generated.");
|
|
270
|
+
}
|
|
271
|
+
function setupProxy(config, nuxt, logger) {
|
|
272
|
+
nuxt.options.routeRules ??= {};
|
|
273
|
+
nuxt.options.routeRules[joinURL(config.proxy.path, "**")] = {
|
|
274
|
+
proxy: defu(config.proxy.options, {
|
|
275
|
+
to: joinURL(config.url, "**")
|
|
276
|
+
})
|
|
277
|
+
};
|
|
278
|
+
logger.info(`Proxy is enabled on path: ${config.proxy.path}`);
|
|
279
|
+
}
|
|
280
|
+
function setupImage(config, nuxt, logger) {
|
|
281
|
+
nuxt.options.image = defu(nuxt.options.image, {
|
|
282
|
+
domains: [new URL(config.url).hostname],
|
|
283
|
+
alias: {
|
|
284
|
+
[config.image.alias]: joinURL(config.url, "assets")
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
logger.info(`Image alias has been registered: ${config.image.alias} -> ${config.url}`);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export { module as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Schema } from '#directus/types';
|
|
2
|
+
/**
|
|
3
|
+
* Create base directus instance.
|
|
4
|
+
*/
|
|
5
|
+
export declare function createBaseDirectus(): import("@directus/sdk").DirectusClient<Schema>;
|
|
6
|
+
/**
|
|
7
|
+
* Get i18n translations.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getI18nTranslations(locale: string, config?: any): Promise<{
|
|
10
|
+
[k: string]: string;
|
|
11
|
+
}>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { NAME } from "./../constants";
|
|
2
|
+
import { createDirectus } from "@directus/sdk";
|
|
3
|
+
import { parseHost, joinURL } from "ufo";
|
|
4
|
+
import { createError, useRuntimeConfig } from "#imports";
|
|
5
|
+
import { fetchTranslations } from "./../helpers";
|
|
6
|
+
function getRuntimeConfig() {
|
|
7
|
+
if (import.meta.server) return useRuntimeConfig()[NAME];
|
|
8
|
+
const base = useRuntimeConfig().public[NAME];
|
|
9
|
+
return {
|
|
10
|
+
...base,
|
|
11
|
+
url: getRuntimeClientDirectusURL(base.url)
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function getRuntimeClientDirectusURL(path) {
|
|
15
|
+
if (!path) throw new Error(`[${NAME}] No Directus URL provided for client.`);
|
|
16
|
+
const hasHost = !!parseHost(path).hostname;
|
|
17
|
+
return hasHost ? path : joinURL(window.location.origin, path);
|
|
18
|
+
}
|
|
19
|
+
export function createBaseDirectus() {
|
|
20
|
+
const { url } = getRuntimeConfig();
|
|
21
|
+
return createDirectus(url, {
|
|
22
|
+
globals: {
|
|
23
|
+
fetch: $fetch.create({
|
|
24
|
+
baseURL: url,
|
|
25
|
+
onResponseError({ response }) {
|
|
26
|
+
const [error] = response._data.errors || [];
|
|
27
|
+
if (!error) return;
|
|
28
|
+
throw createError({
|
|
29
|
+
status: response.status,
|
|
30
|
+
message: error.message
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
export async function getI18nTranslations(locale, config = getRuntimeConfig()) {
|
|
38
|
+
const data = await fetchTranslations(locale, config);
|
|
39
|
+
return Object.fromEntries(data.map((item) => [item.key, item.value]));
|
|
40
|
+
}
|
package/dist/types.d.mts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yassidev/nuxt-directus",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "A Nuxt module for better integration with Directus CMS.",
|
|
5
|
+
"repository": "yassilah/nuxt-directus",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"private": false,
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/types.d.mts",
|
|
12
|
+
"import": "./dist/module.mjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"main": "./dist/module.mjs",
|
|
16
|
+
"typesVersions": {
|
|
17
|
+
"*": {
|
|
18
|
+
".": [
|
|
19
|
+
"./dist/types.d.mts"
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"prepack": "nuxt-module-build build",
|
|
28
|
+
"dev": "npm run dev:prepare && nuxi dev playground",
|
|
29
|
+
"dev:build": "nuxi build playground",
|
|
30
|
+
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
31
|
+
"release": "npm run lint && npm run test && npm run prepack && changelogen --release && npm publish --access public && git push --follow-tags",
|
|
32
|
+
"lint": "eslint .",
|
|
33
|
+
"test": "vitest run",
|
|
34
|
+
"test:watch": "vitest watch",
|
|
35
|
+
"test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@directus/sdk": "^20.1.0",
|
|
39
|
+
"@nuxt/kit": "^4.1.3",
|
|
40
|
+
"directus-sdk-typegen": "^0.2.1"
|
|
41
|
+
},
|
|
42
|
+
"build": {
|
|
43
|
+
"failOnWarn": false
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@nuxt/devtools": "^2.6.5",
|
|
47
|
+
"@nuxt/eslint": "1.9.0",
|
|
48
|
+
"@nuxt/eslint-config": "^1.9.0",
|
|
49
|
+
"@nuxt/image": "^1.11.0",
|
|
50
|
+
"@nuxt/module-builder": "^1.0.2",
|
|
51
|
+
"@nuxt/schema": "^4.1.3",
|
|
52
|
+
"@nuxt/test-utils": "^3.19.2",
|
|
53
|
+
"@nuxtjs/i18n": "^10.1.0",
|
|
54
|
+
"@types/node": "latest",
|
|
55
|
+
"changelogen": "^0.6.2",
|
|
56
|
+
"eslint": "^9.37.0",
|
|
57
|
+
"nuxt": "^4.1.3",
|
|
58
|
+
"typescript": "~5.9.3",
|
|
59
|
+
"vitest": "^3.2.4",
|
|
60
|
+
"vue-tsc": "^3.1.0"
|
|
61
|
+
}
|
|
62
|
+
}
|