@beeable/sdk 0.6.0 → 0.7.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/dist/app-runtime/data.d.ts +137 -0
- package/dist/app-runtime/data.d.ts.map +1 -0
- package/dist/app-runtime/data.js +360 -0
- package/dist/app-runtime/data.js.map +1 -0
- package/dist/app-runtime/index.d.ts +37 -27
- package/dist/app-runtime/index.d.ts.map +1 -1
- package/dist/app-runtime/index.js +64 -67
- package/dist/app-runtime/index.js.map +1 -1
- package/dist/app-runtime/typed-api.d.ts +196 -0
- package/dist/app-runtime/typed-api.d.ts.map +1 -0
- package/dist/app-runtime/typed-api.js +233 -0
- package/dist/app-runtime/typed-api.js.map +1 -0
- package/dist/app-sdk.d.ts +2 -2
- package/dist/app-sdk.js +2 -2
- package/dist/generated/apps/apps.d.ts +1 -1
- package/dist/generated/apps/apps.js +1 -1
- package/dist/generated/schemas/appTemplateResponseDto.d.ts +5 -3
- package/dist/generated/schemas/appTemplateResponseDto.d.ts.map +1 -1
- package/dist/generated/schemas/appTemplateResponseDto.js +84 -0
- package/dist/generated/schemas/appTemplateResponseDto.js.map +1 -1
- package/dist/generated/schemas/chatCompletionDto.d.ts +7 -6
- package/dist/generated/schemas/chatCompletionDto.d.ts.map +1 -1
- package/dist/generated/schemas/chatCompletionDtoToolChoice.d.ts +5 -3
- package/dist/generated/schemas/chatCompletionDtoToolChoice.d.ts.map +1 -1
- package/dist/generated/schemas/chatCompletionDtoToolChoice.js +0 -84
- package/dist/generated/schemas/chatCompletionDtoToolChoice.js.map +1 -1
- package/dist/generated/schemas/chatContentPartDto.d.ts +103 -0
- package/dist/generated/schemas/chatContentPartDto.d.ts.map +1 -0
- package/dist/generated/schemas/chatContentPartDto.js +2 -0
- package/dist/generated/schemas/chatContentPartDto.js.map +1 -0
- package/dist/generated/schemas/chatContentPartDtoContent.d.ts +91 -0
- package/dist/generated/schemas/chatContentPartDtoContent.d.ts.map +1 -0
- package/dist/generated/schemas/chatContentPartDtoContent.js +86 -0
- package/dist/generated/schemas/chatContentPartDtoContent.js.map +1 -0
- package/dist/generated/schemas/chatContentPartDtoImageUrl.d.ts +91 -0
- package/dist/generated/schemas/chatContentPartDtoImageUrl.d.ts.map +1 -0
- package/dist/generated/schemas/chatContentPartDtoImageUrl.js +86 -0
- package/dist/generated/schemas/chatContentPartDtoImageUrl.js.map +1 -0
- package/dist/generated/schemas/chatContentPartDtoInput.d.ts +91 -0
- package/dist/generated/schemas/chatContentPartDtoInput.d.ts.map +1 -0
- package/dist/generated/schemas/chatContentPartDtoInput.js +86 -0
- package/dist/generated/schemas/chatContentPartDtoInput.js.map +1 -0
- package/dist/generated/schemas/chatContentPartDtoType.d.ts +95 -0
- package/dist/generated/schemas/chatContentPartDtoType.d.ts.map +1 -0
- package/dist/generated/schemas/chatContentPartDtoType.js +92 -0
- package/dist/generated/schemas/chatContentPartDtoType.js.map +1 -0
- package/dist/generated/schemas/chatMessageDto.d.ts +3 -2
- package/dist/generated/schemas/chatMessageDto.d.ts.map +1 -1
- package/dist/generated/schemas/chatMessageDtoContent.d.ts +3 -4
- package/dist/generated/schemas/chatMessageDtoContent.d.ts.map +1 -1
- package/dist/generated/schemas/chatMessageDtoContent.js +0 -84
- package/dist/generated/schemas/chatMessageDtoContent.js.map +1 -1
- package/dist/generated/schemas/chatResponseFormatDto.d.ts +89 -0
- package/dist/generated/schemas/chatResponseFormatDto.d.ts.map +1 -0
- package/dist/generated/schemas/chatResponseFormatDto.js +2 -0
- package/dist/generated/schemas/chatResponseFormatDto.js.map +1 -0
- package/dist/generated/schemas/chatResponseFormatDtoType.d.ts +90 -0
- package/dist/generated/schemas/chatResponseFormatDtoType.d.ts.map +1 -0
- package/dist/generated/schemas/chatResponseFormatDtoType.js +90 -0
- package/dist/generated/schemas/chatResponseFormatDtoType.js.map +1 -0
- package/dist/generated/schemas/chatStreamOptionsDto.d.ts +89 -0
- package/dist/generated/schemas/chatStreamOptionsDto.d.ts.map +1 -0
- package/dist/generated/schemas/chatStreamOptionsDto.js +86 -0
- package/dist/generated/schemas/chatStreamOptionsDto.js.map +1 -0
- package/dist/generated/schemas/chatToolCallDto.d.ts +92 -0
- package/dist/generated/schemas/chatToolCallDto.d.ts.map +1 -0
- package/dist/generated/schemas/chatToolCallDto.js +2 -0
- package/dist/generated/schemas/chatToolCallDto.js.map +1 -0
- package/dist/generated/schemas/chatToolCallDtoType.d.ts +89 -0
- package/dist/generated/schemas/chatToolCallDtoType.d.ts.map +1 -0
- package/dist/generated/schemas/chatToolCallDtoType.js +89 -0
- package/dist/generated/schemas/chatToolCallDtoType.js.map +1 -0
- package/dist/generated/schemas/chatToolCallFunctionDto.d.ts +90 -0
- package/dist/generated/schemas/chatToolCallFunctionDto.d.ts.map +1 -0
- package/dist/generated/schemas/chatToolCallFunctionDto.js +86 -0
- package/dist/generated/schemas/chatToolCallFunctionDto.js.map +1 -0
- package/dist/generated/schemas/chatToolChoiceDto.d.ts +91 -0
- package/dist/generated/schemas/chatToolChoiceDto.d.ts.map +1 -0
- package/dist/generated/schemas/chatToolChoiceDto.js +2 -0
- package/dist/generated/schemas/chatToolChoiceDto.js.map +1 -0
- package/dist/generated/schemas/chatToolChoiceDtoType.d.ts +89 -0
- package/dist/generated/schemas/chatToolChoiceDtoType.d.ts.map +1 -0
- package/dist/generated/schemas/chatToolChoiceDtoType.js +89 -0
- package/dist/generated/schemas/chatToolChoiceDtoType.js.map +1 -0
- package/dist/generated/schemas/chatToolChoiceFunctionDto.d.ts +88 -0
- package/dist/generated/schemas/chatToolChoiceFunctionDto.d.ts.map +1 -0
- package/dist/generated/schemas/chatToolChoiceFunctionDto.js +86 -0
- package/dist/generated/schemas/chatToolChoiceFunctionDto.js.map +1 -0
- package/dist/generated/schemas/chatToolDto.d.ts +91 -0
- package/dist/generated/schemas/chatToolDto.d.ts.map +1 -0
- package/dist/generated/schemas/chatToolDto.js +2 -0
- package/dist/generated/schemas/chatToolDto.js.map +1 -0
- package/dist/generated/schemas/chatToolDtoType.d.ts +89 -0
- package/dist/generated/schemas/chatToolDtoType.d.ts.map +1 -0
- package/dist/generated/schemas/chatToolDtoType.js +89 -0
- package/dist/generated/schemas/chatToolDtoType.js.map +1 -0
- package/dist/generated/schemas/chatToolFunctionDto.d.ts +92 -0
- package/dist/generated/schemas/chatToolFunctionDto.d.ts.map +1 -0
- package/dist/generated/schemas/chatToolFunctionDto.js +2 -0
- package/dist/generated/schemas/chatToolFunctionDto.js.map +1 -0
- package/dist/generated/schemas/chatToolFunctionDtoParameters.d.ts +91 -0
- package/dist/generated/schemas/chatToolFunctionDtoParameters.d.ts.map +1 -0
- package/dist/generated/schemas/chatToolFunctionDtoParameters.js +86 -0
- package/dist/generated/schemas/chatToolFunctionDtoParameters.js.map +1 -0
- package/dist/generated/schemas/connectIntegrationDto.d.ts +1 -1
- package/dist/generated/schemas/connectIntegrationDto.d.ts.map +1 -1
- package/dist/generated/schemas/connectIntegrationDtoConfig.d.ts +1 -1
- package/dist/generated/schemas/createTaskDto.d.ts +1 -1
- package/dist/generated/schemas/createTaskDto.d.ts.map +1 -1
- package/dist/generated/schemas/createTaskDtoInput.d.ts +1 -1
- package/dist/generated/schemas/eventExecutionResponseDto.d.ts +1 -0
- package/dist/generated/schemas/eventExecutionResponseDto.d.ts.map +1 -1
- package/dist/generated/schemas/eventExecutionResponseDtoTriggerPayload.d.ts +3 -0
- package/dist/generated/schemas/eventExecutionResponseDtoTriggerPayload.d.ts.map +1 -1
- package/dist/generated/schemas/eventExecutionStepResponseDto.d.ts +8 -2
- package/dist/generated/schemas/eventExecutionStepResponseDto.d.ts.map +1 -1
- package/dist/generated/schemas/eventExecutionStepResponseDtoInputPayload.d.ts +1 -0
- package/dist/generated/schemas/eventExecutionStepResponseDtoInputPayload.d.ts.map +1 -1
- package/dist/generated/schemas/eventExecutionStepResponseDtoTranslatedPayload.d.ts +1 -0
- package/dist/generated/schemas/eventExecutionStepResponseDtoTranslatedPayload.d.ts.map +1 -1
- package/dist/generated/schemas/flowStepDtoNext.d.ts +2 -1
- package/dist/generated/schemas/flowStepDtoNext.d.ts.map +1 -1
- package/dist/generated/schemas/flowStepDtoNext.js +0 -84
- package/dist/generated/schemas/flowStepDtoNext.js.map +1 -1
- package/dist/generated/schemas/index.d.ts +28 -0
- package/dist/generated/schemas/index.d.ts.map +1 -1
- package/dist/generated/schemas/index.js +28 -0
- package/dist/generated/schemas/index.js.map +1 -1
- package/dist/generated/schemas/inlineWidgetResponseDto.d.ts +6 -5
- package/dist/generated/schemas/inlineWidgetResponseDto.d.ts.map +1 -1
- package/dist/generated/schemas/inlineWidgetResponseDto.js +84 -0
- package/dist/generated/schemas/inlineWidgetResponseDto.js.map +1 -1
- package/dist/generated/schemas/integrationActionDto.d.ts +97 -0
- package/dist/generated/schemas/integrationActionDto.d.ts.map +1 -0
- package/dist/generated/schemas/integrationActionDto.js +2 -0
- package/dist/generated/schemas/integrationActionDto.js.map +1 -0
- package/dist/generated/schemas/integrationActionDtoInputSchema.d.ts +91 -0
- package/dist/generated/schemas/integrationActionDtoInputSchema.d.ts.map +1 -0
- package/dist/generated/schemas/integrationActionDtoInputSchema.js +86 -0
- package/dist/generated/schemas/integrationActionDtoInputSchema.js.map +1 -0
- package/dist/generated/schemas/integrationActionDtoOutputSchema.d.ts +91 -0
- package/dist/generated/schemas/integrationActionDtoOutputSchema.d.ts.map +1 -0
- package/dist/generated/schemas/integrationActionDtoOutputSchema.js +86 -0
- package/dist/generated/schemas/integrationActionDtoOutputSchema.js.map +1 -0
- package/dist/generated/schemas/integrationTypeInfoDto.d.ts +4 -4
- package/dist/generated/schemas/integrationTypeInfoDto.d.ts.map +1 -1
- package/dist/generated/schemas/integrationTypeInfoDtoConfigSchema.d.ts +1 -1
- package/dist/generated/schemas/memoryEdgeResponseDto.d.ts +4 -1
- package/dist/generated/schemas/memoryEdgeResponseDto.d.ts.map +1 -1
- package/dist/generated/schemas/memoryEdgeResponseDtoMetadata.d.ts +1 -0
- package/dist/generated/schemas/memoryEdgeResponseDtoMetadata.d.ts.map +1 -1
- package/dist/generated/schemas/messageAttachmentResponseDto.d.ts +2 -4
- package/dist/generated/schemas/messageAttachmentResponseDto.d.ts.map +1 -1
- package/dist/generated/schemas/messageAttachmentResponseDto.js +84 -0
- package/dist/generated/schemas/messageAttachmentResponseDto.js.map +1 -1
- package/dist/generated/schemas/messageResponseDto.d.ts +3 -3
- package/dist/generated/schemas/messageResponseDto.d.ts.map +1 -1
- package/dist/generated/schemas/orchestratorTaskResponseDto.d.ts +5 -1
- package/dist/generated/schemas/orchestratorTaskResponseDto.d.ts.map +1 -1
- package/dist/generated/schemas/orchestratorTaskResponseDtoInput.d.ts +3 -0
- package/dist/generated/schemas/orchestratorTaskResponseDtoInput.d.ts.map +1 -1
- package/dist/generated/schemas/orchestratorTaskResponseDtoResult.d.ts +1 -0
- package/dist/generated/schemas/orchestratorTaskResponseDtoResult.d.ts.map +1 -1
- package/dist/generated/schemas/organizationDetailResponseDto.d.ts +1 -0
- package/dist/generated/schemas/organizationDetailResponseDto.d.ts.map +1 -1
- package/dist/generated/schemas/organizationDetailResponseDtoSettings.d.ts +3 -0
- package/dist/generated/schemas/organizationDetailResponseDtoSettings.d.ts.map +1 -1
- package/dist/generated/schemas/organizationResponseDto.d.ts +1 -0
- package/dist/generated/schemas/organizationResponseDto.d.ts.map +1 -1
- package/dist/generated/schemas/organizationResponseDtoSettings.d.ts +3 -0
- package/dist/generated/schemas/organizationResponseDtoSettings.d.ts.map +1 -1
- package/dist/generated/schemas/pendingClarificationFieldDto.d.ts +103 -0
- package/dist/generated/schemas/pendingClarificationFieldDto.d.ts.map +1 -0
- package/dist/generated/schemas/pendingClarificationFieldDto.js +2 -0
- package/dist/generated/schemas/pendingClarificationFieldDto.js.map +1 -0
- package/dist/generated/schemas/pendingClarificationFieldDtoDefaultValue.d.ts +89 -0
- package/dist/generated/schemas/pendingClarificationFieldDtoDefaultValue.d.ts.map +1 -0
- package/dist/generated/schemas/pendingClarificationFieldDtoDefaultValue.js +86 -0
- package/dist/generated/schemas/pendingClarificationFieldDtoDefaultValue.js.map +1 -0
- package/dist/generated/schemas/pendingClarificationFieldDtoType.d.ts +96 -0
- package/dist/generated/schemas/pendingClarificationFieldDtoType.d.ts.map +1 -0
- package/dist/generated/schemas/pendingClarificationFieldDtoType.js +93 -0
- package/dist/generated/schemas/pendingClarificationFieldDtoType.js.map +1 -0
- package/dist/generated/schemas/pendingClarificationResponseDto.d.ts +3 -4
- package/dist/generated/schemas/pendingClarificationResponseDto.d.ts.map +1 -1
- package/dist/generated/schemas/publishEventDto.d.ts +1 -1
- package/dist/generated/schemas/publishEventDto.d.ts.map +1 -1
- package/dist/generated/schemas/publishEventDtoPayload.d.ts +1 -1
- package/dist/generated/schemas/recordUsageDto.d.ts +1 -1
- package/dist/generated/schemas/recordUsageDto.d.ts.map +1 -1
- package/dist/generated/schemas/recordUsageDtoMetadata.d.ts +1 -1
- package/dist/generated/schemas/reportWidgetErrorDto.d.ts +4 -1
- package/dist/generated/schemas/reportWidgetErrorDto.d.ts.map +1 -1
- package/dist/generated/schemas/reportWidgetErrorDtoBody.d.ts +3 -2
- package/dist/generated/schemas/reportWidgetErrorDtoBody.d.ts.map +1 -1
- package/dist/generated/schemas/submitClarificationDto.d.ts +1 -1
- package/dist/generated/schemas/submitClarificationDto.d.ts.map +1 -1
- package/dist/generated/schemas/submitClarificationDtoValues.d.ts +2 -2
- package/dist/generated/schemas/submitClarificationDtoValues.d.ts.map +1 -1
- package/dist/generated/schemas/toolHistoryEntryDto.d.ts +102 -0
- package/dist/generated/schemas/toolHistoryEntryDto.d.ts.map +1 -0
- package/dist/generated/schemas/toolHistoryEntryDto.js +2 -0
- package/dist/generated/schemas/toolHistoryEntryDto.js.map +1 -0
- package/dist/generated/schemas/toolHistoryEntryDtoInput.d.ts +91 -0
- package/dist/generated/schemas/toolHistoryEntryDtoInput.d.ts.map +1 -0
- package/dist/generated/schemas/toolHistoryEntryDtoInput.js +86 -0
- package/dist/generated/schemas/toolHistoryEntryDtoInput.js.map +1 -0
- package/dist/generated/schemas/toolHistoryEntryDtoResult.d.ts +91 -0
- package/dist/generated/schemas/toolHistoryEntryDtoResult.d.ts.map +1 -0
- package/dist/generated/schemas/toolHistoryEntryDtoResult.js +86 -0
- package/dist/generated/schemas/toolHistoryEntryDtoResult.js.map +1 -0
- package/dist/generated/schemas/toolHistoryEntryDtoType.d.ts +93 -0
- package/dist/generated/schemas/toolHistoryEntryDtoType.d.ts.map +1 -0
- package/dist/generated/schemas/toolHistoryEntryDtoType.js +90 -0
- package/dist/generated/schemas/toolHistoryEntryDtoType.js.map +1 -0
- package/dist/generated/schemas/updateAdminOrganizationDto.d.ts +1 -1
- package/dist/generated/schemas/updateAdminOrganizationDto.d.ts.map +1 -1
- package/dist/generated/schemas/updateAdminOrganizationDtoSettings.d.ts +1 -1
- package/dist/generated/schemas/updateColleagueDto.d.ts +30 -18
- package/dist/generated/schemas/updateColleagueDto.d.ts.map +1 -1
- package/dist/generated/schemas/updateFlowDto.d.ts +5 -3
- package/dist/generated/schemas/updateFlowDto.d.ts.map +1 -1
- package/dist/generated/schemas/updateIntegrationDto.d.ts +1 -1
- package/dist/generated/schemas/updateIntegrationDto.d.ts.map +1 -1
- package/dist/generated/schemas/updateIntegrationDtoConfig.d.ts +1 -1
- package/dist/generated/schemas/updateOrganizationDto.d.ts +1 -0
- package/dist/generated/schemas/updateOrganizationDto.d.ts.map +1 -1
- package/dist/generated/schemas/updateOrganizationDtoSettings.d.ts +3 -0
- package/dist/generated/schemas/updateOrganizationDtoSettings.d.ts.map +1 -1
- package/dist/generated/schemas/updatedOrganizationResponseDto.d.ts +1 -0
- package/dist/generated/schemas/updatedOrganizationResponseDto.d.ts.map +1 -1
- package/dist/generated/schemas/updatedOrganizationResponseDtoSettings.d.ts +3 -0
- package/dist/generated/schemas/updatedOrganizationResponseDtoSettings.d.ts.map +1 -1
- package/dist/generated/schemas/widgetSqlDto.d.ts +1 -1
- package/dist/generated/schemas/widgetSqlDto.d.ts.map +1 -1
- package/dist/generated/schemas/widgetSqlDtoParamsItem.d.ts +4 -3
- package/dist/generated/schemas/widgetSqlDtoParamsItem.d.ts.map +1 -1
- package/package.json +6 -1
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Beeable SDK — app-runtime data layer.
|
|
3
|
+
*
|
|
4
|
+
* Unified `collection<T>()` API with two backends, chosen automatically
|
|
5
|
+
* by the environment the app is running in:
|
|
6
|
+
*
|
|
7
|
+
* • In production (inside the Beeable app-runtime container):
|
|
8
|
+
* `FetchCollection<T>` hits a private REST surface on the runtime
|
|
9
|
+
* at `/_internal/collection/:name/*`. The runtime validates every
|
|
10
|
+
* POST/PATCH against the app's declared manifest schema (Ajv), and
|
|
11
|
+
* the routes are **not** emitted into the app's openapi.json —
|
|
12
|
+
* which means the orchestrator's tool catalog and other apps'
|
|
13
|
+
* generated clients can't see them. This is the private surface
|
|
14
|
+
* for the app's own frontend.
|
|
15
|
+
*
|
|
16
|
+
* • In Lovable's preview (or any browser context with no Beeable
|
|
17
|
+
* server reachable): `IndexedDBCollection<T>` stores the same
|
|
18
|
+
* shape in browser-local IndexedDB. This lets Lovable build and
|
|
19
|
+
* iterate on a real, working app without needing a backend.
|
|
20
|
+
*
|
|
21
|
+
* Both backends satisfy the same `Collection<T>` interface, so the
|
|
22
|
+
* rest of your app code is backend-agnostic.
|
|
23
|
+
*
|
|
24
|
+
* import { collection } from '@beeable/sdk/app-runtime/data';
|
|
25
|
+
*
|
|
26
|
+
* interface Note extends Record<string, unknown> {
|
|
27
|
+
* title: string;
|
|
28
|
+
* body: string;
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* const notes = collection<Note>('notes', {
|
|
32
|
+
* version: 1,
|
|
33
|
+
* normalize: (doc) => doc as Note,
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* await notes.insert({ title: 'hi', body: 'there' });
|
|
37
|
+
* await notes.find({ title: 'hi' });
|
|
38
|
+
*
|
|
39
|
+
* Design rationale
|
|
40
|
+
* ----------------
|
|
41
|
+
*
|
|
42
|
+
* The pattern evolved from an earlier unified auto-CRUD setup that
|
|
43
|
+
* exposed collection routes as part of the app's public HTTP surface.
|
|
44
|
+
* That turned into a footgun — the LLM saw POST tools with
|
|
45
|
+
* `additionalProperties: true` and produced ghost records with no
|
|
46
|
+
* required fields. We fixed it by making apps own their entire
|
|
47
|
+
* public HTTP surface (every public operation declared with an
|
|
48
|
+
* `@openapi` JSDoc block) and keeping auto-CRUD for the app's own
|
|
49
|
+
* frontend only, on a path the tool catalog never sees.
|
|
50
|
+
*/
|
|
51
|
+
/**
|
|
52
|
+
* Stored document shape — `id`, `created_at`, `updated_at` are set by
|
|
53
|
+
* the runtime / IndexedDB store; callers provide the rest.
|
|
54
|
+
*/
|
|
55
|
+
export type CollectionDocument<T> = T & {
|
|
56
|
+
id: string;
|
|
57
|
+
created_at: string;
|
|
58
|
+
updated_at: string;
|
|
59
|
+
};
|
|
60
|
+
export interface CollectionOptions<T> {
|
|
61
|
+
/**
|
|
62
|
+
* Increment when the document shape changes. The `normalize`
|
|
63
|
+
* function is expected to handle migrations from older versions.
|
|
64
|
+
*/
|
|
65
|
+
version: number;
|
|
66
|
+
/**
|
|
67
|
+
* Called on every read before the doc is returned to the caller.
|
|
68
|
+
* Use it to upgrade old rows to the current shape.
|
|
69
|
+
*/
|
|
70
|
+
normalize: (doc: Record<string, unknown>) => T;
|
|
71
|
+
}
|
|
72
|
+
export interface Collection<T> {
|
|
73
|
+
find(filter?: Partial<T>): Promise<CollectionDocument<T>[]>;
|
|
74
|
+
findOne(id: string): Promise<CollectionDocument<T> | null>;
|
|
75
|
+
insert(doc: T): Promise<CollectionDocument<T>>;
|
|
76
|
+
update(id: string, changes: Partial<T>): Promise<CollectionDocument<T> | null>;
|
|
77
|
+
remove(id: string): Promise<boolean>;
|
|
78
|
+
count(filter?: Partial<T>): Promise<number>;
|
|
79
|
+
}
|
|
80
|
+
declare class FetchCollection<T> implements Collection<T> {
|
|
81
|
+
private readonly base;
|
|
82
|
+
constructor(name: string);
|
|
83
|
+
private request;
|
|
84
|
+
find(filter?: Partial<T>): Promise<CollectionDocument<T>[]>;
|
|
85
|
+
findOne(id: string): Promise<CollectionDocument<T> | null>;
|
|
86
|
+
insert(doc: T): Promise<CollectionDocument<T>>;
|
|
87
|
+
update(id: string, changes: Partial<T>): Promise<CollectionDocument<T> | null>;
|
|
88
|
+
remove(id: string): Promise<boolean>;
|
|
89
|
+
count(filter?: Partial<T>): Promise<number>;
|
|
90
|
+
}
|
|
91
|
+
declare class IndexedDBCollection<T> implements Collection<T> {
|
|
92
|
+
private readonly name;
|
|
93
|
+
private readonly options;
|
|
94
|
+
constructor(name: string, options: CollectionOptions<T>);
|
|
95
|
+
private store;
|
|
96
|
+
private toDocument;
|
|
97
|
+
private matchesFilter;
|
|
98
|
+
find(filter?: Partial<T>): Promise<CollectionDocument<T>[]>;
|
|
99
|
+
findOne(id: string): Promise<CollectionDocument<T> | null>;
|
|
100
|
+
insert(doc: T): Promise<CollectionDocument<T>>;
|
|
101
|
+
update(id: string, changes: Partial<T>): Promise<CollectionDocument<T> | null>;
|
|
102
|
+
remove(id: string): Promise<boolean>;
|
|
103
|
+
count(filter?: Partial<T>): Promise<number>;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Open a typed collection. Returns a backend that matches the current
|
|
107
|
+
* environment — no server means IndexedDB, server present means
|
|
108
|
+
* FetchCollection routed through the private `/_internal/collection/*`
|
|
109
|
+
* surface.
|
|
110
|
+
*
|
|
111
|
+
* For the production path to work, the app's `manifest.json` must
|
|
112
|
+
* declare the collection under `collections` with a JSON Schema so
|
|
113
|
+
* the runtime can validate writes:
|
|
114
|
+
*
|
|
115
|
+
* {
|
|
116
|
+
* "collections": {
|
|
117
|
+
* "notes": {
|
|
118
|
+
* "version": 1,
|
|
119
|
+
* "schema": {
|
|
120
|
+
* "type": "object",
|
|
121
|
+
* "required": ["title"],
|
|
122
|
+
* "properties": {
|
|
123
|
+
* "title": { "type": "string" },
|
|
124
|
+
* "body": { "type": "string" }
|
|
125
|
+
* },
|
|
126
|
+
* "additionalProperties": false
|
|
127
|
+
* }
|
|
128
|
+
* }
|
|
129
|
+
* }
|
|
130
|
+
* }
|
|
131
|
+
*
|
|
132
|
+
* Writes that fail schema validation are rejected with HTTP 400 — so
|
|
133
|
+
* even on the private surface, callers can't produce ghost records.
|
|
134
|
+
*/
|
|
135
|
+
export declare function collection<T>(name: string, options: CollectionOptions<T>): Collection<T>;
|
|
136
|
+
export { FetchCollection, IndexedDBCollection };
|
|
137
|
+
//# sourceMappingURL=data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../src/app-runtime/data.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AA0BH;;;GAGG;AACH,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI,CAAC,GAAG;IACtC,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,WAAW,iBAAiB,CAAC,CAAC;IAClC;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;CAChD;AAED,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B,IAAI,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAC5D,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IA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AC,CAAC,CAAC;IAEjD,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO;gBADP,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC;YAGlC,KAAK;IAKnB,OAAO,CAAC,UAAU;IAUlB,OAAO,CAAC,aAAa;IASf,IAAI,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,CAAC;IAS3D,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAM1D,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC;IAa9C,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAiB9E,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAQpC,KAAK,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;CAQlD;AAID;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAC1B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAC5B,UAAU,CAAC,CAAC,CAAC,CAKf;AAGD,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Beeable SDK — app-runtime data layer.
|
|
3
|
+
*
|
|
4
|
+
* Unified `collection<T>()` API with two backends, chosen automatically
|
|
5
|
+
* by the environment the app is running in:
|
|
6
|
+
*
|
|
7
|
+
* • In production (inside the Beeable app-runtime container):
|
|
8
|
+
* `FetchCollection<T>` hits a private REST surface on the runtime
|
|
9
|
+
* at `/_internal/collection/:name/*`. The runtime validates every
|
|
10
|
+
* POST/PATCH against the app's declared manifest schema (Ajv), and
|
|
11
|
+
* the routes are **not** emitted into the app's openapi.json —
|
|
12
|
+
* which means the orchestrator's tool catalog and other apps'
|
|
13
|
+
* generated clients can't see them. This is the private surface
|
|
14
|
+
* for the app's own frontend.
|
|
15
|
+
*
|
|
16
|
+
* • In Lovable's preview (or any browser context with no Beeable
|
|
17
|
+
* server reachable): `IndexedDBCollection<T>` stores the same
|
|
18
|
+
* shape in browser-local IndexedDB. This lets Lovable build and
|
|
19
|
+
* iterate on a real, working app without needing a backend.
|
|
20
|
+
*
|
|
21
|
+
* Both backends satisfy the same `Collection<T>` interface, so the
|
|
22
|
+
* rest of your app code is backend-agnostic.
|
|
23
|
+
*
|
|
24
|
+
* import { collection } from '@beeable/sdk/app-runtime/data';
|
|
25
|
+
*
|
|
26
|
+
* interface Note extends Record<string, unknown> {
|
|
27
|
+
* title: string;
|
|
28
|
+
* body: string;
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* const notes = collection<Note>('notes', {
|
|
32
|
+
* version: 1,
|
|
33
|
+
* normalize: (doc) => doc as Note,
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* await notes.insert({ title: 'hi', body: 'there' });
|
|
37
|
+
* await notes.find({ title: 'hi' });
|
|
38
|
+
*
|
|
39
|
+
* Design rationale
|
|
40
|
+
* ----------------
|
|
41
|
+
*
|
|
42
|
+
* The pattern evolved from an earlier unified auto-CRUD setup that
|
|
43
|
+
* exposed collection routes as part of the app's public HTTP surface.
|
|
44
|
+
* That turned into a footgun — the LLM saw POST tools with
|
|
45
|
+
* `additionalProperties: true` and produced ghost records with no
|
|
46
|
+
* required fields. We fixed it by making apps own their entire
|
|
47
|
+
* public HTTP surface (every public operation declared with an
|
|
48
|
+
* `@openapi` JSDoc block) and keeping auto-CRUD for the app's own
|
|
49
|
+
* frontend only, on a path the tool catalog never sees.
|
|
50
|
+
*/
|
|
51
|
+
// ── Environment detection ──────────────────────────────────────────
|
|
52
|
+
// Same logic as in ./index.ts — duplicated here so this module is
|
|
53
|
+
// self-contained (bundled via esbuild into app-runtime/src/public/
|
|
54
|
+
// beeable-sdk.js the same way).
|
|
55
|
+
function detectHasServer() {
|
|
56
|
+
if (typeof window === 'undefined')
|
|
57
|
+
return false;
|
|
58
|
+
if (window.__BEEABLE_APP_ID__)
|
|
59
|
+
return true;
|
|
60
|
+
const proxyMatch = window.location.pathname.match(/^\/api\/apps\/[^/]+\/proxy\b/);
|
|
61
|
+
if (proxyMatch)
|
|
62
|
+
return true;
|
|
63
|
+
const directMatch = window.location.pathname.match(/\/apps\/([^/]+)/);
|
|
64
|
+
return !!directMatch;
|
|
65
|
+
}
|
|
66
|
+
function currentAppId() {
|
|
67
|
+
if (typeof window === 'undefined')
|
|
68
|
+
return 'lovable-dev';
|
|
69
|
+
if (window.__BEEABLE_APP_ID__)
|
|
70
|
+
return window.__BEEABLE_APP_ID__;
|
|
71
|
+
const direct = window.location.pathname.match(/\/apps\/([^/]+)/);
|
|
72
|
+
if (direct)
|
|
73
|
+
return direct[1];
|
|
74
|
+
return 'lovable-dev';
|
|
75
|
+
}
|
|
76
|
+
// ── Shared helpers ─────────────────────────────────────────────────
|
|
77
|
+
function nowIso() {
|
|
78
|
+
return new Date().toISOString();
|
|
79
|
+
}
|
|
80
|
+
function newId() {
|
|
81
|
+
// 16 bytes of hex, matches the server-side SQLiteCollection id format.
|
|
82
|
+
const bytes = new Uint8Array(16);
|
|
83
|
+
crypto.getRandomValues(bytes);
|
|
84
|
+
let hex = '';
|
|
85
|
+
for (const b of bytes)
|
|
86
|
+
hex += b.toString(16).padStart(2, '0');
|
|
87
|
+
return hex;
|
|
88
|
+
}
|
|
89
|
+
// ── FetchCollection — production (talks to the runtime) ────────────
|
|
90
|
+
class FetchCollection {
|
|
91
|
+
base;
|
|
92
|
+
constructor(name) {
|
|
93
|
+
// The proxy path-transparently forwards /api/apps/:id/proxy/… to
|
|
94
|
+
// the runtime's /apps/:id/api/…, and the iframe loads under that
|
|
95
|
+
// proxy prefix, so relative URLs Just Work. `_internal/collection`
|
|
96
|
+
// is a private path — never declared in openapi.json.
|
|
97
|
+
this.base = `/api/apps/${encodeURIComponent(currentAppId())}/proxy/_internal/collection/${encodeURIComponent(name)}`;
|
|
98
|
+
}
|
|
99
|
+
async request(path, init) {
|
|
100
|
+
const res = await fetch(`${this.base}${path}`, {
|
|
101
|
+
...init,
|
|
102
|
+
headers: {
|
|
103
|
+
'Content-Type': 'application/json',
|
|
104
|
+
...(init?.headers ?? {}),
|
|
105
|
+
},
|
|
106
|
+
credentials: 'include',
|
|
107
|
+
});
|
|
108
|
+
if (!res.ok) {
|
|
109
|
+
let detail = '';
|
|
110
|
+
try {
|
|
111
|
+
const body = (await res.json());
|
|
112
|
+
detail = body.error ?? '';
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
/* not JSON */
|
|
116
|
+
}
|
|
117
|
+
throw new Error(`${init?.method ?? 'GET'} ${this.base}${path}: ${res.status}${detail ? ` ${detail}` : ''}`);
|
|
118
|
+
}
|
|
119
|
+
if (res.status === 204)
|
|
120
|
+
return undefined;
|
|
121
|
+
return (await res.json());
|
|
122
|
+
}
|
|
123
|
+
async find(filter) {
|
|
124
|
+
const params = filter
|
|
125
|
+
? '?' +
|
|
126
|
+
new URLSearchParams(Object.entries(filter).map(([k, v]) => [
|
|
127
|
+
`filter.${k}`,
|
|
128
|
+
String(v),
|
|
129
|
+
])).toString()
|
|
130
|
+
: '';
|
|
131
|
+
return this.request(`${params}`);
|
|
132
|
+
}
|
|
133
|
+
async findOne(id) {
|
|
134
|
+
try {
|
|
135
|
+
return await this.request(`/${encodeURIComponent(id)}`);
|
|
136
|
+
}
|
|
137
|
+
catch (err) {
|
|
138
|
+
if (err instanceof Error && err.message.includes(' 404'))
|
|
139
|
+
return null;
|
|
140
|
+
throw err;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
async insert(doc) {
|
|
144
|
+
return this.request(``, {
|
|
145
|
+
method: 'POST',
|
|
146
|
+
body: JSON.stringify(doc),
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
async update(id, changes) {
|
|
150
|
+
try {
|
|
151
|
+
return await this.request(`/${encodeURIComponent(id)}`, {
|
|
152
|
+
method: 'PATCH',
|
|
153
|
+
body: JSON.stringify(changes),
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
catch (err) {
|
|
157
|
+
if (err instanceof Error && err.message.includes(' 404'))
|
|
158
|
+
return null;
|
|
159
|
+
throw err;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
async remove(id) {
|
|
163
|
+
try {
|
|
164
|
+
await this.request(`/${encodeURIComponent(id)}`, { method: 'DELETE' });
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
catch (err) {
|
|
168
|
+
if (err instanceof Error && err.message.includes(' 404'))
|
|
169
|
+
return false;
|
|
170
|
+
throw err;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
async count(filter) {
|
|
174
|
+
const params = filter
|
|
175
|
+
? '?' +
|
|
176
|
+
new URLSearchParams(Object.entries(filter).map(([k, v]) => [
|
|
177
|
+
`filter.${k}`,
|
|
178
|
+
String(v),
|
|
179
|
+
])).toString()
|
|
180
|
+
: '';
|
|
181
|
+
const res = await this.request(`/_count${params}`);
|
|
182
|
+
return res.count;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
const DB_NAME = 'beeable-collections';
|
|
186
|
+
const DB_VERSION = 1;
|
|
187
|
+
// Open once per session; lazily create the object store for the
|
|
188
|
+
// collection on the first read/write that touches it.
|
|
189
|
+
let _dbPromise = null;
|
|
190
|
+
async function openDb(storeName) {
|
|
191
|
+
const existing = await existingDb();
|
|
192
|
+
if (existing.objectStoreNames.contains(storeName))
|
|
193
|
+
return existing;
|
|
194
|
+
// Need to upgrade to add the object store for this collection.
|
|
195
|
+
existing.close();
|
|
196
|
+
_dbPromise = null;
|
|
197
|
+
const currentVersion = existing.version;
|
|
198
|
+
return new Promise((resolve, reject) => {
|
|
199
|
+
const req = indexedDB.open(DB_NAME, currentVersion + 1);
|
|
200
|
+
req.onupgradeneeded = () => {
|
|
201
|
+
const db = req.result;
|
|
202
|
+
if (!db.objectStoreNames.contains(storeName)) {
|
|
203
|
+
db.createObjectStore(storeName, { keyPath: 'id' });
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
req.onsuccess = () => {
|
|
207
|
+
_dbPromise = Promise.resolve(req.result);
|
|
208
|
+
resolve(req.result);
|
|
209
|
+
};
|
|
210
|
+
req.onerror = () => reject(req.error);
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
async function existingDb() {
|
|
214
|
+
if (_dbPromise)
|
|
215
|
+
return _dbPromise;
|
|
216
|
+
_dbPromise = new Promise((resolve, reject) => {
|
|
217
|
+
const req = indexedDB.open(DB_NAME, DB_VERSION);
|
|
218
|
+
req.onupgradeneeded = () => {
|
|
219
|
+
// First open — no stores yet; they're created on demand above.
|
|
220
|
+
};
|
|
221
|
+
req.onsuccess = () => resolve(req.result);
|
|
222
|
+
req.onerror = () => reject(req.error);
|
|
223
|
+
});
|
|
224
|
+
return _dbPromise;
|
|
225
|
+
}
|
|
226
|
+
function promisifyRequest(req) {
|
|
227
|
+
return new Promise((resolve, reject) => {
|
|
228
|
+
req.onsuccess = () => resolve(req.result);
|
|
229
|
+
req.onerror = () => reject(req.error);
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
class IndexedDBCollection {
|
|
233
|
+
name;
|
|
234
|
+
options;
|
|
235
|
+
constructor(name, options) {
|
|
236
|
+
this.name = name;
|
|
237
|
+
this.options = options;
|
|
238
|
+
}
|
|
239
|
+
async store(mode) {
|
|
240
|
+
const db = await openDb(this.name);
|
|
241
|
+
return db.transaction(this.name, mode).objectStore(this.name);
|
|
242
|
+
}
|
|
243
|
+
toDocument(row) {
|
|
244
|
+
const data = this.options.normalize(row.data);
|
|
245
|
+
return {
|
|
246
|
+
...data,
|
|
247
|
+
id: row.id,
|
|
248
|
+
created_at: row.created_at,
|
|
249
|
+
updated_at: row.updated_at,
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
matchesFilter(doc, filter) {
|
|
253
|
+
if (!filter)
|
|
254
|
+
return true;
|
|
255
|
+
const record = doc;
|
|
256
|
+
for (const [key, value] of Object.entries(filter)) {
|
|
257
|
+
if (record[key] !== value)
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
262
|
+
async find(filter) {
|
|
263
|
+
const store = await this.store('readonly');
|
|
264
|
+
const rows = (await promisifyRequest(store.getAll()));
|
|
265
|
+
const all = rows.map((r) => this.toDocument(r));
|
|
266
|
+
const filtered = all.filter((d) => this.matchesFilter(d, filter));
|
|
267
|
+
filtered.sort((a, b) => (b.created_at ?? '').localeCompare(a.created_at ?? ''));
|
|
268
|
+
return filtered;
|
|
269
|
+
}
|
|
270
|
+
async findOne(id) {
|
|
271
|
+
const store = await this.store('readonly');
|
|
272
|
+
const row = (await promisifyRequest(store.get(id)));
|
|
273
|
+
return row ? this.toDocument(row) : null;
|
|
274
|
+
}
|
|
275
|
+
async insert(doc) {
|
|
276
|
+
const now = nowIso();
|
|
277
|
+
const row = {
|
|
278
|
+
id: newId(),
|
|
279
|
+
data: { ...doc, _v: this.options.version },
|
|
280
|
+
created_at: now,
|
|
281
|
+
updated_at: now,
|
|
282
|
+
};
|
|
283
|
+
const store = await this.store('readwrite');
|
|
284
|
+
await promisifyRequest(store.put(row));
|
|
285
|
+
return this.toDocument(row);
|
|
286
|
+
}
|
|
287
|
+
async update(id, changes) {
|
|
288
|
+
const store = await this.store('readwrite');
|
|
289
|
+
const existing = (await promisifyRequest(store.get(id)));
|
|
290
|
+
if (!existing)
|
|
291
|
+
return null;
|
|
292
|
+
const next = {
|
|
293
|
+
...existing,
|
|
294
|
+
data: {
|
|
295
|
+
...existing.data,
|
|
296
|
+
...changes,
|
|
297
|
+
_v: this.options.version,
|
|
298
|
+
},
|
|
299
|
+
updated_at: nowIso(),
|
|
300
|
+
};
|
|
301
|
+
await promisifyRequest(store.put(next));
|
|
302
|
+
return this.toDocument(next);
|
|
303
|
+
}
|
|
304
|
+
async remove(id) {
|
|
305
|
+
const store = await this.store('readwrite');
|
|
306
|
+
const existing = (await promisifyRequest(store.get(id)));
|
|
307
|
+
if (!existing)
|
|
308
|
+
return false;
|
|
309
|
+
await promisifyRequest(store.delete(id));
|
|
310
|
+
return true;
|
|
311
|
+
}
|
|
312
|
+
async count(filter) {
|
|
313
|
+
if (!filter) {
|
|
314
|
+
const store = await this.store('readonly');
|
|
315
|
+
return promisifyRequest(store.count());
|
|
316
|
+
}
|
|
317
|
+
const all = await this.find(filter);
|
|
318
|
+
return all.length;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
// ── Factory ────────────────────────────────────────────────────────
|
|
322
|
+
/**
|
|
323
|
+
* Open a typed collection. Returns a backend that matches the current
|
|
324
|
+
* environment — no server means IndexedDB, server present means
|
|
325
|
+
* FetchCollection routed through the private `/_internal/collection/*`
|
|
326
|
+
* surface.
|
|
327
|
+
*
|
|
328
|
+
* For the production path to work, the app's `manifest.json` must
|
|
329
|
+
* declare the collection under `collections` with a JSON Schema so
|
|
330
|
+
* the runtime can validate writes:
|
|
331
|
+
*
|
|
332
|
+
* {
|
|
333
|
+
* "collections": {
|
|
334
|
+
* "notes": {
|
|
335
|
+
* "version": 1,
|
|
336
|
+
* "schema": {
|
|
337
|
+
* "type": "object",
|
|
338
|
+
* "required": ["title"],
|
|
339
|
+
* "properties": {
|
|
340
|
+
* "title": { "type": "string" },
|
|
341
|
+
* "body": { "type": "string" }
|
|
342
|
+
* },
|
|
343
|
+
* "additionalProperties": false
|
|
344
|
+
* }
|
|
345
|
+
* }
|
|
346
|
+
* }
|
|
347
|
+
* }
|
|
348
|
+
*
|
|
349
|
+
* Writes that fail schema validation are rejected with HTTP 400 — so
|
|
350
|
+
* even on the private surface, callers can't produce ghost records.
|
|
351
|
+
*/
|
|
352
|
+
export function collection(name, options) {
|
|
353
|
+
if (detectHasServer()) {
|
|
354
|
+
return new FetchCollection(name);
|
|
355
|
+
}
|
|
356
|
+
return new IndexedDBCollection(name, options);
|
|
357
|
+
}
|
|
358
|
+
// Named exports in case callers want to pin a specific backend.
|
|
359
|
+
export { FetchCollection, IndexedDBCollection };
|
|
360
|
+
//# sourceMappingURL=data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data.js","sourceRoot":"","sources":["../../src/app-runtime/data.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AAEH,sEAAsE;AAEtE,kEAAkE;AAClE,mEAAmE;AACnE,gCAAgC;AAChC,SAAS,eAAe;IACtB,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO,KAAK,CAAC;IAChD,IAAI,MAAM,CAAC,kBAAkB;QAAE,OAAO,IAAI,CAAC;IAC3C,MAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAClF,IAAI,UAAU;QAAE,OAAO,IAAI,CAAC;IAC5B,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACtE,OAAO,CAAC,CAAC,WAAW,CAAC;AACvB,CAAC;AAED,SAAS,YAAY;IACnB,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO,aAAa,CAAC;IACxD,IAAI,MAAM,CAAC,kBAAkB;QAAE,OAAO,MAAM,CAAC,kBAAkB,CAAC;IAChE,MAAM,MAAM,G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3C,OAAO,gBAAgB,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;QACzC,CAAC;QACD,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACpC,OAAO,GAAG,CAAC,MAAM,CAAC;IACpB,CAAC;CACF;AAED,sEAAsE;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,UAAU,UAAU,CACxB,IAAY,EACZ,OAA6B;IAE7B,IAAI,eAAe,EAAE,EAAE,CAAC;QACtB,OAAO,IAAI,eAAe,CAAI,IAAI,CAAC,CAAC;IACtC,CAAC;IACD,OAAO,IAAI,mBAAmB,CAAI,IAAI,EAAE,OAAO,CAAC,CAAC;AACnD,CAAC;AAED,gEAAgE;AAChE,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -2,22 +2,29 @@
|
|
|
2
2
|
* Beeable App Runtime SDK
|
|
3
3
|
*
|
|
4
4
|
* The client-side SDK that runs INSIDE a Beeable app — both in
|
|
5
|
-
* production (the app
|
|
6
|
-
* Lovable's preview where the runtime isn't available.
|
|
5
|
+
* production (the app-runtime container) and in development sandboxes
|
|
6
|
+
* like Lovable's preview where the runtime isn't available.
|
|
7
7
|
*
|
|
8
8
|
* Provides:
|
|
9
9
|
* - Host bridge: postMessage communication with the Beeable host UI
|
|
10
10
|
* (`ready`, `declareMenu`, `clearMenu`, `onMenuAction`, `requestSelect`)
|
|
11
11
|
* - Live data signals: `onDataChanged` (SSE in production, no-op in dev)
|
|
12
|
-
* -
|
|
13
|
-
*
|
|
12
|
+
* - **Typed platform API**: `beeable.api.<tag>.<method>(...)` — full
|
|
13
|
+
* orval-generated TypeScript inference on every endpoint. Backed by
|
|
14
|
+
* `beeableRequest` which is auto-configured for the iframe context.
|
|
15
|
+
* - **Typed LLM chat**: `beeable.llm.chat(dto)` → OpenAI-compatible
|
|
16
|
+
* response shape.
|
|
17
|
+
* - Escape hatches: `beeable.api.raw.get<T>(path)` / `.post<T>` for paths
|
|
18
|
+
* the generated client doesn't cover.
|
|
19
|
+
* - Cross-app calls: `beeable.app(name)` — untyped by default, since
|
|
20
|
+
* the target's route shape is unknown. For typed cross-app access,
|
|
21
|
+
* codegen a client from the app's openapi.json.
|
|
14
22
|
*
|
|
15
23
|
* Apps own their entire HTTP surface. There is intentionally no
|
|
16
|
-
* SDK collection() helper — every public operation
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* One contract for the frontend AND any LLM/external caller.
|
|
24
|
+
* SDK collection() helper here — every public operation an app exposes
|
|
25
|
+
* is a deliberate `@openapi`-annotated route in server/routes.ts. For
|
|
26
|
+
* apps that also want a local data store (IndexedDB in dev, SQLite via
|
|
27
|
+
* private routes in production), see `@beeable/sdk/app-runtime/data`.
|
|
21
28
|
*
|
|
22
29
|
* Usage:
|
|
23
30
|
* import { beeable, ready, declareMenu, onDataChanged } from '@beeable/sdk/app-runtime';
|
|
@@ -26,12 +33,17 @@
|
|
|
26
33
|
* declareMenu([{ id: 'new', label: 'New' }]);
|
|
27
34
|
* onDataChanged(() => refetch());
|
|
28
35
|
*
|
|
36
|
+
* const me = await beeable.api.auth.getMe();
|
|
37
|
+
* const convs = await beeable.api.conversations.list({ colleagueId });
|
|
38
|
+
* const reply = await beeable.llm.chat({ model: 'claude-sonnet-4-6', messages });
|
|
39
|
+
*
|
|
29
40
|
* IMPORTANT: this file is the canonical source. The Beeable app runtime
|
|
30
41
|
* mirrors a built copy at `app-runtime/src/public/beeable-sdk.js` so its
|
|
31
42
|
* Vite override plugin can serve the same bytes inside running app
|
|
32
43
|
* containers. Both must stay in sync — the SDK build's postbuild step
|
|
33
44
|
* handles that automatically.
|
|
34
45
|
*/
|
|
46
|
+
import * as api from './typed-api';
|
|
35
47
|
declare global {
|
|
36
48
|
interface Window {
|
|
37
49
|
__BEEABLE_APP_ID__?: string;
|
|
@@ -43,14 +55,8 @@ export interface MenuItem {
|
|
|
43
55
|
label: string;
|
|
44
56
|
children?: MenuItem[];
|
|
45
57
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
content: string;
|
|
49
|
-
}
|
|
50
|
-
export interface LlmChatOptions {
|
|
51
|
-
model?: string;
|
|
52
|
-
[key: string]: unknown;
|
|
53
|
-
}
|
|
58
|
+
/** True when running inside the Beeable runtime (proxy or direct). False in Lovable preview. */
|
|
59
|
+
export declare const hasServer: boolean;
|
|
54
60
|
/** Notify the host that the app has loaded and is ready. */
|
|
55
61
|
export declare function ready(): void;
|
|
56
62
|
/** Declare (or update) the app's menu items. */
|
|
@@ -77,20 +83,24 @@ export declare function onMenuAction(callback: (action: string) => void): () =>
|
|
|
77
83
|
* Returns an unsubscribe function.
|
|
78
84
|
*/
|
|
79
85
|
export declare function onDataChanged(callback: () => void): () => void;
|
|
80
|
-
export interface
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
+
export interface RawApi {
|
|
87
|
+
get<T = unknown>(path: string): Promise<T>;
|
|
88
|
+
post<T = unknown>(path: string, body?: unknown): Promise<T>;
|
|
89
|
+
put<T = unknown>(path: string, body?: unknown): Promise<T>;
|
|
90
|
+
patch<T = unknown>(path: string, body?: unknown): Promise<T>;
|
|
91
|
+
delete<T = unknown>(path: string): Promise<T>;
|
|
86
92
|
}
|
|
87
93
|
export interface BeeableAppClient {
|
|
88
|
-
|
|
89
|
-
post(path: string, body: unknown): Promise<unknown>;
|
|
94
|
+
raw: RawApi;
|
|
90
95
|
}
|
|
91
96
|
export interface Beeable {
|
|
92
|
-
|
|
93
|
-
api:
|
|
97
|
+
/** Fully-typed platform API, grouped by OpenAPI tag. */
|
|
98
|
+
api: typeof api & {
|
|
99
|
+
raw: RawApi;
|
|
100
|
+
};
|
|
101
|
+
/** Fully-typed LLM surface (shortcut for `beeable.api.llm`). */
|
|
102
|
+
llm: typeof api.llm;
|
|
103
|
+
/** Call another installed app. Untyped by default — use the app's generated client for inference. */
|
|
94
104
|
app(name: string): BeeableAppClient;
|
|
95
105
|
}
|
|
96
106
|
export declare const beeable: Beeable;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/app-runtime/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/app-runtime/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAGH,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AAInC,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,kBAAkB,CAAC,EAAE,MAAM,CAAC;QAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAC;KAC3B;CACF;AAID,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC;CACvB;AAqBD,gGAAgG;AAChG,eAAO,MAAM,SAAS,EAAE,OAA0D,CAAC;AA0CnF,4DAA4D;AAC5D,wBAAgB,KAAK,IAAI,IAAI,CAE5B;AAED,gDAAgD;AAChD,wBAAgB,WAAW,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI,CAEnD;AAED,0BAA0B;AAC1B,wBAAgB,SAAS,IAAI,IAAI,CAEhC;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,IAAI,IAAI,CAEpC;AAYD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM,IAAI,CAQ3E;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAK9D;AAQD,MAAM,WAAW,MAAM;IACrB,GAAG,CAAC,CAAC,GAAG,OAAO,EA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