@gaganref/confect-core 10.3.1-fork.5 → 10.3.1-fork.50
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/dist/ActionCall.d.ts +18 -0
- package/dist/ActionCall.d.ts.map +1 -0
- package/dist/ActionCall.js +21 -0
- package/dist/ActionCall.js.map +1 -0
- package/dist/App.d.ts +13 -2
- package/dist/App.d.ts.map +1 -1
- package/dist/App.js +6 -3
- package/dist/App.js.map +1 -1
- package/dist/Auth.d.ts +31 -6
- package/dist/Auth.d.ts.map +1 -1
- package/dist/Auth.js +15 -1
- package/dist/Auth.js.map +1 -1
- package/dist/Callback.d.ts.map +1 -1
- package/dist/Callback.js +2 -2
- package/dist/Callback.js.map +1 -1
- package/dist/Component.d.ts.map +1 -1
- package/dist/Component.js +1 -1
- package/dist/Component.js.map +1 -1
- package/dist/FunctionSpec.d.ts +365 -2
- package/dist/FunctionSpec.d.ts.map +1 -1
- package/dist/FunctionSpec.js +66 -3
- package/dist/FunctionSpec.js.map +1 -1
- package/dist/GroupSpec.js +1 -1
- package/dist/Http.d.ts.map +1 -1
- package/dist/Http.js +2 -2
- package/dist/Http.js.map +1 -1
- package/dist/ManifestSection.d.ts +24 -0
- package/dist/ManifestSection.d.ts.map +1 -0
- package/dist/ManifestSection.js +7 -0
- package/dist/ManifestSection.js.map +1 -0
- package/dist/Profile.d.ts +95 -0
- package/dist/Profile.d.ts.map +1 -0
- package/dist/Profile.js +15 -0
- package/dist/Profile.js.map +1 -0
- package/dist/Ref.d.ts +4 -2
- package/dist/Ref.d.ts.map +1 -1
- package/dist/Ref.js +8 -4
- package/dist/Ref.js.map +1 -1
- package/dist/SchemaToValidator.d.ts +10 -1
- package/dist/SchemaToValidator.d.ts.map +1 -1
- package/dist/SchemaToValidator.js +19 -4
- package/dist/SchemaToValidator.js.map +1 -1
- package/dist/SystemFields.js +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -6
- package/dist/internal/scalarDocs.d.ts +5 -0
- package/dist/internal/scalarDocs.d.ts.map +1 -0
- package/dist/internal/scalarDocs.js +43 -0
- package/dist/internal/scalarDocs.js.map +1 -0
- package/package.json +3 -3
- package/src/ActionCall.ts +25 -0
- package/src/App.ts +19 -3
- package/src/Auth.ts +48 -6
- package/src/Callback.ts +1 -0
- package/src/Component.ts +2 -0
- package/src/FunctionSpec.ts +570 -5
- package/src/Http.ts +2 -5
- package/src/ManifestSection.ts +29 -0
- package/src/Profile.ts +141 -0
- package/src/Ref.ts +17 -4
- package/src/SchemaToValidator.ts +22 -1
- package/src/index.ts +3 -0
- package/src/internal/scalarDocs.ts +72 -0
package/src/FunctionSpec.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type * as ManifestSection from "./ManifestSection.js";
|
|
1
2
|
import type * as MiddlewareAttachment from "./MiddlewareAttachment.js";
|
|
2
3
|
import type {
|
|
3
4
|
DefaultFunctionArgs,
|
|
@@ -7,11 +8,12 @@ import type {
|
|
|
7
8
|
RegisteredMutation,
|
|
8
9
|
RegisteredQuery,
|
|
9
10
|
} from "convex/server";
|
|
10
|
-
import
|
|
11
|
+
import * as Schema from "effect/Schema";
|
|
11
12
|
import * as Predicate from "effect/Predicate";
|
|
12
13
|
import * as FunctionProvenance from "./FunctionProvenance.js";
|
|
13
14
|
import { validateConfectFunctionIdentifier } from "./Identifier.js";
|
|
14
|
-
import
|
|
15
|
+
import * as MiddlewareSpec from "./MiddlewareSpec.js";
|
|
16
|
+
import type * as Profile from "./Profile.js";
|
|
15
17
|
import * as RuntimeAndFunctionType from "./RuntimeAndFunctionType.js";
|
|
16
18
|
|
|
17
19
|
export const TypeId = "~@confect/core/FunctionSpec";
|
|
@@ -31,6 +33,8 @@ export interface FunctionSpec<
|
|
|
31
33
|
readonly runtimeAndFunctionType: RuntimeAndFunctionType_;
|
|
32
34
|
readonly functionVisibility: FunctionVisibility_;
|
|
33
35
|
readonly name: Name_;
|
|
36
|
+
readonly reservedArgument?: string;
|
|
37
|
+
readonly manifestSections?: ReadonlyArray<ManifestSection.Entry>;
|
|
34
38
|
readonly functionProvenance: FunctionProvenance_;
|
|
35
39
|
readonly middlewareSpecs: ReadonlyArray<MiddlewareSpecs_>;
|
|
36
40
|
readonly middlewareAttachments: ReadonlyArray<
|
|
@@ -69,6 +73,78 @@ export interface Builder<
|
|
|
69
73
|
>;
|
|
70
74
|
}
|
|
71
75
|
|
|
76
|
+
export interface DescribedBuilder<
|
|
77
|
+
RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,
|
|
78
|
+
FunctionVisibility_ extends FunctionVisibility,
|
|
79
|
+
Name_ extends string,
|
|
80
|
+
FunctionProvenance_ extends FunctionProvenance.FunctionProvenance,
|
|
81
|
+
MiddlewareSpecs_ extends MiddlewareSpec.AnyMiddlewareSpec = never,
|
|
82
|
+
> extends Builder<
|
|
83
|
+
RuntimeAndFunctionType_,
|
|
84
|
+
FunctionVisibility_,
|
|
85
|
+
Name_,
|
|
86
|
+
FunctionProvenance_,
|
|
87
|
+
MiddlewareSpecs_
|
|
88
|
+
> {
|
|
89
|
+
readonly description?: string;
|
|
90
|
+
|
|
91
|
+
middleware<MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec>(
|
|
92
|
+
middlewareSpec: MiddlewareSpec_ &
|
|
93
|
+
MiddlewareSpec.ValidateFunctionAttach<
|
|
94
|
+
MiddlewareSpec_,
|
|
95
|
+
RuntimeAndFunctionType_,
|
|
96
|
+
FunctionProvenance_,
|
|
97
|
+
MiddlewareSpecs_
|
|
98
|
+
>,
|
|
99
|
+
...options: MiddlewareAttachment.Args<NoInfer<MiddlewareSpec_>>
|
|
100
|
+
): DescribedBuilder<
|
|
101
|
+
RuntimeAndFunctionType_,
|
|
102
|
+
FunctionVisibility_,
|
|
103
|
+
Name_,
|
|
104
|
+
FunctionProvenance_,
|
|
105
|
+
MiddlewareSpecs_ | MiddlewareSpec_
|
|
106
|
+
>;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* A spec built through {@link extend}, keeping its fields through middleware.
|
|
111
|
+
*/
|
|
112
|
+
export interface ExtendedBuilder<
|
|
113
|
+
RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,
|
|
114
|
+
FunctionVisibility_ extends FunctionVisibility,
|
|
115
|
+
Name_ extends string,
|
|
116
|
+
FunctionProvenance_ extends FunctionProvenance.FunctionProvenance,
|
|
117
|
+
MiddlewareSpecs_ extends MiddlewareSpec.AnyMiddlewareSpec,
|
|
118
|
+
Fields_,
|
|
119
|
+
> extends Builder<
|
|
120
|
+
RuntimeAndFunctionType_,
|
|
121
|
+
FunctionVisibility_,
|
|
122
|
+
Name_,
|
|
123
|
+
FunctionProvenance_,
|
|
124
|
+
MiddlewareSpecs_
|
|
125
|
+
> {
|
|
126
|
+
readonly description?: string;
|
|
127
|
+
readonly fields: Profile.Info<Fields_>["fields"];
|
|
128
|
+
|
|
129
|
+
middleware<MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec>(
|
|
130
|
+
middlewareSpec: MiddlewareSpec_ &
|
|
131
|
+
MiddlewareSpec.ValidateFunctionAttach<
|
|
132
|
+
MiddlewareSpec_,
|
|
133
|
+
RuntimeAndFunctionType_,
|
|
134
|
+
FunctionProvenance_,
|
|
135
|
+
MiddlewareSpecs_
|
|
136
|
+
>,
|
|
137
|
+
...options: MiddlewareAttachment.Args<NoInfer<MiddlewareSpec_>>
|
|
138
|
+
): ExtendedBuilder<
|
|
139
|
+
RuntimeAndFunctionType_,
|
|
140
|
+
FunctionVisibility_,
|
|
141
|
+
Name_,
|
|
142
|
+
FunctionProvenance_,
|
|
143
|
+
MiddlewareSpecs_ | MiddlewareSpec_,
|
|
144
|
+
Fields_
|
|
145
|
+
>;
|
|
146
|
+
}
|
|
147
|
+
|
|
72
148
|
export interface Any {
|
|
73
149
|
readonly [TypeId]: TypeId;
|
|
74
150
|
}
|
|
@@ -79,7 +155,10 @@ export interface AnyWithProps extends FunctionSpec<
|
|
|
79
155
|
string,
|
|
80
156
|
FunctionProvenance.FunctionProvenance,
|
|
81
157
|
MiddlewareSpec.AnyMiddlewareSpec
|
|
82
|
-
> {
|
|
158
|
+
> {
|
|
159
|
+
readonly description?: string;
|
|
160
|
+
readonly fields?: object;
|
|
161
|
+
}
|
|
83
162
|
|
|
84
163
|
export interface AnyConfect extends FunctionSpec<
|
|
85
164
|
RuntimeAndFunctionType.RuntimeAndFunctionType,
|
|
@@ -326,6 +405,14 @@ const Proto = {
|
|
|
326
405
|
runtimeAndFunctionType: this.runtimeAndFunctionType,
|
|
327
406
|
functionVisibility: this.functionVisibility,
|
|
328
407
|
name: this.name,
|
|
408
|
+
...(this.manifestSections === undefined
|
|
409
|
+
? {}
|
|
410
|
+
: { manifestSections: this.manifestSections }),
|
|
411
|
+
...(this.reservedArgument === undefined
|
|
412
|
+
? {}
|
|
413
|
+
: { reservedArgument: this.reservedArgument }),
|
|
414
|
+
...("description" in this ? { description: this.description } : {}),
|
|
415
|
+
...("fields" in this ? { fields: this.fields } : {}),
|
|
329
416
|
functionProvenance: this.functionProvenance,
|
|
330
417
|
middlewareAttachments: [
|
|
331
418
|
...this.middlewareAttachments,
|
|
@@ -336,6 +423,8 @@ const Proto = {
|
|
|
336
423
|
} satisfies ThisType<AnyWithProps>;
|
|
337
424
|
|
|
338
425
|
interface Options {
|
|
426
|
+
readonly reservedArgument?: string;
|
|
427
|
+
readonly description?: string;
|
|
339
428
|
readonly name: string;
|
|
340
429
|
readonly args?: () => FunctionProvenance.ArgsFields;
|
|
341
430
|
readonly returns: () => Schema.Codec<any, any>;
|
|
@@ -355,7 +444,11 @@ const make = <
|
|
|
355
444
|
Returns_ extends Schema.Codec<any, any>,
|
|
356
445
|
Error_ extends Schema.Codec<any, any> = never,
|
|
357
446
|
>(options: {
|
|
447
|
+
reservedArgument?: RuntimeAndFunctionType_["functionType"] extends "query"
|
|
448
|
+
? never
|
|
449
|
+
: string;
|
|
358
450
|
name: Name_;
|
|
451
|
+
description?: never;
|
|
359
452
|
args: () => ArgsFields_;
|
|
360
453
|
returns: () => Returns_;
|
|
361
454
|
error?: () => Error_;
|
|
@@ -370,7 +463,11 @@ const make = <
|
|
|
370
463
|
Returns_ extends Schema.Codec<any, any>,
|
|
371
464
|
Error_ extends Schema.Codec<any, any> = never,
|
|
372
465
|
>(options: {
|
|
466
|
+
reservedArgument?: RuntimeAndFunctionType_["functionType"] extends "query"
|
|
467
|
+
? never
|
|
468
|
+
: string;
|
|
373
469
|
name: Name_;
|
|
470
|
+
description?: never;
|
|
374
471
|
args?: never;
|
|
375
472
|
returns: () => Returns_;
|
|
376
473
|
error?: () => Error_;
|
|
@@ -380,13 +477,64 @@ const make = <
|
|
|
380
477
|
Name_,
|
|
381
478
|
FunctionProvenance.Confect<{}, Returns_, Error_>
|
|
382
479
|
>;
|
|
383
|
-
function makeSpec
|
|
480
|
+
function makeSpec<
|
|
481
|
+
const Name_ extends string,
|
|
482
|
+
const ArgsFields_ extends FunctionProvenance.ArgsFields,
|
|
483
|
+
Returns_ extends Schema.Codec<any, any>,
|
|
484
|
+
Error_ extends Schema.Codec<any, any> = never,
|
|
485
|
+
>(options: {
|
|
486
|
+
reservedArgument?: RuntimeAndFunctionType_["functionType"] extends "query"
|
|
487
|
+
? never
|
|
488
|
+
: string;
|
|
489
|
+
name: Name_;
|
|
490
|
+
description?: FunctionVisibility_ extends "public" ? string : never;
|
|
491
|
+
args: () => ArgsFields_;
|
|
492
|
+
returns: () => Returns_;
|
|
493
|
+
error?: () => Error_;
|
|
494
|
+
}): DescribedBuilder<
|
|
495
|
+
RuntimeAndFunctionType_,
|
|
496
|
+
FunctionVisibility_,
|
|
497
|
+
Name_,
|
|
498
|
+
FunctionProvenance.Confect<ArgsFields_, Returns_, Error_>
|
|
499
|
+
>;
|
|
500
|
+
function makeSpec<
|
|
501
|
+
const Name_ extends string,
|
|
502
|
+
Returns_ extends Schema.Codec<any, any>,
|
|
503
|
+
Error_ extends Schema.Codec<any, any> = never,
|
|
504
|
+
>(options: {
|
|
505
|
+
reservedArgument?: RuntimeAndFunctionType_["functionType"] extends "query"
|
|
506
|
+
? never
|
|
507
|
+
: string;
|
|
508
|
+
name: Name_;
|
|
509
|
+
description?: FunctionVisibility_ extends "public" ? string : never;
|
|
510
|
+
args?: never;
|
|
511
|
+
returns: () => Returns_;
|
|
512
|
+
error?: () => Error_;
|
|
513
|
+
}): DescribedBuilder<
|
|
514
|
+
RuntimeAndFunctionType_,
|
|
515
|
+
FunctionVisibility_,
|
|
516
|
+
Name_,
|
|
517
|
+
FunctionProvenance.Confect<{}, Returns_, Error_>
|
|
518
|
+
>;
|
|
519
|
+
function makeSpec({
|
|
520
|
+
name,
|
|
521
|
+
description,
|
|
522
|
+
args,
|
|
523
|
+
returns,
|
|
524
|
+
error,
|
|
525
|
+
reservedArgument,
|
|
526
|
+
}: Options) {
|
|
384
527
|
validateConfectFunctionIdentifier(name);
|
|
385
528
|
|
|
386
529
|
return Object.assign(Object.create(Proto), {
|
|
387
530
|
runtimeAndFunctionType,
|
|
388
531
|
functionVisibility,
|
|
389
532
|
name,
|
|
533
|
+
...(runtimeAndFunctionType.functionType !== "query" &&
|
|
534
|
+
reservedArgument !== undefined
|
|
535
|
+
? { reservedArgument }
|
|
536
|
+
: {}),
|
|
537
|
+
...(description === undefined ? {} : { description }),
|
|
390
538
|
functionProvenance:
|
|
391
539
|
args === undefined
|
|
392
540
|
? FunctionProvenance.Confect(() => ({}), returns, error)
|
|
@@ -411,6 +559,7 @@ type ForbidPaginationOpts<
|
|
|
411
559
|
: unknown;
|
|
412
560
|
|
|
413
561
|
interface PaginatedOptions {
|
|
562
|
+
readonly description?: string;
|
|
414
563
|
readonly name: string;
|
|
415
564
|
readonly args?: () => FunctionProvenance.ArgsFields;
|
|
416
565
|
readonly item: () => Schema.Codec<any, any>;
|
|
@@ -431,6 +580,7 @@ const makePaginated = <
|
|
|
431
580
|
Error_ extends Schema.Codec<any, any> = never,
|
|
432
581
|
>(options: {
|
|
433
582
|
name: Name_;
|
|
583
|
+
description?: never;
|
|
434
584
|
args: () => UserArgsFields_ & ForbidPaginationOpts<UserArgsFields_>;
|
|
435
585
|
item: () => Item_;
|
|
436
586
|
error?: () => Error_;
|
|
@@ -446,6 +596,7 @@ const makePaginated = <
|
|
|
446
596
|
Error_ extends Schema.Codec<any, any> = never,
|
|
447
597
|
>(options: {
|
|
448
598
|
name: Name_;
|
|
599
|
+
description?: never;
|
|
449
600
|
args?: never;
|
|
450
601
|
item: () => Item_;
|
|
451
602
|
error?: () => Error_;
|
|
@@ -455,13 +606,53 @@ const makePaginated = <
|
|
|
455
606
|
Name_,
|
|
456
607
|
FunctionProvenance.ConfectPaginated<{}, Item_, Error_>
|
|
457
608
|
>;
|
|
458
|
-
function makeSpec
|
|
609
|
+
function makeSpec<
|
|
610
|
+
const Name_ extends string,
|
|
611
|
+
const UserArgsFields_ extends FunctionProvenance.ArgsFields,
|
|
612
|
+
Item_ extends Schema.Codec<any, any>,
|
|
613
|
+
Error_ extends Schema.Codec<any, any> = never,
|
|
614
|
+
>(options: {
|
|
615
|
+
name: Name_;
|
|
616
|
+
description?: FunctionVisibility_ extends "public" ? string : never;
|
|
617
|
+
args: () => UserArgsFields_ & ForbidPaginationOpts<UserArgsFields_>;
|
|
618
|
+
item: () => Item_;
|
|
619
|
+
error?: () => Error_;
|
|
620
|
+
}): DescribedBuilder<
|
|
621
|
+
RuntimeAndFunctionType_,
|
|
622
|
+
FunctionVisibility_,
|
|
623
|
+
Name_,
|
|
624
|
+
FunctionProvenance.ConfectPaginated<UserArgsFields_, Item_, Error_>
|
|
625
|
+
>;
|
|
626
|
+
function makeSpec<
|
|
627
|
+
const Name_ extends string,
|
|
628
|
+
Item_ extends Schema.Codec<any, any>,
|
|
629
|
+
Error_ extends Schema.Codec<any, any> = never,
|
|
630
|
+
>(options: {
|
|
631
|
+
name: Name_;
|
|
632
|
+
description?: FunctionVisibility_ extends "public" ? string : never;
|
|
633
|
+
args?: never;
|
|
634
|
+
item: () => Item_;
|
|
635
|
+
error?: () => Error_;
|
|
636
|
+
}): DescribedBuilder<
|
|
637
|
+
RuntimeAndFunctionType_,
|
|
638
|
+
FunctionVisibility_,
|
|
639
|
+
Name_,
|
|
640
|
+
FunctionProvenance.ConfectPaginated<{}, Item_, Error_>
|
|
641
|
+
>;
|
|
642
|
+
function makeSpec({
|
|
643
|
+
name,
|
|
644
|
+
description,
|
|
645
|
+
args,
|
|
646
|
+
item,
|
|
647
|
+
error,
|
|
648
|
+
}: PaginatedOptions) {
|
|
459
649
|
validateConfectFunctionIdentifier(name);
|
|
460
650
|
|
|
461
651
|
return Object.assign(Object.create(Proto), {
|
|
462
652
|
runtimeAndFunctionType,
|
|
463
653
|
functionVisibility,
|
|
464
654
|
name,
|
|
655
|
+
...(description === undefined ? {} : { description }),
|
|
465
656
|
functionProvenance:
|
|
466
657
|
args === undefined
|
|
467
658
|
? FunctionProvenance.ConfectPaginated(() => ({}), item, error)
|
|
@@ -509,6 +700,380 @@ export const internalNodeAction = make(
|
|
|
509
700
|
"internal",
|
|
510
701
|
);
|
|
511
702
|
|
|
703
|
+
type OptionlessMiddlewareSpec = MiddlewareSpec.AnyMiddlewareSpec & {
|
|
704
|
+
readonly "~Options": never;
|
|
705
|
+
};
|
|
706
|
+
|
|
707
|
+
type BuilderOption =
|
|
708
|
+
| "name"
|
|
709
|
+
| "description"
|
|
710
|
+
| "args"
|
|
711
|
+
| "returns"
|
|
712
|
+
| "item"
|
|
713
|
+
| "error";
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* Only a required description string may name a builder option. The builder
|
|
717
|
+
* reads it as that option. The conditional keeps the mapped type out of a
|
|
718
|
+
* builder call's inference, which would otherwise widen the function's name to
|
|
719
|
+
* `string` when reporting the error.
|
|
720
|
+
*/
|
|
721
|
+
type OptionFree<Type> = [keyof Type & BuilderOption] extends [never]
|
|
722
|
+
? unknown
|
|
723
|
+
: {
|
|
724
|
+
readonly [
|
|
725
|
+
Option in keyof Type & BuilderOption as Option extends "description"
|
|
726
|
+
? Type[Option] extends string
|
|
727
|
+
? string extends Type[Option]
|
|
728
|
+
? never
|
|
729
|
+
: Option
|
|
730
|
+
: Option
|
|
731
|
+
: Option
|
|
732
|
+
]: never;
|
|
733
|
+
};
|
|
734
|
+
|
|
735
|
+
/**
|
|
736
|
+
* A function's fields, checked once applied, since a profile's field type can
|
|
737
|
+
* branch on the function's name.
|
|
738
|
+
*/
|
|
739
|
+
type CheckedFields<Type> = Type & OptionFree<Type>;
|
|
740
|
+
|
|
741
|
+
type NotRepeated<
|
|
742
|
+
Middleware_,
|
|
743
|
+
Inherited extends MiddlewareSpec.AnyMiddlewareSpec,
|
|
744
|
+
> = Middleware_ extends {
|
|
745
|
+
readonly key: infer Key extends MiddlewareSpec.Key<Inherited>;
|
|
746
|
+
}
|
|
747
|
+
? MiddlewareSpec.AttachmentError<`Middleware "${Key}" is already attached by this profile`>
|
|
748
|
+
: Middleware_;
|
|
749
|
+
|
|
750
|
+
/**
|
|
751
|
+
* Refuses a middleware without options that an earlier layer attached, as it is
|
|
752
|
+
* attached at most once; one with options may repeat. Each member of an
|
|
753
|
+
* element's union is checked, so an array typed `(A | B)[]` is refused when
|
|
754
|
+
* either was attached.
|
|
755
|
+
*/
|
|
756
|
+
type NotInherited<
|
|
757
|
+
Middleware_ extends ReadonlyArray<unknown>,
|
|
758
|
+
Inherited extends MiddlewareSpec.AnyMiddlewareSpec,
|
|
759
|
+
> = {
|
|
760
|
+
readonly [Index in keyof Middleware_]: NotRepeated<
|
|
761
|
+
Middleware_[Index],
|
|
762
|
+
Inherited
|
|
763
|
+
>;
|
|
764
|
+
};
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* A profile's middleware: a spec without options, or an attachment.
|
|
768
|
+
*/
|
|
769
|
+
type ProfileMiddleware<FieldsType> =
|
|
770
|
+
| OptionlessMiddlewareSpec
|
|
771
|
+
| Profile.Attachment<MiddlewareSpec.AnyMiddlewareSpec, FieldsType>;
|
|
772
|
+
|
|
773
|
+
type SpecOf<Middleware_> =
|
|
774
|
+
Middleware_ extends Profile.Attachment<infer MiddlewareSpec_, any>
|
|
775
|
+
? MiddlewareSpec_
|
|
776
|
+
: Extract<Middleware_, MiddlewareSpec.AnyMiddlewareSpec>;
|
|
777
|
+
|
|
778
|
+
/**
|
|
779
|
+
* `never` when a profile middleware does not declare the function type.
|
|
780
|
+
*/
|
|
781
|
+
type Declared<
|
|
782
|
+
MiddlewareSpecs_ extends MiddlewareSpec.AnyMiddlewareSpec,
|
|
783
|
+
FunctionType_ extends FunctionType,
|
|
784
|
+
Make,
|
|
785
|
+
> = [
|
|
786
|
+
MiddlewareSpecs_ extends unknown
|
|
787
|
+
? FunctionType_ extends MiddlewareSpec.FunctionTypes<MiddlewareSpecs_>
|
|
788
|
+
? never
|
|
789
|
+
: MiddlewareSpecs_
|
|
790
|
+
: never,
|
|
791
|
+
] extends [never]
|
|
792
|
+
? Make
|
|
793
|
+
: never;
|
|
794
|
+
|
|
795
|
+
type Wrapped<
|
|
796
|
+
Layers extends ReadonlyArray<Profile.Transforms>,
|
|
797
|
+
Key extends keyof Profile.Transforms,
|
|
798
|
+
Input,
|
|
799
|
+
> = Layers extends readonly [
|
|
800
|
+
infer First extends Profile.Transforms,
|
|
801
|
+
...infer Rest extends ReadonlyArray<Profile.Transforms>,
|
|
802
|
+
]
|
|
803
|
+
? Wrapped<
|
|
804
|
+
Rest,
|
|
805
|
+
Key,
|
|
806
|
+
Key extends keyof First
|
|
807
|
+
? [Input] extends [never]
|
|
808
|
+
? Key extends "error"
|
|
809
|
+
? Profile.Transform<First[Key], typeof Schema.Never>
|
|
810
|
+
: never
|
|
811
|
+
: Profile.Transform<First[Key], Input>
|
|
812
|
+
: Input
|
|
813
|
+
>
|
|
814
|
+
: Input;
|
|
815
|
+
|
|
816
|
+
type UserArgs<A> = [A] extends [never] ? {} : A;
|
|
817
|
+
|
|
818
|
+
type ExtendedMake<
|
|
819
|
+
RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,
|
|
820
|
+
Fields_ extends Profile.Fields,
|
|
821
|
+
MiddlewareSpecs_ extends MiddlewareSpec.AnyMiddlewareSpec,
|
|
822
|
+
Layers extends ReadonlyArray<Profile.Transforms>,
|
|
823
|
+
> = Declared<
|
|
824
|
+
MiddlewareSpecs_,
|
|
825
|
+
RuntimeAndFunctionType_["functionType"],
|
|
826
|
+
<
|
|
827
|
+
const Name_ extends string,
|
|
828
|
+
const ArgsFields_ extends FunctionProvenance.ArgsFields = never,
|
|
829
|
+
Returns_ extends Schema.Codec<any, any> = never,
|
|
830
|
+
Error_ extends Schema.Codec<any, any> = never,
|
|
831
|
+
>(
|
|
832
|
+
options: {
|
|
833
|
+
readonly name: Name_;
|
|
834
|
+
readonly description?: string;
|
|
835
|
+
readonly args?: () => ArgsFields_;
|
|
836
|
+
readonly returns: () => Returns_;
|
|
837
|
+
readonly error?: () => Error_;
|
|
838
|
+
} & NoInfer<
|
|
839
|
+
CheckedFields<Profile.Apply<Fields_, Name_, UserArgs<ArgsFields_>>>
|
|
840
|
+
>,
|
|
841
|
+
) => ExtendedBuilder<
|
|
842
|
+
RuntimeAndFunctionType_,
|
|
843
|
+
"public",
|
|
844
|
+
Name_,
|
|
845
|
+
FunctionProvenance.Confect<
|
|
846
|
+
UserArgs<Wrapped<Layers, "args", ArgsFields_>>,
|
|
847
|
+
Wrapped<Layers, "returns", Returns_>,
|
|
848
|
+
Wrapped<Layers, "error", Error_>
|
|
849
|
+
>,
|
|
850
|
+
MiddlewareSpecs_,
|
|
851
|
+
Profile.Apply<Fields_, Name_, UserArgs<ArgsFields_>>
|
|
852
|
+
>
|
|
853
|
+
>;
|
|
854
|
+
|
|
855
|
+
type ExtendedMakePaginated<
|
|
856
|
+
Fields_ extends Profile.Fields,
|
|
857
|
+
MiddlewareSpecs_ extends MiddlewareSpec.AnyMiddlewareSpec,
|
|
858
|
+
Layers extends ReadonlyArray<Profile.Transforms>,
|
|
859
|
+
> = Declared<
|
|
860
|
+
MiddlewareSpecs_,
|
|
861
|
+
"query",
|
|
862
|
+
<
|
|
863
|
+
const Name_ extends string,
|
|
864
|
+
const UserArgsFields_ extends FunctionProvenance.ArgsFields = never,
|
|
865
|
+
Item_ extends Schema.Codec<any, any> = never,
|
|
866
|
+
Error_ extends Schema.Codec<any, any> = never,
|
|
867
|
+
>(
|
|
868
|
+
options: {
|
|
869
|
+
readonly name: Name_;
|
|
870
|
+
readonly description?: string;
|
|
871
|
+
readonly args?: () => UserArgsFields_ &
|
|
872
|
+
ForbidPaginationOpts<UserArgsFields_>;
|
|
873
|
+
readonly item: () => Item_;
|
|
874
|
+
readonly error?: () => Error_;
|
|
875
|
+
} & NoInfer<
|
|
876
|
+
CheckedFields<Profile.Apply<Fields_, Name_, UserArgs<UserArgsFields_>>>
|
|
877
|
+
>,
|
|
878
|
+
) => ExtendedBuilder<
|
|
879
|
+
RuntimeAndFunctionType.ConvexQuery,
|
|
880
|
+
"public",
|
|
881
|
+
Name_,
|
|
882
|
+
FunctionProvenance.ConfectPaginated<
|
|
883
|
+
UserArgs<Wrapped<Layers, "args", UserArgsFields_>>,
|
|
884
|
+
Wrapped<Layers, "item", Item_>,
|
|
885
|
+
Wrapped<Layers, "error", Error_>
|
|
886
|
+
>,
|
|
887
|
+
MiddlewareSpecs_,
|
|
888
|
+
Profile.Apply<Fields_, Name_, UserArgs<UserArgsFields_>>
|
|
889
|
+
>
|
|
890
|
+
>;
|
|
891
|
+
|
|
892
|
+
interface ExtendedRuntimes {
|
|
893
|
+
readonly publicQuery: RuntimeAndFunctionType.ConvexQuery;
|
|
894
|
+
readonly publicMutation: RuntimeAndFunctionType.ConvexMutation;
|
|
895
|
+
readonly publicAction: RuntimeAndFunctionType.ConvexAction;
|
|
896
|
+
readonly publicNodeAction: RuntimeAndFunctionType.NodeAction;
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
/**
|
|
900
|
+
* A profile's five public builders and its own `extend`.
|
|
901
|
+
*/
|
|
902
|
+
export type Extended<
|
|
903
|
+
Fields_ extends Profile.Fields,
|
|
904
|
+
MiddlewareSpecs_ extends MiddlewareSpec.AnyMiddlewareSpec,
|
|
905
|
+
Layers extends ReadonlyArray<Profile.Transforms> = [],
|
|
906
|
+
> = {
|
|
907
|
+
readonly [Builder_ in keyof ExtendedRuntimes]: ExtendedMake<
|
|
908
|
+
ExtendedRuntimes[Builder_],
|
|
909
|
+
Fields_,
|
|
910
|
+
MiddlewareSpecs_,
|
|
911
|
+
Layers
|
|
912
|
+
>;
|
|
913
|
+
} & {
|
|
914
|
+
readonly publicPaginatedQuery: ExtendedMakePaginated<
|
|
915
|
+
Fields_,
|
|
916
|
+
MiddlewareSpecs_,
|
|
917
|
+
Layers
|
|
918
|
+
>;
|
|
919
|
+
/**
|
|
920
|
+
* Require more fields and attach more middleware after this profile's.
|
|
921
|
+
*/
|
|
922
|
+
extend<
|
|
923
|
+
Extension extends Profile.Fields = Profile.NoFields,
|
|
924
|
+
Transforms extends Profile.Transforms = {},
|
|
925
|
+
>(): <
|
|
926
|
+
const Middleware_ extends ReadonlyArray<
|
|
927
|
+
ProfileMiddleware<
|
|
928
|
+
Profile.Apply<Profile.Both<Fields_, Extension>, string, any>
|
|
929
|
+
>
|
|
930
|
+
>,
|
|
931
|
+
>(
|
|
932
|
+
config: {
|
|
933
|
+
readonly manifest?: Readonly<
|
|
934
|
+
Record<string, ManifestSection.ManifestSection>
|
|
935
|
+
>;
|
|
936
|
+
readonly reservedArgument?: string;
|
|
937
|
+
readonly middleware: Middleware_ &
|
|
938
|
+
NotInherited<Middleware_, MiddlewareSpecs_>;
|
|
939
|
+
} & OptionFree<Extension["Type"]> &
|
|
940
|
+
Profile.SchemaConfig<
|
|
941
|
+
Transforms,
|
|
942
|
+
Profile.Apply<Profile.Both<Fields_, Extension>, string, any>
|
|
943
|
+
>,
|
|
944
|
+
) => Extended<
|
|
945
|
+
Profile.Both<Fields_, Extension>,
|
|
946
|
+
MiddlewareSpecs_ | SpecOf<Middleware_[number]>,
|
|
947
|
+
[...Layers, Transforms]
|
|
948
|
+
>;
|
|
949
|
+
};
|
|
950
|
+
|
|
951
|
+
type RuntimeWrappers = Partial<
|
|
952
|
+
Record<
|
|
953
|
+
keyof Profile.Transforms,
|
|
954
|
+
(thunk: () => any, info: Profile.Info<any>) => () => any
|
|
955
|
+
>
|
|
956
|
+
>;
|
|
957
|
+
|
|
958
|
+
const makeExtended = (
|
|
959
|
+
middleware: ReadonlyArray<ProfileMiddleware<any>>,
|
|
960
|
+
schemas: ReadonlyArray<RuntimeWrappers> = [],
|
|
961
|
+
reservedArgument?: string,
|
|
962
|
+
manifestSections: ReadonlyArray<ManifestSection.Entry> = [],
|
|
963
|
+
): Extended<any, any> => {
|
|
964
|
+
const extended =
|
|
965
|
+
(
|
|
966
|
+
makeSpec: (options: never) => object,
|
|
967
|
+
paginated = false,
|
|
968
|
+
reserves = false,
|
|
969
|
+
): any =>
|
|
970
|
+
({
|
|
971
|
+
name,
|
|
972
|
+
description,
|
|
973
|
+
args,
|
|
974
|
+
returns,
|
|
975
|
+
item,
|
|
976
|
+
error,
|
|
977
|
+
...fields
|
|
978
|
+
}: Record<string, unknown>) => {
|
|
979
|
+
const info = {
|
|
980
|
+
name,
|
|
981
|
+
...(description === undefined ? {} : { description }),
|
|
982
|
+
args: args ?? (() => ({})),
|
|
983
|
+
fields,
|
|
984
|
+
} as Profile.Info<unknown>;
|
|
985
|
+
const thunks = {
|
|
986
|
+
args,
|
|
987
|
+
returns: paginated ? undefined : returns,
|
|
988
|
+
item: paginated ? item : undefined,
|
|
989
|
+
error,
|
|
990
|
+
} as Partial<Record<keyof Profile.Transforms, () => any>>;
|
|
991
|
+
for (const wrappers of schemas) {
|
|
992
|
+
for (const key of ["args", "returns", "item", "error"] as const) {
|
|
993
|
+
const wrap = wrappers[key];
|
|
994
|
+
const thunk =
|
|
995
|
+
thunks[key] ?? (key === "error" ? () => Schema.Never : undefined);
|
|
996
|
+
if (wrap !== undefined && thunk !== undefined) {
|
|
997
|
+
thunks[key] = () => wrap(thunk, info)();
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
return middleware.reduce(
|
|
1002
|
+
(spec: any, entry) =>
|
|
1003
|
+
MiddlewareSpec.isMiddlewareSpec(entry)
|
|
1004
|
+
? spec.middleware(entry)
|
|
1005
|
+
: spec.middleware(entry.spec, entry.options(info)),
|
|
1006
|
+
Object.assign(makeSpec({ name, description, ...thunks } as never), {
|
|
1007
|
+
fields,
|
|
1008
|
+
manifestSections,
|
|
1009
|
+
...(reserves && reservedArgument !== undefined
|
|
1010
|
+
? { reservedArgument }
|
|
1011
|
+
: {}),
|
|
1012
|
+
}),
|
|
1013
|
+
);
|
|
1014
|
+
};
|
|
1015
|
+
|
|
1016
|
+
return {
|
|
1017
|
+
publicQuery: extended(publicQuery),
|
|
1018
|
+
publicMutation: extended(publicMutation, false, true),
|
|
1019
|
+
publicAction: extended(publicAction, false, true),
|
|
1020
|
+
publicNodeAction: extended(publicNodeAction, false, true),
|
|
1021
|
+
publicPaginatedQuery: extended(publicPaginatedQuery, true),
|
|
1022
|
+
extend:
|
|
1023
|
+
() =>
|
|
1024
|
+
(config: {
|
|
1025
|
+
middleware: ReadonlyArray<ProfileMiddleware<any>>;
|
|
1026
|
+
schemas?: RuntimeWrappers;
|
|
1027
|
+
reservedArgument?: string;
|
|
1028
|
+
manifest?: Readonly<Record<string, ManifestSection.ManifestSection>>;
|
|
1029
|
+
}) =>
|
|
1030
|
+
makeExtended(
|
|
1031
|
+
[...middleware, ...config.middleware],
|
|
1032
|
+
[...schemas, config.schemas ?? {}],
|
|
1033
|
+
config.reservedArgument ?? reservedArgument,
|
|
1034
|
+
[
|
|
1035
|
+
...manifestSections,
|
|
1036
|
+
...Object.entries(config.manifest ?? {}).map(([key, section]) => ({
|
|
1037
|
+
key,
|
|
1038
|
+
section,
|
|
1039
|
+
})),
|
|
1040
|
+
],
|
|
1041
|
+
),
|
|
1042
|
+
};
|
|
1043
|
+
};
|
|
1044
|
+
|
|
1045
|
+
/**
|
|
1046
|
+
* Public builders whose specs require and keep `Fields_`, with `middleware`.
|
|
1047
|
+
*/
|
|
1048
|
+
export const extend =
|
|
1049
|
+
<
|
|
1050
|
+
Fields_ extends Profile.Fields = Profile.NoFields,
|
|
1051
|
+
Transforms extends Profile.Transforms = {},
|
|
1052
|
+
>() =>
|
|
1053
|
+
<
|
|
1054
|
+
const Middleware_ extends ReadonlyArray<
|
|
1055
|
+
ProfileMiddleware<Profile.Apply<Fields_, string, any>>
|
|
1056
|
+
>,
|
|
1057
|
+
>(
|
|
1058
|
+
config: {
|
|
1059
|
+
readonly manifest?: Readonly<
|
|
1060
|
+
Record<string, ManifestSection.ManifestSection>
|
|
1061
|
+
>;
|
|
1062
|
+
readonly reservedArgument?: string;
|
|
1063
|
+
readonly middleware: Middleware_;
|
|
1064
|
+
} & OptionFree<Fields_["Type"]> &
|
|
1065
|
+
Profile.SchemaConfig<Transforms, Profile.Apply<Fields_, string, any>>,
|
|
1066
|
+
) =>
|
|
1067
|
+
makeExtended(
|
|
1068
|
+
config.middleware,
|
|
1069
|
+
[config.schemas ?? {}],
|
|
1070
|
+
config.reservedArgument,
|
|
1071
|
+
Object.entries(config.manifest ?? {}).map(([key, section]) => ({
|
|
1072
|
+
key,
|
|
1073
|
+
section,
|
|
1074
|
+
})),
|
|
1075
|
+
) as Extended<Fields_, SpecOf<Middleware_[number]>, [Transforms]>;
|
|
1076
|
+
|
|
512
1077
|
type MatchingRegisteredFunction<
|
|
513
1078
|
RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType,
|
|
514
1079
|
FunctionVisibility_ extends FunctionVisibility,
|
package/src/Http.ts
CHANGED
|
@@ -7,7 +7,7 @@ import * as SchemaAST from "effect/SchemaAST";
|
|
|
7
7
|
import type * as HttpApi from "effect/http-api/HttpApi";
|
|
8
8
|
import * as HttpApiBuilder from "effect/http-api/HttpApiBuilder";
|
|
9
9
|
import type * as HttpApiGroup from "effect/http-api/HttpApiGroup";
|
|
10
|
-
import
|
|
10
|
+
import { scalarDocs } from "./internal/scalarDocs.js";
|
|
11
11
|
import * as App from "./App.js";
|
|
12
12
|
|
|
13
13
|
const TypeId = "~@confect/core/Http";
|
|
@@ -57,10 +57,7 @@ export const make = <
|
|
|
57
57
|
const routes =
|
|
58
58
|
options.docs === undefined
|
|
59
59
|
? api
|
|
60
|
-
: Layer.merge(
|
|
61
|
-
api,
|
|
62
|
-
HttpApiScalar.layerCdn(options.api, { path: options.docs }),
|
|
63
|
-
);
|
|
60
|
+
: Layer.merge(api, scalarDocs(options.api, options.docs));
|
|
64
61
|
const http: Http<HttpApi.HttpApi<Id, Groups>, typeof routes> = {
|
|
65
62
|
[TypeId]: TypeId,
|
|
66
63
|
api: options.api,
|