@tanglemedia/svelte-starter-directus-api 7.0.0 → 9.0.0-next.0

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.
@@ -1,12 +1,10 @@
1
- import { type AllCollections, type DirectusClient, type RegularCollections, type RestClient } from '@directus/sdk';
2
- import { ApiAdapterAbstract, type AnyObject, type ApiAdapterHandle, type ApiAdapterRequestConfig, type ApiAggregateQuery, type ApiCreateManyQuery, type ApiDeleteManyQuery, type ApiFindQuery, type ApiId, type ApiResponse, type ApiUpdateManyQuery, type BaseApiMethods, type HandleEvent } from '@tanglemedia/svelte-starter-core';
3
- import type { DirectusConfig, SchemaShape } from '../types/adapter.types';
4
- export type AdapterClient<Schema extends SchemaShape = SchemaShape> = DirectusClient<Schema> & RestClient<Schema>;
5
- /**
6
- * TODO: Various types fixes. The current adapter doesn't correctly follow the types defined under the ApiAdapterAbstract.
7
- * See the fetch adapter under the core
8
- */
9
- export declare class DirectusApiAdapter<Schema extends SchemaShape = SchemaShape, Path extends RegularCollections<Schema> = RegularCollections<Schema>> extends ApiAdapterAbstract<DirectusConfig, ApiAdapterRequestConfig, Path, AdapterClient> implements ApiAdapterHandle {
1
+ import { type RegularCollections } from '@directus/sdk';
2
+ import { ApiAdapterAbstract, type AnyObject, type ApiAdapterHandle, type ApiAdapterRequestConfig, type ApiAggregateQuery, type ApiCreateManyQuery, type ApiDeleteManyQuery, type ApiFindQuery, type ApiId, type ApiPatchQuery, type ApiPostQuery, type ApiPutQuery, type ApiResponse, type ApiUpdateManyQuery, type BaseApiMethods, type HandleEvent } from '@tanglemedia/svelte-starter-core';
3
+ import type { DirectusAdapterClient, DirectusConfig, SchemaShape } from '../types/adapter.types';
4
+ type PathKey<Schema extends SchemaShape> = Extract<RegularCollections<Schema>, string>;
5
+ export type AdapterClient<Schema extends SchemaShape = SchemaShape> = DirectusAdapterClient<Schema>;
6
+ type Q = Record<string, unknown>;
7
+ export declare class DirectusApiAdapter<Schema extends SchemaShape = SchemaShape, Path extends PathKey<Schema> = PathKey<Schema>> extends ApiAdapterAbstract<DirectusConfig, ApiAdapterRequestConfig, Path, AdapterClient<Schema>> implements ApiAdapterHandle {
10
8
  protected config: DirectusConfig;
11
9
  private readonly directus;
12
10
  constructor(config: DirectusConfig, directus: AdapterClient<Schema>);
@@ -19,25 +17,30 @@ export declare class DirectusApiAdapter<Schema extends SchemaShape = SchemaShape
19
17
  total: number;
20
18
  displayed: number;
21
19
  };
22
- includeTotals(collection: AllCollections<Schema>, query?: ApiFindQuery<any>): Promise<number | null>;
20
+ includeTotals(collection: Path, query?: ApiFindQuery<any>): Promise<number | null>;
23
21
  transformResponse<T, M extends object = AnyObject>(res: {
24
22
  data: T;
25
23
  meta?: AnyObject;
26
- }, status?: number): Promise<ApiResponse<T, Response, M>>;
27
- getConfig(configuration?: unknown): DirectusConfig;
28
- normalizeQuery(config?: ApiAdapterRequestConfig, merge?: Record<string, unknown>): {
24
+ }, status?: number): Promise<ApiResponse<T, null, M>>;
25
+ normalizeQuery(config?: ApiAdapterRequestConfig, merge?: Q): {
29
26
  [x: string]: unknown;
30
27
  };
31
- request<T>(method: BaseApiMethods, url: string, query?: ApiAdapterRequestConfig): Promise<T>;
32
- find<T, Q = T, R = T>(collection: Path, query: ApiFindQuery<Q>, config?: ApiAdapterRequestConfig): Promise<ApiResponse<R[]>>;
33
- findOne<T>(collection: Path, key?: ApiId, query?: ApiAdapterRequestConfig): Promise<ApiResponse<T>>;
34
- aggregate<T, Q = T, R = T>(collection: Path, query: ApiAggregateQuery<Q>, config?: ApiAdapterRequestConfig): Promise<ApiResponse<R>>;
35
- patch<T>(collection: Path, key: ApiId, query?: Record<string, unknown>, config?: ApiAdapterRequestConfig): Promise<ApiResponse<T>>;
36
- post<T>(collection: Path, data: AnyObject, query?: Record<string, unknown>, config?: ApiAdapterRequestConfig): Promise<ApiResponse<T>>;
37
- delete<T>(collection: Path, key?: ApiId, config?: ApiAdapterRequestConfig): Promise<ApiResponse<T>>;
38
- put<T extends object, R = T>(collection: Path, key?: ApiId, payload?: AnyObject, query?: ApiAdapterRequestConfig): Promise<ApiResponse<R>>;
39
- upload<T>(path: string | undefined, data: FormData, config?: ApiAdapterRequestConfig): Promise<ApiResponse<T>>;
40
- createMany<T, R = T>(path: Path, body: ApiCreateManyQuery<T>, config?: ApiAdapterRequestConfig): Promise<ApiResponse<R[], Response, AnyObject>>;
41
- updateMany<T, R = T>(path: Path, body: ApiUpdateManyQuery<T>, config?: ApiAdapterRequestConfig): Promise<ApiResponse<R[], Response, AnyObject>>;
42
- deleteMany<R = null>(path: Path, body: ApiDeleteManyQuery<ApiId>, config?: ApiAdapterRequestConfig): Promise<ApiResponse<R, Response, AnyObject>>;
28
+ getId(data: object, config?: ApiAdapterRequestConfig): ApiId | null;
29
+ stripId(config?: ApiAdapterRequestConfig): ApiAdapterRequestConfig | undefined;
30
+ request<T, R = T>(method: BaseApiMethods, url: Path, query?: ApiAdapterRequestConfig): Promise<ApiResponse<R>>;
31
+ find<T, F = T, R = T>(collection: Path, query: ApiFindQuery<F>, config?: ApiAdapterRequestConfig): Promise<ApiResponse<R[]>>;
32
+ findOne<T, R = T>(collection: Path, key: ApiId, query?: ApiAdapterRequestConfig): Promise<ApiResponse<R>>;
33
+ aggregate<T, F = T, R = T>(collection: Path, query: ApiAggregateQuery<F>, config?: ApiAdapterRequestConfig): Promise<ApiResponse<R>>;
34
+ patch<T extends object, R = T>(collection: Path, key: ApiId, data: ApiPatchQuery<T>, config?: ApiAdapterRequestConfig): Promise<ApiResponse<R>>;
35
+ post<T extends object, R = T>(collection: Path, data: ApiPostQuery<T>, config?: ApiAdapterRequestConfig): Promise<ApiResponse<R>>;
36
+ delete<T, R = T>(collection: Path, key: ApiId, config?: ApiAdapterRequestConfig): Promise<ApiResponse<R>>;
37
+ put<T extends object, R = T>(collection: Path, data: ApiPutQuery<T>, config?: ApiAdapterRequestConfig): Promise<ApiResponse<R>>;
38
+ put<T extends object, R = T>(collection: Path, key: ApiId, data?: AnyObject, config?: ApiAdapterRequestConfig): Promise<ApiResponse<R>>;
39
+ upload<T, R = T>(path: Path, data: FormData, config?: ApiAdapterRequestConfig & {
40
+ method?: BaseApiMethods;
41
+ }): Promise<ApiResponse<R>>;
42
+ createMany<T, R = T>(path: Path, body: ApiCreateManyQuery<T>, config?: ApiAdapterRequestConfig): Promise<ApiResponse<R[]>>;
43
+ updateMany<T, R = T>(path: Path, body: ApiUpdateManyQuery<T>, config?: ApiAdapterRequestConfig): Promise<ApiResponse<R[]>>;
44
+ deleteMany<R>(path: Path, body: ApiDeleteManyQuery<ApiId>, config?: ApiAdapterRequestConfig): Promise<ApiResponse<R[]>>;
43
45
  }
46
+ export {};
@@ -16,10 +16,6 @@ const allowedQueryKeys = [
16
16
  'deep',
17
17
  'alias'
18
18
  ];
19
- /**
20
- * TODO: Various types fixes. The current adapter doesn't correctly follow the types defined under the ApiAdapterAbstract.
21
- * See the fetch adapter under the core
22
- */
23
19
  export class DirectusApiAdapter extends ApiAdapterAbstract {
24
20
  config;
25
21
  directus;
@@ -29,24 +25,18 @@ export class DirectusApiAdapter extends ApiAdapterAbstract {
29
25
  this.directus = directus;
30
26
  }
31
27
  async handle(event) {
32
- const f = event.fetch;
33
- this.directus.globals.fetch = f;
28
+ this.directus.globals.fetch = event.fetch;
34
29
  }
35
30
  getAdapterClient() {
36
31
  return this.directus;
37
32
  }
38
33
  normalizeMeta(response) {
39
34
  const payload = response.data, meta = response.meta;
40
- if (!meta) {
41
- return {};
42
- }
43
- if (typeof meta.total === 'undefined') {
35
+ if (!meta || typeof meta.total === 'undefined') {
44
36
  return {};
45
37
  }
46
38
  const displayed = Array.isArray(payload) ? payload.length : 0;
47
39
  const total = Number(meta.total);
48
- // todo: Transform or attempt to get meta information
49
- // consider pulling count based on existing filters in order to determine pagination
50
40
  return { total, displayed };
51
41
  }
52
42
  async includeTotals(collection, query) {
@@ -75,26 +65,16 @@ export class DirectusApiAdapter extends ApiAdapterAbstract {
75
65
  }
76
66
  async transformResponse(res, status = 200) {
77
67
  return {
78
- body: await this.envelopeResponse(res.data, (res.meta ? this.normalizeMeta(res) : {})),
79
- status: status,
68
+ body: (await this.envelopeResponse(res.data, (res.meta ? this.normalizeMeta(res) : {}))),
69
+ status,
80
70
  statusText: 'OK',
81
71
  headers: {},
82
72
  adapterResponse: null
83
73
  };
84
74
  }
85
- getConfig(configuration) {
86
- const client = this.directus;
87
- // Add the 'configuration' property to the returned object
88
- const config = {
89
- ...this.config,
90
- configuration: configuration ?? this.config.configuration ?? {} // Use the provided configuration or an empty object if not provided
91
- };
92
- return Object.assign(client, config);
93
- }
94
75
  normalizeQuery(config = {}, merge) {
95
76
  const q = { ...(config?.params || {}) };
96
77
  const c = { ...config };
97
- // legacy support, this pulls the directus specific keys from the config
98
78
  const r = allowedQueryKeys.reduce((acc, k) => (typeof c[k] !== 'undefined' ? ((acc[k] = c[k]), acc) : acc), {});
99
79
  return {
100
80
  ...q,
@@ -102,16 +82,46 @@ export class DirectusApiAdapter extends ApiAdapterAbstract {
102
82
  ...(merge || {})
103
83
  };
104
84
  }
85
+ getId(data, config) {
86
+ const d = data;
87
+ const q = config?.params;
88
+ if (typeof d.id === 'string' || typeof d.id === 'number') {
89
+ return d.id;
90
+ }
91
+ if (q && (typeof q.id === 'string' || typeof q.id === 'number')) {
92
+ return q.id;
93
+ }
94
+ return null;
95
+ }
96
+ stripId(config) {
97
+ const q = config?.params;
98
+ if (!q || typeof q.id === 'undefined') {
99
+ return config;
100
+ }
101
+ const { id: _id, ...params } = q;
102
+ return {
103
+ ...config,
104
+ params
105
+ };
106
+ }
105
107
  async request(method, url, query) {
106
108
  try {
107
- const response = await this.directus.request(() => {
108
- const params = JSON.stringify(query);
109
- return {
110
- path: `${url}?${params}`,
111
- method: method
112
- };
113
- });
114
- return response;
109
+ const { body, headers } = query || {};
110
+ const params = this.normalizeQuery(query);
111
+ const data = await this.directus.request((() => ({
112
+ path: url,
113
+ method,
114
+ headers,
115
+ params,
116
+ ...(typeof body === 'undefined'
117
+ ? {}
118
+ : {
119
+ body: body instanceof FormData || typeof body === 'string'
120
+ ? body
121
+ : JSON.stringify(body)
122
+ })
123
+ })));
124
+ return this.transformResponse({ data }, method === 'POST' ? 201 : method === 'DELETE' ? 202 : 200);
115
125
  }
116
126
  catch (error) {
117
127
  console.error(`Error request:`, error);
@@ -119,72 +129,82 @@ export class DirectusApiAdapter extends ApiAdapterAbstract {
119
129
  }
120
130
  }
121
131
  async find(collection, query, config) {
122
- query = this.normalizeQuery(config, query);
123
- const response = (await this.directus.request(readItems(collection, query)));
132
+ const q = this.normalizeQuery(config, query);
133
+ const data = await this.directus.request(readItems(collection, q));
124
134
  const total = await this.includeTotals(collection, query);
125
135
  if (null === total) {
126
- return this.transformResponse({ data: response });
136
+ return this.transformResponse({ data });
127
137
  }
128
- // console.log('find meta', response, total)
129
- return this.transformResponse({ data: response, meta: { total } });
138
+ return this.transformResponse({ data, meta: { total } });
130
139
  }
131
140
  async findOne(collection, key, query) {
132
141
  const q = this.normalizeQuery(query);
133
- const data = await this.directus.request(readItem(collection, key, query));
142
+ const data = await this.directus.request(readItem(collection, key, q));
134
143
  return this.transformResponse({ data });
135
144
  }
136
145
  async aggregate(collection, query, config) {
137
- const { aggregate: aggregate_, ...rest } = this.normalizeQuery(config, query);
146
+ const { aggregate: a, ...rest } = this.normalizeQuery(config, query);
138
147
  const data = await this.directus.request(aggregate(collection, {
139
- aggregate: aggregate_
140
- ? aggregate_
141
- : {
142
- count: 'id'
143
- },
148
+ aggregate: a ? a : { count: 'id' },
144
149
  query: rest
145
150
  }));
146
151
  return this.transformResponse({ data });
147
152
  }
148
- async patch(collection, key, query, config) {
149
- const data = await this.directus.request(updateItem(collection, key, query));
150
- return this.transformResponse({ data });
153
+ async patch(collection, key, data, config) {
154
+ const q = this.normalizeQuery(config);
155
+ const res = await this.directus.request(updateItem(collection, key, data, q));
156
+ return this.transformResponse({ data: res });
151
157
  }
152
- async post(collection, data, query, config) {
153
- const response = await this.directus.request(createItem(collection, data, query));
154
- return this.transformResponse({ data: response }, 201);
158
+ async post(collection, data, config) {
159
+ const q = this.normalizeQuery(config);
160
+ const res = await this.directus.request(createItem(collection, data, q));
161
+ return this.transformResponse({ data: res }, 201);
155
162
  }
156
163
  async delete(collection, key, config) {
164
+ void config;
157
165
  const data = await this.directus.request(deleteItem(collection, key));
158
166
  return this.transformResponse({ data }, 202);
159
167
  }
160
- async put(collection, key, payload, query) {
161
- if (key) {
162
- const data = (await this.directus.request(updateItem(collection, key, payload, query)));
163
- return this.transformResponse({ data }, 201);
164
- }
165
- else {
166
- console.error(`Error updating all ${collection}: no key specified`);
168
+ async put(collection, keyOrData, dataOrConfig, config) {
169
+ const key = typeof keyOrData === 'string' || typeof keyOrData === 'number'
170
+ ? keyOrData
171
+ : this.getId(keyOrData, dataOrConfig);
172
+ const data = typeof keyOrData === 'string' || typeof keyOrData === 'number'
173
+ ? dataOrConfig
174
+ : keyOrData;
175
+ const q = typeof keyOrData === 'string' || typeof keyOrData === 'number'
176
+ ? config
177
+ : dataOrConfig;
178
+ if (!key) {
167
179
  throw new Error('No key specified');
168
180
  }
181
+ const res = await this.directus.request(updateItem(collection, key, data, this.normalizeQuery(this.stripId(q))));
182
+ return this.transformResponse({ data: res }, 201);
169
183
  }
170
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
171
- async upload(path = '', data, config) {
172
- const response = await this.directus.request(uploadFiles(data));
173
- return this.transformResponse({ data: response }, 201);
184
+ async upload(path, data, config) {
185
+ void path;
186
+ void config;
187
+ const res = await this.directus.request(uploadFiles(data));
188
+ return this.transformResponse({ data: res }, 201);
174
189
  }
175
190
  async createMany(path, body, config) {
176
- const data = await this.directus.request(createItems(path, body.data, body?.query));
191
+ const q = this.normalizeQuery(config, body.query || {});
192
+ const data = await this.directus.request(createItems(path, body.data, q));
177
193
  return this.transformResponse({ data }, 200);
178
194
  }
179
195
  async updateMany(path, body, config) {
180
196
  if (!body.ids) {
181
197
  throw Error('You must provide an array of keys to update');
182
198
  }
183
- const data = await this.directus.request(updateItems(path, body.ids || [], body.data, body?.query));
199
+ const q = this.normalizeQuery(config, body.query || {});
200
+ const ids = body.ids;
201
+ const data = await this.directus.request(updateItems(path, ids, body.data, q));
184
202
  return this.transformResponse({ data }, 200);
185
203
  }
186
204
  async deleteMany(path, body, config) {
187
- const data = await this.directus.request(deleteItems(path, body.ids));
205
+ void config;
206
+ const ids = body.ids;
207
+ const data = await this.directus.request(deleteItems(path, ids));
188
208
  return this.transformResponse({ data }, 201);
189
209
  }
190
210
  }
@@ -1,7 +1,7 @@
1
- import type { AdapterProviderRegister, ApiAdapterInterface, ApiAdapterProviderInterface } from '@tanglemedia/svelte-starter-core';
2
- import type { DirectusConfig } from '../types/adapter.types';
1
+ import type { AdapterProviderRegister, ApiAdapterRequestConfig, ApiAdapterInterface, ApiAdapterProviderInterface } from '@tanglemedia/svelte-starter-core';
2
+ import type { DirectusAdapterClient, DirectusConfig, SchemaShape } from '../types/adapter.types';
3
3
  export declare class DirectusApiProvider implements ApiAdapterProviderInterface<DirectusConfig> {
4
- loadAdapter(key?: string, config?: DirectusConfig): Promise<ApiAdapterInterface<DirectusConfig>>;
5
- createDirectusClient<T extends object>(config: DirectusConfig): import("@directus/sdk").DirectusClient<T> & import("@directus/sdk").RestClient<T>;
4
+ loadAdapter(key?: string, config?: DirectusConfig): Promise<ApiAdapterInterface<DirectusConfig, ApiAdapterRequestConfig, string, DirectusAdapterClient<SchemaShape>>>;
5
+ createDirectusClient<T extends SchemaShape>(config: DirectusConfig): DirectusAdapterClient<T>;
6
6
  }
7
7
  export declare const registerDirectusProvider: () => AdapterProviderRegister;
@@ -1 +1,10 @@
1
- export * from '@directus/sdk';
1
+ export { authentication, createDirectus, memoryStorage, rest, staticToken } from '@directus/sdk';
2
+ export { login, logout, passwordRequest, passwordReset, readProviders, refresh, } from '@directus/sdk';
3
+ export { createCollection, createComment, createComments, createContentVersion, createContentVersions, createDashboard, createDashboards, createField, createFlow, createFlows, createFolder, createFolders, createItem, createItems, createNotification, createNotifications, createOperation, createOperations, createPanel, createPanels, createPermission, createPermissions, createPolicies, createPolicy, createPreset, createPresets, createRelation, createRole, createRoles, createShare, createShares, createTranslation, createTranslations, createUser, createUsers, importFile, uploadFiles, } from '@directus/sdk';
4
+ export { aggregate, downloadFilesZip, downloadFolderZip, readActivities, readActivity, readAssetArrayBuffer, readAssetBlob, readAssetRaw, readCollection, readCollections, readComment, readComments, readContentVersion, readContentVersions, readDashboard, readDashboards, readExtensions, readField, readFields, readFieldsByCollection, readFile, readFiles, readFlow, readFlows, readFolder, readFolders, readGraphqlSdl, readItem, readItemPermissions, readItems, readMe, readNotification, readNotifications, readOpenApiSpec, readOperation, readOperations, readPanel, readPanels, readPermission, readPermissions, readPolicies, readPolicy, readPolicyGlobals, readPreset, readPresets, readRelation, readRelationByCollection, readRelations, readRevision, readRevisions, readRole, readRoles, readRolesMe, readSettings, readShare, readShareInfo, readShares, readSingleton, readTranslation, readTranslations, readUser, readUserPermissions, readUsers, } from '@directus/sdk';
5
+ export { updateCollection, updateCollectionsBatch, updateComment, updateComments, updateCommentsBatch, updateContentVersion, updateContentVersions, updateContentVersionsBatch, updateDashboard, updateDashboards, updateDashboardsBatch, updateExtension, updateField, updateFields, updateFile, updateFiles, updateFilesBatch, updateFlow, updateFlows, updateFlowsBatch, updateFolder, updateFolders, updateFoldersBatch, updateItem, updateItems, updateItemsBatch, updateMe, updateNotification, updateNotifications, updateNotificationsBatch, updateOperation, updateOperations, updateOperationsBatch, updatePanel, updatePanels, updatePanelsBatch, updatePermission, updatePermissions, updatePermissionsBatch, updatePolicies, updatePoliciesBatch, updatePolicy, updatePreset, updatePresets, updatePresetsBatch, updateRelation, updateRole, updateRoles, updateRolesBatch, updateSettings, updateShare, updateShares, updateSharesBatch, updateSingleton, updateTranslation, updateTranslations, updateTranslationsBatch, updateUser, updateUsers, updateUsersBatch, } from '@directus/sdk';
6
+ export { deleteCollection, deleteComment, deleteComments, deleteContentVersion, deleteContentVersions, deleteDashboard, deleteDashboards, deleteField, deleteFile, deleteFiles, deleteFlow, deleteFlows, deleteFolder, deleteFolders, deleteItem, deleteItems, deleteNotification, deleteNotifications, deleteOperation, deleteOperations, deletePanel, deletePanels, deletePermission, deletePermissions, deletePolicies, deletePolicy, deletePreset, deletePresets, deleteRelation, deleteRole, deleteRoles, deleteShare, deleteShares, deleteTranslation, deleteTranslations, deleteUser, deleteUsers, } from '@directus/sdk';
7
+ export { schemaApply, schemaDiff, schemaSnapshot } from '@directus/sdk';
8
+ export { serverHealth, serverInfo, serverPing } from '@directus/sdk';
9
+ export { acceptUserInvite, authenticateShare, clearCache, compareContentVersion, customEndpoint, disableTwoFactor, enableTwoFactor, generateHash, generateTwoFactorSecret, inviteShare, inviteUser, isDirectusError, promoteContentVersion, randomString, registerUser, registerUserVerify, saveToContentVersion, triggerFlow, utilitySort, utilsExport, utilsImport, verifyHash, withOptions, withSearch, withToken, } from '@directus/sdk';
10
+ export type { DirectusClient, RestClient, RestCommand } from '@directus/sdk';
@@ -1 +1,18 @@
1
- export * from '@directus/sdk';
1
+ // Client setup
2
+ export { authentication, createDirectus, memoryStorage, rest, staticToken } from '@directus/sdk';
3
+ // Auth commands
4
+ export { login, logout, passwordRequest, passwordReset, readProviders, refresh, } from '@directus/sdk';
5
+ // Create commands
6
+ export { createCollection, createComment, createComments, createContentVersion, createContentVersions, createDashboard, createDashboards, createField, createFlow, createFlows, createFolder, createFolders, createItem, createItems, createNotification, createNotifications, createOperation, createOperations, createPanel, createPanels, createPermission, createPermissions, createPolicies, createPolicy, createPreset, createPresets, createRelation, createRole, createRoles, createShare, createShares, createTranslation, createTranslations, createUser, createUsers, importFile, uploadFiles, } from '@directus/sdk';
7
+ // Read commands
8
+ export { aggregate, downloadFilesZip, downloadFolderZip, readActivities, readActivity, readAssetArrayBuffer, readAssetBlob, readAssetRaw, readCollection, readCollections, readComment, readComments, readContentVersion, readContentVersions, readDashboard, readDashboards, readExtensions, readField, readFields, readFieldsByCollection, readFile, readFiles, readFlow, readFlows, readFolder, readFolders, readGraphqlSdl, readItem, readItemPermissions, readItems, readMe, readNotification, readNotifications, readOpenApiSpec, readOperation, readOperations, readPanel, readPanels, readPermission, readPermissions, readPolicies, readPolicy, readPolicyGlobals, readPreset, readPresets, readRelation, readRelationByCollection, readRelations, readRevision, readRevisions, readRole, readRoles, readRolesMe, readSettings, readShare, readShareInfo, readShares, readSingleton, readTranslation, readTranslations, readUser, readUserPermissions, readUsers, } from '@directus/sdk';
9
+ // Update commands
10
+ export { updateCollection, updateCollectionsBatch, updateComment, updateComments, updateCommentsBatch, updateContentVersion, updateContentVersions, updateContentVersionsBatch, updateDashboard, updateDashboards, updateDashboardsBatch, updateExtension, updateField, updateFields, updateFile, updateFiles, updateFilesBatch, updateFlow, updateFlows, updateFlowsBatch, updateFolder, updateFolders, updateFoldersBatch, updateItem, updateItems, updateItemsBatch, updateMe, updateNotification, updateNotifications, updateNotificationsBatch, updateOperation, updateOperations, updateOperationsBatch, updatePanel, updatePanels, updatePanelsBatch, updatePermission, updatePermissions, updatePermissionsBatch, updatePolicies, updatePoliciesBatch, updatePolicy, updatePreset, updatePresets, updatePresetsBatch, updateRelation, updateRole, updateRoles, updateRolesBatch, updateSettings, updateShare, updateShares, updateSharesBatch, updateSingleton, updateTranslation, updateTranslations, updateTranslationsBatch, updateUser, updateUsers, updateUsersBatch, } from '@directus/sdk';
11
+ // Delete commands
12
+ export { deleteCollection, deleteComment, deleteComments, deleteContentVersion, deleteContentVersions, deleteDashboard, deleteDashboards, deleteField, deleteFile, deleteFiles, deleteFlow, deleteFlows, deleteFolder, deleteFolders, deleteItem, deleteItems, deleteNotification, deleteNotifications, deleteOperation, deleteOperations, deletePanel, deletePanels, deletePermission, deletePermissions, deletePolicies, deletePolicy, deletePreset, deletePresets, deleteRelation, deleteRole, deleteRoles, deleteShare, deleteShares, deleteTranslation, deleteTranslations, deleteUser, deleteUsers, } from '@directus/sdk';
13
+ // Schema commands
14
+ export { schemaApply, schemaDiff, schemaSnapshot } from '@directus/sdk';
15
+ // Server commands
16
+ export { serverHealth, serverInfo, serverPing } from '@directus/sdk';
17
+ // Utility functions
18
+ export { acceptUserInvite, authenticateShare, clearCache, compareContentVersion, customEndpoint, disableTwoFactor, enableTwoFactor, generateHash, generateTwoFactorSecret, inviteShare, inviteUser, isDirectusError, promoteContentVersion, randomString, registerUser, registerUserVerify, saveToContentVersion, triggerFlow, utilitySort, utilsExport, utilsImport, verifyHash, withOptions, withSearch, withToken, } from '@directus/sdk';
@@ -1,6 +1,6 @@
1
1
  import { type ClientOptions } from '@directus/sdk';
2
- import type { DirectusConfig } from '../types/adapter.types';
2
+ import type { DirectusAdapterClient, DirectusConfig, SchemaShape } from '../types/adapter.types';
3
3
  /**
4
4
  * Creates a directus client based on the application configuration
5
5
  */
6
- export declare const createDirectusClientFactory: <T extends object>({ baseUrl, configuration: { protocol, host, auth, staticToken: token, graphql: gql, rest: rs } }: DirectusConfig, options?: ClientOptions) => import("@directus/sdk").DirectusClient<T> & import("@directus/sdk").RestClient<T>;
6
+ export declare const createDirectusClientFactory: <T extends SchemaShape>({ baseUrl, configuration: { protocol, host, auth, staticToken: token, graphql: gql, rest: rs } }: DirectusConfig, options?: ClientOptions) => DirectusAdapterClient<T>;
@@ -1,7 +1,8 @@
1
- import type { AuthenticationClient, DirectusClient, RestClient } from '@directus/sdk';
2
1
  import { ServiceAbstract } from '@tanglemedia/svelte-starter-core';
2
+ import type { DirectusAdapterClient, SchemaShape } from '../types';
3
3
  declare class DirectusAuthServices extends ServiceAbstract {
4
- getDirectus(): Promise<DirectusClient<object> & RestClient<object> & AuthenticationClient<object>>;
4
+ getDirectus(): Promise<DirectusAdapterClient<SchemaShape>>;
5
+ private getAuthenticatedDirectus;
5
6
  refresh(): Promise<import("@directus/sdk").AuthenticationData>;
6
7
  getToken(): Promise<string | null>;
7
8
  login(email: string, password: string): Promise<import("@directus/sdk").AuthenticationData>;
@@ -4,12 +4,19 @@ class DirectusAuthServices extends ServiceAbstract {
4
4
  getDirectus() {
5
5
  return this.getAdapterClient();
6
6
  }
7
+ async getAuthenticatedDirectus() {
8
+ const directus = await this.getDirectus();
9
+ if (!directus.refresh || !directus.getToken || !directus.login || !directus.logout) {
10
+ throw new Error('Directus client is missing authentication methods');
11
+ }
12
+ return directus;
13
+ }
7
14
  // public getConfig<T extends object>(): DirectusClient<T> & RestClient<object> {
8
15
  // return this.directus as DirectusClient<T> & RestClient<object>;
9
16
  // }
10
17
  async refresh() {
11
18
  try {
12
- const response = await (await this.getDirectus()).refresh();
19
+ const response = await (await this.getAuthenticatedDirectus()).refresh();
13
20
  return response;
14
21
  }
15
22
  catch (error) {
@@ -19,7 +26,7 @@ class DirectusAuthServices extends ServiceAbstract {
19
26
  }
20
27
  async getToken() {
21
28
  try {
22
- const response = await (await this.getDirectus()).getToken();
29
+ const response = await (await this.getAuthenticatedDirectus()).getToken();
23
30
  return response;
24
31
  }
25
32
  catch (error) {
@@ -29,7 +36,7 @@ class DirectusAuthServices extends ServiceAbstract {
29
36
  }
30
37
  async login(email, password) {
31
38
  try {
32
- const response = await (await this.getDirectus()).login(email, password);
39
+ const response = await (await this.getAuthenticatedDirectus()).login({ email, password });
33
40
  return response;
34
41
  }
35
42
  catch (error) {
@@ -39,7 +46,7 @@ class DirectusAuthServices extends ServiceAbstract {
39
46
  }
40
47
  async logout() {
41
48
  try {
42
- const response = await (await this.getDirectus()).logout();
49
+ const response = await (await this.getAuthenticatedDirectus()).logout();
43
50
  return response;
44
51
  }
45
52
  catch (error) {
@@ -51,7 +58,8 @@ class DirectusAuthServices extends ServiceAbstract {
51
58
  try {
52
59
  if (!(await this.getToken()))
53
60
  await this.refresh();
54
- const response = await (await this.getDirectus()).request(readMe({ fields: fields ? fields : ['*', 'roles.*'] }));
61
+ const queryFields = (fields ?? ['*', 'roles.*']);
62
+ const response = await (await this.getDirectus()).request(readMe({ fields: queryFields }));
55
63
  return response;
56
64
  }
57
65
  catch (error) {
@@ -1,6 +1,7 @@
1
- import type { AuthenticationMode, GraphqlConfig } from '@directus/sdk';
1
+ import type { AuthenticationClient, AuthenticationMode, DirectusClient, GraphqlClient, GraphqlConfig, RestClient, StaticTokenClient } from '@directus/sdk';
2
2
  import type { BaseApiAdapterConfig } from '@tanglemedia/svelte-starter-core';
3
- export { type AllCollections, type DirectusClient, type RegularCollections, type RestClient, type StaticTokenClient, type AuthenticationClient } from '@directus/sdk';
3
+ export type { AllCollections, RegularCollections, DirectusClient, RestClient, StaticTokenClient, AuthenticationClient } from '@directus/sdk';
4
+ export type * from '@directus/types';
4
5
  export type DirectusApiAuthOptions = {
5
6
  mode: AuthenticationMode;
6
7
  config?: Partial<{
@@ -24,4 +25,5 @@ export type DirectusApiAdapterOptions = {
24
25
  totalField?: string;
25
26
  };
26
27
  export type DirectusConfig = BaseApiAdapterConfig<DirectusApiAdapterOptions>;
27
- export type SchemaShape = Record<string, object>;
28
+ export type SchemaShape = Record<string, object | object[]>;
29
+ export type DirectusAdapterClient<Schema extends SchemaShape = SchemaShape> = DirectusClient<Schema> & RestClient<Schema> & Partial<AuthenticationClient<Schema>> & Partial<StaticTokenClient<Schema>> & Partial<GraphqlClient<Schema>>;
@@ -1 +1 @@
1
- export {} from '@directus/sdk';
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanglemedia/svelte-starter-directus-api",
3
- "version": "7.0.0",
3
+ "version": "9.0.0-next.0",
4
4
  "main": "src/index.ts",
5
5
  "types": "src/index.ts",
6
6
  "description": "directus API wrapper for all the directus sdk functionality",
@@ -22,31 +22,31 @@
22
22
  }
23
23
  },
24
24
  "devDependencies": {
25
- "@directus/types": "13.5.0",
26
- "@sveltejs/adapter-auto": "^7.0.0",
25
+ "@directus/types": "15.0.1",
26
+ "@sveltejs/adapter-auto": "^7.0.1",
27
27
  "@sveltejs/package": "^2.5.7",
28
- "@sveltejs/vite-plugin-svelte": "^6.2.1",
28
+ "@sveltejs/vite-plugin-svelte": "^7.0.0",
29
29
  "@testing-library/jest-dom": "^6.6.3",
30
30
  "@testing-library/svelte": "^5.2.7",
31
31
  "@vitest/coverage-v8": "^3.0.8",
32
32
  "jsdom": "^26.0.0",
33
33
  "msw": "^2.7.3",
34
- "svelte": "^5.46.1",
35
- "svelte-check": "^4.3.5",
36
- "vite": "^7.3.0",
37
- "vitest": "^4.0.16",
34
+ "svelte": "^5.55.3",
35
+ "svelte-check": "^4.4.6",
36
+ "vite": "^8.0.8",
37
+ "vitest": "^4.1.4",
38
38
  "@internal/eslint-config": "0.0.0",
39
- "@tanglemedia/svelte-starter-core": "3.0.0"
39
+ "@tanglemedia/svelte-starter-core": "4.0.0-next.0"
40
40
  },
41
41
  "dependencies": {
42
- "@directus/sdk": "20.3.0",
42
+ "@directus/sdk": "21.2.2",
43
43
  "@types/js-cookie": "^3.0.6",
44
44
  "esm-env": "^1.2.2",
45
45
  "js-cookie": "^3.0.5"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "@sveltejs/kit": ">=2 <3",
49
- "@tanglemedia/svelte-starter-core": ">=3.0.0",
49
+ "@tanglemedia/svelte-starter-core": ">=4.0.0-next.0",
50
50
  "svelte": "^4.0.0 || >=5.0.0"
51
51
  },
52
52
  "scripts": {