@azure/provisioning-core 0.1.0-alpha.20261014.1

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 (152) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +62 -0
  3. package/dist/constructs/built-in-resources/resource-group.d.ts +50 -0
  4. package/dist/constructs/built-in-resources/resource-group.d.ts.map +1 -0
  5. package/dist/constructs/built-in-resources/resource-group.js +97 -0
  6. package/dist/constructs/built-in-resources/resource-group.js.map +1 -0
  7. package/dist/constructs/output.d.ts +80 -0
  8. package/dist/constructs/output.d.ts.map +1 -0
  9. package/dist/constructs/output.js +76 -0
  10. package/dist/constructs/output.js.map +1 -0
  11. package/dist/constructs/parameter.d.ts +77 -0
  12. package/dist/constructs/parameter.d.ts.map +1 -0
  13. package/dist/constructs/parameter.js +93 -0
  14. package/dist/constructs/parameter.js.map +1 -0
  15. package/dist/constructs/provisioning-component.d.ts +91 -0
  16. package/dist/constructs/provisioning-component.d.ts.map +1 -0
  17. package/dist/constructs/provisioning-component.js +150 -0
  18. package/dist/constructs/provisioning-component.js.map +1 -0
  19. package/dist/constructs/resource/resource-proxy.d.ts +134 -0
  20. package/dist/constructs/resource/resource-proxy.d.ts.map +1 -0
  21. package/dist/constructs/resource/resource-proxy.js +523 -0
  22. package/dist/constructs/resource/resource-proxy.js.map +1 -0
  23. package/dist/constructs/resource/resource-query.d.ts +23 -0
  24. package/dist/constructs/resource/resource-query.d.ts.map +1 -0
  25. package/dist/constructs/resource/resource-query.js +71 -0
  26. package/dist/constructs/resource/resource-query.js.map +1 -0
  27. package/dist/constructs/resource/resource-registry.d.ts +99 -0
  28. package/dist/constructs/resource/resource-registry.d.ts.map +1 -0
  29. package/dist/constructs/resource/resource-registry.js +51 -0
  30. package/dist/constructs/resource/resource-registry.js.map +1 -0
  31. package/dist/constructs/resource/resource-type-registry.d.ts +46 -0
  32. package/dist/constructs/resource/resource-type-registry.d.ts.map +1 -0
  33. package/dist/constructs/resource/resource-type-registry.js +156 -0
  34. package/dist/constructs/resource/resource-type-registry.js.map +1 -0
  35. package/dist/constructs/resource/resource-utils.d.ts +60 -0
  36. package/dist/constructs/resource/resource-utils.d.ts.map +1 -0
  37. package/dist/constructs/resource/resource-utils.js +77 -0
  38. package/dist/constructs/resource/resource-utils.js.map +1 -0
  39. package/dist/constructs/resource/resource.d.ts +460 -0
  40. package/dist/constructs/resource/resource.d.ts.map +1 -0
  41. package/dist/constructs/resource/resource.js +584 -0
  42. package/dist/constructs/resource/resource.js.map +1 -0
  43. package/dist/constructs/stack.d.ts +110 -0
  44. package/dist/constructs/stack.d.ts.map +1 -0
  45. package/dist/constructs/stack.js +110 -0
  46. package/dist/constructs/stack.js.map +1 -0
  47. package/dist/constructs/variable.d.ts +63 -0
  48. package/dist/constructs/variable.d.ts.map +1 -0
  49. package/dist/constructs/variable.js +74 -0
  50. package/dist/constructs/variable.js.map +1 -0
  51. package/dist/deployment-context/deployment-context.d.ts +27 -0
  52. package/dist/deployment-context/deployment-context.d.ts.map +1 -0
  53. package/dist/deployment-context/deployment-context.js +4 -0
  54. package/dist/deployment-context/deployment-context.js.map +1 -0
  55. package/dist/expression/ast-nodes.d.ts +100 -0
  56. package/dist/expression/ast-nodes.d.ts.map +1 -0
  57. package/dist/expression/ast-nodes.js +127 -0
  58. package/dist/expression/ast-nodes.js.map +1 -0
  59. package/dist/expression/expressions.d.ts +164 -0
  60. package/dist/expression/expressions.d.ts.map +1 -0
  61. package/dist/expression/expressions.js +211 -0
  62. package/dist/expression/expressions.js.map +1 -0
  63. package/dist/fn.d.ts +194 -0
  64. package/dist/fn.d.ts.map +1 -0
  65. package/dist/fn.js +353 -0
  66. package/dist/fn.js.map +1 -0
  67. package/dist/index.d.ts +25 -0
  68. package/dist/index.d.ts.map +1 -0
  69. package/dist/index.js +19 -0
  70. package/dist/index.js.map +1 -0
  71. package/dist/internal-loop.d.ts +14 -0
  72. package/dist/internal-loop.d.ts.map +1 -0
  73. package/dist/internal-loop.js +16 -0
  74. package/dist/internal-loop.js.map +1 -0
  75. package/dist/internal.d.ts +13 -0
  76. package/dist/internal.d.ts.map +1 -0
  77. package/dist/internal.js +10 -0
  78. package/dist/internal.js.map +1 -0
  79. package/dist/naming/naming-policy.d.ts +56 -0
  80. package/dist/naming/naming-policy.d.ts.map +1 -0
  81. package/dist/naming/naming-policy.js +99 -0
  82. package/dist/naming/naming-policy.js.map +1 -0
  83. package/dist/naming/naming-rules.d.ts +15 -0
  84. package/dist/naming/naming-rules.d.ts.map +1 -0
  85. package/dist/naming/naming-rules.js +15 -0
  86. package/dist/naming/naming-rules.js.map +1 -0
  87. package/dist/serialization/contract/generated/ast.d.ts +508 -0
  88. package/dist/serialization/contract/generated/ast.d.ts.map +1 -0
  89. package/dist/serialization/contract/generated/ast.js +23 -0
  90. package/dist/serialization/contract/generated/ast.js.map +1 -0
  91. package/dist/serialization/contract/index.d.ts +2 -0
  92. package/dist/serialization/contract/index.d.ts.map +1 -0
  93. package/dist/serialization/contract/index.js +4 -0
  94. package/dist/serialization/contract/index.js.map +1 -0
  95. package/dist/serialization/index.d.ts +4 -0
  96. package/dist/serialization/index.d.ts.map +1 -0
  97. package/dist/serialization/index.js +5 -0
  98. package/dist/serialization/index.js.map +1 -0
  99. package/dist/serialization/json/deserialize.d.ts +24 -0
  100. package/dist/serialization/json/deserialize.d.ts.map +1 -0
  101. package/dist/serialization/json/deserialize.js +476 -0
  102. package/dist/serialization/json/deserialize.js.map +1 -0
  103. package/dist/serialization/json/encoding.d.ts +4 -0
  104. package/dist/serialization/json/encoding.d.ts.map +1 -0
  105. package/dist/serialization/json/encoding.js +323 -0
  106. package/dist/serialization/json/encoding.js.map +1 -0
  107. package/dist/serialization/json/expression.d.ts +32 -0
  108. package/dist/serialization/json/expression.d.ts.map +1 -0
  109. package/dist/serialization/json/expression.js +490 -0
  110. package/dist/serialization/json/expression.js.map +1 -0
  111. package/dist/serialization/json/lower.d.ts +41 -0
  112. package/dist/serialization/json/lower.d.ts.map +1 -0
  113. package/dist/serialization/json/lower.js +343 -0
  114. package/dist/serialization/json/lower.js.map +1 -0
  115. package/dist/serialization/json/pluralize-config.d.ts +3 -0
  116. package/dist/serialization/json/pluralize-config.d.ts.map +1 -0
  117. package/dist/serialization/json/pluralize-config.js +7 -0
  118. package/dist/serialization/json/pluralize-config.js.map +1 -0
  119. package/dist/serialization/json/serialize.d.ts +12 -0
  120. package/dist/serialization/json/serialize.d.ts.map +1 -0
  121. package/dist/serialization/json/serialize.js +399 -0
  122. package/dist/serialization/json/serialize.js.map +1 -0
  123. package/dist/serialization/json/util.d.ts +2 -0
  124. package/dist/serialization/json/util.d.ts.map +1 -0
  125. package/dist/serialization/json/util.js +19 -0
  126. package/dist/serialization/json/util.js.map +1 -0
  127. package/dist/serialization/utils.d.ts +3 -0
  128. package/dist/serialization/utils.d.ts.map +1 -0
  129. package/dist/serialization/utils.js +146 -0
  130. package/dist/serialization/utils.js.map +1 -0
  131. package/dist/shape/shape-registry.d.ts +51 -0
  132. package/dist/shape/shape-registry.d.ts.map +1 -0
  133. package/dist/shape/shape-registry.js +41 -0
  134. package/dist/shape/shape-registry.js.map +1 -0
  135. package/dist/shape/shape.d.ts +407 -0
  136. package/dist/shape/shape.d.ts.map +1 -0
  137. package/dist/shape/shape.js +425 -0
  138. package/dist/shape/shape.js.map +1 -0
  139. package/dist/shape/value-encoding.d.ts +121 -0
  140. package/dist/shape/value-encoding.d.ts.map +1 -0
  141. package/dist/shape/value-encoding.js +32 -0
  142. package/dist/shape/value-encoding.js.map +1 -0
  143. package/dist/tsconfig.tsbuildinfo +1 -0
  144. package/dist/types.d.ts +9 -0
  145. package/dist/types.d.ts.map +1 -0
  146. package/dist/types.js +4 -0
  147. package/dist/types.js.map +1 -0
  148. package/dist/util.d.ts +33 -0
  149. package/dist/util.d.ts.map +1 -0
  150. package/dist/util.js +78 -0
  151. package/dist/util.js.map +1 -0
  152. package/package.json +49 -0
@@ -0,0 +1,425 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ // ---------------------------------------------------------------------------
4
+ // Constructor helpers
5
+ // ---------------------------------------------------------------------------
6
+ /** Build a {@link FlatModelShape} from a property map. */
7
+ export const createFlatModelShape = (byJsName) => ({ kind: "flatModel", byJsName });
8
+ /**
9
+ * Build a {@link DiscriminatedModelShape}.
10
+ *
11
+ * Pass a bare string when the field goes by the same name on both
12
+ * sides, which is the overwhelmingly common case; pass a
13
+ * {@link DiscriminatorNames} pair when a `@clientName` makes them
14
+ * differ.
15
+ */
16
+ export const createDiscriminatedModelShape = (discriminator, byValue) => ({
17
+ kind: "discriminatedModel",
18
+ discriminator: typeof discriminator === "string"
19
+ ? { jsName: discriminator, armName: discriminator }
20
+ : discriminator,
21
+ byValue,
22
+ });
23
+ /**
24
+ * Build a {@link DeferredShape}. The thunk is called on dereference; defer
25
+ * the actual shape lookup so that mutually-referential constants can
26
+ * be emitted in any order.
27
+ */
28
+ export const createDeferredShape = (value) => ({
29
+ kind: "deferred",
30
+ value,
31
+ });
32
+ /** Build an {@link AnyShape}. */
33
+ export const createAnyShape = () => ({ kind: "any" });
34
+ /** Build a {@link StringShape}, optionally with a compatible wire encoding. */
35
+ export const createStringShape = (encoding) => ({
36
+ kind: "string",
37
+ ...(encoding ? { encoding } : {}),
38
+ });
39
+ /** Build a {@link BooleanShape}, optionally with a compatible wire encoding. */
40
+ export const createBooleanShape = (encoding) => ({
41
+ kind: "boolean",
42
+ ...(encoding ? { encoding } : {}),
43
+ });
44
+ /** Build a {@link NumberShape}, optionally with a compatible wire encoding. */
45
+ export const createNumberShape = (encoding) => ({
46
+ kind: "number",
47
+ ...(encoding ? { encoding } : {}),
48
+ });
49
+ /** Build a {@link BytesShape}, optionally with a compatible wire encoding. */
50
+ export const createBytesShape = (encoding) => ({
51
+ kind: "bytes",
52
+ ...(encoding ? { encoding } : {}),
53
+ });
54
+ /** Build a {@link DateShape}, optionally with a compatible wire encoding. */
55
+ export const createDateShape = (encoding) => ({
56
+ kind: "date",
57
+ ...(encoding ? { encoding } : {}),
58
+ });
59
+ /** Build a terminal {@link StringLiteralShape}. */
60
+ export const createStringLiteralShape = () => ({
61
+ kind: "stringLiteral",
62
+ });
63
+ /** Build a terminal {@link NumberLiteralShape}. */
64
+ export const createNumberLiteralShape = (encoding) => ({
65
+ kind: "numberLiteral",
66
+ ...(encoding ? { encoding } : {}),
67
+ });
68
+ /** Build a terminal {@link BooleanLiteralShape}. */
69
+ export const createBooleanLiteralShape = (encoding) => ({
70
+ kind: "booleanLiteral",
71
+ ...(encoding ? { encoding } : {}),
72
+ });
73
+ /** Build a terminal {@link EnumShape}. */
74
+ export const createEnumShape = () => ({ kind: "enum" });
75
+ /** Build a terminal {@link UnionShape}. */
76
+ export const createUnionShape = () => ({ kind: "union" });
77
+ /** Build a terminal {@link NullShape}. */
78
+ export const createNullShape = () => ({ kind: "null" });
79
+ /** Build an {@link ArrayShape}. */
80
+ export const createArrayShape = (element) => ({
81
+ kind: "array",
82
+ element,
83
+ });
84
+ /** Build a {@link RecordShape}. */
85
+ export const createRecordShape = (value) => ({
86
+ kind: "record",
87
+ value,
88
+ });
89
+ /** Build a {@link TupleShape}. */
90
+ export const createTupleShape = (values) => ({
91
+ kind: "tuple",
92
+ values,
93
+ });
94
+ /** Return whether a value shape terminates property navigation. */
95
+ export function isTerminalValueShape(shape) {
96
+ switch (shape.kind) {
97
+ case "any":
98
+ case "string":
99
+ case "boolean":
100
+ case "number":
101
+ case "bytes":
102
+ case "date":
103
+ case "stringLiteral":
104
+ case "numberLiteral":
105
+ case "booleanLiteral":
106
+ case "enum":
107
+ case "union":
108
+ case "null":
109
+ return true;
110
+ case "deferred":
111
+ case "array":
112
+ case "record":
113
+ case "tuple":
114
+ return false;
115
+ default:
116
+ return assertNeverShape(shape);
117
+ }
118
+ }
119
+ function assertNeverShape(shape) {
120
+ throw new Error(`Unhandled value shape: ${String(shape)}`);
121
+ }
122
+ /**
123
+ * Resolve a {@link ModelShape} to the single concrete variant that
124
+ * applies to `value`.
125
+ *
126
+ * Resolution is iterative, not a single step, because a variant may
127
+ * itself be a discriminated group keyed on a *different* field (see
128
+ * {@link DiscriminatedModelShape.byValue}). Each hop reads its own
129
+ * discriminator out of the same `value`, so
130
+ * `{ kind: "cat", breed: "siamese" }` resolves through `Pet` → `Cat`
131
+ * → `Siamese`. {@link DeferredShape} entries are dereferenced in
132
+ * place, and flat model shapes are returned as-is.
133
+ *
134
+ * When a hop's discriminator can't be read — it is absent, is not a
135
+ * string (the *expression-valued* case), or names an unknown variant —
136
+ * the variant is instead **inferred from the value's structure** by
137
+ * {@link selectVariant}. That inference is sound rather than a guess:
138
+ * ARM would reject a payload that doesn't match the variant its
139
+ * discriminator selects, so a concrete payload determines the variant
140
+ * even when the discriminator itself is only known at deploy time.
141
+ *
142
+ * Bicep takes the same position — a discriminator it can't evaluate at
143
+ * compile time downgrades type checking for that object (diagnostic
144
+ * `BCP225`) rather than failing the build.
145
+ *
146
+ * Returns `undefined` when `shape` is `undefined`, when there is no
147
+ * `value` to infer from, or when the `byValue` graph is cyclic
148
+ * (defensive; the emitter does not produce cycles here).
149
+ *
150
+ * @param shape - The shape to resolve. Flat shapes are returned
151
+ * unchanged, so callers can pass either kind without checking.
152
+ * @param value - The object this shape describes, used both to read
153
+ * discriminators and to infer a variant when they can't be read.
154
+ * Omit it when no value exists (an `Expression<T>` proxy, say) and
155
+ * discriminated shapes will resolve to `undefined`.
156
+ * @param valueKeyedBy - Which naming **`value`'s own keys** use — not
157
+ * the shape's. A {@link FlatModelShape} is the mapping *between* the
158
+ * two sides (one property is `secretVersion` in TypeScript and
159
+ * `version` on the wire), so inference has to read both sides in the
160
+ * same naming or nothing matches:
161
+ *
162
+ * - `"js"` — client-facing names, as authored in TypeScript and held
163
+ * in a resource's state. These are
164
+ * {@link FlatModelShape.byJsName}'s own keys. Passed by
165
+ * `lowerState`, on state about to be serialized.
166
+ * - `"arm"` — wire names, as they appear in an ARM template or a
167
+ * service response. These are the first segment of each
168
+ * {@link PropertyShape.armPath}. Passed by `raiseState`, on JSON
169
+ * just parsed off the wire.
170
+ *
171
+ * Has no effect when the discriminator resolves normally, and no
172
+ * effect at all for models whose properties map 1:1.
173
+ */
174
+ export function resolveModelShape(shape, value, valueKeyedBy = "js") {
175
+ let current = shape;
176
+ const seen = new Set();
177
+ while (current !== undefined) {
178
+ if (seen.has(current))
179
+ return undefined;
180
+ seen.add(current);
181
+ if (current.kind === "deferred") {
182
+ current = current.value();
183
+ continue;
184
+ }
185
+ if (current.kind === "flatModel")
186
+ return current;
187
+ const group = current;
188
+ // Read the discriminator under the same naming as `value`'s own
189
+ // keys: JS-side state holds it under the client name, wire JSON
190
+ // under the ARM name. The two coincide for almost every ARM
191
+ // discriminator, but a `@clientName` on the field makes them
192
+ // differ, and reading the wrong one silently downgrades exact
193
+ // dispatch to structural inference below.
194
+ const names = group.discriminator;
195
+ const key = value?.[valueKeyedBy === "js" ? names.jsName : names.armName];
196
+ const next = typeof key === "string" ? group.byValue[key] : undefined;
197
+ if (next === undefined) {
198
+ return value ? selectVariant(group, value, valueKeyedBy) : undefined;
199
+ }
200
+ current = next;
201
+ }
202
+ return undefined;
203
+ }
204
+ /**
205
+ * Infer which variant of `group` a value belongs to by structure.
206
+ *
207
+ * Every variant is scored by how many of the value's keys it declares,
208
+ * descending into nested objects and containers so that variants which
209
+ * are indistinguishable at the top level can still be told apart. CDN's
210
+ * delivery-rule actions are exactly that case: all nine variants
211
+ * declare `{ name, parameters }` and differ only inside `parameters`.
212
+ *
213
+ * The highest score wins; ties keep the earliest variant in `byValue`
214
+ * order, which is stable emitter output. A tie means the tied variants
215
+ * declare the same keys for the data given, and the emitter guarantees
216
+ * that keys shared across variants map identically — so either choice
217
+ * produces the same wire mapping for everything actually present.
218
+ */
219
+ function selectVariant(group, value, valueKeyedBy) {
220
+ let best;
221
+ let bestScore = -1;
222
+ for (const variant of flattenVariants(group, new Set())) {
223
+ const score = scoreShape(variant, value, valueKeyedBy, new WeakSet());
224
+ if (score > bestScore) {
225
+ bestScore = score;
226
+ best = variant;
227
+ }
228
+ }
229
+ return best;
230
+ }
231
+ /** How many of `value`'s keys, recursively, `shape` accounts for. */
232
+ function scoreShape(shape, value, valueKeyedBy, visiting) {
233
+ if (visiting.has(value))
234
+ return 0;
235
+ visiting.add(value);
236
+ const byKey = getShapePropertiesMap(shape, valueKeyedBy);
237
+ let score = 0;
238
+ for (const [key, sub] of Object.entries(value)) {
239
+ const prop = byKey.get(key);
240
+ if (!prop)
241
+ continue;
242
+ score += 1;
243
+ score += scoreNested(sub, prop.value, valueKeyedBy, visiting);
244
+ }
245
+ visiting.delete(value);
246
+ return score;
247
+ }
248
+ /**
249
+ * Score one level deeper, through a property's target. Containers are
250
+ * sampled at their first entry — enough to discriminate, and bounded
251
+ * regardless of how large the value is.
252
+ */
253
+ function scoreNested(value, target, valueKeyedBy, visiting) {
254
+ if (!target ||
255
+ isTerminalValueShape(target) ||
256
+ value === null ||
257
+ typeof value !== "object") {
258
+ return 0;
259
+ }
260
+ if (target.kind === "array") {
261
+ if (!Array.isArray(value) || value.length === 0)
262
+ return 0;
263
+ return scoreNested(value[0], target.element, valueKeyedBy, visiting);
264
+ }
265
+ if (target.kind === "record") {
266
+ if (Array.isArray(value))
267
+ return 0;
268
+ const first = Object.values(value)[0];
269
+ if (first === undefined)
270
+ return 0;
271
+ return scoreNested(first, target.value, valueKeyedBy, visiting);
272
+ }
273
+ if (target.kind === "tuple") {
274
+ if (!Array.isArray(value))
275
+ return 0;
276
+ return target.values.reduce((score, tupleValue, index) => score + scoreNested(value[index], tupleValue, valueKeyedBy, visiting), 0);
277
+ }
278
+ if (Array.isArray(value))
279
+ return 0;
280
+ const nested = resolveModelShape(target.value(), value, valueKeyedBy);
281
+ if (!nested)
282
+ return 0;
283
+ return scoreShape(nested, value, valueKeyedBy, visiting);
284
+ }
285
+ const shapePropertiesCache = new WeakMap();
286
+ /**
287
+ * A shape's properties as a map, keyed by the name they go by in the
288
+ * requested naming. Pass the same naming the value uses and the two
289
+ * line up, which is what lets {@link scoreShape} compare them.
290
+ *
291
+ * Memoized per (shape, naming): scoring calls this once per candidate
292
+ * variant per level, so rebuilding would be wasteful.
293
+ *
294
+ * @param shape - The shape whose properties to map.
295
+ * @param keyedBy - Which name to key by. Note this describes the *map
296
+ * being built*, not an incoming value — unlike the `valueKeyedBy`
297
+ * parameter the callers thread through.
298
+ */
299
+ function getShapePropertiesMap(shape, keyedBy) {
300
+ let byNaming = shapePropertiesCache.get(shape);
301
+ if (!byNaming) {
302
+ byNaming = new Map();
303
+ shapePropertiesCache.set(shape, byNaming);
304
+ }
305
+ let byKey = byNaming.get(keyedBy);
306
+ if (byKey)
307
+ return byKey;
308
+ byKey = new Map();
309
+ for (const [jsName, prop] of Object.entries(shape.byJsName)) {
310
+ // `armPath[0]` rather than the whole path: that is the top-level
311
+ // wire key, even for properties hoisted through `@flattenProperty`.
312
+ const key = keyedBy === "js" ? jsName : prop.armPath[0];
313
+ // First writer wins, so a hoisted property never shadows the
314
+ // wrapper it was hoisted through.
315
+ if (key !== undefined && !byKey.has(key))
316
+ byKey.set(key, prop);
317
+ }
318
+ byNaming.set(keyedBy, byKey);
319
+ return byKey;
320
+ }
321
+ /**
322
+ * Flatten a group to the concrete flat shapes underneath it,
323
+ * dereferencing thunks and descending through nested groups.
324
+ */
325
+ function flattenVariants(group, seen) {
326
+ if (seen.has(group))
327
+ return [];
328
+ seen.add(group);
329
+ const out = [];
330
+ for (const key of Object.keys(group.byValue)) {
331
+ let entry = group.byValue[key];
332
+ if (entry?.kind === "deferred")
333
+ entry = entry.value();
334
+ if (entry === undefined)
335
+ continue;
336
+ if (entry.kind === "flatModel")
337
+ out.push(entry);
338
+ else
339
+ out.push(...flattenVariants(entry, seen));
340
+ }
341
+ return out;
342
+ }
343
+ /**
344
+ * Navigate `nav` one step deeper using `segment`. For string segments
345
+ * (`.foo`) at a model position, returns the property's shape entry as
346
+ * `stamp` and advances `next` into the property's target. For numeric
347
+ * segments (`[i]`) or string keys at a record position, peels one
348
+ * container layer; `stamp` is always `undefined`.
349
+ *
350
+ * Returns `{ stamp: undefined, next: undefined }` when the step can't
351
+ * be resolved (unknown property, out-of-shape access, etc.) — the
352
+ * access is treated as passthrough.
353
+ *
354
+ * @param nav - Where navigation currently sits.
355
+ * @param segment - The member name or array index being accessed.
356
+ * @param value - The value sitting at `nav`, when the caller has one.
357
+ * Consulted only at a {@link DiscriminatedModelShape} position, to
358
+ * select the variant via {@link resolveModelShape}. Always read with
359
+ * `"js"` naming, since navigation follows client-facing property
360
+ * names. Callers with no value — an `Expression<T>` proxy, for
361
+ * instance — omit it and get passthrough for discriminated
362
+ * positions, which is the honest answer when the variant is
363
+ * unknowable.
364
+ */
365
+ export function navigateShape(nav, segment, value) {
366
+ if (typeof segment === "number") {
367
+ return { stamp: undefined, next: peelContainer(nav, segment) };
368
+ }
369
+ if (isModelShape(nav)) {
370
+ const flat = resolveModelShape(nav, asRecord(value));
371
+ const stamp = flat?.byJsName[segment];
372
+ if (!stamp)
373
+ return { stamp: undefined, next: undefined };
374
+ return { stamp, next: derefTarget(stamp.value) };
375
+ }
376
+ // String segment against a container — treat as a record key access.
377
+ if (nav && nav.kind === "record") {
378
+ return { stamp: undefined, next: derefTarget(nav.value) };
379
+ }
380
+ return { stamp: undefined, next: undefined };
381
+ }
382
+ function asRecord(value) {
383
+ return value !== null && typeof value === "object" && !Array.isArray(value)
384
+ ? value
385
+ : undefined;
386
+ }
387
+ function isModelShape(nav) {
388
+ return (nav !== undefined &&
389
+ (nav.kind === "flatModel" || nav.kind === "discriminatedModel"));
390
+ }
391
+ /**
392
+ * Peel one container layer off `nav`. Returns `undefined` for
393
+ * non-containers (caller treats the step as passthrough).
394
+ */
395
+ function peelContainer(nav, index) {
396
+ if (!nav || isModelShape(nav))
397
+ return undefined;
398
+ if (nav.kind === "array")
399
+ return derefTarget(nav.element);
400
+ if (nav.kind === "record")
401
+ return derefTarget(nav.value);
402
+ return derefTarget(nav.values[index]);
403
+ }
404
+ /**
405
+ * Convert a {@link ValueShape} — where a property *points* — into a
406
+ * {@link NavShape} — where navigation now *is*.
407
+ *
408
+ * The only real work is forcing a {@link DeferredShape} thunk; the
409
+ * resolved model becomes the new position whether or not it is
410
+ * discriminated, since {@link navigateShape} can look up properties on
411
+ * either. Container shapes pass through unchanged, pending an index
412
+ * step.
413
+ *
414
+ * Deliberately *not* named `resolve*` — that prefix belongs to
415
+ * {@link resolveModelShape}, which picks a variant and is a much
416
+ * heavier operation.
417
+ */
418
+ function derefTarget(shape) {
419
+ if (!shape || isTerminalValueShape(shape))
420
+ return undefined;
421
+ if (shape.kind === "deferred")
422
+ return shape.value();
423
+ return shape;
424
+ }
425
+ //# sourceMappingURL=shape.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shape.js","sourceRoot":"","sources":["../../src/shape/shape.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAwTlC,8EAA8E;AAC9E,sBAAsB;AACtB,8EAA8E;AAE9E,0DAA0D;AAC1D,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,QAAuC,EACvB,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC,CAAC;AAEvD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAC3C,aAA0C,EAC1C,OAA+D,EACtC,EAAE,CAAC,CAAC;IAC7B,IAAI,EAAE,oBAAoB;IAC1B,aAAa,EACX,OAAO,aAAa,KAAK,QAAQ;QAC/B,CAAC,CAAC,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,aAAa,EAAE;QACnD,CAAC,CAAC,aAAa;IACnB,OAAO;CACR,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAI,KAAc,EAAoB,EAAE,CAAC,CAAC;IAC3E,IAAI,EAAE,UAAU;IAChB,KAAK;CACN,CAAC,CAA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AC;IAC5D,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU;QAAE,OAAO,KAAK,CAAC,KAAK,EAAE,CAAC;IACpD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,121 @@
1
+ export declare const INTEGER_SCALAR_NAMES: readonly ["integer", "safeint", "int8", "int16", "int32", "int64", "uint8", "uint16", "uint32", "uint64"];
2
+ export type IntegerScalarName = (typeof INTEGER_SCALAR_NAMES)[number];
3
+ export declare const NUMERIC_SCALAR_NAMES: readonly ["integer", "safeint", "int8", "int16", "int32", "int64", "uint8", "uint16", "uint32", "uint64", "numeric", "decimal", "decimal128", "float", "float32", "float64"];
4
+ export type NumericScalarName = (typeof NUMERIC_SCALAR_NAMES)[number];
5
+ export declare function isIntegerScalarName(name: string): name is IntegerScalarName;
6
+ export declare function isNumericScalarName(name: string): name is NumericScalarName;
7
+ export interface DateTimeTextEncodingDescriptor {
8
+ readonly kind: "date-time-text";
9
+ readonly source: "utcDateTime" | "offsetDateTime";
10
+ readonly format: "rfc3339" | "rfc7231";
11
+ readonly clientMode: "client" | "wire";
12
+ readonly wire: {
13
+ readonly kind: "string";
14
+ };
15
+ }
16
+ export interface UnixTimestampEncodingDescriptor {
17
+ readonly kind: "unix-timestamp";
18
+ readonly source: "utcDateTime";
19
+ readonly unit: "seconds";
20
+ readonly clientMode: "client" | "wire";
21
+ readonly wire: {
22
+ readonly kind: "integer";
23
+ readonly scalar: IntegerScalarName;
24
+ };
25
+ }
26
+ export interface DurationIso8601EncodingDescriptor {
27
+ readonly kind: "duration-iso8601";
28
+ readonly source: "duration";
29
+ readonly clientMode: "wire";
30
+ readonly wire: {
31
+ readonly kind: "string";
32
+ };
33
+ }
34
+ export interface DurationNumericEncodingDescriptor {
35
+ readonly kind: "duration-numeric";
36
+ readonly source: "duration";
37
+ readonly unit: "seconds" | "milliseconds";
38
+ readonly clientMode: "wire";
39
+ readonly wire: {
40
+ readonly kind: "integer";
41
+ readonly scalar: IntegerScalarName;
42
+ };
43
+ }
44
+ export interface BytesEncodingDescriptor {
45
+ readonly kind: "bytes";
46
+ readonly source: "bytes";
47
+ readonly format: "base64" | "base64url";
48
+ readonly clientMode: "client" | "wire";
49
+ readonly wire: {
50
+ readonly kind: "string";
51
+ };
52
+ }
53
+ export interface PlainDateEncodingDescriptor {
54
+ readonly kind: "plain-date";
55
+ readonly source: "plainDate";
56
+ readonly clientMode: "client" | "wire";
57
+ readonly wire: {
58
+ readonly kind: "string";
59
+ };
60
+ }
61
+ export interface NumericStringEncodingDescriptor {
62
+ readonly kind: "numeric-string";
63
+ readonly source: "integer" | "number";
64
+ readonly sourceScalar: NumericScalarName;
65
+ readonly clientMode: "wire";
66
+ readonly wire: {
67
+ readonly kind: "string";
68
+ };
69
+ }
70
+ export interface BooleanStringEncodingDescriptor {
71
+ readonly kind: "boolean-string";
72
+ readonly source: "boolean";
73
+ readonly clientMode: "client" | "wire";
74
+ readonly wire: {
75
+ readonly kind: "string";
76
+ };
77
+ }
78
+ export type ValueEncodingDescriptor = DateTimeTextEncodingDescriptor | UnixTimestampEncodingDescriptor | DurationIso8601EncodingDescriptor | DurationNumericEncodingDescriptor | BytesEncodingDescriptor | PlainDateEncodingDescriptor | NumericStringEncodingDescriptor | BooleanStringEncodingDescriptor;
79
+ /**
80
+ * Encodings whose client-side value is a JavaScript `string`.
81
+ *
82
+ * The source TypeSpec scalar can be a date/time, duration, byte sequence,
83
+ * numeric value, or boolean. `clientMode: "wire"` is the important invariant:
84
+ * it means the generated TypeScript API exposes the encoded string itself.
85
+ */
86
+ export type StringValueEncodingDescriptor = (DateTimeTextEncodingDescriptor & {
87
+ readonly clientMode: "wire";
88
+ }) | DurationIso8601EncodingDescriptor | (BytesEncodingDescriptor & {
89
+ readonly clientMode: "wire";
90
+ }) | (PlainDateEncodingDescriptor & {
91
+ readonly clientMode: "wire";
92
+ }) | NumericStringEncodingDescriptor | (BooleanStringEncodingDescriptor & {
93
+ readonly clientMode: "wire";
94
+ });
95
+ /** Encoding supported by a client-side JavaScript `boolean`. */
96
+ export type BooleanValueEncodingDescriptor = BooleanStringEncodingDescriptor & {
97
+ readonly clientMode: "client";
98
+ };
99
+ /** Encodings whose client-side value is a JavaScript `number`. */
100
+ export type NumberValueEncodingDescriptor = (UnixTimestampEncodingDescriptor & {
101
+ readonly clientMode: "wire";
102
+ }) | DurationNumericEncodingDescriptor;
103
+ /** Encoding supported by a client-side JavaScript `Uint8Array`. */
104
+ export type BytesValueEncodingDescriptor = BytesEncodingDescriptor & {
105
+ readonly clientMode: "client";
106
+ };
107
+ /**
108
+ * Encodings whose client-side value is a JavaScript `Date`.
109
+ *
110
+ * `offsetDateTime` is intentionally absent: the emitter exposes it as a
111
+ * string so the original offset is not erased.
112
+ */
113
+ export type DateValueEncodingDescriptor = (DateTimeTextEncodingDescriptor & {
114
+ readonly source: "utcDateTime";
115
+ readonly clientMode: "client";
116
+ }) | (UnixTimestampEncodingDescriptor & {
117
+ readonly clientMode: "client";
118
+ }) | (PlainDateEncodingDescriptor & {
119
+ readonly clientMode: "client";
120
+ });
121
+ //# sourceMappingURL=value-encoding.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"value-encoding.d.ts","sourceRoot":"","sources":["../../src/shape/value-encoding.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,oBAAoB,2GAWvB,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtE,eAAO,MAAM,oBAAoB,8KAQvB,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAKtE,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,iBAAiB,CAE3E;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,iBAAiB,CAE3E;AAED,MAAM,WAAW,8BAA8B;IAC7C,Q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,CAAA;CAAE,CAAC,CAAC"}
@@ -0,0 +1,32 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ export const INTEGER_SCALAR_NAMES = [
4
+ "integer",
5
+ "safeint",
6
+ "int8",
7
+ "int16",
8
+ "int32",
9
+ "int64",
10
+ "uint8",
11
+ "uint16",
12
+ "uint32",
13
+ "uint64",
14
+ ];
15
+ export const NUMERIC_SCALAR_NAMES = [
16
+ ...INTEGER_SCALAR_NAMES,
17
+ "numeric",
18
+ "decimal",
19
+ "decimal128",
20
+ "float",
21
+ "float32",
22
+ "float64",
23
+ ];
24
+ const integerScalarNames = new Set(INTEGER_SCALAR_NAMES);
25
+ const numericScalarNames = new Set(NUMERIC_SCALAR_NAMES);
26
+ export function isIntegerScalarName(name) {
27
+ return integerScalarNames.has(name);
28
+ }
29
+ export function isNumericScalarName(name) {
30
+ return numericScalarNames.has(name);
31
+ }
32
+ //# sourceMappingURL=value-encoding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"value-encoding.js","sourceRoot":"","sources":["../../src/shape/value-encoding.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,SAAS;IACT,SAAS;IACT,MAAM;IACN,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,QAAQ;CACA,CAAC;AAIX,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,GAAG,oBAAoB;IACvB,SAAS;IACT,SAAS;IACT,YAAY;IACZ,OAAO;IACP,SAAS;IACT,SAAS;CACD,CAAC;AAIX,MAAM,kBAAkB,GAAwB,IAAI,GAAG,CAAC,oBAAoB,CAAC,CAAC;AAC9E,MAAM,kBAAkB,GAAwB,IAAI,GAAG,CAAC,oBAAoB,CAAC,CAAC;AAE9E,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC9C,OAAO,kBAAkB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC9C,OAAO,kBAAkB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC"}