@prisma-next/mongo 0.10.0-dev.25 → 0.10.0-dev.27
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 +71 -8
- package/dist/config.d.mts +5 -0
- package/dist/config.d.mts.map +1 -1
- package/dist/config.mjs +5 -1
- package/dist/config.mjs.map +1 -1
- package/dist/contract-builder.d.mts +31 -2
- package/dist/contract-builder.d.mts.map +1 -0
- package/dist/contract-builder.mjs +16 -1
- package/dist/contract-builder.mjs.map +1 -0
- package/dist/control.d.mts +11 -0
- package/dist/control.d.mts.map +1 -0
- package/dist/control.mjs +21 -0
- package/dist/control.mjs.map +1 -0
- package/dist/runtime.mjs +1 -1
- package/package.json +21 -19
- package/src/config/define-config.ts +10 -1
- package/src/contract/define-contract.ts +99 -0
- package/src/exports/bson.ts +1 -0
- package/src/exports/contract-builder.ts +1 -1
- package/src/exports/control.ts +29 -0
- package/src/exports/index.ts +0 -11
- /package/dist/{index.d.mts → bson.d.mts} +0 -0
- /package/dist/{index.mjs → bson.mjs} +0 -0
package/README.md
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
# @prisma-next/mongo
|
|
2
2
|
|
|
3
|
-
One-package MongoDB setup for Prisma Next. Install this single package to get config, runtime, and
|
|
3
|
+
One-package MongoDB setup for Prisma Next. Install this single package to get config, runtime, contract authoring, control-plane access, and BSON value constructors — no reach-ins to internal packages required.
|
|
4
|
+
|
|
5
|
+
> **Breaking change:** the top-level `@prisma-next/mongo` barrel (`import { ObjectId } from '@prisma-next/mongo'`) has been removed. Move BSON constructor imports to `@prisma-next/mongo/bson`:
|
|
6
|
+
>
|
|
7
|
+
> ```diff
|
|
8
|
+
> - import { ObjectId } from '@prisma-next/mongo';
|
|
9
|
+
> + import { ObjectId } from '@prisma-next/mongo/bson';
|
|
10
|
+
> ```
|
|
4
11
|
|
|
5
12
|
## Package Classification
|
|
6
13
|
|
|
7
14
|
- **Domain**: extensions
|
|
8
15
|
- **Layer**: adapters
|
|
9
|
-
- **Planes**: shared (config), runtime (runtime)
|
|
16
|
+
- **Planes**: shared (config, contract-builder, bson, family, target), migration (control), runtime (runtime)
|
|
10
17
|
|
|
11
18
|
## Quick Start
|
|
12
19
|
|
|
@@ -20,27 +27,83 @@ export default defineConfig({
|
|
|
20
27
|
});
|
|
21
28
|
```
|
|
22
29
|
|
|
30
|
+
```typescript
|
|
31
|
+
// prisma/contract.ts
|
|
32
|
+
import { defineContract, field, model } from '@prisma-next/mongo/contract-builder';
|
|
33
|
+
|
|
34
|
+
export default defineContract({
|
|
35
|
+
models: {
|
|
36
|
+
User: model('User', { fields: { id: field.objectId() } }),
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
23
41
|
## Exports
|
|
24
42
|
|
|
25
43
|
### `@prisma-next/mongo/config`
|
|
26
44
|
|
|
27
|
-
Simplified `defineConfig` that pre-wires all MongoDB internals (family, target, adapter, driver, contract providers).
|
|
45
|
+
Simplified `defineConfig` that pre-wires all MongoDB internals (family, target, adapter, driver, contract providers). Accepts `contract`, `db`, `extensions`, and `migrations.dir`.
|
|
28
46
|
|
|
29
|
-
|
|
47
|
+
```typescript
|
|
48
|
+
import { defineConfig } from '@prisma-next/mongo/config';
|
|
30
49
|
|
|
31
|
-
|
|
50
|
+
export default defineConfig({
|
|
51
|
+
contract: './prisma/contract.prisma',
|
|
52
|
+
db: { connection: process.env['MONGODB_URL']! },
|
|
53
|
+
migrations: { dir: 'migrations/app' },
|
|
54
|
+
});
|
|
55
|
+
```
|
|
32
56
|
|
|
33
57
|
### `@prisma-next/mongo/contract-builder`
|
|
34
58
|
|
|
35
|
-
|
|
59
|
+
TypeScript contract authoring DSL (`defineContract`, `field`, `model`, `rel`, `index`, `valueObject`, …). The `defineContract` facade pre-binds `family` and `target` — callers do not pass those fields.
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import { defineContract, field, model } from '@prisma-next/mongo/contract-builder';
|
|
63
|
+
|
|
64
|
+
export default defineContract({
|
|
65
|
+
models: {
|
|
66
|
+
User: model('User', { fields: { id: field.objectId() } }),
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### `@prisma-next/mongo/control`
|
|
72
|
+
|
|
73
|
+
Control-plane client factory. Collapses the family + target + adapter + driver wiring into a single call.
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
import { createMongoControlClient } from '@prisma-next/mongo/control';
|
|
77
|
+
|
|
78
|
+
const control = createMongoControlClient({
|
|
79
|
+
connection: process.env['MONGODB_URL']!,
|
|
80
|
+
});
|
|
81
|
+
await control.dbUpdate({ migrations: { dir: 'migrations/app' } });
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### `@prisma-next/mongo/bson`
|
|
85
|
+
|
|
86
|
+
BSON value constructors for use in seed scripts, fixtures, and tests.
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
import { ObjectId } from '@prisma-next/mongo/bson';
|
|
90
|
+
|
|
91
|
+
const id = new ObjectId();
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Exports: `Binary`, `Decimal128`, `Long`, `MongoClient`, `ObjectId`, `Timestamp`.
|
|
95
|
+
|
|
96
|
+
### `@prisma-next/mongo/runtime`
|
|
97
|
+
|
|
98
|
+
Re-exports `createMongoRuntime` from `@prisma-next/mongo-runtime` for composing the MongoDB execution pipeline.
|
|
36
99
|
|
|
37
100
|
### `@prisma-next/mongo/family`
|
|
38
101
|
|
|
39
|
-
Re-exports the MongoDB family pack (
|
|
102
|
+
Re-exports the MongoDB family pack (only needed when using the low-level API; `defineContract` pre-binds this for you).
|
|
40
103
|
|
|
41
104
|
### `@prisma-next/mongo/target`
|
|
42
105
|
|
|
43
|
-
Re-exports the MongoDB target pack (
|
|
106
|
+
Re-exports the MongoDB target pack (only needed when using the low-level API; `defineContract` pre-binds this for you).
|
|
44
107
|
|
|
45
108
|
## Dependencies
|
|
46
109
|
|
package/dist/config.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PrismaNextConfig } from "@prisma-next/config/config-types";
|
|
2
|
+
import { ControlExtensionDescriptor } from "@prisma-next/framework-components/control";
|
|
2
3
|
|
|
3
4
|
//#region src/config/define-config.d.ts
|
|
4
5
|
interface MongoConfigOptions {
|
|
@@ -6,6 +7,10 @@ interface MongoConfigOptions {
|
|
|
6
7
|
readonly db?: {
|
|
7
8
|
readonly connection?: string;
|
|
8
9
|
};
|
|
10
|
+
readonly extensions?: readonly ControlExtensionDescriptor<'mongo', 'mongo'>[];
|
|
11
|
+
readonly migrations?: {
|
|
12
|
+
readonly dir?: string;
|
|
13
|
+
};
|
|
9
14
|
}
|
|
10
15
|
declare function defineConfig(options: MongoConfigOptions): PrismaNextConfig<'mongo', 'mongo'>;
|
|
11
16
|
//#endregion
|
package/dist/config.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.mts","names":[],"sources":["../src/config/define-config.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.mts","names":[],"sources":["../src/config/define-config.ts"],"mappings":";;;;UAYiB,kBAAA;EAAA,SACN,QAAA;EAAA,SACA,EAAA;IAAA,SACE,UAAA;EAAA;EAAA,SAEF,UAAA,YAAsB,0BAAA;EAAA,SACtB,UAAA;IAAA,SACE,GAAA;EAAA;AAAA;AAAA,iBAYG,YAAA,CAAa,OAAA,EAAS,kBAAA,GAAqB,gBAAA"}
|
package/dist/config.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { mongoFamilyDescriptor } from "@prisma-next/family-mongo/control";
|
|
|
5
5
|
import { mongoContract } from "@prisma-next/mongo-contract-psl/provider";
|
|
6
6
|
import { typescriptContractFromPath } from "@prisma-next/mongo-contract-ts/config-types";
|
|
7
7
|
import { mongoTargetDescriptor } from "@prisma-next/target-mongo/control";
|
|
8
|
+
import { ifDefined } from "@prisma-next/utils/defined";
|
|
8
9
|
import { extname } from "pathe";
|
|
9
10
|
//#region src/config/define-config.ts
|
|
10
11
|
function deriveOutputPath(contractPath) {
|
|
@@ -13,14 +14,17 @@ function deriveOutputPath(contractPath) {
|
|
|
13
14
|
return `${contractPath.slice(0, -ext.length)}.json`;
|
|
14
15
|
}
|
|
15
16
|
function defineConfig(options) {
|
|
17
|
+
const extensions = options.extensions ?? [];
|
|
16
18
|
const output = deriveOutputPath(options.contract);
|
|
17
19
|
return defineConfig$1({
|
|
18
20
|
family: mongoFamilyDescriptor,
|
|
19
21
|
target: mongoTargetDescriptor,
|
|
20
22
|
adapter: mongoAdapter,
|
|
21
23
|
driver: mongoDriver,
|
|
24
|
+
extensionPacks: extensions,
|
|
22
25
|
contract: extname(options.contract) === ".ts" ? typescriptContractFromPath(options.contract, output) : mongoContract(options.contract, { output }),
|
|
23
|
-
...
|
|
26
|
+
...ifDefined("db", options.db),
|
|
27
|
+
...ifDefined("migrations", options.migrations)
|
|
24
28
|
});
|
|
25
29
|
}
|
|
26
30
|
//#endregion
|
package/dist/config.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.mjs","names":["coreDefineConfig"],"sources":["../src/config/define-config.ts"],"sourcesContent":["import mongoAdapter from '@prisma-next/adapter-mongo/control';\nimport type { PrismaNextConfig } from '@prisma-next/config/config-types';\nimport { defineConfig as coreDefineConfig } from '@prisma-next/config/config-types';\nimport mongoDriver from '@prisma-next/driver-mongo/control';\nimport { mongoFamilyDescriptor } from '@prisma-next/family-mongo/control';\nimport { mongoContract } from '@prisma-next/mongo-contract-psl/provider';\nimport { typescriptContractFromPath } from '@prisma-next/mongo-contract-ts/config-types';\nimport { mongoTargetDescriptor } from '@prisma-next/target-mongo/control';\nimport { extname } from 'pathe';\n\nexport interface MongoConfigOptions {\n readonly contract: string;\n readonly db?: {\n readonly connection?: string;\n };\n}\n\nfunction deriveOutputPath(contractPath: string): string {\n const ext = extname(contractPath);\n if (ext.length === 0) {\n return `${contractPath}.json`;\n }\n return `${contractPath.slice(0, -ext.length)}.json`;\n}\n\nexport function defineConfig(options: MongoConfigOptions): PrismaNextConfig<'mongo', 'mongo'> {\n const output = deriveOutputPath(options.contract);\n const ext = extname(options.contract);\n\n const contractConfig =\n ext === '.ts'\n ? typescriptContractFromPath(options.contract, output)\n : mongoContract(options.contract, { output });\n\n return coreDefineConfig({\n family: mongoFamilyDescriptor,\n target: mongoTargetDescriptor,\n adapter: mongoAdapter,\n driver: mongoDriver,\n contract: contractConfig,\n ...(options.db
|
|
1
|
+
{"version":3,"file":"config.mjs","names":["coreDefineConfig"],"sources":["../src/config/define-config.ts"],"sourcesContent":["import mongoAdapter from '@prisma-next/adapter-mongo/control';\nimport type { PrismaNextConfig } from '@prisma-next/config/config-types';\nimport { defineConfig as coreDefineConfig } from '@prisma-next/config/config-types';\nimport mongoDriver from '@prisma-next/driver-mongo/control';\nimport { mongoFamilyDescriptor } from '@prisma-next/family-mongo/control';\nimport type { ControlExtensionDescriptor } from '@prisma-next/framework-components/control';\nimport { mongoContract } from '@prisma-next/mongo-contract-psl/provider';\nimport { typescriptContractFromPath } from '@prisma-next/mongo-contract-ts/config-types';\nimport { mongoTargetDescriptor } from '@prisma-next/target-mongo/control';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { extname } from 'pathe';\n\nexport interface MongoConfigOptions {\n readonly contract: string;\n readonly db?: {\n readonly connection?: string;\n };\n readonly extensions?: readonly ControlExtensionDescriptor<'mongo', 'mongo'>[];\n readonly migrations?: {\n readonly dir?: string;\n };\n}\n\nfunction deriveOutputPath(contractPath: string): string {\n const ext = extname(contractPath);\n if (ext.length === 0) {\n return `${contractPath}.json`;\n }\n return `${contractPath.slice(0, -ext.length)}.json`;\n}\n\nexport function defineConfig(options: MongoConfigOptions): PrismaNextConfig<'mongo', 'mongo'> {\n const extensions = options.extensions ?? [];\n const output = deriveOutputPath(options.contract);\n const ext = extname(options.contract);\n\n const contractConfig =\n ext === '.ts'\n ? typescriptContractFromPath(options.contract, output)\n : mongoContract(options.contract, { output });\n\n return coreDefineConfig({\n family: mongoFamilyDescriptor,\n target: mongoTargetDescriptor,\n adapter: mongoAdapter,\n driver: mongoDriver,\n extensionPacks: extensions,\n contract: contractConfig,\n ...ifDefined('db', options.db),\n ...ifDefined('migrations', options.migrations),\n });\n}\n"],"mappings":";;;;;;;;;;AAuBA,SAAS,iBAAiB,cAA8B;CACtD,MAAM,MAAM,QAAQ,aAAa;CACjC,IAAI,IAAI,WAAW,GACjB,OAAO,GAAG,aAAa;CAEzB,OAAO,GAAG,aAAa,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC;;AAG/C,SAAgB,aAAa,SAAiE;CAC5F,MAAM,aAAa,QAAQ,cAAc,EAAE;CAC3C,MAAM,SAAS,iBAAiB,QAAQ,SAAS;CAQjD,OAAOA,eAAiB;EACtB,QAAQ;EACR,QAAQ;EACR,SAAS;EACT,QAAQ;EACR,gBAAgB;EAChB,UAbU,QAAQ,QAAQ,SAGvB,KAAK,QACJ,2BAA2B,QAAQ,UAAU,OAAO,GACpD,cAAc,QAAQ,UAAU,EAAE,QAAQ,CAAC;EAS/C,GAAG,UAAU,MAAM,QAAQ,GAAG;EAC9B,GAAG,UAAU,cAAc,QAAQ,WAAW;EAC/C,CAAC"}
|
|
@@ -1,2 +1,31 @@
|
|
|
1
|
-
import { ContractDefinition, ContractFactory, ContractScaffold, FieldBuilder, FieldReference, ModelBuilder, MongoContractResult, RelationBuilder, ValueObjectBuilder,
|
|
2
|
-
|
|
1
|
+
import { ContractDefinition, ContractDefinition as ContractDefinition$1, ContractFactory, ContractFactory as ContractFactory$1, ContractScaffold, ContractScaffold as ContractScaffold$1, FieldBuilder, FieldReference, ModelBuilder, MongoContractResult, MongoContractResult as MongoContractResult$1, RelationBuilder, ValueObjectBuilder, field, index, model, rel, valueObject } from "@prisma-next/mongo-contract-ts/contract-builder";
|
|
2
|
+
import mongoFamilyPack from "@prisma-next/family-mongo/pack";
|
|
3
|
+
import mongoTargetPack from "@prisma-next/target-mongo/pack";
|
|
4
|
+
|
|
5
|
+
//#region src/contract/define-contract.d.ts
|
|
6
|
+
type MongoFamilyPack = typeof mongoFamilyPack;
|
|
7
|
+
type MongoTargetPack = typeof mongoTargetPack;
|
|
8
|
+
type MongoHelpers = Parameters<ContractFactory$1<Record<never, never>, Record<never, never>, undefined, MongoFamilyPack, MongoTargetPack, undefined>>[0];
|
|
9
|
+
type MongoDefinitionInput = Omit<ContractDefinition$1<MongoFamilyPack, MongoTargetPack>, 'family' | 'target'> & {
|
|
10
|
+
readonly family?: never;
|
|
11
|
+
readonly target?: never;
|
|
12
|
+
};
|
|
13
|
+
type MongoScaffoldInput = Omit<ContractScaffold$1<MongoFamilyPack, MongoTargetPack>, 'family' | 'target'> & {
|
|
14
|
+
readonly family?: never;
|
|
15
|
+
readonly target?: never;
|
|
16
|
+
};
|
|
17
|
+
declare function defineContract<const Definition extends MongoDefinitionInput>(definition: Definition): MongoContractResult$1<Definition & {
|
|
18
|
+
readonly family: MongoFamilyPack;
|
|
19
|
+
readonly target: MongoTargetPack;
|
|
20
|
+
}>;
|
|
21
|
+
declare function defineContract<const Definition extends MongoScaffoldInput, const Built extends {
|
|
22
|
+
readonly models?: Record<string, unknown>;
|
|
23
|
+
readonly valueObjects?: Record<string, unknown>;
|
|
24
|
+
readonly roots?: Record<string, string>;
|
|
25
|
+
}>(scaffold: Definition, factory: (helpers: MongoHelpers) => Built): MongoContractResult$1<Definition & Built & {
|
|
26
|
+
readonly family: MongoFamilyPack;
|
|
27
|
+
readonly target: MongoTargetPack;
|
|
28
|
+
}>;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { type ContractDefinition, type ContractFactory, type ContractScaffold, type FieldBuilder, type FieldReference, type ModelBuilder, type MongoContractResult, type RelationBuilder, type ValueObjectBuilder, defineContract, field, index, model, rel, valueObject };
|
|
31
|
+
//# sourceMappingURL=contract-builder.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-builder.d.mts","names":[],"sources":["../src/contract/define-contract.ts"],"mappings":";;;;;KAUK,eAAA,UAAyB,eAAA;AAAA,KACzB,eAAA,UAAyB,eAAA;AAAA,KAIzB,YAAA,GAAe,UAAA,CAClB,iBAAA,CACE,MAAA,gBACA,MAAA,2BAEA,eAAA,EACA,eAAA;AAAA,KAOC,oBAAA,GAAuB,IAAA,CAC1B,oBAAA,CAAmB,eAAA,EAAiB,eAAA;EAAA,SAG3B,MAAA;EAAA,SACA,MAAA;AAAA;AAAA,KAGN,kBAAA,GAAqB,IAAA,CACxB,kBAAA,CAAiB,eAAA,EAAiB,eAAA;EAAA,SAGzB,MAAA;EAAA,SACA,MAAA;AAAA;AAAA,iBAIK,cAAA,0BAAwC,oBAAA,CAAA,CACtD,UAAA,EAAY,UAAA,GACX,qBAAA,CACD,UAAA;EAAA,SAAwB,MAAA,EAAQ,eAAA;EAAA,SAA0B,MAAA,EAAQ,eAAA;AAAA;AAAA,iBAIpD,cAAA,0BACW,kBAAA;EAAA,SAEd,MAAA,GAAS,MAAA;EAAA,SACT,YAAA,GAAe,MAAA;EAAA,SACf,KAAA,GAAQ,MAAA;AAAA,EAAA,CAGnB,QAAA,EAAU,UAAA,EACV,OAAA,GAAU,OAAA,EAAS,YAAA,KAAiB,KAAA,GACnC,qBAAA,CACD,UAAA,GAAa,KAAA;EAAA,SAAmB,MAAA,EAAQ,eAAA;EAAA,SAA0B,MAAA,EAAQ,eAAA;AAAA"}
|
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
import { defineContract, field, index, model, rel, valueObject } from "@prisma-next/mongo-contract-ts/contract-builder";
|
|
1
|
+
import { defineContract as defineContract$1, field, index, model, rel, valueObject } from "@prisma-next/mongo-contract-ts/contract-builder";
|
|
2
|
+
import mongoFamilyPack from "@prisma-next/family-mongo/pack";
|
|
3
|
+
import mongoTargetPack from "@prisma-next/target-mongo/pack";
|
|
4
|
+
//#region src/contract/define-contract.ts
|
|
5
|
+
function defineContract(definition, factory) {
|
|
6
|
+
const full = {
|
|
7
|
+
...definition,
|
|
8
|
+
family: mongoFamilyPack,
|
|
9
|
+
target: mongoTargetPack
|
|
10
|
+
};
|
|
11
|
+
if (factory !== void 0) return defineContract$1(full, factory);
|
|
12
|
+
return defineContract$1(full);
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
2
15
|
export { defineContract, field, index, model, rel, valueObject };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=contract-builder.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-builder.mjs","names":["baseDefineContract"],"sources":["../src/contract/define-contract.ts"],"sourcesContent":["import mongoFamilyPack from '@prisma-next/family-mongo/pack';\nimport type {\n ContractDefinition,\n ContractFactory,\n ContractScaffold,\n MongoContractResult,\n} from '@prisma-next/mongo-contract-ts/contract-builder';\nimport { defineContract as baseDefineContract } from '@prisma-next/mongo-contract-ts/contract-builder';\nimport mongoTargetPack from '@prisma-next/target-mongo/pack';\n\ntype MongoFamilyPack = typeof mongoFamilyPack;\ntype MongoTargetPack = typeof mongoTargetPack;\n\n// Helpers type derived from the exported ContractFactory rather than the\n// un-exported ContractAuthoringHelpers, so we stay inside the public surface.\ntype MongoHelpers = Parameters<\n ContractFactory<\n Record<never, never>,\n Record<never, never>,\n undefined,\n MongoFamilyPack,\n MongoTargetPack,\n undefined\n >\n>[0];\n\n// Input types omit family + target AND explicitly forbid them so that\n// `@ts-expect-error` tests can verify the fields are rejected.\ntype MongoDefinitionInput = Omit<\n ContractDefinition<MongoFamilyPack, MongoTargetPack>,\n 'family' | 'target'\n> & {\n readonly family?: never;\n readonly target?: never;\n};\n\ntype MongoScaffoldInput = Omit<\n ContractScaffold<MongoFamilyPack, MongoTargetPack>,\n 'family' | 'target'\n> & {\n readonly family?: never;\n readonly target?: never;\n};\n\n// Overload 1: definition form — models / valueObjects inline in the definition object.\nexport function defineContract<const Definition extends MongoDefinitionInput>(\n definition: Definition,\n): MongoContractResult<\n Definition & { readonly family: MongoFamilyPack; readonly target: MongoTargetPack }\n>;\n\n// Overload 2: factory form — models / valueObjects provided by a factory function.\nexport function defineContract<\n const Definition extends MongoScaffoldInput,\n const Built extends {\n readonly models?: Record<string, unknown>;\n readonly valueObjects?: Record<string, unknown>;\n readonly roots?: Record<string, string>;\n },\n>(\n scaffold: Definition,\n factory: (helpers: MongoHelpers) => Built,\n): MongoContractResult<\n Definition & Built & { readonly family: MongoFamilyPack; readonly target: MongoTargetPack }\n>;\n\n// Implementation — pre-binds family and target before delegating to the base.\n// The `as unknown` cast is safe: every declared overload produces a MongoContractResult\n// and the only difference between the public overload signatures and the impl is\n// that we union both call forms here.\nexport function defineContract(\n definition: MongoDefinitionInput,\n factory?: (helpers: MongoHelpers) => {\n readonly models?: Record<string, unknown>;\n readonly valueObjects?: Record<string, unknown>;\n readonly roots?: Record<string, string>;\n },\n): MongoContractResult<\n MongoDefinitionInput & { readonly family: MongoFamilyPack; readonly target: MongoTargetPack }\n> {\n const full = {\n ...definition,\n family: mongoFamilyPack,\n target: mongoTargetPack,\n } as ContractDefinition<MongoFamilyPack, MongoTargetPack>;\n\n if (factory !== undefined) {\n return baseDefineContract(\n full as ContractScaffold<MongoFamilyPack, MongoTargetPack>,\n factory as unknown as Parameters<typeof baseDefineContract>[1],\n ) as unknown as MongoContractResult<\n MongoDefinitionInput & { readonly family: MongoFamilyPack; readonly target: MongoTargetPack }\n >;\n }\n\n return baseDefineContract(full) as unknown as MongoContractResult<\n MongoDefinitionInput & { readonly family: MongoFamilyPack; readonly target: MongoTargetPack }\n >;\n}\n"],"mappings":";;;;AAsEA,SAAgB,eACd,YACA,SAOA;CACA,MAAM,OAAO;EACX,GAAG;EACH,QAAQ;EACR,QAAQ;EACT;CAED,IAAI,YAAY,KAAA,GACd,OAAOA,iBACL,MACA,QACD;CAKH,OAAOA,iBAAmB,KAAK"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ControlClient, ControlClientOptions } from "@prisma-next/cli/control-api";
|
|
2
|
+
|
|
3
|
+
//#region src/exports/control.d.ts
|
|
4
|
+
interface MongoControlClientOptions {
|
|
5
|
+
readonly connection?: string;
|
|
6
|
+
readonly extensionPacks?: ControlClientOptions['extensionPacks'];
|
|
7
|
+
}
|
|
8
|
+
declare function createMongoControlClient(options?: MongoControlClientOptions): ControlClient;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { type ControlClient, MongoControlClientOptions, createMongoControlClient };
|
|
11
|
+
//# sourceMappingURL=control.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control.d.mts","names":[],"sources":["../src/exports/control.ts"],"mappings":";;;UAWiB,yBAAA;EAAA,SACN,UAAA;EAAA,SACA,cAAA,GAAiB,oBAAA;AAAA;AAAA,iBAGZ,wBAAA,CAAyB,OAAA,GAAS,yBAAA,GAAiC,aAAA"}
|
package/dist/control.mjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import mongoAdapter from "@prisma-next/adapter-mongo/control";
|
|
2
|
+
import mongoDriver from "@prisma-next/driver-mongo/control";
|
|
3
|
+
import { mongoFamilyDescriptor } from "@prisma-next/family-mongo/control";
|
|
4
|
+
import { mongoTargetDescriptor } from "@prisma-next/target-mongo/control";
|
|
5
|
+
import { ifDefined } from "@prisma-next/utils/defined";
|
|
6
|
+
import { createControlClient } from "@prisma-next/cli/control-api";
|
|
7
|
+
//#region src/exports/control.ts
|
|
8
|
+
function createMongoControlClient(options = {}) {
|
|
9
|
+
return createControlClient({
|
|
10
|
+
family: mongoFamilyDescriptor,
|
|
11
|
+
target: mongoTargetDescriptor,
|
|
12
|
+
adapter: mongoAdapter,
|
|
13
|
+
driver: mongoDriver,
|
|
14
|
+
...ifDefined("connection", options.connection),
|
|
15
|
+
...ifDefined("extensionPacks", options.extensionPacks)
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { createMongoControlClient };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=control.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control.mjs","names":[],"sources":["../src/exports/control.ts"],"sourcesContent":["import mongoAdapter from '@prisma-next/adapter-mongo/control';\nimport {\n type ControlClient,\n type ControlClientOptions,\n createControlClient,\n} from '@prisma-next/cli/control-api';\nimport mongoDriver from '@prisma-next/driver-mongo/control';\nimport { mongoFamilyDescriptor } from '@prisma-next/family-mongo/control';\nimport { mongoTargetDescriptor } from '@prisma-next/target-mongo/control';\nimport { ifDefined } from '@prisma-next/utils/defined';\n\nexport interface MongoControlClientOptions {\n readonly connection?: string;\n readonly extensionPacks?: ControlClientOptions['extensionPacks'];\n}\n\nexport function createMongoControlClient(options: MongoControlClientOptions = {}): ControlClient {\n const clientOptions: ControlClientOptions = {\n family: mongoFamilyDescriptor,\n target: mongoTargetDescriptor,\n adapter: mongoAdapter,\n driver: mongoDriver,\n ...ifDefined('connection', options.connection),\n ...ifDefined('extensionPacks', options.extensionPacks),\n };\n return createControlClient(clientOptions);\n}\n\nexport type { ControlClient };\n"],"mappings":";;;;;;;AAgBA,SAAgB,yBAAyB,UAAqC,EAAE,EAAiB;CAS/F,OAAO,oBAAoB;EAPzB,QAAQ;EACR,QAAQ;EACR,SAAS;EACT,QAAQ;EACR,GAAG,UAAU,cAAc,QAAQ,WAAW;EAC9C,GAAG,UAAU,kBAAkB,QAAQ,eAAe;EAEhB,CAAC"}
|
package/dist/runtime.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ifDefined } from "@prisma-next/utils/defined";
|
|
1
2
|
import mongoRuntimeAdapter from "@prisma-next/adapter-mongo/runtime";
|
|
2
3
|
import { MongoDriverImpl } from "@prisma-next/driver-mongo";
|
|
3
4
|
import { MongoContractSerializer } from "@prisma-next/family-mongo/ir";
|
|
@@ -6,7 +7,6 @@ import { mongoOrm } from "@prisma-next/mongo-orm";
|
|
|
6
7
|
import { mongoQuery } from "@prisma-next/mongo-query-builder";
|
|
7
8
|
import { createMongoExecutionContext, createMongoExecutionStack, createMongoRuntime } from "@prisma-next/mongo-runtime";
|
|
8
9
|
import mongoRuntimeTarget from "@prisma-next/target-mongo/runtime";
|
|
9
|
-
import { ifDefined } from "@prisma-next/utils/defined";
|
|
10
10
|
//#region src/runtime/binding.ts
|
|
11
11
|
function validateMongoUrl(url) {
|
|
12
12
|
const trimmed = url.trim();
|
package/package.json
CHANGED
|
@@ -1,32 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/mongo",
|
|
3
|
-
"version": "0.10.0-dev.
|
|
3
|
+
"version": "0.10.0-dev.27",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"description": "One-package Mongo setup for Prisma Next",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@prisma-next/adapter-mongo": "0.10.0-dev.
|
|
10
|
-
"@prisma-next/
|
|
11
|
-
"@prisma-next/
|
|
12
|
-
"@prisma-next/
|
|
13
|
-
"@prisma-next/
|
|
14
|
-
"@prisma-next/
|
|
15
|
-
"@prisma-next/
|
|
16
|
-
"@prisma-next/mongo-contract
|
|
17
|
-
"@prisma-next/mongo-contract-
|
|
18
|
-
"@prisma-next/mongo-
|
|
19
|
-
"@prisma-next/mongo-
|
|
20
|
-
"@prisma-next/mongo-
|
|
21
|
-
"@prisma-next/
|
|
22
|
-
"@prisma-next/
|
|
9
|
+
"@prisma-next/adapter-mongo": "0.10.0-dev.27",
|
|
10
|
+
"@prisma-next/cli": "0.10.0-dev.27",
|
|
11
|
+
"@prisma-next/config": "0.10.0-dev.27",
|
|
12
|
+
"@prisma-next/contract": "0.10.0-dev.27",
|
|
13
|
+
"@prisma-next/driver-mongo": "0.10.0-dev.27",
|
|
14
|
+
"@prisma-next/family-mongo": "0.10.0-dev.27",
|
|
15
|
+
"@prisma-next/framework-components": "0.10.0-dev.27",
|
|
16
|
+
"@prisma-next/mongo-contract": "0.10.0-dev.27",
|
|
17
|
+
"@prisma-next/mongo-contract-psl": "0.10.0-dev.27",
|
|
18
|
+
"@prisma-next/mongo-contract-ts": "0.10.0-dev.27",
|
|
19
|
+
"@prisma-next/mongo-orm": "0.10.0-dev.27",
|
|
20
|
+
"@prisma-next/mongo-query-builder": "0.10.0-dev.27",
|
|
21
|
+
"@prisma-next/mongo-runtime": "0.10.0-dev.27",
|
|
22
|
+
"@prisma-next/target-mongo": "0.10.0-dev.27",
|
|
23
|
+
"@prisma-next/utils": "0.10.0-dev.27",
|
|
23
24
|
"mongodb": "^6.16.0",
|
|
24
25
|
"pathe": "^2.0.3"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
|
-
"@prisma-next/test-utils": "0.10.0-dev.
|
|
28
|
-
"@prisma-next/tsconfig": "0.10.0-dev.
|
|
29
|
-
"@prisma-next/tsdown": "0.10.0-dev.
|
|
28
|
+
"@prisma-next/test-utils": "0.10.0-dev.27",
|
|
29
|
+
"@prisma-next/tsconfig": "0.10.0-dev.27",
|
|
30
|
+
"@prisma-next/tsdown": "0.10.0-dev.27",
|
|
30
31
|
"mongodb-memory-server": "11.1.0",
|
|
31
32
|
"tsdown": "0.22.0",
|
|
32
33
|
"typescript": "5.9.3",
|
|
@@ -45,9 +46,10 @@
|
|
|
45
46
|
"node": ">=20"
|
|
46
47
|
},
|
|
47
48
|
"exports": {
|
|
48
|
-
"
|
|
49
|
+
"./bson": "./dist/bson.mjs",
|
|
49
50
|
"./config": "./dist/config.mjs",
|
|
50
51
|
"./contract-builder": "./dist/contract-builder.mjs",
|
|
52
|
+
"./control": "./dist/control.mjs",
|
|
51
53
|
"./family": "./dist/family.mjs",
|
|
52
54
|
"./runtime": "./dist/runtime.mjs",
|
|
53
55
|
"./target": "./dist/target.mjs",
|
|
@@ -3,9 +3,11 @@ import type { PrismaNextConfig } from '@prisma-next/config/config-types';
|
|
|
3
3
|
import { defineConfig as coreDefineConfig } from '@prisma-next/config/config-types';
|
|
4
4
|
import mongoDriver from '@prisma-next/driver-mongo/control';
|
|
5
5
|
import { mongoFamilyDescriptor } from '@prisma-next/family-mongo/control';
|
|
6
|
+
import type { ControlExtensionDescriptor } from '@prisma-next/framework-components/control';
|
|
6
7
|
import { mongoContract } from '@prisma-next/mongo-contract-psl/provider';
|
|
7
8
|
import { typescriptContractFromPath } from '@prisma-next/mongo-contract-ts/config-types';
|
|
8
9
|
import { mongoTargetDescriptor } from '@prisma-next/target-mongo/control';
|
|
10
|
+
import { ifDefined } from '@prisma-next/utils/defined';
|
|
9
11
|
import { extname } from 'pathe';
|
|
10
12
|
|
|
11
13
|
export interface MongoConfigOptions {
|
|
@@ -13,6 +15,10 @@ export interface MongoConfigOptions {
|
|
|
13
15
|
readonly db?: {
|
|
14
16
|
readonly connection?: string;
|
|
15
17
|
};
|
|
18
|
+
readonly extensions?: readonly ControlExtensionDescriptor<'mongo', 'mongo'>[];
|
|
19
|
+
readonly migrations?: {
|
|
20
|
+
readonly dir?: string;
|
|
21
|
+
};
|
|
16
22
|
}
|
|
17
23
|
|
|
18
24
|
function deriveOutputPath(contractPath: string): string {
|
|
@@ -24,6 +30,7 @@ function deriveOutputPath(contractPath: string): string {
|
|
|
24
30
|
}
|
|
25
31
|
|
|
26
32
|
export function defineConfig(options: MongoConfigOptions): PrismaNextConfig<'mongo', 'mongo'> {
|
|
33
|
+
const extensions = options.extensions ?? [];
|
|
27
34
|
const output = deriveOutputPath(options.contract);
|
|
28
35
|
const ext = extname(options.contract);
|
|
29
36
|
|
|
@@ -37,7 +44,9 @@ export function defineConfig(options: MongoConfigOptions): PrismaNextConfig<'mon
|
|
|
37
44
|
target: mongoTargetDescriptor,
|
|
38
45
|
adapter: mongoAdapter,
|
|
39
46
|
driver: mongoDriver,
|
|
47
|
+
extensionPacks: extensions,
|
|
40
48
|
contract: contractConfig,
|
|
41
|
-
...(
|
|
49
|
+
...ifDefined('db', options.db),
|
|
50
|
+
...ifDefined('migrations', options.migrations),
|
|
42
51
|
});
|
|
43
52
|
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import mongoFamilyPack from '@prisma-next/family-mongo/pack';
|
|
2
|
+
import type {
|
|
3
|
+
ContractDefinition,
|
|
4
|
+
ContractFactory,
|
|
5
|
+
ContractScaffold,
|
|
6
|
+
MongoContractResult,
|
|
7
|
+
} from '@prisma-next/mongo-contract-ts/contract-builder';
|
|
8
|
+
import { defineContract as baseDefineContract } from '@prisma-next/mongo-contract-ts/contract-builder';
|
|
9
|
+
import mongoTargetPack from '@prisma-next/target-mongo/pack';
|
|
10
|
+
|
|
11
|
+
type MongoFamilyPack = typeof mongoFamilyPack;
|
|
12
|
+
type MongoTargetPack = typeof mongoTargetPack;
|
|
13
|
+
|
|
14
|
+
// Helpers type derived from the exported ContractFactory rather than the
|
|
15
|
+
// un-exported ContractAuthoringHelpers, so we stay inside the public surface.
|
|
16
|
+
type MongoHelpers = Parameters<
|
|
17
|
+
ContractFactory<
|
|
18
|
+
Record<never, never>,
|
|
19
|
+
Record<never, never>,
|
|
20
|
+
undefined,
|
|
21
|
+
MongoFamilyPack,
|
|
22
|
+
MongoTargetPack,
|
|
23
|
+
undefined
|
|
24
|
+
>
|
|
25
|
+
>[0];
|
|
26
|
+
|
|
27
|
+
// Input types omit family + target AND explicitly forbid them so that
|
|
28
|
+
// `@ts-expect-error` tests can verify the fields are rejected.
|
|
29
|
+
type MongoDefinitionInput = Omit<
|
|
30
|
+
ContractDefinition<MongoFamilyPack, MongoTargetPack>,
|
|
31
|
+
'family' | 'target'
|
|
32
|
+
> & {
|
|
33
|
+
readonly family?: never;
|
|
34
|
+
readonly target?: never;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
type MongoScaffoldInput = Omit<
|
|
38
|
+
ContractScaffold<MongoFamilyPack, MongoTargetPack>,
|
|
39
|
+
'family' | 'target'
|
|
40
|
+
> & {
|
|
41
|
+
readonly family?: never;
|
|
42
|
+
readonly target?: never;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// Overload 1: definition form — models / valueObjects inline in the definition object.
|
|
46
|
+
export function defineContract<const Definition extends MongoDefinitionInput>(
|
|
47
|
+
definition: Definition,
|
|
48
|
+
): MongoContractResult<
|
|
49
|
+
Definition & { readonly family: MongoFamilyPack; readonly target: MongoTargetPack }
|
|
50
|
+
>;
|
|
51
|
+
|
|
52
|
+
// Overload 2: factory form — models / valueObjects provided by a factory function.
|
|
53
|
+
export function defineContract<
|
|
54
|
+
const Definition extends MongoScaffoldInput,
|
|
55
|
+
const Built extends {
|
|
56
|
+
readonly models?: Record<string, unknown>;
|
|
57
|
+
readonly valueObjects?: Record<string, unknown>;
|
|
58
|
+
readonly roots?: Record<string, string>;
|
|
59
|
+
},
|
|
60
|
+
>(
|
|
61
|
+
scaffold: Definition,
|
|
62
|
+
factory: (helpers: MongoHelpers) => Built,
|
|
63
|
+
): MongoContractResult<
|
|
64
|
+
Definition & Built & { readonly family: MongoFamilyPack; readonly target: MongoTargetPack }
|
|
65
|
+
>;
|
|
66
|
+
|
|
67
|
+
// Implementation — pre-binds family and target before delegating to the base.
|
|
68
|
+
// The `as unknown` cast is safe: every declared overload produces a MongoContractResult
|
|
69
|
+
// and the only difference between the public overload signatures and the impl is
|
|
70
|
+
// that we union both call forms here.
|
|
71
|
+
export function defineContract(
|
|
72
|
+
definition: MongoDefinitionInput,
|
|
73
|
+
factory?: (helpers: MongoHelpers) => {
|
|
74
|
+
readonly models?: Record<string, unknown>;
|
|
75
|
+
readonly valueObjects?: Record<string, unknown>;
|
|
76
|
+
readonly roots?: Record<string, string>;
|
|
77
|
+
},
|
|
78
|
+
): MongoContractResult<
|
|
79
|
+
MongoDefinitionInput & { readonly family: MongoFamilyPack; readonly target: MongoTargetPack }
|
|
80
|
+
> {
|
|
81
|
+
const full = {
|
|
82
|
+
...definition,
|
|
83
|
+
family: mongoFamilyPack,
|
|
84
|
+
target: mongoTargetPack,
|
|
85
|
+
} as ContractDefinition<MongoFamilyPack, MongoTargetPack>;
|
|
86
|
+
|
|
87
|
+
if (factory !== undefined) {
|
|
88
|
+
return baseDefineContract(
|
|
89
|
+
full as ContractScaffold<MongoFamilyPack, MongoTargetPack>,
|
|
90
|
+
factory as unknown as Parameters<typeof baseDefineContract>[1],
|
|
91
|
+
) as unknown as MongoContractResult<
|
|
92
|
+
MongoDefinitionInput & { readonly family: MongoFamilyPack; readonly target: MongoTargetPack }
|
|
93
|
+
>;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return baseDefineContract(full) as unknown as MongoContractResult<
|
|
97
|
+
MongoDefinitionInput & { readonly family: MongoFamilyPack; readonly target: MongoTargetPack }
|
|
98
|
+
>;
|
|
99
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Binary, Decimal128, Long, MongoClient, ObjectId, Timestamp } from 'mongodb';
|
|
@@ -10,10 +10,10 @@ export type {
|
|
|
10
10
|
ValueObjectBuilder,
|
|
11
11
|
} from '@prisma-next/mongo-contract-ts/contract-builder';
|
|
12
12
|
export {
|
|
13
|
-
defineContract,
|
|
14
13
|
field,
|
|
15
14
|
index,
|
|
16
15
|
model,
|
|
17
16
|
rel,
|
|
18
17
|
valueObject,
|
|
19
18
|
} from '@prisma-next/mongo-contract-ts/contract-builder';
|
|
19
|
+
export { defineContract } from '../contract/define-contract';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import mongoAdapter from '@prisma-next/adapter-mongo/control';
|
|
2
|
+
import {
|
|
3
|
+
type ControlClient,
|
|
4
|
+
type ControlClientOptions,
|
|
5
|
+
createControlClient,
|
|
6
|
+
} from '@prisma-next/cli/control-api';
|
|
7
|
+
import mongoDriver from '@prisma-next/driver-mongo/control';
|
|
8
|
+
import { mongoFamilyDescriptor } from '@prisma-next/family-mongo/control';
|
|
9
|
+
import { mongoTargetDescriptor } from '@prisma-next/target-mongo/control';
|
|
10
|
+
import { ifDefined } from '@prisma-next/utils/defined';
|
|
11
|
+
|
|
12
|
+
export interface MongoControlClientOptions {
|
|
13
|
+
readonly connection?: string;
|
|
14
|
+
readonly extensionPacks?: ControlClientOptions['extensionPacks'];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function createMongoControlClient(options: MongoControlClientOptions = {}): ControlClient {
|
|
18
|
+
const clientOptions: ControlClientOptions = {
|
|
19
|
+
family: mongoFamilyDescriptor,
|
|
20
|
+
target: mongoTargetDescriptor,
|
|
21
|
+
adapter: mongoAdapter,
|
|
22
|
+
driver: mongoDriver,
|
|
23
|
+
...ifDefined('connection', options.connection),
|
|
24
|
+
...ifDefined('extensionPacks', options.extensionPacks),
|
|
25
|
+
};
|
|
26
|
+
return createControlClient(clientOptions);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type { ControlClient };
|
package/src/exports/index.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Top-level entry for `@prisma-next/mongo`.
|
|
3
|
-
*
|
|
4
|
-
* Re-exports the BSON value constructors users reach for when authoring
|
|
5
|
-
* seed scripts, fixtures, or relational graphs that need to pre-allocate
|
|
6
|
-
* `_id`s before insert (e.g. wiring related rows in a single `createAll`
|
|
7
|
-
* call). Routing these through the facade keeps the user's `package.json`
|
|
8
|
-
* to a single `@prisma-next/mongo` pin and removes the version-drift risk
|
|
9
|
-
* of also declaring `mongodb` directly when the facade already bundles it.
|
|
10
|
-
*/
|
|
11
|
-
export { Binary, Decimal128, Long, MongoClient, ObjectId, Timestamp } from 'mongodb';
|
|
File without changes
|
|
File without changes
|