@baseplate-dev/project-builder-lib 0.6.4 → 0.6.6

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 (287) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/dist/compiler/admin-crud-action-compiler.js +1 -1
  3. package/dist/compiler/admin-crud-action-compiler.js.map +1 -1
  4. package/dist/compiler/admin-crud-column-compiler-spec.js +1 -1
  5. package/dist/compiler/admin-crud-column-compiler-spec.js.map +1 -1
  6. package/dist/compiler/admin-crud-input-spec.js +1 -1
  7. package/dist/compiler/admin-crud-input-spec.js.map +1 -1
  8. package/dist/compiler/app-compiler-spec.js +1 -1
  9. package/dist/compiler/app-compiler-spec.js.map +1 -1
  10. package/dist/compiler/index.d.ts +1 -0
  11. package/dist/compiler/index.d.ts.map +1 -1
  12. package/dist/compiler/index.js +1 -0
  13. package/dist/compiler/index.js.map +1 -1
  14. package/dist/compiler/model-transformer-compiler-spec.js +1 -1
  15. package/dist/compiler/model-transformer-compiler-spec.js.map +1 -1
  16. package/dist/compiler/root-compiler-spec.d.ts +25 -0
  17. package/dist/compiler/root-compiler-spec.d.ts.map +1 -0
  18. package/dist/compiler/root-compiler-spec.js +23 -0
  19. package/dist/compiler/root-compiler-spec.js.map +1 -0
  20. package/dist/constants/theme-colors.d.ts +0 -48
  21. package/dist/constants/theme-colors.d.ts.map +1 -1
  22. package/dist/constants/theme-colors.js +0 -32
  23. package/dist/constants/theme-colors.js.map +1 -1
  24. package/dist/definition/feature/feature-utils.d.ts +2 -2
  25. package/dist/definition/feature/feature-utils.d.ts.map +1 -1
  26. package/dist/definition/feature/feature-utils.js +3 -3
  27. package/dist/definition/feature/feature-utils.js.map +1 -1
  28. package/dist/definition/plugins/plugin-utils.d.ts +15 -0
  29. package/dist/definition/plugins/plugin-utils.d.ts.map +1 -1
  30. package/dist/definition/plugins/plugin-utils.js +50 -1
  31. package/dist/definition/plugins/plugin-utils.js.map +1 -1
  32. package/dist/definition/project-definition-container.d.ts.map +1 -1
  33. package/dist/definition/project-definition-container.js +3 -1
  34. package/dist/definition/project-definition-container.js.map +1 -1
  35. package/dist/{schema/models → expression-parsers}/authorizer/authorizer-expression-acorn-parser.d.ts +2 -0
  36. package/dist/expression-parsers/authorizer/authorizer-expression-acorn-parser.d.ts.map +1 -0
  37. package/dist/{schema/models → expression-parsers}/authorizer/authorizer-expression-acorn-parser.js +107 -52
  38. package/dist/expression-parsers/authorizer/authorizer-expression-acorn-parser.js.map +1 -0
  39. package/dist/{schema/models → expression-parsers}/authorizer/authorizer-expression-ast.d.ts +69 -1
  40. package/dist/expression-parsers/authorizer/authorizer-expression-ast.d.ts.map +1 -0
  41. package/dist/{schema/models → expression-parsers}/authorizer/authorizer-expression-ast.js +2 -0
  42. package/dist/expression-parsers/authorizer/authorizer-expression-ast.js.map +1 -0
  43. package/dist/{schema/models → expression-parsers}/authorizer/authorizer-expression-parser.d.ts +13 -14
  44. package/dist/expression-parsers/authorizer/authorizer-expression-parser.d.ts.map +1 -0
  45. package/dist/expression-parsers/authorizer/authorizer-expression-parser.js +292 -0
  46. package/dist/expression-parsers/authorizer/authorizer-expression-parser.js.map +1 -0
  47. package/dist/{schema/models → expression-parsers}/authorizer/authorizer-expression-validator.d.ts +37 -17
  48. package/dist/expression-parsers/authorizer/authorizer-expression-validator.d.ts.map +1 -0
  49. package/dist/expression-parsers/authorizer/authorizer-expression-validator.js +379 -0
  50. package/dist/expression-parsers/authorizer/authorizer-expression-validator.js.map +1 -0
  51. package/dist/expression-parsers/authorizer/authorizer-expression-visitor.d.ts +54 -0
  52. package/dist/expression-parsers/authorizer/authorizer-expression-visitor.d.ts.map +1 -0
  53. package/dist/expression-parsers/authorizer/authorizer-expression-visitor.js +52 -0
  54. package/dist/expression-parsers/authorizer/authorizer-expression-visitor.js.map +1 -0
  55. package/dist/expression-parsers/authorizer/index.d.ts +6 -0
  56. package/dist/expression-parsers/authorizer/index.d.ts.map +1 -0
  57. package/dist/expression-parsers/authorizer/index.js +6 -0
  58. package/dist/expression-parsers/authorizer/index.js.map +1 -0
  59. package/dist/expression-parsers/register-core-module.d.ts +6 -0
  60. package/dist/expression-parsers/register-core-module.d.ts.map +1 -0
  61. package/dist/expression-parsers/register-core-module.js +29 -0
  62. package/dist/expression-parsers/register-core-module.js.map +1 -0
  63. package/dist/index.d.ts +1 -0
  64. package/dist/index.js +1 -0
  65. package/dist/migrations/index.d.ts.map +1 -1
  66. package/dist/migrations/index.js +6 -0
  67. package/dist/migrations/index.js.map +1 -1
  68. package/dist/migrations/migration-029-admin-role-and-auto-assigned.d.ts +25 -0
  69. package/dist/migrations/migration-029-admin-role-and-auto-assigned.d.ts.map +1 -0
  70. package/dist/migrations/migration-029-admin-role-and-auto-assigned.js +72 -0
  71. package/dist/migrations/migration-029-admin-role-and-auto-assigned.js.map +1 -0
  72. package/dist/migrations/migration-030-remove-theme-hover-colors.d.ts +17 -0
  73. package/dist/migrations/migration-030-remove-theme-hover-colors.d.ts.map +1 -0
  74. package/dist/migrations/migration-030-remove-theme-hover-colors.js +41 -0
  75. package/dist/migrations/migration-030-remove-theme-hover-colors.js.map +1 -0
  76. package/dist/migrations/migration-031-uuid-default-generation.d.ts +24 -0
  77. package/dist/migrations/migration-031-uuid-default-generation.d.ts.map +1 -0
  78. package/dist/migrations/migration-031-uuid-default-generation.js +40 -0
  79. package/dist/migrations/migration-031-uuid-default-generation.js.map +1 -0
  80. package/dist/migrations/transform-json-path.d.ts.map +1 -1
  81. package/dist/migrations/transform-json-path.js +2 -3
  82. package/dist/migrations/transform-json-path.js.map +1 -1
  83. package/dist/parser/collect-definition-issues.d.ts.map +1 -1
  84. package/dist/parser/collect-definition-issues.js +10 -2
  85. package/dist/parser/collect-definition-issues.js.map +1 -1
  86. package/dist/parser/collect-expression-issues.d.ts +17 -9
  87. package/dist/parser/collect-expression-issues.d.ts.map +1 -1
  88. package/dist/parser/collect-expression-issues.js +21 -15
  89. package/dist/parser/collect-expression-issues.js.map +1 -1
  90. package/dist/parser/definition-issue-checkers/plugin-dependency-checker.d.ts +11 -0
  91. package/dist/parser/definition-issue-checkers/plugin-dependency-checker.d.ts.map +1 -0
  92. package/dist/parser/definition-issue-checkers/plugin-dependency-checker.js +41 -0
  93. package/dist/parser/definition-issue-checkers/plugin-dependency-checker.js.map +1 -0
  94. package/dist/parser/definition-issue-checkers/plugin-implementation-checker.d.ts +16 -0
  95. package/dist/parser/definition-issue-checkers/plugin-implementation-checker.d.ts.map +1 -0
  96. package/dist/parser/definition-issue-checkers/plugin-implementation-checker.js +69 -0
  97. package/dist/parser/definition-issue-checkers/plugin-implementation-checker.js.map +1 -0
  98. package/dist/parser/definition-issue-utils.d.ts +28 -1
  99. package/dist/parser/definition-issue-utils.d.ts.map +1 -1
  100. package/dist/parser/definition-issue-utils.js +59 -0
  101. package/dist/parser/definition-issue-utils.js.map +1 -1
  102. package/dist/parser/find-orphaned-union-items.d.ts +30 -0
  103. package/dist/parser/find-orphaned-union-items.d.ts.map +1 -0
  104. package/dist/parser/find-orphaned-union-items.js +47 -0
  105. package/dist/parser/find-orphaned-union-items.js.map +1 -0
  106. package/dist/parser/index.d.ts +3 -1
  107. package/dist/parser/index.d.ts.map +1 -1
  108. package/dist/parser/index.js +3 -1
  109. package/dist/parser/index.js.map +1 -1
  110. package/dist/parser/parser.d.ts.map +1 -1
  111. package/dist/parser/parser.js +3 -0
  112. package/dist/parser/parser.js.map +1 -1
  113. package/dist/parser/transform-data-with-schema.js +1 -1
  114. package/dist/parser/transform-data-with-schema.js.map +1 -1
  115. package/dist/plugins/imports/index.d.ts +1 -0
  116. package/dist/plugins/imports/index.d.ts.map +1 -1
  117. package/dist/plugins/imports/index.js +1 -0
  118. package/dist/plugins/imports/index.js.map +1 -1
  119. package/dist/plugins/imports/validate-plugin-dependencies.d.ts +42 -0
  120. package/dist/plugins/imports/validate-plugin-dependencies.d.ts.map +1 -0
  121. package/dist/plugins/imports/validate-plugin-dependencies.js +80 -0
  122. package/dist/plugins/imports/validate-plugin-dependencies.js.map +1 -0
  123. package/dist/plugins/metadata/types.d.ts +13 -0
  124. package/dist/plugins/metadata/types.d.ts.map +1 -1
  125. package/dist/plugins/metadata/types.js +15 -0
  126. package/dist/plugins/metadata/types.js.map +1 -1
  127. package/dist/plugins/spec/auth-config-spec.d.ts +1 -0
  128. package/dist/plugins/spec/auth-config-spec.d.ts.map +1 -1
  129. package/dist/plugins/spec/auth-config-spec.js.map +1 -1
  130. package/dist/references/definition-ref-builder.d.ts +2 -0
  131. package/dist/references/definition-ref-builder.d.ts.map +1 -1
  132. package/dist/references/definition-ref-registry.d.ts +2 -0
  133. package/dist/references/definition-ref-registry.d.ts.map +1 -1
  134. package/dist/references/definition-ref-registry.js.map +1 -1
  135. package/dist/references/expression-parser-ref.d.ts +51 -0
  136. package/dist/references/expression-parser-ref.d.ts.map +1 -0
  137. package/dist/references/expression-parser-ref.js +14 -0
  138. package/dist/references/expression-parser-ref.js.map +1 -0
  139. package/dist/references/expression-parser-spec.d.ts +29 -0
  140. package/dist/references/expression-parser-spec.d.ts.map +1 -0
  141. package/dist/references/expression-parser-spec.js +29 -0
  142. package/dist/references/expression-parser-spec.js.map +1 -0
  143. package/dist/references/expression-types.d.ts +20 -22
  144. package/dist/references/expression-types.d.ts.map +1 -1
  145. package/dist/references/expression-types.js +1 -2
  146. package/dist/references/expression-types.js.map +1 -1
  147. package/dist/references/extend-parser-context-with-refs.d.ts +7 -2
  148. package/dist/references/extend-parser-context-with-refs.d.ts.map +1 -1
  149. package/dist/references/extend-parser-context-with-refs.js +42 -12
  150. package/dist/references/extend-parser-context-with-refs.js.map +1 -1
  151. package/dist/references/extract-definition-refs.js +1 -1
  152. package/dist/references/extract-definition-refs.js.map +1 -1
  153. package/dist/references/fix-definition-refs.d.ts +22 -0
  154. package/dist/references/fix-definition-refs.d.ts.map +1 -0
  155. package/dist/references/fix-definition-refs.js +29 -0
  156. package/dist/references/fix-definition-refs.js.map +1 -0
  157. package/dist/references/fix-expression-renames.d.ts +20 -0
  158. package/dist/references/fix-expression-renames.d.ts.map +1 -0
  159. package/dist/references/fix-expression-renames.js +87 -0
  160. package/dist/references/fix-expression-renames.js.map +1 -0
  161. package/dist/references/index.d.ts +4 -0
  162. package/dist/references/index.d.ts.map +1 -1
  163. package/dist/references/index.js +4 -0
  164. package/dist/references/index.js.map +1 -1
  165. package/dist/references/parse-schema-with-references.d.ts +2 -1
  166. package/dist/references/parse-schema-with-references.d.ts.map +1 -1
  167. package/dist/references/parse-schema-with-references.js.map +1 -1
  168. package/dist/schema/apps/web/admin/sections/crud.d.ts.map +1 -1
  169. package/dist/schema/apps/web/admin/sections/crud.js +3 -2
  170. package/dist/schema/apps/web/admin/sections/crud.js.map +1 -1
  171. package/dist/schema/creator/definition-issue-checkers.d.ts +15 -0
  172. package/dist/schema/creator/definition-issue-checkers.d.ts.map +1 -1
  173. package/dist/schema/creator/definition-issue-checkers.js +33 -0
  174. package/dist/schema/creator/definition-issue-checkers.js.map +1 -1
  175. package/dist/schema/creator/schema-creator.js +1 -1
  176. package/dist/schema/creator/schema-creator.js.map +1 -1
  177. package/dist/schema/features/feature.js +1 -1
  178. package/dist/schema/features/feature.js.map +1 -1
  179. package/dist/schema/libraries/library.d.ts.map +1 -1
  180. package/dist/schema/libraries/library.js +1 -0
  181. package/dist/schema/libraries/library.js.map +1 -1
  182. package/dist/schema/models/authorizer/authorizer-expression-ref.d.ts +11 -0
  183. package/dist/schema/models/authorizer/authorizer-expression-ref.d.ts.map +1 -0
  184. package/dist/schema/models/authorizer/authorizer-expression-ref.js +10 -0
  185. package/dist/schema/models/authorizer/authorizer-expression-ref.js.map +1 -0
  186. package/dist/schema/models/authorizer/authorizer.js +2 -2
  187. package/dist/schema/models/authorizer/authorizer.js.map +1 -1
  188. package/dist/schema/models/authorizer/index.d.ts +1 -4
  189. package/dist/schema/models/authorizer/index.d.ts.map +1 -1
  190. package/dist/schema/models/authorizer/index.js +1 -4
  191. package/dist/schema/models/authorizer/index.js.map +1 -1
  192. package/dist/schema/models/enums.d.ts +12 -0
  193. package/dist/schema/models/enums.d.ts.map +1 -1
  194. package/dist/schema/models/enums.js +5 -2
  195. package/dist/schema/models/enums.js.map +1 -1
  196. package/dist/schema/models/graphql.js +3 -3
  197. package/dist/schema/models/graphql.js.map +1 -1
  198. package/dist/schema/models/models.d.ts +12 -24
  199. package/dist/schema/models/models.d.ts.map +1 -1
  200. package/dist/schema/models/models.js +6 -4
  201. package/dist/schema/models/models.js.map +1 -1
  202. package/dist/schema/plugins/definition.d.ts.map +1 -1
  203. package/dist/schema/plugins/definition.js +2 -0
  204. package/dist/schema/plugins/definition.js.map +1 -1
  205. package/dist/schema/project-definition.d.ts +10 -18
  206. package/dist/schema/project-definition.d.ts.map +1 -1
  207. package/dist/schema/project-definition.js +5 -1
  208. package/dist/schema/project-definition.js.map +1 -1
  209. package/dist/schema/settings/settings.d.ts +2 -10
  210. package/dist/schema/settings/settings.d.ts.map +1 -1
  211. package/dist/schema/settings/theme.d.ts +3 -15
  212. package/dist/schema/settings/theme.d.ts.map +1 -1
  213. package/dist/schema/utils/validation.d.ts.map +1 -1
  214. package/dist/schema/utils/validation.js +16 -3
  215. package/dist/schema/utils/validation.js.map +1 -1
  216. package/dist/specs/packages/library-type-spec.d.ts +4 -0
  217. package/dist/specs/packages/library-type-spec.d.ts.map +1 -1
  218. package/dist/specs/packages/library-type-spec.js +2 -2
  219. package/dist/specs/packages/library-type-spec.js.map +1 -1
  220. package/dist/testing/definition-helpers.test-helper.js +2 -2
  221. package/dist/testing/definition-helpers.test-helper.js.map +1 -1
  222. package/dist/testing/expression-stub-parser.test-helper.d.ts +2 -4
  223. package/dist/testing/expression-stub-parser.test-helper.d.ts.map +1 -1
  224. package/dist/testing/expression-stub-parser.test-helper.js +2 -10
  225. package/dist/testing/expression-stub-parser.test-helper.js.map +1 -1
  226. package/dist/testing/expression-warning-parser.test-helper.d.ts +2 -4
  227. package/dist/testing/expression-warning-parser.test-helper.d.ts.map +1 -1
  228. package/dist/testing/expression-warning-parser.test-helper.js +2 -8
  229. package/dist/testing/expression-warning-parser.test-helper.js.map +1 -1
  230. package/dist/testing/index.d.ts +1 -0
  231. package/dist/testing/index.d.ts.map +1 -1
  232. package/dist/testing/index.js +1 -0
  233. package/dist/testing/index.js.map +1 -1
  234. package/dist/testing/parser-context.test-helper.d.ts.map +1 -1
  235. package/dist/testing/parser-context.test-helper.js +2 -1
  236. package/dist/testing/parser-context.test-helper.js.map +1 -1
  237. package/dist/testing/plugin-store.test-helper.d.ts +11 -0
  238. package/dist/testing/plugin-store.test-helper.d.ts.map +1 -0
  239. package/dist/testing/plugin-store.test-helper.js +32 -0
  240. package/dist/testing/plugin-store.test-helper.js.map +1 -0
  241. package/dist/testing/project-definition-container.test-helper.d.ts.map +1 -1
  242. package/dist/testing/project-definition-container.test-helper.js +2 -1
  243. package/dist/testing/project-definition-container.test-helper.js.map +1 -1
  244. package/dist/tools/index.d.ts +2 -0
  245. package/dist/tools/index.d.ts.map +1 -1
  246. package/dist/tools/index.js +2 -0
  247. package/dist/tools/index.js.map +1 -1
  248. package/dist/tools/sort-entity-arrays.d.ts +15 -0
  249. package/dist/tools/sort-entity-arrays.d.ts.map +1 -0
  250. package/dist/tools/sort-entity-arrays.js +31 -0
  251. package/dist/tools/sort-entity-arrays.js.map +1 -0
  252. package/dist/utils/color-conversions.d.ts +12 -0
  253. package/dist/utils/color-conversions.d.ts.map +1 -1
  254. package/dist/utils/color-conversions.js +17 -1
  255. package/dist/utils/color-conversions.js.map +1 -1
  256. package/dist/utils/color-names.d.ts.map +1 -1
  257. package/dist/utils/color-names.js +6 -5
  258. package/dist/utils/color-names.js.map +1 -1
  259. package/dist/utils/definition-diff/definition-diff.js +2 -2
  260. package/dist/utils/definition-diff/definition-diff.js.map +1 -1
  261. package/dist/utils/theme.d.ts +1 -0
  262. package/dist/utils/theme.d.ts.map +1 -1
  263. package/dist/utils/theme.js +18 -10
  264. package/dist/utils/theme.js.map +1 -1
  265. package/dist/web/components/definition-diff-alert.js +2 -2
  266. package/dist/web/components/definition-diff-alert.js.map +1 -1
  267. package/dist/web/specs/admin-crud-action-web-spec.js +1 -1
  268. package/dist/web/specs/admin-crud-action-web-spec.js.map +1 -1
  269. package/dist/web/specs/admin-crud-column-web-spec.js +1 -1
  270. package/dist/web/specs/admin-crud-column-web-spec.js.map +1 -1
  271. package/dist/web/specs/admin-crud-input-web-spec.js +1 -1
  272. package/dist/web/specs/admin-crud-input-web-spec.js.map +1 -1
  273. package/dist/web/specs/model-transformer-web-spec.d.ts +19 -2
  274. package/dist/web/specs/model-transformer-web-spec.d.ts.map +1 -1
  275. package/dist/web/specs/model-transformer-web-spec.js +1 -1
  276. package/dist/web/specs/model-transformer-web-spec.js.map +1 -1
  277. package/package.json +8 -8
  278. package/dist/schema/models/authorizer/authorizer-expression-acorn-parser.d.ts.map +0 -1
  279. package/dist/schema/models/authorizer/authorizer-expression-acorn-parser.js.map +0 -1
  280. package/dist/schema/models/authorizer/authorizer-expression-ast.d.ts.map +0 -1
  281. package/dist/schema/models/authorizer/authorizer-expression-ast.js.map +0 -1
  282. package/dist/schema/models/authorizer/authorizer-expression-parser.d.ts.map +0 -1
  283. package/dist/schema/models/authorizer/authorizer-expression-parser.js +0 -145
  284. package/dist/schema/models/authorizer/authorizer-expression-parser.js.map +0 -1
  285. package/dist/schema/models/authorizer/authorizer-expression-validator.d.ts.map +0 -1
  286. package/dist/schema/models/authorizer/authorizer-expression-validator.js +0 -284
  287. package/dist/schema/models/authorizer/authorizer-expression-validator.js.map +0 -1
@@ -0,0 +1,292 @@
1
+ import { z } from 'zod';
2
+ import { RefExpressionParser } from '#src/references/expression-types.js';
3
+ import { modelAuthorizerRoleEntityType } from '#src/schema/models/authorizer/types.js';
4
+ import { modelForeignRelationEntityType, modelLocalRelationEntityType, modelScalarFieldEntityType, } from '#src/schema/models/types.js';
5
+ import { parseAuthorizerExpression } from './authorizer-expression-acorn-parser.js';
6
+ import { AuthorizerExpressionParseError } from './authorizer-expression-ast.js';
7
+ import { buildModelExpressionContext, validateAuthorizerExpression, } from './authorizer-expression-validator.js';
8
+ import { visitAuthorizerExpression } from './authorizer-expression-visitor.js';
9
+ /**
10
+ * Expression parser for model authorizer role expressions.
11
+ *
12
+ * Parses expressions like:
13
+ * - `model.id === auth.userId` (ownership check)
14
+ * - `auth.hasRole('admin')` (global role check)
15
+ * - `model.id === auth.userId || auth.hasRole('admin')` (combined)
16
+ *
17
+ * Uses Acorn to parse JavaScript expressions and validates
18
+ * that only supported constructs are used.
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * const schema = z.object({
23
+ * expression: ctx.withExpression(authorizerExpressionParser, { model: modelSlot }),
24
+ * });
25
+ * ```
26
+ */
27
+ export class AuthorizerExpressionParser extends RefExpressionParser {
28
+ name = 'authorizer-expression';
29
+ /**
30
+ * Creates a Zod schema for validating expression strings.
31
+ * Requires a non-empty string value.
32
+ */
33
+ createSchema() {
34
+ return z.string().min(1, 'Expression is required');
35
+ }
36
+ /**
37
+ * Parse the expression string into an AST.
38
+ *
39
+ * @param value - The expression string
40
+ * @returns Success with parsed expression info, or failure with error message
41
+ */
42
+ parse(value) {
43
+ try {
44
+ return { success: true, value: parseAuthorizerExpression(value) };
45
+ }
46
+ catch (error) {
47
+ if (error instanceof AuthorizerExpressionParseError) {
48
+ return { success: false, error: error.message };
49
+ }
50
+ throw error;
51
+ }
52
+ }
53
+ /**
54
+ * Get validation warnings for the expression.
55
+ *
56
+ * Validates:
57
+ * - Syntax errors from parsing
58
+ * - Model field references exist
59
+ * - Auth field references are valid
60
+ * - Role names exist in project config (warning only)
61
+ */
62
+ getWarnings(parseResult, context, resolvedSlots) {
63
+ // Get model context from resolved slots (throws if model not found)
64
+ const modelContext = this.getModelContext(context.definition, resolvedSlots);
65
+ // Validate the expression against model fields and roles
66
+ return validateAuthorizerExpression(parseResult.ast, modelContext, context.pluginStore, context.definition);
67
+ }
68
+ /**
69
+ * Get entity references from the expression with their positions.
70
+ *
71
+ * Walks the AST and resolves each name reference (field, relation, role)
72
+ * to its entity ID by navigating the model definition from the resolved slots.
73
+ * Returns positions marking exactly which text to replace when an entity is renamed.
74
+ */
75
+ getReferencedEntities(_value, parseResult, definition, resolvedSlots) {
76
+ if (!parseResult.success) {
77
+ return [];
78
+ }
79
+ const model = this.getRawModel(definition, resolvedSlots);
80
+ const allModels = definition.models.filter((m) => typeof m.name === 'string');
81
+ // Build lookup maps
82
+ const fieldByName = new Map();
83
+ for (const field of model.model.fields) {
84
+ fieldByName.set(field.name, { id: field.id });
85
+ }
86
+ const relationByName = new Map();
87
+ // Local relations (defined on this model)
88
+ for (const relation of model.model.relations) {
89
+ relationByName.set(relation.name, {
90
+ id: relation.id,
91
+ modelRef: relation.modelRef,
92
+ entityType: modelLocalRelationEntityType,
93
+ });
94
+ }
95
+ const modelById = new Map();
96
+ for (const m of allModels) {
97
+ modelById.set(m.id, m);
98
+ }
99
+ // Foreign relations (defined on other models pointing to this model via foreignRelationName)
100
+ for (const m of allModels) {
101
+ for (const relation of m.model.relations) {
102
+ if (relation.foreignRelationName && relation.modelRef === model.id) {
103
+ relationByName.set(relation.foreignRelationName, {
104
+ id: relation.foreignId,
105
+ // Foreign relation points back to the model that defines it
106
+ modelRef: m.id,
107
+ entityType: modelForeignRelationEntityType,
108
+ });
109
+ }
110
+ }
111
+ }
112
+ const deps = [];
113
+ const visitor = {
114
+ fieldComparison(node) {
115
+ for (const side of [node.left, node.right]) {
116
+ if (side.type === 'fieldRef' && side.source === 'model') {
117
+ const field = fieldByName.get(side.field);
118
+ if (field) {
119
+ deps.push({
120
+ entityType: modelScalarFieldEntityType,
121
+ entityId: field.id,
122
+ start: side.end - side.field.length,
123
+ end: side.end,
124
+ });
125
+ }
126
+ }
127
+ }
128
+ },
129
+ hasRole() {
130
+ // Global auth roles are defined by plugins, not navigable from
131
+ // the raw model definition. Skip — auth role renames are rare
132
+ // and would require traversing plugin-specific config.
133
+ },
134
+ hasSomeRole() {
135
+ // Same as hasRole — skip global auth role references
136
+ },
137
+ nestedHasRole(node) {
138
+ const relation = relationByName.get(node.relationName);
139
+ if (relation) {
140
+ deps.push({
141
+ entityType: relation.entityType,
142
+ entityId: relation.id,
143
+ start: node.relationEnd - node.relationName.length,
144
+ end: node.relationEnd,
145
+ });
146
+ // Foreign authorizer role
147
+ const foreignModel = modelById.get(relation.modelRef);
148
+ if (foreignModel) {
149
+ const foreignRole = foreignModel.authorizer.roles.find((r) => r.name === node.role);
150
+ if (foreignRole) {
151
+ deps.push({
152
+ entityType: modelAuthorizerRoleEntityType,
153
+ entityId: foreignRole.id,
154
+ start: node.roleStart + 1,
155
+ end: node.roleEnd - 1,
156
+ });
157
+ }
158
+ }
159
+ }
160
+ },
161
+ nestedHasSomeRole(node) {
162
+ const relation = relationByName.get(node.relationName);
163
+ if (relation) {
164
+ deps.push({
165
+ entityType: relation.entityType,
166
+ entityId: relation.id,
167
+ start: node.relationEnd - node.relationName.length,
168
+ end: node.relationEnd,
169
+ });
170
+ const foreignModel = modelById.get(relation.modelRef);
171
+ if (foreignModel) {
172
+ const foreignRoleByName = new Map(foreignModel.authorizer.roles.map((r) => [r.name, r]));
173
+ for (let i = 0; i < node.roles.length; i++) {
174
+ const foreignRole = foreignRoleByName.get(node.roles[i]);
175
+ if (foreignRole) {
176
+ deps.push({
177
+ entityType: modelAuthorizerRoleEntityType,
178
+ entityId: foreignRole.id,
179
+ start: node.rolesStart[i] + 1,
180
+ end: node.rolesEnd[i] - 1,
181
+ });
182
+ }
183
+ }
184
+ }
185
+ }
186
+ },
187
+ relationFilter(node) {
188
+ const relation = relationByName.get(node.relationName);
189
+ if (relation) {
190
+ deps.push({
191
+ entityType: relation.entityType,
192
+ entityId: relation.id,
193
+ start: node.relationEnd - node.relationName.length,
194
+ end: node.relationEnd,
195
+ });
196
+ // Foreign model fields referenced in conditions
197
+ const foreignModel = modelById.get(relation.modelRef);
198
+ const foreignFieldByName = new Map();
199
+ if (foreignModel) {
200
+ for (const f of foreignModel.model.fields) {
201
+ foreignFieldByName.set(f.name, { id: f.id });
202
+ }
203
+ }
204
+ for (const condition of node.conditions) {
205
+ // Condition key references a field on the foreign model
206
+ const foreignField = foreignFieldByName.get(condition.field);
207
+ if (foreignField) {
208
+ deps.push({
209
+ entityType: modelScalarFieldEntityType,
210
+ entityId: foreignField.id,
211
+ start: condition.fieldStart,
212
+ end: condition.fieldEnd,
213
+ });
214
+ }
215
+ // Condition value may be a model field ref
216
+ if (condition.value.type === 'fieldRef' &&
217
+ condition.value.source === 'model') {
218
+ const field = fieldByName.get(condition.value.field);
219
+ if (field) {
220
+ deps.push({
221
+ entityType: modelScalarFieldEntityType,
222
+ entityId: field.id,
223
+ start: condition.value.end - condition.value.field.length,
224
+ end: condition.value.end,
225
+ });
226
+ }
227
+ }
228
+ }
229
+ }
230
+ },
231
+ isAuthenticated() {
232
+ // No entity references
233
+ },
234
+ binaryLogical(_node, _ctx, visit) {
235
+ visit(_node.left);
236
+ visit(_node.right);
237
+ },
238
+ };
239
+ visitAuthorizerExpression(parseResult.value.ast, visitor);
240
+ return deps;
241
+ }
242
+ /**
243
+ * Navigate to the raw model object from the definition using resolved slots.
244
+ *
245
+ * Resolved slot paths point to the entity's ID field (e.g., `['models', 2, 'id']`),
246
+ * so we walk parent paths until we find an object with a string `name` property.
247
+ */
248
+ getRawModel(definition, resolvedSlots) {
249
+ const modelPath = resolvedSlots.model;
250
+ // Walk progressively shorter paths to find the model object.
251
+ // Slot paths include the idPath suffix (e.g., ['models', 2, 'id']),
252
+ // so we try the full path first, then strip segments until we find
253
+ // an object with a name property.
254
+ for (let len = modelPath.length; len > 0; len--) {
255
+ let current = definition;
256
+ for (let i = 0; i < len; i++) {
257
+ if (current === null || current === undefined) {
258
+ break;
259
+ }
260
+ current = current[modelPath[i]];
261
+ }
262
+ if (current !== null &&
263
+ current !== undefined &&
264
+ typeof current === 'object' &&
265
+ 'name' in current &&
266
+ typeof current.name === 'string') {
267
+ return current;
268
+ }
269
+ }
270
+ throw new Error(`Could not resolve model at path ${modelPath.join('.')}`);
271
+ }
272
+ /**
273
+ * Extract model context from the project definition using resolved slots.
274
+ */
275
+ getModelContext(definition, resolvedSlots) {
276
+ const model = this.getRawModel(definition, resolvedSlots);
277
+ const allModels = definition.models.filter((m) => typeof m.name === 'string');
278
+ return buildModelExpressionContext({
279
+ id: model.id,
280
+ name: model.name,
281
+ fields: model.model.fields,
282
+ model: { relations: model.model.relations },
283
+ }, allModels.map((m) => ({
284
+ id: m.id,
285
+ name: m.name,
286
+ authorizer: m.authorizer,
287
+ fields: m.model.fields,
288
+ model: { relations: m.model.relations },
289
+ })));
290
+ }
291
+ }
292
+ //# sourceMappingURL=authorizer-expression-parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorizer-expression-parser.js","sourceRoot":"","sources":["../../../src/expression-parsers/authorizer/authorizer-expression-parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAcxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AACvF,OAAO,EACL,8BAA8B,EAC9B,4BAA4B,EAC5B,0BAA0B,GAC3B,MAAM,6BAA6B,CAAC;AAMrC,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AACpF,OAAO,EAAE,8BAA8B,EAAE,MAAM,gCAAgC,CAAC;AAChF,OAAO,EACL,2BAA2B,EAC3B,4BAA4B,GAC7B,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AAE/E;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,0BAA2B,SAAQ,mBAI/C;IACU,IAAI,GAAG,uBAAuB,CAAC;IAExC;;;OAGG;IACH,YAAY;QACV,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,wBAAwB,CAAC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K,CAAC,KAAK,CAAC,MAAM;YAC1B,KAAK,EAAE,EAAE,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,SAAS,EAAE;SAC5C,EACD,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACpB,EAAE,EAAE,CAAC,CAAC,EAAE;YACR,IAAI,EAAE,CAAC,CAAC,IAAI;YACZ,UAAU,EAAE,CAAC,CAAC,UAAU;YACxB,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM;YACtB,KAAK,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,SAAS,EAAE;SACxC,CAAC,CAAC,CACJ,CAAC;IACJ,CAAC;CACF"}
@@ -8,7 +8,6 @@
8
8
  */
9
9
  import type { PluginSpecStore } from '#src/plugins/index.js';
10
10
  import type { RefExpressionWarning } from '#src/references/expression-types.js';
11
- import type { ModelConfig } from '../models.js';
12
11
  import type { AuthorizerExpressionNode } from './authorizer-expression-ast.js';
13
12
  /**
14
13
  * Information about a model relation for nested authorizer validation.
@@ -20,6 +19,12 @@ export interface RelationValidationInfo {
20
19
  foreignModelName: string;
21
20
  /** Set of role names defined on the foreign model's authorizer */
22
21
  foreignAuthorizerRoleNames: Set<string>;
22
+ /** Scalar field names on the foreign model (for relation filter condition validation) */
23
+ foreignScalarFieldNames?: Set<string>;
24
+ /** Field type map for the foreign model (for type-checking relation filter condition values) */
25
+ foreignFieldTypes?: Map<string, string>;
26
+ /** Whether this is a local relation (FK on this model) or foreign/reverse (FK on the other model) */
27
+ direction: 'local' | 'foreign';
23
28
  }
24
29
  /**
25
30
  * Model information needed for validation.
@@ -55,20 +60,11 @@ export interface ModelValidationContext {
55
60
  */
56
61
  export declare function validateAuthorizerExpression(ast: AuthorizerExpressionNode, modelContext: ModelValidationContext, pluginStore: PluginSpecStore, definition: unknown): RefExpressionWarning[];
57
62
  /**
58
- * Build relation validation info from model relations and the full list of models.
59
- *
63
+ * Shape of a model for expression context building.
60
64
  * Uses structural typing so both raw JSON shapes and typed `ModelConfig` objects
61
65
  * can be passed directly.
62
- *
63
- * @param modelRelations - The relations on the current model
64
- * @param allModels - All models in the project (for foreign model lookup)
65
- * @returns Map of relation name → validation info
66
66
  */
67
- export declare function buildRelationValidationInfo(modelRelations: readonly {
68
- name: string;
69
- modelRef: string;
70
- references: readonly unknown[];
71
- }[], allModels: readonly {
67
+ interface ExpressionContextModel {
72
68
  id?: string;
73
69
  name: string;
74
70
  authorizer?: {
@@ -76,12 +72,36 @@ export declare function buildRelationValidationInfo(modelRelations: readonly {
76
72
  name: string;
77
73
  }[];
78
74
  };
79
- }[]): Map<string, RelationValidationInfo>;
75
+ /** Top-level fields (used by raw JSON shapes) */
76
+ fields?: readonly {
77
+ name: string;
78
+ type?: string;
79
+ }[];
80
+ model?: {
81
+ /** Nested fields (used by typed ModelConfig objects) */
82
+ fields?: readonly {
83
+ name: string;
84
+ type?: string;
85
+ }[];
86
+ relations?: readonly {
87
+ name: string;
88
+ modelRef: string;
89
+ foreignRelationName?: string;
90
+ references?: readonly unknown[];
91
+ }[];
92
+ };
93
+ }
80
94
  /**
81
- * Extract model validation context from a model configuration.
95
+ * Build complete model expression context from a model and all project models.
96
+ *
97
+ * This is the primary entry point for building validation and autocomplete context.
98
+ * It discovers both local relations (FK on this model) and foreign/reverse relations
99
+ * (FK on other models pointing to this model) for use with `hasRole()`, `exists()`, `all()`, etc.
82
100
  *
83
- * @param modelConfig - The parsed model configuration
84
- * @returns Model validation context for the validator
101
+ * @param model - The current model (structural typing: works with both typed ModelConfig and raw JSON)
102
+ * @param allModels - All models in the project
103
+ * @returns Complete model validation context including all relations
85
104
  */
86
- export declare function createModelValidationContext(modelConfig: ModelConfig): ModelValidationContext;
105
+ export declare function buildModelExpressionContext(model: ExpressionContextModel, allModels: readonly ExpressionContextModel[]): ModelValidationContext;
106
+ export {};
87
107
  //# sourceMappingURL=authorizer-expression-validator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorizer-expression-validator.d.ts","sourceRoot":"","sources":["../../../src/expression-parsers/authorizer/authorizer-expression-validator.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAKhF,OAAO,KAAK,EACV,wBAAwB,EAGzB,MAAM,gCAAgC,CAAC;AAKxC;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,iFAAiF;IACjF,cAAc,EAAE,MAAM,CAAC;IACvB,8CAA8C;IAC9C,gBAAgB,EAAE,MAAM,CAAC;IACzB,kEAAkE;IAClE,0BAA0B,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACxC,yFAAyF;IACzF,uBAAuB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACtC,gGAAgG;IAChG,iBAAiB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,qGAAqG;IACrG,SAAS,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,0CAA0C;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,mDAAmD;IACnD,gBAAgB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC9B,iEAAiE;IACjE,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,qFAAqF;IACrF,YAAY,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;CACpD;AAyCD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,4BAA4B,CAC1C,GAAG,EAAE,wBAAwB,EAC7B,YAAY,EAAE,sBAAsB,EACpC,WAAW,EAAE,eAAe,EAC5B,UAAU,EAAE,OAAO,GAClB,oBAAoB,EAAE,CA6SxB;AAED;;;;GAIG;AACH,UAAU,s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