@cmflow/atlas 3.4.0-beta.9 → 3.5.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 (50) hide show
  1. package/README.md +82 -22
  2. package/dist/{types-cYprdLUO.d.mts → UserConfig-BlRknCRh.d.mts} +38 -15
  3. package/dist/bin/atlas.d.mts +2 -0
  4. package/dist/bin/atlas.mjs +22553 -2982
  5. package/dist/bin/atlas.mjs.map +1 -0
  6. package/dist/defineExpressionRule-GhkeHHT8.mjs +10 -0
  7. package/dist/defineExpressionRule-GhkeHHT8.mjs.map +1 -0
  8. package/dist/dist-DedUrNm2.mjs +6950 -0
  9. package/dist/dist-DedUrNm2.mjs.map +1 -0
  10. package/dist/index.d.mts +12 -10
  11. package/dist/index.mjs +1317 -1
  12. package/dist/index.mjs.map +1 -1
  13. package/dist/rolldown-runtime-CGR6nZuH.mjs +34 -0
  14. package/dist/routeBackendTopologyService-bbiOHBq0.mjs +8769 -0
  15. package/dist/routeBackendTopologyService-bbiOHBq0.mjs.map +1 -0
  16. package/dist/rules/lodashGetRule.d.mts +2 -1
  17. package/dist/rules/lodashGetRule.mjs +23 -1
  18. package/dist/rules/lodashGetRule.mjs.map +1 -1
  19. package/dist/rules/mappingUtilityRule.d.mts +2 -1
  20. package/dist/rules/mappingUtilityRule.mjs +37 -1
  21. package/dist/rules/mappingUtilityRule.mjs.map +1 -1
  22. package/dist/rules/memberGetFieldRule.d.mts +2 -1
  23. package/dist/rules/memberGetFieldRule.mjs +26 -1
  24. package/dist/rules/memberGetFieldRule.mjs.map +1 -1
  25. package/dist/taskProgressService-BIc_o1wl.mjs +1247 -0
  26. package/dist/taskProgressService-BIc_o1wl.mjs.map +1 -0
  27. package/dist/token-CiiblKFL.mjs +62 -0
  28. package/dist/token-CiiblKFL.mjs.map +1 -0
  29. package/dist/token-util-Br4-y5kE.mjs +7 -0
  30. package/dist/token-util-Dnzm6rU4.mjs +471 -0
  31. package/dist/token-util-Dnzm6rU4.mjs.map +1 -0
  32. package/dist/workers/routeBackendTopologyWorker.d.mts +2 -0
  33. package/dist/workers/routeBackendTopologyWorker.mjs +29 -19
  34. package/dist/workers/routeBackendTopologyWorker.mjs.map +1 -0
  35. package/package.json +15 -14
  36. package/dist/defineExpressionRule-Dfvzj6n2.mjs +0 -2
  37. package/dist/defineExpressionRule-Dfvzj6n2.mjs.map +0 -1
  38. package/dist/routeBackendTopologyService-DElirHSh.mjs +0 -820
  39. package/dist/rules/cleanObjectRule.d.mts +0 -6
  40. package/dist/rules/cleanObjectRule.mjs +0 -2
  41. package/dist/rules/cleanObjectRule.mjs.map +0 -1
  42. package/dist/rules/cmsI18nFieldRule.d.mts +0 -12
  43. package/dist/rules/cmsI18nFieldRule.mjs +0 -2
  44. package/dist/rules/cmsI18nFieldRule.mjs.map +0 -1
  45. package/dist/rules/dateConversionRule.d.mts +0 -6
  46. package/dist/rules/dateConversionRule.mjs +0 -2
  47. package/dist/rules/dateConversionRule.mjs.map +0 -1
  48. package/dist/rules/quableI18nFieldRule.d.mts +0 -6
  49. package/dist/rules/quableI18nFieldRule.mjs +0 -2
  50. package/dist/rules/quableI18nFieldRule.mjs.map +0 -1
package/README.md CHANGED
@@ -42,7 +42,7 @@ atlas init
42
42
  atlas --config /path/to/api/atlas.config.ts init
43
43
  ```
44
44
 
45
- By default, Atlas loads `atlas.config.ts` from the directory where the command is launched. Use `--config` (or `-c`) to reference another configuration file. Use `--project-root` only to override the API project directory to analyze.
45
+ By default, Atlas loads `atlas.config.ts` from the directory where the command is launched. Use `--config` (or `-c`) to reference another configuration file. Use `--analysis-dir` only to override the API source directory to analyze.
46
46
 
47
47
  The configuration imports `defineConfig` from Atlas:
48
48
 
@@ -50,26 +50,55 @@ The configuration imports `defineConfig` from Atlas:
50
50
  import { defineConfig } from "@cmflow/atlas";
51
51
 
52
52
  export default defineConfig({
53
+ outputDir: "./tmp/atlas",
54
+ envs: {
55
+ XM_API_URL: "https://xm.example/openapi.json"
56
+ },
53
57
  openapiUrl: "https://api.example.com/openapi.json",
54
58
  openapiTimeoutMs: 60_000,
55
59
  directusUrl: "https://cms.api.clubmed",
56
60
  analysis: {
61
+ rootDir: "./app",
57
62
  backends: ["ICC", "CMS", "CMS_B2C"]
58
63
  }
59
64
  });
60
65
  ```
61
66
 
62
- Atlas reads `compilerOptions.paths` from the `tsconfig.json` in the directory where the command is run (`process.cwd()`) and uses them as module aliases. `repoRoot` only defines the source tree to analyze and may therefore point to a subdirectory. Add `resolver.alias` only to override or complement those aliases.
67
+ `process.cwd()` is always the project root: `outputDir`, `tsconfig.json`, Git paths and serialized source paths are resolved from it. `analysis.rootDir` only defines the source tree to analyze and may therefore point to a subdirectory such as `./app`. Atlas reads `compilerOptions.paths` from the root `tsconfig.json` and uses them as module aliases. Add `resolver.alias` only to override or complement those aliases.
68
+
69
+ `outputDir` is resolved from the project root, not from `analysis.rootDir`. With the configuration above, artifacts are written to `<project-root>/tmp/atlas`, never to `<project-root>/app/tmp/atlas`.
70
+
71
+ Use `analysis.excluded` for project-root-relative technical files that must not enter dependency traversal or `analysis_files`:
72
+
73
+ ```ts
74
+ analysis: {
75
+ rootDir: "./app",
76
+ excluded: ["tools/build/*-reference.json"],
77
+ backends: [/* ... */]
78
+ }
79
+ ```
63
80
 
64
81
  ## Backend sources
65
82
 
66
- Atlas extracts a candidate mapping from code, then optionally consolidates it against a strict backend field reference. Configure these references in the same `analysis.backends` list used to declare backends.
83
+ Atlas starts from accesses actually detected in code on a backend reached by the route graph. It then consolidates those code candidates against the canonical properties returned by the matching `BackendSource`. Atlas never creates a confirmed mapping from API field-name similarity alone.
84
+
85
+ For a backend with no configured source, Atlas preserves code candidates for optional AI inference. A configured source is authoritative: only its resolved properties can validate the code access.
67
86
 
68
87
  A backend can be either a string or a `BackendSource` created with `defineBackendSource`:
69
88
 
70
89
  - a string (for example `"ICC"`) has no field reference; Atlas keeps the current code-analysis and optional inference flow;
71
90
  - a `BackendSource` provides a `resolve` function that returns the backend's known properties. Atlas assigns its `name` as `backend` on every resolved property.
72
91
 
92
+ Any backend source can persist its resolved properties in a YAML cache. When the cache exists, Atlas uses it and does not call the remote source. Refresh it explicitly with `atlas backend-source --refresh` (or the compatible `atlas backend-sources --refresh`). Use `atlas backend-sources --refresh --all` to refresh every configured source without an interactive prompt.
93
+
94
+ ```ts
95
+ export const xm = defineBackendSource({
96
+ name: "XM",
97
+ cache: `${__dirname}/cache.yaml`,
98
+ resolve: () => openapiSource({ url: "https://xm.example/openapi.json" })
99
+ });
100
+ ```
101
+
73
102
  When a string and a source share the same name, the last declaration wins. This lets a source enrich a list of backend names, for example `[..., Object.values(BackendTypes), quableBackendSource]`.
74
103
 
75
104
  The resolver returns one of the following shapes. Document-oriented backends have no route; REST backends have no document.
@@ -91,12 +120,23 @@ type BackendProperty =
91
120
 
92
121
  The generated mapping preserves this shape. In particular, `document` is a separate property: Atlas does not turn a Quable field into an artificial path such as `products.product_geographical_area`.
93
122
 
123
+ ## Resolved backend metadata artifacts
124
+
125
+ At the start of `generate:graph` and `generate:catalog`, Atlas resolves every configured backend source and writes its metadata for inspection:
126
+
127
+ ```text
128
+ <outputDir>/backends/<backend>.yaml
129
+ ```
130
+
131
+ For example, `<outputDir>/backends/quable_rest.yaml` contains the source name, generation date and canonical properties returned by Quable. Backends declared as strings still receive an artifact with `resolved: false`; this makes missing metadata sources visible during analysis.
132
+
94
133
  ### Quable
95
134
 
96
135
  Attach rules that are specific to Quable directly to its source. They inherit the source backend automatically and their candidates are validated by the Quable property list.
97
136
 
98
137
  ```ts
99
- import { defineBackendSource, httpClient, quableI18nFieldRule } from "@cmflow/atlas";
138
+ import { defineBackendSource, httpClient } from "@cmflow/atlas";
139
+ import { quableI18nFieldRule } from "./atlas-rules";
100
140
 
101
141
  export const quable = defineBackendSource({
102
142
  name: "QUABLE",
@@ -131,7 +171,8 @@ For example, the resolver above may return:
131
171
  CMS Directus follows the same document-oriented contract. Its `cmsI18nFieldRule` is owned by the CMS source rather than registered as a global expression rule.
132
172
 
133
173
  ```ts
134
- import { defineBackendSource, cmsI18nFieldRule } from "@cmflow/atlas";
174
+ import { defineBackendSource } from "@cmflow/atlas";
175
+ import { cmsI18nFieldRule } from "./atlas-rules";
135
176
 
136
177
  export const cmsDirectus = defineBackendSource({
137
178
  name: "CMS",
@@ -147,7 +188,8 @@ export const cmsDirectus = defineBackendSource({
147
188
  CMS Legacy is configured identically, with its own resolver and backend identifier. It may reuse `cmsI18nFieldRule` when the backend uses `CmsI18n` helpers.
148
189
 
149
190
  ```ts
150
- import { defineBackendSource, cmsI18nFieldRule } from "@cmflow/atlas";
191
+ import { defineBackendSource } from "@cmflow/atlas";
192
+ import { cmsI18nFieldRule } from "./atlas-rules";
151
193
 
152
194
  export const cmsLegacy = defineBackendSource({
153
195
  name: "CMS_LEGACY",
@@ -165,6 +207,7 @@ import { constant, defineBackendSource, openapiSource } from "@cmflow/atlas";
165
207
 
166
208
  export const xm = defineBackendSource({
167
209
  name: "XM",
210
+ cache: `${__dirname}/xm-openapi.yaml`,
168
211
  resolve: () =>
169
212
  openapiSource({
170
213
  url: constant<string>("XM_API_URL", "https://xm.example/openapi.json")
@@ -172,13 +215,13 @@ export const xm = defineBackendSource({
172
215
  });
173
216
  ```
174
217
 
175
- `constant` resolves an environment variable directly from `process.env`, falling back to its second argument. No resolver context is required.
218
+ `constant` resolves a value declared in `envs`, falling back to its second argument. No resolver context is required.
176
219
 
177
220
  ### Environment constants
178
221
 
179
- Use `constant` when a backend source needs a configurable value such as a URL or an access token. The value is resolved when the source runs:
222
+ Use `constant` when a backend source needs a configurable value such as a URL or an access token. Declare injected values at the root of `atlas.config.ts`; the value is resolved when the source runs:
180
223
 
181
- 1. Atlas uses `process.env[name]` when it is set.
224
+ 1. Atlas uses `envs[name]` when it is set.
182
225
  2. Otherwise, it returns the supplied default value.
183
226
 
184
227
  ```ts
@@ -193,12 +236,19 @@ export const xmBackendSource = defineBackendSource({
193
236
  });
194
237
  ```
195
238
 
196
- For example, override the default in CI or locally:
239
+ For example, configure the endpoint used by the source:
197
240
 
198
- ```bash
199
- XM_API_URL=https://xm.internal/openapi.json atlas backend-sources --backend XM
241
+ ```ts
242
+ export default defineConfig({
243
+ envs: {
244
+ XM_API_URL: "https://xm.internal/openapi.json"
245
+ }
246
+ // …other Atlas options
247
+ });
200
248
  ```
201
249
 
250
+ `envs` can itself be populated from `process.env` when appropriate for the project.
251
+
202
252
  This returns entries such as:
203
253
 
204
254
  ```ts
@@ -227,7 +277,7 @@ export default defineConfig({
227
277
 
228
278
  ## Custom expression rules
229
279
 
230
- Use `defineExpressionRule` when a project-specific helper hides a backend field or wraps an expression that Atlas should follow. Add a cross-backend rule to `analysis.rules` in `atlas.config.ts`. Attach a backend-specific rule, such as `quableI18nFieldRule` or `cmsI18nFieldRule`, to `defineBackendSource({ rules: [...] })` instead.
280
+ Use `defineExpressionRule` when a project-specific helper hides a backend field or wraps an expression that Atlas should follow. Define those rules in the analyzed project, add a cross-backend rule to `analysis.rules` in `atlas.config.ts`, and attach backend-specific rules to `defineBackendSource({ rules: [...] })` instead.
231
281
 
232
282
  `match` is a cheap predicate that selects the `ts-morph` expression. `parse` returns the information Atlas should use: a backend field, a transparent wrapper, or both.
233
283
 
@@ -281,23 +331,30 @@ DIRECTUS_TOKEN=replace-with-a-static-token
281
331
  Generate the topology first, then the route catalogue:
282
332
 
283
333
  ```bash
284
- atlas --project-root /path/to/api generate:graph
285
- atlas --project-root /path/to/api generate:catalog --output .tmp/datasource-catalogue
334
+ atlas --analysis-dir /path/to/api generate:graph
335
+ atlas --analysis-dir /path/to/api generate:catalog --output .tmp/datasource-catalogue
286
336
  ```
287
337
 
288
338
  Each route produces a YAML document and a `.graph.yaml` topology artifact. The catalogue requires a valid graph and leaves ambiguous fields marked `needs_review`.
289
339
 
340
+ When changing `analysis.rootDir`, backend sources or exclusions, regenerate the graph before the catalogue so the route graph and metadata artifacts use the same configuration:
341
+
342
+ ```bash
343
+ atlas generate:graph "GET /v2/products"
344
+ atlas generate:catalog "GET /v2/products"
345
+ ```
346
+
290
347
  Check configured coverage baselines:
291
348
 
292
349
  ```bash
293
- atlas --project-root /path/to/api generate:test
350
+ atlas --analysis-dir /path/to/api generate:test
294
351
  ```
295
352
 
296
353
  Review unresolved mappings or run optional AI inference:
297
354
 
298
355
  ```bash
299
- atlas --project-root /path/to/api needs-review --sort percentage --limit 25
300
- atlas --project-root /path/to/api infer .tmp/datasource-catalogue
356
+ atlas --analysis-dir /path/to/api needs-review --sort percentage --limit 25
357
+ atlas --analysis-dir /path/to/api infer .tmp/datasource-catalogue
301
358
  ```
302
359
 
303
360
  The inference pass only reads analysis files referenced by each route graph. Accepted suggestions remain marked `inferred`; suggestions below the configured confidence threshold are retained for manual review.
@@ -305,16 +362,17 @@ The inference pass only reads analysis files referenced by each route graph. Acc
305
362
  Push route artifacts to Directus with an explicit write flag:
306
363
 
307
364
  ```bash
308
- atlas --project-root /path/to/api push .tmp/datasource-catalogue --write
365
+ atlas --analysis-dir /path/to/api push .tmp/datasource-catalogue --update
309
366
  ```
310
367
 
311
- Without `--write`, the command performs a dry run. Use `clean-orphans` to inspect Directus links that no longer reference an API or backend property.
368
+ Without `--update`, the command performs a dry run. Use `clean-orphans` to inspect Directus links that no longer reference an API or backend property.
312
369
 
313
370
  ## Command reference
314
371
 
315
372
  ```text
316
373
  atlas init Create atlas.config.ts
317
- atlas backend-sources Execute backend sources and display resolved metadata
374
+ atlas backend-source [--refresh] Display backend metadata; refresh configured source caches when requested
375
+ atlas backend-sources [--refresh] [--all] Compatible plural alias; --all skips the source picker
318
376
  atlas generate:graph Trace API routes to backends
319
377
  atlas generate:catalog [route] Generate route review documents
320
378
  atlas generate:test Check configured coverage baselines
@@ -340,6 +398,8 @@ yarn workspace @cmflow/atlas test
340
398
 
341
399
  ## License
342
400
 
343
- LicenseThe MIT License (MIT)Copyright (c) 2016 - Today ClubMed
401
+ The MIT License (MIT)
402
+
403
+ Copyright (c) 2016 - Today ClubMed
344
404
 
345
405
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,5 +1,6 @@
1
+
1
2
  import { Expression } from "ts-morph";
2
- //#region src/utils/defineExpressionRule.d.ts
3
+ //#region src/fn/defineExpressionRule.d.ts
3
4
  type FieldExtractionRuleResult = {
4
5
  backendField?: string;
5
6
  transparent?: boolean;
@@ -15,12 +16,21 @@ type FieldExtractionRule = {
15
16
  };
16
17
  declare function defineExpressionRule(rule: FieldExtractionRule): FieldExtractionRule;
17
18
  //#endregion
18
- //#region src/models/types.d.ts
19
- interface NeutralExpressionMatcher {
20
- prefix: string;
21
- apiMapping?: boolean;
19
+ //#region src/interfaces/Direction.d.ts
20
+ type Direction = "input" | "output";
21
+ //#endregion
22
+ //#region src/interfaces/PropertyLocation.d.ts
23
+ type PropertyLocation = "query" | "path" | "header" | "body";
24
+ //#endregion
25
+ //#region src/interfaces/PropertyMetadata.d.ts
26
+ interface PropertyMetadata {
27
+ direction?: Direction;
28
+ location?: PropertyLocation;
29
+ type?: string;
22
30
  }
23
- type BackendProperty = {
31
+ //#endregion
32
+ //#region src/interfaces/BackendProperty.d.ts
33
+ type BackendProperty = PropertyMetadata & ({
24
34
  document: string;
25
35
  field: string;
26
36
  description?: string;
@@ -29,18 +39,27 @@ type BackendProperty = {
29
39
  method: string;
30
40
  field: string;
31
41
  description?: string;
32
- };
42
+ });
43
+ //#endregion
44
+ //#region src/interfaces/BackendSource.d.ts
33
45
  interface BackendSource {
34
46
  name: string;
47
+ /** YAML file containing resolved properties. Existing caches are read before calling `resolve`. */
48
+ cache?: string;
35
49
  resolve?: () => Promise<BackendProperty[]>;
36
50
  rules?: FieldExtractionRule[];
37
51
  }
52
+ //#endregion
53
+ //#region src/config/interfaces/UserConfig.d.ts
54
+ interface NeutralExpressionMatcher {
55
+ prefix: string;
56
+ apiMapping?: boolean;
57
+ }
38
58
  interface UserConfig {
39
- /**
40
- * Absolute path to the root of the repository to analyze (e.g. the digital-api repo).
41
- * Can be set via the ATLAS_CWD environment variable.
42
- */
43
- repoRoot?: string;
59
+ /** Values injectable into backend source resolvers through `constant`. */
60
+ envs?: Record<string, unknown>;
61
+ /** Directory where Atlas writes generated graph and catalogue artifacts, resolved from `process.cwd()`. */
62
+ outputDir: string;
44
63
  /**
45
64
  * Default OpenAPI document URL used to extract the public contract exposed by the API.
46
65
  * The CLI can still override this value with `--openapi-url`.
@@ -50,6 +69,8 @@ interface UserConfig {
50
69
  openapiTimeoutMs: number;
51
70
  /** Default Directus base URL used by `push` when no CLI option or environment variable overrides it. */
52
71
  directusUrl: string;
72
+ /** Default Directus token used by `push` when no CLI option or environment variable overrides it. */
73
+ directusToken: string;
53
74
  /**
54
75
  * Module aliases resolved while traversing static-analysis dependencies.
55
76
  * Defaults are read from `compilerOptions.paths` in the repository tsconfig.
@@ -75,10 +96,12 @@ interface UserConfig {
75
96
  * Static analysis options used to keep generated artifacts focused on business-relevant files and fields.
76
97
  */
77
98
  analysis: {
99
+ /** Directory containing the application source tree to analyze, resolved from `process.cwd()`. */
100
+ rootDir: string;
78
101
  /** Backend identifiers used by the API project. */
79
102
  backends: Array<string | BackendSource>;
80
103
  /**
81
- * Glob patterns excluded from `analysis_files`.
104
+ * Glob patterns, relative to the project working directory, excluded from `analysis_files`.
82
105
  * Use this to hide technical plumbing files that add noise to route review documents.
83
106
  */
84
107
  excluded: string[];
@@ -115,5 +138,5 @@ interface UserConfig {
115
138
  };
116
139
  }
117
140
  //#endregion
118
- export { defineExpressionRule as a, FieldExtractionRule as i, BackendSource as n, UserConfig as r, BackendProperty as t };
119
- //# sourceMappingURL=types-cYprdLUO.d.mts.map
141
+ export { defineExpressionRule as a, FieldExtractionRule as i, BackendSource as n, BackendProperty as r, UserConfig as t };
142
+ //# sourceMappingURL=UserConfig-BlRknCRh.d.mts.map
@@ -0,0 +1,2 @@
1
+
2
+ export {}