@verft/sdk 0.0.0-stage → 1.0.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/LICENSE +22 -0
- package/README.md +14 -2
- package/dist/activity.d.ts +12 -0
- package/dist/activity.js +59 -0
- package/dist/connection.d.ts +135 -0
- package/dist/connection.js +1032 -0
- package/dist/encoding.d.ts +112 -0
- package/dist/encoding.js +428 -0
- package/dist/files.d.ts +31 -0
- package/dist/files.js +56 -0
- package/dist/functions.d.ts +26 -0
- package/dist/functions.js +15 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +7 -0
- package/dist/landing.d.ts +25 -0
- package/dist/landing.js +19 -0
- package/dist/platform.d.ts +70 -0
- package/dist/platform.js +11 -0
- package/dist/protocol.d.ts +1198 -0
- package/dist/protocol.js +334 -0
- package/dist/react-native.d.ts +30 -0
- package/dist/react-native.js +34 -0
- package/dist/react.d.ts +20 -0
- package/dist/react.js +38 -0
- package/dist/readable.d.ts +14 -0
- package/dist/readable.js +31 -0
- package/dist/storage.d.ts +6 -0
- package/dist/storage.js +8 -0
- package/dist/subscriptions.d.ts +70 -0
- package/dist/subscriptions.js +168 -0
- package/dist/svelte.d.ts +23 -0
- package/dist/svelte.js +57 -0
- package/dist/tables.d.ts +17 -0
- package/dist/tables.js +18 -0
- package/dist/vue.d.ts +17 -0
- package/dist/vue.js +55 -0
- package/package.json +72 -4
package/dist/protocol.js
ADDED
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import { bool, bytes, connectionId, duration, f32, f64, fileHandle, i8, i16, i32, i64, identity, list, named as recursive, option, record, string, timestamp, u8, u16, u32, u64, variants, } from "./encoding.js";
|
|
2
|
+
export const PROTOCOL = 1;
|
|
3
|
+
const identityKind = variants({ Anonymous: null, SignedIn: null, ApiKey: null, Verft: null });
|
|
4
|
+
const caller = record({ identity, kind: identityKind });
|
|
5
|
+
const method = variants({ Get: null, Head: null, Post: null, Put: null, Patch: null, Delete: null, Options: null });
|
|
6
|
+
const kind = variants({
|
|
7
|
+
Action: null,
|
|
8
|
+
Query: null,
|
|
9
|
+
Job: record({ attempts: u32 }),
|
|
10
|
+
Route: record({ method, path: string }),
|
|
11
|
+
Predicate: record({ table: string }),
|
|
12
|
+
Migration: null,
|
|
13
|
+
});
|
|
14
|
+
const malformed = variants({
|
|
15
|
+
Truncated: null,
|
|
16
|
+
TrailingBytes: null,
|
|
17
|
+
InvalidBool: u8,
|
|
18
|
+
InvalidOption: u8,
|
|
19
|
+
InvalidUtf8: null,
|
|
20
|
+
UnknownVariant: u32,
|
|
21
|
+
TooDeep: null,
|
|
22
|
+
});
|
|
23
|
+
const tableColumn = record({ table: string, column: string });
|
|
24
|
+
const rejection = variants({
|
|
25
|
+
TooLong: record({ limit: u64 }),
|
|
26
|
+
Syntax: record({ at: u64, expected: string }),
|
|
27
|
+
Write: null,
|
|
28
|
+
Aggregate: string,
|
|
29
|
+
Unsupported: record({ at: u64, construct: string }),
|
|
30
|
+
TooManyTables: record({ limit: u64 }),
|
|
31
|
+
TooComplex: record({ comparisons: u64, nesting: u64 }),
|
|
32
|
+
UnknownTable: string,
|
|
33
|
+
PrivateTable: string,
|
|
34
|
+
DuplicateName: string,
|
|
35
|
+
UnknownName: string,
|
|
36
|
+
UnknownColumn: tableColumn,
|
|
37
|
+
UnqualifiedInJoin: string,
|
|
38
|
+
ColumnWithoutOrder: tableColumn,
|
|
39
|
+
TypeMismatch: tableColumn,
|
|
40
|
+
ComparedWithNull: tableColumn,
|
|
41
|
+
JoinOutOfOrder: tableColumn,
|
|
42
|
+
JoinNeedsIndex: record({ table: string, columns: list(string) }),
|
|
43
|
+
JoinAcrossKinds: record({ durable: string, ephemeral: string }),
|
|
44
|
+
Parameters: record({ reason: string }),
|
|
45
|
+
});
|
|
46
|
+
const callFailure = variants({
|
|
47
|
+
NotConnected: null,
|
|
48
|
+
NotFound: null,
|
|
49
|
+
ModuleError: bytes,
|
|
50
|
+
Panicked: null,
|
|
51
|
+
WriteInQuery: null,
|
|
52
|
+
WrongKind: record({ declared: kind }),
|
|
53
|
+
MalformedArguments: malformed,
|
|
54
|
+
ArgumentCount: record({ expected: u64, received: u64 }),
|
|
55
|
+
ArgumentType: record({ index: u64, reason: string }),
|
|
56
|
+
Unavailable: string,
|
|
57
|
+
Indeterminate: null,
|
|
58
|
+
TimeLimit: null,
|
|
59
|
+
MemoryLimit: null,
|
|
60
|
+
ContractViolation: string,
|
|
61
|
+
PredicateRowLimit: record({ table: string, limit: u64 }),
|
|
62
|
+
Rejected: rejection,
|
|
63
|
+
Overloaded: record({ retry_after: duration }),
|
|
64
|
+
LimitReached: record({
|
|
65
|
+
measure: variants({ Compute: null, Actions: null, DatabaseStorage: null, EphemeralStorage: null, DataSent: null, LogVolume: null, FileStorage: null, FileDownloads: null }),
|
|
66
|
+
until: option(timestamp),
|
|
67
|
+
}),
|
|
68
|
+
});
|
|
69
|
+
const subscribeRefusal = variants({
|
|
70
|
+
NotConnected: null,
|
|
71
|
+
Refused: callFailure,
|
|
72
|
+
Rejected: rejection,
|
|
73
|
+
IdInUse: null,
|
|
74
|
+
Ended: null,
|
|
75
|
+
});
|
|
76
|
+
const connectRefusal = variants({
|
|
77
|
+
NotAuthenticated: null,
|
|
78
|
+
Unavailable: string,
|
|
79
|
+
Refused: callFailure,
|
|
80
|
+
Subscription: record({ subscription: u64, reason: subscribeRefusal }),
|
|
81
|
+
});
|
|
82
|
+
const weakPassword = variants({
|
|
83
|
+
TooShort: record({ minimum: u64 }),
|
|
84
|
+
TooLong: record({ maximum: u64 }),
|
|
85
|
+
Common: null,
|
|
86
|
+
});
|
|
87
|
+
const identityFailure = variants({
|
|
88
|
+
InvalidEmail: null,
|
|
89
|
+
WeakPassword: weakPassword,
|
|
90
|
+
IncorrectEmailOrPassword: null,
|
|
91
|
+
NotAuthenticated: null,
|
|
92
|
+
AlreadySignedUp: null,
|
|
93
|
+
TooManyAttempts: record({ retry_after: duration }),
|
|
94
|
+
RefusedByModule: bytes,
|
|
95
|
+
Unavailable: string,
|
|
96
|
+
InvalidLink: null,
|
|
97
|
+
IncorrectCode: null,
|
|
98
|
+
Disabled: null,
|
|
99
|
+
NotInvited: null,
|
|
100
|
+
UnknownConnection: null,
|
|
101
|
+
RedirectNotAllowed: null,
|
|
102
|
+
InvalidResult: null,
|
|
103
|
+
UnverifiedEmail: null,
|
|
104
|
+
SecondFactorNeeded: record({ step: string }),
|
|
105
|
+
EnrolmentNeeded: record({ step: string }),
|
|
106
|
+
AlreadyEnrolled: null,
|
|
107
|
+
UnknownRelyingParty: null,
|
|
108
|
+
InvalidPasskey: null,
|
|
109
|
+
UnknownPasskey: null,
|
|
110
|
+
OnlyCredential: null,
|
|
111
|
+
InvalidName: null,
|
|
112
|
+
NotEnrolled: null,
|
|
113
|
+
SecondFactorRequired: null,
|
|
114
|
+
SecondFactorNotPassed: null,
|
|
115
|
+
InvalidDevice: string,
|
|
116
|
+
});
|
|
117
|
+
const callOutcome = variants({
|
|
118
|
+
Returned: record({ value: bytes, position: option(u64), ephemeral: option(u64) }),
|
|
119
|
+
Failed: callFailure,
|
|
120
|
+
});
|
|
121
|
+
const delivered = variants({
|
|
122
|
+
Reply: bytes,
|
|
123
|
+
Snapshot: list(bytes),
|
|
124
|
+
Rows: record({ removed: list(bytes), added: list(bytes) }),
|
|
125
|
+
Failed: callFailure,
|
|
126
|
+
});
|
|
127
|
+
const signInMethod = variants({ Password: null, Email: null, Provider: null, Passkey: null });
|
|
128
|
+
const named = record({ name: string });
|
|
129
|
+
const called = record({ function: string });
|
|
130
|
+
const invitation = record({ email: string, key: string });
|
|
131
|
+
const signedInBy = record({ method: signInMethod });
|
|
132
|
+
const failedJob = record({ job: bytes });
|
|
133
|
+
const value = recursive(() => variants({
|
|
134
|
+
Unit: null,
|
|
135
|
+
Bool: bool,
|
|
136
|
+
I8: i8,
|
|
137
|
+
I16: i16,
|
|
138
|
+
I32: i32,
|
|
139
|
+
I64: i64,
|
|
140
|
+
U8: u8,
|
|
141
|
+
U16: u16,
|
|
142
|
+
U32: u32,
|
|
143
|
+
U64: u64,
|
|
144
|
+
F32: f32,
|
|
145
|
+
F64: f64,
|
|
146
|
+
String: string,
|
|
147
|
+
Bytes: bytes,
|
|
148
|
+
Timestamp: i64,
|
|
149
|
+
Duration: i64,
|
|
150
|
+
Identity: identity,
|
|
151
|
+
ConnectionId: connectionId,
|
|
152
|
+
Option: option(value),
|
|
153
|
+
List: list(value),
|
|
154
|
+
Struct: list(value),
|
|
155
|
+
Enum: record({ variant: u32, fields: list(value) }),
|
|
156
|
+
File: fileHandle,
|
|
157
|
+
}));
|
|
158
|
+
export const auditEvent = variants({
|
|
159
|
+
Published: record({ version: u64 }),
|
|
160
|
+
SettingChanged: named,
|
|
161
|
+
Republished: record({ version: u64, of: u64 }),
|
|
162
|
+
PublishCancelled: null,
|
|
163
|
+
CalledAction: called,
|
|
164
|
+
CalledQuery: called,
|
|
165
|
+
SignInConnectionSet: named,
|
|
166
|
+
SignInConnectionRemoved: named,
|
|
167
|
+
RedirectTargetsSet: record({ targets: list(string) }),
|
|
168
|
+
SignUpModeSet: record({ invite_only: bool }),
|
|
169
|
+
MessageTemplateSet: record({ kind: string }),
|
|
170
|
+
IdentityDisabled: null,
|
|
171
|
+
IdentityEnabled: null,
|
|
172
|
+
IdentityDeleted: null,
|
|
173
|
+
InvitationSent: invitation,
|
|
174
|
+
InvitationRevoked: invitation,
|
|
175
|
+
ApiKeyIssued: named,
|
|
176
|
+
ApiKeyRevoked: null,
|
|
177
|
+
SecondFactorRequirementSet: record({ required: bool }),
|
|
178
|
+
SecondFactorReset: null,
|
|
179
|
+
RowChanged: record({ table: string, change: variants({ Inserted: null, Replaced: null, Deleted: null }), index: option(u32), key: bytes }),
|
|
180
|
+
RelyingPartiesSet: record({ domains: list(string) }),
|
|
181
|
+
PasskeyRemoved: null,
|
|
182
|
+
EmailSenderSet: record({ address: string }),
|
|
183
|
+
EmailSenderRemoved: null,
|
|
184
|
+
SignedUp: null,
|
|
185
|
+
SignedIn: signedInBy,
|
|
186
|
+
SignInFailed: signedInBy,
|
|
187
|
+
SignedOut: record({ everywhere: bool }),
|
|
188
|
+
PasswordReset: null,
|
|
189
|
+
InvitationAccepted: record({ key: string }),
|
|
190
|
+
SecondFactorEnrolled: null,
|
|
191
|
+
SecondStepPassed: null,
|
|
192
|
+
SecondStepFailed: null,
|
|
193
|
+
RecoveryCodeUsed: null,
|
|
194
|
+
PasskeyAdded: null,
|
|
195
|
+
FailedJobRerun: failedJob,
|
|
196
|
+
FailedJobDiscarded: failedJob,
|
|
197
|
+
FailedScheduleRerun: record({ function: string, schedule: bytes }),
|
|
198
|
+
FailedScheduleDiscarded: called,
|
|
199
|
+
EmailSenderTested: record({ to: string }),
|
|
200
|
+
SecondFactorReplaced: null,
|
|
201
|
+
SecondFactorRemoved: null,
|
|
202
|
+
RecoveryCodesReissued: null,
|
|
203
|
+
IdentityDeletionCompleted: null,
|
|
204
|
+
PersonalDataExported: null,
|
|
205
|
+
Removed: record({ table: string, column: option(string) }),
|
|
206
|
+
ViewOpened: record({ at: timestamp, before_publish: option(u64) }),
|
|
207
|
+
Restored: record({
|
|
208
|
+
restore: u64,
|
|
209
|
+
at: timestamp,
|
|
210
|
+
before_publish: option(u64),
|
|
211
|
+
before_restore: option(u64),
|
|
212
|
+
tables: list(record({ table: string, columns: option(list(string)), put_back: u64, overwritten: u64, removed: u64 })),
|
|
213
|
+
}),
|
|
214
|
+
WholeRestored: record({
|
|
215
|
+
restore: u64,
|
|
216
|
+
at: timestamp,
|
|
217
|
+
before_publish: option(u64),
|
|
218
|
+
before_restore: option(u64),
|
|
219
|
+
version: u64,
|
|
220
|
+
tables: list(record({ table: string, columns: option(list(string)), put_back: u64, overwritten: u64, removed: u64 })),
|
|
221
|
+
}),
|
|
222
|
+
SettingsSaved: record({
|
|
223
|
+
changes: list(record({ setting: string, key: option(value), path: string, before: option(value), after: option(value) })),
|
|
224
|
+
}),
|
|
225
|
+
Exported: record({ position: u64, rows: u64 }),
|
|
226
|
+
Imported: record({ from: string, position: u64, version: u64, rows: u64, identities: u64, files: u64, forced: bool }),
|
|
227
|
+
SessionsEnded: null,
|
|
228
|
+
AllowedOriginsSet: record({ origins: list(string) }),
|
|
229
|
+
PushCredentialSet: record({ service: string }),
|
|
230
|
+
PushCredentialRemoved: record({ service: string }),
|
|
231
|
+
DirectoryConsented: record({ connection: string, directory: string }),
|
|
232
|
+
DirectoryWithdrawn: record({ connection: string, directory: string }),
|
|
233
|
+
LandingPageSet: record({ url: option(string) }),
|
|
234
|
+
Unrecognised: record({ kind: string }),
|
|
235
|
+
});
|
|
236
|
+
const identityOutcome = variants({
|
|
237
|
+
SignedIn: record({ caller, token: string }),
|
|
238
|
+
Done: null,
|
|
239
|
+
Refused: identityFailure,
|
|
240
|
+
SignedUp: record({ pending: string }),
|
|
241
|
+
ProviderSignInStarted: record({ url: string, binding: string }),
|
|
242
|
+
EnrolmentStarted: record({ secret: string }),
|
|
243
|
+
Enrolled: record({ caller, token: string, recovery_codes: list(string) }),
|
|
244
|
+
PasskeyCeremonyStarted: record({ ceremony: string, options: string }),
|
|
245
|
+
PasskeysListed: record({ passkeys: list(record({ id: bytes, name: string, relying_party: string, created: timestamp })) }),
|
|
246
|
+
RecoveryCodesReissued: record({ recovery_codes: list(string) }),
|
|
247
|
+
AccountActivityRead: record({ entries: list(record({ at: timestamp, by_administrator: bool, address: option(string), event: auditEvent })), next: option(u64) }),
|
|
248
|
+
DeviceRegistered: record({ device: bytes }),
|
|
249
|
+
DirectoryConsented: record({ directory: string }),
|
|
250
|
+
SessionCodeIssued: record({ code: string }),
|
|
251
|
+
SessionCodeRedeemed: record({ caller, token: string, email: option(string) }),
|
|
252
|
+
});
|
|
253
|
+
const subscription = variants({
|
|
254
|
+
Query: record({ name: string, arguments: bytes }),
|
|
255
|
+
ClientQuery: record({ sql: string, parameters: bytes }),
|
|
256
|
+
});
|
|
257
|
+
const resume = record({
|
|
258
|
+
connection: connectionId,
|
|
259
|
+
position: option(u64),
|
|
260
|
+
ephemeral: option(u64),
|
|
261
|
+
subscriptions: list(record({ subscription: u64, to: subscription })),
|
|
262
|
+
});
|
|
263
|
+
const anonymous = option(string);
|
|
264
|
+
const enrolling = variants({
|
|
265
|
+
SignedIn: record({ token: string }),
|
|
266
|
+
Required: record({ step: string }),
|
|
267
|
+
});
|
|
268
|
+
const identityOperation = variants({
|
|
269
|
+
StartAnonymous: null,
|
|
270
|
+
SignUp: record({ email: string, password: string, anonymous }),
|
|
271
|
+
SignIn: record({ email: string, password: string }),
|
|
272
|
+
SignOut: record({ token: string }),
|
|
273
|
+
SignOutEverywhere: record({ token: string }),
|
|
274
|
+
VerifyEmail: record({ emailed: string, pending: option(string) }),
|
|
275
|
+
RequestSignInLink: record({ email: string, anonymous, redirect_to: option(string) }),
|
|
276
|
+
SignInWithLink: record({ emailed: string }),
|
|
277
|
+
RequestSignInCode: record({ email: string, anonymous }),
|
|
278
|
+
SignInWithCode: record({ email: string, code: string }),
|
|
279
|
+
RequestPasswordReset: record({ email: string }),
|
|
280
|
+
ResetPassword: record({ emailed: string, password: string }),
|
|
281
|
+
AcceptInvitation: record({ emailed: string, anonymous }),
|
|
282
|
+
StartProviderSignIn: record({ connection: string, redirect_to: string }),
|
|
283
|
+
FinishProviderSignIn: record({ result: string, binding: string, anonymous }),
|
|
284
|
+
PassSecondStep: record({ step: string, code: string }),
|
|
285
|
+
StartEnrolment: record({ by: enrolling }),
|
|
286
|
+
FinishEnrolment: record({ by: enrolling, code: string }),
|
|
287
|
+
StartPasskeyRegistration: record({ session: option(string), relying_party: string, account: string, name: string }),
|
|
288
|
+
FinishPasskeyRegistration: record({ ceremony: string, response: string }),
|
|
289
|
+
StartPasskeySignIn: record({ relying_party: string }),
|
|
290
|
+
FinishPasskeySignIn: record({ ceremony: string, response: string }),
|
|
291
|
+
Passkeys: record({ token: string }),
|
|
292
|
+
RenamePasskey: record({ token: string, id: bytes, name: string }),
|
|
293
|
+
RemovePasskey: record({ token: string, id: bytes }),
|
|
294
|
+
StartReplacement: record({ token: string }),
|
|
295
|
+
FinishReplacement: record({ token: string, code: string, new_code: string }),
|
|
296
|
+
RemoveSecondFactor: record({ token: string, code: string }),
|
|
297
|
+
ReissueRecoveryCodes: record({ token: string }),
|
|
298
|
+
AccountActivity: record({ token: string, after: option(u64), limit: u32 }),
|
|
299
|
+
RegisterDevice: record({ token: string, device: variants({
|
|
300
|
+
Apns: record({ token: string, sandbox: bool }),
|
|
301
|
+
Fcm: record({ token: string }),
|
|
302
|
+
WebPush: record({ endpoint: string, p256dh: bytes, auth: bytes }),
|
|
303
|
+
}) }),
|
|
304
|
+
UnregisterDevice: record({ token: string }),
|
|
305
|
+
StartDirectoryConsent: record({ connection: string, redirect_to: string }),
|
|
306
|
+
FinishDirectoryConsent: record({ result: string, binding: string }),
|
|
307
|
+
IssueSessionCode: record({ token: string, binding_hash: string }),
|
|
308
|
+
RedeemSessionCode: record({ code: string, binding: string }),
|
|
309
|
+
});
|
|
310
|
+
export const clientMessage = variants({
|
|
311
|
+
Hello: record({ protocol: u32 }),
|
|
312
|
+
Connect: record({ token: string, resume: option(resume) }),
|
|
313
|
+
Action: record({ call: u64, name: string, arguments: bytes }),
|
|
314
|
+
Query: record({ request: u64, name: string, arguments: bytes }),
|
|
315
|
+
Subscribe: record({ subscription: u64, to: subscription }),
|
|
316
|
+
Unsubscribe: record({ subscription: u64 }),
|
|
317
|
+
Close: null,
|
|
318
|
+
Identity: record({ request: u64, operation: identityOperation }),
|
|
319
|
+
});
|
|
320
|
+
export const serverMessage = variants({
|
|
321
|
+
Welcome: record({ protocol: u32, heartbeat: duration }),
|
|
322
|
+
UnsupportedProtocol: record({ supported: list(u32) }),
|
|
323
|
+
Connected: record({ connection: connectionId, caller }),
|
|
324
|
+
ConnectRefused: record({ reason: connectRefusal }),
|
|
325
|
+
Unauthenticated: null,
|
|
326
|
+
ActionReply: record({ call: u64, outcome: callOutcome }),
|
|
327
|
+
QueryReply: record({ request: u64, outcome: callOutcome }),
|
|
328
|
+
SubscribeRefused: record({ subscription: u64, reason: subscribeRefusal }),
|
|
329
|
+
Unsubscribed: record({ subscription: u64 }),
|
|
330
|
+
Update: record({ position: u64, ephemeral: u64, caused_by: list(u64), awaiting: list(record({ call: u64, subscriptions: list(u64) })), changes: list(record({ subscription: u64, delivered })) }),
|
|
331
|
+
Ended: record({ resume_from: u64, ephemeral: u64 }),
|
|
332
|
+
IdentityReply: record({ request: u64, outcome: identityOutcome }),
|
|
333
|
+
Heartbeat: null,
|
|
334
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { Connection } from "./connection.js";
|
|
3
|
+
export { useAccountActivity, useAction, useCaller, useConnection, useLanding, useStatus, useSubscription } from "./react.js";
|
|
4
|
+
export interface AppState {
|
|
5
|
+
addEventListener(type: "change", listener: (state: string) => void): {
|
|
6
|
+
remove(): void;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export interface Linking {
|
|
10
|
+
getInitialURL(): Promise<string | null>;
|
|
11
|
+
addEventListener(type: "url", listener: (event: {
|
|
12
|
+
readonly url: string;
|
|
13
|
+
}) => void): {
|
|
14
|
+
remove(): void;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export interface Network {
|
|
18
|
+
addEventListener(listener: (state: {
|
|
19
|
+
readonly type: string;
|
|
20
|
+
readonly isConnected: boolean | null;
|
|
21
|
+
}) => void): () => void;
|
|
22
|
+
}
|
|
23
|
+
export interface Device {
|
|
24
|
+
readonly connection: Connection;
|
|
25
|
+
readonly appState: AppState;
|
|
26
|
+
readonly linking: Linking;
|
|
27
|
+
readonly network?: Network;
|
|
28
|
+
readonly children?: ReactNode;
|
|
29
|
+
}
|
|
30
|
+
export declare function VerftProvider({ connection, appState, linking, network, children }: Device): ReactNode;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createElement, useEffect } from "react";
|
|
2
|
+
import { VerftProvider as Provider } from "./react.js";
|
|
3
|
+
export { useAccountActivity, useAction, useCaller, useConnection, useLanding, useStatus, useSubscription } from "./react.js";
|
|
4
|
+
const launched = new WeakSet();
|
|
5
|
+
export function VerftProvider({ connection, appState, linking, network, children }) {
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
const foreground = appState.addEventListener("change", (state) => {
|
|
8
|
+
if (state === "active")
|
|
9
|
+
connection.wake();
|
|
10
|
+
});
|
|
11
|
+
return () => foreground.remove();
|
|
12
|
+
}, [connection, appState]);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
let reachedOver;
|
|
15
|
+
let reachable = false;
|
|
16
|
+
return network?.addEventListener(({ type, isConnected }) => {
|
|
17
|
+
if (isConnected && reachedOver !== undefined && reachedOver !== type)
|
|
18
|
+
connection.reconnect();
|
|
19
|
+
else if (isConnected && !reachable)
|
|
20
|
+
connection.wake();
|
|
21
|
+
if (isConnected)
|
|
22
|
+
reachedOver = type;
|
|
23
|
+
reachable = isConnected === true;
|
|
24
|
+
});
|
|
25
|
+
}, [connection, network]);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (!launched.has(connection))
|
|
28
|
+
void linking.getInitialURL().then((url) => url !== null && connection.redeem(url), () => { });
|
|
29
|
+
launched.add(connection);
|
|
30
|
+
const opened = linking.addEventListener("url", ({ url }) => void connection.redeem(url));
|
|
31
|
+
return () => opened.remove();
|
|
32
|
+
}, [connection, linking]);
|
|
33
|
+
return createElement(Provider, { connection }, children);
|
|
34
|
+
}
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type AccountActivityLog } from "./activity.js";
|
|
3
|
+
import type { CallOptions, Connection, Status } from "./connection.js";
|
|
4
|
+
import type { Action, Query, Reply } from "./functions.js";
|
|
5
|
+
import type { Landing } from "./landing.js";
|
|
6
|
+
import type { Caller } from "./protocol.js";
|
|
7
|
+
import type { Local, Result } from "./subscriptions.js";
|
|
8
|
+
import type { ClientQuery } from "./tables.js";
|
|
9
|
+
export declare function VerftProvider({ connection, children }: {
|
|
10
|
+
readonly connection: Connection;
|
|
11
|
+
readonly children?: ReactNode;
|
|
12
|
+
}): ReactNode;
|
|
13
|
+
export declare function useConnection(): Connection;
|
|
14
|
+
export declare function useSubscription<A, R, E>(query: Query<A, R, E>, args: NoInfer<A>): Result<Reply<R, E>>;
|
|
15
|
+
export declare function useSubscription<R>(query: ClientQuery<R>): Result<R[]>;
|
|
16
|
+
export declare function useStatus(): Status;
|
|
17
|
+
export declare function useCaller(): Caller | null;
|
|
18
|
+
export declare function useLanding(): Landing;
|
|
19
|
+
export declare function useAction<A, R, E>(action: Action<A, R, E>): (args: NoInfer<A>, optimistic?: (local: Local) => void, options?: CallOptions) => Promise<Reply<R, E>>;
|
|
20
|
+
export declare function useAccountActivity(limit?: number): AccountActivityLog;
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { createContext, createElement, useCallback, useContext, useMemo, useSyncExternalStore } from "react";
|
|
2
|
+
import { accountActivityLog } from "./activity.js";
|
|
3
|
+
const Current = createContext(null);
|
|
4
|
+
export function VerftProvider({ connection, children }) {
|
|
5
|
+
return createElement(Current.Provider, { value: connection }, children);
|
|
6
|
+
}
|
|
7
|
+
export function useConnection() {
|
|
8
|
+
const connection = useContext(Current);
|
|
9
|
+
if (connection === null)
|
|
10
|
+
throw new Error("a Verft hook was used outside a VerftProvider");
|
|
11
|
+
return connection;
|
|
12
|
+
}
|
|
13
|
+
function useReadable(readable) {
|
|
14
|
+
return useSyncExternalStore(readable.onChange, readable.get, readable.get);
|
|
15
|
+
}
|
|
16
|
+
export function useSubscription(target, args) {
|
|
17
|
+
const connection = useConnection();
|
|
18
|
+
const latest = connection.shared(target, args);
|
|
19
|
+
const shared = useMemo(() => latest, [connection, latest.key]);
|
|
20
|
+
return useReadable(shared);
|
|
21
|
+
}
|
|
22
|
+
export function useStatus() {
|
|
23
|
+
return useReadable(useConnection().status);
|
|
24
|
+
}
|
|
25
|
+
export function useCaller() {
|
|
26
|
+
return useReadable(useConnection().caller);
|
|
27
|
+
}
|
|
28
|
+
export function useLanding() {
|
|
29
|
+
return useReadable(useConnection().landing);
|
|
30
|
+
}
|
|
31
|
+
export function useAction(action) {
|
|
32
|
+
const connection = useConnection();
|
|
33
|
+
return useCallback((args, optimistic, options) => connection.action(action, args, optimistic, options), [connection, action]);
|
|
34
|
+
}
|
|
35
|
+
export function useAccountActivity(limit) {
|
|
36
|
+
const connection = useConnection();
|
|
37
|
+
return useReadable(useMemo(() => accountActivityLog(connection, limit), [connection, limit]));
|
|
38
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface Readable<T> {
|
|
2
|
+
get(): T;
|
|
3
|
+
onChange(listener: () => void): () => void;
|
|
4
|
+
}
|
|
5
|
+
export declare class Watched<T> implements Readable<T> {
|
|
6
|
+
private value;
|
|
7
|
+
private readonly listeners;
|
|
8
|
+
constructor(value: T);
|
|
9
|
+
readonly get: () => T;
|
|
10
|
+
readonly onChange: (listener: () => void) => (() => void);
|
|
11
|
+
set(value: T): void;
|
|
12
|
+
notify(): void;
|
|
13
|
+
}
|
|
14
|
+
export declare function thrownLater(error: unknown): void;
|
package/dist/readable.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { platform } from "./platform.js";
|
|
2
|
+
export class Watched {
|
|
3
|
+
constructor(value) {
|
|
4
|
+
this.listeners = new Set();
|
|
5
|
+
this.get = () => this.value;
|
|
6
|
+
this.onChange = (listener) => {
|
|
7
|
+
const once = () => listener();
|
|
8
|
+
this.listeners.add(once);
|
|
9
|
+
return () => void this.listeners.delete(once);
|
|
10
|
+
};
|
|
11
|
+
this.value = value;
|
|
12
|
+
}
|
|
13
|
+
set(value) {
|
|
14
|
+
this.value = value;
|
|
15
|
+
}
|
|
16
|
+
notify() {
|
|
17
|
+
for (const listener of [...this.listeners]) {
|
|
18
|
+
try {
|
|
19
|
+
listener();
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
thrownLater(error);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function thrownLater(error) {
|
|
28
|
+
platform.setTimeout(() => {
|
|
29
|
+
throw error;
|
|
30
|
+
}, 0);
|
|
31
|
+
}
|
package/dist/storage.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { type Bytes, type Codec } from "./encoding.js";
|
|
2
|
+
import { type Action, type Query, type Reply } from "./functions.js";
|
|
3
|
+
import type { CallFailure, Delivered, SubscribeRefusal, WireSubscription } from "./protocol.js";
|
|
4
|
+
import { type Readable, Watched } from "./readable.js";
|
|
5
|
+
import type { ClientQuery } from "./tables.js";
|
|
6
|
+
export type Result<T> = {
|
|
7
|
+
readonly state: "pending";
|
|
8
|
+
} | {
|
|
9
|
+
readonly state: "ready";
|
|
10
|
+
readonly value: T;
|
|
11
|
+
} | {
|
|
12
|
+
readonly state: "failed";
|
|
13
|
+
readonly failure: CallFailure;
|
|
14
|
+
} | {
|
|
15
|
+
readonly state: "refused";
|
|
16
|
+
readonly reason: SubscribeRefusal;
|
|
17
|
+
} | {
|
|
18
|
+
readonly state: "undecodable";
|
|
19
|
+
readonly error: unknown;
|
|
20
|
+
};
|
|
21
|
+
export interface Subscription<T> extends Readable<Result<T>> {
|
|
22
|
+
unsubscribe(): void;
|
|
23
|
+
}
|
|
24
|
+
export interface Shared<T> extends Readable<Result<T>> {
|
|
25
|
+
readonly key: string;
|
|
26
|
+
}
|
|
27
|
+
export type Copy<T> = (delivered: Delivered) => Result<T>;
|
|
28
|
+
export interface Local {
|
|
29
|
+
update<A, R, E>(query: Query<A, R, E>, args: NoInfer<A>, edit: (value: Reply<R, E>) => Reply<R, E>): void;
|
|
30
|
+
update<R>(query: ClientQuery<R>, edit: (rows: readonly R[]) => R[]): void;
|
|
31
|
+
}
|
|
32
|
+
export interface Revision {
|
|
33
|
+
readonly key: string;
|
|
34
|
+
readonly edit: (value: unknown) => unknown;
|
|
35
|
+
}
|
|
36
|
+
export type Edits = ReadonlyMap<bigint, readonly Revision[]>;
|
|
37
|
+
export type Target = Query<unknown, unknown, unknown> | ClientQuery<unknown>;
|
|
38
|
+
export declare function wire(target: Target, args: unknown): WireSubscription;
|
|
39
|
+
export declare function keyOfSubscription(to: WireSubscription): string;
|
|
40
|
+
export declare function revisions(optimistic: (local: Local) => void): Revision[];
|
|
41
|
+
export declare const pending: {
|
|
42
|
+
readonly state: "pending";
|
|
43
|
+
};
|
|
44
|
+
export declare class Standing<T> extends Watched<Result<T>> implements Subscription<T> {
|
|
45
|
+
readonly to: WireSubscription;
|
|
46
|
+
readonly key: string;
|
|
47
|
+
readonly unsubscribe: () => void;
|
|
48
|
+
private readonly copy;
|
|
49
|
+
private readonly edits;
|
|
50
|
+
private apply;
|
|
51
|
+
private confirmed;
|
|
52
|
+
private waiting;
|
|
53
|
+
due: number;
|
|
54
|
+
sent: boolean;
|
|
55
|
+
delivered: boolean;
|
|
56
|
+
constructor(to: WireSubscription, copy: () => Copy<T>, unsubscribe: () => void, edits: Edits);
|
|
57
|
+
deliver(delivered: Delivered): void;
|
|
58
|
+
endsWith(delivered: Delivered): boolean;
|
|
59
|
+
awaitFirst(due: number, deadline: (due: number) => () => void): void;
|
|
60
|
+
unanswered(): void;
|
|
61
|
+
stopWaiting(): void;
|
|
62
|
+
refuse(reason: SubscribeRefusal): void;
|
|
63
|
+
reset(): void;
|
|
64
|
+
rebase(): void;
|
|
65
|
+
private confirm;
|
|
66
|
+
}
|
|
67
|
+
export declare function returned<A, R, E>(fn: Action<A, R, E> | Query<A, R, E>, value: Bytes): Reply<R, E>;
|
|
68
|
+
export declare function moduleError<A, R, E>(fn: Action<A, R, E> | Query<A, R, E>, failure: CallFailure): Reply<R, E> | undefined;
|
|
69
|
+
export declare function replies<A, R, E>(query: Query<A, R, E>): () => Copy<Reply<R, E>>;
|
|
70
|
+
export declare function rows<R>(row: Codec<R>): () => Copy<R[]>;
|