@world-engines/ladybug-bridge 0.1.0-alpha.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 +46 -0
- package/README.md +3 -0
- package/dist/index.d.ts +704 -0
- package/dist/index.js +3781 -0
- package/dist/view-access-policy.d.ts +153 -0
- package/dist/view-access-policy.js +835 -0
- package/package.json +53 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
export declare const VIEW_ACCESS_POLICY_SCHEMA_VERSION: 2;
|
|
2
|
+
export declare const VIEW_ACCESS_POLICY_ROOT_SUBJECT_ID: "view_policy_root_v2";
|
|
3
|
+
export type ViewAccessMode = "inherit" | "deny" | "read" | "read_write";
|
|
4
|
+
export type EffectiveViewAccessMode = Exclude<ViewAccessMode, "inherit">;
|
|
5
|
+
export type ViewAccessPolicySubjectKind = "root" | "node" | "attr" | "edge";
|
|
6
|
+
export type ViewAccessAttributeOwnerAddress = {
|
|
7
|
+
readonly kind: "node";
|
|
8
|
+
readonly nodeId: string;
|
|
9
|
+
} | {
|
|
10
|
+
readonly kind: "edge";
|
|
11
|
+
readonly sourceNodeId: string;
|
|
12
|
+
readonly destinationNodeId: string;
|
|
13
|
+
readonly relationKind: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Typed, canonical address of one policy subject. Attribute paths are always
|
|
17
|
+
* segmented; a key containing `.` is therefore distinct from nested keys.
|
|
18
|
+
* Vectors are intentionally absent: their policy subject is the owning node.
|
|
19
|
+
*/
|
|
20
|
+
export type ViewAccessPolicyAddress = {
|
|
21
|
+
readonly kind: "root";
|
|
22
|
+
} | {
|
|
23
|
+
readonly kind: "node";
|
|
24
|
+
readonly nodeId: string;
|
|
25
|
+
} | {
|
|
26
|
+
readonly kind: "attr";
|
|
27
|
+
readonly owner: ViewAccessAttributeOwnerAddress;
|
|
28
|
+
readonly path: readonly string[];
|
|
29
|
+
} | {
|
|
30
|
+
readonly kind: "edge";
|
|
31
|
+
readonly sourceNodeId: string;
|
|
32
|
+
readonly destinationNodeId: string;
|
|
33
|
+
readonly relationKind: string;
|
|
34
|
+
};
|
|
35
|
+
/** A runtime target that can be reduced to exactly one policy address. */
|
|
36
|
+
export type ViewAccessPolicyTarget = Exclude<ViewAccessPolicyAddress, {
|
|
37
|
+
readonly kind: "root";
|
|
38
|
+
}> | {
|
|
39
|
+
readonly kind: "vector";
|
|
40
|
+
readonly nodeId: string;
|
|
41
|
+
readonly vectorSpace: string;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* A policy subject's parent is structural only. Graph relations and `$ref`
|
|
45
|
+
* values are deliberately absent from this contract and must never be
|
|
46
|
+
* translated into `structuralParentId` by callers.
|
|
47
|
+
*/
|
|
48
|
+
export type ViewAccessPolicySubject = {
|
|
49
|
+
readonly id: string;
|
|
50
|
+
readonly kind: ViewAccessPolicySubjectKind;
|
|
51
|
+
readonly address: ViewAccessPolicyAddress;
|
|
52
|
+
readonly structuralParentId: string | null;
|
|
53
|
+
readonly mode: ViewAccessMode;
|
|
54
|
+
};
|
|
55
|
+
export declare const VIEW_ACCESS_POLICY_DENY_ROOT: ViewAccessPolicySubject;
|
|
56
|
+
export type ViewAccessPolicySnapshot = {
|
|
57
|
+
readonly schemaVersion: typeof VIEW_ACCESS_POLICY_SCHEMA_VERSION;
|
|
58
|
+
/** Subjects are sorted by canonical UTF-8 byte order. */
|
|
59
|
+
readonly subjects: readonly ViewAccessPolicySubject[];
|
|
60
|
+
/** SHA-256 of the canonical policy bytes. Exactly 32 octets. */
|
|
61
|
+
readonly policySha256: readonly number[];
|
|
62
|
+
};
|
|
63
|
+
/** Compact database only: the complete schema-v2 policy is derived from graph-v5. */
|
|
64
|
+
export type DerivedGraphViewAccessPolicy = {
|
|
65
|
+
readonly schemaVersion: 3;
|
|
66
|
+
readonly derivation: "graph-v5";
|
|
67
|
+
readonly policySha256: readonly number[];
|
|
68
|
+
};
|
|
69
|
+
export declare function derivedGraphViewAccessPolicy(snapshot: ViewAccessPolicySnapshot): DerivedGraphViewAccessPolicy;
|
|
70
|
+
export type ViewAccessResolution = {
|
|
71
|
+
readonly mode: EffectiveViewAccessMode;
|
|
72
|
+
readonly decidedBySubjectId: string;
|
|
73
|
+
};
|
|
74
|
+
export type AttributeOwnerKind = "node" | "edge";
|
|
75
|
+
/** Stable typed identity; callers must not collapse attribute paths to dotted strings. */
|
|
76
|
+
export type TypedLadybugTarget = {
|
|
77
|
+
readonly kind: "node";
|
|
78
|
+
readonly nodeId: string;
|
|
79
|
+
} | {
|
|
80
|
+
readonly kind: "attribute";
|
|
81
|
+
readonly ownerKind: AttributeOwnerKind;
|
|
82
|
+
readonly ownerId: string;
|
|
83
|
+
readonly path: readonly string[];
|
|
84
|
+
} | {
|
|
85
|
+
readonly kind: "edge";
|
|
86
|
+
readonly edgeId: string;
|
|
87
|
+
readonly sourceNodeId: string;
|
|
88
|
+
readonly destinationNodeId: string;
|
|
89
|
+
} | {
|
|
90
|
+
readonly kind: "vector";
|
|
91
|
+
readonly nodeId: string;
|
|
92
|
+
readonly vectorSpace: string;
|
|
93
|
+
};
|
|
94
|
+
export type OverlayLeafProvenance = "baseline" | "overlay_created";
|
|
95
|
+
export type CanonicalWalLeafChange = {
|
|
96
|
+
readonly target: TypedLadybugTarget;
|
|
97
|
+
/** Full segmented canonical path to one changed leaf. Empty paths are rejected. */
|
|
98
|
+
readonly leafPath: readonly string[];
|
|
99
|
+
readonly provenance: OverlayLeafProvenance;
|
|
100
|
+
};
|
|
101
|
+
export type OverlayLeafAccessInput = {
|
|
102
|
+
readonly target: TypedLadybugTarget;
|
|
103
|
+
/** Full segmented canonical path of the leaf being considered. */
|
|
104
|
+
readonly leafPath: readonly string[];
|
|
105
|
+
/** Provenance must describe this exact target and leaf, not its containing row. */
|
|
106
|
+
readonly provenance: OverlayLeafProvenance;
|
|
107
|
+
readonly policyMode: EffectiveViewAccessMode;
|
|
108
|
+
readonly canonicalWalChanges: readonly CanonicalWalLeafChange[];
|
|
109
|
+
};
|
|
110
|
+
/** Canonical Ladybug relation identity shared with the Rust store. */
|
|
111
|
+
export declare function canonicalLadybugRelationId(sourceNodeId: string, destinationNodeId: string, relationKind: string): string;
|
|
112
|
+
/** Domain-separated stable identity of one typed policy address. */
|
|
113
|
+
export declare function deriveViewAccessPolicySubjectId(address: ViewAccessPolicyAddress): string;
|
|
114
|
+
/** Constructs a bound non-root subject; the root is the exported fixed constant. */
|
|
115
|
+
export declare function createViewAccessPolicySubject(address: Exclude<ViewAccessPolicyAddress, {
|
|
116
|
+
readonly kind: "root";
|
|
117
|
+
}>, structuralParentId: string, mode: ViewAccessMode): ViewAccessPolicySubject;
|
|
118
|
+
/**
|
|
119
|
+
* Reduces a runtime target to its policy address. Vector spaces cannot carry
|
|
120
|
+
* policy overrides and always resolve through their owning node.
|
|
121
|
+
*/
|
|
122
|
+
export declare function viewAccessPolicyAddressForTarget(target: ViewAccessPolicyTarget): Exclude<ViewAccessPolicyAddress, {
|
|
123
|
+
readonly kind: "root";
|
|
124
|
+
}>;
|
|
125
|
+
/**
|
|
126
|
+
* Stable target-to-subject mapping used by every query and mutation gate.
|
|
127
|
+
* Vector-space names are validated but deliberately do not influence the id:
|
|
128
|
+
* every vector is governed by the policy subject of its owning node.
|
|
129
|
+
*/
|
|
130
|
+
export declare function deriveViewAccessPolicySubjectIdForTarget(target: ViewAccessPolicyTarget): string;
|
|
131
|
+
/** Sorts, validates and seals one canonical fail-closed policy snapshot. */
|
|
132
|
+
export declare function sealViewAccessPolicy(subjects: readonly ViewAccessPolicySubject[]): ViewAccessPolicySnapshot;
|
|
133
|
+
/** Validates canonical ordering, graph invariants and digest. */
|
|
134
|
+
export declare function validateViewAccessPolicy(snapshot: ViewAccessPolicySnapshot): void;
|
|
135
|
+
/**
|
|
136
|
+
* Resolves the closest explicit mode on the subject's structural parent chain.
|
|
137
|
+
* A chain with only `inherit` modes ends at the sealed fixed-deny root.
|
|
138
|
+
*/
|
|
139
|
+
export declare function resolveViewAccessMode(subjects: readonly ViewAccessPolicySubject[], subjectId: string): ViewAccessResolution;
|
|
140
|
+
export declare function isViewReadable(mode: EffectiveViewAccessMode): boolean;
|
|
141
|
+
export declare function isViewWritable(mode: EffectiveViewAccessMode): boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Edge access never inherits through its endpoints. Endpoints are gates only:
|
|
144
|
+
* both must be readable; writing additionally requires the edge itself to be
|
|
145
|
+
* explicitly/effectively `read_write`.
|
|
146
|
+
*/
|
|
147
|
+
export declare function resolveEdgeViewAccessMode(edgeMode: EffectiveViewAccessMode, sourceMode: EffectiveViewAccessMode, destinationMode: EffectiveViewAccessMode): EffectiveViewAccessMode;
|
|
148
|
+
/**
|
|
149
|
+
* Makes a leaf-scoped overlay decision. Canonical WAL visibility is granted
|
|
150
|
+
* only for an exact typed target and changed-leaf path; neither ancestor-prefix
|
|
151
|
+
* matches, a changed sibling nor another owner can make baseline data visible.
|
|
152
|
+
*/
|
|
153
|
+
export declare function resolveOverlayLeafViewAccessMode(input: OverlayLeafAccessInput): EffectiveViewAccessMode;
|