@oddington/sdk 0.1.19 → 0.1.21
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 +87 -63
- package/dist/browser.js +584 -474
- package/dist/index.js +6 -6
- package/dist/types/packages/sdk/src/public.d.ts +87 -35
- package/dist/types/packages/sdk/src/routine-definition-types.d.ts +53 -19
- package/dist/types/shared/app-descriptor.d.ts +21 -0
- package/dist/types/shared/app-routine-contract.d.ts +1 -0
- package/dist/types/shared/inbox-contract.d.ts +5 -1
- package/dist/types/shared/inbox-member-contract.d.ts +2 -2
- package/dist/types/shared/inbox-member-types.d.ts +5 -1
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@ import type { AskInput, CapturedRecords, DigestInput, InboxFile, PublicationRequ
|
|
|
2
2
|
import type { FileAddOptions } from '../../../shared/inbox-files.js';
|
|
3
3
|
import type { RecordReadInput } from '../../../shared/record-capture.js';
|
|
4
4
|
import type { RecordDeleteRequest, RecordUpdateRequest, RecordWriteRequest } from '../../../shared/record-write.js';
|
|
5
|
-
export type { RoutineSchema, RoutineSchemaValue, RoutineDefinition, RoutineInput, RoutineRuntime, RoutineArtifactInput, RoutineArtifact } from './routine-definition-types.js';
|
|
5
|
+
export type { RoutineSchema, RoutineSchemaValue, RoutineDefinition, RoutineInput, RoutineRuntime, RoutineAccess, RoutineCapabilities, RoutineStep, RoutineSteps, RoutineStepInput, RoutineStepResult, RoutineStepOutput, RoutineArtifactInput, RoutineArtifact } from './routine-definition-types.js';
|
|
6
6
|
export declare const defineRoutine: import('./routine-definition-types.js').DefineRoutine;
|
|
7
7
|
export declare const schema: import('./routine-definition-types.js').RoutineSchemaBuilders;
|
|
8
8
|
export declare const file: import('./routine-definition-types.js').RoutineFileSchema;
|
|
@@ -84,53 +84,105 @@ export declare const auth: {
|
|
|
84
84
|
/** Customer-owned module augmentation supplies types, never runtime authority. */
|
|
85
85
|
export interface AppRoutineTypes {
|
|
86
86
|
}
|
|
87
|
-
|
|
87
|
+
/** Generated app declarations derive inference directly from the authored export. */
|
|
88
|
+
export type RoutineAppBinding<Definition> = Definition extends import('./routine-definition-types.js').RoutineDefinition<infer Input extends import('./routine-definition-types.js').RoutineSchema<unknown> | undefined, infer Steps extends import('./routine-definition-types.js').RoutineSteps, infer Result extends import('./routine-definition-types.js').RoutineSchema<unknown> | undefined, any, any, any> ? Omit<AppRoutineBinding<import('./routine-definition-types.js').RoutineSchemaValue<Input>, import('./routine-definition-types.js').RoutineSchemaValue<Result>, {
|
|
89
|
+
[Key in keyof Steps]: Awaited<ReturnType<Steps[Key]['run']>>;
|
|
90
|
+
}>, 'run'> & {
|
|
91
|
+
run(...input: Input extends undefined | import('./routine-definition-types.js').RoutineSchema<unknown, true> ? [input?: Input extends undefined ? Record<string, never> : import('./routine-definition-types.js').RoutineSchemaValue<Input>] : [input: import('./routine-definition-types.js').RoutineSchemaValue<Input>]): Promise<AppRoutineHandle<import('./routine-definition-types.js').RoutineSchemaValue<Result>, {
|
|
92
|
+
[Key in keyof Steps]: Awaited<ReturnType<Steps[Key]['run']>>;
|
|
93
|
+
}>>;
|
|
94
|
+
} : never;
|
|
95
|
+
export type AppRoutineErrorReason = 'authority_unavailable' | 'execution_unavailable' | 'invalid_input';
|
|
88
96
|
export declare class AppRoutineError extends Error {
|
|
89
97
|
readonly reason: AppRoutineErrorReason;
|
|
90
98
|
constructor(reason: AppRoutineErrorReason);
|
|
91
99
|
}
|
|
92
|
-
export type
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
+
export type AppRoutineHandle<Result, Steps> = {
|
|
101
|
+
current(): Promise<Omit<RunSummary, 'result'> & {
|
|
102
|
+
result?: Result;
|
|
103
|
+
}>;
|
|
104
|
+
watch(): AsyncIterable<Omit<RunSummary, 'result'> & {
|
|
105
|
+
result?: Result;
|
|
106
|
+
}>;
|
|
107
|
+
step<Key extends Extract<keyof Steps, string>>(id: Key): Promise<Omit<StepDetail, 'summary' | 'data'> & (Steps[Key] extends {
|
|
108
|
+
summary: infer Summary;
|
|
109
|
+
data?: infer Data;
|
|
110
|
+
} ? {
|
|
111
|
+
summary?: Summary;
|
|
112
|
+
data?: Data;
|
|
100
113
|
} : {
|
|
101
|
-
summary
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
type: 'finished';
|
|
114
|
+
summary?: unknown;
|
|
115
|
+
data?: unknown;
|
|
116
|
+
})>;
|
|
117
|
+
publish(): Promise<Omit<RunSummary, 'result'> & {
|
|
118
|
+
result?: Result;
|
|
119
|
+
}>;
|
|
120
|
+
};
|
|
121
|
+
export type LocalPublication = {
|
|
122
|
+
state: 'not_needed' | 'ready' | 'published';
|
|
123
|
+
} | {
|
|
112
124
|
state: 'failed';
|
|
113
|
-
|
|
125
|
+
message: string;
|
|
126
|
+
};
|
|
127
|
+
export type StepDetail = {
|
|
128
|
+
id: string;
|
|
129
|
+
title: string;
|
|
130
|
+
status: 'pending' | 'running' | 'completed' | 'failed' | 'skipped';
|
|
131
|
+
startedAt?: string;
|
|
132
|
+
finishedAt?: string;
|
|
133
|
+
summary?: unknown;
|
|
134
|
+
data?: unknown;
|
|
135
|
+
};
|
|
136
|
+
export type RunSummary = {
|
|
137
|
+
id: string;
|
|
138
|
+
routine: string;
|
|
139
|
+
placement: 'local' | 'remote';
|
|
140
|
+
status: 'queued' | 'running' | 'succeeded' | 'failed';
|
|
141
|
+
createdAt: string;
|
|
142
|
+
startedAt?: string;
|
|
143
|
+
finishedAt?: string;
|
|
144
|
+
steps: Array<Omit<StepDetail, 'data'> & {
|
|
145
|
+
detailAvailable: boolean;
|
|
146
|
+
}>;
|
|
147
|
+
result?: unknown;
|
|
148
|
+
failure?: {
|
|
149
|
+
message: string;
|
|
150
|
+
};
|
|
151
|
+
publication?: LocalPublication;
|
|
152
|
+
};
|
|
153
|
+
export type RunHandle = {
|
|
154
|
+
current(): Promise<RunSummary>;
|
|
155
|
+
watch(): AsyncIterable<RunSummary>;
|
|
156
|
+
step(id: string): Promise<StepDetail>;
|
|
157
|
+
publish(): Promise<RunSummary>;
|
|
158
|
+
};
|
|
159
|
+
export type RoutineReadiness = {
|
|
160
|
+
state: 'ready';
|
|
161
|
+
placement: 'local' | 'remote';
|
|
114
162
|
} | {
|
|
115
|
-
|
|
116
|
-
|
|
163
|
+
state: 'unavailable';
|
|
164
|
+
reason: 'not_deployed' | 'definition_invalid' | 'capability_unavailable';
|
|
165
|
+
message: string;
|
|
117
166
|
};
|
|
118
|
-
export type
|
|
119
|
-
|
|
120
|
-
|
|
167
|
+
export type RoutineDescription = Omit<import('../../../shared/app-descriptor.js').AppRoutineDescriptor, 'connections'> & {
|
|
168
|
+
connections: Array<{
|
|
169
|
+
id: string;
|
|
170
|
+
provider: string;
|
|
171
|
+
name: string;
|
|
172
|
+
available: boolean;
|
|
173
|
+
}>;
|
|
174
|
+
readiness: RoutineReadiness;
|
|
121
175
|
};
|
|
122
176
|
export type AppRoutineBinding<Input, Result, Steps> = {
|
|
123
|
-
|
|
124
|
-
available: true;
|
|
125
|
-
steps: Extract<keyof Steps, string>[];
|
|
126
|
-
} | {
|
|
127
|
-
available: false;
|
|
128
|
-
reason: 'not_enabled' | 'authority_unavailable' | 'execution_unavailable';
|
|
129
|
-
}>;
|
|
177
|
+
describe(): Promise<RoutineDescription>;
|
|
130
178
|
run(input: Input): Promise<AppRoutineHandle<Result, Steps>>;
|
|
131
|
-
|
|
179
|
+
runs: {
|
|
180
|
+
list(): Promise<RunSummary[]>;
|
|
181
|
+
get(id: string): Promise<RunHandle>;
|
|
182
|
+
};
|
|
132
183
|
};
|
|
133
184
|
export declare const app: {
|
|
185
|
+
listRoutines(): Promise<RoutineDescription[]>;
|
|
134
186
|
routines: AppRoutineTypes;
|
|
135
187
|
};
|
|
136
188
|
/** A declared stage without a summary takes no second argument. */
|
|
@@ -2,14 +2,37 @@ import type { AppValueSchema } from '../../../shared/app-routine-contract.js';
|
|
|
2
2
|
import type { File } from '../../../shared/files-contract.js';
|
|
3
3
|
import type { Connections } from '../../../shared/airtable-contract.js';
|
|
4
4
|
import type { DataRepository } from '../../../shared/data-contract.js';
|
|
5
|
+
import type { Handler } from '../../../shared/inbox-contract.js';
|
|
5
6
|
import type { files, RoutinePublicationClient } from './public.js';
|
|
6
7
|
declare const valueType: unique symbol;
|
|
7
8
|
/** Serializable declaration; the phantom type never carries authority. */
|
|
8
|
-
export type RoutineSchema<Value> = AppValueSchema & {
|
|
9
|
+
export type RoutineSchema<Value, Defaulted extends boolean = boolean> = AppValueSchema & {
|
|
9
10
|
readonly [valueType]?: Value;
|
|
11
|
+
default(value: Value): RoutineSchema<Value, true>;
|
|
12
|
+
readonly hasDefault?: Defaulted;
|
|
10
13
|
};
|
|
11
14
|
export type RoutineSchemaValue<Schema> = Schema extends RoutineSchema<infer Value> ? Value : undefined;
|
|
12
|
-
export type
|
|
15
|
+
export type RoutineAccess = {
|
|
16
|
+
readonly repositories?: Readonly<Record<string, 'read' | 'write'>>;
|
|
17
|
+
readonly connections?: readonly string[];
|
|
18
|
+
readonly models?: readonly string[];
|
|
19
|
+
readonly files?: 'read' | 'read-write';
|
|
20
|
+
readonly publish?: readonly ('asks' | 'digests')[];
|
|
21
|
+
};
|
|
22
|
+
export type RoutineStepOutput = {
|
|
23
|
+
summary: unknown;
|
|
24
|
+
data: unknown;
|
|
25
|
+
};
|
|
26
|
+
export type RoutineStep<Input = any, Output extends RoutineStepOutput = RoutineStepOutput, Access extends RoutineAccess = RoutineAccess> = {
|
|
27
|
+
readonly title: string;
|
|
28
|
+
readonly run: (input: Input, os: RoutineCapabilities<Access>) => Output | Promise<Output>;
|
|
29
|
+
};
|
|
30
|
+
export type RoutineSteps = Record<string, {
|
|
31
|
+
readonly title: string;
|
|
32
|
+
readonly run: (...args: any[]) => RoutineStepOutput | Promise<RoutineStepOutput>;
|
|
33
|
+
}>;
|
|
34
|
+
export type RoutineStepInput<Step extends RoutineSteps[string]> = Parameters<Step['run']>[0];
|
|
35
|
+
export type RoutineStepResult<Step extends RoutineSteps[string]> = Awaited<ReturnType<Step['run']>>;
|
|
13
36
|
export type RoutineInput<Value> = Value extends object ? {
|
|
14
37
|
readonly [Key in keyof Value]: RoutineInput<Value[Key]>;
|
|
15
38
|
} : Value;
|
|
@@ -29,45 +52,56 @@ export type RoutineArtifact = Readonly<{
|
|
|
29
52
|
size: number;
|
|
30
53
|
sha256: string;
|
|
31
54
|
}>;
|
|
32
|
-
|
|
55
|
+
type RepositoryFor<Mode> = Mode extends 'write' ? DataRepository : Omit<DataRepository, 'changes'>;
|
|
56
|
+
type ConnectionName<Access extends RoutineAccess> = Access['connections'] extends readonly (infer Name)[] ? Name extends `airtable/${infer Alias}` ? Alias : never : never;
|
|
57
|
+
export type RoutineCapabilities<Access extends RoutineAccess> = {
|
|
33
58
|
readonly run: {
|
|
34
59
|
readonly id: string;
|
|
35
60
|
};
|
|
36
61
|
readonly data: {
|
|
37
|
-
repository(name:
|
|
62
|
+
repository<Name extends Extract<keyof Access['repositories'], string>>(name: Name): RepositoryFor<NonNullable<Access['repositories']>[Name]>;
|
|
63
|
+
};
|
|
64
|
+
readonly files: Access['files'] extends 'read-write' ? typeof files : Access['files'] extends 'read' ? Pick<typeof files, 'get' | 'read'> : {};
|
|
65
|
+
readonly connections: {
|
|
66
|
+
airtable(name: ConnectionName<Access>): ReturnType<Connections['airtable']>;
|
|
38
67
|
};
|
|
39
|
-
readonly
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
step<Key extends Extract<keyof Steps, string>>(id: Key, ...summary: Steps[Key] extends null ? [] : [summary: RoutineSchemaValue<Steps[Key]>]): Promise<void>;
|
|
68
|
+
readonly inbox: Pick<RoutinePublicationClient, (Access['publish'] extends readonly string[] ? 'asks' extends Access['publish'][number] ? 'publishAsk' : never : never) | (Access['publish'] extends readonly string[] ? 'digests' extends Access['publish'][number] ? 'publishDigest' : never : never)>;
|
|
69
|
+
};
|
|
70
|
+
export type RoutineRuntime<Steps extends RoutineSteps, Access extends RoutineAccess = RoutineAccess> = RoutineCapabilities<Access> & {
|
|
71
|
+
step<Key extends Extract<keyof Steps, string>>(id: Key, ...input: Parameters<Steps[Key]['run']> extends [] ? [] : [input: RoutineInput<RoutineStepInput<Steps[Key]>>]): Promise<RoutineStepResult<Steps[Key]>>;
|
|
44
72
|
};
|
|
45
|
-
export type RoutineDefinition<Input extends RoutineSchema<unknown> | undefined, Steps extends RoutineSteps, Result extends RoutineSchema<unknown> | undefined> = {
|
|
73
|
+
export type RoutineDefinition<Input extends RoutineSchema<unknown> | undefined = RoutineSchema<unknown> | undefined, Steps extends RoutineSteps = RoutineSteps, Result extends RoutineSchema<unknown> | undefined = RoutineSchema<unknown> | undefined, Access extends RoutineAccess = RoutineAccess, Responses extends readonly Handler<any>[] = readonly Handler<any>[], Id extends string = string> = {
|
|
74
|
+
readonly id: Id;
|
|
75
|
+
readonly title?: string;
|
|
46
76
|
readonly input?: Input;
|
|
47
77
|
readonly steps?: Steps;
|
|
48
78
|
readonly result?: Result;
|
|
49
|
-
readonly
|
|
79
|
+
readonly access?: Access;
|
|
80
|
+
readonly responses?: Responses;
|
|
81
|
+
readonly run: (input: RoutineInput<Input extends undefined ? Record<string, never> : RoutineSchemaValue<Input>>, os: RoutineRuntime<Steps, Access>) => Result extends undefined ? void | Promise<void> : RoutineSchemaValue<Result> | Promise<RoutineSchemaValue<Result>>;
|
|
50
82
|
};
|
|
51
|
-
export type DefineRoutine = <Input extends RoutineSchema<unknown> | undefined = undefined, const Steps extends
|
|
83
|
+
export type DefineRoutine = <const Id extends string, Input extends RoutineSchema<unknown> | undefined = undefined, const Access extends RoutineAccess = {}, const Steps extends Record<string, RoutineStep<any, RoutineStepOutput, Access>> = {}, Result extends RoutineSchema<unknown> | undefined = undefined, const Responses extends readonly Handler<any>[] = readonly []>(definition: RoutineDefinition<Input, Steps, Result, Access, Responses, Id> & {
|
|
84
|
+
steps?: Steps & Record<string, RoutineStep<any, RoutineStepOutput, Access>>;
|
|
85
|
+
}) => RoutineDefinition<Input, Steps, Result, Access, Responses, Id>;
|
|
52
86
|
export type RoutineSchemaBuilders = {
|
|
53
87
|
object<const Properties extends Record<string, RoutineSchema<unknown>>>(properties: Properties): RoutineSchema<{
|
|
54
88
|
[Key in keyof Properties]: RoutineSchemaValue<Properties[Key]>;
|
|
55
|
-
}>;
|
|
89
|
+
}, false>;
|
|
56
90
|
array<Item extends RoutineSchema<unknown>>(items: Item, options: {
|
|
57
91
|
maxItems: number;
|
|
58
|
-
}): RoutineSchema<RoutineSchemaValue<Item>[]>;
|
|
92
|
+
}): RoutineSchema<RoutineSchemaValue<Item>[], false>;
|
|
59
93
|
string(options?: {
|
|
60
94
|
maxLength?: number;
|
|
61
|
-
}): RoutineSchema<string>;
|
|
95
|
+
}): RoutineSchema<string, false>;
|
|
62
96
|
integer(options?: {
|
|
63
97
|
minimum?: number;
|
|
64
98
|
maximum?: number;
|
|
65
|
-
}): RoutineSchema<number>;
|
|
99
|
+
}): RoutineSchema<number, false>;
|
|
66
100
|
number(options?: {
|
|
67
101
|
minimum?: number;
|
|
68
102
|
maximum?: number;
|
|
69
|
-
}): RoutineSchema<number>;
|
|
70
|
-
boolean(): RoutineSchema<boolean>;
|
|
103
|
+
}): RoutineSchema<number, false>;
|
|
104
|
+
boolean(): RoutineSchema<boolean, false>;
|
|
71
105
|
};
|
|
72
|
-
export type RoutineFileSchema = () => RoutineSchema<File>;
|
|
106
|
+
export type RoutineFileSchema = () => RoutineSchema<File, false>;
|
|
73
107
|
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AppValueSchema } from './app-routine-contract.js';
|
|
2
|
+
/** Build-time structure only. Runtime readiness and availability belong to hosts. */
|
|
3
|
+
export type AppRoutineDescriptor = {
|
|
4
|
+
id: string;
|
|
5
|
+
title?: string;
|
|
6
|
+
input: AppValueSchema & {
|
|
7
|
+
default?: unknown;
|
|
8
|
+
};
|
|
9
|
+
connections: {
|
|
10
|
+
id: string;
|
|
11
|
+
provider: string;
|
|
12
|
+
name: string;
|
|
13
|
+
}[];
|
|
14
|
+
steps: {
|
|
15
|
+
id: string;
|
|
16
|
+
title: string;
|
|
17
|
+
}[];
|
|
18
|
+
};
|
|
19
|
+
export type AppDescriptor = {
|
|
20
|
+
routines: AppRoutineDescriptor[];
|
|
21
|
+
};
|
|
@@ -44,6 +44,7 @@ export declare class AppRoutineContractError extends Error {
|
|
|
44
44
|
readonly code: 'invalid_contract' | 'invalid_value';
|
|
45
45
|
constructor(code: 'invalid_contract' | 'invalid_value');
|
|
46
46
|
}
|
|
47
|
+
export declare function isAppRoutineName(value: unknown): value is string;
|
|
47
48
|
/** One operation owns the property budget across input, result and all summaries. */
|
|
48
49
|
export declare function parseAppRoutineContract(value: unknown): AppRoutineContract;
|
|
49
50
|
export declare function validateRoutineSchemaValue(schema: AppValueSchema, value: unknown): void;
|
|
@@ -310,7 +310,11 @@ export declare function validateRecordReference(value: unknown): RecordReference
|
|
|
310
310
|
export declare function validateRecordSource(value: unknown): RecordSource;
|
|
311
311
|
export declare function validateResponseDefinition(value: unknown): ResponseDefinition;
|
|
312
312
|
export declare function validateResponse(definition: unknown, value: unknown): QuestionResponse;
|
|
313
|
-
export declare function defineHandler<Input extends JsonValue>(value: Handler<Input>
|
|
313
|
+
export declare function defineHandler<Input extends JsonValue, const Id extends string = string>(value: Handler<Input> & {
|
|
314
|
+
id: Id;
|
|
315
|
+
}): Handler<Input> & {
|
|
316
|
+
id: Id;
|
|
317
|
+
};
|
|
314
318
|
export declare function respond<Input extends JsonValue>(handler: Handler<Input>, input: Input): HandlerReference;
|
|
315
319
|
export declare function question(value: QuestionInput): Question;
|
|
316
320
|
/** Structural validation is shared. Registered view/handler availability,
|
|
@@ -11,8 +11,8 @@ export declare const INBOX_LOCAL_INPUT_BYTES: number;
|
|
|
11
11
|
export declare const INBOX_UUID: RegExp;
|
|
12
12
|
export type InboxOperation = 'current' | 'items.list' | 'items.read' | 'items.see' | 'items.markDigestRead' | 'items.rename' | 'items.setLifecycle' | 'items.listRecipientCandidates' | 'items.addRecipient' | 'questions.list' | 'questions.answer' | 'questions.searchRecords' | 'files.read';
|
|
13
13
|
export declare function isAppQuestionOperation(operation: InboxOperation): boolean;
|
|
14
|
-
/** Closed wire vocabulary
|
|
15
|
-
export declare function parseInboxRequest(value: unknown): {
|
|
14
|
+
/** Closed wire vocabulary. Hosts select the listing mode; input cannot select it. */
|
|
15
|
+
export declare function parseInboxRequest(value: unknown, questionListContext?: 'local' | 'hosted'): {
|
|
16
16
|
operation: InboxOperation;
|
|
17
17
|
input: Record<string, unknown>;
|
|
18
18
|
};
|
|
@@ -161,6 +161,10 @@ export type InboxSearchInput = ItemRevision & {
|
|
|
161
161
|
query: string;
|
|
162
162
|
selected?: RecordReference;
|
|
163
163
|
};
|
|
164
|
+
/** Hosted listing relevance only; local listing uses its bound declaration. */
|
|
165
|
+
export type InboxQuestionListInput = {
|
|
166
|
+
routines: readonly string[];
|
|
167
|
+
};
|
|
164
168
|
export interface InboxMember {
|
|
165
169
|
current(): Promise<InboxCurrent>;
|
|
166
170
|
items: {
|
|
@@ -181,7 +185,7 @@ export interface InboxMember {
|
|
|
181
185
|
}): Promise<RecipientAddition>;
|
|
182
186
|
};
|
|
183
187
|
questions: {
|
|
184
|
-
list(): Promise<AnswerableQuestion[]>;
|
|
188
|
+
list(input?: InboxQuestionListInput): Promise<AnswerableQuestion[]>;
|
|
185
189
|
answer(input: InboxAnswerInput): Promise<ResponseAcceptance>;
|
|
186
190
|
searchRecords(input: InboxSearchInput): Promise<RecordSelectionResult>;
|
|
187
191
|
};
|