@devwithbobby/loops 0.1.18 → 0.1.19
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/client/index.d.ts +91 -96
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +13 -6
- package/dist/component/_generated/api.d.ts +44 -0
- package/dist/component/_generated/api.d.ts.map +1 -0
- package/{src → dist}/component/_generated/api.js +10 -3
- package/dist/component/_generated/component.d.ts +259 -0
- package/dist/component/_generated/component.d.ts.map +1 -0
- package/dist/component/_generated/component.js +9 -0
- package/dist/component/_generated/dataModel.d.ts +46 -0
- package/dist/component/_generated/dataModel.d.ts.map +1 -0
- package/dist/component/_generated/dataModel.js +10 -0
- package/{src → dist}/component/_generated/server.d.ts +10 -38
- package/dist/component/_generated/server.d.ts.map +1 -0
- package/{src → dist}/component/_generated/server.js +9 -22
- package/dist/component/convex.config.d.ts.map +1 -1
- package/dist/component/convex.config.js +0 -22
- package/dist/component/helpers.d.ts +1 -1
- package/dist/component/helpers.d.ts.map +1 -1
- package/dist/component/helpers.js +1 -2
- package/dist/test.d.ts +83 -0
- package/dist/test.d.ts.map +1 -0
- package/dist/test.js +16 -0
- package/package.json +15 -9
- package/src/client/index.ts +18 -13
- package/src/component/_generated/api.ts +60 -0
- package/src/component/_generated/component.ts +323 -0
- package/src/component/_generated/{dataModel.d.ts → dataModel.ts} +1 -1
- package/src/component/_generated/server.ts +161 -0
- package/src/component/convex.config.ts +0 -27
- package/src/component/helpers.ts +2 -2
- package/src/test.ts +27 -0
- package/src/component/_generated/api.d.ts +0 -47
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/**
|
|
3
|
+
* Generated utilities for implementing server-side Convex query and mutation functions.
|
|
4
|
+
*
|
|
5
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
6
|
+
*
|
|
7
|
+
* To regenerate, run `npx convex dev`.
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type {
|
|
12
|
+
ActionBuilder,
|
|
13
|
+
HttpActionBuilder,
|
|
14
|
+
MutationBuilder,
|
|
15
|
+
QueryBuilder,
|
|
16
|
+
GenericActionCtx,
|
|
17
|
+
GenericMutationCtx,
|
|
18
|
+
GenericQueryCtx,
|
|
19
|
+
GenericDatabaseReader,
|
|
20
|
+
GenericDatabaseWriter,
|
|
21
|
+
} from "convex/server";
|
|
22
|
+
import {
|
|
23
|
+
actionGeneric,
|
|
24
|
+
httpActionGeneric,
|
|
25
|
+
queryGeneric,
|
|
26
|
+
mutationGeneric,
|
|
27
|
+
internalActionGeneric,
|
|
28
|
+
internalMutationGeneric,
|
|
29
|
+
internalQueryGeneric,
|
|
30
|
+
} from "convex/server";
|
|
31
|
+
import type { DataModel } from "./dataModel.js";
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Define a query in this Convex app's public API.
|
|
35
|
+
*
|
|
36
|
+
* This function will be allowed to read your Convex database and will be accessible from the client.
|
|
37
|
+
*
|
|
38
|
+
* @param func - The query function. It receives a {@link QueryCtx} as its first argument.
|
|
39
|
+
* @returns The wrapped query. Include this as an `export` to name it and make it accessible.
|
|
40
|
+
*/
|
|
41
|
+
export const query: QueryBuilder<DataModel, "public"> = queryGeneric;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Define a query that is only accessible from other Convex functions (but not from the client).
|
|
45
|
+
*
|
|
46
|
+
* This function will be allowed to read from your Convex database. It will not be accessible from the client.
|
|
47
|
+
*
|
|
48
|
+
* @param func - The query function. It receives a {@link QueryCtx} as its first argument.
|
|
49
|
+
* @returns The wrapped query. Include this as an `export` to name it and make it accessible.
|
|
50
|
+
*/
|
|
51
|
+
export const internalQuery: QueryBuilder<DataModel, "internal"> =
|
|
52
|
+
internalQueryGeneric;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Define a mutation in this Convex app's public API.
|
|
56
|
+
*
|
|
57
|
+
* This function will be allowed to modify your Convex database and will be accessible from the client.
|
|
58
|
+
*
|
|
59
|
+
* @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
|
|
60
|
+
* @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
|
|
61
|
+
*/
|
|
62
|
+
export const mutation: MutationBuilder<DataModel, "public"> = mutationGeneric;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Define a mutation that is only accessible from other Convex functions (but not from the client).
|
|
66
|
+
*
|
|
67
|
+
* This function will be allowed to modify your Convex database. It will not be accessible from the client.
|
|
68
|
+
*
|
|
69
|
+
* @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
|
|
70
|
+
* @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
|
|
71
|
+
*/
|
|
72
|
+
export const internalMutation: MutationBuilder<DataModel, "internal"> =
|
|
73
|
+
internalMutationGeneric;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Define an action in this Convex app's public API.
|
|
77
|
+
*
|
|
78
|
+
* An action is a function which can execute any JavaScript code, including non-deterministic
|
|
79
|
+
* code and code with side-effects, like calling third-party services.
|
|
80
|
+
* They can be run in Convex's JavaScript environment or in Node.js using the "use node" directive.
|
|
81
|
+
* They can interact with the database indirectly by calling queries and mutations using the {@link ActionCtx}.
|
|
82
|
+
*
|
|
83
|
+
* @param func - The action. It receives an {@link ActionCtx} as its first argument.
|
|
84
|
+
* @returns The wrapped action. Include this as an `export` to name it and make it accessible.
|
|
85
|
+
*/
|
|
86
|
+
export const action: ActionBuilder<DataModel, "public"> = actionGeneric;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Define an action that is only accessible from other Convex functions (but not from the client).
|
|
90
|
+
*
|
|
91
|
+
* @param func - The function. It receives an {@link ActionCtx} as its first argument.
|
|
92
|
+
* @returns The wrapped function. Include this as an `export` to name it and make it accessible.
|
|
93
|
+
*/
|
|
94
|
+
export const internalAction: ActionBuilder<DataModel, "internal"> =
|
|
95
|
+
internalActionGeneric;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Define an HTTP action.
|
|
99
|
+
*
|
|
100
|
+
* The wrapped function will be used to respond to HTTP requests received
|
|
101
|
+
* by a Convex deployment if the requests matches the path and method where
|
|
102
|
+
* this action is routed. Be sure to route your httpAction in `convex/http.js`.
|
|
103
|
+
*
|
|
104
|
+
* @param func - The function. It receives an {@link ActionCtx} as its first argument
|
|
105
|
+
* and a Fetch API `Request` object as its second.
|
|
106
|
+
* @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
|
|
107
|
+
*/
|
|
108
|
+
export const httpAction: HttpActionBuilder = httpActionGeneric;
|
|
109
|
+
|
|
110
|
+
type GenericCtx =
|
|
111
|
+
| GenericActionCtx<DataModel>
|
|
112
|
+
| GenericMutationCtx<DataModel>
|
|
113
|
+
| GenericQueryCtx<DataModel>;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* A set of services for use within Convex query functions.
|
|
117
|
+
*
|
|
118
|
+
* The query context is passed as the first argument to any Convex query
|
|
119
|
+
* function run on the server.
|
|
120
|
+
*
|
|
121
|
+
* If you're using code generation, use the `QueryCtx` type in `convex/_generated/server.d.ts` instead.
|
|
122
|
+
*/
|
|
123
|
+
export type QueryCtx = GenericQueryCtx<DataModel>;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* A set of services for use within Convex mutation functions.
|
|
127
|
+
*
|
|
128
|
+
* The mutation context is passed as the first argument to any Convex mutation
|
|
129
|
+
* function run on the server.
|
|
130
|
+
*
|
|
131
|
+
* If you're using code generation, use the `MutationCtx` type in `convex/_generated/server.d.ts` instead.
|
|
132
|
+
*/
|
|
133
|
+
export type MutationCtx = GenericMutationCtx<DataModel>;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* A set of services for use within Convex action functions.
|
|
137
|
+
*
|
|
138
|
+
* The action context is passed as the first argument to any Convex action
|
|
139
|
+
* function run on the server.
|
|
140
|
+
*/
|
|
141
|
+
export type ActionCtx = GenericActionCtx<DataModel>;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* An interface to read from the database within Convex query functions.
|
|
145
|
+
*
|
|
146
|
+
* The two entry points are {@link DatabaseReader.get}, which fetches a single
|
|
147
|
+
* document by its {@link Id}, or {@link DatabaseReader.query}, which starts
|
|
148
|
+
* building a query.
|
|
149
|
+
*/
|
|
150
|
+
export type DatabaseReader = GenericDatabaseReader<DataModel>;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* An interface to read from and write to the database within Convex mutation
|
|
154
|
+
* functions.
|
|
155
|
+
*
|
|
156
|
+
* Convex guarantees that all writes within a single mutation are
|
|
157
|
+
* executed atomically, so you never have to worry about partial writes leaving
|
|
158
|
+
* your data in an inconsistent state. See [the Convex Guide](https://docs.convex.dev/understanding/convex-fundamentals/functions#atomicity-and-optimistic-concurrency-control)
|
|
159
|
+
* for the guarantees Convex provides your functions.
|
|
160
|
+
*/
|
|
161
|
+
export type DatabaseWriter = GenericDatabaseWriter<DataModel>;
|
|
@@ -1,32 +1,5 @@
|
|
|
1
1
|
import { defineComponent } from "convex/server";
|
|
2
|
-
import { api } from "./_generated/api";
|
|
3
2
|
|
|
4
3
|
const component = defineComponent("loops");
|
|
5
4
|
|
|
6
|
-
type ExportableComponent = typeof component & {
|
|
7
|
-
export: (apiRef: typeof api, functions: Record<string, unknown>) => void;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
(component as ExportableComponent).export(api, {
|
|
11
|
-
addContact: api.lib.addContact,
|
|
12
|
-
updateContact: api.lib.updateContact,
|
|
13
|
-
findContact: api.lib.findContact,
|
|
14
|
-
batchCreateContacts: api.lib.batchCreateContacts,
|
|
15
|
-
unsubscribeContact: api.lib.unsubscribeContact,
|
|
16
|
-
resubscribeContact: api.lib.resubscribeContact,
|
|
17
|
-
countContacts: api.lib.countContacts,
|
|
18
|
-
listContacts: api.lib.listContacts,
|
|
19
|
-
sendTransactional: api.lib.sendTransactional,
|
|
20
|
-
sendEvent: api.lib.sendEvent,
|
|
21
|
-
triggerLoop: api.lib.triggerLoop,
|
|
22
|
-
deleteContact: api.lib.deleteContact,
|
|
23
|
-
detectRecipientSpam: api.lib.detectRecipientSpam,
|
|
24
|
-
detectActorSpam: api.lib.detectActorSpam,
|
|
25
|
-
getEmailStats: api.lib.getEmailStats,
|
|
26
|
-
detectRapidFirePatterns: api.lib.detectRapidFirePatterns,
|
|
27
|
-
checkRecipientRateLimit: api.lib.checkRecipientRateLimit,
|
|
28
|
-
checkActorRateLimit: api.lib.checkActorRateLimit,
|
|
29
|
-
checkGlobalRateLimit: api.lib.checkGlobalRateLimit,
|
|
30
|
-
});
|
|
31
|
-
|
|
32
5
|
export default component;
|
package/src/component/helpers.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { HeadersInitParam } from "../types";
|
|
2
2
|
|
|
3
3
|
const allowedOrigin =
|
|
4
4
|
process.env.CONVEX_URL ??
|
|
@@ -82,7 +82,7 @@ export const emptyResponse = (init?: ResponseInit) => {
|
|
|
82
82
|
export const readJsonBody = async <T>(request: Request): Promise<T> => {
|
|
83
83
|
try {
|
|
84
84
|
return (await request.json()) as T;
|
|
85
|
-
} catch (
|
|
85
|
+
} catch (_error) {
|
|
86
86
|
throw new Error("Invalid JSON body");
|
|
87
87
|
}
|
|
88
88
|
};
|
package/src/test.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { TestConvex } from "convex-test";
|
|
2
|
+
import type { GenericSchema, SchemaDefinition } from "convex/server";
|
|
3
|
+
import schema from "./component/schema.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Register the Loops component with the test convex instance.
|
|
7
|
+
*
|
|
8
|
+
* @param t - The test convex instance from convexTest().
|
|
9
|
+
* @param name - The name of the component as registered in convex.config.ts.
|
|
10
|
+
* @param modules - The modules object from import.meta.glob. Required.
|
|
11
|
+
*/
|
|
12
|
+
export function register(
|
|
13
|
+
t: TestConvex<SchemaDefinition<GenericSchema, boolean>>,
|
|
14
|
+
name: string = "loops",
|
|
15
|
+
modules?: Record<string, () => Promise<unknown>>,
|
|
16
|
+
) {
|
|
17
|
+
if (!modules) {
|
|
18
|
+
throw new Error(
|
|
19
|
+
"modules parameter is required. Pass import.meta.glob from your test file.",
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
t.registerComponent(name, schema, modules);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { schema };
|
|
26
|
+
|
|
27
|
+
export default { register, schema };
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
/**
|
|
3
|
-
* Generated `api` utility.
|
|
4
|
-
*
|
|
5
|
-
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
6
|
-
*
|
|
7
|
-
* To regenerate, run `npx convex dev`.
|
|
8
|
-
* @module
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import type * as lib from "../lib.js";
|
|
12
|
-
|
|
13
|
-
import type {
|
|
14
|
-
ApiFromModules,
|
|
15
|
-
FilterApi,
|
|
16
|
-
FunctionReference,
|
|
17
|
-
} from "convex/server";
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* A utility for referencing Convex functions in your app's API.
|
|
21
|
-
*
|
|
22
|
-
* Usage:
|
|
23
|
-
* ```js
|
|
24
|
-
* const myFunctionReference = api.myModule.myFunction;
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
declare const fullApi: ApiFromModules<{
|
|
28
|
-
lib: typeof lib;
|
|
29
|
-
}>;
|
|
30
|
-
export type Mounts = ApiFromModules<{
|
|
31
|
-
lib: typeof lib;
|
|
32
|
-
}>;
|
|
33
|
-
// For now fullApiWithMounts is only fullApi which provides
|
|
34
|
-
// jump-to-definition in component client code.
|
|
35
|
-
// Use Mounts for the same type without the inference.
|
|
36
|
-
declare const fullApiWithMounts: typeof fullApi;
|
|
37
|
-
|
|
38
|
-
export declare const api: FilterApi<
|
|
39
|
-
typeof fullApiWithMounts,
|
|
40
|
-
FunctionReference<any, "public">
|
|
41
|
-
>;
|
|
42
|
-
export declare const internal: FilterApi<
|
|
43
|
-
typeof fullApiWithMounts,
|
|
44
|
-
FunctionReference<any, "internal">
|
|
45
|
-
>;
|
|
46
|
-
|
|
47
|
-
export declare const components: {};
|