@runtypelabs/sdk 6.5.1 → 6.6.1

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.cjs CHANGED
@@ -89,6 +89,7 @@ __export(index_exports, {
89
89
  ToolEnsureConflictError: () => ToolEnsureConflictError,
90
90
  ToolsEndpoint: () => ToolsEndpoint,
91
91
  ToolsNamespace: () => ToolsNamespace,
92
+ TypedRecordsScope: () => TypedRecordsScope,
92
93
  UNIFIED_EVENTS_QUERY: () => UNIFIED_EVENTS_QUERY,
93
94
  UsersEndpoint: () => UsersEndpoint,
94
95
  applyGeneratedRuntimeToolProposalToDispatchRequest: () => applyGeneratedRuntimeToolProposalToDispatchRequest,
@@ -6448,7 +6449,7 @@ var Runtype = class {
6448
6449
 
6449
6450
  // src/version.ts
6450
6451
  var FALLBACK_VERSION = "0.0.0";
6451
- var SDK_VERSION = "6.5.1".length > 0 ? "6.5.1" : FALLBACK_VERSION;
6452
+ var SDK_VERSION = "6.6.1".length > 0 ? "6.6.1" : FALLBACK_VERSION;
6452
6453
  var RUNTYPE_CLIENT_KIND = "sdk";
6453
6454
  var SDK_USER_AGENT = `runtype-sdk/${SDK_VERSION} (typescript)`;
6454
6455
 
@@ -8695,6 +8696,69 @@ var RecordsEndpoint = class {
8695
8696
  limit: 1
8696
8697
  });
8697
8698
  }
8699
+ /**
8700
+ * Scope record operations to a single collection slug, typing `metadata`
8701
+ * against the customer-augmented `RecordCollections` map (§5.1). The returned
8702
+ * scope pins the record `type` filter to `slug` and types `.list/.get/.create/
8703
+ * .update` metadata as `CollectionMeta<S>`.
8704
+ *
8705
+ * @example
8706
+ * ```ts
8707
+ * const customers = client.records.from('customers')
8708
+ * await customers.create({ name: 'Acme', metadata: { tier: 'pro' } })
8709
+ * ```
8710
+ */
8711
+ from(slug) {
8712
+ return new TypedRecordsScope(this.client, slug);
8713
+ }
8714
+ };
8715
+ var TypedRecordsScope = class {
8716
+ constructor(client, slug) {
8717
+ this.client = client;
8718
+ this.slug = slug;
8719
+ }
8720
+ /** List records of this collection (the `type` filter is pinned to the slug). */
8721
+ async list(params) {
8722
+ return this.client.get("/records", {
8723
+ ...params,
8724
+ type: this.slug
8725
+ });
8726
+ }
8727
+ /**
8728
+ * Get a record of this collection by id. Throws if the fetched record belongs
8729
+ * to a different collection — otherwise `metadata` would be mistyped as this
8730
+ * scope's shape. Use `client.records.get()` for cross-collection reads.
8731
+ */
8732
+ async get(id) {
8733
+ const record = await this.client.get(`/records/${id}`);
8734
+ const type = record.type;
8735
+ if (type !== void 0 && type !== this.slug) throw this.typeMismatchError(id, type);
8736
+ return record;
8737
+ }
8738
+ /** Create a record in this collection (`type` is supplied from the slug). */
8739
+ async create(data) {
8740
+ return this.client.post("/records", {
8741
+ ...data,
8742
+ type: this.slug
8743
+ });
8744
+ }
8745
+ /**
8746
+ * Update a record in this collection. Guards BEFORE writing with a GET: this
8747
+ * scope's `metadata` type must not be written onto a record of another
8748
+ * collection, so a cross-collection id throws instead of mutating. That costs
8749
+ * one extra request; use `client.records.update()` to skip the guard.
8750
+ */
8751
+ async update(id, data) {
8752
+ const existing = await this.client.get(`/records/${id}`);
8753
+ const type = existing?.type;
8754
+ if (type !== void 0 && type !== this.slug) throw this.typeMismatchError(id, type);
8755
+ return this.client.put(`/records/${id}`, data);
8756
+ }
8757
+ typeMismatchError(id, actualType) {
8758
+ return new Error(
8759
+ `Record ${id} belongs to collection "${actualType}", not "${this.slug}". Use client.records.from("${actualType}") or the untyped client.records methods for cross-collection access.`
8760
+ );
8761
+ }
8698
8762
  };
8699
8763
  var CollectionsEndpoint = class {
8700
8764
  constructor(client) {
@@ -8758,6 +8822,15 @@ var CollectionsEndpoint = class {
8758
8822
  data ?? {}
8759
8823
  );
8760
8824
  }
8825
+ /**
8826
+ * Fetch generated TypeScript declarations for the account's schematized
8827
+ * collections (`GET /v1/collections/types.d.ts`) as a raw `.d.ts` string.
8828
+ * Powers `runtype records typegen`; write it to a file and augment the SDK's
8829
+ * `RecordCollections` map so `client.records.from(slug)` types metadata.
8830
+ */
8831
+ async typegen() {
8832
+ return this.client.get("/collections/types.d.ts");
8833
+ }
8761
8834
  };
8762
8835
  var ApiKeysEndpoint = class {
8763
8836
  constructor(client) {
@@ -14243,6 +14316,7 @@ var STEP_TYPE_TO_METHOD = {
14243
14316
  ToolEnsureConflictError,
14244
14317
  ToolsEndpoint,
14245
14318
  ToolsNamespace,
14319
+ TypedRecordsScope,
14246
14320
  UNIFIED_EVENTS_QUERY,
14247
14321
  UsersEndpoint,
14248
14322
  applyGeneratedRuntimeToolProposalToDispatchRequest,