@notis_ai/cli 0.2.25 → 0.2.26
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/README.md +186 -5
- package/config/notis_app_design_rules.json +36 -14
- package/config/portal-route-roots.json +1 -0
- package/dist/agent-hooks/notis-agent-hook.mjs +2784 -541
- package/dist/base-skills/notis-cli/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-cli/references/intelligence.md +1 -1
- package/dist/base-skills/notis-query/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-query/SKILL.md +0 -1
- package/dist/base-skills/notis-query/references/documents.md +7 -0
- package/dist/base-skills/notis-query/references/query.md +1 -0
- package/dist/base-skills/notis-spaces/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-spaces/SKILL.md +96 -24
- package/dist/base-skills/notis-spaces/references/architecture.md +4 -3
- package/dist/base-skills/notis-spaces/references/design.md +37 -18
- package/dist/base-skills/notis-spaces/references/reading.md +8 -1
- package/dist/base-skills/notis-spaces/references/reports.md +6 -6
- package/dist/base-skills/notis-spaces/references/sdk.md +71 -7
- package/dist/base-skills/notis-spaces/references/store.md +22 -13
- package/dist/base-skills/notis-spaces/references/views.md +99 -6
- package/dist/sdk/package.json +3 -0
- package/dist/sdk/src/cloudComputerWords.ts +53 -0
- package/dist/sdk/src/components/Audience.tsx +76 -0
- package/dist/sdk/src/components/DocumentPage.tsx +15 -4
- package/dist/sdk/src/components/MarkdownEditor.tsx +44 -14
- package/dist/sdk/src/components/MultiSelectActionBar.tsx +16 -5
- package/dist/sdk/src/components/Skeleton.tsx +162 -6
- package/dist/sdk/src/hooks/useAction.ts +12 -2
- package/dist/sdk/src/hooks/useAgentQueue.ts +125 -0
- package/dist/sdk/src/hooks/useCloudComputerJob.ts +142 -0
- package/dist/sdk/src/hooks/useCloudComputerService.ts +388 -0
- package/dist/sdk/src/hooks/useCloudComputerShell.ts +95 -7
- package/dist/sdk/src/hooks/useCollectionInteractions.ts +40 -2
- package/dist/sdk/src/hooks/useItemThread.ts +58 -0
- package/dist/sdk/src/hooks/useMarqueeSelection.ts +6 -1
- package/dist/sdk/src/hooks/useNativeDocuments.ts +61 -8
- package/dist/sdk/src/hooks/useNotisNavigation.ts +31 -8
- package/dist/sdk/src/hooks/useQuery.ts +67 -10
- package/dist/sdk/src/hooks/useViewParams.ts +47 -11
- package/dist/sdk/src/index.ts +31 -4
- package/dist/sdk/src/interactions.ts +2 -0
- package/dist/sdk/src/nativeData.ts +2 -0
- package/dist/sdk/src/optimisticRows.ts +329 -0
- package/dist/sdk/src/perf.ts +188 -0
- package/dist/sdk/src/provider.tsx +2 -1
- package/dist/sdk/src/queryCache.ts +366 -17
- package/dist/sdk/src/runtime.ts +55 -4
- package/dist/sdk/src/skeleton.ts +103 -0
- package/dist/sdk/src/space.ts +662 -28
- package/dist/sdk/src/spacePublicUI.ts +36 -0
- package/dist/sdk/src/ui/engine/step.ts +54 -0
- package/dist/sdk/src/ui/icons.tsx +3 -1
- package/dist/sdk/src/words/shell.ts +1 -0
- package/dist/skill-sync/index.js +7 -2
- package/dist/skill-sync-worker.mjs +40 -26
- package/dist/space-harness/host.js +272 -105
- package/dist/space-sdk/dist/chunk-BWHAORT4.js +5 -0
- package/dist/space-sdk/dist/index.js +9 -4
- package/dist/space-sdk/dist/ui.js +12 -12
- package/dist/space-sdk/package.json +3 -0
- package/dist/space-sdk/src/cloudComputerWords.d.ts +34 -0
- package/dist/space-sdk/src/components/Audience.d.ts +46 -0
- package/dist/space-sdk/src/components/DocumentPage.d.ts +3 -1
- package/dist/space-sdk/src/components/MarkdownEditor.d.ts +21 -0
- package/dist/space-sdk/src/components/MultiSelectActionBar.d.ts +5 -1
- package/dist/space-sdk/src/components/Skeleton.d.ts +7 -2
- package/dist/space-sdk/src/hooks/useAction.d.ts +8 -1
- package/dist/space-sdk/src/hooks/useAgentQueue.d.ts +61 -0
- package/dist/space-sdk/src/hooks/useCloudComputerJob.d.ts +35 -0
- package/dist/space-sdk/src/hooks/useCloudComputerService.d.ts +75 -0
- package/dist/space-sdk/src/hooks/useCloudComputerShell.d.ts +36 -3
- package/dist/space-sdk/src/hooks/useCollectionInteractions.d.ts +6 -0
- package/dist/space-sdk/src/hooks/useItemThread.d.ts +32 -0
- package/dist/space-sdk/src/hooks/useMarqueeSelection.d.ts +2 -1
- package/dist/space-sdk/src/hooks/useNativeDocumentBody.d.ts +1 -0
- package/dist/space-sdk/src/hooks/useNativeDocuments.d.ts +20 -5
- package/dist/space-sdk/src/hooks/useNotisNavigation.d.ts +11 -2
- package/dist/space-sdk/src/hooks/useQuery.d.ts +24 -2
- package/dist/space-sdk/src/hooks/useViewParams.d.ts +2 -0
- package/dist/space-sdk/src/index.d.ts +24 -4
- package/dist/space-sdk/src/nativeData.d.ts +6 -0
- package/dist/space-sdk/src/queryCache.d.ts +97 -2
- package/dist/space-sdk/src/runtime.d.ts +53 -4
- package/dist/space-sdk/src/skeleton.d.ts +42 -0
- package/dist/space-sdk/src/space.ts +662 -28
- package/dist/space-sdk/src/tailwind-candidates.d.ts +754 -5
- package/dist/space-sdk/src/ui/cloud/CloudComputerFrame.d.ts +29 -0
- package/dist/space-sdk/src/ui/cloud/CloudComputerWaking.d.ts +20 -0
- package/dist/space-sdk/src/ui/comments/CommentPane.d.ts +15 -2
- package/dist/space-sdk/src/ui/comments/PassageComments.d.ts +50 -0
- package/dist/space-sdk/src/ui/comments/commentFiles.d.ts +64 -0
- package/dist/space-sdk/src/ui/comments/commentModel.d.ts +49 -1
- package/dist/space-sdk/src/ui/comments/commentWords.d.ts +26 -0
- package/dist/space-sdk/src/ui/comments/index.d.ts +4 -0
- package/dist/space-sdk/src/ui/comments/passageModel.d.ts +82 -0
- package/dist/space-sdk/src/ui/comments/useComments.d.ts +34 -4
- package/dist/space-sdk/src/ui/comments/usePassageComments.d.ts +67 -0
- package/dist/space-sdk/src/ui/engine/index.d.ts +2 -2
- package/dist/space-sdk/src/ui/engine/step.d.ts +9 -0
- package/dist/space-sdk/src/ui/fields/fields.d.ts +2 -1
- package/dist/space-sdk/src/ui/index.d.ts +4 -0
- package/dist/space-sdk/src/ui/layout/Panels.d.ts +9 -2
- package/dist/space-sdk/src/ui/layout/SidePane.d.ts +42 -0
- package/dist/space-sdk/src/ui/layout/index.d.ts +2 -1
- package/dist/space-sdk/src/ui/layout/panelMath.d.ts +11 -2
- package/dist/space-sdk/src/ui/list/ListReader.d.ts +38 -7
- package/dist/space-sdk/src/ui/list/Row.d.ts +4 -0
- package/dist/space-sdk/src/ui/list/SelectionBar.d.ts +9 -4
- package/dist/space-sdk/src/ui/list/useListKeys.d.ts +4 -0
- package/dist/space-sdk/src/words/shell.ts +1 -0
- package/dist/view-renderer/dist/host.js +355 -188
- package/dist/view-renderer/dist/theme.css +1 -1
- package/dist/view-renderer/src/host.tsx +4 -1
- package/dist/view-renderer/src/index.js +3 -0
- package/dist/view-renderer/src/pool.js +8 -4
- package/dist/view-renderer/src/renderer.js +92 -23
- package/dist/view-renderer/src/skeleton.js +450 -0
- package/package.json +4 -4
- package/skills/notis-cli/AGENT_INSTRUCTIONS.md +8 -4
- package/skills/notis-onboarding/BRIEF.md +15 -9
- package/skills/notis-spaces/cli.md +43 -4
- package/src/command-specs/auth.js +5 -3
- package/src/command-specs/cc.js +410 -0
- package/src/command-specs/computer.js +320 -0
- package/src/command-specs/diagnostics.js +2 -13
- package/src/command-specs/documents.js +22 -4
- package/src/command-specs/index.js +7 -0
- package/src/command-specs/onboarding.js +127 -7
- package/src/command-specs/skills.js +2 -2
- package/src/command-specs/spaces.js +162 -30
- package/src/command-specs/tools.js +26 -8
- package/src/command-specs/views.js +4 -1
- package/src/runtime/agent-setup.js +20 -2
- package/src/runtime/app-boundary-validator.js +2 -1
- package/src/runtime/app-platform.js +13 -0
- package/src/runtime/auth-recovery.js +5 -0
- package/src/runtime/channel.js +16 -2
- package/src/runtime/cloud-transfer.js +587 -0
- package/src/runtime/computer-ssh.js +127 -0
- package/src/runtime/oauth.js +50 -4
- package/src/runtime/skill-sync/index.ts +20 -1
- package/src/runtime/skill-sync/local-scanner.ts +1 -0
- package/src/runtime/skill-sync/types.ts +2 -0
- package/src/runtime/space-audience.js +94 -0
- package/src/runtime/space-collection-scaffold.js +2 -1
- package/src/runtime/space-fixture-broker.js +2 -1
- package/src/runtime/space-lock.js +1 -4
- package/src/runtime/space-platform.js +18 -2
- package/src/runtime/space-source.js +105 -7
- package/src/runtime/space-test-server.js +13 -2
- package/src/runtime/space-verification.js +99 -6
- package/src/runtime/space-view-manifest.js +22 -4
- package/src/runtime/sync-skills.js +24 -20
- package/src/runtime/transport.js +19 -0
- package/src/runtime/view-render.js +2 -2
- package/template/.harness/index.html.tmpl +1 -1
- package/dist/skill-sync/index.js.map +0 -7
- package/dist/space-sdk/dist/chunk-SVZATGZB.js +0 -5
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useCallback } from 'react';
|
|
4
|
+
import { useQuery } from './useQuery';
|
|
5
|
+
import { useNotisRuntime } from '../provider';
|
|
6
|
+
import type { SpaceItemThread } from '../space';
|
|
7
|
+
|
|
8
|
+
export interface UseItemThreadResult {
|
|
9
|
+
/** The matched thread, or null while reading or when nothing matches yet. */
|
|
10
|
+
thread: SpaceItemThread | null;
|
|
11
|
+
loading: boolean;
|
|
12
|
+
error: Error | null;
|
|
13
|
+
/**
|
|
14
|
+
* Open the item's thread in the side chat, with an optional unsent draft. When nothing matches yet it
|
|
15
|
+
* opens a new chat with the draft; the first message creates the thread and links it to the item.
|
|
16
|
+
* Resolves false on hosts without a side chat.
|
|
17
|
+
*/
|
|
18
|
+
open: (options?: { draft?: string }) => Promise<boolean>;
|
|
19
|
+
/** False on hosts without the resolver (Sites, links, the dev harness): keep the Space's own fallback. */
|
|
20
|
+
available: boolean;
|
|
21
|
+
refresh: () => Promise<Error | null>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const NONE: SpaceItemThread = { thread_id: null, rule: 'best_match', level: null };
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The thread an item continues, from the Space's thread rule: the same thread the side chat, `useHandover`
|
|
28
|
+
* and the Space's agents use.
|
|
29
|
+
*
|
|
30
|
+
* ```tsx
|
|
31
|
+
* const { thread, open } = useItemThread(recordKey);
|
|
32
|
+
* return <Button onClick={() => void open()}>{thread?.thread_id ? 'Continue the chat' : 'Ask Notis'}</Button>;
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* Omit `recordKey` for the Space itself. With the `best_match` rule a record's own thread wins, then the
|
|
36
|
+
* current view with its params, then the view, then the Space; with `space` there is one thread per Space
|
|
37
|
+
* and person.
|
|
38
|
+
*/
|
|
39
|
+
export function useItemThread(recordKey?: string | null): UseItemThreadResult {
|
|
40
|
+
const runtime = useNotisRuntime();
|
|
41
|
+
const transport = runtime?.resource?.kind === 'space' ? runtime.spaceThreads : undefined;
|
|
42
|
+
const key = typeof recordKey === 'string' && recordKey ? recordKey : null;
|
|
43
|
+
const query = useQuery<SpaceItemThread>(['item-thread', key], async () => {
|
|
44
|
+
if (!transport) return NONE;
|
|
45
|
+
return transport.resolve(key ? { recordKey: key } : undefined);
|
|
46
|
+
}, { readOnly: true, enabled: Boolean(transport), staleTimeMs: 15_000 });
|
|
47
|
+
const open = useCallback(async (options?: { draft?: string }) => {
|
|
48
|
+
if (!transport) return false;
|
|
49
|
+
// Resolve again at the click: another surface may have linked a thread since the last read.
|
|
50
|
+
const thread = await transport.resolve(key ? { recordKey: key } : undefined);
|
|
51
|
+
if (thread.thread_id) return transport.open(thread.thread_id, options);
|
|
52
|
+
if (!runtime?.draftHandover) return false;
|
|
53
|
+
await runtime.draftHandover({ prompt: options?.draft });
|
|
54
|
+
return true;
|
|
55
|
+
}, [key, runtime, transport]);
|
|
56
|
+
return { thread: query.data ?? null, loading: query.loading, error: query.error, open,
|
|
57
|
+
available: Boolean(transport), refresh: query.refetch };
|
|
58
|
+
}
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* (`useCollectionInteractions`) and the toolkit list (`ListReader`), so both run the same code.
|
|
6
6
|
*
|
|
7
7
|
* - A press starts a marquee only on empty space inside the container: not on an item, not on a control
|
|
8
|
-
* (button, link, field). A press on a control does nothing here; a press on an item is left to the item.
|
|
8
|
+
* (button, link, field). A press on a control does nothing here; a press on an item is left to the item. A press
|
|
9
|
+
* outside the container's DOM (a portaled menu or popover React bubbles through it) is not on its space either.
|
|
9
10
|
* - The marquee shows once the pointer moved past `threshold` px; the text selection is cleared then.
|
|
10
11
|
* - While dragging, every selectable item the rectangle intersects is selected, live (`onSelect`, in DOM order;
|
|
11
12
|
* the last one is the anchor).
|
|
@@ -106,6 +107,10 @@ export function useMarqueeSelection(options: UseMarqueeSelectionOptions): Marque
|
|
|
106
107
|
if (!enabled || event.button !== 0) return;
|
|
107
108
|
const target = event.target as HTMLElement | null;
|
|
108
109
|
if (!target || typeof target.closest !== 'function') return;
|
|
110
|
+
if (!(event.currentTarget as HTMLElement).contains(target)) {
|
|
111
|
+
clickShouldClearRef.current = false;
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
109
114
|
const itemTarget = target.closest(`[${itemAttribute}]`);
|
|
110
115
|
const interactiveTarget = target.closest(interactiveSelector);
|
|
111
116
|
if (interactiveTarget && interactiveTarget !== itemTarget) {
|
|
@@ -5,8 +5,10 @@ import { useNotisRuntime } from '../provider';
|
|
|
5
5
|
import { normalizeDocumentRecord } from '../documents';
|
|
6
6
|
import type { DocumentRecord, NotisRuntime } from '../runtime';
|
|
7
7
|
import type { NativeDelete, NativeInsert, NativeMutationReceipt, NativeQuery, NativeUpdate } from '../nativeData';
|
|
8
|
+
import { insertChange, tempRecordKey, updateChange } from '../optimisticRows';
|
|
8
9
|
import { useQuery, type UseQueryResult } from './useQuery';
|
|
9
10
|
import { SdkQueryError } from '../queryErrors';
|
|
11
|
+
import { NATIVE_ROWS } from '../queryCache';
|
|
10
12
|
|
|
11
13
|
function actionFor(runtime: NotisRuntime | null, binding: string, operation: 'query' | 'insert' | 'update' | 'delete'): string {
|
|
12
14
|
const descriptor = runtime?.space?.bindings[binding];
|
|
@@ -42,54 +44,105 @@ export function useNativeDocuments(binding: string, options: {
|
|
|
42
44
|
return () => { cancelled = true; setLive(false); stop?.(); };
|
|
43
45
|
}, [runtime, binding, follow]);
|
|
44
46
|
const locale = runtime?.context?.locale === 'fr' ? 'fr' : 'en';
|
|
45
|
-
const query = useQuery(['native-documents', binding, options.query ?? {}, Boolean(options.fetchAll), locale], async () => {
|
|
47
|
+
const query = useQuery<{ documents: DocumentRecord[]; schemaRevision: number }>(['native-documents', binding, options.query ?? {}, Boolean(options.fetchAll), locale], async (publish) => {
|
|
46
48
|
const action = actionFor(runtime, binding, 'query');
|
|
47
49
|
if (options.query?.mode && !['rows', 'search'].includes(options.query.mode)) throw new Error('Use useActionQuery for counts and aggregates.');
|
|
48
50
|
const rows: unknown[] = [];
|
|
49
51
|
let offset = options.query?.offset ?? 0;
|
|
50
52
|
let revision: number | undefined;
|
|
53
|
+
const answerOf = (list: unknown[]) => {
|
|
54
|
+
const answer = { documents: list.map((row) => normalizeDocumentRecord(row, { locale })), schemaRevision: revision! };
|
|
55
|
+
// The flattened documents drop property types and option ids; writes shown at once need them.
|
|
56
|
+
Object.defineProperty(answer, NATIVE_ROWS, { value: list, enumerable: false });
|
|
57
|
+
return answer;
|
|
58
|
+
};
|
|
51
59
|
while (true) {
|
|
52
60
|
const result = await runtime!.callAction!<{ rows: unknown[]; schema_revision: number; has_more: boolean; next_offset: number | null }>(
|
|
53
61
|
action, { request: { ...options.query, offset } }, { readOnly: true, dedupe: true, schemaRevision: revision });
|
|
54
62
|
if (!result || !Array.isArray(result.rows) || !Number.isSafeInteger(result.schema_revision)) throw new SdkQueryError('responseIncomplete', 'Native query must return rows and a safe integer schema_revision.');
|
|
55
63
|
if (revision !== undefined && revision !== result.schema_revision) throw new SdkQueryError('schemaChanged');
|
|
64
|
+
const first = revision === undefined;
|
|
56
65
|
revision = result.schema_revision;
|
|
57
66
|
rows.push(...result.rows);
|
|
58
67
|
if (!options.fetchAll || !result.has_more) break;
|
|
59
68
|
if (typeof result.next_offset !== 'number' || result.next_offset <= offset) throw new SdkQueryError('responseIncomplete', 'Native query pagination did not advance next_offset.');
|
|
69
|
+
// Every page is asked for: the first one shows at once (still fetching) while the next ones load.
|
|
70
|
+
if (first) publish?.(answerOf(rows.slice()));
|
|
60
71
|
offset = result.next_offset;
|
|
61
72
|
}
|
|
62
|
-
return
|
|
63
|
-
}, { readOnly: true, enabled: options.enabled, staleTimeMs: options.staleTimeMs
|
|
73
|
+
return answerOf(rows);
|
|
74
|
+
}, { readOnly: true, enabled: options.enabled, staleTimeMs: options.staleTimeMs,
|
|
75
|
+
rows: { binding, at: 'documents', shape: 'document', query: options.query ?? {} } });
|
|
64
76
|
return { ...query, documents: query.data?.documents ?? EMPTY_DOCUMENTS, schemaRevision: query.data?.schemaRevision, live };
|
|
65
77
|
}
|
|
66
78
|
|
|
67
|
-
/**
|
|
79
|
+
/** Options of one native write. */
|
|
80
|
+
export interface NativeMutationOptions {
|
|
81
|
+
schemaRevision: number;
|
|
82
|
+
requestId: string;
|
|
83
|
+
/**
|
|
84
|
+
* Inserts: the Space `shows` lists the new row shows in before the server answers (their filters stay on the
|
|
85
|
+
* server). By default the view's only list over this database, if it has exactly one.
|
|
86
|
+
*/
|
|
87
|
+
showIn?: string | readonly string[];
|
|
88
|
+
/** One step of a batch that refreshes the lists itself at the end. */
|
|
89
|
+
deferRefresh?: boolean;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Explicit insert/update/trash; update never silently creates a missing row.
|
|
94
|
+
*
|
|
95
|
+
* The write shows in every cached read of the database at once: an edited row changes where it is (and moves to its
|
|
96
|
+
* sorted place, or leaves a read whose filter the page sent and no longer keeps it), a new row joins the reads whose
|
|
97
|
+
* filter it passes and the `showIn` lists, a trashed row leaves. A failed write puts the server's rows back.
|
|
98
|
+
*/
|
|
68
99
|
export function useNativeMutation<TOperation extends 'insert' | 'update' | 'delete'>(binding: string, operation: TOperation): {
|
|
69
100
|
mutate: (input: TOperation extends 'insert' ? NativeInsert : TOperation extends 'update' ? NativeUpdate : NativeDelete,
|
|
70
|
-
options:
|
|
101
|
+
options: NativeMutationOptions) => Promise<NativeMutationReceipt>;
|
|
71
102
|
loading: boolean; error: Error | null;
|
|
72
103
|
} {
|
|
73
104
|
const runtime = useNotisRuntime();
|
|
74
105
|
const [pending, setPending] = useState(0), [error, setError] = useState<Error | null>(null);
|
|
75
|
-
const mutate = useCallback(async (input: NativeInsert | NativeUpdate | NativeDelete, options:
|
|
106
|
+
const mutate = useCallback(async (input: NativeInsert | NativeUpdate | NativeDelete, options: NativeMutationOptions) => {
|
|
76
107
|
const action = actionFor(runtime, binding, operation);
|
|
77
108
|
setPending((value) => value + 1); setError(null);
|
|
109
|
+
const client = runtime?.queryClient;
|
|
78
110
|
// A trashed row leaves every cached read at once and comes back if the write fails.
|
|
79
111
|
const key = operation === 'delete' && typeof (input as NativeDelete).record_key === 'string' ? (input as NativeDelete).record_key : null;
|
|
80
|
-
const hidden = key ?
|
|
112
|
+
const hidden = key ? client?.hideRecords?.([key]) : undefined;
|
|
113
|
+
const shown = operation === 'update' && typeof (input as NativeUpdate).record_key === 'string'
|
|
114
|
+
? client?.optimistic?.([updateChange(binding, input as NativeUpdate)])
|
|
115
|
+
: operation === 'insert' ? client?.optimistic?.([insertChange(binding, input as NativeInsert, tempRecordKey(), showInLists(runtime, binding, options.showIn))])
|
|
116
|
+
: undefined;
|
|
117
|
+
const { showIn: _showIn, ...callOptions } = options;
|
|
81
118
|
try {
|
|
82
|
-
|
|
119
|
+
// A shown write refreshes the lists itself, after it is confirmed: every read of that refresh then holds it,
|
|
120
|
+
// so none can keep the change on top of rows the server already answered without it.
|
|
121
|
+
const receipt = await runtime!.callAction!<NativeMutationReceipt>(action, { request: input },
|
|
122
|
+
shown ? { ...callOptions, deferRefresh: true } : callOptions);
|
|
83
123
|
hidden?.commit();
|
|
124
|
+
shown?.commit(receipt && typeof receipt.record_key === 'string'
|
|
125
|
+
? { recordKey: receipt.record_key, id: receipt.id, revision: receipt.revision } : undefined);
|
|
126
|
+
if (shown && !callOptions.deferRefresh) client?.invalidate();
|
|
84
127
|
return receipt;
|
|
85
128
|
} catch (cause) {
|
|
86
129
|
hidden?.restore();
|
|
130
|
+
shown?.rollback();
|
|
131
|
+
// The write may still have landed (an unknown outcome): read the server's rows again.
|
|
132
|
+
if (shown) client?.invalidate();
|
|
87
133
|
const failure = cause instanceof Error ? cause : new Error(String(cause)); setError(failure); throw failure;
|
|
88
134
|
} finally { setPending((value) => value - 1); }
|
|
89
135
|
}, [runtime, binding, operation]);
|
|
90
136
|
return { mutate, loading: pending > 0, error };
|
|
91
137
|
}
|
|
92
138
|
|
|
139
|
+
/** The `shows` lists a new row of `binding` shows in: the ones named, else the view's only list over it. */
|
|
140
|
+
function showInLists(runtime: NotisRuntime | null, binding: string, showIn: NativeMutationOptions['showIn']): string[] {
|
|
141
|
+
if (showIn !== undefined) return typeof showIn === 'string' ? [showIn] : [...showIn];
|
|
142
|
+
const lists = Object.entries(runtime?.space?.shows ?? {}).filter(([, list]) => 'database' in list && list.database === binding);
|
|
143
|
+
return lists.length === 1 ? [lists[0]![0]] : [];
|
|
144
|
+
}
|
|
145
|
+
|
|
93
146
|
export interface NativeDeleteManyResult {
|
|
94
147
|
done: NativeDelete[];
|
|
95
148
|
failed: Array<{ input: NativeDelete; error: Error }>;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { useCallback } from 'react';
|
|
4
4
|
import { useNotisRuntime } from '../provider';
|
|
5
|
+
import { isNotisNavigationRefusal, type NotisNavigationAnswer } from '../runtime';
|
|
5
6
|
|
|
6
7
|
export interface SpaceNavigationOptions {
|
|
7
8
|
recordKey?: string | null;
|
|
@@ -19,9 +20,9 @@ interface NavigationActions {
|
|
|
19
20
|
*/
|
|
20
21
|
toSpace: (spaceId: string, options?: SpaceNavigationOptions) => Promise<void>;
|
|
21
22
|
/** Navigate to a route within the app by its path. */
|
|
22
|
-
toRoute: (path: string, options?: { resourceId?: string | null }) => void
|
|
23
|
+
toRoute: (path: string, options?: { resourceId?: string | null }) => Promise<void>;
|
|
23
24
|
/** Navigate to the app's default route. */
|
|
24
|
-
toApp: () => void
|
|
25
|
+
toApp: () => Promise<void>;
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
/**
|
|
@@ -34,36 +35,58 @@ interface NavigationActions {
|
|
|
34
35
|
* nav.toSpace(spaceId, { recordKey });
|
|
35
36
|
* ```
|
|
36
37
|
*/
|
|
38
|
+
/**
|
|
39
|
+
* A navigation the host refuses (its Manager draft context ended, the Space closed, the view is retained or covered)
|
|
40
|
+
* is reported and returned to the caller, never left as an unhandled rejection: navigation is fire-and-forget in
|
|
41
|
+
* most Spaces (PostHog "This Space context is no longer active." unhandled on app-nightly, 2026-10-30, and again
|
|
42
|
+
* from toSpace and setParams: health:2026-11-06:space-navigation). The host refuses by throwing or by answering a
|
|
43
|
+
* typed refusal; both settle the same way, and a caller that awaits still sees the refusal.
|
|
44
|
+
*/
|
|
45
|
+
export function settledNavigation(navigate: () => NotisNavigationAnswer | Promise<NotisNavigationAnswer>): Promise<void> {
|
|
46
|
+
let outcome: Promise<void>;
|
|
47
|
+
try {
|
|
48
|
+
outcome = Promise.resolve(navigate()).then((answer) => {
|
|
49
|
+
if (isNotisNavigationRefusal(answer)) throw new Error(answer.message);
|
|
50
|
+
});
|
|
51
|
+
} catch (error) { outcome = Promise.reject(error); }
|
|
52
|
+
outcome.catch((error: unknown) => {
|
|
53
|
+
console.warn('The Notis host refused the navigation.', error instanceof Error ? error.message : error);
|
|
54
|
+
});
|
|
55
|
+
return outcome;
|
|
56
|
+
}
|
|
57
|
+
|
|
37
58
|
export function useNotisNavigation(): NavigationActions {
|
|
38
59
|
const runtime = useNotisRuntime();
|
|
39
60
|
|
|
40
61
|
const toNamedSpace = useCallback(async (alias: string, options?: SpaceNavigationOptions) => {
|
|
41
62
|
if (runtime?.resource?.kind !== 'space' || !runtime.navigate) throw new Error('Open this Space in a current Notis host to navigate.');
|
|
42
|
-
await runtime.navigate({ kind: 'space-reference', alias, documentId: options?.recordKey ?? null,
|
|
43
|
-
...(options?.params ? { params: options.params } : {}) });
|
|
63
|
+
await settledNavigation(() => runtime.navigate!({ kind: 'space-reference', alias, documentId: options?.recordKey ?? null,
|
|
64
|
+
selection: options?.selection ?? null, ...(options?.params ? { params: options.params } : {}) }));
|
|
44
65
|
}, [runtime]);
|
|
45
66
|
|
|
46
67
|
const toSpace = useCallback(async (spaceId: string, options?: SpaceNavigationOptions) => {
|
|
47
68
|
if (!runtime?.navigate) throw new Error('Open this Space in a current Notis host to navigate.');
|
|
48
|
-
await runtime.navigate({ kind: 'space', spaceId, documentId: options?.recordKey ?? null,
|
|
49
|
-
...(options?.params ? { params: options.params } : {}), ...(options?.selection ? { selection: options.selection } : {}) });
|
|
69
|
+
await settledNavigation(() => runtime.navigate!({ kind: 'space', spaceId, documentId: options?.recordKey ?? null,
|
|
70
|
+
...(options?.params ? { params: options.params } : {}), ...(options?.selection ? { selection: options.selection } : {}) }));
|
|
50
71
|
}, [runtime]);
|
|
51
72
|
|
|
52
73
|
const toRoute = useCallback((path: string, options?: { resourceId?: string | null }) => {
|
|
53
74
|
if (runtime?.navigate) {
|
|
54
|
-
runtime.navigate({ kind: 'route', path, resourceId: options?.resourceId ?? null });
|
|
75
|
+
return settledNavigation(() => runtime.navigate!({ kind: 'route', path, resourceId: options?.resourceId ?? null }));
|
|
55
76
|
} else if (typeof window !== 'undefined') {
|
|
56
77
|
const url = new URL(path, window.location.href);
|
|
57
78
|
if (options?.resourceId) url.searchParams.set('resource', options.resourceId);
|
|
58
79
|
else url.searchParams.delete('resource');
|
|
59
80
|
window.location.href = url.toString();
|
|
60
81
|
}
|
|
82
|
+
return Promise.resolve();
|
|
61
83
|
}, [runtime]);
|
|
62
84
|
|
|
63
85
|
const toApp = useCallback(() => {
|
|
64
86
|
if (runtime?.navigate) {
|
|
65
|
-
runtime.navigate({ kind: 'app' });
|
|
87
|
+
return settledNavigation(() => runtime.navigate!({ kind: 'app' }));
|
|
66
88
|
}
|
|
89
|
+
return Promise.resolve();
|
|
67
90
|
}, [runtime]);
|
|
68
91
|
|
|
69
92
|
return { toNamedSpace, toSpace, toRoute, toApp };
|
|
@@ -2,15 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useSyncExternalStore } from 'react';
|
|
4
4
|
import { useNotisRuntime } from '../provider';
|
|
5
|
-
import { createQueryClient, queryKey } from '../queryCache';
|
|
5
|
+
import { createQueryClient, queryKey, type NotisQueryClient, type QueryRead, type QuerySnapshot, type RowsDescriptor } from '../queryCache';
|
|
6
6
|
import { spaceQueryKey } from '../space';
|
|
7
7
|
import { localizeQueryError } from '../queryErrors';
|
|
8
|
+
import { beginWait, endWait } from '../perf';
|
|
8
9
|
|
|
9
10
|
export interface UseQueryOptions {
|
|
10
11
|
/** Required acknowledgement: only idempotent reads may run on mount or prefetch. */
|
|
11
12
|
readOnly: true;
|
|
12
13
|
enabled?: boolean;
|
|
13
14
|
staleTimeMs?: number;
|
|
15
|
+
/**
|
|
16
|
+
* The native rows this read answers with, so a write to that database shows in it at once: `binding` is the
|
|
17
|
+
* database binding, `at` the answer field holding the rows ('' when the answer is the list). Rows are native
|
|
18
|
+
* rows unless `shape` says 'document'; give `query` (the native query the read runs) to let a write add a new
|
|
19
|
+
* row, move a row to its sorted place, or take out a row its filter no longer keeps.
|
|
20
|
+
*/
|
|
21
|
+
rows?: { binding: string; at?: string; shape?: RowsDescriptor['shape']; query?: unknown; list?: string };
|
|
22
|
+
/**
|
|
23
|
+
* When the key changes (a filter, a search, a tab), keep answering with the last key's result, from the same
|
|
24
|
+
* cache and access scope, until the new one is read: `isPreviousData` is then true and `loading` false. Default
|
|
25
|
+
* true for reads that declare `rows` (lists), false otherwise (a read keyed by one record must not show another).
|
|
26
|
+
*/
|
|
27
|
+
keepPrevious?: boolean;
|
|
14
28
|
}
|
|
15
29
|
|
|
16
30
|
export interface UseQueryResult<T> {
|
|
@@ -18,26 +32,67 @@ export interface UseQueryResult<T> {
|
|
|
18
32
|
hasData: boolean;
|
|
19
33
|
loading: boolean;
|
|
20
34
|
isFetching: boolean;
|
|
35
|
+
/** `data` is the previous key's result, shown while this key is read (see `keepPrevious`). */
|
|
36
|
+
isPreviousData?: boolean;
|
|
21
37
|
error: Error | null;
|
|
22
38
|
/** Reads again; resolves to the read's localized error, or null when it succeeded (never rejects). */
|
|
23
39
|
refetch: () => Promise<Error | null>;
|
|
24
40
|
}
|
|
25
41
|
|
|
42
|
+
type Shown = { key: string; scope: string; client: NotisQueryClient };
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The previous key's snapshot to keep showing while `key` loads: only from the same client and access scope, only
|
|
46
|
+
* while that client still holds it (a cleared scope or a refused read takes it away), never over an error.
|
|
47
|
+
*/
|
|
48
|
+
function previousSnapshot<T>(client: NotisQueryClient, scope: string, key: string, current: QuerySnapshot<T>,
|
|
49
|
+
previous: Shown | null): QuerySnapshot<T> | null {
|
|
50
|
+
if (current.hasData || current.error || !previous || previous.key === key || previous.client !== client || previous.scope !== scope) return null;
|
|
51
|
+
const prior = client.getSnapshot<T>(previous.key);
|
|
52
|
+
return prior.hasData && !prior.error ? prior : null;
|
|
53
|
+
}
|
|
54
|
+
|
|
26
55
|
/** Cached read callback; scope and lifetime are provided by the host, never by app globals. */
|
|
27
|
-
export function useQuery<T>(key: readonly unknown[], read: () => Promise<T>, options: UseQueryOptions): UseQueryResult<T> {
|
|
56
|
+
export function useQuery<T>(key: readonly unknown[], read: (publish?: (partial: NoInfer<T>) => void) => Promise<T>, options: UseQueryOptions): UseQueryResult<T> {
|
|
28
57
|
const runtime = useNotisRuntime();
|
|
29
58
|
// Older hosts deliberately get a hook-local cache: no cross-runtime/account reuse.
|
|
30
59
|
const fallback = useMemo(() => createQueryClient(), [runtime]);
|
|
31
60
|
const client = runtime?.queryClient ?? fallback;
|
|
32
61
|
const cacheKey = queryKey(spaceQueryKey(runtime, key));
|
|
62
|
+
const scope = queryKey(spaceQueryKey(runtime, []));
|
|
33
63
|
const enabled = Boolean(runtime) && options.enabled !== false && options.readOnly === true;
|
|
64
|
+
const keep = options.keepPrevious ?? Boolean(options.rows);
|
|
34
65
|
const readRef = useRef(read);
|
|
66
|
+
const rowsRef = useRef<RowsDescriptor | undefined>(undefined);
|
|
67
|
+
rowsRef.current = options.rows ? { at: '', shape: 'native', ...options.rows } : undefined;
|
|
35
68
|
useLayoutEffect(() => { readRef.current = read; });
|
|
36
69
|
const subscribe = useCallback((listener: () => void) => enabled ? client.subscribe(cacheKey, listener) : () => {}, [cacheKey, client, enabled]);
|
|
37
70
|
const snapshot = useSyncExternalStore(subscribe, () => client.getSnapshot<T>(cacheKey), () => client.getSnapshot<T>(cacheKey));
|
|
71
|
+
// The last key this hook showed an answer for.
|
|
72
|
+
const shownRef = useRef<Shown | null>(null);
|
|
73
|
+
const prior = enabled && keep ? previousSnapshot(client, scope, cacheKey, snapshot, shownRef.current) : null;
|
|
74
|
+
const hasData = enabled && (snapshot.hasData || prior !== null);
|
|
75
|
+
// A changed key waits from the key press or click that changed it until its own answer paints (perf.ts).
|
|
76
|
+
const waitPart = useRef({});
|
|
77
|
+
const waitedKey = useRef<string | null>(null);
|
|
78
|
+
useLayoutEffect(() => {
|
|
79
|
+
if (!enabled) return;
|
|
80
|
+
const previous = shownRef.current;
|
|
81
|
+
if (previous && previous.key !== cacheKey && waitedKey.current !== cacheKey) {
|
|
82
|
+
if (waitedKey.current !== null) endWait('notis:query-change', waitPart.current);
|
|
83
|
+
waitedKey.current = cacheKey;
|
|
84
|
+
beginWait('notis:query-change', waitPart.current);
|
|
85
|
+
}
|
|
86
|
+
if (snapshot.hasData) {
|
|
87
|
+
shownRef.current = { key: cacheKey, scope, client };
|
|
88
|
+
if (waitedKey.current === cacheKey) { waitedKey.current = null; endWait('notis:query-change', waitPart.current); }
|
|
89
|
+
}
|
|
90
|
+
}, [cacheKey, client, enabled, scope, snapshot.hasData]);
|
|
91
|
+
// A hook that stops reading never holds a wait open.
|
|
92
|
+
useEffect(() => () => { if (waitedKey.current !== null) endWait('notis:query-change', waitPart.current); }, []);
|
|
38
93
|
const fetch = useCallback(() => {
|
|
39
94
|
const capturedRead = readRef.current;
|
|
40
|
-
return client.fetch(cacheKey, capturedRead, { staleTimeMs: options.staleTimeMs });
|
|
95
|
+
return client.fetch(cacheKey, capturedRead, { staleTimeMs: options.staleTimeMs, rows: rowsRef.current });
|
|
41
96
|
}, [cacheKey, client, options.staleTimeMs]);
|
|
42
97
|
useEffect(() => {
|
|
43
98
|
if (!enabled) return;
|
|
@@ -56,10 +111,11 @@ export function useQuery<T>(key: readonly unknown[], read: () => Promise<T>, opt
|
|
|
56
111
|
}, [cacheKey, client, enabled, fetch, locale]);
|
|
57
112
|
const error = useMemo(() => localizeQueryError(snapshot.error, runtime?.context?.locale), [snapshot.error, runtime?.context?.locale]);
|
|
58
113
|
return {
|
|
59
|
-
data: enabled ? snapshot.data : undefined,
|
|
60
|
-
hasData
|
|
61
|
-
loading: enabled && !
|
|
62
|
-
isFetching: enabled && snapshot.isFetching,
|
|
114
|
+
data: enabled ? (prior ?? snapshot).data : undefined,
|
|
115
|
+
hasData,
|
|
116
|
+
loading: enabled && !hasData && !snapshot.error,
|
|
117
|
+
isFetching: enabled && (snapshot.isFetching || prior !== null),
|
|
118
|
+
isPreviousData: prior !== null,
|
|
63
119
|
error: enabled ? error : null,
|
|
64
120
|
refetch,
|
|
65
121
|
};
|
|
@@ -68,14 +124,15 @@ export function useQuery<T>(key: readonly unknown[], read: () => Promise<T>, opt
|
|
|
68
124
|
/** Opt-in preparation for small, known read queries. Never use for writes or full-database crawls. */
|
|
69
125
|
export function useQueryClient(): {
|
|
70
126
|
invalidate(key?: readonly unknown[]): void;
|
|
71
|
-
prefetch<T>(key: readonly unknown[], read:
|
|
127
|
+
prefetch<T>(key: readonly unknown[], read: QueryRead<T>, options: UseQueryOptions): Promise<T | undefined>;
|
|
72
128
|
} {
|
|
73
129
|
const runtime = useNotisRuntime();
|
|
74
130
|
return useMemo(() => ({
|
|
75
131
|
invalidate: (key?: readonly unknown[]) => runtime?.queryClient?.invalidate(key ? queryKey(spaceQueryKey(runtime, key)) : undefined),
|
|
76
|
-
prefetch: <T,>(key: readonly unknown[], read:
|
|
132
|
+
prefetch: <T,>(key: readonly unknown[], read: QueryRead<T>, options: UseQueryOptions) => {
|
|
77
133
|
if (!runtime?.queryClient || options.enabled === false || options.readOnly !== true) return Promise.resolve(undefined);
|
|
78
|
-
return runtime.queryClient.prefetch(queryKey(spaceQueryKey(runtime, key)), read, { staleTimeMs: options.staleTimeMs
|
|
134
|
+
return runtime.queryClient.prefetch(queryKey(spaceQueryKey(runtime, key)), read, { staleTimeMs: options.staleTimeMs,
|
|
135
|
+
rows: options.rows ? { at: '', shape: 'native', ...options.rows } : undefined });
|
|
79
136
|
},
|
|
80
137
|
}), [runtime]);
|
|
81
138
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { useCallback, useMemo } from 'react';
|
|
3
|
+
import { useCallback, useEffect, useMemo, useRef } from 'react';
|
|
4
|
+
import { settledNavigation } from './useNotisNavigation';
|
|
4
5
|
import { useNotisRuntime } from '../provider';
|
|
5
6
|
import type { NotisRuntime } from '../runtime';
|
|
6
|
-
import {
|
|
7
|
+
import { queryKey } from '../queryCache';
|
|
8
|
+
import { useQuery, useQueryClient, type UseQueryResult } from './useQuery';
|
|
7
9
|
import { SdkQueryError } from '../queryErrors';
|
|
8
10
|
import type { SpaceDefinition, SpaceShownOptions, SpaceShownResult, SpaceViewParam } from '../space';
|
|
9
11
|
import { isViewDate, isViewPeriod } from '../viewPeriod';
|
|
@@ -104,12 +106,11 @@ export function writeViewParams(runtime: NotisRuntime | null | undefined, change
|
|
|
104
106
|
if (pendingWrites.get(runtime)?.params === next) pendingWrites.delete(runtime);
|
|
105
107
|
throw error;
|
|
106
108
|
};
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
109
|
+
// A refused write (the view is retained, covered or pending) is warned and settled like any navigation.
|
|
110
|
+
const written = settledNavigation(() => runtime.navigate!({ kind: 'view-params', params: next, ...(options.replace ? { replace: true } : {}) }))
|
|
111
|
+
.then(() => undefined, forget);
|
|
112
|
+
written.catch(() => undefined);
|
|
113
|
+
return written;
|
|
113
114
|
}
|
|
114
115
|
|
|
115
116
|
/**
|
|
@@ -139,6 +140,9 @@ export interface UseShownOptions extends SpaceShownOptions {
|
|
|
139
140
|
/** The most pages `useShown({ allPages: true })` reads. */
|
|
140
141
|
export const SHOWN_ALL_PAGES_MAX = 50;
|
|
141
142
|
const SHOWN_ALL_PAGES_SIZE = 200;
|
|
143
|
+
/** The most other tabs (enum values) of a shown list read ahead, and how long after it shows. */
|
|
144
|
+
export const SHOWN_SIBLING_TABS_MAX = 4;
|
|
145
|
+
const SHOWN_SIBLING_TABS_DELAY_MS = 300;
|
|
142
146
|
|
|
143
147
|
/** True when a declared list has an authorized host reader (Editor or exact record Site). */
|
|
144
148
|
export function useShownAvailable(name: string): boolean {
|
|
@@ -167,8 +171,8 @@ export function useShown<TRow = Record<string, unknown>>(name: string, options:
|
|
|
167
171
|
// already shown instead of reading the same list again. The read itself always sends every param.
|
|
168
172
|
const keyed = useMemo(() => reads ? Object.fromEntries(Object.entries(params).filter(([param]) => reads.includes(param))) : params,
|
|
169
173
|
[params, reads]);
|
|
170
|
-
const result = useQuery(['shown', name, keyed, sorts ?? null, pageSize ?? null, offset ?? null, includeContent ?? false,
|
|
171
|
-
allPages], async () => {
|
|
174
|
+
const result = useQuery<SpaceShownResult & { rows: TRow[] }>(['shown', name, keyed, sorts ?? null, pageSize ?? null, offset ?? null, includeContent ?? false,
|
|
175
|
+
allPages], async (publish) => {
|
|
172
176
|
if (!runtime?.shown) throw new SdkQueryError('listUnavailable');
|
|
173
177
|
if (!allPages) {
|
|
174
178
|
return runtime.shown<SpaceShownResult & { rows: TRow[] }>(name, params as Record<string, unknown>,
|
|
@@ -184,10 +188,42 @@ export function useShown<TRow = Record<string, unknown>>(name: string, options:
|
|
|
184
188
|
const pageRows = Array.isArray(answer?.rows) ? answer.rows : [];
|
|
185
189
|
rows.push(...pageRows);
|
|
186
190
|
if (pageRows.length < size) break;
|
|
191
|
+
// The first page shows at once (still fetching) while the next ones load.
|
|
192
|
+
if (page === 0) publish?.({ ...answer, rows: rows.slice() } as SpaceShownResult & { rows: TRow[] });
|
|
187
193
|
}
|
|
188
194
|
const merged = { ...(first as SpaceShownResult & { rows: TRow[] }), rows } as SpaceShownResult & { rows: TRow[] };
|
|
189
195
|
return merged;
|
|
190
|
-
}, { readOnly: true, enabled: available && !missing.length && options.enabled !== false, staleTimeMs: options.staleTimeMs
|
|
196
|
+
}, { readOnly: true, enabled: available && !missing.length && options.enabled !== false, staleTimeMs: options.staleTimeMs,
|
|
197
|
+
// The list's filter stays on the server: only its sorts are known here.
|
|
198
|
+
rows: list && 'database' in list ? { binding: list.database, at: 'rows', list: name, query: { sorts } } : undefined });
|
|
199
|
+
// The other tabs of this list (the values of an enum param its filter reads) are read once it shows, so switching
|
|
200
|
+
// tab shows its rows at once. One page lists only, a few values, in the host's background queue.
|
|
201
|
+
const { prefetch } = useQueryClient();
|
|
202
|
+
const settled = result.hasData && !result.isPreviousData && !result.isFetching && !result.error;
|
|
203
|
+
const siblingsKey = settled && !allPages && reads && list && 'database' in list ? queryKey([name, keyed, sorts ?? null, pageSize ?? null,
|
|
204
|
+
offset ?? null, includeContent ?? false]) : null;
|
|
205
|
+
const siblingRead = useRef({ params, keyed });
|
|
206
|
+
siblingRead.current = { params, keyed };
|
|
207
|
+
useEffect(() => {
|
|
208
|
+
if (!siblingsKey || !runtime?.shown || !reads || !list || !('database' in list)) return undefined;
|
|
209
|
+
const declared = runtime.space?.params ?? {};
|
|
210
|
+
const tab = reads.find((param) => declared[param]?.type === 'enum' && (declared[param]?.values?.length ?? 0) > 1);
|
|
211
|
+
if (!tab) return undefined;
|
|
212
|
+
const { params: current, keyed: currentKeyed } = siblingRead.current;
|
|
213
|
+
const values = declared[tab]!.values!.filter((value) => value !== current[tab]).slice(0, SHOWN_SIBLING_TABS_MAX);
|
|
214
|
+
const timer = setTimeout(() => {
|
|
215
|
+
for (const value of values) {
|
|
216
|
+
const nextParams = { ...current, [tab]: value };
|
|
217
|
+
void prefetch(['shown', name, { ...currentKeyed, [tab]: value }, sorts ?? null, pageSize ?? null, offset ?? null,
|
|
218
|
+
includeContent ?? false, false], () => runtime.shown!<SpaceShownResult & { rows: TRow[] }>(name, nextParams as Record<string, unknown>,
|
|
219
|
+
{ sorts, pageSize, offset, includeContent }), { readOnly: true, staleTimeMs: options.staleTimeMs,
|
|
220
|
+
rows: { binding: list.database, at: 'rows', list: name, query: { sorts } } }).catch(() => {});
|
|
221
|
+
}
|
|
222
|
+
}, SHOWN_SIBLING_TABS_DELAY_MS);
|
|
223
|
+
return () => clearTimeout(timer);
|
|
224
|
+
// The key names every input of the reads; the latest params are read from the ref.
|
|
225
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
226
|
+
}, [siblingsKey, runtime, prefetch]);
|
|
191
227
|
const unavailable = runtime !== null && !available && options.enabled !== false;
|
|
192
228
|
const error = useMemo(() => unavailable ? new SdkQueryError('listUnavailable', `The list "${name}" is unavailable in this view: declare it in \`shows\` `
|
|
193
229
|
+ `with a database, or gate it on useShownAvailable("${name}").`, runtime?.context?.locale) : null, [unavailable, name, runtime?.context?.locale]);
|
package/dist/sdk/src/index.ts
CHANGED
|
@@ -11,7 +11,8 @@ export { NotisProvider, useNotisRuntime } from './provider';
|
|
|
11
11
|
|
|
12
12
|
// Hooks
|
|
13
13
|
export { useAction, useActionQuery } from './hooks/useAction';
|
|
14
|
-
export {
|
|
14
|
+
export type { UseActionQueryOptions } from './hooks/useAction';
|
|
15
|
+
export { useNativeDocuments, useNativeMutation, useNativeDelete, type NativeDeleteManyResult, type NativeMutationOptions } from './hooks/useNativeDocuments';
|
|
15
16
|
export type { NativeField, NativeFilter, NativeQuery, NativeInsert, NativeUpdate, NativeDelete, NativeMutationReceipt } from './nativeData';
|
|
16
17
|
export type { SpaceDatabaseCreate, SpaceResourceReference } from './space';
|
|
17
18
|
export type { SpaceActionTemplate, SpaceActionDescriptor, SpaceRuntimeDescriptor, SpaceActionOptions } from './space';
|
|
@@ -26,16 +27,31 @@ export type { SpaceViewParam, SpaceViewParamType, SpaceViewFilter, SpaceShows, S
|
|
|
26
27
|
SpaceMemoryPolicy, SpaceMemorySnapshot, SpaceChrome, SpaceMarkdownInput } from './space';
|
|
27
28
|
export { SPACE_VIEWER_READ_OPERATIONS } from './space';
|
|
28
29
|
export { SPACE_CLOUD_COMPUTER_OPERATIONS, spaceCloudComputerAllows } from './space';
|
|
30
|
+
export { spaceCloudComputerAccess } from './space';
|
|
29
31
|
export type { SpaceCloudComputerLevel, SpaceCloudComputerOperation, SpaceCloudComputerStatus, SpaceCloudComputerRelease, SpaceCloudComputerRunInput,
|
|
30
|
-
SpaceCloudComputerRunResult, SpaceCloudComputerUploadInput, SpaceCloudComputerUploadResult, SpaceCloudComputerTransport
|
|
32
|
+
SpaceCloudComputerRunResult, SpaceCloudComputerUploadInput, SpaceCloudComputerUploadResult, SpaceCloudComputerTransport,
|
|
33
|
+
SpaceCloudComputerDeclaration, SpaceCloudComputerService, SpaceCloudComputerJobOperation, SpaceCloudComputerJobInput,
|
|
34
|
+
SpaceCloudComputerJobStatus, SpaceCloudComputerJobLogs, SpaceCloudComputerJobResult, SpaceCloudComputerLeaseInput,
|
|
35
|
+
SpaceCloudComputerLeaseResult, SpaceCloudComputerFolder, JobState, SpaceCloudComputerAccessInput, SpaceCloudComputerAccessResult,
|
|
36
|
+
SpaceCloudComputerMediaLink, SpaceCloudComputerFrameCode, SpaceCloudComputerTransferOperation, SpaceCloudComputerFileUpload,
|
|
37
|
+
SpaceCloudComputerUploadProgress, SpaceCloudComputerFileUploadResult, SpaceCloudComputerImportInput,
|
|
38
|
+
SpaceCloudComputerImportResult } from './space';
|
|
31
39
|
export type { SpaceViewerReadFamily, SpaceViewerReadOperation, SpaceViewerReadInput, SpaceViewerReadResult, SpaceViewerLink,
|
|
32
40
|
SpaceViewerDatabase, SpaceViewerDatabaseSchema, SpaceViewerSkill, SpaceViewerSkillPage } from './space';
|
|
41
|
+
export type { SpaceAgentDeclaration, SpaceItemThread, SpaceAgentQueue, SpaceAgentsStatus, SpaceThreadsTransport } from './space';
|
|
33
42
|
export { SpaceActionError, SpaceNavigationCancelled, isSpaceNavigationCancelled } from './space';
|
|
43
|
+
export { spaceAudience, spaceMarksEditorsOnly, publicSpaceDescriptor, withoutEditorColumns } from './space';
|
|
44
|
+
export type { SpaceAudience, SpaceEditorsOnly, SpaceResourceColumns, EditorOnlyColumns, AudienceRow } from './space';
|
|
45
|
+
export { useAudience, Editors, Public, ViewAsPublic, AUDIENCE_WORDS } from './components/Audience';
|
|
46
|
+
export type { UseAudienceResult, ViewAsPublicProps } from './components/Audience';
|
|
47
|
+
export { SpaceFileError, SPACE_FILE_EXTENSIONS, SPACE_FILE_MAX_BYTES } from './space';
|
|
48
|
+
export type { SpaceFileUploadInput, SpaceFileUploadResult, SpaceFileReference, SpaceFilesCheck, SpaceFilesTransport } from './space';
|
|
34
49
|
export type { SpaceActionFailureDetails } from './space';
|
|
35
50
|
export { useQuery, useQueryClient } from './hooks/useQuery';
|
|
36
51
|
export type { UseQueryOptions, UseQueryResult } from './hooks/useQuery';
|
|
37
|
-
export { createQueryClient, createPrefetchQueue, queryKey } from './queryCache';
|
|
38
|
-
export type { NotisQueryClient, QuerySnapshot, QueryFetchOptions, HiddenRecords
|
|
52
|
+
export { createQueryClient, createPrefetchQueue, queryKey, optimisticRowState, OPTIMISTIC_ROW } from './queryCache';
|
|
53
|
+
export type { NotisQueryClient, QuerySnapshot, QueryFetchOptions, HiddenRecords, RowsDescriptor, RowsRead, RowChange,
|
|
54
|
+
OptimisticWrite, OptimisticRowState } from './queryCache';
|
|
39
55
|
export { useNotis } from './hooks/useNotis';
|
|
40
56
|
export { useDocuments } from './hooks/useDocuments';
|
|
41
57
|
export type { UseDocumentsOptions, UseDocumentsResult } from './hooks/useDocuments';
|
|
@@ -57,8 +73,17 @@ export { useHandover } from './hooks/useHandover';
|
|
|
57
73
|
export type { UseHandoverResult } from './hooks/useHandover';
|
|
58
74
|
export { useCloudComputer } from './hooks/useCloudComputer';
|
|
59
75
|
export type { UseCloudComputerResult } from './hooks/useCloudComputer';
|
|
76
|
+
export { useItemThread } from './hooks/useItemThread';
|
|
77
|
+
export type { UseItemThreadResult } from './hooks/useItemThread';
|
|
78
|
+
export { useAgentQueue, AGENT_QUEUE_WORDS } from './hooks/useAgentQueue';
|
|
79
|
+
export type { UseAgentQueueResult, AgentQueueStatus } from './hooks/useAgentQueue';
|
|
60
80
|
export { useCloudComputerShell } from './hooks/useCloudComputerShell';
|
|
61
81
|
export type { UseCloudComputerShellResult } from './hooks/useCloudComputerShell';
|
|
82
|
+
export { useCloudComputerService, SERVICE_PULSE_MS } from './hooks/useCloudComputerService';
|
|
83
|
+
export type { CloudComputerServiceStatus, UseCloudComputerServiceOptions, UseCloudComputerServiceResult } from './hooks/useCloudComputerService';
|
|
84
|
+
export { useCloudComputerJob } from './hooks/useCloudComputerJob';
|
|
85
|
+
export type { UseCloudComputerJobOptions, UseCloudComputerJobResult } from './hooks/useCloudComputerJob';
|
|
86
|
+
export { CLOUD_COMPUTER_WORDS, cloudComputerPriceWords, formatHourlyPrice } from './cloudComputerWords';
|
|
62
87
|
export { useNotisNavigation } from './hooks/useNotisNavigation';
|
|
63
88
|
export { useTopBarSearch } from './hooks/useTopBarSearch';
|
|
64
89
|
export { useTopBarTitleLeaf } from './hooks/useTopBarTitleLeaf';
|
|
@@ -196,6 +221,8 @@ export type {
|
|
|
196
221
|
export { useToolQuery } from './hooks/useToolQuery';
|
|
197
222
|
|
|
198
223
|
export { Skeleton, SKELETON_WORDS, ViewSkeleton } from './components/Skeleton';
|
|
224
|
+
export { isNotisSpaceSkeleton, pickSkeletonEntry, SPACE_SKELETON_SCHEMA } from './skeleton';
|
|
225
|
+
export type { NotisSkeletonEntry, NotisSkeletonLocale, NotisSkeletonRow, NotisSkeletonWidth, NotisSpaceSkeleton, SkeletonBone } from './skeleton';
|
|
199
226
|
|
|
200
227
|
export { useLongPressSelection } from './hooks/useLongPressSelection';
|
|
201
228
|
export { isInteractionElementVisible } from './interactions/visibility';
|
|
@@ -19,6 +19,8 @@ export type {
|
|
|
19
19
|
ResolvedCollectionAction,
|
|
20
20
|
} from './interactions/actions';
|
|
21
21
|
export { useCollectionInteractions, COLLECTION_ITEM_ATTRIBUTE } from './hooks/useCollectionInteractions';
|
|
22
|
+
export { continuationOf, travelBetween } from './ui/engine/step';
|
|
23
|
+
export type { TravelDirection } from './ui/engine/step';
|
|
22
24
|
export type {
|
|
23
25
|
CollectionInteractionController,
|
|
24
26
|
CollectionInteractionReason,
|
|
@@ -19,6 +19,8 @@ export interface NativeQuery {
|
|
|
19
19
|
aggregate?: { op: 'sum' | 'avg' | 'min' | 'max'; field: NativeField };
|
|
20
20
|
page_size?: number;
|
|
21
21
|
offset?: number;
|
|
22
|
+
/** Return only these properties; the title column follows the title property. */
|
|
23
|
+
properties?: Array<{ property_id: string } | { property: string }>;
|
|
22
24
|
}
|
|
23
25
|
export interface NativeInsert {
|
|
24
26
|
columns?: { title?: string | null; icon?: string | null; cover?: string | null };
|