@bb-labs/convex-helpers 0.0.1

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/README.md ADDED
@@ -0,0 +1,67 @@
1
+ ## Introduction
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
+ ---
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @bigbang-sdk/deep-sort
19
+ # or
20
+ yarn add @bigbang-sdk/deep-sort
21
+ # or
22
+ bun add @bigbang-sdk/deep-sort
23
+ ```
24
+
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.
32
+
33
+ Behavior:
34
+
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
38
+
39
+ ```ts
40
+ import { deepSort } from "@bigbang-sdk/deep-sort";
41
+
42
+ deepSort([3, 1, 2]);
43
+ // → [1, 2, 3]
44
+
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
53
+ ```
54
+
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
+ ## License
66
+
67
+ MIT
@@ -0,0 +1,25 @@
1
+ import { type TableDefinition, type GenericTableIndexes } from "convex/server";
2
+ import type { GenericValidator, ObjectType, VObject } from "convex/values";
3
+ type SchemaDefinition = Record<string, GenericValidator>;
4
+ type IndexDefinition<T extends SchemaDefinition> = {
5
+ name: string;
6
+ fields: [keyof T & string, ...(keyof T & string)[]];
7
+ };
8
+ type CreateTableOptions<T extends SchemaDefinition> = {
9
+ schema: T;
10
+ indexes?: IndexDefinition<T>[];
11
+ };
12
+ /**
13
+ * Helper to define a Convex table with a declarative syntax.
14
+ *
15
+ * @example
16
+ * export const otpsTable = createTable({
17
+ * schema: OtpSchema,
18
+ * indexes: [
19
+ * { name: "by_email_otp", fields: ["email", "otp"] },
20
+ * { name: "by_email", fields: ["email", "expiresAt"] },
21
+ * ],
22
+ * });
23
+ */
24
+ export declare function createTable<T extends SchemaDefinition>({ schema, indexes, }: CreateTableOptions<T>): TableDefinition<VObject<ObjectType<T>, T>, GenericTableIndexes>;
25
+ export {};
@@ -0,0 +1,20 @@
1
+ import { defineTable } from "convex/server";
2
+ /**
3
+ * Helper to define a Convex table with a declarative syntax.
4
+ *
5
+ * @example
6
+ * export const otpsTable = createTable({
7
+ * schema: OtpSchema,
8
+ * indexes: [
9
+ * { name: "by_email_otp", fields: ["email", "otp"] },
10
+ * { name: "by_email", fields: ["email", "expiresAt"] },
11
+ * ],
12
+ * });
13
+ */
14
+ export function createTable({ schema, indexes = [], }) {
15
+ let table = defineTable(schema);
16
+ for (const index of indexes) {
17
+ table = table.index(index.name, index.fields);
18
+ }
19
+ return table;
20
+ }
@@ -0,0 +1 @@
1
+ export * from "./fns/create-table";
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from "./fns/create-table";
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@bb-labs/convex-helpers",
3
+ "version": "0.0.1",
4
+ "author": "Beepbop",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/beepbop-labs/convex-helpers.git"
8
+ },
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
+ "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/"
32
+ },
33
+ "dependencies": {
34
+ "convex": "^1.31.2"
35
+ }
36
+ }