@confect/core 1.0.0-next.3 → 1.0.0
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 +12 -0
- package/dist/FunctionSpec.d.ts +69 -20
- package/dist/FunctionSpec.d.ts.map +1 -1
- package/dist/FunctionSpec.js +15 -10
- package/dist/FunctionSpec.js.map +1 -1
- package/dist/GroupSpec.d.ts +14 -10
- package/dist/GroupSpec.d.ts.map +1 -1
- package/dist/GroupSpec.js +18 -4
- package/dist/GroupSpec.js.map +1 -1
- package/dist/Ref.d.ts +25 -22
- package/dist/Ref.d.ts.map +1 -1
- package/dist/Ref.js.map +1 -1
- package/dist/Refs.d.ts +6 -6
- package/dist/Refs.d.ts.map +1 -1
- package/dist/Refs.js +8 -3
- package/dist/Refs.js.map +1 -1
- package/dist/RuntimeAndFunctionType.d.ts +54 -0
- package/dist/RuntimeAndFunctionType.d.ts.map +1 -0
- package/dist/RuntimeAndFunctionType.js +21 -0
- package/dist/RuntimeAndFunctionType.js.map +1 -0
- package/dist/Spec.d.ts +20 -8
- package/dist/Spec.d.ts.map +1 -1
- package/dist/Spec.js +43 -7
- package/dist/Spec.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/package.json +1 -1
- package/src/FunctionSpec.ts +73 -25
- package/src/GroupSpec.ts +47 -15
- package/src/Ref.ts +50 -24
- package/src/Refs.ts +42 -11
- package/src/RuntimeAndFunctionType.ts +57 -0
- package/src/Spec.ts +75 -10
- package/src/index.ts +1 -0
package/dist/Refs.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { makeNode } from "./GroupSpec.js";
|
|
2
3
|
import { getConvexFunctionName, make as make$1 } from "./Ref.js";
|
|
3
|
-
import { Record, pipe } from "effect";
|
|
4
|
+
import { Array, Record, pipe } from "effect";
|
|
4
5
|
|
|
5
6
|
//#region src/Refs.ts
|
|
6
7
|
var Refs_exports = /* @__PURE__ */ __exportAll({ make: () => make });
|
|
7
|
-
const make = (
|
|
8
|
-
const
|
|
8
|
+
const make = (convexSpec, nodeSpec) => {
|
|
9
|
+
const nodeGroup = nodeSpec ? Array.reduce(Record.values(nodeSpec.groups), makeNode("node"), (nodeGroupSpec, group) => nodeGroupSpec.addGroup(group)) : null;
|
|
10
|
+
const refs = makeHelper(nodeGroup ? {
|
|
11
|
+
...convexSpec.groups,
|
|
12
|
+
node: nodeGroup
|
|
13
|
+
} : convexSpec.groups);
|
|
9
14
|
return {
|
|
10
15
|
public: refs,
|
|
11
16
|
internal: refs
|
package/dist/Refs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Refs.js","names":["Ref.make","Ref.getConvexFunctionName"],"sources":["../src/Refs.ts"],"sourcesContent":["import type { Types } from \"effect\";\nimport { pipe, Record } from \"effect\";\nimport type * as FunctionSpec from \"./FunctionSpec\";\nimport
|
|
1
|
+
{"version":3,"file":"Refs.js","names":["GroupSpec.makeNode","Ref.make","Ref.getConvexFunctionName"],"sources":["../src/Refs.ts"],"sourcesContent":["import type { Types } from \"effect\";\nimport { Array, pipe, Record } from \"effect\";\nimport type * as FunctionSpec from \"./FunctionSpec\";\nimport * as GroupSpec from \"./GroupSpec\";\nimport * as Ref from \"./Ref\";\nimport type * as Spec from \"./Spec\";\n\nexport type Refs<\n ConvexSpec extends Spec.AnyWithPropsWithRuntime<\"Convex\">,\n NodeSpec extends Spec.AnyWithPropsWithRuntime<\"Node\"> = never,\n Predicate extends Ref.Any = Ref.Any,\n> = Types.Simplify<\n OmitEmpty<\n Helper<\n | Spec.Groups<ConvexSpec>\n | (NodeSpec extends never\n ? never\n : GroupSpec.GroupSpec<\n \"Node\",\n \"node\",\n never,\n NodeSpec[\"groups\"][keyof NodeSpec[\"groups\"]]\n >),\n Predicate\n >\n >\n>;\n\ntype GroupRefs<\n Group extends GroupSpec.AnyWithProps,\n Predicate extends Ref.Any,\n> = Types.Simplify<\n OmitEmpty<Helper<GroupSpec.Groups<Group>, Predicate>> &\n FilteredFunctions<GroupSpec.Functions<Group>, Predicate>\n>;\n\ntype OmitEmpty<T> = {\n [K in keyof T as keyof T[K] extends never ? never : K]: T[K];\n};\n\ntype FilteredFunctions<\n Functions extends FunctionSpec.AnyWithProps,\n Predicate extends Ref.Any,\n> = {\n [Name in FunctionSpec.Name<Functions> as FunctionSpec.WithName<\n Functions,\n Name\n > extends infer F extends FunctionSpec.AnyWithProps\n ? Ref.FromFunctionSpec<F> extends Predicate\n ? Name\n : never\n : never]: FunctionSpec.WithName<Functions, Name> extends infer F extends\n FunctionSpec.AnyWithProps\n ? Ref.FromFunctionSpec<F>\n : never;\n};\n\ntype Helper<\n Groups extends GroupSpec.AnyWithProps,\n Predicate extends Ref.Any,\n> = {\n [GroupName in GroupSpec.Name<Groups>]: GroupSpec.WithName<\n Groups,\n GroupName\n > extends infer Group extends GroupSpec.AnyWithProps\n ? GroupRefs<Group, Predicate>\n : never;\n};\n\ntype Any =\n | {\n readonly [key: string]: Any;\n }\n | Ref.Any;\n\nexport const make = <\n ConvexSpec extends Spec.AnyWithPropsWithRuntime<\"Convex\">,\n NodeSpec extends Spec.AnyWithPropsWithRuntime<\"Node\"> = never,\n>(\n convexSpec: ConvexSpec,\n nodeSpec?: NodeSpec,\n): {\n public: Refs<ConvexSpec, NodeSpec, Ref.AnyPublic>;\n internal: Refs<ConvexSpec, NodeSpec, Ref.AnyInternal>;\n} => {\n const nodeGroup = nodeSpec\n ? Array.reduce(\n Record.values(nodeSpec.groups),\n GroupSpec.makeNode(\"node\"),\n (nodeGroupSpec, group) => nodeGroupSpec.addGroup(group),\n )\n : null;\n\n const groups = nodeGroup\n ? { ...convexSpec.groups, node: nodeGroup }\n : convexSpec.groups;\n const refs = makeHelper(groups);\n return {\n public: refs as Refs<ConvexSpec, NodeSpec, Ref.AnyPublic>,\n internal: refs as Refs<ConvexSpec, NodeSpec, Ref.AnyInternal>,\n };\n};\n\nconst makeHelper = (\n groups: Record.ReadonlyRecord<string, GroupSpec.Any>,\n groupPath: string | null = null,\n): Any =>\n pipe(\n groups as Record.ReadonlyRecord<string, GroupSpec.AnyWithProps>,\n Record.map((group) => {\n const currentGroupPath = groupPath\n ? `${groupPath}/${group.name}`\n : group.name;\n\n return Record.union(\n makeHelper(group.groups, currentGroupPath),\n Record.map(group.functions, (function_) =>\n Ref.make(`${currentGroupPath}:${function_.name}`, function_),\n ),\n (_subGroup, _function) => {\n throw new Error(\n `Group and function at same level have same name ('${Ref.getConvexFunctionName(_function)}')`,\n );\n },\n );\n }),\n );\n"],"mappings":";;;;;;;AA2EA,MAAa,QAIX,YACA,aAIG;CACH,MAAM,YAAY,WACd,MAAM,OACJ,OAAO,OAAO,SAAS,OAAO,EAC9BA,SAAmB,OAAO,GACzB,eAAe,UAAU,cAAc,SAAS,MAAM,CACxD,GACD;CAKJ,MAAM,OAAO,WAHE,YACX;EAAE,GAAG,WAAW;EAAQ,MAAM;EAAW,GACzC,WAAW,OACgB;AAC/B,QAAO;EACL,QAAQ;EACR,UAAU;EACX;;AAGH,MAAM,cACJ,QACA,YAA2B,SAE3B,KACE,QACA,OAAO,KAAK,UAAU;CACpB,MAAM,mBAAmB,YACrB,GAAG,UAAU,GAAG,MAAM,SACtB,MAAM;AAEV,QAAO,OAAO,MACZ,WAAW,MAAM,QAAQ,iBAAiB,EAC1C,OAAO,IAAI,MAAM,YAAY,cAC3BC,OAAS,GAAG,iBAAiB,GAAG,UAAU,QAAQ,UAAU,CAC7D,GACA,WAAW,cAAc;AACxB,QAAM,IAAI,MACR,qDAAqDC,sBAA0B,UAAU,CAAC,IAC3F;GAEJ;EACD,CACH"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
declare namespace RuntimeAndFunctionType_d_exports {
|
|
2
|
+
export { AnyAction, AnyMutation, AnyQuery, ConvexAction, ConvexMutation, ConvexQuery, GetFunctionType, GetRuntime, NodeAction, Runtime, RuntimeAndFunctionType, WithRuntime };
|
|
3
|
+
}
|
|
4
|
+
type RuntimeAndFunctionType = {
|
|
5
|
+
readonly runtime: "Convex";
|
|
6
|
+
readonly functionType: "query";
|
|
7
|
+
} | {
|
|
8
|
+
readonly runtime: "Convex";
|
|
9
|
+
readonly functionType: "mutation";
|
|
10
|
+
} | {
|
|
11
|
+
readonly runtime: "Convex";
|
|
12
|
+
readonly functionType: "action";
|
|
13
|
+
} | {
|
|
14
|
+
readonly runtime: "Node";
|
|
15
|
+
readonly functionType: "action";
|
|
16
|
+
};
|
|
17
|
+
type Runtime = RuntimeAndFunctionType["runtime"];
|
|
18
|
+
type AnyQuery = Extract<RuntimeAndFunctionType, {
|
|
19
|
+
readonly functionType: "query";
|
|
20
|
+
}>;
|
|
21
|
+
type AnyMutation = Extract<RuntimeAndFunctionType, {
|
|
22
|
+
readonly functionType: "mutation";
|
|
23
|
+
}>;
|
|
24
|
+
type AnyAction = Extract<RuntimeAndFunctionType, {
|
|
25
|
+
readonly functionType: "action";
|
|
26
|
+
}>;
|
|
27
|
+
type WithRuntime<Runtime_ extends Runtime> = Extract<RuntimeAndFunctionType, {
|
|
28
|
+
readonly runtime: Runtime_;
|
|
29
|
+
}>;
|
|
30
|
+
type GetRuntime<RuntimeAndFunctionType_ extends RuntimeAndFunctionType> = RuntimeAndFunctionType_["runtime"];
|
|
31
|
+
type GetFunctionType<RuntimeAndFunctionType_ extends RuntimeAndFunctionType> = RuntimeAndFunctionType_["functionType"];
|
|
32
|
+
declare const ConvexQuery: {
|
|
33
|
+
readonly runtime: "Convex";
|
|
34
|
+
readonly functionType: "query";
|
|
35
|
+
};
|
|
36
|
+
type ConvexQuery = typeof ConvexQuery;
|
|
37
|
+
declare const ConvexMutation: {
|
|
38
|
+
readonly runtime: "Convex";
|
|
39
|
+
readonly functionType: "mutation";
|
|
40
|
+
};
|
|
41
|
+
type ConvexMutation = typeof ConvexMutation;
|
|
42
|
+
declare const ConvexAction: {
|
|
43
|
+
readonly runtime: "Convex";
|
|
44
|
+
readonly functionType: "action";
|
|
45
|
+
};
|
|
46
|
+
type ConvexAction = typeof ConvexAction;
|
|
47
|
+
declare const NodeAction: {
|
|
48
|
+
readonly runtime: "Node";
|
|
49
|
+
readonly functionType: "action";
|
|
50
|
+
};
|
|
51
|
+
type NodeAction = typeof NodeAction;
|
|
52
|
+
//#endregion
|
|
53
|
+
export { AnyAction, AnyMutation, AnyQuery, ConvexAction, ConvexMutation, ConvexQuery, GetFunctionType, GetRuntime, NodeAction, Runtime, RuntimeAndFunctionType, RuntimeAndFunctionType_d_exports, WithRuntime };
|
|
54
|
+
//# sourceMappingURL=RuntimeAndFunctionType.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RuntimeAndFunctionType.d.ts","names":[],"sources":["../src/RuntimeAndFunctionType.ts"],"mappings":";;;KAAY,sBAAA;EAAA,SACG,OAAA;EAAA,SAA4B,YAAA;AAAA;EAAA,SAC5B,OAAA;EAAA,SAA4B,YAAA;AAAA;EAAA,SAC5B,OAAA;EAAA,SAA4B,YAAA;AAAA;EAAA,SAC5B,OAAA;EAAA,SAA0B,YAAA;AAAA;AAAA,KAE7B,OAAA,GAAU,sBAAA;AAAA,KAaV,QAAA,GAAW,OAAA,CACrB,sBAAA;EAAA,SACW,YAAA;AAAA;AAAA,KAGD,WAAA,GAAc,OAAA,CACxB,sBAAA;EAAA,SACW,YAAA;AAAA;AAAA,KAGD,SAAA,GAAY,OAAA,CACtB,sBAAA;EAAA,SACW,YAAA;AAAA;AAAA,KAGD,WAAA,kBAA6B,OAAA,IAAW,OAAA,CAClD,sBAAA;EAAA,SACW,OAAA,EAAS,QAAA;AAAA;AAAA,KAGV,UAAA,iCAA2C,sBAAA,IACrD,uBAAA;AAAA,KAEU,eAAA,iCACsB,sBAAA,IAC9B,uBAAA;AAAA,cAES,WAAA;EAAA,SAAqC,OAAA;EAAA,SAAA,YAAA;AAAA;AAAA,KACtC,WAAA,UAAqB,WAAA;AAAA,cAEpB,cAAA;EAAA,SAA2C,OAAA;EAAA,SAAA,YAAA;AAAA;AAAA,KAC5C,cAAA,UAAwB,cAAA;AAAA,cAEvB,YAAA;EAAA,SAAuC,OAAA;EAAA,SAAA,YAAA;AAAA;AAAA,KACxC,YAAA,UAAsB,YAAA;AAAA,cAErB,UAAA;EAAA,SAAmC,OAAA;EAAA,SAAA,YAAA;AAAA;AAAA,KACpC,UAAA,UAAoB,UAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
+
|
|
3
|
+
//#region src/RuntimeAndFunctionType.ts
|
|
4
|
+
var RuntimeAndFunctionType_exports = /* @__PURE__ */ __exportAll({
|
|
5
|
+
ConvexAction: () => ConvexAction,
|
|
6
|
+
ConvexMutation: () => ConvexMutation,
|
|
7
|
+
ConvexQuery: () => ConvexQuery,
|
|
8
|
+
NodeAction: () => NodeAction
|
|
9
|
+
});
|
|
10
|
+
const make = (runtime, functionType) => ({
|
|
11
|
+
runtime,
|
|
12
|
+
functionType
|
|
13
|
+
});
|
|
14
|
+
const ConvexQuery = make("Convex", "query");
|
|
15
|
+
const ConvexMutation = make("Convex", "mutation");
|
|
16
|
+
const ConvexAction = make("Convex", "action");
|
|
17
|
+
const NodeAction = make("Node", "action");
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { ConvexAction, ConvexMutation, ConvexQuery, NodeAction, RuntimeAndFunctionType_exports };
|
|
21
|
+
//# sourceMappingURL=RuntimeAndFunctionType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RuntimeAndFunctionType.js","names":[],"sources":["../src/RuntimeAndFunctionType.ts"],"sourcesContent":["export type RuntimeAndFunctionType =\n | { readonly runtime: \"Convex\"; readonly functionType: \"query\" }\n | { readonly runtime: \"Convex\"; readonly functionType: \"mutation\" }\n | { readonly runtime: \"Convex\"; readonly functionType: \"action\" }\n | { readonly runtime: \"Node\"; readonly functionType: \"action\" };\n\nexport type Runtime = RuntimeAndFunctionType[\"runtime\"];\n\nconst make = <\n Runtime_ extends Runtime,\n FunctionType_ extends GetFunctionType<WithRuntime<Runtime_>>,\n>(\n runtime: Runtime_,\n functionType: FunctionType_,\n): { readonly runtime: Runtime_; readonly functionType: FunctionType_ } => ({\n runtime,\n functionType,\n});\n\nexport type AnyQuery = Extract<\n RuntimeAndFunctionType,\n { readonly functionType: \"query\" }\n>;\n\nexport type AnyMutation = Extract<\n RuntimeAndFunctionType,\n { readonly functionType: \"mutation\" }\n>;\n\nexport type AnyAction = Extract<\n RuntimeAndFunctionType,\n { readonly functionType: \"action\" }\n>;\n\nexport type WithRuntime<Runtime_ extends Runtime> = Extract<\n RuntimeAndFunctionType,\n { readonly runtime: Runtime_ }\n>;\n\nexport type GetRuntime<RuntimeAndFunctionType_ extends RuntimeAndFunctionType> =\n RuntimeAndFunctionType_[\"runtime\"];\n\nexport type GetFunctionType<\n RuntimeAndFunctionType_ extends RuntimeAndFunctionType,\n> = RuntimeAndFunctionType_[\"functionType\"];\n\nexport const ConvexQuery = make(\"Convex\", \"query\");\nexport type ConvexQuery = typeof ConvexQuery;\n\nexport const ConvexMutation = make(\"Convex\", \"mutation\");\nexport type ConvexMutation = typeof ConvexMutation;\n\nexport const ConvexAction = make(\"Convex\", \"action\");\nexport type ConvexAction = typeof ConvexAction;\n\nexport const NodeAction = make(\"Node\", \"action\");\nexport type NodeAction = typeof NodeAction;\n"],"mappings":";;;;;;;;;AAQA,MAAM,QAIJ,SACA,kBAC0E;CAC1E;CACA;CACD;AA6BD,MAAa,cAAc,KAAK,UAAU,QAAQ;AAGlD,MAAa,iBAAiB,KAAK,UAAU,WAAW;AAGxD,MAAa,eAAe,KAAK,UAAU,SAAS;AAGpD,MAAa,aAAa,KAAK,QAAQ,SAAS"}
|
package/dist/Spec.d.ts
CHANGED
|
@@ -1,23 +1,35 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Runtime } from "./RuntimeAndFunctionType.js";
|
|
2
|
+
import { AnyWithProps as AnyWithProps$1, AnyWithPropsWithRuntime as AnyWithPropsWithRuntime$1, Name, WithName } from "./GroupSpec.js";
|
|
2
3
|
|
|
3
4
|
//#region src/Spec.d.ts
|
|
4
5
|
declare namespace Spec_d_exports {
|
|
5
|
-
export { Any, AnyWithProps, Groups, Spec, TypeId, isSpec, make };
|
|
6
|
+
export { Any, AnyWithProps, AnyWithPropsWithRuntime, Groups, Spec, TypeId, isConvexSpec, isNodeSpec, isSpec, make, makeNode, merge };
|
|
6
7
|
}
|
|
7
|
-
declare const TypeId = "@confect/core/
|
|
8
|
+
declare const TypeId = "@confect/core/Spec";
|
|
8
9
|
type TypeId = typeof TypeId;
|
|
9
10
|
declare const isSpec: (u: unknown) => u is AnyWithProps;
|
|
10
|
-
|
|
11
|
+
declare const isConvexSpec: (u: unknown) => u is AnyWithPropsWithRuntime<"Convex">;
|
|
12
|
+
declare const isNodeSpec: (u: unknown) => u is AnyWithPropsWithRuntime<"Node">;
|
|
13
|
+
interface Spec<Runtime$2 extends Runtime, Groups_ extends AnyWithPropsWithRuntime$1<Runtime$2> = never> {
|
|
11
14
|
readonly [TypeId]: TypeId;
|
|
15
|
+
readonly runtime: Runtime$2;
|
|
12
16
|
readonly groups: { [GroupName in Name<Groups_>]: WithName<Groups_, GroupName> };
|
|
13
|
-
add<Group extends
|
|
17
|
+
add<Group extends AnyWithPropsWithRuntime$1<Runtime$2>>(group: Group): Spec<Runtime$2, Groups_ | Group>;
|
|
14
18
|
}
|
|
15
19
|
interface Any {
|
|
16
20
|
readonly [TypeId]: TypeId;
|
|
17
21
|
}
|
|
18
|
-
interface AnyWithProps extends Spec<AnyWithProps$1> {}
|
|
22
|
+
interface AnyWithProps extends Spec<Runtime, AnyWithProps$1> {}
|
|
23
|
+
interface AnyWithPropsWithRuntime<Runtime$1 extends Runtime> extends Spec<Runtime$1, AnyWithPropsWithRuntime$1<Runtime$1>> {}
|
|
19
24
|
type Groups<Spec_ extends AnyWithProps> = Spec_["groups"][keyof Spec_["groups"]];
|
|
20
|
-
declare const make: () => Spec
|
|
25
|
+
declare const make: () => Spec<"Convex">;
|
|
26
|
+
declare const makeNode: () => Spec<"Node">;
|
|
27
|
+
/**
|
|
28
|
+
* Merges a Convex spec with an optional Node spec for use with `Api.make`.
|
|
29
|
+
* When `nodeSpec` is provided, its groups are merged under a "node" namespace,
|
|
30
|
+
* mirroring the structure used by `Refs.make`.
|
|
31
|
+
*/
|
|
32
|
+
declare const merge: <ConvexSpec extends AnyWithPropsWithRuntime<"Convex">, NodeSpec extends AnyWithPropsWithRuntime<"Node">>(convexSpec: ConvexSpec, nodeSpec?: NodeSpec) => AnyWithProps;
|
|
21
33
|
//#endregion
|
|
22
|
-
export { Any, AnyWithProps, Groups, Spec, Spec_d_exports, TypeId, isSpec, make };
|
|
34
|
+
export { Any, AnyWithProps, AnyWithPropsWithRuntime, Groups, Spec, Spec_d_exports, TypeId, isConvexSpec, isNodeSpec, isSpec, make, makeNode, merge };
|
|
23
35
|
//# sourceMappingURL=Spec.d.ts.map
|
package/dist/Spec.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Spec.d.ts","names":[],"sources":["../src/Spec.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"Spec.d.ts","names":[],"sources":["../src/Spec.ts"],"mappings":";;;;;;;cAIa,MAAA;AAAA,KACD,MAAA,UAAgB,MAAA;AAAA,cAEf,MAAA,GAAU,CAAA,cAAa,CAAA,IAAK,YAAA;AAAA,cAG5B,YAAA,GACX,CAAA,cACC,CAAA,IAAK,uBAAA;AAAA,cAKK,UAAA,GAAc,CAAA,cAAa,CAAA,IAAK,uBAAA;AAAA,UAK5B,IAAA,mBACC,OAAA,kBACA,yBAAA,CAAkC,SAAA;EAAA,UAExC,MAAA,GAAS,MAAA;EAAA,SACV,OAAA,EAAS,SAAA;EAAA,SACT,MAAA,kBACO,IAAA,CAAe,OAAA,IAAW,QAAA,CACtC,OAAA,EACA,SAAA;EAIJ,GAAA,eAAkB,yBAAA,CAAkC,SAAA,GAClD,KAAA,EAAO,KAAA,GACN,IAAA,CAAK,SAAA,EAAS,OAAA,GAAU,KAAA;AAAA;AAAA,UAGZ,GAAA;EAAA,UACL,MAAA,GAAS,MAAA;AAAA;AAAA,UAGJ,YAAA,SAAqB,IAAA,CACpC,OAAA,EACA,cAAA;AAAA,UAGe,uBAAA,mBACC,OAAA,UACR,IAAA,CAAK,SAAA,EAAS,yBAAA,CAAkC,SAAA;AAAA,KAE9C,MAAA,eAAqB,YAAA,IAC/B,KAAA,iBAAsB,KAAA;AAAA,cA4BX,IAAA,QAAW,IAAA;AAAA,cAGX,QAAA,QAAe,IAAA;;;;;AA9E5B;cAsFa,KAAA,sBACQ,uBAAA,6BACF,uBAAA,UAEjB,UAAA,EAAY,UAAA,EACZ,QAAA,GAAW,QAAA,KACV,YAAA"}
|
package/dist/Spec.js
CHANGED
|
@@ -1,23 +1,59 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
-
import {
|
|
2
|
+
import { makeNode as makeNode$1 } from "./GroupSpec.js";
|
|
3
|
+
import { Array, Predicate, Record } from "effect";
|
|
3
4
|
|
|
4
5
|
//#region src/Spec.ts
|
|
5
6
|
var Spec_exports = /* @__PURE__ */ __exportAll({
|
|
6
7
|
TypeId: () => TypeId,
|
|
8
|
+
isConvexSpec: () => isConvexSpec,
|
|
9
|
+
isNodeSpec: () => isNodeSpec,
|
|
7
10
|
isSpec: () => isSpec,
|
|
8
|
-
make: () => make
|
|
11
|
+
make: () => make,
|
|
12
|
+
makeNode: () => makeNode,
|
|
13
|
+
merge: () => merge
|
|
9
14
|
});
|
|
10
|
-
const TypeId = "@confect/core/
|
|
15
|
+
const TypeId = "@confect/core/Spec";
|
|
11
16
|
const isSpec = (u) => Predicate.hasProperty(u, TypeId);
|
|
17
|
+
const isConvexSpec = (u) => Predicate.hasProperty(u, TypeId) && Predicate.hasProperty(u, "runtime") && u.runtime === "Convex";
|
|
18
|
+
const isNodeSpec = (u) => Predicate.hasProperty(u, TypeId) && Predicate.hasProperty(u, "runtime") && u.runtime === "Node";
|
|
12
19
|
const Proto = {
|
|
13
20
|
[TypeId]: TypeId,
|
|
14
21
|
add(group) {
|
|
15
|
-
return makeProto({
|
|
22
|
+
return makeProto({
|
|
23
|
+
runtime: this.runtime,
|
|
24
|
+
groups: Record.set(this.groups, group.name, group)
|
|
25
|
+
});
|
|
16
26
|
}
|
|
17
27
|
};
|
|
18
|
-
const makeProto = ({ groups }) => Object.assign(Object.create(Proto), {
|
|
19
|
-
|
|
28
|
+
const makeProto = ({ runtime, groups }) => Object.assign(Object.create(Proto), {
|
|
29
|
+
runtime,
|
|
30
|
+
groups
|
|
31
|
+
});
|
|
32
|
+
const make = () => makeProto({
|
|
33
|
+
runtime: "Convex",
|
|
34
|
+
groups: {}
|
|
35
|
+
});
|
|
36
|
+
const makeNode = () => makeProto({
|
|
37
|
+
runtime: "Node",
|
|
38
|
+
groups: {}
|
|
39
|
+
});
|
|
40
|
+
/**
|
|
41
|
+
* Merges a Convex spec with an optional Node spec for use with `Api.make`.
|
|
42
|
+
* When `nodeSpec` is provided, its groups are merged under a "node" namespace,
|
|
43
|
+
* mirroring the structure used by `Refs.make`.
|
|
44
|
+
*/
|
|
45
|
+
const merge = (convexSpec, nodeSpec) => {
|
|
46
|
+
const nodeGroup = nodeSpec ? Array.reduce(Record.values(nodeSpec.groups), makeNode$1("node"), (nodeGroupSpec, group) => nodeGroupSpec.addGroup(group)) : null;
|
|
47
|
+
const groups = nodeGroup ? {
|
|
48
|
+
...convexSpec.groups,
|
|
49
|
+
node: nodeGroup
|
|
50
|
+
} : convexSpec.groups;
|
|
51
|
+
return Object.assign(Object.create(Proto), {
|
|
52
|
+
runtime: "Convex",
|
|
53
|
+
groups
|
|
54
|
+
});
|
|
55
|
+
};
|
|
20
56
|
|
|
21
57
|
//#endregion
|
|
22
|
-
export { Spec_exports, TypeId, isSpec, make };
|
|
58
|
+
export { Spec_exports, TypeId, isConvexSpec, isNodeSpec, isSpec, make, makeNode, merge };
|
|
23
59
|
//# sourceMappingURL=Spec.js.map
|
package/dist/Spec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Spec.js","names":[],"sources":["../src/Spec.ts"],"sourcesContent":["import { Predicate, Record } from \"effect\";\nimport
|
|
1
|
+
{"version":3,"file":"Spec.js","names":["GroupSpec.makeNode"],"sources":["../src/Spec.ts"],"sourcesContent":["import { Array, Predicate, Record } from \"effect\";\nimport * as GroupSpec from \"./GroupSpec\";\nimport type * as RuntimeAndFunctionType from \"./RuntimeAndFunctionType\";\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\nexport const isConvexSpec = (\n u: unknown,\n): u is AnyWithPropsWithRuntime<\"Convex\"> =>\n Predicate.hasProperty(u, TypeId) &&\n Predicate.hasProperty(u, \"runtime\") &&\n u.runtime === \"Convex\";\n\nexport const isNodeSpec = (u: unknown): u is AnyWithPropsWithRuntime<\"Node\"> =>\n Predicate.hasProperty(u, TypeId) &&\n Predicate.hasProperty(u, \"runtime\") &&\n u.runtime === \"Node\";\n\nexport interface Spec<\n Runtime extends RuntimeAndFunctionType.Runtime,\n Groups_ extends GroupSpec.AnyWithPropsWithRuntime<Runtime> = never,\n> {\n readonly [TypeId]: TypeId;\n readonly runtime: Runtime;\n readonly groups: {\n [GroupName in GroupSpec.Name<Groups_>]: GroupSpec.WithName<\n Groups_,\n GroupName\n >;\n };\n\n add<Group extends GroupSpec.AnyWithPropsWithRuntime<Runtime>>(\n group: Group,\n ): Spec<Runtime, Groups_ | Group>;\n}\n\nexport interface Any {\n readonly [TypeId]: TypeId;\n}\n\nexport interface AnyWithProps extends Spec<\n RuntimeAndFunctionType.Runtime,\n GroupSpec.AnyWithProps\n> {}\n\nexport interface AnyWithPropsWithRuntime<\n Runtime extends RuntimeAndFunctionType.Runtime,\n> extends Spec<Runtime, GroupSpec.AnyWithPropsWithRuntime<Runtime>> {}\n\nexport type Groups<Spec_ extends AnyWithProps> =\n Spec_[\"groups\"][keyof Spec_[\"groups\"]];\n\nconst Proto = {\n [TypeId]: TypeId,\n\n add<Group extends GroupSpec.AnyWithProps>(this: AnyWithProps, group: Group) {\n return makeProto({\n runtime: this.runtime,\n groups: Record.set(this.groups, group.name, group),\n });\n },\n};\n\nconst makeProto = <\n Runtime extends RuntimeAndFunctionType.Runtime,\n Groups_ extends GroupSpec.AnyWithPropsWithRuntime<Runtime>,\n>({\n runtime,\n groups,\n}: {\n runtime: Runtime;\n groups: Record.ReadonlyRecord<string, Groups_>;\n}): Spec<Runtime, Groups_> =>\n Object.assign(Object.create(Proto), {\n runtime,\n groups,\n });\n\nexport const make = (): Spec<\"Convex\"> =>\n makeProto({ runtime: \"Convex\", groups: {} });\n\nexport const makeNode = (): Spec<\"Node\"> =>\n makeProto({ runtime: \"Node\", groups: {} });\n\n/**\n * Merges a Convex spec with an optional Node spec for use with `Api.make`.\n * When `nodeSpec` is provided, its groups are merged under a \"node\" namespace,\n * mirroring the structure used by `Refs.make`.\n */\nexport const merge = <\n ConvexSpec extends AnyWithPropsWithRuntime<\"Convex\">,\n NodeSpec extends AnyWithPropsWithRuntime<\"Node\">,\n>(\n convexSpec: ConvexSpec,\n nodeSpec?: NodeSpec,\n): AnyWithProps => {\n const nodeGroup = nodeSpec\n ? Array.reduce(\n Record.values(nodeSpec.groups),\n GroupSpec.makeNode(\"node\"),\n (nodeGroupSpec, group) => nodeGroupSpec.addGroup(group),\n )\n : null;\n\n const groups = nodeGroup\n ? { ...convexSpec.groups, node: nodeGroup }\n : convexSpec.groups;\n\n return Object.assign(Object.create(Proto), {\n runtime: \"Convex\" as const,\n groups,\n }) as AnyWithProps;\n};\n"],"mappings":";;;;;;;;;;;;;;AAIA,MAAa,SAAS;AAGtB,MAAa,UAAU,MACrB,UAAU,YAAY,GAAG,OAAO;AAElC,MAAa,gBACX,MAEA,UAAU,YAAY,GAAG,OAAO,IAChC,UAAU,YAAY,GAAG,UAAU,IACnC,EAAE,YAAY;AAEhB,MAAa,cAAc,MACzB,UAAU,YAAY,GAAG,OAAO,IAChC,UAAU,YAAY,GAAG,UAAU,IACnC,EAAE,YAAY;AAoChB,MAAM,QAAQ;EACX,SAAS;CAEV,IAA8D,OAAc;AAC1E,SAAO,UAAU;GACf,SAAS,KAAK;GACd,QAAQ,OAAO,IAAI,KAAK,QAAQ,MAAM,MAAM,MAAM;GACnD,CAAC;;CAEL;AAED,MAAM,aAGJ,EACA,SACA,aAKA,OAAO,OAAO,OAAO,OAAO,MAAM,EAAE;CAClC;CACA;CACD,CAAC;AAEJ,MAAa,aACX,UAAU;CAAE,SAAS;CAAU,QAAQ,EAAE;CAAE,CAAC;AAE9C,MAAa,iBACX,UAAU;CAAE,SAAS;CAAQ,QAAQ,EAAE;CAAE,CAAC;;;;;;AAO5C,MAAa,SAIX,YACA,aACiB;CACjB,MAAM,YAAY,WACd,MAAM,OACJ,OAAO,OAAO,SAAS,OAAO,EAC9BA,WAAmB,OAAO,GACzB,eAAe,UAAU,cAAc,SAAS,MAAM,CACxD,GACD;CAEJ,MAAM,SAAS,YACX;EAAE,GAAG,WAAW;EAAQ,MAAM;EAAW,GACzC,WAAW;AAEf,QAAO,OAAO,OAAO,OAAO,OAAO,MAAM,EAAE;EACzC,SAAS;EACT;EACD,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RuntimeAndFunctionType_d_exports } from "./RuntimeAndFunctionType.js";
|
|
1
2
|
import { FunctionSpec_d_exports } from "./FunctionSpec.js";
|
|
2
3
|
import { GenericId_d_exports } from "./GenericId.js";
|
|
3
4
|
import { GroupSpec_d_exports } from "./GroupSpec.js";
|
|
@@ -9,4 +10,4 @@ import { Refs_d_exports } from "./Refs.js";
|
|
|
9
10
|
import { SystemFields_d_exports } from "./SystemFields.js";
|
|
10
11
|
import { Types_d_exports } from "./Types.js";
|
|
11
12
|
import { UserIdentity_d_exports } from "./UserIdentity.js";
|
|
12
|
-
export { FunctionSpec_d_exports as FunctionSpec, GenericId_d_exports as GenericId, GroupPath_d_exports as GroupPath, GroupSpec_d_exports as GroupSpec, PaginationResult_d_exports as PaginationResult, Ref_d_exports as Ref, Refs_d_exports as Refs, Spec_d_exports as Spec, SystemFields_d_exports as SystemFields, Types_d_exports as Types, UserIdentity_d_exports as UserIdentity };
|
|
13
|
+
export { FunctionSpec_d_exports as FunctionSpec, GenericId_d_exports as GenericId, GroupPath_d_exports as GroupPath, GroupSpec_d_exports as GroupSpec, PaginationResult_d_exports as PaginationResult, Ref_d_exports as Ref, Refs_d_exports as Refs, RuntimeAndFunctionType_d_exports as RuntimeAndFunctionType, Spec_d_exports as Spec, SystemFields_d_exports as SystemFields, Types_d_exports as Types, UserIdentity_d_exports as UserIdentity };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RuntimeAndFunctionType_exports } from "./RuntimeAndFunctionType.js";
|
|
1
2
|
import { FunctionSpec_exports } from "./FunctionSpec.js";
|
|
2
3
|
import { GenericId_exports } from "./GenericId.js";
|
|
3
4
|
import { GroupPath_exports } from "./GroupPath.js";
|
|
@@ -10,4 +11,4 @@ import { SystemFields_exports } from "./SystemFields.js";
|
|
|
10
11
|
import { Types_exports } from "./Types.js";
|
|
11
12
|
import { UserIdentity_exports } from "./UserIdentity.js";
|
|
12
13
|
|
|
13
|
-
export { FunctionSpec_exports as FunctionSpec, GenericId_exports as GenericId, GroupPath_exports as GroupPath, GroupSpec_exports as GroupSpec, PaginationResult_exports as PaginationResult, Ref_exports as Ref, Refs_exports as Refs, Spec_exports as Spec, SystemFields_exports as SystemFields, Types_exports as Types, UserIdentity_exports as UserIdentity };
|
|
14
|
+
export { FunctionSpec_exports as FunctionSpec, GenericId_exports as GenericId, GroupPath_exports as GroupPath, GroupSpec_exports as GroupSpec, PaginationResult_exports as PaginationResult, Ref_exports as Ref, Refs_exports as Refs, RuntimeAndFunctionType_exports as RuntimeAndFunctionType, Spec_exports as Spec, SystemFields_exports as SystemFields, Types_exports as Types, UserIdentity_exports as UserIdentity };
|
package/package.json
CHANGED
package/src/FunctionSpec.ts
CHANGED
|
@@ -8,22 +8,23 @@ import type {
|
|
|
8
8
|
import type { Schema } from "effect";
|
|
9
9
|
import { Predicate } from "effect";
|
|
10
10
|
import { validateConfectFunctionIdentifier } from "./internal/utils";
|
|
11
|
+
import * as RuntimeAndFunctionType from "./RuntimeAndFunctionType";
|
|
11
12
|
|
|
12
|
-
export const TypeId = "@confect/core/
|
|
13
|
+
export const TypeId = "@confect/core/FunctionSpec";
|
|
13
14
|
export type TypeId = typeof TypeId;
|
|
14
15
|
|
|
15
16
|
export const isFunctionSpec = (u: unknown): u is AnyWithProps =>
|
|
16
17
|
Predicate.hasProperty(u, TypeId);
|
|
17
18
|
|
|
18
19
|
export interface FunctionSpec<
|
|
19
|
-
|
|
20
|
+
RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,
|
|
20
21
|
FunctionVisibility_ extends FunctionVisibility,
|
|
21
22
|
Name_ extends string,
|
|
22
23
|
Args_ extends Schema.Schema.AnyNoContext,
|
|
23
24
|
Returns_ extends Schema.Schema.AnyNoContext,
|
|
24
25
|
> {
|
|
25
26
|
readonly [TypeId]: TypeId;
|
|
26
|
-
readonly
|
|
27
|
+
readonly runtimeAndFunctionType: RuntimeAndFunctionType_;
|
|
27
28
|
readonly functionVisibility: FunctionVisibility_;
|
|
28
29
|
readonly name: Name_;
|
|
29
30
|
readonly args: Args_;
|
|
@@ -35,7 +36,17 @@ export interface Any {
|
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
export interface AnyWithProps extends FunctionSpec<
|
|
38
|
-
|
|
39
|
+
RuntimeAndFunctionType.RuntimeAndFunctionType,
|
|
40
|
+
FunctionVisibility,
|
|
41
|
+
string,
|
|
42
|
+
Schema.Schema.AnyNoContext,
|
|
43
|
+
Schema.Schema.AnyNoContext
|
|
44
|
+
> {}
|
|
45
|
+
|
|
46
|
+
export interface AnyWithPropsWithRuntime<
|
|
47
|
+
Runtime extends RuntimeAndFunctionType.Runtime,
|
|
48
|
+
> extends FunctionSpec<
|
|
49
|
+
RuntimeAndFunctionType.WithRuntime<Runtime>,
|
|
39
50
|
FunctionVisibility,
|
|
40
51
|
string,
|
|
41
52
|
Schema.Schema.AnyNoContext,
|
|
@@ -43,17 +54,17 @@ export interface AnyWithProps extends FunctionSpec<
|
|
|
43
54
|
> {}
|
|
44
55
|
|
|
45
56
|
export interface AnyWithPropsWithFunctionType<
|
|
46
|
-
|
|
57
|
+
RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,
|
|
47
58
|
> extends FunctionSpec<
|
|
48
|
-
|
|
59
|
+
RuntimeAndFunctionType_,
|
|
49
60
|
FunctionVisibility,
|
|
50
61
|
string,
|
|
51
62
|
Schema.Schema.AnyNoContext,
|
|
52
63
|
Schema.Schema.AnyNoContext
|
|
53
64
|
> {}
|
|
54
65
|
|
|
55
|
-
export type
|
|
56
|
-
Function["
|
|
66
|
+
export type GetRuntimeAndFunctionType<Function extends AnyWithProps> =
|
|
67
|
+
Function["runtimeAndFunctionType"];
|
|
57
68
|
|
|
58
69
|
export type GetFunctionVisibility<Function extends AnyWithProps> =
|
|
59
70
|
Function["functionVisibility"];
|
|
@@ -69,30 +80,47 @@ export type WithName<
|
|
|
69
80
|
Name_ extends string,
|
|
70
81
|
> = Extract<Function, { readonly name: Name_ }>;
|
|
71
82
|
|
|
83
|
+
export type WithRuntimeAndFunctionType<
|
|
84
|
+
Function extends AnyWithProps,
|
|
85
|
+
RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,
|
|
86
|
+
> = Extract<
|
|
87
|
+
Function,
|
|
88
|
+
{ readonly runtimeAndFunctionType: RuntimeAndFunctionType_ }
|
|
89
|
+
>;
|
|
90
|
+
|
|
72
91
|
export type WithFunctionType<
|
|
73
92
|
Function extends AnyWithProps,
|
|
74
93
|
FunctionType_ extends FunctionType,
|
|
75
|
-
> = Extract<
|
|
94
|
+
> = Extract<
|
|
95
|
+
Function,
|
|
96
|
+
{ readonly runtimeAndFunctionType: { readonly functionType: FunctionType_ } }
|
|
97
|
+
>;
|
|
76
98
|
|
|
77
|
-
export type
|
|
99
|
+
export type WithoutName<
|
|
78
100
|
Function extends AnyWithProps,
|
|
79
101
|
Name_ extends Name<Function>,
|
|
80
102
|
> = Exclude<Function, { readonly name: Name_ }>;
|
|
81
103
|
|
|
82
104
|
export type RegisteredFunction<Function extends AnyWithProps> =
|
|
83
|
-
|
|
105
|
+
RuntimeAndFunctionType.GetFunctionType<
|
|
106
|
+
Function["runtimeAndFunctionType"]
|
|
107
|
+
> extends "Convex"
|
|
84
108
|
? RegisteredQuery<
|
|
85
109
|
GetFunctionVisibility<Function>,
|
|
86
110
|
Args<Function>["Encoded"],
|
|
87
111
|
Promise<Returns<Function>["Encoded"]>
|
|
88
112
|
>
|
|
89
|
-
:
|
|
113
|
+
: RuntimeAndFunctionType.GetFunctionType<
|
|
114
|
+
Function["runtimeAndFunctionType"]
|
|
115
|
+
> extends "mutation"
|
|
90
116
|
? RegisteredMutation<
|
|
91
117
|
GetFunctionVisibility<Function>,
|
|
92
118
|
Args<Function>["Encoded"],
|
|
93
119
|
Promise<Returns<Function>["Encoded"]>
|
|
94
120
|
>
|
|
95
|
-
:
|
|
121
|
+
: RuntimeAndFunctionType.GetFunctionType<
|
|
122
|
+
Function["runtimeAndFunctionType"]
|
|
123
|
+
> extends "action"
|
|
96
124
|
? RegisteredAction<
|
|
97
125
|
GetFunctionVisibility<Function>,
|
|
98
126
|
Args<Function>["Encoded"],
|
|
@@ -106,10 +134,11 @@ const Proto = {
|
|
|
106
134
|
|
|
107
135
|
const make =
|
|
108
136
|
<
|
|
109
|
-
|
|
137
|
+
RuntimeAndFunctionType_ extends
|
|
138
|
+
RuntimeAndFunctionType.RuntimeAndFunctionType,
|
|
110
139
|
FunctionVisibility_ extends FunctionVisibility,
|
|
111
140
|
>(
|
|
112
|
-
|
|
141
|
+
runtimeAndFunctionType: RuntimeAndFunctionType_,
|
|
113
142
|
functionVisibility: FunctionVisibility_,
|
|
114
143
|
) =>
|
|
115
144
|
<
|
|
@@ -125,7 +154,7 @@ const make =
|
|
|
125
154
|
args: Args_;
|
|
126
155
|
returns: Returns_;
|
|
127
156
|
}): FunctionSpec<
|
|
128
|
-
|
|
157
|
+
RuntimeAndFunctionType_,
|
|
129
158
|
FunctionVisibility_,
|
|
130
159
|
Name_,
|
|
131
160
|
Args_,
|
|
@@ -134,7 +163,7 @@ const make =
|
|
|
134
163
|
validateConfectFunctionIdentifier(name);
|
|
135
164
|
|
|
136
165
|
return Object.assign(Object.create(Proto), {
|
|
137
|
-
|
|
166
|
+
runtimeAndFunctionType,
|
|
138
167
|
functionVisibility,
|
|
139
168
|
name,
|
|
140
169
|
args,
|
|
@@ -142,11 +171,30 @@ const make =
|
|
|
142
171
|
});
|
|
143
172
|
};
|
|
144
173
|
|
|
145
|
-
export const
|
|
146
|
-
export const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
174
|
+
export const publicQuery = make(RuntimeAndFunctionType.ConvexQuery, "public");
|
|
175
|
+
export const internalQuery = make(
|
|
176
|
+
RuntimeAndFunctionType.ConvexQuery,
|
|
177
|
+
"internal",
|
|
178
|
+
);
|
|
179
|
+
export const publicMutation = make(
|
|
180
|
+
RuntimeAndFunctionType.ConvexMutation,
|
|
181
|
+
"public",
|
|
182
|
+
);
|
|
183
|
+
export const internalMutation = make(
|
|
184
|
+
RuntimeAndFunctionType.ConvexMutation,
|
|
185
|
+
"internal",
|
|
186
|
+
);
|
|
187
|
+
export const publicAction = make(RuntimeAndFunctionType.ConvexAction, "public");
|
|
188
|
+
export const internalAction = make(
|
|
189
|
+
RuntimeAndFunctionType.ConvexAction,
|
|
190
|
+
"internal",
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
export const publicNodeAction = make(
|
|
194
|
+
RuntimeAndFunctionType.NodeAction,
|
|
195
|
+
"public",
|
|
196
|
+
);
|
|
197
|
+
export const internalNodeAction = make(
|
|
198
|
+
RuntimeAndFunctionType.NodeAction,
|
|
199
|
+
"internal",
|
|
200
|
+
);
|
package/src/GroupSpec.ts
CHANGED
|
@@ -1,37 +1,39 @@
|
|
|
1
1
|
import { Predicate, Record } from "effect";
|
|
2
2
|
import type * as FunctionSpec from "./FunctionSpec";
|
|
3
|
+
import type * as RuntimeAndFunctionType from "./RuntimeAndFunctionType";
|
|
3
4
|
import { validateConfectFunctionIdentifier } from "./internal/utils";
|
|
4
5
|
|
|
5
|
-
export const TypeId = "@confect/core/
|
|
6
|
+
export const TypeId = "@confect/core/GroupSpec";
|
|
6
7
|
export type TypeId = typeof TypeId;
|
|
7
8
|
|
|
8
9
|
export const isGroupSpec = (u: unknown): u is Any =>
|
|
9
10
|
Predicate.hasProperty(u, TypeId);
|
|
10
11
|
|
|
11
12
|
export interface GroupSpec<
|
|
13
|
+
Runtime extends RuntimeAndFunctionType.Runtime,
|
|
12
14
|
Name_ extends string,
|
|
13
|
-
Functions_ extends FunctionSpec.
|
|
14
|
-
Groups_ extends
|
|
15
|
+
Functions_ extends FunctionSpec.AnyWithPropsWithRuntime<Runtime> = never,
|
|
16
|
+
Groups_ extends AnyWithPropsWithRuntime<Runtime> = never,
|
|
15
17
|
> {
|
|
16
18
|
readonly [TypeId]: TypeId;
|
|
19
|
+
readonly runtime: Runtime;
|
|
17
20
|
readonly name: Name_;
|
|
18
21
|
readonly functions: {
|
|
19
|
-
[FunctionName in FunctionSpec.Name<
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
>;
|
|
22
|
+
[FunctionName in FunctionSpec.Name<
|
|
23
|
+
FunctionSpec.AnyWithPropsWithRuntime<Runtime>
|
|
24
|
+
>]: FunctionSpec.WithName<Functions_, FunctionName>;
|
|
23
25
|
};
|
|
24
26
|
readonly groups: {
|
|
25
27
|
[GroupName in Name<Groups_>]: WithName<Groups_, GroupName>;
|
|
26
28
|
};
|
|
27
29
|
|
|
28
|
-
addFunction<Function extends FunctionSpec.
|
|
30
|
+
addFunction<Function extends FunctionSpec.AnyWithPropsWithRuntime<Runtime>>(
|
|
29
31
|
function_: Function,
|
|
30
|
-
): GroupSpec<Name_, Functions_ | Function, Groups_>;
|
|
32
|
+
): GroupSpec<Runtime, Name_, Functions_ | Function, Groups_>;
|
|
31
33
|
|
|
32
|
-
addGroup<Group extends
|
|
34
|
+
addGroup<Group extends AnyWithPropsWithRuntime<Runtime>>(
|
|
33
35
|
group: Group,
|
|
34
|
-
): GroupSpec<Name_, Functions_, Groups_ | Group>;
|
|
36
|
+
): GroupSpec<Runtime, Name_, Functions_, Groups_ | Group>;
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
export interface Any {
|
|
@@ -39,11 +41,21 @@ export interface Any {
|
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
export interface AnyWithProps extends GroupSpec<
|
|
44
|
+
RuntimeAndFunctionType.Runtime,
|
|
42
45
|
string,
|
|
43
46
|
FunctionSpec.AnyWithProps,
|
|
44
47
|
AnyWithProps
|
|
45
48
|
> {}
|
|
46
49
|
|
|
50
|
+
export interface AnyWithPropsWithRuntime<
|
|
51
|
+
Runtime extends RuntimeAndFunctionType.Runtime,
|
|
52
|
+
> extends GroupSpec<
|
|
53
|
+
Runtime,
|
|
54
|
+
string,
|
|
55
|
+
FunctionSpec.AnyWithPropsWithRuntime<Runtime>,
|
|
56
|
+
AnyWithPropsWithRuntime<Runtime>
|
|
57
|
+
> {}
|
|
58
|
+
|
|
47
59
|
export type Name<Group extends AnyWithProps> = Group["name"];
|
|
48
60
|
|
|
49
61
|
export type Functions<Group extends AnyWithProps> =
|
|
@@ -73,6 +85,7 @@ const Proto = {
|
|
|
73
85
|
const this_ = this as AnyWithProps;
|
|
74
86
|
|
|
75
87
|
return makeProto({
|
|
88
|
+
runtime: this_.runtime,
|
|
76
89
|
name: this_.name,
|
|
77
90
|
functions: Record.set(this_.functions, function_.name, function_),
|
|
78
91
|
groups: this_.groups,
|
|
@@ -84,6 +97,7 @@ const Proto = {
|
|
|
84
97
|
const group_ = group as unknown as AnyWithProps;
|
|
85
98
|
|
|
86
99
|
return makeProto({
|
|
100
|
+
runtime: this_.runtime,
|
|
87
101
|
name: this_.name,
|
|
88
102
|
functions: this_.functions,
|
|
89
103
|
groups: Record.set(this_.groups, group_.name, group_),
|
|
@@ -92,19 +106,23 @@ const Proto = {
|
|
|
92
106
|
};
|
|
93
107
|
|
|
94
108
|
const makeProto = <
|
|
109
|
+
Runtime extends RuntimeAndFunctionType.Runtime,
|
|
95
110
|
Name_ extends string,
|
|
96
|
-
Functions_ extends FunctionSpec.
|
|
97
|
-
Groups_ extends
|
|
111
|
+
Functions_ extends FunctionSpec.AnyWithPropsWithRuntime<Runtime>,
|
|
112
|
+
Groups_ extends AnyWithPropsWithRuntime<Runtime>,
|
|
98
113
|
>({
|
|
114
|
+
runtime,
|
|
99
115
|
name,
|
|
100
116
|
functions,
|
|
101
117
|
groups,
|
|
102
118
|
}: {
|
|
119
|
+
runtime: Runtime;
|
|
103
120
|
name: Name_;
|
|
104
121
|
functions: Record.ReadonlyRecord<string, Functions_>;
|
|
105
122
|
groups: Record.ReadonlyRecord<string, Groups_>;
|
|
106
|
-
}): GroupSpec<Name_, Functions_, Groups_> =>
|
|
123
|
+
}): GroupSpec<Runtime, Name_, Functions_, Groups_> =>
|
|
107
124
|
Object.assign(Object.create(Proto), {
|
|
125
|
+
runtime,
|
|
108
126
|
name,
|
|
109
127
|
functions,
|
|
110
128
|
groups,
|
|
@@ -112,10 +130,24 @@ const makeProto = <
|
|
|
112
130
|
|
|
113
131
|
export const make = <const Name_ extends string>(
|
|
114
132
|
name: Name_,
|
|
115
|
-
): GroupSpec<Name_> => {
|
|
133
|
+
): GroupSpec<"Convex", Name_> => {
|
|
134
|
+
validateConfectFunctionIdentifier(name);
|
|
135
|
+
|
|
136
|
+
return makeProto({
|
|
137
|
+
runtime: "Convex",
|
|
138
|
+
name,
|
|
139
|
+
functions: Record.empty(),
|
|
140
|
+
groups: Record.empty(),
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
export const makeNode = <const Name_ extends string>(
|
|
145
|
+
name: Name_,
|
|
146
|
+
): GroupSpec<"Node", Name_> => {
|
|
116
147
|
validateConfectFunctionIdentifier(name);
|
|
117
148
|
|
|
118
149
|
return makeProto({
|
|
150
|
+
runtime: "Node",
|
|
119
151
|
name,
|
|
120
152
|
functions: Record.empty(),
|
|
121
153
|
groups: Record.empty(),
|