@remult/core
Advanced tools
Comparing version 3.0.10 to 3.0.11
@@ -1,2 +0,2 @@ | ||
export { ClassType, Field, FieldDefinitionsOf, Entity, EntityBase, EntityField, EntityFields, EntityDefinitions, EntityOrderBy, EntityWhere, EntityWhereItem, FindOptions, InputTypes, IteratableResult, IterateOptions, Repository, FieldType, comparableFilterItem, controllerDefs, filterOf, filterOptions, getControllerDefs, getEntityOf, getEntitySettings, rowHelper, sortOf, supportsContains, ValueListFieldType, DateOnlyField, DecimalField } from './src/remult3'; | ||
export { ClassType, Field, FieldDefinitionsOf, Entity, EntityBase, EntityField, EntityFields, EntityDefinitions, EntityOrderBy, EntityWhere, FindOptions, InputTypes, IteratableResult, IterateOptions, Repository, FieldType, comparableFilterItem, controllerDefs, filterOf, filterOptions, getControllerDefs, getEntityOf, getEntitySettings, rowHelper, sortOf, supportsContains, ValueListFieldType, DateOnlyField, DecimalField, CaptionHelper } from './src/remult3'; | ||
export { EntitySettings } from './src/entity'; | ||
@@ -17,3 +17,2 @@ export { DataProvider, EntityDataProvider, EntityDataProviderFindOptions, ErrorInfo, RestDataProviderHttpProvider } from './src/data-interfaces'; | ||
export { SortSegment, Sort } from './src/sort'; | ||
export * from './src/columns/loaders'; | ||
export { ManyToOne, OneToMany } from './src/column'; | ||
@@ -20,0 +19,0 @@ export { Filter, AndFilter, OrFilter } from './src/filter/filter-interfaces'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Validators = exports.UrlBuilder = exports.FilterConsumerBridgeToSqlRequest = exports.OrFilter = exports.AndFilter = exports.Filter = exports.OneToMany = exports.ManyToOne = exports.Sort = exports.IdEntity = exports.keyFor = exports.ServerContext = exports.Role = exports.EventSource = exports.Context = exports.controllerAllowed = exports.ServerProgress = exports.ServerMethod = exports.ServerFunction = exports.ServerController = exports.JsonDataProvider = exports.SqlDatabase = exports.WebSqlDataProvider = exports.ArrayEntityDataProvider = exports.InMemoryDataProvider = exports.RestDataProvider = exports.valueOrExpressionToValue = exports.DecimalField = exports.DateOnlyField = exports.ValueListFieldType = exports.getEntitySettings = exports.getEntityOf = exports.getControllerDefs = exports.FieldType = exports.InputTypes = exports.EntityBase = exports.Entity = exports.Field = void 0; | ||
var tslib_1 = require("tslib"); | ||
exports.Validators = exports.UrlBuilder = exports.FilterConsumerBridgeToSqlRequest = exports.OrFilter = exports.AndFilter = exports.Filter = exports.OneToMany = exports.ManyToOne = exports.Sort = exports.IdEntity = exports.keyFor = exports.ServerContext = exports.Role = exports.EventSource = exports.Context = exports.controllerAllowed = exports.ServerProgress = exports.ServerMethod = exports.ServerFunction = exports.ServerController = exports.JsonDataProvider = exports.SqlDatabase = exports.WebSqlDataProvider = exports.ArrayEntityDataProvider = exports.InMemoryDataProvider = exports.RestDataProvider = exports.valueOrExpressionToValue = exports.CaptionHelper = exports.DecimalField = exports.DateOnlyField = exports.ValueListFieldType = exports.getEntitySettings = exports.getEntityOf = exports.getControllerDefs = exports.FieldType = exports.InputTypes = exports.EntityBase = exports.Entity = exports.Field = void 0; | ||
/* | ||
@@ -20,2 +19,3 @@ * Public API Surface of @remult/core | ||
Object.defineProperty(exports, "DecimalField", { enumerable: true, get: function () { return remult3_1.DecimalField; } }); | ||
Object.defineProperty(exports, "CaptionHelper", { enumerable: true, get: function () { return remult3_1.CaptionHelper; } }); | ||
var column_interfaces_1 = require("./src/column-interfaces"); // revisit input type | ||
@@ -52,3 +52,2 @@ Object.defineProperty(exports, "valueOrExpressionToValue", { enumerable: true, get: function () { return column_interfaces_1.valueOrExpressionToValue; } }); | ||
Object.defineProperty(exports, "Sort", { enumerable: true, get: function () { return sort_1.Sort; } }); | ||
tslib_1.__exportStar(require("./src/columns/loaders"), exports); | ||
var column_1 = require("./src/column"); | ||
@@ -55,0 +54,0 @@ Object.defineProperty(exports, "ManyToOne", { enumerable: true, get: function () { return column_1.ManyToOne; } }); |
{ | ||
"name": "@remult/core", | ||
"schematics": "./schematics/collection.json", | ||
"version": "3.0.10", | ||
"version": "3.0.11", | ||
"description": "remult core lib", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
@@ -35,8 +35,8 @@ import { Allowed, Context, EntityAllowed } from './context'; | ||
export interface ValueConverter<T> { | ||
fromJson(val: any): T; | ||
toJson(val: T): any; | ||
fromDb(val: any): T; | ||
toDb(val: T): any; | ||
toInput(val: T, inputType: string): string; | ||
fromInput(val: string, inputType: string): T; | ||
fromJson?(val: any): T; | ||
toJson?(val: T): any; | ||
fromDb?(val: any): T; | ||
toDb?(val: T): any; | ||
toInput?(val: T, inputType: string): string; | ||
fromInput?(val: string, inputType: string): T; | ||
displayValue?(val: T): string; | ||
@@ -43,0 +43,0 @@ readonly fieldTypeInDb?: string; |
@@ -1,6 +0,4 @@ | ||
import { Context } from './context'; | ||
import { FieldDefinitions, ValueConverter, ValueListItem } from './column-interfaces'; | ||
import { FieldDefinitions } from './column-interfaces'; | ||
import { Filter } from './filter/filter-interfaces'; | ||
import { ClassType, EntityWhere, FindOptions, Repository } from './remult3'; | ||
import { StoreAsStringValueConverter } from './columns/loaders'; | ||
import { EntityWhere, FindOptions, Repository } from './remult3'; | ||
export declare function makeTitle(name: string): string; | ||
@@ -16,19 +14,2 @@ export declare class CompoundIdField { | ||
} | ||
export declare class ValueListValueConverter<T extends ValueListItem> implements ValueConverter<T> { | ||
private type; | ||
private info; | ||
constructor(type: ClassType<T>); | ||
fromJson(val: any): T; | ||
toJson(val: T): any; | ||
fromDb(val: any): T; | ||
toDb(val: T): any; | ||
toInput(val: T, inputType: string): string; | ||
fromInput(val: string, inputType: string): T; | ||
displayValue?(val: T): string; | ||
fieldTypeInDb?: string; | ||
inputType?: string; | ||
getOptions(): T[]; | ||
byId(key: any): T; | ||
} | ||
export declare function lookupConverter<T>(type: ClassType<T>): (c: Context) => StoreAsStringValueConverter<LookupColumn<T>>; | ||
export declare class LookupColumn<T> { | ||
@@ -35,0 +16,0 @@ private repository; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.OneToMany = exports.ManyToOne = exports.LookupColumn = exports.lookupConverter = exports.ValueListValueConverter = exports.CompoundIdField = exports.makeTitle = void 0; | ||
exports.OneToMany = exports.ManyToOne = exports.LookupColumn = exports.CompoundIdField = exports.makeTitle = void 0; | ||
var tslib_1 = require("tslib"); | ||
var filter_interfaces_1 = require("./filter/filter-interfaces"); | ||
var loaders_1 = require("./columns/loaders"); | ||
function makeTitle(name) { | ||
@@ -83,92 +82,2 @@ // insert a space before all caps | ||
exports.CompoundIdField = CompoundIdField; | ||
var ValueListValueConverter = /** @class */ (function () { | ||
function ValueListValueConverter(type) { | ||
this.type = type; | ||
this.info = ValueListInfo.get(this.type); | ||
if (this.info.isNumeric) { | ||
this.fieldTypeInDb = 'int'; | ||
} | ||
} | ||
ValueListValueConverter.prototype.fromJson = function (val) { | ||
return this.byId(val); | ||
}; | ||
ValueListValueConverter.prototype.toJson = function (val) { | ||
if (!val) | ||
return undefined; | ||
return val.id; | ||
}; | ||
ValueListValueConverter.prototype.fromDb = function (val) { | ||
return this.fromJson(val); | ||
}; | ||
ValueListValueConverter.prototype.toDb = function (val) { | ||
return this.toJson(val); | ||
}; | ||
ValueListValueConverter.prototype.toInput = function (val, inputType) { | ||
return this.toJson(val); | ||
}; | ||
ValueListValueConverter.prototype.fromInput = function (val, inputType) { | ||
return this.fromJson(val); | ||
}; | ||
ValueListValueConverter.prototype.displayValue = function (val) { | ||
if (!val) | ||
return ''; | ||
return val.caption; | ||
}; | ||
ValueListValueConverter.prototype.getOptions = function () { | ||
return this.info.getOptions(); | ||
}; | ||
ValueListValueConverter.prototype.byId = function (key) { | ||
if (key === undefined) | ||
return undefined; | ||
if (this.info.isNumeric) | ||
key = +key; | ||
return this.info.byId(key); | ||
}; | ||
return ValueListValueConverter; | ||
}()); | ||
exports.ValueListValueConverter = ValueListValueConverter; | ||
var ValueListInfo = /** @class */ (function () { | ||
function ValueListInfo(valueListType) { | ||
this.valueListType = valueListType; | ||
this.byIdMap = new Map(); | ||
this.values = []; | ||
this.isNumeric = false; | ||
for (var member in this.valueListType) { | ||
var s = this.valueListType[member]; | ||
if (s instanceof this.valueListType) { | ||
if (s.id === undefined) | ||
s.id = member; | ||
if (s.caption === undefined) | ||
s.caption = makeTitle(member); | ||
if (typeof s.id === 'number') | ||
this.isNumeric = true; | ||
this.byIdMap.set(s.id, s); | ||
this.values.push(s); | ||
} | ||
} | ||
} | ||
ValueListInfo.get = function (type) { | ||
var r = typeCache.get(type); | ||
if (!r) | ||
r = new ValueListInfo(type); | ||
typeCache.set(type, r); | ||
return r; | ||
}; | ||
ValueListInfo.prototype.getOptions = function () { | ||
return this.values; | ||
}; | ||
ValueListInfo.prototype.byId = function (key) { | ||
if (this.isNumeric) | ||
key = +key; | ||
return this.byIdMap.get(key); | ||
}; | ||
return ValueListInfo; | ||
}()); | ||
var typeCache = new Map(); | ||
function lookupConverter(type) { | ||
return function (c) { | ||
return new loaders_1.StoreAsStringValueConverter(function (x) { return x.id.toString(); }, function (x) { return new LookupColumn(c.for(type), x); }); | ||
}; | ||
} | ||
exports.lookupConverter = lookupConverter; | ||
var LookupColumn = /** @class */ (function () { | ||
@@ -175,0 +84,0 @@ function LookupColumn(repository, id) { |
@@ -79,3 +79,3 @@ "use strict"; | ||
hasId_1 = false; | ||
w = this.repository.translateWhereToFilter(findOptions.where); | ||
w = this.repository.defs.translateWhereToFilter(findOptions.where); | ||
if (w) { | ||
@@ -149,3 +149,3 @@ w.__applyToConsumer({ | ||
if (this.options && this.options.get && this.options.get.where) | ||
where = this.repository.translateWhereToFilter(this.options.get.where); | ||
where = this.repository.defs.translateWhereToFilter(this.options.get.where); | ||
if (request) { | ||
@@ -170,3 +170,3 @@ where = new filter_interfaces_1.AndFilter(where, this.repository.extractWhere(request)); | ||
if (_this.options && _this.options.get && _this.options.get.where) | ||
where = new filter_interfaces_1.AndFilter(where, _this.repository.translateWhereToFilter(_this.options.get.where)); | ||
where = new filter_interfaces_1.AndFilter(where, _this.repository.defs.translateWhereToFilter(_this.options.get.where)); | ||
return where; | ||
@@ -173,0 +173,0 @@ } |
@@ -254,3 +254,8 @@ "use strict"; | ||
var col = colKeys[index]; | ||
result[col.key] = col.valueConverter.fromDb(y[r.getColumnKeyInResultForIndexInSelect(index)]); | ||
try { | ||
result[col.key] = col.valueConverter.fromDb(y[r.getColumnKeyInResultForIndexInSelect(index)]); | ||
} | ||
catch (err) { | ||
throw new Error("Failed to load from db:" + col.key + "\r\n" + err); | ||
} | ||
} | ||
@@ -291,3 +296,3 @@ return result; | ||
v = x.valueConverter.toDb(data[x.key]); | ||
if (v != undefined) { | ||
if (v !== undefined) { | ||
if (!added) | ||
@@ -294,0 +299,0 @@ added = true; |
@@ -120,3 +120,3 @@ "use strict"; | ||
else | ||
result += " text default '' not null "; | ||
result += " text" + (x.allowNull ? " " : " default '' not null "); | ||
return result; | ||
@@ -123,0 +123,0 @@ }; |
import { Allowed, Context, EntityAllowed } from "./context"; | ||
import { FieldDefinitions } from './column-interfaces'; | ||
import { EntityOrderBy, EntityWhereItem, FieldDefinitionsOf, filterOf } from "./remult3"; | ||
import { EntityOrderBy, FieldDefinitionsOf, filterOf, EntityWhere } from "./remult3"; | ||
import { Filter } from "./filter/filter-interfaces"; | ||
@@ -48,3 +48,3 @@ export interface EntitySettings<T = any> { | ||
*/ | ||
fixedFilter?: EntityWhereItem<T>; | ||
fixedFilter?: EntityWhere<T>; | ||
/** An order by to be used, in case no order by was specified | ||
@@ -51,0 +51,0 @@ * @example |
@@ -19,2 +19,3 @@ import { FieldDefinitions } from "../column-interfaces"; | ||
error: string; | ||
setValues(item?: Partial<T>): any; | ||
toApiPojo(): any; | ||
@@ -37,3 +38,2 @@ register(listener: RowEvents): any; | ||
idField: FieldDefinitions; | ||
createFilterOf(): filterOf<Type>; | ||
}; | ||
@@ -71,5 +71,7 @@ export declare type sortOf<Type> = { | ||
readonly evilOriginalSettings: EntitySettings; | ||
translateWhereToFilter(where: EntityWhere<T>): Filter; | ||
createFilterOf(): filterOf<T>; | ||
} | ||
export interface Repository<T> { | ||
fromPojo(x: any): any; | ||
fromPojo(x: any): T; | ||
defs: EntityDefinitions<T>; | ||
@@ -110,3 +112,2 @@ find(options?: FindOptions<T>): Promise<T[]>; | ||
createIdInFilter(items: T[]): Filter; | ||
translateWhereToFilter(where: EntityWhere<T>): Filter; | ||
packWhere(where: EntityWhere<T>): any; | ||
@@ -164,8 +165,3 @@ unpackWhere(packed: any): Filter; | ||
*/ | ||
export declare type EntityWhereItem<entityType> = ((entityType: filterOf<entityType>) => (Filter | Filter[])); | ||
/**Used to filter the desired result set | ||
* @example | ||
* where: p=> p.availableFrom.isLessOrEqualTo(new Date()).and(p.availableTo.isGreaterOrEqualTo(new Date())) | ||
*/ | ||
export declare type EntityWhere<entityType> = EntityWhereItem<entityType> | EntityWhereItem<entityType>[]; | ||
export declare type EntityWhere<entityType> = ((entityType: filterOf<entityType>) => (Filter | Filter[])) | EntityWhere<entityType>[]; | ||
export interface filterOptions<x> { | ||
@@ -188,2 +184,4 @@ isEqualTo(val: x): Filter; | ||
[Properties in keyof Type]: Type[Properties] extends number | Date ? comparableFilterItem<Type[Properties]> : Type[Properties] extends string ? supportsContains<Type[Properties]> & comparableFilterItem<Type[Properties]> : supportsContains<Type[Properties]>; | ||
} & { | ||
translateWhereToFilter(where: EntityWhere<Type>): Filter; | ||
}; | ||
@@ -190,0 +188,0 @@ export declare type ClassType<T> = { |
@@ -26,3 +26,3 @@ import { FieldDefinitions, FieldSettings, ValueConverter, ValueListItem } from "../column-interfaces"; | ||
addToCache(item: T): void; | ||
fromPojo(x: any): void; | ||
fromPojo(x: any): T; | ||
get defs(): EntityDefinitions; | ||
@@ -47,3 +47,2 @@ _getApiSettings(): DataApiSettings<T>; | ||
translateOrderByToSort(orderBy: EntityOrderBy<T>): Sort; | ||
translateWhereToFilter(where: EntityWhere<T>): Filter; | ||
updateEntityBasedOnWhere(where: EntityWhere<T>, r: T): void; | ||
@@ -89,2 +88,3 @@ packWhere(where: EntityWhere<T>): any; | ||
constructor(info: EntityFullInfo<T>, instance: T, repository: Repository<T>, edp: EntityDataProvider, context: Context, _isNew: boolean); | ||
setValues(item?: Partial<T>): T; | ||
private _wasDeleted; | ||
@@ -144,2 +144,6 @@ listeners: RowEvents[]; | ||
export declare function getEntityOf<T>(item: T): rowHelper<T>; | ||
export declare const CaptionHelper: { | ||
determineCaption: (context: Context, key: string, caption: string) => string; | ||
}; | ||
export declare function buildCaption(caption: string | ((context: Context) => string), key: string, context: Context): string; | ||
export declare class columnDefsImpl implements FieldDefinitions { | ||
@@ -169,2 +173,3 @@ private colInfo; | ||
constructor(columnsInfo: columnInfo[], entityInfo: EntitySettings, context: Context); | ||
translateWhereToFilter(where: EntityWhere<T>, ignoreFixed?: boolean): Filter; | ||
dbAutoIncrementId: boolean; | ||
@@ -228,3 +233,4 @@ idField: FieldDefinitions<any>; | ||
get $(): EntityFields<this>; | ||
setValues(item?: Partial<this>): any; | ||
} | ||
export {}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
1212919
304
18763