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
package/build/generate.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { merge, tableToEntityName } from "./utils.js";
|
|
2
|
-
import { generateMetadataDocsFile } from "./docs/generate-metadata-docs.js";
|
|
3
1
|
import { loadEntityDocs, syncDocs } from "./docs/index.js";
|
|
2
|
+
import { generateMetadataDocsFile } from "./docs/generate-metadata-docs.js";
|
|
4
3
|
import { findAllEntityScopes } from "./findEntityScopes.js";
|
|
5
4
|
import { generateEntitiesFile } from "./generateEntitiesFile.js";
|
|
6
|
-
import { Entity, JoistEntityManager, configureMetadata, setRuntimeConfig } from "./symbols.js";
|
|
7
5
|
import { generateEntityCodegenFile, getIdType } from "./generateEntityCodegenFile.js";
|
|
8
6
|
import { generateEntityFile } from "./generateEntityFile.js";
|
|
9
7
|
import { generateEntityTestFile } from "./generateEntityTestFile.js";
|
|
@@ -12,10 +10,12 @@ import { generateFactoriesFiles } from "./generateFactoriesFiles.js";
|
|
|
12
10
|
import { generateColumnDeclarations, generateMetadataFile } from "./generateMetadataFile.js";
|
|
13
11
|
import { generatePgEnumFile } from "./generatePgEnumFile.js";
|
|
14
12
|
import "./index.js";
|
|
13
|
+
import { Entity, JoistEntityManager, configureMetadata, setRuntimeConfig } from "./symbols.js";
|
|
14
|
+
import { merge, tableToEntityName } from "./utils.js";
|
|
15
15
|
import { createRequire } from "node:module";
|
|
16
16
|
import { code, def, imp } from "ts-poet";
|
|
17
17
|
import { readdir } from "fs/promises";
|
|
18
|
-
|
|
18
|
+
// src/generate.ts
|
|
19
19
|
const runtimeRequire = createRequire(import.meta.url);
|
|
20
20
|
/** Generates our `${Entity}` and `${Entity}Codegen` files based on the `db` schema. */
|
|
21
21
|
async function generateFiles(config, dbMeta) {
|
|
@@ -122,7 +122,6 @@ async function readExistingFiles(config) {
|
|
|
122
122
|
return [];
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
-
//#endregion
|
|
126
125
|
export { generateFiles };
|
|
127
126
|
|
|
128
127
|
//# sourceMappingURL=generate.js.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
require("./pgMetadata.cjs");
|
|
3
|
-
const require_utils = require("./utils.cjs");
|
|
4
2
|
require("./config.cjs");
|
|
5
|
-
require("./index.cjs");
|
|
6
3
|
require("./EntityDbMetadata.cjs");
|
|
4
|
+
require("./index.cjs");
|
|
5
|
+
require("./pgMetadata.cjs");
|
|
6
|
+
const require_utils = require("./utils.cjs");
|
|
7
7
|
let ts_poet = require("ts-poet");
|
|
8
|
-
|
|
8
|
+
// src/generateEntitiesFile.ts
|
|
9
9
|
function generateEntitiesFile(config, entities, enums, pgEnums) {
|
|
10
10
|
const baseClasses = entities.filter((e) => e.baseClassName === void 0);
|
|
11
11
|
const subClasses = entities.filter((e) => e.baseClassName !== void 0);
|
|
@@ -40,7 +40,6 @@ function generateEntitiesFile(config, entities, enums, pgEnums) {
|
|
|
40
40
|
export * from "./codegen/metadata${esmExt}";
|
|
41
41
|
`;
|
|
42
42
|
}
|
|
43
|
-
//#endregion
|
|
44
43
|
exports.generateEntitiesFile = generateEntitiesFile;
|
|
45
44
|
|
|
46
45
|
//# sourceMappingURL=generateEntitiesFile.cjs.map
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { Config } from "./config.cjs";
|
|
2
|
-
import {
|
|
2
|
+
import { EntityDbMetadata } from "./EntityDbMetadata.cjs";
|
|
3
3
|
import "./index.cjs";
|
|
4
4
|
import { PgEnumData } from "./loadMetadata.cjs";
|
|
5
|
-
import {
|
|
5
|
+
import { Table } from "./pgMetadata.cjs";
|
|
6
6
|
import { Code } from "ts-poet";
|
|
7
|
-
|
|
8
|
-
declare function generateEntitiesFile(config: Config, entities: EntityDbMetadata[], enums: Table[], pgEnums: PgEnumData[]): Code;
|
|
9
|
-
//#endregion
|
|
10
|
-
export { generateEntitiesFile };
|
|
7
|
+
export declare function generateEntitiesFile(config: Config, entities: EntityDbMetadata[], enums: Table[], pgEnums: PgEnumData[]): Code;
|
|
11
8
|
//# sourceMappingURL=generateEntitiesFile.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateEntitiesFile.d.cts","names":[],"sources":["../src/generateEntitiesFile.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"generateEntitiesFile.d.cts","names":[],"sources":["../src/generateEntitiesFile.ts"],"mappings":";;;;;;wBAQgB,qBACd,QAAQ,QACR,UAAU,oBACV,OAAO,SACP,SAAS,eACR"}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { Config } from "./config.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { EntityDbMetadata } from "./EntityDbMetadata.mjs";
|
|
3
3
|
import "./index.mjs";
|
|
4
4
|
import { PgEnumData } from "./loadMetadata.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { Table } from "./pgMetadata.mjs";
|
|
6
6
|
import { Code } from "ts-poet";
|
|
7
|
-
|
|
8
|
-
declare function generateEntitiesFile(config: Config, entities: EntityDbMetadata[], enums: Table[], pgEnums: PgEnumData[]): Code;
|
|
9
|
-
//#endregion
|
|
10
|
-
export { generateEntitiesFile };
|
|
7
|
+
export declare function generateEntitiesFile(config: Config, entities: EntityDbMetadata[], enums: Table[], pgEnums: PgEnumData[]): Code;
|
|
11
8
|
//# sourceMappingURL=generateEntitiesFile.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateEntitiesFile.d.mts","names":[],"sources":["../src/generateEntitiesFile.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"generateEntitiesFile.d.mts","names":[],"sources":["../src/generateEntitiesFile.ts"],"mappings":";;;;;;wBAQgB,qBACd,QAAQ,QACR,UAAU,oBACV,OAAO,SACP,SAAS,eACR"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import "./pgMetadata.js";
|
|
2
|
-
import { tableToEntityName } from "./utils.js";
|
|
3
1
|
import "./config.js";
|
|
4
|
-
import "./index.js";
|
|
5
2
|
import "./EntityDbMetadata.js";
|
|
3
|
+
import "./index.js";
|
|
4
|
+
import "./pgMetadata.js";
|
|
5
|
+
import { tableToEntityName } from "./utils.js";
|
|
6
6
|
import { code } from "ts-poet";
|
|
7
|
-
|
|
7
|
+
// src/generateEntitiesFile.ts
|
|
8
8
|
function generateEntitiesFile(config, entities, enums, pgEnums) {
|
|
9
9
|
const baseClasses = entities.filter((e) => e.baseClassName === void 0);
|
|
10
10
|
const subClasses = entities.filter((e) => e.baseClassName !== void 0);
|
|
@@ -39,7 +39,6 @@ function generateEntitiesFile(config, entities, enums, pgEnums) {
|
|
|
39
39
|
export * from "./codegen/metadata${esmExt}";
|
|
40
40
|
`;
|
|
41
41
|
}
|
|
42
|
-
//#endregion
|
|
43
42
|
export { generateEntitiesFile };
|
|
44
43
|
|
|
45
44
|
//# sourceMappingURL=generateEntitiesFile.js.map
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
3
|
-
const require_utils = require("./utils.cjs");
|
|
4
|
-
const require_inheritance = require("./inheritance.cjs");
|
|
5
3
|
require("./config.cjs");
|
|
6
|
-
const require_docs_parsing = require("./docs/parsing.cjs");
|
|
7
4
|
require("./docs/index.cjs");
|
|
5
|
+
const require_EntityDbMetadata = require("./EntityDbMetadata.cjs");
|
|
6
|
+
const require_docs_parsing = require("./docs/parsing.cjs");
|
|
8
7
|
require("./findEntityScopes.cjs");
|
|
8
|
+
const require_inheritance = require("./inheritance.cjs");
|
|
9
9
|
const require_keywords = require("./keywords.cjs");
|
|
10
10
|
const require_symbols = require("./symbols.cjs");
|
|
11
11
|
const require_tsdoc = require("./tsdoc.cjs");
|
|
12
|
-
require("./
|
|
12
|
+
const require_utils = require("./utils.cjs");
|
|
13
13
|
let change_case = require("change-case");
|
|
14
14
|
let pluralize = require("pluralize");
|
|
15
15
|
pluralize = require_runtime.__toESM(pluralize, 1);
|
|
16
16
|
let ts_poet = require("ts-poet");
|
|
17
|
-
|
|
17
|
+
// src/generateEntityCodegenFile.ts
|
|
18
18
|
const { plural } = pluralize.default;
|
|
19
19
|
/** Creates the base class with the boilerplate annotations. */
|
|
20
20
|
function generateEntityCodegenFile(config, dbMeta, meta, scopeMembers = [], docs) {
|
|
@@ -23,17 +23,21 @@ function generateEntityCodegenFile(config, dbMeta, meta, scopeMembers = [], docs
|
|
|
23
23
|
const entityName = entity.name;
|
|
24
24
|
const fieldDocs = docs?.fields ?? {};
|
|
25
25
|
const varName = require_keywords.keywords.includes(tagName) ? require_utils.uncapitalize(entityName) : tagName;
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
primitives
|
|
29
|
-
primitives.push(...
|
|
26
|
+
const readIndexes = require_EntityDbMetadata.getFieldReadIndexes(meta);
|
|
27
|
+
const extraReadWords = meta.baseClassName ? [] : Array.from({ length: Math.ceil(readIndexes.size / 32) - 1 }, (_, word) => ts_poet.code`declare protected __readFields${word + 1}: number;`);
|
|
28
|
+
const primitives = createPrimitives(meta, entity, fieldDocs, readIndexes);
|
|
29
|
+
primitives.push(...createRegularEnums(meta, entity, fieldDocs, readIndexes));
|
|
30
|
+
primitives.push(...createArrayEnums(meta, fieldDocs, readIndexes));
|
|
31
|
+
primitives.push(...createPgEnums(meta, fieldDocs, readIndexes));
|
|
30
32
|
const relations = createRelations(config, meta, entity);
|
|
31
33
|
const configName = `${(0, change_case.camelCase)(entityName)}Config`;
|
|
32
34
|
const scopeFnName = `${(0, change_case.camelCase)(entityName)}Scope`;
|
|
33
35
|
const metadata = (0, ts_poet.imp)(`${(0, change_case.camelCase)(entityName)}Meta@./entities.ts`);
|
|
34
36
|
const contextType = config.contextType ? (0, ts_poet.imp)(`t:${config.contextType}`) : "{}";
|
|
35
37
|
const factoryMethod = (0, ts_poet.imp)(`new${entity.name}@./entities.ts`);
|
|
36
|
-
const idMaybeCode = config.idType === "tagged-string" ? ts_poet.code`return this.idTaggedMaybe;` : ts_poet.code`
|
|
38
|
+
const idMaybeCode = !config.idType || config.idType === "tagged-string" ? ts_poet.code`return this.idTaggedMaybe;` : ts_poet.code`
|
|
39
|
+
return (this.__data.idCache ??= ${require_symbols.toIdOf}(${metadata}, this.idTaggedMaybe)) as ${entity.idName} | undefined;
|
|
40
|
+
`;
|
|
37
41
|
const idType = getIdType(config);
|
|
38
42
|
const maybeSoftDeleteMethods = meta.deletedAt ? ts_poet.code`
|
|
39
43
|
get isSoftDeletedEntity(): boolean {
|
|
@@ -68,6 +72,7 @@ function generateEntityCodegenFile(config, dbMeta, meta, scopeMembers = [], docs
|
|
|
68
72
|
const maybeBaseFilter = baseEntity ? ts_poet.code`extends ${(0, ts_poet.imp)("t:" + baseEntity.entity.filterName + "@./entities.ts")}` : "";
|
|
69
73
|
const maybeBaseGqlFilter = baseEntity ? ts_poet.code`extends ${(0, ts_poet.imp)("t:" + baseEntity.entity.graphqlFilterName + "@./entities.ts")}` : "";
|
|
70
74
|
const maybeBaseOrder = baseEntity ? ts_poet.code`extends ${baseEntity.entity.orderType}` : "";
|
|
75
|
+
const maybeBaseFactoryExtras = baseEntity ? ts_poet.code`extends ${(0, ts_poet.imp)("t:" + baseEntity.entity.factoryExtrasName + "@./entities.ts")}` : "";
|
|
71
76
|
meta.abstract && ts_poet.code`
|
|
72
77
|
if (this.constructor === ${entity.type} && !(em as any).fakeInstance) {
|
|
73
78
|
throw new Error(\`${entity.type} must be instantiated via a subtype\`);
|
|
@@ -111,7 +116,7 @@ function generateEntityCodegenFile(config, dbMeta, meta, scopeMembers = [], docs
|
|
|
111
116
|
${generateOrderFields(meta)}
|
|
112
117
|
}
|
|
113
118
|
|
|
114
|
-
export interface ${entity.factoryExtrasName} {
|
|
119
|
+
export interface ${entity.factoryExtrasName} ${maybeBaseFactoryExtras} {
|
|
115
120
|
${generateFactoryExtrasType(meta)}
|
|
116
121
|
}
|
|
117
122
|
|
|
@@ -151,6 +156,8 @@ function generateEntityCodegenFile(config, dbMeta, meta, scopeMembers = [], docs
|
|
|
151
156
|
static readonly tagName = "${tagName}";
|
|
152
157
|
static readonly metadata: ${require_symbols.EntityMetadata}<${entity.type}>;
|
|
153
158
|
|
|
159
|
+
${extraReadWords}
|
|
160
|
+
|
|
154
161
|
declare readonly __type: {
|
|
155
162
|
${baseEntity ? `0: "${baseEntity.name}",` : ""}
|
|
156
163
|
${baseEntity ? 1 : 0}: "${entityName}",
|
|
@@ -179,7 +186,7 @@ function generateEntityCodegenFile(config, dbMeta, meta, scopeMembers = [], docs
|
|
|
179
186
|
}
|
|
180
187
|
|
|
181
188
|
get idTaggedMaybe(): ${require_symbols.TaggedId} | undefined {
|
|
182
|
-
return ${
|
|
189
|
+
return ${fieldReadExpression(readIndexes, "id")};
|
|
183
190
|
}
|
|
184
191
|
|
|
185
192
|
${primitives}
|
|
@@ -355,8 +362,9 @@ function generateFieldsType(meta, idType) {
|
|
|
355
362
|
return ts_poet.code`${fieldName}: { kind: "primitive"; type: ${fieldType}; unique: ${unique}; nullable: ${undefinedOrNever(notNull)}, derived: ${derived !== false}; };`;
|
|
356
363
|
});
|
|
357
364
|
const enums = meta.enums.map((field) => {
|
|
358
|
-
const { fieldName, enumType, notNull, isArray } = field;
|
|
365
|
+
const { fieldName, enumType, notNull, isArray, hasTransitions } = field;
|
|
359
366
|
if (isArray) return ts_poet.code`${fieldName}: { kind: "enum"; type: ${enumType}[]; nullable: never; };`;
|
|
367
|
+
else if (hasTransitions) return ts_poet.code`${fieldName}: { kind: "enum"; type: ${enumType}; nullable: ${undefinedOrNever(notNull)}; accessors: keyof typeof ${enumType}; };`;
|
|
360
368
|
else return ts_poet.code`${fieldName}: { kind: "enum"; type: ${enumType}; nullable: ${undefinedOrNever(notNull)}; };`;
|
|
361
369
|
});
|
|
362
370
|
const pgEnums = meta.pgEnums.map((field) => {
|
|
@@ -599,14 +607,14 @@ function generateFactoryExtrasType(meta) {
|
|
|
599
607
|
const { fieldName, fieldType, notNull } = field;
|
|
600
608
|
return ts_poet.code`${withName(fieldName)}?: ${fieldType}${maybeUnionNull(notNull)};`;
|
|
601
609
|
});
|
|
602
|
-
const enums = meta.enums.filter((f) => f.derived === "async").map((field) => {
|
|
610
|
+
const enums = meta.enums.filter((f) => f.derived === "async" || f.hasTransitions).map((field) => {
|
|
603
611
|
const { fieldName, enumType, notNull, isArray } = field;
|
|
604
612
|
if (isArray) return ts_poet.code`${withName(fieldName)}?: ${enumType}[];`;
|
|
605
613
|
else return ts_poet.code`${withName(fieldName)}?: ${enumType}${maybeUnionNull(notNull)};`;
|
|
606
614
|
});
|
|
607
615
|
return [...primitives, ...enums];
|
|
608
616
|
}
|
|
609
|
-
function createPrimitives(meta, entity, fieldDocs) {
|
|
617
|
+
function createPrimitives(meta, entity, fieldDocs, readIndexes) {
|
|
610
618
|
return meta.primitives.map((p) => {
|
|
611
619
|
const { fieldName, fieldType, notNull } = p;
|
|
612
620
|
const maybeOptional = notNull ? "" : " | undefined";
|
|
@@ -620,12 +628,12 @@ function createPrimitives(meta, entity, fieldDocs) {
|
|
|
620
628
|
`;
|
|
621
629
|
else if (p.zodSchema) getter = ts_poet.code`
|
|
622
630
|
get ${fieldName}(): ${require_symbols.Zod}.output<typeof ${p.zodSchema}>${maybeOptional} {
|
|
623
|
-
return ${
|
|
631
|
+
return ${fieldReadExpression(readIndexes, fieldName)};
|
|
624
632
|
}
|
|
625
633
|
`;
|
|
626
634
|
else getter = ts_poet.code`
|
|
627
635
|
get ${fieldName}(): ${fieldType}${maybeOptional} {
|
|
628
|
-
return ${
|
|
636
|
+
return ${fieldReadExpression(readIndexes, fieldName)};
|
|
629
637
|
}
|
|
630
638
|
`;
|
|
631
639
|
let setter;
|
|
@@ -661,7 +669,7 @@ function createPrimitives(meta, entity, fieldDocs) {
|
|
|
661
669
|
return ts_poet.code`${fieldDocBlock(fieldDocs, fieldName, entity.name)}${getter} ${setter}`;
|
|
662
670
|
});
|
|
663
671
|
}
|
|
664
|
-
function createRegularEnums(meta, entity, fieldDocs) {
|
|
672
|
+
function createRegularEnums(meta, entity, fieldDocs, readIndexes) {
|
|
665
673
|
return meta.enums.filter((e) => !e.isArray).flatMap((e) => {
|
|
666
674
|
const { fieldName, enumType, enumDetailType, enumDetailsType, notNull, enumRows, derived } = e;
|
|
667
675
|
const maybeOptional = notNull ? "" : " | undefined";
|
|
@@ -675,7 +683,7 @@ function createRegularEnums(meta, entity, fieldDocs) {
|
|
|
675
683
|
`;
|
|
676
684
|
else getter = ts_poet.code`
|
|
677
685
|
get ${fieldName}(): ${enumType}${maybeOptional} {
|
|
678
|
-
return ${
|
|
686
|
+
return ${fieldReadExpression(readIndexes, fieldName)};
|
|
679
687
|
}
|
|
680
688
|
|
|
681
689
|
get ${fieldName}Details(): ${enumDetailsType}${maybeOptional} {
|
|
@@ -693,7 +701,7 @@ function createRegularEnums(meta, entity, fieldDocs) {
|
|
|
693
701
|
const shouldPrefixAccessors = meta.enums.filter((other) => other !== e).some((other) => other.enumRows.some((r) => codes.has(r.code)));
|
|
694
702
|
const accessors = enumRows.map((row) => ts_poet.code`
|
|
695
703
|
get is${shouldPrefixAccessors ? (0, change_case.pascalCase)(fieldName) : ""}${(0, change_case.pascalCase)(row.code)}(): boolean {
|
|
696
|
-
return ${require_symbols.getField}(this, "${fieldName}") === ${enumType}.${(0, change_case.pascalCase)(row.code)};
|
|
704
|
+
return ${derived ? ts_poet.code`${require_symbols.getField}(this, "${fieldName}")` : ts_poet.code`this.${fieldName}`} === ${enumType}.${(0, change_case.pascalCase)(row.code)};
|
|
697
705
|
}
|
|
698
706
|
`);
|
|
699
707
|
return [
|
|
@@ -703,12 +711,12 @@ function createRegularEnums(meta, entity, fieldDocs) {
|
|
|
703
711
|
];
|
|
704
712
|
});
|
|
705
713
|
}
|
|
706
|
-
function createArrayEnums(meta, fieldDocs) {
|
|
714
|
+
function createArrayEnums(meta, fieldDocs, readIndexes) {
|
|
707
715
|
return meta.enums.filter((e) => e.isArray).flatMap((e) => {
|
|
708
716
|
const { fieldName, enumType, enumDetailType, enumDetailsType, enumRows } = e;
|
|
709
717
|
const getter = ts_poet.code`
|
|
710
718
|
get ${fieldName}(): ${enumType}[] {
|
|
711
|
-
return ${
|
|
719
|
+
return (${fieldReadExpression(readIndexes, fieldName)}) || [];
|
|
712
720
|
}
|
|
713
721
|
|
|
714
722
|
get ${fieldName}Details(): ${enumDetailsType}[] {
|
|
@@ -734,13 +742,13 @@ function createArrayEnums(meta, fieldDocs) {
|
|
|
734
742
|
];
|
|
735
743
|
});
|
|
736
744
|
}
|
|
737
|
-
function createPgEnums(meta, fieldDocs) {
|
|
745
|
+
function createPgEnums(meta, fieldDocs, readIndexes) {
|
|
738
746
|
return meta.pgEnums.flatMap((e) => {
|
|
739
747
|
const { fieldName, enumType, enumValues, notNull } = e;
|
|
740
748
|
const maybeOptional = notNull ? "" : " | undefined";
|
|
741
749
|
const getter = ts_poet.code`
|
|
742
750
|
get ${fieldName}(): ${enumType}${maybeOptional} {
|
|
743
|
-
return ${
|
|
751
|
+
return ${fieldReadExpression(readIndexes, fieldName)};
|
|
744
752
|
}
|
|
745
753
|
`;
|
|
746
754
|
const setter = ts_poet.code`
|
|
@@ -1004,7 +1012,13 @@ function getIdType(config) {
|
|
|
1004
1012
|
default: return require_utils.assertNever(config.idType);
|
|
1005
1013
|
}
|
|
1006
1014
|
}
|
|
1007
|
-
|
|
1015
|
+
/** Emits a conditional warm read directly from data, falling back to getField for the first read. */
|
|
1016
|
+
function fieldReadExpression(indexes, fieldName) {
|
|
1017
|
+
const index = indexes.get(fieldName) ?? require_utils.fail(`Missing first-read index for ${fieldName}`);
|
|
1018
|
+
const bit = 1 << (index & 31);
|
|
1019
|
+
const word = index < 32 ? "__readFields" : `__readFields${index >>> 5}`;
|
|
1020
|
+
return ts_poet.code`(this.${word} & ${bit}) !== 0 ? this.__data.data.${fieldName} : ${require_symbols.getField}(this, "${fieldName}")`;
|
|
1021
|
+
}
|
|
1008
1022
|
exports.generateEntityCodegenFile = generateEntityCodegenFile;
|
|
1009
1023
|
exports.getIdType = getIdType;
|
|
1010
1024
|
|