@better-giving/fundraiser 3.0.14 → 3.0.15

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 (3) hide show
  1. package/dist/db.mjs +22 -16
  2. package/package.json +1 -1
  3. package/src/db.mts +27 -17
package/dist/db.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { BatchGetCommand, QueryCommand, UpdateCommand, } from "@aws-sdk/lib-dynamodb";
2
- import { Db, UpdateBuilder } from "@better-giving/db";
1
+ import { BatchGetCommand, GetCommand, QueryCommand, UpdateCommand, } from "@aws-sdk/lib-dynamodb";
2
+ import { Db, UpdateBuilder, } from "@better-giving/db";
3
3
  import { UUID_REGEX } from "valibot";
4
4
  export class FundDb extends Db {
5
5
  static table = "funds";
@@ -24,24 +24,30 @@ export class FundDb extends Db {
24
24
  }
25
25
  /**@param id - slug or uuid */
26
26
  async fund(id) {
27
- const q = {
28
- TableName: FundDb.table,
29
- Limit: 1,
30
- };
27
+ let item;
31
28
  if (UUID_REGEX.test(id)) {
32
- q.KeyConditionExpression = "PK = :PK AND SK = :SK";
33
- q.ExpressionAttributeValues = this.key_fund(id);
29
+ const cmd = new GetCommand({
30
+ TableName: FundDb.table,
31
+ Key: this.key_fund(id),
32
+ });
33
+ const res = await this.client.send(cmd);
34
+ item = res.Item;
34
35
  }
35
36
  else {
36
- q.IndexName = FundDb.slug_env_gsi;
37
- q.KeyConditionExpression = "slug = :slug AND env = :env";
38
- q.ExpressionAttributeValues = {
39
- ":slug": id,
40
- ":env": this.env,
41
- };
37
+ const cmd = new QueryCommand({
38
+ TableName: FundDb.table,
39
+ Limit: 1,
40
+ IndexName: FundDb.slug_env_gsi,
41
+ KeyConditionExpression: "slug = :slug AND env = :env",
42
+ ExpressionAttributeValues: {
43
+ ":slug": id,
44
+ ":env": this.env,
45
+ },
46
+ });
47
+ const { Items: i = [] } = await this.client.send(cmd);
48
+ item = i[0];
42
49
  }
43
- const { Items: i = [] } = await this.client.send(new QueryCommand(q));
44
- return i[0] && this.sans_keys(i[0]);
50
+ return item && this.sans_keys(item);
45
51
  }
46
52
  async funds_get(ids) {
47
53
  const cmd = new BatchGetCommand({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-giving/fundraiser",
3
- "version": "3.0.14",
3
+ "version": "3.0.15",
4
4
  "peerDependencies": {
5
5
  "valibot": "0.42.0",
6
6
  "@better-giving/schemas": "2.0.0",
package/src/db.mts CHANGED
@@ -1,10 +1,15 @@
1
1
  import {
2
2
  BatchGetCommand,
3
+ GetCommand,
3
4
  QueryCommand,
4
- type QueryCommandInput,
5
5
  UpdateCommand,
6
6
  } from "@aws-sdk/lib-dynamodb";
7
- import { Db, type TxType, UpdateBuilder } from "@better-giving/db";
7
+ import {
8
+ Db,
9
+ type TRecord,
10
+ type TxType,
11
+ UpdateBuilder,
12
+ } from "@better-giving/db";
8
13
  import { UUID_REGEX } from "valibot";
9
14
  import type { IFund } from "./interfaces.mjs";
10
15
  import type { IFundUpdate } from "./schema.mjs";
@@ -32,24 +37,29 @@ export class FundDb extends Db {
32
37
  }
33
38
  /**@param id - slug or uuid */
34
39
  async fund(id: string): Promise<IFund | undefined> {
35
- const q: QueryCommandInput = {
36
- TableName: FundDb.table,
37
- Limit: 1,
38
- };
40
+ let item: TRecord | undefined;
39
41
  if (UUID_REGEX.test(id)) {
40
- q.KeyConditionExpression = "PK = :PK AND SK = :SK";
41
- q.ExpressionAttributeValues = this.key_fund(id);
42
+ const cmd = new GetCommand({
43
+ TableName: FundDb.table,
44
+ Key: this.key_fund(id),
45
+ });
46
+ const res = await this.client.send(cmd);
47
+ item = res.Item;
42
48
  } else {
43
- q.IndexName = FundDb.slug_env_gsi;
44
- q.KeyConditionExpression = "slug = :slug AND env = :env";
45
- q.ExpressionAttributeValues = {
46
- ":slug": id,
47
- ":env": this.env,
48
- };
49
+ const cmd = new QueryCommand({
50
+ TableName: FundDb.table,
51
+ Limit: 1,
52
+ IndexName: FundDb.slug_env_gsi,
53
+ KeyConditionExpression: "slug = :slug AND env = :env",
54
+ ExpressionAttributeValues: {
55
+ ":slug": id,
56
+ ":env": this.env,
57
+ },
58
+ });
59
+ const { Items: i = [] } = await this.client.send(cmd);
60
+ item = i[0];
49
61
  }
50
-
51
- const { Items: i = [] } = await this.client.send(new QueryCommand(q));
52
- return i[0] && this.sans_keys(i[0]);
62
+ return item && this.sans_keys(item);
53
63
  }
54
64
 
55
65
  async funds_get(ids: string[]): Promise<IFund[]> {