joist-codegen 2.3.0-next.6 → 2.3.0-next.60
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 +951 -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 +734 -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,144 +1,116 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const typescript_1 = __importDefault(require("typescript"));
|
|
1
|
+
import "./config.js";
|
|
2
|
+
import "./EntityDbMetadata.js";
|
|
3
|
+
import { camelCase } from "change-case";
|
|
4
|
+
import { join } from "path";
|
|
5
|
+
import jscodeshift from "jscodeshift";
|
|
6
|
+
import { readFile } from "fs/promises";
|
|
7
|
+
import "ast-types";
|
|
8
|
+
//#region src/findEntityScopes.ts
|
|
9
|
+
const j = jscodeshift.withParser("ts");
|
|
11
10
|
/** Finds static scope declarations for all entity files. */
|
|
12
11
|
async function findAllEntityScopes(config, entities) {
|
|
13
|
-
|
|
12
|
+
return Object.fromEntries(await Promise.all(entities.map((entity) => findEntityScopes(config, entity))));
|
|
14
13
|
}
|
|
15
14
|
/** Finds static scope declarations a given entity file. */
|
|
16
15
|
async function findEntityScopes(config, entity) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
for (const statement of sourceFile.statements) {
|
|
29
|
-
// i.e. `export class Author extends AuthorCodegen { ... }`.
|
|
30
|
-
if (typescript_1.default.isClassDeclaration(statement) && statement.name?.text === entityName) {
|
|
31
|
-
return [
|
|
32
|
-
entityName,
|
|
33
|
-
statement.members.flatMap((member) => maybeScopeMember(sourceFile, member, entityName, scopeTypeName)),
|
|
34
|
-
];
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return [entityName, []];
|
|
16
|
+
const { name: entityName, scopeName: scopeTypeName } = entity;
|
|
17
|
+
const scopeFnName = `${camelCase(entityName)}Scope`;
|
|
18
|
+
const contents = await readEntityFile(join(config.entitiesDirectory, `${entityName}.ts`));
|
|
19
|
+
if (contents === void 0) return [entityName, []];
|
|
20
|
+
if (contents.indexOf(scopeFnName) === -1) return [entityName, []];
|
|
21
|
+
const program = j(contents).find(j.Program).nodes()[0];
|
|
22
|
+
for (const statement of program.body) {
|
|
23
|
+
const declaration = j.ExportNamedDeclaration.check(statement) || j.ExportDefaultDeclaration.check(statement) ? statement.declaration : statement;
|
|
24
|
+
if (declaration && j.ClassDeclaration.check(declaration) && declaration.id?.name === entityName) return [entityName, declaration.body.body.flatMap((member) => maybeScopeMember(member, entityName, scopeTypeName))];
|
|
25
|
+
}
|
|
26
|
+
return [entityName, []];
|
|
38
27
|
}
|
|
39
28
|
/** Reads an entity file if it already exists. */
|
|
40
29
|
async function readEntityFile(fileName) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
throw e;
|
|
48
|
-
}
|
|
30
|
+
try {
|
|
31
|
+
return await readFile(fileName, "utf8");
|
|
32
|
+
} catch (e) {
|
|
33
|
+
if (isNoSuchFileError(e)) return void 0;
|
|
34
|
+
throw e;
|
|
35
|
+
}
|
|
49
36
|
}
|
|
50
37
|
/** Returns true for a missing user-owned entity file. */
|
|
51
38
|
function isNoSuchFileError(e) {
|
|
52
|
-
|
|
39
|
+
return typeof e === "object" && e !== null && "code" in e && e.code === "ENOENT";
|
|
53
40
|
}
|
|
54
41
|
/** Converts a static property declaration into a generated scope member. */
|
|
55
|
-
function maybeScopeMember(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
42
|
+
function maybeScopeMember(member, entityName, scopeTypeName) {
|
|
43
|
+
if (!j.ClassProperty.check(member) || !member.static) return [];
|
|
44
|
+
if (!member.value || !j.Identifier.check(member.key)) return [];
|
|
45
|
+
if (!isScopeInitializer(member.value, entityName)) return [];
|
|
46
|
+
if (member.typeAnnotation) {
|
|
47
|
+
if (!j.TSTypeAnnotation.check(member.typeAnnotation)) return [];
|
|
48
|
+
const type = member.typeAnnotation.typeAnnotation;
|
|
49
|
+
if (!isScopeType(type, scopeTypeName)) return [];
|
|
50
|
+
return [{
|
|
51
|
+
name: member.key.name,
|
|
52
|
+
type: j(type).toSource()
|
|
53
|
+
}];
|
|
54
|
+
}
|
|
55
|
+
const type = inferScopeType(member.value, scopeTypeName);
|
|
56
|
+
return type ? [{
|
|
57
|
+
name: member.key.name,
|
|
58
|
+
type
|
|
59
|
+
}] : [];
|
|
72
60
|
}
|
|
73
61
|
/** Infers a generated scope member type from an untyped static scope initializer. */
|
|
74
|
-
function inferScopeType(
|
|
75
|
-
|
|
76
|
-
? maybeParameterizedScope(sourceFile, initializer, scopeTypeName)
|
|
77
|
-
: scopeTypeName;
|
|
62
|
+
function inferScopeType(initializer, scopeTypeName) {
|
|
63
|
+
return isParameterizedScopeInitializer(initializer) ? maybeParameterizedScope(initializer, scopeTypeName) : scopeTypeName;
|
|
78
64
|
}
|
|
79
65
|
/** Returns true for `scope.fn(...)` initializers. */
|
|
80
66
|
function isParameterizedScopeInitializer(initializer) {
|
|
81
|
-
|
|
82
|
-
typescript_1.default.isPropertyAccessExpression(initializer.expression) &&
|
|
83
|
-
initializer.expression.name.text === "fn");
|
|
67
|
+
return j.CallExpression.check(initializer) && j.MemberExpression.check(initializer.callee) && !initializer.callee.computed && j.Identifier.check(initializer.callee.property) && initializer.callee.property.name === "fn";
|
|
84
68
|
}
|
|
85
69
|
/** Returns a function type for `scope.fn((prefix: string) => ...)` initializers. */
|
|
86
|
-
function maybeParameterizedScope(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const params = fn.parameters.map((param) => parameterType(sourceFile, param));
|
|
97
|
-
if (params.some((param) => param === undefined))
|
|
98
|
-
return undefined;
|
|
99
|
-
return `(${params.join(", ")}) => ${scopeTypeName}`;
|
|
70
|
+
function maybeParameterizedScope(initializer, scopeTypeName) {
|
|
71
|
+
if (!j.CallExpression.check(initializer)) return void 0;
|
|
72
|
+
if (!j.MemberExpression.check(initializer.callee)) return void 0;
|
|
73
|
+
if (initializer.callee.computed || !j.Identifier.check(initializer.callee.property)) return void 0;
|
|
74
|
+
if (initializer.callee.property.name !== "fn") return void 0;
|
|
75
|
+
const fn = initializer.arguments[0];
|
|
76
|
+
if (!fn || !j.ArrowFunctionExpression.check(fn) && !j.FunctionExpression.check(fn)) return void 0;
|
|
77
|
+
const params = fn.params.map(parameterType);
|
|
78
|
+
if (params.some((param) => param === void 0)) return void 0;
|
|
79
|
+
return `(${params.join(", ")}) => ${scopeTypeName}`;
|
|
100
80
|
}
|
|
101
81
|
/** Returns a function-type parameter, i.e. `prefix: string`, when syntax-only inference is safe. */
|
|
102
|
-
function parameterType(
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
82
|
+
function parameterType(param) {
|
|
83
|
+
if (j.Identifier.check(param)) {
|
|
84
|
+
if (!param.typeAnnotation || !j.TSTypeAnnotation.check(param.typeAnnotation)) return void 0;
|
|
85
|
+
const optional = param.optional ? "?" : "";
|
|
86
|
+
return `${param.name}${optional}: ${j(param.typeAnnotation.typeAnnotation).toSource()}`;
|
|
87
|
+
}
|
|
88
|
+
if (j.RestElement.check(param) && j.Identifier.check(param.argument)) {
|
|
89
|
+
const typeAnnotation = param.typeAnnotation ?? param.argument.typeAnnotation;
|
|
90
|
+
if (!typeAnnotation || !j.TSTypeAnnotation.check(typeAnnotation)) return void 0;
|
|
91
|
+
return `...${param.argument.name}: ${j(typeAnnotation.typeAnnotation).toSource()}`;
|
|
92
|
+
}
|
|
113
93
|
}
|
|
114
94
|
/** Returns true for `EntityScope` and function types returning `EntityScope`. */
|
|
115
95
|
function isScopeType(type, scopeTypeName) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (typescript_1.default.isFunctionTypeNode(type))
|
|
121
|
-
return isScopeType(type.type, scopeTypeName);
|
|
122
|
-
if (typescript_1.default.isParenthesizedTypeNode(type))
|
|
123
|
-
return isScopeType(type.type, scopeTypeName);
|
|
124
|
-
return false;
|
|
96
|
+
if (j.TSTypeReference.check(type) && j.Identifier.check(type.typeName)) return type.typeName.name === scopeTypeName;
|
|
97
|
+
if (j.TSFunctionType.check(type) && type.typeAnnotation && j.TSTypeAnnotation.check(type.typeAnnotation)) return isScopeType(type.typeAnnotation.typeAnnotation, scopeTypeName);
|
|
98
|
+
if (j.TSParenthesizedType.check(type)) return isScopeType(type.typeAnnotation, scopeTypeName);
|
|
99
|
+
return false;
|
|
125
100
|
}
|
|
126
101
|
/** Returns true for scope initializers, I.e. `scope(...)`, `scope(...).orderBy(...)`, or `Author.adult...`. */
|
|
127
102
|
function isScopeInitializer(initializer, entityName) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return isScopeRootedExpression(initializer, entityName);
|
|
103
|
+
if (!j.CallExpression.check(initializer) && !j.MemberExpression.check(initializer)) return false;
|
|
104
|
+
return isScopeRootedExpression(initializer, entityName);
|
|
131
105
|
}
|
|
132
106
|
/** Returns true for a call/property expression chain rooted at `scope` or the current entity. */
|
|
133
107
|
function isScopeRootedExpression(expression, entityName) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
return isScopeRootedExpression(expression.expression, entityName);
|
|
139
|
-
// i.e. `scope.fn((prefix) => (a) => a.firstName.like(`${prefix}%`))` or `Author.adult.orderBy(...)`.
|
|
140
|
-
if (typescript_1.default.isPropertyAccessExpression(expression))
|
|
141
|
-
return isScopeRootedExpression(expression.expression, entityName);
|
|
142
|
-
return false;
|
|
108
|
+
if (j.Identifier.check(expression)) return expression.name === "scope" || expression.name === entityName;
|
|
109
|
+
if (j.CallExpression.check(expression)) return isScopeRootedExpression(expression.callee, entityName);
|
|
110
|
+
if (j.MemberExpression.check(expression) && !expression.computed) return isScopeRootedExpression(expression.object, entityName);
|
|
111
|
+
return false;
|
|
143
112
|
}
|
|
113
|
+
//#endregion
|
|
114
|
+
export { findAllEntityScopes };
|
|
115
|
+
|
|
144
116
|
//# sourceMappingURL=findEntityScopes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findEntityScopes.js","sourceRoot":"","sources":["../src/findEntityScopes.ts"],"names":[],"mappings":";;;;;AAkBA,kDAEC;AApBD,6CAAwC;AACxC,0CAAuC;AACvC,+BAA4B;AAC5B,4DAA4B;AAc5B,4DAA4D;AACrD,KAAK,UAAU,mBAAmB,CAAC,MAAc,EAAE,QAAkB;IAC1E,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3G,CAAC;AAED,2DAA2D;AAC3D,KAAK,UAAU,gBAAgB,CAAC,MAAc,EAAE,MAAc;IAC5D,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,GAAG,MAAM,CAAC;IAC9D,kGAAkG;IAClG,MAAM,WAAW,GAAG,GAAG,IAAA,uBAAS,EAAC,UAAU,CAAC,OAAO,CAAC;IAEpD,0FAA0F;IAC1F,MAAM,QAAQ,GAAG,IAAA,WAAI,EAAC,MAAM,CAAC,iBAAiB,EAAE,GAAG,UAAU,KAAK,CAAC,CAAC;IACpE,MAAM,QAAQ,GAAG,MAAM,cAAc,CAAC,QAAQ,CAAC,CAAC;IAChD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C,IAAI,EAAE,aAAa,CAAC,CAAC;IAC9E,IAAI,oBAAE,CAAC,uBAAuB,CAAC,IAAI,CAAC;QAAE,OAAO,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IACnF,OAAO,KAAK,CAAC;AACf,CAAC;AAED,+GAA+G;AAC/G,SAAS,kBAAkB,CAAC,WAA0B,EAAE,UAAkB;IACxE,IAAI,CAAC,oBAAE,CAAC,gBAAgB,CAAC,WAAW,CAAC,IAAI,CAAC,oBAAE,CAAC,0BAA0B,CAAC,WAAW,CAAC;QAAE,OAAO,KAAK,CAAC;IACnG,OAAO,uBAAuB,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;AAC1D,CAAC;AAED,iGAAiG;AACjG,SAAS,uBAAuB,CAAC,UAAyB,EAAE,UAAkB;IAC5E,sCAAsC;IACtC,IAAI,oBAAE,CAAC,YAAY,CAAC,UAAU,CAAC;QAAE,OAAO,UAAU,CAAC,IAAI,KAAK,OAAO,IAAI,UAAU,CAAC,IAAI,KAAK,UAAU,CAAC;IACtG,IAAI,oBAAE,CAAC,gBAAgB,CAAC,UAAU,CAAC;QAAE,OAAO,uBAAuB,CAAC,UAAU,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IACvG,qGAAqG;IACrG,IAAI,oBAAE,CAAC,0BAA0B,CAAC,UAAU,CAAC;QAAE,OAAO,uBAAuB,CAAC,UAAU,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IACjH,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
1
|
+
{"version":3,"file":"findEntityScopes.js","names":[],"sources":["../src/findEntityScopes.ts"],"sourcesContent":["import { readFile } from \"fs/promises\";\nimport { join } from \"path\";\n\nimport { type namedTypes } from \"ast-types\";\nimport { camelCase } from \"change-case\";\nimport jscodeshift from \"jscodeshift\";\n\nimport { type Config } from \"./config.ts\";\nimport { type Entity } from \"./EntityDbMetadata.ts\";\n\nconst j = jscodeshift.withParser(\"ts\");\n\ntype Expression = NonNullable<namedTypes.ClassProperty[\"value\"]>;\ntype Parameter = namedTypes.ArrowFunctionExpression[\"params\"][number];\ntype TypeNode = namedTypes.TSTypeAnnotation[\"typeAnnotation\"];\n\n/** Each `static active = ...` scope in an entity. */\nexport interface ScopeMember {\n // I.e. \"adult\" from `static adult: AuthorScope = scope(...)`.\n name: string;\n // I.e. \"AuthorScope\" or \"(prefix: string) => AuthorScope\".\n type: string;\n}\n\nexport type ScopeMembersByEntity = Record<string, ScopeMember[]>;\n\n/** Finds static scope declarations for all entity files. */\nexport async function findAllEntityScopes(config: Config, entities: Entity[]): Promise<ScopeMembersByEntity> {\n return Object.fromEntries(await Promise.all(entities.map((entity) => findEntityScopes(config, entity))));\n}\n\n/** Finds static scope declarations a given entity file. */\nasync function findEntityScopes(config: Config, entity: Entity): Promise<[string, ScopeMember[]]> {\n const { name: entityName, scopeName: scopeTypeName } = entity;\n // i.e. `authorScope`, the conventional renamed-to-`scope` import users put in their entity files.\n const scopeFnName = `${camelCase(entityName)}Scope`;\n\n // i.e. `packages/tests/integration/src/entities/Author.ts` when `entityName` is \"Author\".\n const fileName = join(config.entitiesDirectory, `${entityName}.ts`);\n const contents = await readEntityFile(fileName);\n if (contents === undefined) return [entityName, []];\n if (contents.indexOf(scopeFnName) === -1) return [entityName, []];\n\n const program = j(contents).find(j.Program).nodes()[0];\n for (const statement of program.body) {\n const declaration =\n j.ExportNamedDeclaration.check(statement) || j.ExportDefaultDeclaration.check(statement)\n ? statement.declaration\n : statement;\n // i.e. `export class Author extends AuthorCodegen { ... }`.\n if (declaration && j.ClassDeclaration.check(declaration) && declaration.id?.name === entityName) {\n return [\n entityName,\n declaration.body.body.flatMap((member) => maybeScopeMember(member, entityName, scopeTypeName)),\n ];\n }\n }\n return [entityName, []];\n}\n\n/** Reads an entity file if it already exists. */\nasync function readEntityFile(fileName: string): Promise<string | undefined> {\n try {\n return await readFile(fileName, \"utf8\");\n } catch (e) {\n if (isNoSuchFileError(e)) return undefined;\n throw e;\n }\n}\n\n/** Returns true for a missing user-owned entity file. */\nfunction isNoSuchFileError(e: unknown): boolean {\n return typeof e === \"object\" && e !== null && \"code\" in e && e.code === \"ENOENT\";\n}\n\n/** Converts a static property declaration into a generated scope member. */\nfunction maybeScopeMember(member: namedTypes.Node, entityName: string, scopeTypeName: string): ScopeMember[] {\n if (!j.ClassProperty.check(member) || !member.static) return [];\n // i.e. accept `static adult = scope(...)`, but skip methods/getters/unsupported fields.\n if (!member.value || !j.Identifier.check(member.key)) return [];\n if (!isScopeInitializer(member.value, entityName)) return [];\n if (member.typeAnnotation) {\n if (!j.TSTypeAnnotation.check(member.typeAnnotation)) return [];\n const type = member.typeAnnotation.typeAnnotation;\n if (!isScopeType(type, scopeTypeName)) return [];\n return [{ name: member.key.name, type: j(type).toSource() }];\n }\n const type = inferScopeType(member.value, scopeTypeName);\n return type ? [{ name: member.key.name, type }] : [];\n}\n\n/** Infers a generated scope member type from an untyped static scope initializer. */\nfunction inferScopeType(initializer: Expression, scopeTypeName: string): string | undefined {\n return isParameterizedScopeInitializer(initializer)\n ? maybeParameterizedScope(initializer, scopeTypeName)\n : scopeTypeName;\n}\n\n/** Returns true for `scope.fn(...)` initializers. */\nfunction isParameterizedScopeInitializer(initializer: Expression): boolean {\n return (\n j.CallExpression.check(initializer) &&\n j.MemberExpression.check(initializer.callee) &&\n !initializer.callee.computed &&\n j.Identifier.check(initializer.callee.property) &&\n initializer.callee.property.name === \"fn\"\n );\n}\n\n/** Returns a function type for `scope.fn((prefix: string) => ...)` initializers. */\nfunction maybeParameterizedScope(initializer: Expression, scopeTypeName: string): string | undefined {\n if (!j.CallExpression.check(initializer)) return undefined;\n if (!j.MemberExpression.check(initializer.callee)) return undefined;\n if (initializer.callee.computed || !j.Identifier.check(initializer.callee.property)) return undefined;\n if (initializer.callee.property.name !== \"fn\") return undefined;\n const fn = initializer.arguments[0];\n if (!fn || (!j.ArrowFunctionExpression.check(fn) && !j.FunctionExpression.check(fn))) return undefined;\n const params = fn.params.map(parameterType);\n if (params.some((param) => param === undefined)) return undefined;\n return `(${params.join(\", \")}) => ${scopeTypeName}`;\n}\n\n/** Returns a function-type parameter, i.e. `prefix: string`, when syntax-only inference is safe. */\nfunction parameterType(param: Parameter): string | undefined {\n if (j.Identifier.check(param)) {\n if (!param.typeAnnotation || !j.TSTypeAnnotation.check(param.typeAnnotation)) return undefined;\n const optional = param.optional ? \"?\" : \"\";\n return `${param.name}${optional}: ${j(param.typeAnnotation.typeAnnotation).toSource()}`;\n }\n if (j.RestElement.check(param) && j.Identifier.check(param.argument)) {\n const typeAnnotation = param.typeAnnotation ?? param.argument.typeAnnotation;\n if (!typeAnnotation || !j.TSTypeAnnotation.check(typeAnnotation)) return undefined;\n return `...${param.argument.name}: ${j(typeAnnotation.typeAnnotation).toSource()}`;\n }\n return undefined;\n}\n\n/** Returns true for `EntityScope` and function types returning `EntityScope`. */\nfunction isScopeType(type: TypeNode, scopeTypeName: string): boolean {\n // i.e. `AuthorScope`.\n if (j.TSTypeReference.check(type) && j.Identifier.check(type.typeName)) return type.typeName.name === scopeTypeName;\n // i.e. `(prefix: string) => AuthorScope`.\n if (j.TSFunctionType.check(type) && type.typeAnnotation && j.TSTypeAnnotation.check(type.typeAnnotation)) {\n return isScopeType(type.typeAnnotation.typeAnnotation, scopeTypeName);\n }\n if (j.TSParenthesizedType.check(type)) return isScopeType(type.typeAnnotation, scopeTypeName);\n return false;\n}\n\n/** Returns true for scope initializers, I.e. `scope(...)`, `scope(...).orderBy(...)`, or `Author.adult...`. */\nfunction isScopeInitializer(initializer: Expression, entityName: string): boolean {\n if (!j.CallExpression.check(initializer) && !j.MemberExpression.check(initializer)) return false;\n return isScopeRootedExpression(initializer, entityName);\n}\n\n/** Returns true for a call/property expression chain rooted at `scope` or the current entity. */\nfunction isScopeRootedExpression(expression: Expression, entityName: string): boolean {\n // i.e. `scope({ age: { gte: 18 } })`.\n if (j.Identifier.check(expression)) return expression.name === \"scope\" || expression.name === entityName;\n if (j.CallExpression.check(expression)) return isScopeRootedExpression(expression.callee, entityName);\n // i.e. `scope.fn((prefix) => (a) => a.firstName.like(`${prefix}%`))` or `Author.adult.orderBy(...)`.\n if (j.MemberExpression.check(expression) && !expression.computed) {\n return isScopeRootedExpression(expression.object, entityName);\n }\n return false;\n}\n"],"mappings":";;;;;;;;AAUA,MAAM,IAAI,YAAY,WAAW,IAAI;;AAiBrC,eAAsB,oBAAoB,QAAgB,UAAmD;CAC3G,OAAO,OAAO,YAAY,MAAM,QAAQ,IAAI,SAAS,KAAK,WAAW,iBAAiB,QAAQ,MAAM,CAAC,CAAC,CAAC;AACzG;;AAGA,eAAe,iBAAiB,QAAgB,QAAkD;CAChG,MAAM,EAAE,MAAM,YAAY,WAAW,kBAAkB;CAEvD,MAAM,cAAc,GAAG,UAAU,UAAU,EAAE;CAI7C,MAAM,WAAW,MAAM,eADN,KAAK,OAAO,mBAAmB,GAAG,WAAW,IACjB,CAAC;CAC9C,IAAI,aAAa,KAAA,GAAW,OAAO,CAAC,YAAY,CAAC,CAAC;CAClD,IAAI,SAAS,QAAQ,WAAW,MAAM,IAAI,OAAO,CAAC,YAAY,CAAC,CAAC;CAEhE,MAAM,UAAU,EAAE,QAAQ,CAAC,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;CACpD,KAAK,MAAM,aAAa,QAAQ,MAAM;EACpC,MAAM,cACJ,EAAE,uBAAuB,MAAM,SAAS,KAAK,EAAE,yBAAyB,MAAM,SAAS,IACnF,UAAU,cACV;EAEN,IAAI,eAAe,EAAE,iBAAiB,MAAM,WAAW,KAAK,YAAY,IAAI,SAAS,YACnF,OAAO,CACL,YACA,YAAY,KAAK,KAAK,SAAS,WAAW,iBAAiB,QAAQ,YAAY,aAAa,CAAC,CAC/F;CAEJ;CACA,OAAO,CAAC,YAAY,CAAC,CAAC;AACxB;;AAGA,eAAe,eAAe,UAA+C;CAC3E,IAAI;EACF,OAAO,MAAM,SAAS,UAAU,MAAM;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AE,WAAW,MAAM,KAAK,QAAQ,GAAG,OAAO,KAAK,SAAS,SAAS;CAEtG,IAAI,EAAE,eAAe,MAAM,IAAI,KAAK,KAAK,kBAAkB,EAAE,iBAAiB,MAAM,KAAK,cAAc,GACrG,OAAO,YAAY,KAAK,eAAe,gBAAgB,aAAa;CAEtE,IAAI,EAAE,oBAAoB,MAAM,IAAI,GAAG,OAAO,YAAY,KAAK,gBAAgB,aAAa;CAC5F,OAAO;AACT;;AAGA,SAAS,mBAAmB,aAAyB,YAA6B;CAChF,IAAI,CAAC,EAAE,eAAe,MAAM,WAAW,KAAK,CAAC,EAAE,iBAAiB,MAAM,WAAW,GAAG,OAAO;CAC3F,OAAO,wBAAwB,aAAa,UAAU;AACxD;;AAGA,SAAS,wBAAwB,YAAwB,YAA6B;CAEpF,IAAI,EAAE,WAAW,MAAM,UAAU,GAAG,OAAO,WAAW,SAAS,WAAW,WAAW,SAAS;CAC9F,IAAI,EAAE,eAAe,MAAM,UAAU,GAAG,OAAO,wBAAwB,WAAW,QAAQ,UAAU;CAEpG,IAAI,EAAE,iBAAiB,MAAM,UAAU,KAAK,CAAC,WAAW,UACtD,OAAO,wBAAwB,WAAW,QAAQ,UAAU;CAE9D,OAAO;AACT"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_utils = require("./utils.cjs");
|
|
3
|
+
const require_logger = require("./logger.cjs");
|
|
4
|
+
const require_sortForeignKeys = require("./sortForeignKeys.cjs");
|
|
5
|
+
require("./index.cjs");
|
|
6
|
+
require("./EntityDbMetadata.cjs");
|
|
7
|
+
let fs = require("fs");
|
|
8
|
+
//#region src/foreignKeyOrdering.ts
|
|
9
|
+
async function maybeSetForeignKeyOrdering(config, entities) {
|
|
10
|
+
if (!entities.some((e) => e.nonDeferredFks.length > 0)) {
|
|
11
|
+
for (const entity of entities) entity.nonDeferredFkOrder = 0;
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const { notNullCycles } = require_sortForeignKeys.sortByNonDeferredForeignKeys(entities);
|
|
15
|
+
const { nonDeferredForeignKeys: setting = "warn" } = config;
|
|
16
|
+
const nonDeferredFks = entities.flatMap((e) => e.nonDeferredFks.map((m2o) => ({
|
|
17
|
+
entity: e,
|
|
18
|
+
m2o
|
|
19
|
+
})));
|
|
20
|
+
if (setting === "error" || setting === "warn") {
|
|
21
|
+
require_logger.logger[setting](`Found ${nonDeferredFks.length} foreign keys that are not DEFERRABLE/INITIALLY DEFERRED`);
|
|
22
|
+
for (const { entity, m2o } of nonDeferredFks) console.log(`${entity.tableName}.${m2o.columnName}`);
|
|
23
|
+
console.log("");
|
|
24
|
+
console.log("Please either:");
|
|
25
|
+
console.log(" - Alter your migration to create the FKs as deferred (ideal)");
|
|
26
|
+
console.log(" - Execute the generated alter-foreign-keys.sql file (one-time fix)");
|
|
27
|
+
console.log(" - Set 'nonDeferredFks: ignore' in joist-config.json");
|
|
28
|
+
console.log("");
|
|
29
|
+
console.log("See https://joist-orm.io/getting-started/schema-assumptions#deferred-constraints");
|
|
30
|
+
console.log("");
|
|
31
|
+
await writeAlterTables(nonDeferredFks);
|
|
32
|
+
} else if (setting === "ignore") {} else require_utils.assertNever(setting);
|
|
33
|
+
if (notNullCycles.length > 0) {
|
|
34
|
+
require_logger.logger.error(`Found a schema cycle of not-null foreign keys:`);
|
|
35
|
+
notNullCycles.forEach((cycle) => console.log(cycle));
|
|
36
|
+
console.log("");
|
|
37
|
+
console.log("These cycles can cause fatal em.flush & flush_test_database errors.");
|
|
38
|
+
console.log("");
|
|
39
|
+
console.log("Please make one of the FKs involved in the cycle nullable.");
|
|
40
|
+
console.log("");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async function writeAlterTables(nonDeferredFks) {
|
|
44
|
+
const queries = nonDeferredFks.map(({ entity, m2o }) => {
|
|
45
|
+
return `ALTER TABLE ${entity.tableName} ALTER CONSTRAINT ${m2o.constraintName} DEFERRABLE INITIALLY DEFERRED;`;
|
|
46
|
+
});
|
|
47
|
+
await fs.promises.writeFile("./alter-foreign-keys.sql", queries.join("\n"));
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
exports.maybeSetForeignKeyOrdering = maybeSetForeignKeyOrdering;
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=foreignKeyOrdering.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"foreignKeyOrdering.cjs","names":["sortByNonDeferredForeignKeys"],"sources":["../src/foreignKeyOrdering.ts"],"sourcesContent":["import { promises as fs } from \"fs\";\n\nimport { type ManyToOneField, type PolymorphicFieldComponent } from \"./EntityDbMetadata.ts\";\nimport { type Config, type EntityDbMetadata } from \"./index.ts\";\nimport { logger } from \"./logger.ts\";\nimport { sortByNonDeferredForeignKeys } from \"./sortForeignKeys.ts\";\nimport { assertNever } from \"./utils.ts\";\n\nexport async function maybeSetForeignKeyOrdering(config: Config, entities: EntityDbMetadata[]): Promise<void> {\n // Hopefully all FKs are deferred, but if not...\n const hasAnyNonDeferredFks = entities.some((e) => e.nonDeferredFks.length > 0);\n if (!hasAnyNonDeferredFks) {\n // Great, nothing to do\n for (const entity of entities) entity.nonDeferredFkOrder = 0;\n return;\n }\n\n // Topo sort the non-deferred FKs into a DAG to establish insert/flush order\n const { notNullCycles } = sortByNonDeferredForeignKeys(entities);\n\n const { nonDeferredForeignKeys: setting = \"warn\" } = config;\n const nonDeferredFks = entities.flatMap((e) => e.nonDeferredFks.map((m2o) => ({ entity: e, m2o })));\n\n if (setting === \"error\" || setting === \"warn\") {\n logger[setting](`Found ${nonDeferredFks.length} foreign keys that are not DEFERRABLE/INITIALLY DEFERRED`);\n for (const { entity, m2o } of nonDeferredFks) console.log(`${entity.tableName}.${m2o.columnName}`);\n console.log(\"\");\n\n console.log(\"Please either:\");\n console.log(\" - Alter your migration to create the FKs as deferred (ideal)\");\n console.log(\" - Execute the generated alter-foreign-keys.sql file (one-time fix)\");\n console.log(\" - Set 'nonDeferredFks: ignore' in joist-config.json\");\n console.log(\"\");\n\n console.log(\"See https://joist-orm.io/getting-started/schema-assumptions#deferred-constraints\");\n console.log(\"\");\n\n await writeAlterTables(nonDeferredFks);\n } else if (setting === \"ignore\") {\n // We trust the user to know what they're doing\n } else {\n assertNever(setting);\n }\n\n // Always treat these as errors, even if `ignore` is set; maybe we need a `ignore-even-not-null-cycles`?\n // But they would still probably break flush_test_database. Unless we tell it to disable constraints,\n // like `ALTER TABLE your_table_name DISABLE TRIGGER ALL;`. But still unsure how we'd insert new rows.\n if (notNullCycles.length > 0) {\n logger.error(`Found a schema cycle of not-null foreign keys:`);\n notNullCycles.forEach((cycle) => console.log(cycle));\n console.log(\"\");\n console.log(\"These cycles can cause fatal em.flush & flush_test_database errors.\");\n console.log(\"\");\n console.log(\"Please make one of the FKs involved in the cycle nullable.\");\n console.log(\"\");\n }\n}\n\nasync function writeAlterTables(\n nonDeferredFks: Array<{\n entity: EntityDbMetadata;\n m2o: ManyToOneField | PolymorphicFieldComponent;\n }>,\n): Promise<void> {\n const queries = nonDeferredFks.map(({ entity, m2o }) => {\n return `ALTER TABLE ${entity.tableName} ALTER CONSTRAINT ${m2o.constraintName} DEFERRABLE INITIALLY DEFERRED;`;\n });\n await fs.writeFile(\"./alter-foreign-keys.sql\", queries.join(\"\\n\"));\n}\n"],"mappings":";;;;;;;;AAQA,eAAsB,2BAA2B,QAAgB,UAA6C;CAG5G,IAAI,CADyB,SAAS,MAAM,MAAM,EAAE,eAAe,SAAS,CACpD,GAAG;EAEzB,KAAK,MAAM,UAAU,UAAU,OAAO,qBAAqB;EAC3D;CACF;CAGA,MAAM,EAAE,kBAAkBA,wBAAAA,6BAA6B,QAAQ;CAE/D,MAAM,EAAE,wBAAwB,UAAU,WAAW;CACrD,MAAM,iBAAiB,SAAS,SAAS,MAAM,EAAE,eAAe,KAAK,SAAS;EAAE,QAAQ;EAAG;CAAI,EAAE,CAAC;CAElG,IAAI,YAAY,WAAW,YAAY,QAAQ;EAC7C,eAAA,OAAO,QAAQ,CAAC,SAAS,eAAe,OAAO,yDAAyD;EACxG,KAAK,MAAM,EAAE,QAAQ,SAAS,gBAAgB,QAAQ,IAAI,GAAG,OAAO,UAAU,GAAG,IAAI,YAAY;EACjG,QAAQ,IAAI,EAAE;EAEd,QAAQ,IAAI,gBAAgB;EAC5B,QAAQ,IAAI,+DAA+D;EAC3E,QAAQ,IAAI,qEAAqE;EACjF,QAAQ,IAAI,sDAAsD;EAClE,QAAQ,IAAI,EAAE;EAEd,QAAQ,IAAI,kFAAkF;EAC9F,QAAQ,IAAI,EAAE;EAEd,MAAM,iBAAiB,cAAc;CACvC,OAAO,IAAI,YAAY,UAAU,CAEjC,OACE,cAAA,YAAY,OAAO;CAMrB,IAAI,cAAc,SAAS,GAAG;EAC5B,eAAA,OAAO,MAAM,gDAAgD;EAC7D,cAAc,SAAS,UAAU,QAAQ,IAAI,KAAK,CAAC;EACnD,QAAQ,IAAI,EAAE;EACd,QAAQ,IAAI,qEAAqE;EACjF,QAAQ,IAAI,EAAE;EACd,QAAQ,IAAI,4DAA4D;EACxE,QAAQ,IAAI,EAAE;CAChB;AACF;AAEA,eAAe,iBACb,gBAIe;CACf,MAAM,UAAU,eAAe,KAAK,EAAE,QAAQ,UAAU;EACtD,OAAO,eAAe,OAAO,UAAU,oBAAoB,IAAI,eAAe;CAChF,CAAC;CACD,MAAM,GAAA,SAAG,UAAU,4BAA4B,QAAQ,KAAK,IAAI,CAAC;AACnE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Config } from "./config.cjs";
|
|
2
|
+
import "./index.cjs";
|
|
3
|
+
import { EntityDbMetadata } from "./EntityDbMetadata.cjs";
|
|
4
|
+
//#region src/foreignKeyOrdering.d.ts
|
|
5
|
+
declare function maybeSetForeignKeyOrdering(config: Config, entities: EntityDbMetadata[]): Promise<void>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { maybeSetForeignKeyOrdering };
|
|
8
|
+
//# sourceMappingURL=foreignKeyOrdering.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"foreignKeyOrdering.d.cts","names":[],"sources":["../src/foreignKeyOrdering.ts"],"mappings":";;;;iBAQsB,2BAA2B,QAAQ,QAAQ,UAAU,qBAAqB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Config } from "./config.mjs";
|
|
2
|
+
import "./index.mjs";
|
|
3
|
+
import { EntityDbMetadata } from "./EntityDbMetadata.mjs";
|
|
4
|
+
//#region src/foreignKeyOrdering.d.ts
|
|
5
|
+
declare function maybeSetForeignKeyOrdering(config: Config, entities: EntityDbMetadata[]): Promise<void>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { maybeSetForeignKeyOrdering };
|
|
8
|
+
//# sourceMappingURL=foreignKeyOrdering.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"foreignKeyOrdering.d.mts","names":[],"sources":["../src/foreignKeyOrdering.ts"],"mappings":";;;;iBAQsB,2BAA2B,QAAQ,QAAQ,UAAU,qBAAqB"}
|
|
@@ -1,60 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { assertNever } from "./utils.js";
|
|
2
|
+
import { logger } from "./logger.js";
|
|
3
|
+
import { sortByNonDeferredForeignKeys } from "./sortForeignKeys.js";
|
|
4
|
+
import "./index.js";
|
|
5
|
+
import "./EntityDbMetadata.js";
|
|
6
|
+
import { promises } from "fs";
|
|
7
|
+
//#region src/foreignKeyOrdering.ts
|
|
8
8
|
async function maybeSetForeignKeyOrdering(config, entities) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
// Always treat these as errors, even if `ignore` is set; maybe we need a `ignore-even-not-null-cycles`?
|
|
42
|
-
// But they would still probably break flush_test_database. Unless we tell it to disable constraints,
|
|
43
|
-
// like `ALTER TABLE your_table_name DISABLE TRIGGER ALL;`. But still unsure how we'd insert new rows.
|
|
44
|
-
if (notNullCycles.length > 0) {
|
|
45
|
-
logger_1.logger.error(`Found a schema cycle of not-null foreign keys:`);
|
|
46
|
-
notNullCycles.forEach((cycle) => console.log(cycle));
|
|
47
|
-
console.log("");
|
|
48
|
-
console.log("These cycles can cause fatal em.flush & flush_test_database errors.");
|
|
49
|
-
console.log("");
|
|
50
|
-
console.log("Please make one of the FKs involved in the cycle nullable.");
|
|
51
|
-
console.log("");
|
|
52
|
-
}
|
|
9
|
+
if (!entities.some((e) => e.nonDeferredFks.length > 0)) {
|
|
10
|
+
for (const entity of entities) entity.nonDeferredFkOrder = 0;
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const { notNullCycles } = sortByNonDeferredForeignKeys(entities);
|
|
14
|
+
const { nonDeferredForeignKeys: setting = "warn" } = config;
|
|
15
|
+
const nonDeferredFks = entities.flatMap((e) => e.nonDeferredFks.map((m2o) => ({
|
|
16
|
+
entity: e,
|
|
17
|
+
m2o
|
|
18
|
+
})));
|
|
19
|
+
if (setting === "error" || setting === "warn") {
|
|
20
|
+
logger[setting](`Found ${nonDeferredFks.length} foreign keys that are not DEFERRABLE/INITIALLY DEFERRED`);
|
|
21
|
+
for (const { entity, m2o } of nonDeferredFks) console.log(`${entity.tableName}.${m2o.columnName}`);
|
|
22
|
+
console.log("");
|
|
23
|
+
console.log("Please either:");
|
|
24
|
+
console.log(" - Alter your migration to create the FKs as deferred (ideal)");
|
|
25
|
+
console.log(" - Execute the generated alter-foreign-keys.sql file (one-time fix)");
|
|
26
|
+
console.log(" - Set 'nonDeferredFks: ignore' in joist-config.json");
|
|
27
|
+
console.log("");
|
|
28
|
+
console.log("See https://joist-orm.io/getting-started/schema-assumptions#deferred-constraints");
|
|
29
|
+
console.log("");
|
|
30
|
+
await writeAlterTables(nonDeferredFks);
|
|
31
|
+
} else if (setting === "ignore") {} else assertNever(setting);
|
|
32
|
+
if (notNullCycles.length > 0) {
|
|
33
|
+
logger.error(`Found a schema cycle of not-null foreign keys:`);
|
|
34
|
+
notNullCycles.forEach((cycle) => console.log(cycle));
|
|
35
|
+
console.log("");
|
|
36
|
+
console.log("These cycles can cause fatal em.flush & flush_test_database errors.");
|
|
37
|
+
console.log("");
|
|
38
|
+
console.log("Please make one of the FKs involved in the cycle nullable.");
|
|
39
|
+
console.log("");
|
|
40
|
+
}
|
|
53
41
|
}
|
|
54
42
|
async function writeAlterTables(nonDeferredFks) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
43
|
+
const queries = nonDeferredFks.map(({ entity, m2o }) => {
|
|
44
|
+
return `ALTER TABLE ${entity.tableName} ALTER CONSTRAINT ${m2o.constraintName} DEFERRABLE INITIALLY DEFERRED;`;
|
|
45
|
+
});
|
|
46
|
+
await promises.writeFile("./alter-foreign-keys.sql", queries.join("\n"));
|
|
59
47
|
}
|
|
48
|
+
//#endregion
|
|
49
|
+
export { maybeSetForeignKeyOrdering };
|
|
50
|
+
|
|
60
51
|
//# sourceMappingURL=foreignKeyOrdering.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"foreignKeyOrdering.js","
|
|
1
|
+
{"version":3,"file":"foreignKeyOrdering.js","names":["fs"],"sources":["../src/foreignKeyOrdering.ts"],"sourcesContent":["import { promises as fs } from \"fs\";\n\nimport { type ManyToOneField, type PolymorphicFieldComponent } from \"./EntityDbMetadata.ts\";\nimport { type Config, type EntityDbMetadata } from \"./index.ts\";\nimport { logger } from \"./logger.ts\";\nimport { sortByNonDeferredForeignKeys } from \"./sortForeignKeys.ts\";\nimport { assertNever } from \"./utils.ts\";\n\nexport async function maybeSetForeignKeyOrdering(config: Config, entities: EntityDbMetadata[]): Promise<void> {\n // Hopefully all FKs are deferred, but if not...\n const hasAnyNonDeferredFks = entities.some((e) => e.nonDeferredFks.length > 0);\n if (!hasAnyNonDeferredFks) {\n // Great, nothing to do\n for (const entity of entities) entity.nonDeferredFkOrder = 0;\n return;\n }\n\n // Topo sort the non-deferred FKs into a DAG to establish insert/flush order\n const { notNullCycles } = sortByNonDeferredForeignKeys(entities);\n\n const { nonDeferredForeignKeys: setting = \"warn\" } = config;\n const nonDeferredFks = entities.flatMap((e) => e.nonDeferredFks.map((m2o) => ({ entity: e, m2o })));\n\n if (setting === \"error\" || setting === \"warn\") {\n logger[setting](`Found ${nonDeferredFks.length} foreign keys that are not DEFERRABLE/INITIALLY DEFERRED`);\n for (const { entity, m2o } of nonDeferredFks) console.log(`${entity.tableName}.${m2o.columnName}`);\n console.log(\"\");\n\n console.log(\"Please either:\");\n console.log(\" - Alter your migration to create the FKs as deferred (ideal)\");\n console.log(\" - Execute the generated alter-foreign-keys.sql file (one-time fix)\");\n console.log(\" - Set 'nonDeferredFks: ignore' in joist-config.json\");\n console.log(\"\");\n\n console.log(\"See https://joist-orm.io/getting-started/schema-assumptions#deferred-constraints\");\n console.log(\"\");\n\n await writeAlterTables(nonDeferredFks);\n } else if (setting === \"ignore\") {\n // We trust the user to know what they're doing\n } else {\n assertNever(setting);\n }\n\n // Always treat these as errors, even if `ignore` is set; maybe we need a `ignore-even-not-null-cycles`?\n // But they would still probably break flush_test_database. Unless we tell it to disable constraints,\n // like `ALTER TABLE your_table_name DISABLE TRIGGER ALL;`. But still unsure how we'd insert new rows.\n if (notNullCycles.length > 0) {\n logger.error(`Found a schema cycle of not-null foreign keys:`);\n notNullCycles.forEach((cycle) => console.log(cycle));\n console.log(\"\");\n console.log(\"These cycles can cause fatal em.flush & flush_test_database errors.\");\n console.log(\"\");\n console.log(\"Please make one of the FKs involved in the cycle nullable.\");\n console.log(\"\");\n }\n}\n\nasync function writeAlterTables(\n nonDeferredFks: Array<{\n entity: EntityDbMetadata;\n m2o: ManyToOneField | PolymorphicFieldComponent;\n }>,\n): Promise<void> {\n const queries = nonDeferredFks.map(({ entity, m2o }) => {\n return `ALTER TABLE ${entity.tableName} ALTER CONSTRAINT ${m2o.constraintName} DEFERRABLE INITIALLY DEFERRED;`;\n });\n await fs.writeFile(\"./alter-foreign-keys.sql\", queries.join(\"\\n\"));\n}\n"],"mappings":";;;;;;;AAQA,eAAsB,2BAA2B,QAAgB,UAA6C;CAG5G,IAAI,CADyB,SAAS,MAAM,MAAM,EAAE,eAAe,SAAS,CACpD,GAAG;EAEzB,KAAK,MAAM,UAAU,UAAU,OAAO,qBAAqB;EAC3D;CACF;CAGA,MAAM,EAAE,kBAAkB,6BAA6B,QAAQ;CAE/D,MAAM,EAAE,wBAAwB,UAAU,WAAW;CACrD,MAAM,iBAAiB,SAAS,SAAS,MAAM,EAAE,eAAe,KAAK,SAAS;EAAE,QAAQ;EAAG;CAAI,EAAE,CAAC;CAElG,IAAI,YAAY,WAAW,YAAY,QAAQ;EAC7C,OAAO,QAAQ,CAAC,SAAS,eAAe,OAAO,yDAAyD;EACxG,KAAK,MAAM,EAAE,QAAQ,SAAS,gBAAgB,QAAQ,IAAI,GAAG,OAAO,UAAU,GAAG,IAAI,YAAY;EACjG,QAAQ,IAAI,EAAE;EAEd,QAAQ,IAAI,gBAAgB;EAC5B,QAAQ,IAAI,+DAA+D;EAC3E,QAAQ,IAAI,qEAAqE;EACjF,QAAQ,IAAI,sDAAsD;EAClE,QAAQ,IAAI,EAAE;EAEd,QAAQ,IAAI,kFAAkF;EAC9F,QAAQ,IAAI,EAAE;EAEd,MAA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