@irpclib/irpc 1.0.0 → 1.1.1

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/module.d.ts CHANGED
@@ -57,21 +57,12 @@ declare class IRPCPackage<K extends string = 'id'> {
57
57
  * Declares a new IRPC specification and returns a callable stub.
58
58
  *
59
59
  * @param name - The unique name for the IRPC specification.
60
- * @param seed - Factory function returning the initial data value.
61
- * @param config - Optional configuration (description, schema, caching, etc).
60
+ * @param seedOrConfig - The initial data seed function, or configuration object.
61
+ * @param config - Optional configuration (if seed was provided).
62
62
  * @returns A stub function that can be used to call the IRPC.
63
63
  * @throws Error if an IRPC with the same name already exists.
64
64
  */
65
- declare<F, I extends IRPCInputs = IRPCInputs, O extends IRPCOutput = IRPCOutput>(name: string, seed: () => IRPCReturnOf<F>, config?: IRPCDeclareConfig<I, O>): IRPCFunction<F>;
66
- /**
67
- * Declares a new IRPC specification and returns a callable stub.
68
- *
69
- * @param name - The unique name for the IRPC specification.
70
- * @param config - Configuration object including seed and optional fields.
71
- * @returns A stub function that can be used to call the IRPC.
72
- * @throws Error if an IRPC with the same name already exists.
73
- */
74
- declare<F, I extends IRPCInputs = IRPCInputs, O extends IRPCOutput = IRPCOutput>(name: string, config: IRPCDeclareConfig<I, O> & IRPCInferInit<IRPCReturnOf<F>>): IRPCFunction<F>;
65
+ declare<F, I extends IRPCInputs = IRPCInputs, O extends IRPCOutput = IRPCOutput>(name: string, seedOrConfig: (() => IRPCReturnOf<F>) | (IRPCDeclareConfig<I, O> & IRPCInferInit<IRPCReturnOf<F>>), config?: IRPCDeclareConfig<I, O>): IRPCFunction<F>;
75
66
  /**
76
67
  * Declares a new IRPC specification and returns a callable stub.
77
68
  *
package/dist/module.js CHANGED
@@ -162,7 +162,7 @@ var IRPCPackage = class {
162
162
  const cached = caches.get(callKey);
163
163
  if (cached) return cached.value;
164
164
  if (spec.coalesce !== false && calls.has(callKey)) return calls.get(callKey);
165
- const { timeout, maxRetries, retryDelay, retryMode } = {
165
+ const { timeout, maxRetries, retryDelay, retryMode, standalone } = {
166
166
  ...this.config,
167
167
  ...spec
168
168
  };
@@ -170,7 +170,8 @@ var IRPCPackage = class {
170
170
  timeout,
171
171
  maxRetries,
172
172
  retryDelay,
173
- retryMode
173
+ retryMode,
174
+ standalone
174
175
  };
175
176
  const hooks = this.hooks.get(spec);
176
177
  if (hooks) hooks.forEach((hook) => hook({
@@ -50,13 +50,23 @@ declare class IRPCTransport {
50
50
  */
51
51
  close(call: IRPCCall): void;
52
52
  /**
53
- * Dispatches a batch of RPC calls. This base implementation rejects all calls
54
- * with a "not implemented" error. Subclasses should override this method to
55
- * provide actual transport mechanism.
53
+ * Dispatches RPC calls over the transport. Subclasses must override this
54
+ * to provide the actual transport mechanism (HTTP, WebSocket, etc.).
55
+ *
56
+ * When `standalone` is true, the call requires its own dedicated HTTP
57
+ * round-trip with full response lifecycle (cookies, headers). This is
58
+ * used for operations like authentication where `Set-Cookie` headers
59
+ * must flow back to the client. Only one call is dispatched at a time
60
+ * in standalone mode.
61
+ *
62
+ * When `standalone` is false or undefined, calls may be batched and
63
+ * streamed together in a single request.
64
+ *
56
65
  * @param calls - An array of RPC calls to dispatch.
66
+ * @param standalone - When true, dispatch as a dedicated request with full HTTP lifecycle.
57
67
  * @returns A promise that resolves when all calls have been processed.
58
68
  */
59
- protected dispatch(calls: IRPCCall[]): Promise<void>;
69
+ protected dispatch(calls: IRPCCall[], standalone?: boolean): Promise<void>;
60
70
  }
61
71
  //#endregion
62
72
  export { IRPCTransport };
package/dist/transport.js CHANGED
@@ -55,8 +55,8 @@ var IRPCTransport = class {
55
55
  retryMode,
56
56
  retryDelay
57
57
  }, reader);
58
- if (spec.stream) {
59
- this.dispatch([call]).finally(() => {}).catch((err) => IRPC_STORE.error(err, [{
58
+ if (spec.stream || config?.standalone) {
59
+ this.dispatch([call], config?.standalone).finally(() => {}).catch((err) => IRPC_STORE.error(err, [{
60
60
  id: call.id,
61
61
  name: call.payload.name
62
62
  }]));
@@ -106,13 +106,23 @@ var IRPCTransport = class {
106
106
  console.log("[irpc] Closing call", call);
107
107
  }
108
108
  /**
109
- * Dispatches a batch of RPC calls. This base implementation rejects all calls
110
- * with a "not implemented" error. Subclasses should override this method to
111
- * provide actual transport mechanism.
109
+ * Dispatches RPC calls over the transport. Subclasses must override this
110
+ * to provide the actual transport mechanism (HTTP, WebSocket, etc.).
111
+ *
112
+ * When `standalone` is true, the call requires its own dedicated HTTP
113
+ * round-trip with full response lifecycle (cookies, headers). This is
114
+ * used for operations like authentication where `Set-Cookie` headers
115
+ * must flow back to the client. Only one call is dispatched at a time
116
+ * in standalone mode.
117
+ *
118
+ * When `standalone` is false or undefined, calls may be batched and
119
+ * streamed together in a single request.
120
+ *
112
121
  * @param calls - An array of RPC calls to dispatch.
122
+ * @param standalone - When true, dispatch as a dedicated request with full HTTP lifecycle.
113
123
  * @returns A promise that resolves when all calls have been processed.
114
124
  */
115
- async dispatch(calls) {
125
+ async dispatch(calls, standalone) {
116
126
  calls.forEach((call) => {
117
127
  call.enqueue({
118
128
  id: call.id,
package/dist/types.d.ts CHANGED
@@ -396,6 +396,8 @@ type IRPCCallConfig = {
396
396
  retryMode?: 'linear' | 'exponential';
397
397
  /** Base delay between retries in milliseconds */
398
398
  retryDelay?: number;
399
+ /** Optional flag to dispatch the call as a standalone HTTP request with full cookie/header lifecycle */
400
+ standalone?: boolean;
399
401
  };
400
402
  /**
401
403
  * Configuration for transport layer, extending call configuration with debounce settings.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@irpclib/irpc",
4
- "version": "1.0.0",
4
+ "version": "1.1.1",
5
5
  "types": "./dist/index.d.ts",
6
6
  "module": "./dist/index.js",
7
7
  "exports": {
@@ -36,6 +36,7 @@
36
36
  "zod": "^4.1.5"
37
37
  },
38
38
  "peerDependencies": {
39
+ "@anchorlib/core": "^1.1.1",
39
40
  "typescript": "^5.9.3"
40
41
  },
41
42
  "optionalDependencies": {
@@ -44,14 +45,11 @@
44
45
  "scripts": {
45
46
  "dev": "rimraf dist && tsdown --watch ./src",
46
47
  "clean": "rimraf dist",
47
- "build": "rimraf dist && tsdown && publint",
48
+ "build": "bun run clean && tsdown && publint",
48
49
  "format": "biome format --write",
49
50
  "test": "rimraf coverage && vitest --run",
50
51
  "test:preview": "rimraf coverage && vitest --run && vite preview --outDir coverage",
51
- "prepublish": "bun run format && bun run clean && tsdown && publint"
52
+ "prepublish": "bun run format && bun run build"
52
53
  },
53
- "license": "MIT",
54
- "dependencies": {
55
- "@anchorlib/core": "^1.0.0"
56
- }
54
+ "license": "MIT"
57
55
  }