@docstack/client 0.1.8 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/LICENSE +0 -0
  2. package/README.md +373 -132
  3. package/lib/core/attribute.d.ts +0 -0
  4. package/lib/core/class.d.ts +0 -0
  5. package/lib/core/content-transfer.d.ts +0 -0
  6. package/lib/core/crypto-engine/index.d.ts +63 -5
  7. package/lib/core/crypto-engine/utils.d.ts +10 -2
  8. package/lib/core/datamodel/index.d.ts +0 -0
  9. package/lib/core/domain.d.ts +0 -0
  10. package/lib/core/guarded-db.d.ts +0 -0
  11. package/lib/core/index.d.ts +4 -2
  12. package/lib/core/job-engine/index.d.ts +0 -0
  13. package/lib/core/job-engine/schedule.d.ts +0 -0
  14. package/lib/core/job-engine/scheduler.d.ts +0 -0
  15. package/lib/core/query-engine/accumulators.d.ts +0 -0
  16. package/lib/core/query-engine/classes.d.ts +0 -0
  17. package/lib/core/query-engine/evaluator.d.ts +0 -0
  18. package/lib/core/query-engine/executor.d.ts +0 -0
  19. package/lib/core/query-engine/index.d.ts +0 -0
  20. package/lib/core/query-engine/parser.d.ts +0 -0
  21. package/lib/core/query-engine/planner.d.ts +0 -0
  22. package/lib/core/stack.d.ts +223 -8
  23. package/lib/core/sync/class-filter.d.ts +0 -0
  24. package/lib/core/sync/filter-identity.d.ts +0 -0
  25. package/lib/core/sync/index.d.ts +17 -2
  26. package/lib/core/sync/internal-docs.d.ts +0 -0
  27. package/lib/core/sync/tenants.d.ts +0 -0
  28. package/lib/core/test-utils/docstack.d.ts +0 -0
  29. package/lib/core/transaction-engine/errors.d.ts +57 -0
  30. package/lib/core/transaction-engine/handle.d.ts +165 -0
  31. package/lib/core/transaction-engine/index.d.ts +82 -0
  32. package/lib/core/transaction-engine/overlay.d.ts +66 -0
  33. package/lib/core/transaction-engine/stage.d.ts +50 -0
  34. package/lib/core/transaction-engine/sweep.d.ts +25 -0
  35. package/lib/core/trigger/index.d.ts +0 -0
  36. package/lib/index.d.ts +12 -2
  37. package/lib/index.js +4710 -733
  38. package/lib/index.umd.js +5259 -623
  39. package/lib/index2.js +641 -0
  40. package/lib/plugins/pouchdb.d.ts +16 -1
  41. package/lib/utils/crypto/index.d.ts +0 -0
  42. package/lib/utils/index.d.ts +4 -2
  43. package/lib/utils/logger/index.d.ts +0 -0
  44. package/lib/utils/logger/transport.d.ts +0 -0
  45. package/lib/workers/dataModel.d.ts +0 -0
  46. package/package.json +3 -1
  47. package/lib/core/policy-engine/index.d.ts +0 -132
@@ -18,7 +18,22 @@ export declare class StackLockedError extends Error {
18
18
  name: string;
19
19
  /** The class the refused document belongs to. */
20
20
  readonly className: string;
21
- constructor(className: string);
21
+ /** The sealed scope, when the refusal is a scope's rather than the legacy key's (ADR-0045). */
22
+ readonly scopeId?: string;
23
+ constructor(className: string, scopeId?: string);
24
+ }
25
+ /**
26
+ * A write whose `~scope` label disagrees with its sealed payloads' key ids
27
+ * (spec 02 §2.3 rule 2). Refused, never repaired: re-sealing content the
28
+ * writer could not open under the labeled scope's key is exactly the
29
+ * induced-downgrade attack a tampered label is fishing for. A legitimate
30
+ * relabel opens the original scope first, so its payloads arrive as plaintext.
31
+ */
32
+ export declare class StackScopeMismatchError extends Error {
33
+ name: string;
34
+ readonly docId: string;
35
+ readonly scopeId: string;
36
+ constructor(docId: string, scopeId: string, kid: string | undefined);
22
37
  }
23
38
  /**
24
39
  * Resolves the effective `new_edits` flag for a `bulkDocs` call.
File without changes
@@ -1,4 +1,6 @@
1
- import { Document } from "@docstack/shared";
1
+ import { AttributeModel, Document } from "@docstack/shared";
2
2
  import Class from "../core/class.js";
3
3
  import * as jsondiff from 'jsondiffpatch';
4
- export declare const applySchemaDelta: (doc: Document, schemaDelta: jsondiff.AddedDelta | jsondiff.ModifiedDelta | jsondiff.DeletedDelta | jsondiff.ObjectDelta | jsondiff.ArrayDelta | jsondiff.MovedDelta | jsondiff.TextDiffDelta, classObj: Class) => Promise<Document>;
4
+ export declare const applySchemaDelta: (doc: Document, schemaDelta: jsondiff.AddedDelta | jsondiff.ModifiedDelta | jsondiff.DeletedDelta | jsondiff.ObjectDelta | jsondiff.ArrayDelta | jsondiff.MovedDelta | jsondiff.TextDiffDelta, classObj: Class, newSchema?: {
5
+ [name: string]: AttributeModel;
6
+ }) => Promise<Document>;
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@docstack/client",
3
3
  "description": "One does not simply stack documents.",
4
- "version": "0.1.8",
4
+ "version": "0.3.0",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.js",
7
7
  "types": "lib/index.d.ts",
@@ -44,8 +44,10 @@
44
44
  },
45
45
  "homepage": "https://onyx.ac/docstack",
46
46
  "dependencies": {
47
+ "@docstack/abe": "^0.1.0",
47
48
  "@docstack/shared": "^0.1.0",
48
49
  "jsondiffpatch": "^0.7.3",
50
+ "pouchdb-selector-core": "^9.0.0",
49
51
  "semver": "^7.7.3",
50
52
  "zod": "^4.1.5"
51
53
  },
@@ -1,132 +0,0 @@
1
- import type ClientStack from "../stack.js";
2
- import type { Document } from "@docstack/shared";
3
- /** The type of operation being authorized: read or write. */
4
- export type PolicyOperation = "read" | "write";
5
- /**
6
- * Engine for evaluating access control policies on documents.
7
- *
8
- * PolicyEngine implements role-based access control (RBAC) by evaluating
9
- * policy rules against documents and user sessions. Policies can be:
10
- * - Class-level (apply to all documents of a class)
11
- * - User-specific (apply only to a specific user)
12
- * - Group-specific (apply only to users in a specific group)
13
- *
14
- * Policy rules are JavaScript expressions that receive the document,
15
- * session, and groupId as context and return a boolean.
16
- *
17
- * @example
18
- * ```typescript
19
- * // Policy engine is used automatically during document operations
20
- * // Policies are defined as documents:
21
- * await stack.createDoc(null, '~Policy', null, {
22
- * name: 'user-read-own',
23
- * targetClass: ['User'],
24
- * rule: 'return document.userId === session.userId;'
25
- * });
26
- * ```
27
- */
28
- export declare class PolicyEngine {
29
- /** Reference to the parent stack for database and session access. */
30
- private readonly stack;
31
- /**
32
- * Every `~Policy` document, loaded once and reused across evaluations.
33
- *
34
- * `isReadableDocument` runs once per document a read returns, and it used to re-fetch
35
- * the policy list from the database each time - the dominant cost of every read path.
36
- * The list is invalidated on any write that touches a `~Policy` document: the write
37
- * path calls {@link invalidatePolicyCache} synchronously (see StackPlugin), and the
38
- * stack's shared changes feed calls it again for out-of-band writes such as another
39
- * tab's. `null` means not loaded.
40
- */
41
- private allPoliciesCache;
42
- /**
43
- * Compiled policy rules, keyed by their source text.
44
- *
45
- * A rule is evaluated once per policy per document, and `new Function` is a full
46
- * compile each time. The source text is the key - not the policy id - so two policies
47
- * sharing a rule share the compilation, and an edited rule is simply a new key.
48
- */
49
- private compiledRules;
50
- /**
51
- * Creates a new PolicyEngine instance.
52
- * @param stack - The parent ClientStack instance
53
- */
54
- constructor(stack: ClientStack);
55
- /**
56
- * Drops the cached policy list so the next evaluation re-reads it.
57
- * Called by the write path and the changes feed whenever a `~Policy` document lands.
58
- */
59
- invalidatePolicyCache(): void;
60
- /**
61
- * Gets the current authentication session proof.
62
- * @returns The session proof, or undefined if not authenticated
63
- */
64
- private getSessionProof;
65
- /**
66
- * Checks if a class should bypass policy evaluation.
67
- * System classes (prefixed with ~) are always allowed.
68
- *
69
- * @param targetClass - The class name to check
70
- * @returns `true` if the class should bypass policies
71
- */
72
- private shouldBypass;
73
- private loadPolicies;
74
- private getTargetIdentifiers;
75
- private resolveClassTarget;
76
- /**
77
- * Evaluates a policy rule against a document and session.
78
- * The rule is a JavaScript expression that returns a boolean.
79
- *
80
- * @param policy - The policy containing the rule
81
- * @param document - The document being accessed
82
- * @param session - The current auth session
83
- * @returns Whether the rule permits access
84
- */
85
- private evaluateRule;
86
- private filterPoliciesForSession;
87
- private authorize;
88
- /**
89
- * Whether any policy applies to a class - i.e. whether reads of it are filtered.
90
- *
91
- * Lets the query engine know when a database-level LIMIT is safe: with no
92
- * applicable policies, no row fetched within the limit can be dropped afterwards.
93
- * Cheap once the policy list is cached.
94
- *
95
- * @param targetClass - The class name or id.
96
- * @returns `true` if at least one policy targets the class.
97
- */
98
- hasPoliciesFor(targetClass: string): Promise<boolean>;
99
- /**
100
- * Ensures write access is allowed for a document of the given class.
101
- * Throws an error if no policy permits the write operation.
102
- *
103
- * @param targetClass - The class of the document being written
104
- * @param document - The document to write
105
- * @throws Error if write is not permitted
106
- *
107
- * @example
108
- * ```typescript
109
- * // Called automatically during createDoc/updateCard operations
110
- * await policyEngine.ensureWriteAllowed('Task', taskDocument);
111
- * ```
112
- */
113
- ensureWriteAllowed(targetClass: string, document: Document | null): Promise<void>;
114
- /**
115
- * Checks if a document is readable by the current user.
116
- * Used to filter query results based on read policies.
117
- *
118
- * @param document - The document to check
119
- * @returns `true` if the document can be read
120
- * @throws Error if the stack is not authenticated
121
- *
122
- * @example
123
- * ```typescript
124
- * // Used internally during findDocuments
125
- * const readable = await policyEngine.isReadableDocument(doc);
126
- * if (readable) {
127
- * results.push(doc);
128
- * }
129
- * ```
130
- */
131
- isReadableDocument(document: Document): Promise<boolean>;
132
- }