@swiftbaseio/admin-sdk 0.0.0-stage → 1.1.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.
@@ -0,0 +1,963 @@
1
+ declare class Token {
2
+ #private;
3
+ constructor(token: string, type: string, expiration?: number);
4
+ private decodeExpiration;
5
+ /**
6
+ * Getter for the raw token
7
+ *
8
+ * @returns {string} The token
9
+ */
10
+ value(): string;
11
+ /**
12
+ * Checks if the token is valid and not expired
13
+ *
14
+ * @returns {boolean} True if the token is valid, false otherwise
15
+ */
16
+ isValid(): boolean;
17
+ /**
18
+ * Checks if the token is an access token
19
+ *
20
+ * @returns {boolean} True if the token is an access token, false otherwise
21
+ */
22
+ isAccessToken(): boolean;
23
+ /**
24
+ * Checks if the token is a refresh token
25
+ *
26
+ * @returns {boolean} True if the token is a refresh token, false otherwise
27
+ */
28
+ isRefreshToken(): boolean;
29
+ }
30
+
31
+ interface SwiftbaseApp {
32
+ projectId: string;
33
+ baseUrl: string;
34
+ accessToken: Token | null;
35
+ serviceId?: string;
36
+ serviceKey?: string;
37
+ }
38
+ interface initializeSdkOptions {
39
+ baseUrl?: string;
40
+ serviceId?: string;
41
+ serviceKey?: string;
42
+ }
43
+ declare const app: SwiftbaseApp;
44
+ declare const initializeSdk: (projectId: string, options?: initializeSdkOptions) => void;
45
+ declare const setAccessToken: (token: string, expiration?: number) => void;
46
+ declare const isLoggedIn: () => boolean;
47
+ declare const logout: () => void;
48
+
49
+ interface RESTPaginatedResponse<T> {
50
+ data: T[];
51
+ meta: {
52
+ total: number;
53
+ page: number;
54
+ limit: number;
55
+ next: string | null;
56
+ back: string | null;
57
+ };
58
+ }
59
+ declare class PaginatedResponse<T> {
60
+ #private;
61
+ constructor(response: RESTPaginatedResponse<T>);
62
+ get items(): T[];
63
+ get total(): number;
64
+ get page(): number;
65
+ get limit(): number;
66
+ get hasNext(): boolean;
67
+ get hasBack(): boolean;
68
+ next(): Promise<PaginatedResponse<T> | null>;
69
+ back(): Promise<PaginatedResponse<T> | null>;
70
+ }
71
+
72
+ /**
73
+ * Login as a service
74
+ *
75
+ * @param {string} serviceId The service ID
76
+ * @param {string} secretKey The service secret key
77
+ *
78
+ * @returns {Promise<void>}
79
+ */
80
+ declare const login: (serviceId: string, secretKey: string) => Promise<void>;
81
+
82
+ /**
83
+ * Get a valid access token.
84
+ * If the current token is missing or expired, it will attempt to login again
85
+ * using the stored serviceId and serviceKey.
86
+ *
87
+ * @returns {Promise<string | null>} The access token
88
+ */
89
+ declare const getAccessToken: () => Promise<string | null>;
90
+
91
+ interface Role {
92
+ id: string;
93
+ name: string;
94
+ permissions: string[];
95
+ projectId: string;
96
+ }
97
+ interface RoleInput {
98
+ name: string;
99
+ permissions: string[];
100
+ projectId: string;
101
+ }
102
+ interface RoleUpdateInput {
103
+ id: string;
104
+ name?: string;
105
+ permissions?: string[];
106
+ }
107
+ interface Service {
108
+ id: string;
109
+ name: string;
110
+ description?: string;
111
+ projectId: string;
112
+ scope?: string[];
113
+ }
114
+ interface ServiceInput {
115
+ name: string;
116
+ description?: string;
117
+ projectId: string;
118
+ secretKey: string;
119
+ scope?: string[];
120
+ }
121
+ interface ServiceUpdateInput {
122
+ id: string;
123
+ name?: string;
124
+ description?: string;
125
+ }
126
+ interface User {
127
+ id: string;
128
+ email: string;
129
+ firstName?: string;
130
+ lastName?: string;
131
+ avatar?: string;
132
+ projectId?: string;
133
+ roles?: string[];
134
+ approved?: boolean;
135
+ attributes?: Record<string, any>;
136
+ }
137
+ interface UserInput {
138
+ email: string;
139
+ password?: string;
140
+ projectId: string;
141
+ firstName?: string;
142
+ lastName?: string;
143
+ approved?: boolean;
144
+ }
145
+
146
+ /**
147
+ * Verify a user's access token
148
+ *
149
+ * @param {string} token The access token to verify
150
+ *
151
+ * @returns {Promise<User>} The user associated with the token
152
+ */
153
+ declare const verifyToken: (token: string) => Promise<User>;
154
+
155
+ /**
156
+ * Verify a service's access token
157
+ *
158
+ * @param {string} token The access token to verify
159
+ * @param {string} [scope] Optional scope to verify
160
+ *
161
+ * @returns {Promise<Service>} The service associated with the token
162
+ */
163
+ declare const verifyServiceToken: (token: string, scope?: string) => Promise<Service>;
164
+
165
+ /**
166
+ * Roles Management
167
+ */
168
+ declare const getRoles: (projectId: string) => Promise<Role[]>;
169
+ declare const createRole: (input: RoleInput) => Promise<Role>;
170
+ declare const updateRole: (input: RoleUpdateInput) => Promise<Role>;
171
+ declare const deleteRole: (id: string) => Promise<string>;
172
+ /**
173
+ * Services Management
174
+ */
175
+ declare const getServices: (projectId: string) => Promise<Service[]>;
176
+ declare const createService: (input: ServiceInput) => Promise<Service>;
177
+ declare const updateService: (input: ServiceUpdateInput) => Promise<Service>;
178
+ declare const deleteService: (id: string) => Promise<string>;
179
+ /**
180
+ * User Management
181
+ */
182
+ declare const getUsers: (projectId: string) => Promise<User[]>;
183
+ declare const assignRole: (userId: string, roleName: string) => Promise<User>;
184
+ declare const unassignRole: (userId: string, roleName: string) => Promise<User>;
185
+ declare const createUser: (input: UserInput) => Promise<User>;
186
+ declare const deleteUser: (id: string) => Promise<string>;
187
+
188
+ interface Profile {
189
+ id: string;
190
+ email: string;
191
+ firstName?: string;
192
+ lastName?: string;
193
+ projectId?: string;
194
+ roles?: string[];
195
+ lastLoginAt?: string;
196
+ failedLoginAttempts?: number;
197
+ lockedUntilAt?: string;
198
+ attributes?: Record<string, any>;
199
+ createdAt?: string;
200
+ updatedAt?: string;
201
+ }
202
+ interface ProfileInput {
203
+ firstName?: string;
204
+ lastName?: string;
205
+ attributes?: Record<string, any>;
206
+ }
207
+ interface ChangePasswordInput {
208
+ currentPassword?: string;
209
+ newPassword?: string;
210
+ }
211
+
212
+ /**
213
+ * Get the current user profile
214
+ *
215
+ * @returns {Promise<Profile>} The user profile
216
+ */
217
+ declare const getProfile: () => Promise<Profile>;
218
+
219
+ /**
220
+ * Update the current user profile
221
+ *
222
+ * @param {ProfileInput} input The profile data to update
223
+ * @returns {Promise<Profile>} The updated profile
224
+ */
225
+ declare const updateProfile: (input: ProfileInput) => Promise<Profile>;
226
+
227
+ /**
228
+ * Update a user by ID
229
+ *
230
+ * @param {string} id The user ID
231
+ * @param {ProfileInput} input The user data to update
232
+ * @returns {Promise<Profile>} The updated user
233
+ */
234
+ declare const updateUser: (id: string, input: ProfileInput) => Promise<Profile>;
235
+
236
+ /**
237
+ * Change the current user password
238
+ *
239
+ * @param {ChangePasswordInput} input The password data
240
+ * @returns {Promise<any>}
241
+ */
242
+ declare const changePassword: (input: ChangePasswordInput) => Promise<any>;
243
+
244
+ interface Configuration {
245
+ id: string;
246
+ project_id: string;
247
+ allow_registration: boolean;
248
+ allow_password_reset: boolean;
249
+ mfa_required: boolean;
250
+ access_expiry: string;
251
+ refresh_expiry: string;
252
+ google_enabled: boolean;
253
+ microsoft_enabled: boolean;
254
+ github_enabled: boolean;
255
+ facebook_enabled: boolean;
256
+ apple_enabled: boolean;
257
+ totp_enabled: boolean;
258
+ totp_required: boolean;
259
+ passkeys_enabled: boolean;
260
+ universal_login_enabled: boolean;
261
+ request_beta_access: boolean;
262
+ beta_access_button_text: string;
263
+ brand_name: string;
264
+ brand_logo_url?: string;
265
+ primary_color: string;
266
+ redirect_uris?: string[];
267
+ created_at: string;
268
+ updated_at: string;
269
+ }
270
+ type ConfigurationInput = Partial<Omit<Configuration, "id" | "project_id" | "created_at" | "updated_at">>;
271
+
272
+ declare const getConfiguration: (projectId: string) => Promise<Configuration>;
273
+ declare const updateConfiguration: (projectId: string, data: ConfigurationInput) => Promise<Configuration>;
274
+
275
+ /**
276
+ * Generates a sequential, lowercase, 26-character time-sortable database ID (monotonic ULID).
277
+ *
278
+ * Features:
279
+ * - Sequential / Time-Sortable: Preserves B-Tree index locality in OLTP (libSQL/SQLite)
280
+ * and chronological row-group ordering in OLAP (DuckDB/Parquet).
281
+ * - Monotonicity: Guarantees strict lexicographical ordering (`id_a < id_b`) even when
282
+ * multiple IDs are generated within the exact same millisecond.
283
+ * - Minimal Byte Footprint: Encoded as a compact 26-character Base32 string (only 26 bytes,
284
+ * saving 10 bytes per ID compared to 36-byte UUID strings).
285
+ * - Lowercase: Uses Crockford's Base32 alphabet rendered strictly in lowercase
286
+ * (`0-9`, `a-z` excluding ambiguous characters `i`, `l`, `o`, `u`).
287
+ *
288
+ * @returns A 26-character sequential lowercase database ID.
289
+ */
290
+ declare function generateId(): string;
291
+
292
+ /**
293
+ * Swiftbase SDK Database Types & Interfaces
294
+ *
295
+ * Defines the core AST and payload representations for query building,
296
+ * batching, realtime events, and dialect-specific execution.
297
+ */
298
+ type LogicalOperator = "AND" | "OR";
299
+ type ComparisonOperator = "=" | "!=" | "<>" | ">" | ">=" | "<" | "<=" | "LIKE" | "NOT LIKE" | "ILIKE" | "NOT ILIKE" | "IN" | "NOT IN" | "IS" | "IS NOT" | "BETWEEN" | "NOT BETWEEN";
300
+ interface WhereCondition {
301
+ column: string;
302
+ operator: ComparisonOperator | string;
303
+ value: any;
304
+ bool?: LogicalOperator;
305
+ isRaw?: boolean;
306
+ }
307
+ type JoinType = "inner" | "left" | "right" | "full" | "cross";
308
+ interface JoinClause {
309
+ type: JoinType;
310
+ table: string;
311
+ firstColumn: string;
312
+ operator: string;
313
+ secondColumn: string;
314
+ }
315
+ interface OrderByClause {
316
+ column: string;
317
+ order: "asc" | "desc";
318
+ nulls?: "first" | "last";
319
+ }
320
+ interface AggregateClause {
321
+ fn: "count" | "min" | "max" | "sum" | "avg";
322
+ column: string;
323
+ as?: string;
324
+ distinct?: boolean;
325
+ }
326
+ interface QueryPayload {
327
+ database: string;
328
+ table: string;
329
+ projectId?: string;
330
+ select?: string[];
331
+ distinct?: boolean;
332
+ where?: WhereCondition[];
333
+ joins?: JoinClause[];
334
+ groupBy?: string[];
335
+ having?: WhereCondition[];
336
+ orderBy?: OrderByClause[];
337
+ aggregates?: AggregateClause[];
338
+ limit?: number;
339
+ offset?: number;
340
+ insert?: any;
341
+ update?: any;
342
+ delete?: boolean;
343
+ onConflict?: {
344
+ columns: string[];
345
+ merge?: boolean;
346
+ update?: Record<string, any>;
347
+ };
348
+ returning?: string[];
349
+ }
350
+ interface BatchQueryResult {
351
+ data: any[];
352
+ columns: string[];
353
+ count: number;
354
+ rowCount: number;
355
+ rowsAffected?: number;
356
+ rowsJSON?: string;
357
+ executionTimeMs?: number;
358
+ }
359
+ interface CompiledSQL {
360
+ sql: string;
361
+ bindings: any[];
362
+ }
363
+
364
+ /**
365
+ * Swiftbase QueryBuilder
366
+ *
367
+ * Full-featured, Knex-compatible fluent query builder that supports both
368
+ * realtime WebSocket execution and REST failover, with full coverage of
369
+ * filtering, grouping, joining, aggregations, mutations, and upserts.
370
+ */
371
+
372
+ declare class QueryBuilder implements PromiseLike<any> {
373
+ protected dbName: string;
374
+ protected tableName: string;
375
+ protected payload: QueryPayload;
376
+ constructor(dbNameOrTable: string, tableName?: string);
377
+ /**
378
+ * Specify columns to select in the result set.
379
+ * Accepts string column names or arrays of column names.
380
+ */
381
+ select(...columns: Array<string | string[]>): this;
382
+ /**
383
+ * Applies DISTINCT to the query projection.
384
+ */
385
+ distinct(): this;
386
+ /**
387
+ * Alias for select().
388
+ */
389
+ columns(...cols: Array<string | string[]>): this;
390
+ private addWhere;
391
+ where(column: string, value: any): this;
392
+ where(column: string, operator: string, value: any): this;
393
+ where(obj: Record<string, any>): this;
394
+ andWhere(column: string, value: any): this;
395
+ andWhere(column: string, operator: string, value: any): this;
396
+ andWhere(obj: Record<string, any>): this;
397
+ orWhere(column: string, value: any): this;
398
+ orWhere(column: string, operator: string, value: any): this;
399
+ orWhere(obj: Record<string, any>): this;
400
+ whereNot(column: string, value: any): this;
401
+ whereNot(column: string, operator: string, value: any): this;
402
+ whereNot(obj: Record<string, any>): this;
403
+ orWhereNot(column: string, value: any): this;
404
+ orWhereNot(column: string, operator: string, value: any): this;
405
+ orWhereNot(obj: Record<string, any>): this;
406
+ whereIn(column: string, values: any[]): this;
407
+ orWhereIn(column: string, values: any[]): this;
408
+ whereNotIn(column: string, values: any[]): this;
409
+ orWhereNotIn(column: string, values: any[]): this;
410
+ whereNull(column: string): this;
411
+ orWhereNull(column: string): this;
412
+ whereNotNull(column: string): this;
413
+ orWhereNotNull(column: string): this;
414
+ whereBetween(column: string, range: [any, any]): this;
415
+ orWhereBetween(column: string, range: [any, any]): this;
416
+ whereNotBetween(column: string, range: [any, any]): this;
417
+ orWhereNotBetween(column: string, range: [any, any]): this;
418
+ whereLike(column: string, pattern: string): this;
419
+ whereILike(column: string, pattern: string): this;
420
+ whereRaw(rawSql: string): this;
421
+ join(table: string, firstColumn: string, operatorOrSecond: string, secondColumn?: string): this;
422
+ innerJoin(table: string, firstColumn: string, operatorOrSecond: string, secondColumn?: string): this;
423
+ leftJoin(table: string, firstColumn: string, operatorOrSecond: string, secondColumn?: string): this;
424
+ rightJoin(table: string, firstColumn: string, operatorOrSecond: string, secondColumn?: string): this;
425
+ fullOuterJoin(table: string, firstColumn: string, operatorOrSecond: string, secondColumn?: string): this;
426
+ crossJoin(table: string): this;
427
+ private addJoin;
428
+ groupBy(...columns: Array<string | string[]>): this;
429
+ having(column: string, operator: string, value: any): this;
430
+ count(column?: string, optionsOrAs?: string | {
431
+ as?: string;
432
+ distinct?: boolean;
433
+ }): this;
434
+ min(column: string, optionsOrAs?: string | {
435
+ as?: string;
436
+ }): this;
437
+ max(column: string, optionsOrAs?: string | {
438
+ as?: string;
439
+ }): this;
440
+ sum(column: string, optionsOrAs?: string | {
441
+ as?: string;
442
+ distinct?: boolean;
443
+ }): this;
444
+ avg(column: string, optionsOrAs?: string | {
445
+ as?: string;
446
+ distinct?: boolean;
447
+ }): this;
448
+ private addAggregate;
449
+ orderBy(column: string, order?: "asc" | "desc", nulls?: "first" | "last"): this;
450
+ limit(value: number): this;
451
+ offset(value: number): this;
452
+ /**
453
+ * Limits results to 1 and unpacks the first row automatically on execution.
454
+ */
455
+ first(...columns: Array<string | string[]>): Promise<any>;
456
+ insert(data: any): this;
457
+ update(data: any): this;
458
+ delete(): this;
459
+ /**
460
+ * Increments a numeric column by an amount (default: 1).
461
+ */
462
+ increment(column: string, amount?: number): this;
463
+ /**
464
+ * Decrements a numeric column by an amount (default: 1).
465
+ */
466
+ decrement(column: string, amount?: number): this;
467
+ /**
468
+ * Specify RETURNING clause for mutations.
469
+ */
470
+ returning(...columns: Array<string | string[]>): this;
471
+ /**
472
+ * Configure ON CONFLICT clause for upserts.
473
+ */
474
+ onConflict(columns: string | string[]): {
475
+ ignore: () => QueryBuilder;
476
+ merge: (updateFields?: Record<string, any>) => QueryBuilder;
477
+ };
478
+ /**
479
+ * Listen for real-time table modifications via persistent WebSocket.
480
+ */
481
+ listen(callback: (change: {
482
+ event: "insert" | "update" | "delete";
483
+ data: any;
484
+ }) => void): () => void;
485
+ /**
486
+ * Stream large query result sets page-by-page.
487
+ */
488
+ stream(options?: {
489
+ batchSize?: number;
490
+ }): AsyncGenerator<{
491
+ data: any[];
492
+ count: number;
493
+ }>;
494
+ /**
495
+ * Returns parameterized SQL representation and bindings.
496
+ */
497
+ toSQL(): CompiledSQL;
498
+ /**
499
+ * Returns human-readable SQL with interpolated literals.
500
+ */
501
+ toString(): string;
502
+ getPayload(): QueryPayload;
503
+ toPayload(): QueryPayload;
504
+ execute(): Promise<{
505
+ data: any[];
506
+ columns: string[];
507
+ count: number;
508
+ }>;
509
+ then<TResult1 = any, TResult2 = never>(onfulfilled?: ((value: any) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
510
+ generateId(): string;
511
+ id(): string;
512
+ }
513
+
514
+ /**
515
+ * Swiftbase Declarative Schema Column Builders
516
+ *
517
+ * Provides a Drizzle-style type-safe column definition API supporting both
518
+ * OLTP (LibSQL / SQLite) and OLAP (DuckLake / DuckDB) database engines.
519
+ */
520
+ type ColumnDataType = "text" | "varchar" | "integer" | "bigint" | "real" | "double" | "boolean" | "timestamp" | "json" | "uuid" | "blob";
521
+ interface ColumnDefinitionOptions {
522
+ name: string;
523
+ dataType: ColumnDataType;
524
+ isPrimaryKey?: boolean;
525
+ isNotNull?: boolean;
526
+ isUnique?: boolean;
527
+ defaultValue?: any;
528
+ references?: () => ColumnBuilder<any>;
529
+ length?: number;
530
+ }
531
+ declare class ColumnBuilder<T = any> {
532
+ options: ColumnDefinitionOptions;
533
+ constructor(name: string, dataType: ColumnDataType, length?: number);
534
+ primaryKey(): this;
535
+ notNull(): this;
536
+ unique(): this;
537
+ default(value: any): this;
538
+ references(refFn: () => ColumnBuilder<any>): this;
539
+ get name(): string;
540
+ get dataType(): ColumnDataType;
541
+ }
542
+ declare function text(name: string): ColumnBuilder<string>;
543
+ declare function varchar(name: string, options?: {
544
+ length: number;
545
+ }): ColumnBuilder<string>;
546
+ declare function integer(name: string): ColumnBuilder<number>;
547
+ declare function bigint(name: string): ColumnBuilder<bigint>;
548
+ declare function real(name: string): ColumnBuilder<number>;
549
+ declare function doublePrecision(name: string): ColumnBuilder<number>;
550
+ declare function boolean(name: string): ColumnBuilder<boolean>;
551
+ declare function timestamp(name: string): ColumnBuilder<Date | string>;
552
+ declare function json(name: string): ColumnBuilder<any>;
553
+ declare function uuid(name: string): ColumnBuilder<string>;
554
+ declare function blob(name: string): ColumnBuilder<Uint8Array>;
555
+
556
+ /**
557
+ * Swiftbase Dialect Mappings
558
+ *
559
+ * Maps abstract column data types into physical SQL column definitions
560
+ * tailored for OLTP (LibSQL / SQLite) and OLAP (DuckLake / DuckDB).
561
+ */
562
+
563
+ type DatabaseEngine = "oltp" | "olap";
564
+
565
+ /**
566
+ * Swiftbase Declarative Table Definition
567
+ *
568
+ * Encapsulates a table schema structure with columns, indexes, and engine metadata.
569
+ */
570
+
571
+ interface IndexDefinition {
572
+ name?: string;
573
+ columns: string[];
574
+ unique?: boolean;
575
+ }
576
+ interface TableOptions {
577
+ engine?: DatabaseEngine;
578
+ indexes?: IndexDefinition[];
579
+ }
580
+ declare class TableDefinition<TColumns extends Record<string, ColumnBuilder<any>> = Record<string, ColumnBuilder<any>>> {
581
+ tableName: string;
582
+ columns: TColumns;
583
+ options: TableOptions;
584
+ constructor(tableName: string, columns: TColumns, options?: TableOptions);
585
+ /**
586
+ * Generates the CREATE TABLE DDL statement for the configured dialect.
587
+ */
588
+ toCreateSQL(engine?: DatabaseEngine): string;
589
+ /**
590
+ * Generates CREATE INDEX statements for any defined indexes.
591
+ */
592
+ toIndexSQL(): string[];
593
+ }
594
+ /**
595
+ * Define a type-safe database table schema.
596
+ */
597
+ declare function defineTable<TColumns extends Record<string, ColumnBuilder<any>>>(tableName: string, columns: TColumns, options?: TableOptions): TableDefinition<TColumns> & TColumns;
598
+
599
+ /**
600
+ * Swiftbase SQL Compiler
601
+ *
602
+ * Translates a high-level QueryPayload AST into dialect-safe SQL queries
603
+ * with parameterized bindings for both OLTP (SQLite/LibSQL) and OLAP (DuckDB).
604
+ */
605
+
606
+ declare class SQLCompiler {
607
+ private payload;
608
+ constructor(payload: QueryPayload);
609
+ private escapeIdentifier;
610
+ private compileWhereClause;
611
+ toSQL(): CompiledSQL;
612
+ toString(): string;
613
+ }
614
+
615
+ /**
616
+ * Swiftbase Schema Diff Engine
617
+ *
618
+ * Compares an existing database schema catalog with target TableDefinition
619
+ * structures and generates atomic, non-destructive migration operations.
620
+ */
621
+
622
+ type MigrationOperation = {
623
+ type: "create_table";
624
+ table: TableDefinition<any>;
625
+ } | {
626
+ type: "drop_table";
627
+ tableName: string;
628
+ } | {
629
+ type: "add_column";
630
+ tableName: string;
631
+ column: ColumnDefinitionOptions;
632
+ } | {
633
+ type: "drop_column";
634
+ tableName: string;
635
+ columnName: string;
636
+ } | {
637
+ type: "create_index";
638
+ tableName: string;
639
+ indexName: string;
640
+ columns: string[];
641
+ unique?: boolean;
642
+ };
643
+ interface ExistingTableCatalog {
644
+ name: string;
645
+ columns: Array<{
646
+ name: string;
647
+ type: string;
648
+ notNull?: boolean;
649
+ primaryKey?: boolean;
650
+ defaultValue?: any;
651
+ }>;
652
+ }
653
+ declare class SchemaDiff {
654
+ static diff(existingTables: ExistingTableCatalog[], targetTables: Array<TableDefinition<any>>, _engine?: DatabaseEngine): MigrationOperation[];
655
+ }
656
+
657
+ /**
658
+ * Swiftbase Migration Plan Generator
659
+ *
660
+ * Compiles high-level MigrationOperations into an executable DDL migration plan.
661
+ */
662
+
663
+ interface MigrationStep {
664
+ description: string;
665
+ sql: string;
666
+ }
667
+ interface MigrationPlan {
668
+ id: string;
669
+ name: string;
670
+ engine: DatabaseEngine;
671
+ steps: MigrationStep[];
672
+ }
673
+ declare class MigrationGenerator {
674
+ static generatePlan(name: string, operations: MigrationOperation[], engine?: DatabaseEngine): MigrationPlan;
675
+ }
676
+
677
+ /**
678
+ * Swiftbase Migration Runner
679
+ *
680
+ * Automatically provisions migration history tracking in '__swiftbase_migrations'
681
+ * and executes migration plans against the remote database via DbClient.
682
+ */
683
+
684
+ interface MigrationResult {
685
+ appliedCount: number;
686
+ durationMs: number;
687
+ steps: string[];
688
+ }
689
+ declare class MigrationRunner {
690
+ private dbClient;
691
+ private engine;
692
+ constructor(dbClient: any, engine?: DatabaseEngine);
693
+ /**
694
+ * Ensures the migrations table exists to track applied schema versions.
695
+ */
696
+ ensureMigrationsTable(): Promise<void>;
697
+ /**
698
+ * Applies a generated migration plan sequentially.
699
+ */
700
+ applyPlan(plan: MigrationPlan): Promise<MigrationResult>;
701
+ /**
702
+ * One-step declarative synchronization: Inspects existing tables,
703
+ * computes diffs against target schemas, generates a plan, and applies it.
704
+ */
705
+ migrate(name: string, targetTables: Array<TableDefinition<any>>, existingTables?: ExistingTableCatalog[]): Promise<MigrationResult>;
706
+ }
707
+
708
+ /**
709
+ * Swiftbase SDK Database Client & Query Module
710
+ *
711
+ * Provides a Knex-compatible fluent query builder, real-time WebSocket subscriptions,
712
+ * batching execution, type-safe schema definition, and zero-SQL declarative migrations.
713
+ */
714
+
715
+ interface LegacyTableDefinition {
716
+ dbname: string;
717
+ name: string;
718
+ ddl: string;
719
+ }
720
+ interface DbClient {
721
+ (tableName: string): QueryBuilder;
722
+ generateId: () => string;
723
+ id: () => string;
724
+ batch: (queries: Array<QueryBuilder | string>) => Promise<BatchQueryResult[]>;
725
+ executeBatch: (sqlStatements: string[]) => Promise<BatchQueryResult[]>;
726
+ executeSQL: (sql: string) => Promise<any>;
727
+ executeBatchSQL: (sqlStatements: string[] | string) => Promise<BatchQueryResult[]>;
728
+ initializeDatabase: (tables: LegacyTableDefinition[]) => Promise<void>;
729
+ init: (tables: LegacyTableDefinition[]) => Promise<void>;
730
+ migrate: (name: string, tables: Array<TableDefinition<any>>, options?: {
731
+ engine?: DatabaseEngine;
732
+ existingCatalog?: any[];
733
+ }) => Promise<any>;
734
+ }
735
+ interface DbInterface {
736
+ (dbName: string): DbClient;
737
+ generateId: () => string;
738
+ id: () => string;
739
+ }
740
+ declare const db: DbInterface;
741
+
742
+ declare function search(indexId: string, query: string): Promise<any[]>;
743
+
744
+ interface StorageOptions {
745
+ bucket: string;
746
+ endpoint?: string;
747
+ region?: string;
748
+ accessKeyId?: string;
749
+ secretAccessKey?: string;
750
+ }
751
+ interface BucketInfo {
752
+ name: string;
753
+ id?: string;
754
+ region?: string;
755
+ cdnEnabled?: boolean;
756
+ creationDate?: string;
757
+ }
758
+ interface S3Object {
759
+ key: string;
760
+ lastModified?: string;
761
+ etag?: string;
762
+ size: number;
763
+ }
764
+ interface ListObjectsResult {
765
+ name: string;
766
+ prefix: string;
767
+ maxKeys: number;
768
+ isTruncated: boolean;
769
+ contents: S3Object[];
770
+ commonPrefixes: string[];
771
+ }
772
+ declare class Storage {
773
+ private bucket;
774
+ private endpoint;
775
+ private region;
776
+ private accessKeyId?;
777
+ private secretAccessKey?;
778
+ constructor(options: StorageOptions);
779
+ private getHeaders;
780
+ listBuckets(): Promise<BucketInfo[]>;
781
+ listObjects(options?: {
782
+ prefix?: string;
783
+ delimiter?: string;
784
+ maxKeys?: number;
785
+ }): Promise<ListObjectsResult>;
786
+ getObject(key: string): Promise<Response>;
787
+ getObjectAsText(key: string): Promise<string>;
788
+ getObjectAsJson<T = any>(key: string): Promise<T>;
789
+ getObjectAsArrayBuffer(key: string): Promise<ArrayBuffer>;
790
+ putObject(key: string, body: Uint8Array | ArrayBuffer | string | Blob, options?: {
791
+ contentType?: string;
792
+ }): Promise<void>;
793
+ deleteObject(key: string): Promise<void>;
794
+ }
795
+
796
+ interface AIToolCall {
797
+ id: string;
798
+ type: "function";
799
+ function: {
800
+ name: string;
801
+ arguments: string;
802
+ };
803
+ }
804
+ interface AITool {
805
+ type: "function";
806
+ function: {
807
+ name: string;
808
+ description?: string;
809
+ parameters?: Record<string, any>;
810
+ };
811
+ }
812
+ interface AIChatMessage {
813
+ role: "system" | "user" | "assistant" | "tool";
814
+ content?: string | null;
815
+ name?: string;
816
+ tool_call_id?: string;
817
+ tool_calls?: AIToolCall[];
818
+ }
819
+ interface AIChatCompletionOptions {
820
+ model?: string;
821
+ messages: AIChatMessage[];
822
+ tools?: AITool[];
823
+ tool_choice?: any;
824
+ temperature?: number;
825
+ max_tokens?: number;
826
+ bypass_guardrails?: boolean;
827
+ bypassGuardrails?: boolean;
828
+ }
829
+ interface AIChatCompletionResponse {
830
+ id?: string;
831
+ object?: string;
832
+ created?: number;
833
+ model?: string;
834
+ choices: Array<{
835
+ index?: number;
836
+ message: {
837
+ role: string;
838
+ content: string | null;
839
+ tool_calls?: AIToolCall[];
840
+ };
841
+ finish_reason?: string;
842
+ }>;
843
+ usage?: {
844
+ prompt_tokens: number;
845
+ completion_tokens: number;
846
+ total_tokens: number;
847
+ };
848
+ }
849
+ interface AIPromptRunOptions {
850
+ inputs?: Record<string, any>;
851
+ parameters?: Record<string, any>;
852
+ model?: string;
853
+ temperature?: number;
854
+ max_tokens?: number;
855
+ }
856
+ interface AIPromptRunResponse {
857
+ success?: boolean;
858
+ output?: string;
859
+ response?: string;
860
+ model?: string;
861
+ usage?: {
862
+ prompt_tokens: number;
863
+ completion_tokens: number;
864
+ total_tokens: number;
865
+ };
866
+ }
867
+ /**
868
+ * AI Service interface for completions and prompts.
869
+ */
870
+ declare const ai: {
871
+ chat: {
872
+ completions: {
873
+ create: (options: AIChatCompletionOptions) => Promise<AIChatCompletionResponse>;
874
+ };
875
+ };
876
+ prompts: {
877
+ run: (promptId: string, options?: AIPromptRunOptions) => Promise<AIPromptRunResponse>;
878
+ };
879
+ };
880
+
881
+ interface VaultSecret {
882
+ id: string;
883
+ projectId: string;
884
+ key: string;
885
+ name: string;
886
+ description?: string;
887
+ currentVersion: number;
888
+ createdAt: string;
889
+ updatedAt: string;
890
+ }
891
+ interface VaultVersion {
892
+ id: string;
893
+ secretId: string;
894
+ projectId: string;
895
+ version: number;
896
+ value: string;
897
+ createdById: string;
898
+ createdAt: string;
899
+ updatedAt: string;
900
+ }
901
+ interface VaultLog {
902
+ id: string;
903
+ secretId?: string;
904
+ projectId: string;
905
+ action: string;
906
+ performedBy: string;
907
+ details?: string;
908
+ createdAt: string;
909
+ updatedAt: string;
910
+ }
911
+ interface CreateSecretInput {
912
+ projectId?: string;
913
+ key: string;
914
+ name?: string;
915
+ description?: string;
916
+ value: string;
917
+ }
918
+ interface UpdateSecretInput {
919
+ value: string;
920
+ }
921
+
922
+ /**
923
+ * Get all secrets for a project
924
+ */
925
+ declare function getSecrets(projectId?: string): Promise<VaultSecret[]>;
926
+ /**
927
+ * Get a specific secret by ID or Key
928
+ */
929
+ declare function getSecret(idOrKey: string, projectId?: string): Promise<VaultSecret | null>;
930
+ /**
931
+ * Create a new encrypted vault secret
932
+ */
933
+ declare function createSecret(input: CreateSecretInput): Promise<VaultSecret>;
934
+ /**
935
+ * Update a secret's value (creates a new version)
936
+ */
937
+ declare function updateSecretValue(id: string, value: string): Promise<VaultSecret>;
938
+ /**
939
+ * Delete a secret and its version history
940
+ */
941
+ declare function deleteSecret(id: string): Promise<void>;
942
+ /**
943
+ * Get decrypted versions history for a secret
944
+ */
945
+ declare function getSecretVersions(secretId: string): Promise<VaultVersion[]>;
946
+ /**
947
+ * Get audit logs for vault operations
948
+ */
949
+ declare function getLogs(options?: {
950
+ projectId?: string;
951
+ secretId?: string;
952
+ }): Promise<VaultLog[]>;
953
+ declare const vault: {
954
+ getSecrets: typeof getSecrets;
955
+ getSecret: typeof getSecret;
956
+ createSecret: typeof createSecret;
957
+ updateSecretValue: typeof updateSecretValue;
958
+ deleteSecret: typeof deleteSecret;
959
+ getSecretVersions: typeof getSecretVersions;
960
+ getLogs: typeof getLogs;
961
+ };
962
+
963
+ export { type AIChatCompletionOptions, type AIChatCompletionResponse, type AIChatMessage, type AIPromptRunOptions, type AIPromptRunResponse, type AggregateClause, type BatchQueryResult, type BucketInfo, type ChangePasswordInput, ColumnBuilder, type ColumnDataType, type ColumnDefinitionOptions, type CompiledSQL, type Configuration, type ConfigurationInput, type CreateSecretInput, type DatabaseEngine, type DbClient, type DbInterface, type ExistingTableCatalog, type User as IdentityUser, type IndexDefinition, type JoinClause, type JoinType, type ListObjectsResult, MigrationGenerator, type MigrationOperation, type MigrationPlan, type MigrationResult, MigrationRunner, type OrderByClause, PaginatedResponse, type Profile, type ProfileInput, QueryBuilder, type QueryPayload, type Role, type RoleInput, type RoleUpdateInput, type S3Object, SQLCompiler, SchemaDiff, type Service, type ServiceInput, type ServiceUpdateInput, Storage, type StorageOptions, TableDefinition, type TableOptions, type UpdateSecretInput, type User, type UserInput, type VaultLog, type VaultSecret, type VaultVersion, type WhereCondition, ai, app, assignRole, bigint, blob, boolean, changePassword, createRole, createService, createUser, db, defineTable, deleteRole, deleteService, deleteUser, doublePrecision, generateId, getAccessToken, getConfiguration, getProfile, getRoles, getServices, getUsers, initializeSdk, integer, isLoggedIn, json, login, logout, real, search, setAccessToken, text, timestamp, unassignRole, updateConfiguration, updateProfile, updateRole, updateService, updateUser, uuid, varchar, vault, verifyServiceToken, verifyToken };