@confect/core 10.0.0-next.2 → 10.0.0-next.21

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 (94) hide show
  1. package/CHANGELOG.md +531 -0
  2. package/README.md +3 -1
  3. package/dist/FunctionProvenance.d.ts +155 -65
  4. package/dist/FunctionProvenance.d.ts.map +1 -1
  5. package/dist/FunctionProvenance.js +51 -10
  6. package/dist/FunctionProvenance.js.map +1 -1
  7. package/dist/FunctionSpec.d.ts +314 -138
  8. package/dist/FunctionSpec.d.ts.map +1 -1
  9. package/dist/FunctionSpec.js +50 -13
  10. package/dist/FunctionSpec.js.map +1 -1
  11. package/dist/GenericId.d.ts.map +1 -1
  12. package/dist/GenericId.js +1 -1
  13. package/dist/GroupPath.d.ts +1 -4
  14. package/dist/GroupPath.d.ts.map +1 -1
  15. package/dist/GroupPath.js.map +1 -1
  16. package/dist/GroupSpec.d.ts +16 -10
  17. package/dist/GroupSpec.d.ts.map +1 -1
  18. package/dist/GroupSpec.js +34 -11
  19. package/dist/GroupSpec.js.map +1 -1
  20. package/dist/Identifier.d.ts.map +1 -1
  21. package/dist/Lazy.d.ts +2 -3
  22. package/dist/Lazy.d.ts.map +1 -1
  23. package/dist/Lazy.js +2 -3
  24. package/dist/Lazy.js.map +1 -1
  25. package/dist/MiddlewareSpec.d.ts +184 -0
  26. package/dist/MiddlewareSpec.d.ts.map +1 -0
  27. package/dist/MiddlewareSpec.js +55 -0
  28. package/dist/MiddlewareSpec.js.map +1 -0
  29. package/dist/PaginationError.d.ts +14 -0
  30. package/dist/PaginationError.d.ts.map +1 -0
  31. package/dist/PaginationError.js +25 -0
  32. package/dist/PaginationError.js.map +1 -0
  33. package/dist/PaginationOptions.d.ts +23 -0
  34. package/dist/PaginationOptions.d.ts.map +1 -0
  35. package/dist/PaginationOptions.js +29 -0
  36. package/dist/PaginationOptions.js.map +1 -0
  37. package/dist/PaginationResult.d.ts +1 -0
  38. package/dist/PaginationResult.d.ts.map +1 -1
  39. package/dist/PaginationResult.js.map +1 -1
  40. package/dist/Ref.d.ts +120 -39
  41. package/dist/Ref.d.ts.map +1 -1
  42. package/dist/Ref.js +94 -38
  43. package/dist/Ref.js.map +1 -1
  44. package/dist/Refs.d.ts +9 -4
  45. package/dist/Refs.d.ts.map +1 -1
  46. package/dist/Refs.js +3 -3
  47. package/dist/Refs.js.map +1 -1
  48. package/dist/SchemaToValidator.d.ts +99 -0
  49. package/dist/SchemaToValidator.d.ts.map +1 -0
  50. package/dist/SchemaToValidator.js +156 -0
  51. package/dist/SchemaToValidator.js.map +1 -0
  52. package/dist/Spec.d.ts +3 -2
  53. package/dist/Spec.d.ts.map +1 -1
  54. package/dist/Spec.js +1 -1
  55. package/dist/Spec.js.map +1 -1
  56. package/dist/SystemFields.d.ts +1 -1
  57. package/dist/SystemFields.d.ts.map +1 -1
  58. package/dist/SystemFields.js +2 -2
  59. package/dist/SystemFields.js.map +1 -1
  60. package/dist/Table.d.ts +74 -0
  61. package/dist/Table.d.ts.map +1 -0
  62. package/dist/Table.js +77 -0
  63. package/dist/Table.js.map +1 -0
  64. package/dist/Types.d.ts +8 -2
  65. package/dist/Types.d.ts.map +1 -1
  66. package/dist/Types.js.map +1 -1
  67. package/dist/UserIdentity.d.ts.map +1 -1
  68. package/dist/index.d.ts +5 -1
  69. package/dist/index.d.ts.map +1 -1
  70. package/dist/index.js +7 -3
  71. package/package.json +15 -14
  72. package/src/FunctionProvenance.ts +186 -31
  73. package/src/FunctionSpec.ts +313 -85
  74. package/src/GroupPath.ts +1 -6
  75. package/src/GroupSpec.ts +125 -18
  76. package/src/Lazy.ts +2 -3
  77. package/src/MiddlewareSpec.ts +356 -0
  78. package/src/PaginationError.ts +72 -0
  79. package/src/PaginationOptions.ts +23 -0
  80. package/src/PaginationResult.ts +4 -0
  81. package/src/Ref.ts +429 -208
  82. package/src/Refs.ts +41 -16
  83. package/src/SchemaToValidator.ts +603 -0
  84. package/src/Spec.ts +4 -4
  85. package/src/SystemFields.ts +6 -9
  86. package/src/Table.ts +426 -0
  87. package/src/Types.ts +9 -3
  88. package/src/index.ts +5 -1
  89. package/dist/Registry.d.ts +0 -24
  90. package/dist/Registry.d.ts.map +0 -1
  91. package/dist/Registry.js +0 -19
  92. package/dist/Registry.js.map +0 -1
  93. package/dist/tsconfig.src.tsbuildinfo +0 -1
  94. package/src/Registry.ts +0 -30
@@ -0,0 +1,72 @@
1
+ import { ConvexError } from "convex/values";
2
+ import type { Value } from "convex/values";
3
+ import * as Match from "effect/Match";
4
+ import * as Option from "effect/Option";
5
+ import * as Schema from "effect/Schema";
6
+
7
+ /** A Convex pagination cursor that no longer describes the current query. */
8
+ export class InvalidCursor extends Schema.TaggedError<InvalidCursor>()(
9
+ "InvalidCursor",
10
+ {
11
+ cause: Schema.Defect(),
12
+ },
13
+ ) {}
14
+
15
+ interface InvalidCursorData {
16
+ readonly isConvexSystemError: true;
17
+ readonly paginationError: "InvalidCursor";
18
+ }
19
+
20
+ const ConvexErrorIdentifier = Symbol.for("ConvexError");
21
+
22
+ const isConvexError = (error: unknown): error is ConvexError<Value> =>
23
+ error instanceof ConvexError ||
24
+ (typeof error === "object" &&
25
+ error !== null &&
26
+ ConvexErrorIdentifier in error);
27
+
28
+ const isInvalidCursorData = (value: unknown): value is InvalidCursorData =>
29
+ typeof value === "object" &&
30
+ value !== null &&
31
+ "isConvexSystemError" in value &&
32
+ value.isConvexSystemError === true &&
33
+ "paginationError" in value &&
34
+ value.paginationError === "InvalidCursor";
35
+
36
+ const fromErrorMessage = (
37
+ error: globalThis.Error,
38
+ ): Option.Option<InvalidCursor> =>
39
+ error.message.includes("InvalidCursor")
40
+ ? Option.some(new InvalidCursor({ cause: error }))
41
+ : Option.none();
42
+
43
+ /** Recognizes an invalid-cursor error emitted by a Convex query. */
44
+ export const fromConvexQueryError = (
45
+ error: unknown,
46
+ ): Option.Option<InvalidCursor> =>
47
+ Match.value(error).pipe(
48
+ Match.when(isConvexError, (convexError) =>
49
+ Match.value(isInvalidCursorData(convexError.data)).pipe(
50
+ Match.when(true, () =>
51
+ Option.some(new InvalidCursor({ cause: error })),
52
+ ),
53
+ Match.when(false, () => fromErrorMessage(convexError)),
54
+ Match.exhaustive,
55
+ ),
56
+ ),
57
+ Match.when(Match.instanceOf(globalThis.Error), fromErrorMessage),
58
+ Match.when(Match.any, () => Option.none<InvalidCursor>()),
59
+ Match.exhaustive,
60
+ );
61
+
62
+ /** Recognizes the error data attached to Convex's invalid-cursor error. */
63
+ export const fromConvexErrorData = (
64
+ errorData: unknown,
65
+ ): Option.Option<InvalidCursor> =>
66
+ Match.value(errorData).pipe(
67
+ Match.when(isInvalidCursorData, (cause) =>
68
+ Option.some(new InvalidCursor({ cause })),
69
+ ),
70
+ Match.when(Match.any, () => Option.none<InvalidCursor>()),
71
+ Match.exhaustive,
72
+ );
@@ -0,0 +1,23 @@
1
+ import * as Schema from "effect/Schema";
2
+
3
+ /**
4
+ * Schema for the `paginationOpts` argument that every paginated query
5
+ * receives. Mirrors `paginationOptsValidator` from `convex/server`.
6
+ *
7
+ * Use this as the `paginationOpts` field of a paginated query's args schema.
8
+ * Beyond `numItems` and `cursor`, Convex's pagination protocol sends the
9
+ * optional fields (`endCursor`, `id`, `maximumRowsRead`, `maximumBytesRead`)
10
+ * with real requests — most notably `usePaginatedQuery` from `convex/react`
11
+ * always includes `id`, and includes `endCursor` when splitting pages.
12
+ * Declaring them is required for the generated Convex argument validator to
13
+ * accept those requests and for the fields to survive decoding and reach
14
+ * `paginate`.
15
+ */
16
+ export const PaginationOptions = Schema.Struct({
17
+ numItems: Schema.Finite,
18
+ cursor: Schema.Union([Schema.String, Schema.Null]),
19
+ endCursor: Schema.optionalKey(Schema.Union([Schema.String, Schema.Null])),
20
+ id: Schema.optionalKey(Schema.Finite),
21
+ maximumRowsRead: Schema.optionalKey(Schema.Finite),
22
+ maximumBytesRead: Schema.optionalKey(Schema.Finite),
23
+ });
@@ -1,5 +1,9 @@
1
1
  import * as Schema from "effect/Schema";
2
2
 
3
+ export type PaginationResult<Doc extends Schema.Codec<any, any>> = ReturnType<
4
+ typeof PaginationResult<Doc>
5
+ >;
6
+
3
7
  export const PaginationResult = <Doc extends Schema.Codec<any, any>>(
4
8
  Doc: Doc,
5
9
  ) =>