@proofkit/fmodata
Version:
FileMaker OData API client
96 lines (95 loc) • 3.21 kB
JavaScript
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
import { needsFieldQuoting } from "../client/builders/select-utils.js";
class Column {
constructor(config) {
__publicField(this, "fieldName");
__publicField(this, "entityId");
__publicField(this, "tableName");
__publicField(this, "tableEntityId");
// biome-ignore lint/suspicious/noExplicitAny: Required for type inference with infer
__publicField(this, "inputValidator");
__publicField(this, "fieldType");
// Phantom types for TypeScript inference - never actually hold values
__publicField(this, "_phantomOutput");
__publicField(this, "_phantomInput");
__publicField(this, "_isContainer");
this.fieldName = config.fieldName;
this.entityId = config.entityId;
this.tableName = config.tableName;
this.tableEntityId = config.tableEntityId;
this.inputValidator = config.inputValidator;
this.fieldType = config.fieldType;
}
/**
* Get the field identifier (entity ID if available, otherwise field name).
* Used when building OData queries.
*/
getFieldIdentifier(useEntityIds) {
if (useEntityIds && this.entityId) {
return this.entityId;
}
return this.fieldName;
}
/**
* Get the table identifier (entity ID if available, otherwise table name).
* Used when building OData queries.
*/
getTableIdentifier(useEntityIds) {
if (useEntityIds && this.tableEntityId) {
return this.tableEntityId;
}
return this.tableName;
}
/**
* Check if this column is from a specific table.
* Useful for validation in cross-table operations.
*/
isFromTable(tableName) {
return this.tableName === tableName;
}
/**
* Create a string representation for debugging.
*/
toString() {
return `${this.tableName}.${this.fieldName}`;
}
}
function isColumn(value) {
return value instanceof Column;
}
class ColumnFunction extends Column {
constructor(fnName, innerColumn) {
super({
fieldName: innerColumn.fieldName,
entityId: innerColumn.entityId,
tableName: innerColumn.tableName,
tableEntityId: innerColumn.tableEntityId,
inputValidator: innerColumn.inputValidator,
fieldType: innerColumn.fieldType
});
__publicField(this, "fnName");
__publicField(this, "innerColumn");
this.fnName = fnName;
this.innerColumn = innerColumn;
}
toFilterString(useEntityIds) {
if (isColumnFunction(this.innerColumn)) {
return `${this.fnName}(${this.innerColumn.toFilterString(useEntityIds)})`;
}
const fieldIdentifier = this.innerColumn.getFieldIdentifier(useEntityIds);
const quoted = needsFieldQuoting(fieldIdentifier) ? `"${fieldIdentifier}"` : fieldIdentifier;
return `${this.fnName}(${quoted})`;
}
}
function isColumnFunction(value) {
return value instanceof ColumnFunction;
}
export {
Column,
ColumnFunction,
isColumn,
isColumnFunction
};
//# sourceMappingURL=column.js.map