@tinycloud/node-sdk 2.2.0-beta.10 → 2.2.0-beta.11

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.
@@ -1011,6 +1011,21 @@ declare class TinyCloudNode {
1011
1011
  * SQL database operations on this user's space.
1012
1012
  */
1013
1013
  get sql(): ISQLService;
1014
+ /**
1015
+ * Get an SQL service scoped to a specific space.
1016
+ *
1017
+ * Mirrors {@link SpaceService}'s per-space KV factory: clones the active
1018
+ * service context and overrides its session's spaceId so that subsequent
1019
+ * `sql/<dbName>/<action>` invocations route to that space. Useful when
1020
+ * the caller already holds a delegation covering the target space (e.g.
1021
+ * via {@link grantRuntimePermissions} or {@link useRuntimeDelegation})
1022
+ * but the SDK's per-space SQL surface isn't otherwise exposed.
1023
+ *
1024
+ * Does NOT auto-create the space.
1025
+ *
1026
+ * @param spaceId - Full space URI (`tinycloud:pkh:eip155:<chain>:<addr>:<name>`).
1027
+ */
1028
+ sqlForSpace(spaceId: string): ISQLService;
1014
1029
  /**
1015
1030
  * DuckDB database operations on this user's space.
1016
1031
  */
@@ -1011,6 +1011,21 @@ declare class TinyCloudNode {
1011
1011
  * SQL database operations on this user's space.
1012
1012
  */
1013
1013
  get sql(): ISQLService;
1014
+ /**
1015
+ * Get an SQL service scoped to a specific space.
1016
+ *
1017
+ * Mirrors {@link SpaceService}'s per-space KV factory: clones the active
1018
+ * service context and overrides its session's spaceId so that subsequent
1019
+ * `sql/<dbName>/<action>` invocations route to that space. Useful when
1020
+ * the caller already holds a delegation covering the target space (e.g.
1021
+ * via {@link grantRuntimePermissions} or {@link useRuntimeDelegation})
1022
+ * but the SDK's per-space SQL surface isn't otherwise exposed.
1023
+ *
1024
+ * Does NOT auto-create the space.
1025
+ *
1026
+ * @param spaceId - Full space URI (`tinycloud:pkh:eip155:<chain>:<addr>:<name>`).
1027
+ */
1028
+ sqlForSpace(spaceId: string): ISQLService;
1014
1029
  /**
1015
1030
  * DuckDB database operations on this user's space.
1016
1031
  */
package/dist/core.cjs CHANGED
@@ -343,7 +343,7 @@ var NodeUserAuthorization = class {
343
343
  ]
344
344
  }
345
345
  };
346
- this.sessionExpirationMs = config.sessionExpirationMs ?? 60 * 60 * 1e3;
346
+ this.sessionExpirationMs = config.sessionExpirationMs ?? import_sdk_core2.EXPIRY.SESSION_MS;
347
347
  this.autoCreateSpace = config.autoCreateSpace ?? false;
348
348
  this.spaceCreationHandler = config.spaceCreationHandler;
349
349
  this.tinycloudHosts = config.tinycloudHosts;
@@ -1231,9 +1231,10 @@ function legacyParamsToPermissionEntries(actions, path, spaceIdOverride) {
1231
1231
  }
1232
1232
  return entries;
1233
1233
  }
1234
+ var DEFAULT_DELEGATION_EXPIRY_MS = import_sdk_core4.EXPIRY.SESSION_MS;
1234
1235
  function resolveExpiryMs(expiry) {
1235
1236
  if (expiry === void 0) {
1236
- return 60 * 60 * 1e3;
1237
+ return DEFAULT_DELEGATION_EXPIRY_MS;
1237
1238
  }
1238
1239
  if (typeof expiry === "number") {
1239
1240
  if (!Number.isFinite(expiry) || expiry <= 0) {
@@ -1403,6 +1404,7 @@ var NodeSecretsService = class {
1403
1404
 
1404
1405
  // src/TinyCloudNode.ts
1405
1406
  var DEFAULT_HOST = "https://node.tinycloud.xyz";
1407
+ var DEFAULT_SESSION_EXPIRATION_MS = import_sdk_core6.EXPIRY.SESSION_MS;
1406
1408
  var _TinyCloudNode = class _TinyCloudNode {
1407
1409
  /**
1408
1410
  * Create a new TinyCloudNode instance.
@@ -1545,7 +1547,7 @@ var _TinyCloudNode = class _TinyCloudNode {
1545
1547
  sessionStorage: config.sessionStorage ?? new MemorySessionStorage(),
1546
1548
  domain: this.siweDomain,
1547
1549
  spacePrefix: config.prefix,
1548
- sessionExpirationMs: config.sessionExpirationMs ?? 60 * 60 * 1e3,
1550
+ sessionExpirationMs: config.sessionExpirationMs ?? DEFAULT_SESSION_EXPIRATION_MS,
1549
1551
  tinycloudHosts: this.explicitHost ? [this.explicitHost] : void 0,
1550
1552
  tinycloudRegistryUrl: config.tinycloudRegistryUrl,
1551
1553
  tinycloudFallbackHosts: config.tinycloudFallbackHosts,
@@ -1855,7 +1857,7 @@ var _TinyCloudNode = class _TinyCloudNode {
1855
1857
  sessionStorage: options?.sessionStorage ?? this.config.sessionStorage ?? new MemorySessionStorage(),
1856
1858
  domain: this.siweDomain,
1857
1859
  spacePrefix: prefix,
1858
- sessionExpirationMs: this.config.sessionExpirationMs ?? 60 * 60 * 1e3,
1860
+ sessionExpirationMs: this.config.sessionExpirationMs ?? DEFAULT_SESSION_EXPIRATION_MS,
1859
1861
  tinycloudHosts: this.explicitHost ? [this.explicitHost] : void 0,
1860
1862
  tinycloudRegistryUrl: this.config.tinycloudRegistryUrl,
1861
1863
  tinycloudFallbackHosts: this.config.tinycloudFallbackHosts,
@@ -1899,7 +1901,7 @@ var _TinyCloudNode = class _TinyCloudNode {
1899
1901
  sessionStorage: options?.sessionStorage ?? this.config.sessionStorage ?? new MemorySessionStorage(),
1900
1902
  domain: this.siweDomain,
1901
1903
  spacePrefix: prefix,
1902
- sessionExpirationMs: this.config.sessionExpirationMs ?? 60 * 60 * 1e3,
1904
+ sessionExpirationMs: this.config.sessionExpirationMs ?? DEFAULT_SESSION_EXPIRATION_MS,
1903
1905
  tinycloudHosts: this.explicitHost ? [this.explicitHost] : void 0,
1904
1906
  tinycloudRegistryUrl: this.config.tinycloudRegistryUrl,
1905
1907
  tinycloudFallbackHosts: this.config.tinycloudFallbackHosts,
@@ -2175,7 +2177,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2175
2177
  * @internal
2176
2178
  */
2177
2179
  getSessionExpiry() {
2178
- const expirationMs = this.config.sessionExpirationMs ?? 60 * 60 * 1e3;
2180
+ const expirationMs = this.config.sessionExpirationMs ?? DEFAULT_SESSION_EXPIRATION_MS;
2179
2181
  return new Date(Date.now() + expirationMs);
2180
2182
  }
2181
2183
  /**
@@ -2332,6 +2334,34 @@ var _TinyCloudNode = class _TinyCloudNode {
2332
2334
  }
2333
2335
  return this._sql;
2334
2336
  }
2337
+ /**
2338
+ * Get an SQL service scoped to a specific space.
2339
+ *
2340
+ * Mirrors {@link SpaceService}'s per-space KV factory: clones the active
2341
+ * service context and overrides its session's spaceId so that subsequent
2342
+ * `sql/<dbName>/<action>` invocations route to that space. Useful when
2343
+ * the caller already holds a delegation covering the target space (e.g.
2344
+ * via {@link grantRuntimePermissions} or {@link useRuntimeDelegation})
2345
+ * but the SDK's per-space SQL surface isn't otherwise exposed.
2346
+ *
2347
+ * Does NOT auto-create the space.
2348
+ *
2349
+ * @param spaceId - Full space URI (`tinycloud:pkh:eip155:<chain>:<addr>:<name>`).
2350
+ */
2351
+ sqlForSpace(spaceId) {
2352
+ if (!this._serviceContext || !this._serviceContext.session) {
2353
+ throw new Error("Not signed in. Call signIn() first.");
2354
+ }
2355
+ const sql = new import_sdk_core6.SQLService({});
2356
+ const spaceScopedContext = new import_sdk_core6.ServiceContext({
2357
+ invoke: this._serviceContext.invoke,
2358
+ fetch: this._serviceContext.fetch,
2359
+ hosts: this._serviceContext.hosts
2360
+ });
2361
+ spaceScopedContext.setSession({ ...this._serviceContext.session, spaceId });
2362
+ sql.initialize(spaceScopedContext);
2363
+ return sql;
2364
+ }
2335
2365
  /**
2336
2366
  * DuckDB database operations on this user's space.
2337
2367
  */
@@ -2758,7 +2788,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2758
2788
  ];
2759
2789
  const abilities = { kv: { "": kvActions } };
2760
2790
  const now = /* @__PURE__ */ new Date();
2761
- const expiryMs = 60 * 60 * 1e3;
2791
+ const expiryMs = import_sdk_core6.EXPIRY.EPHEMERAL_MS;
2762
2792
  const expirationTime = new Date(now.getTime() + expiryMs);
2763
2793
  const prepared = this.wasmBindings.prepareSession({
2764
2794
  abilities,