@prisma-next/sql-relational-core 0.5.0-dev.7 → 0.5.0-dev.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +30 -0
  2. package/dist/{codec-types-DcEITed4.d.mts → codec-types-B2Xdq0Wr.d.mts} +43 -20
  3. package/dist/codec-types-B2Xdq0Wr.d.mts.map +1 -0
  4. package/dist/{errors-ChY_dHam.d.mts → errors-CDvhnH7P.d.mts} +2 -2
  5. package/dist/errors-CDvhnH7P.d.mts.map +1 -0
  6. package/dist/exports/ast.d.mts +2 -2
  7. package/dist/exports/ast.mjs +31 -6
  8. package/dist/exports/ast.mjs.map +1 -1
  9. package/dist/exports/errors.d.mts +4 -4
  10. package/dist/exports/plan.d.mts +3 -2
  11. package/dist/exports/plan.mjs.map +1 -1
  12. package/dist/exports/query-lane-context.d.mts +2 -2
  13. package/dist/exports/types.d.mts +5 -4
  14. package/dist/index.d.mts +8 -7
  15. package/dist/plan-CRPxW2Jj.d.mts +32 -0
  16. package/dist/plan-CRPxW2Jj.d.mts.map +1 -0
  17. package/dist/{query-lane-context-UlR8vOkd.d.mts → query-lane-context-DDRW5NBG.d.mts} +2 -2
  18. package/dist/{query-lane-context-UlR8vOkd.d.mts.map → query-lane-context-DDRW5NBG.d.mts.map} +1 -1
  19. package/dist/sql-execution-plan-DY0WvJOW.d.mts +33 -0
  20. package/dist/sql-execution-plan-DY0WvJOW.d.mts.map +1 -0
  21. package/dist/types-B5XsBeaT.d.mts +24 -0
  22. package/dist/types-B5XsBeaT.d.mts.map +1 -0
  23. package/dist/{types-k9pir8XY.d.mts → types-CG3u534i.d.mts} +12 -17
  24. package/dist/types-CG3u534i.d.mts.map +1 -0
  25. package/package.json +10 -10
  26. package/src/ast/codec-types.ts +91 -41
  27. package/src/exports/plan.ts +1 -0
  28. package/src/exports/types.ts +1 -0
  29. package/src/plan.ts +12 -11
  30. package/src/runtime-scope.ts +20 -0
  31. package/src/sql-execution-plan.ts +28 -0
  32. package/src/types.ts +9 -20
  33. package/dist/codec-types-DcEITed4.d.mts.map +0 -1
  34. package/dist/errors-ChY_dHam.d.mts.map +0 -1
  35. package/dist/plan-Cs65hb-E.d.mts +0 -28
  36. package/dist/plan-Cs65hb-E.d.mts.map +0 -1
  37. package/dist/types-k9pir8XY.d.mts.map +0 -1
package/README.md CHANGED
@@ -91,6 +91,36 @@ flowchart TD
91
91
  - Defines `SqlQueryPlan<Row>` interface for SQL query plans produced by lanes before lowering
92
92
  - Provides `augmentDescriptorWithColumnMeta(descriptors, columnMeta)` helper to update ParamDescriptor with `codecId` and `nativeType` from column metadata
93
93
 
94
+ ### Codec Factory (`ast/codec-types.ts` via `exports/ast.ts`)
95
+
96
+ - `codec({...})` is the SQL-side factory for constructing `Codec` values. It accepts `encode` and `decode` author functions in **either sync or async form** with no annotations; the constructed codec exposes Promise-returning query-time methods regardless of which form was used. `encode` may be omitted (identity default); `decode` is required.
97
+ - Build-time methods (`encodeJson`, `decodeJson`, `renderOutputType?`) are synchronous and pass through unchanged.
98
+ - This is the only public entry point for SQL codecs. There is no separate `codecSync` / `codecAsync` factory and no per-codec async marker on the resulting value.
99
+
100
+ ```ts
101
+ // Sync authoring:
102
+ const textCodec = codec({
103
+ typeId: 'pg/text@1',
104
+ targetTypes: ['text'],
105
+ encode: (v: string) => v,
106
+ decode: (w: string) => w,
107
+ encodeJson: (v: string) => v,
108
+ decodeJson: (j: string) => j as string,
109
+ });
110
+
111
+ // Async authoring (e.g. KMS-backed encryption): same factory, same shape.
112
+ const secretCodec = codec({
113
+ typeId: 'pg/secret@1',
114
+ targetTypes: ['text'],
115
+ encode: async (v: string) => encrypt(v, await getKey()),
116
+ decode: async (w: string) => decrypt(w, await getKey()),
117
+ encodeJson: (v: string) => v,
118
+ decodeJson: (j: string) => j as string,
119
+ });
120
+ ```
121
+
122
+ See [ADR 204 — Single-Path Async Codec Runtime](../../../../docs/architecture%20docs/adrs/ADR%20204%20-%20Single-Path%20Async%20Codec%20Runtime.md).
123
+
94
124
  ### AST Surface (`ast/*` via `exports/ast.ts`)
95
125
  - Query roots: `SelectAst`, `InsertAst`, `UpdateAst`, `DeleteAst`
96
126
  - Expressions: `ColumnRef`, `ParamRef`, `LiteralExpr`, `OperationExpr`, `ListExpression`
@@ -41,13 +41,15 @@ interface CodecMeta {
41
41
  };
42
42
  }
43
43
  /**
44
- * SQL codec interface — extends the framework base with SQL-specific fields.
44
+ * SQL codec — extends the framework codec base with SQL-specific metadata:
45
+ * driver-native type info (`meta.db.sql.<dialect>.nativeType`) and an
46
+ * optional parameterized-codec descriptor (`paramsSchema` + `init`) for
47
+ * codecs that require type-parameter validation (e.g. `pg/vector@1`).
45
48
  *
46
- * Codecs are pure, synchronous functions with no side effects or IO.
47
- * They provide deterministic conversion between database wire types and JS values,
48
- * and between JS values and contract JSON.
49
+ * See `Codec` in `@prisma-next/framework-components/codec` for the codec
50
+ * contract that this interface extends.
49
51
  */
50
- interface Codec$1<Id$1 extends string = string, TTraits$1 extends readonly CodecTrait[] = readonly CodecTrait[], TWire = unknown, TJs = unknown, TParams = Record<string, unknown>, THelper = unknown> extends Codec<Id$1, TTraits$1, TWire, TJs> {
52
+ interface Codec$1<Id$1 extends string = string, TTraits$1 extends readonly CodecTrait[] = readonly CodecTrait[], TWire = unknown, TInput = unknown, TParams = Record<string, unknown>, THelper = unknown> extends Codec<Id$1, TTraits$1, TWire, TInput> {
51
53
  readonly meta?: CodecMeta;
52
54
  readonly paramsSchema?: Type<TParams>;
53
55
  readonly init?: (params: TParams) => THelper;
@@ -74,37 +76,58 @@ interface CodecRegistry {
74
76
  values(): IterableIterator<Codec$1<string>>;
75
77
  }
76
78
  /**
77
- * Codec factory - creates a codec with typeId and encode/decode functions.
78
- * Provides identity defaults for encodeJson/decodeJson when not supplied.
79
+ * Conditional bundle for `encodeJson`/`decodeJson`: when `TInput` is
80
+ * structurally assignable to `JsonValue` the identity defaults are
81
+ * sound and both fields are optional; otherwise both fields are
82
+ * required so an author cannot silently produce a non-JSON-safe
83
+ * contract artifact.
79
84
  */
80
- declare function codec<Id$1 extends string, const TTraits$1 extends readonly CodecTrait[], TWire, TJs, TParams = Record<string, unknown>, THelper = unknown>(config: {
85
+ type JsonRoundTripConfig<TInput> = [TInput] extends [JsonValue] ? {
86
+ encodeJson?: (value: TInput) => JsonValue;
87
+ decodeJson?: (json: JsonValue) => TInput;
88
+ } : {
89
+ encodeJson: (value: TInput) => JsonValue;
90
+ decodeJson: (json: JsonValue) => TInput;
91
+ };
92
+ /**
93
+ * Construct a SQL codec from author functions and optional metadata.
94
+ *
95
+ * Author `encode` and `decode` as sync or async functions; the factory
96
+ * produces a {@link Codec} whose query-time methods follow the boundary
97
+ * contract documented on `Codec`.
98
+ *
99
+ * `encode` is optional — when omitted, an identity default is installed
100
+ * (declaring "the input value already is the wire value", so `TInput` and
101
+ * `TWire` are interchangeable for that codec). `decode` is always
102
+ * required. `encodeJson` and `decodeJson` default to identity **only when
103
+ * `TInput` is assignable to `JsonValue`**; otherwise both are required
104
+ * so the contract artifact stays JSON-safe.
105
+ */
106
+ declare function codec<Id$1 extends string, const TTraits$1 extends readonly CodecTrait[] = readonly [], TWire = unknown, TInput = unknown, TParams = Record<string, unknown>, THelper = unknown>(config: {
81
107
  typeId: Id$1;
82
108
  targetTypes: readonly string[];
83
- encode: (value: TJs) => TWire;
84
- decode: (wire: TWire) => TJs;
85
- encodeJson?: (value: TJs) => JsonValue;
86
- decodeJson?: (json: JsonValue) => TJs;
109
+ encode?: (value: TInput) => TWire | Promise<TWire>;
110
+ decode: (wire: TWire) => TInput | Promise<TInput>;
87
111
  meta?: CodecMeta;
88
112
  paramsSchema?: Type<TParams>;
89
113
  init?: (params: TParams) => THelper;
90
114
  traits?: TTraits$1;
91
115
  renderOutputType?: (typeParams: Record<string, unknown>) => string | undefined;
92
- }): Codec$1<Id$1, TTraits$1, TWire, TJs, TParams, THelper>;
116
+ } & JsonRoundTripConfig<TInput>): Codec$1<Id$1, TTraits$1, TWire, TInput, TParams, THelper>;
93
117
  /**
94
118
  * Type helpers to extract codec types.
95
119
  */
96
120
  type CodecId<T> = T extends Codec$1<infer Id> ? Id : T extends {
97
121
  readonly id: infer Id;
98
122
  } ? Id : never;
99
- type CodecInput<T> = T extends Codec$1<string, readonly CodecTrait[], unknown, infer JsT> ? JsT : never;
100
- type CodecOutput<T> = T extends Codec$1<string, readonly CodecTrait[], unknown, infer JsT> ? JsT : never;
123
+ type CodecInput<T> = T extends Codec$1<string, readonly CodecTrait[], unknown, infer In> ? In : never;
101
124
  type CodecTraits<T> = T extends Codec$1<string, infer TTraits> ? TTraits[number] & CodecTrait : never;
102
125
  /**
103
126
  * Type helper to extract codec types from builder instance.
104
127
  */
105
128
  type ExtractCodecTypes<ScalarNames extends { readonly [K in keyof ScalarNames]: Codec$1<string> } = Record<never, never>> = { readonly [K in keyof ScalarNames as ScalarNames[K] extends Codec$1<infer Id> ? Id : never]: {
106
129
  readonly input: CodecInput<ScalarNames[K]>;
107
- readonly output: CodecOutput<ScalarNames[K]>;
130
+ readonly output: CodecInput<ScalarNames[K]>;
108
131
  readonly traits: CodecTraits<ScalarNames[K]>;
109
132
  } };
110
133
  /**
@@ -126,8 +149,8 @@ interface CodecDefBuilder<ScalarNames extends { readonly [K in keyof ScalarNames
126
149
  readonly scalar: K;
127
150
  readonly codec: ScalarNames[K];
128
151
  readonly input: CodecInput<ScalarNames[K]>;
129
- readonly output: CodecOutput<ScalarNames[K]>;
130
- readonly jsType: CodecOutput<ScalarNames[K]>;
152
+ readonly output: CodecInput<ScalarNames[K]>;
153
+ readonly jsType: CodecInput<ScalarNames[K]>;
131
154
  } };
132
155
  readonly dataTypes: { readonly [K in keyof ScalarNames]: { readonly [Id in keyof ExtractCodecTypes<Record<K, ScalarNames[K]>>]: Id }[keyof ExtractCodecTypes<Record<K, ScalarNames[K]>>] };
133
156
  }
@@ -140,5 +163,5 @@ declare function createCodecRegistry(): CodecRegistry;
140
163
  */
141
164
  declare function defineCodecs(): CodecDefBuilder<Record<never, never>>;
142
165
  //#endregion
143
- export { CodecMeta as a, CodecRegistry as c, ExtractCodecTypes as d, ExtractDataTypes as f, defineCodecs as h, CodecInput as i, CodecTrait$1 as l, createCodecRegistry as m, CodecDefBuilder as n, CodecOutput as o, codec as p, CodecId as r, CodecParamsDescriptor as s, Codec$1 as t, CodecTraits as u };
144
- //# sourceMappingURL=codec-types-DcEITed4.d.mts.map
166
+ export { CodecMeta as a, CodecTrait$1 as c, ExtractDataTypes as d, codec as f, CodecInput as i, CodecTraits as l, defineCodecs as m, CodecDefBuilder as n, CodecParamsDescriptor as o, createCodecRegistry as p, CodecId as r, CodecRegistry as s, Codec$1 as t, ExtractCodecTypes as u };
167
+ //# sourceMappingURL=codec-types-B2Xdq0Wr.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codec-types-B2Xdq0Wr.d.mts","names":[],"sources":["../src/ast/codec-types.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAeA;;;;;;AAe8C,UAf7B,qBAe6B,CAAA,UAfG,MAeH,CAAA,MAAA,EAAA,OAAA,CAAA,EAAA,UAAA,OAAA,CAAA,CAAA;EAO7B;EAmBA,SAAA,OAAK,EAAA,MAAA;EAEK;;;;EAKH,SAAA,YAAA,EAxCC,IAwCD,CAxCM,OAwCN,CAAA;EAAS;;;;;EAGN,SAAA,IAAA,CAAA,EAAA,CAAA,MAAA,EApCA,OAoCA,EAAA,GApCY,OAoCZ;;;;AAW3B;;AAGwC,UA3CvB,SAAA,CA2CuB;EACL,SAAA,EAAA,CAAA,EAAA;IACjB,SAAA,GAAA,CAAA,EAAA;MAEiB,SAAA,QAAA,CAAA,EAAA;QAEG,SAAA,UAAA,EAAA,MAAA;MACN,CAAA;IAAT,CAAA;EACM,CAAA;;;AAC5B;;;;;;;;AA2GoC,UA5IpB,OA4IoB,CAAA,aAAA,MAAA,GAAA,MAAA,EAAA,kBAAA,SA1IV,UA0IU,EAAA,G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AAA,EAAX,UAAW,CAAA,WAAA,CAAY,CAAZ,CAAA,CAAA;EAAY,CAAA,EAAvB;EAKE,SAAA,SAAA,EAAA,iBAC4B,MAD5B,WAC4B,GAAA,kBAAG,MAA5B,iBAA4B,CAAV,MAAU,CAAH,CAAG,EAAA,WAAA,CAAY,CAAZ,CAAA,CAAA,CAAA,GAAmB,EAAnB,EAAY,CAAA,MACxD,iBADwD,CACtC,MADsC,CAC/B,CAD+B,EAC5B,WAD4B,CAChB,CADgB,CAAA,CAAA,CAAA,CAAA,EAAtB;;;;;AACM,iBAyHpC,mBAAA,CAAA,CAzHoC,EAyHb,aAzHa;;;;AAyHpC,iBAOA,YAAA,CAAA,CAPmB,EAOH,eAPoB,CAOJ,MAPI,CAAA,KAAA,EAAA,KAAA,CAAA,CAAA"}
@@ -1,8 +1,8 @@
1
- import { b as RuntimeError } from "./types-k9pir8XY.mjs";
1
+ import { y as RuntimeError } from "./types-CG3u534i.mjs";
2
2
 
3
3
  //#region src/errors.d.ts
4
4
  declare function planInvalid(message: string, details?: Record<string, unknown>, hints?: readonly string[], docs?: readonly string[]): RuntimeError;
5
5
  declare function planUnsupported(message: string, details?: Record<string, unknown>, hints?: readonly string[], docs?: readonly string[]): RuntimeError;
6
6
  //#endregion
7
7
  export { planUnsupported as n, planInvalid as t };
8
- //# sourceMappingURL=errors-ChY_dHam.d.mts.map
8
+ //# sourceMappingURL=errors-CDvhnH7P.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors-CDvhnH7P.d.mts","names":[],"sources":["../src/errors.ts"],"sourcesContent":[],"mappings":";;;iBAEgB,WAAA,4BAEJ,+EAGT;iBAkBa,eAAA,4BAEJ,+EAGT"}
@@ -1,4 +1,4 @@
1
- import { a as CodecMeta, c as CodecRegistry, d as ExtractCodecTypes, f as ExtractDataTypes, h as defineCodecs, i as CodecInput, l as CodecTrait, m as createCodecRegistry, n as CodecDefBuilder, o as CodecOutput, p as codec, r as CodecId, s as CodecParamsDescriptor, t as Codec, u as CodecTraits } from "../codec-types-DcEITed4.mjs";
1
+ import { a as CodecMeta, c as CodecTrait, d as ExtractDataTypes, f as codec, i as CodecInput, l as CodecTraits, m as defineCodecs, n as CodecDefBuilder, o as CodecParamsDescriptor, p as createCodecRegistry, r as CodecId, s as CodecRegistry, t as Codec, u as ExtractCodecTypes } from "../codec-types-B2Xdq0Wr.mjs";
2
2
  import { $ as ToWhereExpr, A as InsertOnConflict, B as NotExpr, C as ExistsExpr, D as ExpressionSource, E as ExpressionRewriter, F as JsonObjectEntry, G as ParamRef, H as OperationExpr, I as JsonObjectExpr, J as SelectAst, K as ProjectionExpr, L as ListExpression, M as JoinAst, N as JoinOnExpr, O as IdentifierRef, P as JsonArrayAggExpr, Q as TableSource, R as LiteralExpr, S as EqColJoinOn, T as ExpressionFolder, U as OrExpr, V as NullCheckExpr, W as OrderByItem, X as SubqueryExpr, Y as SelectAstOptions, Z as TableRef, _ as DeleteAst, a as AndExpr, at as whereExprKinds, b as DoNothingConflictAction, c as AnyInsertOnConflictAction, d as AnyQueryAst, et as UpdateAst, f as AstRewriter, g as DefaultValueExpr, h as ColumnRef, i as AggregateOpFn, it as queryAstKinds, j as InsertValue, k as InsertAst, l as AnyInsertValue, m as BinaryOp, n as AggregateExpr, nt as isQueryAst, o as AnyExpression, p as BinaryExpr, q as ProjectionItem, r as AggregateFn, rt as isWhereExpr, s as AnyFromSource, t as AggregateCountFn, tt as WhereArg, u as AnyOperationArg, v as DerivedTableSource, w as ExprVisitor, x as DoUpdateSetConflictAction, y as Direction, z as LoweredStatement } from "../types-C3Hg-CVz.mjs";
3
3
 
4
4
  //#region src/ast/adapter-types.d.ts
@@ -186,5 +186,5 @@ type SqlCodecTypes = typeof codecs.CodecTypes;
186
186
  //#region src/ast/util.d.ts
187
187
  declare function compact<T extends Record<string, unknown>>(o: T): T;
188
188
  //#endregion
189
- export { Adapter, AdapterProfile, AdapterTarget, AggregateCountFn, AggregateExpr, AggregateFn, AggregateOpFn, AndExpr, AnyExpression, AnyFromSource, AnyInsertOnConflictAction, AnyInsertValue, AnyOperationArg, AnyQueryAst, AstRewriter, BinaryExpr, BinaryOp, Codec, CodecDefBuilder, CodecId, CodecInput, CodecMeta, CodecOutput, CodecParamsDescriptor, CodecRegistry, CodecTrait, CodecTraits, ColumnRef, DefaultValueExpr, DeleteAst, DerivedTableSource, Direction, DoNothingConflictAction, DoUpdateSetConflictAction, EqColJoinOn, ExistsExpr, ExprVisitor, ExpressionFolder, ExpressionRewriter, ExpressionSource, ExtractCodecTypes, ExtractDataTypes, IdentifierRef, InsertAst, InsertOnConflict, InsertValue, JoinAst, JoinOnExpr, JsonArrayAggExpr, JsonObjectEntry, JsonObjectExpr, ListExpression, LiteralExpr, LoweredStatement, Lowerer, LowererContext, MarkerStatement, NotExpr, NullCheckExpr, OperationExpr, OrExpr, OrderByItem, ParamRef, ProjectionExpr, ProjectionItem, SQL_CHAR_CODEC_ID, SQL_FLOAT_CODEC_ID, SQL_INT_CODEC_ID, SQL_TEXT_CODEC_ID, SQL_TIMESTAMP_CODEC_ID, SQL_VARCHAR_CODEC_ID, SelectAst, SelectAstOptions, SqlCodecTypes, SqlConnection, SqlDriver, SqlDriverState, SqlExecuteRequest, SqlExplainResult, SqlQueryResult, SqlQueryable, SqlTransaction, SubqueryExpr, TableRef, TableSource, ToWhereExpr, UpdateAst, WhereArg, codec, compact, createCodecRegistry, defineCodecs, isQueryAst, isWhereExpr, queryAstKinds, sqlCodecDefinitions, sqlDataTypes, whereExprKinds };
189
+ export { Adapter, AdapterProfile, AdapterTarget, AggregateCountFn, AggregateExpr, AggregateFn, AggregateOpFn, AndExpr, AnyExpression, AnyFromSource, AnyInsertOnConflictAction, AnyInsertValue, AnyOperationArg, AnyQueryAst, AstRewriter, BinaryExpr, BinaryOp, Codec, CodecDefBuilder, CodecId, CodecInput, CodecMeta, CodecParamsDescriptor, CodecRegistry, CodecTrait, CodecTraits, ColumnRef, DefaultValueExpr, DeleteAst, DerivedTableSource, Direction, DoNothingConflictAction, DoUpdateSetConflictAction, EqColJoinOn, ExistsExpr, ExprVisitor, ExpressionFolder, ExpressionRewriter, ExpressionSource, ExtractCodecTypes, ExtractDataTypes, IdentifierRef, InsertAst, InsertOnConflict, InsertValue, JoinAst, JoinOnExpr, JsonArrayAggExpr, JsonObjectEntry, JsonObjectExpr, ListExpression, LiteralExpr, LoweredStatement, Lowerer, LowererContext, MarkerStatement, NotExpr, NullCheckExpr, OperationExpr, OrExpr, OrderByItem, ParamRef, ProjectionExpr, ProjectionItem, SQL_CHAR_CODEC_ID, SQL_FLOAT_CODEC_ID, SQL_INT_CODEC_ID, SQL_TEXT_CODEC_ID, SQL_TIMESTAMP_CODEC_ID, SQL_VARCHAR_CODEC_ID, SelectAst, SelectAstOptions, SqlCodecTypes, SqlConnection, SqlDriver, SqlDriverState, SqlExecuteRequest, SqlExplainResult, SqlQueryResult, SqlQueryable, SqlTransaction, SubqueryExpr, TableRef, TableSource, ToWhereExpr, UpdateAst, WhereArg, codec, compact, createCodecRegistry, defineCodecs, isQueryAst, isWhereExpr, queryAstKinds, sqlCodecDefinitions, sqlDataTypes, whereExprKinds };
190
190
  //# sourceMappingURL=ast.d.mts.map
@@ -73,11 +73,24 @@ var CodecRegistryImpl = class {
73
73
  }
74
74
  };
75
75
  /**
76
- * Codec factory - creates a codec with typeId and encode/decode functions.
77
- * Provides identity defaults for encodeJson/decodeJson when not supplied.
76
+ * Construct a SQL codec from author functions and optional metadata.
77
+ *
78
+ * Author `encode` and `decode` as sync or async functions; the factory
79
+ * produces a {@link Codec} whose query-time methods follow the boundary
80
+ * contract documented on `Codec`.
81
+ *
82
+ * `encode` is optional — when omitted, an identity default is installed
83
+ * (declaring "the input value already is the wire value", so `TInput` and
84
+ * `TWire` are interchangeable for that codec). `decode` is always
85
+ * required. `encodeJson` and `decodeJson` default to identity **only when
86
+ * `TInput` is assignable to `JsonValue`**; otherwise both are required
87
+ * so the contract artifact stays JSON-safe.
78
88
  */
79
89
  function codec(config) {
80
90
  const identity = (v) => v;
91
+ const userEncode = config.encode ?? ((value) => value);
92
+ const userDecode = config.decode;
93
+ const widenedConfig = config;
81
94
  return {
82
95
  id: config.typeId,
83
96
  targetTypes: config.targetTypes,
@@ -86,10 +99,22 @@ function codec(config) {
86
99
  ...ifDefined("init", config.init),
87
100
  ...ifDefined("traits", config.traits ? Object.freeze([...config.traits]) : void 0),
88
101
  ...ifDefined("renderOutputType", config.renderOutputType),
89
- encode: config.encode,
90
- decode: config.decode,
91
- encodeJson: config.encodeJson ?? identity,
92
- decodeJson: config.decodeJson ?? identity
102
+ encode: (value) => {
103
+ try {
104
+ return Promise.resolve(userEncode(value));
105
+ } catch (error) {
106
+ return Promise.reject(error);
107
+ }
108
+ },
109
+ decode: (wire) => {
110
+ try {
111
+ return Promise.resolve(userDecode(wire));
112
+ } catch (error) {
113
+ return Promise.reject(error);
114
+ }
115
+ },
116
+ encodeJson: widenedConfig.encodeJson ?? identity,
117
+ decodeJson: widenedConfig.decodeJson ?? identity
93
118
  };
94
119
  }
95
120
  /**