@freehour/supabase-core 1.5.4 → 1.7.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/embedding-service.d.ts +2 -6
- package/dist/embedding-service.d.ts.map +1 -1
- package/dist/embedding.d.ts +1 -12
- package/dist/embedding.d.ts.map +1 -1
- package/dist/errors.d.ts +0 -25
- package/dist/errors.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +83 -111
- package/dist/processing.d.ts +3 -0
- package/dist/processing.d.ts.map +1 -0
- package/package.json +4 -5
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { 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,
|
|
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): Promise<EmbeddingSynchronizationResult[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"embedding-service.d.ts","sourceRoot":"","sources":["../lib/embedding-service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"embedding-service.d.ts","sourceRoot":"","sources":["../lib/embedding-service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAmC,8BAA8B,EAAmC,QAAQ,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAC9K,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGxD,MAAM,WAAW,sBAAsB,CACnC,UAAU,SAAS,MAAM,GAAG,MAAM;IAElC,OAAO,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;CACvC;AAED,8BAAsB,gBAAgB,CAClC,UAAU,SAAS,MAAM,GAAG,MAAM;IAElC,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;gBAE3C,EACR,OAAO,GACV,EAAE,sBAAsB,CAAC,UAAU,CAAC;IAIrC;;;;;OAKG;IACH,SAAS,CAAC,QAAQ,CAAC,aAAa,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,SAAS,EAAE,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;CAoB9H"}
|
package/dist/embedding.d.ts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import { MimeString } from '@freehour/mime';
|
|
2
1
|
import { Json } from './json';
|
|
3
2
|
import { FileRef, StorageLocation } from './storage';
|
|
4
3
|
export type Metadata = Record<string, Json>;
|
|
5
|
-
export type MetadataGeneratorFn = (
|
|
6
|
-
export interface FileMetadata {
|
|
7
|
-
name: string;
|
|
8
|
-
type: MimeString;
|
|
9
|
-
size: number;
|
|
10
|
-
}
|
|
4
|
+
export type MetadataGeneratorFn = (location: StorageLocation) => Metadata;
|
|
11
5
|
export interface Embedding extends StorageLocation {
|
|
12
6
|
text: string;
|
|
13
7
|
vector: number[];
|
|
@@ -25,9 +19,4 @@ export interface EmbeddingSynchronizationFailure {
|
|
|
25
19
|
error: Error;
|
|
26
20
|
}
|
|
27
21
|
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
22
|
//# sourceMappingURL=embedding.d.ts.map
|
package/dist/embedding.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"embedding.d.ts","sourceRoot":"","sources":["../lib/embedding.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"embedding.d.ts","sourceRoot":"","sources":["../lib/embedding.ts"],"names":[],"mappings":"AAAA,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;AAG1E,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/errors.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { default as z } from 'zod';
|
|
2
|
-
import { Mime } from '@freehour/mime';
|
|
3
2
|
import { PostgrestError } from '@supabase/supabase-js';
|
|
4
3
|
/**
|
|
5
4
|
* Automatically sets the name and captures the stack trace for the error.
|
|
@@ -98,30 +97,6 @@ export declare class RecordNotFoundError extends TracedError {
|
|
|
98
97
|
readonly id?: string | number;
|
|
99
98
|
constructor(message: string, { schema, relation, id, }?: RecordNotFoundErrorOptions);
|
|
100
99
|
}
|
|
101
|
-
export interface UnsupportedMimeErrorOptions extends ErrorOptions {
|
|
102
|
-
/**
|
|
103
|
-
* The MIME type that is unsupported.
|
|
104
|
-
*/
|
|
105
|
-
value?: Mime;
|
|
106
|
-
/**
|
|
107
|
-
* The list of supported MIME types.
|
|
108
|
-
*/
|
|
109
|
-
supported?: Mime[];
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* An error that indicates that a supplied MIME type is not supported.
|
|
113
|
-
*/
|
|
114
|
-
export declare class UnsupportedMimeError extends Error {
|
|
115
|
-
/**
|
|
116
|
-
* The MIME type that is unsupported.
|
|
117
|
-
*/
|
|
118
|
-
readonly value?: Mime;
|
|
119
|
-
/**
|
|
120
|
-
* The list of supported MIME types.
|
|
121
|
-
*/
|
|
122
|
-
readonly supported?: Mime[];
|
|
123
|
-
constructor(message: string, { value, supported, ...options }?: UnsupportedMimeErrorOptions);
|
|
124
|
-
}
|
|
125
100
|
/**
|
|
126
101
|
* PostgREST errors are sometimes returned in this format instead of the declared PostgrestError class.
|
|
127
102
|
*/
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../lib/errors.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AAEpB,OAAO,
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../lib/errors.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AAEpB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAGvD;;GAEG;AACH,qBAAa,WAAY,SAAQ,KAAK;gBACtB,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB;CAK3D;AAGD,MAAM,WAAW,wBAAwB;IAErC;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,WAAW;IAC9C;;OAEG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;gBAGnB,OAAO,EAAE,MAAM,EACf,EACI,MAAM,EACN,MAAM,EACN,IAAI,GACP,GAAE,wBAA6B;CAOvC;AAGD,MAAM,WAAW,iBAAkB,SAAQ,YAAY;IAEnD;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,WAAW;IAEvC;;OAEG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAE7B;;OAEG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;gBAGtB,OAAO,EAAE,MAAM,EACf,EACI,UAAU,EACV,MAAM,EACN,GAAG,OAAO,EACb,GAAE,iBAAsB;CAMhC;AAGD,MAAM,WAAW,0BAA0B;IAEvC;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACxB;AAED;;;;;GAKG;AACH,qBAAa,mBAAoB,SAAQ,WAAW;IAChD;;OAEG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAE3B;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;gBAG1B,OAAO,EAAE,MAAM,EACf,EACI,MAAM,EACN,QAAQ,EACR,EAAE,GACL,GAAE,0BAA+B;CAOzC;AAED;;GAEG;AACH,eAAO,MAAM,uBAAuB;;;;;;iBAgB9B,CAAC;AAEP,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAE9E;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,cAAc,GAAG,uBAAuB,CAAC;AAExE,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,gBAAgB,CAE5E"}
|
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';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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,
|
|
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,66 @@ 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
|
|
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
|
-
},
|
|
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
|
-
},
|
|
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
|
-
},
|
|
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
|
-
},
|
|
32
|
-
value;
|
|
33
|
-
supported;
|
|
34
|
-
constructor(e, { value: t, supported: n, ...r } = {}) {
|
|
35
|
-
super(e, r), this.value = t, this.supported = n;
|
|
36
|
-
}
|
|
37
|
-
}, u = t.object({
|
|
30
|
+
}, c = t.object({
|
|
38
31
|
code: t.string(),
|
|
39
32
|
details: t.string().nullable(),
|
|
40
33
|
hint: t.string().nullable(),
|
|
41
34
|
name: t.string().optional(),
|
|
42
35
|
message: t.string().optional()
|
|
43
36
|
});
|
|
44
|
-
function
|
|
45
|
-
return e instanceof n ||
|
|
37
|
+
function l(e) {
|
|
38
|
+
return e instanceof n || c.safeParse(e).success;
|
|
46
39
|
}
|
|
47
40
|
//#endregion
|
|
48
41
|
//#region lib/utils.ts
|
|
49
|
-
function
|
|
42
|
+
function u(e, t = "/") {
|
|
50
43
|
let n = e.lastIndexOf(t);
|
|
51
44
|
return n === -1 ? ["", e] : [e.substring(0, n), e.substring(n + 1)];
|
|
52
45
|
}
|
|
53
|
-
function
|
|
46
|
+
function d(e) {
|
|
54
47
|
return Array.isArray(e) ? e : [e];
|
|
55
48
|
}
|
|
56
|
-
function
|
|
49
|
+
function f(e, t) {
|
|
57
50
|
return e.reduce((e, n) => {
|
|
58
51
|
let r = t(n);
|
|
59
52
|
return (e[r] ??= []).push(n), e;
|
|
60
53
|
}, {});
|
|
61
54
|
}
|
|
62
|
-
function
|
|
55
|
+
function p(e, t) {
|
|
63
56
|
let n = e.findIndex(t);
|
|
64
57
|
return n !== -1 && e.splice(n, 1), e;
|
|
65
58
|
}
|
|
66
|
-
function
|
|
59
|
+
function m(e) {
|
|
67
60
|
return Object.entries(e);
|
|
68
61
|
}
|
|
69
62
|
//#endregion
|
|
70
63
|
//#region lib/data-service.ts
|
|
71
|
-
var
|
|
64
|
+
var h = class {
|
|
72
65
|
database;
|
|
73
66
|
schema;
|
|
74
67
|
relation;
|
|
@@ -76,7 +69,7 @@ var _ = class {
|
|
|
76
69
|
this.database = e, this.schema = t, this.relation = n;
|
|
77
70
|
}
|
|
78
71
|
recordNotFoundError(e) {
|
|
79
|
-
return new
|
|
72
|
+
return new s(`Record with id ${e} not found in ${this.schema}.${this.relation}`, {
|
|
80
73
|
schema: this.schema,
|
|
81
74
|
relation: this.relation,
|
|
82
75
|
id: e
|
|
@@ -124,7 +117,7 @@ var _ = class {
|
|
|
124
117
|
}
|
|
125
118
|
async upsert(e, { onConflict: t, ...n } = {}) {
|
|
126
119
|
let { data: r } = await this.query.upsert(e, {
|
|
127
|
-
onConflict: t === void 0 ? void 0 :
|
|
120
|
+
onConflict: t === void 0 ? void 0 : d(t).join(","),
|
|
128
121
|
...n
|
|
129
122
|
}).select().single().throwOnError();
|
|
130
123
|
return r;
|
|
@@ -133,7 +126,7 @@ var _ = class {
|
|
|
133
126
|
let { data: n } = await this.query.update(t).eq("id", e).select().single().throwOnError();
|
|
134
127
|
return n;
|
|
135
128
|
}
|
|
136
|
-
},
|
|
129
|
+
}, g = class extends h {
|
|
137
130
|
constructor({ database: e, schema: t, table: n }) {
|
|
138
131
|
super({
|
|
139
132
|
database: e,
|
|
@@ -141,7 +134,7 @@ var _ = class {
|
|
|
141
134
|
relation: n
|
|
142
135
|
});
|
|
143
136
|
}
|
|
144
|
-
},
|
|
137
|
+
}, _ = class extends h {
|
|
145
138
|
constructor({ database: e, schema: t, view: n }) {
|
|
146
139
|
super({
|
|
147
140
|
database: e,
|
|
@@ -150,13 +143,13 @@ var _ = class {
|
|
|
150
143
|
});
|
|
151
144
|
}
|
|
152
145
|
};
|
|
153
|
-
function
|
|
146
|
+
function v(t) {
|
|
154
147
|
if (t.error) throw t.error;
|
|
155
148
|
return e(t.count !== null, "Response does not contain a count. Make sure to set the `count` option in the request."), t;
|
|
156
149
|
}
|
|
157
150
|
//#endregion
|
|
158
151
|
//#region lib/filter.ts
|
|
159
|
-
var
|
|
152
|
+
var y = [
|
|
160
153
|
"eq",
|
|
161
154
|
"neq",
|
|
162
155
|
"gt",
|
|
@@ -182,17 +175,17 @@ var x = [
|
|
|
182
175
|
"nxr",
|
|
183
176
|
"nxl",
|
|
184
177
|
"adj"
|
|
185
|
-
],
|
|
178
|
+
], b = ["and", "or"], x = ",", S = "~", C = (e) => (n = {}) => {
|
|
186
179
|
let r = (e) => n[e] ?? e, i = Object.keys(e.shape);
|
|
187
180
|
return t.string().transform((e, t) => {
|
|
188
181
|
try {
|
|
189
|
-
return
|
|
182
|
+
return k(e, i, r);
|
|
190
183
|
} catch (n) {
|
|
191
184
|
return t.addIssue({
|
|
192
185
|
code: "custom",
|
|
193
186
|
input: e,
|
|
194
187
|
message: n instanceof Error ? n.message : void 0,
|
|
195
|
-
params: n instanceof
|
|
188
|
+
params: n instanceof o ? {
|
|
196
189
|
expression: n.expression,
|
|
197
190
|
format: n.format
|
|
198
191
|
} : void 0
|
|
@@ -200,26 +193,26 @@ var x = [
|
|
|
200
193
|
}
|
|
201
194
|
});
|
|
202
195
|
};
|
|
203
|
-
function
|
|
196
|
+
function w(e) {
|
|
204
197
|
return e.startsWith("not.") ? e.slice(4) : `not.${e}`;
|
|
205
198
|
}
|
|
206
|
-
function
|
|
199
|
+
function T(e) {
|
|
207
200
|
return {
|
|
208
201
|
...e,
|
|
209
|
-
op:
|
|
202
|
+
op: w(e.op)
|
|
210
203
|
};
|
|
211
204
|
}
|
|
212
|
-
function
|
|
205
|
+
function E(e, t = (e) => e) {
|
|
213
206
|
if (e.type === "logical") {
|
|
214
|
-
let n = e.args.map((e) =>
|
|
207
|
+
let n = e.args.map((e) => E(e, t));
|
|
215
208
|
return `${e.op}(${n})`;
|
|
216
209
|
}
|
|
217
210
|
return `${t(e.key)}.${e.op}.${e.value}`;
|
|
218
211
|
}
|
|
219
|
-
function
|
|
220
|
-
return e.map((e) =>
|
|
212
|
+
function D(e, t = (e) => e, n = "~") {
|
|
213
|
+
return e.map((e) => E(e, t)).join(n);
|
|
221
214
|
}
|
|
222
|
-
function
|
|
215
|
+
function O(t, n = [], r = (e) => e) {
|
|
223
216
|
function i(e) {
|
|
224
217
|
let t = [], n = 0, r = "", i = !1;
|
|
225
218
|
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 +222,34 @@ function A(t, n = [], r = (e) => e) {
|
|
|
229
222
|
if (t.startsWith("and(")) return {
|
|
230
223
|
type: "logical",
|
|
231
224
|
op: "and",
|
|
232
|
-
args: i(t.slice(4, -1)).map((e) =>
|
|
225
|
+
args: i(t.slice(4, -1)).map((e) => O(e, n, r))
|
|
233
226
|
};
|
|
234
227
|
if (t.startsWith("or(")) return {
|
|
235
228
|
type: "logical",
|
|
236
229
|
op: "or",
|
|
237
|
-
args: i(t.slice(3, -1)).map((e) =>
|
|
230
|
+
args: i(t.slice(3, -1)).map((e) => O(e, n, r))
|
|
238
231
|
};
|
|
239
232
|
if (t.startsWith("not.and(")) return {
|
|
240
233
|
type: "logical",
|
|
241
234
|
op: "not.and",
|
|
242
|
-
args: i(t.slice(8, -1)).map((e) =>
|
|
235
|
+
args: i(t.slice(8, -1)).map((e) => O(e, n, r))
|
|
243
236
|
};
|
|
244
237
|
if (t.startsWith("not.or(")) return {
|
|
245
238
|
type: "logical",
|
|
246
239
|
op: "not.or",
|
|
247
|
-
args: i(t.slice(7, -1)).map((e) =>
|
|
240
|
+
args: i(t.slice(7, -1)).map((e) => O(e, n, r))
|
|
248
241
|
};
|
|
249
242
|
}
|
|
250
|
-
let a = `^(${n.length === 0 ? "[a-zA-Z_][a-zA-Z0-9_]*" : n.join("|")})\\.((?:not\\.)?(?:${
|
|
251
|
-
if (!
|
|
243
|
+
let a = `^(${n.length === 0 ? "[a-zA-Z_][a-zA-Z0-9_]*" : n.join("|")})\\.((?:not\\.)?(?:${y.join("|")}))\\.(.+)$`, s = new RegExp(a).exec(t);
|
|
244
|
+
if (!s) throw new o(`Invalid filter expression '${t}'`, {
|
|
252
245
|
expression: t,
|
|
253
246
|
format: {
|
|
254
247
|
syntax: "key.(not.)op.value",
|
|
255
248
|
keys: n.length === 0 ? "*" : n,
|
|
256
|
-
operators:
|
|
249
|
+
operators: y
|
|
257
250
|
}
|
|
258
251
|
});
|
|
259
|
-
let [, c, l, u] =
|
|
252
|
+
let [, c, l, u] = s;
|
|
260
253
|
return {
|
|
261
254
|
type: "condition",
|
|
262
255
|
key: r(c),
|
|
@@ -264,22 +257,22 @@ function A(t, n = [], r = (e) => e) {
|
|
|
264
257
|
value: e.defined(u)
|
|
265
258
|
};
|
|
266
259
|
}
|
|
267
|
-
function
|
|
268
|
-
return e.length === 0 ? [] : e.split(r).map((e) =>
|
|
260
|
+
function k(e, t = [], n = (e) => e, r = "~") {
|
|
261
|
+
return e.length === 0 ? [] : e.split(r).map((e) => O(e, t, n));
|
|
269
262
|
}
|
|
270
263
|
//#endregion
|
|
271
264
|
//#region lib/postgrest.ts
|
|
272
|
-
var
|
|
265
|
+
var A = class t extends r.PostgrestFilterBuilder {
|
|
273
266
|
pagination;
|
|
274
267
|
constructor(e) {
|
|
275
268
|
super(e);
|
|
276
269
|
}
|
|
277
270
|
select(e = "*") {
|
|
278
|
-
return new t(super.select(
|
|
271
|
+
return new t(super.select(d(e).join(",")));
|
|
279
272
|
}
|
|
280
273
|
where(e) {
|
|
281
274
|
if (e.type === "logical") {
|
|
282
|
-
let t = e.args.map((e) =>
|
|
275
|
+
let t = e.args.map((e) => E(e)).join(",");
|
|
283
276
|
this.url.searchParams.append(e.op, `(${t})`);
|
|
284
277
|
} else this.url.searchParams.append(e.key, `${e.op}.${e.value}`);
|
|
285
278
|
return this;
|
|
@@ -321,89 +314,75 @@ var M = class t extends r.PostgrestFilterBuilder {
|
|
|
321
314
|
};
|
|
322
315
|
});
|
|
323
316
|
}
|
|
324
|
-
},
|
|
317
|
+
}, j = class extends r.PostgrestQueryBuilder {
|
|
325
318
|
constructor(e) {
|
|
326
319
|
super(e.url, e);
|
|
327
320
|
}
|
|
328
321
|
select(e = "*", t) {
|
|
329
|
-
return new
|
|
322
|
+
return new A(super.select(d(e).join(","), t));
|
|
330
323
|
}
|
|
331
324
|
count(e = "exact") {
|
|
332
|
-
return new
|
|
325
|
+
return new A(this.select("*", {
|
|
333
326
|
count: e,
|
|
334
327
|
head: !0
|
|
335
328
|
}));
|
|
336
329
|
}
|
|
337
330
|
insert(e, t) {
|
|
338
|
-
return new
|
|
331
|
+
return new A(super.insert(e, t));
|
|
339
332
|
}
|
|
340
333
|
upsert(e, { onConflict: t, ...n } = {}) {
|
|
341
|
-
return new
|
|
342
|
-
onConflict:
|
|
334
|
+
return new A(super.upsert(e, {
|
|
335
|
+
onConflict: d(t).join(","),
|
|
343
336
|
...n
|
|
344
337
|
}));
|
|
345
338
|
}
|
|
346
339
|
update(e, t) {
|
|
347
|
-
return new
|
|
340
|
+
return new A(super.update(e, t));
|
|
348
341
|
}
|
|
349
342
|
delete() {
|
|
350
|
-
return new
|
|
343
|
+
return new A(super.delete());
|
|
351
344
|
}
|
|
352
|
-
},
|
|
345
|
+
}, M = class {
|
|
353
346
|
client;
|
|
354
347
|
constructor(e) {
|
|
355
348
|
this.client = e;
|
|
356
349
|
}
|
|
357
350
|
from(e) {
|
|
358
|
-
return new
|
|
351
|
+
return new j(this.client.from(e));
|
|
359
352
|
}
|
|
360
353
|
rpc(e, t, n) {
|
|
361
|
-
return new
|
|
354
|
+
return new A(this.client.rpc(e, t, n));
|
|
362
355
|
}
|
|
363
|
-
},
|
|
356
|
+
}, N = class {
|
|
364
357
|
supabase;
|
|
365
358
|
constructor({ supabase: e }) {
|
|
366
359
|
this.supabase = e;
|
|
367
360
|
}
|
|
368
361
|
schema(e) {
|
|
369
|
-
return new
|
|
362
|
+
return new M(this.supabase.schema(e));
|
|
370
363
|
}
|
|
371
364
|
relation(e, t) {
|
|
372
|
-
return new
|
|
365
|
+
return new h({
|
|
373
366
|
database: this,
|
|
374
367
|
schema: e,
|
|
375
368
|
relation: t
|
|
376
369
|
});
|
|
377
370
|
}
|
|
378
371
|
table(e, t) {
|
|
379
|
-
return new
|
|
372
|
+
return new g({
|
|
380
373
|
database: this,
|
|
381
374
|
schema: e,
|
|
382
375
|
table: t
|
|
383
376
|
});
|
|
384
377
|
}
|
|
385
378
|
view(e, t) {
|
|
386
|
-
return new
|
|
379
|
+
return new _({
|
|
387
380
|
database: this,
|
|
388
381
|
schema: e,
|
|
389
382
|
view: t
|
|
390
383
|
});
|
|
391
384
|
}
|
|
392
|
-
},
|
|
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 = [];
|
|
385
|
+
}, P = class {
|
|
407
386
|
storage;
|
|
408
387
|
constructor({ storage: e }) {
|
|
409
388
|
this.storage = e;
|
|
@@ -415,49 +394,42 @@ var M = class t extends r.PostgrestFilterBuilder {
|
|
|
415
394
|
let t = new Date(e.updated_at), n = await this.storage.getFileStorageLocation({ fileId: e.id }), r = await this.getEmbeddings(n);
|
|
416
395
|
return r.length === 0 || r.some((e) => e.createdAt < t);
|
|
417
396
|
}));
|
|
418
|
-
t.push(...i.filter((e, t) => o[t]).map(({ id: e }) => ({ fileId: e }))), {hasNext: n, nextCursor: r} = a;
|
|
397
|
+
t.push(...i.filter((e, t) => o[t] ?? !1).map(({ id: e }) => ({ fileId: e }))), {hasNext: n, nextCursor: r} = a;
|
|
419
398
|
}
|
|
420
399
|
return t;
|
|
421
400
|
}
|
|
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
401
|
async get(e) {
|
|
434
402
|
let t = await this.storage.getFileStorageLocation(e);
|
|
435
403
|
return this.getEmbeddings(t);
|
|
436
404
|
}
|
|
437
405
|
async ingest(e, t) {
|
|
438
|
-
let
|
|
439
|
-
|
|
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);
|
|
406
|
+
let n = await this.storage.getFileStorageLocation(e);
|
|
407
|
+
return await this.deleteEmbeddings(n), this.createEmbeddings(n, typeof t == "function" ? t(n) : t);
|
|
447
408
|
}
|
|
448
409
|
async synchronize(e, t) {
|
|
449
410
|
let n = await this.getOutdatedEmbeddings(e);
|
|
450
|
-
return
|
|
411
|
+
return Promise.all(n.map(async (e) => this.ingest(e, t).then(() => ({
|
|
451
412
|
file: e,
|
|
452
413
|
success: !0,
|
|
453
414
|
error: null
|
|
454
|
-
})).catch((t) =>
|
|
415
|
+
})).catch((t) => ({
|
|
455
416
|
file: e,
|
|
456
417
|
error: t,
|
|
457
418
|
success: !1
|
|
458
|
-
}))))
|
|
419
|
+
}))));
|
|
459
420
|
}
|
|
460
|
-
}
|
|
421
|
+
};
|
|
422
|
+
//#endregion
|
|
423
|
+
//#region lib/processing.ts
|
|
424
|
+
function F(e) {
|
|
425
|
+
return e.replace(/!\[([^\]]*)\]\([^)]*\)/g, (e, t) => `![${t}]()`);
|
|
426
|
+
}
|
|
427
|
+
function I(e) {
|
|
428
|
+
return e.replace(/\[([^\]]*)\]\([^)]*\)/g, (e, t) => `[${t}]()`);
|
|
429
|
+
}
|
|
430
|
+
//#endregion
|
|
431
|
+
//#region lib/storage-service.ts
|
|
432
|
+
var L = class {
|
|
461
433
|
client;
|
|
462
434
|
database;
|
|
463
435
|
constructor({ client: e, database: t }) {
|
|
@@ -479,7 +451,7 @@ var M = class t extends r.PostgrestFilterBuilder {
|
|
|
479
451
|
async getFileStorageLocation(t) {
|
|
480
452
|
if ("fileId" in t) {
|
|
481
453
|
let { fileId: n } = t, r = await this.files.get(n, ["bucket_id", "path_tokens"]);
|
|
482
|
-
if (!r) throw new
|
|
454
|
+
if (!r) throw new a(`File with ID ${n} not found`, { fileId: n });
|
|
483
455
|
return {
|
|
484
456
|
fileId: n,
|
|
485
457
|
bucket: e.notNull(r.bucket_id, "bucket_id must not be null"),
|
|
@@ -519,7 +491,7 @@ var M = class t extends r.PostgrestFilterBuilder {
|
|
|
519
491
|
async assertExistsFile(e) {
|
|
520
492
|
let { bucket: t, path: n } = await this.getFileStorageLocation(e), { data: r, error: i } = await this.client.from(t).exists(n);
|
|
521
493
|
if (i) throw i;
|
|
522
|
-
if (!r) throw new
|
|
494
|
+
if (!r) throw new a(`File not found in bucket '${t}' at path '${n}'`, {
|
|
523
495
|
bucket: t,
|
|
524
496
|
path: n
|
|
525
497
|
});
|
|
@@ -536,7 +508,7 @@ var M = class t extends r.PostgrestFilterBuilder {
|
|
|
536
508
|
async downloadFile(e) {
|
|
537
509
|
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
510
|
if (o) throw o;
|
|
539
|
-
let [, s] =
|
|
511
|
+
let [, s] = u(r);
|
|
540
512
|
return {
|
|
541
513
|
fileId: t,
|
|
542
514
|
bucket: n,
|
|
@@ -548,7 +520,7 @@ var M = class t extends r.PostgrestFilterBuilder {
|
|
|
548
520
|
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
521
|
bucket: e.notNull(t, "bucket_id must not be null"),
|
|
550
522
|
path: e.notNull(n, "path_tokens must not be null").join("/")
|
|
551
|
-
})), i =
|
|
523
|
+
})), i = m(f(t.filter((e) => "path" in e).concat(r), (e) => e.bucket)).map(([e, t]) => ({
|
|
552
524
|
bucket: e,
|
|
553
525
|
paths: t.map((e) => e.path)
|
|
554
526
|
}));
|
|
@@ -563,4 +535,4 @@ var M = class t extends r.PostgrestFilterBuilder {
|
|
|
563
535
|
}
|
|
564
536
|
};
|
|
565
537
|
//#endregion
|
|
566
|
-
export {
|
|
538
|
+
export { h as DataService, N as DatabaseService, P as EmbeddingService, a as FileNotFoundError, C as Filter, S as FilterChainSeparator, y as FilterOp, b as LogicalOp, x as LogicalOpSeparator, o as ParseError, M as PostgrestClient, c as PostgrestErrorInterface, A as PostgrestFilterBuilder, j as PostgrestQueryBuilder, s as RecordNotFoundError, L as StorageService, g as TableDataService, i as TracedError, _ as ViewDataService, v as assertCounted, d as coerceArray, D as encodeFilter, E as encodeFilterNode, m as entries, f as groupBy, l as isDatabaseApiError, T as negateFilterNode, w as negateOp, O as parseFilterExpression, k as parseFilterExpressionChain, p as removeElement, F as removeImagesFromMarkdown, I as removeLinksFromMarkdown, u as splitPath };
|
|
@@ -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.
|
|
6
|
+
"version": "1.7.0",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
@@ -28,20 +28,19 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@freehour/assert": "^1.0.0",
|
|
31
|
-
"@freehour/mime": "^1.0.5",
|
|
32
31
|
"@supabase/postgrest-js": "^2.101.1",
|
|
33
32
|
"@supabase/storage-js": "^2.101.1",
|
|
34
33
|
"@supabase/supabase-js": "^2.101.1",
|
|
35
34
|
"zod": "4.3.6"
|
|
36
35
|
},
|
|
37
36
|
"devDependencies": {
|
|
38
|
-
"@freehour/eslint-rules": "^1.0.
|
|
37
|
+
"@freehour/eslint-rules": "^1.0.16",
|
|
39
38
|
"ajv": "^8.18.0",
|
|
40
39
|
"bun-types": "^1.3.11",
|
|
41
40
|
"eslint": "9.39.4",
|
|
42
|
-
"supabase": "^2.
|
|
41
|
+
"supabase": "^2.85.0",
|
|
43
42
|
"typescript": "^6.0.2",
|
|
44
|
-
"vite": "^8.0.
|
|
43
|
+
"vite": "^8.0.5",
|
|
45
44
|
"vite-plugin-dts": "^4.5.4"
|
|
46
45
|
},
|
|
47
46
|
"trustedDependencies": [
|