@freehour/supabase-core 1.0.0 → 1.0.2

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
- ## Supa Core
1
+ ## Supabase Core
2
2
 
3
- This package provides lightweight wrappers around the Supabase client to make it easier to work with databases, tables and storage buckets.
3
+ This package provides lightweight services to supabase to make it easier to work with databases, tables and storage buckets.
4
4
 
5
5
  ### Installation
6
6
 
@@ -16,7 +16,20 @@ or
16
16
  bun install @freehour/supabase-core
17
17
  ```
18
18
 
19
- Copy the
19
+ Add `schemas/supabase-core/*.sql` to your `schema_paths` in `supabase/config.toml`:
20
+
21
+ ```toml
22
+ schema_paths = ["./schemas/supabase-core/*.sql", /* your app schema paths */]
23
+ ```
24
+
25
+ ### Building
26
+
27
+ To build the package, run the following command:
28
+
29
+ ```bash
30
+ bun run build
31
+ ```
32
+
20
33
 
21
34
 
22
35
 
@@ -90,7 +90,7 @@ export interface CoreSchema extends GenericSchema {
90
90
  }
91
91
  export interface CoreDatabase {
92
92
  storage: StorageSchema;
93
- core: CoreSchema;
93
+ supabase_core: CoreSchema;
94
94
  }
95
95
  export type BaseDatabase<Database> = GenericDatabase<KeyOfString<Database>> & CoreDatabase;
96
96
  //# sourceMappingURL=database.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../lib/database.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAG3C,MAAM,WAAW,mBAAmB;IAChC,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,iBAAiB,EAAE,MAAM,EAAE,CAAC;CAC/B;AAED,MAA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ED,MAAM,MAAM,YAAY,CAAC,QAAQ,IAAI,eAAe,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,GAAG,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { assert as o } from "@freehour/assert";
2
2
  import d from "zod";
3
- import { PostgrestError as S } from "@supabase/supabase-js";
3
+ import { PostgrestError as _ } from "@supabase/supabase-js";
4
4
  class k extends Error {
5
5
  constructor(t, e = {}) {
6
6
  super(t, e), this.name = this.constructor.name, Error.captureStackTrace(this, this.constructor);
@@ -44,7 +44,7 @@ class q extends k {
44
44
  super(t, n), this.expression = e, this.format = a;
45
45
  }
46
46
  }
47
- class _ extends k {
47
+ class S extends k {
48
48
  /**
49
49
  * The schema where the record was expected to be found.
50
50
  */
@@ -73,7 +73,7 @@ const $ = d.object({
73
73
  message: d.string().optional()
74
74
  });
75
75
  function V(r) {
76
- return r instanceof S || $.safeParse(r).success;
76
+ return r instanceof _ || $.safeParse(r).success;
77
77
  }
78
78
  const I = ["eq", "neq", "gt", "gte", "lt", "lte", "like", "ilike", "match", "imatch", "in", "is", "isdistinct", "fts", "plfts", "phfts", "wfts", "cs", "cd", "ov", "sl", "sr", "nxr", "nxl", "adj"], Z = ["and", "or"], G = ",", v = "~", H = (r) => (t = {}) => {
79
79
  const e = (n) => t[n] ?? n, a = Object.keys(r.shape);
@@ -331,7 +331,7 @@ class F {
331
331
  this.database = t, this.schema = e, this.relation = a;
332
332
  }
333
333
  recordNotFoundError(t) {
334
- return new _(`Record with id ${t} not found in ${this.schema}.${this.relation}`, {
334
+ return new S(`Record with id ${t} not found in ${this.schema}.${this.relation}`, {
335
335
  schema: this.schema,
336
336
  relation: this.relation,
337
337
  id: t
@@ -358,7 +358,7 @@ class F {
358
358
  minSimilarity: a = 0,
359
359
  limit: n = 64
360
360
  }) {
361
- const { data: s } = await this.database.schema("core").rpc("fuzzy_search", {
361
+ const { data: s } = await this.database.schema("supabase_core").rpc("fuzzy_search", {
362
362
  relation: this.relation,
363
363
  schema_name: this.schema,
364
364
  column_name: t,
@@ -672,7 +672,7 @@ export {
672
672
  G as LogicalOpSeparator,
673
673
  q as ParseError,
674
674
  $ as PostgrestErrorInterface,
675
- _ as RecordNotFoundError,
675
+ S as RecordNotFoundError,
676
676
  X as StorageService,
677
677
  M as TableDataService,
678
678
  k as TracedError,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "private": false,
4
4
  "displayName": "Supabase-Core",
5
5
  "description": "Core services for Supabase",
6
- "version": "1.0.0",
6
+ "version": "1.0.2",
7
7
  "type": "module",
8
8
  "repository": {
9
9
  "type": "git",
@@ -10,27 +10,51 @@ const __filename = fileURLToPath(import.meta.url);
10
10
  const __dirname = dirname(__filename);
11
11
 
12
12
  // Find the package root (assume script is in node_modules/@freehour/supabase-core/scripts)
13
- const packageRoot = resolve(__dirname, '..', '..');
13
+ const packageRoot = resolve(__dirname, '..');
14
14
  const sourceDir = join(packageRoot, 'supabase');
15
- const destDir = resolve(process.cwd(), 'supabase');
15
+ const destDir = resolve(packageRoot, '..', '..', '..', 'supabase');
16
16
 
17
17
  function copyRecursive(src, dest) {
18
- if (!existsSync(src)) return;
19
- const stats = statSync(src);
18
+ if (!existsSync(src)) {
19
+ console.warn(`[WARN] Source does not exist: ${src}`);
20
+ return;
21
+ }
22
+ let stats;
23
+ try {
24
+ stats = statSync(src);
25
+ } catch (err) {
26
+ console.error(`[ERROR] Failed to stat: ${src}`, err);
27
+ return;
28
+ }
20
29
  if (stats.isDirectory()) {
21
- if (!existsSync(dest)) mkdirSync(dest, { recursive: true });
30
+ if (!existsSync(dest)) {
31
+ try {
32
+ mkdirSync(dest, { recursive: true });
33
+ console.log(`[INFO] Created directory: ${dest}`);
34
+ } catch (err) {
35
+ console.error(`[ERROR] Failed to create directory: ${dest}`, err);
36
+ return;
37
+ }
38
+ }
22
39
  for (const file of readdirSync(src)) {
23
40
  copyRecursive(join(src, file), join(dest, file));
24
41
  }
25
42
  } else {
26
- copyFileSync(src, dest);
43
+ try {
44
+ copyFileSync(src, dest);
45
+ console.log(`[INFO] Copied file: ${src} -> ${dest}`);
46
+ } catch (err) {
47
+ console.error(`[ERROR] Failed to copy file: ${src} -> ${dest}`, err);
48
+ }
27
49
  }
28
50
  }
29
51
 
52
+ if (process.env.INIT_CWD === process.cwd())
53
+ process.exit(); // Prevent running in the package root
54
+
30
55
  // Copy migrations and schemas folders
31
56
  for (const folder of ['migrations', 'schemas']) {
32
57
  const src = join(sourceDir, folder);
33
58
  const dest = join(destDir, folder);
34
59
  copyRecursive(src, dest);
35
- console.log(`Copied ${src} -> ${dest}`);
36
60
  }
@@ -1,10 +1,10 @@
1
1
  create extension if not exists "pg_trgm" with schema "extensions";
2
2
 
3
- create schema if not exists "core";
3
+ create schema if not exists "supabase_core";
4
4
 
5
5
  set check_function_bodies = off;
6
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)
7
+ CREATE OR REPLACE FUNCTION supabase_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
8
  RETURNS SETOF json
9
9
  LANGUAGE plpgsql
10
10
  STABLE
@@ -1,11 +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.
1
+ -- This file includes SQL commands for the supabase_core schema.
2
+ -- This schema is used by services of the supabase-core package.
3
3
 
4
4
  -- Ensure the schema exists
5
- CREATE SCHEMA IF NOT EXISTS core;
5
+ CREATE SCHEMA IF NOT EXISTS supabase_core;
6
6
 
7
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";
8
+ GRANT USAGE ON SCHEMA supabase_core TO "anon";
9
+ GRANT USAGE ON SCHEMA supabase_core TO "authenticated";
10
+ GRANT USAGE ON SCHEMA supabase_core TO "service_role";
11
11
 
@@ -1,5 +1,3 @@
1
- -- enable the "vector" extension for embeddings
2
-
3
- -- Ensure required extensions are installed in the `extensions` schema
1
+ -- enable the "pg_trgm" extension for fuzzy text search
4
2
  CREATE EXTENSION IF NOT EXISTS pg_trgm WITH SCHEMA extensions;
5
3
 
@@ -1,7 +1,7 @@
1
1
  -- Function to perform a fuzzy search on a specified table and column.
2
2
  -- It returns records where the similarity score exceeds a specified threshold (optional).
3
3
  -- The results are ordered by similarity score in descending order.
4
- CREATE OR REPLACE FUNCTION core.fuzzy_search(
4
+ CREATE OR REPLACE FUNCTION supabase_core.fuzzy_search(
5
5
  relation text, -- The name of the table or view to search
6
6
  column_name text,
7
7
  search_term text,