@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.mjs CHANGED
@@ -6261,7 +6261,7 @@ var Runtype = class {
6261
6261
 
6262
6262
  // src/version.ts
6263
6263
  var FALLBACK_VERSION = "0.0.0";
6264
- var SDK_VERSION = "6.5.1".length > 0 ? "6.5.1" : FALLBACK_VERSION;
6264
+ var SDK_VERSION = "6.6.1".length > 0 ? "6.6.1" : FALLBACK_VERSION;
6265
6265
  var RUNTYPE_CLIENT_KIND = "sdk";
6266
6266
  var SDK_USER_AGENT = `runtype-sdk/${SDK_VERSION} (typescript)`;
6267
6267
 
@@ -8508,6 +8508,69 @@ var RecordsEndpoint = class {
8508
8508
  limit: 1
8509
8509
  });
8510
8510
  }
8511
+ /**
8512
+ * Scope record operations to a single collection slug, typing `metadata`
8513
+ * against the customer-augmented `RecordCollections` map (§5.1). The returned
8514
+ * scope pins the record `type` filter to `slug` and types `.list/.get/.create/
8515
+ * .update` metadata as `CollectionMeta<S>`.
8516
+ *
8517
+ * @example
8518
+ * ```ts
8519
+ * const customers = client.records.from('customers')
8520
+ * await customers.create({ name: 'Acme', metadata: { tier: 'pro' } })
8521
+ * ```
8522
+ */
8523
+ from(slug) {
8524
+ return new TypedRecordsScope(this.client, slug);
8525
+ }
8526
+ };
8527
+ var TypedRecordsScope = class {
8528
+ constructor(client, slug) {
8529
+ this.client = client;
8530
+ this.slug = slug;
8531
+ }
8532
+ /** List records of this collection (the `type` filter is pinned to the slug). */
8533
+ async list(params) {
8534
+ return this.client.get("/records", {
8535
+ ...params,
8536
+ type: this.slug
8537
+ });
8538
+ }
8539
+ /**
8540
+ * Get a record of this collection by id. Throws if the fetched record belongs
8541
+ * to a different collection — otherwise `metadata` would be mistyped as this
8542
+ * scope's shape. Use `client.records.get()` for cross-collection reads.
8543
+ */
8544
+ async get(id) {
8545
+ const record = await this.client.get(`/records/${id}`);
8546
+ const type = record.type;
8547
+ if (type !== void 0 && type !== this.slug) throw this.typeMismatchError(id, type);
8548
+ return record;
8549
+ }
8550
+ /** Create a record in this collection (`type` is supplied from the slug). */
8551
+ async create(data) {
8552
+ return this.client.post("/records", {
8553
+ ...data,
8554
+ type: this.slug
8555
+ });
8556
+ }
8557
+ /**
8558
+ * Update a record in this collection. Guards BEFORE writing with a GET: this
8559
+ * scope's `metadata` type must not be written onto a record of another
8560
+ * collection, so a cross-collection id throws instead of mutating. That costs
8561
+ * one extra request; use `client.records.update()` to skip the guard.
8562
+ */
8563
+ async update(id, data) {
8564
+ const existing = await this.client.get(`/records/${id}`);
8565
+ const type = existing?.type;
8566
+ if (type !== void 0 && type !== this.slug) throw this.typeMismatchError(id, type);
8567
+ return this.client.put(`/records/${id}`, data);
8568
+ }
8569
+ typeMismatchError(id, actualType) {
8570
+ return new Error(
8571
+ `Record ${id} belongs to collection "${actualType}", not "${this.slug}". Use client.records.from("${actualType}") or the untyped client.records methods for cross-collection access.`
8572
+ );
8573
+ }
8511
8574
  };
8512
8575
  var CollectionsEndpoint = class {
8513
8576
  constructor(client) {
@@ -8571,6 +8634,15 @@ var CollectionsEndpoint = class {
8571
8634
  data ?? {}
8572
8635
  );
8573
8636
  }
8637
+ /**
8638
+ * Fetch generated TypeScript declarations for the account's schematized
8639
+ * collections (`GET /v1/collections/types.d.ts`) as a raw `.d.ts` string.
8640
+ * Powers `runtype records typegen`; write it to a file and augment the SDK's
8641
+ * `RecordCollections` map so `client.records.from(slug)` types metadata.
8642
+ */
8643
+ async typegen() {
8644
+ return this.client.get("/collections/types.d.ts");
8645
+ }
8574
8646
  };
8575
8647
  var ApiKeysEndpoint = class {
8576
8648
  constructor(client) {
@@ -14055,6 +14127,7 @@ export {
14055
14127
  ToolEnsureConflictError,
14056
14128
  ToolsEndpoint,
14057
14129
  ToolsNamespace,
14130
+ TypedRecordsScope,
14058
14131
  UNIFIED_EVENTS_QUERY,
14059
14132
  UsersEndpoint,
14060
14133
  applyGeneratedRuntimeToolProposalToDispatchRequest,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runtypelabs/sdk",
3
- "version": "6.5.1",
3
+ "version": "6.6.1",
4
4
  "type": "module",
5
5
  "description": "TypeScript SDK for the Runtype API with fluent methods. Use it to quickly realize AI products, agents, and workflows.",
6
6
  "main": "dist/index.cjs",