@mostajs/dialect-registry 0.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,39 @@
1
+ import type { ConnectionConfig, EntitySchema, IDialect } from '@mostajs/orm';
2
+ /**
3
+ * Open an isolated dialect — NOT stored as singleton.
4
+ * Each call returns a new, independent connection to the database.
5
+ * Schemas are initialized on this instance only, not in the global registry.
6
+ *
7
+ * Use this when you need multiple simultaneous database connections
8
+ * (e.g., multi-project / multi-tenant scenarios, default + meta DB split).
9
+ *
10
+ * Example:
11
+ * const metaDialect = await openIsolatedDialect({
12
+ * dialect: 'postgres',
13
+ * uri: 'postgresql://user:pass@localhost:5432/octonet_meta',
14
+ * })
15
+ * registerNamedConnection('meta', metaDialect)
16
+ */
17
+ export declare function openIsolatedDialect(config: ConnectionConfig, schemas?: EntitySchema[]): Promise<IDialect>;
18
+ /**
19
+ * Register a named connection for later retrieval.
20
+ * @param name - Unique name (e.g., 'default', 'meta', 'tenant-42')
21
+ * @param dialect - Connected dialect instance
22
+ */
23
+ export declare function registerNamedConnection(name: string, dialect: IDialect): void;
24
+ /**
25
+ * Retrieve a previously registered named connection.
26
+ * Returns null if not found. Does NOT create a new connection.
27
+ */
28
+ export declare function getNamedConnection(name: string): IDialect | null;
29
+ /** List all registered connection names. */
30
+ export declare function listNamedConnections(): string[];
31
+ /**
32
+ * Remove a named connection from the registry.
33
+ * Does NOT disconnect — call dialect.disconnect() separately if needed.
34
+ */
35
+ export declare function removeNamedConnection(name: string): void;
36
+ /** Remove all named connections (for testing or shutdown). */
37
+ export declare function clearNamedConnections(): void;
38
+ export type { ConnectionConfig, EntitySchema, IDialect } from '@mostajs/orm';
39
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAc7E;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,gBAAgB,EACxB,OAAO,CAAC,EAAE,YAAY,EAAE,GACvB,OAAO,CAAC,QAAQ,CAAC,CAEnB;AAUD;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,IAAI,CAE7E;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAEhE;AAED,4CAA4C;AAC5C,wBAAgB,oBAAoB,IAAI,MAAM,EAAE,CAE/C;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAExD;AAED,8DAA8D;AAC9D,wBAAgB,qBAAqB,IAAI,IAAI,CAE5C;AAGD,YAAY,EAAE,gBAAgB,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,87 @@
1
+ // @mostajs/dialect-registry — Multi-dialect connection registry
2
+ //
3
+ // Orchestre N dialects @mostajs/orm en parallèle dans un même process.
4
+ // Concerne complémentaire de @mostajs/orm (qui possède l'ORM lui-même :
5
+ // schemas, queries, dialects par SGBD). Ce module gère la *coordination* :
6
+ //
7
+ // - openIsolatedDialect(config) → ouvre une connexion neuve (non-singleton)
8
+ // - registerNamedConnection(name, d) → la stocke sous un nom logique
9
+ // - getNamedConnection(name) → la retrouve par nom
10
+ // - listNamedConnections() → liste tous les noms
11
+ // - removeNamedConnection(name) → la sort du registry (sans déconnecter)
12
+ // - clearNamedConnections() → reset complet
13
+ //
14
+ // Cas d'usage typiques :
15
+ // - Octonet : `default` (project DB) + `meta` (RBAC/ApiKey shared avec Octocloud)
16
+ // - Multi-tenant : 1 dialect par tenant, registry-keyed par tenant-id
17
+ // - Tests : isolation per-test
18
+ //
19
+ // Author: Dr Hamid MADANI <drmdh@msn.com>
20
+ import { createIsolatedDialect as _ormCreateIsolatedDialect, registerNamedConnection as _ormRegisterNamedConnection, getNamedConnection as _ormGetNamedConnection, listNamedConnections as _ormListNamedConnections, removeNamedConnection as _ormRemoveNamedConnection, clearNamedConnections as _ormClearNamedConnections, } from '@mostajs/orm';
21
+ // ─────────────────────────────────────────────────────────────────────────
22
+ // openIsolatedDialect — renamed from createIsolatedDialect
23
+ // ─────────────────────────────────────────────────────────────────────────
24
+ //
25
+ // "open" matches the connection lifecycle (cf. JDBC openConnection,
26
+ // Hibernate openSession, POSIX open()) — pendant naturel à `getDialect()`
27
+ // qui partage le singleton. Le verbe `create` insistait sur la fabrication ;
28
+ // `open` insiste sur l'usage.
29
+ //
30
+ // L'implémentation reste dans @mostajs/orm (où vit `loadDialectModule`).
31
+ // Ce ré-export aliase juste le nom dans l'API publique du registry.
32
+ /**
33
+ * Open an isolated dialect — NOT stored as singleton.
34
+ * Each call returns a new, independent connection to the database.
35
+ * Schemas are initialized on this instance only, not in the global registry.
36
+ *
37
+ * Use this when you need multiple simultaneous database connections
38
+ * (e.g., multi-project / multi-tenant scenarios, default + meta DB split).
39
+ *
40
+ * Example:
41
+ * const metaDialect = await openIsolatedDialect({
42
+ * dialect: 'postgres',
43
+ * uri: 'postgresql://user:pass@localhost:5432/octonet_meta',
44
+ * })
45
+ * registerNamedConnection('meta', metaDialect)
46
+ */
47
+ export async function openIsolatedDialect(config, schemas) {
48
+ return _ormCreateIsolatedDialect(config, schemas);
49
+ }
50
+ // ─────────────────────────────────────────────────────────────────────────
51
+ // Named-connection registry — re-exports from @mostajs/orm
52
+ // ─────────────────────────────────────────────────────────────────────────
53
+ //
54
+ // Le store sous-jacent est un Map module-level dans @mostajs/orm. Tant que
55
+ // les deux packages sont chargés via le même process Node.js, ils voient
56
+ // la même instance (Node.js module cache).
57
+ /**
58
+ * Register a named connection for later retrieval.
59
+ * @param name - Unique name (e.g., 'default', 'meta', 'tenant-42')
60
+ * @param dialect - Connected dialect instance
61
+ */
62
+ export function registerNamedConnection(name, dialect) {
63
+ _ormRegisterNamedConnection(name, dialect);
64
+ }
65
+ /**
66
+ * Retrieve a previously registered named connection.
67
+ * Returns null if not found. Does NOT create a new connection.
68
+ */
69
+ export function getNamedConnection(name) {
70
+ return _ormGetNamedConnection(name);
71
+ }
72
+ /** List all registered connection names. */
73
+ export function listNamedConnections() {
74
+ return _ormListNamedConnections();
75
+ }
76
+ /**
77
+ * Remove a named connection from the registry.
78
+ * Does NOT disconnect — call dialect.disconnect() separately if needed.
79
+ */
80
+ export function removeNamedConnection(name) {
81
+ _ormRemoveNamedConnection(name);
82
+ }
83
+ /** Remove all named connections (for testing or shutdown). */
84
+ export function clearNamedConnections() {
85
+ _ormClearNamedConnections();
86
+ }
87
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,EAAE;AACF,uEAAuE;AACvE,wEAAwE;AACxE,2EAA2E;AAC3E,EAAE;AACF,qFAAqF;AACrF,yEAAyE;AACzE,+DAA+D;AAC/D,+DAA+D;AAC/D,kFAAkF;AAClF,yDAAyD;AACzD,EAAE;AACF,yBAAyB;AACzB,oFAAoF;AACpF,wEAAwE;AACxE,iCAAiC;AACjC,EAAE;AACF,0CAA0C;AAE1C,OAAO,EACL,qBAAqB,IAAI,yBAAyB,EAClD,uBAAuB,IAAI,2BAA2B,EACtD,kBAAkB,IAAI,sBAAsB,EAC5C,oBAAoB,IAAI,wBAAwB,EAChD,qBAAqB,IAAI,yBAAyB,EAClD,qBAAqB,IAAI,yBAAyB,GACnD,MAAM,cAAc,CAAC;AAGtB,4EAA4E;AAC5E,4DAA4D;AAC5D,4EAA4E;AAC5E,EAAE;AACF,oEAAoE;AACpE,0EAA0E;AAC1E,6EAA6E;AAC7E,8BAA8B;AAC9B,EAAE;AACF,yEAAyE;AACzE,oEAAoE;AAEpE;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,MAAwB,EACxB,OAAwB;IAExB,OAAO,yBAAyB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACpD,CAAC;AAED,4EAA4E;AAC5E,4DAA4D;AAC5D,4EAA4E;AAC5E,EAAE;AACF,2EAA2E;AAC3E,yEAAyE;AACzE,2CAA2C;AAE3C;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAY,EAAE,OAAiB;IACrE,2BAA2B,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC7C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,OAAO,sBAAsB,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC;AAED,4CAA4C;AAC5C,MAAM,UAAU,oBAAoB;IAClC,OAAO,wBAAwB,EAAE,CAAC;AACpC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,yBAAyB,CAAC,IAAI,CAAC,CAAC;AAClC,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,qBAAqB;IACnC,yBAAyB,EAAE,CAAC;AAC9B,CAAC"}
package/llms.txt ADDED
@@ -0,0 +1,68 @@
1
+ # @mostajs/dialect-registry — fiche LLM
2
+ > Registre de connexions multi-dialecte — orchestre N dialectes parallèles par process (default, meta, per-tenant…).
3
+
4
+ - Version: 0.1.0 · Licence: AGPL-3.0-or-later · Auteur: Dr Hamid MADANI <drmdh@msn.com>
5
+ - Chemin: mostajs/mosta-dialect-registry · Statut audit: complet (dist/)
6
+
7
+ ## RÔLE
8
+ Concern frère de @mostajs/orm : @mostajs/orm possède les implémentations de dialectes,
9
+ ce module gère leur orchestration. Permet d'ouvrir plusieurs connexions de bases de données
10
+ indépendantes dans le même process et de les retrouver par un nom logique (`default`, `meta`,
11
+ `tenant-42`…). Cas d'usage : multi-tenant, séparation base métier / base meta, multi-projet.
12
+
13
+ ## INSTALLATION
14
+ npm i @mostajs/dialect-registry
15
+ (peerDep : @mostajs/orm >=1.13.0)
16
+
17
+ ## EXPORTS
18
+ - openIsolatedDialect — ouvre une connexion isolée (hors singleton)
19
+ - registerNamedConnection, getNamedConnection, listNamedConnections,
20
+ removeNamedConnection, clearNamedConnections
21
+ - Types ré-exportés de @mostajs/orm : ConnectionConfig, EntitySchema, IDialect
22
+
23
+ ## API — SIGNATURES
24
+ - openIsolatedDialect(config: ConnectionConfig, schemas?: EntitySchema[]): Promise<IDialect>
25
+ → chaque appel = connexion neuve et indépendante ; schémas initialisés sur cette
26
+ instance uniquement, pas dans le registre global de @mostajs/orm.
27
+ - registerNamedConnection(name: string, dialect: IDialect): void
28
+ - getNamedConnection(name: string): IDialect | null (null si absent, NE crée rien)
29
+ - listNamedConnections(): string[]
30
+ - removeNamedConnection(name: string): void (ne déconnecte PAS)
31
+ - clearNamedConnections(): void (vide le registre — tests / shutdown)
32
+
33
+ ## TYPES CLÉS
34
+ - ConnectionConfig, EntitySchema, IDialect : ré-exports directs de @mostajs/orm
35
+ (voir la fiche llms.txt de @mostajs/orm pour leur forme détaillée).
36
+
37
+ ## PATTERN
38
+ ```ts
39
+ import {
40
+ openIsolatedDialect, registerNamedConnection, getNamedConnection,
41
+ } from '@mostajs/dialect-registry';
42
+
43
+ const metaDialect = await openIsolatedDialect({
44
+ dialect: 'postgres',
45
+ uri: 'postgresql://user:pass@localhost:5432/octonet_meta',
46
+ });
47
+ registerNamedConnection('meta', metaDialect);
48
+
49
+ // plus loin, ailleurs dans le process :
50
+ const meta = getNamedConnection('meta'); // IDialect | null
51
+ ```
52
+
53
+ ## DÉPEND DE
54
+ - @mostajs/orm (peerDep — fournit IDialect, ConnectionConfig, EntitySchema et la connexion réelle)
55
+
56
+ ## PIÈGES
57
+ - `openIsolatedDialect` ne stocke RIEN comme singleton et n'enregistre pas le dialecte sous
58
+ un nom — il faut appeler `registerNamedConnection` explicitement pour le retrouver ensuite.
59
+ - `getNamedConnection` retourne `null` si le nom est inconnu ; il NE crée pas de connexion.
60
+ - `removeNamedConnection` / `clearNamedConnections` ne ferment PAS la connexion physique —
61
+ appeler `dialect.disconnect()` séparément pour libérer les ressources.
62
+ - Les schémas passés à `openIsolatedDialect` sont locaux à cette instance ; ils n'apparaissent
63
+ pas dans `getAllSchemas()` du registre global de @mostajs/orm.
64
+ - API très proche des helpers `createIsolatedDialect` / `*NamedConnection` de @mostajs/orm
65
+ lui-même — ce module les expose comme concern dédié et stable.
66
+
67
+ ## RÉFÉRENCES
68
+ - (pas de README.md ni CHANGELOG.md présents dans le module au moment de l'audit)
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@mostajs/dialect-registry",
3
+ "version": "0.1.0",
4
+ "description": "Multi-dialect connection registry — orchestrate N parallel dialects per process (default, meta, per-tenant…). Sibling concern of @mostajs/orm (which owns the dialect implementations).",
5
+ "author": "Dr Hamid MADANI <drmdh@msn.com>",
6
+ "license": "AGPL-3.0-or-later",
7
+ "type": "module",
8
+ "main": "dist/index.js",
9
+ "types": "dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js",
14
+ "default": "./dist/index.js"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "LICENSE",
20
+ "README.md",
21
+ "llms.txt"
22
+ ],
23
+ "keywords": [
24
+ "mostajs",
25
+ "orm",
26
+ "dialect",
27
+ "connection",
28
+ "registry",
29
+ "multi-tenant",
30
+ "named-connection"
31
+ ],
32
+ "engines": {
33
+ "node": ">=18.0.0"
34
+ },
35
+ "peerDependencies": {
36
+ "@mostajs/orm": ">=1.13.0"
37
+ },
38
+ "devDependencies": {
39
+ "@mostajs/orm": "^1.13.0",
40
+ "@types/node": "^25.5.2",
41
+ "typescript": "^5.6.0"
42
+ },
43
+ "scripts": {
44
+ "build": "tsc"
45
+ }
46
+ }