@tinycloud/node-sdk 2.0.4-beta.0 → 2.1.0-beta.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/dist/core.cjs CHANGED
@@ -311,12 +311,22 @@ var NodeUserAuthorization = class {
311
311
  },
312
312
  capabilities: {
313
313
  "": ["tinycloud.capabilities/read"]
314
+ },
315
+ hooks: {
316
+ "": [
317
+ "tinycloud.hooks/subscribe",
318
+ "tinycloud.hooks/register",
319
+ "tinycloud.hooks/list",
320
+ "tinycloud.hooks/unregister"
321
+ ]
314
322
  }
315
323
  };
316
324
  this.sessionExpirationMs = config.sessionExpirationMs ?? 60 * 60 * 1e3;
317
325
  this.autoCreateSpace = config.autoCreateSpace ?? false;
318
326
  this.spaceCreationHandler = config.spaceCreationHandler;
319
- this.tinycloudHosts = config.tinycloudHosts ?? ["https://node.tinycloud.xyz"];
327
+ this.tinycloudHosts = config.tinycloudHosts ?? [
328
+ "https://node.tinycloud.xyz"
329
+ ];
320
330
  this.enablePublicSpace = config.enablePublicSpace ?? true;
321
331
  this.nonce = config.nonce;
322
332
  this.siweConfig = config.siweConfig;
@@ -456,7 +466,10 @@ var NodeUserAuthorization = class {
456
466
  throw err;
457
467
  }
458
468
  } catch (error) {
459
- handler.onSpaceCreationFailed?.(creationContext, error instanceof Error ? error : new Error(String(error)));
469
+ handler.onSpaceCreationFailed?.(
470
+ creationContext,
471
+ error instanceof Error ? error : new Error(String(error))
472
+ );
460
473
  throw error;
461
474
  }
462
475
  await new Promise((resolve) => setTimeout(resolve, 100));
@@ -490,7 +503,10 @@ var NodeUserAuthorization = class {
490
503
  throw err;
491
504
  }
492
505
  } catch (error) {
493
- handler.onSpaceCreationFailed?.(creationContext, error instanceof Error ? error : new Error(String(error)));
506
+ handler.onSpaceCreationFailed?.(
507
+ creationContext,
508
+ error instanceof Error ? error : new Error(String(error))
509
+ );
494
510
  throw error;
495
511
  }
496
512
  await new Promise((resolve) => setTimeout(resolve, 100));
@@ -599,7 +615,10 @@ var NodeUserAuthorization = class {
599
615
  this._tinyCloudSession = tinyCloudSession;
600
616
  this._address = address;
601
617
  this._chainId = chainId;
602
- const nodeInfo = await (0, import_sdk_core2.checkNodeInfo)(this.tinycloudHosts[0], this.wasm.protocolVersion());
618
+ const nodeInfo = await (0, import_sdk_core2.checkNodeInfo)(
619
+ this.tinycloudHosts[0],
620
+ this.wasm.protocolVersion()
621
+ );
603
622
  this._nodeFeatures = nodeInfo.features;
604
623
  for (const ext of this.extensions) {
605
624
  if (ext.afterSignIn) {
@@ -759,7 +778,10 @@ var NodeUserAuthorization = class {
759
778
  this._tinyCloudSession = tinyCloudSession;
760
779
  this._address = address;
761
780
  this._chainId = chainId;
762
- const nodeInfo = await (0, import_sdk_core2.checkNodeInfo)(this.tinycloudHosts[0], this.wasm.protocolVersion());
781
+ const nodeInfo = await (0, import_sdk_core2.checkNodeInfo)(
782
+ this.tinycloudHosts[0],
783
+ this.wasm.protocolVersion()
784
+ );
763
785
  this._nodeFeatures = nodeInfo.features;
764
786
  for (const ext of this.extensions) {
765
787
  if (ext.afterSignIn) {
@@ -810,7 +832,9 @@ var NodeUserAuthorization = class {
810
832
  );
811
833
  }
812
834
  default:
813
- throw new Error(`Unknown sign strategy: ${this.signStrategy.type}`);
835
+ throw new Error(
836
+ `Unknown sign strategy: ${this.signStrategy.type}`
837
+ );
814
838
  }
815
839
  }
816
840
  /**
@@ -862,6 +886,9 @@ var DelegatedAccess = class {
862
886
  this._duckdb = new import_sdk_core3.DuckDbService({});
863
887
  this._duckdb.initialize(this._serviceContext);
864
888
  this._serviceContext.registerService("duckdb", this._duckdb);
889
+ this._hooks = new import_sdk_core3.HooksService({});
890
+ this._hooks.initialize(this._serviceContext);
891
+ this._serviceContext.registerService("hooks", this._hooks);
865
892
  const serviceSession = {
866
893
  delegationHeader: session.delegationHeader,
867
894
  delegationCid: session.delegationCid,
@@ -907,6 +934,12 @@ var DelegatedAccess = class {
907
934
  get duckdb() {
908
935
  return this._duckdb;
909
936
  }
937
+ /**
938
+ * Hooks write-stream subscriptions on the delegated space.
939
+ */
940
+ get hooks() {
941
+ return this._hooks;
942
+ }
910
943
  };
911
944
 
912
945
  // src/keys/WasmKeyProvider.ts
@@ -1112,7 +1145,9 @@ var TinyCloudNode = class _TinyCloudNode {
1112
1145
  nonce: config.nonce,
1113
1146
  siweConfig: config.siweConfig
1114
1147
  });
1115
- this.tc = new import_sdk_core4.TinyCloud(this.auth);
1148
+ this.tc = new import_sdk_core4.TinyCloud(this.auth, {
1149
+ invokeAny: this.wasmBindings.invokeAny
1150
+ });
1116
1151
  }
1117
1152
  /**
1118
1153
  * Get the primary identity DID for this user.
@@ -1181,6 +1216,7 @@ var TinyCloudNode = class _TinyCloudNode {
1181
1216
  this._kv = void 0;
1182
1217
  this._sql = void 0;
1183
1218
  this._duckdb = void 0;
1219
+ this._hooks = void 0;
1184
1220
  this._serviceContext = void 0;
1185
1221
  await this.tc.signIn();
1186
1222
  this.initializeServices();
@@ -1200,6 +1236,7 @@ var TinyCloudNode = class _TinyCloudNode {
1200
1236
  this._kv = void 0;
1201
1237
  this._sql = void 0;
1202
1238
  this._duckdb = void 0;
1239
+ this._hooks = void 0;
1203
1240
  this._serviceContext = void 0;
1204
1241
  if (sessionData.address) {
1205
1242
  this._address = sessionData.address;
@@ -1209,6 +1246,7 @@ var TinyCloudNode = class _TinyCloudNode {
1209
1246
  }
1210
1247
  this._serviceContext = new import_sdk_core4.ServiceContext({
1211
1248
  invoke: this.wasmBindings.invoke,
1249
+ invokeAny: this.wasmBindings.invokeAny,
1212
1250
  fetch: globalThis.fetch.bind(globalThis),
1213
1251
  hosts: [this.config.host]
1214
1252
  });
@@ -1221,6 +1259,9 @@ var TinyCloudNode = class _TinyCloudNode {
1221
1259
  this._duckdb = new import_sdk_core4.DuckDbService({});
1222
1260
  this._duckdb.initialize(this._serviceContext);
1223
1261
  this._serviceContext.registerService("duckdb", this._duckdb);
1262
+ this._hooks = new import_sdk_core4.HooksService({});
1263
+ this._hooks.initialize(this._serviceContext);
1264
+ this._serviceContext.registerService("hooks", this._hooks);
1224
1265
  const serviceSession = {
1225
1266
  delegationHeader: sessionData.delegationHeader,
1226
1267
  delegationCid: sessionData.delegationCid,
@@ -1320,7 +1361,9 @@ var TinyCloudNode = class _TinyCloudNode {
1320
1361
  nonce: this.config.nonce,
1321
1362
  siweConfig: this.config.siweConfig
1322
1363
  });
1323
- this.tc = new import_sdk_core4.TinyCloud(this.auth);
1364
+ this.tc = new import_sdk_core4.TinyCloud(this.auth, {
1365
+ invokeAny: this.wasmBindings.invokeAny
1366
+ });
1324
1367
  this.config.prefix = prefix;
1325
1368
  }
1326
1369
  /**
@@ -1358,7 +1401,9 @@ var TinyCloudNode = class _TinyCloudNode {
1358
1401
  nonce: this.config.nonce,
1359
1402
  siweConfig: this.config.siweConfig
1360
1403
  });
1361
- this.tc = new import_sdk_core4.TinyCloud(this.auth);
1404
+ this.tc = new import_sdk_core4.TinyCloud(this.auth, {
1405
+ invokeAny: this.wasmBindings.invokeAny
1406
+ });
1362
1407
  this.config.prefix = prefix;
1363
1408
  }
1364
1409
  /**
@@ -1373,6 +1418,7 @@ var TinyCloudNode = class _TinyCloudNode {
1373
1418
  this.tc.initializeServices(this.wasmBindings.invoke, [this.config.host]);
1374
1419
  this._serviceContext = new import_sdk_core4.ServiceContext({
1375
1420
  invoke: this.wasmBindings.invoke,
1421
+ invokeAny: this.wasmBindings.invokeAny,
1376
1422
  fetch: globalThis.fetch.bind(globalThis),
1377
1423
  hosts: [this.config.host]
1378
1424
  });
@@ -1390,6 +1436,9 @@ var TinyCloudNode = class _TinyCloudNode {
1390
1436
  this._duckdb.initialize(this._serviceContext);
1391
1437
  this._serviceContext.registerService("duckdb", this._duckdb);
1392
1438
  }
1439
+ this._hooks = new import_sdk_core4.HooksService({});
1440
+ this._hooks.initialize(this._serviceContext);
1441
+ this._serviceContext.registerService("hooks", this._hooks);
1393
1442
  const serviceSession = {
1394
1443
  delegationHeader: session.delegationHeader,
1395
1444
  delegationCid: session.delegationCid,
@@ -1768,6 +1817,15 @@ var TinyCloudNode = class _TinyCloudNode {
1768
1817
  }
1769
1818
  return this._vault;
1770
1819
  }
1820
+ /**
1821
+ * Hooks write stream subscription API.
1822
+ */
1823
+ get hooks() {
1824
+ if (!this._hooks) {
1825
+ throw new Error("Not signed in. Call signIn() first.");
1826
+ }
1827
+ return this._hooks;
1828
+ }
1771
1829
  // ===========================================================================
1772
1830
  // v2 Service Accessors
1773
1831
  // ===========================================================================