joist-codegen 2.4.0 → 2.5.0-next.10
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/build/EntityDbMetadata.cjs +50 -8
- package/build/EntityDbMetadata.cjs.map +1 -1
- package/build/EntityDbMetadata.d.cts +36 -28
- package/build/EntityDbMetadata.d.cts.map +1 -1
- package/build/EntityDbMetadata.d.mts +36 -28
- package/build/EntityDbMetadata.d.mts.map +1 -1
- package/build/EntityDbMetadata.js +50 -9
- package/build/EntityDbMetadata.js.map +1 -1
- package/build/_virtual/_rolldown/runtime.cjs +1 -2
- package/build/_virtual/_rolldown/runtime.js +1 -2
- package/build/assignTags.cjs +2 -3
- package/build/assignTags.d.cts +1 -4
- package/build/assignTags.d.cts.map +1 -1
- package/build/assignTags.d.mts +1 -4
- package/build/assignTags.d.mts.map +1 -1
- package/build/assignTags.js +2 -3
- package/build/codemods/Codemod.d.cts +1 -4
- package/build/codemods/Codemod.d.cts.map +1 -1
- package/build/codemods/Codemod.d.mts +1 -4
- package/build/codemods/Codemod.d.mts.map +1 -1
- package/build/codemods/JscodeshiftMod.cjs +2 -3
- package/build/codemods/JscodeshiftMod.d.cts +1 -4
- package/build/codemods/JscodeshiftMod.d.cts.map +1 -1
- package/build/codemods/JscodeshiftMod.d.mts +1 -4
- package/build/codemods/JscodeshiftMod.d.mts.map +1 -1
- package/build/codemods/JscodeshiftMod.js +2 -3
- package/build/codemods/codemod_0001-rename_has_async_property.cjs +1 -2
- package/build/codemods/codemod_0001-rename_has_async_property.d.cts +2 -4
- package/build/codemods/codemod_0001-rename_has_async_property.d.cts.map +1 -1
- package/build/codemods/codemod_0001-rename_has_async_property.d.mts +2 -4
- package/build/codemods/codemod_0001-rename_has_async_property.d.mts.map +1 -1
- package/build/codemods/codemod_0001-rename_has_async_property.js +1 -2
- package/build/codemods/codemod_0002-rename_async_query_fields.cjs +1 -2
- package/build/codemods/codemod_0002-rename_async_query_fields.d.cts +2 -4
- package/build/codemods/codemod_0002-rename_async_query_fields.d.cts.map +1 -1
- package/build/codemods/codemod_0002-rename_async_query_fields.d.mts +2 -4
- package/build/codemods/codemod_0002-rename_async_query_fields.d.mts.map +1 -1
- package/build/codemods/codemod_0002-rename_async_query_fields.js +1 -2
- package/build/codemods/codemod_0003-rename_find_paginated.cjs +1 -2
- package/build/codemods/codemod_0003-rename_find_paginated.d.cts +2 -4
- package/build/codemods/codemod_0003-rename_find_paginated.d.cts.map +1 -1
- package/build/codemods/codemod_0003-rename_find_paginated.d.mts +2 -4
- package/build/codemods/codemod_0003-rename_find_paginated.d.mts.map +1 -1
- package/build/codemods/codemod_0003-rename_find_paginated.js +1 -2
- package/build/codemods/index.cjs +2 -3
- package/build/codemods/index.d.cts +3 -6
- package/build/codemods/index.d.cts.map +1 -1
- package/build/codemods/index.d.mts +3 -6
- package/build/codemods/index.d.mts.map +1 -1
- package/build/codemods/index.js +2 -3
- package/build/config.cjs +11 -7
- package/build/config.cjs.map +1 -1
- package/build/config.d.cts +30 -29
- package/build/config.d.cts.map +1 -1
- package/build/config.d.mts +30 -29
- package/build/config.d.mts.map +1 -1
- package/build/config.js +11 -7
- package/build/config.js.map +1 -1
- package/build/docs/cache.cjs +1 -2
- package/build/docs/cache.cjs.map +1 -1
- package/build/docs/cache.d.cts +2 -5
- package/build/docs/cache.d.cts.map +1 -1
- package/build/docs/cache.d.mts +2 -5
- package/build/docs/cache.d.mts.map +1 -1
- package/build/docs/cache.js +1 -2
- package/build/docs/cache.js.map +1 -1
- package/build/docs/generate-metadata-docs.cjs +2 -3
- package/build/docs/generate-metadata-docs.d.cts +1 -4
- package/build/docs/generate-metadata-docs.d.cts.map +1 -1
- package/build/docs/generate-metadata-docs.d.mts +1 -4
- package/build/docs/generate-metadata-docs.d.mts.map +1 -1
- package/build/docs/generate-metadata-docs.js +2 -3
- package/build/docs/index.cjs +1 -2
- package/build/docs/index.d.cts +3 -5
- package/build/docs/index.d.cts.map +1 -1
- package/build/docs/index.d.mts +3 -5
- package/build/docs/index.d.mts.map +1 -1
- package/build/docs/index.js +1 -2
- package/build/docs/markdown.cjs +1 -2
- package/build/docs/markdown.d.cts +8 -10
- package/build/docs/markdown.d.cts.map +1 -1
- package/build/docs/markdown.d.mts +8 -10
- package/build/docs/markdown.d.mts.map +1 -1
- package/build/docs/markdown.js +1 -2
- package/build/docs/parsing.cjs +1 -2
- package/build/docs/parsing.d.cts +9 -11
- package/build/docs/parsing.d.cts.map +1 -1
- package/build/docs/parsing.d.mts +9 -11
- package/build/docs/parsing.d.mts.map +1 -1
- package/build/docs/parsing.js +1 -2
- package/build/findEntityScopes.cjs +1 -2
- package/build/findEntityScopes.d.cts +3 -6
- package/build/findEntityScopes.d.cts.map +1 -1
- package/build/findEntityScopes.d.mts +3 -6
- package/build/findEntityScopes.d.mts.map +1 -1
- package/build/findEntityScopes.js +1 -2
- package/build/foreignKeyOrdering.cjs +4 -5
- package/build/foreignKeyOrdering.d.cts +1 -4
- package/build/foreignKeyOrdering.d.cts.map +1 -1
- package/build/foreignKeyOrdering.d.mts +1 -4
- package/build/foreignKeyOrdering.d.mts.map +1 -1
- package/build/foreignKeyOrdering.js +4 -5
- package/build/generate.cjs +4 -5
- package/build/generate.cjs.map +1 -1
- package/build/generate.d.cts +3 -6
- package/build/generate.d.cts.map +1 -1
- package/build/generate.d.mts +3 -6
- package/build/generate.d.mts.map +1 -1
- package/build/generate.js +4 -5
- package/build/generateEntitiesFile.cjs +4 -5
- package/build/generateEntitiesFile.d.cts +3 -6
- package/build/generateEntitiesFile.d.cts.map +1 -1
- package/build/generateEntitiesFile.d.mts +3 -6
- package/build/generateEntitiesFile.d.mts.map +1 -1
- package/build/generateEntitiesFile.js +4 -5
- package/build/generateEntityCodegenFile.cjs +39 -25
- package/build/generateEntityCodegenFile.cjs.map +1 -1
- package/build/generateEntityCodegenFile.d.cts +5 -8
- package/build/generateEntityCodegenFile.d.cts.map +1 -1
- package/build/generateEntityCodegenFile.d.mts +5 -8
- package/build/generateEntityCodegenFile.d.mts.map +1 -1
- package/build/generateEntityCodegenFile.js +39 -25
- package/build/generateEntityCodegenFile.js.map +1 -1
- package/build/generateEntityFile.cjs +1 -2
- package/build/generateEntityFile.d.cts +1 -4
- package/build/generateEntityFile.d.cts.map +1 -1
- package/build/generateEntityFile.d.mts +1 -4
- package/build/generateEntityFile.d.mts.map +1 -1
- package/build/generateEntityFile.js +1 -2
- package/build/generateEntityTestFile.cjs +1 -2
- package/build/generateEntityTestFile.d.cts +1 -4
- package/build/generateEntityTestFile.d.cts.map +1 -1
- package/build/generateEntityTestFile.d.mts +1 -4
- package/build/generateEntityTestFile.d.mts.map +1 -1
- package/build/generateEntityTestFile.js +1 -2
- package/build/generateEnumFile.cjs +2 -3
- package/build/generateEnumFile.d.cts +1 -4
- package/build/generateEnumFile.d.cts.map +1 -1
- package/build/generateEnumFile.d.mts +1 -4
- package/build/generateEnumFile.d.mts.map +1 -1
- package/build/generateEnumFile.js +2 -3
- package/build/generateFactoriesFiles.cjs +2 -3
- package/build/generateFactoriesFiles.d.cts +1 -4
- package/build/generateFactoriesFiles.d.cts.map +1 -1
- package/build/generateFactoriesFiles.d.mts +1 -4
- package/build/generateFactoriesFiles.d.mts.map +1 -1
- package/build/generateFactoriesFiles.js +2 -3
- package/build/generateFlushFunction.cjs +1 -2
- package/build/generateFlushFunction.d.cts +3 -6
- package/build/generateFlushFunction.d.cts.map +1 -1
- package/build/generateFlushFunction.d.mts +3 -6
- package/build/generateFlushFunction.d.mts.map +1 -1
- package/build/generateFlushFunction.js +1 -2
- package/build/generateMetadataFile.cjs +36 -5
- package/build/generateMetadataFile.cjs.map +1 -1
- package/build/generateMetadataFile.d.cts +2 -5
- package/build/generateMetadataFile.d.cts.map +1 -1
- package/build/generateMetadataFile.d.mts +2 -5
- package/build/generateMetadataFile.d.mts.map +1 -1
- package/build/generateMetadataFile.js +37 -6
- package/build/generateMetadataFile.js.map +1 -1
- package/build/generatePgEnumFile.cjs +1 -2
- package/build/generatePgEnumFile.d.cts +1 -4
- package/build/generatePgEnumFile.d.cts.map +1 -1
- package/build/generatePgEnumFile.d.mts +1 -4
- package/build/generatePgEnumFile.d.mts.map +1 -1
- package/build/generatePgEnumFile.js +1 -2
- package/build/index.cjs +8 -9
- package/build/index.d.cts +5 -7
- package/build/index.d.cts.map +1 -1
- package/build/index.d.mts +5 -7
- package/build/index.d.mts.map +1 -1
- package/build/index.js +8 -9
- package/build/inheritance.cjs +2 -3
- package/build/inheritance.d.cts +3 -5
- package/build/inheritance.d.cts.map +1 -1
- package/build/inheritance.d.mts +3 -5
- package/build/inheritance.d.mts.map +1 -1
- package/build/inheritance.js +2 -3
- package/build/installSkills.cjs +1 -2
- package/build/installSkills.d.cts +1 -4
- package/build/installSkills.d.cts.map +1 -1
- package/build/installSkills.d.mts +1 -4
- package/build/installSkills.d.mts.map +1 -1
- package/build/installSkills.js +1 -2
- package/build/keywords.cjs +1 -2
- package/build/keywords.d.cts +1 -4
- package/build/keywords.d.cts.map +1 -1
- package/build/keywords.d.mts +1 -4
- package/build/keywords.d.mts.map +1 -1
- package/build/keywords.js +1 -2
- package/build/loadMetadata.cjs +2 -3
- package/build/loadMetadata.d.cts +8 -11
- package/build/loadMetadata.d.cts.map +1 -1
- package/build/loadMetadata.d.mts +8 -11
- package/build/loadMetadata.d.mts.map +1 -1
- package/build/loadMetadata.js +2 -3
- package/build/logger.cjs +1 -2
- package/build/logger.d.cts +3 -6
- package/build/logger.d.cts.map +1 -1
- package/build/logger.d.mts +3 -6
- package/build/logger.d.mts.map +1 -1
- package/build/logger.js +1 -2
- package/build/pgMetadata.cjs +1 -2
- package/build/pgMetadata.d.cts +13 -16
- package/build/pgMetadata.d.cts.map +1 -1
- package/build/pgMetadata.d.mts +13 -16
- package/build/pgMetadata.d.mts.map +1 -1
- package/build/pgMetadata.js +1 -2
- package/build/scanEntityFiles.cjs +7 -3
- package/build/scanEntityFiles.cjs.map +1 -1
- package/build/scanEntityFiles.d.cts +2 -5
- package/build/scanEntityFiles.d.cts.map +1 -1
- package/build/scanEntityFiles.d.mts +2 -5
- package/build/scanEntityFiles.d.mts.map +1 -1
- package/build/scanEntityFiles.js +7 -3
- package/build/scanEntityFiles.js.map +1 -1
- package/build/sortForeignKeys.cjs +1 -2
- package/build/sortForeignKeys.d.cts +1 -4
- package/build/sortForeignKeys.d.cts.map +1 -1
- package/build/sortForeignKeys.d.mts +1 -4
- package/build/sortForeignKeys.d.mts.map +1 -1
- package/build/sortForeignKeys.js +1 -2
- package/build/symbols.cjs +3 -2
- package/build/symbols.cjs.map +1 -1
- package/build/symbols.d.cts +117 -119
- package/build/symbols.d.cts.map +1 -1
- package/build/symbols.d.mts +117 -119
- package/build/symbols.d.mts.map +1 -1
- package/build/symbols.js +3 -3
- package/build/symbols.js.map +1 -1
- package/build/tsdoc.cjs +1 -2
- package/build/tsdoc.d.cts +1 -4
- package/build/tsdoc.d.cts.map +1 -1
- package/build/tsdoc.d.mts +1 -4
- package/build/tsdoc.d.mts.map +1 -1
- package/build/tsdoc.js +1 -2
- package/build/utils.cjs +3 -3
- package/build/utils.cjs.map +1 -1
- package/build/utils.d.cts +22 -25
- package/build/utils.d.cts.map +1 -1
- package/build/utils.d.mts +22 -25
- package/build/utils.d.mts.map +1 -1
- package/build/utils.js +3 -3
- package/build/utils.js.map +1 -1
- package/build/write-json-schema.cjs +1 -2
- package/build/write-json-schema.js +1 -2
- package/package.json +10 -10
- package/skills/joist-test-factories/SKILL.md +93 -6
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Config } from "./config.cjs";
|
|
2
|
-
import { Action, Column, M2MRelation, M2ORelation, O2MRelation, Table } from "./pgMetadata.cjs";
|
|
3
2
|
import { EnumMetadata, EnumRow, PgEnumMetadata } from "./loadMetadata.cjs";
|
|
3
|
+
import { Action, Column, M2MRelation, M2ORelation, O2MRelation, Table } from "./pgMetadata.cjs";
|
|
4
4
|
import { Code, Import } from "ts-poet";
|
|
5
|
-
//#region src/EntityDbMetadata.d.ts
|
|
6
5
|
/** All the entities + enums in our database. */
|
|
7
|
-
interface DbMetadata {
|
|
6
|
+
export interface DbMetadata {
|
|
8
7
|
entities: EntityDbMetadata[];
|
|
9
8
|
/** Type name i.e. `Author` to metadata. */
|
|
10
9
|
entitiesByName: Record<string, EntityDbMetadata>;
|
|
@@ -16,7 +15,7 @@ interface DbMetadata {
|
|
|
16
15
|
totalTables: number;
|
|
17
16
|
}
|
|
18
17
|
/** Codegen-time metadata about a given domain entity. */
|
|
19
|
-
type Entity = {
|
|
18
|
+
export type Entity = {
|
|
20
19
|
name: string;
|
|
21
20
|
/** The _type_ symbol pointing to the entity itself. */
|
|
22
21
|
type: Import;
|
|
@@ -56,7 +55,7 @@ type Entity = {
|
|
|
56
55
|
/** i.e. `AuthorScopes`. */
|
|
57
56
|
scopesName: string;
|
|
58
57
|
};
|
|
59
|
-
type DatabaseColumnType = "boolean" | "int" | "uuid" | "numeric" | "smallint" | "integer" | "bigint" | "decimal" | "real" | "smallserial" | "serial" | "bigserial" | "double precision" | "text" | "citext" | "character varying" | "varchar" | "time without time zone" | "timestamp with time zone" | "timestamp without time zone" | "date" | "jsonb" | "bytea" | "tsvector" | "tstzrange";
|
|
58
|
+
export type DatabaseColumnType = "boolean" | "int" | "uuid" | "numeric" | "smallint" | "integer" | "bigint" | "decimal" | "real" | "smallserial" | "serial" | "bigserial" | "double precision" | "text" | "citext" | "character varying" | "varchar" | "time without time zone" | "timestamp with time zone" | "timestamp without time zone" | "date" | "jsonb" | "bytea" | "tsvector" | "tstzrange" | "vector";
|
|
60
59
|
/**
|
|
61
60
|
* A logical entity field.
|
|
62
61
|
*
|
|
@@ -66,8 +65,8 @@ interface Field {
|
|
|
66
65
|
fieldName: string;
|
|
67
66
|
ignore?: boolean;
|
|
68
67
|
}
|
|
69
|
-
type PrimitiveTypescriptType = "boolean" | "string" | "number" | "Object" | "bigint" | "Uint8Array" | Code;
|
|
70
|
-
type PrimitiveField = Field & {
|
|
68
|
+
export type PrimitiveTypescriptType = "boolean" | "string" | "number" | "number[]" | "Object" | "bigint" | "Uint8Array" | Code;
|
|
69
|
+
export type PrimitiveField = Field & {
|
|
71
70
|
kind: "primitive";
|
|
72
71
|
columnName: string;
|
|
73
72
|
/** Physical table owner, unchanged by domain inheritance specialization. */
|
|
@@ -90,7 +89,7 @@ type PrimitiveField = Field & {
|
|
|
90
89
|
hasConfigDefault: boolean;
|
|
91
90
|
lazy?: boolean;
|
|
92
91
|
};
|
|
93
|
-
type EnumField = Field & {
|
|
92
|
+
export type EnumField = Field & {
|
|
94
93
|
kind: "enum";
|
|
95
94
|
columnName: string;
|
|
96
95
|
/** Physical table owner, unchanged by domain inheritance specialization. */
|
|
@@ -108,8 +107,10 @@ type EnumField = Field & {
|
|
|
108
107
|
notNull: boolean;
|
|
109
108
|
isArray: boolean;
|
|
110
109
|
hasConfigDefault: boolean;
|
|
110
|
+
/** Whether the entity file calls `config.setTransitions`, `addTransitionRule`, or `addTransitionReaction` on this field, set by `scanEntityFiles`. */
|
|
111
|
+
hasTransitions: boolean;
|
|
111
112
|
};
|
|
112
|
-
type PgEnumField = Field & {
|
|
113
|
+
export type PgEnumField = Field & {
|
|
113
114
|
kind: "pg-enum";
|
|
114
115
|
columnName: string;
|
|
115
116
|
/** Physical table owner, unchanged by domain inheritance specialization. */
|
|
@@ -127,7 +128,7 @@ type PgEnumField = Field & {
|
|
|
127
128
|
hasConfigDefault: boolean;
|
|
128
129
|
};
|
|
129
130
|
/** I.e. a `Book.author` reference pointing to an `Author`. */
|
|
130
|
-
type ManyToOneField = Field & {
|
|
131
|
+
export type ManyToOneField = Field & {
|
|
131
132
|
kind: "m2o";
|
|
132
133
|
columnName: string;
|
|
133
134
|
/** Physical table owner, unchanged by domain inheritance specialization. */
|
|
@@ -146,7 +147,7 @@ type ManyToOneField = Field & {
|
|
|
146
147
|
onDelete: Action;
|
|
147
148
|
};
|
|
148
149
|
/** I.e. a `Author.books` collection. */
|
|
149
|
-
type OneToManyField = Field & {
|
|
150
|
+
export type OneToManyField = Field & {
|
|
150
151
|
kind: "o2m";
|
|
151
152
|
singularName: string;
|
|
152
153
|
otherEntity: Entity;
|
|
@@ -161,14 +162,14 @@ type OneToManyField = Field & {
|
|
|
161
162
|
softDeletes: "include" | "exclude" | undefined;
|
|
162
163
|
};
|
|
163
164
|
/** I.e. a `Author.image` reference when `image.author_id` is unique. */
|
|
164
|
-
type OneToOneField = Field & {
|
|
165
|
+
export type OneToOneField = Field & {
|
|
165
166
|
kind: "o2o";
|
|
166
167
|
otherEntity: Entity;
|
|
167
168
|
otherFieldName: string;
|
|
168
169
|
otherColumnName: string;
|
|
169
170
|
otherColumnNotNull: boolean;
|
|
170
171
|
};
|
|
171
|
-
type ManyToManyField = Field & {
|
|
172
|
+
export type ManyToManyField = Field & {
|
|
172
173
|
kind: "m2m";
|
|
173
174
|
joinTableName: string;
|
|
174
175
|
singularName: string;
|
|
@@ -184,7 +185,7 @@ type ManyToManyField = Field & {
|
|
|
184
185
|
hasJoinTableId: boolean;
|
|
185
186
|
};
|
|
186
187
|
/** I.e. a `Publisher.logoColors` m2m to the `color` enum table, backed by `publisher_logo_colors`. */
|
|
187
|
-
type ManyToManyEnumField = Field & {
|
|
188
|
+
export type ManyToManyEnumField = Field & {
|
|
188
189
|
kind: "m2mEnum";
|
|
189
190
|
joinTableName: string;
|
|
190
191
|
/** The entity's FK column, e.g. `publisher_id`. */
|
|
@@ -200,7 +201,7 @@ type ManyToManyEnumField = Field & {
|
|
|
200
201
|
hasJoinTableId: boolean;
|
|
201
202
|
};
|
|
202
203
|
/** I.e. a `Comment.parent` reference that groups `comments.parent_book_id` and `comments.parent_book_review_id`. */
|
|
203
|
-
type PolymorphicField = Field & {
|
|
204
|
+
export type PolymorphicField = Field & {
|
|
204
205
|
kind: "poly";
|
|
205
206
|
fieldType: string;
|
|
206
207
|
notNull: boolean;
|
|
@@ -208,7 +209,7 @@ type PolymorphicField = Field & {
|
|
|
208
209
|
components: PolymorphicFieldComponent[];
|
|
209
210
|
};
|
|
210
211
|
/** A column such as `parent_book_id` or `parent_book_review_id`. */
|
|
211
|
-
type PolymorphicFieldComponent = {
|
|
212
|
+
export type PolymorphicFieldComponent = {
|
|
212
213
|
columnName: string;
|
|
213
214
|
/** Physical table owner, unchanged by domain inheritance specialization. */
|
|
214
215
|
columnOwner: Entity;
|
|
@@ -218,12 +219,12 @@ type PolymorphicFieldComponent = {
|
|
|
218
219
|
constraintName: string;
|
|
219
220
|
notNull: false;
|
|
220
221
|
};
|
|
221
|
-
type FieldNameOverrides = {
|
|
222
|
+
export type FieldNameOverrides = {
|
|
222
223
|
fieldName?: string;
|
|
223
224
|
otherFieldName?: string;
|
|
224
225
|
};
|
|
225
226
|
/** Adapts PostgreSQL catalog metadata into our specific ORM types. */
|
|
226
|
-
declare class EntityDbMetadata {
|
|
227
|
+
export declare class EntityDbMetadata {
|
|
227
228
|
entity: Entity;
|
|
228
229
|
primaryKey: PrimitiveField;
|
|
229
230
|
primitives: PrimitiveField[];
|
|
@@ -265,16 +266,16 @@ declare class EntityDbMetadata {
|
|
|
265
266
|
get nonDeferredManyToManyFks(): Array<ManyToManyField>;
|
|
266
267
|
}
|
|
267
268
|
/** Finds the field name for o2o side of a o2o/m2o. */
|
|
268
|
-
declare function oneToOneName(config: Config, refEntity: Entity, keyEntity: Entity, r: M2ORelation | O2MRelation): string;
|
|
269
|
-
declare function referenceName(config: Config, entity: Entity, r: M2ORelation | O2MRelation): string;
|
|
270
|
-
declare function manyToManyName(column: Column): string;
|
|
269
|
+
export declare function oneToOneName(config: Config, refEntity: Entity, keyEntity: Entity, r: M2ORelation | O2MRelation): string;
|
|
270
|
+
export declare function referenceName(config: Config, entity: Entity, r: M2ORelation | O2MRelation): string;
|
|
271
|
+
export declare function manyToManyName(column: Column): string;
|
|
271
272
|
/** Returns the collection name to use on `entity` when referring to `otherEntity`s. */
|
|
272
|
-
declare function collectionName(config: Config, singleEntity: Entity, collectionEntity: Entity, r: M2ORelation | O2MRelation | M2MRelation): {
|
|
273
|
+
export declare function collectionName(config: Config, singleEntity: Entity, collectionEntity: Entity, r: M2ORelation | O2MRelation | M2MRelation): {
|
|
273
274
|
fieldName: string;
|
|
274
275
|
singularName: string;
|
|
275
276
|
};
|
|
276
|
-
declare function failIfOverlappingFieldNames(entity: EntityDbMetadata): void;
|
|
277
|
-
declare function makeEntity(entityName: string): Entity;
|
|
277
|
+
export declare function failIfOverlappingFieldNames(entity: EntityDbMetadata): void;
|
|
278
|
+
export declare function makeEntity(entityName: string): Entity;
|
|
278
279
|
/**
|
|
279
280
|
* Collapses the per-relation `otherEntity` copies down to the one primary `Entity` per name.
|
|
280
281
|
*
|
|
@@ -284,18 +285,25 @@ declare function makeEntity(entityName: string): Entity;
|
|
|
284
285
|
*
|
|
285
286
|
* Must run after inheritance, since STI/CTI specialization both adds and re-points `otherEntity`s.
|
|
286
287
|
*/
|
|
287
|
-
declare function canonicalizeOtherEntities(db: DbMetadata): void;
|
|
288
|
+
export declare function canonicalizeOtherEntities(db: DbMetadata): void;
|
|
288
289
|
/**
|
|
289
290
|
* Rewrites codegen'd type names that collide with another exported type name.
|
|
290
291
|
*
|
|
291
292
|
* `makeEntity` defaults each name to the conventional `${name}<Suffix>`, but if a separate entity or
|
|
292
293
|
* enum is literally named e.g. `AuthorScope` or `AuthorOrder`, our generated type of the same name
|
|
293
294
|
* would collide with it, so we fall back to `Author_Scope` / `Author_Order`.
|
|
295
|
+
* Polymorphic unions yield to these API names by appending `Poly` until the name is available.
|
|
294
296
|
*
|
|
295
297
|
* Relies on `canonicalizeOtherEntities` having run, so mutating each primary `meta.entity` also updates
|
|
296
298
|
* the `otherEntity` references that point at it (e.g. `Book.author: AuthorId` follows `Author`'s rename).
|
|
297
299
|
*/
|
|
298
|
-
declare function resolveNameConflicts(config: Config, db: DbMetadata): void;
|
|
299
|
-
|
|
300
|
-
|
|
300
|
+
export declare function resolveNameConflicts(config: Config, db: DbMetadata): void;
|
|
301
|
+
/**
|
|
302
|
+
* Assigns family-wide scalar-field ordinals for metadata and generated first-read guards.
|
|
303
|
+
*
|
|
304
|
+
* Inherited getters must use the same bits on every subtype, including fields that
|
|
305
|
+
* specialize an inherited field. Value storage remains the existing data bag.
|
|
306
|
+
*/
|
|
307
|
+
export declare function getFieldReadIndexes(meta: EntityDbMetadata): ReadonlyMap<string, number>;
|
|
308
|
+
export {};
|
|
301
309
|
//# sourceMappingURL=EntityDbMetadata.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityDbMetadata.d.cts","names":[],"sources":["../src/EntityDbMetadata.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"EntityDbMetadata.d.cts","names":[],"sources":["../src/EntityDbMetadata.ts"],"mappings":";;;;;iBAmDiB;EACf,UAAU;;EAEV,gBAAgB,eAAe;EAC/B,OAAO;EACP,SAAS;EACT;;EAEA;EACA;;;YAIU;EACV;;EAEA,MAAM;;EAEN,YAAY;;EAEZ,qBAAqB;;EAErB;;EAEA,UAAU;;EAEV,QAAQ;;EAER,WAAW;;EAEX,aAAa;EACb,UAAU;;EAKV;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;YAGU;;;;;;UAiCF;EACR;EACA;;YAGU,8GAQR;YAEQ,iBAAiB;EAC3B;EACA;;EAEA,aAAa;EACb,YAAY;EACZ;EACA;;EAEA;EAEA,WAAW,0BAA0B;EACrC,cAAc;EACd;EACA;EACA;EACA;EACA,aAAa;EACb,WAAW;EACX,aAAa;EACb;EACA;EACA;;YAGU,YAAY;EACtB;EACA;;EAEA,aAAa;EACb,YAAY;EACZ;EACA;EACA;EACA;EACA;EACA,UAAU;EACV,gBAAgB;EAChB,iBAAiB;EACjB,UAAU;EACV;EACA;EACA;;EAEA;;YAGU,cAAc;EACxB;EACA;;EAEA,aAAa;EACb;EACA;EACA;;EAEA;;EAEA;EACA,UAAU;EACV;EACA;EACA;;;YAIU,iBAAiB;EAC3B;EACA;;EAEA,aAAa;EACb;EACA;EACA;EACA;EACA;EACA,aAAa;EACb;EACA;EACA;EACA;EACA;EACA,UAAU;;;YAIA,iBAAiB;EAC3B;EACA;EACA,aAAa;EACb;EACA;EACA;EACA;EACA;IAAW;IAAe;;EAC1B;;;YAIU,gBAAgB;EAC1B;EACA,aAAa;EACb;EACA;EACA;;YAGU,kBAAkB;EAC5B;EACA;EACA;EACA;EACA,aAAa;EACb;EACA;EACA;EACA;EACA;EACA;;EAEA;;;YAIU,sBAAsB;EAChC;EACA;;EAEA;;EAEA;EACA;EACA,UAAU;EACV,gBAAgB;EAChB,iBAAiB;EACjB,UAAU;;EAEV;;;YAIU,mBAAmB;EAC7B;EACA;EACA;EACA;EACA,YAAY;;;YAIF;EACV;;EAEA,aAAa;EACb;EACA,aAAa;EACb;EACA;EACA;;YAGU;EACV;EACA;;;qBAIW;EACX,QAAQ;EACR,YAAY;EACZ,YAAY;EACZ,OAAO;EACP,SAAS;EACT,YAAY;EACZ,YAAY;EACZ,iBAAiB;EACjB,WAAW;EACX,aAAa;EACb,kBAAkB;EAClB,iBAAiB;EACjB,cAAc;EACd;EACA;EACA,WAAW;EACX,WAAW;EACX,WAAW;EACX;EACA,UAAU;EACV,UAAU;EACV;;EAEA;;EAEA;EACA;EACA;EACA;;EAEA;;EAEA,mBAAmB;;EAEnB,gBAAgB;EAEhB,YAAY,QAAQ,QAAQ,OAAO,OAAO,QAAO;MAqI7C;MAIA,kBAAkB,MAAM,iBAAiB;MAOzC,4BAA4B,MAAM;;;wBAucxB,aACd,QAAQ,QAER,WAAW,QAEX,WAAW,QACX,GAAG,cAAc;wBAgCH,cAAc,QAAQ,QAAQ,QAAQ,QAAQ,GAAG,cAAc;wBAmB/D,eAAe,QAAQ;;wBAUvB,eACd,QAAQ,QAER,cAAc,QAEd,kBAAkB,QAClB,GAAG,cAAc,cAAc;EAC5B;EAAmB;;wBA4BR,4BAA4B,QAAQ;wBAwBpC,WAAW,qBAAqB;;;;;;;;;;wBA6BhC,0BAA0B,IAAI;;;;;;;;;;;;wBAiC9B,qBAAqB,QAAQ,QAAQ,IAAI;;;;;;;wBA4IzC,oBAAoB,MAAM,mBAAmB"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Config } from "./config.mjs";
|
|
2
|
-
import { Action, Column, M2MRelation, M2ORelation, O2MRelation, Table } from "./pgMetadata.mjs";
|
|
3
2
|
import { EnumMetadata, EnumRow, PgEnumMetadata } from "./loadMetadata.mjs";
|
|
3
|
+
import { Action, Column, M2MRelation, M2ORelation, O2MRelation, Table } from "./pgMetadata.mjs";
|
|
4
4
|
import { Code, Import } from "ts-poet";
|
|
5
|
-
//#region src/EntityDbMetadata.d.ts
|
|
6
5
|
/** All the entities + enums in our database. */
|
|
7
|
-
interface DbMetadata {
|
|
6
|
+
export interface DbMetadata {
|
|
8
7
|
entities: EntityDbMetadata[];
|
|
9
8
|
/** Type name i.e. `Author` to metadata. */
|
|
10
9
|
entitiesByName: Record<string, EntityDbMetadata>;
|
|
@@ -16,7 +15,7 @@ interface DbMetadata {
|
|
|
16
15
|
totalTables: number;
|
|
17
16
|
}
|
|
18
17
|
/** Codegen-time metadata about a given domain entity. */
|
|
19
|
-
type Entity = {
|
|
18
|
+
export type Entity = {
|
|
20
19
|
name: string;
|
|
21
20
|
/** The _type_ symbol pointing to the entity itself. */
|
|
22
21
|
type: Import;
|
|
@@ -56,7 +55,7 @@ type Entity = {
|
|
|
56
55
|
/** i.e. `AuthorScopes`. */
|
|
57
56
|
scopesName: string;
|
|
58
57
|
};
|
|
59
|
-
type DatabaseColumnType = "boolean" | "int" | "uuid" | "numeric" | "smallint" | "integer" | "bigint" | "decimal" | "real" | "smallserial" | "serial" | "bigserial" | "double precision" | "text" | "citext" | "character varying" | "varchar" | "time without time zone" | "timestamp with time zone" | "timestamp without time zone" | "date" | "jsonb" | "bytea" | "tsvector" | "tstzrange";
|
|
58
|
+
export type DatabaseColumnType = "boolean" | "int" | "uuid" | "numeric" | "smallint" | "integer" | "bigint" | "decimal" | "real" | "smallserial" | "serial" | "bigserial" | "double precision" | "text" | "citext" | "character varying" | "varchar" | "time without time zone" | "timestamp with time zone" | "timestamp without time zone" | "date" | "jsonb" | "bytea" | "tsvector" | "tstzrange" | "vector";
|
|
60
59
|
/**
|
|
61
60
|
* A logical entity field.
|
|
62
61
|
*
|
|
@@ -66,8 +65,8 @@ interface Field {
|
|
|
66
65
|
fieldName: string;
|
|
67
66
|
ignore?: boolean;
|
|
68
67
|
}
|
|
69
|
-
type PrimitiveTypescriptType = "boolean" | "string" | "number" | "Object" | "bigint" | "Uint8Array" | Code;
|
|
70
|
-
type PrimitiveField = Field & {
|
|
68
|
+
export type PrimitiveTypescriptType = "boolean" | "string" | "number" | "number[]" | "Object" | "bigint" | "Uint8Array" | Code;
|
|
69
|
+
export type PrimitiveField = Field & {
|
|
71
70
|
kind: "primitive";
|
|
72
71
|
columnName: string;
|
|
73
72
|
/** Physical table owner, unchanged by domain inheritance specialization. */
|
|
@@ -90,7 +89,7 @@ type PrimitiveField = Field & {
|
|
|
90
89
|
hasConfigDefault: boolean;
|
|
91
90
|
lazy?: boolean;
|
|
92
91
|
};
|
|
93
|
-
type EnumField = Field & {
|
|
92
|
+
export type EnumField = Field & {
|
|
94
93
|
kind: "enum";
|
|
95
94
|
columnName: string;
|
|
96
95
|
/** Physical table owner, unchanged by domain inheritance specialization. */
|
|
@@ -108,8 +107,10 @@ type EnumField = Field & {
|
|
|
108
107
|
notNull: boolean;
|
|
109
108
|
isArray: boolean;
|
|
110
109
|
hasConfigDefault: boolean;
|
|
110
|
+
/** Whether the entity file calls `config.setTransitions`, `addTransitionRule`, or `addTransitionReaction` on this field, set by `scanEntityFiles`. */
|
|
111
|
+
hasTransitions: boolean;
|
|
111
112
|
};
|
|
112
|
-
type PgEnumField = Field & {
|
|
113
|
+
export type PgEnumField = Field & {
|
|
113
114
|
kind: "pg-enum";
|
|
114
115
|
columnName: string;
|
|
115
116
|
/** Physical table owner, unchanged by domain inheritance specialization. */
|
|
@@ -127,7 +128,7 @@ type PgEnumField = Field & {
|
|
|
127
128
|
hasConfigDefault: boolean;
|
|
128
129
|
};
|
|
129
130
|
/** I.e. a `Book.author` reference pointing to an `Author`. */
|
|
130
|
-
type ManyToOneField = Field & {
|
|
131
|
+
export type ManyToOneField = Field & {
|
|
131
132
|
kind: "m2o";
|
|
132
133
|
columnName: string;
|
|
133
134
|
/** Physical table owner, unchanged by domain inheritance specialization. */
|
|
@@ -146,7 +147,7 @@ type ManyToOneField = Field & {
|
|
|
146
147
|
onDelete: Action;
|
|
147
148
|
};
|
|
148
149
|
/** I.e. a `Author.books` collection. */
|
|
149
|
-
type OneToManyField = Field & {
|
|
150
|
+
export type OneToManyField = Field & {
|
|
150
151
|
kind: "o2m";
|
|
151
152
|
singularName: string;
|
|
152
153
|
otherEntity: Entity;
|
|
@@ -161,14 +162,14 @@ type OneToManyField = Field & {
|
|
|
161
162
|
softDeletes: "include" | "exclude" | undefined;
|
|
162
163
|
};
|
|
163
164
|
/** I.e. a `Author.image` reference when `image.author_id` is unique. */
|
|
164
|
-
type OneToOneField = Field & {
|
|
165
|
+
export type OneToOneField = Field & {
|
|
165
166
|
kind: "o2o";
|
|
166
167
|
otherEntity: Entity;
|
|
167
168
|
otherFieldName: string;
|
|
168
169
|
otherColumnName: string;
|
|
169
170
|
otherColumnNotNull: boolean;
|
|
170
171
|
};
|
|
171
|
-
type ManyToManyField = Field & {
|
|
172
|
+
export type ManyToManyField = Field & {
|
|
172
173
|
kind: "m2m";
|
|
173
174
|
joinTableName: string;
|
|
174
175
|
singularName: string;
|
|
@@ -184,7 +185,7 @@ type ManyToManyField = Field & {
|
|
|
184
185
|
hasJoinTableId: boolean;
|
|
185
186
|
};
|
|
186
187
|
/** I.e. a `Publisher.logoColors` m2m to the `color` enum table, backed by `publisher_logo_colors`. */
|
|
187
|
-
type ManyToManyEnumField = Field & {
|
|
188
|
+
export type ManyToManyEnumField = Field & {
|
|
188
189
|
kind: "m2mEnum";
|
|
189
190
|
joinTableName: string;
|
|
190
191
|
/** The entity's FK column, e.g. `publisher_id`. */
|
|
@@ -200,7 +201,7 @@ type ManyToManyEnumField = Field & {
|
|
|
200
201
|
hasJoinTableId: boolean;
|
|
201
202
|
};
|
|
202
203
|
/** I.e. a `Comment.parent` reference that groups `comments.parent_book_id` and `comments.parent_book_review_id`. */
|
|
203
|
-
type PolymorphicField = Field & {
|
|
204
|
+
export type PolymorphicField = Field & {
|
|
204
205
|
kind: "poly";
|
|
205
206
|
fieldType: string;
|
|
206
207
|
notNull: boolean;
|
|
@@ -208,7 +209,7 @@ type PolymorphicField = Field & {
|
|
|
208
209
|
components: PolymorphicFieldComponent[];
|
|
209
210
|
};
|
|
210
211
|
/** A column such as `parent_book_id` or `parent_book_review_id`. */
|
|
211
|
-
type PolymorphicFieldComponent = {
|
|
212
|
+
export type PolymorphicFieldComponent = {
|
|
212
213
|
columnName: string;
|
|
213
214
|
/** Physical table owner, unchanged by domain inheritance specialization. */
|
|
214
215
|
columnOwner: Entity;
|
|
@@ -218,12 +219,12 @@ type PolymorphicFieldComponent = {
|
|
|
218
219
|
constraintName: string;
|
|
219
220
|
notNull: false;
|
|
220
221
|
};
|
|
221
|
-
type FieldNameOverrides = {
|
|
222
|
+
export type FieldNameOverrides = {
|
|
222
223
|
fieldName?: string;
|
|
223
224
|
otherFieldName?: string;
|
|
224
225
|
};
|
|
225
226
|
/** Adapts PostgreSQL catalog metadata into our specific ORM types. */
|
|
226
|
-
declare class EntityDbMetadata {
|
|
227
|
+
export declare class EntityDbMetadata {
|
|
227
228
|
entity: Entity;
|
|
228
229
|
primaryKey: PrimitiveField;
|
|
229
230
|
primitives: PrimitiveField[];
|
|
@@ -265,16 +266,16 @@ declare class EntityDbMetadata {
|
|
|
265
266
|
get nonDeferredManyToManyFks(): Array<ManyToManyField>;
|
|
266
267
|
}
|
|
267
268
|
/** Finds the field name for o2o side of a o2o/m2o. */
|
|
268
|
-
declare function oneToOneName(config: Config, refEntity: Entity, keyEntity: Entity, r: M2ORelation | O2MRelation): string;
|
|
269
|
-
declare function referenceName(config: Config, entity: Entity, r: M2ORelation | O2MRelation): string;
|
|
270
|
-
declare function manyToManyName(column: Column): string;
|
|
269
|
+
export declare function oneToOneName(config: Config, refEntity: Entity, keyEntity: Entity, r: M2ORelation | O2MRelation): string;
|
|
270
|
+
export declare function referenceName(config: Config, entity: Entity, r: M2ORelation | O2MRelation): string;
|
|
271
|
+
export declare function manyToManyName(column: Column): string;
|
|
271
272
|
/** Returns the collection name to use on `entity` when referring to `otherEntity`s. */
|
|
272
|
-
declare function collectionName(config: Config, singleEntity: Entity, collectionEntity: Entity, r: M2ORelation | O2MRelation | M2MRelation): {
|
|
273
|
+
export declare function collectionName(config: Config, singleEntity: Entity, collectionEntity: Entity, r: M2ORelation | O2MRelation | M2MRelation): {
|
|
273
274
|
fieldName: string;
|
|
274
275
|
singularName: string;
|
|
275
276
|
};
|
|
276
|
-
declare function failIfOverlappingFieldNames(entity: EntityDbMetadata): void;
|
|
277
|
-
declare function makeEntity(entityName: string): Entity;
|
|
277
|
+
export declare function failIfOverlappingFieldNames(entity: EntityDbMetadata): void;
|
|
278
|
+
export declare function makeEntity(entityName: string): Entity;
|
|
278
279
|
/**
|
|
279
280
|
* Collapses the per-relation `otherEntity` copies down to the one primary `Entity` per name.
|
|
280
281
|
*
|
|
@@ -284,18 +285,25 @@ declare function makeEntity(entityName: string): Entity;
|
|
|
284
285
|
*
|
|
285
286
|
* Must run after inheritance, since STI/CTI specialization both adds and re-points `otherEntity`s.
|
|
286
287
|
*/
|
|
287
|
-
declare function canonicalizeOtherEntities(db: DbMetadata): void;
|
|
288
|
+
export declare function canonicalizeOtherEntities(db: DbMetadata): void;
|
|
288
289
|
/**
|
|
289
290
|
* Rewrites codegen'd type names that collide with another exported type name.
|
|
290
291
|
*
|
|
291
292
|
* `makeEntity` defaults each name to the conventional `${name}<Suffix>`, but if a separate entity or
|
|
292
293
|
* enum is literally named e.g. `AuthorScope` or `AuthorOrder`, our generated type of the same name
|
|
293
294
|
* would collide with it, so we fall back to `Author_Scope` / `Author_Order`.
|
|
295
|
+
* Polymorphic unions yield to these API names by appending `Poly` until the name is available.
|
|
294
296
|
*
|
|
295
297
|
* Relies on `canonicalizeOtherEntities` having run, so mutating each primary `meta.entity` also updates
|
|
296
298
|
* the `otherEntity` references that point at it (e.g. `Book.author: AuthorId` follows `Author`'s rename).
|
|
297
299
|
*/
|
|
298
|
-
declare function resolveNameConflicts(config: Config, db: DbMetadata): void;
|
|
299
|
-
|
|
300
|
-
|
|
300
|
+
export declare function resolveNameConflicts(config: Config, db: DbMetadata): void;
|
|
301
|
+
/**
|
|
302
|
+
* Assigns family-wide scalar-field ordinals for metadata and generated first-read guards.
|
|
303
|
+
*
|
|
304
|
+
* Inherited getters must use the same bits on every subtype, including fields that
|
|
305
|
+
* specialize an inherited field. Value storage remains the existing data bag.
|
|
306
|
+
*/
|
|
307
|
+
export declare function getFieldReadIndexes(meta: EntityDbMetadata): ReadonlyMap<string, number>;
|
|
308
|
+
export {};
|
|
301
309
|
//# sourceMappingURL=EntityDbMetadata.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityDbMetadata.d.mts","names":[],"sources":["../src/EntityDbMetadata.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"EntityDbMetadata.d.mts","names":[],"sources":["../src/EntityDbMetadata.ts"],"mappings":";;;;;iBAmDiB;EACf,UAAU;;EAEV,gBAAgB,eAAe;EAC/B,OAAO;EACP,SAAS;EACT;;EAEA;EACA;;;YAIU;EACV;;EAEA,MAAM;;EAEN,YAAY;;EAEZ,qBAAqB;;EAErB;;EAEA,UAAU;;EAEV,QAAQ;;EAER,WAAW;;EAEX,aAAa;EACb,UAAU;;EAKV;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;YAGU;;;;;;UAiCF;EACR;EACA;;YAGU,8GAQR;YAEQ,iBAAiB;EAC3B;EACA;;EAEA,aAAa;EACb,YAAY;EACZ;EACA;;EAEA;EAEA,WAAW,0BAA0B;EACrC,cAAc;EACd;EACA;EACA;EACA;EACA,aAAa;EACb,WAAW;EACX,aAAa;EACb;EACA;EACA;;YAGU,YAAY;EACtB;EACA;;EAEA,aAAa;EACb,YAAY;EACZ;EACA;EACA;EACA;EACA;EACA,UAAU;EACV,gBAAgB;EAChB,iBAAiB;EACjB,UAAU;EACV;EACA;EACA;;EAEA;;YAGU,cAAc;EACxB;EACA;;EAEA,aAAa;EACb;EACA;EACA;;EAEA;;EAEA;EACA,UAAU;EACV;EACA;EACA;;;YAIU,iBAAiB;EAC3B;EACA;;EAEA,aAAa;EACb;EACA;EACA;EACA;EACA;EACA,aAAa;EACb;EACA;EACA;EACA;EACA;EACA,UAAU;;;YAIA,iBAAiB;EAC3B;EACA;EACA,aAAa;EACb;EACA;EACA;EACA;EACA;IAAW;IAAe;;EAC1B;;;YAIU,gBAAgB;EAC1B;EACA,aAAa;EACb;EACA;EACA;;YAGU,kBAAkB;EAC5B;EACA;EACA;EACA;EACA,aAAa;EACb;EACA;EACA;EACA;EACA;EACA;;EAEA;;;YAIU,sBAAsB;EAChC;EACA;;EAEA;;EAEA;EACA;EACA,UAAU;EACV,gBAAgB;EAChB,iBAAiB;EACjB,UAAU;;EAEV;;;YAIU,mBAAmB;EAC7B;EACA;EACA;EACA;EACA,YAAY;;;YAIF;EACV;;EAEA,aAAa;EACb;EACA,aAAa;EACb;EACA;EACA;;YAGU;EACV;EACA;;;qBAIW;EACX,QAAQ;EACR,YAAY;EACZ,YAAY;EACZ,OAAO;EACP,SAAS;EACT,YAAY;EACZ,YAAY;EACZ,iBAAiB;EACjB,WAAW;EACX,aAAa;EACb,kBAAkB;EAClB,iBAAiB;EACjB,cAAc;EACd;EACA;EACA,WAAW;EACX,WAAW;EACX,WAAW;EACX;EACA,UAAU;EACV,UAAU;EACV;;EAEA;;EAEA;EACA;EACA;EACA;;EAEA;;EAEA,mBAAmB;;EAEnB,gBAAgB;EAEhB,YAAY,QAAQ,QAAQ,OAAO,OAAO,QAAO;MAqI7C;MAIA,kBAAkB,MAAM,iBAAiB;MAOzC,4BAA4B,MAAM;;;wBAucxB,aACd,QAAQ,QAER,WAAW,QAEX,WAAW,QACX,GAAG,cAAc;wBAgCH,cAAc,QAAQ,QAAQ,QAAQ,QAAQ,GAAG,cAAc;wBAmB/D,eAAe,QAAQ;;wBAUvB,eACd,QAAQ,QAER,cAAc,QAEd,kBAAkB,QAClB,GAAG,cAAc,cAAc;EAC5B;EAAmB;;wBA4BR,4BAA4B,QAAQ;wBAwBpC,WAAW,qBAAqB;;;;;;;;;;wBA6BhC,0BAA0B,IAAI;;;;;;;;;;;;wBAiC9B,qBAAqB,QAAQ,QAAQ,IAAI;;;;;;;wBA4IzC,oBAAoB,MAAM,mBAAmB"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { EnumType, M2ORelation } from "./pgMetadata.js";
|
|
2
|
-
import { fail, isEnumTable, isJoinTable, isSubClassTable, joinTableHasId, mapSimpleDbTypeToTypescriptType, parseOrder, tableToEntityName } from "./utils.js";
|
|
3
1
|
import { fieldTypeConfig, getTimestampConfig, isFieldHasDefault, isFieldIgnored, isGetterField, isLargeCollection, isLazyField, isProtected, isReactiveField, isReactiveManyToMany, isReactiveReference, ormMaintainedFields, serdeConfig, softDeletesConfig, superstructConfig, zodSchemaConfig } from "./config.js";
|
|
4
|
-
import { Zod } from "./symbols.js";
|
|
5
2
|
import "./loadMetadata.js";
|
|
3
|
+
import { EnumType, M2ORelation } from "./pgMetadata.js";
|
|
4
|
+
import { Zod } from "./symbols.js";
|
|
5
|
+
import { fail, isEnumTable, isJoinTable, isSubClassTable, joinTableHasId, mapSimpleDbTypeToTypescriptType, parseOrder, tableToEntityName } from "./utils.js";
|
|
6
6
|
import { camelCase, pascalCase, snakeCase } from "change-case";
|
|
7
7
|
import { groupBy } from "joist-utils";
|
|
8
8
|
import pluralize from "pluralize";
|
|
9
9
|
import { Import, code, imp } from "ts-poet";
|
|
10
|
-
|
|
10
|
+
// src/EntityDbMetadata.ts
|
|
11
11
|
const { plural, singular } = pluralize;
|
|
12
12
|
/** Adapts PostgreSQL catalog metadata into our specific ORM types. */
|
|
13
13
|
var EntityDbMetadata = class {
|
|
@@ -120,7 +120,7 @@ function inferUniqueConstraints(meta, table) {
|
|
|
120
120
|
/** Returns the queryable field name for a unique constraint column. */
|
|
121
121
|
function fieldNameForColumn(meta, columnName) {
|
|
122
122
|
const primitive = meta.primitives.find((field) => field.columnName === columnName);
|
|
123
|
-
if (primitive && !primitive.derived && !primitive.
|
|
123
|
+
if (primitive && !primitive.derived && !primitive.customSerde) return primitive.fieldName;
|
|
124
124
|
const enumField = meta.enums.find((field) => field.columnName === columnName);
|
|
125
125
|
if (enumField && !enumField.derived && !enumField.isArray) return enumField.fieldName;
|
|
126
126
|
const pgEnum = meta.pgEnums.find((field) => field.columnName === columnName);
|
|
@@ -251,7 +251,8 @@ function newEnumField(config, entity, r, enums) {
|
|
|
251
251
|
ignore,
|
|
252
252
|
enumRows: enums[r.targetTable.name].rows,
|
|
253
253
|
isArray: false,
|
|
254
|
-
hasConfigDefault
|
|
254
|
+
hasConfigDefault,
|
|
255
|
+
hasTransitions: false
|
|
255
256
|
};
|
|
256
257
|
}
|
|
257
258
|
function newEnumArrayField(config, entity, column, enums) {
|
|
@@ -284,7 +285,8 @@ function newEnumArrayField(config, entity, column, enums) {
|
|
|
284
285
|
ignore,
|
|
285
286
|
enumRows: enums[enumTable].rows,
|
|
286
287
|
isArray: true,
|
|
287
|
-
hasConfigDefault
|
|
288
|
+
hasConfigDefault,
|
|
289
|
+
hasTransitions: false
|
|
288
290
|
};
|
|
289
291
|
}
|
|
290
292
|
function newPgEnumField(config, entity, column) {
|
|
@@ -570,6 +572,7 @@ function canonicalizeOtherEntities(db) {
|
|
|
570
572
|
* `makeEntity` defaults each name to the conventional `${name}<Suffix>`, but if a separate entity or
|
|
571
573
|
* enum is literally named e.g. `AuthorScope` or `AuthorOrder`, our generated type of the same name
|
|
572
574
|
* would collide with it, so we fall back to `Author_Scope` / `Author_Order`.
|
|
575
|
+
* Polymorphic unions yield to these API names by appending `Poly` until the name is available.
|
|
573
576
|
*
|
|
574
577
|
* Relies on `canonicalizeOtherEntities` having run, so mutating each primary `meta.entity` also updates
|
|
575
578
|
* the `otherEntity` references that point at it (e.g. `Book.author: AuthorId` follows `Author`'s rename).
|
|
@@ -582,6 +585,21 @@ function resolveNameConflicts(config, db) {
|
|
|
582
585
|
}
|
|
583
586
|
for (const pgEnum of Object.values(db.pgEnums)) reserved.add(pgEnum.name);
|
|
584
587
|
for (const meta of db.entities) if (hasNameConflict(meta.name, reserved)) applyEntityNames(meta.entity, reserved);
|
|
588
|
+
for (const meta of db.entities) {
|
|
589
|
+
const keys = Object.keys(entitySymbolNames(meta.name));
|
|
590
|
+
for (const key of keys) reserved.add(meta.entity[key]);
|
|
591
|
+
reserved.add(`${meta.name}Codegen`).add(`${meta.name}Columns`);
|
|
592
|
+
}
|
|
593
|
+
const polymorphics = db.entities.flatMap((meta) => meta.polymorphics);
|
|
594
|
+
const unionNames = new Set(polymorphics.map((poly) => poly.fieldType));
|
|
595
|
+
for (const poly of polymorphics) {
|
|
596
|
+
if (reserved.has(poly.fieldType)) {
|
|
597
|
+
let name = `${poly.fieldType}Poly`;
|
|
598
|
+
while (reserved.has(name) || unionNames.has(name)) name += "Poly";
|
|
599
|
+
poly.fieldType = name;
|
|
600
|
+
}
|
|
601
|
+
reserved.add(poly.fieldType);
|
|
602
|
+
}
|
|
585
603
|
}
|
|
586
604
|
/** Computes the codegen'd type names for an entity, underscoring any that `reserved` already contains. */
|
|
587
605
|
function entitySymbolNames(name, reserved) {
|
|
@@ -655,7 +673,30 @@ function userFieldTypeType(s) {
|
|
|
655
673
|
function serdeType(s) {
|
|
656
674
|
return Import.from(s);
|
|
657
675
|
}
|
|
658
|
-
|
|
659
|
-
|
|
676
|
+
/**
|
|
677
|
+
* Assigns family-wide scalar-field ordinals for metadata and generated first-read guards.
|
|
678
|
+
*
|
|
679
|
+
* Inherited getters must use the same bits on every subtype, including fields that
|
|
680
|
+
* specialize an inherited field. Value storage remains the existing data bag.
|
|
681
|
+
*/
|
|
682
|
+
function getFieldReadIndexes(meta) {
|
|
683
|
+
let root = meta;
|
|
684
|
+
while (root.baseType) root = root.baseType;
|
|
685
|
+
const pending = [root];
|
|
686
|
+
const names = /* @__PURE__ */ new Set(["id"]);
|
|
687
|
+
while (pending.length > 0) {
|
|
688
|
+
const current = pending.pop();
|
|
689
|
+
for (const field of [
|
|
690
|
+
...current.primitives,
|
|
691
|
+
...current.enums,
|
|
692
|
+
...current.pgEnums,
|
|
693
|
+
...current.manyToOnes,
|
|
694
|
+
...current.polymorphics
|
|
695
|
+
]) names.add(field.fieldName);
|
|
696
|
+
pending.push(...current.subTypes);
|
|
697
|
+
}
|
|
698
|
+
return new Map([...names].sort().map((name, index) => [name, index]));
|
|
699
|
+
}
|
|
700
|
+
export { EntityDbMetadata, canonicalizeOtherEntities, collectionName, failIfOverlappingFieldNames, getFieldReadIndexes, makeEntity, manyToManyName, oneToOneName, referenceName, resolveNameConflicts };
|
|
660
701
|
|
|
661
702
|
//# sourceMappingURL=EntityDbMetadata.js.map
|