@verft/sdk 1.0.0 → 1.1.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/drafts.d.ts +13 -0
- package/dist/drafts.js +21 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/react-native.d.ts +1 -1
- package/dist/react-native.js +1 -1
- package/dist/react.d.ts +3 -0
- package/dist/react.js +5 -0
- package/dist/svelte.d.ts +3 -0
- package/dist/svelte.js +16 -0
- package/dist/vue.d.ts +3 -0
- package/dist/vue.js +5 -0
- package/package.json +1 -1
package/dist/drafts.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Bytes } from "./encoding.js";
|
|
2
|
+
import type { Result } from "./subscriptions.js";
|
|
3
|
+
export interface Drafted {
|
|
4
|
+
readonly job: Bytes;
|
|
5
|
+
readonly run: number;
|
|
6
|
+
readonly piece: number;
|
|
7
|
+
}
|
|
8
|
+
export interface DraftedRow {
|
|
9
|
+
readonly at: Drafted;
|
|
10
|
+
}
|
|
11
|
+
export declare function jobOf(row: DraftedRow): string;
|
|
12
|
+
export declare function drafts<R extends DraftedRow>(rows: readonly R[]): ReadonlyMap<string, R[]>;
|
|
13
|
+
export declare function drafted<R extends DraftedRow>(result: Result<readonly R[]>): Result<ReadonlyMap<string, R[]>>;
|
package/dist/drafts.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export function jobOf(row) {
|
|
2
|
+
return Array.from(row.at.job, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
3
|
+
}
|
|
4
|
+
export function drafts(rows) {
|
|
5
|
+
const newest = new Map();
|
|
6
|
+
for (const row of rows) {
|
|
7
|
+
const job = jobOf(row);
|
|
8
|
+
const kept = newest.get(job);
|
|
9
|
+
const run = kept?.[0]?.at.run ?? -1;
|
|
10
|
+
if (row.at.run > run)
|
|
11
|
+
newest.set(job, [row]);
|
|
12
|
+
else if (row.at.run === run)
|
|
13
|
+
kept.push(row);
|
|
14
|
+
}
|
|
15
|
+
for (const pieces of newest.values())
|
|
16
|
+
pieces.sort((left, right) => left.at.piece - right.at.piece);
|
|
17
|
+
return newest;
|
|
18
|
+
}
|
|
19
|
+
export function drafted(result) {
|
|
20
|
+
return result.state === "ready" ? { state: "ready", value: drafts(result.value) } : result;
|
|
21
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export * from "./tables.js";
|
|
|
4
4
|
export * from "./connection.js";
|
|
5
5
|
export * from "./activity.js";
|
|
6
6
|
export * from "./files.js";
|
|
7
|
+
export { drafts, jobOf } from "./drafts.js";
|
|
8
|
+
export type { Drafted, DraftedRow } from "./drafts.js";
|
|
7
9
|
export { PROTOCOL, auditEvent } from "./protocol.js";
|
|
8
10
|
export type { Activity, ActivityPage, AuditEvent, Caller, CallFailure, ConnectRefusal, IdentityFailure, IdentityKind, Kind, ListedPasskey, Malformed, Measure, Method, Rejection, RowChange, SavedSetting, SignInMethod, SubscribeRefusal, Value, WeakPassword } from "./protocol.js";
|
|
9
11
|
export type { Authenticator } from "./platform.js";
|
package/dist/index.js
CHANGED
package/dist/react-native.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
2
|
import type { Connection } from "./connection.js";
|
|
3
|
-
export { useAccountActivity, useAction, useCaller, useConnection, useLanding, useStatus, useSubscription } from "./react.js";
|
|
3
|
+
export { useAccountActivity, useAction, useCaller, useConnection, useDraft, useLanding, useStatus, useSubscription } from "./react.js";
|
|
4
4
|
export interface AppState {
|
|
5
5
|
addEventListener(type: "change", listener: (state: string) => void): {
|
|
6
6
|
remove(): void;
|
package/dist/react-native.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createElement, useEffect } from "react";
|
|
2
2
|
import { VerftProvider as Provider } from "./react.js";
|
|
3
|
-
export { useAccountActivity, useAction, useCaller, useConnection, useLanding, useStatus, useSubscription } from "./react.js";
|
|
3
|
+
export { useAccountActivity, useAction, useCaller, useConnection, useDraft, useLanding, useStatus, useSubscription } from "./react.js";
|
|
4
4
|
const launched = new WeakSet();
|
|
5
5
|
export function VerftProvider({ connection, appState, linking, network, children }) {
|
|
6
6
|
useEffect(() => {
|
package/dist/react.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { Landing } from "./landing.js";
|
|
|
6
6
|
import type { Caller } from "./protocol.js";
|
|
7
7
|
import type { Local, Result } from "./subscriptions.js";
|
|
8
8
|
import type { ClientQuery } from "./tables.js";
|
|
9
|
+
import { type DraftedRow } from "./drafts.js";
|
|
9
10
|
export declare function VerftProvider({ connection, children }: {
|
|
10
11
|
readonly connection: Connection;
|
|
11
12
|
readonly children?: ReactNode;
|
|
@@ -13,6 +14,8 @@ export declare function VerftProvider({ connection, children }: {
|
|
|
13
14
|
export declare function useConnection(): Connection;
|
|
14
15
|
export declare function useSubscription<A, R, E>(query: Query<A, R, E>, args: NoInfer<A>): Result<Reply<R, E>>;
|
|
15
16
|
export declare function useSubscription<R>(query: ClientQuery<R>): Result<R[]>;
|
|
17
|
+
export declare function useDraft<A, R extends DraftedRow>(query: Query<A, R[], never>, args: NoInfer<A>): Result<ReadonlyMap<string, R[]>>;
|
|
18
|
+
export declare function useDraft<R extends DraftedRow>(query: ClientQuery<R>): Result<ReadonlyMap<string, R[]>>;
|
|
16
19
|
export declare function useStatus(): Status;
|
|
17
20
|
export declare function useCaller(): Caller | null;
|
|
18
21
|
export declare function useLanding(): Landing;
|
package/dist/react.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createContext, createElement, useCallback, useContext, useMemo, useSyncExternalStore } from "react";
|
|
2
2
|
import { accountActivityLog } from "./activity.js";
|
|
3
|
+
import { drafted } from "./drafts.js";
|
|
3
4
|
const Current = createContext(null);
|
|
4
5
|
export function VerftProvider({ connection, children }) {
|
|
5
6
|
return createElement(Current.Provider, { value: connection }, children);
|
|
@@ -19,6 +20,10 @@ export function useSubscription(target, args) {
|
|
|
19
20
|
const shared = useMemo(() => latest, [connection, latest.key]);
|
|
20
21
|
return useReadable(shared);
|
|
21
22
|
}
|
|
23
|
+
export function useDraft(target, args) {
|
|
24
|
+
const rows = useSubscription(target, args);
|
|
25
|
+
return useMemo(() => drafted(rows), [rows]);
|
|
26
|
+
}
|
|
22
27
|
export function useStatus() {
|
|
23
28
|
return useReadable(useConnection().status);
|
|
24
29
|
}
|
package/dist/svelte.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { Landing } from "./landing.js";
|
|
|
5
5
|
import type { Caller } from "./protocol.js";
|
|
6
6
|
import type { Local, Result } from "./subscriptions.js";
|
|
7
7
|
import type { ClientQuery } from "./tables.js";
|
|
8
|
+
import { type DraftedRow } from "./drafts.js";
|
|
8
9
|
export interface Current<T> {
|
|
9
10
|
readonly current: T;
|
|
10
11
|
}
|
|
@@ -15,6 +16,8 @@ type NotAFunction = {
|
|
|
15
16
|
};
|
|
16
17
|
export declare function useSubscription<A, R, E>(query: Query<A, R, E>, args: (NoInfer<A> & NotAFunction) | (() => NoInfer<A>)): Current<Result<Reply<R, E>>>;
|
|
17
18
|
export declare function useSubscription<R>(query: ClientQuery<R>): Current<Result<R[]>>;
|
|
19
|
+
export declare function useDraft<A, R extends DraftedRow>(query: Query<A, R[], never>, args: (NoInfer<A> & NotAFunction) | (() => NoInfer<A>)): Current<Result<ReadonlyMap<string, R[]>>>;
|
|
20
|
+
export declare function useDraft<R extends DraftedRow>(query: ClientQuery<R>): Current<Result<ReadonlyMap<string, R[]>>>;
|
|
18
21
|
export declare function useStatus(): Current<Status>;
|
|
19
22
|
export declare function useCaller(): Current<Caller | null>;
|
|
20
23
|
export declare function useLanding(): Current<Landing>;
|
package/dist/svelte.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createContext } from "svelte";
|
|
2
2
|
import { createSubscriber } from "svelte/reactivity";
|
|
3
3
|
import { accountActivityLog } from "./activity.js";
|
|
4
|
+
import { drafted } from "./drafts.js";
|
|
4
5
|
const [current, provide, provided] = createContext();
|
|
5
6
|
export function setConnection(connection) {
|
|
6
7
|
provide(connection);
|
|
@@ -35,6 +36,21 @@ export function useSubscription(target, args) {
|
|
|
35
36
|
return shared;
|
|
36
37
|
});
|
|
37
38
|
}
|
|
39
|
+
export function useDraft(target, args) {
|
|
40
|
+
const rows = useSubscription(target, args);
|
|
41
|
+
let seen;
|
|
42
|
+
let shown = { state: "pending" };
|
|
43
|
+
return {
|
|
44
|
+
get current() {
|
|
45
|
+
const latest = rows.current;
|
|
46
|
+
if (latest !== seen) {
|
|
47
|
+
seen = latest;
|
|
48
|
+
shown = drafted(latest);
|
|
49
|
+
}
|
|
50
|
+
return shown;
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
38
54
|
export function useStatus() {
|
|
39
55
|
const connection = useConnection();
|
|
40
56
|
return following(() => connection.status);
|
package/dist/vue.d.ts
CHANGED
|
@@ -6,10 +6,13 @@ import type { Landing } from "./landing.js";
|
|
|
6
6
|
import type { Caller } from "./protocol.js";
|
|
7
7
|
import type { Local, Result } from "./subscriptions.js";
|
|
8
8
|
import type { ClientQuery } from "./tables.js";
|
|
9
|
+
import { type DraftedRow } from "./drafts.js";
|
|
9
10
|
export declare const verft: Plugin<[Connection]>;
|
|
10
11
|
export declare function useConnection(): Connection;
|
|
11
12
|
export declare function useSubscription<A, R, E>(query: Query<A, R, E>, args: MaybeRefOrGetter<NoInfer<A>>): Readonly<Ref<Result<Reply<R, E>>>>;
|
|
12
13
|
export declare function useSubscription<R>(query: ClientQuery<R>): Readonly<Ref<Result<R[]>>>;
|
|
14
|
+
export declare function useDraft<A, R extends DraftedRow>(query: Query<A, R[], never>, args: MaybeRefOrGetter<NoInfer<A>>): Readonly<Ref<Result<ReadonlyMap<string, R[]>>>>;
|
|
15
|
+
export declare function useDraft<R extends DraftedRow>(query: ClientQuery<R>): Readonly<Ref<Result<ReadonlyMap<string, R[]>>>>;
|
|
13
16
|
export declare function useStatus(): Readonly<Ref<Status>>;
|
|
14
17
|
export declare function useCaller(): Readonly<Ref<Caller | null>>;
|
|
15
18
|
export declare function useLanding(): Readonly<Ref<Landing>>;
|
package/dist/vue.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { computed, inject, onMounted, shallowRef, toValue, watch } from "vue";
|
|
2
2
|
import { accountActivityLog } from "./activity.js";
|
|
3
|
+
import { drafted } from "./drafts.js";
|
|
3
4
|
const current = Symbol("verft");
|
|
4
5
|
export const verft = {
|
|
5
6
|
install(app, connection) {
|
|
@@ -33,6 +34,10 @@ export function useSubscription(target, args) {
|
|
|
33
34
|
});
|
|
34
35
|
return useReadable(() => shared.value);
|
|
35
36
|
}
|
|
37
|
+
export function useDraft(target, args) {
|
|
38
|
+
const rows = useSubscription(target, args);
|
|
39
|
+
return computed(() => drafted(rows.value));
|
|
40
|
+
}
|
|
36
41
|
export function useStatus() {
|
|
37
42
|
const connection = useConnection();
|
|
38
43
|
return useReadable(() => connection.status);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verft/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "The client of Verft Apps: typed Actions, Queries and live Subscriptions, with React, React Native, Vue and Svelte bindings",
|
|
5
5
|
"homepage": "https://docs.verft.cloud",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|