@flanksource/clicky-ui 0.3.86 → 0.3.88
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/components.cjs +0 -1
- package/dist/components.d.ts +1 -1
- package/dist/components.d.ts.map +1 -1
- package/dist/components.js +2 -2
- package/dist/data/ProgressBars.cjs +157 -101
- package/dist/data/ProgressBars.cjs.map +1 -1
- package/dist/data/ProgressBars.d.ts +1 -1
- package/dist/data/ProgressBars.d.ts.map +1 -1
- package/dist/data/ProgressBars.js +157 -101
- package/dist/data/ProgressBars.js.map +1 -1
- package/dist/data/ai/PromptCatalog/PromptCatalogTable.cjs +1 -0
- package/dist/data/ai/PromptCatalog/PromptCatalogTable.cjs.map +1 -1
- package/dist/data/ai/PromptCatalog/PromptCatalogTable.d.ts.map +1 -1
- package/dist/data/ai/PromptCatalog/PromptCatalogTable.js +1 -0
- package/dist/data/ai/PromptCatalog/PromptCatalogTable.js.map +1 -1
- package/dist/data/traces/ProcessResourceMetrics.cjs +99 -0
- package/dist/data/traces/ProcessResourceMetrics.cjs.map +1 -0
- package/dist/data/traces/ProcessResourceMetrics.d.ts +10 -0
- package/dist/data/traces/ProcessResourceMetrics.d.ts.map +1 -0
- package/dist/data/traces/ProcessResourceMetrics.js +99 -0
- package/dist/data/traces/ProcessResourceMetrics.js.map +1 -0
- package/dist/data/traces/ProcessTraceDetail.cjs +85 -108
- package/dist/data/traces/ProcessTraceDetail.cjs.map +1 -1
- package/dist/data/traces/ProcessTraceDetail.d.ts +7 -1
- package/dist/data/traces/ProcessTraceDetail.d.ts.map +1 -1
- package/dist/data/traces/ProcessTraceDetail.js +88 -111
- package/dist/data/traces/ProcessTraceDetail.js.map +1 -1
- package/dist/data/traces/ProcessUsageBars.cjs +37 -41
- package/dist/data/traces/ProcessUsageBars.cjs.map +1 -1
- package/dist/data/traces/ProcessUsageBars.d.ts.map +1 -1
- package/dist/data/traces/ProcessUsageBars.js +37 -41
- package/dist/data/traces/ProcessUsageBars.js.map +1 -1
- package/dist/data/traces/process-tree.cjs +35 -0
- package/dist/data/traces/process-tree.cjs.map +1 -1
- package/dist/data/traces/process-tree.d.ts +15 -0
- package/dist/data/traces/process-tree.d.ts.map +1 -1
- package/dist/data/traces/process-tree.js +35 -1
- package/dist/data/traces/process-tree.js.map +1 -1
- package/dist/data/version-info.cjs +3 -3
- package/dist/data/version-info.js +3 -3
- package/dist/expressions/lang/attributes.cjs.map +1 -1
- package/dist/expressions/lang/attributes.d.ts.map +1 -1
- package/dist/expressions/lang/attributes.js.map +1 -1
- package/dist/expressions/lang/completion.cjs.map +1 -1
- package/dist/expressions/lang/completion.d.ts.map +1 -1
- package/dist/expressions/lang/completion.js.map +1 -1
- package/dist/expressions/lang/generated/conformance.json.d.ts +280 -0
- package/dist/expressions/lang/generated/index.cjs.map +1 -1
- package/dist/expressions/lang/generated/index.d.ts.map +1 -1
- package/dist/expressions/lang/generated/index.js.map +1 -1
- package/dist/expressions/lang/generated/languages.cjs +2 -0
- package/dist/expressions/lang/generated/languages.cjs.map +1 -1
- package/dist/expressions/lang/generated/languages.js +2 -0
- package/dist/expressions/lang/generated/languages.js.map +1 -1
- package/dist/expressions/lang/generated/languages.json.d.ts +2 -0
- package/dist/expressions/lang/generated/spec.cjs +2 -2
- package/dist/expressions/lang/generated/spec.cjs.map +1 -1
- package/dist/expressions/lang/generated/spec.js +2 -2
- package/dist/expressions/lang/generated/spec.js.map +1 -1
- package/dist/expressions/lang/generated/spec.json.d.ts +81 -26
- package/dist/expressions/lang/hover.cjs +3 -1
- package/dist/expressions/lang/hover.cjs.map +1 -1
- package/dist/expressions/lang/hover.d.ts.map +1 -1
- package/dist/expressions/lang/hover.js +3 -1
- package/dist/expressions/lang/hover.js.map +1 -1
- package/dist/expressions/lang/index.cjs.map +1 -1
- package/dist/expressions/lang/index.d.ts.map +1 -1
- package/dist/expressions/lang/index.js.map +1 -1
- package/dist/expressions/lang/merge.cjs +5 -0
- package/dist/expressions/lang/merge.cjs.map +1 -1
- package/dist/expressions/lang/merge.d.ts +4 -0
- package/dist/expressions/lang/merge.d.ts.map +1 -1
- package/dist/expressions/lang/merge.js +5 -0
- package/dist/expressions/lang/merge.js.map +1 -1
- package/dist/expressions/lang/prefix.cjs.map +1 -1
- package/dist/expressions/lang/prefix.d.ts.map +1 -1
- package/dist/expressions/lang/prefix.js.map +1 -1
- package/dist/expressions/lang/spec.d.ts.map +1 -1
- package/dist/expressions/lang/theme.cjs.map +1 -1
- package/dist/expressions/lang/theme.d.ts.map +1 -1
- package/dist/expressions/lang/theme.js.map +1 -1
- package/dist/expressions/lang/types.d.ts +12 -0
- package/dist/expressions/lang/types.d.ts.map +1 -1
- package/dist/expressions/playground/EmbeddedPlayground.cjs +6 -5
- package/dist/expressions/playground/EmbeddedPlayground.cjs.map +1 -1
- package/dist/expressions/playground/EmbeddedPlayground.d.ts +12 -4
- package/dist/expressions/playground/EmbeddedPlayground.d.ts.map +1 -1
- package/dist/expressions/playground/EmbeddedPlayground.js +6 -5
- package/dist/expressions/playground/EmbeddedPlayground.js.map +1 -1
- package/dist/expressions/playground/ExpressionPlayground.cjs +217 -156
- package/dist/expressions/playground/ExpressionPlayground.cjs.map +1 -1
- package/dist/expressions/playground/ExpressionPlayground.d.ts +7 -6
- package/dist/expressions/playground/ExpressionPlayground.d.ts.map +1 -1
- package/dist/expressions/playground/ExpressionPlayground.js +217 -156
- package/dist/expressions/playground/ExpressionPlayground.js.map +1 -1
- package/dist/expressions/playground/panels/ReferencePanel.cjs +34 -0
- package/dist/expressions/playground/panels/ReferencePanel.cjs.map +1 -0
- package/dist/expressions/playground/panels/ReferencePanel.d.ts +22 -0
- package/dist/expressions/playground/panels/ReferencePanel.d.ts.map +1 -0
- package/dist/expressions/playground/panels/ReferencePanel.js +33 -0
- package/dist/expressions/playground/panels/ReferencePanel.js.map +1 -0
- package/dist/expressions/playground/panels/SpecPanel.cjs +10 -2
- package/dist/expressions/playground/panels/SpecPanel.cjs.map +1 -1
- package/dist/expressions/playground/panels/SpecPanel.d.ts.map +1 -1
- package/dist/expressions/playground/panels/SpecPanel.js +10 -2
- package/dist/expressions/playground/panels/SpecPanel.js.map +1 -1
- package/dist/expressions/playground/useEvaluator.cjs +56 -42
- package/dist/expressions/playground/useEvaluator.cjs.map +1 -1
- package/dist/expressions/playground/useEvaluator.d.ts +0 -2
- package/dist/expressions/playground/useEvaluator.d.ts.map +1 -1
- package/dist/expressions/playground/useEvaluator.js +56 -42
- package/dist/expressions/playground/useEvaluator.js.map +1 -1
- package/dist/expressions/playground/useSampleRuns.cjs +22 -18
- package/dist/expressions/playground/useSampleRuns.cjs.map +1 -1
- package/dist/expressions/playground/useSampleRuns.d.ts +2 -3
- package/dist/expressions/playground/useSampleRuns.d.ts.map +1 -1
- package/dist/expressions/playground/useSampleRuns.js +22 -18
- package/dist/expressions/playground/useSampleRuns.js.map +1 -1
- package/dist/hooks/use-latest.cjs +14 -0
- package/dist/hooks/use-latest.cjs.map +1 -0
- package/dist/hooks/use-latest.d.ts +3 -0
- package/dist/hooks/use-latest.d.ts.map +1 -0
- package/dist/hooks/use-latest.js +14 -0
- package/dist/hooks/use-latest.js.map +1 -0
- package/dist/index.cjs +0 -1
- package/dist/index.js +2 -2
- package/dist/overlay/ConfirmDialog.cjs +12 -37
- package/dist/overlay/ConfirmDialog.cjs.map +1 -1
- package/dist/overlay/ConfirmDialog.d.ts +3 -17
- package/dist/overlay/ConfirmDialog.d.ts.map +1 -1
- package/dist/overlay/ConfirmDialog.js +12 -37
- package/dist/overlay/ConfirmDialog.js.map +1 -1
- package/dist/overlay/useConfirm.cjs +1 -16
- package/dist/overlay/useConfirm.cjs.map +1 -1
- package/dist/overlay/useConfirm.d.ts +1 -9
- package/dist/overlay/useConfirm.d.ts.map +1 -1
- package/dist/overlay/useConfirm.js +3 -17
- package/dist/overlay/useConfirm.js.map +1 -1
- package/dist/runtime/barrels.json +1574 -1576
- package/dist/runtime/importmap.json +2185 -2183
- package/package.json +1 -1
- package/dist/overlay/confirmMemory.cjs +0 -58
- package/dist/overlay/confirmMemory.cjs.map +0 -1
- package/dist/overlay/confirmMemory.d.ts +0 -8
- package/dist/overlay/confirmMemory.d.ts.map +0 -1
- package/dist/overlay/confirmMemory.js +0 -54
- package/dist/overlay/confirmMemory.js.map +0 -1
|
@@ -304,7 +304,8 @@ declare const _default: {
|
|
|
304
304
|
],
|
|
305
305
|
"result": "google.protobuf.Any"
|
|
306
306
|
}
|
|
307
|
-
]
|
|
307
|
+
],
|
|
308
|
+
"group": "kubernetes"
|
|
308
309
|
},
|
|
309
310
|
{
|
|
310
311
|
"name": "GetStatus",
|
|
@@ -316,7 +317,8 @@ declare const _default: {
|
|
|
316
317
|
],
|
|
317
318
|
"result": "google.protobuf.Any"
|
|
318
319
|
}
|
|
319
|
-
]
|
|
320
|
+
],
|
|
321
|
+
"group": "kubernetes"
|
|
320
322
|
},
|
|
321
323
|
{
|
|
322
324
|
"name": "Has",
|
|
@@ -365,7 +367,8 @@ declare const _default: {
|
|
|
365
367
|
],
|
|
366
368
|
"result": "bool"
|
|
367
369
|
}
|
|
368
|
-
]
|
|
370
|
+
],
|
|
371
|
+
"group": "kubernetes"
|
|
369
372
|
},
|
|
370
373
|
{
|
|
371
374
|
"name": "IsReady",
|
|
@@ -377,7 +380,8 @@ declare const _default: {
|
|
|
377
380
|
],
|
|
378
381
|
"result": "bool"
|
|
379
382
|
}
|
|
380
|
-
]
|
|
383
|
+
],
|
|
384
|
+
"group": "kubernetes"
|
|
381
385
|
},
|
|
382
386
|
{
|
|
383
387
|
"name": "JSON",
|
|
@@ -2293,7 +2297,8 @@ declare const _default: {
|
|
|
2293
2297
|
],
|
|
2294
2298
|
"result": "google.protobuf.Any"
|
|
2295
2299
|
}
|
|
2296
|
-
]
|
|
2300
|
+
],
|
|
2301
|
+
"group": "kubernetes"
|
|
2297
2302
|
},
|
|
2298
2303
|
{
|
|
2299
2304
|
"name": "k8s.getResourcesLimit",
|
|
@@ -2307,7 +2312,8 @@ declare const _default: {
|
|
|
2307
2312
|
],
|
|
2308
2313
|
"result": "google.protobuf.Any"
|
|
2309
2314
|
}
|
|
2310
|
-
]
|
|
2315
|
+
],
|
|
2316
|
+
"group": "kubernetes"
|
|
2311
2317
|
},
|
|
2312
2318
|
{
|
|
2313
2319
|
"name": "k8s.getResourcesRequests",
|
|
@@ -2321,7 +2327,8 @@ declare const _default: {
|
|
|
2321
2327
|
],
|
|
2322
2328
|
"result": "google.protobuf.Any"
|
|
2323
2329
|
}
|
|
2324
|
-
]
|
|
2330
|
+
],
|
|
2331
|
+
"group": "kubernetes"
|
|
2325
2332
|
},
|
|
2326
2333
|
{
|
|
2327
2334
|
"name": "k8s.getStatus",
|
|
@@ -2334,7 +2341,8 @@ declare const _default: {
|
|
|
2334
2341
|
],
|
|
2335
2342
|
"result": "google.protobuf.Any"
|
|
2336
2343
|
}
|
|
2337
|
-
]
|
|
2344
|
+
],
|
|
2345
|
+
"group": "kubernetes"
|
|
2338
2346
|
},
|
|
2339
2347
|
{
|
|
2340
2348
|
"name": "k8s.isHealthy",
|
|
@@ -2347,7 +2355,8 @@ declare const _default: {
|
|
|
2347
2355
|
],
|
|
2348
2356
|
"result": "bool"
|
|
2349
2357
|
}
|
|
2350
|
-
]
|
|
2358
|
+
],
|
|
2359
|
+
"group": "kubernetes"
|
|
2351
2360
|
},
|
|
2352
2361
|
{
|
|
2353
2362
|
"name": "k8s.isReady",
|
|
@@ -2360,7 +2369,8 @@ declare const _default: {
|
|
|
2360
2369
|
],
|
|
2361
2370
|
"result": "bool"
|
|
2362
2371
|
}
|
|
2363
|
-
]
|
|
2372
|
+
],
|
|
2373
|
+
"group": "kubernetes"
|
|
2364
2374
|
},
|
|
2365
2375
|
{
|
|
2366
2376
|
"name": "k8s.is_healthy",
|
|
@@ -2373,7 +2383,8 @@ declare const _default: {
|
|
|
2373
2383
|
],
|
|
2374
2384
|
"result": "bool"
|
|
2375
2385
|
}
|
|
2376
|
-
]
|
|
2386
|
+
],
|
|
2387
|
+
"group": "kubernetes"
|
|
2377
2388
|
},
|
|
2378
2389
|
{
|
|
2379
2390
|
"name": "k8s.labels",
|
|
@@ -2386,7 +2397,8 @@ declare const _default: {
|
|
|
2386
2397
|
],
|
|
2387
2398
|
"result": "google.protobuf.Any"
|
|
2388
2399
|
}
|
|
2389
|
-
]
|
|
2400
|
+
],
|
|
2401
|
+
"group": "kubernetes"
|
|
2390
2402
|
},
|
|
2391
2403
|
{
|
|
2392
2404
|
"name": "k8s.memoryAsBytes",
|
|
@@ -2420,7 +2432,8 @@ declare const _default: {
|
|
|
2420
2432
|
],
|
|
2421
2433
|
"result": "string"
|
|
2422
2434
|
}
|
|
2423
|
-
]
|
|
2435
|
+
],
|
|
2436
|
+
"group": "kubernetes"
|
|
2424
2437
|
},
|
|
2425
2438
|
{
|
|
2426
2439
|
"name": "k8s.nodeProperties",
|
|
@@ -2433,7 +2446,8 @@ declare const _default: {
|
|
|
2433
2446
|
],
|
|
2434
2447
|
"result": "google.protobuf.Any"
|
|
2435
2448
|
}
|
|
2436
|
-
]
|
|
2449
|
+
],
|
|
2450
|
+
"group": "kubernetes"
|
|
2437
2451
|
},
|
|
2438
2452
|
{
|
|
2439
2453
|
"name": "k8s.podProperties",
|
|
@@ -2446,7 +2460,8 @@ declare const _default: {
|
|
|
2446
2460
|
],
|
|
2447
2461
|
"result": "google.protobuf.Any"
|
|
2448
2462
|
}
|
|
2449
|
-
]
|
|
2463
|
+
],
|
|
2464
|
+
"group": "kubernetes"
|
|
2450
2465
|
},
|
|
2451
2466
|
{
|
|
2452
2467
|
"name": "kebabCase",
|
|
@@ -3443,6 +3458,21 @@ declare const _default: {
|
|
|
3443
3458
|
"// pick the value for the given key if the key exists, otherwise return 'you'\n{'hello': 'world', 'goodbye': 'cruel world'}[?greeting].orValue('you')"
|
|
3444
3459
|
]
|
|
3445
3460
|
},
|
|
3461
|
+
{
|
|
3462
|
+
"name": "percentile",
|
|
3463
|
+
"memberOnly": true,
|
|
3464
|
+
"overloads": [
|
|
3465
|
+
{
|
|
3466
|
+
"id": "collection_percentile",
|
|
3467
|
+
"args": [
|
|
3468
|
+
"list(dyn)",
|
|
3469
|
+
"dyn"
|
|
3470
|
+
],
|
|
3471
|
+
"result": "double",
|
|
3472
|
+
"member": true
|
|
3473
|
+
}
|
|
3474
|
+
]
|
|
3475
|
+
},
|
|
3446
3476
|
{
|
|
3447
3477
|
"name": "pick",
|
|
3448
3478
|
"memberOnly": true,
|
|
@@ -4105,6 +4135,20 @@ declare const _default: {
|
|
|
4105
4135
|
"'hello world'.startsWith('hello') // true\n'hello world'.startsWith('world') // false"
|
|
4106
4136
|
]
|
|
4107
4137
|
},
|
|
4138
|
+
{
|
|
4139
|
+
"name": "stats",
|
|
4140
|
+
"memberOnly": true,
|
|
4141
|
+
"overloads": [
|
|
4142
|
+
{
|
|
4143
|
+
"id": "collection_stats",
|
|
4144
|
+
"args": [
|
|
4145
|
+
"list(dyn)"
|
|
4146
|
+
],
|
|
4147
|
+
"result": "map(string, dyn)",
|
|
4148
|
+
"member": true
|
|
4149
|
+
}
|
|
4150
|
+
]
|
|
4151
|
+
},
|
|
4108
4152
|
{
|
|
4109
4153
|
"name": "string",
|
|
4110
4154
|
"doc": "convert a value to a string",
|
|
@@ -5659,11 +5703,13 @@ declare const _default: {
|
|
|
5659
5703
|
},
|
|
5660
5704
|
{
|
|
5661
5705
|
"name": "getHealth",
|
|
5662
|
-
"signature": "(in interface {}) kubernetes.HealthStatus"
|
|
5706
|
+
"signature": "(in interface {}) kubernetes.HealthStatus",
|
|
5707
|
+
"group": "kubernetes"
|
|
5663
5708
|
},
|
|
5664
5709
|
{
|
|
5665
5710
|
"name": "getStatus",
|
|
5666
|
-
"signature": "(in interface {}) string"
|
|
5711
|
+
"signature": "(in interface {}) string",
|
|
5712
|
+
"group": "kubernetes"
|
|
5667
5713
|
},
|
|
5668
5714
|
{
|
|
5669
5715
|
"name": "has",
|
|
@@ -5695,7 +5741,8 @@ declare const _default: {
|
|
|
5695
5741
|
},
|
|
5696
5742
|
{
|
|
5697
5743
|
"name": "isHealthy",
|
|
5698
|
-
"signature": "(in interface {}) bool"
|
|
5744
|
+
"signature": "(in interface {}) bool",
|
|
5745
|
+
"group": "kubernetes"
|
|
5699
5746
|
},
|
|
5700
5747
|
{
|
|
5701
5748
|
"name": "isKind",
|
|
@@ -5703,7 +5750,8 @@ declare const _default: {
|
|
|
5703
5750
|
},
|
|
5704
5751
|
{
|
|
5705
5752
|
"name": "isReady",
|
|
5706
|
-
"signature": "(in interface {}) bool"
|
|
5753
|
+
"signature": "(in interface {}) bool",
|
|
5754
|
+
"group": "kubernetes"
|
|
5707
5755
|
},
|
|
5708
5756
|
{
|
|
5709
5757
|
"name": "jmespath",
|
|
@@ -5732,32 +5780,38 @@ declare const _default: {
|
|
|
5732
5780
|
{
|
|
5733
5781
|
"name": "k8s.GetHealth",
|
|
5734
5782
|
"namespace": "k8s",
|
|
5735
|
-
"signature": "(in interface {}) kubernetes.HealthStatus"
|
|
5783
|
+
"signature": "(in interface {}) kubernetes.HealthStatus",
|
|
5784
|
+
"group": "kubernetes"
|
|
5736
5785
|
},
|
|
5737
5786
|
{
|
|
5738
5787
|
"name": "k8s.GetHealthMap",
|
|
5739
5788
|
"namespace": "k8s",
|
|
5740
|
-
"signature": "(in interface {}) map[string]string"
|
|
5789
|
+
"signature": "(in interface {}) map[string]string",
|
|
5790
|
+
"group": "kubernetes"
|
|
5741
5791
|
},
|
|
5742
5792
|
{
|
|
5743
5793
|
"name": "k8s.GetStatus",
|
|
5744
5794
|
"namespace": "k8s",
|
|
5745
|
-
"signature": "(in interface {}) string"
|
|
5795
|
+
"signature": "(in interface {}) string",
|
|
5796
|
+
"group": "kubernetes"
|
|
5746
5797
|
},
|
|
5747
5798
|
{
|
|
5748
5799
|
"name": "k8s.IsHealthy",
|
|
5749
5800
|
"namespace": "k8s",
|
|
5750
|
-
"signature": "(in interface {}) bool"
|
|
5801
|
+
"signature": "(in interface {}) bool",
|
|
5802
|
+
"group": "kubernetes"
|
|
5751
5803
|
},
|
|
5752
5804
|
{
|
|
5753
5805
|
"name": "k8s.IsReady",
|
|
5754
5806
|
"namespace": "k8s",
|
|
5755
|
-
"signature": "(in interface {}) bool"
|
|
5807
|
+
"signature": "(in interface {}) bool",
|
|
5808
|
+
"group": "kubernetes"
|
|
5756
5809
|
},
|
|
5757
5810
|
{
|
|
5758
5811
|
"name": "k8s.Neat",
|
|
5759
5812
|
"namespace": "k8s",
|
|
5760
|
-
"signature": "(in string) (string, error)"
|
|
5813
|
+
"signature": "(in string) (string, error)",
|
|
5814
|
+
"group": "kubernetes"
|
|
5761
5815
|
},
|
|
5762
5816
|
{
|
|
5763
5817
|
"name": "keyValToMap",
|
|
@@ -5873,7 +5927,8 @@ declare const _default: {
|
|
|
5873
5927
|
},
|
|
5874
5928
|
{
|
|
5875
5929
|
"name": "neat",
|
|
5876
|
-
"signature": "(in string) (string, error)"
|
|
5930
|
+
"signature": "(in string) (string, error)",
|
|
5931
|
+
"group": "kubernetes"
|
|
5877
5932
|
},
|
|
5878
5933
|
{
|
|
5879
5934
|
"name": "net.ContainsCIDR",
|
|
@@ -63,7 +63,8 @@ function functionDocumentation(fn) {
|
|
|
63
63
|
lines.push(`- \`${receiver}${leafOf(fn.name)}(${args.join(", ")}) -> ${overload.result}\``);
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
if (fn.examples?.length) lines.push("", "**Examples**", "", "```cel", ...fn.examples, "```");
|
|
66
|
+
if (fn.examples?.length) lines.push("", "**Examples**", "", fn.signature ? "```gomplate" : "```cel", ...fn.examples, "```");
|
|
67
|
+
if (fn.docsUrl) lines.push("", `[Reference](${fn.docsUrl})`);
|
|
67
68
|
return lines.join("\n");
|
|
68
69
|
}
|
|
69
70
|
/** Renders a macro as markdown. */
|
|
@@ -77,6 +78,7 @@ function macroDocumentation(macro) {
|
|
|
77
78
|
];
|
|
78
79
|
if (macro.doc) lines.push("", macro.doc);
|
|
79
80
|
if (macro.examples?.length) lines.push("", "```cel", ...macro.examples, "```");
|
|
81
|
+
if (macro.docsUrl) lines.push("", `[Reference](${macro.docsUrl})`);
|
|
80
82
|
return lines.join("\n");
|
|
81
83
|
}
|
|
82
84
|
function leafOf(name) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hover.cjs","names":[],"sources":["../../../src/expressions/lang/hover.ts"],"sourcesContent":["import type { GomplateSpec, Monaco, SpecFunction, SpecMacro } from \"./types\";\n\n/**\n * Indexes are built per registration, not once per module.\n *\n * A host's catalogue arrives from its `/api/spec` after the editor has already\n * mounted, so anything computed at module scope is frozen before the host can\n * speak. `setSpec` re-registers with a fresh index instead.\n */\nexport function registerCelHover(monaco: Monaco, languageId: string, spec: GomplateSpec) {\n return monaco.languages.registerHoverProvider(languageId, celHoverProvider(spec));\n}\n\nexport function registerGoTemplateHover(monaco: Monaco, languageId: string, spec: GomplateSpec) {\n return monaco.languages.registerHoverProvider(languageId, goTemplateHoverProvider(spec));\n}\n\n/**\n * The providers the register functions install, exposed so a test can drive\n * them over a real model rather than through Monaco's registry, which offers no\n * way to enumerate what is registered.\n */\nexport function celHoverProvider(spec: GomplateSpec) {\n const functions = new Map<string, SpecFunction>(spec.cel.functions.map((f) => [f.name, f]));\n const macrosByName = new Map<string, SpecMacro[]>();\n for (const macro of spec.cel.macros) {\n macrosByName.set(macro.name, [...(macrosByName.get(macro.name) ?? []), macro]);\n }\n\n return {\n provideHover(model: Model, position: Position) {\n const word = dottedWordAt(model, position);\n if (!word) return null;\n\n const fn = functions.get(word.text) ?? functions.get(word.leaf);\n if (fn) return { range: word.range, contents: [{ value: functionDocumentation(fn) }] };\n\n const macros = macrosByName.get(word.leaf);\n if (macros) {\n return {\n range: word.range,\n contents: macros.map((macro) => ({ value: macroDocumentation(macro) })),\n };\n }\n return null;\n },\n };\n}\n\nexport function goTemplateHoverProvider(spec: GomplateSpec) {\n const functions = new Map<string, SpecFunction>(\n spec.gotemplate.functions.map((f) => [f.name, f]),\n );\n\n return {\n provideHover(model: Model, position: Position) {\n const word = dottedWordAt(model, position);\n const fn = word && functions.get(word.text);\n if (!fn || !word) return null;\n return { range: word.range, contents: [{ value: functionDocumentation(fn) }] };\n },\n };\n}\n\n/** Renders a function as markdown: signature, overloads, docs, examples. */\nexport function functionDocumentation(fn: SpecFunction): string {\n const lines: string[] = [];\n lines.push(\"```\", fn.signature ? `${fn.name}${fn.signature}` : fn.name, \"```\");\n\n if (fn.memberOnly) {\n lines.push(\"\", \"_Callable only in member position: `value.\" + leafOf(fn.name) + \"(...)`._\");\n }\n if (fn.doc) lines.push(\"\", fn.doc);\n\n if (fn.overloads?.length) {\n lines.push(\"\", \"**Overloads**\", \"\");\n for (const overload of fn.overloads) {\n const receiver = overload.member && overload.args.length > 0 ? `${overload.args[0]}.` : \"\";\n const args = overload.member ? overload.args.slice(1) : overload.args;\n lines.push(`- \\`${receiver}${leafOf(fn.name)}(${args.join(\", \")}) -> ${overload.result}\\``);\n }\n }\n if (fn.examples?.length) {\n lines.push(\"\", \"**Examples**\", \"\", \"```cel\", ...fn.examples, \"```\");\n }\n return lines.join(\"\\n\");\n}\n\n/** Renders a macro as markdown. */\nexport function macroDocumentation(macro: SpecMacro): string {\n const shape = macro.receiverStyle ? `value.${macro.name}(...)` : `${macro.name}(...)`;\n const arity = macro.argCount === 0 ? \"variadic\" : `${macro.argCount} arguments`;\n const lines = [\"```\", shape, \"```\", \"\", `_Macro, ${arity}. Expanded at parse time._`];\n if (macro.doc) lines.push(\"\", macro.doc);\n if (macro.examples?.length) lines.push(\"\", \"```cel\", ...macro.examples, \"```\");\n return lines.join(\"\\n\");\n}\n\nfunction leafOf(name: string) {\n const dot = name.lastIndexOf(\".\");\n return dot < 0 ? name : name.slice(dot + 1);\n}\n\ninterface Model {\n getLineContent(line: number): string;\n}\n\ninterface Position {\n lineNumber: number;\n column: number;\n}\n\n/**\n * Monaco's own word lookup stops at a dot, so `k8s.isHealthy` would be read as\n * `isHealthy`. The dotted name is what the spec is keyed by, so widen it here.\n */\nfunction dottedWordAt(model: Model, position: Position) {\n const line = model.getLineContent(position.lineNumber);\n const isWord = (c: string) => /[A-Za-z0-9_.]/.test(c);\n\n let start = position.column - 1;\n while (start > 0 && isWord(line[start - 1]!)) start--;\n let end = position.column - 1;\n while (end < line.length && isWord(line[end]!)) end++;\n if (start === end) return null;\n\n const text = line.slice(start, end).replace(/^\\.+|\\.+$/g, \"\");\n if (!text) return null;\n\n return {\n text,\n leaf: leafOf(text),\n range: {\n startLineNumber: position.lineNumber,\n endLineNumber: position.lineNumber,\n startColumn: start + 1,\n endColumn: end + 1,\n },\n };\n}\n"],"mappings":";;;;;;;;AASA,SAAgB,iBAAiB,QAAgB,YAAoB,MAAoB;CACvF,OAAO,OAAO,UAAU,sBAAsB,YAAY,iBAAiB,IAAI,CAAC;AAClF;AAEA,SAAgB,wBAAwB,QAAgB,YAAoB,MAAoB;CAC9F,OAAO,OAAO,UAAU,sBAAsB,YAAY,wBAAwB,IAAI,CAAC;AACzF;;;;;;AAOA,SAAgB,iBAAiB,MAAoB;CACnD,MAAM,YAAY,IAAI,IAA0B,KAAK,IAAI,UAAU,KAAK,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;CAC1F,MAAM,+BAAe,IAAI,IAAyB;CAClD,KAAK,MAAM,SAAS,KAAK,IAAI,QAC3B,aAAa,IAAI,MAAM,MAAM,CAAC,GAAI,aAAa,IAAI,MAAM,IAAI,KAAK,CAAC,GAAI,KAAK,CAAC;CAG/E,OAAO,EACL,aAAa,OAAc,UAAoB;EAC7C,MAAM,OAAO,aAAa,OAAO,QAAQ;EACzC,IAAI,CAAC,MAAM,OAAO;EAElB,MAAM,KAAK,UAAU,IAAI,KAAK,IAAI,KAAK,UAAU,IAAI,KAAK,IAAI;EAC9D,IAAI,IAAI,OAAO;GAAE,OAAO,KAAK;GAAO,UAAU,CAAC,EAAE,OAAO,sBAAsB,EAAE,EAAE,CAAC;EAAE;EAErF,MA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CACA,IAAI,GAAG,UAAU,
|
|
1
|
+
{"version":3,"file":"hover.cjs","names":[],"sources":["../../../src/expressions/lang/hover.ts"],"sourcesContent":["import type { GomplateSpec, Monaco, SpecFunction, SpecMacro } from \"./types.js\";\n\n/**\n * Indexes are built per registration, not once per module.\n *\n * A host's catalogue arrives from its `/api/spec` after the editor has already\n * mounted, so anything computed at module scope is frozen before the host can\n * speak. `setSpec` re-registers with a fresh index instead.\n */\nexport function registerCelHover(monaco: Monaco, languageId: string, spec: GomplateSpec) {\n return monaco.languages.registerHoverProvider(languageId, celHoverProvider(spec));\n}\n\nexport function registerGoTemplateHover(monaco: Monaco, languageId: string, spec: GomplateSpec) {\n return monaco.languages.registerHoverProvider(languageId, goTemplateHoverProvider(spec));\n}\n\n/**\n * The providers the register functions install, exposed so a test can drive\n * them over a real model rather than through Monaco's registry, which offers no\n * way to enumerate what is registered.\n */\nexport function celHoverProvider(spec: GomplateSpec) {\n const functions = new Map<string, SpecFunction>(spec.cel.functions.map((f) => [f.name, f]));\n const macrosByName = new Map<string, SpecMacro[]>();\n for (const macro of spec.cel.macros) {\n macrosByName.set(macro.name, [...(macrosByName.get(macro.name) ?? []), macro]);\n }\n\n return {\n provideHover(model: Model, position: Position) {\n const word = dottedWordAt(model, position);\n if (!word) return null;\n\n const fn = functions.get(word.text) ?? functions.get(word.leaf);\n if (fn) return { range: word.range, contents: [{ value: functionDocumentation(fn) }] };\n\n const macros = macrosByName.get(word.leaf);\n if (macros) {\n return {\n range: word.range,\n contents: macros.map((macro) => ({ value: macroDocumentation(macro) })),\n };\n }\n return null;\n },\n };\n}\n\nexport function goTemplateHoverProvider(spec: GomplateSpec) {\n const functions = new Map<string, SpecFunction>(\n spec.gotemplate.functions.map((f) => [f.name, f]),\n );\n\n return {\n provideHover(model: Model, position: Position) {\n const word = dottedWordAt(model, position);\n const fn = word && functions.get(word.text);\n if (!fn || !word) return null;\n return { range: word.range, contents: [{ value: functionDocumentation(fn) }] };\n },\n };\n}\n\n/** Renders a function as markdown: signature, overloads, docs, examples. */\nexport function functionDocumentation(fn: SpecFunction): string {\n const lines: string[] = [];\n lines.push(\"```\", fn.signature ? `${fn.name}${fn.signature}` : fn.name, \"```\");\n\n if (fn.memberOnly) {\n lines.push(\"\", \"_Callable only in member position: `value.\" + leafOf(fn.name) + \"(...)`._\");\n }\n if (fn.doc) lines.push(\"\", fn.doc);\n\n if (fn.overloads?.length) {\n lines.push(\"\", \"**Overloads**\", \"\");\n for (const overload of fn.overloads) {\n const receiver = overload.member && overload.args.length > 0 ? `${overload.args[0]}.` : \"\";\n const args = overload.member ? overload.args.slice(1) : overload.args;\n lines.push(`- \\`${receiver}${leafOf(fn.name)}(${args.join(\", \")}) -> ${overload.result}\\``);\n }\n }\n if (fn.examples?.length) {\n // A Go signature marks a template function; its examples are templates.\n lines.push(\"\", \"**Examples**\", \"\", fn.signature ? \"```gomplate\" : \"```cel\", ...fn.examples, \"```\");\n }\n if (fn.docsUrl) lines.push(\"\", `[Reference](${fn.docsUrl})`);\n return lines.join(\"\\n\");\n}\n\n/** Renders a macro as markdown. */\nexport function macroDocumentation(macro: SpecMacro): string {\n const shape = macro.receiverStyle ? `value.${macro.name}(...)` : `${macro.name}(...)`;\n const arity = macro.argCount === 0 ? \"variadic\" : `${macro.argCount} arguments`;\n const lines = [\"```\", shape, \"```\", \"\", `_Macro, ${arity}. Expanded at parse time._`];\n if (macro.doc) lines.push(\"\", macro.doc);\n if (macro.examples?.length) lines.push(\"\", \"```cel\", ...macro.examples, \"```\");\n if (macro.docsUrl) lines.push(\"\", `[Reference](${macro.docsUrl})`);\n return lines.join(\"\\n\");\n}\n\nfunction leafOf(name: string) {\n const dot = name.lastIndexOf(\".\");\n return dot < 0 ? name : name.slice(dot + 1);\n}\n\ninterface Model {\n getLineContent(line: number): string;\n}\n\ninterface Position {\n lineNumber: number;\n column: number;\n}\n\n/**\n * Monaco's own word lookup stops at a dot, so `k8s.isHealthy` would be read as\n * `isHealthy`. The dotted name is what the spec is keyed by, so widen it here.\n */\nfunction dottedWordAt(model: Model, position: Position) {\n const line = model.getLineContent(position.lineNumber);\n const isWord = (c: string) => /[A-Za-z0-9_.]/.test(c);\n\n let start = position.column - 1;\n while (start > 0 && isWord(line[start - 1]!)) start--;\n let end = position.column - 1;\n while (end < line.length && isWord(line[end]!)) end++;\n if (start === end) return null;\n\n const text = line.slice(start, end).replace(/^\\.+|\\.+$/g, \"\");\n if (!text) return null;\n\n return {\n text,\n leaf: leafOf(text),\n range: {\n startLineNumber: position.lineNumber,\n endLineNumber: position.lineNumber,\n startColumn: start + 1,\n endColumn: end + 1,\n },\n };\n}\n"],"mappings":";;;;;;;;AASA,SAAgB,iBAAiB,QAAgB,YAAoB,MAAoB;CACvF,OAAO,OAAO,UAAU,sBAAsB,YAAY,iBAAiB,IAAI,CAAC;AAClF;AAEA,SAAgB,wBAAwB,QAAgB,YAAoB,MAAoB;CAC9F,OAAO,OAAO,UAAU,sBAAsB,YAAY,wBAAwB,IAAI,CAAC;AACzF;;;;;;AAOA,SAAgB,iBAAiB,MAAoB;CACnD,MAAM,YAAY,IAAI,IAA0B,KAAK,IAAI,UAAU,KAAK,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;CAC1F,MAAM,+BAAe,IAAI,IAAyB;CAClD,KAAK,MAAM,SAAS,KAAK,IAAI,QAC3B,aAAa,IAAI,MAAM,MAAM,CAAC,GAAI,aAAa,IAAI,MAAM,IAAI,KAAK,CAAC,GAAI,KAAK,CAAC;CAG/E,OAAO,EACL,aAAa,OAAc,UAAoB;EAC7C,MAAM,OAAO,aAAa,OAAO,QAAQ;EACzC,IAAI,CAAC,MAAM,OAAO;EAElB,MAAM,KAAK,UAAU,IAAI,KAAK,IAAI,KAAK,UAAU,IAAI,KAAK,IAAI;EAC9D,IAAI,IAAI,OAAO;GAAE,OAAO,KAAK;GAAO,UAAU,CAAC,EAAE,OAAO,sBAAsB,EAAE,EAAE,CAAC;EAAE;EAErF,MAAM,SAAS,aAA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,IAAI;EACjB,OAAO;GACL,iBAAiB,SAAS;GAC1B,eAAe,SAAS;GACxB,aAAa,QAAQ;GACrB,WAAW,MAAM;EACnB;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hover.d.ts","sourceRoot":"","sources":["../../../src/expressions/lang/hover.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"hover.d.ts","sourceRoot":"","sources":["../../../src/expressions/lang/hover.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEhF;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,uCAEtF;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,uCAE7F;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,YAAY;wBAQ3B,KAAK,YAAY,QAAQ;;;;;;;;;;;EAiBhD;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,YAAY;wBAMlC,KAAK,YAAY,QAAQ;;;;;;;;;;;EAOhD;AAED,4EAA4E;AAC5E,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,YAAY,GAAG,MAAM,CAuB9D;AAED,mCAAmC;AACnC,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAQ3D;AAOD,UAAU,KAAK;IACb,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CACtC;AAED,UAAU,QAAQ;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB"}
|
|
@@ -63,7 +63,8 @@ function functionDocumentation(fn) {
|
|
|
63
63
|
lines.push(`- \`${receiver}${leafOf(fn.name)}(${args.join(", ")}) -> ${overload.result}\``);
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
if (fn.examples?.length) lines.push("", "**Examples**", "", "```cel", ...fn.examples, "```");
|
|
66
|
+
if (fn.examples?.length) lines.push("", "**Examples**", "", fn.signature ? "```gomplate" : "```cel", ...fn.examples, "```");
|
|
67
|
+
if (fn.docsUrl) lines.push("", `[Reference](${fn.docsUrl})`);
|
|
67
68
|
return lines.join("\n");
|
|
68
69
|
}
|
|
69
70
|
/** Renders a macro as markdown. */
|
|
@@ -77,6 +78,7 @@ function macroDocumentation(macro) {
|
|
|
77
78
|
];
|
|
78
79
|
if (macro.doc) lines.push("", macro.doc);
|
|
79
80
|
if (macro.examples?.length) lines.push("", "```cel", ...macro.examples, "```");
|
|
81
|
+
if (macro.docsUrl) lines.push("", `[Reference](${macro.docsUrl})`);
|
|
80
82
|
return lines.join("\n");
|
|
81
83
|
}
|
|
82
84
|
function leafOf(name) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hover.js","names":[],"sources":["../../../src/expressions/lang/hover.ts"],"sourcesContent":["import type { GomplateSpec, Monaco, SpecFunction, SpecMacro } from \"./types\";\n\n/**\n * Indexes are built per registration, not once per module.\n *\n * A host's catalogue arrives from its `/api/spec` after the editor has already\n * mounted, so anything computed at module scope is frozen before the host can\n * speak. `setSpec` re-registers with a fresh index instead.\n */\nexport function registerCelHover(monaco: Monaco, languageId: string, spec: GomplateSpec) {\n return monaco.languages.registerHoverProvider(languageId, celHoverProvider(spec));\n}\n\nexport function registerGoTemplateHover(monaco: Monaco, languageId: string, spec: GomplateSpec) {\n return monaco.languages.registerHoverProvider(languageId, goTemplateHoverProvider(spec));\n}\n\n/**\n * The providers the register functions install, exposed so a test can drive\n * them over a real model rather than through Monaco's registry, which offers no\n * way to enumerate what is registered.\n */\nexport function celHoverProvider(spec: GomplateSpec) {\n const functions = new Map<string, SpecFunction>(spec.cel.functions.map((f) => [f.name, f]));\n const macrosByName = new Map<string, SpecMacro[]>();\n for (const macro of spec.cel.macros) {\n macrosByName.set(macro.name, [...(macrosByName.get(macro.name) ?? []), macro]);\n }\n\n return {\n provideHover(model: Model, position: Position) {\n const word = dottedWordAt(model, position);\n if (!word) return null;\n\n const fn = functions.get(word.text) ?? functions.get(word.leaf);\n if (fn) return { range: word.range, contents: [{ value: functionDocumentation(fn) }] };\n\n const macros = macrosByName.get(word.leaf);\n if (macros) {\n return {\n range: word.range,\n contents: macros.map((macro) => ({ value: macroDocumentation(macro) })),\n };\n }\n return null;\n },\n };\n}\n\nexport function goTemplateHoverProvider(spec: GomplateSpec) {\n const functions = new Map<string, SpecFunction>(\n spec.gotemplate.functions.map((f) => [f.name, f]),\n );\n\n return {\n provideHover(model: Model, position: Position) {\n const word = dottedWordAt(model, position);\n const fn = word && functions.get(word.text);\n if (!fn || !word) return null;\n return { range: word.range, contents: [{ value: functionDocumentation(fn) }] };\n },\n };\n}\n\n/** Renders a function as markdown: signature, overloads, docs, examples. */\nexport function functionDocumentation(fn: SpecFunction): string {\n const lines: string[] = [];\n lines.push(\"```\", fn.signature ? `${fn.name}${fn.signature}` : fn.name, \"```\");\n\n if (fn.memberOnly) {\n lines.push(\"\", \"_Callable only in member position: `value.\" + leafOf(fn.name) + \"(...)`._\");\n }\n if (fn.doc) lines.push(\"\", fn.doc);\n\n if (fn.overloads?.length) {\n lines.push(\"\", \"**Overloads**\", \"\");\n for (const overload of fn.overloads) {\n const receiver = overload.member && overload.args.length > 0 ? `${overload.args[0]}.` : \"\";\n const args = overload.member ? overload.args.slice(1) : overload.args;\n lines.push(`- \\`${receiver}${leafOf(fn.name)}(${args.join(\", \")}) -> ${overload.result}\\``);\n }\n }\n if (fn.examples?.length) {\n lines.push(\"\", \"**Examples**\", \"\", \"```cel\", ...fn.examples, \"```\");\n }\n return lines.join(\"\\n\");\n}\n\n/** Renders a macro as markdown. */\nexport function macroDocumentation(macro: SpecMacro): string {\n const shape = macro.receiverStyle ? `value.${macro.name}(...)` : `${macro.name}(...)`;\n const arity = macro.argCount === 0 ? \"variadic\" : `${macro.argCount} arguments`;\n const lines = [\"```\", shape, \"```\", \"\", `_Macro, ${arity}. Expanded at parse time._`];\n if (macro.doc) lines.push(\"\", macro.doc);\n if (macro.examples?.length) lines.push(\"\", \"```cel\", ...macro.examples, \"```\");\n return lines.join(\"\\n\");\n}\n\nfunction leafOf(name: string) {\n const dot = name.lastIndexOf(\".\");\n return dot < 0 ? name : name.slice(dot + 1);\n}\n\ninterface Model {\n getLineContent(line: number): string;\n}\n\ninterface Position {\n lineNumber: number;\n column: number;\n}\n\n/**\n * Monaco's own word lookup stops at a dot, so `k8s.isHealthy` would be read as\n * `isHealthy`. The dotted name is what the spec is keyed by, so widen it here.\n */\nfunction dottedWordAt(model: Model, position: Position) {\n const line = model.getLineContent(position.lineNumber);\n const isWord = (c: string) => /[A-Za-z0-9_.]/.test(c);\n\n let start = position.column - 1;\n while (start > 0 && isWord(line[start - 1]!)) start--;\n let end = position.column - 1;\n while (end < line.length && isWord(line[end]!)) end++;\n if (start === end) return null;\n\n const text = line.slice(start, end).replace(/^\\.+|\\.+$/g, \"\");\n if (!text) return null;\n\n return {\n text,\n leaf: leafOf(text),\n range: {\n startLineNumber: position.lineNumber,\n endLineNumber: position.lineNumber,\n startColumn: start + 1,\n endColumn: end + 1,\n },\n };\n}\n"],"mappings":";;;;;;;;AASA,SAAgB,iBAAiB,QAAgB,YAAoB,MAAoB;CACvF,OAAO,OAAO,UAAU,sBAAsB,YAAY,iBAAiB,IAAI,CAAC;AAClF;AAEA,SAAgB,wBAAwB,QAAgB,YAAoB,MAAoB;CAC9F,OAAO,OAAO,UAAU,sBAAsB,YAAY,wBAAwB,IAAI,CAAC;AACzF;;;;;;AAOA,SAAgB,iBAAiB,MAAoB;CACnD,MAAM,YAAY,IAAI,IAA0B,KAAK,IAAI,U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AE7E,IAAI,GAAG,YACL,MAAM,KAAK,IAAI,+CAA+C,OAAO,GAAG,IAAI,IAAI,UAAU;CAE5F,IAAI,GAAG,KAAK,MAAM,KAAK,IAAI,GAAG,GAAG;CAEjC,IAAI,GAAG,WAAW,QAAQ;EACxB,MAAM,KAAK,IAAI,iBAAiB,EAAE;EAClC,KAAK,MAAM,YAAY,GAAG,WAAW;GACnC,MAAM,WAAW,SAAS,UAAU,SAAS,KAAK,SAAS,IAAI,GAAG,SAAS,KAAK,GAAG,KAAK;GACxF,MAAM,OAAO,SAAS,SAAS,SAAS,KAAK,MAAM,CAAC,IAAI,SAAS;GACjE,MAAM,KAAK,OAAO,WAAW,OAAO,GAAG,IAAI,EAAE,GAAG,KAAK,KAAK,IAAI,EAAE,OAAO,SAAS,OAAO,GAAG;EAC5F;CACF;CACA,IAAI,GAAG,UAAU,
|
|
1
|
+
{"version":3,"file":"hover.js","names":[],"sources":["../../../src/expressions/lang/hover.ts"],"sourcesContent":["import type { GomplateSpec, Monaco, SpecFunction, SpecMacro } from \"./types.js\";\n\n/**\n * Indexes are built per registration, not once per module.\n *\n * A host's catalogue arrives from its `/api/spec` after the editor has already\n * mounted, so anything computed at module scope is frozen before the host can\n * speak. `setSpec` re-registers with a fresh index instead.\n */\nexport function registerCelHover(monaco: Monaco, languageId: string, spec: GomplateSpec) {\n return monaco.languages.registerHoverProvider(languageId, celHoverProvider(spec));\n}\n\nexport function registerGoTemplateHover(monaco: Monaco, languageId: string, spec: GomplateSpec) {\n return monaco.languages.registerHoverProvider(languageId, goTemplateHoverProvider(spec));\n}\n\n/**\n * The providers the register functions install, exposed so a test can drive\n * them over a real model rather than through Monaco's registry, which offers no\n * way to enumerate what is registered.\n */\nexport function celHoverProvider(spec: GomplateSpec) {\n const functions = new Map<string, SpecFunction>(spec.cel.functions.map((f) => [f.name, f]));\n const macrosByName = new Map<string, SpecMacro[]>();\n for (const macro of spec.cel.macros) {\n macrosByName.set(macro.name, [...(macrosByName.get(macro.name) ?? []), macro]);\n }\n\n return {\n provideHover(model: Model, position: Position) {\n const word = dottedWordAt(model, position);\n if (!word) return null;\n\n const fn = functions.get(word.text) ?? functions.get(word.leaf);\n if (fn) return { range: word.range, contents: [{ value: functionDocumentation(fn) }] };\n\n const macros = macrosByName.get(word.leaf);\n if (macros) {\n return {\n range: word.range,\n contents: macros.map((macro) => ({ value: macroDocumentation(macro) })),\n };\n }\n return null;\n },\n };\n}\n\nexport function goTemplateHoverProvider(spec: GomplateSpec) {\n const functions = new Map<string, SpecFunction>(\n spec.gotemplate.functions.map((f) => [f.name, f]),\n );\n\n return {\n provideHover(model: Model, position: Position) {\n const word = dottedWordAt(model, position);\n const fn = word && functions.get(word.text);\n if (!fn || !word) return null;\n return { range: word.range, contents: [{ value: functionDocumentation(fn) }] };\n },\n };\n}\n\n/** Renders a function as markdown: signature, overloads, docs, examples. */\nexport function functionDocumentation(fn: SpecFunction): string {\n const lines: string[] = [];\n lines.push(\"```\", fn.signature ? `${fn.name}${fn.signature}` : fn.name, \"```\");\n\n if (fn.memberOnly) {\n lines.push(\"\", \"_Callable only in member position: `value.\" + leafOf(fn.name) + \"(...)`._\");\n }\n if (fn.doc) lines.push(\"\", fn.doc);\n\n if (fn.overloads?.length) {\n lines.push(\"\", \"**Overloads**\", \"\");\n for (const overload of fn.overloads) {\n const receiver = overload.member && overload.args.length > 0 ? `${overload.args[0]}.` : \"\";\n const args = overload.member ? overload.args.slice(1) : overload.args;\n lines.push(`- \\`${receiver}${leafOf(fn.name)}(${args.join(\", \")}) -> ${overload.result}\\``);\n }\n }\n if (fn.examples?.length) {\n // A Go signature marks a template function; its examples are templates.\n lines.push(\"\", \"**Examples**\", \"\", fn.signature ? \"```gomplate\" : \"```cel\", ...fn.examples, \"```\");\n }\n if (fn.docsUrl) lines.push(\"\", `[Reference](${fn.docsUrl})`);\n return lines.join(\"\\n\");\n}\n\n/** Renders a macro as markdown. */\nexport function macroDocumentation(macro: SpecMacro): string {\n const shape = macro.receiverStyle ? `value.${macro.name}(...)` : `${macro.name}(...)`;\n const arity = macro.argCount === 0 ? \"variadic\" : `${macro.argCount} arguments`;\n const lines = [\"```\", shape, \"```\", \"\", `_Macro, ${arity}. Expanded at parse time._`];\n if (macro.doc) lines.push(\"\", macro.doc);\n if (macro.examples?.length) lines.push(\"\", \"```cel\", ...macro.examples, \"```\");\n if (macro.docsUrl) lines.push(\"\", `[Reference](${macro.docsUrl})`);\n return lines.join(\"\\n\");\n}\n\nfunction leafOf(name: string) {\n const dot = name.lastIndexOf(\".\");\n return dot < 0 ? name : name.slice(dot + 1);\n}\n\ninterface Model {\n getLineContent(line: number): string;\n}\n\ninterface Position {\n lineNumber: number;\n column: number;\n}\n\n/**\n * Monaco's own word lookup stops at a dot, so `k8s.isHealthy` would be read as\n * `isHealthy`. The dotted name is what the spec is keyed by, so widen it here.\n */\nfunction dottedWordAt(model: Model, position: Position) {\n const line = model.getLineContent(position.lineNumber);\n const isWord = (c: string) => /[A-Za-z0-9_.]/.test(c);\n\n let start = position.column - 1;\n while (start > 0 && isWord(line[start - 1]!)) start--;\n let end = position.column - 1;\n while (end < line.length && isWord(line[end]!)) end++;\n if (start === end) return null;\n\n const text = line.slice(start, end).replace(/^\\.+|\\.+$/g, \"\");\n if (!text) return null;\n\n return {\n text,\n leaf: leafOf(text),\n range: {\n startLineNumber: position.lineNumber,\n endLineNumber: position.lineNumber,\n startColumn: start + 1,\n endColumn: end + 1,\n },\n };\n}\n"],"mappings":";;;;;;;;AASA,SAAgB,iBAAiB,QAAgB,YAAoB,MAAoB;CACvF,OAAO,OAAO,UAAU,sBAAsB,YAAY,iBAAiB,IAAI,CAAC;AAClF;AAEA,SAAgB,wBAAwB,QAAgB,YAAoB,MAAoB;CAC9F,OAAO,OAAO,UAAU,sBAAsB,YAAY,wBAAwB,IAAI,CAAC;AACzF;;;;;;AAOA,SAAgB,iBAAiB,MAAoB;CACnD,MAAM,YAAY,IAAI,IAA0B,KAAK,IAAI,UAAU,KAAK,MAAM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AAI,OAAO,KAAK,MAAM,MAAM,CAAC;AAC5C;;;;;AAeA,SAAS,aAAa,OAAc,UAAoB;CACtD,MAAM,OAAO,MAAM,eAAe,SAAS,UAAU;CACrD,MAAM,UAAU,MAAc,gBAAgB,KAAK,CAAC;CAEpD,IAAI,QAAQ,SAAS,SAAS;CAC9B,OAAO,QAAQ,KAAK,OAAO,KAAK,QAAQ,EAAG,GAAG;CAC9C,IAAI,MAAM,SAAS,SAAS;CAC5B,OAAO,MAAM,KAAK,UAAU,OAAO,KAAK,IAAK,GAAG;CAChD,IAAI,UAAU,KAAK,OAAO;CAE1B,MAAM,OAAO,KAAK,MAAM,OAAO,GAAG,CAAC,CAAC,QAAQ,cAAc,EAAE;CAC5D,IAAI,CAAC,MAAM,OAAO;CAElB,OAAO;EACL;EACA,MAAM,OAAO,IAAI;EACjB,OAAO;GACL,iBAAiB,SAAS;GAC1B,eAAe,SAAS;GACxB,aAAa,QAAQ;GACrB,WAAW,MAAM;EACnB;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["LANGUAGE_IDS","definitions","attributesFor","pathFlavour","registerCompletion","registerCelHover","registerGoTemplateHover","mergeSpec","spec"],"sources":["../../../src/expressions/lang/index.ts"],"sourcesContent":["import { LANGUAGE_IDS, definitions, spec } from \"./generated\";\nimport type { LanguageId } from \"./generated\";\nimport { registerCompletion } from \"./completion\";\nimport type { EnvironmentSource } from \"./completion\";\nimport { registerCelHover, registerGoTemplateHover } from \"./hover\";\nimport { pathFlavour } from \"./environment\";\nimport { attributesFor } from \"./attributes\";\nimport { mergeSpec } from \"./merge\";\nimport { defineThemes } from \"./theme\";\nimport type { GomplateSpec, LanguageDefinition, Monaco } from \"./types\";\n\nexport { spec, LANGUAGE_IDS, definitions };\nexport type { LanguageId };\nexport * from \"./types\";\nexport { GOMPLATE_DARK_THEME, GOMPLATE_LIGHT_THEME } from \"./theme\";\nexport {\n childEntries,\n isIdentifier,\n kindOf,\n pathExpression,\n pathFlavour,\n resolvePath,\n summarize,\n} from \"./environment\";\nexport type { EnvironmentEntry, PathSegment, ValueKind } from \"./environment\";\nexport { environmentPrefixAt } from \"./prefix\";\nexport type { EnvironmentPrefix } from \"./prefix\";\nexport type { EnvironmentSource } from \"./completion\";\nexport { mergeSpec } from \"./merge\";\nexport { attributesFor, celAttributes, goTemplateAttributes } from \"./attributes\";\nexport type { Attributes } from \"./attributes\";\n\nexport interface RegisterOptions {\n /** Which languages to register. Defaults to all of them. */\n languages?: readonly LanguageId[];\n /** Register completion providers. Defaults to true. */\n completions?: boolean;\n /** Register hover providers. Defaults to true. */\n hovers?: boolean;\n /** Define the gomplate colour themes. Defaults to true. */\n themes?: boolean;\n /**\n * The document expressions are evaluated against, so completion can offer the\n * key paths it actually contains.\n *\n * A getter rather than a value: registration happens once, before the first\n * editor mounts, while the document keeps being edited afterwards. It is\n * called on every completion request.\n */\n environment?: EnvironmentSource;\n /**\n * A host's own catalogue, merged over gomplate's.\n *\n * Usually left unset here and supplied later through `setSpec`, because it\n * arrives from the host's `GET /api/spec` after the editor has mounted.\n */\n spec?: GomplateSpec;\n}\n\n/** What `registerGomplateLanguages` hands back. */\nexport interface RegisteredLanguages {\n /**\n * Replaces the catalogue and re-applies it.\n *\n * Registration has to happen in `beforeMount`, before the first model exists,\n * while a host's spec arrives over the network afterwards — so gating\n * registration on the fetch would stall the editor. Register with the baked\n * catalogue instead and call this when the response lands: the tokenizers are\n * re-applied with the merged word lists, and completion and hover are\n * re-registered against the merged functions.\n */\n setSpec(spec: GomplateSpec | undefined): void;\n dispose(): void;\n}\n\n/**\n * Registers gomplate's languages with a Monaco instance.\n *\n * Safe to call more than once: a language already registered is left alone, so\n * a component tree with several editors does not need to coordinate. The\n * returned handle removes only the providers this call added.\n */\nexport function registerGomplateLanguages(\n monaco: Monaco,\n options: RegisterOptions = {},\n): RegisteredLanguages {\n const { languages = LANGUAGE_IDS, completions = true, hovers = true, themes = true } = options;\n\n if (themes) defineThemes(monaco);\n\n const known = new Set(monaco.languages.getLanguages().map((l) => l.id));\n const selected: LanguageId[] = [];\n\n for (const id of languages) {\n const definition: LanguageDefinition | undefined = definitions[id];\n if (!definition) {\n throw new Error(\n `unknown gomplate language \"${id}\"; expected one of ${LANGUAGE_IDS.join(\", \")}`,\n );\n }\n selected.push(id);\n\n // Only the registration itself is once-only. The tokenizer and the\n // providers are re-applied below for every selected language, whether or\n // not this call is the one that introduced it -- otherwise a second editor\n // would get a handle whose setSpec silently does nothing.\n if (known.has(id)) continue;\n monaco.languages.register({ id });\n monaco.languages.setLanguageConfiguration(id, definition.configuration);\n }\n\n const applySpec = (merged: GomplateSpec) => {\n for (const id of selected) {\n const definition = definitions[id]!;\n const attributes = attributesFor(id, merged);\n // Spread over the generated definition rather than replacing it: the\n // tokenizer rules and the grammar-derived lists (CEL's `operators`) are\n // not the spec's to change.\n monaco.languages.setMonarchTokensProvider(\n id,\n attributes ? { ...definition.monarch, ...attributes } : definition.monarch,\n );\n\n const flavour = pathFlavour(id);\n const installed: { dispose(): void }[] = [];\n if (completions) {\n installed.push(\n registerCompletion(monaco, id, { spec: merged, environment: options.environment }),\n );\n }\n if (hovers && flavour === \"cel\") installed.push(registerCelHover(monaco, id, merged));\n if (hovers && flavour === \"gotemplate\") {\n installed.push(registerGoTemplateHover(monaco, id, merged));\n }\n replaceProviders(monaco, id, installed);\n }\n };\n\n applySpec(mergeSpec(spec, options.spec));\n\n return {\n setSpec(next) {\n applySpec(mergeSpec(spec, next));\n },\n dispose() {\n for (const id of selected) replaceProviders(monaco, id, []);\n },\n };\n}\n\n/**\n * One set of completion and hover providers per language, per Monaco.\n *\n * Monaco stacks providers rather than replacing them, so registering twice for\n * a language shows every suggestion twice. Tracking them here means the latest\n * registration wins instead, and a component tree with several editors does not\n * have to coordinate.\n */\nconst providersByLanguage = new WeakMap<Monaco, Map<string, { dispose(): void }[]>>();\n\nfunction replaceProviders(monaco: Monaco, id: string, installed: { dispose(): void }[]) {\n let byLanguage = providersByLanguage.get(monaco);\n if (!byLanguage) {\n byLanguage = new Map();\n providersByLanguage.set(monaco, byLanguage);\n }\n for (const disposable of byLanguage.get(id) ?? []) disposable.dispose();\n if (installed.length === 0) byLanguage.delete(id);\n else byLanguage.set(id, installed);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkFA,SAAgB,0BACd,QACA,UAA2B,CAAC,GACP;CACrB,MAAM,EAAE,YAAYA,cAAAA,cAAc,cAAc,MAAM,SAAS,MAAM,SAAS,SAAS;CAEvF,IAAI,QAAQ,cAAA,aAAa,MAAM;CAE/B,MAAM,QAAQ,IAAI,IAAI,OAAO,UAAU,aAAa,CAAC,CAAC,KAAK,MAAM,EAAE,EAAE,CAAC;CACtE,MAAM,WAAyB,CAAC;CAEhC,KAAK,MAAM,MAAM,WAAW;EAC1B,MAAM,aAA6CC,cAAAA,YAAY;EAC/D,IAAI,CAAC,YACH,MAAM,IAAI,MACR,8BAA8B,GAAG,qBAAqBD,cAAAA,aAAa,KAAK,IAAI,GAC9E;EAEF,SAAS,KAAK,EAAE;EAMhB,IAAI,MAAM,IAAI,EAAE,GAAG;EACnB,OAAO,UAAU,SAAS,EAAE,GAAG,CAAC;EAChC,OAAO,UAAU,yBAAyB,IAAI,WAAW,aAAa;CACxE;CAEA,MAAM,aAAa,WAAyB;EAC1C,KAAK,MAAM,MAAM,UAAU;GACzB,MAAM,aAAaC,cAAAA,YAAY;GAC/B,MAAM,aAAaC,mBAAAA,cAAc,IAAI,MAAM;GAI3C,OAAO,UAAU,yBACf,IACA,aAAa;IAAE,GAAG,WAAW;IAAS,GAAG;GAAW,IAAI,WAAW,OACrE;GAEA,MAAM,UAAUC,oBAAAA,YAAY,EAAE;GAC9B,MAAM,YAAmC,CAAC;GAC1C,IAAI,aACF,UAAU,KACRC,mBAAAA,mBAAmB,QAAQ,IAAI;IAAE,MAAM;IAAQ,aAAa,QAAQ;GAAY,CAAC,CACnF;GAEF,IAAI,UAAU,YAAY,OAAO,UAAU,KAAKC,cAAAA,iBAAiB,QAAQ,IAAI,MAAM,CAAC;GACpF,IAAI,UAAU,YAAY,cACxB,UAAU,KAAKC,cAAAA,wBAAwB,QAAQ,IAAI,MAAM,CAAC;GAE5D,iBAAiB,QAAQ,IAAI,SAAS;EACxC;CACF;CAEA,UAAUC,cAAAA,UAAUC,cAAAA,MAAM,QAAQ,IAAI,CAAC;CAEvC,OAAO;EACL,QAAQ,MAAM;GACZ,UAAUD,cAAAA,UAAUC,cAAAA,MAAM,IAAI,CAAC;EACjC;EACA,UAAU;GACR,KAAK,MAAM,MAAM,UAAU,iBAAiB,QAAQ,IAAI,CAAC,CAAC;EAC5D;CACF;AACF;;;;;;;;;AAUA,IAAM,sCAAsB,IAAI,QAAoD;AAEpF,SAAS,iBAAiB,QAAgB,IAAY,WAAkC;CACtF,IAAI,aAAa,oBAAoB,IAAI,MAAM;CAC/C,IAAI,CAAC,YAAY;EACf,6BAAa,IAAI,IAAI;EACrB,oBAAoB,IAAI,QAAQ,UAAU;CAC5C;CACA,KAAK,MAAM,cAAc,WAAW,IAAI,EAAE,KAAK,CAAC,GAAG,WAAW,QAAQ;CACtE,IAAI,UAAU,WAAW,GAAG,WAAW,OAAO,EAAE;MAC3C,WAAW,IAAI,IAAI,SAAS;AACnC"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["LANGUAGE_IDS","definitions","attributesFor","pathFlavour","registerCompletion","registerCelHover","registerGoTemplateHover","mergeSpec","spec"],"sources":["../../../src/expressions/lang/index.ts"],"sourcesContent":["import { LANGUAGE_IDS, definitions, spec } from \"./generated/index.js\";\nimport type { LanguageId } from \"./generated/index.js\";\nimport { registerCompletion } from \"./completion.js\";\nimport type { EnvironmentSource } from \"./completion.js\";\nimport { registerCelHover, registerGoTemplateHover } from \"./hover.js\";\nimport { pathFlavour } from \"./environment.js\";\nimport { attributesFor } from \"./attributes.js\";\nimport { mergeSpec } from \"./merge.js\";\nimport { defineThemes } from \"./theme.js\";\nimport type { GomplateSpec, LanguageDefinition, Monaco } from \"./types.js\";\n\nexport { spec, LANGUAGE_IDS, definitions };\nexport type { LanguageId };\nexport * from \"./types.js\";\nexport { GOMPLATE_DARK_THEME, GOMPLATE_LIGHT_THEME } from \"./theme.js\";\nexport {\n childEntries,\n isIdentifier,\n kindOf,\n pathExpression,\n pathFlavour,\n resolvePath,\n summarize,\n} from \"./environment.js\";\nexport type { EnvironmentEntry, PathSegment, ValueKind } from \"./environment.js\";\nexport { environmentPrefixAt } from \"./prefix.js\";\nexport type { EnvironmentPrefix } from \"./prefix.js\";\nexport type { EnvironmentSource } from \"./completion.js\";\nexport { mergeSpec } from \"./merge.js\";\nexport { attributesFor, celAttributes, goTemplateAttributes } from \"./attributes.js\";\nexport type { Attributes } from \"./attributes.js\";\n\nexport interface RegisterOptions {\n /** Which languages to register. Defaults to all of them. */\n languages?: readonly LanguageId[];\n /** Register completion providers. Defaults to true. */\n completions?: boolean;\n /** Register hover providers. Defaults to true. */\n hovers?: boolean;\n /** Define the gomplate colour themes. Defaults to true. */\n themes?: boolean;\n /**\n * The document expressions are evaluated against, so completion can offer the\n * key paths it actually contains.\n *\n * A getter rather than a value: registration happens once, before the first\n * editor mounts, while the document keeps being edited afterwards. It is\n * called on every completion request.\n */\n environment?: EnvironmentSource;\n /**\n * A host's own catalogue, merged over gomplate's.\n *\n * Usually left unset here and supplied later through `setSpec`, because it\n * arrives from the host's `GET /api/spec` after the editor has mounted.\n */\n spec?: GomplateSpec;\n}\n\n/** What `registerGomplateLanguages` hands back. */\nexport interface RegisteredLanguages {\n /**\n * Replaces the catalogue and re-applies it.\n *\n * Registration has to happen in `beforeMount`, before the first model exists,\n * while a host's spec arrives over the network afterwards — so gating\n * registration on the fetch would stall the editor. Register with the baked\n * catalogue instead and call this when the response lands: the tokenizers are\n * re-applied with the merged word lists, and completion and hover are\n * re-registered against the merged functions.\n */\n setSpec(spec: GomplateSpec | undefined): void;\n dispose(): void;\n}\n\n/**\n * Registers gomplate's languages with a Monaco instance.\n *\n * Safe to call more than once: a language already registered is left alone, so\n * a component tree with several editors does not need to coordinate. The\n * returned handle removes only the providers this call added.\n */\nexport function registerGomplateLanguages(\n monaco: Monaco,\n options: RegisterOptions = {},\n): RegisteredLanguages {\n const { languages = LANGUAGE_IDS, completions = true, hovers = true, themes = true } = options;\n\n if (themes) defineThemes(monaco);\n\n const known = new Set(monaco.languages.getLanguages().map((l) => l.id));\n const selected: LanguageId[] = [];\n\n for (const id of languages) {\n const definition: LanguageDefinition | undefined = definitions[id];\n if (!definition) {\n throw new Error(\n `unknown gomplate language \"${id}\"; expected one of ${LANGUAGE_IDS.join(\", \")}`,\n );\n }\n selected.push(id);\n\n // Only the registration itself is once-only. The tokenizer and the\n // providers are re-applied below for every selected language, whether or\n // not this call is the one that introduced it -- otherwise a second editor\n // would get a handle whose setSpec silently does nothing.\n if (known.has(id)) continue;\n monaco.languages.register({ id });\n monaco.languages.setLanguageConfiguration(id, definition.configuration);\n }\n\n const applySpec = (merged: GomplateSpec) => {\n for (const id of selected) {\n const definition = definitions[id]!;\n const attributes = attributesFor(id, merged);\n // Spread over the generated definition rather than replacing it: the\n // tokenizer rules and the grammar-derived lists (CEL's `operators`) are\n // not the spec's to change.\n monaco.languages.setMonarchTokensProvider(\n id,\n attributes ? { ...definition.monarch, ...attributes } : definition.monarch,\n );\n\n const flavour = pathFlavour(id);\n const installed: { dispose(): void }[] = [];\n if (completions) {\n installed.push(\n registerCompletion(monaco, id, { spec: merged, environment: options.environment }),\n );\n }\n if (hovers && flavour === \"cel\") installed.push(registerCelHover(monaco, id, merged));\n if (hovers && flavour === \"gotemplate\") {\n installed.push(registerGoTemplateHover(monaco, id, merged));\n }\n replaceProviders(monaco, id, installed);\n }\n };\n\n applySpec(mergeSpec(spec, options.spec));\n\n return {\n setSpec(next) {\n applySpec(mergeSpec(spec, next));\n },\n dispose() {\n for (const id of selected) replaceProviders(monaco, id, []);\n },\n };\n}\n\n/**\n * One set of completion and hover providers per language, per Monaco.\n *\n * Monaco stacks providers rather than replacing them, so registering twice for\n * a language shows every suggestion twice. Tracking them here means the latest\n * registration wins instead, and a component tree with several editors does not\n * have to coordinate.\n */\nconst providersByLanguage = new WeakMap<Monaco, Map<string, { dispose(): void }[]>>();\n\nfunction replaceProviders(monaco: Monaco, id: string, installed: { dispose(): void }[]) {\n let byLanguage = providersByLanguage.get(monaco);\n if (!byLanguage) {\n byLanguage = new Map();\n providersByLanguage.set(monaco, byLanguage);\n }\n for (const disposable of byLanguage.get(id) ?? []) disposable.dispose();\n if (installed.length === 0) byLanguage.delete(id);\n else byLanguage.set(id, installed);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkFA,SAAgB,0BACd,QACA,UAA2B,CAAC,GACP;CACrB,MAAM,EAAE,YAAYA,cAAAA,cAAc,cAAc,MAAM,SAAS,MAAM,SAAS,SAAS;CAEvF,IAAI,QAAQ,cAAA,aAAa,MAAM;CAE/B,MAAM,QAAQ,IAAI,IAAI,OAAO,UAAU,aAAa,CAAC,CAAC,KAAK,MAAM,EAAE,EAAE,CAAC;CACtE,MAAM,WAAyB,CAAC;CAEhC,KAAK,MAAM,MAAM,WAAW;EAC1B,MAAM,aAA6CC,cAAAA,YAAY;EAC/D,IAAI,CAAC,YACH,MAAM,IAAI,MACR,8BAA8B,GAAG,qBAAqBD,cAAAA,aAAa,KAAK,IAAI,GAC9E;EAEF,SAAS,KAAK,EAAE;EAMhB,IAAI,MAAM,IAAI,EAAE,GAAG;EACnB,OAAO,UAAU,SAAS,EAAE,GAAG,CAAC;EAChC,OAAO,UAAU,yBAAyB,IAAI,WAAW,aAAa;CACxE;CAEA,MAAM,aAAa,WAAyB;EAC1C,KAAK,MAAM,MAAM,UAAU;GACzB,MAAM,aAAaC,cAAAA,YAAY;GAC/B,MAAM,aAAaC,mBAAAA,cAAc,IAAI,MAAM;GAI3C,OAAO,UAAU,yBACf,IACA,aAAa;IAAE,GAAG,WAAW;IAAS,GAAG;GAAW,IAAI,WAAW,OACrE;GAEA,MAAM,UAAUC,oBAAAA,YAAY,EAAE;GAC9B,MAAM,YAAmC,CAAC;GAC1C,IAAI,aACF,UAAU,KACRC,mBAAAA,mBAAmB,QAAQ,IAAI;IAAE,MAAM;IAAQ,aAAa,QAAQ;GAAY,CAAC,CACnF;GAEF,IAAI,UAAU,YAAY,OAAO,UAAU,KAAKC,cAAAA,iBAAiB,QAAQ,IAAI,MAAM,CAAC;GACpF,IAAI,UAAU,YAAY,cACxB,UAAU,KAAKC,cAAAA,wBAAwB,QAAQ,IAAI,MAAM,CAAC;GAE5D,iBAAiB,QAAQ,IAAI,SAAS;EACxC;CACF;CAEA,UAAUC,cAAAA,UAAUC,cAAAA,MAAM,QAAQ,IAAI,CAAC;CAEvC,OAAO;EACL,QAAQ,MAAM;GACZ,UAAUD,cAAAA,UAAUC,cAAAA,MAAM,IAAI,CAAC;EACjC;EACA,UAAU;GACR,KAAK,MAAM,MAAM,UAAU,iBAAiB,QAAQ,IAAI,CAAC,CAAC;EAC5D;CACF;AACF;;;;;;;;;AAUA,IAAM,sCAAsB,IAAI,QAAoD;AAEpF,SAAS,iBAAiB,QAAgB,IAAY,WAAkC;CACtF,IAAI,aAAa,oBAAoB,IAAI,MAAM;CAC/C,IAAI,CAAC,YAAY;EACf,6BAAa,IAAI,IAAI;EACrB,oBAAoB,IAAI,QAAQ,UAAU;CAC5C;CACA,KAAK,MAAM,cAAc,WAAW,IAAI,EAAE,KAAK,CAAC,GAAG,WAAW,QAAQ;CACtE,IAAI,UAAU,WAAW,GAAG,WAAW,OAAO,EAAE;MAC3C,WAAW,IAAI,IAAI,SAAS;AACnC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/expressions/lang/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/expressions/lang/index.ts"],"names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;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAChC;;;;;OAKG;IACH,IAAI,CAAC,EAAE,YAAY,CAAC;CACrB;AAED,mDAAmD;AACnD,MAAM,WAAW,mBAAmB;IAClC;;;;;;;;;OASG;IACH,OAAO,CAAC,IAAI,EAAE,YAAY,GAAG,SAAS,GAAG,IAAI,CAAC;IAC9C,OAAO,IAAI,IAAI,CAAC;CACjB;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,eAAoB,GAC5B,mBAAmB,CA+DrB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/expressions/lang/index.ts"],"sourcesContent":["import { LANGUAGE_IDS, definitions, spec } from \"./generated\";\nimport type { LanguageId } from \"./generated\";\nimport { registerCompletion } from \"./completion\";\nimport type { EnvironmentSource } from \"./completion\";\nimport { registerCelHover, registerGoTemplateHover } from \"./hover\";\nimport { pathFlavour } from \"./environment\";\nimport { attributesFor } from \"./attributes\";\nimport { mergeSpec } from \"./merge\";\nimport { defineThemes } from \"./theme\";\nimport type { GomplateSpec, LanguageDefinition, Monaco } from \"./types\";\n\nexport { spec, LANGUAGE_IDS, definitions };\nexport type { LanguageId };\nexport * from \"./types\";\nexport { GOMPLATE_DARK_THEME, GOMPLATE_LIGHT_THEME } from \"./theme\";\nexport {\n childEntries,\n isIdentifier,\n kindOf,\n pathExpression,\n pathFlavour,\n resolvePath,\n summarize,\n} from \"./environment\";\nexport type { EnvironmentEntry, PathSegment, ValueKind } from \"./environment\";\nexport { environmentPrefixAt } from \"./prefix\";\nexport type { EnvironmentPrefix } from \"./prefix\";\nexport type { EnvironmentSource } from \"./completion\";\nexport { mergeSpec } from \"./merge\";\nexport { attributesFor, celAttributes, goTemplateAttributes } from \"./attributes\";\nexport type { Attributes } from \"./attributes\";\n\nexport interface RegisterOptions {\n /** Which languages to register. Defaults to all of them. */\n languages?: readonly LanguageId[];\n /** Register completion providers. Defaults to true. */\n completions?: boolean;\n /** Register hover providers. Defaults to true. */\n hovers?: boolean;\n /** Define the gomplate colour themes. Defaults to true. */\n themes?: boolean;\n /**\n * The document expressions are evaluated against, so completion can offer the\n * key paths it actually contains.\n *\n * A getter rather than a value: registration happens once, before the first\n * editor mounts, while the document keeps being edited afterwards. It is\n * called on every completion request.\n */\n environment?: EnvironmentSource;\n /**\n * A host's own catalogue, merged over gomplate's.\n *\n * Usually left unset here and supplied later through `setSpec`, because it\n * arrives from the host's `GET /api/spec` after the editor has mounted.\n */\n spec?: GomplateSpec;\n}\n\n/** What `registerGomplateLanguages` hands back. */\nexport interface RegisteredLanguages {\n /**\n * Replaces the catalogue and re-applies it.\n *\n * Registration has to happen in `beforeMount`, before the first model exists,\n * while a host's spec arrives over the network afterwards — so gating\n * registration on the fetch would stall the editor. Register with the baked\n * catalogue instead and call this when the response lands: the tokenizers are\n * re-applied with the merged word lists, and completion and hover are\n * re-registered against the merged functions.\n */\n setSpec(spec: GomplateSpec | undefined): void;\n dispose(): void;\n}\n\n/**\n * Registers gomplate's languages with a Monaco instance.\n *\n * Safe to call more than once: a language already registered is left alone, so\n * a component tree with several editors does not need to coordinate. The\n * returned handle removes only the providers this call added.\n */\nexport function registerGomplateLanguages(\n monaco: Monaco,\n options: RegisterOptions = {},\n): RegisteredLanguages {\n const { languages = LANGUAGE_IDS, completions = true, hovers = true, themes = true } = options;\n\n if (themes) defineThemes(monaco);\n\n const known = new Set(monaco.languages.getLanguages().map((l) => l.id));\n const selected: LanguageId[] = [];\n\n for (const id of languages) {\n const definition: LanguageDefinition | undefined = definitions[id];\n if (!definition) {\n throw new Error(\n `unknown gomplate language \"${id}\"; expected one of ${LANGUAGE_IDS.join(\", \")}`,\n );\n }\n selected.push(id);\n\n // Only the registration itself is once-only. The tokenizer and the\n // providers are re-applied below for every selected language, whether or\n // not this call is the one that introduced it -- otherwise a second editor\n // would get a handle whose setSpec silently does nothing.\n if (known.has(id)) continue;\n monaco.languages.register({ id });\n monaco.languages.setLanguageConfiguration(id, definition.configuration);\n }\n\n const applySpec = (merged: GomplateSpec) => {\n for (const id of selected) {\n const definition = definitions[id]!;\n const attributes = attributesFor(id, merged);\n // Spread over the generated definition rather than replacing it: the\n // tokenizer rules and the grammar-derived lists (CEL's `operators`) are\n // not the spec's to change.\n monaco.languages.setMonarchTokensProvider(\n id,\n attributes ? { ...definition.monarch, ...attributes } : definition.monarch,\n );\n\n const flavour = pathFlavour(id);\n const installed: { dispose(): void }[] = [];\n if (completions) {\n installed.push(\n registerCompletion(monaco, id, { spec: merged, environment: options.environment }),\n );\n }\n if (hovers && flavour === \"cel\") installed.push(registerCelHover(monaco, id, merged));\n if (hovers && flavour === \"gotemplate\") {\n installed.push(registerGoTemplateHover(monaco, id, merged));\n }\n replaceProviders(monaco, id, installed);\n }\n };\n\n applySpec(mergeSpec(spec, options.spec));\n\n return {\n setSpec(next) {\n applySpec(mergeSpec(spec, next));\n },\n dispose() {\n for (const id of selected) replaceProviders(monaco, id, []);\n },\n };\n}\n\n/**\n * One set of completion and hover providers per language, per Monaco.\n *\n * Monaco stacks providers rather than replacing them, so registering twice for\n * a language shows every suggestion twice. Tracking them here means the latest\n * registration wins instead, and a component tree with several editors does not\n * have to coordinate.\n */\nconst providersByLanguage = new WeakMap<Monaco, Map<string, { dispose(): void }[]>>();\n\nfunction replaceProviders(monaco: Monaco, id: string, installed: { dispose(): void }[]) {\n let byLanguage = providersByLanguage.get(monaco);\n if (!byLanguage) {\n byLanguage = new Map();\n providersByLanguage.set(monaco, byLanguage);\n }\n for (const disposable of byLanguage.get(id) ?? []) disposable.dispose();\n if (installed.length === 0) byLanguage.delete(id);\n else byLanguage.set(id, installed);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkFA,SAAgB,0BACd,QACA,UAA2B,CAAC,GACP;CACrB,MAAM,EAAE,YAAY,cAAc,cAAc,MAAM,SAAS,MAAM,SAAS,SAAS;CAEvF,I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M,sCAAsB,IAAI,QAAoD;AAEpF,SAAS,iBAAiB,QAAgB,IAAY,WAAkC;CACtF,IAAI,aAAa,oBAAoB,IAAI,MAAM;CAC/C,IAAI,CAAC,YAAY;EACf,6BAAa,IAAI,IAAI;EACrB,oBAAoB,IAAI,QAAQ,UAAU;CAC5C;CACA,KAAK,MAAM,cAAc,WAAW,IAAI,EAAE,KAAK,CAAC,GAAG,WAAW,QAAQ;CACtE,IAAI,UAAU,WAAW,GAAG,WAAW,OAAO,EAAE;MAC3C,WAAW,IAAI,IAAI,SAAS;AACnC"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/expressions/lang/index.ts"],"sourcesContent":["import { LANGUAGE_IDS, definitions, spec } from \"./generated/index.js\";\nimport type { LanguageId } from \"./generated/index.js\";\nimport { registerCompletion } from \"./completion.js\";\nimport type { EnvironmentSource } from \"./completion.js\";\nimport { registerCelHover, registerGoTemplateHover } from \"./hover.js\";\nimport { pathFlavour } from \"./environment.js\";\nimport { attributesFor } from \"./attributes.js\";\nimport { mergeSpec } from \"./merge.js\";\nimport { defineThemes } from \"./theme.js\";\nimport type { GomplateSpec, LanguageDefinition, Monaco } from \"./types.js\";\n\nexport { spec, LANGUAGE_IDS, definitions };\nexport type { LanguageId };\nexport * from \"./types.js\";\nexport { GOMPLATE_DARK_THEME, GOMPLATE_LIGHT_THEME } from \"./theme.js\";\nexport {\n childEntries,\n isIdentifier,\n kindOf,\n pathExpression,\n pathFlavour,\n resolvePath,\n summarize,\n} from \"./environment.js\";\nexport type { EnvironmentEntry, PathSegment, ValueKind } from \"./environment.js\";\nexport { environmentPrefixAt } from \"./prefix.js\";\nexport type { EnvironmentPrefix } from \"./prefix.js\";\nexport type { EnvironmentSource } from \"./completion.js\";\nexport { mergeSpec } from \"./merge.js\";\nexport { attributesFor, celAttributes, goTemplateAttributes } from \"./attributes.js\";\nexport type { Attributes } from \"./attributes.js\";\n\nexport interface RegisterOptions {\n /** Which languages to register. Defaults to all of them. */\n languages?: readonly LanguageId[];\n /** Register completion providers. Defaults to true. */\n completions?: boolean;\n /** Register hover providers. Defaults to true. */\n hovers?: boolean;\n /** Define the gomplate colour themes. Defaults to true. */\n themes?: boolean;\n /**\n * The document expressions are evaluated against, so completion can offer the\n * key paths it actually contains.\n *\n * A getter rather than a value: registration happens once, before the first\n * editor mounts, while the document keeps being edited afterwards. It is\n * called on every completion request.\n */\n environment?: EnvironmentSource;\n /**\n * A host's own catalogue, merged over gomplate's.\n *\n * Usually left unset here and supplied later through `setSpec`, because it\n * arrives from the host's `GET /api/spec` after the editor has mounted.\n */\n spec?: GomplateSpec;\n}\n\n/** What `registerGomplateLanguages` hands back. */\nexport interface RegisteredLanguages {\n /**\n * Replaces the catalogue and re-applies it.\n *\n * Registration has to happen in `beforeMount`, before the first model exists,\n * while a host's spec arrives over the network afterwards — so gating\n * registration on the fetch would stall the editor. Register with the baked\n * catalogue instead and call this when the response lands: the tokenizers are\n * re-applied with the merged word lists, and completion and hover are\n * re-registered against the merged functions.\n */\n setSpec(spec: GomplateSpec | undefined): void;\n dispose(): void;\n}\n\n/**\n * Registers gomplate's languages with a Monaco instance.\n *\n * Safe to call more than once: a language already registered is left alone, so\n * a component tree with several editors does not need to coordinate. The\n * returned handle removes only the providers this call added.\n */\nexport function registerGomplateLanguages(\n monaco: Monaco,\n options: RegisterOptions = {},\n): RegisteredLanguages {\n const { languages = LANGUAGE_IDS, completions = true, hovers = true, themes = true } = options;\n\n if (themes) defineThemes(monaco);\n\n const known = new Set(monaco.languages.getLanguages().map((l) => l.id));\n const selected: LanguageId[] = [];\n\n for (const id of languages) {\n const definition: LanguageDefinition | undefined = definitions[id];\n if (!definition) {\n throw new Error(\n `unknown gomplate language \"${id}\"; expected one of ${LANGUAGE_IDS.join(\", \")}`,\n );\n }\n selected.push(id);\n\n // Only the registration itself is once-only. The tokenizer and the\n // providers are re-applied below for every selected language, whether or\n // not this call is the one that introduced it -- otherwise a second editor\n // would get a handle whose setSpec silently does nothing.\n if (known.has(id)) continue;\n monaco.languages.register({ id });\n monaco.languages.setLanguageConfiguration(id, definition.configuration);\n }\n\n const applySpec = (merged: GomplateSpec) => {\n for (const id of selected) {\n const definition = definitions[id]!;\n const attributes = attributesFor(id, merged);\n // Spread over the generated definition rather than replacing it: the\n // tokenizer rules and the grammar-derived lists (CEL's `operators`) are\n // not the spec's to change.\n monaco.languages.setMonarchTokensProvider(\n id,\n attributes ? { ...definition.monarch, ...attributes } : definition.monarch,\n );\n\n const flavour = pathFlavour(id);\n const installed: { dispose(): void }[] = [];\n if (completions) {\n installed.push(\n registerCompletion(monaco, id, { spec: merged, environment: options.environment }),\n );\n }\n if (hovers && flavour === \"cel\") installed.push(registerCelHover(monaco, id, merged));\n if (hovers && flavour === \"gotemplate\") {\n installed.push(registerGoTemplateHover(monaco, id, merged));\n }\n replaceProviders(monaco, id, installed);\n }\n };\n\n applySpec(mergeSpec(spec, options.spec));\n\n return {\n setSpec(next) {\n applySpec(mergeSpec(spec, next));\n },\n dispose() {\n for (const id of selected) replaceProviders(monaco, id, []);\n },\n };\n}\n\n/**\n * One set of completion and hover providers per language, per Monaco.\n *\n * Monaco stacks providers rather than replacing them, so registering twice for\n * a language shows every suggestion twice. Tracking them here means the latest\n * registration wins instead, and a component tree with several editors does not\n * have to coordinate.\n */\nconst providersByLanguage = new WeakMap<Monaco, Map<string, { dispose(): void }[]>>();\n\nfunction replaceProviders(monaco: Monaco, id: string, installed: { dispose(): void }[]) {\n let byLanguage = providersByLanguage.get(monaco);\n if (!byLanguage) {\n byLanguage = new Map();\n providersByLanguage.set(monaco, byLanguage);\n }\n for (const disposable of byLanguage.get(id) ?? []) disposable.dispose();\n if (installed.length === 0) byLanguage.delete(id);\n else byLanguage.set(id, installed);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkFA,SAAgB,0BACd,QACA,UAA2B,CAAC,GACP;CACrB,MAAM,EAAE,YAAY,cAAc,cAAc,MAAM,SAAS,MAAM,SAAS,SAAS;CAEvF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AAM,sCAAsB,IAAI,QAAoD;AAEpF,SAAS,iBAAiB,QAAgB,IAAY,WAAkC;CACtF,IAAI,aAAa,oBAAoB,IAAI,MAAM;CAC/C,IAAI,CAAC,YAAY;EACf,6BAAa,IAAI,IAAI;EACrB,oBAAoB,IAAI,QAAQ,UAAU;CAC5C;CACA,KAAK,MAAM,cAAc,WAAW,IAAI,EAAE,KAAK,CAAC,GAAG,WAAW,QAAQ;CACtE,IAAI,UAAU,WAAW,GAAG,WAAW,OAAO,EAAE;MAC3C,WAAW,IAAI,IAAI,SAAS;AACnC"}
|
|
@@ -7,9 +7,14 @@
|
|
|
7
7
|
* That response already *contains* gomplate's own functions, so merging is
|
|
8
8
|
* mostly a union; the interesting case is a host that overrides a name, where
|
|
9
9
|
* the host wins because its binary is what will actually evaluate.
|
|
10
|
+
*
|
|
11
|
+
* A `complete` catalogue (catalog.Build) is the host's whole surface and
|
|
12
|
+
* replaces the base outright: a union could never drop a packaged function the
|
|
13
|
+
* host does not register, such as an opt-in group it leaves disabled.
|
|
10
14
|
*/
|
|
11
15
|
function mergeSpec(base, incoming) {
|
|
12
16
|
if (!incoming) return base;
|
|
17
|
+
if (incoming.complete) return incoming;
|
|
13
18
|
return {
|
|
14
19
|
cel: mergeCel(base.cel, incoming.cel),
|
|
15
20
|
gotemplate: mergeGoTemplate(base.gotemplate, incoming.gotemplate)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge.cjs","names":[],"sources":["../../../src/expressions/lang/merge.ts"],"sourcesContent":["import type { CelSpec, GoTemplateSpec, GomplateSpec, SpecFunction, SpecMacro } from \"./types\";\n\n/**\n * Folds a host's catalogue into the one this package ships.\n *\n * A host binary registers functions on top of gomplate's — mission-control's\n * `catalog.query`, `gitops.source` — and serves the result from `/api/spec`.\n * That response already *contains* gomplate's own functions, so merging is\n * mostly a union; the interesting case is a host that overrides a name, where\n * the host wins because its binary is what will actually evaluate.\n */\nexport function mergeSpec(base: GomplateSpec, incoming: GomplateSpec | undefined): GomplateSpec {\n if (!incoming) return base;\n return {\n cel: mergeCel(base.cel, incoming.cel),\n gotemplate: mergeGoTemplate(base.gotemplate, incoming.gotemplate),\n };\n}\n\nfunction mergeCel(base: CelSpec, incoming: CelSpec): CelSpec {\n return {\n namespaces: union(base.namespaces, incoming.namespaces),\n keywords: union(base.keywords, incoming.keywords),\n types: union(base.types, incoming.types),\n variables: union(base.variables ?? [], incoming.variables ?? []),\n // Keyed by arity as well as name: `map` is registered twice, at 2 and 3\n // arguments, and folding those together would drop an overload the hover\n // list already renders separately.\n macros: keyed<SpecMacro>(\n base.macros,\n incoming.macros,\n (macro) => `${macro.name}/${macro.argCount}/${macro.receiverStyle}`,\n ),\n functions: byName<SpecFunction>(base.functions, incoming.functions),\n };\n}\n\nfunction mergeGoTemplate(base: GoTemplateSpec, incoming: GoTemplateSpec): GoTemplateSpec {\n return {\n namespaces: union(base.namespaces, incoming.namespaces),\n keywords: union(base.keywords, incoming.keywords),\n builtins: union(base.builtins, incoming.builtins),\n // Delimiters are a property of the binary's parser, not a list to merge:\n // a host that has changed them means it, and half of a pair would be worse\n // than either.\n delimiters: incoming.delimiters ?? base.delimiters,\n functions: byName<SpecFunction>(base.functions, incoming.functions),\n };\n}\n\nfunction union(base: readonly string[], incoming: readonly string[]): string[] {\n return [...new Set([...base, ...incoming])].sort();\n}\n\n/** Keyed by name, incoming wins, order stable and alphabetical. */\nfunction byName<T extends { name: string }>(base: readonly T[], incoming: readonly T[]): T[] {\n return keyed(base, incoming, (item) => item.name);\n}\n\nfunction keyed<T extends { name: string }>(\n base: readonly T[],\n incoming: readonly T[],\n key: (item: T) => string,\n): T[] {\n const merged = new Map<string, T>();\n for (const item of base) merged.set(key(item), item);\n for (const item of incoming) merged.set(key(item), item);\n return [...merged.values()].sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"merge.cjs","names":[],"sources":["../../../src/expressions/lang/merge.ts"],"sourcesContent":["import type { CelSpec, GoTemplateSpec, GomplateSpec, SpecFunction, SpecMacro } from \"./types.js\";\n\n/**\n * Folds a host's catalogue into the one this package ships.\n *\n * A host binary registers functions on top of gomplate's — mission-control's\n * `catalog.query`, `gitops.source` — and serves the result from `/api/spec`.\n * That response already *contains* gomplate's own functions, so merging is\n * mostly a union; the interesting case is a host that overrides a name, where\n * the host wins because its binary is what will actually evaluate.\n *\n * A `complete` catalogue (catalog.Build) is the host's whole surface and\n * replaces the base outright: a union could never drop a packaged function the\n * host does not register, such as an opt-in group it leaves disabled.\n */\nexport function mergeSpec(base: GomplateSpec, incoming: GomplateSpec | undefined): GomplateSpec {\n if (!incoming) return base;\n if (incoming.complete) return incoming;\n return {\n cel: mergeCel(base.cel, incoming.cel),\n gotemplate: mergeGoTemplate(base.gotemplate, incoming.gotemplate),\n };\n}\n\nfunction mergeCel(base: CelSpec, incoming: CelSpec): CelSpec {\n return {\n namespaces: union(base.namespaces, incoming.namespaces),\n keywords: union(base.keywords, incoming.keywords),\n types: union(base.types, incoming.types),\n variables: union(base.variables ?? [], incoming.variables ?? []),\n // Keyed by arity as well as name: `map` is registered twice, at 2 and 3\n // arguments, and folding those together would drop an overload the hover\n // list already renders separately.\n macros: keyed<SpecMacro>(\n base.macros,\n incoming.macros,\n (macro) => `${macro.name}/${macro.argCount}/${macro.receiverStyle}`,\n ),\n functions: byName<SpecFunction>(base.functions, incoming.functions),\n };\n}\n\nfunction mergeGoTemplate(base: GoTemplateSpec, incoming: GoTemplateSpec): GoTemplateSpec {\n return {\n namespaces: union(base.namespaces, incoming.namespaces),\n keywords: union(base.keywords, incoming.keywords),\n builtins: union(base.builtins, incoming.builtins),\n // Delimiters are a property of the binary's parser, not a list to merge:\n // a host that has changed them means it, and half of a pair would be worse\n // than either.\n delimiters: incoming.delimiters ?? base.delimiters,\n functions: byName<SpecFunction>(base.functions, incoming.functions),\n };\n}\n\nfunction union(base: readonly string[], incoming: readonly string[]): string[] {\n return [...new Set([...base, ...incoming])].sort();\n}\n\n/** Keyed by name, incoming wins, order stable and alphabetical. */\nfunction byName<T extends { name: string }>(base: readonly T[], incoming: readonly T[]): T[] {\n return keyed(base, incoming, (item) => item.name);\n}\n\nfunction keyed<T extends { name: string }>(\n base: readonly T[],\n incoming: readonly T[],\n key: (item: T) => string,\n): T[] {\n const merged = new Map<string, T>();\n for (const item of base) merged.set(key(item), item);\n for (const item of incoming) merged.set(key(item), item);\n return [...merged.values()].sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));\n}\n"],"mappings":";;;;;;;;;;;;;;AAeA,SAAgB,UAAU,MAAoB,UAAkD;CAC9F,IAAI,CAAC,UAAU,OAAO;CACtB,IAAI,SAAS,UAAU,OAAO;CAC9B,OAAO;EACL,KAAK,SAAS,KAAK,KAAK,SAAS,GAAG;EACpC,YAAY,gBAAgB,KAAK,YAAY,SAAS,UAAU;CAClE;AACF;AAEA,SAAS,SAAS,MAAe,UAA4B;CAC3D,OAAO;EACL,YAAY,MAAM,KAAK,YAAY,SAAS,UAAU;EACtD,UAAU,MAAM,KAAK,UAAU,SAAS,QAAQ;EAChD,OAAO,MAAM,KAAK,OAAO,SAAS,KAAK;EACvC,WAAW,MAAM,KAAK,aAAa,CAAC,GAAG,SAAS,aAAa,CAAC,CAAC;EAI/D,QAAQ,MACN,KAAK,QACL,SAAS,SACR,UAAU,GAAG,MAAM,KAAK,GAAG,MAAM,SAAS,GAAG,MAAM,eACtD;EACA,WAAW,OAAqB,KAAK,WAAW,SAAS,SAAS;CACpE;AACF;AAEA,SAAS,gBAAgB,MAAsB,UAA0C;CACvF,OAAO;EACL,YAAY,MAAM,KAAK,YAAY,SAAS,UAAU;EACtD,UAAU,MAAM,KAAK,UAAU,SAAS,QAAQ;EAChD,UAAU,MAAM,KAAK,UAAU,SAAS,QAAQ;EAIhD,YAAY,SAAS,cAAc,KAAK;EACxC,WAAW,OAAqB,KAAK,WAAW,SAAS,SAAS;CACpE;AACF;AAEA,SAAS,MAAM,MAAyB,UAAuC;CAC7E,OAAO,CAAC,mBAAG,IAAI,IAAI,CAAC,GAAG,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK;AACnD;;AAGA,SAAS,OAAmC,MAAoB,UAA6B;CAC3F,OAAO,MAAM,MAAM,WAAW,SAAS,KAAK,IAAI;AAClD;AAEA,SAAS,MACP,MACA,UACA,KACK;CACL,MAAM,yBAAS,IAAI,IAAe;CAClC,KAAK,MAAM,QAAQ,MAAM,OAAO,IAAI,IAAI,IAAI,GAAG,IAAI;CACnD,KAAK,MAAM,QAAQ,UAAU,OAAO,IAAI,IAAI,IAAI,GAAG,IAAI;CACvD,OAAO,CAAC,GAAG,OAAO,OAAO,CAAC,CAAC,CAAC,MAAM,GAAG,MAAO,EAAE,OAAO,EAAE,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,IAAI,CAAE;AAC7F"}
|
|
@@ -7,6 +7,10 @@ import { GomplateSpec } from './types.js';
|
|
|
7
7
|
* That response already *contains* gomplate's own functions, so merging is
|
|
8
8
|
* mostly a union; the interesting case is a host that overrides a name, where
|
|
9
9
|
* the host wins because its binary is what will actually evaluate.
|
|
10
|
+
*
|
|
11
|
+
* A `complete` catalogue (catalog.Build) is the host's whole surface and
|
|
12
|
+
* replaces the base outright: a union could never drop a packaged function the
|
|
13
|
+
* host does not register, such as an opt-in group it leaves disabled.
|
|
10
14
|
*/
|
|
11
15
|
export declare function mergeSpec(base: GomplateSpec, incoming: GomplateSpec | undefined): GomplateSpec;
|
|
12
16
|
//# sourceMappingURL=merge.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../../src/expressions/lang/merge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA2B,YAAY,EAA2B,MAAM,
|
|
1
|
+
{"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../../src/expressions/lang/merge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA2B,YAAY,EAA2B,MAAM,YAAY,CAAC;AAEjG;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,YAAY,GAAG,SAAS,GAAG,YAAY,CAO9F"}
|
|
@@ -7,9 +7,14 @@
|
|
|
7
7
|
* That response already *contains* gomplate's own functions, so merging is
|
|
8
8
|
* mostly a union; the interesting case is a host that overrides a name, where
|
|
9
9
|
* the host wins because its binary is what will actually evaluate.
|
|
10
|
+
*
|
|
11
|
+
* A `complete` catalogue (catalog.Build) is the host's whole surface and
|
|
12
|
+
* replaces the base outright: a union could never drop a packaged function the
|
|
13
|
+
* host does not register, such as an opt-in group it leaves disabled.
|
|
10
14
|
*/
|
|
11
15
|
function mergeSpec(base, incoming) {
|
|
12
16
|
if (!incoming) return base;
|
|
17
|
+
if (incoming.complete) return incoming;
|
|
13
18
|
return {
|
|
14
19
|
cel: mergeCel(base.cel, incoming.cel),
|
|
15
20
|
gotemplate: mergeGoTemplate(base.gotemplate, incoming.gotemplate)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge.js","names":[],"sources":["../../../src/expressions/lang/merge.ts"],"sourcesContent":["import type { CelSpec, GoTemplateSpec, GomplateSpec, SpecFunction, SpecMacro } from \"./types\";\n\n/**\n * Folds a host's catalogue into the one this package ships.\n *\n * A host binary registers functions on top of gomplate's — mission-control's\n * `catalog.query`, `gitops.source` — and serves the result from `/api/spec`.\n * That response already *contains* gomplate's own functions, so merging is\n * mostly a union; the interesting case is a host that overrides a name, where\n * the host wins because its binary is what will actually evaluate.\n */\nexport function mergeSpec(base: GomplateSpec, incoming: GomplateSpec | undefined): GomplateSpec {\n if (!incoming) return base;\n return {\n cel: mergeCel(base.cel, incoming.cel),\n gotemplate: mergeGoTemplate(base.gotemplate, incoming.gotemplate),\n };\n}\n\nfunction mergeCel(base: CelSpec, incoming: CelSpec): CelSpec {\n return {\n namespaces: union(base.namespaces, incoming.namespaces),\n keywords: union(base.keywords, incoming.keywords),\n types: union(base.types, incoming.types),\n variables: union(base.variables ?? [], incoming.variables ?? []),\n // Keyed by arity as well as name: `map` is registered twice, at 2 and 3\n // arguments, and folding those together would drop an overload the hover\n // list already renders separately.\n macros: keyed<SpecMacro>(\n base.macros,\n incoming.macros,\n (macro) => `${macro.name}/${macro.argCount}/${macro.receiverStyle}`,\n ),\n functions: byName<SpecFunction>(base.functions, incoming.functions),\n };\n}\n\nfunction mergeGoTemplate(base: GoTemplateSpec, incoming: GoTemplateSpec): GoTemplateSpec {\n return {\n namespaces: union(base.namespaces, incoming.namespaces),\n keywords: union(base.keywords, incoming.keywords),\n builtins: union(base.builtins, incoming.builtins),\n // Delimiters are a property of the binary's parser, not a list to merge:\n // a host that has changed them means it, and half of a pair would be worse\n // than either.\n delimiters: incoming.delimiters ?? base.delimiters,\n functions: byName<SpecFunction>(base.functions, incoming.functions),\n };\n}\n\nfunction union(base: readonly string[], incoming: readonly string[]): string[] {\n return [...new Set([...base, ...incoming])].sort();\n}\n\n/** Keyed by name, incoming wins, order stable and alphabetical. */\nfunction byName<T extends { name: string }>(base: readonly T[], incoming: readonly T[]): T[] {\n return keyed(base, incoming, (item) => item.name);\n}\n\nfunction keyed<T extends { name: string }>(\n base: readonly T[],\n incoming: readonly T[],\n key: (item: T) => string,\n): T[] {\n const merged = new Map<string, T>();\n for (const item of base) merged.set(key(item), item);\n for (const item of incoming) merged.set(key(item), item);\n return [...merged.values()].sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"merge.js","names":[],"sources":["../../../src/expressions/lang/merge.ts"],"sourcesContent":["import type { CelSpec, GoTemplateSpec, GomplateSpec, SpecFunction, SpecMacro } from \"./types.js\";\n\n/**\n * Folds a host's catalogue into the one this package ships.\n *\n * A host binary registers functions on top of gomplate's — mission-control's\n * `catalog.query`, `gitops.source` — and serves the result from `/api/spec`.\n * That response already *contains* gomplate's own functions, so merging is\n * mostly a union; the interesting case is a host that overrides a name, where\n * the host wins because its binary is what will actually evaluate.\n *\n * A `complete` catalogue (catalog.Build) is the host's whole surface and\n * replaces the base outright: a union could never drop a packaged function the\n * host does not register, such as an opt-in group it leaves disabled.\n */\nexport function mergeSpec(base: GomplateSpec, incoming: GomplateSpec | undefined): GomplateSpec {\n if (!incoming) return base;\n if (incoming.complete) return incoming;\n return {\n cel: mergeCel(base.cel, incoming.cel),\n gotemplate: mergeGoTemplate(base.gotemplate, incoming.gotemplate),\n };\n}\n\nfunction mergeCel(base: CelSpec, incoming: CelSpec): CelSpec {\n return {\n namespaces: union(base.namespaces, incoming.namespaces),\n keywords: union(base.keywords, incoming.keywords),\n types: union(base.types, incoming.types),\n variables: union(base.variables ?? [], incoming.variables ?? []),\n // Keyed by arity as well as name: `map` is registered twice, at 2 and 3\n // arguments, and folding those together would drop an overload the hover\n // list already renders separately.\n macros: keyed<SpecMacro>(\n base.macros,\n incoming.macros,\n (macro) => `${macro.name}/${macro.argCount}/${macro.receiverStyle}`,\n ),\n functions: byName<SpecFunction>(base.functions, incoming.functions),\n };\n}\n\nfunction mergeGoTemplate(base: GoTemplateSpec, incoming: GoTemplateSpec): GoTemplateSpec {\n return {\n namespaces: union(base.namespaces, incoming.namespaces),\n keywords: union(base.keywords, incoming.keywords),\n builtins: union(base.builtins, incoming.builtins),\n // Delimiters are a property of the binary's parser, not a list to merge:\n // a host that has changed them means it, and half of a pair would be worse\n // than either.\n delimiters: incoming.delimiters ?? base.delimiters,\n functions: byName<SpecFunction>(base.functions, incoming.functions),\n };\n}\n\nfunction union(base: readonly string[], incoming: readonly string[]): string[] {\n return [...new Set([...base, ...incoming])].sort();\n}\n\n/** Keyed by name, incoming wins, order stable and alphabetical. */\nfunction byName<T extends { name: string }>(base: readonly T[], incoming: readonly T[]): T[] {\n return keyed(base, incoming, (item) => item.name);\n}\n\nfunction keyed<T extends { name: string }>(\n base: readonly T[],\n incoming: readonly T[],\n key: (item: T) => string,\n): T[] {\n const merged = new Map<string, T>();\n for (const item of base) merged.set(key(item), item);\n for (const item of incoming) merged.set(key(item), item);\n return [...merged.values()].sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));\n}\n"],"mappings":";;;;;;;;;;;;;;AAeA,SAAgB,UAAU,MAAoB,UAAkD;CAC9F,IAAI,CAAC,UAAU,OAAO;CACtB,IAAI,SAAS,UAAU,OAAO;CAC9B,OAAO;EACL,KAAK,SAAS,KAAK,KAAK,SAAS,GAAG;EACpC,YAAY,gBAAgB,KAAK,YAAY,SAAS,UAAU;CAClE;AACF;AAEA,SAAS,SAAS,MAAe,UAA4B;CAC3D,OAAO;EACL,YAAY,MAAM,KAAK,YAAY,SAAS,UAAU;EACtD,UAAU,MAAM,KAAK,UAAU,SAAS,QAAQ;EAChD,OAAO,MAAM,KAAK,OAAO,SAAS,KAAK;EACvC,WAAW,MAAM,KAAK,aAAa,CAAC,GAAG,SAAS,aAAa,CAAC,CAAC;EAI/D,QAAQ,MACN,KAAK,QACL,SAAS,SACR,UAAU,GAAG,MAAM,KAAK,GAAG,MAAM,SAAS,GAAG,MAAM,eACtD;EACA,WAAW,OAAqB,KAAK,WAAW,SAAS,SAAS;CACpE;AACF;AAEA,SAAS,gBAAgB,MAAsB,UAA0C;CACvF,OAAO;EACL,YAAY,MAAM,KAAK,YAAY,SAAS,UAAU;EACtD,UAAU,MAAM,KAAK,UAAU,SAAS,QAAQ;EAChD,UAAU,MAAM,KAAK,UAAU,SAAS,QAAQ;EAIhD,YAAY,SAAS,cAAc,KAAK;EACxC,WAAW,OAAqB,KAAK,WAAW,SAAS,SAAS;CACpE;AACF;AAEA,SAAS,MAAM,MAAyB,UAAuC;CAC7E,OAAO,CAAC,mBAAG,IAAI,IAAI,CAAC,GAAG,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK;AACnD;;AAGA,SAAS,OAAmC,MAAoB,UAA6B;CAC3F,OAAO,MA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