@mostajs/orm-adapter 0.2.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.
Files changed (44) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/LICENSE +29 -0
  3. package/README.md +182 -0
  4. package/dist/adapters/native.adapter.d.ts +36 -0
  5. package/dist/adapters/native.adapter.d.ts.map +1 -0
  6. package/dist/adapters/native.adapter.js +83 -0
  7. package/dist/adapters/native.adapter.js.map +1 -0
  8. package/dist/adapters/prisma.adapter.d.ts +48 -0
  9. package/dist/adapters/prisma.adapter.d.ts.map +1 -0
  10. package/dist/adapters/prisma.adapter.js +400 -0
  11. package/dist/adapters/prisma.adapter.js.map +1 -0
  12. package/dist/core/abstract.adapter.d.ts +39 -0
  13. package/dist/core/abstract.adapter.d.ts.map +1 -0
  14. package/dist/core/abstract.adapter.js +130 -0
  15. package/dist/core/abstract.adapter.js.map +1 -0
  16. package/dist/core/errors.d.ts +21 -0
  17. package/dist/core/errors.d.ts.map +1 -0
  18. package/dist/core/errors.js +37 -0
  19. package/dist/core/errors.js.map +1 -0
  20. package/dist/core/registry.d.ts +25 -0
  21. package/dist/core/registry.d.ts.map +1 -0
  22. package/dist/core/registry.js +68 -0
  23. package/dist/core/registry.js.map +1 -0
  24. package/dist/core/types.d.ts +76 -0
  25. package/dist/core/types.d.ts.map +1 -0
  26. package/dist/core/types.js +21 -0
  27. package/dist/core/types.js.map +1 -0
  28. package/dist/index.d.ts +18 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +32 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/utils/prisma-ast-helpers.d.ts +43 -0
  33. package/dist/utils/prisma-ast-helpers.d.ts.map +1 -0
  34. package/dist/utils/prisma-ast-helpers.js +155 -0
  35. package/dist/utils/prisma-ast-helpers.js.map +1 -0
  36. package/dist/utils/prisma-default-mapper.d.ts +29 -0
  37. package/dist/utils/prisma-default-mapper.d.ts.map +1 -0
  38. package/dist/utils/prisma-default-mapper.js +124 -0
  39. package/dist/utils/prisma-default-mapper.js.map +1 -0
  40. package/dist/utils/prisma-type-mapper.d.ts +32 -0
  41. package/dist/utils/prisma-type-mapper.d.ts.map +1 -0
  42. package/dist/utils/prisma-type-mapper.js +95 -0
  43. package/dist/utils/prisma-type-mapper.js.map +1 -0
  44. package/package.json +90 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,60 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@mostajs/orm-adapter` will be documented in this file.
4
+
5
+ ## [0.2.0] — 2026-04-12
6
+
7
+ ### Added
8
+
9
+ - **PrismaAdapter** : converts `.prisma` files to `EntitySchema[]`
10
+ - All scalar types : String, Int, BigInt, Float, Decimal, Boolean, DateTime, Json, Bytes
11
+ - Modifiers : `?` (optional), `[]` (array)
12
+ - Field attributes : `@id`, `@unique`, `@default`, `@map`, `@updatedAt`, `@db.VarChar(n)`
13
+ - Model attributes : `@@id`, `@@unique`, `@@index`, `@@map`, `@@schema`, `@@fulltext`
14
+ - Enums (as `FieldDef.enum`)
15
+ - Relations : 1-1, 1-N, many-to-one, implicit M-N (synthesized `_ATo B` junction)
16
+ - Self-relations (named via `@relation("Name")`)
17
+ - Referential actions : Cascade, SetNull, Restrict, NoAction, SetDefault (warn → set-null)
18
+ - `@default` sentinels : AUTOINCREMENT, NOW, UUID_V4/V7, CUID/CUID2, NANOID, ULID, OBJECT_ID
19
+ - Auto-detection of `createdAt` + `updatedAt` convention → `timestamps: true`
20
+ - **Utils** : `prisma-ast-helpers`, `prisma-type-mapper`, `prisma-default-mapper`
21
+ - **DefaultSentinel** constants exported for downstream ORM interpretation
22
+ - 55 new unit tests (all passing) on 4 fixtures (blog, scalars, m2m-implicit, self-relation)
23
+
24
+ ### Changed
25
+
26
+ - `createDefaultRegistry()` now pre-registers PrismaAdapter alongside NativeAdapter
27
+
28
+ ### Warnings emitted (new)
29
+
30
+ - `LOSSY_CONVERSION` on BigInt, Decimal, Bytes
31
+ - `UNSUPPORTED_FEATURE` on `Unsupported("...")`, `@@ignore`, `onDelete: SetDefault`
32
+ - `PREVIEW_FEATURE` on `view`, composite `type`, `@@fulltext`, `@@schema`
33
+ - `UNKNOWN_EXTENSION` on unrecognized `@default(fn())`
34
+
35
+ ## [0.1.0] — 2026-04-12
36
+
37
+ ### Added
38
+
39
+ - Initial release
40
+ - **Core abstractions** : `IAdapter`, `AbstractAdapter`, `AdapterRegistry`
41
+ - **NativeAdapter** : passthrough for @mostajs/orm EntitySchema with structural validation
42
+ - Error types : `AdapterError`, `NoAdapterFoundError`, `InvalidSchemaError`, `StrictWarningError`
43
+ - Warning system with 8 standard codes (`UNSUPPORTED_FEATURE`, `LOSSY_CONVERSION`, etc.)
44
+ - Strict mode (warnings as exceptions)
45
+ - Helpers : case conversion (snake/pascal/camel), schema validation
46
+ - `createDefaultRegistry()` factory
47
+ - 31 unit tests (all passing)
48
+ - AGPL-3.0-or-later license + commercial option
49
+
50
+ ### Planned for v0.2.0
51
+
52
+ - PrismaAdapter (MVP covering scalars, 1-1, 1-N, M-N, enums, native types)
53
+
54
+ ### Planned for v0.3.0
55
+
56
+ - JsonSchemaAdapter (Draft 2020-12 + Draft-07 compat)
57
+
58
+ ### Planned for v0.4.0
59
+
60
+ - OpenApiAdapter (3.1 with 3.0 normalization)
package/LICENSE ADDED
@@ -0,0 +1,29 @@
1
+ GNU AFFERO GENERAL PUBLIC LICENSE
2
+ Version 3, 19 November 2007
3
+
4
+ Copyright (c) 2026 Dr Hamid MADANI <drmdh@msn.com>
5
+
6
+ This program is free software: you can redistribute it and/or modify
7
+ it under the terms of the GNU Affero General Public License as published by
8
+ the Free Software Foundation, either version 3 of the License, or
9
+ (at your option) any later version.
10
+
11
+ This program is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU Affero General Public License for more details.
15
+
16
+ You should have received a copy of the GNU Affero General Public License
17
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
18
+
19
+ COMMERCIAL LICENSE
20
+
21
+ For organizations that cannot comply with the AGPL open-source requirements,
22
+ a commercial license is available. Contact: drmdh@msn.com
23
+
24
+ The commercial license allows you to:
25
+ - Use the software in proprietary/closed-source projects
26
+ - Modify without publishing your source code
27
+ - Get priority support and SLA
28
+
29
+ Contact: Dr Hamid MADANI <drmdh@msn.com>
package/README.md ADDED
@@ -0,0 +1,182 @@
1
+ # @mostajs/orm-adapter
2
+
3
+ > Third-party schema adapters for [@mostajs/orm](https://github.com/apolocine/mosta-orm).
4
+ > Convert Prisma, JSON Schema, OpenAPI, and more to `EntitySchema[]`.
5
+
6
+ [![npm version](https://img.shields.io/npm/v/@mostajs/orm-adapter.svg)](https://www.npmjs.com/package/@mostajs/orm-adapter)
7
+ [![License: AGPL-3.0-or-later](https://img.shields.io/badge/License-AGPL%203.0-blue.svg)](LICENSE)
8
+
9
+ ## Why
10
+
11
+ @mostajs/orm supports **13 databases** with a unified `EntitySchema` format. This package bridges that format with the rest of the ecosystem, letting you reuse schemas you already have:
12
+
13
+ - **Prisma** `.prisma` files → EntitySchema[] (planned)
14
+ - **JSON Schema** Draft 2020-12 → EntitySchema[] (planned)
15
+ - **OpenAPI 3.1** `components/schemas` → EntitySchema[] (planned)
16
+ - **Native** EntitySchema → EntitySchema[] (passthrough, **v0.1.0**)
17
+
18
+ ## Install
19
+
20
+ ```bash
21
+ npm install @mostajs/orm-adapter @mostajs/orm
22
+ ```
23
+
24
+ ## Quick start
25
+
26
+ ### Native passthrough (validation layer)
27
+
28
+ ```ts
29
+ import { NativeAdapter } from '@mostajs/orm-adapter';
30
+ import type { EntitySchema } from '@mostajs/orm';
31
+
32
+ const UserSchema: EntitySchema = {
33
+ name: 'User',
34
+ collection: 'users',
35
+ fields: {
36
+ email: { type: 'string', required: true, unique: true },
37
+ },
38
+ relations: {},
39
+ indexes: [{ fields: { email: 'asc' }, unique: true }],
40
+ timestamps: true,
41
+ };
42
+
43
+ const adapter = new NativeAdapter();
44
+ const entities = await adapter.toEntitySchema(UserSchema);
45
+ // -> EntitySchema[]
46
+ ```
47
+
48
+ ### Auto-detection via Registry
49
+
50
+ ```ts
51
+ import { createDefaultRegistry } from '@mostajs/orm-adapter';
52
+
53
+ const registry = createDefaultRegistry();
54
+ const entities = await registry.fromAny(unknownInput);
55
+ // Auto-detects format (native / prisma / jsonschema / openapi)
56
+ ```
57
+
58
+ ### Strict mode — fail fast on invalid schema
59
+
60
+ ```ts
61
+ try {
62
+ await adapter.toEntitySchema(maybeInvalid, { strict: true });
63
+ } catch (e) {
64
+ if (e instanceof InvalidSchemaError) console.error(e.details);
65
+ }
66
+ ```
67
+
68
+ ### Collect warnings for logging
69
+
70
+ ```ts
71
+ await adapter.toEntitySchema(userSchema, {
72
+ onWarning: (w) => logger.warn(`[${w.code}] ${w.message}`, {
73
+ entity: w.entity,
74
+ field: w.field,
75
+ }),
76
+ });
77
+ ```
78
+
79
+ ## API
80
+
81
+ ### `IAdapter` interface
82
+
83
+ ```ts
84
+ interface IAdapter {
85
+ readonly name: string;
86
+ readonly vendor: string;
87
+ readonly version: string;
88
+ canParse(input: string | object): boolean;
89
+ toEntitySchema(input: string | object, opts?: AdapterOptions): Promise<EntitySchema[]>;
90
+ fromEntitySchema?(entities: EntitySchema[], opts?: AdapterOptions): Promise<string | object>;
91
+ }
92
+ ```
93
+
94
+ ### `AdapterOptions`
95
+
96
+ | Option | Type | Description |
97
+ |--------|------|-------------|
98
+ | `strict` | `boolean` | Warnings become exceptions (fail-fast) |
99
+ | `onWarning` | `(w: AdapterWarning) => void` | Callback for each warning |
100
+ | `extensions` | `Record<string, unknown>` | Custom values for x-mostajs-* |
101
+ | `relationStrategy` | `'explicit' \| 'auto' \| 'none'` | Relation detection mode |
102
+ | `unknownTypesFallback` | `'json' \| 'error' \| 'string'` | Fallback for unmappable types |
103
+
104
+ ### Warning codes
105
+
106
+ - `UNSUPPORTED_FEATURE` — source has a feature the target cannot express
107
+ - `LOSSY_CONVERSION` — precision or constraint lost during mapping
108
+ - `MISSING_METADATA` — expected metadata absent
109
+ - `AMBIGUOUS_MAPPING` — multiple valid interpretations
110
+ - `PREVIEW_FEATURE` — experimental/preview feature used
111
+ - `FALLBACK_APPLIED` — default strategy used
112
+ - `CYCLIC_REFERENCE` — self-referencing schema detected
113
+ - `UNKNOWN_EXTENSION` — unrecognized x-* extension
114
+
115
+ ## Building your own adapter
116
+
117
+ ```ts
118
+ import { AbstractAdapter, type AdapterOptions, WarningCode } from '@mostajs/orm-adapter';
119
+ import type { EntitySchema } from '@mostajs/orm';
120
+
121
+ export class MyCustomAdapter extends AbstractAdapter {
122
+ readonly name = 'my-format';
123
+ readonly vendor = 'my-org';
124
+ readonly version = '0.1.0';
125
+
126
+ canParse(input: string | object): boolean {
127
+ // Fast, non-destructive detection
128
+ return typeof input === 'string' && input.includes('@my-format');
129
+ }
130
+
131
+ async toEntitySchema(input: string | object, opts?: AdapterOptions): Promise<EntitySchema[]> {
132
+ // 1. Parse your source format
133
+ // 2. Map to EntitySchema[]
134
+ // 3. Emit warnings for lossy conversions
135
+ this.warn(opts, {
136
+ code: WarningCode.LOSSY_CONVERSION,
137
+ message: 'Some feature lost during mapping',
138
+ entity: 'Foo',
139
+ });
140
+ return [/* ... */];
141
+ }
142
+ }
143
+ ```
144
+
145
+ ## Roadmap
146
+
147
+ - **v0.1.0** — NativeAdapter + core (AbstractAdapter, Registry) ✅
148
+ - **v0.2.0** — PrismaAdapter (scalars, relations, enums, implicit M-N) ✅
149
+ - **v0.3.0** — JsonSchemaAdapter (Draft 2020-12 + Draft-07)
150
+ - **v0.4.0** — OpenApiAdapter (3.1 with 3.0 normalization)
151
+ - **v1.0.0** — Production-ready, all 4 adapters with reverse conversion
152
+
153
+ ## PrismaAdapter example
154
+
155
+ ```ts
156
+ import { PrismaAdapter, DefaultSentinel } from '@mostajs/orm-adapter';
157
+ import { readFileSync } from 'fs';
158
+
159
+ const source = readFileSync('./schema.prisma', 'utf8');
160
+ const adapter = new PrismaAdapter();
161
+ const entities = await adapter.toEntitySchema(source, {
162
+ onWarning: (w) => console.warn(`[${w.code}] ${w.message}`),
163
+ });
164
+
165
+ // entities: EntitySchema[] — feed directly to @mostajs/orm
166
+ // Supports 13 databases (Postgres, Oracle, DB2, MongoDB, etc.)
167
+ // where Prisma only supports 7.
168
+ ```
169
+
170
+ ## License
171
+
172
+ **AGPL-3.0-or-later** + commercial license available.
173
+
174
+ For commercial use in closed-source projects, contact: drmdh@msn.com
175
+
176
+ ## Author
177
+
178
+ Dr Hamid MADANI <drmdh@msn.com>
179
+
180
+ ---
181
+
182
+ Part of the [@mostajs ecosystem](https://github.com/apolocine) — 13 databases, 11 transports, one unified backend.
@@ -0,0 +1,36 @@
1
+ import type { EntitySchema } from '@mostajs/orm';
2
+ import { AbstractAdapter } from '../core/abstract.adapter.js';
3
+ import type { AdapterOptions } from '../core/types.js';
4
+ /**
5
+ * NativeAdapter — accepts EntitySchema objects directly (passthrough).
6
+ *
7
+ * Use cases:
8
+ * - baseline to validate the IAdapter contract
9
+ * - allows mixing native and third-party schemas in one Registry
10
+ * - adds structural validation before handing off to the ORM
11
+ */
12
+ export declare class NativeAdapter extends AbstractAdapter {
13
+ readonly name = "native";
14
+ readonly vendor = "@mostajs/orm";
15
+ readonly version = "0.1.0";
16
+ /**
17
+ * Detects an EntitySchema by structural shape (duck typing).
18
+ * Accepts both single schema and array of schemas.
19
+ */
20
+ canParse(input: string | object): boolean;
21
+ /**
22
+ * Passthrough : validates each schema, emits warnings if invalid,
23
+ * throws InvalidSchemaError in strict mode.
24
+ */
25
+ toEntitySchema(input: EntitySchema | EntitySchema[] | object, opts?: AdapterOptions): Promise<EntitySchema[]>;
26
+ /**
27
+ * Reverse : native format IS the EntitySchema — identity function.
28
+ */
29
+ fromEntitySchema(entities: EntitySchema[]): Promise<EntitySchema[]>;
30
+ /**
31
+ * Duck-type check : does the object look like an EntitySchema?
32
+ * Checks for required structural fields without deep validation.
33
+ */
34
+ private isEntitySchemaShape;
35
+ }
36
+ //# sourceMappingURL=native.adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native.adapter.d.ts","sourceRoot":"","sources":["../../src/adapters/native.adapter.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAIvD;;;;;;;GAOG;AACH,qBAAa,aAAc,SAAQ,eAAe;IAChD,QAAQ,CAAC,IAAI,YAAY;IACzB,QAAQ,CAAC,MAAM,kBAAkB;IACjC,QAAQ,CAAC,OAAO,WAAW;IAE3B;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO;IAQzC;;;OAGG;IACG,cAAc,CAClB,KAAK,EAAE,YAAY,GAAG,YAAY,EAAE,GAAG,MAAM,EAC7C,IAAI,CAAC,EAAE,cAAc,GACpB,OAAO,CAAC,YAAY,EAAE,CAAC;IAyB1B;;OAEG;IACG,gBAAgB,CAAC,QAAQ,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAQzE;;;OAGG;IACH,OAAO,CAAC,mBAAmB;CAc5B"}
@@ -0,0 +1,83 @@
1
+ // @mostajs/orm-adapter — NativeAdapter
2
+ // Passthrough adapter for the native @mostajs/orm EntitySchema format.
3
+ // Useful as baseline, detection fallback, and validation layer.
4
+ // Author: Dr Hamid MADANI drmdh@msn.com
5
+ // License: AGPL-3.0-or-later
6
+ import { AbstractAdapter } from '../core/abstract.adapter.js';
7
+ import { WarningCode } from '../core/types.js';
8
+ import { InvalidSchemaError } from '../core/errors.js';
9
+ /**
10
+ * NativeAdapter — accepts EntitySchema objects directly (passthrough).
11
+ *
12
+ * Use cases:
13
+ * - baseline to validate the IAdapter contract
14
+ * - allows mixing native and third-party schemas in one Registry
15
+ * - adds structural validation before handing off to the ORM
16
+ */
17
+ export class NativeAdapter extends AbstractAdapter {
18
+ name = 'native';
19
+ vendor = '@mostajs/orm';
20
+ version = '0.1.0';
21
+ /**
22
+ * Detects an EntitySchema by structural shape (duck typing).
23
+ * Accepts both single schema and array of schemas.
24
+ */
25
+ canParse(input) {
26
+ if (typeof input === 'string')
27
+ return false;
28
+ if (Array.isArray(input)) {
29
+ return input.length === 0 || this.isEntitySchemaShape(input[0]);
30
+ }
31
+ return this.isEntitySchemaShape(input);
32
+ }
33
+ /**
34
+ * Passthrough : validates each schema, emits warnings if invalid,
35
+ * throws InvalidSchemaError in strict mode.
36
+ */
37
+ async toEntitySchema(input, opts) {
38
+ const array = Array.isArray(input) ? input : [input];
39
+ for (const schema of array) {
40
+ const errors = this.validateEntitySchema(schema);
41
+ if (errors.length > 0) {
42
+ if (opts?.strict) {
43
+ throw new InvalidSchemaError(`Invalid EntitySchema: ${errors.join('; ')}`, { schema, errors });
44
+ }
45
+ for (const err of errors) {
46
+ this.warn(opts, {
47
+ code: WarningCode.MISSING_METADATA,
48
+ message: err,
49
+ entity: schema.name,
50
+ });
51
+ }
52
+ }
53
+ }
54
+ return array;
55
+ }
56
+ /**
57
+ * Reverse : native format IS the EntitySchema — identity function.
58
+ */
59
+ async fromEntitySchema(entities) {
60
+ return entities;
61
+ }
62
+ // ============================================================
63
+ // Private helpers
64
+ // ============================================================
65
+ /**
66
+ * Duck-type check : does the object look like an EntitySchema?
67
+ * Checks for required structural fields without deep validation.
68
+ */
69
+ isEntitySchemaShape(obj) {
70
+ if (!obj || typeof obj !== 'object')
71
+ return false;
72
+ const o = obj;
73
+ return (typeof o.name === 'string' &&
74
+ typeof o.collection === 'string' &&
75
+ typeof o.fields === 'object' &&
76
+ o.fields !== null &&
77
+ typeof o.relations === 'object' &&
78
+ o.relations !== null &&
79
+ Array.isArray(o.indexes) &&
80
+ typeof o.timestamps === 'boolean');
81
+ }
82
+ }
83
+ //# sourceMappingURL=native.adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native.adapter.js","sourceRoot":"","sources":["../../src/adapters/native.adapter.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,uEAAuE;AACvE,gEAAgE;AAChE,wCAAwC;AACxC,6BAA6B;AAG7B,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD;;;;;;;GAOG;AACH,MAAM,OAAO,aAAc,SAAQ,eAAe;IACvC,IAAI,GAAG,QAAQ,CAAC;IAChB,MAAM,GAAG,cAAc,CAAC;IACxB,OAAO,GAAG,OAAO,CAAC;IAE3B;;;OAGG;IACH,QAAQ,CAAC,KAAsB;QAC7B,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,OAAO,KAAK,CAAC;QAC5C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAClE,CAAC;QACD,OAAO,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,cAAc,CAClB,KAA6C,EAC7C,IAAqB;QAErB,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAqB,CAAC,CAAC;QAErE,KAAK,MAAM,MAAM,IAAI,KAAK,EAAE,CAAC;YAC3B,MAAM,MAAM,GAAG,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;YACjD,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACtB,IAAI,IAAI,EAAE,MAAM,EAAE,CAAC;oBACjB,MAAM,IAAI,kBAAkB,CAC1B,yBAAyB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAC5C,EAAE,MAAM,EAAE,MAAM,EAAE,CACnB,CAAC;gBACJ,CAAC;gBACD,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;oBACzB,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;wBACd,IAAI,EAAE,WAAW,CAAC,gBAAgB;wBAClC,OAAO,EAAE,GAAG;wBACZ,MAAM,EAAE,MAAM,CAAC,IAAI;qBACpB,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,KAAuB,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,gBAAgB,CAAC,QAAwB;QAC7C,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,+DAA+D;IAC/D,kBAAkB;IAClB,+DAA+D;IAE/D;;;OAGG;IACK,mBAAmB,CAAC,GAAY;QACtC,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ;YAAE,OAAO,KAAK,CAAC;QAClD,MAAM,CAAC,GAAG,GAA8B,CAAC;QACzC,OAAO,CACL,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ;YAC1B,OAAO,CAAC,CAAC,UAAU,KAAK,QAAQ;YAChC,OAAO,CAAC,CAAC,MAAM,KAAK,QAAQ;YAC5B,CAAC,CAAC,MAAM,KAAK,IAAI;YACjB,OAAO,CAAC,CAAC,SAAS,KAAK,QAAQ;YAC/B,CAAC,CAAC,SAAS,KAAK,IAAI;YACpB,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;YACxB,OAAO,CAAC,CAAC,UAAU,KAAK,SAAS,CAClC,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,48 @@
1
+ import type { EntitySchema } from '@mostajs/orm';
2
+ import { AbstractAdapter } from '../core/abstract.adapter.js';
3
+ import { type AdapterOptions } from '../core/types.js';
4
+ /**
5
+ * PrismaAdapter — converts .prisma files to EntitySchema[].
6
+ *
7
+ * Supports (MVP v0.2.0):
8
+ * - All scalar types (String, Int, BigInt, Float, Decimal, Boolean, DateTime, Json, Bytes)
9
+ * - Modifiers (?, [])
10
+ * - @id, @unique, @default, @map, @updatedAt
11
+ * - @@id, @@unique, @@index, @@map
12
+ * - @db.VarChar(N), @db.Decimal(p,s) (metadata extraction)
13
+ * - Enums (as FieldDef.enum)
14
+ * - Relations 1-1, 1-N, M-N (implicit & explicit)
15
+ * - Self-relations (named)
16
+ * - onDelete actions (Cascade, SetNull, Restrict, NoAction, SetDefault)
17
+ *
18
+ * Not yet supported (v0.3+):
19
+ * - Composite types (MongoDB embedded docs)
20
+ * - Views (preview)
21
+ * - Multi-schema
22
+ * - @@fulltext, specialized @@index(type: Gin)
23
+ */
24
+ export declare class PrismaAdapter extends AbstractAdapter {
25
+ readonly name = "prisma";
26
+ readonly vendor = "prisma.io";
27
+ readonly version = "0.2.0";
28
+ canParse(input: string | object): boolean;
29
+ toEntitySchema(input: string | object, opts?: AdapterOptions): Promise<EntitySchema[]>;
30
+ private modelToEntity;
31
+ private resolveTableName;
32
+ private isRelationField;
33
+ private fieldToFieldDef;
34
+ private applyFieldAttributes;
35
+ private fieldToRelation;
36
+ private mapReferentialAction;
37
+ private applyBlockAttribute;
38
+ /**
39
+ * Prisma allows implicit M-N: `categories Category[]` on both sides with NO join
40
+ * table declared. The adapter detects these and upgrades one-to-many pairs to
41
+ * many-to-many, synthesizing `through` as `_${A}To${B}` (Prisma's convention).
42
+ */
43
+ private synthesizeImplicitM2M;
44
+ private hasTimestampsConvention;
45
+ private unquote;
46
+ private detectPreviewFeatures;
47
+ }
48
+ //# sourceMappingURL=prisma.adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prisma.adapter.d.ts","sourceRoot":"","sources":["../../src/adapters/prisma.adapter.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAiE,MAAM,cAAc,CAAC;AAChH,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAe,KAAK,cAAc,EAAuB,MAAM,kBAAkB,CAAC;AAoBzF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,aAAc,SAAQ,eAAe;IAChD,QAAQ,CAAC,IAAI,YAAY;IACzB,QAAQ,CAAC,MAAM,eAAe;IAC9B,QAAQ,CAAC,OAAO,WAAW;IAE3B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO;IAMnC,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAmC5F,OAAO,CAAC,aAAa;IAyCrB,OAAO,CAAC,gBAAgB;IAaxB,OAAO,CAAC,eAAe;IAkBvB,OAAO,CAAC,eAAe;IA4DvB,OAAO,CAAC,oBAAoB;IAuC5B,OAAO,CAAC,eAAe;IAsDvB,OAAO,CAAC,oBAAoB;IA4B5B,OAAO,CAAC,mBAAmB;IA0E3B;;;;OAIG;IACH,OAAO,CAAC,qBAAqB;IA2C7B,OAAO,CAAC,uBAAuB;IAK/B,OAAO,CAAC,OAAO;IAKf,OAAO,CAAC,qBAAqB;CAgB9B"}