@confect/core 10.0.0-next.9 → 10.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 +958 -47
- package/README.md +3 -1
- package/dist/FunctionProvenance.d.ts +166 -68
- package/dist/FunctionProvenance.d.ts.map +1 -1
- package/dist/FunctionProvenance.js +55 -13
- package/dist/FunctionProvenance.js.map +1 -1
- package/dist/FunctionSpec.d.ts +320 -138
- package/dist/FunctionSpec.d.ts.map +1 -1
- package/dist/FunctionSpec.js +56 -13
- package/dist/FunctionSpec.js.map +1 -1
- package/dist/GenericId.d.ts.map +1 -1
- package/dist/GenericId.js +1 -1
- package/dist/GroupPath.d.ts +6 -10
- package/dist/GroupPath.d.ts.map +1 -1
- package/dist/GroupPath.js.map +1 -1
- package/dist/GroupSpec.d.ts +25 -12
- package/dist/GroupSpec.d.ts.map +1 -1
- package/dist/GroupSpec.js +51 -14
- 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 -14
- package/dist/Lazy.d.ts.map +1 -1
- package/dist/Lazy.js +11 -14
- 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 +198 -0
- package/dist/MiddlewareSpec.d.ts.map +1 -0
- package/dist/MiddlewareSpec.js +60 -0
- package/dist/MiddlewareSpec.js.map +1 -0
- package/dist/PaginationError.d.ts +20 -0
- package/dist/PaginationError.d.ts.map +1 -0
- package/dist/PaginationError.js +31 -0
- package/dist/PaginationError.js.map +1 -0
- package/dist/PaginationOptions.d.ts +23 -0
- package/dist/PaginationOptions.d.ts.map +1 -0
- package/dist/PaginationOptions.js +29 -0
- package/dist/PaginationOptions.js.map +1 -0
- package/dist/PaginationResult.d.ts +1 -0
- package/dist/PaginationResult.d.ts.map +1 -1
- package/dist/PaginationResult.js.map +1 -1
- package/dist/Ref.d.ts +135 -47
- package/dist/Ref.d.ts.map +1 -1
- package/dist/Ref.js +104 -46
- package/dist/Ref.js.map +1 -1
- package/dist/Refs.d.ts +10 -5
- package/dist/Refs.d.ts.map +1 -1
- package/dist/Refs.js +5 -4
- package/dist/Refs.js.map +1 -1
- package/dist/SchemaToValidator.d.ts +99 -0
- package/dist/SchemaToValidator.d.ts.map +1 -0
- package/dist/SchemaToValidator.js +158 -0
- package/dist/SchemaToValidator.js.map +1 -0
- package/dist/Spec.d.ts +16 -12
- package/dist/Spec.d.ts.map +1 -1
- package/dist/Spec.js +14 -9
- package/dist/Spec.js.map +1 -1
- package/dist/SystemFields.d.ts +16 -15
- package/dist/SystemFields.d.ts.map +1 -1
- package/dist/SystemFields.js +16 -15
- package/dist/SystemFields.js.map +1 -1
- package/dist/Table.d.ts +75 -0
- package/dist/Table.d.ts.map +1 -0
- package/dist/Table.js +77 -0
- package/dist/Table.js.map +1 -0
- package/dist/Types.d.ts +8 -2
- package/dist/Types.d.ts.map +1 -1
- package/dist/Types.js.map +1 -1
- package/dist/UserIdentity.d.ts.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -4
- package/package.json +17 -15
- package/src/FunctionProvenance.ts +197 -34
- package/src/FunctionSpec.ts +332 -86
- package/src/GroupPath.ts +6 -12
- package/src/GroupSpec.ts +184 -25
- package/src/Identifier.ts +6 -5
- package/src/Lazy.ts +11 -14
- package/src/MiddlewareAttachment.ts +106 -0
- package/src/MiddlewareSpec.ts +392 -0
- package/src/PaginationError.ts +78 -0
- package/src/PaginationOptions.ts +23 -0
- package/src/PaginationResult.ts +4 -0
- package/src/Ref.ts +468 -236
- package/src/Refs.ts +43 -18
- package/src/SchemaToValidator.ts +612 -0
- package/src/Spec.ts +50 -39
- package/src/SystemFields.ts +30 -31
- package/src/Table.ts +427 -0
- package/src/Types.ts +9 -3
- package/src/index.ts +6 -1
- package/dist/Registry.d.ts +0 -24
- package/dist/Registry.d.ts.map +0 -1
- package/dist/Registry.js +0 -19
- package/dist/Registry.js.map +0 -1
- package/dist/tsconfig.src.tsbuildinfo +0 -1
- package/src/Registry.ts +0 -30
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,22 +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
|
|
18
|
-
* `
|
|
19
|
-
* 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.
|
|
20
17
|
*/
|
|
21
18
|
export declare const defineProperty: <T extends object, K extends PropertyKey>(target: T, key: K, compute: () => unknown) => void;
|
|
22
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,23 +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
|
|
21
|
-
* `
|
|
22
|
-
* 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.
|
|
23
20
|
*/
|
|
24
21
|
const defineProperty = (target, key, compute) => {
|
|
25
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,iBAAiB,IAChC,eAAe,SAAS,cAAc,CAAC,iBAAiB,GACxD;IACE,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAC/B,QAAQ,CAAC,OAAO,EAAE,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAC3D,SAAS,GACT,cAAc,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;CAC7C,GACD,KAAK,CAAC;AAEV,MAAM,MAAM,IAAI,CAAC,eAAe,SAAS,cAAc,CAAC,iBAAiB,IAAI;IAC3E,eAAe,CAAC,UAAU,CAAC;CAC5B,SAAS,CAAC,KAAK,CAAC,GACb,EAAE,GACF,CAAC,OAAO,EAAE,cAAc,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC;AAEvD,MAAM,MAAM,eAAe,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gCACR,MAAM;;;;gCAdN,MAAM;2BACX,MAAM;kCACC,MAAM;;CAgB6B,CAAC;AAElE,eAAO,MAAM,qBAAqB;;4BAfN,MAAM;uBACX,MAAM;8BACC,MAAM;4BACR,MAAM;;;4BAGN,MAAM;uBACX,MAAM;8BACC,MAAM;4BACR,MAAM;;;4BAdN,MAAM;uBACX,MAAM;8BACC,MAAM;YA8BlC,CAAC;AAEH,eAAO,MAAM,WAAW,gBACT,aAAa,CAAC,oBAAoB,CAAC,YACtC,MAAM,KACf,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,eAAe,CA2CrC,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
+
import * as Data from "effect/Data";
|
|
3
|
+
import * as Schema from "effect/Schema";
|
|
4
|
+
import * as Result from "effect/Result";
|
|
5
|
+
//#region src/MiddlewareAttachment.ts
|
|
6
|
+
var MiddlewareAttachment_exports = /* @__PURE__ */ __exportAll({
|
|
7
|
+
ValidationError: () => ValidationError,
|
|
8
|
+
formatValidationError: () => formatValidationError,
|
|
9
|
+
validateAll: () => validateAll
|
|
10
|
+
});
|
|
11
|
+
const ValidationError = Data.taggedEnum();
|
|
12
|
+
const formatValidationError = ValidationError.$match({
|
|
13
|
+
InvalidOptions: ({ middlewareKey, location, attachmentIndex }) => `Middleware "${middlewareKey}" has invalid options at attachment ${attachmentIndex + 1} on ${location}`,
|
|
14
|
+
ConflictingSpecs: ({ middlewareKey, location }) => `Different middleware specs share key "${middlewareKey}" on ${location}`,
|
|
15
|
+
EquivalentOptions: ({ middlewareKey, location, attachmentIndex, previousIndex }) => `Middleware "${middlewareKey}" has equivalent options at attachments ${previousIndex + 1} and ${attachmentIndex + 1} on ${location}`
|
|
16
|
+
});
|
|
17
|
+
const validateAll = (attachments, location) => {
|
|
18
|
+
for (const [index, attachment] of attachments.entries()) {
|
|
19
|
+
const schema = attachment.spec.options;
|
|
20
|
+
if (schema !== void 0 && !Schema.is(schema)(attachment.options)) return Result.fail(ValidationError.InvalidOptions({
|
|
21
|
+
middlewareKey: attachment.spec.key,
|
|
22
|
+
location,
|
|
23
|
+
attachmentIndex: index
|
|
24
|
+
}));
|
|
25
|
+
const equivalent = schema === void 0 ? void 0 : Schema.toEquivalence(schema);
|
|
26
|
+
for (const [previousIndex, previous] of attachments.entries()) {
|
|
27
|
+
if (previousIndex === index) break;
|
|
28
|
+
if (previous.spec.key !== attachment.spec.key) continue;
|
|
29
|
+
if (previous.spec !== attachment.spec) return Result.fail(ValidationError.ConflictingSpecs({
|
|
30
|
+
middlewareKey: attachment.spec.key,
|
|
31
|
+
location,
|
|
32
|
+
attachmentIndex: index,
|
|
33
|
+
previousIndex
|
|
34
|
+
}));
|
|
35
|
+
if (equivalent === void 0 || equivalent(previous.options, attachment.options)) return Result.fail(ValidationError.EquivalentOptions({
|
|
36
|
+
middlewareKey: attachment.spec.key,
|
|
37
|
+
location,
|
|
38
|
+
attachmentIndex: index,
|
|
39
|
+
previousIndex
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return Result.void;
|
|
44
|
+
};
|
|
45
|
+
//#endregion
|
|
46
|
+
export { MiddlewareAttachment_exports, ValidationError, formatValidationError, validateAll };
|
|
47
|
+
|
|
48
|
+
//# sourceMappingURL=MiddlewareAttachment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MiddlewareAttachment.js","names":[],"sources":["../src/MiddlewareAttachment.ts"],"sourcesContent":["import * as Data from \"effect/Data\";\nimport * as Result from \"effect/Result\";\nimport * as Schema from \"effect/Schema\";\nimport type * as MiddlewareSpec from \"./MiddlewareSpec\";\n\nexport type MiddlewareAttachment<\n MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec =\n MiddlewareSpec.AnyMiddlewareSpec,\n> = MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec\n ? {\n readonly spec: MiddlewareSpec_;\n readonly options: [MiddlewareSpec_[\"~Options\"]] extends [never]\n ? undefined\n : MiddlewareSpec.Options<MiddlewareSpec_>;\n }\n : never;\n\nexport type Args<MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec> = [\n MiddlewareSpec_[\"~Options\"],\n] extends [never]\n ? []\n : [options: MiddlewareSpec.Options<MiddlewareSpec_>];\n\nexport type ValidationError = Data.TaggedEnum<{\n InvalidOptions: {\n readonly middlewareKey: string;\n readonly location: string;\n readonly attachmentIndex: number;\n };\n ConflictingSpecs: {\n readonly middlewareKey: string;\n readonly location: string;\n readonly attachmentIndex: number;\n readonly previousIndex: number;\n };\n EquivalentOptions: {\n readonly middlewareKey: string;\n readonly location: string;\n readonly attachmentIndex: number;\n readonly previousIndex: number;\n };\n}>;\n\nexport const ValidationError = Data.taggedEnum<ValidationError>();\n\nexport const formatValidationError = ValidationError.$match({\n InvalidOptions: ({ middlewareKey, location, attachmentIndex }) =>\n `Middleware \"${middlewareKey}\" has invalid options at attachment ${attachmentIndex + 1} on ${location}`,\n ConflictingSpecs: ({ middlewareKey, location }) =>\n `Different middleware specs share key \"${middlewareKey}\" on ${location}`,\n EquivalentOptions: ({\n middlewareKey,\n location,\n attachmentIndex,\n previousIndex,\n }) =>\n `Middleware \"${middlewareKey}\" has equivalent options at attachments ${previousIndex + 1} and ${attachmentIndex + 1} on ${location}`,\n});\n\nexport const validateAll = (\n attachments: ReadonlyArray<MiddlewareAttachment>,\n location: string,\n): Result.Result<void, ValidationError> => {\n for (const [index, attachment] of attachments.entries()) {\n const schema = attachment.spec.options;\n if (schema !== undefined && !Schema.is(schema)(attachment.options)) {\n return Result.fail(\n ValidationError.InvalidOptions({\n middlewareKey: attachment.spec.key,\n location,\n attachmentIndex: index,\n }),\n );\n }\n const equivalent =\n schema === undefined ? undefined : Schema.toEquivalence(schema);\n for (const [previousIndex, previous] of attachments.entries()) {\n if (previousIndex === index) break;\n if (previous.spec.key !== attachment.spec.key) continue;\n if (previous.spec !== attachment.spec) {\n return Result.fail(\n ValidationError.ConflictingSpecs({\n middlewareKey: attachment.spec.key,\n location,\n attachmentIndex: index,\n previousIndex,\n }),\n );\n }\n if (\n equivalent === undefined ||\n equivalent(previous.options, attachment.options)\n ) {\n return Result.fail(\n ValidationError.EquivalentOptions({\n middlewareKey: attachment.spec.key,\n location,\n attachmentIndex: index,\n previousIndex,\n }),\n );\n }\n }\n }\n return Result.void;\n};\n"],"mappings":";;;;;;;;;;AA2CA,MAAa,kBAAkB,KAAK,WAA4B;AAEhE,MAAa,wBAAwB,gBAAgB,OAAO;CAC1D,iBAAiB,EAAE,eAAe,UAAU,sBAC1C,eAAe,cAAc,sCAAsC,kBAAkB,EAAE,MAAM;CAC/F,mBAAmB,EAAE,eAAe,eAClC,yCAAyC,cAAc,OAAO;CAChE,oBAAoB,EAClB,eACA,UACA,iBACA,oBAEA,eAAe,cAAc,0CAA0C,gBAAgB,EAAE,OAAO,kBAAkB,EAAE,MAAM;AAC9H,CAAC;AAED,MAAa,eACX,aACA,aACyC;CACzC,KAAK,MAAM,CAAC,OAAO,eAAe,YAAY,QAAQ,GAAG;EACvD,MAAM,SAAS,WAAW,KAAK;EAC/B,IAAI,WAAW,KAAA,KAAa,CAAC,OAAO,GAAG,MAAM,CAAC,CAAC,WAAW,OAAO,GAC/D,OAAO,OAAO,KACZ,gBAAgB,eAAe;GAC7B,eAAe,WAAW,KAAK;GAC/B;GACA,iBAAiB;EACnB,CAAC,CACH;EAEF,MAAM,aACJ,WAAW,KAAA,IAAY,KAAA,IAAY,OAAO,cAAc,MAAM;EAChE,KAAK,MAAM,CAAC,eAAe,aAAa,YAAY,QAAQ,GAAG;GAC7D,IAAI,kBAAkB,OAAO;GAC7B,IAAI,SAAS,KAAK,QAAQ,WAAW,KAAK,KAAK;GAC/C,IAAI,SAAS,SAAS,WAAW,MAC/B,OAAO,OAAO,KACZ,gBAAgB,iBAAiB;IAC/B,eAAe,WAAW,KAAK;IAC/B;IACA,iBAAiB;IACjB;GACF,CAAC,CACH;GAEF,IACE,eAAe,KAAA,KACf,WAAW,SAAS,SAAS,WAAW,OAAO,GAE/C,OAAO,OAAO,KACZ,gBAAgB,kBAAkB;IAChC,eAAe,WAAW,KAAK;IAC/B;IACA,iBAAiB;IACjB;GACF,CAAC,CACH;EAEJ;CACF;CACA,OAAO,OAAO;AAChB"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import type { FunctionType, FunctionVisibility } from "convex/server";
|
|
2
|
+
import type * as Effect from "effect/Effect";
|
|
3
|
+
import type * as Schema from "effect/Schema";
|
|
4
|
+
import type { unhandled } from "effect/Types";
|
|
5
|
+
import type * as FunctionProvenance from "./FunctionProvenance";
|
|
6
|
+
import type * as FunctionSpec from "./FunctionSpec";
|
|
7
|
+
import type * as RuntimeAndFunctionType from "./RuntimeAndFunctionType";
|
|
8
|
+
export declare const TypeId = "~@confect/core/MiddlewareSpec";
|
|
9
|
+
export type TypeId = typeof TypeId;
|
|
10
|
+
export declare const isMiddlewareSpec: (u: unknown) => u is AnyMiddlewareSpec;
|
|
11
|
+
export declare const allFunctionTypes: ReadonlyArray<FunctionType>;
|
|
12
|
+
export interface SupportedFunctionTypes {
|
|
13
|
+
readonly query: boolean;
|
|
14
|
+
readonly mutation: boolean;
|
|
15
|
+
readonly action: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Marker success type used by middleware to represent the handler's outcome
|
|
19
|
+
* without exposing its concrete success value.
|
|
20
|
+
*
|
|
21
|
+
* Mirrors `RpcMiddleware.SuccessValue` in Effect.
|
|
22
|
+
*/
|
|
23
|
+
export interface SuccessValue {
|
|
24
|
+
readonly _: unique symbol;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The wrap-style middleware implementation shape: receives the downstream
|
|
28
|
+
* effect (the remaining middleware plus the function handler) and the covered
|
|
29
|
+
* invocation's metadata, and returns the effect that runs in its place.
|
|
30
|
+
*
|
|
31
|
+
* Mirrors `RpcMiddleware.RpcMiddleware` in Effect.
|
|
32
|
+
*/
|
|
33
|
+
export interface MiddlewareImpl<Provides_, E, R, Options_ = never> {
|
|
34
|
+
(effect: Effect.Effect<SuccessValue, E | unhandled, Provides_>, context: MiddlewareOptions<Options_>): Effect.Effect<SuccessValue, E | unhandled, R>;
|
|
35
|
+
}
|
|
36
|
+
export type MiddlewareOptions<Options_ = never> = {
|
|
37
|
+
readonly invocation: {
|
|
38
|
+
readonly name: string;
|
|
39
|
+
readonly functionType: FunctionType;
|
|
40
|
+
readonly functionVisibility: FunctionVisibility;
|
|
41
|
+
readonly args: unknown;
|
|
42
|
+
};
|
|
43
|
+
} & ([Options_] extends [never] ? unknown : {
|
|
44
|
+
readonly options: Options_;
|
|
45
|
+
});
|
|
46
|
+
export interface AnyMiddlewareImpl {
|
|
47
|
+
(effect: Effect.Effect<SuccessValue, any, any>, context: MiddlewareOptions | MiddlewareOptions<unknown>): Effect.Effect<SuccessValue, any, any>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The class shape produced by {@link MiddlewareSpec}. Only the static side is
|
|
51
|
+
* ever used—the class is a value-level carrier for the middleware's key, its
|
|
52
|
+
* declared functionTypes, and its (lazily-evaluated) error schema, plus the
|
|
53
|
+
* type-level `Provides`/`Error` metadata. It is deliberately not a
|
|
54
|
+
* `Context.Tag`: implementations are registered through the group `Registry`
|
|
55
|
+
* (like `FunctionImpl`s), not resolved from a Layer context.
|
|
56
|
+
*/
|
|
57
|
+
export interface MiddlewareSpec<in out Self, Key_ extends string, Provides_, Requires_, ErrorSchema_ extends Schema.Codec<any, any>, FunctionTypes_ extends FunctionType, OptionsSchema_ extends Schema.Schema<any> = never> {
|
|
58
|
+
new (_: never): {
|
|
59
|
+
readonly [TypeId]: TypeId;
|
|
60
|
+
readonly key: Key_;
|
|
61
|
+
};
|
|
62
|
+
readonly [TypeId]: TypeId;
|
|
63
|
+
readonly key: Key_;
|
|
64
|
+
readonly functionTypes: SupportedFunctionTypes;
|
|
65
|
+
readonly error?: ErrorSchema_;
|
|
66
|
+
readonly options?: OptionsSchema_;
|
|
67
|
+
readonly "~Provides": Provides_;
|
|
68
|
+
readonly "~Requires": Requires_;
|
|
69
|
+
readonly "~Error": ErrorSchema_;
|
|
70
|
+
readonly "~FunctionTypes": FunctionTypes_;
|
|
71
|
+
readonly "~Self": Self;
|
|
72
|
+
readonly "~Options": OptionsSchema_;
|
|
73
|
+
}
|
|
74
|
+
export interface AnyMiddlewareSpec {
|
|
75
|
+
readonly [TypeId]: TypeId;
|
|
76
|
+
readonly key: string;
|
|
77
|
+
readonly functionTypes: SupportedFunctionTypes;
|
|
78
|
+
readonly error?: Schema.Codec<any, any>;
|
|
79
|
+
readonly options?: Schema.Schema<any>;
|
|
80
|
+
readonly "~Provides": any;
|
|
81
|
+
readonly "~Requires": any;
|
|
82
|
+
readonly "~Error": any;
|
|
83
|
+
readonly "~FunctionTypes": FunctionType;
|
|
84
|
+
readonly "~Options": any;
|
|
85
|
+
}
|
|
86
|
+
export type Options<MiddlewareSpec_ extends AnyMiddlewareSpec> = MiddlewareSpec_["~Options"]["Type"];
|
|
87
|
+
export type WithoutOptions<MiddlewareSpec_ extends AnyMiddlewareSpec> = MiddlewareSpec_ extends AnyMiddlewareSpec ? [MiddlewareSpec_["~Options"]] extends [never] ? MiddlewareSpec_ : never : never;
|
|
88
|
+
export type Key<MiddlewareSpec_ extends AnyMiddlewareSpec> = MiddlewareSpec_["key"];
|
|
89
|
+
export type Provides<MiddlewareSpec_ extends AnyMiddlewareSpec> = MiddlewareSpec_ extends AnyMiddlewareSpec ? MiddlewareSpec_["~Provides"] : never;
|
|
90
|
+
/**
|
|
91
|
+
* The services a middleware's implementation may consume from middleware that
|
|
92
|
+
* runs earlier in the same chain (type-level only, like `provides`).
|
|
93
|
+
*/
|
|
94
|
+
export type Requires<MiddlewareSpec_ extends AnyMiddlewareSpec> = MiddlewareSpec_ extends AnyMiddlewareSpec ? MiddlewareSpec_["~Requires"] : never;
|
|
95
|
+
export type ErrorSchema<MiddlewareSpec_ extends AnyMiddlewareSpec> = MiddlewareSpec_ extends AnyMiddlewareSpec ? MiddlewareSpec_["~Error"] : never;
|
|
96
|
+
export type Error<MiddlewareSpec_ extends AnyMiddlewareSpec> = MiddlewareSpec_ extends AnyMiddlewareSpec ? MiddlewareSpec_["~Error"]["Type"] : never;
|
|
97
|
+
export type EncodedError<MiddlewareSpec_ extends AnyMiddlewareSpec> = MiddlewareSpec_ extends AnyMiddlewareSpec ? MiddlewareSpec_["~Error"]["Encoded"] : never;
|
|
98
|
+
export type FunctionTypes<MiddlewareSpec_ extends AnyMiddlewareSpec> = MiddlewareSpec_ extends AnyMiddlewareSpec ? MiddlewareSpec_["~FunctionTypes"] : never;
|
|
99
|
+
/**
|
|
100
|
+
* Declare a middleware's client-safe interface: its identifying key, the
|
|
101
|
+
* service it provides to downstream handlers, the error schema its failures
|
|
102
|
+
* encode through, and the function types it may attach to.
|
|
103
|
+
*
|
|
104
|
+
* ```ts
|
|
105
|
+
* class RequireUser extends MiddlewareSpec.MiddlewareSpec<
|
|
106
|
+
* RequireUser,
|
|
107
|
+
* {
|
|
108
|
+
* provides: CurrentUser;
|
|
109
|
+
* }
|
|
110
|
+
* >()("RequireUser", {
|
|
111
|
+
* error: () => NotSignedIn,
|
|
112
|
+
* functionTypes: { query: true, mutation: true, action: false },
|
|
113
|
+
* }) {}
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* The implementation is server-only and supplied separately via
|
|
117
|
+
* `MiddlewareImpl.make` (or `makeByFunctionType`/`provides`) in
|
|
118
|
+
* `@confect/server`.
|
|
119
|
+
*/
|
|
120
|
+
export declare const MiddlewareSpec: <Self, Config extends {
|
|
121
|
+
provides?: any;
|
|
122
|
+
requires?: any;
|
|
123
|
+
} = {}>() => <const Key_ extends string, const FunctionTypesConfig_ extends SupportedFunctionTypes, ErrorSchema_ extends Schema.Codec<any, any> = never, OptionsSchema_ extends Schema.Schema<any> = never>(key: Key_, options: {
|
|
124
|
+
readonly error?: () => ErrorSchema_;
|
|
125
|
+
readonly options?: () => OptionsSchema_;
|
|
126
|
+
readonly functionTypes: FunctionTypesConfig_ & ValidateFunctionTypesConfig<FunctionTypesConfig_>;
|
|
127
|
+
}) => MiddlewareSpec<Self, Key_, "provides" extends keyof Config ? Config["provides"] : never, "requires" extends keyof Config ? Config["requires"] : never, ErrorSchema_, FunctionTypesFromConfig<FunctionTypesConfig_>, OptionsSchema_>;
|
|
128
|
+
type FunctionTypesFromConfig<Config extends SupportedFunctionTypes> = {
|
|
129
|
+
[K in FunctionType]: Config[K] extends true ? K : never;
|
|
130
|
+
}[FunctionType];
|
|
131
|
+
type ValidateFunctionTypesConfig<Config extends SupportedFunctionTypes> = ValidationResult<{
|
|
132
|
+
[K in keyof Config]: boolean extends Config[K] ? AttachmentError<`Function type flag "${K & string}" must be a literal \`true\` or \`false\`, not a computed \`boolean\``> : never;
|
|
133
|
+
}[keyof Config] | ([FunctionTypesFromConfig<Config>] extends [never] ? AttachmentError<`A middleware must declare at least one function type`> : never)>;
|
|
134
|
+
export declare const errorSchemas: (middlewareSpecs: ReadonlyArray<AnyMiddlewareSpec>) => ReadonlyArray<Schema.Codec<any, any>>;
|
|
135
|
+
/**
|
|
136
|
+
* A branded, unconstructible type carrying a spec-authoring error message.
|
|
137
|
+
* Surfaced as (part of) a parameter type so the diagnostic names the exact
|
|
138
|
+
* problem at the `.middleware()`/`.addFunction()` call site.
|
|
139
|
+
*/
|
|
140
|
+
export interface AttachmentError<Message extends string> {
|
|
141
|
+
readonly "~@confect/core/MiddlewareSpec/AttachmentError": Message;
|
|
142
|
+
}
|
|
143
|
+
type FunctionTypeOf<FunctionSpec_ extends FunctionSpec.AnyWithProps> = FunctionSpec_["runtimeAndFunctionType"]["functionType"];
|
|
144
|
+
type ValidationResult<Errors> = [Errors] extends [never] ? unknown : Errors;
|
|
145
|
+
/**
|
|
146
|
+
* A matching-type Convex-provenance function is rejected rather than silently
|
|
147
|
+
* skipped: its raw handler passes through Confect untouched, so the middleware
|
|
148
|
+
* could not actually cover it, and skipping it would be a policy hole.
|
|
149
|
+
*/
|
|
150
|
+
export type ValidateFunction<FunctionSpec_ extends FunctionSpec.AnyWithProps, MiddlewareSpec_ extends AnyMiddlewareSpec> = FunctionSpec_ extends any ? MiddlewareSpec_ extends any ? FunctionSpec_ extends {
|
|
151
|
+
readonly functionProvenance: {
|
|
152
|
+
readonly _tag: "Convex";
|
|
153
|
+
};
|
|
154
|
+
} ? FunctionTypeOf<FunctionSpec_> extends FunctionTypes<MiddlewareSpec_> ? AttachmentError<`Convex-provenance function "${FunctionSpec_["name"]}" cannot be covered by middleware "${Key<MiddlewareSpec_>}"—attach middleware only to groups whose matching-type functions are all Confect-provenance`> : never : [
|
|
155
|
+
Extract<FunctionSpec.MiddlewareSpecs<FunctionSpec_>, {
|
|
156
|
+
readonly key: Key<WithoutOptions<MiddlewareSpec_>>;
|
|
157
|
+
}>
|
|
158
|
+
] extends [never] ? FunctionTypeOf<FunctionSpec_> extends FunctionTypes<MiddlewareSpec_> ? never : AttachmentError<`Middleware "${Key<MiddlewareSpec_>}" does not declare function type "${FunctionTypeOf<FunctionSpec_>}", the type of function "${FunctionSpec_["name"]}"`> : AttachmentError<`Middleware "${Key<MiddlewareSpec_>}" is already attached to function "${FunctionSpec_["name"]}"`> : never : never;
|
|
159
|
+
/**
|
|
160
|
+
* Attachment order is chain order, so requiring `requires` to be satisfied by
|
|
161
|
+
* already-attached middleware is exactly requiring the provider to run
|
|
162
|
+
* earlier.
|
|
163
|
+
*/
|
|
164
|
+
export type ValidateAttach<MiddlewareSpec_ extends AnyMiddlewareSpec, Functions_ extends FunctionSpec.AnyWithProps, MiddlewareSpecs_ extends AnyMiddlewareSpec> = [
|
|
165
|
+
Extract<MiddlewareSpecs_, {
|
|
166
|
+
readonly key: Key<WithoutOptions<MiddlewareSpec_>>;
|
|
167
|
+
}>
|
|
168
|
+
] extends [never] ? [Exclude<Requires<MiddlewareSpec_>, Provides<MiddlewareSpecs_>>] extends [
|
|
169
|
+
never
|
|
170
|
+
] ? ValidationResult<ValidateFunction<Functions_, MiddlewareSpec_>> : AttachmentError<`Middleware "${Key<MiddlewareSpec_>}" requires services that no middleware attached earlier to this group provides—attach the providing middleware first`> : AttachmentError<`Middleware "${Key<MiddlewareSpec_>}" is already attached to this group`>;
|
|
171
|
+
export type ValidateAddedFunction<FunctionSpec_ extends FunctionSpec.AnyWithProps, MiddlewareSpecs_ extends AnyMiddlewareSpec> = [MiddlewareSpecs_] extends [never] ? unknown : ValidationResult<ValidateFunction<FunctionSpec_, MiddlewareSpecs_> | GroupOverlap<FunctionSpec_, MiddlewareSpecs_>>;
|
|
172
|
+
type GroupOverlap<FunctionSpec_ extends FunctionSpec.AnyWithProps, MiddlewareSpecs_ extends AnyMiddlewareSpec> = FunctionSpec.MiddlewareSpecs<FunctionSpec_> extends infer FunctionMiddlewareSpec ? FunctionMiddlewareSpec extends AnyMiddlewareSpec ? [
|
|
173
|
+
Extract<MiddlewareSpecs_, {
|
|
174
|
+
readonly key: Key<WithoutOptions<FunctionMiddlewareSpec>>;
|
|
175
|
+
}>
|
|
176
|
+
] extends [never] ? never : AttachmentError<`Middleware "${Key<FunctionMiddlewareSpec>}" is attached to both function "${FunctionSpec_["name"]}" and its group`> : never : never;
|
|
177
|
+
/**
|
|
178
|
+
* The parameter-type validation applied to the group spec at `GroupImpl.make`:
|
|
179
|
+
* every function's attached middleware must have its `requires` services
|
|
180
|
+
* provided by some middleware covering that function (the group's or the
|
|
181
|
+
* function's own). Checked here—with the group fully assembled—rather than at
|
|
182
|
+
* the spec builders, because a function-level middleware's `requires` may
|
|
183
|
+
* legitimately be satisfied by a group middleware the function spec never sees,
|
|
184
|
+
* and group attachment is declaratively order-independent with respect to
|
|
185
|
+
* `addFunction`.
|
|
186
|
+
*/
|
|
187
|
+
export type ValidateImplRequires<Functions_ extends FunctionSpec.AnyWithProps, GroupMiddlewareSpecs_ extends AnyMiddlewareSpec> = ValidationResult<Functions_ extends any ? [
|
|
188
|
+
Exclude<Requires<FunctionSpec.MiddlewareSpecs<Functions_>>, Provides<GroupMiddlewareSpecs_ | FunctionSpec.MiddlewareSpecs<Functions_>>>
|
|
189
|
+
] extends [never] ? never : AttachmentError<`Function "${Functions_["name"]}" has middleware requiring services that no middleware covering it provides`> : never>;
|
|
190
|
+
export type ValidateFunctionAttach<MiddlewareSpec_ extends AnyMiddlewareSpec, RuntimeAndFunctionType_ extends RuntimeAndFunctionType.RuntimeAndFunctionType, FunctionProvenance_ extends FunctionProvenance.FunctionProvenance, MiddlewareSpecs_ extends AnyMiddlewareSpec> = FunctionProvenance_ extends {
|
|
191
|
+
readonly _tag: "Convex";
|
|
192
|
+
} ? AttachmentError<`Plain Convex functions cannot have middleware—their raw handlers are passed through untouched`> : [
|
|
193
|
+
Extract<MiddlewareSpecs_, {
|
|
194
|
+
readonly key: Key<WithoutOptions<MiddlewareSpec_>>;
|
|
195
|
+
}>
|
|
196
|
+
] extends [never] ? RuntimeAndFunctionType_["functionType"] extends FunctionTypes<MiddlewareSpec_> ? unknown : AttachmentError<`Middleware "${Key<MiddlewareSpec_>}" does not declare function type "${RuntimeAndFunctionType_["functionType"]}"`> : AttachmentError<`Middleware "${Key<MiddlewareSpec_>}" is already attached to this function`>;
|
|
197
|
+
export {};
|
|
198
|
+
//# sourceMappingURL=MiddlewareSpec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MiddlewareSpec.d.ts","sourceRoot":"","sources":["../src/MiddlewareSpec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAC;AAE7C,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,KAAK,kB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AqB,SAAS,iBAAiB,IAC7C,gBAAgB,CAClB,UAAU,SAAS,GAAG,GAClB;IACE,OAAO,CACL,QAAQ,CAAC,YAAY,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,EAClD,QAAQ,CACN,qBAAqB,GAAG,YAAY,CAAC,eAAe,CAAC,UAAU,CAAC,CACjE,CACF;CACF,SAAS,CAAC,KAAK,CAAC,GACf,KAAK,GACL,eAAe,CAAC,aAAa,UAAU,CAAC,MAAM,CAAC,6EAA6E,CAAC,GAC/H,KAAK,CACV,CAAC;AAEF,MAAM,MAAM,sBAAsB,CAChC,eAAe,SAAS,iBAAiB,EACzC,uBAAuB,SAAS,sBAAsB,CAAC,sBAAsB,EAC7E,mBAAmB,SAAS,kBAAkB,CAAC,kBAAkB,EACjE,gBAAgB,SAAS,iBAAiB,IACxC,mBAAmB,SAAS;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,GACvD,eAAe,CAAC,+FAA+F,CAAC,GAChH;IACI,OAAO,CACL,gBAAgB,EAChB;QAAE,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC,CAAA;KAAE,CACvD;CACF,SAAS,CAAC,KAAK,CAAC,GACjB,uBAAuB,CAAC,cAAc,CAAC,SAAS,aAAa,CAAC,eAAe,CAAC,GAC5E,OAAO,GACP,eAAe,CAAC,eAAe,GAAG,CAAC,eAAe,CAAC,qCAAqC,uBAAuB,CAAC,cAAc,CAAC,GAAG,CAAC,GACrI,eAAe,CAAC,eAAe,GAAG,CAAC,eAAe,CAAC,wCAAwC,CAAC,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { defineProperty } from "./Lazy.js";
|
|
3
|
+
import * as Predicate from "effect/Predicate";
|
|
4
|
+
//#region src/MiddlewareSpec.ts
|
|
5
|
+
var MiddlewareSpec_exports = /* @__PURE__ */ __exportAll({
|
|
6
|
+
MiddlewareSpec: () => MiddlewareSpec,
|
|
7
|
+
TypeId: () => TypeId,
|
|
8
|
+
allFunctionTypes: () => allFunctionTypes,
|
|
9
|
+
errorSchemas: () => errorSchemas,
|
|
10
|
+
isMiddlewareSpec: () => isMiddlewareSpec
|
|
11
|
+
});
|
|
12
|
+
const TypeId = "~@confect/core/MiddlewareSpec";
|
|
13
|
+
const isMiddlewareSpec = (u) => Predicate.hasProperty(u, TypeId);
|
|
14
|
+
const allFunctionTypes = [
|
|
15
|
+
"query",
|
|
16
|
+
"mutation",
|
|
17
|
+
"action"
|
|
18
|
+
];
|
|
19
|
+
/**
|
|
20
|
+
* Declare a middleware's client-safe interface: its identifying key, the
|
|
21
|
+
* service it provides to downstream handlers, the error schema its failures
|
|
22
|
+
* encode through, and the function types it may attach to.
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* class RequireUser extends MiddlewareSpec.MiddlewareSpec<
|
|
26
|
+
* RequireUser,
|
|
27
|
+
* {
|
|
28
|
+
* provides: CurrentUser;
|
|
29
|
+
* }
|
|
30
|
+
* >()("RequireUser", {
|
|
31
|
+
* error: () => NotSignedIn,
|
|
32
|
+
* functionTypes: { query: true, mutation: true, action: false },
|
|
33
|
+
* }) {}
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* The implementation is server-only and supplied separately via
|
|
37
|
+
* `MiddlewareImpl.make` (or `makeByFunctionType`/`provides`) in
|
|
38
|
+
* `@confect/server`.
|
|
39
|
+
*/
|
|
40
|
+
const MiddlewareSpec = () => (key, options) => {
|
|
41
|
+
const { query, mutation, action } = options.functionTypes;
|
|
42
|
+
if (!query && !mutation && !action) throw new Error(`Middleware "${key}" must declare at least one function type`);
|
|
43
|
+
function MiddlewareSpecClass() {}
|
|
44
|
+
const class_ = MiddlewareSpecClass;
|
|
45
|
+
class_[TypeId] = TypeId;
|
|
46
|
+
class_.key = key;
|
|
47
|
+
class_.functionTypes = {
|
|
48
|
+
query,
|
|
49
|
+
mutation,
|
|
50
|
+
action
|
|
51
|
+
};
|
|
52
|
+
if (options.error !== void 0) defineProperty(class_, "error", options.error);
|
|
53
|
+
if (options.options !== void 0) defineProperty(class_, "options", options.options);
|
|
54
|
+
return class_;
|
|
55
|
+
};
|
|
56
|
+
const errorSchemas = (middlewareSpecs) => middlewareSpecs.flatMap((middlewareSpec) => "error" in middlewareSpec && middlewareSpec.error !== void 0 ? [middlewareSpec.error] : []);
|
|
57
|
+
//#endregion
|
|
58
|
+
export { MiddlewareSpec, MiddlewareSpec_exports, TypeId, allFunctionTypes, errorSchemas, isMiddlewareSpec };
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=MiddlewareSpec.js.map
|