@prisma-next/mongo-emitter 0.12.0-dev.40 → 0.12.0-dev.42

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 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/index.ts"],"mappings":";;;;cAyEa,aAAA;;0BAGa,QAAA,EAAQ,IAAA,EAAQ,iBAAA;8BA6CZ,QAAA;gCAyGE,QAAA,EAAQ,mBAAA;+CAMK,KAAA,EAAS,aAAA;;;;+CAuCT,YAAA;AAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/index.ts"],"mappings":";;;;cAuEa,aAAA;;0BAGa,QAAA,EAAQ,IAAA,EAAQ,iBAAA;8BA6CZ,QAAA;gCAyGE,QAAA,EAAQ,mBAAA;+CAMK,KAAA,EAAS,aAAA;;;;+CAuCT,YAAA;AAAA"}
@@ -8,7 +8,7 @@ function mongoNamespaceSerializedKind(ns) {
8
8
  }
9
9
  function assertUniqueMongoCollectionNames(storage) {
10
10
  const seen = /* @__PURE__ */ new Map();
11
- for (const [namespaceId, ns] of Object.entries(storage.namespaces)) for (const coll of Object.keys(ns.collections)) {
11
+ for (const [namespaceId, ns] of Object.entries(storage.namespaces)) for (const coll of Object.keys(ns.entries.collection)) {
12
12
  const existing = seen.get(coll);
13
13
  if (existing !== void 0 && existing !== namespaceId) throw new Error(`Duplicate collection name "${coll}" in namespaces "${existing}" and "${namespaceId}"`);
14
14
  seen.set(coll, namespaceId);
@@ -29,8 +29,8 @@ function generateMongoNamespacesType(namespaces) {
29
29
  if (sorted.length === 0) return "Record<string, never>";
30
30
  const parts = [];
31
31
  for (const [name, ns] of sorted) {
32
- const collectionsType = generateMongoNamespaceCollectionsType(ns.collections);
33
- parts.push(`readonly ${serializeObjectKey(name)}: { readonly id: ${serializeValue(ns.id)}; ${mongoNamespaceSerializedKind(ns)}; readonly collections: ${collectionsType} }`);
32
+ const collectionsType = generateMongoNamespaceCollectionsType(ns.entries.collection);
33
+ parts.push(`readonly ${serializeObjectKey(name)}: { readonly id: ${serializeValue(ns.id)}; ${mongoNamespaceSerializedKind(ns)}; readonly entries: { readonly collection: ${collectionsType} } }`);
34
34
  }
35
35
  return `{ ${parts.join("; ")} }`;
36
36
  }
@@ -61,7 +61,7 @@ const mongoEmission = {
61
61
  if (!storage?.namespaces || typeof storage.namespaces !== "object") throw new Error("Mongo contract must have storage.namespaces");
62
62
  assertUniqueMongoCollectionNames(storage);
63
63
  const collectionNames = /* @__PURE__ */ new Set();
64
- for (const ns of Object.values(storage.namespaces)) for (const c of Object.keys(ns.collections)) collectionNames.add(c);
64
+ for (const ns of Object.values(storage.namespaces)) for (const c of Object.keys(ns.entries.collection)) collectionNames.add(c);
65
65
  for (const [namespaceId, domainNs] of Object.entries(contract.domain.namespaces)) {
66
66
  const models = domainNs.models;
67
67
  if (Object.keys(models).length === 0) continue;
@@ -76,7 +76,7 @@ const mongoEmission = {
76
76
  if (collection) throw new Error(`Owned model "${qualifiedName}" must not have storage.collection (embedded models are stored within their owner)`);
77
77
  if (!models[model.owner]) throw new Error(`Model "${qualifiedName}" declares owner "${model.owner}" which does not exist in models`);
78
78
  } else if (collection) {
79
- if (!collectionNames.has(collection)) throw new Error(`Model "${qualifiedName}" references collection "${collection}" which is not in storage.namespaces[..].collections`);
79
+ if (!collectionNames.has(collection)) throw new Error(`Model "${qualifiedName}" references collection "${collection}" which is not in storage.namespaces[..].entries.collection`);
80
80
  }
81
81
  if (model.base) {
82
82
  const baseModel = models[model.base.model];
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["relObj"],"sources":["../../src/index.ts"],"sourcesContent":["import type { Contract, ContractModel } from '@prisma-next/contract/types';\nimport { serializeObjectKey, serializeValue } from '@prisma-next/emitter/domain-type-generation';\nimport type { ValidationContext } from '@prisma-next/framework-components/emission';\nimport type { Namespace } from '@prisma-next/framework-components/ir';\nimport type { MongoCollection, MongoStorage } from '@prisma-next/mongo-contract';\n\nconst MONGO_NAMESPACE_KIND_FALLBACK = 'mongo-namespace' as const;\n\nfunction mongoNamespaceSerializedKind(ns: Namespace): string {\n const kind = (ns as { kind?: unknown }).kind;\n if (typeof kind === 'string') {\n return `readonly kind: ${serializeValue(kind)}`;\n }\n return `readonly kind: '${MONGO_NAMESPACE_KIND_FALLBACK}'`;\n}\n\nfunction assertUniqueMongoCollectionNames(storage: MongoStorage): void {\n const seen = new Map<string, string>();\n for (const [namespaceId, ns] of Object.entries(storage.namespaces)) {\n for (const coll of Object.keys(ns.collections)) {\n const existing = seen.get(coll);\n if (existing !== undefined && existing !== namespaceId) {\n throw new Error(\n `Duplicate collection name \"${coll}\" in namespaces \"${existing}\" and \"${namespaceId}\"`,\n );\n }\n seen.set(coll, namespaceId);\n }\n }\n}\n\nfunction generateMongoCollectionEntryType(coll: MongoCollection): string {\n const entries = Object.entries(coll).filter(([key, v]) => v !== undefined && key !== 'kind');\n if (entries.length === 0) {\n return 'MongoCollection';\n }\n return serializeValue(coll);\n}\n\nfunction generateMongoNamespaceCollectionsType(\n collections: Readonly<Record<string, MongoCollection>>,\n): string {\n const entries: string[] = [];\n for (const [collName, coll] of Object.entries(collections).sort(([a], [b]) =>\n a.localeCompare(b),\n )) {\n entries.push(\n `readonly ${serializeObjectKey(collName)}: ${generateMongoCollectionEntryType(coll)}`,\n );\n }\n if (entries.length === 0) {\n return 'Record<string, never>';\n }\n return `{ ${entries.join('; ')} }`;\n}\n\nfunction generateMongoNamespacesType(namespaces: MongoStorage['namespaces']): string {\n const sorted = Object.entries(namespaces ?? {}).sort(([a], [b]) => a.localeCompare(b));\n if (sorted.length === 0) {\n return 'Record<string, never>';\n }\n const parts: string[] = [];\n for (const [name, ns] of sorted) {\n const collectionsType = generateMongoNamespaceCollectionsType(\n ns.collections as Readonly<Record<string, MongoCollection>>,\n );\n parts.push(\n `readonly ${serializeObjectKey(name)}: { readonly id: ${serializeValue(ns.id)}; ${mongoNamespaceSerializedKind(ns)}; readonly collections: ${collectionsType} }`,\n );\n }\n return `{ ${parts.join('; ')} }`;\n}\n\nexport const mongoEmission = {\n id: 'mongo',\n\n validateTypes(contract: Contract, _ctx: ValidationContext): void {\n const typeIdRegex = /^([^/]+)\\/([^@]+)@(\\d+)$/;\n\n for (const [namespaceId, domainNs] of Object.entries(contract.domain.namespaces)) {\n const models = domainNs.models as Record<string, ContractModel>;\n for (const [modelName, model] of Object.entries(models)) {\n const qualifiedName = `${namespaceId}:${modelName}`;\n for (const [fieldName, field] of Object.entries(model.fields)) {\n const fieldType = (\n field as {\n type?: {\n kind: string;\n codecId?: string;\n members?: ReadonlyArray<{ kind: string; codecId?: string }>;\n };\n }\n ).type;\n if (!fieldType) continue;\n\n const scalarTypes: Array<{ codecId?: string }> =\n fieldType.kind === 'scalar'\n ? [fieldType]\n : fieldType.kind === 'union' && fieldType.members\n ? fieldType.members.filter((m) => m.kind === 'scalar')\n : [];\n\n for (const scalarType of scalarTypes) {\n const { codecId } = scalarType;\n if (!codecId) {\n throw new Error(\n `Field \"${fieldName}\" on model \"${qualifiedName}\" is missing codecId`,\n );\n }\n const match = codecId.match(typeIdRegex);\n if (!match?.[1]) {\n throw new Error(\n `Field \"${fieldName}\" on model \"${qualifiedName}\" has invalid codec ID format \"${codecId}\". Expected format: ns/name@version`,\n );\n }\n }\n }\n }\n }\n },\n\n validateStructure(contract: Contract): void {\n if (contract.targetFamily !== 'mongo') {\n throw new Error(`Expected targetFamily \"mongo\", got \"${contract.targetFamily}\"`);\n }\n\n const storage = contract.storage as MongoStorage | undefined;\n if (!storage?.namespaces || typeof storage.namespaces !== 'object') {\n throw new Error('Mongo contract must have storage.namespaces');\n }\n\n assertUniqueMongoCollectionNames(storage);\n\n const collectionNames = new Set<string>();\n for (const ns of Object.values(storage.namespaces)) {\n for (const c of Object.keys(ns.collections)) {\n collectionNames.add(c);\n }\n }\n\n for (const [namespaceId, domainNs] of Object.entries(contract.domain.namespaces)) {\n const models = domainNs.models as Record<string, ContractModel>;\n if (Object.keys(models).length === 0) continue;\n\n for (const [modelName, model] of Object.entries(models)) {\n const qualifiedName = `${namespaceId}:${modelName}`;\n if (!model.fields || typeof model.fields !== 'object') {\n throw new Error(`Model \"${qualifiedName}\" is missing required field \"fields\"`);\n }\n if (!model.relations || typeof model.relations !== 'object') {\n throw new Error(\n `Model \"${qualifiedName}\" is missing required field \"relations\" (must be an object)`,\n );\n }\n if (!model.storage || typeof model.storage !== 'object') {\n throw new Error(\n `Model \"${qualifiedName}\" is missing required field \"storage\" (must be an object)`,\n );\n }\n\n const collectionValue = model.storage['collection'];\n const collection = typeof collectionValue === 'string' ? collectionValue : undefined;\n\n if (model.owner) {\n if (collection) {\n throw new Error(\n `Owned model \"${qualifiedName}\" must not have storage.collection (embedded models are stored within their owner)`,\n );\n }\n if (!models[model.owner]) {\n throw new Error(\n `Model \"${qualifiedName}\" declares owner \"${model.owner}\" which does not exist in models`,\n );\n }\n } else if (collection) {\n if (!collectionNames.has(collection)) {\n throw new Error(\n `Model \"${qualifiedName}\" references collection \"${collection}\" which is not in storage.namespaces[..].collections`,\n );\n }\n }\n\n if (model.base) {\n const baseModel = models[model.base.model];\n if (!baseModel) {\n throw new Error(\n `Model \"${qualifiedName}\" declares base \"${model.base.namespace}:${model.base.model}\" which does not exist in models`,\n );\n }\n const variantCollection = collection;\n const baseCollection = baseModel.storage['collection'] as string | undefined;\n if (variantCollection !== baseCollection) {\n throw new Error(\n `Variant \"${qualifiedName}\" must share its base's collection (\"${baseCollection ?? '(none)'}\"), but has \"${variantCollection ?? '(none)'}\"`,\n );\n }\n }\n\n const storageRelations = model.storage['relations'] as Record<string, unknown> | undefined;\n if (storageRelations) {\n for (const relName of Object.keys(storageRelations)) {\n if (!model.relations[relName]) {\n throw new Error(\n `Model \"${qualifiedName}\" has storage.relations.${relName} but no matching domain-level relation`,\n );\n }\n }\n }\n\n for (const [relName, rel] of Object.entries(model.relations)) {\n const relObj = rel as Record<string, unknown>;\n const targetRef = relObj['to'] as { readonly model?: string } | undefined;\n const targetModelName = targetRef?.model;\n if (targetModelName) {\n const targetModel = models[targetModelName];\n if (targetModel?.owner === modelName && !storageRelations?.[relName]) {\n throw new Error(\n `Model \"${qualifiedName}\" has embed relation \"${relName}\" to owned model \"${targetModelName}\" but no matching storage.relations entry`,\n );\n }\n }\n }\n }\n }\n },\n\n generateStorageType(contract: Contract, storageHashTypeName: string): string {\n const storage = contract.storage as MongoStorage;\n const namespacesType = generateMongoNamespacesType(storage.namespaces);\n return `{ readonly namespaces: ${namespacesType}; readonly storageHash: ${storageHashTypeName} }`;\n },\n\n generateModelStorageType(_modelName: string, model: ContractModel): string {\n const parts: string[] = [];\n const collection = model.storage['collection'] as string | undefined;\n if (collection) {\n parts.push(`readonly collection: ${serializeValue(collection)}`);\n }\n\n const storageRelations = model.storage['relations'] as\n | Record<string, Record<string, unknown>>\n | undefined;\n if (storageRelations && Object.keys(storageRelations).length > 0) {\n const relEntries: string[] = [];\n for (const [relName, relVal] of Object.entries(storageRelations)) {\n relEntries.push(`readonly ${serializeObjectKey(relName)}: ${serializeValue(relVal)}`);\n }\n parts.push(`readonly relations: { ${relEntries.join('; ')} }`);\n }\n\n return parts.length > 0 ? `{ ${parts.join('; ')} }` : 'Record<string, never>';\n },\n\n getFamilyImports(): string[] {\n return [\n 'import type {',\n ' MongoCollection,',\n ' MongoContractWithTypeMaps,',\n ' MongoTypeMaps,',\n \"} from '@prisma-next/mongo-contract';\",\n ];\n },\n\n getFamilyTypeAliases(): string {\n return '';\n },\n\n getTypeMapsExpression(): string {\n return 'MongoTypeMaps<CodecTypes, FieldOutputTypes, FieldInputTypes>';\n },\n\n getContractWrapper(contractBaseName: string, typeMapsName: string): string {\n return `export type Contract = MongoContractWithTypeMaps<${contractBaseName}, ${typeMapsName}>;`;\n },\n};\n"],"mappings":";;AAMA,MAAM,gCAAgC;AAEtC,SAAS,6BAA6B,IAAuB;CAC3D,MAAM,OAAQ,GAA0B;CACxC,IAAI,OAAO,SAAS,UAClB,OAA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;GACL;GACA;GACA;GACA;GACA;EACF;CACF;CAEA,uBAA+B;EAC7B,OAAO;CACT;CAEA,wBAAgC;EAC9B,OAAO;CACT;CAEA,mBAAmB,kBAA0B,cAA8B;EACzE,OAAO,oDAAoD,iBAAiB,IAAI,aAAa;CAC/F;AACF"}
1
+ {"version":3,"file":"index.mjs","names":["relObj"],"sources":["../../src/index.ts"],"sourcesContent":["import type { Contract, ContractModel } from '@prisma-next/contract/types';\nimport { serializeObjectKey, serializeValue } from '@prisma-next/emitter/domain-type-generation';\nimport type { ValidationContext } from '@prisma-next/framework-components/emission';\nimport type { Namespace } from '@prisma-next/framework-components/ir';\nimport type { MongoCollection, MongoStorage } from '@prisma-next/mongo-contract';\n\nconst MONGO_NAMESPACE_KIND_FALLBACK = 'mongo-namespace' as const;\n\nfunction mongoNamespaceSerializedKind(ns: Namespace): string {\n const kind = (ns as { kind?: unknown }).kind;\n if (typeof kind === 'string') {\n return `readonly kind: ${serializeValue(kind)}`;\n }\n return `readonly kind: '${MONGO_NAMESPACE_KIND_FALLBACK}'`;\n}\n\nfunction assertUniqueMongoCollectionNames(storage: MongoStorage): void {\n const seen = new Map<string, string>();\n for (const [namespaceId, ns] of Object.entries(storage.namespaces)) {\n for (const coll of Object.keys(ns.entries.collection)) {\n const existing = seen.get(coll);\n if (existing !== undefined && existing !== namespaceId) {\n throw new Error(\n `Duplicate collection name \"${coll}\" in namespaces \"${existing}\" and \"${namespaceId}\"`,\n );\n }\n seen.set(coll, namespaceId);\n }\n }\n}\n\nfunction generateMongoCollectionEntryType(coll: MongoCollection): string {\n const entries = Object.entries(coll).filter(([key, v]) => v !== undefined && key !== 'kind');\n if (entries.length === 0) {\n return 'MongoCollection';\n }\n return serializeValue(coll);\n}\n\nfunction generateMongoNamespaceCollectionsType(\n collections: Readonly<Record<string, MongoCollection>>,\n): string {\n const entries: string[] = [];\n for (const [collName, coll] of Object.entries(collections).sort(([a], [b]) =>\n a.localeCompare(b),\n )) {\n entries.push(\n `readonly ${serializeObjectKey(collName)}: ${generateMongoCollectionEntryType(coll)}`,\n );\n }\n if (entries.length === 0) {\n return 'Record<string, never>';\n }\n return `{ ${entries.join('; ')} }`;\n}\n\nfunction generateMongoNamespacesType(namespaces: MongoStorage['namespaces']): string {\n const sorted = Object.entries(namespaces ?? {}).sort(([a], [b]) => a.localeCompare(b));\n if (sorted.length === 0) {\n return 'Record<string, never>';\n }\n const parts: string[] = [];\n for (const [name, ns] of sorted) {\n const collectionsType = generateMongoNamespaceCollectionsType(ns.entries.collection);\n parts.push(\n `readonly ${serializeObjectKey(name)}: { readonly id: ${serializeValue(ns.id)}; ${mongoNamespaceSerializedKind(ns)}; readonly entries: { readonly collection: ${collectionsType} } }`,\n );\n }\n return `{ ${parts.join('; ')} }`;\n}\n\nexport const mongoEmission = {\n id: 'mongo',\n\n validateTypes(contract: Contract, _ctx: ValidationContext): void {\n const typeIdRegex = /^([^/]+)\\/([^@]+)@(\\d+)$/;\n\n for (const [namespaceId, domainNs] of Object.entries(contract.domain.namespaces)) {\n const models = domainNs.models as Record<string, ContractModel>;\n for (const [modelName, model] of Object.entries(models)) {\n const qualifiedName = `${namespaceId}:${modelName}`;\n for (const [fieldName, field] of Object.entries(model.fields)) {\n const fieldType = (\n field as {\n type?: {\n kind: string;\n codecId?: string;\n members?: ReadonlyArray<{ kind: string; codecId?: string }>;\n };\n }\n ).type;\n if (!fieldType) continue;\n\n const scalarTypes: Array<{ codecId?: string }> =\n fieldType.kind === 'scalar'\n ? [fieldType]\n : fieldType.kind === 'union' && fieldType.members\n ? fieldType.members.filter((m) => m.kind === 'scalar')\n : [];\n\n for (const scalarType of scalarTypes) {\n const { codecId } = scalarType;\n if (!codecId) {\n throw new Error(\n `Field \"${fieldName}\" on model \"${qualifiedName}\" is missing codecId`,\n );\n }\n const match = codecId.match(typeIdRegex);\n if (!match?.[1]) {\n throw new Error(\n `Field \"${fieldName}\" on model \"${qualifiedName}\" has invalid codec ID format \"${codecId}\". Expected format: ns/name@version`,\n );\n }\n }\n }\n }\n }\n },\n\n validateStructure(contract: Contract): void {\n if (contract.targetFamily !== 'mongo') {\n throw new Error(`Expected targetFamily \"mongo\", got \"${contract.targetFamily}\"`);\n }\n\n const storage = contract.storage as MongoStorage | undefined;\n if (!storage?.namespaces || typeof storage.namespaces !== 'object') {\n throw new Error('Mongo contract must have storage.namespaces');\n }\n\n assertUniqueMongoCollectionNames(storage);\n\n const collectionNames = new Set<string>();\n for (const ns of Object.values(storage.namespaces)) {\n for (const c of Object.keys(ns.entries.collection)) {\n collectionNames.add(c);\n }\n }\n\n for (const [namespaceId, domainNs] of Object.entries(contract.domain.namespaces)) {\n const models = domainNs.models as Record<string, ContractModel>;\n if (Object.keys(models).length === 0) continue;\n\n for (const [modelName, model] of Object.entries(models)) {\n const qualifiedName = `${namespaceId}:${modelName}`;\n if (!model.fields || typeof model.fields !== 'object') {\n throw new Error(`Model \"${qualifiedName}\" is missing required field \"fields\"`);\n }\n if (!model.relations || typeof model.relations !== 'object') {\n throw new Error(\n `Model \"${qualifiedName}\" is missing required field \"relations\" (must be an object)`,\n );\n }\n if (!model.storage || typeof model.storage !== 'object') {\n throw new Error(\n `Model \"${qualifiedName}\" is missing required field \"storage\" (must be an object)`,\n );\n }\n\n const collectionValue = model.storage['collection'];\n const collection = typeof collectionValue === 'string' ? collectionValue : undefined;\n\n if (model.owner) {\n if (collection) {\n throw new Error(\n `Owned model \"${qualifiedName}\" must not have storage.collection (embedded models are stored within their owner)`,\n );\n }\n if (!models[model.owner]) {\n throw new Error(\n `Model \"${qualifiedName}\" declares owner \"${model.owner}\" which does not exist in models`,\n );\n }\n } else if (collection) {\n if (!collectionNames.has(collection)) {\n throw new Error(\n `Model \"${qualifiedName}\" references collection \"${collection}\" which is not in storage.namespaces[..].entries.collection`,\n );\n }\n }\n\n if (model.base) {\n const baseModel = models[model.base.model];\n if (!baseModel) {\n throw new Error(\n `Model \"${qualifiedName}\" declares base \"${model.base.namespace}:${model.base.model}\" which does not exist in models`,\n );\n }\n const variantCollection = collection;\n const baseCollection = baseModel.storage['collection'] as string | undefined;\n if (variantCollection !== baseCollection) {\n throw new Error(\n `Variant \"${qualifiedName}\" must share its base's collection (\"${baseCollection ?? '(none)'}\"), but has \"${variantCollection ?? '(none)'}\"`,\n );\n }\n }\n\n const storageRelations = model.storage['relations'] as Record<string, unknown> | undefined;\n if (storageRelations) {\n for (const relName of Object.keys(storageRelations)) {\n if (!model.relations[relName]) {\n throw new Error(\n `Model \"${qualifiedName}\" has storage.relations.${relName} but no matching domain-level relation`,\n );\n }\n }\n }\n\n for (const [relName, rel] of Object.entries(model.relations)) {\n const relObj = rel as Record<string, unknown>;\n const targetRef = relObj['to'] as { readonly model?: string } | undefined;\n const targetModelName = targetRef?.model;\n if (targetModelName) {\n const targetModel = models[targetModelName];\n if (targetModel?.owner === modelName && !storageRelations?.[relName]) {\n throw new Error(\n `Model \"${qualifiedName}\" has embed relation \"${relName}\" to owned model \"${targetModelName}\" but no matching storage.relations entry`,\n );\n }\n }\n }\n }\n }\n },\n\n generateStorageType(contract: Contract, storageHashTypeName: string): string {\n const storage = contract.storage as MongoStorage;\n const namespacesType = generateMongoNamespacesType(storage.namespaces);\n return `{ readonly namespaces: ${namespacesType}; readonly storageHash: ${storageHashTypeName} }`;\n },\n\n generateModelStorageType(_modelName: string, model: ContractModel): string {\n const parts: string[] = [];\n const collection = model.storage['collection'] as string | undefined;\n if (collection) {\n parts.push(`readonly collection: ${serializeValue(collection)}`);\n }\n\n const storageRelations = model.storage['relations'] as\n | Record<string, Record<string, unknown>>\n | undefined;\n if (storageRelations && Object.keys(storageRelations).length > 0) {\n const relEntries: string[] = [];\n for (const [relName, relVal] of Object.entries(storageRelations)) {\n relEntries.push(`readonly ${serializeObjectKey(relName)}: ${serializeValue(relVal)}`);\n }\n parts.push(`readonly relations: { ${relEntries.join('; ')} }`);\n }\n\n return parts.length > 0 ? `{ ${parts.join('; ')} }` : 'Record<string, never>';\n },\n\n getFamilyImports(): string[] {\n return [\n 'import type {',\n ' MongoCollection,',\n ' MongoContractWithTypeMaps,',\n ' MongoTypeMaps,',\n \"} from '@prisma-next/mongo-contract';\",\n ];\n },\n\n getFamilyTypeAliases(): string {\n return '';\n },\n\n getTypeMapsExpression(): string {\n return 'MongoTypeMaps<CodecTypes, FieldOutputTypes, FieldInputTypes>';\n },\n\n getContractWrapper(contractBaseName: string, typeMapsName: string): string {\n return `export type Contract = MongoContractWithTypeMaps<${contractBaseName}, ${typeMapsName}>;`;\n },\n};\n"],"mappings":";;AAMA,MAAM,gCAAgC;AAEtC,SAAS,6BAA6B,IAAuB;CAC3D,MAAM,OAAQ,GAA0B;CACxC,IAAI,OAAO,SAAS,UAClB,OAAO,kBAAkB,eAAe,IAAI;CAE9C,OAAO,mBAAmB,8BAA8B;AAC1D;AAEA,SAAS,iCAAiC,SAA6B;CACrE,MAAM,uBAAO,IAAI,IAAoB;CACrC,KAAK,MAAM,CAAC,aAAa,OAAO,OAAO,QAAQ,QAAQ,UAAU,GAC/D,KAAK,MAAM,QAAQ,OAAO,KAAK,GAAG,QAAQ,UAAU,GAAG;EACrD,MAAM,WAAW,KAAK,IAAI,IAAI;EAC9B,IAAI,aAAa,KAAA,KAAa,aAAa,aACzC,MAAM,IAAI,MACR,8BAA8B,KAAK,mBAAmB,SAAS,SAAS,YAAY,EACtF;EAEF,KAAK,IAAI,MAAM,WAAW;CAC5B;AAEJ;AAEA,SAAS,iCAAiC,MAA+B;CAEvE,IADgB,OAAO,QAAQ,IAAI,EAAE,QAAQ,CAAC,KAAK,OAAO,MAAM,KAAA,KAAa,QAAQ,MAC3E,EAAE,WAAW,GACrB,OAAO;CAET,OAAO,eAAe,IAAI;AAC5B;AAEA,SAAS,sCACP,aACQ;CACR,MAAM,UAAoB,CAAC;CAC3B,KAAK,MAAM,CAAC,UAAU,SAAS,OAAO,QAAQ,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,OACrE,EAAE,cAAc,CAAC,CACnB,GACE,QAAQ,KACN,Y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AAI,YACF,MAAM,KAAK,wBAAwB,eAAe,UAAU,GAAG;EAGjE,MAAM,mBAAmB,MAAM,QAAQ;EAGvC,IAAI,oBAAoB,OAAO,KAAK,gBAAgB,EAAE,SAAS,GAAG;GAChE,MAAM,aAAuB,CAAC;GAC9B,KAAK,MAAM,CAAC,SAAS,WAAW,OAAO,QAAQ,gBAAgB,GAC7D,WAAW,KAAK,YAAY,mBAAmB,OAAO,EAAE,IAAI,eAAe,MAAM,GAAG;GAEtF,MAAM,KAAK,yBAAyB,WAAW,KAAK,IAAI,EAAE,GAAG;EAC/D;EAEA,OAAO,MAAM,SAAS,IAAI,KAAK,MAAM,KAAK,IAAI,EAAE,MAAM;CACxD;CAEA,mBAA6B;EAC3B,OAAO;GACL;GACA;GACA;GACA;GACA;EACF;CACF;CAEA,uBAA+B;EAC7B,OAAO;CACT;CAEA,wBAAgC;EAC9B,OAAO;CACT;CAEA,mBAAmB,kBAA0B,cAA8B;EACzE,OAAO,oDAAoD,iBAAiB,IAAI,aAAa;CAC/F;AACF"}
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@prisma-next/mongo-emitter",
3
- "version": "0.12.0-dev.40",
3
+ "version": "0.12.0-dev.42",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "description": "Mongo emitter hook for Prisma Next",
8
8
  "dependencies": {
9
- "@prisma-next/contract": "0.12.0-dev.40",
10
- "@prisma-next/emitter": "0.12.0-dev.40",
11
- "@prisma-next/framework-components": "0.12.0-dev.40",
12
- "@prisma-next/mongo-contract": "0.12.0-dev.40"
9
+ "@prisma-next/contract": "0.12.0-dev.42",
10
+ "@prisma-next/emitter": "0.12.0-dev.42",
11
+ "@prisma-next/framework-components": "0.12.0-dev.42",
12
+ "@prisma-next/mongo-contract": "0.12.0-dev.42"
13
13
  },
14
14
  "devDependencies": {
15
- "@prisma-next/test-utils": "0.12.0-dev.40",
16
- "@prisma-next/tsconfig": "0.12.0-dev.40",
17
- "@prisma-next/tsdown": "0.12.0-dev.40",
15
+ "@prisma-next/test-utils": "0.12.0-dev.42",
16
+ "@prisma-next/tsconfig": "0.12.0-dev.42",
17
+ "@prisma-next/tsdown": "0.12.0-dev.42",
18
18
  "tsdown": "0.22.0",
19
19
  "typescript": "5.9.3",
20
20
  "vitest": "4.1.6"
package/src/index.ts CHANGED
@@ -17,7 +17,7 @@ function mongoNamespaceSerializedKind(ns: Namespace): string {
17
17
  function assertUniqueMongoCollectionNames(storage: MongoStorage): void {
18
18
  const seen = new Map<string, string>();
19
19
  for (const [namespaceId, ns] of Object.entries(storage.namespaces)) {
20
- for (const coll of Object.keys(ns.collections)) {
20
+ for (const coll of Object.keys(ns.entries.collection)) {
21
21
  const existing = seen.get(coll);
22
22
  if (existing !== undefined && existing !== namespaceId) {
23
23
  throw new Error(
@@ -61,11 +61,9 @@ function generateMongoNamespacesType(namespaces: MongoStorage['namespaces']): st
61
61
  }
62
62
  const parts: string[] = [];
63
63
  for (const [name, ns] of sorted) {
64
- const collectionsType = generateMongoNamespaceCollectionsType(
65
- ns.collections as Readonly<Record<string, MongoCollection>>,
66
- );
64
+ const collectionsType = generateMongoNamespaceCollectionsType(ns.entries.collection);
67
65
  parts.push(
68
- `readonly ${serializeObjectKey(name)}: { readonly id: ${serializeValue(ns.id)}; ${mongoNamespaceSerializedKind(ns)}; readonly collections: ${collectionsType} }`,
66
+ `readonly ${serializeObjectKey(name)}: { readonly id: ${serializeValue(ns.id)}; ${mongoNamespaceSerializedKind(ns)}; readonly entries: { readonly collection: ${collectionsType} } }`,
69
67
  );
70
68
  }
71
69
  return `{ ${parts.join('; ')} }`;
@@ -133,7 +131,7 @@ export const mongoEmission = {
133
131
 
134
132
  const collectionNames = new Set<string>();
135
133
  for (const ns of Object.values(storage.namespaces)) {
136
- for (const c of Object.keys(ns.collections)) {
134
+ for (const c of Object.keys(ns.entries.collection)) {
137
135
  collectionNames.add(c);
138
136
  }
139
137
  }
@@ -175,7 +173,7 @@ export const mongoEmission = {
175
173
  } else if (collection) {
176
174
  if (!collectionNames.has(collection)) {
177
175
  throw new Error(
178
- `Model "${qualifiedName}" references collection "${collection}" which is not in storage.namespaces[..].collections`,
176
+ `Model "${qualifiedName}" references collection "${collection}" which is not in storage.namespaces[..].entries.collection`,
179
177
  );
180
178
  }
181
179
  }