Commit 6dd575d
authored
Update typed FieldMask in sdk-core (#101)
## 🥞 Stacked PR
Use this [link](https://github.com/databricks/sdk-js/pull/101/files) to
review incremental changes.
-
[**stack/field-mask-sdk-core**](#101)
[[Files changed](https://github.com/databricks/sdk-js/pull/101/files)]
-
[stack/generator-field-mask](#102)
[[Files
changed](https://github.com/databricks/sdk-js/pull/102/files/9662ed8687549fc04fb0dd2588bb8d3c5e59853b..b49f0f673265f605667d95501e6beaea9630647d)]
-
[stack/field-mask-convertors](#100)
[[Files
changed](https://github.com/databricks/sdk-js/pull/100/files/b49f0f673265f605667d95501e6beaea9630647d..7b206bc649bc57d0915f922997954ce0323ff8ef)]
---------
## Summary
Update the `FieldMask<T>` in `@databricks/sdk-core/wkt`.
`FieldMask.build` validates paths against a per-message schema,
translates them to wire format, and stores the result privately.
`toString()` serializes to the comma-separated wire string the server
expects.
## Why
Databricks accepts field-mask paths in proto snake_case, but generated
TS interfaces use camelCase. The existing `FieldMask` didn't translate
or validate — typos went silently to the server. This is the runtime
foundation the generator needs; the follow-up PR emits the per-message
schemas and factories that call `FieldMask.build`.
### Why validation is at runtime, not compile time
A compile-time `FieldPaths<T>` conditional type (computing the
string-literal union of valid paths for each generated interface) was
explored and rejected. TypeScript's conditional-type evaluation has a
hard recursion depth limit — any proto message that references itself or
forms a cycle through another message (common in Databricks' schemas:
`Node { child: Node }`, `A → B → A`) triggers `TS2589: Type
instantiation is excessively deep and possibly infinite`. Verified by
probing against the real sdk-js `tsconfig`. Because we can't express a
complete set of valid paths at the type level for the schemas we
actually ship, `FieldMask.build` walks the schema at runtime and throws
on a mismatch instead. The schema itself is a plain runtime object with
lazy `() => FieldMaskSchema` child references, which keeps recursive and
mutually-recursive protos describable as finite graphs.
## What changed
### Interface changes
- **`FieldMask<T = unknown>`** — private constructor, `@internal static
build<T>(paths, schema)` as the sole entry point, `toString(): string`
returning the joined wire paths. Phantom `T` distinguishes masks across
messages at compile time.
- **`FieldMaskSchema`, `FieldMaskSchemaField`** — new exports. The shape
the generator emits per message; `children?: () => FieldMaskSchema`
keeps recursive/mutual-recursive protos cycle-safe.
- **Removed**: `FieldPaths<T>`, `FieldMask.of(...)`,
`FieldMask.append(...)`. See the "Why validation is at runtime" note
above for the rationale.
### Behavioral changes
`FieldMask.build` throws on an unknown path segment or descent past a
scalar leaf. Before, any string was accepted.
### Internal changes
`walkFieldMaskPath` and `normalize` are module-private in
`packages/core/src/wkt/fieldmask.ts`.
## How is this tested?
Table-driven tests (`it.each`) in
`packages/core/tests/wkt/fieldmask.test.ts`:
- **Valid paths translate and serialize** (8 cases): flat, nested, deep,
multi-path sort, dedup, parent subsumption, empty input, self-cycle at
arbitrary depth.
- **Invalid paths throw** (3 cases): unknown top-level, unknown nested,
descent past scalar.1 parent abc2d31 commit 6dd575d
3 files changed
Lines changed: 158 additions & 168 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
| 1 | + | |
| 2 | + | |
45 | 3 | | |
46 | | - | |
| 4 | + | |
47 | 5 | | |
48 | 6 | | |
49 | 7 | | |
| |||
54 | 12 | | |
55 | 13 | | |
56 | 14 | | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
| 15 | + | |
68 | 16 | | |
69 | | - | |
70 | | - | |
71 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
72 | 21 | | |
73 | | - | |
74 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
75 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
76 | 55 | | |
77 | | - | |
78 | | - | |
79 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
80 | 81 | | |
81 | 82 | | |
82 | | - | |
83 | | - | |
84 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
85 | 88 | | |
86 | 89 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
10 | 18 | | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
27 | 24 | | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
57 | 33 | | |
58 | | - | |
59 | | - | |
60 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
61 | 38 | | |
62 | 39 | | |
63 | | - | |
64 | | - | |
65 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
66 | 44 | | |
67 | 45 | | |
68 | | - | |
69 | | - | |
70 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
71 | 50 | | |
72 | 51 | | |
73 | | - | |
74 | | - | |
75 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
76 | 56 | | |
77 | 57 | | |
78 | | - | |
79 | | - | |
80 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
81 | 80 | | |
82 | | - | |
83 | 81 | | |
84 | 82 | | |
85 | | - | |
86 | | - | |
87 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
88 | 86 | | |
89 | 87 | | |
90 | 88 | | |
91 | | - | |
92 | | - | |
| 89 | + | |
| 90 | + | |
93 | 91 | | |
94 | | - | |
95 | | - | |
96 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
97 | 95 | | |
98 | 96 | | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
103 | 101 | | |
104 | 102 | | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
109 | 107 | | |
110 | 108 | | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
115 | 113 | | |
116 | 114 | | |
117 | 115 | | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
| 116 | + | |
| 117 | + | |
131 | 118 | | |
132 | 119 | | |
133 | 120 | | |
0 commit comments