@data-client/rest 0.7.5 → 0.8.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.
Files changed (77) hide show
  1. package/dist/index.js +21 -79
  2. package/dist/index.umd.min.js +1 -1
  3. package/dist/next.js +0 -566
  4. package/legacy/NetworkError.js +2 -2
  5. package/legacy/RestEndpoint.js +16 -17
  6. package/legacy/RestEndpointTypes.js +1 -1
  7. package/legacy/createResource.js +5 -5
  8. package/legacy/hookifyResource.js +2 -2
  9. package/legacy/index.js +1 -2
  10. package/legacy/next/index.js +2 -4
  11. package/legacy/resourceTypes.js +1 -1
  12. package/lib/NetworkError.d.ts +1 -1
  13. package/lib/NetworkError.js +2 -2
  14. package/lib/RestEndpoint.d.ts +1 -1
  15. package/lib/RestEndpoint.js +16 -17
  16. package/lib/RestEndpointTypes.d.ts +15 -15
  17. package/lib/RestEndpointTypes.d.ts.map +1 -1
  18. package/lib/RestEndpointTypes.js +1 -1
  19. package/lib/createResource.d.ts +1 -1
  20. package/lib/createResource.js +5 -5
  21. package/lib/hookifyResource.d.ts +1 -1
  22. package/lib/hookifyResource.js +2 -2
  23. package/lib/index.d.ts +1 -1
  24. package/lib/index.d.ts.map +1 -1
  25. package/lib/index.js +1 -2
  26. package/lib/next/index.d.ts +0 -5
  27. package/lib/next/index.d.ts.map +1 -1
  28. package/lib/next/index.js +2 -4
  29. package/lib/resourceTypes.d.ts +13 -13
  30. package/lib/resourceTypes.d.ts.map +1 -1
  31. package/lib/resourceTypes.js +1 -1
  32. package/package.json +2 -2
  33. package/src/NetworkError.ts +1 -1
  34. package/src/RestEndpoint.d.ts +1 -1
  35. package/src/RestEndpoint.js +14 -13
  36. package/src/RestEndpointTypes.ts +15 -15
  37. package/src/__tests__/Resource.test.ts +10 -8
  38. package/src/__tests__/RestEndpoint.ts +55 -13
  39. package/src/__tests__/__snapshots__/RestEndpoint.ts.snap +9 -1
  40. package/src/__tests__/createResource.test.ts +16 -16
  41. package/src/__tests__/hookifyResource.ts +9 -9
  42. package/src/createResource.ts +4 -4
  43. package/src/hookifyResource.ts +1 -1
  44. package/src/index.ts +6 -1
  45. package/src/next/index.ts +0 -5
  46. package/src/resourceTypes.ts +13 -13
  47. package/ts4.0/NetworkError.d.ts +1 -1
  48. package/ts4.0/RestEndpoint.d.ts +1 -1
  49. package/ts4.0/RestEndpointTypes.d.ts +15 -15
  50. package/ts4.0/createResource.d.ts +1 -1
  51. package/ts4.0/hookifyResource.d.ts +1 -1
  52. package/ts4.0/index.d.ts +1 -1
  53. package/ts4.0/next/index.d.ts +0 -5
  54. package/ts4.0/resourceTypes.d.ts +13 -13
  55. package/ts4.1/NetworkError.d.ts +1 -1
  56. package/ts4.1/RestEndpoint.d.ts +1 -1
  57. package/ts4.1/RestEndpointTypes.d.ts +15 -15
  58. package/ts4.1/createResource.d.ts +1 -1
  59. package/ts4.1/hookifyResource.d.ts +1 -1
  60. package/ts4.1/index.d.ts +1 -1
  61. package/ts4.1/next/index.d.ts +0 -5
  62. package/ts4.1/resourceTypes.d.ts +13 -13
  63. package/legacy/getArrayPath.js +0 -19
  64. package/legacy/paginationUpdate.js +0 -36
  65. package/lib/getArrayPath.d.ts +0 -3
  66. package/lib/getArrayPath.d.ts.map +0 -1
  67. package/lib/getArrayPath.js +0 -19
  68. package/lib/paginationUpdate.d.ts +0 -8
  69. package/lib/paginationUpdate.d.ts.map +0 -1
  70. package/lib/paginationUpdate.js +0 -40
  71. package/src/__tests__/getArrayPath.test.ts +0 -30
  72. package/src/getArrayPath.ts +0 -20
  73. package/src/paginationUpdate.ts +0 -49
  74. package/ts4.0/getArrayPath.d.ts +0 -3
  75. package/ts4.0/paginationUpdate.d.ts +0 -10
  76. package/ts4.1/getArrayPath.d.ts +0 -3
  77. package/ts4.1/paginationUpdate.d.ts +0 -10
@@ -5,7 +5,7 @@ import { CacheProvider } from '@data-client/react';
5
5
  import { Article, CoolerArticle, CoolerArticleResource } from '__tests__/new';
6
6
  import nock from 'nock';
7
7
 
8
- import { makeRenderRestHook } from '../../../test';
8
+ import { makeRenderDataClient } from '../../../test';
9
9
  import RestEndpoint, {
10
10
  Defaults,
11
11
  RestEndpointConstructorOptions,
@@ -58,7 +58,7 @@ const getArticleList = new RestEndpoint({
58
58
  path: '/article-paginated',
59
59
  schema: {
60
60
  nextPage: '',
61
- data: { results: [PaginatedArticle] },
61
+ data: { results: new schema.Collection([PaginatedArticle]) },
62
62
  },
63
63
  method: 'GET',
64
64
  });
@@ -72,7 +72,7 @@ const getArticleList2 = new RestEndpoint({
72
72
  name: 'get',
73
73
  schema: {
74
74
  nextPage: '',
75
- data: { results: [PaginatedArticle] },
75
+ data: { results: new schema.Collection([PaginatedArticle]) },
76
76
  },
77
77
  method: 'GET',
78
78
  });
@@ -143,8 +143,8 @@ const getNextPage3 = getArticleList3.getPage;
143
143
  };
144
144
 
145
145
  describe('RestEndpoint', () => {
146
- const renderRestHook: ReturnType<typeof makeRenderRestHook> =
147
- makeRenderRestHook(CacheProvider);
146
+ const renderDataClient: ReturnType<typeof makeRenderDataClient> =
147
+ makeRenderDataClient(CacheProvider);
148
148
  let mynock: nock.Scope;
149
149
 
150
150
  beforeEach(() => {
@@ -306,7 +306,7 @@ describe('RestEndpoint', () => {
306
306
  mynock.get(`/article-paginated`).reply(200, paginatedFirstPage);
307
307
  mynock.get(`/article-paginated?cursor=2`).reply(200, paginatedSecondPage);
308
308
 
309
- const { result, waitForNextUpdate, controller } = renderRestHook(() => {
309
+ const { result, waitForNextUpdate, controller } = renderDataClient(() => {
310
310
  const { fetch } = useController();
311
311
  const {
312
312
  data: { results: articles },
@@ -333,7 +333,7 @@ describe('RestEndpoint', () => {
333
333
  .get(`/article-paginated/happy?cursor=2`)
334
334
  .reply(200, paginatedSecondPage);
335
335
 
336
- const { result, waitForNextUpdate, controller } = renderRestHook(() => {
336
+ const { result, waitForNextUpdate, controller } = renderDataClient(() => {
337
337
  const {
338
338
  data: { results: articles },
339
339
  nextPage,
@@ -358,13 +358,31 @@ describe('RestEndpoint', () => {
358
358
  expect(result.current.articles.map(({ id }) => id)).toEqual([5, 3, 7, 8]);
359
359
  });
360
360
 
361
+ it('push: should extend name of parent endpoint', () => {
362
+ expect(getArticleList3.push.name).toMatchSnapshot();
363
+ expect(getArticleList3.push.name).toBe(getArticleList3.unshift.name);
364
+ });
365
+
366
+ it('unshift: should extend name of parent endpoint', () => {
367
+ expect(getArticleList3.unshift.name).toMatchSnapshot();
368
+ });
369
+
370
+ // TODO: but we need a Values collection
371
+ // it('assign: should extend name of parent endpoint', () => {
372
+ // expect(getArticleList3.assign.name).toMatchSnapshot();
373
+ // });
374
+
375
+ it('getPage: should extend name of parent endpoint', () => {
376
+ expect(getNextPage3.name).toMatchSnapshot();
377
+ });
378
+
361
379
  it('getPage: should update on get for a paginated resource with parameter in path', async () => {
362
380
  mynock.get(`/article-paginated?group=happy`).reply(200, paginatedFirstPage);
363
381
  mynock
364
382
  .get(`/article-paginated?cursor=2&group=happy`)
365
383
  .reply(200, paginatedSecondPage);
366
384
 
367
- const { result, waitForNextUpdate, controller } = renderRestHook(() => {
385
+ const { result, waitForNextUpdate, controller } = renderDataClient(() => {
368
386
  const {
369
387
  data: { results: articles },
370
388
  nextPage,
@@ -396,7 +414,7 @@ describe('RestEndpoint', () => {
396
414
  results: [nested[nested.length - 1], ...moreNested],
397
415
  });
398
416
 
399
- const { result, waitForNextUpdate } = renderRestHook(() => {
417
+ const { result, waitForNextUpdate } = renderDataClient(() => {
400
418
  const { fetch } = useController();
401
419
  const {
402
420
  data: { results: articles },
@@ -444,7 +462,7 @@ describe('RestEndpoint', () => {
444
462
  };
445
463
  mynock.get(`/complex-thing/5`).reply(200, firstResponse);
446
464
 
447
- const { result, waitForNextUpdate } = renderRestHook(() => {
465
+ const { result, waitForNextUpdate } = renderDataClient(() => {
448
466
  const { fetch } = useController();
449
467
  const article = useSuspense(getComplex, { id: '5' });
450
468
  return { article, fetch };
@@ -685,7 +703,7 @@ describe('RestEndpoint', () => {
685
703
  path: 'http\\://test.com/user/:id',
686
704
  name: 'update',
687
705
  });
688
- const { result, waitForNextUpdate } = renderRestHook(() => {
706
+ const { result, waitForNextUpdate } = renderDataClient(() => {
689
707
  return useSuspense(getUser, { id: 5 });
690
708
  });
691
709
  await waitForNextUpdate();
@@ -724,7 +742,7 @@ describe('RestEndpoint', () => {
724
742
  method: 'GET',
725
743
  name: 'update',
726
744
  });
727
- const { result, waitForNextUpdate } = renderRestHook(() => {
745
+ const { result, waitForNextUpdate } = renderDataClient(() => {
728
746
  return useSuspense(getUser, { id: 5 });
729
747
  });
730
748
  await waitForNextUpdate();
@@ -1414,7 +1432,31 @@ describe('RestEndpoint.fetch()', () => {
1414
1432
  });
1415
1433
 
1416
1434
  it('without Collection in schema - endpoint.push schema should be null', () => {
1417
- expect(getArticleList2.push.schema).toBeFalsy();
1435
+ const noColletionEndpoint = new RestEndpoint({
1436
+ urlPrefix: 'http://test.com/article-paginated/',
1437
+ path: ':group',
1438
+ name: 'get',
1439
+ schema: {
1440
+ nextPage: '',
1441
+ data: { results: [PaginatedArticle] },
1442
+ },
1443
+ method: 'GET',
1444
+ });
1445
+ expect(noColletionEndpoint.push.schema).toBeFalsy();
1446
+ });
1447
+
1448
+ it('without Collection in schema - endpoint.getPage should throw', () => {
1449
+ const noColletionEndpoint = new RestEndpoint({
1450
+ urlPrefix: 'http://test.com/article-paginated/',
1451
+ path: ':group',
1452
+ name: 'get',
1453
+ schema: {
1454
+ nextPage: '',
1455
+ data: { results: [PaginatedArticle] },
1456
+ },
1457
+ method: 'GET',
1458
+ });
1459
+ expect(() => noColletionEndpoint.getPage).toThrowErrorMatchingSnapshot();
1418
1460
  });
1419
1461
  });
1420
1462
  const proto = Object.prototype;
@@ -1,5 +1,11 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
+ exports[`RestEndpoint getPage: should extend name of parent endpoint 1`] = `"http://test.com/article-paginated.getPage"`;
4
+
5
+ exports[`RestEndpoint push: should extend name of parent endpoint 1`] = `"http://test.com/article-paginated.create"`;
6
+
7
+ exports[`RestEndpoint unshift: should extend name of parent endpoint 1`] = `"http://test.com/article-paginated.create"`;
8
+
3
9
  exports[`RestEndpoint.fetch() should reject if content-type does not exist with schema 1`] = `[NetworkError: Unexpected text response for schema CoolerArticle]`;
4
10
 
5
11
  exports[`RestEndpoint.fetch() should reject if content-type is not json with schema 1`] = `
@@ -14,5 +20,7 @@ exports[`RestEndpoint.fetch() should reject with custom message if content type
14
20
  See https://www.rfc-editor.org/rfc/rfc4627 for information on JSON responses
15
21
 
16
22
  Using parsed JSON.
17
- If text content was expected see https://resthooks.io/rest/api/RestEndpoint#parseResponse]
23
+ If text content was expected see https://dataclient.io/rest/api/RestEndpoint#parseResponse]
18
24
  `;
25
+
26
+ exports[`RestEndpoint.fetch() without Collection in schema - endpoint.getPage should throw 1`] = `"Missing Collection"`;
@@ -6,7 +6,7 @@ import {
6
6
  Controller,
7
7
  useSuspense,
8
8
  } from '@data-client/react';
9
- import { makeRenderRestHook } from '@data-client/test';
9
+ import { makeRenderDataClient } from '@data-client/test';
10
10
  import { act } from '@testing-library/react-hooks';
11
11
  import nock, { ReplyHeaders } from 'nock';
12
12
 
@@ -14,8 +14,8 @@ import createResource from '../createResource';
14
14
  import RestEndpoint, { RestGenerics } from '../RestEndpoint';
15
15
 
16
16
  describe('createResource()', () => {
17
- const renderRestHook: ReturnType<typeof makeRenderRestHook> =
18
- makeRenderRestHook(CacheProvider);
17
+ const renderDataClient: ReturnType<typeof makeRenderDataClient> =
18
+ makeRenderDataClient(CacheProvider);
19
19
  let mynock: nock.Scope;
20
20
 
21
21
  class User extends Entity {
@@ -182,7 +182,7 @@ describe('createResource()', () => {
182
182
  isAdmin: false,
183
183
  });
184
184
 
185
- const { result, waitForNextUpdate, controller } = renderRestHook(() => {
185
+ const { result, waitForNextUpdate, controller } = renderDataClient(() => {
186
186
  return useSuspense(UserResource.current);
187
187
  });
188
188
  await waitForNextUpdate();
@@ -321,7 +321,7 @@ describe('createResource()', () => {
321
321
  },
322
322
  ]);
323
323
 
324
- const { result, waitForNextUpdate, controller } = renderRestHook(() => {
324
+ const { result, waitForNextUpdate, controller } = renderDataClient(() => {
325
325
  return [
326
326
  useSuspense(UserResource.current),
327
327
  useSuspense(UserResource.getList, { blob: '5', isAdmin: false }),
@@ -486,7 +486,7 @@ describe('createResource()', () => {
486
486
  },
487
487
  ]);
488
488
 
489
- const { result, waitForNextUpdate, controller } = renderRestHook(() => {
489
+ const { result, waitForNextUpdate, controller } = renderDataClient(() => {
490
490
  return [
491
491
  useSuspense(UserResource.current),
492
492
  useSuspense(UserResource.getList, { blob: '5', isAdmin: false }),
@@ -543,7 +543,7 @@ describe('createResource()', () => {
543
543
  });
544
544
 
545
545
  it('UserResource.get should work', async () => {
546
- const { result, waitForNextUpdate } = renderRestHook(() => {
546
+ const { result, waitForNextUpdate } = renderDataClient(() => {
547
547
  return useSuspense(UserResource.get, { group: 'five', id: '5' });
548
548
  });
549
549
  await waitForNextUpdate();
@@ -559,7 +559,7 @@ describe('createResource()', () => {
559
559
  });
560
560
 
561
561
  it('UserResource.getList should work', async () => {
562
- const { result, waitForNextUpdate } = renderRestHook(() => {
562
+ const { result, waitForNextUpdate } = renderDataClient(() => {
563
563
  return useSuspense(UserResource.getList, { group: 'five' });
564
564
  });
565
565
  await waitForNextUpdate();
@@ -585,7 +585,7 @@ describe('createResource()', () => {
585
585
  ...body,
586
586
  }));
587
587
 
588
- const { result, waitForNextUpdate } = renderRestHook(
588
+ const { result, waitForNextUpdate } = renderDataClient(
589
589
  () => {
590
590
  return [
591
591
  useSuspense(UserResource.get, { group: 'five', id: '5' }),
@@ -650,7 +650,7 @@ describe('createResource()', () => {
650
650
  ...body,
651
651
  }));
652
652
 
653
- const { result } = renderRestHook(() => {
653
+ const { result } = renderDataClient(() => {
654
654
  return [
655
655
  useCache(UserResource.get, { group: 'five', id: '5' }),
656
656
  useController(),
@@ -724,7 +724,7 @@ describe('createResource()', () => {
724
724
  mynock
725
725
  .delete(`/groups/five/users/${userPayload.id}`)
726
726
  .reply(200, (uri, body: any) => response, headers);
727
- const { result, waitForNextUpdate } = renderRestHook(
727
+ const { result, waitForNextUpdate } = renderDataClient(
728
728
  () => {
729
729
  return [
730
730
  useSuspense(UserResource.get, { group: 'five', id: '5' }),
@@ -801,7 +801,7 @@ describe('createResource()', () => {
801
801
  schema: User2,
802
802
  }),
803
803
  };
804
- const { result, waitForNextUpdate } = renderRestHook(() => {
804
+ const { result, waitForNextUpdate } = renderDataClient(() => {
805
805
  return useSuspense(UserResourceExtend.get, { magic: 'vi', id: 5 });
806
806
  });
807
807
  await waitForNextUpdate();
@@ -848,7 +848,7 @@ describe('createResource()', () => {
848
848
  it('should work with detail', async () => {
849
849
  mynock.get(`/feed/${feedPayload.id}`).reply(200, feedPayload);
850
850
 
851
- const { result, waitForNextUpdate } = renderRestHook(() => {
851
+ const { result, waitForNextUpdate } = renderDataClient(() => {
852
852
  return useSuspense(FeedResource.get, { id: '5' });
853
853
  });
854
854
  await waitForNextUpdate();
@@ -876,7 +876,7 @@ describe('createResource()', () => {
876
876
  it('should work with list [no args]', async () => {
877
877
  mynock.get(`/feed`).reply(200, [feedPayload]);
878
878
 
879
- const { result, waitForNextUpdate } = renderRestHook(() => {
879
+ const { result, waitForNextUpdate } = renderDataClient(() => {
880
880
  return useSuspense(FeedResource.getList);
881
881
  });
882
882
  await waitForNextUpdate();
@@ -905,7 +905,7 @@ describe('createResource()', () => {
905
905
  ...body,
906
906
  }));
907
907
 
908
- const { result, waitForNextUpdate } = renderRestHook(() => {
908
+ const { result, waitForNextUpdate } = renderDataClient(() => {
909
909
  return [
910
910
  useCache(FeedResource.get, { id: '5', type: 'link' }),
911
911
  useController(),
@@ -1073,7 +1073,7 @@ describe('createResource()', () => {
1073
1073
  }),
1074
1074
  }));
1075
1075
 
1076
- const { controller, result } = renderRestHook(
1076
+ const { controller, result } = renderDataClient(
1077
1077
  () => {
1078
1078
  return useSuspense(UserResource.getList);
1079
1079
  },
@@ -3,7 +3,7 @@ import { CacheProvider } from '@data-client/react';
3
3
  import { CoolerArticleResource, CoolerArticle, User } from '__tests__/new';
4
4
  import nock from 'nock';
5
5
 
6
- import { makeRenderRestHook } from '../../../test';
6
+ import { makeRenderDataClient } from '../../../test';
7
7
  import hookifyResource from '../hookifyResource';
8
8
 
9
9
  const CoolerArticleHookResource = hookifyResource(
@@ -62,10 +62,10 @@ describe('hookifyResource()', () => {
62
62
  completed: false,
63
63
  };
64
64
 
65
- let renderRestHook: ReturnType<typeof makeRenderRestHook>;
65
+ let renderDataClient: ReturnType<typeof makeRenderDataClient>;
66
66
 
67
67
  beforeEach(() => {
68
- renderRestHook = makeRenderRestHook(CacheProvider);
68
+ renderDataClient = makeRenderDataClient(CacheProvider);
69
69
 
70
70
  nock(/.*/)
71
71
  .defaultReplyHeaders({
@@ -110,7 +110,7 @@ describe('hookifyResource()', () => {
110
110
  });
111
111
 
112
112
  it('useDetail', async () => {
113
- const { result, waitForNextUpdate } = renderRestHook(() =>
113
+ const { result, waitForNextUpdate } = renderDataClient(() =>
114
114
  useSuspense(CoolerArticleHookResource.useGet(), { id: payload.id }),
115
115
  );
116
116
  await waitForNextUpdate();
@@ -119,7 +119,7 @@ describe('hookifyResource()', () => {
119
119
  });
120
120
 
121
121
  it('useList', async () => {
122
- const { result, waitForNextUpdate } = renderRestHook(() =>
122
+ const { result, waitForNextUpdate } = renderDataClient(() =>
123
123
  useSuspense(CoolerArticleHookResource.useGetList()),
124
124
  );
125
125
  await waitForNextUpdate();
@@ -127,7 +127,7 @@ describe('hookifyResource()', () => {
127
127
  });
128
128
 
129
129
  it('useCreate', async () => {
130
- const { result } = renderRestHook(() => ({
130
+ const { result } = renderDataClient(() => ({
131
131
  endpoint: CoolerArticleHookResource.useCreate(),
132
132
  fetch: useController().fetch,
133
133
  }));
@@ -142,7 +142,7 @@ describe('hookifyResource()', () => {
142
142
  });
143
143
 
144
144
  it('useDelete', async () => {
145
- const { result } = renderRestHook(() => ({
145
+ const { result } = renderDataClient(() => ({
146
146
  endpoint: CoolerArticleHookResource.useDelete(),
147
147
  fetch: useController().fetch,
148
148
  }));
@@ -154,7 +154,7 @@ describe('hookifyResource()', () => {
154
154
  });
155
155
 
156
156
  it('useUpdate', async () => {
157
- const { result } = renderRestHook(() => ({
157
+ const { result } = renderDataClient(() => ({
158
158
  endpoint: CoolerArticleHookResource.useUpdate(),
159
159
  fetch: useController().fetch,
160
160
  }));
@@ -172,7 +172,7 @@ describe('hookifyResource()', () => {
172
172
  });
173
173
 
174
174
  it('usePartialUpdate', async () => {
175
- const { result } = renderRestHook(() => ({
175
+ const { result } = renderDataClient(() => ({
176
176
  endpoint: CoolerArticleHookResource.usePartialUpdate(),
177
177
  fetch: useController().fetch,
178
178
  }));
@@ -23,7 +23,7 @@ const { Invalidate, Collection: BaseCollection } = schema;
23
23
 
24
24
  /** Creates collection of Endpoints for common operations on a given data/schema.
25
25
  *
26
- * @see https://resthooks.io/rest/api/createResource
26
+ * @see https://dataclient.io/rest/api/createResource
27
27
  */
28
28
  export default function createResource<O extends ResourceGenerics>({
29
29
  path,
@@ -138,7 +138,7 @@ export default function createResource<O extends ResourceGenerics>({
138
138
  function optimisticUpdate(snap: SnapshotInterface, params: any, body: any) {
139
139
  return {
140
140
  ...params,
141
- ...ensureBodyPojo(body),
141
+ ...ensurePojo(body),
142
142
  };
143
143
  }
144
144
  function optimisticPartial(
@@ -151,14 +151,14 @@ function optimisticPartial(
151
151
  ...params,
152
152
  ...data,
153
153
  // even tho we don't always have two arguments, the extra one will simply be undefined which spreads fine
154
- ...ensureBodyPojo(body),
154
+ ...ensurePojo(body),
155
155
  };
156
156
  };
157
157
  }
158
158
  function optimisticDelete(snap: SnapshotInterface, params: any) {
159
159
  return params;
160
160
  }
161
- function ensureBodyPojo(body: any) {
161
+ function ensurePojo(body: any) {
162
162
  return body instanceof FormData
163
163
  ? Object.fromEntries((body as any).entries())
164
164
  : body;
@@ -7,7 +7,7 @@ export interface HookableEndpointInterface extends EndpointInterface {
7
7
  /** Turns a collection of Endpoints (Resource) into a collection of hooks.
8
8
  * This is useful for Endpoints that need hooks to prepare their fetch requests.
9
9
  *
10
- * @see https://resthooks.io/rest/api/hookifyResource
10
+ * @see https://dataclient.io/rest/api/hookifyResource
11
11
  */
12
12
  export default function hookifyResource<R extends {}>(
13
13
  resource: R,
package/src/index.ts CHANGED
@@ -23,13 +23,18 @@ export type {
23
23
  export { default as createResource } from './createResource.js';
24
24
  export type { Resource } from './resourceTypes.js';
25
25
  export type { ResourceOptions, ResourceGenerics } from './resourceTypes.js';
26
+ export type {
27
+ ResourceExtension,
28
+ ResourceEndpointExtensions,
29
+ CustomResource,
30
+ ExtendedResource,
31
+ } from './resourceExtensionTypes.js';
26
32
  export { default as hookifyResource } from './hookifyResource.js';
27
33
  export type {
28
34
  HookResource,
29
35
  HookableEndpointInterface,
30
36
  } from './hookifyResource.js';
31
37
  export { default as NetworkError } from './NetworkError.js';
32
- export { default as paginationUpdate } from './paginationUpdate.js';
33
38
  export type { OptionsToFunction } from './OptionsToFunction.js';
34
39
  export type {
35
40
  ShortenPath,
package/src/next/index.ts CHANGED
@@ -1,5 +0,0 @@
1
- export * from '../RestEndpoint.js';
2
- export { default as RestEndpoint } from '../RestEndpoint.js';
3
- export { default as createResource } from '../createResource.js';
4
- export type { Resource } from '../resourceTypes.js';
5
- export type { ResourceOptions, ResourceGenerics } from '../resourceTypes.js';
@@ -13,28 +13,28 @@ import RestEndpoint, {
13
13
 
14
14
  /** The typed (generic) options for a Resource */
15
15
  export interface ResourceGenerics {
16
- /** @see https://resthooks.io/rest/api/createResource#path */
16
+ /** @see https://dataclient.io/rest/api/createResource#path */
17
17
  readonly path: ResourcePath;
18
- /** @see https://resthooks.io/rest/api/createResource#schema */
18
+ /** @see https://dataclient.io/rest/api/createResource#schema */
19
19
  readonly schema: Schema;
20
20
  /** Only used for types */
21
21
  /** @see https://dataclient.io/rest/api/createResource#body */
22
22
  readonly body?: any;
23
23
  /** Only used for types */
24
- /** @see https://resthooks.io/rest/api/createResource#searchParams */
24
+ /** @see https://dataclient.io/rest/api/createResource#searchParams */
25
25
  readonly searchParams?: any;
26
- /** @see https://resthooks.io/rest/api/createResource#paginationfield */
26
+ /** @see https://dataclient.io/rest/api/createResource#paginationfield */
27
27
  readonly paginationField?: string;
28
28
  }
29
29
  /** The untyped options for createResource() */
30
30
  export interface ResourceOptions {
31
- /** @see https://resthooks.io/rest/api/createResource#endpoint */
31
+ /** @see https://dataclient.io/rest/api/createResource#endpoint */
32
32
  Endpoint?: typeof RestEndpoint;
33
33
  /** @see https://dataclient.io/rest/api/createResource#collection */
34
34
  Collection?: typeof Collection;
35
- /** @see https://resthooks.io/rest/api/createResource#optimistic */
35
+ /** @see https://dataclient.io/rest/api/createResource#optimistic */
36
36
  optimistic?: boolean;
37
- /** @see https://resthooks.io/rest/api/createResource#urlprefix */
37
+ /** @see https://dataclient.io/rest/api/createResource#urlprefix */
38
38
  urlPrefix?: string;
39
39
  requestInit?: RequestInit;
40
40
  getHeaders?(headers: HeadersInit): Promise<HeadersInit> | HeadersInit;
@@ -54,19 +54,19 @@ export interface ResourceOptions {
54
54
  }
55
55
 
56
56
  /** Resources are a collection of methods for a given data model.
57
- * @see https://resthooks.io/rest/api/createResource
57
+ * @see https://dataclient.io/rest/api/createResource
58
58
  */
59
59
  export interface Resource<
60
60
  O extends ResourceGenerics = { path: ResourcePath; schema: any },
61
61
  > extends Extendable<O> {
62
62
  /** Get a singular item
63
63
  *
64
- * @see https://resthooks.io/rest/api/createResource#get
64
+ * @see https://dataclient.io/rest/api/createResource#get
65
65
  */
66
66
  get: GetEndpoint<{ path: O['path']; schema: O['schema'] }>;
67
67
  /** Get a list of item
68
68
  *
69
- * @see https://resthooks.io/rest/api/createResource#getlist
69
+ * @see https://dataclient.io/rest/api/createResource#getlist
70
70
  */
71
71
  getList: 'searchParams' extends keyof O
72
72
  ? GetEndpoint<
@@ -111,7 +111,7 @@ export interface Resource<
111
111
  }>;
112
112
  /** Update an item (PUT)
113
113
  *
114
- * @see https://resthooks.io/rest/api/createResource#update
114
+ * @see https://dataclient.io/rest/api/createResource#update
115
115
  */
116
116
  update: 'body' extends keyof O
117
117
  ? MutateEndpoint<{
@@ -126,7 +126,7 @@ export interface Resource<
126
126
  }>;
127
127
  /** Update an item (PATCH)
128
128
  *
129
- * @see https://resthooks.io/rest/api/createResource#partialupdate
129
+ * @see https://dataclient.io/rest/api/createResource#partialupdate
130
130
  */
131
131
  partialUpdate: 'body' extends keyof O
132
132
  ? MutateEndpoint<{
@@ -141,7 +141,7 @@ export interface Resource<
141
141
  }>;
142
142
  /** Delete an item (DELETE)
143
143
  *
144
- * @see https://resthooks.io/rest/api/createResource#delete
144
+ * @see https://dataclient.io/rest/api/createResource#delete
145
145
  */
146
146
  delete: RestTypeNoBody<
147
147
  PathArgs<O['path']>,
@@ -1,6 +1,6 @@
1
1
  /** An error with a Rest Endpoint fetch
2
2
  *
3
- * @see https://resthooks.io/rest/api/NetworkError
3
+ * @see https://dataclient.io/rest/api/NetworkError
4
4
  */
5
5
  export default class NetworkError extends Error {
6
6
  status: number;
@@ -3,7 +3,7 @@ import type { RestEndpointConstructor } from './RestEndpointTypes.js';
3
3
  export * from './RestEndpointTypes.js';
4
4
  /** Simplifies endpoint definitions that follow REST patterns
5
5
  *
6
- * @see https://resthooks.io/rest/api/RestEndpoint
6
+ * @see https://dataclient.io/rest/api/RestEndpoint
7
7
  */
8
8
  export declare let RestEndpoint: RestEndpointConstructor;
9
9
  export default RestEndpoint;
@@ -11,37 +11,37 @@ export interface RestInstanceBase<F extends FetchFunction = FetchFunction, S ext
11
11
  } = {
12
12
  path: string;
13
13
  }> extends EndpointInstanceInterface<F, S, M> {
14
- /** @see https://resthooks.io/rest/api/RestEndpoint#body */
14
+ /** @see https://dataclient.io/rest/api/RestEndpoint#body */
15
15
  readonly body?: 'body' extends keyof O ? O['body'] : any;
16
- /** @see https://resthooks.io/rest/api/RestEndpoint#searchParams */
16
+ /** @see https://dataclient.io/rest/api/RestEndpoint#searchParams */
17
17
  readonly searchParams?: 'searchParams' extends keyof O ? O['searchParams'] : unknown;
18
18
  /** Pattern to construct url based on Url Parameters
19
- * @see https://resthooks.io/rest/api/RestEndpoint#path
19
+ * @see https://dataclient.io/rest/api/RestEndpoint#path
20
20
  */
21
21
  readonly path: O['path'];
22
22
  /** Prepended to all urls
23
- * @see https://resthooks.io/rest/api/RestEndpoint#urlPrefix
23
+ * @see https://dataclient.io/rest/api/RestEndpoint#urlPrefix
24
24
  */
25
25
  readonly urlPrefix: string;
26
26
  readonly requestInit: RequestInit;
27
- /** @see https://resthooks.io/rest/api/RestEndpoint#method */
27
+ /** @see https://dataclient.io/rest/api/RestEndpoint#method */
28
28
  readonly method: (O & {
29
29
  method: string;
30
30
  })['method'];
31
31
  readonly signal: AbortSignal | undefined;
32
32
  readonly paginationField?: string;
33
33
  url(...args: Parameters<F>): string;
34
- /** @see https://resthooks.io/rest/api/RestEndpoint#getRequestInit */
34
+ /** @see https://dataclient.io/rest/api/RestEndpoint#getRequestInit */
35
35
  getRequestInit(this: any, body?: RequestInit['body'] | Record<string, unknown>): Promise<RequestInit> | RequestInit;
36
- /** @see https://resthooks.io/rest/api/RestEndpoint#getHeaders */
36
+ /** @see https://dataclient.io/rest/api/RestEndpoint#getHeaders */
37
37
  getHeaders(headers: HeadersInit): Promise<HeadersInit> | HeadersInit;
38
- /** @see https://resthooks.io/rest/api/RestEndpoint#fetchResponse */
38
+ /** @see https://dataclient.io/rest/api/RestEndpoint#fetchResponse */
39
39
  fetchResponse(input: RequestInfo, init: RequestInit): Promise<Response>;
40
- /** @see https://resthooks.io/rest/api/RestEndpoint#parseResponse */
40
+ /** @see https://dataclient.io/rest/api/RestEndpoint#parseResponse */
41
41
  parseResponse(response: Response): Promise<any>;
42
- /** @see https://resthooks.io/rest/api/RestEndpoint#process */
42
+ /** @see https://dataclient.io/rest/api/RestEndpoint#process */
43
43
  process(value: any, ...args: Parameters<F>): ResolveType<F>;
44
- /** @see https://resthooks.io/rest/api/RestEndpoint#testKey */
44
+ /** @see https://dataclient.io/rest/api/RestEndpoint#testKey */
45
45
  testKey(key: string): boolean;
46
46
  /** Creates a child endpoint that inherits from this while overriding provided `options`.
47
47
  * @see https://dataclient.io/rest/api/RestEndpoint#extend
@@ -134,11 +134,11 @@ export type RestExtendedEndpoint<O extends PartialRestGenerics, E extends RestIn
134
134
  paginationField: E['getPage']['paginationField'];
135
135
  } : unknown), RestInstance<(...args: Parameters<E>) => O['process'] extends {} ? Promise<ReturnType<O['process']>> : ReturnType<E>, 'schema' extends keyof O ? O['schema'] : E['schema'], 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect']>> & Omit<O, KeyofRestEndpoint> & Omit<E, KeyofRestEndpoint | keyof O>;
136
136
  export interface PartialRestGenerics {
137
- /** @see https://resthooks.io/rest/api/RestEndpoint#path */
137
+ /** @see https://dataclient.io/rest/api/RestEndpoint#path */
138
138
  readonly path?: string;
139
- /** @see https://resthooks.io/rest/api/RestEndpoint#schema */
139
+ /** @see https://dataclient.io/rest/api/RestEndpoint#schema */
140
140
  readonly schema?: Schema | undefined;
141
- /** @see https://resthooks.io/rest/api/RestEndpoint#method */
141
+ /** @see https://dataclient.io/rest/api/RestEndpoint#method */
142
142
  readonly method?: string;
143
143
  /** Only used for types */
144
144
  /** @see https://dataclient.io/rest/api/RestEndpoint#body */
@@ -148,7 +148,7 @@ export interface PartialRestGenerics {
148
148
  searchParams?: any;
149
149
  /** @see https://dataclient.io/rest/api/RestEndpoint#paginationfield */
150
150
  readonly paginationField?: string;
151
- /** @see https://resthooks.io/rest/api/RestEndpoint#process */
151
+ /** @see https://dataclient.io/rest/api/RestEndpoint#process */
152
152
  process?(value: any, ...args: any): any;
153
153
  }
154
154
  export interface RestGenerics extends PartialRestGenerics {
@@ -1,7 +1,7 @@
1
1
  import { ResourceGenerics, ResourceOptions, Resource } from './resourceTypes.js';
2
2
  /** Creates collection of Endpoints for common operations on a given data/schema.
3
3
  *
4
- * @see https://resthooks.io/rest/api/createResource
4
+ * @see https://dataclient.io/rest/api/createResource
5
5
  */
6
6
  export default function createResource<O extends ResourceGenerics>({ path, schema, Endpoint, Collection, optimistic, paginationField, ...extraOptions }: Readonly<O> & ResourceOptions): Resource<O>;
7
7
  //# sourceMappingURL=createResource.d.ts.map
@@ -7,7 +7,7 @@ export interface HookableEndpointInterface extends EndpointInterface {
7
7
  *
8
8
  * Requires TypeScript 4.1 to be typed correctly
9
9
  *
10
- * @see https://resthooks.io/rest/api/hookifyResource
10
+ * @see https://dataclient.io/rest/api/hookifyResource
11
11
  */
12
12
  export default function hookifyResource<R extends {}>(
13
13
  resource: R,