@snaptrude/plugin-core 0.0.0-dev-20260708130115 → 0.0.0-dev-20260827135706
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 +152 -1
- package/api-manifest.json +3620 -276
- package/dist/api/analysis/daylight.d.ts +603 -0
- package/dist/api/analysis/daylight.d.ts.map +1 -0
- package/dist/api/analysis/heatmaps.d.ts +658 -0
- package/dist/api/analysis/heatmaps.d.ts.map +1 -0
- package/dist/api/analysis/illuminance.d.ts +145 -0
- package/dist/api/analysis/illuminance.d.ts.map +1 -0
- package/dist/api/analysis/index.d.ts +59 -0
- package/dist/api/analysis/index.d.ts.map +1 -0
- package/dist/api/analysis/shadows.d.ts +165 -0
- package/dist/api/analysis/shadows.d.ts.map +1 -0
- package/dist/api/analysis/solar.d.ts +249 -0
- package/dist/api/analysis/solar.d.ts.map +1 -0
- package/dist/api/analysis/sunlightHours.d.ts +208 -0
- package/dist/api/analysis/sunlightHours.d.ts.map +1 -0
- package/dist/api/analysis/sunpath.d.ts +80 -0
- package/dist/api/analysis/sunpath.d.ts.map +1 -0
- package/dist/api/analysis/weather.d.ts +193 -0
- package/dist/api/analysis/weather.d.ts.map +1 -0
- package/dist/api/core/camera/index.d.ts +261 -0
- package/dist/api/core/camera/index.d.ts.map +1 -0
- package/dist/api/core/comment/index.d.ts +105 -2
- package/dist/api/core/comment/index.d.ts.map +1 -1
- package/dist/api/core/geom/create/index.d.ts +840 -14
- package/dist/api/core/geom/create/index.d.ts.map +1 -1
- package/dist/api/core/geom/delete/index.d.ts +8 -2
- package/dist/api/core/geom/delete/index.d.ts.map +1 -1
- package/dist/api/core/geom/query/arc.d.ts +5 -5
- package/dist/api/core/geom/query/brep.d.ts +130 -18
- package/dist/api/core/geom/query/brep.d.ts.map +1 -1
- package/dist/api/core/geom/query/circle.d.ts +18 -18
- package/dist/api/core/geom/query/contour.d.ts +20 -20
- package/dist/api/core/geom/query/curve.d.ts +49 -49
- package/dist/api/core/geom/query/edge.d.ts +5 -5
- package/dist/api/core/geom/query/face.d.ts +16 -16
- package/dist/api/core/geom/query/halfedge.d.ts +8 -8
- package/dist/api/core/geom/query/profile.d.ts +19 -19
- package/dist/api/core/geom/query/vertex.d.ts +8 -8
- package/dist/api/core/geom/update/contour.d.ts +14 -14
- package/dist/api/core/geom/update/curve.d.ts +7 -7
- package/dist/api/core/geom/update/profile.d.ts +16 -16
- package/dist/api/core/handles/index.d.ts +210 -0
- package/dist/api/core/handles/index.d.ts.map +1 -0
- package/dist/api/core/index.d.ts +34 -0
- package/dist/api/core/index.d.ts.map +1 -1
- package/dist/api/core/io/export/index.d.ts +134 -0
- package/dist/api/core/io/export/index.d.ts.map +1 -0
- package/dist/api/core/io/import/index.d.ts +453 -0
- package/dist/api/core/io/import/index.d.ts.map +1 -0
- package/dist/api/core/io/index.d.ts +40 -0
- package/dist/api/core/io/index.d.ts.map +1 -0
- package/dist/api/core/io/job/index.d.ts +139 -0
- package/dist/api/core/io/job/index.d.ts.map +1 -0
- package/dist/api/core/io/query/index.d.ts +74 -0
- package/dist/api/core/io/query/index.d.ts.map +1 -0
- package/dist/api/core/io/terrain/index.d.ts +341 -0
- package/dist/api/core/io/terrain/index.d.ts.map +1 -0
- package/dist/api/core/io/underlay/index.d.ts +805 -0
- package/dist/api/core/io/underlay/index.d.ts.map +1 -0
- package/dist/api/core/layers.d.ts +7 -7
- package/dist/api/core/mode/index.d.ts +99 -0
- package/dist/api/core/mode/index.d.ts.map +1 -0
- package/dist/api/core/project/index.d.ts +68 -1
- package/dist/api/core/project/index.d.ts.map +1 -1
- package/dist/api/core/proposals/index.d.ts +531 -0
- package/dist/api/core/proposals/index.d.ts.map +1 -0
- package/dist/api/core/storeys/index.d.ts +265 -0
- package/dist/api/core/storeys/index.d.ts.map +1 -0
- package/dist/api/core/tags.d.ts +24 -0
- package/dist/api/core/tags.d.ts.map +1 -1
- package/dist/api/core/user.d.ts +44 -0
- package/dist/api/core/user.d.ts.map +1 -0
- package/dist/api/core/zoom/index.d.ts +4 -0
- package/dist/api/core/zoom/index.d.ts.map +1 -1
- package/dist/api/design/boolean/index.d.ts +4 -4
- package/dist/api/design/create/index.d.ts +568 -45
- package/dist/api/design/create/index.d.ts.map +1 -1
- package/dist/api/design/delete/index.d.ts +3 -0
- package/dist/api/design/delete/index.d.ts.map +1 -1
- package/dist/api/design/doors/index.d.ts +195 -0
- package/dist/api/design/doors/index.d.ts.map +1 -1
- package/dist/api/design/edit/index.d.ts +1 -1
- package/dist/api/design/erase/index.d.ts +2 -2
- package/dist/api/design/family.d.ts +349 -0
- package/dist/api/design/family.d.ts.map +1 -0
- package/dist/api/design/furniture/index.d.ts +181 -8
- package/dist/api/design/furniture/index.d.ts.map +1 -1
- package/dist/api/design/index.d.ts +98 -0
- package/dist/api/design/index.d.ts.map +1 -1
- package/dist/api/design/lock.d.ts +26 -0
- package/dist/api/design/lock.d.ts.map +1 -1
- package/dist/api/design/materials/index.d.ts +270 -16
- package/dist/api/design/materials/index.d.ts.map +1 -1
- package/dist/api/design/query/geometry/index.d.ts +112 -0
- package/dist/api/design/query/geometry/index.d.ts.map +1 -1
- package/dist/api/design/query/index.d.ts +282 -11
- package/dist/api/design/query/index.d.ts.map +1 -1
- package/dist/api/design/query/referenceLines.d.ts +45 -0
- package/dist/api/design/query/referenceLines.d.ts.map +1 -0
- package/dist/api/design/query/spaces.d.ts +181 -8
- package/dist/api/design/query/spaces.d.ts.map +1 -1
- package/dist/api/design/selection/index.d.ts +144 -0
- package/dist/api/design/selection/index.d.ts.map +1 -1
- package/dist/api/design/transform/index.d.ts +172 -10
- package/dist/api/design/transform/index.d.ts.map +1 -1
- package/dist/api/design/types/index.d.ts +181 -0
- package/dist/api/design/types/index.d.ts.map +1 -0
- package/dist/api/design/update/index.d.ts +553 -2
- package/dist/api/design/update/index.d.ts.map +1 -1
- package/dist/api/design/visibility.d.ts +126 -0
- package/dist/api/design/visibility.d.ts.map +1 -0
- package/dist/api/design/windows/index.d.ts +113 -2
- package/dist/api/design/windows/index.d.ts.map +1 -1
- package/dist/api/entity/buildableEnvelope.d.ts +4 -0
- package/dist/api/entity/buildableEnvelope.d.ts.map +1 -1
- package/dist/api/entity/referenceLine.d.ts +10 -2
- package/dist/api/entity/referenceLine.d.ts.map +1 -1
- package/dist/api/entity/space.d.ts +21 -21
- package/dist/api/entity/story.d.ts +242 -15
- package/dist/api/entity/story.d.ts.map +1 -1
- package/dist/api/index.d.ts +10 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/presentation/aiInspiration.d.ts +25 -25
- package/dist/api/presentation/annotate.d.ts +467 -0
- package/dist/api/presentation/annotate.d.ts.map +1 -0
- package/dist/api/presentation/diagrams.d.ts +111 -8
- package/dist/api/presentation/diagrams.d.ts.map +1 -1
- package/dist/api/presentation/export.d.ts +108 -0
- package/dist/api/presentation/export.d.ts.map +1 -0
- package/dist/api/presentation/import.d.ts +55 -4
- package/dist/api/presentation/import.d.ts.map +1 -1
- package/dist/api/presentation/index.d.ts +58 -1
- package/dist/api/presentation/index.d.ts.map +1 -1
- package/dist/api/presentation/placedViews.d.ts +1139 -0
- package/dist/api/presentation/placedViews.d.ts.map +1 -0
- package/dist/api/presentation/shapes.d.ts +481 -0
- package/dist/api/presentation/shapes.d.ts.map +1 -0
- package/dist/api/presentation/sheets.d.ts +452 -13
- package/dist/api/presentation/sheets.d.ts.map +1 -1
- package/dist/api/presentation/slideshow.d.ts +125 -0
- package/dist/api/presentation/slideshow.d.ts.map +1 -0
- package/dist/api/presentation/tables.d.ts +81 -0
- package/dist/api/presentation/tables.d.ts.map +1 -0
- package/dist/api/presentation/views.d.ts +367 -7
- package/dist/api/presentation/views.d.ts.map +1 -1
- package/dist/api/program/areas.d.ts +102 -12
- package/dist/api/program/areas.d.ts.map +1 -1
- package/dist/api/program/cores.d.ts +3 -99
- package/dist/api/program/cores.d.ts.map +1 -1
- package/dist/api/program/index.d.ts +7 -15
- package/dist/api/program/index.d.ts.map +1 -1
- package/dist/api/program/layout.d.ts +346 -11
- package/dist/api/program/layout.d.ts.map +1 -1
- package/dist/api/program/site.d.ts +469 -13
- package/dist/api/program/site.d.ts.map +1 -1
- package/dist/api/program/spreadsheet.d.ts +365 -41
- package/dist/api/program/spreadsheet.d.ts.map +1 -1
- package/dist/api/workspace/index.d.ts +505 -0
- package/dist/api/workspace/index.d.ts.map +1 -0
- package/dist/errors/codes.d.ts +34 -0
- package/dist/errors/codes.d.ts.map +1 -0
- package/dist/errors/envelope.d.ts +56 -0
- package/dist/errors/envelope.d.ts.map +1 -0
- package/dist/errors/index.d.ts +6 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/plugin-error.d.ts +69 -0
- package/dist/errors/plugin-error.d.ts.map +1 -0
- package/dist/handles.d.ts +97 -25
- package/dist/handles.d.ts.map +1 -1
- package/dist/host-utils.d.ts +4 -0
- package/dist/host-utils.d.ts.map +1 -1
- package/dist/index.cjs +4582 -1422
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4171 -1411
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
- package/scripts/generate-manifest.mjs +45 -0
- package/scripts/generate-manifest.test.mjs +103 -4
- package/src/api/analysis/daylight.ts +470 -0
- package/src/api/analysis/heatmaps.ts +683 -0
- package/src/api/analysis/illuminance.ts +155 -0
- package/src/api/analysis/index.ts +61 -0
- package/src/api/analysis/shadows.ts +183 -0
- package/src/api/analysis/solar.ts +237 -0
- package/src/api/analysis/sunlightHours.ts +211 -0
- package/src/api/analysis/sunpath.ts +83 -0
- package/src/api/analysis/weather.ts +179 -0
- package/src/api/core/camera/index.ts +268 -0
- package/src/api/core/comment/index.ts +120 -2
- package/src/api/core/geom/create/index.ts +912 -1
- package/src/api/core/geom/delete/index.ts +6 -0
- package/src/api/core/geom/query/brep.ts +119 -0
- package/src/api/core/handles/index.ts +233 -0
- package/src/api/core/index.ts +34 -0
- package/src/api/core/io/export/index.ts +126 -0
- package/src/api/core/io/import/index.ts +496 -0
- package/src/api/core/io/index.ts +42 -0
- package/src/api/core/io/job/index.ts +140 -0
- package/src/api/core/io/query/index.ts +71 -0
- package/src/api/core/io/terrain/index.ts +360 -0
- package/src/api/core/io/underlay/index.ts +705 -0
- package/src/api/core/mode/index.ts +96 -0
- package/src/api/core/project/index.ts +62 -1
- package/src/api/core/proposals/index.ts +569 -0
- package/src/api/core/storeys/index.ts +294 -0
- package/src/api/core/tags.ts +27 -0
- package/src/api/core/user.ts +46 -0
- package/src/api/core/zoom/index.ts +4 -0
- package/src/api/design/create/index.ts +670 -30
- package/src/api/design/delete/index.ts +3 -0
- package/src/api/design/doors/index.ts +208 -0
- package/src/api/design/erase/index.ts +1 -1
- package/src/api/design/family.ts +388 -0
- package/src/api/design/furniture/index.ts +197 -8
- package/src/api/design/index.ts +102 -0
- package/src/api/design/lock.ts +27 -0
- package/src/api/design/materials/index.ts +334 -27
- package/src/api/design/query/geometry/index.ts +125 -3
- package/src/api/design/query/index.ts +217 -7
- package/src/api/design/query/referenceLines.ts +52 -0
- package/src/api/design/query/spaces.ts +143 -0
- package/src/api/design/selection/index.ts +129 -0
- package/src/api/design/transform/index.ts +170 -9
- package/src/api/design/types/index.ts +156 -0
- package/src/api/design/update/index.ts +631 -3
- package/src/api/design/visibility.ts +143 -0
- package/src/api/design/windows/index.ts +128 -2
- package/src/api/entity/buildableEnvelope.ts +4 -0
- package/src/api/entity/referenceLine.ts +8 -0
- package/src/api/entity/story.ts +259 -15
- package/src/api/index.ts +10 -0
- package/src/api/presentation/annotate.ts +385 -0
- package/src/api/presentation/diagrams.ts +118 -8
- package/src/api/presentation/export.ts +108 -0
- package/src/api/presentation/import.ts +51 -4
- package/src/api/presentation/index.ts +66 -1
- package/src/api/presentation/placedViews.ts +1120 -0
- package/src/api/presentation/shapes.ts +274 -0
- package/src/api/presentation/sheets.ts +400 -13
- package/src/api/presentation/slideshow.ts +134 -0
- package/src/api/presentation/tables.ts +84 -0
- package/src/api/presentation/views.ts +376 -8
- package/src/api/program/areas.ts +88 -15
- package/src/api/program/cores.ts +3 -91
- package/src/api/program/index.ts +7 -15
- package/src/api/program/layout.ts +365 -11
- package/src/api/program/site.ts +435 -13
- package/src/api/program/spreadsheet.ts +376 -35
- package/src/api/workspace/index.ts +563 -0
- package/src/errors/codes.ts +136 -0
- package/src/errors/envelope.ts +75 -0
- package/src/errors/index.ts +21 -0
- package/src/errors/plugin-error.ts +134 -0
- package/src/handles.ts +123 -13
- package/src/host-utils.ts +4 -0
- package/src/index.ts +1 -0
- package/test/errors.test.mjs +184 -0
- package/tsconfig.json +7 -2
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { WirePluginErrorCode } from "./codes"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Structured error payload carried on the `{success: false}` branch of the RPC
|
|
5
|
+
* wire result, next to the legacy `error: string` field (additive — old
|
|
6
|
+
* clients ignore it, old hosts never set it).
|
|
7
|
+
*
|
|
8
|
+
* Errors cross the worker boundary as THIS plain object, never as a thrown
|
|
9
|
+
* class: Comlink's throw transfer strips subclasses and custom fields and
|
|
10
|
+
* leaks host stacks. plugin-client reconstructs a typed `PluginError` from it
|
|
11
|
+
* (`fromEnvelope`).
|
|
12
|
+
*/
|
|
13
|
+
export const ERROR_ENVELOPE_VERSION = 1 as const
|
|
14
|
+
|
|
15
|
+
export interface ErrorEnvelope {
|
|
16
|
+
envelopeVersion: typeof ERROR_ENVELOPE_VERSION
|
|
17
|
+
code: WirePluginErrorCode
|
|
18
|
+
/**
|
|
19
|
+
* Human-readable failure description. For INTERNAL/UNKNOWN this is a GENERIC
|
|
20
|
+
* message — the real message and stack stay host-side, logged under
|
|
21
|
+
* `errorId` (the worker is untrusted; internals must not leak).
|
|
22
|
+
*/
|
|
23
|
+
message: string
|
|
24
|
+
/**
|
|
25
|
+
* Per-occurrence id. For INTERNAL the host logs the real message and stack
|
|
26
|
+
* under this id (the sanitized message would otherwise be an undebuggable
|
|
27
|
+
* dead end). Other codes carry the id only to identify the occurrence in
|
|
28
|
+
* bug reports — the host does not log them. Client-minted ids carry a `c-`
|
|
29
|
+
* prefix.
|
|
30
|
+
*/
|
|
31
|
+
errorId: string
|
|
32
|
+
/** Structured, JSON-safe, code-specific data (issues / retryAfterMs / didYouMean / handles…). */
|
|
33
|
+
details?: Record<string, unknown>
|
|
34
|
+
/**
|
|
35
|
+
* Wire id of the single primary offending handle, when the failure is
|
|
36
|
+
* handle-scoped. Multiple offenders go in `details.handles: string[]`.
|
|
37
|
+
* May echo ONLY ids the caller itself supplied (anti-oracle rule).
|
|
38
|
+
*/
|
|
39
|
+
handle?: string
|
|
40
|
+
/** Dotted method path of the failed call (e.g. "design.boolean.union"). */
|
|
41
|
+
methodPath?: string
|
|
42
|
+
/** Machine-actionable fix suggestion (written for LLM plugin authors). */
|
|
43
|
+
hint?: string
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Structural guard for a wire value claiming to be an `ErrorEnvelope`.
|
|
48
|
+
*
|
|
49
|
+
* Checks shape only — deliberately does NOT reject codes outside the known
|
|
50
|
+
* union, so envelopes from a newer host still pass (forward compatibility).
|
|
51
|
+
*/
|
|
52
|
+
export function isErrorEnvelope(value: unknown): value is ErrorEnvelope {
|
|
53
|
+
if (typeof value !== "object" || value === null) return false
|
|
54
|
+
const record = value as Record<string, unknown>
|
|
55
|
+
return (
|
|
56
|
+
record.envelopeVersion === ERROR_ENVELOPE_VERSION &&
|
|
57
|
+
typeof record.code === "string" &&
|
|
58
|
+
typeof record.message === "string" &&
|
|
59
|
+
typeof record.errorId === "string"
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
let idCounter = 0
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Mint a per-occurrence error id. Uses `crypto.randomUUID` when available
|
|
67
|
+
* (browser main thread and workers both have it); falls back to a
|
|
68
|
+
* counter+random suffix — uniqueness within a session is all that is needed.
|
|
69
|
+
*/
|
|
70
|
+
export function newErrorId(prefix = ""): string {
|
|
71
|
+
const cryptoApi = (globalThis as { crypto?: { randomUUID?: () => string } }).crypto
|
|
72
|
+
if (cryptoApi?.randomUUID) return `${prefix}${cryptoApi.randomUUID()}`
|
|
73
|
+
idCounter += 1
|
|
74
|
+
return `${prefix}${Date.now().toString(36)}-${idCounter}-${Math.random().toString(36).slice(2, 10)}`
|
|
75
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export { PLUGIN_ERROR_CODES, CODE_META, isPluginErrorCode } from "./codes"
|
|
2
|
+
export type { PluginErrorCode, WirePluginErrorCode, PluginErrorCategory, CodeMeta } from "./codes"
|
|
3
|
+
|
|
4
|
+
export { ERROR_ENVELOPE_VERSION, isErrorEnvelope, newErrorId } from "./envelope"
|
|
5
|
+
export type { ErrorEnvelope } from "./envelope"
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
PluginError,
|
|
9
|
+
PluginValidationError,
|
|
10
|
+
PluginNotFoundError,
|
|
11
|
+
PluginPermissionError,
|
|
12
|
+
PluginHandleError,
|
|
13
|
+
PluginQuotaError,
|
|
14
|
+
PluginTimeoutError,
|
|
15
|
+
PluginTransportError,
|
|
16
|
+
PluginLifecycleError,
|
|
17
|
+
PluginExecutionError,
|
|
18
|
+
PluginInternalError,
|
|
19
|
+
fromEnvelope,
|
|
20
|
+
makeClientEnvelope,
|
|
21
|
+
} from "./plugin-error"
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { CODE_META, isPluginErrorCode } from "./codes"
|
|
2
|
+
import type { PluginErrorCategory, PluginErrorCode, WirePluginErrorCode } from "./codes"
|
|
3
|
+
import { ERROR_ENVELOPE_VERSION, newErrorId } from "./envelope"
|
|
4
|
+
import type { ErrorEnvelope } from "./envelope"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Cross-copy brand: a plugin bundle may contain its OWN copy of this module,
|
|
8
|
+
* in which case `instanceof` fails across the two class identities.
|
|
9
|
+
* `Symbol.for` resolves to the same symbol in every copy within a realm, so
|
|
10
|
+
* `PluginError.is()` keeps working. Canonical check = `.is()` + `code`.
|
|
11
|
+
*/
|
|
12
|
+
const BRAND = Symbol.for("snaptrude.pluginError")
|
|
13
|
+
|
|
14
|
+
interface Branded {
|
|
15
|
+
[BRAND]?: boolean
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Typed error every failed plugin API call rejects with.
|
|
20
|
+
*
|
|
21
|
+
* Rehydrated client-side from the wire `ErrorEnvelope` (`fromEnvelope`) — the
|
|
22
|
+
* class itself never crosses the worker boundary. Branch on the stable string
|
|
23
|
+
* `code`; use `PluginError.is()` rather than `instanceof` (a bundled duplicate
|
|
24
|
+
* SDK copy breaks `instanceof`, never the brand).
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* try {
|
|
29
|
+
* await snaptrude.design.boolean.union(handles)
|
|
30
|
+
* } catch (e) {
|
|
31
|
+
* if (PluginError.is(e) && e.code === "RATE_LIMITED") {
|
|
32
|
+
* await sleep(e.details?.retryAfterMs as number)
|
|
33
|
+
* } else {
|
|
34
|
+
* throw e
|
|
35
|
+
* }
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export class PluginError extends Error {
|
|
40
|
+
readonly code: WirePluginErrorCode
|
|
41
|
+
readonly errorId: string
|
|
42
|
+
readonly details?: Record<string, unknown>
|
|
43
|
+
readonly handle?: string
|
|
44
|
+
readonly methodPath?: string
|
|
45
|
+
readonly hint?: string
|
|
46
|
+
|
|
47
|
+
constructor(envelope: ErrorEnvelope) {
|
|
48
|
+
super(envelope.message)
|
|
49
|
+
this.name = new.target.name
|
|
50
|
+
this.code = envelope.code
|
|
51
|
+
this.errorId = envelope.errorId
|
|
52
|
+
this.details = envelope.details
|
|
53
|
+
this.handle = envelope.handle
|
|
54
|
+
this.methodPath = envelope.methodPath
|
|
55
|
+
this.hint = envelope.hint ?? hintFor(envelope.code)
|
|
56
|
+
;(this as Branded)[BRAND] = true
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Canonical check — survives bundled duplicate SDK copies where `instanceof` fails. */
|
|
60
|
+
static is(value: unknown): value is PluginError {
|
|
61
|
+
return (
|
|
62
|
+
typeof value === "object" &&
|
|
63
|
+
value !== null &&
|
|
64
|
+
(value as Branded)[BRAND] === true
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Derived (not wire-carried) family of the code; unknown codes map to "internal". */
|
|
69
|
+
get category(): PluginErrorCategory {
|
|
70
|
+
return isPluginErrorCode(this.code) ? CODE_META[this.code].category : "internal"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Category sugar — same brand, so `PluginError.is()` matches all of them.
|
|
75
|
+
// Convenience for single-SDK-copy plugins; docs teach `.is()` + `code`.
|
|
76
|
+
export class PluginValidationError extends PluginError {}
|
|
77
|
+
export class PluginNotFoundError extends PluginError {}
|
|
78
|
+
export class PluginPermissionError extends PluginError {}
|
|
79
|
+
export class PluginHandleError extends PluginError {}
|
|
80
|
+
export class PluginQuotaError extends PluginError {}
|
|
81
|
+
export class PluginTimeoutError extends PluginError {}
|
|
82
|
+
export class PluginTransportError extends PluginError {}
|
|
83
|
+
export class PluginLifecycleError extends PluginError {}
|
|
84
|
+
export class PluginExecutionError extends PluginError {}
|
|
85
|
+
export class PluginInternalError extends PluginError {}
|
|
86
|
+
|
|
87
|
+
type PluginErrorConstructor = new (envelope: ErrorEnvelope) => PluginError
|
|
88
|
+
|
|
89
|
+
const CATEGORY_CLASS: Record<PluginErrorCategory, PluginErrorConstructor> = {
|
|
90
|
+
validation: PluginValidationError,
|
|
91
|
+
not_found: PluginNotFoundError,
|
|
92
|
+
permission: PluginPermissionError,
|
|
93
|
+
handle: PluginHandleError,
|
|
94
|
+
quota: PluginQuotaError,
|
|
95
|
+
timeout: PluginTimeoutError,
|
|
96
|
+
transport: PluginTransportError,
|
|
97
|
+
lifecycle: PluginLifecycleError,
|
|
98
|
+
execution: PluginExecutionError,
|
|
99
|
+
internal: PluginInternalError,
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function hintFor(code: WirePluginErrorCode): string | undefined {
|
|
103
|
+
return isPluginErrorCode(code) ? CODE_META[code].hintTemplate : undefined
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Rehydrate a wire envelope into the typed error the plugin catches.
|
|
108
|
+
* A code outside the known union (newer host) constructs the base
|
|
109
|
+
* `PluginError` with the code preserved verbatim.
|
|
110
|
+
*/
|
|
111
|
+
export function fromEnvelope(envelope: ErrorEnvelope): PluginError {
|
|
112
|
+
if (!isPluginErrorCode(envelope.code)) return new PluginError(envelope)
|
|
113
|
+
const ErrorClass = CATEGORY_CLASS[CODE_META[envelope.code].category]
|
|
114
|
+
return new ErrorClass(envelope)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Build an envelope for a CLIENT-detected failure (transport rejection,
|
|
119
|
+
* legacy host without `errorInfo`). Host-originated envelopes are built by
|
|
120
|
+
* the host's `toErrorEnvelope` mapper, never by this.
|
|
121
|
+
*/
|
|
122
|
+
export function makeClientEnvelope(
|
|
123
|
+
code: PluginErrorCode,
|
|
124
|
+
message: string,
|
|
125
|
+
extra?: Partial<Pick<ErrorEnvelope, "details" | "handle" | "methodPath" | "hint">>
|
|
126
|
+
): ErrorEnvelope {
|
|
127
|
+
return {
|
|
128
|
+
envelopeVersion: ERROR_ENVELOPE_VERSION,
|
|
129
|
+
code,
|
|
130
|
+
message,
|
|
131
|
+
errorId: newErrorId("c-"),
|
|
132
|
+
...extra,
|
|
133
|
+
}
|
|
134
|
+
}
|
package/src/handles.ts
CHANGED
|
@@ -1,22 +1,71 @@
|
|
|
1
1
|
import * as z from "zod"
|
|
2
|
+
import type { ArenaKind } from "./api/core/handles"
|
|
3
|
+
|
|
4
|
+
// Runtime polyfill: engines without explicit-resource-management would otherwise
|
|
5
|
+
// evaluate the class's computed [Symbol.asyncDispose] key as undefined and
|
|
6
|
+
// silently create a property literally named "undefined".
|
|
7
|
+
;(Symbol as { asyncDispose?: symbol }).asyncDispose ??= Symbol.for("Symbol.asyncDispose")
|
|
2
8
|
|
|
3
9
|
/**
|
|
4
10
|
* An opaque, kind-tagged reference to a host-side object that crosses the RPC
|
|
5
11
|
* boundary by IDENTITY rather than by value. See `PLUGIN_API_EXPOSURE_HLD.md` §9.
|
|
6
12
|
*
|
|
7
|
-
*
|
|
8
|
-
* `Handle<"
|
|
9
|
-
*
|
|
10
|
-
*
|
|
13
|
+
* A handle is a small CLASS instance wrapping the wire id. The phantom
|
|
14
|
+
* `__handle` brand makes a `Handle<"profile">` incompatible with a
|
|
15
|
+
* `Handle<"vec3">` at compile time. On the wire the id string is all that
|
|
16
|
+
* travels: the client SDK unwraps `Handle` arguments to `.id` before the RPC
|
|
17
|
+
* call, and the host tags returned handles as `{ __h: "<id>" }` (via
|
|
18
|
+
* {@linkcode Handle.toJSON}) for the client to re-wrap.
|
|
19
|
+
*
|
|
20
|
+
* Plugin-side lifecycle: the client SDK interns one live instance per id and
|
|
21
|
+
* registers it with a FinalizationRegistry — dropping every reference to a
|
|
22
|
+
* handle eventually releases its host registry entry. Deterministic release is
|
|
23
|
+
* still preferred: `core.handles.release/releaseAll` or scopes.
|
|
24
|
+
*
|
|
25
|
+
* Crossing non-RPC boundaries (UI postMessage, persistence, logging):
|
|
26
|
+
* send {@linkcode Handle.id} — structured clone strips the class prototype.
|
|
11
27
|
*/
|
|
12
|
-
export
|
|
28
|
+
export class Handle<K extends string> {
|
|
29
|
+
/** Phantom brand — keeps `Handle<"vec3">` ≠ `Handle<"mass">` at compile time. */
|
|
30
|
+
declare readonly __handle: K
|
|
31
|
+
|
|
32
|
+
constructor(readonly id: string) {}
|
|
33
|
+
|
|
34
|
+
/** Wire tag — the host's result serialization (JSON round-trip) calls this. */
|
|
35
|
+
toJSON(): { __h: string } {
|
|
36
|
+
return { __h: this.id }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Template-string / logging form stays the bare id. */
|
|
40
|
+
toString(): string {
|
|
41
|
+
return this.id
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Identity comparison by id — safe across re-wraps. */
|
|
45
|
+
equals(other: Handle<string>): boolean {
|
|
46
|
+
return this.id === other.id
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Explicit-resource-management hook (`await using`). A no-op here; the
|
|
51
|
+
* plugin-client runtime installs the real enqueue-release behavior on the
|
|
52
|
+
* interned instance.
|
|
53
|
+
*/
|
|
54
|
+
async [Symbol.asyncDispose](): Promise<void> {}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Union of all releasable (arena-backed) handle kinds. */
|
|
58
|
+
export type AnyArenaHandle = Handle<ArenaKind>
|
|
13
59
|
|
|
14
60
|
/**
|
|
15
61
|
* A scene-entity handle. Backed by the host `Component.id` and resolved live via
|
|
16
62
|
* the host scene index (StructureCollection) — never stored in the resource
|
|
17
63
|
* registry. Stable across undo/redo and persistable across sessions (§9.2).
|
|
64
|
+
* Entity handles remain raw branded STRINGS (not {@linkcode Handle} instances):
|
|
65
|
+
* they have no arena entry, no lifecycle, and are equality-matched against
|
|
66
|
+
* plain ids embedded in result records.
|
|
18
67
|
*/
|
|
19
|
-
export type EntityId<K extends string = string> =
|
|
68
|
+
export type EntityId<K extends string = string> = string & { readonly __handle: K }
|
|
20
69
|
|
|
21
70
|
/** Resource handle: a host-resident, session-ephemeral geometry object (§9.2). */
|
|
22
71
|
export type ProfileHandle = Handle<"profile">
|
|
@@ -46,6 +95,34 @@ export type ComponentHandle = EntityId<"component">
|
|
|
46
95
|
*/
|
|
47
96
|
export type MaterialHandle = EntityId<"material">
|
|
48
97
|
|
|
98
|
+
/**
|
|
99
|
+
* A placed **scene underlay** — an imported reference plane the user traces over:
|
|
100
|
+
* an image `FloorPlan`, a `PDF` overlay, or a `CAD` sketch. Entity-style: the token
|
|
101
|
+
* IS the raw `Component.id` (`fp_…` / a pdf id / `cad_…`). Resolved live host-side
|
|
102
|
+
* via the import-order layer walk (`collectStoreyImportItems`) — NOT via
|
|
103
|
+
* `ComponentUtility.FindComponentById`, which does not index underlays. No arena, no
|
|
104
|
+
* quota, stable across undo/redo. Returned by `core.io.import.{image,pdf,cadJson}`
|
|
105
|
+
* and consumed by every `core.io.underlay.*` method.
|
|
106
|
+
*/
|
|
107
|
+
export type UnderlayHandle = EntityId<"underlay">
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* The project's **site terrain** — a Mapbox-derived topography mesh. Entity-style
|
|
111
|
+
* and a project **singleton** (one terrain per project): the token is the terrain
|
|
112
|
+
* `Component.id` (`terrain-…`), resolved live via `TerrainOperations.getTerrain()`
|
|
113
|
+
* (absent from the level component collections, so NOT `FindComponentById`).
|
|
114
|
+
* Returned by `core.io.import.terrain`.
|
|
115
|
+
*/
|
|
116
|
+
export type TerrainHandle = EntityId<"terrain">
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* A handle to an **asynchronous import job** (today: a DWG → Forge conversion, which
|
|
120
|
+
* can take minutes). Returned immediately by `core.io.import.dwg`; poll it via
|
|
121
|
+
* `core.io.job.*` (`getStatus` / `isComplete` / `getResult` / `getError`). The token
|
|
122
|
+
* is the engine's import request id; job state lives in a host-side registry.
|
|
123
|
+
*/
|
|
124
|
+
export type ImportJobHandle = EntityId<"importJob">
|
|
125
|
+
|
|
49
126
|
// ── Value-kind handles (all-handle model, §11) ──────────────────────────────
|
|
50
127
|
// Under the all-handle decision every structured type is a handle. The only
|
|
51
128
|
// non-handles crossing the boundary are JS primitives (number/string/boolean)
|
|
@@ -91,19 +168,34 @@ export type BBoxComponents = { min: Vec3Components; max: Vec3Components }
|
|
|
91
168
|
|
|
92
169
|
/**
|
|
93
170
|
* Build a Zod schema validating a handle of the given `kind` at the trust
|
|
94
|
-
* boundary
|
|
95
|
-
*
|
|
96
|
-
* the
|
|
171
|
+
* boundary and emitting a {@linkcode Handle} instance for impl code. Inbound
|
|
172
|
+
* forms accepted:
|
|
173
|
+
* - the bare id string (the wire form — the client unwraps args to ids)
|
|
174
|
+
* - a live `Handle` instance (host-internal re-parse, direct host callers)
|
|
175
|
+
* - `{ __h: string }` (the tagged result form, echoed back as an arg)
|
|
176
|
+
* - `{ id: string }` (a Handle stripped by structured clone at the UI boundary)
|
|
177
|
+
* Shape checking stays prefix-only; existence, kind, and ownership are enforced
|
|
178
|
+
* host-side by the HandleRegistry (§9.7) — no existence oracle.
|
|
97
179
|
*/
|
|
98
180
|
export const handleSchema = <K extends string>(kind: K) =>
|
|
99
181
|
z
|
|
100
|
-
.
|
|
101
|
-
|
|
102
|
-
|
|
182
|
+
.preprocess(
|
|
183
|
+
(v) => {
|
|
184
|
+
if (typeof v === "string") return v
|
|
185
|
+
if (v instanceof Handle) return v.id
|
|
186
|
+
if (v && typeof v === "object") {
|
|
187
|
+
const o = v as Record<string, unknown>
|
|
188
|
+
if (typeof o.__h === "string") return o.__h
|
|
189
|
+
if (typeof o.id === "string") return o.id
|
|
190
|
+
}
|
|
191
|
+
return v
|
|
192
|
+
},
|
|
193
|
+
z.string().regex(new RegExp(`^${kind}_[A-Za-z0-9_-]+$`), `expected a "${kind}" handle`)
|
|
194
|
+
)
|
|
195
|
+
.transform((s) => new Handle<K>(s))
|
|
103
196
|
|
|
104
197
|
export const ProfileHandle = handleSchema("profile")
|
|
105
198
|
export const ContourHandle = handleSchema("contour")
|
|
106
|
-
export const MassHandle = handleSchema("mass")
|
|
107
199
|
|
|
108
200
|
/**
|
|
109
201
|
* Entity handles are raw `Component.id` strings (no `"<kind>_"` prefix) — validated
|
|
@@ -123,6 +215,24 @@ export const MaterialHandle = z
|
|
|
123
215
|
.min(1)
|
|
124
216
|
.transform((s) => s as MaterialHandle)
|
|
125
217
|
|
|
218
|
+
/**
|
|
219
|
+
* {@linkcode UnderlayHandle} / {@linkcode TerrainHandle} / {@linkcode ImportJobHandle}
|
|
220
|
+
* are entity-style handles — raw host ids, validated only as a non-empty string
|
|
221
|
+
* (no `"<kind>_"` prefix), resolved live host-side (existence enforced there).
|
|
222
|
+
*/
|
|
223
|
+
export const UnderlayHandle = z
|
|
224
|
+
.string()
|
|
225
|
+
.min(1)
|
|
226
|
+
.transform((s) => s as UnderlayHandle)
|
|
227
|
+
export const TerrainHandle = z
|
|
228
|
+
.string()
|
|
229
|
+
.min(1)
|
|
230
|
+
.transform((s) => s as TerrainHandle)
|
|
231
|
+
export const ImportJobHandle = z
|
|
232
|
+
.string()
|
|
233
|
+
.min(1)
|
|
234
|
+
.transform((s) => s as ImportJobHandle)
|
|
235
|
+
|
|
126
236
|
// Value-kind handle schemas (all-handle model, §11).
|
|
127
237
|
export const Vec3Handle = handleSchema("vec3")
|
|
128
238
|
export const QuatHandle = handleSchema("quat")
|
package/src/host-utils.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PluginApi } from "./api"
|
|
2
|
+
import type { ErrorEnvelope } from "./errors"
|
|
2
3
|
|
|
3
4
|
// -- Type Utilities for inferring method paths from the class hierarchy ------
|
|
4
5
|
|
|
@@ -60,5 +61,8 @@ export type PluginApiCallResult<M extends PluginApiMethod> =
|
|
|
60
61
|
export type PluginApiCallWrappedResult<M extends PluginApiMethod> = {
|
|
61
62
|
success: boolean;
|
|
62
63
|
data?: PluginApiCallResult<M>;
|
|
64
|
+
/** Legacy failure message — kept verbatim for already-published plugins. */
|
|
63
65
|
error?: string;
|
|
66
|
+
/** Structured failure (hosts ≥ error-envelope rollout). Present iff `success` is false. */
|
|
67
|
+
errorInfo?: ErrorEnvelope;
|
|
64
68
|
}
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
// Node built-in test runner suite for the error module (codes/envelope/PluginError).
|
|
2
|
+
// Run: node --test test/
|
|
3
|
+
// Imports the BUILT package (dist) — run `pnpm build` first.
|
|
4
|
+
import test from "node:test"
|
|
5
|
+
import assert from "node:assert/strict"
|
|
6
|
+
import {
|
|
7
|
+
PLUGIN_ERROR_CODES,
|
|
8
|
+
CODE_META,
|
|
9
|
+
isPluginErrorCode,
|
|
10
|
+
ERROR_ENVELOPE_VERSION,
|
|
11
|
+
isErrorEnvelope,
|
|
12
|
+
newErrorId,
|
|
13
|
+
PluginError,
|
|
14
|
+
PluginValidationError,
|
|
15
|
+
PluginQuotaError,
|
|
16
|
+
PluginTimeoutError,
|
|
17
|
+
PluginTransportError,
|
|
18
|
+
PluginInternalError,
|
|
19
|
+
fromEnvelope,
|
|
20
|
+
makeClientEnvelope,
|
|
21
|
+
} from "../dist/index.js"
|
|
22
|
+
|
|
23
|
+
const CATEGORIES = [
|
|
24
|
+
"validation", "not_found", "permission", "handle", "quota",
|
|
25
|
+
"timeout", "transport", "lifecycle", "execution", "internal",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
function envelope(overrides = {}) {
|
|
29
|
+
return {
|
|
30
|
+
envelopeVersion: ERROR_ENVELOPE_VERSION,
|
|
31
|
+
code: "OPERATION_FAILED",
|
|
32
|
+
message: "it failed",
|
|
33
|
+
errorId: "test-id-1",
|
|
34
|
+
...overrides,
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// --- codes registry ---------------------------------------------------------
|
|
39
|
+
|
|
40
|
+
test("every code has CODE_META with a valid category (union↔meta completeness)", () => {
|
|
41
|
+
for (const code of PLUGIN_ERROR_CODES) {
|
|
42
|
+
const meta = CODE_META[code]
|
|
43
|
+
assert.ok(meta, `missing CODE_META for ${code}`)
|
|
44
|
+
assert.ok(CATEGORIES.includes(meta.category), `bad category for ${code}: ${meta.category}`)
|
|
45
|
+
}
|
|
46
|
+
assert.equal(Object.keys(CODE_META).length, PLUGIN_ERROR_CODES.length)
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
test("codes are unique", () => {
|
|
50
|
+
assert.equal(new Set(PLUGIN_ERROR_CODES).size, PLUGIN_ERROR_CODES.length)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
test("isPluginErrorCode narrows union members and rejects strangers", () => {
|
|
54
|
+
assert.equal(isPluginErrorCode("HANDLE_INVALID"), true)
|
|
55
|
+
assert.equal(isPluginErrorCode("TOTALLY_MADE_UP"), false)
|
|
56
|
+
assert.equal(isPluginErrorCode(""), false)
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
// --- envelope ----------------------------------------------------------------
|
|
60
|
+
|
|
61
|
+
test("isErrorEnvelope accepts a minimal valid envelope", () => {
|
|
62
|
+
assert.equal(isErrorEnvelope(envelope()), true)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
test("isErrorEnvelope accepts codes OUTSIDE the union (forward compat)", () => {
|
|
66
|
+
assert.equal(isErrorEnvelope(envelope({ code: "FUTURE_CODE" })), true)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
test("isErrorEnvelope rejects malformed values", () => {
|
|
70
|
+
assert.equal(isErrorEnvelope(null), false)
|
|
71
|
+
assert.equal(isErrorEnvelope("boom"), false)
|
|
72
|
+
assert.equal(isErrorEnvelope({}), false)
|
|
73
|
+
assert.equal(isErrorEnvelope(envelope({ envelopeVersion: 2 })), false)
|
|
74
|
+
assert.equal(isErrorEnvelope(envelope({ errorId: undefined })), false)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
test("newErrorId returns unique prefixed ids", () => {
|
|
78
|
+
const a = newErrorId("c-")
|
|
79
|
+
const b = newErrorId("c-")
|
|
80
|
+
assert.notEqual(a, b)
|
|
81
|
+
assert.ok(a.startsWith("c-"))
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
// --- PluginError rehydration --------------------------------------------------
|
|
85
|
+
|
|
86
|
+
test("fromEnvelope picks the category sugar subclass", () => {
|
|
87
|
+
assert.ok(fromEnvelope(envelope({ code: "VALIDATION" })) instanceof PluginValidationError)
|
|
88
|
+
assert.ok(fromEnvelope(envelope({ code: "RATE_LIMITED" })) instanceof PluginQuotaError)
|
|
89
|
+
assert.ok(fromEnvelope(envelope({ code: "TIMEOUT" })) instanceof PluginTimeoutError)
|
|
90
|
+
assert.ok(fromEnvelope(envelope({ code: "TRANSPORT_LOST" })) instanceof PluginTransportError)
|
|
91
|
+
assert.ok(fromEnvelope(envelope({ code: "INTERNAL" })) instanceof PluginInternalError)
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
test("fromEnvelope preserves envelope fields on the error", () => {
|
|
95
|
+
const err = fromEnvelope(
|
|
96
|
+
envelope({
|
|
97
|
+
code: "OPERATION_FAILED",
|
|
98
|
+
details: { op: "union", handles: ["mass_1", "mass_2"] },
|
|
99
|
+
handle: "mass_1",
|
|
100
|
+
methodPath: "design.boolean.union",
|
|
101
|
+
hint: "check overlap",
|
|
102
|
+
})
|
|
103
|
+
)
|
|
104
|
+
assert.equal(err.code, "OPERATION_FAILED")
|
|
105
|
+
assert.equal(err.message, "it failed")
|
|
106
|
+
assert.equal(err.errorId, "test-id-1")
|
|
107
|
+
assert.deepEqual(err.details, { op: "union", handles: ["mass_1", "mass_2"] })
|
|
108
|
+
assert.equal(err.handle, "mass_1")
|
|
109
|
+
assert.equal(err.methodPath, "design.boolean.union")
|
|
110
|
+
assert.equal(err.hint, "check overlap")
|
|
111
|
+
assert.equal(err.category, "execution")
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
test("unknown code constructs base PluginError with code preserved verbatim", () => {
|
|
115
|
+
const err = fromEnvelope(envelope({ code: "FUTURE_CODE" }))
|
|
116
|
+
assert.equal(err.constructor, PluginError)
|
|
117
|
+
assert.equal(err.code, "FUTURE_CODE")
|
|
118
|
+
assert.equal(err.category, "internal")
|
|
119
|
+
assert.equal(PluginError.is(err), true)
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
test("hint falls back to the code's template when the envelope has none", () => {
|
|
123
|
+
const err = fromEnvelope(envelope({ code: "RATE_LIMITED" }))
|
|
124
|
+
assert.equal(err.hint, CODE_META.RATE_LIMITED.hintTemplate)
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
test("PluginError.is matches the brand across class identities (dual SDK copy)", () => {
|
|
128
|
+
// Simulate a second bundled copy: a plain object carrying the Symbol.for
|
|
129
|
+
// brand but NOT part of this module's prototype chain.
|
|
130
|
+
const impostor = Object.assign(new Error("from other copy"), {
|
|
131
|
+
[Symbol.for("snaptrude.pluginError")]: true,
|
|
132
|
+
code: "TIMEOUT",
|
|
133
|
+
})
|
|
134
|
+
assert.equal(impostor instanceof PluginError, false)
|
|
135
|
+
assert.equal(PluginError.is(impostor), true)
|
|
136
|
+
assert.equal(PluginError.is(new Error("plain")), false)
|
|
137
|
+
assert.equal(PluginError.is(null), false)
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
// --- makeClientEnvelope --------------------------------------------------------
|
|
141
|
+
|
|
142
|
+
test("makeClientEnvelope mints a c- prefixed id and passes extras through", () => {
|
|
143
|
+
const env = makeClientEnvelope("TRANSPORT_LOST", "port closed", {
|
|
144
|
+
methodPath: "design.boolean.union",
|
|
145
|
+
})
|
|
146
|
+
assert.equal(isErrorEnvelope(env), true)
|
|
147
|
+
assert.equal(env.code, "TRANSPORT_LOST")
|
|
148
|
+
assert.ok(env.errorId.startsWith("c-"))
|
|
149
|
+
assert.equal(env.methodPath, "design.boolean.union")
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
// --- Registry snapshot (append-only guard) -----------------------------------
|
|
153
|
+
// Deliberate: adding a code REQUIRES updating this list in the same change so
|
|
154
|
+
// the addition is reviewed; removing or renaming one must fail loudly forever.
|
|
155
|
+
|
|
156
|
+
test("PLUGIN_ERROR_CODES matches the reviewed snapshot (append-only contract)", () => {
|
|
157
|
+
assert.deepEqual([...PLUGIN_ERROR_CODES], [
|
|
158
|
+
"VALIDATION",
|
|
159
|
+
"INVALID_RPC_FORMAT",
|
|
160
|
+
"METHOD_NOT_FOUND",
|
|
161
|
+
"METHOD_NOT_PERMITTED",
|
|
162
|
+
"HANDLE_INVALID",
|
|
163
|
+
"HANDLE_KIND_MISMATCH",
|
|
164
|
+
"RESOURCE_QUOTA_EXCEEDED",
|
|
165
|
+
"RATE_LIMITED",
|
|
166
|
+
"PRECONDITION_FAILED",
|
|
167
|
+
"OPERATION_FAILED",
|
|
168
|
+
"TIMEOUT",
|
|
169
|
+
"CALL_TIMEOUT",
|
|
170
|
+
"TRANSPORT_LOST",
|
|
171
|
+
"PLUGIN_NOT_READY",
|
|
172
|
+
"PLUGIN_TERMINATED",
|
|
173
|
+
"RESULT_NOT_SERIALIZABLE",
|
|
174
|
+
"RESULT_TOO_LARGE",
|
|
175
|
+
"BATCH_PARTIAL",
|
|
176
|
+
"STORY_UPDATE_FAILED",
|
|
177
|
+
"STORY_HEIGHT_REJECTED",
|
|
178
|
+
"NO_ACTIVE_STRUCTURE",
|
|
179
|
+
"NO_ELIGIBLE_ELEMENTS",
|
|
180
|
+
"PROPOSAL_SWITCH_BLOCKED",
|
|
181
|
+
"INTERNAL",
|
|
182
|
+
"UNKNOWN",
|
|
183
|
+
])
|
|
184
|
+
})
|
package/tsconfig.json
CHANGED
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
"target": "ES2020",
|
|
4
4
|
"module": "ES2020",
|
|
5
5
|
"moduleResolution": "bundler",
|
|
6
|
-
"lib": [
|
|
6
|
+
"lib": [
|
|
7
|
+
"ES2020",
|
|
8
|
+
"ESNext.Disposable"
|
|
9
|
+
],
|
|
7
10
|
"strict": true,
|
|
8
11
|
"esModuleInterop": true,
|
|
9
12
|
"skipLibCheck": true,
|
|
@@ -13,5 +16,7 @@
|
|
|
13
16
|
"declarationMap": true,
|
|
14
17
|
"outDir": "dist"
|
|
15
18
|
},
|
|
16
|
-
"include": [
|
|
19
|
+
"include": [
|
|
20
|
+
"src/**/*.ts"
|
|
21
|
+
]
|
|
17
22
|
}
|