uql-orm 0.104.1 → 0.105.0

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 (143) hide show
  1. package/README.md +24 -10
  2. package/dist/browser/uql-browser.min.js +2 -2
  3. package/dist/browser/uql-browser.min.js.map +7 -7
  4. package/dist/dialect/abstractSqlDialect.d.ts +6 -4
  5. package/dist/dialect/abstractSqlDialect.js +35 -32
  6. package/dist/dialect/aliases.d.ts +2 -0
  7. package/dist/dialect/aliases.js +2 -0
  8. package/dist/dialect/jsonSql.js +2 -2
  9. package/dist/dialect/mysqlLikeSqlDialect.d.ts +1 -1
  10. package/dist/dialect/mysqlLikeSqlDialect.js +1 -1
  11. package/dist/dialect/operators.js +2 -4
  12. package/dist/dialect/queryJoins.d.ts +2 -0
  13. package/dist/dialect/vectorSqlDialect.d.ts +1 -1
  14. package/dist/dialect/vectorSqlDialect.js +1 -1
  15. package/dist/entity/column.d.ts +3 -0
  16. package/dist/entity/column.js +3 -0
  17. package/dist/entity/columnOptionsBuilder.d.ts +54 -0
  18. package/dist/entity/columnOptionsBuilder.js +108 -0
  19. package/dist/entity/decorator/bag.d.ts +4 -4
  20. package/dist/entity/decorator/entity.d.ts +2 -19
  21. package/dist/entity/decorator/entity.js +3 -37
  22. package/dist/entity/decorator/members.d.ts +46 -76
  23. package/dist/entity/decorator/members.js +18 -7
  24. package/dist/entity/index.d.ts +2 -1
  25. package/dist/entity/index.js +2 -1
  26. package/dist/entity/metadata/definition.d.ts +10 -24
  27. package/dist/entity/metadata/definition.js +329 -147
  28. package/dist/entity/metadata/schemaFixture/animal.d.ts +54 -0
  29. package/dist/entity/metadata/schemaFixture/animal.js +7 -0
  30. package/dist/entity/metadata/schemaFixture/author.d.ts +140 -0
  31. package/dist/entity/metadata/schemaFixture/author.js +25 -0
  32. package/dist/entity/metadata/schemaFixture/book.d.ts +192 -0
  33. package/dist/entity/metadata/schemaFixture/book.js +22 -0
  34. package/dist/http/query.js +12 -13
  35. package/dist/index.d.ts +2 -2
  36. package/dist/index.js +2 -1
  37. package/dist/mariadb/mariaDialect.js +1 -1
  38. package/dist/mariadb/mariadbQuerier.js +1 -3
  39. package/dist/migrate/builder/columnBuilder.d.ts +20 -68
  40. package/dist/migrate/builder/columnBuilder.js +104 -110
  41. package/dist/migrate/builder/migrationBuilder.d.ts +3 -3
  42. package/dist/migrate/builder/migrationBuilder.js +7 -6
  43. package/dist/migrate/builder/tableBuilder.d.ts +3 -55
  44. package/dist/migrate/builder/tableBuilder.js +88 -204
  45. package/dist/migrate/builder/types.d.ts +52 -151
  46. package/dist/migrate/builder/types.js +0 -6
  47. package/dist/migrate/codegen/entityCodeGenerator.d.ts +2 -2
  48. package/dist/migrate/codegen/entityCodeGenerator.js +24 -24
  49. package/dist/migrate/codegen/fieldOptionsSource.d.ts +3 -1
  50. package/dist/migrate/codegen/fieldOptionsSource.js +35 -34
  51. package/dist/migrate/codegen/indexEntrySource.d.ts +16 -0
  52. package/dist/migrate/codegen/{indexDecoratorSource.js → indexEntrySource.js} +54 -27
  53. package/dist/migrate/ddl/defaultSql.js +7 -6
  54. package/dist/migrate/ddl/indexCapabilities.d.ts +8 -7
  55. package/dist/migrate/ddl/indexCapabilities.js +26 -13
  56. package/dist/migrate/ddl/indexDdl.d.ts +13 -13
  57. package/dist/migrate/ddl/indexDdl.js +33 -30
  58. package/dist/migrate/ddl/mysqlIndexDdl.d.ts +6 -11
  59. package/dist/migrate/ddl/mysqlIndexDdl.js +17 -28
  60. package/dist/migrate/ddl/pgIndexDdl.d.ts +2 -2
  61. package/dist/migrate/ddl/sqliteIndexDdl.d.ts +2 -2
  62. package/dist/migrate/drift/driftDetector.js +2 -2
  63. package/dist/migrate/generator/definitionToNode.d.ts +8 -2
  64. package/dist/migrate/generator/definitionToNode.js +4 -5
  65. package/dist/migrate/introspection/abstractSqlSchemaIntrospector.js +11 -2
  66. package/dist/migrate/introspection/jsonIndexEntry.d.ts +6 -0
  67. package/dist/migrate/introspection/jsonIndexEntry.js +120 -0
  68. package/dist/migrate/introspection/mysqlIntrospector.d.ts +4 -4
  69. package/dist/migrate/introspection/mysqlIntrospector.js +25 -21
  70. package/dist/migrate/introspection/postgresIntrospector.d.ts +1 -1
  71. package/dist/migrate/introspection/postgresIntrospector.js +3 -4
  72. package/dist/migrate/introspection/sqliteIntrospector.js +24 -9
  73. package/dist/migrate/introspection/tableSchemaAST.js +5 -1
  74. package/dist/migrate/schemaChange.d.ts +3 -3
  75. package/dist/migrate/schemaChange.js +3 -2
  76. package/dist/migrate/schemaGenerator.js +1 -1
  77. package/dist/migrate/storage/databaseStorage.js +4 -4
  78. package/dist/mongodb/mongoDialect.d.ts +33 -36
  79. package/dist/mongodb/mongoDialect.js +118 -32
  80. package/dist/mongodb/mongoIntrospector.d.ts +3 -1
  81. package/dist/mongodb/mongoIntrospector.js +11 -5
  82. package/dist/mongodb/mongoSchemaGenerator.js +35 -27
  83. package/dist/mongodb/mongodbQuerier.d.ts +1 -11
  84. package/dist/mongodb/mongodbQuerier.js +9 -43
  85. package/dist/querier/abstractQuerier.d.ts +0 -1
  86. package/dist/querier/abstractQuerier.js +1 -20
  87. package/dist/querier/keyset.js +3 -3
  88. package/dist/schema/declaredColumn.d.ts +11 -0
  89. package/dist/schema/declaredColumn.js +21 -0
  90. package/dist/schema/indexColumns.d.ts +0 -3
  91. package/dist/schema/indexColumns.js +11 -7
  92. package/dist/schema/indexDifferences.d.ts +10 -5
  93. package/dist/schema/indexDifferences.js +42 -28
  94. package/dist/schema/schemaASTBuilder.js +28 -36
  95. package/dist/schema/schemaASTDiffer.js +8 -4
  96. package/dist/schema/sqlExpression.d.ts +21 -17
  97. package/dist/schema/sqlExpression.js +11 -23
  98. package/dist/type/column.d.ts +328 -0
  99. package/dist/type/column.js +2 -0
  100. package/dist/type/config.d.ts +1 -1
  101. package/dist/type/dialect.d.ts +2 -1
  102. package/dist/type/dialect.js +1 -0
  103. package/dist/type/entity.d.ts +290 -279
  104. package/dist/type/entity.js +6 -1
  105. package/dist/type/index.d.ts +2 -0
  106. package/dist/type/index.js +2 -0
  107. package/dist/type/migration.d.ts +5 -5
  108. package/dist/type/query.d.ts +44 -40
  109. package/dist/type/query.js +2 -3
  110. package/dist/type/queryAggregate.d.ts +22 -12
  111. package/dist/type/querySql.d.ts +20 -4
  112. package/dist/type/querySql.js +27 -9
  113. package/dist/type/schemaEntity.d.ts +190 -0
  114. package/dist/type/schemaEntity.js +1 -0
  115. package/dist/type/utility.d.ts +0 -6
  116. package/dist/type/vector.d.ts +1 -1
  117. package/dist/util/ddlExpression.util.d.ts +12 -13
  118. package/dist/util/ddlExpression.util.js +12 -21
  119. package/dist/util/dialect.util.d.ts +11 -5
  120. package/dist/util/dialect.util.js +31 -37
  121. package/dist/util/field.util.d.ts +10 -9
  122. package/dist/util/field.util.js +14 -10
  123. package/dist/util/fieldOption.util.d.ts +11 -95
  124. package/dist/util/fieldOption.util.js +49 -16
  125. package/dist/util/hook.util.d.ts +2 -14
  126. package/dist/util/hook.util.js +3 -16
  127. package/dist/util/index.d.ts +1 -0
  128. package/dist/util/index.js +1 -0
  129. package/dist/util/indexEntry.util.d.ts +45 -0
  130. package/dist/util/indexEntry.util.js +138 -0
  131. package/dist/util/relationQuery.util.d.ts +0 -1
  132. package/dist/util/relationQuery.util.js +0 -5
  133. package/dist/util/sql.d.ts +10 -7
  134. package/dist/util/sql.js +34 -16
  135. package/dist/util/sql.util.d.ts +4 -5
  136. package/dist/util/sql.util.js +7 -16
  137. package/dist/util/string.util.d.ts +2 -0
  138. package/dist/util/string.util.js +4 -0
  139. package/dist/util/uqlError.d.ts +1 -1
  140. package/dist/util/uqlError.js +1 -1
  141. package/package.json +1 -1
  142. package/skills/uql-orm/SKILL.md +76 -25
  143. package/dist/migrate/codegen/indexDecoratorSource.d.ts +0 -16
@@ -0,0 +1,54 @@
1
+ export declare const Animal: import("../../../index.js").SchemaEntity<object & {
2
+ id: number;
3
+ name: string;
4
+ } & {} & import("../../../index.js").Brands<{
5
+ readonly id: import("../../../index.js").NumericColumn<{
6
+ readonly type: NumberConstructor;
7
+ } & {
8
+ readonly isId: true;
9
+ }, number>;
10
+ readonly name: import("../../../index.js").StringColumn<{
11
+ readonly type: StringConstructor;
12
+ }, string>;
13
+ }>, number, {
14
+ id: number;
15
+ name: string;
16
+ } & {}, object>;
17
+ export declare const Dog: import("../../../index.js").SchemaEntity<object & {
18
+ id: number;
19
+ name: string;
20
+ } & {} & import("../../../index.js").Brands<{
21
+ readonly id: import("../../../index.js").NumericColumn<{
22
+ readonly type: NumberConstructor;
23
+ } & {
24
+ readonly isId: true;
25
+ }, number>;
26
+ readonly name: import("../../../index.js").StringColumn<{
27
+ readonly type: StringConstructor;
28
+ }, string>;
29
+ }> & {} & {
30
+ tricks?: number | null | undefined;
31
+ } & import("../../../index.js").Brands<{
32
+ readonly tricks: import("../../../index.js").NumericColumn<{
33
+ readonly type: NumberConstructor;
34
+ } & {
35
+ readonly nullable: true;
36
+ }, number>;
37
+ }>, number, {
38
+ id: number;
39
+ name: string;
40
+ } & {} & {} & {
41
+ tricks?: number | null | undefined;
42
+ }, object & {
43
+ id: number;
44
+ name: string;
45
+ } & {} & import("../../../index.js").Brands<{
46
+ readonly id: import("../../../index.js").NumericColumn<{
47
+ readonly type: NumberConstructor;
48
+ } & {
49
+ readonly isId: true;
50
+ }, number>;
51
+ readonly name: import("../../../index.js").StringColumn<{
52
+ readonly type: StringConstructor;
53
+ }, string>;
54
+ }>>;
@@ -0,0 +1,7 @@
1
+ import { f } from '../../column.js';
2
+ import { defineEntity } from '../definition.js';
3
+ export const Animal = defineEntity({
4
+ name: 'Animal',
5
+ fields: { id: f.number().id(), name: f.string() },
6
+ });
7
+ export const Dog = defineEntity({ name: 'Dog', extends: Animal, fields: { tricks: f.number().nullable() } });
@@ -0,0 +1,140 @@
1
+ export declare const Author: import("../../../index.js").SchemaClass<object & {
2
+ id: number;
3
+ name: string;
4
+ createdAt: Date;
5
+ } & {
6
+ bio?: string | null | undefined;
7
+ } & import("../../../index.js").Brands<{
8
+ readonly id: import("../../../index.js").NumericColumn<{
9
+ readonly type: NumberConstructor;
10
+ } & {
11
+ readonly isId: true;
12
+ }, number>;
13
+ readonly name: import("../../../index.js").StringColumn<{
14
+ readonly type: StringConstructor;
15
+ }, string>;
16
+ readonly bio: import("../../../index.js").StringColumn<{
17
+ readonly type: StringConstructor;
18
+ } & {
19
+ readonly nullable: true;
20
+ }, string>;
21
+ readonly createdAt: import("../../../index.js").DateColumn<{
22
+ readonly type: DateConstructor;
23
+ } & {
24
+ readonly defaultValue: unknown;
25
+ }, Date>;
26
+ }> & import("../../../index.js").RelationRow<{
27
+ readonly books: () => import("../../../index.js").SchemaRelation<object & {
28
+ id: number;
29
+ title: string;
30
+ stock: number;
31
+ status: "draft" | "published";
32
+ version: number;
33
+ authorId: number;
34
+ } & {} & import("../../../index.js").Brands<{
35
+ readonly id: import("../../../index.js").NumericColumn<{
36
+ readonly type: NumberConstructor;
37
+ } & {
38
+ readonly isId: true;
39
+ }, number>;
40
+ readonly title: import("../../../index.js").StringColumn<{
41
+ readonly type: StringConstructor;
42
+ }, string>;
43
+ readonly stock: import("../../../index.js").NumericColumn<{
44
+ readonly type: NumberConstructor;
45
+ } & {
46
+ readonly defaultValue: unknown;
47
+ }, number>;
48
+ readonly status: import("../../../index.js").StringColumn<{
49
+ readonly type: StringConstructor;
50
+ readonly enum: readonly ["draft", "published"];
51
+ }, "draft" | "published">;
52
+ readonly version: import("../../../index.js").VersionColumn<{
53
+ readonly type: NumberConstructor;
54
+ readonly version: true;
55
+ }, number>;
56
+ readonly authorId: import("../../../index.js").NumericColumn<{
57
+ readonly type: NumberConstructor;
58
+ }, number>;
59
+ }> & {
60
+ readonly shout?: string | null | undefined;
61
+ } & import("../../../index.js").RelationRow<{
62
+ readonly author: () => import("../../../index.js").SchemaRelation<object & {
63
+ id: number;
64
+ name: string;
65
+ createdAt: Date;
66
+ } & {
67
+ bio?: string | null | undefined;
68
+ } & import("../../../index.js").Brands<{
69
+ readonly id: import("../../../index.js").NumericColumn<{
70
+ readonly type: NumberConstructor;
71
+ } & {
72
+ readonly isId: true;
73
+ }, number>;
74
+ readonly name: import("../../../index.js").StringColumn<{
75
+ readonly type: StringConstructor;
76
+ }, string>;
77
+ readonly bio: import("../../../index.js").StringColumn<{
78
+ readonly type: StringConstructor;
79
+ } & {
80
+ readonly nullable: true;
81
+ }, string>;
82
+ readonly createdAt: import("../../../index.js").DateColumn<{
83
+ readonly type: DateConstructor;
84
+ } & {
85
+ readonly defaultValue: unknown;
86
+ }, Date>;
87
+ }> & import("../../../index.js").RelationRow</*elided*/ any> & import("../../../index.js").AggregateRow<{
88
+ readonly bookCount: () => import("../../../index.js").RelationAggregate<number>;
89
+ readonly topStock: () => import("../../../index.js").RelationAggregate<number | null>;
90
+ }>, "m1", object & {
91
+ id: number;
92
+ name: string;
93
+ createdAt: Date;
94
+ } & {
95
+ bio?: string | null | undefined;
96
+ } & import("../../../index.js").Brands<{
97
+ readonly id: import("../../../index.js").NumericColumn<{
98
+ readonly type: NumberConstructor;
99
+ } & {
100
+ readonly isId: true;
101
+ }, number>;
102
+ readonly name: import("../../../index.js").StringColumn<{
103
+ readonly type: StringConstructor;
104
+ }, string>;
105
+ readonly bio: import("../../../index.js").StringColumn<{
106
+ readonly type: StringConstructor;
107
+ } & {
108
+ readonly nullable: true;
109
+ }, string>;
110
+ readonly createdAt: import("../../../index.js").DateColumn<{
111
+ readonly type: DateConstructor;
112
+ } & {
113
+ readonly defaultValue: unknown;
114
+ }, Date>;
115
+ }> & import("../../../index.js").RelationRow</*elided*/ any> & import("../../../index.js").AggregateRow<{
116
+ readonly bookCount: () => import("../../../index.js").RelationAggregate<number>;
117
+ readonly topStock: () => import("../../../index.js").RelationAggregate<number | null>;
118
+ }>>;
119
+ }> & import("../../../index.js").AggregateRow<{}>, "1m", {
120
+ id: number;
121
+ title: string;
122
+ stock: number;
123
+ status: "draft" | "published";
124
+ version: number;
125
+ authorId: number;
126
+ } & {} & {
127
+ readonly shout?: string | null | undefined;
128
+ }>;
129
+ }> & import("../../../index.js").AggregateRow<{
130
+ readonly bookCount: () => import("../../../index.js").RelationAggregate<number>;
131
+ readonly topStock: () => import("../../../index.js").RelationAggregate<number | null>;
132
+ }>, number, {
133
+ id: number;
134
+ name: string;
135
+ createdAt: Date;
136
+ } & {
137
+ bio?: string | null | undefined;
138
+ }>;
139
+ export type Author = InstanceType<typeof Author>;
140
+ export declare const label: (author: Author) => string;
@@ -0,0 +1,25 @@
1
+ import { currentTimestamp } from '../../../util/index.js';
2
+ import { f } from '../../column.js';
3
+ import { defineEntity } from '../definition.js';
4
+ import { Book } from './book.js';
5
+ export const Author = defineEntity({
6
+ name: 'Author',
7
+ fields: {
8
+ id: f.number().id(),
9
+ name: f.string(),
10
+ bio: f.string().nullable(),
11
+ createdAt: f.date().default(currentTimestamp),
12
+ },
13
+ })
14
+ .hooks({
15
+ beforeInsert: [
16
+ (author) => {
17
+ author.bio ??= 'unwritten';
18
+ },
19
+ ],
20
+ })
21
+ .relations((rel) => ({ books: () => rel.oneToMany(Book, { mappedBy: (book) => book.author }) }), (rel) => ({
22
+ bookCount: () => rel.books.count(),
23
+ topStock: () => rel.books.max((book) => book.stock),
24
+ }));
25
+ export const label = (author) => `${author.name} (${author.books?.length ?? 0})`;
@@ -0,0 +1,192 @@
1
+ export declare const Book: import("../../../index.js").SchemaClass<object & {
2
+ id: number;
3
+ title: string;
4
+ stock: number;
5
+ status: "draft" | "published";
6
+ version: number;
7
+ authorId: number;
8
+ } & {} & import("../../../index.js").Brands<{
9
+ readonly id: import("../../../index.js").NumericColumn<{
10
+ readonly type: NumberConstructor;
11
+ } & {
12
+ readonly isId: true;
13
+ }, number>;
14
+ readonly title: import("../../../index.js").StringColumn<{
15
+ readonly type: StringConstructor;
16
+ }, string>;
17
+ readonly stock: import("../../../index.js").NumericColumn<{
18
+ readonly type: NumberConstructor;
19
+ } & {
20
+ readonly defaultValue: unknown;
21
+ }, number>;
22
+ readonly status: import("../../../index.js").StringColumn<{
23
+ readonly type: StringConstructor;
24
+ readonly enum: readonly ["draft", "published"];
25
+ }, "draft" | "published">;
26
+ readonly version: import("../../../index.js").VersionColumn<{
27
+ readonly type: NumberConstructor;
28
+ readonly version: true;
29
+ }, number>;
30
+ readonly authorId: import("../../../index.js").NumericColumn<{
31
+ readonly type: NumberConstructor;
32
+ }, number>;
33
+ }> & {
34
+ readonly shout?: string | null | undefined;
35
+ } & import("../../../index.js").RelationRow<{
36
+ readonly author: () => import("../../../index.js").SchemaRelation<object & {
37
+ id: number;
38
+ name: string;
39
+ createdAt: Date;
40
+ } & {
41
+ bio?: string | null | undefined;
42
+ } & import("../../../index.js").Brands<{
43
+ readonly id: import("../../../index.js").NumericColumn<{
44
+ readonly type: NumberConstructor;
45
+ } & {
46
+ readonly isId: true;
47
+ }, number>;
48
+ readonly name: import("../../../index.js").StringColumn<{
49
+ readonly type: StringConstructor;
50
+ }, string>;
51
+ readonly bio: import("../../../index.js").StringColumn<{
52
+ readonly type: StringConstructor;
53
+ } & {
54
+ readonly nullable: true;
55
+ }, string>;
56
+ readonly createdAt: import("../../../index.js").DateColumn<{
57
+ readonly type: DateConstructor;
58
+ } & {
59
+ readonly defaultValue: unknown;
60
+ }, Date>;
61
+ }> & import("../../../index.js").RelationRow<{
62
+ readonly books: () => import("../../../index.js").SchemaRelation<object & {
63
+ id: number;
64
+ title: string;
65
+ stock: number;
66
+ status: "draft" | "published";
67
+ version: number;
68
+ authorId: number;
69
+ } & {} & import("../../../index.js").Brands<{
70
+ readonly id: import("../../../index.js").NumericColumn<{
71
+ readonly type: NumberConstructor;
72
+ } & {
73
+ readonly isId: true;
74
+ }, number>;
75
+ readonly title: import("../../../index.js").StringColumn<{
76
+ readonly type: StringConstructor;
77
+ }, string>;
78
+ readonly stock: import("../../../index.js").NumericColumn<{
79
+ readonly type: NumberConstructor;
80
+ } & {
81
+ readonly defaultValue: unknown;
82
+ }, number>;
83
+ readonly status: import("../../../index.js").StringColumn<{
84
+ readonly type: StringConstructor;
85
+ readonly enum: readonly ["draft", "published"];
86
+ }, "draft" | "published">;
87
+ readonly version: import("../../../index.js").VersionColumn<{
88
+ readonly type: NumberConstructor;
89
+ readonly version: true;
90
+ }, number>;
91
+ readonly authorId: import("../../../index.js").NumericColumn<{
92
+ readonly type: NumberConstructor;
93
+ }, number>;
94
+ }> & {
95
+ readonly shout?: string | null | undefined;
96
+ } & import("../../../index.js").RelationRow</*elided*/ any> & import("../../../index.js").AggregateRow<{}>, "1m", {
97
+ id: number;
98
+ title: string;
99
+ stock: number;
100
+ status: "draft" | "published";
101
+ version: number;
102
+ authorId: number;
103
+ } & {} & {
104
+ readonly shout?: string | null | undefined;
105
+ }>;
106
+ }> & import("../../../index.js").AggregateRow<{
107
+ readonly bookCount: () => import("../../../index.js").RelationAggregate<number>;
108
+ readonly topStock: () => import("../../../index.js").RelationAggregate<number | null>;
109
+ }>, "m1", object & {
110
+ id: number;
111
+ name: string;
112
+ createdAt: Date;
113
+ } & {
114
+ bio?: string | null | undefined;
115
+ } & import("../../../index.js").Brands<{
116
+ readonly id: import("../../../index.js").NumericColumn<{
117
+ readonly type: NumberConstructor;
118
+ } & {
119
+ readonly isId: true;
120
+ }, number>;
121
+ readonly name: import("../../../index.js").StringColumn<{
122
+ readonly type: StringConstructor;
123
+ }, string>;
124
+ readonly bio: import("../../../index.js").StringColumn<{
125
+ readonly type: StringConstructor;
126
+ } & {
127
+ readonly nullable: true;
128
+ }, string>;
129
+ readonly createdAt: import("../../../index.js").DateColumn<{
130
+ readonly type: DateConstructor;
131
+ } & {
132
+ readonly defaultValue: unknown;
133
+ }, Date>;
134
+ }> & import("../../../index.js").RelationRow<{
135
+ readonly books: () => import("../../../index.js").SchemaRelation<object & {
136
+ id: number;
137
+ title: string;
138
+ stock: number;
139
+ status: "draft" | "published";
140
+ version: number;
141
+ authorId: number;
142
+ } & {} & import("../../../index.js").Brands<{
143
+ readonly id: import("../../../index.js").NumericColumn<{
144
+ readonly type: NumberConstructor;
145
+ } & {
146
+ readonly isId: true;
147
+ }, number>;
148
+ readonly title: import("../../../index.js").StringColumn<{
149
+ readonly type: StringConstructor;
150
+ }, string>;
151
+ readonly stock: import("../../../index.js").NumericColumn<{
152
+ readonly type: NumberConstructor;
153
+ } & {
154
+ readonly defaultValue: unknown;
155
+ }, number>;
156
+ readonly status: import("../../../index.js").StringColumn<{
157
+ readonly type: StringConstructor;
158
+ readonly enum: readonly ["draft", "published"];
159
+ }, "draft" | "published">;
160
+ readonly version: import("../../../index.js").VersionColumn<{
161
+ readonly type: NumberConstructor;
162
+ readonly version: true;
163
+ }, number>;
164
+ readonly authorId: import("../../../index.js").NumericColumn<{
165
+ readonly type: NumberConstructor;
166
+ }, number>;
167
+ }> & {
168
+ readonly shout?: string | null | undefined;
169
+ } & import("../../../index.js").RelationRow<any> & import("../../../index.js").AggregateRow<{}>, "1m", {
170
+ id: number;
171
+ title: string;
172
+ stock: number;
173
+ status: "draft" | "published";
174
+ version: number;
175
+ authorId: number;
176
+ } & {} & {
177
+ readonly shout?: string | null | undefined;
178
+ }>;
179
+ }> & import("../../../index.js").AggregateRow<{
180
+ readonly bookCount: () => import("../../../index.js").RelationAggregate<number>;
181
+ readonly topStock: () => import("../../../index.js").RelationAggregate<number | null>;
182
+ }>>;
183
+ }> & import("../../../index.js").AggregateRow<{}>, number, {
184
+ id: number;
185
+ title: string;
186
+ stock: number;
187
+ status: "draft" | "published";
188
+ version: number;
189
+ authorId: number;
190
+ } & {} & {
191
+ readonly shout?: string | null | undefined;
192
+ }>;
@@ -0,0 +1,22 @@
1
+ import { sql } from '../../../util/index.js';
2
+ import { f } from '../../column.js';
3
+ import { defineEntity } from '../definition.js';
4
+ import { Author } from './author.js';
5
+ export const Book = defineEntity({
6
+ name: 'Book',
7
+ fields: {
8
+ id: f.number().id(),
9
+ title: f.string(),
10
+ stock: f.number().default(0),
11
+ status: f.enum(['draft', 'published']),
12
+ version: f.version(),
13
+ authorId: f.number(),
14
+ },
15
+ })
16
+ .computed((book) => ({
17
+ shout: f
18
+ .string()
19
+ .nullable()
20
+ .as(sql `upper(${book.title})`),
21
+ }))
22
+ .relations((rel) => ({ author: () => rel.manyToOne(Author, { references: (book) => book.authorId }) }));
@@ -9,22 +9,21 @@ import { getKeys, isRecord, isWhereMap } from '../util/object.util.js';
9
9
  import { UqlUsageError } from '../util/uqlError.js';
10
10
  /** The flags a request carries beside its query: `hardDelete` on a delete, `count` on a `findMany`. */
11
11
  const WIRE_FLAGS = ['hardDelete', 'count'];
12
- /**
13
- * Keys that mean something locally but that this transport can never honor, so they are rejected
14
- * rather than dropped like the rest. Each request runs on its own auto-committing connection, so a
15
- * row lock taken here is released before the response is written: honoring `$lock` is impossible,
16
- * and ignoring it would hand the caller a read they believe is serialized and is not.
17
- */
18
- const REJECTED_QUERY_KEYS = new Set(['$lock']);
19
12
  /**
20
13
  * The keys accepted from the wire, mapped to how each value is decoded: every query clause ({@link QUERY_CLAUSES})
21
- * plus the {@link WIRE_FLAGS}. Anything else (e.g. `filters`, `context`, `$entity`) is dropped, so a remote
22
- * client can't bypass a security filter or inject ambient context.
14
+ * HTTP carries, plus the {@link WIRE_FLAGS}. Any other `$` key is refused, since dropping a clause answers a read
15
+ * other than the one asked for; any other key (e.g. `filters`, `context`) is dropped, so a remote client can't
16
+ * bypass a security filter or inject ambient context.
23
17
  */
24
18
  const WIRE_VALUES = new Map([
25
- ...getKeys(QUERY_CLAUSES).map((key) => [key, QUERY_CLAUSES[key].value]),
19
+ ...getKeys(QUERY_CLAUSES)
20
+ .filter((key) => carriedOverHttp(QUERY_CLAUSES[key]))
21
+ .map((key) => [key, QUERY_CLAUSES[key].value]),
26
22
  ...WIRE_FLAGS.map((flag) => [flag, 'boolean']),
27
23
  ]);
24
+ function carriedOverHttp(clause) {
25
+ return clause.wire !== false;
26
+ }
28
27
  /**
29
28
  * Parse raw query-string entries (with JSON-stringified values), or a `QUERY` body, into a UQL query
30
29
  * object. Symmetric counterpart of {@link stringifyQuery}. Only the keys in {@link WIRE_VALUES} are honored.
@@ -35,10 +34,10 @@ export function parseQueryParams(params = {}) {
35
34
  }
36
35
  const query = {};
37
36
  for (const key of getKeys(params)) {
38
- if (REJECTED_QUERY_KEYS.has(key)) {
39
- throw new UqlUsageError(`'${key}' is not supported over HTTP`);
40
- }
41
37
  const shape = WIRE_VALUES.get(key);
38
+ if (!shape && key.startsWith('$')) {
39
+ throw new UqlUsageError(`'${key}' is not a query key HTTP takes`);
40
+ }
42
41
  if (shape && params[key] !== undefined) {
43
42
  query[key] = decodeWireValue(key, shape, params[key]);
44
43
  }
package/dist/index.d.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  export { captureContext, getContext, withContext } from './context/context.js';
2
2
  export * from './entity/decorator/entity.js';
3
3
  export * from './entity/decorator/members.js';
4
- export { defineEntity, defineField, defineFilter, defineHook, defineId, defineIndex, defineRelation, defineTrigger, getMeta, idOf, keyOf, removeEntity, } from './entity/metadata/definition.js';
4
+ export { f } from './entity/column.js';
5
+ export { defineEntity, getMeta, idOf, keyOf, removeEntity } from './entity/metadata/definition.js';
5
6
  export * from './namingStrategy/index.js';
6
7
  export { type QueryError, queryErrorKind } from './querier/queryError.js';
7
8
  export type * from './type/index.js';
8
9
  export { filledKey, idKey, isSqlQuerier, versionKey } from './type/index.js';
9
10
  export { withDeleted } from './util/filters.util.js';
10
11
  export { sortOf } from './util/query.util.js';
11
- export type { HookContext } from './util/hook.util.js';
12
12
  export { DefaultLogger } from './util/logger.js';
13
13
  export { currentDate, currentTime, currentTimestamp, raw, refs, sql, uuid, uuidv7 } from './util/sql.js';
14
14
  export { deleteFrom, insertInto, refuse, updateTable, upsertInto } from './util/triggerWrite.js';
package/dist/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  export { captureContext, getContext, withContext } from './context/context.js';
2
2
  export * from './entity/decorator/entity.js';
3
3
  export * from './entity/decorator/members.js';
4
- export { defineEntity, defineField, defineFilter, defineHook, defineId, defineIndex, defineRelation, defineTrigger, getMeta, idOf, keyOf, removeEntity, } from './entity/metadata/definition.js';
4
+ export { f } from './entity/column.js';
5
+ export { defineEntity, getMeta, idOf, keyOf, removeEntity } from './entity/metadata/definition.js';
5
6
  export * from './namingStrategy/index.js';
6
7
  export { queryErrorKind } from './querier/queryError.js';
7
8
  export { filledKey, idKey, isSqlQuerier, versionKey } from './type/index.js';
@@ -29,7 +29,7 @@ export class MariaDialect extends MysqlLikeSqlDialect {
29
29
  appendRelationArray(ctx, { entity, query, alias, joins }) {
30
30
  const meta = getMeta(entity);
31
31
  const terms = this.projection(ctx, entity, query, { prefix: alias, json: true }, joins);
32
- const order = this.buildFragment(ctx, (fragmentCtx) => this.sort(fragmentCtx, entity, query, { prefix: alias, joins }));
32
+ const order = this.buildFragment(ctx, (fragmentCtx) => this.sort(fragmentCtx, entity, query, { prefix: alias, joins, unaliased: true }));
33
33
  const page = this.buildFragment(ctx, (fragmentCtx) => this.pager(fragmentCtx, query));
34
34
  const from = this.buildFragment(ctx, (fragmentCtx) => {
35
35
  this.selectRelationJoins(fragmentCtx, meta, alias, joins);
@@ -25,9 +25,7 @@ export class MariadbQuerier extends AbstractPoolQuerier {
25
25
  }
26
26
  }
27
27
  finally {
28
- if ('close' in stream && typeof stream.close === 'function') {
29
- stream.close();
30
- }
28
+ stream.close?.();
31
29
  }
32
30
  }
33
31
  /**
@@ -1,81 +1,33 @@
1
+ import { type ColumnOptionsBuilder } from '../../entity/columnOptionsBuilder.js';
2
+ import type { EnumValues, ForeignKeyAction } from '../../schema/types.js';
3
+ import { type FieldOptions } from '../../type/index.js';
4
+ import type { ForeignKeyBuilder, FullColumnDefinition, TableColumnFactory } from './types.js';
1
5
  /**
2
- * Column Builder
3
- *
4
- * Fluent API for defining columns in migrations.
6
+ * A table's column, named, over the `f` builder an entity column is: each method is that builder's, and `build` reads
7
+ * its options as the schema reads an entity's. Mutable, since the table collects it before its chain ends.
5
8
  */
6
- import type { CanonicalType, EnumValues, ForeignKeyAction } from '../../schema/types.js';
7
- import type { BaseColumnOptions, FullColumnDefinition, ColumnBuilder, ForeignKeyBuilder } from './types.js';
8
- /**
9
- * Builder for column definitions with a fluent API. Each call replaces the definition it holds, and `build`
10
- * returns it. Columns are NOT NULL by default (safer).
11
- */
12
- export declare class ColumnDefinitionBuilder implements ColumnBuilder, ForeignKeyBuilder {
13
- private column;
14
- constructor(name: string, type: CanonicalType, options?: BaseColumnOptions);
15
- private set;
16
- /**
17
- * Make the column nullable or not nullable.
18
- */
19
- nullable(value?: boolean): this;
20
- /**
21
- * Make the column NOT NULL.
22
- */
23
- notNullable(): this;
24
- /**
25
- * Set a default value for the column.
26
- */
27
- defaultValue(value: unknown): this;
28
- /**
29
- * Mark as primary key.
30
- */
31
- primaryKey(): this;
32
- /**
33
- * Enable auto-increment (for integer types).
34
- */
9
+ export declare class TableColumn implements ForeignKeyBuilder {
10
+ #private;
11
+ constructor(name: string, column: ColumnOptionsBuilder);
12
+ private chain;
13
+ nullable(): this;
14
+ default(value: FieldOptions['defaultValue']): this;
15
+ id(): this;
35
16
  autoIncrement(): this;
36
- /**
37
- * Add a unique constraint.
38
- */
39
17
  unique(): this;
40
- /**
41
- * Make the column one the database computes: `GENERATED ALWAYS AS (<sql>) STORED`.
42
- *
43
- * Takes the SQL as text, since a `CREATE TABLE` has nowhere to bind a value into - the same reason
44
- * a check expression and a partial-index predicate do.
45
- */
46
- computed(sql: string): this;
47
- /**
48
- * Constrain the column to these values, as a `CHECK (col IN (...))` - what `@Field({ enum })` emits.
49
- */
18
+ as(expression: string): this;
19
+ length(length: number): this;
20
+ precision(digits: number): this;
21
+ scale(digits: number): this;
50
22
  enum(values: EnumValues): this;
51
- /**
52
- * Add a comment to the column.
53
- */
54
23
  comment(text: string): this;
55
- /**
56
- * Add an index on this column.
57
- * @param name - Optional index name. If true, auto-generates name.
58
- */
59
24
  index(name?: string): this;
60
- /**
61
- * Set as unsigned (MySQL/MariaDB).
62
- */
63
25
  unsigned(): this;
64
- /**
65
- * Add a foreign key reference.
66
- * Returns a ForeignKeyBuilder for additional options.
67
- */
68
26
  references(table: string, column?: string): ForeignKeyBuilder;
69
- /**
70
- * Set ON DELETE action for foreign key.
71
- */
72
27
  onDelete(action: ForeignKeyAction): this;
73
- /**
74
- * Set ON UPDATE action for foreign key.
75
- */
76
28
  onUpdate(action: ForeignKeyAction): this;
77
- /**
78
- * Build and return the column definition.
79
- */
29
+ /** A key here is never implied to auto-increment: a migration states what it creates. */
80
30
  build(): FullColumnDefinition;
81
31
  }
32
+ /** Every column type, named and typed as `f` types it; `add` receives each column it makes. */
33
+ export declare function tableColumns(add: (column: TableColumn) => TableColumn): TableColumnFactory;