@postxl/generators 6.0.0 → 6.1.0

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.
Files changed (78) hide show
  1. package/dist/backend-ai/ai.generator.d.ts +2 -7
  2. package/dist/backend-ai/ai.generator.js.map +1 -1
  3. package/dist/backend-ai/get-backend-ai.d.ts +18 -0
  4. package/dist/backend-ai/get-backend-ai.js +11 -0
  5. package/dist/backend-ai/get-backend-ai.js.map +1 -0
  6. package/dist/backend-ai/index.d.ts +1 -0
  7. package/dist/backend-ai/index.js +3 -1
  8. package/dist/backend-ai/index.js.map +1 -1
  9. package/dist/backend-database-prisma/generators/prisma-schema.generator.js +5 -0
  10. package/dist/backend-database-prisma/generators/prisma-schema.generator.js.map +1 -1
  11. package/dist/backend-import/generators/detect-delta/model-function.generator.js +4 -1
  12. package/dist/backend-import/generators/detect-delta/model-function.generator.js.map +1 -1
  13. package/dist/backend-repositories/generators/model-repository.generator.js +236 -71
  14. package/dist/backend-repositories/generators/model-repository.generator.js.map +1 -1
  15. package/dist/backend-router-trpc/generators/app-routes.generator.js +7 -3
  16. package/dist/backend-router-trpc/generators/app-routes.generator.js.map +1 -1
  17. package/dist/backend-router-trpc/generators/trpc-plugin.generator.js +10 -3
  18. package/dist/backend-router-trpc/generators/trpc-plugin.generator.js.map +1 -1
  19. package/dist/backend-router-trpc/generators/trpc-router-module.generator.js +13 -6
  20. package/dist/backend-router-trpc/generators/trpc-router-module.generator.js.map +1 -1
  21. package/dist/backend-router-trpc/generators/trpc-shared.generator.js +16 -3
  22. package/dist/backend-router-trpc/generators/trpc-shared.generator.js.map +1 -1
  23. package/dist/backend-router-trpc/router-trpc.generator.d.ts +1 -2
  24. package/dist/backend-router-trpc/router-trpc.generator.js +2 -1
  25. package/dist/backend-router-trpc/router-trpc.generator.js.map +1 -1
  26. package/dist/backend-router-trpc/template/viewer.router.ts +31 -0
  27. package/dist/backend-update/model-update-service.generator.js +20 -4
  28. package/dist/backend-update/model-update-service.generator.js.map +1 -1
  29. package/dist/backend-update/update.generator.js +6 -2
  30. package/dist/backend-update/update.generator.js.map +1 -1
  31. package/dist/base/generators/claudemd.generator.js +1 -0
  32. package/dist/base/generators/claudemd.generator.js.map +1 -1
  33. package/dist/decoders/default-value.helper.d.ts +25 -1
  34. package/dist/decoders/default-value.helper.js +44 -0
  35. package/dist/decoders/default-value.helper.js.map +1 -1
  36. package/dist/decoders/excel-field-decoder.helper.js +23 -5
  37. package/dist/decoders/excel-field-decoder.helper.js.map +1 -1
  38. package/dist/decoders/field-decoder.helper.js +16 -9
  39. package/dist/decoders/field-decoder.helper.js.map +1 -1
  40. package/dist/devops/generators/bitbucket-pipelines-yml.generator.js +7 -1
  41. package/dist/devops/generators/bitbucket-pipelines-yml.generator.js.map +1 -1
  42. package/dist/devops/generators/e2e-yml.generator.js +9 -2
  43. package/dist/devops/generators/e2e-yml.generator.js.map +1 -1
  44. package/dist/devops/generators/prisma-migrations.d.ts +14 -0
  45. package/dist/devops/generators/prisma-migrations.js +18 -0
  46. package/dist/devops/generators/prisma-migrations.js.map +1 -0
  47. package/dist/e2e/template/e2e/tsconfig.json +0 -3
  48. package/dist/frontend-actions/actions.generator.js +12 -6
  49. package/dist/frontend-actions/actions.generator.js.map +1 -1
  50. package/dist/frontend-actions/generators/base-global-actions.generator.d.ts +7 -1
  51. package/dist/frontend-actions/generators/base-global-actions.generator.js +89 -1
  52. package/dist/frontend-actions/generators/base-global-actions.generator.js.map +1 -1
  53. package/dist/frontend-actions/generators/sidepanel-toggle.generator.d.ts +4 -0
  54. package/dist/frontend-actions/generators/sidepanel-toggle.generator.js +4 -0
  55. package/dist/frontend-actions/generators/sidepanel-toggle.generator.js.map +1 -1
  56. package/dist/frontend-admin/generators/detail-sidebar.generator.js +30 -17
  57. package/dist/frontend-admin/generators/detail-sidebar.generator.js.map +1 -1
  58. package/dist/frontend-admin/generators/model-admin-page.generator.js +42 -54
  59. package/dist/frontend-admin/generators/model-admin-page.generator.js.map +1 -1
  60. package/dist/frontend-core/frontend.generator.js +10 -0
  61. package/dist/frontend-core/frontend.generator.js.map +1 -1
  62. package/dist/frontend-core/template/src/context-providers/auth-context-provider.tsx +27 -1
  63. package/dist/frontend-core/template/src/pages/dashboard/dashboard.page.tsx +3 -5
  64. package/dist/frontend-forms/generators/model/forms.generator.js +72 -30
  65. package/dist/frontend-forms/generators/model/forms.generator.js.map +1 -1
  66. package/dist/frontend-tables/generators/model-table.generator.js +4 -0
  67. package/dist/frontend-tables/generators/model-table.generator.js.map +1 -1
  68. package/dist/mock-data/generators/data-mocker.generator.js +27 -3
  69. package/dist/mock-data/generators/data-mocker.generator.js.map +1 -1
  70. package/dist/skailify/generators/capabilities-file.generator.js +14 -2
  71. package/dist/skailify/generators/capabilities-file.generator.js.map +1 -1
  72. package/dist/types/generators/models.generator.d.ts +9 -0
  73. package/dist/types/generators/models.generator.js +15 -3
  74. package/dist/types/generators/models.generator.js.map +1 -1
  75. package/dist/types/types.generator.d.ts +5 -0
  76. package/dist/types/types.generator.js +4 -0
  77. package/dist/types/types.generator.js.map +1 -1
  78. package/package.json +5 -5
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Prisma commands the generated CI pipelines use to set up the test database.
3
+ *
4
+ * CI applies the committed migrations with `migrate deploy`, exactly as `docker/backend/migrate.sh`
5
+ * does in production, and then fails if the migrated database differs from the generated
6
+ * `schema.prisma`. It used to run `migrate dev`, which generates any migration that was never
7
+ * committed - so a drifted `migrations/` folder passed CI and only failed on a deployed boot.
8
+ */
9
+ export declare const prismaMigrateDeploy = "pnpm prisma migrate deploy";
10
+ /**
11
+ * Exits 2 and prints the missing migration when the migrated database differs from the schema.
12
+ * The path is the `schema` of the generated `prisma.config.ts`.
13
+ */
14
+ export declare const prismaMigrationsDriftCheck = "pnpm prisma migrate diff --from-config-datasource --to-schema backend/libs/database/src/schema.prisma --script --exit-code";
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prismaMigrationsDriftCheck = exports.prismaMigrateDeploy = void 0;
4
+ /**
5
+ * Prisma commands the generated CI pipelines use to set up the test database.
6
+ *
7
+ * CI applies the committed migrations with `migrate deploy`, exactly as `docker/backend/migrate.sh`
8
+ * does in production, and then fails if the migrated database differs from the generated
9
+ * `schema.prisma`. It used to run `migrate dev`, which generates any migration that was never
10
+ * committed - so a drifted `migrations/` folder passed CI and only failed on a deployed boot.
11
+ */
12
+ exports.prismaMigrateDeploy = 'pnpm prisma migrate deploy';
13
+ /**
14
+ * Exits 2 and prints the missing migration when the migrated database differs from the schema.
15
+ * The path is the `schema` of the generated `prisma.config.ts`.
16
+ */
17
+ exports.prismaMigrationsDriftCheck = 'pnpm prisma migrate diff --from-config-datasource --to-schema backend/libs/database/src/schema.prisma --script --exit-code';
18
+ //# sourceMappingURL=prisma-migrations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prisma-migrations.js","sourceRoot":"","sources":["../../../src/devops/generators/prisma-migrations.ts"],"names":[],"mappings":";;;AAAA;;;;;;;GAOG;AACU,QAAA,mBAAmB,GAAG,4BAA4B,CAAA;AAE/D;;;GAGG;AACU,QAAA,0BAA0B,GACrC,4HAA4H,CAAA"}
@@ -1,7 +1,4 @@
1
1
  {
2
- "ts-node": {
3
- "require": ["tsconfig-paths/register"]
4
- },
5
2
  "compilerOptions": {
6
3
  "module": "commonjs",
7
4
  "removeComments": true,
@@ -35,6 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.generator = exports.generatorId = void 0;
37
37
  const Generator = __importStar(require("@postxl/generator"));
38
+ const get_backend_ai_1 = require("../backend-ai/get-backend-ai");
38
39
  const backend_router_trpc_1 = require("../backend-router-trpc");
39
40
  const base_1 = require("../base");
40
41
  const frontend_core_1 = require("../frontend-core");
@@ -78,12 +79,17 @@ exports.generator = {
78
79
  // `-m` run dropped them.
79
80
  context.vfs.write('frontend/src/actions/command-palette-action.ts', (0, command_palette_action_generator_1.generateCommandPaletteAction)(), 'shared');
80
81
  context.vfs.write('frontend/src/actions/command-palette-store.ts', (0, command_palette_store_generator_1.generateCommandPaletteStore)(), 'shared');
81
- context.vfs.write('frontend/src/actions/ai-assistant-store.ts', (0, ai_assistant_store_generator_1.generateAiAssistantStore)(), 'shared');
82
- context.vfs.write('frontend/src/actions/ai-action-text.utils.ts', (0, ai_action_text_utils_generator_1.generateAiActionTextUtils)(), 'shared');
83
- context.vfs.write('frontend/src/actions/ai-sidebar-content.tsx', (0, ai_sidebar_content_generator_1.generateAiSidebarContent)(), 'shared');
84
- context.vfs.write('frontend/src/actions/ai-sidepane.tsx', (0, ai_sidepane_generator_1.generateAiSidepane)(), 'shared');
85
- context.vfs.write('frontend/src/actions/sidepanel-toggle.tsx', (0, sidepanel_toggle_generator_1.generateSidepanelToggle)(), 'shared');
86
- context.vfs.write('frontend/src/actions/base-global.actions.tsx', (0, base_global_actions_generator_1.generateBaseGlobalActions)(), 'shared');
82
+ // The assistant is only emitted when the project uses `backendAiGenerator` (#923). Files left
83
+ // out here are removed by the next run if an earlier one had written them.
84
+ const hasAi = (0, get_backend_ai_1.getBackendAi)(context) !== undefined;
85
+ if (hasAi) {
86
+ context.vfs.write('frontend/src/actions/ai-assistant-store.ts', (0, ai_assistant_store_generator_1.generateAiAssistantStore)(), 'shared');
87
+ context.vfs.write('frontend/src/actions/ai-action-text.utils.ts', (0, ai_action_text_utils_generator_1.generateAiActionTextUtils)(), 'shared');
88
+ context.vfs.write('frontend/src/actions/ai-sidebar-content.tsx', (0, ai_sidebar_content_generator_1.generateAiSidebarContent)(), 'shared');
89
+ context.vfs.write('frontend/src/actions/ai-sidepane.tsx', (0, ai_sidepane_generator_1.generateAiSidepane)(), 'shared');
90
+ context.vfs.write('frontend/src/actions/sidepanel-toggle.tsx', (0, sidepanel_toggle_generator_1.generateSidepanelToggle)(), 'shared');
91
+ }
92
+ context.vfs.write('frontend/src/actions/base-global.actions.tsx', (0, base_global_actions_generator_1.generateBaseGlobalActions)({ hasAi }), 'shared');
87
93
  context.vfs.write('frontend/src/actions/command-palette.tsx', (0, command_palette_generator_1.generateCommandPalette)({ context }), 'shared');
88
94
  context.vfs.write('frontend/src/lib/command-palette-filter.utils.ts', (0, filter_utils_generator_1.generateFilterUtils)(), 'shared');
89
95
  const rootDocumentPath = 'frontend/src/pages/root-document.tsx';
@@ -1 +1 @@
1
- {"version":3,"file":"actions.generator.js","sourceRoot":"","sources":["../../src/frontend-actions/actions.generator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAY,SAAS,8CAAyB;AAE9C,gEAA4F;AAC5F,kCAAmD;AACnD,oDAAoE;AACpE,kEAA+F;AAE/F,gGAAuF;AACvF,4FAAoF;AACpF,4FAAoF;AACpF,8EAAuE;AACvE,8FAAsF;AACtF,sFAA+E;AAC/E,oGAA4F;AAC5F,kGAA0F;AAC1F,gFAAyE;AACzE,wFAAiF;AAgBpE,QAAA,WAAW,GAAG,SAAS,CAAC,sBAAsB,CAAC,kBAAkB,CAAC,CAAA;AAElE,QAAA,SAAS,GAAiC;IACrD,EAAE,EAAE,QAAA,WAAW;IACf,QAAQ,EAAE,CAAC,sBAAe,EAAE,mCAAmB,EAAE,kDAA4B,EAAE,oDAA6B,CAAC;IAE7G,QAAQ,EAAE,CAAsC,OAAgB,EAAiB,EAAE;QACjF,MAAM,cAAc,GAAiC;YACnD,IAAI,EAAE,SAAS,CAAC,cAAc,CAAC,gBAAgB,CAAC;YAChD,QAAQ,EAAE,SAAS,CAAC,uBAAuB,CAAC,8BAA8B,CAAC;SAC5E,CAAA;QAED,MAAM,iBAAiB,GAAiC;YACtD,IAAI,EAAE,SAAS,CAAC,cAAc,CAAC,sBAAsB,CAAC;YACtD,QAAQ,EAAE,SAAS,CAAC,uBAAuB,CAAC,kCAAkC,CAAC;SAChF,CAAA;QAED,OAAO;YACL,GAAG,OAAO;YACV,eA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DAAyB,EAAC,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAA;QACjH,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,0CAA0C,EAAE,IAAA,kDAAsB,EAAC,EAAE,OAAO,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAA;QAC5G,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,kDAAkD,EAAE,IAAA,4CAAmB,GAAE,EAAE,QAAQ,CAAC,CAAA;QAEtG,MAAM,gBAAgB,GAAG,sCAAsC,CAAA;QAC/D,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAA;QAEtD,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE,CAAC;YACrC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,gBAAgB,EAAE,YAAY,EAAE,QAAQ,CAAC,CAAA;QAC7D,CAAC;QAED,OAAO,OAAO,CAAA;IAChB,CAAC;CACF,CAAA"}
@@ -1 +1,7 @@
1
- export declare function generateBaseGlobalActions(): string;
1
+ /**
2
+ * @param hasAi Whether the project uses `backendAiGenerator`. Without it, the file carries no
3
+ * assistant: no `trpc.ai` executor, no `open-ai-assistant` action, no `ai-*` imports (#923).
4
+ */
5
+ export declare function generateBaseGlobalActions({ hasAi }: {
6
+ hasAi: boolean;
7
+ }): string;
@@ -1,7 +1,95 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateBaseGlobalActions = generateBaseGlobalActions;
4
- function generateBaseGlobalActions() {
4
+ /**
5
+ * @param hasAi Whether the project uses `backendAiGenerator`. Without it, the file carries no
6
+ * assistant: no `trpc.ai` executor, no `open-ai-assistant` action, no `ai-*` imports (#923).
7
+ */
8
+ function generateBaseGlobalActions({ hasAi }) {
9
+ return hasAi ? generateWithAi() : generateWithoutAi();
10
+ }
11
+ function generateWithoutAi() {
12
+ return `import { useTheme } from '@context-providers/theme-context-provider'
13
+ import { useNavigate } from '@tanstack/react-router'
14
+
15
+ import { useEffect } from 'react'
16
+
17
+ import { command, waitForNextFrame } from './command-palette-action'
18
+ import { useCommandPaletteActions } from './command-palette-store'
19
+
20
+ export const useBaseGlobalActions = () => {
21
+ useNavigationActions()
22
+ useThemeActions()
23
+ }
24
+
25
+ const useNavigationActions = () => {
26
+ const navigate = useNavigate()
27
+ const { registerGlobalActions } = useCommandPaletteActions()
28
+
29
+ useEffect(() => {
30
+ const actions = [
31
+ command({
32
+ key: 'navigate-dashboard',
33
+ visibility: 'visible',
34
+ group: 'Navigate',
35
+ label: 'Dashboard',
36
+ run: async () => {
37
+ await navigate({ to: '/dashboard' })
38
+ await waitForNextFrame()
39
+ return { kind: 'close' }
40
+ },
41
+ }),
42
+ ]
43
+
44
+ registerGlobalActions(...actions)
45
+ }, [navigate, registerGlobalActions])
46
+ }
47
+
48
+ const useThemeActions = () => {
49
+ const { setColorMode } = useTheme()
50
+ const { registerGlobalActions } = useCommandPaletteActions()
51
+
52
+ useEffect(() => {
53
+ registerGlobalActions(
54
+ command({
55
+ key: 'set-theme-dark',
56
+ visibility: 'visible',
57
+ group: 'Appearance',
58
+ label: 'Switch to dark mode',
59
+ run: async () => {
60
+ setColorMode('dark')
61
+ await waitForNextFrame()
62
+ return { kind: 'close' }
63
+ },
64
+ }),
65
+ command({
66
+ key: 'set-theme-light',
67
+ visibility: 'visible',
68
+ group: 'Appearance',
69
+ label: 'Switch to light mode',
70
+ run: async () => {
71
+ setColorMode('light')
72
+ await waitForNextFrame()
73
+ return { kind: 'close' }
74
+ },
75
+ }),
76
+ command({
77
+ key: 'set-theme-system',
78
+ visibility: 'visible',
79
+ group: 'Appearance',
80
+ label: 'Use system theme',
81
+ run: async () => {
82
+ setColorMode('system')
83
+ await waitForNextFrame()
84
+ return { kind: 'close' }
85
+ },
86
+ }),
87
+ )
88
+ }, [registerGlobalActions, setColorMode])
89
+ }
90
+ `;
91
+ }
92
+ function generateWithAi() {
5
93
  return `import { useAuth } from '@context-providers/auth-context-provider'
6
94
  import { useTheme } from '@context-providers/theme-context-provider'
7
95
  import { useMutation } from '@tanstack/react-query'
@@ -1 +1 @@
1
- {"version":3,"file":"base-global-actions.generator.js","sourceRoot":"","sources":["../../../src/frontend-actions/generators/base-global-actions.generator.ts"],"names":[],"mappings":";;;AAAA;IACE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8YR,CAAA;AACD,CAAC"}
1
+ {"version":3,"file":"base-global-actions.generator.js","sourceRoot":"","sources":["../../../src/frontend-actions/generators/base-global-actions.generator.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,mCAA0C,EAAE,KAAK,EAAsB;IACrE,OAAO,KAAK,CAAC,CAAC,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAA;AACvD,CAAC;AAED,SAAS,iBAAiB;IACxB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8ER,CAAA;AACD,CAAC;AAED,SAAS,cAAc;IACrB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8YR,CAAA;AACD,CAAC"}
@@ -1 +1,5 @@
1
+ /**
2
+ * The toggle drives the assistant's side panel, so it is only emitted when the project uses
3
+ * `backendAiGenerator` (#923).
4
+ */
1
5
  export declare function generateSidepanelToggle(): string;
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateSidepanelToggle = generateSidepanelToggle;
4
+ /**
5
+ * The toggle drives the assistant's side panel, so it is only emitted when the project uses
6
+ * `backendAiGenerator` (#923).
7
+ */
4
8
  function generateSidepanelToggle() {
5
9
  return `import { PanelRightIcon } from 'lucide-react'
6
10
  import { useLocation } from '@tanstack/react-router'
@@ -1 +1 @@
1
- {"version":3,"file":"sidepanel-toggle.generator.js","sourceRoot":"","sources":["../../../src/frontend-actions/generators/sidepanel-toggle.generator.ts"],"names":[],"mappings":";;;AAAA;IACE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8BR,CAAA;AACD,CAAC"}
1
+ {"version":3,"file":"sidepanel-toggle.generator.js","sourceRoot":"","sources":["../../../src/frontend-actions/generators/sidepanel-toggle.generator.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH;IACE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8BR,CAAA;AACD,CAAC"}
@@ -35,33 +35,39 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.generateAdminDetailSidebar = generateAdminDetailSidebar;
37
37
  const Generator = __importStar(require("@postxl/generator"));
38
+ const get_backend_ai_1 = require("../../backend-ai/get-backend-ai");
38
39
  /**
39
40
  * Generator function that generates the Admin Detail Sidebar wrapper component.
40
41
  * This component owns the right-side sidebar shell (Sidebar, SidebarRail, SidebarContent, Tabs)
41
42
  * and renders AuditLogSidebar and (optionally) ModelCommentContent internally.
42
43
  */
43
44
  function generateAdminDetailSidebar({ context }) {
45
+ // The "AI" tab, its store and its content only exist when the project uses `backendAiGenerator` (#923).
46
+ const hasAi = (0, get_backend_ai_1.getBackendAi)(context) !== undefined;
44
47
  const imports = Generator.ImportGenerator
45
48
  //
46
49
  .from(Generator.toBackendModuleLocation('@ui/admin/AdminDetailSidebar'))
47
- .add(context.admin.components.auditLogSidebar)
48
- .addImport({
49
- from: Generator.toBackendModuleLocation('@app-actions/ai-assistant-store'),
50
- items: [Generator.toFunctionName('useAiAssistantActions'), Generator.toFunctionName('useAiAssistantState')],
51
- })
52
- .addImport({
53
- from: Generator.toBackendModuleLocation('@app-actions/ai-sidebar-content'),
54
- items: [Generator.toFunctionName('AiSidebarContent')],
55
- });
50
+ .add(context.admin.components.auditLogSidebar);
51
+ if (hasAi) {
52
+ imports
53
+ .addImport({
54
+ from: Generator.toBackendModuleLocation('@app-actions/ai-assistant-store'),
55
+ items: [Generator.toFunctionName('useAiAssistantActions'), Generator.toFunctionName('useAiAssistantState')],
56
+ })
57
+ .addImport({
58
+ from: Generator.toBackendModuleLocation('@app-actions/ai-sidebar-content'),
59
+ items: [Generator.toFunctionName('AiSidebarContent')],
60
+ });
61
+ }
56
62
  const hasComments = !!context.admin.components.commentSidebar;
57
63
  if (hasComments) {
58
64
  imports.add(context.admin.components.commentSidebar); // NOSONAR
59
65
  }
60
66
  return `
61
67
  import type { ComponentProps } from 'react'
62
- ${hasComments ? "import { useState } from 'react'" : ''}
68
+ ${hasComments || !hasAi ? `import { useState } from 'react'` : ''}
63
69
  ${imports.generate()}
64
- import { APP_CONFIG } from '@lib/config'
70
+ ${hasAi ? "import { APP_CONFIG } from '@lib/config'" : ''}
65
71
  import {
66
72
  ${hasComments ? 'Badge,' : ''}
67
73
  Sidebar,
@@ -103,9 +109,12 @@ export function AdminDetailSidebar({
103
109
  ...sidebarProps
104
110
  }: AdminDetailSidebarProps) {
105
111
  ${hasComments ? 'const [commentCount, setCommentCount] = useState(0)' : ''}
106
- const activeAdminTab = useAiAssistantState((state) => state.activeAdminTab)
112
+ ${hasAi
113
+ ? `const activeAdminTab = useAiAssistantState((state) => state.activeAdminTab)
107
114
  const { setActiveAdminTab } = useAiAssistantActions()
108
- const availableTabs = new Set([${hasComments ? "'comments', " : ''}'audit-log', ...(APP_CONFIG.enableAI ? ['ai'] : [])])
115
+ const availableTabs = new Set([${hasComments ? "'comments', " : ''}'audit-log', ...(APP_CONFIG.enableAI ? ['ai'] : [])])`
116
+ : `const [activeAdminTab, setActiveAdminTab] = useState('${hasComments ? 'comments' : 'audit-log'}')
117
+ const availableTabs = new Set([${hasComments ? "'comments', " : ''}'audit-log'])`}
109
118
  const selectedTab = availableTabs.has(activeAdminTab) ? activeAdminTab : '${hasComments ? 'comments' : 'audit-log'}'
110
119
 
111
120
  return (
@@ -120,9 +129,11 @@ export function AdminDetailSidebar({
120
129
  ? `<TabsTrigger value="comments" variant="protocol" className="group/tab cursor-pointer px-3 h-8">Comments{commentCount > 0 && <Badge variant="secondary" size="xs" className="ml-1.5 transition-none group-hover/tab:bg-primary group-hover/tab:text-primary-foreground group-data-[state=active]/tab:bg-primary group-data-[state=active]/tab:text-primary-foreground">{commentCount}</Badge>}</TabsTrigger>`
121
130
  : ''}
122
131
  <TabsTrigger value="audit-log" variant="protocol" className="cursor-pointer px-3 h-8">Audit Log</TabsTrigger>
123
- {APP_CONFIG.enableAI && (
132
+ ${hasAi
133
+ ? `{APP_CONFIG.enableAI && (
124
134
  <TabsTrigger value="ai" variant="protocol" className="cursor-pointer px-3 h-8">AI</TabsTrigger>
125
- )}
135
+ )}`
136
+ : ''}
126
137
  </TabsList>
127
138
  </SidebarGroupContent>
128
139
  </SidebarGroup>
@@ -149,11 +160,13 @@ export function AdminDetailSidebar({
149
160
  onClearEntity={onClearEntity}
150
161
  />
151
162
  </TabsContent>
152
- {APP_CONFIG.enableAI && (
163
+ ${hasAi
164
+ ? `{APP_CONFIG.enableAI && (
153
165
  <TabsContent value="ai" className="mt-0 h-full min-h-0">
154
166
  <AiSidebarContent />
155
167
  </TabsContent>
156
- )}
168
+ )}`
169
+ : ''}
157
170
  </Tabs>
158
171
  </SidebarContent>
159
172
  </Sidebar>
@@ -1 +1 @@
1
- {"version":3,"file":"detail-sidebar.generator.js","sourceRoot":"","sources":["../../../src/frontend-admin/generators/detail-sidebar.generator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAY,SAAS,8CAAyB;AAI9C;;;;GAIG;AACH,oCAA2C,EAAE,OAAO,EAA8B;IAChF,MAAM,OAAO,GAAG,SAAS,CAAC,eAAe;QACvC,EAAE;SACD,IAAI,CAAC,SAAS,CAAC,uBAAuB,CAAC,8BAA8B,CAAC,CAAC;SACvE,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,eAAe,CAAC;SAC7C,SAAS,CAAC;QACT,IAAI,EAAE,SAAS,CAAC,uBAAuB,CAAC,iCAAiC,CAAC;QAC1E,KAAK,EAAE,CAAC,SAAS,CAAC,cAAc,CAAC,uBAAuB,CAAC,EAAE,SAAS,CAAC,cAAc,CAAC,qBAAqB,CAAC,CAAC;KAC5G,CAAC;SACD,SAAS,CAAC;QACT,IAAI,EAAE,SAAS,CAAC,uBAAuB,CAAC,iCAAiC,CAAC;QAC1E,KAAK,EAAE,CAAC,SAAS,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAC;KACtD,CAAC,CAAA;IAEJ,MAAM,WAAW,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,cAAc,CAAA;IAC7D,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,cAAe,CAAC,CAAA,CAAC,UAAU;IAClE,CAAC;IAED,OAAO;;EAEP,WAAW,CAAC,CAAC,CAAC,kCAAkC,CAAC,CAAC,CAAC,EAAE;EACrD,OAAO,CAAC,QAAQ,EAAE;;;IAGhB,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE;;;;;;;;;;;;;;;;;;;;IAqB3B,WAAW;QACT,CAAC,CAAC;;;gCAGwB;QAC1B,CAAC,CAAC,EACN;;;;;;;;;;;IAWE,WAAW,CAAC,CAAC,CAAC,+DAA+D,CAAC,CAAC,CAAC,EAAE;;;IAGlF,WAAW,CAAC,CAAC,CAAC,qDAAqD,CAAC,CAAC,CAAC,EAAE;;;mCAGzC,WAAW,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE;8EACU,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW;;;;;;;;;;kBAWlG,WAAW;QACT,CAAC,CAAC,6YAA6Y;QAC/Y,CAAC,CAAC,EACN;;;;;;;;YASJ,WAAW;QACT,CAAC,CAAC;eACD,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,cAAe,CAAC,IAAI;;;;;;;;yBAQnC;QACX,CAAC,CAAC,EACN;;;;;;;;;;;;;;;;;;;;;;CAsBT,CAAA;AACD,CAAC"}
1
+ {"version":3,"file":"detail-sidebar.generator.js","sourceRoot":"","sources":["../../../src/frontend-admin/generators/detail-sidebar.generator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAY,SAAS,8CAAyB;AAE9C,oEAA8D;AAG9D;;;;GAIG;AACH,oCAA2C,EAAE,OAAO,EAA8B;IACh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QAC1B,CAAC,CAAC,EACN;;;;;;;;;;;IAWE,WAAW,CAAC,CAAC,CAAC,+DAA+D,CAAC,CAAC,CAAC,EAAE;;;IAGlF,WAAW,CAAC,CAAC,CAAC,qDAAqD,CAAC,CAAC,CAAC,EAAE;IAExE,KAAK;QACH,CAAC,CAAC;;mCAE2B,WAAW,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,uDAAuD;QACrH,CAAC,CAAC,yDAAyD,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW;mCACpE,WAAW,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,eAClE;8EAC4E,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW;;;;;;;;;;kBAWlG,WAAW;QACT,CAAC,CAAC,6YAA6Y;QAC/Y,CAAC,CAAC,EACN;;kBAGE,KAAK;QACH,CAAC,CAAC;;mBAEH;QACC,CAAC,CAAC,EACN;;;;YAKJ,WAAW;QACT,CAAC,CAAC;eACD,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,cAAe,CAAC,IAAI;;;;;;;;yBAQnC;QACX,CAAC,CAAC,EACN;;;;;;;;;;;;YAaE,KAAK;QACH,CAAC,CAAC;;;;aAIH;QACC,CAAC,CAAC,EACN;;;;;;CAMT,CAAA;AACD,CAAC"}
@@ -35,6 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.generateModelAdminPage = generateModelAdminPage;
37
37
  const Generator = __importStar(require("@postxl/generator"));
38
+ const get_backend_ai_1 = require("../../backend-ai/get-backend-ai");
38
39
  const frontend_core_1 = require("../../frontend-core");
39
40
  const frontend_forms_1 = require("../../frontend-forms");
40
41
  const frontend_tables_1 = require("../../frontend-tables");
@@ -42,6 +43,8 @@ const frontend_tables_1 = require("../../frontend-tables");
42
43
  * Generator function that generates the Admin page for a model
43
44
  */
44
45
  function generateModelAdminPage({ model, context, }) {
46
+ // The AI tab and its imports only exist when the project uses `backendAiGenerator` (#923).
47
+ const hasAi = (0, get_backend_ai_1.getBackendAi)(context) !== undefined;
45
48
  const adminUiPolicy = resolveAdminUiPolicy(model, context);
46
49
  const writePolicy = resolveWritePolicy(model, context);
47
50
  const imports = Generator.ImportGenerator
@@ -92,10 +95,6 @@ function generateModelAdminPage({ model, context, }) {
92
95
  .addImport({
93
96
  from: Generator.toBackendModuleLocation('@app-actions/command-palette-store'),
94
97
  items: [Generator.toFunctionName('useCommandPaletteActions')],
95
- })
96
- .addImport({
97
- from: Generator.toBackendModuleLocation('@app-actions/ai-sidebar-content'),
98
- items: [Generator.toFunctionName('AiSidebarContent')],
99
98
  })
100
99
  .addImport({
101
100
  from: Generator.toBackendModuleLocation('@lib/command-palette-filter.utils'),
@@ -108,8 +107,14 @@ function generateModelAdminPage({ model, context, }) {
108
107
  Generator.toFunctionName('toFilterActionLabel'),
109
108
  ],
110
109
  });
110
+ if (hasAi) {
111
+ imports.addImport({
112
+ from: Generator.toBackendModuleLocation('@app-actions/ai-sidebar-content'),
113
+ items: [Generator.toFunctionName('AiSidebarContent')],
114
+ });
115
+ }
111
116
  const showComments = model.name !== 'Comment' && !!context.admin.components.commentSidebar;
112
- configureSidebarImports({ imports, context, showComments });
117
+ configureSidebarImports({ imports, context, showComments, hasAi });
113
118
  const childRelations = collectChildRelationInfos({ model, context });
114
119
  const relatedModels = collectRelatedModels({ model, context, imports });
115
120
  configureChildCountImports({ imports, context, hasChildRelations: childRelations.length > 0 });
@@ -128,7 +133,7 @@ function generateModelAdminPage({ model, context, }) {
128
133
  const removeRowsHandler = buildRemoveRowsHandler(model);
129
134
  const commentSidebarTab = buildCommentSidebarTab({ showComments, model });
130
135
  const relatedTableProps = buildRelatedTableProps(relatedModels);
131
- const childRelationCountDefinitions = buildChildRelationCountDefinitions({ childRelations, context });
136
+ const childRelationCountDefinitions = buildChildRelationCountDefinitions(childRelations);
132
137
  const childRelationTableProps = buildChildRelationTableProps(childRelations);
133
138
  const filterSearchParamFields = model.admin.page.filterSearchParamFields ?? [];
134
139
  const initialFiltersFromSearchParams = buildInitialFiltersFromSearchParams({
@@ -142,14 +147,14 @@ function generateModelAdminPage({ model, context, }) {
142
147
  const removeRowsProp = buildRemoveRowsProp(model);
143
148
  return `
144
149
  import { SidebarTab, useDebouncedCallback } from '@postxl/ui-components'
145
- import { APP_CONFIG } from '@lib/config'
150
+ ${hasAi ? "import { APP_CONFIG } from '@lib/config'" : ''}
146
151
  import { useAuth } from '@context-providers/auth-context-provider'
147
152
  import { hasAnyRole } from '@lib/authorization'
148
153
  ${imports.generate()}
149
154
 
150
155
  export default function ${model.admin.page.pageComponent.name}() {
151
156
  const navigate = useNavigate()
152
- const { viewerData } = useAuth()${withTableView ? '\n const currentUserId = viewerData?.user?.id' : ''}
157
+ const { viewerData${childRelations.length > 0 ? ', canReadModel' : ''} } = useAuth()${withTableView ? '\n const currentUserId = viewerData?.user?.id' : ''}
153
158
  const userRoles = viewerData?.userRoles ?? []${childRelations.length > 0 ? `\n const trpc = ${context.trpcClient.name}()` : ''}
154
159
  const canAccessAdminPage = ${canAccessAdminExpression}${withTableView ? `\n const canWriteModel = ${canWriteModelExpression}` : ''}
155
160
  ${commentCountState}
@@ -184,7 +189,7 @@ export default function ${model.admin.page.pageComponent.name}() {
184
189
  // Queries for related models' maps used by the table (passed as separate props)
185
190
  ${relatedModels.map((rm) => rm.mapDefinition).join('\n ')}
186
191
 
187
- ${childRelations.length > 0 ? '// Child relation count maps (number of children referencing each parent row).\n // Counts are computed in the backend via grouped DB counts — the child rows are\n // never fetched to the client just to count them. A relation whose child model\n // restricts read access is only queried for viewers who hold one of those roles;\n // the others are handed no map at all, so the column reads unknown, not 0.' : ''}
192
+ ${childRelations.length > 0 ? '// Child relation count maps (number of children referencing each parent row).\n // Counts are computed in the backend via grouped DB counts — the child rows are\n // never fetched to the client just to count them. Each relation is only queried\n // when the server says it would serve this viewer that read; the others are handed\n // no map at all, so the column reads unknown, not 0.' : ''}
188
193
  ${childRelationCountDefinitions}
189
194
 
190
195
  // The selected entity ID comes from the URL selectedKey (which is the entity's id)
@@ -401,7 +406,8 @@ export default function ${model.admin.page.pageComponent.name}() {
401
406
  />
402
407
  </SidebarTab>
403
408
 
404
- {APP_CONFIG.enableAI && (
409
+ ${hasAi
410
+ ? `{APP_CONFIG.enableAI && (
405
411
  <SidebarTab
406
412
  side="right"
407
413
  id="ai-assistant-content"
@@ -411,7 +417,8 @@ export default function ${model.admin.page.pageComponent.name}() {
411
417
  >
412
418
  <AiSidebarContent />
413
419
  </SidebarTab>
414
- )}
420
+ )}`
421
+ : ''}
415
422
  <div className="p-4 overflow-hidden gap-4">
416
423
  <Link
417
424
  to="/admin"
@@ -467,7 +474,8 @@ export default function ${model.admin.page.pageComponent.name}() {
467
474
  }
468
475
  `;
469
476
  }
470
- function configureSidebarImports({ imports, context, showComments, }) {
477
+ function configureSidebarImports({ imports, context, showComments, hasAi, }) {
478
+ const sparkles = hasAi ? [Generator.toFunctionName('Sparkles')] : [];
471
479
  if (showComments) {
472
480
  imports.add(context.admin.components.commentSidebar);
473
481
  imports.addImport({
@@ -477,7 +485,7 @@ function configureSidebarImports({ imports, context, showComments, }) {
477
485
  Generator.toFunctionName('ListTree'),
478
486
  Generator.toFunctionName('MessageSquareText'),
479
487
  Generator.toFunctionName('ScrollText'),
480
- Generator.toFunctionName('Sparkles'),
488
+ ...sparkles,
481
489
  ],
482
490
  });
483
491
  return;
@@ -488,7 +496,7 @@ function configureSidebarImports({ imports, context, showComments, }) {
488
496
  Generator.toFunctionName('ArrowLeft'),
489
497
  Generator.toFunctionName('ListTree'),
490
498
  Generator.toFunctionName('ScrollText'),
491
- Generator.toFunctionName('Sparkles'),
499
+ ...sparkles,
492
500
  ],
493
501
  });
494
502
  }
@@ -680,21 +688,26 @@ function buildRelatedTableProps(relatedModels) {
680
688
  * grouped DB count. We no longer fetch the child rows and count them on the
681
689
  * client (see issue #766).
682
690
  *
683
- * Each query is gated on the *child* model's effective read roles (#875). A page is
684
- * counted by every model that points at it, and those models carry their own auth: a
685
- * page an `Owner` may open routinely counts rows of a model only a `PlatformAdmin` may
686
- * read. `<Model>ViewService.getChildCounts` throws `ForbiddenException` on a `canRead`
687
- * miss, so without the gate every such relation cost a rejected round trip, a console
688
- * error from the app's global query-cache handler and a dev toast, on every mount, for
689
- * every viewer who was never going to be allowed the answer.
691
+ * Each query is gated on whether the backend would serve it (#875). A page is counted by
692
+ * every model that points at it, and those models carry their own auth: a page an `Owner`
693
+ * may open routinely counts rows of a model only a `PlatformAdmin` may read.
694
+ * `<Model>ViewService.getChildCounts` throws `ForbiddenException` on a `canRead` miss, so
695
+ * without the gate every such relation cost a rejected round trip, a console error from the
696
+ * app's global query-cache handler and a dev toast, on every mount, for every viewer who was
697
+ * never going to be allowed the answer.
690
698
  *
691
- * **The gate mirrors only the role half of the backend decision.** `canRead` ANDs the
692
- * role check with `evaluateCustomPolicy`, a `@custom-*` hook a consumer can override to
693
- * deny per row. A query this gate lets through can still be refused; it is a necessary
694
- * condition on the request, never a guarantee that it succeeds.
699
+ * **The page does not decide - it asks.** `canReadModel` is `viewer.readableModels`, which
700
+ * runs the real `canRead` with no `item`, exactly as `getChildCounts` will. The first version
701
+ * of this gate transcribed the *role half* of that decision into the page instead, and #909
702
+ * reported what that costs: `canRead` ANDs the role check with `evaluateCustomPolicy`, a
703
+ * `@custom-*` hook a consumer overrides to deny per row, and for a rowless read that hook can
704
+ * deny every role the matrix admits. The transcription let through exactly the requests it
705
+ * existed to stop - and it could not be fixed at generate time, because the hook is consumer
706
+ * TypeScript that does not exist when this runs.
695
707
  *
696
- * A model whose read is open to everyone gets no `enabled` property at all, so the
697
- * common case emits exactly what it emitted before.
708
+ * Every relation is gated, including one whose read is open to every role: "open to every
709
+ * role" is not "open", for the same reason. Until the answer arrives `canReadModel` is
710
+ * `false`, so counts appear a beat after the page rather than as a burst of rejected requests.
698
711
  *
699
712
  * The query's `data` is handed to the table as-is rather than defaulted to an empty map.
700
713
  * A disabled query never resolves, so the default would have turned "you may not see
@@ -702,7 +715,7 @@ function buildRelatedTableProps(relatedModels) {
702
715
  * thing only: no answer. A map that is present but has no entry for a row still means a
703
716
  * genuine zero, because the grouped count omits parents with no children.
704
717
  */
705
- function buildChildRelationCountDefinitions({ childRelations, context, }) {
718
+ function buildChildRelationCountDefinitions(childRelations) {
706
719
  if (childRelations.length === 0) {
707
720
  return '';
708
721
  }
@@ -711,10 +724,7 @@ function buildChildRelationCountDefinitions({ childRelations, context, }) {
711
724
  const routeName = child.childModel.trpcRoute.name;
712
725
  const fieldName = child.descriptor.fieldName;
713
726
  const queryOptions = `trpc.${routeName}.getChildCounts.queryOptions({ field: '${fieldName}' })`;
714
- const readPolicy = resolveReadPolicy(child.childModel, context);
715
- const query = readPolicy.allowAll
716
- ? `useQuery(${queryOptions})`
717
- : `useQuery({ ...${queryOptions}, enabled: ${toRoleExpression(readPolicy, 'userRoles')} })`;
727
+ const query = `useQuery({ ...${queryOptions}, enabled: canReadModel('${child.childModel.name}') })`;
718
728
  return `const ${child.countMapName}Query = ${query}
719
729
  const ${child.countMapName} = ${child.countMapName}Query.data`;
720
730
  })
@@ -881,28 +891,6 @@ function resolveWritePolicy(model, context) {
881
891
  }
882
892
  return { allowAll: !(context.schema.auth?.defaultDeny ?? true), roles: [] };
883
893
  }
884
- /**
885
- * The role half of the backend's `AuthorizationPolicyService.canRead` for a model, resolved
886
- * at template-expansion time.
887
- *
888
- * Deliberately a mirror of the emitted `canOperate`, not a variation on it: the same
889
- * `{ ...schemaRules, ...modelRules }` merge, the same `!defaultDeny` answer when no rule
890
- * applies, and - unlike create/update/delete - no fallback to `rules.write`. A frontend that
891
- * were more permissive would put the rejected requests of #875 back; one that were stricter
892
- * would hide counts the backend would happily have served.
893
- *
894
- * What it cannot mirror is `evaluateCustomPolicy`, which the backend ANDs onto this decision
895
- * and which a consumer may override to deny. Everything derived from this policy is therefore
896
- * a necessary condition on a request, never a sufficient one.
897
- */
898
- function resolveReadPolicy(model, context) {
899
- const effectiveRules = resolveEffectiveRuleSet(model, context);
900
- const roles = effectiveRules.read?.anyRole;
901
- if (roles) {
902
- return { allowAll: false, roles };
903
- }
904
- return { allowAll: !(context.schema.auth?.defaultDeny ?? true), roles: [] };
905
- }
906
894
  function resolveAdminUiPolicy(model, context) {
907
895
  const effectiveRules = resolveEffectiveRuleSet(model, context);
908
896
  const roles = effectiveRules.adminUi?.visibleFor;