firstly 0.9.2 → 0.9.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # firstly
2
2
 
3
+ ## 0.9.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [#352](https://github.com/jycouet/firstly/pull/352) [`53ec5e1`](https://github.com/jycouet/firstly/commit/53ec5e12f744ed207b9fce6fa80f3bc9b4918a92) Thanks [@jycouet](https://github.com/jycouet)! - feedback: `getIssues` returned nothing when `milestones.labels_filters` was unset (GitHub treats `labels: []` as "match nothing"); the filter is now omitted in that case.
8
+
9
+ ## 0.9.3
10
+
11
+ ### Patch Changes
12
+
13
+ - [#349](https://github.com/jycouet/firstly/pull/349) [`b285731`](https://github.com/jycouet/firstly/commit/b285731fe8e6cd41e5a257a044524486319e5544) Thanks [@jycouet](https://github.com/jycouet)! - feedback: `getIssues` now returns `labels` (names), `createdAt` and `updatedAt` per issue; `createIssue` accepts an optional `labels: string[]` applied on top of `create_label`.
14
+
15
+ - [#351](https://github.com/jycouet/firstly/pull/351) [`9701c40`](https://github.com/jycouet/firstly/commit/9701c404c7c2e6e2f94a7e3eab536b6a55d0c9c2) Thanks [@jycouet](https://github.com/jycouet)! - `withShortTermCache`: mutations (POST writes, PUT, PATCH, DELETE) now clear the cache once they settle, so a follow-up refresh no longer serves the pre-mutation read.
16
+
3
17
  ## 0.9.2
4
18
 
5
19
  ### Patch Changes
@@ -28,7 +28,8 @@ export type ShortTermCacheOptions = {
28
28
  * Middleware that dedupes identical read requests within a short TTL - a tiny
29
29
  * client-side cache. Two components mounting and issuing the same query result in
30
30
  * ONE network call; each caller gets its own `Response` clone. Failed requests are
31
- * evicted immediately so the next call retries.
31
+ * evicted immediately so the next call retries. Any mutation (non-GET that isn't a
32
+ * cached read) clears the cache once it settles, so a follow-up refresh sees fresh data.
32
33
  *
33
34
  * ```ts
34
35
  * remult.apiClient.httpClient = stackHttpClient(withShortTermCache({ ttlMs: 2000 }))
@@ -26,7 +26,8 @@ const defaultShouldCache = (_input, init, key) => {
26
26
  * Middleware that dedupes identical read requests within a short TTL - a tiny
27
27
  * client-side cache. Two components mounting and issuing the same query result in
28
28
  * ONE network call; each caller gets its own `Response` clone. Failed requests are
29
- * evicted immediately so the next call retries.
29
+ * evicted immediately so the next call retries. Any mutation (non-GET that isn't a
30
+ * cached read) clears the cache once it settles, so a follow-up refresh sees fresh data.
30
31
  *
31
32
  * ```ts
32
33
  * remult.apiClient.httpClient = stackHttpClient(withShortTermCache({ ttlMs: 2000 }))
@@ -48,7 +49,18 @@ export function withShortTermCache(opts = {}) {
48
49
  cacheKey = `${cacheKey}:${bodyStr}`;
49
50
  }
50
51
  if (!shouldCache(input, init, cacheKey)) {
51
- return next(input, init);
52
+ const method = init?.method?.toUpperCase() ?? 'GET';
53
+ if (method === 'GET')
54
+ return next(input, init);
55
+ // Mutation: drop cached reads once it settles (not before, so a read racing the
56
+ // write can't re-cache pre-mutation data). Cleared on error too: the server may
57
+ // have partially mutated.
58
+ try {
59
+ return await next(input, init);
60
+ }
61
+ finally {
62
+ cache.clear();
63
+ }
52
64
  }
53
65
  const now = Date.now();
54
66
  const cached = cache.get(cacheKey);
@@ -9,6 +9,10 @@ export declare class FeedbackController {
9
9
  number: number;
10
10
  titleHTML: string;
11
11
  state: string;
12
+ createdAt: string;
13
+ updatedAt: string;
14
+ /** GitHub label names. */
15
+ labels: string[];
12
16
  highlight: boolean;
13
17
  }[]>;
14
18
  static getIssue(issueNumber: number): Promise<{
@@ -27,7 +31,9 @@ export declare class FeedbackController {
27
31
  }>;
28
32
  static createIssue(milestoneId: string, title: string, body: string, metadata: {
29
33
  page: string;
30
- }): Promise<{
34
+ },
35
+ /** Extra label names applied on top of `create_label` (unknown names are ignored). */
36
+ labels?: string[]): Promise<{
31
37
  id: string;
32
38
  number: number;
33
39
  }>;
@@ -121,6 +121,8 @@ export class FeedbackController {
121
121
  number
122
122
  titleHTML
123
123
  state
124
+ createdAt
125
+ updatedAt
124
126
  labels(first:10){
125
127
  nodes {
126
128
  name
@@ -136,20 +138,27 @@ export class FeedbackController {
136
138
  owner: remult.context.feedbackOptions.repo.owner,
137
139
  milestoneNumber,
138
140
  filters: {
139
- labels: remult.context.feedbackOptions.milestones?.labels_filters ?? [],
141
+ // GitHub treats `labels: []` as "match nothing", so omit the key when unset.
142
+ labels: remult.context.feedbackOptions.milestones?.labels_filters?.length
143
+ ? remult.context.feedbackOptions.milestones.labels_filters
144
+ : undefined,
140
145
  states: [issueState],
141
146
  },
142
147
  issueOrder,
143
148
  });
144
149
  return data.repository.milestone.issues.nodes.map((issue) => {
150
+ const labels = issue.labels.nodes.map((label) => label.name);
145
151
  const hasWaitingForAnswerLabel = remult.context.feedbackOptions.highlight_label
146
- ? issue.labels.nodes.some((label) => label.name.includes(remult.context.feedbackOptions.highlight_label))
152
+ ? labels.some((name) => name.includes(remult.context.feedbackOptions.highlight_label))
147
153
  : false;
148
154
  return {
149
155
  id: issue.id,
150
156
  number: issue.number,
151
157
  titleHTML: issue.titleHTML,
152
158
  state: issue.state,
159
+ createdAt: issue.createdAt,
160
+ updatedAt: issue.updatedAt,
161
+ labels,
153
162
  highlight: hasWaitingForAnswerLabel,
154
163
  };
155
164
  });
@@ -231,7 +240,9 @@ repository(name: $repository, owner: $owner) {
231
240
  };
232
241
  return toRet;
233
242
  }
234
- static async createIssue(milestoneId, title, body, metadata) {
243
+ static async createIssue(milestoneId, title, body, metadata,
244
+ /** Extra label names applied on top of `create_label` (unknown names are ignored). */
245
+ labels = []) {
235
246
  const repoInfo = await getGitHub(`query RepoInfo(
236
247
  $repository: String!
237
248
  $owner: String!
@@ -250,7 +261,8 @@ repository(name: $repository, owner: $owner) {
250
261
  owner: remult.context.feedbackOptions.repo.owner,
251
262
  });
252
263
  const repoInfoData = repoInfo.repository;
253
- const create_label = repoInfoData.labels.nodes.find((c) => c.name === remult.context.feedbackOptions.create_label);
264
+ const wanted = new Set([remult.context.feedbackOptions.create_label, ...labels]);
265
+ const labelIds = repoInfoData.labels.nodes.filter((c) => wanted.has(c.name)).map((c) => c.id);
254
266
  const newIssue = await getGitHub(`mutation CreateIssue($input: CreateIssueInput!) {
255
267
  createIssue(input: $input) {
256
268
  issue {
@@ -263,7 +275,7 @@ repository(name: $repository, owner: $owner) {
263
275
  input: {
264
276
  repositoryId: repoInfoData.id,
265
277
  milestoneId: milestoneId,
266
- labelIds: [create_label?.id],
278
+ labelIds,
267
279
  title: title ?? 'New Feedback (wo title...)',
268
280
  body: body,
269
281
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firstly",
3
- "version": "0.9.2",
3
+ "version": "0.9.4",
4
4
  "type": "module",
5
5
  "description": "Firstly, an opinionated Remult setup!",
6
6
  "funding": "https://github.com/sponsors/jycouet",