@gaganref/confect-core 10.3.1-fork.3 → 10.3.1-fork.30

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.
Files changed (99) hide show
  1. package/dist/ActionCall.d.ts +18 -0
  2. package/dist/ActionCall.d.ts.map +1 -0
  3. package/dist/ActionCall.js +21 -0
  4. package/dist/ActionCall.js.map +1 -0
  5. package/dist/App.d.ts +14 -3
  6. package/dist/App.d.ts.map +1 -1
  7. package/dist/App.js +6 -3
  8. package/dist/App.js.map +1 -1
  9. package/dist/Auth.d.ts +2 -2
  10. package/dist/Auth.d.ts.map +1 -1
  11. package/dist/Auth.js.map +1 -1
  12. package/dist/Callback.d.ts +3 -3
  13. package/dist/Callback.d.ts.map +1 -1
  14. package/dist/Callback.js +2 -2
  15. package/dist/Callback.js.map +1 -1
  16. package/dist/Component.d.ts +8 -8
  17. package/dist/Component.d.ts.map +1 -1
  18. package/dist/Component.js +1 -1
  19. package/dist/Component.js.map +1 -1
  20. package/dist/FunctionProvenance.d.ts +2 -2
  21. package/dist/FunctionProvenance.d.ts.map +1 -1
  22. package/dist/FunctionProvenance.js.map +1 -1
  23. package/dist/FunctionSpec.d.ts +329 -5
  24. package/dist/FunctionSpec.d.ts.map +1 -1
  25. package/dist/FunctionSpec.js +53 -3
  26. package/dist/FunctionSpec.js.map +1 -1
  27. package/dist/GenericId.d.ts +2 -2
  28. package/dist/GenericId.d.ts.map +1 -1
  29. package/dist/GenericId.js.map +1 -1
  30. package/dist/GroupPath.d.ts +1 -1
  31. package/dist/GroupPath.d.ts.map +1 -1
  32. package/dist/GroupPath.js.map +1 -1
  33. package/dist/GroupSpec.d.ts +4 -4
  34. package/dist/GroupSpec.d.ts.map +1 -1
  35. package/dist/GroupSpec.js +1 -1
  36. package/dist/GroupSpec.js.map +1 -1
  37. package/dist/Http.d.ts +1 -1
  38. package/dist/Http.d.ts.map +1 -1
  39. package/dist/Http.js.map +1 -1
  40. package/dist/Manifest.d.ts +1 -1
  41. package/dist/Manifest.d.ts.map +1 -1
  42. package/dist/Manifest.js.map +1 -1
  43. package/dist/MiddlewareAttachment.d.ts +1 -1
  44. package/dist/MiddlewareAttachment.d.ts.map +1 -1
  45. package/dist/MiddlewareAttachment.js.map +1 -1
  46. package/dist/MiddlewareSpec.d.ts +3 -3
  47. package/dist/MiddlewareSpec.d.ts.map +1 -1
  48. package/dist/MiddlewareSpec.js.map +1 -1
  49. package/dist/Profile.d.ts +95 -0
  50. package/dist/Profile.d.ts.map +1 -0
  51. package/dist/Profile.js +15 -0
  52. package/dist/Profile.js.map +1 -0
  53. package/dist/Ref.d.ts +8 -7
  54. package/dist/Ref.d.ts.map +1 -1
  55. package/dist/Ref.js +7 -4
  56. package/dist/Ref.js.map +1 -1
  57. package/dist/Refs.d.ts +5 -5
  58. package/dist/Refs.d.ts.map +1 -1
  59. package/dist/Refs.js.map +1 -1
  60. package/dist/SchemaToValidator.d.ts +2 -2
  61. package/dist/SchemaToValidator.d.ts.map +1 -1
  62. package/dist/SchemaToValidator.js +1 -1
  63. package/dist/SchemaToValidator.js.map +1 -1
  64. package/dist/Spec.d.ts +1 -1
  65. package/dist/Spec.d.ts.map +1 -1
  66. package/dist/Spec.js.map +1 -1
  67. package/dist/SystemFields.d.ts +2 -2
  68. package/dist/SystemFields.d.ts.map +1 -1
  69. package/dist/SystemFields.js +1 -1
  70. package/dist/SystemFields.js.map +1 -1
  71. package/dist/Table.d.ts +3 -3
  72. package/dist/Table.d.ts.map +1 -1
  73. package/dist/Table.js.map +1 -1
  74. package/dist/index.d.ts +31 -29
  75. package/dist/index.d.ts.map +1 -1
  76. package/dist/index.js +8 -6
  77. package/package.json +1 -1
  78. package/src/ActionCall.ts +25 -0
  79. package/src/App.ts +20 -4
  80. package/src/Auth.ts +2 -2
  81. package/src/Callback.ts +4 -3
  82. package/src/Component.ts +12 -11
  83. package/src/FunctionProvenance.ts +3 -3
  84. package/src/FunctionSpec.ts +509 -9
  85. package/src/GenericId.ts +2 -2
  86. package/src/GroupPath.ts +1 -1
  87. package/src/GroupSpec.ts +5 -5
  88. package/src/Http.ts +1 -1
  89. package/src/Manifest.ts +1 -1
  90. package/src/MiddlewareAttachment.ts +1 -1
  91. package/src/MiddlewareSpec.ts +4 -4
  92. package/src/Profile.ts +141 -0
  93. package/src/Ref.ts +19 -10
  94. package/src/Refs.ts +5 -5
  95. package/src/SchemaToValidator.ts +3 -3
  96. package/src/Spec.ts +1 -1
  97. package/src/SystemFields.ts +2 -2
  98. package/src/Table.ts +4 -4
  99. package/src/index.ts +31 -29
package/src/Profile.ts ADDED
@@ -0,0 +1,141 @@
1
+ import type * as Schema from "effect/Schema";
2
+ import type * as FunctionProvenance from "./FunctionProvenance.js";
3
+ import type * as MiddlewareSpec from "./MiddlewareSpec.js";
4
+
5
+ /**
6
+ * A type-level function from a function's name and args fields to the fields a
7
+ * profile's builders require. Read `this["Name"]` and `this["Args"]` directly
8
+ * in `Type`, passing them to a type alias; a nested object type cannot name
9
+ * `this`.
10
+ */
11
+ export interface Fields {
12
+ readonly Name: string;
13
+ // `unknown`, not `ArgsFields`: an index signature here would leak into
14
+ // `keyof this["Args"]`.
15
+ readonly Args: unknown;
16
+ readonly Type: object;
17
+ }
18
+
19
+ export interface NoFields extends Fields {
20
+ readonly Type: {};
21
+ }
22
+
23
+ export type Apply<
24
+ Fields_ extends Fields,
25
+ Name_ extends string,
26
+ Args_,
27
+ > = (Fields_ & { readonly Name: Name_; readonly Args: Args_ })["Type"];
28
+
29
+ /**
30
+ * A base profile's fields and its extension's, for one function.
31
+ */
32
+ export interface Both<
33
+ Base extends Fields,
34
+ Extension extends Fields,
35
+ > extends Fields {
36
+ readonly Type: Apply<Base, this["Name"], this["Args"]> &
37
+ Apply<Extension, this["Name"], this["Args"]>;
38
+ }
39
+
40
+ /**
41
+ * What a profile callback sees. `args` stays a thunk.
42
+ */
43
+ export interface Info<FieldsType> {
44
+ readonly name: string;
45
+ readonly description?: string;
46
+ readonly args: () => FunctionProvenance.ArgsFields;
47
+ readonly fields: "description" extends keyof FieldsType
48
+ ? Omit<FieldsType, "description">
49
+ : FieldsType;
50
+ }
51
+
52
+ export interface Attachment<
53
+ MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec,
54
+ FieldsType,
55
+ > {
56
+ readonly spec: MiddlewareSpec_;
57
+ readonly options: (
58
+ info: Info<FieldsType>,
59
+ ) => MiddlewareSpec.Options<MiddlewareSpec_>;
60
+ }
61
+
62
+ /**
63
+ * A middleware without options has none to compute and is attached at most
64
+ * once, so it joins a profile's list directly.
65
+ */
66
+ type TakesOptions<MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec> = [
67
+ MiddlewareSpec.WithoutOptions<MiddlewareSpec_>,
68
+ ] extends [never]
69
+ ? unknown
70
+ : MiddlewareSpec.AttachmentError<`Middleware "${MiddlewareSpec.Key<MiddlewareSpec_>}" takes no options, so list it without Profile.attach`>;
71
+
72
+ /**
73
+ * Attach a middleware that takes options to every function a profile builds,
74
+ * with options computed from each function's fields.
75
+ */
76
+ export const attach = <
77
+ MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec,
78
+ FieldsType,
79
+ >(
80
+ spec: MiddlewareSpec_ & TakesOptions<MiddlewareSpec_>,
81
+ options: (
82
+ info: Info<FieldsType>,
83
+ ) => MiddlewareSpec.Options<NoInfer<MiddlewareSpec_>>,
84
+ ): Attachment<MiddlewareSpec_, FieldsType> => ({ spec, options });
85
+
86
+ /**
87
+ * A type function for a schema wrapper, applied to each declared codec.
88
+ */
89
+ export interface SchemaTransform {
90
+ readonly Input: Schema.Codec<unknown, unknown>;
91
+ readonly Type: Schema.Codec<any, any>;
92
+ }
93
+
94
+ /**
95
+ * Args wrappers transform the declared field map, before Struct composition.
96
+ */
97
+ export interface ArgsTransform {
98
+ readonly Input: unknown;
99
+ readonly Type: FunctionProvenance.ArgsFields;
100
+ }
101
+
102
+ export interface Transforms {
103
+ readonly args?: ArgsTransform;
104
+ readonly returns?: SchemaTransform;
105
+ readonly item?: SchemaTransform;
106
+ readonly error?: SchemaTransform;
107
+ }
108
+
109
+ export type Transform<T, Input> = (T & { readonly Input: Input })["Type" &
110
+ keyof T];
111
+
112
+ /**
113
+ * Error wrappers opt into Schema.Never when no error thunk was declared.
114
+ */
115
+ export type Wrappers<T extends Transforms, FieldsType> = {
116
+ readonly [K in keyof T]-?: K extends keyof Transforms
117
+ ? <
118
+ Input extends (K extends "args"
119
+ ? FunctionProvenance.ArgsFields
120
+ : Schema.Codec<any, any>),
121
+ >(
122
+ thunk: () => Input,
123
+ info: Info<FieldsType>,
124
+ ) => () => Transform<T[K], Input>
125
+ : never;
126
+ } & { readonly [K in Exclude<keyof Transforms, keyof T>]?: never };
127
+
128
+ type NonemptyError<T extends Transforms> = T extends {
129
+ readonly error: infer E extends SchemaTransform;
130
+ }
131
+ ? [Transform<E, typeof Schema.Never>["Type"]] extends [never]
132
+ ? MiddlewareSpec.AttachmentError<"Profile error wrapper must add an error to Schema.Never">
133
+ : unknown
134
+ : unknown;
135
+
136
+ export type SchemaConfig<T extends Transforms, FieldsType> = ([
137
+ keyof T,
138
+ ] extends [never]
139
+ ? { readonly schemas?: never }
140
+ : { readonly schemas: Wrappers<T, FieldsType> }) &
141
+ NonemptyError<T>;
package/src/Ref.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type * as MiddlewareAttachment from "./MiddlewareAttachment";
1
+ import type * as MiddlewareAttachment from "./MiddlewareAttachment.js";
2
2
  import type {
3
3
  DefaultFunctionArgs,
4
4
  FunctionReference as ConvexFunctionReference,
@@ -14,11 +14,11 @@ import * as Match from "effect/Match";
14
14
  import * as Option from "effect/Option";
15
15
  import * as Predicate from "effect/Predicate";
16
16
  import * as Schema from "effect/Schema";
17
- import type * as FunctionProvenance from "./FunctionProvenance";
18
- import type * as FunctionSpec from "./FunctionSpec";
19
- import * as Lazy from "./Lazy";
20
- import * as MiddlewareSpec from "./MiddlewareSpec";
21
- import type * as RuntimeAndFunctionType from "./RuntimeAndFunctionType";
17
+ import type * as FunctionProvenance from "./FunctionProvenance.js";
18
+ import type * as FunctionSpec from "./FunctionSpec.js";
19
+ import * as Lazy from "./Lazy.js";
20
+ import * as MiddlewareSpec from "./MiddlewareSpec.js";
21
+ import type * as RuntimeAndFunctionType from "./RuntimeAndFunctionType.js";
22
22
 
23
23
  export const TypeId = "~@confect/core/Ref";
24
24
  export type TypeId = typeof TypeId;
@@ -41,6 +41,7 @@ export interface Base<
41
41
  : (args: Args_) => void;
42
42
  readonly "~Returns": Returns_;
43
43
  readonly "~Error": Error_;
44
+ readonly functionType?: RuntimeAndFunctionType_["functionType"];
44
45
  readonly convexFunctionName: string;
45
46
  /**
46
47
  * Preserved for component references and function handles, which have no
@@ -447,14 +448,18 @@ export const make = <
447
448
  ({
448
449
  [TypeId]: TypeId,
449
450
  _tag: "Convex",
451
+ functionType: functionSpec.runtimeAndFunctionType.functionType,
450
452
  convexFunctionName,
451
453
  }) as Any,
452
454
  ),
453
455
  Match.tag("Confect", (provenance): Any =>
454
- fromProvenance(convexFunctionName, provenance, [
455
- ...groupMiddlewareAttachments,
456
- ...functionSpec.middlewareAttachments,
457
- ]),
456
+ fromProvenance(
457
+ convexFunctionName,
458
+ provenance,
459
+ [...groupMiddlewareAttachments, ...functionSpec.middlewareAttachments],
460
+ undefined,
461
+ functionSpec.runtimeAndFunctionType.functionType,
462
+ ),
458
463
  ),
459
464
  Match.exhaustive,
460
465
  ) as FromFunctionSpec<
@@ -476,10 +481,12 @@ export const fromProvenance = (
476
481
  provenance: FunctionProvenance.AnyConfect,
477
482
  middlewareAttachments: ReadonlyArray<MiddlewareAttachment.MiddlewareAttachment>,
478
483
  functionReference?: ConvexFunctionReference<any, any>,
484
+ functionType?: "query" | "mutation" | "action",
479
485
  ): AnyConfect => {
480
486
  const ref = {
481
487
  [TypeId]: TypeId as TypeId,
482
488
  _tag: "Confect" as const,
489
+ ...(functionType === undefined ? {} : { functionType }),
483
490
  convexFunctionName,
484
491
  ...(functionReference === undefined ? {} : { functionReference }),
485
492
  kind: provenance.kind,
@@ -532,6 +539,7 @@ export const fromFunctionReference = <
532
539
  Returns_,
533
540
  >(
534
541
  functionReference: ConvexFunctionReference<Type, Visibility, Args_, Returns_>,
542
+ functionType?: NoInfer<Type>,
535
543
  ): ConvexRef<
536
544
  Extract<
537
545
  RuntimeAndFunctionType.RuntimeAndFunctionType,
@@ -545,6 +553,7 @@ export const fromFunctionReference = <
545
553
  return {
546
554
  [TypeId]: TypeId,
547
555
  _tag: "Convex",
556
+ ...(functionType === undefined ? {} : { functionType }),
548
557
  convexFunctionName:
549
558
  address.name ??
550
559
  address.reference ??
package/src/Refs.ts CHANGED
@@ -2,11 +2,11 @@ import type { Types } from "effect";
2
2
  import { pipe } from "effect/Function";
3
3
  import * as Option from "effect/Option";
4
4
  import * as Record from "effect/Record";
5
- import type * as FunctionSpec from "./FunctionSpec";
6
- import type * as GroupSpec from "./GroupSpec";
7
- import type * as MiddlewareSpec from "./MiddlewareSpec";
8
- import * as Ref from "./Ref";
9
- import * as Spec from "./Spec";
5
+ import type * as FunctionSpec from "./FunctionSpec.js";
6
+ import type * as GroupSpec from "./GroupSpec.js";
7
+ import type * as MiddlewareSpec from "./MiddlewareSpec.js";
8
+ import * as Ref from "./Ref.js";
9
+ import * as Spec from "./Spec.js";
10
10
 
11
11
  export type Refs<
12
12
  Spec_ extends Spec.AnyWithProps,
@@ -1,4 +1,4 @@
1
- import * as IdScope from "./IdScope";
1
+ import * as IdScope from "./IdScope.js";
2
2
  import type {
3
3
  GenericId as ConvexGenericId,
4
4
  PropertyValidators,
@@ -30,7 +30,7 @@ import * as Schema from "effect/Schema";
30
30
  import * as SchemaAST from "effect/SchemaAST";
31
31
  import * as String from "effect/String";
32
32
 
33
- import * as GenericId from "./GenericId";
33
+ import * as GenericId from "./GenericId.js";
34
34
  import type {
35
35
  IsAny,
36
36
  IsOptional,
@@ -39,7 +39,7 @@ import type {
39
39
  IsUnion,
40
40
  TypeError,
41
41
  UnionToTuple,
42
- } from "./Types";
42
+ } from "./Types.js";
43
43
 
44
44
  // Args
45
45
 
package/src/Spec.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as Predicate from "effect/Predicate";
2
2
  import * as Record from "effect/Record";
3
- import * as GroupSpec from "./GroupSpec";
3
+ import * as GroupSpec from "./GroupSpec.js";
4
4
 
5
5
  export const TypeId = "~@confect/core/Spec";
6
6
  export type TypeId = typeof TypeId;
@@ -1,4 +1,4 @@
1
- import type * as IdScope from "./IdScope";
1
+ import type * as IdScope from "./IdScope.js";
2
2
  import type { SystemFields as NonIdSystemFields } from "convex/server";
3
3
  import { pipe } from "effect/Function";
4
4
  import * as Array from "effect/Array";
@@ -11,7 +11,7 @@ import * as SchemaAST from "effect/SchemaAST";
11
11
  import * as SchemaGetter from "effect/SchemaGetter";
12
12
  import * as SchemaTransformation from "effect/SchemaTransformation";
13
13
  import * as Struct from "effect/Struct";
14
- import * as GenericId from "./GenericId";
14
+ import * as GenericId from "./GenericId.js";
15
15
 
16
16
  /**
17
17
  * Produces a schema for Convex system fields. In Confect, system fields include
package/src/Table.ts CHANGED
@@ -1,7 +1,7 @@
1
- import * as IdScope from "./IdScope";
2
- import * as Lazy from "./Lazy";
3
- import * as SystemFields from "./SystemFields";
4
- import type { TableSchemaToTableValidator } from "./SchemaToValidator";
1
+ import * as IdScope from "./IdScope.js";
2
+ import * as Lazy from "./Lazy.js";
3
+ import * as SystemFields from "./SystemFields.js";
4
+ import type { TableSchemaToTableValidator } from "./SchemaToValidator.js";
5
5
  import type {
6
6
  SystemFields as ConvexSystemFields,
7
7
  Expand,
package/src/index.ts CHANGED
@@ -1,29 +1,31 @@
1
- export * as Callback from "./Callback";
2
- export * as FunctionProvenance from "./FunctionProvenance";
3
- export * as FunctionSpec from "./FunctionSpec";
4
- export * as GenericId from "./GenericId";
5
- export * as App from "./App";
6
- export * as Auth from "./Auth";
7
- export * as Component from "./Component";
8
- export * as Env from "./Env";
9
- export * as Http from "./Http";
10
- export * as IdScope from "./IdScope";
11
- export * as GroupPath from "./GroupPath";
12
- export * as GroupSpec from "./GroupSpec";
13
- export * as Identifier from "./Identifier";
14
- export * as Lazy from "./Lazy";
15
- export * as Manifest from "./Manifest";
16
- export * as MiddlewareAttachment from "./MiddlewareAttachment";
17
- export * as MiddlewareSpec from "./MiddlewareSpec";
18
- export * as PaginationError from "./PaginationError";
19
- export * as PaginationOptions from "./PaginationOptions";
20
- export * as PaginationResult from "./PaginationResult";
21
- export * as Ref from "./Ref";
22
- export * as Refs from "./Refs";
23
- export * as RuntimeAndFunctionType from "./RuntimeAndFunctionType";
24
- export * as SchemaToValidator from "./SchemaToValidator";
25
- export * as Spec from "./Spec";
26
- export * as SystemFields from "./SystemFields";
27
- export * as Table from "./Table";
28
- export * as Types from "./Types";
29
- export * as UserIdentity from "./UserIdentity";
1
+ export * as ActionCall from "./ActionCall.js";
2
+ export * as Callback from "./Callback.js";
3
+ export * as FunctionProvenance from "./FunctionProvenance.js";
4
+ export * as FunctionSpec from "./FunctionSpec.js";
5
+ export * as GenericId from "./GenericId.js";
6
+ export * as App from "./App.js";
7
+ export * as Auth from "./Auth.js";
8
+ export * as Component from "./Component.js";
9
+ export * as Env from "./Env.js";
10
+ export * as Http from "./Http.js";
11
+ export * as IdScope from "./IdScope.js";
12
+ export * as GroupPath from "./GroupPath.js";
13
+ export * as GroupSpec from "./GroupSpec.js";
14
+ export * as Identifier from "./Identifier.js";
15
+ export * as Lazy from "./Lazy.js";
16
+ export * as Manifest from "./Manifest.js";
17
+ export * as MiddlewareAttachment from "./MiddlewareAttachment.js";
18
+ export * as MiddlewareSpec from "./MiddlewareSpec.js";
19
+ export * as PaginationError from "./PaginationError.js";
20
+ export * as PaginationOptions from "./PaginationOptions.js";
21
+ export * as PaginationResult from "./PaginationResult.js";
22
+ export * as Profile from "./Profile.js";
23
+ export * as Ref from "./Ref.js";
24
+ export * as Refs from "./Refs.js";
25
+ export * as RuntimeAndFunctionType from "./RuntimeAndFunctionType.js";
26
+ export * as SchemaToValidator from "./SchemaToValidator.js";
27
+ export * as Spec from "./Spec.js";
28
+ export * as SystemFields from "./SystemFields.js";
29
+ export * as Table from "./Table.js";
30
+ export * as Types from "./Types.js";
31
+ export * as UserIdentity from "./UserIdentity.js";