@haverstack/core 0.41.0 → 0.43.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 (317) hide show
  1. package/README.md +124 -64
  2. package/dist/access.d.ts +43 -47
  3. package/dist/access.d.ts.map +1 -1
  4. package/dist/access.js +66 -101
  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} +18 -3
  9. package/dist/adapter/combine.js.map +1 -0
  10. package/dist/adapter/index.d.ts +19 -0
  11. package/dist/adapter/index.d.ts.map +1 -0
  12. package/dist/adapter/index.js +16 -0
  13. package/dist/adapter/index.js.map +1 -0
  14. package/dist/adapter/reach.d.ts +14 -0
  15. package/dist/adapter/reach.d.ts.map +1 -0
  16. package/dist/adapter/reach.js +31 -0
  17. package/dist/adapter/reach.js.map +1 -0
  18. package/dist/{sort.d.ts → adapter/sort.d.ts} +20 -20
  19. package/dist/adapter/sort.d.ts.map +1 -0
  20. package/dist/{sort.js → adapter/sort.js} +37 -27
  21. package/dist/adapter/sort.js.map +1 -0
  22. package/dist/associations/identity.d.ts +69 -0
  23. package/dist/associations/identity.d.ts.map +1 -0
  24. package/dist/associations/identity.js +174 -0
  25. package/dist/associations/identity.js.map +1 -0
  26. package/dist/associations/validation.d.ts +83 -0
  27. package/dist/associations/validation.d.ts.map +1 -0
  28. package/dist/associations/validation.js +312 -0
  29. package/dist/associations/validation.js.map +1 -0
  30. package/dist/attachment-records.d.ts +48 -0
  31. package/dist/attachment-records.d.ts.map +1 -0
  32. package/dist/attachment-records.js +52 -0
  33. package/dist/attachment-records.js.map +1 -0
  34. package/dist/collection.d.ts +178 -0
  35. package/dist/collection.d.ts.map +1 -0
  36. package/dist/collection.js +397 -0
  37. package/dist/collection.js.map +1 -0
  38. package/dist/content-match.d.ts +25 -0
  39. package/dist/content-match.d.ts.map +1 -0
  40. package/dist/content-match.js +51 -0
  41. package/dist/content-match.js.map +1 -0
  42. package/dist/content-translation.d.ts +42 -0
  43. package/dist/content-translation.d.ts.map +1 -0
  44. package/dist/content-translation.js +108 -0
  45. package/dist/content-translation.js.map +1 -0
  46. package/dist/did/did.d.ts.map +1 -0
  47. package/dist/{did.js → did/did.js} +3 -4
  48. package/dist/did/did.js.map +1 -0
  49. package/dist/{did-entry.d.ts → did/index.d.ts} +1 -1
  50. package/dist/did/index.d.ts.map +1 -0
  51. package/dist/{did-entry.js → did/index.js} +3 -3
  52. package/dist/did/index.js.map +1 -0
  53. package/dist/errors.d.ts +54 -66
  54. package/dist/errors.d.ts.map +1 -1
  55. package/dist/errors.js +58 -62
  56. package/dist/errors.js.map +1 -1
  57. package/dist/grants.d.ts +20 -44
  58. package/dist/grants.d.ts.map +1 -1
  59. package/dist/grants.js +69 -151
  60. package/dist/grants.js.map +1 -1
  61. package/dist/id.d.ts +13 -31
  62. package/dist/id.d.ts.map +1 -1
  63. package/dist/id.js +13 -31
  64. package/dist/id.js.map +1 -1
  65. package/dist/index.d.ts +13 -9
  66. package/dist/index.d.ts.map +1 -1
  67. package/dist/index.js +9 -6
  68. package/dist/index.js.map +1 -1
  69. package/dist/install.d.ts +3 -6
  70. package/dist/install.d.ts.map +1 -1
  71. package/dist/install.js +6 -10
  72. package/dist/install.js.map +1 -1
  73. package/dist/lazy.d.ts +13 -0
  74. package/dist/lazy.d.ts.map +1 -0
  75. package/dist/lazy.js +27 -0
  76. package/dist/lazy.js.map +1 -0
  77. package/dist/merge.d.ts +1 -1
  78. package/dist/merge.d.ts.map +1 -1
  79. package/dist/merge.js +6 -12
  80. package/dist/merge.js.map +1 -1
  81. package/dist/migration-steps.d.ts +102 -0
  82. package/dist/migration-steps.d.ts.map +1 -0
  83. package/dist/migration-steps.js +293 -0
  84. package/dist/migration-steps.js.map +1 -0
  85. package/dist/query-validation.d.ts +68 -121
  86. package/dist/query-validation.d.ts.map +1 -1
  87. package/dist/query-validation.js +214 -380
  88. package/dist/query-validation.js.map +1 -1
  89. package/dist/record-changes.d.ts +11 -150
  90. package/dist/record-changes.d.ts.map +1 -1
  91. package/dist/record-changes.js +14 -305
  92. package/dist/record-changes.js.map +1 -1
  93. package/dist/schema.d.ts +18 -7
  94. package/dist/schema.d.ts.map +1 -1
  95. package/dist/schema.js +59 -30
  96. package/dist/schema.js.map +1 -1
  97. package/dist/scoped-stack/authority-snapshot.d.ts +37 -0
  98. package/dist/scoped-stack/authority-snapshot.d.ts.map +1 -0
  99. package/dist/scoped-stack/authority-snapshot.js +49 -0
  100. package/dist/scoped-stack/authority-snapshot.js.map +1 -0
  101. package/dist/scoped-stack/authority.d.ts +169 -0
  102. package/dist/scoped-stack/authority.d.ts.map +1 -0
  103. package/dist/scoped-stack/authority.js +408 -0
  104. package/dist/scoped-stack/authority.js.map +1 -0
  105. package/dist/scoped-stack/family-policy.d.ts +59 -0
  106. package/dist/scoped-stack/family-policy.d.ts.map +1 -0
  107. package/dist/scoped-stack/family-policy.js +68 -0
  108. package/dist/scoped-stack/family-policy.js.map +1 -0
  109. package/dist/scoped-stack/scoped-stack.d.ts +318 -0
  110. package/dist/scoped-stack/scoped-stack.d.ts.map +1 -0
  111. package/dist/scoped-stack/scoped-stack.js +695 -0
  112. package/dist/scoped-stack/scoped-stack.js.map +1 -0
  113. package/dist/scoped-stack/subscription.d.ts +36 -0
  114. package/dist/scoped-stack/subscription.d.ts.map +1 -0
  115. package/dist/scoped-stack/subscription.js +69 -0
  116. package/dist/scoped-stack/subscription.js.map +1 -0
  117. package/dist/stack/arguments.d.ts +27 -0
  118. package/dist/stack/arguments.d.ts.map +1 -0
  119. package/dist/stack/arguments.js +53 -0
  120. package/dist/stack/arguments.js.map +1 -0
  121. package/dist/stack/attachments.d.ts +24 -0
  122. package/dist/stack/attachments.d.ts.map +1 -0
  123. package/dist/stack/attachments.js +113 -0
  124. package/dist/stack/attachments.js.map +1 -0
  125. package/dist/{changes.d.ts → stack/changes.d.ts} +30 -72
  126. package/dist/stack/changes.d.ts.map +1 -0
  127. package/dist/{changes.js → stack/changes.js} +40 -74
  128. package/dist/stack/changes.js.map +1 -0
  129. package/dist/stack/client.d.ts +247 -0
  130. package/dist/stack/client.d.ts.map +1 -0
  131. package/dist/stack/client.js +9 -0
  132. package/dist/stack/client.js.map +1 -0
  133. package/dist/stack/identity-bindings.d.ts.map +1 -0
  134. package/dist/{identity-bindings.js → stack/identity-bindings.js} +5 -14
  135. package/dist/stack/identity-bindings.js.map +1 -0
  136. package/dist/stack/install-app.d.ts +22 -0
  137. package/dist/stack/install-app.d.ts.map +1 -0
  138. package/dist/stack/install-app.js +262 -0
  139. package/dist/stack/install-app.js.map +1 -0
  140. package/dist/stack/integrity.d.ts +94 -0
  141. package/dist/stack/integrity.d.ts.map +1 -0
  142. package/dist/stack/integrity.js +268 -0
  143. package/dist/stack/integrity.js.map +1 -0
  144. package/dist/{limits.d.ts → stack/limits.d.ts} +2 -5
  145. package/dist/stack/limits.d.ts.map +1 -0
  146. package/dist/{limits.js → stack/limits.js} +3 -6
  147. package/dist/stack/limits.js.map +1 -0
  148. package/dist/stack/migrations.d.ts +59 -0
  149. package/dist/stack/migrations.d.ts.map +1 -0
  150. package/dist/stack/migrations.js +141 -0
  151. package/dist/stack/migrations.js.map +1 -0
  152. package/dist/stack/reads.d.ts +69 -0
  153. package/dist/stack/reads.d.ts.map +1 -0
  154. package/dist/stack/reads.js +141 -0
  155. package/dist/stack/reads.js.map +1 -0
  156. package/dist/stack/record-id.d.ts +35 -0
  157. package/dist/stack/record-id.d.ts.map +1 -0
  158. package/dist/stack/record-id.js +82 -0
  159. package/dist/stack/record-id.js.map +1 -0
  160. package/dist/stack/stack.d.ts +444 -0
  161. package/dist/stack/stack.d.ts.map +1 -0
  162. package/dist/stack/stack.js +1339 -0
  163. package/dist/stack/stack.js.map +1 -0
  164. package/dist/stack/system-types.d.ts +16 -0
  165. package/dist/stack/system-types.d.ts.map +1 -0
  166. package/dist/stack/system-types.js +111 -0
  167. package/dist/stack/system-types.js.map +1 -0
  168. package/dist/stack/type-grants.d.ts +20 -0
  169. package/dist/stack/type-grants.d.ts.map +1 -0
  170. package/dist/stack/type-grants.js +69 -0
  171. package/dist/stack/type-grants.js.map +1 -0
  172. package/dist/stack/write-expectation.d.ts +79 -0
  173. package/dist/stack/write-expectation.d.ts.map +1 -0
  174. package/dist/stack/write-expectation.js +71 -0
  175. package/dist/stack/write-expectation.js.map +1 -0
  176. package/dist/stack/write-gate.d.ts +23 -0
  177. package/dist/stack/write-gate.d.ts.map +1 -0
  178. package/dist/stack/write-gate.js +17 -0
  179. package/dist/stack/write-gate.js.map +1 -0
  180. package/dist/testing.d.ts +44 -33
  181. package/dist/testing.d.ts.map +1 -1
  182. package/dist/testing.js +180 -176
  183. package/dist/testing.js.map +1 -1
  184. package/dist/type-handle.d.ts +67 -78
  185. package/dist/type-handle.d.ts.map +1 -1
  186. package/dist/type-handle.js +44 -111
  187. package/dist/type-handle.js.map +1 -1
  188. package/dist/types/adapter.d.ts +282 -0
  189. package/dist/types/adapter.d.ts.map +1 -0
  190. package/dist/types/adapter.js +5 -0
  191. package/dist/types/adapter.js.map +1 -0
  192. package/dist/types/associations.d.ts +140 -0
  193. package/dist/types/associations.d.ts.map +1 -0
  194. package/dist/types/associations.js +6 -0
  195. package/dist/types/associations.js.map +1 -0
  196. package/dist/types/capabilities.d.ts +89 -0
  197. package/dist/types/capabilities.d.ts.map +1 -0
  198. package/dist/types/capabilities.js +5 -0
  199. package/dist/types/capabilities.js.map +1 -0
  200. package/dist/types/events.d.ts +150 -0
  201. package/dist/types/events.d.ts.map +1 -0
  202. package/dist/types/events.js +5 -0
  203. package/dist/types/events.js.map +1 -0
  204. package/dist/types/ids.d.ts +43 -0
  205. package/dist/types/ids.d.ts.map +1 -0
  206. package/dist/types/ids.js +5 -0
  207. package/dist/types/ids.js.map +1 -0
  208. package/dist/types/index.d.ts +19 -0
  209. package/dist/types/index.d.ts.map +1 -0
  210. package/dist/types/index.js +19 -0
  211. package/dist/types/index.js.map +1 -0
  212. package/dist/types/journal.d.ts +47 -0
  213. package/dist/types/journal.d.ts.map +1 -0
  214. package/dist/types/journal.js +5 -0
  215. package/dist/types/journal.js.map +1 -0
  216. package/dist/types/query.d.ts +185 -0
  217. package/dist/types/query.d.ts.map +1 -0
  218. package/dist/types/query.js +10 -0
  219. package/dist/types/query.js.map +1 -0
  220. package/dist/types/records.d.ts +76 -0
  221. package/dist/types/records.d.ts.map +1 -0
  222. package/dist/types/records.js +5 -0
  223. package/dist/types/records.js.map +1 -0
  224. package/dist/types/schema.d.ts +74 -0
  225. package/dist/types/schema.d.ts.map +1 -0
  226. package/dist/types/schema.js +5 -0
  227. package/dist/types/schema.js.map +1 -0
  228. package/dist/types/system.d.ts +161 -0
  229. package/dist/types/system.d.ts.map +1 -0
  230. package/dist/types/system.js +32 -0
  231. package/dist/types/system.js.map +1 -0
  232. package/dist/types/tokens.d.ts +39 -0
  233. package/dist/types/tokens.d.ts.map +1 -0
  234. package/dist/types/tokens.js +5 -0
  235. package/dist/types/tokens.js.map +1 -0
  236. package/dist/validate.d.ts +31 -70
  237. package/dist/validate.d.ts.map +1 -1
  238. package/dist/validate.js +52 -92
  239. package/dist/validate.js.map +1 -1
  240. package/dist/{attachment-download.d.ts → wire/attachment-download.d.ts} +0 -57
  241. package/dist/wire/attachment-download.d.ts.map +1 -0
  242. package/dist/{attachment-download.js → wire/attachment-download.js} +0 -61
  243. package/dist/wire/attachment-download.js.map +1 -0
  244. package/dist/{auth.d.ts → wire/auth.d.ts} +5 -8
  245. package/dist/wire/auth.d.ts.map +1 -0
  246. package/dist/{auth.js → wire/auth.js} +5 -8
  247. package/dist/wire/auth.js.map +1 -0
  248. package/dist/{wire-body.d.ts → wire/body.d.ts} +35 -12
  249. package/dist/wire/body.d.ts.map +1 -0
  250. package/dist/{wire-body.js → wire/body.js} +74 -13
  251. package/dist/wire/body.js.map +1 -0
  252. package/dist/{wire-entry.d.ts → wire/index.d.ts} +12 -12
  253. package/dist/wire/index.d.ts.map +1 -0
  254. package/dist/{wire-entry.js → wire/index.js} +13 -17
  255. package/dist/wire/index.js.map +1 -0
  256. package/dist/wire/record.d.ts +31 -0
  257. package/dist/wire/record.d.ts.map +1 -0
  258. package/dist/{wire-record.js → wire/record.js} +7 -67
  259. package/dist/wire/record.js.map +1 -0
  260. package/dist/{wire-request.d.ts → wire/request.d.ts} +32 -49
  261. package/dist/wire/request.d.ts.map +1 -0
  262. package/dist/{wire-request.js → wire/request.js} +113 -83
  263. package/dist/wire/request.js.map +1 -0
  264. package/package.json +7 -7
  265. package/dist/adapter-entry.d.ts +0 -16
  266. package/dist/adapter-entry.d.ts.map +0 -1
  267. package/dist/adapter-entry.js +0 -14
  268. package/dist/adapter-entry.js.map +0 -1
  269. package/dist/attachment-download.d.ts.map +0 -1
  270. package/dist/attachment-download.js.map +0 -1
  271. package/dist/auth.d.ts.map +0 -1
  272. package/dist/auth.js.map +0 -1
  273. package/dist/changes.d.ts.map +0 -1
  274. package/dist/changes.js.map +0 -1
  275. package/dist/combine.d.ts.map +0 -1
  276. package/dist/combine.js.map +0 -1
  277. package/dist/did-entry.d.ts.map +0 -1
  278. package/dist/did-entry.js.map +0 -1
  279. package/dist/did.d.ts.map +0 -1
  280. package/dist/did.js.map +0 -1
  281. package/dist/identity-bindings.d.ts.map +0 -1
  282. package/dist/identity-bindings.js.map +0 -1
  283. package/dist/limits.d.ts.map +0 -1
  284. package/dist/limits.js.map +0 -1
  285. package/dist/record-id.d.ts +0 -70
  286. package/dist/record-id.d.ts.map +0 -1
  287. package/dist/record-id.js +0 -127
  288. package/dist/record-id.js.map +0 -1
  289. package/dist/scoped-stack.d.ts +0 -549
  290. package/dist/scoped-stack.d.ts.map +0 -1
  291. package/dist/scoped-stack.js +0 -1301
  292. package/dist/scoped-stack.js.map +0 -1
  293. package/dist/sort.d.ts.map +0 -1
  294. package/dist/sort.js.map +0 -1
  295. package/dist/stack-reads.d.ts +0 -38
  296. package/dist/stack-reads.d.ts.map +0 -1
  297. package/dist/stack-reads.js +0 -79
  298. package/dist/stack-reads.js.map +0 -1
  299. package/dist/stack.d.ts +0 -1032
  300. package/dist/stack.d.ts.map +0 -1
  301. package/dist/stack.js +0 -2337
  302. package/dist/stack.js.map +0 -1
  303. package/dist/types.d.ts +0 -1278
  304. package/dist/types.d.ts.map +0 -1
  305. package/dist/types.js +0 -51
  306. package/dist/types.js.map +0 -1
  307. package/dist/wire-body.d.ts.map +0 -1
  308. package/dist/wire-body.js.map +0 -1
  309. package/dist/wire-entry.d.ts.map +0 -1
  310. package/dist/wire-entry.js.map +0 -1
  311. package/dist/wire-record.d.ts +0 -50
  312. package/dist/wire-record.d.ts.map +0 -1
  313. package/dist/wire-record.js.map +0 -1
  314. package/dist/wire-request.d.ts.map +0 -1
  315. package/dist/wire-request.js.map +0 -1
  316. /package/dist/{did.d.ts → did/did.d.ts} +0 -0
  317. /package/dist/{identity-bindings.d.ts → stack/identity-bindings.d.ts} +0 -0
@@ -0,0 +1,318 @@
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
+ * ask the same read reach a get() does, so a feed can never disagree with
24
+ * 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, Reach, RecordChange, RecordId, RecordVersion, RecordJournalEntry, JournalQuery, VersionsQuery, StackAdapter, StackCapabilities, IfVersionOptions, StackQuery, StackRecord, SubscribeOptions, TypeId, Unsubscribe } from '../types/index.js';
30
+ import type { SplitQuery } from '../query-validation.js';
31
+ import type { ExpectationOptions } from '../stack/write-expectation.js';
32
+ import type { ContentOf, ReadonlyTypeSchema, TypeHandle } from '../type-handle.js';
33
+ import type { Collection } from '../collection.js';
34
+ import type { MigrationRegistry } from '../stack/migrations.js';
35
+ import type { Stack } from '../stack/stack.js';
36
+ import type { BackdatableCreateRecordOptions, CollectAttachmentGarbageOptions, CollectAttachmentGarbageResult, DeleteRecordOptions, DeleteResult, GetRecordOptions, StackClient } from '../stack/client.js';
37
+ /**
38
+ * Held by Stack alone: the index re-exports ScopedStack but not this, so
39
+ * asEntity()/asActor() stay the only way to one, and the actor
40
+ * normalization and open-check they run can't be skipped.
41
+ */
42
+ export declare const scopeToken: unique symbol;
43
+ /** Everything a ScopedStack borrows from the Stack that scoped it. */
44
+ export type ScopedStackInit = {
45
+ stack: Stack;
46
+ principalId: EntityId | null;
47
+ subjectId: EntityId | null;
48
+ idTimestampSkewMs: number | null;
49
+ /**
50
+ * Bytes-storage primitive for putAttachment(), which composes bytes with
51
+ * its own create() so the record carries the subject and principal as
52
+ * `createdBy` — neither of which the adapter-level atomic capability takes.
53
+ */
54
+ adapter: StackAdapter;
55
+ /** The stack's own unfiltered stream, which subscribe() narrows. */
56
+ changes: ChangeEmitter;
57
+ assertOpen: () => void;
58
+ /** The app's migrations, which collection() migrates records through. */
59
+ migrations: MigrationRegistry;
60
+ /** Stack.query() within a reach over type families — see query(). */
61
+ queryReadable: (split: SplitQuery, reach: Reach) => Promise<QueryResult>;
62
+ };
63
+ /**
64
+ * A permission-enforcing view of a Stack for one (principal, subject) pair,
65
+ * obtained via `stack.asEntity()` or `stack.asActor()`. A record the request
66
+ * cannot read answers exactly as a missing one does.
67
+ * See docs/spec/disclosure.md § Which refusal a Record answers with.
68
+ */
69
+ export declare class ScopedStack implements StackClient {
70
+ #private;
71
+ private readonly stack;
72
+ private readonly idTimestampSkewMs;
73
+ private readonly adapter;
74
+ private readonly changes;
75
+ private readonly assertStackOpen;
76
+ private readonly migrations;
77
+ private readonly queryReadable;
78
+ /** Not callable from outside the package — see ScopedStackInit. */
79
+ constructor(token: typeof scopeToken, init: ScopedStackInit);
80
+ collection<S extends ReadonlyTypeSchema>(handle: TypeHandle<S>): Collection<ContentOf<S>>;
81
+ /**
82
+ * The identity whose authority this view acts with; `null` when
83
+ * anonymous. See docs/spec/access-control.md § Delegation: principal and subject.
84
+ */
85
+ get principalId(): EntityId | null;
86
+ /**
87
+ * The identity this view acts for and attributes writes to; `null` when
88
+ * anonymous. Equal to `principalId` unless an app is acting for a user.
89
+ */
90
+ get subjectId(): EntityId | null;
91
+ get capabilities(): StackCapabilities;
92
+ private get actor();
93
+ /** Refuse a create outside this request's reach — see ScopeAuthority.canCreate(). */
94
+ private requireCreateGrant;
95
+ /** Refuse anything but the owner acting as itself — see ScopeAuthority.ownerActingAlone. */
96
+ private requireOwnerActingAlone;
97
+ /**
98
+ * Fetch a record the subject can reach and the principal holds `update` on
99
+ * (via permissions or an update grant), or throw. `mutating: false` marks
100
+ * the history readers, which borrow this gate without changing anything —
101
+ * the one way through it a `_grant` Record stays open to.
102
+ */
103
+ private requireUpdatable;
104
+ /**
105
+ * The write gate both requireUpdatable() and requireDeletable() are: the
106
+ * subject can reach the record (record-level permission or a grant) and
107
+ * the principal holds the same verb, intersected — or, for a `_group`, the
108
+ * stricter management rule that no grant reaches.
109
+ * See docs/spec/access-control.md § Delegation: principal and subject.
110
+ */
111
+ private requireVerb;
112
+ /** requireVerb()'s gate, asked of a record already found in its family. */
113
+ private gateVerb;
114
+ /**
115
+ * Fetch a record the subject can reach and the principal holds `delete` on
116
+ * (via permissions or a delete grant), or throw.
117
+ */
118
+ private requireDeletable;
119
+ /**
120
+ * Gates file-ref content fields on file access, mirroring the
121
+ * attachment-association gate — a file-ref field conveys attachment
122
+ * access exactly like an `attachment` association. Only fields present
123
+ * in `content` are checked (a content patch is a merge patch; untouched fields
124
+ * carry no new reference).
125
+ */
126
+ private requireFileRefAccess;
127
+ /**
128
+ * Reference-creation gate for one association: file access for an
129
+ * `attachment`, read access for a `relationship` to a record in this
130
+ * stack. Other targets convey nothing, and a `_group` roster has the
131
+ * stricter management gate. See docs/spec/access-control.md
132
+ * § Reference-creation gating.
133
+ */
134
+ private requireAssociationAccess;
135
+ /**
136
+ * Create a record on behalf of the subject, stamped with the requester as
137
+ * `createdBy`. Every option that could widen reach or forge a position is
138
+ * refused rather than dropped, so an app never believes it published
139
+ * something it didn't. See docs/spec/data-model.md § Backdating on import.
140
+ */
141
+ create<T extends Record<string, unknown> = Record<string, unknown>>(typeId: TypeId, content: T, opts?: BackdatableCreateRecordOptions): Promise<StackRecord & {
142
+ content: T;
143
+ }>;
144
+ /**
145
+ * A record this request may read, or null. Never throws
146
+ * StackPermissionError: an unreadable record answers exactly as a missing
147
+ * one does, so a caller learns only what it may read.
148
+ * See docs/spec/disclosure.md § Which refusal a Record answers with.
149
+ */
150
+ get(id: RecordId, opts?: GetRecordOptions): Promise<StackRecord | null>;
151
+ /**
152
+ * Runs through this.query(), so the read reach still applies — this
153
+ * answers a question the caller asks on its own behalf. includeUnlisted
154
+ * is passed only when the request is the owner acting alone, per
155
+ * docs/spec/identity.md § DID bindings.
156
+ */
157
+ getEntityByDid(did: EntityId): Promise<StackRecord | null>;
158
+ getOwnerEntity(): Promise<StackRecord | null>;
159
+ /**
160
+ * Query records, among those this request can read: the adapter matches
161
+ * the request's read reach as one more condition of the query, so a page,
162
+ * its cursor and whether one comes back are decided among readable
163
+ * Records alone. See docs/spec/disclosure.md § What a query reveals.
164
+ */
165
+ query(query?: StackQuery): Promise<QueryResult>;
166
+ /**
167
+ * Patch content on behalf of the subject, on the write gate, plus the
168
+ * gates a content value can carry: a card's binding fields and the files
169
+ * a `file-ref` field names. See docs/spec/access-control.md § Per-verb gates.
170
+ */
171
+ patchContent(id: RecordId, patch: Record<string, unknown | null>, opts?: IfVersionOptions & ExpectationOptions): Promise<StackRecord>;
172
+ /**
173
+ * The write gate, plus read access to the destination: a container is a
174
+ * reference the requester has to be allowed to create.
175
+ */
176
+ setParent(id: RecordId, parentId: RecordId | null, opts?: IfVersionOptions & ExpectationOptions): Promise<StackRecord>;
177
+ /**
178
+ * Listing decides who can enumerate a record, so it carries the reshare
179
+ * gate rather than the write bit. See docs/spec/unlisted.md.
180
+ */
181
+ setUnlisted(id: RecordId, unlisted: boolean, opts?: IfVersionOptions & ExpectationOptions): Promise<StackRecord>;
182
+ /**
183
+ * The write gate, plus the reference gate on each add new to the record:
184
+ * a remove, or an add of an identity already held, names a reference the
185
+ * record carries, so it is gated by the write bit alone.
186
+ */
187
+ editAssociations(id: RecordId, edits: AssociationEdit[], opts?: IfVersionOptions & ExpectationOptions): Promise<StackRecord>;
188
+ /** editAssociations()'s gates, with every element new to the set an add. */
189
+ setAssociations(id: RecordId, associations: DataAssociation[], opts?: IfVersionOptions & ExpectationOptions): Promise<StackRecord>;
190
+ /**
191
+ * The write gate, then the reference gate over the elements a write adds,
192
+ * asked against the stored set so an association the record already
193
+ * carries is not re-gated. `Stack` asks it of each read it writes from,
194
+ * so a retried write is gated on the set it lands on.
195
+ */
196
+ private gateAssociationWrite;
197
+ /**
198
+ * Extend or withdraw who reaches a record, on the reshare gate. The write
199
+ * bit does not confer it, or a write-holder could decide who else reaches
200
+ * the record. See docs/spec/access-control.md § Record-level permissions.
201
+ */
202
+ editAccess(id: RecordId, edits: AssociationEdit[], opts?: IfVersionOptions & ExpectationOptions): Promise<StackRecord>;
203
+ /** See editAccess() — the same gate. */
204
+ setAccess(id: RecordId, permissions: AuthorityAssociation[], opts?: IfVersionOptions & ExpectationOptions): Promise<StackRecord>;
205
+ /**
206
+ * The record, having established that this request may decide who else
207
+ * reaches it — the owner-or-creator rule, asked of both sides of a
208
+ * delegation, or a Group's admin rule for a `_group`. The gate the access
209
+ * and listing verbs carry, which the write bit deliberately does not confer.
210
+ */
211
+ private requireReshareable;
212
+ /** requireReshareable()'s gate, asked of a record already found in its family. */
213
+ private gateReshare;
214
+ /**
215
+ * Refuse a write moving content its family reserves to the owner acting
216
+ * alone — an `_app` card's bindings, the owner's own DID on an `_entity`
217
+ * — whichever verb carries it. See docs/spec/identity.md § DID bindings.
218
+ */
219
+ private requireOwnerFields;
220
+ /**
221
+ * A delegated write's `appId` must match the `_app` card the owner
222
+ * registered for the principal's DID, if there is one: a verified
223
+ * principal may not claim a name the owner gave other software.
224
+ * See docs/spec/identity.md § Attribution and what can be trusted.
225
+ */
226
+ private requireAppIdMatchesPrincipal;
227
+ /**
228
+ * Refuse anyone but the owner acting alone a write to a family only the
229
+ * owner writes — `_grant` and `_install`, which are authority — with the
230
+ * refusal an unreadable Record answers with. Any other family passes.
231
+ * See docs/spec/access-control.md § What a grant covers.
232
+ */
233
+ private requireOwnerAloneWriter;
234
+ /**
235
+ * Purge is owner-only: it is irreversible and destroys version
236
+ * history, so neither the write bit nor delete-own/delete-any grants
237
+ * reach it, and delegation doesn't carry it either. Everyone else is
238
+ * limited to soft delete.
239
+ */
240
+ delete(id: RecordId, opts?: DeleteRecordOptions & ExpectationOptions): Promise<DeleteResult>;
241
+ /**
242
+ * Reverse a soft delete. Gated the same as delete() — undelete is the
243
+ * inverse of soft delete, so granting one direction without the other
244
+ * would be backwards. Idempotent, per Stack.undelete().
245
+ */
246
+ undelete(id: RecordId, opts?: IfVersionOptions & ExpectationOptions): Promise<StackRecord>;
247
+ /**
248
+ * History is the mutation/recovery surface, not a read surface — gated
249
+ * like patchContent(). Reading it changes nothing, so it is the one path
250
+ * the `_grant` write fence leaves alone: seeing how a Record you can
251
+ * already read got that way is not the escalation that fence exists to
252
+ * stop. See docs/spec/versioning.md § History access.
253
+ */
254
+ getVersions(id: RecordId, query?: VersionsQuery): Promise<RecordVersion[]>;
255
+ /**
256
+ * See getVersions() — the same gate. A requester who may not reshare the
257
+ * record is served each `reshare` op without the elements beneath it.
258
+ * See docs/spec/journal.md § Reading it.
259
+ */
260
+ getJournal(id: RecordId, query?: JournalQuery): Promise<RecordJournalEntry[]>;
261
+ /** See getVersions() — the same mutate-surface gate. */
262
+ getVersion(id: RecordId, version: number): Promise<RecordVersion | null>;
263
+ /**
264
+ * Re-runs the reference-creation checks against the snapshot, so a
265
+ * restore can't re-convey access to a file the subject can no longer
266
+ * reach today. Only the owner acting alone is exempt: under delegation
267
+ * the checks resolve against the subject, which is whose reach the
268
+ * restore would widen. See docs/spec/versioning.md § Restore semantics.
269
+ */
270
+ restoreVersion(id: RecordId, version: number, opts?: IfVersionOptions & ExpectationOptions): Promise<StackRecord>;
271
+ /**
272
+ * Commit a per-record migration: the owner acting alone, or an installed
273
+ * app within its own families (requireInstallMigration()). Ordinary write
274
+ * access is not consent to move a record between families.
275
+ * See docs/spec/access-control.md § What a grant covers.
276
+ */
277
+ commitMigration(id: RecordId, toTypeId: TypeId, content: Record<string, unknown>, opts?: IfVersionOptions): Promise<StackRecord>;
278
+ /**
279
+ * Refuse a migration this request may not commit as an installed app —
280
+ * see ScopeAuthority.installMayMigrate(). The tombstone refusal comes
281
+ * only once authority is settled, as every mutating verb asks it: the
282
+ * owner may migrate a tombstone; an app sees it without content.
283
+ * See docs/spec/apps.md § Migrating an installed app's types.
284
+ */
285
+ private requireInstallMigration;
286
+ /**
287
+ * Store bytes and create an _attachment@1 metadata record (create grant
288
+ * on `_attachment@1` required; anonymous denied), returning that record.
289
+ * Authorship and principal are stamped exactly as create() does.
290
+ */
291
+ putAttachment(data: Uint8Array, opts: PutAttachmentOptions): Promise<StackRecord & {
292
+ content: AttachmentContent;
293
+ }>;
294
+ /**
295
+ * Download attachment bytes. Accessible to the owner, a reader of any
296
+ * referencing record, or the uploader pre-association — the same
297
+ * predicate as the reference-creation gate (canAccessFile).
298
+ */
299
+ getAttachment(fileId: FileId): Promise<Uint8Array>;
300
+ /**
301
+ * Delete an attachment. Only the stack owner may delete attachments.
302
+ * Delegates to Stack.deleteAttachment(), which enforces the "not referenced" check.
303
+ */
304
+ deleteAttachment(fileId: FileId): Promise<void>;
305
+ /**
306
+ * Sweep for unreferenced attachment bytes and delete them. Only the stack
307
+ * owner may run this. Delegates to Stack.collectAttachmentGarbage().
308
+ */
309
+ collectAttachmentGarbage(opts?: CollectAttachmentGarbageOptions): Promise<CollectAttachmentGarbageResult>;
310
+ /**
311
+ * Observe the changes this request may read, decided per event by the
312
+ * same read reach that get() and query() ask. An unreadable record yields
313
+ * no event at all, since a change's existence is itself a disclosure.
314
+ * See docs/spec/events.md § Permission scoping.
315
+ */
316
+ subscribe(handler: (change: RecordChange) => void, opts?: SubscribeOptions): Promise<Unsubscribe>;
317
+ }
318
+ //# 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,EACN,WAAW,EACX,KAAK,EACL,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,UAAU,EACV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