@bb-labs/convex-helpers 0.0.1 → 0.0.3

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.
@@ -0,0 +1,11 @@
1
+ $ bldr
2
+
3
+ [bldr] • project: ./tsconfig.json
4
+ [bldr] → rootDir : ./src
5
+ [bldr] → outDir : ./dist
6
+ [bldr] ▶ mode : build
7
+
8
+ ⌫ cleaning output directory...
9
+ ✓ output directory cleaned
10
+ ▶ starting build...
11
+ ✓ [bldr] build completed successfully!
package/README.md CHANGED
@@ -1,67 +1,43 @@
1
1
  ## Introduction
2
2
 
3
- A tiny utility that **deeply normalizes** JavaScript values by:
4
-
5
- - ✅ Recursively sorting **object keys**
6
- - ✅ Recursively sorting **arrays** using **SuperJSON** for deterministic comparison
7
- - ✅ Preserving non-plain objects (`Date`, `Map`, `Set`, `BigInt`, class instances, etc.)
8
- - ⚡ Perfect for generating cache keys, hashing structured data, or stabilizing query arguments
9
-
10
- The goal:
11
- **Identical structures always produce identical normalized output — even when key order or array order differs.**
12
-
13
- ---
3
+ A lightweight utility library for [Convex](https://convex.dev) containing helpers.
14
4
 
15
5
  ## Installation
16
6
 
17
7
  ```bash
18
- npm install @bigbang-sdk/deep-sort
8
+ npm install @bb-labs/convex-helpers
19
9
  # or
20
- yarn add @bigbang-sdk/deep-sort
10
+ bun add @bb-labs/convex-helpers
21
11
  # or
22
- bun add @bigbang-sdk/deep-sort
12
+ yarn add @bb-labs/convex-helpers
23
13
  ```
24
14
 
25
- ---
26
-
27
- ## API
28
-
29
- ### `deepSort(value: unknown): unknown`
30
-
31
- Returns a **fully normalized, deeply sorted copy** of any JSON-compatible data structure.
15
+ ## Helpers
32
16
 
33
- Behavior:
17
+ ### `createTable`
34
18
 
35
- - **Object keys** are sorted at every level
36
- - **Arrays** are deeply normalized, then **sorted** using SuperJSON’s structural encoding
37
- - Non-plain objects (Dates, Maps, Sets, etc.) are **preserved**, and naturally handled by SuperJSON
19
+ A helper function that provides a declarative way to define Convex tables with schemas and indexes in a single, readable configuration object.
38
20
 
39
- ```ts
40
- import { deepSort } from "@bigbang-sdk/deep-sort";
21
+ ```typescript
22
+ import { createTable } from "@bb-labs/convex-helpers";
23
+ import { v } from "convex/values";
41
24
 
42
- deepSort([3, 1, 2]);
43
- // → [1, 2, 3]
25
+ const UserSchema = {
26
+ email: v.string(),
27
+ name: v.string(),
28
+ role: v.string(),
29
+ createdAt: v.number(),
30
+ };
44
31
 
45
- deepSort([{ b: 2, a: 1 }, { a: 3 }]);
46
- // → [ { a: 1, b: 2 }, { a: 3 } ]
47
-
48
- deepSort([
49
- { id: 2, tags: ["b", "a"] },
50
- { id: 1, tags: ["c", "a"] },
51
- ]);
52
- // → normalized deeply, sorted deterministically
32
+ const usersTable = createTable({
33
+ schema: UserSchema,
34
+ indexes: [
35
+ { name: "by_email", fields: ["email"] },
36
+ { name: "by_role", fields: ["role", "createdAt"] },
37
+ ],
38
+ });
53
39
  ```
54
40
 
55
- ---
56
-
57
- ## Caveats
58
-
59
- - Sorting arrays by SuperJSON string is deterministic but may be expensive for very large/nested data.
60
- - Circular references are **not supported** (SuperJSON cannot serialize them).
61
- - This is intended for **cache key normalization**, **equality pre-normalization**, and **stable hashing** — not for mutating live data structuress.
62
-
63
- ---
64
-
65
41
  ## License
66
42
 
67
43
  MIT
@@ -13,11 +13,11 @@ type CreateTableOptions<T extends SchemaDefinition> = {
13
13
  * Helper to define a Convex table with a declarative syntax.
14
14
  *
15
15
  * @example
16
- * export const otpsTable = createTable({
17
- * schema: OtpSchema,
16
+ * const usersTable = createTable({
17
+ * schema: UserSchema,
18
18
  * indexes: [
19
- * { name: "by_email_otp", fields: ["email", "otp"] },
20
- * { name: "by_email", fields: ["email", "expiresAt"] },
19
+ * { name: "by_email", fields: ["email"] },
20
+ * { name: "by_role", fields: ["role", "createdAt"] },
21
21
  * ],
22
22
  * });
23
23
  */
@@ -3,11 +3,11 @@ import { defineTable } from "convex/server";
3
3
  * Helper to define a Convex table with a declarative syntax.
4
4
  *
5
5
  * @example
6
- * export const otpsTable = createTable({
7
- * schema: OtpSchema,
6
+ * const usersTable = createTable({
7
+ * schema: UserSchema,
8
8
  * indexes: [
9
- * { name: "by_email_otp", fields: ["email", "otp"] },
10
- * { name: "by_email", fields: ["email", "expiresAt"] },
9
+ * { name: "by_email", fields: ["email"] },
10
+ * { name: "by_role", fields: ["role", "createdAt"] },
11
11
  * ],
12
12
  * });
13
13
  */
package/package.json CHANGED
@@ -1,36 +1,27 @@
1
1
  {
2
2
  "name": "@bb-labs/convex-helpers",
3
- "version": "0.0.1",
4
- "author": "Beepbop",
3
+ "version": "0.0.3",
4
+ "npm": true,
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "https://github.com/beepbop-labs/convex-helpers.git"
7
+ "url": "https://github.com/beepbop-labs/libraries.git"
8
8
  },
9
9
  "main": "dist/index.js",
10
- "devDependencies": {
11
- "@types/bun": "latest"
12
- },
13
- "peerDependencies": {
14
- "typescript": "^5"
15
- },
16
- "description": "A library for convex helpers",
17
- "files": [
18
- "dist",
19
- "README.md"
20
- ],
21
- "homepage": "https://github.com/beepbop-labs/convex-helpers",
22
- "keywords": [
23
- "convex-helpers",
24
- "convex",
25
- "helpers"
26
- ],
27
- "license": "MIT",
28
10
  "scripts": {
29
- "clean": "rm -rf dist",
30
- "build": "npm run clean && tsc -p tsconfig.json",
31
- "pack": "npm run build && npm pack --pack-destination ./archive/"
11
+ "build": "bldr",
12
+ "dev": "bldr -w",
13
+ "clean": "rm -rf node_modules bun.lock dist"
32
14
  },
33
15
  "dependencies": {
16
+ "@bb-labs/bldr": "^0.0.16",
17
+ "@bb-labs/tsconfigs": "^0.0.4",
34
18
  "convex": "^1.31.2"
19
+ },
20
+ "devDependencies": {
21
+ "@types/bun": "latest",
22
+ "tsc-alias": "^1.8.16"
23
+ },
24
+ "peerDependencies": {
25
+ "typescript": "^5"
35
26
  }
36
27
  }
@@ -0,0 +1,39 @@
1
+ import { defineTable, type TableDefinition, type GenericTableIndexes } from "convex/server";
2
+ import type { GenericValidator, ObjectType, VObject } from "convex/values";
3
+
4
+ type SchemaDefinition = Record<string, GenericValidator>;
5
+
6
+ type IndexDefinition<T extends SchemaDefinition> = {
7
+ name: string;
8
+ fields: [keyof T & string, ...(keyof T & string)[]];
9
+ };
10
+
11
+ type CreateTableOptions<T extends SchemaDefinition> = {
12
+ schema: T;
13
+ indexes?: IndexDefinition<T>[];
14
+ };
15
+
16
+ /**
17
+ * Helper to define a Convex table with a declarative syntax.
18
+ *
19
+ * @example
20
+ * const usersTable = createTable({
21
+ * schema: UserSchema,
22
+ * indexes: [
23
+ * { name: "by_email", fields: ["email"] },
24
+ * { name: "by_role", fields: ["role", "createdAt"] },
25
+ * ],
26
+ * });
27
+ */
28
+ export function createTable<T extends SchemaDefinition>({
29
+ schema,
30
+ indexes = [],
31
+ }: CreateTableOptions<T>): TableDefinition<VObject<ObjectType<T>, T>, GenericTableIndexes> {
32
+ let table: TableDefinition = defineTable(schema);
33
+
34
+ for (const index of indexes) {
35
+ table = table.index(index.name, index.fields);
36
+ }
37
+
38
+ return table as TableDefinition<VObject<ObjectType<T>, T>, GenericTableIndexes>;
39
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./fns/create-table";
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "@bb-labs/tsconfigs/lib.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist",
5
+ "rootDir": "src",
6
+ "paths": {
7
+ "@/*": ["./src/*"]
8
+ }
9
+ },
10
+ "include": ["src"]
11
+ }