@freehour/supabase-core 1.0.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/LICENSE +21 -0
- package/README.md +22 -0
- package/dist/data-service.d.ts +3136 -0
- package/dist/data-service.d.ts.map +1 -0
- package/dist/database-service.d.ts +21 -0
- package/dist/database-service.d.ts.map +1 -0
- package/dist/database.d.ts +96 -0
- package/dist/database.d.ts.map +1 -0
- package/dist/errors.d.ts +116 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/filter.d.ts +157 -0
- package/dist/filter.d.ts.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +695 -0
- package/dist/json.d.ts +4 -0
- package/dist/json.d.ts.map +1 -0
- package/dist/postgrest-extensions.d.ts +180 -0
- package/dist/postgrest-extensions.d.ts.map +1 -0
- package/dist/relation.d.ts +29 -0
- package/dist/relation.d.ts.map +1 -0
- package/dist/select.d.ts +26 -0
- package/dist/select.d.ts.map +1 -0
- package/dist/storage-service.d.ts +73 -0
- package/dist/storage-service.d.ts.map +1 -0
- package/dist/storage.d.ts +20 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/utils.d.ts +66 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +53 -0
- package/scripts/copy-supabase-assets.js +36 -0
- package/supabase/migrations/0000_supabase_core.sql +58 -0
- package/supabase/schemas/supabase-core/1_schemas.sql +11 -0
- package/supabase/schemas/supabase-core/2_extensions.sql +5 -0
- package/supabase/schemas/supabase-core/3_functions.sql +57 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { PostgrestClientOptions, PostgrestFilterBuilder, PostgrestQueryBuilder, UnstableGetResult } from '@supabase/postgrest-js';
|
|
2
|
+
import { GenericSchema, GenericTable, GenericView } from './database';
|
|
3
|
+
import { Filter } from './filter';
|
|
4
|
+
import { CountMethod, Select, SelectColumns, SelectOptions } from './select';
|
|
5
|
+
import { ElementOf } from './utils';
|
|
6
|
+
/**
|
|
7
|
+
* Paginated list of items with pagination info.
|
|
8
|
+
*/
|
|
9
|
+
export interface PaginatedList<Item> {
|
|
10
|
+
items: Item[];
|
|
11
|
+
page: number;
|
|
12
|
+
limit: number;
|
|
13
|
+
totalItems: number;
|
|
14
|
+
totalPages: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Internal context for PostgREST filter extension. Keeps track of current filter state
|
|
18
|
+
* modified by functions in the postgrestExtensions.filter chain.
|
|
19
|
+
*/
|
|
20
|
+
interface PostgrestFilterExtensionContext {
|
|
21
|
+
pagination?: {
|
|
22
|
+
page: number;
|
|
23
|
+
limit: number;
|
|
24
|
+
count?: number;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Database extensions for PostgREST queries.
|
|
29
|
+
* Provides methods for column selection, filtering and pagination.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* const selection = supabase.schema('public').from('my_table').select('*', { count: 'exact' });
|
|
33
|
+
* const {data, error} = await postgrestExtensions.filter.enable(selection)
|
|
34
|
+
* .apply({ key: 'name', op: 'eq', value: 'John' })
|
|
35
|
+
* .paginate(1, 10)
|
|
36
|
+
* .collect();
|
|
37
|
+
*/
|
|
38
|
+
export declare const postgrestExtensions: {
|
|
39
|
+
/**
|
|
40
|
+
* Query extension for PostgREST queries.
|
|
41
|
+
* Supports typesafe column selection and counting.
|
|
42
|
+
* This extension can be used with any PostgREST query builder.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* const table = supabase.schema('public').from('my_table');
|
|
46
|
+
* const {data, error} = await postgrestExtensions.query.enable(table)
|
|
47
|
+
* .selectColumns(['id', 'name'])
|
|
48
|
+
* .then(({data}) => console.log(data)); // [{ id: 1, name: 'John' }, ...]
|
|
49
|
+
*/
|
|
50
|
+
readonly query: {
|
|
51
|
+
readonly enable: <ClientOptions extends PostgrestClientOptions, Schema extends GenericSchema, Relation extends GenericTable | GenericView, RelationName = unknown, Relationships = Relation extends {
|
|
52
|
+
Relationships: infer R;
|
|
53
|
+
} ? R : unknown>(builder: PostgrestQueryBuilder<ClientOptions, Schema, Relation, RelationName, Relationships>) => PostgrestQueryBuilder<ClientOptions, Schema, Relation, RelationName, Relationships> & {
|
|
54
|
+
/**
|
|
55
|
+
* Selects columns from the relation.
|
|
56
|
+
*
|
|
57
|
+
* @param columns The array of column names to select, or '*' to select all columns.
|
|
58
|
+
* @param options The options for the selection, such as count.
|
|
59
|
+
* @returns The PostgREST filter builder with selection applied and filter extension enabled.
|
|
60
|
+
*/
|
|
61
|
+
select: <Columns extends SelectColumns<Relation["Row"]>>(columns: Columns, options?: SelectOptions) => PostgrestFilterBuilder<ClientOptions, Schema, Relation["Row"], Select<Relation["Row"], Columns>[], RelationName, Relationships, "GET"> & {
|
|
62
|
+
/**
|
|
63
|
+
* Applies a filter to the query.
|
|
64
|
+
* A filter is defined as an array of AST filter nodes including conditions and logical operators.
|
|
65
|
+
* @param filter The filter to apply.
|
|
66
|
+
*/
|
|
67
|
+
apply: <K extends string = string>(filter: Filter<K>) => PostgrestFilterBuilder<ClientOptions, Schema, Relation["Row"], Select<Relation["Row"], Columns>[], RelationName, Relationships, "GET"> & /*elided*/ any;
|
|
68
|
+
/**
|
|
69
|
+
* Limits the range of results to a specific page given a page index and limit.
|
|
70
|
+
* @param page The page index (0-based).
|
|
71
|
+
* @param limit The number of items per page.
|
|
72
|
+
* @param count Optional count of total items, if known.
|
|
73
|
+
* If provided, it will be used to check if the pagination range is valid and resolve to an empty range if not.
|
|
74
|
+
*/
|
|
75
|
+
paginate: (page: number, limit: number, count?: number) => PostgrestFilterBuilder<ClientOptions, Schema, Relation["Row"], Select<Relation["Row"], Columns>[], RelationName, Relationships, "GET"> & /*elided*/ any;
|
|
76
|
+
/**
|
|
77
|
+
* Collects the results of a pagination query.
|
|
78
|
+
* **Note:** For collect to work, paginate() must be called before collect() and the selection must include a `count`.
|
|
79
|
+
* @returns The paginated list of queried items.
|
|
80
|
+
*/
|
|
81
|
+
collect: () => PromiseLike<PaginatedList<Select<Relation["Row"], Columns>>>;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Counts the number of rows in the relation.
|
|
85
|
+
* Does not select any columns, only counts the rows.
|
|
86
|
+
*
|
|
87
|
+
* @param method The counting method to use, defaults to 'exact'.
|
|
88
|
+
* @returns The PostgREST filter builder with counting applied and filter extension enabled.
|
|
89
|
+
*/
|
|
90
|
+
count: (method?: CountMethod) => PostgrestFilterBuilder<ClientOptions, Schema, Relation["Row"], UnstableGetResult<Schema, Relation["Row"], RelationName, Relationships, "*", ClientOptions>[], RelationName, Relationships, "GET"> & {
|
|
91
|
+
/**
|
|
92
|
+
* Applies a filter to the query.
|
|
93
|
+
* A filter is defined as an array of AST filter nodes including conditions and logical operators.
|
|
94
|
+
* @param filter The filter to apply.
|
|
95
|
+
*/
|
|
96
|
+
apply: <K extends string = string>(filter: Filter<K>) => PostgrestFilterBuilder<ClientOptions, Schema, Relation["Row"], UnstableGetResult<Schema, Relation["Row"], RelationName, Relationships, "*", ClientOptions>[], RelationName, Relationships, "GET"> & /*elided*/ any;
|
|
97
|
+
/**
|
|
98
|
+
* Limits the range of results to a specific page given a page index and limit.
|
|
99
|
+
* @param page The page index (0-based).
|
|
100
|
+
* @param limit The number of items per page.
|
|
101
|
+
* @param count Optional count of total items, if known.
|
|
102
|
+
* If provided, it will be used to check if the pagination range is valid and resolve to an empty range if not.
|
|
103
|
+
*/
|
|
104
|
+
paginate: (page: number, limit: number, count?: number) => PostgrestFilterBuilder<ClientOptions, Schema, Relation["Row"], UnstableGetResult<Schema, Relation["Row"], RelationName, Relationships, "*", ClientOptions>[], RelationName, Relationships, "GET"> & /*elided*/ any;
|
|
105
|
+
/**
|
|
106
|
+
* Collects the results of a pagination query.
|
|
107
|
+
* **Note:** For collect to work, paginate() must be called before collect() and the selection must include a `count`.
|
|
108
|
+
* @returns The paginated list of queried items.
|
|
109
|
+
*/
|
|
110
|
+
collect: () => PromiseLike<PaginatedList< UnstableGetResult<Schema, Relation["Row"], RelationName, Relationships, "*", ClientOptions>>>;
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Deletes rows from the relation.
|
|
114
|
+
* Returns a filter builder for further filtering before deletion.
|
|
115
|
+
*
|
|
116
|
+
* @returns The PostgREST filter builder with delete applied and filter extension enabled.
|
|
117
|
+
*/
|
|
118
|
+
delete: () => PostgrestFilterBuilder<ClientOptions, Schema, Relation["Row"], null, RelationName, Relationships, "DELETE"> & {
|
|
119
|
+
/**
|
|
120
|
+
* Applies a filter to the query.
|
|
121
|
+
* A filter is defined as an array of AST filter nodes including conditions and logical operators.
|
|
122
|
+
* @param filter The filter to apply.
|
|
123
|
+
*/
|
|
124
|
+
apply: <K extends string = string>(filter: Filter<K>) => PostgrestFilterBuilder<ClientOptions, Schema, Relation["Row"], null, RelationName, Relationships, "DELETE"> & /*elided*/ any;
|
|
125
|
+
/**
|
|
126
|
+
* Limits the range of results to a specific page given a page index and limit.
|
|
127
|
+
* @param page The page index (0-based).
|
|
128
|
+
* @param limit The number of items per page.
|
|
129
|
+
* @param count Optional count of total items, if known.
|
|
130
|
+
* If provided, it will be used to check if the pagination range is valid and resolve to an empty range if not.
|
|
131
|
+
*/
|
|
132
|
+
paginate: (page: number, limit: number, count?: number) => PostgrestFilterBuilder<ClientOptions, Schema, Relation["Row"], null, RelationName, Relationships, "DELETE"> & /*elided*/ any;
|
|
133
|
+
/**
|
|
134
|
+
* Collects the results of a pagination query.
|
|
135
|
+
* **Note:** For collect to work, paginate() must be called before collect() and the selection must include a `count`.
|
|
136
|
+
* @returns The paginated list of queried items.
|
|
137
|
+
*/
|
|
138
|
+
collect: () => PromiseLike<PaginatedList<null>>;
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* Filter extension for PostgREST queries.
|
|
144
|
+
* Supports applying filters, pagination and collecting results.
|
|
145
|
+
* This extension can be used with any PostgREST filter builder.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* const selection = supabase.schema('public').from('my_table').select('*', { count: 'exact' });
|
|
149
|
+
* const {data, error} = await postgrestExtensions.filter.enable(selection)
|
|
150
|
+
* .apply({ key: 'name', op: 'eq', value: 'John' })
|
|
151
|
+
* .paginate(1, 10)
|
|
152
|
+
* .collect();
|
|
153
|
+
*/
|
|
154
|
+
readonly filter: {
|
|
155
|
+
readonly enable: <ClientOptions extends PostgrestClientOptions, Schema extends GenericSchema, Row extends Record<string, unknown>, Result, RelationName = unknown, Relationships = unknown, Method = unknown>(builder: PostgrestFilterBuilder<ClientOptions, Schema, Row, Result, RelationName, Relationships, Method>, context?: PostgrestFilterExtensionContext) => PostgrestFilterBuilder<ClientOptions, Schema, Row, Result, RelationName, Relationships, Method> & {
|
|
156
|
+
/**
|
|
157
|
+
* Applies a filter to the query.
|
|
158
|
+
* A filter is defined as an array of AST filter nodes including conditions and logical operators.
|
|
159
|
+
* @param filter The filter to apply.
|
|
160
|
+
*/
|
|
161
|
+
apply: <K extends string = string>(filter: Filter<K>) => PostgrestFilterBuilder<ClientOptions, Schema, Row, Result, RelationName, Relationships, Method> & /*elided*/ any;
|
|
162
|
+
/**
|
|
163
|
+
* Limits the range of results to a specific page given a page index and limit.
|
|
164
|
+
* @param page The page index (0-based).
|
|
165
|
+
* @param limit The number of items per page.
|
|
166
|
+
* @param count Optional count of total items, if known.
|
|
167
|
+
* If provided, it will be used to check if the pagination range is valid and resolve to an empty range if not.
|
|
168
|
+
*/
|
|
169
|
+
paginate: (page: number, limit: number, count?: number) => PostgrestFilterBuilder<ClientOptions, Schema, Row, Result, RelationName, Relationships, Method> & /*elided*/ any;
|
|
170
|
+
/**
|
|
171
|
+
* Collects the results of a pagination query.
|
|
172
|
+
* **Note:** For collect to work, paginate() must be called before collect() and the selection must include a `count`.
|
|
173
|
+
* @returns The paginated list of queried items.
|
|
174
|
+
*/
|
|
175
|
+
collect: () => PromiseLike<PaginatedList<ElementOf<Result>>>;
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
export {};
|
|
180
|
+
//# sourceMappingURL=postgrest-extensions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgrest-extensions.d.ts","sourceRoot":"","sources":["../lib/postgrest-extensions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,qBAAqB,EAA4B,MAAM,wBAAwB,CAAC;AAE9I,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC3E,OAAO,KAAK,EAAE,MAAM,EAAc,MAAM,UAAU,CAAC;AAEnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAClF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGzC;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,IAAI;IAC/B,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACtB;AAED;;;GAGG;AACH,UAAU,+BAA+B;IACrC,UAAU,CAAC,EAAE;QACT,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;CACL;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB;IAC5B;;;;;;;;;;OAUG;;0BAGK,aAAa,SAAS,sBAAsB,EAC5C,MAAM,SAAS,aAAa,EAC5B,QAAQ,SAAS,YAAY,GAAG,WAAW,EAC3C,YAAY,YACZ,aAAa;2BAAqC,MAAM,CAAC;kCAEhD,qBAAqB,CAAC,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,aAAa,CAAC;YAE5F;;;;;;eAMG;qBAEC,OAAO,SAAS,aAAa,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,WACvC,OAAO,YAAY,aAAa;gBA2D3C;;;;mBAIG;wBACK,CAAC,SAAS,MAAM;gBAgCxB;;;;;;mBAMG;iCACc,MAAM,SAAS,MAAM,UAAU,MAAM;gBA8BtD;;;;mBAIG;;;YA/HH;;;;;;eAMG;6BACa,WAAW;gBA0C3B;;;;mBAIG;wBACK,CAAC,SAAS,MAAM;gBAgCxB;;;;;;mBAMG;iCACc,MAAM,SAAS,MAAM,UAAU,MAAM;gBA8BtD;;;;mBAIG;;;YApHH;;;;;eAKG;;gBAiCH;;;;mBAIG;wBACK,CAAC,SAAS,MAAM;gBAgCxB;;;;;;mBAMG;iCACc,MAAM,SAAS,MAAM,UAAU,MAAM;gBA8BtD;;;;mBAIG;;;;;IAxGX;;;;;;;;;;;OAWG;;0BAGK,aAAa,SAAS,sBAAsB,EAC5C,MAAM,SAAS,aAAa,EAC5B,GAAG,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,MAAM,EACN,YAAY,YACZ,aAAa,YACb,MAAM,qBAEG,sBAAsB,CAAC,aAAa,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,CAAC,YAC/F,+BAA+B;YAGxC;;;;eAIG;oBACK,CAAC,SAAS,MAAM,mBAAmB,MAAM,CAAC,CAAC,CAAC;YAgCpD;;;;;;eAMG;6BACc,MAAM,SAAS,MAAM,UAAU,MAAM;YA8BtD;;;;eAIG;;;;CAoBL,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { GenericDatabase } from './database';
|
|
2
|
+
import { KeyOfString } from './utils';
|
|
3
|
+
export type SchemaName<D extends GenericDatabase> = Exclude<KeyOfString<D>, '__InternalSupabase'>;
|
|
4
|
+
export type RelationType = 'Tables' | 'Views';
|
|
5
|
+
export type RelationName<D extends GenericDatabase<S>, S extends SchemaName<D> = SchemaName<D>, R extends RelationType = RelationType> = KeyOfString<D[S][R]>;
|
|
6
|
+
export type TableName<D extends GenericDatabase<S>, S extends SchemaName<D> = SchemaName<D>> = RelationName<D, S, 'Tables'>;
|
|
7
|
+
export type ViewName<D extends GenericDatabase<S>, S extends SchemaName<D> = SchemaName<D>> = RelationName<D, S, 'Views'>;
|
|
8
|
+
export type ColumnName<D extends GenericDatabase<S>, S extends SchemaName<D> = SchemaName<D>, R extends RelationType = RelationType, T extends RelationName<D, S, R> = RelationName<D, S, R>> = KeyOfString<D[S][R][T]['Row']>;
|
|
9
|
+
export type TableColumnName<D extends GenericDatabase<S>, S extends SchemaName<D> = SchemaName<D>, T extends TableName<D, S> = TableName<D, S>> = ColumnName<D, S, 'Tables', T>;
|
|
10
|
+
export type ViewColumnName<D extends GenericDatabase<S>, S extends SchemaName<D> = SchemaName<D>, V extends ViewName<D, S> = ViewName<D, S>> = ColumnName<D, S, 'Views', V>;
|
|
11
|
+
export type Relation<D extends GenericDatabase<KeyOfString<D>>, S extends SchemaName<D>, R extends RelationType, T extends RelationName<D, S, R>> = D[S][R][T] extends {
|
|
12
|
+
Row: infer R;
|
|
13
|
+
Insert?: infer I;
|
|
14
|
+
Update?: infer U;
|
|
15
|
+
Relationships: infer Rel;
|
|
16
|
+
} ? {
|
|
17
|
+
Row: R;
|
|
18
|
+
Insert: I;
|
|
19
|
+
Update: U;
|
|
20
|
+
Relationships: Rel;
|
|
21
|
+
} : never;
|
|
22
|
+
export type Row<D extends GenericDatabase<KeyOfString<D>>, S extends SchemaName<D>, R extends RelationType, T extends RelationName<D, S, R>> = Relation<D, S, R, T>['Row'];
|
|
23
|
+
export type Insert<D extends GenericDatabase<KeyOfString<D>>, S extends SchemaName<D>, R extends RelationType, T extends RelationName<D, S, R>> = Relation<D, S, R, T>['Insert'];
|
|
24
|
+
export type Update<D extends GenericDatabase<KeyOfString<D>>, S extends SchemaName<D>, R extends RelationType, T extends RelationName<D, S, R>> = Relation<D, S, R, T>['Update'];
|
|
25
|
+
export type Relationships<D extends GenericDatabase<KeyOfString<D>>, S extends SchemaName<D>, R extends RelationType, T extends RelationName<D, S, R>> = Relation<D, S, R, T>['Relationships'];
|
|
26
|
+
export type ID<D extends GenericDatabase<KeyOfString<D>>, S extends SchemaName<D>, R extends RelationType, T extends RelationName<D, S, R>> = Row<D, S, R, T> extends {
|
|
27
|
+
id: infer ID;
|
|
28
|
+
} ? ID : never;
|
|
29
|
+
//# sourceMappingURL=relation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relation.d.ts","sourceRoot":"","sources":["../lib/relation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAG3C,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,eAAe,IAAI,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,oBAAoB,CAAC,CAAC;AAElG,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,OAAO,CAAC;AAC9C,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,YAAY,GAAG,YAAY,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9J,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,IAAI,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC;AAC5H,MAAM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,CAAC,SAAS,eAAe,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EACzC,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,EACvB,CAAC,SAAS,YAAY,EACtB,CAAC,SAAS,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,IAC/B,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;AAEnC,MAAM,MAAM,aAAa,CACrB,CAAC,SAAS,eAAe,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EACzC,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,EACvB,CAAC,SAAS,YAAY,EACtB,CAAC,SAAS,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,IAC/B,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC;AAE1C,MAAM,MAAM,EAAE,CACV,CAAC,SAAS,eAAe,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EACzC,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,EACvB,CAAC,SAAS,YAAY,EACtB,CAAC,SAAS,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,IAC/B,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,EAAE,CAAA;CAAE,GAAG,EAAE,GAAG,KAAK,CAAC"}
|
package/dist/select.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The method to use to count rows returned by the function.
|
|
3
|
+
* - `exact`: Counts the rows exactly.
|
|
4
|
+
* - `planned`: Uses statistics to get a fairly accurate and fast count.
|
|
5
|
+
* - `estimated`: Uses an estimated count which is the exact count up until a threshold and the planned count when that threshold is surpassed.
|
|
6
|
+
*
|
|
7
|
+
* @see https://docs.postgrest.org/en/v12/references/api/pagination_count.html#counting
|
|
8
|
+
*/
|
|
9
|
+
export type CountMethod = 'exact' | 'planned' | 'estimated';
|
|
10
|
+
/**
|
|
11
|
+
* Options for selecting rows from a database table.
|
|
12
|
+
*/
|
|
13
|
+
export interface SelectOptions {
|
|
14
|
+
/**
|
|
15
|
+
* When set to `true`, `data` will not be returned, useful if you only need the count.
|
|
16
|
+
*/
|
|
17
|
+
head?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* The method to use to count rows returned by the function.
|
|
20
|
+
* If not set, no count will be performed.
|
|
21
|
+
*/
|
|
22
|
+
count?: CountMethod;
|
|
23
|
+
}
|
|
24
|
+
export type SelectColumns<Row> = (keyof Row)[] | '*';
|
|
25
|
+
export type Select<Row, Columns extends SelectColumns<Row> = SelectColumns<Row>> = Pick<Row, Columns extends '*' ? keyof Row : Columns[number]>;
|
|
26
|
+
//# sourceMappingURL=select.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../lib/select.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,SAAS,GAAG,WAAW,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,aAAa;IAC1B;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf;;;OAGG;IACH,KAAK,CAAC,EAAE,WAAW,CAAC;CACvB;AAED,MAAM,MAAM,aAAa,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,GAAG,GAAG,CAAC;AACrD,MAAM,MAAM,MAAM,CACd,GAAG,EACH,OAAO,SAAS,aAAa,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC,GAAG,CAAC,IACvD,IAAI,CAAC,GAAG,EAAE,OAAO,SAAS,GAAG,GAAG,MAAM,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { SearchV2Folder, SearchV2Object, SearchV2Options, StorageClient as SupabaseStorageClient } from '@supabase/storage-js';
|
|
2
|
+
import { DatabaseService } from './database-service';
|
|
3
|
+
import { FileInfo, PublicURLOptions, StorageInfo, StorageLocation } from './storage';
|
|
4
|
+
import { MaybeArray } from './utils';
|
|
5
|
+
export declare class StorageClient<BucketName extends string = string> extends SupabaseStorageClient {
|
|
6
|
+
from(bucket: BucketName | (string & {})): ReturnType<SupabaseStorageClient['from']>;
|
|
7
|
+
}
|
|
8
|
+
export interface StorageServiceParams<BucketName extends string = string> {
|
|
9
|
+
client: StorageClient<BucketName>;
|
|
10
|
+
database: DatabaseService<any>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Service for interacting with supabase storage.
|
|
14
|
+
*/
|
|
15
|
+
export declare class StorageService<BucketName extends string = string> {
|
|
16
|
+
private readonly client;
|
|
17
|
+
private readonly database;
|
|
18
|
+
constructor({ client, database, }: StorageServiceParams<BucketName>);
|
|
19
|
+
private get files();
|
|
20
|
+
uploadFile({ bucket, path, file, overwriteExisting, }: {
|
|
21
|
+
file: File;
|
|
22
|
+
bucket: BucketName;
|
|
23
|
+
path: string;
|
|
24
|
+
overwriteExisting?: boolean;
|
|
25
|
+
}): Promise<StorageLocation>;
|
|
26
|
+
downloadFile(params: {
|
|
27
|
+
bucket: BucketName;
|
|
28
|
+
path: string;
|
|
29
|
+
properties?: FilePropertyBag;
|
|
30
|
+
} | {
|
|
31
|
+
fileId: string;
|
|
32
|
+
}): Promise<File>;
|
|
33
|
+
deleteFiles(params: MaybeArray<{
|
|
34
|
+
bucket: BucketName;
|
|
35
|
+
paths: string | string[];
|
|
36
|
+
}> | {
|
|
37
|
+
fileIds: string[];
|
|
38
|
+
}): Promise<StorageLocation[]>;
|
|
39
|
+
existsFile(params: {
|
|
40
|
+
bucket: BucketName;
|
|
41
|
+
path: string;
|
|
42
|
+
} | {
|
|
43
|
+
fileId: string;
|
|
44
|
+
}): Promise<boolean>;
|
|
45
|
+
assertExistsFile(params: {
|
|
46
|
+
bucket: BucketName;
|
|
47
|
+
path: string;
|
|
48
|
+
} | {
|
|
49
|
+
fileId: string;
|
|
50
|
+
}): Promise<void>;
|
|
51
|
+
getFiles({ bucket, ...options }: {
|
|
52
|
+
bucket: BucketName;
|
|
53
|
+
} & SearchV2Options): Promise<{
|
|
54
|
+
hasNext: boolean;
|
|
55
|
+
folders: SearchV2Folder[];
|
|
56
|
+
objects: SearchV2Object[];
|
|
57
|
+
nextCursor?: string;
|
|
58
|
+
}>;
|
|
59
|
+
getFileStorageInfo(fileId: string): Promise<StorageInfo>;
|
|
60
|
+
getFileInfo(params: {
|
|
61
|
+
bucket: BucketName;
|
|
62
|
+
path: string;
|
|
63
|
+
} | {
|
|
64
|
+
fileId: string;
|
|
65
|
+
}): Promise<FileInfo>;
|
|
66
|
+
getPublicURL({ transform, download, ...params }: ({
|
|
67
|
+
bucket: BucketName;
|
|
68
|
+
path: string;
|
|
69
|
+
} | {
|
|
70
|
+
fileId: string;
|
|
71
|
+
}) & PublicURLOptions): Promise<string>;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=storage-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-service.d.ts","sourceRoot":"","sources":["../lib/storage-service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5F,OAAO,EAAE,aAAa,IAAI,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAE9E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1D,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE1F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAI1C,MAAM,CAAC,OAAO,OAAO,a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|
+
import { StorageObjectMetadata, StorageObjectsTable } from './database';
|
|
3
|
+
export type StorageObject = StorageObjectsTable['Row'];
|
|
4
|
+
export type FileInfo = Camelize<FileObjectV2>;
|
|
5
|
+
export interface PublicURLOptions {
|
|
6
|
+
download?: string | boolean;
|
|
7
|
+
transform?: TransformOptions;
|
|
8
|
+
}
|
|
9
|
+
export interface StorageLocation {
|
|
10
|
+
id: string;
|
|
11
|
+
bucket: string;
|
|
12
|
+
path: string;
|
|
13
|
+
}
|
|
14
|
+
export interface StorageInfo extends StorageLocation {
|
|
15
|
+
metadata: StorageObjectMetadata;
|
|
16
|
+
properties: FilePropertyBag;
|
|
17
|
+
}
|
|
18
|
+
export declare function toStorageLocation(object: Pick<StorageObject, 'id' | 'bucket_id' | 'path_tokens'>): StorageLocation;
|
|
19
|
+
export declare function toStorageInfo(object: Pick<StorageObject, 'id' | 'bucket_id' | 'path_tokens' | 'metadata'>): StorageInfo;
|
|
20
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../lib/storage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAErF,OAAO,KAAK,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAG7E,MAAM,MAAM,aAAa,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;AACvD,MAAM,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC;AAE9C,MAAM,WAAW,gBAAgB;IAC7B,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC5B,SAAS,CAAC,EAAE,gBAAgB,CAAC;CAChC;AAED,MAAM,WAAW,eAAe;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,WAAY,SAAQ,eAAe;IAChD,QAAQ,EAAE,qBAAqB,CAAC;IAChC,UAAU,EAAE,eAAe,CAAC;CAC/B;AAED,wBAAgB,iBAAiB,CAC7B,MAAM,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,GAAG,WAAW,GAAG,aAAa,CAAC,GAChE,eAAe,CAMjB;AAED,wBAAgB,aAAa,CACzB,MAAM,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,GAAG,WAAW,GAAG,aAAa,GAAG,UAAU,CAAC,GAC7E,WAAW,CAUb"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typesafe and autocompleting version of `Omit` that omits keys from a base type.
|
|
3
|
+
*/
|
|
4
|
+
export type OmitFrom<Base, Keys extends keyof Base> = Omit<Base, Keys>;
|
|
5
|
+
/**
|
|
6
|
+
* A type for keys that excludes symbols and numbers.
|
|
7
|
+
* This is useful for objects with string keys only.
|
|
8
|
+
* @template T The type to extract keys from.
|
|
9
|
+
*/
|
|
10
|
+
export type KeyOfString<T> = Exclude<keyof T, symbol | number>;
|
|
11
|
+
/**
|
|
12
|
+
* Extracts the element type from an array type.
|
|
13
|
+
* If the type is not an array, it returns the type itself.
|
|
14
|
+
*
|
|
15
|
+
* @template T - The type to extract the element from.
|
|
16
|
+
* @returns The element type if T is an array, otherwise T itself.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* type MyArray = number[];
|
|
20
|
+
* type Element = ElementOf<MyArray>; // number
|
|
21
|
+
*
|
|
22
|
+
* type MyType = string;
|
|
23
|
+
* type Element2 = ElementOf<MyType>; // string
|
|
24
|
+
*/
|
|
25
|
+
export type ElementOf<T> = T extends (infer U)[] ? U : T;
|
|
26
|
+
/**
|
|
27
|
+
* Equivalent to `T | T[]`, used to indicate that a value can be either a single item or an array of items.
|
|
28
|
+
*/
|
|
29
|
+
export type MaybeArray<T> = T | T[];
|
|
30
|
+
/**
|
|
31
|
+
* Splits a path into its directory and file name components.
|
|
32
|
+
* @param path The path to split.
|
|
33
|
+
* @param separator The separator to use for splitting. Defaults to '/'.
|
|
34
|
+
* To split at the extension, you can pass '.' as the separator.
|
|
35
|
+
* @returns The directory and file name as a tuple.
|
|
36
|
+
* If no separator is found, the first element will be an empty string and the second will be the entire path.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* splitPath('/path/to/file.txt'); // returns ['/path/to', 'file.txt']
|
|
40
|
+
* splitPath('file.txt'); // returns ['', 'file.txt']
|
|
41
|
+
* splitPath('path/to/file.txt', '.'); // returns ['path/to/file', 'txt']
|
|
42
|
+
*/
|
|
43
|
+
export declare function splitPath(path: string, separator?: string): [string, string];
|
|
44
|
+
/**
|
|
45
|
+
* Returns the input as an array if it is not already an array.
|
|
46
|
+
* @param input The input to coerce into an array.
|
|
47
|
+
* @returns The input as an array.
|
|
48
|
+
*/
|
|
49
|
+
export declare function coerceArray<T>(input: MaybeArray<T>): T[];
|
|
50
|
+
/**
|
|
51
|
+
* Groups an array of items by a key function.
|
|
52
|
+
* @param items The array of items to group.
|
|
53
|
+
* @param groupFn The function that extracts the grouping key from each item.
|
|
54
|
+
* @returns The grouped items as a record where keys are the grouping keys and values are the grouped items.
|
|
55
|
+
*/
|
|
56
|
+
export declare function groupBy<T, G extends PropertyKey>(items: T[], groupFn: (item: T) => G): Record<G, T[]>;
|
|
57
|
+
/**
|
|
58
|
+
* Extracts entries from an object as tuples of key-value pairs.
|
|
59
|
+
* This is a typesafe version of `Object.entries` that preserves the types of the keys and values.
|
|
60
|
+
*
|
|
61
|
+
* @template T The type of the object from which to extract entries.
|
|
62
|
+
* @param obj The object from which to extract entries.
|
|
63
|
+
* @returns The entries of the object as tuples of key-value pairs.
|
|
64
|
+
*/
|
|
65
|
+
export declare function entries<T extends object>(obj: T): [keyof T, T[keyof T]][];
|
|
66
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0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{
|
|
2
|
+
"name": "@freehour/supabase-core",
|
|
3
|
+
"private": false,
|
|
4
|
+
"displayName": "Supabase-Core",
|
|
5
|
+
"description": "Core services for Supabase",
|
|
6
|
+
"version": "1.0.0",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/freehour/supabase-core.git"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"lint": "eslint ./lib --ext ts",
|
|
14
|
+
"build": "bun run lint && tsc && vite build",
|
|
15
|
+
"postinstall": "bun ./scripts/copy-supabase-assets.js"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"supabase/migrations",
|
|
20
|
+
"supabase/schemas",
|
|
21
|
+
"scripts"
|
|
22
|
+
],
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"import": "./dist/index.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@freehour/assert": "1.0.0",
|
|
31
|
+
"@supabase/storage-js": "^2.99.3",
|
|
32
|
+
"@supabase/supabase-js": "2.99.3",
|
|
33
|
+
"zod": "4.3.6"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@stylistic/eslint-plugin-js": "2.10.1",
|
|
37
|
+
"@stylistic/eslint-plugin-plus": "2.10.1",
|
|
38
|
+
"@stylistic/eslint-plugin-ts": "2.10.1",
|
|
39
|
+
"@typescript-eslint/eslint-plugin": "8.14.0",
|
|
40
|
+
"@typescript-eslint/parser": "8.14.0",
|
|
41
|
+
"ajv": "^8.18.0",
|
|
42
|
+
"bun-types": "^1.3.11",
|
|
43
|
+
"eslint": "8.57.1",
|
|
44
|
+
"eslint-import-resolver-typescript": "3.6.3",
|
|
45
|
+
"eslint-plugin-import-x": "4.4.3",
|
|
46
|
+
"eslint-plugin-simple-import-sort": "12.1.1",
|
|
47
|
+
"supabase": "^2.83.0",
|
|
48
|
+
"typescript": "^5.9.3",
|
|
49
|
+
"vite": "^7.3.1",
|
|
50
|
+
"vite-plugin-dts": "^4.5.4",
|
|
51
|
+
"vite-tsconfig-paths": "^5.1.4"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// scripts/copy-supabase-assets.js
|
|
2
|
+
// Copies migrations and schemas from @freehour/supabase-core to ./supabase in the consuming package
|
|
3
|
+
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
import { dirname, join, resolve } from 'path';
|
|
6
|
+
import { copyFileSync, mkdirSync, existsSync, readdirSync, statSync } from 'fs';
|
|
7
|
+
|
|
8
|
+
// Get the directory of this script
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = dirname(__filename);
|
|
11
|
+
|
|
12
|
+
// Find the package root (assume script is in node_modules/@freehour/supabase-core/scripts)
|
|
13
|
+
const packageRoot = resolve(__dirname, '..', '..');
|
|
14
|
+
const sourceDir = join(packageRoot, 'supabase');
|
|
15
|
+
const destDir = resolve(process.cwd(), 'supabase');
|
|
16
|
+
|
|
17
|
+
function copyRecursive(src, dest) {
|
|
18
|
+
if (!existsSync(src)) return;
|
|
19
|
+
const stats = statSync(src);
|
|
20
|
+
if (stats.isDirectory()) {
|
|
21
|
+
if (!existsSync(dest)) mkdirSync(dest, { recursive: true });
|
|
22
|
+
for (const file of readdirSync(src)) {
|
|
23
|
+
copyRecursive(join(src, file), join(dest, file));
|
|
24
|
+
}
|
|
25
|
+
} else {
|
|
26
|
+
copyFileSync(src, dest);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Copy migrations and schemas folders
|
|
31
|
+
for (const folder of ['migrations', 'schemas']) {
|
|
32
|
+
const src = join(sourceDir, folder);
|
|
33
|
+
const dest = join(destDir, folder);
|
|
34
|
+
copyRecursive(src, dest);
|
|
35
|
+
console.log(`Copied ${src} -> ${dest}`);
|
|
36
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
create extension if not exists "pg_trgm" with schema "extensions";
|
|
2
|
+
|
|
3
|
+
create schema if not exists "core";
|
|
4
|
+
|
|
5
|
+
set check_function_bodies = off;
|
|
6
|
+
|
|
7
|
+
CREATE OR REPLACE FUNCTION core.fuzzy_search(relation text, column_name text, search_term text, schema_name text DEFAULT 'public'::text, min_similarity double precision DEFAULT 0, limit_results integer DEFAULT 64)
|
|
8
|
+
RETURNS SETOF json
|
|
9
|
+
LANGUAGE plpgsql
|
|
10
|
+
STABLE
|
|
11
|
+
SET search_path TO ''
|
|
12
|
+
AS $function$
|
|
13
|
+
DECLARE
|
|
14
|
+
query text;
|
|
15
|
+
BEGIN
|
|
16
|
+
IF search_term = '' THEN
|
|
17
|
+
query := format(
|
|
18
|
+
$q$
|
|
19
|
+
SELECT row_to_json(t) AS result
|
|
20
|
+
FROM (
|
|
21
|
+
SELECT *
|
|
22
|
+
FROM %I.%I
|
|
23
|
+
LIMIT %s
|
|
24
|
+
) t
|
|
25
|
+
$q$,
|
|
26
|
+
schema_name,
|
|
27
|
+
relation,
|
|
28
|
+
limit_results
|
|
29
|
+
);
|
|
30
|
+
ELSE
|
|
31
|
+
query := format(
|
|
32
|
+
$q$
|
|
33
|
+
SELECT row_to_json(t) AS result
|
|
34
|
+
FROM (
|
|
35
|
+
SELECT *
|
|
36
|
+
FROM (
|
|
37
|
+
SELECT *, extensions.similarity(lower(%I), lower(%L)) AS score
|
|
38
|
+
FROM %I.%I
|
|
39
|
+
) s
|
|
40
|
+
WHERE score > %s
|
|
41
|
+
ORDER BY score DESC
|
|
42
|
+
LIMIT %s
|
|
43
|
+
) t
|
|
44
|
+
$q$,
|
|
45
|
+
column_name,
|
|
46
|
+
search_term,
|
|
47
|
+
schema_name,
|
|
48
|
+
relation,
|
|
49
|
+
min_similarity,
|
|
50
|
+
limit_results
|
|
51
|
+
);
|
|
52
|
+
END IF;
|
|
53
|
+
RETURN QUERY EXECUTE query;
|
|
54
|
+
END;
|
|
55
|
+
$function$
|
|
56
|
+
;
|
|
57
|
+
|
|
58
|
+
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
-- This file includes SQL commands for the core schema.
|
|
2
|
+
-- This schame is used by services in the core directory and is independent of the specific application logic.
|
|
3
|
+
|
|
4
|
+
-- Ensure the schema exists
|
|
5
|
+
CREATE SCHEMA IF NOT EXISTS core;
|
|
6
|
+
|
|
7
|
+
-- Grant access privileges
|
|
8
|
+
GRANT USAGE ON SCHEMA core TO "anon";
|
|
9
|
+
GRANT USAGE ON SCHEMA core TO "authenticated";
|
|
10
|
+
GRANT USAGE ON SCHEMA core TO "service_role";
|
|
11
|
+
|