@prisma-next/family-mongo 0.0.1 → 0.3.0-dev.162
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/README.md +81 -28
- package/dist/control.d.mts +18 -0
- package/dist/control.d.mts.map +1 -0
- package/dist/control.mjs +647 -0
- package/dist/control.mjs.map +1 -0
- package/dist/pack.d.mts +13 -0
- package/dist/pack.d.mts.map +1 -0
- package/dist/pack.mjs +12 -0
- package/dist/pack.mjs.map +1 -0
- package/package.json +13 -7
- package/src/core/control-instance.ts +290 -15
- package/src/core/mongo-target-descriptor.ts +25 -2
- package/src/core/schema-diff.ts +402 -0
- package/src/core/schema-to-view.ts +128 -0
- package/src/exports/pack.ts +10 -0
package/README.md
CHANGED
|
@@ -1,28 +1,35 @@
|
|
|
1
1
|
# @prisma-next/family-mongo
|
|
2
2
|
|
|
3
|
-
Mongo family descriptor for Prisma Next.
|
|
3
|
+
Mongo family descriptor and family pack for Prisma Next.
|
|
4
4
|
|
|
5
5
|
## Purpose
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
7
|
+
This package is the Mongo family integration point for both control-plane assembly and authoring-time pack composition. It provides:
|
|
8
|
+
|
|
9
|
+
- the Mongo `ControlFamilyDescriptor` and `mongoTargetDescriptor` used by configs and CLI flows
|
|
10
|
+
- the pure-data Mongo family pack ref used by `contract.ts` authoring
|
|
11
|
+
- a cohesive dependency surface for the Mongo family, including `@prisma-next/mongo-contract-ts`
|
|
11
12
|
|
|
12
13
|
## Responsibilities
|
|
13
14
|
|
|
14
|
-
- **
|
|
15
|
-
- **Family
|
|
16
|
-
- **
|
|
17
|
-
- **
|
|
18
|
-
- **
|
|
19
|
-
|
|
15
|
+
- **Control-plane assembly**: Exposes `mongoFamilyDescriptor` and `createMongoFamilyInstance()` for validation and emission flows.
|
|
16
|
+
- **Family hook integration**: Wires `mongoEmission` from `@prisma-next/mongo-emitter` into the family descriptor.
|
|
17
|
+
- **Target bridge**: Exposes a `mongoTargetDescriptor` built from `@prisma-next/target-mongo/pack` metadata for control-plane stacks.
|
|
18
|
+
- **Authoring-time family pack**: Exposes `@prisma-next/family-mongo/pack` so `defineContract(...)` can bind a Mongo contract to the Mongo family without importing control-plane code.
|
|
19
|
+
- **Validation and emission**: Delegates Mongo contract validation to `@prisma-next/mongo-contract` and contract emission to the shared emitter pipeline.
|
|
20
|
+
|
|
21
|
+
## Entrypoints
|
|
22
|
+
|
|
23
|
+
- `./control`: control-plane entrypoint exporting `mongoFamilyDescriptor`, `mongoTargetDescriptor`, `createMongoFamilyInstance`, and `MongoControlFamilyInstance`
|
|
24
|
+
- `./pack`: pure pack ref for TypeScript authoring flows such as `@prisma-next/mongo-contract-ts/contract-builder`
|
|
20
25
|
|
|
21
26
|
## Usage
|
|
22
27
|
|
|
28
|
+
### Control plane
|
|
29
|
+
|
|
23
30
|
```typescript
|
|
24
|
-
import { mongoFamilyDescriptor, mongoTargetDescriptor } from '@prisma-next/family-mongo/control';
|
|
25
31
|
import { createControlStack } from '@prisma-next/framework-components/control';
|
|
32
|
+
import { mongoFamilyDescriptor, mongoTargetDescriptor } from '@prisma-next/family-mongo/control';
|
|
26
33
|
|
|
27
34
|
const stack = createControlStack({
|
|
28
35
|
family: mongoFamilyDescriptor,
|
|
@@ -35,25 +42,71 @@ const contract = familyInstance.validateContract(contractJson);
|
|
|
35
42
|
const result = await familyInstance.emitContract({ contract });
|
|
36
43
|
```
|
|
37
44
|
|
|
38
|
-
|
|
45
|
+
### TypeScript authoring
|
|
39
46
|
|
|
40
|
-
|
|
41
|
-
-
|
|
42
|
-
|
|
43
|
-
-
|
|
47
|
+
```typescript
|
|
48
|
+
import mongoFamily from '@prisma-next/family-mongo/pack';
|
|
49
|
+
import { defineContract, field, model, rel, valueObject } from '@prisma-next/mongo-contract-ts/contract-builder';
|
|
50
|
+
import mongoTarget from '@prisma-next/target-mongo/pack';
|
|
51
|
+
|
|
52
|
+
const Address = valueObject('Address', {
|
|
53
|
+
fields: {
|
|
54
|
+
street: field.string(),
|
|
55
|
+
zip: field.string().optional(),
|
|
56
|
+
},
|
|
57
|
+
});
|
|
44
58
|
|
|
45
|
-
|
|
59
|
+
const Task = model('Task', {
|
|
60
|
+
collection: 'tasks',
|
|
61
|
+
storageRelations: {
|
|
62
|
+
comments: { field: 'comments' },
|
|
63
|
+
},
|
|
64
|
+
fields: {
|
|
65
|
+
_id: field.objectId(),
|
|
66
|
+
type: field.string(),
|
|
67
|
+
metadata: field.valueObject(Address).optional(),
|
|
68
|
+
},
|
|
69
|
+
relations: {
|
|
70
|
+
comments: rel.hasMany('Comment'),
|
|
71
|
+
},
|
|
72
|
+
discriminator: {
|
|
73
|
+
field: 'type',
|
|
74
|
+
variants: {
|
|
75
|
+
Bug: { value: 'bug' },
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
});
|
|
46
79
|
|
|
47
|
-
|
|
80
|
+
const Comment = model('Comment', {
|
|
81
|
+
owner: Task,
|
|
82
|
+
fields: {
|
|
83
|
+
_id: field.objectId(),
|
|
84
|
+
text: field.string(),
|
|
85
|
+
},
|
|
86
|
+
});
|
|
48
87
|
|
|
49
|
-
|
|
88
|
+
export const contract = defineContract({
|
|
89
|
+
family: mongoFamily,
|
|
90
|
+
target: mongoTarget,
|
|
91
|
+
valueObjects: { Address },
|
|
92
|
+
models: { Task, Comment },
|
|
93
|
+
});
|
|
94
|
+
```
|
|
50
95
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
-
|
|
56
|
-
-
|
|
96
|
+
The current `contract.ts` slice supports roots and collections, typed reference relations, owned models with `storage.relations`, value objects, and discriminator-based polymorphism.
|
|
97
|
+
|
|
98
|
+
## Package Structure
|
|
99
|
+
|
|
100
|
+
- `src/core/control-descriptor.ts`: `MongoFamilyDescriptor` implementation
|
|
101
|
+
- `src/core/control-instance.ts`: `createMongoFamilyInstance()` and `MongoControlFamilyInstance`
|
|
102
|
+
- `src/core/mongo-target-descriptor.ts`: pre-built control target descriptor derived from `@prisma-next/target-mongo/pack`
|
|
103
|
+
- `src/exports/control.ts`: control-plane entrypoint
|
|
104
|
+
- `src/exports/pack.ts`: authoring-time family pack ref
|
|
105
|
+
|
|
106
|
+
## Dependencies
|
|
57
107
|
|
|
58
|
-
|
|
59
|
-
-
|
|
108
|
+
- `@prisma-next/framework-components`: control-plane types and stack assembly
|
|
109
|
+
- `@prisma-next/mongo-contract`: Mongo contract validation and types
|
|
110
|
+
- `@prisma-next/mongo-contract-ts`: Mongo `contract.ts` authoring surface
|
|
111
|
+
- `@prisma-next/mongo-emitter`: Mongo family emission hook
|
|
112
|
+
- `@prisma-next/target-mongo`: Mongo target pack metadata
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ControlFamilyDescriptor, ControlFamilyInstance, ControlStack, MigratableTargetDescriptor, SchemaViewCapable } from "@prisma-next/framework-components/control";
|
|
2
|
+
import { MongoSchemaIR } from "@prisma-next/mongo-schema-ir";
|
|
3
|
+
import { Contract } from "@prisma-next/contract/types";
|
|
4
|
+
|
|
5
|
+
//#region src/core/control-instance.d.ts
|
|
6
|
+
interface MongoControlFamilyInstance extends ControlFamilyInstance<'mongo', MongoSchemaIR>, SchemaViewCapable<MongoSchemaIR> {
|
|
7
|
+
validateContract(contractJson: unknown): Contract;
|
|
8
|
+
}
|
|
9
|
+
declare function createMongoFamilyInstance(_controlStack: ControlStack): MongoControlFamilyInstance;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/core/control-descriptor.d.ts
|
|
12
|
+
declare const mongoFamilyDescriptor: ControlFamilyDescriptor<'mongo', MongoControlFamilyInstance>;
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/core/mongo-target-descriptor.d.ts
|
|
15
|
+
declare const mongoTargetDescriptor: MigratableTargetDescriptor<'mongo', 'mongo', MongoControlFamilyInstance>;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { type MongoControlFamilyInstance, createMongoFamilyInstance, mongoFamilyDescriptor, mongoTargetDescriptor };
|
|
18
|
+
//# sourceMappingURL=control.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control.d.mts","names":[],"sources":["../src/core/control-instance.ts","../src/core/control-descriptor.ts","../src/core/mongo-target-descriptor.ts"],"sourcesContent":[],"mappings":";;;;;UAgCiB,0BAAA,SACP,+BAA+B,gBACrC,kBAAkB;2CACqB;AAH3C;AACyC,iBAkSzB,yBAAA,CAlSyB,aAAA,EAkSgB,YAlShB,CAAA,EAkS+B,0BAlS/B;;;cCV5B,uBAAuB,iCAAiC;;;cCZxD,uBAAuB,6CAGlC"}
|