firstly 0.9.1 → 0.9.3

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.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#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`.
8
+
9
+ - [#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.
10
+
11
+ ## 0.9.2
12
+
13
+ ### Patch Changes
14
+
15
+ - [#347](https://github.com/jycouet/firstly/pull/347) [`2a6576c`](https://github.com/jycouet/firstly/commit/2a6576ce7955ad73b38b3c07a3daf7c0fde78525) Thanks [@jycouet](https://github.com/jycouet)! - fix(sqlAdmin): read-only queries no longer fail with "nested transactions not allowed" on Postgres
16
+
3
17
  ## 0.9.1
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
@@ -142,14 +144,18 @@ export class FeedbackController {
142
144
  issueOrder,
143
145
  });
144
146
  return data.repository.milestone.issues.nodes.map((issue) => {
147
+ const labels = issue.labels.nodes.map((label) => label.name);
145
148
  const hasWaitingForAnswerLabel = remult.context.feedbackOptions.highlight_label
146
- ? issue.labels.nodes.some((label) => label.name.includes(remult.context.feedbackOptions.highlight_label))
149
+ ? labels.some((name) => name.includes(remult.context.feedbackOptions.highlight_label))
147
150
  : false;
148
151
  return {
149
152
  id: issue.id,
150
153
  number: issue.number,
151
154
  titleHTML: issue.titleHTML,
152
155
  state: issue.state,
156
+ createdAt: issue.createdAt,
157
+ updatedAt: issue.updatedAt,
158
+ labels,
153
159
  highlight: hasWaitingForAnswerLabel,
154
160
  };
155
161
  });
@@ -231,7 +237,9 @@ repository(name: $repository, owner: $owner) {
231
237
  };
232
238
  return toRet;
233
239
  }
234
- static async createIssue(milestoneId, title, body, metadata) {
240
+ static async createIssue(milestoneId, title, body, metadata,
241
+ /** Extra label names applied on top of `create_label` (unknown names are ignored). */
242
+ labels = []) {
235
243
  const repoInfo = await getGitHub(`query RepoInfo(
236
244
  $repository: String!
237
245
  $owner: String!
@@ -250,7 +258,8 @@ repository(name: $repository, owner: $owner) {
250
258
  owner: remult.context.feedbackOptions.repo.owner,
251
259
  });
252
260
  const repoInfoData = repoInfo.repository;
253
- const create_label = repoInfoData.labels.nodes.find((c) => c.name === remult.context.feedbackOptions.create_label);
261
+ const wanted = new Set([remult.context.feedbackOptions.create_label, ...labels]);
262
+ const labelIds = repoInfoData.labels.nodes.filter((c) => wanted.has(c.name)).map((c) => c.id);
254
263
  const newIssue = await getGitHub(`mutation CreateIssue($input: CreateIssueInput!) {
255
264
  createIssue(input: $input) {
256
265
  issue {
@@ -263,7 +272,7 @@ repository(name: $repository, owner: $owner) {
263
272
  input: {
264
273
  repositoryId: repoInfoData.id,
265
274
  milestoneId: milestoneId,
266
- labelIds: [create_label?.id],
275
+ labelIds,
267
276
  title: title ?? 'New Feedback (wo title...)',
268
277
  body: body,
269
278
  },
@@ -21,17 +21,14 @@ export class SqlAdminController {
21
21
  const db = SqlAdminController.dp ?? SqlDatabase.getDb();
22
22
  const start = performance.now();
23
23
  let rows = [];
24
- if (notReadOnly) {
25
- rows = (await db.execute(cmd)).rows;
26
- }
27
- else {
28
- await db.transaction(async (tx) => {
29
- const txDb = SqlDatabase.getDb(tx);
30
- // Postgres: makes the whole transaction reject writes at the DB level.
24
+ // One transaction either way: a failing multi-statement script leaves nothing behind.
25
+ await db.transaction(async (tx) => {
26
+ const txDb = SqlDatabase.getDb(tx);
27
+ // Postgres: makes the whole transaction reject writes at the DB level.
28
+ if (!notReadOnly)
31
29
  await txDb.execute('SET TRANSACTION READ ONLY');
32
- rows = (await txDb.execute(cmd)).rows;
33
- });
34
- }
30
+ rows = (await txDb.execute(cmd)).rows;
31
+ });
35
32
  const took = performance.now() - start;
36
33
  return { rows, rowCount: rows.length, took };
37
34
  }
@@ -40,5 +37,8 @@ __decorate([
40
37
  BackendMethod({
41
38
  allowed: [Roles_SqlAdmin.SqlAdmin_Admin, FF_Role.FF_Role_Admin],
42
39
  apiPrefix: 'ff/sqlAdmin',
40
+ // Remult wraps BackendMethods in a transaction by default; ours would then be
41
+ // nested, which Postgres rejects. We open our own below instead.
42
+ transactional: false,
43
43
  })
44
44
  ], SqlAdminController, "exec", null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firstly",
3
- "version": "0.9.1",
3
+ "version": "0.9.3",
4
4
  "type": "module",
5
5
  "description": "Firstly, an opinionated Remult setup!",
6
6
  "funding": "https://github.com/sponsors/jycouet",