@eidos.space/client 0.1.0 → 0.2.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/README.md +2 -0
- package/dist/{index.d.ts → index.d.mts} +9 -11
- package/dist/index.d.mts.map +1 -0
- package/dist/{index.js → index.mjs} +44 -16
- package/dist/index.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -15,6 +15,7 @@ import { createEidosClient } from "@eidos.space/client"
|
|
|
15
15
|
|
|
16
16
|
const client = createEidosClient({
|
|
17
17
|
endpoint: "http://localhost:3000/rpc",
|
|
18
|
+
apiKey: "your-api-key", // Optional: if server requires authentication
|
|
18
19
|
})
|
|
19
20
|
|
|
20
21
|
// Query table data
|
|
@@ -112,6 +113,7 @@ The `createEidosClient` function accepts a configuration object:
|
|
|
112
113
|
| `endpoint` | `string` | The RPC endpoint URL (e.g., `http://localhost:3000/rpc`) |
|
|
113
114
|
| `timeout` | `number` | Request timeout in milliseconds (default: 30000) |
|
|
114
115
|
| `fetch` | `typeof fetch` | Custom fetch implementation (optional) |
|
|
116
|
+
| `apiKey` | `string` | API Key for authentication (optional) |
|
|
115
117
|
|
|
116
118
|
## Features
|
|
117
119
|
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { DataSpace, DataSpace as DataSpace$1 } from "@eidos.space/core";
|
|
2
2
|
|
|
3
3
|
//#region src/types.d.ts
|
|
4
|
-
|
|
5
4
|
/**
|
|
6
5
|
* Eidos client interface
|
|
7
6
|
*/
|
|
8
7
|
interface EidosClient {
|
|
9
8
|
/**
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
* The current data space
|
|
10
|
+
*/
|
|
12
11
|
currentSpace: DataSpace$1;
|
|
13
12
|
/**
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
* Alias for currentSpace
|
|
14
|
+
*/
|
|
16
15
|
space: DataSpace$1;
|
|
17
16
|
}
|
|
18
17
|
/**
|
|
@@ -25,8 +24,9 @@ interface EidosClientConfig {
|
|
|
25
24
|
timeout?: number;
|
|
26
25
|
/** Custom fetch function */
|
|
27
26
|
fetch?: typeof fetch;
|
|
27
|
+
/** API Key for authentication */
|
|
28
|
+
apiKey?: string;
|
|
28
29
|
}
|
|
29
|
-
//# sourceMappingURL=types.d.ts.map
|
|
30
30
|
//#endregion
|
|
31
31
|
//#region src/transport.d.ts
|
|
32
32
|
/**
|
|
@@ -37,6 +37,7 @@ interface TransportConfig {
|
|
|
37
37
|
endpoint: string;
|
|
38
38
|
timeout?: number;
|
|
39
39
|
fetch?: typeof fetch;
|
|
40
|
+
apiKey?: string;
|
|
40
41
|
}
|
|
41
42
|
interface TransportPort {
|
|
42
43
|
onmessage: ((event: {
|
|
@@ -55,15 +56,12 @@ declare function createHttpTransport(config: TransportConfig): {
|
|
|
55
56
|
* Wait for callback from transport port
|
|
56
57
|
*/
|
|
57
58
|
declare function onCallBack(port: TransportPort): Promise<any>;
|
|
58
|
-
//# sourceMappingURL=transport.d.ts.map
|
|
59
59
|
//#endregion
|
|
60
60
|
//#region src/space-proxy.d.ts
|
|
61
61
|
/**
|
|
62
62
|
* Create space proxy with Prisma-style API
|
|
63
63
|
*/
|
|
64
64
|
declare function createSpaceProxy(config: TransportConfig): {};
|
|
65
|
-
//# sourceMappingURL=space-proxy.d.ts.map
|
|
66
|
-
|
|
67
65
|
//#endregion
|
|
68
66
|
//#region src/index.d.ts
|
|
69
67
|
/**
|
|
@@ -71,5 +69,5 @@ declare function createSpaceProxy(config: TransportConfig): {};
|
|
|
71
69
|
*/
|
|
72
70
|
declare function createEidosClient(config: EidosClientConfig): EidosClient;
|
|
73
71
|
//#endregion
|
|
74
|
-
export { DataSpace, EidosClient, EidosClientConfig, TransportConfig, TransportPort, createEidosClient, createHttpTransport, createSpaceProxy, onCallBack };
|
|
75
|
-
//# sourceMappingURL=index.d.
|
|
72
|
+
export { type DataSpace, type EidosClient, type EidosClientConfig, type TransportConfig, type TransportPort, createEidosClient, createHttpTransport, createSpaceProxy, onCallBack };
|
|
73
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/transport.ts","../src/space-proxy.ts","../src/index.ts"],"mappings":";;;;AAKA;;UAAiB,WAAA;EAAA;;;EAIf,YAAA,EAAc,WAAA;EAAA;;;EAId,KAAA,EAAO,WAAA;AAAA;AAAA;;;AAAA,UAMQ,iBAAA;EAAA;EAEf,QAAA;EAAA;EAEA,OAAA;EAAA;EAEA,KAAA,UAAe,KAAA;EAAA;EAEf,MAAA;AAAA;;;;ACtBF;;;UAAiB,eAAA;EACf,QAAA;EACA,OAAA;EACA,KAAA,UAAe,KAAA;EACf,MAAA;AAAA;AAAA,UAGe,aAAA;EACf,SAAA,IAAa,KAAA;IAAS,IAAA;EAAA;EACtB,KAAA;AAAA;AAAA;;;AAAA,iBAMc,mBAAA,CAAoB,MAAA,EAAQ,eAAA;8BAKR,OAAA,CAAQ,aAAA;;;;;;iBAyD5B,UAAA,CAAW,IAAA,EAAM,aAAA,GAAgB,OAAA;;;;ACvEjD;;iBAAgB,gBAAA,CAAiB,MAAA,EAAQ,eAAA;;;;ACqBzC;;iBAAgB,iBAAA,CAAkB,MAAA,EAAQ,iBAAA,GAAoB,WAAA"}
|
|
@@ -12,7 +12,10 @@ function createHttpTransport(config) {
|
|
|
12
12
|
try {
|
|
13
13
|
const response = await fetchFn(endpoint, {
|
|
14
14
|
method: "POST",
|
|
15
|
-
headers: {
|
|
15
|
+
headers: {
|
|
16
|
+
"Content-Type": "application/json",
|
|
17
|
+
...config.apiKey ? { "Authorization": `Bearer ${config.apiKey}` } : {}
|
|
18
|
+
},
|
|
16
19
|
body: JSON.stringify(requestData),
|
|
17
20
|
signal: controller.signal
|
|
18
21
|
});
|
|
@@ -57,6 +60,11 @@ function onCallBack(port) {
|
|
|
57
60
|
//#endregion
|
|
58
61
|
//#region src/space-proxy.ts
|
|
59
62
|
/**
|
|
63
|
+
* Space Proxy for Eidos RPC client
|
|
64
|
+
* Creates a Proxy-based interface for calling RPC methods
|
|
65
|
+
* Extracted and adapted from packages/sandbox/src/sdk-inject-script.html
|
|
66
|
+
*/
|
|
67
|
+
/**
|
|
60
68
|
* Create space proxy with Prisma-style API
|
|
61
69
|
*/
|
|
62
70
|
function createSpaceProxy(config) {
|
|
@@ -77,16 +85,14 @@ function createSpaceProxy(config) {
|
|
|
77
85
|
];
|
|
78
86
|
return new Proxy({}, { get(target$1, tableMethod) {
|
|
79
87
|
if (tableMethods.includes(tableMethod)) return async function(args) {
|
|
80
|
-
|
|
88
|
+
return onCallBack(await transport.send({
|
|
81
89
|
method: `table(${tableId}).${tableMethod}`,
|
|
82
90
|
params: [args]
|
|
83
|
-
});
|
|
84
|
-
return onCallBack(port);
|
|
91
|
+
}));
|
|
85
92
|
};
|
|
86
|
-
return void 0;
|
|
87
93
|
} });
|
|
88
94
|
};
|
|
89
|
-
|
|
95
|
+
if ([
|
|
90
96
|
"doc",
|
|
91
97
|
"action",
|
|
92
98
|
"graft",
|
|
@@ -102,22 +108,19 @@ function createSpaceProxy(config) {
|
|
|
102
108
|
"dataView",
|
|
103
109
|
"kv",
|
|
104
110
|
"fs"
|
|
105
|
-
]
|
|
106
|
-
if (namespaces.includes(method)) return new Proxy({}, { get(target$1, subMethod) {
|
|
111
|
+
].includes(method)) return new Proxy({}, { get(target$1, subMethod) {
|
|
107
112
|
return async function(...params) {
|
|
108
|
-
|
|
113
|
+
return onCallBack(await transport.send({
|
|
109
114
|
method: `${method}.${subMethod}`,
|
|
110
115
|
params
|
|
111
|
-
});
|
|
112
|
-
return onCallBack(port);
|
|
116
|
+
}));
|
|
113
117
|
};
|
|
114
118
|
} });
|
|
115
119
|
return async (...params) => {
|
|
116
|
-
|
|
120
|
+
return onCallBack(await transport.send({
|
|
117
121
|
method,
|
|
118
122
|
params
|
|
119
|
-
});
|
|
120
|
-
return onCallBack(port);
|
|
123
|
+
}));
|
|
121
124
|
};
|
|
122
125
|
} });
|
|
123
126
|
}
|
|
@@ -125,6 +128,30 @@ function createSpaceProxy(config) {
|
|
|
125
128
|
//#endregion
|
|
126
129
|
//#region src/index.ts
|
|
127
130
|
/**
|
|
131
|
+
* @eidos.space/client
|
|
132
|
+
*
|
|
133
|
+
* Eidos RPC client for Node.js and browser environments.
|
|
134
|
+
* Connect to a headless Eidos server via HTTP.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* import { createEidosClient } from '@eidos.space/client'
|
|
139
|
+
*
|
|
140
|
+
* const eidos = createEidosClient({
|
|
141
|
+
* endpoint: 'http://localhost:3000/rpc'
|
|
142
|
+
* })
|
|
143
|
+
*
|
|
144
|
+
* // Query table data
|
|
145
|
+
* const posts = await eidos.currentSpace.table('posts').findMany({
|
|
146
|
+
* where: { published: true },
|
|
147
|
+
* orderBy: { created_at: 'desc' }
|
|
148
|
+
* })
|
|
149
|
+
*
|
|
150
|
+
* // Get document
|
|
151
|
+
* const doc = await eidos.currentSpace.doc.get('doc-id')
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
/**
|
|
128
155
|
* Create an Eidos client for connecting to headless server
|
|
129
156
|
*/
|
|
130
157
|
function createEidosClient(config) {
|
|
@@ -132,7 +159,8 @@ function createEidosClient(config) {
|
|
|
132
159
|
const spaceProxy = createSpaceProxy({
|
|
133
160
|
endpoint,
|
|
134
161
|
timeout,
|
|
135
|
-
fetch: fetchFn
|
|
162
|
+
fetch: fetchFn,
|
|
163
|
+
apiKey: config.apiKey
|
|
136
164
|
});
|
|
137
165
|
return {
|
|
138
166
|
currentSpace: spaceProxy,
|
|
@@ -142,4 +170,4 @@ function createEidosClient(config) {
|
|
|
142
170
|
|
|
143
171
|
//#endregion
|
|
144
172
|
export { createEidosClient, createHttpTransport, createSpaceProxy, onCallBack };
|
|
145
|
-
//# sourceMappingURL=index.
|
|
173
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"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 apiKey?: string\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 ...(config.apiKey ? { 'Authorization': `Bearer ${config.apiKey}` } : {}),\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 apiKey: config.apiKey,\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":";;;;AAoBA,SAAgB,oBAAoB,QAAyB;CAC3D,MAAM,EAAE,UAAU,UAAU,QAAU;CACtC,MAAM,UAAU,OAAO,SAAS,WAAW;AAE3C,QAAO;EACL,MAAM,OAAO,gBAA6C;GACxD,MAAM,aAAa,IAAI,iBAAiB;GACxC,MAAM,YAAY,iBAAiB,WAAW,OAAO,EAAE,QAAQ;AAE/D,OAAI;IACF,MAAM,WAAW,MAAM,QAAQ,UAAU;KACvC,QAAQ;KACR,SAAS;MACP,gBAAgB;MAChB,GAAI,OAAO,SAAS,EAAE,iBAAiB,UAAU,OAAO,UAAU,GAAG,EAAE;MACxE;KACD,MAAM,KAAK,UAAU,YAAY;KACjC,QAAQ,WAAW;KACpB,CAAC;AAEF,iBAAa,UAAU;AAEvB,QAAI,CAAC,SAAS,GACZ,OAAM,IAAI,MAAM,eAAe,SAAS,SAAS;IAGnD,MAAM,WAAW,MAAM,SAAS,MAAM;AAEtC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AAmB;AAC7B,UAAO,eAAe,GAAG,QAAe;AAKtC,WAAO,WAJM,MAAM,UAAU,KAAK;KAChC,QAAQ,GAAG,OAAO,GAAG;KACrB;KACD,CAAC,CACqB;;KAG5B,CAAC;AAIJ,SAAO,OAAO,GAAG,WAAkB;AAKjC,UAAO,WAJM,MAAM,UAAU,KAAK;IAChC;IACA;IACD,CAAC,CACqB;;IAG5B,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC3DJ,SAAgB,kBAAkB,QAAwC;CACxE,MAAM,EAAE,UAAU,SAAS,OAAO,YAAY;CAE9C,MAAM,aAAa,iBAAiB;EAClC;EACA;EACA,OAAO;EACP,QAAQ,OAAO;EAChB,CAAC;AAEF,QAAO;EACL,cAAc;EACd,OAAO;EACR"}
|
package/package.json
CHANGED
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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":";;;;AAmBA,SAAgB,oBAAoBA,QAAyB;CAC3D,MAAM,EAAE,UAAU,UAAU,KAAO,GAAG;CACtC,MAAM,UAAU,OAAO,SAAS,WAAW;AAE3C,QAAO;EACL,MAAM,OAAOC,gBAA6C;GACxD,MAAM,aAAa,IAAI;GACvB,MAAM,YAAY,WAAW,MAAM,WAAW,OAAO,EAAE,QAAQ;AAE/D,OAAI;IACF,MAAM,WAAW,MAAM,QAAQ,UAAU;KACvC,QA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