joist-codegen 2.3.0-next.8 → 2.3.0-next.81
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 +241 -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 +221 -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 +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
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: joist-partial-updates
|
|
3
|
+
description: Joist ORM partial updates, em.upsert, setPartial, nested collection op semantics, and GraphQL/REST/gRPC save inputs. Use when designing, implementing, reviewing, or debugging Joist partial-update or save-input APIs, especially parent-child graphs, id-less nested rows, required-parent validation errors, or accidental collection removal.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Joist Partial Update APIs
|
|
7
|
+
|
|
8
|
+
Use Joist's native partial-update contract from the transport through to `EntityManager.upsert` or `Entity.setPartial`. Do not load an existing graph and write custom reconciliation code when IDs and Joist collection operations can express the update.
|
|
9
|
+
|
|
10
|
+
Authoritative documentation: <https://joist-orm.io/features/partial-update-apis/>
|
|
11
|
+
|
|
12
|
+
## Non-Negotiable Rules
|
|
13
|
+
|
|
14
|
+
1. Preserve entity IDs across read, edit, and write boundaries.
|
|
15
|
+
2. Decide whether every supplied collection is exhaustive or incremental before writing the payload.
|
|
16
|
+
3. Omit a field to leave it unchanged. Do not replace omission with `null`, `[]`, or a generated default.
|
|
17
|
+
4. A collection array is exhaustive by default. Omitted existing children are removed from the relation.
|
|
18
|
+
5. A collection becomes incremental when its child objects use `op`.
|
|
19
|
+
6. If any child has `op`, every child in that collection must have `op`, including newly created children.
|
|
20
|
+
7. An empty array is always exhaustive and clears the collection. It never means "no changes."
|
|
21
|
+
8. Use `{ op: "incremental" }` only as a no-op sentinel when the collection key must be present. Prefer omitting the collection key.
|
|
22
|
+
9. Use `include`, `delete`, and `remove` according to their actual relationship semantics.
|
|
23
|
+
10. Test updates against an already-persisted graph and flush the unit of work. Mapper-only tests cannot catch detached required children.
|
|
24
|
+
11. Authorize every supplied ID and operation. Joist enforces persistence rules, not API permissions or tenant boundaries.
|
|
25
|
+
|
|
26
|
+
## Partial Field Semantics
|
|
27
|
+
|
|
28
|
+
Joist distinguishes omission, `undefined`, and `null`:
|
|
29
|
+
|
|
30
|
+
| Input | Scalar or relation behavior | Collection behavior |
|
|
31
|
+
| --- | --- | --- |
|
|
32
|
+
| Omitted | Leave unchanged | Leave unchanged |
|
|
33
|
+
| `undefined` | Leave unchanged | Leave unchanged |
|
|
34
|
+
| `null` | Unset optional value; required value fails validation | Clear the collection |
|
|
35
|
+
| Value or array | Set/update | Exhaustively replace unless `op` enables incremental behavior |
|
|
36
|
+
|
|
37
|
+
Do not globally normalize `null` to `undefined`. That destroys the caller's ability to explicitly unset an optional field. Adapt only fields whose transport representation differs from the entity graph.
|
|
38
|
+
|
|
39
|
+
Transport-specific presence rules:
|
|
40
|
+
|
|
41
|
+
- GraphQL: preserve the difference between an omitted input field and an explicit `null`. Codegen commonly produces `T | null | undefined`; this is what `DeepPartialOrNull` and the partial APIs are designed to accept.
|
|
42
|
+
- REST/JSON: omission means no change; JSON has no `undefined`, so do not synthesize absent keys while decoding or mapping.
|
|
43
|
+
- gRPC/Protobuf: scalar presence can use `optional`, wrappers, or `oneof`, but ordinary repeated fields do not distinguish omitted from empty. Wrap repeated fields in a present message, use a `oneof`, or use a field mask so "unchanged" cannot decode to `[]`.
|
|
44
|
+
|
|
45
|
+
## Choose the Collection Contract
|
|
46
|
+
|
|
47
|
+
### Exhaustive Replacement
|
|
48
|
+
|
|
49
|
+
Use an exhaustive collection only when the caller intentionally sends the complete desired membership:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
await em.upsert(Author, {
|
|
53
|
+
id: "a:1",
|
|
54
|
+
books: [
|
|
55
|
+
{ id: "b:1", title: "Retained and updated" },
|
|
56
|
+
{ title: "New book" },
|
|
57
|
+
],
|
|
58
|
+
});
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
This removes every omitted existing book from `author.books`. It does not imply hard deletion. If the inverse relation is required, detaching an omitted child can produce validation errors such as `Book author is required`.
|
|
62
|
+
|
|
63
|
+
Do not use exhaustive replacement when:
|
|
64
|
+
|
|
65
|
+
- The client does not know every existing child.
|
|
66
|
+
- The UI discarded child IDs.
|
|
67
|
+
- Omitted children should remain untouched.
|
|
68
|
+
- Removed children must be hard-deleted rather than merely detached.
|
|
69
|
+
|
|
70
|
+
### Incremental Update
|
|
71
|
+
|
|
72
|
+
Use incremental operations when the request describes additions, updates, removals, or deletions without replacing the whole collection:
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
await em.upsert(Author, {
|
|
76
|
+
id: "a:1",
|
|
77
|
+
books: [
|
|
78
|
+
{ id: "b:1", op: "include", title: "Updated title" },
|
|
79
|
+
{ op: "include", title: "New book" },
|
|
80
|
+
{ id: "b:2", op: "delete" },
|
|
81
|
+
],
|
|
82
|
+
});
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Operation meanings:
|
|
86
|
+
|
|
87
|
+
| Operation | Behavior |
|
|
88
|
+
| --- | --- |
|
|
89
|
+
| `include` | Create or update the child, and ensure it belongs to the collection |
|
|
90
|
+
| `delete` | Remove the child from the collection and call `EntityManager.delete` |
|
|
91
|
+
| `remove` | Detach the child without deleting it |
|
|
92
|
+
| `incremental` | No-op sentinel that enables incremental semantics for an otherwise empty list |
|
|
93
|
+
|
|
94
|
+
Use `remove` only when the child can validly exist without this parent or is being reparented in the same unit of work. For a required parent relation, `remove` alone usually creates an invalid entity. Use `delete` when the child should cease to exist.
|
|
95
|
+
|
|
96
|
+
An actual empty array still clears:
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
await em.upsert(Author, { id: "a:1", books: [] });
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
For an incremental no-op, prefer:
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
await em.upsert(Author, { id: "a:1" });
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
If a generic payload builder must emit `books`, use:
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
await em.upsert(Author, {
|
|
112
|
+
id: "a:1",
|
|
113
|
+
books: [{ op: "incremental" }],
|
|
114
|
+
});
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Stable Identity End to End
|
|
118
|
+
|
|
119
|
+
IDs are the reliable identity contract for active nested updates. A nested object without an ID is normally a request to create a new entity.
|
|
120
|
+
|
|
121
|
+
For an editable parent-child graph:
|
|
122
|
+
|
|
123
|
+
1. Query IDs for the parent and every editable nested entity.
|
|
124
|
+
2. Include those IDs in API response types.
|
|
125
|
+
3. Store IDs in form or draft state.
|
|
126
|
+
4. Send retained rows as `{ id, op: "include", ...changes }`.
|
|
127
|
+
5. Mark deleted persisted rows in place by switching their `op` to `delete` (or `remove`); keep them in the same array rather than moving their IDs to a separate deletion list.
|
|
128
|
+
6. Send new rows without an ID but with `op: "include"`.
|
|
129
|
+
7. Keep the same discipline recursively for grandchildren.
|
|
130
|
+
|
|
131
|
+
A robust UI row model carries `op` on the row itself, so a deleted book flips to `op: "delete"`/`"remove"` in place instead of moving to a separate collection:
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
interface EditableBook {
|
|
135
|
+
id?: string;
|
|
136
|
+
op?: "include" | "remove" | "delete";
|
|
137
|
+
title: string;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
interface AuthorDraft {
|
|
141
|
+
books: EditableBook[];
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Because each row already mirrors `SaveBookInput` (`id`, `op`, scalars), the draft state can go directly onto the wire as the GraphQL input, with no separate deletion list to reconcile back in. Keep the collection incremental (every row has `op`) once any row does.
|
|
146
|
+
|
|
147
|
+
Do not key editable rows only by array index. Reordering or deleting an earlier row can assign an existing ID to the wrong logical row. Prefer structured row state with stable IDs. If a textarea represents multiple database rows, either maintain line identity explicitly or document why positional identity is safe for that domain.
|
|
148
|
+
|
|
149
|
+
Do not infer identity from `sortOrder`, names, unique constraints, or array position. Joist may use configured uniqueness for specific upsert cases such as soft-deleted rows, but do not assume `uniqueBy` will match active id-less children. Send the ID unless the current Joist behavior is intentionally relied on and covered by an integration test.
|
|
150
|
+
|
|
151
|
+
## GraphQL Shape
|
|
152
|
+
|
|
153
|
+
Make GraphQL inputs mirror Joist's native graph shape:
|
|
154
|
+
|
|
155
|
+
```graphql
|
|
156
|
+
enum UpsertOp {
|
|
157
|
+
include
|
|
158
|
+
remove
|
|
159
|
+
delete
|
|
160
|
+
incremental
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
input SaveAuthorInput {
|
|
164
|
+
id: ID
|
|
165
|
+
firstName: String
|
|
166
|
+
books: [SaveBookInput!]
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
input SaveBookInput {
|
|
170
|
+
id: ID
|
|
171
|
+
op: UpsertOp
|
|
172
|
+
title: String
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
The corresponding output query must expose nested IDs:
|
|
177
|
+
|
|
178
|
+
```graphql
|
|
179
|
+
query EditAuthor($id: ID!) {
|
|
180
|
+
author(id: $id) {
|
|
181
|
+
id
|
|
182
|
+
firstName
|
|
183
|
+
books {
|
|
184
|
+
id
|
|
185
|
+
title
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Keep the resolver thin when the schema already matches the entity graph:
|
|
192
|
+
|
|
193
|
+
```ts
|
|
194
|
+
import { type DeepPartialOrNull } from "joist-orm";
|
|
195
|
+
|
|
196
|
+
async function saveAuthor(input: SaveAuthorInput, em: EntityManager): Promise<Author> {
|
|
197
|
+
return em.upsert(Author, input as DeepPartialOrNull<Author>);
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
The cast is appropriate only after checking that relation names, IDs, scalar fields, and nested collection operations align with Joist's expected graph. A cast does not make an incompatible payload safe.
|
|
202
|
+
|
|
203
|
+
Thin does not mean unchecked. Before calling `upsert`, authorize the parent and every nested ID for the caller's tenant/scope, and validate that each requested attach, reparent, remove, or delete operation is allowed. This security validation is separate from persistence reconciliation.
|
|
204
|
+
|
|
205
|
+
If the API also accepts convenience fields, such as a textarea that expands into child rows, use a small boundary mapper:
|
|
206
|
+
|
|
207
|
+
```ts
|
|
208
|
+
type SaveAuthorConvenienceInput = SaveAuthorInput & { booksText?: string | null };
|
|
209
|
+
|
|
210
|
+
function toAuthorUpsertInput(input: SaveAuthorConvenienceInput): DeepPartialOrNull<Author> {
|
|
211
|
+
return {
|
|
212
|
+
id: input.id,
|
|
213
|
+
firstName: input.firstName,
|
|
214
|
+
books: mapBooks(input),
|
|
215
|
+
} as DeepPartialOrNull<Author>;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function mapBooks(input: SaveAuthorConvenienceInput) {
|
|
219
|
+
if (input.books !== undefined) return input.books;
|
|
220
|
+
if (input.booksText === undefined) return undefined;
|
|
221
|
+
return parseLegacyBooks(input.booksText ?? "");
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
The mapper should transform representation, not reconcile persistence. It must preserve `books: null` as an explicit clear and preserve omission as `undefined`; do not use `??` when `null` and omission have different meanings.
|
|
226
|
+
|
|
227
|
+
## REST and gRPC Shapes
|
|
228
|
+
|
|
229
|
+
Use the same graph contract regardless of transport. For example, a REST PATCH body can be:
|
|
230
|
+
|
|
231
|
+
```json
|
|
232
|
+
{
|
|
233
|
+
"id": "a:1",
|
|
234
|
+
"books": [
|
|
235
|
+
{ "id": "b:1", "op": "include", "title": "Updated title" },
|
|
236
|
+
{ "id": "b:2", "op": "delete" }
|
|
237
|
+
]
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
A gRPC message should model the same operations with an enum and explicit collection presence. A plain `repeated SaveBookInput books` field is unsafe for a partial update because its decoded empty list cannot distinguish "omitted" from "clear." Use a wrapper message inside a `oneof`, or an equivalent field-mask convention:
|
|
242
|
+
|
|
243
|
+
```proto
|
|
244
|
+
message BookChanges {
|
|
245
|
+
repeated SaveBookInput values = 1;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
message SaveAuthorRequest {
|
|
249
|
+
optional string id = 1;
|
|
250
|
+
oneof books_update {
|
|
251
|
+
BookChanges books = 2;
|
|
252
|
+
bool clear_books = 3;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
An unset `books_update` means unchanged; a present `books` wrapper carries incremental or exhaustive values; `clear_books: true` explicitly clears. Convert generated enum values to Joist's lowercase strings at the boundary if necessary.
|
|
258
|
+
|
|
259
|
+
Do not invent transport-specific reconciliation semantics. GraphQL, REST, and gRPC should all produce the same `DeepPartialOrNull<Entity>` graph before calling Joist.
|
|
260
|
+
|
|
261
|
+
## Implementation Workflow
|
|
262
|
+
|
|
263
|
+
1. Read the entity metadata and identify required inverse relations and delete behavior.
|
|
264
|
+
2. Trace the complete read-edit-write path, not only the resolver.
|
|
265
|
+
3. Verify every editable output type and query includes stable nested IDs.
|
|
266
|
+
4. Verify client state retains those IDs after parsing, normalization, and form edits.
|
|
267
|
+
5. Choose exhaustive or incremental semantics independently for every nested collection.
|
|
268
|
+
6. Make transport inputs match Joist's graph and expose `op` where incremental updates are needed.
|
|
269
|
+
7. Add only the smallest representation mapper required by the transport.
|
|
270
|
+
8. Call `em.upsert`, `entity.setPartial`, or a thin shared helper that delegates to them.
|
|
271
|
+
9. Flush in an integration test and assert identity, membership, deletion, and untouched fields.
|
|
272
|
+
|
|
273
|
+
## Failure Signatures
|
|
274
|
+
|
|
275
|
+
### `<Child> <parent> is required` after updating a parent
|
|
276
|
+
|
|
277
|
+
Likely cause: an id-less or incomplete child array was interpreted as exhaustive replacement. Joist created new children and detached omitted persisted children, whose required parent relation then failed validation.
|
|
278
|
+
|
|
279
|
+
Fix: preserve child IDs and either send the complete exhaustive graph or use `op: "include"`/`"delete"` incrementally.
|
|
280
|
+
|
|
281
|
+
### Duplicate children after each save
|
|
282
|
+
|
|
283
|
+
Likely cause: existing child IDs are missing from the write payload, so each row is treated as new.
|
|
284
|
+
|
|
285
|
+
Fix: query, retain, and resend IDs. Do not match by sort order or content on the server.
|
|
286
|
+
|
|
287
|
+
### All children disappear on a no-change save
|
|
288
|
+
|
|
289
|
+
Likely cause: a payload builder emitted `children: []`, which is an exhaustive clear.
|
|
290
|
+
|
|
291
|
+
Fix: omit `children`, or emit `[{ op: "incremental" }]` only if the key is mandatory.
|
|
292
|
+
|
|
293
|
+
### Incremental update is rejected or behaves exhaustively
|
|
294
|
+
|
|
295
|
+
Likely cause: only some children have `op`.
|
|
296
|
+
|
|
297
|
+
Fix: give every child in that collection an operation, including new children.
|
|
298
|
+
|
|
299
|
+
### GraphQL input does not type-check against Joist
|
|
300
|
+
|
|
301
|
+
Likely cause: generated nullable input types do not directly match strict entity setters, or the API has convenience fields not present on the entity.
|
|
302
|
+
|
|
303
|
+
Fix: target `DeepPartialOrNull<Entity>` and use a narrow boundary mapper. Do not weaken unrelated types or write a persistence reconciliation layer.
|
|
304
|
+
|
|
305
|
+
## Anti-Patterns
|
|
306
|
+
|
|
307
|
+
Never solve a partial-update mismatch by defaulting to these approaches:
|
|
308
|
+
|
|
309
|
+
- Loading all existing children in the resolver to assign IDs by array position.
|
|
310
|
+
- Diffing old and new child arrays manually.
|
|
311
|
+
- Appending custom delete markers after comparing database state.
|
|
312
|
+
- Matching active children by `sortOrder`, name, or another mutable field.
|
|
313
|
+
- Assuming a database unique constraint supplies identity to an id-less upsert.
|
|
314
|
+
- Dropping nested IDs from API output, DTOs, parsers, or form state.
|
|
315
|
+
- Mapping an omitted collection to `[]`.
|
|
316
|
+
- Mixing children with and without `op` in one collection.
|
|
317
|
+
- Using `remove` for a child whose parent relation is required.
|
|
318
|
+
- Treating an empty array as an incremental no-op.
|
|
319
|
+
- Converting every GraphQL `null` to `undefined`.
|
|
320
|
+
- Adding backward-compatibility reconciliation without a concrete shipped caller that requires it.
|
|
321
|
+
|
|
322
|
+
Custom reconciliation is justified only when the API contract fundamentally cannot carry stable identity or Joist operations, and changing that contract is impossible. Document that constraint before adding such code.
|
|
323
|
+
|
|
324
|
+
## Regression Tests
|
|
325
|
+
|
|
326
|
+
For a nested update bug, build a persisted graph before invoking the real API boundary:
|
|
327
|
+
|
|
328
|
+
1. Create a parent with at least three children.
|
|
329
|
+
2. Give one child at least two grandchildren.
|
|
330
|
+
3. Update retained entities using their IDs and `op: "include"`.
|
|
331
|
+
4. Add one new id-less entity with `op: "include"`.
|
|
332
|
+
5. Delete one persisted entity with `op: "delete"`.
|
|
333
|
+
6. Omit another relation and prove it remains unchanged.
|
|
334
|
+
7. Flush and reload.
|
|
335
|
+
8. Assert retained IDs are unchanged, new IDs were created, deleted entities are gone, and no duplicates exist.
|
|
336
|
+
|
|
337
|
+
Do not re-test `em.upsert`'s own collection semantics (omitted vs `[]` vs `[{ op: "incremental" }]`, `remove` vs `delete`, mixed-`op` rejection) — Joist owns and tests those. Test what is yours: that nested IDs and operations survive the transport boundary and reach the resolver. Do not stop at payload snapshots; the original class of failure often appears only during validation or flush.
|
|
338
|
+
|
|
339
|
+
## Review Checklist
|
|
340
|
+
|
|
341
|
+
- Are IDs selected for every editable nested entity?
|
|
342
|
+
- Are IDs retained in client or caller state?
|
|
343
|
+
- Does each supplied collection intentionally use exhaustive or incremental semantics?
|
|
344
|
+
- If incremental, does every child have `op`?
|
|
345
|
+
- Are new children marked `include`?
|
|
346
|
+
- Are deleted persisted IDs sent as `delete`?
|
|
347
|
+
- Is `remove` valid for the inverse relation's nullability?
|
|
348
|
+
- Can any no-change path emit `[]` accidentally?
|
|
349
|
+
- Are omitted fields preserved as omitted or `undefined`?
|
|
350
|
+
- Are explicit `null` values preserved where they mean unset?
|
|
351
|
+
- Is the resolver a thin `upsert`/`setPartial` boundary instead of a reconciliation engine?
|
|
352
|
+
- Does an integration test update a persisted graph and verify stable IDs after flush?
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: joist-reactive-hint
|
|
3
|
+
description: Explains how Joist reactive hints work and what they cost to run — a hint is both a reverse-reactivity trigger (which roots re-run when a hinted field changes) and a forward load hint (what gets populated before the lambda runs), so a rule can pull an entire child collection into memory even when its lambda only reads a parent field. Covers followReverseHint, the two rule shapes (child-rooted reacting up to a parent vs parent-rooted reacting down into a child collection), and how to avoid surprise O(children) loads. Use when reasoning about the performance of a reactive rule/field/property (addRule, hasReactiveField, hasReactiveProperty, hasReactiveReference), when a validation rule seems to load far more rows than expected, when deciding whether to put a field in a reactive hint vs load it on-demand, or when a hot-path mutation (e.g. a bulk job) triggers surprise N×M loads. Keywords: reactive hint, load hint, reverse reactivity, followReverseHint, reverseSubHint, m2o vs o2m reactivity, over-invalidation, populate, "a parent rule that hints a child collection loads the whole collection".
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Joist reactive hints
|
|
7
|
+
|
|
8
|
+
Reactive hints declare the fields a rule, `ReactiveField`, `ReactiveProperty`, or `ReactiveReference`
|
|
9
|
+
depends on. A hint does **double duty**: Joist walks it in **reverse** to find *which* roots to re-run
|
|
10
|
+
when a hinted field changes, then uses it **forward as a load hint** to populate that data on each root
|
|
11
|
+
before the lambda runs. Most hints are cheap — but either direction can pull an entire child collection
|
|
12
|
+
into memory, and the *forward* load is the surprising one, so both are the focus below.
|
|
13
|
+
|
|
14
|
+
## TL;DR
|
|
15
|
+
|
|
16
|
+
A reactive rule/field is declared on a **root entity** with a hint. There are two shapes, and they
|
|
17
|
+
cost very differently.
|
|
18
|
+
|
|
19
|
+
**Shape #1 — rule on the child, hint reaches *up* to the parent** (e.g. a rule on `Book` with
|
|
20
|
+
`{ author: ["currentDraftBook"] }`). When `Author.currentDraftBook` changes, Joist walks the hint in
|
|
21
|
+
reverse (`followReverseHint`), reversing the `Book.author` m2o into the `Author.books` o2m and
|
|
22
|
+
**loading the whole collection** to enumerate the child roots, then re-runs each book's rule.
|
|
23
|
+
`O(children)` per parent-field change. This is **intuitive**: "change the author, and all of its books
|
|
24
|
+
re-check."
|
|
25
|
+
|
|
26
|
+
**Shape #2 — rule on the parent, hint reaches *down* into a child collection** (e.g. a rule on `Author`
|
|
27
|
+
with `{ books: ["title"] }`). When a single `Book.title` changes, the reverse walk is **cheap** — one
|
|
28
|
+
`book.author` m2o hop to the one author. But the reactive hint is **also a load hint**: before running
|
|
29
|
+
the author's lambda, Joist populates `author.books`, pulling the **entire** collection into memory —
|
|
30
|
+
*even if the lambda only reads `author.status` and never touches the books*.
|
|
31
|
+
|
|
32
|
+
> The surprising one is **Shape #2**. `{ books: ["title"] }` reads like "react to book titles," but it
|
|
33
|
+
> *also* means "load all of this author's books every time this rule fires." A lambda whose body is just
|
|
34
|
+
> `return a.status === "active" ? undefined : "…"` still pays to load `author.books`, because the
|
|
35
|
+
> **hint, not the lambda body, decides what gets loaded**.
|
|
36
|
+
|
|
37
|
+
Neither shows up in tests (behavior is correct; only throughput/memory suffer). Both bite bulk/hot-path
|
|
38
|
+
jobs at scale — Shape #2 especially, because it looks cheap from the reverse-reactivity side.
|
|
39
|
+
|
|
40
|
+
## Why: reverse reactivity *and* load hints
|
|
41
|
+
|
|
42
|
+
A hinted-field change triggers two steps, both in `joist-core/build/reactiveHints.js`:
|
|
43
|
+
|
|
44
|
+
**Step 1 — find the roots (reverse walk).** `followReverseHint` starts at the changed entity and walks
|
|
45
|
+
the hint in reverse, reversing each *traversed relation* (via `reverseSubHint`):
|
|
46
|
+
|
|
47
|
+
- Reverse of an **m2o** (`Book.author`) is the **o2m** (`Author.books`) — so a **child-rooted** rule
|
|
48
|
+
reacting to a parent field loads the whole sibling collection just to list the roots (Shape #1).
|
|
49
|
+
- Reverse of an **o2m** (`Author.books`) is the **m2o** (`Book.author`) — so a **parent-rooted** rule
|
|
50
|
+
reacting to a child field finds exactly one root per changed child (Shape #2's reverse is cheap).
|
|
51
|
+
- A **leaf field** (primitive / enum / m2o read as a value, e.g. `["title"]`, `["currentDraftBook"]`) is
|
|
52
|
+
only a "react to this field changing" trigger; it is **not** traversed into.
|
|
53
|
+
|
|
54
|
+
**Step 2 — load the hint (forward populate).** Before running each root's lambda, Joist populates the
|
|
55
|
+
reactive hint *as a load hint* on that root so the lambda can read it synchronously. For a parent-rooted
|
|
56
|
+
rule with `{ books: [...] }`, that is effectively `author.populate("books")` — the **full collection** —
|
|
57
|
+
**regardless of what the lambda actually reads**. This is why Shape #2 is expensive even though its
|
|
58
|
+
reverse walk touched only one author: the cost is in the forward load, not the reverse walk.
|
|
59
|
+
|
|
60
|
+
So `{ author: ["currentDraftBook"] }` on `Book` compiles to a reactive target
|
|
61
|
+
`{ entity: Author, fields: ["currentDraftBook"], path: ["books"] }` — "when `Author.currentDraftBook`
|
|
62
|
+
changes, load `Author.books` and re-validate each" — while `{ books: ["title"] }` on `Author` loads
|
|
63
|
+
`author.books` on every fire so the rule can run at all. Either way Joist over-invalidates for
|
|
64
|
+
correctness: every sibling is re-checked/loaded even when only one could change the outcome.
|
|
65
|
+
|
|
66
|
+
## The old/new-value shortcut — and when it does NOT apply
|
|
67
|
+
|
|
68
|
+
`followReverseHint` has a reference-history optimization (`getInstanceData(c).getReferenceHistory`)
|
|
69
|
+
that pulls in **old + new** values — but only when the **step being walked is itself an m2o/poly**
|
|
70
|
+
(the "`Book.author` moved to a new `Author`" reparent case). It exists so a reparent re-validates
|
|
71
|
+
both the old and new parent.
|
|
72
|
+
|
|
73
|
+
It does **not** turn a child→`parent.field` reaction into a cheap old/new lookup: there, the walked
|
|
74
|
+
step is the `books` **o2m**, so Joist takes the `relation.load()` (full-collection) branch. The
|
|
75
|
+
`currentDraftBook` field's own m2o-ness is irrelevant — it's reacted to *as a field*, not *traversed*.
|
|
76
|
+
|
|
77
|
+
Rule of thumb for the cost of one changed field:
|
|
78
|
+
- reverse step is an **o2m/o2o** (you're on the child, parent-field changed) → **loads the full
|
|
79
|
+
sibling collection**.
|
|
80
|
+
- reverse step is an **m2o/poly** being reparented → loads a couple entities (current + history).
|
|
81
|
+
|
|
82
|
+
## How to spot / avoid it
|
|
83
|
+
|
|
84
|
+
- **The hint decides the load, not the lambda body.** A parent rule with `{ books: [...] }` loads
|
|
85
|
+
*every* book on *every* fire, even if the lambda only reads the parent's own fields. If the rule does
|
|
86
|
+
not actually need the collection, do not hint it; if it does, know you are paying `O(children)` memory
|
|
87
|
+
per fire.
|
|
88
|
+
- **For SQL-derived fields, split the hint with `hasAsyncReactiveField`.** It takes two hints — a
|
|
89
|
+
`loadHint`, whose data is populated into memory and passed to the lambda, and a `reactiveHint`, whose
|
|
90
|
+
data only *triggers* recalculation but is **not** loaded into memory (the lambda recomputes from SQL
|
|
91
|
+
instead). Put the large child collections you merely need to react to in the `reactiveHint` so a
|
|
92
|
+
child-field change still recomputes the value without pulling every sibling into memory.
|
|
93
|
+
- **Root the rule where the frequently-changing field lives.** A rule on `Book` reacting to
|
|
94
|
+
`author.currentDraftBook` reloads all siblings; the same check rooted on `Author` reacting to its
|
|
95
|
+
own `["currentDraftBook"]` needs no reverse collection-load (but then detecting anything about the
|
|
96
|
+
*children* forces you to scan them anyway — so this only helps if the check is about the parent).
|
|
97
|
+
- **Only react to fields that change rarely.** Put a field in the reactive hint only if you truly
|
|
98
|
+
need to re-run when it changes. If you just need to *read* a value, `await rel.load()` it on
|
|
99
|
+
demand inside the rule and leave it out of the hint. Reserve the hint for the rare-change trigger
|
|
100
|
+
that actually needs to fire the rule.
|
|
101
|
+
- **Watch bulk/hot-path mutations.** If a job sets some `parent.fk` once per child (e.g. a bulk
|
|
102
|
+
copy job setting `author.currentDraftBook` per book), any child-rooted rule reacting to that fk
|
|
103
|
+
reloads every child's siblings — the same `O(children × siblings)` you'd get from an explicit
|
|
104
|
+
`parent.children.load()` in the loop.
|
|
105
|
+
|
|
106
|
+
## Worked examples
|
|
107
|
+
|
|
108
|
+
### Shape #2 — the surprising one: a parent rule hinting into a child collection
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
// ❌ Rooted on Author. The hint `{ books: ["title"] }` reads like "react to book titles" — but it is
|
|
112
|
+
// ALSO a load hint, so every time ANY book's title changes, Joist loads the author's ENTIRE `books`
|
|
113
|
+
// collection into memory to run this rule, even though the lambda only looks at the author's status.
|
|
114
|
+
authorConfig.addRule(["status", { books: ["title"] }], (a) => {
|
|
115
|
+
return a.status === "active" ? undefined : "inactive authors need review";
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// ✅ The rule only depends on the author's own status, so hint only that — no books are loaded.
|
|
119
|
+
authorConfig.addRule("status", (a) => {
|
|
120
|
+
return a.status === "active" ? undefined : "inactive authors need review";
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
If the rule genuinely must react to a child field, keep the hint — but know each fire loads the whole
|
|
125
|
+
collection, so reserve it for collections the lambda actually reads and for child fields that change
|
|
126
|
+
rarely.
|
|
127
|
+
|
|
128
|
+
### Shape #1 — intuitive but still O(children): a child rule reacting to a parent field
|
|
129
|
+
|
|
130
|
+
Invariant wanted: "an unpublished book must be one of its author's tracked books — its `favoriteBook` or
|
|
131
|
+
`currentDraftBook`."
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
// ❌ Simple but O(books × siblings) on the bulk copy-job hot path:
|
|
135
|
+
// the job sets author.currentDraftBook per book -> reverse-loads author.books each time.
|
|
136
|
+
bookConfig.addRule(
|
|
137
|
+
["publishedAt", { author: ["favoriteBook", "currentDraftBook"] }],
|
|
138
|
+
(b) => { ... },
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
// ✅ React only to favoriteBook (which changes rarely — on publish, not per draft edit);
|
|
142
|
+
// read currentDraftBook on-demand so it's not a reactive dependency.
|
|
143
|
+
bookConfig.addRule(["publishedAt", { author: ["favoriteBook"] }], async (b) => {
|
|
144
|
+
if (b.publishedAt) return;
|
|
145
|
+
const author = b.author.get;
|
|
146
|
+
const favorite = author.favoriteBook.get;
|
|
147
|
+
const draft = await author.currentDraftBook.load(); // read, don't react
|
|
148
|
+
if (b !== favorite && b !== draft) return `${b} is unpublished but neither the favorite nor current draft`;
|
|
149
|
+
});
|
|
150
|
+
```
|