@shetty4l/core 0.1.39 → 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/state/decorators.ts +16 -7
package/package.json
CHANGED
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
|