@@ -9,16 +9,19 @@ import type { FMODataLayer, ODataConfig } from "../services";
99import { transformFieldNamesToIds , transformResponseFields } from "../transform" ;
1010import type {
1111 ConditionallyWithODataAnnotations ,
12+ ConditionallyWithSpecialColumns ,
1213 ExecutableBuilder ,
1314 ExecuteMethodOptions ,
1415 ExecuteOptions ,
16+ NormalizeIncludeSpecialColumns ,
1517 Result ,
1618} from "../types" ;
1719import { getAcceptHeader } from "../types" ;
1820import { validateAndTransformInput , validateSingleResponse } from "../validation" ;
1921import {
2022 getLocationHeader ,
2123 mergeMutationExecuteOptions ,
24+ mergePreferHeaderValues ,
2225 parseRowIdFromLocationHeader ,
2326 resolveMutationTableId ,
2427} from "./builders/mutation-helpers" ;
@@ -36,9 +39,16 @@ export class InsertBuilder<
3639 // biome-ignore lint/suspicious/noExplicitAny: Accepts any FMTable configuration
3740 Occ extends FMTable < any , any > | undefined = undefined ,
3841 ReturnPreference extends "minimal" | "representation" = "representation" ,
42+ DatabaseIncludeSpecialColumns extends boolean = false ,
3943> implements
4044 ExecutableBuilder <
41- ReturnPreference extends "minimal" ? { ROWID : number } : InferSchemaOutputFromFMTable < NonNullable < Occ > >
45+ ReturnPreference extends "minimal"
46+ ? { ROWID : number }
47+ : ConditionallyWithSpecialColumns <
48+ InferSchemaOutputFromFMTable < NonNullable < Occ > > ,
49+ DatabaseIncludeSpecialColumns ,
50+ false
51+ >
4252 >
4353{
4454 private readonly table ?: Occ ;
@@ -67,8 +77,8 @@ export class InsertBuilder<
6777 */
6878 private mergeExecuteOptions (
6979 options ?: RequestInit & FFetchOptions & ExecuteOptions ,
70- ) : RequestInit & FFetchOptions & { useEntityIds ?: boolean } {
71- return mergeMutationExecuteOptions ( options , this . config . useEntityIds ) ;
80+ ) : RequestInit & FFetchOptions & { useEntityIds ?: boolean ; includeSpecialColumns ?: boolean } {
81+ return mergeMutationExecuteOptions ( options , this . config . useEntityIds , this . config . includeSpecialColumns ) ;
7282 }
7383
7484 /**
@@ -117,7 +127,11 @@ export class InsertBuilder<
117127 ReturnPreference extends "minimal"
118128 ? { ROWID : number }
119129 : ConditionallyWithODataAnnotations <
120- InferSchemaOutputFromFMTable < NonNullable < Occ > > ,
130+ ConditionallyWithSpecialColumns <
131+ InferSchemaOutputFromFMTable < NonNullable < Occ > > ,
132+ NormalizeIncludeSpecialColumns < EO [ "includeSpecialColumns" ] , DatabaseIncludeSpecialColumns > ,
133+ false
134+ > ,
121135 EO [ "includeODataAnnotations" ] extends true ? true : false
122136 >
123137 >
@@ -128,8 +142,14 @@ export class InsertBuilder<
128142 const { method : _method , headers : callerHeaders , body : _body , ...requestOptions } = mergedOptions as any ;
129143 const tableId = this . getTableId ( mergedOptions . useEntityIds ) ;
130144 const url = `/${ this . config . databaseName } /${ tableId } ` ;
131- const shouldUseIds = mergedOptions . useEntityIds ?? false ;
132- const preferHeader = this . returnPreference === "minimal" ? "return=minimal" : "return=representation" ;
145+ const shouldUseIds = mergedOptions . useEntityIds ?? this . config . useEntityIds ;
146+ const includeSpecialColumns = mergedOptions . includeSpecialColumns ?? this . config . includeSpecialColumns ;
147+ const preferHeader = mergePreferHeaderValues (
148+ new Headers ( callerHeaders ) . get ( "Prefer" ) ?? undefined ,
149+ this . returnPreference === "minimal" ? "return=minimal" : "return=representation" ,
150+ shouldUseIds ? "fmodata.entity-ids" : undefined ,
151+ includeSpecialColumns ? "fmodata.include-specialcolumns" : undefined ,
152+ ) ;
133153
134154 const pipeline = Effect . gen ( this , function * ( ) {
135155 // Step 1: Validate input
@@ -157,7 +177,7 @@ export class InsertBuilder<
157177 headers : {
158178 ...( callerHeaders || { } ) ,
159179 "Content-Type" : "application/json" ,
160- Prefer : preferHeader ,
180+ ... ( preferHeader ? { Prefer : preferHeader } : { } ) ,
161181 } ,
162182 body : JSON . stringify ( transformedData ) ,
163183 } ) ;
@@ -191,6 +211,7 @@ export class InsertBuilder<
191211 undefined ,
192212 undefined ,
193213 "exact" ,
214+ includeSpecialColumns ,
194215 ) ,
195216 ) ;
196217
@@ -216,7 +237,11 @@ export class InsertBuilder<
216237 ReturnPreference extends "minimal"
217238 ? { ROWID : number }
218239 : ConditionallyWithODataAnnotations <
219- InferSchemaOutputFromFMTable < NonNullable < Occ > > ,
240+ ConditionallyWithSpecialColumns <
241+ InferSchemaOutputFromFMTable < NonNullable < Occ > > ,
242+ NormalizeIncludeSpecialColumns < EO [ "includeSpecialColumns" ] , DatabaseIncludeSpecialColumns > ,
243+ false
244+ > ,
220245 EO [ "includeODataAnnotations" ] extends true ? true : false
221246 >
222247 >
@@ -241,16 +266,20 @@ export class InsertBuilder<
241266 toRequest ( baseUrl : string , options ?: ExecuteOptions ) : Request {
242267 const config = this . getRequestConfig ( ) ;
243268 const fullUrl = `${ baseUrl } ${ config . url } ` ;
244-
245- // Set Prefer header based on return preference
246- const preferHeader = this . returnPreference === "minimal" ? "return=minimal" : "return=representation" ;
269+ const preferHeader = mergePreferHeaderValues (
270+ this . returnPreference === "minimal" ? "return=minimal" : "return=representation" ,
271+ ( options ?. useEntityIds ?? this . config . useEntityIds ) ? "fmodata.entity-ids" : undefined ,
272+ ( options ?. includeSpecialColumns ?? this . config . includeSpecialColumns )
273+ ? "fmodata.include-specialcolumns"
274+ : undefined ,
275+ ) ;
247276
248277 return new Request ( fullUrl , {
249278 method : config . method ,
250279 headers : {
251280 "Content-Type" : "application/json" ,
252281 Accept : getAcceptHeader ( options ?. includeODataAnnotations ) ,
253- Prefer : preferHeader ,
282+ ... ( preferHeader ? { Prefer : preferHeader } : { } ) ,
254283 } ,
255284 body : config . body ,
256285 } ) ;
@@ -260,7 +289,15 @@ export class InsertBuilder<
260289 response : Response ,
261290 options ?: ExecuteOptions ,
262291 ) : Promise <
263- Result < ReturnPreference extends "minimal" ? { ROWID : number } : InferSchemaOutputFromFMTable < NonNullable < Occ > > >
292+ Result <
293+ ReturnPreference extends "minimal"
294+ ? { ROWID : number }
295+ : ConditionallyWithSpecialColumns <
296+ InferSchemaOutputFromFMTable < NonNullable < Occ > > ,
297+ DatabaseIncludeSpecialColumns ,
298+ false
299+ >
300+ >
264301 > {
265302 // Check for error responses (important for batch operations)
266303 if ( ! response . ok ) {
@@ -345,6 +382,7 @@ export class InsertBuilder<
345382
346383 // Transform response field IDs back to names if using entity IDs
347384 const shouldUseIds = options ?. useEntityIds ?? this . config . useEntityIds ;
385+ const includeSpecialColumns = options ?. includeSpecialColumns ?? this . config . includeSpecialColumns ;
348386
349387 let transformedResponse = rawResponse ;
350388 if ( this . table && shouldUseIds ) {
@@ -376,6 +414,7 @@ export class InsertBuilder<
376414 undefined , // No selected fields for insert
377415 undefined , // No expand configs
378416 "exact" , // Expect exactly one record
417+ includeSpecialColumns ,
379418 ) ;
380419
381420 if ( ! validation . valid ) {
0 commit comments