cojson 0.0.6 → 0.0.8

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 (74) hide show
  1. package/.eslintrc.cjs +11 -8
  2. package/dist/coValue.d.ts +97 -0
  3. package/dist/coValue.js +341 -401
  4. package/dist/coValue.js.map +1 -0
  5. package/dist/coValue.test.d.ts +1 -0
  6. package/dist/coValue.test.js +69 -113
  7. package/dist/coValue.test.js.map +1 -0
  8. package/dist/contentType.d.ts +15 -0
  9. package/dist/contentType.js +5 -5
  10. package/dist/contentType.js.map +1 -0
  11. package/dist/contentType.test.d.ts +1 -0
  12. package/dist/contentType.test.js +138 -168
  13. package/dist/contentType.test.js.map +1 -0
  14. package/dist/contentTypes/coList.d.ts +11 -0
  15. package/dist/contentTypes/coList.js +14 -16
  16. package/dist/contentTypes/coList.js.map +1 -0
  17. package/dist/contentTypes/coMap.d.ts +56 -0
  18. package/dist/contentTypes/coMap.js +112 -112
  19. package/dist/contentTypes/coMap.js.map +1 -0
  20. package/dist/contentTypes/coStream.d.ts +11 -0
  21. package/dist/contentTypes/coStream.js +14 -16
  22. package/dist/contentTypes/coStream.js.map +1 -0
  23. package/dist/contentTypes/static.d.ts +11 -0
  24. package/dist/contentTypes/static.js +12 -14
  25. package/dist/contentTypes/static.js.map +1 -0
  26. package/dist/crypto.d.ts +97 -0
  27. package/dist/crypto.js +100 -151
  28. package/dist/crypto.js.map +1 -0
  29. package/dist/crypto.test.d.ts +1 -0
  30. package/dist/crypto.test.js +94 -134
  31. package/dist/crypto.test.js.map +1 -0
  32. package/dist/ids.d.ts +7 -0
  33. package/dist/ids.js +2 -1
  34. package/dist/ids.js.map +1 -0
  35. package/dist/index.d.ts +19 -0
  36. package/dist/index.js +10 -18
  37. package/dist/index.js.map +1 -0
  38. package/dist/jsonValue.d.ts +7 -0
  39. package/dist/jsonValue.js +2 -1
  40. package/dist/jsonValue.js.map +1 -0
  41. package/dist/node.d.ts +33 -0
  42. package/dist/node.js +102 -133
  43. package/dist/node.js.map +1 -0
  44. package/dist/permissions.d.ts +54 -0
  45. package/dist/permissions.js +202 -228
  46. package/dist/permissions.js.map +1 -0
  47. package/dist/permissions.test.d.ts +1 -0
  48. package/dist/permissions.test.js +724 -915
  49. package/dist/permissions.test.js.map +1 -0
  50. package/dist/sync.d.ts +80 -0
  51. package/dist/sync.js +247 -294
  52. package/dist/sync.js.map +1 -0
  53. package/dist/sync.test.d.ts +1 -0
  54. package/dist/sync.test.js +763 -798
  55. package/dist/sync.test.js.map +1 -0
  56. package/package.json +7 -4
  57. package/src/coValue.test.ts +3 -4
  58. package/src/coValue.ts +11 -17
  59. package/src/contentType.test.ts +3 -3
  60. package/src/contentType.ts +6 -6
  61. package/src/contentTypes/coList.ts +4 -4
  62. package/src/contentTypes/coMap.ts +6 -6
  63. package/src/contentTypes/coStream.ts +4 -4
  64. package/src/contentTypes/static.ts +5 -5
  65. package/src/crypto.test.ts +1 -1
  66. package/src/crypto.ts +2 -2
  67. package/src/index.ts +9 -7
  68. package/src/jsonValue.ts +1 -1
  69. package/src/node.ts +6 -7
  70. package/src/permissions.test.ts +5 -5
  71. package/src/permissions.ts +7 -7
  72. package/src/sync.test.ts +7 -7
  73. package/src/sync.ts +6 -6
  74. package/tsconfig.json +1 -7
package/.eslintrc.cjs CHANGED
@@ -1,18 +1,21 @@
1
1
  module.exports = {
2
2
  extends: [
3
- 'eslint:recommended',
4
- 'plugin:@typescript-eslint/recommended',
3
+ "eslint:recommended",
4
+ "plugin:@typescript-eslint/recommended",
5
+ "plugin:require-extensions/recommended",
5
6
  ],
6
- parser: '@typescript-eslint/parser',
7
- plugins: ['@typescript-eslint'],
7
+ parser: "@typescript-eslint/parser",
8
+ plugins: ["@typescript-eslint", "require-extensions"],
8
9
  parserOptions: {
9
- project: './tsconfig.json',
10
+ project: "./tsconfig.json",
10
11
  },
11
12
  root: true,
12
13
  rules: {
13
14
  "no-unused-vars": "off",
14
- "@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }],
15
+ "@typescript-eslint/no-unused-vars": [
16
+ "error",
17
+ { argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
18
+ ],
15
19
  "@typescript-eslint/no-floating-promises": "error",
16
20
  },
17
-
18
- };
21
+ };
@@ -0,0 +1,97 @@
1
+ import { ContentType } from './contentType.js';
2
+ import { Encrypted, Hash, KeySecret, RecipientID, RecipientSecret, SignatoryID, SignatorySecret, Signature, StreamingHash, KeyID } from './crypto.js';
3
+ import { JsonValue } from './jsonValue.js';
4
+ import { PermissionsDef as RulesetDef, Team } from './permissions.js';
5
+ import { LocalNode } from './node.js';
6
+ import { CoValueKnownState, NewContentMessage } from './sync.js';
7
+ import { AgentID, RawCoValueID, SessionID, TransactionID } from './ids.js';
8
+ export type CoValueHeader = {
9
+ type: ContentType["type"];
10
+ ruleset: RulesetDef;
11
+ meta: JsonValue;
12
+ createdAt: `2${string}` | null;
13
+ uniqueness: `z${string}` | null;
14
+ publicNickname?: string;
15
+ };
16
+ export declare function agentIDfromSessionID(sessionID: SessionID): AgentID;
17
+ export declare function newRandomSessionID(agentID: AgentID): SessionID;
18
+ type SessionLog = {
19
+ transactions: Transaction[];
20
+ lastHash?: Hash;
21
+ streamingHash: StreamingHash;
22
+ lastSignature: Signature;
23
+ };
24
+ export type PrivateTransaction = {
25
+ privacy: "private";
26
+ madeAt: number;
27
+ keyUsed: KeyID;
28
+ encryptedChanges: Encrypted<JsonValue[], {
29
+ in: RawCoValueID;
30
+ tx: TransactionID;
31
+ }>;
32
+ };
33
+ export type TrustingTransaction = {
34
+ privacy: "trusting";
35
+ madeAt: number;
36
+ changes: JsonValue[];
37
+ };
38
+ export type Transaction = PrivateTransaction | TrustingTransaction;
39
+ export type DecryptedTransaction = {
40
+ txID: TransactionID;
41
+ changes: JsonValue[];
42
+ madeAt: number;
43
+ };
44
+ export declare class CoValue {
45
+ id: RawCoValueID;
46
+ node: LocalNode;
47
+ header: CoValueHeader;
48
+ sessions: {
49
+ [key: SessionID]: SessionLog;
50
+ };
51
+ content?: ContentType;
52
+ listeners: Set<(content?: ContentType) => void>;
53
+ constructor(header: CoValueHeader, node: LocalNode);
54
+ testWithDifferentCredentials(agentCredential: AgentCredential, ownSessionID: SessionID): CoValue;
55
+ knownState(): CoValueKnownState;
56
+ get meta(): JsonValue;
57
+ nextTransactionID(): TransactionID;
58
+ tryAddTransactions(sessionID: SessionID, newTransactions: Transaction[], newHash: Hash, newSignature: Signature): boolean;
59
+ subscribe(listener: (content?: ContentType) => void): () => void;
60
+ expectedNewHashAfter(sessionID: SessionID, newTransactions: Transaction[]): {
61
+ expectedNewHash: Hash;
62
+ newStreamingHash: StreamingHash;
63
+ };
64
+ makeTransaction(changes: JsonValue[], privacy: "private" | "trusting"): boolean;
65
+ getCurrentContent(): ContentType;
66
+ getValidSortedTransactions(): DecryptedTransaction[];
67
+ getCurrentReadKey(): {
68
+ secret: KeySecret | undefined;
69
+ id: KeyID;
70
+ };
71
+ getReadKey(keyID: KeyID): KeySecret | undefined;
72
+ getTeam(): Team;
73
+ getTx(txID: TransactionID): Transaction | undefined;
74
+ newContentSince(knownState: CoValueKnownState | undefined): NewContentMessage | undefined;
75
+ getDependedOnCoValues(): RawCoValueID[];
76
+ }
77
+ export type Agent = {
78
+ signatoryID: SignatoryID;
79
+ recipientID: RecipientID;
80
+ publicNickname?: string;
81
+ };
82
+ export declare function getAgent(agentCredential: AgentCredential): {
83
+ signatoryID: `signatory_z${string}`;
84
+ recipientID: `recipient_z${string}`;
85
+ publicNickname: string | undefined;
86
+ };
87
+ export declare function getAgentCoValueHeader(agent: Agent): CoValueHeader;
88
+ export declare function getAgentID(agent: Agent): AgentID;
89
+ export type AgentCredential = {
90
+ signatorySecret: SignatorySecret;
91
+ recipientSecret: RecipientSecret;
92
+ publicNickname?: string;
93
+ };
94
+ export declare function newRandomAgentCredential(publicNickname?: string): AgentCredential;
95
+ export declare function agentCredentialToBytes(cred: AgentCredential): Uint8Array;
96
+ export declare function agentCredentialFromBytes(bytes: Uint8Array): AgentCredential | undefined;
97
+ export {};