every-plugin 0.8.3 → 0.8.5
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/dist/_virtual/rolldown_runtime.cjs +1 -7
- package/dist/_virtual/rolldown_runtime.mjs +1 -7
- package/dist/build/rspack/dev-server-middleware.cjs.map +1 -1
- package/dist/build/rspack/dev-server-middleware.mjs.map +1 -1
- package/dist/build/rspack/index.cjs +7 -1
- package/dist/build/rspack/index.d.cts +2 -1
- package/dist/build/rspack/index.d.mts +2 -1
- package/dist/build/rspack/index.mjs +2 -1
- package/dist/build/rspack/module-federation.cjs +2 -33
- package/dist/build/rspack/module-federation.cjs.map +1 -1
- package/dist/build/rspack/module-federation.mjs +2 -33
- package/dist/build/rspack/module-federation.mjs.map +1 -1
- package/dist/build/rspack/plugin.cjs +2 -2
- package/dist/build/rspack/plugin.cjs.map +1 -1
- package/dist/build/rspack/plugin.d.cts.map +1 -1
- package/dist/build/rspack/plugin.d.mts.map +1 -1
- package/dist/build/rspack/plugin.mjs.map +1 -1
- package/dist/build/rspack/utils.cjs +2 -2
- package/dist/build/rspack/utils.cjs.map +1 -1
- package/dist/build/shared-deps.cjs +77 -0
- package/dist/build/shared-deps.cjs.map +1 -0
- package/dist/build/shared-deps.d.cts +16 -0
- package/dist/build/shared-deps.d.cts.map +1 -0
- package/dist/build/shared-deps.d.mts +16 -0
- package/dist/build/shared-deps.d.mts.map +1 -0
- package/dist/build/shared-deps.mjs +73 -0
- package/dist/build/shared-deps.mjs.map +1 -0
- package/dist/errors.cjs +105 -79
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts +164 -5
- package/dist/errors.d.cts.map +1 -1
- package/dist/errors.d.mts +164 -5
- package/dist/errors.d.mts.map +1 -1
- package/dist/errors.mjs +97 -81
- package/dist/errors.mjs.map +1 -1
- package/dist/index.cjs +10 -0
- package/dist/index.d.cts +3 -3
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +3 -3
- package/dist/orpc.cjs +15 -15
- package/dist/package.cjs +28 -10
- package/dist/package.cjs.map +1 -1
- package/dist/package.mjs +23 -11
- package/dist/package.mjs.map +1 -1
- package/dist/plugin.cjs +6 -3
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.d.cts +5 -5
- package/dist/plugin.d.cts.map +1 -1
- package/dist/plugin.d.mts +5 -5
- package/dist/plugin.d.mts.map +1 -1
- package/dist/plugin.mjs +4 -1
- package/dist/plugin.mjs.map +1 -1
- package/dist/runtime/errors.cjs +22 -3
- package/dist/runtime/errors.cjs.map +1 -1
- package/dist/runtime/errors.d.cts +11 -5
- package/dist/runtime/errors.d.cts.map +1 -1
- package/dist/runtime/errors.d.mts +11 -5
- package/dist/runtime/errors.d.mts.map +1 -1
- package/dist/runtime/errors.mjs +20 -2
- package/dist/runtime/errors.mjs.map +1 -1
- package/dist/runtime/index.cjs +2 -2
- package/dist/runtime/index.cjs.map +1 -1
- package/dist/runtime/index.d.cts.map +1 -1
- package/dist/runtime/index.d.mts.map +1 -1
- package/dist/runtime/index.mjs.map +1 -1
- package/dist/runtime/services/module-federation.service.cjs +11 -14
- package/dist/runtime/services/module-federation.service.cjs.map +1 -1
- package/dist/runtime/services/module-federation.service.d.cts.map +1 -1
- package/dist/runtime/services/module-federation.service.d.mts.map +1 -1
- package/dist/runtime/services/module-federation.service.mjs +6 -9
- package/dist/runtime/services/module-federation.service.mjs.map +1 -1
- package/dist/runtime/services/normalize.d.cts.map +1 -1
- package/dist/runtime/services/normalize.d.mts.map +1 -1
- package/dist/runtime/services/plugin-lifecycle.service.d.cts.map +1 -1
- package/dist/runtime/services/plugin-lifecycle.service.d.mts.map +1 -1
- package/dist/runtime/services/plugin-loader.service.d.cts.map +1 -1
- package/dist/runtime/services/plugin-loader.service.d.mts.map +1 -1
- package/dist/runtime/services/plugin.service.d.cts.map +1 -1
- package/dist/runtime/services/plugin.service.d.mts.map +1 -1
- package/dist/runtime/services/secrets.service.cjs.map +1 -1
- package/dist/runtime/services/secrets.service.d.cts.map +1 -1
- package/dist/runtime/services/secrets.service.d.mts.map +1 -1
- package/dist/runtime/services/secrets.service.mjs.map +1 -1
- package/dist/testing/index.cjs.map +1 -1
- package/dist/testing/index.d.cts.map +1 -1
- package/dist/testing/index.d.mts.map +1 -1
- package/dist/testing/index.mjs.map +1 -1
- package/dist/types.d.cts +26 -27
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +26 -27
- package/dist/types.d.mts.map +1 -1
- package/dist/zod.d.cts.map +1 -1
- package/dist/zod.d.mts.map +1 -1
- package/package.json +54 -24
package/dist/package.mjs
CHANGED
|
@@ -1,17 +1,29 @@
|
|
|
1
1
|
//#region package.json
|
|
2
|
-
var version = "0.8.
|
|
2
|
+
var version = "0.8.4";
|
|
3
3
|
var dependencies = {
|
|
4
|
-
"@module-federation/enhanced": "^0.
|
|
5
|
-
"@module-federation/node": "^2.7.
|
|
6
|
-
"@module-federation/runtime-core": "^0.
|
|
7
|
-
"@orpc/
|
|
8
|
-
"@orpc/
|
|
9
|
-
"@orpc/
|
|
10
|
-
"@orpc/
|
|
11
|
-
"
|
|
12
|
-
"
|
|
4
|
+
"@module-federation/enhanced": "^0.22.1",
|
|
5
|
+
"@module-federation/node": "^2.7.27",
|
|
6
|
+
"@module-federation/runtime-core": "^0.22.1",
|
|
7
|
+
"@orpc/client": "^1.12.3",
|
|
8
|
+
"@orpc/contract": "^1.13.4",
|
|
9
|
+
"@orpc/experimental-publisher": "^1.13.4",
|
|
10
|
+
"@orpc/openapi": "^1.12.3",
|
|
11
|
+
"@orpc/react-query": "^1.13.4",
|
|
12
|
+
"@orpc/server": "^1.13.4",
|
|
13
|
+
"@orpc/tanstack-query": "^1.13.4",
|
|
14
|
+
"@orpc/zod": "^1.13.4",
|
|
15
|
+
"effect": "3.19.14",
|
|
16
|
+
"zod": "4.3.5"
|
|
13
17
|
};
|
|
18
|
+
var sharedDependencies = { "ui": {
|
|
19
|
+
"react": "^19.2.0",
|
|
20
|
+
"react-dom": "^19.2.0",
|
|
21
|
+
"@tanstack/react-query": "^5.90.11",
|
|
22
|
+
"@tanstack/react-router": "^1.139.14",
|
|
23
|
+
"@hot-labs/near-connect": "^0.6.11",
|
|
24
|
+
"near-kit": "^0.7.0"
|
|
25
|
+
} };
|
|
14
26
|
|
|
15
27
|
//#endregion
|
|
16
|
-
export { dependencies, version };
|
|
28
|
+
export { dependencies, sharedDependencies, version };
|
|
17
29
|
//# sourceMappingURL=package.mjs.map
|
package/dist/package.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package.mjs","names":[],"sources":["../package.json"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"package.mjs","names":[],"sources":["../package.json"],"sourcesContent":[""],"mappings":""}
|
package/dist/plugin.cjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_errors = require('./runtime/errors.cjs');
|
|
3
|
+
let _orpc_contract = require("@orpc/contract");
|
|
3
4
|
let effect = require("effect");
|
|
4
|
-
let
|
|
5
|
+
let _orpc_server = require("@orpc/server");
|
|
5
6
|
|
|
6
7
|
//#region src/plugin.ts
|
|
7
8
|
/**
|
|
@@ -31,10 +32,12 @@ function createPlugin(config) {
|
|
|
31
32
|
});
|
|
32
33
|
}
|
|
33
34
|
createRouter(deps) {
|
|
34
|
-
const base =
|
|
35
|
+
const base = _orpc_server.os.$context().use((0, _orpc_server.onError)((error) => {
|
|
36
|
+
const unwrapped = require_errors.extractFromFiberFailure(error);
|
|
37
|
+
if (unwrapped !== error && unwrapped instanceof _orpc_contract.ORPCError) throw unwrapped;
|
|
35
38
|
require_errors.formatORPCError(error);
|
|
36
39
|
}));
|
|
37
|
-
const builder = (0,
|
|
40
|
+
const builder = (0, _orpc_server.implement)(config.contract, base);
|
|
38
41
|
return config.createRouter(deps, builder);
|
|
39
42
|
}
|
|
40
43
|
}
|
package/dist/plugin.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs","names":["
|
|
1
|
+
{"version":3,"file":"plugin.cjs","names":["Effect","os","extractFromFiberFailure","ORPCError"],"sources":["../src/plugin.ts"],"sourcesContent":["import type { AnyContractRouter, AnySchema, InferSchemaOutput } from \"@orpc/contract\";\nimport type { Context, Implementer, Router } from \"@orpc/server\";\nimport { ORPCError } from \"@orpc/contract\";\nimport { implement, onError, os } from \"@orpc/server\";\nimport { Effect, type Scope } from \"effect\";\nimport { extractFromFiberFailure, formatORPCError } from \"./runtime/errors\";\n\ntype ContextOutput<T> = T extends AnySchema ? InferSchemaOutput<T> : {};\n\n/**\n * Helper type that correctly constructs the config schema type\n */\nexport type PluginConfigFor<V extends AnySchema, S extends AnySchema, TRequestContext extends AnySchema | undefined> = {\n\tvariables: V;\n\tsecrets: S;\n\tcontext: TRequestContext;\n};\n\n/**\n * Loaded plugin with static binding property\n */\nexport interface LoadedPluginWithBinding<\n\tTContract extends AnyContractRouter,\n\tTVariables extends AnySchema,\n\tTSecrets extends AnySchema,\n\tTRequestContext extends AnySchema | undefined,\n\tTDeps extends Context = Record<never, never>\n> {\n\tnew(): Plugin<TContract, TVariables, TSecrets, TRequestContext, TDeps>;\n\tbinding: {\n\t\tcontract: TContract;\n\t\tvariables: TVariables;\n\t\tsecrets: TSecrets;\n\t\tcontext: TRequestContext;\n\t};\n}\n\n/**\n * Plugin interface\n */\nexport interface Plugin<\n\tTContract extends AnyContractRouter,\n\tTVariables extends AnySchema,\n\tTSecrets extends AnySchema,\n\tTRequestContext extends AnySchema | undefined,\n\tTDeps extends Context = Record<never, never>\n> {\n\treadonly id: string;\n\treadonly contract: TContract;\n\treadonly configSchema: PluginConfigFor<TVariables, TSecrets, TRequestContext>;\n\n\t// Plugin lifecycle\n\tinitialize(\n\t\tconfig: { variables: InferSchemaOutput<TVariables>; secrets: InferSchemaOutput<TSecrets> }\n\t): Effect.Effect<TDeps, unknown, Scope.Scope>;\n\n\tshutdown(): Effect.Effect<void, never>;\n\n\t/**\n\t * Creates the strongly-typed oRPC router for this plugin.\n\t * The router's procedure types are inferred directly from the contract.\n\t * @param deps The initialized plugin dependencies\n\t * @returns A router with procedures matching the plugin's contract\n\t */\n\tcreateRouter(deps: TDeps): Router<TContract, any>;\n}\n\n/**\n * Factory function to create plugins\n */\nexport function createPlugin<\n\tV extends AnySchema,\n\tS extends AnySchema,\n\tTContract extends AnyContractRouter,\n\tTRequestContext extends AnySchema | undefined = undefined,\n\tTDeps extends Context = Record<never, never>\n>(config: {\n\tvariables: V;\n\tsecrets: S;\n\tcontract: TContract;\n\tcontext?: TRequestContext;\n\tinitialize?: (\n\t\tconfig: { variables: InferSchemaOutput<V>; secrets: InferSchemaOutput<S> }\n\t) => Effect.Effect<TDeps, Error, Scope.Scope>;\n\tcreateRouter: (\n\t\tdeps: TDeps,\n\t\tbuilder: Implementer<TContract, ContextOutput<TRequestContext>, ContextOutput<TRequestContext>>\n\t) => Router<TContract, any>;\n\tshutdown?: (deps: TDeps) => Effect.Effect<void, Error, never>;\n}) {\n\tconst configSchema: PluginConfigFor<V, S, TRequestContext> = {\n\t\tvariables: config.variables,\n\t\tsecrets: config.secrets,\n\t\tcontext: config.context as TRequestContext\n\t};\n\n\tclass CreatedPlugin implements Plugin<TContract, V, S, TRequestContext, TDeps> {\n\t\t/** set during instantiation - registry key */\n\t\tid!: string;\n\t\treadonly contract = config.contract;\n\t\treadonly configSchema = configSchema;\n\n\t\tprivate _deps: TDeps | null = null;\n\n\t\tinitialize(\n\t\t\tpluginConfig: { variables: InferSchemaOutput<V>; secrets: InferSchemaOutput<S> }\n\t\t): Effect.Effect<TDeps, unknown, Scope.Scope> {\n\t\t\tconst init = config.initialize ?? (() => Effect.succeed({} as TDeps));\n\n\t\t\treturn init(pluginConfig).pipe(\n\t\t\t\tEffect.tap((deps) => Effect.sync(() => { this._deps = deps; })),\n\t\t\t\tEffect.map(() => this._deps as TDeps),\n\t\t\t\tEffect.mapError((error) => error as unknown)\n\t\t\t);\n\t\t}\n\n\t\tshutdown(): Effect.Effect<void, never> {\n\t\t\tconst self = this;\n\t\t\treturn Effect.gen(function* () {\n\t\t\t\tif (config.shutdown && self._deps) {\n\t\t\t\t\tyield* config.shutdown(self._deps).pipe(\n\t\t\t\t\t\tEffect.catchAll(() => Effect.void)\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\n\t\tcreateRouter(deps: TDeps): Router<TContract, any> {\n\t\t\tconst base = os\n\t\t\t\t.$context<ContextOutput<TRequestContext>>()\n\t\t\t\t.use(onError((error) => {\n\t\t\t\t\tconst unwrapped = extractFromFiberFailure(error);\n\t\t\t\t\t\n\t\t\t\t\tif (unwrapped !== error && unwrapped instanceof ORPCError) {\n\t\t\t\t\t\tthrow unwrapped;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tformatORPCError(error);\n\t\t\t\t}));\n\t\t\tconst builder = implement(config.contract, base);\n\t\t\tconst router = config.createRouter(deps, builder);\n\t\t\treturn router as Router<TContract, any>;\n\t\t}\n\t}\n\n\tconst PluginConstructor = CreatedPlugin as unknown as {\n\t\tnew(): Plugin<TContract, V, S, TRequestContext, TDeps>;\n\t\tbinding: {\n\t\t\tcontract: TContract;\n\t\t\tvariables: V;\n\t\t\tsecrets: S;\n\t\t\tcontext: TRequestContext;\n\t\t};\n\t};\n\n\tPluginConstructor.binding = {\n\t\tcontract: config.contract,\n\t\tvariables: config.variables,\n\t\tsecrets: config.secrets,\n\t\tcontext: config.context as TRequestContext\n\t};\n\n\treturn PluginConstructor as LoadedPluginWithBinding<TContract, V, S, TRequestContext, TDeps>;\n}\n"],"mappings":";;;;;;;;;;AAsEA,SAAgB,aAMd,QAaC;CACF,MAAM,eAAuD;EAC5D,WAAW,OAAO;EAClB,SAAS,OAAO;EAChB,SAAS,OAAO;EAChB;CAED,MAAM,cAAyE;;EAE9E;EACA,AAAS,WAAW,OAAO;EAC3B,AAAS,eAAe;EAExB,AAAQ,QAAsB;EAE9B,WACC,cAC6C;AAG7C,WAFa,OAAO,qBAAqBA,cAAO,QAAQ,EAAE,CAAU,GAExD,aAAa,CAAC,KACzBA,cAAO,KAAK,SAASA,cAAO,WAAW;AAAE,SAAK,QAAQ;KAAQ,CAAC,EAC/DA,cAAO,UAAU,KAAK,MAAe,EACrCA,cAAO,UAAU,UAAU,MAAiB,CAC5C;;EAGF,WAAuC;GACtC,MAAM,OAAO;AACb,UAAOA,cAAO,IAAI,aAAa;AAC9B,QAAI,OAAO,YAAY,KAAK,MAC3B,QAAO,OAAO,SAAS,KAAK,MAAM,CAAC,KAClCA,cAAO,eAAeA,cAAO,KAAK,CAClC;KAED;;EAGH,aAAa,MAAqC;GACjD,MAAM,OAAOC,gBACX,UAA0C,CAC1C,+BAAa,UAAU;IACvB,MAAM,YAAYC,uCAAwB,MAAM;AAEhD,QAAI,cAAc,SAAS,qBAAqBC,yBAC/C,OAAM;AAGP,mCAAgB,MAAM;KACrB,CAAC;GACJ,MAAM,sCAAoB,OAAO,UAAU,KAAK;AAEhD,UADe,OAAO,aAAa,MAAM,QAAQ;;;CAKnD,MAAM,oBAAoB;AAU1B,mBAAkB,UAAU;EAC3B,UAAU,OAAO;EACjB,WAAW,OAAO;EAClB,SAAS,OAAO;EAChB,SAAS,OAAO;EAChB;AAED,QAAO"}
|
package/dist/plugin.d.cts
CHANGED
|
@@ -37,11 +37,11 @@ interface Plugin<TContract extends AnyContractRouter, TVariables extends AnySche
|
|
|
37
37
|
}): Effect.Effect<TDeps, unknown, Scope.Scope>;
|
|
38
38
|
shutdown(): Effect.Effect<void, never>;
|
|
39
39
|
/**
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
* Creates the strongly-typed oRPC router for this plugin.
|
|
41
|
+
* The router's procedure types are inferred directly from the contract.
|
|
42
|
+
* @param deps The initialized plugin dependencies
|
|
43
|
+
* @returns A router with procedures matching the plugin's contract
|
|
44
|
+
*/
|
|
45
45
|
createRouter(deps: TDeps): Router<TContract, any>;
|
|
46
46
|
}
|
|
47
47
|
/**
|
package/dist/plugin.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.cts","names":[],"sources":["../src/plugin.ts"],"
|
|
1
|
+
{"version":3,"file":"plugin.d.cts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;;;KAOK,aAAA,MAAmB,CAAA,SAAU,SAAA,GAAY,iBAAA,CAAkB,CAAA;AAAA;;;AAAA,KAKpD,eAAA,WAA0B,SAAA,YAAqB,SAAA,0BAAmC,SAAA;EAAA,SAAA,EAClF,CAAA;EAAA,OAAA,EACF,CAAA;EAAA,OAAA,EACA,eAAA;AAAA;AAAA;;AAMV;AANU,UAMO,uBAAA,mBACE,iBAAA,qBACC,SAAA,mBACF,SAAA,0BACO,SAAA,4BACV,SAAA,GAAU,MAAA;EAAA,QAEjB,MAAA,CAAO,SAAA,EAAW,UAAA,EAAY,QAAA,EAAU,eAAA,EAAiB,KAAA;EAAA,OAAA;IAAA,QAAA,EAErD,SAAA;IAAA,SAAA,EACC,UAAA;IAAA,OAAA,EACF,QAAA;IAAA,OAAA,EACA,eAAA;EAAA;AAAA;AAAA;;AAOX;AAPW,UAOM,MAAA,mBACE,iBAAA,qBACC,SAAA,mBACF,SAAA,0BACO,SAAA,4BACV,SAAA,GAAU,MAAA;EAAA,SAAA,EAAA;EAAA,SAAA,QAAA,EAGL,SAAA;EAAA,SAAA,YAAA,EACI,eAAA,CAAgB,UAAA,EAAY,QAAA,EAAU,eAAA;EAAA,UAAA,CAAA,MAAA;IAAA,SAAA,EAIvC,iBAAA,CAAkB,UAAA;IAAA,OAAA,EAAsB,iBAAA,CAAkB,QAAA;EAAA,IAC7E,MAAA,CAAO,MAAA,CAAO,KAAA,WAAgB,KAAA,CAAM,KAAA;EAAA,QAAA,IAE3B,MAAA,CAAO,MAAA;EAAA;;;;;AAcpB;EAdoB,YAAA,CAAA,IAAA,EAQA,KAAA,GAAQ,MAAA,CAAO,SAAA;AAAA;AAAA;;;AAAA,iBAMnB,YAAA,WACL,SAAA,YACA,SAAA,oBACQ,iBAAA,0BACM,SAAA,wCACV,SAAA,GAAU,MAAA,eAAA,CAAA,MAAA;EAAA,SAAA,EAEb,CAAA;EAAA,OAAA,EACF,CAAA;EAAA,QAAA,EACC,SAAA;EAAA,OAAA,GACA,eAAA;EAAA,UAAA,IAAA,MAAA;IAAA,SAAA,EAEY,iBAAA,CAAkB,CAAA;IAAA,OAAA,EAAa,iBAAA,CAAkB,CAAA;EAAA,MAClE,MAAA,CAAO,MAAA,CAAO,KAAA,EAAO,KAAA,EAAO,KAAA,CAAM,KAAA;EAAA,YAAA,GAAA,IAAA,EAEhC,KAAA,EAAA,OAAA,EACG,WAAA,CAAY,SAAA,EAAW,aAAA,CAAc,eAAA,GAAkB,aAAA,CAAc,eAAA,OAC1E,MAAA,CAAO,SAAA;EAAA,QAAA,IAAA,IAAA,EACM,KAAA,KAAU,MAAA,CAAO,MAAA,OAAa,KAAA;AAAA,IA0EpB,uBAAA,CAAwB,SAAA,EAAW,CAAA,EAAG,CAAA,EAAG,eAAA,EAAiB,KAAA"}
|
package/dist/plugin.d.mts
CHANGED
|
@@ -37,11 +37,11 @@ interface Plugin<TContract extends AnyContractRouter, TVariables extends AnySche
|
|
|
37
37
|
}): Effect.Effect<TDeps, unknown, Scope.Scope>;
|
|
38
38
|
shutdown(): Effect.Effect<void, never>;
|
|
39
39
|
/**
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
* Creates the strongly-typed oRPC router for this plugin.
|
|
41
|
+
* The router's procedure types are inferred directly from the contract.
|
|
42
|
+
* @param deps The initialized plugin dependencies
|
|
43
|
+
* @returns A router with procedures matching the plugin's contract
|
|
44
|
+
*/
|
|
45
45
|
createRouter(deps: TDeps): Router<TContract, any>;
|
|
46
46
|
}
|
|
47
47
|
/**
|
package/dist/plugin.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.mts","names":[],"sources":["../src/plugin.ts"],"
|
|
1
|
+
{"version":3,"file":"plugin.d.mts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;;;KAOK,aAAA,MAAmB,CAAA,SAAU,SAAA,GAAY,iBAAA,CAAkB,CAAA;AAAA;;;AAAA,KAKpD,eAAA,WAA0B,SAAA,YAAqB,SAAA,0BAAmC,SAAA;EAAA,SAAA,EAClF,CAAA;EAAA,OAAA,EACF,CAAA;EAAA,OAAA,EACA,eAAA;AAAA;AAAA;;AAMV;AANU,UAMO,uBAAA,mBACE,iBAAA,qBACC,SAAA,mBACF,SAAA,0BACO,SAAA,4BACV,SAAA,GAAU,MAAA;EAAA,QAEjB,MAAA,CAAO,SAAA,EAAW,UAAA,EAAY,QAAA,EAAU,eAAA,EAAiB,KAAA;EAAA,OAAA;IAAA,QAAA,EAErD,SAAA;IAAA,SAAA,EACC,UAAA;IAAA,OAAA,EACF,QAAA;IAAA,OAAA,EACA,eAAA;EAAA;AAAA;AAAA;;AAOX;AAPW,UAOM,MAAA,mBACE,iBAAA,qBACC,SAAA,mBACF,SAAA,0BACO,SAAA,4BACV,SAAA,GAAU,MAAA;EAAA,SAAA,EAAA;EAAA,SAAA,QAAA,EAGL,SAAA;EAAA,SAAA,YAAA,EACI,eAAA,CAAgB,UAAA,EAAY,QAAA,EAAU,eAAA;EAAA,UAAA,CAAA,MAAA;IAAA,SAAA,EAIvC,iBAAA,CAAkB,UAAA;IAAA,OAAA,EAAsB,iBAAA,CAAkB,QAAA;EAAA,IAC7E,MAAA,CAAO,MAAA,CAAO,KAAA,WAAgB,KAAA,CAAM,KAAA;EAAA,QAAA,IAE3B,MAAA,CAAO,MAAA;EAAA;;;;;AAcpB;EAdoB,YAAA,CAAA,IAAA,EAQA,KAAA,GAAQ,MAAA,CAAO,SAAA;AAAA;AAAA;;;AAAA,iBAMnB,YAAA,WACL,SAAA,YACA,SAAA,oBACQ,iBAAA,0BACM,SAAA,wCACV,SAAA,GAAU,MAAA,eAAA,CAAA,MAAA;EAAA,SAAA,EAEb,CAAA;EAAA,OAAA,EACF,CAAA;EAAA,QAAA,EACC,SAAA;EAAA,OAAA,GACA,eAAA;EAAA,UAAA,IAAA,MAAA;IAAA,SAAA,EAEY,iBAAA,CAAkB,CAAA;IAAA,OAAA,EAAa,iBAAA,CAAkB,CAAA;EAAA,MAClE,MAAA,CAAO,MAAA,CAAO,KAAA,EAAO,KAAA,EAAO,KAAA,CAAM,KAAA;EAAA,YAAA,GAAA,IAAA,EAEhC,KAAA,EAAA,OAAA,EACG,WAAA,CAAY,SAAA,EAAW,aAAA,CAAc,eAAA,GAAkB,aAAA,CAAc,eAAA,OAC1E,MAAA,CAAO,SAAA;EAAA,QAAA,IAAA,IAAA,EACM,KAAA,KAAU,MAAA,CAAO,MAAA,OAAa,KAAA;AAAA,IA0EpB,uBAAA,CAAwB,SAAA,EAAW,CAAA,EAAG,CAAA,EAAG,eAAA,EAAiB,KAAA"}
|
package/dist/plugin.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { formatORPCError } from "./runtime/errors.mjs";
|
|
1
|
+
import { extractFromFiberFailure, formatORPCError } from "./runtime/errors.mjs";
|
|
2
|
+
import { ORPCError } from "@orpc/contract";
|
|
2
3
|
import { Effect } from "effect";
|
|
3
4
|
import { implement, onError, os } from "@orpc/server";
|
|
4
5
|
|
|
@@ -31,6 +32,8 @@ function createPlugin(config) {
|
|
|
31
32
|
}
|
|
32
33
|
createRouter(deps) {
|
|
33
34
|
const base = os.$context().use(onError((error) => {
|
|
35
|
+
const unwrapped = extractFromFiberFailure(error);
|
|
36
|
+
if (unwrapped !== error && unwrapped instanceof ORPCError) throw unwrapped;
|
|
34
37
|
formatORPCError(error);
|
|
35
38
|
}));
|
|
36
39
|
const builder = implement(config.contract, base);
|
package/dist/plugin.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.mjs","names":[
|
|
1
|
+
{"version":3,"file":"plugin.mjs","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import type { AnyContractRouter, AnySchema, InferSchemaOutput } from \"@orpc/contract\";\nimport type { Context, Implementer, Router } from \"@orpc/server\";\nimport { ORPCError } from \"@orpc/contract\";\nimport { implement, onError, os } from \"@orpc/server\";\nimport { Effect, type Scope } from \"effect\";\nimport { extractFromFiberFailure, formatORPCError } from \"./runtime/errors\";\n\ntype ContextOutput<T> = T extends AnySchema ? InferSchemaOutput<T> : {};\n\n/**\n * Helper type that correctly constructs the config schema type\n */\nexport type PluginConfigFor<V extends AnySchema, S extends AnySchema, TRequestContext extends AnySchema | undefined> = {\n\tvariables: V;\n\tsecrets: S;\n\tcontext: TRequestContext;\n};\n\n/**\n * Loaded plugin with static binding property\n */\nexport interface LoadedPluginWithBinding<\n\tTContract extends AnyContractRouter,\n\tTVariables extends AnySchema,\n\tTSecrets extends AnySchema,\n\tTRequestContext extends AnySchema | undefined,\n\tTDeps extends Context = Record<never, never>\n> {\n\tnew(): Plugin<TContract, TVariables, TSecrets, TRequestContext, TDeps>;\n\tbinding: {\n\t\tcontract: TContract;\n\t\tvariables: TVariables;\n\t\tsecrets: TSecrets;\n\t\tcontext: TRequestContext;\n\t};\n}\n\n/**\n * Plugin interface\n */\nexport interface Plugin<\n\tTContract extends AnyContractRouter,\n\tTVariables extends AnySchema,\n\tTSecrets extends AnySchema,\n\tTRequestContext extends AnySchema | undefined,\n\tTDeps extends Context = Record<never, never>\n> {\n\treadonly id: string;\n\treadonly contract: TContract;\n\treadonly configSchema: PluginConfigFor<TVariables, TSecrets, TRequestContext>;\n\n\t// Plugin lifecycle\n\tinitialize(\n\t\tconfig: { variables: InferSchemaOutput<TVariables>; secrets: InferSchemaOutput<TSecrets> }\n\t): Effect.Effect<TDeps, unknown, Scope.Scope>;\n\n\tshutdown(): Effect.Effect<void, never>;\n\n\t/**\n\t * Creates the strongly-typed oRPC router for this plugin.\n\t * The router's procedure types are inferred directly from the contract.\n\t * @param deps The initialized plugin dependencies\n\t * @returns A router with procedures matching the plugin's contract\n\t */\n\tcreateRouter(deps: TDeps): Router<TContract, any>;\n}\n\n/**\n * Factory function to create plugins\n */\nexport function createPlugin<\n\tV extends AnySchema,\n\tS extends AnySchema,\n\tTContract extends AnyContractRouter,\n\tTRequestContext extends AnySchema | undefined = undefined,\n\tTDeps extends Context = Record<never, never>\n>(config: {\n\tvariables: V;\n\tsecrets: S;\n\tcontract: TContract;\n\tcontext?: TRequestContext;\n\tinitialize?: (\n\t\tconfig: { variables: InferSchemaOutput<V>; secrets: InferSchemaOutput<S> }\n\t) => Effect.Effect<TDeps, Error, Scope.Scope>;\n\tcreateRouter: (\n\t\tdeps: TDeps,\n\t\tbuilder: Implementer<TContract, ContextOutput<TRequestContext>, ContextOutput<TRequestContext>>\n\t) => Router<TContract, any>;\n\tshutdown?: (deps: TDeps) => Effect.Effect<void, Error, never>;\n}) {\n\tconst configSchema: PluginConfigFor<V, S, TRequestContext> = {\n\t\tvariables: config.variables,\n\t\tsecrets: config.secrets,\n\t\tcontext: config.context as TRequestContext\n\t};\n\n\tclass CreatedPlugin implements Plugin<TContract, V, S, TRequestContext, TDeps> {\n\t\t/** set during instantiation - registry key */\n\t\tid!: string;\n\t\treadonly contract = config.contract;\n\t\treadonly configSchema = configSchema;\n\n\t\tprivate _deps: TDeps | null = null;\n\n\t\tinitialize(\n\t\t\tpluginConfig: { variables: InferSchemaOutput<V>; secrets: InferSchemaOutput<S> }\n\t\t): Effect.Effect<TDeps, unknown, Scope.Scope> {\n\t\t\tconst init = config.initialize ?? (() => Effect.succeed({} as TDeps));\n\n\t\t\treturn init(pluginConfig).pipe(\n\t\t\t\tEffect.tap((deps) => Effect.sync(() => { this._deps = deps; })),\n\t\t\t\tEffect.map(() => this._deps as TDeps),\n\t\t\t\tEffect.mapError((error) => error as unknown)\n\t\t\t);\n\t\t}\n\n\t\tshutdown(): Effect.Effect<void, never> {\n\t\t\tconst self = this;\n\t\t\treturn Effect.gen(function* () {\n\t\t\t\tif (config.shutdown && self._deps) {\n\t\t\t\t\tyield* config.shutdown(self._deps).pipe(\n\t\t\t\t\t\tEffect.catchAll(() => Effect.void)\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\n\t\tcreateRouter(deps: TDeps): Router<TContract, any> {\n\t\t\tconst base = os\n\t\t\t\t.$context<ContextOutput<TRequestContext>>()\n\t\t\t\t.use(onError((error) => {\n\t\t\t\t\tconst unwrapped = extractFromFiberFailure(error);\n\t\t\t\t\t\n\t\t\t\t\tif (unwrapped !== error && unwrapped instanceof ORPCError) {\n\t\t\t\t\t\tthrow unwrapped;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tformatORPCError(error);\n\t\t\t\t}));\n\t\t\tconst builder = implement(config.contract, base);\n\t\t\tconst router = config.createRouter(deps, builder);\n\t\t\treturn router as Router<TContract, any>;\n\t\t}\n\t}\n\n\tconst PluginConstructor = CreatedPlugin as unknown as {\n\t\tnew(): Plugin<TContract, V, S, TRequestContext, TDeps>;\n\t\tbinding: {\n\t\t\tcontract: TContract;\n\t\t\tvariables: V;\n\t\t\tsecrets: S;\n\t\t\tcontext: TRequestContext;\n\t\t};\n\t};\n\n\tPluginConstructor.binding = {\n\t\tcontract: config.contract,\n\t\tvariables: config.variables,\n\t\tsecrets: config.secrets,\n\t\tcontext: config.context as TRequestContext\n\t};\n\n\treturn PluginConstructor as LoadedPluginWithBinding<TContract, V, S, TRequestContext, TDeps>;\n}\n"],"mappings":";;;;;;;;;AAsEA,SAAgB,aAMd,QAaC;CACF,MAAM,eAAuD;EAC5D,WAAW,OAAO;EAClB,SAAS,OAAO;EAChB,SAAS,OAAO;EAChB;CAED,MAAM,cAAyE;;EAE9E;EACA,AAAS,WAAW,OAAO;EAC3B,AAAS,eAAe;EAExB,AAAQ,QAAsB;EAE9B,WACC,cAC6C;AAG7C,WAFa,OAAO,qBAAqB,OAAO,QAAQ,EAAE,CAAU,GAExD,aAAa,CAAC,KACzB,OAAO,KAAK,SAAS,OAAO,WAAW;AAAE,SAAK,QAAQ;KAAQ,CAAC,EAC/D,OAAO,UAAU,KAAK,MAAe,EACrC,OAAO,UAAU,UAAU,MAAiB,CAC5C;;EAGF,WAAuC;GACtC,MAAM,OAAO;AACb,UAAO,OAAO,IAAI,aAAa;AAC9B,QAAI,OAAO,YAAY,KAAK,MAC3B,QAAO,OAAO,SAAS,KAAK,MAAM,CAAC,KAClC,OAAO,eAAe,OAAO,KAAK,CAClC;KAED;;EAGH,aAAa,MAAqC;GACjD,MAAM,OAAO,GACX,UAA0C,CAC1C,IAAI,SAAS,UAAU;IACvB,MAAM,YAAY,wBAAwB,MAAM;AAEhD,QAAI,cAAc,SAAS,qBAAqB,UAC/C,OAAM;AAGP,oBAAgB,MAAM;KACrB,CAAC;GACJ,MAAM,UAAU,UAAU,OAAO,UAAU,KAAK;AAEhD,UADe,OAAO,aAAa,MAAM,QAAQ;;;CAKnD,MAAM,oBAAoB;AAU1B,mBAAkB,UAAU;EAC3B,UAAU,OAAO;EACjB,WAAW,OAAO;EAClB,SAAS,OAAO;EAChB,SAAS,OAAO;EAChB;AAED,QAAO"}
|
package/dist/runtime/errors.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let
|
|
2
|
+
let _orpc_contract = require("@orpc/contract");
|
|
3
3
|
let effect = require("effect");
|
|
4
4
|
|
|
5
5
|
//#region src/runtime/errors.ts
|
|
@@ -61,7 +61,7 @@ const formatORPCValidationError = (error) => {
|
|
|
61
61
|
return lines;
|
|
62
62
|
};
|
|
63
63
|
const formatORPCError = (error) => {
|
|
64
|
-
if (!(error instanceof
|
|
64
|
+
if (!(error instanceof _orpc_contract.ORPCError)) return;
|
|
65
65
|
const validationLines = formatORPCValidationError(error);
|
|
66
66
|
if (validationLines) {
|
|
67
67
|
console.error(validationLines.join("\n"));
|
|
@@ -166,8 +166,26 @@ const wrapORPCError = (orpcError, pluginId, procedureName, operation) => {
|
|
|
166
166
|
cause: orpcError
|
|
167
167
|
});
|
|
168
168
|
};
|
|
169
|
+
/**
|
|
170
|
+
* Extracts the underlying error from Effect's FiberFailure wrapper.
|
|
171
|
+
* When Effect.runPromise rejects, errors are wrapped in FiberFailure.
|
|
172
|
+
* This extracts the original error so oRPC can handle it properly.
|
|
173
|
+
*/
|
|
174
|
+
const extractFromFiberFailure = (error) => {
|
|
175
|
+
if (!error || typeof error !== "object") return error;
|
|
176
|
+
if ("cause" in error) {
|
|
177
|
+
const cause = error.cause;
|
|
178
|
+
if (cause && typeof cause === "object" && "_tag" in cause) try {
|
|
179
|
+
const squashed = effect.Cause.squash(cause);
|
|
180
|
+
if (squashed instanceof _orpc_contract.ORPCError) return squashed;
|
|
181
|
+
return squashed;
|
|
182
|
+
} catch {}
|
|
183
|
+
if (cause instanceof _orpc_contract.ORPCError) return cause;
|
|
184
|
+
}
|
|
185
|
+
return error;
|
|
186
|
+
};
|
|
169
187
|
const toPluginRuntimeError = (error, pluginId, procedureName, operation, defaultRetryable = false) => {
|
|
170
|
-
if (error instanceof
|
|
188
|
+
if (error instanceof _orpc_contract.ORPCError) return wrapORPCError(error, pluginId, procedureName, operation);
|
|
171
189
|
if (error instanceof PluginRuntimeError) return error;
|
|
172
190
|
const validationLines = formatORPCValidationError(error);
|
|
173
191
|
if (validationLines) console.error(validationLines.join("\n"));
|
|
@@ -185,6 +203,7 @@ const toPluginRuntimeError = (error, pluginId, procedureName, operation, default
|
|
|
185
203
|
exports.ModuleFederationError = ModuleFederationError;
|
|
186
204
|
exports.PluginRuntimeError = PluginRuntimeError;
|
|
187
205
|
exports.ValidationError = ValidationError;
|
|
206
|
+
exports.extractFromFiberFailure = extractFromFiberFailure;
|
|
188
207
|
exports.formatORPCError = formatORPCError;
|
|
189
208
|
exports.isRetryableORPCCode = isRetryableORPCCode;
|
|
190
209
|
exports.toPluginRuntimeError = toPluginRuntimeError;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.cjs","names":["Data","lines: string[]","ORPCError"],"sources":["../../src/runtime/errors.ts"],"sourcesContent":["import { ORPCError } from \"@orpc/contract\";\nimport { Data } from \"effect\";\nimport type { z } from \"zod\";\n\nexport class PluginRuntimeError extends Data.TaggedError(\"PluginRuntimeError\")<{\n\treadonly pluginId?: string;\n\treadonly operation?: string;\n\treadonly procedureName?: string;\n\treadonly cause?: Error;\n\treadonly retryable: boolean;\n}> { }\n\nexport class ModuleFederationError extends Data.TaggedError(\n\t\"ModuleFederationError\",\n)<{\n\treadonly pluginId: string;\n\treadonly remoteUrl: string;\n\treadonly cause?: Error;\n}> { }\n\nexport class ValidationError extends Data.TaggedError(\"ValidationError\")<{\n\treadonly pluginId: string;\n\treadonly stage: \"config\" | \"input\" | \"output\" | \"state\";\n\treadonly zodError: z.ZodError;\n}> { }\n\nconst extractErrorMessage = (error: unknown): string => {\n\tif (!error) return 'Unknown error';\n\n\tif (error instanceof Error) {\n\t\tif (error.message) return error.message;\n\t\tif ((error as any).cause instanceof Error) {\n\t\t\treturn extractErrorMessage((error as any).cause);\n\t\t}\n\t}\n\n\tif (error instanceof AggregateError && error.errors?.length) {\n\t\treturn error.errors.map(e => extractErrorMessage(e)).join('; ');\n\t}\n\n\tif (typeof error === 'object' && 'message' in error) {\n\t\treturn String((error as any).message);\n\t}\n\n\treturn String(error);\n};\n\nconst formatValidationIssue = (issue: any, index: number, maxDisplay: number): string => {\n\tif (index >= maxDisplay) return '';\n\t\n\tconst path = Array.isArray(issue.path) && issue.path.length > 0\n\t\t? issue.path.join('.')\n\t\t: issue.path || 'root';\n\t\n\tconst message = issue.message || 'Validation failed';\n\t\n\treturn `│ ${index + 1}. ${path}: ${message}`;\n};\n\nconst formatDataPreview = (data: unknown, maxLength = 100): string => {\n\tif (!data) return 'undefined';\n\t\n\ttry {\n\t\tconst str = JSON.stringify(data);\n\t\tif (str.length <= maxLength) return str;\n\t\t\n\t\tif (typeof data === 'object' && data !== null) {\n\t\t\tif (Array.isArray(data)) {\n\t\t\t\treturn `Array(${data.length}) [...]`;\n\t\t\t}\n\t\t\tconst keys = Object.keys(data);\n\t\t\treturn `{ ${keys.slice(0, 3).join(', ')}${keys.length > 3 ? ', ...' : ''} }`;\n\t\t}\n\t\t\n\t\treturn str.slice(0, maxLength) + '...';\n\t} catch {\n\t\treturn String(data).slice(0, maxLength);\n\t}\n};\n\nconst formatORPCValidationError = (error: any): string[] | null => {\n\tconst cause = error?.cause || error;\n\t\n\tif (!cause?.issues || !Array.isArray(cause.issues) || cause.issues.length === 0) {\n\t\treturn null;\n\t}\n\n\tconst lines: string[] = [];\n\tconst errorType = error?.message || cause?.message || 'Validation failed';\n\t\n\tlines.push(`\\n╭─ oRPC Validation Error ${'─'.repeat(30)}`);\n\tlines.push(`│ ${errorType}`);\n\tlines.push(`│`);\n\t\n\tconst maxDisplay = 10;\n\tconst totalIssues = cause.issues.length;\n\t\n\tlines.push(`│ Issues (${totalIssues}):`);\n\t\n\tconst displayedIssues = cause.issues.slice(0, maxDisplay);\n\tdisplayedIssues.forEach((issue: any, idx: number) => {\n\t\tconst formatted = formatValidationIssue(issue, idx, maxDisplay);\n\t\tif (formatted) lines.push(formatted);\n\t});\n\t\n\tif (totalIssues > maxDisplay) {\n\t\tlines.push(`│ ... and ${totalIssues - maxDisplay} more`);\n\t}\n\t\n\tif (cause.data !== undefined) {\n\t\tlines.push(`│`);\n\t\tlines.push(`│ Data preview: ${formatDataPreview(cause.data, 80)}`);\n\t}\n\t\n\tlines.push(`╰${'─'.repeat(50)}\\n`);\n\t\n\treturn lines;\n};\n\nexport const formatORPCError = (error: any): void => {\n\tif (!(error instanceof ORPCError)) {\n\t\treturn;\n\t}\n\n\tconst validationLines = formatORPCValidationError(error);\n\tif (validationLines) {\n\t\tconsole.error(validationLines.join('\\n'));\n\t\treturn;\n\t}\n\n\tconst lines: string[] = [];\n\tconst code = error.code || 'UNKNOWN';\n\tconst status = error.status || 500;\n\tconst message = error.message || 'An error occurred';\n\n\tlines.push(`\\n╭─ oRPC Error ${'─'.repeat(40)}`);\n\tlines.push(`│ ${message}`);\n\tlines.push(`│ Code: ${code} (${status})`);\n\tlines.push(`│`);\n\n\tif (error.data) {\n\t\tconst dataType = typeof error.data;\n\t\tif (dataType === 'object' && error.data !== null) {\n\t\t\tif ('retryAfter' in error.data) {\n\t\t\t\tlines.push(`│ Retry after: ${error.data.retryAfter} seconds`);\n\t\t\t}\n\t\t\tif ('remainingRequests' in error.data) {\n\t\t\t\tlines.push(`│ Remaining: ${error.data.remainingRequests} requests`);\n\t\t\t}\n\t\t\tif ('host' in error.data) {\n\t\t\t\tlines.push(`│ Host: ${error.data.host}`);\n\t\t\t}\n\t\t\tif ('port' in error.data) {\n\t\t\t\tlines.push(`│ Port: ${error.data.port}`);\n\t\t\t}\n\t\t\tif ('suggestion' in error.data) {\n\t\t\t\tlines.push(`│ → ${error.data.suggestion}`);\n\t\t\t}\n\t\t\tif ('resource' in error.data) {\n\t\t\t\tlines.push(`│ Resource: ${error.data.resource}`);\n\t\t\t}\n\t\t\tif ('resourceId' in error.data) {\n\t\t\t\tlines.push(`│ ID: ${error.data.resourceId}`);\n\t\t\t}\n\t\t}\n\t}\n\n\tswitch (code) {\n\t\tcase 'UNAUTHORIZED':\n\t\t\tlines.push(`│ → Check your API key or credentials`);\n\t\t\tbreak;\n\t\tcase 'TOO_MANY_REQUESTS':\n\t\t\tlines.push(`│ → Wait before retrying`);\n\t\t\tbreak;\n\t\tcase 'SERVICE_UNAVAILABLE':\n\t\tcase 'BAD_GATEWAY':\n\t\tcase 'GATEWAY_TIMEOUT':\n\t\t\tlines.push(`│ → The service may be temporarily unavailable`);\n\t\t\tbreak;\n\t\tcase 'TIMEOUT':\n\t\t\tlines.push(`│ → The operation took too long`);\n\t\t\tbreak;\n\t}\n\n\tlines.push(`╰${'─'.repeat(50)}\\n`);\n\tconsole.error(lines.join('\\n'));\n};\n\nconst formatPluginError = (\n\tpluginId: string | undefined,\n\toperation: string | undefined,\n\tmessage: string\n): void => {\n\tconst lines: string[] = [];\n\n\tlines.push(`\\n╭─ Plugin Error ${'─'.repeat(40)}`);\n\tif (pluginId) lines.push(`│ Plugin: ${pluginId}`);\n\tif (operation) lines.push(`│ During: ${operation}`);\n\tlines.push(`│`);\n\n\tif (message.includes('ECONNREFUSED')) {\n\t\tlines.push(`│ ❌ Connection refused`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ A required service is not running.`);\n\t\tlines.push(`│ → Run: docker compose up -d`);\n\t} else if (message.includes('ENOTFOUND')) {\n\t\tlines.push(`│ ❌ Host not found`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ Check your connection URL or network settings.`);\n\t} else if (message.includes('ETIMEDOUT') || message.includes('timeout')) {\n\t\tlines.push(`│ ❌ Connection timeout`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ The service took too long to respond.`);\n\t} else if (message.includes('EACCES') || message.includes('permission')) {\n\t\tlines.push(`│ ❌ Permission denied`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ Check credentials or access permissions.`);\n\t} else if (message.includes('401') || message.includes('unauthorized')) {\n\t\tlines.push(`│ ❌ Authentication failed`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ Check your API key or credentials.`);\n\t} else {\n\t\tlines.push(`│ ❌ ${message}`);\n\t}\n\n\tlines.push(`╰${'─'.repeat(50)}\\n`);\n\n\tconsole.error(lines.join('\\n'));\n};\n\nconst isRetryableError = (message: string): boolean => {\n\tconst retryablePatterns = ['ETIMEDOUT', 'ECONNRESET', 'timeout', '503', '429'];\n\treturn retryablePatterns.some(p => message.toLowerCase().includes(p.toLowerCase()));\n};\n\n// Helper to determine if an oRPC error code is retryable\nexport const isRetryableORPCCode = (code: string): boolean => {\n\tswitch (code) {\n\t\tcase 'TOO_MANY_REQUESTS':\n\t\tcase 'SERVICE_UNAVAILABLE':\n\t\tcase 'BAD_GATEWAY':\n\t\tcase 'GATEWAY_TIMEOUT':\n\t\tcase 'TIMEOUT':\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n};\n\n// Convert ORPC errors from plugin procedures to PluginRuntimeError\nexport const wrapORPCError = (\n\torpcError: ORPCError<string, unknown>,\n\tpluginId?: string,\n\tprocedureName?: string,\n\toperation?: string\n): PluginRuntimeError => {\n\tconst validationLines = formatORPCValidationError(orpcError);\n\tif (validationLines) {\n\t\tconsole.error(validationLines.join('\\n'));\n\t}\n\t\n\treturn new PluginRuntimeError({\n\t\tpluginId,\n\t\toperation,\n\t\tprocedureName,\n\t\tretryable: isRetryableORPCCode(orpcError.code),\n\t\tcause: orpcError as Error\n\t});\n};\n\n// Universal error converter for the runtime\nexport const toPluginRuntimeError = (\n\terror: unknown,\n\tpluginId?: string,\n\tprocedureName?: string,\n\toperation?: string,\n\tdefaultRetryable = false\n): PluginRuntimeError => {\n\tif (error instanceof ORPCError) {\n\t\treturn wrapORPCError(error, pluginId, procedureName, operation);\n\t}\n\n\tif (error instanceof PluginRuntimeError) {\n\t\treturn error;\n\t}\n\n\tconst validationLines = formatORPCValidationError(error);\n\tif (validationLines) {\n\t\tconsole.error(validationLines.join('\\n'));\n\t} else {\n\t\tconst message = extractErrorMessage(error);\n\t\tformatPluginError(pluginId, operation, message);\n\t}\n\n\treturn new PluginRuntimeError({\n\t\tpluginId,\n\t\toperation,\n\t\tprocedureName,\n\t\tretryable: defaultRetryable || isRetryableError(extractErrorMessage(error)),\n\t\tcause: error instanceof Error ? error : new Error(extractErrorMessage(error))\n\t});\n};\n"],"mappings":";;;;;AAIA,IAAa,qBAAb,cAAwCA,YAAK,YAAY,qBAAqB,CAM3E;AAEH,IAAa,wBAAb,cAA2CA,YAAK,YAC/C,wBACA,CAIE;AAEH,IAAa,kBAAb,cAAqCA,YAAK,YAAY,kBAAkB,CAIrE;AAEH,MAAM,uBAAuB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OAAO,UAAU,eAAe,UAAU;AAGhE,KAAI,iBAAiB,mBACpB,QAAO;CAGR,MAAM,kBAAkB,0BAA0B,MAAM;AACxD,KAAI,gBACH,SAAQ,MAAM,gBAAgB,KAAK,KAAK,CAAC;KAGzC,mBAAkB,UAAU,WADZ,oBAAoB,MAAM,CACK;AAGhD,QAAO,IAAI,mBAAmB;EAC7B;EACA;EACA;EACA,WAAW,oBAAoB,iBAAiB,oBAAoB,MAAM,CAAC;EAC3E,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,oBAAoB,MAAM,CAAC;EAC7E,CAAC"}
|
|
1
|
+
{"version":3,"file":"errors.cjs","names":["Data","ORPCError","Cause"],"sources":["../../src/runtime/errors.ts"],"sourcesContent":["import { ORPCError } from \"@orpc/contract\";\nimport { Cause, Data } from \"effect\";\nimport type { z } from \"zod\";\n\nexport class PluginRuntimeError extends Data.TaggedError(\"PluginRuntimeError\")<{\n\treadonly pluginId?: string;\n\treadonly operation?: string;\n\treadonly procedureName?: string;\n\treadonly cause?: Error;\n\treadonly retryable: boolean;\n}> { }\n\nexport class ModuleFederationError extends Data.TaggedError(\n\t\"ModuleFederationError\",\n)<{\n\treadonly pluginId: string;\n\treadonly remoteUrl: string;\n\treadonly cause?: Error;\n}> { }\n\nexport class ValidationError extends Data.TaggedError(\"ValidationError\")<{\n\treadonly pluginId: string;\n\treadonly stage: \"config\" | \"input\" | \"output\" | \"state\";\n\treadonly zodError: z.ZodError;\n}> { }\n\nconst extractErrorMessage = (error: unknown): string => {\n\tif (!error) return 'Unknown error';\n\n\tif (error instanceof Error) {\n\t\tif (error.message) return error.message;\n\t\tif ((error as any).cause instanceof Error) {\n\t\t\treturn extractErrorMessage((error as any).cause);\n\t\t}\n\t}\n\n\tif (error instanceof AggregateError && error.errors?.length) {\n\t\treturn error.errors.map(e => extractErrorMessage(e)).join('; ');\n\t}\n\n\tif (typeof error === 'object' && 'message' in error) {\n\t\treturn String((error as any).message);\n\t}\n\n\treturn String(error);\n};\n\nconst formatValidationIssue = (issue: any, index: number, maxDisplay: number): string => {\n\tif (index >= maxDisplay) return '';\n\t\n\tconst path = Array.isArray(issue.path) && issue.path.length > 0\n\t\t? issue.path.join('.')\n\t\t: issue.path || 'root';\n\t\n\tconst message = issue.message || 'Validation failed';\n\t\n\treturn `│ ${index + 1}. ${path}: ${message}`;\n};\n\nconst formatDataPreview = (data: unknown, maxLength = 100): string => {\n\tif (!data) return 'undefined';\n\t\n\ttry {\n\t\tconst str = JSON.stringify(data);\n\t\tif (str.length <= maxLength) return str;\n\t\t\n\t\tif (typeof data === 'object' && data !== null) {\n\t\t\tif (Array.isArray(data)) {\n\t\t\t\treturn `Array(${data.length}) [...]`;\n\t\t\t}\n\t\t\tconst keys = Object.keys(data);\n\t\t\treturn `{ ${keys.slice(0, 3).join(', ')}${keys.length > 3 ? ', ...' : ''} }`;\n\t\t}\n\t\t\n\t\treturn str.slice(0, maxLength) + '...';\n\t} catch {\n\t\treturn String(data).slice(0, maxLength);\n\t}\n};\n\nconst formatORPCValidationError = (error: any): string[] | null => {\n\tconst cause = error?.cause || error;\n\t\n\tif (!cause?.issues || !Array.isArray(cause.issues) || cause.issues.length === 0) {\n\t\treturn null;\n\t}\n\n\tconst lines: string[] = [];\n\tconst errorType = error?.message || cause?.message || 'Validation failed';\n\t\n\tlines.push(`\\n╭─ oRPC Validation Error ${'─'.repeat(30)}`);\n\tlines.push(`│ ${errorType}`);\n\tlines.push(`│`);\n\t\n\tconst maxDisplay = 10;\n\tconst totalIssues = cause.issues.length;\n\t\n\tlines.push(`│ Issues (${totalIssues}):`);\n\t\n\tconst displayedIssues = cause.issues.slice(0, maxDisplay);\n\tdisplayedIssues.forEach((issue: any, idx: number) => {\n\t\tconst formatted = formatValidationIssue(issue, idx, maxDisplay);\n\t\tif (formatted) lines.push(formatted);\n\t});\n\t\n\tif (totalIssues > maxDisplay) {\n\t\tlines.push(`│ ... and ${totalIssues - maxDisplay} more`);\n\t}\n\t\n\tif (cause.data !== undefined) {\n\t\tlines.push(`│`);\n\t\tlines.push(`│ Data preview: ${formatDataPreview(cause.data, 80)}`);\n\t}\n\t\n\tlines.push(`╰${'─'.repeat(50)}\\n`);\n\t\n\treturn lines;\n};\n\nexport const formatORPCError = (error: any): void => {\n\tif (!(error instanceof ORPCError)) {\n\t\treturn;\n\t}\n\n\tconst validationLines = formatORPCValidationError(error);\n\tif (validationLines) {\n\t\tconsole.error(validationLines.join('\\n'));\n\t\treturn;\n\t}\n\n\tconst lines: string[] = [];\n\tconst code = error.code || 'UNKNOWN';\n\tconst status = error.status || 500;\n\tconst message = error.message || 'An error occurred';\n\n\tlines.push(`\\n╭─ oRPC Error ${'─'.repeat(40)}`);\n\tlines.push(`│ ${message}`);\n\tlines.push(`│ Code: ${code} (${status})`);\n\tlines.push(`│`);\n\n\tif (error.data) {\n\t\tconst dataType = typeof error.data;\n\t\tif (dataType === 'object' && error.data !== null) {\n\t\t\tif ('retryAfter' in error.data) {\n\t\t\t\tlines.push(`│ Retry after: ${error.data.retryAfter} seconds`);\n\t\t\t}\n\t\t\tif ('remainingRequests' in error.data) {\n\t\t\t\tlines.push(`│ Remaining: ${error.data.remainingRequests} requests`);\n\t\t\t}\n\t\t\tif ('host' in error.data) {\n\t\t\t\tlines.push(`│ Host: ${error.data.host}`);\n\t\t\t}\n\t\t\tif ('port' in error.data) {\n\t\t\t\tlines.push(`│ Port: ${error.data.port}`);\n\t\t\t}\n\t\t\tif ('suggestion' in error.data) {\n\t\t\t\tlines.push(`│ → ${error.data.suggestion}`);\n\t\t\t}\n\t\t\tif ('resource' in error.data) {\n\t\t\t\tlines.push(`│ Resource: ${error.data.resource}`);\n\t\t\t}\n\t\t\tif ('resourceId' in error.data) {\n\t\t\t\tlines.push(`│ ID: ${error.data.resourceId}`);\n\t\t\t}\n\t\t}\n\t}\n\n\tswitch (code) {\n\t\tcase 'UNAUTHORIZED':\n\t\t\tlines.push(`│ → Check your API key or credentials`);\n\t\t\tbreak;\n\t\tcase 'TOO_MANY_REQUESTS':\n\t\t\tlines.push(`│ → Wait before retrying`);\n\t\t\tbreak;\n\t\tcase 'SERVICE_UNAVAILABLE':\n\t\tcase 'BAD_GATEWAY':\n\t\tcase 'GATEWAY_TIMEOUT':\n\t\t\tlines.push(`│ → The service may be temporarily unavailable`);\n\t\t\tbreak;\n\t\tcase 'TIMEOUT':\n\t\t\tlines.push(`│ → The operation took too long`);\n\t\t\tbreak;\n\t}\n\n\tlines.push(`╰${'─'.repeat(50)}\\n`);\n\tconsole.error(lines.join('\\n'));\n};\n\nconst formatPluginError = (\n\tpluginId: string | undefined,\n\toperation: string | undefined,\n\tmessage: string\n): void => {\n\tconst lines: string[] = [];\n\n\tlines.push(`\\n╭─ Plugin Error ${'─'.repeat(40)}`);\n\tif (pluginId) lines.push(`│ Plugin: ${pluginId}`);\n\tif (operation) lines.push(`│ During: ${operation}`);\n\tlines.push(`│`);\n\n\tif (message.includes('ECONNREFUSED')) {\n\t\tlines.push(`│ ❌ Connection refused`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ A required service is not running.`);\n\t\tlines.push(`│ → Run: docker compose up -d`);\n\t} else if (message.includes('ENOTFOUND')) {\n\t\tlines.push(`│ ❌ Host not found`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ Check your connection URL or network settings.`);\n\t} else if (message.includes('ETIMEDOUT') || message.includes('timeout')) {\n\t\tlines.push(`│ ❌ Connection timeout`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ The service took too long to respond.`);\n\t} else if (message.includes('EACCES') || message.includes('permission')) {\n\t\tlines.push(`│ ❌ Permission denied`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ Check credentials or access permissions.`);\n\t} else if (message.includes('401') || message.includes('unauthorized')) {\n\t\tlines.push(`│ ❌ Authentication failed`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ Check your API key or credentials.`);\n\t} else {\n\t\tlines.push(`│ ❌ ${message}`);\n\t}\n\n\tlines.push(`╰${'─'.repeat(50)}\\n`);\n\n\tconsole.error(lines.join('\\n'));\n};\n\nconst isRetryableError = (message: string): boolean => {\n\tconst retryablePatterns = ['ETIMEDOUT', 'ECONNRESET', 'timeout', '503', '429'];\n\treturn retryablePatterns.some(p => message.toLowerCase().includes(p.toLowerCase()));\n};\n\n// Helper to determine if an oRPC error code is retryable\nexport const isRetryableORPCCode = (code: string): boolean => {\n\tswitch (code) {\n\t\tcase 'TOO_MANY_REQUESTS':\n\t\tcase 'SERVICE_UNAVAILABLE':\n\t\tcase 'BAD_GATEWAY':\n\t\tcase 'GATEWAY_TIMEOUT':\n\t\tcase 'TIMEOUT':\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n};\n\n// Convert ORPC errors from plugin procedures to PluginRuntimeError\nexport const wrapORPCError = (\n\torpcError: ORPCError<string, unknown>,\n\tpluginId?: string,\n\tprocedureName?: string,\n\toperation?: string\n): PluginRuntimeError => {\n\tconst validationLines = formatORPCValidationError(orpcError);\n\tif (validationLines) {\n\t\tconsole.error(validationLines.join('\\n'));\n\t}\n\t\n\treturn new PluginRuntimeError({\n\t\tpluginId,\n\t\toperation,\n\t\tprocedureName,\n\t\tretryable: isRetryableORPCCode(orpcError.code),\n\t\tcause: orpcError as Error\n\t});\n};\n\n/**\n * Extracts the underlying error from Effect's FiberFailure wrapper.\n * When Effect.runPromise rejects, errors are wrapped in FiberFailure.\n * This extracts the original error so oRPC can handle it properly.\n */\nexport const extractFromFiberFailure = (error: unknown): unknown => {\n\tif (!error || typeof error !== 'object') return error;\n\t\n\tif ('cause' in error) {\n\t\tconst cause = (error as { cause?: unknown }).cause;\n\t\t\n\t\tif (cause && typeof cause === 'object' && '_tag' in cause) {\n\t\t\ttry {\n\t\t\t\tconst squashed = Cause.squash(cause as Cause.Cause<unknown>);\n\t\t\t\tif (squashed instanceof ORPCError) {\n\t\t\t\t\treturn squashed;\n\t\t\t\t}\n\t\t\t\treturn squashed;\n\t\t\t} catch {\n\t\t\t\t// Not a valid Cause\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (cause instanceof ORPCError) {\n\t\t\treturn cause;\n\t\t}\n\t}\n\t\n\treturn error;\n};\n\n// Universal error converter for the runtime\nexport const toPluginRuntimeError = (\n\terror: unknown,\n\tpluginId?: string,\n\tprocedureName?: string,\n\toperation?: string,\n\tdefaultRetryable = false\n): PluginRuntimeError => {\n\tif (error instanceof ORPCError) {\n\t\treturn wrapORPCError(error, pluginId, procedureName, operation);\n\t}\n\n\tif (error instanceof PluginRuntimeError) {\n\t\treturn error;\n\t}\n\n\tconst validationLines = formatORPCValidationError(error);\n\tif (validationLines) {\n\t\tconsole.error(validationLines.join('\\n'));\n\t} else {\n\t\tconst message = extractErrorMessage(error);\n\t\tformatPluginError(pluginId, operation, message);\n\t}\n\n\treturn new PluginRuntimeError({\n\t\tpluginId,\n\t\toperation,\n\t\tprocedureName,\n\t\tretryable: defaultRetryable || isRetryableError(extractErrorMessage(error)),\n\t\tcause: error instanceof Error ? error : new Error(extractErrorMessage(error))\n\t});\n};\n"],"mappings":";;;;;AAIA,IAAa,qBAAb,cAAwCA,YAAK,YAAY,qBAAqB,CAM3E;AAEH,IAAa,wBAAb,cAA2CA,YAAK,YAC/C,wBACA,CAIE;AAEH,IAAa,kBAAb,cAAqCA,YAAK,YAAY,kBAAkB,CAIrE;AAEH,MAAM,uBAAuB,UAA2B;AACvD,KAAI,CAAC,MAAO,QAAO;AAEnB,KAAI,iBAAiB,OAAO;AAC3B,MAAI,MAAM,QAAS,QAAO,MAAM;AAChC,MAAK,MAAc,iBAAiB,MACnC,QAAO,oBAAqB,MAAc,MAAM;;AAIlD,KAAI,iBAAiB,kBAAkB,MAAM,QAAQ,OACpD,QAAO,MAAM,OAAO,KAAI,MAAK,oBAAoB,EAAE,CAAC,CAAC,KAAK,KAAK;AAGhE,KAAI,OAAO,UAAU,YAAY,aAAa,MAC7C,QAAO,OAAQ,MAAc,QAAQ;AAGtC,QAAO,OAAO,MAAM;;AAGrB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R,MAAM,kBAAkB,0BAA0B,MAAM;AACxD,KAAI,gBACH,SAAQ,MAAM,gBAAgB,KAAK,KAAK,CAAC;KAGzC,mBAAkB,UAAU,WADZ,oBAAoB,MAAM,CACK;AAGhD,QAAO,IAAI,mBAAmB;EAC7B;EACA;EACA;EACA,WAAW,oBAAoB,iBAAiB,oBAAoB,MAAM,CAAC;EAC3E,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,oBAAoB,MAAM,CAAC;EAC7E,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { Cause } from "effect";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
import * as effect_Types0 from "effect/Types";
|
|
3
|
-
import * as effect_Cause0 from "effect/Cause";
|
|
4
4
|
import { ORPCError } from "@orpc/contract";
|
|
5
5
|
|
|
6
6
|
//#region src/runtime/errors.d.ts
|
|
7
|
-
declare const PluginRuntimeError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) =>
|
|
7
|
+
declare const PluginRuntimeError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) => Cause.YieldableError & {
|
|
8
8
|
readonly _tag: "PluginRuntimeError";
|
|
9
9
|
} & Readonly<A>;
|
|
10
10
|
declare class PluginRuntimeError extends PluginRuntimeError_base<{
|
|
@@ -14,7 +14,7 @@ declare class PluginRuntimeError extends PluginRuntimeError_base<{
|
|
|
14
14
|
readonly cause?: Error;
|
|
15
15
|
readonly retryable: boolean;
|
|
16
16
|
}> {}
|
|
17
|
-
declare const ModuleFederationError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) =>
|
|
17
|
+
declare const ModuleFederationError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) => Cause.YieldableError & {
|
|
18
18
|
readonly _tag: "ModuleFederationError";
|
|
19
19
|
} & Readonly<A>;
|
|
20
20
|
declare class ModuleFederationError extends ModuleFederationError_base<{
|
|
@@ -22,7 +22,7 @@ declare class ModuleFederationError extends ModuleFederationError_base<{
|
|
|
22
22
|
readonly remoteUrl: string;
|
|
23
23
|
readonly cause?: Error;
|
|
24
24
|
}> {}
|
|
25
|
-
declare const ValidationError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) =>
|
|
25
|
+
declare const ValidationError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) => Cause.YieldableError & {
|
|
26
26
|
readonly _tag: "ValidationError";
|
|
27
27
|
} & Readonly<A>;
|
|
28
28
|
declare class ValidationError extends ValidationError_base<{
|
|
@@ -33,7 +33,13 @@ declare class ValidationError extends ValidationError_base<{
|
|
|
33
33
|
declare const formatORPCError: (error: any) => void;
|
|
34
34
|
declare const isRetryableORPCCode: (code: string) => boolean;
|
|
35
35
|
declare const wrapORPCError: (orpcError: ORPCError<string, unknown>, pluginId?: string, procedureName?: string, operation?: string) => PluginRuntimeError;
|
|
36
|
+
/**
|
|
37
|
+
* Extracts the underlying error from Effect's FiberFailure wrapper.
|
|
38
|
+
* When Effect.runPromise rejects, errors are wrapped in FiberFailure.
|
|
39
|
+
* This extracts the original error so oRPC can handle it properly.
|
|
40
|
+
*/
|
|
41
|
+
declare const extractFromFiberFailure: (error: unknown) => unknown;
|
|
36
42
|
declare const toPluginRuntimeError: (error: unknown, pluginId?: string, procedureName?: string, operation?: string, defaultRetryable?: boolean) => PluginRuntimeError;
|
|
37
43
|
//#endregion
|
|
38
|
-
export { ModuleFederationError, PluginRuntimeError, ValidationError, formatORPCError, isRetryableORPCCode, toPluginRuntimeError, wrapORPCError };
|
|
44
|
+
export { ModuleFederationError, PluginRuntimeError, ValidationError, extractFromFiberFailure, formatORPCError, isRetryableORPCCode, toPluginRuntimeError, wrapORPCError };
|
|
39
45
|
//# sourceMappingURL=errors.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.cts","names":[],"sources":["../../src/runtime/errors.ts"],"
|
|
1
|
+
{"version":3,"file":"errors.d.cts","names":[],"sources":["../../src/runtime/errors.ts"],"mappings":";;;;;;cAE6B,uBAAA;;;cAEhB,kBAAA,SAA2B,uBAAA;EAAA,SAAA,QAAA;EAAA,SAAA,SAAA;EAAA,SAAA,aAAA;EAAA,SAAA,KAAA,GAItB,KAAA;EAAA,SAAA,SAAA;AAAA;AAAA,cAEZ,0BAAA;;;cAEO,qBAAA,SAA8B,0BAAA;EAAA,SAAA,QAAA;EAAA,SAAA,SAAA;EAAA,SAAA,KAAA,GAKzB,KAAA;AAAA;AAAA,cACZ,oBAAA;;;cAEO,eAAA,SAAwB,oBAAA;EAAA,SAAA,QAAA;EAAA,SAAA,KAAA;EAAA,SAAA,QAAA,EAGjB,CAAA,CAAE,QAAA;AAAA;AAAA,cAgGT,eAAA,GAAA,KAAA;AAAA,cAqHA,mBAAA,GAAA,IAAA;AAAA,cAcA,aAAA,GAAA,SAAA,EACD,SAAA,mBAAA,QAAA,WAAA,aAAA,WAAA,SAAA,cAIT,kBAAA;AAAA;AAoBH;AA2BA;;;AA/CG,cAoBU,uBAAA,GAAA,KAAA;AAAA,cA2BA,oBAAA,GAAA,KAAA,WAAA,QAAA,WAAA,aAAA,WAAA,SAAA,WAAA,gBAAA,eAMV,kBAAA"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { ORPCError } from "@orpc/contract";
|
|
3
|
+
import { Cause } from "effect";
|
|
3
4
|
import * as effect_Types0 from "effect/Types";
|
|
4
|
-
import * as effect_Cause0 from "effect/Cause";
|
|
5
5
|
|
|
6
6
|
//#region src/runtime/errors.d.ts
|
|
7
|
-
declare const PluginRuntimeError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) =>
|
|
7
|
+
declare const PluginRuntimeError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) => Cause.YieldableError & {
|
|
8
8
|
readonly _tag: "PluginRuntimeError";
|
|
9
9
|
} & Readonly<A>;
|
|
10
10
|
declare class PluginRuntimeError extends PluginRuntimeError_base<{
|
|
@@ -14,7 +14,7 @@ declare class PluginRuntimeError extends PluginRuntimeError_base<{
|
|
|
14
14
|
readonly cause?: Error;
|
|
15
15
|
readonly retryable: boolean;
|
|
16
16
|
}> {}
|
|
17
|
-
declare const ModuleFederationError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) =>
|
|
17
|
+
declare const ModuleFederationError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) => Cause.YieldableError & {
|
|
18
18
|
readonly _tag: "ModuleFederationError";
|
|
19
19
|
} & Readonly<A>;
|
|
20
20
|
declare class ModuleFederationError extends ModuleFederationError_base<{
|
|
@@ -22,7 +22,7 @@ declare class ModuleFederationError extends ModuleFederationError_base<{
|
|
|
22
22
|
readonly remoteUrl: string;
|
|
23
23
|
readonly cause?: Error;
|
|
24
24
|
}> {}
|
|
25
|
-
declare const ValidationError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) =>
|
|
25
|
+
declare const ValidationError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) => Cause.YieldableError & {
|
|
26
26
|
readonly _tag: "ValidationError";
|
|
27
27
|
} & Readonly<A>;
|
|
28
28
|
declare class ValidationError extends ValidationError_base<{
|
|
@@ -33,7 +33,13 @@ declare class ValidationError extends ValidationError_base<{
|
|
|
33
33
|
declare const formatORPCError: (error: any) => void;
|
|
34
34
|
declare const isRetryableORPCCode: (code: string) => boolean;
|
|
35
35
|
declare const wrapORPCError: (orpcError: ORPCError<string, unknown>, pluginId?: string, procedureName?: string, operation?: string) => PluginRuntimeError;
|
|
36
|
+
/**
|
|
37
|
+
* Extracts the underlying error from Effect's FiberFailure wrapper.
|
|
38
|
+
* When Effect.runPromise rejects, errors are wrapped in FiberFailure.
|
|
39
|
+
* This extracts the original error so oRPC can handle it properly.
|
|
40
|
+
*/
|
|
41
|
+
declare const extractFromFiberFailure: (error: unknown) => unknown;
|
|
36
42
|
declare const toPluginRuntimeError: (error: unknown, pluginId?: string, procedureName?: string, operation?: string, defaultRetryable?: boolean) => PluginRuntimeError;
|
|
37
43
|
//#endregion
|
|
38
|
-
export { ModuleFederationError, PluginRuntimeError, ValidationError, formatORPCError, isRetryableORPCCode, toPluginRuntimeError, wrapORPCError };
|
|
44
|
+
export { ModuleFederationError, PluginRuntimeError, ValidationError, extractFromFiberFailure, formatORPCError, isRetryableORPCCode, toPluginRuntimeError, wrapORPCError };
|
|
39
45
|
//# sourceMappingURL=errors.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.mts","names":[],"sources":["../../src/runtime/errors.ts"],"
|
|
1
|
+
{"version":3,"file":"errors.d.mts","names":[],"sources":["../../src/runtime/errors.ts"],"mappings":";;;;;;cAE6B,uBAAA;;;cAEhB,kBAAA,SAA2B,uBAAA;EAAA,SAAA,QAAA;EAAA,SAAA,SAAA;EAAA,SAAA,aAAA;EAAA,SAAA,KAAA,GAItB,KAAA;EAAA,SAAA,SAAA;AAAA;AAAA,cAEZ,0BAAA;;;cAEO,qBAAA,SAA8B,0BAAA;EAAA,SAAA,QAAA;EAAA,SAAA,SAAA;EAAA,SAAA,KAAA,GAKzB,KAAA;AAAA;AAAA,cACZ,oBAAA;;;cAEO,eAAA,SAAwB,oBAAA;EAAA,SAAA,QAAA;EAAA,SAAA,KAAA;EAAA,SAAA,QAAA,EAGjB,CAAA,CAAE,QAAA;AAAA;AAAA,cAgGT,eAAA,GAAA,KAAA;AAAA,cAqHA,mBAAA,GAAA,IAAA;AAAA,cAcA,aAAA,GAAA,SAAA,EACD,SAAA,mBAAA,QAAA,WAAA,aAAA,WAAA,SAAA,cAIT,kBAAA;AAAA;AAoBH;AA2BA;;;AA/CG,cAoBU,uBAAA,GAAA,KAAA;AAAA,cA2BA,oBAAA,GAAA,KAAA,WAAA,QAAA,WAAA,aAAA,WAAA,SAAA,WAAA,gBAAA,eAMV,kBAAA"}
|
package/dist/runtime/errors.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ORPCError } from "@orpc/contract";
|
|
2
|
-
import { Data } from "effect";
|
|
2
|
+
import { Cause, Data } from "effect";
|
|
3
3
|
|
|
4
4
|
//#region src/runtime/errors.ts
|
|
5
5
|
var PluginRuntimeError = class extends Data.TaggedError("PluginRuntimeError") {};
|
|
@@ -165,6 +165,24 @@ const wrapORPCError = (orpcError, pluginId, procedureName, operation) => {
|
|
|
165
165
|
cause: orpcError
|
|
166
166
|
});
|
|
167
167
|
};
|
|
168
|
+
/**
|
|
169
|
+
* Extracts the underlying error from Effect's FiberFailure wrapper.
|
|
170
|
+
* When Effect.runPromise rejects, errors are wrapped in FiberFailure.
|
|
171
|
+
* This extracts the original error so oRPC can handle it properly.
|
|
172
|
+
*/
|
|
173
|
+
const extractFromFiberFailure = (error) => {
|
|
174
|
+
if (!error || typeof error !== "object") return error;
|
|
175
|
+
if ("cause" in error) {
|
|
176
|
+
const cause = error.cause;
|
|
177
|
+
if (cause && typeof cause === "object" && "_tag" in cause) try {
|
|
178
|
+
const squashed = Cause.squash(cause);
|
|
179
|
+
if (squashed instanceof ORPCError) return squashed;
|
|
180
|
+
return squashed;
|
|
181
|
+
} catch {}
|
|
182
|
+
if (cause instanceof ORPCError) return cause;
|
|
183
|
+
}
|
|
184
|
+
return error;
|
|
185
|
+
};
|
|
168
186
|
const toPluginRuntimeError = (error, pluginId, procedureName, operation, defaultRetryable = false) => {
|
|
169
187
|
if (error instanceof ORPCError) return wrapORPCError(error, pluginId, procedureName, operation);
|
|
170
188
|
if (error instanceof PluginRuntimeError) return error;
|
|
@@ -181,5 +199,5 @@ const toPluginRuntimeError = (error, pluginId, procedureName, operation, default
|
|
|
181
199
|
};
|
|
182
200
|
|
|
183
201
|
//#endregion
|
|
184
|
-
export { ModuleFederationError, PluginRuntimeError, ValidationError, formatORPCError, isRetryableORPCCode, toPluginRuntimeError, wrapORPCError };
|
|
202
|
+
export { ModuleFederationError, PluginRuntimeError, ValidationError, extractFromFiberFailure, formatORPCError, isRetryableORPCCode, toPluginRuntimeError, wrapORPCError };
|
|
185
203
|
//# sourceMappingURL=errors.mjs.map
|