@better-giving/endowment 4.0.30 → 4.0.31

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.mjs CHANGED
@@ -3,7 +3,8 @@ import { BatchGetCommand, DeleteCommand, GetCommand, PutCommand, QueryCommand, T
3
3
  import { Db, Txs, UpdateBuilder, } from "@better-giving/db";
4
4
  import KSUID from "ksuid";
5
5
  import { med_key_filter, med_sk, to_imedia } from "./media.mjs";
6
- import { projection } from "./npo.mjs";
6
+ import { npo_fields } from "./npo.mjs";
7
+ import { projection } from "@better-giving/db/helpers";
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({
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.31",
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
@@ -28,7 +28,6 @@ import type {
28
28
  TNpoDbProjectedTo,
29
29
  } from "./interfaces.mjs";
30
30
  import { med_key_filter, med_sk, to_imedia } from "./media.mjs";
31
- import { projection } from "./npo.mjs";
32
31
  import type {
33
32
  IMediaSearchObj,
34
33
  IMediaUpdate,
@@ -43,6 +42,8 @@ import type {
43
42
  IProgramUpdate,
44
43
  TMediaType,
45
44
  } from "./schema.mjs";
45
+ import { npo_fields } from "./npo.mjs";
46
+ import { projection } from "@better-giving/db/helpers";
46
47
 
47
48
  export class NpoDb extends Db {
48
49
  static readonly table = "endowments_v3";
@@ -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
 
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 {