@irpclib/irpc 1.0.0-beta.25 → 1.0.0

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.
@@ -0,0 +1,76 @@
1
+ import { IRPCCrudMeta, IRPCData, IRPCDriver, IRPCStub } from "./types.js";
2
+ import { IRPCPackage } from "./module.js";
3
+
4
+ //#region src/adapter.d.ts
5
+ declare class NextDriver extends Error {
6
+ constructor();
7
+ }
8
+ /** Extracts operational method names from an adapter, excluding its own API. */
9
+ type AttachableMethod<T> = string & keyof Omit<T, 'attach' | 'use' | 'dispatch'>;
10
+ type AnyStub = IRPCStub<any, any[], any>;
11
+ /**
12
+ * Attaches handlers to IRPC stubs and bridges them to drivers.
13
+ * Dispatches calls through the registered driver chain.
14
+ */
15
+ declare class IRPCAdapter {
16
+ private module;
17
+ private drivers;
18
+ constructor(module: IRPCPackage);
19
+ /**
20
+ * Runs a get operation through the driver chain
21
+ * @param meta - Resolved entity metadata
22
+ * @param id - The entity identifier
23
+ */
24
+ get(meta: IRPCCrudMeta, id: IRPCData): Promise<IRPCData> | IRPCData;
25
+ /**
26
+ * Runs a create operation through the driver chain
27
+ * @param meta - Resolved entity metadata
28
+ * @param data - The entity data to create
29
+ */
30
+ create(meta: IRPCCrudMeta, data: IRPCData): Promise<IRPCData> | IRPCData;
31
+ /**
32
+ * Runs an update operation through the driver chain
33
+ * @param meta - Resolved entity metadata
34
+ * @param id - The entity identifier
35
+ * @param data - The entity data to update
36
+ */
37
+ update(meta: IRPCCrudMeta, id: IRPCData, data: IRPCData): Promise<IRPCData> | IRPCData;
38
+ /**
39
+ * Runs a delete operation through the driver chain
40
+ * @param meta - Resolved entity metadata
41
+ * @param id - The entity identifier
42
+ */
43
+ delete(meta: IRPCCrudMeta, id: IRPCData): Promise<IRPCData> | IRPCData;
44
+ /**
45
+ * Dispatches a method call through each registered driver in order
46
+ * @param method - The method name to dispatch
47
+ * @param meta - Resolved entity metadata
48
+ * @param args - Arguments forwarded to the driver method
49
+ * @throws CrudError.notImplemented if no driver handles the method
50
+ */
51
+ protected dispatch(method: string, meta: IRPCCrudMeta, ...args: IRPCData[]): Promise<IRPCData> | IRPCData;
52
+ /**
53
+ * Attaches a single stub to a specific method on this adapter
54
+ * @param stub - The stub function to attach
55
+ * @param method - The method name matching an adapter operation
56
+ * @throws CrudError.notFound if the stub is not registered in the package
57
+ */
58
+ attach(stub: AnyStub, method: AttachableMethod<this>): this;
59
+ /**
60
+ * Attaches stubs to this adapter by matching object keys to adapter methods
61
+ * @param stubs - Object mapping method names to stub functions
62
+ * @throws CrudError.notFound if a stub is not registered in the package
63
+ */
64
+ attach(stubs: Partial<Record<AttachableMethod<this>, AnyStub>>): this;
65
+ /**
66
+ * Registers a driver to handle dispatched operations
67
+ * @param driver - The driver implementation
68
+ */
69
+ use(driver: IRPCDriver): this;
70
+ /**
71
+ * Signals the current driver to pass execution to the next driver in the chain
72
+ */
73
+ static next(): NextDriver;
74
+ }
75
+ //#endregion
76
+ export { IRPCAdapter };
@@ -0,0 +1,109 @@
1
+ import { CrudError } from "./error.js";
2
+
3
+ //#region src/adapter.ts
4
+ var NextDriver = class extends Error {
5
+ constructor() {
6
+ super("Next driver");
7
+ }
8
+ };
9
+ /**
10
+ * Attaches handlers to IRPC stubs and bridges them to drivers.
11
+ * Dispatches calls through the registered driver chain.
12
+ */
13
+ var IRPCAdapter = class {
14
+ drivers = /* @__PURE__ */ new Set();
15
+ constructor(module) {
16
+ this.module = module;
17
+ }
18
+ /**
19
+ * Runs a get operation through the driver chain
20
+ * @param meta - Resolved entity metadata
21
+ * @param id - The entity identifier
22
+ */
23
+ get(meta, id) {
24
+ return this.dispatch("get", meta, id);
25
+ }
26
+ /**
27
+ * Runs a create operation through the driver chain
28
+ * @param meta - Resolved entity metadata
29
+ * @param data - The entity data to create
30
+ */
31
+ create(meta, data) {
32
+ return this.dispatch("create", meta, data);
33
+ }
34
+ /**
35
+ * Runs an update operation through the driver chain
36
+ * @param meta - Resolved entity metadata
37
+ * @param id - The entity identifier
38
+ * @param data - The entity data to update
39
+ */
40
+ update(meta, id, data) {
41
+ return this.dispatch("update", meta, id, data);
42
+ }
43
+ /**
44
+ * Runs a delete operation through the driver chain
45
+ * @param meta - Resolved entity metadata
46
+ * @param id - The entity identifier
47
+ */
48
+ delete(meta, id) {
49
+ return this.dispatch("delete", meta, id);
50
+ }
51
+ /**
52
+ * Dispatches a method call through each registered driver in order
53
+ * @param method - The method name to dispatch
54
+ * @param meta - Resolved entity metadata
55
+ * @param args - Arguments forwarded to the driver method
56
+ * @throws CrudError.notImplemented if no driver handles the method
57
+ */
58
+ dispatch(method, meta, ...args) {
59
+ for (const driver of this.drivers) {
60
+ const fn = driver[method];
61
+ if (!fn) continue;
62
+ try {
63
+ return fn(meta, ...args);
64
+ } catch (err) {
65
+ if (err instanceof NextDriver) continue;
66
+ throw err;
67
+ }
68
+ }
69
+ throw CrudError.notImplemented(method);
70
+ }
71
+ attach(stubOrStubs, m) {
72
+ const stubs = m ? { [m]: stubOrStubs } : stubOrStubs;
73
+ const key = this.module.config.key ?? "id";
74
+ for (const [method, stub] of Object.entries(stubs)) {
75
+ if (!stub) continue;
76
+ const spec = this.module["stubs"].get(stub);
77
+ if (!spec) throw CrudError.notFound();
78
+ const meta = {
79
+ name: spec.name.replace(`.${method}`, ""),
80
+ key,
81
+ description: spec.description,
82
+ schema: spec.schema,
83
+ maxAge: spec.maxAge,
84
+ coalesce: spec.coalesce
85
+ };
86
+ this.module.construct(stub, ((...args) => {
87
+ return this[method](meta, ...args);
88
+ }));
89
+ }
90
+ return this;
91
+ }
92
+ /**
93
+ * Registers a driver to handle dispatched operations
94
+ * @param driver - The driver implementation
95
+ */
96
+ use(driver) {
97
+ this.drivers.add(driver);
98
+ return this;
99
+ }
100
+ /**
101
+ * Signals the current driver to pass execution to the next driver in the chain
102
+ */
103
+ static next() {
104
+ return new NextDriver();
105
+ }
106
+ };
107
+
108
+ //#endregion
109
+ export { IRPCAdapter };
package/dist/call.js CHANGED
@@ -1,5 +1,5 @@
1
- import { IRPC_PACKET_TYPE, IRPC_STATUS } from "./enum.js";
2
1
  import { CallError } from "./error.js";
2
+ import { IRPC_PACKET_TYPE, IRPC_STATUS } from "./enum.js";
3
3
  import { IRPCReader } from "./reader.js";
4
4
  import { IRPC_STORE } from "./store.js";
5
5
  import { uuid } from "@anchorlib/core";
package/dist/error.d.ts CHANGED
@@ -5,6 +5,7 @@ declare const IRPC_ERROR_TYPE: {
5
5
  readonly STUB: "stub";
6
6
  readonly HOOK: "hook";
7
7
  readonly CALL: "call";
8
+ readonly CRUD: "crud";
8
9
  readonly HANDLER: "handler";
9
10
  readonly RESOLVE: "resolve";
10
11
  readonly TRANSPORT: "transport";
@@ -47,6 +48,10 @@ declare const CALL_ERROR: {
47
48
  readonly MAX_RETRIES: "max_retries";
48
49
  readonly STREAM_ERROR: "stream_error";
49
50
  };
51
+ declare const CRUD_ERROR: {
52
+ readonly NOT_FOUND: "not_found";
53
+ readonly NOT_IMPLEMENTED: "not_implemented";
54
+ };
50
55
  /**
51
56
  * Base error class for all IRPC errors.
52
57
  *
@@ -112,5 +117,11 @@ declare class CallError extends IRPCError {
112
117
  static maxRetries(reasons: Set<Error>): CallError;
113
118
  static streamError(input: Error | string): CallError;
114
119
  }
120
+ /** Errors related to CRUD adapter operations. */
121
+ declare class CrudError extends IRPCError {
122
+ constructor(code: string, message: string, cause?: Error);
123
+ static notFound(): CrudError;
124
+ static notImplemented(method: string): CrudError;
125
+ }
115
126
  //#endregion
116
- export { CALL_ERROR, CallError, HANDLER_ERROR, HOOK_ERROR, HandlerError, HookError, IRPCError, IRPCErrorType, IRPC_ERROR_TYPE, RESOLVE_ERROR, ResolveError, STUB_ERROR, StubError, TRANSPORT_ERROR, TransportError };
127
+ export { CALL_ERROR, CRUD_ERROR, CallError, CrudError, HANDLER_ERROR, HOOK_ERROR, HandlerError, HookError, IRPCError, IRPCErrorType, IRPC_ERROR_TYPE, RESOLVE_ERROR, ResolveError, STUB_ERROR, StubError, TRANSPORT_ERROR, TransportError };
package/dist/error.js CHANGED
@@ -3,6 +3,7 @@ const IRPC_ERROR_TYPE = {
3
3
  STUB: "stub",
4
4
  HOOK: "hook",
5
5
  CALL: "call",
6
+ CRUD: "crud",
6
7
  HANDLER: "handler",
7
8
  RESOLVE: "resolve",
8
9
  TRANSPORT: "transport"
@@ -44,6 +45,10 @@ const CALL_ERROR = {
44
45
  MAX_RETRIES: "max_retries",
45
46
  STREAM_ERROR: "stream_error"
46
47
  };
48
+ const CRUD_ERROR = {
49
+ NOT_FOUND: "not_found",
50
+ NOT_IMPLEMENTED: "not_implemented"
51
+ };
47
52
  function unwrap(input) {
48
53
  if (input instanceof Error) return {
49
54
  message: input.message,
@@ -199,14 +204,27 @@ var CallError = class CallError extends IRPCError {
199
204
  return new CallError(CALL_ERROR.STREAM_ERROR, message, cause);
200
205
  }
201
206
  };
207
+ /** Errors related to CRUD adapter operations. */
208
+ var CrudError = class CrudError extends IRPCError {
209
+ constructor(code, message, cause) {
210
+ super(IRPC_ERROR_TYPE.CRUD, code, message, cause);
211
+ }
212
+ static notFound() {
213
+ return new CrudError(CRUD_ERROR.NOT_FOUND, "Unknown CRUD instance — was it created with pkg.crud()?");
214
+ }
215
+ static notImplemented(method) {
216
+ return new CrudError(CRUD_ERROR.NOT_IMPLEMENTED, `CRUD method "${method}" not implemented.`);
217
+ }
218
+ };
202
219
  const IRPC_ERROR_CLASS = {
203
220
  [IRPC_ERROR_TYPE.STUB]: StubError,
204
221
  [IRPC_ERROR_TYPE.HANDLER]: HandlerError,
205
222
  [IRPC_ERROR_TYPE.TRANSPORT]: TransportError,
206
223
  [IRPC_ERROR_TYPE.RESOLVE]: ResolveError,
207
224
  [IRPC_ERROR_TYPE.HOOK]: HookError,
208
- [IRPC_ERROR_TYPE.CALL]: CallError
225
+ [IRPC_ERROR_TYPE.CALL]: CallError,
226
+ [IRPC_ERROR_TYPE.CRUD]: CrudError
209
227
  };
210
228
 
211
229
  //#endregion
212
- export { CALL_ERROR, CallError, HANDLER_ERROR, HOOK_ERROR, HandlerError, HookError, IRPCError, IRPC_ERROR_TYPE, RESOLVE_ERROR, ResolveError, STUB_ERROR, StubError, TRANSPORT_ERROR, TransportError };
230
+ export { CALL_ERROR, CRUD_ERROR, CallError, CrudError, HANDLER_ERROR, HOOK_ERROR, HandlerError, HookError, IRPCError, IRPC_ERROR_TYPE, RESOLVE_ERROR, ResolveError, STUB_ERROR, StubError, TRANSPORT_ERROR, TransportError };
package/dist/index.d.ts CHANGED
@@ -1,19 +1,20 @@
1
- import { IRPCCacheEntry, IRPCCacher } from "./cache.js";
2
1
  import { IRPC_BASE_CONTEXT, IRPC_FILE_STATUS, IRPC_PACKET_TYPE, IRPC_STATUS, IRPC_STORE_EVENT } from "./enum.js";
3
2
  import { IRPCFile, IRPCFileMeta, IRPCFilePipe, IRPCFileState, IRPCFileStatus, IRPCFileStream, IRPCFileUnpipe } from "./file.js";
4
3
  import { IRPCFilePointer, IRPCFileQueue, IRPCPacketJson, IRPCPacketQueues, IRPC_FILE_IDENTIFIER, PacketStream, decode, encode, isFilePointer } from "./packet.js";
5
- import { IRPCHookArgs, IRPCPackage, IRPCSpecHook, createPackage, intercept } from "./module.js";
4
+ import { DEFAULT_RETRY_DELAY, DEFAULT_RETRY_MODE, IRPCCall } from "./call.js";
6
5
  import { IRPCTransport } from "./transport.js";
7
- import { IRPCArraySchema, IRPCCallConfig, IRPCContext, IRPCContextProvider, IRPCCredentials, IRPCCredentialsFactory, IRPCData, IRPCDataSchema, IRPCDeclareInit, IRPCDefined, IRPCFunction, IRPCHandler, IRPCInferInit, IRPCInit, IRPCInputs, IRPCObject, IRPCObjectSchema, IRPCOutput, IRPCPackageConfig, IRPCPackageInfo, IRPCPacketAnswer, IRPCPacketBase, IRPCPacketCall, IRPCPacketClose, IRPCPacketError, IRPCPacketEvent, IRPCPacketStream, IRPCPacketType, IRPCParseResult, IRPCPayload, IRPCPrimitive, IRPCPrimitiveSchema, IRPCReadable, IRPCRequest, IRPCRequests, IRPCResponse, IRPCSchema, IRPCSpec, IRPCSpecStore, IRPCStatus, IRPCStreamInit, IRPCStub, IRPCStubStore, StreamCleanup, StreamConstructor, TransportConfig } from "./types.js";
6
+ import { IRPCArraySchema, IRPCCallConfig, IRPCContext, IRPCContextProvider, IRPCCredentials, IRPCCredentialsFactory, IRPCCrudField, IRPCCrudMeta, IRPCCrudMethod, IRPCCrudOptions, IRPCCrudStubs, IRPCData, IRPCDataSchema, IRPCDeclareConfig, IRPCDeclareInit, IRPCDefined, IRPCDriver, IRPCEntityId, IRPCFunction, IRPCHandler, IRPCInferInit, IRPCInit, IRPCInputs, IRPCObject, IRPCObjectSchema, IRPCOutput, IRPCPackageConfig, IRPCPackageInfo, IRPCPacketAnswer, IRPCPacketBase, IRPCPacketCall, IRPCPacketClose, IRPCPacketError, IRPCPacketEvent, IRPCPacketStream, IRPCPacketType, IRPCParseResult, IRPCPayload, IRPCPrimitive, IRPCPrimitiveSchema, IRPCReadable, IRPCRequest, IRPCRequests, IRPCResponse, IRPCReturnOf, IRPCSchema, IRPCSpec, IRPCSpecStore, IRPCStatus, IRPCStreamInit, IRPCStub, IRPCStubStore, StreamCleanup, StreamConstructor, TransportConfig } from "./types.js";
8
7
  import { RemoteState, stream } from "./state.js";
9
8
  import { IRPCReader } from "./reader.js";
10
- import { DEFAULT_RETRY_DELAY, DEFAULT_RETRY_MODE, IRPCCall } from "./call.js";
9
+ import { IRPCHookArgs, IRPCPackage, IRPCSpecHook, createPackage, intercept } from "./module.js";
10
+ import { IRPCAdapter } from "./adapter.js";
11
+ import { IRPCCacheEntry, IRPCCacher } from "./cache.js";
11
12
  import { createContext, createContextStore, getAbortController, getAbortSignal, getContext, setContext, setContextProvider, withContext } from "./context.js";
12
13
  import { createCredentials, credential, getCredentials } from "./credential.js";
13
- import { CALL_ERROR, CallError, HANDLER_ERROR, HOOK_ERROR, HandlerError, HookError, IRPCError, IRPCErrorType, IRPC_ERROR_TYPE, RESOLVE_ERROR, ResolveError, STUB_ERROR, StubError, TRANSPORT_ERROR, TransportError } from "./error.js";
14
+ import { CALL_ERROR, CRUD_ERROR, CallError, CrudError, HANDLER_ERROR, HOOK_ERROR, HandlerError, HookError, IRPCError, IRPCErrorType, IRPC_ERROR_TYPE, RESOLVE_ERROR, ResolveError, STUB_ERROR, StubError, TRANSPORT_ERROR, TransportError } from "./error.js";
14
15
  import { IRPCResolver } from "./resolver.js";
15
16
  import { IRPCHook, IRPCRouter } from "./router.js";
16
17
  import { IRPCStream } from "./stream.js";
17
18
  import { IRPCStore, IRPCStoreEvent, IRPCStoreSubscriber, IRPC_STORE } from "./store.js";
18
19
  import { plan } from "@anchorlib/core";
19
- export { CALL_ERROR, CallError, DEFAULT_RETRY_DELAY, DEFAULT_RETRY_MODE, HANDLER_ERROR, HOOK_ERROR, HandlerError, HookError, IRPCArraySchema, IRPCCacheEntry, IRPCCacher, IRPCCall, IRPCCallConfig, IRPCContext, IRPCContextProvider, IRPCCredentials, IRPCCredentialsFactory, IRPCData, IRPCDataSchema, IRPCDeclareInit, IRPCDefined, IRPCError, IRPCErrorType, IRPCFile, IRPCFileMeta, IRPCFilePipe, IRPCFilePointer, IRPCFileQueue, IRPCFileState, IRPCFileStatus, IRPCFileStream, IRPCFileUnpipe, IRPCFunction, IRPCHandler, IRPCHook, IRPCHookArgs, IRPCInferInit, IRPCInit, IRPCInputs, IRPCObject, IRPCObjectSchema, IRPCOutput, IRPCPackage, IRPCPackageConfig, IRPCPackageInfo, IRPCPacketAnswer, IRPCPacketBase, IRPCPacketCall, IRPCPacketClose, IRPCPacketError, IRPCPacketEvent, IRPCPacketJson, IRPCPacketQueues, IRPCPacketStream, IRPCPacketType, IRPCParseResult, IRPCPayload, IRPCPrimitive, IRPCPrimitiveSchema, IRPCReadable, IRPCReader, IRPCRequest, IRPCRequests, IRPCResolver, IRPCResponse, IRPCRouter, IRPCSchema, IRPCSpec, IRPCSpecHook, IRPCSpecStore, IRPCStatus, IRPCStore, IRPCStoreEvent, IRPCStoreSubscriber, IRPCStream, IRPCStreamInit, IRPCStub, IRPCStubStore, IRPCTransport, IRPC_BASE_CONTEXT, IRPC_ERROR_TYPE, IRPC_FILE_IDENTIFIER, IRPC_FILE_STATUS, IRPC_PACKET_TYPE, IRPC_STATUS, IRPC_STORE, IRPC_STORE_EVENT, PacketStream, RESOLVE_ERROR, RemoteState, ResolveError, STUB_ERROR, StreamCleanup, StreamConstructor, StubError, TRANSPORT_ERROR, TransportConfig, TransportError, createContext, createContextStore, createCredentials, createPackage, credential, decode, encode, getAbortController, getAbortSignal, getContext, getCredentials, intercept, isFilePointer, plan, setContext, setContextProvider, stream, withContext };
20
+ export { CALL_ERROR, CRUD_ERROR, CallError, CrudError, DEFAULT_RETRY_DELAY, DEFAULT_RETRY_MODE, HANDLER_ERROR, HOOK_ERROR, HandlerError, HookError, IRPCAdapter, IRPCArraySchema, IRPCCacheEntry, IRPCCacher, IRPCCall, IRPCCallConfig, IRPCContext, IRPCContextProvider, IRPCCredentials, IRPCCredentialsFactory, IRPCCrudField, IRPCCrudMeta, IRPCCrudMethod, IRPCCrudOptions, IRPCCrudStubs, IRPCData, IRPCDataSchema, IRPCDeclareConfig, IRPCDeclareInit, IRPCDefined, IRPCDriver, IRPCEntityId, IRPCError, IRPCErrorType, IRPCFile, IRPCFileMeta, IRPCFilePipe, IRPCFilePointer, IRPCFileQueue, IRPCFileState, IRPCFileStatus, IRPCFileStream, IRPCFileUnpipe, IRPCFunction, IRPCHandler, IRPCHook, IRPCHookArgs, IRPCInferInit, IRPCInit, IRPCInputs, IRPCObject, IRPCObjectSchema, IRPCOutput, IRPCPackage, IRPCPackageConfig, IRPCPackageInfo, IRPCPacketAnswer, IRPCPacketBase, IRPCPacketCall, IRPCPacketClose, IRPCPacketError, IRPCPacketEvent, IRPCPacketJson, IRPCPacketQueues, IRPCPacketStream, IRPCPacketType, IRPCParseResult, IRPCPayload, IRPCPrimitive, IRPCPrimitiveSchema, IRPCReadable, IRPCReader, IRPCRequest, IRPCRequests, IRPCResolver, IRPCResponse, IRPCReturnOf, IRPCRouter, IRPCSchema, IRPCSpec, IRPCSpecHook, IRPCSpecStore, IRPCStatus, IRPCStore, IRPCStoreEvent, IRPCStoreSubscriber, IRPCStream, IRPCStreamInit, IRPCStub, IRPCStubStore, IRPCTransport, IRPC_BASE_CONTEXT, IRPC_ERROR_TYPE, IRPC_FILE_IDENTIFIER, IRPC_FILE_STATUS, IRPC_PACKET_TYPE, IRPC_STATUS, IRPC_STORE, IRPC_STORE_EVENT, PacketStream, RESOLVE_ERROR, RemoteState, ResolveError, STUB_ERROR, StreamCleanup, StreamConstructor, StubError, TRANSPORT_ERROR, TransportConfig, TransportError, createContext, createContextStore, createCredentials, createPackage, credential, decode, encode, getAbortController, getAbortSignal, getContext, getCredentials, intercept, isFilePointer, plan, setContext, setContextProvider, stream, withContext };
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
+ import { CALL_ERROR, CRUD_ERROR, CallError, CrudError, HANDLER_ERROR, HOOK_ERROR, HandlerError, HookError, IRPCError, IRPC_ERROR_TYPE, RESOLVE_ERROR, ResolveError, STUB_ERROR, StubError, TRANSPORT_ERROR, TransportError } from "./error.js";
2
+ import { IRPCAdapter } from "./adapter.js";
1
3
  import { IRPCCacher } from "./cache.js";
2
4
  import { IRPC_BASE_CONTEXT, IRPC_FILE_STATUS, IRPC_PACKET_TYPE, IRPC_STATUS, IRPC_STORE_EVENT } from "./enum.js";
3
- import { CALL_ERROR, CallError, HANDLER_ERROR, HOOK_ERROR, HandlerError, HookError, IRPCError, IRPC_ERROR_TYPE, RESOLVE_ERROR, ResolveError, STUB_ERROR, StubError, TRANSPORT_ERROR, TransportError } from "./error.js";
4
5
  import { createContext, createContextStore, getAbortController, getAbortSignal, getContext, setContext, setContextProvider, withContext } from "./context.js";
5
6
  import { RemoteState, stream } from "./state.js";
6
7
  import { IRPCReader } from "./reader.js";
@@ -14,6 +15,7 @@ import { createCredentials, credential, getCredentials } from "./credential.js";
14
15
  import { IRPCFile, IRPCFileStream } from "./file.js";
15
16
  import { IRPC_FILE_IDENTIFIER, decode, encode, isFilePointer } from "./packet.js";
16
17
  import { IRPCResolver } from "./resolver.js";
18
+ import { IRPCDriver } from "./types.js";
17
19
  import { plan } from "@anchorlib/core";
18
20
 
19
- export { CALL_ERROR, CallError, DEFAULT_RETRY_DELAY, DEFAULT_RETRY_MODE, HANDLER_ERROR, HOOK_ERROR, HandlerError, HookError, IRPCCacher, IRPCCall, IRPCError, IRPCFile, IRPCFileStream, IRPCPackage, IRPCReader, IRPCResolver, IRPCRouter, IRPCStore, IRPCStream, IRPCTransport, IRPC_BASE_CONTEXT, IRPC_ERROR_TYPE, IRPC_FILE_IDENTIFIER, IRPC_FILE_STATUS, IRPC_PACKET_TYPE, IRPC_STATUS, IRPC_STORE, IRPC_STORE_EVENT, RESOLVE_ERROR, RemoteState, ResolveError, STUB_ERROR, StubError, TRANSPORT_ERROR, TransportError, createContext, createContextStore, createCredentials, createPackage, credential, decode, encode, getAbortController, getAbortSignal, getContext, getCredentials, intercept, isFilePointer, plan, setContext, setContextProvider, stream, withContext };
21
+ export { CALL_ERROR, CRUD_ERROR, CallError, CrudError, DEFAULT_RETRY_DELAY, DEFAULT_RETRY_MODE, HANDLER_ERROR, HOOK_ERROR, HandlerError, HookError, IRPCAdapter, IRPCCacher, IRPCCall, IRPCDriver, IRPCError, IRPCFile, IRPCFileStream, IRPCPackage, IRPCReader, IRPCResolver, IRPCRouter, IRPCStore, IRPCStream, IRPCTransport, IRPC_BASE_CONTEXT, IRPC_ERROR_TYPE, IRPC_FILE_IDENTIFIER, IRPC_FILE_STATUS, IRPC_PACKET_TYPE, IRPC_STATUS, IRPC_STORE, IRPC_STORE_EVENT, RESOLVE_ERROR, RemoteState, ResolveError, STUB_ERROR, StubError, TRANSPORT_ERROR, TransportError, createContext, createContextStore, createCredentials, createPackage, credential, decode, encode, getAbortController, getAbortSignal, getContext, getCredentials, intercept, isFilePointer, plan, setContext, setContextProvider, stream, withContext };
package/dist/module.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { IRPCTransport } from "./transport.js";
2
- import { IRPCData, IRPCDeclareInit, IRPCFunction, IRPCHandler, IRPCInputs, IRPCOutput, IRPCPackageConfig, IRPCPackageInfo, IRPCRequest, IRPCSpec, IRPCStub } from "./types.js";
2
+ import { IRPCCrudMethod, IRPCCrudOptions, IRPCCrudStubs, IRPCData, IRPCDeclareConfig, IRPCDeclareInit, IRPCFunction, IRPCHandler, IRPCInferInit, IRPCInputs, IRPCObject, IRPCOutput, IRPCPackageConfig, IRPCPackageInfo, IRPCRequest, IRPCReturnOf, IRPCSpec, IRPCStub } from "./types.js";
3
3
  import { RemoteState } from "./state.js";
4
4
  import { IRPCReader } from "./reader.js";
5
5
 
@@ -17,7 +17,7 @@ type IRPCSpecHook<F$1> = (req: IRPCHookArgs<F$1>) => void | Promise<void>;
17
17
  * and their corresponding stubs. It manages the configuration, transport, and execution
18
18
  * of remote procedure calls.
19
19
  */
20
- declare class IRPCPackage {
20
+ declare class IRPCPackage<K extends string = 'id'> {
21
21
  /**
22
22
  * A map storing all IRPC specifications by their names
23
23
  */
@@ -54,12 +54,47 @@ declare class IRPCPackage {
54
54
  */
55
55
  constructor(config?: Partial<IRPCPackageConfig>);
56
56
  /**
57
- * Declares a new IRPC specification and creates a corresponding stub function
58
- * @param options - The initialization object containing the IRPC specification
59
- * @returns A stub function that can be used to call the IRPC
60
- * @throws Error if an IRPC with the same name already exists
57
+ * Declares a new IRPC specification and returns a callable stub.
58
+ *
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).
62
+ * @returns A stub function that can be used to call the IRPC.
63
+ * @throws Error if an IRPC with the same name already exists.
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>;
75
+ /**
76
+ * Declares a new IRPC specification and returns a callable stub.
77
+ *
78
+ * @param options - The initialization object containing name, seed, and configuration.
79
+ * @returns A stub function that can be used to call the IRPC.
80
+ * @throws Error if an IRPC with the same name already exists.
61
81
  */
62
82
  declare<F, I extends IRPCInputs = IRPCInputs, O extends IRPCOutput = IRPCOutput>(options: IRPCDeclareInit<F, I, O>): IRPCFunction<F>;
83
+ /**
84
+ * Declares CRUD stubs (get, create, update, delete) for an entity
85
+ * @param name - The entity name used as prefix for stub names
86
+ * @param seed - Factory function returning a default entity instance
87
+ * @param options - Optional configuration for caching, schemas, and call behavior
88
+ * @returns An object containing the four CRUD stub functions
89
+ */
90
+ crud<T extends IRPCObject, I extends IRPCObject = T, U extends IRPCObject = T, CK extends string = K>(name: string, seed: () => T, options?: IRPCCrudOptions): IRPCCrudStubs<T, CK, I, U>;
91
+ /**
92
+ * Removes CRUD methods from a stubs object and unregisters their specs
93
+ * @param stubs - The CRUD stubs object to modify
94
+ * @param keys - The method names to remove
95
+ * @returns The stubs object without the excluded methods
96
+ */
97
+ exclude<S extends object, E extends IRPCCrudMethod>(stubs: S, keys: E[]): Omit<S, E>;
63
98
  /**
64
99
  * Resolves and executes an IRPC call based on a request object
65
100
  * @param req - The request containing the IRPC name and arguments
@@ -76,13 +111,17 @@ declare class IRPCPackage {
76
111
  */
77
112
  construct<F, A extends unknown[], R extends IRPCData>(stub: IRPCStub<F, A, R>, handler: F): this;
78
113
  /**
79
- * Registers a hook function for a specific stub function
80
- * @param stub - The stub function created by declare()
81
- * @param handler - The hook function to register
82
- * @returns This IRPCPackage instance for chaining
83
- * @throws Error if the stub is invalid or if no IRPC exists for the stub
114
+ * Registers a hook for a specific stub.
115
+ * @param stub - The stub function created by declare().
116
+ * @param handler - The hook function to register.
84
117
  */
85
118
  hook<F extends IRPCHandler>(stub: F, handler: IRPCSpecHook<F>): this;
119
+ /**
120
+ * Registers a hook for all stubs in a group (e.g., CRUD).
121
+ * @param stubs - An object whose values are stub functions.
122
+ * @param handler - The hook function to register.
123
+ */
124
+ hook(stubs: Record<string, IRPCHandler>, handler: IRPCSpecHook<IRPCHandler>): this;
86
125
  /**
87
126
  * Resolves and executes all registered hooks for a given request
88
127
  * @param req - The request containing the IRPC name and arguments
@@ -122,7 +161,9 @@ declare class IRPCPackage {
122
161
  * @param config - Optional partial configuration for the package
123
162
  * @returns A new IRPCPackage instance
124
163
  */
125
- declare function createPackage(config?: Partial<IRPCPackageConfig>): IRPCPackage;
164
+ declare function createPackage<K extends string = 'id'>(config?: Partial<IRPCPackageConfig> & {
165
+ key?: K;
166
+ }): IRPCPackage<K>;
126
167
  /**
127
168
  * Intercepts local function call to get an instant response without remote execution.
128
169
  *
package/dist/module.js CHANGED
@@ -1,6 +1,6 @@
1
+ import { HandlerError, ResolveError, StubError, TransportError } from "./error.js";
1
2
  import { IRPCCacher } from "./cache.js";
2
3
  import { IRPC_STATUS } from "./enum.js";
3
- import { HandlerError, ResolveError, StubError, TransportError } from "./error.js";
4
4
  import { getAbortSignal } from "./context.js";
5
5
  import { RemoteState } from "./state.js";
6
6
  import { IRPCReader } from "./reader.js";
@@ -37,6 +37,7 @@ var IRPCPackage = class {
37
37
  config = {
38
38
  name: "global",
39
39
  version: "1.0.0",
40
+ key: "id",
40
41
  timeout: DEFAULT_TIMEOUT
41
42
  };
42
43
  /**
@@ -71,13 +72,18 @@ var IRPCPackage = class {
71
72
  this.configure(config ?? {});
72
73
  IRPC_STORE.register(this);
73
74
  }
74
- /**
75
- * Declares a new IRPC specification and creates a corresponding stub function
76
- * @param options - The initialization object containing the IRPC specification
77
- * @returns A stub function that can be used to call the IRPC
78
- * @throws Error if an IRPC with the same name already exists
79
- */
80
- declare(options) {
75
+ declare(nameOrOptions, seedOrConfig, config) {
76
+ let options;
77
+ if (typeof nameOrOptions === "string") if (typeof seedOrConfig === "function") options = {
78
+ name: nameOrOptions,
79
+ seed: seedOrConfig,
80
+ ...config
81
+ };
82
+ else options = {
83
+ name: nameOrOptions,
84
+ ...seedOrConfig
85
+ };
86
+ else options = nameOrOptions;
81
87
  const $options = options;
82
88
  if (this.specs.has($options.name)) throw StubError.duplicate($options.name);
83
89
  if ($options.init && !$options.seed) $options.seed = $options.init;
@@ -160,7 +166,7 @@ var IRPCPackage = class {
160
166
  ...this.config,
161
167
  ...spec
162
168
  };
163
- const config = {
169
+ const config$1 = {
164
170
  timeout,
165
171
  maxRetries,
166
172
  retryDelay,
@@ -171,7 +177,7 @@ var IRPCPackage = class {
171
177
  name: spec.name,
172
178
  args
173
179
  }));
174
- const call = typeof spec.handler === "function" ? intercept(spec, args, reader) : this.transport.call(spec, args, config, reader);
180
+ const call = typeof spec.handler === "function" ? intercept(spec, args, reader) : this.transport.call(spec, args, config$1, reader);
175
181
  calls.set(callKey, call);
176
182
  if (spec.maxAge) caches.set(callKey, call, spec.maxAge);
177
183
  onCleanup(() => call.close());
@@ -185,6 +191,50 @@ var IRPCPackage = class {
185
191
  return stub;
186
192
  }
187
193
  /**
194
+ * Declares CRUD stubs (get, create, update, delete) for an entity
195
+ * @param name - The entity name used as prefix for stub names
196
+ * @param seed - Factory function returning a default entity instance
197
+ * @param options - Optional configuration for caching, schemas, and call behavior
198
+ * @returns An object containing the four CRUD stub functions
199
+ */
200
+ crud(name, seed, options) {
201
+ const { description, schema, maxAge, coalesce,...callConfig } = options ?? {};
202
+ const desc = (method) => typeof description === "string" ? description : description?.[method];
203
+ const init = (method) => ({
204
+ ...callConfig,
205
+ name: `${name}.${method}`,
206
+ seed,
207
+ description: desc(method),
208
+ schema: schema?.[method],
209
+ ...method === "get" ? { maxAge } : {},
210
+ coalesce
211
+ });
212
+ return {
213
+ get: this.declare(init("get")),
214
+ create: this.declare(init("create")),
215
+ update: this.declare(init("update")),
216
+ delete: this.declare(init("delete"))
217
+ };
218
+ }
219
+ /**
220
+ * Removes CRUD methods from a stubs object and unregisters their specs
221
+ * @param stubs - The CRUD stubs object to modify
222
+ * @param keys - The method names to remove
223
+ * @returns The stubs object without the excluded methods
224
+ */
225
+ exclude(stubs, keys) {
226
+ for (const key of keys) {
227
+ const stub = stubs[key];
228
+ if (stub) {
229
+ const spec = this.stubs.get(stub);
230
+ if (spec) this.specs.delete(spec.name);
231
+ this.stubs.delete(stub);
232
+ }
233
+ delete stubs[key];
234
+ }
235
+ return stubs;
236
+ }
237
+ /**
188
238
  * Resolves and executes an IRPC call based on a request object
189
239
  * @param req - The request containing the IRPC name and arguments
190
240
  * @returns The result of the IRPC execution
@@ -211,21 +261,21 @@ var IRPCPackage = class {
211
261
  spec.handler = handler;
212
262
  return this;
213
263
  }
214
- /**
215
- * Registers a hook function for a specific stub function
216
- * @param stub - The stub function created by declare()
217
- * @param handler - The hook function to register
218
- * @returns This IRPCPackage instance for chaining
219
- * @throws Error if the stub is invalid or if no IRPC exists for the stub
220
- */
221
- hook(stub, handler) {
222
- if (!this.stubs.has(stub)) {
223
- const error = StubError.notFound();
224
- IRPC_STORE.error(error);
264
+ hook(stubOrGroup, handler) {
265
+ if (typeof stubOrGroup === "function") {
266
+ if (!this.stubs.has(stubOrGroup)) {
267
+ const error = StubError.notFound();
268
+ IRPC_STORE.error(error);
269
+ return this;
270
+ }
271
+ const spec = this.stubs.get(stubOrGroup);
272
+ this.hooks.get(spec).add(handler);
225
273
  return this;
226
274
  }
227
- const spec = this.stubs.get(stub);
228
- this.hooks.get(spec).add(handler);
275
+ for (const stub of Object.values(stubOrGroup)) if (typeof stub === "function" && this.stubs.has(stub)) {
276
+ const spec = this.stubs.get(stub);
277
+ this.hooks.get(spec).add(handler);
278
+ }
229
279
  return this;
230
280
  }
231
281
  /**
package/dist/reader.js CHANGED
@@ -1,5 +1,5 @@
1
- import { IRPC_PACKET_TYPE, IRPC_STATUS } from "./enum.js";
2
1
  import { IRPCError } from "./error.js";
2
+ import { IRPC_PACKET_TYPE, IRPC_STATUS } from "./enum.js";
3
3
  import { RemoteState } from "./state.js";
4
4
  import { replay } from "@anchorlib/core";
5
5
 
@@ -1,5 +1,5 @@
1
- import { IRPCPackage } from "./module.js";
2
1
  import { IRPCDataSchema, IRPCInputs, IRPCOutput, IRPCRequest, IRPCResponse, IRPCSpec } from "./types.js";
2
+ import { IRPCPackage } from "./module.js";
3
3
 
4
4
  //#region src/resolver.d.ts
5
5
 
package/dist/router.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { IRPCPackage } from "./module.js";
2
1
  import { IRPCTransport } from "./transport.js";
3
2
  import { IRPCPacketError, IRPCRequest } from "./types.js";
3
+ import { IRPCPackage } from "./module.js";
4
4
 
5
5
  //#region src/router.d.ts
6
6
  type IRPCHook = () => void | Promise<void>;
package/dist/router.js CHANGED
@@ -1,5 +1,5 @@
1
- import { IRPC_BASE_CONTEXT, IRPC_PACKET_TYPE, IRPC_STATUS } from "./enum.js";
2
1
  import { HookError } from "./error.js";
2
+ import { IRPC_BASE_CONTEXT, IRPC_PACKET_TYPE, IRPC_STATUS } from "./enum.js";
3
3
  import { createContextStore, withContext } from "./context.js";
4
4
  import { IRPC_STORE } from "./store.js";
5
5
 
package/dist/state.js CHANGED
@@ -1,5 +1,5 @@
1
- import { IRPC_STATUS } from "./enum.js";
2
1
  import { IRPCError, IRPC_ERROR_TYPE } from "./error.js";
2
+ import { IRPC_STATUS } from "./enum.js";
3
3
  import { getAbortSignal } from "./context.js";
4
4
  import { $do, anchor, mutable, onCleanup, replay, subscribe } from "@anchorlib/core";
5
5
 
package/dist/store.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { IRPC_STORE_EVENT } from "./enum.js";
2
- import { IRPCPackage } from "./module.js";
3
2
  import { IRPCData } from "./types.js";
3
+ import { IRPCPackage } from "./module.js";
4
4
  import { IRPCRouter } from "./router.js";
5
5
  import { IRPCStream } from "./stream.js";
6
6
 
@@ -27,7 +27,7 @@ declare class IRPCStore {
27
27
  #private;
28
28
  calls: Set<IRPCStream<IRPCData>>;
29
29
  routers: Set<IRPCRouter>;
30
- packages: Set<IRPCPackage>;
30
+ packages: Set<IRPCPackage<"id">>;
31
31
  callCount: number;
32
32
  errorCount: number;
33
33
  register(pkg: IRPCPackage): void;
package/dist/stream.js CHANGED
@@ -1,5 +1,5 @@
1
- import { IRPC_PACKET_TYPE, IRPC_STATUS } from "./enum.js";
2
1
  import { CallError, HandlerError, ResolveError } from "./error.js";
2
+ import { IRPC_PACKET_TYPE, IRPC_STATUS } from "./enum.js";
3
3
  import { getAbortController, getAbortSignal } from "./context.js";
4
4
  import { RemoteState } from "./state.js";
5
5
  import { IRPC_STORE } from "./store.js";
@@ -1,7 +1,7 @@
1
- import { IRPCPackage } from "./module.js";
1
+ import { IRPCCall } from "./call.js";
2
2
  import { IRPCCallConfig, IRPCCredentials, IRPCCredentialsFactory, IRPCData, IRPCInputs, IRPCOutput, IRPCSpec, TransportConfig } from "./types.js";
3
3
  import { IRPCReader } from "./reader.js";
4
- import { IRPCCall } from "./call.js";
4
+ import { IRPCPackage } from "./module.js";
5
5
 
6
6
  //#region src/transport.d.ts
7
7
 
@@ -12,7 +12,7 @@ import { IRPCCall } from "./call.js";
12
12
  declare class IRPCTransport {
13
13
  #private;
14
14
  config?: TransportConfig | undefined;
15
- modules: Set<IRPCPackage>;
15
+ modules: Set<IRPCPackage<"id">>;
16
16
  /**
17
17
  * A set of pending RPC calls that are queued for execution.
18
18
  */
package/dist/transport.js CHANGED
@@ -1,5 +1,5 @@
1
- import { IRPC_PACKET_TYPE, IRPC_STATUS } from "./enum.js";
2
1
  import { TransportError } from "./error.js";
2
+ import { IRPC_PACKET_TYPE, IRPC_STATUS } from "./enum.js";
3
3
  import { IRPCReader } from "./reader.js";
4
4
  import { IRPC_STORE } from "./store.js";
5
5
  import { IRPCCall } from "./call.js";
package/dist/types.d.ts CHANGED
@@ -160,6 +160,8 @@ type IRPCPackageInfo = {
160
160
  description?: string;
161
161
  };
162
162
  type IRPCPackageConfig = IRPCPackageInfo & IRPCCallConfig & {
163
+ /** Primary key field name for CRUD operations. Defaults to 'id'. */
164
+ key?: string;
163
165
  transport?: IRPCTransport;
164
166
  };
165
167
  /**
@@ -214,6 +216,28 @@ type IRPCInferInit<R$1> = R$1 extends IRPCDefined ? {
214
216
  } : {
215
217
  seed?: () => R$1;
216
218
  };
219
+ /**
220
+ * Extracts the data type from a function's return type by unwrapping
221
+ * RemoteState and Promise wrappers.
222
+ *
223
+ * @template F - The function type to extract from.
224
+ */
225
+ type IRPCReturnOf<F> = F extends ((...args: infer _A) => infer R) ? R extends RemoteState<infer S> ? S : R extends Promise<infer D> ? D : R : IRPCData;
226
+ /**
227
+ * Configuration options for the shorthand `declare(name, seed, config?)` overload.
228
+ * Contains all IRPCInit fields except `name` and `seed`.
229
+ *
230
+ * @template I - Tuple of input validation schemas
231
+ * @template O - Output validation schema
232
+ */
233
+ type IRPCDeclareConfig<I extends IRPCInputs = IRPCInputs, O$1 extends IRPCOutput = IRPCOutput> = {
234
+ description?: string;
235
+ schema?: IRPCSchema<I, O$1>;
236
+ maxAge?: number;
237
+ coalesce?: boolean;
238
+ stream?: true;
239
+ ttl?: number;
240
+ } & IRPCCallConfig;
217
241
  /**
218
242
  * Configuration options for initializing an RPC stream function.
219
243
  * Contains metadata and constraints for the RPC stream function.
@@ -234,6 +258,64 @@ type IRPCStreamInit<I extends IRPCInputs, O$1 extends IRPCOutput, R$1> = IRPCIni
234
258
  * @template O - Output validation schema
235
259
  */
236
260
  type IRPCDeclareInit<F, I extends IRPCInputs, O$1 extends IRPCOutput> = F extends ((...args: infer _A) => infer R) ? R extends RemoteState<infer S> ? S extends IRPCData ? IRPCStreamInit<I, O$1, S> : IRPCInit<S, IRPCInputs, IRPCOutput> : R extends Promise<infer D> ? D extends IRPCData ? IRPCInit<D, I, O$1> : IRPCInit<D, IRPCInputs, IRPCOutput> : R extends IRPCData ? IRPCInit<R, I, O$1> : IRPCInit<R, IRPCInputs, IRPCOutput> : IRPCInit<IRPCData, IRPCInputs, IRPCOutput>;
261
+ type IRPCCrudMethod = 'get' | 'create' | 'update' | 'delete';
262
+ /**
263
+ * Discriminated field — shared value or per-operation values.
264
+ */
265
+ type IRPCCrudField<T> = T | {
266
+ get?: T;
267
+ create?: T;
268
+ update?: T;
269
+ delete?: T;
270
+ };
271
+ type IRPCCrudOptions = {
272
+ description?: IRPCCrudField<string>;
273
+ schema?: {
274
+ get?: IRPCSchema<IRPCInputs, IRPCOutput>;
275
+ create?: IRPCSchema<IRPCInputs, IRPCOutput>;
276
+ update?: IRPCSchema<IRPCInputs, IRPCOutput>;
277
+ delete?: IRPCSchema<IRPCInputs, IRPCOutput>;
278
+ };
279
+ /** Cache max age — only applied to get. */
280
+ maxAge?: number;
281
+ coalesce?: boolean;
282
+ } & IRPCCallConfig;
283
+ /**
284
+ * ID type extracted from entity using the key field.
285
+ * Falls back to string if the key doesn't exist on the entity.
286
+ */
287
+ type IRPCEntityId<T, K$1 extends string> = K$1 extends keyof T ? T[K$1] : string;
288
+ type IRPCCrudStubs<T extends IRPCObject, K$1 extends string, I extends IRPCObject = T, U extends IRPCObject = T> = {
289
+ get: IRPCFunction<(id: IRPCEntityId<T, K$1>) => Promise<T> | RemoteState<T>>;
290
+ create: IRPCFunction<(data: I) => Promise<T> | RemoteState<T>>;
291
+ update: IRPCFunction<(id: IRPCEntityId<T, K$1>, data: U) => Promise<T> | RemoteState<T>>;
292
+ delete: IRPCFunction<(id: IRPCEntityId<T, K$1>) => Promise<T> | RemoteState<T>>;
293
+ };
294
+ /**
295
+ * Per-method resolved metadata — discriminated fields flattened,
296
+ * method-specific options applied. Passed to driver on every call.
297
+ */
298
+ type IRPCCrudMeta = {
299
+ /** Entity/table name. */
300
+ name: string;
301
+ /** Primary key field name. */
302
+ key: string;
303
+ /** Resolved description for this method. */
304
+ description?: string;
305
+ /** Resolved schema for this method. */
306
+ schema?: IRPCSchema<IRPCInputs, IRPCOutput>;
307
+ maxAge?: number;
308
+ coalesce?: boolean;
309
+ } & IRPCCallConfig;
310
+ /**
311
+ * Base class for CRUD drivers that receive per-method resolved metadata on every call
312
+ */
313
+ declare abstract class IRPCDriver {
314
+ get?(meta: IRPCCrudMeta, id: IRPCData): Promise<IRPCData> | IRPCData;
315
+ create?(meta: IRPCCrudMeta, data: IRPCData): Promise<IRPCData> | IRPCData;
316
+ update?(meta: IRPCCrudMeta, id: IRPCData, data: IRPCData): Promise<IRPCData> | IRPCData;
317
+ delete?(meta: IRPCCrudMeta, id: IRPCData): Promise<IRPCData> | IRPCData;
318
+ }
237
319
  /**
238
320
  * Complete specification for an RPC function including its implementation.
239
321
  * Extends IRPCInit with the actual handler function.
@@ -335,4 +417,4 @@ type StreamCleanup = () => void;
335
417
  */
336
418
  type StreamConstructor<T> = (state: IRPCReadable<T>, resolve: (value?: T) => void, reject: (error: Error) => void) => StreamCleanup | void | Promise<StreamCleanup | void>;
337
419
  //#endregion
338
- export { IRPCArraySchema, IRPCCallConfig, IRPCContext, IRPCContextProvider, IRPCCredentials, IRPCCredentialsFactory, IRPCData, IRPCDataSchema, IRPCDeclareInit, IRPCDefined, IRPCFunction, IRPCHandler, IRPCInferInit, IRPCInit, IRPCInputs, IRPCObject, IRPCObjectSchema, IRPCOutput, IRPCPackageConfig, IRPCPackageInfo, IRPCPacketAnswer, IRPCPacketBase, IRPCPacketCall, IRPCPacketClose, IRPCPacketError, IRPCPacketEvent, IRPCPacketStream, IRPCPacketType, IRPCParseResult, IRPCPayload, IRPCPrimitive, IRPCPrimitiveSchema, IRPCReadable, IRPCRequest, IRPCRequests, IRPCResponse, IRPCSchema, IRPCSpec, IRPCSpecStore, IRPCStatus, IRPCStreamInit, IRPCStub, IRPCStubStore, StreamCleanup, StreamConstructor, TransportConfig };
420
+ export { IRPCArraySchema, IRPCCallConfig, IRPCContext, IRPCContextProvider, IRPCCredentials, IRPCCredentialsFactory, IRPCCrudField, IRPCCrudMeta, IRPCCrudMethod, IRPCCrudOptions, IRPCCrudStubs, IRPCData, IRPCDataSchema, IRPCDeclareConfig, IRPCDeclareInit, IRPCDefined, IRPCDriver, IRPCEntityId, IRPCFunction, IRPCHandler, IRPCInferInit, IRPCInit, IRPCInputs, IRPCObject, IRPCObjectSchema, IRPCOutput, IRPCPackageConfig, IRPCPackageInfo, IRPCPacketAnswer, IRPCPacketBase, IRPCPacketCall, IRPCPacketClose, IRPCPacketError, IRPCPacketEvent, IRPCPacketStream, IRPCPacketType, IRPCParseResult, IRPCPayload, IRPCPrimitive, IRPCPrimitiveSchema, IRPCReadable, IRPCRequest, IRPCRequests, IRPCResponse, IRPCReturnOf, IRPCSchema, IRPCSpec, IRPCSpecStore, IRPCStatus, IRPCStreamInit, IRPCStub, IRPCStubStore, StreamCleanup, StreamConstructor, TransportConfig };
package/dist/types.js CHANGED
@@ -1 +1,8 @@
1
- export { };
1
+ //#region src/types.ts
2
+ /**
3
+ * Base class for CRUD drivers that receive per-method resolved metadata on every call
4
+ */
5
+ var IRPCDriver = class {};
6
+
7
+ //#endregion
8
+ export { IRPCDriver };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@irpclib/irpc",
4
- "version": "1.0.0-beta.25",
4
+ "version": "1.0.0",
5
5
  "types": "./dist/index.d.ts",
6
6
  "module": "./dist/index.js",
7
7
  "exports": {
@@ -52,6 +52,6 @@
52
52
  },
53
53
  "license": "MIT",
54
54
  "dependencies": {
55
- "@anchorlib/core": "^1.0.0-beta.25"
55
+ "@anchorlib/core": "^1.0.0"
56
56
  }
57
57
  }