prisma-effect-kysely 5.7.0 → 5.9.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 +70 -0
- package/dist/effect/generator.d.ts.map +1 -1
- package/dist/effect/generator.js +5 -4
- package/dist/effect/generator.js.map +1 -1
- package/dist/kysely/type.d.ts +12 -10
- package/dist/kysely/type.d.ts.map +1 -1
- package/dist/kysely/type.js +13 -11
- package/dist/kysely/type.js.map +1 -1
- package/dist/utils/type-mappings.d.ts +12 -9
- package/dist/utils/type-mappings.d.ts.map +1 -1
- package/dist/utils/type-mappings.js +11 -8
- package/dist/utils/type-mappings.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,75 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 5.9.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 5f07c8f: fix: regular tables in DB interface use `Schema.Schema.Type`, join tables use `Schema.Schema.Encoded`
|
|
8
|
+
|
|
9
|
+
5.7.0 flipped the DB interface to `Schema.Schema.Encoded` for **all** tables to fix the join-table column-name bug (`_product_tags.product_id` was decoded-name; SQL needs `A`). That was the right fix for join tables but accidentally **stripped branded IDs** for regular tables — `Schema.Schema.Encoded<typeof X>` strips `Schema.brand(...)` because brands live on the Type side.
|
|
10
|
+
|
|
11
|
+
Concrete consequence: every Kysely consumer queried `result.seller_id: string` instead of `result.seller_id: string & Brand<"SellerId">`. Branded ID type safety silently disabled across the entire monorepo.
|
|
12
|
+
|
|
13
|
+
Fix: the two table categories need different treatment.
|
|
14
|
+
- **Regular tables**: `Schema.Schema.Type<typeof X>` — preserves branded IDs (`string & Brand<"SellerId">`) and the `ColumnType<S, I, U>` `__select__`/`__insert__`/`__update__` phantoms. Type === Encoded for column names anyway because regular tables don't use `Schema.fromKey`.
|
|
15
|
+
- **Join tables**: `Schema.Schema.Encoded<typeof X>` — only join tables use `Schema.fromKey('A')` to remap DB columns `A`/`B` to semantic names. Type would expose the decoded names that Kysely passes to SQL verbatim → "column does not exist". Encoded preserves real column names.
|
|
16
|
+
|
|
17
|
+
Effectively: pick the side that matches the _intended consumer view_. For non-`fromKey` tables, that's the Type side (richer info, brand info preserved). For `fromKey` tables, that's the Encoded side (matches DB).
|
|
18
|
+
|
|
19
|
+
**Migration**: regular-table consumers regain `Brand<...>` IDs immediately. Join-table consumers (`_product_tags.A`/`B` queries) unchanged from 5.7.0 — those still expose real DB column names.
|
|
20
|
+
|
|
21
|
+
## 5.8.0
|
|
22
|
+
|
|
23
|
+
### Minor Changes
|
|
24
|
+
|
|
25
|
+
- ac42853: fix: DateTime maps back to `Schema.DateFromSelf` (Date ↔ Date) — Prisma+Kysely canonical
|
|
26
|
+
|
|
27
|
+
Reverts the 5.6.0 change that mapped `DateTime` to `DateFromInput` (a
|
|
28
|
+
`Schema.Union(DateFromSelf, Date)` with `Encoded = Date | string`).
|
|
29
|
+
|
|
30
|
+
**Why revert**: the dual-input Union pushed the boundary problem onto
|
|
31
|
+
DA-layer consumers. Kysely's pg driver returns native `Date` instances,
|
|
32
|
+
but `Selectable<X>.created_at` typed as `Date | string` forced every DA
|
|
33
|
+
mapper that copies `result.created_at` into a contract type to either
|
|
34
|
+
narrow manually (no cast-free path) or wrap the read in
|
|
35
|
+
`Schema.decode(Selectable(X))` (heavy refactor across hundreds of sites).
|
|
36
|
+
|
|
37
|
+
**Why DateFromSelf is correct**:
|
|
38
|
+
- **Prisma docs**: _"Prisma Client returns all DateTime values as native
|
|
39
|
+
JavaScript Date objects. ... DateTime values must be passed as Date
|
|
40
|
+
objects, not strings, to avoid runtime errors."_
|
|
41
|
+
- **Kysely docs**: idiomatic DateTime column is
|
|
42
|
+
`created_at: ColumnType<Date, string | undefined, never>` — SELECT
|
|
43
|
+
yields `Date`. _"TypeScript is a compile-time concept and cannot
|
|
44
|
+
alter runtime JavaScript types. If your TypeScript definition for a
|
|
45
|
+
column differs from the database's actual return type, the runtime
|
|
46
|
+
type will not change automatically."_
|
|
47
|
+
- **Effect Schema docs (Doc 10944)**: _"schemas should be defined such
|
|
48
|
+
that encode + decode return the original value"_ — one Type, one
|
|
49
|
+
Encoded per schema. The dual-boundary problem (DA Date ↔ Date vs
|
|
50
|
+
RPC string ↔ Date) is solved by **two schemas** (one per boundary),
|
|
51
|
+
not one Union. Doc 4312 (`@effect/sql/Model.Class`) shows this
|
|
52
|
+
canonical variant pattern (`select`/`insert`/`update` vs
|
|
53
|
+
`json`/`jsonCreate`/`jsonUpdate`).
|
|
54
|
+
|
|
55
|
+
**For RPC/HTTP wire boundaries**: define a contract-layer schema that
|
|
56
|
+
overrides date columns with `Schema.Date` (Encoded = string) before the
|
|
57
|
+
RPC framework calls `Schema.decode`. This is the same pattern as
|
|
58
|
+
`@effect/sql`'s `json` variants — one schema per boundary.
|
|
59
|
+
|
|
60
|
+
**`DateFromInput` is still exported** from the package for consumers that
|
|
61
|
+
specifically want the dual-input behavior at a single call site. The
|
|
62
|
+
codegen just no longer auto-emits it for every DateTime column.
|
|
63
|
+
|
|
64
|
+
**The Schema.Schema.Encoded fix in 5.7.0 stays** — that's still correct
|
|
65
|
+
for join-table column exposure (`_product_tags.A`/`B`).
|
|
66
|
+
|
|
67
|
+
**Migration**: most consumers benefit immediately (DA mappers stop
|
|
68
|
+
seeing `Date | string`). For RPC contracts that previously didn't have
|
|
69
|
+
a Date override (because they relied on `DateFromInput`), re-add a
|
|
70
|
+
`Schema.extend` with `Schema.Date` overrides for date columns to keep
|
|
71
|
+
wire decode working.
|
|
72
|
+
|
|
3
73
|
## 5.7.0
|
|
4
74
|
|
|
5
75
|
### Minor Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/effect/generator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAErD,OAAO,EA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EAAE,OAAO;IAsBrC;;OAEG;IACH,wBAAwB,CAAC,UAAU,EAAE,aAAa,EAAE;CAGrD"}
|
package/dist/effect/generator.js
CHANGED
|
@@ -76,12 +76,13 @@ export type ${name} = typeof ${name};`;
|
|
|
76
76
|
*/
|
|
77
77
|
generateTypesHeader(hasEnums) {
|
|
78
78
|
const header = generateFileHeader();
|
|
79
|
-
// Import runtime helpers from prisma-effect-kysely
|
|
80
|
-
//
|
|
81
|
-
//
|
|
79
|
+
// Import runtime helpers from prisma-effect-kysely.
|
|
80
|
+
// DateTime fields use Schema.DateFromSelf (Date ↔ Date), matching
|
|
81
|
+
// Prisma's contract that DateTime values are native Date instances.
|
|
82
|
+
// Decode through a Schema.Date contract schema at JSON wire boundaries.
|
|
82
83
|
const imports = [
|
|
83
84
|
`import { Schema } from "effect";`,
|
|
84
|
-
`import { columnType, generated, JsonValue
|
|
85
|
+
`import { columnType, generated, JsonValue } from "prisma-effect-kysely";`,
|
|
85
86
|
];
|
|
86
87
|
if (hasEnums) {
|
|
87
88
|
// Import PascalCase enum schemas
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../src/effect/generator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAsB,MAAM,uBAAuB,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE3C;;GAEG;AACH,MAAM,OAAO,eAAe;IACG;IAA7B,YAA6B,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,IAAI,CAAC,CAAC;YACpE,OAAO,KAAK,KAAK,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QACzC,CAAC,CAAC;aACD,IAAI,CAAC,KAAK,CAAC,CAAC;QAEf,OAAO,gBAAgB,IAAI;EAC7B,gBAAgB;;cAEJ,IAAI,aAAa,IAAI,GAAG,CAAC;IACrC,CAAC;IAED;;OAEG;IACH,mBAAmB,CAAC,QAAiB;QACnC,MAAM,MAAM,GAAG,kBAAkB,EAAE,CAAC;QAEpC,oDAAoD;QACpD,kEAAkE;QAClE,oEAAoE;QACpE,wEAAwE;QACxE,MAAM,OAAO,GAAG;YACd,kCAAkC;YAClC,0EAA0E;SAC3E,CAAC;QAEF,IAAI,QAAQ,EAAE,CAAC;YACb,iCAAiC;YACjC,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAE1F,OAAO,CAAC,IAAI,CAAC,YAAY,WAAW,oBAAoB,CAAC,CAAC;QAC5D,CAAC;QAED,OAAO,GAAG,MAAM,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,wBAAwB,CAAC,UAA2B;QAClD,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,uBAAuB,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACrF,CAAC;CACF"}
|
package/dist/kysely/type.d.ts
CHANGED
|
@@ -32,20 +32,22 @@ export declare function buildKyselyFieldType(baseFieldType: string, field: DMMF.
|
|
|
32
32
|
/**
|
|
33
33
|
* Generate DB interface entry for a model
|
|
34
34
|
*
|
|
35
|
-
* Uses Schema.Schema.
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* runtime shape after `Schema.decode` (which Kysely never runs).
|
|
35
|
+
* Uses Schema.Schema.Type<Model> for regular tables. The Type side
|
|
36
|
+
* preserves branded IDs (e.g. `string & Brand<"SellerId">`), which is
|
|
37
|
+
* what Kysely's Selectable/Insertable/Updateable consumers want.
|
|
39
38
|
*
|
|
40
|
-
*
|
|
39
|
+
* Regular tables don't use Schema.fromKey, so `Type === Encoded` for
|
|
40
|
+
* column names — both shapes have the same key structure. The
|
|
41
|
+
* difference is at the leaf level: Type preserves brands and refinements,
|
|
42
|
+
* Encoded strips them. For a SQL contract, brand info is harmless and
|
|
43
|
+
* useful (Kysely passes it through to consumers).
|
|
41
44
|
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* Encoded preserves the real DB column names
|
|
45
|
+
* Join tables are different — see generateJoinTableDBInterfaceEntry —
|
|
46
|
+
* because they use Schema.fromKey to remap column names, and only
|
|
47
|
+
* Encoded preserves the real DB column names.
|
|
45
48
|
*
|
|
46
49
|
* ColumnType<S, I, U> brand preserves the __select__/__insert__/__update__
|
|
47
|
-
* phantom properties on both sides
|
|
48
|
-
* type inference still works correctly.
|
|
50
|
+
* phantom properties on both sides, so INSERT/UPDATE inference works.
|
|
49
51
|
*/
|
|
50
52
|
export declare function generateDBInterfaceEntry(model: DMMF.Model): string;
|
|
51
53
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../src/kysely/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAI3D;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,WAEhD;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,WAE/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iC,CAAC,SAAS,EAAE,aAAa,UAIzE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,SAAS,IAAI,CAAC,KAAK,EAAE,EAC7B,UAAU,GAAE,aAAa,EAAO,UAajC"}
|
package/dist/kysely/type.js
CHANGED
|
@@ -63,25 +63,27 @@ export function buildKyselyFieldType(baseFieldType, field, modelName) {
|
|
|
63
63
|
/**
|
|
64
64
|
* Generate DB interface entry for a model
|
|
65
65
|
*
|
|
66
|
-
* Uses Schema.Schema.
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* runtime shape after `Schema.decode` (which Kysely never runs).
|
|
66
|
+
* Uses Schema.Schema.Type<Model> for regular tables. The Type side
|
|
67
|
+
* preserves branded IDs (e.g. `string & Brand<"SellerId">`), which is
|
|
68
|
+
* what Kysely's Selectable/Insertable/Updateable consumers want.
|
|
70
69
|
*
|
|
71
|
-
*
|
|
70
|
+
* Regular tables don't use Schema.fromKey, so `Type === Encoded` for
|
|
71
|
+
* column names — both shapes have the same key structure. The
|
|
72
|
+
* difference is at the leaf level: Type preserves brands and refinements,
|
|
73
|
+
* Encoded strips them. For a SQL contract, brand info is harmless and
|
|
74
|
+
* useful (Kysely passes it through to consumers).
|
|
72
75
|
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* Encoded preserves the real DB column names
|
|
76
|
+
* Join tables are different — see generateJoinTableDBInterfaceEntry —
|
|
77
|
+
* because they use Schema.fromKey to remap column names, and only
|
|
78
|
+
* Encoded preserves the real DB column names.
|
|
76
79
|
*
|
|
77
80
|
* ColumnType<S, I, U> brand preserves the __select__/__insert__/__update__
|
|
78
|
-
* phantom properties on both sides
|
|
79
|
-
* type inference still works correctly.
|
|
81
|
+
* phantom properties on both sides, so INSERT/UPDATE inference works.
|
|
80
82
|
*/
|
|
81
83
|
export function generateDBInterfaceEntry(model) {
|
|
82
84
|
const tableName = model.dbName || model.name;
|
|
83
85
|
const modelName = toPascalCase(model.name);
|
|
84
|
-
return ` ${tableName}: Schema.Schema.
|
|
86
|
+
return ` ${tableName}: Schema.Schema.Type<typeof ${modelName}>;`;
|
|
85
87
|
}
|
|
86
88
|
/**
|
|
87
89
|
* Generate DB interface entry for a join table
|
package/dist/kysely/type.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../src/kysely/type.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,KAAiB;IAC/C,OAAO,eAAe,CAAC,KAAK,CAAC,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC;AACpD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,KAAiB;IAC9C,OAAO,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AACrD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,SAAiB,EAAE,KAAiB,EAAE,SAAkB;IACzF,IAAI,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3B,yEAAyE;QACzE,MAAM,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;QACtE,OAAO,cAAc,MAAM,+BAA+B,CAAC;IAC7D,CAAC;SAAM,IAAI,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;QACjC,OAAO,aAAa,SAAS,GAAG,CAAC;IACnC,CAAC;IACD,kFAAkF;IAClF,4EAA4E;IAC5E,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QAC1B,OAAO,cAAc,SAAS,KAAK,SAAS,KAAK,SAAS,GAAG,CAAC;IAChE,CAA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;IAC7C,MAAM,SAAS,GAAG,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3C,OAAO,KAAK,SAAS,+BAA+B,SAAS,IAAI,CAAC;AACpE,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,iCAAiC,CAAC,SAAwB;IACxE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,GAAG,SAAS,CAAC;IAC9C,MAAM,UAAU,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;IAC9C,OAAO,KAAK,SAAS,kCAAkC,UAAU,IAAI,CAAC;AACxE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAA6B,EAC7B,aAA8B,EAAE;IAEhC,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEjF,MAAM,gBAAgB,GACpB,UAAU,CAAC,MAAM,GAAG,CAAC;QACnB,CAAC,CAAC,KAAK,UAAU,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QACrE,CAAC,CAAC,EAAE,CAAC;IAET,OAAO;;EAEP,YAAY,GAAG,gBAAgB;EAC/B,CAAC;AACH,CAAC"}
|
|
@@ -11,14 +11,17 @@
|
|
|
11
11
|
* Prisma scalar type mapping to Effect Schema types
|
|
12
12
|
* Uses const assertion for type safety
|
|
13
13
|
*
|
|
14
|
-
* DateTime uses `
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
14
|
+
* DateTime uses `Schema.DateFromSelf` (Type === Encoded === Date) — matches
|
|
15
|
+
* Prisma's contract that Client returns DateTime as native `Date` instances
|
|
16
|
+
* (https://www.prisma.io/docs — "Prisma Client returns all DateTime values
|
|
17
|
+
* as native JavaScript Date objects"). Also matches Kysely's idiomatic
|
|
18
|
+
* `ColumnType<Date, ...>` pattern: SELECT yields Date.
|
|
18
19
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
20
|
+
* For RPC/JSON wire boundaries (where dates serialize to ISO strings),
|
|
21
|
+
* decode through a `Schema.Date`-typed contract schema at the boundary.
|
|
22
|
+
* Effect's Schema is single-pair (Type, Encoded) by design — see Doc 10944
|
|
23
|
+
* "The Rule of Schemas" — and the dual-boundary problem is solved by
|
|
24
|
+
* having two schemas (DA-side vs wire-side), not one Union.
|
|
22
25
|
*/
|
|
23
26
|
export declare const PRISMA_TO_EFFECT_SCHEMA: {
|
|
24
27
|
readonly String: "Schema.String";
|
|
@@ -27,7 +30,7 @@ export declare const PRISMA_TO_EFFECT_SCHEMA: {
|
|
|
27
30
|
readonly BigInt: "Schema.BigInt";
|
|
28
31
|
readonly Decimal: "Schema.String";
|
|
29
32
|
readonly Boolean: "Schema.Boolean";
|
|
30
|
-
readonly DateTime: "
|
|
33
|
+
readonly DateTime: "Schema.DateFromSelf";
|
|
31
34
|
readonly Json: "JsonValue";
|
|
32
35
|
readonly Bytes: "Schema.Uint8Array";
|
|
33
36
|
};
|
|
@@ -57,7 +60,7 @@ export declare function isPrismaScalarType(type: string): type is PrismaScalarTy
|
|
|
57
60
|
* Get Effect Schema type for a Prisma scalar type
|
|
58
61
|
* Returns undefined for non-scalar types (enums, relations)
|
|
59
62
|
*/
|
|
60
|
-
export declare function getEffectSchemaType(type: string): "Schema.String" | "Schema.Number" | "Schema.BigInt" | "Schema.Boolean" | "
|
|
63
|
+
export declare function getEffectSchemaType(type: string): "Schema.String" | "Schema.Number" | "Schema.BigInt" | "Schema.Boolean" | "Schema.DateFromSelf" | "JsonValue" | "Schema.Uint8Array" | undefined;
|
|
61
64
|
/**
|
|
62
65
|
* Get TypeScript type for a Prisma scalar type
|
|
63
66
|
* Returns the input type unchanged for non-scalar types (enums, models)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-mappings.d.ts","sourceRoot":"","sources":["../../src/utils/type-mappings.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH
|
|
1
|
+
{"version":3,"file":"type-mappings.d.ts","sourceRoot":"","sources":["../../src/utils/type-mappings.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,uBAAuB;;;;;;;;;;CAU1B,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;CAUvB,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,OAAO,uBAAuB,CAAC;AAEpE;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,gBAAgB,CAEzE;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,kJAK/C;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,UAK7C"}
|
|
@@ -11,14 +11,17 @@
|
|
|
11
11
|
* Prisma scalar type mapping to Effect Schema types
|
|
12
12
|
* Uses const assertion for type safety
|
|
13
13
|
*
|
|
14
|
-
* DateTime uses `
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
14
|
+
* DateTime uses `Schema.DateFromSelf` (Type === Encoded === Date) — matches
|
|
15
|
+
* Prisma's contract that Client returns DateTime as native `Date` instances
|
|
16
|
+
* (https://www.prisma.io/docs — "Prisma Client returns all DateTime values
|
|
17
|
+
* as native JavaScript Date objects"). Also matches Kysely's idiomatic
|
|
18
|
+
* `ColumnType<Date, ...>` pattern: SELECT yields Date.
|
|
18
19
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
20
|
+
* For RPC/JSON wire boundaries (where dates serialize to ISO strings),
|
|
21
|
+
* decode through a `Schema.Date`-typed contract schema at the boundary.
|
|
22
|
+
* Effect's Schema is single-pair (Type, Encoded) by design — see Doc 10944
|
|
23
|
+
* "The Rule of Schemas" — and the dual-boundary problem is solved by
|
|
24
|
+
* having two schemas (DA-side vs wire-side), not one Union.
|
|
22
25
|
*/
|
|
23
26
|
export const PRISMA_TO_EFFECT_SCHEMA = {
|
|
24
27
|
String: 'Schema.String',
|
|
@@ -27,7 +30,7 @@ export const PRISMA_TO_EFFECT_SCHEMA = {
|
|
|
27
30
|
BigInt: 'Schema.BigInt',
|
|
28
31
|
Decimal: 'Schema.String', // For precision
|
|
29
32
|
Boolean: 'Schema.Boolean',
|
|
30
|
-
DateTime: '
|
|
33
|
+
DateTime: 'Schema.DateFromSelf', // Date ↔ Date — Prisma+Kysely canonical
|
|
31
34
|
Json: 'JsonValue', // Recursive JSON type — prevents null absorption in NullOr
|
|
32
35
|
Bytes: 'Schema.Uint8Array',
|
|
33
36
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-mappings.js","sourceRoot":"","sources":["../../src/utils/type-mappings.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH
|
|
1
|
+
{"version":3,"file":"type-mappings.js","sourceRoot":"","sources":["../../src/utils/type-mappings.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,MAAM,EAAE,eAAe;IACvB,GAAG,EAAE,eAAe;IACpB,KAAK,EAAE,eAAe;IACtB,MAAM,EAAE,eAAe;IACvB,OAAO,EAAE,eAAe,EAAE,gBAAgB;IAC1C,OAAO,EAAE,gBAAgB;IACzB,QAAQ,EAAE,qBAAqB,EAAE,wCAAwC;IACzE,IAAI,EAAE,WAAW,EAAE,2DAA2D;IAC9E,KAAK,EAAE,mBAAmB;CAClB,CAAC;AAEX;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,MAAM,EAAE,QAAQ;IAChB,GAAG,EAAE,QAAQ;IACb,KAAK,EAAE,QAAQ;IACf,OAAO,EAAE,SAAS;IAClB,Q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