@codecks/fetch 1.0.1 → 2.0.1

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 (120) hide show
  1. package/README.md +80 -32
  2. package/dist/_exploration/api-requester.d.ts +3 -4
  3. package/dist/_exploration/api-requester.js +2 -2
  4. package/dist/_exploration/create-hooks.d.ts +4313 -13097
  5. package/dist/_exploration/create-hooks.js +1 -1
  6. package/dist/_exploration/loader.d.ts +2 -2
  7. package/dist/_exploration/loader.js +1 -1
  8. package/dist/_exploration/store.d.ts +5 -4
  9. package/dist/_exploration/store.js +1 -1
  10. package/dist/{collection-utils-KmtGUuXm.js → collection-utils-y85xawyq.js} +4 -2
  11. package/dist/index-iEtXFnkY.d.ts +39 -0
  12. package/dist/index.d.ts +4 -19
  13. package/dist/index.js +26 -15
  14. package/dist/{loader-types-fd5tV0FD.d.ts → loader-types-CIO8hJAv.d.ts} +1 -1
  15. package/dist/loader-utils-DdrmVo0F.d.ts +2218 -0
  16. package/dist/query-helpers-DndWBcMF.js +1203 -0
  17. package/dist/{query-type-BqQ9oX_U.d.ts → query-type-CwrwqxUP.d.ts} +30 -15
  18. package/dist/store-Dpx1yvWU.d.ts +1203 -0
  19. package/package.json +2 -1
  20. package/schema/actions.md +789 -0
  21. package/schema/models/account.md +57 -90
  22. package/schema/models/attachment.md +15 -11
  23. package/schema/models/card.md +91 -65
  24. package/schema/models/cardHistory.md +15 -9
  25. package/schema/models/deck.md +41 -36
  26. package/schema/models/file.md +13 -15
  27. package/schema/models/handCard.md +8 -5
  28. package/schema/models/milestone.md +27 -22
  29. package/schema/models/milestoneProgress.md +9 -3
  30. package/schema/models/milestoneProject.md +6 -4
  31. package/schema/models/project.md +15 -39
  32. package/schema/models/projectTag.md +12 -7
  33. package/schema/models/queueEntry.md +12 -8
  34. package/schema/models/release.md +8 -6
  35. package/schema/models/resolvable.md +19 -15
  36. package/schema/models/resolvableEntry.md +16 -13
  37. package/schema/models/resolvableEntryReaction.md +16 -12
  38. package/schema/models/sprint.md +35 -25
  39. package/schema/models/sprintConfig.md +24 -20
  40. package/schema/models/sprintConfigProgress.md +9 -3
  41. package/schema/models/sprintProgress.md +9 -3
  42. package/schema/models/sprintProject.md +7 -5
  43. package/schema/models/user.md +15 -56
  44. package/schema/models/workflowItem.md +47 -31
  45. package/schema/overview.md +40 -93
  46. package/schema/query-syntax.md +1 -1
  47. package/schema/types.md +103 -0
  48. package/dist/_root-BW9uzB79.d.ts +0 -34
  49. package/dist/index-k-KPWV9R.d.ts +0 -2680
  50. package/dist/loader-utils-hvdC-xsQ.d.ts +0 -42
  51. package/dist/query-helpers-iX1fiqLv.js +0 -3062
  52. package/dist/store-BvEJzUVp.d.ts +0 -2667
  53. package/schema/models/accountOnboarding.md +0 -15
  54. package/schema/models/accountOnboardingStep.md +0 -14
  55. package/schema/models/accountRole.md +0 -19
  56. package/schema/models/accountUserAchievement.md +0 -17
  57. package/schema/models/accountUserSetting.md +0 -20
  58. package/schema/models/activeTimeTracker.md +0 -19
  59. package/schema/models/activity.md +0 -30
  60. package/schema/models/affiliateCode.md +0 -30
  61. package/schema/models/affiliateCodeStat.md +0 -19
  62. package/schema/models/app.md +0 -10
  63. package/schema/models/appInstallation.md +0 -19
  64. package/schema/models/assigneeAssignment.md +0 -18
  65. package/schema/models/assigneeDeckAssignment.md +0 -20
  66. package/schema/models/autoFinishedTimeTrackingSegment.md +0 -20
  67. package/schema/models/cardDiffNotification.md +0 -22
  68. package/schema/models/cardOrder.md +0 -17
  69. package/schema/models/cardOrderInDeck.md +0 -18
  70. package/schema/models/cardPreset.md +0 -19
  71. package/schema/models/cardSubscription.md +0 -19
  72. package/schema/models/cardUpvote.md +0 -21
  73. package/schema/models/cardsEffortHistory.md +0 -9
  74. package/schema/models/cardsFinishedHistory.md +0 -16
  75. package/schema/models/cardsStatusHistory.md +0 -9
  76. package/schema/models/cardsTimeToFinished.md +0 -18
  77. package/schema/models/dailyDiscordGuildVoteMembership.md +0 -15
  78. package/schema/models/dailyPublicProjectMembership.md +0 -15
  79. package/schema/models/deckAssignment.md +0 -18
  80. package/schema/models/deckGuardian.md +0 -17
  81. package/schema/models/deckSubscription.md +0 -18
  82. package/schema/models/discordGuild.md +0 -30
  83. package/schema/models/discordMember.md +0 -21
  84. package/schema/models/discordProjectNotification.md +0 -19
  85. package/schema/models/discordSlashCommand.md +0 -28
  86. package/schema/models/dueCard.md +0 -18
  87. package/schema/models/integration.md +0 -23
  88. package/schema/models/invoice.md +0 -21
  89. package/schema/models/lastSeenCardUpvote.md +0 -17
  90. package/schema/models/pinnedMilestone.md +0 -22
  91. package/schema/models/projectOrder.md +0 -18
  92. package/schema/models/projectSelection.md +0 -18
  93. package/schema/models/projectUser.md +0 -18
  94. package/schema/models/projectUserSetting.md +0 -15
  95. package/schema/models/publicProjectInfo.md +0 -20
  96. package/schema/models/publicProjectMembership.md +0 -17
  97. package/schema/models/publicProjectVisit.md +0 -16
  98. package/schema/models/queueSelection.md +0 -19
  99. package/schema/models/resolvableEntryHistory.md +0 -20
  100. package/schema/models/resolvableNotification.md +0 -30
  101. package/schema/models/resolvableParticipant.md +0 -25
  102. package/schema/models/resolvableParticipantHistory.md +0 -23
  103. package/schema/models/savedSearch.md +0 -18
  104. package/schema/models/stripeAccountSync.md +0 -29
  105. package/schema/models/timeTrackingSegment.md +0 -24
  106. package/schema/models/timeTrackingSum.md +0 -18
  107. package/schema/models/userDismissedHint.md +0 -16
  108. package/schema/models/userEmail.md +0 -18
  109. package/schema/models/userInvitation.md +0 -20
  110. package/schema/models/userInviteCode.md +0 -23
  111. package/schema/models/userOnboarding.md +0 -14
  112. package/schema/models/userProjectAccess.md +0 -17
  113. package/schema/models/userReportEmail.md +0 -19
  114. package/schema/models/userReportSetting.md +0 -23
  115. package/schema/models/userReportToken.md +0 -18
  116. package/schema/models/userTag.md +0 -18
  117. package/schema/models/visionBoard.md +0 -21
  118. package/schema/models/visionBoardQuery.md +0 -22
  119. package/schema/models/wizard.md +0 -19
  120. package/schema/models/workflowItemHistory.md +0 -18
package/README.md CHANGED
@@ -13,7 +13,7 @@ npm install @codecks/fetch
13
13
  ```ts
14
14
  import {buildFetchers} from "@codecks/fetch";
15
15
 
16
- const {fetchFromRoot, fetchInstance, fetchInstances, fetchFromInstance} = buildFetchers({
16
+ const {fetchFromRoot, fetchInstance, fetchInstances, fetchFromInstance, dispatch} = buildFetchers({
17
17
  token: "cdxat_…",
18
18
  });
19
19
  ```
@@ -61,7 +61,7 @@ before then.
61
61
 
62
62
  ### `fetchFromRoot` — query top-level relations
63
63
 
64
- Use this to query entry points like `account`, `loggedInUser`, or `releases`.
64
+ Use this to query the entry points `account`, `loggedInUser` and `releases`.
65
65
 
66
66
  ```ts
67
67
  const result = await fetchFromRoot({
@@ -105,9 +105,8 @@ const account = result.account;
105
105
  // account has { ~model: "account", ~key: "1" }
106
106
 
107
107
  const details = await fetchFromInstance(account, {
108
- fields: ["seats", "activeProjectCount"],
109
108
  relations: {
110
- roles: {fields: ["role"]},
109
+ projects: {fields: ["name"]},
111
110
  },
112
111
  });
113
112
  ```
@@ -121,22 +120,19 @@ const result = await fetchFromRoot({
121
120
  account: {
122
121
  fields: ["name"],
123
122
  relations: {
124
- // belongsTo — returns a single object (or null if optional)
125
- disabledBy: {fields: ["name"]},
126
-
127
123
  // hasMany — returns an array
128
- roles: {
129
- fields: ["role"],
124
+ cards: {
125
+ fields: ["title"],
130
126
  relations: {
131
- user: {fields: ["name", "fullName"]},
127
+ // belongsTo — returns a single object (or null if optional)
128
+ assignee: {fields: ["name", "fullName"]},
132
129
  },
133
130
  },
134
131
  },
135
132
  },
136
133
  });
137
134
 
138
- // result.account.disabledBy?.name
139
- // result.account.roles[0].user.name
135
+ // result.account.cards[0].assignee?.name
140
136
  ```
141
137
 
142
138
  ## hasMany variants
@@ -147,32 +143,32 @@ hasMany relations support several query modes. Non-default variants require an `
147
143
 
148
144
  ```ts
149
145
  relations: {
150
- roles: {
151
- fields: ["role"],
152
- orderBy: "-accountId",
146
+ cards: {
147
+ fields: ["title"],
148
+ orderBy: "-createdAt",
153
149
  limit: 10,
154
150
  offset: 0,
155
151
  },
156
152
  }
157
- // result.roles: Array<{role: string, ...}>
153
+ // result.cards: Array<{title: string, ...}>
158
154
  ```
159
155
 
160
156
  ### Count
161
157
 
162
158
  ```ts
163
159
  relations: {
164
- roles: {type: "count", as: "roleCount"},
160
+ cards: {type: "count", as: "cardCount"},
165
161
  }
166
- // result.roleCount: number
162
+ // result.cardCount: number
167
163
  ```
168
164
 
169
165
  ### Exists
170
166
 
171
167
  ```ts
172
168
  relations: {
173
- releases: {type: "exists", as: "hasReleases"},
169
+ cards: {type: "exists", as: "hasCards"},
174
170
  }
175
- // result.hasReleases: boolean
171
+ // result.hasCards: boolean
176
172
  ```
177
173
 
178
174
  ### First
@@ -181,14 +177,14 @@ Returns a single result or `null`. Requires `orderBy`.
181
177
 
182
178
  ```ts
183
179
  relations: {
184
- roles: {
180
+ cards: {
185
181
  type: "first",
186
- as: "firstRole",
187
- orderBy: "-accountId",
188
- fields: ["role"],
182
+ as: "newestCard",
183
+ orderBy: "-createdAt",
184
+ fields: ["title"],
189
185
  },
190
186
  }
191
- // result.firstRole: {role: string, ...} | null
187
+ // result.newestCard: {title: string, ...} | null
192
188
  ```
193
189
 
194
190
  ### Multiple queries on the same relation
@@ -197,13 +193,13 @@ Pass an array of aliased queries to query the same relation in different ways:
197
193
 
198
194
  ```ts
199
195
  relations: {
200
- roles: [
201
- {as: "adminRoles", fields: ["role"], filter: {role: "admin"}},
202
- {as: "roleCount", type: "count"},
196
+ cards: [
197
+ {as: "startedCards", fields: ["title"], filter: {status: "started"}},
198
+ {as: "cardCount", type: "count"},
203
199
  ],
204
200
  }
205
- // result.adminRoles: Array<...>
206
- // result.roleCount: number
201
+ // result.startedCards: Array<...>
202
+ // result.cardCount: number
207
203
  ```
208
204
 
209
205
  ## Filtering
@@ -231,7 +227,7 @@ filter: {
231
227
 
232
228
  ```ts
233
229
  filter: {
234
- createdAt: {op: "gt", value: "2025-01-01"},
230
+ createdAt: {op: "gt", value: new Date("2025-01-01")},
235
231
  effort: {op: "lte", value: 5},
236
232
  }
237
233
  ```
@@ -328,14 +324,62 @@ const card = await fetchInstance("card", "card-123", {
328
324
 
329
325
  All response types are fully inferred from your query — TypeScript knows exactly which fields and relations are present.
330
326
 
327
+ ## Writing data
328
+
329
+ Every change is an action of the API, called with `dispatch(name, params)`. The name is the one
330
+ the [API Reference](https://manual.codecks.io/api-reference/#actions) lists, and the params and the
331
+ response are typed from it.
332
+
333
+ ```ts
334
+ const {id, accountSeq} = await dispatch("cards/create", {content: "Fix login\nDetails…", deckId});
335
+ await dispatch("cards/update", {id, status: "done", assigneeId: null});
336
+ ```
337
+
338
+ - **Optional and nullable params**: left out, a value stays as it is; `null` clears it.
339
+ - **Enums in params are closed**: `status: "snoozing"` is a type error, since the API only accepts
340
+ the listed values. Enums the API answers stay open, see [Field types](#field-types).
341
+ - **Response**: an action without one resolves to `undefined`.
342
+ - **Errors**: a refused action throws a `CodecksApiError` with the reason as its message, e.g.
343
+ `[403] requires card:write` for a read-only token. A missing scope has the `code`
344
+ `missing_scope` and the scope in `body.requiredScope`.
345
+
346
+ Each action's JSDoc holds its description and the token scopes it needs. `ActionMap`,
347
+ `ActionName`, `ActionParams<N>` and `ActionResponse<N>` are exported for wrapping `dispatch`.
348
+
349
+ `dispatch` doesn't change what the `fetch*` functions return: they always ask the API again.
350
+
351
+ ## Stability
352
+
353
+ The models and fields in this package are the ones the [API Reference](https://manual.codecks.io/api-reference/) documents. The API answers more than that, but anything undocumented is internal and can change without notice, so this package leaves it out.
354
+
355
+ - **stable** — changes only after a deprecation and 6 months' notice, see [Stability](https://manual.codecks.io/api/#stability).
356
+ - **preview** — may change in any release, listed in the [API changelog](https://manual.codecks.io/api-changelog/). The types mark these `@experimental`.
357
+ - **deprecated** — the types mark these `@deprecated`, with the removal date and what to use instead, so editors strike them through.
358
+
359
+ ## Field types
360
+
361
+ Field types come from the API Reference's schemas.
362
+
363
+ - **Enums are open unions**: `card.status` is `"not_started" | "started" | "snoozing" | "done" | (string & {})`. The values autocomplete, but the API may add new ones, so a `switch` over one isn't exhaustive. Keep a `default` branch.
364
+ - **Ids are nominal**: `CardId`, `UserId`, … can't be mixed up, also inside arrays and maps (`card.mentionedUsers: UserId[]`, `milestone.userCapacities: {[userId: UserId]: number}`).
365
+ - **Dates**: a top-level timestamp is a `Date`, a day is `{year, month, day}`, except a day that is part of a key (`milestoneProgress.date`), which stays a string. Inside a json value (e.g. an entry of an array field) they stay ISO strings.
366
+
367
+ The reference's named types and every id type are exported, so you can use them in your own code:
368
+
369
+ ```ts
370
+ import type {CardId, Checkbox, Priority, UserId} from "@codecks/fetch";
371
+ ```
372
+
331
373
  ## Schema reference for LLMs
332
374
 
333
- This package ships with generated markdown files describing every API model, its fields, and relations. These are designed for LLM-based tools (Claude Code, Cursor, Copilot, etc.) that need to discover the API schema without relying on TypeScript autocomplete.
375
+ This package ships with generated markdown files describing every documented API model, its fields, and relations, with the same stability markers. These are designed for LLM-based tools (Claude Code, Cursor, Copilot, etc.) that need to discover the API schema without relying on TypeScript autocomplete.
334
376
 
335
377
  ```
336
378
  node_modules/@codecks/fetch/schema/
337
379
  overview.md # Root entry points + index of all models
338
380
  query-syntax.md # Query DSL reference with examples
381
+ types.md # Named types (Priority, Checkbox, ...) the model files link to
382
+ actions.md # Every action with its params, response and required scopes
339
383
  models/
340
384
  card.md # Fields + relations for the card model
341
385
  account.md # Fields + relations for the account model
@@ -356,5 +400,9 @@ const {fetchFromRoot} = buildFetchersFromLoader({
356
400
  // your custom loading logic
357
401
  return recordOfResults;
358
402
  },
403
+ dispatch: async (name, params) => {
404
+ // POST params to `dispatch/${name}`, return the answer's `payload`
405
+ return payload;
406
+ },
359
407
  });
360
408
  ```
@@ -1,7 +1,6 @@
1
- import "../query-type-BqQ9oX_U.js";
2
- import "../index-k-KPWV9R.js";
3
- import { FetchOptions } from "../loader-utils-hvdC-xsQ.js";
4
- import { BaseRequester, MissingDataRequest } from "../loader-types-fd5tV0FD.js";
1
+ import "../query-type-CwrwqxUP.js";
2
+ import { FetchOptions } from "../loader-utils-DdrmVo0F.js";
3
+ import { BaseRequester, MissingDataRequest } from "../loader-types-CIO8hJAv.js";
5
4
 
6
5
  //#region src/_exploration/api-requester.d.ts
7
6
  declare class ApiRequester implements BaseRequester {
@@ -1,5 +1,5 @@
1
- import { bearerTransport, configuredFetch, ensureMapValue } from "../collection-utils-KmtGUuXm.js";
2
- import { serializeModel } from "../query-helpers-iX1fiqLv.js";
1
+ import { bearerTransport, configuredFetch, ensureMapValue } from "../collection-utils-y85xawyq.js";
2
+ import { serializeModel } from "../query-helpers-DndWBcMF.js";
3
3
 
4
4
  //#region src/_exploration/utils/concurrency-limiter.ts
5
5
  var ConcurrencyLimiter = class {