@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.
- package/CHANGELOG.md +347 -0
- package/dist/add/add-analytics.d.ts +9 -0
- package/dist/add/add-analytics.js +178 -0
- package/dist/add/add-auth.js +0 -54
- package/dist/add/add-feature-flag.d.ts +2 -0
- package/dist/add/add-feature-flag.js +162 -0
- package/dist/add/add-wire-addon.js +1 -0
- package/dist/add/add-wire-remote-addon.js +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/inspector.js +4 -0
- package/dist/surface/collect-surface.d.ts +58 -0
- package/dist/surface/collect-surface.js +613 -0
- package/dist/types.d.ts +20 -11
- package/dist/utils/filter-inspector-state.js +23 -13
- package/dist/utils/post-process.js +15 -0
- package/dist/utils/read-module-specifiers.d.ts +8 -0
- package/dist/utils/read-module-specifiers.js +23 -0
- package/dist/utils/read-tsconfig-out-dir.d.ts +5 -0
- package/dist/utils/read-tsconfig-out-dir.js +12 -0
- package/dist/utils/resolve-deploy-target.d.ts +7 -0
- package/dist/utils/resolve-deploy-target.js +15 -7
- package/dist/utils/serialize-inspector-state.d.ts +5 -0
- package/dist/utils/serialize-inspector-state.js +8 -0
- package/dist/visit.js +4 -0
- package/package.json +16 -6
- package/run-tests.sh +21 -6
- package/src/add/add-addon-bans.ts +0 -85
- package/src/add/add-agent-scorer.test.ts +0 -197
- package/src/add/add-agent-scorer.ts +0 -83
- package/src/add/add-agent.test.ts +0 -87
- package/src/add/add-agent.ts +0 -638
- package/src/add/add-approval-description.ts +0 -76
- package/src/add/add-auth.test.ts +0 -791
- package/src/add/add-auth.ts +0 -424
- package/src/add/add-channel.ts +0 -778
- package/src/add/add-cli-renderers.test.ts +0 -74
- package/src/add/add-cli.ts +0 -1006
- package/src/add/add-credential.ts +0 -186
- package/src/add/add-feature.test.ts +0 -306
- package/src/add/add-feature.ts +0 -253
- package/src/add/add-file-extends-core-type.ts +0 -66
- package/src/add/add-file-with-config.ts +0 -45
- package/src/add/add-file-with-factory.test.ts +0 -134
- package/src/add/add-file-with-factory.ts +0 -288
- package/src/add/add-functions.test.ts +0 -743
- package/src/add/add-functions.ts +0 -1548
- package/src/add/add-gateway.ts +0 -143
- package/src/add/add-http-route-ref.test.ts +0 -149
- package/src/add/add-http-route.ts +0 -530
- package/src/add/add-http-routes.ts +0 -471
- package/src/add/add-keyed-wiring.ts +0 -180
- package/src/add/add-mcp-prompt.ts +0 -157
- package/src/add/add-mcp-resource.ts +0 -175
- package/src/add/add-middleware.test.ts +0 -196
- package/src/add/add-middleware.ts +0 -879
- package/src/add/add-permission-auth.test.ts +0 -59
- package/src/add/add-permission.ts +0 -311
- package/src/add/add-personas.test.ts +0 -406
- package/src/add/add-personas.ts +0 -287
- package/src/add/add-queue-worker.ts +0 -117
- package/src/add/add-rpc-invocations.test.ts +0 -287
- package/src/add/add-rpc-invocations.ts +0 -221
- package/src/add/add-scenario-step.test.ts +0 -509
- package/src/add/add-schedule.ts +0 -120
- package/src/add/add-scope.test.ts +0 -419
- package/src/add/add-scope.ts +0 -221
- package/src/add/add-secret.ts +0 -10
- package/src/add/add-subject-scenario-steps.test.ts +0 -161
- package/src/add/add-system-role.test.ts +0 -297
- package/src/add/add-system-role.ts +0 -162
- package/src/add/add-trigger.ts +0 -165
- package/src/add/add-variable.ts +0 -10
- package/src/add/add-wire-addon.test.ts +0 -185
- package/src/add/add-wire-addon.ts +0 -146
- package/src/add/add-wire-remote-addon.ts +0 -80
- package/src/add/add-workflow-edge-cases.test.ts +0 -201
- package/src/add/add-workflow-fanout.test.ts +0 -166
- package/src/add/add-workflow-graph-foreach.test.ts +0 -174
- package/src/add/add-workflow-graph-input.test.ts +0 -94
- package/src/add/add-workflow-graph-notes.test.ts +0 -74
- package/src/add/add-workflow-graph.ts +0 -644
- package/src/add/add-workflow-on-error.test.ts +0 -118
- package/src/add/add-workflow-return-switch.test.ts +0 -121
- package/src/add/add-workflow-silent-drops.test.ts +0 -261
- package/src/add/add-workflow-sleep-expression.test.ts +0 -96
- package/src/add/add-workflow.test.ts +0 -155
- package/src/add/add-workflow.ts +0 -482
- package/src/add/addon-bans.test.ts +0 -121
- package/src/add/addon-contracts.test.ts +0 -221
- package/src/add/allow-escape-hatches.test.ts +0 -144
- package/src/add/audit-meta.test.ts +0 -75
- package/src/add/classified-sink-check.test.ts +0 -347
- package/src/add/config-value-metadata.test.ts +0 -263
- package/src/add/dynamic-import-check.test.ts +0 -119
- package/src/add/expect-eventually-scenario-only.test.ts +0 -108
- package/src/add/function-body-span.test.ts +0 -96
- package/src/add/inline-wiring-function.test.ts +0 -104
- package/src/add/pii-check.test.ts +0 -258
- package/src/add/rpc-type-cast.test.ts +0 -123
- package/src/add/scenario-instrumentation.test.ts +0 -89
- package/src/add/scenario-instrumentation.ts +0 -42
- package/src/add/scenario-marker.test.ts +0 -89
- package/src/add/scenario-not-extractable.test.ts +0 -159
- package/src/add/scenario-services.test.ts +0 -103
- package/src/add/scenario-skip.test.ts +0 -83
- package/src/add/validate-workflow-graph-addons.test.ts +0 -102
- package/src/add/wire-name-literal.test.ts +0 -117
- package/src/error-codes-emitted.test.ts +0 -76
- package/src/error-codes.ts +0 -145
- package/src/index.ts +0 -66
- package/src/inspector.ts +0 -575
- package/src/schema-generator.ts +0 -1
- package/src/source-file-cache.ts +0 -73
- package/src/tsconfig-paths.test.ts +0 -90
- package/src/types-map.ts +0 -141
- package/src/types.ts +0 -775
- package/src/utils/annotate-http-route-auth.test.ts +0 -161
- package/src/utils/annotate-http-route-auth.ts +0 -53
- package/src/utils/check-classified-sinks.ts +0 -215
- package/src/utils/check-pii-output.ts +0 -120
- package/src/utils/compute-diagnostics.test.ts +0 -106
- package/src/utils/compute-required-schemas.ts +0 -48
- package/src/utils/contract-hashes.test.ts +0 -553
- package/src/utils/contract-hashes.ts +0 -387
- package/src/utils/custom-types-generator.test.ts +0 -124
- package/src/utils/custom-types-generator.ts +0 -150
- package/src/utils/detect-schema-vendor.test.ts +0 -123
- package/src/utils/detect-schema-vendor.ts +0 -120
- package/src/utils/does-type-extend-core-type.ts +0 -53
- package/src/utils/ensure-function-metadata.ts +0 -385
- package/src/utils/extract-function-name.ts +0 -612
- package/src/utils/extract-function-node.ts +0 -70
- package/src/utils/extract-node-value.test.ts +0 -117
- package/src/utils/extract-node-value.ts +0 -172
- package/src/utils/extract-secret-usage.test.ts +0 -81
- package/src/utils/extract-secret-usage.ts +0 -73
- package/src/utils/extract-services.ts +0 -70
- package/src/utils/extract-surface-usage.test.ts +0 -147
- package/src/utils/extract-surface-usage.ts +0 -121
- package/src/utils/filter-inspector-state.test.ts +0 -2207
- package/src/utils/filter-inspector-state.ts +0 -1302
- package/src/utils/filter-utils.test.ts +0 -843
- package/src/utils/filter-utils.ts +0 -161
- package/src/utils/find-root-dir.ts +0 -68
- package/src/utils/find-zod-transform.test.ts +0 -70
- package/src/utils/find-zod-transform.ts +0 -103
- package/src/utils/get-exported-variable-name.ts +0 -48
- package/src/utils/get-files-and-methods.ts +0 -157
- package/src/utils/get-property-value.test.ts +0 -141
- package/src/utils/get-property-value.ts +0 -331
- package/src/utils/hash.ts +0 -26
- package/src/utils/literal-properties.ts +0 -97
- package/src/utils/load-addon-functions-meta.test.ts +0 -157
- package/src/utils/load-addon-functions-meta.ts +0 -508
- package/src/utils/load-addon-scopes.test.ts +0 -138
- package/src/utils/middleware.test.ts +0 -204
- package/src/utils/middleware.ts +0 -303
- package/src/utils/nested-project-filter.test.ts +0 -53
- package/src/utils/nested-project-filter.ts +0 -28
- package/src/utils/permissions-shorthand.test.ts +0 -79
- package/src/utils/permissions.test.ts +0 -125
- package/src/utils/permissions.ts +0 -129
- package/src/utils/post-process.test.ts +0 -1094
- package/src/utils/post-process.ts +0 -1604
- package/src/utils/resolve-addon-package.ts +0 -106
- package/src/utils/resolve-core-type.test.ts +0 -142
- package/src/utils/resolve-core-type.ts +0 -35
- package/src/utils/resolve-deploy-target.test.ts +0 -135
- package/src/utils/resolve-deploy-target.ts +0 -65
- package/src/utils/resolve-function-meta.ts +0 -25
- package/src/utils/resolve-function-types.ts +0 -42
- package/src/utils/resolve-identifier.ts +0 -46
- package/src/utils/resolve-ref-contract.ts +0 -71
- package/src/utils/resolve-versions.test.ts +0 -499
- package/src/utils/resolve-versions.ts +0 -228
- package/src/utils/schema-cache.test.ts +0 -124
- package/src/utils/schema-generator.test.ts +0 -272
- package/src/utils/schema-generator.ts +0 -780
- package/src/utils/secret-alias-services.test.ts +0 -146
- package/src/utils/secret-alias-services.ts +0 -58
- package/src/utils/serialize-inspector-state.ts +0 -742
- package/src/utils/serialize-mcp-json.ts +0 -150
- package/src/utils/serialize-middleware-groups-meta.ts +0 -36
- package/src/utils/serialize-openapi-json.ts +0 -277
- package/src/utils/serialize-permissions-groups-meta.ts +0 -7
- package/src/utils/single-declaration.ts +0 -57
- package/src/utils/type-utils.ts +0 -145
- package/src/utils/validate-auth-sessionless.ts +0 -30
- package/src/utils/validate-exposed-functions-gated.test.ts +0 -230
- package/src/utils/validate-exposed-functions-gated.ts +0 -103
- package/src/utils/validate-tags-resolve-to-middleware.test.ts +0 -108
- package/src/utils/validate-tags-resolve-to-middleware.ts +0 -48
- package/src/utils/workflow/derive-workflow-plan.test.ts +0 -178
- package/src/utils/workflow/derive-workflow-plan.ts +0 -117
- package/src/utils/workflow/dsl/deserialize-dsl-workflow.ts +0 -1465
- package/src/utils/workflow/dsl/deserialize-fanout-body.test.ts +0 -71
- package/src/utils/workflow/dsl/deserialize-fanout-fidelity.test.ts +0 -99
- package/src/utils/workflow/dsl/deserialize-graph-next.test.ts +0 -161
- package/src/utils/workflow/dsl/deserialize-roundtrip-bindings.test.ts +0 -121
- package/src/utils/workflow/dsl/deserialize-roundtrip-values.test.ts +0 -116
- package/src/utils/workflow/dsl/deserialize-roundtrip.test.ts +0 -145
- package/src/utils/workflow/dsl/extract-approval-policy.test.ts +0 -71
- package/src/utils/workflow/dsl/extract-dsl-workflow.ts +0 -2254
- package/src/utils/workflow/dsl/index.ts +0 -11
- package/src/utils/workflow/dsl/patterns.ts +0 -440
- package/src/utils/workflow/dsl/validation.ts +0 -203
- package/src/utils/workflow/graph/convert-dsl-to-graph-skip.test.ts +0 -35
- package/src/utils/workflow/graph/convert-dsl-to-graph.ts +0 -543
- package/src/utils/workflow/graph/fanout-node-identity.test.ts +0 -105
- package/src/utils/workflow/graph/finalize-workflow-wires.ts +0 -310
- package/src/utils/workflow/graph/finalize-workflows.test.ts +0 -50
- package/src/utils/workflow/graph/finalize-workflows.ts +0 -130
- package/src/utils/workflow/graph/index.ts +0 -28
- package/src/utils/workflow/graph/serialize-workflow-graph.ts +0 -240
- package/src/utils/workflow/graph/workflow-graph.types.ts +0 -281
- package/src/visit.ts +0 -181
- package/tsconfig.json +0 -19
- package/tsconfig.tsbuildinfo +0 -1
package/src/add/add-gateway.ts
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import * as ts from 'typescript'
|
|
2
|
-
import {
|
|
3
|
-
getPropertyValue,
|
|
4
|
-
getCommonWireMetaData,
|
|
5
|
-
} from '../utils/get-property-value.js'
|
|
6
|
-
import type { AddWiring } from '../types.js'
|
|
7
|
-
import {
|
|
8
|
-
extractFunctionName,
|
|
9
|
-
makeContextBasedId,
|
|
10
|
-
} from '../utils/extract-function-name.js'
|
|
11
|
-
import { getPropertyAssignmentInitializer } from '../utils/type-utils.js'
|
|
12
|
-
import { ensureInlineWiringFunction } from '../utils/ensure-function-metadata.js'
|
|
13
|
-
import { resolveMiddleware } from '../utils/middleware.js'
|
|
14
|
-
import { extractWireNames } from '../utils/post-process.js'
|
|
15
|
-
import { resolveAddonName } from '../utils/resolve-addon-package.js'
|
|
16
|
-
import type { GatewayTransportType } from '@pikku/core/gateway'
|
|
17
|
-
|
|
18
|
-
import { ErrorCode } from '../error-codes.js'
|
|
19
|
-
|
|
20
|
-
export const addGateway: AddWiring = (
|
|
21
|
-
logger,
|
|
22
|
-
node,
|
|
23
|
-
checker,
|
|
24
|
-
state,
|
|
25
|
-
_options
|
|
26
|
-
) => {
|
|
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 (!ts.isIdentifier(expression) || expression.text !== 'wireGateway') {
|
|
36
|
-
return
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (!firstArg || !ts.isObjectLiteralExpression(firstArg)) {
|
|
40
|
-
return
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const obj = firstArg
|
|
44
|
-
|
|
45
|
-
const nameValue = getPropertyValue(obj, 'name') as string | null
|
|
46
|
-
const typeValue = getPropertyValue(obj, 'type') as GatewayTransportType | null
|
|
47
|
-
const routeValue = getPropertyValue(obj, 'route') as string | null
|
|
48
|
-
const platformValue = getPropertyValue(obj, 'platform') as string | null
|
|
49
|
-
const authValue = getPropertyValue(obj, 'auth')
|
|
50
|
-
const { disabled, tags, summary, description, errors } =
|
|
51
|
-
getCommonWireMetaData(obj, 'Gateway', nameValue, logger, checker)
|
|
52
|
-
|
|
53
|
-
if (disabled) return
|
|
54
|
-
|
|
55
|
-
const funcInitializer = getPropertyAssignmentInitializer(
|
|
56
|
-
obj,
|
|
57
|
-
'func',
|
|
58
|
-
true,
|
|
59
|
-
checker
|
|
60
|
-
)
|
|
61
|
-
if (!funcInitializer) {
|
|
62
|
-
logger.critical(
|
|
63
|
-
ErrorCode.MISSING_FUNC,
|
|
64
|
-
`No valid 'func' property for gateway '${nameValue}'.`
|
|
65
|
-
)
|
|
66
|
-
return
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const extracted = extractFunctionName(funcInitializer, checker, state.rootDir)
|
|
70
|
-
let pikkuFuncId = extracted.pikkuFuncId
|
|
71
|
-
if (pikkuFuncId.startsWith('__temp_') && nameValue) {
|
|
72
|
-
pikkuFuncId = makeContextBasedId('gateway', nameValue)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const packageName = ts.isIdentifier(funcInitializer)
|
|
76
|
-
? resolveAddonName(
|
|
77
|
-
funcInitializer,
|
|
78
|
-
checker,
|
|
79
|
-
state.rpc.wireAddonDeclarations
|
|
80
|
-
)
|
|
81
|
-
: null
|
|
82
|
-
|
|
83
|
-
if (!nameValue || !typeValue) {
|
|
84
|
-
return
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Register metadata for a func inlined into the wiring (see helper).
|
|
88
|
-
ensureInlineWiringFunction(
|
|
89
|
-
state,
|
|
90
|
-
pikkuFuncId,
|
|
91
|
-
nameValue,
|
|
92
|
-
funcInitializer,
|
|
93
|
-
checker,
|
|
94
|
-
extracted.isHelper
|
|
95
|
-
)
|
|
96
|
-
|
|
97
|
-
const middleware = resolveMiddleware(state, obj, tags, checker)
|
|
98
|
-
|
|
99
|
-
state.serviceAggregation.usedFunctions.add(pikkuFuncId)
|
|
100
|
-
extractWireNames(middleware).forEach((name) =>
|
|
101
|
-
state.serviceAggregation.usedMiddleware.add(name)
|
|
102
|
-
)
|
|
103
|
-
|
|
104
|
-
// Project webhook POST/GET wrappers into compiled http + function meta.
|
|
105
|
-
if (typeValue === 'webhook' && routeValue) {
|
|
106
|
-
const wrappers = [
|
|
107
|
-
{ method: 'post', funcId: `gateway__${nameValue}__post` },
|
|
108
|
-
{ method: 'get', funcId: `gateway__${nameValue}__verify` },
|
|
109
|
-
] as const
|
|
110
|
-
for (const { method, funcId } of wrappers) {
|
|
111
|
-
// no middleware here — the gateway POST wrapper runs it itself
|
|
112
|
-
state.http.meta[method][routeValue] = {
|
|
113
|
-
pikkuFuncId: funcId,
|
|
114
|
-
route: routeValue,
|
|
115
|
-
method,
|
|
116
|
-
}
|
|
117
|
-
state.functions.meta[funcId] = {
|
|
118
|
-
pikkuFuncId: funcId,
|
|
119
|
-
inputSchemaName: null,
|
|
120
|
-
outputSchemaName: null,
|
|
121
|
-
sessionless: true,
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
state.http.files.add(node.getSourceFile().fileName)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
state.gateways.files.add(node.getSourceFile().fileName)
|
|
128
|
-
state.gateways.meta[nameValue] = {
|
|
129
|
-
pikkuFuncId,
|
|
130
|
-
...(packageName && { packageName }),
|
|
131
|
-
name: nameValue,
|
|
132
|
-
type: typeValue,
|
|
133
|
-
...(routeValue && { route: routeValue }),
|
|
134
|
-
...(platformValue && { platform: platformValue }),
|
|
135
|
-
...(typeof authValue === 'boolean' && { auth: authValue }),
|
|
136
|
-
gateway: true,
|
|
137
|
-
summary,
|
|
138
|
-
description,
|
|
139
|
-
errors,
|
|
140
|
-
tags,
|
|
141
|
-
middleware,
|
|
142
|
-
}
|
|
143
|
-
}
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { strict as assert } from 'assert'
|
|
2
|
-
import { describe, test, before, after } from 'node:test'
|
|
3
|
-
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from 'fs'
|
|
4
|
-
import { tmpdir } from 'os'
|
|
5
|
-
import { join } from 'path'
|
|
6
|
-
import { inspect } from '../inspector.js'
|
|
7
|
-
import { filterInspectorState } from '../utils/filter-inspector-state.js'
|
|
8
|
-
import type { InspectorLogger, InspectorState } from '../types.js'
|
|
9
|
-
|
|
10
|
-
const ADDON_PACKAGE = '@addon/greeter'
|
|
11
|
-
const NAMESPACE = 'ext'
|
|
12
|
-
const TARGET = `${NAMESPACE}:greet`
|
|
13
|
-
|
|
14
|
-
const logger: InspectorLogger = {
|
|
15
|
-
debug: () => {},
|
|
16
|
-
info: () => {},
|
|
17
|
-
warn: () => {},
|
|
18
|
-
error: () => {},
|
|
19
|
-
diagnostic: () => {},
|
|
20
|
-
critical: () => {},
|
|
21
|
-
hasCriticalErrors: () => false,
|
|
22
|
-
} as unknown as InspectorLogger
|
|
23
|
-
|
|
24
|
-
const writeAddonFixture = (rootDir: string) => {
|
|
25
|
-
writeFileSync(
|
|
26
|
-
join(rootDir, 'package.json'),
|
|
27
|
-
JSON.stringify({ name: 'consumer' })
|
|
28
|
-
)
|
|
29
|
-
const addonDir = join(rootDir, 'node_modules', ADDON_PACKAGE)
|
|
30
|
-
const pikku = join(addonDir, '.pikku')
|
|
31
|
-
mkdirSync(join(pikku, 'function'), { recursive: true })
|
|
32
|
-
mkdirSync(join(pikku, 'schemas', 'schemas'), { recursive: true })
|
|
33
|
-
writeFileSync(
|
|
34
|
-
join(addonDir, 'package.json'),
|
|
35
|
-
JSON.stringify({ name: ADDON_PACKAGE })
|
|
36
|
-
)
|
|
37
|
-
writeFileSync(
|
|
38
|
-
join(pikku, 'function', 'pikku-functions-meta.gen.json'),
|
|
39
|
-
JSON.stringify({
|
|
40
|
-
greet: {
|
|
41
|
-
pikkuFuncId: 'greet',
|
|
42
|
-
name: 'greet',
|
|
43
|
-
sessionless: true,
|
|
44
|
-
inputSchemaName: 'GreetInput',
|
|
45
|
-
outputSchemaName: 'GreetOutput',
|
|
46
|
-
inputs: ['GreetInput'],
|
|
47
|
-
outputs: ['GreetOutput'],
|
|
48
|
-
services: { optimized: true, services: ['logger'] },
|
|
49
|
-
},
|
|
50
|
-
})
|
|
51
|
-
)
|
|
52
|
-
writeFileSync(
|
|
53
|
-
join(pikku, 'schemas', 'schemas', 'GreetInput.schema.json'),
|
|
54
|
-
JSON.stringify({
|
|
55
|
-
type: 'object',
|
|
56
|
-
properties: {
|
|
57
|
-
id: { type: 'string' },
|
|
58
|
-
loud: { type: 'boolean' },
|
|
59
|
-
name: { type: 'string' },
|
|
60
|
-
},
|
|
61
|
-
})
|
|
62
|
-
)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const writeWiring = (rootDir: string): string => {
|
|
66
|
-
const file = join(rootDir, 'greet.wiring.ts')
|
|
67
|
-
writeFileSync(
|
|
68
|
-
file,
|
|
69
|
-
[
|
|
70
|
-
`import { ref, wireAddon } from '@pikku/core'`,
|
|
71
|
-
`import { wireHTTP } from '@pikku/core/http'`,
|
|
72
|
-
``,
|
|
73
|
-
`wireAddon({ name: '${NAMESPACE}', package: '${ADDON_PACKAGE}' })`,
|
|
74
|
-
``,
|
|
75
|
-
`wireHTTP({`,
|
|
76
|
-
` auth: false,`,
|
|
77
|
-
` method: 'get',`,
|
|
78
|
-
` route: '/greet/:id',`,
|
|
79
|
-
` func: ref('${TARGET}'),`,
|
|
80
|
-
`})`,
|
|
81
|
-
``,
|
|
82
|
-
`wireHTTP({`,
|
|
83
|
-
` auth: false,`,
|
|
84
|
-
` method: 'post',`,
|
|
85
|
-
` route: '/greet',`,
|
|
86
|
-
` query: ['loud'],`,
|
|
87
|
-
` func: ref('${TARGET}'),`,
|
|
88
|
-
`})`,
|
|
89
|
-
].join('\n')
|
|
90
|
-
)
|
|
91
|
-
return file
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
describe('an HTTP route wired with ref() to an addon function', () => {
|
|
95
|
-
let rootDir: string
|
|
96
|
-
let state: InspectorState
|
|
97
|
-
|
|
98
|
-
before(async () => {
|
|
99
|
-
rootDir = mkdtempSync(join(tmpdir(), 'pikku-http-ref-'))
|
|
100
|
-
writeAddonFixture(rootDir)
|
|
101
|
-
const file = writeWiring(rootDir)
|
|
102
|
-
state = await inspect(logger, [file], { rootDir })
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
after(() => {
|
|
106
|
-
rmSync(rootDir, { recursive: true, force: true })
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
test('records the ref target as the route function id', () => {
|
|
110
|
-
assert.equal(state.http.meta.get['/greet/:id']?.pikkuFuncId, TARGET)
|
|
111
|
-
assert.equal(state.http.meta.post['/greet']?.pikkuFuncId, TARGET)
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
// packageName names the package a wire runs in — its middleware, its
|
|
115
|
-
// services, its scoped credentials. The route belongs to the consuming app
|
|
116
|
-
// however its function is reached, so tagging it with the addon's package
|
|
117
|
-
// would silently swap the app's global middleware for the addon's.
|
|
118
|
-
test("leaves the route in the consuming app's package", () => {
|
|
119
|
-
assert.equal(state.http.meta.get['/greet/:id']?.packageName, undefined)
|
|
120
|
-
assert.equal(state.http.meta.post['/greet']?.packageName, undefined)
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
test('mints no wrapper function metadata for the route', () => {
|
|
124
|
-
const wrapperIds = Object.keys(state.functions.meta).filter((id) =>
|
|
125
|
-
id.startsWith('http:')
|
|
126
|
-
)
|
|
127
|
-
assert.deepEqual(wrapperIds, [])
|
|
128
|
-
assert.equal(state.functions.meta[TARGET], undefined)
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
test('keeps each route its own params and query', () => {
|
|
132
|
-
assert.deepEqual(state.http.meta.get['/greet/:id']?.params, ['id'])
|
|
133
|
-
assert.equal(state.http.meta.get['/greet/:id']?.query, undefined)
|
|
134
|
-
assert.equal(state.http.meta.post['/greet']?.params, undefined)
|
|
135
|
-
assert.deepEqual(state.http.meta.post['/greet']?.query, ['loud'])
|
|
136
|
-
})
|
|
137
|
-
|
|
138
|
-
test('marks the addon target as used so tree-shaking keeps it', () => {
|
|
139
|
-
assert.ok(state.serviceAggregation.usedFunctions.has(TARGET))
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
test('survives a filtered bundle together with its addon declaration', () => {
|
|
143
|
-
const filtered = filterInspectorState(state, { names: [TARGET] }, logger)
|
|
144
|
-
assert.equal(filtered.http.meta.get['/greet/:id']?.pikkuFuncId, TARGET)
|
|
145
|
-
assert.equal(filtered.http.meta.post['/greet']?.pikkuFuncId, TARGET)
|
|
146
|
-
assert.ok(filtered.rpc.wireAddonDeclarations.has(NAMESPACE))
|
|
147
|
-
assert.ok(filtered.serviceAggregation.usedFunctions.has(TARGET))
|
|
148
|
-
})
|
|
149
|
-
})
|