@shortlink-org/portolan 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -0
- package/catalog/enum_test.go +46 -0
- package/catalog/evidence_test.go +35 -0
- package/catalog/model.go +1066 -0
- package/catalog/roundtrip_test.go +203 -0
- package/catalog/via_test.go +38 -0
- package/cli/init.test.mjs +6 -1
- package/cli/portolan.mjs +8 -0
- package/cli/portolan.test.mjs +49 -0
- package/go.mod +14 -0
- package/go.sum +20 -0
- package/internal/gocall/README.md +19 -0
- package/internal/gocall/analyze.go +189 -0
- package/internal/gocall/analyze_test.go +107 -0
- package/internal/gohttp/analyze.go +2562 -0
- package/internal/gohttp/destination.go +373 -0
- package/internal/gohttp/endpoints.go +1067 -0
- package/internal/gohttp/roots.go +320 -0
- package/internal/gohttp/typed.go +96 -0
- package/internal/goscan/constants.go +85 -0
- package/internal/goscan/goscan_test.go +227 -0
- package/internal/goscan/index.go +629 -0
- package/internal/goscan/index_test.go +66 -0
- package/internal/goscan/names.go +52 -0
- package/internal/goscan/parse_test.go +11 -0
- package/internal/goscan/source.go +37 -0
- package/internal/goscan/tree.go +284 -0
- package/internal/goscan/types.go +99 -0
- package/internal/wsdl/ids.go +127 -0
- package/internal/wsdl/ids_test.go +21 -0
- package/internal/wsdl/model.go +70 -0
- package/internal/wsdl/parse.go +949 -0
- package/internal/wsdl/parse_test.go +170 -0
- package/package.json +22 -10
- package/plugin/describe.go +118 -0
- package/plugin/describe_test.go +114 -0
- package/plugin/protocol.go +141 -0
- package/plugin/schematest/schematest.go +126 -0
- package/plugins/README.md +114 -46
- package/plugins/cmd/portolan-http-clients/main.go +19 -0
- package/plugins/extract-celery/extract.py +0 -2
- package/plugins/extract-celery/extract_test.py +1 -1
- package/plugins/extract-django/README.md +39 -17
- package/plugins/extract-django/domain.py +28 -17
- package/plugins/extract-django/extract.py +21 -7
- package/plugins/extract-django/extract_test.py +55 -2
- package/plugins/extract-django/lifecycle.py +2 -0
- package/plugins/extract-django/operations.py +1 -1
- package/plugins/extract-django/routing_test.py +109 -1
- package/plugins/extract-django/store.py +1 -1
- package/plugins/extract-django/transport.py +101 -55
- package/plugins/extract-django/verbs.py +241 -0
- package/plugins/extract-go/README.md +47 -0
- package/plugins/extract-http-clients/describe.go +19 -0
- package/plugins/extract-http-clients/describe_test.go +11 -0
- package/plugins/extract-http-clients/extract.go +740 -0
- package/plugins/extract-http-clients/extract_test.go +1561 -0
- package/plugins/extract-http-clients/main.go +41 -0
- package/plugins/extract-java/build/org/portolan/extract/Extract.class +0 -0
- package/plugins/extract-java/build/org/portolan/extract/Protocol$Builder.class +0 -0
- package/plugins/extract-java/build/org/portolan/extract/Protocol$Input.class +0 -0
- package/plugins/extract-java/build/org/portolan/extract/Protocol$Options.class +0 -0
- package/plugins/extract-python-kafka/README.md +6 -0
- package/plugins/extract-python-kafka/extract.py +2 -4
- package/plugins/extract-python-kafka/extract_test.py +18 -2
- package/plugins/extract-ts/extract.test.ts +2 -2
- package/plugins/extract-ts/extract.ts +4 -5
- package/plugins/extract-ts/graphql.test.ts +1 -1
- package/plugins/openapi/ids.go +261 -0
- package/plugins/openapi/ids_test.go +98 -0
- package/plugins/portolan-go.wasm +0 -0
- package/plugins/pyplugin/catalog.py +12 -1
- package/plugins/pyplugin/kafka.py +74 -3
- package/plugins/pyplugin/protocol.py +1 -5
- package/portolan.json +3 -2
- package/schema/portolan.schema.json +34 -0
- package/scripts/README.md +18 -12
- package/scripts/catalog-sources.mjs +6 -0
- package/scripts/delivery-presets.mjs +21 -11
- package/scripts/diff.mjs +5 -1
- package/scripts/django-aggregates.test.mjs +58 -0
- package/scripts/gen-likec4.mjs +79 -21
- package/scripts/gen-likec4.test.mjs +25 -2
- package/scripts/gen.mjs +118 -115
- package/scripts/go-discovery.test.mjs +30 -0
- package/scripts/history.mjs +186 -3
- package/scripts/history.test.mjs +1 -1
- package/scripts/host-plugins/fetch-git.mjs +77 -21
- package/scripts/host-plugins/fetch-git.test.mjs +62 -8
- package/scripts/local-api.mjs +71 -4
- package/scripts/local-api.test.mjs +63 -4
- package/scripts/local-discovery.mjs +82 -9
- package/scripts/manifest.mjs +5 -3
- package/scripts/manifest.test.mjs +24 -0
- package/scripts/output-diff.mjs +94 -0
- package/scripts/output-diff.test.mjs +36 -0
- package/scripts/package-smoke.mjs +62 -4
- package/scripts/plugin-host.mjs +22 -2
- package/scripts/plugin-host.test.mjs +9 -0
- package/scripts/plugin-wasm-worker.mjs +4 -1
- package/scripts/provenance.mjs +72 -0
- package/scripts/provenance.test.mjs +149 -0
- package/scripts/run-builtin.mjs +39 -5
- package/scripts/schema.mjs +29 -0
- package/scripts/warning-policy.mjs +161 -0
- package/scripts/warning-policy.test.mjs +56 -0
- package/src/app/Breadcrumbs.test.ts +4 -0
- package/src/app/Breadcrumbs.tsx +1 -0
- package/src/app/Sidebar.tsx +3 -3
- package/src/catalog-docs.test.ts +64 -0
- package/src/catalog-docs.ts +35 -0
- package/src/catalog-error.test.ts +15 -0
- package/src/catalog-model.ts +70 -6
- package/src/catalog-stores.test.ts +17 -0
- package/src/catalog-validation.ts +52 -2
- package/src/catalog.test.ts +13 -2
- package/src/chat/Starter.tsx +5 -11
- package/src/chat/tools.test.ts +27 -0
- package/src/chat/tools.ts +5 -9
- package/src/components/CatalogStamp.tsx +10 -8
- package/src/components/ChannelRows.messagepack.test.tsx +28 -0
- package/src/components/ChannelRows.test.tsx +54 -0
- package/src/components/ChannelRows.tsx +57 -10
- package/src/components/HTTPDestinationEvidence.test.tsx +23 -0
- package/src/components/HTTPDestinationEvidence.tsx +31 -0
- package/src/components/Integrations.tsx +1 -1
- package/src/components/LifecycleDiagram.tsx +28 -12
- package/src/components/MachineDocs.tsx +6 -5
- package/src/components/MethodRows.tsx +9 -2
- package/src/components/ProblemRow.tsx +4 -0
- package/src/components/RelationEvidence.test.tsx +14 -0
- package/src/components/RelationEvidence.tsx +53 -0
- package/src/components/WhatLinksHere.tsx +6 -4
- package/src/data.ts +25 -7
- package/src/enrich.test.ts +336 -6
- package/src/enrich.ts +206 -3
- package/src/flow/StepDetail.tsx +104 -54
- package/src/flow/answers.test.ts +18 -1
- package/src/flow/answers.ts +37 -8
- package/src/flow/evidence.test.ts +16 -0
- package/src/flow/evidence.ts +34 -0
- package/src/index.css +44 -0
- package/src/landing/DraggableReveal.tsx +3 -2
- package/src/landing/EvidencePipeline.tsx +105 -0
- package/src/landing/LandingPage.tsx +2 -59
- package/src/lib/backlinks.test.ts +16 -1
- package/src/lib/backlinks.ts +20 -0
- package/src/lib/catalog-diff.test.ts +18 -0
- package/src/lib/catalog-diff.ts +20 -2
- package/src/lib/derive.ts +1 -0
- package/src/lib/django-aggregates.d.mts +9 -0
- package/src/lib/django-aggregates.mjs +36 -0
- package/src/lib/django-aggregates.test.ts +29 -0
- package/src/lib/django-aggregates.ts +5 -0
- package/src/lib/kafka-ui.test.ts +87 -0
- package/src/lib/kafka-ui.ts +105 -0
- package/src/lib/local-api.ts +20 -2
- package/src/lib/setup-info.test.ts +17 -0
- package/src/lib/setup-info.ts +58 -0
- package/src/lib/warnings.test.ts +54 -0
- package/src/lib/warnings.ts +260 -0
- package/src/lib/wire-problems.test.ts +21 -0
- package/src/lib/wire-problems.ts +62 -1
- package/src/likec4/FlowView.tsx +2 -6
- package/src/likec4/flow-edges.test.ts +64 -1
- package/src/likec4/flow-edges.ts +43 -7
- package/src/likec4/view-index.ts +8 -2
- package/src/map/ContextMapGraph.tsx +76 -32
- package/src/merge.test.ts +23 -0
- package/src/merge.ts +33 -10
- package/src/pages/AggregatePage.tsx +8 -7
- package/src/pages/CatalogFailure.tsx +2 -2
- package/src/pages/ContextPage.tsx +6 -5
- package/src/pages/ServicePage.tsx +4 -3
- package/src/pages/Settings.tsx +200 -44
- package/src/pages/settings/DjangoAggregateChoices.tsx +79 -0
- package/src/pages/settings/IntegrationsSettings.tsx +117 -0
- package/src/routes.test.ts +2 -0
- package/src/routes.ts +2 -1
- package/src/selection/DetailPanel.tsx +61 -1
- package/src/virtual-provenance.d.ts +11 -0
- package/vite.config.ts +5 -0
- package/scripts/vendor-lock.mjs +0 -58
- package/scripts/vendor-lock.test.mjs +0 -69
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
package wsdl
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"os"
|
|
5
|
+
"path/filepath"
|
|
6
|
+
"strings"
|
|
7
|
+
"testing"
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
func writeFixture(t *testing.T, root, name, contents string) {
|
|
11
|
+
t.Helper()
|
|
12
|
+
path := filepath.Join(root, name)
|
|
13
|
+
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
|
14
|
+
t.Fatal(err)
|
|
15
|
+
}
|
|
16
|
+
if err := os.WriteFile(path, []byte(contents), 0o644); err != nil {
|
|
17
|
+
t.Fatal(err)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
func TestReadJoinsImportedPortTypeBindingAndSchema(t *testing.T) {
|
|
22
|
+
root := t.TempDir()
|
|
23
|
+
writeFixture(t, root, "types.xsd", `
|
|
24
|
+
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:booking" xmlns:tns="urn:booking">
|
|
25
|
+
<xsd:complexType name="CancelRequestType">
|
|
26
|
+
<xsd:sequence>
|
|
27
|
+
<xsd:element name="bookingId" type="xsd:string"/>
|
|
28
|
+
<xsd:element name="passengerIds" type="xsd:string" maxOccurs="unbounded"/>
|
|
29
|
+
</xsd:sequence>
|
|
30
|
+
</xsd:complexType>
|
|
31
|
+
<xsd:element name="CancelRequest" type="tns:CancelRequestType"/>
|
|
32
|
+
<xsd:element name="CancelResponse">
|
|
33
|
+
<xsd:complexType><xsd:sequence><xsd:element name="accepted" type="xsd:boolean"/></xsd:sequence></xsd:complexType>
|
|
34
|
+
</xsd:element>
|
|
35
|
+
</xsd:schema>`)
|
|
36
|
+
writeFixture(t, root, "contract.wsdl", `
|
|
37
|
+
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="urn:booking" targetNamespace="urn:booking">
|
|
38
|
+
<wsdl:types><xsd:schema targetNamespace="urn:booking"><xsd:import namespace="urn:booking" schemaLocation="types.xsd"/></xsd:schema></wsdl:types>
|
|
39
|
+
<wsdl:message name="CancelRequestMessage"><wsdl:part name="body" element="tns:CancelRequest"/></wsdl:message>
|
|
40
|
+
<wsdl:message name="CancelResponseMessage"><wsdl:part name="body" element="tns:CancelResponse"/></wsdl:message>
|
|
41
|
+
<wsdl:message name="BookingFault"><wsdl:part name="reason" type="xsd:string"/></wsdl:message>
|
|
42
|
+
<wsdl:portType name="BookingPortType">
|
|
43
|
+
<wsdl:operation name="CancelBooking">
|
|
44
|
+
<wsdl:documentation>Cancels a booking.</wsdl:documentation>
|
|
45
|
+
<wsdl:input message="tns:CancelRequestMessage"/>
|
|
46
|
+
<wsdl:output message="tns:CancelResponseMessage"/>
|
|
47
|
+
<wsdl:fault name="BookingFault" message="tns:BookingFault"/>
|
|
48
|
+
</wsdl:operation>
|
|
49
|
+
</wsdl:portType>
|
|
50
|
+
</wsdl:definitions>`)
|
|
51
|
+
writeFixture(t, root, "service.wsdl", `
|
|
52
|
+
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:tns="urn:booking" targetNamespace="urn:booking" name="BookingDefinitions">
|
|
53
|
+
<wsdl:import namespace="urn:booking" location="contract.wsdl"/>
|
|
54
|
+
<wsdl:binding name="BookingBinding" type="tns:BookingPortType">
|
|
55
|
+
<soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
|
|
56
|
+
<wsdl:operation name="CancelBooking">
|
|
57
|
+
<soap12:operation soapAction="urn:booking:cancel"/>
|
|
58
|
+
<wsdl:input><soap12:body use="literal"/><soap12:header message="tns:BookingFault" part="reason" use="literal"/></wsdl:input>
|
|
59
|
+
</wsdl:operation>
|
|
60
|
+
</wsdl:binding>
|
|
61
|
+
<wsdl:binding name="BookingBinding11" type="tns:BookingPortType">
|
|
62
|
+
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
|
|
63
|
+
<wsdl:operation name="CancelBooking"><soap:operation soapAction="urn:booking:cancel:v1"/></wsdl:operation>
|
|
64
|
+
</wsdl:binding>
|
|
65
|
+
<wsdl:service name="BookingService">
|
|
66
|
+
<wsdl:documentation>Booking supplier API.</wsdl:documentation>
|
|
67
|
+
<wsdl:port name="BookingPort" binding="tns:BookingBinding"><soap12:address location="https://booking.example/soap"/></wsdl:port>
|
|
68
|
+
<wsdl:port name="BookingPort11" binding="tns:BookingBinding11"><soap:address location="https://booking.example/soap/v1"/></wsdl:port>
|
|
69
|
+
</wsdl:service>
|
|
70
|
+
</wsdl:definitions>`)
|
|
71
|
+
|
|
72
|
+
result, err := Read(root, "service.wsdl")
|
|
73
|
+
if err != nil {
|
|
74
|
+
t.Fatal(err)
|
|
75
|
+
}
|
|
76
|
+
if len(result.Contracts) != 1 {
|
|
77
|
+
t.Fatalf("contracts = %+v", result.Contracts)
|
|
78
|
+
}
|
|
79
|
+
contract := result.Contracts[0]
|
|
80
|
+
if contract.Name != "BookingService" || contract.Summary != "Booking supplier API." || contract.Source != "service.wsdl" {
|
|
81
|
+
t.Fatalf("contract = %+v", contract)
|
|
82
|
+
}
|
|
83
|
+
if len(contract.Interfaces) != 2 {
|
|
84
|
+
t.Fatalf("interfaces = %+v", contract.Interfaces)
|
|
85
|
+
}
|
|
86
|
+
var iface Interface
|
|
87
|
+
for _, candidate := range contract.Interfaces {
|
|
88
|
+
if candidate.Name == "BookingPort" {
|
|
89
|
+
iface = candidate
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if iface.Name != "BookingPort" || iface.PortType != "BookingPortType" || iface.Binding != "BookingBinding" || iface.Version != "1.2" || iface.Style != "document" || iface.Endpoint != "https://booking.example/soap" {
|
|
93
|
+
t.Fatalf("interface = %+v", iface)
|
|
94
|
+
}
|
|
95
|
+
if len(iface.Operations) != 1 {
|
|
96
|
+
t.Fatalf("operations = %+v", iface.Operations)
|
|
97
|
+
}
|
|
98
|
+
op := iface.Operations[0]
|
|
99
|
+
if op.Action != "urn:booking:cancel" || op.Request != "CancelRequestMessage" || op.Response != "CancelResponseMessage" || strings.Join(op.Faults, ",") != "BookingFault" || strings.Join(op.Headers, ",") != "BookingFault.reason" {
|
|
100
|
+
t.Fatalf("operation = %+v", op)
|
|
101
|
+
}
|
|
102
|
+
messages := map[string]Message{}
|
|
103
|
+
for _, message := range iface.Messages {
|
|
104
|
+
messages[message.Name] = message
|
|
105
|
+
}
|
|
106
|
+
request := messages["CancelRequestMessage"]
|
|
107
|
+
if len(request.Fields) != 2 || request.Fields[0].Name != "bookingId" || request.Fields[0].Type != "string" || request.Fields[1].Type != "string[]" {
|
|
108
|
+
t.Fatalf("request = %+v", request)
|
|
109
|
+
}
|
|
110
|
+
response := messages["CancelResponseMessage"]
|
|
111
|
+
if len(response.Fields) != 1 || response.Fields[0].Name != "accepted" || response.Fields[0].Type != "boolean" {
|
|
112
|
+
t.Fatalf("response = %+v", response)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
func TestRemoteImportsAreWarningsAndNeverFetched(t *testing.T) {
|
|
117
|
+
root := t.TempDir()
|
|
118
|
+
writeFixture(t, root, "service.wsdl", `
|
|
119
|
+
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="urn:local">
|
|
120
|
+
<import namespace="urn:remote" location="https://example.invalid/remote.wsdl"/>
|
|
121
|
+
<portType name="Local"><operation name="Ping"/></portType>
|
|
122
|
+
</definitions>`)
|
|
123
|
+
result, err := Read(root, "service.wsdl")
|
|
124
|
+
if err != nil {
|
|
125
|
+
t.Fatal(err)
|
|
126
|
+
}
|
|
127
|
+
if len(result.Warnings) != 1 || !strings.Contains(result.Warnings[0], "remote import") {
|
|
128
|
+
t.Fatalf("warnings = %v", result.Warnings)
|
|
129
|
+
}
|
|
130
|
+
if len(result.Contracts) != 1 || len(result.Contracts[0].Interfaces) != 1 {
|
|
131
|
+
t.Fatalf("contracts = %+v", result.Contracts)
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// A schema copied beside every document that uses it is one finding per
|
|
136
|
+
// namespace, naming the file whose declarations were kept and the files that
|
|
137
|
+
// repeat them. It goes out as a schema warning, not a resolution one, so only
|
|
138
|
+
// the extractor publishing the contracts reports it.
|
|
139
|
+
func TestDuplicateDeclarationsAreSummarisedWithTheirOrigin(t *testing.T) {
|
|
140
|
+
root := t.TempDir()
|
|
141
|
+
schema := `
|
|
142
|
+
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:common">
|
|
143
|
+
<complexType name="CodeType"/>
|
|
144
|
+
<complexType name="AmountType"/>
|
|
145
|
+
<element name="Ping"/>
|
|
146
|
+
</schema>`
|
|
147
|
+
writeFixture(t, root, "a/common.xsd", schema)
|
|
148
|
+
writeFixture(t, root, "b/common.xsd", schema)
|
|
149
|
+
writeFixture(t, root, "c/common.xsd", schema)
|
|
150
|
+
writeFixture(t, root, "service.wsdl", `
|
|
151
|
+
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:local">
|
|
152
|
+
<types>
|
|
153
|
+
<xs:schema><xs:import namespace="urn:common" schemaLocation="a/common.xsd"/></xs:schema>
|
|
154
|
+
<xs:schema><xs:import namespace="urn:common" schemaLocation="b/common.xsd"/></xs:schema>
|
|
155
|
+
<xs:schema><xs:import namespace="urn:common" schemaLocation="c/common.xsd"/></xs:schema>
|
|
156
|
+
</types>
|
|
157
|
+
<portType name="Local"><operation name="Ping"/></portType>
|
|
158
|
+
</definitions>`)
|
|
159
|
+
result, err := Read(root, "service.wsdl")
|
|
160
|
+
if err != nil {
|
|
161
|
+
t.Fatal(err)
|
|
162
|
+
}
|
|
163
|
+
if len(result.Warnings) != 0 {
|
|
164
|
+
t.Errorf("resolution warnings = %v, want none", result.Warnings)
|
|
165
|
+
}
|
|
166
|
+
want := "b/common.xsd: duplicate declaration CodeType and 2 more in namespace urn:common (also in c/common.xsd); the declarations in a/common.xsd are used"
|
|
167
|
+
if len(result.SchemaWarnings) != 1 || result.SchemaWarnings[0] != want {
|
|
168
|
+
t.Fatalf("schema warnings = %v\nwant [%s]", result.SchemaWarnings, want)
|
|
169
|
+
}
|
|
170
|
+
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@shortlink-org/portolan",
|
|
3
3
|
"description": "Generate a navigable architecture catalog from code and specifications.",
|
|
4
4
|
"private": false,
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.3.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"homepage": "https://github.com/shortlink-org/portolan#readme",
|
|
@@ -25,7 +25,18 @@
|
|
|
25
25
|
"src",
|
|
26
26
|
"public",
|
|
27
27
|
"schema",
|
|
28
|
+
"go.mod",
|
|
29
|
+
"go.sum",
|
|
30
|
+
"catalog",
|
|
31
|
+
"plugin",
|
|
32
|
+
"internal/gohttp",
|
|
33
|
+
"internal/gocall",
|
|
34
|
+
"internal/goscan",
|
|
35
|
+
"internal/wsdl",
|
|
28
36
|
"plugins/*.wasm",
|
|
37
|
+
"plugins/cmd/portolan-http-clients",
|
|
38
|
+
"plugins/extract-http-clients",
|
|
39
|
+
"plugins/openapi",
|
|
29
40
|
"plugins/*/*.py",
|
|
30
41
|
"plugins/*/*.ts",
|
|
31
42
|
"plugins/*/*.json",
|
|
@@ -67,12 +78,13 @@
|
|
|
67
78
|
"prepack": "npm run plugins:build"
|
|
68
79
|
},
|
|
69
80
|
"dependencies": {
|
|
70
|
-
"@ai-sdk/openai-compatible": "3.0.
|
|
71
|
-
"@ai-sdk/react": "4.0.
|
|
81
|
+
"@ai-sdk/openai-compatible": "3.0.47",
|
|
82
|
+
"@ai-sdk/react": "4.0.100",
|
|
72
83
|
"@asyncapi/react-component": "^3.1.8",
|
|
73
84
|
"@clack/prompts": "^1.8.0",
|
|
74
85
|
"@floating-ui/react": "^0.27.20",
|
|
75
86
|
"@headlessui/react": "^2.2.10",
|
|
87
|
+
"@marcbachmann/cel-js": "^8.0.0",
|
|
76
88
|
"@scalar/api-reference-react": "^0.9.66",
|
|
77
89
|
"@tailwindcss/vite": "^4.0.0",
|
|
78
90
|
"@tanstack/react-query": "^5.102.8",
|
|
@@ -80,19 +92,19 @@
|
|
|
80
92
|
"@tanstack/react-virtual": "^3.14.10",
|
|
81
93
|
"@vitejs/plugin-react": "^6.1.1",
|
|
82
94
|
"@xyflow/react": "^12.11.5",
|
|
83
|
-
"ai": "7.0.
|
|
95
|
+
"ai": "7.0.97",
|
|
84
96
|
"ajv": "^8.20.0",
|
|
85
97
|
"elkjs": "^0.12.0",
|
|
86
98
|
"html-to-image": "^1.11.13",
|
|
87
99
|
"likec4": "^1.59.2",
|
|
88
100
|
"lowlight": "^3.3.0",
|
|
89
101
|
"lucide-react": "^1.38.0",
|
|
90
|
-
"mermaid": "^
|
|
102
|
+
"mermaid": "^12.0.0",
|
|
91
103
|
"motion": "^13.2.0",
|
|
92
104
|
"oxc-parser": "^0.149.0",
|
|
93
105
|
"oxc-resolver": "^11.24.2",
|
|
94
|
-
"react": "^19.
|
|
95
|
-
"react-dom": "^19.
|
|
106
|
+
"react": "^19.3.0",
|
|
107
|
+
"react-dom": "^19.3.0",
|
|
96
108
|
"react-markdown": "^10.1.0",
|
|
97
109
|
"react-resizable-panels": "^4.12.3",
|
|
98
110
|
"react-router": "^8.3.1",
|
|
@@ -104,9 +116,9 @@
|
|
|
104
116
|
"zustand": "^5.0.15"
|
|
105
117
|
},
|
|
106
118
|
"devDependencies": {
|
|
107
|
-
"@types/node": "^26.5.
|
|
108
|
-
"@types/react": "^19.
|
|
109
|
-
"@types/react-dom": "^19.
|
|
119
|
+
"@types/node": "^26.5.1",
|
|
120
|
+
"@types/react": "^19.3.0",
|
|
121
|
+
"@types/react-dom": "^19.3.0",
|
|
110
122
|
"typescript": "^7.0.2",
|
|
111
123
|
"vitest": "^5.0.0"
|
|
112
124
|
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// Describing a plugin: what it is called, where it belongs in a run, and what
|
|
2
|
+
// it can be told.
|
|
3
|
+
//
|
|
4
|
+
// The options a plugin takes are facts the source does not carry - which
|
|
5
|
+
// bounded context a Go module belongs to, whose proto package a client calls.
|
|
6
|
+
// Only the plugin knows them, and until it could say so the manifest was a
|
|
7
|
+
// file you wrote by reading somebody's struct. A misspelled key was silently
|
|
8
|
+
// dropped, because that is what encoding/json does with a field it does not
|
|
9
|
+
// recognise.
|
|
10
|
+
//
|
|
11
|
+
// So a plugin answers a second question now. The schema it hands back is
|
|
12
|
+
// composed into schema/portolan.schema.json, which an editor reads while the
|
|
13
|
+
// manifest is being written and the host checks before it runs anything.
|
|
14
|
+
|
|
15
|
+
package plugin
|
|
16
|
+
|
|
17
|
+
import (
|
|
18
|
+
"encoding/json"
|
|
19
|
+
"fmt"
|
|
20
|
+
"io"
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
// KindDescribe asks a plugin what it is rather than asking it to work.
|
|
24
|
+
const KindDescribe = "describe"
|
|
25
|
+
|
|
26
|
+
// Phases a step can be declared under in the manifest. A plugin names the ones
|
|
27
|
+
// it belongs in, which is what stops the schema from offering an extractor
|
|
28
|
+
// where a renderer goes.
|
|
29
|
+
const (
|
|
30
|
+
PhaseExtract = "extract"
|
|
31
|
+
PhaseVerify = "verify"
|
|
32
|
+
PhaseGenerate = "generate"
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
// Descriptor is a plugin's answer to KindDescribe.
|
|
36
|
+
type Descriptor struct {
|
|
37
|
+
// Name is what the plugin calls itself. The manifest is free to declare it
|
|
38
|
+
// under another name - the schema is keyed by the declared one - so this is
|
|
39
|
+
// for the reader, not for lookup.
|
|
40
|
+
Name string `json:"name"`
|
|
41
|
+
|
|
42
|
+
// Summary is one line, and it is the line an editor shows beside the step.
|
|
43
|
+
Summary string `json:"summary,omitempty"`
|
|
44
|
+
|
|
45
|
+
// Phases are the manifest sections this plugin belongs in.
|
|
46
|
+
Phases []string `json:"phases"`
|
|
47
|
+
|
|
48
|
+
// Options is a JSON Schema for what the manifest may pass in `options`.
|
|
49
|
+
// It must close itself with `additionalProperties: false`: the misspelled
|
|
50
|
+
// key is the error worth catching, and a schema that accepts anything
|
|
51
|
+
// catches nothing.
|
|
52
|
+
Options json.RawMessage `json:"options,omitempty"`
|
|
53
|
+
|
|
54
|
+
// Needs names what the host must put in the request beyond the tree: a
|
|
55
|
+
// fact a sandboxed module cannot reach on its own. The one need so far is
|
|
56
|
+
// NeedHistory (portolan.0007). A host that cannot supply a need leaves
|
|
57
|
+
// the field out, and the plugin says what it could not do without it.
|
|
58
|
+
Needs []string `json:"needs,omitempty"`
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// NeedHistory asks the host for Input.History: when each file under the root
|
|
62
|
+
// was first committed and last changed, read from git by the host so that the
|
|
63
|
+
// plugin need not run anything.
|
|
64
|
+
const NeedHistory = "history"
|
|
65
|
+
|
|
66
|
+
// Serve reads one request and writes one response - the whole of a plugin's
|
|
67
|
+
// main, apart from the work itself.
|
|
68
|
+
//
|
|
69
|
+
// Every plugin had this loop written out, and each copy had to remember the
|
|
70
|
+
// describe branch once there was one. The options type is the only thing that
|
|
71
|
+
// differs, so it is the only thing the caller supplies.
|
|
72
|
+
func Serve[O any](stdin io.Reader, stdout io.Writer, d Descriptor, run func(Request, O) (Response, error)) error {
|
|
73
|
+
in, err := io.ReadAll(stdin)
|
|
74
|
+
if err != nil {
|
|
75
|
+
return fmt.Errorf("reading the request: %w", err)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
var req Request
|
|
79
|
+
if err := json.Unmarshal(in, &req); err != nil {
|
|
80
|
+
return fmt.Errorf("the request is not a portolan plugin request: %w", err)
|
|
81
|
+
}
|
|
82
|
+
if req.PortolanVersion != "" && req.PortolanVersion != Version {
|
|
83
|
+
return fmt.Errorf("unsupported portolan protocol %q (plugin supports %s)", req.PortolanVersion, Version)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
resp := Response{}
|
|
87
|
+
switch req.Kind {
|
|
88
|
+
case KindDescribe:
|
|
89
|
+
// Files is named rather than left nil because the host reads it on
|
|
90
|
+
// every response, and a describe that answers `"files": null` is a
|
|
91
|
+
// plugin that looks broken the first time anyone asks it anything.
|
|
92
|
+
resp = Response{Files: []File{}, Describe: &d}
|
|
93
|
+
case "":
|
|
94
|
+
var opts O
|
|
95
|
+
if len(req.Options) > 0 {
|
|
96
|
+
if err := json.Unmarshal(req.Options, &opts); err != nil {
|
|
97
|
+
return fmt.Errorf("options: %w", err)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if resp, err = run(req, opts); err != nil {
|
|
102
|
+
return err
|
|
103
|
+
}
|
|
104
|
+
default:
|
|
105
|
+
return fmt.Errorf("unknown request kind %q", req.Kind)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
out, err := json.Marshal(resp)
|
|
109
|
+
if err != nil {
|
|
110
|
+
return fmt.Errorf("encoding the response: %w", err)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if _, err := stdout.Write(out); err != nil {
|
|
114
|
+
return fmt.Errorf("writing the response: %w", err)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return nil
|
|
118
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
package plugin_test
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"bytes"
|
|
5
|
+
"encoding/json"
|
|
6
|
+
"strings"
|
|
7
|
+
"testing"
|
|
8
|
+
|
|
9
|
+
"github.com/shortlink-org/portolan/plugin"
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
type options struct {
|
|
13
|
+
Context string `json:"context"`
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
func descriptor() plugin.Descriptor {
|
|
17
|
+
return plugin.Descriptor{
|
|
18
|
+
Name: "example",
|
|
19
|
+
Phases: []string{plugin.PhaseExtract},
|
|
20
|
+
Options: json.RawMessage(`{"type":"object","additionalProperties":false}`),
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
func TestServeDescribesWithoutWorking(t *testing.T) {
|
|
25
|
+
worked := false
|
|
26
|
+
out := &bytes.Buffer{}
|
|
27
|
+
|
|
28
|
+
err := plugin.Serve(strings.NewReader(`{"kind":"describe"}`), out, descriptor(),
|
|
29
|
+
func(plugin.Request, options) (plugin.Response, error) {
|
|
30
|
+
worked = true
|
|
31
|
+
|
|
32
|
+
return plugin.Response{}, nil
|
|
33
|
+
})
|
|
34
|
+
if err != nil {
|
|
35
|
+
t.Fatalf("describe: %v", err)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if worked {
|
|
39
|
+
t.Error("a describe ran the plugin, which is the one thing it must not do")
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
var resp plugin.Response
|
|
43
|
+
if err := json.Unmarshal(out.Bytes(), &resp); err != nil {
|
|
44
|
+
t.Fatalf("the answer is not a response: %v", err)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if resp.Describe == nil {
|
|
48
|
+
t.Fatal("a describe answered without a descriptor")
|
|
49
|
+
}
|
|
50
|
+
if resp.Describe.Name != "example" {
|
|
51
|
+
t.Errorf("descriptor names %q", resp.Describe.Name)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// The host reads files on every response, so a describe that answers null
|
|
55
|
+
// is a plugin that looks broken the first time anyone asks it anything.
|
|
56
|
+
if !strings.Contains(out.String(), `"files":[]`) {
|
|
57
|
+
t.Errorf("a describe answered %s, which has no files list", out)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
func TestServeReadsOptions(t *testing.T) {
|
|
62
|
+
var seen options
|
|
63
|
+
out := &bytes.Buffer{}
|
|
64
|
+
|
|
65
|
+
err := plugin.Serve(
|
|
66
|
+
strings.NewReader(`{"input":{"root":"examples/auth"},"options":{"context":"auth"}}`),
|
|
67
|
+
out, descriptor(),
|
|
68
|
+
func(req plugin.Request, opts options) (plugin.Response, error) {
|
|
69
|
+
seen = opts
|
|
70
|
+
|
|
71
|
+
return plugin.Response{Files: []plugin.File{{Name: req.Input.Root + ".json"}}}, nil
|
|
72
|
+
})
|
|
73
|
+
if err != nil {
|
|
74
|
+
t.Fatalf("run: %v", err)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if seen.Context != "auth" {
|
|
78
|
+
t.Errorf("options came through as %+v", seen)
|
|
79
|
+
}
|
|
80
|
+
if !strings.Contains(out.String(), "examples/auth.json") {
|
|
81
|
+
t.Errorf("the response is %s", out)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
func TestServeRefusesAnUnknownKind(t *testing.T) {
|
|
86
|
+
err := plugin.Serve(strings.NewReader(`{"kind":"explain"}`), &bytes.Buffer{}, descriptor(),
|
|
87
|
+
func(plugin.Request, options) (plugin.Response, error) {
|
|
88
|
+
return plugin.Response{}, nil
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
if err == nil || !strings.Contains(err.Error(), "explain") {
|
|
92
|
+
t.Errorf("an unknown kind gave %v", err)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
func TestServeRefusesAnIncompatibleProtocol(t *testing.T) {
|
|
97
|
+
err := plugin.Serve(strings.NewReader(`{"portolanVersion":"9.0.0","kind":"describe"}`), &bytes.Buffer{}, descriptor(),
|
|
98
|
+
func(plugin.Request, options) (plugin.Response, error) { return plugin.Response{}, nil })
|
|
99
|
+
if err == nil || !strings.Contains(err.Error(), "unsupported portolan protocol") {
|
|
100
|
+
t.Errorf("incompatible version gave %v", err)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
func TestWarningsAreNotAResponseProperty(t *testing.T) {
|
|
105
|
+
b := &plugin.Builder{}
|
|
106
|
+
b.Warn("fixture", "not represented")
|
|
107
|
+
out, err := json.Marshal(b.Response())
|
|
108
|
+
if err != nil {
|
|
109
|
+
t.Fatal(err)
|
|
110
|
+
}
|
|
111
|
+
if strings.Contains(string(out), "diagnostics") || strings.Contains(string(out), "warning") {
|
|
112
|
+
t.Errorf("warning leaked into wire response: %s", out)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// Package plugin is the wire contract between the host and a generator.
|
|
2
|
+
//
|
|
3
|
+
// One JSON message in, one JSON message out, and the same shape whichever
|
|
4
|
+
// direction the generator runs in: an extractor reads source and answers with
|
|
5
|
+
// a catalog fragment, a renderer reads the catalog and answers with pages.
|
|
6
|
+
// Both name files; neither writes them. The host does that, which is what lets
|
|
7
|
+
// a generator run as a wasm module with nothing preopened at all.
|
|
8
|
+
package plugin
|
|
9
|
+
|
|
10
|
+
import (
|
|
11
|
+
"encoding/json"
|
|
12
|
+
"fmt"
|
|
13
|
+
"os"
|
|
14
|
+
|
|
15
|
+
"github.com/shortlink-org/portolan/catalog"
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
const Version = "0.1.0"
|
|
19
|
+
|
|
20
|
+
// Request is everything a plugin is allowed to know. There is no ambient state
|
|
21
|
+
// to read, no environment, and - for a wasm plugin - no filesystem either.
|
|
22
|
+
type Request struct {
|
|
23
|
+
PortolanVersion string `json:"portolanVersion"`
|
|
24
|
+
|
|
25
|
+
// Kind is what the host is asking for. Empty - the only thing anyone sent
|
|
26
|
+
// before this field existed - means do the work. KindDescribe means answer
|
|
27
|
+
// with a Descriptor and read nothing: it is how the manifest schema is
|
|
28
|
+
// built, and it has to be cheap enough to run over every declared plugin.
|
|
29
|
+
Kind string `json:"kind,omitempty"`
|
|
30
|
+
|
|
31
|
+
// Catalog is the merged catalog, for a plugin that renders from it. An
|
|
32
|
+
// extractor is handed the zero value: it runs before there is one.
|
|
33
|
+
Catalog catalog.Catalog `json:"catalog"`
|
|
34
|
+
|
|
35
|
+
// Input is where a plugin that reads source should look. Empty for a
|
|
36
|
+
// renderer, which has no business touching the tree.
|
|
37
|
+
Input Input `json:"input"`
|
|
38
|
+
|
|
39
|
+
// Options belong to the plugin and are passed through from the manifest
|
|
40
|
+
// unread, so the host never has to know what any plugin can be told.
|
|
41
|
+
Options json.RawMessage `json:"options"`
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
type Input struct {
|
|
45
|
+
// Root is the directory to read, relative to the repository.
|
|
46
|
+
Root string `json:"root"`
|
|
47
|
+
|
|
48
|
+
// Output is the directory where the host will place the files returned by
|
|
49
|
+
// this plugin, relative to the repository. Extractors use it only when a
|
|
50
|
+
// catalog entry needs to point at a generated companion document.
|
|
51
|
+
Output string `json:"output,omitempty"`
|
|
52
|
+
|
|
53
|
+
// Provenance is not part of the request (portolan.0010). A fragment used
|
|
54
|
+
// to carry a commit and a date that the host worked out from the last
|
|
55
|
+
// commit touching Root and every plugin copied to the top of its output.
|
|
56
|
+
// The host now reads both from the git history of the fragment it wrote,
|
|
57
|
+
// so a plugin has nothing to stamp and no clock to read: its output
|
|
58
|
+
// changes exactly when the source it describes changes, and when that was
|
|
59
|
+
// is a fact about the file, not a field in it.
|
|
60
|
+
|
|
61
|
+
// History is when each file under Root was first committed and last
|
|
62
|
+
// changed, keyed by the file's path as the plugin would name it - the same
|
|
63
|
+
// relative form as Root. Present only for a plugin whose descriptor asks
|
|
64
|
+
// (NeedHistory) and only when Root lies inside a git checkout; a plugin
|
|
65
|
+
// that asked and finds nil knows there was no history to read. The host
|
|
66
|
+
// reads it (portolan.0007) so that no plugin has to run git, which a wasm
|
|
67
|
+
// module cannot.
|
|
68
|
+
History map[string]FileHistory `json:"history,omitempty"`
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// FileHistory is one file's first and last commit. Revised is nil when the
|
|
72
|
+
// file has one commit.
|
|
73
|
+
type FileHistory struct {
|
|
74
|
+
Created Commit `json:"created"`
|
|
75
|
+
Revised *Commit `json:"revised,omitempty"`
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Commit is one commit as the host read it: full sha, author name, and the
|
|
79
|
+
// committer date in strict ISO 8601.
|
|
80
|
+
type Commit struct {
|
|
81
|
+
Commit string `json:"commit"`
|
|
82
|
+
Author string `json:"author"`
|
|
83
|
+
Date string `json:"date"`
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Response is what comes back.
|
|
87
|
+
//
|
|
88
|
+
// Files are named, not written (portolan.0001). The host rejects a name that climbs out of the
|
|
89
|
+
// output directory, and that rejection is the whole of a plugin's authority
|
|
90
|
+
// over the tree.
|
|
91
|
+
type Response struct {
|
|
92
|
+
Files []File `json:"files"`
|
|
93
|
+
warnings []Warning
|
|
94
|
+
|
|
95
|
+
// Describe answers KindDescribe and is absent otherwise. A plugin written
|
|
96
|
+
// against an older version of this protocol answers without it, which the
|
|
97
|
+
// host reports rather than treating as a plugin with no options.
|
|
98
|
+
Describe *Descriptor `json:"describe,omitempty"`
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
type File struct {
|
|
102
|
+
Name string `json:"name"`
|
|
103
|
+
Contents string `json:"contents"`
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Warning is an in-process extraction note. It is intentionally not serialized
|
|
107
|
+
// into Response: the wire contract has one decisive outcome, files or error.
|
|
108
|
+
type Warning struct {
|
|
109
|
+
Severity string `json:"severity"` // "warning" | "error"
|
|
110
|
+
Message string `json:"message"`
|
|
111
|
+
Ref string `json:"ref,omitempty"`
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Builder accumulates a response. Every plugin needs exactly this and nothing
|
|
115
|
+
// more, so it lives here rather than being written twice.
|
|
116
|
+
type Builder struct {
|
|
117
|
+
Files []File
|
|
118
|
+
Warnings []Warning
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
func (b *Builder) File(name, contents string) {
|
|
122
|
+
b.Files = append(b.Files, File{Name: name, Contents: contents})
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
func (b *Builder) Warn(ref, message string) {
|
|
126
|
+
b.Warnings = append(b.Warnings, Warning{Severity: "warning", Message: message, Ref: ref})
|
|
127
|
+
where := ""
|
|
128
|
+
if ref != "" {
|
|
129
|
+
where = ref + ": "
|
|
130
|
+
}
|
|
131
|
+
fmt.Fprintln(os.Stderr, "warning:", where+message)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
func (b *Builder) Response() Response {
|
|
135
|
+
return Response{Files: b.Files, warnings: b.Warnings}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Warnings exposes extraction notes to in-process tests and embedders. They
|
|
139
|
+
// are deliberately absent from the JSON protocol: a caller's result is files
|
|
140
|
+
// or an error, not files plus an advisory property nobody is required to act on.
|
|
141
|
+
func (r Response) Warnings() []Warning { return r.warnings }
|