@better-giving/endowment 4.0.12 → 4.0.14

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/dist/db.d.mts CHANGED
@@ -37,6 +37,7 @@ export declare class NpoDb extends Db {
37
37
  gsi1PK: string;
38
38
  gsi1SK: string;
39
39
  };
40
+ npos_get<T extends TNpoDbKeys[]>(ids: number[], fields?: T): Promise<TNpoDbProjectedTo<T>[]>;
40
41
  npo_count_inc(): Promise<number>;
41
42
  npo_media(npo: number, opts: IMediaSearchObj): Promise<IMediaPage>;
42
43
  npo_referred_by(id: string): Promise<INpoReferredBy[]>;
@@ -110,6 +111,7 @@ export declare class NpoDb extends Db {
110
111
  SK: string;
111
112
  };
112
113
  prog_milestone_record(prog: string, data: IMilestoneNew): {
114
+ id: `${string}-${string}-${string}-${string}-${string}`;
113
115
  date: string;
114
116
  title: string;
115
117
  description: string;
package/dist/db.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { DeleteCommand, GetCommand, PutCommand, QueryCommand, TransactWriteCommand, UpdateCommand, } from "@aws-sdk/lib-dynamodb";
1
+ import { BatchGetCommand, DeleteCommand, GetCommand, PutCommand, QueryCommand, TransactWriteCommand, UpdateCommand, } from "@aws-sdk/lib-dynamodb";
2
2
  import { Db, Txs, UpdateBuilder } from "@better-giving/db";
3
3
  import KSUID from "ksuid";
4
4
  import { med_key_filter, med_sk, to_imedia } from "./media.mjs";
@@ -55,6 +55,20 @@ export class NpoDb extends Db {
55
55
  gsi1SK: med_sk(id, type, featured),
56
56
  };
57
57
  }
58
+ async npos_get(ids, fields) {
59
+ const { names, expression } = projection(fields);
60
+ const batch_get = new BatchGetCommand({
61
+ RequestItems: {
62
+ [NpoDb.name]: {
63
+ Keys: ids.map((id) => this.key_npo(id)),
64
+ ProjectionExpression: expression,
65
+ ExpressionAttributeNames: names,
66
+ },
67
+ },
68
+ });
69
+ const { Responses } = await this.client.send(batch_get);
70
+ return (Responses?.[NpoDb.name] ?? []);
71
+ }
58
72
  async npo_count_inc() {
59
73
  const cmd = new UpdateCommand({
60
74
  TableName: NpoDb.name,
@@ -152,6 +166,7 @@ export class NpoDb extends Db {
152
166
  return {
153
167
  ...this.key_prog_milestone(mid, prog),
154
168
  ...data,
169
+ id: mid,
155
170
  };
156
171
  }
157
172
  npo_med_record(npo_id, { featured /** not saved as attribute */, ...d }) {
@@ -291,13 +306,12 @@ export class NpoDb extends Db {
291
306
  return this.client.send(cmd);
292
307
  }
293
308
  async prog_milestone_put(pid, content) {
294
- const mid = crypto.randomUUID();
295
309
  const item = this.prog_milestone_record(pid, content);
296
310
  const cmd = new PutCommand({
297
311
  TableName: NpoDb.name,
298
312
  Item: item,
299
313
  });
300
- return this.client.send(cmd).then(() => mid);
314
+ return this.client.send(cmd).then(() => item.id);
301
315
  }
302
316
  async prog_milestone_update(pid, mid, update) {
303
317
  const upd8 = new UpdateBuilder();
package/dist/db2.d.mts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/dist/db2.mjs ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@better-giving/endowment",
3
- "version": "4.0.12",
3
+ "version": "4.0.14",
4
4
  "dependencies": {
5
5
  "ksuid": "3.0.0"
6
6
  },
7
7
  "peerDependencies": {
8
8
  "@better-giving/schemas": "2.0.0",
9
9
  "@better-giving/types": "1.1.8",
10
- "@better-giving/db": "2.0.0",
10
+ "@better-giving/db": "2.0.1",
11
11
  "@aws-sdk/lib-dynamodb": "3.485.0",
12
12
  "valibot": "0.42.0"
13
13
  },
package/src/db.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import {
2
+ BatchGetCommand,
2
3
  DeleteCommand,
3
4
  GetCommand,
4
5
  PutCommand,
@@ -94,6 +95,24 @@ export class NpoDb extends Db {
94
95
  };
95
96
  }
96
97
 
98
+ async npos_get<T extends TNpoDbKeys[]>(
99
+ ids: number[],
100
+ fields?: T
101
+ ): Promise<TNpoDbProjectedTo<T>[]> {
102
+ const { names, expression } = projection(fields);
103
+ const batch_get = new BatchGetCommand({
104
+ RequestItems: {
105
+ [NpoDb.name]: {
106
+ Keys: ids.map((id) => this.key_npo(id)),
107
+ ProjectionExpression: expression,
108
+ ExpressionAttributeNames: names,
109
+ },
110
+ },
111
+ });
112
+ const { Responses } = await this.client.send(batch_get);
113
+ return (Responses?.[NpoDb.name] ?? []) as any;
114
+ }
115
+
97
116
  async npo_count_inc(): Promise<number> {
98
117
  const cmd = new UpdateCommand({
99
118
  TableName: NpoDb.name,
@@ -206,7 +225,8 @@ export class NpoDb extends Db {
206
225
  return {
207
226
  ...this.key_prog_milestone(mid, prog),
208
227
  ...data,
209
- };
228
+ id: mid,
229
+ } satisfies IMilestone;
210
230
  }
211
231
 
212
232
  npo_med_record(
@@ -376,13 +396,12 @@ export class NpoDb extends Db {
376
396
  pid: string,
377
397
  content: IMilestoneNew
378
398
  ): Promise<string> {
379
- const mid = crypto.randomUUID();
380
399
  const item = this.prog_milestone_record(pid, content);
381
400
  const cmd = new PutCommand({
382
401
  TableName: NpoDb.name,
383
402
  Item: item,
384
403
  });
385
- return this.client.send(cmd).then(() => mid);
404
+ return this.client.send(cmd).then(() => item.id);
386
405
  }
387
406
 
388
407
  async prog_milestone_update(