@confect/core 10.2.0 → 10.3.1
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 +20 -0
- package/dist/GroupSpec.d.ts +5 -7
- package/dist/GroupSpec.d.ts.map +1 -1
- package/dist/GroupSpec.js +9 -45
- package/dist/GroupSpec.js.map +1 -1
- package/dist/SchemaToValidator.d.ts +16 -15
- package/dist/SchemaToValidator.d.ts.map +1 -1
- package/dist/SchemaToValidator.js.map +1 -1
- package/dist/Spec.d.ts +1 -4
- package/dist/Spec.d.ts.map +1 -1
- package/dist/Spec.js +4 -14
- package/dist/Spec.js.map +1 -1
- package/dist/SystemFields.js +1 -1
- package/dist/Types.d.ts +13 -2
- package/dist/Types.d.ts.map +1 -1
- package/dist/Types.js.map +1 -1
- package/package.json +6 -6
- package/src/GroupSpec.ts +20 -83
- package/src/SchemaToValidator.ts +108 -97
- package/src/Spec.ts +6 -44
- package/src/Types.ts +40 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @confect/core
|
|
2
2
|
|
|
3
|
+
## 10.3.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 7963e35: Fix excessively deep TypeScript instantiation errors when indexing tables with wide literal-union fields using `Table.make(...).index(...)`.
|
|
8
|
+
|
|
9
|
+
## 10.3.0
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 33eaf6a: Reduce the initialization cost of generated function references in projects with many groups.
|
|
14
|
+
|
|
15
|
+
Fix `confect/_generated/spec.ts` failing to typecheck with "Type instantiation is excessively deep and possibly infinite" (TS2589) in projects with many top-level or child groups, while keeping `refs` precisely typed.
|
|
16
|
+
|
|
17
|
+
Run `confect codegen` after upgrading to regenerate existing files before typechecking or deploying. User-authored group definitions using `GroupSpec.make()`, `GroupSpec.makeNode()`, `.addFunction()`, and `.middleware()` do not need to change.
|
|
18
|
+
|
|
19
|
+
- 52e4397: Stop reporting a nested struct as recursive when it is merely assignable to one of its ancestors. `IsRecursive` compared a type against the types above it by assignability, so a struct nested under a parent whose extra fields are all optional (for example `{ badge: string }` inside `{ badge: string; rows?: { badge: string }[] }`) was treated as a cycle: its validator type became `VAny`, and a table built from it had a `never` document type and rejected its own index fields. Types already on the path are now compared by identity.
|
|
20
|
+
- bc41806: Type a record of `Schema.Any` with a required value validator. `Schema.Record(Schema.String, Schema.Any)` compiled to `v.record(v.string(), v.any())` at runtime, but its type carried an optional `VAny` value, which `VRecord` does not accept, so a table with such a field could not be passed to `Table.tableDefinition`.
|
|
21
|
+
- 5ea7c07: Reduce TypeScript type-checking work for table schemas with nested objects, arrays, unions, and optional fields while preserving their inferred types.
|
|
22
|
+
|
|
3
23
|
## 10.2.0
|
|
4
24
|
|
|
5
25
|
No changes in this release.
|
package/dist/GroupSpec.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as MiddlewareAttachment from "./MiddlewareAttachment";
|
|
2
|
+
import * as Record from "effect/Record";
|
|
2
3
|
import * as Result from "effect/Result";
|
|
3
4
|
import type * as FunctionSpec from "./FunctionSpec";
|
|
4
5
|
import type * as MiddlewareSpec from "./MiddlewareSpec";
|
|
@@ -21,8 +22,6 @@ export interface GroupSpec<Runtime extends RuntimeAndFunctionType.Runtime, Name_
|
|
|
21
22
|
readonly "~Functions": Functions_;
|
|
22
23
|
readonly "~Groups": Groups_;
|
|
23
24
|
addFunction<Function extends FunctionSpec.AnyWithPropsWithRuntime<Runtime>>(function_: Function & MiddlewareSpec.ValidateAddedFunction<Function, MiddlewareSpecs_>): GroupSpec<Runtime, Name_, Functions_ | Function, Groups_, MiddlewareSpecs_>;
|
|
24
|
-
addGroup<Group extends AnyWithProps>(group: Group): GroupSpec<Runtime, Name_, Functions_, Groups_ | Group, MiddlewareSpecs_>;
|
|
25
|
-
addGroupAt<const AtName extends string, Group extends AnyWithProps>(name: AtName, group: Group): GroupSpec<Runtime, Name_, Functions_, Groups_ | NamedAt<Group, AtName>, MiddlewareSpecs_>;
|
|
26
25
|
middleware<MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec>(middlewareSpec: MiddlewareSpec_ & MiddlewareSpec.ValidateAttach<MiddlewareSpec_, Functions_, MiddlewareSpecs_>, ...options: MiddlewareAttachment.Args<NoInfer<MiddlewareSpec_>>): GroupSpec<Runtime, Name_, Functions_, Groups_, MiddlewareSpecs_ | MiddlewareSpec_>;
|
|
27
26
|
}
|
|
28
27
|
export interface Any {
|
|
@@ -30,8 +29,6 @@ export interface Any {
|
|
|
30
29
|
}
|
|
31
30
|
export interface AnyWithProps extends GroupSpec<RuntimeAndFunctionType.Runtime, string, FunctionSpec.AnyWithProps, AnyWithProps, MiddlewareSpec.AnyMiddlewareSpec> {
|
|
32
31
|
}
|
|
33
|
-
export interface AnyWithPropsWithRuntime<Runtime extends RuntimeAndFunctionType.Runtime> extends GroupSpec<Runtime, string, FunctionSpec.AnyWithPropsWithRuntime<Runtime>, AnyWithPropsWithRuntime<Runtime>, MiddlewareSpec.AnyMiddlewareSpec> {
|
|
34
|
-
}
|
|
35
32
|
export type Name<Group extends AnyWithProps> = Group["name"];
|
|
36
33
|
export type Functions<Group extends AnyWithProps> = Group["~Functions"];
|
|
37
34
|
export type Groups<Group extends AnyWithProps> = Group["~Groups"];
|
|
@@ -49,11 +46,12 @@ export type WithName<Group extends AnyWithProps, Name_ extends Name<Group>> = Ex
|
|
|
49
46
|
export type NamedAt<Group extends Any, Name_ extends string> = Omit<Group, "name"> & {
|
|
50
47
|
readonly name: Name_;
|
|
51
48
|
};
|
|
52
|
-
export type AddGroups<Group extends AnyWithProps, ExtraGroups extends AnyWithProps> = Group extends GroupSpec<infer Runtime,
|
|
49
|
+
export type AddGroups<Group extends AnyWithProps, ExtraGroups extends AnyWithProps> = Group extends GroupSpec<infer Runtime, string, infer Functions_, infer Groups_, infer MiddlewareSpecs_> ? GroupSpec<Runtime, Group["name"], Functions_, Exclude<Groups_, {
|
|
50
|
+
readonly name: Name<ExtraGroups>;
|
|
51
|
+
}> | ExtraGroups, MiddlewareSpecs_> : never;
|
|
53
52
|
export declare const make: () => GroupSpec<"Convex", "">;
|
|
54
|
-
export declare const makeAt: <const Name_ extends string>(name: Name_) => GroupSpec<"Convex", Name_>;
|
|
55
53
|
export declare const makeNode: () => GroupSpec<"Node", "">;
|
|
56
|
-
export declare const makeNodeAt: <const Name_ extends string>(name: Name_) => GroupSpec<"Node", Name_>;
|
|
57
54
|
export declare function withName<const Name_ extends string, Group extends Any>(name: Name_, group: Group): NamedAt<Group, Name_>;
|
|
55
|
+
export declare const addGroupsAt: (group: AnyWithProps, children: Record.ReadonlyRecord<string, AnyWithProps>) => AnyWithProps;
|
|
58
56
|
export declare const validateMiddleware: (group: AnyWithProps) => Result.Result<void, MiddlewareAttachment.ValidationError>;
|
|
59
57
|
//# sourceMappingURL=GroupSpec.d.ts.map
|
package/dist/GroupSpec.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GroupSpec.d.ts","sourceRoot":"","sources":["../src/GroupSpec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,oBAAoB,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"GroupSpec.d.ts","sourceRoot":"","sources":["../src/GroupSpec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,oBAAoB,MAAM,wBAAwB,CAAC;AAE/D,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,YAAY,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,KAAK,cAAc,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,KAAK,sBAAsB,MAAM,0BAA0B,CAAC;AAGxE,eAAO,MAAM,MAAM,6BAA6B,CAAC;AACjD,MAAM,MAAM,MAAM,GAAG,OAAO,M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AcvD,CAAC"}
|
package/dist/GroupSpec.js
CHANGED
|
@@ -7,11 +7,10 @@ import * as Record from "effect/Record";
|
|
|
7
7
|
//#region src/GroupSpec.ts
|
|
8
8
|
var GroupSpec_exports = /* @__PURE__ */ __exportAll({
|
|
9
9
|
TypeId: () => TypeId,
|
|
10
|
+
addGroupsAt: () => addGroupsAt,
|
|
10
11
|
isGroupSpec: () => isGroupSpec,
|
|
11
12
|
make: () => make,
|
|
12
|
-
makeAt: () => makeAt,
|
|
13
13
|
makeNode: () => makeNode,
|
|
14
|
-
makeNodeAt: () => makeNodeAt,
|
|
15
14
|
validateMiddleware: () => validateMiddleware,
|
|
16
15
|
withName: () => withName
|
|
17
16
|
});
|
|
@@ -34,28 +33,6 @@ const Proto = {
|
|
|
34
33
|
middlewareAttachments: this_.middlewareAttachments
|
|
35
34
|
});
|
|
36
35
|
},
|
|
37
|
-
addGroup(group) {
|
|
38
|
-
const this_ = this;
|
|
39
|
-
const group_ = group;
|
|
40
|
-
return makeProto({
|
|
41
|
-
runtime: this_.runtime,
|
|
42
|
-
name: this_.name,
|
|
43
|
-
functions: this_.functions,
|
|
44
|
-
groups: Record.set(this_.groups, group_.name, group_),
|
|
45
|
-
middlewareAttachments: this_.middlewareAttachments
|
|
46
|
-
});
|
|
47
|
-
},
|
|
48
|
-
addGroupAt(name, group) {
|
|
49
|
-
const this_ = this;
|
|
50
|
-
const group_ = group;
|
|
51
|
-
return makeProto({
|
|
52
|
-
runtime: this_.runtime,
|
|
53
|
-
name: this_.name,
|
|
54
|
-
functions: this_.functions,
|
|
55
|
-
groups: Record.set(this_.groups, name, withName(name, group_)),
|
|
56
|
-
middlewareAttachments: this_.middlewareAttachments
|
|
57
|
-
});
|
|
58
|
-
},
|
|
59
36
|
middleware(middlewareSpec, ...options) {
|
|
60
37
|
const this_ = this;
|
|
61
38
|
if (!("options" in middlewareSpec) && this_.middlewareAttachments.some(({ spec }) => spec.key === middlewareSpec.key)) throw new Error(`Middleware "${middlewareSpec.key}" is already attached to this group`);
|
|
@@ -86,16 +63,6 @@ const make = () => makeProto({
|
|
|
86
63
|
groups: Record.empty(),
|
|
87
64
|
middlewareAttachments: []
|
|
88
65
|
});
|
|
89
|
-
const makeAt = (name) => {
|
|
90
|
-
validateConfectFunctionIdentifier(name);
|
|
91
|
-
return makeProto({
|
|
92
|
-
runtime: "Convex",
|
|
93
|
-
name,
|
|
94
|
-
functions: Record.empty(),
|
|
95
|
-
groups: Record.empty(),
|
|
96
|
-
middlewareAttachments: []
|
|
97
|
-
});
|
|
98
|
-
};
|
|
99
66
|
const makeNode = () => makeProto({
|
|
100
67
|
runtime: "Node",
|
|
101
68
|
name: "",
|
|
@@ -103,16 +70,6 @@ const makeNode = () => makeProto({
|
|
|
103
70
|
groups: Record.empty(),
|
|
104
71
|
middlewareAttachments: []
|
|
105
72
|
});
|
|
106
|
-
const makeNodeAt = (name) => {
|
|
107
|
-
validateConfectFunctionIdentifier(name);
|
|
108
|
-
return makeProto({
|
|
109
|
-
runtime: "Node",
|
|
110
|
-
name,
|
|
111
|
-
functions: Record.empty(),
|
|
112
|
-
groups: Record.empty(),
|
|
113
|
-
middlewareAttachments: []
|
|
114
|
-
});
|
|
115
|
-
};
|
|
116
73
|
function withName(name, group) {
|
|
117
74
|
validateConfectFunctionIdentifier(name);
|
|
118
75
|
const group_ = group;
|
|
@@ -125,12 +82,19 @@ function withName(name, group) {
|
|
|
125
82
|
middlewareAttachments: group_.middlewareAttachments
|
|
126
83
|
});
|
|
127
84
|
}
|
|
85
|
+
const addGroupsAt = (group, children) => makeProto({
|
|
86
|
+
runtime: group.runtime,
|
|
87
|
+
name: group.name,
|
|
88
|
+
functions: group.functions,
|
|
89
|
+
groups: Record.union(group.groups, Record.map(children, (child, name) => withName(name, child)), (_existing, incoming) => incoming),
|
|
90
|
+
middlewareAttachments: group.middlewareAttachments
|
|
91
|
+
});
|
|
128
92
|
const validateMiddleware = (group) => Result.gen(function* () {
|
|
129
93
|
yield* validateAll(group.middlewareAttachments, `group "${group.name}"`);
|
|
130
94
|
for (const function_ of Object.values(group.functions)) yield* validateAll([...group.middlewareAttachments, ...function_.middlewareAttachments], `function "${function_.name}"`);
|
|
131
95
|
for (const child of Object.values(group.groups)) yield* validateMiddleware(child);
|
|
132
96
|
});
|
|
133
97
|
//#endregion
|
|
134
|
-
export { GroupSpec_exports, TypeId, isGroupSpec, make,
|
|
98
|
+
export { GroupSpec_exports, TypeId, addGroupsAt, isGroupSpec, make, makeNode, validateMiddleware, withName };
|
|
135
99
|
|
|
136
100
|
//# sourceMappingURL=GroupSpec.js.map
|
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/**\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":";;;;;;;;;;;;;;;;;AASA,MAAa,SAAS;AAGtB,MAAa,eAAe,MAC1B,UAAU,YAAY,GAAG,MAAM;AAqJjC,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,WAAW,UAAU,MAAM,SAAS;GAChE,QAAQ,MAAM;GACd,uBAAuB,MAAM;EAC/B,CAAC;CACH;CAEA,SAAuC,OAAc;EACnD,MAAM,QAAQ;EACd,MAAM,SAAS;EAEf,OAAO,UAAU;GACf,SAAS,MAAM;GACf,MAAM,MAAM;GACZ,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AAO,UAAU;EACf,SAAS;EACT;EACA,WAAW,OAAO,MAAM;EACxB,QAAQ,OAAO,MAAM;EACrB,uBAAuB,CAAC;CAC1B,CAAC;AACH;AAEA,MAAa,iBACX,UAAU;CACR,SAAS;CACT,MAAM;CACN,WAAW,OAAO,MAAM;CACxB,QAAQ,OAAO,MAAM;CACrB,uBAAuB,CAAC;AAC1B,CAAC;AAEH,MAAa,cACX,SAC6B;CAC7B,kCAAkC,IAAI;CAEtC,OAAO,UAAU;EACf,SAAS;EACT;EACA,WAAW,OAAO,MAAM;EACxB,QAAQ,OAAO,MAAM;EACrB,uBAAuB,CAAC;CAC1B,CAAC;AACH;AAMA,SAAgB,SAAS,MAAc,OAA0B;CAC/D,kCAAkC,IAAI;CACtC,MAAM,SAAS;CAEf,IAAI,OAAO,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"}
|
|
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 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 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 string,\n infer Functions_,\n infer Groups_,\n infer MiddlewareSpecs_\n >\n ? GroupSpec<\n Runtime,\n Group[\"name\"],\n Functions_,\n Exclude<Groups_, { readonly name: Name<ExtraGroups> }> | 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 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 AnyWithProps,\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 makeNode = (): GroupSpec<\"Node\", \"\"> =>\n makeProto({\n runtime: \"Node\",\n name: \"\",\n functions: Record.empty(),\n groups: Record.empty(),\n middlewareAttachments: [],\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 addGroupsAt = (\n group: AnyWithProps,\n children: Record.ReadonlyRecord<string, AnyWithProps>,\n): AnyWithProps =>\n makeProto({\n runtime: group.runtime,\n name: group.name,\n functions: group.functions,\n groups: Record.union(\n group.groups,\n Record.map(children, (child, name) => withName(name, child)),\n (_existing, incoming) => incoming,\n ),\n middlewareAttachments: group.middlewareAttachments,\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;AA4HjC,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,WAAW,UAAU,MAAM,SAAS;GAChE,QAAQ,MAAM;GACd,uBAAuB,MAAM;EAC/B,CAAC;CACH;CAEA,WAEE,gBACA,GAAG,SACH;EACA,MAAM,QAAQ;EAEd,IACE,EAAE,aAAa,mBACf,MAAM,sBAAsB,MACzB,EAAE,WAAW,KAAK,QAAQ,eAAe,GAC5C,GAEA,MAAM,IAAI,MACR,eAAe,eAAe,IAAI,oCACpC;EAGF,KAAK,MAAM,aAAa,OAAO,OAAO,MAAM,SAAS,GACnD,IACE,EAAE,aAAa,mBACf,UAAU,sBAAsB,MAC7B,EAAE,WAAW,KAAK,QAAQ,eAAe,GAC5C,GAEA,MAAM,IAAI,MACR,eAAe,eAAe,IAAI,kCAAkC,UAAU,KAAK,gBACrF;EAIJ,OAAO,UAAU;GACf,SAAS,MAAM;GACf,MAAM,MAAM;GACZ,WAAW,MAAM;GACjB,QAAQ,MAAM;GACd,uBAAu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,KAAK;AACnC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PropertyValidators, Validator, VAny, VArray, VBoolean, VBytes, VFloat64, VId, VInt64, VLiteral, VNull, VObject,
|
|
1
|
+
import type { PropertyValidators, Validator, VAny, VArray, VBoolean, VBytes, VFloat64, VId, VInt64, VLiteral, VNull, VObject, VRecord, VString, VUnion } from "convex/values";
|
|
2
2
|
import * as Effect from "effect/Effect";
|
|
3
3
|
import * as Schema from "effect/Schema";
|
|
4
4
|
import * as SchemaAST from "effect/SchemaAST";
|
|
@@ -19,21 +19,22 @@ export type ReadonlyRecordValue = {
|
|
|
19
19
|
type MutableValue<T> = T extends ReadonlyArray<infer El> ? MutableValue<El>[] : T extends ReadonlyRecordValue ? {
|
|
20
20
|
-readonly [K in keyof T]: MutableValue<Exclude<T[K], undefined>>;
|
|
21
21
|
} : T;
|
|
22
|
-
export type ValueToValidator<Vl> = [Vl] extends [never] ? never : IsAny<Vl> extends true ? VAny : [Vl] extends [
|
|
22
|
+
export type ValueToValidator<Vl> = [Vl] extends [never] ? never : IsAny<Vl> extends true ? VAny : [Vl] extends [string | number | bigint | boolean | null | ArrayBuffer] ? ConvertValueToValidator<Vl> : IsRecursive<Vl> extends true ? VAny : [Vl] extends [ReadonlyValue] ? ConvertValueToValidator<Vl> : TypeError<"Provided value is not a valid Convex value", Vl>;
|
|
23
|
+
type OptionalValue<Vl, Optionality> = Optionality extends "optional" ? Vl | undefined : Vl;
|
|
24
|
+
type ConvertValueToValidator<Vl, Optionality extends "required" | "optional" = "required"> = [Vl] extends [never] ? never : IsAny<Vl> extends true ? VAny<any, Optionality> : [Vl] extends [null] ? VNull<OptionalValue<null, Optionality>, Optionality> : [Vl] extends [boolean] ? [boolean] extends [Vl] ? VBoolean<OptionalValue<boolean, Optionality>, Optionality> : VLiteral<OptionalValue<Vl, Optionality>, Optionality> : IsUnion<Vl> extends true ? UnionValueToValidator<Vl, Optionality> : [Vl] extends [number] ? [number] extends [Vl] ? VFloat64<OptionalValue<number, Optionality>, Optionality> : VLiteral<OptionalValue<Vl, Optionality>, Optionality> : [Vl] extends [bigint] ? [bigint] extends [Vl] ? VInt64<OptionalValue<bigint, Optionality>, Optionality> : VLiteral<OptionalValue<Vl, Optionality>, Optionality> : [Vl] extends [string] ? StringValueToValidator<Vl, Optionality> : [Vl] extends [ArrayBuffer] ? VBytes<OptionalValue<ArrayBuffer, Optionality>, Optionality> : IsRecursive<Vl> extends true ? VAny<any, Optionality> : Vl extends ReadonlyArray<infer El> ? VArray<OptionalValue<MutableValue<El[]>, Optionality>, ConvertValueToValidator<El>, Optionality> : Vl extends object ? ObjectValueToValidator<Vl, Optionality> : never;
|
|
25
|
+
type StringValueToValidator<Vl, Optionality extends "required" | "optional"> = Vl extends {
|
|
23
26
|
__tableName: infer TableName extends string;
|
|
24
|
-
} ? VId<GenericId.GenericId<TableName
|
|
25
|
-
type
|
|
26
|
-
type
|
|
27
|
-
-readonly [K in keyof Vl]-?: IsAny<Vl[K]> extends true ? IsOptional<Vl, K> extends true ?
|
|
28
|
-
}
|
|
29
|
-
export type UndefinedOrValueToValidator<Vl extends ReadonlyValue | undefined> = undefined extends Vl ?
|
|
30
|
-
type UnionValueToValidator<Vl extends
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
...infer VlRest extends ReadonlyArray<ReadonlyValue>
|
|
36
|
-
] ? ValueToValidator<Vl> extends infer Vd extends Validator<any, any, any> ? ValueTupleToValidatorTuple<VlRest> extends infer VdRest extends Validator<any, "required", any>[] ? [Vd, ...VdRest] : never : never : [];
|
|
27
|
+
} ? VId<OptionalValue<GenericId.GenericId<TableName>, Optionality>, Optionality> : [string] extends [Vl] ? VString<OptionalValue<string, Optionality>, Optionality> : VLiteral<OptionalValue<Vl, Optionality>, Optionality>;
|
|
28
|
+
type ObjectValueToValidator<Vl, Optionality extends "required" | "optional"> = IsRecord<MutableValue<Vl>> extends true ? ValueToValidator<Vl[keyof Vl]> extends infer VdValue extends Validator<any, "required", any> ? VRecord<OptionalValue<MutableValue<Vl>, Optionality>, VString, VdValue, Optionality> : never : ObjectFieldsToValidators<Vl> extends infer VdFields extends Record<string, any> ? VObject<OptionalValue<MutableValue<Vl>, Optionality>, VdFields, Optionality> : never;
|
|
29
|
+
type ObjectFieldsToValidators<Vl> = {
|
|
30
|
+
-readonly [K in keyof Vl]-?: IsAny<Vl[K]> extends true ? IsOptional<Vl, K> extends true ? VAny<any, "optional"> : VAny : undefined extends Vl[K] ? OptionalValueToValidator<Vl[K]> : [Vl[K]] extends [ReadonlyValue] ? ConvertValueToValidator<Vl[K]> : never;
|
|
31
|
+
};
|
|
32
|
+
export type UndefinedOrValueToValidator<Vl extends ReadonlyValue | undefined> = undefined extends Vl ? OptionalValueToValidator<Vl> : [Vl] extends [ReadonlyValue] ? ValueToValidator<Vl> : never;
|
|
33
|
+
type UnionValueToValidator<Vl, Optionality extends "required" | "optional"> = IsRecursive<Vl> extends true ? VAny<any, Optionality> : VUnion<OptionalValue<MutableValue<Vl>, Optionality>, ValueTupleToValidatorTuple<UnionToTuple<Vl>>, Optionality>;
|
|
34
|
+
type ValueTupleToValidatorTuple<VlTuple extends readonly unknown[], Acc extends Validator<any, "required", any>[] = []> = VlTuple extends [true, false, ...infer VlRest] | [false, true, ...infer VlRest] ? ValueTupleToValidatorTuple<VlRest, [...Acc, VBoolean]> : VlTuple extends [infer Vl, ...infer VlRest] ? ValueTupleToValidatorTuple<VlRest, [...Acc, ConvertValueToValidator<Vl>]> : Acc;
|
|
35
|
+
type OptionalValueToValidator<Vl> = [Vl] extends [
|
|
36
|
+
(infer Val extends ReadonlyValue) | undefined
|
|
37
|
+
] ? ConvertValueToValidator<Val, "optional"> : never;
|
|
37
38
|
export declare const compileSchema: <T, E>(schema: Schema.Codec<T, E>) => ValueToValidator<(typeof schema)["Encoded"]>;
|
|
38
39
|
export declare const isRecursive: (ast: SchemaAST.AST) => boolean;
|
|
39
40
|
export declare const compileAst: (ast: SchemaAST.AST, isOptionalPropertyOfTypeLiteral?: boolean) => Effect.Effect<Validator<any, any, any>, UnsupportedSchemaTypeError | UnsupportedPropertySignatureKeyTypeError | IndexSignaturesAreNotSupportedError | MixedIndexAndPropertySignaturesAreNotSupportedError | OptionalTupleElementsAreNotSupportedError | EmptyTupleIsNotSupportedError | EmptyUnionIsNotSupportedError>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaToValidator.d.ts","sourceRoot":"","sources":["../src/SchemaToValidator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,SAAS,EACT,IAAI,EACJ,MAAM,EACN,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,GAAG,EACH,MAAM,EACN,QAAQ,EACR,KAAK,EACL,OAAO,EACP,
|
|
1
|
+
{"version":3,"file":"SchemaToValidator.d.ts","sourceRoot":"","sources":["../src/SchemaToValidator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,SAAS,EACT,IAAI,EACJ,MAAM,EACN,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,GAAG,EACH,MAAM,EACN,QAAQ,EACR,KAAK,EACL,OAAO,EACP,OAAO,EACP,OAAO,EACP,MAAM,EACP,MAAM,eAAe,CAAC;AAKvB,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAKxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAC;AAG9C,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EACV,KAAK,EACL,UAAU,EACV,QAAQ,EACR,WAAW,EACX,OAAO,EACP,SAAS,EACT,YAAY,EACb,MAAM,SAAS,CAAC;AAIjB,eAAO,MAAM,iBAAiB,GAAI,YAAY,EAAE,WAAW,cAC7C,MAAM,CAAC,KAAK,CAAC,YAAY,EAAE,WAAW,CAAC,KAClD,kBAcF,CAAC;AAI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AAa,mCAAoC,SAAQ,wCAExD;IAEC,IAAa,OAAO,WAEnB;CAEF;;;;AAED,qBAAa,mDAAoD,SAAQ,wDAExE;IAEC,IAAa,OAAO,WAEnB;CAEF;;;;AAED,qBAAa,yCAA0C,SAAQ,8CAE9D;IAEC,IAAa,OAAO,WAEnB;CAEF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaToValidator.js","names":["GenericId.tableName"],"sources":["../src/SchemaToValidator.ts"],"sourcesContent":["import type {\n PropertyValidators,\n Validator,\n VAny,\n VArray,\n VBoolean,\n VBytes,\n VFloat64,\n VId,\n VInt64,\n VLiteral,\n VNull,\n VObject,\n VOptional,\n VRecord,\n VString,\n VUnion,\n} from \"convex/values\";\nimport { v } from \"convex/values\";\nimport { pipe } from \"effect/Function\";\nimport * as Array from \"effect/Array\";\nimport * as Data from \"effect/Data\";\nimport * as Effect from \"effect/Effect\";\nimport * as Match from \"effect/Match\";\nimport * as Number from \"effect/Number\";\nimport * as Option from \"effect/Option\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Schema from \"effect/Schema\";\nimport * as SchemaAST from \"effect/SchemaAST\";\nimport * as String from \"effect/String\";\n\nimport * as GenericId from \"./GenericId\";\nimport type {\n IsAny,\n IsOptional,\n IsRecord,\n IsRecursive,\n IsUnion,\n TypeError,\n UnionToTuple,\n} from \"./Types\";\n\n// Args\n\nexport const compileArgsSchema = <ConfectValue, ConvexValue>(\n argsSchema: Schema.Codec<ConfectValue, ConvexValue>,\n): PropertyValidators => {\n const ast = Schema.toEncoded(argsSchema).ast;\n\n return pipe(\n ast,\n Match.value,\n Match.tag(\"Objects\", (objectsAst) =>\n Array.isReadonlyArrayEmpty(objectsAst.indexSignatures)\n ? handlePropertySignatures(objectsAst)\n : Effect.fail(new IndexSignaturesAreNotSupportedError()),\n ),\n Match.orElse(() => Effect.fail(new TopLevelMustBeObjectError())),\n Effect.runSync,\n );\n};\n\n// Returns\n\nexport const compileReturnsSchema = <ConfectValue, ConvexValue>(\n schema: Schema.Codec<ConfectValue, ConvexValue>,\n): Validator<any, any, any> =>\n Effect.runSync(compileAst(Schema.toEncoded(schema).ast));\n\n// Table\n\n/**\n * Convert a table `Schema` to a table `Validator`.\n */\nexport type TableSchemaToTableValidator<\n TableSchema extends Schema.Codec<any, any>,\n> =\n ValueToValidator<TableSchema[\"Encoded\"]> extends infer Vd extends\n | VObject<any, any, any, any>\n | VUnion<any, any, any, any>\n ? Vd\n : never;\n\nexport const compileTableSchema = <TableSchema extends Schema.Codec<any, any>>(\n schema: TableSchema,\n): TableSchemaToTableValidator<TableSchema> => {\n const ast = Schema.toEncoded(schema).ast;\n\n return pipe(\n ast,\n Match.value,\n Match.tag(\"Objects\", ({ indexSignatures }) =>\n Array.isReadonlyArrayEmpty(indexSignatures)\n ? // oxlint-disable-next-line effecttsgo/unsafe-effect-type-assertion -- The return type is derived from the input schema and cannot be recovered from the runtime AST.\n (compileAst(ast) as Effect.Effect<any>)\n : Effect.fail(new IndexSignaturesAreNotSupportedError()),\n ),\n Match.tag(\"Union\", (unionAst) => compileAst(unionAst)),\n Match.orElse(() => Effect.fail(new TopLevelMustBeObjectOrUnionError())),\n Effect.runSync,\n );\n};\n\n// Compiler\n\nexport type ReadonlyValue =\n | string\n | number\n | bigint\n | boolean\n | ArrayBuffer\n | ReadonlyArrayValue\n | ReadonlyRecordValue\n | null;\n\ntype ReadonlyArrayValue = readonly ReadonlyValue[];\n\nexport type ReadonlyRecordValue = {\n readonly [key: string]: ReadonlyValue | undefined;\n};\n\ntype MutableValue<T> =\n T extends ReadonlyArray<infer El>\n ? MutableValue<El>[]\n : T extends ReadonlyRecordValue\n ? { -readonly [K in keyof T]: MutableValue<Exclude<T[K], undefined>> }\n : T;\n\nexport type ValueToValidator<Vl> = [Vl] extends [never]\n ? never\n : IsAny<Vl> extends true\n ? VAny\n : [Vl] extends [null]\n ? VNull\n : [Vl] extends [boolean]\n ? [boolean] extends [Vl]\n ? VBoolean\n : VLiteral<Vl>\n : IsUnion<Vl> extends true\n ? IsRecursive<Vl> extends true\n ? VAny\n : [Vl] extends [ReadonlyValue]\n ? UnionValueToValidator<Vl>\n : TypeError<\"Provided value is not a valid Convex value\", Vl>\n : [Vl] extends [number]\n ? [number] extends [Vl]\n ? VFloat64\n : VLiteral<Vl>\n : [Vl] extends [bigint]\n ? [bigint] extends [Vl]\n ? VInt64\n : VLiteral<Vl>\n : [Vl] extends [string]\n ? Vl extends {\n __tableName: infer TableName extends string;\n }\n ? VId<GenericId.GenericId<TableName>>\n : [string] extends [Vl]\n ? VString\n : VLiteral<Vl>\n : [Vl] extends [ArrayBuffer]\n ? VBytes\n : IsRecursive<Vl> extends true\n ? VAny\n : [Vl] extends [ReadonlyValue]\n ? Vl extends ReadonlyArray<ReadonlyValue>\n ? ArrayValueToValidator<Vl>\n : Vl extends ReadonlyRecordValue\n ? RecordValueToValidator<Vl>\n : TypeError<\"Unexpected value\", Vl>\n : TypeError<\n \"Provided value is not a valid Convex value\",\n Vl\n >;\n\ntype ArrayValueToValidator<Vl extends ReadonlyArray<ReadonlyValue>> =\n Vl extends ReadonlyArray<infer El extends ReadonlyValue>\n ? ValueToValidator<El> extends infer Vd extends Validator<any, any, any>\n ? VArray<MutableValue<El[]>, Vd>\n : never\n : never;\n\ntype RecordValueToValidator<Vl> = Vl extends ReadonlyRecordValue\n ? {\n -readonly [K in keyof Vl]-?: IsAny<Vl[K]> extends true\n ? IsOptional<Vl, K> extends true\n ? VOptional<VAny>\n : VAny\n : UndefinedOrValueToValidator<Vl[K]>;\n } extends infer VdRecord extends Record<string, any>\n ? MutableValue<Vl> extends infer VlRecord extends Record<string, any>\n ? IsRecord<VlRecord> extends true\n ? VRecord<VlRecord, VString, VdRecord[keyof VdRecord]>\n : VObject<VlRecord, VdRecord>\n : never\n : never\n : never;\n\nexport type UndefinedOrValueToValidator<Vl extends ReadonlyValue | undefined> =\n undefined extends Vl\n ? [Vl] extends [(infer Val extends ReadonlyValue) | undefined]\n ? ValueToValidator<Val> extends infer Vd extends Validator<\n any,\n \"required\",\n any\n >\n ? VOptional<Vd>\n : never\n : never\n : [Vl] extends [ReadonlyValue]\n ? ValueToValidator<Vl>\n : never;\n\ntype UnionValueToValidator<Vl extends ReadonlyValue> = [Vl] extends [\n ReadonlyValue,\n]\n ? IsUnion<Vl> extends true\n ? UnionToTuple<Vl> extends infer VlTuple extends\n ReadonlyArray<ReadonlyValue>\n ? ValueTupleToValidatorTuple<VlTuple> extends infer VdTuple extends\n Validator<any, \"required\", any>[]\n ? VUnion<MutableValue<Vl>, VdTuple>\n : TypeError<\"Failed to convert value tuple to validator tuple\">\n : TypeError<\"Failed to convert union to tuple\">\n : TypeError<\"Expected a union of values, but got a single value instead\">\n : TypeError<\"Provided value is not a valid Convex value\">;\n\ntype ValueTupleToValidatorTuple<VlTuple extends ReadonlyArray<ReadonlyValue>> =\n VlTuple extends\n | [true, false, ...infer VlRest extends ReadonlyArray<ReadonlyValue>]\n | [false, true, ...infer VlRest extends ReadonlyArray<ReadonlyValue>]\n ? ValueTupleToValidatorTuple<VlRest> extends infer VdRest extends Validator<\n any,\n any,\n any\n >[]\n ? [VBoolean<boolean>, ...VdRest]\n : never\n : VlTuple extends [\n infer Vl extends ReadonlyValue,\n ...infer VlRest extends ReadonlyArray<ReadonlyValue>,\n ]\n ? ValueToValidator<Vl> extends infer Vd extends Validator<any, any, any>\n ? ValueTupleToValidatorTuple<VlRest> extends infer VdRest extends\n Validator<any, \"required\", any>[]\n ? [Vd, ...VdRest]\n : never\n : never\n : [];\n\nexport const compileSchema = <T, E>(\n schema: Schema.Codec<T, E>,\n): ValueToValidator<(typeof schema)[\"Encoded\"]> =>\n Effect.runSync(compileAst(schema.ast)) as any;\n\nexport const isRecursive = (ast: SchemaAST.AST): boolean =>\n pipe(\n ast,\n Match.value,\n Match.tag(\n \"Literal\",\n \"Null\",\n \"Boolean\",\n \"String\",\n \"Number\",\n \"BigInt\",\n \"Unknown\",\n \"Any\",\n \"Declaration\",\n \"UniqueSymbol\",\n \"Symbol\",\n \"Undefined\",\n \"Void\",\n \"Never\",\n \"Enum\",\n \"TemplateLiteral\",\n \"ObjectKeyword\",\n () => false,\n ),\n Match.tag(\"Union\", ({ types }) =>\n Array.some(types, (type) => isRecursive(type)),\n ),\n Match.tag(\"Objects\", ({ propertySignatures }) =>\n Array.some(propertySignatures, ({ type }) => isRecursive(type)),\n ),\n Match.tag(\n \"Arrays\",\n ({ elements, rest }) =>\n Array.some(elements, (element) => isRecursive(element)) ||\n Array.some(rest, (element) => isRecursive(element)),\n ),\n Match.tag(\"Suspend\", () => true),\n Match.exhaustive,\n );\n\nexport const compileAst = (\n ast: SchemaAST.AST,\n isOptionalPropertyOfTypeLiteral = false,\n): Effect.Effect<\n Validator<any, any, any>,\n | UnsupportedSchemaTypeError\n | UnsupportedPropertySignatureKeyTypeError\n | IndexSignaturesAreNotSupportedError\n | MixedIndexAndPropertySignaturesAreNotSupportedError\n | OptionalTupleElementsAreNotSupportedError\n | EmptyTupleIsNotSupportedError\n | EmptyUnionIsNotSupportedError\n> =>\n isRecursive(ast)\n ? Effect.succeed(v.any())\n : pipe(\n ast,\n Match.value,\n Match.tag(\"Literal\", ({ literal }) =>\n pipe(\n literal,\n Match.value,\n Match.whenOr(\n Match.string,\n Match.number,\n Match.bigint,\n Match.boolean,\n (l) => v.literal(l),\n ),\n Match.exhaustive,\n Effect.succeed,\n ),\n ),\n Match.tag(\"Null\", () => Effect.succeed(v.null())),\n Match.tag(\"Boolean\", () => Effect.succeed(v.boolean())),\n Match.tag(\"String\", (stringAst) =>\n GenericId.tableName(stringAst).pipe(\n Option.match({\n onNone: () => Effect.succeed(v.string()),\n onSome: (tableName) => Effect.succeed(v.id(tableName)),\n }),\n ),\n ),\n Match.tag(\"Number\", () => Effect.succeed(v.float64())),\n Match.tag(\"BigInt\", () => Effect.succeed(v.int64())),\n Match.tag(\"Union\", (unionAst) =>\n handleUnion(unionAst, isOptionalPropertyOfTypeLiteral),\n ),\n Match.tag(\"Objects\", (objectsAst) => handleObjects(objectsAst)),\n Match.tag(\"Arrays\", (arraysAst) => handleArrays(arraysAst)),\n Match.tag(\"Unknown\", \"Any\", () => Effect.succeed(v.any())),\n Match.tag(\"Declaration\", (declaration) =>\n Effect.mapBoth(\n // oxlint-disable-next-line effecttsgo/any-unknown-in-error-context -- Codec inputs are context-free, but Effect's SchemaAST.DeclarationRun erases their requirements to `any`.\n declaration.run(declaration.typeParameters)(\n new ArrayBuffer(0),\n declaration,\n {},\n ) as Effect.Effect<ArrayBuffer, unknown, never>,\n {\n onSuccess: () => v.bytes(),\n onFailure: () =>\n new UnsupportedSchemaTypeError({\n schemaType: declaration._tag,\n }),\n },\n ),\n ),\n Match.tag(\"Suspend\", () => Effect.succeed(v.any())),\n Match.tag(\n \"UniqueSymbol\",\n \"Symbol\",\n \"Undefined\",\n \"Void\",\n \"Never\",\n \"Enum\",\n \"TemplateLiteral\",\n \"ObjectKeyword\",\n () =>\n Effect.fail(\n new UnsupportedSchemaTypeError({\n schemaType: ast._tag,\n }),\n ),\n ),\n Match.exhaustive,\n );\n\nconst handleUnion = (\n { types }: SchemaAST.Union,\n isOptionalPropertyOfTypeLiteral: boolean,\n) => handleUnionTypes(types, isOptionalPropertyOfTypeLiteral);\n\nconst handleUnionTypes = Effect.fnUntraced(function* (\n types: SchemaAST.Union[\"types\"],\n isOptionalPropertyOfTypeLiteral: boolean,\n) {\n const members = isOptionalPropertyOfTypeLiteral\n ? Array.filter(types, Predicate.not(SchemaAST.isUndefined))\n : types;\n\n const [firstValidator, secondValidator, ...restValidators] =\n yield* Effect.all(Array.map(members, (type) => compileAst(type)));\n\n if (firstValidator === undefined) {\n return yield* new EmptyUnionIsNotSupportedError();\n } else if (secondValidator === undefined) {\n return firstValidator;\n } else {\n return v.union(firstValidator, secondValidator, ...restValidators);\n }\n});\n\nconst handleObjects = (objectsAst: SchemaAST.Objects) =>\n pipe(\n objectsAst.indexSignatures,\n Array.head,\n Option.match({\n onNone: () => Effect.map(handlePropertySignatures(objectsAst), v.object),\n onSome: ({ parameter, type }) =>\n pipe(\n objectsAst.propertySignatures,\n Array.head,\n Option.match({\n onNone: () =>\n Effect.map(\n Effect.all({\n parameter_: compileAst(parameter),\n type_: compileAst(type),\n }),\n ({ parameter_, type_ }) => v.record(parameter_, type_),\n ),\n onSome: () =>\n Effect.fail(\n new MixedIndexAndPropertySignaturesAreNotSupportedError(),\n ),\n }),\n ),\n }),\n );\n\nconst handleArrays = ({ elements, rest }: SchemaAST.Arrays) =>\n handleArrayElements(elements, rest);\n\nconst handleArrayElements = Effect.fnUntraced(function* (\n elements: SchemaAST.Arrays[\"elements\"],\n rest: SchemaAST.Arrays[\"rest\"],\n) {\n const [f, s, ...r] = elements;\n\n const elementToValidator = (element: SchemaAST.AST) =>\n SchemaAST.isOptional(element)\n ? Effect.fail(new OptionalTupleElementsAreNotSupportedError())\n : compileAst(element);\n\n const arrayItemsValidator = yield* f === undefined\n ? pipe(\n rest,\n Array.head,\n Option.match({\n onNone: () => Effect.fail(new EmptyTupleIsNotSupportedError()),\n onSome: (type) => compileAst(type),\n }),\n )\n : s === undefined\n ? elementToValidator(f)\n : Effect.gen(function* () {\n const firstValidator = yield* elementToValidator(f);\n const secondValidator = yield* elementToValidator(s);\n const restValidators = yield* Effect.forEach(r, elementToValidator);\n\n return v.union(firstValidator, secondValidator, ...restValidators);\n });\n\n return v.array(arrayItemsValidator);\n});\n\nconst handlePropertySignatures = (objectsAst: SchemaAST.Objects) =>\n pipe(\n objectsAst.propertySignatures,\n Effect.forEach(({ type, name }) => {\n const isOptional = SchemaAST.isOptional(type);\n if (String.isString(name)) {\n // Somehow, somewhere, keys of type number are being coerced to strings…\n return Option.match(Number.parse(name), {\n onNone: () =>\n Effect.gen(function* () {\n const validator = yield* compileAst(type, isOptional);\n\n return {\n propertyName: name,\n validator: isOptional ? v.optional(validator) : validator,\n };\n }),\n onSome: (number) =>\n Effect.fail(\n new UnsupportedPropertySignatureKeyTypeError({\n propertyKey: number,\n }),\n ),\n });\n } else {\n return Effect.fail(\n new UnsupportedPropertySignatureKeyTypeError({ propertyKey: name }),\n );\n }\n }),\n Effect.andThen((propertyNamesWithValidators) =>\n pipe(\n propertyNamesWithValidators,\n Array.reduce(\n {} as Record<string, Validator<any, any, any>>,\n (acc, { propertyName, validator }) => ({\n [propertyName]: validator,\n ...acc,\n }),\n ),\n Effect.succeed,\n ),\n ),\n );\n\n// Errors\n\nexport class TopLevelMustBeObjectError extends Data.TaggedError(\n \"TopLevelMustBeObjectError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Top level schema must be an object\";\n }\n /* v8 ignore stop */\n}\n\nexport class TopLevelMustBeObjectOrUnionError extends Data.TaggedError(\n \"TopLevelMustBeObjectOrUnionError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Top level schema must be an object or a union\";\n }\n /* v8 ignore stop */\n}\n\nexport class UnsupportedPropertySignatureKeyTypeError extends Data.TaggedError(\n \"UnsupportedPropertySignatureKeyTypeError\",\n)<{\n readonly propertyKey: number | symbol;\n}> {\n /* v8 ignore start */\n override get message() {\n return `Unsupported property signature '${this.propertyKey.toString()}'. Property is of type '${typeof this.propertyKey}' but only 'string' properties are supported.`;\n }\n /* v8 ignore stop */\n}\n\nexport class EmptyTupleIsNotSupportedError extends Data.TaggedError(\n \"EmptyTupleIsNotSupportedError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Tuple must have at least one element\";\n }\n /* v8 ignore stop */\n}\n\nexport class EmptyUnionIsNotSupportedError extends Data.TaggedError(\n \"EmptyUnionIsNotSupportedError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Union must have at least one member that compiles to a validator\";\n }\n /* v8 ignore stop */\n}\n\nexport class UnsupportedSchemaTypeError extends Data.TaggedError(\n \"UnsupportedSchemaTypeError\",\n)<{\n readonly schemaType: SchemaAST.AST[\"_tag\"];\n}> {\n /* v8 ignore start */\n override get message() {\n return `Unsupported schema type '${this.schemaType}'`;\n }\n /* v8 ignore stop */\n}\n\nexport class IndexSignaturesAreNotSupportedError extends Data.TaggedError(\n \"IndexSignaturesAreNotSupportedError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Index signatures are not supported\";\n }\n /* v8 ignore stop */\n}\n\nexport class MixedIndexAndPropertySignaturesAreNotSupportedError extends Data.TaggedError(\n \"MixedIndexAndPropertySignaturesAreNotSupportedError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Mixed index and property signatures are not supported\";\n }\n /* v8 ignore stop */\n}\n\nexport class OptionalTupleElementsAreNotSupportedError extends Data.TaggedError(\n \"OptionalTupleElementsAreNotSupportedError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Optional tuple elements are not supported\";\n }\n /* v8 ignore stop */\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,MAAa,qBACX,eACuB;CACvB,MAAM,MAAM,OAAO,UAAU,UAAU,CAAC,CAAC;CAEzC,OAAO,KACL,KACA,MAAM,OACN,MAAM,IAAI,YAAY,eACpB,MAAM,qBAAqB,WAAW,eAAe,IACjD,yBAAyB,UAAU,IACnC,OAAO,KAAK,IAAI,oCAAoC,CAAC,CAC3D,GACA,MAAM,aAAa,OAAO,KAAK,IAAI,0BAA0B,CAAC,CAAC,GAC/D,OAAO,OACT;AACF;AAIA,MAAa,wBACX,WAEA,OAAO,QAAQ,WAAW,OAAO,UAAU,MAAM,CAAC,CAAC,GAAG,CAAC;AAgBzD,MAAa,sBACX,WAC6C;CAC7C,MAAM,MAAM,OAAO,UAAU,MAAM,CAAC,CAAC;CAErC,OAAO,KACL,KACA,MAAM,OACN,MAAM,IAAI,YAAY,EAAE,sBACtB,MAAM,qBAAqB,eAAe,IAErC,WAAW,GAAG,IACf,OAAO,KAAK,IAAI,oCAAoC,CAAC,CAC3D,GACA,MAAM,IAAI,UAAU,aAAa,WAAW,QAAQ,CAAC,GACrD,MAAM,aAAa,OAAO,KAAK,IAAI,iCAAiC,CAAC,CAAC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D,KAAK,YAC5D,qCACF,CAAC,CAAC;;CAEA,IAAa,UAAU;EACrB,OAAO;CACT;AAEF;AAEA,IAAa,sDAAb,cAAyE,KAAK,YAC5E,qDACF,CAAC,CAAC;;CAEA,IAAa,UAAU;EACrB,OAAO;CACT;AAEF;AAEA,IAAa,4CAAb,cAA+D,KAAK,YAClE,2CACF,CAAC,CAAC;;CAEA,IAAa,UAAU;EACrB,OAAO;CACT;AAEF"}
|
|
1
|
+
{"version":3,"file":"SchemaToValidator.js","names":["GenericId.tableName"],"sources":["../src/SchemaToValidator.ts"],"sourcesContent":["import type {\n PropertyValidators,\n Validator,\n VAny,\n VArray,\n VBoolean,\n VBytes,\n VFloat64,\n VId,\n VInt64,\n VLiteral,\n VNull,\n VObject,\n VRecord,\n VString,\n VUnion,\n} from \"convex/values\";\nimport { v } from \"convex/values\";\nimport { pipe } from \"effect/Function\";\nimport * as Array from \"effect/Array\";\nimport * as Data from \"effect/Data\";\nimport * as Effect from \"effect/Effect\";\nimport * as Match from \"effect/Match\";\nimport * as Number from \"effect/Number\";\nimport * as Option from \"effect/Option\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Schema from \"effect/Schema\";\nimport * as SchemaAST from \"effect/SchemaAST\";\nimport * as String from \"effect/String\";\n\nimport * as GenericId from \"./GenericId\";\nimport type {\n IsAny,\n IsOptional,\n IsRecord,\n IsRecursive,\n IsUnion,\n TypeError,\n UnionToTuple,\n} from \"./Types\";\n\n// Args\n\nexport const compileArgsSchema = <ConfectValue, ConvexValue>(\n argsSchema: Schema.Codec<ConfectValue, ConvexValue>,\n): PropertyValidators => {\n const ast = Schema.toEncoded(argsSchema).ast;\n\n return pipe(\n ast,\n Match.value,\n Match.tag(\"Objects\", (objectsAst) =>\n Array.isReadonlyArrayEmpty(objectsAst.indexSignatures)\n ? handlePropertySignatures(objectsAst)\n : Effect.fail(new IndexSignaturesAreNotSupportedError()),\n ),\n Match.orElse(() => Effect.fail(new TopLevelMustBeObjectError())),\n Effect.runSync,\n );\n};\n\n// Returns\n\nexport const compileReturnsSchema = <ConfectValue, ConvexValue>(\n schema: Schema.Codec<ConfectValue, ConvexValue>,\n): Validator<any, any, any> =>\n Effect.runSync(compileAst(Schema.toEncoded(schema).ast));\n\n// Table\n\n/**\n * Convert a table `Schema` to a table `Validator`.\n */\nexport type TableSchemaToTableValidator<\n TableSchema extends Schema.Codec<any, any>,\n> =\n ValueToValidator<TableSchema[\"Encoded\"]> extends infer Vd extends\n | VObject<any, any, any, any>\n | VUnion<any, any, any, any>\n ? Vd\n : never;\n\nexport const compileTableSchema = <TableSchema extends Schema.Codec<any, any>>(\n schema: TableSchema,\n): TableSchemaToTableValidator<TableSchema> => {\n const ast = Schema.toEncoded(schema).ast;\n\n return pipe(\n ast,\n Match.value,\n Match.tag(\"Objects\", ({ indexSignatures }) =>\n Array.isReadonlyArrayEmpty(indexSignatures)\n ? // oxlint-disable-next-line effecttsgo/unsafe-effect-type-assertion -- The return type is derived from the input schema and cannot be recovered from the runtime AST.\n (compileAst(ast) as Effect.Effect<any>)\n : Effect.fail(new IndexSignaturesAreNotSupportedError()),\n ),\n Match.tag(\"Union\", (unionAst) => compileAst(unionAst)),\n Match.orElse(() => Effect.fail(new TopLevelMustBeObjectOrUnionError())),\n Effect.runSync,\n );\n};\n\n// Compiler\n\nexport type ReadonlyValue =\n | string\n | number\n | bigint\n | boolean\n | ArrayBuffer\n | ReadonlyArrayValue\n | ReadonlyRecordValue\n | null;\n\ntype ReadonlyArrayValue = readonly ReadonlyValue[];\n\nexport type ReadonlyRecordValue = {\n readonly [key: string]: ReadonlyValue | undefined;\n};\n\ntype MutableValue<T> =\n T extends ReadonlyArray<infer El>\n ? MutableValue<El>[]\n : T extends ReadonlyRecordValue\n ? { -readonly [K in keyof T]: MutableValue<Exclude<T[K], undefined>> }\n : T;\n\nexport type ValueToValidator<Vl> = [Vl] extends [never]\n ? never\n : IsAny<Vl> extends true\n ? VAny\n : [Vl] extends [string | number | bigint | boolean | null | ArrayBuffer]\n ? ConvertValueToValidator<Vl>\n : IsRecursive<Vl> extends true\n ? VAny\n : [Vl] extends [ReadonlyValue]\n ? ConvertValueToValidator<Vl>\n : TypeError<\"Provided value is not a valid Convex value\", Vl>;\n\ntype OptionalValue<Vl, Optionality> = Optionality extends \"optional\"\n ? Vl | undefined\n : Vl;\n\ntype ConvertValueToValidator<\n Vl,\n Optionality extends \"required\" | \"optional\" = \"required\",\n> = [Vl] extends [never]\n ? never\n : IsAny<Vl> extends true\n ? VAny<any, Optionality>\n : [Vl] extends [null]\n ? VNull<OptionalValue<null, Optionality>, Optionality>\n : [Vl] extends [boolean]\n ? [boolean] extends [Vl]\n ? VBoolean<OptionalValue<boolean, Optionality>, Optionality>\n : VLiteral<OptionalValue<Vl, Optionality>, Optionality>\n : IsUnion<Vl> extends true\n ? UnionValueToValidator<Vl, Optionality>\n : [Vl] extends [number]\n ? [number] extends [Vl]\n ? VFloat64<OptionalValue<number, Optionality>, Optionality>\n : VLiteral<OptionalValue<Vl, Optionality>, Optionality>\n : [Vl] extends [bigint]\n ? [bigint] extends [Vl]\n ? VInt64<OptionalValue<bigint, Optionality>, Optionality>\n : VLiteral<OptionalValue<Vl, Optionality>, Optionality>\n : [Vl] extends [string]\n ? StringValueToValidator<Vl, Optionality>\n : [Vl] extends [ArrayBuffer]\n ? VBytes<OptionalValue<ArrayBuffer, Optionality>, Optionality>\n : IsRecursive<Vl> extends true\n ? VAny<any, Optionality>\n : Vl extends ReadonlyArray<infer El>\n ? VArray<\n OptionalValue<MutableValue<El[]>, Optionality>,\n ConvertValueToValidator<El>,\n Optionality\n >\n : Vl extends object\n ? ObjectValueToValidator<Vl, Optionality>\n : never;\n\ntype StringValueToValidator<\n Vl,\n Optionality extends \"required\" | \"optional\",\n> = Vl extends { __tableName: infer TableName extends string }\n ? VId<OptionalValue<GenericId.GenericId<TableName>, Optionality>, Optionality>\n : [string] extends [Vl]\n ? VString<OptionalValue<string, Optionality>, Optionality>\n : VLiteral<OptionalValue<Vl, Optionality>, Optionality>;\n\ntype ObjectValueToValidator<Vl, Optionality extends \"required\" | \"optional\"> =\n IsRecord<MutableValue<Vl>> extends true\n ? ValueToValidator<Vl[keyof Vl]> extends infer VdValue extends Validator<\n any,\n \"required\",\n any\n >\n ? VRecord<\n OptionalValue<MutableValue<Vl>, Optionality>,\n VString,\n VdValue,\n Optionality\n >\n : never\n : ObjectFieldsToValidators<Vl> extends infer VdFields extends Record<\n string,\n any\n >\n ? VObject<\n OptionalValue<MutableValue<Vl>, Optionality>,\n VdFields,\n Optionality\n >\n : never;\n\ntype ObjectFieldsToValidators<Vl> = {\n -readonly [K in keyof Vl]-?: IsAny<Vl[K]> extends true\n ? IsOptional<Vl, K> extends true\n ? VAny<any, \"optional\">\n : VAny\n : undefined extends Vl[K]\n ? OptionalValueToValidator<Vl[K]>\n : [Vl[K]] extends [ReadonlyValue]\n ? ConvertValueToValidator<Vl[K]>\n : never;\n};\n\nexport type UndefinedOrValueToValidator<Vl extends ReadonlyValue | undefined> =\n undefined extends Vl\n ? OptionalValueToValidator<Vl>\n : [Vl] extends [ReadonlyValue]\n ? ValueToValidator<Vl>\n : never;\n\ntype UnionValueToValidator<Vl, Optionality extends \"required\" | \"optional\"> =\n IsRecursive<Vl> extends true\n ? VAny<any, Optionality>\n : VUnion<\n OptionalValue<MutableValue<Vl>, Optionality>,\n ValueTupleToValidatorTuple<UnionToTuple<Vl>>,\n Optionality\n >;\n\ntype ValueTupleToValidatorTuple<\n VlTuple extends readonly unknown[],\n Acc extends Validator<any, \"required\", any>[] = [],\n> = VlTuple extends\n | [true, false, ...infer VlRest]\n | [false, true, ...infer VlRest]\n ? ValueTupleToValidatorTuple<VlRest, [...Acc, VBoolean]>\n : VlTuple extends [infer Vl, ...infer VlRest]\n ? ValueTupleToValidatorTuple<VlRest, [...Acc, ConvertValueToValidator<Vl>]>\n : Acc;\n\ntype OptionalValueToValidator<Vl> = [Vl] extends [\n (infer Val extends ReadonlyValue) | undefined,\n]\n ? ConvertValueToValidator<Val, \"optional\">\n : never;\n\nexport const compileSchema = <T, E>(\n schema: Schema.Codec<T, E>,\n): ValueToValidator<(typeof schema)[\"Encoded\"]> =>\n Effect.runSync(compileAst(schema.ast)) as any;\n\nexport const isRecursive = (ast: SchemaAST.AST): boolean =>\n pipe(\n ast,\n Match.value,\n Match.tag(\n \"Literal\",\n \"Null\",\n \"Boolean\",\n \"String\",\n \"Number\",\n \"BigInt\",\n \"Unknown\",\n \"Any\",\n \"Declaration\",\n \"UniqueSymbol\",\n \"Symbol\",\n \"Undefined\",\n \"Void\",\n \"Never\",\n \"Enum\",\n \"TemplateLiteral\",\n \"ObjectKeyword\",\n () => false,\n ),\n Match.tag(\"Union\", ({ types }) =>\n Array.some(types, (type) => isRecursive(type)),\n ),\n Match.tag(\"Objects\", ({ propertySignatures }) =>\n Array.some(propertySignatures, ({ type }) => isRecursive(type)),\n ),\n Match.tag(\n \"Arrays\",\n ({ elements, rest }) =>\n Array.some(elements, (element) => isRecursive(element)) ||\n Array.some(rest, (element) => isRecursive(element)),\n ),\n Match.tag(\"Suspend\", () => true),\n Match.exhaustive,\n );\n\nexport const compileAst = (\n ast: SchemaAST.AST,\n isOptionalPropertyOfTypeLiteral = false,\n): Effect.Effect<\n Validator<any, any, any>,\n | UnsupportedSchemaTypeError\n | UnsupportedPropertySignatureKeyTypeError\n | IndexSignaturesAreNotSupportedError\n | MixedIndexAndPropertySignaturesAreNotSupportedError\n | OptionalTupleElementsAreNotSupportedError\n | EmptyTupleIsNotSupportedError\n | EmptyUnionIsNotSupportedError\n> =>\n isRecursive(ast)\n ? Effect.succeed(v.any())\n : pipe(\n ast,\n Match.value,\n Match.tag(\"Literal\", ({ literal }) =>\n pipe(\n literal,\n Match.value,\n Match.whenOr(\n Match.string,\n Match.number,\n Match.bigint,\n Match.boolean,\n (l) => v.literal(l),\n ),\n Match.exhaustive,\n Effect.succeed,\n ),\n ),\n Match.tag(\"Null\", () => Effect.succeed(v.null())),\n Match.tag(\"Boolean\", () => Effect.succeed(v.boolean())),\n Match.tag(\"String\", (stringAst) =>\n GenericId.tableName(stringAst).pipe(\n Option.match({\n onNone: () => Effect.succeed(v.string()),\n onSome: (tableName) => Effect.succeed(v.id(tableName)),\n }),\n ),\n ),\n Match.tag(\"Number\", () => Effect.succeed(v.float64())),\n Match.tag(\"BigInt\", () => Effect.succeed(v.int64())),\n Match.tag(\"Union\", (unionAst) =>\n handleUnion(unionAst, isOptionalPropertyOfTypeLiteral),\n ),\n Match.tag(\"Objects\", (objectsAst) => handleObjects(objectsAst)),\n Match.tag(\"Arrays\", (arraysAst) => handleArrays(arraysAst)),\n Match.tag(\"Unknown\", \"Any\", () => Effect.succeed(v.any())),\n Match.tag(\"Declaration\", (declaration) =>\n Effect.mapBoth(\n // oxlint-disable-next-line effecttsgo/any-unknown-in-error-context -- Codec inputs are context-free, but Effect's SchemaAST.DeclarationRun erases their requirements to `any`.\n declaration.run(declaration.typeParameters)(\n new ArrayBuffer(0),\n declaration,\n {},\n ) as Effect.Effect<ArrayBuffer, unknown, never>,\n {\n onSuccess: () => v.bytes(),\n onFailure: () =>\n new UnsupportedSchemaTypeError({\n schemaType: declaration._tag,\n }),\n },\n ),\n ),\n Match.tag(\"Suspend\", () => Effect.succeed(v.any())),\n Match.tag(\n \"UniqueSymbol\",\n \"Symbol\",\n \"Undefined\",\n \"Void\",\n \"Never\",\n \"Enum\",\n \"TemplateLiteral\",\n \"ObjectKeyword\",\n () =>\n Effect.fail(\n new UnsupportedSchemaTypeError({\n schemaType: ast._tag,\n }),\n ),\n ),\n Match.exhaustive,\n );\n\nconst handleUnion = (\n { types }: SchemaAST.Union,\n isOptionalPropertyOfTypeLiteral: boolean,\n) => handleUnionTypes(types, isOptionalPropertyOfTypeLiteral);\n\nconst handleUnionTypes = Effect.fnUntraced(function* (\n types: SchemaAST.Union[\"types\"],\n isOptionalPropertyOfTypeLiteral: boolean,\n) {\n const members = isOptionalPropertyOfTypeLiteral\n ? Array.filter(types, Predicate.not(SchemaAST.isUndefined))\n : types;\n\n const [firstValidator, secondValidator, ...restValidators] =\n yield* Effect.all(Array.map(members, (type) => compileAst(type)));\n\n if (firstValidator === undefined) {\n return yield* new EmptyUnionIsNotSupportedError();\n } else if (secondValidator === undefined) {\n return firstValidator;\n } else {\n return v.union(firstValidator, secondValidator, ...restValidators);\n }\n});\n\nconst handleObjects = (objectsAst: SchemaAST.Objects) =>\n pipe(\n objectsAst.indexSignatures,\n Array.head,\n Option.match({\n onNone: () => Effect.map(handlePropertySignatures(objectsAst), v.object),\n onSome: ({ parameter, type }) =>\n pipe(\n objectsAst.propertySignatures,\n Array.head,\n Option.match({\n onNone: () =>\n Effect.map(\n Effect.all({\n parameter_: compileAst(parameter),\n type_: compileAst(type),\n }),\n ({ parameter_, type_ }) => v.record(parameter_, type_),\n ),\n onSome: () =>\n Effect.fail(\n new MixedIndexAndPropertySignaturesAreNotSupportedError(),\n ),\n }),\n ),\n }),\n );\n\nconst handleArrays = ({ elements, rest }: SchemaAST.Arrays) =>\n handleArrayElements(elements, rest);\n\nconst handleArrayElements = Effect.fnUntraced(function* (\n elements: SchemaAST.Arrays[\"elements\"],\n rest: SchemaAST.Arrays[\"rest\"],\n) {\n const [f, s, ...r] = elements;\n\n const elementToValidator = (element: SchemaAST.AST) =>\n SchemaAST.isOptional(element)\n ? Effect.fail(new OptionalTupleElementsAreNotSupportedError())\n : compileAst(element);\n\n const arrayItemsValidator = yield* f === undefined\n ? pipe(\n rest,\n Array.head,\n Option.match({\n onNone: () => Effect.fail(new EmptyTupleIsNotSupportedError()),\n onSome: (type) => compileAst(type),\n }),\n )\n : s === undefined\n ? elementToValidator(f)\n : Effect.gen(function* () {\n const firstValidator = yield* elementToValidator(f);\n const secondValidator = yield* elementToValidator(s);\n const restValidators = yield* Effect.forEach(r, elementToValidator);\n\n return v.union(firstValidator, secondValidator, ...restValidators);\n });\n\n return v.array(arrayItemsValidator);\n});\n\nconst handlePropertySignatures = (objectsAst: SchemaAST.Objects) =>\n pipe(\n objectsAst.propertySignatures,\n Effect.forEach(({ type, name }) => {\n const isOptional = SchemaAST.isOptional(type);\n if (String.isString(name)) {\n // Somehow, somewhere, keys of type number are being coerced to strings…\n return Option.match(Number.parse(name), {\n onNone: () =>\n Effect.gen(function* () {\n const validator = yield* compileAst(type, isOptional);\n\n return {\n propertyName: name,\n validator: isOptional ? v.optional(validator) : validator,\n };\n }),\n onSome: (number) =>\n Effect.fail(\n new UnsupportedPropertySignatureKeyTypeError({\n propertyKey: number,\n }),\n ),\n });\n } else {\n return Effect.fail(\n new UnsupportedPropertySignatureKeyTypeError({ propertyKey: name }),\n );\n }\n }),\n Effect.andThen((propertyNamesWithValidators) =>\n pipe(\n propertyNamesWithValidators,\n Array.reduce(\n {} as Record<string, Validator<any, any, any>>,\n (acc, { propertyName, validator }) => ({\n [propertyName]: validator,\n ...acc,\n }),\n ),\n Effect.succeed,\n ),\n ),\n );\n\n// Errors\n\nexport class TopLevelMustBeObjectError extends Data.TaggedError(\n \"TopLevelMustBeObjectError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Top level schema must be an object\";\n }\n /* v8 ignore stop */\n}\n\nexport class TopLevelMustBeObjectOrUnionError extends Data.TaggedError(\n \"TopLevelMustBeObjectOrUnionError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Top level schema must be an object or a union\";\n }\n /* v8 ignore stop */\n}\n\nexport class UnsupportedPropertySignatureKeyTypeError extends Data.TaggedError(\n \"UnsupportedPropertySignatureKeyTypeError\",\n)<{\n readonly propertyKey: number | symbol;\n}> {\n /* v8 ignore start */\n override get message() {\n return `Unsupported property signature '${this.propertyKey.toString()}'. Property is of type '${typeof this.propertyKey}' but only 'string' properties are supported.`;\n }\n /* v8 ignore stop */\n}\n\nexport class EmptyTupleIsNotSupportedError extends Data.TaggedError(\n \"EmptyTupleIsNotSupportedError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Tuple must have at least one element\";\n }\n /* v8 ignore stop */\n}\n\nexport class EmptyUnionIsNotSupportedError extends Data.TaggedError(\n \"EmptyUnionIsNotSupportedError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Union must have at least one member that compiles to a validator\";\n }\n /* v8 ignore stop */\n}\n\nexport class UnsupportedSchemaTypeError extends Data.TaggedError(\n \"UnsupportedSchemaTypeError\",\n)<{\n readonly schemaType: SchemaAST.AST[\"_tag\"];\n}> {\n /* v8 ignore start */\n override get message() {\n return `Unsupported schema type '${this.schemaType}'`;\n }\n /* v8 ignore stop */\n}\n\nexport class IndexSignaturesAreNotSupportedError extends Data.TaggedError(\n \"IndexSignaturesAreNotSupportedError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Index signatures are not supported\";\n }\n /* v8 ignore stop */\n}\n\nexport class MixedIndexAndPropertySignaturesAreNotSupportedError extends Data.TaggedError(\n \"MixedIndexAndPropertySignaturesAreNotSupportedError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Mixed index and property signatures are not supported\";\n }\n /* v8 ignore stop */\n}\n\nexport class OptionalTupleElementsAreNotSupportedError extends Data.TaggedError(\n \"OptionalTupleElementsAreNotSupportedError\",\n) {\n /* v8 ignore start */\n override get message() {\n return \"Optional tuple elements are not supported\";\n }\n /* v8 ignore stop */\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,MAAa,qBACX,eACuB;CACvB,MAAM,MAAM,OAAO,UAAU,UAAU,CAAC,CAAC;CAEzC,OAAO,KACL,KACA,MAAM,OACN,MAAM,IAAI,YAAY,eACpB,MAAM,qBAAqB,WAAW,eAAe,IACjD,yBAAyB,UAAU,IACnC,OAAO,KAAK,IAAI,oCAAoC,CAAC,CAC3D,GACA,MAAM,aAAa,OAAO,KAAK,IAAI,0BAA0B,CAAC,CAAC,GAC/D,OAAO,OACT;AACF;AAIA,MAAa,wBACX,WAEA,OAAO,QAAQ,WAAW,OAAO,UAAU,MAAM,CAAC,CAAC,GAAG,CAAC;AAgBzD,MAAa,sBACX,WAC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,+BACF,CAAC,CAAC;;CAEA,IAAa,UAAU;EACrB,OAAO;CACT;AAEF;AAEA,IAAa,gCAAb,cAAmD,KAAK,YACtD,+BACF,CAAC,CAAC;;CAEA,IAAa,UAAU;EACrB,OAAO;CACT;AAEF;AAEA,IAAa,6BAAb,cAAgD,KAAK,YACnD,4BACF,CAAC,CAEE;;CAED,IAAa,UAAU;EACrB,OAAO,4BAA4B,KAAK,WAAW;CACrD;AAEF;AAEA,IAAa,sCAAb,cAAyD,KAAK,YAC5D,qCACF,CAAC,CAAC;;CAEA,IAAa,UAAU;EACrB,OAAO;CACT;AAEF;AAEA,IAAa,sDAAb,cAAyE,KAAK,YAC5E,qDACF,CAAC,CAAC;;CAEA,IAAa,UAAU;EACrB,OAAO;CACT;AAEF;AAEA,IAAa,4CAAb,cAA+D,KAAK,YAClE,2CACF,CAAC,CAAC;;CAEA,IAAa,UAAU;EACrB,OAAO;CACT;AAEF"}
|
package/dist/Spec.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as Record from "effect/Record";
|
|
2
|
-
import * as Struct from "effect/Struct";
|
|
3
2
|
import * as GroupSpec from "./GroupSpec";
|
|
4
3
|
export declare const TypeId = "~@confect/core/Spec";
|
|
5
4
|
export type TypeId = typeof TypeId;
|
|
@@ -13,8 +12,6 @@ export declare const isSpec: (u: unknown) => u is AnyWithProps;
|
|
|
13
12
|
*/
|
|
14
13
|
export interface Spec<Groups_ extends Record.ReadonlyRecord<string, GroupSpec.AnyWithProps> = {}> {
|
|
15
14
|
readonly [TypeId]: Readonly<Groups_>;
|
|
16
|
-
add<Group extends GroupSpec.AnyWithProps>(group: Group): Spec<Struct.Assign<Groups_, Record.ReadonlyRecord<GroupSpec.Name<Group>, Group>>>;
|
|
17
|
-
addAt<const Name extends string, Group extends GroupSpec.AnyWithProps>(name: Name, group: Group): Spec<Struct.Assign<Groups_, Record.ReadonlyRecord<Name, GroupSpec.NamedAt<Group, Name>>>>;
|
|
18
15
|
}
|
|
19
16
|
export interface Any {
|
|
20
17
|
readonly [TypeId]: unknown;
|
|
@@ -27,5 +24,5 @@ export type Groups<Spec_ extends AnyWithProps> = Spec_[TypeId][keyof Spec_[TypeI
|
|
|
27
24
|
* The group record stored by a spec, with its precise member types.
|
|
28
25
|
*/
|
|
29
26
|
export declare const groups: <Spec_ extends AnyWithProps>(self: Spec_) => Spec_[TypeId];
|
|
30
|
-
export declare const
|
|
27
|
+
export declare const fromGroups: (record: Record.ReadonlyRecord<string, GroupSpec.AnyWithProps>) => AnyWithProps;
|
|
31
28
|
//# sourceMappingURL=Spec.d.ts.map
|
package/dist/Spec.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Spec.d.ts","sourceRoot":"","sources":["../src/Spec.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"Spec.d.ts","sourceRoot":"","sources":["../src/Spec.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AAEzC,eAAO,MAAM,MAAM,wBAAwB,CAAC;AAC5C,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC;AAEnC,eAAO,MAAM,MAAM,MAAO,OAAO,KAAG,CAAC,IAAI,YACP,CAAC;AAEnC;;;;;;GAMG;AACH,MAAM,WAAW,IAAI,CACnB,OAAO,SAAS,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,SAAS,CAAC,YAAY,CAAC,GAAG,EAAE;IAE1E,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;CACtC;AAED,MAAM,WAAW,GAAG;IAClB,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,YAAa,SAAQ,GAAG;IACvC,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,SAAS,CAAC,YAAY,CAAC,CAAC;CAC1E;AAED,MAAM,MAAM,MAAM,CAAC,KAAK,SAAS,YAAY,IAC3C,KAAK,CAAC,MAAM,CAAC,CAAC,MAAM,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;AAErC;;GAEG;AACH,eAAO,MAAM,MAAM,GAAI,KAAK,SAAS,YAAY,QACzC,KAAK,KACV,KAAK,CAAC,MAAM,CAAiB,CAAC;AAEjC,eAAO,MAAM,UAAU,WACb,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,SAAS,CAAC,YAAY,CAAC,KAC5D,YAID,CAAC"}
|
package/dist/Spec.js
CHANGED
|
@@ -2,13 +2,12 @@ import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
|
2
2
|
import { withName } from "./GroupSpec.js";
|
|
3
3
|
import * as Predicate from "effect/Predicate";
|
|
4
4
|
import * as Record from "effect/Record";
|
|
5
|
-
import * as Struct from "effect/Struct";
|
|
6
5
|
//#region src/Spec.ts
|
|
7
6
|
var Spec_exports = /* @__PURE__ */ __exportAll({
|
|
8
7
|
TypeId: () => TypeId,
|
|
8
|
+
fromGroups: () => fromGroups,
|
|
9
9
|
groups: () => groups,
|
|
10
|
-
isSpec: () => isSpec
|
|
11
|
-
make: () => make
|
|
10
|
+
isSpec: () => isSpec
|
|
12
11
|
});
|
|
13
12
|
const TypeId = "~@confect/core/Spec";
|
|
14
13
|
const isSpec = (u) => Predicate.hasProperty(u, TypeId);
|
|
@@ -16,17 +15,8 @@ const isSpec = (u) => Predicate.hasProperty(u, TypeId);
|
|
|
16
15
|
* The group record stored by a spec, with its precise member types.
|
|
17
16
|
*/
|
|
18
17
|
const groups = (self) => self[TypeId];
|
|
19
|
-
const
|
|
20
|
-
[TypeId]: record,
|
|
21
|
-
add(group) {
|
|
22
|
-
return makeRecord(Struct.assign(record, Record.singleton(group.name, group)));
|
|
23
|
-
},
|
|
24
|
-
addAt(name, group) {
|
|
25
|
-
return makeRecord(Struct.assign(record, Record.singleton(name, withName(name, group))));
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
const make = () => makeRecord({});
|
|
18
|
+
const fromGroups = (record) => ({ [TypeId]: Record.map(record, (group, name) => withName(name, group)) });
|
|
29
19
|
//#endregion
|
|
30
|
-
export { Spec_exports, TypeId, groups, isSpec
|
|
20
|
+
export { Spec_exports, TypeId, fromGroups, groups, isSpec };
|
|
31
21
|
|
|
32
22
|
//# sourceMappingURL=Spec.js.map
|
package/dist/Spec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Spec.js","names":["GroupSpec.withName"],"sources":["../src/Spec.ts"],"sourcesContent":["import * as Predicate from \"effect/Predicate\";\nimport * as Record from \"effect/Record\";\nimport * as
|
|
1
|
+
{"version":3,"file":"Spec.js","names":["GroupSpec.withName"],"sources":["../src/Spec.ts"],"sourcesContent":["import * as Predicate from \"effect/Predicate\";\nimport * as Record from \"effect/Record\";\nimport * as GroupSpec from \"./GroupSpec\";\n\nexport const TypeId = \"~@confect/core/Spec\";\nexport type TypeId = typeof TypeId;\n\nexport const isSpec = (u: unknown): u is AnyWithProps =>\n Predicate.hasProperty(u, TypeId);\n\n/**\n * A Confect spec: a flat container of function groups. Groups may be of any\n * runtime—a group built with `GroupSpec.makeNode()` (a Node action group) sits\n * alongside `GroupSpec.make()` groups in the same namespace. The runtime of a\n * group lives on the group itself (`GroupSpec.runtime`) and on each function's\n * `RuntimeAndFunctionType`; the spec does not carry a runtime of its own.\n */\nexport interface Spec<\n Groups_ extends Record.ReadonlyRecord<string, GroupSpec.AnyWithProps> = {},\n> {\n readonly [TypeId]: Readonly<Groups_>;\n}\n\nexport interface Any {\n readonly [TypeId]: unknown;\n}\n\nexport interface AnyWithProps extends Any {\n readonly [TypeId]: Record.ReadonlyRecord<string, GroupSpec.AnyWithProps>;\n}\n\nexport type Groups<Spec_ extends AnyWithProps> =\n Spec_[TypeId][keyof Spec_[TypeId]];\n\n/**\n * The group record stored by a spec, with its precise member types.\n */\nexport const groups = <Spec_ extends AnyWithProps>(\n self: Spec_,\n): Spec_[TypeId] => self[TypeId];\n\nexport const fromGroups = (\n record: Record.ReadonlyRecord<string, GroupSpec.AnyWithProps>,\n): AnyWithProps => ({\n [TypeId]: Record.map(record, (group, name) =>\n GroupSpec.withName(name, group),\n ),\n});\n"],"mappings":";;;;;;;;;;;AAIA,MAAa,SAAS;AAGtB,MAAa,UAAU,MACrB,UAAU,YAAY,GAAG,MAAM;;;;AA6BjC,MAAa,UACX,SACkB,KAAK;AAEzB,MAAa,cACX,YACkB,GACjB,SAAS,OAAO,IAAI,SAAS,OAAO,SACnCA,SAAmB,MAAM,KAAK,CAChC,EACF"}
|
package/dist/SystemFields.js
CHANGED
|
@@ -7,10 +7,10 @@ import * as SchemaAST from "effect/SchemaAST";
|
|
|
7
7
|
import * as Record from "effect/Record";
|
|
8
8
|
import * as Effect from "effect/Effect";
|
|
9
9
|
import { pipe } from "effect/Function";
|
|
10
|
-
import * as Struct from "effect/Struct";
|
|
11
10
|
import * as Array from "effect/Array";
|
|
12
11
|
import * as SchemaGetter from "effect/SchemaGetter";
|
|
13
12
|
import * as SchemaTransformation from "effect/SchemaTransformation";
|
|
13
|
+
import * as Struct from "effect/Struct";
|
|
14
14
|
//#region src/SystemFields.ts
|
|
15
15
|
var SystemFields_exports = /* @__PURE__ */ __exportAll({
|
|
16
16
|
SystemFields: () => SystemFields,
|