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