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