@pothos/selection-mapper 0.1.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/.swcrc +10 -0
- package/LICENSE +6 -0
- package/README.md +92 -0
- package/dts/adapter.d.ts +74 -0
- package/dts/adapter.d.ts.map +1 -0
- package/dts/deep-equal.d.ts +7 -0
- package/dts/deep-equal.d.ts.map +1 -0
- package/dts/index.d.ts +13 -0
- package/dts/index.d.ts.map +1 -0
- package/dts/loader-map.d.ts +63 -0
- package/dts/loader-map.d.ts.map +1 -0
- package/dts/matches.d.ts +113 -0
- package/dts/matches.d.ts.map +1 -0
- package/dts/node.d.ts +85 -0
- package/dts/node.d.ts.map +1 -0
- package/dts/plan.d.ts +176 -0
- package/dts/plan.d.ts.map +1 -0
- package/dts/types.d.ts +97 -0
- package/dts/types.d.ts.map +1 -0
- package/dts/walk.d.ts +24 -0
- package/dts/walk.d.ts.map +1 -0
- package/esm/adapter.d.ts +74 -0
- package/esm/adapter.d.ts.map +1 -0
- package/esm/adapter.js +47 -0
- package/esm/adapter.js.map +1 -0
- package/esm/deep-equal.d.ts +7 -0
- package/esm/deep-equal.d.ts.map +1 -0
- package/esm/deep-equal.js +50 -0
- package/esm/deep-equal.js.map +1 -0
- package/esm/index.d.ts +13 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +12 -0
- package/esm/index.js.map +1 -0
- package/esm/loader-map.d.ts +63 -0
- package/esm/loader-map.d.ts.map +1 -0
- package/esm/loader-map.js +197 -0
- package/esm/loader-map.js.map +1 -0
- package/esm/matches.d.ts +113 -0
- package/esm/matches.d.ts.map +1 -0
- package/esm/matches.js +419 -0
- package/esm/matches.js.map +1 -0
- package/esm/node.d.ts +85 -0
- package/esm/node.d.ts.map +1 -0
- package/esm/node.js +232 -0
- package/esm/node.js.map +1 -0
- package/esm/package.json +3 -0
- package/esm/plan.d.ts +176 -0
- package/esm/plan.d.ts.map +1 -0
- package/esm/plan.js +339 -0
- package/esm/plan.js.map +1 -0
- package/esm/types.d.ts +97 -0
- package/esm/types.d.ts.map +1 -0
- package/esm/types.js +10 -0
- package/esm/types.js.map +1 -0
- package/esm/walk.d.ts +24 -0
- package/esm/walk.d.ts.map +1 -0
- package/esm/walk.js +442 -0
- package/esm/walk.js.map +1 -0
- package/lib/adapter.js +43 -0
- package/lib/adapter.js.map +1 -0
- package/lib/deep-equal.js +60 -0
- package/lib/deep-equal.js.map +1 -0
- package/lib/index.js +57 -0
- package/lib/index.js.map +1 -0
- package/lib/loader-map.js +209 -0
- package/lib/loader-map.js.map +1 -0
- package/lib/matches.js +427 -0
- package/lib/matches.js.map +1 -0
- package/lib/node.js +245 -0
- package/lib/node.js.map +1 -0
- package/lib/plan.js +349 -0
- package/lib/plan.js.map +1 -0
- package/lib/types.js +9 -0
- package/lib/types.js.map +1 -0
- package/lib/walk.js +455 -0
- package/lib/walk.js.map +1 -0
- package/package.json +55 -0
- package/src/adapter.ts +96 -0
- package/src/deep-equal.ts +67 -0
- package/src/index.ts +32 -0
- package/src/loader-map.ts +287 -0
- package/src/matches.ts +681 -0
- package/src/node.ts +327 -0
- package/src/plan.ts +454 -0
- package/src/types.ts +123 -0
- package/src/walk.ts +696 -0
package/.swcrc
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
ISC License (ISC)
|
|
2
|
+
Copyright 2021 Michael Hayes
|
|
3
|
+
|
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
|
5
|
+
|
|
6
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# @pothos/selection-mapper
|
|
2
|
+
|
|
3
|
+
The selection-to-query walker shared by `@pothos/plugin-prisma` and `@pothos/plugin-drizzle`. It
|
|
4
|
+
turns the selection set a resolver receives into the ORM plugin's own query format — through
|
|
5
|
+
fragments, variants, directives and indirect includes — and records the loader mappings the
|
|
6
|
+
plugins' field resolvers look up at resolve time.
|
|
7
|
+
|
|
8
|
+
This package is an implementation detail of those plugins. Its exports exist for them and change
|
|
9
|
+
with them: it is not a supported public API, and its versions carry no compatibility promise of
|
|
10
|
+
their own. Use the plugins.
|
|
11
|
+
|
|
12
|
+
The surface is what those plugins import and nothing more: `Plan` (with the statics `Plan.fromInfo`
|
|
13
|
+
and `Plan.forParentRow`), `Adapter` and `NodeAdapter`, the loader-map helpers (`cacheKey`,
|
|
14
|
+
`getLoaderMapping`, `setFieldMapping`, `setLoaderMappings`, `setRowFieldMapping`,
|
|
15
|
+
`setRowMappings`), `selectedFieldNames` and `deepEqual`. Turning a plan into the query a resolver
|
|
16
|
+
is handed is each plugin's own job — prisma's `queryFromInfo` and drizzle's differ — so neither of
|
|
17
|
+
them is here.
|
|
18
|
+
|
|
19
|
+
## Vocabulary
|
|
20
|
+
|
|
21
|
+
- **Selection** — what the GraphQL document asks for: a `SelectionNode`, a selection set, a
|
|
22
|
+
fragment. Always the input side; graphql-js owns the word.
|
|
23
|
+
- **Query** — what the ORM is told to load, in the ORM's own format (prisma
|
|
24
|
+
`{ select, include, ...args }`, drizzle `DBQueryConfig`). Opaque to the walker, which hands
|
|
25
|
+
queries to the adapter and returns what the adapter serializes. The `Query` type parameter.
|
|
26
|
+
- **Model** — the adapter's description of one table or prisma model. One object per model, so
|
|
27
|
+
model identity is model equality.
|
|
28
|
+
- **Node** — one level of the query being built (a model, its columns, its relations, its computed
|
|
29
|
+
values), and the tree of them one root accumulates into. The adapter owns the shape; the walker
|
|
30
|
+
reads only `node.model`.
|
|
31
|
+
- **Plan** — what a traversal collected for one root: the model it loads, the selection it starts
|
|
32
|
+
from, and the merges it collected, in order. A plan holds no node.
|
|
33
|
+
- **Merge** — one item in a plan's list: a type's selection, a variant's, a nested selection's
|
|
34
|
+
relation query, or a field's, each with the query the adapter produced for it.
|
|
35
|
+
- **Play** — to fold a plan's merges into a fresh node, in order, behind a seed selection. Every
|
|
36
|
+
merge is offered to the node being built, so this is where one is accepted or rejected and the
|
|
37
|
+
only place a mapping is recorded. A plan can be played any number of times, behind a different
|
|
38
|
+
seed each time, and a play owns its node, so a caller may merge into what it gets back.
|
|
39
|
+
- **Computed value** — what a node holds that is neither a column nor a relation: a value the ORM
|
|
40
|
+
computes per row (prisma's `_count` keys, drizzle's `extras`). `node.computed` in the shared
|
|
41
|
+
contract; each ORM keeps its own word for it in what its users read.
|
|
42
|
+
- **Mapping** — what a play records for a field whose merge it took, so the field's resolver can
|
|
43
|
+
find its data in the loaded row; absent means the resolver loads its own data.
|
|
44
|
+
- **Position** — where a field is: a link of `{ parent, type, field, node }` running back to the
|
|
45
|
+
field an entry point was called for, handed to a select function and recorded with the field's
|
|
46
|
+
mapping.
|
|
47
|
+
|
|
48
|
+
## The adapter contract
|
|
49
|
+
|
|
50
|
+
An ORM plugin subclasses `Adapter<Model, Query, NodeType>`. Six members must be answered: three
|
|
51
|
+
translate the schema — `modelFor` (a type's `Model`), `typeSelection` and `fieldSelection` (what a
|
|
52
|
+
type and a field select, in the ORM's own `Query` format) — and three accumulate — `createNode`
|
|
53
|
+
for a model, `mergeQuery` into one, `toQuery` for the node written back. The traversal reads
|
|
54
|
+
nothing of a node but its `model`, and nothing of a query at all.
|
|
55
|
+
|
|
56
|
+
The four members below those are the merge rules, and each is inherited with the answer an adapter
|
|
57
|
+
that never shares a slot between two consumers wants: `canMergeQuery` is true, `firstConflict` is
|
|
58
|
+
none, and `mergeNode` and `canMergeNode` round-trip through `toQuery`. `canMergeQuery` and
|
|
59
|
+
`firstConflict` ask the same thing of different callers: one is the yes or no a play gates a merge
|
|
60
|
+
on, the other names the first offending key for an error message. An adapter that gives every
|
|
61
|
+
consumer its own slot therefore writes six methods and nothing more.
|
|
62
|
+
|
|
63
|
+
`MergeOptions` says how one merge differs from a plain one: `asQuery` (a relation query adds no
|
|
64
|
+
columns), `lenient` (conflicting keys are left out rather than refused), `ignoreArgs` (the node's
|
|
65
|
+
own top-level arguments are not compared), and the `alias` the query came from, so an adapter may
|
|
66
|
+
merge same-named relations into one node (prisma, drizzle) or keep one slot per selected field.
|
|
67
|
+
`skipDeferredFragments` defaults to true.
|
|
68
|
+
|
|
69
|
+
`NodeAdapter<Model, Query>` is what the prisma and drizzle adapters extend: the node tree of
|
|
70
|
+
`node.ts` (columns, relations, computed values, arguments) with every merge rule this package
|
|
71
|
+
owns. A subclass writes `visitQuery`, the key loop of its own query, reported key by key to a
|
|
72
|
+
`QueryVisitor`; `toQuery`, the node written back; and optionally `computedConflicts` when its
|
|
73
|
+
computed values are not compared by value — three methods on top of the three translation ones.
|
|
74
|
+
The visitor is reused down the tree, so a merge allocates only what the subclass's own key loop
|
|
75
|
+
already allocated. An ORM whose query is not a tree of columns, relations and computed values
|
|
76
|
+
extends `Adapter` directly.
|
|
77
|
+
|
|
78
|
+
## What an adapter must uphold
|
|
79
|
+
|
|
80
|
+
- A field's `query` may be async, and what is built from it is then a promise. Every API that
|
|
81
|
+
takes one returns a `MaybePromise`, and a caller either awaits it or hands it on.
|
|
82
|
+
- A merge holds the query the adapter produced for it by reference, and a play merges that same
|
|
83
|
+
object however many times the plan is played. A select function that returns a query and then
|
|
84
|
+
mutates it changes what a later play builds. Nothing copies it, because a query is opaque to
|
|
85
|
+
this package and could only be copied by round-tripping it through the adapter on every field.
|
|
86
|
+
- Every play records its loader mappings on the request context, which pothos requires to be an
|
|
87
|
+
object; an adapter whose resolvers read a loaded row another way simply never looks them up.
|
|
88
|
+
- Every select function is handed the `Position` of the field it plans: the field's node, the type
|
|
89
|
+
it was walked on, and a link to the position of the field the plan hangs beneath. The walker
|
|
90
|
+
reads none of it — an adapter that wants a path or a list of segments walks `parent` and
|
|
91
|
+
materializes its own — and records it with the field's mapping, so a resolver can ask the same
|
|
92
|
+
question the select path asked.
|
package/dts/adapter.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ORM boundary: what an adapter tells the traversal, and where the selections it produces
|
|
3
|
+
* accumulate. One class, so an adapter's state and helpers have a home and the members it has
|
|
4
|
+
* nothing to say about are inherited rather than checked for.
|
|
5
|
+
*/
|
|
6
|
+
import type { GraphQLField, GraphQLNamedType } from 'graphql';
|
|
7
|
+
import type { MergeOptions, SelectFn, TypeLevelConflict, WalkedType } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* What the traversal requires of a node: the model it loads. `Model` is the adapter's model
|
|
10
|
+
* description: whatever it needs to look a relation's target up by name. One object per model,
|
|
11
|
+
* so model identity is the same as model equality.
|
|
12
|
+
*/
|
|
13
|
+
export interface NodeBase<Model> {
|
|
14
|
+
model: Model;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The ORM boundary, translation only. `Model` is the model description a node carries, `Query`
|
|
18
|
+
* the ORM's own selection format (prisma `{ select, include, ...args }`, drizzle
|
|
19
|
+
* `DBQueryConfig`), opaque to the traversal, and `NodeType` what selections accumulate into, of
|
|
20
|
+
* which the traversal reads only `model`.
|
|
21
|
+
*
|
|
22
|
+
* Six members must be answered: three translate a schema into queries (`modelFor`,
|
|
23
|
+
* `typeSelection`, `fieldSelection`) and three accumulate them (`createNode`, `mergeQuery`,
|
|
24
|
+
* `toQuery`). The four below those are the merge rules, inherited with the answer an adapter with
|
|
25
|
+
* no conflicts to report wants: nothing ever conflicts, and node-to-node work round-trips through
|
|
26
|
+
* `toQuery`. An adapter that gives every consumer of a relation its own slot inherits all four.
|
|
27
|
+
*
|
|
28
|
+
* `NodeAdapter` in node.ts overrides all four over a concrete query tree, and is what the prisma
|
|
29
|
+
* and drizzle adapters extend; an adapter whose query is not such a tree extends this directly.
|
|
30
|
+
*/
|
|
31
|
+
export declare abstract class Adapter<Model, Query, NodeType extends NodeBase<Model>> {
|
|
32
|
+
/**
|
|
33
|
+
* Whether a fragment under `@defer` is walked. `EntryOptions.skipDeferredFragments` overrides
|
|
34
|
+
* it for one entry point.
|
|
35
|
+
*/
|
|
36
|
+
skipDeferredFragments: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* The model a type carries, or undefined. Does not follow indirect includes (the walker's own
|
|
39
|
+
* `modelOf` does). One object per model: identity is model identity.
|
|
40
|
+
*/
|
|
41
|
+
abstract modelFor(type: GraphQLNamedType): Model | undefined;
|
|
42
|
+
/** What the type always needs, merged whenever the type is entered, or undefined. */
|
|
43
|
+
abstract typeSelection(type: GraphQLNamedType): Query | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* What the field selects: a static query, a select function, or nothing. `type` is the type the
|
|
46
|
+
* field is being walked on (its parent type, or a same-model type the plan moved to), for an
|
|
47
|
+
* adapter that classifies a selection's keys against the parent model.
|
|
48
|
+
*/
|
|
49
|
+
abstract fieldSelection(field: GraphQLField<unknown, unknown>, type: WalkedType): Query | SelectFn<Query> | undefined;
|
|
50
|
+
/** A fresh, empty node for `model`. */
|
|
51
|
+
abstract createNode(model: Model): NodeType;
|
|
52
|
+
/** Folds `query` into `node`, in place. Never mutates `query`. */
|
|
53
|
+
abstract mergeQuery(node: NodeType, query: Query, options?: MergeOptions): void;
|
|
54
|
+
/** The node as a query of this ORM's format. */
|
|
55
|
+
abstract toQuery(node: NodeType): Query;
|
|
56
|
+
/**
|
|
57
|
+
* Whether merging `query` into `node` would leave everything already selected as it is. A yes
|
|
58
|
+
* or no; `firstConflict` is the version that names a key. Inherited: nothing ever conflicts.
|
|
59
|
+
*/
|
|
60
|
+
canMergeQuery(_node: NodeType, _query: Query, _options?: MergeOptions): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* The first key of a type-level `query` that conflicts with what `node` holds, for the error
|
|
63
|
+
* message that names it. Inherited: none.
|
|
64
|
+
*/
|
|
65
|
+
firstConflict(_node: NodeType, _query: Query): TypeLevelConflict | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* `mergeQuery` from another node: everything `from` holds, merged into `node`. Inherited: the
|
|
68
|
+
* round trip through `toQuery`.
|
|
69
|
+
*/
|
|
70
|
+
mergeNode(node: NodeType, from: NodeType): void;
|
|
71
|
+
/** `canMergeQuery` node to node. Inherited: the round trip through `toQuery`. */
|
|
72
|
+
canMergeNode(node: NodeType, from: NodeType): boolean;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExF;;;;GAIG;AACH,MAAM,WAAW,QAAQ,CAAC,KAAK;IAC7B,KAAK,EAAE,KAAK,CAAC;CACd;AAED;;;;;;;;;;;;;;GAcG;AACH,8BAAsB,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,SAAS,QAAQ,CAAC,KAAK,CAAC;IAC1E;;;OAGG;IACH,qBAAqB,UAAQ;IAE7B;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,gBAAgB,GAAG,KAAK,GAAG,SAAS,CAAC;IAE7D,qFAAqF;IACrF,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,gBAAgB,GAAG,KAAK,GAAG,SAAS,CAAC;IAElE;;;;OAIG;IACH,QAAQ,CAAC,cAAc,CACrB,KAAK,EAAE,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,EACrC,IAAI,EAAE,UAAU,GACf,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC;IAEvC,uCAAuC;IACvC,QAAQ,CAAC,UAAU,CAAC,KAAK,EAAE,KAAK,GAAG,QAAQ,CAAC;IAE5C,kEAAkE;IAClE,QAAQ,CAAC,UAAU,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;IAEhF,gDAAgD;IAChD,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,GAAG,KAAK,CAAC;IAExC;;;OAGG;IACH,aAAa,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,EAAE,YAAY,GAAG,OAAO,CAE9E;IAED;;;OAGG;IACH,aAAa,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,GAAG,iBAAiB,GAAG,SAAS,CAE3E;IAED;;;OAGG;IACH,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,GAAG,IAAI,CAE9C;IAED,iFAAiF;IACjF,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,GAAG,OAAO,CAEpD;CACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structural equality for query arguments (`where`, `orderBy`, `take`, ...). Keys holding
|
|
3
|
+
* `undefined` are treated as absent, so `{ where: cond ? filter : undefined }` compares equal to
|
|
4
|
+
* `{}` when the condition is false.
|
|
5
|
+
*/
|
|
6
|
+
export declare function deepEqual(left: unknown, right: unknown): boolean;
|
|
7
|
+
//# sourceMappingURL=deep-equal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deep-equal.d.ts","sourceRoot":"","sources":["../src/deep-equal.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAyDhE"}
|
package/dts/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the ORM plugins use: the `Plan` class with the two entry points on it, the `Adapter`
|
|
3
|
+
* classes their own adapters extend, and the loader-map, usage and equality helpers their
|
|
4
|
+
* adapters and loaders call. Everything else is module-private; see the README.
|
|
5
|
+
*/
|
|
6
|
+
export { Adapter } from './adapter.js';
|
|
7
|
+
export { deepEqual } from './deep-equal.js';
|
|
8
|
+
export { cacheKey, getLoaderMapping, type Mappings, setFieldMapping, setLoaderMappings, setRowFieldMapping, setRowMappings, } from './loader-map.js';
|
|
9
|
+
export { type IndirectInclude, type IndirectPathSegment, type PathSegment, selectedFieldNames, } from './matches.js';
|
|
10
|
+
export { type Node, NodeAdapter, type QueryVisitor } from './node.js';
|
|
11
|
+
export { Plan, type PlayedPlan } from './plan.js';
|
|
12
|
+
export type { MergeOptions, NestedSelection, Position, SelectedFieldNode, SelectFn, WalkedType, } from './types.js';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EACL,QAAQ,EACR,gBAAgB,EAChB,KAAK,QAAQ,EACb,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,GACf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAChB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,KAAK,IAAI,EAAE,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,EAAE,IAAI,EAAE,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AAClD,YAAY,EACV,YAAY,EACZ,eAAe,EACf,QAAQ,EACR,iBAAiB,EACjB,QAAQ,EACR,UAAU,GACX,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { GraphQLResolveInfo } from 'graphql';
|
|
2
|
+
import type { Position } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* What a plan records for one field whose selection was merged: the mappings of the fields walked
|
|
5
|
+
* beneath it, and, for a field a select function planned, the position it was planned at, so a
|
|
6
|
+
* resolver can ask the same question of it that the select path asked. A static selection records
|
|
7
|
+
* the shared empty mapping and has no position: it ran no callback that could have read one.
|
|
8
|
+
*/
|
|
9
|
+
export interface Mapping {
|
|
10
|
+
nested: Mappings;
|
|
11
|
+
position?: Position;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Mappings keyed by `${Type}@${relative.path}`, where the relative path is the aliased field path
|
|
15
|
+
* from the walked field to the mapped field (`Post@edges.node.author`). A resolver beneath the
|
|
16
|
+
* walked field finds a mapping iff the plan that would have loaded its data was merged.
|
|
17
|
+
*/
|
|
18
|
+
export type Mappings = Record<string, Mapping>;
|
|
19
|
+
/** The mapping of a static selection: nothing can ever be recorded beneath one. */
|
|
20
|
+
export declare const EMPTY_MAPPING: Mapping;
|
|
21
|
+
/**
|
|
22
|
+
* Adopts the first mapping recorded for a key; a later one deep-unions into a copy, so a recorded
|
|
23
|
+
* mapping is never changed after the fact (two plays may accept a different subset of the fields).
|
|
24
|
+
*/
|
|
25
|
+
export declare function unionMappings(into: Mapping | undefined, from: Mapping): Mapping;
|
|
26
|
+
/** The string keys of a response path joined by `.`; list indices are dropped. */
|
|
27
|
+
export declare function responsePath(path: GraphQLResolveInfo['path'] | undefined): string;
|
|
28
|
+
export declare function cacheKey(type: string, path: GraphQLResolveInfo['path']): string;
|
|
29
|
+
/**
|
|
30
|
+
* Records the mappings of a plan rooted at the field `info` resolves, under that field's path.
|
|
31
|
+
* The plan loaded the whole field, so its mappings answer for every row of it: they go to the
|
|
32
|
+
* shared tier. Multiple plans can contribute to one field (Relay nodes of different model
|
|
33
|
+
* types share the list's path), so later contributions replace matching keys and retain others.
|
|
34
|
+
*/
|
|
35
|
+
export declare function setLoaderMappings(ctx: object, info: GraphQLResolveInfo, mappings: Mappings): void;
|
|
36
|
+
/**
|
|
37
|
+
* Records a row's mappings and scopes its descendants to this concrete field execution. A
|
|
38
|
+
* descendant's parent is a different object, so row identity alone cannot carry its plan through
|
|
39
|
+
* a relation, connection wrapper, or list. The execution path retains indices to isolate siblings.
|
|
40
|
+
*/
|
|
41
|
+
export declare function setRowMappings(ctx: object, info: GraphQLResolveInfo, mappings: Mappings): void;
|
|
42
|
+
/**
|
|
43
|
+
* Records the mapping of the field `info` resolves (under its own parent type) along with the
|
|
44
|
+
* mappings beneath it, so both the field's resolver and the resolvers below it can look
|
|
45
|
+
* themselves up. `row` is the value the field is about to resolve with: the parent row when it
|
|
46
|
+
* was loaded by the planned query, and the reloaded row when the fallback loader fetched it.
|
|
47
|
+
*/
|
|
48
|
+
export declare function setFieldMapping(ctx: object, info: GraphQLResolveInfo, mapping: Mapping, row: unknown): void;
|
|
49
|
+
/**
|
|
50
|
+
* `setFieldMapping` for a plan that loaded `row` alone: the field's own mapping is recorded
|
|
51
|
+
* against `row` rather than claimed for the whole field, so a sibling row the plan never loaded
|
|
52
|
+
* keeps falling back instead of reading the entry and resolving against data it does not carry.
|
|
53
|
+
*
|
|
54
|
+
* Descendants inherit the mapping through this field's execution scope, even when their parent
|
|
55
|
+
* is a child object or a connection wrapper rather than the row that was reloaded.
|
|
56
|
+
*/
|
|
57
|
+
export declare function setRowFieldMapping(ctx: object, info: GraphQLResolveInfo, mapping: Mapping, row: unknown): void;
|
|
58
|
+
/**
|
|
59
|
+
* The mapping recorded for the field at `path` on `row`, preferring one recorded for that row
|
|
60
|
+
* over the plan's. `row` is the value whose data the mapping describes — the resolver's parent.
|
|
61
|
+
*/
|
|
62
|
+
export declare function getLoaderMapping(ctx: object, path: GraphQLResolveInfo['path'], type: string, row?: unknown): Mapping | null;
|
|
63
|
+
//# sourceMappingURL=loader-map.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader-map.d.ts","sourceRoot":"","sources":["../src/loader-map.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,QAAQ,CAAC;IACjB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE/C,mFAAmF;AACnF,eAAO,MAAM,aAAa,EAAE,OAAkE,CAAC;AAE/F;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,GAAG,SAAS,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAY/E;AAgCD,kFAAkF;AAClF,wBAAgB,YAAY,CAAC,IAAI,EAAE,kBAAkB,CAAC,MAAM,CAAC,GAAG,SAAS,GAAG,MAAM,CAgBjF;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,CAAC,MAAM,CAAC,UAEtE;AAuFD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,EAAE,QAAQ,EAAE,QAAQ,QAU1F;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,EAAE,QAAQ,EAAE,QAAQ,QAEvF;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,kBAAkB,EACxB,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,OAAO,QAOb;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,kBAAkB,EACxB,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,OAAO,QAUb;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,kBAAkB,CAAC,MAAM,CAAC,EAChC,IAAI,EAAE,MAAM,EACZ,GAAG,CAAC,EAAE,OAAO,GACZ,OAAO,GAAG,IAAI,CA0BhB"}
|
package/dts/matches.d.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { type FieldNode, type FragmentDefinitionNode, type FragmentSpreadNode, type GraphQLNamedType, type GraphQLResolveInfo, type GraphQLSchema, type InlineFragmentNode } from 'graphql';
|
|
2
|
+
export interface IndirectPathSegment {
|
|
3
|
+
type?: string;
|
|
4
|
+
name: string;
|
|
5
|
+
}
|
|
6
|
+
export type PathSegment = string | IndirectPathSegment;
|
|
7
|
+
/**
|
|
8
|
+
* Set on a type's extensions (by the errors plugin, or by hand) to say that a selection on the
|
|
9
|
+
* type is really a selection on `getType()`, found under `path` (or any of `paths`).
|
|
10
|
+
*/
|
|
11
|
+
export interface IndirectInclude {
|
|
12
|
+
getType: () => string;
|
|
13
|
+
path?: IndirectPathSegment[];
|
|
14
|
+
paths?: IndirectPathSegment[][];
|
|
15
|
+
}
|
|
16
|
+
export interface Match {
|
|
17
|
+
/** The GraphQL type of the matched field's return type */
|
|
18
|
+
type: GraphQLNamedType;
|
|
19
|
+
field: FieldNode;
|
|
20
|
+
/** Aliased field names from the starting selection to the matched field */
|
|
21
|
+
path: string[];
|
|
22
|
+
deferred: boolean;
|
|
23
|
+
}
|
|
24
|
+
export interface MatchOptions {
|
|
25
|
+
/** A type-level path prepended to every path. */
|
|
26
|
+
prefix?: IndirectPathSegment[];
|
|
27
|
+
/** The alias path the returned matches' paths start with. */
|
|
28
|
+
path?: string[];
|
|
29
|
+
deferred?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/** Just enough of an `Adapter` to look a type's model up. */
|
|
32
|
+
export interface ModelLookup<Model> {
|
|
33
|
+
modelFor: (type: GraphQLNamedType) => Model | undefined;
|
|
34
|
+
}
|
|
35
|
+
/** The include a type carries, if any. */
|
|
36
|
+
export declare function includeOf(type: GraphQLNamedType): IndirectInclude | undefined;
|
|
37
|
+
/** Follows `pothosIndirectInclude.getType()` until a type without one. */
|
|
38
|
+
export declare function resolveType(schema: GraphQLSchema, type: GraphQLNamedType): GraphQLNamedType;
|
|
39
|
+
/**
|
|
40
|
+
* The model of a type, following indirect includes, which `Adapter.modelFor` does not. Every
|
|
41
|
+
* model question the plan asks goes through here.
|
|
42
|
+
*/
|
|
43
|
+
export declare function modelOf<Model>(adapter: ModelLookup<Model>, schema: GraphQLSchema, type: GraphQLNamedType): Model | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* `matches` without the ones whose field returns a model other than `targetType`'s. Several
|
|
46
|
+
* implementations of an interface may share a field name while returning different models, and
|
|
47
|
+
* their selections must never be merged into the same query. Types without a model always match,
|
|
48
|
+
* and a target without one filters nothing.
|
|
49
|
+
*/
|
|
50
|
+
export declare function matchesForModel<Model>(adapter: ModelLookup<Model>, schema: GraphQLSchema, matches: Match[], targetType: GraphQLNamedType): Match[];
|
|
51
|
+
/**
|
|
52
|
+
* One selection set being read, as `eachSelectedField` hands it to a visitor.
|
|
53
|
+
*
|
|
54
|
+
* `type` is the type of the selection set. `expectedType` is the type a field must be selected on
|
|
55
|
+
* for it to count: a field applies only while the two are the same, which is what stops a
|
|
56
|
+
* same-named field under an unrelated fragment from being seen. `resolveFragmentTypes` moves both.
|
|
57
|
+
*/
|
|
58
|
+
export interface SelectionLevel {
|
|
59
|
+
type: GraphQLNamedType;
|
|
60
|
+
expectedType: GraphQLNamedType;
|
|
61
|
+
/** Aliased field names from the starting selection down to this level. */
|
|
62
|
+
path: string[];
|
|
63
|
+
/** Whether a `@defer` was crossed on the way to this level. */
|
|
64
|
+
deferred: boolean;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* What `eachSelectedField` calls at every field that applies. Returning `true` stops the
|
|
68
|
+
* traversal; anything else continues it.
|
|
69
|
+
*/
|
|
70
|
+
export type FieldVisitor = (field: FieldNode, level: SelectionLevel) => boolean | void;
|
|
71
|
+
/**
|
|
72
|
+
* Every field selected at the end of one of `paths`, each with the `deferred` flag
|
|
73
|
+
* `eachSelectedField` computed for it.
|
|
74
|
+
*/
|
|
75
|
+
export declare function findMatches(info: GraphQLResolveInfo, type: GraphQLNamedType, selection: FieldNode | FragmentDefinitionNode | InlineFragmentNode, paths: IndirectPathSegment[][], options?: MatchOptions): Match[];
|
|
76
|
+
/**
|
|
77
|
+
* The first field selected at the end of `path`, in document order, or undefined. The traversal
|
|
78
|
+
* stops at it. The match's `deferred` flag is reported but this function's caller — the
|
|
79
|
+
* `selectedFieldNode` handed to a select function — discards it; see `eachSelectedField` for why
|
|
80
|
+
* over-reporting a deferred selection there is safe.
|
|
81
|
+
*/
|
|
82
|
+
export declare function firstMatch(info: GraphQLResolveInfo, type: GraphQLNamedType, selection: FieldNode, path: IndirectPathSegment[], { prefix }?: Pick<MatchOptions, 'prefix'>): Match | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* The names of the fields the document selects directly beneath the field being resolved, seen
|
|
85
|
+
* through any wrapper on its return type. Every row of a list resolves the field with the same
|
|
86
|
+
* field nodes, so the result is memoised on them for the execution — on the nodes rather than on
|
|
87
|
+
* `info.fieldNodes`, which graphql-js 17 builds anew for every resolve, and beneath that on
|
|
88
|
+
* `info.variableValues` (one object per execution) and the return type.
|
|
89
|
+
*
|
|
90
|
+
* `@skip` and `@include` are honoured, `@defer` is not: a name selected only under a deferred
|
|
91
|
+
* fragment is reported as selected even when the plan that loads the row will not walk it. This
|
|
92
|
+
* is the over-reporting side of the divergence `eachSelectedField` describes, which is the safe
|
|
93
|
+
* side to gate a column or a count on. A caller that needs to know what the plan will actually
|
|
94
|
+
* load must ask the plan.
|
|
95
|
+
*/
|
|
96
|
+
export declare function selectedFieldNames(context: object, info: GraphQLResolveInfo): ReadonlySet<string>;
|
|
97
|
+
export declare function collectSelectedFieldNames(info: GraphQLResolveInfo, returnType?: import("graphql").GraphQLNamedOutputType, fieldNodes?: readonly FieldNode[]): ReadonlySet<string>;
|
|
98
|
+
/**
|
|
99
|
+
* Turns a path handed to `nestedSelection` into an include. A string segment is a field of the
|
|
100
|
+
* type the previous segment reached; the walker narrows through fragments on its own. A
|
|
101
|
+
* `{ name, type }` segment pins the fragment type condition the field must be found under, and
|
|
102
|
+
* is a field of that type.
|
|
103
|
+
*/
|
|
104
|
+
export declare function normalizeInclude(path: PathSegment[], type: GraphQLNamedType, expectedType: GraphQLNamedType | undefined, schema: GraphQLSchema): IndirectInclude;
|
|
105
|
+
/**
|
|
106
|
+
* Whether a field or fragment is under `@skip(if: true)` or `@include(if: false)`. Asked of every
|
|
107
|
+
* selection the traversal reads, so it answers a selection carrying no directive at all — nearly
|
|
108
|
+
* every one — without building a directive's argument values twice.
|
|
109
|
+
*/
|
|
110
|
+
export declare function isSkipped(info: GraphQLResolveInfo, selection: FieldNode | FragmentSpreadNode | InlineFragmentNode): boolean;
|
|
111
|
+
/** Whether a fragment is under `@defer` (when the schema declares the directive). */
|
|
112
|
+
export declare function isDeferred(info: GraphQLResolveInfo, node: FragmentSpreadNode | InlineFragmentNode): boolean;
|
|
113
|
+
//# sourceMappingURL=matches.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matches.d.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wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,GAAG,WAAW,CAAC,MAAM,CAAC,CAkBjG;AAgBD,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,kBAAkB,EACxB,UAAU,2CAAgC,EAC1C,UAAU,GAAE,SAAS,SAAS,EAAoB,GACjD,WAAW,CAAC,MAAM,CAAC,CA4BrB;AAuED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,WAAW,EAAE,EACnB,IAAI,EAAE,gBAAgB,EACtB,YAAY,EAAE,gBAAgB,GAAG,SAAS,EAC1C,MAAM,EAAE,aAAa,GACpB,eAAe,CAiDjB;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,kBAAkB,EACxB,SAAS,EAAE,SAAS,GAAG,kBAAkB,GAAG,kBAAkB,WAiB/D;AAED,qFAAqF;AACrF,wBAAgB,UAAU,CACxB,IAAI,EAAE,kBAAkB,EACxB,IAAI,EAAE,kBAAkB,GAAG,kBAAkB,WAa9C"}
|
package/dts/node.d.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Adapter, type NodeBase } from './adapter.js';
|
|
2
|
+
import type { MergeOptions, TypeLevelConflict } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* One level of the query being built, used by the prisma and drizzle adapters: the model, its
|
|
5
|
+
* arguments, the columns it selects (`null` = every column, which is final: a node never goes
|
|
6
|
+
* back to named columns), its relations and its computed values (prisma `_count` keys, drizzle
|
|
7
|
+
* `extras`). An adapter whose query is not a tree of this shape extends `Adapter` directly.
|
|
8
|
+
*/
|
|
9
|
+
export interface Node<Model> extends NodeBase<Model> {
|
|
10
|
+
args: object;
|
|
11
|
+
columns: Set<string> | null;
|
|
12
|
+
relations: Map<string, Node<Model>>;
|
|
13
|
+
computed: Map<string, unknown>;
|
|
14
|
+
}
|
|
15
|
+
export declare function createNode<Model>(model: Model): Node<Model>;
|
|
16
|
+
/**
|
|
17
|
+
* The only way to obtain a child node: get the relation's node or create it. `value` is what the
|
|
18
|
+
* map holds for the relation, checked here because a thenable is an un-awaited
|
|
19
|
+
* `nestedSelection()` that would otherwise be spread as an empty object.
|
|
20
|
+
*/
|
|
21
|
+
export declare function relation<Model>(node: Node<Model>, name: string, model: Model, value: unknown): Node<Model>;
|
|
22
|
+
/**
|
|
23
|
+
* What an adapter reports for one key of its query. Called by `NodeAdapter.visitQuery`; the
|
|
24
|
+
* visitor decides what to do with the key, so merging, checking and conflict-finding share one
|
|
25
|
+
* key loop per adapter instead of one each.
|
|
26
|
+
*
|
|
27
|
+
* A visitor is re-entrant: `relation` reads the nested query with the same visitor, so a
|
|
28
|
+
* `visitQuery` must hold no state of its own across a callback.
|
|
29
|
+
*/
|
|
30
|
+
export interface QueryVisitor<Model, Query> {
|
|
31
|
+
/** A named column of the model. */
|
|
32
|
+
column(name: string): void;
|
|
33
|
+
/** Every column. Final — a node never goes back to named columns. */
|
|
34
|
+
allColumns(): void;
|
|
35
|
+
/** A relation, with the model it targets and the query selected beneath it. */
|
|
36
|
+
relation(name: string, model: Model, query: Query): void;
|
|
37
|
+
/**
|
|
38
|
+
* A value the ORM computes per row, neither a column nor a relation (prisma `_count` keys,
|
|
39
|
+
* drizzle `extras`). `kind` is what a conflict on it is called to a user of that ORM, whose own
|
|
40
|
+
* word for these is not the shared one (prisma's counts read as a relation).
|
|
41
|
+
*/
|
|
42
|
+
computed(name: string, value: unknown, kind?: TypeLevelConflict['kind']): void;
|
|
43
|
+
/**
|
|
44
|
+
* The query arguments, normalized. A non-empty set replaces whatever the node holds. Reported
|
|
45
|
+
* on every pass, empty or not, since a merge check compares a query's arguments to the node's
|
|
46
|
+
* whether or not the query has any.
|
|
47
|
+
*/
|
|
48
|
+
args(args: object): void;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The adapter the prisma and drizzle adapters extend: the node tree above with every merge,
|
|
52
|
+
* compare and conflict rule this package owns. A subclass answers `visitQuery` and `toQuery`, plus
|
|
53
|
+
* the three translation members of `Adapter`.
|
|
54
|
+
*/
|
|
55
|
+
export declare abstract class NodeAdapter<Model, Query> extends Adapter<Model, Query, Node<Model>> {
|
|
56
|
+
/**
|
|
57
|
+
* One merger and one merge check per adapter, re-used down the tree: each saves and restores
|
|
58
|
+
* the node it is at rather than allocating a visitor per level, so a merge allocates only what
|
|
59
|
+
* the subclass's own `visitQuery` does. They cannot be this object — a lenient merge runs a
|
|
60
|
+
* check inside itself, so one `this` could not hold both cursors.
|
|
61
|
+
*/
|
|
62
|
+
private readonly merger;
|
|
63
|
+
private readonly mergeCheck;
|
|
64
|
+
/** Every key of `query`, read against `model` and reported to `visit`. The ORM's key loop. */
|
|
65
|
+
abstract visitQuery(query: Query, model: Model, visit: QueryVisitor<Model, Query>): void;
|
|
66
|
+
createNode(model: Model): Node<Model>;
|
|
67
|
+
mergeQuery(node: Node<Model>, query: Query, options?: MergeOptions): void;
|
|
68
|
+
canMergeQuery(node: Node<Model>, query: Query, options?: MergeOptions): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Whether `value` cannot join `computed` under `name`. A `deepEqual` against the value already
|
|
71
|
+
* there, which is what an adapter whose computed values are plain values wants; drizzle
|
|
72
|
+
* compares its `extras` by identity, and prisma overrides it for the `_count: true` wildcard.
|
|
73
|
+
*/
|
|
74
|
+
computedConflicts(computed: ReadonlyMap<string, unknown>, name: string, value: unknown): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* The first top-level key of `query` that conflicts with `node`. Top-level only, so the error
|
|
77
|
+
* names the key a user wrote rather than something nested beneath it.
|
|
78
|
+
*/
|
|
79
|
+
firstConflict(node: Node<Model>, query: Query): TypeLevelConflict | undefined;
|
|
80
|
+
/** Node to node, without the serialize/merge round trip. */
|
|
81
|
+
mergeNode(into: Node<Model>, from: Node<Model>): void;
|
|
82
|
+
/** `canMergeQuery` node to node, likewise. */
|
|
83
|
+
canMergeNode(into: Node<Model>, from: Node<Model>): bo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