joist-core 2.2.0-next.9 → 2.3.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/build/Aliases.d.ts.map +1 -1
- package/build/Aliases.js.map +1 -1
- package/build/BaseEntity.d.ts +2 -0
- package/build/BaseEntity.d.ts.map +1 -1
- package/build/BaseEntity.js.map +1 -1
- package/build/Entity.d.ts +1 -0
- package/build/Entity.d.ts.map +1 -1
- package/build/EntityFilter.d.ts +27 -8
- package/build/EntityFilter.d.ts.map +1 -1
- package/build/EntityFilter.js +18 -0
- package/build/EntityFilter.js.map +1 -1
- package/build/EntityGraphQLFilter.d.ts +3 -0
- package/build/EntityGraphQLFilter.d.ts.map +1 -1
- package/build/EntityGraphQLFilter.js.map +1 -1
- package/build/EntityManager.d.ts +14 -11
- package/build/EntityManager.d.ts.map +1 -1
- package/build/EntityManager.js +61 -28
- package/build/EntityManager.js.map +1 -1
- package/build/EntityMetadata.d.ts +31 -1
- package/build/EntityMetadata.d.ts.map +1 -1
- package/build/EntityMetadata.js +17 -0
- package/build/EntityMetadata.js.map +1 -1
- package/build/IndexManager.d.ts +3 -3
- package/build/IndexManager.d.ts.map +1 -1
- package/build/IndexManager.js +30 -20
- package/build/IndexManager.js.map +1 -1
- package/build/InstanceData.d.ts +2 -0
- package/build/InstanceData.d.ts.map +1 -1
- package/build/InstanceData.js +3 -1
- package/build/InstanceData.js.map +1 -1
- package/build/JoinRows.d.ts +54 -12
- package/build/JoinRows.d.ts.map +1 -1
- package/build/JoinRows.js +114 -44
- package/build/JoinRows.js.map +1 -1
- package/build/QueryParser.d.ts +6 -1
- package/build/QueryParser.d.ts.map +1 -1
- package/build/QueryParser.js +293 -190
- package/build/QueryParser.js.map +1 -1
- package/build/QueryParser.test.d.ts +2 -0
- package/build/QueryParser.test.d.ts.map +1 -0
- package/build/QueryParser.test.js +27 -0
- package/build/QueryParser.test.js.map +1 -0
- package/build/Todo.d.ts +4 -0
- package/build/Todo.d.ts.map +1 -1
- package/build/Todo.js.map +1 -1
- package/build/batchloaders/enumCollectionBatchLoader.d.ts +7 -0
- package/build/batchloaders/enumCollectionBatchLoader.d.ts.map +1 -0
- package/build/batchloaders/enumCollectionBatchLoader.js +54 -0
- package/build/batchloaders/enumCollectionBatchLoader.js.map +1 -0
- package/build/batchloaders/manyToManyBatchLoader.d.ts.map +1 -1
- package/build/batchloaders/manyToManyBatchLoader.js +10 -2
- package/build/batchloaders/manyToManyBatchLoader.js.map +1 -1
- package/build/batchloaders/populateBatchLoader.d.ts.map +1 -1
- package/build/batchloaders/populateBatchLoader.js +26 -8
- package/build/batchloaders/populateBatchLoader.js.map +1 -1
- package/build/batchloaders/recursiveChildrenBatchLoader.d.ts.map +1 -1
- package/build/batchloaders/recursiveChildrenBatchLoader.js +2 -0
- package/build/batchloaders/recursiveChildrenBatchLoader.js.map +1 -1
- package/build/batchloaders/recursiveM2mBatchLoader.d.ts.map +1 -1
- package/build/batchloaders/recursiveM2mBatchLoader.js +1 -3
- package/build/batchloaders/recursiveM2mBatchLoader.js.map +1 -1
- package/build/batchloaders/recursiveParentsBatchLoader.d.ts.map +1 -1
- package/build/batchloaders/recursiveParentsBatchLoader.js +2 -0
- package/build/batchloaders/recursiveParentsBatchLoader.js.map +1 -1
- package/build/changes.d.ts +13 -0
- package/build/changes.d.ts.map +1 -1
- package/build/changes.js +49 -0
- package/build/changes.js.map +1 -1
- package/build/configure.d.ts +2 -0
- package/build/configure.d.ts.map +1 -1
- package/build/configure.js +6 -0
- package/build/configure.js.map +1 -1
- package/build/dataloaders/findCountDataLoader.d.ts +12 -2
- package/build/dataloaders/findCountDataLoader.d.ts.map +1 -1
- package/build/dataloaders/findCountDataLoader.js +45 -5
- package/build/dataloaders/findCountDataLoader.js.map +1 -1
- package/build/dataloaders/findDataLoader.d.ts +44 -9
- package/build/dataloaders/findDataLoader.d.ts.map +1 -1
- package/build/dataloaders/findDataLoader.js +123 -34
- package/build/dataloaders/findDataLoader.js.map +1 -1
- package/build/dataloaders/findIdsDataLoader.js +4 -4
- package/build/dataloaders/findIdsDataLoader.js.map +1 -1
- package/build/dataloaders/findOrCreateDataLoader.d.ts.map +1 -1
- package/build/dataloaders/findOrCreateDataLoader.js +2 -2
- package/build/dataloaders/findOrCreateDataLoader.js.map +1 -1
- package/build/dataloaders/findPaginatedDataLoader.d.ts.map +1 -1
- package/build/dataloaders/findPaginatedDataLoader.js +14 -8
- package/build/dataloaders/findPaginatedDataLoader.js.map +1 -1
- package/build/dataloaders/manyToManyFindDataLoader.js +7 -1
- package/build/dataloaders/manyToManyFindDataLoader.js.map +1 -1
- package/build/fields.d.ts +2 -0
- package/build/fields.d.ts.map +1 -1
- package/build/fields.js +2 -0
- package/build/fields.js.map +1 -1
- package/build/index.d.ts +3 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +4 -1
- package/build/index.js.map +1 -1
- package/build/loadHints.d.ts +4 -4
- package/build/loadHints.d.ts.map +1 -1
- package/build/loadHints.js.map +1 -1
- package/build/loadLens.d.ts.map +1 -1
- package/build/loadLens.js +20 -4
- package/build/loadLens.js.map +1 -1
- package/build/newEntity.d.ts.map +1 -1
- package/build/newEntity.js +16 -14
- package/build/newEntity.js.map +1 -1
- package/build/newTestInstance.d.ts.map +1 -1
- package/build/newTestInstance.js +3 -0
- package/build/newTestInstance.js.map +1 -1
- package/build/normalizeHints.d.ts +7 -0
- package/build/normalizeHints.d.ts.map +1 -1
- package/build/normalizeHints.js +40 -2
- package/build/normalizeHints.js.map +1 -1
- package/build/preloading/JsonAggregatePreloader.d.ts.map +1 -1
- package/build/preloading/JsonAggregatePreloader.js +91 -9
- package/build/preloading/JsonAggregatePreloader.js.map +1 -1
- package/build/preloading/canPreload.d.ts +2 -2
- package/build/preloading/canPreload.d.ts.map +1 -1
- package/build/preloading/canPreload.js +3 -0
- package/build/preloading/canPreload.js.map +1 -1
- package/build/preloading/partitionHint.d.ts.map +1 -1
- package/build/preloading/partitionHint.js +10 -4
- package/build/preloading/partitionHint.js.map +1 -1
- package/build/reactiveHints.d.ts +2 -2
- package/build/reactiveHints.d.ts.map +1 -1
- package/build/reactiveHints.js +9 -0
- package/build/reactiveHints.js.map +1 -1
- package/build/relations/EnumCollection.d.ts +81 -0
- package/build/relations/EnumCollection.d.ts.map +1 -0
- package/build/relations/EnumCollection.js +211 -0
- package/build/relations/EnumCollection.js.map +1 -0
- package/build/relations/ManyToManyCollection.d.ts +1 -0
- package/build/relations/ManyToManyCollection.d.ts.map +1 -1
- package/build/relations/ManyToManyCollection.js +5 -2
- package/build/relations/ManyToManyCollection.js.map +1 -1
- package/build/relations/ManyToManyLargeCollection.d.ts +3 -2
- package/build/relations/ManyToManyLargeCollection.d.ts.map +1 -1
- package/build/relations/ManyToManyLargeCollection.js +7 -4
- package/build/relations/ManyToManyLargeCollection.js.map +1 -1
- package/build/relations/OneToManyCollection.d.ts.map +1 -1
- package/build/relations/OneToManyCollection.js +2 -2
- package/build/relations/OneToManyCollection.js.map +1 -1
- package/build/relations/OneToManyLargeCollection.d.ts.map +1 -1
- package/build/relations/OneToManyLargeCollection.js +2 -1
- package/build/relations/OneToManyLargeCollection.js.map +1 -1
- package/build/relations/ReactiveManyToMany.d.ts +1 -0
- package/build/relations/ReactiveManyToMany.d.ts.map +1 -1
- package/build/relations/ReactiveManyToMany.js +4 -1
- package/build/relations/ReactiveManyToMany.js.map +1 -1
- package/build/relations/ReactiveManyToManyOtherSide.d.ts +1 -0
- package/build/relations/ReactiveManyToManyOtherSide.d.ts.map +1 -1
- package/build/relations/ReactiveManyToManyOtherSide.js +4 -1
- package/build/relations/ReactiveManyToManyOtherSide.js.map +1 -1
- package/build/relations/RecursiveCollection.d.ts +2 -6
- package/build/relations/RecursiveCollection.d.ts.map +1 -1
- package/build/relations/RecursiveCollection.js +9 -17
- package/build/relations/RecursiveCollection.js.map +1 -1
- package/build/relations/RecursiveCycleError.d.ts +13 -0
- package/build/relations/RecursiveCycleError.d.ts.map +1 -0
- package/build/relations/RecursiveCycleError.js +15 -0
- package/build/relations/RecursiveCycleError.js.map +1 -0
- package/build/relations/hasProperty.d.ts +2 -1
- package/build/relations/hasProperty.d.ts.map +1 -1
- package/build/relations/hasProperty.js +15 -5
- package/build/relations/hasProperty.js.map +1 -1
- package/build/relations/index.d.ts +1 -0
- package/build/relations/index.d.ts.map +1 -1
- package/build/relations/index.js +5 -2
- package/build/relations/index.js.map +1 -1
- package/build/rules.js +1 -1
- package/build/rules.js.map +1 -1
- package/build/scopes.d.ts +185 -0
- package/build/scopes.d.ts.map +1 -0
- package/build/scopes.js +302 -0
- package/build/scopes.js.map +1 -0
- package/build/temporal.d.ts +32 -2
- package/build/temporal.d.ts.map +1 -1
- package/build/temporal.js +18 -0
- package/build/temporal.js.map +1 -1
- package/build/upsert.d.ts.map +1 -1
- package/build/upsert.js +9 -2
- package/build/upsert.js.map +1 -1
- package/package.json +7 -7
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { type Alias } from "./Aliases";
|
|
2
|
+
import type { Entity } from "./Entity";
|
|
3
|
+
import type { ExpressionCondition, ExpressionFilter, FilterAndSettings, FilterWithAlias, FindFilter } from "./EntityFilter";
|
|
4
|
+
import type { GraphQLFilterWithAlias } from "./EntityGraphQLFilter";
|
|
5
|
+
import type { EntityManager, FindFilterOptions } from "./EntityManager";
|
|
6
|
+
import type { Loaded, LoadHint } from "./loadHints";
|
|
7
|
+
import type { OrderOf } from "./typeMap";
|
|
8
|
+
/**
|
|
9
|
+
* A scope fragment that introduces its own join aliases: a join tree plus conditions
|
|
10
|
+
* that reference the aliases it binds.
|
|
11
|
+
*
|
|
12
|
+
* Lets a scope express predicates a plain nested filter can't, e.g. a top-level `OR`
|
|
13
|
+
* spanning two different joined tables. Both halves are required — the `where` tree binds
|
|
14
|
+
* the aliases (via `as:`) that `conditions` reference, so neither is meaningful alone.
|
|
15
|
+
*/
|
|
16
|
+
export interface ScopeJoinFilter<T extends Entity> {
|
|
17
|
+
where: FilterWithAlias<T>;
|
|
18
|
+
conditions: ExpressionFilter;
|
|
19
|
+
}
|
|
20
|
+
/** A predicate expressed against a bound alias, i.e. `(a) => a.age.gte(18)`. */
|
|
21
|
+
export type AliasFn<T extends Entity> = (a: Alias<T>) => ExpressionCondition | ExpressionCondition[] | ScopeJoinFilter<T>;
|
|
22
|
+
/**
|
|
23
|
+
* Discriminates an {@link AliasFn} result that is a {@link ScopeJoinFilter} from a bare
|
|
24
|
+
* condition / condition array.
|
|
25
|
+
*
|
|
26
|
+
* A `ScopeJoinFilter` is the only `AliasFn` return that carries both `where` and `conditions`
|
|
27
|
+
* keys; `ExpressionFilter` (`and`/`or`), `ColumnCondition`/`RawCondition` (`kind`), and arrays
|
|
28
|
+
* have neither, so the two-key check is unambiguous.
|
|
29
|
+
*/
|
|
30
|
+
export declare function isScopeJoinFilter<T extends Entity>(result: ExpressionCondition | ExpressionCondition[] | ScopeJoinFilter<T>): result is ScopeJoinFilter<T>;
|
|
31
|
+
/**
|
|
32
|
+
* The fluent builder to either a) terminate/invoke or b) chain scope methods.
|
|
33
|
+
*
|
|
34
|
+
* I.e. `Author.adult` is a ScopeQuery that can either do `.find` or `.popular`.
|
|
35
|
+
*
|
|
36
|
+
* This `ScopeQuery` is just the terminal/invocation methods, the `.popular` methods
|
|
37
|
+
* are chained on via the `Scope` mapped type below.
|
|
38
|
+
*/
|
|
39
|
+
export interface ScopeQuery<T extends Entity> {
|
|
40
|
+
/**
|
|
41
|
+
* ANDs an ad-hoc filter onto the scope, i.e. `Author.adult.where({ firstName: "a1" })`.
|
|
42
|
+
*
|
|
43
|
+
* Accepts either a plain find filter (`{ field: value }`) or an alias callback
|
|
44
|
+
* (`(a) => a.field.eq(value)`) and appends it to the recorded ops — multiple
|
|
45
|
+
* `.where(...)` calls on the same field AND together rather than override.
|
|
46
|
+
*/
|
|
47
|
+
where(where: FilterWithAlias<T>): this;
|
|
48
|
+
where(fn: AliasFn<T>): this;
|
|
49
|
+
/**
|
|
50
|
+
* Appends an `orderBy` to the scope, i.e. `Author.adult.orderBy({ age: "DESC" })`.
|
|
51
|
+
*
|
|
52
|
+
* Chained `.orderBy(...)` calls **accumulate** (the resulting query has every recorded
|
|
53
|
+
* orderBy in declaration order), unlike `.limit`/`.offset`/`.softDeletes` which are
|
|
54
|
+
* last-wins. To replace an existing scope's ordering, pass `orderBy` to the terminal
|
|
55
|
+
* `.find(em, { orderBy: ... })` instead — terminal options override the scope's.
|
|
56
|
+
*/
|
|
57
|
+
orderBy(orderBy: OrderOf<T> | OrderOf<T>[]): this;
|
|
58
|
+
/**
|
|
59
|
+
* Sets the row limit on the scope, i.e. `Author.adult.limit(10)`.
|
|
60
|
+
*
|
|
61
|
+
* Chained `.limit(...)` calls are last-wins — only the most recent value survives compile.
|
|
62
|
+
*/
|
|
63
|
+
limit(limit: number): this;
|
|
64
|
+
/**
|
|
65
|
+
* Sets the row offset on the scope, i.e. `Author.adult.offset(10)`.
|
|
66
|
+
*
|
|
67
|
+
* Chained `.offset(...)` calls are last-wins — only the most recent value survives compile.
|
|
68
|
+
*/
|
|
69
|
+
offset(offset: number): this;
|
|
70
|
+
/**
|
|
71
|
+
* Overrides Joist's default soft-delete handling for this query, i.e.
|
|
72
|
+
* `Author.adult.softDeletes("include")` to see soft-deleted rows.
|
|
73
|
+
*
|
|
74
|
+
* Chained `.softDeletes(...)` calls are last-wins. The effective value also gates
|
|
75
|
+
* how `.where({ relation: ... })` filters that touch soft-delete-aware entities are
|
|
76
|
+
* composed at compile time.
|
|
77
|
+
*/
|
|
78
|
+
softDeletes(softDeletes: "include" | "exclude"): this;
|
|
79
|
+
/**
|
|
80
|
+
* Runs the scope against `em`, returning all matching rows.
|
|
81
|
+
*
|
|
82
|
+
* Terminal options (`orderBy`, `limit`, `offset`, `softDeletes`) passed here
|
|
83
|
+
* **override** anything the scope recorded via `.orderBy(...)`, `.limit(...)`, etc.;
|
|
84
|
+
* `conditions` passed here are ANDed with the scope's compiled conditions rather than
|
|
85
|
+
* replacing them. To extend the scope's ordering instead of replacing it, chain
|
|
86
|
+
* `.orderBy(...)` before `.find(em)`.
|
|
87
|
+
*/
|
|
88
|
+
find(em: EntityManager): Promise<T[]>;
|
|
89
|
+
find<const H extends LoadHint<T>>(em: EntityManager, opts?: FindFilterOptions<T> & {
|
|
90
|
+
populate?: H;
|
|
91
|
+
}): Promise<Loaded<T, H>[]>;
|
|
92
|
+
/** Like {@link find} but returns a single match or `undefined`. Same options precedence as `find`. */
|
|
93
|
+
findOne(em: EntityManager): Promise<T | undefined>;
|
|
94
|
+
findOne<const H extends LoadHint<T>>(em: EntityManager, opts?: FindFilterOptions<T> & {
|
|
95
|
+
populate?: H;
|
|
96
|
+
}): Promise<Loaded<T, H> | undefined>;
|
|
97
|
+
/** Like {@link findOne} but throws if no row matches. Same options precedence as `find`. */
|
|
98
|
+
findOneOrFail(em: EntityManager): Promise<T>;
|
|
99
|
+
findOneOrFail<const H extends LoadHint<T>>(em: EntityManager, opts?: FindFilterOptions<T> & {
|
|
100
|
+
populate?: H;
|
|
101
|
+
}): Promise<Loaded<T, H>>;
|
|
102
|
+
/**
|
|
103
|
+
* Returns the count of rows matching the scope.
|
|
104
|
+
*
|
|
105
|
+
* Recorded `orderBy`/`limit`/`offset` ops are dropped (they're meaningless for a count);
|
|
106
|
+
* `softDeletes` and conditions still apply.
|
|
107
|
+
*/
|
|
108
|
+
findCount(em: EntityManager): Promise<number>;
|
|
109
|
+
/**
|
|
110
|
+
* Returns the tagged ids of rows matching the scope.
|
|
111
|
+
*
|
|
112
|
+
* Like {@link findCount}, recorded `orderBy`/`limit`/`offset` ops are dropped.
|
|
113
|
+
*/
|
|
114
|
+
findIds(em: EntityManager): Promise<string[]>;
|
|
115
|
+
/**
|
|
116
|
+
* Compiles the scope into Joist's `FilterAndSettings` shape for passing to other APIs
|
|
117
|
+
* or for inspection in tests.
|
|
118
|
+
*
|
|
119
|
+
* Useful primarily for debugging — the returned shape captures whatever the terminal
|
|
120
|
+
* `find` methods would have sent to `em.find`, before terminal-options precedence is
|
|
121
|
+
* applied.
|
|
122
|
+
*/
|
|
123
|
+
toFindArgs(): FilterAndSettings<T>;
|
|
124
|
+
}
|
|
125
|
+
/** A scope for entity `T`, with chainable named accessors supplied by `S`. */
|
|
126
|
+
export type Scope<T extends Entity, S = {}> = ScopeQuery<T> & S;
|
|
127
|
+
/**
|
|
128
|
+
* A per-entity, pre-typed function for declaring scopes.
|
|
129
|
+
*
|
|
130
|
+
* I.e. this is the type of the `import { authorScope as scope }` that entity files
|
|
131
|
+
* use to declare their scopes.
|
|
132
|
+
*
|
|
133
|
+
* Because of the `authorScope as scope` rename, we can bake into the API that this
|
|
134
|
+
* is the Author entity, and so simplify its usage.
|
|
135
|
+
*/
|
|
136
|
+
export interface ScopeFn<T extends Entity, R extends Scope<T>> {
|
|
137
|
+
/** Defines a scope based on a filter condition, i.e. `scope({ name: "John" })` or `scope(a => a.name.eq("John")`. */
|
|
138
|
+
(arg: FilterWithAlias<T> | AliasFn<T>): R;
|
|
139
|
+
/** Defines a parametrized filter, i.e. `scope(name => ({ name: { startsWith: name } }))`. */
|
|
140
|
+
fn<A extends unknown[]>(fn: (...args: A) => FilterWithAlias<T> | AliasFn<T>): (...args: A) => R;
|
|
141
|
+
}
|
|
142
|
+
/** A scope fragment that can be expanded against any current query alias. */
|
|
143
|
+
export type ScopeFilterFragment<T extends Entity> = {
|
|
144
|
+
kind: "alias";
|
|
145
|
+
fn: AliasFn<T>;
|
|
146
|
+
} | {
|
|
147
|
+
kind: "filter";
|
|
148
|
+
filter: FilterWithAlias<T>;
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* Fully-expanded scope contents, with named refs resolved and settings collapsed.
|
|
152
|
+
*
|
|
153
|
+
* Deliberately *not* a `ParsedFindQuery`, even though they look adjacent: this is the pre-parse,
|
|
154
|
+
* alias-free *input* we feed into `parseFindQuery`, not its alias-committed AST output. Two reasons
|
|
155
|
+
* the distinction matters:
|
|
156
|
+
* - `fragments` are un-parsed DSL — filter objects plus un-invoked `AliasFn` closures — so the same
|
|
157
|
+
* scope can be re-rooted onto the query's primary alias (`Author.adult.find(em)`) or onto a joined
|
|
158
|
+
* relation alias (`em.find(Book, { author: Author.adult })`). A `ParsedFindQuery` has already baked
|
|
159
|
+
* in concrete aliases like `a`/`b1` and could only be reused via alias-rewrite surgery.
|
|
160
|
+
* - keeping `fragments` as a *list* (rather than one merged condition tree) preserves independent-EXISTS
|
|
161
|
+
* semantics: `.where({ books: ... }).where({ books: ... })` must stay two predicates — one EXISTS each —
|
|
162
|
+
* which a collapsed `ParsedFindQuery.condition` can no longer be split back into.
|
|
163
|
+
*/
|
|
164
|
+
export interface ResolvedScope<T extends Entity> {
|
|
165
|
+
fragments: ScopeFilterFragment<T>[];
|
|
166
|
+
orderBys: OrderOf<T>[];
|
|
167
|
+
limit: number | undefined;
|
|
168
|
+
offset: number | undefined;
|
|
169
|
+
softDeletes: "include" | "exclude" | undefined;
|
|
170
|
+
}
|
|
171
|
+
/** Creates a per-entity, pre-typed scope function. */
|
|
172
|
+
export declare function newScopeFn<T extends Entity, R extends Scope<T>>(entityType: string): ScopeFn<T, R>;
|
|
173
|
+
/** Returns true if `value` is one of our scope proxies. */
|
|
174
|
+
export declare function isScope<T extends Entity>(value: unknown): value is Scope<T>;
|
|
175
|
+
/** Resolves a scope proxy into ordered filter fragments plus collapsed settings. */
|
|
176
|
+
export declare function resolveScope<T extends Entity>(scope: Scope<T>): ResolvedScope<T>;
|
|
177
|
+
/**
|
|
178
|
+
* Returns true for find filters that select every row of the entity type, i.e. an empty `{}` filter
|
|
179
|
+
* or a scope that resolved to no fragments.
|
|
180
|
+
*
|
|
181
|
+
* Used by `em.findCount` and the count dataloader to short-circuit in-memory delete adjustments, which
|
|
182
|
+
* are only safe when the query has no `where`/`conditions` to evaluate created/deleted entities against.
|
|
183
|
+
*/
|
|
184
|
+
export declare function isSelectAllFilter<T extends Entity>(where: FindFilter<T> | GraphQLFilterWithAlias<T>, conditions: ExpressionFilter | undefined):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
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isScopeJoinFilter = isScopeJoinFilter;
|
|
4
|
+
exports.newScopeFn = newScopeFn;
|
|
5
|
+
exports.isScope = isScope;
|
|
6
|
+
exports.resolveScope = resolveScope;
|
|
7
|
+
exports.isSelectAllFilter = isSelectAllFilter;
|
|
8
|
+
const configure_1 = require("./configure");
|
|
9
|
+
/**
|
|
10
|
+
* Discriminates an {@link AliasFn} result that is a {@link ScopeJoinFilter} from a bare
|
|
11
|
+
* condition / condition array.
|
|
12
|
+
*
|
|
13
|
+
* A `ScopeJoinFilter` is the only `AliasFn` return that carries both `where` and `conditions`
|
|
14
|
+
* keys; `ExpressionFilter` (`and`/`or`), `ColumnCondition`/`RawCondition` (`kind`), and arrays
|
|
15
|
+
* have neither, so the two-key check is unambiguous.
|
|
16
|
+
*/
|
|
17
|
+
function isScopeJoinFilter(result) {
|
|
18
|
+
return (typeof result === "object" &&
|
|
19
|
+
result !== null &&
|
|
20
|
+
!Array.isArray(result) &&
|
|
21
|
+
"where" in result &&
|
|
22
|
+
"conditions" in result);
|
|
23
|
+
}
|
|
24
|
+
// Use a symbol so stored scope fragments cannot collide with user-defined scope names.
|
|
25
|
+
const kOps = Symbol("scopeOps");
|
|
26
|
+
const kResolver = Symbol("scopeResolver");
|
|
27
|
+
const kWithScopeOp = Symbol("scopeWithOp");
|
|
28
|
+
// Symbol-keyed so it can't collide with a user's named scope (e.g. `Author.resolve`), which the
|
|
29
|
+
// proxy would otherwise treat as a chained ref.
|
|
30
|
+
const kResolve = Symbol("scopeResolve");
|
|
31
|
+
/** Creates a per-entity, pre-typed scope function. */
|
|
32
|
+
function newScopeFn(entityType) {
|
|
33
|
+
// We won't immediately have access to the EntityMetadata during static field assignment, so provide a lazy handle
|
|
34
|
+
const resolver = {
|
|
35
|
+
entityType,
|
|
36
|
+
maybeGet: () => (0, configure_1.maybeGetMetadataForType)(entityType)?.cstr,
|
|
37
|
+
};
|
|
38
|
+
// Create the scopeFn
|
|
39
|
+
function scopeFn(arg) {
|
|
40
|
+
return newScope(resolver, [toOp(arg)]);
|
|
41
|
+
}
|
|
42
|
+
// But then also add the `.fn(...)` for parameterized scopes
|
|
43
|
+
scopeFn.fn = function scopeFn(fn) {
|
|
44
|
+
return (...args) => newScope(resolver, [toOp(fn(...args))]);
|
|
45
|
+
};
|
|
46
|
+
return scopeFn;
|
|
47
|
+
}
|
|
48
|
+
/** Returns true if `value` is one of our scope proxies. */
|
|
49
|
+
function isScope(value) {
|
|
50
|
+
// A scope is a callable Proxy (so parameterized refs like `Author.adult.named("a")` work), so it's
|
|
51
|
+
// always `typeof === "function"`; that guard also keeps the `in` checks from throwing on primitives.
|
|
52
|
+
return typeof value === "function" && kOps in value && kResolver in value;
|
|
53
|
+
}
|
|
54
|
+
/** Resolves a scope proxy into ordered filter fragments plus collapsed settings. */
|
|
55
|
+
function resolveScope(scope) {
|
|
56
|
+
return asScopeInternalApi(scope)[kResolve]();
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Returns true for find filters that select every row of the entity type, i.e. an empty `{}` filter
|
|
60
|
+
* or a scope that resolved to no fragments.
|
|
61
|
+
*
|
|
62
|
+
* Used by `em.findCount` and the count dataloader to short-circuit in-memory delete adjustments, which
|
|
63
|
+
* are only safe when the query has no `where`/`conditions` to evaluate created/deleted entities against.
|
|
64
|
+
*/
|
|
65
|
+
function isSelectAllFilter(where, conditions) {
|
|
66
|
+
if (conditions !== undefined)
|
|
67
|
+
return false;
|
|
68
|
+
if (isScope(where))
|
|
69
|
+
return resolveScope(where).fragments.length === 0;
|
|
70
|
+
return Object.keys(where).length === 0;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Creates an immutable scope proxy with `ops` as its current scope fragments.
|
|
74
|
+
*
|
|
75
|
+
* The proxy target is a function so the proxy is callable (for parameterized refs
|
|
76
|
+
* like `Author.adult.named("a")`); unknown property accesses always record a `ref`
|
|
77
|
+
* op, with validation against the entity constructor deferred until `compile` runs.
|
|
78
|
+
*/
|
|
79
|
+
function newScope(resolver, ops) {
|
|
80
|
+
const terminals = new ScopeTerminals(resolver, ops);
|
|
81
|
+
function callable() { }
|
|
82
|
+
Object.defineProperty(callable, kOps, { value: ops });
|
|
83
|
+
Object.defineProperty(callable, kResolver, { value: resolver });
|
|
84
|
+
return new Proxy(callable, {
|
|
85
|
+
get(target, prop) {
|
|
86
|
+
if (prop === kOps || prop === kResolver)
|
|
87
|
+
return Reflect.get(target, prop);
|
|
88
|
+
if (typeof prop === "symbol" || prop in terminals) {
|
|
89
|
+
const value = Reflect.get(terminals, prop, terminals);
|
|
90
|
+
return typeof value === "function" ? value.bind(terminals) : value;
|
|
91
|
+
}
|
|
92
|
+
// `await scope` probes `.then`; returning undefined lets await resolve to the scope itself
|
|
93
|
+
// instead of treating the proxy as a thenable.
|
|
94
|
+
if (prop === "then")
|
|
95
|
+
return undefined;
|
|
96
|
+
return newScope(resolver, [...ops, { kind: "ref", name: prop }]);
|
|
97
|
+
},
|
|
98
|
+
apply(_target, _thisArg, args) {
|
|
99
|
+
// Invoked for chained parameterized refs, i.e. the `("a")` in `Author.adult.named("a")`.
|
|
100
|
+
const lastOp = ops[ops.length - 1];
|
|
101
|
+
if (lastOp?.kind !== "ref")
|
|
102
|
+
throw new Error(`Scope is not parameterized`);
|
|
103
|
+
return newScope(resolver, [...ops.slice(0, -1), { ...lastOp, args }]);
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Concrete builder/terminal methods for a scope proxy.
|
|
109
|
+
*
|
|
110
|
+
* The outer proxy handles dynamic named-scope access like `.popular`; this class handles
|
|
111
|
+
* fixed methods like `.where`, `.find`, and `.toFindArgs`.
|
|
112
|
+
*/
|
|
113
|
+
class ScopeTerminals {
|
|
114
|
+
#ops;
|
|
115
|
+
#resolver;
|
|
116
|
+
constructor(resolver, ops) {
|
|
117
|
+
this.#resolver = resolver;
|
|
118
|
+
this.#ops = ops;
|
|
119
|
+
}
|
|
120
|
+
get [kOps]() {
|
|
121
|
+
return this.#ops;
|
|
122
|
+
}
|
|
123
|
+
/** Flattens our recorded ops (resolving named refs, collapsing settings) into a {@link ResolvedScope}. */
|
|
124
|
+
[kResolve]() {
|
|
125
|
+
return resolveScopeOps(this.#resolver, this.#ops);
|
|
126
|
+
}
|
|
127
|
+
where(arg) {
|
|
128
|
+
return this[kWithScopeOp](toOp(arg));
|
|
129
|
+
}
|
|
130
|
+
orderBy(orderBy) {
|
|
131
|
+
return this[kWithScopeOp]({ kind: "orderBy", orderBy });
|
|
132
|
+
}
|
|
133
|
+
limit(limit) {
|
|
134
|
+
return this[kWithScopeOp]({ kind: "limit", limit });
|
|
135
|
+
}
|
|
136
|
+
offset(offset) {
|
|
137
|
+
return this[kWithScopeOp]({ kind: "offset", offset });
|
|
138
|
+
}
|
|
139
|
+
softDeletes(value) {
|
|
140
|
+
return this[kWithScopeOp]({ kind: "softDeletes", value });
|
|
141
|
+
}
|
|
142
|
+
toFindArgs() {
|
|
143
|
+
return compile(this.#resolver, this.#ops);
|
|
144
|
+
}
|
|
145
|
+
find(em, opts) {
|
|
146
|
+
const args = compile(this.#resolver, this.#ops);
|
|
147
|
+
return em.find(resolveCstr(this.#resolver), args.where, toFindOptions(args, opts));
|
|
148
|
+
}
|
|
149
|
+
findOne(em, opts) {
|
|
150
|
+
const args = compile(this.#resolver, this.#ops);
|
|
151
|
+
return em.findOne(resolveCstr(this.#resolver), args.where, toFindOptions(args, opts));
|
|
152
|
+
}
|
|
153
|
+
findOneOrFail(em, opts) {
|
|
154
|
+
const args = compile(this.#resolver, this.#ops);
|
|
155
|
+
return em.findOneOrFail(resolveCstr(this.#resolver), args.where, toFindOptions(args, opts));
|
|
156
|
+
}
|
|
157
|
+
findCount(em) {
|
|
158
|
+
const args = compile(this.#resolver, this.#ops);
|
|
159
|
+
return em.findCount(resolveCstr(this.#resolver), args.where, toCountOptions(args));
|
|
160
|
+
}
|
|
161
|
+
findIds(em) {
|
|
162
|
+
const args = compile(this.#resolver, this.#ops);
|
|
163
|
+
return em.findIds(resolveCstr(this.#resolver), args.where, toCountOptions(args));
|
|
164
|
+
}
|
|
165
|
+
/** Returns a new scope with one more recorded operation. */
|
|
166
|
+
[kWithScopeOp](op) {
|
|
167
|
+
return newScope(this.#resolver, [...this.#ops, op]);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/** Compiles the ordered scope ops into Joist's existing find args shape. */
|
|
171
|
+
function compile(resolver, ops) {
|
|
172
|
+
const resolved = resolveScopeOps(resolver, ops);
|
|
173
|
+
return {
|
|
174
|
+
// A scope is a valid `FindFilter` `where`, so `em.find` re-parses & expands its fragments.
|
|
175
|
+
where: newScope(resolver, resolved.fragments),
|
|
176
|
+
orderBy: resolved.orderBys.length ? resolved.orderBys : undefined,
|
|
177
|
+
limit: resolved.limit,
|
|
178
|
+
offset: resolved.offset,
|
|
179
|
+
softDeletes: resolved.softDeletes,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
/** Resolves ordered scope ops into filter fragments and root-only settings. */
|
|
183
|
+
function resolveScopeOps(resolver, ops) {
|
|
184
|
+
const fragments = [];
|
|
185
|
+
const orderBys = [];
|
|
186
|
+
const refArgKeys = new WeakMap();
|
|
187
|
+
const nextRefArgKey = { value: 0 };
|
|
188
|
+
let limit;
|
|
189
|
+
let offset;
|
|
190
|
+
let softDeletes;
|
|
191
|
+
function expand(currentOps, seen) {
|
|
192
|
+
for (const op of currentOps) {
|
|
193
|
+
switch (op.kind) {
|
|
194
|
+
case "alias":
|
|
195
|
+
case "filter":
|
|
196
|
+
fragments.push(op);
|
|
197
|
+
break;
|
|
198
|
+
case "orderBy":
|
|
199
|
+
if (Array.isArray(op.orderBy))
|
|
200
|
+
orderBys.push(...op.orderBy);
|
|
201
|
+
else
|
|
202
|
+
orderBys.push(op.orderBy);
|
|
203
|
+
break;
|
|
204
|
+
case "limit":
|
|
205
|
+
limit = op.limit;
|
|
206
|
+
break;
|
|
207
|
+
case "offset":
|
|
208
|
+
offset = op.offset;
|
|
209
|
+
break;
|
|
210
|
+
case "softDeletes":
|
|
211
|
+
softDeletes = op.value;
|
|
212
|
+
break;
|
|
213
|
+
case "ref": {
|
|
214
|
+
const key = scopeRefKey(op, refArgKeys, nextRefArgKey);
|
|
215
|
+
if (seen.has(key))
|
|
216
|
+
break;
|
|
217
|
+
seen.add(key);
|
|
218
|
+
expand(scopeOpsForRef(resolver, op), seen);
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
expand(ops, new Set());
|
|
225
|
+
return { fragments, orderBys, limit, offset, softDeletes };
|
|
226
|
+
}
|
|
227
|
+
/** Resolves a recorded named-scope ref to its underlying ops. */
|
|
228
|
+
function scopeOpsForRef(resolver, op) {
|
|
229
|
+
const cstr = resolveCstr(resolver);
|
|
230
|
+
const sibling = cstr[op.name];
|
|
231
|
+
if (op.args) {
|
|
232
|
+
// Scope proxies are also `typeof === "function"`, so explicitly reject them via `isScope`.
|
|
233
|
+
if (typeof sibling !== "function" || isScope(sibling)) {
|
|
234
|
+
throw new Error(`Scope ${resolver.entityType}.${op.name} is not parameterized`);
|
|
235
|
+
}
|
|
236
|
+
return scopeOpsFromValue(resolver, op.name, sibling(...op.args));
|
|
237
|
+
}
|
|
238
|
+
return scopeOpsFromValue(resolver, op.name, sibling);
|
|
239
|
+
}
|
|
240
|
+
/** Extracts recorded scope ops from a resolved static field. */
|
|
241
|
+
function scopeOpsFromValue(resolver, name, value) {
|
|
242
|
+
if (isScope(value))
|
|
243
|
+
return asScopeInternalApi(value)[kOps];
|
|
244
|
+
if (value === undefined)
|
|
245
|
+
throw new Error(`Invalid scope ${resolver.entityType}.${name}`);
|
|
246
|
+
if (typeof value === "function")
|
|
247
|
+
throw new Error(`Scope ${resolver.entityType}.${name} requires arguments`);
|
|
248
|
+
throw new Error(`${resolver.entityType}.${name} is not a scope`);
|
|
249
|
+
}
|
|
250
|
+
/** Creates a cycle key for named-scope refs without serializing arbitrary entities/functions. */
|
|
251
|
+
function scopeRefKey(op, refArgKeys, nextRefArgKey) {
|
|
252
|
+
return op.args
|
|
253
|
+
? `${op.name}(${op.args.map((arg) => scopeRefArgKey(arg, refArgKeys, nextRefArgKey)).join(",")})`
|
|
254
|
+
: op.name;
|
|
255
|
+
}
|
|
256
|
+
/** Creates a stable per-resolution key for one named-scope argument. */
|
|
257
|
+
function scopeRefArgKey(arg, refArgKeys, nextRefArgKey) {
|
|
258
|
+
if ((typeof arg === "object" && arg !== null) || typeof arg === "function") {
|
|
259
|
+
let key = refArgKeys.get(arg);
|
|
260
|
+
if (key === undefined) {
|
|
261
|
+
key = nextRefArgKey.value;
|
|
262
|
+
nextRefArgKey.value += 1;
|
|
263
|
+
refArgKeys.set(arg, key);
|
|
264
|
+
}
|
|
265
|
+
return `${typeof arg}:${key}`;
|
|
266
|
+
}
|
|
267
|
+
return `${typeof arg}:${JSON.stringify(String(arg))}`;
|
|
268
|
+
}
|
|
269
|
+
/** Narrows a known scope proxy to its internal-only (symbol-keyed) API. */
|
|
270
|
+
function asScopeInternalApi(scope) {
|
|
271
|
+
if (!isScope(scope))
|
|
272
|
+
throw new Error("Invalid scope");
|
|
273
|
+
return scope;
|
|
274
|
+
}
|
|
275
|
+
/** Resolves the lazy entity constructor. */
|
|
276
|
+
function resolveCstr(resolver) {
|
|
277
|
+
const cstr = resolver.maybeGet();
|
|
278
|
+
if (cstr === undefined)
|
|
279
|
+
throw new Error(`Unknown type ${resolver.entityType}`);
|
|
280
|
+
return cstr;
|
|
281
|
+
}
|
|
282
|
+
/** Converts a scope declaration argument into a recorded op. */
|
|
283
|
+
function toOp(arg) {
|
|
284
|
+
return typeof arg === "function"
|
|
285
|
+
? { kind: "alias", fn: arg }
|
|
286
|
+
: { kind: "filter", filter: arg };
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Pulls the option half of `FilterAndSettings` back out for `em.find`.
|
|
290
|
+
*
|
|
291
|
+
* The scope's recorded settings are the defaults; terminal `opts` (orderBy/limit/offset/conditions/
|
|
292
|
+
* populate) override. The scope itself carries no `conditions` — it compiles to a `where` scope that
|
|
293
|
+
* `em.find` expands — so the only conditions are the caller's, which flow through the `...opts` spread.
|
|
294
|
+
*/
|
|
295
|
+
function toFindOptions(args, opts) {
|
|
296
|
+
return { orderBy: args.orderBy, limit: args.limit, offset: args.offset, softDeletes: args.softDeletes, ...opts };
|
|
297
|
+
}
|
|
298
|
+
/** Like `toFindOptions`, but drops the `orderBy`/`limit`/`offset` that `findCount`/`findIds` ignore. */
|
|
299
|
+
function toCountOptions(args) {
|
|
300
|
+
return { softDeletes: args.softDeletes };
|
|
301
|
+
}
|
|
302
|
+
//# sourceMappingURL=scopes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scopes.js","sourceRoot":"","sources":["../src/scopes.ts"],"names":[],"mappings":";;AAyCA,8CAUC;AA8LD,gCAiBC;AAGD,0BAIC;AAGD,oCAEC;AASD,8CAOC;AA7RD,2CAAsD;AAgCtD;;;;;;;GAOG;AACH,SAAgB,iBAAiB,CAC/B,MAAwE;IAExE,OAAO,CACL,OAAO,MAAM,KAAK,QAAQ;QAC1B,MAAM,KAAK,IAAI;QACf,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QACtB,OAAO,IAAI,MAAM;QACjB,YAAY,IAAI,MAAM,CACvB,CAAC;AACJ,CAAC;AA8KD,uFAAuF;AACvF,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAChC,MAAM,SAAS,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AAC1C,MAAM,YAAY,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;AAC3C,gGAAgG;AAChG,gDAAgD;AAChD,MAAM,QAAQ,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AASxC,sD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AACtC,CAAC;AAED,4CAA4C;AAC5C,SAAS,WAAW,CAAmB,QAA+B;IACpE,MAAM,IAAI,GAAG,QAAQ,CAAC,QAAQ,EAAE,CAAC;IACjC,IAAI,IAAI,KAAK,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,gBAAgB,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;IAC/E,OAAO,IAAI,CAAC;AACd,CAAC;AAED,gEAAgE;AAChE,SAAS,IAAI,CAAmB,GAAoC;IAClE,OAAO,OAAO,GAAG,KAAK,UAAU;QAC9B,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,GAAiB,EAAE;QAC1C,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAyB,EAAE,CAAC;AAC5D,CAAC;AAED;;;;;;GAMG;AACH,SAAS,aAAa,CACpB,IAA0B,EAC1B,IAAiC;IAEjC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,GAAG,IAAI,EAAE,CAAC;AACnH,CAAC;AAED,wGAAwG;AACxG,SAAS,cAAc,CAAmB,IAA0B;IAClE,OAAO,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC;AAC3C,CAAC"}
|
package/build/temporal.d.ts
CHANGED
|
@@ -1,9 +1,39 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Intl, type Temporal as TemporalType, type toTemporalInstant } from "temporal-polyfill";
|
|
2
2
|
type RequireTemporal = {
|
|
3
|
-
Temporal: typeof
|
|
3
|
+
Temporal: typeof TemporalType;
|
|
4
4
|
toTemporalInstant: typeof toTemporalInstant;
|
|
5
5
|
Intl: typeof Intl;
|
|
6
6
|
};
|
|
7
|
+
/**
|
|
8
|
+
* Lazily exposes Joist's native-first / polyfill-fallback Temporal detection.
|
|
9
|
+
*
|
|
10
|
+
* This is useful while the joist-orm repo itself has both pre-Node 26, and post-Node 26
|
|
11
|
+
* test coverage, b/c our CI test suite needs the same a) codegen output and b) test suites
|
|
12
|
+
* to "just work" with either Node 24/25 or Node 26, which means they can't have an explicit
|
|
13
|
+
* import to either `temporal-polyfill` or the `Temporal` global.
|
|
14
|
+
*
|
|
15
|
+
* This is exactly what Joist's internal temporal resolution was already working around, so
|
|
16
|
+
* this just exposes an `import { Temporal } from joist-orm` that lets the codegen & tests
|
|
17
|
+
* reuse the same abstraction.
|
|
18
|
+
*/
|
|
19
|
+
export declare const Temporal: typeof TemporalType;
|
|
20
|
+
/**
|
|
21
|
+
* A type-only `Temporal` namespace that merges with the `const Temporal` above.
|
|
22
|
+
*
|
|
23
|
+
* The `const` is only a value, so using `Temporal.PlainDate` / `Temporal.ZonedDateTime` as a
|
|
24
|
+
* type needs a namespace to resolve against. Node 26 has that as a global, but older Node
|
|
25
|
+
* versions don't, so we add it here by pointing the names at `temporal-polyfill`'s types.
|
|
26
|
+
*/
|
|
27
|
+
export declare namespace Temporal {
|
|
28
|
+
type Instant = TemporalType.Instant;
|
|
29
|
+
type ZonedDateTime = TemporalType.ZonedDateTime;
|
|
30
|
+
type PlainDate = TemporalType.PlainDate;
|
|
31
|
+
type PlainTime = TemporalType.PlainTime;
|
|
32
|
+
type PlainDateTime = TemporalType.PlainDateTime;
|
|
33
|
+
type PlainYearMonth = TemporalType.PlainYearMonth;
|
|
34
|
+
type PlainMonthDay = TemporalType.PlainMonthDay;
|
|
35
|
+
type Duration = TemporalType.Duration;
|
|
36
|
+
}
|
|
7
37
|
/**
|
|
8
38
|
* Conditionally/dynamically requires `temporal-polyfill`.
|
|
9
39
|
*
|
package/build/temporal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"temporal.d.ts","sourceRoot":"","sources":["../src/temporal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"temporal.d.ts","sourceRoot":"","sources":["../src/temporal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,QAAQ,IAAI,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAGrG,KAAK,eAAe,GAAG;IACrB,QAAQ,EAAE,OAAO,YAAY,CAAC;IAC9B,iBAAiB,EAAE,OAAO,iBAAiB,CAAC;IAC5C,IAAI,EAAE,OAAO,IAAI,CAAC;CACnB,CAAC;AAGF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,QAAQ,EAOhB,OAAO,YAAY,CAAC;AAEzB;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,WAAW,QAAQ,CAAC;IAChC,KAAY,OAAO,GAAG,YAAY,CAAC,OAAO,CAAC;IAC3C,KAAY,aAAa,GAAG,YAAY,CAAC,aAAa,CAAC;IACvD,KAAY,SAAS,GAAG,YAAY,CAAC,SAAS,CAAC;IAC/C,KAAY,SAAS,GAAG,YAAY,CAAC,SAAS,CAAC;IAC/C,KAAY,aAAa,GAAG,YAAY,CAAC,aAAa,CAAC;IACvD,KAAY,cAAc,GAAG,YAAY,CAAC,cAAc,CAAC;IACzD,KAAY,aAAa,GAAG,YAAY,CAAC,aAAa,CAAC;IACvD,KAAY,QAAQ,GAAG,YAAY,CAAC,QAAQ,CAAC;CAC9C;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,IAAI,eAAe,GAAG,SAAS,CA2BlE;AAED,wBAAgB,eAAe,IAAI,eAAe,CAEjD"}
|
package/build/temporal.js
CHANGED
|
@@ -1,9 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Temporal = void 0;
|
|
3
4
|
exports.maybeRequireTemporal = maybeRequireTemporal;
|
|
4
5
|
exports.requireTemporal = requireTemporal;
|
|
5
6
|
const utils_1 = require("./utils");
|
|
6
7
|
let temporal;
|
|
8
|
+
/**
|
|
9
|
+
* Lazily exposes Joist's native-first / polyfill-fallback Temporal detection.
|
|
10
|
+
*
|
|
11
|
+
* This is useful while the joist-orm repo itself has both pre-Node 26, and post-Node 26
|
|
12
|
+
* test coverage, b/c our CI test suite needs the same a) codegen output and b) test suites
|
|
13
|
+
* to "just work" with either Node 24/25 or Node 26, which means they can't have an explicit
|
|
14
|
+
* import to either `temporal-polyfill` or the `Temporal` global.
|
|
15
|
+
*
|
|
16
|
+
* This is exactly what Joist's internal temporal resolution was already working around, so
|
|
17
|
+
* this just exposes an `import { Temporal } from joist-orm` that lets the codegen & tests
|
|
18
|
+
* reuse the same abstraction.
|
|
19
|
+
*/
|
|
20
|
+
exports.Temporal = new Proxy({}, {
|
|
21
|
+
get(_target, property, receiver) {
|
|
22
|
+
return Reflect.get(requireTemporal().Temporal, property, receiver);
|
|
23
|
+
},
|
|
24
|
+
});
|
|
7
25
|
/**
|
|
8
26
|
* Conditionally/dynamically requires `temporal-polyfill`.
|
|
9
27
|
*
|
package/build/temporal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"temporal.js","sourceRoot":"","sources":["../src/temporal.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"temporal.js","sourceRoot":"","sources":["../src/temporal.ts"],"names":[],"mappings":";;;AAuDA,oDA2BC;AAED,0CAEC;AArFD,mCAA+B;AAO/B,IAAI,QAA6C,CAAC;AAElD;;;;;;;;;;;GAWG;AACU,QAAA,QAAQ,GAAG,IAAI,KAAK,CAC/B,EAAE,EACF;IACE,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ;QAC7B,OAAO,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACrE,CAAC;CACF,CACqB,CAAC;AAoBzB;;;;;GAKG;AACH,SAAgB,oBAAoB;IAClC,+EAA+E;IAC/E,IAAI,QAAQ,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AAC,SAAS,eAAe,CAAC,MAAM,CAAC,CAAC,GACjD,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,CAAC,GACtB,CAAC,SAAS,MAAM,GACd,KAAK,CAAC,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,GACpE,CAAC,CAAC,CAAC,CAAC,GACN,CAAC,SAAS,MAAM,GACd,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,GACxD,CAAC,CAAC,CAAC,CAAC,GACR,CAAC,CAAC,CAAC,CAAC;CACT,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAyM3G;AAED;;GAEG;AACH,wBAAsB,MAAM,CAAC,CAAC,SAAS,MAAM,EAC3C,EAAE,EAAE,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAChC,WAAW,EAAE,8BAA8B,CAAC,CAAC,CAAC,EAC9C,KAAK,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAC1B,OAAO,CAAC,CAAC,CAAC,CAcZ"}
|
package/build/upsert.js
CHANGED
|
@@ -140,8 +140,10 @@ async function updatePartial(entity, input) {
|
|
|
140
140
|
const values = (0, utils_1.toArray)(value);
|
|
141
141
|
const otherMeta = field.otherMetadata();
|
|
142
142
|
const maybeSoftDelete = otherMeta.timestampFields?.deletedAt;
|
|
143
|
-
// Incremental handling
|
|
144
|
-
|
|
143
|
+
// Incremental handling. Detect incremental mode by a meaningful `op` value--`op: undefined`/`op: null`
|
|
144
|
+
// is the natural shape of an optional field and must behave like "no op", consistent with how
|
|
145
|
+
// updatePartial treats `value === undefined` and how delete/remove are read by truthiness.
|
|
146
|
+
const anyValueHasOp = values.some((v) => v && typeof v === "object" && !(0, Entity_1.isEntity)(v) && v.op != null);
|
|
145
147
|
if (anyValueHasOp) {
|
|
146
148
|
let anyValueMissingOp = false;
|
|
147
149
|
const current = entity[name];
|
|
@@ -171,6 +173,11 @@ async function updatePartial(entity, input) {
|
|
|
171
173
|
else if (op === "incremental") {
|
|
172
174
|
// This is a marker entry, just ignore it
|
|
173
175
|
}
|
|
176
|
+
else {
|
|
177
|
+
// A child entered incremental mode (a sibling had a real op) but has no op of its own;
|
|
178
|
+
// never silently skip it--flag it so the guard below throws instead of dropping the row.
|
|
179
|
+
anyValueMissingOp = true;
|
|
180
|
+
}
|
|
174
181
|
}));
|
|
175
182
|
if (anyValueMissingOp) {
|
|
176
183
|
throw new Error("If any child sets the `op` key, then all children must have the `op` key.");
|