@dusted/anqst 1.0.1 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.renderTsBoundaryCodecHelpers = exports.renderCppBoundaryCodecHelpers = void 0;
4
+ exports.buildBoundaryCodecCatalog = buildBoundaryCodecCatalog;
5
+ exports.getBoundaryPayloadSite = getBoundaryPayloadSite;
6
+ exports.getBoundaryParameterSite = getBoundaryParameterSite;
7
+ const debug_dump_1 = require("./debug-dump");
8
+ const boundary_codec_model_1 = require("./boundary-codec-model");
9
+ const boundary_codec_analysis_1 = require("./boundary-codec-analysis");
10
+ const boundary_codec_plan_1 = require("./boundary-codec-plan");
11
+ var boundary_codec_render_1 = require("./boundary-codec-render");
12
+ Object.defineProperty(exports, "renderCppBoundaryCodecHelpers", { enumerable: true, get: function () { return boundary_codec_render_1.renderCppBoundaryCodecHelpers; } });
13
+ Object.defineProperty(exports, "renderTsBoundaryCodecHelpers", { enumerable: true, get: function () { return boundary_codec_render_1.renderTsBoundaryCodecHelpers; } });
14
+ function renderAnalysisNode(node, level, lines, visitedNamed = new Set()) {
15
+ const pad = " ".repeat(level);
16
+ if (node.nodeKind === "leaf") {
17
+ lines.push(`${pad}- leaf ${node.path.join(".")} :: ${node.leaf.logicalKind} -> ${node.leaf.region}`);
18
+ return;
19
+ }
20
+ if (node.nodeKind === "finite-domain") {
21
+ lines.push(`${pad}- finite-domain ${node.path.join(".")} :: ${node.domain.primitive} {${node.domain.variants.map((variant) => variant.tsLiteralText).join(", ")}}`);
22
+ return;
23
+ }
24
+ if (node.nodeKind === "array") {
25
+ lines.push(`${pad}- array ${node.path.join(".")} :: count metadata required`);
26
+ renderAnalysisNode(node.element, level + 1, lines, visitedNamed);
27
+ return;
28
+ }
29
+ if (node.nodeKind === "named") {
30
+ lines.push(`${pad}- named ${node.name}`);
31
+ if (visitedNamed.has(node.name)) {
32
+ lines.push(`${pad} [recursive]`);
33
+ return;
34
+ }
35
+ visitedNamed.add(node.name);
36
+ renderAnalysisNode(node.target, level + 1, lines, visitedNamed);
37
+ return;
38
+ }
39
+ lines.push(`${pad}- struct ${node.path.join(".")}`);
40
+ for (const field of node.fields) {
41
+ lines.push(`${pad} field ${field.name}${field.optional ? "?" : ""}`);
42
+ renderAnalysisNode(field.node, level + 2, lines, visitedNamed);
43
+ }
44
+ }
45
+ function renderPlanNode(node, level, lines, visitedNamed = new Set()) {
46
+ const pad = " ".repeat(level);
47
+ const loweringText = (lowering) => `ts:${lowering.tsEncode.mode}/${lowering.tsDecode.mode} cpp:${lowering.cppEncode.mode}/${lowering.cppDecode.mode}`;
48
+ if (node.nodeKind === "leaf") {
49
+ if (node.blobEntryId) {
50
+ lines.push(`${pad}- blob leaf ${node.path.join(".")} packing=${node.selectedPacking} lowering=${loweringText(node.lowering)} -> ${node.blobEntryId}`);
51
+ }
52
+ else {
53
+ lines.push(`${pad}- ${node.leaf.region} leaf ${node.path.join(".")} packing=${node.selectedPacking} lowering=${loweringText(node.lowering)} -> ${node.itemEntryId}`);
54
+ }
55
+ return;
56
+ }
57
+ if (node.nodeKind === "finite-domain") {
58
+ if (node.representation.kind === "identity-text") {
59
+ lines.push(`${pad}- finite-domain ${node.path.join(".")} identity-text lowering=${loweringText(node.lowering)} -> ${node.itemEntryId}`);
60
+ }
61
+ else {
62
+ lines.push(`${pad}- finite-domain ${node.path.join(".")} code=${node.representation.scalarKind} lowering=${loweringText(node.lowering)} -> ${node.blobEntryId}`);
63
+ }
64
+ return;
65
+ }
66
+ if (node.nodeKind === "array") {
67
+ lines.push(`${pad}- array ${node.path.join(".")} extent=${node.extentStrategy}${node.countEntryId ? ` count=${node.countEntryId}` : ""}`);
68
+ renderPlanNode(node.element, level + 1, lines, visitedNamed);
69
+ return;
70
+ }
71
+ if (node.nodeKind === "named") {
72
+ lines.push(`${pad}- named ${node.name}`);
73
+ if (visitedNamed.has(node.name)) {
74
+ lines.push(`${pad} [recursive]`);
75
+ return;
76
+ }
77
+ visitedNamed.add(node.name);
78
+ renderPlanNode(node.target, level + 1, lines, visitedNamed);
79
+ return;
80
+ }
81
+ lines.push(`${pad}- struct ${node.path.join(".")} ordering=${node.ordering}`);
82
+ for (const field of node.fields) {
83
+ lines.push(`${pad} field ${field.name}${field.optional ? `? presence=${field.presenceStrategy}:${field.presenceEntryId}` : ""}`);
84
+ renderPlanNode(field.node, level + 2, lines, visitedNamed);
85
+ }
86
+ }
87
+ function renderBoundaryDebugSummaries(plans) {
88
+ const analysisChunks = [];
89
+ const planChunks = [];
90
+ for (const plan of plans) {
91
+ analysisChunks.push(`codec ${plan.codecId} :: ${plan.typeText}`);
92
+ analysisChunks.push(`summary ${JSON.stringify(plan.analysis.summary)}`);
93
+ renderAnalysisNode(plan.analysis.root, 1, analysisChunks);
94
+ analysisChunks.push("");
95
+ planChunks.push(`codec ${plan.codecId} :: ${plan.typeText}`);
96
+ planChunks.push(`decodePolicy=${plan.decodePolicy} blob=${plan.blobEntries.length} items=${plan.itemEntries.length} kinds=${plan.requirements.itemKinds.join(",") || "none"} itemCountHeaderKinds=${plan.requirements.itemCountHeaderKinds.join(",") || "none"}`);
97
+ renderPlanNode(plan.root, 1, planChunks);
98
+ planChunks.push("");
99
+ }
100
+ return {
101
+ analyses: `${analysisChunks.join("\n")}\n`,
102
+ plans: `${planChunks.join("\n")}\n`
103
+ };
104
+ }
105
+ function buildBoundaryCodecCatalog(spec) {
106
+ const analyzer = new boundary_codec_analysis_1.BoundaryTransportAnalyzer(spec);
107
+ const plans = [];
108
+ const plansByCodecId = new Map();
109
+ const codecIdByTypeText = new Map();
110
+ const payloadSites = new Map();
111
+ const parameterSites = new Map();
112
+ const usedCodecIds = new Set();
113
+ const ensureCodec = (typeText, pathHintParts) => {
114
+ const existing = codecIdByTypeText.get(typeText);
115
+ if (existing)
116
+ return existing;
117
+ const proposed = `AnQstStructured_${(0, boundary_codec_model_1.sanitizeIdentifier)((0, boundary_codec_model_1.stripAnQstType)(typeText).replace(/\s+/g, "_"))}`;
118
+ let codecId = proposed;
119
+ let suffix = 2;
120
+ while (usedCodecIds.has(codecId)) {
121
+ codecId = `${proposed}_${suffix++}`;
122
+ }
123
+ usedCodecIds.add(codecId);
124
+ codecIdByTypeText.set(typeText, codecId);
125
+ const analysis = analyzer.analyzeTypeText(typeText, pathHintParts);
126
+ const plan = (0, boundary_codec_plan_1.buildBoundaryCodecPlan)(codecId, analysis);
127
+ plans.push(plan);
128
+ plansByCodecId.set(codecId, plan);
129
+ return codecId;
130
+ };
131
+ for (const service of spec.services) {
132
+ for (const member of service.members) {
133
+ if (member.payloadTypeText && member.payloadTypeText.trim() !== "void") {
134
+ const site = {
135
+ siteKey: (0, boundary_codec_model_1.codecSiteKey)("payload", service.name, member.name, null),
136
+ kind: "payload",
137
+ serviceName: service.name,
138
+ memberName: member.name,
139
+ parameterName: null,
140
+ typeText: member.payloadTypeText,
141
+ codecId: ensureCodec(member.payloadTypeText, [service.name, member.name, "Payload"])
142
+ };
143
+ payloadSites.set(site.siteKey, site);
144
+ }
145
+ for (const parameter of member.parameters) {
146
+ const site = {
147
+ siteKey: (0, boundary_codec_model_1.codecSiteKey)("parameter", service.name, member.name, parameter.name),
148
+ kind: "parameter",
149
+ serviceName: service.name,
150
+ memberName: member.name,
151
+ parameterName: parameter.name,
152
+ typeText: parameter.typeText,
153
+ codecId: ensureCodec(parameter.typeText, [service.name, member.name, parameter.name])
154
+ };
155
+ parameterSites.set(site.siteKey, site);
156
+ }
157
+ }
158
+ }
159
+ const debug = renderBoundaryDebugSummaries(plans);
160
+ (0, debug_dump_1.writeDebugFile)(process.cwd(), "codecs/boundary-transport-analysis.txt", debug.analyses);
161
+ (0, debug_dump_1.writeDebugFile)(process.cwd(), "codecs/boundary-plans.txt", debug.plans);
162
+ return {
163
+ plans,
164
+ plansByCodecId,
165
+ payloadSites,
166
+ parameterSites
167
+ };
168
+ }
169
+ function getBoundaryPayloadSite(catalog, serviceName, memberName) {
170
+ return catalog.payloadSites.get((0, boundary_codec_model_1.codecSiteKey)("payload", serviceName, memberName, null));
171
+ }
172
+ function getBoundaryParameterSite(catalog, serviceName, memberName, parameterName) {
173
+ return catalog.parameterSites.get((0, boundary_codec_model_1.codecSiteKey)("parameter", serviceName, memberName, parameterName));
174
+ }