@spacelr/sdk 0.3.0 → 0.5.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/index.mjs CHANGED
@@ -825,7 +825,7 @@ var RealtimeClient = class {
825
825
  if (!where || Object.keys(where).length === 0) {
826
826
  return base;
827
827
  }
828
- const filterStr = Object.keys(where).sort().map((k) => `${k}=${String(where[k])}`).join("&");
828
+ const filterStr = Object.keys(where).sort().map((k) => `${k}=${JSON.stringify(where[k])}`).join("&");
829
829
  return `${base}?${filterStr}`;
830
830
  }
831
831
  async ensureConnected() {
@@ -973,15 +973,15 @@ var RealtimeClient = class {
973
973
  if (room === base) return true;
974
974
  if (!room.startsWith(`${base}?`)) return false;
975
975
  const where = this.roomWhereMap.get(room);
976
- if (!where) return true;
976
+ if (!where) return false;
977
977
  if (!event.document) return false;
978
978
  for (const [key, value] of Object.entries(where)) {
979
979
  const docValue = event.document[key];
980
980
  if (Array.isArray(docValue)) {
981
- if (!docValue.some((item) => String(item) === String(value))) {
981
+ if (!docValue.includes(value)) {
982
982
  return false;
983
983
  }
984
- } else if (String(docValue) !== String(value)) {
984
+ } else if (docValue !== value) {
985
985
  return false;
986
986
  }
987
987
  }
@@ -2672,6 +2672,65 @@ var FunctionsModule = class {
2672
2672
  }
2673
2673
  };
2674
2674
 
2675
+ // libs/sdk/src/modules/schedule.module.ts
2676
+ var ScheduleModule = class {
2677
+ constructor(http, projectId) {
2678
+ this.http = http;
2679
+ this.projectId = projectId;
2680
+ }
2681
+ /**
2682
+ * Schedule a one-shot function invocation. Returns the existing handle
2683
+ * unchanged if `idempotencyKey` matches a prior invoke in this project
2684
+ * for this function.
2685
+ */
2686
+ async invoke(options) {
2687
+ return this.http.request({
2688
+ method: "POST",
2689
+ path: `/schedules/${encodeURIComponent(this.projectId)}`,
2690
+ body: {
2691
+ functionId: options.functionId,
2692
+ executeAt: this.toIsoString(options.executeAt),
2693
+ ...options.payload !== void 0 ? { payload: options.payload } : {},
2694
+ ...options.idempotencyKey !== void 0 ? { idempotencyKey: options.idempotencyKey } : {},
2695
+ ...options.maxAttempts !== void 0 ? { maxAttempts: options.maxAttempts } : {}
2696
+ },
2697
+ authenticated: true
2698
+ });
2699
+ }
2700
+ async get(scheduleId) {
2701
+ return this.http.request({
2702
+ method: "GET",
2703
+ path: `/schedules/${encodeURIComponent(this.projectId)}/${encodeURIComponent(scheduleId)}`,
2704
+ authenticated: true
2705
+ });
2706
+ }
2707
+ async list(options = {}) {
2708
+ return this.http.request({
2709
+ method: "GET",
2710
+ path: `/schedules/${encodeURIComponent(this.projectId)}`,
2711
+ query: {
2712
+ functionId: options.functionId,
2713
+ status: options.status,
2714
+ limit: options.limit,
2715
+ offset: options.offset
2716
+ },
2717
+ authenticated: true
2718
+ });
2719
+ }
2720
+ async cancel(scheduleId) {
2721
+ return this.http.request({
2722
+ method: "DELETE",
2723
+ path: `/schedules/${encodeURIComponent(this.projectId)}/${encodeURIComponent(scheduleId)}`,
2724
+ authenticated: true
2725
+ });
2726
+ }
2727
+ toIsoString(input) {
2728
+ if (input instanceof Date) return input.toISOString();
2729
+ if (typeof input === "number") return new Date(input).toISOString();
2730
+ return input;
2731
+ }
2732
+ };
2733
+
2675
2734
  // libs/sdk/src/client.ts
2676
2735
  function createClient(config) {
2677
2736
  const tokenStorage = config.tokenStorage ?? (typeof window !== "undefined" && typeof window.localStorage !== "undefined" ? new BrowserTokenStorage() : new MemoryTokenStorage());
@@ -2690,12 +2749,14 @@ function createClient(config) {
2690
2749
  const db = new DatabaseModule(httpClient, config.projectId, realtime);
2691
2750
  const notifications = new NotificationsModule(httpClient);
2692
2751
  const functions = new FunctionsModule(httpClient);
2752
+ const schedule = new ScheduleModule(httpClient, config.projectId);
2693
2753
  return {
2694
2754
  auth,
2695
2755
  storage,
2696
2756
  db,
2697
2757
  notifications,
2698
2758
  functions,
2759
+ schedule,
2699
2760
  setTokens(tokens) {
2700
2761
  return tokenManager.setTokens(tokens);
2701
2762
  },