@proofkit/fmodata 0.1.0-alpha.3 → 0.1.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +357 -28
- package/dist/esm/client/base-table.d.ts +122 -5
- package/dist/esm/client/base-table.js +46 -5
- package/dist/esm/client/base-table.js.map +1 -1
- package/dist/esm/client/database.d.ts +20 -3
- package/dist/esm/client/database.js +62 -13
- package/dist/esm/client/database.js.map +1 -1
- package/dist/esm/client/delete-builder.js +24 -27
- package/dist/esm/client/delete-builder.js.map +1 -1
- package/dist/esm/client/entity-set.d.ts +9 -6
- package/dist/esm/client/entity-set.js +5 -1
- package/dist/esm/client/entity-set.js.map +1 -1
- package/dist/esm/client/filemaker-odata.d.ts +17 -4
- package/dist/esm/client/filemaker-odata.js +90 -27
- package/dist/esm/client/filemaker-odata.js.map +1 -1
- package/dist/esm/client/insert-builder.js +45 -34
- package/dist/esm/client/insert-builder.js.map +1 -1
- package/dist/esm/client/query-builder.d.ts +7 -2
- package/dist/esm/client/query-builder.js +273 -202
- package/dist/esm/client/query-builder.js.map +1 -1
- package/dist/esm/client/record-builder.d.ts +2 -2
- package/dist/esm/client/record-builder.js +50 -40
- package/dist/esm/client/record-builder.js.map +1 -1
- package/dist/esm/client/table-occurrence.d.ts +66 -2
- package/dist/esm/client/table-occurrence.js +36 -1
- package/dist/esm/client/table-occurrence.js.map +1 -1
- package/dist/esm/client/update-builder.js +39 -35
- package/dist/esm/client/update-builder.js.map +1 -1
- package/dist/esm/errors.d.ts +60 -0
- package/dist/esm/errors.js +122 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/index.d.ts +6 -3
- package/dist/esm/index.js +26 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/transform.d.ts +56 -0
- package/dist/esm/transform.js +107 -0
- package/dist/esm/transform.js.map +1 -0
- package/dist/esm/types.d.ts +21 -5
- package/dist/esm/validation.d.ts +6 -3
- package/dist/esm/validation.js +104 -33
- package/dist/esm/validation.js.map +1 -1
- package/package.json +10 -1
- package/src/client/base-table.ts +155 -8
- package/src/client/database.ts +116 -13
- package/src/client/delete-builder.ts +42 -43
- package/src/client/entity-set.ts +21 -11
- package/src/client/filemaker-odata.ts +132 -34
- package/src/client/insert-builder.ts +69 -37
- package/src/client/query-builder.ts +345 -233
- package/src/client/record-builder.ts +84 -59
- package/src/client/table-occurrence.ts +118 -4
- package/src/client/update-builder.ts +77 -49
- package/src/errors.ts +185 -0
- package/src/index.ts +31 -2
- package/src/transform.ts +236 -0
- package/src/types.ts +112 -34
- package/src/validation.ts +120 -36
|
@@ -3,6 +3,8 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
|
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
4
|
import buildQuery from "odata-query";
|
|
5
5
|
import { validateSingleResponse, validateListResponse } from "../validation.js";
|
|
6
|
+
import { RecordCountMismatchError } from "../errors.js";
|
|
7
|
+
import { transformTableName, transformFieldName, transformOrderByField, transformFieldNamesArray, transformResponseFields } from "../transform.js";
|
|
6
8
|
class QueryBuilder {
|
|
7
9
|
constructor(config) {
|
|
8
10
|
__publicField(this, "queryOptions", {});
|
|
@@ -33,6 +35,12 @@ class QueryBuilder {
|
|
|
33
35
|
const { "@id": _id, "@editLink": _editLink, ...rest } = data;
|
|
34
36
|
return rest;
|
|
35
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Gets the table ID (FMTID) if using entity IDs, otherwise returns the table name
|
|
40
|
+
*/
|
|
41
|
+
getTableId() {
|
|
42
|
+
return this.occurrence ? transformTableName(this.occurrence) : this.tableName;
|
|
43
|
+
}
|
|
36
44
|
select(...fields) {
|
|
37
45
|
const uniqueFields = [...new Set(fields)];
|
|
38
46
|
const newBuilder = new QueryBuilder({
|
|
@@ -62,6 +70,7 @@ class QueryBuilder {
|
|
|
62
70
|
* - Shorthand values are handled by odata-query
|
|
63
71
|
*/
|
|
64
72
|
transformFilter(filter) {
|
|
73
|
+
var _a;
|
|
65
74
|
if (typeof filter === "string") {
|
|
66
75
|
return filter;
|
|
67
76
|
}
|
|
@@ -84,12 +93,13 @@ class QueryBuilder {
|
|
|
84
93
|
const result = {};
|
|
85
94
|
const andConditions = [];
|
|
86
95
|
for (const [field, value] of Object.entries(filter)) {
|
|
96
|
+
const fieldId = ((_a = this.occurrence) == null ? void 0 : _a.baseTable) ? transformFieldName(field, this.occurrence.baseTable) : field;
|
|
87
97
|
if (Array.isArray(value)) {
|
|
88
98
|
if (value.length === 1) {
|
|
89
|
-
result[
|
|
99
|
+
result[fieldId] = value[0];
|
|
90
100
|
} else {
|
|
91
101
|
for (const op of value) {
|
|
92
|
-
andConditions.push({ [
|
|
102
|
+
andConditions.push({ [fieldId]: op });
|
|
93
103
|
}
|
|
94
104
|
}
|
|
95
105
|
} else if (value && typeof value === "object" && !(value instanceof Date) && !Array.isArray(value)) {
|
|
@@ -107,12 +117,12 @@ class QueryBuilder {
|
|
|
107
117
|
];
|
|
108
118
|
const isOperatorObject = operatorKeys.some((key) => key in value);
|
|
109
119
|
if (isOperatorObject) {
|
|
110
|
-
result[
|
|
120
|
+
result[fieldId] = value;
|
|
111
121
|
} else {
|
|
112
|
-
result[
|
|
122
|
+
result[fieldId] = value;
|
|
113
123
|
}
|
|
114
124
|
} else {
|
|
115
|
-
result[
|
|
125
|
+
result[fieldId] = value;
|
|
116
126
|
}
|
|
117
127
|
}
|
|
118
128
|
if (andConditions.length > 0) {
|
|
@@ -129,7 +139,21 @@ class QueryBuilder {
|
|
|
129
139
|
return this;
|
|
130
140
|
}
|
|
131
141
|
orderBy(orderBy) {
|
|
132
|
-
|
|
142
|
+
var _a;
|
|
143
|
+
if (((_a = this.occurrence) == null ? void 0 : _a.baseTable) && orderBy) {
|
|
144
|
+
if (Array.isArray(orderBy)) {
|
|
145
|
+
this.queryOptions.orderBy = orderBy.map(
|
|
146
|
+
(field) => transformOrderByField(String(field), this.occurrence.baseTable)
|
|
147
|
+
);
|
|
148
|
+
} else {
|
|
149
|
+
this.queryOptions.orderBy = transformOrderByField(
|
|
150
|
+
String(orderBy),
|
|
151
|
+
this.occurrence.baseTable
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
} else {
|
|
155
|
+
this.queryOptions.orderBy = orderBy;
|
|
156
|
+
}
|
|
133
157
|
return this;
|
|
134
158
|
}
|
|
135
159
|
top(count) {
|
|
@@ -142,13 +166,18 @@ class QueryBuilder {
|
|
|
142
166
|
}
|
|
143
167
|
/**
|
|
144
168
|
* Formats select fields for use in query strings.
|
|
169
|
+
* - Transforms field names to FMFIDs if using entity IDs
|
|
145
170
|
* - Wraps "id" fields in double quotes
|
|
146
171
|
* - URL-encodes special characters but preserves spaces
|
|
147
172
|
*/
|
|
148
|
-
formatSelectFields(select) {
|
|
173
|
+
formatSelectFields(select, baseTable) {
|
|
149
174
|
if (!select) return "";
|
|
150
175
|
const selectFieldsArray = Array.isArray(select) ? select : [select];
|
|
151
|
-
|
|
176
|
+
const transformedFields = baseTable ? transformFieldNamesArray(
|
|
177
|
+
selectFieldsArray.map((f) => String(f)),
|
|
178
|
+
baseTable
|
|
179
|
+
) : selectFieldsArray.map((f) => String(f));
|
|
180
|
+
return transformedFields.map((field) => {
|
|
152
181
|
if (field === "id") return `"id"`;
|
|
153
182
|
const encodedField = encodeURIComponent(String(field));
|
|
154
183
|
return encodedField.replace(/%20/g, " ");
|
|
@@ -168,6 +197,9 @@ class QueryBuilder {
|
|
|
168
197
|
relation: config.relation,
|
|
169
198
|
targetSchema,
|
|
170
199
|
targetOccurrence,
|
|
200
|
+
targetBaseTable: targetOccurrence == null ? void 0 : targetOccurrence.baseTable,
|
|
201
|
+
occurrence: targetOccurrence,
|
|
202
|
+
// Add occurrence for transformation
|
|
171
203
|
selectedFields,
|
|
172
204
|
nestedExpands: void 0
|
|
173
205
|
// TODO: Handle nested expands if needed
|
|
@@ -177,18 +209,25 @@ class QueryBuilder {
|
|
|
177
209
|
/**
|
|
178
210
|
* Builds OData expand query string from expand configurations.
|
|
179
211
|
* Handles nested expands recursively.
|
|
212
|
+
* Transforms relation names to FMTIDs if using entity IDs.
|
|
180
213
|
*/
|
|
181
214
|
buildExpandString(configs) {
|
|
182
215
|
if (configs.length === 0) {
|
|
183
216
|
return "";
|
|
184
217
|
}
|
|
185
218
|
return configs.map((config) => {
|
|
219
|
+
var _a;
|
|
220
|
+
const targetOccurrence = (_a = this.occurrence) == null ? void 0 : _a.navigation[config.relation];
|
|
221
|
+
const relationName = targetOccurrence && targetOccurrence.isUsingTableId() ? targetOccurrence.getTableId() : config.relation;
|
|
186
222
|
if (!config.options || Object.keys(config.options).length === 0) {
|
|
187
|
-
return
|
|
223
|
+
return relationName;
|
|
188
224
|
}
|
|
189
225
|
const parts = [];
|
|
190
226
|
if (config.options.select) {
|
|
191
|
-
const selectFields = this.formatSelectFields(
|
|
227
|
+
const selectFields = this.formatSelectFields(
|
|
228
|
+
config.options.select,
|
|
229
|
+
targetOccurrence == null ? void 0 : targetOccurrence.baseTable
|
|
230
|
+
);
|
|
192
231
|
parts.push(`$select=${selectFields}`);
|
|
193
232
|
}
|
|
194
233
|
if (config.options.filter) {
|
|
@@ -214,9 +253,9 @@ class QueryBuilder {
|
|
|
214
253
|
}
|
|
215
254
|
}
|
|
216
255
|
if (parts.length === 0) {
|
|
217
|
-
return
|
|
256
|
+
return relationName;
|
|
218
257
|
}
|
|
219
|
-
return `${
|
|
258
|
+
return `${relationName}(${parts.join(";")})`;
|
|
220
259
|
}).join(",");
|
|
221
260
|
}
|
|
222
261
|
expand(relation, callback) {
|
|
@@ -307,200 +346,141 @@ class QueryBuilder {
|
|
|
307
346
|
return newBuilder;
|
|
308
347
|
}
|
|
309
348
|
async execute(options) {
|
|
310
|
-
var _a, _b, _c, _d, _e, _f;
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
queryOptionsWithoutExpand.select
|
|
316
|
-
|
|
317
|
-
|
|
349
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
350
|
+
const queryOptionsWithoutExpand = { ...this.queryOptions };
|
|
351
|
+
delete queryOptionsWithoutExpand.expand;
|
|
352
|
+
if (queryOptionsWithoutExpand.select) {
|
|
353
|
+
queryOptionsWithoutExpand.select = this.formatSelectFields(
|
|
354
|
+
queryOptionsWithoutExpand.select,
|
|
355
|
+
(_a = this.occurrence) == null ? void 0 : _a.baseTable
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
let queryString = buildQuery(queryOptionsWithoutExpand);
|
|
359
|
+
const expandString = this.buildExpandString(this.expandConfigs);
|
|
360
|
+
if (expandString) {
|
|
361
|
+
const separator = queryString.includes("?") ? "&" : "?";
|
|
362
|
+
queryString = `${queryString}${separator}$expand=${expandString}`;
|
|
363
|
+
}
|
|
364
|
+
if (this.isNavigate && this.navigateRecordId && this.navigateRelation && this.navigateSourceTableName) {
|
|
365
|
+
let url;
|
|
366
|
+
if (this.navigateBaseRelation) {
|
|
367
|
+
url = `/${this.databaseName}/${this.navigateSourceTableName}/${this.navigateBaseRelation}('${this.navigateRecordId}')/${this.navigateRelation}${queryString}`;
|
|
368
|
+
} else {
|
|
369
|
+
url = `/${this.databaseName}/${this.navigateSourceTableName}('${this.navigateRecordId}')/${this.navigateRelation}${queryString}`;
|
|
318
370
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
const separator = queryString.includes("?") ? "&" : "?";
|
|
323
|
-
queryString = `${queryString}${separator}$expand=${expandString}`;
|
|
371
|
+
const result2 = await this.context._makeRequest(url, options);
|
|
372
|
+
if (result2.error) {
|
|
373
|
+
return { data: void 0, error: result2.error };
|
|
324
374
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
url = `/${this.databaseName}/${this.navigateSourceTableName}/${this.navigateBaseRelation}('${this.navigateRecordId}')/${this.navigateRelation}${queryString}`;
|
|
329
|
-
} else {
|
|
330
|
-
url = `/${this.databaseName}/${this.navigateSourceTableName}('${this.navigateRecordId}')/${this.navigateRelation}${queryString}`;
|
|
331
|
-
}
|
|
332
|
-
const response2 = await this.context._makeRequest(url, options);
|
|
333
|
-
if ((options == null ? void 0 : options.skipValidation) === true) {
|
|
334
|
-
const resp = response2;
|
|
335
|
-
if (this.singleMode !== false) {
|
|
336
|
-
const records = resp.value ?? [resp];
|
|
337
|
-
const count = Array.isArray(records) ? records.length : 1;
|
|
338
|
-
if (count > 1) {
|
|
339
|
-
return {
|
|
340
|
-
data: void 0,
|
|
341
|
-
error: new Error(
|
|
342
|
-
`Expected ${this.singleMode === "exact" ? "exactly one" : "at most one"} record, but received ${count}`
|
|
343
|
-
)
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
if (count === 0) {
|
|
347
|
-
if (this.singleMode === "exact") {
|
|
348
|
-
return {
|
|
349
|
-
data: void 0,
|
|
350
|
-
error: new Error(
|
|
351
|
-
"Expected exactly one record, but received none"
|
|
352
|
-
)
|
|
353
|
-
};
|
|
354
|
-
}
|
|
355
|
-
return { data: null, error: void 0 };
|
|
356
|
-
}
|
|
357
|
-
const record = Array.isArray(records) ? records[0] : records;
|
|
358
|
-
const stripped = this.stripODataAnnotationsIfNeeded(
|
|
359
|
-
record,
|
|
360
|
-
options
|
|
361
|
-
);
|
|
362
|
-
return { data: stripped, error: void 0 };
|
|
363
|
-
} else {
|
|
364
|
-
const records = resp.value ?? [];
|
|
365
|
-
const stripped = records.map(
|
|
366
|
-
(record) => this.stripODataAnnotationsIfNeeded(record, options)
|
|
367
|
-
);
|
|
368
|
-
return { data: stripped, error: void 0 };
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
const schema2 = (_b = (_a = this.occurrence) == null ? void 0 : _a.baseTable) == null ? void 0 : _b.schema;
|
|
372
|
-
const selectedFields2 = this.queryOptions.select;
|
|
373
|
-
const expandValidationConfigs2 = this.buildExpandValidationConfigs(
|
|
375
|
+
let response2 = result2.data;
|
|
376
|
+
if ((_b = this.occurrence) == null ? void 0 : _b.baseTable) {
|
|
377
|
+
const expandValidationConfigs3 = this.buildExpandValidationConfigs(
|
|
374
378
|
this.expandConfigs
|
|
375
379
|
);
|
|
380
|
+
response2 = transformResponseFields(
|
|
381
|
+
response2,
|
|
382
|
+
this.occurrence.baseTable,
|
|
383
|
+
expandValidationConfigs3
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
if ((options == null ? void 0 : options.skipValidation) === true) {
|
|
387
|
+
const resp = response2;
|
|
376
388
|
if (this.singleMode !== false) {
|
|
377
|
-
const
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
const stripped = validation.data ? this.stripODataAnnotationsIfNeeded(validation.data, options) : null;
|
|
388
|
-
return { data: stripped, error: void 0 };
|
|
389
|
-
} else {
|
|
390
|
-
const validation = await validateListResponse(
|
|
391
|
-
response2,
|
|
392
|
-
schema2,
|
|
393
|
-
selectedFields2,
|
|
394
|
-
expandValidationConfigs2
|
|
395
|
-
);
|
|
396
|
-
if (!validation.valid) {
|
|
397
|
-
return { data: void 0, error: validation.error };
|
|
389
|
+
const records = resp.value ?? [resp];
|
|
390
|
+
const count = Array.isArray(records) ? records.length : 1;
|
|
391
|
+
if (count > 1) {
|
|
392
|
+
return {
|
|
393
|
+
data: void 0,
|
|
394
|
+
error: new RecordCountMismatchError(
|
|
395
|
+
this.singleMode === "exact" ? "one" : "at-most-one",
|
|
396
|
+
count
|
|
397
|
+
)
|
|
398
|
+
};
|
|
398
399
|
}
|
|
399
|
-
|
|
400
|
-
(
|
|
401
|
-
);
|
|
402
|
-
return { data: stripped, error: void 0 };
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
if (this.isNavigate && !this.navigateRecordId && this.navigateRelation && this.navigateSourceTableName) {
|
|
406
|
-
const response2 = await this.context._makeRequest(
|
|
407
|
-
`/${this.databaseName}/${this.navigateSourceTableName}/${this.navigateRelation}${queryString}`,
|
|
408
|
-
options
|
|
409
|
-
);
|
|
410
|
-
if ((options == null ? void 0 : options.skipValidation) === true) {
|
|
411
|
-
const resp = response2;
|
|
412
|
-
if (this.singleMode !== false) {
|
|
413
|
-
const records = resp.value ?? [resp];
|
|
414
|
-
const count = Array.isArray(records) ? records.length : 1;
|
|
415
|
-
if (count > 1) {
|
|
400
|
+
if (count === 0) {
|
|
401
|
+
if (this.singleMode === "exact") {
|
|
416
402
|
return {
|
|
417
403
|
data: void 0,
|
|
418
|
-
error: new
|
|
419
|
-
`Expected ${this.singleMode === "exact" ? "exactly one" : "at most one"} record, but received ${count}`
|
|
420
|
-
)
|
|
404
|
+
error: new RecordCountMismatchError("one", 0)
|
|
421
405
|
};
|
|
422
406
|
}
|
|
423
|
-
|
|
424
|
-
if (this.singleMode === "exact") {
|
|
425
|
-
return {
|
|
426
|
-
data: void 0,
|
|
427
|
-
error: new Error(
|
|
428
|
-
"Expected exactly one record, but received none"
|
|
429
|
-
)
|
|
430
|
-
};
|
|
431
|
-
}
|
|
432
|
-
return { data: null, error: void 0 };
|
|
433
|
-
}
|
|
434
|
-
const record = Array.isArray(records) ? records[0] : records;
|
|
435
|
-
const stripped = this.stripODataAnnotationsIfNeeded(
|
|
436
|
-
record,
|
|
437
|
-
options
|
|
438
|
-
);
|
|
439
|
-
return { data: stripped, error: void 0 };
|
|
440
|
-
} else {
|
|
441
|
-
const records = resp.value ?? [];
|
|
442
|
-
const stripped = records.map(
|
|
443
|
-
(record) => this.stripODataAnnotationsIfNeeded(record, options)
|
|
444
|
-
);
|
|
445
|
-
return { data: stripped, error: void 0 };
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
const schema2 = (_d = (_c = this.occurrence) == null ? void 0 : _c.baseTable) == null ? void 0 : _d.schema;
|
|
449
|
-
const selectedFields2 = this.queryOptions.select;
|
|
450
|
-
const expandValidationConfigs2 = this.buildExpandValidationConfigs(
|
|
451
|
-
this.expandConfigs
|
|
452
|
-
);
|
|
453
|
-
if (this.singleMode !== false) {
|
|
454
|
-
const validation = await validateSingleResponse(
|
|
455
|
-
response2,
|
|
456
|
-
schema2,
|
|
457
|
-
selectedFields2,
|
|
458
|
-
expandValidationConfigs2,
|
|
459
|
-
this.singleMode
|
|
460
|
-
);
|
|
461
|
-
if (!validation.valid) {
|
|
462
|
-
return { data: void 0, error: validation.error };
|
|
407
|
+
return { data: null, error: void 0 };
|
|
463
408
|
}
|
|
464
|
-
const
|
|
409
|
+
const record = Array.isArray(records) ? records[0] : records;
|
|
410
|
+
const stripped = this.stripODataAnnotationsIfNeeded(record, options);
|
|
465
411
|
return { data: stripped, error: void 0 };
|
|
466
412
|
} else {
|
|
467
|
-
const
|
|
468
|
-
|
|
469
|
-
schema2,
|
|
470
|
-
selectedFields2,
|
|
471
|
-
expandValidationConfigs2
|
|
472
|
-
);
|
|
473
|
-
if (!validation.valid) {
|
|
474
|
-
return { data: void 0, error: validation.error };
|
|
475
|
-
}
|
|
476
|
-
const stripped = validation.data.map(
|
|
413
|
+
const records = resp.value ?? [];
|
|
414
|
+
const stripped = records.map(
|
|
477
415
|
(record) => this.stripODataAnnotationsIfNeeded(record, options)
|
|
478
416
|
);
|
|
479
417
|
return { data: stripped, error: void 0 };
|
|
480
418
|
}
|
|
481
419
|
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
420
|
+
const schema2 = (_d = (_c = this.occurrence) == null ? void 0 : _c.baseTable) == null ? void 0 : _d.schema;
|
|
421
|
+
const selectedFields2 = this.queryOptions.select;
|
|
422
|
+
const expandValidationConfigs2 = this.buildExpandValidationConfigs(
|
|
423
|
+
this.expandConfigs
|
|
424
|
+
);
|
|
425
|
+
if (this.singleMode !== false) {
|
|
426
|
+
const validation = await validateSingleResponse(
|
|
427
|
+
response2,
|
|
428
|
+
schema2,
|
|
429
|
+
selectedFields2,
|
|
430
|
+
expandValidationConfigs2,
|
|
431
|
+
this.singleMode
|
|
432
|
+
);
|
|
433
|
+
if (!validation.valid) {
|
|
434
|
+
return { data: void 0, error: validation.error };
|
|
435
|
+
}
|
|
436
|
+
const stripped = validation.data ? this.stripODataAnnotationsIfNeeded(validation.data, options) : null;
|
|
437
|
+
return { data: stripped, error: void 0 };
|
|
438
|
+
} else {
|
|
439
|
+
const validation = await validateListResponse(
|
|
440
|
+
response2,
|
|
441
|
+
schema2,
|
|
442
|
+
selectedFields2,
|
|
443
|
+
expandValidationConfigs2
|
|
486
444
|
);
|
|
487
|
-
|
|
488
|
-
|
|
445
|
+
if (!validation.valid) {
|
|
446
|
+
return { data: void 0, error: validation.error };
|
|
447
|
+
}
|
|
448
|
+
const stripped = validation.data.map(
|
|
449
|
+
(record) => this.stripODataAnnotationsIfNeeded(record, options)
|
|
450
|
+
);
|
|
451
|
+
return { data: stripped, error: void 0 };
|
|
489
452
|
}
|
|
490
|
-
|
|
491
|
-
|
|
453
|
+
}
|
|
454
|
+
if (this.isNavigate && !this.navigateRecordId && this.navigateRelation && this.navigateSourceTableName) {
|
|
455
|
+
const result2 = await this.context._makeRequest(
|
|
456
|
+
`/${this.databaseName}/${this.navigateSourceTableName}/${this.navigateRelation}${queryString}`,
|
|
492
457
|
options
|
|
493
458
|
);
|
|
459
|
+
if (result2.error) {
|
|
460
|
+
return { data: void 0, error: result2.error };
|
|
461
|
+
}
|
|
462
|
+
let response2 = result2.data;
|
|
463
|
+
if ((_e = this.occurrence) == null ? void 0 : _e.baseTable) {
|
|
464
|
+
const expandValidationConfigs3 = this.buildExpandValidationConfigs(
|
|
465
|
+
this.expandConfigs
|
|
466
|
+
);
|
|
467
|
+
response2 = transformResponseFields(
|
|
468
|
+
response2,
|
|
469
|
+
this.occurrence.baseTable,
|
|
470
|
+
expandValidationConfigs3
|
|
471
|
+
);
|
|
472
|
+
}
|
|
494
473
|
if ((options == null ? void 0 : options.skipValidation) === true) {
|
|
495
|
-
const resp =
|
|
474
|
+
const resp = response2;
|
|
496
475
|
if (this.singleMode !== false) {
|
|
497
476
|
const records = resp.value ?? [resp];
|
|
498
477
|
const count = Array.isArray(records) ? records.length : 1;
|
|
499
478
|
if (count > 1) {
|
|
500
479
|
return {
|
|
501
480
|
data: void 0,
|
|
502
|
-
error: new
|
|
503
|
-
|
|
481
|
+
error: new RecordCountMismatchError(
|
|
482
|
+
this.singleMode === "exact" ? "one" : "at-most-one",
|
|
483
|
+
count
|
|
504
484
|
)
|
|
505
485
|
};
|
|
506
486
|
}
|
|
@@ -508,9 +488,7 @@ class QueryBuilder {
|
|
|
508
488
|
if (this.singleMode === "exact") {
|
|
509
489
|
return {
|
|
510
490
|
data: void 0,
|
|
511
|
-
error: new
|
|
512
|
-
"Expected exactly one record, but received none"
|
|
513
|
-
)
|
|
491
|
+
error: new RecordCountMismatchError("one", 0)
|
|
514
492
|
};
|
|
515
493
|
}
|
|
516
494
|
return { data: null, error: void 0 };
|
|
@@ -526,33 +504,30 @@ class QueryBuilder {
|
|
|
526
504
|
return { data: stripped, error: void 0 };
|
|
527
505
|
}
|
|
528
506
|
}
|
|
529
|
-
const
|
|
530
|
-
const
|
|
531
|
-
const
|
|
507
|
+
const schema2 = (_g = (_f = this.occurrence) == null ? void 0 : _f.baseTable) == null ? void 0 : _g.schema;
|
|
508
|
+
const selectedFields2 = this.queryOptions.select;
|
|
509
|
+
const expandValidationConfigs2 = this.buildExpandValidationConfigs(
|
|
532
510
|
this.expandConfigs
|
|
533
511
|
);
|
|
534
512
|
if (this.singleMode !== false) {
|
|
535
513
|
const validation = await validateSingleResponse(
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
514
|
+
response2,
|
|
515
|
+
schema2,
|
|
516
|
+
selectedFields2,
|
|
517
|
+
expandValidationConfigs2,
|
|
540
518
|
this.singleMode
|
|
541
519
|
);
|
|
542
520
|
if (!validation.valid) {
|
|
543
521
|
return { data: void 0, error: validation.error };
|
|
544
522
|
}
|
|
545
523
|
const stripped = validation.data ? this.stripODataAnnotationsIfNeeded(validation.data, options) : null;
|
|
546
|
-
return {
|
|
547
|
-
data: stripped,
|
|
548
|
-
error: void 0
|
|
549
|
-
};
|
|
524
|
+
return { data: stripped, error: void 0 };
|
|
550
525
|
} else {
|
|
551
526
|
const validation = await validateListResponse(
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
527
|
+
response2,
|
|
528
|
+
schema2,
|
|
529
|
+
selectedFields2,
|
|
530
|
+
expandValidationConfigs2
|
|
556
531
|
);
|
|
557
532
|
if (!validation.valid) {
|
|
558
533
|
return { data: void 0, error: validation.error };
|
|
@@ -560,15 +535,111 @@ class QueryBuilder {
|
|
|
560
535
|
const stripped = validation.data.map(
|
|
561
536
|
(record) => this.stripODataAnnotationsIfNeeded(record, options)
|
|
562
537
|
);
|
|
563
|
-
return {
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
538
|
+
return { data: stripped, error: void 0 };
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
if (this.isCountMode) {
|
|
542
|
+
const tableId2 = this.getTableId();
|
|
543
|
+
const result2 = await this.context._makeRequest(
|
|
544
|
+
`/${this.databaseName}/${tableId2}/$count${queryString}`,
|
|
545
|
+
options
|
|
546
|
+
);
|
|
547
|
+
if (result2.error) {
|
|
548
|
+
return { data: void 0, error: result2.error };
|
|
567
549
|
}
|
|
568
|
-
|
|
550
|
+
const count = typeof result2.data === "string" ? Number(result2.data) : result2.data;
|
|
551
|
+
return { data: count, error: void 0 };
|
|
552
|
+
}
|
|
553
|
+
const tableId = this.getTableId();
|
|
554
|
+
const result = await this.context._makeRequest(
|
|
555
|
+
`/${this.databaseName}/${tableId}${queryString}`,
|
|
556
|
+
options
|
|
557
|
+
);
|
|
558
|
+
if (result.error) {
|
|
559
|
+
return { data: void 0, error: result.error };
|
|
560
|
+
}
|
|
561
|
+
let response = result.data;
|
|
562
|
+
if ((_h = this.occurrence) == null ? void 0 : _h.baseTable) {
|
|
563
|
+
const expandValidationConfigs2 = this.buildExpandValidationConfigs(
|
|
564
|
+
this.expandConfigs
|
|
565
|
+
);
|
|
566
|
+
response = transformResponseFields(
|
|
567
|
+
response,
|
|
568
|
+
this.occurrence.baseTable,
|
|
569
|
+
expandValidationConfigs2
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
if ((options == null ? void 0 : options.skipValidation) === true) {
|
|
573
|
+
const resp = response;
|
|
574
|
+
if (this.singleMode !== false) {
|
|
575
|
+
const records = resp.value ?? [resp];
|
|
576
|
+
const count = Array.isArray(records) ? records.length : 1;
|
|
577
|
+
if (count > 1) {
|
|
578
|
+
return {
|
|
579
|
+
data: void 0,
|
|
580
|
+
error: new RecordCountMismatchError(
|
|
581
|
+
this.singleMode === "exact" ? "one" : "at-most-one",
|
|
582
|
+
count
|
|
583
|
+
)
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
if (count === 0) {
|
|
587
|
+
if (this.singleMode === "exact") {
|
|
588
|
+
return {
|
|
589
|
+
data: void 0,
|
|
590
|
+
error: new RecordCountMismatchError("one", 0)
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
return { data: null, error: void 0 };
|
|
594
|
+
}
|
|
595
|
+
const record = Array.isArray(records) ? records[0] : records;
|
|
596
|
+
const stripped = this.stripODataAnnotationsIfNeeded(record, options);
|
|
597
|
+
return { data: stripped, error: void 0 };
|
|
598
|
+
} else {
|
|
599
|
+
const records = resp.value ?? [];
|
|
600
|
+
const stripped = records.map(
|
|
601
|
+
(record) => this.stripODataAnnotationsIfNeeded(record, options)
|
|
602
|
+
);
|
|
603
|
+
return { data: stripped, error: void 0 };
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
const schema = (_j = (_i = this.occurrence) == null ? void 0 : _i.baseTable) == null ? void 0 : _j.schema;
|
|
607
|
+
const selectedFields = this.queryOptions.select;
|
|
608
|
+
const expandValidationConfigs = this.buildExpandValidationConfigs(
|
|
609
|
+
this.expandConfigs
|
|
610
|
+
);
|
|
611
|
+
if (this.singleMode !== false) {
|
|
612
|
+
const validation = await validateSingleResponse(
|
|
613
|
+
response,
|
|
614
|
+
schema,
|
|
615
|
+
selectedFields,
|
|
616
|
+
expandValidationConfigs,
|
|
617
|
+
this.singleMode
|
|
618
|
+
);
|
|
619
|
+
if (!validation.valid) {
|
|
620
|
+
return { data: void 0, error: validation.error };
|
|
621
|
+
}
|
|
622
|
+
const stripped = validation.data ? this.stripODataAnnotationsIfNeeded(validation.data, options) : null;
|
|
623
|
+
return {
|
|
624
|
+
data: stripped,
|
|
625
|
+
error: void 0
|
|
626
|
+
};
|
|
627
|
+
} else {
|
|
628
|
+
const validation = await validateListResponse(
|
|
629
|
+
response,
|
|
630
|
+
schema,
|
|
631
|
+
selectedFields,
|
|
632
|
+
expandValidationConfigs
|
|
633
|
+
);
|
|
634
|
+
if (!validation.valid) {
|
|
635
|
+
return { data: void 0, error: validation.error };
|
|
636
|
+
}
|
|
637
|
+
const stripped = validation.data.map(
|
|
638
|
+
(record) => this.stripODataAnnotationsIfNeeded(record, options)
|
|
639
|
+
);
|
|
569
640
|
return {
|
|
570
|
-
data:
|
|
571
|
-
error:
|
|
641
|
+
data: stripped,
|
|
642
|
+
error: void 0
|
|
572
643
|
};
|
|
573
644
|
}
|
|
574
645
|
}
|