@freehour/supabase-core 1.5.4 → 1.6.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.
@@ -1,11 +1,10 @@
1
- import { Embedding, EmbeddingPreprocessingStep, EmbeddingSynchronizationResult, FileMetadata, Metadata, MetadataGeneratorFn } from './embedding';
1
+ import { Embedding, EmbeddingSynchronizationResult, Metadata, MetadataGeneratorFn } from './embedding';
2
2
  import { FileRef, StorageLocation } from './storage';
3
3
  import { StorageService } from './storage-service';
4
4
  export interface EmbeddingServiceParams<BucketName extends string = string> {
5
5
  storage: StorageService<BucketName>;
6
6
  }
7
7
  export declare abstract class EmbeddingService<BucketName extends string = string> {
8
- private readonly preprocesses;
9
8
  protected readonly storage: StorageService<BucketName>;
10
9
  constructor({ storage, }: EmbeddingServiceParams<BucketName>);
11
10
  /**
@@ -24,7 +23,7 @@ export declare abstract class EmbeddingService<BucketName extends string = strin
24
23
  * @param metadata Additional metadata to store with the embedding.
25
24
  * @return An array of generated embeddings.
26
25
  */
27
- protected abstract createEmbeddings(location: StorageLocation, text: string, file: FileMetadata, metadata?: Metadata): Promise<Embedding[]>;
26
+ protected abstract createEmbeddings(location: StorageLocation, metadata?: Metadata): Promise<Embedding[]>;
28
27
  /**
29
28
  * Delete the embeddings associated with the given file reference.
30
29
  *
@@ -40,9 +39,6 @@ export declare abstract class EmbeddingService<BucketName extends string = strin
40
39
  * @returns A promise that resolves to an array of file references with outdated embeddings.
41
40
  */
42
41
  protected getOutdatedEmbeddings(bucket: BucketName): Promise<FileRef<BucketName>[]>;
43
- private preprocess;
44
- addPreprocessingStep(preprocess: EmbeddingPreprocessingStep): this;
45
- removePreprocessingStep(name: string): this;
46
42
  get(fileRef: FileRef<BucketName>): Promise<Embedding[]>;
47
43
  ingest(fileRef: FileRef<BucketName>, metadata?: Metadata | MetadataGeneratorFn): Promise<Embedding[]>;
48
44
  synchronize(bucket: BucketName, metadata?: Metadata | MetadataGeneratorFn):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AE,CAAC;IAEjF;;;;;;;;OAQG;IACH,SAAS,CAAC,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,EAAE,eAAe,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAEzG;;;;OAIG;IACH,SAAS,CAAC,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAE7E;;;;;;;OAOG;cACa,qBAAqB,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;IA4BnF,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAKvD,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,mBAAmB,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAarG,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,mBAAmB,GAAG,OAAO,CAAC,8BAA8B,EAAE,CAAC;CA2B9H"}
@@ -2,7 +2,7 @@ import { MimeString } from '@freehour/mime';
2
2
  import { Json } from './json';
3
3
  import { FileRef, StorageLocation } from './storage';
4
4
  export type Metadata = Record<string, Json>;
5
- export type MetadataGeneratorFn = (file: File, location: StorageLocation) => Metadata;
5
+ export type MetadataGeneratorFn = (location: StorageLocation) => Metadata;
6
6
  export interface FileMetadata {
7
7
  name: string;
8
8
  type: MimeString;
@@ -25,9 +25,4 @@ export interface EmbeddingSynchronizationFailure {
25
25
  error: Error;
26
26
  }
27
27
  export type EmbeddingSynchronizationResult = EmbeddingSynchronizationSuccess | EmbeddingSynchronizationFailure;
28
- export interface EmbeddingPreprocessingStep {
29
- name: string;
30
- run: (text: string, metadata: FileMetadata) => string;
31
- }
32
- export declare const preprocessingSteps: Record<string, EmbeddingPreprocessingStep>;
33
28
  //# sourceMappingURL=embedding.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"embedding.d.ts","sourceRoot":"","sources":["../lib/embedding.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAG1D,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAC5C,MAAM,MAAM,mBAAmB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,eAAe,KAAK,QAAQ,CAAC;AAEtF,MAAM,WAAW,YAAY;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,SAAU,SAAQ,eAAe;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,EAAE,QAAQ,CAAC;IACnB,SAAS,EAAE,IAAI,CAAC;CACnB;AAED,MAAM,WAAW,+BAA+B;IAC5C,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,IAAI,CAAC;IACd,KAAK,EAAE,IAAI,CAAC;CACf;AAED,MAAM,WAAW,+BAA+B;IAC5C,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,KAAK,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;CAChB;AAED,MAAM,MAAM,8BAA8B,GAAG,+BAA+B,GAAG,+BAA+B,CAAC;AAE/G,MAAM,WAAW,0BAA0B;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,KAAK,MAAM,CAAC;CACzD;AAED,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,0BAA0B,CAwBzE,CAAC"}
1
+ {"version":3,"file":"embedding.d.ts","sourceRoot":"","sources":["../lib/embedding.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAG1D,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAC5C,MAAM,MAAM,mBAAmB,GAAG,CAAC,QAAQ,EAAE,eAAe,KAAK,QAAQ,CAAC;AAE1E,MAAM,WAAW,YAAY;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,SAAU,SAAQ,eAAe;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,EAAE,QAAQ,CAAC;IACnB,SAAS,EAAE,IAAI,CAAC;CACnB;AAED,MAAM,WAAW,+BAA+B;IAC5C,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,IAAI,CAAC;IACd,KAAK,EAAE,IAAI,CAAC;CACf;AAED,MAAM,WAAW,+BAA+B;IAC5C,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,KAAK,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;CAChB;AAED,MAAM,MAAM,8BAA8B,GAAG,+BAA+B,GAAG,+BAA+B,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,12 +1,13 @@
1
1
  export * from './data-service';
2
2
  export type * from './database';
3
3
  export * from './database-service';
4
- export * from './embedding';
4
+ export type * from './embedding';
5
5
  export * from './embedding-service';
6
6
  export * from './errors';
7
7
  export * from './filter';
8
8
  export type * from './json';
9
9
  export * from './postgrest';
10
+ export * from './processing';
10
11
  export type * from './storage';
11
12
  export * from './storage-service';
12
13
  export * from './utils';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,mBAAmB,YAAY,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,mBAAmB,QAAQ,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,mBAAmB,WAAW,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,mBAAmB,YAAY,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,mBAAmB,aAAa,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,mBAAmB,QAAQ,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,mBAAmB,WAAW,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -2,73 +2,72 @@ import { assert as e } from "@freehour/assert";
2
2
  import t from "zod";
3
3
  import { PostgrestError as n } from "@supabase/supabase-js";
4
4
  import * as r from "@supabase/postgrest-js";
5
- import { Mime as i } from "@freehour/mime";
6
5
  //#region lib/errors.ts
7
- var a = class extends Error {
6
+ var i = class extends Error {
8
7
  constructor(e, t = {}) {
9
8
  super(e, t), this.name = this.constructor.name, Error.captureStackTrace(this, this.constructor);
10
9
  }
11
- }, o = class extends a {
10
+ }, a = class extends i {
12
11
  fileId;
13
12
  bucket;
14
13
  path;
15
14
  constructor(e, { fileId: t, bucket: n, path: r } = {}) {
16
15
  super(e), this.fileId = t, this.bucket = n, this.path = r;
17
16
  }
18
- }, s = class extends a {
17
+ }, o = class extends i {
19
18
  expression;
20
19
  format;
21
20
  constructor(e, { expression: t, format: n, ...r } = {}) {
22
21
  super(e, r), this.expression = t, this.format = n;
23
22
  }
24
- }, c = class extends a {
23
+ }, s = class extends i {
25
24
  schema;
26
25
  relation;
27
26
  id;
28
27
  constructor(e, { schema: t, relation: n, id: r } = {}) {
29
28
  super(e), this.schema = t, this.relation = n, this.id = r;
30
29
  }
31
- }, l = class extends Error {
30
+ }, c = class extends Error {
32
31
  value;
33
32
  supported;
34
33
  constructor(e, { value: t, supported: n, ...r } = {}) {
35
34
  super(e, r), this.value = t, this.supported = n;
36
35
  }
37
- }, u = t.object({
36
+ }, l = t.object({
38
37
  code: t.string(),
39
38
  details: t.string().nullable(),
40
39
  hint: t.string().nullable(),
41
40
  name: t.string().optional(),
42
41
  message: t.string().optional()
43
42
  });
44
- function d(e) {
45
- return e instanceof n || u.safeParse(e).success;
43
+ function u(e) {
44
+ return e instanceof n || l.safeParse(e).success;
46
45
  }
47
46
  //#endregion
48
47
  //#region lib/utils.ts
49
- function f(e, t = "/") {
48
+ function d(e, t = "/") {
50
49
  let n = e.lastIndexOf(t);
51
50
  return n === -1 ? ["", e] : [e.substring(0, n), e.substring(n + 1)];
52
51
  }
53
- function p(e) {
52
+ function f(e) {
54
53
  return Array.isArray(e) ? e : [e];
55
54
  }
56
- function m(e, t) {
55
+ function p(e, t) {
57
56
  return e.reduce((e, n) => {
58
57
  let r = t(n);
59
58
  return (e[r] ??= []).push(n), e;
60
59
  }, {});
61
60
  }
62
- function h(e, t) {
61
+ function m(e, t) {
63
62
  let n = e.findIndex(t);
64
63
  return n !== -1 && e.splice(n, 1), e;
65
64
  }
66
- function g(e) {
65
+ function h(e) {
67
66
  return Object.entries(e);
68
67
  }
69
68
  //#endregion
70
69
  //#region lib/data-service.ts
71
- var _ = class {
70
+ var g = class {
72
71
  database;
73
72
  schema;
74
73
  relation;
@@ -76,7 +75,7 @@ var _ = class {
76
75
  this.database = e, this.schema = t, this.relation = n;
77
76
  }
78
77
  recordNotFoundError(e) {
79
- return new c(`Record with id ${e} not found in ${this.schema}.${this.relation}`, {
78
+ return new s(`Record with id ${e} not found in ${this.schema}.${this.relation}`, {
80
79
  schema: this.schema,
81
80
  relation: this.relation,
82
81
  id: e
@@ -124,7 +123,7 @@ var _ = class {
124
123
  }
125
124
  async upsert(e, { onConflict: t, ...n } = {}) {
126
125
  let { data: r } = await this.query.upsert(e, {
127
- onConflict: t === void 0 ? void 0 : p(t).join(","),
126
+ onConflict: t === void 0 ? void 0 : f(t).join(","),
128
127
  ...n
129
128
  }).select().single().throwOnError();
130
129
  return r;
@@ -133,7 +132,7 @@ var _ = class {
133
132
  let { data: n } = await this.query.update(t).eq("id", e).select().single().throwOnError();
134
133
  return n;
135
134
  }
136
- }, v = class extends _ {
135
+ }, _ = class extends g {
137
136
  constructor({ database: e, schema: t, table: n }) {
138
137
  super({
139
138
  database: e,
@@ -141,7 +140,7 @@ var _ = class {
141
140
  relation: n
142
141
  });
143
142
  }
144
- }, y = class extends _ {
143
+ }, v = class extends g {
145
144
  constructor({ database: e, schema: t, view: n }) {
146
145
  super({
147
146
  database: e,
@@ -150,13 +149,13 @@ var _ = class {
150
149
  });
151
150
  }
152
151
  };
153
- function b(t) {
152
+ function y(t) {
154
153
  if (t.error) throw t.error;
155
154
  return e(t.count !== null, "Response does not contain a count. Make sure to set the `count` option in the request."), t;
156
155
  }
157
156
  //#endregion
158
157
  //#region lib/filter.ts
159
- var x = [
158
+ var b = [
160
159
  "eq",
161
160
  "neq",
162
161
  "gt",
@@ -182,17 +181,17 @@ var x = [
182
181
  "nxr",
183
182
  "nxl",
184
183
  "adj"
185
- ], S = ["and", "or"], C = ",", w = "~", T = (e) => (n = {}) => {
184
+ ], x = ["and", "or"], S = ",", C = "~", w = (e) => (n = {}) => {
186
185
  let r = (e) => n[e] ?? e, i = Object.keys(e.shape);
187
186
  return t.string().transform((e, t) => {
188
187
  try {
189
- return j(e, i, r);
188
+ return A(e, i, r);
190
189
  } catch (n) {
191
190
  return t.addIssue({
192
191
  code: "custom",
193
192
  input: e,
194
193
  message: n instanceof Error ? n.message : void 0,
195
- params: n instanceof s ? {
194
+ params: n instanceof o ? {
196
195
  expression: n.expression,
197
196
  format: n.format
198
197
  } : void 0
@@ -200,26 +199,26 @@ var x = [
200
199
  }
201
200
  });
202
201
  };
203
- function E(e) {
202
+ function T(e) {
204
203
  return e.startsWith("not.") ? e.slice(4) : `not.${e}`;
205
204
  }
206
- function D(e) {
205
+ function E(e) {
207
206
  return {
208
207
  ...e,
209
- op: E(e.op)
208
+ op: T(e.op)
210
209
  };
211
210
  }
212
- function O(e, t = (e) => e) {
211
+ function D(e, t = (e) => e) {
213
212
  if (e.type === "logical") {
214
- let n = e.args.map((e) => O(e, t));
213
+ let n = e.args.map((e) => D(e, t));
215
214
  return `${e.op}(${n})`;
216
215
  }
217
216
  return `${t(e.key)}.${e.op}.${e.value}`;
218
217
  }
219
- function k(e, t = (e) => e, n = "~") {
220
- return e.map((e) => O(e, t)).join(n);
218
+ function O(e, t = (e) => e, n = "~") {
219
+ return e.map((e) => D(e, t)).join(n);
221
220
  }
222
- function A(t, n = [], r = (e) => e) {
221
+ function k(t, n = [], r = (e) => e) {
223
222
  function i(e) {
224
223
  let t = [], n = 0, r = "", i = !1;
225
224
  for (let a of e) a === "\"" ? (i = !i, r += a) : a === "(" && !i ? (n++, r += a) : a === ")" && !i ? (n--, r += a) : a === "," && n === 0 && !i ? (t.push(r.trim()), r = "") : r += a;
@@ -229,34 +228,34 @@ function A(t, n = [], r = (e) => e) {
229
228
  if (t.startsWith("and(")) return {
230
229
  type: "logical",
231
230
  op: "and",
232
- args: i(t.slice(4, -1)).map((e) => A(e, n, r))
231
+ args: i(t.slice(4, -1)).map((e) => k(e, n, r))
233
232
  };
234
233
  if (t.startsWith("or(")) return {
235
234
  type: "logical",
236
235
  op: "or",
237
- args: i(t.slice(3, -1)).map((e) => A(e, n, r))
236
+ args: i(t.slice(3, -1)).map((e) => k(e, n, r))
238
237
  };
239
238
  if (t.startsWith("not.and(")) return {
240
239
  type: "logical",
241
240
  op: "not.and",
242
- args: i(t.slice(8, -1)).map((e) => A(e, n, r))
241
+ args: i(t.slice(8, -1)).map((e) => k(e, n, r))
243
242
  };
244
243
  if (t.startsWith("not.or(")) return {
245
244
  type: "logical",
246
245
  op: "not.or",
247
- args: i(t.slice(7, -1)).map((e) => A(e, n, r))
246
+ args: i(t.slice(7, -1)).map((e) => k(e, n, r))
248
247
  };
249
248
  }
250
- let a = `^(${n.length === 0 ? "[a-zA-Z_][a-zA-Z0-9_]*" : n.join("|")})\\.((?:not\\.)?(?:${x.join("|")}))\\.(.+)$`, o = new RegExp(a).exec(t);
251
- if (!o) throw new s(`Invalid filter expression '${t}'`, {
249
+ let a = `^(${n.length === 0 ? "[a-zA-Z_][a-zA-Z0-9_]*" : n.join("|")})\\.((?:not\\.)?(?:${b.join("|")}))\\.(.+)$`, s = new RegExp(a).exec(t);
250
+ if (!s) throw new o(`Invalid filter expression '${t}'`, {
252
251
  expression: t,
253
252
  format: {
254
253
  syntax: "key.(not.)op.value",
255
254
  keys: n.length === 0 ? "*" : n,
256
- operators: x
255
+ operators: b
257
256
  }
258
257
  });
259
- let [, c, l, u] = o;
258
+ let [, c, l, u] = s;
260
259
  return {
261
260
  type: "condition",
262
261
  key: r(c),
@@ -264,22 +263,22 @@ function A(t, n = [], r = (e) => e) {
264
263
  value: e.defined(u)
265
264
  };
266
265
  }
267
- function j(e, t = [], n = (e) => e, r = "~") {
268
- return e.length === 0 ? [] : e.split(r).map((e) => A(e, t, n));
266
+ function A(e, t = [], n = (e) => e, r = "~") {
267
+ return e.length === 0 ? [] : e.split(r).map((e) => k(e, t, n));
269
268
  }
270
269
  //#endregion
271
270
  //#region lib/postgrest.ts
272
- var M = class t extends r.PostgrestFilterBuilder {
271
+ var j = class t extends r.PostgrestFilterBuilder {
273
272
  pagination;
274
273
  constructor(e) {
275
274
  super(e);
276
275
  }
277
276
  select(e = "*") {
278
- return new t(super.select(p(e).join(",")));
277
+ return new t(super.select(f(e).join(",")));
279
278
  }
280
279
  where(e) {
281
280
  if (e.type === "logical") {
282
- let t = e.args.map((e) => O(e)).join(",");
281
+ let t = e.args.map((e) => D(e)).join(",");
283
282
  this.url.searchParams.append(e.op, `(${t})`);
284
283
  } else this.url.searchParams.append(e.key, `${e.op}.${e.value}`);
285
284
  return this;
@@ -321,89 +320,75 @@ var M = class t extends r.PostgrestFilterBuilder {
321
320
  };
322
321
  });
323
322
  }
324
- }, N = class extends r.PostgrestQueryBuilder {
323
+ }, M = class extends r.PostgrestQueryBuilder {
325
324
  constructor(e) {
326
325
  super(e.url, e);
327
326
  }
328
327
  select(e = "*", t) {
329
- return new M(super.select(p(e).join(","), t));
328
+ return new j(super.select(f(e).join(","), t));
330
329
  }
331
330
  count(e = "exact") {
332
- return new M(this.select("*", {
331
+ return new j(this.select("*", {
333
332
  count: e,
334
333
  head: !0
335
334
  }));
336
335
  }
337
336
  insert(e, t) {
338
- return new M(super.insert(e, t));
337
+ return new j(super.insert(e, t));
339
338
  }
340
339
  upsert(e, { onConflict: t, ...n } = {}) {
341
- return new M(super.upsert(e, {
342
- onConflict: p(t).join(","),
340
+ return new j(super.upsert(e, {
341
+ onConflict: f(t).join(","),
343
342
  ...n
344
343
  }));
345
344
  }
346
345
  update(e, t) {
347
- return new M(super.update(e, t));
346
+ return new j(super.update(e, t));
348
347
  }
349
348
  delete() {
350
- return new M(super.delete());
349
+ return new j(super.delete());
351
350
  }
352
- }, P = class {
351
+ }, N = class {
353
352
  client;
354
353
  constructor(e) {
355
354
  this.client = e;
356
355
  }
357
356
  from(e) {
358
- return new N(this.client.from(e));
357
+ return new M(this.client.from(e));
359
358
  }
360
359
  rpc(e, t, n) {
361
- return new M(this.client.rpc(e, t, n));
360
+ return new j(this.client.rpc(e, t, n));
362
361
  }
363
- }, F = class {
362
+ }, P = class {
364
363
  supabase;
365
364
  constructor({ supabase: e }) {
366
365
  this.supabase = e;
367
366
  }
368
367
  schema(e) {
369
- return new P(this.supabase.schema(e));
368
+ return new N(this.supabase.schema(e));
370
369
  }
371
370
  relation(e, t) {
372
- return new _({
371
+ return new g({
373
372
  database: this,
374
373
  schema: e,
375
374
  relation: t
376
375
  });
377
376
  }
378
377
  table(e, t) {
379
- return new v({
378
+ return new _({
380
379
  database: this,
381
380
  schema: e,
382
381
  table: t
383
382
  });
384
383
  }
385
384
  view(e, t) {
386
- return new y({
385
+ return new v({
387
386
  database: this,
388
387
  schema: e,
389
388
  view: t
390
389
  });
391
390
  }
392
- }, I = {
393
- removeImagesFromMarkdown: {
394
- name: "removeImagesFromMarkdown",
395
- run(e, t) {
396
- return t.type === "text/markdown" ? e.replace(/!\[([^\]]*)\]\([^)]*\)/g, (e, t) => `![${t}]()`) : e;
397
- }
398
- },
399
- removeLinksFromMarkdown: {
400
- name: "removeLinksFromMarkdown",
401
- run(e, t) {
402
- return t.type === "text/markdown" ? e.replace(/\[([^\]]*)\]\([^)]*\)/g, (e, t) => `[${t}]()`) : e;
403
- }
404
- }
405
- }, L = class {
406
- preprocesses = [];
391
+ }, F = class {
407
392
  storage;
408
393
  constructor({ storage: e }) {
409
394
  this.storage = e;
@@ -419,31 +404,13 @@ var M = class t extends r.PostgrestFilterBuilder {
419
404
  }
420
405
  return t;
421
406
  }
422
- preprocess(e, t) {
423
- return this.preprocesses.forEach((n) => {
424
- e = n.run(e, t);
425
- }), e;
426
- }
427
- addPreprocessingStep(e) {
428
- return this.preprocesses.push(e), this;
429
- }
430
- removePreprocessingStep(e) {
431
- return h(this.preprocesses, (t) => t.name === e), this;
432
- }
433
407
  async get(e) {
434
408
  let t = await this.storage.getFileStorageLocation(e);
435
409
  return this.getEmbeddings(t);
436
410
  }
437
411
  async ingest(e, t) {
438
- let { file: n, ...r } = await this.storage.downloadFile(e), a = i.parse(n.type);
439
- if (a.type !== "text") throw new l(`Unsupported file type: ${a}. Only text files can be embedded.`);
440
- await this.deleteEmbeddings(r);
441
- let o = {
442
- name: n.name,
443
- type: n.type,
444
- size: n.size
445
- }, s = this.preprocess(await n.text(), o);
446
- return this.createEmbeddings(r, s, o, typeof t == "function" ? t(n, r) : t);
412
+ let n = await this.storage.getFileStorageLocation(e);
413
+ return await this.deleteEmbeddings(n), this.createEmbeddings(n, typeof t == "function" ? t(n) : t);
447
414
  }
448
415
  async synchronize(e, t) {
449
416
  let n = await this.getOutdatedEmbeddings(e);
@@ -451,13 +418,24 @@ var M = class t extends r.PostgrestFilterBuilder {
451
418
  file: e,
452
419
  success: !0,
453
420
  error: null
454
- })).catch((t) => t instanceof l ? null : {
421
+ })).catch((t) => t instanceof c ? null : {
455
422
  file: e,
456
423
  error: t,
457
424
  success: !1
458
425
  })))).filter((e) => e !== null);
459
426
  }
460
- }, R = class {
427
+ };
428
+ //#endregion
429
+ //#region lib/processing.ts
430
+ function I(e) {
431
+ return e.replace(/!\[([^\]]*)\]\([^)]*\)/g, (e, t) => `![${t}]()`);
432
+ }
433
+ function L(e) {
434
+ return e.replace(/\[([^\]]*)\]\([^)]*\)/g, (e, t) => `[${t}]()`);
435
+ }
436
+ //#endregion
437
+ //#region lib/storage-service.ts
438
+ var R = class {
461
439
  client;
462
440
  database;
463
441
  constructor({ client: e, database: t }) {
@@ -479,7 +457,7 @@ var M = class t extends r.PostgrestFilterBuilder {
479
457
  async getFileStorageLocation(t) {
480
458
  if ("fileId" in t) {
481
459
  let { fileId: n } = t, r = await this.files.get(n, ["bucket_id", "path_tokens"]);
482
- if (!r) throw new o(`File with ID ${n} not found`, { fileId: n });
460
+ if (!r) throw new a(`File with ID ${n} not found`, { fileId: n });
483
461
  return {
484
462
  fileId: n,
485
463
  bucket: e.notNull(r.bucket_id, "bucket_id must not be null"),
@@ -519,7 +497,7 @@ var M = class t extends r.PostgrestFilterBuilder {
519
497
  async assertExistsFile(e) {
520
498
  let { bucket: t, path: n } = await this.getFileStorageLocation(e), { data: r, error: i } = await this.client.from(t).exists(n);
521
499
  if (i) throw i;
522
- if (!r) throw new o(`File not found in bucket '${t}' at path '${n}'`, {
500
+ if (!r) throw new a(`File not found in bucket '${t}' at path '${n}'`, {
523
501
  bucket: t,
524
502
  path: n
525
503
  });
@@ -536,7 +514,7 @@ var M = class t extends r.PostgrestFilterBuilder {
536
514
  async downloadFile(e) {
537
515
  let { fileId: t, bucket: n, path: r, properties: i } = await this.getFileInfo(e), { data: a, error: o } = await this.client.from(n).download(r);
538
516
  if (o) throw o;
539
- let [, s] = f(r);
517
+ let [, s] = d(r);
540
518
  return {
541
519
  fileId: t,
542
520
  bucket: n,
@@ -548,7 +526,7 @@ var M = class t extends r.PostgrestFilterBuilder {
548
526
  let n = t.filter((e) => "fileId" in e).map((e) => e.fileId), r = (await this.files.query.select(["bucket_id", "path_tokens"]).containedBy("id", n).throwOnError()).data.map(({ bucket_id: t, path_tokens: n }) => ({
549
527
  bucket: e.notNull(t, "bucket_id must not be null"),
550
528
  path: e.notNull(n, "path_tokens must not be null").join("/")
551
- })), i = g(m(t.filter((e) => "path" in e).concat(r), (e) => e.bucket)).map(([e, t]) => ({
529
+ })), i = h(p(t.filter((e) => "path" in e).concat(r), (e) => e.bucket)).map(([e, t]) => ({
552
530
  bucket: e,
553
531
  paths: t.map((e) => e.path)
554
532
  }));
@@ -563,4 +541,4 @@ var M = class t extends r.PostgrestFilterBuilder {
563
541
  }
564
542
  };
565
543
  //#endregion
566
- export { _ as DataService, F as DatabaseService, L as EmbeddingService, o as FileNotFoundError, T as Filter, w as FilterChainSeparator, x as FilterOp, S as LogicalOp, C as LogicalOpSeparator, s as ParseError, P as PostgrestClient, u as PostgrestErrorInterface, M as PostgrestFilterBuilder, N as PostgrestQueryBuilder, c as RecordNotFoundError, R as StorageService, v as TableDataService, a as TracedError, l as UnsupportedMimeError, y as ViewDataService, b as assertCounted, p as coerceArray, k as encodeFilter, O as encodeFilterNode, g as entries, m as groupBy, d as isDatabaseApiError, D as negateFilterNode, E as negateOp, A as parseFilterExpression, j as parseFilterExpressionChain, I as preprocessingSteps, h as removeElement, f as splitPath };
544
+ export { g as DataService, P as DatabaseService, F as EmbeddingService, a as FileNotFoundError, w as Filter, C as FilterChainSeparator, b as FilterOp, x as LogicalOp, S as LogicalOpSeparator, o as ParseError, N as PostgrestClient, l as PostgrestErrorInterface, j as PostgrestFilterBuilder, M as PostgrestQueryBuilder, s as RecordNotFoundError, R as StorageService, _ as TableDataService, i as TracedError, c as UnsupportedMimeError, v as ViewDataService, y as assertCounted, f as coerceArray, O as encodeFilter, D as encodeFilterNode, h as entries, p as groupBy, u as isDatabaseApiError, E as negateFilterNode, T as negateOp, k as parseFilterExpression, A as parseFilterExpressionChain, m as removeElement, I as removeImagesFromMarkdown, L as removeLinksFromMarkdown, d as splitPath };
@@ -0,0 +1,3 @@
1
+ export declare function removeImagesFromMarkdown(text: string): string;
2
+ export declare function removeLinksFromMarkdown(text: string): string;
3
+ //# sourceMappingURL=processing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processing.d.ts","sourceRoot":"","sources":["../lib/processing.ts"],"names":[],"mappings":"AACA,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAG7D;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAG5D"}
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "private": false,
4
4
  "displayName": "Supabase-Core",
5
5
  "description": "Lightweight services for supabase to make it easier to work with databases, tables and storage buckets",
6
- "version": "1.5.4",
6
+ "version": "1.6.0",
7
7
  "type": "module",
8
8
  "repository": {
9
9
  "type": "git",