@better-giving/endowment 4.0.30 → 4.0.32

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
@@ -134,7 +134,7 @@ export declare class NpoDb extends Db {
134
134
  npo_med_update(npo: number, prev: IMedia, update: IMediaUpdate): Promise<Record<string, any>>;
135
135
  npo_med_delete(npo: number, mid: string): Promise<import("@aws-sdk/lib-dynamodb").DeleteCommandOutput>;
136
136
  npo<T extends TNpoDbKeys[]>(id: string | number, fields?: T): Promise<TNpoDbProjectedTo<T> | undefined>;
137
- npo_update_comps({ target, slug, social_media_urls, ...update }: INpoUpdate): UpdateComps;
137
+ npo_update_comps({ target, slug, social_media_urls, increments, ...update }: INpoUpdate): UpdateComps;
138
138
  npo_update(id: number, update: INpoUpdate): Promise<import("@aws-sdk/lib-dynamodb").UpdateCommandOutput>;
139
139
  npo_update_txi(id: number, update: INpoUpdate): TxType["Update"];
140
140
  prog_milestones(id: string): Promise<IMilestone[]>;
package/dist/db.mjs CHANGED
@@ -1,9 +1,10 @@
1
1
  import crypto from "node:crypto";
2
2
  import { BatchGetCommand, DeleteCommand, GetCommand, PutCommand, QueryCommand, TransactWriteCommand, UpdateCommand, } from "@aws-sdk/lib-dynamodb";
3
3
  import { Db, Txs, UpdateBuilder, } from "@better-giving/db";
4
+ import { projection } from "@better-giving/db/helpers";
4
5
  import KSUID from "ksuid";
5
6
  import { med_key_filter, med_sk, to_imedia } from "./media.mjs";
6
- import { projection } from "./npo.mjs";
7
+ import { npo_fields } from "./npo.mjs";
7
8
  export class NpoDb extends Db {
8
9
  static table = "endowments_v3";
9
10
  static slug_env_gsi = "slug-env-gsi";
@@ -56,7 +57,7 @@ export class NpoDb extends Db {
56
57
  gsi1SK: med_sk(id, type, featured),
57
58
  };
58
59
  }
59
- async npos_get(ids, fields) {
60
+ async npos_get(ids, fields = Object.keys(npo_fields)) {
60
61
  if (ids.length === 0)
61
62
  return [];
62
63
  const { names, expression } = projection(fields);
@@ -227,7 +228,7 @@ export class NpoDb extends Db {
227
228
  });
228
229
  return this.client.send(cmd);
229
230
  }
230
- async npo(id, fields) {
231
+ async npo(id, fields = Object.keys(npo_fields)) {
231
232
  const { names, expression } = projection(fields);
232
233
  if (typeof id === "string") {
233
234
  const cmd = new QueryCommand({
@@ -257,14 +258,19 @@ export class NpoDb extends Db {
257
258
  const { Item: i } = await this.client.send(cmd);
258
259
  return i ? this.sans_keys(i) : undefined;
259
260
  }
260
- npo_update_comps({ target, slug, social_media_urls, ...update }) {
261
+ npo_update_comps({ target, slug, social_media_urls, increments, ...update }) {
261
262
  const updates = new UpdateBuilder();
262
263
  if (slug)
263
264
  updates.set("slug", slug);
264
265
  if (slug === "")
265
266
  updates.remove("slug");
266
- if (target || target === "0") {
267
- updates.set("target", target);
267
+ if (increments) {
268
+ if (increments.length > 0) {
269
+ updates.set("increments", increments);
270
+ }
271
+ else {
272
+ updates.remove("increments");
273
+ }
268
274
  }
269
275
  if (social_media_urls) {
270
276
  for (const [k, v] of Object.entries(social_media_urls)) {
package/dist/npo.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export declare function projection(fields?: string[]): {
2
- expression: string;
3
- names: Record<string, string>;
1
+ import type { INpo } from "./schema.mjs";
2
+ export declare const npo_fields: {
3
+ [K in keyof Required<INpo>]: "";
4
4
  };
package/dist/npo.mjs CHANGED
@@ -1,4 +1,4 @@
1
- const npo_fields = {
1
+ export const npo_fields = {
2
2
  id: "",
3
3
  active_in_countries: "",
4
4
  endow_designation: "",
@@ -34,8 +34,3 @@ const npo_fields = {
34
34
  w_form: "",
35
35
  payout_minimum: "",
36
36
  };
37
- export function projection(fields = Object.keys(npo_fields)) {
38
- const expression = fields.map((n) => `#${n}`).join(",");
39
- const names = fields.reduce((prev, curr) => ({ ...prev, [`#${curr}`]: curr }), {});
40
- return { expression, names };
41
- }
package/dist/schema.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { $, $int_gte1, $req, donate_method_id, env, https_url, increment, int_gte1, MAX_NUM_INCREMENTS, target, org_designation, slug, unsdg_num, } from "@better-giving/schemas";
1
+ import { $, $int_gte1, $req, MAX_NUM_INCREMENTS, donate_method_id, env, https_url, increment, int_gte1, org_designation, slug, target, unsdg_num, } from "@better-giving/schemas";
2
2
  export { $, $req, $req_num_gt0, donate_method_id, env, https_url, int_gte1, $int_gte1, org_designation, slug, unsdg_num, } from "@better-giving/schemas";
3
3
  import * as v from "valibot";
4
4
  export const min_payout_amount = 50;
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@better-giving/endowment",
3
- "version": "4.0.30",
3
+ "version": "4.0.32",
4
4
  "dependencies": {
5
5
  "ksuid": "3.0.0"
6
6
  },
7
7
  "peerDependencies": {
8
+ "@better-giving/schemas": "2.0.4",
8
9
  "@better-giving/types": "1.1.8",
9
- "@better-giving/db": "2.0.6",
10
+ "@better-giving/db": "2.0.7",
10
11
  "@aws-sdk/lib-dynamodb": "3.485.0",
11
- "valibot": "0.42.0",
12
- "@better-giving/schemas": "2.0.4"
12
+ "valibot": "0.42.0"
13
13
  },
14
14
  "devDependencies": {
15
15
  "@better-giving/config": "1.1.2"
package/src/db.mts CHANGED
@@ -15,6 +15,7 @@ import {
15
15
  UpdateBuilder,
16
16
  type UpdateComps,
17
17
  } from "@better-giving/db";
18
+ import { projection } from "@better-giving/db/helpers";
18
19
  import KSUID from "ksuid";
19
20
  import type {
20
21
  IMedia,
@@ -28,7 +29,7 @@ import type {
28
29
  TNpoDbProjectedTo,
29
30
  } from "./interfaces.mjs";
30
31
  import { med_key_filter, med_sk, to_imedia } from "./media.mjs";
31
- import { projection } from "./npo.mjs";
32
+ import { npo_fields } from "./npo.mjs";
32
33
  import type {
33
34
  IMediaSearchObj,
34
35
  IMediaUpdate,
@@ -104,7 +105,7 @@ export class NpoDb extends Db {
104
105
 
105
106
  async npos_get<T extends TNpoDbKeys[]>(
106
107
  ids: number[],
107
- fields?: T
108
+ fields: T = Object.keys(npo_fields) as T
108
109
  ): Promise<TNpoDbProjectedTo<T>[]> {
109
110
  if (ids.length === 0) return [];
110
111
  const { names, expression } = projection(fields);
@@ -307,7 +308,7 @@ export class NpoDb extends Db {
307
308
 
308
309
  async npo<T extends TNpoDbKeys[]>(
309
310
  id: string | number,
310
- fields?: T
311
+ fields: T = Object.keys(npo_fields) as T
311
312
  ): Promise<TNpoDbProjectedTo<T> | undefined> {
312
313
  const { names, expression } = projection(fields);
313
314
 
@@ -345,6 +346,7 @@ export class NpoDb extends Db {
345
346
  target,
346
347
  slug,
347
348
  social_media_urls,
349
+ increments,
348
350
  ...update
349
351
  }: INpoUpdate): UpdateComps {
350
352
  const updates = new UpdateBuilder();
@@ -352,8 +354,12 @@ export class NpoDb extends Db {
352
354
  if (slug) updates.set("slug", slug);
353
355
  if (slug === "") updates.remove("slug");
354
356
 
355
- if (target || target === "0") {
356
- updates.set("target", target);
357
+ if (increments) {
358
+ if (increments.length > 0) {
359
+ updates.set("increments", increments);
360
+ } else {
361
+ updates.remove("increments");
362
+ }
357
363
  }
358
364
 
359
365
  if (social_media_urls) {
package/src/npo.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { INpo } from "./schema.mjs";
2
2
 
3
- const npo_fields: { [K in keyof Required<INpo>]: "" } = {
3
+ export const npo_fields: { [K in keyof Required<INpo>]: "" } = {
4
4
  id: "",
5
5
  active_in_countries: "",
6
6
  endow_designation: "",
@@ -36,12 +36,3 @@ const npo_fields: { [K in keyof Required<INpo>]: "" } = {
36
36
  w_form: "",
37
37
  payout_minimum: "",
38
38
  };
39
-
40
- export function projection(fields: string[] = Object.keys(npo_fields)) {
41
- const expression = fields.map((n) => `#${n}`).join(",");
42
- const names = fields.reduce(
43
- (prev, curr) => ({ ...prev, [`#${curr}`]: curr }),
44
- {} as Record<string, string>
45
- );
46
- return { expression, names };
47
- }
package/src/schema.mts CHANGED
@@ -2,15 +2,15 @@ import {
2
2
  $,
3
3
  $int_gte1,
4
4
  $req,
5
+ MAX_NUM_INCREMENTS,
5
6
  donate_method_id,
6
7
  env,
7
8
  https_url,
8
9
  increment,
9
10
  int_gte1,
10
- MAX_NUM_INCREMENTS,
11
- target,
12
11
  org_designation,
13
12
  slug,
13
+ target,
14
14
  unsdg_num,
15
15
  } from "@better-giving/schemas";
16
16
  export {