@neupgroup/mapper 1.2.0 → 1.2.1

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/dist/docs.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export declare const documentationMd = "\n# Mapper Library Documentation\n\nWelcome to `@neupgroup/mapper`. This guide covers:\n- Installation\n- Configuring connections (DSL and UI)\n- Using connections in code\n- Creating schemas (ORM)\n- Configuring and using schemas\n- CRUD operations: insert, update, delete, fetch\n- Error handling and troubleshooting\n\n---\n\n## Installation\n\n- Install from npm:\n `npm install @neupgroup/mapper`\n- In this workspace, the app depends on the library via `workspace:*`. Build the library when you update it:\n `cd library && npm run build`\n- Import helpers:\n `import { parseConnectionsDsl, toNormalizedConnections } from '@neupgroup/mapper'`\n\n---\n\n## Configure Connections\n\nYou can configure connections in two ways:\n\n1) DSL File (recommended)\n2) UI Configure page (runtime setup)\n\n### 1) DSL Format\n\nCreate `connections.dsl` at your project root:\n\n```\nconnections = [\n mysql_prod: {\n type: mysql\n host: 127.0.0.1\n port: 3306\n user: root\n password: \"s3cr3t\"\n database: appdb\n }\n\n mongo_dev: {\n type: mongodb\n uri: \"mongodb://127.0.0.1:27017\"\n database: devdb\n }\n\n firestore_local: {\n type: firestore\n projectId: my-project\n applicationDefault: true\n }\n\n http_api: {\n type: api\n baseUrl: \"https://api.example.com\"\n token: \"abc123\"\n }\n]\n```\n\nNotes:\n- `type` (or `dbType`) defaults to `api` if omitted.\n- Values can be unquoted or quoted; comments using `#` are ignored.\n\nParse and normalize:\n\n```ts\nimport { parseConnectionsDsl, toNormalizedConnections } from '@neupgroup/mapper'\n\nconst text = await fs.promises.readFile('connections.dsl', 'utf8')\nconst envMap = parseConnectionsDsl(text)\nconst connections = toNormalizedConnections(envMap)\n// connections: Array<{ name, type, key }>\n```\n\n### 2) UI Configure Page\n\n- Go to `/configure` to define connections at runtime.\n- Use \"Generate collective env\" to produce `connections.dsl` from configured connections.\n- Download the file and commit it or load at startup.\n\n---\n\n## Use Connections in Code\n\n### Normalize and route by type\n\n```ts\nimport { parseConnectionsDsl, toNormalizedConnections } from '@neupgroup/mapper'\nimport { connection, schema } from '@neupgroup/mapper'\n\nconst text = await fs.promises.readFile('connections.dsl', 'utf8')\nconst envMap = parseConnectionsDsl(text)\nconst conns = toNormalizedConnections(envMap)\n\n// Register connections\nconst conRegistry = connection()\nfor (const c of conns) {\n conRegistry.register({ name: c.name, type: c.type, key: c.key })\n}\n\n// Use with schemas\nconst sm = schema(conRegistry)\n```\n\n### Direct construction\n\n```ts\nconst conRegistry = connection()\nconRegistry.create('mysql_prod', 'mysql').key({\n host: '127.0.0.1',\n port: 3306,\n user: 'root',\n password: 's3cr3t',\n database: 'appdb',\n})\n```\n\n---\n\n## Schemas and Models\n\nSchemas define structure for collections/tables bound to a connection.\n\n### Define and register a schema\n\n```ts\nimport { schema } from '@neupgroup/mapper'\n\nconst sm = schema(conRegistry)\n\nsm.create('User')\n .use({ connection: 'mysql_prod', collection: 'users' })\n .setStructure({\n id: 'string primary',\n email: 'string unique',\n name: 'string editable',\n createdAt: 'date',\n '?field': 'allow-undefined', // optional: permit fields not listed\n })\n\nconst User = sm.use('User')\n```\n\n---\n\n## CRUD Operations\n\nAll operations return Promises and may throw on errors.\n\n### Insert\n\n```ts\nconst createdId = await User.add({\n id: 'u_123',\n email: 'alice@example.com',\n name: 'Alice',\n createdAt: new Date(),\n})\n```\n\n### Update\n\n```ts\nawait User.where(['id', 'u_123']).to({ name: 'Alice Cooper' }).updateOne()\n```\n\n### Delete\n\n```ts\nawait User.where(['id', 'u_123']).deleteOne()\n```\n\n### Fetch / Query\n\n```ts\nconst one = await User.where(['id', 'u_123']).getOne()\nconst many = await User.where('email', '%@example.com', 'like').get()\n```\n\n---\n\n## Schema Configuration Details\n\n- `primary`: marks primary key; used for updates/deletes.\n- `unique`: enforces uniqueness in supported backends.\n- `editable`: indicates fields commonly modified via UI.\n- `type`: one of `string`, `number`, `boolean`, `date`, `int`.\n- `?field`: enables accepting fields not defined in the schema.\n\n---\n\n## Error Handling\n\nWrap operations in `try/catch` and inspect known error shapes.\n\n```ts\ntry {\n const user = await User.where(['id', 'u_404']).getOne()\n if (!user) {\n // handle not found gracefully\n }\n} catch (err) {\n if (err && typeof err === 'object' && 'code' in err) {\n console.error('Database error code:', (err as any).code)\n }\n console.error('Unexpected error', err)\n}\n```\n\nRecommendations:\n- Validate required creds before initializing connections.\n- Prefer parameterized queries or ORM filters over string concatenation.\n- Log request IDs and timestamps for audit trails.\n\n---\n\n## Troubleshooting\n\n- \"Connection refused\": check host/port/firewall and credentials.\n- \"Authentication failed\": verify tokens/passwords and token scopes.\n- \"Timeout\": review network paths and optimize query.\n- \"Schema mismatch\": ensure field names/types match the backend.\n\n---\n\n## API Quick Reference\n\n- `parseConnectionsDsl(text)` \u2192 Map of connectionName \u2192 key/value creds\n- `toNormalizedConnections(map)` \u2192 Array of { name, type, key }\n- `connection()` \u2192 Connection registry (create/register/list/get)\n- `schema(connections?)` \u2192 Schema manager; define, register, and use schemas\n\n---\n\n## End-to-End Example\n\n```ts\nimport { parseConnectionsDsl, toNormalizedConnections, connection, schema } from '@neupgroup/mapper'\n\nconst text = await fs.promises.readFile('connections.dsl', 'utf8')\nconst map = parseConnectionsDsl(text)\nconst conns = toNormalizedConnections(map)\n\nconst conRegistry = connection()\nfor (const c of conns) conRegistry.register({ name: c.name, type: c.type, key: c.key })\n\nconst sm = schema(conRegistry)\nsm.create('Product')\n .use({ connection: conns[0].name, collection: 'products' })\n .setStructure({\n id: 'string primary',\n title: 'string',\n price: 'number',\n tags: 'string',\n })\nconst Product = sm.use('Product')\n\nawait Product.add({ id: 'p_1', title: 'Widget', price: 9.99, tags: 'sale' })\nawait Product.where(['id', 'p_1']).to({ price: 7.99 }).updateOne()\nconst items = await Product.where('price', 10, '<').get()\nawait Product.where(['id', 'p_1']).deleteOne()\n```\n";
2
+ export declare function markdownToHtml(md: string): string;
3
+ export declare function getDocumentationHtml(): string;
package/dist/docs.js ADDED
@@ -0,0 +1,351 @@
1
+ // Centralized documentation for @neupgroup/mapper.
2
+ // Exports Markdown plus a minimal Markdown→HTML converter so apps can render
3
+ // without a heavy dependency. Keep content comprehensive and up-to-date.
4
+ export const documentationMd = `
5
+ # Mapper Library Documentation
6
+
7
+ Welcome to \`@neupgroup/mapper\`. This guide covers:
8
+ - Installation
9
+ - Configuring connections (DSL and UI)
10
+ - Using connections in code
11
+ - Creating schemas (ORM)
12
+ - Configuring and using schemas
13
+ - CRUD operations: insert, update, delete, fetch
14
+ - Error handling and troubleshooting
15
+
16
+ ---
17
+
18
+ ## Installation
19
+
20
+ - Install from npm:
21
+ \`npm install @neupgroup/mapper\`
22
+ - In this workspace, the app depends on the library via \`workspace:*\`. Build the library when you update it:
23
+ \`cd library && npm run build\`
24
+ - Import helpers:
25
+ \`import { parseConnectionsDsl, toNormalizedConnections } from '@neupgroup/mapper'\`
26
+
27
+ ---
28
+
29
+ ## Configure Connections
30
+
31
+ You can configure connections in two ways:
32
+
33
+ 1) DSL File (recommended)
34
+ 2) UI Configure page (runtime setup)
35
+
36
+ ### 1) DSL Format
37
+
38
+ Create \`connections.dsl\` at your project root:
39
+
40
+ \`\`\`
41
+ connections = [
42
+ mysql_prod: {
43
+ type: mysql
44
+ host: 127.0.0.1
45
+ port: 3306
46
+ user: root
47
+ password: "s3cr3t"
48
+ database: appdb
49
+ }
50
+
51
+ mongo_dev: {
52
+ type: mongodb
53
+ uri: "mongodb://127.0.0.1:27017"
54
+ database: devdb
55
+ }
56
+
57
+ firestore_local: {
58
+ type: firestore
59
+ projectId: my-project
60
+ applicationDefault: true
61
+ }
62
+
63
+ http_api: {
64
+ type: api
65
+ baseUrl: "https://api.example.com"
66
+ token: "abc123"
67
+ }
68
+ ]
69
+ \`\`\`
70
+
71
+ Notes:
72
+ - \`type\` (or \`dbType\`) defaults to \`api\` if omitted.
73
+ - Values can be unquoted or quoted; comments using \`#\` are ignored.
74
+
75
+ Parse and normalize:
76
+
77
+ \`\`\`ts
78
+ import { parseConnectionsDsl, toNormalizedConnections } from '@neupgroup/mapper'
79
+
80
+ const text = await fs.promises.readFile('connections.dsl', 'utf8')
81
+ const envMap = parseConnectionsDsl(text)
82
+ const connections = toNormalizedConnections(envMap)
83
+ // connections: Array<{ name, type, key }>
84
+ \`\`\`
85
+
86
+ ### 2) UI Configure Page
87
+
88
+ - Go to \`/configure\` to define connections at runtime.
89
+ - Use \"Generate collective env\" to produce \`connections.dsl\` from configured connections.
90
+ - Download the file and commit it or load at startup.
91
+
92
+ ---
93
+
94
+ ## Use Connections in Code
95
+
96
+ ### Normalize and route by type
97
+
98
+ \`\`\`ts
99
+ import { parseConnectionsDsl, toNormalizedConnections } from '@neupgroup/mapper'
100
+ import { connection, schema } from '@neupgroup/mapper'
101
+
102
+ const text = await fs.promises.readFile('connections.dsl', 'utf8')
103
+ const envMap = parseConnectionsDsl(text)
104
+ const conns = toNormalizedConnections(envMap)
105
+
106
+ // Register connections
107
+ const conRegistry = connection()
108
+ for (const c of conns) {
109
+ conRegistry.register({ name: c.name, type: c.type, key: c.key })
110
+ }
111
+
112
+ // Use with schemas
113
+ const sm = schema(conRegistry)
114
+ \`\`\`
115
+
116
+ ### Direct construction
117
+
118
+ \`\`\`ts
119
+ const conRegistry = connection()
120
+ conRegistry.create('mysql_prod', 'mysql').key({
121
+ host: '127.0.0.1',
122
+ port: 3306,
123
+ user: 'root',
124
+ password: 's3cr3t',
125
+ database: 'appdb',
126
+ })
127
+ \`\`\`
128
+
129
+ ---
130
+
131
+ ## Schemas and Models
132
+
133
+ Schemas define structure for collections/tables bound to a connection.
134
+
135
+ ### Define and register a schema
136
+
137
+ \`\`\`ts
138
+ import { schema } from '@neupgroup/mapper'
139
+
140
+ const sm = schema(conRegistry)
141
+
142
+ sm.create('User')
143
+ .use({ connection: 'mysql_prod', collection: 'users' })
144
+ .setStructure({
145
+ id: 'string primary',
146
+ email: 'string unique',
147
+ name: 'string editable',
148
+ createdAt: 'date',
149
+ '?field': 'allow-undefined', // optional: permit fields not listed
150
+ })
151
+
152
+ const User = sm.use('User')
153
+ \`\`\`
154
+
155
+ ---
156
+
157
+ ## CRUD Operations
158
+
159
+ All operations return Promises and may throw on errors.
160
+
161
+ ### Insert
162
+
163
+ \`\`\`ts
164
+ const createdId = await User.add({
165
+ id: 'u_123',
166
+ email: 'alice@example.com',
167
+ name: 'Alice',
168
+ createdAt: new Date(),
169
+ })
170
+ \`\`\`
171
+
172
+ ### Update
173
+
174
+ \`\`\`ts
175
+ await User.where(['id', 'u_123']).to({ name: 'Alice Cooper' }).updateOne()
176
+ \`\`\`
177
+
178
+ ### Delete
179
+
180
+ \`\`\`ts
181
+ await User.where(['id', 'u_123']).deleteOne()
182
+ \`\`\`
183
+
184
+ ### Fetch / Query
185
+
186
+ \`\`\`ts
187
+ const one = await User.where(['id', 'u_123']).getOne()
188
+ const many = await User.where('email', '%@example.com', 'like').get()
189
+ \`\`\`
190
+
191
+ ---
192
+
193
+ ## Schema Configuration Details
194
+
195
+ - \`primary\`: marks primary key; used for updates/deletes.
196
+ - \`unique\`: enforces uniqueness in supported backends.
197
+ - \`editable\`: indicates fields commonly modified via UI.
198
+ - \`type\`: one of \`string\`, \`number\`, \`boolean\`, \`date\`, \`int\`.
199
+ - \`?field\`: enables accepting fields not defined in the schema.
200
+
201
+ ---
202
+
203
+ ## Error Handling
204
+
205
+ Wrap operations in \`try/catch\` and inspect known error shapes.
206
+
207
+ \`\`\`ts
208
+ try {
209
+ const user = await User.where(['id', 'u_404']).getOne()
210
+ if (!user) {
211
+ // handle not found gracefully
212
+ }
213
+ } catch (err) {
214
+ if (err && typeof err === 'object' && 'code' in err) {
215
+ console.error('Database error code:', (err as any).code)
216
+ }
217
+ console.error('Unexpected error', err)
218
+ }
219
+ \`\`\`
220
+
221
+ Recommendations:
222
+ - Validate required creds before initializing connections.
223
+ - Prefer parameterized queries or ORM filters over string concatenation.
224
+ - Log request IDs and timestamps for audit trails.
225
+
226
+ ---
227
+
228
+ ## Troubleshooting
229
+
230
+ - \"Connection refused\": check host/port/firewall and credentials.
231
+ - \"Authentication failed\": verify tokens/passwords and token scopes.
232
+ - \"Timeout\": review network paths and optimize query.
233
+ - \"Schema mismatch\": ensure field names/types match the backend.
234
+
235
+ ---
236
+
237
+ ## API Quick Reference
238
+
239
+ - \`parseConnectionsDsl(text)\` → Map of connectionName → key/value creds
240
+ - \`toNormalizedConnections(map)\` → Array of { name, type, key }
241
+ - \`connection()\` → Connection registry (create/register/list/get)
242
+ - \`schema(connections?)\` → Schema manager; define, register, and use schemas
243
+
244
+ ---
245
+
246
+ ## End-to-End Example
247
+
248
+ \`\`\`ts
249
+ import { parseConnectionsDsl, toNormalizedConnections, connection, schema } from '@neupgroup/mapper'
250
+
251
+ const text = await fs.promises.readFile('connections.dsl', 'utf8')
252
+ const map = parseConnectionsDsl(text)
253
+ const conns = toNormalizedConnections(map)
254
+
255
+ const conRegistry = connection()
256
+ for (const c of conns) conRegistry.register({ name: c.name, type: c.type, key: c.key })
257
+
258
+ const sm = schema(conRegistry)
259
+ sm.create('Product')
260
+ .use({ connection: conns[0].name, collection: 'products' })
261
+ .setStructure({
262
+ id: 'string primary',
263
+ title: 'string',
264
+ price: 'number',
265
+ tags: 'string',
266
+ })
267
+ const Product = sm.use('Product')
268
+
269
+ await Product.add({ id: 'p_1', title: 'Widget', price: 9.99, tags: 'sale' })
270
+ await Product.where(['id', 'p_1']).to({ price: 7.99 }).updateOne()
271
+ const items = await Product.where('price', 10, '<').get()
272
+ await Product.where(['id', 'p_1']).deleteOne()
273
+ \`\`\`
274
+ `;
275
+ // Minimal Markdown → HTML converter (headings, lists, code fences, inline code, paragraphs)
276
+ export function markdownToHtml(md) {
277
+ const lines = md.split(/\r?\n/);
278
+ let html = [];
279
+ let inCode = false;
280
+ let codeBuf = [];
281
+ function escapeHtml(s) {
282
+ return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
283
+ }
284
+ function inline(s) {
285
+ s = s.replace(/`([^`]+)`/g, (_m, g1) => `<code>${escapeHtml(g1)}</code>`);
286
+ s = s.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>');
287
+ s = s.replace(/\*([^*]+)\*/g, '<em>$1</em>');
288
+ s = s.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2">$1</a>');
289
+ return s;
290
+ }
291
+ function flushParagraph(buf) {
292
+ const text = buf.join(' ').trim();
293
+ if (!text)
294
+ return;
295
+ html.push(`<p>${inline(escapeHtml(text))}</p>`);
296
+ buf.length = 0;
297
+ }
298
+ let paraBuf = [];
299
+ for (let i = 0; i < lines.length; i++) {
300
+ const line = lines[i];
301
+ if (line.trim().startsWith('```')) {
302
+ if (inCode) {
303
+ html.push(`<pre><code>${escapeHtml(codeBuf.join('\n'))}</code></pre>`);
304
+ codeBuf = [];
305
+ inCode = false;
306
+ }
307
+ else {
308
+ flushParagraph(paraBuf);
309
+ inCode = true;
310
+ }
311
+ continue;
312
+ }
313
+ if (inCode) {
314
+ codeBuf.push(line);
315
+ continue;
316
+ }
317
+ const hMatch = /^(#{1,6})\s+(.*)$/.exec(line);
318
+ if (hMatch) {
319
+ flushParagraph(paraBuf);
320
+ const level = hMatch[1].length;
321
+ const content = hMatch[2];
322
+ html.push(`<h${level}>${inline(escapeHtml(content))}</h${level}>`);
323
+ continue;
324
+ }
325
+ if (/^\s*[-*]\s+/.test(line)) {
326
+ flushParagraph(paraBuf);
327
+ let ulItems = [];
328
+ ulItems.push(line.replace(/^\s*[-*]\s+/, ''));
329
+ while (i + 1 < lines.length && /^\s*[-*]\s+/.test(lines[i + 1])) {
330
+ i++;
331
+ ulItems.push(lines[i].replace(/^\s*[-*]\s+/, ''));
332
+ }
333
+ const lis = ulItems.map(item => `<li>${inline(escapeHtml(item))}</li>`).join('');
334
+ html.push(`<ul>${lis}</ul>`);
335
+ continue;
336
+ }
337
+ if (/^\s*$/.test(line)) {
338
+ flushParagraph(paraBuf);
339
+ continue;
340
+ }
341
+ paraBuf.push(line);
342
+ }
343
+ if (inCode) {
344
+ html.push(`<pre><code>${codeBuf.map(s => s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')).join('\n')}</code></pre>`);
345
+ }
346
+ flushParagraph(paraBuf);
347
+ return html.join('\n');
348
+ }
349
+ export function getDocumentationHtml() {
350
+ return markdownToHtml(documentationMd);
351
+ }
package/dist/env.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ export type EnvDslConnections = Record<string, Record<string, string>>;
2
+ /**
3
+ * Parse a simple DSL of the form:
4
+ * connections = [
5
+ * connectionName = [
6
+ * key: value,
7
+ * key2: "value2",
8
+ * ],
9
+ * other = [
10
+ * type: SQL,
11
+ * host: localhost,
12
+ * ]
13
+ * ]
14
+ */
15
+ export declare function parseConnectionsDsl(text: string): EnvDslConnections;
16
+ export type NormalizedConnection = {
17
+ name: string;
18
+ type: 'mysql' | 'sql' | 'firestore' | 'mongodb' | 'api';
19
+ key: Record<string, any>;
20
+ };
21
+ /**
22
+ * Convert DSL map to normalized connections compatible with library Connections.
23
+ * If no explicit type is provided, defaults to 'api'.
24
+ */
25
+ export declare function toNormalizedConnections(map: EnvDslConnections): NormalizedConnection[];
package/dist/env.js ADDED
@@ -0,0 +1,88 @@
1
+ function stripComments(input) {
2
+ return input
3
+ .split(/\r?\n/)
4
+ .map(line => line.replace(/#.*$/, ''))
5
+ .join('\n');
6
+ }
7
+ function unquote(val) {
8
+ const trimmed = val.trim();
9
+ if ((trimmed.startsWith('"') && trimmed.endsWith('"')) || (trimmed.startsWith("'") && trimmed.endsWith("'"))) {
10
+ return trimmed.slice(1, -1);
11
+ }
12
+ return trimmed;
13
+ }
14
+ /**
15
+ * Parse a simple DSL of the form:
16
+ * connections = [
17
+ * connectionName = [
18
+ * key: value,
19
+ * key2: "value2",
20
+ * ],
21
+ * other = [
22
+ * type: SQL,
23
+ * host: localhost,
24
+ * ]
25
+ * ]
26
+ */
27
+ export function parseConnectionsDsl(text) {
28
+ const cleaned = stripComments(text);
29
+ const result = {};
30
+ // Find the connections block
31
+ const match = cleaned.match(/connections\s*=\s*\[/i);
32
+ if (!match)
33
+ return result;
34
+ // Extract everything after 'connections = [' and before the final ']'
35
+ const start = match.index + match[0].length;
36
+ const after = cleaned.slice(start);
37
+ // naive bracket balance to find end of top-level list
38
+ let depth = 1;
39
+ let endIndex = -1;
40
+ for (let i = 0; i < after.length; i++) {
41
+ const ch = after[i];
42
+ if (ch === '[')
43
+ depth++;
44
+ else if (ch === ']') {
45
+ depth--;
46
+ if (depth === 0) {
47
+ endIndex = i;
48
+ break;
49
+ }
50
+ }
51
+ }
52
+ const inner = endIndex >= 0 ? after.slice(0, endIndex) : after;
53
+ // Split by connection assignments at top level: name = [ ... ]
54
+ const connBlocks = inner.split(/\],?/).map(s => s.trim()).filter(Boolean);
55
+ for (const block of connBlocks) {
56
+ const assign = block.match(/^(\w[\w-]*)\s*=\s*\[/);
57
+ if (!assign)
58
+ continue;
59
+ const name = assign[1];
60
+ const content = block.slice(assign[0].length); // inside the [ ...
61
+ const lines = content.split(/\r?\n|,/).map(l => l.trim()).filter(l => l.length);
62
+ const map = {};
63
+ for (const line of lines) {
64
+ const kv = line.match(/^(\w[\w-]*)\s*:\s*(.+)$/);
65
+ if (!kv)
66
+ continue;
67
+ const key = kv[1];
68
+ const value = unquote(kv[2].replace(/,\s*$/, ''));
69
+ map[key] = value;
70
+ }
71
+ result[name] = map;
72
+ }
73
+ return result;
74
+ }
75
+ /**
76
+ * Convert DSL map to normalized connections compatible with library Connections.
77
+ * If no explicit type is provided, defaults to 'api'.
78
+ */
79
+ export function toNormalizedConnections(map) {
80
+ const conns = [];
81
+ for (const [name, kv] of Object.entries(map)) {
82
+ const rawType = (kv['type'] || kv['dbType'] || '').toLowerCase();
83
+ const type = ['mysql', 'sql', 'firestore', 'mongodb', 'api'].includes(rawType) ? rawType : 'api';
84
+ const { type: _omitType, dbType: _omitDbType, ...rest } = kv;
85
+ conns.push({ name, type, key: rest });
86
+ }
87
+ return conns;
88
+ }
package/dist/index.d.ts CHANGED
@@ -86,3 +86,6 @@ export declare function schema(conns?: Connections): SchemaManager;
86
86
  export declare const schemas: SchemaManager;
87
87
  export { createOrm } from './orm';
88
88
  export type { DbAdapter, QueryOptions };
89
+ export { parseConnectionsDsl, toNormalizedConnections } from './env';
90
+ export type { EnvDslConnections, NormalizedConnection } from './env';
91
+ export { documentationMd, markdownToHtml, getDocumentationHtml } from './docs';
package/dist/index.js CHANGED
@@ -276,3 +276,5 @@ export const schemas = (() => {
276
276
  return new SchemaManager(conns);
277
277
  })();
278
278
  export { createOrm } from './orm';
279
+ export { parseConnectionsDsl, toNormalizedConnections } from './env';
280
+ export { documentationMd, markdownToHtml, getDocumentationHtml } from './docs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neupgroup/mapper",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Neup.Mapper core library for schema and mapping utilities",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -1,27 +0,0 @@
1
- import { z } from 'genkit';
2
- export declare const AIOperationSuggestionInputSchema: z.ZodObject<{
3
- operationDescription: z.ZodString;
4
- databaseType: z.ZodString;
5
- schema: z.ZodString;
6
- }, "strip", z.ZodTypeAny, {
7
- databaseType: string;
8
- operationDescription: string;
9
- schema: string;
10
- }, {
11
- databaseType: string;
12
- operationDescription: string;
13
- schema: string;
14
- }>;
15
- export type AIOperationSuggestionInput = z.infer<typeof AIOperationSuggestionInputSchema>;
16
- export declare const AIOperationSuggestionOutputSchema: z.ZodObject<{
17
- suggestedCode: z.ZodString;
18
- rationale: z.ZodString;
19
- }, "strip", z.ZodTypeAny, {
20
- rationale: string;
21
- suggestedCode: string;
22
- }, {
23
- rationale: string;
24
- suggestedCode: string;
25
- }>;
26
- export type AIOperationSuggestionOutput = z.infer<typeof AIOperationSuggestionOutputSchema>;
27
- export declare function createSuggestOperation(ai: any): (input: AIOperationSuggestionInput) => Promise<any>;
@@ -1,46 +0,0 @@
1
- import { z } from 'genkit';
2
- export const AIOperationSuggestionInputSchema = z.object({
3
- operationDescription: z
4
- .string()
5
- .describe('A detailed description of the operation to be performed.'),
6
- databaseType: z
7
- .string()
8
- .describe('The type of database (e.g., MongoDB, Firestore, SQL).'),
9
- schema: z.string().describe('The JSON schema of the data structure.'),
10
- });
11
- export const AIOperationSuggestionOutputSchema = z.object({
12
- suggestedCode: z
13
- .string()
14
- .describe('The suggested code for the operation, as a string.'),
15
- rationale: z
16
- .string()
17
- .describe('Explanation of why the suggested code is optimal.'),
18
- });
19
- export function createSuggestOperation(ai) {
20
- const aiOperationSuggestionPrompt = ai.definePrompt({
21
- name: 'aiOperationSuggestionPrompt',
22
- input: { schema: AIOperationSuggestionInputSchema },
23
- output: { schema: AIOperationSuggestionOutputSchema },
24
- prompt: `You are an expert database engineer. Given a description of a database operation, a database type, and a data schema, you will generate the code to perform that operation. The operation can be for inserting, fetching, or updating data.
25
-
26
- Operation Description: {{{operationDescription}}}
27
- Database Type: {{{databaseType}}}
28
- Schema: {{{schema}}}
29
-
30
- Generate the code for the specified database type. Provide a rationale for the generated code.
31
-
32
- Return the suggested code as a string, and include the rationale.
33
- `,
34
- });
35
- const aiOperationSuggestionFlow = ai.defineFlow({
36
- name: 'aiOperationSuggestionFlow',
37
- inputSchema: AIOperationSuggestionInputSchema,
38
- outputSchema: AIOperationSuggestionOutputSchema,
39
- }, async (input) => {
40
- const { output } = await aiOperationSuggestionPrompt(input);
41
- return output;
42
- });
43
- return async function suggestOperation(input) {
44
- return aiOperationSuggestionFlow(input);
45
- };
46
- }
@@ -1,24 +0,0 @@
1
- import { z } from 'genkit';
2
- export declare const AISchemaSuggestionInputSchema: z.ZodObject<{
3
- dataDescription: z.ZodString;
4
- databaseType: z.ZodString;
5
- }, "strip", z.ZodTypeAny, {
6
- dataDescription: string;
7
- databaseType: string;
8
- }, {
9
- dataDescription: string;
10
- databaseType: string;
11
- }>;
12
- export type AISchemaSuggestionInput = z.infer<typeof AISchemaSuggestionInputSchema>;
13
- export declare const AISchemaSuggestionOutputSchema: z.ZodObject<{
14
- suggestedSchema: z.ZodString;
15
- rationale: z.ZodString;
16
- }, "strip", z.ZodTypeAny, {
17
- suggestedSchema: string;
18
- rationale: string;
19
- }, {
20
- suggestedSchema: string;
21
- rationale: string;
22
- }>;
23
- export type AISchemaSuggestionOutput = z.infer<typeof AISchemaSuggestionOutputSchema>;
24
- export declare function createSuggestSchema(ai: any): (input: AISchemaSuggestionInput) => Promise<any>;
@@ -1,46 +0,0 @@
1
- import { z } from 'genkit';
2
- export const AISchemaSuggestionInputSchema = z.object({
3
- dataDescription: z
4
- .string()
5
- .describe('A detailed description of the data that the schema should represent.'),
6
- databaseType: z
7
- .string()
8
- .describe('The type of database for which the schema is being created (e.g., MongoDB, Firestore, SQL).'),
9
- });
10
- export const AISchemaSuggestionOutputSchema = z.object({
11
- suggestedSchema: z
12
- .string()
13
- .describe('The suggested schema structure, formatted as a JSON string, tailored for the specified database type.'),
14
- rationale: z
15
- .string()
16
- .describe('Explanation of why the suggested schema is optimal for the given data description and database type.'),
17
- });
18
- export function createSuggestSchema(ai) {
19
- const aiSchemaSuggestionPrompt = ai.definePrompt({
20
- name: 'aiSchemaSuggestionPrompt',
21
- input: { schema: AISchemaSuggestionInputSchema },
22
- output: { schema: AISchemaSuggestionOutputSchema },
23
- prompt: `You are an expert database architect. Given a description of data and a database type, you will suggest an optimal schema structure.
24
-
25
- Data Description: {{{dataDescription}}}
26
- Database Type: {{{databaseType}}}
27
-
28
- Consider the characteristics and constraints of the specified database type when formulating the schema.
29
-
30
- Return the suggested schema as a JSON string, and include a rationale explaining why the schema is optimal.
31
-
32
- Ensure that the suggested schema is valid and can be directly used with the specified database.
33
- `,
34
- });
35
- const aiSchemaSuggestionFlow = ai.defineFlow({
36
- name: 'aiSchemaSuggestionFlow',
37
- inputSchema: AISchemaSuggestionInputSchema,
38
- outputSchema: AISchemaSuggestionOutputSchema,
39
- }, async (input) => {
40
- const { output } = await aiSchemaSuggestionPrompt(input);
41
- return output;
42
- });
43
- return async function suggestSchema(input) {
44
- return aiSchemaSuggestionFlow(input);
45
- };
46
- }