@haverstack/core 0.40.0 → 0.42.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.
Files changed (287) hide show
  1. package/README.md +121 -59
  2. package/dist/access.d.ts +34 -36
  3. package/dist/access.d.ts.map +1 -1
  4. package/dist/access.js +65 -42
  5. package/dist/access.js.map +1 -1
  6. package/dist/{combine.d.ts → adapter/combine.d.ts} +8 -1
  7. package/dist/adapter/combine.d.ts.map +1 -0
  8. package/dist/{combine.js → adapter/combine.js} +7 -0
  9. package/dist/adapter/combine.js.map +1 -0
  10. package/dist/{adapter-entry.d.ts → adapter/index.d.ts} +6 -5
  11. package/dist/adapter/index.d.ts.map +1 -0
  12. package/dist/{adapter-entry.js → adapter/index.js} +5 -4
  13. package/dist/adapter/index.js.map +1 -0
  14. package/dist/{sort.d.ts → adapter/sort.d.ts} +20 -20
  15. package/dist/adapter/sort.d.ts.map +1 -0
  16. package/dist/{sort.js → adapter/sort.js} +37 -27
  17. package/dist/adapter/sort.js.map +1 -0
  18. package/dist/associations/identity.d.ts +93 -0
  19. package/dist/associations/identity.d.ts.map +1 -0
  20. package/dist/associations/identity.js +198 -0
  21. package/dist/associations/identity.js.map +1 -0
  22. package/dist/associations/validation.d.ts +90 -0
  23. package/dist/associations/validation.d.ts.map +1 -0
  24. package/dist/associations/validation.js +339 -0
  25. package/dist/associations/validation.js.map +1 -0
  26. package/dist/attachment-records.d.ts +48 -0
  27. package/dist/attachment-records.d.ts.map +1 -0
  28. package/dist/attachment-records.js +52 -0
  29. package/dist/attachment-records.js.map +1 -0
  30. package/dist/collection.d.ts +182 -0
  31. package/dist/collection.d.ts.map +1 -0
  32. package/dist/collection.js +407 -0
  33. package/dist/collection.js.map +1 -0
  34. package/dist/content-match.d.ts +25 -0
  35. package/dist/content-match.d.ts.map +1 -0
  36. package/dist/content-match.js +51 -0
  37. package/dist/content-match.js.map +1 -0
  38. package/dist/content-translation.d.ts +42 -0
  39. package/dist/content-translation.d.ts.map +1 -0
  40. package/dist/content-translation.js +108 -0
  41. package/dist/content-translation.js.map +1 -0
  42. package/dist/did/did.d.ts.map +1 -0
  43. package/dist/{did.js → did/did.js} +3 -4
  44. package/dist/did/did.js.map +1 -0
  45. package/dist/{did-entry.d.ts → did/index.d.ts} +1 -1
  46. package/dist/did/index.d.ts.map +1 -0
  47. package/dist/{did-entry.js → did/index.js} +3 -3
  48. package/dist/did/index.js.map +1 -0
  49. package/dist/errors.d.ts +36 -63
  50. package/dist/errors.d.ts.map +1 -1
  51. package/dist/errors.js +35 -58
  52. package/dist/errors.js.map +1 -1
  53. package/dist/grants.d.ts +20 -43
  54. package/dist/grants.d.ts.map +1 -1
  55. package/dist/grants.js +71 -134
  56. package/dist/grants.js.map +1 -1
  57. package/dist/id.d.ts +13 -31
  58. package/dist/id.d.ts.map +1 -1
  59. package/dist/id.js +13 -31
  60. package/dist/id.js.map +1 -1
  61. package/dist/index.d.ts +14 -8
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js +9 -5
  64. package/dist/index.js.map +1 -1
  65. package/dist/install.d.ts +141 -0
  66. package/dist/install.d.ts.map +1 -0
  67. package/dist/install.js +219 -0
  68. package/dist/install.js.map +1 -0
  69. package/dist/merge.d.ts.map +1 -1
  70. package/dist/merge.js +5 -11
  71. package/dist/merge.js.map +1 -1
  72. package/dist/migration-steps.d.ts +102 -0
  73. package/dist/migration-steps.d.ts.map +1 -0
  74. package/dist/migration-steps.js +293 -0
  75. package/dist/migration-steps.js.map +1 -0
  76. package/dist/query-validation.d.ts +28 -94
  77. package/dist/query-validation.d.ts.map +1 -1
  78. package/dist/query-validation.js +156 -336
  79. package/dist/query-validation.js.map +1 -1
  80. package/dist/record-changes.d.ts +2 -117
  81. package/dist/record-changes.d.ts.map +1 -1
  82. package/dist/record-changes.js +10 -212
  83. package/dist/record-changes.js.map +1 -1
  84. package/dist/schema.d.ts +18 -7
  85. package/dist/schema.d.ts.map +1 -1
  86. package/dist/schema.js +59 -30
  87. package/dist/schema.js.map +1 -1
  88. package/dist/scoped-stack/authority.d.ts +156 -0
  89. package/dist/scoped-stack/authority.d.ts.map +1 -0
  90. package/dist/scoped-stack/authority.js +384 -0
  91. package/dist/scoped-stack/authority.js.map +1 -0
  92. package/dist/scoped-stack/scoped-stack.d.ts +338 -0
  93. package/dist/scoped-stack/scoped-stack.d.ts.map +1 -0
  94. package/dist/scoped-stack/scoped-stack.js +776 -0
  95. package/dist/scoped-stack/scoped-stack.js.map +1 -0
  96. package/dist/scoped-stack/subscription.d.ts +55 -0
  97. package/dist/scoped-stack/subscription.d.ts.map +1 -0
  98. package/dist/scoped-stack/subscription.js +110 -0
  99. package/dist/scoped-stack/subscription.js.map +1 -0
  100. package/dist/stack/attachments.d.ts +24 -0
  101. package/dist/stack/attachments.d.ts.map +1 -0
  102. package/dist/stack/attachments.js +113 -0
  103. package/dist/stack/attachments.js.map +1 -0
  104. package/dist/{changes.d.ts → stack/changes.d.ts} +29 -65
  105. package/dist/stack/changes.d.ts.map +1 -0
  106. package/dist/{changes.js → stack/changes.js} +32 -66
  107. package/dist/stack/changes.js.map +1 -0
  108. package/dist/stack/client.d.ts +271 -0
  109. package/dist/stack/client.d.ts.map +1 -0
  110. package/dist/stack/client.js +9 -0
  111. package/dist/stack/client.js.map +1 -0
  112. package/dist/stack/identity-bindings.d.ts.map +1 -0
  113. package/dist/{identity-bindings.js → stack/identity-bindings.js} +8 -14
  114. package/dist/stack/identity-bindings.js.map +1 -0
  115. package/dist/stack/install-app.d.ts +22 -0
  116. package/dist/stack/install-app.d.ts.map +1 -0
  117. package/dist/stack/install-app.js +260 -0
  118. package/dist/stack/install-app.js.map +1 -0
  119. package/dist/stack/integrity.d.ts +94 -0
  120. package/dist/stack/integrity.d.ts.map +1 -0
  121. package/dist/stack/integrity.js +268 -0
  122. package/dist/stack/integrity.js.map +1 -0
  123. package/dist/{limits.d.ts → stack/limits.d.ts} +2 -5
  124. package/dist/stack/limits.d.ts.map +1 -0
  125. package/dist/{limits.js → stack/limits.js} +3 -6
  126. package/dist/stack/limits.js.map +1 -0
  127. package/dist/stack/migrations.d.ts +59 -0
  128. package/dist/stack/migrations.d.ts.map +1 -0
  129. package/dist/stack/migrations.js +141 -0
  130. package/dist/stack/migrations.js.map +1 -0
  131. package/dist/{stack-reads.d.ts → stack/reads.d.ts} +33 -6
  132. package/dist/stack/reads.d.ts.map +1 -0
  133. package/dist/{stack-reads.js → stack/reads.js} +49 -7
  134. package/dist/stack/reads.js.map +1 -0
  135. package/dist/stack/record-id.d.ts +35 -0
  136. package/dist/stack/record-id.d.ts.map +1 -0
  137. package/dist/stack/record-id.js +82 -0
  138. package/dist/stack/record-id.js.map +1 -0
  139. package/dist/stack/stack.d.ts +438 -0
  140. package/dist/stack/stack.d.ts.map +1 -0
  141. package/dist/stack/stack.js +1366 -0
  142. package/dist/stack/stack.js.map +1 -0
  143. package/dist/stack/system-types.d.ts +16 -0
  144. package/dist/stack/system-types.d.ts.map +1 -0
  145. package/dist/stack/system-types.js +111 -0
  146. package/dist/stack/system-types.js.map +1 -0
  147. package/dist/stack/type-grants.d.ts +20 -0
  148. package/dist/stack/type-grants.d.ts.map +1 -0
  149. package/dist/stack/type-grants.js +69 -0
  150. package/dist/stack/type-grants.js.map +1 -0
  151. package/dist/stack/write-expectation.d.ts +78 -0
  152. package/dist/stack/write-expectation.d.ts.map +1 -0
  153. package/dist/stack/write-expectation.js +71 -0
  154. package/dist/stack/write-expectation.js.map +1 -0
  155. package/dist/testing.d.ts +21 -26
  156. package/dist/testing.d.ts.map +1 -1
  157. package/dist/testing.js +50 -70
  158. package/dist/testing.js.map +1 -1
  159. package/dist/type-handle.d.ts +67 -78
  160. package/dist/type-handle.d.ts.map +1 -1
  161. package/dist/type-handle.js +44 -111
  162. package/dist/type-handle.js.map +1 -1
  163. package/dist/types/adapter.d.ts +223 -0
  164. package/dist/types/adapter.d.ts.map +1 -0
  165. package/dist/types/adapter.js +5 -0
  166. package/dist/types/adapter.js.map +1 -0
  167. package/dist/types/associations.d.ts +156 -0
  168. package/dist/types/associations.d.ts.map +1 -0
  169. package/dist/types/associations.js +13 -0
  170. package/dist/types/associations.js.map +1 -0
  171. package/dist/types/capabilities.d.ts +89 -0
  172. package/dist/types/capabilities.d.ts.map +1 -0
  173. package/dist/types/capabilities.js +5 -0
  174. package/dist/types/capabilities.js.map +1 -0
  175. package/dist/types/events.d.ts +155 -0
  176. package/dist/types/events.d.ts.map +1 -0
  177. package/dist/types/events.js +5 -0
  178. package/dist/types/events.js.map +1 -0
  179. package/dist/types/ids.d.ts +43 -0
  180. package/dist/types/ids.d.ts.map +1 -0
  181. package/dist/types/ids.js +5 -0
  182. package/dist/types/ids.js.map +1 -0
  183. package/dist/types/index.d.ts +19 -0
  184. package/dist/types/index.d.ts.map +1 -0
  185. package/dist/types/index.js +19 -0
  186. package/dist/types/index.js.map +1 -0
  187. package/dist/types/journal.d.ts +47 -0
  188. package/dist/types/journal.d.ts.map +1 -0
  189. package/dist/types/journal.js +5 -0
  190. package/dist/types/journal.js.map +1 -0
  191. package/dist/types/query.d.ts +185 -0
  192. package/dist/types/query.d.ts.map +1 -0
  193. package/dist/types/query.js +10 -0
  194. package/dist/types/query.js.map +1 -0
  195. package/dist/types/records.d.ts +76 -0
  196. package/dist/types/records.d.ts.map +1 -0
  197. package/dist/types/records.js +5 -0
  198. package/dist/types/records.js.map +1 -0
  199. package/dist/types/schema.d.ts +74 -0
  200. package/dist/types/schema.d.ts.map +1 -0
  201. package/dist/types/schema.js +5 -0
  202. package/dist/types/schema.js.map +1 -0
  203. package/dist/types/system.d.ts +161 -0
  204. package/dist/types/system.d.ts.map +1 -0
  205. package/dist/types/system.js +32 -0
  206. package/dist/types/system.js.map +1 -0
  207. package/dist/types/tokens.d.ts +39 -0
  208. package/dist/types/tokens.d.ts.map +1 -0
  209. package/dist/types/tokens.js +5 -0
  210. package/dist/types/tokens.js.map +1 -0
  211. package/dist/validate.d.ts +29 -70
  212. package/dist/validate.d.ts.map +1 -1
  213. package/dist/validate.js +65 -97
  214. package/dist/validate.js.map +1 -1
  215. package/dist/{attachment-download.d.ts → wire/attachment-download.d.ts} +0 -57
  216. package/dist/wire/attachment-download.d.ts.map +1 -0
  217. package/dist/{attachment-download.js → wire/attachment-download.js} +0 -61
  218. package/dist/wire/attachment-download.js.map +1 -0
  219. package/dist/{auth.d.ts → wire/auth.d.ts} +5 -8
  220. package/dist/wire/auth.d.ts.map +1 -0
  221. package/dist/{auth.js → wire/auth.js} +5 -8
  222. package/dist/wire/auth.js.map +1 -0
  223. package/dist/{wire-body.d.ts → wire/body.d.ts} +13 -5
  224. package/dist/wire/body.d.ts.map +1 -0
  225. package/dist/{wire-body.js → wire/body.js} +65 -7
  226. package/dist/wire/body.js.map +1 -0
  227. package/dist/{wire-entry.d.ts → wire/index.d.ts} +12 -12
  228. package/dist/wire/index.d.ts.map +1 -0
  229. package/dist/{wire-entry.js → wire/index.js} +13 -17
  230. package/dist/wire/index.js.map +1 -0
  231. package/dist/{wire-record.d.ts → wire/record.d.ts} +10 -22
  232. package/dist/wire/record.d.ts.map +1 -0
  233. package/dist/{wire-record.js → wire/record.js} +12 -24
  234. package/dist/wire/record.js.map +1 -0
  235. package/dist/{wire-request.d.ts → wire/request.d.ts} +20 -37
  236. package/dist/wire/request.d.ts.map +1 -0
  237. package/dist/{wire-request.js → wire/request.js} +79 -54
  238. package/dist/wire/request.js.map +1 -0
  239. package/package.json +7 -7
  240. package/dist/adapter-entry.d.ts.map +0 -1
  241. package/dist/adapter-entry.js.map +0 -1
  242. package/dist/attachment-download.d.ts.map +0 -1
  243. package/dist/attachment-download.js.map +0 -1
  244. package/dist/auth.d.ts.map +0 -1
  245. package/dist/auth.js.map +0 -1
  246. package/dist/changes.d.ts.map +0 -1
  247. package/dist/changes.js.map +0 -1
  248. package/dist/combine.d.ts.map +0 -1
  249. package/dist/combine.js.map +0 -1
  250. package/dist/did-entry.d.ts.map +0 -1
  251. package/dist/did-entry.js.map +0 -1
  252. package/dist/did.d.ts.map +0 -1
  253. package/dist/did.js.map +0 -1
  254. package/dist/identity-bindings.d.ts.map +0 -1
  255. package/dist/identity-bindings.js.map +0 -1
  256. package/dist/limits.d.ts.map +0 -1
  257. package/dist/limits.js.map +0 -1
  258. package/dist/record-id.d.ts +0 -70
  259. package/dist/record-id.d.ts.map +0 -1
  260. package/dist/record-id.js +0 -127
  261. package/dist/record-id.js.map +0 -1
  262. package/dist/scoped-stack.d.ts +0 -532
  263. package/dist/scoped-stack.d.ts.map +0 -1
  264. package/dist/scoped-stack.js +0 -1219
  265. package/dist/scoped-stack.js.map +0 -1
  266. package/dist/sort.d.ts.map +0 -1
  267. package/dist/sort.js.map +0 -1
  268. package/dist/stack-reads.d.ts.map +0 -1
  269. package/dist/stack-reads.js.map +0 -1
  270. package/dist/stack.d.ts +0 -971
  271. package/dist/stack.d.ts.map +0 -1
  272. package/dist/stack.js +0 -2012
  273. package/dist/stack.js.map +0 -1
  274. package/dist/types.d.ts +0 -1250
  275. package/dist/types.d.ts.map +0 -1
  276. package/dist/types.js +0 -49
  277. package/dist/types.js.map +0 -1
  278. package/dist/wire-body.d.ts.map +0 -1
  279. package/dist/wire-body.js.map +0 -1
  280. package/dist/wire-entry.d.ts.map +0 -1
  281. package/dist/wire-entry.js.map +0 -1
  282. package/dist/wire-record.d.ts.map +0 -1
  283. package/dist/wire-record.js.map +0 -1
  284. package/dist/wire-request.d.ts.map +0 -1
  285. package/dist/wire-request.js.map +0 -1
  286. /package/dist/{did.d.ts → did/did.d.ts} +0 -0
  287. /package/dist/{identity-bindings.d.ts → stack/identity-bindings.d.ts} +0 -0
@@ -0,0 +1,338 @@
1
+ /**
2
+ * ScopedStack — the permission-enforcing view
3
+ * -------------------------------------------------------
4
+ * A `Stack` answers every question; a `ScopedStack` answers only the ones a
5
+ * particular requester is entitled to. It wraps a Stack rather than an
6
+ * adapter, so every invariant the Stack layer holds is already in force by
7
+ * the time a check here runs, and the gates below only ever narrow.
8
+ *
9
+ * Two identities, one rule: **the principal governs authority, the subject
10
+ * governs attribution.** Both are DIDs and both are often equal, which is
11
+ * what makes them easy to confuse — so the split is stated on every gate
12
+ * that depends on it. Grant lookup and the privilege-bearing gates no grant
13
+ * reaches (resharing, group management, purge, widening access at create
14
+ * time) key on the principal; authorship, `-own` matching, record-level
15
+ * permissions and "files I uploaded" key on the subject. Unconditional
16
+ * owner access splits the same way: an owner subject passes every
17
+ * permission check, an owner principal is not bounded by grants, and under
18
+ * delegation both halves apply. The questions those gates ask are
19
+ * ScopeAuthority's, in authority.ts; this module turns their answers into
20
+ * refusals.
21
+ *
22
+ * Also holds the feed side of the same rule: a subscription's deliveries
23
+ * run through the same canRead() a get() answers with, so a feed can never
24
+ * disagree with a read about what a session sees.
25
+ *
26
+ * See docs/spec/access-control.md and docs/spec/events.md § Permission scoping.
27
+ */
28
+ import { ChangeEmitter } from '../stack/changes.js';
29
+ import type { PutAttachmentOptions, AssociationEdit, AttachmentContent, AuthorityAssociation, DataAssociation, EntityId, FileId, QueryResult, RecordChange, RecordId, RecordVersion, RecordJournalEntry, JournalQuery, VersionsQuery, StackAdapter, StackCapabilities, IfVersionOptions, StackQuery, StackRecord, SubscribeOptions, TypeId, Unsubscribe, RecordChangeSet } from '../types/index.js';
30
+ import type { ExpectationOptions } from '../stack/write-expectation.js';
31
+ import type { ContentOf, ReadonlyTypeSchema, TypeHandle } from '../type-handle.js';
32
+ import type { Collection } from '../collection.js';
33
+ import type { MigrationRegistry } from '../stack/migrations.js';
34
+ import type { Stack } from '../stack/stack.js';
35
+ import type { BackdatableCreateRecordOptions, CollectAttachmentGarbageOptions, CollectAttachmentGarbageResult, DeleteAndReturnResult, DeleteRecordOptions, DeleteResult, GetRecordOptions, StackClient } from '../stack/client.js';
36
+ /**
37
+ * Held by Stack alone: the index re-exports ScopedStack but not this, so
38
+ * asEntity()/asActor() stay the only way to one, and the actor
39
+ * normalization and open-check they run can't be skipped.
40
+ */
41
+ export declare const scopeToken: unique symbol;
42
+ /** Everything a ScopedStack borrows from the Stack that scoped it. */
43
+ export type ScopedStackInit = {
44
+ stack: Stack;
45
+ principalId: EntityId | null;
46
+ subjectId: EntityId | null;
47
+ idTimestampSkewMs: number | null;
48
+ /**
49
+ * Bytes-storage primitive for putAttachment(), which composes bytes with
50
+ * its own create() so the record carries the subject and principal as
51
+ * `createdBy` — neither of which the adapter-level atomic capability takes.
52
+ */
53
+ adapter: StackAdapter;
54
+ /** The stack's own unfiltered stream, which subscribe() narrows. */
55
+ changes: ChangeEmitter;
56
+ assertOpen: () => void;
57
+ /** Whether changes reach the stack from elsewhere — see subscribe(). */
58
+ relaysChanges: boolean;
59
+ /** The app's migrations, which collection() migrates records through. */
60
+ migrations: MigrationRegistry;
61
+ };
62
+ /**
63
+ * A permission-enforcing view of a Stack for one (principal, subject) pair,
64
+ * obtained via `stack.asEntity()` or `stack.asActor()`. A record the request
65
+ * cannot read answers exactly as a missing one does.
66
+ * See docs/spec/disclosure.md § Which refusal a Record answers with.
67
+ */
68
+ export declare class ScopedStack implements StackClient {
69
+ #private;
70
+ private readonly stack;
71
+ private readonly idTimestampSkewMs;
72
+ private readonly adapter;
73
+ private readonly changes;
74
+ private readonly assertStackOpen;
75
+ private readonly relaysChanges;
76
+ private readonly migrations;
77
+ /** Not callable from outside the package — see ScopedStackInit. */
78
+ constructor(token: typeof scopeToken, init: ScopedStackInit);
79
+ collection<S extends ReadonlyTypeSchema>(handle: TypeHandle<S>): Collection<ContentOf<S>>;
80
+ /**
81
+ * The identity whose authority this view acts with; `null` when
82
+ * anonymous. See docs/spec/access-control.md § Delegation: principal and subject.
83
+ */
84
+ get principalId(): EntityId | null;
85
+ /**
86
+ * The identity this view acts for and attributes writes to; `null` when
87
+ * anonymous. Equal to `principalId` unless an app is acting for a user.
88
+ */
89
+ get subjectId(): EntityId | null;
90
+ get capabilities(): StackCapabilities;
91
+ private get actor();
92
+ /** Refuse a create this request holds no grant for — see ScopeAuthority.checkCreateGrant(). */
93
+ private requireCreateGrant;
94
+ /** Refuse anything but the owner acting as itself — see ScopeAuthority.ownerActingAlone. */
95
+ private requireOwnerActingAlone;
96
+ /**
97
+ * Fetch a record the subject can reach and the principal holds `update` on
98
+ * (via permissions or an update grant), or throw. `mutating: false` marks
99
+ * the history readers, which borrow this gate without changing anything —
100
+ * the one way through it a `_grant` Record stays open to.
101
+ */
102
+ private requireUpdatable;
103
+ /**
104
+ * The write gate both requireUpdatable() and requireDeletable() are: the
105
+ * subject can reach the record (record-level permission or a grant) and
106
+ * the principal holds the same verb, intersected — or, for a `_group`, the
107
+ * stricter management rule that no grant reaches.
108
+ * See docs/spec/access-control.md § Delegation: principal and subject.
109
+ */
110
+ private requireVerb;
111
+ /**
112
+ * Fetch a record the subject can reach and the principal holds `delete` on
113
+ * (via permissions or a delete grant), or throw.
114
+ */
115
+ private requireDeletable;
116
+ /**
117
+ * Gates file-ref content fields on file access, mirroring the
118
+ * attachment-association gate — a file-ref field conveys attachment
119
+ * access exactly like an `attachment` association. Only fields present
120
+ * in `content` are checked (a content patch is a merge patch; untouched fields
121
+ * carry no new reference).
122
+ */
123
+ private requireFileRefAccess;
124
+ /**
125
+ * Reference-creation gate for one association: file access for an
126
+ * `attachment`, read access for a `relationship` to a record in this
127
+ * stack. Other targets convey nothing, and a `_group` roster has the
128
+ * stricter management gate. See docs/spec/access-control.md
129
+ * § Reference-creation gating.
130
+ */
131
+ private requireAssociationAccess;
132
+ /**
133
+ * Create a record on behalf of the subject, stamped with the requester as
134
+ * `createdBy`. Every option that could widen reach or forge a position is
135
+ * refused rather than dropped, so an app never believes it published
136
+ * something it didn't. See docs/spec/data-model.md § Backdating on import.
137
+ */
138
+ create<T extends Record<string, unknown> = Record<string, unknown>>(typeId: TypeId, content: T, opts?: BackdatableCreateRecordOptions): Promise<StackRecord & {
139
+ content: T;
140
+ }>;
141
+ /**
142
+ * A record this request may read, or null. Never throws
143
+ * StackPermissionError: an unreadable record answers exactly as a missing
144
+ * one does, so a caller learns only what it may read.
145
+ * See docs/spec/disclosure.md § Which refusal a Record answers with.
146
+ */
147
+ get(id: RecordId, opts?: GetRecordOptions): Promise<StackRecord | null>;
148
+ /**
149
+ * Runs through this.query(), so canRead() still applies — this answers a
150
+ * question the caller asks on its own behalf. includeUnlisted is passed
151
+ * only when the request is the owner acting alone, per
152
+ * docs/spec/identity.md § DID bindings.
153
+ */
154
+ getEntityByDid(did: EntityId): Promise<StackRecord | null>;
155
+ getOwnerEntity(): Promise<StackRecord | null>;
156
+ /**
157
+ * Query records, filtered to those this request can read. Pages are
158
+ * filtered then refilled, so a page may slightly overshoot `limit` but
159
+ * never skips a record. Grants are prefetched once, cursor-walked to
160
+ * exhaustion.
161
+ */
162
+ query(query?: StackQuery): Promise<QueryResult>;
163
+ /**
164
+ * Apply a change set on behalf of the subject. Each key is gated against
165
+ * the record as it stands, never as the set would leave it, and one
166
+ * refused key refuses the call. See docs/spec/access-control.md
167
+ * § Composing a change set.
168
+ */
169
+ mutate(id: RecordId, changes: RecordChangeSet, opts?: IfVersionOptions & ExpectationOptions): Promise<StackRecord>;
170
+ patchContent(id: RecordId, patch: Record<string, unknown | null>, opts?: IfVersionOptions & ExpectationOptions): Promise<StackRecord>;
171
+ /**
172
+ * The record, having established that this request may decide who else
173
+ * reaches it — the owner-or-creator rule, asked of both sides of a
174
+ * delegation, or a Group's admin rule for a `_group`. The gate the
175
+ * `permissions` and `unlisted` keys carry, which the write bit
176
+ * deliberately does not confer.
177
+ */
178
+ private requireReshareable;
179
+ /**
180
+ * Whether a change set's `permissions` key moves the ACL, read off the
181
+ * computed delta so a replacement that drops everything — naming nothing
182
+ * — still counts. See docs/spec/access-control.md § Record-level permissions.
183
+ */
184
+ private permissionsMove;
185
+ /** The reshare decision alone, for a record already read and write-gated. */
186
+ private requireReshareOf;
187
+ /**
188
+ * An `_app` card's `did` and `appId` are the owner's alone to set, or
189
+ * record-level `write` would be a second way to name the software behind
190
+ * a key. `_entity` cards stay writable by grant, as a contacts app needs.
191
+ * See docs/spec/identity.md § DID bindings.
192
+ */
193
+ private requireOwnerForAppIdentity;
194
+ /**
195
+ * A delegated write's `appId` must match the `_app` card the owner
196
+ * registered for the principal's DID, if there is one: a verified
197
+ * principal may not claim a name the owner gave other software.
198
+ * See docs/spec/identity.md § Attribution and what can be trusted.
199
+ */
200
+ private requireAppIdMatchesPrincipal;
201
+ /**
202
+ * The owner's own DID is the one `_entity` binding a grantee may not
203
+ * claim: `ownerProfile` adopts whichever card holds it.
204
+ * See docs/spec/identity.md § DID bindings.
205
+ */
206
+ private requireOwnerForOwnerDid;
207
+ /**
208
+ * `_grant` and `_install` Records are authority, so only the owner acting
209
+ * alone may write one; reading them stays on the ordinary gate.
210
+ * See docs/spec/access-control.md § What a grant covers.
211
+ */
212
+ private requireOwnerForGrantRecord;
213
+ /**
214
+ * Gated on the write bit alone, which is why the list is held to its
215
+ * rules first: authority reached through this verb would be exactly the
216
+ * escalation the partition exists to stop, decided before any record is
217
+ * read so it cannot depend on who is asking.
218
+ */
219
+ associate(id: RecordId, associations: DataAssociation[], opts?: ExpectationOptions): Promise<StackRecord>;
220
+ /** See associate() — the same write gate, the same kind refusal. */
221
+ dissociate(id: RecordId, associations: DataAssociation[], opts?: ExpectationOptions): Promise<StackRecord>;
222
+ /**
223
+ * The write gate, plus the per-element reference gate on each add: what a
224
+ * remove names is already on the record, so it is gated by the write bit
225
+ * alone. See associate().
226
+ */
227
+ amendAssociations(id: RecordId, changes: AssociationEdit[], opts?: ExpectationOptions, surface?: string): Promise<StackRecord>;
228
+ /**
229
+ * Extend who reaches a record, on the reshare gate the `permissions` key
230
+ * carries. The write bit does not confer it, or a write-holder could
231
+ * decide who else reaches the record.
232
+ * See docs/spec/access-control.md § Record-level permissions.
233
+ */
234
+ grantAccess(id: RecordId, permissions: AuthorityAssociation[], opts?: ExpectationOptions): Promise<StackRecord>;
235
+ /** Withdraw elements of who reaches a record — see grantAccess(). */
236
+ revokeAccess(id: RecordId, permissions: AuthorityAssociation[], opts?: ExpectationOptions): Promise<StackRecord>;
237
+ /** The reshare gate over an edit list — see grantAccess(). */
238
+ amendAccess(id: RecordId, changes: AssociationEdit[], opts?: ExpectationOptions, surface?: string): Promise<StackRecord>;
239
+ /**
240
+ * Purge is owner-only: it is irreversible and destroys version
241
+ * history, so neither the write bit nor delete-own/delete-any grants
242
+ * reach it, and delegation doesn't carry it either. Everyone else is
243
+ * limited to soft delete.
244
+ */
245
+ delete(id: RecordId, opts?: DeleteRecordOptions & ExpectationOptions): Promise<DeleteResult>;
246
+ /**
247
+ * delete(), plus the record it acted on. Gated identically — the
248
+ * existence/visibility check that produces a 404 ahead of the 403
249
+ * permission gate still runs via requireDeletable() before either kind
250
+ * of delete, so this changes what a successful call reports, not the
251
+ * disclosure ordering a refused one follows.
252
+ */
253
+ deleteAndReturn(id: RecordId, opts?: DeleteRecordOptions & ExpectationOptions): Promise<DeleteAndReturnResult>;
254
+ /**
255
+ * Reverse a soft delete. Gated the same as delete() — undelete is the
256
+ * inverse of soft delete, so granting one direction without the other
257
+ * would be backwards. Idempotent, per Stack.undelete().
258
+ */
259
+ undelete(id: RecordId, opts?: IfVersionOptions & ExpectationOptions): Promise<StackRecord>;
260
+ /**
261
+ * History is the mutation/recovery surface, not a read surface — gated
262
+ * like patchContent(). Reading it changes nothing, so it is the one path
263
+ * the `_grant` write fence leaves alone: seeing how a Record you can
264
+ * already read got that way is not the escalation that fence exists to
265
+ * stop. See docs/spec/versioning.md § History access.
266
+ */
267
+ getVersions(id: RecordId, query?: VersionsQuery): Promise<RecordVersion[]>;
268
+ /**
269
+ * See getVersions() — the same gate. A requester who may not reshare the
270
+ * record is served each `reshare` op without the elements beneath it.
271
+ * See docs/spec/journal.md § Reading it.
272
+ */
273
+ getJournal(id: RecordId, query?: JournalQuery): Promise<RecordJournalEntry[]>;
274
+ /** See getVersions() — the same mutate-surface gate. */
275
+ getVersion(id: RecordId, version: number): Promise<RecordVersion | null>;
276
+ /**
277
+ * Re-runs the reference-creation checks against the snapshot, so a
278
+ * restore can't re-convey access to a file the subject can no longer
279
+ * reach today. Only the owner acting alone is exempt: under delegation
280
+ * the checks resolve against the subject, which is whose reach the
281
+ * restore would widen. See docs/spec/versioning.md § Restore semantics.
282
+ */
283
+ restoreVersion(id: RecordId, version: number, opts?: IfVersionOptions & ExpectationOptions): Promise<StackRecord>;
284
+ /**
285
+ * Commit a per-record migration: the owner acting alone, or an installed
286
+ * app within its own families (requireInstallMigration()). Ordinary write
287
+ * access is not consent to move a record between families.
288
+ * See docs/spec/access-control.md § What a grant covers.
289
+ */
290
+ commitMigration(id: RecordId, toTypeId: TypeId, content: Record<string, unknown>, opts?: IfVersionOptions): Promise<StackRecord>;
291
+ /**
292
+ * Refuse a migration this request may not commit as an installed app —
293
+ * see ScopeAuthority.installMayMigrate(). The tombstone refusal comes
294
+ * only once authority is settled, as every mutating verb asks it: the
295
+ * owner may migrate a tombstone; an app sees it without content.
296
+ * See docs/spec/apps.md § Migrating an installed app's types.
297
+ */
298
+ private requireInstallMigration;
299
+ /**
300
+ * Store bytes and create an _attachment@1 metadata record (create grant
301
+ * on `_attachment@1` required; anonymous denied), returning that record.
302
+ * Authorship and principal are stamped exactly as create() does.
303
+ */
304
+ putAttachment(data: Uint8Array, opts: PutAttachmentOptions): Promise<StackRecord & {
305
+ content: AttachmentContent;
306
+ }>;
307
+ /**
308
+ * Download attachment bytes. Accessible to the owner, a reader of any
309
+ * referencing record, or the uploader pre-association — the same
310
+ * predicate as the reference-creation gate (canAccessFile).
311
+ */
312
+ getAttachment(fileId: FileId): Promise<Uint8Array>;
313
+ /**
314
+ * Delete an attachment. Only the stack owner may delete attachments.
315
+ * Delegates to Stack.deleteAttachment(), which enforces the "not referenced" check.
316
+ */
317
+ deleteAttachment(fileId: FileId): Promise<void>;
318
+ /**
319
+ * Sweep for unreferenced attachment bytes and delete them. Only the stack
320
+ * owner may run this. Delegates to Stack.collectAttachmentGarbage().
321
+ */
322
+ collectAttachmentGarbage(opts?: CollectAttachmentGarbageOptions): Promise<CollectAttachmentGarbageResult>;
323
+ /**
324
+ * Observe the changes this request may read, decided per event by the
325
+ * same canRead() that get() and query() use. An unreadable record yields
326
+ * no event at all, since a change's existence is itself a disclosure.
327
+ * See docs/spec/events.md § Permission scoping.
328
+ */
329
+ subscribe(handler: (change: RecordChange) => void, opts?: SubscribeOptions): Promise<Unsubscribe>;
330
+ /**
331
+ * canRead for one event, through the subscription's own cache. Grants
332
+ * are prefetched once and refilled after an invalidation rather than
333
+ * re-queried per event, which would be a `_grant` scan for every change
334
+ * the stack makes.
335
+ */
336
+ private canReadCached;
337
+ }
338
+ //# sourceMappingURL=scoped-stack.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scoped-stack.d.ts","sourceRoot":"","sources":["../../src/scoped-stack/scoped-stack.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAIH,OAAO,EAAE,aAAa,EAAqB,MAAM,qBAAqB,CAAC;AAEvE,OAAO,KAAK,EAIV,oBAAoB,EAEpB,eAAe,EACf,iBAAiB,EACjB,oBAAoB,EACpB,eAAe,EACf,QAAQ,EACR,MAAM,EAGN,WAAW,EACX,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,UAAU,EACV,WAAW,EACX,gBAAgB,EAChB,MAAM,EACN,WAAW,EACX,eAAe,EAChB,MAAM,mBAAmB,CAAC;AA6B3B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAcxE,OAAO,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEnF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAIhE,OAAO,KAAK,EAAE,KAAK,EAAE,MAA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