mneme-sdk 0.1.0 → 0.3.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.cjs CHANGED
@@ -140,6 +140,25 @@ var Mneme = class {
140
140
  from(table) {
141
141
  return new Collection(this, table);
142
142
  }
143
+ /**
144
+ * Run raw SQL against your project's Postgres schema.
145
+ *
146
+ * Safety guards (server-side):
147
+ * - 5-second statement timeout
148
+ * - search_path pinned to your schema (unqualified table refs resolve to YOUR schema)
149
+ * - cross-tenant schema references are blocked
150
+ * - 1000-row result cap
151
+ * - single statement only
152
+ *
153
+ * Returns rows, column metadata, and elapsed time.
154
+ *
155
+ * @example
156
+ * await m.sql("SELECT count(*) FROM memories");
157
+ * await m.sql("CREATE INDEX ON books (rating)");
158
+ */
159
+ sql(query) {
160
+ return this.request("POST", "/v1/sql", { query });
161
+ }
143
162
  // ─── Storage (Cloudflare R2 backend, $MNEME burn quota) ──────────────────
144
163
  storage = {
145
164
  upload: async (args) => {
@@ -220,6 +239,7 @@ var Collection = class {
220
239
  }
221
240
  mneme;
222
241
  table;
242
+ /** Insert one row or an array of rows. Returns the inserted rows. */
223
243
  insert(rows) {
224
244
  return this.mneme.request(
225
245
  "POST",
@@ -227,14 +247,54 @@ var Collection = class {
227
247
  rows
228
248
  );
229
249
  }
250
+ /**
251
+ * List rows. Supports filtering with `where` (PostgREST-style col.op.value),
252
+ * ordering with `order` (e.g. "created_at.desc"), and pagination.
253
+ *
254
+ * Ops: eq, neq, gt, gte, lt, lte, like, ilike, in, is.
255
+ * Example: `m.from("todos").list({ where: ["done.eq.false"], order: "created_at.desc" })`
256
+ */
230
257
  list(opts) {
231
258
  const q = new URLSearchParams();
232
259
  if (opts?.limit != null) q.set("limit", String(opts.limit));
233
260
  if (opts?.offset != null) q.set("offset", String(opts.offset));
234
261
  if (opts?.order) q.set("order", opts.order);
262
+ if (opts?.where) {
263
+ const ws = Array.isArray(opts.where) ? opts.where : [opts.where];
264
+ for (const w of ws) q.append("where", w);
265
+ }
235
266
  const qs = q.toString() ? `?${q}` : "";
236
267
  return this.mneme.request("GET", `/v1/rows/${this.table}${qs}`);
237
268
  }
269
+ /** Update one row by id. Returns the updated row. */
270
+ update(id, updates) {
271
+ return this.mneme.request(
272
+ "PATCH",
273
+ `/v1/rows/${this.table}/${id}`,
274
+ updates
275
+ );
276
+ }
277
+ /** Delete one row by id. */
278
+ delete(id) {
279
+ return this.mneme.request(
280
+ "DELETE",
281
+ `/v1/rows/${this.table}/${id}`
282
+ );
283
+ }
284
+ /**
285
+ * Bulk delete by filter. Refuses to delete the whole table — at least one
286
+ * where clause is required. Returns the count of deleted rows.
287
+ */
288
+ deleteWhere(where) {
289
+ const ws = Array.isArray(where) ? where : [where];
290
+ if (ws.length === 0) throw new Error("deleteWhere requires at least one filter");
291
+ const q = new URLSearchParams();
292
+ for (const w of ws) q.append("where", w);
293
+ return this.mneme.request(
294
+ "DELETE",
295
+ `/v1/rows/${this.table}?${q}`
296
+ );
297
+ }
238
298
  };
239
299
 
240
300
  // src/types.ts
package/dist/index.d.cts CHANGED
@@ -112,6 +112,29 @@ declare class Mneme {
112
112
  }>;
113
113
  stats(): Promise<StatsResponse>;
114
114
  from<T = unknown>(table: string): Collection<T>;
115
+ /**
116
+ * Run raw SQL against your project's Postgres schema.
117
+ *
118
+ * Safety guards (server-side):
119
+ * - 5-second statement timeout
120
+ * - search_path pinned to your schema (unqualified table refs resolve to YOUR schema)
121
+ * - cross-tenant schema references are blocked
122
+ * - 1000-row result cap
123
+ * - single statement only
124
+ *
125
+ * Returns rows, column metadata, and elapsed time.
126
+ *
127
+ * @example
128
+ * await m.sql("SELECT count(*) FROM memories");
129
+ * await m.sql("CREATE INDEX ON books (rating)");
130
+ */
131
+ sql<T = Record<string, unknown>>(query: string): Promise<{
132
+ rows: T[];
133
+ row_count: number;
134
+ columns: string[];
135
+ truncated: boolean;
136
+ elapsed_ms: number;
137
+ }>;
115
138
  readonly storage: {
116
139
  upload: (args: {
117
140
  key: string;
@@ -183,20 +206,49 @@ declare class Mneme {
183
206
  };
184
207
  request<T = unknown>(method: string, path: string, body?: unknown): Promise<T>;
185
208
  }
209
+ /** PostgREST-ish where clause. e.g. `["status.eq.done", "score.gt.10"]`. */
210
+ type WhereClause = string;
186
211
  declare class Collection<T = unknown> {
187
212
  private mneme;
188
213
  readonly table: string;
189
214
  constructor(mneme: Mneme, table: string);
215
+ /** Insert one row or an array of rows. Returns the inserted rows. */
190
216
  insert(rows: T | T[]): Promise<{
191
217
  inserted: number;
192
218
  rows: T[];
193
219
  }>;
220
+ /**
221
+ * List rows. Supports filtering with `where` (PostgREST-style col.op.value),
222
+ * ordering with `order` (e.g. "created_at.desc"), and pagination.
223
+ *
224
+ * Ops: eq, neq, gt, gte, lt, lte, like, ilike, in, is.
225
+ * Example: `m.from("todos").list({ where: ["done.eq.false"], order: "created_at.desc" })`
226
+ */
194
227
  list(opts?: {
195
228
  limit?: number;
196
229
  offset?: number;
197
230
  order?: string;
231
+ where?: WhereClause | WhereClause[];
198
232
  }): Promise<{
199
233
  rows: T[];
234
+ count: number;
235
+ }>;
236
+ /** Update one row by id. Returns the updated row. */
237
+ update(id: string | number, updates: Partial<T>): Promise<{
238
+ updated: 1;
239
+ row: T;
240
+ }>;
241
+ /** Delete one row by id. */
242
+ delete(id: string | number): Promise<{
243
+ deleted: 1;
244
+ id: number | string;
245
+ }>;
246
+ /**
247
+ * Bulk delete by filter. Refuses to delete the whole table — at least one
248
+ * where clause is required. Returns the count of deleted rows.
249
+ */
250
+ deleteWhere(where: WhereClause | WhereClause[]): Promise<{
251
+ deleted: number;
200
252
  }>;
201
253
  }
202
254
 
package/dist/index.d.ts CHANGED
@@ -112,6 +112,29 @@ declare class Mneme {
112
112
  }>;
113
113
  stats(): Promise<StatsResponse>;
114
114
  from<T = unknown>(table: string): Collection<T>;
115
+ /**
116
+ * Run raw SQL against your project's Postgres schema.
117
+ *
118
+ * Safety guards (server-side):
119
+ * - 5-second statement timeout
120
+ * - search_path pinned to your schema (unqualified table refs resolve to YOUR schema)
121
+ * - cross-tenant schema references are blocked
122
+ * - 1000-row result cap
123
+ * - single statement only
124
+ *
125
+ * Returns rows, column metadata, and elapsed time.
126
+ *
127
+ * @example
128
+ * await m.sql("SELECT count(*) FROM memories");
129
+ * await m.sql("CREATE INDEX ON books (rating)");
130
+ */
131
+ sql<T = Record<string, unknown>>(query: string): Promise<{
132
+ rows: T[];
133
+ row_count: number;
134
+ columns: string[];
135
+ truncated: boolean;
136
+ elapsed_ms: number;
137
+ }>;
115
138
  readonly storage: {
116
139
  upload: (args: {
117
140
  key: string;
@@ -183,20 +206,49 @@ declare class Mneme {
183
206
  };
184
207
  request<T = unknown>(method: string, path: string, body?: unknown): Promise<T>;
185
208
  }
209
+ /** PostgREST-ish where clause. e.g. `["status.eq.done", "score.gt.10"]`. */
210
+ type WhereClause = string;
186
211
  declare class Collection<T = unknown> {
187
212
  private mneme;
188
213
  readonly table: string;
189
214
  constructor(mneme: Mneme, table: string);
215
+ /** Insert one row or an array of rows. Returns the inserted rows. */
190
216
  insert(rows: T | T[]): Promise<{
191
217
  inserted: number;
192
218
  rows: T[];
193
219
  }>;
220
+ /**
221
+ * List rows. Supports filtering with `where` (PostgREST-style col.op.value),
222
+ * ordering with `order` (e.g. "created_at.desc"), and pagination.
223
+ *
224
+ * Ops: eq, neq, gt, gte, lt, lte, like, ilike, in, is.
225
+ * Example: `m.from("todos").list({ where: ["done.eq.false"], order: "created_at.desc" })`
226
+ */
194
227
  list(opts?: {
195
228
  limit?: number;
196
229
  offset?: number;
197
230
  order?: string;
231
+ where?: WhereClause | WhereClause[];
198
232
  }): Promise<{
199
233
  rows: T[];
234
+ count: number;
235
+ }>;
236
+ /** Update one row by id. Returns the updated row. */
237
+ update(id: string | number, updates: Partial<T>): Promise<{
238
+ updated: 1;
239
+ row: T;
240
+ }>;
241
+ /** Delete one row by id. */
242
+ delete(id: string | number): Promise<{
243
+ deleted: 1;
244
+ id: number | string;
245
+ }>;
246
+ /**
247
+ * Bulk delete by filter. Refuses to delete the whole table — at least one
248
+ * where clause is required. Returns the count of deleted rows.
249
+ */
250
+ deleteWhere(where: WhereClause | WhereClause[]): Promise<{
251
+ deleted: number;
200
252
  }>;
201
253
  }
202
254
 
package/dist/index.js CHANGED
@@ -108,6 +108,25 @@ var Mneme = class {
108
108
  from(table) {
109
109
  return new Collection(this, table);
110
110
  }
111
+ /**
112
+ * Run raw SQL against your project's Postgres schema.
113
+ *
114
+ * Safety guards (server-side):
115
+ * - 5-second statement timeout
116
+ * - search_path pinned to your schema (unqualified table refs resolve to YOUR schema)
117
+ * - cross-tenant schema references are blocked
118
+ * - 1000-row result cap
119
+ * - single statement only
120
+ *
121
+ * Returns rows, column metadata, and elapsed time.
122
+ *
123
+ * @example
124
+ * await m.sql("SELECT count(*) FROM memories");
125
+ * await m.sql("CREATE INDEX ON books (rating)");
126
+ */
127
+ sql(query) {
128
+ return this.request("POST", "/v1/sql", { query });
129
+ }
111
130
  // ─── Storage (Cloudflare R2 backend, $MNEME burn quota) ──────────────────
112
131
  storage = {
113
132
  upload: async (args) => {
@@ -188,6 +207,7 @@ var Collection = class {
188
207
  }
189
208
  mneme;
190
209
  table;
210
+ /** Insert one row or an array of rows. Returns the inserted rows. */
191
211
  insert(rows) {
192
212
  return this.mneme.request(
193
213
  "POST",
@@ -195,14 +215,54 @@ var Collection = class {
195
215
  rows
196
216
  );
197
217
  }
218
+ /**
219
+ * List rows. Supports filtering with `where` (PostgREST-style col.op.value),
220
+ * ordering with `order` (e.g. "created_at.desc"), and pagination.
221
+ *
222
+ * Ops: eq, neq, gt, gte, lt, lte, like, ilike, in, is.
223
+ * Example: `m.from("todos").list({ where: ["done.eq.false"], order: "created_at.desc" })`
224
+ */
198
225
  list(opts) {
199
226
  const q = new URLSearchParams();
200
227
  if (opts?.limit != null) q.set("limit", String(opts.limit));
201
228
  if (opts?.offset != null) q.set("offset", String(opts.offset));
202
229
  if (opts?.order) q.set("order", opts.order);
230
+ if (opts?.where) {
231
+ const ws = Array.isArray(opts.where) ? opts.where : [opts.where];
232
+ for (const w of ws) q.append("where", w);
233
+ }
203
234
  const qs = q.toString() ? `?${q}` : "";
204
235
  return this.mneme.request("GET", `/v1/rows/${this.table}${qs}`);
205
236
  }
237
+ /** Update one row by id. Returns the updated row. */
238
+ update(id, updates) {
239
+ return this.mneme.request(
240
+ "PATCH",
241
+ `/v1/rows/${this.table}/${id}`,
242
+ updates
243
+ );
244
+ }
245
+ /** Delete one row by id. */
246
+ delete(id) {
247
+ return this.mneme.request(
248
+ "DELETE",
249
+ `/v1/rows/${this.table}/${id}`
250
+ );
251
+ }
252
+ /**
253
+ * Bulk delete by filter. Refuses to delete the whole table — at least one
254
+ * where clause is required. Returns the count of deleted rows.
255
+ */
256
+ deleteWhere(where) {
257
+ const ws = Array.isArray(where) ? where : [where];
258
+ if (ws.length === 0) throw new Error("deleteWhere requires at least one filter");
259
+ const q = new URLSearchParams();
260
+ for (const w of ws) q.append("where", w);
261
+ return this.mneme.request(
262
+ "DELETE",
263
+ `/v1/rows/${this.table}?${q}`
264
+ );
265
+ }
206
266
  };
207
267
 
208
268
  // src/types.ts
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mneme-sdk",
3
- "version": "0.1.0",
4
- "description": "TypeScript SDK for Mneme — agent-native Postgres + R2 storage on Base. Wallet-auth, runtime DDL, pgvector, wallet-bound files with $MNEME burn quota.",
3
+ "version": "0.3.0",
4
+ "description": "TypeScript SDK for Mneme — agent-native Postgres + R2 storage on Base. Wallet-auth, runtime DDL, full CRUD with WHERE filters, raw SQL, pgvector, wallet-bound files with $MNEME burn quota.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",