@softr/sdk 0.0.27 → 0.0.29
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/action.d.ts +30 -73
- package/dist/action.js +9 -8
- package/dist/cli.js +2 -618
- package/dist/codegen/datasource-types.js +1 -1
- package/dist/codegen/fetch-metadata.js +46 -0
- package/dist/codegen/softr-env.js +1 -2
- package/dist/core/integration.d.ts +1 -1
- package/dist/core/integration.js +2 -2
- package/dist/datasource/record.js +2 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/package.js +1 -1
- package/package.json +1 -1
- package/skills/softr-sdk/SKILL.md +14 -14
- package/skills/softr-sdk/auth/SKILL.md +1 -1
- package/skills/softr-sdk/charts-and-metrics/SKILL.md +180 -0
- package/skills/softr-sdk/charts-and-metrics/references/aggregations.md +76 -0
- package/skills/softr-sdk/current-user/SKILL.md +6 -6
- package/skills/softr-sdk/integrations/SKILL.md +9 -8
- package/skills/softr-sdk/record-mutations/SKILL.md +149 -0
- package/skills/softr-sdk/record-queries/SKILL.md +163 -0
- package/skills/softr-sdk/record-queries/references/field-types.md +63 -0
- package/skills/softr-sdk/record-queries/references/filters-and-sorting.md +146 -0
- package/skills/softr-sdk/routes-and-visibility/SKILL.md +4 -4
- package/skills/softr-sdk/data-mutations/SKILL.md +0 -138
- package/skills/softr-sdk/reading-records/SKILL.md +0 -176
- package/skills/softr-sdk/reading-records/references/field-types.md +0 -70
- package/skills/softr-sdk/reading-records/references/query-builder.md +0 -144
package/dist/action.d.ts
CHANGED
|
@@ -31,84 +31,41 @@ type ActionPermission = {
|
|
|
31
31
|
*/
|
|
32
32
|
interface SoftrDatasources {}
|
|
33
33
|
type SoftrDatasourceId = keyof SoftrDatasources extends never ? string : keyof SoftrDatasources & string;
|
|
34
|
-
/** The read type one datasource returns. */
|
|
35
34
|
type ReadOf<TDatasource$1> = TDatasource$1 extends keyof SoftrDatasources ? SoftrDatasources[TDatasource$1] extends {
|
|
36
35
|
read: infer TRecord;
|
|
37
36
|
} ? TRecord : never : never;
|
|
38
|
-
/**
|
|
39
|
-
* The DSv2 type name one field declares, as codegen emitted it: `"NUMBER"`, `"SELECT[]"`.
|
|
40
|
-
* `never` for a field no augmentation describes.
|
|
41
|
-
*/
|
|
42
37
|
type FieldTypeOf<TDatasource$1, TFieldId> = TDatasource$1 extends keyof SoftrDatasources ? SoftrDatasources[TDatasource$1] extends {
|
|
43
38
|
fieldTypes: infer TTypes;
|
|
44
39
|
} ? TFieldId extends keyof TTypes ? TTypes[TFieldId] : never : never : never;
|
|
45
|
-
/** The write type one datasource accepts for one operation. */
|
|
46
40
|
type WriteOf<TDatasource$1, TOperation$1> = TDatasource$1 extends keyof SoftrDatasources ? TOperation$1 extends keyof SoftrDatasources[TDatasource$1] ? SoftrDatasources[TDatasource$1][TOperation$1] : never : never;
|
|
47
|
-
/** The field ids a write may name. Any string, until {@link SoftrDatasources} is declared. */
|
|
48
41
|
type FieldIdOf<TDatasource$1, TOperation$1> = keyof SoftrDatasources extends never ? string : keyof WriteOf<TDatasource$1, TOperation$1> & string;
|
|
49
|
-
/**
|
|
50
|
-
* The field ids a read may name. Any string, until {@link SoftrDatasources} is declared.
|
|
51
|
-
*
|
|
52
|
-
* A read constrains against the record type rather than a write type, because a read may
|
|
53
|
-
* name a field no write can: a formula or a lookup is on the record and on neither.
|
|
54
|
-
*/
|
|
55
42
|
type ReadFieldIdOf<TDatasource$1> = keyof SoftrDatasources extends never ? string : keyof ReadOf<TDatasource$1> & string;
|
|
56
|
-
/**
|
|
57
|
-
* What an action declares, as the type layer reads it. `permission` is absent because no
|
|
58
|
-
* call site depends on it, and the build reads it off the value.
|
|
59
|
-
*/
|
|
60
43
|
type ActionShape = {
|
|
61
44
|
id: string;
|
|
62
45
|
datasource: SoftrDatasourceId;
|
|
63
46
|
operation: ActionOperation;
|
|
64
47
|
fields?: Record<string, string>;
|
|
65
48
|
};
|
|
66
|
-
/** What a read declares. A read is the whole field list, so `fields` is not optional. */
|
|
67
49
|
type ReadShape = ActionShape & {
|
|
68
50
|
operation: "read";
|
|
69
51
|
fields: Record<string, string>;
|
|
70
52
|
};
|
|
71
|
-
/**
|
|
72
|
-
* What one action writes: its own aliases, each resolved to the value that field accepts.
|
|
73
|
-
*
|
|
74
|
-
* An alias renames the field, and a mapped type keeps a property's docstring only while it
|
|
75
|
-
* keeps the key, so the prose that sits on the field in `softr-env.d.ts` does not reach the
|
|
76
|
-
* call site. The type does.
|
|
77
|
-
*/
|
|
78
53
|
type ActionData<TShape extends ActionShape> = keyof SoftrDatasources extends never ? Record<string, unknown> : TShape extends {
|
|
79
54
|
datasource: infer TDatasource;
|
|
80
55
|
operation: infer TOperation;
|
|
81
56
|
fields: infer TFields;
|
|
82
57
|
} ? { [Alias in keyof TFields]?: WriteOf<TDatasource, TOperation>[TFields[Alias] & keyof WriteOf<TDatasource, TOperation>] } : Record<string, unknown>;
|
|
83
|
-
/**
|
|
84
|
-
* What a mutation reads back: the same aliases, resolved against the table's read type.
|
|
85
|
-
*
|
|
86
|
-
* A write returns the record it wrote, and the SDK aliases its fields on the way out, so a
|
|
87
|
-
* field the action never declared is absent from the result as well as from the payload.
|
|
88
|
-
*
|
|
89
|
-
* Every alias the action does declare is present. An empty field reads as `null`, so nothing
|
|
90
|
-
* here is optional.
|
|
91
|
-
*/
|
|
92
58
|
type ActionRecord<TShape extends ActionShape> = keyof SoftrDatasources extends never ? Record<string, unknown> : TShape extends {
|
|
93
59
|
datasource: infer TDatasource;
|
|
94
60
|
fields: infer TFields;
|
|
95
61
|
} ? { [Alias in keyof TFields]: ReadOf<TDatasource>[TFields[Alias] & keyof ReadOf<TDatasource>] } : Record<string, unknown>;
|
|
96
62
|
declare const brand: unique symbol;
|
|
97
|
-
/**
|
|
98
|
-
* A handle to a declared action, and the only thing a mutation accepts. The brand keeps it
|
|
99
|
-
* nominal, so an object literal of the same shape will not do and no mutation can be reached
|
|
100
|
-
* without passing through a declaration the build reads.
|
|
101
|
-
*
|
|
102
|
-
* The brand carries the declaration itself, which is what lets a call site resolve what the
|
|
103
|
-
* action writes without codegen having said anything about this action.
|
|
104
|
-
*/
|
|
105
63
|
type Action<TShape extends ActionShape = ActionShape> = {
|
|
106
64
|
type: "action";
|
|
107
65
|
id: TShape["id"];
|
|
108
66
|
} & {
|
|
109
67
|
readonly [brand]: TShape;
|
|
110
68
|
};
|
|
111
|
-
/** What a write action declares. */
|
|
112
69
|
type WriteDeclaration<TId extends string, TDatasource$1, TOperation$1, TFields$1> = {
|
|
113
70
|
id: TId;
|
|
114
71
|
datasource: TDatasource$1;
|
|
@@ -116,15 +73,12 @@ type WriteDeclaration<TId extends string, TDatasource$1, TOperation$1, TFields$1
|
|
|
116
73
|
fields: TFields$1;
|
|
117
74
|
permission: ActionPermission;
|
|
118
75
|
};
|
|
119
|
-
/** What a read action declares. */
|
|
120
76
|
type ReadDeclaration<TId extends string, TDatasource$1, TFields$1> = {
|
|
121
77
|
id: TId;
|
|
122
78
|
datasource: TDatasource$1;
|
|
123
|
-
operation: "read";
|
|
124
79
|
fields: TFields$1;
|
|
125
80
|
permission: ActionPermission;
|
|
126
81
|
};
|
|
127
|
-
/** What a delete action declares. `fields?: never` so a stray one is rejected rather than ignored. */
|
|
128
82
|
type DeleteDeclaration<TId extends string, TDatasource$1> = {
|
|
129
83
|
id: TId;
|
|
130
84
|
datasource: TDatasource$1;
|
|
@@ -132,28 +86,15 @@ type DeleteDeclaration<TId extends string, TDatasource$1> = {
|
|
|
132
86
|
fields?: never;
|
|
133
87
|
permission: ActionPermission;
|
|
134
88
|
};
|
|
135
|
-
/** The whole declaration, which is what an action is at runtime and in the manifest. */
|
|
136
|
-
|
|
137
89
|
/**
|
|
138
|
-
* Declares a
|
|
139
|
-
* participate, and who may run it.
|
|
140
|
-
*
|
|
141
|
-
* One call per action, at module scope, with a literal: the build reads these declarations
|
|
142
|
-
* to publish what the app may read and write.
|
|
90
|
+
* Declares a read: which datasource, which fields participate, and who may run it.
|
|
143
91
|
*
|
|
144
|
-
* The
|
|
145
|
-
* datasource the action names. The result, `data`, `where` and `orderBy` at the call site
|
|
146
|
-
* are all keyed by those aliases, so nothing there restates what the action already says.
|
|
147
|
-
*
|
|
148
|
-
* A read fixes the table and the columns. It does not fix which rows: `where`, `orderBy` and
|
|
149
|
-
* the paging arguments stay at the call site, because a list screen changes them as the user
|
|
150
|
-
* types and a declaration cannot follow that.
|
|
92
|
+
* The argument must be a static object.
|
|
151
93
|
*
|
|
152
94
|
* @example
|
|
153
|
-
* const publishedPosts =
|
|
95
|
+
* const publishedPosts = defineQuery({
|
|
154
96
|
* id: "publishedPosts",
|
|
155
97
|
* datasource: "8f14e45f-ceea-467a-9d0b-2c1a0e3b5d77",
|
|
156
|
-
* operation: "read",
|
|
157
98
|
* fields: { title: "V1StGXR8", author: "Z7pQm4Kd", publishedAt: "Xp2dLh6v" },
|
|
158
99
|
* permission: { userGroup: "ALL_USERS" },
|
|
159
100
|
* })
|
|
@@ -162,9 +103,21 @@ type DeleteDeclaration<TId extends string, TDatasource$1> = {
|
|
|
162
103
|
* .list(publishedPosts)
|
|
163
104
|
* .where((q) => q.publishedAt.lte(today))
|
|
164
105
|
* .orderBy((q) => q.publishedAt.desc)
|
|
106
|
+
*/
|
|
107
|
+
declare function defineQuery<const TId extends string, const TDatasource$1 extends SoftrDatasourceId, const TFields$1 extends Record<string, ReadFieldIdOf<TDatasource$1>>>(definition: ReadDeclaration<TId, TDatasource$1, TFields$1>): Action<{
|
|
108
|
+
id: TId;
|
|
109
|
+
datasource: TDatasource$1;
|
|
110
|
+
operation: "read";
|
|
111
|
+
fields: TFields$1;
|
|
112
|
+
}>;
|
|
113
|
+
/**
|
|
114
|
+
* Declares a write: which datasource, whether it creates, updates or deletes, which fields
|
|
115
|
+
* participate, and who may run it.
|
|
116
|
+
*
|
|
117
|
+
* The argument must be a static object.
|
|
165
118
|
*
|
|
166
119
|
* @example
|
|
167
|
-
* const
|
|
120
|
+
* const closeOrder = defineMutation({
|
|
168
121
|
* id: "closeOrder",
|
|
169
122
|
* datasource: "8f14e45f-ceea-467a-9d0b-2c1a0e3b5d77",
|
|
170
123
|
* operation: "update",
|
|
@@ -172,24 +125,28 @@ type DeleteDeclaration<TId extends string, TDatasource$1> = {
|
|
|
172
125
|
* permission: { userGroup: "LOGGED_IN_USERS", userGroupIds: ["grp_staff"] },
|
|
173
126
|
* })
|
|
174
127
|
*
|
|
175
|
-
* await ds.update(
|
|
128
|
+
* await ds.update(closeOrder, { id, data: { status: "closed" } })
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* const removeOrder = defineMutation({
|
|
132
|
+
* id: "removeOrder",
|
|
133
|
+
* datasource: "8f14e45f-ceea-467a-9d0b-2c1a0e3b5d77",
|
|
134
|
+
* operation: "delete",
|
|
135
|
+
* permission: { userGroup: "LOGGED_IN_USERS", userGroupIds: ["grp_staff"] },
|
|
136
|
+
* })
|
|
137
|
+
*
|
|
138
|
+
* await ds.delete(removeOrder, { id })
|
|
176
139
|
*/
|
|
177
|
-
declare function
|
|
178
|
-
id: TId;
|
|
179
|
-
datasource: TDatasource$1;
|
|
180
|
-
operation: "read";
|
|
181
|
-
fields: TFields$1;
|
|
182
|
-
}>;
|
|
183
|
-
declare function defineAction<const TId extends string, const TDatasource$1 extends SoftrDatasourceId, const TOperation$1 extends "create" | "update", const TFields$1 extends Record<string, FieldIdOf<TDatasource$1, TOperation$1>>>(definition: WriteDeclaration<TId, TDatasource$1, TOperation$1, TFields$1>): Action<{
|
|
140
|
+
declare function defineMutation<const TId extends string, const TDatasource$1 extends SoftrDatasourceId, const TOperation$1 extends "create" | "update", const TFields$1 extends Record<string, FieldIdOf<TDatasource$1, TOperation$1>>>(definition: WriteDeclaration<TId, TDatasource$1, TOperation$1, TFields$1>): Action<{
|
|
184
141
|
id: TId;
|
|
185
142
|
datasource: TDatasource$1;
|
|
186
143
|
operation: TOperation$1;
|
|
187
144
|
fields: TFields$1;
|
|
188
145
|
}>;
|
|
189
|
-
declare function
|
|
146
|
+
declare function defineMutation<const TId extends string, const TDatasource$1 extends SoftrDatasourceId>(definition: DeleteDeclaration<TId, TDatasource$1>): Action<{
|
|
190
147
|
id: TId;
|
|
191
148
|
datasource: TDatasource$1;
|
|
192
149
|
operation: "delete";
|
|
193
150
|
}>;
|
|
194
151
|
//#endregion
|
|
195
|
-
export { Action, ActionData, ActionRecord, ActionShape, FieldTypeOf, ReadOf, ReadShape, SoftrDatasources,
|
|
152
|
+
export { Action, ActionData, ActionRecord, ActionShape, FieldTypeOf, ReadOf, ReadShape, SoftrDatasources, defineMutation, defineQuery };
|
package/dist/action.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
//#region src/action.ts
|
|
2
|
-
function
|
|
2
|
+
function defineQuery(definition) {
|
|
3
|
+
return {
|
|
4
|
+
type: "action",
|
|
5
|
+
...definition,
|
|
6
|
+
operation: "read"
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
function defineMutation(definition) {
|
|
3
10
|
return {
|
|
4
11
|
type: "action",
|
|
5
12
|
...definition
|
|
6
13
|
};
|
|
7
14
|
}
|
|
8
|
-
/**
|
|
9
|
-
* True for anything {@link defineAction} produced, whatever its operation.
|
|
10
|
-
*
|
|
11
|
-
* Matched on `type` rather than with `instanceof`, so two copies of the SDK in one
|
|
12
|
-
* dependency tree still recognise each other's actions.
|
|
13
|
-
*/
|
|
14
15
|
function isAction(value) {
|
|
15
16
|
if (typeof value !== "object" || value === null) return false;
|
|
16
17
|
const candidate = value;
|
|
@@ -18,4 +19,4 @@ function isAction(value) {
|
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
//#endregion
|
|
21
|
-
export {
|
|
22
|
+
export { defineMutation, defineQuery, isAction };
|