@prisma-next/family-mongo 0.0.1 → 0.3.0-dev.163

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 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
- Provides the Mongo family descriptor (`ControlFamilyDescriptor`) that includes:
8
- - The Mongo target family hook (`mongoEmission`)
9
- - Factory method (`create()`) to create family instances
10
- - The Mongo target descriptor with codec type imports
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
- - **Family Descriptor Export**: Exports the Mongo `ControlFamilyDescriptor` for use in CLI configuration files and the Mongo demo
15
- - **Family Instance Creation**: Creates `MongoControlFamilyInstance` objects that implement control-plane domain actions (`validateContract`, `emitContract`)
16
- - **Family Hook Integration**: Integrates the Mongo target family hook (`mongoEmission`) from `@prisma-next/mongo-emitter`
17
- - **Target Descriptor Export**: Exports a pre-built `mongoTargetDescriptor` with codec type imports pointing to `@prisma-next/mongo-core/codec-types`
18
- - **Contract Validation**: Validates Mongo contract JSON via `validateMongoContract()` from `@prisma-next/mongo-core`
19
- - **Contract Emission**: Emits `contract.json` and `contract.d.ts` for the Mongo family using the shared `emit()` pipeline
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
- ## Package Structure
45
+ ### TypeScript authoring
39
46
 
40
- - **`src/core/control-descriptor.ts`**: `MongoFamilyDescriptor` class implementing `ControlFamilyDescriptor` (pure data + factory)
41
- - **`src/core/control-instance.ts`**: `createMongoFamilyInstance()` factory and `MongoControlFamilyInstance` interface with domain action methods (`validateContract`, `emitContract`)
42
- - **`src/core/mongo-target-descriptor.ts`**: Pre-built `mongoTargetDescriptor` with codec type import metadata
43
- - **`src/exports/control.ts`**: Control plane entry point
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
- ## Entrypoints
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
- - **`./control`**: Control plane entry point — exports `mongoFamilyDescriptor`, `mongoTargetDescriptor`, `createMongoFamilyInstance`, and `MongoControlFamilyInstance`
80
+ const Comment = model('Comment', {
81
+ owner: Task,
82
+ fields: {
83
+ _id: field.objectId(),
84
+ text: field.string(),
85
+ },
86
+ });
48
87
 
49
- ## Dependencies
88
+ export const contract = defineContract({
89
+ family: mongoFamily,
90
+ target: mongoTarget,
91
+ valueObjects: { Address },
92
+ models: { Task, Comment },
93
+ });
94
+ ```
50
95
 
51
- - **`@prisma-next/framework-components`**: `ControlStack`, `ControlFamilyDescriptor`, component types
52
- - **`@prisma-next/emitter`**: `emit()` function for contract emission
53
- - **`@prisma-next/contract`**: `Contract`, `ContractMarkerRecord`
54
- - **`@prisma-next/mongo-core`**: `MongoContract`, `validateMongoContract()`
55
- - **`@prisma-next/mongo-emitter`**: `mongoEmission`
56
- - **`@prisma-next/target-mongo`**: Target descriptor metadata
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
- **Dependents:**
59
- - `examples/mongo-demo/` imports this package to wire the Mongo control plane
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"}