@shetty4l/core 0.1.38 → 0.1.40
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 +1 -1
- package/src/db.ts +1 -0
- package/src/state/decorators.ts +16 -7
- package/src/state/loader.ts +4 -3
package/package.json
CHANGED
package/src/db.ts
CHANGED
|
@@ -77,6 +77,7 @@ export function createDatabaseManager(opts: DatabaseOpts): DatabaseManager {
|
|
|
77
77
|
// Enable WAL mode for better concurrent access (not applicable to :memory:)
|
|
78
78
|
if (path !== ":memory:") {
|
|
79
79
|
db.exec("PRAGMA journal_mode = WAL;");
|
|
80
|
+
db.exec("PRAGMA busy_timeout = 5000;");
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
// Execute schema SQL
|
package/src/state/decorators.ts
CHANGED
|
@@ -4,10 +4,8 @@
|
|
|
4
4
|
* Uses explicit type specification for all fields to ensure correct
|
|
5
5
|
* serialization without relying on runtime type inference.
|
|
6
6
|
*
|
|
7
|
-
* Note:
|
|
8
|
-
*
|
|
9
|
-
* - Class decorator context is undefined (not an object)
|
|
10
|
-
* - Field decorators run before class decorator (allows global accumulation)
|
|
7
|
+
* Note: Field decorators run before class decorator, which allows
|
|
8
|
+
* global accumulation of field definitions.
|
|
11
9
|
*
|
|
12
10
|
* @example
|
|
13
11
|
* ```ts
|
|
@@ -33,6 +31,19 @@ function toSnakeCase(str: string): string {
|
|
|
33
31
|
);
|
|
34
32
|
}
|
|
35
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Extract property name from TC39 decorator context.
|
|
36
|
+
*
|
|
37
|
+
* TC39 field decorator context is a ClassFieldDecoratorContext object with a `name` property.
|
|
38
|
+
* This handles both the standard TC39 context object and legacy string contexts.
|
|
39
|
+
*/
|
|
40
|
+
function extractPropertyName(context: unknown): string {
|
|
41
|
+
if (typeof context === "object" && context !== null && "name" in context) {
|
|
42
|
+
return String((context as { name: unknown }).name);
|
|
43
|
+
}
|
|
44
|
+
return String(context);
|
|
45
|
+
}
|
|
46
|
+
|
|
36
47
|
/** Options for the @Field decorator. */
|
|
37
48
|
export interface FieldOptions {
|
|
38
49
|
/** Custom column name. Defaults to snake_case of property name. */
|
|
@@ -99,10 +110,8 @@ export function Persisted(table: string) {
|
|
|
99
110
|
* @param options - Optional field configuration (column name override)
|
|
100
111
|
*/
|
|
101
112
|
export function Field(type: FieldType, options?: FieldOptions) {
|
|
102
|
-
// Bun's TC39 decorator: context is the field name as string, not ClassFieldDecoratorContext
|
|
103
113
|
return function (_target: undefined, context: unknown): void {
|
|
104
|
-
|
|
105
|
-
const property = typeof context === "string" ? context : String(context);
|
|
114
|
+
const property = extractPropertyName(context);
|
|
106
115
|
const column = options?.column ?? toSnakeCase(property);
|
|
107
116
|
|
|
108
117
|
// Accumulate field definitions
|
package/src/state/loader.ts
CHANGED
|
@@ -538,8 +538,9 @@ export class StateLoader {
|
|
|
538
538
|
/**
|
|
539
539
|
* Execute a function within a database transaction.
|
|
540
540
|
*
|
|
541
|
-
* Uses BEGIN
|
|
542
|
-
*
|
|
541
|
+
* Uses BEGIN DEFERRED to defer lock acquisition until the first write.
|
|
542
|
+
* This allows concurrent readers and writers with WAL mode.
|
|
543
|
+
* If the function throws, the transaction is rolled back.
|
|
543
544
|
* Otherwise, it is committed.
|
|
544
545
|
*
|
|
545
546
|
* @param fn - The function to execute within the transaction
|
|
@@ -559,7 +560,7 @@ export class StateLoader {
|
|
|
559
560
|
* ```
|
|
560
561
|
*/
|
|
561
562
|
async transaction<T>(fn: () => T | Promise<T>): Promise<T> {
|
|
562
|
-
this.db.exec("BEGIN
|
|
563
|
+
this.db.exec("BEGIN DEFERRED");
|
|
563
564
|
try {
|
|
564
565
|
const result = await fn();
|
|
565
566
|
this.db.exec("COMMIT");
|