@confect/server 7.0.0 → 8.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 +29 -0
- package/dist/DatabaseSchema.d.ts +5 -10
- package/dist/DatabaseSchema.d.ts.map +1 -1
- package/dist/DatabaseSchema.js +5 -6
- package/dist/DatabaseSchema.js.map +1 -1
- package/dist/Document.d.ts.map +1 -1
- package/dist/Document.js +35 -23
- package/dist/Document.js.map +1 -1
- package/dist/RegisteredConvexFunction.d.ts +2 -2
- package/dist/RegisteredConvexFunction.d.ts.map +1 -1
- package/dist/RegisteredConvexFunction.js +18 -7
- package/dist/RegisteredConvexFunction.js.map +1 -1
- package/dist/RegisteredFunction.d.ts +2 -2
- package/dist/RegisteredFunction.d.ts.map +1 -1
- package/dist/SchemaToValidator.d.ts +8 -8
- package/dist/StorageActionWriter.d.ts +1 -1
- package/package.json +21 -17
- package/src/DatabaseSchema.ts +7 -10
- package/src/Document.ts +90 -58
- package/src/RegisteredConvexFunction.ts +18 -17
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# @confect/server
|
|
2
2
|
|
|
3
|
+
## 8.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 87b7207: Renamed `DatabaseSchema.isSchema` to `DatabaseSchema.isDatabaseSchema` for consistency with the `is<TypeName>` predicate convention used elsewhere (e.g. `Spec.isSpec`). `TypeId` and `Any` are now defined in `@confect/core/DatabaseSchema` and re-exported from `@confect/server`; the underlying brand string is unchanged, so existing schema values continue to be recognized. Migration: replace `DatabaseSchema.isSchema(x)` with `DatabaseSchema.isDatabaseSchema(x)`.
|
|
8
|
+
|
|
9
|
+
Internally, this removes a cyclic workspace dependency between `@confect/cli` and `@confect/server` that triggered a pnpm install warning. `@confect/cli` no longer peer-depends on `@confect/server`.
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 4bb2722: Bump Effect ecosystem to latest. `@effect/platform` is now `^0.96.1` and `@effect/platform-node` is now `^0.106.0` in `@confect/server`'s peer dependencies; `effect` peer is now `^3.21.2` across packages. Consumers must upgrade `@effect/platform`, `@effect/platform-node`, and `effect` in lockstep when bumping `@confect/server`.
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- f308edd: Fix Convex query cache invalidation when handlers use `Effect.log`, `Effect.withSpan`, or other Effect features that read the clock through its `unsafe*` methods.
|
|
18
|
+
|
|
19
|
+
The `Clock` provided to confect-wrapped handlers previously implemented `unsafeCurrentTimeMillis`/`unsafeCurrentTimeNanos` by calling the real `Date.now`, so Effect internals (logging, span events, the default scheduler) would read real time during handler execution and invalidate Convex's per-query cache. Those unsafe methods now return constants (`0`/`0n`), making the only opt-in to cache invalidation the user-facing `Clock.currentTimeMillis`/`Clock.currentTimeNanos` effects, as originally intended.
|
|
20
|
+
|
|
21
|
+
- a02ef8a: Memoize `Document.decode` and `Document.encode` parsers in module-scoped `WeakMap` caches. Decoders are keyed by table schema and table name so shared schemas across tables get the correct `extendWithSystemFields` parser; encoders are keyed by schema only.
|
|
22
|
+
- 40c1cff: Switch sibling `@confect/*` peer-dependency specifiers from `workspace:*` to `workspace:^`. Published peer ranges are now caret-based (e.g. `^7.0.0`) instead of exact-pinned, so non-major upgrades of one `@confect/*` package no longer fall out of range for its peer dependents.
|
|
23
|
+
|
|
24
|
+
Paired with the Changesets `onlyUpdatePeerDependentsWhenOutOfRange` flag, this prevents the entire `@confect/*` family from being promoted to a major bump on every release when only minor/patch changes are present.
|
|
25
|
+
|
|
26
|
+
`@confect/cli` additionally moves `@effect/platform` from `peerDependencies` to `dependencies`, since the CLI consumes it as an internal implementation detail (for `FileSystem`/`Path`) rather than exposing it in its public API. Consumers no longer need to install `@effect/platform` themselves to use the CLI.
|
|
27
|
+
|
|
28
|
+
- Updated dependencies [4bb2722]
|
|
29
|
+
- Updated dependencies [40c1cff]
|
|
30
|
+
- @confect/core@8.0.0
|
|
31
|
+
|
|
3
32
|
## 7.0.0
|
|
4
33
|
|
|
5
34
|
### Minor Changes
|
package/dist/DatabaseSchema.d.ts
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
import { AnyWithProps as AnyWithProps$1, Name, SystemTables, Table, TablesRecord, WithName } from "./Table.js";
|
|
2
2
|
import { Expand, GenericSchema, SchemaDefinition } from "convex/server";
|
|
3
3
|
import * as convex_values0 from "convex/values";
|
|
4
|
+
import { Any, TypeId, TypeId as TypeId$1, isDatabaseSchema } from "@confect/core/DatabaseSchema";
|
|
4
5
|
import * as effect_Schema0 from "effect/Schema";
|
|
5
6
|
|
|
6
7
|
//#region src/DatabaseSchema.d.ts
|
|
7
8
|
declare namespace DatabaseSchema_d_exports {
|
|
8
|
-
export { Any, AnyWithProps, ConvexDatabaseSchemaFromTables, DatabaseSchema, ExtendWithSystemTables, IncludeSystemTables, TableNames, TableWithName, Tables, TypeId, extendWithSystemTables,
|
|
9
|
+
export { Any, AnyWithProps, ConvexDatabaseSchemaFromTables, DatabaseSchema, ExtendWithSystemTables, IncludeSystemTables, TableNames, TableWithName, Tables, TypeId, extendWithSystemTables, isDatabaseSchema, make, systemSchema };
|
|
9
10
|
}
|
|
10
|
-
declare const TypeId = "@confect/server/DatabaseSchema";
|
|
11
|
-
type TypeId = typeof TypeId;
|
|
12
|
-
declare const isSchema: (u: unknown) => u is Any;
|
|
13
11
|
/**
|
|
14
12
|
* A schema definition tracks the schema and its Convex schema definition.
|
|
15
13
|
*/
|
|
16
14
|
interface DatabaseSchema<Tables_ extends AnyWithProps$1 = never> {
|
|
17
|
-
readonly [TypeId]: TypeId;
|
|
15
|
+
readonly [TypeId$1]: TypeId$1;
|
|
18
16
|
readonly tables: TablesRecord<Tables_>;
|
|
19
17
|
readonly convexSchemaDefinition: SchemaDefinition<ConvexDatabaseSchemaFromTables<Tables_>, true>;
|
|
20
18
|
/**
|
|
@@ -22,11 +20,8 @@ interface DatabaseSchema<Tables_ extends AnyWithProps$1 = never> {
|
|
|
22
20
|
*/
|
|
23
21
|
addTable<TableDef extends AnyWithProps$1>(table: TableDef): DatabaseSchema<Tables_ | TableDef>;
|
|
24
22
|
}
|
|
25
|
-
interface Any {
|
|
26
|
-
readonly [TypeId]: TypeId;
|
|
27
|
-
}
|
|
28
23
|
interface AnyWithProps {
|
|
29
|
-
readonly [TypeId]: TypeId;
|
|
24
|
+
readonly [TypeId$1]: TypeId$1;
|
|
30
25
|
readonly tables: Record<string, AnyWithProps$1>;
|
|
31
26
|
readonly convexSchemaDefinition: SchemaDefinition<GenericSchema, true>;
|
|
32
27
|
addTable<TableDef extends AnyWithProps$1>(table: TableDef): AnyWithProps;
|
|
@@ -135,5 +130,5 @@ declare const extendWithSystemTables: <Tables_ extends AnyWithProps$1>(tables: T
|
|
|
135
130
|
type ExtendWithSystemTables<Tables_ extends AnyWithProps$1> = TablesRecord<Tables_ | SystemTables>;
|
|
136
131
|
type IncludeSystemTables<Tables_ extends AnyWithProps$1> = Tables_ | SystemTables extends infer T ? T extends AnyWithProps$1 ? T : never : never;
|
|
137
132
|
//#endregion
|
|
138
|
-
export { Any, AnyWithProps, ConvexDatabaseSchemaFromTables, DatabaseSchema, DatabaseSchema_d_exports, ExtendWithSystemTables, IncludeSystemTables, TableNames, TableWithName, Tables, TypeId, extendWithSystemTables,
|
|
133
|
+
export { type Any, AnyWithProps, ConvexDatabaseSchemaFromTables, DatabaseSchema, DatabaseSchema_d_exports, ExtendWithSystemTables, IncludeSystemTables, TableNames, TableWithName, Tables, TypeId, extendWithSystemTables, isDatabaseSchema, make, systemSchema };
|
|
139
134
|
//# sourceMappingURL=DatabaseSchema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatabaseSchema.d.ts","names":[],"sources":["../src/DatabaseSchema.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"DatabaseSchema.d.ts","names":[],"sources":["../src/DatabaseSch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OAAA;AAAA,KAMd,sBAAA,iBAAuC,cAAA,IACjD,YAAA,CAAmB,OAAA,GAAU,YAAA;AAAA,KAEnB,mBAAA,iBAAoC,cAAA,IAC5C,OAAA,GACA,YAAA,mBACA,CAAA,SAAU,cAAA,GACR,CAAA"}
|
package/dist/DatabaseSchema.js
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { scheduledFunctionsTable, storageTable, systemTables } from "./Table.js";
|
|
3
|
-
import { Array,
|
|
3
|
+
import { Array, Record, pipe } from "effect";
|
|
4
4
|
import { defineSchema } from "convex/server";
|
|
5
|
+
import { TypeId, TypeId as TypeId$1, isDatabaseSchema } from "@confect/core/DatabaseSchema";
|
|
5
6
|
|
|
6
7
|
//#region src/DatabaseSchema.ts
|
|
7
8
|
var DatabaseSchema_exports = /* @__PURE__ */ __exportAll({
|
|
8
9
|
TypeId: () => TypeId,
|
|
9
10
|
extendWithSystemTables: () => extendWithSystemTables,
|
|
10
|
-
|
|
11
|
+
isDatabaseSchema: () => isDatabaseSchema,
|
|
11
12
|
make: () => make,
|
|
12
13
|
systemSchema: () => systemSchema
|
|
13
14
|
});
|
|
14
|
-
const TypeId = "@confect/server/DatabaseSchema";
|
|
15
|
-
const isSchema = (u) => Predicate.hasProperty(u, TypeId);
|
|
16
15
|
const Proto = {
|
|
17
|
-
[TypeId]: TypeId,
|
|
16
|
+
[TypeId$1]: TypeId$1,
|
|
18
17
|
addTable(table) {
|
|
19
18
|
const newTablesArray = [...Object.values(this.tables), table];
|
|
20
19
|
return makeProto({
|
|
@@ -41,5 +40,5 @@ const extendWithSystemTables = (tables) => ({
|
|
|
41
40
|
});
|
|
42
41
|
|
|
43
42
|
//#endregion
|
|
44
|
-
export { DatabaseSchema_exports, TypeId, extendWithSystemTables,
|
|
43
|
+
export { DatabaseSchema_exports, TypeId, extendWithSystemTables, isDatabaseSchema, make, systemSchema };
|
|
45
44
|
//# sourceMappingURL=DatabaseSchema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatabaseSchema.js","names":["defineConvexSchema","Table.scheduledFunctionsTable","Table.storageTable","Table.systemTables"],"sources":["../src/DatabaseSchema.ts"],"sourcesContent":["import type { Expand, GenericSchema } from \"convex/server\";\nimport {\n defineSchema as defineConvexSchema,\n type SchemaDefinition,\n} from \"convex/server\";\nimport { Array, pipe,
|
|
1
|
+
{"version":3,"file":"DatabaseSchema.js","names":["TypeId","defineConvexSchema","Table.scheduledFunctionsTable","Table.storageTable","Table.systemTables"],"sources":["../src/DatabaseSchema.ts"],"sourcesContent":["import type { Expand, GenericSchema } from \"convex/server\";\nimport {\n defineSchema as defineConvexSchema,\n type SchemaDefinition,\n} from \"convex/server\";\nimport { Array, pipe, Record } from \"effect\";\nimport * as Table from \"./Table\";\nimport { TypeId } from \"@confect/core/DatabaseSchema\";\n\nexport {\n type Any,\n isDatabaseSchema,\n TypeId,\n} from \"@confect/core/DatabaseSchema\";\n\n/**\n * A schema definition tracks the schema and its Convex schema definition.\n */\nexport interface DatabaseSchema<Tables_ extends Table.AnyWithProps = never> {\n readonly [TypeId]: TypeId;\n readonly tables: Table.TablesRecord<Tables_>;\n readonly convexSchemaDefinition: SchemaDefinition<\n ConvexDatabaseSchemaFromTables<Tables_>,\n true\n >;\n\n /**\n * Add a table definition to the schema.\n */\n addTable<TableDef extends Table.AnyWithProps>(\n table: TableDef,\n ): DatabaseSchema<Tables_ | TableDef>;\n}\n\nexport interface AnyWithProps {\n readonly [TypeId]: TypeId;\n readonly tables: Record<string, Table.AnyWithProps>;\n readonly convexSchemaDefinition: SchemaDefinition<GenericSchema, true>;\n addTable<TableDef extends Table.AnyWithProps>(table: TableDef): AnyWithProps;\n}\n\nexport type Tables<DatabaseSchema_ extends AnyWithProps> =\n DatabaseSchema_ extends DatabaseSchema<infer Tables_> ? Tables_ : never;\n\nexport type TableNames<DatabaseSchema_ extends AnyWithProps> = Table.Name<\n Tables<DatabaseSchema_>\n> &\n string;\n\nexport type TableWithName<\n DatabaseSchema_ extends AnyWithProps,\n TableName extends TableNames<DatabaseSchema_>,\n> = Extract<Tables<DatabaseSchema_>, { readonly name: TableName }>;\n\nconst Proto = {\n [TypeId]: TypeId,\n\n addTable<TableDef extends Table.AnyWithProps>(\n this: DatabaseSchema<Table.AnyWithProps>,\n table: TableDef,\n ) {\n const tablesArray = Object.values(this.tables) as Table.AnyWithProps[];\n const newTablesArray = [...tablesArray, table];\n\n return makeProto({\n tables: Record.set(this.tables, table.name, table),\n convexSchemaDefinition: pipe(\n newTablesArray,\n Array.map(\n ({ name, tableDefinition }) => [name, tableDefinition] as const,\n ),\n Record.fromEntries,\n defineConvexSchema,\n ),\n });\n },\n};\n\nconst makeProto = <Tables_ extends Table.AnyWithProps>({\n tables,\n convexSchemaDefinition,\n}: {\n tables: Record.ReadonlyRecord<string, Tables_>;\n convexSchemaDefinition: SchemaDefinition<GenericSchema, true>;\n}): DatabaseSchema<Tables_> =>\n Object.assign(Object.create(Proto), {\n tables,\n convexSchemaDefinition,\n });\n\n/**\n * Create an empty schema definition. Add tables incrementally via `addTable`.\n */\nexport const make = (): DatabaseSchema<never> =>\n makeProto({\n tables: Record.empty(),\n convexSchemaDefinition: defineConvexSchema({}),\n });\n\nexport type ConvexDatabaseSchemaFromTables<Tables_ extends Table.AnyWithProps> =\n Expand<{\n [TableName in Table.Name<Tables_> & string]: Table.WithName<\n Tables_,\n TableName\n >[\"tableDefinition\"];\n }>;\n\n// System tables\n\nexport const systemSchema = make()\n .addTable(Table.scheduledFunctionsTable)\n .addTable(Table.storageTable);\n\nexport const extendWithSystemTables = <Tables_ extends Table.AnyWithProps>(\n tables: Table.TablesRecord<Tables_>,\n): ExtendWithSystemTables<Tables_> =>\n ({\n ...tables,\n ...Table.systemTables,\n }) as ExtendWithSystemTables<Tables_>;\n\nexport type ExtendWithSystemTables<Tables_ extends Table.AnyWithProps> =\n Table.TablesRecord<Tables_ | Table.SystemTables>;\n\nexport type IncludeSystemTables<Tables_ extends Table.AnyWithProps> =\n | Tables_\n | Table.SystemTables extends infer T\n ? T extends Table.AnyWithProps\n ? T\n : never\n : never;\n"],"mappings":";;;;;;;;;;;;;;AAsDA,MAAM,QAAQ;EACXA,WAASA;CAEV,SAEE,OACA;EAEA,MAAM,iBAAiB,CAAC,GADJ,OAAO,OAAO,KAAK,OAAO,EACN,MAAM;AAE9C,SAAO,UAAU;GACf,QAAQ,OAAO,IAAI,KAAK,QAAQ,MAAM,MAAM,MAAM;GAClD,wBAAwB,KACtB,gBACA,MAAM,KACH,EAAE,MAAM,sBAAsB,CAAC,MAAM,gBAAgB,CACvD,EACD,OAAO,aACPC,aACD;GACF,CAAC;;CAEL;AAED,MAAM,aAAiD,EACrD,QACA,6BAKA,OAAO,OAAO,OAAO,OAAO,MAAM,EAAE;CAClC;CACA;CACD,CAAC;;;;AAKJ,MAAa,aACX,UAAU;CACR,QAAQ,OAAO,OAAO;CACtB,wBAAwBA,aAAmB,EAAE,CAAC;CAC/C,CAAC;AAYJ,MAAa,eAAe,MAAM,CAC/B,SAASC,wBAA8B,CACvC,SAASC,aAAmB;AAE/B,MAAa,0BACX,YAEC;CACC,GAAG;CACH,GAAGC;CACJ"}
|
package/dist/Document.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Document.d.ts","names":[],"sources":["../src/Document.ts"],"mappings":";;;;;;;;;;KAOY,mBAAA,QAA2B,IAAA,CAAK,GAAA;AAAA,KAEhC,GAAA;AAAA,KACA,UAAA,GAAa,cAAA,SAAuB,aAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"Document.d.ts","names":[],"sources":["../src/Document.ts"],"mappings":";;;;;;;;;;KAOY,mBAAA,QAA2B,IAAA,CAAK,GAAA;AAAA,KAEhC,GAAA;AAAA,KACA,UAAA,GAAa,cAAA,SAAuB,aAAA;AAAA,cAiCnC,MAAA,uBAEU,YAAA,oBACD,UAAA,CAAqB,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KnC,EAAA;EACA,SAAA;EACA,OAAA;AAAA"}
|
package/dist/Document.js
CHANGED
|
@@ -10,29 +10,41 @@ var Document_exports = /* @__PURE__ */ __exportAll({
|
|
|
10
10
|
documentErrorMessage: () => documentErrorMessage,
|
|
11
11
|
encode: () => encode
|
|
12
12
|
});
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}));
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
13
|
+
const decoderCache = /* @__PURE__ */ new WeakMap();
|
|
14
|
+
const getDecoder = (tableName, tableSchema) => {
|
|
15
|
+
const byTable = decoderCache.get(tableSchema) ?? (() => {
|
|
16
|
+
const map = /* @__PURE__ */ new Map();
|
|
17
|
+
decoderCache.set(tableSchema, map);
|
|
18
|
+
return map;
|
|
19
|
+
})();
|
|
20
|
+
return byTable.get(tableName) ?? (() => {
|
|
21
|
+
const decoder = Schema.decode(SystemFields.extendWithSystemFields(tableName, tableSchema));
|
|
22
|
+
byTable.set(tableName, decoder);
|
|
23
|
+
return decoder;
|
|
24
|
+
})();
|
|
25
|
+
};
|
|
26
|
+
const decode = Function.dual(3, (self, tableName, tableSchema) => pipe(self, getDecoder(tableName, tableSchema), Effect.catchIf(ParseResult.isParseError, (parseError) => Effect.gen(function* () {
|
|
27
|
+
const formattedParseError = yield* ParseResult.TreeFormatter.formatError(parseError);
|
|
28
|
+
return yield* new DocumentDecodeError({
|
|
29
|
+
tableName,
|
|
30
|
+
id: self._id,
|
|
31
|
+
parseError: formattedParseError
|
|
32
|
+
});
|
|
33
|
+
})), Effect.map((decodedDoc) => decodedDoc)));
|
|
34
|
+
const encoderCache = /* @__PURE__ */ new WeakMap();
|
|
35
|
+
const getEncoder = (tableSchema) => encoderCache.get(tableSchema) ?? (() => {
|
|
36
|
+
const encoder = Schema.encode(tableSchema);
|
|
37
|
+
encoderCache.set(tableSchema, encoder);
|
|
38
|
+
return encoder;
|
|
39
|
+
})();
|
|
40
|
+
const encode = Function.dual(3, (self, tableName, tableSchema) => pipe(self, getEncoder(tableSchema), Effect.catchIf(ParseResult.isParseError, (parseError) => Effect.gen(function* () {
|
|
41
|
+
const formattedParseError = yield* ParseResult.TreeFormatter.formatError(parseError);
|
|
42
|
+
return yield* new DocumentEncodeError({
|
|
43
|
+
tableName,
|
|
44
|
+
id: self._id,
|
|
45
|
+
parseError: formattedParseError
|
|
46
|
+
});
|
|
47
|
+
})), Effect.map((encodedDoc) => encodedDoc)));
|
|
36
48
|
var DocumentDecodeError = class extends Schema.TaggedError()("DocumentDecodeError", {
|
|
37
49
|
tableName: Schema.String,
|
|
38
50
|
id: Schema.String,
|
package/dist/Document.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Document.js","names":[],"sources":["../src/Document.ts"],"sourcesContent":["import { Effect, Function, ParseResult, pipe, Schema } from \"effect\";\nimport type { ReadonlyRecord } from \"effect/Record\";\nimport
|
|
1
|
+
{"version":3,"file":"Document.js","names":[],"sources":["../src/Document.ts"],"sourcesContent":["import * as SystemFields from \"@confect/core/SystemFields\";\nimport { Effect, Function, ParseResult, pipe, Schema } from \"effect\";\nimport type { ReadonlyRecord } from \"effect/Record\";\nimport type * as DataModel from \"./DataModel\";\nimport type { ReadonlyValue } from \"./SchemaToValidator\";\nimport type * as TableInfo from \"./TableInfo\";\n\nexport type WithoutSystemFields<Doc> = Omit<Doc, \"_creationTime\" | \"_id\">;\n\nexport type Any = any;\nexport type AnyEncoded = ReadonlyRecord<string, ReadonlyValue>;\n\ntype Decode = (doc: unknown) => Effect.Effect<unknown, ParseResult.ParseError>;\n\nconst decoderCache = new WeakMap<\n Schema.Schema.AnyNoContext,\n Map<string, Decode>\n>();\n\nconst getDecoder = (\n tableName: string,\n tableSchema: Schema.Schema.AnyNoContext,\n): Decode => {\n const byTable =\n decoderCache.get(tableSchema) ??\n (() => {\n const map = new Map<string, Decode>();\n decoderCache.set(tableSchema, map);\n return map;\n })();\n\n return (\n byTable.get(tableName) ??\n (() => {\n const decoder = Schema.decode(\n SystemFields.extendWithSystemFields(tableName, tableSchema),\n ) as Decode;\n byTable.set(tableName, decoder);\n return decoder;\n })()\n );\n};\n\nexport const decode = Function.dual<\n <\n DataModel_ extends DataModel.AnyWithProps,\n TableName extends DataModel.TableNames<DataModel_>,\n >(\n tableName: TableName,\n tableSchema: TableInfo.TableSchema<\n DataModel.TableInfoWithName_<DataModel_, TableName>\n >,\n ) => (\n self: DataModel.TableInfoWithName_<DataModel_, TableName>[\"convexDocument\"],\n ) => Effect.Effect<\n DataModel.TableInfoWithName_<DataModel_, TableName>[\"document\"],\n DocumentDecodeError\n >,\n <\n DataModel_ extends DataModel.AnyWithProps,\n TableName extends DataModel.TableNames<DataModel_>,\n >(\n self: DataModel.TableInfoWithName_<DataModel_, TableName>[\"convexDocument\"],\n tableName: TableName,\n tableSchema: TableInfo.TableSchema<\n DataModel.TableInfoWithName_<DataModel_, TableName>\n >,\n ) => Effect.Effect<\n DataModel.TableInfoWithName_<DataModel_, TableName>[\"document\"],\n DocumentDecodeError\n >\n>(\n 3,\n <\n DataModel_ extends DataModel.AnyWithProps,\n TableName extends DataModel.TableNames<DataModel_>,\n >(\n self: DataModel.TableInfoWithName_<DataModel_, TableName>[\"convexDocument\"],\n tableName: TableName,\n tableSchema: TableInfo.TableSchema<\n DataModel.TableInfoWithName_<DataModel_, TableName>\n >,\n ): Effect.Effect<\n DataModel.TableInfoWithName_<DataModel_, TableName>[\"document\"],\n DocumentDecodeError\n > =>\n pipe(\n self,\n getDecoder(tableName, tableSchema),\n Effect.catchIf(ParseResult.isParseError, (parseError) =>\n Effect.gen(function* () {\n const formattedParseError =\n yield* ParseResult.TreeFormatter.formatError(parseError);\n\n return yield* new DocumentDecodeError({\n tableName,\n id: self._id,\n parseError: formattedParseError,\n });\n }),\n ),\n Effect.map(\n (decodedDoc) =>\n decodedDoc as DataModel.TableInfoWithName_<\n DataModel_,\n TableName\n >[\"document\"],\n ),\n ),\n);\n\ntype Encode = (doc: unknown) => Effect.Effect<unknown, ParseResult.ParseError>;\n\nconst encoderCache = new WeakMap<Schema.Schema.AnyNoContext, Encode>();\n\nconst getEncoder = (tableSchema: Schema.Schema.AnyNoContext): Encode =>\n encoderCache.get(tableSchema) ??\n (() => {\n const encoder = Schema.encode(tableSchema) as Encode;\n encoderCache.set(tableSchema, encoder);\n return encoder;\n })();\n\nexport const encode = Function.dual<\n <\n DataModel_ extends DataModel.AnyWithProps,\n TableName extends DataModel.TableNames<DataModel_>,\n >(\n tableName: TableName,\n tableSchema: TableInfo.TableSchema<\n DataModel.TableInfoWithName_<DataModel_, TableName>\n >,\n ) => (\n self: DataModel.TableInfoWithName_<DataModel_, TableName>[\"document\"],\n ) => Effect.Effect<\n DataModel.TableInfoWithName_<DataModel_, TableName>[\"encodedDocument\"],\n DocumentEncodeError\n >,\n <\n DataModel_ extends DataModel.AnyWithProps,\n TableName extends DataModel.TableNames<DataModel_>,\n >(\n self: DataModel.TableInfoWithName_<DataModel_, TableName>[\"document\"],\n tableName: TableName,\n tableSchema: TableInfo.TableSchema<\n DataModel.TableInfoWithName_<DataModel_, TableName>\n >,\n ) => Effect.Effect<\n DataModel.TableInfoWithName_<DataModel_, TableName>[\"encodedDocument\"],\n DocumentEncodeError\n >\n>(\n 3,\n <\n DataModel_ extends DataModel.AnyWithProps,\n TableName extends DataModel.TableNames<DataModel_>,\n >(\n self: DataModel.TableInfoWithName_<DataModel_, TableName>[\"document\"],\n tableName: TableName,\n tableSchema: TableInfo.TableSchema<\n DataModel.TableInfoWithName_<DataModel_, TableName>\n >,\n ): Effect.Effect<\n DataModel.TableInfoWithName_<DataModel_, TableName>[\"encodedDocument\"],\n DocumentEncodeError\n > =>\n pipe(\n self,\n getEncoder(tableSchema),\n Effect.catchIf(ParseResult.isParseError, (parseError) =>\n Effect.gen(function* () {\n const formattedParseError =\n yield* ParseResult.TreeFormatter.formatError(parseError);\n\n return yield* new DocumentEncodeError({\n tableName,\n id: self._id,\n parseError: formattedParseError,\n });\n }),\n ),\n Effect.map(\n (encodedDoc) =>\n encodedDoc as DataModel.TableInfoWithName_<\n DataModel_,\n TableName\n >[\"encodedDocument\"],\n ),\n ),\n);\n\nexport class DocumentDecodeError extends Schema.TaggedError<DocumentDecodeError>()(\n \"DocumentDecodeError\",\n {\n tableName: Schema.String,\n id: Schema.String,\n parseError: Schema.String,\n },\n) {\n override get message(): string {\n return documentErrorMessage({\n id: this.id,\n tableName: this.tableName,\n message: `could not be decoded:\\n\\n${this.parseError}`,\n });\n }\n}\n\nexport class DocumentEncodeError extends Schema.TaggedError<DocumentEncodeError>()(\n \"DocumentEncodeError\",\n {\n tableName: Schema.String,\n id: Schema.String,\n parseError: Schema.String,\n },\n) {\n override get message(): string {\n return documentErrorMessage({\n id: this.id,\n tableName: this.tableName,\n message: `could not be encoded:\\n\\n${this.parseError}`,\n });\n }\n}\n\nexport const documentErrorMessage = ({\n id,\n tableName,\n message,\n}: {\n id: string;\n tableName: string;\n message: string;\n}) => `Document with ID '${id}' in table '${tableName}' ${message}`;\n"],"mappings":";;;;;;;;;;;;AAcA,MAAM,+BAAe,IAAI,SAGtB;AAEH,MAAM,cACJ,WACA,gBACW;CACX,MAAM,UACJ,aAAa,IAAI,YAAY,WACtB;EACL,MAAM,sBAAM,IAAI,KAAqB;AACrC,eAAa,IAAI,aAAa,IAAI;AAClC,SAAO;KACL;AAEN,QACE,QAAQ,IAAI,UAAU,WACf;EACL,MAAM,UAAU,OAAO,OACrB,aAAa,uBAAuB,WAAW,YAAY,CAC5D;AACD,UAAQ,IAAI,WAAW,QAAQ;AAC/B,SAAO;KACL;;AAIR,MAAa,SAAS,SAAS,KA6B7B,IAKE,MACA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,wBAAwB,EACnC,IACA,WACA,cAKI,qBAAqB,GAAG,cAAc,UAAU,IAAI"}
|
|
@@ -35,7 +35,7 @@ declare const make: <Api_ extends AnyWithPropsWithRuntime<"Convex">>(api: Api_,
|
|
|
35
35
|
functionSpec,
|
|
36
36
|
handler
|
|
37
37
|
}: AnyWithProps$1) => Any;
|
|
38
|
-
declare const mutationLayer: <Schema extends AnyWithProps>(schema: Schema, ctx: GenericMutationCtx<ToConvex<FromSchema<Schema>>>) => Layer.Layer<
|
|
38
|
+
declare const mutationLayer: <Schema extends AnyWithProps>(schema: Schema, ctx: GenericMutationCtx<ToConvex<FromSchema<Schema>>>) => Layer.Layer<StorageReader$1 | StorageWriter$1 | (<Query extends _confect_core_Ref0.AnyQuery>(query: Query, ...args: _confect_core_Ref0.OptionalArgs<Query>) => Effect.Effect<_confect_core_Ref0.Returns<Query>, _confect_core_Ref0.Error<Query> | effect_ParseResult0.ParseError>) | GenericMutationCtx<ToConvex<FromSchema<Schema>>> | {
|
|
39
39
|
table: <const TableName extends Name<IncludeSystemTables<Tables<Schema>>>>(tableName: TableName) => {
|
|
40
40
|
readonly get: {
|
|
41
41
|
(id: convex_values0.GenericId<TableName>): Effect.Effect<TableInfo<WithName<IncludeSystemTables<Tables<Schema>>, TableName>>["document"], DocumentDecodeError | GetByIdFailure, never>;
|
|
@@ -54,7 +54,7 @@ declare const mutationLayer: <Schema extends AnyWithProps>(schema: Schema, ctx:
|
|
|
54
54
|
replace: (id: convex_values0.GenericId<TableName>, value: convex_server0.Expand<convex_server0.BetterOmit<DocumentByName<FromSchema<Schema>, TableName>, "_id" | "_creationTime">>) => Effect.Effect<void, DocumentEncodeError, never>;
|
|
55
55
|
delete: (id: convex_values0.GenericId<TableName>) => Effect.Effect<void, never, never>;
|
|
56
56
|
};
|
|
57
|
-
} | {
|
|
57
|
+
} | Auth$1 | {
|
|
58
58
|
runAfter: <Ref_ extends _confect_core_Ref0.AnyMutation | _confect_core_Ref0.AnyAction>(delay: effect_Duration0.Duration, ref: Ref_, ...args: _confect_core_Ref0.OptionalArgs<Ref_>) => Effect.Effect<convex_values0.GenericId<"_scheduled_functions">, never, never>;
|
|
59
59
|
runAt: <Ref_ extends _confect_core_Ref0.AnyMutation | _confect_core_Ref0.AnyAction>(dateTime: effect_DateTime0.DateTime, ref: Ref_, ...args: _confect_core_Ref0.OptionalArgs<Ref_>) => Effect.Effect<convex_values0.GenericId<"_scheduled_functions">, never, never>;
|
|
60
60
|
} | (<Mutation extends _confect_core_Ref0.AnyMutation>(mutation: Mutation, ...args: _confect_core_Ref0.OptionalArgs<Mutation>) => Effect.Effect<_confect_core_Ref0.Returns<Mutation>, _confect_core_Ref0.Error<Mutation> | effect_ParseResult0.ParseError>), never, never>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RegisteredConvexFunction.d.ts","names":[],"sources":["../src/RegisteredConvexFunction.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAiCa,IAAA,gBAAqB,uBAAA,YAChC,GAAA,EAAK,IAAA;EACL,YAAA;EAAA;AAAA,GAA2B,cAAA,KAC1B,GAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"RegisteredConvexFunction.d.ts","names":[],"sources":["../src/RegisteredConvexFunction.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAiCa,IAAA,gBAAqB,uBAAA,YAChC,GAAA,EAAK,IAAA;EACL,YAAA;EAAA;AAAA,GAA2B,cAAA,KAC1B,GAAA;AAAA,cAkLU,aAAA,kBAAgC,YAAA,EAC3C,MAAA,EAAQ,MAAA,EACR,GAAA,EAAK,kBAAA,CAAmB,QAAA,CAAmB,UAAA,CAAqB,MAAA,QAAS,KAAA,CAAA,KAAA,CAAA,eAAA,GAAA,eAAA,mBAAA,kBAAA,CAAA,QAAA,EAAA,KAAA,EAAA,KAAA,KAAA,IAAA,EAAA,kBAAA,CAAA,YAAA,CAAA,KAAA,MAAA,MAAA,CAAA,MAAA,CAAA,kBAAA,CAAA,OAAA,CAAA,KAAA,GAAA,kBAAA,CAAA,KAAA,CAAA,KAAA,IAAA,mBAAA,CAAA,UAAA,KAAA,kBAAA,CAAA,QAAA,CAAA,UAAA,CAAA,MAAA;;;;;;;;;;;;;;;;;;;;;;;KAoB/D,gBAAA,gBAAgC,YAAA,IACxC,cAAA,CAA8B,MAAA,IAC9B,cAAA,CAA8B,MAAA,IAC9B,MAAA,GACA,WAAA,GACA,eAAA,GACA,eAAA,GACA,WAAA,GACA,cAAA,GACA,WAAA,CAAwB,QAAA,CAAmB,UAAA,CAAqB,MAAA"}
|
|
@@ -47,16 +47,27 @@ const make = (api, { functionSpec, handler }) => Match.value(functionSpec.functi
|
|
|
47
47
|
}));
|
|
48
48
|
}), Match.exhaustive);
|
|
49
49
|
}), Match.exhaustive);
|
|
50
|
+
/**
|
|
51
|
+
* Convex's query cache is invalidated by any Date.now() call during handler
|
|
52
|
+
* execution. Effect's unsafeFork calls Date.now() when constructing a
|
|
53
|
+
* FiberId.Runtime, which trips the cache for every confect-wrapped query. We
|
|
54
|
+
* stub Date.now to 0 for the span of the handler; queries are forbidden from
|
|
55
|
+
* relying on real time for correctness anyway.
|
|
56
|
+
*
|
|
57
|
+
* Users who explicitly want the real timestamp can still reach it via Effect's
|
|
58
|
+
* Clock service (Clock.currentTimeMillis/Clock.currentTimeNanos). We provide a
|
|
59
|
+
* Clock whose user-facing Effects call realDateNow (Convex's tracker) directly,
|
|
60
|
+
* making Clock an explicit opt-in to cache invalidation. The unsafe methods
|
|
61
|
+
* used internally by Effect (logging, span events, scheduler) return constants
|
|
62
|
+
* so they never touch the tracker—caching is not broken by default.
|
|
63
|
+
*/
|
|
50
64
|
const unpatchedClock = (realDateNow) => {
|
|
51
|
-
const bigint1e6 = BigInt(1e6);
|
|
52
|
-
const unsafeCurrentTimeMillis = () => realDateNow();
|
|
53
|
-
const unsafeCurrentTimeNanos = () => BigInt(realDateNow()) * bigint1e6;
|
|
54
65
|
return {
|
|
55
66
|
...Clock.make(),
|
|
56
|
-
unsafeCurrentTimeMillis,
|
|
57
|
-
unsafeCurrentTimeNanos,
|
|
58
|
-
currentTimeMillis: Effect.sync(
|
|
59
|
-
currentTimeNanos: Effect.sync(
|
|
67
|
+
unsafeCurrentTimeMillis: () => 0,
|
|
68
|
+
unsafeCurrentTimeNanos: () => 0n,
|
|
69
|
+
currentTimeMillis: Effect.sync(() => realDateNow()),
|
|
70
|
+
currentTimeNanos: Effect.sync(() => BigInt(realDateNow()) * 1000000n)
|
|
60
71
|
};
|
|
61
72
|
};
|
|
62
73
|
const withStubbedDateNow = async (queryHandler) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RegisteredConvexFunction.js","names":["SchemaToValidator.compileArgsSchema","SchemaToValidator.compileReturnsSchema","DatabaseReader.layer","Auth.layer","StorageReader","QueryRunner.layer","QueryCtx.QueryCtx","ConvexConfigProvider.make","RegisteredFunction.runHandlerPromise","DatabaseWriter.layer","Scheduler.layer","StorageWriter","MutationRunner.layer","MutationCtx.MutationCtx","RegisteredFunction.actionFunctionBase","RegisteredFunction.actionLayer"],"sources":["../src/RegisteredConvexFunction.ts"],"sourcesContent":["import type * as FunctionSpec from \"@confect/core/FunctionSpec\";\nimport {\n actionGeneric,\n type DefaultFunctionArgs,\n type GenericMutationCtx,\n type GenericQueryCtx,\n internalActionGeneric,\n internalMutationGeneric,\n internalQueryGeneric,\n mutationGeneric,\n queryGeneric,\n} from \"convex/server\";\nimport type { Value } from \"convex/values\";\nimport { Clock, Effect, Layer, Match, pipe, Schema } from \"effect\";\nimport type * as Api from \"./Api\";\nimport * as Auth from \"./Auth\";\nimport * as ConvexConfigProvider from \"./ConvexConfigProvider\";\nimport * as DatabaseReader from \"./DatabaseReader\";\nimport type * as DatabaseSchema from \"./DatabaseSchema\";\nimport * as DatabaseWriter from \"./DatabaseWriter\";\nimport type * as DataModel from \"./DataModel\";\nimport type * as Handler from \"./Handler\";\nimport * as MutationCtx from \"./MutationCtx\";\nimport * as MutationRunner from \"./MutationRunner\";\nimport * as QueryCtx from \"./QueryCtx\";\nimport * as QueryRunner from \"./QueryRunner\";\nimport * as RegisteredFunction from \"./RegisteredFunction\";\nimport type * as RegistryItem from \"./RegistryItem\";\nimport * as Scheduler from \"./Scheduler\";\nimport * as SchemaToValidator from \"./SchemaToValidator\";\nimport { StorageReader } from \"./StorageReader\";\nimport { StorageWriter } from \"./StorageWriter\";\n\nexport const make = <Api_ extends Api.AnyWithPropsWithRuntime<\"Convex\">>(\n api: Api_,\n { functionSpec, handler }: RegistryItem.AnyWithProps,\n): RegisteredFunction.Any =>\n Match.value(functionSpec.functionProvenance).pipe(\n Match.tag(\"Convex\", () => handler as RegisteredFunction.Any),\n Match.tag(\"Confect\", () => {\n const { functionVisibility, functionProvenance } =\n functionSpec as FunctionSpec.AnyConfect;\n\n return Match.value(functionSpec.runtimeAndFunctionType.functionType).pipe(\n Match.when(\"query\", () => {\n const genericFunction = Match.value(functionVisibility).pipe(\n Match.when(\"public\", () => queryGeneric),\n Match.when(\"internal\", () => internalQueryGeneric),\n Match.exhaustive,\n );\n\n return genericFunction(\n queryFunction({\n databaseSchema: api.databaseSchema,\n args: functionProvenance.args,\n returns: functionProvenance.returns,\n error: functionProvenance.error,\n handler: handler as Handler.AnyConfectProvenance,\n }),\n );\n }),\n Match.when(\"mutation\", () => {\n const genericFunction = Match.value(functionVisibility).pipe(\n Match.when(\"public\", () => mutationGeneric),\n Match.when(\"internal\", () => internalMutationGeneric),\n Match.exhaustive,\n );\n\n return genericFunction(\n mutationFunction({\n databaseSchema: api.databaseSchema,\n args: functionProvenance.args,\n returns: functionProvenance.returns,\n error: functionProvenance.error,\n handler: handler as Handler.AnyConfectProvenance,\n }),\n );\n }),\n Match.when(\"action\", () => {\n const genericFunction = Match.value(functionVisibility).pipe(\n Match.when(\"public\", () => actionGeneric),\n Match.when(\"internal\", () => internalActionGeneric),\n Match.exhaustive,\n );\n\n return genericFunction(\n convexActionFunction(api.databaseSchema, {\n args: functionProvenance.args,\n returns: functionProvenance.returns,\n error: functionProvenance.error,\n handler: handler as Handler.AnyConfectProvenance,\n }),\n );\n }),\n Match.exhaustive,\n );\n }),\n Match.exhaustive,\n );\n\n// Convex's query cache is invalidated by any Date.now() call during handler\n// execution. Effect's unsafeFork calls Date.now() when constructing a\n// FiberId.Runtime, which trips the cache for every confect-wrapped query. We\n// stub Date.now to 0 for the span of the handler; queries are forbidden from\n// relying on real time for correctness anyway.\n//\n// Users who explicitly want the real timestamp can still reach it via Effect's\n// Clock service (Clock.currentTimeMillis/Clock.currentTimeNanos). We provide\n// a Clock layer whose methods close over the *original* Date.now, so opting in\n// to Clock is an opt-in to worse caching—but caching is not broken by default.\nconst unpatchedClock = (realDateNow: () => number): Clock.Clock => {\n const bigint1e6 = BigInt(1_000_000);\n const unsafeCurrentTimeMillis = () => realDateNow();\n const unsafeCurrentTimeNanos = () => BigInt(realDateNow()) * bigint1e6;\n const defaultClock = Clock.make();\n return {\n ...defaultClock,\n unsafeCurrentTimeMillis,\n unsafeCurrentTimeNanos,\n currentTimeMillis: Effect.sync(unsafeCurrentTimeMillis),\n currentTimeNanos: Effect.sync(unsafeCurrentTimeNanos),\n };\n};\n\nconst withStubbedDateNow = async <T>(\n queryHandler: (clock: Clock.Clock) => Promise<T>,\n): Promise<T> => {\n const realDateNow = Date.now;\n const clock = unpatchedClock(realDateNow);\n Date.now = () => 0;\n try {\n return await queryHandler(clock);\n } finally {\n Date.now = realDateNow;\n }\n};\n\nconst queryFunction = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Args,\n ConvexArgs extends DefaultFunctionArgs,\n Returns,\n ConvexReturns,\n E,\n>({\n databaseSchema,\n args,\n returns,\n error,\n handler,\n}: {\n databaseSchema: DatabaseSchema_;\n args: Schema.Schema<Args, ConvexArgs>;\n returns: Schema.Schema<Returns, ConvexReturns>;\n error: Schema.Schema<Error, Value> | undefined;\n handler: (\n a: Args,\n ) => Effect.Effect<\n Returns,\n E,\n | DatabaseReader.DatabaseReader<DatabaseSchema_>\n | Auth.Auth\n | StorageReader\n | QueryRunner.QueryRunner\n | QueryCtx.QueryCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >\n >;\n}) => ({\n args: SchemaToValidator.compileArgsSchema(args),\n returns: SchemaToValidator.compileReturnsSchema(returns),\n handler: (\n ctx: GenericQueryCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >,\n actualArgs: ConvexArgs,\n ): Promise<ConvexReturns> =>\n withStubbedDateNow((clock) =>\n Effect.gen(function* () {\n const decodedArgs = yield* pipe(\n actualArgs,\n Schema.decode(args),\n Effect.orDie,\n );\n const decodedReturns = yield* handler(decodedArgs).pipe(\n Effect.provide(\n Layer.mergeAll(\n DatabaseReader.layer(databaseSchema, ctx.db),\n Auth.layer(ctx.auth),\n StorageReader.layer(ctx.storage),\n QueryRunner.layer(ctx.runQuery),\n Layer.succeed(\n QueryCtx.QueryCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >(),\n ctx,\n ),\n Layer.setConfigProvider(ConvexConfigProvider.make()),\n ),\n ),\n );\n return yield* pipe(\n decodedReturns,\n Schema.encode(returns),\n Effect.orDie,\n );\n }).pipe(\n Effect.withClock(clock),\n RegisteredFunction.runHandlerPromise(error),\n ),\n ),\n});\n\nexport const mutationLayer = <Schema extends DatabaseSchema.AnyWithProps>(\n schema: Schema,\n ctx: GenericMutationCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>,\n) =>\n Layer.mergeAll(\n DatabaseReader.layer(schema, ctx.db),\n DatabaseWriter.layer(schema, ctx.db),\n Auth.layer(ctx.auth),\n Scheduler.layer(ctx.scheduler),\n StorageReader.layer(ctx.storage),\n StorageWriter.layer(ctx.storage),\n QueryRunner.layer(ctx.runQuery),\n MutationRunner.layer(ctx.runMutation),\n Layer.succeed(\n MutationCtx.MutationCtx<\n DataModel.ToConvex<DataModel.FromSchema<Schema>>\n >(),\n ctx,\n ),\n Layer.setConfigProvider(ConvexConfigProvider.make()),\n );\n\nexport type MutationServices<Schema extends DatabaseSchema.AnyWithProps> =\n | DatabaseReader.DatabaseReader<Schema>\n | DatabaseWriter.DatabaseWriter<Schema>\n | Auth.Auth\n | Scheduler.Scheduler\n | StorageReader\n | StorageWriter\n | QueryRunner.QueryRunner\n | MutationRunner.MutationRunner\n | MutationCtx.MutationCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>;\n\nconst mutationFunction = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Args,\n ConvexArgs extends DefaultFunctionArgs,\n Returns,\n ConvexReturns,\n E,\n>({\n databaseSchema,\n args,\n returns,\n error,\n handler,\n}: {\n databaseSchema: DatabaseSchema_;\n args: Schema.Schema<Args, ConvexArgs>;\n returns: Schema.Schema<Returns, ConvexReturns>;\n error: Schema.Schema<Error, Value> | undefined;\n handler: (\n a: Args,\n ) => Effect.Effect<Returns, E, MutationServices<DatabaseSchema_>>;\n}) => ({\n args: SchemaToValidator.compileArgsSchema(args),\n returns: SchemaToValidator.compileReturnsSchema(returns),\n handler: (\n ctx: GenericMutationCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >,\n actualArgs: ConvexArgs,\n ): Promise<ConvexReturns> =>\n Effect.gen(function* () {\n const decodedArgs = yield* pipe(\n actualArgs,\n Schema.decode(args),\n Effect.orDie,\n );\n const decodedReturns = yield* handler(decodedArgs).pipe(\n Effect.provide(mutationLayer(databaseSchema, ctx)),\n );\n return yield* pipe(decodedReturns, Schema.encode(returns), Effect.orDie);\n }).pipe(RegisteredFunction.runHandlerPromise(error)),\n});\n\nconst convexActionFunction = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Args,\n ConvexArgs extends DefaultFunctionArgs,\n Returns,\n ConvexReturns,\n E,\n>(\n schema: DatabaseSchema_,\n {\n args,\n returns,\n error,\n handler,\n }: {\n args: Schema.Schema<Args, ConvexArgs>;\n returns: Schema.Schema<Returns, ConvexReturns>;\n error: Schema.Schema.AnyNoContext | undefined;\n handler: (\n a: Args,\n ) => Effect.Effect<\n Returns,\n E,\n RegisteredFunction.ActionServices<DatabaseSchema_>\n >;\n },\n) =>\n RegisteredFunction.actionFunctionBase({\n args,\n returns,\n error,\n handler,\n createLayer: (ctx) =>\n Layer.mergeAll(\n RegisteredFunction.actionLayer(schema, ctx),\n Layer.setConfigProvider(ConvexConfigProvider.make()),\n ),\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAa,QACX,KACA,EAAE,cAAc,cAEhB,MAAM,MAAM,aAAa,mBAAmB,CAAC,KAC3C,MAAM,IAAI,gBAAgB,QAAkC,EAC5D,MAAM,IAAI,iBAAiB;CACzB,MAAM,EAAE,oBAAoB,uBAC1B;AAEF,QAAO,MAAM,MAAM,aAAa,uBAAuB,aAAa,CAAC,KACnE,MAAM,KAAK,eAAe;AAOxB,SANwB,MAAM,MAAM,mBAAmB,CAAC,KACtD,MAAM,KAAK,gBAAgB,aAAa,EACxC,MAAM,KAAK,kBAAkB,qBAAqB,EAClD,MAAM,WACP,CAGC,cAAc;GACZ,gBAAgB,IAAI;GACpB,MAAM,mBAAmB;GACzB,SAAS,mBAAmB;GAC5B,OAAO,mBAAmB;GACjB;GACV,CAAC,CACH;GACD,EACF,MAAM,KAAK,kBAAkB;AAO3B,SANwB,MAAM,MAAM,mBAAmB,CAAC,KACtD,MAAM,KAAK,gBAAgB,gBAAgB,EAC3C,MAAM,KAAK,kBAAkB,wBAAwB,EACrD,MAAM,WACP,CAGC,iBAAiB;GACf,gBAAgB,IAAI;GACpB,MAAM,mBAAmB;GACzB,SAAS,mBAAmB;GAC5B,OAAO,mBAAmB;GACjB;GACV,CAAC,CACH;GACD,EACF,MAAM,KAAK,gBAAgB;AAOzB,SANwB,MAAM,MAAM,mBAAmB,CAAC,KACtD,MAAM,KAAK,gBAAgB,cAAc,EACzC,MAAM,KAAK,kB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BACX,QACA,QAEA,MAAM,SACJN,QAAqB,QAAQ,IAAI,GAAG,EACpCO,QAAqB,QAAQ,IAAI,GAAG,EACpCN,MAAW,IAAI,KAAK,EACpBO,QAAgB,IAAI,UAAU,EAC9BN,gBAAc,MAAM,IAAI,QAAQ,EAChCO,gBAAc,MAAM,IAAI,QAAQ,EAChCN,QAAkB,IAAI,SAAS,EAC/BO,QAAqB,IAAI,YAAY,EACrC,MAAM,QACJC,aAEG,EACH,IACD,EACD,MAAM,kBAAkBN,QAA2B,CAAC,CACrD;AAaH,MAAM,oBAOJ,EACA,gBACA,MACA,SACA,OACA,eASK;CACL,MAAMP,kBAAoC,KAAK;CAC/C,SAASC,qBAAuC,QAAQ;CACxD,UACE,KAGA,eAEA,OAAO,IAAI,aAAa;AAStB,SAAO,OAAO,KAHS,OAAO,QALV,OAAO,KACzB,YACA,OAAO,OAAO,KAAK,EACnB,OAAO,MACR,CACiD,CAAC,KACjD,OAAO,QAAQ,cAAc,gBAAgB,IAAI,CAAC,CACnD,EACkC,OAAO,OAAO,QAAQ,EAAE,OAAO,MAAM;GACxE,CAAC,KAAKO,kBAAqC,MAAM,CAAC;CACvD;AAED,MAAM,wBAQJ,QACA,EACE,MACA,SACA,OACA,cAcFM,mBAAsC;CACpC;CACA;CACA;CACA;CACA,cAAc,QACZ,MAAM,SACJC,YAA+B,QAAQ,IAAI,EAC3C,MAAM,kBAAkBR,QAA2B,CAAC,CACrD;CACJ,CAAC"}
|
|
1
|
+
{"version":3,"file":"RegisteredConvexFunction.js","names":["SchemaToValidator.compileArgsSchema","SchemaToValidator.compileReturnsSchema","DatabaseReader.layer","Auth.layer","StorageReader","QueryRunner.layer","QueryCtx.QueryCtx","ConvexConfigProvider.make","RegisteredFunction.runHandlerPromise","DatabaseWriter.layer","Scheduler.layer","StorageWriter","MutationRunner.layer","MutationCtx.MutationCtx","RegisteredFunction.actionFunctionBase","RegisteredFunction.actionLayer"],"sources":["../src/RegisteredConvexFunction.ts"],"sourcesContent":["import type * as FunctionSpec from \"@confect/core/FunctionSpec\";\nimport {\n actionGeneric,\n type DefaultFunctionArgs,\n type GenericMutationCtx,\n type GenericQueryCtx,\n internalActionGeneric,\n internalMutationGeneric,\n internalQueryGeneric,\n mutationGeneric,\n queryGeneric,\n} from \"convex/server\";\nimport type { Value } from \"convex/values\";\nimport { Clock, Effect, Layer, Match, pipe, Schema } from \"effect\";\nimport type * as Api from \"./Api\";\nimport * as Auth from \"./Auth\";\nimport * as ConvexConfigProvider from \"./ConvexConfigProvider\";\nimport * as DatabaseReader from \"./DatabaseReader\";\nimport type * as DatabaseSchema from \"./DatabaseSchema\";\nimport * as DatabaseWriter from \"./DatabaseWriter\";\nimport type * as DataModel from \"./DataModel\";\nimport type * as Handler from \"./Handler\";\nimport * as MutationCtx from \"./MutationCtx\";\nimport * as MutationRunner from \"./MutationRunner\";\nimport * as QueryCtx from \"./QueryCtx\";\nimport * as QueryRunner from \"./QueryRunner\";\nimport * as RegisteredFunction from \"./RegisteredFunction\";\nimport type * as RegistryItem from \"./RegistryItem\";\nimport * as Scheduler from \"./Scheduler\";\nimport * as SchemaToValidator from \"./SchemaToValidator\";\nimport { StorageReader } from \"./StorageReader\";\nimport { StorageWriter } from \"./StorageWriter\";\n\nexport const make = <Api_ extends Api.AnyWithPropsWithRuntime<\"Convex\">>(\n api: Api_,\n { functionSpec, handler }: RegistryItem.AnyWithProps,\n): RegisteredFunction.Any =>\n Match.value(functionSpec.functionProvenance).pipe(\n Match.tag(\"Convex\", () => handler as RegisteredFunction.Any),\n Match.tag(\"Confect\", () => {\n const { functionVisibility, functionProvenance } =\n functionSpec as FunctionSpec.AnyConfect;\n\n return Match.value(functionSpec.runtimeAndFunctionType.functionType).pipe(\n Match.when(\"query\", () => {\n const genericFunction = Match.value(functionVisibility).pipe(\n Match.when(\"public\", () => queryGeneric),\n Match.when(\"internal\", () => internalQueryGeneric),\n Match.exhaustive,\n );\n\n return genericFunction(\n queryFunction({\n databaseSchema: api.databaseSchema,\n args: functionProvenance.args,\n returns: functionProvenance.returns,\n error: functionProvenance.error,\n handler: handler as Handler.AnyConfectProvenance,\n }),\n );\n }),\n Match.when(\"mutation\", () => {\n const genericFunction = Match.value(functionVisibility).pipe(\n Match.when(\"public\", () => mutationGeneric),\n Match.when(\"internal\", () => internalMutationGeneric),\n Match.exhaustive,\n );\n\n return genericFunction(\n mutationFunction({\n databaseSchema: api.databaseSchema,\n args: functionProvenance.args,\n returns: functionProvenance.returns,\n error: functionProvenance.error,\n handler: handler as Handler.AnyConfectProvenance,\n }),\n );\n }),\n Match.when(\"action\", () => {\n const genericFunction = Match.value(functionVisibility).pipe(\n Match.when(\"public\", () => actionGeneric),\n Match.when(\"internal\", () => internalActionGeneric),\n Match.exhaustive,\n );\n\n return genericFunction(\n convexActionFunction(api.databaseSchema, {\n args: functionProvenance.args,\n returns: functionProvenance.returns,\n error: functionProvenance.error,\n handler: handler as Handler.AnyConfectProvenance,\n }),\n );\n }),\n Match.exhaustive,\n );\n }),\n Match.exhaustive,\n );\n\n/**\n * Convex's query cache is invalidated by any Date.now() call during handler\n * execution. Effect's unsafeFork calls Date.now() when constructing a\n * FiberId.Runtime, which trips the cache for every confect-wrapped query. We\n * stub Date.now to 0 for the span of the handler; queries are forbidden from\n * relying on real time for correctness anyway.\n *\n * Users who explicitly want the real timestamp can still reach it via Effect's\n * Clock service (Clock.currentTimeMillis/Clock.currentTimeNanos). We provide a\n * Clock whose user-facing Effects call realDateNow (Convex's tracker) directly,\n * making Clock an explicit opt-in to cache invalidation. The unsafe methods\n * used internally by Effect (logging, span events, scheduler) return constants\n * so they never touch the tracker—caching is not broken by default.\n */\nconst unpatchedClock = (realDateNow: () => number): Clock.Clock => {\n const defaultClock = Clock.make();\n return {\n ...defaultClock,\n unsafeCurrentTimeMillis: () => 0,\n unsafeCurrentTimeNanos: () => 0n,\n currentTimeMillis: Effect.sync(() => realDateNow()),\n currentTimeNanos: Effect.sync(() => BigInt(realDateNow()) * 1_000_000n),\n };\n};\n\nconst withStubbedDateNow = async <T>(\n queryHandler: (clock: Clock.Clock) => Promise<T>,\n): Promise<T> => {\n const realDateNow = Date.now;\n const clock = unpatchedClock(realDateNow);\n Date.now = () => 0;\n try {\n return await queryHandler(clock);\n } finally {\n Date.now = realDateNow;\n }\n};\n\nconst queryFunction = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Args,\n ConvexArgs extends DefaultFunctionArgs,\n Returns,\n ConvexReturns,\n E,\n>({\n databaseSchema,\n args,\n returns,\n error,\n handler,\n}: {\n databaseSchema: DatabaseSchema_;\n args: Schema.Schema<Args, ConvexArgs>;\n returns: Schema.Schema<Returns, ConvexReturns>;\n error: Schema.Schema<Error, Value> | undefined;\n handler: (\n a: Args,\n ) => Effect.Effect<\n Returns,\n E,\n | DatabaseReader.DatabaseReader<DatabaseSchema_>\n | Auth.Auth\n | StorageReader\n | QueryRunner.QueryRunner\n | QueryCtx.QueryCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >\n >;\n}) => ({\n args: SchemaToValidator.compileArgsSchema(args),\n returns: SchemaToValidator.compileReturnsSchema(returns),\n handler: (\n ctx: GenericQueryCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >,\n actualArgs: ConvexArgs,\n ): Promise<ConvexReturns> =>\n withStubbedDateNow((clock) =>\n Effect.gen(function* () {\n const decodedArgs = yield* pipe(\n actualArgs,\n Schema.decode(args),\n Effect.orDie,\n );\n const decodedReturns = yield* handler(decodedArgs).pipe(\n Effect.provide(\n Layer.mergeAll(\n DatabaseReader.layer(databaseSchema, ctx.db),\n Auth.layer(ctx.auth),\n StorageReader.layer(ctx.storage),\n QueryRunner.layer(ctx.runQuery),\n Layer.succeed(\n QueryCtx.QueryCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >(),\n ctx,\n ),\n Layer.setConfigProvider(ConvexConfigProvider.make()),\n ),\n ),\n );\n return yield* pipe(\n decodedReturns,\n Schema.encode(returns),\n Effect.orDie,\n );\n }).pipe(\n Effect.withClock(clock),\n RegisteredFunction.runHandlerPromise(error),\n ),\n ),\n});\n\nexport const mutationLayer = <Schema extends DatabaseSchema.AnyWithProps>(\n schema: Schema,\n ctx: GenericMutationCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>,\n) =>\n Layer.mergeAll(\n DatabaseReader.layer(schema, ctx.db),\n DatabaseWriter.layer(schema, ctx.db),\n Auth.layer(ctx.auth),\n Scheduler.layer(ctx.scheduler),\n StorageReader.layer(ctx.storage),\n StorageWriter.layer(ctx.storage),\n QueryRunner.layer(ctx.runQuery),\n MutationRunner.layer(ctx.runMutation),\n Layer.succeed(\n MutationCtx.MutationCtx<\n DataModel.ToConvex<DataModel.FromSchema<Schema>>\n >(),\n ctx,\n ),\n Layer.setConfigProvider(ConvexConfigProvider.make()),\n );\n\nexport type MutationServices<Schema extends DatabaseSchema.AnyWithProps> =\n | DatabaseReader.DatabaseReader<Schema>\n | DatabaseWriter.DatabaseWriter<Schema>\n | Auth.Auth\n | Scheduler.Scheduler\n | StorageReader\n | StorageWriter\n | QueryRunner.QueryRunner\n | MutationRunner.MutationRunner\n | MutationCtx.MutationCtx<DataModel.ToConvex<DataModel.FromSchema<Schema>>>;\n\nconst mutationFunction = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Args,\n ConvexArgs extends DefaultFunctionArgs,\n Returns,\n ConvexReturns,\n E,\n>({\n databaseSchema,\n args,\n returns,\n error,\n handler,\n}: {\n databaseSchema: DatabaseSchema_;\n args: Schema.Schema<Args, ConvexArgs>;\n returns: Schema.Schema<Returns, ConvexReturns>;\n error: Schema.Schema<Error, Value> | undefined;\n handler: (\n a: Args,\n ) => Effect.Effect<Returns, E, MutationServices<DatabaseSchema_>>;\n}) => ({\n args: SchemaToValidator.compileArgsSchema(args),\n returns: SchemaToValidator.compileReturnsSchema(returns),\n handler: (\n ctx: GenericMutationCtx<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >,\n actualArgs: ConvexArgs,\n ): Promise<ConvexReturns> =>\n Effect.gen(function* () {\n const decodedArgs = yield* pipe(\n actualArgs,\n Schema.decode(args),\n Effect.orDie,\n );\n const decodedReturns = yield* handler(decodedArgs).pipe(\n Effect.provide(mutationLayer(databaseSchema, ctx)),\n );\n return yield* pipe(decodedReturns, Schema.encode(returns), Effect.orDie);\n }).pipe(RegisteredFunction.runHandlerPromise(error)),\n});\n\nconst convexActionFunction = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Args,\n ConvexArgs extends DefaultFunctionArgs,\n Returns,\n ConvexReturns,\n E,\n>(\n schema: DatabaseSchema_,\n {\n args,\n returns,\n error,\n handler,\n }: {\n args: Schema.Schema<Args, ConvexArgs>;\n returns: Schema.Schema<Returns, ConvexReturns>;\n error: Schema.Schema.AnyNoContext | undefined;\n handler: (\n a: Args,\n ) => Effect.Effect<\n Returns,\n E,\n RegisteredFunction.ActionServices<DatabaseSchema_>\n >;\n },\n) =>\n RegisteredFunction.actionFunctionBase({\n args,\n returns,\n error,\n handler,\n createLayer: (ctx) =>\n Layer.mergeAll(\n RegisteredFunction.actionLayer(schema, ctx),\n Layer.setConfigProvider(ConvexConfigProvider.make()),\n ),\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAa,QACX,KACA,EAAE,cAAc,cAEhB,MAAM,MAAM,aAAa,mBAAmB,CAAC,KAC3C,MAAM,IAAI,gBAAgB,QAAkC,EAC5D,MAAM,IAAI,iBAAiB;CACzB,MAAM,EAAE,oBAAoB,uBAC1B;AAEF,QAAO,MAAM,MAAM,aAAa,uBAAuB,aAAa,CAAC,KACnE,MAAM,KAAK,eAAe;AAOxB,SANwB,MAAM,MAAM,mBAAmB,CAAC,KACtD,MAAM,KAAK,gBAAgB,aAAa,EACxC,MAAM,KAAK,kBAAkB,qBAAqB,EAClD,MAAM,WACP,CAGC,cAAc;GACZ,gBAAgB,IAAI;GACpB,MAAM,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ACA;CACA,cAAc,QACZ,MAAM,SACJC,YAA+B,QAAQ,IAAI,EAC3C,MAAM,kBAAkBR,QAA2B,CAAC,CACrD;CACJ,CAAC"}
|
|
@@ -70,10 +70,10 @@ declare const actionFunctionBase: <Schema extends AnyWithProps, Args, ConvexArgs
|
|
|
70
70
|
handler: (ctx: GenericActionCtx<ToConvex<FromSchema<Schema>>>, actualArgs: ConvexArgs) => Promise<ConvexReturns>;
|
|
71
71
|
};
|
|
72
72
|
type ActionServices<DatabaseSchema_ extends AnyWithProps> = Scheduler$1 | Auth$1 | StorageReader$1 | StorageWriter$1 | StorageActionWriter$1 | QueryRunner | MutationRunner | ActionRunner | VectorSearch<FromSchema<DatabaseSchema_>> | ActionCtx<ToConvex<FromSchema<DatabaseSchema_>>>;
|
|
73
|
-
declare const actionLayer: <DatabaseSchema_ extends AnyWithProps>(databaseSchema: DatabaseSchema_, ctx: GenericActionCtx<ToConvex<FromSchema<DatabaseSchema_>>>) => Layer.Layer<(<Action extends _confect_core_Ref0.AnyAction>(action: Action, ...args: _confect_core_Ref0.OptionalArgs<Action>) => Effect.Effect<_confect_core_Ref0.Returns<Action>, _confect_core_Ref0.Error<Action> | effect_ParseResult0.ParseError>) |
|
|
73
|
+
declare const actionLayer: <DatabaseSchema_ extends AnyWithProps>(databaseSchema: DatabaseSchema_, ctx: GenericActionCtx<ToConvex<FromSchema<DatabaseSchema_>>>) => Layer.Layer<StorageActionWriter$1 | StorageReader$1 | StorageWriter$1 | (<Action extends _confect_core_Ref0.AnyAction>(action: Action, ...args: _confect_core_Ref0.OptionalArgs<Action>) => Effect.Effect<_confect_core_Ref0.Returns<Action>, _confect_core_Ref0.Error<Action> | effect_ParseResult0.ParseError>) | (<Query extends _confect_core_Ref0.AnyQuery>(query: Query, ...args: _confect_core_Ref0.OptionalArgs<Query>) => Effect.Effect<_confect_core_Ref0.Returns<Query>, _confect_core_Ref0.Error<Query> | effect_ParseResult0.ParseError>) | Auth$1 | {
|
|
74
74
|
runAfter: <Ref_ extends _confect_core_Ref0.AnyMutation | _confect_core_Ref0.AnyAction>(delay: effect_Duration0.Duration, ref: Ref_, ...args: _confect_core_Ref0.OptionalArgs<Ref_>) => Effect.Effect<convex_values0.GenericId<"_scheduled_functions">, never, never>;
|
|
75
75
|
runAt: <Ref_ extends _confect_core_Ref0.AnyMutation | _confect_core_Ref0.AnyAction>(dateTime: effect_DateTime0.DateTime, ref: Ref_, ...args: _confect_core_Ref0.OptionalArgs<Ref_>) => Effect.Effect<convex_values0.GenericId<"_scheduled_functions">, never, never>;
|
|
76
|
-
} | (<Mutation extends _confect_core_Ref0.AnyMutation>(mutation: Mutation, ...args: _confect_core_Ref0.OptionalArgs<Mutation>) => Effect.Effect<_confect_core_Ref0.Returns<Mutation>, _confect_core_Ref0.Error<Mutation> | effect_ParseResult0.ParseError>) | GenericActionCtx<ToConvex<FromSchema<DatabaseSchema_>>> |
|
|
76
|
+
} | (<Mutation extends _confect_core_Ref0.AnyMutation>(mutation: Mutation, ...args: _confect_core_Ref0.OptionalArgs<Mutation>) => Effect.Effect<_confect_core_Ref0.Returns<Mutation>, _confect_core_Ref0.Error<Mutation> | effect_ParseResult0.ParseError>) | GenericActionCtx<ToConvex<FromSchema<DatabaseSchema_>>> | (<TableName extends TableNames<FromSchema<DatabaseSchema_>>, IndexName extends keyof convex_server0.VectorIndexes<convex_server0.NamedTableInfo<ToConvex<FromSchema<DatabaseSchema_>>, TableName>>>(tableName: TableName, indexName: IndexName, query: {
|
|
77
77
|
vector: number[];
|
|
78
78
|
limit?: number;
|
|
79
79
|
filter?: (q: convex_server0.VectorFilterBuilder<convex_server0.DocumentByInfo<convex_server0.NamedTableInfo<ToConvex<FromSchema<DatabaseSchema_>>, TableName>>, convex_server0.NamedVectorIndex<convex_server0.NamedTableInfo<ToConvex<FromSchema<DatabaseSchema_>>, TableName>, IndexName>>) => convex_server0.FilterExpression<boolean>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RegisteredFunction.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A,KAAS,UAAA,EAC3D,UAAA,KACX,OAAA,CAAQ,aAAA;AAAA;AAAA,KAcD,cAAA,yBACc,YAAA,IAEtB,WAAA,GACA,MAAA,GACA,eAAA,GACA,eAAA,GACA,qBAAA,GACA,WAAA,GACA,cAAA,GACA,YAAA,GACA,YAAA,CAA0B,UAAA,CAAqB,eAAA,KAC/C,SAAA,CACE,QAAA,CAAmB,UAAA,CAAqB,eAAA;AAAA,cAGjC,WAAA,2BACa,YAAA,EAExB,cAAA,EAAgB,eAAA,EAChB,GAAA,EAAK,gBAAA,CACH,QAAA,CAAmB,UAAA,CAAqB,eAAA,QACzC,KAAA,CAAA,KAAA,CAAA,qBAAA,GAAA,eAAA,GAAA,eAAA,oBAAA,kBAAA,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,KAAA,IAAA,EAAA,kBAAA,CAAA,YAAA,CAAA,MAAA,MAAA,MAAA,CAAA,MAAA,CAAA,kBAAA,CAAA,OAAA,CAAA,MAAA,GAAA,kBAAA,CAAA,KAAA,CAAA,MAAA,IAAA,mBAAA,CAAA,UAAA,qBAAA,kBAAA,CAAA,QAAA,EAAA,KAAA,EAAA,KAAA,KAAA,IAAA,EAAA,kBAAA,CAAA,YAAA,CAAA,KAAA,MAAA,MAAA,CAAA,MAAA,CAAA,kBAAA,CAAA,OAAA,CAAA,KAAA,GAAA,kBAAA,CAAA,KAAA,CAAA,KAAA,IAAA,mBAAA,CAAA,UAAA,KAAA,MAAA;0BAAA,kBAAA,CAAA,WAAA"}
|
|
@@ -32,19 +32,19 @@ type ValueTupleToValidatorTuple<VlTuple extends ReadonlyArray<ReadonlyValue>> =
|
|
|
32
32
|
declare const compileSchema: <T, E>(schema: Schema.Schema<T, E>) => ValueToValidator<(typeof schema)["Encoded"]>;
|
|
33
33
|
declare const isRecursive: (ast: SchemaAST.AST) => boolean;
|
|
34
34
|
declare const compileAst: (ast: SchemaAST.AST, isOptionalPropertyOfTypeLiteral?: boolean) => Effect.Effect<Validator<any, any, any>, UnsupportedSchemaTypeError | UnsupportedPropertySignatureKeyTypeError | IndexSignaturesAreNotSupportedError | MixedIndexAndPropertySignaturesAreNotSupportedError | OptionalTupleElementsAreNotSupportedError | EmptyTupleIsNotSupportedError>;
|
|
35
|
-
declare const TopLevelMustBeObjectError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.
|
|
35
|
+
declare const TopLevelMustBeObjectError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => Cause.YieldableError & {
|
|
36
36
|
readonly _tag: "TopLevelMustBeObjectError";
|
|
37
37
|
} & Readonly<A>;
|
|
38
38
|
declare class TopLevelMustBeObjectError extends TopLevelMustBeObjectError_base {
|
|
39
39
|
get message(): string;
|
|
40
40
|
}
|
|
41
|
-
declare const TopLevelMustBeObjectOrUnionError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.
|
|
41
|
+
declare const TopLevelMustBeObjectOrUnionError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => Cause.YieldableError & {
|
|
42
42
|
readonly _tag: "TopLevelMustBeObjectOrUnionError";
|
|
43
43
|
} & Readonly<A>;
|
|
44
44
|
declare class TopLevelMustBeObjectOrUnionError extends TopLevelMustBeObjectOrUnionError_base {
|
|
45
45
|
get message(): string;
|
|
46
46
|
}
|
|
47
|
-
declare const UnsupportedPropertySignatureKeyTypeError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.
|
|
47
|
+
declare const UnsupportedPropertySignatureKeyTypeError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => Cause.YieldableError & {
|
|
48
48
|
readonly _tag: "UnsupportedPropertySignatureKeyTypeError";
|
|
49
49
|
} & Readonly<A>;
|
|
50
50
|
declare class UnsupportedPropertySignatureKeyTypeError extends UnsupportedPropertySignatureKeyTypeError_base<{
|
|
@@ -52,13 +52,13 @@ declare class UnsupportedPropertySignatureKeyTypeError extends UnsupportedProper
|
|
|
52
52
|
}> {
|
|
53
53
|
get message(): string;
|
|
54
54
|
}
|
|
55
|
-
declare const EmptyTupleIsNotSupportedError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.
|
|
55
|
+
declare const EmptyTupleIsNotSupportedError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => Cause.YieldableError & {
|
|
56
56
|
readonly _tag: "EmptyTupleIsNotSupportedError";
|
|
57
57
|
} & Readonly<A>;
|
|
58
58
|
declare class EmptyTupleIsNotSupportedError extends EmptyTupleIsNotSupportedError_base {
|
|
59
59
|
get message(): string;
|
|
60
60
|
}
|
|
61
|
-
declare const UnsupportedSchemaTypeError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.
|
|
61
|
+
declare const UnsupportedSchemaTypeError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => Cause.YieldableError & {
|
|
62
62
|
readonly _tag: "UnsupportedSchemaTypeError";
|
|
63
63
|
} & Readonly<A>;
|
|
64
64
|
declare class UnsupportedSchemaTypeError extends UnsupportedSchemaTypeError_base<{
|
|
@@ -66,19 +66,19 @@ declare class UnsupportedSchemaTypeError extends UnsupportedSchemaTypeError_base
|
|
|
66
66
|
}> {
|
|
67
67
|
get message(): string;
|
|
68
68
|
}
|
|
69
|
-
declare const IndexSignaturesAreNotSupportedError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.
|
|
69
|
+
declare const IndexSignaturesAreNotSupportedError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => Cause.YieldableError & {
|
|
70
70
|
readonly _tag: "IndexSignaturesAreNotSupportedError";
|
|
71
71
|
} & Readonly<A>;
|
|
72
72
|
declare class IndexSignaturesAreNotSupportedError extends IndexSignaturesAreNotSupportedError_base {
|
|
73
73
|
get message(): string;
|
|
74
74
|
}
|
|
75
|
-
declare const MixedIndexAndPropertySignaturesAreNotSupportedError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.
|
|
75
|
+
declare const MixedIndexAndPropertySignaturesAreNotSupportedError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => Cause.YieldableError & {
|
|
76
76
|
readonly _tag: "MixedIndexAndPropertySignaturesAreNotSupportedError";
|
|
77
77
|
} & Readonly<A>;
|
|
78
78
|
declare class MixedIndexAndPropertySignaturesAreNotSupportedError extends MixedIndexAndPropertySignaturesAreNotSupportedError_base {
|
|
79
79
|
get message(): string;
|
|
80
80
|
}
|
|
81
|
-
declare const OptionalTupleElementsAreNotSupportedError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.
|
|
81
|
+
declare const OptionalTupleElementsAreNotSupportedError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => Cause.YieldableError & {
|
|
82
82
|
readonly _tag: "OptionalTupleElementsAreNotSupportedError";
|
|
83
83
|
} & Readonly<A>;
|
|
84
84
|
declare class OptionalTupleElementsAreNotSupportedError extends OptionalTupleElementsAreNotSupportedError_base {
|
|
@@ -25,7 +25,7 @@ declare const StorageActionWriter_base: effect_Context0.TagClass<StorageActionWr
|
|
|
25
25
|
store: (blob: Blob, options?: {
|
|
26
26
|
sha256?: string;
|
|
27
27
|
}) => Effect.Effect<GenericId<"_storage">, never, never>;
|
|
28
|
-
}) => X) => [X] extends [Effect.Effect<infer A, infer E, infer R>] ? Effect.Effect<A, E,
|
|
28
|
+
}) => X) => [X] extends [Effect.Effect<infer A, infer E, infer R>] ? Effect.Effect<A, E, StorageActionWriter | R> : [X] extends [PromiseLike<infer A_1>] ? Effect.Effect<A_1, effect_Cause0.UnknownException, StorageActionWriter> : Effect.Effect<X, never, StorageActionWriter>;
|
|
29
29
|
};
|
|
30
30
|
declare class StorageActionWriter extends StorageActionWriter_base {
|
|
31
31
|
static readonly layer: (storageActionWriter: StorageActionWriter$1) => Layer.Layer<StorageActionWriter, never, never>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@confect/server",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"description": "Backend bindings to the Convex platform",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -44,38 +44,38 @@
|
|
|
44
44
|
"license": "ISC",
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@ark/attest": "0.56.0",
|
|
47
|
-
"@effect/cluster": "0.
|
|
48
|
-
"@effect/experimental": "0.
|
|
49
|
-
"@effect/platform": "0.
|
|
50
|
-
"@effect/rpc": "0.
|
|
51
|
-
"@effect/sql": "0.
|
|
52
|
-
"@effect/vitest": "0.
|
|
53
|
-
"@effect/workflow": "0.
|
|
47
|
+
"@effect/cluster": "0.58.2",
|
|
48
|
+
"@effect/experimental": "0.60.0",
|
|
49
|
+
"@effect/platform": "0.96.1",
|
|
50
|
+
"@effect/rpc": "0.75.1",
|
|
51
|
+
"@effect/sql": "0.51.1",
|
|
52
|
+
"@effect/vitest": "0.29.0",
|
|
53
|
+
"@effect/workflow": "0.18.1",
|
|
54
54
|
"@eslint/js": "10.0.1",
|
|
55
55
|
"@swc/jest": "0.2.39",
|
|
56
56
|
"@types/node": "25.3.3",
|
|
57
57
|
"@vitest/coverage-v8": "3.2.4",
|
|
58
58
|
"convex-test": "0.0.50",
|
|
59
59
|
"dotenv": "17.3.1",
|
|
60
|
-
"effect": "3.
|
|
60
|
+
"effect": "3.21.2",
|
|
61
61
|
"eslint": "10.0.2",
|
|
62
62
|
"prettier": "3.8.1",
|
|
63
63
|
"tsdown": "0.20.3",
|
|
64
|
-
"tsx": "
|
|
64
|
+
"tsx": "4.21.0",
|
|
65
65
|
"typescript": "5.9.3",
|
|
66
66
|
"typescript-eslint": "8.56.1",
|
|
67
67
|
"vite": "7.3.1",
|
|
68
68
|
"vite-tsconfig-paths": "6.1.1",
|
|
69
69
|
"vitest": "3.2.4",
|
|
70
|
-
"@confect/cli": "
|
|
71
|
-
"@confect/test": "
|
|
70
|
+
"@confect/cli": "8.0.0",
|
|
71
|
+
"@confect/test": "8.0.0"
|
|
72
72
|
},
|
|
73
73
|
"peerDependencies": {
|
|
74
|
-
"@effect/platform": "^0.
|
|
75
|
-
"@effect/platform-node": "^0.
|
|
74
|
+
"@effect/platform": "^0.96.1",
|
|
75
|
+
"@effect/platform-node": "^0.106.0",
|
|
76
76
|
"convex": "^1.30.0",
|
|
77
|
-
"effect": "^3.
|
|
78
|
-
"@confect/core": "
|
|
77
|
+
"effect": "^3.21.2",
|
|
78
|
+
"@confect/core": "^8.0.0"
|
|
79
79
|
},
|
|
80
80
|
"engines": {
|
|
81
81
|
"node": ">=22",
|
|
@@ -88,11 +88,15 @@
|
|
|
88
88
|
"build": "tsdown --config-loader unrun",
|
|
89
89
|
"dev": "tsdown --watch",
|
|
90
90
|
"test": "vitest run",
|
|
91
|
+
"test:mock-backend": "vitest run --config vitest.mock-backend.config.ts",
|
|
92
|
+
"test:local-backend": "vitest run --config vitest.local-backend.config.ts",
|
|
93
|
+
"codegen:mock-backend": "cd test/mock-backend/fixtures && pnpm confect codegen && CONVEX_AGENT_MODE=anonymous pnpm convex dev --once --typecheck=disable --tail-logs=disable",
|
|
94
|
+
"codegen:local-backend": "cd test/local-backend/fixtures && pnpm confect codegen && CONVEX_AGENT_MODE=anonymous pnpm convex dev --once --typecheck=disable --tail-logs=disable",
|
|
91
95
|
"typecheck": "tsc --noEmit --project tsconfig.json",
|
|
92
96
|
"fix": "prettier --write . && eslint --fix . --max-warnings=0",
|
|
93
97
|
"format": "prettier --check .",
|
|
94
98
|
"lint": "eslint . --max-warnings=0",
|
|
95
|
-
"bench": "tsx test/SchemaToValidator.bench.ts",
|
|
99
|
+
"bench": "tsx test/SchemaToValidator.bench.ts && tsx test/Document.bench.ts",
|
|
96
100
|
"clean": "rm -rf dist coverage node_modules"
|
|
97
101
|
}
|
|
98
102
|
}
|
package/src/DatabaseSchema.ts
CHANGED
|
@@ -3,14 +3,15 @@ import {
|
|
|
3
3
|
defineSchema as defineConvexSchema,
|
|
4
4
|
type SchemaDefinition,
|
|
5
5
|
} from "convex/server";
|
|
6
|
-
import { Array, pipe,
|
|
6
|
+
import { Array, pipe, Record } from "effect";
|
|
7
7
|
import * as Table from "./Table";
|
|
8
|
+
import { TypeId } from "@confect/core/DatabaseSchema";
|
|
8
9
|
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
export {
|
|
11
|
+
type Any,
|
|
12
|
+
isDatabaseSchema,
|
|
13
|
+
TypeId,
|
|
14
|
+
} from "@confect/core/DatabaseSchema";
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* A schema definition tracks the schema and its Convex schema definition.
|
|
@@ -31,10 +32,6 @@ export interface DatabaseSchema<Tables_ extends Table.AnyWithProps = never> {
|
|
|
31
32
|
): DatabaseSchema<Tables_ | TableDef>;
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
export interface Any {
|
|
35
|
-
readonly [TypeId]: TypeId;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
35
|
export interface AnyWithProps {
|
|
39
36
|
readonly [TypeId]: TypeId;
|
|
40
37
|
readonly tables: Record<string, Table.AnyWithProps>;
|
package/src/Document.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import * as SystemFields from "@confect/core/SystemFields";
|
|
1
2
|
import { Effect, Function, ParseResult, pipe, Schema } from "effect";
|
|
2
3
|
import type { ReadonlyRecord } from "effect/Record";
|
|
3
|
-
import * as SystemFields from "@confect/core/SystemFields";
|
|
4
4
|
import type * as DataModel from "./DataModel";
|
|
5
5
|
import type { ReadonlyValue } from "./SchemaToValidator";
|
|
6
6
|
import type * as TableInfo from "./TableInfo";
|
|
@@ -10,6 +10,37 @@ export type WithoutSystemFields<Doc> = Omit<Doc, "_creationTime" | "_id">;
|
|
|
10
10
|
export type Any = any;
|
|
11
11
|
export type AnyEncoded = ReadonlyRecord<string, ReadonlyValue>;
|
|
12
12
|
|
|
13
|
+
type Decode = (doc: unknown) => Effect.Effect<unknown, ParseResult.ParseError>;
|
|
14
|
+
|
|
15
|
+
const decoderCache = new WeakMap<
|
|
16
|
+
Schema.Schema.AnyNoContext,
|
|
17
|
+
Map<string, Decode>
|
|
18
|
+
>();
|
|
19
|
+
|
|
20
|
+
const getDecoder = (
|
|
21
|
+
tableName: string,
|
|
22
|
+
tableSchema: Schema.Schema.AnyNoContext,
|
|
23
|
+
): Decode => {
|
|
24
|
+
const byTable =
|
|
25
|
+
decoderCache.get(tableSchema) ??
|
|
26
|
+
(() => {
|
|
27
|
+
const map = new Map<string, Decode>();
|
|
28
|
+
decoderCache.set(tableSchema, map);
|
|
29
|
+
return map;
|
|
30
|
+
})();
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
byTable.get(tableName) ??
|
|
34
|
+
(() => {
|
|
35
|
+
const decoder = Schema.decode(
|
|
36
|
+
SystemFields.extendWithSystemFields(tableName, tableSchema),
|
|
37
|
+
) as Decode;
|
|
38
|
+
byTable.set(tableName, decoder);
|
|
39
|
+
return decoder;
|
|
40
|
+
})()
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
|
|
13
44
|
export const decode = Function.dual<
|
|
14
45
|
<
|
|
15
46
|
DataModel_ extends DataModel.AnyWithProps,
|
|
@@ -53,36 +84,43 @@ export const decode = Function.dual<
|
|
|
53
84
|
DataModel.TableInfoWithName_<DataModel_, TableName>["document"],
|
|
54
85
|
DocumentDecodeError
|
|
55
86
|
> =>
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
),
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
return decodedDoc;
|
|
83
|
-
}),
|
|
87
|
+
pipe(
|
|
88
|
+
self,
|
|
89
|
+
getDecoder(tableName, tableSchema),
|
|
90
|
+
Effect.catchIf(ParseResult.isParseError, (parseError) =>
|
|
91
|
+
Effect.gen(function* () {
|
|
92
|
+
const formattedParseError =
|
|
93
|
+
yield* ParseResult.TreeFormatter.formatError(parseError);
|
|
94
|
+
|
|
95
|
+
return yield* new DocumentDecodeError({
|
|
96
|
+
tableName,
|
|
97
|
+
id: self._id,
|
|
98
|
+
parseError: formattedParseError,
|
|
99
|
+
});
|
|
100
|
+
}),
|
|
101
|
+
),
|
|
102
|
+
Effect.map(
|
|
103
|
+
(decodedDoc) =>
|
|
104
|
+
decodedDoc as DataModel.TableInfoWithName_<
|
|
105
|
+
DataModel_,
|
|
106
|
+
TableName
|
|
107
|
+
>["document"],
|
|
108
|
+
),
|
|
109
|
+
),
|
|
84
110
|
);
|
|
85
111
|
|
|
112
|
+
type Encode = (doc: unknown) => Effect.Effect<unknown, ParseResult.ParseError>;
|
|
113
|
+
|
|
114
|
+
const encoderCache = new WeakMap<Schema.Schema.AnyNoContext, Encode>();
|
|
115
|
+
|
|
116
|
+
const getEncoder = (tableSchema: Schema.Schema.AnyNoContext): Encode =>
|
|
117
|
+
encoderCache.get(tableSchema) ??
|
|
118
|
+
(() => {
|
|
119
|
+
const encoder = Schema.encode(tableSchema) as Encode;
|
|
120
|
+
encoderCache.set(tableSchema, encoder);
|
|
121
|
+
return encoder;
|
|
122
|
+
})();
|
|
123
|
+
|
|
86
124
|
export const encode = Function.dual<
|
|
87
125
|
<
|
|
88
126
|
DataModel_ extends DataModel.AnyWithProps,
|
|
@@ -126,35 +164,29 @@ export const encode = Function.dual<
|
|
|
126
164
|
DataModel.TableInfoWithName_<DataModel_, TableName>["encodedDocument"],
|
|
127
165
|
DocumentEncodeError
|
|
128
166
|
> =>
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}),
|
|
153
|
-
),
|
|
154
|
-
);
|
|
155
|
-
|
|
156
|
-
return encodedDoc;
|
|
157
|
-
}),
|
|
167
|
+
pipe(
|
|
168
|
+
self,
|
|
169
|
+
getEncoder(tableSchema),
|
|
170
|
+
Effect.catchIf(ParseResult.isParseError, (parseError) =>
|
|
171
|
+
Effect.gen(function* () {
|
|
172
|
+
const formattedParseError =
|
|
173
|
+
yield* ParseResult.TreeFormatter.formatError(parseError);
|
|
174
|
+
|
|
175
|
+
return yield* new DocumentEncodeError({
|
|
176
|
+
tableName,
|
|
177
|
+
id: self._id,
|
|
178
|
+
parseError: formattedParseError,
|
|
179
|
+
});
|
|
180
|
+
}),
|
|
181
|
+
),
|
|
182
|
+
Effect.map(
|
|
183
|
+
(encodedDoc) =>
|
|
184
|
+
encodedDoc as DataModel.TableInfoWithName_<
|
|
185
|
+
DataModel_,
|
|
186
|
+
TableName
|
|
187
|
+
>["encodedDocument"],
|
|
188
|
+
),
|
|
189
|
+
),
|
|
158
190
|
);
|
|
159
191
|
|
|
160
192
|
export class DocumentDecodeError extends Schema.TaggedError<DocumentDecodeError>()(
|
|
@@ -98,27 +98,28 @@ export const make = <Api_ extends Api.AnyWithPropsWithRuntime<"Convex">>(
|
|
|
98
98
|
Match.exhaustive,
|
|
99
99
|
);
|
|
100
100
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
101
|
+
/**
|
|
102
|
+
* Convex's query cache is invalidated by any Date.now() call during handler
|
|
103
|
+
* execution. Effect's unsafeFork calls Date.now() when constructing a
|
|
104
|
+
* FiberId.Runtime, which trips the cache for every confect-wrapped query. We
|
|
105
|
+
* stub Date.now to 0 for the span of the handler; queries are forbidden from
|
|
106
|
+
* relying on real time for correctness anyway.
|
|
107
|
+
*
|
|
108
|
+
* Users who explicitly want the real timestamp can still reach it via Effect's
|
|
109
|
+
* Clock service (Clock.currentTimeMillis/Clock.currentTimeNanos). We provide a
|
|
110
|
+
* Clock whose user-facing Effects call realDateNow (Convex's tracker) directly,
|
|
111
|
+
* making Clock an explicit opt-in to cache invalidation. The unsafe methods
|
|
112
|
+
* used internally by Effect (logging, span events, scheduler) return constants
|
|
113
|
+
* so they never touch the tracker—caching is not broken by default.
|
|
114
|
+
*/
|
|
111
115
|
const unpatchedClock = (realDateNow: () => number): Clock.Clock => {
|
|
112
|
-
const bigint1e6 = BigInt(1_000_000);
|
|
113
|
-
const unsafeCurrentTimeMillis = () => realDateNow();
|
|
114
|
-
const unsafeCurrentTimeNanos = () => BigInt(realDateNow()) * bigint1e6;
|
|
115
116
|
const defaultClock = Clock.make();
|
|
116
117
|
return {
|
|
117
118
|
...defaultClock,
|
|
118
|
-
unsafeCurrentTimeMillis,
|
|
119
|
-
unsafeCurrentTimeNanos,
|
|
120
|
-
currentTimeMillis: Effect.sync(
|
|
121
|
-
currentTimeNanos: Effect.sync(
|
|
119
|
+
unsafeCurrentTimeMillis: () => 0,
|
|
120
|
+
unsafeCurrentTimeNanos: () => 0n,
|
|
121
|
+
currentTimeMillis: Effect.sync(() => realDateNow()),
|
|
122
|
+
currentTimeNanos: Effect.sync(() => BigInt(realDateNow()) * 1_000_000n),
|
|
122
123
|
};
|
|
123
124
|
};
|
|
124
125
|
|