@zanzojs/core 0.1.0-beta.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/LICENSE +21 -0
- package/README.md +123 -0
- package/dist/index.cjs +546 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +407 -0
- package/dist/index.d.ts +407 -0
- package/dist/index.js +533 -0
- package/dist/index.js.map +1 -0
- package/package.json +61 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a parsed, validated Zanzo entity reference.
|
|
3
|
+
* All entity identifiers in Zanzo follow the "Type:ID" convention.
|
|
4
|
+
*/
|
|
5
|
+
interface EntityRef {
|
|
6
|
+
readonly type: string;
|
|
7
|
+
readonly id: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The canonical separator used to join EntityRef parts into a string.
|
|
11
|
+
* Both expandTuples and the Drizzle adapter depend on this constant.
|
|
12
|
+
* Never hardcode ':' for entity refs anywhere else in the codebase.
|
|
13
|
+
*/
|
|
14
|
+
declare const ENTITY_REF_SEPARATOR: ":";
|
|
15
|
+
/**
|
|
16
|
+
* The canonical separator used to join nested relation path segments.
|
|
17
|
+
* Both expandTuples and the Drizzle adapter depend on this constant.
|
|
18
|
+
* Never hardcode '.' for relation paths anywhere else in the codebase.
|
|
19
|
+
*/
|
|
20
|
+
declare const RELATION_PATH_SEPARATOR: ".";
|
|
21
|
+
/**
|
|
22
|
+
* Parses a "Type:ID" string into a structured EntityRef.
|
|
23
|
+
* Validates format strictly at the boundary.
|
|
24
|
+
*
|
|
25
|
+
* @throws Error if the string does not contain exactly one ':' separator,
|
|
26
|
+
* or if type or id segments are empty.
|
|
27
|
+
*/
|
|
28
|
+
declare function parseEntityRef(raw: string): EntityRef;
|
|
29
|
+
/**
|
|
30
|
+
* Serializes an EntityRef back to its canonical "Type:ID" string form.
|
|
31
|
+
*/
|
|
32
|
+
declare function serializeEntityRef(entityRef: EntityRef): string;
|
|
33
|
+
/**
|
|
34
|
+
* Convenience factory. Equivalent to parseEntityRef but named for ergonomics.
|
|
35
|
+
* Use this at API boundaries when constructing entity identifiers.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ref('User:123') // { type: 'User', id: '123' }
|
|
39
|
+
* ref('Project:A') // { type: 'Project', id: 'A' }
|
|
40
|
+
*/
|
|
41
|
+
declare function ref(raw: string): EntityRef;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* ZANZO-REVIEW: Hemos eliminado los aliases opacos (Resource, Action, Relation, Role) en favor de `string` puro.
|
|
45
|
+
* Usar Branded Types habría roto la ergonomía del API Builder al exigir aserciones manuales
|
|
46
|
+
* de tipos literales en los genéricos (ej. '.entity("User" as Resource)').
|
|
47
|
+
* El formato esperado se documenta nativamente.
|
|
48
|
+
*/
|
|
49
|
+
/**
|
|
50
|
+
* Strict Permission format mapping a Resource to an Action.
|
|
51
|
+
* Automatically infers specific strings from string literals.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* type MyPerm = Permission<'Project', 'read' | 'write'>;
|
|
55
|
+
* // 'Project:read' | 'Project:write'
|
|
56
|
+
*/
|
|
57
|
+
type Permission<R extends string, A extends string> = `${R}:${A}`;
|
|
58
|
+
/**
|
|
59
|
+
* Extracts the Action type from a given Permission string type.
|
|
60
|
+
*/
|
|
61
|
+
type ExtractAction<P extends string> = P extends `${string}:${infer A}` ? A : never;
|
|
62
|
+
/**
|
|
63
|
+
* Extracts the Resource type from a given Permission string type.
|
|
64
|
+
*/
|
|
65
|
+
type ExtractResource<P extends string> = P extends `${infer R}:${string}` ? R : never;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Definition for an entity in the ReBAC schema.
|
|
69
|
+
*/
|
|
70
|
+
interface EntityDefinition<A extends string = string, R extends Record<string, string> = Record<string, string>> {
|
|
71
|
+
actions: A[];
|
|
72
|
+
relations?: R;
|
|
73
|
+
permissions?: Partial<Record<A, Array<Extract<keyof R, string> | `${Extract<keyof R, string>}.${string}`>>>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Internal representation of the ReBAC schema.
|
|
77
|
+
*/
|
|
78
|
+
type SchemaData = Record<string, EntityDefinition<any, any>>;
|
|
79
|
+
/**
|
|
80
|
+
* A fluent API builder for constructing a ReBAC schema.
|
|
81
|
+
* Uses advanced generics to carry type information through chained calls
|
|
82
|
+
* for maximum type safety and inference.
|
|
83
|
+
*/
|
|
84
|
+
declare class ZanzoBuilder<TSchema extends SchemaData = {}> {
|
|
85
|
+
private schema;
|
|
86
|
+
constructor(initialSchema?: TSchema);
|
|
87
|
+
/**
|
|
88
|
+
* Defines a new entity (resource) in the schema.
|
|
89
|
+
*
|
|
90
|
+
* @param name The name of the entity resource (e.g., 'User', 'Project')
|
|
91
|
+
* @param definition The definition containing allowed actions and relations.
|
|
92
|
+
* @returns A new ZanzoBuilder instance carrying the expanded type information.
|
|
93
|
+
*/
|
|
94
|
+
entity<TName extends string, TActions extends string, TRelations extends Record<string, keyof TSchema | string> = Record<never, never>>(name: TName, definition: {
|
|
95
|
+
actions: readonly TActions[];
|
|
96
|
+
relations?: TRelations;
|
|
97
|
+
permissions?: Partial<Record<TActions, readonly (keyof TRelations | `${Extract<keyof TRelations, string>}.${string}`)[]>>;
|
|
98
|
+
}): ZanzoBuilder<TSchema & {
|
|
99
|
+
[K in TName]: {
|
|
100
|
+
actions: TActions[];
|
|
101
|
+
relations: TRelations;
|
|
102
|
+
permissions: Partial<Record<TActions, (keyof TRelations | `${Extract<keyof TRelations, string>}.${string}`)[]>>;
|
|
103
|
+
};
|
|
104
|
+
}>;
|
|
105
|
+
/**
|
|
106
|
+
* Builds and freezes the schema, preventing further modifications.
|
|
107
|
+
*
|
|
108
|
+
* @returns The immutable, frozen ReBAC schema.
|
|
109
|
+
*/
|
|
110
|
+
build(): Readonly<TSchema>;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* UnionToIntersection is a TypeScript utility that converts a union of types into an intersection.
|
|
114
|
+
* Example: `UnionToIntersection<{A: 1} | {B: 2}>` becomes `{A: 1} & {B: 2}`
|
|
115
|
+
*/
|
|
116
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
117
|
+
/**
|
|
118
|
+
* Extracts the tuple types array into a union of their elements.
|
|
119
|
+
*/
|
|
120
|
+
type TupleTypes<T extends readonly any[]> = T[number];
|
|
121
|
+
/**
|
|
122
|
+
* Merges multiple frozen SchemaData objects into a single cohesive Schema.
|
|
123
|
+
* It enforces strict typings so the resulting Schema is an Intersection of all provided subsets.
|
|
124
|
+
*
|
|
125
|
+
* It validates at runtime that no two domain-schemas define the same entity,
|
|
126
|
+
* preventing silent overwrites and "God Object" collisions.
|
|
127
|
+
*
|
|
128
|
+
* @param schemas A rest array of individual built schemas to be merged.
|
|
129
|
+
* @returns A strictly merged and deep-frozen unified SchemaData intersection.
|
|
130
|
+
* @throws Error if overlapping entity definitions are found.
|
|
131
|
+
*/
|
|
132
|
+
declare function mergeSchemas<T extends Readonly<SchemaData>[]>(...schemas: T): Readonly<UnionToIntersection<TupleTypes<T>>>;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Represents a logical combination of multiple conditions in the AST.
|
|
136
|
+
*/
|
|
137
|
+
interface QueryAST {
|
|
138
|
+
operator: 'OR' | 'AND';
|
|
139
|
+
conditions: Condition[];
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* A condition evaluating a single relation path towards a generic target subject.
|
|
143
|
+
*/
|
|
144
|
+
type Condition = DirectCondition | NestedCondition;
|
|
145
|
+
/**
|
|
146
|
+
* Represents a direct, 1-level relation requirement.
|
|
147
|
+
* e.g. "We need to find if this resource has the given `targetSubject` as its `relation`".
|
|
148
|
+
*/
|
|
149
|
+
interface DirectCondition {
|
|
150
|
+
type: 'direct';
|
|
151
|
+
relation: string;
|
|
152
|
+
targetSubject: string;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Represents an inherited relation requirement.
|
|
156
|
+
* e.g. "We need to find an intermediate entity linked via `relation` that can satisfy `nextRelationPath` to reach `targetSubject`".
|
|
157
|
+
*/
|
|
158
|
+
interface NestedCondition {
|
|
159
|
+
type: 'nested';
|
|
160
|
+
relation: string;
|
|
161
|
+
nextRelationPath: string[];
|
|
162
|
+
targetSubject: string;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Represents a logical ReBAC relational tuple binding a Subject to an Object via a Relation.
|
|
167
|
+
* Example: User:1 is the 'owner' of Project:A
|
|
168
|
+
*/
|
|
169
|
+
interface RelationTuple {
|
|
170
|
+
/**
|
|
171
|
+
* The actor or subject Entity, typically format 'Type:ID' (e.g. 'User:123')
|
|
172
|
+
*/
|
|
173
|
+
subject: string;
|
|
174
|
+
/**
|
|
175
|
+
* The relationship linking the subject to the object (e.g. 'owner', 'viewer')
|
|
176
|
+
*/
|
|
177
|
+
relation: string;
|
|
178
|
+
/**
|
|
179
|
+
* The target object Entity, typically format 'Type:ID' (e.g. 'Project:456')
|
|
180
|
+
*/
|
|
181
|
+
object: string;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Extracts all valid Entity Types (Resources) defined in the provided Schema
|
|
185
|
+
*/
|
|
186
|
+
type ExtractSchemaResources<TSchema extends SchemaData> = keyof TSchema;
|
|
187
|
+
/**
|
|
188
|
+
* Extracts all Action string unions allowed for a specific Resource type
|
|
189
|
+
* from the provided Schema.
|
|
190
|
+
*/
|
|
191
|
+
type ExtractSchemaActions<TSchema extends SchemaData, TResource extends keyof TSchema> = TSchema[TResource]['actions'][number];
|
|
192
|
+
/**
|
|
193
|
+
* Advanced Generic ReBAC Engine.
|
|
194
|
+
* Takes a Schema initialized by ZanzoBuilder as its type base to offer strict autocomplete.
|
|
195
|
+
*/
|
|
196
|
+
declare class ZanzoEngine<TSchema extends SchemaData> {
|
|
197
|
+
private schema;
|
|
198
|
+
private index;
|
|
199
|
+
constructor(schema: Readonly<TSchema>);
|
|
200
|
+
/**
|
|
201
|
+
* Retreives the readonly schema structure.
|
|
202
|
+
*/
|
|
203
|
+
getSchema(): Readonly<TSchema>;
|
|
204
|
+
/**
|
|
205
|
+
* Retrieves the read-only relation-graph maps indexing memory objects.
|
|
206
|
+
* Exposing strictly for flat compilers.
|
|
207
|
+
*/
|
|
208
|
+
getIndex(): ReadonlyMap<string, ReadonlyMap<string, ReadonlySet<string>>>;
|
|
209
|
+
private validateInput;
|
|
210
|
+
/**
|
|
211
|
+
* Injects a relation tuple into the in-memory store.
|
|
212
|
+
* Issue #3: Validates all tuple fields before storing to prevent graph poisoning.
|
|
213
|
+
*/
|
|
214
|
+
addTuple(tuple: RelationTuple): void;
|
|
215
|
+
/**
|
|
216
|
+
* Injects multiple relation tuples into the in-memory store.
|
|
217
|
+
*/
|
|
218
|
+
addTuples(tuples: RelationTuple[]): void;
|
|
219
|
+
/**
|
|
220
|
+
* Clears all relation tuples in the memory store.
|
|
221
|
+
*/
|
|
222
|
+
clearTuples(): void;
|
|
223
|
+
/**
|
|
224
|
+
* PERF-2: Evaluates ALL actions for a given actor on a specific resource in a
|
|
225
|
+
* single pass. Returns the list of granted actions.
|
|
226
|
+
*
|
|
227
|
+
* This is more efficient than calling can() per action because:
|
|
228
|
+
* - Identical routes shared by multiple actions are evaluated only once
|
|
229
|
+
* - Early exit when all actions are already resolved
|
|
230
|
+
* - Only one validation pass per (actor, resource) pair
|
|
231
|
+
*
|
|
232
|
+
* @internal This method is public solely because `createZanzoSnapshot` (in compiler/)
|
|
233
|
+
* requires access to it. It is NOT part of the public API contract and may change
|
|
234
|
+
* without notice in any minor version. Making it private would require moving
|
|
235
|
+
* `createZanzoSnapshot` into ZanzoEngine as a method, which would break the current
|
|
236
|
+
* modular architecture where the compiler is a standalone pure function.
|
|
237
|
+
*/
|
|
238
|
+
evaluateAllActions(actor: string, resource: string): string[];
|
|
239
|
+
/**
|
|
240
|
+
* Evaluates if a given actor has permission to perform an action on a specific resource.
|
|
241
|
+
* Leverages TypeScript assertions to provide strict autocompletion based on the schema.
|
|
242
|
+
*
|
|
243
|
+
* @param actor The subject entity string identifier (e.g., 'User:1')
|
|
244
|
+
* @param action The specific action to perform (e.g., 'edit'), strictly typed.
|
|
245
|
+
* @param resource The target resource entity string identifier (e.g., 'Project:A')
|
|
246
|
+
* @returns boolean True if authorized, false otherwise.
|
|
247
|
+
*/
|
|
248
|
+
can<TResourceName extends Extract<ExtractSchemaResources<TSchema>, string>, TAction extends ExtractSchemaActions<TSchema, TResourceName>>(actor: string, action: TAction, resource: `${TResourceName}:${string}`): boolean;
|
|
249
|
+
/**
|
|
250
|
+
* Internal recursive relation evaluation algorithm via Map Indexes.
|
|
251
|
+
*
|
|
252
|
+
* @param actor The original actor trying to accomplish the task
|
|
253
|
+
* @param allowedRoutes Array of relation chains (pre-splitted parts) that grant access
|
|
254
|
+
* @param currentTarget The current entity node in the graph being evaluated
|
|
255
|
+
* @param visited Set of visited nodes to prevent cycles in graph evaluation
|
|
256
|
+
* @returns True if relation path connects target to actor
|
|
257
|
+
*/
|
|
258
|
+
private checkRelationsRecursive;
|
|
259
|
+
/**
|
|
260
|
+
* Generates a database-agnostic Abstract Syntax Tree (AST) representing
|
|
261
|
+
* the logical query needed to verify if the given actor is authorized to
|
|
262
|
+
* perform action on a specific resourceType.
|
|
263
|
+
*
|
|
264
|
+
* Useful for "Query Pushdown", allowing ORMs or databases to evaluate permissions
|
|
265
|
+
* directly across their own relational tables instead of loading data into memory.
|
|
266
|
+
*
|
|
267
|
+
* @param actor The subject entity string identifier (e.g., 'User:1')
|
|
268
|
+
* @param action The specific action to perform (e.g., 'read'), strictly typed.
|
|
269
|
+
* @param resourceType The target resource entity TYPE (e.g., 'Project')
|
|
270
|
+
* @returns QueryAST block if action is valid and has mapped relations, null otherwise.
|
|
271
|
+
*/
|
|
272
|
+
buildDatabaseQuery<TResourceName extends Extract<ExtractSchemaResources<TSchema>, string>, TAction extends ExtractSchemaActions<TSchema, TResourceName>>(actor: string, action: TAction, resourceType: TResourceName): QueryAST | null;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* A compiled, flat JSON representation of authorized actions for a given actor over specific resources.
|
|
277
|
+
* Output Format: Record<ResourceID, string[]>
|
|
278
|
+
* Example: { "Project:A": ["read", "write"] }
|
|
279
|
+
*/
|
|
280
|
+
type CompiledPermissions = Record<string, string[]>;
|
|
281
|
+
/**
|
|
282
|
+
* Compiles a flat JSON object containing all authorized actions a specific actor
|
|
283
|
+
* can perform over every resource currently present in the engine's memory.
|
|
284
|
+
*
|
|
285
|
+
* This strips away all the relational ReBAC graph complexity, allowing lightweight
|
|
286
|
+
* clients (Browsers, Mobile Apps, Edge workers) to do fast O(1) checks.
|
|
287
|
+
*
|
|
288
|
+
* @param engine The initialized ZanzoEngine containing the rules and graph memory
|
|
289
|
+
* @param actor The subject entity string identifier (e.g., 'User:1')
|
|
290
|
+
* @returns CompiledPermissions A flat JSON map answering "what can I do and where?"
|
|
291
|
+
*/
|
|
292
|
+
declare function createZanzoSnapshot<TSchema extends SchemaData>(engine: ZanzoEngine<TSchema>, actor: string): CompiledPermissions;
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* A lightweight, ultra-fast O(1) ReBAC Client intended for Frontend applications
|
|
296
|
+
* or Edge Environments.
|
|
297
|
+
*
|
|
298
|
+
* It operates solely on a pre-compiled JSON mask. It forces 0 dependencies
|
|
299
|
+
* and requires no knowledge of schemas, graph recursion, or Rebac Engines.
|
|
300
|
+
*
|
|
301
|
+
* Issue #5: Uses Map<string, Set<string>> internally for true O(1) lookups.
|
|
302
|
+
* Issue #12: Deep-copies incoming snapshot to prevent external mutation.
|
|
303
|
+
*/
|
|
304
|
+
declare class ZanzoClient {
|
|
305
|
+
private permissions;
|
|
306
|
+
private snapshotCache;
|
|
307
|
+
/**
|
|
308
|
+
* Initializes the client with a strictly flat JSON representation of permissions.
|
|
309
|
+
* The input is deep-copied internally to prevent Prototype Pollution
|
|
310
|
+
* or external mutation attacks.
|
|
311
|
+
*
|
|
312
|
+
* @param compiledPermissions The Record<ResourceID, string[]> derived from `createZanzoSnapshot`
|
|
313
|
+
*/
|
|
314
|
+
constructor(compiledPermissions: CompiledPermissions);
|
|
315
|
+
/**
|
|
316
|
+
* True O(1) constant time evaluation of permissions via Set.has().
|
|
317
|
+
*
|
|
318
|
+
* @param action The specific action to evaluate
|
|
319
|
+
* @param resource The target resource entity identifier
|
|
320
|
+
* @returns boolean True if authorized, False otherwise
|
|
321
|
+
*/
|
|
322
|
+
can(action: string, resource: string): boolean;
|
|
323
|
+
/**
|
|
324
|
+
* Returns the compiled snapshot state as a plain JSON object.
|
|
325
|
+
* Result is cached after first call to avoid re-serialization.
|
|
326
|
+
* Useful for persisting it locally or dumping to Redux/Vuex inside Client apps.
|
|
327
|
+
*/
|
|
328
|
+
getSnapshot(): CompiledPermissions;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Callback que el usuario debe implementar para proveer los objetos hijos
|
|
333
|
+
* de un objeto padre dado una relación específica.
|
|
334
|
+
*
|
|
335
|
+
* Ejemplo: para el tuple `User:1 → admin → Org:A`, el engine necesita saber
|
|
336
|
+
* qué Projects pertenecen a `Org:A` via la relación `org` para poder derivar
|
|
337
|
+
* `User:1 → org.admin → Project:X`.
|
|
338
|
+
*
|
|
339
|
+
* @param parentObject El objeto padre (e.g. "Org:A")
|
|
340
|
+
* @param relationToChildren El nombre de la relación inversa (e.g. "org")
|
|
341
|
+
* @returns Array de identificadores de objetos hijos (e.g. ["Project:1", "Project:2"])
|
|
342
|
+
*/
|
|
343
|
+
type FetchChildrenCallback = (parentObject: string, relationToChildren: string) => Promise<string[]> | string[];
|
|
344
|
+
interface ExpansionContext {
|
|
345
|
+
schema: Readonly<SchemaData>;
|
|
346
|
+
newTuple: RelationTuple;
|
|
347
|
+
fetchChildren: FetchChildrenCallback;
|
|
348
|
+
/**
|
|
349
|
+
* Maximum number of derived tuples allowed before aborting expansion.
|
|
350
|
+
* Prevents denial-of-service via unbounded queue growth in pathological schemas.
|
|
351
|
+
* @default 500
|
|
352
|
+
*/
|
|
353
|
+
maxExpansionSize?: number;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Dado un nuevo tuple base, calcula todas las tuplas derivadas implícitas
|
|
357
|
+
* que deben ser materializadas en la base de datos para que las nested
|
|
358
|
+
* permission paths funcionen correctamente en el adapter SQL.
|
|
359
|
+
*
|
|
360
|
+
* Esta función es PURA en su lógica: solo lee el schema y delega
|
|
361
|
+
* el acceso a datos al callback provisto. No tiene side effects.
|
|
362
|
+
*
|
|
363
|
+
* @remarks
|
|
364
|
+
* **Resolución Transitiva (Nested de múltiples niveles):**
|
|
365
|
+
* Para schemas con paths de más de dos niveles (e.g. `parent.org.admin`), los
|
|
366
|
+
* tuples intermedios también deben ser expandidos. Esta función maneja la
|
|
367
|
+
* propagación completa automáticamente mediante una cola (queue) interna,
|
|
368
|
+
* procesando iterativamente cada nuevo tuple derivado hasta agotar las rutas dinámicas.
|
|
369
|
+
* No requiere llamadas manuales recurrentes por parte del desarrollador.
|
|
370
|
+
*
|
|
371
|
+
* @returns Array de RelationTuple derivados que deben ser insertados
|
|
372
|
+
* junto al tuple original. Si no hay derivaciones, retorna [].
|
|
373
|
+
*/
|
|
374
|
+
declare function expandTuples(ctx: ExpansionContext): Promise<RelationTuple[]>;
|
|
375
|
+
|
|
376
|
+
interface CollapseContext {
|
|
377
|
+
schema: Readonly<SchemaData>;
|
|
378
|
+
/**
|
|
379
|
+
* El tuple base que se está revocando.
|
|
380
|
+
* Debe ser idéntico al tuple base que se pasó a expandTuples originalmente.
|
|
381
|
+
*/
|
|
382
|
+
revokedTuple: RelationTuple;
|
|
383
|
+
fetchChildren: FetchChildrenCallback;
|
|
384
|
+
/**
|
|
385
|
+
* Límite máximo de tuples a procesar en la cola de colapso.
|
|
386
|
+
* Debe ser igual al maxExpansionSize usado al expandir.
|
|
387
|
+
* @default 500
|
|
388
|
+
*/
|
|
389
|
+
maxCollapseSize?: number;
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Calcula todos los tuples derivados que deben ser eliminados de la DB
|
|
393
|
+
* cuando se revoca un tuple base previamente expandido con `expandTuples`.
|
|
394
|
+
*
|
|
395
|
+
* Esta función es el inverso simétrico de `expandTuples`. Usa el mismo
|
|
396
|
+
* algoritmo de queue-based traversal y el mismo `fetchChildren` callback
|
|
397
|
+
* para reconstruir qué tuples derivados existen y deben ser borrados.
|
|
398
|
+
*
|
|
399
|
+
* Es PURA: no elimina nada. Retorna los tuples a eliminar para que
|
|
400
|
+
* el caller decida cómo ejecutar el DELETE en su base de datos.
|
|
401
|
+
*
|
|
402
|
+
* @returns Array de RelationTuple que deben ser eliminados,
|
|
403
|
+
* NO incluye el revokedTuple base (el caller lo elimina por separado).
|
|
404
|
+
*/
|
|
405
|
+
declare function collapseTuples(ctx: CollapseContext): Promise<RelationTuple[]>;
|
|
406
|
+
|
|
407
|
+
export { type CollapseContext, type CompiledPermissions, type Condition, type DirectCondition, ENTITY_REF_SEPARATOR, type EntityDefinition, type EntityRef, type ExpansionContext, type ExtractAction, type ExtractResource, type ExtractSchemaActions, type ExtractSchemaResources, type FetchChildrenCallback, type NestedCondition, type Permission, type QueryAST, RELATION_PATH_SEPARATOR, type RelationTuple, type SchemaData, type TupleTypes, type UnionToIntersection, ZanzoBuilder, ZanzoClient, ZanzoEngine, collapseTuples, createZanzoSnapshot, expandTuples, mergeSchemas, parseEntityRef, ref, serializeEntityRef };
|