@elysiumjs/mnemosyne-drizzle 0.1.3 → 0.1.4

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,88 @@
1
+ import type { TenancyStrategy } from '@elysiumjs/mnemosyne';
2
+ import type { PgColumnBuilderBase, PgSchema, PgTable, PgTransaction } from 'drizzle-orm/pg-core';
3
+ import type { DrizzleConnection } from './database';
4
+ /**
5
+ * Returns the Drizzle `PgSchema` for the given tenant, creating it if needed.
6
+ * @author Axel Nana <axel.nana@workbud.com>
7
+ * @param tenant The tenant identifier.
8
+ * @returns The tenant's PostgreSQL schema.
9
+ */
10
+ export declare const getTenantSchema: (tenant: string) => PgSchema;
11
+ /**
12
+ * Registers a new tenant schema in the registry.
13
+ * @author Axel Nana <axel.nana@workbud.com>
14
+ * @param tenant The tenant identifier.
15
+ * @returns The newly registered (or existing) `PgSchema`.
16
+ */
17
+ export declare const registerTenantSchema: (tenant: string) => PgSchema;
18
+ /**
19
+ * Wraps a table definition in a tenant-specific schema.
20
+ *
21
+ * For the `'public'` tenant, returns a standard `pgTable`.
22
+ * For other tenants, creates a schema-qualified table and caches it.
23
+ *
24
+ * @author Axel Nana <axel.nana@workbud.com>
25
+ * @param tenant The tenant identifier.
26
+ * @param tableName The table name.
27
+ * @param columns The column definitions.
28
+ * @returns A tenant-scoped `PgTable`.
29
+ */
30
+ export declare const wrapTenantSchema: <TTableName extends string, TColumnsMap extends Record<string, PgColumnBuilderBase>>(tenant: string, tableName: TTableName, columns: TColumnsMap) => PgTable;
31
+ /**
32
+ * Executes a callback within an RLS-scoped transaction for the given tenant.
33
+ * @author Axel Nana <axel.nana@workbud.com>
34
+ * @param tenant The tenant identifier (or `null` for 'public').
35
+ * @param callback The function to execute within the transaction.
36
+ * @param connectionName The database connection name.
37
+ * @returns The return value of the callback.
38
+ */
39
+ export declare const withRLS: <T>(tenant: string | null, callback: (tx: PgTransaction<any, any, any>) => Promise<T>, connectionName?: string) => Promise<T>;
40
+ /**
41
+ * Sets the current tenant on a persistent database connection (session-level).
42
+ * @author Axel Nana <axel.nana@workbud.com>
43
+ * @param tenant The tenant identifier (or `null` for 'public').
44
+ * @param connectionName The database connection name.
45
+ */
46
+ export declare const setConnectionTenant: (tenant: string | null, connectionName?: string) => Promise<void>;
47
+ /**
48
+ * Reads the current tenant from the PostgreSQL session variable.
49
+ * @author Axel Nana <axel.nana@workbud.com>
50
+ * @param connectionName The database connection name.
51
+ * @returns The current tenant identifier, or `null`.
52
+ */
53
+ export declare const getSessionTenant: (connectionName?: string) => Promise<string | null>;
54
+ /**
55
+ * Creates an RLS policy for tenant isolation on a table.
56
+ * @author Axel Nana <axel.nana@workbud.com>
57
+ * @param tableName The table name.
58
+ * @param columnName The tenant column name (defaults to config or 'tenant_id').
59
+ * @param policyName The policy name (defaults to `{tableName}_tenant_isolation`).
60
+ * @returns A Drizzle `PgPolicy` instance.
61
+ */
62
+ export declare const createRLSPolicy: (tableName: string, columnName?: string, policyName?: string) => import("drizzle-orm/pg-core").PgPolicy;
63
+ /**
64
+ * Schema-based tenancy strategy for Drizzle.
65
+ *
66
+ * Each tenant gets its own PostgreSQL schema. Table resolution maps
67
+ * the base table to a schema-qualified equivalent.
68
+ *
69
+ * @author Axel Nana <axel.nana@workbud.com>
70
+ */
71
+ export declare class DrizzleSchemaTenancy implements TenancyStrategy<PgTable, DrizzleConnection> {
72
+ readonly mode = "schema";
73
+ resolveTable(table: PgTable, tenant: string): PgTable;
74
+ withIsolation<T>(_connection: DrizzleConnection, _tenant: string, callback: () => Promise<T>): Promise<T>;
75
+ }
76
+ /**
77
+ * Row-Level Security tenancy strategy for Drizzle.
78
+ *
79
+ * All tenants share the same schema. Isolation is achieved via
80
+ * PostgreSQL RLS policies and a session variable set in each transaction.
81
+ *
82
+ * @author Axel Nana <axel.nana@workbud.com>
83
+ */
84
+ export declare class DrizzleRLSTenancy implements TenancyStrategy<PgTable, DrizzleConnection> {
85
+ readonly mode = "rls";
86
+ resolveTable(table: PgTable, _tenant: string): PgTable;
87
+ withIsolation<T>(connection: DrizzleConnection, tenant: string, callback: () => Promise<T>): Promise<T>;
88
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elysiumjs/mnemosyne-drizzle",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Drizzle ORM driver for @elysiumjs/mnemosyne",
6
6
  "private": false,
@@ -31,14 +31,14 @@
31
31
  "types": "dist/index.d.ts",
32
32
  "sideEffects": false,
33
33
  "peerDependencies": {
34
- "@elysiumjs/core": "workspace:^",
35
- "@elysiumjs/mnemosyne": "workspace:^"
34
+ "@elysiumjs/core": "^0.7.0",
35
+ "@elysiumjs/mnemosyne": "^0.1.1"
36
36
  },
37
37
  "dependencies": {
38
38
  "drizzle-orm": "^0.45.1"
39
39
  },
40
40
  "devDependencies": {
41
- "@elysiumjs/core": "workspace:*",
42
- "@elysiumjs/mnemosyne": "workspace:*"
41
+ "@elysiumjs/core": "0.7.0",
42
+ "@elysiumjs/mnemosyne": "0.1.1"
43
43
  }
44
44
  }
package/src/index.ts CHANGED
@@ -22,7 +22,15 @@ import { Database } from './database';
22
22
  import { DrizzleRLSTenancy, DrizzleSchemaTenancy } from './tenancy';
23
23
 
24
24
  // Re-export drizzle-orm/pg-core with enhanced pgTable
25
+ export * from 'drizzle-orm';
25
26
  export * from 'drizzle-orm/pg-core';
27
+ export type {
28
+ ColumnsWithTable,
29
+ SelectedFields,
30
+ SelectedFieldsFlat,
31
+ SelectedFieldsOrdered,
32
+ TableConfig
33
+ } from 'drizzle-orm/pg-core';
26
34
  export { pgTable, getTableBuilders } from './table';
27
35
 
28
36
  // Re-exports
package/bunfig.toml DELETED
@@ -1,11 +0,0 @@
1
- [test]
2
- root = "./tests"
3
- preload = ["./tests/setup.ts"]
4
- coverage = true
5
- coverageThreshold = { line = 0.9, function = 0.7, statement = 0.8 }
6
- coverageSkipTestFiles = true
7
- coverageReporter = ["lcov", "text"]
8
- coverageDir = "./coverage"
9
-
10
- [run]
11
- bun = true