@xanots/sdk 0.0.10 → 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/CHANGELOG.md +17 -0
- package/README.md +38 -0
- package/dist/.build-fingerprint +1 -1
- package/dist/bin.js +7 -6
- package/dist/bundle.d.ts +218 -0
- package/dist/bundle.js +143 -0
- package/dist/{chunk-5YCQ2QHH.js → chunk-22TKBSDV.js} +2 -2
- package/dist/{chunk-YYFXVYPX.js → chunk-4IF54NU5.js} +3 -3
- package/dist/{chunk-W24FJHPD.js → chunk-4Q7ZOHH7.js} +2 -2
- package/dist/{chunk-4BXJGVZ3.js → chunk-BC2C5GVI.js} +2 -69
- package/dist/chunk-BSK7ELHU.js +70 -0
- package/dist/chunk-EHP3WPEG.js +21 -0
- package/dist/{chunk-75Z74TA7.js → chunk-G4EJMQLD.js} +2 -2
- package/dist/{chunk-I7DQDJAM.js → chunk-HYBN4H3F.js} +38 -46
- package/dist/chunk-OHX6MIUZ.js +184 -0
- package/dist/{chunk-VKSOTZK3.js → chunk-OWGCOGKK.js} +155 -3
- package/dist/{chunk-LBYWGMOA.js → chunk-QK7ZQJLP.js} +140 -20
- package/dist/{chunk-5R73LFWK.js → chunk-QYMAZRAU.js} +7 -7
- package/dist/{chunk-ACCBOMCB.js → chunk-RCT7UX7B.js} +12 -12
- package/dist/{chunk-P6TAVLOX.js → chunk-UOZMSF4C.js} +15 -8
- package/dist/{chunk-7JDT4PBU.js → chunk-VAF6A3YD.js} +5 -179
- package/dist/{chunk-OYMR5AMJ.js → chunk-XEOX6AM7.js} +2 -2
- package/dist/cli.js +6 -5
- package/dist/{codegen-command-GB3H2KQ7.js → codegen-command-FUT2KJB6.js} +15 -12
- package/dist/codegen.d.ts +2 -1
- package/dist/{deploy-command-QTIVA22A.js → deploy-command-IP7V7GT4.js} +8 -7
- package/dist/index.d.ts +6 -4
- package/dist/index.js +10 -9
- package/dist/{init-command-MAXULNAD.js → init-command-NPVL32L6.js} +8 -7
- package/dist/internal.d.ts +4 -4
- package/dist/internal.js +62 -40
- package/dist/io-P2H75UV2.js +12 -0
- package/dist/{lock-GFXD6G2E.js → lock-46FWYE4D.js} +3 -2
- package/dist/{lock-commands-DQ7CUMIV.js → lock-commands-ZZKZ4LZJ.js} +8 -7
- package/dist/node.d.ts +5 -4
- package/dist/node.js +12 -11
- package/dist/{preflight-command-GZ2GE5RN.js → preflight-command-K346GPTY.js} +8 -7
- package/dist/{release-command-YUBTNHVX.js → release-command-IMNTIVWK.js} +14 -13
- package/dist/response-BQVQ24l1.d.ts +844 -0
- package/dist/{store-BG1UPZ3Z.d.ts → store-BLyNeQ8S.d.ts} +16 -3
- package/dist/{upgrade-command-FB5QJ363.js → upgrade-command-BN3EHAOI.js} +8 -7
- package/dist/{workspace-command-43P42FBP.js → workspace-command-MNK7Y7MQ.js} +15 -12
- package/dist/{response-CVAE2kMj.d.ts → xdo-BjJj5W_E.d.ts} +1 -837
- package/guides/typed-frontend.md +1 -1
- package/llms/filters.md +11 -10
- package/llms/kinds-core.md +1 -1
- package/llms/statements-data.md +3 -1
- package/llms/values.md +1 -1
- package/llms-full.txt +41 -30
- package/llms.txt +25 -17
- package/manifest.json +2 -2
- package/package.json +7 -2
- package/dist/io-M7XZEMK7.js +0 -11
|
@@ -0,0 +1,844 @@
|
|
|
1
|
+
import { V as Value, h as FilterXdo, S as StackItemXdo, k as ResultItemXdo } from './xdo-BjJj5W_E.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A statement's per-test MOCK — the value a step returns instead of doing its
|
|
5
|
+
* work, when one specific test runs.
|
|
6
|
+
*
|
|
7
|
+
* Authored keyed by TEST NAME, which is what the Xano editor shows and what
|
|
8
|
+
* XanoScript spells. The stored form is keyed by test ID; the rewrite happens
|
|
9
|
+
* at kind-encode time, the only place that knows both the stack and the test
|
|
10
|
+
* list (see `../kinds/test-mocks.js`).
|
|
11
|
+
*
|
|
12
|
+
* A mock applies ONLY while its test runs. It has no effect on a normal
|
|
13
|
+
* request, so mocking a step does not change what the deployed endpoint does.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* One mock: a value, or a value plus `enabled`.
|
|
18
|
+
*
|
|
19
|
+
* The bare form means enabled. The object form exists so a mock can be kept
|
|
20
|
+
* around switched off — the editor stores a disabled mock rather than deleting
|
|
21
|
+
* it, and dropping it on encode would lose an authored artefact.
|
|
22
|
+
*/
|
|
23
|
+
type MockEntry = Value | {
|
|
24
|
+
value: Value;
|
|
25
|
+
enabled?: boolean;
|
|
26
|
+
};
|
|
27
|
+
/** A statement's mocks, keyed by the name of the test each applies to. */
|
|
28
|
+
type MockMap = Record<string, MockEntry>;
|
|
29
|
+
/** The stored `mvp_test_mock` shape. */
|
|
30
|
+
interface MockXdo {
|
|
31
|
+
value: string;
|
|
32
|
+
tag: string;
|
|
33
|
+
filters: unknown[];
|
|
34
|
+
enabled: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Statement model, base envelope encoder, and registry (U5 — the KTD-4
|
|
39
|
+
* extensibility seam).
|
|
40
|
+
*
|
|
41
|
+
* The real stored statement shape (from the golden fixture's `run[0]`) is lean:
|
|
42
|
+
* `{name, as?, context, input}`. The base encoder fills the common envelope
|
|
43
|
+
* (`input: []` default) so each concrete statement factory only declares its
|
|
44
|
+
* `name`, optional `as`, and `context`. The registry maps statement name →
|
|
45
|
+
* factory so the eventual ~500-statement catalog plugs in here.
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The type-level contract linking a branded db statement (the **producer** —
|
|
50
|
+
* `db.get`/`db.query`/`db.add`/`db.edit`/`db.patch`/`db.add_or_edit`/`db.has`/
|
|
51
|
+
* `db.bulk.patch`/`db.bulk.delete`, each returning `Statement & AsShapeBrand<…>`)
|
|
52
|
+
* to `InferResponse`'s single-variable trace (the **consumer** — `TraceVar`,
|
|
53
|
+
* which destructures this shape). Both `__as` (the stack variable the statement
|
|
54
|
+
* binds) and `__shape` (the row shape it produces) are phantom carriers — never
|
|
55
|
+
* present at runtime. Naming the contract here keeps producer and consumer
|
|
56
|
+
* compiler-linked, so any further branded statement joins the trace by extending
|
|
57
|
+
* this type with zero edits to the trace logic.
|
|
58
|
+
*/
|
|
59
|
+
type AsShapeBrand<As extends string, Shape> = {
|
|
60
|
+
readonly __as: As;
|
|
61
|
+
readonly __shape: Shape;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* The two envelope members every stack item carries, whatever it does.
|
|
65
|
+
*
|
|
66
|
+
* They are editor affordances rather than statement arguments — `disabled` is
|
|
67
|
+
* how a step is commented out (it stays in the stack; the run engine skips it),
|
|
68
|
+
* and `description` is the note shown on the step. `encodeStatement` writes both
|
|
69
|
+
* for every statement, so every factory accepts them: the generated ones as two
|
|
70
|
+
* more optional fields on their argument object, the positional specials as a
|
|
71
|
+
* trailing options argument.
|
|
72
|
+
*
|
|
73
|
+
* Both are elided at their defaults on both sides of a round trip, so setting one
|
|
74
|
+
* to `false`/`""` is the same bytes as omitting it.
|
|
75
|
+
*/
|
|
76
|
+
interface StatementAnnotations {
|
|
77
|
+
/** Leave the step in the stack but skip it at runtime — Xano's "disable step". */
|
|
78
|
+
disabled?: boolean;
|
|
79
|
+
/** Free-text note on the step, shown in the editor beside it. */
|
|
80
|
+
description?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Per-test MOCKS — what this step returns instead of running, keyed by the
|
|
83
|
+
* name of the test the mock applies to.
|
|
84
|
+
*
|
|
85
|
+
* `{ "happy path": c.int(1) }` makes the step return `1` while the test named
|
|
86
|
+
* "happy path" runs, and changes nothing about a normal request. Wrap an
|
|
87
|
+
* entry as `{ value, enabled: false }` to keep a mock switched off.
|
|
88
|
+
*
|
|
89
|
+
* Every name must match a test declared on the object this statement belongs
|
|
90
|
+
* to; an unmatched name throws at encode time, because the engine silently
|
|
91
|
+
* ignores a mock whose key is not a real test id.
|
|
92
|
+
*/
|
|
93
|
+
mock?: MockMap;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* {@link StatementAnnotations} plus the result-filter option, for the statements
|
|
97
|
+
* that bind an `as` variable.
|
|
98
|
+
*
|
|
99
|
+
* Split from the annotations rather than folded into them so `asFilters` is only
|
|
100
|
+
* offered where there is a binding to attach it to: a statement that returns
|
|
101
|
+
* nothing (`precondition`, `switch`, `while`, …) should not surface the option
|
|
102
|
+
* in autocomplete at all. The runtime guard in {@link assertBindsAs} still
|
|
103
|
+
* backs this up for callers that reach past the types.
|
|
104
|
+
*/
|
|
105
|
+
interface StatementOptions extends StatementAnnotations {
|
|
106
|
+
/**
|
|
107
|
+
* Filters piped onto the result before it is bound — the editor's
|
|
108
|
+
* `return as token | upper`.
|
|
109
|
+
*
|
|
110
|
+
* Authored from the same `fl.*` catalog as value filters and applied in
|
|
111
|
+
* order, so `asFilters: [fl.trim(), fl.upper()]` trims and then upper-cases.
|
|
112
|
+
*
|
|
113
|
+
* The bound variable is RETYPED by the chain: `InferResponse` folds each
|
|
114
|
+
* filter's declared result, so a `db.query` bound through `[fl.count()]` is a
|
|
115
|
+
* `number`. Filters the engine declares as returning `any` (`get`, `set`,
|
|
116
|
+
* `json_decode`, …) fold to `unknown` — see `values/filter-result.ts`.
|
|
117
|
+
*/
|
|
118
|
+
asFilters?: FilterXdo[];
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Apply {@link StatementOptions} to a built statement.
|
|
122
|
+
*
|
|
123
|
+
* Only members that were actually authored are copied, so a factory's own
|
|
124
|
+
* `description` (a few statements route one) is not clobbered by an absent key.
|
|
125
|
+
*
|
|
126
|
+
* `asFilters` merges into the `output` envelope rather than replacing it: a db
|
|
127
|
+
* statement's column selection (`output.items`) and its result filters live in
|
|
128
|
+
* the same block, and dropping one to write the other would silently discard
|
|
129
|
+
* whichever the factory set first.
|
|
130
|
+
*/
|
|
131
|
+
declare function annotate<T extends Statement>(stmt: T, a?: StatementOptions): T;
|
|
132
|
+
/** What a statement factory returns before base-envelope encoding. */
|
|
133
|
+
interface Statement {
|
|
134
|
+
name: string;
|
|
135
|
+
as?: string;
|
|
136
|
+
context: unknown;
|
|
137
|
+
input?: unknown[];
|
|
138
|
+
/** `output` envelope. Lean (`{filters:[]}`) or rich (`{customize,filters,items}`) forms are both accepted and normalized to the full rich form. */
|
|
139
|
+
output?: unknown;
|
|
140
|
+
/** Statement description (defaults to `""`). */
|
|
141
|
+
description?: string;
|
|
142
|
+
/** Settings-registry bindings (defaults to `null`). */
|
|
143
|
+
settings_registry?: unknown[] | null;
|
|
144
|
+
/** Attached addons (defaults to `[]`). */
|
|
145
|
+
addon?: unknown[];
|
|
146
|
+
/** Async/runtime block (e.g. `mvp:call_agent`'s `{ mode }`); defaults to `null`. */
|
|
147
|
+
runtime?: unknown;
|
|
148
|
+
/**
|
|
149
|
+
* Encoded per-test mocks, keyed by test NAME until the owning kind rewrites
|
|
150
|
+
* the keys to test ids. Authored via the `mock` option, not set directly.
|
|
151
|
+
*/
|
|
152
|
+
mocks?: Record<string, MockXdo> | unknown;
|
|
153
|
+
/** Whether the statement is disabled in the stack (defaults to `false`). */
|
|
154
|
+
disabled?: boolean;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Return a statement sequence from a helper **without losing the tuple**
|
|
158
|
+
* (issue #11).
|
|
159
|
+
*
|
|
160
|
+
* `InferResponse` traces the `as` binding a `response` names by walking the
|
|
161
|
+
* stack's TUPLE type. Spreading anything typed `Statement[]` widens the whole
|
|
162
|
+
* array, and every binding — including ones declared *after* the spread —
|
|
163
|
+
* becomes invisible, so the response silently resolves to
|
|
164
|
+
* {@link StackTupleWidened}. A helper that emits more than one statement has to
|
|
165
|
+
* return an array, so any shared helper triggers it:
|
|
166
|
+
*
|
|
167
|
+
* ```ts
|
|
168
|
+
* // ✗ widens: every `as` in the calling stack stops being traceable
|
|
169
|
+
* function assertOk(v: string): Statement[] { return [s.lambda({…}), s.precondition({…})]; }
|
|
170
|
+
*
|
|
171
|
+
* // ✓ tuple survives the spread
|
|
172
|
+
* function assertOk(v: string) { return statements(s.lambda({…}), s.precondition({…})); }
|
|
173
|
+
* ```
|
|
174
|
+
*
|
|
175
|
+
* Type-level only — the returned array is the arguments verbatim, so there is no
|
|
176
|
+
* encoder involvement and no cost.
|
|
177
|
+
*
|
|
178
|
+
* **Fixed arity only.** A helper that builds its array in a loop cannot be a
|
|
179
|
+
* tuple; declare `responseShape` on the calling def instead.
|
|
180
|
+
*/
|
|
181
|
+
declare function statements<const T extends readonly Statement[]>(...items: T): T;
|
|
182
|
+
/** True when a statement name has a registered factory. */
|
|
183
|
+
declare function isRegisteredStatement(name: string): boolean;
|
|
184
|
+
/** Look up a registered factory, throwing a clear error when absent. */
|
|
185
|
+
declare function getStatementFactory(name: string): (...args: any[]) => Statement;
|
|
186
|
+
/**
|
|
187
|
+
* Encode a statement into the stored `StackItemXdo`, filling the **full**
|
|
188
|
+
* persisted envelope. Every stored statement carries the same 12 keys
|
|
189
|
+
* regardless of type (confirmed against live `mvp_query`/`mvp_tool`), so the
|
|
190
|
+
* envelope is uniform here rather than per-statement: empty members are emitted
|
|
191
|
+
* with their canonical defaults so the output is 1:1 with the engine's
|
|
192
|
+
* persisted form. `_xsid` is engine-generated on import; we emit `""` (the
|
|
193
|
+
* stored placeholder) so the key is present for comparison.
|
|
194
|
+
*/
|
|
195
|
+
declare function encodeStatement(stmt: Statement): StackItemXdo;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Shared field encoder (KTD-6). Function inputs and table columns are nearly
|
|
199
|
+
* the same stored shape; this encoder fills the common defaults and is
|
|
200
|
+
* parameterized by a `FieldContext` for the three spots where they differ:
|
|
201
|
+
* `customize` (`""` vs `{}`), `market_item` id types (string vs numeric), and
|
|
202
|
+
* whether `description` is emitted.
|
|
203
|
+
*/
|
|
204
|
+
|
|
205
|
+
/** Field visibility — the engine's `access` enum. */
|
|
206
|
+
type FieldAccess = "public" | "private" | "internal";
|
|
207
|
+
/** Valid `format` values for text fields (per the engine's text-field schema). */
|
|
208
|
+
type TextFormat = "" | "plaintext" | "yaml" | "html" | "xml" | "markdown";
|
|
209
|
+
/** Field cardinality — `"single"` (scalar) or `"list"` (array column). */
|
|
210
|
+
type FieldStyleType = "single" | "list";
|
|
211
|
+
interface FieldOptions {
|
|
212
|
+
required?: boolean;
|
|
213
|
+
nullable?: boolean;
|
|
214
|
+
/**
|
|
215
|
+
* Default value. Authored as a `string`, `number`, or `boolean` for
|
|
216
|
+
* ergonomics (`default: 0`, `default: false`); the engine stores it as a
|
|
217
|
+
* string, so it's coerced at encode time (`0` → `"0"`, `false` → `"false"`).
|
|
218
|
+
*
|
|
219
|
+
* On a **table column** the default must stay within the Basic Multilingual
|
|
220
|
+
* Plane: a 4-byte character (codepoint > U+FFFF — emoji, CJK-extension glyphs)
|
|
221
|
+
* is mangled into an invalid UTF-8 sequence by the engine's default pipeline
|
|
222
|
+
* and is rejected at export/encode time rather than 500ing at deploy with
|
|
223
|
+
* Postgres `22021` (issue #45). BMP characters (accents, `€`, most CJK) store
|
|
224
|
+
* fine. A *function/endpoint input* default binds at runtime and has no limit.
|
|
225
|
+
*/
|
|
226
|
+
default?: string | number | boolean;
|
|
227
|
+
/**
|
|
228
|
+
* Persist **no `default` key at all** for this field, rather than the empty
|
|
229
|
+
* `default: ""` every other field carries.
|
|
230
|
+
*
|
|
231
|
+
* Set on a table's `uuid` PRIMARY KEY, which is the one column the engine
|
|
232
|
+
* stores this way — its value is engine-generated, so there is nothing for a
|
|
233
|
+
* default to mean, and absent vs empty are different stored bytes. Applied
|
|
234
|
+
* automatically by `idType: "uuid"`; you rarely set it by hand.
|
|
235
|
+
*
|
|
236
|
+
* NOT a property of `uuid` in general: an ordinary (non-key) `uuid` column
|
|
237
|
+
* does carry `default: ""`. Mutually exclusive with {@link default}.
|
|
238
|
+
*/
|
|
239
|
+
noDefault?: boolean;
|
|
240
|
+
description?: string;
|
|
241
|
+
/**
|
|
242
|
+
* Methods/filters applied at bind time. Each entry is either a bare name
|
|
243
|
+
* (`"trim"`), a colon-form string with args (`"min:8"` → `{name:"min",
|
|
244
|
+
* arg:["8"]}`), or an explicit `{ name, arg }` object.
|
|
245
|
+
*/
|
|
246
|
+
methods?: MethodSpec[];
|
|
247
|
+
/** Enum values (for `type:"enum"` fields), e.g. `["draft","live"]`. */
|
|
248
|
+
values?: Array<string | number>;
|
|
249
|
+
mode?: string;
|
|
250
|
+
/** Text-field display format (text fields only; the engine drops it elsewhere). */
|
|
251
|
+
format?: TextFormat;
|
|
252
|
+
sensitive?: boolean;
|
|
253
|
+
/**
|
|
254
|
+
* Merge the referenced object's fields into this one rather than nesting them.
|
|
255
|
+
*
|
|
256
|
+
* **Leave this unset** unless reproducing a pulled field. It defaults to `false`,
|
|
257
|
+
* which is what every field this SDK authors from scratch wants; it is here so a
|
|
258
|
+
* pulled workspace's field can be recovered as a readable `f.*` call instead of
|
|
259
|
+
* degrading to `rawField()`. Paired with {@link hidden} in the wild — 584 fields
|
|
260
|
+
* across the sweep carry `merge: true` with a `hidden` list beside it.
|
|
261
|
+
*/
|
|
262
|
+
merge?: boolean;
|
|
263
|
+
/**
|
|
264
|
+
* Names to hide from this field's expansion (e.g. `["created_at"]`).
|
|
265
|
+
*
|
|
266
|
+
* **Leave this unset** unless reproducing a pulled field; it defaults to `[]`.
|
|
267
|
+
* Each entry is resolved as a name and removed from the expanded shape, so an
|
|
268
|
+
* entry naming nothing hides nothing — a stored `[""]` is a real spelling that
|
|
269
|
+
* appears in the wild and round-trips verbatim here rather than being guessed at.
|
|
270
|
+
*/
|
|
271
|
+
hidden?: readonly string[];
|
|
272
|
+
/** Field visibility in API output. Defaults to `"public"`. */
|
|
273
|
+
access?: FieldAccess;
|
|
274
|
+
style?: {
|
|
275
|
+
type: FieldStyleType;
|
|
276
|
+
};
|
|
277
|
+
/**
|
|
278
|
+
* Length bounds for an array field. Both members are `json`-typed in the
|
|
279
|
+
* engine, not numeric — the editor declares them as `json` and every consumer
|
|
280
|
+
* reads them through a numeric coercion (`+list.max`) — so a bound can arrive
|
|
281
|
+
* as `5` or as `"5"` and neither spelling is wrong.
|
|
282
|
+
*
|
|
283
|
+
* That is also why "unset" has no single spelling: an empty `json` control
|
|
284
|
+
* serializes to `""` on 8,814 fields in the sweep and to `{}` on two. Codegen
|
|
285
|
+
* elides the block whenever every member is blank in either form (see
|
|
286
|
+
* `hasNoListBounds`), so only a bound that is actually SET reaches this type.
|
|
287
|
+
*/
|
|
288
|
+
list?: {
|
|
289
|
+
min?: string | number;
|
|
290
|
+
max?: string | number;
|
|
291
|
+
};
|
|
292
|
+
vector?: {
|
|
293
|
+
size: number;
|
|
294
|
+
};
|
|
295
|
+
/**
|
|
296
|
+
* Array/list field — stored as `style:{type:"list"}` (e.g. `int[]`, `object[]`).
|
|
297
|
+
* Ignored when an explicit `style` is given.
|
|
298
|
+
*/
|
|
299
|
+
array?: boolean;
|
|
300
|
+
/** Nested fields for `type:"obj"` columns; each is itself a named, typed field. */
|
|
301
|
+
children?: NestedField[];
|
|
302
|
+
/**
|
|
303
|
+
* Per-column overrides applied to this field's EXPANSION, keyed by the
|
|
304
|
+
* expanded column's name. Meaningful on a merged field — an
|
|
305
|
+
* {@link input.dbLink} — where the engine expands a table's columns into
|
|
306
|
+
* request inputs and consults this map for each one.
|
|
307
|
+
*
|
|
308
|
+
* **Leave this unset** unless reproducing a pulled field; it defaults to `{}`.
|
|
309
|
+
* Xano's own CRUD scaffold writes it, so it is the common shape in a pulled
|
|
310
|
+
* workspace, not an edge case.
|
|
311
|
+
*/
|
|
312
|
+
customize?: Readonly<Record<string, FieldCustomization>>;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* One expanded column's override inside a merged field's {@link
|
|
316
|
+
* FieldOptions.customize} map.
|
|
317
|
+
*
|
|
318
|
+
* Every member restates what the column already declares, so an omitted member
|
|
319
|
+
* is not "inherit" — it is the stored default (`hidden:false`, `required:false`,
|
|
320
|
+
* `default:""`, no methods). Author the ones you mean to change and accept the
|
|
321
|
+
* rest, which is what the editor writes.
|
|
322
|
+
*/
|
|
323
|
+
interface FieldCustomization {
|
|
324
|
+
/** Drop this column from the expansion entirely. */
|
|
325
|
+
hidden?: boolean;
|
|
326
|
+
/** Whether the expanded input is required. */
|
|
327
|
+
required?: boolean;
|
|
328
|
+
/** Default for the expanded input; stored as a string (`0` → `"0"`). */
|
|
329
|
+
default?: string | number | boolean;
|
|
330
|
+
/** Methods/filters appended to the column's own, in the same spellings as {@link FieldOptions.methods}. */
|
|
331
|
+
methods?: readonly MethodSpec[];
|
|
332
|
+
/** Overrides for an object column's OWN children, keyed by child name. */
|
|
333
|
+
customize?: Readonly<Record<string, FieldCustomization>>;
|
|
334
|
+
}
|
|
335
|
+
/** A nested field inside an object column's `children` — a named, typed `FieldOptions`. */
|
|
336
|
+
interface NestedField extends FieldOptions {
|
|
337
|
+
name: string;
|
|
338
|
+
type: string;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* A field method/filter: a bare name (`"trim"`), a colon-form string carrying
|
|
342
|
+
* args (`"min:8"`, `"min:8:foo"` — first segment is the name, the rest are
|
|
343
|
+
* args), or an explicit `{ name, arg }` object.
|
|
344
|
+
*/
|
|
345
|
+
type MethodSpec = string | {
|
|
346
|
+
name: string;
|
|
347
|
+
arg?: Array<string | number>;
|
|
348
|
+
};
|
|
349
|
+
/**
|
|
350
|
+
* A type-narrowed {@link MethodSpec} for a field constructor: a bare method name
|
|
351
|
+
* from the field type's valid set `N` (`"trim"`), the colon-form carrying args
|
|
352
|
+
* (`"min:8"`), or the explicit `{ name, arg }` object — which stays a universal
|
|
353
|
+
* escape hatch for any name the per-type union doesn't enumerate. The per-type
|
|
354
|
+
* `N` unions live in `fields/generated/field-methods.generated.ts`.
|
|
355
|
+
*/
|
|
356
|
+
type MethodArg<N extends string> = N | `${N}:${string}` | {
|
|
357
|
+
name: string;
|
|
358
|
+
arg?: Array<string | number>;
|
|
359
|
+
};
|
|
360
|
+
/**
|
|
361
|
+
* An options type `T` with its `methods` array widened to `readonly`. Field/input
|
|
362
|
+
* constructors capture their options via a `const` type parameter so literal
|
|
363
|
+
* flags (`required`/`nullable`/`array`) survive for `InferInput`; `const` also
|
|
364
|
+
* makes any inline `methods: [...]` a readonly tuple, so a constructor's options
|
|
365
|
+
* constraint must accept readonly arrays. The runtime cast back to `FieldOptions`
|
|
366
|
+
* is safe — the encoder only ever reads (`.map`) the methods.
|
|
367
|
+
*/
|
|
368
|
+
type ReadonlyMethods<T, N extends string> = Omit<T, "methods"> & {
|
|
369
|
+
methods?: readonly MethodArg<N>[];
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Value-type algebra for the typed descriptor layer (U1/U2).
|
|
374
|
+
*
|
|
375
|
+
* Input and column constructors (`input.*`, `f.*`) return a runtime descriptor
|
|
376
|
+
* of exactly `{ type, options }`. This module adds a **phantom brand** to those
|
|
377
|
+
* return types that carries, at the TYPE LEVEL only, the field's value type `V`
|
|
378
|
+
* and the literal options object `O` the caller passed. The brand props are
|
|
379
|
+
* optional and never assigned at runtime, so the emitted object is unchanged and
|
|
380
|
+
* every branded descriptor stays structurally assignable to the un-branded
|
|
381
|
+
* `FieldDescriptor` / `InputDescriptor` — existing consumers are unaffected.
|
|
382
|
+
*
|
|
383
|
+
* `InferInput` (see `../inputs/infer.ts`) reads these brands to turn a query's
|
|
384
|
+
* declared `input` map into the request-payload TS type. The same algebra powers
|
|
385
|
+
* nested-object inference, since object `children` are built from `f.*`.
|
|
386
|
+
*/
|
|
387
|
+
/**
|
|
388
|
+
* Opaque runtime value of a file input/column. The request payload carries a
|
|
389
|
+
* resource reference (path/metadata), not the raw bytes — model it structurally
|
|
390
|
+
* rather than as `unknown` so a consumer at least sees an object shape.
|
|
391
|
+
*/
|
|
392
|
+
interface XanoFileRef {
|
|
393
|
+
/** Vault path, e.g. `/vault/<…>/<name>`. Join it to your base URL — see {@link import("./file-url.js").fileUrl}. */
|
|
394
|
+
path?: string;
|
|
395
|
+
name?: string;
|
|
396
|
+
type?: string;
|
|
397
|
+
size?: number;
|
|
398
|
+
/** Storage visibility as stored on the column (`"public"` / `"private"`). */
|
|
399
|
+
access?: string;
|
|
400
|
+
/** Type-specific metadata — e.g. `{ width, height }` on an image. */
|
|
401
|
+
meta?: unknown;
|
|
402
|
+
/**
|
|
403
|
+
* ⚠ The engine's own absolute URL, which on a tenant-scoped environment omits
|
|
404
|
+
* the `/tenant/<name>` segment and 404s. Do NOT read it directly: pass the
|
|
405
|
+
* file to `fileUrl(file, baseUrl)`, which joins the correct `path` to the base
|
|
406
|
+
* URL your client already has (issue #31).
|
|
407
|
+
*/
|
|
408
|
+
url?: string;
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Opaque runtime value of a raw file **upload** (`input.file()`).
|
|
412
|
+
*
|
|
413
|
+
* Distinct from {@link XanoFileRef}, and the distinction matters: this is the
|
|
414
|
+
* bytes as they arrive on the request (multipart, base64, or a fetched URI). It
|
|
415
|
+
* is not yet stored anywhere and cannot be written to a file column. Pass it to
|
|
416
|
+
* a `s.storage.create_*` statement (`create_image`, `create_attachment`, …) to
|
|
417
|
+
* store it and get back the {@link XanoFileRef} a column holds.
|
|
418
|
+
*/
|
|
419
|
+
interface XanoFileUpload {
|
|
420
|
+
readonly __fileUpload?: never;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Marker value of a database-link input (`input.dbLink()`).
|
|
424
|
+
*
|
|
425
|
+
* Opaque on purpose: a dblink input does not bind a value of its own. The engine
|
|
426
|
+
* EXPANDS it into one input per column of the linked table, so a table with
|
|
427
|
+
* three columns turns one dblink entry into three request inputs. Read those by
|
|
428
|
+
* their own column names — `inp("email")`, not `inp("user__")`.
|
|
429
|
+
*/
|
|
430
|
+
interface XanoDbLink {
|
|
431
|
+
readonly __dbLink?: never;
|
|
432
|
+
}
|
|
433
|
+
/** Opaque runtime value of a geo input/column (a GeoJSON-shaped object). */
|
|
434
|
+
/** One `{ lng, lat }` position, as the engine both accepts and returns. */
|
|
435
|
+
interface XanoGeoPosition {
|
|
436
|
+
lng: number;
|
|
437
|
+
lat: number;
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* The value of an `f.geo.*` column: `{ type, data }`.
|
|
441
|
+
*
|
|
442
|
+
* Named for what it is rather than for GeoJSON, which this is NOT — the
|
|
443
|
+
* previous `XanoGeoJson` declared `{ type, coordinates }`, a shape the engine
|
|
444
|
+
* neither accepts nor returns (issue #208).
|
|
445
|
+
*
|
|
446
|
+
* The same shape works in BOTH directions, verified live: seeding
|
|
447
|
+
* `{ type: "point", data: { lng: 1, lat: 2 } }` reads back byte-identical, and
|
|
448
|
+
* a polygon seeded as `{ type: "poly", data: [{ lng, lat }, …] }` reads back
|
|
449
|
+
* with its ring closed for you. `type` is the engine's own abbreviation
|
|
450
|
+
* (`"point"`, `"poly"`, …), not the GeoJSON keyword, and `data` nests by
|
|
451
|
+
* geometry: an object for a point, an array of positions for a polygon.
|
|
452
|
+
*
|
|
453
|
+
* Raw WKT text (`c.text("POINT(1 2)")`) is also accepted wherever a value is
|
|
454
|
+
* taken — it is just not the typed path, because a read never returns one.
|
|
455
|
+
*/
|
|
456
|
+
interface XanoGeoValue {
|
|
457
|
+
type: string;
|
|
458
|
+
data: XanoGeoPosition | XanoGeoPosition[] | XanoGeoPosition[][];
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Phantom brand intersected onto a descriptor's return type. `V` is the field's
|
|
462
|
+
* base value type; `O` is the literal options object captured via a `const` type
|
|
463
|
+
* parameter at the call site. Both props are optional and never present at
|
|
464
|
+
* runtime.
|
|
465
|
+
*/
|
|
466
|
+
interface TypeBrand<V, O> {
|
|
467
|
+
readonly __value?: V;
|
|
468
|
+
readonly __opts?: O;
|
|
469
|
+
}
|
|
470
|
+
/** The base value type carried by a branded descriptor `D` (before array/nullable). */
|
|
471
|
+
type BrandValue<D> = D extends TypeBrand<infer V, unknown> ? V : unknown;
|
|
472
|
+
/** The literal options object captured on a branded descriptor `D`. */
|
|
473
|
+
type BrandOpts<D> = D extends TypeBrand<unknown, infer O> ? O : object;
|
|
474
|
+
type ApplyArray<T, O> = O extends {
|
|
475
|
+
array: true;
|
|
476
|
+
} ? T[] : T;
|
|
477
|
+
type ApplyNullable<T, O> = O extends {
|
|
478
|
+
nullable: true;
|
|
479
|
+
} ? T | null : T;
|
|
480
|
+
/**
|
|
481
|
+
* The full value type of a single branded descriptor `D`: its base value with
|
|
482
|
+
* `array` and `nullable` applied. (Optionality of the *key* is a map-level
|
|
483
|
+
* concern handled by {@link FromFieldMap}.)
|
|
484
|
+
*/
|
|
485
|
+
type ValueOf<D> = ApplyNullable<ApplyArray<BrandValue<D>, BrandOpts<D>>, BrandOpts<D>>;
|
|
486
|
+
/** Keys whose descriptor options declare `required: true`. */
|
|
487
|
+
type RequiredKeys<M> = {
|
|
488
|
+
[K in keyof M]: BrandOpts<M[K]> extends {
|
|
489
|
+
required: true;
|
|
490
|
+
} ? K : never;
|
|
491
|
+
}[keyof M];
|
|
492
|
+
/** Keys without `required: true` — optional in the produced payload type. */
|
|
493
|
+
type OptionalKeys<M> = Exclude<keyof M, RequiredKeys<M>>;
|
|
494
|
+
/**
|
|
495
|
+
* Turn a named map of branded descriptors into an object type: required inputs
|
|
496
|
+
* become required keys, everything else becomes an optional (`?`) key. Used both
|
|
497
|
+
* for a query's top-level `input` map and for nested `object` children.
|
|
498
|
+
*/
|
|
499
|
+
type FromFieldMap<M> = Prettify<{
|
|
500
|
+
[K in RequiredKeys<M>]: ValueOf<M[K]>;
|
|
501
|
+
} & {
|
|
502
|
+
[K in OptionalKeys<M>]?: ValueOf<M[K]>;
|
|
503
|
+
}>;
|
|
504
|
+
/**
|
|
505
|
+
* Turn a named map of branded descriptors into a **row** type — the read shape
|
|
506
|
+
* of a table. Unlike {@link FromFieldMap} (a request payload, where `required`
|
|
507
|
+
* gates key optionality), every declared column is present on a returned row, so
|
|
508
|
+
* all keys are required here; `nullable`/`array` still apply via {@link ValueOf}.
|
|
509
|
+
* Powers `InferRow<typeof table>` (see `../kinds/table.ts`).
|
|
510
|
+
*/
|
|
511
|
+
type RowFromFieldMap<M> = Prettify<{
|
|
512
|
+
[K in keyof M]: ValueOf<M[K]>;
|
|
513
|
+
}>;
|
|
514
|
+
/** Flatten an intersection into a single object literal for readable hovers. */
|
|
515
|
+
type Prettify<T> = {
|
|
516
|
+
[K in keyof T]: T[K];
|
|
517
|
+
} & {};
|
|
518
|
+
|
|
519
|
+
declare const REFERENCEABLE_KINDS: Set<string>;
|
|
520
|
+
/**
|
|
521
|
+
* A reference to another workspace object: its def handle, or a bare name.
|
|
522
|
+
*
|
|
523
|
+
* A def may carry an explicit `guid` (its Xano identity). When present it's used
|
|
524
|
+
* verbatim; otherwise the guid is derived from `name`. Pass def handles (which
|
|
525
|
+
* carry the `guid`) rather than bare names when an object sets an explicit guid,
|
|
526
|
+
* so the reference and the target agree on the *same* guid.
|
|
527
|
+
*/
|
|
528
|
+
type ObjectRef = string | {
|
|
529
|
+
name: string;
|
|
530
|
+
guid?: string;
|
|
531
|
+
};
|
|
532
|
+
/**
|
|
533
|
+
* The guid for a `(type, name)` pair. A seeded `xano.lock` override wins (the
|
|
534
|
+
* lock freezes identity across renames — see lock/store.ts); otherwise the
|
|
535
|
+
* deterministic 32-char hex derivation. Every reference and every emitted
|
|
536
|
+
* target flows through here, so a lock override propagates everywhere by
|
|
537
|
+
* construction — including guids embedded inside strings at authoring time.
|
|
538
|
+
*/
|
|
539
|
+
declare function deriveGuid(type: string, name: string): string;
|
|
540
|
+
/** Resolve a reference target (def handle or name) to the referenced object's guid. */
|
|
541
|
+
declare function resolveRef(type: string, target: ObjectRef): string;
|
|
542
|
+
|
|
543
|
+
/**
|
|
544
|
+
* AUTO-GENERATED by scripts/codegen-field-methods.ts — DO NOT EDIT BY HAND.
|
|
545
|
+
*
|
|
546
|
+
* Per-field-type method-name unions, distilled from the engine's column-create
|
|
547
|
+
* API schema (the per-type field-schema definitions). Each
|
|
548
|
+
* `f.<type>` / `input.<type>` constructor types its `methods` against the
|
|
549
|
+
* matching union so only names valid for that field type are accepted (the
|
|
550
|
+
* explicit `{ name, arg }` form remains a universal escape hatch).
|
|
551
|
+
*
|
|
552
|
+
* Regenerate with `npm run codegen:methods` (`-- --refresh` to re-distill upstream).
|
|
553
|
+
*/
|
|
554
|
+
/** Per-field-type method metadata (method name → colon-form arg type; `bool` = flag, no arg). */
|
|
555
|
+
declare const FIELD_METHODS: Readonly<Record<string, Readonly<Record<string, string>>>>;
|
|
556
|
+
/** Field methods valid on `decimal` fields. */
|
|
557
|
+
type DecimalMethod = "max" | "min";
|
|
558
|
+
/** Field methods valid on `email` fields. */
|
|
559
|
+
type EmailMethod = "lower" | "trim";
|
|
560
|
+
/** Field methods valid on `int` fields. */
|
|
561
|
+
type IntMethod = "max" | "min";
|
|
562
|
+
/** Field methods valid on `password` fields. */
|
|
563
|
+
type PasswordMethod = "max" | "min" | "minAlpha" | "minDigit" | "minLowerAlpha" | "minSymbol" | "minUpperAlpha" | "salt";
|
|
564
|
+
/** Field methods valid on `tableRef` fields. */
|
|
565
|
+
type TableRefMethod = "max" | "min";
|
|
566
|
+
/** Field methods valid on `text` fields. */
|
|
567
|
+
type TextMethod = "alphaOk" | "digitOk" | "lower" | "max" | "min" | "ok" | "pattern" | "startsWith" | "trim" | "upper";
|
|
568
|
+
/** Field methods valid on `vector` fields. */
|
|
569
|
+
type VectorMethod = "max" | "min";
|
|
570
|
+
|
|
571
|
+
/**
|
|
572
|
+
* Rich field-type catalog (`f.*`). A typed, validated authoring surface over the
|
|
573
|
+
* shared field encoder. Each constructor returns a {@link FieldDescriptor}
|
|
574
|
+
* (`{ type, options }`) carrying the **stored** type string — the engine's
|
|
575
|
+
* author-facing names differ from what it persists, so this layer applies the
|
|
576
|
+
* authoritative mapping (the engine's stored-type map):
|
|
577
|
+
*
|
|
578
|
+
* object → obj · timestamp → epochms · image → blob_img ·
|
|
579
|
+
* video → blob_video · audio → blob_audio · attachment → blob
|
|
580
|
+
*
|
|
581
|
+
* Every other type (text/int/decimal/bool/uuid/date/email/password/json/enum/
|
|
582
|
+
* vector/geo_*) is stored under its own name. Columns and inputs both consume
|
|
583
|
+
* descriptors; the per-context differences (`customize`, `market_item`,
|
|
584
|
+
* `description`) are still applied by {@link encodeField}.
|
|
585
|
+
*/
|
|
586
|
+
|
|
587
|
+
/** A typed field, ready to attach to a column/input name. */
|
|
588
|
+
interface FieldDescriptor {
|
|
589
|
+
/** The **stored** type string (post-mapping), e.g. `blob_img`, `epochms`. */
|
|
590
|
+
type: string;
|
|
591
|
+
options: FieldOptions;
|
|
592
|
+
}
|
|
593
|
+
/** A named map of fields — used for table schemas and object children. */
|
|
594
|
+
type FieldMap = Record<string, FieldDescriptor>;
|
|
595
|
+
/** Options accepted by every catalog constructor (no `values`/`children`/`vector` — those are positional). */
|
|
596
|
+
type FieldOpts = Omit<FieldOptions, "values" | "children" | "vector">;
|
|
597
|
+
/**
|
|
598
|
+
* {@link FieldOpts} with `methods` narrowed to the field type's valid method set
|
|
599
|
+
* `N` (see {@link MethodArg}). Types with no engine-declared methods use
|
|
600
|
+
* `MethodOpts<never>`, leaving only the `{ name, arg }` escape hatch.
|
|
601
|
+
*/
|
|
602
|
+
type MethodOpts<N extends string> = Omit<FieldOpts, "methods"> & {
|
|
603
|
+
methods?: MethodArg<N>[];
|
|
604
|
+
};
|
|
605
|
+
/** {@link MethodOpts} made safe to capture under a `const` type parameter (see {@link ReadonlyMethods}). */
|
|
606
|
+
type ConstMethodOpts<N extends string> = ReadonlyMethods<MethodOpts<N>, N>;
|
|
607
|
+
/** Convert a named field map into the encoder's `NestedField[]` form. */
|
|
608
|
+
declare function toNestedFields(map: FieldMap): NestedField[];
|
|
609
|
+
/**
|
|
610
|
+
* The stored scalar type of a `tableRef` FK, derived from its `type` option: a
|
|
611
|
+
* `uuid`-keyed reference stores a `string`, everything else (the default `int`)
|
|
612
|
+
* stores a `number`. Keeps `InferRow` honest — a FK column is the referenced
|
|
613
|
+
* table's PK value, never the loose `string | number`.
|
|
614
|
+
*/
|
|
615
|
+
type TableRefValue<O> = "uuid" extends (O extends {
|
|
616
|
+
type: infer T;
|
|
617
|
+
} ? T : never) ? string : number;
|
|
618
|
+
/** The rich field-type catalog. */
|
|
619
|
+
declare const f: {
|
|
620
|
+
readonly text: <const O extends ConstMethodOpts<TextMethod> = Record<string, never>>(options?: O) => FieldDescriptor & TypeBrand<string, O>;
|
|
621
|
+
readonly int: <const O extends ConstMethodOpts<IntMethod> = Record<string, never>>(options?: O) => FieldDescriptor & TypeBrand<number, O>;
|
|
622
|
+
readonly decimal: <const O extends ConstMethodOpts<DecimalMethod> = Record<string, never>>(options?: O) => FieldDescriptor & TypeBrand<number, O>;
|
|
623
|
+
readonly bool: <const O extends ConstMethodOpts<never> = Record<string, never>>(options?: O) => FieldDescriptor & TypeBrand<boolean, O>;
|
|
624
|
+
readonly uuid: <const O extends ConstMethodOpts<never> = Record<string, never>>(options?: O) => FieldDescriptor & TypeBrand<string, O>;
|
|
625
|
+
readonly date: <const O extends ConstMethodOpts<never> = Record<string, never>>(options?: O) => FieldDescriptor & TypeBrand<string, O>;
|
|
626
|
+
readonly email: <const O extends ConstMethodOpts<EmailMethod> = Record<string, never>>(options?: O) => FieldDescriptor & TypeBrand<string, O>;
|
|
627
|
+
/** Password field; defaults to `access:"internal"` (the engine's stored default). */
|
|
628
|
+
readonly password: <const O extends ConstMethodOpts<PasswordMethod> = Record<string, never>>(options?: O) => FieldDescriptor & TypeBrand<string, O>;
|
|
629
|
+
/**
|
|
630
|
+
* JSON column. Accepts an optional nested `children` schema — the structure the
|
|
631
|
+
* editor shows when a `json` field is expanded, and what a pulled workspace
|
|
632
|
+
* carries.
|
|
633
|
+
*
|
|
634
|
+
* `children` is spelled as an ARRAY of named, typed fields rather than the
|
|
635
|
+
* `FieldMap` {@link FieldCatalog.object} takes positionally. The two are not
|
|
636
|
+
* interchangeable: an object column's children are the column's own schema,
|
|
637
|
+
* while a json column's are a description of the shape stored inside it, which
|
|
638
|
+
* the engine persists in the order given. That order is part of the stored
|
|
639
|
+
* bytes, and a map does not preserve it.
|
|
640
|
+
*
|
|
641
|
+
* Without this there is no way to author a structured JSON column at all
|
|
642
|
+
* (issue #135).
|
|
643
|
+
*/
|
|
644
|
+
readonly json: <const O extends ConstMethodOpts<never> & {
|
|
645
|
+
children?: readonly NestedField[];
|
|
646
|
+
} = Record<string, never>>(options?: O) => FieldDescriptor & TypeBrand<unknown, O>;
|
|
647
|
+
/** Epoch-millisecond timestamp (authored as `timestamp`). */
|
|
648
|
+
readonly timestamp: <const O extends ConstMethodOpts<never> = Record<string, never>>(options?: O) => FieldDescriptor & TypeBrand<number, O>;
|
|
649
|
+
/** Image file resource (stored `blob_img`). */
|
|
650
|
+
readonly image: <const O extends ConstMethodOpts<never> = Record<string, never>>(options?: O) => FieldDescriptor & TypeBrand<XanoFileRef, O>;
|
|
651
|
+
/** Video file resource (stored `blob_video`). */
|
|
652
|
+
readonly video: <const O extends ConstMethodOpts<never> = Record<string, never>>(options?: O) => FieldDescriptor & TypeBrand<XanoFileRef, O>;
|
|
653
|
+
/** Audio file resource (stored `blob_audio`). */
|
|
654
|
+
readonly audio: <const O extends ConstMethodOpts<never> = Record<string, never>>(options?: O) => FieldDescriptor & TypeBrand<XanoFileRef, O>;
|
|
655
|
+
/** Generic file attachment (stored `blob`). */
|
|
656
|
+
readonly attachment: <const O extends ConstMethodOpts<never> = Record<string, never>>(options?: O) => FieldDescriptor & TypeBrand<XanoFileRef, O>;
|
|
657
|
+
readonly geo: {
|
|
658
|
+
readonly point: <const O extends ConstMethodOpts<never> = Record<string, never>>(options?: O) => FieldDescriptor & TypeBrand<XanoGeoValue, O>;
|
|
659
|
+
readonly multipoint: <const O extends ConstMethodOpts<never> = Record<string, never>>(options?: O) => FieldDescriptor & TypeBrand<XanoGeoValue, O>;
|
|
660
|
+
readonly linestring: <const O extends ConstMethodOpts<never> = Record<string, never>>(options?: O) => FieldDescriptor & TypeBrand<XanoGeoValue, O>;
|
|
661
|
+
readonly multilinestring: <const O extends ConstMethodOpts<never> = Record<string, never>>(options?: O) => FieldDescriptor & TypeBrand<XanoGeoValue, O>;
|
|
662
|
+
readonly polygon: <const O extends ConstMethodOpts<never> = Record<string, never>>(options?: O) => FieldDescriptor & TypeBrand<XanoGeoValue, O>;
|
|
663
|
+
readonly multipolygon: <const O extends ConstMethodOpts<never> = Record<string, never>>(options?: O) => FieldDescriptor & TypeBrand<XanoGeoValue, O>;
|
|
664
|
+
};
|
|
665
|
+
/**
|
|
666
|
+
* Enum field. `values` may be empty — that is an enum column added in the
|
|
667
|
+
* editor and not yet given its options, which the engine stores and which
|
|
668
|
+
* appears in the survey corpus. Refusing it made the SDK stricter than the
|
|
669
|
+
* engine and cost a real table its readable form.
|
|
670
|
+
*
|
|
671
|
+
* An empty `values` brands the column `never` — an enum permitting nothing can
|
|
672
|
+
* hold nothing. Note what that becomes downstream: `InferRow` surfaces the
|
|
673
|
+
* column as `undefined`, not `never`, so a read-time narrow written against
|
|
674
|
+
* `never` (`if (row.e === "x")`) is dead differently than it looks.
|
|
675
|
+
*/
|
|
676
|
+
readonly enum: <const V extends ReadonlyArray<string | number>, const O extends ConstMethodOpts<never> = Record<string, never>>(values: V, options?: O) => FieldDescriptor & TypeBrand<V[number], O>;
|
|
677
|
+
/** Vector field; `size` (>= 1) is the embedding dimensionality. */
|
|
678
|
+
readonly vector: <const O extends ConstMethodOpts<VectorMethod> = Record<string, never>>(size: number, options?: O) => FieldDescriptor & TypeBrand<number[], O>;
|
|
679
|
+
/** Nested object field (stored `obj`); `children` is a named field map. */
|
|
680
|
+
readonly object: <const C extends FieldMap, const O extends ConstMethodOpts<never> = Record<string, never>>(children: C, options?: O) => FieldDescriptor & TypeBrand<FromFieldMap<C>, O>;
|
|
681
|
+
/**
|
|
682
|
+
* Table-reference (foreign-key) field — the column holds the referenced
|
|
683
|
+
* table's primary key. The engine persists the link as a trailing `@` method
|
|
684
|
+
* carrying the target table's id (`{name:"@", arg:["dbo=<guid>"]}`); on import
|
|
685
|
+
* it parses that back into the column's `tableref_id`. The reference resolves to the
|
|
686
|
+
* table's deterministic guid via the shared cross-object resolver, so it
|
|
687
|
+
* agrees with the target table's payload `guid` with no shared registry.
|
|
688
|
+
*
|
|
689
|
+
* Defaults to an `int` column (matching an `int` primary key); pass
|
|
690
|
+
* `{ type: "uuid" }` to reference a uuid-keyed table. A reference column may
|
|
691
|
+
* only be `int` or `uuid` — the two valid primary-key types.
|
|
692
|
+
*
|
|
693
|
+
* @param table The referenced table (a `table()` def handle or its bare name).
|
|
694
|
+
* For a **self-reference** (e.g. `tweets.reply_to → tweets`), the table's
|
|
695
|
+
* `const` binding isn't assigned yet inside its own initializer — using the
|
|
696
|
+
* handle throws a "used before declaration" error. Pass the **bare name**
|
|
697
|
+
* instead: `f.tableRef("tweets", { type: "int" })`. Identity guids derive
|
|
698
|
+
* from `(type, name)`, so the name form resolves to the same guid.
|
|
699
|
+
*
|
|
700
|
+
* Byte-verified whole-object against a persisted table readback
|
|
701
|
+
* (`test/fixtures/tables/ex_field_table_ref.json`, asserted in
|
|
702
|
+
* `test/conformance/kinds-corpus.test.ts`): the `@` method carries
|
|
703
|
+
* `disabled:false`, sits last in `methods`, and its `dbo=` arg is the target
|
|
704
|
+
* table's payload guid.
|
|
705
|
+
*
|
|
706
|
+
* The engine asserts the referenced table's primary-key type matches
|
|
707
|
+
* (int↔int, uuid↔uuid). When the target is passed as a **def handle** its
|
|
708
|
+
* `idType` is in hand, so a mismatch throws here instead of surfacing as an
|
|
709
|
+
* import failure. The bare-name form (self-references) carries no schema —
|
|
710
|
+
* there is nothing to check against, and it is not guessed at.
|
|
711
|
+
*/
|
|
712
|
+
readonly tableRef: <const O extends ConstMethodOpts<TableRefMethod> & {
|
|
713
|
+
type?: "int" | "uuid";
|
|
714
|
+
} = Record<string, never>>(table: ObjectRef, options?: O) => FieldDescriptor & TypeBrand<TableRefValue<O>, O>;
|
|
715
|
+
};
|
|
716
|
+
|
|
717
|
+
/**
|
|
718
|
+
* `obj({...})` — a **dynamic** object value: an object literal whose members can
|
|
719
|
+
* be live references (`inp`/`ref`/`auth`/`col`) or constants. This is the
|
|
720
|
+
* missing sibling of `c.obj` (issue #42): `c.obj` takes plain JSON only and
|
|
721
|
+
* rejects nested tagged values, so it can't express `{ id: inp("id") }`.
|
|
722
|
+
*
|
|
723
|
+
* Xano stores a dynamic object as a single value with `tag: "const:expr2"` whose
|
|
724
|
+
* `value` is the object rendered as a **XanoScript expression string** (verified
|
|
725
|
+
* against the Xano engine's stored inline-value format). So `obj`
|
|
726
|
+
* serializes each member to its XanoScript form (`$input.x`, `$var.x`, `$auth`,
|
|
727
|
+
* `$db.col`, quoted strings, numbers) and wraps them in `{ … }`.
|
|
728
|
+
*
|
|
729
|
+
* Why `const:expr2` and not a structured `const:obj`: the Xano runtime value
|
|
730
|
+
* evaluator resolves `const:obj` by JSON-decoding its value — it
|
|
731
|
+
* treats the value as a *static JSON string*, so dynamic members (`$input.x`)
|
|
732
|
+
* would never resolve. Only `const:expr2` is run through the expression parser
|
|
733
|
+
* (it normalizes to `const:expr` and evaluates), so it is the sole
|
|
734
|
+
* representation that resolves live references inside an object literal. That
|
|
735
|
+
* choice is therefore runtime-verified, not a preference.
|
|
736
|
+
*
|
|
737
|
+
* The rendered string form (spacing/escaping) is now golden-verified: the
|
|
738
|
+
* `call_agent` object-args fixture in the conformance corpus pins the exact
|
|
739
|
+
* `const:expr` string this encoder emits for `obj({ question: inp(...) })`.
|
|
740
|
+
*
|
|
741
|
+
* **Supported members:** `inp()`, `ref()`, `auth()`, `col()`, `env()` /
|
|
742
|
+
* `setting()` / `sys.*`, `c.now()`, `c.text/int/decimal/bool/null`,
|
|
743
|
+
* `c.obj(…)` / `c.array([…])`, nested `obj`-style records, and arrays of those —
|
|
744
|
+
* each optionally carrying a **filter chain**, which renders as the expression
|
|
745
|
+
* language's own postfix pipe (`$var.row|get:"address.city"`).
|
|
746
|
+
*
|
|
747
|
+
* A constant record or list has two spellings that mean the same thing here: a
|
|
748
|
+
* bare `{…}` / `[…]` and `c.obj` / `c.array`. They render to identical bytes
|
|
749
|
+
* (issue #295) — `c.array` used to throw while the bare form worked, which made
|
|
750
|
+
* the empty list an export failure.
|
|
751
|
+
*
|
|
752
|
+
* The filter chain used to throw, and the rejection was wrong (#222). It
|
|
753
|
+
* collided constantly, because `db.get` binds `null` on a miss — the SDK's own
|
|
754
|
+
* headline gotcha — so almost every object built from a `db.get` result needs a
|
|
755
|
+
* null-safe drill, which compiles through the `get` filter. One team counted
|
|
756
|
+
* twenty pure-plumbing `s.set_var` statements written to work around it.
|
|
757
|
+
*
|
|
758
|
+
* The representation was never the obstacle: the engine's own parser stores
|
|
759
|
+
* `{ …, goals: [$q.goal_1, …]|filter:$$ != null, … }` as ONE `const:expr2`
|
|
760
|
+
* string, so a per-member chain is exactly what it carries. Nothing had to
|
|
761
|
+
* change in the engine; the SDK was guessing that it could not.
|
|
762
|
+
*
|
|
763
|
+
* **On evidence.** The value of an `expr2` is an expression string the engine
|
|
764
|
+
* parses — it is NOT XanoScript, and nothing validates its contents ahead of a
|
|
765
|
+
* live run. So what backs this is the engine's own parser fixtures (paired
|
|
766
|
+
* source → stored JSON), which show the exact string its tooling produces. A
|
|
767
|
+
* rendering outside that set is not "probably fine"; it is unverified. Keep the
|
|
768
|
+
* emitted grammar to shapes a fixture demonstrates.
|
|
769
|
+
*
|
|
770
|
+
* What still throws: a filter argument carrying its OWN chain (a trailing `|`
|
|
771
|
+
* binds to the whole value, so it cannot be written without changing meaning),
|
|
772
|
+
* a **disabled** filter (an expression string has nowhere to record that), and
|
|
773
|
+
* the remaining exotic tags (`output`/`response`/`toolset`/`reg`). Build those
|
|
774
|
+
* in a prior stack step and reference them with `ref`.
|
|
775
|
+
*/
|
|
776
|
+
|
|
777
|
+
/**
|
|
778
|
+
* A member of an {@link obj} literal — a {@link Value}, a raw scalar literal
|
|
779
|
+
* (`string`/`number`/`boolean`, coerced to the matching constant), a nested
|
|
780
|
+
* record, or an array. Raw scalars let `obj({ max_age_days: 3 })` and
|
|
781
|
+
* `obj({ greeting: "hi" })` *just work* without wrapping each in `c.int`/`c.text`.
|
|
782
|
+
*/
|
|
783
|
+
type ObjMember = Value | string | number | boolean | ObjInput | ObjMember[];
|
|
784
|
+
/** The record shape {@link obj} accepts: keys → members. */
|
|
785
|
+
interface ObjInput {
|
|
786
|
+
[key: string]: ObjMember;
|
|
787
|
+
}
|
|
788
|
+
/**
|
|
789
|
+
* A {@link Value} that also carries, **at the type level only**, the member
|
|
790
|
+
* record it was built from (`obj({ id: ref("u.id") })` → `ObjValue<{ id:
|
|
791
|
+
* RefValue<"u.id"> }>`). The `__obj` carrier is phantom — never present at
|
|
792
|
+
* runtime — and exists so `InferResponse` can recurse into the members and
|
|
793
|
+
* resolve each one the way it resolves a top-level response key (issue #118).
|
|
794
|
+
*
|
|
795
|
+
* Before this, `obj()` returned a bare `Value`: the members were erased at the
|
|
796
|
+
* signature, so the resolver saw no `__ref` to trace and every member landed on
|
|
797
|
+
* the `unknown` floor. `{ user: obj({ id: ref("u.id") }) }` derived `{ user:
|
|
798
|
+
* unknown }` while the identical refs written as object-literal keys derived
|
|
799
|
+
* `{ id: number | null }` — and the mismatch only surfaced downstream, as
|
|
800
|
+
* `unknown` flowing into a caller that had asked for a type.
|
|
801
|
+
*
|
|
802
|
+
* Because it is a subtype of `Value`, every existing `obj(...)` use — a request
|
|
803
|
+
* body, an agent's `args`, a statement field — keeps type-checking unchanged.
|
|
804
|
+
*/
|
|
805
|
+
type ObjValue<T extends ObjInput = ObjInput> = Value & {
|
|
806
|
+
readonly __obj: T;
|
|
807
|
+
};
|
|
808
|
+
/**
|
|
809
|
+
* Build a dynamic object {@link Value} from a record of members. Members may be
|
|
810
|
+
* references (`inp`/`ref`/`auth`/`col`), constants (`c.*`), nested records, or
|
|
811
|
+
* arrays. Emits `tag:"const:expr2"` — the engine's dynamic-object representation.
|
|
812
|
+
*
|
|
813
|
+
* ```ts
|
|
814
|
+
* obj({ id: inp("id"), name: c.text("Bob"), tags: [c.text("a"), ref("t")] })
|
|
815
|
+
* // → { value: '{ id: $input.id, name: "Bob", tags: ["a", $var.t] }', tag: "const:expr2", filters: [] }
|
|
816
|
+
* ```
|
|
817
|
+
*
|
|
818
|
+
* The member record is preserved on the return type as {@link ObjValue}, so a
|
|
819
|
+
* response built with `obj()` traces through `InferResponse` exactly as the same
|
|
820
|
+
* members written as object-literal keys would (issue #118). A dynamically-built
|
|
821
|
+
* `ObjInput` has no literal to read and degrades to unknown-valued members.
|
|
822
|
+
*/
|
|
823
|
+
declare function obj<T extends ObjInput>(fields: T): ObjValue<T>;
|
|
824
|
+
|
|
825
|
+
/**
|
|
826
|
+
* Response → `result[]` mapping, shared by every response-bearing kind
|
|
827
|
+
* (function, query, tool, middleware, and the response-bearing triggers).
|
|
828
|
+
* Extracted from the MVP's compile.ts so kinds beyond function can reuse it.
|
|
829
|
+
*/
|
|
830
|
+
|
|
831
|
+
/**
|
|
832
|
+
* A member of a record response — a {@link Value}, or a nested plain object
|
|
833
|
+
* literal which is auto-wrapped via {@link obj} (so `response: { user: { id:
|
|
834
|
+
* ref(x) } }` just works instead of failing tsc against `TaggedValue`; #133).
|
|
835
|
+
*/
|
|
836
|
+
type ResponseMember = Value | ObjInput;
|
|
837
|
+
/** A single `Value` response, or a record of named result items. */
|
|
838
|
+
type ResponseDef = Value | Record<string, ResponseMember>;
|
|
839
|
+
/** Map a response into `result[]`: one unnamed item for a single value, or
|
|
840
|
+
* one named item per key for a record. A record member that is a nested plain
|
|
841
|
+
* object is auto-wrapped via {@link obj} (a dynamic `const:expr2` value). */
|
|
842
|
+
declare function encodeResponse(response: ResponseDef | undefined): ResultItemXdo[];
|
|
843
|
+
|
|
844
|
+
export { type XanoDbLink as $, type TextFormat as A, type BrandOpts as B, type TextMethod as C, type DecimalMethod as D, type EmailMethod as E, FIELD_METHODS as F, type TypeBrand as G, type VectorMethod as H, type IntMethod as I, type XanoGeoPosition as J, type XanoGeoValue as K, annotate as L, type MethodArg as M, f as N, type ObjInput as O, type PasswordMethod as P, obj as Q, REFERENCEABLE_KINDS as R, type Statement as S, type TableRefMethod as T, statements as U, type ValueOf as V, type FieldOptions as W, type XanoFileRef as X, type Prettify as Y, type ReadonlyMethods as Z, type XanoFileUpload as _, encodeStatement as a, type ConstMethodOpts as a0, type AsShapeBrand as a1, type BrandValue as b, type FieldAccess as c, deriveGuid as d, encodeResponse as e, type FieldDescriptor as f, getStatementFactory as g, type FieldMap as h, isRegisteredStatement as i, type FieldOpts as j, type FieldStyleType as k, type FromFieldMap as l, type MethodOpts as m, type MethodSpec as n, type MockEntry as o, type MockMap as p, type MockXdo as q, resolveRef as r, type ObjMember as s, toNestedFields as t, type ObjValue as u, type ObjectRef as v, type ResponseDef as w, type RowFromFieldMap as x, type StatementAnnotations as y, type StatementOptions as z };
|