@effect-dynamodb/schema 1.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.
Files changed (71) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +53 -0
  3. package/dist/Aggregate.d.ts +128 -0
  4. package/dist/Aggregate.d.ts.map +1 -0
  5. package/dist/Aggregate.js +69 -0
  6. package/dist/Aggregate.js.map +1 -0
  7. package/dist/DynamoModel.d.ts +370 -0
  8. package/dist/DynamoModel.d.ts.map +1 -0
  9. package/dist/DynamoModel.js +541 -0
  10. package/dist/DynamoModel.js.map +1 -0
  11. package/dist/DynamoSchema.d.ts +137 -0
  12. package/dist/DynamoSchema.d.ts.map +1 -0
  13. package/dist/DynamoSchema.js +188 -0
  14. package/dist/DynamoSchema.js.map +1 -0
  15. package/dist/Entity.d.ts +239 -0
  16. package/dist/Entity.d.ts.map +1 -0
  17. package/dist/Entity.js +558 -0
  18. package/dist/Entity.js.map +1 -0
  19. package/dist/Errors.d.ts +387 -0
  20. package/dist/Errors.d.ts.map +1 -0
  21. package/dist/Errors.js +218 -0
  22. package/dist/Errors.js.map +1 -0
  23. package/dist/KeyComposer.d.ts +264 -0
  24. package/dist/KeyComposer.d.ts.map +1 -0
  25. package/dist/KeyComposer.js +516 -0
  26. package/dist/KeyComposer.js.map +1 -0
  27. package/dist/Projection.d.ts +28 -0
  28. package/dist/Projection.d.ts.map +1 -0
  29. package/dist/Projection.js +39 -0
  30. package/dist/Projection.js.map +1 -0
  31. package/dist/index.d.ts +32 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +26 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/internal/AggregateCursor.d.ts +44 -0
  36. package/dist/internal/AggregateCursor.d.ts.map +1 -0
  37. package/dist/internal/AggregateCursor.js +18 -0
  38. package/dist/internal/AggregateCursor.js.map +1 -0
  39. package/dist/internal/AggregateEdges.d.ts +117 -0
  40. package/dist/internal/AggregateEdges.d.ts.map +1 -0
  41. package/dist/internal/AggregateEdges.js +51 -0
  42. package/dist/internal/AggregateEdges.js.map +1 -0
  43. package/dist/internal/AggregateSchemas.d.ts +76 -0
  44. package/dist/internal/AggregateSchemas.d.ts.map +1 -0
  45. package/dist/internal/AggregateSchemas.js +164 -0
  46. package/dist/internal/AggregateSchemas.js.map +1 -0
  47. package/dist/internal/AggregateTypes.d.ts +132 -0
  48. package/dist/internal/AggregateTypes.d.ts.map +1 -0
  49. package/dist/internal/AggregateTypes.js +7 -0
  50. package/dist/internal/AggregateTypes.js.map +1 -0
  51. package/dist/internal/DefaultCrypto.d.ts +26 -0
  52. package/dist/internal/DefaultCrypto.d.ts.map +1 -0
  53. package/dist/internal/DefaultCrypto.js +40 -0
  54. package/dist/internal/DefaultCrypto.js.map +1 -0
  55. package/dist/internal/EntityConfig.d.ts +152 -0
  56. package/dist/internal/EntityConfig.d.ts.map +1 -0
  57. package/dist/internal/EntityConfig.js +7 -0
  58. package/dist/internal/EntityConfig.js.map +1 -0
  59. package/dist/internal/EntitySchemas.d.ts +198 -0
  60. package/dist/internal/EntitySchemas.d.ts.map +1 -0
  61. package/dist/internal/EntitySchemas.js +798 -0
  62. package/dist/internal/EntitySchemas.js.map +1 -0
  63. package/dist/internal/EntityTypes.d.ts +233 -0
  64. package/dist/internal/EntityTypes.d.ts.map +1 -0
  65. package/dist/internal/EntityTypes.js +7 -0
  66. package/dist/internal/EntityTypes.js.map +1 -0
  67. package/dist/internal/SchemaAccessors.d.ts +90 -0
  68. package/dist/internal/SchemaAccessors.d.ts.map +1 -0
  69. package/dist/internal/SchemaAccessors.js +171 -0
  70. package/dist/internal/SchemaAccessors.js.map +1 -0
  71. package/package.json +70 -0
@@ -0,0 +1,132 @@
1
+ /**
2
+ * @internal Aggregate type-level computations — derived types for Aggregate operations.
3
+ *
4
+ * Extracted from Aggregate.ts for decomposition. Not part of the public API.
5
+ */
6
+ import type { Schema } from "effect";
7
+ import type { DiscriminatorConfig, UpdateContext } from "./AggregateCursor.js";
8
+ import type { AggregateEdge, ManyEdge, OneEdge, RefEdge, RefEntity } from "./AggregateEdges.js";
9
+ import type { RefEntityIdentifierValue } from "./EntityTypes.js";
10
+ /**
11
+ * A composable sub-aggregate definition — a graph shape that can be embedded
12
+ * in a parent aggregate via `.with()`.
13
+ */
14
+ export interface SubAggregate<TSchema extends Schema.Top, TEdges extends Record<string, AggregateEdge | BoundSubAggregate<any, any>> = Record<string, AggregateEdge | BoundSubAggregate<any, any>>> {
15
+ readonly _tag: "SubAggregate";
16
+ readonly schema: TSchema;
17
+ readonly root: {
18
+ readonly entityType: string;
19
+ };
20
+ readonly edges: TEdges;
21
+ /** Bind with discriminator values to distinguish multiple embeddings */
22
+ readonly with: (config: DiscriminatorConfig) => BoundSubAggregate<TSchema, TEdges>;
23
+ }
24
+ /**
25
+ * A sub-aggregate bound with discriminator values, ready to embed in a parent.
26
+ */
27
+ export interface BoundSubAggregate<TSchema extends Schema.Top, TEdges extends Record<string, AggregateEdge | BoundSubAggregate<any, any>> = Record<string, AggregateEdge | BoundSubAggregate<any, any>>> {
28
+ readonly _tag: "BoundSubAggregate";
29
+ readonly aggregate: SubAggregate<TSchema, TEdges>;
30
+ readonly discriminator: Record<string, unknown>;
31
+ }
32
+ /** Extract the domain type from an Aggregate */
33
+ export type Type<T> = T extends {
34
+ readonly schema: infer S extends Schema.Top;
35
+ } ? Schema.Schema.Type<S> : never;
36
+ /** Extract the key type from an Aggregate */
37
+ export type Key<T> = T extends {
38
+ readonly get: (key: infer K) => any;
39
+ } ? K : never;
40
+ /** Extract the input type from an Aggregate */
41
+ export type Input<T> = T extends {
42
+ readonly inputSchema: Schema.Codec<infer I>;
43
+ } ? I : never;
44
+ /** Extract the update mutation function type from an Aggregate */
45
+ export type UpdateFn<T> = T extends {
46
+ readonly schema: infer S extends Schema.Top;
47
+ } ? (context: UpdateContext<S["Iso"], Schema.Schema.Type<S>>) => Schema.Schema.Type<S> | S["Iso"] : never;
48
+ /**
49
+ * Resolve the `${field}Id` value type for a OneEdge / RefEdge / ManyEdge.
50
+ *
51
+ * Extracts the referenced entity from the edge and resolves its branded
52
+ * primary-key identifier via `RefEntityIdentifierValue`. Edges without an
53
+ * associated entity (e.g. a `OneEdge` whose member is a pure sub-shape) fall
54
+ * back to `string`.
55
+ *
56
+ * `entity` is required on RefEdge but optional on OneEdge / ManyEdge
57
+ * (`entity?: E | undefined`), so we read it via indexed access and strip
58
+ * `undefined` with `NonNullable` before resolving — otherwise the optional
59
+ * modifier widens `infer E` to `E | undefined`, fails the `extends RefEntity`
60
+ * guard, and silently collapses the brand back to `string`.
61
+ */
62
+ type _EdgeIdValue<Edge> = NonNullable<Edge extends {
63
+ readonly entity?: unknown;
64
+ } ? Edge["entity"] : undefined> extends infer E ? E extends RefEntity ? RefEntityIdentifierValue<E> : string : string;
65
+ /**
66
+ * Compute the aggregate input type from the domain model, edges, and PK composites.
67
+ *
68
+ * - OneEdge / RefEdge fields → `${field}Id: <entity branded id | string>`
69
+ * - BoundSubAggregate fields → recursed
70
+ * - ManyEdge fields → array elements recursed for ref replacement
71
+ * - PK composites → omitted
72
+ * - Everything else → kept as-is
73
+ *
74
+ * Edge id fields resolve to the referenced entity's branded primary-key
75
+ * identifier type (e.g. `venueId: VenueId`) when the edge carries an `entity`,
76
+ * mirroring the standalone Entity ref path (`EntityRefInputType`). Without an
77
+ * entity, they fall back to `string`.
78
+ */
79
+ export type AggregateInputType<TModel, TEdges extends Record<string, AggregateEdge | BoundSubAggregate<any, any>>, TPK extends ReadonlyArray<string>> = _Simplify<{
80
+ readonly [K in keyof TModel as K extends keyof TEdges ? never : K extends TPK[number] ? never : K]: _StripUndefined<TModel[K]>;
81
+ } & {
82
+ readonly [K in keyof TEdges as TEdges[K] extends OneEdge<any> | RefEdge<any> ? _IsOptionalIn<TModel, K> extends true ? never : `${K & string}Id` : never]: _EdgeIdValue<TEdges[K]>;
83
+ } & {
84
+ readonly [K in keyof TEdges as TEdges[K] extends OneEdge<any> | RefEdge<any> ? _IsOptionalIn<TModel, K> extends true ? `${K & string}Id` : never : never]?: _EdgeIdValue<TEdges[K]>;
85
+ } & {
86
+ readonly [K in keyof TEdges as TEdges[K] extends BoundSubAggregate<any, any> ? _IsOptionalIn<TModel, K> extends true ? never : K : never]: TEdges[K] extends BoundSubAggregate<infer S, infer E> ? AggregateInputType<Schema.Schema.Type<S>, E, []> : never;
87
+ } & {
88
+ readonly [K in keyof TEdges as TEdges[K] extends BoundSubAggregate<any, any> ? _IsOptionalIn<TModel, K> extends true ? K : never : never]?: TEdges[K] extends BoundSubAggregate<infer S, infer E> ? AggregateInputType<Schema.Schema.Type<S>, E, []> : never;
89
+ } & {
90
+ readonly [K in keyof TEdges as TEdges[K] extends ManyEdge<any> ? _IsOptionalIn<TModel, K> extends true ? never : TEdges[K] extends {
91
+ readonly inputField: infer IF extends string;
92
+ } ? IF : K : never]: K extends keyof TModel ? _TransformManyEdge<TModel[K], _EdgeIdValue<TEdges[K]>> : never;
93
+ } & {
94
+ readonly [K in keyof TEdges as TEdges[K] extends ManyEdge<any> ? _IsOptionalIn<TModel, K> extends true ? TEdges[K] extends {
95
+ readonly inputField: infer IF extends string;
96
+ } ? IF : K : never : never]?: K extends keyof TModel ? _TransformManyEdge<TModel[K], _EdgeIdValue<TEdges[K]>> : never;
97
+ }>;
98
+ /** Detect ref-like types: objects with an `id: string` property (Schema.Class entities) */
99
+ type _IsRefLike<T> = T extends {
100
+ readonly id: string;
101
+ } ? string extends keyof T ? false : true : false;
102
+ /**
103
+ * Transform an object's ref-like fields to `${field}Id: <Id>`.
104
+ *
105
+ * `Id` is the edge entity's branded identifier type — the ManyEdge associates a
106
+ * single entity, and the runtime decomposition (`deriveEntityFieldName`) maps
107
+ * the element's entity-derived ref field to exactly that entity, so the brand
108
+ * is shared by the element's nested ref field. Falls back to `string` when the
109
+ * edge carries no entity (`Id = string`).
110
+ */
111
+ type _RefFieldsToIds<T, Id> = _Simplify<{
112
+ readonly [K in keyof T as _IsRefLike<T[K]> extends true ? `${K & string}Id` : K]: _IsRefLike<T[K]> extends true ? Id : T[K];
113
+ }>;
114
+ /**
115
+ * Distribute over unions (e.g., ReadonlyArray<T> | undefined) to transform array elements.
116
+ *
117
+ * `Id` is the ManyEdge entity's branded identifier type:
118
+ * - When the element IS the ref (`Array<Umpire>`), the array becomes `Array<Id>`.
119
+ * - When the element wraps the ref (`Array<{ player: Player, ... }>`), the nested
120
+ * ref field is rewritten to `${field}Id: Id`.
121
+ */
122
+ type _TransformManyEdge<T, Id> = T extends ReadonlyArray<infer E> ? _IsRefLike<E> extends true ? ReadonlyArray<Id> : ReadonlyArray<_RefFieldsToIds<E, Id>> : T;
123
+ /** Check if key K is an optional property of T */
124
+ type _IsOptionalIn<T, K> = K extends keyof T ? ({} extends Pick<T, K> ? true : false) : false;
125
+ /** Strip `undefined` from optional field value types — the `?` modifier already expresses optionality */
126
+ type _StripUndefined<T> = undefined extends T ? Exclude<T, undefined> : T;
127
+ /** Flatten intersection types — `extends infer O` breaks the alias chain for eager IDE expansion */
128
+ type _Simplify<T> = T extends infer O ? {
129
+ [K in keyof O]: O[K];
130
+ } : never;
131
+ export {};
132
+ //# sourceMappingURL=AggregateTypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AggregateTypes.d.ts","sourceRoot":"","sources":["../../src/internal/AggregateTypes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AACpC,OAAO,KAAK,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAC9E,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAC/F,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAA;AAMhE;;;GAGG;AACH,MAAM,WAAW,YAAY,CAC3B,OAAO,SAAS,MAAM,CAAC,GA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,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,CAAC,CAAA;AAEzE,oGAAoG;AACpG,KAAK,SAAS,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,CAAC,GAAG;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,GAAG,KAAK,CAAA"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @internal Aggregate type-level computations — derived types for Aggregate operations.
3
+ *
4
+ * Extracted from Aggregate.ts for decomposition. Not part of the public API.
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=AggregateTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AggregateTypes.js","sourceRoot":"","sources":["../../src/internal/AggregateTypes.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @internal Default `Crypto` service for the typed client.
3
+ *
4
+ * `DynamoClient.make()` bundles a default {@link Crypto.Crypto} service into the
5
+ * captured context so that bound entity operations (e.g. auto-generated UUID
6
+ * primary keys via `generatedId`) can resolve a cryptographically-secure source
7
+ * WITHOUT widening the public `R` of bound methods. Bound `put` stays
8
+ * `R = never` — the service is provided from the bundled context, never
9
+ * surfaced as a requirement.
10
+ *
11
+ * The implementation is a thin wrapper over the global Web Crypto API
12
+ * (`globalThis.crypto`), available on Node 18+ and all modern browsers/edge
13
+ * runtimes — NO new dependency. Consumers needing a platform-specific source
14
+ * (e.g. `@effect/platform-node`) may override it via
15
+ * `DynamoClient.make({ crypto })`.
16
+ */
17
+ import { Crypto } from "effect";
18
+ /**
19
+ * Build the default `Crypto` service backed by `globalThis.crypto`.
20
+ *
21
+ * `randomBytes` uses `crypto.getRandomValues` (synchronous, CSPRNG). `digest`
22
+ * delegates to `crypto.subtle.digest` — unused by the ORM today but required by
23
+ * `Crypto.make`'s constructor contract.
24
+ */
25
+ export declare const makeDefaultCrypto: () => Crypto.Crypto;
26
+ //# sourceMappingURL=DefaultCrypto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DefaultCrypto.d.ts","sourceRoot":"","sources":["../../src/internal/DefaultCrypto.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,MAAM,EAAyB,MAAM,QAAQ,CAAA;AAEtD;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,QAAO,MAAM,CAAC,MAgB3C,CAAA"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @internal Default `Crypto` service for the typed client.
3
+ *
4
+ * `DynamoClient.make()` bundles a default {@link Crypto.Crypto} service into the
5
+ * captured context so that bound entity operations (e.g. auto-generated UUID
6
+ * primary keys via `generatedId`) can resolve a cryptographically-secure source
7
+ * WITHOUT widening the public `R` of bound methods. Bound `put` stays
8
+ * `R = never` — the service is provided from the bundled context, never
9
+ * surfaced as a requirement.
10
+ *
11
+ * The implementation is a thin wrapper over the global Web Crypto API
12
+ * (`globalThis.crypto`), available on Node 18+ and all modern browsers/edge
13
+ * runtimes — NO new dependency. Consumers needing a platform-specific source
14
+ * (e.g. `@effect/platform-node`) may override it via
15
+ * `DynamoClient.make({ crypto })`.
16
+ */
17
+ import { Crypto, Effect, PlatformError } from "effect";
18
+ /**
19
+ * Build the default `Crypto` service backed by `globalThis.crypto`.
20
+ *
21
+ * `randomBytes` uses `crypto.getRandomValues` (synchronous, CSPRNG). `digest`
22
+ * delegates to `crypto.subtle.digest` — unused by the ORM today but required by
23
+ * `Crypto.make`'s constructor contract.
24
+ */
25
+ export const makeDefaultCrypto = () => {
26
+ const webCrypto = globalThis.crypto;
27
+ return Crypto.make({
28
+ // Crypto.make requires a fresh array per call (it mutates UUID bytes).
29
+ randomBytes: (size) => webCrypto.getRandomValues(new Uint8Array(size)),
30
+ digest: (algorithm, data) => Effect.tryPromise({
31
+ try: () => webCrypto.subtle.digest(algorithm, data),
32
+ catch: (cause) => PlatformError.badArgument({
33
+ module: "Crypto",
34
+ method: "digest",
35
+ description: `digest failed: ${cause instanceof Error ? cause.message : String(cause)}`,
36
+ }),
37
+ }).pipe(Effect.map((buf) => new Uint8Array(buf))),
38
+ });
39
+ };
40
+ //# sourceMappingURL=DefaultCrypto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DefaultCrypto.js","sourceRoot":"","sources":["../../src/internal/DefaultCrypto.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AAEtD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAkB,EAAE;IACnD,MAAM,SAAS,GAAG,UAAU,CAAC,MAAM,CAAA;IACnC,OAAO,MAAM,CAAC,IAAI,CAAC;QACjB,uEAAuE;QACvE,WAAW,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;QACtE,MAAM,EAAE,CAAC,SAAS,EAAE,IAAI,EAAE,EAAE,CAC1B,MAAM,CAAC,UAAU,CAAC;YAChB,GAAG,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,IAA8B,CAAC;YAC7E,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CACf,aAAa,CAAC,WAAW,CAAC;gBACxB,MAAM,EAAE,QAAQ;gBAChB,MAAM,EAAE,QAAQ;gBAChB,WAAW,EAAE,kBAAkB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;aACxF,CAAC;SACL,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;KACpD,CAAC,CAAA;AACJ,CAAC,CAAA"}
@@ -0,0 +1,152 @@
1
+ /**
2
+ * @internal Entity configuration types — system field and constraint config.
3
+ *
4
+ * Extracted from Entity.ts for decomposition. Not part of the public API.
5
+ */
6
+ import type { Duration, Schema } from "effect";
7
+ /**
8
+ * Per-timestamp field configuration.
9
+ *
10
+ * - `string` — override field name only (default DateString schema)
11
+ * - `Schema.Top` — override schema only (default field name)
12
+ * - `{ field?, schema? }` — override both field name and schema
13
+ */
14
+ export type TimestampFieldConfig = string | Schema.Top | {
15
+ readonly field?: string | undefined;
16
+ readonly schema?: Schema.Top | undefined;
17
+ };
18
+ /**
19
+ * Timestamp configuration for automatic `createdAt` / `updatedAt` fields.
20
+ *
21
+ * - `true` — add `createdAt` and `updatedAt` with default names and ISO string storage
22
+ * - `{ created?, updated? }` — per-field configuration (string, schema, or object)
23
+ * - `false` / `undefined` — no timestamps
24
+ */
25
+ export type TimestampsConfig = boolean | {
26
+ readonly created?: TimestampFieldConfig | undefined;
27
+ readonly updated?: TimestampFieldConfig | undefined;
28
+ };
29
+ /**
30
+ * Optimistic locking configuration via an auto-incrementing version field.
31
+ *
32
+ * - `true` — add a `version` field with default name
33
+ * - `{ field?, retain?, ttl? }` — override field name and retention behavior
34
+ * - `false` / `undefined` — no versioning
35
+ */
36
+ export type VersionedConfig = boolean | {
37
+ readonly field?: string | undefined;
38
+ readonly retain?: boolean | undefined;
39
+ readonly ttl?: Duration.Duration | string | undefined;
40
+ };
41
+ /**
42
+ * Soft-delete configuration. When enabled, deletes mark items rather than removing them.
43
+ *
44
+ * - `true` — enable soft delete with defaults
45
+ * - `{ ttl?, preserveUnique? }` — configure TTL cleanup and unique constraint behavior
46
+ * - `false` / `undefined` — hard deletes
47
+ */
48
+ export type SoftDeleteConfig = boolean | {
49
+ readonly ttl?: Duration.Duration | string | undefined;
50
+ readonly preserveUnique?: boolean | undefined;
51
+ };
52
+ /**
53
+ * Time-series configuration. When set, the entity stores one "current" item
54
+ * per partition and many immutable "event" items. See guides/timeseries.mdx.
55
+ *
56
+ * Current-item SK matches the primary index SK. Event-item SK is
57
+ * `<currentSk>#e#<orderBy-value>`, GSI keys stripped, TTL attribute set
58
+ * (attribute name comes from `TableConfig.ttlAttributeName`, default `"_ttl"`).
59
+ *
60
+ * `.append(input)` is a `TransactWriteItems` (UpdateItem current + Put event)
61
+ * with CAS `attribute_not_exists(pk) OR #orderBy < :newOb`. Returns
62
+ * `{ applied: true | false, current }` — stale is a value, not an error.
63
+ *
64
+ * Mutually exclusive with `versioned` (EDD-9012) and `softDelete` (EDD-9015).
65
+ */
66
+ export type TimeSeriesConfig<TAppendInput extends Schema.Top = Schema.Top> = {
67
+ /** Model attribute used as the monotonic clock for CAS and event SK decoration. Required. */
68
+ readonly orderBy: string;
69
+ /** TTL applied to event items (not current). Omit for retention-forever. */
70
+ readonly ttl?: Duration.Duration | string | undefined;
71
+ /**
72
+ * REQUIRED schema restricting which model fields are allowed in `.append()`
73
+ * input AND which fields are written into the current-item SET clause.
74
+ * The schema MUST include `orderBy` plus all PK/SK composite fields.
75
+ *
76
+ * Fields in the model but NOT in this schema are never referenced by
77
+ * `.append()`'s UpdateExpression and therefore cannot be overwritten — this
78
+ * is the enrichment-preservation contract.
79
+ *
80
+ * Omitting `appendInput` is a hard error at `make()` time (EDD-9016).
81
+ * Users who genuinely want every append to overwrite every model field
82
+ * must pass the full model schema explicitly.
83
+ */
84
+ readonly appendInput: TAppendInput;
85
+ };
86
+ /**
87
+ * Auto-generated UUID primary-key configuration.
88
+ *
89
+ * When set, `put` / `create` / `upsert` fill the named field with a freshly
90
+ * generated UUID at write time **when the caller omits it** — a caller-supplied
91
+ * value is always respected. The id is sourced from the bundled `Crypto`
92
+ * service (`DynamoClient.make` provides a default; override via
93
+ * `DynamoClient.make({ crypto })`), so bound operations keep `R = never`.
94
+ *
95
+ * The `field` MUST exist in the model AND participate in the `primaryKey`
96
+ * (pk or sk composite). Violations throw EDD-9008 at `make()` time.
97
+ *
98
+ * - `version` — `"v4"` (default, random) or `"v7"` (time-ordered).
99
+ */
100
+ export type GeneratedIdConfig = {
101
+ readonly field: string;
102
+ readonly version?: "v4" | "v7" | undefined;
103
+ };
104
+ /** An array of model field names that together form a unique constraint. */
105
+ export type UniqueFieldsDef = ReadonlyArray<string>;
106
+ /**
107
+ * A unique constraint definition — either a simple field list or an object
108
+ * with additional options like TTL for sentinel items.
109
+ */
110
+ export type UniqueConstraintDef = UniqueFieldsDef | {
111
+ readonly fields: UniqueFieldsDef;
112
+ readonly ttl?: Duration.Duration | string | undefined;
113
+ };
114
+ /**
115
+ * Map of named unique constraints. Each key is the constraint name,
116
+ * each value defines which fields must be globally unique together.
117
+ *
118
+ * Enforced via DynamoDB transaction sentinel items.
119
+ */
120
+ export type UniqueConfig = globalThis.Record<string, UniqueConstraintDef>;
121
+ /**
122
+ * Per-ref cascade index configuration. Tells Entity.make() which physical GSI
123
+ * to use for auto-generated cascade indexes.
124
+ *
125
+ * The library fills in the PK/SK composites automatically from the resolved ref
126
+ * and primary key — the consumer only specifies physical GSI details.
127
+ */
128
+ export interface CascadeIndexConfig {
129
+ /** Physical GSI name (e.g., "gsi3") */
130
+ readonly index: string;
131
+ /** PK field descriptor */
132
+ readonly pk: {
133
+ readonly field: string;
134
+ };
135
+ /** SK field descriptor */
136
+ readonly sk: {
137
+ readonly field: string;
138
+ };
139
+ }
140
+ /**
141
+ * A ref value in the `refs` config — an object with the entity and optional cascade index config.
142
+ *
143
+ * Simple: `refs: { player: { entity: Players } }`
144
+ * Cascade: `refs: { player: { entity: Players, cascade: { index: "gsi3", pk: { field: "gsi3pk" }, sk: { field: "gsi3sk" } } } }`
145
+ */
146
+ export interface RefValue {
147
+ readonly entity: {
148
+ readonly _tag: "Entity";
149
+ };
150
+ readonly cascade?: CascadeIndexConfig;
151
+ }
152
+ //# sourceMappingURL=EntityConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntityConfig.d.ts","sourceRoot":"","sources":["../../src/internal/EntityConfig.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA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al Entity configuration types — system field and constraint config.
3
+ *
4
+ * Extracted from Entity.ts for decomposition. Not part of the public API.
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=EntityConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntityConfig.js","sourceRoot":"","sources":["../../src/internal/EntityConfig.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -0,0 +1,198 @@
1
+ /**
2
+ * @internal Entity schema building — derived schemas and system field resolution.
3
+ *
4
+ * Extracted from Entity.ts for decomposition. Not part of the public API.
5
+ */
6
+ import { Schema } from "effect";
7
+ import { type DynamoEncoding } from "../DynamoModel.js";
8
+ import type { IndexDefinition } from "../KeyComposer.js";
9
+ import type { TimeSeriesConfig, TimestampsConfig, UniqueConstraintDef, VersionedConfig } from "./EntityConfig.js";
10
+ import { getSchemaFields } from "./SchemaAccessors.js";
11
+ export interface ResolvedSystemFields {
12
+ readonly createdAt: string | null;
13
+ readonly createdAtEncoding: DynamoEncoding | null;
14
+ /** True when the model declares a field whose name matches `createdAt`. */
15
+ readonly createdAtCollision: boolean;
16
+ readonly updatedAt: string | null;
17
+ readonly updatedAtEncoding: DynamoEncoding | null;
18
+ /** True when the model declares a field whose name matches `updatedAt`. */
19
+ readonly updatedAtCollision: boolean;
20
+ readonly version: string | null;
21
+ /** True when the model declares a field whose name matches `version`. */
22
+ readonly versionCollision: boolean;
23
+ }
24
+ /**
25
+ * Minimal shape of the `attributes` record on a ConfiguredModel — we only need
26
+ * `encoding` here. Declared locally to avoid importing ConfiguredModel types.
27
+ */
28
+ export type ConfiguredAttributeEncodings = globalThis.Record<string, {
29
+ readonly encoding?: DynamoEncoding;
30
+ }>;
31
+ /**
32
+ * Resolve the effective DynamoEncoding for a model-declared field, applying
33
+ * ConfiguredModel storage overrides on top of schema-level annotations.
34
+ *
35
+ * Precedence: schema annotation (getEncoding) > inferred default (Effect date
36
+ * schemas) > none. ConfiguredModel `storedAs` then overrides storage only,
37
+ * preserving the domain from the schema side when present.
38
+ *
39
+ * Returns `null` if the field is not a date-compatible schema.
40
+ */
41
+ export declare const resolveFieldEncoding: (fieldSchema: Schema.Top, override: DynamoEncoding | undefined) => DynamoEncoding | null;
42
+ /**
43
+ * Build the field → DynamoEncoding map for a set of model fields, merging
44
+ * ConfiguredModel storage overrides. Used at `Entity.make()` time.
45
+ */
46
+ export declare const buildFieldEncodings: (modelFields: SchemaFields, configuredAttributes: ConfiguredAttributeEncodings) => globalThis.Record<string, DynamoEncoding>;
47
+ export declare const resolveSystemFields: (timestamps?: TimestampsConfig | undefined, versioned?: VersionedConfig | undefined, timeSeries?: TimeSeriesConfig<any> | undefined, modelFields?: SchemaFields, configuredAttributes?: ConfiguredAttributeEncodings) => ResolvedSystemFields;
48
+ export declare const primaryKeyComposites: (indexes: globalThis.Record<string, IndexDefinition>) => ReadonlyArray<string>;
49
+ export declare const allKeyFieldNames: (indexes: globalThis.Record<string, IndexDefinition>) => ReadonlyArray<string>;
50
+ export declare const allCompositeAttributes: (indexes: globalThis.Record<string, IndexDefinition>) => ReadonlyArray<string>;
51
+ export type SchemaFields = globalThis.Record<string, Schema.Top>;
52
+ /**
53
+ * Re-export of the shared typed `.fields` accessor (returns `undefined` for
54
+ * non-Struct/Class schemas). Use this when the call site has its own
55
+ * fallback/error handling; use {@link getFields} when a missing `.fields` is a
56
+ * hard error.
57
+ */
58
+ export { getSchemaFields };
59
+ export declare const getFields: (model: Schema.Top) => SchemaFields;
60
+ /**
61
+ * Infer a default DynamoEncoding for standard Effect date schemas that lack
62
+ * an explicit DynamoEncoding annotation. This enables Pattern B (pure model
63
+ * with Schema.DateTimeUtcFromString etc.) to work without explicit storedAs.
64
+ *
65
+ * Detection uses the typeConstructor annotation from Effect's schema AST.
66
+ */
67
+ export declare const inferDefaultEncoding: (schema: Schema.Top) => DynamoEncoding | undefined;
68
+ /**
69
+ * Returns true when the schema is a "self" schema — i.e. it carries no
70
+ * encoding transformation. Self schemas have `ast.encoding === undefined`.
71
+ *
72
+ * - `Schema.DateTimeUtc` — self
73
+ * - `Schema.DateTimeUtcFromString` — transform (encodes to string)
74
+ * - `Schema.RedactedFromValue(...)` — transform
75
+ * - any `.pipe(Schema.decodeTo(...))` chain — transform
76
+ */
77
+ export declare const isSelfSchema: (schema: Schema.Top) => boolean;
78
+ /**
79
+ * True if the schema is a self DateTime/Date schema that can have its storage
80
+ * configured via a DynamoEncoding annotation. Distinguished from a transform
81
+ * by `ast.encoding === undefined`.
82
+ */
83
+ export declare const isSelfDateSchema: (schema: Schema.Top) => boolean;
84
+ /**
85
+ * Returns true when the schema is a transform schema with a date typeConstructor
86
+ * (e.g. `Schema.DateTimeUtcFromString`, `DynamoModel.DateEpochSeconds`).
87
+ * Used to enforce the "transform owns the wire format" policy at Entity.make().
88
+ */
89
+ export declare const isDateTransform: (schema: Schema.Top) => boolean;
90
+ /**
91
+ * Build a bidirectional Schema for a given DynamoEncoding.
92
+ *
93
+ * The encoded side is `Schema.Any` so `decode` tolerates either:
94
+ * - the wire primitive (string / number) — the storage-shape input, OR
95
+ * - a domain value (`DateTime.Utc`, `Date`, etc.) — what users typically pass
96
+ * into `entity.put({...})` and `.set({...})`.
97
+ *
98
+ * The `decode` direction always lifts to the domain type (DateTime.Utc /
99
+ * DateTime.Zoned / Date). The `encode` direction always produces the wire
100
+ * primitive. This makes both `Schema.encode(substituted)` and
101
+ * `Schema.decode(substituted)` work end-to-end regardless of whether the
102
+ * caller passed wire-form or domain-form.
103
+ *
104
+ * @internal
105
+ */
106
+ export declare const buildDateTransform: (encoding: DynamoEncoding) => Schema.Top;
107
+ /**
108
+ * Substitute model fields with bidirectional transforms where needed:
109
+ *
110
+ * - Self date schemas with an effective encoding (annotation or override)
111
+ * → tolerant date transform that accepts either wire form (string/number)
112
+ * or domain form (DateTime / Date) on decode, and always produces the
113
+ * configured wire primitive on encode.
114
+ * - `Schema.RedactedFromValue(inner)` fields → tolerant Redacted transform
115
+ * that accepts either form on decode and unwraps to wire primitive on
116
+ * encode (Effect v4's `RedactedFromValue` forbids encoding by default;
117
+ * our substitution makes the round-trip work for storage).
118
+ *
119
+ * Existing transform schemas (other than `RedactedFromValue`) are passed
120
+ * through unchanged — the user-declared transform IS the wire format.
121
+ *
122
+ * Schema.Class fields (and Schema.Class fields nested inside Schema.Array,
123
+ * Schema.optional, etc.) are NOT substituted here. Instead, callers run
124
+ * `decode → encode` against the substituted schema: `Schema.decode` is
125
+ * forgiving for Schema.Class (lifts plain objects to instances), and the
126
+ * tolerant date / Redacted substitutes make the decode pass accept both
127
+ * wire and domain values. The subsequent `Schema.encode` produces the
128
+ * canonical wire shape.
129
+ *
130
+ * @internal
131
+ */
132
+ export declare const substituteSchemas: (modelFields: SchemaFields, fieldEncodings: globalThis.Record<string, DynamoEncoding>) => SchemaFields;
133
+ /**
134
+ * Validate that no model field combines a transform schema with a storage
135
+ * override. The two configuration paths are mutually exclusive: either declare
136
+ * a self schema (`Schema.DateTimeUtc`) and let the annotation drive storage,
137
+ * OR declare a transform and own the wire format yourself — not both.
138
+ *
139
+ * Two override sources are checked:
140
+ *
141
+ * 1. `ConfiguredModel.storedAs` (configured attributes) — surfaces the
142
+ * override via `configuredAttributes[name].encoding`.
143
+ *
144
+ * 2. `DynamoModel.storedAs(...)` modifier piped onto the field schema —
145
+ * adds a `DynamoEncoding` annotation directly to the AST. We detect this
146
+ * by checking whether the field-level annotation disagrees with the
147
+ * transform's actual wire format (the `inferDefaultEncoding` of the
148
+ * transform). For an unmodified transform (e.g. `DynamoModel.DateString`
149
+ * with a matching ISO-string annotation), the two agree and the field is
150
+ * accepted.
151
+ *
152
+ * Throws at `Entity.make()` time if the conflict is detected.
153
+ *
154
+ * @internal
155
+ */
156
+ export declare const validateNoTransformOverride: (modelFields: SchemaFields, configuredAttributes: ConfiguredAttributeEncodings) => void;
157
+ export interface DerivedSchemas {
158
+ /** Pure model fields schema (substituted — used for both validation and decode) */
159
+ readonly modelSchema: Schema.Codec<any>;
160
+ /** Model + system fields schema */
161
+ readonly recordSchema: Schema.Codec<any>;
162
+ /**
163
+ * Typed input schema — the public payload type users see. Ref-aware (ref
164
+ * fields swapped for ID fields). System-colliding `createdAt`/`updatedAt`
165
+ * are marked optional; `version` (if colliding) is stripped.
166
+ *
167
+ * Used both as the public type and as the runtime encode/decode schema.
168
+ */
169
+ readonly inputSchema: Schema.Codec<any>;
170
+ /** Input fields minus primary key composites — the common "create" payload */
171
+ readonly createSchema: Schema.Codec<any>;
172
+ /** Optional model fields minus keys and immutable */
173
+ readonly updateSchema: Schema.Codec<any>;
174
+ /** Primary key composites only */
175
+ readonly keySchema: Schema.Codec<any>;
176
+ /** Record + key attrs + __edd_e__ */
177
+ readonly itemSchema: Schema.Codec<any>;
178
+ /** Record fields + deletedAt for soft-deleted items */
179
+ readonly deletedRecordSchema: Schema.Codec<any>;
180
+ /**
181
+ * `appendInput` schema for `.append()` on time-series entities.
182
+ * `null` when the entity is not configured with `timeSeries`.
183
+ */
184
+ readonly appendInputSchema: Schema.Codec<any> | null;
185
+ /**
186
+ * Record schema for history/event items. Same shape as `recordSchema` minus
187
+ * `updatedAt` (time-series auto-suppresses it). `null` when the entity is
188
+ * not configured with `timeSeries`.
189
+ */
190
+ readonly historyRecordSchema: Schema.Codec<any> | null;
191
+ }
192
+ export declare const buildDerivedSchemas: (modelFields: SchemaFields, indexes: globalThis.Record<string, IndexDefinition>, systemFields: ResolvedSystemFields, resolvedRefs?: ReadonlyArray<{
193
+ readonly fieldName: string;
194
+ readonly idFieldName: string;
195
+ readonly identifierSchema: Schema.Top;
196
+ }>, immutableFields?: ReadonlySet<string>, identifierField?: string | undefined, timeSeries?: TimeSeriesConfig<any> | undefined, fieldEncodings?: globalThis.Record<string, DynamoEncoding>, generatedIdField?: string | undefined) => DerivedSchemas;
197
+ export declare const resolveUniqueFields: (def: UniqueConstraintDef) => ReadonlyArray<string>;
198
+ //# sourceMappingURL=EntitySchemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntitySchemas.d.ts","sourceRoot":"","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