@softr/sdk 0.0.7 → 0.0.11
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/client.d.ts +6 -0
- package/dist/{react.js → client.js} +2 -1
- package/dist/index.d.ts +659 -11
- package/dist/index.js +874 -24
- package/dist/server.d.ts +85 -0
- package/dist/server.js +196 -0
- package/dist/session-GUEI96C8.js +360 -0
- package/dist/user-D23hwTsf.d.ts +28 -0
- package/dist/vite.d.ts +6 -3
- package/dist/vite.js +28 -2
- package/package.json +6 -5
- package/dist/query-C6022JhD.js +0 -528
- package/dist/react.d.ts +0 -4
- package/dist/tanstack.d.ts +0 -18
- package/dist/tanstack.js +0 -320
- package/dist/types-CjB4xUg-.d.ts +0 -661
package/dist/vite.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
1
2
|
import * as nodeFs from "node:fs/promises";
|
|
2
3
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
3
4
|
import path from "node:path";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
4
6
|
import { Generator, getConfig, inferFullPath } from "@tanstack/router-generator";
|
|
5
|
-
import { randomUUID } from "node:crypto";
|
|
6
7
|
import os from "node:os";
|
|
7
8
|
import { parse } from "@babel/parser";
|
|
8
9
|
import babelTraverse from "@babel/traverse";
|
|
@@ -428,8 +429,15 @@ async function writeManifest(root, contents) {
|
|
|
428
429
|
async function generateManifest(root) {
|
|
429
430
|
return writeManifest(root, await renderManifest(root));
|
|
430
431
|
}
|
|
431
|
-
/**
|
|
432
|
+
/**
|
|
433
|
+
* Everything Softr adds to an app's Vite config: the build-time routes manifest, plus the studio
|
|
434
|
+
* edit engine when the pod supplies one.
|
|
435
|
+
*/
|
|
432
436
|
function softr() {
|
|
437
|
+
return [routesManifest(), editEngine()];
|
|
438
|
+
}
|
|
439
|
+
/** Plugin order does not matter: this puts nothing into the module graph. */
|
|
440
|
+
function routesManifest() {
|
|
433
441
|
let root = process.cwd();
|
|
434
442
|
let rendered = null;
|
|
435
443
|
return {
|
|
@@ -444,6 +452,24 @@ function softr() {
|
|
|
444
452
|
}
|
|
445
453
|
};
|
|
446
454
|
}
|
|
455
|
+
/**
|
|
456
|
+
* The edit engine is provided by the pod runtime rather than an app dependency: it is never in the
|
|
457
|
+
* app's `package.json` and never in its `node_modules`. The pod points `SOFTR_EDIT_ENGINE_DIR` at
|
|
458
|
+
* the copy baked into its image, and this function loads it from there.
|
|
459
|
+
*
|
|
460
|
+
* If the env var is unset, this plugin is a no-op. It's only loaded in the preview mode
|
|
461
|
+
*/
|
|
462
|
+
async function editEngine() {
|
|
463
|
+
const dir = process.env.SOFTR_EDIT_ENGINE_DIR;
|
|
464
|
+
if (!dir) return false;
|
|
465
|
+
const entry = pathToFileURL(path.join(dir, "dist", "vite.js")).href;
|
|
466
|
+
try {
|
|
467
|
+
return (await import(entry)).editEngineStudio();
|
|
468
|
+
} catch (error) {
|
|
469
|
+
console.error(`[softr] could not load the edit engine from ${entry}:`, error);
|
|
470
|
+
return false;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
447
473
|
|
|
448
474
|
//#endregion
|
|
449
475
|
export { MANIFEST_RELATIVE_PATH, generateManifest, softr };
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@softr/sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" },
|
|
7
|
-
"./
|
|
8
|
-
"./
|
|
9
|
-
"./
|
|
7
|
+
"./client": { "types": "./dist/client.d.ts", "import": "./dist/client.js" },
|
|
8
|
+
"./server": { "types": "./dist/server.d.ts", "import": "./dist/server.js" },
|
|
9
|
+
"./vite": { "types": "./dist/vite.d.ts", "import": "./dist/vite.js" }
|
|
10
10
|
},
|
|
11
11
|
"files": ["dist"],
|
|
12
12
|
"publishConfig": { "access": "public" },
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"@babel/parser": "^7.28.0",
|
|
20
20
|
"@babel/traverse": "^7.28.0",
|
|
21
21
|
"@babel/types": "^7.28.0",
|
|
22
|
-
"@tanstack/router-generator": "1.167.23"
|
|
22
|
+
"@tanstack/router-generator": "1.167.23",
|
|
23
|
+
"zod": "^4.4.3"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
26
|
"@tanstack/react-router": "^1.168.0",
|
package/dist/query-C6022JhD.js
DELETED
|
@@ -1,528 +0,0 @@
|
|
|
1
|
-
//#region src/core/query.ts
|
|
2
|
-
const INTERNAL_KIND = Symbol("KIND");
|
|
3
|
-
/**
|
|
4
|
-
* Query builder for filter queries. This exist to alleviate the (LLM?) mental overhead. API filter schema is a bit
|
|
5
|
-
* verbose and confusing, even when dealing with very basic queries. So to fall into the pit of success, aim here
|
|
6
|
-
* is to simplify filtering as much as possible.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* single filter
|
|
10
|
-
* ```tsx
|
|
11
|
-
* const query = q.text("title").contains("hello");
|
|
12
|
-
*
|
|
13
|
-
* const json = buildFilterCriteria(query);
|
|
14
|
-
* // result
|
|
15
|
-
* {
|
|
16
|
-
* "filterCriteria": {
|
|
17
|
-
* "filterConditionGroup": {
|
|
18
|
-
* "logicalOperator": "AND"
|
|
19
|
-
* "filterGroups": [{
|
|
20
|
-
* "logicalOperator": "AND",
|
|
21
|
-
* "filters": [{
|
|
22
|
-
* "subject": "title",
|
|
23
|
-
* "type": "TEXT",
|
|
24
|
-
* "operator": "CONTAINS",
|
|
25
|
-
* "value": "hello"
|
|
26
|
-
* }],
|
|
27
|
-
* }]
|
|
28
|
-
* }
|
|
29
|
-
* }
|
|
30
|
-
* }
|
|
31
|
-
*
|
|
32
|
-
* ```
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* combining multiple filters
|
|
36
|
-
* ```tsx
|
|
37
|
-
* const query = q.and(
|
|
38
|
-
* q.text("title").contains("hello"),
|
|
39
|
-
* q.number("views").is(100),
|
|
40
|
-
* q.or(
|
|
41
|
-
* q.text("author").is("John"),
|
|
42
|
-
* q.boolean("isPublished").is(true)
|
|
43
|
-
* )
|
|
44
|
-
* );
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
const q = {
|
|
48
|
-
select(mapping) {
|
|
49
|
-
return mapping;
|
|
50
|
-
},
|
|
51
|
-
and(...filters) {
|
|
52
|
-
return {
|
|
53
|
-
logicalOperator: "AND",
|
|
54
|
-
filters,
|
|
55
|
-
[INTERNAL_KIND]: "LOGICAL_GROUP"
|
|
56
|
-
};
|
|
57
|
-
},
|
|
58
|
-
or(...filters) {
|
|
59
|
-
return {
|
|
60
|
-
logicalOperator: "OR",
|
|
61
|
-
filters,
|
|
62
|
-
[INTERNAL_KIND]: "LOGICAL_GROUP"
|
|
63
|
-
};
|
|
64
|
-
},
|
|
65
|
-
text(subject) {
|
|
66
|
-
const filter = {
|
|
67
|
-
subject,
|
|
68
|
-
type: "TEXT",
|
|
69
|
-
[INTERNAL_KIND]: "FILTER"
|
|
70
|
-
};
|
|
71
|
-
return {
|
|
72
|
-
is(value) {
|
|
73
|
-
return {
|
|
74
|
-
...filter,
|
|
75
|
-
operator: "IS",
|
|
76
|
-
value
|
|
77
|
-
};
|
|
78
|
-
},
|
|
79
|
-
isNot(value) {
|
|
80
|
-
return {
|
|
81
|
-
...filter,
|
|
82
|
-
operator: "IS_NOT",
|
|
83
|
-
value
|
|
84
|
-
};
|
|
85
|
-
},
|
|
86
|
-
contains(value) {
|
|
87
|
-
return {
|
|
88
|
-
...filter,
|
|
89
|
-
operator: "CONTAINS",
|
|
90
|
-
value
|
|
91
|
-
};
|
|
92
|
-
},
|
|
93
|
-
isOneOf(value) {
|
|
94
|
-
return {
|
|
95
|
-
...filter,
|
|
96
|
-
operator: "IS_ONE_OF",
|
|
97
|
-
value
|
|
98
|
-
};
|
|
99
|
-
},
|
|
100
|
-
isNoneOf(value) {
|
|
101
|
-
return {
|
|
102
|
-
...filter,
|
|
103
|
-
operator: "IS_NONE_OF",
|
|
104
|
-
value
|
|
105
|
-
};
|
|
106
|
-
},
|
|
107
|
-
startsWith(value) {
|
|
108
|
-
return {
|
|
109
|
-
...filter,
|
|
110
|
-
operator: "STARTS_WITH",
|
|
111
|
-
value
|
|
112
|
-
};
|
|
113
|
-
},
|
|
114
|
-
endsWith(value) {
|
|
115
|
-
return {
|
|
116
|
-
...filter,
|
|
117
|
-
operator: "ENDS_WITH",
|
|
118
|
-
value
|
|
119
|
-
};
|
|
120
|
-
},
|
|
121
|
-
hasAllOf(value) {
|
|
122
|
-
return {
|
|
123
|
-
...filter,
|
|
124
|
-
operator: "HAS_ALL_OF",
|
|
125
|
-
value
|
|
126
|
-
};
|
|
127
|
-
},
|
|
128
|
-
isEmpty() {
|
|
129
|
-
return {
|
|
130
|
-
...filter,
|
|
131
|
-
operator: "IS_EMPTY"
|
|
132
|
-
};
|
|
133
|
-
},
|
|
134
|
-
isNotEmpty() {
|
|
135
|
-
return {
|
|
136
|
-
...filter,
|
|
137
|
-
operator: "IS_NOT_EMPTY"
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
},
|
|
142
|
-
boolean(subject) {
|
|
143
|
-
const filter = {
|
|
144
|
-
subject,
|
|
145
|
-
type: "BOOLEAN",
|
|
146
|
-
[INTERNAL_KIND]: "FILTER"
|
|
147
|
-
};
|
|
148
|
-
return {
|
|
149
|
-
is(value) {
|
|
150
|
-
return {
|
|
151
|
-
...filter,
|
|
152
|
-
operator: "IS",
|
|
153
|
-
value
|
|
154
|
-
};
|
|
155
|
-
},
|
|
156
|
-
isNot(value) {
|
|
157
|
-
return {
|
|
158
|
-
...filter,
|
|
159
|
-
operator: "IS_NOT",
|
|
160
|
-
value
|
|
161
|
-
};
|
|
162
|
-
},
|
|
163
|
-
isEmpty() {
|
|
164
|
-
return {
|
|
165
|
-
...filter,
|
|
166
|
-
operator: "IS_EMPTY"
|
|
167
|
-
};
|
|
168
|
-
},
|
|
169
|
-
isNotEmpty() {
|
|
170
|
-
return {
|
|
171
|
-
...filter,
|
|
172
|
-
operator: "IS_NOT_EMPTY"
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
},
|
|
177
|
-
number(subject) {
|
|
178
|
-
const filter = {
|
|
179
|
-
subject,
|
|
180
|
-
type: "NUMERIC",
|
|
181
|
-
[INTERNAL_KIND]: "FILTER"
|
|
182
|
-
};
|
|
183
|
-
return {
|
|
184
|
-
is(value) {
|
|
185
|
-
return {
|
|
186
|
-
...filter,
|
|
187
|
-
operator: "IS",
|
|
188
|
-
value: value.toString()
|
|
189
|
-
};
|
|
190
|
-
},
|
|
191
|
-
isNot(value) {
|
|
192
|
-
return {
|
|
193
|
-
...filter,
|
|
194
|
-
operator: "IS_NOT",
|
|
195
|
-
value: value.toString()
|
|
196
|
-
};
|
|
197
|
-
},
|
|
198
|
-
gt(value) {
|
|
199
|
-
return {
|
|
200
|
-
...filter,
|
|
201
|
-
operator: "GT",
|
|
202
|
-
value: value.toString()
|
|
203
|
-
};
|
|
204
|
-
},
|
|
205
|
-
gte(value) {
|
|
206
|
-
return {
|
|
207
|
-
...filter,
|
|
208
|
-
operator: "GTE",
|
|
209
|
-
value: value.toString()
|
|
210
|
-
};
|
|
211
|
-
},
|
|
212
|
-
lt(value) {
|
|
213
|
-
return {
|
|
214
|
-
...filter,
|
|
215
|
-
operator: "LT",
|
|
216
|
-
value: value.toString()
|
|
217
|
-
};
|
|
218
|
-
},
|
|
219
|
-
lte(value) {
|
|
220
|
-
return {
|
|
221
|
-
...filter,
|
|
222
|
-
operator: "LTE",
|
|
223
|
-
value: value.toString()
|
|
224
|
-
};
|
|
225
|
-
},
|
|
226
|
-
between(start, end) {
|
|
227
|
-
return {
|
|
228
|
-
...filter,
|
|
229
|
-
operator: "BETWEEN",
|
|
230
|
-
value: [start.toString(), end.toString()]
|
|
231
|
-
};
|
|
232
|
-
},
|
|
233
|
-
isEmpty() {
|
|
234
|
-
return {
|
|
235
|
-
...filter,
|
|
236
|
-
operator: "IS_EMPTY"
|
|
237
|
-
};
|
|
238
|
-
},
|
|
239
|
-
isNotEmpty() {
|
|
240
|
-
return {
|
|
241
|
-
...filter,
|
|
242
|
-
operator: "IS_NOT_EMPTY"
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
},
|
|
247
|
-
array(subject) {
|
|
248
|
-
const filter = {
|
|
249
|
-
subject,
|
|
250
|
-
type: "ARRAY",
|
|
251
|
-
[INTERNAL_KIND]: "FILTER"
|
|
252
|
-
};
|
|
253
|
-
return {
|
|
254
|
-
is(value) {
|
|
255
|
-
return {
|
|
256
|
-
...filter,
|
|
257
|
-
operator: "IS",
|
|
258
|
-
value
|
|
259
|
-
};
|
|
260
|
-
},
|
|
261
|
-
isOneOf(value) {
|
|
262
|
-
return {
|
|
263
|
-
...filter,
|
|
264
|
-
operator: "IS_ONE_OF",
|
|
265
|
-
value
|
|
266
|
-
};
|
|
267
|
-
},
|
|
268
|
-
isNoneOf(value) {
|
|
269
|
-
return {
|
|
270
|
-
...filter,
|
|
271
|
-
operator: "IS_NONE_OF",
|
|
272
|
-
value
|
|
273
|
-
};
|
|
274
|
-
},
|
|
275
|
-
hasAllOf(value) {
|
|
276
|
-
return {
|
|
277
|
-
...filter,
|
|
278
|
-
operator: "HAS_ALL_OF",
|
|
279
|
-
value
|
|
280
|
-
};
|
|
281
|
-
},
|
|
282
|
-
isEmpty() {
|
|
283
|
-
return {
|
|
284
|
-
...filter,
|
|
285
|
-
operator: "IS_EMPTY"
|
|
286
|
-
};
|
|
287
|
-
},
|
|
288
|
-
isNotEmpty() {
|
|
289
|
-
return {
|
|
290
|
-
...filter,
|
|
291
|
-
operator: "IS_NOT_EMPTY"
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
};
|
|
295
|
-
},
|
|
296
|
-
date(subject) {
|
|
297
|
-
const filter = {
|
|
298
|
-
subject,
|
|
299
|
-
type: "DATE",
|
|
300
|
-
[INTERNAL_KIND]: "FILTER"
|
|
301
|
-
};
|
|
302
|
-
return {
|
|
303
|
-
is(value) {
|
|
304
|
-
return {
|
|
305
|
-
...filter,
|
|
306
|
-
operator: "IS",
|
|
307
|
-
value
|
|
308
|
-
};
|
|
309
|
-
},
|
|
310
|
-
isNot(value) {
|
|
311
|
-
return {
|
|
312
|
-
...filter,
|
|
313
|
-
operator: "IS_NOT",
|
|
314
|
-
value
|
|
315
|
-
};
|
|
316
|
-
},
|
|
317
|
-
gt(value) {
|
|
318
|
-
return {
|
|
319
|
-
...filter,
|
|
320
|
-
operator: "GT",
|
|
321
|
-
value
|
|
322
|
-
};
|
|
323
|
-
},
|
|
324
|
-
gte(value) {
|
|
325
|
-
return {
|
|
326
|
-
...filter,
|
|
327
|
-
operator: "GTE",
|
|
328
|
-
value
|
|
329
|
-
};
|
|
330
|
-
},
|
|
331
|
-
lt(value) {
|
|
332
|
-
return {
|
|
333
|
-
...filter,
|
|
334
|
-
operator: "LT",
|
|
335
|
-
value
|
|
336
|
-
};
|
|
337
|
-
},
|
|
338
|
-
lte(value) {
|
|
339
|
-
return {
|
|
340
|
-
...filter,
|
|
341
|
-
operator: "LTE",
|
|
342
|
-
value
|
|
343
|
-
};
|
|
344
|
-
},
|
|
345
|
-
between(start, end) {
|
|
346
|
-
return {
|
|
347
|
-
...filter,
|
|
348
|
-
operator: "BETWEEN",
|
|
349
|
-
value: [start, end]
|
|
350
|
-
};
|
|
351
|
-
},
|
|
352
|
-
isNotBetween(start, end) {
|
|
353
|
-
return {
|
|
354
|
-
...filter,
|
|
355
|
-
operator: "IS_NOT_BETWEEN",
|
|
356
|
-
value: [start, end]
|
|
357
|
-
};
|
|
358
|
-
},
|
|
359
|
-
isEmpty() {
|
|
360
|
-
return {
|
|
361
|
-
...filter,
|
|
362
|
-
operator: "IS_EMPTY"
|
|
363
|
-
};
|
|
364
|
-
},
|
|
365
|
-
isNotEmpty() {
|
|
366
|
-
return {
|
|
367
|
-
...filter,
|
|
368
|
-
operator: "IS_NOT_EMPTY"
|
|
369
|
-
};
|
|
370
|
-
}
|
|
371
|
-
};
|
|
372
|
-
},
|
|
373
|
-
asc(subject) {
|
|
374
|
-
return {
|
|
375
|
-
sortingField: subject,
|
|
376
|
-
sortType: "ASC",
|
|
377
|
-
[INTERNAL_KIND]: "ORDER_BY"
|
|
378
|
-
};
|
|
379
|
-
},
|
|
380
|
-
desc(subject) {
|
|
381
|
-
return {
|
|
382
|
-
sortingField: subject,
|
|
383
|
-
sortType: "DESC",
|
|
384
|
-
[INTERNAL_KIND]: "ORDER_BY"
|
|
385
|
-
};
|
|
386
|
-
}
|
|
387
|
-
};
|
|
388
|
-
/**
|
|
389
|
-
* Converts filter utility conditions to a format our backend supports
|
|
390
|
-
*
|
|
391
|
-
* @example
|
|
392
|
-
* ```tsx
|
|
393
|
-
* const query = q.text("title").contains("hello");
|
|
394
|
-
*
|
|
395
|
-
* const json = buildFilterCriteria(query);
|
|
396
|
-
* // result
|
|
397
|
-
* {
|
|
398
|
-
* "filterCriteria": {
|
|
399
|
-
* "filterConditionGroup": {
|
|
400
|
-
* "logicalOperator": "AND"
|
|
401
|
-
* "filterGroups": [{
|
|
402
|
-
* "logicalOperator": "AND",
|
|
403
|
-
* "filters": [{
|
|
404
|
-
* "subject": "title",
|
|
405
|
-
* "type": "TEXT",
|
|
406
|
-
* "operator": "CONTAINS",
|
|
407
|
-
* "value": "hello"
|
|
408
|
-
* }],
|
|
409
|
-
* }]
|
|
410
|
-
* }
|
|
411
|
-
* }
|
|
412
|
-
* }
|
|
413
|
-
*
|
|
414
|
-
* ```
|
|
415
|
-
*/
|
|
416
|
-
function buildFilterCriteria(input) {
|
|
417
|
-
if (!(INTERNAL_KIND in input)) throw new Error("Filters cannot be constructed manually. Use the 'q' helper.");
|
|
418
|
-
if (isFilter(input)) return { filterConditionGroup: {
|
|
419
|
-
logicalOperator: "AND",
|
|
420
|
-
filterGroups: [{
|
|
421
|
-
logicalOperator: "AND",
|
|
422
|
-
filters: [stripInternalKind(input)]
|
|
423
|
-
}]
|
|
424
|
-
} };
|
|
425
|
-
if (isFilterGroup(input)) {
|
|
426
|
-
if (input.filters.length === 0) return { filterConditionGroup: {
|
|
427
|
-
logicalOperator: input.logicalOperator,
|
|
428
|
-
filterGroups: []
|
|
429
|
-
} };
|
|
430
|
-
return { filterConditionGroup: {
|
|
431
|
-
logicalOperator: input.logicalOperator,
|
|
432
|
-
filterGroups: input.filters.map((inner) => {
|
|
433
|
-
if (isFilter(inner)) return {
|
|
434
|
-
logicalOperator: "AND",
|
|
435
|
-
filters: [stripInternalKind(inner)]
|
|
436
|
-
};
|
|
437
|
-
if (!inner.filters.every(isFilter)) throw new Error("Cannot nest filter groups more than three levels deep.");
|
|
438
|
-
return {
|
|
439
|
-
logicalOperator: inner.logicalOperator,
|
|
440
|
-
filters: inner.filters.map(stripInternalKind)
|
|
441
|
-
};
|
|
442
|
-
})
|
|
443
|
-
} };
|
|
444
|
-
}
|
|
445
|
-
throw new Error("Unknown filter kind: " + input[INTERNAL_KIND]);
|
|
446
|
-
}
|
|
447
|
-
/**
|
|
448
|
-
* Converts order-by utility conditions to a format our backend supports
|
|
449
|
-
*
|
|
450
|
-
* @example
|
|
451
|
-
* single orderBy
|
|
452
|
-
* ```tsx
|
|
453
|
-
* const orderBy = buildOrderBy(q.asc("title"));
|
|
454
|
-
* // result: [{ sortingField: "title", sortType: "ASC" }]
|
|
455
|
-
* ```
|
|
456
|
-
*
|
|
457
|
-
* @example
|
|
458
|
-
* multiple orderBys
|
|
459
|
-
* ```tsx
|
|
460
|
-
* const orderBy = buildOrderBy([q.desc("createdAt"), q.asc("title")]);
|
|
461
|
-
* // result: [
|
|
462
|
-
* // { sortingField: "createdAt", sortType: "DESC" },
|
|
463
|
-
* // { sortingField: "title", sortType: "ASC" }
|
|
464
|
-
* // ]
|
|
465
|
-
* ```
|
|
466
|
-
*/
|
|
467
|
-
function buildOrderBy(input) {
|
|
468
|
-
const orderBys = Array.isArray(input) ? input : [input];
|
|
469
|
-
if (!orderBys.every((ob) => ob[INTERNAL_KIND] === "ORDER_BY")) throw new Error("orderBy conditions cannot be constructed manually. Use the 'q' helper.");
|
|
470
|
-
return orderBys.map((orderBy) => ({
|
|
471
|
-
sortingField: orderBy.sortingField,
|
|
472
|
-
sortType: orderBy.sortType
|
|
473
|
-
}));
|
|
474
|
-
}
|
|
475
|
-
function dealiasOrderBy(orderbys, aliases) {
|
|
476
|
-
return orderbys.map((orderBy) => {
|
|
477
|
-
const subject = aliases[orderBy.sortingField];
|
|
478
|
-
if (!subject) throw new Error(`Could not find an alias for subject "${orderBy.sortingField}"`);
|
|
479
|
-
return {
|
|
480
|
-
...orderBy,
|
|
481
|
-
sortingField: subject
|
|
482
|
-
};
|
|
483
|
-
});
|
|
484
|
-
}
|
|
485
|
-
/**
|
|
486
|
-
* Replaces filter subjects with their aliased values.
|
|
487
|
-
*
|
|
488
|
-
* Throws an error if any filter subject does not have a corresponding alias in the provided mapping.
|
|
489
|
-
*
|
|
490
|
-
* @example
|
|
491
|
-
* ```tsx
|
|
492
|
-
* const criteria = buildFilterCriteria(q.text("name").contains("John"));
|
|
493
|
-
* const aliases = { name: "abcxy123" };
|
|
494
|
-
* const dealiased = dealiasFilterCriteria(criteria, aliases);
|
|
495
|
-
* // Result: filter subject is now "abcxyz123" instead of "name"
|
|
496
|
-
* ```
|
|
497
|
-
*/
|
|
498
|
-
function dealiasFilterCriteria(criteria, aliases) {
|
|
499
|
-
if (!criteria.filterConditionGroup) return criteria;
|
|
500
|
-
return { filterConditionGroup: {
|
|
501
|
-
...criteria.filterConditionGroup,
|
|
502
|
-
filterGroups: criteria.filterConditionGroup.filterGroups.map((group) => ({
|
|
503
|
-
...group,
|
|
504
|
-
filters: group.filters.map(dealiasFilter)
|
|
505
|
-
}))
|
|
506
|
-
} };
|
|
507
|
-
function dealiasFilter(filter) {
|
|
508
|
-
const subject = aliases[filter.subject];
|
|
509
|
-
if (!subject) throw new Error(`Could not find an alias for subject "${subject}"`);
|
|
510
|
-
return {
|
|
511
|
-
...filter,
|
|
512
|
-
subject
|
|
513
|
-
};
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
function stripInternalKind(item) {
|
|
517
|
-
const { [INTERNAL_KIND]: _,...rest } = item;
|
|
518
|
-
return rest;
|
|
519
|
-
}
|
|
520
|
-
function isFilterGroup(item) {
|
|
521
|
-
return item[INTERNAL_KIND] === "LOGICAL_GROUP";
|
|
522
|
-
}
|
|
523
|
-
function isFilter(item) {
|
|
524
|
-
return item[INTERNAL_KIND] === "FILTER";
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
//#endregion
|
|
528
|
-
export { q as a, dealiasOrderBy as i, buildOrderBy as n, dealiasFilterCriteria as r, buildFilterCriteria as t };
|
package/dist/react.d.ts
DELETED
package/dist/tanstack.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { _ as SoftrSDK } from "./types-CjB4xUg-.js";
|
|
2
|
-
|
|
3
|
-
//#region src/tanstack.d.ts
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* TanStack Start middleware. Injects a per-request Softr SDK instance with
|
|
7
|
-
* cookies forwarded automatically. The base URL is read from VITE_SOFTR_BASE_URL.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* import { withSDK } from '@softr/sdk/tanstack'
|
|
11
|
-
*
|
|
12
|
-
* export const getProjects = createServerFn()
|
|
13
|
-
* .middleware([withSDK])
|
|
14
|
-
* .handler(({ context }) => context.sdk.datasource('ds_projects').list())
|
|
15
|
-
*/
|
|
16
|
-
declare const withSDK: any;
|
|
17
|
-
//#endregion
|
|
18
|
-
export { type SoftrSDK, withSDK };
|