@meeovi/directus-client 1.0.4 → 1.0.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meeovi/directus-client",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "Directus Client Library with auto generating forms and tables, Directus SDK and Types, and vue/react components for Directus Visual Editing.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -15,9 +15,18 @@
15
15
  "test": "echo \"Error: no test specified\" && exit 1",
16
16
  "build": "tsc -p tsconfig.json"
17
17
  },
18
- "keywords": [],
19
- "author": "",
20
- "license": "ISC",
18
+ "keywords": [
19
+ "directus",
20
+ "directus-sdk",
21
+ "directus-types",
22
+ "directus-visual-editing",
23
+ "directus-client",
24
+ "vue",
25
+ "react",
26
+ "typescript"
27
+ ],
28
+ "author": "Meeovi",
29
+ "license": "MIT",
21
30
  "type": "module",
22
31
  "dependencies": {
23
32
  "@directus/sdk": "^18.0.3",
@@ -9,13 +9,13 @@ import {
9
9
  deleteItem,
10
10
  uploadFiles,
11
11
  readSingleton,
12
- readFieldsByCollection,
13
- type DirectusClient
12
+ readFieldsByCollection
14
13
  } from '@directus/sdk';
14
+ import type { RestClient } from '@directus/sdk';
15
15
 
16
16
  export interface MeeoviDirectusClient<Schema> {
17
- client: DirectusClient<Schema>;
18
- request: any;
17
+ client: RestClient<Schema>;
18
+ request: RestClient<Schema>['request'];
19
19
  readItem: typeof readItem;
20
20
  readItems: typeof readItems;
21
21
  createItem: typeof createItem;
@@ -43,4 +43,4 @@ export function createMeeoviDirectusClient<Schema>(url: string): MeeoviDirectusC
43
43
  readSingleton,
44
44
  readFieldsByCollection
45
45
  };
46
- }
46
+ }
@@ -1,11 +1,45 @@
1
1
  import type { DirectusField } from '../schema/types';
2
2
 
3
- export function generateTableSchema(fields: DirectusField[]) {
3
+ export interface TableColumn {
4
+ key: string;
5
+ label: string;
6
+ type: string;
7
+ sortable?: boolean;
8
+ hidden?: boolean;
9
+ }
10
+
11
+ /**
12
+ * Convert Directus fields into a table schema.
13
+ */
14
+ export function generateTableSchema(fields: DirectusField[]): TableColumn[] {
4
15
  return fields
5
- .filter(f => !f.hidden)
6
- .map(f => ({
16
+ .filter((f) => !f.hidden)
17
+ .map((f) => ({
7
18
  key: f.field,
8
- label: f.field.replace(/_/g, ' ').replace(/\b\w/g, c => c.toUpperCase()),
9
- type: f.type
19
+ label: prettifyLabel(f.field),
20
+ type: f.type,
21
+ sortable: true,
22
+ hidden: false
10
23
  }));
11
24
  }
25
+
26
+ /**
27
+ * Convert "product_name" → "Product Name"
28
+ */
29
+ function prettifyLabel(str: string): string {
30
+ return str
31
+ .replace(/_/g, ' ')
32
+ .replace(/\b\w/g, (c) => c.toUpperCase());
33
+ }
34
+
35
+ /**
36
+ * Fetch table rows from Directus.
37
+ */
38
+ export async function fetchTableRows(
39
+ directus: any,
40
+ collection: string
41
+ ): Promise<any[]> {
42
+ return await directus.request(
43
+ directus.readItems(collection)
44
+ );
45
+ }