@myco-dev/sdk 0.1.0 → 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 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 swr from 'swr';
6
- import { SWRResponse } from 'swr';
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
- interface UseRecordsResult<T> extends SWRResponse<T[]> {
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): swr.SWRResponse<TypedEntityRecord<TEntities[K]>, any, any>;
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 useSWR from "swr";
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 swrResult = useSWR(
224
- entitySlug ? ["records", entitySlug, page, queryOptions] : null,
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
- ...swrResult,
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 useSWR(
259
- entitySlug && recordId ? ["record", entitySlug, recordId] : null,
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
@@ -4,7 +4,7 @@ import { MycoSDKInstance } from './index.js';
4
4
  import 'better-auth';
5
5
  import '@better-fetch/fetch';
6
6
  import './types-D2J6kXGR.js';
7
- import 'swr';
7
+ import '@tanstack/react-query';
8
8
 
9
9
  interface AuthContextValue {
10
10
  isLoading: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myco-dev/sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -19,7 +19,8 @@
19
19
  }
20
20
  },
21
21
  "files": [
22
- "dist"
22
+ "dist",
23
+ "README.md"
23
24
  ],
24
25
  "scripts": {
25
26
  "build": "tsup src/index.ts src/server.ts src/react.tsx --format esm --dts",
@@ -28,12 +29,13 @@
28
29
  "peerDependencies": {
29
30
  "react": "^18 || ^19",
30
31
  "better-auth": "^1.4",
31
- "swr": "^2.4.0"
32
+ "@tanstack/react-query": "^5.0.0"
32
33
  },
33
34
  "dependencies": {
34
35
  "jose": "^5.0.0"
35
36
  },
36
37
  "devDependencies": {
38
+ "@tanstack/react-query": "^5.0.0",
37
39
  "@types/react": "^19.0.0",
38
40
  "tsup": "^8.0.0",
39
41
  "typescript": "^5.0.0"