@prisma-next/mongo-contract 0.7.0 → 0.8.0-dev.10

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.
@@ -1,4 +1,4 @@
1
- import type { MongoStorageIndex } from './contract-types';
1
+ import { MongoIndex, type MongoIndexInput } from './ir/mongo-index';
2
2
 
3
3
  export type PolymorphicIndexScope = {
4
4
  readonly discriminatorField: string;
@@ -6,7 +6,7 @@ export type PolymorphicIndexScope = {
6
6
  };
7
7
 
8
8
  export type ApplyScopeResult =
9
- | { readonly kind: 'ok'; readonly index: MongoStorageIndex }
9
+ | { readonly kind: 'ok'; readonly index: MongoIndex }
10
10
  | { readonly kind: 'conflict'; readonly reason: string };
11
11
 
12
12
  function isScalarDiscriminatorValue(value: unknown): value is string | number | boolean {
@@ -23,7 +23,7 @@ function formatValue(value: unknown): string {
23
23
  }
24
24
 
25
25
  export function applyPolymorphicScopeToMongoIndex(
26
- index: MongoStorageIndex,
26
+ index: MongoIndex,
27
27
  scope: PolymorphicIndexScope,
28
28
  ): ApplyScopeResult {
29
29
  if (!isScalarDiscriminatorValue(scope.discriminatorValue)) {
@@ -50,8 +50,18 @@ export function applyPolymorphicScopeToMongoIndex(
50
50
  [scope.discriminatorField]: scope.discriminatorValue,
51
51
  };
52
52
 
53
- return {
54
- kind: 'ok',
55
- index: { ...index, partialFilterExpression: merged },
53
+ const cloned: MongoIndexInput = {
54
+ keys: index.keys,
55
+ ...(index.unique !== undefined && { unique: index.unique }),
56
+ ...(index.sparse !== undefined && { sparse: index.sparse }),
57
+ ...(index.expireAfterSeconds !== undefined && { expireAfterSeconds: index.expireAfterSeconds }),
58
+ partialFilterExpression: merged,
59
+ ...(index.wildcardProjection !== undefined && { wildcardProjection: index.wildcardProjection }),
60
+ ...(index.collation !== undefined && { collation: index.collation }),
61
+ ...(index.weights !== undefined && { weights: index.weights }),
62
+ ...(index.default_language !== undefined && { default_language: index.default_language }),
63
+ ...(index.language_override !== undefined && { language_override: index.language_override }),
56
64
  };
65
+
66
+ return { kind: 'ok', index: new MongoIndex(cloned) };
57
67
  }
@@ -22,6 +22,14 @@ export function validateMongoContract<TContract extends MongoContract>(
22
22
  throw new Error(`Contract structural validation failed: ${parsed.summary}`);
23
23
  }
24
24
 
25
+ // arktype's `infer`d type for `MongoContractSchema` is structurally
26
+ // equivalent to `MongoContract` but not nominally so (arktype DSL output
27
+ // types differ on optional/readonly modifiers, narrowed-literal positions,
28
+ // and utility-type wrappings from the hand-authored generic
29
+ // `MongoContract<S, M>` surface). The double cast is the documented
30
+ // escape hatch from arktype's nominal-output representation to the
31
+ // project's nominal-contract representation; the schema and the type are
32
+ // kept in lockstep by the round-trip fixtures under `test/validate.test.ts`.
25
33
  const contract = parsed as unknown as TContract;
26
34
 
27
35
  validateContractDomain(contract);