joist-codegen 2.3.0-next.12 → 2.3.0-next.120
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 +672 -0
- package/build/EntityDbMetadata.cjs.map +1 -0
- package/build/EntityDbMetadata.d.cts +301 -0
- package/build/EntityDbMetadata.d.cts.map +1 -0
- package/build/EntityDbMetadata.d.mts +301 -0
- package/build/EntityDbMetadata.d.mts.map +1 -0
- package/build/EntityDbMetadata.js +550 -664
- package/build/EntityDbMetadata.js.map +1 -1
- package/build/_virtual/_rolldown/runtime.cjs +23 -0
- package/build/_virtual/_rolldown/runtime.js +5 -0
- package/build/assignTags.cjs +45 -0
- package/build/assignTags.cjs.map +1 -0
- package/build/{assignTags.d.ts → assignTags.d.cts} +8 -4
- package/build/assignTags.d.cts.map +1 -0
- package/build/assignTags.d.mts +16 -0
- package/build/assignTags.d.mts.map +1 -0
- package/build/assignTags.js +37 -59
- package/build/assignTags.js.map +1 -1
- package/build/codemods/Codemod.cjs +2 -0
- package/build/codemods/Codemod.d.cts +17 -0
- package/build/codemods/Codemod.d.cts.map +1 -0
- package/build/codemods/Codemod.d.mts +17 -0
- package/build/codemods/Codemod.d.mts.map +1 -0
- package/build/codemods/Codemod.js +2 -3
- package/build/codemods/JscodeshiftMod.cjs +42 -0
- package/build/codemods/JscodeshiftMod.cjs.map +1 -0
- package/build/codemods/JscodeshiftMod.d.cts +14 -0
- package/build/codemods/JscodeshiftMod.d.cts.map +1 -0
- package/build/codemods/JscodeshiftMod.d.mts +14 -0
- package/build/codemods/JscodeshiftMod.d.mts.map +1 -0
- package/build/codemods/JscodeshiftMod.js +33 -33
- package/build/codemods/JscodeshiftMod.js.map +1 -1
- package/build/codemods/codemod_0001-rename_has_async_property.cjs +30 -0
- package/build/codemods/codemod_0001-rename_has_async_property.cjs.map +1 -0
- package/build/codemods/codemod_0001-rename_has_async_property.d.cts +9 -0
- package/build/codemods/codemod_0001-rename_has_async_property.d.cts.map +1 -0
- package/build/codemods/codemod_0001-rename_has_async_property.d.mts +9 -0
- package/build/codemods/codemod_0001-rename_has_async_property.d.mts.map +1 -0
- package/build/codemods/codemod_0001-rename_has_async_property.js +21 -25
- package/build/codemods/codemod_0001-rename_has_async_property.js.map +1 -1
- package/build/codemods/codemod_0002-rename_async_query_fields.cjs +50 -0
- package/build/codemods/codemod_0002-rename_async_query_fields.cjs.map +1 -0
- package/build/codemods/codemod_0002-rename_async_query_fields.d.cts +9 -0
- package/build/codemods/codemod_0002-rename_async_query_fields.d.cts.map +1 -0
- package/build/codemods/codemod_0002-rename_async_query_fields.d.mts +9 -0
- package/build/codemods/codemod_0002-rename_async_query_fields.d.mts.map +1 -0
- package/build/codemods/codemod_0002-rename_async_query_fields.js +38 -52
- package/build/codemods/codemod_0002-rename_async_query_fields.js.map +1 -1
- package/build/codemods/codemod_0003-rename_find_paginated.cjs +25 -0
- package/build/codemods/codemod_0003-rename_find_paginated.cjs.map +1 -0
- package/build/codemods/codemod_0003-rename_find_paginated.d.cts +9 -0
- package/build/codemods/codemod_0003-rename_find_paginated.d.cts.map +1 -0
- package/build/codemods/codemod_0003-rename_find_paginated.d.mts +9 -0
- package/build/codemods/codemod_0003-rename_find_paginated.d.mts.map +1 -0
- package/build/codemods/codemod_0003-rename_find_paginated.js +17 -26
- package/build/codemods/codemod_0003-rename_find_paginated.js.map +1 -1
- package/build/codemods/index.cjs +49 -0
- package/build/codemods/index.cjs.map +1 -0
- package/build/codemods/index.d.cts +12 -0
- package/build/codemods/index.d.cts.map +1 -0
- package/build/codemods/index.d.mts +12 -0
- package/build/codemods/index.d.mts.map +1 -0
- package/build/codemods/index.js +34 -42
- package/build/codemods/index.js.map +1 -1
- package/build/config.cjs +377 -0
- package/build/config.cjs.map +1 -0
- package/build/config.d.cts +181 -0
- package/build/config.d.cts.map +1 -0
- package/build/config.d.mts +181 -0
- package/build/config.d.mts.map +1 -0
- package/build/config.js +306 -356
- package/build/config.js.map +1 -1
- package/build/docs/cache.cjs +62 -0
- package/build/docs/cache.cjs.map +1 -0
- package/build/docs/cache.d.cts +17 -0
- package/build/docs/cache.d.cts.map +1 -0
- package/build/docs/cache.d.mts +17 -0
- package/build/docs/cache.d.mts.map +1 -0
- package/build/docs/cache.js +52 -53
- package/build/docs/cache.js.map +1 -1
- package/build/docs/generate-metadata-docs.cjs +32 -0
- package/build/docs/generate-metadata-docs.cjs.map +1 -0
- package/build/docs/generate-metadata-docs.d.cts +9 -0
- package/build/docs/generate-metadata-docs.d.cts.map +1 -0
- package/build/docs/generate-metadata-docs.d.mts +9 -0
- package/build/docs/generate-metadata-docs.d.mts.map +1 -0
- package/build/docs/generate-metadata-docs.js +19 -24
- package/build/docs/generate-metadata-docs.js.map +1 -1
- package/build/docs/index.cjs +90 -0
- package/build/docs/index.cjs.map +1 -0
- package/build/docs/index.d.cts +16 -0
- package/build/docs/index.d.cts.map +1 -0
- package/build/docs/index.d.mts +16 -0
- package/build/docs/index.d.mts.map +1 -0
- package/build/docs/index.js +75 -80
- package/build/docs/index.js.map +1 -1
- package/build/docs/markdown.cjs +181 -0
- package/build/docs/markdown.cjs.map +1 -0
- package/build/docs/{markdown.d.ts → markdown.d.cts} +14 -12
- package/build/docs/markdown.d.cts.map +1 -0
- package/build/docs/markdown.d.mts +32 -0
- package/build/docs/markdown.d.mts.map +1 -0
- package/build/docs/markdown.js +152 -220
- package/build/docs/markdown.js.map +1 -1
- package/build/docs/parsing.cjs +117 -0
- package/build/docs/parsing.cjs.map +1 -0
- package/build/docs/parsing.d.cts +48 -0
- package/build/docs/parsing.d.cts.map +1 -0
- package/build/docs/parsing.d.mts +48 -0
- package/build/docs/parsing.d.mts.map +1 -0
- package/build/docs/parsing.js +89 -88
- package/build/docs/parsing.js.map +1 -1
- package/build/findEntityScopes.cjs +119 -0
- package/build/findEntityScopes.cjs.map +1 -0
- package/build/findEntityScopes.d.cts +14 -0
- package/build/findEntityScopes.d.cts.map +1 -0
- package/build/findEntityScopes.d.mts +14 -0
- package/build/findEntityScopes.d.mts.map +1 -0
- package/build/findEntityScopes.js +83 -111
- package/build/findEntityScopes.js.map +1 -1
- package/build/foreignKeyOrdering.cjs +52 -0
- package/build/foreignKeyOrdering.cjs.map +1 -0
- package/build/foreignKeyOrdering.d.cts +8 -0
- package/build/foreignKeyOrdering.d.cts.map +1 -0
- package/build/foreignKeyOrdering.d.mts +8 -0
- package/build/foreignKeyOrdering.d.mts.map +1 -0
- package/build/foreignKeyOrdering.js +46 -55
- package/build/foreignKeyOrdering.js.map +1 -1
- package/build/generate.cjs +128 -0
- package/build/generate.cjs.map +1 -0
- package/build/generate.d.cts +17 -0
- package/build/generate.d.cts.map +1 -0
- package/build/generate.d.mts +17 -0
- package/build/generate.d.mts.map +1 -0
- package/build/generate.js +111 -124
- package/build/generate.js.map +1 -1
- package/build/generateEntitiesFile.cjs +46 -0
- package/build/generateEntitiesFile.cjs.map +1 -0
- package/build/generateEntitiesFile.d.cts +11 -0
- package/build/generateEntitiesFile.d.cts.map +1 -0
- package/build/generateEntitiesFile.d.mts +11 -0
- package/build/generateEntitiesFile.d.mts.map +1 -0
- package/build/generateEntitiesFile.js +28 -25
- package/build/generateEntitiesFile.js.map +1 -1
- package/build/generateEntityCodegenFile.cjs +1011 -0
- package/build/generateEntityCodegenFile.cjs.map +1 -0
- package/build/generateEntityCodegenFile.d.cts +16 -0
- package/build/generateEntityCodegenFile.d.cts.map +1 -0
- package/build/generateEntityCodegenFile.d.mts +16 -0
- package/build/generateEntityCodegenFile.d.mts.map +1 -0
- package/build/generateEntityCodegenFile.js +794 -827
- package/build/generateEntityCodegenFile.js.map +1 -1
- package/build/generateEntityFile.cjs +23 -0
- package/build/generateEntityFile.cjs.map +1 -0
- package/build/generateEntityFile.d.cts +9 -0
- package/build/generateEntityFile.d.cts.map +1 -0
- package/build/generateEntityFile.d.mts +9 -0
- package/build/generateEntityFile.d.mts.map +1 -0
- package/build/generateEntityFile.js +11 -8
- package/build/generateEntityFile.js.map +1 -1
- package/build/generateEntityTestFile.cjs +25 -0
- package/build/generateEntityTestFile.cjs.map +1 -0
- package/build/generateEntityTestFile.d.cts +9 -0
- package/build/generateEntityTestFile.d.cts.map +1 -0
- package/build/generateEntityTestFile.d.mts +9 -0
- package/build/generateEntityTestFile.d.mts.map +1 -0
- package/build/generateEntityTestFile.js +10 -7
- package/build/generateEntityTestFile.js.map +1 -1
- package/build/generateEnumFile.cjs +73 -0
- package/build/generateEnumFile.cjs.map +1 -0
- package/build/generateEnumFile.d.cts +9 -0
- package/build/generateEnumFile.d.cts.map +1 -0
- package/build/generateEnumFile.d.mts +9 -0
- package/build/generateEnumFile.d.mts.map +1 -0
- package/build/generateEnumFile.js +33 -43
- package/build/generateEnumFile.js.map +1 -1
- package/build/generateFactoriesFiles.cjs +28 -0
- package/build/generateFactoriesFiles.cjs.map +1 -0
- package/build/generateFactoriesFiles.d.cts +7 -0
- package/build/generateFactoriesFiles.d.cts.map +1 -0
- package/build/generateFactoriesFiles.d.mts +7 -0
- package/build/generateFactoriesFiles.d.mts.map +1 -0
- package/build/generateFactoriesFiles.js +21 -16
- package/build/generateFactoriesFiles.js.map +1 -1
- package/build/generateFlushFunction.cjs +61 -0
- package/build/generateFlushFunction.cjs.map +1 -0
- package/build/{generateFlushFunction.d.ts → generateFlushFunction.d.cts} +8 -5
- package/build/generateFlushFunction.d.cts.map +1 -0
- package/build/generateFlushFunction.d.mts +23 -0
- package/build/generateFlushFunction.d.mts.map +1 -0
- package/build/generateFlushFunction.js +32 -78
- package/build/generateFlushFunction.js.map +1 -1
- package/build/generateMetadataFile.cjs +315 -0
- package/build/generateMetadataFile.cjs.map +1 -0
- package/build/generateMetadataFile.d.cts +10 -0
- package/build/generateMetadataFile.d.cts.map +1 -0
- package/build/generateMetadataFile.d.mts +10 -0
- package/build/generateMetadataFile.d.mts.map +1 -0
- package/build/generateMetadataFile.js +151 -157
- package/build/generateMetadataFile.js.map +1 -1
- package/build/generatePgEnumFile.cjs +21 -0
- package/build/generatePgEnumFile.cjs.map +1 -0
- package/build/generatePgEnumFile.d.cts +9 -0
- package/build/generatePgEnumFile.d.cts.map +1 -0
- package/build/generatePgEnumFile.d.mts +9 -0
- package/build/generatePgEnumFile.d.mts.map +1 -0
- package/build/generatePgEnumFile.js +12 -9
- package/build/generatePgEnumFile.js.map +1 -1
- package/build/index.cjs +135 -0
- package/build/index.cjs.map +1 -0
- package/build/index.d.cts +12 -0
- package/build/index.d.cts.map +1 -0
- package/build/index.d.mts +12 -0
- package/build/index.d.mts.map +1 -0
- package/build/index.js +109 -127
- package/build/index.js.map +1 -1
- package/build/inheritance.cjs +258 -0
- package/build/inheritance.cjs.map +1 -0
- package/build/inheritance.d.cts +13 -0
- package/build/inheritance.d.cts.map +1 -0
- package/build/inheritance.d.mts +13 -0
- package/build/inheritance.d.mts.map +1 -0
- package/build/inheritance.js +238 -247
- package/build/inheritance.js.map +1 -1
- package/build/installSkills.cjs +68 -0
- package/build/installSkills.cjs.map +1 -0
- package/build/installSkills.d.cts +16 -0
- package/build/installSkills.d.cts.map +1 -0
- package/build/installSkills.d.mts +16 -0
- package/build/installSkills.d.mts.map +1 -0
- package/build/installSkills.js +67 -0
- package/build/installSkills.js.map +1 -0
- package/build/keywords.cjs +7 -0
- package/build/keywords.cjs.map +1 -0
- package/build/keywords.d.cts +5 -0
- package/build/keywords.d.cts.map +1 -0
- package/build/keywords.d.mts +5 -0
- package/build/keywords.d.mts.map +1 -0
- package/build/keywords.js +5 -4
- package/build/keywords.js.map +1 -1
- package/build/loadMetadata.cjs +39 -0
- package/build/loadMetadata.cjs.map +1 -0
- package/build/loadMetadata.d.cts +31 -0
- package/build/loadMetadata.d.cts.map +1 -0
- package/build/loadMetadata.d.mts +31 -0
- package/build/loadMetadata.d.mts.map +1 -0
- package/build/loadMetadata.js +32 -39
- package/build/loadMetadata.js.map +1 -1
- package/build/logger.cjs +28 -0
- package/build/logger.cjs.map +1 -0
- package/build/logger.d.cts +13 -0
- package/build/logger.d.cts.map +1 -0
- package/build/logger.d.mts +13 -0
- package/build/logger.d.mts.map +1 -0
- package/build/logger.js +17 -16
- package/build/logger.js.map +1 -1
- package/build/pgMetadata.cjs +332 -0
- package/build/pgMetadata.cjs.map +1 -0
- package/build/pgMetadata.d.cts +128 -0
- package/build/pgMetadata.d.cts.map +1 -0
- package/build/pgMetadata.d.mts +128 -0
- package/build/pgMetadata.d.mts.map +1 -0
- package/build/pgMetadata.js +320 -0
- package/build/pgMetadata.js.map +1 -0
- package/build/scanEntityFiles.cjs +46 -0
- package/build/scanEntityFiles.cjs.map +1 -0
- package/build/scanEntityFiles.d.cts +8 -0
- package/build/scanEntityFiles.d.cts.map +1 -0
- package/build/scanEntityFiles.d.mts +8 -0
- package/build/scanEntityFiles.d.mts.map +1 -0
- package/build/scanEntityFiles.js +37 -42
- package/build/scanEntityFiles.js.map +1 -1
- package/build/sortForeignKeys.cjs +99 -0
- package/build/sortForeignKeys.cjs.map +1 -0
- package/build/{sortForeignKeys.d.ts → sortForeignKeys.d.cts} +8 -5
- package/build/sortForeignKeys.d.cts.map +1 -0
- package/build/sortForeignKeys.d.mts +35 -0
- package/build/sortForeignKeys.d.mts.map +1 -0
- package/build/sortForeignKeys.js +88 -117
- package/build/sortForeignKeys.js.map +1 -1
- package/build/symbols.cjs +238 -0
- package/build/symbols.cjs.map +1 -0
- package/build/symbols.d.cts +120 -0
- package/build/symbols.d.cts.map +1 -0
- package/build/symbols.d.mts +120 -0
- package/build/symbols.d.mts.map +1 -0
- package/build/symbols.js +121 -113
- package/build/symbols.js.map +1 -1
- package/build/tsdoc.cjs +22 -0
- package/build/tsdoc.cjs.map +1 -0
- package/build/tsdoc.d.cts +15 -0
- package/build/tsdoc.d.cts.map +1 -0
- package/build/tsdoc.d.mts +15 -0
- package/build/tsdoc.d.mts.map +1 -0
- package/build/tsdoc.js +18 -15
- package/build/tsdoc.js.map +1 -1
- package/build/utils.cjs +175 -0
- package/build/utils.cjs.map +1 -0
- package/build/utils.d.cts +36 -0
- package/build/utils.d.cts.map +1 -0
- package/build/utils.d.mts +36 -0
- package/build/utils.d.mts.map +1 -0
- package/build/utils.js +113 -166
- package/build/utils.js.map +1 -1
- package/build/write-json-schema.cjs +23 -0
- package/build/write-json-schema.cjs.map +1 -0
- package/build/write-json-schema.d.cts +1 -0
- package/build/write-json-schema.d.mts +1 -0
- package/build/write-json-schema.js +19 -13
- package/build/write-json-schema.js.map +1 -1
- package/package.json +47 -18
- package/skills/joist-docs/SKILL.md +142 -0
- package/skills/joist-em-basics/SKILL.md +114 -0
- package/skills/joist-partial-updates/SKILL.md +352 -0
- package/skills/joist-reactive-hints/SKILL.md +150 -0
- package/skills/joist-test-factories/SKILL.md +397 -0
- package/skills/joist-upsert/SKILL.md +95 -0
- package/build/EntityDbMetadata.d.ts +0 -271
- package/build/EntityDbMetadata.d.ts.map +0 -1
- package/build/EntityDbMetadata.test.d.ts +0 -2
- package/build/EntityDbMetadata.test.d.ts.map +0 -1
- package/build/EntityDbMetadata.test.js +0 -211
- package/build/EntityDbMetadata.test.js.map +0 -1
- package/build/assignTags.d.ts.map +0 -1
- package/build/codemods/Codemod.d.ts +0 -14
- package/build/codemods/Codemod.d.ts.map +0 -1
- package/build/codemods/Codemod.js.map +0 -1
- package/build/codemods/JscodeshiftMod.d.ts +0 -11
- package/build/codemods/JscodeshiftMod.d.ts.map +0 -1
- package/build/codemods/__tests__/codemod_0001-rename_has_async_property.test.d.ts +0 -2
- package/build/codemods/__tests__/codemod_0001-rename_has_async_property.test.d.ts.map +0 -1
- package/build/codemods/__tests__/codemod_0001-rename_has_async_property.test.js +0 -9
- package/build/codemods/__tests__/codemod_0001-rename_has_async_property.test.js.map +0 -1
- package/build/codemods/__tests__/codemod_0002-rename_async_query_fields.test.d.ts +0 -2
- package/build/codemods/__tests__/codemod_0002-rename_async_query_fields.test.d.ts.map +0 -1
- package/build/codemods/__tests__/codemod_0002-rename_async_query_fields.test.js +0 -9
- package/build/codemods/__tests__/codemod_0002-rename_async_query_fields.test.js.map +0 -1
- package/build/codemods/__tests__/codemod_0003-rename_find_paginated.test.d.ts +0 -2
- package/build/codemods/__tests__/codemod_0003-rename_find_paginated.test.d.ts.map +0 -1
- package/build/codemods/__tests__/codemod_0003-rename_find_paginated.test.js +0 -9
- package/build/codemods/__tests__/codemod_0003-rename_find_paginated.test.js.map +0 -1
- package/build/codemods/codemod_0001-rename_has_async_property.d.ts +0 -7
- package/build/codemods/codemod_0001-rename_has_async_property.d.ts.map +0 -1
- package/build/codemods/codemod_0002-rename_async_query_fields.d.ts +0 -7
- package/build/codemods/codemod_0002-rename_async_query_fields.d.ts.map +0 -1
- package/build/codemods/codemod_0003-rename_find_paginated.d.ts +0 -7
- package/build/codemods/codemod_0003-rename_find_paginated.d.ts.map +0 -1
- package/build/codemods/index.d.ts +0 -9
- package/build/codemods/index.d.ts.map +0 -1
- package/build/codemods/index.test.d.ts +0 -2
- package/build/codemods/index.test.d.ts.map +0 -1
- package/build/codemods/index.test.js +0 -24
- package/build/codemods/index.test.js.map +0 -1
- package/build/config.d.ts +0 -172
- package/build/config.d.ts.map +0 -1
- package/build/config.test.d.ts +0 -2
- package/build/config.test.d.ts.map +0 -1
- package/build/config.test.js +0 -78
- package/build/config.test.js.map +0 -1
- package/build/docs/cache.d.ts +0 -14
- package/build/docs/cache.d.ts.map +0 -1
- package/build/docs/cache.test.d.ts +0 -2
- package/build/docs/cache.test.d.ts.map +0 -1
- package/build/docs/cache.test.js +0 -47
- package/build/docs/cache.test.js.map +0 -1
- package/build/docs/generate-metadata-docs.d.ts +0 -6
- package/build/docs/generate-metadata-docs.d.ts.map +0 -1
- package/build/docs/index.d.ts +0 -9
- package/build/docs/index.d.ts.map +0 -1
- package/build/docs/index.test.d.ts +0 -2
- package/build/docs/index.test.d.ts.map +0 -1
- package/build/docs/index.test.js +0 -100
- package/build/docs/index.test.js.map +0 -1
- package/build/docs/markdown.d.ts.map +0 -1
- package/build/docs/markdown.test.d.ts +0 -2
- package/build/docs/markdown.test.d.ts.map +0 -1
- package/build/docs/markdown.test.js +0 -280
- package/build/docs/markdown.test.js.map +0 -1
- package/build/docs/parsing.d.ts +0 -42
- package/build/docs/parsing.d.ts.map +0 -1
- package/build/docs/parsing.test.d.ts +0 -2
- package/build/docs/parsing.test.d.ts.map +0 -1
- package/build/docs/parsing.test.js +0 -190
- package/build/docs/parsing.test.js.map +0 -1
- package/build/findEntityScopes.d.ts +0 -11
- package/build/findEntityScopes.d.ts.map +0 -1
- package/build/foreignKeyOrdering.d.ts +0 -3
- package/build/foreignKeyOrdering.d.ts.map +0 -1
- package/build/generate.d.ts +0 -12
- package/build/generate.d.ts.map +0 -1
- package/build/generateEntitiesFile.d.ts +0 -7
- package/build/generateEntitiesFile.d.ts.map +0 -1
- package/build/generateEntityCodegenFile.d.ts +0 -11
- package/build/generateEntityCodegenFile.d.ts.map +0 -1
- package/build/generateEntityFile.d.ts +0 -6
- package/build/generateEntityFile.d.ts.map +0 -1
- package/build/generateEntityTestFile.d.ts +0 -6
- package/build/generateEntityTestFile.d.ts.map +0 -1
- package/build/generateEnumFile.d.ts +0 -5
- package/build/generateEnumFile.d.ts.map +0 -1
- package/build/generateFactoriesFiles.d.ts +0 -4
- package/build/generateFactoriesFiles.d.ts.map +0 -1
- package/build/generateFlushFunction.d.ts.map +0 -1
- package/build/generateMetadataFile.d.ts +0 -5
- package/build/generateMetadataFile.d.ts.map +0 -1
- package/build/generatePgEnumFile.d.ts +0 -5
- package/build/generatePgEnumFile.d.ts.map +0 -1
- package/build/index.d.ts +0 -11
- package/build/index.d.ts.map +0 -1
- package/build/inheritance.d.ts +0 -10
- package/build/inheritance.d.ts.map +0 -1
- package/build/keywords.d.ts +0 -2
- package/build/keywords.d.ts.map +0 -1
- package/build/loadMetadata.d.ts +0 -26
- package/build/loadMetadata.d.ts.map +0 -1
- package/build/logger.d.ts +0 -10
- package/build/logger.d.ts.map +0 -1
- package/build/scanEntityFiles.d.ts +0 -5
- package/build/scanEntityFiles.d.ts.map +0 -1
- package/build/sortForeignKeys.d.ts.map +0 -1
- package/build/symbols.d.ts +0 -108
- package/build/symbols.d.ts.map +0 -1
- package/build/tsdoc.d.ts +0 -12
- package/build/tsdoc.d.ts.map +0 -1
- package/build/utils.d.ts +0 -31
- package/build/utils.d.ts.map +0 -1
- package/build/write-json-schema.d.ts +0 -2
- package/build/write-json-schema.d.ts.map +0 -1
|
@@ -1,775 +1,661 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
.filter((f) => !(0, config_1.isReactiveReference)(config, f.otherEntity, f.otherFieldName))
|
|
99
|
-
.filter((f) => !f.ignore);
|
|
100
|
-
this.oneToManys = allOneToManys.filter((f) => !f.isLargeCollection);
|
|
101
|
-
this.largeOneToManys = allOneToManys.filter((f) => f.isLargeCollection);
|
|
102
|
-
this.oneToOnes = table.o2mRelations
|
|
103
|
-
// ManyToMany join tables also show up as OneToMany tables in pg-structure
|
|
104
|
-
.filter((r) => !(0, utils_1.isJoinTable)(config, r.targetTable))
|
|
105
|
-
.filter((r) => !isMultiColumnForeignKey(r))
|
|
106
|
-
.filter((r) => !isBaseClassForeignKey(r))
|
|
107
|
-
.filter((r) => isOneToOneRelation(r))
|
|
108
|
-
.map((r) => newOneToOne(config, this.entity, r))
|
|
109
|
-
.filter((f) => !f.ignore);
|
|
110
|
-
// We split these into regular/large
|
|
111
|
-
const allManyToManys = table.m2mRelations
|
|
112
|
-
// pg-structure is really loose on what it considers a m2m relationship, i.e. any entity
|
|
113
|
-
// that has a foreign key to us, and a foreign key to something else, is automatically
|
|
114
|
-
// considered as a join table/m2m between "us" and "something else". Filter these out
|
|
115
|
-
// by looking for only true join tables, i.e. tables with only id, fk1, and fk2.
|
|
116
|
-
.filter((r) => (0, utils_1.isJoinTable)(config, r.joinTable))
|
|
117
|
-
.filter((r) => !isMultiColumnForeignKey(r))
|
|
118
|
-
// Join tables whose "other" side is an enum table become EnumCollections instead.
|
|
119
|
-
.filter((r) => !(0, utils_1.isEnumTable)(config, r.targetTable))
|
|
120
|
-
.map((r) => newManyToManyField(config, this.entity, r))
|
|
121
|
-
.filter((f) => !f.ignore);
|
|
122
|
-
this.manyToManys = allManyToManys.filter((f) => !f.isLargeCollection);
|
|
123
|
-
this.largeManyToManys = allManyToManys.filter((f) => f.isLargeCollection);
|
|
124
|
-
// A join table between us and an enum table, i.e. `Publisher.logoColors`.
|
|
125
|
-
this.manyToManyEnums = table.m2mRelations
|
|
126
|
-
.filter((r) => (0, utils_1.isJoinTable)(config, r.joinTable))
|
|
127
|
-
.filter((r) => !isMultiColumnForeignKey(r))
|
|
128
|
-
.filter((r) => (0, utils_1.isEnumTable)(config, r.targetTable))
|
|
129
|
-
.map((r) => newManyToManyEnumField(config, this.entity, r, enums))
|
|
130
|
-
.filter((f) => !f.ignore);
|
|
131
|
-
this.polymorphics = polymorphicRelations(config, table).map((rc) => newPolymorphicField(config, table, this.entity, rc));
|
|
132
|
-
this.tableName = table.name;
|
|
133
|
-
this.tagName = config.entities[this.entity.name]?.tag;
|
|
134
|
-
this.abstract = config.entities[this.entity.name]?.abstract || false;
|
|
135
|
-
const { createdAtConf, updatedAtConf, deletedAtConf } = (0, config_1.getTimestampConfig)(config);
|
|
136
|
-
this.createdAt = this.primitives.find((f) => createdAtConf.names.includes(f.columnName));
|
|
137
|
-
this.updatedAt = this.primitives.find((f) => updatedAtConf.names.includes(f.columnName));
|
|
138
|
-
this.deletedAt = this.primitives.find((f) => deletedAtConf.names.includes(f.columnName));
|
|
139
|
-
this.uniqueConstraints = inferUniqueConstraints(this, table);
|
|
140
|
-
}
|
|
141
|
-
get name() {
|
|
142
|
-
return this.entity.name;
|
|
143
|
-
}
|
|
144
|
-
get nonDeferredFks() {
|
|
145
|
-
return [
|
|
146
|
-
...this.manyToOnes.filter((r) => !r.isDeferredAndDeferrable),
|
|
147
|
-
...this.polymorphics.flatMap((p) => p.components).filter((c) => !c.isDeferredAndDeferrable),
|
|
148
|
-
];
|
|
149
|
-
}
|
|
150
|
-
get nonDeferredManyToManyFks() {
|
|
151
|
-
return this.manyToManys.filter((r) => !r.isDeferredAndDeferrable);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
exports.EntityDbMetadata = EntityDbMetadata;
|
|
1
|
+
import { EnumType, M2ORelation } from "./pgMetadata.js";
|
|
2
|
+
import { fail, isEnumTable, isJoinTable, isSubClassTable, joinTableHasId, mapSimpleDbTypeToTypescriptType, parseOrder, tableToEntityName } from "./utils.js";
|
|
3
|
+
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
|
+
import "./loadMetadata.js";
|
|
6
|
+
import { camelCase, pascalCase, snakeCase } from "change-case";
|
|
7
|
+
import { groupBy } from "joist-utils";
|
|
8
|
+
import pluralize from "pluralize";
|
|
9
|
+
import { Import, code, imp } from "ts-poet";
|
|
10
|
+
//#region src/EntityDbMetadata.ts
|
|
11
|
+
const { plural, singular } = pluralize;
|
|
12
|
+
/** Adapts PostgreSQL catalog metadata into our specific ORM types. */
|
|
13
|
+
var EntityDbMetadata = class {
|
|
14
|
+
entity;
|
|
15
|
+
primaryKey;
|
|
16
|
+
primitives;
|
|
17
|
+
enums;
|
|
18
|
+
pgEnums;
|
|
19
|
+
manyToOnes;
|
|
20
|
+
oneToManys;
|
|
21
|
+
largeOneToManys;
|
|
22
|
+
oneToOnes;
|
|
23
|
+
manyToManys;
|
|
24
|
+
largeManyToManys;
|
|
25
|
+
manyToManyEnums;
|
|
26
|
+
polymorphics;
|
|
27
|
+
tableName;
|
|
28
|
+
tagName;
|
|
29
|
+
createdAt;
|
|
30
|
+
updatedAt;
|
|
31
|
+
deletedAt;
|
|
32
|
+
baseClassName;
|
|
33
|
+
baseType;
|
|
34
|
+
subTypes = [];
|
|
35
|
+
inheritanceType;
|
|
36
|
+
/** This will only be set on the base meta. */
|
|
37
|
+
stiDiscriminatorField;
|
|
38
|
+
/** This will only be set on the sub metas. */
|
|
39
|
+
stiDiscriminatorValue;
|
|
40
|
+
abstract;
|
|
41
|
+
nonDeferredFkOrder = -1;
|
|
42
|
+
uniqueConstraints;
|
|
43
|
+
/** Gates mutation targets, not reads; false when required columns or array storage have no supported mutation mapping. */
|
|
44
|
+
supportsEmExecute;
|
|
45
|
+
/** Original table fields, captured before inheritance partitions or specializes them. */
|
|
46
|
+
physicalMetadata;
|
|
47
|
+
/** Physical columns ignored by entity fields, retained for direct SQL reads and writes. */
|
|
48
|
+
ignoredColumns;
|
|
49
|
+
constructor(config, table, enums = {}) {
|
|
50
|
+
this.entity = makeEntity(tableToEntityName(config, table));
|
|
51
|
+
if (isSubClassTable(table)) {
|
|
52
|
+
this.baseClassName = tableToEntityName(config, table.columns.get("id").foreignKeys[0].referencedTable);
|
|
53
|
+
this.inheritanceType = "cti";
|
|
54
|
+
}
|
|
55
|
+
this.primaryKey = table.columns.filter((c) => c.isPrimaryKey).map((column) => newPrimitive(config, this.entity, column, table))[0] || fail(`No primary key found for ${table.name}`);
|
|
56
|
+
this.primitives = table.columns.filter((c) => !c.isPrimaryKey && !c.isForeignKey).filter((c) => !isEnumArray(c) && !isPgEnum(c)).map((column) => newPrimitive(config, this.entity, column, table)).filter((f) => !f.ignore);
|
|
57
|
+
this.enums = [...table.m2oRelations.filter((r) => isEnumTable(config, r.targetTable)).map((r) => newEnumField(config, this.entity, r, enums)).filter((f) => !f.ignore), ...table.columns.filter((c) => isEnumArray(c)).map((column) => newEnumArrayField(config, this.entity, column, enums)).filter((f) => !f.ignore)];
|
|
58
|
+
this.pgEnums = table.columns.filter((c) => isPgEnum(c)).map((column) => newPgEnumField(config, this.entity, column)).filter((f) => !f.ignore);
|
|
59
|
+
this.manyToOnes = table.m2oRelations.filter((r) => !isEnumTable(config, r.targetTable)).filter((r) => !isMultiColumnForeignKey(r)).filter((r) => !isComponentOfPolymorphicRelation(config, r)).filter((r) => !isBaseClassForeignKey(r)).map((r) => newManyToOneField(config, this.entity, r)).filter((f) => !f.ignore);
|
|
60
|
+
const allOneToManys = table.o2mRelations.filter((r) => !isJoinTable(config, r.targetTable)).filter((r) => !isMultiColumnForeignKey(r)).filter((r) => !isOneToOneRelation(r)).map((r) => newOneToMany(config, this.entity, r)).filter((f) => !isReactiveReference(config, f.otherEntity, f.otherFieldName)).filter((f) => !f.ignore);
|
|
61
|
+
this.oneToManys = allOneToManys.filter((f) => !f.isLargeCollection);
|
|
62
|
+
this.largeOneToManys = allOneToManys.filter((f) => f.isLargeCollection);
|
|
63
|
+
this.oneToOnes = table.o2mRelations.filter((r) => !isJoinTable(config, r.targetTable)).filter((r) => !isMultiColumnForeignKey(r)).filter((r) => !isBaseClassForeignKey(r)).filter((r) => isOneToOneRelation(r)).map((r) => newOneToOne(config, this.entity, r)).filter((f) => !f.ignore);
|
|
64
|
+
const allManyToManys = table.m2mRelations.filter((r) => isJoinTable(config, r.joinTable)).filter((r) => !isMultiColumnForeignKey(r)).filter((r) => !isEnumTable(config, r.targetTable)).map((r) => newManyToManyField(config, this.entity, r)).filter((f) => !f.ignore);
|
|
65
|
+
this.manyToManys = allManyToManys.filter((f) => !f.isLargeCollection);
|
|
66
|
+
this.largeManyToManys = allManyToManys.filter((f) => f.isLargeCollection);
|
|
67
|
+
this.manyToManyEnums = table.m2mRelations.filter((r) => isJoinTable(config, r.joinTable)).filter((r) => !isMultiColumnForeignKey(r)).filter((r) => isEnumTable(config, r.targetTable)).map((r) => newManyToManyEnumField(config, this.entity, r, enums)).filter((f) => !f.ignore);
|
|
68
|
+
this.polymorphics = polymorphicRelations(config, table).map((rc) => newPolymorphicField(config, table, this.entity, rc));
|
|
69
|
+
const modeledColumns = /* @__PURE__ */ new Set([
|
|
70
|
+
this.primaryKey.columnName,
|
|
71
|
+
...this.primitives.map((field) => field.columnName),
|
|
72
|
+
...this.enums.map((field) => field.columnName),
|
|
73
|
+
...this.pgEnums.map((field) => field.columnName),
|
|
74
|
+
...this.manyToOnes.map((field) => field.columnName),
|
|
75
|
+
...this.polymorphics.flatMap((field) => field.components.map((component) => component.columnName))
|
|
76
|
+
]);
|
|
77
|
+
this.ignoredColumns = table.columns.filter((column) => !modeledColumns.has(column.name)).map((column) => newPhysicalColumn(config, this.entity, column));
|
|
78
|
+
this.tableName = table.name;
|
|
79
|
+
this.tagName = config.entities[this.entity.name]?.tag;
|
|
80
|
+
this.abstract = config.entities[this.entity.name]?.abstract || false;
|
|
81
|
+
const { createdAtConf, updatedAtConf, deletedAtConf } = getTimestampConfig(config);
|
|
82
|
+
this.createdAt = this.primitives.find((f) => createdAtConf.names.includes(f.columnName));
|
|
83
|
+
this.updatedAt = this.primitives.find((f) => updatedAtConf.names.includes(f.columnName));
|
|
84
|
+
this.deletedAt = this.primitives.find((f) => deletedAtConf.names.includes(f.columnName));
|
|
85
|
+
this.uniqueConstraints = inferUniqueConstraints(this, table);
|
|
86
|
+
this.supportsEmExecute = table.primaryKey?.columns.length === 1 && this.primaryKey.columnName === "id" && table.columns.every((column) => column.arrayDimension <= 1 && !(isArray(column) && isPgEnum(column))) && ![...this.primitives, ...this.ignoredColumns].some((field) => field.isArray && !field.customSerde && (field.columnType === "jsonb" || !config.temporal && (field.columnType === "date" || field.columnType === "timestamp with time zone" || field.columnType === "timestamp without time zone")));
|
|
87
|
+
}
|
|
88
|
+
get name() {
|
|
89
|
+
return this.entity.name;
|
|
90
|
+
}
|
|
91
|
+
get nonDeferredFks() {
|
|
92
|
+
return [...this.manyToOnes.filter((r) => !r.isDeferredAndDeferrable), ...this.polymorphics.flatMap((p) => p.components).filter((c) => !c.isDeferredAndDeferrable)];
|
|
93
|
+
}
|
|
94
|
+
get nonDeferredManyToManyFks() {
|
|
95
|
+
return this.manyToManys.filter((r) => !r.isDeferredAndDeferrable);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
155
98
|
function isMultiColumnForeignKey(r) {
|
|
156
|
-
|
|
99
|
+
return r.foreignKey.columns.length > 1;
|
|
157
100
|
}
|
|
158
101
|
function isBaseClassForeignKey(r) {
|
|
159
|
-
|
|
102
|
+
return r.foreignKey.columns.length === 1 && r.foreignKey.columns[0].name === "id";
|
|
160
103
|
}
|
|
161
104
|
function isOneToOneRelation(r) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
// r.foreignKey.index is the index on _us_ (i.e. our Book primary key), so look up indexes in the target table
|
|
165
|
-
const indexes = r.targetTable.columns.find((c) => c.name == otherColumn.name)?.uniqueIndexes || [];
|
|
166
|
-
return indexes.find(isOneToOneIndex) !== undefined;
|
|
105
|
+
const otherColumn = r.foreignKey.columns[0];
|
|
106
|
+
return (r.targetTable.columns.find((c) => c.name == otherColumn.name)?.uniqueIndexes || []).find(isOneToOneIndex) !== void 0;
|
|
167
107
|
}
|
|
168
|
-
// If the unique index has only one column and is NOT a partial index, it's a one-to-one
|
|
169
108
|
function isOneToOneIndex(i) {
|
|
170
|
-
|
|
109
|
+
return i.columns.length === 1 && !i.isPartial;
|
|
171
110
|
}
|
|
172
111
|
/** Infers field names from unique constraints, i.e. `(author_id, title)` becomes `author, title`. */
|
|
173
112
|
function inferUniqueConstraints(meta, table) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
return [fields];
|
|
181
|
-
});
|
|
113
|
+
return table.uniqueConstraints.flatMap((constraint) => {
|
|
114
|
+
if (constraint.index.isPartial) return [];
|
|
115
|
+
const fields = Array.from(constraint.columns).map((column) => fieldNameForColumn(meta, column.name));
|
|
116
|
+
if (fields.some((field) => field === void 0)) return [];
|
|
117
|
+
return [fields];
|
|
118
|
+
});
|
|
182
119
|
}
|
|
183
120
|
/** Returns the queryable field name for a unique constraint column. */
|
|
184
121
|
function fieldNameForColumn(meta, columnName) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
return pgEnum.fieldName;
|
|
194
|
-
const manyToOne = meta.manyToOnes.find((field) => field.columnName === columnName);
|
|
195
|
-
if (manyToOne && !manyToOne.derived)
|
|
196
|
-
return manyToOne.fieldName;
|
|
197
|
-
return undefined;
|
|
122
|
+
const primitive = meta.primitives.find((field) => field.columnName === columnName);
|
|
123
|
+
if (primitive && !primitive.derived && !primitive.isArray && !primitive.customSerde) return primitive.fieldName;
|
|
124
|
+
const enumField = meta.enums.find((field) => field.columnName === columnName);
|
|
125
|
+
if (enumField && !enumField.derived && !enumField.isArray) return enumField.fieldName;
|
|
126
|
+
const pgEnum = meta.pgEnums.find((field) => field.columnName === columnName);
|
|
127
|
+
if (pgEnum) return pgEnum.fieldName;
|
|
128
|
+
const manyToOne = meta.manyToOnes.find((field) => field.columnName === columnName);
|
|
129
|
+
if (manyToOne && !manyToOne.derived) return manyToOne.fieldName;
|
|
198
130
|
}
|
|
199
131
|
function polymorphicRelations(config, table) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
132
|
+
const entity = config.entities[tableToEntityName(config, table)];
|
|
133
|
+
return Object.entries(entity?.relations ?? {}).filter(([, r]) => r.polymorphic).map(([fieldName, { polymorphic }]) => ({
|
|
134
|
+
fieldName,
|
|
135
|
+
notNull: polymorphic === "notNull"
|
|
136
|
+
}));
|
|
204
137
|
}
|
|
205
138
|
function polymorphicFieldName(config, r) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
return polymorphicRelations(config, table).find((pr) => name.startsWith(`${(0, change_case_1.snakeCase)(pr.fieldName)}_`))?.fieldName;
|
|
139
|
+
const { name } = r.foreignKey.columns[0];
|
|
140
|
+
return polymorphicRelations(config, r.type === "m2o" ? r.sourceTable : r.targetTable).find((pr) => name.startsWith(`${snakeCase(pr.fieldName)}_`))?.fieldName;
|
|
209
141
|
}
|
|
210
142
|
function isComponentOfPolymorphicRelation(config, r) {
|
|
211
|
-
|
|
143
|
+
return polymorphicFieldName(config, r) !== void 0;
|
|
212
144
|
}
|
|
213
145
|
function determineUserType(fieldType, superstruct, zodSchema, userFieldType) {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
return zodSchemaType(zodSchema);
|
|
219
|
-
}
|
|
220
|
-
if (userFieldType) {
|
|
221
|
-
return userFieldTypeType(userFieldType);
|
|
222
|
-
}
|
|
223
|
-
return fieldType;
|
|
146
|
+
if (fieldType === "Object" && superstruct) return superstructType(superstruct);
|
|
147
|
+
if (fieldType === "Object" && zodSchema) return zodSchemaType(zodSchema);
|
|
148
|
+
if (userFieldType) return userFieldTypeType(userFieldType);
|
|
149
|
+
return fieldType;
|
|
224
150
|
}
|
|
225
151
|
function newPrimitive(config, entity, column, table) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
152
|
+
const fieldName = primitiveFieldName(column.name);
|
|
153
|
+
const columnName = column.name;
|
|
154
|
+
const columnType = column.type.shortName || column.type.name;
|
|
155
|
+
const array = isArray(column);
|
|
156
|
+
const fieldType = mapType(config, table.name, columnName, columnType);
|
|
157
|
+
const customSerde = serdeConfig(config, entity, fieldName);
|
|
158
|
+
const superstruct = superstructConfig(config, entity, fieldName);
|
|
159
|
+
const zodSchema = zodSchemaConfig(config, entity, fieldName);
|
|
160
|
+
const maybeUserType = determineUserType(fieldType, superstruct, zodSchema, fieldTypeConfig(config, entity, fieldName));
|
|
161
|
+
const unique = column.uniqueIndexes.find(isOneToOneIndex) !== void 0;
|
|
162
|
+
const hasConfigDefault = isFieldHasDefault(config, entity, fieldName);
|
|
163
|
+
return {
|
|
164
|
+
kind: "primitive",
|
|
165
|
+
columnOwner: entity,
|
|
166
|
+
columnNotNull: column.notNull,
|
|
167
|
+
fieldName,
|
|
168
|
+
columnName,
|
|
169
|
+
columnType,
|
|
170
|
+
fieldType: array ? code`${maybeUserType}[]` : maybeUserType,
|
|
171
|
+
rawFieldType: fieldType,
|
|
172
|
+
notNull: column.notNull,
|
|
173
|
+
columnDefault: column.default,
|
|
174
|
+
columnGenerated: column.isGenerated,
|
|
175
|
+
derived: fieldDerived(config, entity, fieldName),
|
|
176
|
+
protected: isProtected(config, entity, fieldName),
|
|
177
|
+
unique,
|
|
178
|
+
ignore: isFieldIgnored(config, entity, fieldName, column.notNull, column.default !== null),
|
|
179
|
+
superstruct: fieldType === "Object" && superstruct ? Import.from(superstruct) : void 0,
|
|
180
|
+
zodSchema: fieldType === "Object" && zodSchema ? Import.from(zodSchema) : void 0,
|
|
181
|
+
customSerde: customSerde ? serdeType(customSerde) : void 0,
|
|
182
|
+
isArray: array,
|
|
183
|
+
hasConfigDefault,
|
|
184
|
+
lazy: isLazyField(config, entity, fieldName)
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
/** Keeps an ignored column's database type without applying entity-only field configuration. */
|
|
188
|
+
function newPhysicalColumn(config, entity, column) {
|
|
189
|
+
const columnType = column.type.shortName || column.type.name;
|
|
190
|
+
const rawFieldType = column.type instanceof EnumType ? "string" : mapSimpleDbTypeToTypescriptType(config, columnType);
|
|
191
|
+
const isArray = column.arrayDimension === 1;
|
|
192
|
+
return {
|
|
193
|
+
kind: "primitive",
|
|
194
|
+
columnOwner: entity,
|
|
195
|
+
columnNotNull: column.notNull,
|
|
196
|
+
fieldName: primitiveFieldName(column.name),
|
|
197
|
+
columnName: column.name,
|
|
198
|
+
columnType,
|
|
199
|
+
fieldType: isArray ? code`${rawFieldType}[]` : rawFieldType,
|
|
200
|
+
rawFieldType,
|
|
201
|
+
notNull: column.notNull,
|
|
202
|
+
columnDefault: column.default,
|
|
203
|
+
columnGenerated: column.isGenerated,
|
|
204
|
+
derived: false,
|
|
205
|
+
protected: false,
|
|
206
|
+
unique: false,
|
|
207
|
+
superstruct: void 0,
|
|
208
|
+
zodSchema: void 0,
|
|
209
|
+
customSerde: void 0,
|
|
210
|
+
isArray,
|
|
211
|
+
hasConfigDefault: false
|
|
212
|
+
};
|
|
257
213
|
}
|
|
258
214
|
function fieldDerived(config, entity, fieldName) {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
return "sync";
|
|
264
|
-
}
|
|
265
|
-
else if ((0, config_1.isReactiveField)(config, entity, fieldName)) {
|
|
266
|
-
return "async";
|
|
267
|
-
}
|
|
268
|
-
else {
|
|
269
|
-
return false;
|
|
270
|
-
}
|
|
215
|
+
if (ormMaintainedFields.includes(fieldName)) return "orm";
|
|
216
|
+
else if (isGetterField(config, entity, fieldName)) return "sync";
|
|
217
|
+
else if (isReactiveField(config, entity, fieldName)) return "async";
|
|
218
|
+
else return false;
|
|
271
219
|
}
|
|
272
220
|
function fkFieldDerived(config, entity, fieldName) {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}
|
|
276
|
-
else {
|
|
277
|
-
return false;
|
|
278
|
-
}
|
|
221
|
+
if (isReactiveReference(config, entity, fieldName)) return "async";
|
|
222
|
+
else return false;
|
|
279
223
|
}
|
|
280
224
|
function newEnumField(config, entity, r, enums) {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
225
|
+
const column = r.foreignKey.columns[0];
|
|
226
|
+
const columnName = column.name;
|
|
227
|
+
const columnType = column.type.shortName || column.type.name;
|
|
228
|
+
const fieldName = enumFieldName(column.name);
|
|
229
|
+
const enumName = tableToEntityName(config, r.targetTable);
|
|
230
|
+
const enumType = imp(`${enumName}@./entities.ts`);
|
|
231
|
+
const enumDetailType = imp(`${plural(enumName)}@./entities.ts`);
|
|
232
|
+
const enumDetailsType = imp(`${enumName}Details@./entities.ts`);
|
|
233
|
+
const notNull = column.notNull;
|
|
234
|
+
const ignore = isFieldIgnored(config, entity, fieldName, notNull, column.default !== null);
|
|
235
|
+
const hasConfigDefault = isFieldHasDefault(config, entity, fieldName);
|
|
236
|
+
return {
|
|
237
|
+
kind: "enum",
|
|
238
|
+
columnOwner: entity,
|
|
239
|
+
columnNotNull: column.notNull,
|
|
240
|
+
fieldName,
|
|
241
|
+
columnName,
|
|
242
|
+
columnType,
|
|
243
|
+
columnDefault: column.default,
|
|
244
|
+
columnGenerated: column.isGenerated,
|
|
245
|
+
derived: fieldDerived(config, entity, fieldName),
|
|
246
|
+
enumName,
|
|
247
|
+
enumType,
|
|
248
|
+
enumDetailType,
|
|
249
|
+
enumDetailsType,
|
|
250
|
+
notNull,
|
|
251
|
+
ignore,
|
|
252
|
+
enumRows: enums[r.targetTable.name].rows,
|
|
253
|
+
isArray: false,
|
|
254
|
+
hasConfigDefault
|
|
255
|
+
};
|
|
309
256
|
}
|
|
310
257
|
function newEnumArrayField(config, entity, column, enums) {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
258
|
+
const columnName = column.name;
|
|
259
|
+
const columnType = column.type.shortName || column.type.name;
|
|
260
|
+
const fieldName = enumFieldName(column.name);
|
|
261
|
+
const enumTable = column.comment.replace("enum=", "");
|
|
262
|
+
const enumName = (enums[enumTable] || fail(`Could not find enum ${enumTable}`)).name;
|
|
263
|
+
const enumType = imp(`${enumName}@./entities.ts`);
|
|
264
|
+
const enumDetailType = imp(`${plural(enumName)}@./entities.ts`);
|
|
265
|
+
const enumDetailsType = imp(`${enumName}Details@./entities.ts`);
|
|
266
|
+
const notNull = column.notNull;
|
|
267
|
+
const ignore = isFieldIgnored(config, entity, fieldName, notNull, column.default !== null);
|
|
268
|
+
const hasConfigDefault = isFieldHasDefault(config, entity, fieldName);
|
|
269
|
+
return {
|
|
270
|
+
kind: "enum",
|
|
271
|
+
columnOwner: entity,
|
|
272
|
+
columnNotNull: column.notNull,
|
|
273
|
+
fieldName,
|
|
274
|
+
columnName,
|
|
275
|
+
columnType,
|
|
276
|
+
columnDefault: column.default,
|
|
277
|
+
columnGenerated: column.isGenerated,
|
|
278
|
+
derived: fieldDerived(config, entity, fieldName),
|
|
279
|
+
enumName,
|
|
280
|
+
enumType,
|
|
281
|
+
enumDetailType,
|
|
282
|
+
enumDetailsType,
|
|
283
|
+
notNull,
|
|
284
|
+
ignore,
|
|
285
|
+
enumRows: enums[enumTable].rows,
|
|
286
|
+
isArray: true,
|
|
287
|
+
hasConfigDefault
|
|
288
|
+
};
|
|
340
289
|
}
|
|
341
290
|
function newPgEnumField(config, entity, column) {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
291
|
+
const fieldName = primitiveFieldName(column.name);
|
|
292
|
+
const columnName = column.name;
|
|
293
|
+
const enumName = pascalCase(column.type.name);
|
|
294
|
+
const enumType = imp(`${enumName}@./entities.ts`);
|
|
295
|
+
const hasConfigDefault = isFieldHasDefault(config, entity, fieldName);
|
|
296
|
+
return {
|
|
297
|
+
kind: "pg-enum",
|
|
298
|
+
columnOwner: entity,
|
|
299
|
+
columnNotNull: column.notNull,
|
|
300
|
+
fieldName,
|
|
301
|
+
columnName,
|
|
302
|
+
dbType: column.type.name,
|
|
303
|
+
enumType,
|
|
304
|
+
enumName,
|
|
305
|
+
enumValues: column.type.values,
|
|
306
|
+
notNull: column.notNull,
|
|
307
|
+
columnDefault: column.default,
|
|
308
|
+
columnGenerated: column.isGenerated,
|
|
309
|
+
ignore: isFieldIgnored(config, entity, fieldName, column.notNull, column.default !== null),
|
|
310
|
+
hasConfigDefault
|
|
311
|
+
};
|
|
360
312
|
}
|
|
361
313
|
function newManyToOneField(config, entity, r) {
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
314
|
+
const column = r.foreignKey.columns[0];
|
|
315
|
+
const columnName = column.name;
|
|
316
|
+
const dbType = r.foreignKey.columns[0].type.shortName;
|
|
317
|
+
const fieldName = referenceName(config, entity, r);
|
|
318
|
+
const otherEntity = makeEntity(tableToEntityName(config, r.targetTable));
|
|
319
|
+
const otherFieldName = column.uniqueIndexes.find(isOneToOneIndex) !== void 0 ? oneToOneName(config, otherEntity, entity, r) : collectionName(config, otherEntity, entity, r).fieldName;
|
|
320
|
+
const notNull = column.notNull;
|
|
321
|
+
const ignore = isFieldIgnored(config, entity, fieldName, notNull, column.default !== null);
|
|
322
|
+
const isDeferredAndDeferrable = r.foreignKey.isDeferred && r.foreignKey.isDeferrable;
|
|
323
|
+
const derived = fkFieldDerived(config, entity, fieldName);
|
|
324
|
+
const hasConfigDefault = isFieldHasDefault(config, entity, fieldName);
|
|
325
|
+
return {
|
|
326
|
+
kind: "m2o",
|
|
327
|
+
columnOwner: entity,
|
|
328
|
+
columnNotNull: column.notNull,
|
|
329
|
+
fieldName,
|
|
330
|
+
columnName,
|
|
331
|
+
columnDefault: column.default,
|
|
332
|
+
columnGenerated: column.isGenerated,
|
|
333
|
+
otherEntity,
|
|
334
|
+
otherFieldName,
|
|
335
|
+
notNull,
|
|
336
|
+
ignore,
|
|
337
|
+
derived,
|
|
338
|
+
dbType,
|
|
339
|
+
isDeferredAndDeferrable,
|
|
340
|
+
constraintName: r.foreignKey.name,
|
|
341
|
+
hasConfigDefault,
|
|
342
|
+
onDelete: r.foreignKey.onDelete
|
|
343
|
+
};
|
|
391
344
|
}
|
|
392
345
|
function newOneToMany(config, entity, r) {
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
softDeletes: (0, config_1.softDeletesConfig)(config, entity, fieldName),
|
|
412
|
-
};
|
|
346
|
+
const column = r.foreignKey.columns[0];
|
|
347
|
+
const otherEntity = makeEntity(tableToEntityName(config, r.targetTable));
|
|
348
|
+
const { singularName, fieldName } = collectionName(config, entity, otherEntity, r);
|
|
349
|
+
const otherFieldName = referenceName(config, otherEntity, r);
|
|
350
|
+
const orderBy = config.entities[entity.name]?.relations?.[fieldName]?.orderBy ?? config.entities[otherEntity.name]?.orderBy;
|
|
351
|
+
return {
|
|
352
|
+
kind: "o2m",
|
|
353
|
+
fieldName,
|
|
354
|
+
singularName,
|
|
355
|
+
otherEntity,
|
|
356
|
+
otherFieldName,
|
|
357
|
+
otherColumnName: column.name,
|
|
358
|
+
otherColumnNotNull: column.notNull,
|
|
359
|
+
ignore: isFieldIgnored(config, entity, fieldName) || isFieldIgnored(config, otherEntity, otherFieldName),
|
|
360
|
+
isLargeCollection: isLargeCollection(config, entity, fieldName),
|
|
361
|
+
orderBy: parseOrder(orderBy),
|
|
362
|
+
softDeletes: softDeletesConfig(config, entity, fieldName)
|
|
363
|
+
};
|
|
413
364
|
}
|
|
414
365
|
function newOneToOne(config, entity, r) {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
366
|
+
const column = r.foreignKey.columns[0];
|
|
367
|
+
const otherEntity = makeEntity(tableToEntityName(config, r.targetTable));
|
|
368
|
+
const fieldName = oneToOneName(config, entity, otherEntity, r);
|
|
369
|
+
const otherFieldName = referenceName(config, otherEntity, r);
|
|
370
|
+
return {
|
|
371
|
+
kind: "o2o",
|
|
372
|
+
fieldName,
|
|
373
|
+
otherEntity,
|
|
374
|
+
otherFieldName,
|
|
375
|
+
otherColumnName: column.name,
|
|
376
|
+
otherColumnNotNull: column.notNull,
|
|
377
|
+
ignore: isFieldIgnored(config, entity, fieldName) || isFieldIgnored(config, otherEntity, otherFieldName)
|
|
378
|
+
};
|
|
425
379
|
}
|
|
426
380
|
function newManyToManyField(config, entity, r) {
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
isDeferredAndDeferrable,
|
|
452
|
-
derived,
|
|
453
|
-
softDeletes: (0, config_1.softDeletesConfig)(config, entity, fieldName),
|
|
454
|
-
hasJoinTableId: (0, utils_1.joinTableHasId)(r.joinTable),
|
|
455
|
-
};
|
|
381
|
+
const { foreignKey, targetForeignKey, targetTable } = r;
|
|
382
|
+
const otherEntity = makeEntity(tableToEntityName(config, targetTable));
|
|
383
|
+
const fieldName = manyToManyName(targetForeignKey.columns[0]);
|
|
384
|
+
const otherFieldName = manyToManyName(foreignKey.columns[0]);
|
|
385
|
+
const isDeferredAndDeferrable = targetForeignKey.isDeferred && targetForeignKey.isDeferrable;
|
|
386
|
+
const isThisSideDerived = isReactiveManyToMany(config, entity, fieldName);
|
|
387
|
+
const isOtherSideDerived = isReactiveManyToMany(config, otherEntity, otherFieldName);
|
|
388
|
+
const derived = isThisSideDerived ? "async" : isOtherSideDerived ? "otherSide" : false;
|
|
389
|
+
return {
|
|
390
|
+
kind: "m2m",
|
|
391
|
+
joinTableName: r.joinTable.name,
|
|
392
|
+
fieldName,
|
|
393
|
+
singularName: singular(fieldName),
|
|
394
|
+
columnName: foreignKey.columns[0].name,
|
|
395
|
+
otherEntity,
|
|
396
|
+
otherFieldName,
|
|
397
|
+
otherColumnName: targetForeignKey.columns[0].name,
|
|
398
|
+
ignore: isFieldIgnored(config, entity, fieldName) || isFieldIgnored(config, otherEntity, otherFieldName),
|
|
399
|
+
isLargeCollection: isLargeCollection(config, entity, fieldName),
|
|
400
|
+
isDeferredAndDeferrable,
|
|
401
|
+
derived,
|
|
402
|
+
softDeletes: softDeletesConfig(config, entity, fieldName),
|
|
403
|
+
hasJoinTableId: joinTableHasId(r.joinTable)
|
|
404
|
+
};
|
|
456
405
|
}
|
|
457
406
|
function newManyToManyEnumField(config, entity, r, enums) {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
};
|
|
407
|
+
const { foreignKey, targetForeignKey, targetTable } = r;
|
|
408
|
+
const fieldName = manyToManyName(targetForeignKey.columns[0]);
|
|
409
|
+
const enumName = tableToEntityName(config, targetTable);
|
|
410
|
+
return {
|
|
411
|
+
kind: "m2mEnum",
|
|
412
|
+
joinTableName: r.joinTable.name,
|
|
413
|
+
fieldName,
|
|
414
|
+
columnName: foreignKey.columns[0].name,
|
|
415
|
+
otherColumnName: targetForeignKey.columns[0].name,
|
|
416
|
+
enumName,
|
|
417
|
+
enumType: imp(`${enumName}@./entities.ts`),
|
|
418
|
+
enumDetailType: imp(`${plural(enumName)}@./entities.ts`),
|
|
419
|
+
enumDetailsType: imp(`${enumName}Details@./entities.ts`),
|
|
420
|
+
enumRows: enums[targetTable.name].rows,
|
|
421
|
+
ignore: isFieldIgnored(config, entity, fieldName),
|
|
422
|
+
hasJoinTableId: joinTableHasId(r.joinTable)
|
|
423
|
+
};
|
|
476
424
|
}
|
|
477
425
|
function newPolymorphicField(config, table, entity, pr) {
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
fieldName,
|
|
489
|
-
fieldType,
|
|
490
|
-
notNull,
|
|
491
|
-
components,
|
|
492
|
-
hasConfigDefault, // can be set to true by scanEntityFiles
|
|
493
|
-
};
|
|
426
|
+
const { fieldName, notNull } = pr;
|
|
427
|
+
const components = table.m2oRelations.filter((r) => !isEnumTable(config, r.targetTable)).filter((r) => !isMultiColumnForeignKey(r)).filter((r) => polymorphicFieldName(config, r) === fieldName).map((r) => newPolymorphicFieldComponent(config, entity, r));
|
|
428
|
+
return {
|
|
429
|
+
kind: "poly",
|
|
430
|
+
fieldName,
|
|
431
|
+
fieldType: `${entity.name}${pascalCase(fieldName)}`,
|
|
432
|
+
notNull,
|
|
433
|
+
components,
|
|
434
|
+
hasConfigDefault: isFieldHasDefault(config, entity, fieldName)
|
|
435
|
+
};
|
|
494
436
|
}
|
|
495
437
|
function newPolymorphicFieldComponent(config, entity, r) {
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
isDeferredAndDeferrable,
|
|
509
|
-
constraintName: r.foreignKey.name,
|
|
510
|
-
notNull: false,
|
|
511
|
-
};
|
|
438
|
+
const column = r.foreignKey.columns[0];
|
|
439
|
+
const columnName = column.name;
|
|
440
|
+
const otherEntity = makeEntity(tableToEntityName(config, r.targetTable));
|
|
441
|
+
return {
|
|
442
|
+
columnName,
|
|
443
|
+
columnOwner: entity,
|
|
444
|
+
otherEntity,
|
|
445
|
+
otherFieldName: column.uniqueIndexes.find(isOneToOneIndex) !== void 0 ? oneToOneName(config, otherEntity, entity, r) : collectionName(config, otherEntity, entity, r).fieldName,
|
|
446
|
+
isDeferredAndDeferrable: r.foreignKey.isDeferred && r.foreignKey.isDeferrable,
|
|
447
|
+
constraintName: r.foreignKey.name,
|
|
448
|
+
notNull: false
|
|
449
|
+
};
|
|
512
450
|
}
|
|
513
451
|
function isFieldNameOverrides(maybeOverride) {
|
|
514
|
-
|
|
515
|
-
!Array.isArray(maybeOverride) &&
|
|
516
|
-
typeof maybeOverride === "object" &&
|
|
517
|
-
Object.keys(maybeOverride).some((k) => k === "fieldName" || k === "otherFieldName"));
|
|
452
|
+
return maybeOverride !== null && !Array.isArray(maybeOverride) && typeof maybeOverride === "object" && Object.keys(maybeOverride).some((k) => k === "fieldName" || k === "otherFieldName");
|
|
518
453
|
}
|
|
519
454
|
/** Finds the field name for o2o side of a o2o/m2o. */
|
|
520
|
-
function oneToOneName(config,
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
// For `comments.parent_book_review_id`, we would just use `BookReview.comment` as the name
|
|
531
|
-
// For `authors.draft_current_book_id`, we would just use `Book.author` as the name
|
|
532
|
-
// For `project_items.current_selection_id`, we would use `HomeownerSelection.currentProjectItem`
|
|
533
|
-
const refTable = r instanceof pg_structure_1.M2ORelation ? r.targetTable : r.sourceTable;
|
|
534
|
-
// Does the ref table have any m2o pointing table at the key table?
|
|
535
|
-
const found = refTable.m2oRelations.find((s) => (0, utils_1.tableToEntityName)(config, s.targetTable) === keyEntity.name);
|
|
536
|
-
// console.log({refTable: refTable.name, keyTable: keyTable.name, found: found?.name, fieldName});
|
|
537
|
-
if (!found) {
|
|
538
|
-
// If there aren't any m2os, just use the raw type name like `.image` or `.comment`
|
|
539
|
-
return (0, change_case_1.camelCase)(keyEntity.name);
|
|
540
|
-
}
|
|
541
|
-
else {
|
|
542
|
-
// If there is a m2o, assume we might conflict, and use the column name to at least be unique
|
|
543
|
-
// Start with `book` from `images.book_id` or `current_draft_book` from `authors.current_draft_book_id`
|
|
544
|
-
let fieldName = r.foreignKey.columns[0].name.replace(idSuffix, "");
|
|
545
|
-
// Suffix the new type that we're pointing to, to `current_draft_book_author`
|
|
546
|
-
fieldName = `${fieldName}_${keyEntity.name}`;
|
|
547
|
-
// And drop the `book`, to `current_draft__author`
|
|
548
|
-
fieldName = fieldName.replace(refEntity.name.toLowerCase(), "");
|
|
549
|
-
// Then camel case, to `currentDraftAuthor`
|
|
550
|
-
return (0, change_case_1.camelCase)(fieldName);
|
|
551
|
-
}
|
|
455
|
+
function oneToOneName(config, refEntity, keyEntity, r) {
|
|
456
|
+
const overrides = r.foreignKey.columns[0].commentData;
|
|
457
|
+
if (isFieldNameOverrides(overrides) && overrides.otherFieldName) return overrides.otherFieldName;
|
|
458
|
+
if (!(r instanceof M2ORelation ? r.targetTable : r.sourceTable).m2oRelations.find((s) => tableToEntityName(config, s.targetTable) === keyEntity.name)) return camelCase(keyEntity.name);
|
|
459
|
+
else {
|
|
460
|
+
let fieldName = r.foreignKey.columns[0].name.replace(idSuffix, "");
|
|
461
|
+
fieldName = `${fieldName}_${keyEntity.name}`;
|
|
462
|
+
fieldName = fieldName.replace(refEntity.name.toLowerCase(), "");
|
|
463
|
+
return camelCase(fieldName);
|
|
464
|
+
}
|
|
552
465
|
}
|
|
553
466
|
const idSuffix = /_id$|Id$/;
|
|
554
467
|
function referenceName(config, entity, r) {
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
// If the name is overridden then use that
|
|
559
|
-
(isFieldNameOverrides(overrides) ? overrides.fieldName : undefined) ??
|
|
560
|
-
(0, change_case_1.camelCase)(column.name.replace(idSuffix, "")));
|
|
468
|
+
const [column] = r.foreignKey.columns;
|
|
469
|
+
const overrides = column.commentData;
|
|
470
|
+
return polymorphicFieldName(config, r) ?? (isFieldNameOverrides(overrides) ? overrides.fieldName : void 0) ?? camelCase(column.name.replace(idSuffix, ""));
|
|
561
471
|
}
|
|
562
472
|
function enumFieldName(columnName) {
|
|
563
|
-
|
|
473
|
+
return camelCase(columnName.replace(idSuffix, ""));
|
|
564
474
|
}
|
|
565
475
|
function primitiveFieldName(columnName) {
|
|
566
|
-
|
|
476
|
+
return camelCase(columnName);
|
|
567
477
|
}
|
|
568
478
|
function manyToManyName(column) {
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
return overrides.otherFieldName;
|
|
573
|
-
}
|
|
574
|
-
return (0, change_case_1.camelCase)((0, pluralize_1.plural)(column.name.replace(idSuffix, "")));
|
|
479
|
+
const overrides = column.commentData;
|
|
480
|
+
if (isFieldNameOverrides(overrides) && overrides.otherFieldName) return overrides.otherFieldName;
|
|
481
|
+
return camelCase(plural(column.name.replace(idSuffix, "")));
|
|
575
482
|
}
|
|
576
483
|
/** Returns the collection name to use on `entity` when referring to `otherEntity`s. */
|
|
577
|
-
function collectionName(config,
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
singularName = `${column.name.replace(idSuffix, "")}_${singularName}`;
|
|
598
|
-
}
|
|
599
|
-
// If we've guessed `Book.bookReviews` based on `book_reviews.book_id` --> `bookReviews`, strip the `Book` prefix
|
|
600
|
-
if (singularName.length > singleEntity.name.length && singularName.startsWith(singleEntity.name)) {
|
|
601
|
-
singularName = singularName.substring(singleEntity.name.length);
|
|
602
|
-
}
|
|
603
|
-
// camelize the name
|
|
604
|
-
singularName = (0, change_case_1.camelCase)(singularName);
|
|
605
|
-
// and pluralize for fieldName
|
|
606
|
-
return { fieldName: (0, pluralize_1.plural)(singularName), singularName };
|
|
484
|
+
function collectionName(config, singleEntity, collectionEntity, r) {
|
|
485
|
+
const [column] = r.foreignKey.columns;
|
|
486
|
+
const overrides = column.commentData;
|
|
487
|
+
if (isFieldNameOverrides(overrides) && overrides.otherFieldName) {
|
|
488
|
+
const fieldName = overrides.otherFieldName;
|
|
489
|
+
return {
|
|
490
|
+
fieldName,
|
|
491
|
+
singularName: singular(fieldName)
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
let singularName = collectionEntity.name;
|
|
495
|
+
const sourceTable = r.type === "m2o" ? r.sourceTable : r.targetTable;
|
|
496
|
+
const targetTable = r.type === "m2o" ? r.targetTable : r.sourceTable;
|
|
497
|
+
if (r.type !== "m2m" && sourceTable.m2oRelations.filter((r) => r.targetTable === targetTable).length > 1) singularName = `${column.name.replace(idSuffix, "")}_${singularName}`;
|
|
498
|
+
if (singularName.length > singleEntity.name.length && singularName.startsWith(singleEntity.name)) singularName = singularName.substring(singleEntity.name.length);
|
|
499
|
+
singularName = camelCase(singularName);
|
|
500
|
+
return {
|
|
501
|
+
fieldName: plural(singularName),
|
|
502
|
+
singularName
|
|
503
|
+
};
|
|
607
504
|
}
|
|
608
505
|
function failIfOverlappingFieldNames(entity) {
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
}
|
|
627
|
-
});
|
|
506
|
+
const allFields = [
|
|
507
|
+
entity.primaryKey,
|
|
508
|
+
...entity.primitives,
|
|
509
|
+
...entity.enums,
|
|
510
|
+
...entity.pgEnums,
|
|
511
|
+
...entity.manyToOnes,
|
|
512
|
+
...entity.oneToManys,
|
|
513
|
+
...entity.largeOneToManys,
|
|
514
|
+
...entity.oneToOnes,
|
|
515
|
+
...entity.manyToManys,
|
|
516
|
+
...entity.largeManyToManys,
|
|
517
|
+
...entity.manyToManyEnums,
|
|
518
|
+
...entity.polymorphics
|
|
519
|
+
];
|
|
520
|
+
Object.entries(groupBy(allFields, (f) => f.fieldName)).forEach(([fieldName, fields]) => {
|
|
521
|
+
if (fields.length > 1) throw new Error(`In ${entity.name}, found multiple fields named '${fieldName}': ${fields.map((f) => f.kind).join(" ")}`);
|
|
522
|
+
});
|
|
628
523
|
}
|
|
629
524
|
function makeEntity(entityName) {
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
}),
|
|
645
|
-
...names,
|
|
646
|
-
};
|
|
525
|
+
const names = entitySymbolNames(entityName);
|
|
526
|
+
return {
|
|
527
|
+
name: entityName,
|
|
528
|
+
type: entityType(entityName),
|
|
529
|
+
typeSymbol: entityTypeSymbol(entityName),
|
|
530
|
+
typeForMetadataFile: entityTypeForMetadataFile(entityName),
|
|
531
|
+
metaName: metaName(entityName),
|
|
532
|
+
metaType: metaType(entityName),
|
|
533
|
+
idType: entityTypeImport(entityName, names.idName),
|
|
534
|
+
orderType: entityTypeImport(entityName, names.orderName),
|
|
535
|
+
optsType: entityTypeImport(entityName, names.optsName),
|
|
536
|
+
configConst: imp(`${camelCase(entityName)}Config@./entities.ts`, { definedIn: `./codegen/${entityName}Codegen.ts` }),
|
|
537
|
+
...names
|
|
538
|
+
};
|
|
647
539
|
}
|
|
648
540
|
/**
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
541
|
+
* Collapses the per-relation `otherEntity` copies down to the one primary `Entity` per name.
|
|
542
|
+
*
|
|
543
|
+
* `makeEntity` mints a fresh `Entity` for every relation's `otherEntity`, so each entity ends up with
|
|
544
|
+
* many duplicate objects floating around. Pointing them all at the single `entitiesByName[name].entity`
|
|
545
|
+
* instance means later passes (i.e. `resolveNameConflicts`) only have to update one object per name.
|
|
546
|
+
*
|
|
547
|
+
* Must run after inheritance, since STI/CTI specialization both adds and re-points `otherEntity`s.
|
|
548
|
+
*/
|
|
657
549
|
function canonicalizeOtherEntities(db) {
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
}
|
|
550
|
+
const canonical = (other) => db.entitiesByName[other.name]?.entity ?? other;
|
|
551
|
+
for (const meta of db.entities) {
|
|
552
|
+
for (const field of [
|
|
553
|
+
...meta.manyToOnes,
|
|
554
|
+
...meta.oneToManys,
|
|
555
|
+
...meta.largeOneToManys,
|
|
556
|
+
...meta.oneToOnes,
|
|
557
|
+
...meta.manyToManys,
|
|
558
|
+
...meta.largeManyToManys
|
|
559
|
+
]) field.otherEntity = canonical(field.otherEntity);
|
|
560
|
+
for (const poly of meta.polymorphics) for (const comp of poly.components) comp.otherEntity = canonical(comp.otherEntity);
|
|
561
|
+
if (meta.physicalMetadata) canonicalizeOtherEntities({
|
|
562
|
+
...db,
|
|
563
|
+
entities: [meta.physicalMetadata]
|
|
564
|
+
});
|
|
565
|
+
}
|
|
675
566
|
}
|
|
676
567
|
/**
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
568
|
+
* Rewrites codegen'd type names that collide with another exported type name.
|
|
569
|
+
*
|
|
570
|
+
* `makeEntity` defaults each name to the conventional `${name}<Suffix>`, but if a separate entity or
|
|
571
|
+
* enum is literally named e.g. `AuthorScope` or `AuthorOrder`, our generated type of the same name
|
|
572
|
+
* would collide with it, so we fall back to `Author_Scope` / `Author_Order`.
|
|
573
|
+
*
|
|
574
|
+
* Relies on `canonicalizeOtherEntities` having run, so mutating each primary `meta.entity` also updates
|
|
575
|
+
* the `otherEntity` references that point at it (e.g. `Book.author: AuthorId` follows `Author`'s rename).
|
|
576
|
+
*/
|
|
686
577
|
function resolveNameConflicts(config, db) {
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
}
|
|
695
|
-
for (const pgEnum of Object.values(db.pgEnums))
|
|
696
|
-
reserved.add(pgEnum.name);
|
|
697
|
-
for (const meta of db.entities) {
|
|
698
|
-
if (hasNameConflict(meta.name, reserved))
|
|
699
|
-
applyEntityNames(meta.entity, reserved);
|
|
700
|
-
}
|
|
578
|
+
const reserved = new Set(db.entities.map((meta) => meta.name));
|
|
579
|
+
for (const enumData of Object.values(db.enums)) {
|
|
580
|
+
const enumName = tableToEntityName(config, enumData.table);
|
|
581
|
+
reserved.add(enumName).add(`${enumName}Details`).add(plural(enumName));
|
|
582
|
+
}
|
|
583
|
+
for (const pgEnum of Object.values(db.pgEnums)) reserved.add(pgEnum.name);
|
|
584
|
+
for (const meta of db.entities) if (hasNameConflict(meta.name, reserved)) applyEntityNames(meta.entity, reserved);
|
|
701
585
|
}
|
|
702
586
|
/** Computes the codegen'd type names for an entity, underscoring any that `reserved` already contains. */
|
|
703
587
|
function entitySymbolNames(name, reserved) {
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
588
|
+
const pick = (suffix) => reserved?.has(`${name}${suffix}`) ? `${name}_${suffix}` : `${name}${suffix}`;
|
|
589
|
+
return {
|
|
590
|
+
idName: pick("Id"),
|
|
591
|
+
fieldsName: pick("Fields"),
|
|
592
|
+
optsName: pick("Opts"),
|
|
593
|
+
idsOptsName: pick("IdsOpts"),
|
|
594
|
+
filterName: pick("Filter"),
|
|
595
|
+
graphqlFilterName: pick("GraphQLFilter"),
|
|
596
|
+
orderName: pick("Order"),
|
|
597
|
+
factoryExtrasName: pick("FactoryExtras"),
|
|
598
|
+
scopeName: pick("Scope"),
|
|
599
|
+
scopesName: pick("Scopes")
|
|
600
|
+
};
|
|
717
601
|
}
|
|
718
602
|
/** Returns true if any of the entity's conventional type names is already taken. */
|
|
719
603
|
function hasNameConflict(name, reserved) {
|
|
720
|
-
|
|
604
|
+
return Object.values(entitySymbolNames(name)).some((conventional) => reserved.has(conventional));
|
|
721
605
|
}
|
|
722
606
|
/** Rewrites an entity's type names (and the `Import`s built from them) to their de-conflicted form. */
|
|
723
607
|
function applyEntityNames(entity, reserved) {
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
608
|
+
const names = entitySymbolNames(entity.name, reserved);
|
|
609
|
+
Object.assign(entity, names);
|
|
610
|
+
entity.idType = entityTypeImport(entity.name, names.idName);
|
|
611
|
+
entity.orderType = entityTypeImport(entity.name, names.orderName);
|
|
612
|
+
entity.optsType = entityTypeImport(entity.name, names.optsName);
|
|
729
613
|
}
|
|
730
614
|
function entityTypeImport(entityName, symbolName) {
|
|
731
|
-
|
|
615
|
+
return imp(`t:${symbolName}@./entities.ts`, { definedIn: `./codegen/${entityName}Codegen.ts` });
|
|
732
616
|
}
|
|
733
617
|
function metaName(entityName) {
|
|
734
|
-
|
|
618
|
+
return `${camelCase(entityName)}Meta`;
|
|
735
619
|
}
|
|
736
620
|
function metaType(entityName) {
|
|
737
|
-
|
|
621
|
+
return imp(`${metaName(entityName)}@./entities.ts`);
|
|
738
622
|
}
|
|
739
623
|
function entityType(entityName) {
|
|
740
|
-
|
|
624
|
+
return imp(`t:${entityName}@./entities.ts`);
|
|
741
625
|
}
|
|
742
626
|
function entityTypeSymbol(entityName) {
|
|
743
|
-
|
|
627
|
+
return imp(`${entityName}@./entities.ts`);
|
|
744
628
|
}
|
|
745
629
|
function entityTypeForMetadataFile(entityName) {
|
|
746
|
-
|
|
630
|
+
return imp(`${entityName}@./${entityName}.ts`);
|
|
747
631
|
}
|
|
748
632
|
function mapType(config, tableName, columnName, dbColumnType) {
|
|
749
|
-
|
|
633
|
+
return mapSimpleDbTypeToTypescriptType(config, dbColumnType);
|
|
750
634
|
}
|
|
751
635
|
function isEnumArray(c) {
|
|
752
|
-
|
|
636
|
+
return c.arrayDimension === 1 && !!c.comment && c.comment.startsWith("enum=");
|
|
753
637
|
}
|
|
754
638
|
function isArray(c) {
|
|
755
|
-
|
|
639
|
+
return c.arrayDimension === 1;
|
|
756
640
|
}
|
|
757
641
|
function isPgEnum(c) {
|
|
758
|
-
|
|
642
|
+
return c.type instanceof EnumType;
|
|
759
643
|
}
|
|
760
644
|
function superstructType(s) {
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
return ts_poet_1.Import.from(`${(0, change_case_1.pascalCase)(symbol)}@${path.join("@")}`);
|
|
645
|
+
const [symbol, ...path] = s.split("@");
|
|
646
|
+
return Import.from(`${pascalCase(symbol)}@${path.join("@")}`);
|
|
764
647
|
}
|
|
765
648
|
function zodSchemaType(s) {
|
|
766
|
-
|
|
767
|
-
|
|
649
|
+
const schema = Import.from(s);
|
|
650
|
+
return code`${Zod}.input<typeof ${schema}>`;
|
|
768
651
|
}
|
|
769
652
|
function userFieldTypeType(s) {
|
|
770
|
-
|
|
653
|
+
return Import.from(`t:${s}`);
|
|
771
654
|
}
|
|
772
655
|
function serdeType(s) {
|
|
773
|
-
|
|
656
|
+
return Import.from(s);
|
|
774
657
|
}
|
|
658
|
+
//#endregion
|
|
659
|
+
export { EntityDbMetadata, canonicalizeOtherEntities, collectionName, failIfOverlappingFieldNames, makeEntity, manyToManyName, oneToOneName, referenceName, resolveNameConflicts };
|
|
660
|
+
|
|
775
661
|
//# sourceMappingURL=EntityDbMetadata.js.map
|