@yassidev/nuxt-directus 0.0.5 → 0.0.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/dist/module.d.mts +1 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +3 -46
- package/dist/runtime/{helpers.js → client.js} +2 -2
- package/dist/runtime/composables/graphql.js +1 -1
- package/dist/runtime/composables/rest.js +1 -1
- package/dist/runtime/constants.d.ts +1 -0
- package/dist/runtime/constants.js +1 -0
- package/dist/runtime/lang/index.js +1 -1
- package/dist/runtime/server.d.ts +19 -0
- package/dist/runtime/server.js +43 -0
- package/dist/types.d.mts +1 -1
- package/package.json +1 -1
- /package/dist/runtime/{helpers.d.ts → client.d.ts} +0 -0
package/dist/module.d.mts
CHANGED
|
@@ -570,7 +570,6 @@ interface ModuleOptions {
|
|
|
570
570
|
alias?: string;
|
|
571
571
|
};
|
|
572
572
|
}
|
|
573
|
-
declare const NAME = "directus";
|
|
574
573
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
575
574
|
|
|
576
|
-
export {
|
|
575
|
+
export { _default as default };
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { defineNuxtModule, useLogger, updateRuntimeConfig, hasNuxtModule, createResolver, addImports, addServerImports, addTemplate, addTypeTemplate } from 'nuxt/kit';
|
|
2
2
|
import { generateDirectusTypes } from 'directus-sdk-typegen';
|
|
3
|
-
import {
|
|
3
|
+
import { fetchTranslations, syncTranslations } from '../dist/runtime/server.js';
|
|
4
4
|
import { readFileSync } from 'node:fs';
|
|
5
|
+
import { NAME } from '../dist/runtime/constants.js';
|
|
5
6
|
|
|
6
7
|
const JOIN_LEADING_SLASH_RE = /^\.?\//;
|
|
7
8
|
function hasTrailingSlash(input = "", respectQueryAndFragment) {
|
|
@@ -91,50 +92,6 @@ function createDefu(merger) {
|
|
|
91
92
|
}
|
|
92
93
|
const defu = createDefu();
|
|
93
94
|
|
|
94
|
-
function useDirectus(config) {
|
|
95
|
-
return createDirectus(config.url).with(rest()).with(staticToken(config.accessToken || ""));
|
|
96
|
-
}
|
|
97
|
-
async function fetchTranslations(locale, config) {
|
|
98
|
-
const { i18nPrefix } = config;
|
|
99
|
-
const directus = useDirectus(config);
|
|
100
|
-
return await directus.request(readTranslations({
|
|
101
|
-
fields: ["key", "value", "id"],
|
|
102
|
-
limit: -1,
|
|
103
|
-
filter: { language: { _eq: locale }, ...i18nPrefix ? { key: { _startsWith: i18nPrefix } } : {} }
|
|
104
|
-
}));
|
|
105
|
-
}
|
|
106
|
-
async function syncTranslations(locale, translations, config) {
|
|
107
|
-
const directus = useDirectus(config);
|
|
108
|
-
const current = await fetchTranslations(locale, config);
|
|
109
|
-
const payload = {
|
|
110
|
-
create: [],
|
|
111
|
-
update: [],
|
|
112
|
-
remove: []
|
|
113
|
-
};
|
|
114
|
-
for (const [key, value] of Object.entries(translations)) {
|
|
115
|
-
const translation = current.find((t) => t.key === key);
|
|
116
|
-
if (!translation) {
|
|
117
|
-
payload.create.push({ key, value, language: locale });
|
|
118
|
-
} else if (translation.value !== value) {
|
|
119
|
-
payload.update.push({ id: translation.id, value });
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
for (const translation of current) {
|
|
123
|
-
if (!translations[translation.key]) {
|
|
124
|
-
payload.remove.push(translation.id);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
if (!payload.create.length && !payload.update.length && !payload.remove.length) {
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
return Promise.all([
|
|
131
|
-
payload.update.length > 0 ? directus.request(updateTranslationsBatch(payload.update)) : null,
|
|
132
|
-
payload.create.length > 0 ? directus.request(createTranslations(payload.create)) : null,
|
|
133
|
-
payload.remove.length > 0 ? directus.request(deleteTranslations(payload.remove)) : null
|
|
134
|
-
]);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const NAME = "directus";
|
|
138
95
|
const module = defineNuxtModule({
|
|
139
96
|
meta: { name: NAME },
|
|
140
97
|
setup(options, nuxt) {
|
|
@@ -286,4 +243,4 @@ function setupImage(config, nuxt, logger) {
|
|
|
286
243
|
logger.info(`Image alias has been registered: ${config.image.alias} -> ${config.url}`);
|
|
287
244
|
}
|
|
288
245
|
|
|
289
|
-
export {
|
|
246
|
+
export { module as default };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { NAME } from "
|
|
1
|
+
import { NAME } from "./constants.js";
|
|
2
2
|
import { createDirectus } from "@directus/sdk";
|
|
3
3
|
import { parseHost, joinURL } from "ufo";
|
|
4
4
|
import { createError, useRuntimeConfig } from "#imports";
|
|
5
|
-
import { fetchTranslations } from "
|
|
5
|
+
import { fetchTranslations } from "./server.js";
|
|
6
6
|
function getRuntimeConfig() {
|
|
7
7
|
if (import.meta.server) return useRuntimeConfig()[NAME];
|
|
8
8
|
const base = useRuntimeConfig().public[NAME];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const NAME = "directus";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const NAME = "directus";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type Config = {
|
|
2
|
+
url: string;
|
|
3
|
+
accessToken?: string;
|
|
4
|
+
i18nPrefix?: string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Fetch translations.
|
|
8
|
+
*/
|
|
9
|
+
export declare function fetchTranslations(locale: string, config: Config): Promise<{
|
|
10
|
+
id: string;
|
|
11
|
+
language: string;
|
|
12
|
+
key: string;
|
|
13
|
+
value: string;
|
|
14
|
+
}[]>;
|
|
15
|
+
/**
|
|
16
|
+
* Update translations.
|
|
17
|
+
*/
|
|
18
|
+
export declare function syncTranslations(locale: string, translations: Record<string, string>, config: Config): Promise<false | [Record<string, any>[] | null, Record<string, any>[] | null, void | null]>;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { createDirectus, createTranslations, deleteTranslations, readTranslations, rest, staticToken, updateTranslationsBatch } from "@directus/sdk";
|
|
2
|
+
function useDirectus(config) {
|
|
3
|
+
return createDirectus(config.url).with(rest()).with(staticToken(config.accessToken || ""));
|
|
4
|
+
}
|
|
5
|
+
export async function fetchTranslations(locale, config) {
|
|
6
|
+
const { i18nPrefix } = config;
|
|
7
|
+
const directus = useDirectus(config);
|
|
8
|
+
return await directus.request(readTranslations({
|
|
9
|
+
fields: ["key", "value", "id"],
|
|
10
|
+
limit: -1,
|
|
11
|
+
filter: { language: { _eq: locale }, ...i18nPrefix ? { key: { _startsWith: i18nPrefix } } : {} }
|
|
12
|
+
}));
|
|
13
|
+
}
|
|
14
|
+
export async function syncTranslations(locale, translations, config) {
|
|
15
|
+
const directus = useDirectus(config);
|
|
16
|
+
const current = await fetchTranslations(locale, config);
|
|
17
|
+
const payload = {
|
|
18
|
+
create: [],
|
|
19
|
+
update: [],
|
|
20
|
+
remove: []
|
|
21
|
+
};
|
|
22
|
+
for (const [key, value] of Object.entries(translations)) {
|
|
23
|
+
const translation = current.find((t) => t.key === key);
|
|
24
|
+
if (!translation) {
|
|
25
|
+
payload.create.push({ key, value, language: locale });
|
|
26
|
+
} else if (translation.value !== value) {
|
|
27
|
+
payload.update.push({ id: translation.id, value });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
for (const translation of current) {
|
|
31
|
+
if (!translations[translation.key]) {
|
|
32
|
+
payload.remove.push(translation.id);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (!payload.create.length && !payload.update.length && !payload.remove.length) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
return Promise.all([
|
|
39
|
+
payload.update.length > 0 ? directus.request(updateTranslationsBatch(payload.update)) : null,
|
|
40
|
+
payload.create.length > 0 ? directus.request(createTranslations(payload.create)) : null,
|
|
41
|
+
payload.remove.length > 0 ? directus.request(deleteTranslations(payload.remove)) : null
|
|
42
|
+
]);
|
|
43
|
+
}
|
package/dist/types.d.mts
CHANGED
package/package.json
CHANGED
|
File without changes
|