@xlr-lib/xlr-utils 0.1.1-next.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.
package/dist/index.mjs ADDED
@@ -0,0 +1,821 @@
1
+ // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/utils/src/annotations.ts
2
+ import ts from "typescript";
3
+ function extractDescription(text) {
4
+ if (!text) {
5
+ return {};
6
+ }
7
+ return { description: text };
8
+ }
9
+ function parentIsNonObjectPath(node) {
10
+ return node.parent && (ts.isArrayTypeNode(node.parent) || ts.isTupleTypeNode(node.parent) || ts.isOptionalTypeNode(node.parent) || ts.isRestTypeNode(node.parent) || ts.isUnionTypeNode(node.parent));
11
+ }
12
+ function recurseTypeChain(node, child) {
13
+ if (!node) {
14
+ return [];
15
+ }
16
+ if (ts.isArrayTypeNode(node) && node.parent && ts.isRestTypeNode(node.parent)) {
17
+ return recurseTypeChain(node.parent, node);
18
+ }
19
+ if (ts.isRestTypeNode(node)) {
20
+ return recurseTypeChain(node.parent, node);
21
+ }
22
+ if (ts.isOptionalTypeNode(node)) {
23
+ return recurseTypeChain(node.parent, node);
24
+ }
25
+ if (ts.isUnionTypeNode(node)) {
26
+ return recurseTypeChain(node.parent, node);
27
+ }
28
+ if (ts.isParenthesizedTypeNode(node)) {
29
+ return recurseTypeChain(node.parent, node);
30
+ }
31
+ if (ts.isTypeLiteralNode(node)) {
32
+ return recurseTypeChain(node.parent, node);
33
+ }
34
+ if (ts.isArrayTypeNode(node)) {
35
+ return ["[]", ...recurseTypeChain(node.parent, node)];
36
+ }
37
+ if (ts.isTupleTypeNode(node)) {
38
+ const pos = node.elements.indexOf(child);
39
+ return [
40
+ ...pos === -1 ? [] : [`${pos}`],
41
+ ...recurseTypeChain(node.parent, node)
42
+ ];
43
+ }
44
+ if (ts.isTypeAliasDeclaration(node) || ts.isInterfaceDeclaration(node) || ts.isPropertySignature(node)) {
45
+ return [node.name.getText(), ...recurseTypeChain(node.parent, node)];
46
+ }
47
+ if (parentIsNonObjectPath(node)) {
48
+ return recurseTypeChain(node.parent, node);
49
+ }
50
+ return [];
51
+ }
52
+ function extractTitle(node) {
53
+ const typeNames = recurseTypeChain(node, void 0).reverse().join(".");
54
+ if (!typeNames.length) {
55
+ return {};
56
+ }
57
+ return { title: typeNames };
58
+ }
59
+ function stringifyDoc(docString) {
60
+ if (typeof docString === "undefined" || typeof docString === "string") {
61
+ return docString;
62
+ }
63
+ return docString.map(({ text }) => text).join(" ");
64
+ }
65
+ function extractTags(tags) {
66
+ const descriptions = [];
67
+ const examples = [];
68
+ const _default = [];
69
+ const see = [];
70
+ const meta = {};
71
+ const extractSee = (tag) => {
72
+ return `${tag.tagName ? `${tag.tagName?.getText()} ` : ""}${stringifyDoc(tag.comment)?.trim() ?? ""}`;
73
+ };
74
+ tags.forEach((tag) => {
75
+ if (!tag.comment) {
76
+ return;
77
+ }
78
+ if (tag.tagName.text === "example") {
79
+ examples.push(stringifyDoc(tag.comment)?.trim() ?? "");
80
+ } else if (tag.tagName.text === "default") {
81
+ _default.push(stringifyDoc(tag.comment)?.trim() ?? "");
82
+ } else if (tag.tagName.text === "see") {
83
+ see.push(extractSee(tag));
84
+ } else if (tag.tagName.text === "meta") {
85
+ const [key, value] = tag.comment.toString().split(/:(.*)/);
86
+ meta[key] = value?.trim() ?? "";
87
+ } else {
88
+ const text = stringifyDoc(tag.comment)?.trim() ?? "";
89
+ descriptions.push(`@${tag.tagName.text} ${text}`);
90
+ }
91
+ });
92
+ return {
93
+ ...descriptions.length === 0 ? {} : { description: descriptions.join("\n") },
94
+ ...examples.length === 0 ? {} : { examples },
95
+ ..._default.length === 0 ? {} : { default: _default.join("\n") },
96
+ ...see.length === 0 ? {} : { see },
97
+ ...meta && Object.keys(meta).length === 0 ? {} : { meta }
98
+ };
99
+ }
100
+ function join(t, separator = "\n") {
101
+ const unique = new Set(t).values();
102
+ return Array.from(unique).filter((s) => s !== void 0).join(separator).trim();
103
+ }
104
+ function mergeAnnotations(nodes) {
105
+ const name = nodes.find((n) => n.name)?.name;
106
+ const title = join(
107
+ nodes.map((n) => n.title),
108
+ ", "
109
+ );
110
+ const description = join(nodes.map((n) => n.description));
111
+ const _default = join(nodes.map((n) => n.default));
112
+ const comment = join(nodes.map((n) => n.comment));
113
+ const examples = join(
114
+ nodes.map(
115
+ (n) => Array.isArray(n.examples) ? join(n.examples) : n.examples
116
+ )
117
+ );
118
+ const see = join(
119
+ nodes.map((n) => Array.isArray(n.see) ? join(n.see) : n.see)
120
+ );
121
+ const meta = nodes.find((n) => n.meta)?.meta;
122
+ return {
123
+ ...name ? { name } : {},
124
+ ...title ? { title } : {},
125
+ ...description ? { description } : {},
126
+ ...examples ? { examples } : {},
127
+ ..._default ? { default: _default } : {},
128
+ ...see ? { see } : {},
129
+ ...comment ? { comment } : {},
130
+ ...meta ? { meta } : {}
131
+ };
132
+ }
133
+ function decorateNode(node) {
134
+ const { jsDoc } = node;
135
+ const titleAnnotation = extractTitle(node);
136
+ if (jsDoc && jsDoc.length) {
137
+ const first = jsDoc[0];
138
+ return mergeAnnotations([
139
+ extractDescription(stringifyDoc(first.comment)),
140
+ titleAnnotation,
141
+ extractTags(first.tags ?? [])
142
+ ]);
143
+ }
144
+ return titleAnnotation;
145
+ }
146
+
147
+ // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/utils/src/ts-helpers.ts
148
+ import ts3 from "typescript";
149
+
150
+ // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/utils/src/type-checks.ts
151
+ import ts2 from "typescript";
152
+ function isOptionalProperty(node) {
153
+ return node.questionToken?.kind === ts2.SyntaxKind.QuestionToken;
154
+ }
155
+ function isGenericInterfaceDeclaration(node) {
156
+ const length = node.typeParameters?.length;
157
+ return length ? length > 0 : false;
158
+ }
159
+ function isGenericTypeDeclaration(node) {
160
+ const length = node.typeParameters?.length;
161
+ return length ? length > 0 : false;
162
+ }
163
+ function isTypeReferenceGeneric(node, typeChecker) {
164
+ const symbol = typeChecker.getSymbolAtLocation(node.typeName);
165
+ if (symbol && symbol.declarations) {
166
+ return symbol.declarations[0].kind === ts2.SyntaxKind.TypeParameter;
167
+ }
168
+ return false;
169
+ }
170
+ function isTopLevelDeclaration(node) {
171
+ return node.kind === ts2.SyntaxKind.InterfaceDeclaration || node.kind === ts2.SyntaxKind.TypeAliasDeclaration;
172
+ }
173
+ function isTopLevelNode(node) {
174
+ return node.kind === ts2.SyntaxKind.InterfaceDeclaration || node.kind === ts2.SyntaxKind.TypeAliasDeclaration || node.kind === ts2.SyntaxKind.VariableStatement;
175
+ }
176
+ function isGenericNodeType(nt) {
177
+ return nt.genericTokens?.length > 0;
178
+ }
179
+ function isGenericNamedType(nt) {
180
+ return nt.genericTokens?.length > 0;
181
+ }
182
+ function isPrimitiveTypeNode(node) {
183
+ return node.type === "string" || node.type === "number" || node.type === "boolean" || node.type === "null" || node.type === "any" || node.type === "never" || node.type === "undefined" || node.type === "unknown" || node.type === "void";
184
+ }
185
+ function isNonNullable(a) {
186
+ return a !== null || a !== void 0;
187
+ }
188
+
189
+ // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/utils/src/validation-helpers.ts
190
+ function propertyToTuple(node) {
191
+ let key = node.children?.[0].value;
192
+ if (key.includes("-")) {
193
+ key = `'${key}'`;
194
+ }
195
+ return {
196
+ key,
197
+ value: node.children?.[1]
198
+ };
199
+ }
200
+ function makePropertyMap(node) {
201
+ const m = /* @__PURE__ */ new Map();
202
+ node.children?.forEach((child) => {
203
+ const property = propertyToTuple(child);
204
+ m.set(property.key, property.value);
205
+ });
206
+ return m;
207
+ }
208
+ function isNode(obj) {
209
+ return typeof obj !== "string" || typeof obj !== "number" || typeof obj !== "boolean";
210
+ }
211
+ function computeExtends(a, b) {
212
+ if ((a.type === "any" || a.type === "unknown") && (b.type === "any" || b.type === "unknown")) {
213
+ return true;
214
+ }
215
+ if ((a.type === "null" || a.type === "undefined") && (b.type === "null" || b.type === "undefined")) {
216
+ return true;
217
+ }
218
+ if (a.type === b.type) {
219
+ if (isPrimitiveTypeNode(a) && isPrimitiveTypeNode(b)) {
220
+ if (a.const && b.const) {
221
+ if (a.const === b.const) {
222
+ return true;
223
+ }
224
+ } else {
225
+ return true;
226
+ }
227
+ }
228
+ if (a.type === "ref" && b.type === "ref") {
229
+ return a.ref === b.ref;
230
+ }
231
+ if (a.type === "object" && b.type === "object") {
232
+ for (const property in b.properties) {
233
+ const propertyNode = b.properties[property];
234
+ if (!a.properties[property] || !computeExtends(a.properties[property].node, propertyNode.node)) {
235
+ return false;
236
+ }
237
+ }
238
+ return true;
239
+ }
240
+ }
241
+ if (isPrimitiveTypeNode(a) && b.type === "or") {
242
+ return b.or.every((member) => computeExtends(a, member));
243
+ }
244
+ if (isPrimitiveTypeNode(b) && a.type === "or") {
245
+ return a.or.every((member) => computeExtends(b, member));
246
+ }
247
+ if (a.type === "or" && b.type === "or") {
248
+ return a.or.every((x) => b.or.some((y) => computeExtends(x, y)));
249
+ }
250
+ return false;
251
+ }
252
+ function resolveConditional(conditional) {
253
+ const { left, right } = conditional.check;
254
+ const conditionalResult = computeExtends(left, right) ? conditional.value.true : conditional.value.false;
255
+ if (isGenericNodeType(conditional)) {
256
+ const genericMap = /* @__PURE__ */ new Map();
257
+ conditional.genericTokens.forEach((token) => {
258
+ genericMap.set(
259
+ token.symbol,
260
+ token.default ?? token.constraints ?? { type: "any" }
261
+ );
262
+ });
263
+ return fillInGenerics(conditionalResult, genericMap);
264
+ }
265
+ return conditionalResult;
266
+ }
267
+ function resolveReferenceNode(genericReference, typeToFill) {
268
+ const genericArgs = genericReference.genericArguments;
269
+ const genericMap = /* @__PURE__ */ new Map();
270
+ if (genericArgs && isGenericNodeType(typeToFill)) {
271
+ typeToFill.genericTokens.forEach((token, index) => {
272
+ genericMap.set(
273
+ token.symbol,
274
+ genericArgs[index] ?? token.default ?? token.constraints
275
+ );
276
+ });
277
+ }
278
+ const filledInNode = fillInGenerics(typeToFill, genericMap);
279
+ if (isGenericNodeType(filledInNode) && genericArgs?.length) {
280
+ if (genericArgs.length < filledInNode.genericTokens.length) {
281
+ filledInNode.genericTokens = filledInNode.genericTokens.slice(
282
+ genericArgs?.length
283
+ );
284
+ } else if (genericArgs.length === filledInNode.genericTokens.length) {
285
+ filledInNode.genericTokens = [];
286
+ }
287
+ }
288
+ if (genericReference.property && filledInNode.type === "object") {
289
+ return filledInNode.properties[genericReference.property]?.node ?? filledInNode.additionalProperties ?? { type: "undefined" };
290
+ }
291
+ return filledInNode;
292
+ }
293
+ function computeEffectiveObject(base, operand, errorOnOverlap = true) {
294
+ const baseObjectName = base.name ?? base.title ?? "object literal";
295
+ const operandObjectName = operand.name ?? operand.title ?? "object literal";
296
+ const newObject = {
297
+ ...JSON.parse(JSON.stringify(base)),
298
+ name: `${baseObjectName} & ${operandObjectName}`,
299
+ description: `Effective type combining ${baseObjectName} and ${operandObjectName}`,
300
+ genericTokens: [
301
+ ...isGenericNodeType(base) ? base.genericTokens : [],
302
+ ...isGenericNodeType(operand) ? operand.genericTokens : []
303
+ ]
304
+ };
305
+ for (const property in operand.properties) {
306
+ if (newObject.properties[property] !== void 0 && errorOnOverlap) {
307
+ if (!computeExtends(
308
+ newObject.properties[property].node,
309
+ operand.properties[property].node
310
+ )) {
311
+ throw new Error(
312
+ `Can't compute effective type for ${baseObjectName} and ${operandObjectName} because of conflicting properties ${property}`
313
+ );
314
+ }
315
+ }
316
+ newObject.properties[property] = operand.properties[property];
317
+ }
318
+ if (newObject.additionalProperties && operand.additionalProperties) {
319
+ if (!isPrimitiveTypeNode(newObject.additionalProperties) || !isPrimitiveTypeNode(operand.additionalProperties) || newObject.additionalProperties.type !== operand.additionalProperties.type) {
320
+ newObject.additionalProperties = {
321
+ type: "and",
322
+ and: [newObject.additionalProperties, operand.additionalProperties]
323
+ };
324
+ }
325
+ } else if (operand.additionalProperties) {
326
+ newObject.additionalProperties = operand.additionalProperties;
327
+ }
328
+ return newObject;
329
+ }
330
+
331
+ // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/utils/src/ts-helpers.ts
332
+ function tsStripOptionalType(node) {
333
+ return ts3.isOptionalTypeNode(node) ? node.type : node;
334
+ }
335
+ function isExportedDeclaration(node) {
336
+ const modifiers = ts3.canHaveModifiers(node) ? ts3.getModifiers(node) : void 0;
337
+ if (modifiers) {
338
+ return modifiers.some((m) => m.kind === ts3.SyntaxKind.ExportKeyword);
339
+ }
340
+ return false;
341
+ }
342
+ function isNodeExported(node) {
343
+ return (ts3.getCombinedModifierFlags(node) & ts3.ModifierFlags.Export) !== 0 || !!node.parent && node.parent.kind === ts3.SyntaxKind.SourceFile;
344
+ }
345
+ function getReferencedType(node, typeChecker) {
346
+ let symbol = typeChecker.getSymbolAtLocation(node.typeName);
347
+ if (symbol && (symbol.flags & ts3.SymbolFlags.Alias) === ts3.SymbolFlags.Alias) {
348
+ symbol = typeChecker.getAliasedSymbol(symbol);
349
+ }
350
+ const varDecl = symbol?.declarations?.[0];
351
+ if (varDecl && (ts3.isInterfaceDeclaration(varDecl) || ts3.isTypeAliasDeclaration(varDecl))) {
352
+ return { declaration: varDecl, exported: isNodeExported(varDecl) };
353
+ }
354
+ }
355
+ function getStringLiteralsFromUnion(node) {
356
+ if (ts3.isUnionTypeNode(node)) {
357
+ return new Set(
358
+ node.types.map((type) => {
359
+ if (ts3.isLiteralTypeNode(type) && ts3.isStringLiteral(type.literal)) {
360
+ return type.literal.text;
361
+ }
362
+ return "";
363
+ })
364
+ );
365
+ }
366
+ if (ts3.isLiteralTypeNode(node) && ts3.isStringLiteral(node.literal)) {
367
+ return /* @__PURE__ */ new Set([node.literal.text]);
368
+ }
369
+ return /* @__PURE__ */ new Set();
370
+ }
371
+ function buildTemplateRegex(node, typeChecker) {
372
+ let regex = node.head.text;
373
+ node.templateSpans.forEach((span) => {
374
+ let type = span.type.kind;
375
+ if (ts3.isTypeReferenceNode(span.type)) {
376
+ let symbol = typeChecker.getSymbolAtLocation(
377
+ span.type.typeName
378
+ );
379
+ if (symbol && (symbol.flags & ts3.SymbolFlags.Alias) === ts3.SymbolFlags.Alias) {
380
+ symbol = typeChecker.getAliasedSymbol(symbol);
381
+ }
382
+ type = (symbol?.declarations?.[0]).type.kind;
383
+ }
384
+ if (type === ts3.SyntaxKind.StringKeyword) {
385
+ regex += ".*";
386
+ } else if (type === ts3.SyntaxKind.NumberKeyword) {
387
+ regex += "[0-9]*";
388
+ } else if (type === ts3.SyntaxKind.BooleanKeyword) {
389
+ regex += "true|false";
390
+ }
391
+ regex += span.literal.text;
392
+ });
393
+ return regex;
394
+ }
395
+ function fillInGenerics(xlrNode, generics) {
396
+ let localGenerics;
397
+ if (generics) {
398
+ localGenerics = new Map(generics);
399
+ } else {
400
+ localGenerics = /* @__PURE__ */ new Map();
401
+ if (isGenericNodeType(xlrNode)) {
402
+ xlrNode.genericTokens?.forEach((token) => {
403
+ const genericValue = token.default ?? token.constraints;
404
+ localGenerics.set(
405
+ token.symbol,
406
+ fillInGenerics(genericValue, localGenerics)
407
+ );
408
+ });
409
+ }
410
+ }
411
+ if (xlrNode.type === "ref") {
412
+ if (localGenerics.has(xlrNode.ref)) {
413
+ return {
414
+ ...localGenerics.get(xlrNode.ref),
415
+ ...xlrNode.genericArguments ? {
416
+ genericArguments: xlrNode.genericArguments.map(
417
+ (ga) => fillInGenerics(ga, localGenerics)
418
+ )
419
+ } : {},
420
+ ...xlrNode.title ? { title: xlrNode.title } : {},
421
+ ...xlrNode.name ? { name: xlrNode.name } : {},
422
+ ...xlrNode.description ? { description: xlrNode.description } : {},
423
+ ...xlrNode.comment ? { comment: xlrNode.comment } : {}
424
+ };
425
+ }
426
+ return {
427
+ ...xlrNode,
428
+ ...xlrNode.genericArguments ? {
429
+ genericArguments: xlrNode.genericArguments.map(
430
+ (ga) => fillInGenerics(ga, localGenerics)
431
+ )
432
+ } : {}
433
+ };
434
+ }
435
+ if (xlrNode.type === "object") {
436
+ const newProperties = {};
437
+ Object.getOwnPropertyNames(xlrNode.properties).forEach((propName) => {
438
+ const prop = xlrNode.properties[propName];
439
+ newProperties[propName] = {
440
+ required: prop.required,
441
+ node: fillInGenerics(prop.node, localGenerics)
442
+ };
443
+ });
444
+ return {
445
+ ...xlrNode,
446
+ properties: newProperties,
447
+ ...isGenericNamedType(xlrNode) ? {
448
+ genericTokens: xlrNode.genericTokens.map((token) => {
449
+ return {
450
+ ...token,
451
+ constraints: token.constraints ? fillInGenerics(token.constraints, localGenerics) : void 0,
452
+ default: token.default ? fillInGenerics(token.default, localGenerics) : void 0
453
+ };
454
+ })
455
+ } : {},
456
+ extends: xlrNode.extends ? fillInGenerics(xlrNode.extends, localGenerics) : void 0,
457
+ additionalProperties: xlrNode.additionalProperties ? fillInGenerics(xlrNode.additionalProperties, localGenerics) : false
458
+ };
459
+ }
460
+ if (xlrNode.type === "array") {
461
+ return {
462
+ ...xlrNode,
463
+ elementType: fillInGenerics(xlrNode.elementType, localGenerics)
464
+ };
465
+ } else if (xlrNode.type === "or" || xlrNode.type === "and") {
466
+ let pointer;
467
+ if (xlrNode.type === "or") {
468
+ pointer = xlrNode.or;
469
+ } else {
470
+ pointer = xlrNode.and;
471
+ }
472
+ return {
473
+ ...xlrNode,
474
+ [xlrNode.type]: pointer.map((prop) => {
475
+ return fillInGenerics(prop, localGenerics);
476
+ })
477
+ };
478
+ } else if (xlrNode.type === "record") {
479
+ return {
480
+ ...xlrNode,
481
+ keyType: fillInGenerics(xlrNode.keyType, localGenerics),
482
+ valueType: fillInGenerics(xlrNode.valueType, localGenerics)
483
+ };
484
+ } else if (xlrNode.type === "conditional") {
485
+ const filledInConditional = {
486
+ ...xlrNode,
487
+ check: {
488
+ left: fillInGenerics(xlrNode.check.left, localGenerics),
489
+ right: fillInGenerics(xlrNode.check.right, localGenerics)
490
+ },
491
+ value: {
492
+ true: fillInGenerics(xlrNode.value.true, localGenerics),
493
+ false: fillInGenerics(xlrNode.value.false, localGenerics)
494
+ }
495
+ };
496
+ if (filledInConditional.check.left.type !== "ref" && filledInConditional.check.right.type !== "ref") {
497
+ return {
498
+ name: xlrNode.name,
499
+ title: xlrNode.title,
500
+ ...resolveConditional(filledInConditional)
501
+ };
502
+ }
503
+ return filledInConditional;
504
+ }
505
+ return xlrNode;
506
+ }
507
+ function applyPickOrOmitToNodeType(baseObject, operation, properties) {
508
+ if (baseObject.type === "object") {
509
+ const newObject = { ...baseObject };
510
+ Object.keys(baseObject.properties).forEach((key) => {
511
+ if (operation === "Omit" && properties.has(key) || operation === "Pick" && !properties.has(key)) {
512
+ delete newObject.properties[key];
513
+ }
514
+ });
515
+ if (Object.keys(newObject.properties).length === 0 && (operation !== "Omit" || newObject.additionalProperties === false)) {
516
+ return void 0;
517
+ }
518
+ return newObject;
519
+ }
520
+ let pointer;
521
+ if (baseObject.type === "and") {
522
+ pointer = baseObject.and;
523
+ } else if (baseObject.type === "or") {
524
+ pointer = baseObject.or;
525
+ } else {
526
+ throw new Error(
527
+ `Error: Can not apply ${operation} to type ${baseObject.type}`
528
+ );
529
+ }
530
+ const pickedTypes = pointer.map((type) => {
531
+ const node = applyPickOrOmitToNodeType(type, operation, properties);
532
+ if (node === void 0) {
533
+ return void 0;
534
+ }
535
+ return { ...node, additionalProperties: false };
536
+ }).filter((type) => type !== void 0);
537
+ if (pickedTypes.length === 0) {
538
+ return void 0;
539
+ }
540
+ if (pickedTypes.length === 1) {
541
+ return pickedTypes[0];
542
+ }
543
+ if (baseObject.type === "and") {
544
+ return { ...baseObject, and: pickedTypes };
545
+ }
546
+ return { ...baseObject, or: pickedTypes };
547
+ }
548
+ function applyPartialOrRequiredToNodeType(baseObject, modifier) {
549
+ if (baseObject.type === "object") {
550
+ const newObject = { ...baseObject };
551
+ Object.keys(baseObject.properties).forEach((key) => {
552
+ newObject.properties[key].required = modifier;
553
+ });
554
+ return newObject;
555
+ }
556
+ if (baseObject.type === "and") {
557
+ const pickedTypes = baseObject.and.map(
558
+ (type) => applyPartialOrRequiredToNodeType(type, modifier)
559
+ );
560
+ return { ...baseObject, and: pickedTypes };
561
+ }
562
+ if (baseObject.type === "or") {
563
+ const pickedTypes = baseObject.or.map(
564
+ (type) => applyPartialOrRequiredToNodeType(type, modifier)
565
+ );
566
+ return { ...baseObject, or: pickedTypes };
567
+ }
568
+ throw new Error(
569
+ `Error: Can not apply ${modifier ? "Required" : "Partial"} to type ${baseObject.type}`
570
+ );
571
+ }
572
+ function applyExcludeToNodeType(baseObject, filters) {
573
+ const remainingMembers = baseObject.or.filter((type) => {
574
+ if (filters.type === "or") {
575
+ return !filters.or.some((filter) => computeExtends(type, filter));
576
+ }
577
+ return !computeExtends(type, filters);
578
+ });
579
+ if (remainingMembers.length === 1) {
580
+ return remainingMembers[0];
581
+ }
582
+ return {
583
+ ...baseObject,
584
+ or: remainingMembers
585
+ };
586
+ }
587
+
588
+ // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/utils/src/documentation.ts
589
+ import ts4 from "typescript";
590
+ var { SymbolDisplayPartKind, displayPartsToString } = ts4;
591
+ function insertBetweenElements(array, separator) {
592
+ return array.reduce((acc, item, index) => {
593
+ if (index === 0) {
594
+ return [item];
595
+ }
596
+ return [...acc, separator, item];
597
+ }, []);
598
+ }
599
+ function createTSDocString(node) {
600
+ if (node.type === "ref") {
601
+ return [
602
+ {
603
+ text: node.ref,
604
+ kind: SymbolDisplayPartKind.keyword
605
+ }
606
+ ];
607
+ }
608
+ if (node.type === "or" || node.type === "and") {
609
+ const items = node.type === "and" ? node.and : node.or;
610
+ return insertBetweenElements(
611
+ items.map((subnode) => createTSDocString(subnode)),
612
+ [
613
+ {
614
+ kind: SymbolDisplayPartKind.punctuation,
615
+ text: node.type === "and" ? " & " : " | "
616
+ }
617
+ ]
618
+ ).flat();
619
+ }
620
+ if (node.type === "function") {
621
+ return [
622
+ {
623
+ kind: SymbolDisplayPartKind.keyword,
624
+ text: "function"
625
+ },
626
+ {
627
+ kind: SymbolDisplayPartKind.space,
628
+ text: " "
629
+ },
630
+ ...node.name ? [{ text: node.name, kind: SymbolDisplayPartKind.methodName }] : [],
631
+ {
632
+ kind: SymbolDisplayPartKind.punctuation,
633
+ text: "("
634
+ },
635
+ ...insertBetweenElements(
636
+ node.parameters.map((p) => {
637
+ if (p.name) {
638
+ return [
639
+ {
640
+ kind: SymbolDisplayPartKind.parameterName,
641
+ text: p.name
642
+ },
643
+ {
644
+ kind: SymbolDisplayPartKind.punctuation,
645
+ text: p.optional ? "?" : ""
646
+ },
647
+ {
648
+ kind: SymbolDisplayPartKind.punctuation,
649
+ text: ": "
650
+ },
651
+ ...createTSDocString(p.type)
652
+ ];
653
+ }
654
+ return createTSDocString(p.type);
655
+ }),
656
+ [
657
+ {
658
+ kind: SymbolDisplayPartKind.punctuation,
659
+ text: ", "
660
+ }
661
+ ]
662
+ ).flat(),
663
+ {
664
+ kind: SymbolDisplayPartKind.punctuation,
665
+ text: ")"
666
+ },
667
+ ...node.returnType ? [
668
+ {
669
+ kind: SymbolDisplayPartKind.punctuation,
670
+ text: ": "
671
+ },
672
+ ...createTSDocString(node.returnType)
673
+ ] : []
674
+ ];
675
+ }
676
+ if (node.type === "tuple") {
677
+ return [
678
+ {
679
+ kind: SymbolDisplayPartKind.punctuation,
680
+ text: "["
681
+ },
682
+ ...insertBetweenElements(
683
+ node.elementTypes.map((t) => {
684
+ if (t.name) {
685
+ return [
686
+ {
687
+ kind: SymbolDisplayPartKind.propertyName,
688
+ text: t.name
689
+ },
690
+ {
691
+ kind: SymbolDisplayPartKind.punctuation,
692
+ text: ": "
693
+ },
694
+ ...createTSDocString(t.type)
695
+ ];
696
+ }
697
+ return createTSDocString(t.type);
698
+ }),
699
+ [
700
+ {
701
+ kind: SymbolDisplayPartKind.punctuation,
702
+ text: ", "
703
+ }
704
+ ]
705
+ ).flat(),
706
+ {
707
+ kind: SymbolDisplayPartKind.punctuation,
708
+ text: "]"
709
+ }
710
+ ];
711
+ }
712
+ if (node.type === "array") {
713
+ return [
714
+ {
715
+ kind: SymbolDisplayPartKind.interfaceName,
716
+ text: "Array"
717
+ },
718
+ {
719
+ kind: SymbolDisplayPartKind.punctuation,
720
+ text: "<"
721
+ },
722
+ ...createTSDocString(node.elementType),
723
+ {
724
+ kind: SymbolDisplayPartKind.punctuation,
725
+ text: ">"
726
+ }
727
+ ];
728
+ }
729
+ if (node.type === "record") {
730
+ return [
731
+ {
732
+ kind: SymbolDisplayPartKind.interfaceName,
733
+ text: "Record"
734
+ },
735
+ {
736
+ kind: SymbolDisplayPartKind.punctuation,
737
+ text: "<"
738
+ },
739
+ ...createTSDocString(node.keyType),
740
+ {
741
+ kind: SymbolDisplayPartKind.punctuation,
742
+ text: ", "
743
+ },
744
+ ...createTSDocString(node.valueType),
745
+ {
746
+ kind: SymbolDisplayPartKind.punctuation,
747
+ text: ">"
748
+ }
749
+ ];
750
+ }
751
+ if ((node.type === "string" || node.type === "boolean" || node.type === "number") && node.const !== void 0) {
752
+ return [
753
+ {
754
+ kind: SymbolDisplayPartKind.keyword,
755
+ text: typeof node.const === "string" ? `"${node.const}"` : String(node.const)
756
+ }
757
+ ];
758
+ }
759
+ if (isPrimitiveTypeNode(node) && node.type !== "null") {
760
+ return [
761
+ {
762
+ kind: SymbolDisplayPartKind.keyword,
763
+ text: node.type
764
+ }
765
+ ];
766
+ }
767
+ if (node.type === "object" && node.name) {
768
+ return [
769
+ {
770
+ kind: SymbolDisplayPartKind.interfaceName,
771
+ text: node.name
772
+ }
773
+ ];
774
+ }
775
+ return [
776
+ {
777
+ kind: SymbolDisplayPartKind.localName,
778
+ text: node.type
779
+ }
780
+ ];
781
+ }
782
+ function symbolDisplayToString(displayParts) {
783
+ return displayPartsToString(displayParts);
784
+ }
785
+ function createDocString(node) {
786
+ return symbolDisplayToString(createTSDocString(node));
787
+ }
788
+ export {
789
+ applyExcludeToNodeType,
790
+ applyPartialOrRequiredToNodeType,
791
+ applyPickOrOmitToNodeType,
792
+ buildTemplateRegex,
793
+ computeEffectiveObject,
794
+ computeExtends,
795
+ createDocString,
796
+ createTSDocString,
797
+ decorateNode,
798
+ fillInGenerics,
799
+ getReferencedType,
800
+ getStringLiteralsFromUnion,
801
+ isExportedDeclaration,
802
+ isGenericInterfaceDeclaration,
803
+ isGenericNamedType,
804
+ isGenericNodeType,
805
+ isGenericTypeDeclaration,
806
+ isNode,
807
+ isNodeExported,
808
+ isNonNullable,
809
+ isOptionalProperty,
810
+ isPrimitiveTypeNode,
811
+ isTopLevelDeclaration,
812
+ isTopLevelNode,
813
+ isTypeReferenceGeneric,
814
+ makePropertyMap,
815
+ propertyToTuple,
816
+ resolveConditional,
817
+ resolveReferenceNode,
818
+ symbolDisplayToString,
819
+ tsStripOptionalType
820
+ };
821
+ //# sourceMappingURL=index.mjs.map