@xemahq/biome-database-nest 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.
package/LICENSE ADDED
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
package/README.md ADDED
@@ -0,0 +1,94 @@
1
+ <p align="center">
2
+ <svg width="680" height="120" viewBox="0 0 680 120" fill="none" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="@xemahq/biome-database-nest">
3
+ <rect width="680" height="120" rx="14" fill="#0B1020"/>
4
+ <g transform="translate(28,34)">
5
+ <path d="M26 0 L52 15 L52 45 L26 60 L0 45 L0 15 Z" fill="#8B5CF6" opacity="0.18"/>
6
+ <path d="M26 12 L41 21 L41 39 L26 48 L11 39 L11 21 Z" fill="#8B5CF6"/>
7
+ </g>
8
+ <text x="92" y="52" font-family="ui-monospace,SFMono-Regular,Menlo,monospace" font-size="22" fill="#F8FAFC" font-weight="700">@xemahq/biome-database-nest</text>
9
+ <text x="92" y="80" font-family="ui-sans-serif,system-ui,sans-serif" font-size="15" fill="#94A3B8">Centralized database wiring for Xema biome services.</text>
10
+ <text x="652" y="105" text-anchor="end" font-family="ui-sans-serif,system-ui,sans-serif" font-size="12" fill="#475569">xema.dev</text>
11
+ </svg>
12
+ </p>
13
+
14
+ <p align="center">
15
+ <a href="https://xema.dev">Website</a> &middot;
16
+ <a href="https://www.npmjs.com/package/@xemahq/biome-database-nest">npm</a>
17
+ </p>
18
+
19
+ <p align="center">
20
+ <img alt="npm" src="https://img.shields.io/npm/v/%40xemahq%2Fbiome-database-nest?color=2563eb&label=npm">
21
+ <img alt="license" src="https://img.shields.io/npm/l/%40xemahq%2Fbiome-database-nest?color=10b981">
22
+ <img alt="types" src="https://img.shields.io/npm/types/%40xemahq%2Fbiome-database-nest?color=3178c6">
23
+ </p>
24
+
25
+ # @xemahq/biome-database-nest
26
+
27
+ > Centralized database wiring for Xema biome services.
28
+
29
+ This package belongs to Layer 1 — it depends only on Layer 0 contracts and
30
+ other Layer 1 SDKs plus npm libraries, and carries zero domain knowledge.
31
+
32
+ ## Overview
33
+
34
+ Xema biome services share one Postgres database and isolate their tables per
35
+ biome by schema (`biome_<id>`). This package makes the correct database
36
+ construction the only construction a biome can perform, so biome services carry
37
+ no DB boilerplate. It provides:
38
+
39
+ - **The schema-qualified driver-adapter.** `createBiomePrismaAdapter` (and its
40
+ `…FromEnv` sibling) build a `PrismaPg` pool that passes the schema as the
41
+ second constructor argument — the one thing that makes Prisma qualify
42
+ `biome_<id>.<table>` instead of `public.<table>`. Raw queries are covered
43
+ separately via the libpq `search_path` option.
44
+ - **The schema-naming convention.** `deriveBiomeSchemaName(biomeId, dbKey?)`
45
+ produces a deterministic, collision-resistant, 63-byte-safe schema name so
46
+ two biomes never collide.
47
+ - **Config resolution.** `resolveBiomeDatabaseConfigFromEnv` reads the standard
48
+ `DB_*` contract (with per-key suffixes); `fetchSystemDatabaseConfig` pulls a
49
+ fully-resolved config from the control plane.
50
+ - **Boot-time bootstrap.** `bootstrapBiomeDatabases` resolves config, writes an
51
+ inline CA cert if supplied, creates the schema under an advisory lock, runs
52
+ `prisma migrate deploy`, and exports the resolved connection into the env.
53
+
54
+ ## When to use it
55
+
56
+ - Use it inside a biome service so the service never hand-wires Prisma, the
57
+ schema name, or the migrate-time connection string.
58
+ - Reach for `createBiomePrismaAdapterFromEnv` in a `PrismaService` constructor,
59
+ and `bootstrapBiomeDatabases` at service boot before Nest starts.
60
+
61
+ ## Installation
62
+
63
+ ```bash
64
+ pnpm add @xemahq/biome-database-nest
65
+ ```
66
+
67
+ ## Usage
68
+
69
+ ```ts
70
+ import {
71
+ bootstrapBiomeDatabases,
72
+ createBiomePrismaAdapterFromEnv,
73
+ } from '@xemahq/biome-database-nest';
74
+
75
+ // At boot (main.ts), before NestFactory.create:
76
+ await bootstrapBiomeDatabases({
77
+ biomeId: 'mailops',
78
+ databases: [{ workspaceDir: process.cwd() }],
79
+ registry,
80
+ serviceToken: () => identity.getAccessToken(),
81
+ });
82
+
83
+ // In PrismaService:
84
+ const adapter = createBiomePrismaAdapterFromEnv(process.env);
85
+ ```
86
+
87
+ ## Peer requirements
88
+
89
+ - `@prisma/client`, `@prisma/adapter-pg` — the consumer owns the Prisma
90
+ version; the adapter is constructed against the consumer's copy.
91
+
92
+ ## License
93
+
94
+ Apache-2.0 &copy; Xema — [xema.dev](https://xema.dev)
@@ -0,0 +1,6 @@
1
+ export { DEFAULT_BIOME_DB_KEY, deriveBiomeSchemaName, } from './lib/schema-name';
2
+ export { resolveBiomeDatabaseConfigFromEnv, type BiomeDatabaseConfig, } from './lib/config';
3
+ export { createBiomePrismaAdapter, createBiomePrismaAdapterFromEnv, } from './lib/adapter';
4
+ export { fetchSystemDatabaseConfig, type SystemDatabaseConfigRequest, } from './lib/control-plane-client';
5
+ export { bootstrapBiomeDatabases, type BiomeDatabaseDeclaration, type BootstrapBiomeDatabasesOptions, } from './lib/bootstrap';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,iCAAiC,EACjC,KAAK,mBAAmB,GACzB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,wBAAwB,EACxB,+BAA+B,GAChC,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,yBAAyB,EACzB,KAAK,2BAA2B,GACjC,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,uBAAuB,EACvB,KAAK,wBAAwB,EAC7B,KAAK,8BAA8B,GACpC,MAAM,iBAAiB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bootstrapBiomeDatabases = exports.fetchSystemDatabaseConfig = exports.createBiomePrismaAdapterFromEnv = exports.createBiomePrismaAdapter = exports.resolveBiomeDatabaseConfigFromEnv = exports.deriveBiomeSchemaName = exports.DEFAULT_BIOME_DB_KEY = void 0;
4
+ var schema_name_1 = require("./lib/schema-name");
5
+ Object.defineProperty(exports, "DEFAULT_BIOME_DB_KEY", { enumerable: true, get: function () { return schema_name_1.DEFAULT_BIOME_DB_KEY; } });
6
+ Object.defineProperty(exports, "deriveBiomeSchemaName", { enumerable: true, get: function () { return schema_name_1.deriveBiomeSchemaName; } });
7
+ var config_1 = require("./lib/config");
8
+ Object.defineProperty(exports, "resolveBiomeDatabaseConfigFromEnv", { enumerable: true, get: function () { return config_1.resolveBiomeDatabaseConfigFromEnv; } });
9
+ var adapter_1 = require("./lib/adapter");
10
+ Object.defineProperty(exports, "createBiomePrismaAdapter", { enumerable: true, get: function () { return adapter_1.createBiomePrismaAdapter; } });
11
+ Object.defineProperty(exports, "createBiomePrismaAdapterFromEnv", { enumerable: true, get: function () { return adapter_1.createBiomePrismaAdapterFromEnv; } });
12
+ var control_plane_client_1 = require("./lib/control-plane-client");
13
+ Object.defineProperty(exports, "fetchSystemDatabaseConfig", { enumerable: true, get: function () { return control_plane_client_1.fetchSystemDatabaseConfig; } });
14
+ var bootstrap_1 = require("./lib/bootstrap");
15
+ Object.defineProperty(exports, "bootstrapBiomeDatabases", { enumerable: true, get: function () { return bootstrap_1.bootstrapBiomeDatabases; } });
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iDAG2B;AAFzB,mHAAA,oBAAoB,OAAA;AACpB,oHAAA,qBAAqB,OAAA;AAEvB,uCAGsB;AAFpB,2HAAA,iCAAiC,OAAA;AAGnC,yCAGuB;AAFrB,mHAAA,wBAAwB,OAAA;AACxB,0HAAA,+BAA+B,OAAA;AAEjC,mEAGoC;AAFlC,iIAAA,yBAAyB,OAAA;AAG3B,6CAIyB;AAHvB,oHAAA,uBAAuB,OAAA"}
@@ -0,0 +1,5 @@
1
+ import { PrismaPg } from '@prisma/adapter-pg';
2
+ import type { BiomeDatabaseConfig } from './config';
3
+ export declare function createBiomePrismaAdapter(config: BiomeDatabaseConfig): PrismaPg;
4
+ export declare function createBiomePrismaAdapterFromEnv(env?: NodeJS.ProcessEnv, dbKey?: string): PrismaPg;
5
+ //# sourceMappingURL=adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/lib/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAM9C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AA2CpD,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,mBAAmB,GAAG,QAAQ,CAW9E;AAeD,wBAAgB,+BAA+B,CAC7C,GAAG,GAAE,MAAM,CAAC,UAAwB,EACpC,KAAK,CAAC,EAAE,MAAM,GACb,QAAQ,CAmCV"}
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createBiomePrismaAdapter = createBiomePrismaAdapter;
4
+ exports.createBiomePrismaAdapterFromEnv = createBiomePrismaAdapterFromEnv;
5
+ const adapter_pg_1 = require("@prisma/adapter-pg");
6
+ const platform_common_1 = require("@xemahq/platform-common");
7
+ const config_1 = require("./config");
8
+ const DEFAULT_POOL_MAX = 3;
9
+ function buildBiomeConnectionString(config) {
10
+ const url = (0, platform_common_1.composeBiomeDatabaseUrl)({
11
+ user: config.username,
12
+ password: config.password,
13
+ host: config.host,
14
+ port: String(config.port),
15
+ database: config.database,
16
+ ...(config.schema !== undefined ? { schema: config.schema } : {}),
17
+ ...(config.sslParams !== undefined ? { sslParams: config.sslParams } : {}),
18
+ });
19
+ if (url === null) {
20
+ throw new Error('createBiomePrismaAdapter: incomplete BiomeDatabaseConfig — ' +
21
+ 'host/port/database/username/password are all required.');
22
+ }
23
+ return (0, platform_common_1.ensureBiomeDbSearchPath)(url);
24
+ }
25
+ function createBiomePrismaAdapter(config) {
26
+ const connectionString = buildBiomeConnectionString(config);
27
+ return new adapter_pg_1.PrismaPg({
28
+ connectionString,
29
+ min: 1,
30
+ max: config.poolMax ?? DEFAULT_POOL_MAX,
31
+ idleTimeoutMillis: 30_000,
32
+ }, config.schema !== undefined ? { schema: config.schema } : undefined);
33
+ }
34
+ function createBiomePrismaAdapterFromEnv(env = process.env, dbKey) {
35
+ const isDefault = dbKey === undefined || dbKey === '' || dbKey === 'primary';
36
+ const upperSuffix = isDefault
37
+ ? ''
38
+ : `_${dbKey.toUpperCase().replace(/[^A-Z0-9]/g, '_')}`;
39
+ const directUrl = env[`DATABASE_URL${upperSuffix}`];
40
+ const schema = env[`DB_SCHEMA${upperSuffix}`];
41
+ const poolMaxRaw = env[`DB_POOL_MAX${upperSuffix}`] ?? env.DB_POOL_MAX;
42
+ const poolMax = poolMaxRaw !== undefined && poolMaxRaw !== ''
43
+ ? Number.parseInt(poolMaxRaw, 10)
44
+ : DEFAULT_POOL_MAX;
45
+ if (directUrl !== undefined && directUrl !== '') {
46
+ const connectionString = (0, platform_common_1.ensureBiomeDbSearchPath)(directUrl);
47
+ return new adapter_pg_1.PrismaPg({
48
+ connectionString,
49
+ min: 1,
50
+ max: poolMax,
51
+ idleTimeoutMillis: 30_000,
52
+ }, schema !== undefined && schema !== '' ? { schema } : undefined);
53
+ }
54
+ const config = (0, config_1.resolveBiomeDatabaseConfigFromEnv)(env, dbKey);
55
+ if (config === null) {
56
+ throw new Error(`createBiomePrismaAdapterFromEnv: no DATABASE_URL${upperSuffix} and no ` +
57
+ `DB_HOST${upperSuffix}/DB_HOST in the environment — cannot construct an adapter.`);
58
+ }
59
+ return createBiomePrismaAdapter(config);
60
+ }
61
+ //# sourceMappingURL=adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../src/lib/adapter.ts"],"names":[],"mappings":";;AAiDA,4DAWC;AAeD,0EAsCC;AAjHD,mDAA8C;AAC9C,6DAGiC;AAGjC,qCAA6D;AAE7D,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAS3B,SAAS,0BAA0B,CAAC,MAA2B;IAC7D,MAAM,GAAG,GAAG,IAAA,yCAAuB,EAAC;QAClC,IAAI,EAAE,MAAM,CAAC,QAAQ;QACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;QACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,GAAG,CAAC,MAAM,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAA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AU,GAAG,GAAG,CAAC,cAAc,WAAW,EAAE,CAAC,IAAI,GAAG,CAAC,WAAW,CAAC;IACvE,MAAM,OAAO,GACX,UAAU,KAAK,SAAS,IAAI,UAAU,KAAK,EAAE;QAC3C,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,EAAE,CAAC;QACjC,CAAC,CAAC,gBAAgB,CAAC;IAEvB,IAAI,SAAS,KAAK,SAAS,IAAI,SAAS,KAAK,EAAE,EAAE,CAAC;QAChD,MAAM,gBAAgB,GAAG,IAAA,yCAAuB,EAAC,SAAS,CAAC,CAAC;QAC5D,OAAO,IAAI,qBAAQ,CACjB;YACE,gBAAgB;YAChB,GAAG,EAAE,CAAC;YACN,GAAG,EAAE,OAAO;YACZ,iBAAiB,EAAE,MAAM;SAC1B,EACD,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS,CAC/D,CAAC;IACJ,CAAC;IAED,MAAM,MAAM,GAAG,IAAA,0CAAiC,EAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC7D,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CACb,mDAAmD,WAAW,UAAU;YACtE,UAAU,WAAW,4DAA4D,CACpF,CAAC;IACJ,CAAC;IACD,OAAO,wBAAwB,CAAC,MAAM,CAAC,CAAC;AAC1C,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { ServiceRegistry } from '@xemahq/kernel-contracts/service-registry';
2
+ export interface BiomeDatabaseDeclaration {
3
+ readonly key?: string;
4
+ readonly workspaceDir: string;
5
+ }
6
+ export interface BootstrapBiomeDatabasesOptions {
7
+ readonly biomeId: string;
8
+ readonly databases: readonly BiomeDatabaseDeclaration[];
9
+ readonly registry?: ServiceRegistry;
10
+ readonly serviceToken?: string | (() => Promise<string>);
11
+ }
12
+ export declare function bootstrapBiomeDatabases(opts: BootstrapBiomeDatabasesOptions): Promise<void>;
13
+ //# sourceMappingURL=bootstrap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../src/lib/bootstrap.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AASjF,MAAM,WAAW,wBAAwB;IAEvC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAEtB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,SAAS,wBAAwB,EAAE,CAAC;IAExD,QAAQ,CAAC,QAAQ,CAAC,EAAE,eAAe,CAAC;IAEpC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;CAC1D;AAwLD,wBAAsB,uBAAuB,CAC3C,IAAI,EAAE,8BAA8B,GACnC,OAAO,CAAC,IAAI,CAAC,CA2Bf"}
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bootstrapBiomeDatabases = bootstrapBiomeDatabases;
4
+ const node_crypto_1 = require("node:crypto");
5
+ const promises_1 = require("node:fs/promises");
6
+ const node_os_1 = require("node:os");
7
+ const node_path_1 = require("node:path");
8
+ const platform_common_1 = require("@xemahq/platform-common");
9
+ const migration_runner_prisma_1 = require("@xemahq/migration-runner-prisma");
10
+ const pg_1 = require("pg");
11
+ const config_1 = require("./config");
12
+ const control_plane_client_1 = require("./control-plane-client");
13
+ const schema_name_1 = require("./schema-name");
14
+ const LOG_PREFIX = '[biome-database]';
15
+ function upperKeySuffix(key) {
16
+ return key === schema_name_1.DEFAULT_BIOME_DB_KEY
17
+ ? ''
18
+ : `_${key.toUpperCase().replace(/[^A-Z0-9]/g, '_')}`;
19
+ }
20
+ async function resolveServiceToken(serviceToken) {
21
+ if (serviceToken === undefined) {
22
+ throw new Error(`${LOG_PREFIX} no local DB_* override and no serviceToken supplied — ` +
23
+ 'cannot authenticate to the control plane.');
24
+ }
25
+ return typeof serviceToken === 'function' ? serviceToken() : serviceToken;
26
+ }
27
+ async function resolveDatabaseConfig(opts, key) {
28
+ const local = (0, config_1.resolveBiomeDatabaseConfigFromEnv)(process.env, key);
29
+ if (local !== null) {
30
+ return local;
31
+ }
32
+ if (opts.registry === undefined) {
33
+ throw new Error(`${LOG_PREFIX} no DB_* override for biome "${opts.biomeId}" key "${key}" ` +
34
+ 'and no registry supplied — cannot resolve the control-plane config.');
35
+ }
36
+ const token = await resolveServiceToken(opts.serviceToken);
37
+ return (0, control_plane_client_1.fetchSystemDatabaseConfig)(opts.registry, token, {
38
+ biomeId: opts.biomeId,
39
+ ...(key !== schema_name_1.DEFAULT_BIOME_DB_KEY ? { dbKey: key } : {}),
40
+ });
41
+ }
42
+ async function materializeInlineCaCert(biomeId, key, config) {
43
+ if (config.caCertPem === undefined || config.caCertPem === '') {
44
+ return config;
45
+ }
46
+ const hash = (0, node_crypto_1.createHash)('sha256')
47
+ .update(`${biomeId}:${key}`)
48
+ .digest('hex')
49
+ .slice(0, 16);
50
+ const certPath = (0, node_path_1.join)((0, node_os_1.tmpdir)(), `xema-biome-db-ca-${hash}.crt`);
51
+ await (0, promises_1.writeFile)(certPath, config.caCertPem, { mode: 0o600 });
52
+ const params = new URLSearchParams(config.sslParams ?? '');
53
+ params.set('sslrootcert', certPath);
54
+ if (!params.has('sslmode')) {
55
+ params.set('sslmode', 'verify-full');
56
+ }
57
+ console.log(`${LOG_PREFIX} biome=${biomeId} key=${key}: wrote inline CA cert to ${certPath}`);
58
+ return { ...config, sslParams: params.toString() };
59
+ }
60
+ async function ensureSchemaExists(biomeId, key, config) {
61
+ const schema = config.schema;
62
+ if (schema === undefined || schema === '') {
63
+ return;
64
+ }
65
+ const client = new pg_1.Client({
66
+ host: config.host,
67
+ port: config.port,
68
+ database: config.database,
69
+ user: config.username,
70
+ password: config.password,
71
+ });
72
+ await client.connect();
73
+ try {
74
+ await client.query('BEGIN');
75
+ await client.query('SELECT pg_advisory_xact_lock(hashtext($1))', [schema]);
76
+ await client.query(`CREATE SCHEMA IF NOT EXISTS "${schema}"`);
77
+ await client.query('COMMIT');
78
+ console.log(`${LOG_PREFIX} biome=${biomeId} key=${key}: ensured schema "${schema}" exists`);
79
+ }
80
+ catch (err) {
81
+ await client.query('ROLLBACK').catch(() => undefined);
82
+ throw err;
83
+ }
84
+ finally {
85
+ await client.end();
86
+ }
87
+ }
88
+ async function runMigrations(biomeId, key, workspaceDir, config) {
89
+ const migrateUrl = (0, platform_common_1.composeBiomeDatabaseUrl)({
90
+ user: config.username,
91
+ password: config.password,
92
+ host: config.host,
93
+ port: String(config.port),
94
+ database: config.database,
95
+ ...(config.schema !== undefined ? { schema: config.schema } : {}),
96
+ ...(config.sslParams !== undefined ? { sslParams: config.sslParams } : {}),
97
+ });
98
+ if (migrateUrl === null) {
99
+ throw new Error(`${LOG_PREFIX} biome=${biomeId} key=${key}: incomplete config — cannot form a migrate URL.`);
100
+ }
101
+ console.log(`${LOG_PREFIX} biome=${biomeId} key=${key}: running prisma migrate deploy (cwd=${workspaceDir})`);
102
+ const result = await new migration_runner_prisma_1.PrismaMigrationRunner().run({
103
+ workspaceDir,
104
+ connectionUrl: migrateUrl,
105
+ env: {},
106
+ });
107
+ if (result.exitCode !== 0) {
108
+ throw new Error(`${LOG_PREFIX} biome=${biomeId} key=${key}: migrations failed (exit ${result.exitCode}):\n${result.output}`);
109
+ }
110
+ return migrateUrl;
111
+ }
112
+ function exportResolvedEnv(key, config, runtimeUrl) {
113
+ const suffix = upperKeySuffix(key);
114
+ process.env[`DATABASE_URL${suffix}`] = runtimeUrl;
115
+ if (config.schema !== undefined && config.schema !== '') {
116
+ process.env[`DB_SCHEMA${suffix}`] = config.schema;
117
+ }
118
+ }
119
+ async function bootstrapBiomeDatabases(opts) {
120
+ for (const decl of opts.databases) {
121
+ const key = decl.key ?? schema_name_1.DEFAULT_BIOME_DB_KEY;
122
+ console.log(`${LOG_PREFIX} biome=${opts.biomeId} key=${key}: resolving config`);
123
+ const rawConfig = await resolveDatabaseConfig(opts, key);
124
+ const config = await materializeInlineCaCert(opts.biomeId, key, rawConfig);
125
+ await ensureSchemaExists(opts.biomeId, key, config);
126
+ const migrateUrl = await runMigrations(opts.biomeId, key, decl.workspaceDir, config);
127
+ const runtimeUrl = (0, platform_common_1.ensureBiomeDbSearchPath)(migrateUrl);
128
+ exportResolvedEnv(key, config, runtimeUrl);
129
+ console.log(`${LOG_PREFIX} biome=${opts.biomeId} key=${key}: bootstrap complete`);
130
+ }
131
+ }
132
+ //# sourceMappingURL=bootstrap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../src/lib/bootstrap.ts"],"names":[],"mappings":";;AAyNA,0DA6BC;AAtPD,6CAAyC;AACzC,+CAA6C;AAC7C,qCAAiC;AACjC,yCAAiC;AAEjC,6DAGiC;AACjC,6EAAwE;AAExE,2BAA4B;AAG5B,qCAA6D;AAC7D,iEAAmE;AACnE,+CAAqD;AAmBrD,MAAM,UAAU,GAAG,kBAAkB,CAAC;AAEtC,SAAS,cAAc,CAAC,GAAW;IACjC,OAAO,GAAG,KAAK,kCAAoB;QACjC,CAAC,CAAC,EAAE;QACJ,CAAC,CAAC,IAAI,GAAG,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,YAAY,EAAE,GAAG,CAAC,EAAE,CAAC;AACzD,CAAC;AAED,KAAK,UAAU,mBAAmB,CAChC,YAA0D;IAE1D,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CACb,GAAG,UAAU,yDAAyD;YACpE,2CAA2C,CAC9C,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,YAAY,KAAK,UAAU,C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I,EAAE,GAAG,CAAC,CAAC;QACzD,MAAM,MAAM,GAAG,MAAM,uBAAuB,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC;QAE3E,MAAM,kBAAkB,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;QACpD,MAAM,UAAU,GAAG,MAAM,aAAa,CACpC,IAAI,CAAC,OAAO,EACZ,GAAG,EACH,IAAI,CAAC,YAAY,EACjB,MAAM,CACP,CAAC;QAIF,MAAM,UAAU,GAAG,IAAA,yCAAuB,EAAC,UAAU,CAAC,CAAC;QACvD,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;QAE3C,OAAO,CAAC,GAAG,CACT,GAAG,UAAU,UAAU,IAAI,CAAC,OAAO,QAAQ,GAAG,sBAAsB,CACrE,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,13 @@
1
+ export interface BiomeDatabaseConfig {
2
+ readonly host: string;
3
+ readonly port: number;
4
+ readonly database: string;
5
+ readonly schema?: string;
6
+ readonly username: string;
7
+ readonly password: string;
8
+ readonly sslParams?: string;
9
+ readonly caCertPem?: string;
10
+ readonly poolMax?: number;
11
+ }
12
+ export declare function resolveBiomeDatabaseConfigFromEnv(env?: NodeJS.ProcessEnv, dbKey?: string): BiomeDatabaseConfig | null;
13
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAE5B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AA8CD,wBAAgB,iCAAiC,CAC/C,GAAG,GAAE,MAAM,CAAC,UAAwB,EACpC,KAAK,CAAC,EAAE,MAAM,GACb,mBAAmB,GAAG,IAAI,CAwD5B"}
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveBiomeDatabaseConfigFromEnv = resolveBiomeDatabaseConfigFromEnv;
4
+ const schema_name_1 = require("./schema-name");
5
+ function envSuffixForKey(dbKey) {
6
+ if (dbKey === undefined || dbKey === '' || dbKey === schema_name_1.DEFAULT_BIOME_DB_KEY) {
7
+ return '';
8
+ }
9
+ return `_${dbKey.toUpperCase().replace(/[^A-Z0-9]/g, '_')}`;
10
+ }
11
+ function readDbVar(env, base, suffix, fallbackToBase) {
12
+ const suffixed = env[`${base}${suffix}`];
13
+ if (suffixed !== undefined && suffixed !== '') {
14
+ return suffixed;
15
+ }
16
+ if (!fallbackToBase || suffix === '') {
17
+ return undefined;
18
+ }
19
+ const baseVal = env[base];
20
+ return baseVal !== undefined && baseVal !== '' ? baseVal : undefined;
21
+ }
22
+ function resolveBiomeDatabaseConfigFromEnv(env = process.env, dbKey) {
23
+ const suffix = envSuffixForKey(dbKey);
24
+ const host = readDbVar(env, 'DB_HOST', suffix, true);
25
+ if (host === undefined) {
26
+ return null;
27
+ }
28
+ const portRaw = readDbVar(env, 'DB_PORT', suffix, true);
29
+ const username = readDbVar(env, 'DB_USER', suffix, true);
30
+ const password = readDbVar(env, 'DB_PASSWORD', suffix, true);
31
+ const database = readDbVar(env, 'DB_NAME', suffix, suffix === '');
32
+ const schema = readDbVar(env, 'DB_SCHEMA', suffix, suffix === '');
33
+ const missing = [];
34
+ if (portRaw === undefined)
35
+ missing.push(`DB_PORT${suffix}`);
36
+ if (username === undefined)
37
+ missing.push(`DB_USER${suffix}`);
38
+ if (password === undefined)
39
+ missing.push(`DB_PASSWORD${suffix}`);
40
+ if (database === undefined)
41
+ missing.push(`DB_NAME${suffix}`);
42
+ if (missing.length > 0) {
43
+ throw new Error(`Partial biome database config for dbKey "${dbKey ?? schema_name_1.DEFAULT_BIOME_DB_KEY}": ` +
44
+ `DB_HOST${suffix} is set but the following are missing: ${missing.join(', ')}. ` +
45
+ `Provide all of them or none.`);
46
+ }
47
+ const port = Number.parseInt(portRaw, 10);
48
+ if (!Number.isInteger(port) || port <= 0) {
49
+ throw new Error(`Invalid DB_PORT${suffix} value "${portRaw}" — expected a positive integer.`);
50
+ }
51
+ const sslParams = readDbVar(env, 'DB_SSL_PARAMS', suffix, true);
52
+ const poolMaxRaw = readDbVar(env, 'DB_POOL_MAX', suffix, true);
53
+ const poolMax = poolMaxRaw !== undefined ? Number.parseInt(poolMaxRaw, 10) : undefined;
54
+ if (poolMaxRaw !== undefined && (!Number.isInteger(poolMax) || poolMax <= 0)) {
55
+ throw new Error(`Invalid DB_POOL_MAX${suffix} value "${poolMaxRaw}" — expected a positive integer.`);
56
+ }
57
+ return {
58
+ host,
59
+ port,
60
+ database: database,
61
+ username: username,
62
+ password: password,
63
+ ...(schema !== undefined ? { schema } : {}),
64
+ ...(sslParams !== undefined ? { sslParams } : {}),
65
+ ...(poolMax !== undefined ? { poolMax } : {}),
66
+ };
67
+ }
68
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":";;AAkEA,8EA2DC;AA7HD,+CAAqD;AAuBrD,SAAS,eAAe,CAAC,KAAyB;IAChD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE,IAAI,KAAK,KAAK,kCAAoB,EAAE,CAAC;QAC1E,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,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IAC/D,MAAM,OAAO,GACX,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACzE,IAAI,UAAU,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,OAAQ,IAAI,CAAC,CAAC,EAAE,CAAC;QAC9E,MAAM,IAAI,KAAK,CACb,sBAAsB,MAAM,WAAW,UAAU,kCAAkC,CACpF,CAAC;IACJ,CAAC;IAED,OAAO;QACL,IAAI;QACJ,IAAI;QACJ,QAAQ,EAAE,QAAkB;QAC5B,QAAQ,EAAE,QAAkB;QAC5B,QAAQ,EAAE,QAAkB;QAC5B,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3C,GAAG,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACjD,GAAG,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC9C,CAAC;AACJ,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { ServiceRegistry } from '@xemahq/kernel-contracts/service-registry';
2
+ import type { BiomeDatabaseConfig } from './config';
3
+ export interface SystemDatabaseConfigRequest {
4
+ readonly biomeId: string;
5
+ readonly dbKey?: string;
6
+ }
7
+ export declare function fetchSystemDatabaseConfig(registry: ServiceRegistry, serviceToken: string, req: SystemDatabaseConfigRequest): Promise<BiomeDatabaseConfig>;
8
+ //# sourceMappingURL=control-plane-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"control-plane-client.d.ts","sourceRoot":"","sources":["../../src/lib/control-plane-client.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AAGjF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEpD,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAWD,wBAAsB,yBAAyB,CAC7C,QAAQ,EAAE,eAAe,EACzB,YAAY,EAAE,MAAM,EACpB,GAAG,EAAE,2BAA2B,GAC/B,OAAO,CAAC,mBAAmB,CAAC,CAwB9B"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchSystemDatabaseConfig = fetchSystemDatabaseConfig;
4
+ const service_registry_1 = require("@xemahq/kernel-contracts/service-registry");
5
+ const service_registry_nest_1 = require("@xemahq/service-registry-nest");
6
+ async function fetchSystemDatabaseConfig(registry, serviceToken, req) {
7
+ const base = await (0, service_registry_nest_1.resolveHttpUrl)(registry, service_registry_1.ServiceName.ORG_DATABASE_POOL_API);
8
+ const url = `${base.replace(/\/$/, '')}/system-databases/config`;
9
+ const response = await fetch(url, {
10
+ method: 'POST',
11
+ headers: {
12
+ authorization: `Bearer ${serviceToken}`,
13
+ 'content-type': 'application/json',
14
+ },
15
+ body: JSON.stringify({
16
+ biomeId: req.biomeId,
17
+ ...(req.dbKey !== undefined ? { dbKey: req.dbKey } : {}),
18
+ }),
19
+ });
20
+ if (!response.ok) {
21
+ const body = await response.text().catch(() => '<unreadable body>');
22
+ throw new Error(`fetchSystemDatabaseConfig: ${url} responded ${response.status} ${response.statusText}: ${body}`);
23
+ }
24
+ return (await response.json());
25
+ }
26
+ //# sourceMappingURL=control-plane-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"control-plane-client.js","sourceRoot":"","sources":["../../src/lib/control-plane-client.ts"],"names":[],"mappings":";;AA+CA,8DA4BC;AAhDD,gFAAwE;AAExE,yEAA+D;AAkBxD,KAAK,UAAU,yBAAyB,CAC7C,QAAyB,EACzB,YAAoB,EACpB,GAAgC;IAEhC,MAAM,IAAI,GAAG,MAAM,IAAA,sCAAc,EAAC,QAAQ,EAAE,8BAAW,CAAC,qBAAqB,CAAC,CAAC;IAC/E,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,0BAA0B,CAAC;IAEjE,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;QAChC,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,aAAa,EAAE,UAAU,YAAY,EAAE;YACvC,cAAc,EAAE,kBAAkB;SACnC;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;YACnB,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,GAAG,CAAC,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACzD,CAAC;KACH,CAAC,CAAC;IAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,mBAAmB,CAAC,CAAC;QACpE,MAAM,IAAI,KAAK,CACb,8BAA8B,GAAG,cAAc,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,KAAK,IAAI,EAAE,CACjG,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAwB,CAAC;AACxD,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare const DEFAULT_BIOME_DB_KEY = "primary";
2
+ export declare function deriveBiomeSchemaName(biomeId: string, dbKey?: string): string;
3
+ //# sourceMappingURL=schema-name.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema-name.d.ts","sourceRoot":"","sources":["../../src/lib/schema-name.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,oBAAoB,YAAY,CAAC;AAsC9C,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAuC7E"}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_BIOME_DB_KEY = void 0;
4
+ exports.deriveBiomeSchemaName = deriveBiomeSchemaName;
5
+ const node_crypto_1 = require("node:crypto");
6
+ exports.DEFAULT_BIOME_DB_KEY = 'primary';
7
+ const SCHEMA_PREFIX = 'biome';
8
+ const MAX_IDENTIFIER_LENGTH = 63;
9
+ const HASH_LENGTH = 12;
10
+ function sanitizeSegment(segment) {
11
+ return segment
12
+ .toLowerCase()
13
+ .replace(/[^a-z0-9_]/g, '_')
14
+ .replace(/_+/g, '_')
15
+ .replace(/^_+|_+$/g, '');
16
+ }
17
+ function deriveBiomeSchemaName(biomeId, dbKey) {
18
+ const sanitizedBiomeId = sanitizeSegment(biomeId);
19
+ if (sanitizedBiomeId.length === 0) {
20
+ throw new Error(`deriveBiomeSchemaName: biomeId "${biomeId}" sanitises to an empty identifier`);
21
+ }
22
+ const isDefaultKey = dbKey === undefined || dbKey === '' || dbKey === exports.DEFAULT_BIOME_DB_KEY;
23
+ const sanitizedDbKey = isDefaultKey ? '' : sanitizeSegment(dbKey);
24
+ if (!isDefaultKey && sanitizedDbKey.length === 0) {
25
+ throw new Error(`deriveBiomeSchemaName: dbKey "${dbKey}" sanitises to an empty identifier`);
26
+ }
27
+ const candidate = isDefaultKey
28
+ ? `${SCHEMA_PREFIX}_${sanitizedBiomeId}`
29
+ : `${SCHEMA_PREFIX}_${sanitizedBiomeId}__${sanitizedDbKey}`;
30
+ if (candidate.length <= MAX_IDENTIFIER_LENGTH) {
31
+ return candidate;
32
+ }
33
+ const hashParts = isDefaultKey ? [biomeId] : [biomeId, dbKey];
34
+ const hash = (0, node_crypto_1.createHash)('sha256')
35
+ .update(hashParts.join(':'))
36
+ .digest('hex')
37
+ .slice(0, HASH_LENGTH);
38
+ const maxPrefixLength = MAX_IDENTIFIER_LENGTH - hash.length - 1;
39
+ const trimmedPrefix = candidate
40
+ .slice(0, maxPrefixLength)
41
+ .replace(/_+$/g, '');
42
+ return `${trimmedPrefix}_${hash}`;
43
+ }
44
+ //# sourceMappingURL=schema-name.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema-name.js","sourceRoot":"","sources":["../../src/lib/schema-name.ts"],"names":[],"mappings":";;;AA4CA,sDAuCC;AAnFD,6CAAyC;AAM5B,QAAA,oBAAoB,GAAG,SAAS,CAAC;AAE9C,MAAM,aAAa,GAAG,OAAO,CAAC;AAC9B,MAAM,qBAAqB,GAAG,EAAE,CAAC;AACjC,MAAM,WAAW,GAAG,EAAE,CAAC;AAOvB,SAAS,eAAe,CAAC,OAAe;IACtC,OAAO,OAAO;SACX,WAAW,EAAE;SACb,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC;SAC3B,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;SACnB,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;AAC7B,CAAC;AAqBD,SAAgB,qBAAqB,CAAC,OAAe,EAAE,KAAc;IACnE,MAAM,gBAAgB,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;IAClD,IAAI,gBAAgB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CACb,mCAAmC,OAAO,oCAAoC,CAC/E,CAAC;IACJ,CAAC;IAED,MAAM,YAAY,GAChB,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE,IAAI,KAAK,KAAK,4BAAoB,CAAC;IACxE,MAAM,cAAc,GAAG,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IAElE,IAAI,CAAC,YAAY,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACjD,MAAM,IAAI,KAAK,CACb,iCAAiC,KAAK,oCAAoC,CAC3E,CAAC;IACJ,CAAC;IAED,MAAM,SAAS,GAAG,YAAY;QAC5B,CAAC,CAAC,GAAG,aAAa,IAAI,gBAAgB,EAAE;QACxC,CAAC,CAAC,GAAG,aAAa,IAAI,gBAAgB,KAAK,cAAc,EAAE,CAAC;IAE9D,IAAI,SAAS,CAAC,MAAM,IAAI,qBAAqB,EAAE,CAAC;QAC9C,OAAO,SAAS,CAAC;IACnB,CAAC;IAKD,MAAM,SAAS,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,KAAe,CAAC,CAAC;IACxE,MAAM,IAAI,GAAG,IAAA,wBAAU,EAAC,QAAQ,CAAC;SAC9B,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;SAC3B,MAAM,CAAC,KAAK,CAAC;SACb,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;IACzB,MAAM,eAAe,GAAG,qBAAqB,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IAChE,MAAM,aAAa,GAAG,SAAS;SAC5B,KAAK,CAAC,CAAC,EAAE,eAAe,CAAC;SACzB,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACvB,OAAO,GAAG,aAAa,IAAI,IAAI,EAAE,CAAC;AACpC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@xemahq/biome-database-nest",
3
+ "version": "0.1.0",
4
+ "description": "Layer 1 SDK that centralizes ALL database concerns for Xema biome services. Provides the single correct construction of a schema-qualified Prisma driver-adapter (the second-arg `{ schema }` that makes `@prisma/adapter-pg` qualify `biome_<id>.<table>` instead of `public.<table>`), the per-biome schema-naming convention, env/control-plane config resolution, and a boot-time bootstrap that creates the schema and runs migrations. Biomes carry zero DB boilerplate.",
5
+ "publishConfig": {
6
+ "registry": "https://registry.npmjs.org/",
7
+ "access": "public"
8
+ },
9
+ "main": "dist/index.js",
10
+ "types": "dist/index.d.ts",
11
+ "files": [
12
+ "dist"
13
+ ],
14
+ "devDependencies": {
15
+ "@types/jest": "^30.0.0",
16
+ "@types/node": "25.2.3",
17
+ "@types/pg": "^8.16.0",
18
+ "jest": "^30.3.0",
19
+ "prettier": "3.6.2",
20
+ "ts-jest": "^29.4.9",
21
+ "typescript": "5.9.3"
22
+ },
23
+ "peerDependencies": {
24
+ "@prisma/adapter-pg": "^7",
25
+ "@prisma/client": "^7"
26
+ },
27
+ "dependencies": {
28
+ "@xemahq/kernel-contracts": "^0.11.0",
29
+ "@xemahq/migration-runner-prisma": "^0.1.1",
30
+ "@xemahq/platform-common": "^0.2.0",
31
+ "@xemahq/service-registry-nest": "0.1.4",
32
+ "pg": "8.16.3"
33
+ },
34
+ "exports": {
35
+ ".": {
36
+ "types": "./dist/index.d.ts",
37
+ "xema-source": "./src/index.ts",
38
+ "default": "./dist/index.js"
39
+ },
40
+ "./dist/lib/*": {
41
+ "types": "./dist/lib/*.d.ts",
42
+ "default": "./dist/lib/*.js"
43
+ }
44
+ },
45
+ "scripts": {
46
+ "clean": "rm -rf dist",
47
+ "build": "tsc -p tsconfig.build.json",
48
+ "format": "prettier --write \"src/**/*.ts\"",
49
+ "test": "jest",
50
+ "typecheck": "tsc -p tsconfig.json --noEmit"
51
+ }
52
+ }