@pooflabs/core 0.0.26 → 0.0.28
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/client/config.d.ts +1 -1
- package/dist/client/operations.d.ts +13 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +25 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +25 -11
- package/dist/index.mjs.map +1 -1
- package/dist/types.d.ts +2 -0
- package/package.json +1 -1
package/dist/client/config.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export interface ClientConfig {
|
|
|
19
19
|
};
|
|
20
20
|
phantomConfig?: {
|
|
21
21
|
appId?: string;
|
|
22
|
-
providers?: Array<'injected' | 'google' | 'apple' | 'phantom'>;
|
|
22
|
+
providers?: Array<'injected' | 'google' | 'apple' | 'phantom' | 'deeplink'>;
|
|
23
23
|
redirectUrl?: string;
|
|
24
24
|
autoConnect?: boolean;
|
|
25
25
|
theme?: 'light' | 'dark';
|
|
@@ -5,13 +5,24 @@ export type SetOptions = {
|
|
|
5
5
|
headers?: Record<string, string>;
|
|
6
6
|
};
|
|
7
7
|
};
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Options for the get function.
|
|
10
|
+
*/
|
|
11
|
+
export type GetOptions = {
|
|
12
|
+
/** Natural language prompt for AI-powered queries (collections only) */
|
|
9
13
|
prompt?: string | undefined;
|
|
14
|
+
/** Bypass the local cache and fetch fresh data */
|
|
10
15
|
bypassCache?: boolean;
|
|
16
|
+
/** Include documents from sub-paths (nested collections) */
|
|
17
|
+
includeSubPaths?: boolean;
|
|
18
|
+
/** Shape object for relationship resolution - specifies which related documents to include */
|
|
19
|
+
shape?: Record<string, any>;
|
|
20
|
+
/** Internal overrides for headers */
|
|
11
21
|
_overrides?: {
|
|
12
22
|
headers?: Record<string, string>;
|
|
13
23
|
};
|
|
14
|
-
}
|
|
24
|
+
};
|
|
25
|
+
export declare function get(path: string, opts?: GetOptions): Promise<any>;
|
|
15
26
|
export type RunExpressionOptions = {
|
|
16
27
|
returnType?: 'Bool' | 'String' | 'Int' | 'UInt';
|
|
17
28
|
_overrides?: {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { init } from './client/config';
|
|
2
2
|
export { getConfig, ClientConfig } from './client/config';
|
|
3
|
-
export { get, set, setMany, setFile, getFiles, runQuery, runQueryMany, runExpression, runExpressionMany, signMessage, signTransaction, signAndSubmitTransaction, SetOptions, RunExpressionOptions, RunExpressionResult } from './client/operations';
|
|
3
|
+
export { get, set, setMany, setFile, getFiles, runQuery, runQueryMany, runExpression, runExpressionMany, signMessage, signTransaction, signAndSubmitTransaction, SetOptions, GetOptions, RunExpressionOptions, RunExpressionResult } from './client/operations';
|
|
4
4
|
export { subscribe, closeAllSubscriptions, clearCache, getCachedData, reconnectWithNewAuth } from './client/subscription';
|
|
5
5
|
export * from './types';
|
|
6
6
|
export { getIdToken } from './utils/utils';
|
package/dist/index.js
CHANGED
|
@@ -3279,8 +3279,10 @@ async function get(path, opts = {}) {
|
|
|
3279
3279
|
if (!normalizedPath || normalizedPath.length === 0) {
|
|
3280
3280
|
return new Error("Invalid path provided.");
|
|
3281
3281
|
}
|
|
3282
|
-
// Create cache key combining path and
|
|
3283
|
-
const
|
|
3282
|
+
// Create cache key combining path, prompt, includeSubPaths, and shape
|
|
3283
|
+
const shapeKey = opts.shape ? JSON.stringify(opts.shape) : '';
|
|
3284
|
+
const includeSubPathsKey = opts.includeSubPaths ? ':subpaths' : '';
|
|
3285
|
+
const cacheKey = `${normalizedPath}:${opts.prompt || ''}${includeSubPathsKey}:${shapeKey}`;
|
|
3284
3286
|
const now = Date.now();
|
|
3285
3287
|
// Check for valid cache entry if not bypassing cache
|
|
3286
3288
|
if (!opts.bypassCache && getCache[cacheKey] && now < getCache[cacheKey].expiresAt) {
|
|
@@ -3301,15 +3303,20 @@ async function get(path, opts = {}) {
|
|
|
3301
3303
|
// Cache miss or bypass - proceed with API request
|
|
3302
3304
|
const pathIsDocument = normalizedPath.split("/").length % 2 === 0;
|
|
3303
3305
|
let response;
|
|
3306
|
+
// Build common query params
|
|
3307
|
+
const includeSubPathsParam = opts.includeSubPaths ? '&includeSubPaths=true' : '';
|
|
3308
|
+
const shapeParam = opts.shape ? `&shape=${encodeURIComponent(JSON.stringify(opts.shape))}` : '';
|
|
3304
3309
|
if (pathIsDocument) {
|
|
3305
3310
|
const itemId = encodeURIComponent(normalizedPath);
|
|
3306
|
-
|
|
3311
|
+
// For documents, query params go after the path
|
|
3312
|
+
const queryParams = [includeSubPathsParam, shapeParam].filter(p => p).join('');
|
|
3313
|
+
const apiPath = queryParams ? `items/${itemId}?${queryParams.substring(1)}` : `items/${itemId}`;
|
|
3307
3314
|
response = await makeApiRequest('GET', apiPath, null, opts._overrides);
|
|
3308
3315
|
}
|
|
3309
3316
|
else {
|
|
3310
3317
|
const path = encodeURIComponent(normalizedPath);
|
|
3311
3318
|
const promptQueryParam = (opts === null || opts === void 0 ? void 0 : opts.prompt) ? `&prompt=${btoa(opts.prompt)}` : "";
|
|
3312
|
-
const apiPath = `items?path=${path}${promptQueryParam}`;
|
|
3319
|
+
const apiPath = `items?path=${path}${promptQueryParam}${includeSubPathsParam}${shapeParam}`;
|
|
3313
3320
|
response = await makeApiRequest('GET', apiPath, null, opts._overrides);
|
|
3314
3321
|
}
|
|
3315
3322
|
// Cache the response (unless bypassing cache)
|
|
@@ -3725,9 +3732,10 @@ const WS_V2_PATH = '/ws/v2';
|
|
|
3725
3732
|
function generateSubscriptionId() {
|
|
3726
3733
|
return `sub_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
|
|
3727
3734
|
}
|
|
3728
|
-
function getCacheKey(path, prompt) {
|
|
3735
|
+
function getCacheKey(path, prompt, shape) {
|
|
3729
3736
|
const normalizedPath = path.startsWith('/') ? path.slice(1) : path;
|
|
3730
|
-
|
|
3737
|
+
const shapeKey = shape && Object.keys(shape).length > 0 ? JSON.stringify(shape) : '';
|
|
3738
|
+
return `${normalizedPath}:${prompt || 'default'}:${shapeKey}`;
|
|
3731
3739
|
}
|
|
3732
3740
|
function isTokenExpired(token) {
|
|
3733
3741
|
try {
|
|
@@ -3893,7 +3901,7 @@ function handleServerMessage(connection, message) {
|
|
|
3893
3901
|
const subscription = connection.subscriptions.get(message.subscriptionId);
|
|
3894
3902
|
if (subscription) {
|
|
3895
3903
|
// Update cache
|
|
3896
|
-
const cacheKey = getCacheKey(subscription.path, subscription.prompt);
|
|
3904
|
+
const cacheKey = getCacheKey(subscription.path, subscription.prompt, subscription.shape);
|
|
3897
3905
|
responseCache.set(cacheKey, { data: message.data, timestamp: Date.now() });
|
|
3898
3906
|
// Store last data
|
|
3899
3907
|
subscription.lastData = message.data;
|
|
@@ -3921,7 +3929,7 @@ function handleServerMessage(connection, message) {
|
|
|
3921
3929
|
const subscription = connection.subscriptions.get(message.subscriptionId);
|
|
3922
3930
|
if (subscription) {
|
|
3923
3931
|
// Update cache
|
|
3924
|
-
const cacheKey = getCacheKey(subscription.path, subscription.prompt);
|
|
3932
|
+
const cacheKey = getCacheKey(subscription.path, subscription.prompt, subscription.shape);
|
|
3925
3933
|
responseCache.set(cacheKey, { data: message.data, timestamp: Date.now() });
|
|
3926
3934
|
// Store last data
|
|
3927
3935
|
subscription.lastData = message.data;
|
|
@@ -3974,6 +3982,9 @@ function sendSubscribe(connection, subscription) {
|
|
|
3974
3982
|
path: subscription.path,
|
|
3975
3983
|
prompt: subscription.prompt ? btoa(subscription.prompt) : undefined,
|
|
3976
3984
|
includeSubPaths: subscription.includeSubPaths,
|
|
3985
|
+
shape: subscription.shape && Object.keys(subscription.shape).length > 0
|
|
3986
|
+
? subscription.shape
|
|
3987
|
+
: undefined,
|
|
3977
3988
|
};
|
|
3978
3989
|
try {
|
|
3979
3990
|
connection.ws.send(JSON.stringify(message));
|
|
@@ -4005,7 +4016,7 @@ function sendUnsubscribe(connection, subscriptionId) {
|
|
|
4005
4016
|
async function subscribeV2(path, subscriptionOptions) {
|
|
4006
4017
|
const config = await getConfig();
|
|
4007
4018
|
const normalizedPath = path.startsWith('/') ? path.slice(1) : path;
|
|
4008
|
-
const cacheKey = getCacheKey(normalizedPath, subscriptionOptions.prompt);
|
|
4019
|
+
const cacheKey = getCacheKey(normalizedPath, subscriptionOptions.prompt, subscriptionOptions.shape);
|
|
4009
4020
|
// Deliver cached data immediately if available
|
|
4010
4021
|
const cachedEntry = responseCache.get(cacheKey);
|
|
4011
4022
|
if (cachedEntry && Date.now() - cachedEntry.timestamp < CACHE_TTL && subscriptionOptions.onData) {
|
|
@@ -4016,10 +4027,12 @@ async function subscribeV2(path, subscriptionOptions) {
|
|
|
4016
4027
|
}
|
|
4017
4028
|
// Get or create connection for this appId
|
|
4018
4029
|
const connection = await getOrCreateConnection(config.appId, config.isServer);
|
|
4019
|
-
// Check if we already have a subscription for this path+prompt
|
|
4030
|
+
// Check if we already have a subscription for this path+prompt+shape
|
|
4031
|
+
const shapeKey = subscriptionOptions.shape ? JSON.stringify(subscriptionOptions.shape) : '';
|
|
4020
4032
|
let existingSubscription;
|
|
4021
4033
|
for (const sub of connection.subscriptions.values()) {
|
|
4022
|
-
|
|
4034
|
+
const subShapeKey = sub.shape ? JSON.stringify(sub.shape) : '';
|
|
4035
|
+
if (sub.path === normalizedPath && sub.prompt === subscriptionOptions.prompt && subShapeKey === shapeKey) {
|
|
4023
4036
|
existingSubscription = sub;
|
|
4024
4037
|
break;
|
|
4025
4038
|
}
|
|
@@ -4044,6 +4057,7 @@ async function subscribeV2(path, subscriptionOptions) {
|
|
|
4044
4057
|
subscriptionId,
|
|
4045
4058
|
path: normalizedPath,
|
|
4046
4059
|
prompt: subscriptionOptions.prompt,
|
|
4060
|
+
shape: subscriptionOptions.shape,
|
|
4047
4061
|
includeSubPaths: false,
|
|
4048
4062
|
callbacks: [subscriptionOptions],
|
|
4049
4063
|
lastData: undefined,
|