@evolu/common 8.10.0 → 8.12.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 (152) hide show
  1. package/dist/src/Bytes.d.ts +39 -2
  2. package/dist/src/Bytes.d.ts.map +1 -1
  3. package/dist/src/Bytes.js +50 -2
  4. package/dist/src/Config.d.ts +22 -22
  5. package/dist/src/Config.d.ts.map +1 -1
  6. package/dist/src/Console.d.ts +62 -7
  7. package/dist/src/Console.d.ts.map +1 -1
  8. package/dist/src/Console.js +20 -4
  9. package/dist/src/Crypto.d.ts +76 -4
  10. package/dist/src/Crypto.d.ts.map +1 -1
  11. package/dist/src/Crypto.js +55 -4
  12. package/dist/src/Error.d.ts +45 -0
  13. package/dist/src/Error.d.ts.map +1 -1
  14. package/dist/src/Error.js +69 -0
  15. package/dist/src/Fs.d.ts +92 -18
  16. package/dist/src/Fs.d.ts.map +1 -1
  17. package/dist/src/Fs.js +2 -0
  18. package/dist/src/Identicon.d.ts +2 -2
  19. package/dist/src/Identicon.js +2 -2
  20. package/dist/src/LeakDetector.d.ts +22 -3
  21. package/dist/src/LeakDetector.d.ts.map +1 -1
  22. package/dist/src/LeakDetector.js +12 -2
  23. package/dist/src/LockManager.d.ts +8 -0
  24. package/dist/src/LockManager.d.ts.map +1 -1
  25. package/dist/src/LockManager.js +6 -0
  26. package/dist/src/Object.d.ts.map +1 -1
  27. package/dist/src/Object.js +5 -0
  28. package/dist/src/Platform.d.ts +47 -7
  29. package/dist/src/Platform.d.ts.map +1 -1
  30. package/dist/src/Platform.js +24 -5
  31. package/dist/src/Random.d.ts +25 -2
  32. package/dist/src/Random.d.ts.map +1 -1
  33. package/dist/src/Random.js +14 -2
  34. package/dist/src/Resource.d.ts +156 -1
  35. package/dist/src/Resource.d.ts.map +1 -1
  36. package/dist/src/Resource.js +201 -72
  37. package/dist/src/Schedule.d.ts +11 -10
  38. package/dist/src/Schedule.d.ts.map +1 -1
  39. package/dist/src/Schedule.js +1 -1
  40. package/dist/src/Sqlite.d.ts +132 -16
  41. package/dist/src/Sqlite.d.ts.map +1 -1
  42. package/dist/src/Sqlite.js +63 -9
  43. package/dist/src/Task.d.ts +15 -4
  44. package/dist/src/Task.d.ts.map +1 -1
  45. package/dist/src/Task.js +41 -15
  46. package/dist/src/Test.d.ts +9 -0
  47. package/dist/src/Test.d.ts.map +1 -1
  48. package/dist/src/Test.js +4 -0
  49. package/dist/src/Time.d.ts +106 -9
  50. package/dist/src/Time.d.ts.map +1 -1
  51. package/dist/src/Time.js +55 -4
  52. package/dist/src/Type.d.ts +1455 -1310
  53. package/dist/src/Type.d.ts.map +1 -1
  54. package/dist/src/Type.js +1274 -517
  55. package/dist/src/WebSocket.d.ts +164 -13
  56. package/dist/src/WebSocket.d.ts.map +1 -1
  57. package/dist/src/WebSocket.js +133 -24
  58. package/dist/src/Worker.d.ts +90 -8
  59. package/dist/src/Worker.d.ts.map +1 -1
  60. package/dist/src/Worker.js +28 -2
  61. package/dist/src/index.d.ts +6 -7
  62. package/dist/src/index.d.ts.map +1 -1
  63. package/dist/src/index.js +2 -3
  64. package/dist/src/local-first/Db.d.ts +52 -3
  65. package/dist/src/local-first/Db.d.ts.map +1 -1
  66. package/dist/src/local-first/Db.js +412 -137
  67. package/dist/src/local-first/Evolu.d.ts +412 -213
  68. package/dist/src/local-first/Evolu.d.ts.map +1 -1
  69. package/dist/src/local-first/Evolu.js +181 -18
  70. package/dist/src/local-first/Owner.d.ts +13 -30
  71. package/dist/src/local-first/Owner.d.ts.map +1 -1
  72. package/dist/src/local-first/Owner.js +13 -30
  73. package/dist/src/local-first/Protocol.d.ts +106 -19
  74. package/dist/src/local-first/Protocol.d.ts.map +1 -1
  75. package/dist/src/local-first/Protocol.js +162 -60
  76. package/dist/src/local-first/Query.d.ts +8 -15
  77. package/dist/src/local-first/Query.d.ts.map +1 -1
  78. package/dist/src/local-first/Relay.d.ts.map +1 -1
  79. package/dist/src/local-first/Relay.js +4 -2
  80. package/dist/src/local-first/Schema.d.ts +346 -23
  81. package/dist/src/local-first/Schema.d.ts.map +1 -1
  82. package/dist/src/local-first/Schema.js +214 -17
  83. package/dist/src/local-first/Shared.d.ts +537 -22
  84. package/dist/src/local-first/Shared.d.ts.map +1 -1
  85. package/dist/src/local-first/Shared.js +1437 -234
  86. package/dist/src/local-first/Storage.d.ts +195 -17
  87. package/dist/src/local-first/Storage.d.ts.map +1 -1
  88. package/dist/src/local-first/Storage.js +85 -22
  89. package/dist/src/local-first/Timestamp.d.ts +392 -41
  90. package/dist/src/local-first/Timestamp.d.ts.map +1 -1
  91. package/dist/src/local-first/Timestamp.js +403 -81
  92. package/dist/src/local-first/index.d.ts +0 -1
  93. package/dist/src/local-first/index.d.ts.map +1 -1
  94. package/dist/src/local-first/index.js +0 -1
  95. package/package.json +1 -1
  96. package/src/Assert.test.ts +2 -5
  97. package/src/Bytes.test.ts +27 -0
  98. package/src/Bytes.ts +58 -2
  99. package/src/Config.test.ts +2 -6
  100. package/src/Config.ts +133 -133
  101. package/src/Console.ts +62 -7
  102. package/src/Crypto.ts +76 -4
  103. package/src/Eq.test.ts +2 -3
  104. package/src/Error.test.ts +76 -3
  105. package/src/Error.ts +71 -0
  106. package/src/Fs.ts +92 -18
  107. package/src/Identicon.ts +2 -2
  108. package/src/LeakDetector.ts +22 -3
  109. package/src/LockManager.ts +8 -0
  110. package/src/Object.test.ts +27 -12
  111. package/src/Object.ts +5 -0
  112. package/src/Platform.ts +50 -8
  113. package/src/Random.ts +25 -2
  114. package/src/Resource.test.ts +837 -0
  115. package/src/Resource.ts +235 -15
  116. package/src/Schedule.test.ts +50 -12
  117. package/src/Schedule.ts +24 -14
  118. package/src/Sqlite.ts +137 -17
  119. package/src/Task.test.ts +189 -8
  120. package/src/Task.ts +56 -17
  121. package/src/Test.ts +9 -0
  122. package/src/Time.ts +106 -9
  123. package/src/Type.test.ts +946 -1028
  124. package/src/Type.ts +4195 -3136
  125. package/src/Types.test.ts +4 -14
  126. package/src/WebSocket.ts +313 -40
  127. package/src/Worker.ts +90 -8
  128. package/src/index.ts +20 -6
  129. package/src/local-first/Db.ts +644 -339
  130. package/src/local-first/Evolu.test.ts +994 -22
  131. package/src/local-first/Evolu.ts +625 -232
  132. package/src/local-first/Owner.ts +13 -30
  133. package/src/local-first/Protocol.test.ts +634 -10
  134. package/src/local-first/Protocol.ts +255 -109
  135. package/src/local-first/Query.ts +8 -15
  136. package/src/local-first/Relay.ts +4 -2
  137. package/src/local-first/Schema.test.ts +143 -0
  138. package/src/local-first/Schema.ts +376 -26
  139. package/src/local-first/Shared.test.ts +7731 -559
  140. package/src/local-first/Shared.ts +2036 -267
  141. package/src/local-first/Storage.ts +224 -36
  142. package/src/local-first/Timestamp.test.ts +344 -70
  143. package/src/local-first/Timestamp.ts +434 -118
  144. package/src/local-first/index.ts +0 -1
  145. package/dist/src/local-first/Error.d.ts +0 -12
  146. package/dist/src/local-first/Error.d.ts.map +0 -1
  147. package/dist/src/local-first/Error.js +0 -6
  148. package/dist/src/local-first/LocalAuth.d.ts +0 -150
  149. package/dist/src/local-first/LocalAuth.d.ts.map +0 -1
  150. package/dist/src/local-first/LocalAuth.js +0 -179
  151. package/src/local-first/Error.ts +0 -17
  152. package/src/local-first/LocalAuth.ts +0 -457
@@ -0,0 +1,143 @@
1
+ import { test } from "node:test";
2
+ import {
3
+ assertEqual,
4
+ assertErr,
5
+ assertOk,
6
+ assertSame,
7
+ assertType,
8
+ createEvolu,
9
+ createQueryBuilder,
10
+ type Evolu,
11
+ NonEmptyTrimmedString100,
12
+ object,
13
+ type OwnerIdBytes,
14
+ ownerIdToOwnerIdBytes,
15
+ sqliteQueryStringToSqliteQuery,
16
+ type Task,
17
+ testAppName,
18
+ testAppOwner,
19
+ type TestEvoluSchema,
20
+ testEvoluSchema,
21
+ testLocalOnlyEvoluSchema,
22
+ testOwnerSecret,
23
+ TestProjectId,
24
+ testProjectId,
25
+ TestTodoId,
26
+ testTodoId,
27
+ type TimestampBytes,
28
+ } from "../index.ts";
29
+ import type { EvoluPlatformDeps } from "./Evolu.ts";
30
+ import type { ValidateSchema } from "./Schema.ts";
31
+
32
+ test("history queries select and filter by ownerId bytes", () => {
33
+ const createQuery = createQueryBuilder(testEvoluSchema);
34
+ const query = createQuery((db) =>
35
+ db
36
+ .selectFrom("evolu_history")
37
+ .select(["ownerId", "timestamp"])
38
+ .where("ownerId", "=", ownerIdToOwnerIdBytes(testAppOwner.id)),
39
+ );
40
+
41
+ assertType<
42
+ typeof query.Row,
43
+ { ownerId: OwnerIdBytes; timestamp: TimestampBytes }
44
+ >();
45
+ });
46
+
47
+ test("testEvoluSchema supports project-linked and independent todos", () => {
48
+ assertType<TestEvoluSchema, typeof testEvoluSchema>();
49
+ assertType<ValidateSchema<TestEvoluSchema>, TestEvoluSchema>();
50
+ assertType<typeof testTodoId, TestTodoId>();
51
+ assertType<typeof testProjectId, TestProjectId>();
52
+ assertSame(testEvoluSchema.todo.id, TestTodoId);
53
+ assertSame(testEvoluSchema.project.id, TestProjectId);
54
+ assertEqual(new Set<string>([testTodoId, testProjectId]).size, 2);
55
+ const Todo = object(testEvoluSchema.todo);
56
+ const todo = {
57
+ id: testTodoId,
58
+ title: "Write documentation",
59
+ isCompleted: null,
60
+ projectId: testProjectId,
61
+ };
62
+ assertOk(Todo.fromUnknown(todo), todo);
63
+ const independentTodo = { ...todo, projectId: null };
64
+ assertOk(Todo.fromUnknown(independentTodo), independentTodo);
65
+ assertOk(testEvoluSchema.todo.projectId.from(testProjectId), testProjectId);
66
+ void (() => {
67
+ // @ts-expect-error A todo ID is not a project ID.
68
+ testEvoluSchema.todo.projectId.from(testTodoId);
69
+ });
70
+
71
+ const createQuery = createQueryBuilder(testEvoluSchema);
72
+ const query = createQuery((db) =>
73
+ db
74
+ .selectFrom("todo")
75
+ .leftJoin("project", "project.id", "todo.projectId")
76
+ .select(["todo.title", "project.name as projectName"]),
77
+ );
78
+ assertType<
79
+ typeof query.Row,
80
+ {
81
+ title: NonEmptyTrimmedString100 | null;
82
+ projectName: NonEmptyTrimmedString100 | null;
83
+ }
84
+ >();
85
+ assertEqual(
86
+ sqliteQueryStringToSqliteQuery(query).sql,
87
+ 'select "todo"."title", "project"."name" as "projectName" from "todo" left join "project" on "project"."id" = "todo"."projectId"',
88
+ );
89
+
90
+ const createTodos = createEvolu(testEvoluSchema, {
91
+ appName: testAppName,
92
+ appOwner: testAppOwner,
93
+ transports: [],
94
+ });
95
+ assertType<
96
+ typeof createTodos,
97
+ Task<Evolu<TestEvoluSchema>, never, EvoluPlatformDeps>
98
+ >();
99
+ });
100
+
101
+ test("testLocalOnlyEvoluSchema supports keys with or without recovery material", () => {
102
+ assertType<
103
+ ValidateSchema<typeof testLocalOnlyEvoluSchema>,
104
+ typeof testLocalOnlyEvoluSchema
105
+ >();
106
+ const AppOwnerRow = object(testLocalOnlyEvoluSchema._appOwner);
107
+ const recoverableOwner = {
108
+ id: testAppOwner.id,
109
+ encryptionKey: testAppOwner.encryptionKey,
110
+ writeKey: testAppOwner.writeKey,
111
+ secret: testOwnerSecret,
112
+ name: "Personal",
113
+ };
114
+ assertOk(AppOwnerRow.fromUnknown(recoverableOwner), recoverableOwner);
115
+ const keyOnlyOwner = {
116
+ ...recoverableOwner,
117
+ secret: null,
118
+ name: null,
119
+ };
120
+ assertOk(AppOwnerRow.fromUnknown(keyOnlyOwner), keyOnlyOwner);
121
+ assertErr(
122
+ AppOwnerRow.fromUnknown({
123
+ ...keyOnlyOwner,
124
+ encryptionKey: new Uint8Array(1),
125
+ }),
126
+ );
127
+ assertErr(
128
+ AppOwnerRow.fromUnknown({
129
+ ...recoverableOwner,
130
+ secret: new Uint8Array(1),
131
+ }),
132
+ );
133
+
134
+ const createAccounts = createEvolu(testLocalOnlyEvoluSchema, {
135
+ appName: testAppName,
136
+ appOwner: testAppOwner,
137
+ transports: [],
138
+ });
139
+ assertType<
140
+ typeof createAccounts,
141
+ Task<Evolu<typeof testLocalOnlyEvoluSchema>, never, EvoluPlatformDeps>
142
+ >();
143
+ });