@devwithbobby/loops 0.1.19 → 0.2.0

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 (37) hide show
  1. package/dist/client/index.d.ts +47 -12
  2. package/dist/client/index.d.ts.map +1 -1
  3. package/dist/client/index.js +42 -4
  4. package/dist/component/_generated/api.d.ts +185 -1
  5. package/dist/component/_generated/api.d.ts.map +1 -1
  6. package/dist/component/_generated/component.d.ts +12 -5
  7. package/dist/component/_generated/component.d.ts.map +1 -1
  8. package/dist/component/_generated/dataModel.d.ts +1 -1
  9. package/dist/component/aggregates.d.ts +42 -0
  10. package/dist/component/aggregates.d.ts.map +1 -0
  11. package/dist/component/aggregates.js +54 -0
  12. package/dist/component/convex.config.d.ts.map +1 -1
  13. package/dist/component/convex.config.js +2 -0
  14. package/dist/component/helpers.d.ts.map +1 -1
  15. package/dist/component/http.js +1 -1
  16. package/dist/component/lib.d.ts +66 -17
  17. package/dist/component/lib.d.ts.map +1 -1
  18. package/dist/component/lib.js +194 -73
  19. package/dist/component/schema.d.ts +2 -2
  20. package/dist/component/tables/contacts.d.ts.map +1 -1
  21. package/dist/component/tables/emailOperations.d.ts +4 -4
  22. package/dist/component/tables/emailOperations.d.ts.map +1 -1
  23. package/dist/test.d.ts +2 -2
  24. package/dist/types.d.ts +249 -62
  25. package/dist/types.d.ts.map +1 -1
  26. package/dist/types.js +4 -2
  27. package/dist/utils.d.ts +6 -6
  28. package/package.json +15 -9
  29. package/src/client/index.ts +52 -6
  30. package/src/component/_generated/api.ts +190 -1
  31. package/src/component/_generated/component.ts +10 -5
  32. package/src/component/_generated/dataModel.ts +1 -1
  33. package/src/component/aggregates.ts +89 -0
  34. package/src/component/convex.config.ts +3 -0
  35. package/src/component/http.ts +1 -1
  36. package/src/component/lib.ts +226 -89
  37. package/src/types.ts +20 -122
package/src/types.ts CHANGED
@@ -1,75 +1,28 @@
1
1
  import type {
2
- Expand,
3
- FunctionArgs,
4
- FunctionReference,
5
- FunctionReturnType,
6
- StorageActionWriter,
7
- StorageReader,
2
+ GenericActionCtx,
3
+ GenericDataModel,
4
+ GenericMutationCtx,
5
+ GenericQueryCtx,
8
6
  } from "convex/server";
9
- import type { GenericId } from "convex/values";
10
- import { internal } from "./component/_generated/api";
7
+ import { api } from "./component/_generated/api";
11
8
 
12
- export type RunQueryCtx = {
13
- runQuery: <Query extends FunctionReference<"query", "internal">>(
14
- query: Query,
15
- args: FunctionArgs<Query>,
16
- ) => Promise<FunctionReturnType<Query>>;
17
- };
9
+ // Convenient types for `ctx` args, that only include the bare minimum.
10
+ export type RunQueryCtx = Pick<GenericQueryCtx<GenericDataModel>, "runQuery">;
18
11
 
19
- export type RunMutationCtx = RunQueryCtx & {
20
- runMutation: <Mutation extends FunctionReference<"mutation", "internal">>(
21
- mutation: Mutation,
22
- args: FunctionArgs<Mutation>,
23
- ) => Promise<FunctionReturnType<Mutation>>;
24
- };
12
+ export type RunMutationCtx = Pick<
13
+ GenericMutationCtx<GenericDataModel>,
14
+ "runQuery" | "runMutation"
15
+ >;
25
16
 
26
- export type RunActionCtx = RunMutationCtx & {
27
- runAction<Action extends FunctionReference<"action", "internal">>(
28
- action: Action,
29
- args: FunctionArgs<Action>,
30
- ): Promise<FunctionReturnType<Action>>;
31
- };
32
-
33
- export type ActionCtx = RunActionCtx & {
34
- storage: StorageActionWriter;
35
- };
36
-
37
- export type QueryCtx = RunQueryCtx & {
38
- storage: StorageReader;
39
- };
40
-
41
- export type OpaqueIds<T> = T extends GenericId<infer _T>
42
- ? string
43
- : T extends (infer U)[]
44
- ? OpaqueIds<U>[]
45
- : T extends ArrayBuffer
46
- ? ArrayBuffer
47
- : T extends object
48
- ? {
49
- [K in keyof T]: OpaqueIds<T[K]>;
50
- }
51
- : T;
52
-
53
- export type UseApi<API> = Expand<{
54
- [mod in keyof API]: API[mod] extends FunctionReference<
55
- infer FType,
56
- "public",
57
- infer FArgs,
58
- infer FReturnType,
59
- infer FComponentPath
60
- >
61
- ? FunctionReference<
62
- FType,
63
- "internal",
64
- OpaqueIds<FArgs>,
65
- OpaqueIds<FReturnType>,
66
- FComponentPath
67
- >
68
- : UseApi<API[mod]>;
69
- }>;
17
+ export type RunActionCtx = Pick<
18
+ GenericActionCtx<GenericDataModel>,
19
+ "runQuery" | "runMutation" | "runAction"
20
+ >;
70
21
 
22
+ // Type for Headers constructor parameter
71
23
  export type HeadersInitParam = ConstructorParameters<typeof Headers>[0];
72
24
 
25
+ // Payload types for the Loops API
73
26
  export interface ContactPayload {
74
27
  email: string;
75
28
  firstName?: string;
@@ -108,61 +61,6 @@ export interface TriggerPayload {
108
61
  eventName?: string;
109
62
  }
110
63
 
111
- export type InternalActionRef<
112
- Args extends Record<string, unknown> = Record<string, unknown>,
113
- Result = unknown,
114
- > = FunctionReference<"action", "internal", Args, Result>;
115
-
116
- export type InternalMutationRef<
117
- Args extends Record<string, unknown> = Record<string, unknown>,
118
- Result = unknown,
119
- > = FunctionReference<"mutation", "internal", Args, Result>;
120
-
121
- export type InternalQueryRef<
122
- Args extends Record<string, unknown> = Record<string, unknown>,
123
- Result = unknown,
124
- > = FunctionReference<"query", "internal", Args, Result>;
125
-
126
- type AddContactArgs = {
127
- apiKey: string;
128
- contact: ContactPayload;
129
- };
130
-
131
- type AddContactResult = {
132
- success: boolean;
133
- id?: string;
134
- };
135
-
136
- export interface InternalActionLib {
137
- addContact: InternalActionRef<AddContactArgs, AddContactResult>;
138
- updateContact: InternalActionRef;
139
- findContact: InternalActionRef;
140
- deleteContact: InternalActionRef;
141
- sendTransactional: InternalActionRef;
142
- sendEvent: InternalActionRef;
143
- triggerLoop: InternalActionRef;
144
- batchCreateContacts: InternalActionRef;
145
- unsubscribeContact: InternalActionRef;
146
- resubscribeContact: InternalActionRef;
147
- storeContact: InternalMutationRef;
148
- removeContact: InternalMutationRef;
149
- logEmailOperation: InternalMutationRef;
150
- }
151
-
152
- export interface InternalQueryLib {
153
- countContacts: InternalQueryRef;
154
- listContacts: InternalQueryRef;
155
- detectRecipientSpam: InternalQueryRef;
156
- detectActorSpam: InternalQueryRef;
157
- getEmailStats: InternalQueryRef;
158
- detectRapidFirePatterns: InternalQueryRef;
159
- checkRecipientRateLimit: InternalQueryRef;
160
- checkActorRateLimit: InternalQueryRef;
161
- checkGlobalRateLimit: InternalQueryRef;
162
- }
163
-
164
- export type InternalLibReferences = InternalActionLib & InternalQueryLib;
165
-
166
- export const internalLib = (
167
- internal as unknown as { lib: InternalLibReferences }
168
- ).lib;
64
+ // Lib reference for component internals
65
+ // This is used internally by the component to call its own functions
66
+ export const internalLib = api.lib;