@eidos.space/client 0.1.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.
- package/LICENSE +21 -0
- package/README.md +121 -0
- package/dist/index.d.ts +75 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +145 -0
- package/dist/index.js.map +1 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 mayneyao
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# @eidos.space/client
|
|
2
|
+
|
|
3
|
+
Eidos RPC client for Node.js and browser environments. Connect to a headless Eidos server via HTTP and interact with your data using a Prisma-style API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @eidos.space/client @eidos.space/core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Basic Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { createEidosClient } from "@eidos.space/client"
|
|
15
|
+
|
|
16
|
+
const client = createEidosClient({
|
|
17
|
+
endpoint: "http://localhost:3000/rpc",
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
// Query table data
|
|
21
|
+
const posts = await client.currentSpace.table("posts").findMany({
|
|
22
|
+
where: { published: true },
|
|
23
|
+
take: 10,
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
// Get graft sync status
|
|
27
|
+
const status = await client.currentSpace.graft.status()
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Integration with React
|
|
31
|
+
|
|
32
|
+
To use the client in a React application, we recommend using `@eidos.space/react` which provides hooks and state management for the Eidos SDK.
|
|
33
|
+
|
|
34
|
+
### 1. Installation
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm install @eidos.space/client @eidos.space/react
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### 2. Setup
|
|
41
|
+
|
|
42
|
+
Initialize the client and set it to the Eidos store. You can do this at the root of your application.
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
import { useEffect } from "react"
|
|
46
|
+
import { createEidosClient } from "@eidos.space/client"
|
|
47
|
+
import { createEidos, useEidosStore } from "@eidos.space/react"
|
|
48
|
+
|
|
49
|
+
function App() {
|
|
50
|
+
const { setEidos } = useEidosStore()
|
|
51
|
+
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
// 1. Create the RPC client
|
|
54
|
+
const client = createEidosClient({
|
|
55
|
+
endpoint: "http://localhost:3000/rpc",
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
// 2. Wrap it with Eidos SDK interface
|
|
59
|
+
// createEidos adds helper methods like AI and utils
|
|
60
|
+
const eidos = createEidos(client.currentSpace)
|
|
61
|
+
|
|
62
|
+
// 3. Set to global store
|
|
63
|
+
setEidos(eidos)
|
|
64
|
+
}, [setEidos])
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<div className="App">
|
|
68
|
+
<BlogPostList />
|
|
69
|
+
</div>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 3. Usage in Components
|
|
75
|
+
|
|
76
|
+
Now you can use the `useEidos` hook in any component to access your data.
|
|
77
|
+
|
|
78
|
+
```tsx
|
|
79
|
+
import { useEidos } from "@eidos.space/react"
|
|
80
|
+
import { useQuery } from "@tanstack/react-query"
|
|
81
|
+
|
|
82
|
+
export function BlogPostList() {
|
|
83
|
+
const eidos = useEidos()
|
|
84
|
+
|
|
85
|
+
// Example with TanStack Query
|
|
86
|
+
const { data: posts, isLoading } = useQuery({
|
|
87
|
+
queryKey: ["posts"],
|
|
88
|
+
queryFn: () =>
|
|
89
|
+
eidos.currentSpace.table("posts").findMany({
|
|
90
|
+
orderBy: { created_at: "desc" },
|
|
91
|
+
}),
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
if (isLoading) return <div>Loading...</div>
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<ul>
|
|
98
|
+
{posts?.map((post) => (
|
|
99
|
+
<li key={post._id}>{post.name}</li>
|
|
100
|
+
))}
|
|
101
|
+
</ul>
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Configuration
|
|
107
|
+
|
|
108
|
+
The `createEidosClient` function accepts a configuration object:
|
|
109
|
+
|
|
110
|
+
| Option | Type | Description |
|
|
111
|
+
| ---------- | -------------- | -------------------------------------------------------- |
|
|
112
|
+
| `endpoint` | `string` | The RPC endpoint URL (e.g., `http://localhost:3000/rpc`) |
|
|
113
|
+
| `timeout` | `number` | Request timeout in milliseconds (default: 30000) |
|
|
114
|
+
| `fetch` | `typeof fetch` | Custom fetch implementation (optional) |
|
|
115
|
+
|
|
116
|
+
## Features
|
|
117
|
+
|
|
118
|
+
- **Prisma-style API**: Type-safe (when used with generated types) and intuitive CRUD operations.
|
|
119
|
+
- **Isomorphic**: Works in Node.js, browsers, and Edge functions.
|
|
120
|
+
- **Minimal Footprint**: Lightweight proxy-based implementation.
|
|
121
|
+
- **Deep Integration**: First-class support for Eidos features like Graft sync, Files, and KV storage.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { DataSpace, DataSpace as DataSpace$1 } from "@eidos.space/core";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Eidos client interface
|
|
7
|
+
*/
|
|
8
|
+
interface EidosClient {
|
|
9
|
+
/**
|
|
10
|
+
* The current data space
|
|
11
|
+
*/
|
|
12
|
+
currentSpace: DataSpace$1;
|
|
13
|
+
/**
|
|
14
|
+
* Alias for currentSpace
|
|
15
|
+
*/
|
|
16
|
+
space: DataSpace$1;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Client configuration
|
|
20
|
+
*/
|
|
21
|
+
interface EidosClientConfig {
|
|
22
|
+
/** RPC endpoint URL */
|
|
23
|
+
endpoint: string;
|
|
24
|
+
/** Request timeout in milliseconds (default: 30000) */
|
|
25
|
+
timeout?: number;
|
|
26
|
+
/** Custom fetch function */
|
|
27
|
+
fetch?: typeof fetch;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=types.d.ts.map
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/transport.d.ts
|
|
32
|
+
/**
|
|
33
|
+
* HTTP Transport for Eidos RPC client
|
|
34
|
+
* Extracted and adapted from packages/sandbox/src/sdk-inject-script.html
|
|
35
|
+
*/
|
|
36
|
+
interface TransportConfig {
|
|
37
|
+
endpoint: string;
|
|
38
|
+
timeout?: number;
|
|
39
|
+
fetch?: typeof fetch;
|
|
40
|
+
}
|
|
41
|
+
interface TransportPort {
|
|
42
|
+
onmessage: ((event: {
|
|
43
|
+
data: any;
|
|
44
|
+
}) => void) | null;
|
|
45
|
+
close: () => void;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Create HTTP transport for RPC calls
|
|
49
|
+
*/
|
|
50
|
+
declare function createHttpTransport(config: TransportConfig): {
|
|
51
|
+
send: (requestData: any) => Promise<TransportPort>;
|
|
52
|
+
close: () => void;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Wait for callback from transport port
|
|
56
|
+
*/
|
|
57
|
+
declare function onCallBack(port: TransportPort): Promise<any>;
|
|
58
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/space-proxy.d.ts
|
|
61
|
+
/**
|
|
62
|
+
* Create space proxy with Prisma-style API
|
|
63
|
+
*/
|
|
64
|
+
declare function createSpaceProxy(config: TransportConfig): {};
|
|
65
|
+
//# sourceMappingURL=space-proxy.d.ts.map
|
|
66
|
+
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/index.d.ts
|
|
69
|
+
/**
|
|
70
|
+
* Create an Eidos client for connecting to headless server
|
|
71
|
+
*/
|
|
72
|
+
declare function createEidosClient(config: EidosClientConfig): EidosClient;
|
|
73
|
+
//#endregion
|
|
74
|
+
export { DataSpace, EidosClient, EidosClientConfig, TransportConfig, TransportPort, createEidosClient, createHttpTransport, createSpaceProxy, onCallBack };
|
|
75
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/transport.ts","../src/space-proxy.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;AAKA;AAA4B,UAAX,WAAA,CAAW;EAAA;;AAQV;EAMD,YAAA,EAVD,WAUkB;;;;ECdjB,KAAA,EDQR,WCRQ;AAMjB;AAQA;;;AAK4C,UDL3B,iBAAA,CCK2B;EAAa;EAAd,QAAA,EAAA,MAAA;EAwD3B;EAAU,OAAA,CAAA,EAAA,MAAA;EAAA;EAAoB,KAAG,CAAA,EAAA,ODvDhC,KCuDgC;AAAO;;;;;;;AD3ExD;AAA4B,UCAX,eAAA,CDAW;EAAA,QAIZ,EAAA,MAAA;EAAS,OAIhB,CAAA,EAAA,MAAA;EAAS,KAAA,CAAA,EAAA,OCLD,KDKC;AAMlB;UCRiB,aAAA;;;EANA,CAAA,EAAA,GAAA,IAAA,CAAA,GAAA,IAAe;EAMf,KAAA,EAAA,GAAA,GAAA,IAAa;AAQ9B;;;;AAKoC,iBALpB,mBAAA,CAKoB,MAAA,EALQ,eAKR,CAAA,EAAA;EAAO,IAAA,EAAA,CAAA,WAAA,EAAA,GAAA,EAAA,GAAP,OAAO,CAAC,aAAD,CAAA;EAwD3B,KAAA,EAAA,GAAA,GAAU,IAAA;CAAA;;;AAA8B;iBAAxC,UAAA,OAAiB,gBAAgB;;;;;ADnE/B;AAMlB;iBERgB,gBAAA,SAAyB;;;;;;;;AAAzB,iBCqBA,iBAAA,CDrByB,MAAe,ECqBd,iBDrBc,CAAA,ECqBM,WDrBN"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
//#region src/transport.ts
|
|
2
|
+
/**
|
|
3
|
+
* Create HTTP transport for RPC calls
|
|
4
|
+
*/
|
|
5
|
+
function createHttpTransport(config) {
|
|
6
|
+
const { endpoint, timeout = 3e4 } = config;
|
|
7
|
+
const fetchFn = config.fetch || globalThis.fetch;
|
|
8
|
+
return {
|
|
9
|
+
send: async (requestData) => {
|
|
10
|
+
const controller = new AbortController();
|
|
11
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
12
|
+
try {
|
|
13
|
+
const response = await fetchFn(endpoint, {
|
|
14
|
+
method: "POST",
|
|
15
|
+
headers: { "Content-Type": "application/json" },
|
|
16
|
+
body: JSON.stringify(requestData),
|
|
17
|
+
signal: controller.signal
|
|
18
|
+
});
|
|
19
|
+
clearTimeout(timeoutId);
|
|
20
|
+
if (!response.ok) throw new Error(`HTTP error: ${response.status}`);
|
|
21
|
+
const jsonData = await response.json();
|
|
22
|
+
if (!jsonData.success) throw new Error(jsonData.error || "RPC call failed");
|
|
23
|
+
const responseData = jsonData.data;
|
|
24
|
+
const simulatedPort = {
|
|
25
|
+
onmessage: null,
|
|
26
|
+
close: () => {}
|
|
27
|
+
};
|
|
28
|
+
setTimeout(() => {
|
|
29
|
+
if (simulatedPort.onmessage) simulatedPort.onmessage({ data: {
|
|
30
|
+
type: "rpcCallResp",
|
|
31
|
+
data: responseData
|
|
32
|
+
} });
|
|
33
|
+
}, 0);
|
|
34
|
+
return simulatedPort;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
clearTimeout(timeoutId);
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
close: () => {}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Wait for callback from transport port
|
|
45
|
+
*/
|
|
46
|
+
function onCallBack(port) {
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
port.onmessage = (event) => {
|
|
49
|
+
port.close();
|
|
50
|
+
const { type, data } = event.data;
|
|
51
|
+
if (type === "rpcCallResp") resolve(data);
|
|
52
|
+
else reject(/* @__PURE__ */ new Error("RPC call failed"));
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/space-proxy.ts
|
|
59
|
+
/**
|
|
60
|
+
* Create space proxy with Prisma-style API
|
|
61
|
+
*/
|
|
62
|
+
function createSpaceProxy(config) {
|
|
63
|
+
const transport = createHttpTransport(config);
|
|
64
|
+
return new Proxy({}, { get: (target, method) => {
|
|
65
|
+
if (method === "table") return function(tableId) {
|
|
66
|
+
const tableMethods = [
|
|
67
|
+
"create",
|
|
68
|
+
"createMany",
|
|
69
|
+
"findUnique",
|
|
70
|
+
"findFirst",
|
|
71
|
+
"findMany",
|
|
72
|
+
"count",
|
|
73
|
+
"update",
|
|
74
|
+
"updateMany",
|
|
75
|
+
"delete",
|
|
76
|
+
"deleteMany"
|
|
77
|
+
];
|
|
78
|
+
return new Proxy({}, { get(target$1, tableMethod) {
|
|
79
|
+
if (tableMethods.includes(tableMethod)) return async function(args) {
|
|
80
|
+
const port = await transport.send({
|
|
81
|
+
method: `table(${tableId}).${tableMethod}`,
|
|
82
|
+
params: [args]
|
|
83
|
+
});
|
|
84
|
+
return onCallBack(port);
|
|
85
|
+
};
|
|
86
|
+
return void 0;
|
|
87
|
+
} });
|
|
88
|
+
};
|
|
89
|
+
const namespaces = [
|
|
90
|
+
"doc",
|
|
91
|
+
"action",
|
|
92
|
+
"graft",
|
|
93
|
+
"script",
|
|
94
|
+
"extension",
|
|
95
|
+
"tree",
|
|
96
|
+
"view",
|
|
97
|
+
"column",
|
|
98
|
+
"embedding",
|
|
99
|
+
"file",
|
|
100
|
+
"extNode",
|
|
101
|
+
"theme",
|
|
102
|
+
"dataView",
|
|
103
|
+
"kv",
|
|
104
|
+
"fs"
|
|
105
|
+
];
|
|
106
|
+
if (namespaces.includes(method)) return new Proxy({}, { get(target$1, subMethod) {
|
|
107
|
+
return async function(...params) {
|
|
108
|
+
const port = await transport.send({
|
|
109
|
+
method: `${method}.${subMethod}`,
|
|
110
|
+
params
|
|
111
|
+
});
|
|
112
|
+
return onCallBack(port);
|
|
113
|
+
};
|
|
114
|
+
} });
|
|
115
|
+
return async (...params) => {
|
|
116
|
+
const port = await transport.send({
|
|
117
|
+
method,
|
|
118
|
+
params
|
|
119
|
+
});
|
|
120
|
+
return onCallBack(port);
|
|
121
|
+
};
|
|
122
|
+
} });
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region src/index.ts
|
|
127
|
+
/**
|
|
128
|
+
* Create an Eidos client for connecting to headless server
|
|
129
|
+
*/
|
|
130
|
+
function createEidosClient(config) {
|
|
131
|
+
const { endpoint, timeout, fetch: fetchFn } = config;
|
|
132
|
+
const spaceProxy = createSpaceProxy({
|
|
133
|
+
endpoint,
|
|
134
|
+
timeout,
|
|
135
|
+
fetch: fetchFn
|
|
136
|
+
});
|
|
137
|
+
return {
|
|
138
|
+
currentSpace: spaceProxy,
|
|
139
|
+
space: spaceProxy
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
//#endregion
|
|
144
|
+
export { createEidosClient, createHttpTransport, createSpaceProxy, onCallBack };
|
|
145
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["config: TransportConfig","requestData: any","simulatedPort: TransportPort","port: TransportPort","config: TransportConfig","method: string","tableId: string","target","tableMethod: string","args?: any","subMethod: string","config: EidosClientConfig"],"sources":["../src/transport.ts","../src/space-proxy.ts","../src/index.ts"],"sourcesContent":["/**\n * HTTP Transport for Eidos RPC client\n * Extracted and adapted from packages/sandbox/src/sdk-inject-script.html\n */\n\nexport interface TransportConfig {\n endpoint: string\n timeout?: number\n fetch?: typeof fetch\n}\n\nexport interface TransportPort {\n onmessage: ((event: { data: any }) => void) | null\n close: () => void\n}\n\n/**\n * Create HTTP transport for RPC calls\n */\nexport function createHttpTransport(config: TransportConfig) {\n const { endpoint, timeout = 30000 } = config\n const fetchFn = config.fetch || globalThis.fetch\n \n return {\n send: async (requestData: any): Promise<TransportPort> => {\n const controller = new AbortController()\n const timeoutId = setTimeout(() => controller.abort(), timeout)\n \n try {\n const response = await fetchFn(endpoint, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(requestData),\n signal: controller.signal,\n })\n \n clearTimeout(timeoutId)\n \n if (!response.ok) {\n throw new Error(`HTTP error: ${response.status}`)\n }\n \n const jsonData = await response.json()\n \n if (!jsonData.success) {\n throw new Error(jsonData.error || 'RPC call failed')\n }\n \n const responseData = jsonData.data\n \n // Create simulated port for callback compatibility\n const simulatedPort: TransportPort = {\n onmessage: null,\n close: () => {},\n }\n \n // Async callback\n setTimeout(() => {\n if (simulatedPort.onmessage) {\n simulatedPort.onmessage({\n data: { type: 'rpcCallResp', data: responseData },\n })\n }\n }, 0)\n \n return simulatedPort\n } catch (error) {\n clearTimeout(timeoutId)\n throw error\n }\n },\n close: () => {},\n }\n}\n\n/**\n * Wait for callback from transport port\n */\nexport function onCallBack(port: TransportPort): Promise<any> {\n return new Promise((resolve, reject) => {\n port.onmessage = (event) => {\n port.close()\n const { type, data } = event.data\n if (type === 'rpcCallResp') {\n resolve(data)\n } else {\n reject(new Error('RPC call failed'))\n }\n }\n })\n}\n","/**\n * Space Proxy for Eidos RPC client\n * Creates a Proxy-based interface for calling RPC methods\n * Extracted and adapted from packages/sandbox/src/sdk-inject-script.html\n */\n\nimport { createHttpTransport, onCallBack, TransportConfig } from './transport'\n\n/**\n * Create space proxy with Prisma-style API\n */\nexport function createSpaceProxy(config: TransportConfig) {\n const transport = createHttpTransport(config)\n \n return new Proxy({}, {\n get: (target, method: string) => {\n // Prisma-style table() API\n if (method === 'table') {\n return function(tableId: string) {\n const tableMethods = [\n 'create',\n 'createMany', \n 'findUnique',\n 'findFirst',\n 'findMany',\n 'count',\n 'update',\n 'updateMany',\n 'delete',\n 'deleteMany',\n ]\n \n return new Proxy({}, {\n get(target, tableMethod: string) {\n if (tableMethods.includes(tableMethod)) {\n return async function(args?: any) {\n const port = await transport.send({\n method: `table(${tableId}).${tableMethod}`,\n params: [args],\n })\n return onCallBack(port)\n }\n }\n return undefined\n },\n })\n }\n }\n \n // Namespace APIs: doc, tree, file, kv, fs, etc.\n const namespaces = [\n 'doc',\n 'action', \n 'graft',\n 'script',\n 'extension',\n 'tree',\n 'view',\n 'column',\n 'embedding',\n 'file',\n 'extNode',\n 'theme',\n 'dataView',\n 'kv',\n 'fs',\n ]\n \n if (namespaces.includes(method)) {\n return new Proxy({}, {\n get(target, subMethod: string) {\n return async function(...params: any[]) {\n const port = await transport.send({\n method: `${method}.${subMethod}`,\n params,\n })\n return onCallBack(port)\n }\n },\n })\n }\n \n // Direct method call\n return async (...params: any[]) => {\n const port = await transport.send({\n method,\n params,\n })\n return onCallBack(port)\n }\n },\n })\n}\n","/**\n * @eidos.space/client\n * \n * Eidos RPC client for Node.js and browser environments.\n * Connect to a headless Eidos server via HTTP.\n * \n * @example\n * ```typescript\n * import { createEidosClient } from '@eidos.space/client'\n * \n * const eidos = createEidosClient({\n * endpoint: 'http://localhost:3000/rpc'\n * })\n * \n * // Query table data\n * const posts = await eidos.currentSpace.table('posts').findMany({\n * where: { published: true },\n * orderBy: { created_at: 'desc' }\n * })\n * \n * // Get document\n * const doc = await eidos.currentSpace.doc.get('doc-id')\n * ```\n */\n\nimport { createSpaceProxy } from './space-proxy'\nimport type { EidosClient, EidosClientConfig } from './types'\nimport type { DataSpace } from '@eidos.space/core'\n\n/**\n * Create an Eidos client for connecting to headless server\n */\nexport function createEidosClient(config: EidosClientConfig): EidosClient {\n const { endpoint, timeout, fetch: fetchFn } = config\n \n const spaceProxy = createSpaceProxy({\n endpoint,\n timeout,\n fetch: fetchFn,\n }) as unknown as DataSpace\n \n return {\n currentSpace: spaceProxy,\n space: spaceProxy,\n }\n}\n\n// Re-export types\nexport type {\n EidosClient,\n EidosClientConfig,\n} from './types'\n\n// Re-export DataSpace for convenience\nexport type { DataSpace } from '@eidos.space/core'\n\n// Re-export low-level APIs for advanced usage\nexport { createSpaceProxy } from './space-proxy'\nexport { createHttpTransport, onCallBack } from './transport'\nexport type { TransportConfig, TransportPort } from './transport'\n"],"mappings":"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"}
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@eidos.space/client",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Eidos RPC client for Node.js and browser",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"eidos",
|
|
7
|
+
"eidos.space",
|
|
8
|
+
"rpc",
|
|
9
|
+
"client",
|
|
10
|
+
"sdk",
|
|
11
|
+
"prisma-style"
|
|
12
|
+
],
|
|
13
|
+
"author": "mayneyao",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/mayneyao/eidos.git",
|
|
18
|
+
"directory": "packages/client"
|
|
19
|
+
},
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/mayneyao/eidos/issues"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://github.com/mayneyao/eidos/tree/main/packages/client#readme",
|
|
24
|
+
"type": "module",
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public",
|
|
28
|
+
"registry": "https://registry.npmjs.org/"
|
|
29
|
+
},
|
|
30
|
+
"main": "dist/index.js",
|
|
31
|
+
"module": "dist/index.js",
|
|
32
|
+
"types": "dist/index.d.ts",
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"import": "./dist/index.js",
|
|
37
|
+
"default": "./dist/index.js"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"files": [
|
|
41
|
+
"dist",
|
|
42
|
+
"README.md",
|
|
43
|
+
"LICENSE"
|
|
44
|
+
],
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@eidos.space/core": "^0.28.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"tsdown": "0.20.0-beta.3",
|
|
50
|
+
"typescript": "^5.7.3"
|
|
51
|
+
},
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"react": ">=18.0.0"
|
|
54
|
+
},
|
|
55
|
+
"peerDependenciesMeta": {
|
|
56
|
+
"react": {
|
|
57
|
+
"optional": true
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"build": "tsdown",
|
|
62
|
+
"dev": "tsdown --watch"
|
|
63
|
+
}
|
|
64
|
+
}
|