convex-helpers 0.1.20 → 0.1.22

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 (2) hide show
  1. package/README.md +15 -32
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -157,11 +157,10 @@ Example:
157
157
  ```js
158
158
  import { Table } from "convex-helpers/server";
159
159
  // Note some redefinitions in the import for even more terse definitions.
160
- import { literals, any, bigint, boolean, literal as is,
161
- id, null_, nullable, number, optional, partial, string, union as or,
162
- deprecated, array, object, brandedString,
160
+ import {
161
+ literals, partial, deprecated, brandedString,
163
162
  } from "convex-helpers/validators";
164
- import { assert, omit, pick } from "convex-helpers";
163
+ import { omit, pick } from "convex-helpers";
165
164
  import { Infer } from "convex/values";
166
165
 
167
166
  // Define a validator that requires an Email string type.
@@ -169,49 +168,28 @@ export const emailValidator = brandedString("email");
169
168
  // Define the Email type based on the branded string.
170
169
  export type Email = Infer<typeof emailValidator>;
171
170
 
172
- export const Users = Table("users", {
173
- name: string,
174
- age: number,
175
- nickname: optional(string),
176
- tokenIdentifier: string,
177
- preferences: optional(id("userPreferences")),
178
- balance: nullable(bigint),
179
- ephemeral: boolean,
171
+ export const Account = Table("accounts", {
172
+ balance: nullable(v.bigint()),
180
173
  status: literals("active", "inactive"),
181
- rawJSON: optional(any),
182
- loginType: or(
183
- object({
184
- type: is("email"),
185
- email: emailValidator,
186
- phone: null_,
187
- verified: boolean,
188
- }),
189
- object({
190
- type: is("phone"),
191
- phone: string,
192
- email: null_,
193
- verified: boolean,
194
- })
195
- ),
196
- logs: or(string, array(string)),
174
+ email: emailValidator,
197
175
 
198
176
  oldField: deprecated,
199
177
  });
200
178
 
201
179
  // convex/schema.ts
202
180
  export default defineSchema({
203
- users: Users.table.index("tokenIdentifier", ["tokenIdentifier"]),
181
+ accounts: Account.table.index("status", ["status"]),
204
182
  //...
205
183
  });
206
184
 
207
185
  // some module
208
186
  export const replaceUser = internalMutation({
209
187
  args: {
210
- id: id("users"),
188
+ id: Account._id,
211
189
  replace: object({
212
190
  // You can provide the document with or without system fields.
213
- ...Users.withoutSystemFields,
214
- ...partial(Users.systemFields),
191
+ ...Account.withoutSystemFields,
192
+ ...partial(Account.systemFields),
215
193
  }),
216
194
  },
217
195
  handler: async (ctx, args) => {
@@ -219,4 +197,9 @@ export const replaceUser = internalMutation({
219
197
  },
220
198
  });
221
199
 
200
+ // A validator just for balance & email: { balance: v.union(...), email: ..}
201
+ const balanceAndEmail = pick(Account.withoutSystemFields, ["balance", "email"]);
202
+
203
+ // A validator for all the fields except balance.
204
+ const accountWithoutBalance = omit(Account.withSystemFields, ["balance"]);
222
205
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "convex-helpers",
3
- "version": "0.1.20",
3
+ "version": "0.1.22",
4
4
  "description": "A collection of useful code to complement the official convex package.",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
@@ -48,7 +48,7 @@
48
48
  },
49
49
  "homepage": "https://github.com/get-convex/convex-helpers/tree/main/packages/convex-helpers/README.md",
50
50
  "peerDependencies": {
51
- "convex": "^1.8.0",
51
+ "convex": "^1.9.1",
52
52
  "react": "^17.0.2 || ^18.0.0",
53
53
  "zod": "^3.22.4"
54
54
  },