@aurabase/aurabase-js 0.5.1 → 0.5.3

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
@@ -20,7 +20,7 @@ Ce package ne réimplémente aucune logique de service : il compose `AuthService
20
20
 
21
21
  - `createClient(projectUrl, apiKey, options?)` — client applicatif standard. **L'URL est le projet** : chaque projet est servi sur son propre sous-domaine (`https://<slug>.aurabase.cloud`) et la passerelle injecte elle-même le `project_id` dans le chemin. Aucun identifiant de projet dans le code client.
22
22
  - `createAdminClient(projectUrl, serviceRoleKey, options?)` — client serveur avec `authAdmin` (clé `service_role`, jamais côté navigateur).
23
- - `aurabase/ssr` — `createServerClient`/`createBrowserClient` pour Next.js et frameworks SSR (cookies, session partagée serveur/navigateur).
23
+ - `@aurabase/aurabase-js/ssr` — `createServerClient`/`createBrowserClient` pour Next.js et frameworks SSR (cookies, session partagée serveur/navigateur).
24
24
 
25
25
  ## Quick Start
26
26
 
@@ -1,7 +1,7 @@
1
1
  import { AiService } from '@aurabase/ai';
2
2
  import { AuthService, AuthAdminService } from '@aurabase/auth';
3
3
  import { AuraClientLike, BaseAuthStore, AuraObservabilityEvent, AuraClientOptions, ChannelConfig } from '@aurabase/core';
4
- import { DatabaseService } from '@aurabase/db';
4
+ import { GenericSchema, DatabaseService, AuraQueryBuilder, AuraClientOptionsT } from '@aurabase/db';
5
5
  import { FunctionsService } from '@aurabase/functions';
6
6
  import { NotificationsService } from '@aurabase/notifications';
7
7
  import { RealtimeService, AuraChannel } from '@aurabase/realtime';
@@ -23,7 +23,9 @@ import { StorageService } from '@aurabase/storage';
23
23
  * const { data } = await aura.db.from('posts').eq('published', true)
24
24
  * ```
25
25
  */
26
- declare class AuraClient<Database = any> implements AuraClientLike {
26
+ declare class AuraClient<Database = any, Schema extends GenericSchema = Database extends {
27
+ public: infer S;
28
+ } ? S extends GenericSchema ? S : any : any> implements AuraClientLike {
27
29
  /** URL du projet (`https://<slug>.aurabase.cloud`), sans barre finale. */
28
30
  readonly baseUrl: string;
29
31
  readonly apiKey: string | null;
@@ -64,12 +66,34 @@ declare class AuraClient<Database = any> implements AuraClientLike {
64
66
  dispose(): void;
65
67
  get auth(): AuthService;
66
68
  get authAdmin(): AuthAdminService;
67
- get db(): DatabaseService<Database>;
69
+ get db(): DatabaseService<Database, Schema>;
68
70
  get storage(): StorageService;
69
71
  get realtime(): RealtimeService;
70
72
  get functions(): FunctionsService;
71
73
  get ai(): AiService;
72
74
  get notifications(): NotificationsService;
75
+ /**
76
+ * Shortcut: query a database table or view (Supabase-compatible API).
77
+ * Equivalent to `aura.db.from(table)`.
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * const { data, error } = await aura.from('posts').select('*').limit(10)
82
+ * ```
83
+ */
84
+ from<TableName extends string & keyof Schema['Tables'], Table extends Schema['Tables'][TableName]>(table: TableName): AuraQueryBuilder<Schema, Table, TableName, AuraClientOptionsT>;
85
+ from<ViewName extends string & keyof Schema['Views'], View extends Schema['Views'][ViewName]>(view: ViewName): AuraQueryBuilder<Schema, View, ViewName, AuraClientOptionsT>;
86
+ from(table: string): AuraQueryBuilder<any, any, any, AuraClientOptionsT>;
87
+ /**
88
+ * Shortcut: call a stored procedure / PostgreSQL function via RPC (Supabase-compatible API).
89
+ * Equivalent to `aura.db.rpc(fn, args, options)`.
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * const { data, error } = await aura.rpc('echo_test', { message: 'hello' })
94
+ * ```
95
+ */
96
+ rpc<T = any>(fn: string, args?: Record<string, unknown>, options?: any): any;
73
97
  /**
74
98
  * Shortcut: create a realtime channel with Supabase-compatible API.
75
99
  * Equivalent to `aura.realtime.channel(name)`.
@@ -1,7 +1,7 @@
1
1
  import { AiService } from '@aurabase/ai';
2
2
  import { AuthService, AuthAdminService } from '@aurabase/auth';
3
3
  import { AuraClientLike, BaseAuthStore, AuraObservabilityEvent, AuraClientOptions, ChannelConfig } from '@aurabase/core';
4
- import { DatabaseService } from '@aurabase/db';
4
+ import { GenericSchema, DatabaseService, AuraQueryBuilder, AuraClientOptionsT } from '@aurabase/db';
5
5
  import { FunctionsService } from '@aurabase/functions';
6
6
  import { NotificationsService } from '@aurabase/notifications';
7
7
  import { RealtimeService, AuraChannel } from '@aurabase/realtime';
@@ -23,7 +23,9 @@ import { StorageService } from '@aurabase/storage';
23
23
  * const { data } = await aura.db.from('posts').eq('published', true)
24
24
  * ```
25
25
  */
26
- declare class AuraClient<Database = any> implements AuraClientLike {
26
+ declare class AuraClient<Database = any, Schema extends GenericSchema = Database extends {
27
+ public: infer S;
28
+ } ? S extends GenericSchema ? S : any : any> implements AuraClientLike {
27
29
  /** URL du projet (`https://<slug>.aurabase.cloud`), sans barre finale. */
28
30
  readonly baseUrl: string;
29
31
  readonly apiKey: string | null;
@@ -64,12 +66,34 @@ declare class AuraClient<Database = any> implements AuraClientLike {
64
66
  dispose(): void;
65
67
  get auth(): AuthService;
66
68
  get authAdmin(): AuthAdminService;
67
- get db(): DatabaseService<Database>;
69
+ get db(): DatabaseService<Database, Schema>;
68
70
  get storage(): StorageService;
69
71
  get realtime(): RealtimeService;
70
72
  get functions(): FunctionsService;
71
73
  get ai(): AiService;
72
74
  get notifications(): NotificationsService;
75
+ /**
76
+ * Shortcut: query a database table or view (Supabase-compatible API).
77
+ * Equivalent to `aura.db.from(table)`.
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * const { data, error } = await aura.from('posts').select('*').limit(10)
82
+ * ```
83
+ */
84
+ from<TableName extends string & keyof Schema['Tables'], Table extends Schema['Tables'][TableName]>(table: TableName): AuraQueryBuilder<Schema, Table, TableName, AuraClientOptionsT>;
85
+ from<ViewName extends string & keyof Schema['Views'], View extends Schema['Views'][ViewName]>(view: ViewName): AuraQueryBuilder<Schema, View, ViewName, AuraClientOptionsT>;
86
+ from(table: string): AuraQueryBuilder<any, any, any, AuraClientOptionsT>;
87
+ /**
88
+ * Shortcut: call a stored procedure / PostgreSQL function via RPC (Supabase-compatible API).
89
+ * Equivalent to `aura.db.rpc(fn, args, options)`.
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * const { data, error } = await aura.rpc('echo_test', { message: 'hello' })
94
+ * ```
95
+ */
96
+ rpc<T = any>(fn: string, args?: Record<string, unknown>, options?: any): any;
73
97
  /**
74
98
  * Shortcut: create a realtime channel with Supabase-compatible API.
75
99
  * Equivalent to `aura.realtime.channel(name)`.
package/dist/index.cjs CHANGED
@@ -76,7 +76,12 @@ var AuraClient = class {
76
76
  this.authStore = resolvedOptions.auth.storage;
77
77
  } else if (resolvedOptions?.auth?.persistSession === false) {
78
78
  this.authStore = new core.BaseAuthStore();
79
- } else if (typeof localStorage !== "undefined") {
79
+ } else if (isBrowserContext() && typeof window.localStorage !== "undefined" || typeof globalThis !== "undefined" && (() => {
80
+ const g = globalThis;
81
+ const proc = g?.process;
82
+ const isTest = !!(proc?.env?.VITEST || proc?.env?.NODE_ENV === "test" || proc?.env?.JEST_WORKER_ID);
83
+ return isTest && g?.localStorage && typeof g.localStorage.getItem === "function";
84
+ })()) {
80
85
  this.authStore = new core.LocalAuthStore(`aura-${core.clientScope(this.baseUrl)}-auth`);
81
86
  } else {
82
87
  this.authStore = new core.BaseAuthStore();
@@ -153,6 +158,23 @@ var AuraClient = class {
153
158
  if (!this._notifications) this._notifications = new notifications.NotificationsService(this);
154
159
  return this._notifications;
155
160
  }
161
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
162
+ from(table) {
163
+ return this.db.from(table);
164
+ }
165
+ /**
166
+ * Shortcut: call a stored procedure / PostgreSQL function via RPC (Supabase-compatible API).
167
+ * Equivalent to `aura.db.rpc(fn, args, options)`.
168
+ *
169
+ * @example
170
+ * ```ts
171
+ * const { data, error } = await aura.rpc('echo_test', { message: 'hello' })
172
+ * ```
173
+ */
174
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
175
+ rpc(fn, args, options) {
176
+ return this.db.rpc(fn, args, options);
177
+ }
156
178
  /**
157
179
  * Shortcut: create a realtime channel with Supabase-compatible API.
158
180
  * Equivalent to `aura.realtime.channel(name)`.
package/dist/index.d.cts CHANGED
@@ -6,8 +6,8 @@ export { DatabaseService, QueryBuilder } from '@aurabase/db';
6
6
  export { FunctionsService } from '@aurabase/functions';
7
7
  export { NotificationsAdminService, NotificationsService } from '@aurabase/notifications';
8
8
  export { AuraChannel, RealtimeService } from '@aurabase/realtime';
9
- export { StorageService } from '@aurabase/storage';
10
- import { A as AuraClient } from './AuraClient-DL7mqfNu.cjs';
9
+ export { StorageBucketClient, StorageService } from '@aurabase/storage';
10
+ import { A as AuraClient } from './AuraClient-K3hRdh9J.cjs';
11
11
 
12
12
  /**
13
13
  * Create a new Aurabase client instance.
package/dist/index.d.ts CHANGED
@@ -6,8 +6,8 @@ export { DatabaseService, QueryBuilder } from '@aurabase/db';
6
6
  export { FunctionsService } from '@aurabase/functions';
7
7
  export { NotificationsAdminService, NotificationsService } from '@aurabase/notifications';
8
8
  export { AuraChannel, RealtimeService } from '@aurabase/realtime';
9
- export { StorageService } from '@aurabase/storage';
10
- import { A as AuraClient } from './AuraClient-DL7mqfNu.js';
9
+ export { StorageBucketClient, StorageService } from '@aurabase/storage';
10
+ import { A as AuraClient } from './AuraClient-K3hRdh9J.js';
11
11
 
12
12
  /**
13
13
  * Create a new Aurabase client instance.
package/dist/index.js CHANGED
@@ -82,7 +82,12 @@ var AuraClient = class {
82
82
  this.authStore = resolvedOptions.auth.storage;
83
83
  } else if (resolvedOptions?.auth?.persistSession === false) {
84
84
  this.authStore = new BaseAuthStore();
85
- } else if (typeof localStorage !== "undefined") {
85
+ } else if (isBrowserContext() && typeof window.localStorage !== "undefined" || typeof globalThis !== "undefined" && (() => {
86
+ const g = globalThis;
87
+ const proc = g?.process;
88
+ const isTest = !!(proc?.env?.VITEST || proc?.env?.NODE_ENV === "test" || proc?.env?.JEST_WORKER_ID);
89
+ return isTest && g?.localStorage && typeof g.localStorage.getItem === "function";
90
+ })()) {
86
91
  this.authStore = new LocalAuthStore(`aura-${clientScope(this.baseUrl)}-auth`);
87
92
  } else {
88
93
  this.authStore = new BaseAuthStore();
@@ -159,6 +164,23 @@ var AuraClient = class {
159
164
  if (!this._notifications) this._notifications = new NotificationsService(this);
160
165
  return this._notifications;
161
166
  }
167
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
168
+ from(table) {
169
+ return this.db.from(table);
170
+ }
171
+ /**
172
+ * Shortcut: call a stored procedure / PostgreSQL function via RPC (Supabase-compatible API).
173
+ * Equivalent to `aura.db.rpc(fn, args, options)`.
174
+ *
175
+ * @example
176
+ * ```ts
177
+ * const { data, error } = await aura.rpc('echo_test', { message: 'hello' })
178
+ * ```
179
+ */
180
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
181
+ rpc(fn, args, options) {
182
+ return this.db.rpc(fn, args, options);
183
+ }
162
184
  /**
163
185
  * Shortcut: create a realtime channel with Supabase-compatible API.
164
186
  * Equivalent to `aura.realtime.channel(name)`.
package/dist/ssr.cjs CHANGED
@@ -76,7 +76,12 @@ var AuraClient = class {
76
76
  this.authStore = resolvedOptions.auth.storage;
77
77
  } else if (resolvedOptions?.auth?.persistSession === false) {
78
78
  this.authStore = new core.BaseAuthStore();
79
- } else if (typeof localStorage !== "undefined") {
79
+ } else if (isBrowserContext() && typeof window.localStorage !== "undefined" || typeof globalThis !== "undefined" && (() => {
80
+ const g = globalThis;
81
+ const proc = g?.process;
82
+ const isTest = !!(proc?.env?.VITEST || proc?.env?.NODE_ENV === "test" || proc?.env?.JEST_WORKER_ID);
83
+ return isTest && g?.localStorage && typeof g.localStorage.getItem === "function";
84
+ })()) {
80
85
  this.authStore = new core.LocalAuthStore(`aura-${core.clientScope(this.baseUrl)}-auth`);
81
86
  } else {
82
87
  this.authStore = new core.BaseAuthStore();
@@ -153,6 +158,23 @@ var AuraClient = class {
153
158
  if (!this._notifications) this._notifications = new notifications.NotificationsService(this);
154
159
  return this._notifications;
155
160
  }
161
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
162
+ from(table) {
163
+ return this.db.from(table);
164
+ }
165
+ /**
166
+ * Shortcut: call a stored procedure / PostgreSQL function via RPC (Supabase-compatible API).
167
+ * Equivalent to `aura.db.rpc(fn, args, options)`.
168
+ *
169
+ * @example
170
+ * ```ts
171
+ * const { data, error } = await aura.rpc('echo_test', { message: 'hello' })
172
+ * ```
173
+ */
174
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
175
+ rpc(fn, args, options) {
176
+ return this.db.rpc(fn, args, options);
177
+ }
156
178
  /**
157
179
  * Shortcut: create a realtime channel with Supabase-compatible API.
158
180
  * Equivalent to `aura.realtime.channel(name)`.
package/dist/ssr.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { SerializeCookieOptions, AuraClientOptions } from '@aurabase/core';
2
2
  export { SerializeCookieOptions, parseCookieHeader, serializeCookieHeader } from '@aurabase/core';
3
- import { A as AuraClient } from './AuraClient-DL7mqfNu.cjs';
3
+ import { A as AuraClient } from './AuraClient-K3hRdh9J.cjs';
4
4
  import '@aurabase/ai';
5
5
  import '@aurabase/auth';
6
6
  import '@aurabase/db';
@@ -14,7 +14,7 @@ import '@aurabase/storage';
14
14
  *
15
15
  * @example Next.js middleware
16
16
  * ```ts
17
- * import { createServerClient } from 'aurabase/ssr'
17
+ * import { createServerClient } from '@aurabase/aurabase-js/ssr'
18
18
  *
19
19
  * export async function middleware(request) {
20
20
  * let response = NextResponse.next({ request })
package/dist/ssr.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { SerializeCookieOptions, AuraClientOptions } from '@aurabase/core';
2
2
  export { SerializeCookieOptions, parseCookieHeader, serializeCookieHeader } from '@aurabase/core';
3
- import { A as AuraClient } from './AuraClient-DL7mqfNu.js';
3
+ import { A as AuraClient } from './AuraClient-K3hRdh9J.js';
4
4
  import '@aurabase/ai';
5
5
  import '@aurabase/auth';
6
6
  import '@aurabase/db';
@@ -14,7 +14,7 @@ import '@aurabase/storage';
14
14
  *
15
15
  * @example Next.js middleware
16
16
  * ```ts
17
- * import { createServerClient } from 'aurabase/ssr'
17
+ * import { createServerClient } from '@aurabase/aurabase-js/ssr'
18
18
  *
19
19
  * export async function middleware(request) {
20
20
  * let response = NextResponse.next({ request })
package/dist/ssr.js CHANGED
@@ -75,7 +75,12 @@ var AuraClient = class {
75
75
  this.authStore = resolvedOptions.auth.storage;
76
76
  } else if (resolvedOptions?.auth?.persistSession === false) {
77
77
  this.authStore = new BaseAuthStore();
78
- } else if (typeof localStorage !== "undefined") {
78
+ } else if (isBrowserContext() && typeof window.localStorage !== "undefined" || typeof globalThis !== "undefined" && (() => {
79
+ const g = globalThis;
80
+ const proc = g?.process;
81
+ const isTest = !!(proc?.env?.VITEST || proc?.env?.NODE_ENV === "test" || proc?.env?.JEST_WORKER_ID);
82
+ return isTest && g?.localStorage && typeof g.localStorage.getItem === "function";
83
+ })()) {
79
84
  this.authStore = new LocalAuthStore(`aura-${clientScope(this.baseUrl)}-auth`);
80
85
  } else {
81
86
  this.authStore = new BaseAuthStore();
@@ -152,6 +157,23 @@ var AuraClient = class {
152
157
  if (!this._notifications) this._notifications = new NotificationsService(this);
153
158
  return this._notifications;
154
159
  }
160
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
161
+ from(table) {
162
+ return this.db.from(table);
163
+ }
164
+ /**
165
+ * Shortcut: call a stored procedure / PostgreSQL function via RPC (Supabase-compatible API).
166
+ * Equivalent to `aura.db.rpc(fn, args, options)`.
167
+ *
168
+ * @example
169
+ * ```ts
170
+ * const { data, error } = await aura.rpc('echo_test', { message: 'hello' })
171
+ * ```
172
+ */
173
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
174
+ rpc(fn, args, options) {
175
+ return this.db.rpc(fn, args, options);
176
+ }
155
177
  /**
156
178
  * Shortcut: create a realtime channel with Supabase-compatible API.
157
179
  * Equivalent to `aura.realtime.channel(name)`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aurabase/aurabase-js",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
4
4
  "description": "Official JavaScript/TypeScript client for Aurabase BaaS",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -55,29 +55,28 @@
55
55
  "sdk",
56
56
  "client"
57
57
  ],
58
+ "dependencies": {
59
+ "@aurabase/core": "0.5.3",
60
+ "@aurabase/realtime": "0.5.3",
61
+ "@aurabase/auth": "0.5.3",
62
+ "@aurabase/functions": "0.5.3",
63
+ "@aurabase/notifications": "0.5.3",
64
+ "@aurabase/ai": "0.5.3",
65
+ "@aurabase/storage": "0.5.3",
66
+ "@aurabase/db": "0.5.3"
67
+ },
68
+ "devDependencies": {
69
+ "@types/node": "20.14.15",
70
+ "tsup": "^8.0.0",
71
+ "typescript": "^5.5.0",
72
+ "vitest": "^4.1.6"
73
+ },
58
74
  "scripts": {
59
75
  "build": "tsup",
60
76
  "test": "vitest run && tsc --noEmit -p tsconfig.test-d.json",
61
77
  "test:types": "tsc --noEmit -p tsconfig.test-d.json",
62
78
  "test:e2e": "RUN_E2E=true vitest run --config vitest.e2e.config.ts tests/integration.test.ts",
63
79
  "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
64
- "prepack": "pnpm build",
65
80
  "typecheck:tests": "tsc --noEmit -p tsconfig.test.json"
66
- },
67
- "dependencies": {
68
- "@aurabase/core": "workspace:*",
69
- "@aurabase/auth": "workspace:*",
70
- "@aurabase/db": "workspace:*",
71
- "@aurabase/storage": "workspace:*",
72
- "@aurabase/realtime": "workspace:*",
73
- "@aurabase/functions": "workspace:*",
74
- "@aurabase/ai": "workspace:*",
75
- "@aurabase/notifications": "workspace:*"
76
- },
77
- "devDependencies": {
78
- "@types/node": "catalog:",
79
- "tsup": "catalog:",
80
- "typescript": "catalog:",
81
- "vitest": "catalog:"
82
81
  }
83
- }
82
+ }