@prisma-next/contract-authoring
Advanced tools
+1
-1
@@ -42,3 +42,3 @@ import { AuthoringEntityContext, AuthoringEntityTypeDescriptor, AuthoringEntityTypeNamespace } from "@prisma-next/framework-components/authoring"; | ||
| } ? Namespace extends Record<string, unknown> ? Namespace : EmptyNamespace : EmptyNamespace; | ||
| type MergeExtensionAuthoringNamespaces<ExtensionPacks, Key extends AuthoringNamespaceKey, EmptyNamespace = Record<never, never>> = ExtensionPacks extends Record<string, unknown> ? keyof ExtensionPacks extends never ? EmptyNamespace : UnionToIntersection<{ [K in keyof ExtensionPacks]: ExtractAuthoringNamespaceFromPack<ExtensionPacks[K], Key, EmptyNamespace>; }[keyof ExtensionPacks]> : EmptyNamespace; | ||
| type MergeExtensionAuthoringNamespaces<Extensions, Key extends AuthoringNamespaceKey, EmptyNamespace = Record<never, never>> = Extensions extends Record<string, unknown> ? keyof Extensions extends never ? EmptyNamespace : UnionToIntersection<{ [K in keyof Extensions]: ExtractAuthoringNamespaceFromPack<Extensions[K], Key, EmptyNamespace>; }[keyof Extensions]> : EmptyNamespace; | ||
| /** | ||
@@ -45,0 +45,0 @@ * Entity-helper shape derivation. Mirrors `FieldHelpersFromNamespace` / |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.d.mts","names":[],"sources":["../src/capability-registry.ts","../src/composed-helpers-scaffolding.ts","../src/descriptors.ts","../src/enum-type.ts"],"mappings":";;;KAAY,mBAAmB,SAAS,eAAe,SAAS;;;;;;;;;;;;;iBAchD,2BACX,SAAS,cAAc,gCACzB,eAAe;;;;;;;;;;;;;;;;;;;;KCSN,oBAAoB,MAAM,qBAAqB,OAAO,8BAChE,aAAa,cAEX;KAGQ;KAEA,kCACV,MACA,YAAY,uBACZ,kBACE;WACO,wBAAwB,KAAK,aAAa;IAEjD,kBAAkB,0BAChB,YACA,iBACF;KAEQ,kCACV,gBACA,YAAY,uBACZ,iBAAiB,wBAEjB,uBAAuB,gCACb,+BACJ,iBACA,uBAEK,WAAW,iBAAiB,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6BAC5B,oCACA,cAAc,KAAK,kDAAkD,KACzE,uDAGI,0BACJ,mBAAmB,WAAW,YAAY,YACvC,mBAAmB,WAAW,YAAY,uBACjC,mBAAmB,WAAW,YAAY,UAExD,MAAM,MACN,OAAO,UACJ,SAAS,UACX,eACD,MACA,oBAAoB,WACpB,mBAAmB,WACnB,uBAAuB;iBAET,SACd,cACA,OAAO,KAAK,oDACT,SAAS,gCACX;;;;;;;;KAqES,cAAc,mBAAmB,uBACrC,2BACA,cAAc,KAAK,uDACnB,0BACJ,mBAAmB,WAAW,YAAY,YACvC,mBAAmB,WAAW,YAAY,YAG/C,MAAM,MACN,OAAO,UACJ,SAAS,YACT,eACH,MACA,oBAAoB,WACpB,mBAAmB,WACnB,uBAAuB;;;;;;;iBAST,aAAa,mBAAmB,iBAAiB,cAAc;;;;;;iBAS/D,iBAAiB,iBAAiB,SAAS"} | ||
| {"version":3,"file":"index.d.mts","names":[],"sources":["../src/capability-registry.ts","../src/composed-helpers-scaffolding.ts","../src/descriptors.ts","../src/enum-type.ts"],"mappings":";;;KAAY,mBAAmB,SAAS,eAAe,SAAS;;;;;;;;;;;;;iBAchD,2BACX,SAAS,cAAc,gCACzB,eAAe;;;;;;;;;;;;;;;;;;;;KCSN,oBAAoB,MAAM,qBAAqB,OAAO,8BAChE,aAAa,cAEX;KAGQ;KAEA,kCACV,MACA,YAAY,uBACZ,kBACE;WACO,wBAAwB,KAAK,aAAa;IAEjD,kBAAkB,0BAChB,YACA,iBACF;KAEQ,kCACV,YACA,YAAY,uBACZ,iBAAiB,wBAEjB,mBAAmB,gCACT,2BACJ,iBACA,uBAEK,WAAW,aAAa,kCACvB,WAAW,IACX,KACA,yBAEI,eAEZ;;;;;;KAOD,6BAA6B,mBAAmB,iCACnD;WACW,UAAU,aAAa,OAAO,KAAK,iCAAiC;;EAEzE,OAAO;EAAO,QAAQ;;EACtB;EAAgB;;KAEZ,qBAAqB,mBAAmB,iCAClD,6BAA6B;EAAsB,aAAa;EAAO,c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iBAET,SACd,cACA,OAAO,KAAK,oDACT,SAAS,gCACX;;;;;;;;KAqES,cAAc,mBAAmB,uBACrC,2BACA,cAAc,KAAK,uDACnB,0BACJ,mBAAmB,WAAW,YAAY,YACvC,mBAAmB,WAAW,YAAY,YAG/C,MAAM,MACN,OAAO,UACJ,SAAS,YACT,eACH,MACA,oBAAoB,WACpB,mBAAmB,WACnB,uBAAuB;;;;;;;iBAST,aAAa,mBAAmB,iBAAiB,cAAc;;;;;;iBAS/D,iBAAiB,iBAAiB,SAAS"} |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.mjs","names":[],"sources":["../src/capability-registry.ts","../src/composed-helpers-scaffolding.ts","../src/contract-errors.ts","../src/enum-type.ts"],"sourcesContent":["export type CapabilityMatrix = Readonly<Record<string, Readonly<Record<string, boolean>>>>;\n\n/**\n * Deep-merges any number of capability matrices into a single matrix.\n *\n * Merge is purely structural — namespaces and capability flags from later\n * sources overlay earlier ones. Undefined entries are skipped so callers\n * can pass optional sources without pre-filtering.\n *\n * The helper is target-agnostic: it contains no SQL or family-specific\n * knowledge. Higher layers contribute their own capability matrices (for\n * example, a target pack, an extension pack, or the contract author's\n * own `capabilities` block) and call this helper to fold them together.\n */\nexport function mergeCapabilityMatrices(\n ...sources: ReadonlyArray<CapabilityMatrix | undefined>\n): Record<string, Record<string, boolean>> {\n const result: Record<string, Record<string, boolean>> = {};\n for (const source of sources) {\n if (source === undefined) continue;\n for (const [namespace, capabilities] of Object.entries(source)) {\n const existing = result[namespace];\n result[namespace] = existing ? { ...existing, ...capabilities } : { ...capabilities };\n }\n }\n return result;\n}\n","import type {\n AuthoringEntityContext,\n AuthoringEntityTypeDescriptor,\n AuthoringEntityTypeNamespace,\n} from '@prisma-next/framework-components/authoring';\nimport { instantiateAuthoringEntityType } from '@prisma-next/framework-components/authoring';\n\n/**\n * Family-agnostic merge / instantiation scaffolding for pack-bag-driven\n * authoring contributions. The per-namespace shape (`field`, `type`,\n * `entityTypes`) is parameterized by the discriminator key so each\n * namespace can reuse the same extractor + cross-pack merger without\n * re-deriving the template per family. Call sites flatten merged\n * `entityTypes` onto the user-facing top-level helpers surface\n * alongside the built-in `model` / `rel` (e.g. `helpers.enum(...)`).\n * The contribution data structure stays as\n * `authoring.entityTypes.<name>` — pack authors keep contributing\n * through the namespace; the composed-helpers template performs the\n * rename in the type system.\n *\n * SQL-specific composition (the `field` / `model` / `rel` / `type` core\n * helpers, the SQL index-types merge) lives in the SQL contract-ts\n * package and imports from here.\n */\n\nexport type UnionToIntersection<U> = (U extends unknown ? (value: U) => void : never) extends (\n value: infer I,\n) => void\n ? I\n : never;\n\nexport type AuthoringNamespaceKey = 'field' | 'type' | 'entityTypes';\n\nexport type ExtractAuthoringNamespaceFromPack<\n Pack,\n Key extends AuthoringNamespaceKey,\n EmptyNamespace,\n> = Pack extends {\n readonly authoring?: { readonly [P in Key]?: infer Namespace };\n}\n ? Namespace extends Record<string, unknown>\n ? Namespace\n : EmptyNamespace\n : EmptyNamespace;\n\nexport type MergeExtensionAuthoringNamespaces<\n ExtensionPacks,\n Key extends AuthoringNamespaceKey,\n EmptyNamespace = Record<never, never>,\n> =\n ExtensionPacks extends Record<string, unknown>\n ? keyof ExtensionPacks extends never\n ? EmptyNamespace\n : UnionToIntersection<\n {\n [K in keyof ExtensionPacks]: ExtractAuthoringNamespaceFromPack<\n ExtensionPacks[K],\n Key,\n EmptyNamespace\n >;\n }[keyof ExtensionPacks]\n >\n : EmptyNamespace;\n\n/**\n * Entity-helper shape derivation. Mirrors `FieldHelpersFromNamespace` /\n * `TypeHelpersFromNamespace` in the SQL package: leaf descriptors become\n * callable helpers; nested namespaces recurse.\n */\ntype ExtractFactoryInputAndOutput<Descriptor extends AuthoringEntityTypeDescriptor> =\n Descriptor['output'] extends {\n readonly factory: (input: infer Input, ctx: AuthoringEntityContext) => infer Output;\n }\n ? { input: Input; output: Output }\n : { input: unknown; output: unknown };\n\nexport type EntityHelperFunction<Descriptor extends AuthoringEntityTypeDescriptor> =\n ExtractFactoryInputAndOutput<Descriptor> extends { input: infer Input; output: infer Output }\n ? (input: Input) => Output\n : never;\n\nexport type EntityHelpersFromNamespace<Namespace> = {\n readonly [K in keyof Namespace]: Namespace[K] extends AuthoringEntityTypeDescriptor\n ? EntityHelperFunction<Namespace[K]>\n : Namespace[K] extends Record<string, unknown>\n ? EntityHelpersFromNamespace<Namespace[K]>\n : never;\n};\n\nexport interface EntityHelperFactoryOptions {\n readonly ctx: AuthoringEntityContext;\n}\n\n/**\n * Walks an entity-type namespace (after cross-pack merge) and produces the\n * runtime callable surface mirroring its tree shape. Each leaf\n * descriptor becomes a function `(input) => factory(input, ctx)`;\n * nested namespace objects recurse.\n */\nexport function createEntityHelpersFromNamespace(\n namespace: AuthoringEntityTypeNamespace,\n options: EntityHelperFactoryOptions,\n path: readonly string[] = [],\n): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(namespace)) {\n const currentPath = [...path, key];\n if (isLeafEntityDescriptor(value)) {\n result[key] = createEntityHelper(currentPath.join('.'), value, options);\n continue;\n }\n if (typeof value === 'object' && value !== null && !Array.isArray(value)) {\n result[key] = createEntityHelpersFromNamespace(\n value as AuthoringEntityTypeNamespace,\n options,\n currentPath,\n );\n }\n }\n return result;\n}\n\nfunction isLeafEntityDescriptor(value: unknown): value is AuthoringEntityTypeDescriptor {\n if (\n typeof value !== 'object' ||\n value === null ||\n (value as { kind?: unknown }).kind !== 'entity'\n ) {\n return false;\n }\n const discriminator = (value as { discriminator?: unknown }).discriminator;\n return typeof discriminator === 'string' && discriminator.length > 0;\n}\n\nfunction createEntityHelper(\n helperPath: string,\n descriptor: AuthoringEntityTypeDescriptor,\n options: EntityHelperFactoryOptions,\n): (...args: readonly unknown[]) => unknown {\n return (...args: readonly unknown[]) =>\n instantiateAuthoringEntityType(helperPath, descriptor, args, options.ctx);\n}\n","import type { StructuredError, StructuredErrorOptions } from '@prisma-next/utils/structured-error';\nimport { structuredError } from '@prisma-next/utils/structured-error';\n\nexport type ContractCode = `CONTRACT.${ContractSubcode}`;\n\ntype ContractSubcode = 'ENUM_INVALID';\n\nexport function contractError(\n code: ContractCode,\n message: string,\n options?: StructuredErrorOptions,\n): StructuredError {\n return structuredError(code, message, options);\n}\n","import type { ColumnTypeDescriptor } from '@prisma-next/framework-components/codec';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { contractError } from './contract-errors';\n\n/**\n * A single enum member produced by `member()`. The `Name` and `Value` generics\n * are preserved as literal types so `enumType()` can carry the ordered value\n * tuple in its return type. `Value` is whatever the codec dictates — its type\n * is constrained at `enumType` against the codec's input type, not here.\n */\nexport interface EnumMember<Name extends string, Value> {\n readonly name: Name;\n readonly value: Value;\n}\n\n/**\n * Declare an enum member. The `value` defaults to `name` when omitted. The\n * value is an unconstrained literal here; `enumType` constrains it against the\n * codec's input type. Both generics are preserved as literals so downstream\n * `enumType` carries the value union in its type; the value is serialized to its\n * codec string form only at lowering.\n */\nexport function member<const Name extends string>(name: Name): EnumMember<Name, Name>;\nexport function member<const Name extends string, const Value>(\n name: Name,\n value: Value,\n): EnumMember<Name, Value>;\nexport function member<const Name extends string, const Value = Name>(\n name: Name,\n value?: Value,\n): EnumMember<Name, Value> {\n return {\n name,\n value: blindCast<\n Value,\n 'overload signatures enforce Value=Name when value is omitted; default generic Value=Name makes this safe'\n >(value === undefined ? name : value),\n };\n}\n\ntype MembersToValues<Members extends readonly EnumMember<string, unknown>[]> = {\n readonly [K in keyof Members]: Members[K] extends EnumMember<string, infer V> ? V : never;\n};\n\ntype MembersToNames<Members extends readonly EnumMember<string, unknown>[]> = {\n readonly [K in keyof Members]: Members[K] extends EnumMember<infer N, unknown> ? N : never;\n};\n\ntype MembersAccessorMap<Members extends readonly EnumMember<string, unknown>[]> = {\n readonly [M in Members[number] as M['name']]: M['value'];\n};\n\n// String-key brand rather than unique symbol: tsdown inlines a fresh unique\n// symbol into each extension's .d.mts when the source package is transitive,\n// breaking nominal type identity across chunk boundaries. A string constant\n// survives .d.mts de-duplication because string equality is preserved by value.\n// Mirrors the FILTER_EXPR_BRAND pattern in mongo-query-ast/filter-expressions.ts.\nexport const ENUM_TYPE_HANDLE_BRAND = '__prismaNextEnumTypeHandle__';\n\n/** Authoring handle returned by `enumType()`. Generic over the ordered value tuple so `const Role = enumType(...)` retains literal types. */\nexport interface EnumTypeHandle<\n Name extends string = string,\n Values extends readonly unknown[] = readonly unknown[],\n Names extends readonly string[] = readonly string[],\n MembersMap extends Record<string, unknown> = Record<string, unknown>,\n> {\n /** Internal brand for lowering-pipeline detection. */\n readonly [ENUM_TYPE_HANDLE_BRAND]: true;\n\n /** The enum's declared name (used as the key in domain `enum` / storage `valueSet`). */\n readonly enumName: Name;\n\n /** codecId from the codec passed to `enumType`. */\n readonly codecId: string;\n\n /** nativeType from the codec passed to `enumType`. */\n readonly nativeType: string;\n\n /** Ordered member list for lowering (name + value pairs). */\n readonly enumMembers: readonly { readonly name: string; readonly value: Values[number] }[];\n\n /** Ordered literal value tuple. Declaration order is preserved. */\n readonly values: Values;\n\n /** Ordered literal name tuple. Declaration order is preserved. */\n readonly names: Names;\n\n /**\n * Namespaced accessor map: `Role.members.User === 'user'`.\n * Namespaced under `.members` to avoid collisions with `.values` / `.has`.\n */\n readonly members: MembersMap;\n\n /** Returns `true` if `v` is a declared member value. */\n has(v: Values[number]): boolean;\n\n /** Returns the member name for a value, or `undefined` if not found. */\n nameOf(v: Values[number]): string | undefined;\n\n /** Returns the zero-based declaration index of a value, or `-1` if not found. */\n ordinalOf(v: Values[number]): number;\n}\n\n/**\n * A codec typemap: codecId → `{ input, output }`, the same shape the query\n * lanes consume. The bound `enumType` wrappers supply the target pack's\n * typemap; the core defaults to an empty map (no codec is known), so member\n * values stay unconstrained.\n */\nexport type CodecTypeMap = Record<string, { readonly input?: unknown }>;\n\n/**\n * The application input type the codec dictates for an enum's member values:\n * looks `Codec['codecId']` up in the supplied codec typemap. When the codecId\n * isn't in the map the input is unconstrained, so any member-value literal is\n * accepted and inferred verbatim.\n */\nexport type CodecInput<\n CodecTypes extends CodecTypeMap,\n Codec extends { readonly codecId: string },\n> = Codec['codecId'] extends keyof CodecTypes\n ? CodecTypes[Codec['codecId']] extends { readonly input: infer In }\n ? In\n : unknown\n : unknown;\n\n/**\n * Declare a domain enum for use in TS-authoring contracts.\n *\n * - The codec is an explicit required argument — the `codecId` and\n * `nativeType` are taken from the passed `ColumnTypeDescriptor` (e.g.\n * `{ codecId: 'pg/text@1', nativeType: 'text' }` from a field preset\n * output or a direct inline object).\n * - `const` generics on the members spread preserve the ordered literal\n * value tuple so `Role.values` is `readonly ['user','admin']`, not\n * `string[]`.\n * - Well-formedness assertions at construction: non-empty member list;\n * unique names; unique values.\n *\n * The returned handle wires into `field.namedType(handle)` to set\n * `valueSet` refs on both the domain field and the storage column.\n *\n * @example\n * ```ts\n * const Role = enumType('Role', { codecId: 'pg/text@1', nativeType: 'text' },\n * member('User', 'user'),\n * member('Admin', 'admin'),\n * );\n * // Role.values → readonly ['user', 'admin']\n * // Role.members.User → 'user'\n * ```\n */\nexport function enumType<\n CodecTypes extends CodecTypeMap = Record<string, never>,\n const Name extends string = string,\n const Codec extends Pick<ColumnTypeDescriptor, 'codecId' | 'nativeType'> = Pick<\n ColumnTypeDescriptor,\n 'codecId' | 'nativeType'\n >,\n const Members extends readonly [\n EnumMember<string, CodecInput<CodecTypes, Codec>>,\n ...EnumMember<string, CodecInput<CodecTypes, Codec>>[],\n ] = readonly [EnumMember<string, CodecInput<CodecTypes, Codec>>],\n>(\n name: Name,\n codec: Codec,\n ...members: Members\n): EnumTypeHandle<\n Name,\n MembersToValues<[...Members]>,\n MembersToNames<[...Members]>,\n MembersAccessorMap<[...Members]>\n>;\nexport function enumType(\n name: string,\n codec: Pick<ColumnTypeDescriptor, 'codecId' | 'nativeType'>,\n ...members: EnumMember<string, unknown>[]\n): EnumTypeHandle;\nexport function enumType(\n name: string,\n codec: Pick<ColumnTypeDescriptor, 'codecId' | 'nativeType'>,\n ...members: EnumMember<string, unknown>[]\n): EnumTypeHandle {\n if (members.length === 0) {\n throw contractError(\n 'CONTRACT.ENUM_INVALID',\n `enumType(\"${name}\"): must have at least one member.`,\n { meta: { enumName: name, reason: 'no-members' } },\n );\n }\n\n const seenNames = new Set<string>();\n const seenValues = new Set<string>();\n for (const m of members) {\n if (seenNames.has(m.name)) {\n throw contractError(\n 'CONTRACT.ENUM_INVALID',\n `enumType(\"${name}\"): duplicate member name \"${m.name}\". Member names must be unique.`,\n { meta: { enumName: name, member: m.name, reason: 'duplicate-member-name' } },\n );\n }\n seenNames.add(m.name);\n\n const loweredValue = String(m.value);\n if (seenValues.has(loweredValue)) {\n throw contractError(\n 'CONTRACT.ENUM_INVALID',\n `enumType(\"${name}\"): duplicate member value \"${loweredValue}\". Member values must be unique.`,\n { meta: { enumName: name, member: loweredValue, reason: 'duplicate-member-value' } },\n );\n }\n seenValues.add(loweredValue);\n }\n\n const values = Object.freeze(members.map((m) => m.value));\n const names = Object.freeze(members.map((m) => m.name));\n const enumMembers = Object.freeze(members.map((m) => ({ name: m.name, value: m.value })));\n\n const membersAccessor = Object.freeze(Object.fromEntries(members.map((m) => [m.name, m.value])));\n\n const valueSet = new Set(values);\n const valueToName = new Map(members.map((m) => [m.value, m.name]));\n const valueToOrdinal = new Map(values.map((v, i) => [v, i]));\n\n return {\n [ENUM_TYPE_HANDLE_BRAND]: true,\n enumName: name,\n codecId: codec.codecId,\n nativeType: codec.nativeType,\n enumMembers,\n values,\n names,\n members: membersAccessor,\n has: (v: unknown) => valueSet.has(v),\n nameOf: (v: unknown) => valueToName.get(v),\n ordinalOf: (v: unknown) => valueToOrdinal.get(v) ?? -1,\n };\n}\n\n/**\n * The signature of an `enumType` whose codec typemap is already bound — the\n * shape a target-bound wrapper (e.g. `@prisma-next/postgres/contract-builder`)\n * exposes. The member values are constrained to the codec's input type drawn\n * from `CodecTypes`, while `Name`, `Codec`, and the member tuple still infer\n * from the call.\n */\nexport type BoundEnumType<CodecTypes extends CodecTypeMap> = <\n const Name extends string,\n const Codec extends Pick<ColumnTypeDescriptor, 'codecId' | 'nativeType'>,\n const Members extends readonly [\n EnumMember<string, CodecInput<CodecTypes, Codec>>,\n ...EnumMember<string, CodecInput<CodecTypes, Codec>>[],\n ],\n>(\n name: Name,\n codec: Codec,\n ...members: Members\n) => EnumTypeHandle<\n Name,\n MembersToValues<[...Members]>,\n MembersToNames<[...Members]>,\n MembersAccessorMap<[...Members]>\n>;\n\n/**\n * Bind `enumType` to a target's codec typemap. The returned function is the\n * same runtime `enumType`, retyped so member values are constrained to the\n * codec's input type. Target packages call this with their pack's\n * `ExtractCodecTypesFromPack<Pack>` to expose a codec-aware `enumType`.\n */\nexport function bindEnumType<CodecTypes extends CodecTypeMap>(): BoundEnumType<CodecTypes> {\n return enumType;\n}\n\n/**\n * Returns true when the value is an `EnumTypeHandle` produced by\n * `enumType()`. Used in the lowering pipeline to detect enum handles\n * in field state without importing the brand key at every call site.\n */\nexport function isEnumTypeHandle(value: unknown): value is EnumTypeHandle {\n return (\n typeof value === 'object' &&\n value !== null &&\n Reflect.get(value, ENUM_TYPE_HANDLE_BRAND) === true\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAcA,SAAgB,wBACd,GAAG,SACsC;CACzC,MAAM,SAAkD,CAAC;CACzD,KAAK,MAAM,UAAU,SAAS;EAC5B,IAAI,WAAW,KAAA,GAAW;EAC1B,KAAK,MAAM,CAAC,WAAW,iBAAiB,OAAO,QAAQ,MAAM,GAAG;GAC9D,MAAM,WAAW,OAAO;GACxB,OAAO,aAAa,WAAW;IAAE,GAAG;IAAU,GAAG;GAAa,IAAI,EAAE,GAAG,aAAa;EACtF;CACF;CACA,OAAO;AACT;;;;;;;;;ACyEA,SAAgB,iCACd,WACA,SACA,OAA0B,CAAC,GACF;CACzB,MAAM,SAAkC,CAAC;CACzC,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,SAAS,GAAG;EACpD,MAAM,cAAc,CAAC,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","../src/contract-errors.ts","../src/enum-type.ts"],"sourcesContent":["export type CapabilityMatrix = Readonly<Record<string, Readonly<Record<string, boolean>>>>;\n\n/**\n * Deep-merges any number of capability matrices into a single matrix.\n *\n * Merge is purely structural — namespaces and capability flags from later\n * sources overlay earlier ones. Undefined entries are skipped so callers\n * can pass optional sources without pre-filtering.\n *\n * The helper is target-agnostic: it contains no SQL or family-specific\n * knowledge. Higher layers contribute their own capability matrices (for\n * example, a target pack, an extension pack, or the contract author's\n * own `capabilities` block) and call this helper to fold them together.\n */\nexport function mergeCapabilityMatrices(\n ...sources: ReadonlyArray<CapabilityMatrix | undefined>\n): Record<string, Record<string, boolean>> {\n const result: Record<string, Record<string, boolean>> = {};\n for (const source of sources) {\n if (source === undefined) continue;\n for (const [namespace, capabilities] of Object.entries(source)) {\n const existing = result[namespace];\n result[namespace] = existing ? { ...existing, ...capabilities } : { ...capabilities };\n }\n }\n return result;\n}\n","import type {\n AuthoringEntityContext,\n AuthoringEntityTypeDescriptor,\n AuthoringEntityTypeNamespace,\n} from '@prisma-next/framework-components/authoring';\nimport { instantiateAuthoringEntityType } from '@prisma-next/framework-components/authoring';\n\n/**\n * Family-agnostic merge / instantiation scaffolding for pack-bag-driven\n * authoring contributions. The per-namespace shape (`field`, `type`,\n * `entityTypes`) is parameterized by the discriminator key so each\n * namespace can reuse the same extractor + cross-pack merger without\n * re-deriving the template per family. Call sites flatten merged\n * `entityTypes` onto the user-facing top-level helpers surface\n * alongside the built-in `model` / `rel` (e.g. `helpers.enum(...)`).\n * The contribution data structure stays as\n * `authoring.entityTypes.<name>` — pack authors keep contributing\n * through the namespace; the composed-helpers template performs the\n * rename in the type system.\n *\n * SQL-specific composition (the `field` / `model` / `rel` / `type` core\n * helpers, the SQL index-types merge) lives in the SQL contract-ts\n * package and imports from here.\n */\n\nexport type UnionToIntersection<U> = (U extends unknown ? (value: U) => void : never) extends (\n value: infer I,\n) => void\n ? I\n : never;\n\nexport type AuthoringNamespaceKey = 'field' | 'type' | 'entityTypes';\n\nexport type ExtractAuthoringNamespaceFromPack<\n Pack,\n Key extends AuthoringNamespaceKey,\n EmptyNamespace,\n> = Pack extends {\n readonly authoring?: { readonly [P in Key]?: infer Namespace };\n}\n ? Namespace extends Record<string, unknown>\n ? Namespace\n : EmptyNamespace\n : EmptyNamespace;\n\nexport type MergeExtensionAuthoringNamespaces<\n Extensions,\n Key extends AuthoringNamespaceKey,\n EmptyNamespace = Record<never, never>,\n> =\n Extensions extends Record<string, unknown>\n ? keyof Extensions extends never\n ? EmptyNamespace\n : UnionToIntersection<\n {\n [K in keyof Extensions]: ExtractAuthoringNamespaceFromPack<\n Extensions[K],\n Key,\n EmptyNamespace\n >;\n }[keyof Extensions]\n >\n : EmptyNamespace;\n\n/**\n * Entity-helper shape derivation. Mirrors `FieldHelpersFromNamespace` /\n * `TypeHelpersFromNamespace` in the SQL package: leaf descriptors become\n * callable helpers; nested namespaces recurse.\n */\ntype ExtractFactoryInputAndOutput<Descriptor extends AuthoringEntityTypeDescriptor> =\n Descriptor['output'] extends {\n readonly factory: (input: infer Input, ctx: AuthoringEntityContext) => infer Output;\n }\n ? { input: Input; output: Output }\n : { input: unknown; output: unknown };\n\nexport type EntityHelperFunction<Descriptor extends AuthoringEntityTypeDescriptor> =\n ExtractFactoryInputAndOutput<Descriptor> extends { input: infer Input; output: infer Output }\n ? (input: Input) => Output\n : never;\n\nexport type EntityHelpersFromNamespace<Namespace> = {\n readonly [K in keyof Namespace]: Namespace[K] extends AuthoringEntityTypeDescriptor\n ? EntityHelperFunction<Namespace[K]>\n : Namespace[K] extends Record<string, unknown>\n ? EntityHelpersFromNamespace<Namespace[K]>\n : never;\n};\n\nexport interface EntityHelperFactoryOptions {\n readonly ctx: AuthoringEntityContext;\n}\n\n/**\n * Walks an entity-type namespace (after cross-pack merge) and produces the\n * runtime callable surface mirroring its tree shape. Each leaf\n * descriptor becomes a function `(input) => factory(input, ctx)`;\n * nested namespace objects recurse.\n */\nexport function createEntityHelpersFromNamespace(\n namespace: AuthoringEntityTypeNamespace,\n options: EntityHelperFactoryOptions,\n path: readonly string[] = [],\n): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(namespace)) {\n const currentPath = [...path, key];\n if (isLeafEntityDescriptor(value)) {\n result[key] = createEntityHelper(currentPath.join('.'), value, options);\n continue;\n }\n if (typeof value === 'object' && value !== null && !Array.isArray(value)) {\n result[key] = createEntityHelpersFromNamespace(\n value as AuthoringEntityTypeNamespace,\n options,\n currentPath,\n );\n }\n }\n return result;\n}\n\nfunction isLeafEntityDescriptor(value: unknown): value is AuthoringEntityTypeDescriptor {\n if (\n typeof value !== 'object' ||\n value === null ||\n (value as { kind?: unknown }).kind !== 'entity'\n ) {\n return false;\n }\n const discriminator = (value as { discriminator?: unknown }).discriminator;\n return typeof discriminator === 'string' && discriminator.length > 0;\n}\n\nfunction createEntityHelper(\n helperPath: string,\n descriptor: AuthoringEntityTypeDescriptor,\n options: EntityHelperFactoryOptions,\n): (...args: readonly unknown[]) => unknown {\n return (...args: readonly unknown[]) =>\n instantiateAuthoringEntityType(helperPath, descriptor, args, options.ctx);\n}\n","import type { StructuredError, StructuredErrorOptions } from '@prisma-next/utils/structured-error';\nimport { structuredError } from '@prisma-next/utils/structured-error';\n\nexport type ContractCode = `CONTRACT.${ContractSubcode}`;\n\ntype ContractSubcode = 'ENUM_INVALID';\n\nexport function contractError(\n code: ContractCode,\n message: string,\n options?: StructuredErrorOptions,\n): StructuredError {\n return structuredError(code, message, options);\n}\n","import type { ColumnTypeDescriptor } from '@prisma-next/framework-components/codec';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { contractError } from './contract-errors';\n\n/**\n * A single enum member produced by `member()`. The `Name` and `Value` generics\n * are preserved as literal types so `enumType()` can carry the ordered value\n * tuple in its return type. `Value` is whatever the codec dictates — its type\n * is constrained at `enumType` against the codec's input type, not here.\n */\nexport interface EnumMember<Name extends string, Value> {\n readonly name: Name;\n readonly value: Value;\n}\n\n/**\n * Declare an enum member. The `value` defaults to `name` when omitted. The\n * value is an unconstrained literal here; `enumType` constrains it against the\n * codec's input type. Both generics are preserved as literals so downstream\n * `enumType` carries the value union in its type; the value is serialized to its\n * codec string form only at lowering.\n */\nexport function member<const Name extends string>(name: Name): EnumMember<Name, Name>;\nexport function member<const Name extends string, const Value>(\n name: Name,\n value: Value,\n): EnumMember<Name, Value>;\nexport function member<const Name extends string, const Value = Name>(\n name: Name,\n value?: Value,\n): EnumMember<Name, Value> {\n return {\n name,\n value: blindCast<\n Value,\n 'overload signatures enforce Value=Name when value is omitted; default generic Value=Name makes this safe'\n >(value === undefined ? name : value),\n };\n}\n\ntype MembersToValues<Members extends readonly EnumMember<string, unknown>[]> = {\n readonly [K in keyof Members]: Members[K] extends EnumMember<string, infer V> ? V : never;\n};\n\ntype MembersToNames<Members extends readonly EnumMember<string, unknown>[]> = {\n readonly [K in keyof Members]: Members[K] extends EnumMember<infer N, unknown> ? N : never;\n};\n\ntype MembersAccessorMap<Members extends readonly EnumMember<string, unknown>[]> = {\n readonly [M in Members[number] as M['name']]: M['value'];\n};\n\n// String-key brand rather than unique symbol: tsdown inlines a fresh unique\n// symbol into each extension's .d.mts when the source package is transitive,\n// breaking nominal type identity across chunk boundaries. A string constant\n// survives .d.mts de-duplication because string equality is preserved by value.\n// Mirrors the FILTER_EXPR_BRAND pattern in mongo-query-ast/filter-expressions.ts.\nexport const ENUM_TYPE_HANDLE_BRAND = '__prismaNextEnumTypeHandle__';\n\n/** Authoring handle returned by `enumType()`. Generic over the ordered value tuple so `const Role = enumType(...)` retains literal types. */\nexport interface EnumTypeHandle<\n Name extends string = string,\n Values extends readonly unknown[] = readonly unknown[],\n Names extends readonly string[] = readonly string[],\n MembersMap extends Record<string, unknown> = Record<string, unknown>,\n> {\n /** Internal brand for lowering-pipeline detection. */\n readonly [ENUM_TYPE_HANDLE_BRAND]: true;\n\n /** The enum's declared name (used as the key in domain `enum` / storage `valueSet`). */\n readonly enumName: Name;\n\n /** codecId from the codec passed to `enumType`. */\n readonly codecId: string;\n\n /** nativeType from the codec passed to `enumType`. */\n readonly nativeType: string;\n\n /** Ordered member list for lowering (name + value pairs). */\n readonly enumMembers: readonly { readonly name: string; readonly value: Values[number] }[];\n\n /** Ordered literal value tuple. Declaration order is preserved. */\n readonly values: Values;\n\n /** Ordered literal name tuple. Declaration order is preserved. */\n readonly names: Names;\n\n /**\n * Namespaced accessor map: `Role.members.User === 'user'`.\n * Namespaced under `.members` to avoid collisions with `.values` / `.has`.\n */\n readonly members: MembersMap;\n\n /** Returns `true` if `v` is a declared member value. */\n has(v: Values[number]): boolean;\n\n /** Returns the member name for a value, or `undefined` if not found. */\n nameOf(v: Values[number]): string | undefined;\n\n /** Returns the zero-based declaration index of a value, or `-1` if not found. */\n ordinalOf(v: Values[number]): number;\n}\n\n/**\n * A codec typemap: codecId → `{ input, output }`, the same shape the query\n * lanes consume. The bound `enumType` wrappers supply the target pack's\n * typemap; the core defaults to an empty map (no codec is known), so member\n * values stay unconstrained.\n */\nexport type CodecTypeMap = Record<string, { readonly input?: unknown }>;\n\n/**\n * The application input type the codec dictates for an enum's member values:\n * looks `Codec['codecId']` up in the supplied codec typemap. When the codecId\n * isn't in the map the input is unconstrained, so any member-value literal is\n * accepted and inferred verbatim.\n */\nexport type CodecInput<\n CodecTypes extends CodecTypeMap,\n Codec extends { readonly codecId: string },\n> = Codec['codecId'] extends keyof CodecTypes\n ? CodecTypes[Codec['codecId']] extends { readonly input: infer In }\n ? In\n : unknown\n : unknown;\n\n/**\n * Declare a domain enum for use in TS-authoring contracts.\n *\n * - The codec is an explicit required argument — the `codecId` and\n * `nativeType` are taken from the passed `ColumnTypeDescriptor` (e.g.\n * `{ codecId: 'pg/text@1', nativeType: 'text' }` from a field preset\n * output or a direct inline object).\n * - `const` generics on the members spread preserve the ordered literal\n * value tuple so `Role.values` is `readonly ['user','admin']`, not\n * `string[]`.\n * - Well-formedness assertions at construction: non-empty member list;\n * unique names; unique values.\n *\n * The returned handle wires into `field.namedType(handle)` to set\n * `valueSet` refs on both the domain field and the storage column.\n *\n * @example\n * ```ts\n * const Role = enumType('Role', { codecId: 'pg/text@1', nativeType: 'text' },\n * member('User', 'user'),\n * member('Admin', 'admin'),\n * );\n * // Role.values → readonly ['user', 'admin']\n * // Role.members.User → 'user'\n * ```\n */\nexport function enumType<\n CodecTypes extends CodecTypeMap = Record<string, never>,\n const Name extends string = string,\n const Codec extends Pick<ColumnTypeDescriptor, 'codecId' | 'nativeType'> = Pick<\n ColumnTypeDescriptor,\n 'codecId' | 'nativeType'\n >,\n const Members extends readonly [\n EnumMember<string, CodecInput<CodecTypes, Codec>>,\n ...EnumMember<string, CodecInput<CodecTypes, Codec>>[],\n ] = readonly [EnumMember<string, CodecInput<CodecTypes, Codec>>],\n>(\n name: Name,\n codec: Codec,\n ...members: Members\n): EnumTypeHandle<\n Name,\n MembersToValues<[...Members]>,\n MembersToNames<[...Members]>,\n MembersAccessorMap<[...Members]>\n>;\nexport function enumType(\n name: string,\n codec: Pick<ColumnTypeDescriptor, 'codecId' | 'nativeType'>,\n ...members: EnumMember<string, unknown>[]\n): EnumTypeHandle;\nexport function enumType(\n name: string,\n codec: Pick<ColumnTypeDescriptor, 'codecId' | 'nativeType'>,\n ...members: EnumMember<string, unknown>[]\n): EnumTypeHandle {\n if (members.length === 0) {\n throw contractError(\n 'CONTRACT.ENUM_INVALID',\n `enumType(\"${name}\"): must have at least one member.`,\n { meta: { enumName: name, reason: 'no-members' } },\n );\n }\n\n const seenNames = new Set<string>();\n const seenValues = new Set<string>();\n for (const m of members) {\n if (seenNames.has(m.name)) {\n throw contractError(\n 'CONTRACT.ENUM_INVALID',\n `enumType(\"${name}\"): duplicate member name \"${m.name}\". Member names must be unique.`,\n { meta: { enumName: name, member: m.name, reason: 'duplicate-member-name' } },\n );\n }\n seenNames.add(m.name);\n\n const loweredValue = String(m.value);\n if (seenValues.has(loweredValue)) {\n throw contractError(\n 'CONTRACT.ENUM_INVALID',\n `enumType(\"${name}\"): duplicate member value \"${loweredValue}\". Member values must be unique.`,\n { meta: { enumName: name, member: loweredValue, reason: 'duplicate-member-value' } },\n );\n }\n seenValues.add(loweredValue);\n }\n\n const values = Object.freeze(members.map((m) => m.value));\n const names = Object.freeze(members.map((m) => m.name));\n const enumMembers = Object.freeze(members.map((m) => ({ name: m.name, value: m.value })));\n\n const membersAccessor = Object.freeze(Object.fromEntries(members.map((m) => [m.name, m.value])));\n\n const valueSet = new Set(values);\n const valueToName = new Map(members.map((m) => [m.value, m.name]));\n const valueToOrdinal = new Map(values.map((v, i) => [v, i]));\n\n return {\n [ENUM_TYPE_HANDLE_BRAND]: true,\n enumName: name,\n codecId: codec.codecId,\n nativeType: codec.nativeType,\n enumMembers,\n values,\n names,\n members: membersAccessor,\n has: (v: unknown) => valueSet.has(v),\n nameOf: (v: unknown) => valueToName.get(v),\n ordinalOf: (v: unknown) => valueToOrdinal.get(v) ?? -1,\n };\n}\n\n/**\n * The signature of an `enumType` whose codec typemap is already bound — the\n * shape a target-bound wrapper (e.g. `@prisma-next/postgres/contract-builder`)\n * exposes. The member values are constrained to the codec's input type drawn\n * from `CodecTypes`, while `Name`, `Codec`, and the member tuple still infer\n * from the call.\n */\nexport type BoundEnumType<CodecTypes extends CodecTypeMap> = <\n const Name extends string,\n const Codec extends Pick<ColumnTypeDescriptor, 'codecId' | 'nativeType'>,\n const Members extends readonly [\n EnumMember<string, CodecInput<CodecTypes, Codec>>,\n ...EnumMember<string, CodecInput<CodecTypes, Codec>>[],\n ],\n>(\n name: Name,\n codec: Codec,\n ...members: Members\n) => EnumTypeHandle<\n Name,\n MembersToValues<[...Members]>,\n MembersToNames<[...Members]>,\n MembersAccessorMap<[...Members]>\n>;\n\n/**\n * Bind `enumType` to a target's codec typemap. The returned function is the\n * same runtime `enumType`, retyped so member values are constrained to the\n * codec's input type. Target packages call this with their pack's\n * `ExtractCodecTypesFromPack<Pack>` to expose a codec-aware `enumType`.\n */\nexport function bindEnumType<CodecTypes extends CodecTypeMap>(): BoundEnumType<CodecTypes> {\n return enumType;\n}\n\n/**\n * Returns true when the value is an `EnumTypeHandle` produced by\n * `enumType()`. Used in the lowering pipeline to detect enum handles\n * in field state without importing the brand key at every call site.\n */\nexport function isEnumTypeHandle(value: unknown): value is EnumTypeHandle {\n return (\n typeof value === 'object' &&\n value !== null &&\n Reflect.get(value, ENUM_TYPE_HANDLE_BRAND) === true\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAcA,SAAgB,wBACd,GAAG,SACsC;CACzC,MAAM,SAAkD,CAAC;CACzD,KAAK,MAAM,UAAU,SAAS;EAC5B,IAAI,WAAW,KAAA,GAAW;EAC1B,KAAK,MAAM,CAAC,WAAW,iBAAiB,OAAO,QAAQ,MAAM,GAAG;GAC9D,MAAM,WAAW,OAAO;GACxB,OAAO,aAAa,WAAW;IAAE,GAAG;IAAU,GAAG;GAAa,IAAI,EAAE,GAAG,aAAa;EACtF;CACF;CACA,OAAO;AACT;;;;;;;;;ACyEA,SAAgB,iCACd,WACA,SACA,OAA0B,CAAC,GACF;CACzB,MAAM,SAAkC,CAAC;CACzC,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,SAAS,GAAG;EACpD,MAAM,cAAc,CAAC,GAAG,MAAM,GAAG;EACjC,IAAI,uBAAuB,KAAK,GAAG;GACjC,OAAO,OAAO,mBAAmB,YAAY,KAAK,GAAG,GAAG,OAAO,OAAO;GACtE;EACF;EACA,IAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK,GACrE,OAAO,OAAO,iCACZ,OACA,SACA,WACF;CAEJ;CACA,OAAO;AACT;AAEA,SAAS,uBAAuB,OAAwD;CACtF,IACE,OAAO,UAAU,YACjB,UAAU,QACT,MAA6B,SAAS,UAEvC,OAAO;CAET,MAAM,gBAAiB,MAAsC;CAC7D,OAAO,OAAO,kBAAkB,YAAY,cAAc,SAAS;AACrE;AAEA,SAAS,mBACP,YACA,YACA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AM,kBAAkB,OAAO,OAAO,OAAO,YAAY,QAAQ,KAAK,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;CAE/F,MAAM,WAAW,IAAI,IAAI,MAAM;CAC/B,MAAM,cAAc,IAAI,IAAI,QAAQ,KAAK,MAAM,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;CACjE,MAAM,iBAAiB,IAAI,IAAI,OAAO,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;CAE3D,OAAO;GACJ,yBAAyB;EAC1B,UAAU;EACV,SAAS,MAAM;EACf,YAAY,MAAM;EAClB;EACA;EACA;EACA,SAAS;EACT,MAAM,MAAe,SAAS,IAAI,CAAC;EACnC,SAAS,MAAe,YAAY,IAAI,CAAC;EACzC,YAAY,MAAe,eAAe,IAAI,CAAC,KAAK;CACtD;AACF;;;;;;;AAiCA,SAAgB,eAA2E;CACzF,OAAO;AACT;;;;;;AAOA,SAAgB,iBAAiB,OAAyC;CACxE,OACE,OAAO,UAAU,YACjB,UAAU,QACV,QAAQ,IAAI,OAAA,8BAA6B,MAAM;AAEnD"} |
+5
-5
| { | ||
| "name": "@prisma-next/contract-authoring", | ||
| "version": "0.16.0-dev.19", | ||
| "version": "0.16.0-dev.21", | ||
| "license": "Apache-2.0", | ||
@@ -9,8 +9,8 @@ "type": "module", | ||
| "dependencies": { | ||
| "@prisma-next/framework-components": "0.16.0-dev.19", | ||
| "@prisma-next/utils": "0.16.0-dev.19" | ||
| "@prisma-next/framework-components": "0.16.0-dev.21", | ||
| "@prisma-next/utils": "0.16.0-dev.21" | ||
| }, | ||
| "devDependencies": { | ||
| "@prisma-next/tsconfig": "0.16.0-dev.19", | ||
| "@prisma-next/tsdown": "0.16.0-dev.19", | ||
| "@prisma-next/tsconfig": "0.16.0-dev.21", | ||
| "@prisma-next/tsdown": "0.16.0-dev.21", | ||
| "tsdown": "0.22.8", | ||
@@ -17,0 +17,0 @@ "typescript": "5.9.3", |
@@ -47,17 +47,17 @@ import type { | ||
| export type MergeExtensionAuthoringNamespaces< | ||
| ExtensionPacks, | ||
| Extensions, | ||
| Key extends AuthoringNamespaceKey, | ||
| EmptyNamespace = Record<never, never>, | ||
| > = | ||
| ExtensionPacks extends Record<string, unknown> | ||
| ? keyof ExtensionPacks extends never | ||
| Extensions extends Record<string, unknown> | ||
| ? keyof Extensions extends never | ||
| ? EmptyNamespace | ||
| : UnionToIntersection< | ||
| { | ||
| [K in keyof ExtensionPacks]: ExtractAuthoringNamespaceFromPack< | ||
| ExtensionPacks[K], | ||
| [K in keyof Extensions]: ExtractAuthoringNamespaceFromPack< | ||
| Extensions[K], | ||
| Key, | ||
| EmptyNamespace | ||
| >; | ||
| }[keyof ExtensionPacks] | ||
| }[keyof Extensions] | ||
| > | ||
@@ -64,0 +64,0 @@ : EmptyNamespace; |
73481
-0.1%+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed