@confect/core 10.0.0-next.22 → 10.0.0-next.24
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/CHANGELOG.md +24 -0
- package/dist/FunctionProvenance.d.ts +34 -25
- package/dist/FunctionProvenance.d.ts.map +1 -1
- package/dist/FunctionProvenance.js +13 -11
- package/dist/FunctionProvenance.js.map +1 -1
- package/dist/FunctionSpec.d.ts +12 -8
- package/dist/FunctionSpec.d.ts.map +1 -1
- package/dist/FunctionSpec.js.map +1 -1
- package/dist/GroupPath.d.ts +5 -6
- package/dist/GroupPath.d.ts.map +1 -1
- package/dist/GroupPath.js.map +1 -1
- package/dist/GroupSpec.d.ts +5 -2
- package/dist/GroupSpec.d.ts.map +1 -1
- package/dist/GroupSpec.js +2 -2
- package/dist/GroupSpec.js.map +1 -1
- package/dist/Identifier.d.ts +5 -4
- package/dist/Identifier.d.ts.map +1 -1
- package/dist/Identifier.js +5 -4
- package/dist/Identifier.js.map +1 -1
- package/dist/Lazy.d.ts +11 -12
- package/dist/Lazy.d.ts.map +1 -1
- package/dist/Lazy.js +11 -12
- package/dist/Lazy.js.map +1 -1
- package/dist/MiddlewareSpec.d.ts +27 -25
- package/dist/MiddlewareSpec.d.ts.map +1 -1
- package/dist/MiddlewareSpec.js +8 -4
- package/dist/MiddlewareSpec.js.map +1 -1
- package/dist/PaginationError.d.ts +9 -3
- package/dist/PaginationError.d.ts.map +1 -1
- package/dist/PaginationError.js +9 -3
- package/dist/PaginationError.js.map +1 -1
- package/dist/PaginationOptions.d.ts +2 -2
- package/dist/PaginationOptions.js +2 -2
- package/dist/PaginationOptions.js.map +1 -1
- package/dist/Ref.d.ts +38 -32
- package/dist/Ref.d.ts.map +1 -1
- package/dist/Ref.js +25 -25
- package/dist/Ref.js.map +1 -1
- package/dist/Refs.d.ts +1 -1
- package/dist/Refs.d.ts.map +1 -1
- package/dist/Refs.js +2 -1
- package/dist/Refs.js.map +1 -1
- package/dist/Spec.d.ts +14 -11
- package/dist/Spec.d.ts.map +1 -1
- package/dist/Spec.js +13 -8
- package/dist/Spec.js.map +1 -1
- package/dist/SystemFields.d.ts +14 -12
- package/dist/SystemFields.d.ts.map +1 -1
- package/dist/SystemFields.js +11 -9
- package/dist/SystemFields.js.map +1 -1
- package/dist/Table.d.ts +1 -0
- package/dist/Table.d.ts.map +1 -1
- package/dist/Table.js.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +6 -5
- package/src/FunctionProvenance.ts +34 -25
- package/src/FunctionSpec.ts +12 -8
- package/src/GroupPath.ts +5 -6
- package/src/GroupSpec.ts +9 -5
- package/src/Identifier.ts +5 -4
- package/src/Lazy.ts +11 -12
- package/src/MiddlewareSpec.ts +27 -25
- package/src/PaginationError.ts +9 -3
- package/src/PaginationOptions.ts +2 -2
- package/src/Ref.ts +38 -32
- package/src/Refs.ts +2 -2
- package/src/Spec.ts +49 -38
- package/src/SystemFields.ts +22 -22
- package/src/Table.ts +1 -0
package/dist/GroupSpec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GroupSpec.js","names":["MiddlewareAttachment.validateAll"],"sources":["../src/GroupSpec.ts"],"sourcesContent":["import * as MiddlewareAttachment from \"./MiddlewareAttachment\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Record from \"effect/Record\";\nimport * as Result from \"effect/Result\";\nimport type * as FunctionSpec from \"./FunctionSpec\";\nimport type * as MiddlewareSpec from \"./MiddlewareSpec\";\nimport type * as RuntimeAndFunctionType from \"./RuntimeAndFunctionType\";\nimport { validateConfectFunctionIdentifier } from \"./Identifier\";\n\nexport const TypeId = \"~@confect/core/GroupSpec\";\nexport type TypeId = typeof TypeId;\n\nexport const isGroupSpec = (u: unknown): u is AnyWithProps =>\n Predicate.hasProperty(u, TypeId);\n\nexport interface GroupSpec<\n Runtime extends RuntimeAndFunctionType.Runtime,\n Name_ extends string,\n Functions_ extends FunctionSpec.AnyWithPropsWithRuntime<Runtime> = never,\n // Subgroups may be of any runtime, independent of this group's own runtime: a\n // group is only a namespace for its children, which are otherwise-independent\n // modules. Functions, by contrast, stay homogeneous (a Node group only accepts\n // Node actions)—`addFunction` keeps the `<Runtime>` bound below.\n Groups_ extends AnyWithProps = never,\n MiddlewareSpecs_ extends MiddlewareSpec.AnyMiddlewareSpec = never,\n> {\n readonly [TypeId]: TypeId;\n readonly runtime: Runtime;\n readonly name: Name_;\n readonly functions: {\n [\n FunctionName in FunctionSpec.Name<\n FunctionSpec.AnyWithPropsWithRuntime<Runtime>\n >\n ]: FunctionSpec.WithName<Functions_, FunctionName>;\n };\n readonly groups: {\n [GroupName in Name<Groups_>]: WithName<Groups_, GroupName>;\n };\n readonly middlewareSpecs: ReadonlyArray<MiddlewareSpecs_>;\n readonly middlewareAttachments: ReadonlyArray<\n MiddlewareAttachment.MiddlewareAttachment<MiddlewareSpecs_>\n >;\n readonly \"~Functions\": Functions_;\n readonly \"~Groups\": Groups_;\n\n addFunction<Function extends FunctionSpec.AnyWithPropsWithRuntime<Runtime>>(\n function_: Function &\n MiddlewareSpec.ValidateAddedFunction<Function, MiddlewareSpecs_>,\n ): GroupSpec<\n Runtime,\n Name_,\n Functions_ | Function,\n Groups_,\n MiddlewareSpecs_\n >;\n\n addGroup<Group extends AnyWithProps>(\n group: Group,\n ): GroupSpec<Runtime, Name_, Functions_, Groups_ | Group, MiddlewareSpecs_>;\n\n addGroupAt<const AtName extends string, Group extends AnyWithProps>(\n name: AtName,\n group: Group,\n ): GroupSpec<\n Runtime,\n Name_,\n Functions_,\n Groups_ | NamedAt<Group, AtName>,\n MiddlewareSpecs_\n >;\n\n middleware<MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec>(\n middlewareSpec: MiddlewareSpec_ &\n MiddlewareSpec.ValidateAttach<\n MiddlewareSpec_,\n Functions_,\n MiddlewareSpecs_\n >,\n ...options: MiddlewareAttachment.Args<NoInfer<MiddlewareSpec_>>\n ): GroupSpec<\n Runtime,\n Name_,\n Functions_,\n Groups_,\n MiddlewareSpecs_ | MiddlewareSpec_\n >;\n}\n\nexport interface Any {\n readonly [TypeId]: TypeId;\n}\n\nexport interface AnyWithProps extends GroupSpec<\n RuntimeAndFunctionType.Runtime,\n string,\n FunctionSpec.AnyWithProps,\n AnyWithProps,\n MiddlewareSpec.AnyMiddlewareSpec\n> {}\n\nexport interface AnyWithPropsWithRuntime<\n Runtime extends RuntimeAndFunctionType.Runtime,\n> extends GroupSpec<\n Runtime,\n string,\n FunctionSpec.AnyWithPropsWithRuntime<Runtime>,\n AnyWithPropsWithRuntime<Runtime>,\n MiddlewareSpec.AnyMiddlewareSpec\n> {}\n\nexport type Name<Group extends AnyWithProps> = Group[\"name\"];\n\nexport type Functions<Group extends AnyWithProps> = Group[\"~Functions\"];\n\nexport type Groups<Group extends AnyWithProps> = Group[\"~Groups\"];\n\nexport type MiddlewareSpecs<Group extends AnyWithProps> =\n Group[\"middlewareSpecs\"][number];\n\nexport type GroupNames<Group extends AnyWithProps> = [Groups<Group>] extends [\n never,\n]\n ? never\n : Name<Groups<Group>>;\n\nexport type WithName<\n Group extends AnyWithProps,\n Name_ extends Name<Group>,\n> = Extract<Group, { readonly name: Name_ }>;\n\n/** Assigns a segment name to a leaf group created with {@link make} for typing and refs. */\nexport type NamedAt<Group extends Any, Name_ extends string> = Omit<\n Group,\n \"name\"\n> & {\n readonly name: Name_;\n};\n\nexport type AddGroups<\n Group extends AnyWithProps,\n ExtraGroups extends AnyWithProps,\n> =\n Group extends GroupSpec<\n infer Runtime,\n infer Name_,\n infer Functions_,\n infer Groups_,\n infer MiddlewareSpecs_\n >\n ? GroupSpec<\n Runtime,\n Name_,\n Functions_,\n Groups_ | ExtraGroups,\n MiddlewareSpecs_\n >\n : never;\n\nconst Proto = {\n [TypeId]: TypeId,\n\n get middlewareSpecs() {\n return this.middlewareAttachments.map(({ spec }) => spec);\n },\n\n addFunction<Function extends FunctionSpec.AnyWithProps>(\n this: Any,\n function_: Function,\n ) {\n const this_ = this as AnyWithProps;\n\n const overlapping = function_.middlewareAttachments.find(\n ({ spec: functionMiddlewareSpec }) =>\n !(\"options\" in functionMiddlewareSpec) &&\n this_.middlewareAttachments.some(\n ({ spec: groupMiddlewareSpec }) =>\n groupMiddlewareSpec.key === functionMiddlewareSpec.key,\n ),\n );\n if (overlapping !== undefined) {\n throw new Error(\n `Middleware \"${overlapping.spec.key}\" is attached to both function \"${function_.name}\" and its group`,\n );\n }\n\n return makeProto({\n runtime: this_.runtime,\n name: this_.name,\n functions: Record.set(this_.functions, function_.name, function_),\n groups: this_.groups,\n middlewareAttachments: this_.middlewareAttachments,\n });\n },\n\n addGroup<Group extends Any>(this: Any, group: Group) {\n const this_ = this as AnyWithProps;\n const group_ = group as unknown as AnyWithProps;\n\n return makeProto({\n runtime: this_.runtime,\n name: this_.name,\n functions: this_.functions,\n groups: Record.set(this_.groups, group_.name, group_),\n middlewareAttachments: this_.middlewareAttachments,\n });\n },\n\n addGroupAt<Group extends Any>(this: Any, name: string, group: Group) {\n const this_ = this as AnyWithProps;\n const group_ = group as unknown as AnyWithProps;\n\n return makeProto({\n runtime: this_.runtime,\n name: this_.name,\n functions: this_.functions,\n groups: Record.set(this_.groups, name, withName(name, group_)),\n middlewareAttachments: this_.middlewareAttachments,\n });\n },\n\n middleware<MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec>(\n this: Any,\n middlewareSpec: MiddlewareSpec_,\n ...options: ReadonlyArray<unknown>\n ) {\n const this_ = this as AnyWithProps;\n\n if (\n !(\"options\" in middlewareSpec) &&\n this_.middlewareAttachments.some(\n ({ spec }) => spec.key === middlewareSpec.key,\n )\n ) {\n throw new Error(\n `Middleware \"${middlewareSpec.key}\" is already attached to this group`,\n );\n }\n\n for (const function_ of Object.values(this_.functions)) {\n if (\n !(\"options\" in middlewareSpec) &&\n function_.middlewareAttachments.some(\n ({ spec }) => spec.key === middlewareSpec.key,\n )\n ) {\n throw new Error(\n `Middleware \"${middlewareSpec.key}\" is attached to both function \"${function_.name}\" and its group`,\n );\n }\n }\n\n return makeProto({\n runtime: this_.runtime,\n name: this_.name,\n functions: this_.functions,\n groups: this_.groups,\n middlewareAttachments: [\n ...this_.middlewareAttachments,\n { spec: middlewareSpec, options: options[0] },\n ],\n });\n },\n} satisfies ThisType<AnyWithProps>;\n\nconst makeProto = <\n Runtime extends RuntimeAndFunctionType.Runtime,\n Name_ extends string,\n Functions_ extends FunctionSpec.AnyWithPropsWithRuntime<Runtime>,\n Groups_ extends AnyWithPropsWithRuntime<Runtime>,\n MiddlewareAttachments_ extends\n ReadonlyArray<MiddlewareAttachment.MiddlewareAttachment>,\n>({\n runtime,\n name,\n functions,\n groups,\n middlewareAttachments,\n}: {\n runtime: Runtime;\n name: Name_;\n functions: Record.ReadonlyRecord<string, Functions_>;\n groups: Record.ReadonlyRecord<string, Groups_>;\n middlewareAttachments: MiddlewareAttachments_;\n}): GroupSpec<\n Runtime,\n Name_,\n Functions_,\n Groups_,\n MiddlewareAttachments_[number][\"spec\"]\n> =>\n Object.assign(Object.create(Proto), {\n runtime,\n name,\n functions,\n groups,\n middlewareAttachments,\n }) as GroupSpec<\n Runtime,\n Name_,\n Functions_,\n Groups_,\n MiddlewareAttachments_[number][\"spec\"]\n >;\n\nexport const make = (): GroupSpec<\"Convex\", \"\"> =>\n makeProto({\n runtime: \"Convex\",\n name: \"\",\n functions: Record.empty(),\n groups: Record.empty(),\n middlewareAttachments: [],\n });\n\nexport const makeAt = <const Name_ extends string>(\n name: Name_,\n): GroupSpec<\"Convex\", Name_> => {\n validateConfectFunctionIdentifier(name);\n\n return makeProto({\n runtime: \"Convex\",\n name,\n functions: Record.empty(),\n groups: Record.empty(),\n middlewareAttachments: [],\n });\n};\n\nexport const makeNode = (): GroupSpec<\"Node\", \"\"> =>\n makeProto({\n runtime: \"Node\",\n name: \"\",\n functions: Record.empty(),\n groups: Record.empty(),\n middlewareAttachments: [],\n });\n\nexport const makeNodeAt = <const Name_ extends string>(\n name: Name_,\n): GroupSpec<\"Node\", Name_> => {\n validateConfectFunctionIdentifier(name);\n\n return makeProto({\n runtime: \"Node\",\n name,\n functions: Record.empty(),\n groups: Record.empty(),\n middlewareAttachments: [],\n });\n};\n\nexport const withName = <const Name_ extends string>(\n name: Name_,\n group: Any,\n): AnyWithProps => {\n validateConfectFunctionIdentifier(name);\n const group_ = group as AnyWithProps;\n\n if (group_.name === name) {\n return group_;\n }\n\n return makeProto({\n runtime: group_.runtime,\n name,\n functions: group_.functions,\n groups: group_.groups,\n middlewareAttachments: group_.middlewareAttachments,\n });\n};\n\nexport const validateMiddleware = (\n group: AnyWithProps,\n): Result.Result<void, MiddlewareAttachment.ValidationError> =>\n Result.gen(function* () {\n yield* MiddlewareAttachment.validateAll(\n group.middlewareAttachments,\n `group \"${group.name}\"`,\n );\n for (const function_ of Object.values(group.functions)) {\n yield* MiddlewareAttachment.validateAll(\n [...group.middlewareAttachments, ...function_.middlewareAttachments],\n `function \"${function_.name}\"`,\n );\n }\n for (const child of Object.values(group.groups))\n yield* validateMiddleware(child);\n });\n"],"mappings":";;;;;;;;;;;;;;;;;AASA,MAAa,SAAS;AAGtB,MAAa,eAAe,MAC1B,UAAU,YAAY,GAAG,MAAM;AAkJjC,MAAM,QAAQ;EACX,SAAS;CAEV,IAAI,kBAAkB;EACpB,OAAO,KAAK,sBAAsB,KAAK,EAAE,WAAW,IAAI;CAC1D;CAEA,YAEE,WACA;EACA,MAAM,QAAQ;EAEd,MAAM,cAAc,UAAU,sBAAsB,MACjD,EAAE,MAAM,6BACP,EAAE,aAAa,2BACf,MAAM,sBAAsB,MACzB,EAAE,MAAM,0BACP,oBAAoB,QAAQ,uBAAuB,GACvD,CACJ;EACA,IAAI,gBAAgB,KAAA,GAClB,MAAM,IAAI,MACR,eAAe,YAAY,KAAK,IAAI,kCAAkC,UAAU,KAAK,gBACvF;EAGF,OAAO,UAAU;GACf,SAAS,MAAM;GACf,MAAM,MAAM;GACZ,WAAW,OAAO,IAAI,MAAM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ourcesContent":["import * as MiddlewareAttachment from \"./MiddlewareAttachment\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Record from \"effect/Record\";\nimport * as Result from \"effect/Result\";\nimport type * as FunctionSpec from \"./FunctionSpec\";\nimport type * as MiddlewareSpec from \"./MiddlewareSpec\";\nimport type * as RuntimeAndFunctionType from \"./RuntimeAndFunctionType\";\nimport { validateConfectFunctionIdentifier } from \"./Identifier\";\n\nexport const TypeId = \"~@confect/core/GroupSpec\";\nexport type TypeId = typeof TypeId;\n\nexport const isGroupSpec = (u: unknown): u is AnyWithProps =>\n Predicate.hasProperty(u, TypeId);\n\nexport interface GroupSpec<\n Runtime extends RuntimeAndFunctionType.Runtime,\n Name_ extends string,\n Functions_ extends FunctionSpec.AnyWithPropsWithRuntime<Runtime> = never,\n // Subgroups may be of any runtime, independent of this group's own runtime: a\n // group is only a namespace for its children, which are otherwise-independent\n // modules. Functions, by contrast, stay homogeneous (a Node group only accepts\n // Node actions)—`addFunction` keeps the `<Runtime>` bound below.\n Groups_ extends AnyWithProps = never,\n MiddlewareSpecs_ extends MiddlewareSpec.AnyMiddlewareSpec = never,\n> {\n readonly [TypeId]: TypeId;\n readonly runtime: Runtime;\n readonly name: Name_;\n readonly functions: {\n [\n FunctionName in FunctionSpec.Name<\n FunctionSpec.AnyWithPropsWithRuntime<Runtime>\n >\n ]: FunctionSpec.WithName<Functions_, FunctionName>;\n };\n readonly groups: {\n [GroupName in Name<Groups_>]: WithName<Groups_, GroupName>;\n };\n readonly middlewareSpecs: ReadonlyArray<MiddlewareSpecs_>;\n readonly middlewareAttachments: ReadonlyArray<\n MiddlewareAttachment.MiddlewareAttachment<MiddlewareSpecs_>\n >;\n readonly \"~Functions\": Functions_;\n readonly \"~Groups\": Groups_;\n\n addFunction<Function extends FunctionSpec.AnyWithPropsWithRuntime<Runtime>>(\n function_: Function &\n MiddlewareSpec.ValidateAddedFunction<Function, MiddlewareSpecs_>,\n ): GroupSpec<\n Runtime,\n Name_,\n Functions_ | Function,\n Groups_,\n MiddlewareSpecs_\n >;\n\n addGroup<Group extends AnyWithProps>(\n group: Group,\n ): GroupSpec<Runtime, Name_, Functions_, Groups_ | Group, MiddlewareSpecs_>;\n\n addGroupAt<const AtName extends string, Group extends AnyWithProps>(\n name: AtName,\n group: Group,\n ): GroupSpec<\n Runtime,\n Name_,\n Functions_,\n Groups_ | NamedAt<Group, AtName>,\n MiddlewareSpecs_\n >;\n\n middleware<MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec>(\n middlewareSpec: MiddlewareSpec_ &\n MiddlewareSpec.ValidateAttach<\n MiddlewareSpec_,\n Functions_,\n MiddlewareSpecs_\n >,\n ...options: MiddlewareAttachment.Args<NoInfer<MiddlewareSpec_>>\n ): GroupSpec<\n Runtime,\n Name_,\n Functions_,\n Groups_,\n MiddlewareSpecs_ | MiddlewareSpec_\n >;\n}\n\nexport interface Any {\n readonly [TypeId]: TypeId;\n}\n\nexport interface AnyWithProps extends GroupSpec<\n RuntimeAndFunctionType.Runtime,\n string,\n FunctionSpec.AnyWithProps,\n AnyWithProps,\n MiddlewareSpec.AnyMiddlewareSpec\n> {}\n\nexport interface AnyWithPropsWithRuntime<\n Runtime extends RuntimeAndFunctionType.Runtime,\n> extends GroupSpec<\n Runtime,\n string,\n FunctionSpec.AnyWithPropsWithRuntime<Runtime>,\n AnyWithPropsWithRuntime<Runtime>,\n MiddlewareSpec.AnyMiddlewareSpec\n> {}\n\nexport type Name<Group extends AnyWithProps> = Group[\"name\"];\n\nexport type Functions<Group extends AnyWithProps> = Group[\"~Functions\"];\n\nexport type Groups<Group extends AnyWithProps> = Group[\"~Groups\"];\n\nexport type MiddlewareSpecs<Group extends AnyWithProps> =\n Group[\"middlewareSpecs\"][number];\n\nexport type GroupNames<Group extends AnyWithProps> = [Groups<Group>] extends [\n never,\n]\n ? never\n : Name<Groups<Group>>;\n\nexport type WithName<\n Group extends AnyWithProps,\n Name_ extends Name<Group>,\n> = Extract<Group, { readonly name: Name_ }>;\n\n/**\n * Assigns a segment name to a leaf group created with {@link make} for typing\n * and refs.\n */\nexport type NamedAt<Group extends Any, Name_ extends string> = Omit<\n Group,\n \"name\"\n> & {\n readonly name: Name_;\n};\n\nexport type AddGroups<\n Group extends AnyWithProps,\n ExtraGroups extends AnyWithProps,\n> =\n Group extends GroupSpec<\n infer Runtime,\n infer Name_,\n infer Functions_,\n infer Groups_,\n infer MiddlewareSpecs_\n >\n ? GroupSpec<\n Runtime,\n Name_,\n Functions_,\n Groups_ | ExtraGroups,\n MiddlewareSpecs_\n >\n : never;\n\nconst Proto = {\n [TypeId]: TypeId,\n\n get middlewareSpecs() {\n return this.middlewareAttachments.map(({ spec }) => spec);\n },\n\n addFunction<Function extends FunctionSpec.AnyWithProps>(\n this: Any,\n function_: Function,\n ) {\n const this_ = this as AnyWithProps;\n\n const overlapping = function_.middlewareAttachments.find(\n ({ spec: functionMiddlewareSpec }) =>\n !(\"options\" in functionMiddlewareSpec) &&\n this_.middlewareAttachments.some(\n ({ spec: groupMiddlewareSpec }) =>\n groupMiddlewareSpec.key === functionMiddlewareSpec.key,\n ),\n );\n if (overlapping !== undefined) {\n throw new Error(\n `Middleware \"${overlapping.spec.key}\" is attached to both function \"${function_.name}\" and its group`,\n );\n }\n\n return makeProto({\n runtime: this_.runtime,\n name: this_.name,\n functions: Record.set(this_.functions, function_.name, function_),\n groups: this_.groups,\n middlewareAttachments: this_.middlewareAttachments,\n });\n },\n\n addGroup<Group extends Any>(this: Any, group: Group) {\n const this_ = this as AnyWithProps;\n const group_ = group as unknown as AnyWithProps;\n\n return makeProto({\n runtime: this_.runtime,\n name: this_.name,\n functions: this_.functions,\n groups: Record.set(this_.groups, group_.name, group_),\n middlewareAttachments: this_.middlewareAttachments,\n });\n },\n\n addGroupAt<Group extends Any>(this: Any, name: string, group: Group) {\n const this_ = this as AnyWithProps;\n const group_ = group as unknown as AnyWithProps;\n\n return makeProto({\n runtime: this_.runtime,\n name: this_.name,\n functions: this_.functions,\n groups: Record.set(this_.groups, name, withName(name, group_)),\n middlewareAttachments: this_.middlewareAttachments,\n });\n },\n\n middleware<MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec>(\n this: Any,\n middlewareSpec: MiddlewareSpec_,\n ...options: ReadonlyArray<unknown>\n ) {\n const this_ = this as AnyWithProps;\n\n if (\n !(\"options\" in middlewareSpec) &&\n this_.middlewareAttachments.some(\n ({ spec }) => spec.key === middlewareSpec.key,\n )\n ) {\n throw new Error(\n `Middleware \"${middlewareSpec.key}\" is already attached to this group`,\n );\n }\n\n for (const function_ of Object.values(this_.functions)) {\n if (\n !(\"options\" in middlewareSpec) &&\n function_.middlewareAttachments.some(\n ({ spec }) => spec.key === middlewareSpec.key,\n )\n ) {\n throw new Error(\n `Middleware \"${middlewareSpec.key}\" is attached to both function \"${function_.name}\" and its group`,\n );\n }\n }\n\n return makeProto({\n runtime: this_.runtime,\n name: this_.name,\n functions: this_.functions,\n groups: this_.groups,\n middlewareAttachments: [\n ...this_.middlewareAttachments,\n { spec: middlewareSpec, options: options[0] },\n ],\n });\n },\n} satisfies ThisType<AnyWithProps>;\n\nconst makeProto = <\n Runtime extends RuntimeAndFunctionType.Runtime,\n Name_ extends string,\n Functions_ extends FunctionSpec.AnyWithPropsWithRuntime<Runtime>,\n Groups_ extends AnyWithPropsWithRuntime<Runtime>,\n MiddlewareAttachments_ extends\n ReadonlyArray<MiddlewareAttachment.MiddlewareAttachment>,\n>({\n runtime,\n name,\n functions,\n groups,\n middlewareAttachments,\n}: {\n runtime: Runtime;\n name: Name_;\n functions: Record.ReadonlyRecord<string, Functions_>;\n groups: Record.ReadonlyRecord<string, Groups_>;\n middlewareAttachments: MiddlewareAttachments_;\n}): GroupSpec<\n Runtime,\n Name_,\n Functions_,\n Groups_,\n MiddlewareAttachments_[number][\"spec\"]\n> =>\n Object.assign(Object.create(Proto), {\n runtime,\n name,\n functions,\n groups,\n middlewareAttachments,\n }) as GroupSpec<\n Runtime,\n Name_,\n Functions_,\n Groups_,\n MiddlewareAttachments_[number][\"spec\"]\n >;\n\nexport const make = (): GroupSpec<\"Convex\", \"\"> =>\n makeProto({\n runtime: \"Convex\",\n name: \"\",\n functions: Record.empty(),\n groups: Record.empty(),\n middlewareAttachments: [],\n });\n\nexport const makeAt = <const Name_ extends string>(\n name: Name_,\n): GroupSpec<\"Convex\", Name_> => {\n validateConfectFunctionIdentifier(name);\n\n return makeProto({\n runtime: \"Convex\",\n name,\n functions: Record.empty(),\n groups: Record.empty(),\n middlewareAttachments: [],\n });\n};\n\nexport const makeNode = (): GroupSpec<\"Node\", \"\"> =>\n makeProto({\n runtime: \"Node\",\n name: \"\",\n functions: Record.empty(),\n groups: Record.empty(),\n middlewareAttachments: [],\n });\n\nexport const makeNodeAt = <const Name_ extends string>(\n name: Name_,\n): GroupSpec<\"Node\", Name_> => {\n validateConfectFunctionIdentifier(name);\n\n return makeProto({\n runtime: \"Node\",\n name,\n functions: Record.empty(),\n groups: Record.empty(),\n middlewareAttachments: [],\n });\n};\n\nexport function withName<const Name_ extends string, Group extends Any>(\n name: Name_,\n group: Group,\n): NamedAt<Group, Name_>;\nexport function withName(name: string, group: Any): AnyWithProps {\n validateConfectFunctionIdentifier(name);\n const group_ = group as AnyWithProps;\n\n if (group_.name === name) {\n return group_;\n }\n\n return makeProto({\n runtime: group_.runtime,\n name,\n functions: group_.functions,\n groups: group_.groups,\n middlewareAttachments: group_.middlewareAttachments,\n });\n}\n\nexport const validateMiddleware = (\n group: AnyWithProps,\n): Result.Result<void, MiddlewareAttachment.ValidationError> =>\n Result.gen(function* () {\n yield* MiddlewareAttachment.validateAll(\n group.middlewareAttachments,\n `group \"${group.name}\"`,\n );\n for (const function_ of Object.values(group.functions)) {\n yield* MiddlewareAttachment.validateAll(\n [...group.middlewareAttachments, ...function_.middlewareAttachments],\n `function \"${function_.name}\"`,\n );\n }\n for (const child of Object.values(group.groups))\n yield* validateMiddleware(child);\n });\n"],"mappings":";;;;;;;;;;;;;;;;;AAS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,SAAS,MAClB,OAAO;CAGT,OAAO,UAAU;EACf,SAAS,OAAO;EAChB;EACA,WAAW,OAAO;EAClB,QAAQ,OAAO;EACf,uBAAuB,OAAO;CAChC,CAAC;AACH;AAEA,MAAa,sBACX,UAEA,OAAO,IAAI,aAAa;CACtB,OAAOA,YACL,MAAM,uBACN,UAAU,MAAM,KAAK,EACvB;CACA,KAAK,MAAM,aAAa,OAAO,OAAO,MAAM,SAAS,GACnD,OAAOA,YACL,CAAC,GAAG,MAAM,uBAAuB,GAAG,UAAU,qBAAqB,GACnE,aAAa,UAAU,KAAK,EAC9B;CAEF,KAAK,MAAM,SAAS,OAAO,OAAO,MAAM,MAAM,GAC5C,OAAO,mBAAmB,KAAK;AACnC,CAAC"}
|
package/dist/Identifier.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
export declare const validateConfectFunctionIdentifier: (identifier: string) => void;
|
|
2
2
|
/**
|
|
3
|
-
* Validate that `identifier` is suitable as a Convex table name (and,
|
|
4
|
-
* as a `confect/tables/<identifier>.ts` filename).
|
|
3
|
+
* Validate that `identifier` is suitable as a Convex table name (and,
|
|
4
|
+
* equivalently, as a `confect/tables/<identifier>.ts` filename).
|
|
5
5
|
*
|
|
6
6
|
* Rules:
|
|
7
|
+
*
|
|
7
8
|
* - Must match `/^[A-Za-z][A-Za-z0-9_]*$/`—letter-leading, alphanumeric plus
|
|
8
9
|
* underscore. No `$` (not a valid Convex table name character); no leading
|
|
9
10
|
* `_` (Convex reserves `_<name>` for its system tables).
|
|
10
|
-
* - Must not be a reserved JavaScript identifier, so the name can also be used
|
|
11
|
-
*
|
|
11
|
+
* - Must not be a reserved JavaScript identifier, so the name can also be used as
|
|
12
|
+
* a binding name in generated code without escaping.
|
|
12
13
|
*/
|
|
13
14
|
export declare const validateConfectTableIdentifier: (identifier: string) => void;
|
|
14
15
|
//# sourceMappingURL=Identifier.d.ts.map
|
package/dist/Identifier.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Identifier.d.ts","sourceRoot":"","sources":["../src/Identifier.ts"],"names":[],"mappings":"AA4EA,eAAO,MAAM,iCAAiC,eAAgB,MAAM,SAkBnE,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"Identifier.d.ts","sourceRoot":"","sources":["../src/Identifier.ts"],"names":[],"mappings":"AA4EA,eAAO,MAAM,iCAAiC,eAAgB,MAAM,SAkBnE,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,8BAA8B,eAAgB,MAAM,SAYhE,CAAC"}
|
package/dist/Identifier.js
CHANGED
|
@@ -70,15 +70,16 @@ const validateConfectFunctionIdentifier = (identifier) => {
|
|
|
70
70
|
if (isReservedConvexFileName(identifier)) throw new Error(`Expected a valid Confect function identifier, but received: "${identifier}". "${identifier}" is a reserved Convex file name.`);
|
|
71
71
|
};
|
|
72
72
|
/**
|
|
73
|
-
* Validate that `identifier` is suitable as a Convex table name (and,
|
|
74
|
-
* as a `confect/tables/<identifier>.ts` filename).
|
|
73
|
+
* Validate that `identifier` is suitable as a Convex table name (and,
|
|
74
|
+
* equivalently, as a `confect/tables/<identifier>.ts` filename).
|
|
75
75
|
*
|
|
76
76
|
* Rules:
|
|
77
|
+
*
|
|
77
78
|
* - Must match `/^[A-Za-z][A-Za-z0-9_]*$/`—letter-leading, alphanumeric plus
|
|
78
79
|
* underscore. No `$` (not a valid Convex table name character); no leading
|
|
79
80
|
* `_` (Convex reserves `_<name>` for its system tables).
|
|
80
|
-
* - Must not be a reserved JavaScript identifier, so the name can also be used
|
|
81
|
-
*
|
|
81
|
+
* - Must not be a reserved JavaScript identifier, so the name can also be used as
|
|
82
|
+
* a binding name in generated code without escaping.
|
|
82
83
|
*/
|
|
83
84
|
const validateConfectTableIdentifier = (identifier) => {
|
|
84
85
|
if (!matchesTableNamePattern(identifier)) throw new Error(`Expected a valid Confect table identifier, but received: "${identifier}". Valid table identifiers must start with a letter and can only contain letters, numbers, and underscores. Leading underscores are reserved for Convex system tables.`);
|
package/dist/Identifier.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Identifier.js","names":[],"sources":["../src/Identifier.ts"],"sourcesContent":["const RESERVED_JS_IDENTIFIERS = new Set([\n // Reserved keywords\n \"break\",\n \"case\",\n \"catch\",\n \"class\",\n \"const\",\n \"continue\",\n \"debugger\",\n \"default\",\n \"delete\",\n \"do\",\n \"else\",\n \"export\",\n \"extends\",\n \"finally\",\n \"for\",\n \"function\",\n \"if\",\n \"import\",\n \"in\",\n \"instanceof\",\n \"new\",\n \"return\",\n \"super\",\n \"switch\",\n \"this\",\n \"throw\",\n \"try\",\n \"typeof\",\n \"var\",\n \"void\",\n \"while\",\n \"with\",\n \"yield\",\n // Future reserved keywords\n \"await\",\n \"enum\",\n \"implements\",\n \"interface\",\n \"let\",\n \"package\",\n \"private\",\n \"protected\",\n \"public\",\n \"static\",\n // Literal values that cannot be reassigned\n \"null\",\n \"true\",\n \"false\",\n // Global objects that shouldn't be shadowed\n \"undefined\",\n]);\n\nconst RESERVED_CONVEX_FILE_NAMES = new Set([\"schema\", \"http\", \"crons\"]);\n\nconst jsIdentifierRegex = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;\n\n// Stricter than `jsIdentifierRegex`: tables cannot start with `_` (Convex\n// reserves leading underscores for system tables) or `$` (Convex's table\n// naming grammar does not accept it). Letters/digits/underscore only,\n// letter-leading.\nconst tableNameRegex = /^[a-zA-Z][a-zA-Z0-9_]*$/;\n\nconst isReservedJsIdentifier = (identifier: string) =>\n RESERVED_JS_IDENTIFIERS.has(identifier);\n\nconst isReservedConvexFileName = (fileName: string) =>\n RESERVED_CONVEX_FILE_NAMES.has(fileName);\n\nconst matchesJsIdentifierPattern = (identifier: string) =>\n jsIdentifierRegex.test(identifier);\n\nconst matchesTableNamePattern = (identifier: string) =>\n tableNameRegex.test(identifier);\n\nexport const validateConfectFunctionIdentifier = (identifier: string) => {\n if (!matchesJsIdentifierPattern(identifier)) {\n throw new Error(\n `Expected a valid Confect function identifier, but received: \"${identifier}\". Valid identifiers must start with a letter, underscore, or dollar sign, and can only contain letters, numbers, underscores, or dollar signs.`,\n );\n }\n\n if (isReservedJsIdentifier(identifier)) {\n throw new Error(\n `Expected a valid Confect function identifier, but received: \"${identifier}\". \"${identifier}\" is a reserved JavaScript identifier.`,\n );\n }\n\n if (isReservedConvexFileName(identifier)) {\n throw new Error(\n `Expected a valid Confect function identifier, but received: \"${identifier}\". \"${identifier}\" is a reserved Convex file name.`,\n );\n }\n};\n\n/**\n * Validate that `identifier` is suitable as a Convex table name (and
|
|
1
|
+
{"version":3,"file":"Identifier.js","names":[],"sources":["../src/Identifier.ts"],"sourcesContent":["const RESERVED_JS_IDENTIFIERS = new Set([\n // Reserved keywords\n \"break\",\n \"case\",\n \"catch\",\n \"class\",\n \"const\",\n \"continue\",\n \"debugger\",\n \"default\",\n \"delete\",\n \"do\",\n \"else\",\n \"export\",\n \"extends\",\n \"finally\",\n \"for\",\n \"function\",\n \"if\",\n \"import\",\n \"in\",\n \"instanceof\",\n \"new\",\n \"return\",\n \"super\",\n \"switch\",\n \"this\",\n \"throw\",\n \"try\",\n \"typeof\",\n \"var\",\n \"void\",\n \"while\",\n \"with\",\n \"yield\",\n // Future reserved keywords\n \"await\",\n \"enum\",\n \"implements\",\n \"interface\",\n \"let\",\n \"package\",\n \"private\",\n \"protected\",\n \"public\",\n \"static\",\n // Literal values that cannot be reassigned\n \"null\",\n \"true\",\n \"false\",\n // Global objects that shouldn't be shadowed\n \"undefined\",\n]);\n\nconst RESERVED_CONVEX_FILE_NAMES = new Set([\"schema\", \"http\", \"crons\"]);\n\nconst jsIdentifierRegex = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;\n\n// Stricter than `jsIdentifierRegex`: tables cannot start with `_` (Convex\n// reserves leading underscores for system tables) or `$` (Convex's table\n// naming grammar does not accept it). Letters/digits/underscore only,\n// letter-leading.\nconst tableNameRegex = /^[a-zA-Z][a-zA-Z0-9_]*$/;\n\nconst isReservedJsIdentifier = (identifier: string) =>\n RESERVED_JS_IDENTIFIERS.has(identifier);\n\nconst isReservedConvexFileName = (fileName: string) =>\n RESERVED_CONVEX_FILE_NAMES.has(fileName);\n\nconst matchesJsIdentifierPattern = (identifier: string) =>\n jsIdentifierRegex.test(identifier);\n\nconst matchesTableNamePattern = (identifier: string) =>\n tableNameRegex.test(identifier);\n\nexport const validateConfectFunctionIdentifier = (identifier: string) => {\n if (!matchesJsIdentifierPattern(identifier)) {\n throw new Error(\n `Expected a valid Confect function identifier, but received: \"${identifier}\". Valid identifiers must start with a letter, underscore, or dollar sign, and can only contain letters, numbers, underscores, or dollar signs.`,\n );\n }\n\n if (isReservedJsIdentifier(identifier)) {\n throw new Error(\n `Expected a valid Confect function identifier, but received: \"${identifier}\". \"${identifier}\" is a reserved JavaScript identifier.`,\n );\n }\n\n if (isReservedConvexFileName(identifier)) {\n throw new Error(\n `Expected a valid Confect function identifier, but received: \"${identifier}\". \"${identifier}\" is a reserved Convex file name.`,\n );\n }\n};\n\n/**\n * Validate that `identifier` is suitable as a Convex table name (and,\n * equivalently, as a `confect/tables/<identifier>.ts` filename).\n *\n * Rules:\n *\n * - Must match `/^[A-Za-z][A-Za-z0-9_]*$/`—letter-leading, alphanumeric plus\n * underscore. No `$` (not a valid Convex table name character); no leading\n * `_` (Convex reserves `_<name>` for its system tables).\n * - Must not be a reserved JavaScript identifier, so the name can also be used as\n * a binding name in generated code without escaping.\n */\nexport const validateConfectTableIdentifier = (identifier: string) => {\n if (!matchesTableNamePattern(identifier)) {\n throw new Error(\n `Expected a valid Confect table identifier, but received: \"${identifier}\". Valid table identifiers must start with a letter and can only contain letters, numbers, and underscores. Leading underscores are reserved for Convex system tables.`,\n );\n }\n\n if (isReservedJsIdentifier(identifier)) {\n throw new Error(\n `Expected a valid Confect table identifier, but received: \"${identifier}\". \"${identifier}\" is a reserved JavaScript identifier.`,\n );\n }\n};\n"],"mappings":";;;;;;AAAA,MAAM,0CAA0B,IAAI,IAAI;CAEtC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CAEA;AACF,CAAC;AAED,MAAM,6CAA6B,IAAI,IAAI;CAAC;CAAU;CAAQ;AAAO,CAAC;AAEtE,MAAM,oBAAoB;AAM1B,MAAM,iBAAiB;AAEvB,MAAM,0BAA0B,eAC9B,wBAAwB,IAAI,UAAU;AAExC,MAAM,4BAA4B,aAChC,2BAA2B,IAAI,QAAQ;AAEzC,MAAM,8BAA8B,eAClC,kBAAkB,KAAK,UAAU;AAEnC,MAAM,2BAA2B,eAC/B,eAAe,KAAK,UAAU;AAEhC,MAAa,qCAAqC,eAAuB;CACvE,IAAI,CAAC,2BAA2B,UAAU,GACxC,MAAM,IAAI,MACR,gEAAgE,WAAW,gJAC7E;CAGF,IAAI,uBAAuB,UAAU,GACnC,MAAM,IAAI,MACR,gEAAgE,WAAW,MAAM,WAAW,uCAC9F;CAGF,IAAI,yBAAyB,UAAU,GACrC,MAAM,IAAI,MACR,gEAAgE,WAAW,MAAM,WAAW,kCAC9F;AAEJ;;;;;;;;;;;;;AAcA,MAAa,kCAAkC,eAAuB;CACpE,IAAI,CAAC,wBAAwB,UAAU,GACrC,MAAM,IAAI,MACR,6DAA6D,WAAW,uKAC1E;CAGF,IAAI,uBAAuB,UAAU,GACnC,MAAM,IAAI,MACR,6DAA6D,WAAW,MAAM,WAAW,uCAC3F;AAEJ"}
|
package/dist/Lazy.d.ts
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Install a lazy memoised property on `target`. The first access runs
|
|
3
|
-
* `compute()` and replaces the getter with a plain, non-writable data
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* observably indistinguishable.
|
|
3
|
+
* `compute()` and replaces the getter with a plain, non-writable data property
|
|
4
|
+
* whose value is the computed result. Subsequent accesses hit the V8 fast path
|
|
5
|
+
* for own data properties—no function call, identical returned reference—so
|
|
6
|
+
* first and second-and-subsequent accesses are observably indistinguishable.
|
|
8
7
|
*
|
|
9
|
-
* The replacement property is `enumerable: true` so the lazy property
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* forcing the computation.
|
|
8
|
+
* The replacement property is `enumerable: true` so the lazy property still
|
|
9
|
+
* participates in `Object.keys`/`JSON.stringify` after it materialises,
|
|
10
|
+
* matching the shape of a plain data property. The property is also
|
|
11
|
+
* `enumerable` before materialising, so presence checks (`"key" in target`,
|
|
12
|
+
* `Object.hasOwn(target, key)`) observe it without forcing the computation.
|
|
15
13
|
*
|
|
16
14
|
* This is the single shared implementation consumed across packages (e.g.
|
|
17
|
-
* `@confect/core`'s lazy `FunctionSpec` schemas and lazy `Table`
|
|
15
|
+
* `@confect/core`'s lazy `FunctionSpec` schemas and lazy `Table`
|
|
16
|
+
* `Fields`/`Doc`), so there is no chance of the two drifting apart.
|
|
18
17
|
*/
|
|
19
18
|
export declare const defineProperty: <T extends object, K extends PropertyKey>(target: T, key: K, compute: () => unknown) => void;
|
|
20
19
|
//# sourceMappingURL=Lazy.d.ts.map
|
package/dist/Lazy.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Lazy.d.ts","sourceRoot":"","sources":["../src/Lazy.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"Lazy.d.ts","sourceRoot":"","sources":["../src/Lazy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,WAAW,UAC5D,CAAC,OACJ,CAAC,WACG,MAAM,OAAO,KACrB,IAeF,CAAC"}
|
package/dist/Lazy.js
CHANGED
|
@@ -3,21 +3,20 @@ import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
|
3
3
|
var Lazy_exports = /* @__PURE__ */ __exportAll({ defineProperty: () => defineProperty });
|
|
4
4
|
/**
|
|
5
5
|
* Install a lazy memoised property on `target`. The first access runs
|
|
6
|
-
* `compute()` and replaces the getter with a plain, non-writable data
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* observably indistinguishable.
|
|
6
|
+
* `compute()` and replaces the getter with a plain, non-writable data property
|
|
7
|
+
* whose value is the computed result. Subsequent accesses hit the V8 fast path
|
|
8
|
+
* for own data properties—no function call, identical returned reference—so
|
|
9
|
+
* first and second-and-subsequent accesses are observably indistinguishable.
|
|
11
10
|
*
|
|
12
|
-
* The replacement property is `enumerable: true` so the lazy property
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* forcing the computation.
|
|
11
|
+
* The replacement property is `enumerable: true` so the lazy property still
|
|
12
|
+
* participates in `Object.keys`/`JSON.stringify` after it materialises,
|
|
13
|
+
* matching the shape of a plain data property. The property is also
|
|
14
|
+
* `enumerable` before materialising, so presence checks (`"key" in target`,
|
|
15
|
+
* `Object.hasOwn(target, key)`) observe it without forcing the computation.
|
|
18
16
|
*
|
|
19
17
|
* This is the single shared implementation consumed across packages (e.g.
|
|
20
|
-
* `@confect/core`'s lazy `FunctionSpec` schemas and lazy `Table`
|
|
18
|
+
* `@confect/core`'s lazy `FunctionSpec` schemas and lazy `Table`
|
|
19
|
+
* `Fields`/`Doc`), so there is no chance of the two drifting apart.
|
|
21
20
|
*/
|
|
22
21
|
const defineProperty = (target, key, compute) => {
|
|
23
22
|
Object.defineProperty(target, key, {
|
package/dist/Lazy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Lazy.js","names":[],"sources":["../src/Lazy.ts"],"sourcesContent":["/**\n * Install a lazy memoised property on `target`. The first access runs\n * `compute()` and replaces the getter with a plain, non-writable data\n *
|
|
1
|
+
{"version":3,"file":"Lazy.js","names":[],"sources":["../src/Lazy.ts"],"sourcesContent":["/**\n * Install a lazy memoised property on `target`. The first access runs\n * `compute()` and replaces the getter with a plain, non-writable data property\n * whose value is the computed result. Subsequent accesses hit the V8 fast path\n * for own data properties—no function call, identical returned reference—so\n * first and second-and-subsequent accesses are observably indistinguishable.\n *\n * The replacement property is `enumerable: true` so the lazy property still\n * participates in `Object.keys`/`JSON.stringify` after it materialises,\n * matching the shape of a plain data property. The property is also\n * `enumerable` before materialising, so presence checks (`\"key\" in target`,\n * `Object.hasOwn(target, key)`) observe it without forcing the computation.\n *\n * This is the single shared implementation consumed across packages (e.g.\n * `@confect/core`'s lazy `FunctionSpec` schemas and lazy `Table`\n * `Fields`/`Doc`), so there is no chance of the two drifting apart.\n */\nexport const defineProperty = <T extends object, K extends PropertyKey>(\n target: T,\n key: K,\n compute: () => unknown,\n): void => {\n Object.defineProperty(target, key, {\n configurable: true,\n enumerable: true,\n get(this: T) {\n const value = compute();\n Object.defineProperty(this, key, {\n value,\n writable: false,\n enumerable: true,\n configurable: false,\n });\n return value;\n },\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAiBA,MAAa,kBACX,QACA,KACA,YACS;CACT,OAAO,eAAe,QAAQ,KAAK;EACjC,cAAc;EACd,YAAY;EACZ,MAAa;GACX,MAAM,QAAQ,QAAQ;GACtB,OAAO,eAAe,MAAM,KAAK;IAC/B;IACA,UAAU;IACV,YAAY;IACZ,cAAc;GAChB,CAAC;GACD,OAAO;EACT;CACF,CAAC;AACH"}
|
package/dist/MiddlewareSpec.d.ts
CHANGED
|
@@ -25,9 +25,8 @@ export interface SuccessValue {
|
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
27
|
* The wrap-style middleware implementation shape: receives the downstream
|
|
28
|
-
* effect (the remaining middleware plus the function handler) and the
|
|
29
|
-
*
|
|
30
|
-
* place.
|
|
28
|
+
* effect (the remaining middleware plus the function handler) and the covered
|
|
29
|
+
* invocation's metadata, and returns the effect that runs in its place.
|
|
31
30
|
*
|
|
32
31
|
* Mirrors `RpcMiddleware.RpcMiddleware` in Effect.
|
|
33
32
|
*/
|
|
@@ -48,8 +47,8 @@ export interface AnyMiddlewareImpl {
|
|
|
48
47
|
(effect: Effect.Effect<SuccessValue, any, any>, context: MiddlewareOptions | MiddlewareOptions<unknown>): Effect.Effect<SuccessValue, any, any>;
|
|
49
48
|
}
|
|
50
49
|
/**
|
|
51
|
-
* The class shape produced by {@link MiddlewareSpec}. Only the static side is
|
|
52
|
-
* used—the class is a value-level carrier for the middleware's key, its
|
|
50
|
+
* The class shape produced by {@link MiddlewareSpec}. Only the static side is
|
|
51
|
+
* ever used—the class is a value-level carrier for the middleware's key, its
|
|
53
52
|
* declared functionTypes, and its (lazily-evaluated) error schema, plus the
|
|
54
53
|
* type-level `Provides`/`Error` metadata. It is deliberately not a
|
|
55
54
|
* `Context.Tag`: implementations are registered through the group `Registry`
|
|
@@ -89,8 +88,8 @@ export type WithoutOptions<MiddlewareSpec_ extends AnyMiddlewareSpec> = Middlewa
|
|
|
89
88
|
export type Key<MiddlewareSpec_ extends AnyMiddlewareSpec> = MiddlewareSpec_["key"];
|
|
90
89
|
export type Provides<MiddlewareSpec_ extends AnyMiddlewareSpec> = MiddlewareSpec_ extends AnyMiddlewareSpec ? MiddlewareSpec_["~Provides"] : never;
|
|
91
90
|
/**
|
|
92
|
-
* The services a middleware's implementation may consume from middleware
|
|
93
|
-
*
|
|
91
|
+
* The services a middleware's implementation may consume from middleware that
|
|
92
|
+
* runs earlier in the same chain (type-level only, like `provides`).
|
|
94
93
|
*/
|
|
95
94
|
export type Requires<MiddlewareSpec_ extends AnyMiddlewareSpec> = MiddlewareSpec_ extends AnyMiddlewareSpec ? MiddlewareSpec_["~Requires"] : never;
|
|
96
95
|
export type ErrorSchema<MiddlewareSpec_ extends AnyMiddlewareSpec> = MiddlewareSpec_ extends AnyMiddlewareSpec ? MiddlewareSpec_["~Error"] : never;
|
|
@@ -103,16 +102,20 @@ export type FunctionTypes<MiddlewareSpec_ extends AnyMiddlewareSpec> = Middlewar
|
|
|
103
102
|
* encode through, and the function types it may attach to.
|
|
104
103
|
*
|
|
105
104
|
* ```ts
|
|
106
|
-
* class RequireUser extends MiddlewareSpec.MiddlewareSpec<
|
|
107
|
-
*
|
|
108
|
-
*
|
|
105
|
+
* class RequireUser extends MiddlewareSpec.MiddlewareSpec<
|
|
106
|
+
* RequireUser,
|
|
107
|
+
* {
|
|
108
|
+
* provides: CurrentUser;
|
|
109
|
+
* }
|
|
110
|
+
* >()("RequireUser", {
|
|
109
111
|
* error: () => NotSignedIn,
|
|
110
112
|
* functionTypes: { query: true, mutation: true, action: false },
|
|
111
113
|
* }) {}
|
|
112
114
|
* ```
|
|
113
115
|
*
|
|
114
116
|
* The implementation is server-only and supplied separately via
|
|
115
|
-
* `MiddlewareImpl.make` (or `makeByFunctionType`/`provides`) in
|
|
117
|
+
* `MiddlewareImpl.make` (or `makeByFunctionType`/`provides`) in
|
|
118
|
+
* `@confect/server`.
|
|
116
119
|
*/
|
|
117
120
|
export declare const MiddlewareSpec: <Self, Config extends {
|
|
118
121
|
provides?: any;
|
|
@@ -140,10 +143,9 @@ export interface AttachmentError<Message extends string> {
|
|
|
140
143
|
type FunctionTypeOf<FunctionSpec_ extends FunctionSpec.AnyWithProps> = FunctionSpec_["runtimeAndFunctionType"]["functionType"];
|
|
141
144
|
type ValidationResult<Errors> = [Errors] extends [never] ? unknown : Errors;
|
|
142
145
|
/**
|
|
143
|
-
* A matching-type Convex-provenance function is rejected rather than
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
* policy hole.
|
|
146
|
+
* A matching-type Convex-provenance function is rejected rather than silently
|
|
147
|
+
* skipped: its raw handler passes through Confect untouched, so the middleware
|
|
148
|
+
* could not actually cover it, and skipping it would be a policy hole.
|
|
147
149
|
*/
|
|
148
150
|
export type ValidateFunction<FunctionSpec_ extends FunctionSpec.AnyWithProps, MiddlewareSpec_ extends AnyMiddlewareSpec> = FunctionSpec_ extends any ? MiddlewareSpec_ extends any ? FunctionSpec_ extends {
|
|
149
151
|
readonly functionProvenance: {
|
|
@@ -155,8 +157,8 @@ export type ValidateFunction<FunctionSpec_ extends FunctionSpec.AnyWithProps, Mi
|
|
|
155
157
|
}>
|
|
156
158
|
] extends [never] ? FunctionTypeOf<FunctionSpec_> extends FunctionTypes<MiddlewareSpec_> ? never : AttachmentError<`Middleware "${Key<MiddlewareSpec_>}" does not declare function type "${FunctionTypeOf<FunctionSpec_>}", the type of function "${FunctionSpec_["name"]}"`> : AttachmentError<`Middleware "${Key<MiddlewareSpec_>}" is already attached to function "${FunctionSpec_["name"]}"`> : never : never;
|
|
157
159
|
/**
|
|
158
|
-
* Attachment order is chain order, so requiring `requires` to be satisfied
|
|
159
|
-
*
|
|
160
|
+
* Attachment order is chain order, so requiring `requires` to be satisfied by
|
|
161
|
+
* already-attached middleware is exactly requiring the provider to run
|
|
160
162
|
* earlier.
|
|
161
163
|
*/
|
|
162
164
|
export type ValidateAttach<MiddlewareSpec_ extends AnyMiddlewareSpec, Functions_ extends FunctionSpec.AnyWithProps, MiddlewareSpecs_ extends AnyMiddlewareSpec> = [
|
|
@@ -173,14 +175,14 @@ type GroupOverlap<FunctionSpec_ extends FunctionSpec.AnyWithProps, MiddlewareSpe
|
|
|
173
175
|
}>
|
|
174
176
|
] extends [never] ? never : AttachmentError<`Middleware "${Key<FunctionMiddlewareSpec>}" is attached to both function "${FunctionSpec_["name"]}" and its group`> : never : never;
|
|
175
177
|
/**
|
|
176
|
-
* The parameter-type validation applied to the group spec at
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
178
|
+
* The parameter-type validation applied to the group spec at `GroupImpl.make`:
|
|
179
|
+
* every function's attached middleware must have its `requires` services
|
|
180
|
+
* provided by some middleware covering that function (the group's or the
|
|
181
|
+
* function's own). Checked here—with the group fully assembled—rather than at
|
|
182
|
+
* the spec builders, because a function-level middleware's `requires` may
|
|
183
|
+
* legitimately be satisfied by a group middleware the function spec never sees,
|
|
184
|
+
* and group attachment is declaratively order-independent with respect to
|
|
185
|
+
* `addFunction`.
|
|
184
186
|
*/
|
|
185
187
|
export type ValidateImplRequires<Functions_ extends FunctionSpec.AnyWithProps, GroupMiddlewareSpecs_ extends AnyMiddlewareSpec> = ValidationResult<Functions_ extends any ? [
|
|
186
188
|
Exclude<Requires<FunctionSpec.MiddlewareSpecs<Functions_>>, Provides<GroupMiddlewareSpecs_ | FunctionSpec.MiddlewareSpecs<Functions_>>>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MiddlewareSpec.d.ts","sourceRoot":"","sources":["../src/MiddlewareSpec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAC;AAE7C,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,KAAK,kBAAkB,MAAM,sBAAsB,CAAC;AAChE,OAAO,KAAK,KAAK,YAAY,MAAM,gBAAgB,CAAC;AAEpD,OAAO,KAAK,KAAK,sBAAsB,MAAM,0BAA0B,CAAC;AAExE,eAAO,MAAM,MAAM,kCAAkC,CAAC;AACtD,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC;AAEnC,eAAO,MAAM,gBAAgB,MAAO,OAAO,KAAG,CAAC,IAAI,iBACjB,CAAC;AAEnC,eAAO,MAAM,gBAAgB,EAAE,aAAa,CAAC,YAAY,CAIxD,CAAC;AAEF,MAAM,WAAW,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,EAChB;QAAE,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC,CAAA;KAAE,CACvD;CACF,SAAS,CAAC,KAAK,CAAC,GACjB,uBAAuB,CAAC,cAAc,CAAC,SAAS,aAAa,CAAC,eAAe,CAAC,GAC5E,OAAO,GACP,eAAe,CAAC,eAAe,GAAG,CAAC,eAAe,CAAC,qCAAqC,uBAAuB,CAAC,cAAc,CAAC,GAAG,CAAC,GACrI,eAAe,CAAC,eAAe,GAAG,CAAC,eAAe,CAAC,wCAAwC,CAAC,CAAC"}
|
package/dist/MiddlewareSpec.js
CHANGED
|
@@ -22,16 +22,20 @@ const allFunctionTypes = [
|
|
|
22
22
|
* encode through, and the function types it may attach to.
|
|
23
23
|
*
|
|
24
24
|
* ```ts
|
|
25
|
-
* class RequireUser extends MiddlewareSpec.MiddlewareSpec<
|
|
26
|
-
*
|
|
27
|
-
*
|
|
25
|
+
* class RequireUser extends MiddlewareSpec.MiddlewareSpec<
|
|
26
|
+
* RequireUser,
|
|
27
|
+
* {
|
|
28
|
+
* provides: CurrentUser;
|
|
29
|
+
* }
|
|
30
|
+
* >()("RequireUser", {
|
|
28
31
|
* error: () => NotSignedIn,
|
|
29
32
|
* functionTypes: { query: true, mutation: true, action: false },
|
|
30
33
|
* }) {}
|
|
31
34
|
* ```
|
|
32
35
|
*
|
|
33
36
|
* The implementation is server-only and supplied separately via
|
|
34
|
-
* `MiddlewareImpl.make` (or `makeByFunctionType`/`provides`) in
|
|
37
|
+
* `MiddlewareImpl.make` (or `makeByFunctionType`/`provides`) in
|
|
38
|
+
* `@confect/server`.
|
|
35
39
|
*/
|
|
36
40
|
const MiddlewareSpec = () => (key, options) => {
|
|
37
41
|
const { query, mutation, action } = options.functionTypes;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MiddlewareSpec.js","names":[],"sources":["../src/MiddlewareSpec.ts"],"sourcesContent":["import type { FunctionType, FunctionVisibility } from \"convex/server\";\nimport type * as Effect from \"effect/Effect\";\nimport * as Predicate from \"effect/Predicate\";\nimport type * as Schema from \"effect/Schema\";\nimport type { unhandled } from \"effect/Types\";\nimport type * as FunctionProvenance from \"./FunctionProvenance\";\nimport type * as FunctionSpec from \"./FunctionSpec\";\nimport * as Lazy from \"./Lazy\";\nimport type * as RuntimeAndFunctionType from \"./RuntimeAndFunctionType\";\n\nexport const TypeId = \"~@confect/core/MiddlewareSpec\";\nexport type TypeId = typeof TypeId;\n\nexport const isMiddlewareSpec = (u: unknown): u is AnyMiddlewareSpec =>\n Predicate.hasProperty(u, TypeId);\n\nexport const allFunctionTypes: ReadonlyArray<FunctionType> = [\n \"query\",\n \"mutation\",\n \"action\",\n];\n\nexport interface SupportedFunctionTypes {\n readonly query: boolean;\n readonly mutation: boolean;\n readonly action: boolean;\n}\n\n/**\n * Marker success type used by middleware to represent the handler's outcome\n * without exposing its concrete success value.\n *\n * Mirrors `RpcMiddleware.SuccessValue` in Effect.\n */\nexport interface SuccessValue {\n readonly _: unique symbol;\n}\n\n/**\n * The wrap-style middleware implementation shape: receives the downstream\n * effect (the remaining middleware plus the function handler) and the\n * covered invocation's metadata, and returns the effect that runs in its\n * place.\n *\n * Mirrors `RpcMiddleware.RpcMiddleware` in Effect.\n */\nexport interface MiddlewareImpl<Provides_, E, R, Options_ = never> {\n (\n effect: Effect.Effect<SuccessValue, E | unhandled, Provides_>,\n context: MiddlewareOptions<Options_>,\n ): Effect.Effect<SuccessValue, E | unhandled, R>;\n}\n\nexport type MiddlewareOptions<Options_ = never> = {\n readonly invocation: {\n readonly name: string;\n readonly functionType: FunctionType;\n readonly functionVisibility: FunctionVisibility;\n readonly args: unknown;\n };\n} & ([Options_] extends [never] ? unknown : { readonly options: Options_ });\n\nexport interface AnyMiddlewareImpl {\n (\n effect: Effect.Effect<SuccessValue, any, any>,\n context: MiddlewareOptions | MiddlewareOptions<unknown>,\n ): Effect.Effect<SuccessValue, any, any>;\n}\n\n/**\n * The class shape produced by {@link MiddlewareSpec}. Only the static side is ever\n * used—the class is a value-level carrier for the middleware's key, its\n * declared functionTypes, and its (lazily-evaluated) error schema, plus the\n * type-level `Provides`/`Error` metadata. It is deliberately not a\n * `Context.Tag`: implementations are registered through the group `Registry`\n * (like `FunctionImpl`s), not resolved from a Layer context.\n */\nexport interface MiddlewareSpec<\n in out Self,\n Key_ extends string,\n Provides_,\n Requires_,\n ErrorSchema_ extends Schema.Codec<any, any>,\n FunctionTypes_ extends FunctionType,\n OptionsSchema_ extends Schema.Schema<any> = never,\n> {\n new (_: never): {\n readonly [TypeId]: TypeId;\n readonly key: Key_;\n };\n readonly [TypeId]: TypeId;\n readonly key: Key_;\n readonly functionTypes: SupportedFunctionTypes;\n readonly error?: ErrorSchema_;\n readonly options?: OptionsSchema_;\n readonly \"~Provides\": Provides_;\n readonly \"~Requires\": Requires_;\n readonly \"~Error\": ErrorSchema_;\n readonly \"~FunctionTypes\": FunctionTypes_;\n readonly \"~Self\": Self;\n readonly \"~Options\": OptionsSchema_;\n}\n\nexport interface AnyMiddlewareSpec {\n readonly [TypeId]: TypeId;\n readonly key: string;\n readonly functionTypes: SupportedFunctionTypes;\n readonly error?: Schema.Codec<any, any>;\n readonly options?: Schema.Schema<any>;\n readonly \"~Provides\": any;\n readonly \"~Requires\": any;\n readonly \"~Error\": any;\n readonly \"~FunctionTypes\": FunctionType;\n readonly \"~Options\": any;\n}\n\nexport type Options<MiddlewareSpec_ extends AnyMiddlewareSpec> =\n MiddlewareSpec_[\"~Options\"][\"Type\"];\n\nexport type WithoutOptions<MiddlewareSpec_ extends AnyMiddlewareSpec> =\n MiddlewareSpec_ extends AnyMiddlewareSpec\n ? [MiddlewareSpec_[\"~Options\"]] extends [never]\n ? MiddlewareSpec_\n : never\n : never;\n\nexport type Key<MiddlewareSpec_ extends AnyMiddlewareSpec> =\n MiddlewareSpec_[\"key\"];\n\nexport type Provides<MiddlewareSpec_ extends AnyMiddlewareSpec> =\n MiddlewareSpec_ extends AnyMiddlewareSpec\n ? MiddlewareSpec_[\"~Provides\"]\n : never;\n\n/**\n * The services a middleware's implementation may consume from middleware\n * that runs earlier in the same chain (type-level only, like `provides`).\n */\nexport type Requires<MiddlewareSpec_ extends AnyMiddlewareSpec> =\n MiddlewareSpec_ extends AnyMiddlewareSpec\n ? MiddlewareSpec_[\"~Requires\"]\n : never;\n\nexport type ErrorSchema<MiddlewareSpec_ extends AnyMiddlewareSpec> =\n MiddlewareSpec_ extends AnyMiddlewareSpec ? MiddlewareSpec_[\"~Error\"] : never;\n\nexport type Error<MiddlewareSpec_ extends AnyMiddlewareSpec> =\n MiddlewareSpec_ extends AnyMiddlewareSpec\n ? MiddlewareSpec_[\"~Error\"][\"Type\"]\n : never;\n\nexport type EncodedError<MiddlewareSpec_ extends AnyMiddlewareSpec> =\n MiddlewareSpec_ extends AnyMiddlewareSpec\n ? MiddlewareSpec_[\"~Error\"][\"Encoded\"]\n : never;\n\nexport type FunctionTypes<MiddlewareSpec_ extends AnyMiddlewareSpec> =\n MiddlewareSpec_ extends AnyMiddlewareSpec\n ? MiddlewareSpec_[\"~FunctionTypes\"]\n : never;\n\n/**\n * Declare a middleware's client-safe interface: its identifying key, the\n * service it provides to downstream handlers, the error schema its failures\n * encode through, and the function types it may attach to.\n *\n * ```ts\n * class RequireUser extends MiddlewareSpec.MiddlewareSpec<RequireUser, {\n * provides: CurrentUser\n * }>()(\"RequireUser\", {\n * error: () => NotSignedIn,\n * functionTypes: { query: true, mutation: true, action: false },\n * }) {}\n * ```\n *\n * The implementation is server-only and supplied separately via\n * `MiddlewareImpl.make` (or `makeByFunctionType`/`provides`) in `@confect/server`.\n */\nexport const MiddlewareSpec =\n <Self, Config extends { provides?: any; requires?: any } = {}>() =>\n <\n const Key_ extends string,\n const FunctionTypesConfig_ extends SupportedFunctionTypes,\n ErrorSchema_ extends Schema.Codec<any, any> = never,\n OptionsSchema_ extends Schema.Schema<any> = never,\n >(\n key: Key_,\n options: {\n readonly error?: () => ErrorSchema_;\n readonly options?: () => OptionsSchema_;\n readonly functionTypes: FunctionTypesConfig_ &\n ValidateFunctionTypesConfig<FunctionTypesConfig_>;\n },\n ): MiddlewareSpec<\n Self,\n Key_,\n \"provides\" extends keyof Config ? Config[\"provides\"] : never,\n \"requires\" extends keyof Config ? Config[\"requires\"] : never,\n ErrorSchema_,\n FunctionTypesFromConfig<FunctionTypesConfig_>,\n OptionsSchema_\n > => {\n const { query, mutation, action } = options.functionTypes;\n if (!query && !mutation && !action) {\n throw new Error(\n `Middleware \"${key}\" must declare at least one function type`,\n );\n }\n\n function MiddlewareSpecClass() {}\n const class_ = MiddlewareSpecClass as any;\n class_[TypeId] = TypeId;\n class_.key = key;\n class_.functionTypes = {\n query,\n mutation,\n action,\n } satisfies SupportedFunctionTypes;\n if (options.error !== undefined) {\n Lazy.defineProperty(class_, \"error\", options.error);\n }\n if (options.options !== undefined) {\n Lazy.defineProperty(class_, \"options\", options.options);\n }\n return class_;\n };\n\ntype FunctionTypesFromConfig<Config extends SupportedFunctionTypes> = {\n [K in FunctionType]: Config[K] extends true ? K : never;\n}[FunctionType];\n\ntype ValidateFunctionTypesConfig<Config extends SupportedFunctionTypes> =\n ValidationResult<\n | {\n [K in keyof Config]: boolean extends Config[K]\n ? AttachmentError<`Function type flag \"${K & string}\" must be a literal \\`true\\` or \\`false\\`, not a computed \\`boolean\\``>\n : never;\n }[keyof Config]\n | ([FunctionTypesFromConfig<Config>] extends [never]\n ? AttachmentError<`A middleware must declare at least one function type`>\n : never)\n >;\n\nexport const errorSchemas = (\n middlewareSpecs: ReadonlyArray<AnyMiddlewareSpec>,\n): ReadonlyArray<Schema.Codec<any, any>> =>\n middlewareSpecs.flatMap((middlewareSpec) =>\n \"error\" in middlewareSpec && middlewareSpec.error !== undefined\n ? [middlewareSpec.error]\n : [],\n );\n\n/**\n * A branded, unconstructible type carrying a spec-authoring error message.\n * Surfaced as (part of) a parameter type so the diagnostic names the exact\n * problem at the `.middleware()`/`.addFunction()` call site.\n */\nexport interface AttachmentError<Message extends string> {\n readonly \"~@confect/core/MiddlewareSpec/AttachmentError\": Message;\n}\n\ntype FunctionTypeOf<FunctionSpec_ extends FunctionSpec.AnyWithProps> =\n FunctionSpec_[\"runtimeAndFunctionType\"][\"functionType\"];\n\ntype ValidationResult<Errors> = [Errors] extends [never] ? unknown : Errors;\n\n/**\n * A matching-type Convex-provenance function is rejected rather than\n * silently skipped: its raw handler passes through Confect untouched, so\n * the middleware could not actually cover it, and skipping it would be a\n * policy hole.\n */\nexport type ValidateFunction<\n FunctionSpec_ extends FunctionSpec.AnyWithProps,\n MiddlewareSpec_ extends AnyMiddlewareSpec,\n> = FunctionSpec_ extends any\n ? MiddlewareSpec_ extends any\n ? FunctionSpec_ extends {\n readonly functionProvenance: { readonly _tag: \"Convex\" };\n }\n ? FunctionTypeOf<FunctionSpec_> extends FunctionTypes<MiddlewareSpec_>\n ? AttachmentError<`Convex-provenance function \"${FunctionSpec_[\"name\"]}\" cannot be covered by middleware \"${Key<MiddlewareSpec_>}\"—attach middleware only to groups whose matching-type functions are all Confect-provenance`>\n : never\n : [\n Extract<\n FunctionSpec.MiddlewareSpecs<FunctionSpec_>,\n { readonly key: Key<WithoutOptions<MiddlewareSpec_>> }\n >,\n ] extends [never]\n ? FunctionTypeOf<FunctionSpec_> extends FunctionTypes<MiddlewareSpec_>\n ? never\n : AttachmentError<`Middleware \"${Key<MiddlewareSpec_>}\" does not declare function type \"${FunctionTypeOf<FunctionSpec_>}\", the type of function \"${FunctionSpec_[\"name\"]}\"`>\n : AttachmentError<`Middleware \"${Key<MiddlewareSpec_>}\" is already attached to function \"${FunctionSpec_[\"name\"]}\"`>\n : never\n : never;\n\n/**\n * Attachment order is chain order, so requiring `requires` to be satisfied\n * by already-attached middleware is exactly requiring the provider to run\n * earlier.\n */\nexport type ValidateAttach<\n MiddlewareSpec_ extends AnyMiddlewareSpec,\n Functions_ extends FunctionSpec.AnyWithProps,\n MiddlewareSpecs_ extends AnyMiddlewareSpec,\n> = [\n Extract<\n MiddlewareSpecs_,\n { readonly key: Key<WithoutOptions<MiddlewareSpec_>> }\n >,\n] extends [never]\n ? [Exclude<Requires<MiddlewareSpec_>, Provides<MiddlewareSpecs_>>] extends [\n never,\n ]\n ? ValidationResult<ValidateFunction<Functions_, MiddlewareSpec_>>\n : AttachmentError<`Middleware \"${Key<MiddlewareSpec_>}\" requires services that no middleware attached earlier to this group provides—attach the providing middleware first`>\n : AttachmentError<`Middleware \"${Key<MiddlewareSpec_>}\" is already attached to this group`>;\n\nexport type ValidateAddedFunction<\n FunctionSpec_ extends FunctionSpec.AnyWithProps,\n MiddlewareSpecs_ extends AnyMiddlewareSpec,\n> = [MiddlewareSpecs_] extends [never]\n ? unknown\n : ValidationResult<\n | ValidateFunction<FunctionSpec_, MiddlewareSpecs_>\n | GroupOverlap<FunctionSpec_, MiddlewareSpecs_>\n >;\n\ntype GroupOverlap<\n FunctionSpec_ extends FunctionSpec.AnyWithProps,\n MiddlewareSpecs_ extends AnyMiddlewareSpec,\n> =\n FunctionSpec.MiddlewareSpecs<FunctionSpec_> extends infer FunctionMiddlewareSpec\n ? FunctionMiddlewareSpec extends AnyMiddlewareSpec\n ? [\n Extract<\n MiddlewareSpecs_,\n { readonly key: Key<WithoutOptions<FunctionMiddlewareSpec>> }\n >,\n ] extends [never]\n ? never\n : AttachmentError<`Middleware \"${Key<FunctionMiddlewareSpec>}\" is attached to both function \"${FunctionSpec_[\"name\"]}\" and its group`>\n : never\n : never;\n\n/**\n * The parameter-type validation applied to the group spec at\n * `GroupImpl.make`: every function's attached middleware must have its\n * `requires` services provided by some middleware covering that function\n * (the group's or the function's own). Checked here—with the group fully\n * assembled—rather than at the spec builders, because a function-level\n * middleware's `requires` may legitimately be satisfied by a group\n * middleware the function spec never sees, and group attachment is\n * declaratively order-independent with respect to `addFunction`.\n */\nexport type ValidateImplRequires<\n Functions_ extends FunctionSpec.AnyWithProps,\n GroupMiddlewareSpecs_ extends AnyMiddlewareSpec,\n> = ValidationResult<\n Functions_ extends any\n ? [\n Exclude<\n Requires<FunctionSpec.MiddlewareSpecs<Functions_>>,\n Provides<\n GroupMiddlewareSpecs_ | FunctionSpec.MiddlewareSpecs<Functions_>\n >\n >,\n ] extends [never]\n ? never\n : AttachmentError<`Function \"${Functions_[\"name\"]}\" has middleware requiring services that no middleware covering it provides`>\n : never\n>;\n\nexport type ValidateFunctionAttach<\n MiddlewareSpec_ extends AnyMiddlewareSpec,\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionProvenance_ extends FunctionProvenance.FunctionProvenance,\n MiddlewareSpecs_ extends AnyMiddlewareSpec,\n> = FunctionProvenance_ extends { readonly _tag: \"Convex\" }\n ? AttachmentError<`Plain Convex functions cannot have middleware—their raw handlers are passed through untouched`>\n : [\n Extract<\n MiddlewareSpecs_,\n { readonly key: Key<WithoutOptions<MiddlewareSpec_>> }\n >,\n ] extends [never]\n ? RuntimeAndFunctionType_[\"functionType\"] extends FunctionTypes<MiddlewareSpec_>\n ? unknown\n : AttachmentError<`Middleware \"${Key<MiddlewareSpec_>}\" does not declare function type \"${RuntimeAndFunctionType_[\"functionType\"]}\"`>\n : AttachmentError<`Middleware \"${Key<MiddlewareSpec_>}\" is already attached to this function`>;\n"],"mappings":";;;;;;;;;;;AAUA,MAAa,SAAS;AAGtB,MAAa,oBAAoB,MAC/B,UAAU,YAAY,GAAG,MAAM;AAEjC,MAAa,mBAAgD;CAC3D;CACA;CACA;AACF;;;;;;;;;;;;;;;;;;AA8JA,MAAa,wBAQT,KACA,YAcG;CACH,MAAM,EAAE,OAAO,UAAU,WAAW,QAAQ;CAC5C,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,QAC1B,MAAM,IAAI,MACR,eAAe,IAAI,0CACrB;CAGF,SAAS,sBAAsB,CAAC;CAChC,MAAM,SAAS;CACf,OAAO,UAAU;CACjB,OAAO,MAAM;CACb,OAAO,gBAAgB;EACrB;EACA;EACA;CACF;CACA,IAAI,QAAQ,UAAU,KAAA,GACpB,eAAoB,QAAQ,SAAS,QAAQ,KAAK;CAEpD,IAAI,QAAQ,YAAY,KAAA,GACtB,eAAoB,QAAQ,WAAW,QAAQ,OAAO;CAExD,OAAO;AACT;AAkBF,MAAa,gBACX,oBAEA,gBAAgB,SAAS,mBACvB,WAAW,kBAAkB,eAAe,UAAU,KAAA,IAClD,CAAC,eAAe,KAAK,IACrB,CAAC,CACP"}
|
|
1
|
+
{"version":3,"file":"MiddlewareSpec.js","names":[],"sources":["../src/MiddlewareSpec.ts"],"sourcesContent":["import type { FunctionType, FunctionVisibility } from \"convex/server\";\nimport type * as Effect from \"effect/Effect\";\nimport * as Predicate from \"effect/Predicate\";\nimport type * as Schema from \"effect/Schema\";\nimport type { unhandled } from \"effect/Types\";\nimport type * as FunctionProvenance from \"./FunctionProvenance\";\nimport type * as FunctionSpec from \"./FunctionSpec\";\nimport * as Lazy from \"./Lazy\";\nimport type * as RuntimeAndFunctionType from \"./RuntimeAndFunctionType\";\n\nexport const TypeId = \"~@confect/core/MiddlewareSpec\";\nexport type TypeId = typeof TypeId;\n\nexport const isMiddlewareSpec = (u: unknown): u is AnyMiddlewareSpec =>\n Predicate.hasProperty(u, TypeId);\n\nexport const allFunctionTypes: ReadonlyArray<FunctionType> = [\n \"query\",\n \"mutation\",\n \"action\",\n];\n\nexport interface SupportedFunctionTypes {\n readonly query: boolean;\n readonly mutation: boolean;\n readonly action: boolean;\n}\n\n/**\n * Marker success type used by middleware to represent the handler's outcome\n * without exposing its concrete success value.\n *\n * Mirrors `RpcMiddleware.SuccessValue` in Effect.\n */\nexport interface SuccessValue {\n readonly _: unique symbol;\n}\n\n/**\n * The wrap-style middleware implementation shape: receives the downstream\n * effect (the remaining middleware plus the function handler) and the covered\n * invocation's metadata, and returns the effect that runs in its place.\n *\n * Mirrors `RpcMiddleware.RpcMiddleware` in Effect.\n */\nexport interface MiddlewareImpl<Provides_, E, R, Options_ = never> {\n (\n effect: Effect.Effect<SuccessValue, E | unhandled, Provides_>,\n context: MiddlewareOptions<Options_>,\n ): Effect.Effect<SuccessValue, E | unhandled, R>;\n}\n\nexport type MiddlewareOptions<Options_ = never> = {\n readonly invocation: {\n readonly name: string;\n readonly functionType: FunctionType;\n readonly functionVisibility: FunctionVisibility;\n readonly args: unknown;\n };\n} & ([Options_] extends [never] ? unknown : { readonly options: Options_ });\n\nexport interface AnyMiddlewareImpl {\n (\n effect: Effect.Effect<SuccessValue, any, any>,\n context: MiddlewareOptions | MiddlewareOptions<unknown>,\n ): Effect.Effect<SuccessValue, any, any>;\n}\n\n/**\n * The class shape produced by {@link MiddlewareSpec}. Only the static side is\n * ever used—the class is a value-level carrier for the middleware's key, its\n * declared functionTypes, and its (lazily-evaluated) error schema, plus the\n * type-level `Provides`/`Error` metadata. It is deliberately not a\n * `Context.Tag`: implementations are registered through the group `Registry`\n * (like `FunctionImpl`s), not resolved from a Layer context.\n */\nexport interface MiddlewareSpec<\n in out Self,\n Key_ extends string,\n Provides_,\n Requires_,\n ErrorSchema_ extends Schema.Codec<any, any>,\n FunctionTypes_ extends FunctionType,\n OptionsSchema_ extends Schema.Schema<any> = never,\n> {\n new (_: never): {\n readonly [TypeId]: TypeId;\n readonly key: Key_;\n };\n readonly [TypeId]: TypeId;\n readonly key: Key_;\n readonly functionTypes: SupportedFunctionTypes;\n readonly error?: ErrorSchema_;\n readonly options?: OptionsSchema_;\n readonly \"~Provides\": Provides_;\n readonly \"~Requires\": Requires_;\n readonly \"~Error\": ErrorSchema_;\n readonly \"~FunctionTypes\": FunctionTypes_;\n readonly \"~Self\": Self;\n readonly \"~Options\": OptionsSchema_;\n}\n\nexport interface AnyMiddlewareSpec {\n readonly [TypeId]: TypeId;\n readonly key: string;\n readonly functionTypes: SupportedFunctionTypes;\n readonly error?: Schema.Codec<any, any>;\n readonly options?: Schema.Schema<any>;\n readonly \"~Provides\": any;\n readonly \"~Requires\": any;\n readonly \"~Error\": any;\n readonly \"~FunctionTypes\": FunctionType;\n readonly \"~Options\": any;\n}\n\nexport type Options<MiddlewareSpec_ extends AnyMiddlewareSpec> =\n MiddlewareSpec_[\"~Options\"][\"Type\"];\n\nexport type WithoutOptions<MiddlewareSpec_ extends AnyMiddlewareSpec> =\n MiddlewareSpec_ extends AnyMiddlewareSpec\n ? [MiddlewareSpec_[\"~Options\"]] extends [never]\n ? MiddlewareSpec_\n : never\n : never;\n\nexport type Key<MiddlewareSpec_ extends AnyMiddlewareSpec> =\n MiddlewareSpec_[\"key\"];\n\nexport type Provides<MiddlewareSpec_ extends AnyMiddlewareSpec> =\n MiddlewareSpec_ extends AnyMiddlewareSpec\n ? MiddlewareSpec_[\"~Provides\"]\n : never;\n\n/**\n * The services a middleware's implementation may consume from middleware that\n * runs earlier in the same chain (type-level only, like `provides`).\n */\nexport type Requires<MiddlewareSpec_ extends AnyMiddlewareSpec> =\n MiddlewareSpec_ extends AnyMiddlewareSpec\n ? MiddlewareSpec_[\"~Requires\"]\n : never;\n\nexport type ErrorSchema<MiddlewareSpec_ extends AnyMiddlewareSpec> =\n MiddlewareSpec_ extends AnyMiddlewareSpec ? MiddlewareSpec_[\"~Error\"] : never;\n\nexport type Error<MiddlewareSpec_ extends AnyMiddlewareSpec> =\n MiddlewareSpec_ extends AnyMiddlewareSpec\n ? MiddlewareSpec_[\"~Error\"][\"Type\"]\n : never;\n\nexport type EncodedError<MiddlewareSpec_ extends AnyMiddlewareSpec> =\n MiddlewareSpec_ extends AnyMiddlewareSpec\n ? MiddlewareSpec_[\"~Error\"][\"Encoded\"]\n : never;\n\nexport type FunctionTypes<MiddlewareSpec_ extends AnyMiddlewareSpec> =\n MiddlewareSpec_ extends AnyMiddlewareSpec\n ? MiddlewareSpec_[\"~FunctionTypes\"]\n : never;\n\n/**\n * Declare a middleware's client-safe interface: its identifying key, the\n * service it provides to downstream handlers, the error schema its failures\n * encode through, and the function types it may attach to.\n *\n * ```ts\n * class RequireUser extends MiddlewareSpec.MiddlewareSpec<\n * RequireUser,\n * {\n * provides: CurrentUser;\n * }\n * >()(\"RequireUser\", {\n * error: () => NotSignedIn,\n * functionTypes: { query: true, mutation: true, action: false },\n * }) {}\n * ```\n *\n * The implementation is server-only and supplied separately via\n * `MiddlewareImpl.make` (or `makeByFunctionType`/`provides`) in\n * `@confect/server`.\n */\nexport const MiddlewareSpec =\n <Self, Config extends { provides?: any; requires?: any } = {}>() =>\n <\n const Key_ extends string,\n const FunctionTypesConfig_ extends SupportedFunctionTypes,\n ErrorSchema_ extends Schema.Codec<any, any> = never,\n OptionsSchema_ extends Schema.Schema<any> = never,\n >(\n key: Key_,\n options: {\n readonly error?: () => ErrorSchema_;\n readonly options?: () => OptionsSchema_;\n readonly functionTypes: FunctionTypesConfig_ &\n ValidateFunctionTypesConfig<FunctionTypesConfig_>;\n },\n ): MiddlewareSpec<\n Self,\n Key_,\n \"provides\" extends keyof Config ? Config[\"provides\"] : never,\n \"requires\" extends keyof Config ? Config[\"requires\"] : never,\n ErrorSchema_,\n FunctionTypesFromConfig<FunctionTypesConfig_>,\n OptionsSchema_\n > => {\n const { query, mutation, action } = options.functionTypes;\n if (!query && !mutation && !action) {\n throw new Error(\n `Middleware \"${key}\" must declare at least one function type`,\n );\n }\n\n function MiddlewareSpecClass() {}\n const class_ = MiddlewareSpecClass as any;\n class_[TypeId] = TypeId;\n class_.key = key;\n class_.functionTypes = {\n query,\n mutation,\n action,\n } satisfies SupportedFunctionTypes;\n if (options.error !== undefined) {\n Lazy.defineProperty(class_, \"error\", options.error);\n }\n if (options.options !== undefined) {\n Lazy.defineProperty(class_, \"options\", options.options);\n }\n return class_;\n };\n\ntype FunctionTypesFromConfig<Config extends SupportedFunctionTypes> = {\n [K in FunctionType]: Config[K] extends true ? K : never;\n}[FunctionType];\n\ntype ValidateFunctionTypesConfig<Config extends SupportedFunctionTypes> =\n ValidationResult<\n | {\n [K in keyof Config]: boolean extends Config[K]\n ? AttachmentError<`Function type flag \"${K & string}\" must be a literal \\`true\\` or \\`false\\`, not a computed \\`boolean\\``>\n : never;\n }[keyof Config]\n | ([FunctionTypesFromConfig<Config>] extends [never]\n ? AttachmentError<`A middleware must declare at least one function type`>\n : never)\n >;\n\nexport const errorSchemas = (\n middlewareSpecs: ReadonlyArray<AnyMiddlewareSpec>,\n): ReadonlyArray<Schema.Codec<any, any>> =>\n middlewareSpecs.flatMap((middlewareSpec) =>\n \"error\" in middlewareSpec && middlewareSpec.error !== undefined\n ? [middlewareSpec.error]\n : [],\n );\n\n/**\n * A branded, unconstructible type carrying a spec-authoring error message.\n * Surfaced as (part of) a parameter type so the diagnostic names the exact\n * problem at the `.middleware()`/`.addFunction()` call site.\n */\nexport interface AttachmentError<Message extends string> {\n readonly \"~@confect/core/MiddlewareSpec/AttachmentError\": Message;\n}\n\ntype FunctionTypeOf<FunctionSpec_ extends FunctionSpec.AnyWithProps> =\n FunctionSpec_[\"runtimeAndFunctionType\"][\"functionType\"];\n\ntype ValidationResult<Errors> = [Errors] extends [never] ? unknown : Errors;\n\n/**\n * A matching-type Convex-provenance function is rejected rather than silently\n * skipped: its raw handler passes through Confect untouched, so the middleware\n * could not actually cover it, and skipping it would be a policy hole.\n */\nexport type ValidateFunction<\n FunctionSpec_ extends FunctionSpec.AnyWithProps,\n MiddlewareSpec_ extends AnyMiddlewareSpec,\n> = FunctionSpec_ extends any\n ? MiddlewareSpec_ extends any\n ? FunctionSpec_ extends {\n readonly functionProvenance: { readonly _tag: \"Convex\" };\n }\n ? FunctionTypeOf<FunctionSpec_> extends FunctionTypes<MiddlewareSpec_>\n ? AttachmentError<`Convex-provenance function \"${FunctionSpec_[\"name\"]}\" cannot be covered by middleware \"${Key<MiddlewareSpec_>}\"—attach middleware only to groups whose matching-type functions are all Confect-provenance`>\n : never\n : [\n Extract<\n FunctionSpec.MiddlewareSpecs<FunctionSpec_>,\n { readonly key: Key<WithoutOptions<MiddlewareSpec_>> }\n >,\n ] extends [never]\n ? FunctionTypeOf<FunctionSpec_> extends FunctionTypes<MiddlewareSpec_>\n ? never\n : AttachmentError<`Middleware \"${Key<MiddlewareSpec_>}\" does not declare function type \"${FunctionTypeOf<FunctionSpec_>}\", the type of function \"${FunctionSpec_[\"name\"]}\"`>\n : AttachmentError<`Middleware \"${Key<MiddlewareSpec_>}\" is already attached to function \"${FunctionSpec_[\"name\"]}\"`>\n : never\n : never;\n\n/**\n * Attachment order is chain order, so requiring `requires` to be satisfied by\n * already-attached middleware is exactly requiring the provider to run\n * earlier.\n */\nexport type ValidateAttach<\n MiddlewareSpec_ extends AnyMiddlewareSpec,\n Functions_ extends FunctionSpec.AnyWithProps,\n MiddlewareSpecs_ extends AnyMiddlewareSpec,\n> = [\n Extract<\n MiddlewareSpecs_,\n { readonly key: Key<WithoutOptions<MiddlewareSpec_>> }\n >,\n] extends [never]\n ? [Exclude<Requires<MiddlewareSpec_>, Provides<MiddlewareSpecs_>>] extends [\n never,\n ]\n ? ValidationResult<ValidateFunction<Functions_, MiddlewareSpec_>>\n : AttachmentError<`Middleware \"${Key<MiddlewareSpec_>}\" requires services that no middleware attached earlier to this group provides—attach the providing middleware first`>\n : AttachmentError<`Middleware \"${Key<MiddlewareSpec_>}\" is already attached to this group`>;\n\nexport type ValidateAddedFunction<\n FunctionSpec_ extends FunctionSpec.AnyWithProps,\n MiddlewareSpecs_ extends AnyMiddlewareSpec,\n> = [MiddlewareSpecs_] extends [never]\n ? unknown\n : ValidationResult<\n | ValidateFunction<FunctionSpec_, MiddlewareSpecs_>\n | GroupOverlap<FunctionSpec_, MiddlewareSpecs_>\n >;\n\ntype GroupOverlap<\n FunctionSpec_ extends FunctionSpec.AnyWithProps,\n MiddlewareSpecs_ extends AnyMiddlewareSpec,\n> =\n FunctionSpec.MiddlewareSpecs<FunctionSpec_> extends infer FunctionMiddlewareSpec\n ? FunctionMiddlewareSpec extends AnyMiddlewareSpec\n ? [\n Extract<\n MiddlewareSpecs_,\n { readonly key: Key<WithoutOptions<FunctionMiddlewareSpec>> }\n >,\n ] extends [never]\n ? never\n : AttachmentError<`Middleware \"${Key<FunctionMiddlewareSpec>}\" is attached to both function \"${FunctionSpec_[\"name\"]}\" and its group`>\n : never\n : never;\n\n/**\n * The parameter-type validation applied to the group spec at `GroupImpl.make`:\n * every function's attached middleware must have its `requires` services\n * provided by some middleware covering that function (the group's or the\n * function's own). Checked here—with the group fully assembled—rather than at\n * the spec builders, because a function-level middleware's `requires` may\n * legitimately be satisfied by a group middleware the function spec never sees,\n * and group attachment is declaratively order-independent with respect to\n * `addFunction`.\n */\nexport type ValidateImplRequires<\n Functions_ extends FunctionSpec.AnyWithProps,\n GroupMiddlewareSpecs_ extends AnyMiddlewareSpec,\n> = ValidationResult<\n Functions_ extends any\n ? [\n Exclude<\n Requires<FunctionSpec.MiddlewareSpecs<Functions_>>,\n Provides<\n GroupMiddlewareSpecs_ | FunctionSpec.MiddlewareSpecs<Functions_>\n >\n >,\n ] extends [never]\n ? never\n : AttachmentError<`Function \"${Functions_[\"name\"]}\" has middleware requiring services that no middleware covering it provides`>\n : never\n>;\n\nexport type ValidateFunctionAttach<\n MiddlewareSpec_ extends AnyMiddlewareSpec,\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,\n FunctionProvenance_ extends FunctionProvenance.FunctionProvenance,\n MiddlewareSpecs_ extends AnyMiddlewareSpec,\n> = FunctionProvenance_ extends { readonly _tag: \"Convex\" }\n ? AttachmentError<`Plain Convex functions cannot have middleware—their raw handlers are passed through untouched`>\n : [\n Extract<\n MiddlewareSpecs_,\n { readonly key: Key<WithoutOptions<MiddlewareSpec_>> }\n >,\n ] extends [never]\n ? RuntimeAndFunctionType_[\"functionType\"] extends FunctionTypes<MiddlewareSpec_>\n ? unknown\n : AttachmentError<`Middleware \"${Key<MiddlewareSpec_>}\" does not declare function type \"${RuntimeAndFunctionType_[\"functionType\"]}\"`>\n : AttachmentError<`Middleware \"${Key<MiddlewareSpec_>}\" is already attached to this function`>;\n"],"mappings":";;;;;;;;;;;AAUA,MAAa,SAAS;AAGtB,MAAa,oBAAoB,MAC/B,UAAU,YAAY,GAAG,MAAM;AAEjC,MAAa,mBAAgD;CAC3D;CACA;CACA;AACF;;;;;;;;;;;;;;;;;;;;;;AAiKA,MAAa,wBAQT,KACA,YAcG;CACH,MAAM,EAAE,OAAO,UAAU,WAAW,QAAQ;CAC5C,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,QAC1B,MAAM,IAAI,MACR,eAAe,IAAI,0CACrB;CAGF,SAAS,sBAAsB,CAAC;CAChC,MAAM,SAAS;CACf,OAAO,UAAU;CACjB,OAAO,MAAM;CACb,OAAO,gBAAgB;EACrB;EACA;EACA;CACF;CACA,IAAI,QAAQ,UAAU,KAAA,GACpB,eAAoB,QAAQ,SAAS,QAAQ,KAAK;CAEpD,IAAI,QAAQ,YAAY,KAAA,GACtB,eAAoB,QAAQ,WAAW,QAAQ,OAAO;CAExD,OAAO;AACT;AAkBF,MAAa,gBACX,oBAEA,gBAAgB,SAAS,mBACvB,WAAW,kBAAkB,eAAe,UAAU,KAAA,IAClD,CAAC,eAAe,KAAK,IACrB,CAAC,CACP"}
|
|
@@ -3,12 +3,18 @@ import * as Schema from "effect/Schema";
|
|
|
3
3
|
declare const InvalidCursor_base: Schema.Class<InvalidCursor, Schema.TaggedStruct<"InvalidCursor", {
|
|
4
4
|
readonly cause: Schema.Defect;
|
|
5
5
|
}>, import("effect/Cause").YieldableError>;
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* A Convex pagination cursor that no longer describes the current query.
|
|
8
|
+
*/
|
|
7
9
|
export declare class InvalidCursor extends InvalidCursor_base {
|
|
8
10
|
}
|
|
9
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* Recognizes an invalid-cursor error emitted by a Convex query.
|
|
13
|
+
*/
|
|
10
14
|
export declare const fromConvexQueryError: (error: unknown) => Option.Option<InvalidCursor>;
|
|
11
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Recognizes the error data attached to Convex's invalid-cursor error.
|
|
17
|
+
*/
|
|
12
18
|
export declare const fromConvexErrorData: (errorData: unknown) => Option.Option<InvalidCursor>;
|
|
13
19
|
export {};
|
|
14
20
|
//# sourceMappingURL=PaginationError.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PaginationError.d.ts","sourceRoot":"","sources":["../src/PaginationError.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;;;;AAExC
|
|
1
|
+
{"version":3,"file":"PaginationError.d.ts","sourceRoot":"","sources":["../src/PaginationError.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;;;;AAExC;;GAEG;AACH,qBAAa,aAAc,SAAQ,kBAKlC;CAAG;AA8BJ;;GAEG;AACH,eAAO,MAAM,oBAAoB,UACxB,OAAO,KACb,MAAM,CAAC,MAAM,CAAC,aAAa,CAc3B,CAAC;AAEJ;;GAEG;AACH,eAAO,MAAM,mBAAmB,cACnB,OAAO,KACjB,MAAM,CAAC,MAAM,CAAC,aAAa,CAO3B,CAAC"}
|
package/dist/PaginationError.js
CHANGED
|
@@ -9,15 +9,21 @@ var PaginationError_exports = /* @__PURE__ */ __exportAll({
|
|
|
9
9
|
fromConvexErrorData: () => fromConvexErrorData,
|
|
10
10
|
fromConvexQueryError: () => fromConvexQueryError
|
|
11
11
|
});
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* A Convex pagination cursor that no longer describes the current query.
|
|
14
|
+
*/
|
|
13
15
|
var InvalidCursor = class extends Schema.TaggedError()("InvalidCursor", { cause: Schema.Defect() }) {};
|
|
14
16
|
const ConvexErrorIdentifier = Symbol.for("ConvexError");
|
|
15
17
|
const isConvexError = (error) => error instanceof ConvexError || typeof error === "object" && error !== null && ConvexErrorIdentifier in error;
|
|
16
18
|
const isInvalidCursorData = (value) => typeof value === "object" && value !== null && "isConvexSystemError" in value && value.isConvexSystemError === true && "paginationError" in value && value.paginationError === "InvalidCursor";
|
|
17
19
|
const fromErrorMessage = (error) => error.message.includes("InvalidCursor") ? Option.some(new InvalidCursor({ cause: error })) : Option.none();
|
|
18
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* Recognizes an invalid-cursor error emitted by a Convex query.
|
|
22
|
+
*/
|
|
19
23
|
const fromConvexQueryError = (error) => Match.value(error).pipe(Match.when(isConvexError, (convexError) => Match.value(isInvalidCursorData(convexError.data)).pipe(Match.when(true, () => Option.some(new InvalidCursor({ cause: error }))), Match.when(false, () => fromErrorMessage(convexError)), Match.exhaustive)), Match.when(Match.instanceOf(globalThis.Error), fromErrorMessage), Match.when(Match.any, () => Option.none()), Match.exhaustive);
|
|
20
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* Recognizes the error data attached to Convex's invalid-cursor error.
|
|
26
|
+
*/
|
|
21
27
|
const fromConvexErrorData = (errorData) => Match.value(errorData).pipe(Match.when(isInvalidCursorData, (cause) => Option.some(new InvalidCursor({ cause }))), Match.when(Match.any, () => Option.none()), Match.exhaustive);
|
|
22
28
|
//#endregion
|
|
23
29
|
export { InvalidCursor, PaginationError_exports, fromConvexErrorData, fromConvexQueryError };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PaginationError.js","names":[],"sources":["../src/PaginationError.ts"],"sourcesContent":["import { ConvexError } from \"convex/values\";\nimport type { Value } from \"convex/values\";\nimport * as Match from \"effect/Match\";\nimport * as Option from \"effect/Option\";\nimport * as Schema from \"effect/Schema\";\n\n
|
|
1
|
+
{"version":3,"file":"PaginationError.js","names":[],"sources":["../src/PaginationError.ts"],"sourcesContent":["import { ConvexError } from \"convex/values\";\nimport type { Value } from \"convex/values\";\nimport * as Match from \"effect/Match\";\nimport * as Option from \"effect/Option\";\nimport * as Schema from \"effect/Schema\";\n\n/**\n * A Convex pagination cursor that no longer describes the current query.\n */\nexport class InvalidCursor extends Schema.TaggedError<InvalidCursor>()(\n \"InvalidCursor\",\n {\n cause: Schema.Defect(),\n },\n) {}\n\ninterface InvalidCursorData {\n readonly isConvexSystemError: true;\n readonly paginationError: \"InvalidCursor\";\n}\n\nconst ConvexErrorIdentifier = Symbol.for(\"ConvexError\");\n\nconst isConvexError = (error: unknown): error is ConvexError<Value> =>\n error instanceof ConvexError ||\n (typeof error === \"object\" &&\n error !== null &&\n ConvexErrorIdentifier in error);\n\nconst isInvalidCursorData = (value: unknown): value is InvalidCursorData =>\n typeof value === \"object\" &&\n value !== null &&\n \"isConvexSystemError\" in value &&\n value.isConvexSystemError === true &&\n \"paginationError\" in value &&\n value.paginationError === \"InvalidCursor\";\n\nconst fromErrorMessage = (\n error: globalThis.Error,\n): Option.Option<InvalidCursor> =>\n error.message.includes(\"InvalidCursor\")\n ? Option.some(new InvalidCursor({ cause: error }))\n : Option.none();\n\n/**\n * Recognizes an invalid-cursor error emitted by a Convex query.\n */\nexport const fromConvexQueryError = (\n error: unknown,\n): Option.Option<InvalidCursor> =>\n Match.value(error).pipe(\n Match.when(isConvexError, (convexError) =>\n Match.value(isInvalidCursorData(convexError.data)).pipe(\n Match.when(true, () =>\n Option.some(new InvalidCursor({ cause: error })),\n ),\n Match.when(false, () => fromErrorMessage(convexError)),\n Match.exhaustive,\n ),\n ),\n Match.when(Match.instanceOf(globalThis.Error), fromErrorMessage),\n Match.when(Match.any, () => Option.none<InvalidCursor>()),\n Match.exhaustive,\n );\n\n/**\n * Recognizes the error data attached to Convex's invalid-cursor error.\n */\nexport const fromConvexErrorData = (\n errorData: unknown,\n): Option.Option<InvalidCursor> =>\n Match.value(errorData).pipe(\n Match.when(isInvalidCursorData, (cause) =>\n Option.some(new InvalidCursor({ cause })),\n ),\n Match.when(Match.any, () => Option.none<InvalidCursor>()),\n Match.exhaustive,\n );\n"],"mappings":";;;;;;;;;;;;;;AASA,IAAa,gBAAb,cAAmC,OAAO,YAA2B,CAAC,CACpE,iBACA,EACE,OAAO,OAAO,OAAO,EACvB,CACF,CAAC,CAAC,CAAC;AAOH,MAAM,wBAAwB,OAAO,IAAI,aAAa;AAEtD,MAAM,iBAAiB,UACrB,iBAAiB,eAChB,OAAO,UAAU,YAChB,UAAU,QACV,yBAAyB;AAE7B,MAAM,uBAAuB,UAC3B,OAAO,UAAU,YACjB,UAAU,QACV,yBAAyB,SACzB,MAAM,wBAAwB,QAC9B,qBAAqB,SACrB,MAAM,oBAAoB;AAE5B,MAAM,oBACJ,UAEA,MAAM,QAAQ,SAAS,eAAe,IAClC,OAAO,KAAK,IAAI,cAAc,EAAE,OAAO,MAAM,CAAC,CAAC,IAC/C,OAAO,KAAK;;;;AAKlB,MAAa,wBACX,UAEA,MAAM,MAAM,KAAK,CAAC,CAAC,KACjB,MAAM,KAAK,gBAAgB,gBACzB,MAAM,MAAM,oBAAoB,YAAY,IAAI,CAAC,CAAC,CAAC,KACjD,MAAM,KAAK,YACT,OAAO,KAAK,IAAI,cAAc,EAAE,OAAO,MAAM,CAAC,CAAC,CACjD,GACA,MAAM,KAAK,aAAa,iBAAiB,WAAW,CAAC,GACrD,MAAM,UACR,CACF,GACA,MAAM,KAAK,MAAM,WAAW,WAAW,KAAK,GAAG,gBAAgB,GAC/D,MAAM,KAAK,MAAM,WAAW,OAAO,KAAoB,CAAC,GACxD,MAAM,UACR;;;;AAKF,MAAa,uBACX,cAEA,MAAM,MAAM,SAAS,CAAC,CAAC,KACrB,MAAM,KAAK,sBAAsB,UAC/B,OAAO,KAAK,IAAI,cAAc,EAAE,MAAM,CAAC,CAAC,CAC1C,GACA,MAAM,KAAK,MAAM,WAAW,OAAO,KAAoB,CAAC,GACxD,MAAM,UACR"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as Schema from "effect/Schema";
|
|
2
2
|
/**
|
|
3
|
-
* Schema for the `paginationOpts` argument that every paginated query
|
|
4
|
-
*
|
|
3
|
+
* Schema for the `paginationOpts` argument that every paginated query receives.
|
|
4
|
+
* Mirrors `paginationOptsValidator` from `convex/server`.
|
|
5
5
|
*
|
|
6
6
|
* Use this as the `paginationOpts` field of a paginated query's args schema.
|
|
7
7
|
* Beyond `numItems` and `cursor`, Convex's pagination protocol sends the
|
|
@@ -3,8 +3,8 @@ import * as Schema from "effect/Schema";
|
|
|
3
3
|
//#region src/PaginationOptions.ts
|
|
4
4
|
var PaginationOptions_exports = /* @__PURE__ */ __exportAll({ PaginationOptions: () => PaginationOptions });
|
|
5
5
|
/**
|
|
6
|
-
* Schema for the `paginationOpts` argument that every paginated query
|
|
7
|
-
*
|
|
6
|
+
* Schema for the `paginationOpts` argument that every paginated query receives.
|
|
7
|
+
* Mirrors `paginationOptsValidator` from `convex/server`.
|
|
8
8
|
*
|
|
9
9
|
* Use this as the `paginationOpts` field of a paginated query's args schema.
|
|
10
10
|
* Beyond `numItems` and `cursor`, Convex's pagination protocol sends the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PaginationOptions.js","names":[],"sources":["../src/PaginationOptions.ts"],"sourcesContent":["import * as Schema from \"effect/Schema\";\n\n/**\n * Schema for the `paginationOpts` argument that every paginated query
|
|
1
|
+
{"version":3,"file":"PaginationOptions.js","names":[],"sources":["../src/PaginationOptions.ts"],"sourcesContent":["import * as Schema from \"effect/Schema\";\n\n/**\n * Schema for the `paginationOpts` argument that every paginated query receives.\n * Mirrors `paginationOptsValidator` from `convex/server`.\n *\n * Use this as the `paginationOpts` field of a paginated query's args schema.\n * Beyond `numItems` and `cursor`, Convex's pagination protocol sends the\n * optional fields (`endCursor`, `id`, `maximumRowsRead`, `maximumBytesRead`)\n * with real requests—most notably `usePaginatedQuery` from `convex/react`\n * always includes `id`, and includes `endCursor` when splitting pages.\n * Declaring them is required for the generated Convex argument validator to\n * accept those requests and for the fields to survive decoding and reach\n * `paginate`.\n */\nexport const PaginationOptions = Schema.Struct({\n numItems: Schema.Finite,\n cursor: Schema.Union([Schema.String, Schema.Null]),\n endCursor: Schema.optionalKey(Schema.Union([Schema.String, Schema.Null])),\n id: Schema.optionalKey(Schema.Finite),\n maximumRowsRead: Schema.optionalKey(Schema.Finite),\n maximumBytesRead: Schema.optionalKey(Schema.Finite),\n});\n"],"mappings":";;;;;;;;;;;;;;;;;AAeA,MAAa,oBAAoB,OAAO,OAAO;CAC7C,UAAU,OAAO;CACjB,QAAQ,OAAO,MAAM,CAAC,OAAO,QAAQ,OAAO,IAAI,CAAC;CACjD,WAAW,OAAO,YAAY,OAAO,MAAM,CAAC,OAAO,QAAQ,OAAO,IAAI,CAAC,CAAC;CACxE,IAAI,OAAO,YAAY,OAAO,MAAM;CACpC,iBAAiB,OAAO,YAAY,OAAO,MAAM;CACjD,kBAAkB,OAAO,YAAY,OAAO,MAAM;AACpD,CAAC"}
|