@confect/core 10.0.0-next.21 → 10.0.0-next.23
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 +168 -81
- package/dist/FunctionProvenance.d.ts +34 -26
- package/dist/FunctionProvenance.d.ts.map +1 -1
- package/dist/FunctionProvenance.js +14 -13
- package/dist/FunctionProvenance.js.map +1 -1
- package/dist/FunctionSpec.d.ts +15 -9
- package/dist/FunctionSpec.d.ts.map +1 -1
- package/dist/FunctionSpec.js +12 -6
- 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 +10 -3
- package/dist/GroupSpec.d.ts.map +1 -1
- package/dist/GroupSpec.js +33 -19
- package/dist/GroupSpec.js.map +1 -1
- package/dist/Identifier.d.ts +6 -5
- package/dist/Identifier.d.ts.map +1 -1
- package/dist/Identifier.js +6 -5
- package/dist/Identifier.js.map +1 -1
- package/dist/Lazy.d.ts +11 -13
- package/dist/Lazy.d.ts.map +1 -1
- package/dist/Lazy.js +11 -13
- package/dist/Lazy.js.map +1 -1
- package/dist/MiddlewareAttachment.d.ts +171 -0
- package/dist/MiddlewareAttachment.d.ts.map +1 -0
- package/dist/MiddlewareAttachment.js +48 -0
- package/dist/MiddlewareAttachment.js.map +1 -0
- package/dist/MiddlewareSpec.d.ts +59 -45
- package/dist/MiddlewareSpec.d.ts.map +1 -1
- package/dist/MiddlewareSpec.js +9 -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 +3 -3
- package/dist/PaginationOptions.js +3 -3
- package/dist/PaginationOptions.js.map +1 -1
- package/dist/Ref.d.ts +42 -35
- package/dist/Ref.d.ts.map +1 -1
- package/dist/Ref.js +32 -30
- 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 +3 -2
- package/dist/Refs.js.map +1 -1
- package/dist/SchemaToValidator.d.ts.map +1 -1
- package/dist/SchemaToValidator.js +4 -2
- package/dist/SchemaToValidator.js.map +1 -1
- package/dist/Spec.d.ts +15 -12
- 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 +15 -14
- package/dist/SystemFields.d.ts.map +1 -1
- package/dist/SystemFields.js +11 -10
- 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.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/package.json +8 -7
- package/src/FunctionProvenance.ts +35 -27
- package/src/FunctionSpec.ts +33 -15
- package/src/GroupPath.ts +5 -6
- package/src/GroupSpec.ts +83 -31
- package/src/Identifier.ts +6 -5
- package/src/Lazy.ts +11 -13
- package/src/MiddlewareAttachment.ts +106 -0
- package/src/MiddlewareSpec.ts +79 -43
- package/src/PaginationError.ts +9 -3
- package/src/PaginationOptions.ts +3 -3
- package/src/Ref.ts +76 -65
- package/src/Refs.ts +3 -3
- package/src/SchemaToValidator.ts +53 -44
- package/src/Spec.ts +50 -39
- package/src/SystemFields.ts +18 -17
- package/src/Table.ts +3 -2
- package/src/index.ts +1 -0
package/dist/GroupSpec.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as MiddlewareAttachment from "./MiddlewareAttachment";
|
|
2
|
+
import * as Result from "effect/Result";
|
|
1
3
|
import type * as FunctionSpec from "./FunctionSpec";
|
|
2
4
|
import type * as MiddlewareSpec from "./MiddlewareSpec";
|
|
3
5
|
import type * as RuntimeAndFunctionType from "./RuntimeAndFunctionType";
|
|
@@ -15,12 +17,13 @@ export interface GroupSpec<Runtime extends RuntimeAndFunctionType.Runtime, Name_
|
|
|
15
17
|
[GroupName in Name<Groups_>]: WithName<Groups_, GroupName>;
|
|
16
18
|
};
|
|
17
19
|
readonly middlewareSpecs: ReadonlyArray<MiddlewareSpecs_>;
|
|
20
|
+
readonly middlewareAttachments: ReadonlyArray<MiddlewareAttachment.MiddlewareAttachment<MiddlewareSpecs_>>;
|
|
18
21
|
readonly "~Functions": Functions_;
|
|
19
22
|
readonly "~Groups": Groups_;
|
|
20
23
|
addFunction<Function extends FunctionSpec.AnyWithPropsWithRuntime<Runtime>>(function_: Function & MiddlewareSpec.ValidateAddedFunction<Function, MiddlewareSpecs_>): GroupSpec<Runtime, Name_, Functions_ | Function, Groups_, MiddlewareSpecs_>;
|
|
21
24
|
addGroup<Group extends AnyWithProps>(group: Group): GroupSpec<Runtime, Name_, Functions_, Groups_ | Group, MiddlewareSpecs_>;
|
|
22
25
|
addGroupAt<const AtName extends string, Group extends AnyWithProps>(name: AtName, group: Group): GroupSpec<Runtime, Name_, Functions_, Groups_ | NamedAt<Group, AtName>, MiddlewareSpecs_>;
|
|
23
|
-
middleware<MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec>(middlewareSpec: MiddlewareSpec_ & MiddlewareSpec.ValidateAttach<MiddlewareSpec_, Functions_, MiddlewareSpecs_
|
|
26
|
+
middleware<MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec>(middlewareSpec: MiddlewareSpec_ & MiddlewareSpec.ValidateAttach<MiddlewareSpec_, Functions_, MiddlewareSpecs_>, ...options: MiddlewareAttachment.Args<NoInfer<MiddlewareSpec_>>): GroupSpec<Runtime, Name_, Functions_, Groups_, MiddlewareSpecs_ | MiddlewareSpec_>;
|
|
24
27
|
}
|
|
25
28
|
export interface Any {
|
|
26
29
|
readonly [TypeId]: TypeId;
|
|
@@ -39,7 +42,10 @@ export type GroupNames<Group extends AnyWithProps> = [Groups<Group>] extends [
|
|
|
39
42
|
export type WithName<Group extends AnyWithProps, Name_ extends Name<Group>> = Extract<Group, {
|
|
40
43
|
readonly name: Name_;
|
|
41
44
|
}>;
|
|
42
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* Assigns a segment name to a leaf group created with {@link make} for typing
|
|
47
|
+
* and refs.
|
|
48
|
+
*/
|
|
43
49
|
export type NamedAt<Group extends Any, Name_ extends string> = Omit<Group, "name"> & {
|
|
44
50
|
readonly name: Name_;
|
|
45
51
|
};
|
|
@@ -48,5 +54,6 @@ export declare const make: () => GroupSpec<"Convex", "">;
|
|
|
48
54
|
export declare const makeAt: <const Name_ extends string>(name: Name_) => GroupSpec<"Convex", Name_>;
|
|
49
55
|
export declare const makeNode: () => GroupSpec<"Node", "">;
|
|
50
56
|
export declare const makeNodeAt: <const Name_ extends string>(name: Name_) => GroupSpec<"Node", Name_>;
|
|
51
|
-
export declare
|
|
57
|
+
export declare function withName<const Name_ extends string, Group extends Any>(name: Name_, group: Group): NamedAt<Group, Name_>;
|
|
58
|
+
export declare const validateMiddleware: (group: AnyWithProps) => Result.Result<void, MiddlewareAttachment.ValidationError>;
|
|
52
59
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"GroupSpec.d.ts","sourceRoot":"","sources":["../src/GroupSpec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,oBAAoB,MAAM,wBAAwB,CAAC;AAG/D,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,eA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AAO,GAAG,WAAW,EACrB,gBAAgB,CACjB,GACD,KAAK,CAAC;AAoJZ,eAAO,MAAM,IAAI,QAAO,SAAS,CAAC,QAAQ,EAAE,EAAE,CAO1C,CAAC;AAEL,eAAO,MAAM,MAAM,GAAI,KAAK,CAAC,KAAK,SAAS,MAAM,QACzC,KAAK,KACV,SAAS,CAAC,QAAQ,EAAE,KAAK,CAU3B,CAAC;AAEF,eAAO,MAAM,QAAQ,QAAO,SAAS,CAAC,MAAM,EAAE,EAAE,CAO5C,CAAC;AAEL,eAAO,MAAM,UAAU,GAAI,KAAK,CAAC,KAAK,SAAS,MAAM,QAC7C,KAAK,KACV,SAAS,CAAC,MAAM,EAAE,KAAK,CAUzB,CAAC;AAEF,wBAAgB,QAAQ,CAAC,KAAK,CAAC,KAAK,SAAS,MAAM,EAAE,KAAK,SAAS,GAAG,EACpE,IAAI,EAAE,KAAK,EACX,KAAK,EAAE,KAAK,GACX,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAkBzB,eAAO,MAAM,kBAAkB,UACtB,YAAY,KAClB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,oBAAoB,CAAC,eAAe,CAcvD,CAAC"}
|
package/dist/GroupSpec.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { validateConfectFunctionIdentifier } from "./Identifier.js";
|
|
3
|
+
import { validateAll } from "./MiddlewareAttachment.js";
|
|
3
4
|
import * as Predicate from "effect/Predicate";
|
|
5
|
+
import * as Result from "effect/Result";
|
|
4
6
|
import * as Record from "effect/Record";
|
|
5
7
|
//#region src/GroupSpec.ts
|
|
6
8
|
var GroupSpec_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -10,22 +12,26 @@ var GroupSpec_exports = /* @__PURE__ */ __exportAll({
|
|
|
10
12
|
makeAt: () => makeAt,
|
|
11
13
|
makeNode: () => makeNode,
|
|
12
14
|
makeNodeAt: () => makeNodeAt,
|
|
15
|
+
validateMiddleware: () => validateMiddleware,
|
|
13
16
|
withName: () => withName
|
|
14
17
|
});
|
|
15
18
|
const TypeId = "~@confect/core/GroupSpec";
|
|
16
19
|
const isGroupSpec = (u) => Predicate.hasProperty(u, TypeId);
|
|
17
20
|
const Proto = {
|
|
18
21
|
[TypeId]: TypeId,
|
|
22
|
+
get middlewareSpecs() {
|
|
23
|
+
return this.middlewareAttachments.map(({ spec }) => spec);
|
|
24
|
+
},
|
|
19
25
|
addFunction(function_) {
|
|
20
26
|
const this_ = this;
|
|
21
|
-
const overlapping = function_.
|
|
22
|
-
if (overlapping !== void 0) throw new Error(`Middleware "${overlapping.key}" is attached to both function "${function_.name}" and its group`);
|
|
27
|
+
const overlapping = function_.middlewareAttachments.find(({ spec: functionMiddlewareSpec }) => !("options" in functionMiddlewareSpec) && this_.middlewareAttachments.some(({ spec: groupMiddlewareSpec }) => groupMiddlewareSpec.key === functionMiddlewareSpec.key));
|
|
28
|
+
if (overlapping !== void 0) throw new Error(`Middleware "${overlapping.spec.key}" is attached to both function "${function_.name}" and its group`);
|
|
23
29
|
return makeProto({
|
|
24
30
|
runtime: this_.runtime,
|
|
25
31
|
name: this_.name,
|
|
26
32
|
functions: Record.set(this_.functions, function_.name, function_),
|
|
27
33
|
groups: this_.groups,
|
|
28
|
-
|
|
34
|
+
middlewareAttachments: this_.middlewareAttachments
|
|
29
35
|
});
|
|
30
36
|
},
|
|
31
37
|
addGroup(group) {
|
|
@@ -36,7 +42,7 @@ const Proto = {
|
|
|
36
42
|
name: this_.name,
|
|
37
43
|
functions: this_.functions,
|
|
38
44
|
groups: Record.set(this_.groups, group_.name, group_),
|
|
39
|
-
|
|
45
|
+
middlewareAttachments: this_.middlewareAttachments
|
|
40
46
|
});
|
|
41
47
|
},
|
|
42
48
|
addGroupAt(name, group) {
|
|
@@ -47,35 +53,38 @@ const Proto = {
|
|
|
47
53
|
name: this_.name,
|
|
48
54
|
functions: this_.functions,
|
|
49
55
|
groups: Record.set(this_.groups, name, withName(name, group_)),
|
|
50
|
-
|
|
56
|
+
middlewareAttachments: this_.middlewareAttachments
|
|
51
57
|
});
|
|
52
58
|
},
|
|
53
|
-
middleware(middlewareSpec) {
|
|
59
|
+
middleware(middlewareSpec, ...options) {
|
|
54
60
|
const this_ = this;
|
|
55
|
-
if (this_.
|
|
56
|
-
for (const function_ of Object.values(this_.functions)) if (function_.
|
|
61
|
+
if (!("options" in middlewareSpec) && this_.middlewareAttachments.some(({ spec }) => spec.key === middlewareSpec.key)) throw new Error(`Middleware "${middlewareSpec.key}" is already attached to this group`);
|
|
62
|
+
for (const function_ of Object.values(this_.functions)) if (!("options" in middlewareSpec) && function_.middlewareAttachments.some(({ spec }) => spec.key === middlewareSpec.key)) throw new Error(`Middleware "${middlewareSpec.key}" is attached to both function "${function_.name}" and its group`);
|
|
57
63
|
return makeProto({
|
|
58
64
|
runtime: this_.runtime,
|
|
59
65
|
name: this_.name,
|
|
60
66
|
functions: this_.functions,
|
|
61
67
|
groups: this_.groups,
|
|
62
|
-
|
|
68
|
+
middlewareAttachments: [...this_.middlewareAttachments, {
|
|
69
|
+
spec: middlewareSpec,
|
|
70
|
+
options: options[0]
|
|
71
|
+
}]
|
|
63
72
|
});
|
|
64
73
|
}
|
|
65
74
|
};
|
|
66
|
-
const makeProto = ({ runtime, name, functions, groups,
|
|
75
|
+
const makeProto = ({ runtime, name, functions, groups, middlewareAttachments }) => Object.assign(Object.create(Proto), {
|
|
67
76
|
runtime,
|
|
68
77
|
name,
|
|
69
78
|
functions,
|
|
70
79
|
groups,
|
|
71
|
-
|
|
80
|
+
middlewareAttachments
|
|
72
81
|
});
|
|
73
82
|
const make = () => makeProto({
|
|
74
83
|
runtime: "Convex",
|
|
75
84
|
name: "",
|
|
76
85
|
functions: Record.empty(),
|
|
77
86
|
groups: Record.empty(),
|
|
78
|
-
|
|
87
|
+
middlewareAttachments: []
|
|
79
88
|
});
|
|
80
89
|
const makeAt = (name) => {
|
|
81
90
|
validateConfectFunctionIdentifier(name);
|
|
@@ -84,7 +93,7 @@ const makeAt = (name) => {
|
|
|
84
93
|
name,
|
|
85
94
|
functions: Record.empty(),
|
|
86
95
|
groups: Record.empty(),
|
|
87
|
-
|
|
96
|
+
middlewareAttachments: []
|
|
88
97
|
});
|
|
89
98
|
};
|
|
90
99
|
const makeNode = () => makeProto({
|
|
@@ -92,7 +101,7 @@ const makeNode = () => makeProto({
|
|
|
92
101
|
name: "",
|
|
93
102
|
functions: Record.empty(),
|
|
94
103
|
groups: Record.empty(),
|
|
95
|
-
|
|
104
|
+
middlewareAttachments: []
|
|
96
105
|
});
|
|
97
106
|
const makeNodeAt = (name) => {
|
|
98
107
|
validateConfectFunctionIdentifier(name);
|
|
@@ -101,10 +110,10 @@ const makeNodeAt = (name) => {
|
|
|
101
110
|
name,
|
|
102
111
|
functions: Record.empty(),
|
|
103
112
|
groups: Record.empty(),
|
|
104
|
-
|
|
113
|
+
middlewareAttachments: []
|
|
105
114
|
});
|
|
106
115
|
};
|
|
107
|
-
|
|
116
|
+
function withName(name, group) {
|
|
108
117
|
validateConfectFunctionIdentifier(name);
|
|
109
118
|
const group_ = group;
|
|
110
119
|
if (group_.name === name) return group_;
|
|
@@ -113,10 +122,15 @@ const withName = (name, group) => {
|
|
|
113
122
|
name,
|
|
114
123
|
functions: group_.functions,
|
|
115
124
|
groups: group_.groups,
|
|
116
|
-
|
|
125
|
+
middlewareAttachments: group_.middlewareAttachments
|
|
117
126
|
});
|
|
118
|
-
}
|
|
127
|
+
}
|
|
128
|
+
const validateMiddleware = (group) => Result.gen(function* () {
|
|
129
|
+
yield* validateAll(group.middlewareAttachments, `group "${group.name}"`);
|
|
130
|
+
for (const function_ of Object.values(group.functions)) yield* validateAll([...group.middlewareAttachments, ...function_.middlewareAttachments], `function "${function_.name}"`);
|
|
131
|
+
for (const child of Object.values(group.groups)) yield* validateMiddleware(child);
|
|
132
|
+
});
|
|
119
133
|
//#endregion
|
|
120
|
-
export { GroupSpec_exports, TypeId, isGroupSpec, make, makeAt, makeNode, makeNodeAt, withName };
|
|
134
|
+
export { GroupSpec_exports, TypeId, isGroupSpec, make, makeAt, makeNode, makeNodeAt, validateMiddleware, withName };
|
|
121
135
|
|
|
122
136
|
//# sourceMappingURL=GroupSpec.js.map
|
package/dist/GroupSpec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GroupSpec.js","names":[],"sources":["../src/GroupSpec.ts"],"sourcesContent":["import * as Predicate from \"effect/Predicate\";\nimport * as Record from \"effect/Record\";\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 \"~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 ): 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 addFunction<Function extends FunctionSpec.AnyWithProps>(\n this: Any,\n function_: Function,\n ) {\n const this_ = this as AnyWithProps;\n\n const overlapping = function_.middlewareSpecs.find(\n (functionMiddlewareSpec) =>\n this_.middlewareSpecs.some(\n (groupMiddlewareSpec) =>\n groupMiddlewareSpec.key === functionMiddlewareSpec.key,\n ),\n );\n if (overlapping !== undefined) {\n throw new Error(\n `Middleware \"${overlapping.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 middlewareSpecs: this_.middlewareSpecs,\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 middlewareSpecs: this_.middlewareSpecs,\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 middlewareSpecs: this_.middlewareSpecs,\n });\n },\n\n middleware<MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec>(\n this: Any,\n middlewareSpec: MiddlewareSpec_,\n ) {\n const this_ = this as AnyWithProps;\n\n if (\n this_.middlewareSpecs.some(\n (existing) => existing.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 function_.middlewareSpecs.some(\n (existing) => existing.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 middlewareSpecs: [...this_.middlewareSpecs, middlewareSpec],\n });\n },\n};\n\nconst makeProto = <\n Runtime extends RuntimeAndFunctionType.Runtime,\n Name_ extends string,\n Functions_ extends FunctionSpec.AnyWithPropsWithRuntime<Runtime>,\n Groups_ extends AnyWithPropsWithRuntime<Runtime>,\n MiddlewareSpecs_ extends MiddlewareSpec.AnyMiddlewareSpec,\n>({\n runtime,\n name,\n functions,\n groups,\n middlewareSpecs,\n}: {\n runtime: Runtime;\n name: Name_;\n functions: Record.ReadonlyRecord<string, Functions_>;\n groups: Record.ReadonlyRecord<string, Groups_>;\n middlewareSpecs: ReadonlyArray<MiddlewareSpecs_>;\n}): GroupSpec<Runtime, Name_, Functions_, Groups_, MiddlewareSpecs_> =>\n Object.assign(Object.create(Proto), {\n runtime,\n name,\n functions,\n groups,\n middlewareSpecs,\n }) as GroupSpec<Runtime, Name_, Functions_, Groups_, MiddlewareSpecs_>;\n\nexport const make = (): GroupSpec<\"Convex\", \"\"> =>\n makeProto({\n runtime: \"Convex\",\n name: \"\",\n functions: Record.empty(),\n groups: Record.empty(),\n middlewareSpecs: [],\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 middlewareSpecs: [],\n });\n};\n\nexport const makeNode = (): GroupSpec<\"Node\", \"\"> =>\n makeProto({\n runtime: \"Node\",\n name: \"\",\n functions: Record.empty(),\n groups: Record.empty(),\n middlewareSpecs: [],\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 middlewareSpecs: [],\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 middlewareSpecs: group_.middlewareSpecs,\n });\n};\n"],"mappings":";;;;;;;;;;;;;;AAOA,MAAa,SAAS;AAGtB,MAAa,eAAe,MAC1B,UAAU,YAAY,GAAG,MAAM;AA8IjC,MAAM,QAAQ;EACX,SAAS;CAEV,YAEE,WACA;EACA,MAAM,QAAQ;EAEd,MAAM,cAAc,UAAU,gBAAgB,MAC3C,2BACC,MAAM,gBAAgB,MACnB,wBACC,oBAAoB,QAAQ,uBAAuB,GACvD,CACJ;EACA,IAAI,gBAAgB,KAAA,GAClB,MAAM,IAAI,MACR,eAAe,YAAY,IAAI,kCAAkC,UAAU,KAAK,gBAClF;EAGF,OAAO,UAAU;GACf,SAAS,MAAM;GACf,MAAM,MAAM;GACZ,WAAW,OAAO,IAAI,MAAM,WAAW,UAAU,MAAM,SAAS;GAChE,QAAQ,MAAM;GACd,iBAAiB,MAAM;EACzB,CAAC;CACH;CAEA,SAAuC,OAAc;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AU;EACf,SAAS;EACT;EACA,WAAW,OAAO,MAAM;EACxB,QAAQ,OAAO,MAAM;EACrB,iBAAiB,CAAC;CACpB,CAAC;AACH;AAEA,MAAa,iBACX,UAAU;CACR,SAAS;CACT,MAAM;CACN,WAAW,OAAO,MAAM;CACxB,QAAQ,OAAO,MAAM;CACrB,iBAAiB,CAAC;AACpB,CAAC;AAEH,MAAa,cACX,SAC6B;CAC7B,kCAAkC,IAAI;CAEtC,OAAO,UAAU;EACf,SAAS;EACT;EACA,WAAW,OAAO,MAAM;EACxB,QAAQ,OAAO,MAAM;EACrB,iBAAiB,CAAC;CACpB,CAAC;AACH;AAEA,MAAa,YACX,MACA,UACiB;CACjB,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,iBAAiB,OAAO;CAC1B,CAAC;AACH"}
|
|
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,IA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ateConfectFunctionIdentifier: (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,21 +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`
|
|
18
|
-
* `Doc`), so there is no chance of the two drifting apart.
|
|
15
|
+
* `@confect/core`'s lazy `FunctionSpec` schemas and lazy `Table`
|
|
16
|
+
* `Fields`/`Doc`), so there is no chance of the two drifting apart.
|
|
19
17
|
*/
|
|
20
18
|
export declare const defineProperty: <T extends object, K extends PropertyKey>(target: T, key: K, compute: () => unknown) => void;
|
|
21
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,22 +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`
|
|
21
|
-
* `Doc`), so there is no chance of the two drifting apart.
|
|
18
|
+
* `@confect/core`'s lazy `FunctionSpec` schemas and lazy `Table`
|
|
19
|
+
* `Fields`/`Doc`), so there is no chance of the two drifting apart.
|
|
22
20
|
*/
|
|
23
21
|
const defineProperty = (target, key, compute) => {
|
|
24
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"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import * as Data from "effect/Data";
|
|
2
|
+
import * as Result from "effect/Result";
|
|
3
|
+
import type * as MiddlewareSpec from "./MiddlewareSpec";
|
|
4
|
+
export type MiddlewareAttachment<MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec = MiddlewareSpec.AnyMiddlewareSpec> = MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec ? {
|
|
5
|
+
readonly spec: MiddlewareSpec_;
|
|
6
|
+
readonly options: [MiddlewareSpec_["~Options"]] extends [never] ? undefined : MiddlewareSpec.Options<MiddlewareSpec_>;
|
|
7
|
+
} : never;
|
|
8
|
+
export type Args<MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec> = [
|
|
9
|
+
MiddlewareSpec_["~Options"]
|
|
10
|
+
] extends [never] ? [] : [options: MiddlewareSpec.Options<MiddlewareSpec_>];
|
|
11
|
+
export type ValidationError = Data.TaggedEnum<{
|
|
12
|
+
InvalidOptions: {
|
|
13
|
+
readonly middlewareKey: string;
|
|
14
|
+
readonly location: string;
|
|
15
|
+
readonly attachmentIndex: number;
|
|
16
|
+
};
|
|
17
|
+
ConflictingSpecs: {
|
|
18
|
+
readonly middlewareKey: string;
|
|
19
|
+
readonly location: string;
|
|
20
|
+
readonly attachmentIndex: number;
|
|
21
|
+
readonly previousIndex: number;
|
|
22
|
+
};
|
|
23
|
+
EquivalentOptions: {
|
|
24
|
+
readonly middlewareKey: string;
|
|
25
|
+
readonly location: string;
|
|
26
|
+
readonly attachmentIndex: number;
|
|
27
|
+
readonly previousIndex: number;
|
|
28
|
+
};
|
|
29
|
+
}>;
|
|
30
|
+
export declare const ValidationError: {
|
|
31
|
+
readonly $is: <Tag extends "ConflictingSpecs" | "EquivalentOptions" | "InvalidOptions">(tag: Tag) => (u: unknown) => u is Extract<{
|
|
32
|
+
readonly _tag: "ConflictingSpecs";
|
|
33
|
+
readonly middlewareKey: string;
|
|
34
|
+
readonly location: string;
|
|
35
|
+
readonly attachmentIndex: number;
|
|
36
|
+
readonly previousIndex: number;
|
|
37
|
+
}, {
|
|
38
|
+
readonly _tag: Tag;
|
|
39
|
+
}> | Extract<{
|
|
40
|
+
readonly _tag: "EquivalentOptions";
|
|
41
|
+
readonly middlewareKey: string;
|
|
42
|
+
readonly location: string;
|
|
43
|
+
readonly attachmentIndex: number;
|
|
44
|
+
readonly previousIndex: number;
|
|
45
|
+
}, {
|
|
46
|
+
readonly _tag: Tag;
|
|
47
|
+
}> | Extract<{
|
|
48
|
+
readonly _tag: "InvalidOptions";
|
|
49
|
+
readonly middlewareKey: string;
|
|
50
|
+
readonly location: string;
|
|
51
|
+
readonly attachmentIndex: number;
|
|
52
|
+
}, {
|
|
53
|
+
readonly _tag: Tag;
|
|
54
|
+
}>;
|
|
55
|
+
readonly $match: {
|
|
56
|
+
<Cases extends { readonly [Tag in "ConflictingSpecs" | "EquivalentOptions" | "InvalidOptions"]: (args: Extract<{
|
|
57
|
+
readonly _tag: "ConflictingSpecs";
|
|
58
|
+
readonly middlewareKey: string;
|
|
59
|
+
readonly location: string;
|
|
60
|
+
readonly attachmentIndex: number;
|
|
61
|
+
readonly previousIndex: number;
|
|
62
|
+
} | {
|
|
63
|
+
readonly _tag: "EquivalentOptions";
|
|
64
|
+
readonly middlewareKey: string;
|
|
65
|
+
readonly location: string;
|
|
66
|
+
readonly attachmentIndex: number;
|
|
67
|
+
readonly previousIndex: number;
|
|
68
|
+
} | {
|
|
69
|
+
readonly _tag: "InvalidOptions";
|
|
70
|
+
readonly middlewareKey: string;
|
|
71
|
+
readonly location: string;
|
|
72
|
+
readonly attachmentIndex: number;
|
|
73
|
+
}, {
|
|
74
|
+
readonly _tag: Tag;
|
|
75
|
+
}>) => any; }>(cases: Cases): (value: {
|
|
76
|
+
readonly _tag: "ConflictingSpecs";
|
|
77
|
+
readonly middlewareKey: string;
|
|
78
|
+
readonly location: string;
|
|
79
|
+
readonly attachmentIndex: number;
|
|
80
|
+
readonly previousIndex: number;
|
|
81
|
+
} | {
|
|
82
|
+
readonly _tag: "EquivalentOptions";
|
|
83
|
+
readonly middlewareKey: string;
|
|
84
|
+
readonly location: string;
|
|
85
|
+
readonly attachmentIndex: number;
|
|
86
|
+
readonly previousIndex: number;
|
|
87
|
+
} | {
|
|
88
|
+
readonly _tag: "InvalidOptions";
|
|
89
|
+
readonly middlewareKey: string;
|
|
90
|
+
readonly location: string;
|
|
91
|
+
readonly attachmentIndex: number;
|
|
92
|
+
}) => import("effect/Unify").Unify<ReturnType<Cases["ConflictingSpecs" | "EquivalentOptions" | "InvalidOptions"]>>;
|
|
93
|
+
<Cases extends { readonly [Tag in "ConflictingSpecs" | "EquivalentOptions" | "InvalidOptions"]: (args: Extract<{
|
|
94
|
+
readonly _tag: "ConflictingSpecs";
|
|
95
|
+
readonly middlewareKey: string;
|
|
96
|
+
readonly location: string;
|
|
97
|
+
readonly attachmentIndex: number;
|
|
98
|
+
readonly previousIndex: number;
|
|
99
|
+
} | {
|
|
100
|
+
readonly _tag: "EquivalentOptions";
|
|
101
|
+
readonly middlewareKey: string;
|
|
102
|
+
readonly location: string;
|
|
103
|
+
readonly attachmentIndex: number;
|
|
104
|
+
readonly previousIndex: number;
|
|
105
|
+
} | {
|
|
106
|
+
readonly _tag: "InvalidOptions";
|
|
107
|
+
readonly middlewareKey: string;
|
|
108
|
+
readonly location: string;
|
|
109
|
+
readonly attachmentIndex: number;
|
|
110
|
+
}, {
|
|
111
|
+
readonly _tag: Tag;
|
|
112
|
+
}>) => any; }>(value: {
|
|
113
|
+
readonly _tag: "ConflictingSpecs";
|
|
114
|
+
readonly middlewareKey: string;
|
|
115
|
+
readonly location: string;
|
|
116
|
+
readonly attachmentIndex: number;
|
|
117
|
+
readonly previousIndex: number;
|
|
118
|
+
} | {
|
|
119
|
+
readonly _tag: "EquivalentOptions";
|
|
120
|
+
readonly middlewareKey: string;
|
|
121
|
+
readonly location: string;
|
|
122
|
+
readonly attachmentIndex: number;
|
|
123
|
+
readonly previousIndex: number;
|
|
124
|
+
} | {
|
|
125
|
+
readonly _tag: "InvalidOptions";
|
|
126
|
+
readonly middlewareKey: string;
|
|
127
|
+
readonly location: string;
|
|
128
|
+
readonly attachmentIndex: number;
|
|
129
|
+
}, cases: Cases): import("effect/Unify").Unify<ReturnType<Cases["ConflictingSpecs" | "EquivalentOptions" | "InvalidOptions"]>>;
|
|
130
|
+
};
|
|
131
|
+
readonly ConflictingSpecs: Data.TaggedEnum.ConstructorFrom<{
|
|
132
|
+
readonly _tag: "ConflictingSpecs";
|
|
133
|
+
readonly middlewareKey: string;
|
|
134
|
+
readonly location: string;
|
|
135
|
+
readonly attachmentIndex: number;
|
|
136
|
+
readonly previousIndex: number;
|
|
137
|
+
}, "_tag">;
|
|
138
|
+
readonly EquivalentOptions: Data.TaggedEnum.ConstructorFrom<{
|
|
139
|
+
readonly _tag: "EquivalentOptions";
|
|
140
|
+
readonly middlewareKey: string;
|
|
141
|
+
readonly location: string;
|
|
142
|
+
readonly attachmentIndex: number;
|
|
143
|
+
readonly previousIndex: number;
|
|
144
|
+
}, "_tag">;
|
|
145
|
+
readonly InvalidOptions: Data.TaggedEnum.ConstructorFrom<{
|
|
146
|
+
readonly _tag: "InvalidOptions";
|
|
147
|
+
readonly middlewareKey: string;
|
|
148
|
+
readonly location: string;
|
|
149
|
+
readonly attachmentIndex: number;
|
|
150
|
+
}, "_tag">;
|
|
151
|
+
};
|
|
152
|
+
export declare const formatValidationError: (value: {
|
|
153
|
+
readonly _tag: "ConflictingSpecs";
|
|
154
|
+
readonly middlewareKey: string;
|
|
155
|
+
readonly location: string;
|
|
156
|
+
readonly attachmentIndex: number;
|
|
157
|
+
readonly previousIndex: number;
|
|
158
|
+
} | {
|
|
159
|
+
readonly _tag: "EquivalentOptions";
|
|
160
|
+
readonly middlewareKey: string;
|
|
161
|
+
readonly location: string;
|
|
162
|
+
readonly attachmentIndex: number;
|
|
163
|
+
readonly previousIndex: number;
|
|
164
|
+
} | {
|
|
165
|
+
readonly _tag: "InvalidOptions";
|
|
166
|
+
readonly middlewareKey: string;
|
|
167
|
+
readonly location: string;
|
|
168
|
+
readonly attachmentIndex: number;
|
|
169
|
+
}) => string;
|
|
170
|
+
export declare const validateAll: (attachments: ReadonlyArray<MiddlewareAttachment>, location: string) => Result.Result<void, ValidationError>;
|
|
171
|
+
//# sourceMappingURL=MiddlewareAttachment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MiddlewareAttachment.d.ts","sourceRoot":"","sources":["../src/MiddlewareAttachment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,KAAK,cAAc,MAAM,kBAAkB,CAAC;AAExD,MAAM,MAAM,oBAAoB,CAC9B,eAAe,SAAS,cAAc,CAAC,iBAAiB,GACtD,cAAc,CAAC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