@gaganref/confect-server 10.3.1-fork.56 → 10.3.1-fork.58

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.
@@ -1,5 +1,5 @@
1
1
  import * as Callback from "@confect/core/Callback";
2
- import * as Ref from "@confect/core/Ref";
2
+ import type * as Ref from "@confect/core/Ref";
3
3
  import * as Effect from "effect/Effect";
4
4
  import * as Schema from "effect/Schema";
5
5
  declare const CallbackContractMismatch_base: Schema.Class<CallbackContractMismatch, Schema.TaggedStruct<"CallbackContractMismatch", {
@@ -1 +1 @@
1
- {"version":3,"file":"Callback.d.ts","sourceRoot":"","sources":["../src/Callback.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,wBAAwB,CAAC;AAEnD,OAAO,KAAK,GAAG,MAAM,mBAAmB,CAAC;AAQzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAOxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;;;;;;;AAGxC;;;;GAIG;AACH,qBAAa,wBAAyB,SAAQ,6BAQ7C;IACC,IAAa,OAAO,IAAI,MAAM,CAE7B;CACF;AAyPD;;;;;;;;;GASG;AACH,eAAO,MAAM,MAAM,GACjB,SAAS,SAAS,QAAQ,CAAC,GAAG,EAC9B,IAAI,SAAS,GAAG,CAAC,GAAG,iJAcpB,CAAC"}
1
+ {"version":3,"file":"Callback.d.ts","sourceRoot":"","sources":["../src/Callback.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,wBAAwB,CAAC;AAEnD,OAAO,KAAK,KAAK,GAAG,MAAM,mBAAmB,CAAC;AAS9C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAOxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;;;;;;;AAGxC;;;;GAIG;AACH,qBAAa,wBAAyB,SAAQ,6BAQ7C;IACC,IAAa,OAAO,IAAI,MAAM,CAE7B;CACF;AAyPD;;;;;;;;;GASG;AACH,eAAO,MAAM,MAAM,GACjB,SAAS,SAAS,QAAQ,CAAC,GAAG,EAC9B,IAAI,SAAS,GAAG,CAAC,GAAG,iJAcpB,CAAC"}
package/dist/Callback.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
2
  import { convexToJson, v } from "convex/values";
3
- import * as Ref from "@confect/core/Ref";
4
3
  import * as Effect from "effect/Effect";
5
4
  import * as MiddlewareSpec from "@confect/core/MiddlewareSpec";
6
5
  import * as Predicate from "effect/Predicate";
7
6
  import * as Array from "effect/Array";
7
+ import { getFunctionReference } from "@confect/core/RefInternal";
8
8
  import { createFunctionHandle } from "convex/server";
9
9
  import * as Schema from "effect/Schema";
10
10
  import { pipe } from "effect/Function";
@@ -173,7 +173,7 @@ const verify = (contract, ref) => {
173
173
  */
174
174
  const create = Effect.fn("Callback.create")(function* (contract, ref) {
175
175
  if (ref._tag === "Confect") yield* Effect.fromResult(verify(contract, ref));
176
- const text = yield* Effect.promise(() => createFunctionHandle(Ref.getFunctionReference(ref)));
176
+ const text = yield* Effect.promise(() => createFunctionHandle(getFunctionReference(ref)));
177
177
  return yield* Schema.decodeEffect(Callback.handle(contract))(text).pipe(Effect.orDie);
178
178
  });
179
179
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"Callback.js","names":[],"sources":["../src/Callback.ts"],"sourcesContent":["import * as Callback from \"@confect/core/Callback\";\nimport * as MiddlewareSpec from \"@confect/core/MiddlewareSpec\";\nimport * as Ref from \"@confect/core/Ref\";\nimport {\n compileAst,\n UnsupportedPropertySignatureKeyTypeError,\n} from \"@confect/core/SchemaToValidator\";\nimport { createFunctionHandle } from \"convex/server\";\nimport { convexToJson, v, type GenericValidator } from \"convex/values\";\nimport * as Array from \"effect/Array\";\nimport * as Effect from \"effect/Effect\";\nimport { pipe } from \"effect/Function\";\nimport * as Number from \"effect/Number\";\nimport * as Option from \"effect/Option\";\nimport * as Order from \"effect/Order\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Result from \"effect/Result\";\nimport * as Schema from \"effect/Schema\";\nimport * as SchemaAST from \"effect/SchemaAST\";\n\n/**\n * The host function does not satisfy the contract on one side. `expected` and\n * `actual` describe the contract's and the host's validators, with union\n * members in a fixed order, or the reason a schema is unsupported.\n */\nexport class CallbackContractMismatch extends Schema.TaggedError<CallbackContractMismatch>()(\n \"CallbackContractMismatch\",\n {\n contract: Schema.String,\n side: Schema.Literals([\"args\", \"returns\", \"error\"]),\n expected: Schema.Json,\n actual: Schema.Json,\n },\n) {\n override get message(): string {\n return `The host function does not satisfy callback contract \"${this.contract}\": its ${this.side === \"error\" ? \"errors\" : this.side} compile to ${JSON.stringify(this.actual)}, the contract's to ${JSON.stringify(this.expected)}.`;\n }\n}\n\nconst alternatives = (\n validator: GenericValidator,\n): ReadonlyArray<GenericValidator> =>\n validator.kind === \"union\"\n ? validator.members.flatMap(alternatives)\n : [validator];\n\nconst literalKinds: Record<string, string> = {\n string: \"string\",\n number: \"float64\",\n bigint: \"int64\",\n boolean: \"boolean\",\n};\n\n/**\n * The alternatives `validators` accept, without those another alternative\n * already covers: everything under `v.any()`, and a literal under its base\n * kind. `true` and `false` together are `v.boolean()`.\n */\nconst alternativesOf = (\n validators: ReadonlyArray<GenericValidator>,\n): ReadonlyArray<GenericValidator> => {\n const flat = validators.flatMap(alternatives);\n if (flat.some(({ kind }) => kind === \"any\")) {\n return [v.any()];\n }\n const booleans = new Set(\n flat.flatMap((validator) =>\n validator.kind === \"literal\" && typeof validator.value === \"boolean\"\n ? [validator.value]\n : [],\n ),\n );\n const widened =\n booleans.has(true) && booleans.has(false) ? [...flat, v.boolean()] : flat;\n const kinds = new Set<string>(widened.map(({ kind }) => kind));\n return widened.filter(\n (validator) =>\n validator.kind !== \"literal\" ||\n !kinds.has(literalKinds[typeof validator.value] ?? \"\"),\n );\n};\n\nconst keyed = (\n described: ReadonlyArray<Schema.Json>,\n): ReadonlyArray<readonly [string, Schema.Json]> =>\n pipe(\n described,\n Array.map((json) => [JSON.stringify(json), json] as const),\n Array.dedupeWith(([a], [b]) => a === b),\n Array.sortWith(([key]) => key, Order.String),\n );\n\n/**\n * The distinct alternatives `validators` accept, keyed by their description and\n * sorted by it, so union order and repetition do not count as differences.\n */\nconst membersOf = (validators: ReadonlyArray<GenericValidator>) =>\n keyed(alternativesOf(validators).map(describe));\n\nconst unionOf = (\n members: ReadonlyArray<readonly [string, Schema.Json]>,\n): Schema.Json => {\n const [only, ...rest] = members;\n return only !== undefined && rest.length === 0\n ? only[1]\n : { kind: \"union\", members: members.map(([, described]) => described) };\n};\n\nconst describe = (validator: GenericValidator): Schema.Json => {\n switch (validator.kind) {\n case \"id\":\n return { kind: \"id\", tableName: validator.tableName };\n case \"literal\":\n return { kind: \"literal\", value: convexToJson(validator.value) };\n case \"array\":\n return { kind: \"array\", element: describe(validator.element) };\n case \"record\":\n return {\n kind: \"record\",\n key: describe(validator.key),\n value: describe(validator.value),\n };\n case \"object\":\n return {\n kind: \"object\",\n fields: Object.fromEntries(\n pipe(\n Object.entries(validator.fields),\n Array.sortWith(([name]) => name, Order.String),\n Array.map(([name, field]) => [\n name,\n field.isOptional === \"optional\"\n ? { kind: \"optional\", value: describe(field) }\n : describe(field),\n ]),\n ),\n ),\n };\n case \"union\":\n return unionOf(membersOf([validator]));\n default:\n return { kind: validator.kind };\n }\n};\n\nconst ownError = (provenance: {\n readonly error?: Schema.Codec<any, any>;\n}): ReadonlyArray<Schema.Codec<any, any>> =>\n \"error\" in provenance && provenance.error !== undefined\n ? [provenance.error]\n : [];\n\nconst errorAlternatives = (schema: Schema.Top): ReadonlyArray<Schema.Top> =>\n SchemaAST.isUnion(schema.ast) &&\n Predicate.hasProperty(schema, \"members\") &&\n Array.isArray(schema.members)\n ? schema.members.flatMap((member) =>\n Schema.isSchema(member) ? errorAlternatives(member) : [],\n )\n : [schema];\n\n/**\n * Compile args field by field, as registration does, so a recursive field does\n * not widen the entire args object to `v.any()`.\n */\nconst compileArgs = (ast: SchemaAST.Objects): ReturnType<typeof compileAst> =>\n Effect.forEach(ast.propertySignatures, ({ name, type }) => {\n if (typeof name !== \"string\") {\n return Effect.fail(\n new UnsupportedPropertySignatureKeyTypeError({ propertyKey: name }),\n );\n }\n return Option.match(Number.parse(name), {\n onSome: (propertyKey) =>\n Effect.fail(\n new UnsupportedPropertySignatureKeyTypeError({ propertyKey }),\n ),\n onNone: () => {\n const optional = SchemaAST.isOptional(type);\n return compileAst(type, optional).pipe(\n Effect.map(\n (validator) =>\n [name, optional ? v.optional(validator) : validator] as const,\n ),\n );\n },\n });\n }).pipe(Effect.map((fields) => v.object(Object.fromEntries(fields))));\n\nconst compileSchema = (schema: Schema.Top, side?: \"args\" | \"returns\") => {\n const ast = Schema.toEncoded(schema).ast;\n return Effect.runSync(\n Effect.result(\n side === \"args\" && SchemaAST.isObjects(ast)\n ? compileArgs(ast)\n : compileAst(ast),\n ),\n );\n};\n\nconst describeCompiled = (\n compiled: ReadonlyArray<ReturnType<typeof compileSchema>>,\n): Schema.Json =>\n unionOf(\n keyed([\n ...membersOf(Array.getSuccesses(compiled)).map(([, json]) => json),\n ...Array.getFailures(compiled).map((error) => ({\n kind: \"unsupported\",\n reason: error.message,\n })),\n ]),\n );\n\n/**\n * Compare the validators Convex would compile for the contract and for the host\n * function, both in the application's ID scope, so a component's IDs are\n * strings on both sides and the host's own IDs stay `v.id`. A host that is\n * itself a component registers its own IDs as `v.id` in its scope, which this\n * check cannot see and compares as strings. Args and returns must be equal.\n * Every error the host may fail with, its middleware's included, must be one\n * the contract declares: the same schema, or one compiling to the same\n * validator. The host may declare fewer errors.\n */\nconst verify = (\n contract: Callback.Any,\n ref: Ref.AnyConfect,\n): Result.Result<void, CallbackContractMismatch> => {\n const mismatch = (\n side: CallbackContractMismatch[\"side\"],\n expected: Schema.Json,\n actual: Schema.Json,\n ) =>\n Result.fail(\n new CallbackContractMismatch({\n contract: contract.id,\n side,\n expected,\n actual,\n }),\n );\n const provenance = contract.functionProvenance;\n\n for (const side of [\"args\", \"returns\"] as const) {\n const expected = compileSchema(provenance[side], side);\n const actual = compileSchema(ref[side], side);\n const expectedDescription = describeCompiled([expected]);\n const actualDescription = describeCompiled([actual]);\n if (\n Result.isFailure(expected) ||\n Result.isFailure(actual) ||\n JSON.stringify(expectedDescription) !== JSON.stringify(actualDescription)\n ) {\n return mismatch(side, expectedDescription, actualDescription);\n }\n }\n\n const declared = ownError(provenance).flatMap(errorAlternatives);\n const undeclared = [\n ...ownError(ref),\n ...MiddlewareSpec.errorSchemas(ref.middlewareSpecs),\n ]\n .flatMap(errorAlternatives)\n .filter((schema) => !declared.includes(schema));\n if (undeclared.length > 0) {\n const expectedErrors = declared.map((schema) => compileSchema(schema));\n const actualErrors = undeclared.map((schema) => compileSchema(schema));\n const keys = new Set(\n membersOf(Array.getSuccesses(expectedErrors)).map(([key]) => key),\n );\n if (\n Array.getFailures(actualErrors).length > 0 ||\n !membersOf(Array.getSuccesses(actualErrors)).every(([key]) =>\n keys.has(key),\n )\n ) {\n return mismatch(\n \"error\",\n describeCompiled(expectedErrors),\n describeCompiled(actualErrors),\n );\n }\n }\n\n return Result.void;\n};\n\n/**\n * Create a handle a component can store and run to call `ref` under `contract`.\n * A ref whose function type, args or returns visibly differ from the contract\n * on the wire, or whose errors are undeclared, is a type error. The host may\n * declare fewer errors. Before asking Convex for the handle, a Confect ref's\n * compiled validators are checked against the contract's. A mismatch or an\n * unsupported schema fails with `CallbackContractMismatch`. A plain Convex ref\n * has no codecs to compile, so only the type check applies to it. A ref to a\n * function that is not deployed is a defect.\n */\nexport const create = Effect.fn(\"Callback.create\")(function* <\n Contract_ extends Callback.Any,\n Ref_ extends Ref.Any,\n>(\n contract: Contract_,\n ref: Ref_ & Callback.Check<Contract_, Ref_>,\n): Effect.fn.Return<Callback.Handle<Contract_>, CallbackContractMismatch> {\n if (ref._tag === \"Confect\") {\n yield* Effect.fromResult(verify(contract, ref));\n }\n const text = yield* Effect.promise(() =>\n create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K,IAAI,GAAG,CACd,GAEA,OAAO,SACL,SACA,iBAAiB,cAAc,GAC/B,iBAAiB,YAAY,CAC/B;CAEJ;CAEA,OAAO,OAAO;AAChB;;;;;;;;;;;AAYA,MAAa,SAAS,OAAO,GAAG,iBAAiB,CAAC,CAAC,WAIjD,UACA,KACwE;CACxE,IAAI,IAAI,SAAS,WACf,OAAO,OAAO,WAAW,OAAO,UAAU,GAAG,CAAC;CAEhD,MAAM,OAAO,OAAO,OAAO,cACzB,qBAAqB,IAAI,qBAAqB,GAAG,CAAC,CACpD;CACA,OAAO,OAAO,OAAO,aAAa,SAAS,OAAO,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,KACjE,OAAO,KACT;AACF,CAAC"}
1
+ {"version":3,"file":"Callback.js","names":[],"sources":["../src/Callback.ts"],"sourcesContent":["import * as Callback from \"@confect/core/Callback\";\nimport * as MiddlewareSpec from \"@confect/core/MiddlewareSpec\";\nimport type * as Ref from \"@confect/core/Ref\";\nimport { getFunctionReference } from \"@confect/core/RefInternal\";\nimport {\n compileAst,\n UnsupportedPropertySignatureKeyTypeError,\n} from \"@confect/core/SchemaToValidator\";\nimport { createFunctionHandle } from \"convex/server\";\nimport { convexToJson, v, type GenericValidator } from \"convex/values\";\nimport * as Array from \"effect/Array\";\nimport * as Effect from \"effect/Effect\";\nimport { pipe } from \"effect/Function\";\nimport * as Number from \"effect/Number\";\nimport * as Option from \"effect/Option\";\nimport * as Order from \"effect/Order\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Result from \"effect/Result\";\nimport * as Schema from \"effect/Schema\";\nimport * as SchemaAST from \"effect/SchemaAST\";\n\n/**\n * The host function does not satisfy the contract on one side. `expected` and\n * `actual` describe the contract's and the host's validators, with union\n * members in a fixed order, or the reason a schema is unsupported.\n */\nexport class CallbackContractMismatch extends Schema.TaggedError<CallbackContractMismatch>()(\n \"CallbackContractMismatch\",\n {\n contract: Schema.String,\n side: Schema.Literals([\"args\", \"returns\", \"error\"]),\n expected: Schema.Json,\n actual: Schema.Json,\n },\n) {\n override get message(): string {\n return `The host function does not satisfy callback contract \"${this.contract}\": its ${this.side === \"error\" ? \"errors\" : this.side} compile to ${JSON.stringify(this.actual)}, the contract's to ${JSON.stringify(this.expected)}.`;\n }\n}\n\nconst alternatives = (\n validator: GenericValidator,\n): ReadonlyArray<GenericValidator> =>\n validator.kind === \"union\"\n ? validator.members.flatMap(alternatives)\n : [validator];\n\nconst literalKinds: Record<string, string> = {\n string: \"string\",\n number: \"float64\",\n bigint: \"int64\",\n boolean: \"boolean\",\n};\n\n/**\n * The alternatives `validators` accept, without those another alternative\n * already covers: everything under `v.any()`, and a literal under its base\n * kind. `true` and `false` together are `v.boolean()`.\n */\nconst alternativesOf = (\n validators: ReadonlyArray<GenericValidator>,\n): ReadonlyArray<GenericValidator> => {\n const flat = validators.flatMap(alternatives);\n if (flat.some(({ kind }) => kind === \"any\")) {\n return [v.any()];\n }\n const booleans = new Set(\n flat.flatMap((validator) =>\n validator.kind === \"literal\" && typeof validator.value === \"boolean\"\n ? [validator.value]\n : [],\n ),\n );\n const widened =\n booleans.has(true) && booleans.has(false) ? [...flat, v.boolean()] : flat;\n const kinds = new Set<string>(widened.map(({ kind }) => kind));\n return widened.filter(\n (validator) =>\n validator.kind !== \"literal\" ||\n !kinds.has(literalKinds[typeof validator.value] ?? \"\"),\n );\n};\n\nconst keyed = (\n described: ReadonlyArray<Schema.Json>,\n): ReadonlyArray<readonly [string, Schema.Json]> =>\n pipe(\n described,\n Array.map((json) => [JSON.stringify(json), json] as const),\n Array.dedupeWith(([a], [b]) => a === b),\n Array.sortWith(([key]) => key, Order.String),\n );\n\n/**\n * The distinct alternatives `validators` accept, keyed by their description and\n * sorted by it, so union order and repetition do not count as differences.\n */\nconst membersOf = (validators: ReadonlyArray<GenericValidator>) =>\n keyed(alternativesOf(validators).map(describe));\n\nconst unionOf = (\n members: ReadonlyArray<readonly [string, Schema.Json]>,\n): Schema.Json => {\n const [only, ...rest] = members;\n return only !== undefined && rest.length === 0\n ? only[1]\n : { kind: \"union\", members: members.map(([, described]) => described) };\n};\n\nconst describe = (validator: GenericValidator): Schema.Json => {\n switch (validator.kind) {\n case \"id\":\n return { kind: \"id\", tableName: validator.tableName };\n case \"literal\":\n return { kind: \"literal\", value: convexToJson(validator.value) };\n case \"array\":\n return { kind: \"array\", element: describe(validator.element) };\n case \"record\":\n return {\n kind: \"record\",\n key: describe(validator.key),\n value: describe(validator.value),\n };\n case \"object\":\n return {\n kind: \"object\",\n fields: Object.fromEntries(\n pipe(\n Object.entries(validator.fields),\n Array.sortWith(([name]) => name, Order.String),\n Array.map(([name, field]) => [\n name,\n field.isOptional === \"optional\"\n ? { kind: \"optional\", value: describe(field) }\n : describe(field),\n ]),\n ),\n ),\n };\n case \"union\":\n return unionOf(membersOf([validator]));\n default:\n return { kind: validator.kind };\n }\n};\n\nconst ownError = (provenance: {\n readonly error?: Schema.Codec<any, any>;\n}): ReadonlyArray<Schema.Codec<any, any>> =>\n \"error\" in provenance && provenance.error !== undefined\n ? [provenance.error]\n : [];\n\nconst errorAlternatives = (schema: Schema.Top): ReadonlyArray<Schema.Top> =>\n SchemaAST.isUnion(schema.ast) &&\n Predicate.hasProperty(schema, \"members\") &&\n Array.isArray(schema.members)\n ? schema.members.flatMap((member) =>\n Schema.isSchema(member) ? errorAlternatives(member) : [],\n )\n : [schema];\n\n/**\n * Compile args field by field, as registration does, so a recursive field does\n * not widen the entire args object to `v.any()`.\n */\nconst compileArgs = (ast: SchemaAST.Objects): ReturnType<typeof compileAst> =>\n Effect.forEach(ast.propertySignatures, ({ name, type }) => {\n if (typeof name !== \"string\") {\n return Effect.fail(\n new UnsupportedPropertySignatureKeyTypeError({ propertyKey: name }),\n );\n }\n return Option.match(Number.parse(name), {\n onSome: (propertyKey) =>\n Effect.fail(\n new UnsupportedPropertySignatureKeyTypeError({ propertyKey }),\n ),\n onNone: () => {\n const optional = SchemaAST.isOptional(type);\n return compileAst(type, optional).pipe(\n Effect.map(\n (validator) =>\n [name, optional ? v.optional(validator) : validator] as const,\n ),\n );\n },\n });\n }).pipe(Effect.map((fields) => v.object(Object.fromEntries(fields))));\n\nconst compileSchema = (schema: Schema.Top, side?: \"args\" | \"returns\") => {\n const ast = Schema.toEncoded(schema).ast;\n return Effect.runSync(\n Effect.result(\n side === \"args\" && SchemaAST.isObjects(ast)\n ? compileArgs(ast)\n : compileAst(ast),\n ),\n );\n};\n\nconst describeCompiled = (\n compiled: ReadonlyArray<ReturnType<typeof compileSchema>>,\n): Schema.Json =>\n unionOf(\n keyed([\n ...membersOf(Array.getSuccesses(compiled)).map(([, json]) => json),\n ...Array.getFailures(compiled).map((error) => ({\n kind: \"unsupported\",\n reason: error.message,\n })),\n ]),\n );\n\n/**\n * Compare the validators Convex would compile for the contract and for the host\n * function, both in the application's ID scope, so a component's IDs are\n * strings on both sides and the host's own IDs stay `v.id`. A host that is\n * itself a component registers its own IDs as `v.id` in its scope, which this\n * check cannot see and compares as strings. Args and returns must be equal.\n * Every error the host may fail with, its middleware's included, must be one\n * the contract declares: the same schema, or one compiling to the same\n * validator. The host may declare fewer errors.\n */\nconst verify = (\n contract: Callback.Any,\n ref: Ref.AnyConfect,\n): Result.Result<void, CallbackContractMismatch> => {\n const mismatch = (\n side: CallbackContractMismatch[\"side\"],\n expected: Schema.Json,\n actual: Schema.Json,\n ) =>\n Result.fail(\n new CallbackContractMismatch({\n contract: contract.id,\n side,\n expected,\n actual,\n }),\n );\n const provenance = contract.functionProvenance;\n\n for (const side of [\"args\", \"returns\"] as const) {\n const expected = compileSchema(provenance[side], side);\n const actual = compileSchema(ref[side], side);\n const expectedDescription = describeCompiled([expected]);\n const actualDescription = describeCompiled([actual]);\n if (\n Result.isFailure(expected) ||\n Result.isFailure(actual) ||\n JSON.stringify(expectedDescription) !== JSON.stringify(actualDescription)\n ) {\n return mismatch(side, expectedDescription, actualDescription);\n }\n }\n\n const declared = ownError(provenance).flatMap(errorAlternatives);\n const undeclared = [\n ...ownError(ref),\n ...MiddlewareSpec.errorSchemas(ref.middlewareSpecs),\n ]\n .flatMap(errorAlternatives)\n .filter((schema) => !declared.includes(schema));\n if (undeclared.length > 0) {\n const expectedErrors = declared.map((schema) => compileSchema(schema));\n const actualErrors = undeclared.map((schema) => compileSchema(schema));\n const keys = new Set(\n membersOf(Array.getSuccesses(expectedErrors)).map(([key]) => key),\n );\n if (\n Array.getFailures(actualErrors).length > 0 ||\n !membersOf(Array.getSuccesses(actualErrors)).every(([key]) =>\n keys.has(key),\n )\n ) {\n return mismatch(\n \"error\",\n describeCompiled(expectedErrors),\n describeCompiled(actualErrors),\n );\n }\n }\n\n return Result.void;\n};\n\n/**\n * Create a handle a component can store and run to call `ref` under `contract`.\n * A ref whose function type, args or returns visibly differ from the contract\n * on the wire, or whose errors are undeclared, is a type error. The host may\n * declare fewer errors. Before asking Convex for the handle, a Confect ref's\n * compiled validators are checked against the contract's. A mismatch or an\n * unsupported schema fails with `CallbackContractMismatch`. A plain Convex ref\n * has no codecs to compile, so only the type check applies to it. A ref to a\n * function that is not deployed is a defect.\n */\nexport const create = Effect.fn(\"Callback.create\")(function* <\n Contract_ extends Callback.Any,\n Ref_ extends Ref.Any,\n>(\n contract: Contract_,\n ref: Ref_ & Callback.Check<Contract_, Ref_>,\n): Effect.fn.Return<Callback.Handle<Contract_>, CallbackContractMismatch> {\n if (ref._tag === \"Confect\") {\n yield* Effect.fromResult(verify(contract, ref));\n }\n const text = yield* Effect.promise(() =>\n createFunctionHandle(getFunctionReference(ref)),\n );\n return yield* Schema.decodeEffect(Callback.handle(contract))(text).pipe(\n Effect.orDie,\n );\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,IAAa,2BAAb,cAA8C,OAAO,YAAsC,CAAC,CAC1F,4BACA;CACE,UAAU,OAAO;CACjB,MAAM,OAAO,SAAS;EAAC;EAAQ;EAAW;CAAO,CAAC;CAClD,UAAU,OAAO;CACjB,QAAQ,OAAO;AACjB,CACF,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C"}
1
+ {"version":3,"file":"CronJobs.d.ts","sourceRoot":"","sources":["../src/CronJobs.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAA+B,KAAK,KAAK,EAAE,MAAM,eAAe,CAAC;AAGxE,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AAEpC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAM5C,OAAO,KAAK,KAAK,OAAO,MAAM,cAAc,CAAC;AAE7C,eAAO,MAAM,MAAM,8BAA8B,CAAC;AAClD,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC;AAEnC,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IACnD,QAAQ,CAAC,cAAc,EAAE,KAAK,CAAC;IAE/B,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,GAAG,QAAQ,CAAC;CACtC;AAED,eAAO,MAAM,UAAU,MAAO,OAAO,KAAG,CAAC,IAAI,QACX,CAAC;AAiDnC,eAAO,MAAM,IAAI,QAAO,QAA4C,CAAC;AAErE,eAAO,MAAM,sBAAsB,SAAU,IAAI,CAAC,IAAI,KAAG,MAwCxD,CAAC;AAYF,eAAO,MAAM,gCAAgC,aACjC,QAAQ,CAAC,QAAQ,KAC1B,gBA2BF,CAAC;AAEF,KAAK,gBAAgB,GAAG,OAAO,CAC7B,aAAa,CAAC,UAAU,CAAC,EACzB;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CACrB,CAAC"}
package/dist/CronJobs.js CHANGED
@@ -2,7 +2,7 @@ import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
2
  import * as Predicate from "effect/Predicate";
3
3
  import * as Array from "effect/Array";
4
4
  import * as Record from "effect/Record";
5
- import { Ref } from "@confect/core";
5
+ import { getFunctionReference } from "@confect/core/RefInternal";
6
6
  import * as DateTime from "effect/DateTime";
7
7
  import * as Duration from "effect/Duration";
8
8
  import { cronJobs } from "convex/server";
@@ -10,6 +10,7 @@ import { pipe } from "effect/Function";
10
10
  import * as Match from "effect/Match";
11
11
  import * as Option from "effect/Option";
12
12
  import * as Order from "effect/Order";
13
+ import { Ref } from "@confect/core";
13
14
  import * as Cron from "effect/Cron";
14
15
  //#region src/CronJobs.ts
15
16
  var CronJobs_exports = /* @__PURE__ */ __exportAll({
@@ -25,7 +26,7 @@ const Proto = {
25
26
  [TypeId]: TypeId,
26
27
  add(cronJob) {
27
28
  const newConvexCrons = Object.assign(cronJobs(), { crons: { ...this.convexCronJobs.crons } });
28
- const functionReference = Ref.getFunctionReference(cronJob.ref);
29
+ const functionReference = getFunctionReference(cronJob.ref);
29
30
  const encodedArgs = Ref.encodeArgsSync(cronJob.ref, cronJob.args);
30
31
  Match.value(cronJob.schedule).pipe(Match.when(Cron.isCron, (cron) => {
31
32
  newConvexCrons.cron(cronJob.identifier, cronToConvexCronString(cron), functionReference, encodedArgs);
@@ -1 +1 @@
1
- {"version":3,"file":"CronJobs.js","names":["makeConvexCrons"],"sources":["../src/CronJobs.ts"],"sourcesContent":["import { Ref } from \"@confect/core\";\nimport type { CronJob as ConvexCronJob } from \"convex/server\";\nimport { cronJobs as makeConvexCrons, type Crons } from \"convex/server\";\nimport { pipe } from \"effect/Function\";\nimport * as Array from \"effect/Array\";\nimport * as Cron from \"effect/Cron\";\nimport * as DateTime from \"effect/DateTime\";\nimport * as Duration from \"effect/Duration\";\nimport * as Match from \"effect/Match\";\nimport * as Option from \"effect/Option\";\nimport * as Order from \"effect/Order\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Record from \"effect/Record\";\nimport type * as CronJob from \"./CronJob.js\";\n\nexport const TypeId = \"~@confect/server/CronJobs\";\nexport type TypeId = typeof TypeId;\n\nexport interface CronJobs {\n readonly [TypeId]: TypeId;\n readonly cronJobs: Record<string, CronJob.CronJob>;\n readonly convexCronJobs: Crons;\n\n add(cron: CronJob.CronJob): CronJobs;\n}\n\nexport const isCronJobs = (u: unknown): u is CronJobs =>\n Predicate.hasProperty(u, TypeId);\n\nconst Proto = {\n [TypeId]: TypeId,\n\n add(this: CronJobs, cronJob: CronJob.CronJob) {\n const newConvexCrons = Object.assign(makeConvexCrons(), {\n crons: { ...this.convexCronJobs.crons },\n });\n\n const functionReference = Ref.getFunctionReference(cronJob.ref);\n const encodedArgs = Ref.encodeArgsSync(cronJob.ref, cronJob.args);\n\n Match.value(cronJob.schedule).pipe(\n Match.when(Cron.isCron, (cron) => {\n newConvexCrons.cron(\n cronJob.identifier,\n cronToConvexCronString(cron),\n functionReference,\n encodedArgs,\n );\n }),\n Match.when(Duration.isDuration, (duration) => {\n newConvexCrons.interval(\n cronJob.identifier,\n durationToConvexIntervalSchedule(duration),\n functionReference,\n encodedArgs,\n );\n }),\n Match.exhaustive,\n );\n\n return makeProto(\n Record.set(this.cronJobs, cronJob.identifier, cronJob),\n newConvexCrons,\n );\n },\n};\n\nconst makeProto = (\n cronJobs: Record<string, CronJob.CronJob>,\n convexCronJobs: Crons,\n): CronJobs =>\n Object.assign(Object.create(Proto), {\n cronJobs,\n convexCronJobs,\n });\n\nexport const make = (): CronJobs => makeProto({}, makeConvexCrons());\n\nexport const cronToConvexCronString = (cron: Cron.Cron): string => {\n pipe(\n cron.tz,\n Option.filter((tz) =>\n pipe(\n tz,\n Match.value,\n Match.tag(\"Offset\", ({ offset }) => offset !== 0),\n Match.tag(\"Named\", ({ id }) => id !== \"UTC\" && id !== \"Etc/UTC\"),\n Match.exhaustive,\n ),\n ),\n Option.map((tz) => {\n throw new Error(\n `Convex cron expressions are always evaluated in UTC, but this cron ` +\n `specifies the time zone \"${DateTime.zoneToString(tz)}\". ` +\n `Either omit the timezone or specify UTC.`,\n );\n }),\n );\n\n const hasNonDefaultSeconds = cron.seconds.size !== 1 || !cron.seconds.has(0);\n if (hasNonDefaultSeconds) {\n throw new Error(\n \"Convex cron expressions do not support a seconds field. \" +\n \"The seconds field must be the default {0}. \" +\n \"Sub-minute scheduling is supported only by interval schedules defined using a Duration.\",\n );\n }\n\n return Array.join(\n [\n setToField(cron.minutes),\n setToField(cron.hours),\n setToField(cron.days),\n setToField(cron.months),\n setToField(cron.weekdays),\n ],\n \" \",\n );\n};\n\nconst setToField = (set: ReadonlySet<number>): string => {\n if (set.size === 0) return \"*\";\n return pipe(\n set,\n Array.sort(Order.Number),\n Array.map((n) => n.toString()),\n Array.join(\",\"),\n );\n};\n\nexport const durationToConvexIntervalSchedule = (\n duration: Duration.Duration,\n): IntervalSchedule => {\n const millis = Duration.toMillis(duration);\n if (millis <= 0) {\n throw new Error(\"Interval must be a positive duration.\");\n }\n\n const oneHourInMillis = Duration.hours(1).pipe(Duration.toMillis);\n const hours = millis / oneHourInMillis;\n if (Number.isInteger(hours)) {\n return { type: \"interval\", hours };\n }\n\n const oneMinuteInMillis = Duration.minutes(1).pipe(Duration.toMillis);\n const minutes = millis / oneMinuteInMillis;\n if (Number.isInteger(minutes)) {\n return { type: \"interval\", minutes };\n }\n\n const oneSecondInMillis = Duration.seconds(1).pipe(Duration.toMillis);\n const seconds = millis / oneSecondInMillis;\n if (Number.isInteger(seconds)) {\n return { type: \"interval\", seconds };\n }\n\n throw new Error(\n \"Interval must be a whole number of seconds, minutes, or hours.\",\n );\n};\n\ntype IntervalSchedule = Extract<\n ConvexCronJob[\"schedule\"],\n { type: \"interval\" }\n>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAeA,MAAa,SAAS;AAWtB,MAAa,cAAc,MACzB,UAAU,YAAY,GAAG,MAAM;AAEjC,MAAM,QAAQ;EACX,SAAS;CAEV,IAAoB,SAA0B;EAC5C,MAAM,iBAAiB,OAAO,OAAOA,SAAgB,GAAG,EACtD,OAAO,EAAE,GAAG,KAAK,eAAe,MAAM,EACxC,CAAC;EAED,M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AG,OAAO;CAC3B,OAAO,KACL,KACA,MAAM,KAAK,MAAM,MAAM,GACvB,MAAM,KAAK,MAAM,EAAE,SAAS,CAAC,GAC7B,MAAM,KAAK,GAAG,CAChB;AACF;AAEA,MAAa,oCACX,aACqB;CACrB,MAAM,SAAS,SAAS,SAAS,QAAQ;CACzC,IAAI,UAAU,GACZ,MAAM,IAAI,MAAM,uCAAuC;CAIzD,MAAM,QAAQ,SADU,SAAS,MAAM,CAAC,CAAC,CAAC,KAAK,SAAS,QACnB;CACrC,IAAI,OAAO,UAAU,KAAK,GACxB,OAAO;EAAE,MAAM;EAAY;CAAM;CAInC,MAAM,UAAU,SADU,SAAS,QAAQ,CAAC,CAAC,CAAC,KAAK,SAAS,QACnB;CACzC,IAAI,OAAO,UAAU,OAAO,GAC1B,OAAO;EAAE,MAAM;EAAY;CAAQ;CAIrC,MAAM,UAAU,SADU,SAAS,QAAQ,CAAC,CAAC,CAAC,KAAK,SAAS,QACnB;CACzC,IAAI,OAAO,UAAU,OAAO,GAC1B,OAAO;EAAE,MAAM;EAAY;CAAQ;CAGrC,MAAM,IAAI,MACR,gEACF;AACF"}
1
+ {"version":3,"file":"CronJobs.js","names":["makeConvexCrons"],"sources":["../src/CronJobs.ts"],"sourcesContent":["import { Ref } from \"@confect/core\";\nimport { getFunctionReference } from \"@confect/core/RefInternal\";\nimport type { CronJob as ConvexCronJob } from \"convex/server\";\nimport { cronJobs as makeConvexCrons, type Crons } from \"convex/server\";\nimport { pipe } from \"effect/Function\";\nimport * as Array from \"effect/Array\";\nimport * as Cron from \"effect/Cron\";\nimport * as DateTime from \"effect/DateTime\";\nimport * as Duration from \"effect/Duration\";\nimport * as Match from \"effect/Match\";\nimport * as Option from \"effect/Option\";\nimport * as Order from \"effect/Order\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Record from \"effect/Record\";\nimport type * as CronJob from \"./CronJob.js\";\n\nexport const TypeId = \"~@confect/server/CronJobs\";\nexport type TypeId = typeof TypeId;\n\nexport interface CronJobs {\n readonly [TypeId]: TypeId;\n readonly cronJobs: Record<string, CronJob.CronJob>;\n readonly convexCronJobs: Crons;\n\n add(cron: CronJob.CronJob): CronJobs;\n}\n\nexport const isCronJobs = (u: unknown): u is CronJobs =>\n Predicate.hasProperty(u, TypeId);\n\nconst Proto = {\n [TypeId]: TypeId,\n\n add(this: CronJobs, cronJob: CronJob.CronJob) {\n const newConvexCrons = Object.assign(makeConvexCrons(), {\n crons: { ...this.convexCronJobs.crons },\n });\n\n const functionReference = getFunctionReference(cronJob.ref);\n const encodedArgs = Ref.encodeArgsSync(cronJob.ref, cronJob.args);\n\n Match.value(cronJob.schedule).pipe(\n Match.when(Cron.isCron, (cron) => {\n newConvexCrons.cron(\n cronJob.identifier,\n cronToConvexCronString(cron),\n functionReference,\n encodedArgs,\n );\n }),\n Match.when(Duration.isDuration, (duration) => {\n newConvexCrons.interval(\n cronJob.identifier,\n durationToConvexIntervalSchedule(duration),\n functionReference,\n encodedArgs,\n );\n }),\n Match.exhaustive,\n );\n\n return makeProto(\n Record.set(this.cronJobs, cronJob.identifier, cronJob),\n newConvexCrons,\n );\n },\n};\n\nconst makeProto = (\n cronJobs: Record<string, CronJob.CronJob>,\n convexCronJobs: Crons,\n): CronJobs =>\n Object.assign(Object.create(Proto), {\n cronJobs,\n convexCronJobs,\n });\n\nexport const make = (): CronJobs => makeProto({}, makeConvexCrons());\n\nexport const cronToConvexCronString = (cron: Cron.Cron): string => {\n pipe(\n cron.tz,\n Option.filter((tz) =>\n pipe(\n tz,\n Match.value,\n Match.tag(\"Offset\", ({ offset }) => offset !== 0),\n Match.tag(\"Named\", ({ id }) => id !== \"UTC\" && id !== \"Etc/UTC\"),\n Match.exhaustive,\n ),\n ),\n Option.map((tz) => {\n throw new Error(\n `Convex cron expressions are always evaluated in UTC, but this cron ` +\n `specifies the time zone \"${DateTime.zoneToString(tz)}\". ` +\n `Either omit the timezone or specify UTC.`,\n );\n }),\n );\n\n const hasNonDefaultSeconds = cron.seconds.size !== 1 || !cron.seconds.has(0);\n if (hasNonDefaultSeconds) {\n throw new Error(\n \"Convex cron expressions do not support a seconds field. \" +\n \"The seconds field must be the default {0}. \" +\n \"Sub-minute scheduling is supported only by interval schedules defined using a Duration.\",\n );\n }\n\n return Array.join(\n [\n setToField(cron.minutes),\n setToField(cron.hours),\n setToField(cron.days),\n setToField(cron.months),\n setToField(cron.weekdays),\n ],\n \" \",\n );\n};\n\nconst setToField = (set: ReadonlySet<number>): string => {\n if (set.size === 0) return \"*\";\n return pipe(\n set,\n Array.sort(Order.Number),\n Array.map((n) => n.toString()),\n Array.join(\",\"),\n );\n};\n\nexport const durationToConvexIntervalSchedule = (\n duration: Duration.Duration,\n): IntervalSchedule => {\n const millis = Duration.toMillis(duration);\n if (millis <= 0) {\n throw new Error(\"Interval must be a positive duration.\");\n }\n\n const oneHourInMillis = Duration.hours(1).pipe(Duration.toMillis);\n const hours = millis / oneHourInMillis;\n if (Number.isInteger(hours)) {\n return { type: \"interval\", hours };\n }\n\n const oneMinuteInMillis = Duration.minutes(1).pipe(Duration.toMillis);\n const minutes = millis / oneMinuteInMillis;\n if (Number.isInteger(minutes)) {\n return { type: \"interval\", minutes };\n }\n\n const oneSecondInMillis = Duration.seconds(1).pipe(Duration.toMillis);\n const seconds = millis / oneSecondInMillis;\n if (Number.isInteger(seconds)) {\n return { type: \"interval\", seconds };\n }\n\n throw new Error(\n \"Interval must be a whole number of seconds, minutes, or hours.\",\n );\n};\n\ntype IntervalSchedule = Extract<\n ConvexCronJob[\"schedule\"],\n { type: \"interval\" }\n>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgBA,MAAa,SAAS;AAWtB,MAAa,cAAc,MACzB,UAAU,YAAY,GAAG,MAAM;AAEjC,MAAM,QAAQ;EACX,SAAS;CAEV,IAAoB,SAA0B;EAC5C,MAAM,iBAAiB,OAAO,OAAOA,SAAgB,GAAG,EACtD,OAAO,EAAE,GAAG,KAAK,eAAe,MAAM,EACxC,CAAC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CAAC,CAAC,CAAC,CAAC,WACjB,iBAAiB,KACzB,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAanB,CAAC;AAEJ;;GAEG;AACH,eAAO,MAAM,WAAW,GACtB,CAAC,SAAS,GAAG,CAAC,UAAU,EACxB,CAAC,SAAS,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,OAEhD,CAAC,OACD,CAAC,SACC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAC7B,MAAM,CAAC,MAAM,CAAC,OAAO,CAMvB,CAAC"}
@@ -5,6 +5,7 @@ import { MutationCtx } from "./MutationCtx.js";
5
5
  import { QueryCtx } from "./QueryCtx.js";
6
6
  import * as Ref from "@confect/core/Ref";
7
7
  import * as Effect from "effect/Effect";
8
+ import { getFunctionReference } from "@confect/core/RefInternal";
8
9
  import * as Schema from "effect/Schema";
9
10
  import * as Option from "effect/Option";
10
11
  //#region src/OfficialComponent.ts
@@ -55,7 +56,7 @@ const make = (component, official) => {
55
56
  * method expects, with an explicit carrier policy.
56
57
  */
57
58
  const encodeCall = (ref, args, options) => (options.carrier === "forward" ? encodeArgs(ref, args) : Ref.encodeArgs(ref, args)).pipe(Effect.flatMap(Schema.decodeUnknownEffect(Schema.Record(Schema.String, Schema.Unknown))), Effect.map((encoded) => ({
58
- reference: Ref.getFunctionReference(ref),
59
+ reference: getFunctionReference(ref),
59
60
  args: encoded
60
61
  })), Effect.orDie);
61
62
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"OfficialComponent.js","names":["ActionCtx.ActionCtx","MutationCtx.MutationCtx","QueryCtx.QueryCtx","ReservedArgument.encodeArgs"],"sources":["../src/OfficialComponent.ts"],"sourcesContent":["import * as Ref from \"@confect/core/Ref\";\nimport type {\n DefaultFunctionArgs,\n GenericActionCtx,\n GenericDataModel,\n GenericMutationCtx,\n GenericQueryCtx,\n} from \"convex/server\";\nimport * as Effect from \"effect/Effect\";\nimport * as Option from \"effect/Option\";\nimport * as Schema from \"effect/Schema\";\nimport * as ActionCtx from \"./ActionCtx.js\";\nimport type * as ActionRunner from \"./ActionRunner.js\";\nimport * as MutationCtx from \"./MutationCtx.js\";\nimport type * as MutationRunner from \"./MutationRunner.js\";\nimport * as QueryCtx from \"./QueryCtx.js\";\nimport type * as QueryRunner from \"./QueryRunner.js\";\nimport * as ReservedArgument from \"./internal/reservedArgument.js\";\n\n/**\n * An official component's method rejected. `cause` is the rejection as thrown.\n */\nexport class ComponentCallFailed extends Schema.TaggedError<ComponentCallFailed>()(\n \"ComponentCallFailed\",\n { component: Schema.String, method: Schema.String, cause: Schema.Defect() },\n) {}\n\ndeclare const unsupported: unique symbol;\ntype Unsupported = typeof unsupported;\ntype Needs<Param> = [GenericActionCtx<GenericDataModel>] extends [Param]\n ? [GenericMutationCtx<GenericDataModel>] extends [Param]\n ? [GenericQueryCtx<GenericDataModel>] extends [Param]\n ? QueryRunner.QueryRunner\n : MutationRunner.MutationRunner\n : [GenericQueryCtx<GenericDataModel>] extends [Param]\n ? Unsupported\n : ActionRunner.ActionRunner\n : Unsupported;\n\ntype Method<Official> = {\n [K in keyof Official & string]: Official[K] extends (\n ctx: infer Ctx,\n ...args: infer _Args\n ) => Promise<unknown>\n ? Needs<Ctx> extends Unsupported\n ? never\n : K\n : never;\n}[keyof Official & string];\n\ntype Call<F> = F extends (\n ctx: infer Ctx,\n ...args: infer Args\n) => Promise<infer A>\n ? (...args: Args) => Effect.Effect<A, never, Needs<Ctx>>\n : never;\n\ntype Lifted<Official> = <M extends Method<Official>>(\n method: M,\n ...args: Parameters<Call<Official[M]>>\n) => ReturnType<Call<Official[M]>>;\n\n/**\n * Lift official promise methods, deriving each capability from its ctx\n * parameter. A rejection is caller misuse, a limit or a platform fault rather\n * than a domain fact, so it dies.\n */\nexport const make = <Official extends object>(\n component: string,\n official: Official,\n): Lifted<Official> => {\n const context = Effect.gen(function* () {\n const action = yield* Effect.serviceOption(\n ActionCtx.ActionCtx<GenericDataModel>(),\n );\n if (Option.isSome(action)) return action.value;\n const mutation = yield* Effect.serviceOption(\n MutationCtx.MutationCtx<GenericDataModel>(),\n );\n if (Option.isSome(mutation)) return mutation.value;\n const query = yield* Effect.serviceOption(\n QueryCtx.QueryCtx<GenericDataModel>(),\n );\n if (Option.isSome(query)) return query.value;\n return yield* Effect.die(\n new Error(`${component} called outside a Confect handler`),\n );\n });\n const call = Effect.fn(`${component}.call`)(function* (\n method: Method<Official>,\n ...args: unknown[]\n ) {\n const ctx = yield* context;\n // Method selects promise methods whose first argument accepts a native handler context.\n const invoke = official[method] as (\n native: typeof ctx,\n ...args: unknown[]\n ) => Promise<unknown>;\n return yield* Effect.tryPromise({\n try: () => invoke.call(official, ctx, ...args),\n catch: (cause) => ComponentCallFailed.make({ component, method, cause }),\n }).pipe(Effect.orDie);\n });\n // Confect installs the native ctx with the runner capability inferred by Needs.\n return call as unknown as Lifted<Official>;\n};\n\n/**\n * A function reference with its encoded arguments, ready for an official method\n * that takes both.\n */\nexport interface Fn<R extends Ref.Any> {\n readonly reference: Ref.FunctionReference<R>;\n readonly args: DefaultFunctionArgs;\n}\n\n/**\n * Choose whether an official component call forwards the caller's carrier.\n */\nexport interface EncodeCallOptions {\n /**\n * Forward the caller's carrier to reserving mutations and actions. Use `none`\n * when the component replays or compares the stored arguments.\n */\n readonly carrier: \"forward\" | \"none\";\n}\n\n/**\n * Encode a ref's arguments through its codecs to the wire record an official\n * method expects, with an explicit carrier policy.\n */\nexport const encodeCall = <R extends Ref.Any>(\n ref: R,\n args: NoInfer<Ref.Args<R>>,\n options: EncodeCallOptions,\n): Effect.Effect<Fn<R>> =>\n (options.carrier === \"forward\"\n ? ReservedArgument.encodeArgs(ref, args)\n : Ref.encodeArgs(ref, args)\n ).pipe(\n Effect.flatMap(\n Schema.decodeUnknownEffect(Schema.Record(Schema.String, Schema.Unknown)),\n ),\n Effect.map((encoded) => ({\n reference: Ref.getFunctionReference(ref),\n args: encoded,\n })),\n Effect.orDie,\n );\n\n/**\n * Encode a callback's real field without fabricating the rest of its arguments.\n */\nexport const encodeField = <\n R extends Ref.AnyConfect,\n K extends keyof Ref.Args<R> & keyof Ref.ArgsFields<R>,\n>(\n ref: R,\n key: K,\n value: NoInfer<Ref.Args<R>[K]>,\n): Effect.Effect<unknown> => {\n const fields = ref.args.fields as Record<\n keyof Ref.ArgsFields<R>,\n Schema.Codec<unknown, unknown>\n >;\n return Schema.encodeUnknownEffect(fields[key])(value).pipe(Effect.orDie);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAsBA,IAAa,sBAAb,cAAyC,OAAO,YAAiC,CAAC,CAChF,uBACA;CAAE,WAAW,OAAO;CAAQ,QAAQ,OAAO;CAAQ,OAAO,OAAO,OAAO;AAAE,CAC5E,CAAC,CAAC,CAAC;;;;;;AA0CH,MAAa,QACX,WACA,aACqB;CACrB,MAAM,UAAU,OAAO,IAAI,aAAa;EACtC,MAAM,SAAS,OAAO,OAAO,cAC3BA,UAAsC,CACxC;EACA,IAAI,OAAO,OAAO,MAAM,GAAG,OAAO,OAAO;EACzC,MAAM,WAAW,OAAO,OAAO,cAC7BC,YAA0C,CAC5C;EACA,IAAI,OAAO,OAAO,QAAQ,GAAG,OAAO,SAAS;EAC7C,MAAM,QAAQ,OAAO,OAAO,cAC1BC,SAAoC,CACtC;EACA,IAAI,OAAO,OAAO,KAAK,GAAG,OAAO,MAAM;EACvC,OAAO,OAAO,OAAO,oBACnB,IAAI,MAAM,GAAG,UAAU,kCAAkC,CAC3D;CACF,CAAC;CAiBD,OAhBa,OAAO,GAAG,GAAG,UAAU,MAAM,CAAC,CAAC,WAC1C,QACA,GAAG,MACH;EACA,MAAM,MAAM,OAAO;EAEnB,MAAM,SAAS,SAAS;EAIxB,OAAO,OAAO,OAAO,WAAW;GAC9B,WAAW,OAAO,KAAK,UAAU,KAAK,GAAG,IAAI;GAC7C,QAAQ,UAAU,oBAAoB,KAAK;IAAE;IAAW;IAAQ;GAAM,CAAC;EACzE,CAAC,CAAC,CAAC,KAAK,OAAO,KAAK;CACtB,CAEU;AACZ;;;;;AA0BA,MAAa,cACX,KACA,MACA,aAEC,QAAQ,YAAY,YACjBC,WAA4B,KAAK,IAAI,IACrC,IAAI,WAAW,KAAK,IAAI,EAAA,CAC1B,KACA,OAAO,QACL,OAAO,oBAAoB,OAAO,OAAO,OAAO,QAAQ,OAAO,OAAO,CAAC,CACzE,GACA,OAAO,KAAK,aAAa;CACvB,WAAW,IAAI,qBAAqB,GAAG;CACvC,MAAM;AACR,EAAE,GACF,OAAO,KACT;;;;AAKF,MAAa,eAIX,KACA,KACA,UAC2B;CAC3B,MAAM,SAAS,IAAI,KAAK;CAIxB,OAAO,OAAO,oBAAoB,OAAO,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,OAAO,KAAK;AACzE"}
1
+ {"version":3,"file":"OfficialComponent.js","names":["ActionCtx.ActionCtx","MutationCtx.MutationCtx","QueryCtx.QueryCtx","ReservedArgument.encodeArgs"],"sources":["../src/OfficialComponent.ts"],"sourcesContent":["import * as Ref from \"@confect/core/Ref\";\nimport { getFunctionReference } from \"@confect/core/RefInternal\";\nimport type {\n DefaultFunctionArgs,\n GenericActionCtx,\n GenericDataModel,\n GenericMutationCtx,\n GenericQueryCtx,\n} from \"convex/server\";\nimport * as Effect from \"effect/Effect\";\nimport * as Option from \"effect/Option\";\nimport * as Schema from \"effect/Schema\";\nimport * as ActionCtx from \"./ActionCtx.js\";\nimport type * as ActionRunner from \"./ActionRunner.js\";\nimport * as MutationCtx from \"./MutationCtx.js\";\nimport type * as MutationRunner from \"./MutationRunner.js\";\nimport * as QueryCtx from \"./QueryCtx.js\";\nimport type * as QueryRunner from \"./QueryRunner.js\";\nimport * as ReservedArgument from \"./internal/reservedArgument.js\";\n\n/**\n * An official component's method rejected. `cause` is the rejection as thrown.\n */\nexport class ComponentCallFailed extends Schema.TaggedError<ComponentCallFailed>()(\n \"ComponentCallFailed\",\n { component: Schema.String, method: Schema.String, cause: Schema.Defect() },\n) {}\n\ndeclare const unsupported: unique symbol;\ntype Unsupported = typeof unsupported;\ntype Needs<Param> = [GenericActionCtx<GenericDataModel>] extends [Param]\n ? [GenericMutationCtx<GenericDataModel>] extends [Param]\n ? [GenericQueryCtx<GenericDataModel>] extends [Param]\n ? QueryRunner.QueryRunner\n : MutationRunner.MutationRunner\n : [GenericQueryCtx<GenericDataModel>] extends [Param]\n ? Unsupported\n : ActionRunner.ActionRunner\n : Unsupported;\n\ntype Method<Official> = {\n [K in keyof Official & string]: Official[K] extends (\n ctx: infer Ctx,\n ...args: infer _Args\n ) => Promise<unknown>\n ? Needs<Ctx> extends Unsupported\n ? never\n : K\n : never;\n}[keyof Official & string];\n\ntype Call<F> = F extends (\n ctx: infer Ctx,\n ...args: infer Args\n) => Promise<infer A>\n ? (...args: Args) => Effect.Effect<A, never, Needs<Ctx>>\n : never;\n\ntype Lifted<Official> = <M extends Method<Official>>(\n method: M,\n ...args: Parameters<Call<Official[M]>>\n) => ReturnType<Call<Official[M]>>;\n\n/**\n * Lift official promise methods, deriving each capability from its ctx\n * parameter. A rejection is caller misuse, a limit or a platform fault rather\n * than a domain fact, so it dies.\n */\nexport const make = <Official extends object>(\n component: string,\n official: Official,\n): Lifted<Official> => {\n const context = Effect.gen(function* () {\n const action = yield* Effect.serviceOption(\n ActionCtx.ActionCtx<GenericDataModel>(),\n );\n if (Option.isSome(action)) return action.value;\n const mutation = yield* Effect.serviceOption(\n MutationCtx.MutationCtx<GenericDataModel>(),\n );\n if (Option.isSome(mutation)) return mutation.value;\n const query = yield* Effect.serviceOption(\n QueryCtx.QueryCtx<GenericDataModel>(),\n );\n if (Option.isSome(query)) return query.value;\n return yield* Effect.die(\n new Error(`${component} called outside a Confect handler`),\n );\n });\n const call = Effect.fn(`${component}.call`)(function* (\n method: Method<Official>,\n ...args: unknown[]\n ) {\n const ctx = yield* context;\n // Method selects promise methods whose first argument accepts a native handler context.\n const invoke = official[method] as (\n native: typeof ctx,\n ...args: unknown[]\n ) => Promise<unknown>;\n return yield* Effect.tryPromise({\n try: () => invoke.call(official, ctx, ...args),\n catch: (cause) => ComponentCallFailed.make({ component, method, cause }),\n }).pipe(Effect.orDie);\n });\n // Confect installs the native ctx with the runner capability inferred by Needs.\n return call as unknown as Lifted<Official>;\n};\n\n/**\n * A function reference with its encoded arguments, ready for an official method\n * that takes both.\n */\nexport interface Fn<R extends Ref.Any> {\n readonly reference: Ref.FunctionReference<R>;\n readonly args: DefaultFunctionArgs;\n}\n\n/**\n * Choose whether an official component call forwards the caller's carrier.\n */\nexport interface EncodeCallOptions {\n /**\n * Forward the caller's carrier to reserving mutations and actions. Use `none`\n * when the component replays or compares the stored arguments.\n */\n readonly carrier: \"forward\" | \"none\";\n}\n\n/**\n * Encode a ref's arguments through its codecs to the wire record an official\n * method expects, with an explicit carrier policy.\n */\nexport const encodeCall = <R extends Ref.Any>(\n ref: R,\n args: NoInfer<Ref.Args<R>>,\n options: EncodeCallOptions,\n): Effect.Effect<Fn<R>> =>\n (options.carrier === \"forward\"\n ? ReservedArgument.encodeArgs(ref, args)\n : Ref.encodeArgs(ref, args)\n ).pipe(\n Effect.flatMap(\n Schema.decodeUnknownEffect(Schema.Record(Schema.String, Schema.Unknown)),\n ),\n Effect.map((encoded) => ({\n reference: getFunctionReference(ref),\n args: encoded,\n })),\n Effect.orDie,\n );\n\n/**\n * Encode a callback's real field without fabricating the rest of its arguments.\n */\nexport const encodeField = <\n R extends Ref.AnyConfect,\n K extends keyof Ref.Args<R> & keyof Ref.ArgsFields<R>,\n>(\n ref: R,\n key: K,\n value: NoInfer<Ref.Args<R>[K]>,\n): Effect.Effect<unknown> => {\n const fields = ref.args.fields as Record<\n keyof Ref.ArgsFields<R>,\n Schema.Codec<unknown, unknown>\n >;\n return Schema.encodeUnknownEffect(fields[key])(value).pipe(Effect.orDie);\n};\n"],"mappings":";;;;;;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GACF,OAAO,KACT;;;;AAKF,MAAa,eAIX,KACA,KACA,UAC2B;CAC3B,MAAM,SAAS,IAAI,KAAK;CAIxB,OAAO,OAAO,oBAAoB,OAAO,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,OAAO,KAAK;AACzE"}
@@ -1,5 +1,5 @@
1
1
  import type * as IdScope from "@confect/core/IdScope";
2
- import { Ref } from "@confect/core";
2
+ import type { Ref } from "@confect/core";
3
3
  import type { GenericId } from "@confect/core/GenericId";
4
4
  import type { Scheduler as ConvexScheduler } from "convex/server";
5
5
  import type { GenericId as ConvexGenericId } from "convex/values";
@@ -1 +1 @@
1
- {"version":3,"file":"Scheduler.d.ts","sourceRoot":"","sources":["../src/Scheduler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,KAAK,EAAE,SAAS,IAAI,eAAe,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,KAAK,EAAE,SAAS,IAAI,eAAe,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAmCtC,eAAO,MAAM,SAAS;iBAhCP,eAAe,CAAC,sBAAsB,CAAC;eAGlD,IAAI,SAAS,GAAG,CAAC,WAAW,GAAG,GAAG,CAAC,SAAS;YAc5C,IAAI,SAAS,GAAG,CAAC,WAAW,GAAG,GAAG,CAAC,SAAS;;;;;EAiB/C,CAAC;AACF,MAAM,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC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IAAI,EAAE,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,GAC9B,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAC,CAAC;IAC3D,KAAK,CAAC,IAAI,SAAS,GAAG,CAAC,WAAW,GAAG,GAAG,CAAC,SAAS,EAChD,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAC3B,GAAG,EAAE,IAAI,EACT,GAAG,IAAI,EAAE,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,GAC9B,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAC,CAAC;CAC5D;AAED,MAAM,MAAM,QAAQ,CAAC,KAAK,SAAS,OAAO,CAAC,OAAO,IAAI,KAAK,SAAS,OAAO,CAAC,GAAG,GAC3E,SAAS,GACT;IAAE,QAAQ,CAAC,kBAAkB,EAAE,KAAK,CAAA;CAAE,CAAC;AAE3C,eAAO,MAAM,QAAQ,GACnB,KAAK,SAAS,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,GAAG,OACxC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CACN,CAAC;AAE/C,eAAO,MAAM,KAAK,GAAI,KAAK,SAAS,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,GAAG,aACpD,eAAe,WACjB,KAAK,+CAMb,CAAC"}
package/dist/Scheduler.js CHANGED
@@ -3,7 +3,7 @@ import { encodeArgs } from "./internal/reservedArgument.js";
3
3
  import * as Context from "effect/Context";
4
4
  import * as Effect from "effect/Effect";
5
5
  import * as Layer from "effect/Layer";
6
- import { Ref } from "@confect/core";
6
+ import { getFunctionReference } from "@confect/core/RefInternal";
7
7
  import * as DateTime from "effect/DateTime";
8
8
  import * as Duration from "effect/Duration";
9
9
  //#region src/Scheduler.ts
@@ -16,13 +16,13 @@ const make = (scheduler) => ({
16
16
  cancel: (id) => Effect.promise(() => scheduler.cancel(id)),
17
17
  runAfter: Effect.fn("Scheduler.runAfter")(function* (delay, ref, ...args) {
18
18
  const delayMs = Duration.toMillis(delay);
19
- const functionReference = Ref.getFunctionReference(ref);
19
+ const functionReference = getFunctionReference(ref);
20
20
  const encodedArgs = yield* encodeArgs(ref, args[0] ?? {});
21
21
  return yield* Effect.promise(() => scheduler.runAfter(delayMs, functionReference, encodedArgs));
22
22
  }),
23
23
  runAt: Effect.fn("Scheduler.runAt")(function* (dateTime, ref, ...args) {
24
24
  const timestamp = DateTime.toEpochMillis(dateTime);
25
- const functionReference = Ref.getFunctionReference(ref);
25
+ const functionReference = getFunctionReference(ref);
26
26
  const encodedArgs = yield* encodeArgs(ref, args[0] ?? {});
27
27
  return yield* Effect.promise(() => scheduler.runAt(timestamp, functionReference, encodedArgs));
28
28
  })
@@ -1 +1 @@
1
- {"version":3,"file":"Scheduler.js","names":["ReservedArgument.encodeArgs"],"sources":["../src/Scheduler.ts"],"sourcesContent":["import * as ReservedArgument from \"./internal/reservedArgument.js\";\nimport type * as IdScope from \"@confect/core/IdScope\";\nimport { Ref } from \"@confect/core\";\nimport type { GenericId } from \"@confect/core/GenericId\";\nimport type { Scheduler as ConvexScheduler } from \"convex/server\";\nimport type { GenericId as ConvexGenericId } from \"convex/values\";\nimport * as Context from \"effect/Context\";\nimport * as DateTime from \"effect/DateTime\";\nimport * as Duration from \"effect/Duration\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\n\nconst make = (scheduler: ConvexScheduler) => ({\n cancel: (id: ConvexGenericId<\"_scheduled_functions\">) =>\n Effect.promise(() => scheduler.cancel(id)),\n runAfter: Effect.fn(\"Scheduler.runAfter\")(function* <\n Ref_ extends Ref.AnyMutation | Ref.AnyAction,\n >(delay: Duration.Duration, ref: Ref_, ...args: Ref.OptionalArgs<Ref_>) {\n const delayMs = Duration.toMillis(delay);\n const functionReference = Ref.getFunctionReference(ref);\n const encodedArgs = yield* ReservedArgument.encodeArgs(\n ref,\n (args[0] ?? {}) as Ref.Args<Ref_>,\n );\n\n return yield* Effect.promise(() =>\n scheduler.runAfter(delayMs, functionReference, encodedArgs),\n );\n }),\n runAt: Effect.fn(\"Scheduler.runAt\")(function* <\n Ref_ extends Ref.AnyMutation | Ref.AnyAction,\n >(dateTime: DateTime.DateTime, ref: Ref_, ...args: Ref.OptionalArgs<Ref_>) {\n const timestamp = DateTime.toEpochMillis(dateTime);\n const functionReference = Ref.getFunctionReference(ref);\n const encodedArgs = yield* ReservedArgument.encodeArgs(\n ref,\n (args[0] ?? {}) as Ref.Args<Ref_>,\n );\n\n return yield* Effect.promise(() =>\n scheduler.runAt(timestamp, functionReference, encodedArgs),\n );\n }),\n});\n\nexport const Scheduler = Context.Service<ReturnType<typeof make>>(\n \"@confect/server/Scheduler\",\n);\nexport type Scheduler = typeof Scheduler.Identifier;\n\nexport interface Service<Scope extends IdScope.IdScope = IdScope.App> {\n cancel(id: GenericId<\"_scheduled_functions\", Scope>): Effect.Effect<void>;\n runAfter<Ref_ extends Ref.AnyMutation | Ref.AnyAction>(\n delay: Duration.Duration,\n ref: Ref_,\n ...args: Ref.OptionalArgs<Ref_>\n ): Effect.Effect<GenericId<\"_scheduled_functions\", Scope>>;\n runAt<Ref_ extends Ref.AnyMutation | Ref.AnyAction>(\n dateTime: DateTime.DateTime,\n ref: Ref_,\n ...args: Ref.OptionalArgs<Ref_>\n ): Effect.Effect<GenericId<\"_scheduled_functions\", Scope>>;\n}\n\nexport type ForScope<Scope extends IdScope.IdScope> = Scope extends IdScope.App\n ? Scheduler\n : { readonly \"~ScopedScheduler\": Scope };\n\nexport const forScope = <\n Scope extends IdScope.IdScope = IdScope.App,\n>(): Context.Service<ForScope<Scope>, Service<Scope>> =>\n Context.Service(\"@confect/server/Scheduler\");\n\nexport const layer = <Scope extends IdScope.IdScope = IdScope.App>(\n scheduler: ConvexScheduler,\n _scope?: Scope,\n) =>\n // Scopes are phantom: Convex still receives and returns the same ID strings.\n Layer.succeed(\n forScope<Scope>(),\n make(scheduler) as unknown as Service<Scope>,\n );\n"],"mappings":";;;;;;;;;;;;;;AAYA,MAAM,QAAQ,eAAgC;CAC5C,SAAS,OACP,OAAO,cAAc,UAAU,OAAO,EAAE,CAAC;CAC3C,UAAU,OAAO,GAAG,oBAAoB,CAAC,CAAC,WAExC,OAA0B,KAAW,GAAG,MAA8B;EACtE,MAAM,UAAU,SAAS,SAAS,KAAK;EACvC,MAAM,oBAAoB,IAAI,qBAAqB,GAAG;EACtD,MAAM,cAAc,OAAOA,WACzB,KACC,KAAK,MAAM,CAAC,CACf;EAEA,OAAO,OAAO,OAAO,cACnB,UAAU,SAAS,SAAS,mBAAmB,WAAW,CAC5D;CACF,CAAC;CACD,OAAO,OAAO,GAAG,iBAAiB,CAAC,CAAC,WAElC,UAA6B,KAAW,GAAG,MAA8B;EACzE,MAAM,YAAY,SAAS,cAAc,QAAQ;EACjD,MAAM,oBAAoB,IAAI,qBAAqB,GAAG;EACtD,MAAM,cAAc,OAAOA,WACzB,KACC,KAAK,MAAM,CAAC,CACf;EAEA,OAAO,OAAO,OAAO,cACnB,UAAU,MAAM,WAAW,mBAAmB,WAAW,CAC3D;CACF,CAAC;AACH;AAEA,MAAa,YAAY,QAAQ,QAC/B,2BACF;AAqBA,MAAa,iBAGX,QAAQ,QAAQ,2BAA2B;AAE7C,MAAa,SACX,WACA,WAGA,MAAM,QACJ,SAAgB,GAChB,KAAK,SAAS,CAChB"}
1
+ {"version":3,"file":"Scheduler.js","names":["ReservedArgument.encodeArgs"],"sources":["../src/Scheduler.ts"],"sourcesContent":["import * as ReservedArgument from \"./internal/reservedArgument.js\";\nimport type * as IdScope from \"@confect/core/IdScope\";\nimport type { Ref } from \"@confect/core\";\nimport { getFunctionReference } from \"@confect/core/RefInternal\";\nimport type { GenericId } from \"@confect/core/GenericId\";\nimport type { Scheduler as ConvexScheduler } from \"convex/server\";\nimport type { GenericId as ConvexGenericId } from \"convex/values\";\nimport * as Context from \"effect/Context\";\nimport * as DateTime from \"effect/DateTime\";\nimport * as Duration from \"effect/Duration\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\n\nconst make = (scheduler: ConvexScheduler) => ({\n cancel: (id: ConvexGenericId<\"_scheduled_functions\">) =>\n Effect.promise(() => scheduler.cancel(id)),\n runAfter: Effect.fn(\"Scheduler.runAfter\")(function* <\n Ref_ extends Ref.AnyMutation | Ref.AnyAction,\n >(delay: Duration.Duration, ref: Ref_, ...args: Ref.OptionalArgs<Ref_>) {\n const delayMs = Duration.toMillis(delay);\n const functionReference = getFunctionReference(ref);\n const encodedArgs = yield* ReservedArgument.encodeArgs(\n ref,\n (args[0] ?? {}) as Ref.Args<Ref_>,\n );\n\n return yield* Effect.promise(() =>\n scheduler.runAfter(delayMs, functionReference, encodedArgs),\n );\n }),\n runAt: Effect.fn(\"Scheduler.runAt\")(function* <\n Ref_ extends Ref.AnyMutation | Ref.AnyAction,\n >(dateTime: DateTime.DateTime, ref: Ref_, ...args: Ref.OptionalArgs<Ref_>) {\n const timestamp = DateTime.toEpochMillis(dateTime);\n const functionReference = getFunctionReference(ref);\n const encodedArgs = yield* ReservedArgument.encodeArgs(\n ref,\n (args[0] ?? {}) as Ref.Args<Ref_>,\n );\n\n return yield* Effect.promise(() =>\n scheduler.runAt(timestamp, functionReference, encodedArgs),\n );\n }),\n});\n\nexport const Scheduler = Context.Service<ReturnType<typeof make>>(\n \"@confect/server/Scheduler\",\n);\nexport type Scheduler = typeof Scheduler.Identifier;\n\nexport interface Service<Scope extends IdScope.IdScope = IdScope.App> {\n cancel(id: GenericId<\"_scheduled_functions\", Scope>): Effect.Effect<void>;\n runAfter<Ref_ extends Ref.AnyMutation | Ref.AnyAction>(\n delay: Duration.Duration,\n ref: Ref_,\n ...args: Ref.OptionalArgs<Ref_>\n ): Effect.Effect<GenericId<\"_scheduled_functions\", Scope>>;\n runAt<Ref_ extends Ref.AnyMutation | Ref.AnyAction>(\n dateTime: DateTime.DateTime,\n ref: Ref_,\n ...args: Ref.OptionalArgs<Ref_>\n ): Effect.Effect<GenericId<\"_scheduled_functions\", Scope>>;\n}\n\nexport type ForScope<Scope extends IdScope.IdScope> = Scope extends IdScope.App\n ? Scheduler\n : { readonly \"~ScopedScheduler\": Scope };\n\nexport const forScope = <\n Scope extends IdScope.IdScope = IdScope.App,\n>(): Context.Service<ForScope<Scope>, Service<Scope>> =>\n Context.Service(\"@confect/server/Scheduler\");\n\nexport const layer = <Scope extends IdScope.IdScope = IdScope.App>(\n scheduler: ConvexScheduler,\n _scope?: Scope,\n) =>\n // Scopes are phantom: Convex still receives and returns the same ID strings.\n Layer.succeed(\n forScope<Scope>(),\n make(scheduler) as unknown as Service<Scope>,\n );\n"],"mappings":";;;;;;;;;;;;;;AAaA,MAAM,QAAQ,eAAgC;CAC5C,SAAS,OACP,OAAO,cAAc,UAAU,OAAO,EAAE,CAAC;CAC3C,UAAU,OAAO,GAAG,oBAAoB,CAAC,CAAC,WAExC,OAA0B,KAAW,GAAG,MAA8B;EACtE,MAAM,UAAU,SAAS,SAAS,KAAK;EACvC,MAAM,oBAAoB,qBAAqB,GAAG;EAClD,MAAM,cAAc,OAAOA,WACzB,KACC,KAAK,MAAM,CAAC,CACf;EAEA,OAAO,OAAO,OAAO,cACnB,UAAU,SAAS,SAAS,mBAAmB,WAAW,CAC5D;CACF,CAAC;CACD,OAAO,OAAO,GAAG,iBAAiB,CAAC,CAAC,WAElC,UAA6B,KAAW,GAAG,MAA8B;EACzE,MAAM,YAAY,SAAS,cAAc,QAAQ;EACjD,MAAM,oBAAoB,qBAAqB,GAAG;EAClD,MAAM,cAAc,OAAOA,WACzB,KACC,KAAK,MAAM,CAAC,CACf;EAEA,OAAO,OAAO,OAAO,cACnB,UAAU,MAAM,WAAW,mBAAmB,WAAW,CAC3D;CACF,CAAC;AACH;AAEA,MAAa,YAAY,QAAQ,QAC/B,2BACF;AAqBA,MAAa,iBAGX,QAAQ,QAAQ,2BAA2B;AAE7C,MAAa,SACX,WACA,WAGA,MAAM,QACJ,SAAgB,GAChB,KAAK,SAAS,CAChB"}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@gaganref/confect-server",
3
- "version": "10.3.1-fork.56",
3
+ "version": "10.3.1-fork.58",
4
4
  "dependencies": {
5
5
  "@effect/ai-openai-compat": "4.0.4",
6
6
  "@effect/ai-openrouter": "4.0.4"
7
7
  },
8
8
  "peerDependencies": {
9
- "@confect/core": "npm:@gaganref/confect-core@10.3.1-fork.56",
9
+ "@confect/core": "npm:@gaganref/confect-core@10.3.1-fork.58",
10
10
  "@effect/platform-node": ">=4.0.0 <4.1.0",
11
11
  "convex": "^1.48.0",
12
12
  "effect": ">=4.0.4 <4.1.0"
package/src/Callback.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as Callback from "@confect/core/Callback";
2
2
  import * as MiddlewareSpec from "@confect/core/MiddlewareSpec";
3
- import * as Ref from "@confect/core/Ref";
3
+ import type * as Ref from "@confect/core/Ref";
4
+ import { getFunctionReference } from "@confect/core/RefInternal";
4
5
  import {
5
6
  compileAst,
6
7
  UnsupportedPropertySignatureKeyTypeError,
@@ -305,7 +306,7 @@ export const create = Effect.fn("Callback.create")(function* <
305
306
  yield* Effect.fromResult(verify(contract, ref));
306
307
  }
307
308
  const text = yield* Effect.promise(() =>
308
- createFunctionHandle(Ref.getFunctionReference(ref)),
309
+ createFunctionHandle(getFunctionReference(ref)),
309
310
  );
310
311
  return yield* Schema.decodeEffect(Callback.handle(contract))(text).pipe(
311
312
  Effect.orDie,
package/src/CronJobs.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Ref } from "@confect/core";
2
+ import { getFunctionReference } from "@confect/core/RefInternal";
2
3
  import type { CronJob as ConvexCronJob } from "convex/server";
3
4
  import { cronJobs as makeConvexCrons, type Crons } from "convex/server";
4
5
  import { pipe } from "effect/Function";
@@ -35,7 +36,7 @@ const Proto = {
35
36
  crons: { ...this.convexCronJobs.crons },
36
37
  });
37
38
 
38
- const functionReference = Ref.getFunctionReference(cronJob.ref);
39
+ const functionReference = getFunctionReference(cronJob.ref);
39
40
  const encodedArgs = Ref.encodeArgsSync(cronJob.ref, cronJob.args);
40
41
 
41
42
  Match.value(cronJob.schedule).pipe(
@@ -1,4 +1,5 @@
1
1
  import * as Ref from "@confect/core/Ref";
2
+ import { getFunctionReference } from "@confect/core/RefInternal";
2
3
  import type {
3
4
  DefaultFunctionArgs,
4
5
  GenericActionCtx,
@@ -142,7 +143,7 @@ export const encodeCall = <R extends Ref.Any>(
142
143
  Schema.decodeUnknownEffect(Schema.Record(Schema.String, Schema.Unknown)),
143
144
  ),
144
145
  Effect.map((encoded) => ({
145
- reference: Ref.getFunctionReference(ref),
146
+ reference: getFunctionReference(ref),
146
147
  args: encoded,
147
148
  })),
148
149
  Effect.orDie,
package/src/Scheduler.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as ReservedArgument from "./internal/reservedArgument.js";
2
2
  import type * as IdScope from "@confect/core/IdScope";
3
- import { Ref } from "@confect/core";
3
+ import type { Ref } from "@confect/core";
4
+ import { getFunctionReference } from "@confect/core/RefInternal";
4
5
  import type { GenericId } from "@confect/core/GenericId";
5
6
  import type { Scheduler as ConvexScheduler } from "convex/server";
6
7
  import type { GenericId as ConvexGenericId } from "convex/values";
@@ -17,7 +18,7 @@ const make = (scheduler: ConvexScheduler) => ({
17
18
  Ref_ extends Ref.AnyMutation | Ref.AnyAction,
18
19
  >(delay: Duration.Duration, ref: Ref_, ...args: Ref.OptionalArgs<Ref_>) {
19
20
  const delayMs = Duration.toMillis(delay);
20
- const functionReference = Ref.getFunctionReference(ref);
21
+ const functionReference = getFunctionReference(ref);
21
22
  const encodedArgs = yield* ReservedArgument.encodeArgs(
22
23
  ref,
23
24
  (args[0] ?? {}) as Ref.Args<Ref_>,
@@ -31,7 +32,7 @@ const make = (scheduler: ConvexScheduler) => ({
31
32
  Ref_ extends Ref.AnyMutation | Ref.AnyAction,
32
33
  >(dateTime: DateTime.DateTime, ref: Ref_, ...args: Ref.OptionalArgs<Ref_>) {
33
34
  const timestamp = DateTime.toEpochMillis(dateTime);
34
- const functionReference = Ref.getFunctionReference(ref);
35
+ const functionReference = getFunctionReference(ref);
35
36
  const encodedArgs = yield* ReservedArgument.encodeArgs(
36
37
  ref,
37
38
  (args[0] ?? {}) as Ref.Args<Ref_>,