@myco-dev/sdk 0.1.1 → 0.1.2
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/index.d.ts +5 -5
- package/dist/index.js +14 -12
- package/dist/react.d.ts +1 -1
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import * as better_auth from 'better-auth';
|
|
|
2
2
|
import * as _better_fetch_fetch from '@better-fetch/fetch';
|
|
3
3
|
import { M as MycoSDKConfig, W as Workspace, a as WorkspaceMember, G as GetRecordsOptions, E as Entity, P as PaginatedResponse, b as EntityRecord } from './types-D2J6kXGR.js';
|
|
4
4
|
export { c as EntityField, J as JoinResponse, V as VerifiedUser } from './types-D2J6kXGR.js';
|
|
5
|
-
import * as
|
|
6
|
-
import {
|
|
5
|
+
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
6
|
+
import { UseQueryResult } from '@tanstack/react-query';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Create auth namespace bound to the given config.
|
|
@@ -144,14 +144,14 @@ interface UseRecordsOptions extends Omit<GetRecordsOptions, "page"> {
|
|
|
144
144
|
initialPage?: number;
|
|
145
145
|
onPageChange?: (page: number) => void;
|
|
146
146
|
}
|
|
147
|
-
|
|
147
|
+
type UseRecordsResult<T> = UseQueryResult<T[]> & {
|
|
148
148
|
page: number;
|
|
149
149
|
hasNextPage: boolean;
|
|
150
150
|
hasPreviousPage: boolean;
|
|
151
151
|
nextPage: () => void;
|
|
152
152
|
previousPage: () => void;
|
|
153
153
|
setPage: (page: number) => void;
|
|
154
|
-
}
|
|
154
|
+
};
|
|
155
155
|
|
|
156
156
|
type ApiRequest = <T>(path: string, options?: RequestInit) => Promise<T>;
|
|
157
157
|
/**
|
|
@@ -198,7 +198,7 @@ declare function createData<TEntities extends Record<string, unknown>>(apiReques
|
|
|
198
198
|
*/
|
|
199
199
|
batchGetRecords<K extends keyof TEntities & string>(entitySlug: K, ids: string[]): Promise<TypedEntityRecord<TEntities[K]>[]>;
|
|
200
200
|
useRecords<K extends keyof TEntities & string>(entitySlug: K | null | undefined, options?: UseRecordsOptions): UseRecordsResult<TypedEntityRecord<TEntities[K]>>;
|
|
201
|
-
useRecord<K extends keyof TEntities & string>(entitySlug: K | null | undefined, recordId: string | null | undefined):
|
|
201
|
+
useRecord<K extends keyof TEntities & string>(entitySlug: K | null | undefined, recordId: string | null | undefined): _tanstack_react_query.UseQueryResult<TypedEntityRecord<TEntities[K]>>;
|
|
202
202
|
};
|
|
203
203
|
type Data<TEntities extends Record<string, unknown>> = ReturnType<typeof createData<TEntities>>;
|
|
204
204
|
|
package/dist/index.js
CHANGED
|
@@ -195,7 +195,7 @@ function createWorkspaces(getConfig, setWorkspaceId, apiRequest, ensureWorkspace
|
|
|
195
195
|
|
|
196
196
|
// src/hooks/records.ts
|
|
197
197
|
import { useState, useCallback } from "react";
|
|
198
|
-
import
|
|
198
|
+
import { useQuery } from "@tanstack/react-query";
|
|
199
199
|
function createRecordsHooks(apiRequest) {
|
|
200
200
|
return {
|
|
201
201
|
useRecords(entitySlug, options) {
|
|
@@ -220,9 +220,9 @@ function createRecordsHooks(apiRequest) {
|
|
|
220
220
|
setPage(page - 1);
|
|
221
221
|
}
|
|
222
222
|
}, [page, setPage]);
|
|
223
|
-
const
|
|
224
|
-
entitySlug ? ["records", entitySlug, page, queryOptions] :
|
|
225
|
-
async () => {
|
|
223
|
+
const queryResult = useQuery({
|
|
224
|
+
queryKey: entitySlug ? ["records", entitySlug, page, queryOptions] : [],
|
|
225
|
+
queryFn: async () => {
|
|
226
226
|
const params = new URLSearchParams();
|
|
227
227
|
params.set("page", String(page));
|
|
228
228
|
if (queryOptions?.pageSize !== void 0) {
|
|
@@ -242,10 +242,11 @@ function createRecordsHooks(apiRequest) {
|
|
|
242
242
|
const response = await apiRequest(path);
|
|
243
243
|
setHasNextPage(response.pagination.hasMore);
|
|
244
244
|
return response.records;
|
|
245
|
-
}
|
|
246
|
-
|
|
245
|
+
},
|
|
246
|
+
enabled: !!entitySlug
|
|
247
|
+
});
|
|
247
248
|
return {
|
|
248
|
-
...
|
|
249
|
+
...queryResult,
|
|
249
250
|
page,
|
|
250
251
|
hasNextPage,
|
|
251
252
|
hasPreviousPage: page > 1,
|
|
@@ -255,15 +256,16 @@ function createRecordsHooks(apiRequest) {
|
|
|
255
256
|
};
|
|
256
257
|
},
|
|
257
258
|
useRecord(entitySlug, recordId) {
|
|
258
|
-
return
|
|
259
|
-
entitySlug && recordId ? ["record", entitySlug, recordId] :
|
|
260
|
-
async () => {
|
|
259
|
+
return useQuery({
|
|
260
|
+
queryKey: entitySlug && recordId ? ["record", entitySlug, recordId] : [],
|
|
261
|
+
queryFn: async () => {
|
|
261
262
|
const response = await apiRequest(
|
|
262
263
|
`/api/entities/${entitySlug}/records/${recordId}`
|
|
263
264
|
);
|
|
264
265
|
return response;
|
|
265
|
-
}
|
|
266
|
-
|
|
266
|
+
},
|
|
267
|
+
enabled: !!entitySlug && !!recordId
|
|
268
|
+
});
|
|
267
269
|
}
|
|
268
270
|
};
|
|
269
271
|
}
|
package/dist/react.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@myco-dev/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -29,12 +29,13 @@
|
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"react": "^18 || ^19",
|
|
31
31
|
"better-auth": "^1.4",
|
|
32
|
-
"
|
|
32
|
+
"@tanstack/react-query": "^5.0.0"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"jose": "^5.0.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
+
"@tanstack/react-query": "^5.0.0",
|
|
38
39
|
"@types/react": "^19.0.0",
|
|
39
40
|
"tsup": "^8.0.0",
|
|
40
41
|
"typescript": "^5.0.0"
|