nuxt-directus-sdk 6.0.0-beta.2 → 6.0.0-beta.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.
- package/README.md +5 -4
- package/dist/cli/index.mjs +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +21 -11
- package/dist/rules/index.d.mts +6 -6
- package/dist/rules/index.d.ts +6 -6
- package/dist/rules/index.mjs +2 -2
- package/dist/runtime/composables/directus.js +0 -1
- package/dist/runtime/composables/files.d.ts +0 -1
- package/dist/runtime/composables/files.js +5 -2
- package/dist/runtime/composables/storage.d.ts +2 -2
- package/dist/runtime/composables/storage.js +4 -6
- package/dist/runtime/server/services/directus.js +1 -1
- package/dist/runtime/types/fallback.d.ts +25 -2
- package/dist/runtime/types/generate.d.ts +1 -2
- package/dist/runtime/types/generate.js +2 -3
- package/dist/runtime/types/index.d.ts +1 -1
- package/dist/runtime/types/index.js +1 -1
- package/dist/runtime/types/modules.d.ts +2 -2
- package/dist/shared/{nuxt-directus-sdk.BzXguU5u.mjs → nuxt-directus-sdk.CtcY1peN.mjs} +28 -37
- package/package.json +7 -4
package/README.md
CHANGED
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
> A Nuxt module for Directus with built-in authentication, realtime, file management, type generation, and visual editor support.
|
|
11
11
|
|
|
12
12
|
- [✨ Release Notes](https://github.com/rolleyio/nuxt-directus-sdk/releases)
|
|
13
|
-
- [📚 Documentation](https://nuxt-directus-sdk.
|
|
13
|
+
- [📚 Documentation](https://www.nuxt-directus-sdk.com)
|
|
14
|
+
- [🛝 Live Playground](https://playground.nuxt-directus-sdk.com)
|
|
14
15
|
|
|
15
16
|
## Features
|
|
16
17
|
|
|
@@ -63,11 +64,11 @@ DIRECTUS_URL=https://your-directus-url.com
|
|
|
63
64
|
DIRECTUS_ADMIN_TOKEN=your_admin_token # Optional: required for type generation
|
|
64
65
|
```
|
|
65
66
|
|
|
66
|
-
4. **Configure your Directus backend** for cross-domain authentication (see the [Authentication Guide](https://nuxt-directus-sdk.
|
|
67
|
+
4. **Configure your Directus backend** for cross-domain authentication (see the [Authentication Guide](https://www.nuxt-directus-sdk.com/guide/authentication.html))
|
|
67
68
|
|
|
68
69
|
That's it! You can now use Directus within your Nuxt app ✨
|
|
69
70
|
|
|
70
|
-
For cross-domain setups (e.g. `app.example.com` and `api.example.com`), see the [Authentication Guide](https://nuxt-directus-sdk.
|
|
71
|
+
For cross-domain setups (e.g. `app.example.com` and `api.example.com`), see the [Authentication Guide](https://www.nuxt-directus-sdk.com/guide/authentication.html).
|
|
71
72
|
|
|
72
73
|
## CLI
|
|
73
74
|
|
|
@@ -84,7 +85,7 @@ npx nuxt-directus-sdk rules:pull -o rules.json
|
|
|
84
85
|
npx nuxt-directus-sdk --help
|
|
85
86
|
```
|
|
86
87
|
|
|
87
|
-
See the [CLI documentation](https://nuxt-directus-sdk.
|
|
88
|
+
See the [CLI documentation](https://www.nuxt-directus-sdk.com/api/configuration/module#types) for flags and examples.
|
|
88
89
|
|
|
89
90
|
## Development
|
|
90
91
|
|
package/dist/cli/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { existsSync, readFileSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
|
3
3
|
import { resolve, dirname } from 'node:path';
|
|
4
4
|
import { parseArgs } from 'node:util';
|
|
5
5
|
import { createDirectus, staticToken, rest } from '@directus/sdk';
|
|
6
|
-
import { d as diffRemoteRules, e as formatDiff, c as compareRulesPayloads, f as fetchRemoteRules, k as loadRulesFromPayload, o as pushRules, g as formatPushResult, b as fetchRemoteRulesAsJson } from '../shared/nuxt-directus-sdk.
|
|
6
|
+
import { d as diffRemoteRules, e as formatDiff, c as compareRulesPayloads, f as fetchRemoteRules, k as loadRulesFromPayload, o as pushRules, g as formatPushResult, b as fetchRemoteRulesAsJson } from '../shared/nuxt-directus-sdk.CtcY1peN.mjs';
|
|
7
7
|
import { generateTypesFromDirectus } from '../../dist/runtime/types/generate.js';
|
|
8
8
|
|
|
9
9
|
function parseCsv(raw) {
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -3,11 +3,12 @@ import { useLogger, defineNuxtModule, createResolver, addServerHandler, hasNuxtM
|
|
|
3
3
|
import { colors } from 'consola/utils';
|
|
4
4
|
import { defu } from 'defu';
|
|
5
5
|
import { joinURL } from 'ufo';
|
|
6
|
+
import { readFileSync } from 'node:fs';
|
|
6
7
|
import { generateTypesFromDirectus } from '../dist/runtime/types/index.js';
|
|
7
8
|
import { useUrl } from '../dist/runtime/utils/index.js';
|
|
8
9
|
|
|
9
10
|
const name = "nuxt-directus-sdk";
|
|
10
|
-
const version = "6.0.0-beta.
|
|
11
|
+
const version = "6.0.0-beta.3";
|
|
11
12
|
|
|
12
13
|
const SDK_CLIENT_FACTORIES = /* @__PURE__ */ new Set([
|
|
13
14
|
"createDirectus",
|
|
@@ -100,6 +101,7 @@ const module$1 = defineNuxtModule({
|
|
|
100
101
|
loggerMessage.push(`\u26A0\uFE0F No Directus URL found at build time:`, ` - Set it in config options, .env file as DIRECTUS_URL or at runtime via NUXT_PUBLIC_DIRECTUS_URL.`, "");
|
|
101
102
|
}
|
|
102
103
|
const resolver = createResolver(import.meta.url);
|
|
104
|
+
const fallbackTypeContent = readFileSync(resolver.resolve("./runtime/types/fallback.d.ts"), "utf-8");
|
|
103
105
|
async function registerModule(name2, key, moduleOptions) {
|
|
104
106
|
if (!hasNuxtModule(name2)) {
|
|
105
107
|
await installModule(name2, defu(nuxtApp.options[key], moduleOptions));
|
|
@@ -276,34 +278,42 @@ const module$1 = defineNuxtModule({
|
|
|
276
278
|
const typesExpandReferences = typeof options.types === "object" ? options.types.expandReferences ?? true : true;
|
|
277
279
|
const typesExclude = typeof options.types === "object" ? options.types.exclude ?? [] : [];
|
|
278
280
|
const typesVerbose = typeof options.types === "object" ? options.types.verbose ?? false : false;
|
|
281
|
+
let typeString = fallbackTypeContent;
|
|
279
282
|
if (typesEnabled) {
|
|
280
283
|
loggerMessage.push("\u{1F4CB} Directus Type Generator Enabled");
|
|
281
284
|
if (!options.adminToken) {
|
|
282
|
-
loggerMessage.push(` ${colors.bgRedBright(`${colors.red("\u2691 ERROR:")} Unable to generate Types`)}`, ` Fix: Set adminToken in config or DIRECTUS_ADMIN_TOKEN in .env`);
|
|
285
|
+
loggerMessage.push(` ${colors.bgRedBright(`${colors.red("\u2691 ERROR:")} Unable to generate Types`)}`, ` Fix: Set adminToken in config or DIRECTUS_ADMIN_TOKEN in .env`, ` - Fallback DirectusSchema is being used ${colors.dim("(not recommended)")}`);
|
|
283
286
|
} else {
|
|
284
287
|
try {
|
|
285
|
-
const { typeString, logs } = await generateTypesFromDirectus(directusUrl, options.adminToken, typesPrefix, {
|
|
288
|
+
const { typeString: generated, logs } = await generateTypesFromDirectus(directusUrl, options.adminToken, typesPrefix, {
|
|
286
289
|
include: typesInclude,
|
|
287
290
|
expandReferences: typesExpandReferences,
|
|
288
291
|
exclude: typesExclude,
|
|
289
292
|
verbose: typesVerbose
|
|
290
293
|
});
|
|
291
294
|
loggerMessage.push(...logs);
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
295
|
+
if (generated !== null) {
|
|
296
|
+
typeString = generated;
|
|
297
|
+
if (!logs.some((log) => log.toLowerCase().includes("error"))) {
|
|
298
|
+
loggerMessage.push(` - Directus Types saved successfully to ${colors.dim(`#build/types/${configKey}.d.ts`)}`);
|
|
299
|
+
} else {
|
|
300
|
+
throw new Error(` ${colors.bgRedBright(`${colors.red("\u2691 ERROR:")} TypeGenerator returned an error`)}`);
|
|
296
301
|
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
throw new Error(` ${colors.bgRedBright(`${colors.red("\u2691 ERROR:")} TypeGenerator returned an error`)}`);
|
|
302
|
+
} else {
|
|
303
|
+
loggerMessage.push(` - Fallback DirectusSchema is being used ${colors.dim("(not recommended)")}`);
|
|
300
304
|
}
|
|
301
|
-
loggerMessage.push(` - Directus Types saved successfully to ${colors.dim(`#build/types/${configKey}.d.ts`)}`);
|
|
302
305
|
} catch (error) {
|
|
306
|
+
typeString = fallbackTypeContent;
|
|
303
307
|
loggerMessage.push(`${error instanceof Error ? error.message : String(error)}`, ` - Fallback DirectusSchema is being used ${colors.dim("(not recommended)")}`);
|
|
304
308
|
}
|
|
305
309
|
}
|
|
306
310
|
}
|
|
311
|
+
addTypeTemplate({
|
|
312
|
+
filename: `types/${configKey}.d.ts`,
|
|
313
|
+
getContents() {
|
|
314
|
+
return typeString;
|
|
315
|
+
}
|
|
316
|
+
}, { nitro: true, nuxt: true });
|
|
307
317
|
logger.box({ message: loggerMessage.join("\n"), title: `${colors.magenta(`Nuxt Directus SDK Version: ${colors.magentaBright(`${version}`)}`)}`, style: { padding: 3, borderColor: "magenta", borderStyle: "double-single-rounded" } });
|
|
308
318
|
}
|
|
309
319
|
});
|
package/dist/rules/index.d.mts
CHANGED
|
@@ -933,7 +933,7 @@ declare function evaluateFilter<T extends Record<string, unknown>>(filter: Recor
|
|
|
933
933
|
* @param collection - The collection name
|
|
934
934
|
* @returns Array of accessible field names, '*' for all, or empty array for none
|
|
935
935
|
*/
|
|
936
|
-
declare function getAccessibleFields<Schema>(rules: RulesConfig<Schema>, roleOrPolicy: string, action: PermissionAction, collection:
|
|
936
|
+
declare function getAccessibleFields<Schema, K extends keyof Schema>(rules: RulesConfig<Schema>, roleOrPolicy: string, action: PermissionAction, collection: K): (keyof CollectionItem<Schema, K>)[] | '*';
|
|
937
937
|
/**
|
|
938
938
|
* Check if a role/policy grants access to a specific field
|
|
939
939
|
*
|
|
@@ -944,7 +944,7 @@ declare function getAccessibleFields<Schema>(rules: RulesConfig<Schema>, roleOrP
|
|
|
944
944
|
* @param field - The field to check
|
|
945
945
|
* @returns true if the field is accessible
|
|
946
946
|
*/
|
|
947
|
-
declare function canAccessField<Schema>(rules: RulesConfig<Schema>, roleOrPolicy: string, action: PermissionAction, collection:
|
|
947
|
+
declare function canAccessField<Schema, K extends keyof Schema>(rules: RulesConfig<Schema>, roleOrPolicy: string, action: PermissionAction, collection: K, field: keyof CollectionItem<Schema, K>): boolean;
|
|
948
948
|
/**
|
|
949
949
|
* Get presets for a permission
|
|
950
950
|
*
|
|
@@ -954,7 +954,7 @@ declare function canAccessField<Schema>(rules: RulesConfig<Schema>, roleOrPolicy
|
|
|
954
954
|
* @param collection - The collection name
|
|
955
955
|
* @returns The presets object or null
|
|
956
956
|
*/
|
|
957
|
-
declare function getPresets<Schema>(rules: RulesConfig<Schema>, roleOrPolicy: string, action: PermissionAction, collection:
|
|
957
|
+
declare function getPresets<Schema, K extends keyof Schema>(rules: RulesConfig<Schema>, roleOrPolicy: string, action: PermissionAction, collection: K): Partial<CollectionItem<Schema, K>> | null;
|
|
958
958
|
|
|
959
959
|
/**
|
|
960
960
|
* Rules tester - main testing interface
|
|
@@ -1004,15 +1004,15 @@ interface RulesTester<Schema> {
|
|
|
1004
1004
|
/**
|
|
1005
1005
|
* Get accessible fields for a permission
|
|
1006
1006
|
*/
|
|
1007
|
-
getAccessibleFields: <K extends keyof Schema>(roleOrPolicy: string, action: PermissionAction, collection: K) => (keyof Schema
|
|
1007
|
+
getAccessibleFields: <K extends keyof Schema>(roleOrPolicy: string, action: PermissionAction, collection: K) => (keyof CollectionItem<Schema, K>)[] | '*';
|
|
1008
1008
|
/**
|
|
1009
1009
|
* Check if a specific field is accessible
|
|
1010
1010
|
*/
|
|
1011
|
-
canAccessField: <K extends keyof Schema>(roleOrPolicy: string, action: PermissionAction, collection: K, field: keyof Schema
|
|
1011
|
+
canAccessField: <K extends keyof Schema>(roleOrPolicy: string, action: PermissionAction, collection: K, field: keyof CollectionItem<Schema, K>) => boolean;
|
|
1012
1012
|
/**
|
|
1013
1013
|
* Get presets for a permission
|
|
1014
1014
|
*/
|
|
1015
|
-
getPresets: <K extends keyof Schema>(roleOrPolicy: string, action: PermissionAction, collection: K) => Partial<Schema
|
|
1015
|
+
getPresets: <K extends keyof Schema>(roleOrPolicy: string, action: PermissionAction, collection: K) => Partial<CollectionItem<Schema, K>> | null;
|
|
1016
1016
|
/**
|
|
1017
1017
|
* Validate an item against permission validation rules
|
|
1018
1018
|
*/
|
package/dist/rules/index.d.ts
CHANGED
|
@@ -933,7 +933,7 @@ declare function evaluateFilter<T extends Record<string, unknown>>(filter: Recor
|
|
|
933
933
|
* @param collection - The collection name
|
|
934
934
|
* @returns Array of accessible field names, '*' for all, or empty array for none
|
|
935
935
|
*/
|
|
936
|
-
declare function getAccessibleFields<Schema>(rules: RulesConfig<Schema>, roleOrPolicy: string, action: PermissionAction, collection:
|
|
936
|
+
declare function getAccessibleFields<Schema, K extends keyof Schema>(rules: RulesConfig<Schema>, roleOrPolicy: string, action: PermissionAction, collection: K): (keyof CollectionItem<Schema, K>)[] | '*';
|
|
937
937
|
/**
|
|
938
938
|
* Check if a role/policy grants access to a specific field
|
|
939
939
|
*
|
|
@@ -944,7 +944,7 @@ declare function getAccessibleFields<Schema>(rules: RulesConfig<Schema>, roleOrP
|
|
|
944
944
|
* @param field - The field to check
|
|
945
945
|
* @returns true if the field is accessible
|
|
946
946
|
*/
|
|
947
|
-
declare function canAccessField<Schema>(rules: RulesConfig<Schema>, roleOrPolicy: string, action: PermissionAction, collection:
|
|
947
|
+
declare function canAccessField<Schema, K extends keyof Schema>(rules: RulesConfig<Schema>, roleOrPolicy: string, action: PermissionAction, collection: K, field: keyof CollectionItem<Schema, K>): boolean;
|
|
948
948
|
/**
|
|
949
949
|
* Get presets for a permission
|
|
950
950
|
*
|
|
@@ -954,7 +954,7 @@ declare function canAccessField<Schema>(rules: RulesConfig<Schema>, roleOrPolicy
|
|
|
954
954
|
* @param collection - The collection name
|
|
955
955
|
* @returns The presets object or null
|
|
956
956
|
*/
|
|
957
|
-
declare function getPresets<Schema>(rules: RulesConfig<Schema>, roleOrPolicy: string, action: PermissionAction, collection:
|
|
957
|
+
declare function getPresets<Schema, K extends keyof Schema>(rules: RulesConfig<Schema>, roleOrPolicy: string, action: PermissionAction, collection: K): Partial<CollectionItem<Schema, K>> | null;
|
|
958
958
|
|
|
959
959
|
/**
|
|
960
960
|
* Rules tester - main testing interface
|
|
@@ -1004,15 +1004,15 @@ interface RulesTester<Schema> {
|
|
|
1004
1004
|
/**
|
|
1005
1005
|
* Get accessible fields for a permission
|
|
1006
1006
|
*/
|
|
1007
|
-
getAccessibleFields: <K extends keyof Schema>(roleOrPolicy: string, action: PermissionAction, collection: K) => (keyof Schema
|
|
1007
|
+
getAccessibleFields: <K extends keyof Schema>(roleOrPolicy: string, action: PermissionAction, collection: K) => (keyof CollectionItem<Schema, K>)[] | '*';
|
|
1008
1008
|
/**
|
|
1009
1009
|
* Check if a specific field is accessible
|
|
1010
1010
|
*/
|
|
1011
|
-
canAccessField: <K extends keyof Schema>(roleOrPolicy: string, action: PermissionAction, collection: K, field: keyof Schema
|
|
1011
|
+
canAccessField: <K extends keyof Schema>(roleOrPolicy: string, action: PermissionAction, collection: K, field: keyof CollectionItem<Schema, K>) => boolean;
|
|
1012
1012
|
/**
|
|
1013
1013
|
* Get presets for a permission
|
|
1014
1014
|
*/
|
|
1015
|
-
getPresets: <K extends keyof Schema>(roleOrPolicy: string, action: PermissionAction, collection: K) => Partial<Schema
|
|
1015
|
+
getPresets: <K extends keyof Schema>(roleOrPolicy: string, action: PermissionAction, collection: K) => Partial<CollectionItem<Schema, K>> | null;
|
|
1016
1016
|
/**
|
|
1017
1017
|
* Validate an item against permission validation rules
|
|
1018
1018
|
*/
|
package/dist/rules/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as isStandardSchema } from '../shared/nuxt-directus-sdk.
|
|
2
|
-
export { c as compareRulesPayloads, d as diffRemoteRules, a as diffRules, f as fetchRemoteRules, b as fetchRemoteRulesAsJson, e as formatDiff, g as formatPushResult, h as isValidationStandardSchema, l as loadRulesFromJson, j as loadRulesFromJsonFile, k as loadRulesFromPayload, m as loadRulesFromPayloadFile, n as normalizeRules, p as pullRules, o as pushRules, r as rulesToJson, s as serializeToDirectusApi, q as serializeToJson, t as toDirectusValidation } from '../shared/nuxt-directus-sdk.
|
|
1
|
+
import { i as isStandardSchema } from '../shared/nuxt-directus-sdk.CtcY1peN.mjs';
|
|
2
|
+
export { c as compareRulesPayloads, d as diffRemoteRules, a as diffRules, f as fetchRemoteRules, b as fetchRemoteRulesAsJson, e as formatDiff, g as formatPushResult, h as isValidationStandardSchema, l as loadRulesFromJson, j as loadRulesFromJsonFile, k as loadRulesFromPayload, m as loadRulesFromPayloadFile, n as normalizeRules, p as pullRules, o as pushRules, r as rulesToJson, s as serializeToDirectusApi, q as serializeToJson, t as toDirectusValidation } from '../shared/nuxt-directus-sdk.CtcY1peN.mjs';
|
|
3
3
|
import '@directus/sdk';
|
|
4
4
|
|
|
5
5
|
function isPolicyReference(input) {
|
|
@@ -2,7 +2,10 @@ import { uploadFiles } from "@directus/sdk";
|
|
|
2
2
|
import { useDirectus, useDirectusUrl } from "./directus.js";
|
|
3
3
|
export async function uploadDirectusFile(file, query) {
|
|
4
4
|
const result = await uploadDirectusFiles([file], query);
|
|
5
|
-
|
|
5
|
+
const uploaded = Array.isArray(result) ? result[0] : result;
|
|
6
|
+
if (!uploaded)
|
|
7
|
+
throw new Error("Upload did not return a file");
|
|
8
|
+
return uploaded;
|
|
6
9
|
}
|
|
7
10
|
export async function uploadDirectusFiles(files, query) {
|
|
8
11
|
const directus = useDirectus();
|
|
@@ -10,7 +13,7 @@ export async function uploadDirectusFiles(files, query) {
|
|
|
10
13
|
files.forEach(({ file, data }) => {
|
|
11
14
|
if (data) {
|
|
12
15
|
Object.entries(data).forEach(([key, value]) => {
|
|
13
|
-
formData.set(key, value);
|
|
16
|
+
if (value !== void 0) formData.set(key, value);
|
|
14
17
|
});
|
|
15
18
|
}
|
|
16
19
|
formData.append("file", file);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AuthenticationStorage } from '@directus/sdk';
|
|
2
2
|
/**
|
|
3
3
|
* Custom storage implementation for Directus SDK on the server
|
|
4
4
|
* Prevents localStorage errors during SSR
|
|
5
5
|
*/
|
|
6
|
-
export declare function useDirectusStorage():
|
|
6
|
+
export declare function useDirectusStorage(): AuthenticationStorage;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
export function useDirectusStorage() {
|
|
2
|
-
|
|
2
|
+
let stored = null;
|
|
3
3
|
return {
|
|
4
|
-
get: async (
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
set: async (key, value) => {
|
|
8
|
-
storage.set(key, value);
|
|
4
|
+
get: async () => stored,
|
|
5
|
+
set: async (value) => {
|
|
6
|
+
stored = value;
|
|
9
7
|
}
|
|
10
8
|
};
|
|
11
9
|
}
|
|
@@ -9,7 +9,7 @@ export function useDirectusUrl(path = "") {
|
|
|
9
9
|
const config = useRuntimeConfig();
|
|
10
10
|
const serverUrl = config.directus?.serverDirectusUrl;
|
|
11
11
|
const fallback = config.public.directus.directusUrl || config.public.directus.url;
|
|
12
|
-
const url = serverUrl || fallback || process.env.DIRECTUS_URL;
|
|
12
|
+
const url = serverUrl || fallback || process.env.DIRECTUS_URL || "";
|
|
13
13
|
return useUrl(url, path);
|
|
14
14
|
}
|
|
15
15
|
export function useTokenDirectus(token) {
|
|
@@ -1,8 +1,31 @@
|
|
|
1
|
+
import type { DirectusFile as SdkDirectusFile } from '@directus/sdk'
|
|
2
|
+
|
|
1
3
|
export {}
|
|
2
4
|
|
|
5
|
+
// Fields anchored to the SDK type so renames/removals error at compile time.
|
|
6
|
+
// folder is included as DirectusFolder<object> | string | null — the union covers both
|
|
7
|
+
// expanded queries and the bare UUID string used when passing folder as FormData metadata.
|
|
8
|
+
type SdkFileStringFields = Partial<Pick<SdkDirectusFile<object>,
|
|
9
|
+
| 'title'
|
|
10
|
+
| 'description'
|
|
11
|
+
| 'location'
|
|
12
|
+
| 'type'
|
|
13
|
+
| 'charset'
|
|
14
|
+
| 'storage'
|
|
15
|
+
| 'filename_disk'
|
|
16
|
+
| 'filename_download'
|
|
17
|
+
| 'folder'
|
|
18
|
+
>>
|
|
19
|
+
|
|
3
20
|
declare global {
|
|
4
|
-
|
|
5
|
-
|
|
21
|
+
interface DirectusFile extends SdkFileStringFields {
|
|
22
|
+
id: string
|
|
23
|
+
}
|
|
24
|
+
interface DirectusUser {
|
|
25
|
+
id: string
|
|
26
|
+
}
|
|
6
27
|
interface DirectusSchema {
|
|
28
|
+
directus_files: DirectusFile
|
|
29
|
+
directus_users: DirectusUser
|
|
7
30
|
}
|
|
8
31
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { SnapshotCollection, SnapshotField, SnapshotRelation } from '@directus/types';
|
|
2
2
|
import type { TypegenExtension } from './extensions/index.js';
|
|
3
|
-
export declare const FALLBACK_TYPE_STRING = "declare global {\n\ninterface DirectusFile {\n\tid: string;\n}\ninterface DirectusUser {\n\tid: string;\n}\ninterface DirectusSchema { }\n}\n\nexport {};";
|
|
4
3
|
interface RewriteRecord {
|
|
5
4
|
fromCollection: string;
|
|
6
5
|
fromField: string;
|
|
@@ -48,7 +47,7 @@ export interface GenerateTypesOptions {
|
|
|
48
47
|
verbose?: boolean;
|
|
49
48
|
}
|
|
50
49
|
export declare function generateTypesFromDirectus(url: string, token: string, prefix: string, options?: GenerateTypesOptions): Promise<{
|
|
51
|
-
typeString: string;
|
|
50
|
+
typeString: string | null;
|
|
52
51
|
logs: string[];
|
|
53
52
|
}>;
|
|
54
53
|
/**
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createDirectus, isDirectusError, readCollections, readFields, readRelations, rest, staticToken } from "@directus/sdk";
|
|
2
2
|
import { typegenExtensions } from "./extensions/index.js";
|
|
3
|
-
export const FALLBACK_TYPE_STRING = "declare global {\n\ninterface DirectusFile {\n id: string;\n}\ninterface DirectusUser {\n id: string;\n}\ninterface DirectusSchema { }\n}\n\nexport {};";
|
|
4
3
|
export async function generateTypesFromDirectus(url, token, prefix, options = {}) {
|
|
5
4
|
const logs = [];
|
|
6
5
|
const client = createDirectus(url).with(rest()).with(staticToken(token));
|
|
@@ -26,7 +25,7 @@ export async function generateTypesFromDirectus(url, token, prefix, options = {}
|
|
|
26
25
|
} else {
|
|
27
26
|
logs.push(` - Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
28
27
|
}
|
|
29
|
-
return { typeString:
|
|
28
|
+
return { typeString: null, logs };
|
|
30
29
|
}
|
|
31
30
|
const resolvedOptions = {
|
|
32
31
|
include: options.include ?? [],
|
|
@@ -355,7 +354,7 @@ function determineFieldType(field) {
|
|
|
355
354
|
);
|
|
356
355
|
const unionOfChoices = [...new Set(choiceValues)].join(" | ");
|
|
357
356
|
const interfacesWithMultiSelect = ["select-multiple", "select-multiple-dropdown", "select-multiple-checkbox"];
|
|
358
|
-
if (interfacesWithMultiSelect.includes(field.meta.interface)) {
|
|
357
|
+
if (interfacesWithMultiSelect.includes(field.meta.interface ?? "")) {
|
|
359
358
|
return `Array<${unionOfChoices}>`;
|
|
360
359
|
}
|
|
361
360
|
return unionOfChoices;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { generateTypesFromDirectus } from './generate.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { generateTypesFromDirectus } from "./generate.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
export {}
|
|
2
2
|
|
|
3
3
|
declare module '#app' {
|
|
4
4
|
interface RuntimeNuxtHooks {
|
|
5
|
-
'directus:loggedIn': (user:
|
|
5
|
+
'directus:loggedIn': (user: DirectusUser | null) => void
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
interface NuxtApp {
|
|
@@ -138,17 +138,15 @@ function loadRulesFromPayload(payload) {
|
|
|
138
138
|
}
|
|
139
139
|
permissionsByPolicy.get(key).push(perm);
|
|
140
140
|
}
|
|
141
|
+
const policyById = /* @__PURE__ */ new Map();
|
|
141
142
|
const policies = payload.policies.map((policy) => {
|
|
142
143
|
const policyPerms = permissionsByPolicy.get(policy.id ?? null) ?? [];
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
for (let i = 0; i < payload.policies.length; i++) {
|
|
147
|
-
const apiPolicy = payload.policies[i];
|
|
148
|
-
if (apiPolicy.id) {
|
|
149
|
-
policyById.set(apiPolicy.id, policies[i]);
|
|
144
|
+
const converted = convertPayloadPolicy(policy, policyPerms);
|
|
145
|
+
if (policy.id) {
|
|
146
|
+
policyById.set(policy.id, converted);
|
|
150
147
|
}
|
|
151
|
-
|
|
148
|
+
return converted;
|
|
149
|
+
});
|
|
152
150
|
const roles = payload.roles.map((role) => {
|
|
153
151
|
const rolePolicies = [];
|
|
154
152
|
if (role.policies) {
|
|
@@ -740,11 +738,13 @@ function formatAddedFields(lines, item, excludeKeys) {
|
|
|
740
738
|
}
|
|
741
739
|
function formatModifiedFields(lines, local, remote, excludeKeys) {
|
|
742
740
|
const allKeys = /* @__PURE__ */ new Set([...Object.keys(local), ...Object.keys(remote)]);
|
|
741
|
+
const localRec = local;
|
|
742
|
+
const remoteRec = remote;
|
|
743
743
|
for (const key of allKeys) {
|
|
744
744
|
if (excludeKeys.includes(key))
|
|
745
745
|
continue;
|
|
746
|
-
const localVal =
|
|
747
|
-
const remoteVal =
|
|
746
|
+
const localVal = localRec[key];
|
|
747
|
+
const remoteVal = remoteRec[key];
|
|
748
748
|
if (!valuesEqual(localVal, remoteVal)) {
|
|
749
749
|
lines.push(` ${key}:`);
|
|
750
750
|
lines.push(` - ${formatValue(remoteVal)}`);
|
|
@@ -1105,13 +1105,12 @@ async function pushRules(client, localRules, options = {}) {
|
|
|
1105
1105
|
}
|
|
1106
1106
|
const policyIdMap = /* @__PURE__ */ new Map();
|
|
1107
1107
|
const policiesToCreate = diff.policies.filter((p) => p.type === "added");
|
|
1108
|
-
for (
|
|
1109
|
-
const change = policiesToCreate[i];
|
|
1108
|
+
for (const [idx, change] of policiesToCreate.entries()) {
|
|
1110
1109
|
onProgress?.({
|
|
1111
1110
|
phase: "policies",
|
|
1112
1111
|
action: "create",
|
|
1113
1112
|
name: change.name,
|
|
1114
|
-
current:
|
|
1113
|
+
current: idx + 1,
|
|
1115
1114
|
total: policiesToCreate.length
|
|
1116
1115
|
});
|
|
1117
1116
|
try {
|
|
@@ -1142,13 +1141,12 @@ async function pushRules(client, localRules, options = {}) {
|
|
|
1142
1141
|
}
|
|
1143
1142
|
if (!addOnly) {
|
|
1144
1143
|
const policiesToUpdate = diff.policies.filter((p) => p.type === "modified");
|
|
1145
|
-
for (
|
|
1146
|
-
const change = policiesToUpdate[i];
|
|
1144
|
+
for (const [idx, change] of policiesToUpdate.entries()) {
|
|
1147
1145
|
onProgress?.({
|
|
1148
1146
|
phase: "policies",
|
|
1149
1147
|
action: "update",
|
|
1150
1148
|
name: change.name,
|
|
1151
|
-
current:
|
|
1149
|
+
current: idx + 1,
|
|
1152
1150
|
total: policiesToUpdate.length
|
|
1153
1151
|
});
|
|
1154
1152
|
try {
|
|
@@ -1184,13 +1182,12 @@ async function pushRules(client, localRules, options = {}) {
|
|
|
1184
1182
|
}
|
|
1185
1183
|
}
|
|
1186
1184
|
const rolesToCreate = diff.roles.filter((r) => r.type === "added");
|
|
1187
|
-
for (
|
|
1188
|
-
const change = rolesToCreate[i];
|
|
1185
|
+
for (const [idx, change] of rolesToCreate.entries()) {
|
|
1189
1186
|
onProgress?.({
|
|
1190
1187
|
phase: "roles",
|
|
1191
1188
|
action: "create",
|
|
1192
1189
|
name: change.name,
|
|
1193
|
-
current:
|
|
1190
|
+
current: idx + 1,
|
|
1194
1191
|
total: rolesToCreate.length
|
|
1195
1192
|
});
|
|
1196
1193
|
try {
|
|
@@ -1218,13 +1215,12 @@ async function pushRules(client, localRules, options = {}) {
|
|
|
1218
1215
|
}
|
|
1219
1216
|
if (!addOnly) {
|
|
1220
1217
|
const rolesToUpdate = diff.roles.filter((r) => r.type === "modified");
|
|
1221
|
-
for (
|
|
1222
|
-
const change = rolesToUpdate[i];
|
|
1218
|
+
for (const [idx, change] of rolesToUpdate.entries()) {
|
|
1223
1219
|
onProgress?.({
|
|
1224
1220
|
phase: "roles",
|
|
1225
1221
|
action: "update",
|
|
1226
1222
|
name: change.name,
|
|
1227
|
-
current:
|
|
1223
|
+
current: idx + 1,
|
|
1228
1224
|
total: rolesToUpdate.length
|
|
1229
1225
|
});
|
|
1230
1226
|
try {
|
|
@@ -1253,13 +1249,12 @@ async function pushRules(client, localRules, options = {}) {
|
|
|
1253
1249
|
}
|
|
1254
1250
|
}
|
|
1255
1251
|
const permsToCreate = diff.permissions.filter((p) => p.type === "added");
|
|
1256
|
-
for (
|
|
1257
|
-
const change = permsToCreate[i];
|
|
1252
|
+
for (const [idx, change] of permsToCreate.entries()) {
|
|
1258
1253
|
onProgress?.({
|
|
1259
1254
|
phase: "permissions",
|
|
1260
1255
|
action: "create",
|
|
1261
1256
|
name: change.name,
|
|
1262
|
-
current:
|
|
1257
|
+
current: idx + 1,
|
|
1263
1258
|
total: permsToCreate.length
|
|
1264
1259
|
});
|
|
1265
1260
|
try {
|
|
@@ -1288,13 +1283,12 @@ async function pushRules(client, localRules, options = {}) {
|
|
|
1288
1283
|
}
|
|
1289
1284
|
if (!addOnly) {
|
|
1290
1285
|
const permsToUpdate = diff.permissions.filter((p) => p.type === "modified");
|
|
1291
|
-
for (
|
|
1292
|
-
const change = permsToUpdate[i];
|
|
1286
|
+
for (const [idx, change] of permsToUpdate.entries()) {
|
|
1293
1287
|
onProgress?.({
|
|
1294
1288
|
phase: "permissions",
|
|
1295
1289
|
action: "update",
|
|
1296
1290
|
name: change.name,
|
|
1297
|
-
current:
|
|
1291
|
+
current: idx + 1,
|
|
1298
1292
|
total: permsToUpdate.length
|
|
1299
1293
|
});
|
|
1300
1294
|
try {
|
|
@@ -1320,13 +1314,12 @@ async function pushRules(client, localRules, options = {}) {
|
|
|
1320
1314
|
}
|
|
1321
1315
|
if (!skipDeletes && !addOnly) {
|
|
1322
1316
|
const permsToDelete = diff.permissions.filter((p) => p.type === "removed");
|
|
1323
|
-
for (
|
|
1324
|
-
const change = permsToDelete[i];
|
|
1317
|
+
for (const [idx, change] of permsToDelete.entries()) {
|
|
1325
1318
|
onProgress?.({
|
|
1326
1319
|
phase: "permissions",
|
|
1327
1320
|
action: "delete",
|
|
1328
1321
|
name: change.name,
|
|
1329
|
-
current:
|
|
1322
|
+
current: idx + 1,
|
|
1330
1323
|
total: permsToDelete.length
|
|
1331
1324
|
});
|
|
1332
1325
|
try {
|
|
@@ -1342,13 +1335,12 @@ async function pushRules(client, localRules, options = {}) {
|
|
|
1342
1335
|
}
|
|
1343
1336
|
}
|
|
1344
1337
|
const rolesToDelete = diff.roles.filter((r) => r.type === "removed");
|
|
1345
|
-
for (
|
|
1346
|
-
const change = rolesToDelete[i];
|
|
1338
|
+
for (const [idx, change] of rolesToDelete.entries()) {
|
|
1347
1339
|
onProgress?.({
|
|
1348
1340
|
phase: "roles",
|
|
1349
1341
|
action: "delete",
|
|
1350
1342
|
name: change.name,
|
|
1351
|
-
current:
|
|
1343
|
+
current: idx + 1,
|
|
1352
1344
|
total: rolesToDelete.length
|
|
1353
1345
|
});
|
|
1354
1346
|
try {
|
|
@@ -1364,13 +1356,12 @@ async function pushRules(client, localRules, options = {}) {
|
|
|
1364
1356
|
}
|
|
1365
1357
|
}
|
|
1366
1358
|
const policiesToDelete = diff.policies.filter((p) => p.type === "removed");
|
|
1367
|
-
for (
|
|
1368
|
-
const change = policiesToDelete[i];
|
|
1359
|
+
for (const [idx, change] of policiesToDelete.entries()) {
|
|
1369
1360
|
onProgress?.({
|
|
1370
1361
|
phase: "policies",
|
|
1371
1362
|
action: "delete",
|
|
1372
1363
|
name: change.name,
|
|
1373
|
-
current:
|
|
1364
|
+
current: idx + 1,
|
|
1374
1365
|
total: policiesToDelete.length
|
|
1375
1366
|
});
|
|
1376
1367
|
try {
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-directus-sdk",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.0.0-beta.
|
|
4
|
+
"version": "6.0.0-beta.3",
|
|
5
5
|
"packageManager": "pnpm@10.32.1",
|
|
6
6
|
"description": "A Nuxt module for Directus with built-in authentication, realtime, file management, type generation, and visual editor support.",
|
|
7
7
|
"author": "Matthew Rollinson <matt@rolley.io>",
|
|
8
8
|
"license": "MIT",
|
|
9
|
-
"homepage": "https://nuxt-directus-sdk.
|
|
9
|
+
"homepage": "https://www.nuxt-directus-sdk.com",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
12
|
"url": "https://github.com/rolleyio/nuxt-directus-sdk"
|
|
@@ -84,11 +84,11 @@
|
|
|
84
84
|
"ufo": "^1.6.3"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
|
-
"@nuxt/eslint-config": "^1.15.2",
|
|
88
87
|
"@directus/sdk": "^21.2.2",
|
|
89
88
|
"@directus/types": "^15.0.2",
|
|
90
89
|
"@directus/visual-editing": "^2.0.0",
|
|
91
90
|
"@nuxt/devtools": "^3.2.4",
|
|
91
|
+
"@nuxt/eslint-config": "^1.15.2",
|
|
92
92
|
"@nuxt/image": "^2.0.0",
|
|
93
93
|
"@nuxt/module-builder": "^1.0.2",
|
|
94
94
|
"@nuxt/schema": "^4.4.2",
|
|
@@ -100,12 +100,15 @@
|
|
|
100
100
|
"typescript": "^6.0.3",
|
|
101
101
|
"vitepress": "^1.6.4",
|
|
102
102
|
"vitest": "^4.1.4",
|
|
103
|
-
"vue-tsc": "^3.
|
|
103
|
+
"vue-tsc": "^3.2.7"
|
|
104
104
|
},
|
|
105
105
|
"unbuild": {
|
|
106
106
|
"failOnWarn": false,
|
|
107
107
|
"externals": [
|
|
108
108
|
"consola/utils"
|
|
109
109
|
]
|
|
110
|
+
},
|
|
111
|
+
"engines": {
|
|
112
|
+
"node": ">=22.0.0"
|
|
110
113
|
}
|
|
111
114
|
}
|