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