@pikku/inspector 0.12.74 → 0.12.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (219) hide show
  1. package/CHANGELOG.md +347 -0
  2. package/dist/add/add-analytics.d.ts +9 -0
  3. package/dist/add/add-analytics.js +178 -0
  4. package/dist/add/add-auth.js +0 -54
  5. package/dist/add/add-feature-flag.d.ts +2 -0
  6. package/dist/add/add-feature-flag.js +162 -0
  7. package/dist/add/add-wire-addon.js +1 -0
  8. package/dist/add/add-wire-remote-addon.js +1 -0
  9. package/dist/index.d.ts +3 -1
  10. package/dist/index.js +3 -1
  11. package/dist/inspector.js +4 -0
  12. package/dist/surface/collect-surface.d.ts +58 -0
  13. package/dist/surface/collect-surface.js +613 -0
  14. package/dist/types.d.ts +20 -11
  15. package/dist/utils/filter-inspector-state.js +23 -13
  16. package/dist/utils/post-process.js +15 -0
  17. package/dist/utils/read-module-specifiers.d.ts +8 -0
  18. package/dist/utils/read-module-specifiers.js +23 -0
  19. package/dist/utils/read-tsconfig-out-dir.d.ts +5 -0
  20. package/dist/utils/read-tsconfig-out-dir.js +12 -0
  21. package/dist/utils/resolve-deploy-target.d.ts +7 -0
  22. package/dist/utils/resolve-deploy-target.js +15 -7
  23. package/dist/utils/serialize-inspector-state.d.ts +5 -0
  24. package/dist/utils/serialize-inspector-state.js +8 -0
  25. package/dist/visit.js +4 -0
  26. package/package.json +16 -6
  27. package/run-tests.sh +21 -6
  28. package/src/add/add-addon-bans.ts +0 -85
  29. package/src/add/add-agent-scorer.test.ts +0 -197
  30. package/src/add/add-agent-scorer.ts +0 -83
  31. package/src/add/add-agent.test.ts +0 -87
  32. package/src/add/add-agent.ts +0 -638
  33. package/src/add/add-approval-description.ts +0 -76
  34. package/src/add/add-auth.test.ts +0 -791
  35. package/src/add/add-auth.ts +0 -424
  36. package/src/add/add-channel.ts +0 -778
  37. package/src/add/add-cli-renderers.test.ts +0 -74
  38. package/src/add/add-cli.ts +0 -1006
  39. package/src/add/add-credential.ts +0 -186
  40. package/src/add/add-feature.test.ts +0 -306
  41. package/src/add/add-feature.ts +0 -253
  42. package/src/add/add-file-extends-core-type.ts +0 -66
  43. package/src/add/add-file-with-config.ts +0 -45
  44. package/src/add/add-file-with-factory.test.ts +0 -134
  45. package/src/add/add-file-with-factory.ts +0 -288
  46. package/src/add/add-functions.test.ts +0 -743
  47. package/src/add/add-functions.ts +0 -1548
  48. package/src/add/add-gateway.ts +0 -143
  49. package/src/add/add-http-route-ref.test.ts +0 -149
  50. package/src/add/add-http-route.ts +0 -530
  51. package/src/add/add-http-routes.ts +0 -471
  52. package/src/add/add-keyed-wiring.ts +0 -180
  53. package/src/add/add-mcp-prompt.ts +0 -157
  54. package/src/add/add-mcp-resource.ts +0 -175
  55. package/src/add/add-middleware.test.ts +0 -196
  56. package/src/add/add-middleware.ts +0 -879
  57. package/src/add/add-permission-auth.test.ts +0 -59
  58. package/src/add/add-permission.ts +0 -311
  59. package/src/add/add-personas.test.ts +0 -406
  60. package/src/add/add-personas.ts +0 -287
  61. package/src/add/add-queue-worker.ts +0 -117
  62. package/src/add/add-rpc-invocations.test.ts +0 -287
  63. package/src/add/add-rpc-invocations.ts +0 -221
  64. package/src/add/add-scenario-step.test.ts +0 -509
  65. package/src/add/add-schedule.ts +0 -120
  66. package/src/add/add-scope.test.ts +0 -419
  67. package/src/add/add-scope.ts +0 -221
  68. package/src/add/add-secret.ts +0 -10
  69. package/src/add/add-subject-scenario-steps.test.ts +0 -161
  70. package/src/add/add-system-role.test.ts +0 -297
  71. package/src/add/add-system-role.ts +0 -162
  72. package/src/add/add-trigger.ts +0 -165
  73. package/src/add/add-variable.ts +0 -10
  74. package/src/add/add-wire-addon.test.ts +0 -185
  75. package/src/add/add-wire-addon.ts +0 -146
  76. package/src/add/add-wire-remote-addon.ts +0 -80
  77. package/src/add/add-workflow-edge-cases.test.ts +0 -201
  78. package/src/add/add-workflow-fanout.test.ts +0 -166
  79. package/src/add/add-workflow-graph-foreach.test.ts +0 -174
  80. package/src/add/add-workflow-graph-input.test.ts +0 -94
  81. package/src/add/add-workflow-graph-notes.test.ts +0 -74
  82. package/src/add/add-workflow-graph.ts +0 -644
  83. package/src/add/add-workflow-on-error.test.ts +0 -118
  84. package/src/add/add-workflow-return-switch.test.ts +0 -121
  85. package/src/add/add-workflow-silent-drops.test.ts +0 -261
  86. package/src/add/add-workflow-sleep-expression.test.ts +0 -96
  87. package/src/add/add-workflow.test.ts +0 -155
  88. package/src/add/add-workflow.ts +0 -482
  89. package/src/add/addon-bans.test.ts +0 -121
  90. package/src/add/addon-contracts.test.ts +0 -221
  91. package/src/add/allow-escape-hatches.test.ts +0 -144
  92. package/src/add/audit-meta.test.ts +0 -75
  93. package/src/add/classified-sink-check.test.ts +0 -347
  94. package/src/add/config-value-metadata.test.ts +0 -263
  95. package/src/add/dynamic-import-check.test.ts +0 -119
  96. package/src/add/expect-eventually-scenario-only.test.ts +0 -108
  97. package/src/add/function-body-span.test.ts +0 -96
  98. package/src/add/inline-wiring-function.test.ts +0 -104
  99. package/src/add/pii-check.test.ts +0 -258
  100. package/src/add/rpc-type-cast.test.ts +0 -123
  101. package/src/add/scenario-instrumentation.test.ts +0 -89
  102. package/src/add/scenario-instrumentation.ts +0 -42
  103. package/src/add/scenario-marker.test.ts +0 -89
  104. package/src/add/scenario-not-extractable.test.ts +0 -159
  105. package/src/add/scenario-services.test.ts +0 -103
  106. package/src/add/scenario-skip.test.ts +0 -83
  107. package/src/add/validate-workflow-graph-addons.test.ts +0 -102
  108. package/src/add/wire-name-literal.test.ts +0 -117
  109. package/src/error-codes-emitted.test.ts +0 -76
  110. package/src/error-codes.ts +0 -145
  111. package/src/index.ts +0 -66
  112. package/src/inspector.ts +0 -575
  113. package/src/schema-generator.ts +0 -1
  114. package/src/source-file-cache.ts +0 -73
  115. package/src/tsconfig-paths.test.ts +0 -90
  116. package/src/types-map.ts +0 -141
  117. package/src/types.ts +0 -775
  118. package/src/utils/annotate-http-route-auth.test.ts +0 -161
  119. package/src/utils/annotate-http-route-auth.ts +0 -53
  120. package/src/utils/check-classified-sinks.ts +0 -215
  121. package/src/utils/check-pii-output.ts +0 -120
  122. package/src/utils/compute-diagnostics.test.ts +0 -106
  123. package/src/utils/compute-required-schemas.ts +0 -48
  124. package/src/utils/contract-hashes.test.ts +0 -553
  125. package/src/utils/contract-hashes.ts +0 -387
  126. package/src/utils/custom-types-generator.test.ts +0 -124
  127. package/src/utils/custom-types-generator.ts +0 -150
  128. package/src/utils/detect-schema-vendor.test.ts +0 -123
  129. package/src/utils/detect-schema-vendor.ts +0 -120
  130. package/src/utils/does-type-extend-core-type.ts +0 -53
  131. package/src/utils/ensure-function-metadata.ts +0 -385
  132. package/src/utils/extract-function-name.ts +0 -612
  133. package/src/utils/extract-function-node.ts +0 -70
  134. package/src/utils/extract-node-value.test.ts +0 -117
  135. package/src/utils/extract-node-value.ts +0 -172
  136. package/src/utils/extract-secret-usage.test.ts +0 -81
  137. package/src/utils/extract-secret-usage.ts +0 -73
  138. package/src/utils/extract-services.ts +0 -70
  139. package/src/utils/extract-surface-usage.test.ts +0 -147
  140. package/src/utils/extract-surface-usage.ts +0 -121
  141. package/src/utils/filter-inspector-state.test.ts +0 -2207
  142. package/src/utils/filter-inspector-state.ts +0 -1302
  143. package/src/utils/filter-utils.test.ts +0 -843
  144. package/src/utils/filter-utils.ts +0 -161
  145. package/src/utils/find-root-dir.ts +0 -68
  146. package/src/utils/find-zod-transform.test.ts +0 -70
  147. package/src/utils/find-zod-transform.ts +0 -103
  148. package/src/utils/get-exported-variable-name.ts +0 -48
  149. package/src/utils/get-files-and-methods.ts +0 -157
  150. package/src/utils/get-property-value.test.ts +0 -141
  151. package/src/utils/get-property-value.ts +0 -331
  152. package/src/utils/hash.ts +0 -26
  153. package/src/utils/literal-properties.ts +0 -97
  154. package/src/utils/load-addon-functions-meta.test.ts +0 -157
  155. package/src/utils/load-addon-functions-meta.ts +0 -508
  156. package/src/utils/load-addon-scopes.test.ts +0 -138
  157. package/src/utils/middleware.test.ts +0 -204
  158. package/src/utils/middleware.ts +0 -303
  159. package/src/utils/nested-project-filter.test.ts +0 -53
  160. package/src/utils/nested-project-filter.ts +0 -28
  161. package/src/utils/permissions-shorthand.test.ts +0 -79
  162. package/src/utils/permissions.test.ts +0 -125
  163. package/src/utils/permissions.ts +0 -129
  164. package/src/utils/post-process.test.ts +0 -1094
  165. package/src/utils/post-process.ts +0 -1604
  166. package/src/utils/resolve-addon-package.ts +0 -106
  167. package/src/utils/resolve-core-type.test.ts +0 -142
  168. package/src/utils/resolve-core-type.ts +0 -35
  169. package/src/utils/resolve-deploy-target.test.ts +0 -135
  170. package/src/utils/resolve-deploy-target.ts +0 -65
  171. package/src/utils/resolve-function-meta.ts +0 -25
  172. package/src/utils/resolve-function-types.ts +0 -42
  173. package/src/utils/resolve-identifier.ts +0 -46
  174. package/src/utils/resolve-ref-contract.ts +0 -71
  175. package/src/utils/resolve-versions.test.ts +0 -499
  176. package/src/utils/resolve-versions.ts +0 -228
  177. package/src/utils/schema-cache.test.ts +0 -124
  178. package/src/utils/schema-generator.test.ts +0 -272
  179. package/src/utils/schema-generator.ts +0 -780
  180. package/src/utils/secret-alias-services.test.ts +0 -146
  181. package/src/utils/secret-alias-services.ts +0 -58
  182. package/src/utils/serialize-inspector-state.ts +0 -742
  183. package/src/utils/serialize-mcp-json.ts +0 -150
  184. package/src/utils/serialize-middleware-groups-meta.ts +0 -36
  185. package/src/utils/serialize-openapi-json.ts +0 -277
  186. package/src/utils/serialize-permissions-groups-meta.ts +0 -7
  187. package/src/utils/single-declaration.ts +0 -57
  188. package/src/utils/type-utils.ts +0 -145
  189. package/src/utils/validate-auth-sessionless.ts +0 -30
  190. package/src/utils/validate-exposed-functions-gated.test.ts +0 -230
  191. package/src/utils/validate-exposed-functions-gated.ts +0 -103
  192. package/src/utils/validate-tags-resolve-to-middleware.test.ts +0 -108
  193. package/src/utils/validate-tags-resolve-to-middleware.ts +0 -48
  194. package/src/utils/workflow/derive-workflow-plan.test.ts +0 -178
  195. package/src/utils/workflow/derive-workflow-plan.ts +0 -117
  196. package/src/utils/workflow/dsl/deserialize-dsl-workflow.ts +0 -1465
  197. package/src/utils/workflow/dsl/deserialize-fanout-body.test.ts +0 -71
  198. package/src/utils/workflow/dsl/deserialize-fanout-fidelity.test.ts +0 -99
  199. package/src/utils/workflow/dsl/deserialize-graph-next.test.ts +0 -161
  200. package/src/utils/workflow/dsl/deserialize-roundtrip-bindings.test.ts +0 -121
  201. package/src/utils/workflow/dsl/deserialize-roundtrip-values.test.ts +0 -116
  202. package/src/utils/workflow/dsl/deserialize-roundtrip.test.ts +0 -145
  203. package/src/utils/workflow/dsl/extract-approval-policy.test.ts +0 -71
  204. package/src/utils/workflow/dsl/extract-dsl-workflow.ts +0 -2254
  205. package/src/utils/workflow/dsl/index.ts +0 -11
  206. package/src/utils/workflow/dsl/patterns.ts +0 -440
  207. package/src/utils/workflow/dsl/validation.ts +0 -203
  208. package/src/utils/workflow/graph/convert-dsl-to-graph-skip.test.ts +0 -35
  209. package/src/utils/workflow/graph/convert-dsl-to-graph.ts +0 -543
  210. package/src/utils/workflow/graph/fanout-node-identity.test.ts +0 -105
  211. package/src/utils/workflow/graph/finalize-workflow-wires.ts +0 -310
  212. package/src/utils/workflow/graph/finalize-workflows.test.ts +0 -50
  213. package/src/utils/workflow/graph/finalize-workflows.ts +0 -130
  214. package/src/utils/workflow/graph/index.ts +0 -28
  215. package/src/utils/workflow/graph/serialize-workflow-graph.ts +0 -240
  216. package/src/utils/workflow/graph/workflow-graph.types.ts +0 -281
  217. package/src/visit.ts +0 -181
  218. package/tsconfig.json +0 -19
  219. package/tsconfig.tsbuildinfo +0 -1
@@ -1,471 +0,0 @@
1
- import * as ts from 'typescript'
2
- import { getPropertyValue } from '../utils/get-property-value.js'
3
- import type {
4
- AddWiring,
5
- ExportedHTTPRouteConfigMeta,
6
- ExportedHTTPRouteMapMeta,
7
- ExportedHTTPRoutesGroupMeta,
8
- InspectorLogger,
9
- InspectorState,
10
- } from '../types.js'
11
- import { registerHTTPRoute, registerHTTPRouteMeta } from './add-http-route.js'
12
- import { resolveIdentifier } from '../utils/resolve-identifier.js'
13
- import { extractFunctionName } from '../utils/extract-function-name.js'
14
- import { getPropertyAssignmentInitializer } from '../utils/type-utils.js'
15
- import { resolveAddonName } from '../utils/resolve-addon-package.js'
16
- import {
17
- resolveRefContract,
18
- type RefContractResolution,
19
- } from '../utils/resolve-ref-contract.js'
20
- import { getExportedVariableName } from '../utils/get-exported-variable-name.js'
21
-
22
- interface GroupConfig {
23
- basePath: string
24
- tags: string[]
25
- auth?: boolean
26
- }
27
-
28
- export const addHTTPRoutes: AddWiring = (
29
- logger,
30
- node,
31
- checker,
32
- state,
33
- options
34
- ) => {
35
- if (!ts.isCallExpression(node)) return
36
-
37
- const { expression, arguments: args } = node
38
- if (!ts.isIdentifier(expression)) return
39
-
40
- if (expression.text === 'defineHTTPRoutes') {
41
- const exportName = getExportedVariableName(node, options.sourceFile)
42
- const firstArg = args[0]
43
- if (exportName && firstArg && ts.isObjectLiteralExpression(firstArg)) {
44
- const contract = serializeHTTPRoutesContract(firstArg, checker, state)
45
- if (contract) {
46
- state.exportedContracts.http[exportName] = contract
47
- }
48
- }
49
- return
50
- }
51
-
52
- if (expression.text !== 'wireHTTPRoutes') return
53
-
54
- const firstArg = args[0]
55
- if (!firstArg || !ts.isObjectLiteralExpression(firstArg)) return
56
-
57
- const groupConfig = extractGroupConfig(firstArg)
58
- const routesProp = getPropertyAssignment(firstArg, 'routes')
59
- if (!routesProp) return
60
-
61
- processRoutes(
62
- routesProp.initializer,
63
- groupConfig,
64
- state,
65
- checker,
66
- logger,
67
- node.getSourceFile()
68
- )
69
- }
70
-
71
- function getPropertyAssignment(
72
- obj: ts.ObjectLiteralExpression,
73
- propName: string
74
- ): ts.PropertyAssignment | undefined {
75
- for (const prop of obj.properties) {
76
- if (
77
- ts.isPropertyAssignment(prop) &&
78
- ts.isIdentifier(prop.name) &&
79
- prop.name.text === propName
80
- ) {
81
- return prop
82
- }
83
- }
84
- return undefined
85
- }
86
-
87
- function extractGroupConfig(obj: ts.ObjectLiteralExpression): GroupConfig {
88
- const basePath = (getPropertyValue(obj, 'basePath') as string) || ''
89
- const tags = (getPropertyValue(obj, 'tags') as string[]) || []
90
- const auth = getPropertyValue(obj, 'auth')
91
-
92
- return {
93
- basePath,
94
- tags,
95
- auth: auth === true ? true : auth === false ? false : undefined,
96
- }
97
- }
98
-
99
- function mergeConfigs(parent: GroupConfig, child: GroupConfig): GroupConfig {
100
- return {
101
- basePath: parent.basePath + child.basePath,
102
- tags: [...parent.tags, ...child.tags],
103
- auth: child.auth ?? parent.auth,
104
- }
105
- }
106
-
107
- function isRouteConfig(obj: ts.ObjectLiteralExpression): boolean {
108
- let hasMethod = false
109
- let hasFunc = false
110
- let hasRoute = false
111
-
112
- for (const prop of obj.properties) {
113
- if (ts.isPropertyAssignment(prop) && ts.isIdentifier(prop.name)) {
114
- if (prop.name.text === 'method') hasMethod = true
115
- if (prop.name.text === 'func') hasFunc = true
116
- if (prop.name.text === 'route') hasRoute = true
117
- }
118
- }
119
-
120
- return hasMethod && hasFunc && hasRoute
121
- }
122
-
123
- function isRouteContract(obj: ts.ObjectLiteralExpression): boolean {
124
- let hasRoutes = false
125
- let hasMethod = false
126
- let hasFunc = false
127
-
128
- for (const prop of obj.properties) {
129
- if (ts.isPropertyAssignment(prop) && ts.isIdentifier(prop.name)) {
130
- if (prop.name.text === 'routes') hasRoutes = true
131
- if (prop.name.text === 'method') hasMethod = true
132
- if (prop.name.text === 'func') hasFunc = true
133
- }
134
- }
135
-
136
- return hasRoutes && !hasMethod && !hasFunc
137
- }
138
-
139
- function processRoutes(
140
- node: ts.Node,
141
- parentConfig: GroupConfig,
142
- state: InspectorState,
143
- checker: ts.TypeChecker,
144
- logger: InspectorLogger,
145
- sourceFile: ts.SourceFile
146
- ): void {
147
- if (ts.isArrayLiteralExpression(node)) {
148
- for (const element of node.elements) {
149
- if (ts.isObjectLiteralExpression(element) && isRouteConfig(element)) {
150
- processRoute(element, parentConfig, state, checker, logger, sourceFile)
151
- }
152
- }
153
- return
154
- }
155
-
156
- if (ts.isObjectLiteralExpression(node)) {
157
- if (isRouteConfig(node)) {
158
- processRoute(node, parentConfig, state, checker, logger, sourceFile)
159
- return
160
- }
161
-
162
- if (isRouteContract(node)) {
163
- const contractConfig = extractGroupConfig(node)
164
- const mergedConfig = mergeConfigs(parentConfig, contractConfig)
165
- const routesProp = getPropertyAssignment(node, 'routes')
166
- if (routesProp) {
167
- processRoutes(
168
- routesProp.initializer,
169
- mergedConfig,
170
- state,
171
- checker,
172
- logger,
173
- sourceFile
174
- )
175
- }
176
- return
177
- }
178
-
179
- for (const prop of node.properties) {
180
- if (ts.isPropertyAssignment(prop)) {
181
- const ref = resolveRefContract(
182
- prop.initializer,
183
- 'refHTTP',
184
- state.exportedContracts.addonHttp
185
- )
186
- if (ref) {
187
- processRefHTTPContract(ref, parentConfig, state, logger, sourceFile)
188
- continue
189
- }
190
- processRoutes(
191
- prop.initializer,
192
- parentConfig,
193
- state,
194
- checker,
195
- logger,
196
- sourceFile
197
- )
198
- }
199
- }
200
- return
201
- }
202
-
203
- if (ts.isCallExpression(node)) {
204
- const ref = resolveRefContract(
205
- node,
206
- 'refHTTP',
207
- state.exportedContracts.addonHttp
208
- )
209
- if (ref) {
210
- processRefHTTPContract(ref, parentConfig, state, logger, sourceFile)
211
- }
212
- return
213
- }
214
-
215
- if (ts.isIdentifier(node)) {
216
- const resolved = resolveIdentifier(node, checker, ['defineHTTPRoutes'])
217
- if (resolved) {
218
- processRoutes(resolved, parentConfig, state, checker, logger, sourceFile)
219
- }
220
- }
221
- }
222
-
223
- function processRefHTTPContract(
224
- ref: RefContractResolution<ExportedHTTPRoutesGroupMeta>,
225
- parentConfig: GroupConfig,
226
- state: InspectorState,
227
- logger: InspectorLogger,
228
- sourceFile: ts.SourceFile
229
- ): void {
230
- const basePath =
231
- ref.basePath !== undefined ? ref.basePath : ref.contract.basePath || ''
232
- processExportedRouteMap(
233
- ref.contract.routes,
234
- mergeConfigs(parentConfig, {
235
- basePath,
236
- tags: ref.contract.tags || [],
237
- auth: ref.contract.auth,
238
- }),
239
- state,
240
- logger,
241
- sourceFile
242
- )
243
- }
244
-
245
- function processExportedRouteMap(
246
- routes: ExportedHTTPRouteMapMeta,
247
- parentConfig: GroupConfig,
248
- state: InspectorState,
249
- logger: InspectorLogger,
250
- sourceFile: ts.SourceFile
251
- ): void {
252
- for (const value of Object.values(routes)) {
253
- if (isExportedRouteConfig(value)) {
254
- registerHTTPRouteMeta({
255
- route: value,
256
- state,
257
- logger,
258
- sourceFile,
259
- basePath: parentConfig.basePath,
260
- inheritedTags: parentConfig.tags,
261
- inheritedAuth: parentConfig.auth,
262
- })
263
- continue
264
- }
265
-
266
- if (isExportedRouteContract(value)) {
267
- processExportedRouteMap(
268
- value.routes,
269
- mergeConfigs(parentConfig, {
270
- basePath: value.basePath || '',
271
- tags: value.tags || [],
272
- auth: value.auth,
273
- }),
274
- state,
275
- logger,
276
- sourceFile
277
- )
278
- continue
279
- }
280
-
281
- processExportedRouteMap(value, parentConfig, state, logger, sourceFile)
282
- }
283
- }
284
-
285
- function isExportedRouteConfig(
286
- value: ExportedHTTPRouteMapMeta[string]
287
- ): value is ExportedHTTPRouteConfigMeta {
288
- return (
289
- typeof value === 'object' &&
290
- value !== null &&
291
- 'method' in value &&
292
- 'route' in value &&
293
- 'func' in value
294
- )
295
- }
296
-
297
- function isExportedRouteContract(
298
- value: ExportedHTTPRouteMapMeta[string]
299
- ): value is ExportedHTTPRoutesGroupMeta {
300
- return (
301
- typeof value === 'object' &&
302
- value !== null &&
303
- 'routes' in value &&
304
- !('method' in value)
305
- )
306
- }
307
-
308
- function serializeHTTPRoutesContract(
309
- node: ts.ObjectLiteralExpression,
310
- checker: ts.TypeChecker,
311
- state: InspectorState
312
- ): ExportedHTTPRoutesGroupMeta | null {
313
- if (isRouteContract(node)) {
314
- const routesProp = getPropertyAssignment(node, 'routes')
315
- if (!routesProp || !ts.isObjectLiteralExpression(routesProp.initializer)) {
316
- return null
317
- }
318
-
319
- return {
320
- ...extractGroupConfig(node),
321
- routes: serializeHTTPRouteMap(routesProp.initializer, checker, state),
322
- }
323
- }
324
-
325
- return {
326
- routes: serializeHTTPRouteMap(node, checker, state),
327
- }
328
- }
329
-
330
- function serializeHTTPRouteMap(
331
- node: ts.ObjectLiteralExpression,
332
- checker: ts.TypeChecker,
333
- state: InspectorState
334
- ): ExportedHTTPRouteMapMeta {
335
- const result: ExportedHTTPRouteMapMeta = {}
336
-
337
- for (const prop of node.properties) {
338
- if (!ts.isPropertyAssignment(prop)) continue
339
-
340
- const key = prop.name.getText().replace(/^['"]|['"]$/g, '')
341
- const value = prop.initializer
342
-
343
- if (ts.isObjectLiteralExpression(value)) {
344
- if (isRouteConfig(value)) {
345
- const route = serializeHTTPRouteConfig(value, checker, state)
346
- if (route) {
347
- result[key] = route
348
- }
349
- continue
350
- }
351
-
352
- if (isRouteContract(value)) {
353
- const routeContract = serializeHTTPRoutesContract(value, checker, state)
354
- if (routeContract) {
355
- result[key] = routeContract
356
- }
357
- continue
358
- }
359
-
360
- result[key] = serializeHTTPRouteMap(value, checker, state)
361
- continue
362
- }
363
-
364
- if (ts.isIdentifier(value)) {
365
- const resolved = resolveIdentifier(value, checker, ['defineHTTPRoutes'])
366
- if (resolved && ts.isObjectLiteralExpression(resolved)) {
367
- if (isRouteContract(resolved)) {
368
- const routeContract = serializeHTTPRoutesContract(
369
- resolved,
370
- checker,
371
- state
372
- )
373
- if (routeContract) {
374
- result[key] = routeContract
375
- }
376
- } else {
377
- result[key] = serializeHTTPRouteMap(resolved, checker, state)
378
- }
379
- }
380
- }
381
- }
382
-
383
- return result
384
- }
385
-
386
- function serializeHTTPRouteConfig(
387
- obj: ts.ObjectLiteralExpression,
388
- checker: ts.TypeChecker,
389
- state: InspectorState
390
- ): ExportedHTTPRouteConfigMeta | null {
391
- const method = getPropertyValue(obj, 'method') as string | null
392
- const route = getPropertyValue(obj, 'route') as string | null
393
- const funcInitializer = getPropertyAssignmentInitializer(
394
- obj,
395
- 'func',
396
- true,
397
- checker
398
- )
399
-
400
- if (!method || !route || !funcInitializer) {
401
- return null
402
- }
403
-
404
- let pikkuFuncId = extractFunctionName(
405
- funcInitializer,
406
- checker,
407
- state.rootDir
408
- ).pikkuFuncId
409
- let packageName: string | undefined
410
-
411
- if (
412
- ts.isCallExpression(funcInitializer) &&
413
- ts.isIdentifier(funcInitializer.expression) &&
414
- funcInitializer.expression.text === 'ref'
415
- ) {
416
- const [firstArg] = funcInitializer.arguments
417
- if (firstArg && ts.isStringLiteral(firstArg)) {
418
- pikkuFuncId = firstArg.text
419
- const addonNamespace = pikkuFuncId.includes(':')
420
- ? pikkuFuncId.split(':')[0]
421
- : null
422
- packageName = addonNamespace
423
- ? state.rpc.wireAddonDeclarations.get(addonNamespace)?.package
424
- : undefined
425
- }
426
- } else if (ts.isIdentifier(funcInitializer)) {
427
- packageName =
428
- resolveAddonName(
429
- funcInitializer,
430
- checker,
431
- state.rpc.wireAddonDeclarations
432
- ) || undefined
433
- }
434
-
435
- return {
436
- auth: getPropertyValue(obj, 'auth') as boolean | undefined,
437
- contentType: getPropertyValue(obj, 'contentType') as string | undefined,
438
- headers:
439
- (getPropertyValue(obj, 'headers') as unknown as Record<string, string>) ||
440
- undefined,
441
- method,
442
- route,
443
- sse: getPropertyValue(obj, 'sse') as boolean | undefined,
444
- tags: (getPropertyValue(obj, 'tags') as string[]) || undefined,
445
- timeout: getPropertyValue(obj, 'timeout') as number | undefined,
446
- func: {
447
- pikkuFuncId,
448
- ...(packageName && { packageName }),
449
- },
450
- }
451
- }
452
-
453
- function processRoute(
454
- obj: ts.ObjectLiteralExpression,
455
- groupConfig: GroupConfig,
456
- state: InspectorState,
457
- checker: ts.TypeChecker,
458
- logger: InspectorLogger,
459
- sourceFile: ts.SourceFile
460
- ): void {
461
- registerHTTPRoute({
462
- obj,
463
- state,
464
- checker,
465
- logger,
466
- sourceFile,
467
- basePath: groupConfig.basePath,
468
- inheritedTags: groupConfig.tags,
469
- inheritedAuth: groupConfig.auth,
470
- })
471
- }
@@ -1,180 +0,0 @@
1
- import * as ts from 'typescript'
2
- import {
3
- getPropertyValue,
4
- getArrayPropertyValue,
5
- assertStringLiteralProperty,
6
- } from '../utils/get-property-value.js'
7
- import type { AddWiring, InspectorState } from '../types.js'
8
- import { ErrorCode } from '../error-codes.js'
9
- import { detectSchemaVendorOrError } from '../utils/detect-schema-vendor.js'
10
- import { parseDurationString } from '@pikku/core/utils'
11
-
12
- export interface KeyedWiringConfig {
13
- functionName: string
14
- idField: string
15
- label: string
16
- schemaPrefix: string
17
- /** Boolean property carrying this wiring kind's deploy-gate opt-in/opt-out. */
18
- flagField: string
19
- getState: (state: InspectorState) => {
20
- definitions: any[]
21
- files: Set<string>
22
- }
23
- }
24
-
25
- export const createAddKeyedWiring = (config: KeyedWiringConfig): AddWiring => {
26
- return (logger, node, checker, state, _options) => {
27
- if (!ts.isCallExpression(node)) {
28
- return
29
- }
30
-
31
- const args = node.arguments
32
- const firstArg = args[0]
33
- const expression = node.expression
34
-
35
- if (
36
- !ts.isIdentifier(expression) ||
37
- expression.text !== config.functionName
38
- ) {
39
- return
40
- }
41
-
42
- if (!firstArg) {
43
- return
44
- }
45
-
46
- if (ts.isObjectLiteralExpression(firstArg)) {
47
- const obj = firstArg
48
-
49
- assertStringLiteralProperty(obj, 'name', config.label, logger)
50
- assertStringLiteralProperty(obj, config.idField, config.label, logger)
51
-
52
- const nameValue = getPropertyValue(obj, 'name') as string | null
53
- const displayNameValue = getPropertyValue(obj, 'displayName') as
54
- string | null
55
- const descriptionValue = getPropertyValue(obj, 'description') as
56
- string | null
57
- const rotationPeriodValue = getPropertyValue(obj, 'rotationPeriod') as
58
- string | null
59
- const docsUrlValue = getPropertyValue(obj, 'docsUrl') as string | null
60
- const allowedHostsValue = getArrayPropertyValue(obj, 'allowedHosts')
61
- const idValue = getPropertyValue(obj, config.idField) as string | null
62
- const flagValue = getPropertyValue(obj, config.flagField) === true
63
-
64
- let schemaVariableName: string | null = null
65
- let schemaSourceFile: string | null = null
66
- let schemaIdentifier: ts.Identifier | null = null
67
- for (const prop of obj.properties) {
68
- if (
69
- ts.isPropertyAssignment(prop) &&
70
- ts.isIdentifier(prop.name) &&
71
- prop.name.text === 'schema'
72
- ) {
73
- if (ts.isIdentifier(prop.initializer)) {
74
- schemaVariableName = prop.initializer.text
75
- schemaIdentifier = prop.initializer
76
-
77
- const symbol = checker.getSymbolAtLocation(prop.initializer)
78
- if (symbol) {
79
- const decl = symbol.valueDeclaration || symbol.declarations?.[0]
80
- if (decl) {
81
- if (ts.isImportSpecifier(decl)) {
82
- const aliasedSymbol = checker.getAliasedSymbol(symbol)
83
- if (aliasedSymbol) {
84
- const aliasedDecl =
85
- aliasedSymbol.valueDeclaration ||
86
- aliasedSymbol.declarations?.[0]
87
- if (aliasedDecl) {
88
- schemaSourceFile = aliasedDecl.getSourceFile().fileName
89
- }
90
- }
91
- } else {
92
- schemaSourceFile = decl.getSourceFile().fileName
93
- }
94
- }
95
- }
96
- }
97
- break
98
- }
99
- }
100
-
101
- if (!nameValue) {
102
- logger.critical(
103
- ErrorCode.MISSING_NAME,
104
- `${config.label} is missing the required 'name' property.`
105
- )
106
- return
107
- }
108
-
109
- if (!displayNameValue) {
110
- logger.critical(
111
- ErrorCode.MISSING_NAME,
112
- `${config.label} '${nameValue}' is missing the required 'displayName' property.`
113
- )
114
- return
115
- }
116
-
117
- if (!idValue) {
118
- logger.critical(
119
- ErrorCode.MISSING_NAME,
120
- `${config.label} '${nameValue}' is missing the required '${config.idField}' property.`
121
- )
122
- return
123
- }
124
-
125
- if (!schemaVariableName || !schemaSourceFile || !schemaIdentifier) {
126
- logger.critical(
127
- ErrorCode.MISSING_NAME,
128
- `${config.label} '${nameValue}' is missing the required 'schema' property or schema is not a variable reference.`
129
- )
130
- return
131
- }
132
-
133
- if (rotationPeriodValue) {
134
- try {
135
- parseDurationString(rotationPeriodValue)
136
- } catch {
137
- logger.critical(
138
- ErrorCode.INVALID_VALUE,
139
- `${config.label} '${nameValue}' has an invalid 'rotationPeriod': '${rotationPeriodValue}'. Use a duration like '1d', '30day', or '1w'.`
140
- )
141
- return
142
- }
143
- }
144
-
145
- const sourceFile = node.getSourceFile().fileName
146
-
147
- const wiringState = config.getState(state)
148
- wiringState.files.add(sourceFile)
149
-
150
- const vendor = detectSchemaVendorOrError(
151
- schemaIdentifier,
152
- checker,
153
- logger,
154
- `${config.label} '${nameValue}'`,
155
- schemaSourceFile
156
- )
157
- if (!vendor) return
158
-
159
- const schemaLookupName = `${config.schemaPrefix}_${nameValue}`
160
- state.schemaLookup.set(schemaLookupName, {
161
- variableName: schemaVariableName,
162
- sourceFile: schemaSourceFile,
163
- vendor,
164
- })
165
-
166
- wiringState.definitions.push({
167
- name: nameValue,
168
- displayName: displayNameValue,
169
- description: descriptionValue || undefined,
170
- rotationPeriod: rotationPeriodValue || undefined,
171
- docsUrl: docsUrlValue || undefined,
172
- allowedHosts: allowedHostsValue || undefined,
173
- [config.idField]: idValue,
174
- [config.flagField]: flagValue || undefined,
175
- schema: schemaLookupName,
176
- sourceFile,
177
- })
178
- }
179
- }
180
- }