every-plugin 0.8.2 → 0.8.3
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/build/rspack/dev-server-middleware.cjs +3 -40
- package/dist/build/rspack/dev-server-middleware.cjs.map +1 -1
- package/dist/build/rspack/dev-server-middleware.mjs +3 -40
- package/dist/build/rspack/dev-server-middleware.mjs.map +1 -1
- package/dist/errors.cjs +8 -0
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts +2 -2
- package/dist/errors.d.cts.map +1 -1
- package/dist/errors.d.mts +2 -2
- package/dist/errors.d.mts.map +1 -1
- package/dist/errors.mjs +2 -1
- package/dist/errors.mjs.map +1 -1
- package/dist/index.cjs +12 -4
- package/dist/index.d.cts +2 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +2 -1
- package/dist/orpc.d.mts +1 -1
- package/dist/orpc.mjs +2 -2
- package/dist/package.cjs +7 -7
- package/dist/package.cjs.map +1 -1
- package/dist/package.mjs +7 -7
- package/dist/package.mjs.map +1 -1
- package/dist/plugin.cjs +6 -2
- package/dist/plugin.cjs.map +1 -1
- 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 +6 -2
- package/dist/plugin.mjs.map +1 -1
- package/dist/runtime/errors.cjs +100 -5
- package/dist/runtime/errors.cjs.map +1 -1
- package/dist/runtime/errors.d.cts +15 -3
- package/dist/runtime/errors.d.cts.map +1 -1
- package/dist/runtime/errors.d.mts +13 -1
- package/dist/runtime/errors.d.mts.map +1 -1
- package/dist/runtime/errors.mjs +98 -6
- package/dist/runtime/errors.mjs.map +1 -1
- package/dist/runtime/index.cjs +1 -1
- package/dist/runtime/index.mjs +1 -1
- package/dist/runtime/services/module-federation.service.cjs +5 -0
- 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 +5 -0
- package/dist/runtime/services/module-federation.service.mjs.map +1 -1
- package/dist/runtime/services/plugin-lifecycle.service.d.cts +1 -1
- package/dist/runtime/services/plugin-lifecycle.service.d.mts +1 -1
- package/dist/runtime/services/plugin-loader.service.d.cts +1 -1
- package/dist/runtime/services/plugin-loader.service.d.mts +2 -2
- package/dist/runtime/services/plugin.service.d.cts +1 -1
- package/dist/runtime/services/plugin.service.d.mts +2 -2
- package/dist/runtime/services/secrets.service.d.cts +1 -1
- package/dist/runtime/services/secrets.service.d.mts +1 -1
- package/dist/types.d.mts +2 -2
- package/package.json +20 -16
package/dist/plugin.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
-
|
|
2
|
+
const require_errors = require('./runtime/errors.cjs');
|
|
3
3
|
let effect = require("effect");
|
|
4
|
+
let __orpc_server = require("@orpc/server");
|
|
4
5
|
|
|
5
6
|
//#region src/plugin.ts
|
|
6
7
|
/**
|
|
@@ -30,7 +31,10 @@ function createPlugin(config) {
|
|
|
30
31
|
});
|
|
31
32
|
}
|
|
32
33
|
createRouter(deps) {
|
|
33
|
-
const
|
|
34
|
+
const base = __orpc_server.os.$context().use((0, __orpc_server.onError)((error) => {
|
|
35
|
+
require_errors.formatORPCError(error);
|
|
36
|
+
}));
|
|
37
|
+
const builder = (0, __orpc_server.implement)(config.contract, base);
|
|
34
38
|
return config.createRouter(deps, builder);
|
|
35
39
|
}
|
|
36
40
|
}
|
package/dist/plugin.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs","names":["configSchema: PluginConfigFor<V, S, TRequestContext>","Effect"],"sources":["../src/plugin.ts"],"sourcesContent":["import type { AnyContractRouter, AnySchema, InferSchemaOutput } from \"@orpc/contract\";\nimport type { Context, Implementer, Router } from \"@orpc/server\";\nimport { implement } from \"@orpc/server\";\nimport { Effect, type Scope } from \"effect\";\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
|
|
1
|
+
{"version":3,"file":"plugin.cjs","names":["configSchema: PluginConfigFor<V, S, TRequestContext>","Effect","os"],"sources":["../src/plugin.ts"],"sourcesContent":["import type { AnyContractRouter, AnySchema, InferSchemaOutput } from \"@orpc/contract\";\nimport type { Context, Implementer, Router } from \"@orpc/server\";\nimport { implement, onError, os } from \"@orpc/server\";\nimport { Effect, type Scope } from \"effect\";\nimport { 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\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":";;;;;;;;;AAqEA,SAAgB,aAMd,QAaC;CACF,MAAMA,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,qBAAqBC,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,iBACX,UAA0C,CAC1C,gCAAa,UAAU;AACvB,mCAAgB,MAAM;KACrB,CAAC;GACJ,MAAM,uCAAoB,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.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.cts","names":[],"sources":["../src/plugin.ts"],"sourcesContent":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"plugin.d.cts","names":[],"sources":["../src/plugin.ts"],"sourcesContent":[],"mappings":";;;;;KAMK,mBAAmB,UAAU,YAAY,kBAAkB;;AAHpB;;AAGV,KAKtB,eALsB,CAAA,UAKI,SALJ,EAAA,UAKyB,SALzB,EAAA,wBAK4D,SAL5D,GAAA,SAAA,CAAA,GAAA;EAA8B,SAAA,EAMpD,CANoD;EAAlB,OAAA,EAOpC,CAPoC;EAAiB,OAAA,EAQrD,eARqD;AAK/D,CAAA;;;;AACY,UAQK,uBARL,CAAA,kBASO,iBATP,EAAA,mBAUQ,SAVR,EAAA,iBAWM,SAXN,EAAA,wBAYa,SAZb,GAAA,SAAA,EAAA,cAaG,SAbH,GAaa,MAbb,CAAA,KAAA,EAAA,KAAA,CAAA,CAAA,CAAA;EACF,MAAA,EAcF,MAdE,CAcK,SAdL,EAcgB,UAdhB,EAc4B,QAd5B,EAcsC,eAdtC,EAcuD,KAdvD,CAAA;EACA,OA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BtE,eA3BsE;EAAlB,UAAA,CAAA,EAAA,CAAA,MAAA,EAAA;IAC7C,SAAA,EA4BK,iBA5BL,CA4BuB,CA5BvB,CAAA;IAAsB,OAAA,EA4Bc,iBA5Bd,CA4BgC,CA5BhC,CAAA;EAApC,CAAA,EAAA,GA6BE,MAAA,CAAO,MA7BF,CA6BS,KA7BT,EA6BgB,KA7BhB,EA6BuB,KAAA,CAAM,KA7B7B,CAAA;EAEE,YAAO,EAAA,CAAA,IAAA,EA6BZ,KA7BY,EAAA,OAAA,EA8BT,WA9BS,CA8BG,SA9BH,EA8Bc,aA9Bd,CA8B4B,eA9B5B,CAAA,EA8B8C,aA9B9C,CA8B4D,eA9B5D,CAAA,CAAA,EAAA,GA+Bd,MA/Bc,CA+BP,SA/BO,EAAA,GAAA,CAAA;EAQA,QAAA,CAAA,EAAA,CAAA,IAAA,EAwBD,KAxBC,EAAA,GAwBS,MAAA,CAAO,MAxBhB,CAAA,IAAA,EAwB6B,KAxB7B,EAAA,KAAA,CAAA;CAAe,CAAA,EA4FN,uBA5FM,CA4FkB,SA5FlB,EA4F6B,CA5F7B,EA4FgC,CA5FhC,EA4FmC,eA5FnC,EA4FoD,KA5FpD,CAAA"}
|
package/dist/plugin.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Context, Implementer, Router } from "@orpc/server";
|
|
2
|
-
import { Effect, Scope } from "effect";
|
|
3
1
|
import { AnyContractRouter, AnySchema, InferSchemaOutput } from "@orpc/contract";
|
|
2
|
+
import { Effect, Scope } from "effect";
|
|
3
|
+
import { Context as Context$1, Implementer, Router } from "@orpc/server";
|
|
4
4
|
|
|
5
5
|
//#region src/plugin.d.ts
|
|
6
6
|
type ContextOutput<T> = T extends AnySchema ? InferSchemaOutput<T> : {};
|
|
@@ -15,7 +15,7 @@ type PluginConfigFor<V extends AnySchema, S extends AnySchema, TRequestContext e
|
|
|
15
15
|
/**
|
|
16
16
|
* Loaded plugin with static binding property
|
|
17
17
|
*/
|
|
18
|
-
interface LoadedPluginWithBinding<TContract extends AnyContractRouter, TVariables extends AnySchema, TSecrets extends AnySchema, TRequestContext extends AnySchema | undefined, TDeps extends Context = Record<never, never>> {
|
|
18
|
+
interface LoadedPluginWithBinding<TContract extends AnyContractRouter, TVariables extends AnySchema, TSecrets extends AnySchema, TRequestContext extends AnySchema | undefined, TDeps extends Context$1 = Record<never, never>> {
|
|
19
19
|
new (): Plugin<TContract, TVariables, TSecrets, TRequestContext, TDeps>;
|
|
20
20
|
binding: {
|
|
21
21
|
contract: TContract;
|
|
@@ -27,7 +27,7 @@ interface LoadedPluginWithBinding<TContract extends AnyContractRouter, TVariable
|
|
|
27
27
|
/**
|
|
28
28
|
* Plugin interface
|
|
29
29
|
*/
|
|
30
|
-
interface Plugin<TContract extends AnyContractRouter, TVariables extends AnySchema, TSecrets extends AnySchema, TRequestContext extends AnySchema | undefined, TDeps extends Context = Record<never, never>> {
|
|
30
|
+
interface Plugin<TContract extends AnyContractRouter, TVariables extends AnySchema, TSecrets extends AnySchema, TRequestContext extends AnySchema | undefined, TDeps extends Context$1 = Record<never, never>> {
|
|
31
31
|
readonly id: string;
|
|
32
32
|
readonly contract: TContract;
|
|
33
33
|
readonly configSchema: PluginConfigFor<TVariables, TSecrets, TRequestContext>;
|
|
@@ -47,7 +47,7 @@ interface Plugin<TContract extends AnyContractRouter, TVariables extends AnySche
|
|
|
47
47
|
/**
|
|
48
48
|
* Factory function to create plugins
|
|
49
49
|
*/
|
|
50
|
-
declare function createPlugin<V extends AnySchema, S extends AnySchema, TContract extends AnyContractRouter, TRequestContext extends AnySchema | undefined = undefined, TDeps extends Context = Record<never, never>>(config: {
|
|
50
|
+
declare function createPlugin<V extends AnySchema, S extends AnySchema, TContract extends AnyContractRouter, TRequestContext extends AnySchema | undefined = undefined, TDeps extends Context$1 = Record<never, never>>(config: {
|
|
51
51
|
variables: V;
|
|
52
52
|
secrets: S;
|
|
53
53
|
contract: TContract;
|
package/dist/plugin.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.mts","names":[],"sources":["../src/plugin.ts"],"sourcesContent":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"plugin.d.mts","names":[],"sources":["../src/plugin.ts"],"sourcesContent":[],"mappings":";;;;;KAMK,mBAAmB,UAAU,YAAY,kBAAkB;;AAHpB;;AAGV,KAKtB,eALsB,CAAA,UAKI,SALJ,EAAA,UAKyB,SALzB,EAAA,wBAK4D,SAL5D,GAAA,SAAA,CAAA,GAAA;EAA8B,SAAA,EAMpD,CANoD;EAAlB,OAAA,EAOpC,CAPoC;EAAiB,OAAA,EAQrD,eARqD;AAK/D,CAAA;;;;AACY,UAQK,uBARL,CAAA,kBASO,iBATP,EAAA,mBAUQ,SAVR,EAAA,iBAWM,SAXN,EAAA,wBAYa,SAZb,GAAA,SAAA,EAAA,cAaG,SAbH,GAaa,MAbb,CAAA,KAAA,EAAA,KAAA,CAAA,CAAA,CAAA;EACF,MAAA,EAcF,MAdE,CAcK,SAdL,EAcgB,UAdhB,EAc4B,QAd5B,EAcsC,eAdtC,EAcuD,KAdvD,CAAA;EACA,OAAA,EAAA;IAAe,QAAA,EAeb,SAfa;IAMR,SAAA,EAUJ,UAVI;IACE,OAAA,EAUR,QAVQ;IACC,OAAA,EAUT,eAVS;EACF,CAAA;;;;;AAIQ,UAYT,MAZS,CAAA,kBAaP,iBAbO,EAAA,mBAcN,SAdM,EAAA,iBAeR,SAfQ,EAAA,wBAgBD,SAhBC,GAAA,SAAA,EAAA,cAiBX,SAjBW,GAiBD,MAjBC,CAAA,KAAA,EAAA,KAAA,CAAA,CAAA,CAAA;EAAY,SAAA,EAAA,EAAA,MAAA;EAAU,SAAA,QAAA,EAoB5B,SApB4B;EAAiB,SAAA,YAAA,EAqBzC,eArByC,CAqBzB,UArByB,EAqBb,QArBa,EAqBH,eArBG,CAAA;EAAzD,UAAA,CAAA,MAAA,EAAA;IAEI,SAAA,EAuBW,i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AAA,CAAA,EAAA,CAAA,IAAA,EAwBD,KAxBC,EAAA,GAwBS,MAAA,CAAO,MAxBhB,CAAA,IAAA,EAwB6B,KAxB7B,EAAA,KAAA,CAAA;CAAe,CAAA,EA4FN,uBA5FM,CA4FkB,SA5FlB,EA4F6B,CA5F7B,EA4FgC,CA5FhC,EA4FmC,eA5FnC,EA4FoD,KA5FpD,CAAA"}
|
package/dist/plugin.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { formatORPCError } from "./runtime/errors.mjs";
|
|
2
2
|
import { Effect } from "effect";
|
|
3
|
+
import { implement, onError, os } from "@orpc/server";
|
|
3
4
|
|
|
4
5
|
//#region src/plugin.ts
|
|
5
6
|
/**
|
|
@@ -29,7 +30,10 @@ function createPlugin(config) {
|
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
32
|
createRouter(deps) {
|
|
32
|
-
const
|
|
33
|
+
const base = os.$context().use(onError((error) => {
|
|
34
|
+
formatORPCError(error);
|
|
35
|
+
}));
|
|
36
|
+
const builder = implement(config.contract, base);
|
|
33
37
|
return config.createRouter(deps, builder);
|
|
34
38
|
}
|
|
35
39
|
}
|
package/dist/plugin.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.mjs","names":["configSchema: PluginConfigFor<V, S, TRequestContext>"],"sources":["../src/plugin.ts"],"sourcesContent":["import type { AnyContractRouter, AnySchema, InferSchemaOutput } from \"@orpc/contract\";\nimport type { Context, Implementer, Router } from \"@orpc/server\";\nimport { implement } from \"@orpc/server\";\nimport { Effect, type Scope } from \"effect\";\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
|
|
1
|
+
{"version":3,"file":"plugin.mjs","names":["configSchema: PluginConfigFor<V, S, TRequestContext>"],"sources":["../src/plugin.ts"],"sourcesContent":["import type { AnyContractRouter, AnySchema, InferSchemaOutput } from \"@orpc/contract\";\nimport type { Context, Implementer, Router } from \"@orpc/server\";\nimport { implement, onError, os } from \"@orpc/server\";\nimport { Effect, type Scope } from \"effect\";\nimport { 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\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":";;;;;;;;AAqEA,SAAgB,aAMd,QAaC;CACF,MAAMA,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;AACvB,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,6 +1,6 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let effect = require("effect");
|
|
3
2
|
let __orpc_contract = require("@orpc/contract");
|
|
3
|
+
let effect = require("effect");
|
|
4
4
|
|
|
5
5
|
//#region src/runtime/errors.ts
|
|
6
6
|
var PluginRuntimeError = class extends effect.Data.TaggedError("PluginRuntimeError") {};
|
|
@@ -16,6 +16,95 @@ const extractErrorMessage = (error) => {
|
|
|
16
16
|
if (typeof error === "object" && "message" in error) return String(error.message);
|
|
17
17
|
return String(error);
|
|
18
18
|
};
|
|
19
|
+
const formatValidationIssue = (issue, index, maxDisplay) => {
|
|
20
|
+
if (index >= maxDisplay) return "";
|
|
21
|
+
const path = Array.isArray(issue.path) && issue.path.length > 0 ? issue.path.join(".") : issue.path || "root";
|
|
22
|
+
const message = issue.message || "Validation failed";
|
|
23
|
+
return `│ ${index + 1}. ${path}: ${message}`;
|
|
24
|
+
};
|
|
25
|
+
const formatDataPreview = (data, maxLength = 100) => {
|
|
26
|
+
if (!data) return "undefined";
|
|
27
|
+
try {
|
|
28
|
+
const str = JSON.stringify(data);
|
|
29
|
+
if (str.length <= maxLength) return str;
|
|
30
|
+
if (typeof data === "object" && data !== null) {
|
|
31
|
+
if (Array.isArray(data)) return `Array(${data.length}) [...]`;
|
|
32
|
+
const keys = Object.keys(data);
|
|
33
|
+
return `{ ${keys.slice(0, 3).join(", ")}${keys.length > 3 ? ", ..." : ""} }`;
|
|
34
|
+
}
|
|
35
|
+
return str.slice(0, maxLength) + "...";
|
|
36
|
+
} catch {
|
|
37
|
+
return String(data).slice(0, maxLength);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const formatORPCValidationError = (error) => {
|
|
41
|
+
const cause = error?.cause || error;
|
|
42
|
+
if (!cause?.issues || !Array.isArray(cause.issues) || cause.issues.length === 0) return null;
|
|
43
|
+
const lines = [];
|
|
44
|
+
const errorType = error?.message || cause?.message || "Validation failed";
|
|
45
|
+
lines.push(`\n╭─ oRPC Validation Error ${"─".repeat(30)}`);
|
|
46
|
+
lines.push(`│ ${errorType}`);
|
|
47
|
+
lines.push(`│`);
|
|
48
|
+
const maxDisplay = 10;
|
|
49
|
+
const totalIssues = cause.issues.length;
|
|
50
|
+
lines.push(`│ Issues (${totalIssues}):`);
|
|
51
|
+
cause.issues.slice(0, maxDisplay).forEach((issue, idx) => {
|
|
52
|
+
const formatted = formatValidationIssue(issue, idx, maxDisplay);
|
|
53
|
+
if (formatted) lines.push(formatted);
|
|
54
|
+
});
|
|
55
|
+
if (totalIssues > maxDisplay) lines.push(`│ ... and ${totalIssues - maxDisplay} more`);
|
|
56
|
+
if (cause.data !== void 0) {
|
|
57
|
+
lines.push(`│`);
|
|
58
|
+
lines.push(`│ Data preview: ${formatDataPreview(cause.data, 80)}`);
|
|
59
|
+
}
|
|
60
|
+
lines.push(`╰${"─".repeat(50)}\n`);
|
|
61
|
+
return lines;
|
|
62
|
+
};
|
|
63
|
+
const formatORPCError = (error) => {
|
|
64
|
+
if (!(error instanceof __orpc_contract.ORPCError)) return;
|
|
65
|
+
const validationLines = formatORPCValidationError(error);
|
|
66
|
+
if (validationLines) {
|
|
67
|
+
console.error(validationLines.join("\n"));
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const lines = [];
|
|
71
|
+
const code = error.code || "UNKNOWN";
|
|
72
|
+
const status = error.status || 500;
|
|
73
|
+
const message = error.message || "An error occurred";
|
|
74
|
+
lines.push(`\n╭─ oRPC Error ${"─".repeat(40)}`);
|
|
75
|
+
lines.push(`│ ${message}`);
|
|
76
|
+
lines.push(`│ Code: ${code} (${status})`);
|
|
77
|
+
lines.push(`│`);
|
|
78
|
+
if (error.data) {
|
|
79
|
+
if (typeof error.data === "object" && error.data !== null) {
|
|
80
|
+
if ("retryAfter" in error.data) lines.push(`│ Retry after: ${error.data.retryAfter} seconds`);
|
|
81
|
+
if ("remainingRequests" in error.data) lines.push(`│ Remaining: ${error.data.remainingRequests} requests`);
|
|
82
|
+
if ("host" in error.data) lines.push(`│ Host: ${error.data.host}`);
|
|
83
|
+
if ("port" in error.data) lines.push(`│ Port: ${error.data.port}`);
|
|
84
|
+
if ("suggestion" in error.data) lines.push(`│ → ${error.data.suggestion}`);
|
|
85
|
+
if ("resource" in error.data) lines.push(`│ Resource: ${error.data.resource}`);
|
|
86
|
+
if ("resourceId" in error.data) lines.push(`│ ID: ${error.data.resourceId}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
switch (code) {
|
|
90
|
+
case "UNAUTHORIZED":
|
|
91
|
+
lines.push(`│ → Check your API key or credentials`);
|
|
92
|
+
break;
|
|
93
|
+
case "TOO_MANY_REQUESTS":
|
|
94
|
+
lines.push(`│ → Wait before retrying`);
|
|
95
|
+
break;
|
|
96
|
+
case "SERVICE_UNAVAILABLE":
|
|
97
|
+
case "BAD_GATEWAY":
|
|
98
|
+
case "GATEWAY_TIMEOUT":
|
|
99
|
+
lines.push(`│ → The service may be temporarily unavailable`);
|
|
100
|
+
break;
|
|
101
|
+
case "TIMEOUT":
|
|
102
|
+
lines.push(`│ → The operation took too long`);
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
lines.push(`╰${"─".repeat(50)}\n`);
|
|
106
|
+
console.error(lines.join("\n"));
|
|
107
|
+
};
|
|
19
108
|
const formatPluginError = (pluginId, operation, message) => {
|
|
20
109
|
const lines = [];
|
|
21
110
|
lines.push(`\n╭─ Plugin Error ${"─".repeat(40)}`);
|
|
@@ -67,6 +156,8 @@ const isRetryableORPCCode = (code) => {
|
|
|
67
156
|
}
|
|
68
157
|
};
|
|
69
158
|
const wrapORPCError = (orpcError, pluginId, procedureName, operation) => {
|
|
159
|
+
const validationLines = formatORPCValidationError(orpcError);
|
|
160
|
+
if (validationLines) console.error(validationLines.join("\n"));
|
|
70
161
|
return new PluginRuntimeError({
|
|
71
162
|
pluginId,
|
|
72
163
|
operation,
|
|
@@ -78,14 +169,15 @@ const wrapORPCError = (orpcError, pluginId, procedureName, operation) => {
|
|
|
78
169
|
const toPluginRuntimeError = (error, pluginId, procedureName, operation, defaultRetryable = false) => {
|
|
79
170
|
if (error instanceof __orpc_contract.ORPCError) return wrapORPCError(error, pluginId, procedureName, operation);
|
|
80
171
|
if (error instanceof PluginRuntimeError) return error;
|
|
81
|
-
const
|
|
82
|
-
|
|
172
|
+
const validationLines = formatORPCValidationError(error);
|
|
173
|
+
if (validationLines) console.error(validationLines.join("\n"));
|
|
174
|
+
else formatPluginError(pluginId, operation, extractErrorMessage(error));
|
|
83
175
|
return new PluginRuntimeError({
|
|
84
176
|
pluginId,
|
|
85
177
|
operation,
|
|
86
178
|
procedureName,
|
|
87
|
-
retryable: defaultRetryable || isRetryableError(
|
|
88
|
-
cause: error instanceof Error ? error : new Error(
|
|
179
|
+
retryable: defaultRetryable || isRetryableError(extractErrorMessage(error)),
|
|
180
|
+
cause: error instanceof Error ? error : new Error(extractErrorMessage(error))
|
|
89
181
|
});
|
|
90
182
|
};
|
|
91
183
|
|
|
@@ -93,5 +185,8 @@ const toPluginRuntimeError = (error, pluginId, procedureName, operation, default
|
|
|
93
185
|
exports.ModuleFederationError = ModuleFederationError;
|
|
94
186
|
exports.PluginRuntimeError = PluginRuntimeError;
|
|
95
187
|
exports.ValidationError = ValidationError;
|
|
188
|
+
exports.formatORPCError = formatORPCError;
|
|
189
|
+
exports.isRetryableORPCCode = isRetryableORPCCode;
|
|
96
190
|
exports.toPluginRuntimeError = toPluginRuntimeError;
|
|
191
|
+
exports.wrapORPCError = wrapORPCError;
|
|
97
192
|
//# sourceMappingURL=errors.cjs.map
|
|
@@ -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 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\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 message = extractErrorMessage(error);\n\n\tformatPluginError(pluginId, operation, message);\n\n\treturn new PluginRuntimeError({\n\t\tpluginId,\n\t\toperation,\n\t\tprocedureName,\n\t\tretryable: defaultRetryable || isRetryableError(message),\n\t\tcause: error instanceof Error ? error : new Error(message)\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,MAAM,qBACL,UACA,WACA,YACU;CACV,MAAMC,QAAkB,EAAE;AAE1B,OAAM,KAAK,qBAAqB,IAAI,OAAO,GAAG,GAAG;AACjD,KAAI,SAAU,OAAM,KAAK,cAAc,WAAW;AAClD,KAAI,UAAW,OAAM,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AO;EACP,CAAC;;AAIH,MAAa,wBACZ,OACA,UACA,eACA,WACA,mBAAmB,UACK;AACxB,KAAI,iBAAiBC,0BACpB,QAAO,cAAc,OAAO,UAAU,eAAe,UAAU;AAGhE,KAAI,iBAAiB,mBACpB,QAAO;CAGR,MAAM,UAAU,oBAAoB,MAAM;AAE1C,mBAAkB,UAAU,WAAW,QAAQ;AAE/C,QAAO,IAAI,mBAAmB;EAC7B;EACA;EACA;EACA,WAAW,oBAAoB,iBAAiB,QAAQ;EACxD,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,QAAQ;EAC1D,CAAC"}
|
|
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,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,MAAM,yBAAyB,OAAY,OAAe,eAA+B;AACxF,KAAI,SAAS,WAAY,QAAO;CAEhC,MAAM,OAAO,MAAM,QAAQ,MAAM,KAAK,IAAI,MAAM,KAAK,SAAS,IAC3D,MAAM,KAAK,KAAK,IAAI,GACpB,MAAM,QAAQ;CAEjB,MAAM,UAAU,MAAM,WAAW;AAEjC,QAAO,QAAQ,QAAQ,EAAE,IAAI,KAAK,IAAI;;AAGvC,MAAM,qBAAqB,MAAe,YAAY,QAAgB;AACrE,KAAI,CAAC,KAAM,QAAO;AAElB,KAAI;EACH,MAAM,MAAM,KAAK,UAAU,KAAK;AAChC,MAAI,IAAI,UAAU,UAAW,QAAO;AAEpC,MAAI,OAAO,SAAS,YAAY,SAAS,MAAM;AAC9C,OAAI,MAAM,QAAQ,KAAK,CACtB,QAAO,SAAS,KAAK,OAAO;GAE7B,MAAM,OA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UACA,eACA,cACwB;CACxB,MAAM,kBAAkB,0BAA0B,UAAU;AAC5D,KAAI,gBACH,SAAQ,MAAM,gBAAgB,KAAK,KAAK,CAAC;AAG1C,QAAO,IAAI,mBAAmB;EAC7B;EACA;EACA;EACA,WAAW,oBAAoB,UAAU,KAAK;EAC9C,OAAO;EACP,CAAC;;AAIH,MAAa,wBACZ,OACA,UACA,eACA,WACA,mBAAmB,UACK;AACxB,KAAI,iBAAiBC,0BACpB,QAAO,cAAc,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,7 +1,7 @@
|
|
|
1
|
-
import "zod";
|
|
2
|
-
import "@orpc/contract";
|
|
1
|
+
import { z } from "zod";
|
|
3
2
|
import * as effect_Types0 from "effect/Types";
|
|
4
3
|
import * as effect_Cause0 from "effect/Cause";
|
|
4
|
+
import { ORPCError } from "@orpc/contract";
|
|
5
5
|
|
|
6
6
|
//#region src/runtime/errors.d.ts
|
|
7
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] }) => effect_Cause0.YieldableError & {
|
|
@@ -22,6 +22,18 @@ 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] }) => effect_Cause0.YieldableError & {
|
|
26
|
+
readonly _tag: "ValidationError";
|
|
27
|
+
} & Readonly<A>;
|
|
28
|
+
declare class ValidationError extends ValidationError_base<{
|
|
29
|
+
readonly pluginId: string;
|
|
30
|
+
readonly stage: "config" | "input" | "output" | "state";
|
|
31
|
+
readonly zodError: z.ZodError;
|
|
32
|
+
}> {}
|
|
33
|
+
declare const formatORPCError: (error: any) => void;
|
|
34
|
+
declare const isRetryableORPCCode: (code: string) => boolean;
|
|
35
|
+
declare const wrapORPCError: (orpcError: ORPCError<string, unknown>, pluginId?: string, procedureName?: string, operation?: string) => PluginRuntimeError;
|
|
36
|
+
declare const toPluginRuntimeError: (error: unknown, pluginId?: string, procedureName?: string, operation?: string, defaultRetryable?: boolean) => PluginRuntimeError;
|
|
25
37
|
//#endregion
|
|
26
|
-
export { ModuleFederationError, PluginRuntimeError };
|
|
38
|
+
export { ModuleFederationError, PluginRuntimeError, ValidationError, formatORPCError, isRetryableORPCCode, toPluginRuntimeError, wrapORPCError };
|
|
27
39
|
//# sourceMappingURL=errors.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.cts","names":[],"sources":["../../src/runtime/errors.ts"],"sourcesContent":[],"mappings":";;;;;;cAE6B;;;cAEhB,kBAAA,SAA2B;EAFX,SAAA,QAAA,CAAA,EAAA,MAAA;;;mBAMX;;;cAEZ;;;cAEO,qBAAA,SAA8B;;;EAR9B,SAAA,KAAA,CAAA,EAaK,KAbc;AAM1B,CAAA,CAAA,CAAA"}
|
|
1
|
+
{"version":3,"file":"errors.d.cts","names":[],"sources":["../../src/runtime/errors.ts"],"sourcesContent":[],"mappings":";;;;;;cAE6B;;;cAEhB,kBAAA,SAA2B;EAFX,SAAA,QAAA,CAAA,EAAA,MAAA;;;mBAMX;;;cAEZ;;;cAEO,qBAAA,SAA8B;;;EAR9B,SAAA,KAAA,CAAA,EAaK,KAbc;AAM1B,CAAA,CAAA,CAAA;cAQA;;;cAEO,eAAA,SAAwB;;;qBAGjB,CAAA,CAAE;;cAgGT;cAqHA;AAhOA,cA8OA,aA9OsB,EAAA,CAAA,SAKjB,EA0ON,SA/O+B,CAAA,MAAA,EAAA,OAAA,CAAA,EAAA,QAAA,CAAA,EAAA,MAAA,EAAA,aAAA,CAAA,EAAA,MAAA,EAAA,SAAA,CAAA,EAAA,MAAA,EAAA,GAmPxC,kBAnPwC;AAMrC,cA6PO,oBA7PP,EAAA,CAAA,KAAA,EAAA,OAAA,EAAA,QAAA,CAAA,EAAA,MAAA,EAAA,aAAA,CAAA,EAAA,MAAA,EAAA,SAAA,CAAA,EAAA,MAAA,EAAA,gBAAA,CAAA,EAAA,OAAA,EAAA,GAmQH,kBAnQG"}
|
|
@@ -22,6 +22,18 @@ 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] }) => effect_Cause0.YieldableError & {
|
|
26
|
+
readonly _tag: "ValidationError";
|
|
27
|
+
} & Readonly<A>;
|
|
28
|
+
declare class ValidationError extends ValidationError_base<{
|
|
29
|
+
readonly pluginId: string;
|
|
30
|
+
readonly stage: "config" | "input" | "output" | "state";
|
|
31
|
+
readonly zodError: z.ZodError;
|
|
32
|
+
}> {}
|
|
33
|
+
declare const formatORPCError: (error: any) => void;
|
|
34
|
+
declare const isRetryableORPCCode: (code: string) => boolean;
|
|
35
|
+
declare const wrapORPCError: (orpcError: ORPCError<string, unknown>, pluginId?: string, procedureName?: string, operation?: string) => PluginRuntimeError;
|
|
36
|
+
declare const toPluginRuntimeError: (error: unknown, pluginId?: string, procedureName?: string, operation?: string, defaultRetryable?: boolean) => PluginRuntimeError;
|
|
25
37
|
//#endregion
|
|
26
|
-
export { ModuleFederationError, PluginRuntimeError };
|
|
38
|
+
export { ModuleFederationError, PluginRuntimeError, ValidationError, formatORPCError, isRetryableORPCCode, toPluginRuntimeError, wrapORPCError };
|
|
27
39
|
//# sourceMappingURL=errors.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.mts","names":[],"sources":["../../src/runtime/errors.ts"],"sourcesContent":[],"mappings":";;;;;;cAE6B;;;cAEhB,kBAAA,SAA2B;EAFX,SAAA,QAAA,CAAA,EAAA,MAAA;;;mBAMX;;;cAEZ;;;cAEO,qBAAA,SAA8B;;;EAR9B,SAAA,KAAA,CAAA,EAaK,KAbc;AAM1B,CAAA,CAAA,CAAA"}
|
|
1
|
+
{"version":3,"file":"errors.d.mts","names":[],"sources":["../../src/runtime/errors.ts"],"sourcesContent":[],"mappings":";;;;;;cAE6B;;;cAEhB,kBAAA,SAA2B;EAFX,SAAA,QAAA,CAAA,EAAA,MAAA;;;mBAMX;;;cAEZ;;;cAEO,qBAAA,SAA8B;;;EAR9B,SAAA,KAAA,CAAA,EAaK,KAbc;AAM1B,CAAA,CAAA,CAAA;cAQA;;;cAEO,eAAA,SAAwB;;;qBAGjB,CAAA,CAAE;;cAgGT;cAqHA;AAhOA,cA8OA,aA9OsB,EAAA,CAAA,SAKjB,EA0ON,SA/O+B,CAAA,MAAA,EAAA,OAAA,CAAA,EAAA,QAAA,CAAA,EAAA,MAAA,EAAA,aAAA,CAAA,EAAA,MAAA,EAAA,SAAA,CAAA,EAAA,MAAA,EAAA,GAmPxC,kBAnPwC;AAMrC,cA6PO,oBA7PP,EAAA,CAAA,KAAA,EAAA,OAAA,EAAA,QAAA,CAAA,EAAA,MAAA,EAAA,aAAA,CAAA,EAAA,MAAA,EAAA,SAAA,CAAA,EAAA,MAAA,EAAA,gBAAA,CAAA,EAAA,OAAA,EAAA,GAmQH,kBAnQG"}
|
package/dist/runtime/errors.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Data } from "effect";
|
|
2
1
|
import { ORPCError } from "@orpc/contract";
|
|
2
|
+
import { Data } from "effect";
|
|
3
3
|
|
|
4
4
|
//#region src/runtime/errors.ts
|
|
5
5
|
var PluginRuntimeError = class extends Data.TaggedError("PluginRuntimeError") {};
|
|
@@ -15,6 +15,95 @@ const extractErrorMessage = (error) => {
|
|
|
15
15
|
if (typeof error === "object" && "message" in error) return String(error.message);
|
|
16
16
|
return String(error);
|
|
17
17
|
};
|
|
18
|
+
const formatValidationIssue = (issue, index, maxDisplay) => {
|
|
19
|
+
if (index >= maxDisplay) return "";
|
|
20
|
+
const path = Array.isArray(issue.path) && issue.path.length > 0 ? issue.path.join(".") : issue.path || "root";
|
|
21
|
+
const message = issue.message || "Validation failed";
|
|
22
|
+
return `│ ${index + 1}. ${path}: ${message}`;
|
|
23
|
+
};
|
|
24
|
+
const formatDataPreview = (data, maxLength = 100) => {
|
|
25
|
+
if (!data) return "undefined";
|
|
26
|
+
try {
|
|
27
|
+
const str = JSON.stringify(data);
|
|
28
|
+
if (str.length <= maxLength) return str;
|
|
29
|
+
if (typeof data === "object" && data !== null) {
|
|
30
|
+
if (Array.isArray(data)) return `Array(${data.length}) [...]`;
|
|
31
|
+
const keys = Object.keys(data);
|
|
32
|
+
return `{ ${keys.slice(0, 3).join(", ")}${keys.length > 3 ? ", ..." : ""} }`;
|
|
33
|
+
}
|
|
34
|
+
return str.slice(0, maxLength) + "...";
|
|
35
|
+
} catch {
|
|
36
|
+
return String(data).slice(0, maxLength);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const formatORPCValidationError = (error) => {
|
|
40
|
+
const cause = error?.cause || error;
|
|
41
|
+
if (!cause?.issues || !Array.isArray(cause.issues) || cause.issues.length === 0) return null;
|
|
42
|
+
const lines = [];
|
|
43
|
+
const errorType = error?.message || cause?.message || "Validation failed";
|
|
44
|
+
lines.push(`\n╭─ oRPC Validation Error ${"─".repeat(30)}`);
|
|
45
|
+
lines.push(`│ ${errorType}`);
|
|
46
|
+
lines.push(`│`);
|
|
47
|
+
const maxDisplay = 10;
|
|
48
|
+
const totalIssues = cause.issues.length;
|
|
49
|
+
lines.push(`│ Issues (${totalIssues}):`);
|
|
50
|
+
cause.issues.slice(0, maxDisplay).forEach((issue, idx) => {
|
|
51
|
+
const formatted = formatValidationIssue(issue, idx, maxDisplay);
|
|
52
|
+
if (formatted) lines.push(formatted);
|
|
53
|
+
});
|
|
54
|
+
if (totalIssues > maxDisplay) lines.push(`│ ... and ${totalIssues - maxDisplay} more`);
|
|
55
|
+
if (cause.data !== void 0) {
|
|
56
|
+
lines.push(`│`);
|
|
57
|
+
lines.push(`│ Data preview: ${formatDataPreview(cause.data, 80)}`);
|
|
58
|
+
}
|
|
59
|
+
lines.push(`╰${"─".repeat(50)}\n`);
|
|
60
|
+
return lines;
|
|
61
|
+
};
|
|
62
|
+
const formatORPCError = (error) => {
|
|
63
|
+
if (!(error instanceof ORPCError)) return;
|
|
64
|
+
const validationLines = formatORPCValidationError(error);
|
|
65
|
+
if (validationLines) {
|
|
66
|
+
console.error(validationLines.join("\n"));
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const lines = [];
|
|
70
|
+
const code = error.code || "UNKNOWN";
|
|
71
|
+
const status = error.status || 500;
|
|
72
|
+
const message = error.message || "An error occurred";
|
|
73
|
+
lines.push(`\n╭─ oRPC Error ${"─".repeat(40)}`);
|
|
74
|
+
lines.push(`│ ${message}`);
|
|
75
|
+
lines.push(`│ Code: ${code} (${status})`);
|
|
76
|
+
lines.push(`│`);
|
|
77
|
+
if (error.data) {
|
|
78
|
+
if (typeof error.data === "object" && error.data !== null) {
|
|
79
|
+
if ("retryAfter" in error.data) lines.push(`│ Retry after: ${error.data.retryAfter} seconds`);
|
|
80
|
+
if ("remainingRequests" in error.data) lines.push(`│ Remaining: ${error.data.remainingRequests} requests`);
|
|
81
|
+
if ("host" in error.data) lines.push(`│ Host: ${error.data.host}`);
|
|
82
|
+
if ("port" in error.data) lines.push(`│ Port: ${error.data.port}`);
|
|
83
|
+
if ("suggestion" in error.data) lines.push(`│ → ${error.data.suggestion}`);
|
|
84
|
+
if ("resource" in error.data) lines.push(`│ Resource: ${error.data.resource}`);
|
|
85
|
+
if ("resourceId" in error.data) lines.push(`│ ID: ${error.data.resourceId}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
switch (code) {
|
|
89
|
+
case "UNAUTHORIZED":
|
|
90
|
+
lines.push(`│ → Check your API key or credentials`);
|
|
91
|
+
break;
|
|
92
|
+
case "TOO_MANY_REQUESTS":
|
|
93
|
+
lines.push(`│ → Wait before retrying`);
|
|
94
|
+
break;
|
|
95
|
+
case "SERVICE_UNAVAILABLE":
|
|
96
|
+
case "BAD_GATEWAY":
|
|
97
|
+
case "GATEWAY_TIMEOUT":
|
|
98
|
+
lines.push(`│ → The service may be temporarily unavailable`);
|
|
99
|
+
break;
|
|
100
|
+
case "TIMEOUT":
|
|
101
|
+
lines.push(`│ → The operation took too long`);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
lines.push(`╰${"─".repeat(50)}\n`);
|
|
105
|
+
console.error(lines.join("\n"));
|
|
106
|
+
};
|
|
18
107
|
const formatPluginError = (pluginId, operation, message) => {
|
|
19
108
|
const lines = [];
|
|
20
109
|
lines.push(`\n╭─ Plugin Error ${"─".repeat(40)}`);
|
|
@@ -66,6 +155,8 @@ const isRetryableORPCCode = (code) => {
|
|
|
66
155
|
}
|
|
67
156
|
};
|
|
68
157
|
const wrapORPCError = (orpcError, pluginId, procedureName, operation) => {
|
|
158
|
+
const validationLines = formatORPCValidationError(orpcError);
|
|
159
|
+
if (validationLines) console.error(validationLines.join("\n"));
|
|
69
160
|
return new PluginRuntimeError({
|
|
70
161
|
pluginId,
|
|
71
162
|
operation,
|
|
@@ -77,17 +168,18 @@ const wrapORPCError = (orpcError, pluginId, procedureName, operation) => {
|
|
|
77
168
|
const toPluginRuntimeError = (error, pluginId, procedureName, operation, defaultRetryable = false) => {
|
|
78
169
|
if (error instanceof ORPCError) return wrapORPCError(error, pluginId, procedureName, operation);
|
|
79
170
|
if (error instanceof PluginRuntimeError) return error;
|
|
80
|
-
const
|
|
81
|
-
|
|
171
|
+
const validationLines = formatORPCValidationError(error);
|
|
172
|
+
if (validationLines) console.error(validationLines.join("\n"));
|
|
173
|
+
else formatPluginError(pluginId, operation, extractErrorMessage(error));
|
|
82
174
|
return new PluginRuntimeError({
|
|
83
175
|
pluginId,
|
|
84
176
|
operation,
|
|
85
177
|
procedureName,
|
|
86
|
-
retryable: defaultRetryable || isRetryableError(
|
|
87
|
-
cause: error instanceof Error ? error : new Error(
|
|
178
|
+
retryable: defaultRetryable || isRetryableError(extractErrorMessage(error)),
|
|
179
|
+
cause: error instanceof Error ? error : new Error(extractErrorMessage(error))
|
|
88
180
|
});
|
|
89
181
|
};
|
|
90
182
|
|
|
91
183
|
//#endregion
|
|
92
|
-
export { ModuleFederationError, PluginRuntimeError, ValidationError, toPluginRuntimeError };
|
|
184
|
+
export { ModuleFederationError, PluginRuntimeError, ValidationError, formatORPCError, isRetryableORPCCode, toPluginRuntimeError, wrapORPCError };
|
|
93
185
|
//# sourceMappingURL=errors.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.mjs","names":["lines: string[]"],"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 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\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 message = extractErrorMessage(error);\n\n\tformatPluginError(pluginId, operation, message);\n\n\treturn new PluginRuntimeError({\n\t\tpluginId,\n\t\toperation,\n\t\tprocedureName,\n\t\tretryable: defaultRetryable || isRetryableError(message),\n\t\tcause: error instanceof Error ? error : new Error(message)\n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a,EAAE;AACxE,QAAM,KAAK,yBAAyB;AACpC,QAAM,KAAK,MAAM;AACjB,QAAM,KAAK,8CAA8C;YAC/C,QAAQ,SAAS,MAAM,IAAI,QAAQ,SAAS,eAAe,EAAE;AACvE,QAAM,KAAK,6BAA6B;AACxC,QAAM,KAAK,MAAM;AACjB,QAAM,KAAK,wCAAwC;OAEnD,OAAM,KAAK,QAAQ,UAAU;AAG9B,OAAM,KAAK,IAAI,IAAI,OAAO,GAAG,CAAC,IAAI;AAElC,SAAQ,MAAM,MAAM,KAAK,KAAK,CAAC;;AAGhC,MAAM,oBAAoB,YAA6B;AAEtD,QAD0B;EAAC;EAAa;EAAc;EAAW;EAAO;EAAM,CACrD,MAAK,MAAK,QAAQ,aAAa,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;;AAIpF,MAAa,uBAAuB,SAA0B;AAC7D,SAAQ,MAAR;EACC,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,UACJ,QAAO;EACR,QACC,QAAO;;;AAKV,MAAa,iBACZ,WACA,UACA,eACA,cACwB;AACxB,QAAO,IAAI,mBAAmB;EAC7B;EACA;EACA;EACA,WAAW,oBAAoB,UAAU,KAAK;EAC9C,OAAO;EACP,CAAC;;AAIH,MAAa,wBACZ,OACA,UACA,eACA,WACA,mBAAmB,UACK;AACxB,KAAI,iBAAiB,UACpB,QAAO,cAAc,OAAO,UAAU,eAAe,UAAU;AAGhE,KAAI,iBAAiB,mBACpB,QAAO;CAGR,MAAM,UAAU,oBAAoB,MAAM;AAE1C,mBAAkB,UAAU,WAAW,QAAQ;AAE/C,QAAO,IAAI,mBAAmB;EAC7B;EACA;EACA;EACA,WAAW,oBAAoB,iBAAiB,QAAQ;EACxD,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,QAAQ;EAC1D,CAAC"}
|
|
1
|
+
{"version":3,"file":"errors.mjs","names":["lines: string[]"],"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,cAAwC,KAAK,YAAY,qBAAqB,CAM3E;AAEH,IAAa,wBAAb,cAA2C,KAAK,YAC/C,wBACA,CAIE;AAEH,IAAa,kBAAb,cAAqC,KAAK,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,kBA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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"}
|
package/dist/runtime/index.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_errors = require('./errors.cjs');
|
|
3
3
|
const require_plugin_service = require('./services/plugin.service.cjs');
|
|
4
|
-
let __orpc_server = require("@orpc/server");
|
|
5
4
|
let effect = require("effect");
|
|
5
|
+
let __orpc_server = require("@orpc/server");
|
|
6
6
|
|
|
7
7
|
//#region src/runtime/index.ts
|
|
8
8
|
var PluginRuntime = class {
|