@shetty4l/core 0.1.34 → 0.1.35

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shetty4l/core",
3
- "version": "0.1.34",
3
+ "version": "0.1.35",
4
4
  "description": "Shared infrastructure primitives for Bun/TypeScript services",
5
5
  "repository": {
6
6
  "type": "git",
@@ -34,6 +34,36 @@ export class StateLoader {
34
34
  this.db = db;
35
35
  }
36
36
 
37
+ /**
38
+ * Check if a state row exists for the given key.
39
+ *
40
+ * Unlike `load()`, this does NOT create a row if it doesn't exist.
41
+ * Ensures table exists and migrates if needed (consistent with load()).
42
+ *
43
+ * @param Cls - The @Persisted class constructor
44
+ * @param key - Unique key to check
45
+ * @returns `true` if row exists, `false` otherwise
46
+ * @throws Error if class is not decorated with @Persisted
47
+ */
48
+ exists<T extends object>(Cls: new () => T, key: string): boolean {
49
+ // Get metadata
50
+ const meta = classMeta.get(Cls);
51
+ if (!meta || !meta.table) {
52
+ throw new Error(
53
+ `Class "${Cls.name}" is not decorated with @Persisted. ` +
54
+ `Add @Persisted('table_name') to the class.`,
55
+ );
56
+ }
57
+
58
+ // Ensure table exists and migrate if needed (consistent with load())
59
+ ensureTable(this.db, meta);
60
+ migrateAdditive(this.db, meta);
61
+
62
+ // Check if row exists
63
+ const row = this.selectRow(meta, key);
64
+ return row !== null;
65
+ }
66
+
37
67
  /**
38
68
  * Load a state object by key.
39
69
  *