@aurios/mizzle 1.1.2 → 1.1.4

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.
Files changed (116) hide show
  1. package/.turbo/turbo-build.log +37 -0
  2. package/LICENSE +21 -0
  3. package/README.md +166 -57
  4. package/dist/chunk-AQVECMXP.js +1 -0
  5. package/dist/chunk-DU7UPWBW.js +1 -0
  6. package/dist/chunk-GPYZK4WY.js +1 -0
  7. package/dist/chunk-NPPZW6VT.js +1 -0
  8. package/dist/chunk-TOYV2M4M.js +1 -0
  9. package/dist/chunk-UM3YF5EC.js +1 -0
  10. package/dist/columns.d.ts +1 -0
  11. package/dist/columns.js +1 -0
  12. package/dist/db-zHIHBm1E.d.ts +815 -0
  13. package/dist/db.d.ts +3 -0
  14. package/dist/db.js +1 -0
  15. package/dist/diff.d.ts +18 -0
  16. package/dist/diff.js +1 -0
  17. package/dist/index.d.ts +42 -0
  18. package/dist/index.js +1 -0
  19. package/dist/introspection.d.ts +7 -0
  20. package/dist/introspection.js +1 -0
  21. package/dist/operators-BVreW0ky.d.ts +719 -0
  22. package/dist/snapshot.d.ts +24 -0
  23. package/dist/snapshot.js +1 -0
  24. package/dist/table.d.ts +1 -0
  25. package/dist/table.js +1 -0
  26. package/dist/transaction-RE7LXTGV.js +1 -0
  27. package/package.json +82 -66
  28. package/src/builders/base.ts +53 -56
  29. package/src/builders/batch-get.ts +63 -58
  30. package/src/builders/batch-write.ts +81 -78
  31. package/src/builders/delete.ts +46 -53
  32. package/src/builders/insert.ts +158 -150
  33. package/src/builders/query-promise.ts +26 -35
  34. package/src/builders/relational-builder.ts +214 -191
  35. package/src/builders/select.ts +250 -237
  36. package/src/builders/transaction.ts +170 -152
  37. package/src/builders/update.ts +197 -192
  38. package/src/columns/binary-set.ts +29 -38
  39. package/src/columns/binary.ts +25 -35
  40. package/src/columns/boolean.ts +25 -30
  41. package/src/columns/date.ts +57 -64
  42. package/src/columns/index.ts +15 -15
  43. package/src/columns/json.ts +39 -48
  44. package/src/columns/list.ts +26 -36
  45. package/src/columns/map.ts +26 -34
  46. package/src/columns/number-set.ts +29 -38
  47. package/src/columns/number.ts +33 -40
  48. package/src/columns/string-set.ts +38 -47
  49. package/src/columns/string.ts +37 -49
  50. package/src/columns/uuid.ts +26 -33
  51. package/src/core/client.ts +9 -9
  52. package/src/core/column-builder.ts +194 -220
  53. package/src/core/column.ts +127 -135
  54. package/src/core/diff.ts +40 -34
  55. package/src/core/errors.ts +20 -17
  56. package/src/core/introspection.ts +62 -58
  57. package/src/core/operations.ts +17 -23
  58. package/src/core/parser.ts +82 -89
  59. package/src/core/relations.ts +164 -154
  60. package/src/core/retry.ts +52 -52
  61. package/src/core/snapshot.ts +131 -130
  62. package/src/core/strategies.ts +222 -218
  63. package/src/core/table.ts +189 -202
  64. package/src/core/validation.ts +52 -52
  65. package/src/db.ts +211 -209
  66. package/src/expressions/actions.ts +26 -26
  67. package/src/expressions/builder.ts +62 -54
  68. package/src/expressions/operators.ts +48 -48
  69. package/src/expressions/update-builder.ts +78 -76
  70. package/src/index.ts +1 -1
  71. package/src/indexes.ts +8 -8
  72. package/test/batch-resilience.test.ts +138 -0
  73. package/test/builders/delete.test.ts +100 -0
  74. package/test/builders/insert.test.ts +216 -0
  75. package/test/builders/relational-types.test.ts +55 -0
  76. package/test/builders/relational.integration.test.ts +291 -0
  77. package/test/builders/relational.test.ts +66 -0
  78. package/test/builders/select.test.ts +411 -0
  79. package/test/builders/transaction-errors.test.ts +46 -0
  80. package/test/builders/transaction-execution.test.ts +99 -0
  81. package/test/builders/transaction-proxy.test.ts +41 -0
  82. package/test/builders/update-expression.test.ts +106 -0
  83. package/test/builders/update.test.ts +179 -0
  84. package/test/core/diff.test.ts +152 -0
  85. package/test/core/expressions.test.ts +64 -0
  86. package/test/core/introspection.test.ts +47 -0
  87. package/test/core/parser.test.ts +69 -0
  88. package/test/core/snapshot-gen.test.ts +155 -0
  89. package/test/core/snapshot.test.ts +52 -0
  90. package/test/date-column.test.ts +159 -0
  91. package/test/fluent-writes.integration.test.ts +148 -0
  92. package/test/integration-retry.test.ts +77 -0
  93. package/test/integration.test.ts +105 -0
  94. package/test/item-size-error.test.ts +16 -0
  95. package/test/item-size-validation.test.ts +82 -0
  96. package/test/item-size.test.ts +47 -0
  97. package/test/iterator-pagination.integration.test.ts +132 -0
  98. package/test/jsdoc-builders.test.ts +55 -0
  99. package/test/jsdoc-schema.test.ts +107 -0
  100. package/test/json-column.test.ts +51 -0
  101. package/test/metadata.test.ts +54 -0
  102. package/test/mizzle-package.test.ts +20 -0
  103. package/test/relational-centralized.test.ts +83 -0
  104. package/test/relational-definition.test.ts +75 -0
  105. package/test/relational-init.test.ts +30 -0
  106. package/test/relational-proxy.test.ts +52 -0
  107. package/test/relations.test.ts +45 -0
  108. package/test/resilience-config.test.ts +34 -0
  109. package/test/retry-handler.test.ts +63 -0
  110. package/test/transaction.integration.test.ts +153 -0
  111. package/test/unified-select.integration.test.ts +153 -0
  112. package/test/unified-update.integration.test.ts +139 -0
  113. package/test/update.integration.test.ts +132 -0
  114. package/tsconfig.json +12 -8
  115. package/tsup.config.ts +11 -11
  116. package/vitest.config.ts +8 -0
@@ -1,58 +1,53 @@
1
1
  import { Column, type ColumnBaseConfig } from "../core/column";
2
2
  import {
3
- ColumnBuider,
4
- type ColumnBuilderBaseConfig,
5
- type MakeColumnConfig,
3
+ ColumnBuider,
4
+ type ColumnBuilderBaseConfig,
5
+ type MakeColumnConfig,
6
6
  } from "../core/column-builder";
7
7
  import type { AnyTable } from "../core/table";
8
8
 
9
9
  export type BooleanColumnInitial<TName extends string> = BooleanColumnBuilder<{
10
- name: TName;
11
- dataType: "boolean";
12
- columnType: "BOOL";
13
- data: boolean;
10
+ name: TName;
11
+ dataType: "boolean";
12
+ columnType: "BOOL";
13
+ data: boolean;
14
14
  }>;
15
15
 
16
16
  export class BooleanColumnBuilder<
17
- T extends ColumnBuilderBaseConfig<"boolean", "BOOL">,
17
+ T extends ColumnBuilderBaseConfig<"boolean", "BOOL">,
18
18
  > extends ColumnBuider<T> {
19
- constructor(name: T["name"]) {
20
- super(name, "boolean", "BOOL");
21
- }
19
+ constructor(name: T["name"]) {
20
+ super(name, "boolean", "BOOL");
21
+ }
22
22
 
23
- build<TTableName extends string>(
24
- table: AnyTable,
25
- ): BooleanColumn<MakeColumnConfig<T, TTableName>> {
26
- return new BooleanColumn<MakeColumnConfig<T, TTableName>>(
27
- table,
28
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
- this.config as any,
30
- );
31
- }
23
+ build<TTableName extends string>(
24
+ table: AnyTable,
25
+ ): BooleanColumn<MakeColumnConfig<T, TTableName>> {
26
+ return new BooleanColumn<MakeColumnConfig<T, TTableName>>(
27
+ table,
28
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
+ this.config as any,
30
+ );
31
+ }
32
32
  }
33
33
 
34
- export class BooleanColumn<
35
- T extends ColumnBaseConfig<"boolean", "BOOL">,
36
- > extends Column<T> {
37
- }
34
+ export class BooleanColumn<T extends ColumnBaseConfig<"boolean", "BOOL">> extends Column<T> {}
38
35
 
39
36
  export function boolean(): BooleanColumnInitial<"">;
40
- export function boolean<TName extends string>(
41
- name: TName,
42
- ): BooleanColumnInitial<TName>;
37
+ export function boolean<TName extends string>(name: TName): BooleanColumnInitial<TName>;
43
38
  /**
44
39
  * Defines a Boolean column ("BOOL") in DynamoDB.
45
- *
40
+ *
46
41
  * @example
47
42
  * ```ts
48
43
  * const users = defineTable("users", {
49
44
  * isActive: boolean("is_active").default(true),
50
45
  * });
51
46
  * ```
52
- *
47
+ *
53
48
  * @param name The name of the attribute in DynamoDB. If omitted, it will use the property name in the definition object.
54
49
  * @returns A BooleanColumnBuilder instance.
55
50
  */
56
51
  export function boolean(name?: string) {
57
- return new BooleanColumnBuilder(name ?? "");
52
+ return new BooleanColumnBuilder(name ?? "");
58
53
  }
@@ -1,91 +1,84 @@
1
+ import { Column, type ColumnBaseConfig } from "../core/column";
1
2
  import {
2
- Column,
3
- type ColumnBaseConfig,
4
- } from "../core/column";
5
- import {
6
- ColumnBuider,
7
- type ColumnBuilderBaseConfig,
8
- type MakeColumnConfig,
9
- type HasDefault,
10
- type HasRuntimeDefault,
3
+ ColumnBuider,
4
+ type ColumnBuilderBaseConfig,
5
+ type MakeColumnConfig,
6
+ type HasDefault,
7
+ type HasRuntimeDefault,
11
8
  } from "../core/column-builder";
12
9
  import type { AnyTable } from "../core/table";
13
10
 
14
11
  export type DateColumnInitial<TName extends string> = DateColumnBuilder<{
15
- name: TName;
16
- dataType: "date";
17
- columnType: "S";
18
- data: Date;
12
+ name: TName;
13
+ dataType: "date";
14
+ columnType: "S";
15
+ data: Date;
19
16
  }>;
20
17
 
21
18
  export class DateColumnBuilder<
22
- T extends ColumnBuilderBaseConfig<"date", "S">,
19
+ T extends ColumnBuilderBaseConfig<"date", "S">,
23
20
  > extends ColumnBuider<T> {
24
- constructor(name: T["name"]) {
25
- super(name, "date", "S");
26
- }
21
+ constructor(name: T["name"]) {
22
+ super(name, "date", "S");
23
+ }
27
24
 
28
- defaultNow(): HasRuntimeDefault<HasDefault<this>> {
29
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
- return this.$defaultFn(() => new Date() as any);
31
- }
25
+ defaultNow(): HasRuntimeDefault<HasDefault<this>> {
26
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
+ return this.$defaultFn(() => new Date() as any);
28
+ }
32
29
 
33
- onUpdateNow(): HasDefault<this> {
34
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
- return this.$onUpdateFn(() => new Date() as any);
36
- }
30
+ onUpdateNow(): HasDefault<this> {
31
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
+ return this.$onUpdateFn(() => new Date() as any);
33
+ }
37
34
 
38
- build<TTableName extends string>(
39
- table: AnyTable,
40
- ): DateColumn<MakeColumnConfig<T, TTableName>> {
41
- return new DateColumn<MakeColumnConfig<T, TTableName>>(
42
- table,
43
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
- this.config as any,
45
- );
46
- }
35
+ build<TTableName extends string>(table: AnyTable): DateColumn<MakeColumnConfig<T, TTableName>> {
36
+ return new DateColumn<MakeColumnConfig<T, TTableName>>(
37
+ table,
38
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
+ this.config as any,
40
+ );
41
+ }
47
42
  }
48
43
 
49
- export class DateColumn<
50
- T extends ColumnBaseConfig<"date", "S">,
51
- > extends Column<T> {
52
- override mapToDynamoValue(value: unknown): unknown {
53
- if (value === null || value === undefined) {
54
- return value;
55
- }
56
-
57
- let date: Date;
58
- if (value instanceof Date) {
59
- date = value;
60
- } else if (typeof value === "string" || typeof value === "number") {
61
- date = new Date(value);
62
- } else {
63
- throw new Error(`Invalid date value: ${value}`);
64
- }
44
+ export class DateColumn<T extends ColumnBaseConfig<"date", "S">> extends Column<T> {
45
+ override mapToDynamoValue(value: unknown): unknown {
46
+ if (value === null || value === undefined) {
47
+ return value;
48
+ }
65
49
 
66
- if (Number.isNaN(date.getTime())) {
67
- throw new Error(`Invalid date value: ${value}`);
68
- }
50
+ let date: Date;
51
+ if (value instanceof Date) {
52
+ date = value;
53
+ } else if (typeof value === "string" || typeof value === "number") {
54
+ date = new Date(value);
55
+ } else {
56
+ throw new Error(`Invalid date value: ${value}`);
57
+ }
69
58
 
70
- return date.toISOString();
59
+ if (Number.isNaN(date.getTime())) {
60
+ throw new Error(`Invalid date value: ${value}`);
71
61
  }
72
62
 
73
- override mapFromDynamoValue(value: unknown): unknown {
74
- if (typeof value === "string") {
75
- return new Date(value);
76
- }
77
- return value;
63
+ return date.toISOString();
64
+ }
65
+
66
+ override mapFromDynamoValue(value: unknown): unknown {
67
+ if (typeof value === "string") {
68
+ return new Date(value);
78
69
  }
70
+ return value;
71
+ }
79
72
  }
80
73
 
81
74
  export function date(): DateColumnInitial<"">;
82
75
  export function date<TName extends string>(name: TName): DateColumnInitial<TName>;
83
76
  /**
84
77
  * Defines a Date column.
85
- *
86
- * In DynamoDB, this is stored as an ISO 8601 string ("S"), but Mizzle automatically
78
+ *
79
+ * In DynamoDB, this is stored as an ISO 8601 string ("S"), but Mizzle automatically
87
80
  * handles conversion to/from JavaScript Date objects in your application code.
88
- *
81
+ *
89
82
  * @example
90
83
  * ```ts
91
84
  * const posts = defineTable("posts", {
@@ -93,10 +86,10 @@ export function date<TName extends string>(name: TName): DateColumnInitial<TName
93
86
  * updatedAt: date("updated_at").onUpdateNow(),
94
87
  * });
95
88
  * ```
96
- *
89
+ *
97
90
  * @param name The name of the attribute in DynamoDB. If omitted, it will use the property name in the definition object.
98
91
  * @returns A DateColumnBuilder instance.
99
92
  */
100
93
  export function date(name?: string) {
101
- return new DateColumnBuilder(name ?? "");
94
+ return new DateColumnBuilder(name ?? "");
102
95
  }
@@ -25,20 +25,20 @@ import { stringSet } from "./string-set";
25
25
  import { uuid } from "./uuid";
26
26
 
27
27
  export function getColumnBuilders() {
28
- return {
29
- binary,
30
- binarySet,
31
- boolean,
32
- date,
33
- json,
34
- list,
35
- map,
36
- number,
37
- numberSet,
38
- string,
39
- stringSet,
40
- uuid,
41
- };
28
+ return {
29
+ binary,
30
+ binarySet,
31
+ boolean,
32
+ date,
33
+ json,
34
+ list,
35
+ map,
36
+ number,
37
+ numberSet,
38
+ string,
39
+ stringSet,
40
+ uuid,
41
+ };
42
42
  }
43
43
 
44
- export type ColumnsBuilder = ReturnType<typeof getColumnBuilders>;
44
+ export type ColumnsBuilder = ReturnType<typeof getColumnBuilders>;
@@ -1,85 +1,76 @@
1
+ import { Column, type ColumnBaseConfig } from "../core/column";
1
2
  import {
2
- Column,
3
- type ColumnBaseConfig,
4
- } from "../core/column";
5
- import {
6
- ColumnBuider,
7
- type ColumnBuilderBaseConfig,
8
- type MakeColumnConfig,
3
+ ColumnBuider,
4
+ type ColumnBuilderBaseConfig,
5
+ type MakeColumnConfig,
9
6
  } from "../core/column-builder";
10
7
  import type { AnyTable } from "../core/table";
11
8
 
12
9
  export type JsonColumnInitial<TName extends string> = JsonColumnBuilder<{
13
- name: TName;
14
- dataType: "json";
15
- columnType: "S";
16
- data: unknown;
10
+ name: TName;
11
+ dataType: "json";
12
+ columnType: "S";
13
+ data: unknown;
17
14
  }>;
18
15
 
19
16
  export class JsonColumnBuilder<
20
- T extends ColumnBuilderBaseConfig<"json", "S">,
17
+ T extends ColumnBuilderBaseConfig<"json", "S">,
21
18
  > extends ColumnBuider<T> {
22
- constructor(name: T["name"]) {
23
- super(name, "json", "S");
24
- }
19
+ constructor(name: T["name"]) {
20
+ super(name, "json", "S");
21
+ }
25
22
 
26
- build<TTableName extends string>(
27
- table: AnyTable,
28
- ): JsonColumn<MakeColumnConfig<T, TTableName>> {
29
- return new JsonColumn<MakeColumnConfig<T, TTableName>>(
30
- table,
31
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
- this.config as any,
33
- );
34
- }
23
+ build<TTableName extends string>(table: AnyTable): JsonColumn<MakeColumnConfig<T, TTableName>> {
24
+ return new JsonColumn<MakeColumnConfig<T, TTableName>>(
25
+ table,
26
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
+ this.config as any,
28
+ );
29
+ }
35
30
  }
36
31
 
37
- export class JsonColumn<
38
- T extends ColumnBaseConfig<"json", "S">,
39
- > extends Column<T> {
40
- override mapToDynamoValue(value: T["data"]): string {
41
- return JSON.stringify(value);
42
- }
32
+ export class JsonColumn<T extends ColumnBaseConfig<"json", "S">> extends Column<T> {
33
+ override mapToDynamoValue(value: T["data"]): string {
34
+ return JSON.stringify(value);
35
+ }
43
36
 
44
- override mapFromDynamoValue(value: T["data"] | string): T["data"] {
45
- if (typeof value === "string") {
46
- try {
47
- return JSON.parse(value);
48
- } catch {
49
- return value as T["data"];
50
- }
51
- }
52
- return value;
37
+ override mapFromDynamoValue(value: T["data"] | string): T["data"] {
38
+ if (typeof value === "string") {
39
+ try {
40
+ return JSON.parse(value);
41
+ } catch {
42
+ return value as T["data"];
43
+ }
53
44
  }
45
+ return value;
46
+ }
54
47
  }
55
48
 
56
49
  export function json(): JsonColumnInitial<"">;
57
- export function json<TName extends string>(
58
- name: TName,
59
- ): JsonColumnInitial<TName>;
50
+ export function json<TName extends string>(name: TName): JsonColumnInitial<TName>;
60
51
  /**
61
52
  * Defines a JSON column.
62
- *
53
+ *
63
54
  * In DynamoDB, this is stored as a string ("S") containing serialized JSON.
64
55
  * Mizzle automatically handles JSON.stringify/parse for you.
65
- *
56
+ *
66
57
  * You can type the JSON object using the `.$type<T>()` method.
67
- *
58
+ *
68
59
  * @example
69
60
  * ```ts
70
61
  * interface Address {
71
62
  * street: string;
72
63
  * city: string;
73
64
  * }
74
- *
65
+ *
75
66
  * const users = defineTable("users", {
76
67
  * address: json("address").$type<Address>(),
77
68
  * });
78
69
  * ```
79
- *
70
+ *
80
71
  * @param name The name of the attribute in DynamoDB. If omitted, it will use the property name in the definition object.
81
72
  * @returns A JsonColumnBuilder instance.
82
73
  */
83
74
  export function json(name?: string) {
84
- return new JsonColumnBuilder(name ?? "");
75
+ return new JsonColumnBuilder(name ?? "");
85
76
  }
@@ -1,63 +1,53 @@
1
+ import { Column, type ColumnBaseConfig } from "../core/column";
1
2
  import {
2
- Column,
3
- type ColumnBaseConfig,
4
- } from "../core/column";
5
- import {
6
- ColumnBuider,
7
- type ColumnBuilderBaseConfig,
8
- type MakeColumnConfig,
3
+ ColumnBuider,
4
+ type ColumnBuilderBaseConfig,
5
+ type MakeColumnConfig,
9
6
  } from "../core/column-builder";
10
7
  import type { AnyTable } from "../core/table";
11
8
 
12
9
  export type ListColumnInitial<TName extends string> = ListColumnBuilder<{
13
- name: TName;
14
- data: unknown[];
15
- dataType: "array";
16
- columnType: "L";
10
+ name: TName;
11
+ data: unknown[];
12
+ dataType: "array";
13
+ columnType: "L";
17
14
  }>;
18
15
 
19
16
  export class ListColumnBuilder<
20
- T extends ColumnBuilderBaseConfig<"array", "L">,
17
+ T extends ColumnBuilderBaseConfig<"array", "L">,
21
18
  > extends ColumnBuider<T> {
22
- constructor(name: T["name"]) {
23
- super(name, "array", "L");
24
- }
25
- build<TTableName extends string>(
26
- table: AnyTable,
27
- ): ListColumn<MakeColumnConfig<T, TTableName>> {
28
- return new ListColumn<MakeColumnConfig<T, TTableName>>(
29
- table,
30
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
- this.config as any,
32
- );
33
- }
19
+ constructor(name: T["name"]) {
20
+ super(name, "array", "L");
21
+ }
22
+ build<TTableName extends string>(table: AnyTable): ListColumn<MakeColumnConfig<T, TTableName>> {
23
+ return new ListColumn<MakeColumnConfig<T, TTableName>>(
24
+ table,
25
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
+ this.config as any,
27
+ );
28
+ }
34
29
  }
35
30
 
36
- export class ListColumn<
37
- T extends ColumnBaseConfig<"array", "L">,
38
- > extends Column<T> {
39
- }
31
+ export class ListColumn<T extends ColumnBaseConfig<"array", "L">> extends Column<T> {}
40
32
 
41
33
  export function list(): ListColumnInitial<"">;
42
- export function list<TName extends string>(
43
- name: TName,
44
- ): ListColumnInitial<TName>;
34
+ export function list<TName extends string>(name: TName): ListColumnInitial<TName>;
45
35
  /**
46
36
  * Defines a List column ("L") in DynamoDB.
47
- *
48
- * A list is an ordered collection of values. It can store mixed types,
37
+ *
38
+ * A list is an ordered collection of values. It can store mixed types,
49
39
  * but you can enforce a specific type using `.$type<T[]>()`.
50
- *
40
+ *
51
41
  * @example
52
42
  * ```ts
53
43
  * const posts = defineTable("posts", {
54
44
  * tags: list("tags").$type<string[]>(),
55
45
  * });
56
46
  * ```
57
- *
47
+ *
58
48
  * @param name The name of the attribute in DynamoDB. If omitted, it will use the property name in the definition object.
59
49
  * @returns A ListColumnBuilder instance.
60
50
  */
61
51
  export function list(name?: string) {
62
- return new ListColumnBuilder(name ?? "");
52
+ return new ListColumnBuilder(name ?? "");
63
53
  }
@@ -1,63 +1,55 @@
1
+ import { Column, type ColumnBaseConfig } from "../core/column";
1
2
  import {
2
- Column,
3
- type ColumnBaseConfig,
4
- } from "../core/column";
5
- import {
6
- ColumnBuider,
7
- type ColumnBuilderBaseConfig,
8
- type MakeColumnConfig,
3
+ ColumnBuider,
4
+ type ColumnBuilderBaseConfig,
5
+ type MakeColumnConfig,
9
6
  } from "../core/column-builder";
10
7
  import type { AnyTable } from "../core/table";
11
8
 
12
9
  export type MapColumnInitial<TName extends string> = MapColumnBuilder<{
13
- name: TName;
14
- data: Record<string, unknown>;
15
- dataType: "map";
16
- columnType: "M";
10
+ name: TName;
11
+ data: Record<string, unknown>;
12
+ dataType: "map";
13
+ columnType: "M";
17
14
  }>;
18
15
 
19
16
  export class MapColumnBuilder<
20
- T extends ColumnBuilderBaseConfig<"map", "M">,
17
+ T extends ColumnBuilderBaseConfig<"map", "M">,
21
18
  > extends ColumnBuider<T> {
22
- constructor(name: T["name"]) {
23
- super(name, "map", "M");
24
- }
19
+ constructor(name: T["name"]) {
20
+ super(name, "map", "M");
21
+ }
25
22
 
26
- build<TTableName extends string>(
27
- table: AnyTable,
28
- ): MapColumn<MakeColumnConfig<T, TTableName>> {
29
- return new MapColumn<MakeColumnConfig<T, TTableName>>(
30
- table,
31
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
- this.config as any,
33
- );
34
- }
23
+ build<TTableName extends string>(table: AnyTable): MapColumn<MakeColumnConfig<T, TTableName>> {
24
+ return new MapColumn<MakeColumnConfig<T, TTableName>>(
25
+ table,
26
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
+ this.config as any,
28
+ );
29
+ }
35
30
  }
36
31
 
37
- export class MapColumn<
38
- T extends ColumnBaseConfig<"map", "M">,
39
- > extends Column<T> {
40
- }
32
+ export class MapColumn<T extends ColumnBaseConfig<"map", "M">> extends Column<T> {}
41
33
 
42
34
  export function map(): MapColumnInitial<"">;
43
35
  export function map<TName extends string>(name: TName): MapColumnInitial<TName>;
44
36
  /**
45
37
  * Defines a Map column ("M") in DynamoDB.
46
- *
47
- * A map is a set of key-value pairs (like a JSON object).
48
- * Unlike `json()`, this is stored as a native DynamoDB Map, allowing you to filter/query nested properties
38
+ *
39
+ * A map is a set of key-value pairs (like a JSON object).
40
+ * Unlike `json()`, this is stored as a native DynamoDB Map, allowing you to filter/query nested properties
49
41
  * more easily in some contexts, though `json()` is often preferred for simple object storage.
50
- *
42
+ *
51
43
  * @example
52
44
  * ```ts
53
45
  * const users = defineTable("users", {
54
46
  * metadata: map("metadata").$type<{ verified: boolean, loginCount: number }>(),
55
47
  * });
56
48
  * ```
57
- *
49
+ *
58
50
  * @param name The name of the attribute in DynamoDB. If omitted, it will use the property name in the definition object.
59
51
  * @returns A MapColumnBuilder instance.
60
52
  */
61
53
  export function map(name?: string) {
62
- return new MapColumnBuilder(name ?? "");
54
+ return new MapColumnBuilder(name ?? "");
63
55
  }