@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.
- package/dist/src/Bytes.d.ts +39 -2
- package/dist/src/Bytes.d.ts.map +1 -1
- package/dist/src/Bytes.js +50 -2
- package/dist/src/Config.d.ts +22 -22
- package/dist/src/Config.d.ts.map +1 -1
- package/dist/src/Console.d.ts +62 -7
- package/dist/src/Console.d.ts.map +1 -1
- package/dist/src/Console.js +20 -4
- package/dist/src/Crypto.d.ts +76 -4
- package/dist/src/Crypto.d.ts.map +1 -1
- package/dist/src/Crypto.js +55 -4
- package/dist/src/Error.d.ts +45 -0
- package/dist/src/Error.d.ts.map +1 -1
- package/dist/src/Error.js +69 -0
- package/dist/src/Fs.d.ts +92 -18
- package/dist/src/Fs.d.ts.map +1 -1
- package/dist/src/Fs.js +2 -0
- package/dist/src/Identicon.d.ts +2 -2
- package/dist/src/Identicon.js +2 -2
- package/dist/src/LeakDetector.d.ts +22 -3
- package/dist/src/LeakDetector.d.ts.map +1 -1
- package/dist/src/LeakDetector.js +12 -2
- package/dist/src/LockManager.d.ts +8 -0
- package/dist/src/LockManager.d.ts.map +1 -1
- package/dist/src/LockManager.js +6 -0
- package/dist/src/Object.d.ts.map +1 -1
- package/dist/src/Object.js +5 -0
- package/dist/src/Platform.d.ts +47 -7
- package/dist/src/Platform.d.ts.map +1 -1
- package/dist/src/Platform.js +24 -5
- package/dist/src/Random.d.ts +25 -2
- package/dist/src/Random.d.ts.map +1 -1
- package/dist/src/Random.js +14 -2
- package/dist/src/Resource.d.ts +156 -1
- package/dist/src/Resource.d.ts.map +1 -1
- package/dist/src/Resource.js +201 -72
- package/dist/src/Schedule.d.ts +11 -10
- package/dist/src/Schedule.d.ts.map +1 -1
- package/dist/src/Schedule.js +1 -1
- package/dist/src/Sqlite.d.ts +132 -16
- package/dist/src/Sqlite.d.ts.map +1 -1
- package/dist/src/Sqlite.js +63 -9
- package/dist/src/Task.d.ts +15 -4
- package/dist/src/Task.d.ts.map +1 -1
- package/dist/src/Task.js +41 -15
- package/dist/src/Test.d.ts +9 -0
- package/dist/src/Test.d.ts.map +1 -1
- package/dist/src/Test.js +4 -0
- package/dist/src/Time.d.ts +106 -9
- package/dist/src/Time.d.ts.map +1 -1
- package/dist/src/Time.js +55 -4
- package/dist/src/Type.d.ts +1455 -1310
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +1274 -517
- package/dist/src/WebSocket.d.ts +164 -13
- package/dist/src/WebSocket.d.ts.map +1 -1
- package/dist/src/WebSocket.js +133 -24
- package/dist/src/Worker.d.ts +90 -8
- package/dist/src/Worker.d.ts.map +1 -1
- package/dist/src/Worker.js +28 -2
- package/dist/src/index.d.ts +6 -7
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -3
- package/dist/src/local-first/Db.d.ts +52 -3
- package/dist/src/local-first/Db.d.ts.map +1 -1
- package/dist/src/local-first/Db.js +412 -137
- package/dist/src/local-first/Evolu.d.ts +412 -213
- package/dist/src/local-first/Evolu.d.ts.map +1 -1
- package/dist/src/local-first/Evolu.js +181 -18
- package/dist/src/local-first/Owner.d.ts +13 -30
- package/dist/src/local-first/Owner.d.ts.map +1 -1
- package/dist/src/local-first/Owner.js +13 -30
- package/dist/src/local-first/Protocol.d.ts +106 -19
- package/dist/src/local-first/Protocol.d.ts.map +1 -1
- package/dist/src/local-first/Protocol.js +162 -60
- package/dist/src/local-first/Query.d.ts +8 -15
- package/dist/src/local-first/Query.d.ts.map +1 -1
- package/dist/src/local-first/Relay.d.ts.map +1 -1
- package/dist/src/local-first/Relay.js +4 -2
- package/dist/src/local-first/Schema.d.ts +346 -23
- package/dist/src/local-first/Schema.d.ts.map +1 -1
- package/dist/src/local-first/Schema.js +214 -17
- package/dist/src/local-first/Shared.d.ts +537 -22
- package/dist/src/local-first/Shared.d.ts.map +1 -1
- package/dist/src/local-first/Shared.js +1437 -234
- package/dist/src/local-first/Storage.d.ts +195 -17
- package/dist/src/local-first/Storage.d.ts.map +1 -1
- package/dist/src/local-first/Storage.js +85 -22
- package/dist/src/local-first/Timestamp.d.ts +392 -41
- package/dist/src/local-first/Timestamp.d.ts.map +1 -1
- package/dist/src/local-first/Timestamp.js +403 -81
- package/dist/src/local-first/index.d.ts +0 -1
- package/dist/src/local-first/index.d.ts.map +1 -1
- package/dist/src/local-first/index.js +0 -1
- package/package.json +1 -1
- package/src/Assert.test.ts +2 -5
- package/src/Bytes.test.ts +27 -0
- package/src/Bytes.ts +58 -2
- package/src/Config.test.ts +2 -6
- package/src/Config.ts +133 -133
- package/src/Console.ts +62 -7
- package/src/Crypto.ts +76 -4
- package/src/Eq.test.ts +2 -3
- package/src/Error.test.ts +76 -3
- package/src/Error.ts +71 -0
- package/src/Fs.ts +92 -18
- package/src/Identicon.ts +2 -2
- package/src/LeakDetector.ts +22 -3
- package/src/LockManager.ts +8 -0
- package/src/Object.test.ts +27 -12
- package/src/Object.ts +5 -0
- package/src/Platform.ts +50 -8
- package/src/Random.ts +25 -2
- package/src/Resource.test.ts +837 -0
- package/src/Resource.ts +235 -15
- package/src/Schedule.test.ts +50 -12
- package/src/Schedule.ts +24 -14
- package/src/Sqlite.ts +137 -17
- package/src/Task.test.ts +189 -8
- package/src/Task.ts +56 -17
- package/src/Test.ts +9 -0
- package/src/Time.ts +106 -9
- package/src/Type.test.ts +946 -1028
- package/src/Type.ts +4195 -3136
- package/src/Types.test.ts +4 -14
- package/src/WebSocket.ts +313 -40
- package/src/Worker.ts +90 -8
- package/src/index.ts +20 -6
- package/src/local-first/Db.ts +644 -339
- package/src/local-first/Evolu.test.ts +994 -22
- package/src/local-first/Evolu.ts +625 -232
- package/src/local-first/Owner.ts +13 -30
- package/src/local-first/Protocol.test.ts +634 -10
- package/src/local-first/Protocol.ts +255 -109
- package/src/local-first/Query.ts +8 -15
- package/src/local-first/Relay.ts +4 -2
- package/src/local-first/Schema.test.ts +143 -0
- package/src/local-first/Schema.ts +376 -26
- package/src/local-first/Shared.test.ts +7731 -559
- package/src/local-first/Shared.ts +2036 -267
- package/src/local-first/Storage.ts +224 -36
- package/src/local-first/Timestamp.test.ts +344 -70
- package/src/local-first/Timestamp.ts +434 -118
- package/src/local-first/index.ts +0 -1
- package/dist/src/local-first/Error.d.ts +0 -12
- package/dist/src/local-first/Error.d.ts.map +0 -1
- package/dist/src/local-first/Error.js +0 -6
- package/dist/src/local-first/LocalAuth.d.ts +0 -150
- package/dist/src/local-first/LocalAuth.d.ts.map +0 -1
- package/dist/src/local-first/LocalAuth.js +0 -179
- package/src/local-first/Error.ts +0 -17
- 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
|
+
});
|