@better-giving/endowment 1.0.8 → 1.0.9

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
@@ -1,5 +1,9 @@
1
1
  import type { EndowId, Endowment as EndowmentShape, Environment, Milestone as MilestoneShape, MilestoneId, Program as ProgramShape, ProgramId } from "./schema.mjs";
2
2
  export type { EndowId, SocialMediaURLs, Allocation, Increment, EndowDesignation, Environment, ProgramId, } from "./schema.mjs";
3
+ export declare const gsi: {
4
+ readonly regnumEnv: "regnum-env-gsi";
5
+ readonly slugEnv: "slug-env-gsi";
6
+ };
3
7
  export declare namespace EndowCount {
4
8
  interface Keys {
5
9
  PK: "Count";
@@ -25,17 +29,18 @@ export declare namespace Endow {
25
29
  splitLiqPct?: number;
26
30
  /** @deprecated */
27
31
  splitFixed?: boolean;
32
+ /** @deprecated */
28
33
  sfCompounded?: boolean;
29
34
  };
30
35
  type DBRecord = Keys & NonKeyAttributes;
31
36
  }
32
37
  export declare namespace RegNumEnvGsi {
33
- type Name = "regnum-env-gsi";
38
+ type Name = typeof gsi.regnumEnv;
34
39
  type Keys = Pick<Endow.NonKeyAttributes, "registration_number" | "env">;
35
40
  type DBRecord = Keys & Endow.Keys & Pick<Endow.NonKeyAttributes, "claimed" | "name" | "hq_country" | "id">;
36
41
  }
37
42
  export declare namespace SlugEnvGsi {
38
- type Name = "slug-env-gsi";
43
+ type Name = typeof gsi.slugEnv;
39
44
  type Keys = Pick<Endow.NonKeyAttributes, "slug" | "env">;
40
45
  type DBRecord = Endow.DBRecord;
41
46
  }
package/dist/db.mjs CHANGED
@@ -1 +1,4 @@
1
- export {};
1
+ export const gsi = {
2
+ regnumEnv: "regnum-env-gsi",
3
+ slugEnv: "slug-env-gsi",
4
+ };
package/dist/schema.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { env, orgDesignation, unSdgNum } from "@better-giving/schemas";
2
2
  export { orgDesignation as endowDesignation, env, unSdgNum };
3
- import { url, array, boolean, check, custom, excludes, integer, isoDate, keyof, lazy, maxLength, maxValue, minLength, minValue, nonEmpty, nullish, number, object, omit, optional, partial, picklist, pipe, regex, string, transform, trim, uuid, startsWith, } from "valibot";
3
+ import { url, array, boolean, check, custom, excludes, integer, isoDate, keyof, lazy, maxLength, maxValue, minLength, minValue, nonEmpty, nullish, number, object, omit, optional, partial, picklist, pipe, regex, startsWith, string, transform, trim, uuid, } from "valibot";
4
4
  export const str = pipe(string(), trim());
5
5
  const pct = pipe(number(), integer(), minValue(0), maxValue(100));
6
6
  export const allocation = pipe(object({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-giving/endowment",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "peerDependencies": {
5
5
  "@better-giving/schemas": "1.0.1",
6
6
  "@better-giving/types": "1.0.1"
package/src/db.mts CHANGED
@@ -2,6 +2,8 @@ import type {
2
2
  EndowId,
3
3
  Endowment as EndowmentShape,
4
4
  Environment,
5
+ MediaId,
6
+ MediaType,
5
7
  Milestone as MilestoneShape,
6
8
  MilestoneId,
7
9
  Program as ProgramShape,
@@ -17,6 +19,11 @@ export type {
17
19
  ProgramId,
18
20
  } from "./schema.mjs";
19
21
 
22
+ export const endowGsi = {
23
+ regnumEnv: "regnum-env-gsi",
24
+ slugEnv: "slug-env-gsi",
25
+ } as const;
26
+
20
27
  export namespace EndowCount {
21
28
  export interface Keys {
22
29
  PK: "Count";
@@ -45,27 +52,28 @@ export namespace Endow {
45
52
  splitLiqPct?: number;
46
53
  /** @deprecated */
47
54
  splitFixed?: boolean;
55
+ /** @deprecated */
48
56
  sfCompounded?: boolean;
49
57
  };
50
58
 
51
- export type DBRecord = Keys & NonKeyAttributes;
59
+ export type DbRecord = Keys & NonKeyAttributes;
52
60
  }
53
61
 
54
62
  export namespace RegNumEnvGsi {
55
- export type Name = "regnum-env-gsi";
63
+ export type Name = typeof endowGsi.regnumEnv;
56
64
  export type Keys = Pick<
57
65
  Endow.NonKeyAttributes,
58
66
  "registration_number" | "env"
59
67
  >;
60
- export type DBRecord = Keys &
68
+ export type DbRecord = Keys &
61
69
  Endow.Keys &
62
70
  Pick<Endow.NonKeyAttributes, "claimed" | "name" | "hq_country" | "id">;
63
71
  }
64
72
 
65
73
  export namespace SlugEnvGsi {
66
- export type Name = "slug-env-gsi";
74
+ export type Name = typeof endowGsi.slugEnv;
67
75
  export type Keys = Pick<Endow.NonKeyAttributes, "slug" | "env">;
68
- export type DBRecord = Endow.DBRecord; //all attributes are copied to this index
76
+ export type DbRecord = Endow.DbRecord; //all attributes are copied to this index
69
77
  }
70
78
 
71
79
  export namespace Program {
@@ -78,7 +86,7 @@ export namespace Program {
78
86
  /** in USD */
79
87
  totalDonations?: number;
80
88
  };
81
- export type DBRecord = Keys & NonKeyAttributes;
89
+ export type DbRecord = Keys & NonKeyAttributes;
82
90
  }
83
91
 
84
92
  export namespace Milestone {
@@ -86,5 +94,39 @@ export namespace Milestone {
86
94
  PK: `Prog#${string}#${Environment}`;
87
95
  SK: `Mile#${MilestoneId}`;
88
96
  };
89
- export type DBRecord = Keys & MilestoneShape;
97
+ export type DbRecord = Keys & MilestoneShape;
98
+ }
99
+
100
+ export const mediaGsi = {
101
+ 1: "gsi1",
102
+ } as const;
103
+ export namespace Media {
104
+ export type Keys = {
105
+ PK: `Endow#${EndowId}#${Environment}`;
106
+ SK: `Media#${MediaId}`;
107
+ };
108
+
109
+ /** "0" - featured (goes before 1), "1" - not-featured */
110
+ export type FeaturedFlag = "0" | "1";
111
+ export type NonKeyAttributes = {
112
+ id: MediaId;
113
+ gsi1PK: Keys["PK"];
114
+ gsi1SK: `MediaList#${FeaturedFlag}#${MediaId}#${MediaType}`;
115
+ /** iso string */
116
+ dateCreated: string;
117
+ };
118
+
119
+ export type VideoAttributes = NonKeyAttributes & {
120
+ type: Extract<MediaType, "video">;
121
+ url: string;
122
+ };
123
+
124
+ export type VideoDbRecord = Keys & VideoAttributes;
125
+ export type DbRecord = VideoDbRecord; // | album | article
126
+
127
+ export namespace Gsi1 {
128
+ export type Name = (typeof mediaGsi)[1];
129
+ export type Keys = Pick<NonKeyAttributes, "gsi1PK" | "gsi1SK">;
130
+ export type DbRecord = Keys & NonKeyAttributes;
131
+ }
90
132
  }
package/src/index.mts CHANGED
@@ -18,11 +18,13 @@ export type {
18
18
  ProgramUpdate,
19
19
  SocialMediaURLs,
20
20
  UnSdgNum,
21
+ MediaQueryParams,
22
+ MediaType,
21
23
  } from "./schema.mjs";
22
24
  export type { FundItem };
23
25
 
24
26
  export type Endow = Pick<
25
- NEndow.DBRecord,
27
+ NEndow.DbRecord,
26
28
  | "id"
27
29
  | "slug"
28
30
  | "active_in_countries"
package/src/schema.mts CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  type InferInput,
11
11
  type InferOutput,
12
12
  array,
13
+ base64,
13
14
  boolean,
14
15
  check,
15
16
  custom,
@@ -32,11 +33,11 @@ import {
32
33
  picklist,
33
34
  pipe,
34
35
  regex,
36
+ startsWith,
35
37
  string,
36
38
  transform,
37
39
  trim,
38
40
  uuid,
39
- startsWith,
40
41
  } from "valibot";
41
42
 
42
43
  export const str = pipe(string(), trim());
@@ -290,3 +291,42 @@ export const programUpdate = partial(omit(newProgram, ["milestones"]));
290
291
  export type NewProgram = InferOutput<typeof newProgram>;
291
292
  export type Program = InferOutput<typeof program>;
292
293
  export type ProgramUpdate = InferOutput<typeof programUpdate>;
294
+
295
+ export const mediaUrl = pipe(str, url());
296
+ /**
297
+ * so that media is automatically sorted by date
298
+ * @see https://github.com/segmentio/ksuid
299
+ * */
300
+ export const mediaKsuid = pipe(str, nonEmpty() /** base62? */);
301
+ export const mediaTypes = ["album", "article", "video"] as const;
302
+ export const mediaType = picklist(mediaTypes);
303
+ export type MediaType = InferOutput<typeof mediaType>;
304
+
305
+ export const mediaUpdate = object({
306
+ url: optional(mediaUrl),
307
+ featured: optional(boolean()),
308
+ });
309
+
310
+ export type MediaId = InferOutput<typeof mediaKsuid>;
311
+
312
+ export const mediaQueryParams = object({
313
+ type: mediaType,
314
+ nextPageKey: optional(pipe(str, base64())),
315
+ featured: optional(
316
+ pipe(
317
+ str,
318
+ transform((x) => Boolean(x)),
319
+ boolean()
320
+ )
321
+ ),
322
+ limit: optional(
323
+ pipe(
324
+ string(),
325
+ transform((x) => +x),
326
+ number(),
327
+ integer(),
328
+ minValue(1)
329
+ )
330
+ ),
331
+ });
332
+ export type MediaQueryParams = InferInput<typeof mediaQueryParams>;