grafeo-ogm 2.2.0 → 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/CHANGELOG.md +83 -0
- package/README.md +49 -1
- package/dist/cjs/compilers/mutation.compiler.d.ts +94 -31
- package/dist/cjs/compilers/mutation.compiler.d.ts.map +1 -1
- package/dist/cjs/compilers/mutation.compiler.js +381 -343
- package/dist/cjs/compilers/mutation.compiler.js.map +1 -1
- package/dist/cjs/compilers/selection.compiler.d.ts +1 -1
- package/dist/cjs/compilers/selection.compiler.d.ts.map +1 -1
- package/dist/cjs/compilers/selection.compiler.js +33 -39
- package/dist/cjs/compilers/selection.compiler.js.map +1 -1
- package/dist/cjs/compilers/where.compiler.d.ts +124 -1
- package/dist/cjs/compilers/where.compiler.d.ts.map +1 -1
- package/dist/cjs/compilers/where.compiler.js +371 -102
- package/dist/cjs/compilers/where.compiler.js.map +1 -1
- package/dist/cjs/interface-model.d.ts +20 -10
- package/dist/cjs/interface-model.d.ts.map +1 -1
- package/dist/cjs/interface-model.js +47 -104
- package/dist/cjs/interface-model.js.map +1 -1
- package/dist/cjs/model.d.ts +4 -29
- package/dist/cjs/model.d.ts.map +1 -1
- package/dist/cjs/model.js +46 -129
- package/dist/cjs/model.js.map +1 -1
- package/dist/cjs/policy/nested-writes.d.ts +35 -0
- package/dist/cjs/policy/nested-writes.d.ts.map +1 -0
- package/dist/cjs/policy/nested-writes.js +199 -0
- package/dist/cjs/policy/nested-writes.js.map +1 -0
- package/dist/cjs/policy/types.d.ts +18 -0
- package/dist/cjs/policy/types.d.ts.map +1 -1
- package/dist/cjs/policy/types.js +24 -0
- package/dist/cjs/policy/types.js.map +1 -1
- package/dist/esm/compilers/mutation.compiler.d.ts +94 -31
- package/dist/esm/compilers/mutation.compiler.d.ts.map +1 -1
- package/dist/esm/compilers/mutation.compiler.js +381 -344
- package/dist/esm/compilers/mutation.compiler.js.map +1 -1
- package/dist/esm/compilers/selection.compiler.d.ts +1 -1
- package/dist/esm/compilers/selection.compiler.d.ts.map +1 -1
- package/dist/esm/compilers/selection.compiler.js +33 -39
- package/dist/esm/compilers/selection.compiler.js.map +1 -1
- package/dist/esm/compilers/where.compiler.d.ts +124 -1
- package/dist/esm/compilers/where.compiler.d.ts.map +1 -1
- package/dist/esm/compilers/where.compiler.js +371 -104
- package/dist/esm/compilers/where.compiler.js.map +1 -1
- package/dist/esm/interface-model.d.ts +20 -10
- package/dist/esm/interface-model.d.ts.map +1 -1
- package/dist/esm/interface-model.js +47 -104
- package/dist/esm/interface-model.js.map +1 -1
- package/dist/esm/model.d.ts +4 -29
- package/dist/esm/model.d.ts.map +1 -1
- package/dist/esm/model.js +47 -130
- package/dist/esm/model.js.map +1 -1
- package/dist/esm/policy/nested-writes.d.ts +35 -0
- package/dist/esm/policy/nested-writes.d.ts.map +1 -0
- package/dist/esm/policy/nested-writes.js +193 -0
- package/dist/esm/policy/nested-writes.js.map +1 -0
- package/dist/esm/policy/types.d.ts +18 -0
- package/dist/esm/policy/types.d.ts.map +1 -1
- package/dist/esm/policy/types.js +23 -0
- package/dist/esm/policy/types.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { OGMLogger } from '../execution/executor';
|
|
2
|
-
import type { PermissivePolicy, PolicyContextBundle, RestrictivePolicy } from '../policy/types';
|
|
2
|
+
import type { Operation, PermissivePolicy, PolicyContextBundle, RestrictivePolicy } from '../policy/types';
|
|
3
3
|
import { NodeDefinition, SchemaMetadata } from '../schema/types';
|
|
4
|
+
import { CypherFieldScope } from '../utils/cypher-field-projection';
|
|
4
5
|
export interface WhereResult {
|
|
5
6
|
cypher: string;
|
|
6
7
|
params: Record<string, unknown>;
|
|
@@ -110,6 +111,14 @@ export declare class WhereCompiler {
|
|
|
110
111
|
* responsible for rejecting BEFORE compile — see `Model`.
|
|
111
112
|
*/
|
|
112
113
|
policyContext?: PolicyContextBundle;
|
|
114
|
+
/**
|
|
115
|
+
* Caller-owned `@cypher` prelude scope (v2.3.0). When given, preludes
|
|
116
|
+
* register into it and are NOT returned — the caller emits the scope
|
|
117
|
+
* once, so several compiles against the same variable (a connection's
|
|
118
|
+
* node filter and its target policy) share one `CALL`/`WITH` chain.
|
|
119
|
+
* `preserveVars` is ignored (the scope already carries its own).
|
|
120
|
+
*/
|
|
121
|
+
scope?: CypherFieldScope;
|
|
113
122
|
}): WhereResult;
|
|
114
123
|
/**
|
|
115
124
|
* Explain-path twin of `compile()`, used by `Model.explainPolicies`.
|
|
@@ -129,6 +138,45 @@ export declare class WhereCompiler {
|
|
|
129
138
|
compileForExplain(where: Record<string, unknown> | undefined | null, nodeVar: string, nodeDef: NodeDefinition, paramCounter: {
|
|
130
139
|
count: number;
|
|
131
140
|
}, policyContext: PolicyContextBundle): ExplainWhereResult;
|
|
141
|
+
/**
|
|
142
|
+
* The policy clause guarding a node of a possibly ABSTRACT type for one
|
|
143
|
+
* operation (v2.3.0) — the single construction behind every target-
|
|
144
|
+
* policy consumer (nested selection, traversal filters, nested writes)
|
|
145
|
+
* and `InterfaceModel`'s root clause:
|
|
146
|
+
*
|
|
147
|
+
* - concrete type → its own composed clause for `op` (byte-identical
|
|
148
|
+
* to compiling it directly); `null` when it has no policy for `op`
|
|
149
|
+
* or an override fires.
|
|
150
|
+
* - interface / union →
|
|
151
|
+
* `(CASE WHEN v:M1 THEN <M1 clause> WHEN v:M2 THEN … ELSE false END)`
|
|
152
|
+
* over the concrete members, each branch being exactly that member's
|
|
153
|
+
* own clause (`resolveForType(M, op)` already folds in M's interface
|
|
154
|
+
* policies). A member without a policy for `op`, or whose override
|
|
155
|
+
* fires, is `true`; when EVERY member is `true` the result is `null`
|
|
156
|
+
* (unconstrained, like a concrete type without policies). `ELSE false`
|
|
157
|
+
* excludes a node carrying no known member label (defense in depth).
|
|
158
|
+
*
|
|
159
|
+
* Pre-2.3.0 abstract targets resolved the ABSTRACT type's name, so the
|
|
160
|
+
* implementers' own policies were never applied through relationships.
|
|
161
|
+
*
|
|
162
|
+
* `fallbackOp`: resolve it for a type with NO policy for `op` — the
|
|
163
|
+
* `aggregate` → `read` fallback `Model.aggregate` applies at the root.
|
|
164
|
+
*
|
|
165
|
+
* `preludes` (for `@cypher` fields referenced by a policy) are returned
|
|
166
|
+
* to the caller; nested contexts reject them.
|
|
167
|
+
*
|
|
168
|
+
* @internal
|
|
169
|
+
*/
|
|
170
|
+
compileTargetPolicyClause(typeName: string, varName: string, op: Operation, policyContext: PolicyContextBundle, paramCounter: {
|
|
171
|
+
count: number;
|
|
172
|
+
}, fallbackOp?: Operation): {
|
|
173
|
+
cypher: string | null;
|
|
174
|
+
params: Record<string, unknown>;
|
|
175
|
+
preludes: string[];
|
|
176
|
+
};
|
|
177
|
+
private compileConcreteTargetClause;
|
|
178
|
+
/** Concrete members of an interface / union; `null` for any other type. */
|
|
179
|
+
private abstractMembers;
|
|
132
180
|
/**
|
|
133
181
|
* Shared body of `compile()` / `compileForExplain()`: compiles the user
|
|
134
182
|
* where, then the policy fragments, sharing one `paramCounter` and one
|
|
@@ -165,6 +213,36 @@ export declare class WhereCompiler {
|
|
|
165
213
|
* nesting (target → target's relationship → ...) keeps cascading.
|
|
166
214
|
*/
|
|
167
215
|
private buildTargetBundle;
|
|
216
|
+
/**
|
|
217
|
+
* Compile a traversal's filter against its target node with the
|
|
218
|
+
* caller's filter (`user`) and the target's `read` policy (`policy`)
|
|
219
|
+
* kept SEPARATE, so each quantifier composes them correctly — the
|
|
220
|
+
* policy must never sit inside a negation (v2.3.0). Pre-2.3.0 the policy
|
|
221
|
+
* was compiled INTO the filter, so `_ALL` (`NOT (user AND policy)`) was
|
|
222
|
+
* falsified by hidden related nodes (an existence oracle), and a
|
|
223
|
+
* connection `node_NOT` was SATISFIED by them.
|
|
224
|
+
*
|
|
225
|
+
* - no policy context → plain compile.
|
|
226
|
+
* - concrete target → one `compileUserAndPolicy` pass (shared `@cypher`
|
|
227
|
+
* prelude scope); the bundle cascades as `NO_ROOT_POLICY` at any depth.
|
|
228
|
+
* - interface target → filter via a `NO_ROOT_POLICY` traversal bundle,
|
|
229
|
+
* policy via `compileTargetPolicyClause` (CASE over the members'
|
|
230
|
+
* own clauses — pre-2.3.0 only the interface's own policies ran).
|
|
231
|
+
*
|
|
232
|
+
* `''` for an absent part. With `scope`, concrete-target preludes
|
|
233
|
+
* register into it (caller emits); otherwise they are returned.
|
|
234
|
+
* Shared with `SelectionCompiler`'s nested-projection filters.
|
|
235
|
+
*
|
|
236
|
+
* @internal
|
|
237
|
+
*/
|
|
238
|
+
compileTargetBody(where: Record<string, unknown> | undefined | null, targetVar: string, targetDef: NodeDefinition, counter: {
|
|
239
|
+
count: number;
|
|
240
|
+
}, policyContext: PolicyContextBundle | undefined, scope?: CypherFieldScope): {
|
|
241
|
+
user: string;
|
|
242
|
+
policy: string;
|
|
243
|
+
params: Record<string, unknown>;
|
|
244
|
+
preludes: string[];
|
|
245
|
+
};
|
|
168
246
|
private compileConditions;
|
|
169
247
|
/**
|
|
170
248
|
* Resolve the Cypher reference for a where-clause field. For stored
|
|
@@ -195,6 +273,37 @@ export declare class WhereCompiler {
|
|
|
195
273
|
* Multiple members are combined with OR.
|
|
196
274
|
*/
|
|
197
275
|
private compileUnionRelationship;
|
|
276
|
+
/**
|
|
277
|
+
* Compile `<key>: null` on a node (v2.3.0). The operator suffix is split
|
|
278
|
+
* off FIRST: pre-2.3.0 the whole key was treated as a property name, so
|
|
279
|
+
* the common "is not null" idiom `{ deletedAt_NOT: null }` compiled to
|
|
280
|
+
* `n.deletedAt_NOT IS NULL` — always true, silently matching every row
|
|
281
|
+
* (and silently restricting nothing when used in a restrictive policy).
|
|
282
|
+
*
|
|
283
|
+
* field: null → field IS NULL
|
|
284
|
+
* field_NOT: null → field IS NOT NULL
|
|
285
|
+
* rel: null → NOT EXISTS { MATCH (n)-[:REL]->(…) }
|
|
286
|
+
* rel_NOT: null → EXISTS { MATCH (n)-[:REL]->(…) }
|
|
287
|
+
* any other operator → OGMError (null has no meaning there)
|
|
288
|
+
* undeclared field → OGMError regardless of `strictWhere` — a null
|
|
289
|
+
* filter on an undeclared field matches every
|
|
290
|
+
* row (fail OPEN), unlike a non-null one
|
|
291
|
+
*
|
|
292
|
+
* A field literally named `key` always wins over suffix parsing.
|
|
293
|
+
*/
|
|
294
|
+
private compileNullCondition;
|
|
295
|
+
/**
|
|
296
|
+
* Scalar half of the null semantics above, shared by node properties and
|
|
297
|
+
* relationship-edge properties: `IS NULL` / `IS NOT NULL`, or an
|
|
298
|
+
* `OGMError` for any other operator and for undeclared fields.
|
|
299
|
+
*/
|
|
300
|
+
private compileNullScalar;
|
|
301
|
+
/**
|
|
302
|
+
* `NOT EXISTS` (no related node) / `EXISTS` (at least one) for a
|
|
303
|
+
* relationship null filter. Byte-identical to the pre-2.3.0 `rel: null`
|
|
304
|
+
* emission for the `NOT EXISTS` case.
|
|
305
|
+
*/
|
|
306
|
+
private compileRelationshipExistence;
|
|
198
307
|
private compileEdgeConditions;
|
|
199
308
|
/**
|
|
200
309
|
* Compile a scalar where-condition. If `fieldName` resolves to a
|
|
@@ -205,6 +314,20 @@ export declare class WhereCompiler {
|
|
|
205
314
|
*/
|
|
206
315
|
private compileScalarCondition;
|
|
207
316
|
}
|
|
317
|
+
/**
|
|
318
|
+
* Stitch a user where-body and a policy clause into a single Cypher
|
|
319
|
+
* fragment. Both come from `compileConditions` so each is already a
|
|
320
|
+
* valid boolean expression. Empty user bodies skip the AND wrap.
|
|
321
|
+
*/
|
|
322
|
+
export declare function stitchUserAndPolicy(userBody: string, policyClause: string): string;
|
|
323
|
+
/**
|
|
324
|
+
* The bundle a traversal's USER filter compiles under (v2.3.0): no clause
|
|
325
|
+
* for the target itself (its policy is composed separately by the caller),
|
|
326
|
+
* but `resolveForType` stays live so deeper traversals keep enforcing.
|
|
327
|
+
*
|
|
328
|
+
* @internal
|
|
329
|
+
*/
|
|
330
|
+
export declare function traversalBundle(policyContext: PolicyContextBundle): PolicyContextBundle;
|
|
208
331
|
/**
|
|
209
332
|
* The boolean value ONE compiled policy contributes to
|
|
210
333
|
* `composePolicyClause`, as a standalone expression (explain path): a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"where.compiler.d.ts","sourceRoot":"","sources":["../../../src/compilers/where.compiler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,KAAK,EACV,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EAClB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,cAAc,EAGd,cAAc,EACf,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"where.compiler.d.ts","sourceRoot":"","sources":["../../../src/compilers/where.compiler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EAClB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,cAAc,EAGd,cAAc,EACf,MAAM,iBAAiB,CAAC;AAMzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAWpE,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE,gBAAgB,GAAG,iBAAiB,CAAC;IACtD,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CACvC;AAED;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,WAAW,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;IACpD,QAAQ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