@proofkit/fmodata 0.1.0-alpha.4 → 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.
Files changed (57) hide show
  1. package/README.md +357 -28
  2. package/dist/esm/client/base-table.d.ts +122 -5
  3. package/dist/esm/client/base-table.js +46 -5
  4. package/dist/esm/client/base-table.js.map +1 -1
  5. package/dist/esm/client/database.d.ts +20 -3
  6. package/dist/esm/client/database.js +62 -13
  7. package/dist/esm/client/database.js.map +1 -1
  8. package/dist/esm/client/delete-builder.js +24 -27
  9. package/dist/esm/client/delete-builder.js.map +1 -1
  10. package/dist/esm/client/entity-set.d.ts +9 -6
  11. package/dist/esm/client/entity-set.js +5 -1
  12. package/dist/esm/client/entity-set.js.map +1 -1
  13. package/dist/esm/client/filemaker-odata.d.ts +17 -4
  14. package/dist/esm/client/filemaker-odata.js +90 -27
  15. package/dist/esm/client/filemaker-odata.js.map +1 -1
  16. package/dist/esm/client/insert-builder.js +45 -34
  17. package/dist/esm/client/insert-builder.js.map +1 -1
  18. package/dist/esm/client/query-builder.d.ts +7 -2
  19. package/dist/esm/client/query-builder.js +273 -202
  20. package/dist/esm/client/query-builder.js.map +1 -1
  21. package/dist/esm/client/record-builder.d.ts +2 -2
  22. package/dist/esm/client/record-builder.js +50 -40
  23. package/dist/esm/client/record-builder.js.map +1 -1
  24. package/dist/esm/client/table-occurrence.d.ts +66 -2
  25. package/dist/esm/client/table-occurrence.js +36 -1
  26. package/dist/esm/client/table-occurrence.js.map +1 -1
  27. package/dist/esm/client/update-builder.js +39 -35
  28. package/dist/esm/client/update-builder.js.map +1 -1
  29. package/dist/esm/errors.d.ts +60 -0
  30. package/dist/esm/errors.js +122 -0
  31. package/dist/esm/errors.js.map +1 -0
  32. package/dist/esm/index.d.ts +5 -2
  33. package/dist/esm/index.js +25 -3
  34. package/dist/esm/index.js.map +1 -1
  35. package/dist/esm/transform.d.ts +56 -0
  36. package/dist/esm/transform.js +107 -0
  37. package/dist/esm/transform.js.map +1 -0
  38. package/dist/esm/types.d.ts +21 -5
  39. package/dist/esm/validation.d.ts +6 -3
  40. package/dist/esm/validation.js +104 -33
  41. package/dist/esm/validation.js.map +1 -1
  42. package/package.json +10 -1
  43. package/src/client/base-table.ts +155 -8
  44. package/src/client/database.ts +116 -13
  45. package/src/client/delete-builder.ts +42 -43
  46. package/src/client/entity-set.ts +21 -11
  47. package/src/client/filemaker-odata.ts +132 -34
  48. package/src/client/insert-builder.ts +69 -37
  49. package/src/client/query-builder.ts +345 -233
  50. package/src/client/record-builder.ts +84 -59
  51. package/src/client/table-occurrence.ts +118 -4
  52. package/src/client/update-builder.ts +77 -49
  53. package/src/errors.ts +185 -0
  54. package/src/index.ts +30 -1
  55. package/src/transform.ts +236 -0
  56. package/src/types.ts +112 -34
  57. package/src/validation.ts +120 -36
package/src/errors.ts ADDED
@@ -0,0 +1,185 @@
1
+ import type { StandardSchemaV1 } from "@standard-schema/spec";
2
+
3
+ /**
4
+ * Base class for all fmodata errors
5
+ */
6
+ export abstract class FMODataError extends Error {
7
+ abstract readonly kind: string;
8
+ readonly timestamp: Date;
9
+
10
+ constructor(message: string, options?: ErrorOptions) {
11
+ super(message, options);
12
+ this.name = this.constructor.name;
13
+ this.timestamp = new Date();
14
+ }
15
+ }
16
+
17
+ // ============================================
18
+ // HTTP Errors (with status codes)
19
+ // ============================================
20
+
21
+ export class HTTPError extends FMODataError {
22
+ readonly kind = "HTTPError" as const;
23
+ readonly url: string;
24
+ readonly status: number;
25
+ readonly statusText: string;
26
+ readonly response?: any;
27
+
28
+ constructor(url: string, status: number, statusText: string, response?: any) {
29
+ super(`HTTP ${status} ${statusText} for ${url}`);
30
+ this.url = url;
31
+ this.status = status;
32
+ this.statusText = statusText;
33
+ this.response = response;
34
+ }
35
+
36
+ // Helper methods for common status checks
37
+ is4xx(): boolean {
38
+ return this.status >= 400 && this.status < 500;
39
+ }
40
+
41
+ is5xx(): boolean {
42
+ return this.status >= 500 && this.status < 600;
43
+ }
44
+
45
+ isNotFound(): boolean {
46
+ return this.status === 404;
47
+ }
48
+
49
+ isUnauthorized(): boolean {
50
+ return this.status === 401;
51
+ }
52
+
53
+ isForbidden(): boolean {
54
+ return this.status === 403;
55
+ }
56
+ }
57
+
58
+ // ============================================
59
+ // OData Specific Errors
60
+ // ============================================
61
+
62
+ export class ODataError extends FMODataError {
63
+ readonly kind = "ODataError" as const;
64
+ readonly url: string;
65
+ readonly code?: string;
66
+ readonly details?: any;
67
+
68
+ constructor(url: string, message: string, code?: string, details?: any) {
69
+ super(`OData error: ${message}`);
70
+ this.url = url;
71
+ this.code = code;
72
+ this.details = details;
73
+ }
74
+ }
75
+
76
+ // ============================================
77
+ // Validation Errors
78
+ // ============================================
79
+
80
+ export class ValidationError extends FMODataError {
81
+ readonly kind = "ValidationError" as const;
82
+ readonly field?: string;
83
+ readonly issues: readonly StandardSchemaV1.Issue[];
84
+ readonly value?: unknown;
85
+
86
+ constructor(
87
+ message: string,
88
+ issues: readonly StandardSchemaV1.Issue[],
89
+ options?: {
90
+ field?: string;
91
+ value?: unknown;
92
+ cause?: Error["cause"];
93
+ },
94
+ ) {
95
+ super(
96
+ message,
97
+ options?.cause !== undefined ? { cause: options.cause } : undefined,
98
+ );
99
+ this.field = options?.field;
100
+ this.issues = issues;
101
+ this.value = options?.value;
102
+ }
103
+ }
104
+
105
+ export class ResponseStructureError extends FMODataError {
106
+ readonly kind = "ResponseStructureError" as const;
107
+ readonly expected: string;
108
+ readonly received: any;
109
+
110
+ constructor(expected: string, received: any) {
111
+ super(`Invalid response structure: expected ${expected}`);
112
+ this.expected = expected;
113
+ this.received = received;
114
+ }
115
+ }
116
+
117
+ export class RecordCountMismatchError extends FMODataError {
118
+ readonly kind = "RecordCountMismatchError" as const;
119
+ readonly expected: number | "one" | "at-most-one";
120
+ readonly received: number;
121
+
122
+ constructor(expected: number | "one" | "at-most-one", received: number) {
123
+ const expectedStr = typeof expected === "number" ? expected : expected;
124
+ super(`Expected ${expectedStr} record(s), but received ${received}`);
125
+ this.expected = expected;
126
+ this.received = received;
127
+ }
128
+ }
129
+
130
+ // ============================================
131
+ // Type Guards
132
+ // ============================================
133
+
134
+ export function isHTTPError(error: unknown): error is HTTPError {
135
+ return error instanceof HTTPError;
136
+ }
137
+
138
+ export function isValidationError(error: unknown): error is ValidationError {
139
+ return error instanceof ValidationError;
140
+ }
141
+
142
+ export function isODataError(error: unknown): error is ODataError {
143
+ return error instanceof ODataError;
144
+ }
145
+
146
+ export function isResponseStructureError(
147
+ error: unknown,
148
+ ): error is ResponseStructureError {
149
+ return error instanceof ResponseStructureError;
150
+ }
151
+
152
+ export function isRecordCountMismatchError(
153
+ error: unknown,
154
+ ): error is RecordCountMismatchError {
155
+ return error instanceof RecordCountMismatchError;
156
+ }
157
+
158
+ export function isFMODataError(error: unknown): error is FMODataError {
159
+ return error instanceof FMODataError;
160
+ }
161
+
162
+ // ============================================
163
+ // Union type for all possible errors
164
+ // ============================================
165
+
166
+ // Re-export ffetch errors (they'll be imported from @fetchkit/ffetch)
167
+ export type {
168
+ TimeoutError,
169
+ AbortError,
170
+ NetworkError,
171
+ RetryLimitError,
172
+ CircuitOpenError,
173
+ } from "@fetchkit/ffetch";
174
+
175
+ export type FMODataErrorType =
176
+ | import("@fetchkit/ffetch").TimeoutError
177
+ | import("@fetchkit/ffetch").AbortError
178
+ | import("@fetchkit/ffetch").NetworkError
179
+ | import("@fetchkit/ffetch").RetryLimitError
180
+ | import("@fetchkit/ffetch").CircuitOpenError
181
+ | HTTPError
182
+ | ODataError
183
+ | ValidationError
184
+ | ResponseStructureError
185
+ | RecordCountMismatchError;
package/src/index.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  // Barrel file - exports all public API from the client folder
2
- export { BaseTable } from "./client/base-table";
2
+ export { BaseTable, BaseTableWithIds } from "./client/base-table";
3
3
  export {
4
4
  TableOccurrence,
5
5
  createTableOccurrence,
6
+ TableOccurrenceWithIds,
7
+ createTableOccurrenceWithIds,
6
8
  } from "./client/table-occurrence";
7
9
  export { FMServerConnection } from "./client/filemaker-odata";
8
10
 
@@ -31,3 +33,30 @@ export type {
31
33
  DateOperators,
32
34
  LogicalFilter,
33
35
  } from "./filter-types";
36
+
37
+ // Re-export ffetch errors
38
+ export {
39
+ TimeoutError,
40
+ AbortError,
41
+ NetworkError,
42
+ RetryLimitError,
43
+ CircuitOpenError,
44
+ } from "@fetchkit/ffetch";
45
+
46
+ // Export our errors
47
+ export {
48
+ FMODataError,
49
+ HTTPError,
50
+ ODataError,
51
+ ValidationError,
52
+ ResponseStructureError,
53
+ RecordCountMismatchError,
54
+ isHTTPError,
55
+ isValidationError,
56
+ isODataError,
57
+ isResponseStructureError,
58
+ isRecordCountMismatchError,
59
+ isFMODataError,
60
+ } from "./errors";
61
+
62
+ export type { FMODataErrorType } from "./errors";
@@ -0,0 +1,236 @@
1
+ import type { BaseTable } from "./client/base-table";
2
+ import type { TableOccurrence } from "./client/table-occurrence";
3
+ import type { StandardSchemaV1 } from "@standard-schema/spec";
4
+
5
+ /**
6
+ * Transforms field names to FileMaker field IDs (FMFID) in an object
7
+ * @param data - Object with field names as keys
8
+ * @param baseTable - BaseTable instance to get field IDs from
9
+ * @returns Object with FMFID keys instead of field names
10
+ */
11
+ export function transformFieldNamesToIds<T extends Record<string, any>>(
12
+ data: T,
13
+ baseTable: BaseTable<any, any, any, any>,
14
+ ): Record<string, any> {
15
+ if (!baseTable.isUsingFieldIds()) {
16
+ return data;
17
+ }
18
+
19
+ const transformed: Record<string, any> = {};
20
+ for (const [fieldName, value] of Object.entries(data)) {
21
+ const fieldId = baseTable.getFieldId(fieldName as any);
22
+ transformed[fieldId] = value;
23
+ }
24
+ return transformed;
25
+ }
26
+
27
+ /**
28
+ * Transforms FileMaker field IDs (FMFID) to field names in an object
29
+ * @param data - Object with FMFID keys
30
+ * @param baseTable - BaseTable instance to get field names from
31
+ * @returns Object with field names as keys instead of FMFIDs
32
+ */
33
+ export function transformFieldIdsToNames<T extends Record<string, any>>(
34
+ data: T,
35
+ baseTable: BaseTable<any, any, any, any>,
36
+ ): Record<string, any> {
37
+ if (!baseTable.isUsingFieldIds()) {
38
+ return data;
39
+ }
40
+
41
+ const transformed: Record<string, any> = {};
42
+ for (const [key, value] of Object.entries(data)) {
43
+ // Check if this is an OData metadata field (starts with @)
44
+ if (key.startsWith("@")) {
45
+ transformed[key] = value;
46
+ continue;
47
+ }
48
+
49
+ const fieldName = baseTable.getFieldName(key);
50
+ transformed[fieldName] = value;
51
+ }
52
+ return transformed;
53
+ }
54
+
55
+ /**
56
+ * Transforms a field name to FMFID or returns the field name if not using IDs
57
+ * @param fieldName - The field name to transform
58
+ * @param baseTable - BaseTable instance to get field ID from
59
+ * @returns The FMFID or field name
60
+ */
61
+ export function transformFieldName(
62
+ fieldName: string,
63
+ baseTable: BaseTable<any, any, any, any>,
64
+ ): string {
65
+ return baseTable.getFieldId(fieldName as any);
66
+ }
67
+
68
+ /**
69
+ * Transforms a table occurrence name to FMTID or returns the name if not using IDs
70
+ * @param occurrence - TableOccurrence instance to get table ID from
71
+ * @returns The FMTID or table name
72
+ */
73
+ export function transformTableName(
74
+ occurrence: TableOccurrence<any, any, any, any>,
75
+ ): string {
76
+ return occurrence.getTableId();
77
+ }
78
+
79
+ /**
80
+ * Transforms response data by converting field IDs back to field names recursively.
81
+ * Handles both single records and arrays of records, as well as nested expand relationships.
82
+ *
83
+ * @param data - Response data from FileMaker (can be single record, array, or wrapped in value property)
84
+ * @param baseTable - BaseTable instance for the main table
85
+ * @param expandConfigs - Configuration for expanded relations (optional)
86
+ * @returns Transformed data with field names instead of IDs
87
+ */
88
+ export function transformResponseFields(
89
+ data: any,
90
+ baseTable: BaseTable<any, any, any, any>,
91
+ expandConfigs?: Array<{
92
+ relation: string;
93
+ occurrence?: TableOccurrence<any, any, any, any>;
94
+ }>,
95
+ ): any {
96
+ if (!baseTable.isUsingFieldIds()) {
97
+ return data;
98
+ }
99
+
100
+ // Handle null/undefined
101
+ if (data === null || data === undefined) {
102
+ return data;
103
+ }
104
+
105
+ // Handle OData list response with value array
106
+ if (data.value && Array.isArray(data.value)) {
107
+ return {
108
+ ...data,
109
+ value: data.value.map((record: any) =>
110
+ transformSingleRecord(record, baseTable, expandConfigs),
111
+ ),
112
+ };
113
+ }
114
+
115
+ // Handle array of records
116
+ if (Array.isArray(data)) {
117
+ return data.map((record) =>
118
+ transformSingleRecord(record, baseTable, expandConfigs),
119
+ );
120
+ }
121
+
122
+ // Handle single record
123
+ return transformSingleRecord(data, baseTable, expandConfigs);
124
+ }
125
+
126
+ /**
127
+ * Transforms a single record, converting field IDs to names and handling nested expands
128
+ */
129
+ function transformSingleRecord(
130
+ record: any,
131
+ baseTable: BaseTable<any, any, any, any>,
132
+ expandConfigs?: Array<{
133
+ relation: string;
134
+ occurrence?: TableOccurrence<any, any, any, any>;
135
+ }>,
136
+ ): any {
137
+ if (!record || typeof record !== "object") {
138
+ return record;
139
+ }
140
+
141
+ const transformed: Record<string, any> = {};
142
+
143
+ for (const [key, value] of Object.entries(record)) {
144
+ // Preserve OData metadata fields
145
+ if (key.startsWith("@")) {
146
+ transformed[key] = value;
147
+ continue;
148
+ }
149
+
150
+ // Check if this is an expanded relation (by relation name)
151
+ let expandConfig = expandConfigs?.find((ec) => ec.relation === key);
152
+
153
+ // If not found by relation name, check if this key is a FMTID
154
+ // (FileMaker returns expanded relations with FMTID keys when using entity IDs)
155
+ if (!expandConfig && key.startsWith("FMTID:")) {
156
+ expandConfig = expandConfigs?.find(
157
+ (ec) =>
158
+ ec.occurrence &&
159
+ ec.occurrence.isUsingTableId() &&
160
+ ec.occurrence.getTableId() === key,
161
+ );
162
+ }
163
+
164
+ if (expandConfig && expandConfig.occurrence) {
165
+ // Transform the expanded relation data recursively
166
+ // Use the relation name (not the FMTID) as the key
167
+ const relationKey = expandConfig.relation;
168
+
169
+ if (Array.isArray(value)) {
170
+ transformed[relationKey] = value.map((nestedRecord) =>
171
+ transformSingleRecord(
172
+ nestedRecord,
173
+ expandConfig.occurrence!.baseTable,
174
+ undefined, // Don't pass nested expand configs for now
175
+ ),
176
+ );
177
+ } else if (value && typeof value === "object") {
178
+ transformed[relationKey] = transformSingleRecord(
179
+ value,
180
+ expandConfig.occurrence.baseTable,
181
+ undefined,
182
+ );
183
+ } else {
184
+ transformed[relationKey] = value;
185
+ }
186
+ continue;
187
+ }
188
+
189
+ // Transform field ID to field name
190
+ const fieldName = baseTable.getFieldName(key);
191
+ transformed[fieldName] = value;
192
+ }
193
+
194
+ return transformed;
195
+ }
196
+
197
+ /**
198
+ * Transforms an array of field names to FMFIDs
199
+ * @param fieldNames - Array of field names
200
+ * @param baseTable - BaseTable instance to get field IDs from
201
+ * @returns Array of FMFIDs or field names
202
+ */
203
+ export function transformFieldNamesArray(
204
+ fieldNames: string[],
205
+ baseTable: BaseTable<any, any, any, any>,
206
+ ): string[] {
207
+ if (!baseTable.isUsingFieldIds()) {
208
+ return fieldNames;
209
+ }
210
+
211
+ return fieldNames.map((fieldName) => baseTable.getFieldId(fieldName as any));
212
+ }
213
+
214
+ /**
215
+ * Transforms a field name in an orderBy string (e.g., "name desc" -> "FMFID:1 desc")
216
+ * @param orderByString - The orderBy string (field name with optional asc/desc)
217
+ * @param baseTable - BaseTable instance to get field ID from
218
+ * @returns Transformed orderBy string with FMFID
219
+ */
220
+ export function transformOrderByField(
221
+ orderByString: string,
222
+ baseTable: BaseTable<any, any, any, any>,
223
+ ): string {
224
+ if (!baseTable.isUsingFieldIds()) {
225
+ return orderByString;
226
+ }
227
+
228
+ // Parse the orderBy string to extract field name and direction
229
+ const parts = orderByString.trim().split(/\s+/);
230
+ const fieldName = parts[0];
231
+ const direction = parts[1]; // "asc" or "desc" or undefined
232
+
233
+ const fieldId = baseTable.getFieldId(fieldName as any);
234
+ return direction ? `${fieldId} ${direction}` : fieldId;
235
+ }
236
+
package/src/types.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { type FFetchOptions } from "@fetchkit/ffetch";
2
- import { z } from "zod/v4";
3
2
  import type { StandardSchemaV1 } from "@standard-schema/spec";
4
3
 
5
4
  export type Auth = { username: string; password: string } | { apiKey: string };
@@ -13,12 +12,14 @@ export interface ExecutionContext {
13
12
  _makeRequest<T>(
14
13
  url: string,
15
14
  options?: RequestInit & FFetchOptions,
16
- ): Promise<T>;
15
+ ): Promise<Result<T>>;
16
+ _setUseEntityIds?(useEntityIds: boolean): void;
17
+ _getUseEntityIds?(): boolean;
17
18
  }
18
19
 
19
20
  export type InferSchemaType<Schema extends Record<string, StandardSchemaV1>> = {
20
- [K in keyof Schema]: Schema[K] extends StandardSchemaV1<any, infer Output>
21
- ? Output
21
+ [K in keyof Schema]: Schema[K] extends StandardSchemaV1<any, infer Output>
22
+ ? Output
22
23
  : never;
23
24
  };
24
25
 
@@ -63,7 +64,7 @@ export type ODataFieldResponse<T> = {
63
64
  };
64
65
 
65
66
  // Result pattern for execute responses
66
- export type Result<T, E = Error> =
67
+ export type Result<T, E = import("./errors").FMODataErrorType> =
67
68
  | { data: T; error: undefined }
68
69
  | { data: undefined; error: E };
69
70
 
@@ -71,34 +72,108 @@ export type Result<T, E = Error> =
71
72
  export type MakeFieldsRequired<T, Keys extends keyof T> = Partial<T> &
72
73
  Required<Pick<T, Keys>>;
73
74
 
75
+ // Extract keys from schema where validator doesn't allow null/undefined (auto-required fields)
76
+ export type AutoRequiredKeys<Schema extends Record<string, StandardSchemaV1>> =
77
+ {
78
+ [K in keyof Schema]: Extract<
79
+ StandardSchemaV1.InferOutput<Schema[K]>,
80
+ null | undefined
81
+ > extends never
82
+ ? K
83
+ : never;
84
+ }[keyof Schema];
85
+
86
+ // Helper type to compute excluded fields (readOnly fields + idField)
87
+ export type ExcludedFields<
88
+ IdField extends keyof any | undefined,
89
+ ReadOnly extends readonly any[],
90
+ > = IdField extends keyof any ? IdField | ReadOnly[number] : ReadOnly[number];
91
+
92
+ // Helper type for InsertData computation
93
+ type ComputeInsertData<
94
+ Schema extends Record<string, StandardSchemaV1>,
95
+ IdField extends keyof Schema | undefined,
96
+ Required extends readonly any[],
97
+ ReadOnly extends readonly any[],
98
+ > = [Required[number]] extends [keyof InferSchemaType<Schema>]
99
+ ? Required extends readonly (keyof InferSchemaType<Schema>)[]
100
+ ? MakeFieldsRequired<
101
+ Omit<InferSchemaType<Schema>, ExcludedFields<IdField, ReadOnly>>,
102
+ Exclude<
103
+ AutoRequiredKeys<Schema> | Required[number],
104
+ ExcludedFields<IdField, ReadOnly>
105
+ >
106
+ >
107
+ : MakeFieldsRequired<
108
+ Omit<InferSchemaType<Schema>, ExcludedFields<IdField, ReadOnly>>,
109
+ Exclude<AutoRequiredKeys<Schema>, ExcludedFields<IdField, ReadOnly>>
110
+ >
111
+ : MakeFieldsRequired<
112
+ Omit<InferSchemaType<Schema>, ExcludedFields<IdField, ReadOnly>>,
113
+ Exclude<AutoRequiredKeys<Schema>, ExcludedFields<IdField, ReadOnly>>
114
+ >;
115
+
74
116
  // Extract insert data type from BaseTable
75
- // This type makes the insertRequired fields required while keeping others optional
117
+ // Auto-infers required fields from validator nullability + user-specified required fields
118
+ // Excludes readOnly fields and idField
76
119
  export type InsertData<BT> = BT extends import("./client/base-table").BaseTable<
77
- infer Schema extends Record<string, z.ZodType>,
78
120
  any,
79
- infer InsertRequired extends readonly any[],
121
+ any,
122
+ any,
80
123
  any
81
124
  >
82
- ? [InsertRequired[number]] extends [keyof InferSchemaType<Schema>]
83
- ? InsertRequired extends readonly (keyof InferSchemaType<Schema>)[]
84
- ? MakeFieldsRequired<InferSchemaType<Schema>, InsertRequired[number]>
85
- : Partial<InferSchemaType<Schema>>
86
- : Partial<InferSchemaType<Schema>>
125
+ ? BT extends {
126
+ schema: infer Schema;
127
+ idField?: infer IdField;
128
+ required?: infer Required;
129
+ readOnly?: infer ReadOnly;
130
+ }
131
+ ? Schema extends Record<string, StandardSchemaV1>
132
+ ? IdField extends keyof Schema | undefined
133
+ ? Required extends readonly any[]
134
+ ? ReadOnly extends readonly any[]
135
+ ? ComputeInsertData<
136
+ Schema,
137
+ Extract<IdField, keyof Schema | undefined>,
138
+ Required,
139
+ ReadOnly
140
+ >
141
+ : Partial<Record<string, any>>
142
+ : Partial<Record<string, any>>
143
+ : Partial<Record<string, any>>
144
+ : Partial<Record<string, any>>
145
+ : Partial<Record<string, any>>
87
146
  : Partial<Record<string, any>>;
88
147
 
89
148
  // Extract update data type from BaseTable
90
- // This type makes the updateRequired fields required while keeping others optional
149
+ // All fields are optional for updates, excludes readOnly fields and idField
91
150
  export type UpdateData<BT> = BT extends import("./client/base-table").BaseTable<
92
- infer Schema extends Record<string, z.ZodType>,
93
151
  any,
94
152
  any,
95
- infer UpdateRequired extends readonly any[]
153
+ any,
154
+ any
96
155
  >
97
- ? [UpdateRequired[number]] extends [keyof InferSchemaType<Schema>]
98
- ? UpdateRequired extends readonly (keyof InferSchemaType<Schema>)[]
99
- ? MakeFieldsRequired<InferSchemaType<Schema>, UpdateRequired[number]>
100
- : Partial<InferSchemaType<Schema>>
101
- : Partial<InferSchemaType<Schema>>
156
+ ? BT extends {
157
+ schema: infer Schema;
158
+ idField?: infer IdField;
159
+ readOnly?: infer ReadOnly;
160
+ }
161
+ ? Schema extends Record<string, StandardSchemaV1>
162
+ ? IdField extends keyof Schema | undefined
163
+ ? ReadOnly extends readonly any[]
164
+ ? Partial<
165
+ Omit<
166
+ InferSchemaType<Schema>,
167
+ ExcludedFields<
168
+ Extract<IdField, keyof Schema | undefined>,
169
+ ReadOnly
170
+ >
171
+ >
172
+ >
173
+ : Partial<Record<string, any>>
174
+ : Partial<Record<string, any>>
175
+ : Partial<Record<string, any>>
176
+ : Partial<Record<string, any>>
102
177
  : Partial<Record<string, any>>;
103
178
 
104
179
  export type ExecuteOptions = {
@@ -106,18 +181,21 @@ export type ExecuteOptions = {
106
181
  skipValidation?: boolean;
107
182
  };
108
183
 
109
- export type ConditionallyWithODataAnnotations<T, IncludeODataAnnotations extends boolean> =
110
- IncludeODataAnnotations extends true
111
- ? T & {
112
- "@id": string;
113
- "@editLink": string;
114
- }
115
- : T;
184
+ export type ConditionallyWithODataAnnotations<
185
+ T,
186
+ IncludeODataAnnotations extends boolean,
187
+ > = IncludeODataAnnotations extends true
188
+ ? T & {
189
+ "@id": string;
190
+ "@editLink": string;
191
+ }
192
+ : T;
116
193
 
117
194
  // Helper type to extract schema from a TableOccurrence
118
- export type ExtractSchemaFromOccurrence<Occ> =
119
- Occ extends { baseTable: { schema: infer S } }
120
- ? S extends Record<string, StandardSchemaV1>
121
- ? S
122
- : Record<string, StandardSchemaV1>
123
- : Record<string, StandardSchemaV1>;
195
+ export type ExtractSchemaFromOccurrence<Occ> = Occ extends {
196
+ baseTable: { schema: infer S };
197
+ }
198
+ ? S extends Record<string, StandardSchemaV1>
199
+ ? S
200
+ : Record<string, StandardSchemaV1>
201
+ : Record<string, StandardSchemaV1>;