@collective-intelligence/external-apps-client-sdk-react 0.0.0-stage → 0.1.1
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 +140 -2
- package/dist/index-6memxjn1.js +49 -0
- package/dist/index.d.ts +958 -0
- package/dist/index.js +2 -0
- package/dist/resources.d.ts +662 -0
- package/dist/resources.js +2 -0
- package/package.json +70 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import{EntityForm,EntityList,EntityRuntimeProvider,EntityTable,FederatedAuthError,__export,createDelegatedEntitySource,defineEntity,useEntityViewState,useMemoryEntityViewState}from"./index-6memxjn1.js";var exports_src={};__export(exports_src,{useWorkflows:()=>useWorkflows,useSkills:()=>useSkills,useSession:()=>useSession,useRuns:()=>useRuns,useOrganizationClient:()=>useOrganizationClient,useMemoryEntityViewState:()=>useMemoryEntityViewState,useKnowledge:()=>useKnowledge,useEntityViewState:()=>useEntityViewState,useCollectiveIntelligenceClient:()=>useCollectiveIntelligenceClient,useCollectiveIntelligenceAuth:()=>useCollectiveIntelligenceAuth,useClientContext:()=>useClientContext,useAttachments:()=>useAttachments,useAgents:()=>useAgents,useAgentInvocation:()=>useAgentInvocation,defineEntity:()=>defineEntity,createPromptKeyHandler:()=>createPromptKeyHandler,createDelegatedEntitySource:()=>createDelegatedEntitySource,clientSdkReactEntrypoint:()=>clientSdkReactEntrypoint,SessionGate:()=>SessionGate,LoginCallbackPrimitive:()=>LoginCallbackPrimitive,LoginCallback:()=>LoginCallback,LoginButton:()=>LoginButton,EntityTable:()=>EntityTable,EntityList:()=>EntityList,EntityForm:()=>EntityForm,CollectiveIntelligenceProvider:()=>CollectiveIntelligenceProvider,CollectiveIntelligenceLoginProvider:()=>CollectiveIntelligenceLoginProvider,AgentPromptPrimitive:()=>AgentPromptPrimitive,AgentPrompt:()=>AgentPrompt});import{useCallback,useId,useState as useState2}from"react";import{QueryClient,QueryClientProvider}from"@tanstack/react-query";import{createContext,useContext,useMemo,useState}from"react";import{jsxDEV}from"react/jsx-dev-runtime";var ClientContext=createContext(null);var CollectiveIntelligenceProvider=(props)=>{const{clientFactory}=props;const[queryClient]=useState(()=>new QueryClient({defaultOptions:{mutations:{retry:false},queries:{retry:false}}}));const ownedClient=useMemo(()=>clientFactory===undefined?undefined:clientFactory(),[clientFactory]);const client=props.client??ownedClient;if(client===undefined){throw new TypeError("A client or clientFactory is required")}return jsxDEV(ClientContext.Provider,{value:client,children:jsxDEV(QueryClientProvider,{client:queryClient,children:props.entitySource===undefined?props.children:jsxDEV(EntityRuntimeProvider,{source:props.entitySource,children:props.children},undefined,false,undefined,this)},undefined,false,undefined,this)},undefined,false,undefined,this)};var useCollectiveIntelligenceClient=()=>{const client=useContext(ClientContext);if(client===null){throw new Error("CollectiveIntelligenceProvider must wrap Collective Intelligence hooks")}return client};var useOrganizationClient=(organizationId)=>{const client=useCollectiveIntelligenceClient();return useMemo(()=>client.forOrganization(organizationId),[client,organizationId])};var useKnowledge=(organizationId)=>useOrganizationClient(organizationId).knowledge;var useAgents=(organizationId)=>useOrganizationClient(organizationId).agents;var useSkills=(organizationId)=>useOrganizationClient(organizationId).skills;var useWorkflows=(organizationId)=>useOrganizationClient(organizationId).workflows;var useRuns=(organizationId)=>useOrganizationClient(organizationId).runs;var useAttachments=(organizationId)=>useOrganizationClient(organizationId).attachments;var useClientContext=(organizationId)=>useOrganizationClient(organizationId).context;import{jsxDEV as jsxDEV2}from"react/jsx-dev-runtime";var ignoreSubmit=()=>false;var createPromptKeyHandler=(onSubmit)=>(event)=>{if(event.key==="Enter"&&!event.shiftKey&&!event.isComposing){event.preventDefault();onSubmit()}};var AgentPromptPrimitive=({autoFocus=false,className,components,id,label,onChange,onSubmit,pending,status,style,submitLabel="Send",value})=>{const Form=components?.Form??"form";const Label=components?.Label??"label";const Textarea=components?.Textarea??"textarea";const Button=components?.Button??"button";const Status=components?.Status??"div";const statusId=`${id}-status`;const submit=(event)=>{event.preventDefault();if(!pending){onSubmit()}};const onKeyDown=(event)=>{createPromptKeyHandler(pending?ignoreSubmit:onSubmit)({isComposing:event.nativeEvent.isComposing,key:event.key,preventDefault:()=>{event.preventDefault()},shiftKey:event.shiftKey})};return jsxDEV2(Form,{className:["ci-agent-prompt",className].filter(Boolean).join(" "),onSubmit:submit,style,children:[jsxDEV2(Label,{className:"ci-agent-prompt__label",htmlFor:id,children:label},undefined,false,undefined,this),jsxDEV2(Textarea,{"aria-describedby":statusId,autoFocus,className:"ci-agent-prompt__input",disabled:pending,id,onChange:(event)=>{onChange(event.currentTarget.value)},onKeyDown,value},undefined,false,undefined,this),jsxDEV2(Button,{className:"ci-agent-prompt__submit",disabled:pending||value.trim().length===0,type:"submit",children:submitLabel},undefined,false,undefined,this),jsxDEV2(Status,{"aria-live":"polite",className:"ci-agent-prompt__status",id:statusId,children:status},undefined,false,undefined,this)]},undefined,true,undefined,this)};var useAgentInvocation=(organizationId)=>{const{agents}=useOrganizationClient(organizationId);const[state,setState]=useState2({status:"idle"});const invoke=useCallback(async(input)=>{setState({status:"submitting"});try{const result=await agents.invoke(input);setState(result.ok?{result,status:"success"}:{result,status:"failure"});return result}catch(error){setState({error,status:"error"});throw error}},[agents]);return{invoke,reset:()=>{setState({status:"idle"})},state}};var invocationStatus=(state)=>{switch(state.status){case"submitting":{return"Sending"}case"success":{return"Request started"}case"failure":{return state.result.error.message}case"error":{return"Request failed"}case"idle":{return null}default:{return null}}};var EMPTY_AGENT_PROMPT_COMPONENTS={};var EMPTY_AGENT_PROMPT_STYLE={};var createDefaultIdempotencyKey=()=>globalThis.crypto.randomUUID();var AgentPrompt=({agentId,autoFocus=false,className="",components=EMPTY_AGENT_PROMPT_COMPONENTS,createIdempotencyKey=createDefaultIdempotencyKey,label="Message",onResult,organizationId,style=EMPTY_AGENT_PROMPT_STYLE,submitLabel="Send"})=>{const id=`ci-agent-prompt-${useId().replaceAll(":","")}`;const[value,setValue]=useState2("");const invocation=useAgentInvocation(organizationId);const submit=()=>{const prompt=value.trim();if(prompt.length===0||invocation.state.status==="submitting"){return}const submitInvocation=async()=>{try{const result=await invocation.invoke({agentId,idempotencyKey:createIdempotencyKey(),input:{prompt}});if(result.ok){setValue("")}onResult?.(result)}catch{}};submitInvocation()};return jsxDEV2(AgentPromptPrimitive,{autoFocus,className,components,id,label,onChange:setValue,onSubmit:submit,pending:invocation.state.status==="submitting",status:invocationStatus(invocation.state),style,submitLabel,value},undefined,false,undefined,this)};import{createContext as createContext2,useCallback as useCallback2,useContext as useContext2,useEffect,useMemo as useMemo2,useSyncExternalStore}from"react";import{jsxDEV as jsxDEV3}from"react/jsx-dev-runtime";var AuthContext=createContext2(null);var toFederatedAuthError=(error)=>new FederatedAuthError("authorization_failed",error.message);var unknownAuthError=()=>new FederatedAuthError("authorization_failed","Sign in failed");var CollectiveIntelligenceLoginProvider=(props)=>{const state=useSyncExternalStore(props.auth.subscribe,props.auth.getState,props.auth.getState);const contextValue=useMemo2(()=>({auth:props.auth,state}),[props.auth,state]);return jsxDEV3(AuthContext.Provider,{value:contextValue,children:props.clientFactory===undefined?jsxDEV3(CollectiveIntelligenceProvider,{client:props.client,entitySource:props.entitySource,children:props.children},undefined,false,undefined,this):jsxDEV3(CollectiveIntelligenceProvider,{clientFactory:props.clientFactory,entitySource:props.entitySource,children:props.children},undefined,false,undefined,this)},undefined,false,undefined,this)};var useCollectiveIntelligenceAuth=()=>{const value=useContext2(AuthContext);if(value===null){throw new Error("CollectiveIntelligenceLoginProvider must wrap authentication bindings")}return{...value,beginLogin:value.auth.beginLogin,completeLogin:value.auth.completeLogin,logout:value.auth.logout,reauthorize:value.auth.reauthorize}};var LoginButton=({children="Sign in with Collective Intelligence",className,components,disabled=false,onError,returnTo,style})=>{const{auth,state}=useCollectiveIntelligenceAuth();const Button=components?.Button??"button";const redirecting=state.status==="redirecting";const onClick=useCallback2((event)=>{event.preventDefault();const target=returnTo??globalThis.location.href;const begin=async()=>{try{await auth.beginLogin({returnTo:target})}catch(error){onError?.(error instanceof Error?toFederatedAuthError(error):unknownAuthError())}};begin()},[auth,onError,returnTo]);return jsxDEV3(Button,{"aria-busy":redirecting,className:["ci-login-button",className].filter(Boolean).join(" "),disabled:disabled||redirecting,onClick,style,type:"button",children},undefined,false,undefined,this)};var callbackMessage=(state)=>{switch(state.status){case"authenticated":{return"Sign in complete"}case"error":{return state.error.message}case"expired":{return"Sign in expired"}case"anonymous":case"redirecting":{return"Completing sign in"}default:{return"Completing sign in"}}};var LoginCallbackPrimitive=({className,components,state,style})=>{const Status=components?.Status??"div";return jsxDEV3(Status,{"aria-live":"polite",className:["ci-login-callback",className].filter(Boolean).join(" "),style,children:callbackMessage(state)},undefined,false,undefined,this)};var LoginCallback=({callbackUrl,onComplete,onError,...primitiveProps})=>{const{auth,state}=useCollectiveIntelligenceAuth();useEffect(()=>{const url=callbackUrl??globalThis.location.href;const complete=async()=>{try{const{returnTo}=await auth.completeLogin(url);onComplete?.(returnTo)}catch(error){onError?.(error instanceof Error?toFederatedAuthError(error):unknownAuthError())}};complete()},[auth,callbackUrl,onComplete,onError]);return jsxDEV3(LoginCallbackPrimitive,{...primitiveProps,state},undefined,false,undefined,this)};var useSession=()=>{const{state}=useCollectiveIntelligenceAuth();return state};var SessionGate=({children,fallback=null})=>{const session=useSession();if(session.status!=="authenticated"){return fallback}return children};"use client";var clientSdkReactEntrypoint="react";"use client";var{AgentPrompt:AgentPrompt2,AgentPromptPrimitive:AgentPromptPrimitive2,CollectiveIntelligenceLoginProvider:CollectiveIntelligenceLoginProvider2,CollectiveIntelligenceProvider:CollectiveIntelligenceProvider2,LoginButton:LoginButton2,LoginCallback:LoginCallback2,LoginCallbackPrimitive:LoginCallbackPrimitive2,SessionGate:SessionGate2,clientSdkReactEntrypoint:clientSdkReactEntrypoint2,createPromptKeyHandler:createPromptKeyHandler2,useAgents:useAgents2,useAttachments:useAttachments2,useClientContext:useClientContext2,useCollectiveIntelligenceAuth:useCollectiveIntelligenceAuth2,useCollectiveIntelligenceClient:useCollectiveIntelligenceClient2,useKnowledge:useKnowledge2,useOrganizationClient:useOrganizationClient2,useRuns:useRuns2,useSession:useSession2,useSkills:useSkills2,useWorkflows:useWorkflows2,useAgentInvocation:useAgentInvocation2}=exports_src;export{useWorkflows2 as useWorkflows,useSkills2 as useSkills,useSession2 as useSession,useRuns2 as useRuns,useOrganizationClient2 as useOrganizationClient,useKnowledge2 as useKnowledge,useCollectiveIntelligenceClient2 as useCollectiveIntelligenceClient,useCollectiveIntelligenceAuth2 as useCollectiveIntelligenceAuth,useClientContext2 as useClientContext,useAttachments2 as useAttachments,useAgents2 as useAgents,useAgentInvocation2 as useAgentInvocation,createPromptKeyHandler2 as createPromptKeyHandler,clientSdkReactEntrypoint2 as clientSdkReactEntrypoint,SessionGate2 as SessionGate,LoginCallbackPrimitive2 as LoginCallbackPrimitive,LoginCallback2 as LoginCallback,LoginButton2 as LoginButton,CollectiveIntelligenceProvider2 as CollectiveIntelligenceProvider,CollectiveIntelligenceLoginProvider2 as CollectiveIntelligenceLoginProvider,AgentPromptPrimitive2 as AgentPromptPrimitive,AgentPrompt2 as AgentPrompt};
|
|
@@ -0,0 +1,662 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
import { ComponentType, ReactNode } from 'react';
|
|
4
|
+
|
|
5
|
+
export type FederatedAuthErrorCode = "configuration_error" | "invalid_return_target" | "invalid_callback" | "invalid_state" | "transaction_expired" | "authorization_failed" | "token_exchange_failed" | "reauthorization_required";
|
|
6
|
+
declare class FederatedAuthError extends Error {
|
|
7
|
+
readonly code: FederatedAuthErrorCode;
|
|
8
|
+
constructor(code: FederatedAuthErrorCode, message: string);
|
|
9
|
+
}
|
|
10
|
+
export type FederatedSessionIdentity = Readonly<{
|
|
11
|
+
email: string | null;
|
|
12
|
+
id: string;
|
|
13
|
+
name: string | null;
|
|
14
|
+
organizationId: string;
|
|
15
|
+
}>;
|
|
16
|
+
export type FederatedAuthState = Readonly<{
|
|
17
|
+
status: "anonymous";
|
|
18
|
+
}> | Readonly<{
|
|
19
|
+
status: "redirecting";
|
|
20
|
+
}> | Readonly<{
|
|
21
|
+
expiresAt: number;
|
|
22
|
+
identity?: FederatedSessionIdentity;
|
|
23
|
+
status: "authenticated";
|
|
24
|
+
}> | Readonly<{
|
|
25
|
+
status: "expired";
|
|
26
|
+
}> | Readonly<{
|
|
27
|
+
error: FederatedAuthError;
|
|
28
|
+
status: "error";
|
|
29
|
+
}>;
|
|
30
|
+
export type ClientFetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
31
|
+
export type ResourceJsonValue = null | boolean | number | string | readonly ResourceJsonValue[] | Readonly<{
|
|
32
|
+
[key: string]: ResourceJsonValue;
|
|
33
|
+
}>;
|
|
34
|
+
/** Opaque wire identity. Callers must not infer or concatenate its internals. */
|
|
35
|
+
export type ResourceId = string;
|
|
36
|
+
export type ResourceRecordId = ResourceId;
|
|
37
|
+
/** Opaque concurrency token independent from source timestamps. */
|
|
38
|
+
export type ResourceRevision = string;
|
|
39
|
+
/** Opaque pagination position issued and consumed only by a resource adapter. */
|
|
40
|
+
export type ResourceCursor = string;
|
|
41
|
+
export type IdempotencyKey = string;
|
|
42
|
+
export type ResourceIdentityField = Readonly<{
|
|
43
|
+
name: string;
|
|
44
|
+
type: "number" | "string";
|
|
45
|
+
}>;
|
|
46
|
+
export type ResourceCapabilities = Readonly<{
|
|
47
|
+
create?: boolean;
|
|
48
|
+
/** Common entity deletion is always soft deletion. */
|
|
49
|
+
delete?: boolean;
|
|
50
|
+
get?: boolean;
|
|
51
|
+
hardDelete?: boolean;
|
|
52
|
+
includeDeleted?: boolean;
|
|
53
|
+
restore?: boolean;
|
|
54
|
+
search: true;
|
|
55
|
+
softDelete?: boolean;
|
|
56
|
+
update?: boolean;
|
|
57
|
+
}>;
|
|
58
|
+
export type ResourcePaginationMode = "cursor" | "page";
|
|
59
|
+
export type PortableResourceSchema = Readonly<Record<string, ResourceJsonValue>>;
|
|
60
|
+
export type ResourceDefinition<Entity, Create = Entity, Update = Partial<Entity>> = Readonly<{
|
|
61
|
+
capabilities: ResourceCapabilities;
|
|
62
|
+
concurrency: "revision";
|
|
63
|
+
id: string;
|
|
64
|
+
identity: Readonly<{
|
|
65
|
+
fields: readonly [
|
|
66
|
+
ResourceIdentityField,
|
|
67
|
+
...ResourceIdentityField[]
|
|
68
|
+
];
|
|
69
|
+
}>;
|
|
70
|
+
query: Readonly<{
|
|
71
|
+
filterableFields: readonly string[];
|
|
72
|
+
pagination: Readonly<{
|
|
73
|
+
modes: readonly ResourcePaginationMode[];
|
|
74
|
+
}>;
|
|
75
|
+
sortableFields: readonly string[];
|
|
76
|
+
textSearchFields?: readonly string[];
|
|
77
|
+
}>;
|
|
78
|
+
schemas: Readonly<{
|
|
79
|
+
create?: PortableResourceSchema;
|
|
80
|
+
entity: PortableResourceSchema;
|
|
81
|
+
update?: PortableResourceSchema;
|
|
82
|
+
}>;
|
|
83
|
+
version: string;
|
|
84
|
+
/** Portable UI metadata; required/enum/nullability remain in schemas. */
|
|
85
|
+
metadata?: Readonly<Record<string, ResourceJsonValue>>;
|
|
86
|
+
/** Type-only slots keep definition values portable and serializable. */
|
|
87
|
+
readonly __types?: Readonly<{
|
|
88
|
+
create: Create;
|
|
89
|
+
entity: Entity;
|
|
90
|
+
update: Update;
|
|
91
|
+
}>;
|
|
92
|
+
}>;
|
|
93
|
+
export type FilterValue = ResourceJsonValue | readonly ResourceJsonValue[];
|
|
94
|
+
export type ResourceFilter = Readonly<{
|
|
95
|
+
field: string;
|
|
96
|
+
operator: "contains" | "ends_with" | "eq" | "gt" | "gte" | "in" | "lt" | "lte" | "ne" | "not_in" | "starts_with";
|
|
97
|
+
value: FilterValue;
|
|
98
|
+
}> | Readonly<{
|
|
99
|
+
field: string;
|
|
100
|
+
operator: "is_not_null" | "is_null";
|
|
101
|
+
}> | Readonly<{
|
|
102
|
+
filters: readonly ResourceFilter[];
|
|
103
|
+
operator: "and" | "or";
|
|
104
|
+
}> | Readonly<{
|
|
105
|
+
filter: ResourceFilter;
|
|
106
|
+
operator: "not";
|
|
107
|
+
}>;
|
|
108
|
+
export type ResourceSort = Readonly<{
|
|
109
|
+
direction: "asc" | "desc";
|
|
110
|
+
field: string;
|
|
111
|
+
}>;
|
|
112
|
+
export type ResourcePagination = Readonly<{
|
|
113
|
+
mode: "cursor";
|
|
114
|
+
cursor?: ResourceCursor;
|
|
115
|
+
limit: number;
|
|
116
|
+
}> | Readonly<{
|
|
117
|
+
mode: "page";
|
|
118
|
+
page: number;
|
|
119
|
+
pageSize: number;
|
|
120
|
+
}>;
|
|
121
|
+
export type ResourceListQuery = Readonly<{
|
|
122
|
+
filter?: ResourceFilter;
|
|
123
|
+
includeDeleted?: boolean;
|
|
124
|
+
pagination: ResourcePagination;
|
|
125
|
+
sort?: readonly ResourceSort[];
|
|
126
|
+
textSearch?: string;
|
|
127
|
+
}>;
|
|
128
|
+
export type ResourceRecord<Entity> = Readonly<{
|
|
129
|
+
deletedAt?: string;
|
|
130
|
+
id: ResourceRecordId;
|
|
131
|
+
revision: ResourceRevision;
|
|
132
|
+
value: Entity;
|
|
133
|
+
}>;
|
|
134
|
+
export type ResourceListResult<Entity> = Readonly<{
|
|
135
|
+
items: readonly ResourceRecord<Entity>[];
|
|
136
|
+
nextCursor?: ResourceCursor;
|
|
137
|
+
pagination: "cursor";
|
|
138
|
+
}> | Readonly<{
|
|
139
|
+
items: readonly ResourceRecord<Entity>[];
|
|
140
|
+
page: number;
|
|
141
|
+
pageSize: number;
|
|
142
|
+
pagination: "page";
|
|
143
|
+
totalItems: number;
|
|
144
|
+
totalPages: number;
|
|
145
|
+
}>;
|
|
146
|
+
export type ResourceErrorCode = "capability_not_supported" | "conflict" | "forbidden" | "internal" | "invalid_request" | "not_found" | "rate_limited" | "transport_error" | "unauthenticated" | "unavailable";
|
|
147
|
+
export type ResourceError = Readonly<{
|
|
148
|
+
code: ResourceErrorCode;
|
|
149
|
+
/** Client-observed dispatch outcome; uncertainty never proves rollback. */
|
|
150
|
+
outcome?: "not_dispatched" | "rejected" | "uncertain";
|
|
151
|
+
details?: Readonly<Record<string, ResourceJsonValue>>;
|
|
152
|
+
message: string;
|
|
153
|
+
retryable: boolean;
|
|
154
|
+
}>;
|
|
155
|
+
export type ResourceResult<Value> = Readonly<{
|
|
156
|
+
correlationId: string;
|
|
157
|
+
ok: true;
|
|
158
|
+
value: Value;
|
|
159
|
+
}> | Readonly<{
|
|
160
|
+
correlationId: string;
|
|
161
|
+
error: ResourceError;
|
|
162
|
+
ok: false;
|
|
163
|
+
}>;
|
|
164
|
+
export type ResourceRequestOptions = Readonly<{
|
|
165
|
+
signal?: AbortSignal;
|
|
166
|
+
}>;
|
|
167
|
+
export type ResourceMutationInput<Value> = Readonly<{
|
|
168
|
+
expectedRevision: ResourceRevision;
|
|
169
|
+
id: ResourceRecordId;
|
|
170
|
+
idempotencyKey?: IdempotencyKey;
|
|
171
|
+
value: Value;
|
|
172
|
+
}>;
|
|
173
|
+
export type ResourceLifecycleInput = Readonly<{
|
|
174
|
+
expectedRevision: ResourceRevision;
|
|
175
|
+
id: ResourceRecordId;
|
|
176
|
+
idempotencyKey?: IdempotencyKey;
|
|
177
|
+
}>;
|
|
178
|
+
export type ResourceCreateInput<Value> = Readonly<{
|
|
179
|
+
idempotencyKey: IdempotencyKey;
|
|
180
|
+
value: Value;
|
|
181
|
+
}>;
|
|
182
|
+
export interface ResourceClient<Entity, Create = Entity, Update = Partial<Entity>> {
|
|
183
|
+
readonly capabilities: ResourceCapabilities;
|
|
184
|
+
readonly create: (input: ResourceCreateInput<Create>, options?: ResourceRequestOptions) => Promise<ResourceResult<ResourceRecord<Entity>>>;
|
|
185
|
+
readonly definition: ResourceDefinition<Entity, Create, Update>;
|
|
186
|
+
readonly get: (input: Readonly<{
|
|
187
|
+
id: ResourceRecordId;
|
|
188
|
+
includeDeleted?: boolean;
|
|
189
|
+
}>, options?: ResourceRequestOptions) => Promise<ResourceResult<ResourceRecord<Entity>>>;
|
|
190
|
+
readonly hardDelete: (input: ResourceLifecycleInput, options?: ResourceRequestOptions) => Promise<ResourceResult<void>>;
|
|
191
|
+
readonly list: (query: ResourceListQuery, options?: ResourceRequestOptions) => Promise<ResourceResult<ResourceListResult<Entity>>>;
|
|
192
|
+
readonly restore: (input: ResourceLifecycleInput, options?: ResourceRequestOptions) => Promise<ResourceResult<ResourceRecord<Entity>>>;
|
|
193
|
+
readonly softDelete: (input: ResourceLifecycleInput, options?: ResourceRequestOptions) => Promise<ResourceResult<ResourceRecord<Entity>>>;
|
|
194
|
+
readonly update: (input: ResourceMutationInput<Update>, options?: ResourceRequestOptions) => Promise<ResourceResult<ResourceRecord<Entity>>>;
|
|
195
|
+
}
|
|
196
|
+
export type EntityListQuery = Omit<ResourceListQuery, "pagination" | "includeDeleted"> & Readonly<{
|
|
197
|
+
pagination: Extract<ResourcePagination, {
|
|
198
|
+
mode: "page";
|
|
199
|
+
}>;
|
|
200
|
+
}>;
|
|
201
|
+
export type EntityPage<Value> = Extract<ResourceListResult<Value>, {
|
|
202
|
+
pagination: "page";
|
|
203
|
+
}>;
|
|
204
|
+
export type EntityCreateInput<Value> = ResourceCreateInput<Value>;
|
|
205
|
+
export type EntityUpdateInput<Patch> = ResourceMutationInput<Patch> & Readonly<{
|
|
206
|
+
idempotencyKey: IdempotencyKey;
|
|
207
|
+
}>;
|
|
208
|
+
export type EntityDeleteInput = ResourceLifecycleInput & Readonly<{
|
|
209
|
+
idempotencyKey: IdempotencyKey;
|
|
210
|
+
}>;
|
|
211
|
+
/** A logical write retains its key, payload and edited revision on explicit resubmission. */
|
|
212
|
+
export interface EntityClient<Value, Create = Value, Patch = Partial<Value>> {
|
|
213
|
+
readonly definition: ResourceDefinition<Value, Create, Patch>;
|
|
214
|
+
readonly list: (query: EntityListQuery, options?: ResourceRequestOptions) => Promise<ResourceResult<EntityPage<Value>>>;
|
|
215
|
+
readonly get: (input: Readonly<{
|
|
216
|
+
id: ResourceRecordId;
|
|
217
|
+
}>, options?: ResourceRequestOptions) => Promise<ResourceResult<ResourceRecord<Value>>>;
|
|
218
|
+
readonly create: (input: EntityCreateInput<Create>) => Promise<ResourceResult<ResourceRecord<Value>>>;
|
|
219
|
+
readonly update: (input: EntityUpdateInput<Patch>) => Promise<ResourceResult<ResourceRecord<Value>>>;
|
|
220
|
+
readonly delete: (input: EntityDeleteInput) => Promise<ResourceResult<ResourceRecord<Value>>>;
|
|
221
|
+
}
|
|
222
|
+
export declare class ResourceQueryError extends Error {
|
|
223
|
+
readonly correlationId: string;
|
|
224
|
+
readonly resourceError: ResourceError;
|
|
225
|
+
constructor(correlationId: string, error: ResourceError);
|
|
226
|
+
}
|
|
227
|
+
export declare const unwrapResourceResult: <Value>(result: ResourceResult<Value>) => Value;
|
|
228
|
+
export type ResourceAuthState = Readonly<{
|
|
229
|
+
status: "authenticated";
|
|
230
|
+
}> | Readonly<{
|
|
231
|
+
status: "expired";
|
|
232
|
+
}> | Readonly<{
|
|
233
|
+
status: "forbidden";
|
|
234
|
+
}> | Readonly<{
|
|
235
|
+
status: "reauthentication_required";
|
|
236
|
+
}> | Readonly<{
|
|
237
|
+
status: "unauthenticated";
|
|
238
|
+
}>;
|
|
239
|
+
export declare const mapResourceAuthState: (source: FederatedAuthState | ResourceResult<unknown>) => ResourceAuthState;
|
|
240
|
+
export declare const hasResourceCapability: (capabilities: ResourceCapabilities, capability: keyof ResourceCapabilities) => boolean;
|
|
241
|
+
export type ResourceListSlotProps<Entity> = Readonly<{
|
|
242
|
+
getItemKey: (item: ResourceRecord<Entity>) => string;
|
|
243
|
+
items: readonly ResourceRecord<Entity>[];
|
|
244
|
+
renderItem: (item: ResourceRecord<Entity>) => ReactNode;
|
|
245
|
+
}>;
|
|
246
|
+
export type ResourcePaginationSlotProps = Readonly<{
|
|
247
|
+
currentPage?: number;
|
|
248
|
+
hasNextPage: boolean;
|
|
249
|
+
hasPreviousPage: boolean;
|
|
250
|
+
isPending: boolean;
|
|
251
|
+
onNext: () => void;
|
|
252
|
+
onPrevious: () => void;
|
|
253
|
+
}>;
|
|
254
|
+
export type ResourceStatusSlotProps = Readonly<{
|
|
255
|
+
authState: ResourceAuthState;
|
|
256
|
+
error?: Error;
|
|
257
|
+
pending: boolean;
|
|
258
|
+
}>;
|
|
259
|
+
export type ResourceListProps<Entity, Create, Update> = Readonly<{
|
|
260
|
+
client: ResourceClient<Entity, Create, Update>;
|
|
261
|
+
components: Readonly<{
|
|
262
|
+
List: ComponentType<ResourceListSlotProps<Entity>>;
|
|
263
|
+
Pagination?: ComponentType<ResourcePaginationSlotProps>;
|
|
264
|
+
Status?: ComponentType<ResourceStatusSlotProps>;
|
|
265
|
+
}>;
|
|
266
|
+
query: ResourceListQuery;
|
|
267
|
+
renderItem: (item: ResourceRecord<Entity>) => ReactNode;
|
|
268
|
+
onQueryChange?: (query: ResourceListQuery) => void;
|
|
269
|
+
}>;
|
|
270
|
+
export declare const ResourceList: <Entity, Create, Update>({ client, components, onQueryChange, query, renderItem }: ResourceListProps<Entity, Create, Update>) => import("react").JSX.Element;
|
|
271
|
+
export type ResourceCapabilityActionProps = Readonly<{
|
|
272
|
+
capability: keyof ResourceCapabilities;
|
|
273
|
+
children: ReactNode;
|
|
274
|
+
components: Readonly<{
|
|
275
|
+
Action: ComponentType<Readonly<{
|
|
276
|
+
children: ReactNode;
|
|
277
|
+
disabled: boolean;
|
|
278
|
+
}>>;
|
|
279
|
+
}>;
|
|
280
|
+
unsupported?: "disable" | "hide";
|
|
281
|
+
}>;
|
|
282
|
+
export declare const ResourceCapabilityAction: ({ capability, children, components, unsupported }: ResourceCapabilityActionProps) => import("react").JSX.Element | null;
|
|
283
|
+
export type ResourceFilterProps = Readonly<{
|
|
284
|
+
components: Readonly<{
|
|
285
|
+
Filter: ComponentType<Readonly<{
|
|
286
|
+
label: string;
|
|
287
|
+
onChange: (value: string) => void;
|
|
288
|
+
value: string;
|
|
289
|
+
}>>;
|
|
290
|
+
}>;
|
|
291
|
+
label?: string;
|
|
292
|
+
onQueryChange: (query: ResourceListQuery) => void;
|
|
293
|
+
query: ResourceListQuery;
|
|
294
|
+
}>;
|
|
295
|
+
declare const ResourceFilter$1: ({ components, label, onQueryChange, query }: ResourceFilterProps) => import("react").JSX.Element;
|
|
296
|
+
export type ResourcePaginationProps<Entity> = Readonly<{
|
|
297
|
+
components: Readonly<{
|
|
298
|
+
Pagination: ComponentType<ResourcePaginationSlotProps>;
|
|
299
|
+
}>;
|
|
300
|
+
isPending?: boolean;
|
|
301
|
+
onQueryChange: (query: ResourceListQuery) => void;
|
|
302
|
+
query: ResourceListQuery;
|
|
303
|
+
result: ResourceListResult<Entity>;
|
|
304
|
+
}>;
|
|
305
|
+
declare const ResourcePagination$1: <Entity>({ components, isPending, onQueryChange, query, result }: ResourcePaginationProps<Entity>) => import("react").JSX.Element;
|
|
306
|
+
export type ResourceTableColumn<Entity> = Readonly<{
|
|
307
|
+
id: string;
|
|
308
|
+
label: ReactNode;
|
|
309
|
+
render: (record: ResourceRecord<Entity>) => ReactNode;
|
|
310
|
+
}>;
|
|
311
|
+
export type ResourceTableProps<Entity, Create, Update> = Readonly<{
|
|
312
|
+
caption: ReactNode;
|
|
313
|
+
client: ResourceClient<Entity, Create, Update>;
|
|
314
|
+
columns: readonly ResourceTableColumn<Entity>[];
|
|
315
|
+
components: Readonly<{
|
|
316
|
+
Status?: ComponentType<ResourceStatusSlotProps>;
|
|
317
|
+
Table: ComponentType<Readonly<{
|
|
318
|
+
caption: ReactNode;
|
|
319
|
+
columns: readonly ResourceTableColumn<Entity>[];
|
|
320
|
+
getRowKey: (row: ResourceRecord<Entity>) => string;
|
|
321
|
+
renderCell: (row: ResourceRecord<Entity>, column: ResourceTableColumn<Entity>) => ReactNode;
|
|
322
|
+
rows: readonly ResourceRecord<Entity>[];
|
|
323
|
+
}>>;
|
|
324
|
+
}>;
|
|
325
|
+
query: ResourceListQuery;
|
|
326
|
+
}>;
|
|
327
|
+
export declare const ResourceTable: <Entity, Create, Update>({ caption, client, columns, components, query }: ResourceTableProps<Entity, Create, Update>) => import("react").JSX.Element;
|
|
328
|
+
export type ResourceLifecycleActionProps<Entity, Create, Update> = Readonly<{
|
|
329
|
+
children: ReactNode;
|
|
330
|
+
client: ResourceClient<Entity, Create, Update>;
|
|
331
|
+
components: Readonly<{
|
|
332
|
+
Action: ComponentType<Readonly<{
|
|
333
|
+
children: ReactNode;
|
|
334
|
+
disabled: boolean;
|
|
335
|
+
onClick: () => void;
|
|
336
|
+
pending: boolean;
|
|
337
|
+
}>>;
|
|
338
|
+
}>;
|
|
339
|
+
input: ResourceLifecycleInput;
|
|
340
|
+
operation: "hard_delete" | "restore" | "soft_delete";
|
|
341
|
+
unsupported?: "disable" | "hide";
|
|
342
|
+
}>;
|
|
343
|
+
export declare const ResourceLifecycleAction: <Entity, Create, Update>({ children, client, components, input, operation, unsupported }: ResourceLifecycleActionProps<Entity, Create, Update>) => import("react").JSX.Element | null;
|
|
344
|
+
export type ResourceProviderProps = Readonly<{
|
|
345
|
+
authState: ResourceAuthState;
|
|
346
|
+
capabilities: ResourceCapabilities;
|
|
347
|
+
children: ReactNode;
|
|
348
|
+
organizationId: string;
|
|
349
|
+
}>;
|
|
350
|
+
export declare const ResourceProvider: ({ authState, capabilities, children, organizationId }: ResourceProviderProps) => import("react").JSX.Element;
|
|
351
|
+
export type EntityIdentity = Readonly<{
|
|
352
|
+
sourceId: string;
|
|
353
|
+
applicationId: string;
|
|
354
|
+
userId: string;
|
|
355
|
+
organizationId: string;
|
|
356
|
+
}>;
|
|
357
|
+
export type EntitySourceState = Readonly<{
|
|
358
|
+
status: "authenticated";
|
|
359
|
+
identity: EntityIdentity;
|
|
360
|
+
}> | Readonly<{
|
|
361
|
+
status: "unauthenticated" | "expired" | "forbidden";
|
|
362
|
+
}>;
|
|
363
|
+
/** Configured authenticated client boundary. Snapshots are stable until identity changes. */
|
|
364
|
+
export interface EntitySource {
|
|
365
|
+
readonly getSnapshot: () => EntitySourceState;
|
|
366
|
+
readonly subscribe: (notify: () => void) => () => void;
|
|
367
|
+
readonly bind: <Value, Create, Patch>(contract: ResourceDefinition<Value, Create, Patch>) => EntityClient<Value, Create, Patch>;
|
|
368
|
+
}
|
|
369
|
+
export type DelegatedIdentity = Readonly<{
|
|
370
|
+
organizationId: string;
|
|
371
|
+
userId: string;
|
|
372
|
+
}>;
|
|
373
|
+
export type DelegatedEntitySourceOptions = Readonly<{
|
|
374
|
+
applicationId: string;
|
|
375
|
+
fetch?: ClientFetch;
|
|
376
|
+
getIdentity: () => DelegatedIdentity | null;
|
|
377
|
+
getStatus: () => string;
|
|
378
|
+
origin: string;
|
|
379
|
+
pathFor?: (contract: Readonly<{
|
|
380
|
+
id: string;
|
|
381
|
+
}>) => string;
|
|
382
|
+
sourceId?: string;
|
|
383
|
+
subscribe: (notify: () => void) => () => void;
|
|
384
|
+
}>;
|
|
385
|
+
/** Binds entity contracts to same-origin Resource proxy routes from the current session. */
|
|
386
|
+
export declare const createDelegatedEntitySource: (options: DelegatedEntitySourceOptions) => EntitySource;
|
|
387
|
+
export declare const useEntityList: <Value, Create, Patch>(contract: ResourceDefinition<Value, Create, Patch>, query: EntityListQuery) => {
|
|
388
|
+
authState: EntitySourceState;
|
|
389
|
+
capabilities: Readonly<{
|
|
390
|
+
create?: boolean;
|
|
391
|
+
delete?: boolean;
|
|
392
|
+
get?: boolean;
|
|
393
|
+
hardDelete?: boolean;
|
|
394
|
+
includeDeleted?: boolean;
|
|
395
|
+
restore?: boolean;
|
|
396
|
+
search: true;
|
|
397
|
+
softDelete?: boolean;
|
|
398
|
+
update?: boolean;
|
|
399
|
+
}>;
|
|
400
|
+
data: NoInfer<Readonly<{
|
|
401
|
+
items: readonly Readonly<{
|
|
402
|
+
deletedAt?: string;
|
|
403
|
+
id: ResourceRecordId;
|
|
404
|
+
revision: ResourceRevision;
|
|
405
|
+
value: Value;
|
|
406
|
+
}>[];
|
|
407
|
+
page: number;
|
|
408
|
+
pageSize: number;
|
|
409
|
+
pagination: "page";
|
|
410
|
+
totalItems: number;
|
|
411
|
+
totalPages: number;
|
|
412
|
+
}>> | undefined;
|
|
413
|
+
empty: boolean;
|
|
414
|
+
error: Error | null;
|
|
415
|
+
loading: boolean;
|
|
416
|
+
refresh: () => Promise<void>;
|
|
417
|
+
refreshing: boolean;
|
|
418
|
+
};
|
|
419
|
+
export declare const useEntityRecord: <Value, Create, Patch>(contract: ResourceDefinition<Value, Create, Patch>, input: Readonly<{
|
|
420
|
+
id: string;
|
|
421
|
+
}>) => {
|
|
422
|
+
authState: EntitySourceState;
|
|
423
|
+
capabilities: Readonly<{
|
|
424
|
+
create?: boolean;
|
|
425
|
+
delete?: boolean;
|
|
426
|
+
get?: boolean;
|
|
427
|
+
hardDelete?: boolean;
|
|
428
|
+
includeDeleted?: boolean;
|
|
429
|
+
restore?: boolean;
|
|
430
|
+
search: true;
|
|
431
|
+
softDelete?: boolean;
|
|
432
|
+
update?: boolean;
|
|
433
|
+
}>;
|
|
434
|
+
data: NoInfer<Readonly<{
|
|
435
|
+
deletedAt?: string;
|
|
436
|
+
id: ResourceRecordId;
|
|
437
|
+
revision: ResourceRevision;
|
|
438
|
+
value: Value;
|
|
439
|
+
}>> | undefined;
|
|
440
|
+
error: Error | null;
|
|
441
|
+
loading: boolean;
|
|
442
|
+
refresh: () => Promise<void>;
|
|
443
|
+
refreshing: boolean;
|
|
444
|
+
};
|
|
445
|
+
export declare const useEntityUpdate: <Value, Create, Patch>(contract: ResourceDefinition<Value, Create, Patch>, target: Readonly<{
|
|
446
|
+
id: string;
|
|
447
|
+
}>) => {
|
|
448
|
+
available: boolean;
|
|
449
|
+
data: Readonly<{
|
|
450
|
+
deletedAt?: string;
|
|
451
|
+
id: ResourceRecordId;
|
|
452
|
+
revision: ResourceRevision;
|
|
453
|
+
value: Value;
|
|
454
|
+
}> | undefined;
|
|
455
|
+
error: ResourceQueryError | null;
|
|
456
|
+
pending: boolean;
|
|
457
|
+
resubmit: () => Promise<ResourceResult<Readonly<{
|
|
458
|
+
deletedAt?: string;
|
|
459
|
+
id: ResourceRecordId;
|
|
460
|
+
revision: ResourceRevision;
|
|
461
|
+
value: Value;
|
|
462
|
+
}>>>;
|
|
463
|
+
status: "pending" | "success" | "idle" | "conflict" | "uncertain" | "rejected";
|
|
464
|
+
submit: (input: Omit<EntityUpdateInput<Patch>, "id" | "idempotencyKey">) => Promise<ResourceResult<Readonly<{
|
|
465
|
+
deletedAt?: string;
|
|
466
|
+
id: ResourceRecordId;
|
|
467
|
+
revision: ResourceRevision;
|
|
468
|
+
value: Value;
|
|
469
|
+
}>>>;
|
|
470
|
+
submitted: EntityUpdateInput<Patch> | undefined;
|
|
471
|
+
};
|
|
472
|
+
export declare const useEntityCreate: <Value, Create, Patch>(contract: ResourceDefinition<Value, Create, Patch>) => {
|
|
473
|
+
available: boolean;
|
|
474
|
+
data: Readonly<{
|
|
475
|
+
deletedAt?: string;
|
|
476
|
+
id: ResourceRecordId;
|
|
477
|
+
revision: ResourceRevision;
|
|
478
|
+
value: Value;
|
|
479
|
+
}> | undefined;
|
|
480
|
+
error: ResourceQueryError | null;
|
|
481
|
+
pending: boolean;
|
|
482
|
+
resubmit: () => Promise<ResourceResult<Readonly<{
|
|
483
|
+
deletedAt?: string;
|
|
484
|
+
id: ResourceRecordId;
|
|
485
|
+
revision: ResourceRevision;
|
|
486
|
+
value: Value;
|
|
487
|
+
}>>>;
|
|
488
|
+
status: "pending" | "success" | "idle" | "conflict" | "uncertain" | "rejected";
|
|
489
|
+
submit: (input: Omit<Readonly<{
|
|
490
|
+
idempotencyKey: IdempotencyKey;
|
|
491
|
+
value: Create;
|
|
492
|
+
}>, "idempotencyKey">) => Promise<ResourceResult<Readonly<{
|
|
493
|
+
deletedAt?: string;
|
|
494
|
+
id: ResourceRecordId;
|
|
495
|
+
revision: ResourceRevision;
|
|
496
|
+
value: Value;
|
|
497
|
+
}>>>;
|
|
498
|
+
submitted: Readonly<{
|
|
499
|
+
idempotencyKey: IdempotencyKey;
|
|
500
|
+
value: Create;
|
|
501
|
+
}> | undefined;
|
|
502
|
+
};
|
|
503
|
+
export declare const useEntityDelete: <Value, Create, Patch>(contract: ResourceDefinition<Value, Create, Patch>, target: Readonly<{
|
|
504
|
+
id: string;
|
|
505
|
+
}>) => {
|
|
506
|
+
available: boolean;
|
|
507
|
+
data: Readonly<{
|
|
508
|
+
deletedAt?: string;
|
|
509
|
+
id: ResourceRecordId;
|
|
510
|
+
revision: ResourceRevision;
|
|
511
|
+
value: Value;
|
|
512
|
+
}> | undefined;
|
|
513
|
+
error: ResourceQueryError | null;
|
|
514
|
+
pending: boolean;
|
|
515
|
+
resubmit: () => Promise<ResourceResult<Readonly<{
|
|
516
|
+
deletedAt?: string;
|
|
517
|
+
id: ResourceRecordId;
|
|
518
|
+
revision: ResourceRevision;
|
|
519
|
+
value: Value;
|
|
520
|
+
}>>>;
|
|
521
|
+
status: "pending" | "success" | "idle" | "conflict" | "uncertain" | "rejected";
|
|
522
|
+
submit: (input: Omit<EntityDeleteInput, "id" | "idempotencyKey">) => Promise<ResourceResult<Readonly<{
|
|
523
|
+
deletedAt?: string;
|
|
524
|
+
id: ResourceRecordId;
|
|
525
|
+
revision: ResourceRevision;
|
|
526
|
+
value: Value;
|
|
527
|
+
}>>>;
|
|
528
|
+
submitted: EntityDeleteInput | undefined;
|
|
529
|
+
};
|
|
530
|
+
export type ResourceValue = string | number | boolean | null | readonly ResourceValue[] | ResourceObject;
|
|
531
|
+
export interface ResourceObject {
|
|
532
|
+
readonly [key: string]: ResourceValue;
|
|
533
|
+
}
|
|
534
|
+
/** Display-ready controls. Schema inference and registry selection belong to the consumer. */
|
|
535
|
+
export type ResourceField = Readonly<{
|
|
536
|
+
name: string;
|
|
537
|
+
label: string;
|
|
538
|
+
control: "text" | "email" | "number" | "checkbox" | "date" | "datetime-local" | "select" | "custom";
|
|
539
|
+
required?: boolean;
|
|
540
|
+
readOnly?: boolean;
|
|
541
|
+
nullable?: boolean;
|
|
542
|
+
options?: readonly Readonly<{
|
|
543
|
+
label: string;
|
|
544
|
+
value: string | number | boolean;
|
|
545
|
+
}>[];
|
|
546
|
+
}>;
|
|
547
|
+
export type ResourceFieldControlProps = Readonly<{
|
|
548
|
+
field: ResourceField;
|
|
549
|
+
id: string;
|
|
550
|
+
value: ResourceValue | undefined;
|
|
551
|
+
disabled: boolean;
|
|
552
|
+
errorId?: string | undefined;
|
|
553
|
+
onChange: (value: ResourceValue) => void;
|
|
554
|
+
}>;
|
|
555
|
+
export type EntityFieldKey<Value> = Extract<keyof Value, string>;
|
|
556
|
+
export type EntityFieldConfig = Readonly<{
|
|
557
|
+
control?: ResourceField["control"] | string;
|
|
558
|
+
label: string;
|
|
559
|
+
readOnly?: boolean;
|
|
560
|
+
renderer?: string;
|
|
561
|
+
}>;
|
|
562
|
+
export type EntityViewVariant<Value> = Readonly<{
|
|
563
|
+
columns: readonly EntityFieldKey<Value>[];
|
|
564
|
+
}>;
|
|
565
|
+
export type EntityConfiguration<Value> = Readonly<{
|
|
566
|
+
fields: Readonly<Partial<Record<EntityFieldKey<Value>, EntityFieldConfig>>>;
|
|
567
|
+
forms: Readonly<{
|
|
568
|
+
create: Readonly<{
|
|
569
|
+
fields: readonly EntityFieldKey<Value>[];
|
|
570
|
+
}>;
|
|
571
|
+
update: Readonly<{
|
|
572
|
+
fields: readonly EntityFieldKey<Value>[];
|
|
573
|
+
}>;
|
|
574
|
+
}>;
|
|
575
|
+
list: Readonly<{
|
|
576
|
+
description?: EntityFieldKey<Value>;
|
|
577
|
+
title: EntityFieldKey<Value>;
|
|
578
|
+
}>;
|
|
579
|
+
table: Readonly<{
|
|
580
|
+
columns: readonly EntityFieldKey<Value>[];
|
|
581
|
+
variants?: Readonly<Record<string, EntityViewVariant<Value>>>;
|
|
582
|
+
}>;
|
|
583
|
+
}>;
|
|
584
|
+
export type EntityDeclaration<Value, Create, Patch> = Readonly<{
|
|
585
|
+
config: EntityConfiguration<Value>;
|
|
586
|
+
contract: ResourceDefinition<Value, Create, Patch>;
|
|
587
|
+
}>;
|
|
588
|
+
export type EntityControlRegistry = Readonly<Record<string, (props: ResourceFieldControlProps) => ReactNode>>;
|
|
589
|
+
export type EntityRendererRegistry<Value> = Readonly<Record<string, (input: Readonly<{
|
|
590
|
+
field: string;
|
|
591
|
+
record: ResourceRecord<Value>;
|
|
592
|
+
}>) => ReactNode>>;
|
|
593
|
+
export declare const defineEntity: <Value extends {
|
|
594
|
+
readonly [Key in keyof Value]: ResourceJsonValue;
|
|
595
|
+
}, Create, Patch>(declaration: EntityDeclaration<Value, Create, Patch>) => EntityDeclaration<Value, Create, Patch>;
|
|
596
|
+
export type JsonObject<Value = Readonly<Record<string, ResourceJsonValue>>> = {
|
|
597
|
+
readonly [Key in keyof Value]: ResourceJsonValue;
|
|
598
|
+
};
|
|
599
|
+
export type ViewStateProps = Readonly<{
|
|
600
|
+
namespace: string;
|
|
601
|
+
viewState?: "url";
|
|
602
|
+
}> | Readonly<{
|
|
603
|
+
namespace?: never;
|
|
604
|
+
viewState: "memory";
|
|
605
|
+
}>;
|
|
606
|
+
export type SharedViewProps<Value, Create, Patch> = Readonly<{
|
|
607
|
+
entity: EntityDeclaration<Value, Create, Patch>;
|
|
608
|
+
empty?: ReactNode;
|
|
609
|
+
pageSize?: number;
|
|
610
|
+
renderers?: EntityRendererRegistry<Value>;
|
|
611
|
+
variant?: string;
|
|
612
|
+
}>;
|
|
613
|
+
export type EntityTableProps<Value extends JsonObject<Value>, Create, Patch> = SharedViewProps<Value, Create, Patch> & ViewStateProps;
|
|
614
|
+
export type EntityListProps<Value extends JsonObject<Value>, Create, Patch> = SharedViewProps<Value, Create, Patch> & ViewStateProps;
|
|
615
|
+
export declare const EntityTable: <Value extends JsonObject<Value>, Create, Patch>(props: EntityTableProps<Value, Create, Patch>) => import("react").JSX.Element;
|
|
616
|
+
export declare const EntityList: <Value extends JsonObject<Value>, Create, Patch>(props: EntityListProps<Value, Create, Patch>) => import("react").JSX.Element;
|
|
617
|
+
export type SharedEntityFormProps<Value extends JsonObject<Value>, Create, Patch> = Readonly<{
|
|
618
|
+
controls?: EntityControlRegistry;
|
|
619
|
+
entity: EntityDeclaration<Value, Create, Patch>;
|
|
620
|
+
initialValues?: Readonly<Record<string, ResourceValue>>;
|
|
621
|
+
onCancel?: () => void;
|
|
622
|
+
onSuccess?: (record: ResourceRecord<Value>) => void;
|
|
623
|
+
}>;
|
|
624
|
+
export type EntityFormProps<Value extends JsonObject<Value>, Create, Patch> = (SharedEntityFormProps<Value, Create, Patch> & Readonly<{
|
|
625
|
+
mode: "create";
|
|
626
|
+
}>) | (SharedEntityFormProps<Value, Create, Patch> & Readonly<{
|
|
627
|
+
mode: "update";
|
|
628
|
+
record: ResourceRecord<Value>;
|
|
629
|
+
}>);
|
|
630
|
+
export declare const EntityForm: <Value extends JsonObject<Value>, Create, Patch>(props: EntityFormProps<Value, Create, Patch>) => import("react").JSX.Element;
|
|
631
|
+
export type EntityViewOptions = Readonly<{
|
|
632
|
+
contract?: ResourceDefinition<unknown, unknown, unknown>;
|
|
633
|
+
pageSize?: number;
|
|
634
|
+
}>;
|
|
635
|
+
export type EntityViewState = Readonly<{
|
|
636
|
+
filter: ResourceFilter | null;
|
|
637
|
+
page: number;
|
|
638
|
+
pageSize: number;
|
|
639
|
+
sort: readonly ResourceSort[];
|
|
640
|
+
textSearch: string;
|
|
641
|
+
}>;
|
|
642
|
+
export type EntityViewStateController = Readonly<{
|
|
643
|
+
query: EntityListQuery;
|
|
644
|
+
state: EntityViewState;
|
|
645
|
+
setFilter: (filter: ResourceFilter | null) => void;
|
|
646
|
+
setPage: (page: number) => void;
|
|
647
|
+
setPageSize: (pageSize: number) => void;
|
|
648
|
+
setSort: (sort: readonly ResourceSort[]) => void;
|
|
649
|
+
setTextSearch: (textSearch: string) => void;
|
|
650
|
+
}>;
|
|
651
|
+
export declare const useEntityViewState: (namespace: string, input?: EntityViewOptions) => EntityViewStateController;
|
|
652
|
+
export declare const useMemoryEntityViewState: (input?: Readonly<{
|
|
653
|
+
pageSize?: number;
|
|
654
|
+
}>) => EntityViewStateController;
|
|
655
|
+
export type ResourceLifecycleOperation = "hard_delete" | "restore" | "soft_delete";
|
|
656
|
+
|
|
657
|
+
export {
|
|
658
|
+
ResourceFilter$1 as ResourceFilter,
|
|
659
|
+
ResourcePagination$1 as ResourcePagination,
|
|
660
|
+
};
|
|
661
|
+
|
|
662
|
+
export {};
|